jiahuimbzuai/CoQuIR huggingface dataset:
//  [rust]
use std::io;
use std::cmp::min;

fn procon_read<T: std::str::FromStr>() ->  Vec<T> {
	let mut buf = String::new();
	io::stdin().read_line(&mut buf).expect("");
	let iter = buf.split_whitespace();
	let mut v: Vec<T> = Vec::new();
	for i in iter {
		v.push(i.parse().ok().unwrap());
	}
	v
}

fn main() {
	let v:Vec<i32> = procon_read();
	let a = v[0];
	let b = v[1];
	let c = v[2];
	let d = v[3];
	let mut pusht = 0;
	if c < b && d > a {
		if a < c {
			pusht = b - c;
		}
		if d < b {
			pusht = d - a;
		}
	}
	println!("{}", pusht);
}
//  [swift]
let i=readLine()!.characters.split(" ").map{Int(String($0))!};print(max(min(i[1],i[3])-max(i[0],i[2]),0))
//  [swift]
let i = readLine()!.characters.split(" ").map{Int(String($0))!};print(max(min(i[1],i[3])-max(i[0],i[2]),0))
//  [swift]
import Foundation

#if swift(>=4.0)
extension String {
    func split(by separator: String) -> [String] {
        return self.components(separatedBy: separator)
    }
    func toArray() -> [String] {
        return self.map{String($0)}
    }
}
func exponentiate(_ lhs: Int, _ rhs: Int) -> Int {
    return (0..<rhs).reduce(1){i,_ in i*lhs}
}
#else
extension String {
    func split(by separator: String) -> [String] {
        return self.componentsSeparatedByString(separator)
    }
    var count: Int {
        return self.characters.count
    }
    func toArray() -> [String] {
        return self.characters.map{String($0)}
    }
    func uppercased() -> String {
        return self.uppercaseString
    }
    func lowercased() -> String {
        return self.lowercaseString
    }
}
//extension Array where Element == String {
//    func joined(separator separator: String) -> String {
//        return self.joinWithSeparator(separator)
//    }
//}
extension Array where Element: Comparable {
    func max() -> Element {
        return self.maxElement()!
    }
    func min() -> Element {
        return self.minElement()!
    }
    func sorted() -> Array {
        return self.sort()
    }
    func reversed() -> Array {
        return self.reverse()
    }
    mutating func sort() {
        self.sortInPlace()
    }
}
extension Array {
    init(repeating: Element, count: Int) {
        self.init(count: count, repeatedValue: repeating)
    }
}
func stride<T: Strideable>(from start: T, to end: T, by stride: T.Stride) -> StrideTo<T> {
    return start.stride(to: end, by: stride)
}
func exponentiate(lhs: Int, _ rhs: Int) -> Int {
    return (0..<rhs).reduce(1){i,_ in i*lhs}
}
#endif
func readInt() -> Int? {
    return Int(readLine()!)
}
func readStringSplit(by separator: String) -> [String] {
    return readLine()!.split(by: separator)
}
func readIntSplit(by separator: String) -> [Int] {
    return readLine()!.split(by: separator).map{Int($0)!}
}

/*************** テストスペース ***************/



/*************** メインプログラム ***************/

let input = readIntSplit(by: " ")
let (A, B, C, D) = (input[0], input[1], input[2], input[3])
let start = max(A, C)
let end = min(B, D)
print(max(end - start, 0))
//  [swift]
import Foundation
func toTuple<T>(_ args: [T]) -> (T, T, T, T) { (args[0], args[1], args[2], args[3]) }
func readInts() -> [Int] { readLine()!.split(separator: " ").map { Int($0)! } }

let main = {
  let (a, b, c, d) = toTuple(readInts())
  if b < c || a > d { print(0); return }
  if a >= c && b <= d { print(b - a); return }
  if a <= c && b >= d { print(d - c); return }
  if a <= c && b >= c && b <= d { print(b - c); return }
  if a >= c  && a <= d && b >= d { print(b - a); return }
}
main()
//  [swift]
a,b,c,d = map(int,input().split())
t = False
if(a<=c<=b or a<=d<=b or c<=a<=d or c<=b<=d):
    t = True
else:
    t = False

if t:
    if(a<=c<=b and b<d):
        print(b-c)
    elif(a<=c<=b and b>=d):
        print(d-c)
    elif(a<=d<=b and a<=c):
        print(d-c)
    elif(a<=d<=b and a>c):
        print(d-a)
    elif(c<=a<=d and b<=d):
        print(b-a)
    elif(c<=a<=d and b>d):
        print(d-a)
    elif(c<=b<=d and a<c):
        print(b-c)
    elif(c<=b<=d and a>c):
        print(b-a)
else:
    print(0)
//  [swift]
import Foundation

#if swift(>=4.0)
extension String {
    func split(by separator: String) -> [String] {
        return self.components(separatedBy: separator)
    }
    func toArray() -> [String] {
        return self.map{String($0)}
    }
}
func exponentiate(_ lhs: Int, _ rhs: Int) -> Int {
    return (0..<rhs).reduce(1){i,_ in i*lhs}
}
#else
extension String {
    func split(by separator: String) -> [String] {
        return self.componentsSeparatedByString(separator)
    }
    var count: Int {
        return self.characters.count
    }
    func toArray() -> [String] {
        return self.characters.map{String($0)}
    }
    func uppercased() -> String {
        return self.uppercaseString
    }
    func lowercased() -> String {
        return self.lowercaseString
    }
}
//extension Array where Element == String {
//    func joined(separator separator: String) -> String {
//        return self.joinWithSeparator(separator)
//    }
//}
extension Array where Element: Comparable {
    func max() -> Element {
        return self.maxElement()!
    }
    func min() -> Element {
        return self.minElement()!
    }
    func sorted() -> Array {
        return self.sort()
    }
    func reversed() -> Array {
        return self.reverse()
    }
    mutating func sort() {
        self.sortInPlace()
    }
}
extension Array {
    init(repeating: Element, count: Int) {
        self.init(count: count, repeatedValue: repeating)
    }
}
func stride<T: Strideable>(from start: T, to end: T, by stride: T.Stride) -> StrideTo<T> {
    return start.stride(to: end, by: stride)
}
func exponentiate(lhs: Int, _ rhs: Int) -> Int {
    return (0..<rhs).reduce(1){i,_ in i*lhs}
}
#endif
func readInt() -> Int? {
    return Int(readLine()!)
}
func readStringSplit(by separator: String) -> [String] {
    return readLine()!.split(by: separator)
}
func readIntSplit(by separator: String) -> [Int] {
    return readLine()!.split(by: separator).map{Int($0)!}
}

/*************** テストスペース ***************/



/*************** メインプログラム ***************/

let input = readIntSplit(by: " ")
let (A, B, C, D) = (input[0], input[1], input[2], input[3])
let start = max(A, C)
let end = min(B, D)
print(min(end - start, 0))
//  [typescript]
import * as fs from 'fs'

const getInput = (): string => {
  return (fs.readFileSync('/dev/stdin', 'utf8') as string).trim()
}

