jiahuimbzuai/CoQuIR huggingface dataset:
//  [rust]

#[allow(unused_macros)]
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

#[allow(unused_macros)]
macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

    ($next:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
}

#[allow(unused_macros)]
macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };

    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };

    ($next:expr, usize1) => {
        read_value!($next, usize) - 1
    };

    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}

#[allow(unused_macros)]
macro_rules! debug {
    ($($a:expr),*) => {
        eprintln!(concat!($(stringify!($a), " = {:?}, "),*), $($a),*);
    }
}

use std::iter::Iterator;

fn main() {

    input!{
       R:usize,
    }

    let mut S = "";

    if R < 1200 {
        S = "ABC"
    }else if  1200 <= R && R < 2800 {
        S = "ARC"
    }else{
        S = "AGC"
    }

    println!("{}", S);

}
//  [rust]
def main():
    r = (int)(input())
    if r < 1200:
        print("ABC")
    elif r >= 1200 and r < 2800:
        print("ARC")
    else:
        print("ARC")

main()
//  [rust]
#[allow(unused_macros)]
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

    ($next:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
}

macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };

    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };

    ($next:expr, usize1) => {
        read_value!($next, usize) - 1
    };

    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}

fn func(i: usize, g: i32, v: &std::vec::Vec<(i32, i32)>) -> Option<i32> {
    if i == 0 {
        // println!("g = {}", g);
        return if g <= 0 { Some(0) } else { None };
    }
    let (p, c) = v[i - 1];
    let mut res = std::vec::Vec::with_capacity((p + 1) as usize);
    for j in 0..(p + 1) {
        // print!("i = {}, j = {}, ", i, j);
        if j == 0 {
            res.push((j, func(i - 1, g, v)));
        } else if 1 <= j && j < p {
            res.push((j, func(i - 1, g - 100 * (i as i32) * j, v)));
        } else {
            res.push((j, func(i - 1, g - 100 * (i as i32) * j - c, v)));
        }
    }
    let r = res.into_iter().flat_map(|(j, r)| r.map(|x| x + j)).min();
    // println!("{:?}", r);
    r
}

fn main() {
    input! {
        d: usize,
        g: i32,
        v: [(i32, i32); d],
    }
    let res = func(d, g, &v).unwrap();
    println!("{}", res);
}
//  [rust]
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)*}
    };
}

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)*}
    };
}

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")
    };
}
fn main() {
    input! {
        R: i32,
    }

    println!(
        "{}",
        if R < 1200 {
            "ABC"
        } else if R < 2400 {
            "ARC"
        } else {
            "AGC"
        }
    );
}
//  [swift]
switch Int(readLine()!)!{case 0..<1200:print("ABC");case 1200..<2800:print("ARC");default:print("AGC")}
//  [swift]
var input:String? = readLine()
var numString:String = input!
var num = Int(numString)

if num < 1200{
  print("ABC")
}else if num<2800{
  print("ARC")
}else {
  print("AGC")
}
//  [swift]
let R=Int(readLine()!)!
if R<1200{
  print("ABC")
}
else if R<2800{
  print("ARC")
}
else{
  print("AGC")
}
//  [swift]
print(switch Int(readLine()!)!{case 0..<1200:"ABC";case 1200..<2800:"ARC";default:"AGC"})
//  [swift]

var r = R
if r < 1200 {
    print("ABC")
} else if r < 2800 {
    print("ARC")
} else {
    print("AGC")
}
//  [swift]
var input:String? = readLine()
var numstring:String = input!
var num = Int(input)

if num < 1200{
  print("ABC")
}else if num<2800{
  print("ARC")
}else {
  print("AGC")
}
//  [typescript]
const main = (input) => {
  input = input.split(' ');
  const a = parseInt(input[0], 10);
  
  if (a<1200) {
    console.log("ABC");
  }else if (a<2800) {
    console.log("ARC");
  }else{
    console.log("AGC");
  }
}
main(require('fs').readFileSync('/dev/stdin', 'utf8'));
//  [typescript]
declare var require: (x: string) => any;

function Main(input: string[]) {
  const r = parseInt(input[0]);

  console.log((r < 1200) ? 'ABC' : (r < 2800) ? 'ARC' : 'AGC');
}

Main(require('fs').readFileSync('/dev/stdin', 'utf8').split('\n'));
//  [typescript]
const stdin = require('fs').readFileSync('/dev/stdin', 'utf8')

const _r = stdin.split('\n')[0]

const r = Number(_r)

let res = 'AGC'
if (r < 1200) {
  res = 'ABC'
} else if (r < 2800) {
  res = 'ARC'
}

console.log(res)
//  [typescript]
st main = (input) => {
  input = input.trim();
  const a = parseInt(input[0], 10);
  
  if (a<1200) {
    console.log("ABC");
  }else if (a<1200&&a<2800) {
    console.log("ARC");
  }else{
    console.log("AGC");
  }
}
main(require('fs').readFileSync('/dev/stdin', 'utf8'));
//  [typescript]
const main = (input) => {
  const a = parseInt(input[0], 10);
  
  if (a<1200) {
    console.log("ABC");
  }else if (a<1200&&a<2800) {
    console.log("ARC");
  }else{
    console.log("AGC");
  }
}
main(require('fs').readFileSync('/dev/stdin', 'utf8'));
//  [typescript]
const main = (input) => {
  input = input.split('');
  const a = parseInt(input[0], 10);
  
  if (a<1200) {
    console.log("ABC");
  }else if (a<1200&&a<2800) {
    console.log("ARC");
  }else{
    console.log("AGC");
  }
}
main(require('fs').readFileSync('/dev/stdin', 'utf8'));
//  [python]
X, K, D = [abs(int(i)) for i in input().strip().split(' ')]

tmp = X // D
d1 = X - (D * tmp)
d2 = X - (D * (tmp + 1))

if tmp >= K:
  ans = X - (D * K)
else:
  if (tmp % 2) ^ (K % 2) == 0:
    ans = d1
  else:
    ans = d2

print(abs(ans))
//  [python]
X,K,D=map(int,input().split())
X=abs(X)
s=X//D
if s>=K:
  print(X-(D*K))
  exit()
n=K-s
n=n%2
if n==0:
  print(X-(D*s))
  exit()