export const solveAbc070b = () => {
  const input = getInput()

  const [A, B, C, D] = input.trim().split(' ').map(Number)

  const min = Math.max(A, C)
  const max = Math.min(B, D)
  console.log(Math.max(max - min, 0))
}
solveAbc070b()
//  [typescript]
function*stdinIter(){const t=require("fs").readFileSync("/dev/stdin","utf-8").trim().split(/\n|\s/);yield*t}function readMany(t,e){const i=e||this.iter||(this.iter=stdinIter()),n=[];for(let e=0;e<t;e+=1)n.push(i.next().value);return n};

(() => {
    const [ a, b, c, d ] = readMany(4)
    let ans = 0

    for (let i = 0; i <= 100; i += 1) {
        if (
            (a <= i && i <= b) &&
            (c <= i && i <= d)
        ) {
            ans += 1
        }
    }

    console.log(ans ? ans - 1 : 0)
})()
//  [typescript]
const input=require('fs').readFileSync('/dev/stdin','utf8').split(/[\s]/);const tn=():number=>{const a=input[0];input.shift();return Number(a)};const tnn=(n:number):number[]=>{const a=[];for(let i=0;i<n;i++){a.push(tn())}return a};const ts=():string=>{const a=input[0];input.shift();return String(a)};const tss=(n:number):string[]=>{const a=[];for(let i=0;i<n;i++){a.push(ts())}return a};const tc=():string=>{let a=input[0].split('');const b=a[0];a.shift();if(a.length>0){input[0]=a.join('')}else{input.shift()}return String(b)};const tcc=(n:number):string[]=>{const a=[];for(let i=0;i<n;i++){a.push(tc())}return a};const to=(...arg)=>{console.log(...arg)};const abs=(a)=>{return Math.abs(a)};const min=(...a)=>{return Math.min(...a)};const max=(...a)=>{return Math.max(...a)};const floor=(a)=>{return Math.floor(a)};const asc=(ar:number[])=>{return ar.sort((a,b)=>{return a-b})};const desc=(ar:number[])=>{return ar.sort((a,b)=>{return b-a})};const sw=(a,arr:any[],op:'=='|'>='|'>'|'<='|'<'='==')=>{for(let i=0;i<arr.length-1;i+=2){if(eval(a+op+arr[i])){return arr[i+1];}}return arr[arr.length-1]};const near=(n:number,arr:number[]):number=>{let ne=arr[0],ni=0;for(let i=1;i<arr.length;i++){if(Math.abs(n-ne)>Math.abs(n-arr[i])){ne=arr[i];ni=i}}return ni};const objvs =(a)=>{const b=[];for(const v in a){b.push(a[v])}return b};
const main=()=>{
  let [a,b,c,d]=tnn(4)
  to(min(b,d)-max(a,c)>=0?min(b,d)-max(a,c):0)
}
main()
//  [typescript]
const input=require('fs').readFileSync('/dev/stdin','utf8').split(/[\s]/);const tn=():number=>{const a=input[0];input.shift();return Number(a)};const tnn=(n:number):number[]=>{const a=[];for(let i=0;i<n;i++){a.push(tn())}return a};const ts=():string=>{const a=input[0];input.shift();return String(a)};const tss=(n:number):string[]=>{const a=[];for(let i=0;i<n;i++){a.push(ts())}return a};const tc=():string=>{let a=input[0].split('');const b=a[0];a.shift();if(a.length>0){input[0]=a.join('')}else{input.shift()}return String(b)};const tcc=(n:number):string[]=>{const a=[];for(let i=0;i<n;i++){a.push(tc())}return a};const to=(...arg)=>{console.log(...arg)};const abs=(a)=>{return Math.abs(a)};const min=(...a)=>{return Math.min(...a)};const max=(...a)=>{return Math.max(...a)};const floor=(a)=>{return Math.floor(a)};const asc=(ar:number[])=>{return ar.sort((a,b)=>{return a-b})};const desc=(ar:number[])=>{return ar.sort((a,b)=>{return b-a})};const sw=(a,arr:any[],op:'=='|'>='|'>'|'<='|'<'='==')=>{for(let i=0;i<arr.length-1;i+=2){if(eval(a+op+arr[i])){return arr[i+1];}}return arr[arr.length-1]};const near=(n:number,arr:number[]):number=>{let ne=arr[0],ni=0;for(let i=1;i<arr.length;i++){if(Math.abs(n-ne)>Math.abs(n-arr[i])){ne=arr[i];ni=i}}return ni};const objvs =(a)=>{const b=[];for(const v in a){b.push(a[v])}return b};
const main=()=>{
  let [a,b,c,d]=tnn(4)
  to(min(b,d)-max(a,c))
}
main()
//  [python]
N,K = map(int,input().split())
if N>=K:
    N %= K
N = min(N,abs(N-K))
print(N)
//  [python]
n, k = map(int, input().split())
print(min(n % k, k - n % k))
//  [python]
n, k = map(int,input().split())
x = n % k
if x < abs(x-k):
    print(x)
else :
    print(abs(x-k))
//  [python]
N, K = map(int, input().split())
# K > 1 かつ　N > Kの場合は、N - N // K * K をスタートにできる
if K > 1:
  N = N - N // K * K
else:
  N = 0
minimum = N
count = 0
#print(N)
while count <= N / 4:
  N = abs(N - K)
  minimum = min(N, minimum)
  count += 1
print(minimum)
//  [python]
N, K = map(int, input().split())
# K > 1 かつ　N > Kの場合は、N - N // K * K をスタートにできる
if K > 1:
  N = N - N // K * K
else:
  N = 0
minimum = N
count = 0
#print(N)
while count < N:
  N = abs(N - K)
  minimum = min(N, minimum)
  count += 1
print(minimum)
//  [python]
N, K = map(int, input().split())
ans = N
x = abs(N - K)
if N % K == 0:
    print(0)
else:
    while ans > x:
        ans = x
        x = abs(x - K)
    else:
        print(ans)
//  [java]
import java.io.*;
import java.util.*;

public class Main {

    private static FastReader in = new FastReader(System.in);
    private static PrintWriter out = new PrintWriter(System.out);

    private static final long MOD = (long) 1e9 + 7;

    public static void main(String[] args) {
        solve();
        out.flush();
    }

    private static void solve() {
        long n = in.nextLong();
        long k = in.nextLong();

        long min = n;

        n -= (n / k) * k;

        min = Math.min(min, n);
        n = Math.abs(n - k);
        out.println(Math.min(min, n));
    }

    // https://www.geeksforgeeks.org/fast-io-in-java-in-competitive-programming/
    static class FastReader {
        BufferedReader br;
        StringTokenizer st;

        FastReader(InputStream inputStream) {
            br = new BufferedReader(new
                    InputStreamReader(inputStream));
        }

        String next() {
            while (st == null || !st.hasMoreElements()) {
                try {
                    st = new StringTokenizer(br.readLine());
                } catch (IOException  e) {
                    e.printStackTrace();
                }
            }
            return st.nextToken();
        }

        int nextInt() {
            return Integer.parseInt(next());
        }

        long nextLong() {
            return Long.parseLong(next());
        }

        double nextDouble() {
            return Double.parseDouble(next());
        }

        String nextLine() {
            String str = "";
            try {
                str = br.readLine();
            } catch (IOException e) {
                e.printStackTrace();
            }
            return str;
        }

        // https://qiita.com/masakinpo/items/5f77f2a879578a85a0bb
        public int[] nextIntArray(int n) {
            int[] a = new int[n];
            for (int i = 0; i < n; i++)
                a[i] = nextInt();
            return a;
        }

        public long[] nextLongArray(int n) {
            long[] a = new long[n];
            for (int i = 0; i < n; i++)
                a[i] = nextLong();
            return a;
        }
    }
}
//  [java]
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.List;

public class Main {

    public static void main(String[] args) throws Exception {
        InputStreamReader is = new InputStreamReader(System.in);
        BufferedReader reader = new BufferedReader(is);

        List<String> mylist = new ArrayList<>();

        // 標準入力からの値を変数strinputに代入
        String strinput = reader.readLine();

        while (strinput != null) {

            mylist.add(strinput);
            strinput = reader.readLine();

        }

        String arr[] = mylist.get(0).split(" ");
        long n = Long.valueOf(arr[0]);
        long k = Long.valueOf(arr[1]);
        long amari = n % k;
        long temp = Math.abs(amari - k);

//        System.out.println(temp + " " + amari);

        System.out.println(Math.min(amari, temp));

    }

}
//  [java]
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {

		Scanner sc = new Scanner(System.in);

		String[] t = sc.nextLine().split(" ");
		long n = Long.parseLong(t[0]);
		long k = Long.parseLong(t[1]);

		long min = Math.min(n, n % k);
		min = Math.min(min, n % k + k);
		min = Math.min(min, n % k - k);

		System.out.println(min);
	}
}
//  [cpp]
#include<stdio.h>
#define ll long long
ll min(ll a,ll b){return a<b?a:b;}
int main(){
    ll n, k;
    scanf("%lld%lld",&n,&k);
    printf("%lld\n",min((n%k),k-(n%k)));
    return 0;
}
//  [cpp]
#include<stdio.h>
long long n, m;
#define min(i, j) i < j ? i : j
int main() {
    scanf("%lld%lld", &n, &m);
    n %= m;
    n = min(n, m - n);
    printf("%lld\n", n);
    return 0;
}
//  [cpp]
#include <bits/stdc++.h>
using namespace std;

int main() {
  
  int64_t N,K;
  cin >> N >> K;
  
  int64_t A = N -((N / K) * K);
  
  while(true){
    A -= K;
    if(A <= 0){
      break;
    }
  }
  int64_t S = A + K;
  int64_t T = A * (-1);
  
  if(S < T){
    cout << S << endl;
  }
  
  else{
    cout << T << endl;
  }
  
    
    
}
//  [cpp]
#include <bits/stdc++.h>
using namespace std;
#define watch(x) cout << (#x) << " is " << (x) << '\n'
#define rep(i,a,n) for (int i=a;i<n;i++)
#define per(i,a,n) for (int i=n-1;i>=a;i--)
#define pb push_bacm
#define mp mame_pair
#define all(x) (x).begin(),(x).end()
#define fi first
#define se second
#define sz(x) ((int)(x).size())
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef pair<int, int> pi;
typedef pair<ll, ll> pll;
typedef double db;
ll gcd(ll a, ll b) { return b?gcd(b,a%b):a; }
//head

void solve(){
    ll n, k;
    cin >> n >> k;
    ll ans;
    if (n < k) ans = n;
    else {
        ll r = n % k;
        ans = min(r, k-r);
    }
    cout << ans << '\n';
}

int main(void){ 
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);

    //int t; cin >> t; while (t--)
        solve();
}
//  [cpp]
#include <bits/stdc++.h>
using namespace std;

#define ll long long
#define FOR(i, a, b) for (int i = (int)(a); i < (int)(b); i++)
#define REP(i, x) for (int i = 0; i < (int)(x); i++)
#define REPS(i, x) for (int i = 1; i <= (int)(x); i++)
#define RREP(i, x) for (int i = ((int)(x)-1); i >= 0; i--)
#define RREPS(i, x) for (int i = ((int)(x)); i > 0; i--)
#define INF 2147483647
#define LLINF 9223372036854775807LL
#define vi vector<int>
#define vvi vector<vector<int>>
#define vvvi vector<vector<vector<int>>>
#define pi pair<int, int>
#define ALL(a) (a).begin(), (a).end()
#define BIT(n) (1LL << (n))

int dx[8] = {1, 0, -1, 0, 1, 1, -1, -1};
int dy[8] = {0, 1, 0, -1, 1, -1, 1, -1};

int main(){
ll N,K,x; cin>>N>>K;
if(N>K){
    x=N%K;
}else{
    x=N;
}
ll ans=0;
while(true){
    ll tmp1,tmp2,tmp3;
    tmp1=x;
    x=abs(x-K);
    tmp2=abs(tmp1-K);
    tmp3=abs(tmp2-K);
    if(tmp1==tmp3){
        ans=min(tmp1,tmp3);
        break;
    }

}
cout<<ans<<endl;
}
//  [cpp]
#include<stdio.h>
#include<math.h>
#include<bits/stdc++.h>
using namespace std;
int main()
{
long long  n,k,s,p;
   cin>>n>>k

s=n%k;
p=abs(s-k);
if(p>s)
{
printf("%lld\n",s);
}
else
{
printf("%lld\n",p);
}


}
//  [c]
#include <stdio.h>
#include <stdlib.h>

int main(void) {
    long long int start;
    long long int sub_value;

    scanf("%lld %lld", &start, &sub_value);

    long long int result = start % sub_value;

    long long int result2 = llabs(result - sub_value);

    if (result <= result2) {
        printf("%lld\n", result);
    } else {
        printf("%lld\n", result2);
    }
    return 0;
}
//  [c]
#include <stdio.h>

long	ft_abs(int abs)
{
	if (abs < 0)
		abs *= -1;
	return (abs);
}

int		main(void)
{
	long N, K, a;
	scanf("%ld%ld",&N,&K);
	if (N < K)
	{
		a = K - N;
		if (a > N)
			printf("%ld", N);
		else
			printf("%ld", a);
	}
	if (N >= K)
	{
		N %= K;
		if (N < K)
			a = K - N;
		if (a >= N)
			printf("%ld", N);
		else if (a < N)
			printf("%ld", a);
	}

	return 0;
}
//  [c]
#include<stdio.h>
#include<stdlib.h>
int main(){
    long n,k,ans1,ans2;
    scanf("%ld %ld",&n,&k);
    
    ans1 = n % k;
    ans2 = labs(ans1-k);
    if(ans1 <= ans2) printf("%ld\n",ans1);
    else printf("%ld\n",ans2);
    return 0;
}
//  [c]
#include<stdio.h>
#include<math.h>
int main()
{
long long  n,k,s,p;
scanf("%lld%lld",&n,&k);

s=n%k;
p=abs(s-k);
if(p>s)
{
printf("%lld\n",s);
}
else
{
printf("%lld\n",p);
}

return 0;
}
//  [c]
#include<stdio.h>
#include<math.h>
int main()
{
long long  n,k,s,p;
scanf("%lld %lld",&n,&k);

s=n%k;
p=abs(s-k);
if(p>s)
{
printf("%lld\n",s);
}
else
{
printf("%lld\n",p);
}


}
//  [c]
#include<stdio.h>
#include<math.h>
int main()
{
long long  n,k,s,p;
scanf("%lld %lld",&n,&k);

s=n%k;
p=abs(k-s);
if(p>s)
{
printf("%lld\n",s);
}
else
{
printf("%lld\n",p);
}

return 0;
}
//  [javascript]
function main(input) {
  const inputs = input.split('\n')
  const [N, K] = inputs[0].split(' ').map(BigInt)
  const r = N % K
  if (K < 2n * r) {
    console.log(String(K - r))
  } else {
    console.log(String(r))
  }
}
main(require("fs").readFileSync("/dev/stdin", "utf8"));
//  [javascript]
"use strict";