else:
  print(abs(X-(D*s)-D))
  exit()
//  [python]
X,K,D=map(int,input().split())
X=abs(X)
if K*D<X:
    print(X-K*D)
else:
    K-=X//D
    X%=D
    if K%2==0:
        print(X)
    else:
        print(D-X)
//  [python]
X,K,D = map(int,input().split())

if X%2 == K%2==0:
    print(X)
elif X%2 != 0 and K%2==0:
    print(abs(X-(K//2)*D))
else:
    print(abs(X-((K//2)+1)*D))
//  [python]
X,K,D = map(int,input().split())

if K%2==0:
    print(abs(X-(K//2)*D))
else:
    print(abs(X-((K//2)+1)*D))
//  [python]
x,k,d=list(map(int,input().split()))
b=100000000000
for i in range(1,k+1):
  a=abs(x-k*d+8*i)
  b=min(b,a)
print(b)
//  [java]
import java.io.*;
import java.util.*;

public class Main {
    public static void main(final String[] args) {
        final FastReader s=new FastReader();
        long x = Math.abs(s.nextLong());
        long k = s.nextLong();
        long d = s.nextLong();
        
        long min = x/d;
        
        if(min>k){
            System.out.println(x-(k*d));
            return;
        }
        k=k-(x/d);
        x=x-(d*(x/d));

        if(k%2!=0) x = d-x;

        System.out.println(x);

    }

    static class FastReader
    {
        BufferedReader br;
        StringTokenizer st;
        public FastReader() { br = new BufferedReader(new InputStreamReader(System.in)); }
        String next() {
            while (st == null || !st.hasMoreElements()) {
                try { st = new StringTokenizer(br.readLine()); }
                catch (final 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 (final IOException e) { e.printStackTrace(); }
            return str;
        }
    }
}
//  [java]

import java.util.Scanner;

/**
 * Created by enpingkuang on 2020/9/20 11:36 下午
 */
public class Main {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        long x = scanner.nextLong();
        long k = scanner.nextLong();
        long d = scanner.nextLong();
        x = Math.abs(x);
        long n = x/d;
        if(n > k){
            System.out.println(x-k*d);
        }else{
            long tmp = k - n;
            if(tmp % 2 == 1){
                System.out.println(x - (n-1)*d);
            }else{
                System.out.println(Math.abs(x-n*d));
            }
        }
    }
}
//  [java]

import java.util.Scanner;

/**
 * Created by enpingkuang on 2020/9/20 11:36 下午
 */
public class Main {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        long x = scanner.nextLong();
        long k = scanner.nextLong();
        long d = scanner.nextLong();
        long ans = 0;
        if(x <= 0){
            long n = -x/d;
            if(x%d !=0)n++;
            if(n > k){
                ans = Math.abs(x+k*d);
            }else{
                if((k - n)%2 == 0){
                    ans = Math.abs(x+n*d);
                }else{
                    ans = Math.abs(x+(n-1)*d);
                }
            }
        }else{
            long n = x/d;
            if(x%d !=0)n++;
            if(n > k){
                ans = Math.abs(x-k*d);
            }else{
                if((k - n)%2 == 0){
                    ans = x-n*d;
                }else{
                    ans = Math.abs(x-(n-1)*d);
                }
            }
        }
        System.out.println(ans);
    }
}
//  [java]
import java.util.*;
public class Main {
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        String s = sc.nextLine();
        String x_k_d [] = s.split(" ", -1);
        long x = Long.parseLong(x_k_d[0]);
        long k = Long.parseLong(x_k_d[1]);
        long d = Long.parseLong(x_k_d[2]);
        
        //移動した後の位置pos、残り移動回数a
        long pos = x;
        long a = k;
        long b = 0;
        long c = 0;

        //出力は絶対値なのでposを正にして計算する
        if(x < 0){
            pos *= -1;
        }
        //0に近づけるように移動させる
        if(x / d < k){
            a -= pos /d;
            pos = pos % d;
            
        }else{
            a = 0;
            pos -= d * k;
        }
        //System.out.println(pos);
        //System.out.println(a);
        
        if(a == 0){
            System.out.println(pos);
        }else{
            b = pos;
            c = (pos - d) * -1;
            if(a % 2 == 0){
                System.out.println(b);
            }else if(a % 2 == 1){
                System.out.println(c);
            }
        }
    }
}
//  [cpp]
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef unsigned long long int llu;
typedef long double ld;
#define vi vector<int>
#define vl vector<ll>
#define vp vector<pair<int,int>>
#define pb push_back
#define pf push_front
#define mp map<ll,ll>
#define INF 1000000000000000000
#define fast ios_base::sync_with_stdio(false);cin.tie(NULL);
ll gcd(ll a,ll b)
{
    if(a==0)
    {
        return b;
    }
    else
    {
        return gcd(b%a,a);   
    }
}
ll lcm(ll a,ll b)
{
    return a*b/gcd(a,b);
}
int f(char c)
{
    return (int)c-96;
}
/**********************************************************************
***********************************************************************
*********************ACTUAL CODE BEGINS HERE***************************/
int main()
{   
    fast;
    ll x,k,d;
    cin>>x>>k>>d;
    x=abs(x);
    if(k<=(x/d))
        cout<<x-(k*d);
    else
    {
        k-=x/d;
        if(k%2)
            cout<<abs((x%d)-d);
        else
        {
            cout<<x%d;
        }
        
    }
    return 0;
}
//  [cpp]
#include "bits/stdc++.h"

using namespace std;
int main() {
	long long X, K, D;
	cin >> X >> K >> D;
	if (X < 0) {
		X = -X;
	}
	long long count = X / D;
	if (count >= K) {
		cout << X - K * D << endl;
		return 0;
	}
	if (1 == K%2) {
		long long x = X + D;
		cout << min(x % (2 * D), abs(2 * D - x % (2 * D))) << endl;
	}
	else {
		cout << min(X % (2 * D), abs(2 * D - X % (2 * D))) << endl;
	}
	return 0;
}
//  [cpp]
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
using P = pair<int,int>;

int main(){
	ll x,k,d;
	cin >> x >> k >> d;
	x = abs(x);
	ll ans = 0;
	if(x/d >= k){
		ans = x - d*k;
	}
	else{
		ll e = x/d;
		k -= e;
		x -= e*d;
		if(k%2 == 1) x = abs(x - d);
		ans = x;
	}
	cout << ans << endl;
}
//  [cpp]
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> l_l;
typedef pair<int, int> i_i;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
// #define debug(a) cout << "["; rep(i,a.size()) cout << a[i] << ", "; cout<<"]"<< endl;

const ll mod = 1000000007;

int main() {
    ll x, k, d; cin >> x >> k >> d;
    ll mostCloseX = x % d;
    ll needMove = abs(x % d - x) / d;
    if(needMove >= k) {
        if(x < 0){
            cout << x + d * k << endl;
        } else {
            cout << x - d * k << endl;
        }
        return 0;
    }
    ll leftMove = k - needMove;
    if(leftMove % 2 == 0){
        cout << abs(mostCloseX) << endl;
    } else {
        cout << min(abs(mostCloseX + d), abs(mostCloseX - d)) << endl;
    }
    return 0;
}
//  [cpp]
#include<bits/stdc++.h>

#define ntest 0

using namespace std;
long long x,k,d;
void solve()
{
    cin >> x >> k >> d;
    x = abs(x);
    if (x - k * d > 0)
    {
        cout << x - k * d;
    }
    else
    {
        long long tmpk = min(k,x / d);
        long long remain = k - tmpk;
        if (remain&1) cout << (tmpk+1)*d - x;
        else cout << x - tmpk * d;
    }

}
int main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
    if(ntest)
    {
        int t;
        cin >> t;
        while(t--) solve();
    }
    else
    {
        solve();
    }

}
//  [cpp]
#include <bits/stdc++.h>
using namespace std;
using ll=long long;

int main(){
    ll x, k, d;
    cin >> x >> k >> d;
    ll a;
    
    if((x>0 && x-k*d>=0) || (x<0 && x-k*d<=0)){
        cout << abs(x-k*d) << endl;
    }else{
        a=x/d-x%d;
        x%=d;
        x=(x+d)%d;
        if(abs(x)<abs(x-d)){
            cout << abs(x) << endl;
        }else{
            cout << abs(x-d) << endl;
        }
    }

    return 0;
}
//  [c]
#include <stdio.h>
#include <stdlib.h>
 
int main(void) {
  long long int x, k, d;
  long long int q, r;
  scanf("%lld%lld%lld", &x, &k, &d);
  
  x = llabs(x);
  d = llabs(d);
  
  q = x/d;
  r = x%d;
  
  if (k <= q) {
    printf("%lld", x - d*k);
    return 0;
  }
  
  if ((k-q)%2==0) {
    printf("%lld", r);
    return 0;
  }
  
  if ((k-q)%2!=0) {
    printf("%lld", d-r);
    return 0;
  }
}
//  [c]
#include <stdio.h>

int main(){
  long long int X,K,D;
  scanf("%lld %lld %lld",&X,&K,&D);
  if(X<0LL) X=-X;
  if(X/D>=K) X-=K*D;
  else{
    long long int Y=X/D;
    K-=Y;
    X-=Y*D;
    if(K%2LL==1LL) X=D-X;
  }
  printf("%lld\n",X);
  return 0;
}
//  [c]
#include <stdio.h>

long long abs(long long A);
int main(void)
{
    long long X,K,D,M,q,r,ans=0;
    scanf("%lld %lld %lld",&X,&K,&D);
    X=abs(X);
    D=abs(D);
    q=X/D;
    r=X%D;

    M=K-q;

    if(M<=0){
        ans=X-K*D;
        // printf("A");
    } else {
        if(M%2==0){
            ans=X%D;
            // printf("B");
        } else {
            ans=abs(D-X%D);
            // printf("C");
        }
    }
    printf("%lld",ans);
    return 0;
}

long long abs(long long A)
{
    if(A<0) A=(-1)*A;
    return A;
}
//  [c]
#include <stdio.h>
#define abs(x) ((x > 0) ? x : -x)

int	main(void)
{
	long	X, K, D;
	int		i, j, sign = 1;

	scanf("%ld %ld %ld", &X, &K, &D);
	if (X < 0)
		sign = -1;
	i = (abs(X) + D - 1) / D;
	if (i > K)
		X -= sign * D * K;
	else
	{
		X -= sign * D * i;
		if (i < K && (K - i) % 2)
			X += sign * D;
	}
	printf("%ld\n", abs(X));
	return (0);
}
//  [c]
#include<stdio.h>
#pragma GCC optimize("Ofast")
int main(void){
  long long X,K,D;
  scanf("%lld%lld%lld",&X,&K,&D);
  long long i;
  long long j=0;
  for(i=1;i<=K;i++){
    if(X-D>=0)
      X = X - D;
    else{
      j = K - i;
      break;
    }
  }
  unsigned long long k=X;
  for(long long l=1;l<=j;l++){
    if(l % 2 == 1)
      k = k - D;
    else
      k = k + D;
  }
  printf("%lld",k);
  return 0;
}
//  [c]
#include <stdio.h>
#define abs(x) ((x > 0) ? x : -x)

int	main(void)
{
	long	X, K, D, i = 0;
	int		sign = 1;

	scanf("%ld %ld %ld", &X, &K, &D);
	if (X < 0)
		sign = -1;
	while (sign * X > 0 && i < K)
	{
		X -= sign * D;
		i++;
	}
	if ((K - i) % 2)
		X += sign * D;
	printf("%ld\n", abs(X));
	return (0);
}
//  [javascript]
const { SSL_OP_SSLEAY_080_CLIENT_DH_BUG } = require("constants");

function Main(input) {
  input = input.split("\n");
  var ans =0;
  var X = parseInt(input[0].split(" ")[0]);
  var K = parseInt(input[0].split(" ")[1]);
  var D = parseInt(input[0].split(" ")[2]);
  if(X<0){
    X=-X;
  }
  if(X==0){
    if(D%2==0){
      ans=0;
    }else{
      ans=K;
    }
  }else if(X>K*D){
    ans=X-K*D;
  }else{
    var a = Math.floor(X/D);
    var b = X%D;
    if((K-a)%2==0){
      ans=b;
    }else{
      ans=D-b;
    }
  }


  console.log('%s', ans);
  return ans;
}

function debug(n){
  var input = document.getElementById("input"+n).value;
  var ans=Main(input);
  var result="WA";
  if(ans==document.getElementById("output"+n).value.split("\n")[0]){
    result="AC";
  }
  document.getElementById("result"+n).innerHTML=result;
}
Main(require("fs").readFileSync("/dev/stdin", "utf8"));
//  [javascript]
function Main(input) {
	const row = input.split(" ");
	const X = parseInt(row[0], 10);
	const K = parseInt(row[1], 10);
	const D = parseInt(row[2], 10);
	const even = num => num % 2 === 0;
	const av_x = X < 0 ? X * -1 : X;
	const cnt = av_x / D;

	if(cnt >= K) {
		console.log(av_x - K * D);
	} else {
		if(even(K - Math.floor(cnt))){
			console.log(av_x - D * Math.floor(cnt));
		} else {
			console.log(D * (Math.floor(cnt) + 1) - av_x);
		}
	}
};

Main(require("fs").readFileSync("/dev/stdin", "utf8"));
//  [javascript]
const input = require("fs").readFileSync("/dev/stdin", "utf8")
const lines = input.split('\n')
let [X, K, D] = lines[0].split(' ').map(Number)

X = Math.abs(X)
const div = Math.min(Math.floor(X / D), K)
let x = X - div * D
let k = K - div
for (let i = 0; i < k; i++) {
    x -= D
    if (x <= 0) {
        if (!((k - i) % 2)) {
            x += D
        }
        break
    }
}
console.log(Math.abs(x))
//  [javascript]
function Main(input) {
  const row = input.split(" ");
    	let X = parseInt(row[0], 10);
    	let K = parseInt(row[1], 10);
    	const D = parseInt(row[2], 10);
    let absX = Math.abs(X);
    let a = Math.floor(absX / D);
    let ans;

    if((absX /D) >= K) {
       ans = absX - D * K;

    } else {
       K2 = K - a;
       absX = absX - K2 * D;
       if(K2 % 2 === 1) {
    　ans = absX - D;
      } else {
         ans = absX;
      }
    } console.log(Math.abs(ans));
}

Main(require("fs").readFileSync("/dev/stdin", "utf8"));
//  [javascript]
function Main(input) {
  const row = input.split(" ");
    	let X = parseInt(row[0], 10);
    	let K = parseInt(row[1], 10);
    	const D = parseInt(row[2], 10);
    let absX = Math.abs(X);
    let a = Math.floor(absX / D);
    let ans;

    // if((absX /D) >= K) {
    //    ans = absX - D * K;
    //
    // } else {
    //    K2 = K - a;
    //    absX = absX - K2 * D;
    //    if(K2 % 2 === 1) {
    // 　ans = absX - D;
    //   } else {
    //      ans = absX;
    //   }
    // } console.log(Math.abs(ans));
}

Main(require("fs").readFileSync("/dev/stdin", "utf8"));
//  [javascript]
function Main(input) {
  const row = input.split(" ");
    	let X = parseInt(row[0], 10);
    	let K = parseInt(row[1], 10);
    	const D = parseInt(row[2], 10);
    let absX = Math.abs(X);
    let a = absX / D;
    let ans;
    if(X == D && K % 2 === 0){
      ans = X;

    } else {
    if((absX /D) >= K) {
       ans = absX - D * K;

    } else {
       K2 = K - a;
       absX = absX - K2 * D;
       if(K2 % 2 === 1) {
    　ans = absX - D;
      } else {
         ans = absX;
      }
    }
    } console.log(Math.abs(ans));
}

Main(require("fs").readFileSync("/dev/stdin", "utf8"));
//  [go]
package main

import (
	"fmt"
)

func main() {

	var x, k, d int64
	fmt.Scan(&x, &k, &d)
	if x < 0 {
		x = -x
	}
	n := x / d

	t1 := x % d
	t2 := t1 -d

	var ans int64

	if k <= n {
		ans = x - k * d
	} else {
		if (k-n) % 2 == 0 {
			ans = t1
		} else {
			ans = -t2
		}
	}
	fmt.Println(ans)
}
//  [go]
package main

import (
	"fmt"
)

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


	if x == 0 {
		if k % 2 == 0 {
			fmt.Println(0)
			return
		}
		fmt.Println(d)
		return
	}
	x = abs(x)
	ans := x % d
	a := x / d
	if a > k {
		// 往復に辿り着く前に終る
		fmt.Println(x - k * d)
		return
	} else if a <= k  {
		// 往復する
		if (k - a) % 2 == 0 {
			fmt.Println(ans)
			return
		} else if (k-a) % 2 == 1 {
			if ans > 0 {
				ans -= d
			} else {
				ans += d
			}
			fmt.Println(abs(ans))
			return
		}
	}
}

func abs(n int) int {
	y := n >> 63
	return (n ^ y) - y
}
//  [go]
package main

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

var (
	// ReadString returns a WORD string.
	ReadString func() string
)

func init() {
	ReadString = newReadString(os.Stdin, bufio.ScanWords)
}

func newReadString(ior io.Reader, sf bufio.SplitFunc) func() string {
	r := bufio.NewScanner(ior)
	r.Buffer(make([]byte, 1024), int(1e+9)) // for Codeforces
	r.Split(sf)

	return func() string {
		if !r.Scan() {
			panic("Scan failed")
		}
		return r.Text()
	}
}

func readInt64() int64 {
	n, _ := strconv.ParseInt(ReadString(), 10, 64)
	return n
}

func readInt() int {
	return int(readInt64())
}

// 10 11 12 => [10, 11, 12]
func readIntSlice(size int) []int {
	a := make([]int, size)
	for i := 0; i < size; i++ {
		a[i] = readInt()
	}
	return a
}

func get2byte(size int) [][]byte {
	a := make([][]byte, size)
	for i := 0; i < size; i++ {
		var low string
		fmt.Scan(&low)
		a[i] = []byte(low)
	}
	return a
}

func transpose(a [][]int) {
	n := len(a)
	for i := 0; i < n; i++ {
		for j := i + 1; j < n; j++ {
			a[i][j], a[j][i] = a[j][i], a[i][j]
		}
	}
}

func fact(n, m int) int {
	res := 1
	for i := m + 1; i <= n; i++ {
		res *= i
	}
	return res
}

func perm(n, r int) int {
	if r > n {
		return 0
	}
	return fact(n, n-r)
}

func comb(n, m int) int {
	if m > n {
		return 0
	}
	return fact(n, n-m) / fact(m, 0)
}

func reverse(s string) string {
	runes := []rune(s)
	for i, j := 0, len(runes)-1; i < j; i, j = i+1, j-1 {
		runes[i], runes[j] = runes[j], runes[i]
	}
	return string(runes)
}

func min(integers ...int) int {
	m := integers[0]
	for i, integer := range integers {
		if i == 0 {
			continue
		}
		if m > integer {
			m = integer
		}
	}
	return m
}

func min64(integers ...int64) int64 {
	m := integers[0]
	for i, integer := range integers {
		if i == 0 {
			continue
		}
		if m > integer {
			m = integer
		}
	}
	return m
}

func max(integers ...int) int {
	m := integers[0]
	for i, integer := range integers {
		if i == 0 {
			continue
		}
		if m < integer {
			m = integer
		}
	}
	return m
}

func main() {
	x, k, d := readInt64(), readInt64(), readInt64()
	fmt.Println(solve(x, k, d))
}

func solve(x, k, d int64) int64 {
	np := (k - x/d) / 2
	nm := (k + x/d) / 2
	if np < 0 {
		return int64(math.Abs(float64(x - k*d)))
	} else if nm < 0 {
		return int64(math.Abs(float64(x + k*d)))
	}
	var res []int64
	for i := -1; i <= 1; i++ {
		xp := np + int64(i)
		if xp < 0 {
			continue
		}
		xm := k - xp

		if xm < 0 {
			continue
		}
		res = append(res, int64(math.Abs(float64(x+(xp-xm)*d))))
	}
	for i := -1; i <= 1; i++ {
		xm := nm + int64(i)
		if xm < 0 {
			continue
		}
		xp := k - xm
		if xp < 0 {
			continue
		}
		res = append(res, int64(math.Abs(float64(x+(xp-xm)*d))))
	}
	return min64(res...)
}
//  [go]
package main

import ("fmt")

func main() {
  
  var(
    X,K,D,i int
  )
  fmt.Scan(&X,&K,&D)
  if D<0{
    var d = -D
  }else{var d=D}
  
  for i:=0; i < K;i++{
  
    
    if X >= 0{X = X - d}else{X = X + d}
  
    
  }
  if X<0 {var x=-X}else{var x=X}
    print(x)
}
//  [go]
package main

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

const (
	initialBufSize = 100000
	maxBufSize     = 10000000
)

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

func next() string {
	sc.Scan()
	return sc.Text()
}

func nextInt() int64 {
	i, _ := strconv.Atoi(next())
	return int64(i)
}

func nextInt3() (int64, int64, int64) {
	return nextInt(), nextInt(), nextInt()
}

func puts(a ...interface{}) {
	fmt.Fprintln(wt, a...)
}

func abs(x int64) int64 {
	if x < 0 {
		return -x
	}
	return x
}

func main() {
	sc.Split(bufio.ScanWords)
	sc.Buffer(make([]byte, initialBufSize), maxBufSize)
	defer wt.Flush()

	x, k, d := nextInt3()
	x = abs(x)

	var ans int64
	if x >= d*k {
		ans = x - d*k
		puts(ans)
		return
	}

	y := x / d
	k -= y
	x -= y * d
	if k%2 == 0 {
		ans = x
	} else {
		ans = d - x
	}
	puts(ans)
}
//  [go]
package main

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

const (
	initialBufSize = 100000
	maxBufSize     = 10000000
)

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

func next() string {
	sc.Scan()
	return sc.Text()
}

func nextInt() int {
	i, _ := strconv.Atoi(next())
	return i
}

func nextInt3() (int, int, int) {
	return nextInt(), nextInt(), nextInt()
}

func puts(a ...interface{}) {
	fmt.Fprintln(wt, a...)
}

func abs(x int) int {
	if x < 0 {
		return -x
	}
	return x
}

func main() {
	sc.Split(bufio.ScanWords)
	sc.Buffer(make([]byte, initialBufSize), maxBufSize)
	defer wt.Flush()

	x, k, d := nextInt3()
	x = abs(x)

	var ans int
	if x >= d*k {
		ans = x - d*k
		puts(ans)
		return
	}

	y := x / d
	k -= y
	x -= y * d
	if k%2 == 0 {
		ans = x
	} else {
		ans = d - x
	}
	puts(ans)
}
//  [ruby]
x, k, d = gets.split(" ").map &:to_i
if (k*d) <= x.abs
  puts x.abs - k*d
  exit
end
l = x.abs/d
if (k - l)%2 == 1
  puts (x.abs - l*d -d).abs
else
  puts x.abs - l*d
end
//  [ruby]
x,k,d = gets.chomp.split.map(&:to_i)
abso = x.abs 
min = abso/d 
if min >= k 
  puts abso - k*d 
elsif (k - min).odd?
  puts (abso - (min + 1)*d).abs 
else 
  puts abso%d
end
//  [ruby]
x, k, d = gets.split(" ").map(&:to_i)
if x.abs >= k * d
  puts x.abs - (k * d)
  exit
end
xx=0
yy=1
flag=false
before_0 = x / d 
if (k - before_0) % 2 == 0
  puts (x - (before_0 * d)).abs
  flag=true
  yy+=1
else (k - before_0) % 2 != 0
  puts  (x - (before_0 * d) - d).abs
  flag=false
  xx+=1
end
//  [ruby]
x, k, d = gets.split(" ").map &:to_i
if (k*d) <= x.abs
  puts x.abs - k*d
  exit
end
l = x.abs/d
if (k - l)%2 == 1
  puts (x.abs - (k-l)*d -d).abs  
else
  puts x.abs - (k-l)*d
end
//  [ruby]
x,k,d = gets.chomp.split(' ').map(&:to_i)
all = [[x]]
# p all[0]
# p all[0][0]
min = x
i = 0
while i < k
  a = []
  j = 0
  while j < all[i].size
    a << (all[i][j]+d) if (all[i][j]+d).abs < min
    a << (all[i][j]-d) if (all[i][j]-d).abs < min
    min = all[i][j]+d if (all[i][j]+d).abs < min
    min = all[i][j]-d if (all[i][j]-d).abs < min
    # a << (all[i][j]+d)
    # a << (all[i][j]-d)
    j += 1
  end
  all << a
  i += 1
end
p min
//  [ruby]
x,k,d = gets.chomp.split(' ').map(&:to_i)
all = [[x]]
# p all[0]
# p all[0][0]
min = x
i = 0
while i < k
  a = []
  j = 0
  while j < all[i].size
    min = all[i][j]+d if (all[i][j]+d).abs < min
    min = all[i][j]-d if (all[i][j]-d).abs < min
    a << (all[i][j]+d)
    a << (all[i][j]-d)
    j += 1
  end
  all << a
  i += 1
end

p min
//  [rust]
fn input_line() -> Vec<String> {
  let mut buf = String::new();
  std::io::stdin().read_line(&mut buf).unwrap();
  return buf
    .split_whitespace()
    .map(|word| String::from(word))
    .collect();
}

fn main() {
  let inputs = input_line();
  let x: i64 = inputs[0].parse().unwrap();
  let k: i64 = inputs[1].parse().unwrap();
  let d: i64 = inputs[2].parse().unwrap();

  let plus_x = if x < 0 {
    -x
  } else {
    x
  };

  let x_per_d = plus_x / d;

  let ans = if k <= x_per_d {
    plus_x - d * k
  } else {
    let x_mod_d = plus_x % d;

    if (k - x_per_d) % 2 == 0 {
      x_mod_d
    } else {
      -(x_mod_d - d)
    }
  };

  println!("{}", ans);
}
//  [rust]
fn main(){
 proconio::input!{mut x:i64,mut k:i64,d:i64};
 let mut x=x.abs();
 let s=k.min(x/d);
 k-=s;
 x-=s*d;
 let ans=if k%2==0{x}else{d-x};
 println!("{}",ans);
}
//  [rust]
#[allow(unused_imports)]
use std::cmp::*;
#[allow(unused_imports)]
use std::collections::*;
use std::io::{Write, BufWriter};
// https://qiita.com/tanakh/items/0ba42c7ca36cd29d0ac8
macro_rules! input {
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};
    ($next:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
}

macro_rules! read_value {
    ($next:expr, [graph1; $len:expr]) => {{
        let mut g = vec![vec![]; $len];
        let ab = read_value!($next, [(usize1, usize1)]);
        for (a, b) in ab {
            g[a].push(b);
            g[b].push(a);
        }
        g
    }};
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };
    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };
    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };
    ($next:expr, usize1) => (read_value!($next, usize) - 1);
    ($next:expr, [ $t:tt ]) => {{
        let len = read_value!($next, usize);
        read_value!($next, [$t; len])
    }};
    ($next:expr, $t:ty) => ($next().parse::<$t>().expect("Parse error"));
}

#[allow(unused)]
macro_rules! debug {
    ($($format:tt)*) => (write!(std::io::stderr(), $($format)*).unwrap());
}
#[allow(unused)]
macro_rules! debugln {
    ($($format:tt)*) => (writeln!(std::io::stderr(), $($format)*).unwrap());
}

fn solve() {
    let out = std::io::stdout();
    let mut out = BufWriter::new(out.lock());
    macro_rules! puts {
        ($($format:tt)*) => (let _ = write!(out,$($format)*););
    }
    input! {
        x: i64, k: i64, d: i64,
    }
    let mut x = x.abs();
    if k % 2 == 1 {
        x = (x - d).abs()
    }
    let q = min(k / 2, x / (2 * d));
    let q1 = min(k / 2, x / (2 * d) + 1);
    puts!("{}\n", min((x - q * 2 * d).abs(), (x - q1 * 2 * d).abs()));
}

fn main() {
    // In order to avoid potential stack overflow, spawn a new thread.
    let stack_size = 104_857_600; // 100 MB
    let thd = std::thread::Builder::new().stack_size(stack_size);
    thd.spawn(|| solve()).unwrap().join().unwrap();
}
//  [rust]
use proconio::{input, fastout};
use std::cmp::{min};

#[fastout]
fn main() {
    input! {
        x: isize,
        k: isize,
        d: isize
    }

    let a = k - min(x / d, k);
    let b = x - (min(x / d, k) * d);
    if a % 2 == 0 {
        println!("{}", b.abs());
    }else{
        println!("{}", (b - d).abs());
    }

}
//  [swift]
struct Scanner {
    private var elements = [String]()
    private var index = 0

    mutating func peek() -> String {
        while elements.count == index {
            elements = readLine()!.split(separator: " ").map(String.init)
            index = 0
        }
        return elements[index]
    }

    mutating func next() -> String {
        let value = peek()
        index += 1
        return value
    }

    mutating func nextInt() -> Int {
        return Int(next())!
    }

    mutating func nextDouble() -> Double {
        return Double(next())!
    }
}

var scanner = Scanner()
let X = abs(scanner.nextInt())
let K = scanner.nextInt()
let D = scanner.nextInt()

if Double(K) * Double(D) >= 1e18 || X <= K * D {
    let count = X / D
    if count % 2 == K % 2 {
        print(X - D * count)
    } else {
        print(D * (count + 1) - X)
    }
} else {
    print(X - K * D)
}
//  [swift]
let l:[Int] = readLine()!.split(separator:" ").map{Int($0)!}
let x = abs(l[0]), k = l[1], d = l[2]
let m = x % d, n = x / d
print(k<n ? x-d*k : ((k-n)%2 == 0 ? m : d-m))
//  [typescript]
import * as fs from "fs";

// inputで受け取り配列化する
const [X, K, D] = fs.readFileSync("/dev/stdin", "utf8").split(" ").map(Number);

const temp = K * D;

if (temp > Math.abs(X)) {
  const x = Math.abs(X);
  const num = Math.floor(x / D);
  const diff = K - num;
  const ans = Math.min(Math.abs(X - num * D), Math.abs(X + num * D));
  if (diff % 2 === 0) {
    console.log(ans);
  } else {
    console.log(Math.min(Math.abs(ans + D), Math.abs(ans - D)));
  }
} else {
  const ans = Math.abs(X) - temp;
  console.log(ans);
}
//  [typescript]
import { readFileSync } from 'fs'

function main(input: string) {
  let [x, k, d] = input.split(' ').map(Number)
  x = Math.abs(x)

  const count = Math.min(k, Math.floor(x / d))
  const pos = x - count * d

  const result = (k - count) % 2 === 0 ? pos : d - pos

  console.log(result)
}

main(readFileSync('/dev/stdin', 'utf8').trim())
//  [typescript]
import * as fs from "fs";

// inputで受け取り配列化する
const [X, K, D] = fs.readFileSync("/dev/stdin", "utf8").split(" ").map(Number);

const temp = K * D;

if (temp > X) {
  const x = Math.abs(X);
  const num = Math.floor(x / D);
  const diff = K - num;
  const ans = Math.min(Math.abs(X - num * D), Math.abs(X + num * D));
  if (diff % 2 === 0) {
    console.log(ans);
  } else {
    console.log(Math.min(Math.abs(ans + D), Math.abs(ans - D)));
  }
} else {
  console.log(X - temp);
}
//  [typescript]
import * as fs from "fs";

// inputで受け取り配列化する
const [X, K, D] = fs.readFileSync("/dev/stdin", "utf8").split(" ").map(Number);

const temp = K * D;

if (temp > X) {
  const x = Math.abs(X);
  const num = Math.floor(x / D);
  const diff = K - num;
  if (diff % 2 === 0) {
    console.log(Math.abs(x - num * D));
  } else {
    console.log(Math.min(Math.abs(x - num * D + D), Math.abs(x - num * D - D)));
  }
} else {
  console.log(X - temp);
}
//  [typescript]
// C - Walking Takahashi
import { readFileSync } from 'fs';
const input = readFileSync('/dev/stdin', 'utf8');

const [X, K, D] = input.split(' ').map((i) => parseInt(i));

let now = X;

for (let i = 0; i <= Math.log(K); i++) {
  const plus = now + D;
  const minus = now - D;
  if (Math.abs(plus) <= Math.abs(minus)) {
    now = plus;
  } else {
    now = minus;
  }
}

console.log(now);
//  [python]
a=int(input())
b=sorted(map(int,input().split()))
print(b[-1]-b[0])
//  [python]
N = int(input())
x = sorted(map(int,input().split()))
print(abs(x[-1]-x[0]))
//  [python]
N = input()
A=sorted(map(int,input().split()),reverse = True)
s = A[0]-A[-1]
print(s)
//  [python]
n = int(input())
min_A = 10**9+7
max_A = -1
for i in range(n):
  tmp = int(input())
  max_A = max(tmp,max_A)
  min_A = min(min_A,tmp)
  
print(abs(max_A-min_A))
//  [python]
N = int(input())
A = list(map(int, input().split()))

print(max(N) - min(N))
//  [python]
N = int(input())
A = list(map(int, input()).split())

print(max(A) - min(N))
//  [java]
import java.io.IOException;
import java.io.InputStream;
import java.util.Arrays;
import java.util.NoSuchElementException;

public class Main {
	public static void main(String[] args) {
		FastScanner sc = new FastScanner();
		int N = sc.nextInt();
		int min = Integer.MAX_VALUE;
		int max = 0;
		for (int i = 0; i < N; i++) {
			int a = sc.nextInt();
			min = Math.min(min, a);
			max = Math.max(max, a);
		}
		System.out.println(max - min);
	}

	private static class Is {
		int a;
		int b;
		Is (int a, int b) {
			this.a = a;
			this.b = b;
		}
	}

	public static long gcd(long a, long b) {
		long remainder = a % b;
		if (remainder == 0) {
			return b;
		} else {
			return gcd(b, remainder);
		}
	}
}

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());
    }
}
//  [java]
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.StringTokenizer;

public class Main {

	static BufferedReader in;
	static PrintWriter out;
	static StringTokenizer tok;

	void solve() throws IOException {
		int[] a = nia( ni());
		Arrays.sort(a);
		out.println(a[a.length-1]-a[0]);
	}

	String ns() throws IOException {
		while (!tok.hasMoreTokens()) {
			tok = new StringTokenizer(in.readLine(), " ");
		}
		return tok.nextToken();
	}

	int ni() throws IOException {
		return Integer.parseInt(ns());
	}

	long nl() throws IOException {
		return Long.parseLong(ns());
	}

	double nd() throws IOException {
		return Double.parseDouble(ns());
	}

	String[] nsa(int n) throws IOException {
		String[] res = new String[n];
		for (int i = 0; i < n; i++) {
			res[i] = ns();
		}
		return res;
	}

	int[] nia(int n) throws IOException {
		int[] res = new int[n];
		for (int i = 0; i < n; i++) {
			res[i] = ni();
		}
		return res;
	}

	long[] nla(int n) throws IOException {
		long[] res = new long[n];
		for (int i = 0; i < n; i++) {
			res[i] = nl();
		}
		return res;
	}

	public static void main(String[] args) throws IOException {
		in = new BufferedReader(new InputStreamReader(System.in));
		out = new PrintWriter(System.out);
		tok = new StringTokenizer("");
		Main main = new Main();
		main.solve();
		out.close();
	}
}
//  [java]
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int[] numbers = new int[N];
		
		for(int j = 0; j <numbers.length; j++) {
			numbers[j] = sc.nextInt();
		}
		
		int max = numbers[0];
		int min = numbers[0];
		
		for(int i = 1; i < 4; i++ ) {
			if(numbers[i] > max ) {
				max = numbers[i];
			}
			if(numbers[i] < min ) {
				min = numbers[i];
			}
		}
		System.out.println(max-min);
	}

}
//  [java]
import java.util.*; import java.io.*; import java.math.*;
public class Main{
	//Don't have to see. start------------------------------------------
	static class InputIterator{
		ArrayList<String> inputLine = new ArrayList<String>(1024);
		int index = 0; int max; String read;
		InputIterator(){
			BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
			try{
				while((read = br.readLine()) != null){
					inputLine.add(read);
				}
			}catch(IOException e){}
			max = inputLine.size();
		}
		boolean hasNext(){return (index < max);}
		String next(){
			if(hasNext()){
				return inputLine.get(index++);
			}else{
				throw new IndexOutOfBoundsException("There is no more input");
			}
		}
	}
	static HashMap<Integer, String> CONVSTR = new HashMap<Integer, String>();
	static InputIterator ii = new InputIterator();//This class cannot be used in reactive problem.
	static PrintWriter out = new PrintWriter(System.out);
	static void flush(){out.flush();}
	static void myout(Object t){out.println(t);}
	static void myerr(Object t){System.err.print("debug:");System.err.println(t);}
	static String next(){return ii.next();}
	static boolean hasNext(){return ii.hasNext();}
	static int nextInt(){return Integer.parseInt(next());}
	static long nextLong(){return Long.parseLong(next());}
	static double nextDouble(){return Double.parseDouble(next());}
	static ArrayList<String> nextStrArray(){return myconv(next(), 8);}
	static ArrayList<String> nextCharArray(){return myconv(next(), 0);}
	static ArrayList<Integer> nextIntArray(){
		ArrayList<String> input = nextStrArray(); ArrayList<Integer> ret = new ArrayList<Integer>(input.size());
		for(int i = 0; i < input.size(); i++){
			ret.add(Integer.parseInt(input.get(i)));
		}
		return ret;
	}
	static ArrayList<Long> nextLongArray(){
		ArrayList<String> input = nextStrArray(); ArrayList<Long> ret = new ArrayList<Long>(input.size());
		for(int i = 0; i < input.size(); i++){
			ret.add(Long.parseLong(input.get(i)));
		}
		return ret;
	}
	static String myconv(Object list, int no){//only join
		String joinString = CONVSTR.get(no);
		if(list instanceof String[]){
			return String.join(joinString, (String[])list);
		}else if(list instanceof ArrayList){
			return String.join(joinString, (ArrayList)list);
		}else{
			throw new ClassCastException("Don't join");
		}
	}
	static ArrayList<String> myconv(String str, int no){//only split
		String splitString = CONVSTR.get(no);
		return new ArrayList<String>(Arrays.asList(str.split(splitString)));
	}
	public static void main(String[] args){
		CONVSTR.put(8, " "); CONVSTR.put(9, "\n"); CONVSTR.put(0, "");
		solve();flush();
	}
	//Don't have to see. end------------------------------------------
	static void solve(){//Here is the main function
      int N = nextInt();
      ArrayList<Integer> list = new ArrayList<Integer>();
      int max = 0;
      for(int i = 0; i < N - 1; i++){
        for(int j = i + 1; j < N; i++){
          max = Math.max(max, Math.abs(list.get(i) - list.get(j)));
        }
      }
      myout(max);
	}
	//Method addition frame start



	//Method addition frame end
}
//  [cpp]
#include<stdio.h>
#include<algorithm>
using namespace std;
int main()
{
    int n,sum;
    int a[105];
    scanf("%d",&n);
    for(int i=0;i<n;i++)
    {
        scanf("%d",&a[i]);
    }
    sort(a,a+n);
    sum=a[n-1]-a[0];
    printf("%d\n",sum);
    return 0;
}
//  [cpp]
#include "bits/stdc++.h"
using namespace std;

int main(void) {
    int N;
    cin >> N;
    vector<int> A(N);
    for (int i = 0; i < N; ++i) {
        cin >> A[i];
    }
    sort(A.begin(), A.end());
    cout << A[N - 1] - A[0];
    return 0;
}
//  [cpp]
 #include <bits/stdc++.h>
 #include <math.h>
 #include <string>
 using namespace std;
 
 int main(){
    int N;
    int i;
    int A[120];
    int ans = 0;
    int min, max;

    cin >> N;
    for(i=0; i<N; i++)
        cin >> A[i];
    min = A[0];
    max = A[0];

    for(i=1; i<N; i++){
        if (A[i] > max)
            max=A[i];
        if (A[i] < min)
            min=A[i];
        }
    ans = max - min;

    cout << ans << endl;
    return 0;
 }
//  [cpp]
#include <bits/stdc++.h>

using namespace std;

int main() {
    int n;
    vector<int> a(n);
    for (int i = 0; i < n; i++) {
        cin >> a.at(i);
    }
    int MAX = 0;
    int MIN = 0;
    for (int i = 0; i < n; i++) {
        if (i == 0) {
            MAX = a.at(0);
            MIN = a.at(0);
            continue;
        }
        MAX = max(a.at(i), MAX);
        MIN = min(a.at(i), MIN);
    }
    cout << MAX - MIN << endl;
    return 0;
}
//  [cpp]
#include <bits/stdc++.h>

using namespace std;

int main() {
    int n;
    vector<int> a(n);
    for (int i = 0; i < n; i++) {
        cin >> a.at(i);
    }
    int MAX = 0;
    int MIN = 0;
    for (int i = 0; i < n; i++) {
        if (i = 0) {
            MAX = a.at(0);
            MIN = a.at(0);
            continue;
        }
        MAX = max(a.at(i), MAX);
        MIN = min(a.at(i), MIN);
    }
    cout << MAX - MIN << endl;
    return 0;
}
//  [cpp]
#include <bits/stdc++.h>

using namespace std;

int main() {
    int n;
    vector<int> a(n);
    for (int i = 0; i < n; i++) {
        cin >> a.at(i);
    }
    int MAX = 0;
    int MIN = 0;
    for (int i = 0; i < n; i++) {
        if (i = 0) {
            MAX = a.at(0);
            MIN = a.at(0);
            break;
        }
        MAX = max(a.at(i), MAX);
        MIN = min(a.at(i), MIN);
    }
    cout << MAX - MIN << endl;
    return 0;
}
//  [c]
#include <stdio.h>

int main()
{
    int n, a[100+1], i, j, min, max;

    scanf( "%d", &n );
    for( i =  1; i < n+1; i++ )
    {
        scanf( "%d", &a[i] );
    }

    //最大と最小を見つけて差を出す
    min = a[1];
    max = a[1];
    for( j = 1; j < n+1; j++ )
    {
        if( a[j] > max ) max = a[j];
        else if( a[j] < min ) min = a[j];
    }
    printf("%d\n", max - min);

    return 0;
}