const main = arg => {
    const input = arg.trim().split("\n");

    const N = BigInt(input[0].split(" ")[0]);
    const K = BigInt(input[0].split(" ")[1]);
    if(N%K == 0){
        console.log(0)
        return
    } 

    let tmp = N % K
    if(Number(tmp) < Math.abs(Number(K-tmp))) console.log(Number(tmp))
    else console.log(Math.abs(Number(K-tmp)))

}
main(require('fs').readFileSync('/dev/stdin', 'utf8'));
//  [javascript]
const input = require("fs").readFileSync("/dev/stdin", "utf8")
const lines = input.split('\n')
const [N, K] = lines[0].split(' ').map(Number)
let ans = N % K
ans = Math.min(ans, Math.abs(ans - K))
console.log(ans)
//  [javascript]
const input = require("fs").readFileSync("/dev/stdin", "utf8")
const lines = input.split('\n')
const [N, K] = lines[0].split(' ').map(Number)

console.log(N, K)

let ans = N % K
ans = Math.min(ans, Math.abs(ans - K))
console.log(ans)
//  [javascript]
function Main(inputs) {
　const inputlines = inputs.split("\n");
　const firstline = inputlines[0].split(" ");
　const votevalues = inputlines[1].split(" ").map(x => parseInt(x, 10));
　const standard = 1 / (4 * firstline[1]);
　let yes = 0; 
  
　let totalvotes  = function(arr) {
　　　let sum = 0;
　　　arr.forEach(function(elm) {
　　　sum += elm;
    	　});
    	　return sum;
　};
  
　const currentstandard = totalvotes(votevalues) * standard;
  
　for (let i = 0; i < votevalues.length; i++){
　　if(votevalues[i] >= currentstandard){
　　　yes++;
　　　if(yes == firstline[1]){
　　　　console.log("Yes");
　　　　break;
　　　}
　　}
　}
　if(yes != firstline[1]){
　　console.log("No");
    }
}
 
Main(require("fs").readFileSync("/dev/stdin", "utf8"));
//  [go]
package main

import (
	"fmt"
)

func min(x, y int) int {
	if x < y {
		return x
	} else {
		return y
	}
}

func main() {
	var n, k int
	fmt.Scan(&n, &k)
	r := n % k

	fmt.Println(min(r, k-r))
}
//  [go]
package main

import (
	"fmt"
	"math"
)

func main() {
	var n, k int
	fmt.Scan(&n, &k)

	fmt.Println(int(math.Min(float64(n%k), float64(k-n%k))))

}
//  [go]
package main

import "fmt"

func main() {
	var n, k int
	fmt.Scan(&n, &k)

	n %= k
	min := Min(n, abs(n-k))
	fmt.Println(min)
}

func abs(a int) int {
	if a < 0 {
		return a * (-1)
	}
	return a
}

func Min(a, b int) int {
	if a > b {
		return b
	}
	return a
}
//  [go]
package main

import (
	"fmt"
	"math"
)

func main() {
	var N, K int
	fmt.Scanf("%d %d", &N, &K)

	var X int = N % K
	var min int = 5 * int(math.Pow10(18))
	for {
		flag := int(math.Abs(float64(X) - float64(K)))
		if flag < int(math.Abs(float64(min))) {
			X = flag
			min = flag
		} else {
			break
		}

	}
	fmt.Println(min)

}
//  [go]
package main

import (
	"fmt"
	"math"
)

func main() {
	var N, K int
	fmt.Scanf("%d %d", &N, &K)

	var X int = N - K*(N/K)
	var min int = 5 * int(math.Pow10(18))
	for {
		flag := int(math.Abs(float64(X) - float64(K)))
		if flag < int(math.Abs(float64(min))) {
			X = flag
			min = flag
		} else {
			break
		}

	}
	fmt.Println(min)

}
//  [go]
package main

import (
	"fmt"
	"math"
)

func main() {
	var N, K int
	fmt.Scanf("%d %d", &N, &K)

	var X int = N - K*(N/K)
	var min int = int(math.Pow10(18))
	for {
		flag := int(math.Abs(float64(X) - float64(K)))
		if flag < int(math.Abs(float64(min))) {
			X = flag
			min = flag
		} else {
			break
		}

	}
	fmt.Println(min)

}
//  [ruby]
n,k = gets.split.map(&:to_i)
a = ((n%k)-k).abs
b = (a-k).abs
if a < b
  puts a
else
  puts b
end
//  [ruby]
n, k = gets.strip.split.map(&:to_i)

a = n % k
b = k - a

puts [a, b].min
//  [ruby]
n, k = gets.split.map(&:to_i)
puts [n % k, k - (n % k)].min
//  [ruby]
N,K = gets.strip.split.map(&:to_i)
a = (N.to_f/K).floor
b = (N.to_f/K).ceil
puts [(N-a*K).abs,(N-b*K).abs].min
//  [ruby]
N,K = gets.strip.split.map(&:to_i)
ary = [N]
x = N
while
  unless ary.include?((x-K).abs) then
    x = (x-K).abs
    ary.unshift(x)
  else
    break
  end
end
puts ary.min
//  [ruby]
x,y=gets.split.map!(&:to_i)
ans1=0
if y<10000
  x=x%10000
end
ans2=x
while true
  ans1=(ans2-y).abs
  if ans1>ans2
    ans1=ans2
    break
  end
  ans2=ans1
end
if x==0
  puts 0
else
  puts ans1
end
//  [rust]
use proconio::{fastout, input};

#[fastout]
fn main() {
    input! {in_n: i64, in_k: i64};
    let m = in_n % in_k;
    let r = in_k - m;

    if m < r {
        println!("{}", m);
    } else {
        println!("{}", r);
    }
}
//  [rust]
use proconio::fastout;
use proconio::input;
#[allow(unused_imports)]
use proconio::marker::*;
use std::cmp::min;

#[fastout]
fn main() {
    input! {
        n: isize,
        k: isize,
    }
    let i = n % k;
    println!("{}", min(i, (k - i).abs()));
}
//  [rust]
#[allow(unused_imports)]
use std::cmp::{max, min, Ordering};
#[allow(unused_imports)]
use std::collections::{BTreeMap, BTreeSet, BinaryHeap, HashMap, HashSet, VecDeque};
#[allow(unused_imports)]
use std::io::{stderr, stdin, stdout, BufRead, BufWriter, Read, StdoutLock, Write};
#[allow(unused_imports)]
use std::iter::FromIterator;
#[allow(unused_imports)]
use std::{i64, u64, usize};
#[allow(unused_macros)]
/// https://qiita.com/tanakh/items/0ba42c7ca36cd29d0ac8
macro_rules !input {(source =$s :expr ,$($r :tt ) *) =>{let mut iter =$s .split_whitespace () ;input_inner !{iter ,$($r ) *} } ;($($r :tt ) *) =>{let mut s ={use std ::io ::Read ;let mut s =String ::new () ;std ::io ::stdin () .read_to_string (&mut s ) .unwrap () ;s } ;let mut iter =s .split_whitespace () ;input_inner !{iter ,$($r ) *} } ;}
#[allow(unused_macros)]
macro_rules !input_inner {($iter :expr ) =>{} ;($iter :expr ,) =>{} ;($iter :expr ,$var :ident :$t :tt $($r :tt ) *) =>{let $var =read_value !($iter ,$t ) ;input_inner !{$iter $($r ) *} } ;}
#[allow(unused_macros)]
macro_rules !read_value {($iter :expr ,($($t :tt ) ,*) ) =>{($(read_value !($iter ,$t ) ) ,*) } ;($iter :expr ,[$t :tt ;$len :expr ] ) =>{(0 ..$len ) .map (|_ |read_value !($iter ,$t ) ) .collect ::<Vec <_ >>() } ;($iter :expr ,chars ) =>{read_value !($iter ,String ) .chars () .collect ::<Vec <char >>() } ;($iter :expr ,usize1 ) =>{read_value !($iter ,usize ) -1 } ;($iter :expr ,$t :ty ) =>{$iter .next () .unwrap () .parse ::<$t >() .expect ("Parse error" ) } ;}
#[allow(unused_macros)]
macro_rules !dbg {($($a :expr ) ,*) =>{writeln !(&mut stderr () ,concat !($(stringify !($a ) ," = {:?}, " ) ,*) ,$($a ) ,*) .unwrap () ;} }
#[allow(dead_code)]
///refer to https://github.com/hatoo/competitive-rust-snippets
pub const MOD: u64 = 1_000_000_007;
#[allow(dead_code)]
pub fn gcd(a: u64, b: u64) -> u64 {
    if b == 0 {
        a
    } else {
        gcd(b, a % b)
    }
}
#[allow(non_snake_case)]
#[allow(dead_code)]
fn main() {
    input! {
        n: u64,
        k: u64,
    }
    let ans: u64 = min(n % k, ((n % k) as i64 - k as i64).abs() as u64);
    println!("{}", ans);
}
//  [rust]
#[allow(unused_imports)]
use proconio::{fastout, input, marker::*};

#[fastout]
fn main() {
    input! {
        mut n: i64,
        k: i64,
    }

    if n < k {
        let a = i64::abs(n - k);
        let b = i64::abs(a - k);
        println!("{}", std::cmp::min(a,b));
    } else if n / k == n {
        println!("0");
    } else if n < k * 2 {
        let a = n % k;
        let b = k % a;
        println!("{}", std::cmp::min(a,b));
    } else {
        println!("{}", n % k);
    }
}
//  [rust]
#[allow(unused_imports)]
use proconio::{fastout, input, marker::*};

#[fastout]
fn main() {
    input! {
        mut n: i64,
        k: i64,
    }

    if n / k == n {
        println!("0");
    } else {
        loop {
            let result = i64::abs(n - k);
            if n <= result {
                break;
            }
            n = result;
        }
        println!("{}", n);
    }
}
//  [rust]
use proconio::{input, fastout};
// use math::round;
// extern crate math;


#[fastout]
fn main() {
    input!{
        n: f64,
        k: f64
    }

    let x = (n/k).ceil();
    let y = (n/k).floor();

    if (n-x*k).abs() < (n-y*k).abs() {
        println!("{}", (n-x*k).abs())
    } else {
        println!("{}", (n-y*k).abs())
    }
}
//  [swift]
import Foundation

let numArray = (readLine()!).componentsSeparatedByString(" ").map{ Int($0) ?? 0 }
var N = numArray[0]

print(min(N%numArray[1], numArray[1] - (N%numArray[1])) )
//  [swift]
// Replacing Integer

func main() {
    let nk = readLine()!.split(separator: " ").map{Int($0)!}
    let n = nk[0]
    let k = nk[1]
    let rem = n % k

    print(min(rem, abs(rem - k)))
}

main()
//  [swift]
let input = readLine()!
let splitInput = input.split(separator: " ")
var n = Int(splitInput[0])!
var k = Int(splitInput[1])!

var rest = n % k

if rest == 0 {
    print(0)
} else {
    rest -= k
    if rest < 0 {
        rest *= -1
    }

    if n < rest {
        rest = n
    }
    print(rest)
}
//  [swift]
// 🐋💭
import Foundation

func readInts() -> [Int] {
    return readLine()!.split(separator: " ").map { Int($0)! }
}

func main() {
    let nk = readInts()
    //let (n, k) = (nk[0], nk[1])
    var n = nk[0]
    let k = nk[1]
    //__________________________________ここまで入力処理
    if n == 1 {
        print(0)
        return
    }
    while n > abs(n - k) {
        n = abs(n - k)
    }
    print(n)
}
main()
//  [swift]
import Foundation
struct Solve {
    
    let N: Int
    let K: Int
    
    var ans = 0
    mutating func swapAbs() {
        if abs(ans-K)>ans{
            return
        }
        ans = abs(ans-K)
        swapAbs()
    }
}

let inputLine = readLine()!.components(separatedBy: " ").map({Int($0)!})
let solve = Solve(N: inputLine[0], K: inputLine[1])

print(solve.ans)
//  [swift]
let arr=readLine()!.characters.split{$0==" "}.map{Int(String($0))!}
var a=arr[0]
var b=arr[1]
var x = 0
var y = 0
while(true){
    x = a
    if(b==1){
       x = 0
       break
     }
  a -= b
  
  if(a==0)
  {
    x = a
    break
  }else{
    if(0<a){
      x = a
    }else if (a<0){
      y = abs(a)
      if(x<y){
        break
      }else{
        x = y
        break
      }
    }
  }
}
print(String(x))
//  [typescript]
import { readFileSync } from 'fs'

function main(input: string[]) {
  let [N, K] = input[0].split(' ').map(v=>BigInt(v))
  let amari = N % K; 
  let ans = K - amari
  if (amari < ans) ans = amari
  console.log(ans.toString())
}

let lines: string[] = [];
const reader = require('readline').createInterface({
  input: process.stdin,
  output: process.stdout
});

reader.on('line', function (line: string) {
  lines.push(line);
});
reader.on('close', function () {
  main(lines)
});
//  [typescript]
import { readFileSync } from 'fs'

function main(input: string[]) {
  let [N, K] = input[0].split(' ').map(v=>BigInt(parseInt(v, 10)))
  let amari = N % K; 
  let ans = K - amari
  if (amari < ans) ans = amari
  console.log(ans.toString())
}

let lines: string[] = [];
const reader = require('readline').createInterface({
  input: process.stdin,
  output: process.stdout
});

reader.on('line', function (line: string) {
  lines.push(line);
});
reader.on('close', function () {
  main(lines)
});
//  [typescript]
import { readFileSync } from 'fs'

function main(input: string[]) {
  let [N, K] = input[0].split(' ').map(v=>parseInt(v, 10))
  let ans = 0
  let amari = N % K; 
  ans = Math.min(amari, K - amari)
  console.log(ans)
}

let lines: string[] = [];
const reader = require('readline').createInterface({
  input: process.stdin,
  output: process.stdout
});

reader.on('line', function (line: string) {
  lines.push(line);
});
reader.on('close', function () {
  main(lines)
});
//  [python]
str_original = input()
N = len(str_original)
loop = int(N/2)
 
count = 0
for i in range(loop):
  if str_original[i] != str_original[(N-1)-i]:
     count+= 1
      
print(count)
//  [python]
S=input()
k=len(S)//2
T=S[:k]
U=S[-k:][::-1]
N=0
for i in range(k):
  if T[i]==U[i]:
     continue
  else:
     N=N+1
print(N)
//  [python]
s=input()
print(sum([a!=b for a,b in zip(s,s[::-1])])//2)
//  [python]
A=input();print(sum(i!=j for i,j in zip(A,A[::-1])//2)
//  [python]
s=input();n=len(s)-1;print(sum(s[i]!=s[n-i]for i in range(n+1))//2)s=input();n=len(s)-1;print(sum(s[i]!=s[n-i]for i in range(n+1))//2)
//  [python]
A=input()
c=0
B=A[::-1]
for i in range(len(A)):
    if A[i]!=B[i]:
        cnt+=1
print(cnt//2)
//  [java]
import java.util.*;
import java.io.*;

class Main{
    public static void main(String[] args){
        FastScanner fsc=new FastScanner();
        char[] c=fsc.next().toCharArray();
        fsc.close();
        int l=c.length;
        int ans=0;
        for(int i=0;i<l/2;i++){
            if(c[i]!=c[l-i-1]) ans++;
        }
        System.out.println(ans);
    }
    static class FastScanner {
        private final InputStream in = System.in;
        private final byte[] buffer = new byte[1024];
        private int ptr = 0;
        private int buflen = 0;
        private boolean hasNextByte(){
            if(ptr<buflen) return true;
            else{
                ptr = 0;
                try{
                    buflen = in.read(buffer);
                }
                catch(IOException e){
                    e.printStackTrace();
                }
                if(buflen<=0) return false;
            }
        return true;
        }
        private int readByte() { if (hasNextByte()) return buffer[ptr++]; else return -1;}
        private static boolean isPrintableChar(int c) { return 33 <= c && c <= 126;}
        public boolean hasNext() { while(hasNextByte() && !isPrintableChar(buffer[ptr])) ptr++; return hasNextByte();}
        public String next() {
            if (!hasNext()) throw new NoSuchElementException();
            StringBuilder sb = new StringBuilder();
            int b = readByte();
            while(isPrintableChar(b)) {
                sb.appendCodePoint(b);
                b = readByte();
            }
            return sb.toString();
        }
        public long nextLong() {
            if (!hasNext()) throw new NoSuchElementException();
            long n = 0;
            boolean minus = false;
            int b = readByte();
            if (b == '-') {
                minus = true;
                b = readByte();
            }
            if (b < '0' || '9' < b) throw new NumberFormatException();
            while(true){
                if ('0' <= b && b <= '9') {
                    n *= 10;
                    n += b - '0';
                }
                else if(b == -1 || !isPrintableChar(b)) return minus ? -n : n;
                else throw new NumberFormatException();
                b = readByte();
            }
        }
        public int nextInt() {
            long nl = nextLong();
            if (nl < Integer.MIN_VALUE || nl > Integer.MAX_VALUE) throw new NumberFormatException();
            return (int) nl;
        }
        public double nextDouble() { return Double.parseDouble(next());}
        public void close(){
            try{in.close();}
            catch(IOException e){e.printStackTrace();}
        }
    }
}
//  [java]
import java.io.IOException;
import java.io.InputStream;
import java.util.NoSuchElementException;

public class Main {

	public static void main(String[] args) {
		FScanner sc = new FScanner();
		String S = sc.next();
		int length = S.length();
		String S1 = "";
		String S2 = "";
		if (length % 2 == 0) {
			S1 = S.substring(0, length / 2);
			S2 = S.substring(length / 2);
		} else {
			S1 = S.substring(0, length / 2);
			S2 = S.substring(length / 2 + 1);
		}
		int cnt = 0;
		char[] c1 = S1.toCharArray();
		char[] c2 = S2.toCharArray();
		for (int i = 0; i < c1.length; i++) {
			if (c1[i] != c2[c2.length - i - 1]) {
				cnt++;
			}
		}
		System.out.println(cnt);
	}

}

class FScanner {
	private final InputStream in = System.in;
	private final byte[] buffer = new byte[1024];
	private int ptr = 0;
	private int buflen = 0;

	private boolean hasNextByte() {
		if (ptr < buflen) {
			return true;
		} else {
			ptr = 0;
			try {
				buflen = in.read(buffer);
			} catch (IOException e) {
				e.printStackTrace();
			}
			if (buflen <= 0) {
				return false;
			}
		}
		return true;
	}

	private int readByte() {
		if (hasNextByte())
			return buffer[ptr++];
		else
			return -1;
	}

	private boolean isPrintableChar(int c) {
		return 33 <= c && c <= 126;
	}

	public boolean hasNext() {
		while (hasNextByte() && !isPrintableChar(buffer[ptr]))
			ptr++;
		return hasNextByte();
	}

	public String next() {
		if (!hasNext())
			throw new NoSuchElementException();
		StringBuilder sb = new StringBuilder();
		int b = readByte();
		while (isPrintableChar(b)) {
			sb.appendCodePoint(b);
			b = readByte();
		}
		return sb.toString();
	}

	public long nextLong() {
		if (!hasNext())
			throw new NoSuchElementException();
		long n = 0;
		boolean minus = false;
		int b = readByte();
		if (b == '-') {
			minus = true;
			b = readByte();
		}
		if (b < '0' || '9' < b) {
			throw new NumberFormatException();
		}
		while (true) {
			if ('0' <= b && b <= '9') {
				n *= 10;
				n += b - '0';
			} else if (b == -1 || !isPrintableChar(b)) {
				return minus ? -n : n;
			} else {
				throw new NumberFormatException();
			}
			b = readByte();
		}
	}

	public int nextInt() {
		long nl = nextLong();
		if (nl < Integer.MIN_VALUE || nl > Integer.MAX_VALUE)
			throw new NumberFormatException();
		return (int) nl;
	}

	public double nextDouble() {
		return Double.parseDouble(next());
	}
}
//  [java]
import java.util.*;

public class Main {
	public static void main(String[] args) throws Exception{
		Scanner scn = new Scanner(System.in);
		String s = scn.next();
		String[] list = s.split("");
      	int count = 0;
		for(int i=0; i<a.length; i++){
			if(!(list[i].equals(list[s.length()-1-i]))) count++;
		}
      	System.out.println(count/2);
	}
}
//  [java]
import java.util.*;
public class Main {
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    String s = sc.next();
    int leg = s.length();
    String s_l = s.substring(0,leg/2);
    String s_r = s.substring(leg/2);

    int c_l = 0;
    int c_r = leg/2-1;
    
    int count = 0;
    
    for(int i = 0 ; i < leg/2 ; ++i){
      if(s_l.charAt(c_l) != s_r.charAt(c_r)){
        count++;
      }
      c_l++;
      c_r--;
    }
    
    if(leg%2==0 ||count==0){
      System.out.println(count);
    }else{
      System.out.println(count-1);
    }
  }
}
//  [java]
import java.util.*;
public class Main {
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    String s = sc.next();
    int leg = s.length();
    String s_l = s.substring(0,leg/2);
    String s_r = s.substring(leg/2);

    int c_l = 0;
    int c_r = leg/2-1;
    
    int count = 0;
    
    for(int i = 0 ; i < leg/2 ; ++i){
      if(s_l.charAt(c_l) != s_r.charAt(c_r)){
        count++;
      }
      c_l++;
      c_r--;
    }
    
    if(leg%2==0){
      System.out.println(count);
    }else{
      System.out.println(count-1);
    }
  }
}
//  [cpp]
#include<cstdio>
#include<algorithm>
#include<functional>
#include<cstring>
using namespace std;
int main(void)
{
	int i,n,cnt,len;
	char s[101];
	scanf("%s",s);
	len=strlen(s);
	cnt=0;
	for(i=0;i<len/2;i++)	{
		if(s[i]!=s[len-i-1])	cnt++;
	}
	printf("%d\n",cnt);
	return 0;
}
//  [cpp]
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
using namespace std;
typedef long long ll;

int main()
{
    string S;

    cin >> S;

    int len = S.length();

    int count = 0;
    rep(i, len / 2)
    {
        if (S.at(i) != S.at(len - i - 1))
        {
            count++;
        }
    }
    cout << count << endl;
}
//  [cpp]
//   _/                _/                 _/_/_/   _/
//_/_/_/_/   _/_/   _/_/_/_/   _/_/    _/       _/_/
// _/     _/    _/   _/     _/    _/  _/_/_/     _/
//_/     _/    _/   _/     _/    _/  _/    _/   _/
// _/_/   _/_/       _/_/   _/_/      _/_/     _/
#include<iostream>
#include<algorithm>
#include<cmath>
#include<iomanip>
#include<set>
#include<map>
#include<queue>
#include<vector>
using namespace std;
typedef long long ll;
const int MOD=1e9+7;
const double pi=acos(-1);
const int inf=1e9;
int main() {
  cin.tie(0),cout.tie(0);
  ios::sync_with_stdio(false);
  string s;
  cin >> s;
  int ans=0;
  for(int i=0; i<s.size()/2; i++) {
    if(s[i]!=s[s.size()-i-1]) {
      ans++;
    }
  }
  cout << ans << endl;
}
//  [cpp]
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using namespace std;

int main() {
  string s;
  cin >> s;
  int n = s.size(), ans = 0;
  if(n == 1) {
    cout << 0 << endl;
    return 0;
  }
  else {
    if(n % 2 == 0) {
      rep(i, n/2-1) {
        if(s.at(i) != s.at(n-1-i)) ans++;
      }
    }
    else {
      rep(i, n/2-1) {
        if(s.at(i) != s.at(n-1-i)) ans++;
      }
    }
    cout << ans << endl;
  }
}
//  [cpp]
#include<bits/stdc++.h>
using namespace std;
int main(void){
  string s,t; cin>>s;
  t=s; reverse(t.begin(),t.end());
  int res=0;
  for(int i=0; i<s.size(); ++i) if(s[i]!=t[i]) ++res;
  cout<<res;
  return 0;
}
//  [cpp]
#include <bits/stdc++.h>
#define repr(i,a,b) for(int i=a;i<b;i++)
#define rep(i,n) for(int i=0;i<n;i++)
#define reprrev(i,a,b) for(int i=b-1;i>=a;i--) // [a, b)
#define reprev(i,n) reprrev(i,0,n)
#define _GLIBCXX_DEBUG
                    
using ll = long long;
using ull = unsigned long long;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
const ll mod = 1e9+7;
void chmod(ll &M){
  if(M >= mod) M %= mod;
  else if(M < 0){
     M += (abs(M)/mod + 1)*mod;
    M %= mod;
}
}
ll modpow(ll x, ll n){
   if(n==0) return 1;
  ll res=modpow(x, n/2);
 if(n%2==0) return res*res%mod;
else return res*res%mod*x%mod;
}


int getl(int i, int N) { return i==0? N-1:i-1; };
int getr(int i, int N) { return i==N-1? 0:i+1; };
long long GCD(long long a, long long b) {
  if (b == 0) return a;
  else return GCD(b, a % b);
}

using namespace std;

int main() {
  cin.tie(nullptr);
  ios_base::sync_with_stdio(false);
  string S; cin >> S;
  int N = S.length();
  string T;
  
  rep(i, N) {
    T += S.at(N-1-i);
  }
  cerr << T << " " << S;
  

  //元の文と回文に比較
  int count = 0;
  rep(i, N) {
    if(T.at(i) != S.at(i)) count++;
  cerr << T.at(i) << " " << S.at(i) << endl;
   }
  
  cout << count << endl;
}
//  [c]
#include <stdio.h>

int main(void)
{
	char s[101];
	int countChar = 0, countHug = 0;
	int i = 0;

	scanf("%s", s);

	while (s[i])
	{
		countChar++;
		i++;
	}

	for (i = 0; i < countChar / 2; i++)
	{
		if (s[i] != s[countChar - 1 - i])
		{
			countHug++;
		}
	}

	printf("%d\n", countHug);

	return 0;
}
//  [c]
#include<stdio.h>
#include<math.h>
#include<string.h>
#define ll long long int


void sort(ll a[],ll n){

ll i,j,temp;

for(i=0;i<n;i++){

    for(j=0;j<n;j++){

        if(a[i]<a[j]){
            temp=a[i];
            a[i]=a[j];
            a[j]=temp;
        }
    }

}



}


int main(){

char a[100000];
ll i,cnt,n;
cnt=0;

scanf("%s",a);
n=strlen(a);
for(i=0;i<strlen(a)/2;i++)
{
    if(a[i]==a[n-i-1])
    {
        continue;


    }
    else{
        cnt++;
    }



}

printf("%lld",cnt);

return 0;
}
//  [c]
#include <stdio.h>
#include <string.h>
char s[101];
int main(void) {
scanf("%s", s);
int res = 0;
int n = strlen(s);
for (int i = 0; i < n; i++) {
  if (s[i] != s[n - 1 - i]) res++;
  }
	printf("%d\n", res / 2);
}
//  [c]
#include<stdio.h>
#include<string.h>
int main(void){
  char S[200];
  scanf("%s",S);
  int leng;
  leng = strlen(S);
  int i,j;
  j=0;
  for(i=0;i<leng/2 + 1;i++){
    if(S[i]==S[leng-i])
      j++;
  }
  printf("%d",j);
  return 0;
}
//  [c]
#include <stdio.h>

int main()
{
  char s[102];
  int i,n=0,count=0;

  scanf("%s", s);

  for(i=0;;i++){
    if(s[i] !='\0')
      n++;
    else
      break;
    }

  for(i=0; i < n/2; i++)
  {
    if(s[i] != s[n-1-i])
      count++;
  }

  printf("%d",n);
  printf("%d",count );

    return 0;
}
//  [c]
main(){char a[110];int t,i,c=0;scanf("%s",a);t=strlen(a);
for(i=0;i<(t-1)/2;i++){if(a[i]!=a[t-i-1])c++;}printf("%d",c);}
//  [javascript]
function main(arg) {
	arg = arg.trim();
  	var long = arg.length,
        c = Math.round(long/2),
  		out = 0;
	for (var i = 0; i < c; i ++) {
    	var stword = arg[i],
           	lsword = arg[long - i -1];
      	if (stword != lsword) {
        	out++;
        }
    }
  console.log(out)
  	
}
main(require('fs').readFileSync('/dev/stdin', 'utf8'));
//  [javascript]
function Main(s) {
  var answer = 0;
 
  const half = Math.ceil(s.length / 2);
  for (var i = half; i < s.length; i++) {
    if (s[s.length - i - 1] !== s[i]) {
      answer++;
    }
  }
 
  console.log(answer);
}
 
Main(require("fs").readFileSync("/dev/stdin", "utf8").trim());
//  [javascript]
function main(input) {
  var n = input[0];
  var len = n.length;
  var ans = 0;
  for(var i=0;i<Math.trunc(len/2);i++){
    var a = n[i], b=n[len-i-1];
    if(a!=b)ans++;
  }
  console.log(ans);
}
main(require('fs').readFileSync('/dev/stdin', 'utf8').trim().split("\n"))
//  [javascript]
'use strict';
function main(input) {
  const arr = input.trim().split('\n');
  const a = arr[0];
  const length = a.length;
  let count = 0;

  for (let i = 0; i < Math.ceil(length / 2); i ++) {
    if (a[i] === a[length - 1 - i]) {
      count++;
    }
  }
  
  console.log(count);
}

main(require("fs").readFileSync("/dev/stdin", "utf8"));
//  [javascript]
'use strict';
function main(input) {
  const arr = input.trim().split('\n');
  const a = arr[0];
  const length = a.length;
  let count = 0;

  for (let i = 0; i < Math.ceil(length / 2); i ++) {
    if (a[i] === a[length - i]) {
      count++;
    }
  }
  
  console.log(count);
}

main(require("fs").readFileSync("/dev/stdin", "utf8"));
//  [javascript]
'use strict';

function Main(input) {
    const str = input.split('');
    let res = 0;
    for ( let i = 0; i < Math.ceil(str.length / 2); i++) {
        if (str[i] !== str[str.length-1-i]) {
            res++;
        }
    }
    console.log(res);
}
// Main(require("fs").readFileSync("/dev/stdin", "utf8"));
Main('redcoder')
//  [go]
package main

import "fmt"

func main() {
	var s string
	fmt.Scan(&s)
	var ret int
	for i := 0; i < len(s)/2; i++ {
		if s[i] != s[len(s)-i-1] {
			ret++
		}
	}
	fmt.Println(ret)
}
//  [go]
package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
)

var sc = bufio.NewScanner(os.Stdin)

func main() {
	sc.Split(bufio.ScanWords)

	s := nextStr()
	if len(s) == 1 {
		fmt.Println("0")
		return
	}
	if IsKaibun(s) == true {
		fmt.Println("0")
		return
	}

	n := len(s)
	diff := 0

	for i := 0; i < n/2; i++ {
		c := s[i]
		if c != s[n-i-1] {
			diff++
		}
	}

	fmt.Println(diff)
}

// IsKaibun return IsKaibun
func IsKaibun(s string) bool {
	n := len(s)

	for i, c := range s {
		if c != rune(s[n-i-1]) {
			return false
		}
	}

	return true
}

// ---- readfunc
func nextInt() int {
	sc.Scan()
	i, e := strconv.Atoi(sc.Text())
	if e != nil {
		panic(e)
	}
	return i
}
func nextStr() string {
	sc.Scan()
	return sc.Text()
}
//  [go]
package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
)

func solve() {
	s := getRunes()

	ans := 0
	for i := 0; i < len(s)/2; i++ {
		r1 := s[i]
		r2 := s[len(s)-i-1]
		if r1 != r2 {
			ans++
		}
	}

	fmt.Fprintln(wr, ans)
}

// -----------------------------------------

const (
	inf = 1 << 60
	// mod = 1000000007
)

var (
	sc = bufio.NewScanner(os.Stdin)
	wr = bufio.NewWriter(os.Stdout)
)

func main() {
	maxBufSize := int(1e8)
	sc.Buffer(make([]byte, 4096), maxBufSize)
	sc.Split(bufio.ScanWords)
	solve()
	wr.Flush()
}

func getInt() (ret int) {
	sc.Scan()
	ret, err := strconv.Atoi(sc.Text())
	if err != nil {
		panic(err)
	}
	return
}

func getIntSlice(n int) (ret []int) {
	ret = make([]int, n)
	for i := range ret {
		ret[i] = getInt()
	}
	return
}

func getString() (ret string) {
	sc.Scan()
	ret = sc.Text()
	return
}

func getRunes() (ret []rune) {
	ret = []rune(getString())
	return
}
//  [go]
package main

import (
	"fmt"
)

func main() {
	var word string
	fmt.Scan(&word)
	palindromeHugger(word)
}

func palindromeHugger(word string) {
	var incidences int
	wordLenght := len(word)

	for i, letter := range word {
		if letter != rune(word[wordLenght-i]) {
			incidences++
		}

		if i == (wordLenght/2)+1 {
			return
		}
	}

	fmt.Println(incidences)
}
//  [go]
package main

import (
	"fmt"
)

func main() {
	var word string
	fmt.Scan(&word)
	palindromeHugger(word)
}

func palindromeHugger(word string) {
	var incidences int
	wordLenght := (len(word) / 2) + 1

	for i, letter := range word {
		if letter != rune(word[wordLenght-i]) {
			incidences++
		}
	}

	fmt.Println(incidences)
}
//  [go]
package main

import (
	"fmt"
)

func main() {
	var word string
	fmt.Scan(&word)
	palindromeHugger(word)
}

func palindromeHugger(word string) {
	var incidences int
	wordLenght := len(word) / 2

	for i, letter := range word {
		if letter != rune(word[wordLenght-i]) {
			incidences++
		}
	}

	fmt.Println(incidences)
}
//  [ruby]
S = gets.chomp
p (0...S.size/2).inject(0){ |sum, i| sum += S[i] == S.reverse[i] ? 0 : 1}
//  [ruby]
s = gets.chomp
cnt = 0
for i in 0..(s.length)/2-1 do
  if s[i]!= s[s.length-1-i] then
    cnt += 1
  end
end
puts(cnt)
//  [ruby]
S=gets.chomp.to_s.chars
count=0

sublength=S.length/2.floor

a=S.shift(sublength)
b=S.pop(sublength).reverse

sublength.times{|n|
    if a[n-1]!=b[n-1]
        count+=1
    end
}

puts count
//  [ruby]
n=gets.chomp
s=n.reverse
ans=0
for i in 0..((n.size+1)/2)-1
  ans+=1 if n[n]!=s[n]
end
puts ans
//  [ruby]
S=gets.chars
N=S.size/2

count = 0
N.times{|i|
  count+=1 if S[i] != S[-i-1]
}

p count
//  [ruby]
S=gets.chars
N=S.size/2

s1,s2=S[0...N],S[-N..-1].reverse

count = 0
N.times{|i|
  count+=1 if s1[i] != s2[i]
}

p count