akhauriyash/Code-Regression huggingface dataset:
#![allow(non_snake_case)]
#![allow(unused_imports)]

use std::io::*;
use std::str::FromStr;
use std::collections::HashSet;

#[allow(dead_code)]
fn read<T : FromStr>() -> T {
  let token: String = stdin().lock()
    .bytes()
    .map(|c| c.expect("failed reading char") as char)
    .skip_while(|c| c.is_whitespace())
    .take_while(|c| !c.is_whitespace())
    .collect();
  token.parse().ok().expect("failed parse")
}

#[allow(dead_code)]
fn read2<T : std::str::FromStr>() -> (T, T) {
  (read::<T>(), read::<T>())
}

#[allow(dead_code)]
fn read3<T : std::str::FromStr>() -> (T, T, T) {
  (read::<T>(), read::<T>(), read::<T>())
}

#[allow(dead_code)]
fn reads<T : std::str::FromStr>() -> Vec<T> {
  let mut line = String::new();
  stdin().read_line(&mut line).ok();
  line.trim().split_whitespace().map(|e| e.parse().ok().unwrap()).collect()
}

struct UnionFind {
  par: Vec<usize>,
  rank: Vec<usize>,
}

impl UnionFind {
  fn new(n: usize) -> Self {
    let mut par: Vec<_> = vec![0; n];
    let rank: Vec<_> = vec![0; n];

    for i in 0..n {
      par[i] = i;
    }
    Self {
      par,
      rank
    }
  }

  #[allow(dead_code)]
  fn find(&mut self, x: usize) -> usize {
    if self.par[x] == x { return x; }
    self.par[x] = self.find(self.par[x]);
    self.par[x]
  }

  #[allow(dead_code)]
  fn unite(&mut self, x: usize, y: usize) {
    let x = self.find(x);
    let y = self.find(y);

    if x == y { return }
    if self.rank[x] < self.rank[y] {
      self.par[x] = y;
    }
    else {
      self.par[y] = x;
      if self.rank[x] == self.rank[y] {
        self.rank[x] += 1;
      }
    }
  }

  #[allow(dead_code)]
  fn is_same(&mut self, x: usize, y: usize) -> bool {
    self.find(x) == self.find(y)
  }
}

fn main() {
  let n: usize = read();
  let m: usize = read();

  let mut edge: Vec<(usize,usize)> = Vec::new();
  for _ in 0..m {
    let (a,b) = read2::<usize>();
    edge.push((a-1, b-1));
  }

  let mut uf = UnionFind::new(n);
  for (u, v) in edge {
    uf.unite(u, v);
  }

  let mut set = HashSet::new();
  for u in 0..n {
    set.insert(uf.find(u));
  }

  println!("{}", set.len() - 1);
}

Measured memory_bytes: 5116
#include <bits/stdc++.h>

#define rep(i, a, b) for (int i = a; i < (int)(b); ++i)
#define rrep(i, a, b) for (int i = b - 1; i >= (int)(a); --i)

using namespace std;
using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vll = vector<ll>;

constexpr int MOD = 1000000007;

template <typename T> class DisjointSet {
public:
    vector<T> rank, p;

    DisjointSet() {}
    DisjointSet(const DisjointSet& tree) : rank(tree.rank), p(tree.p) {}
    DisjointSet(T size) : rank(size, 0), p(size, 0) {
        rep(i, 0, size) { make_set(i); }
    }

    void make_set(T x) {
        p[x] = x;
        rank[x] = 0;
    }

    bool same(T x, T y) { return find_set(x) == find_set(y); }

    void unite(T x, T y) { link(find_set(x), find_set(y)); }

    void link(T x, T y) {
        if (rank[x] > rank[y]) {
            p[y] = x;
        } else {
            p[x] = y;
            if (rank[x] == rank[y]) { rank[y]++; }
        }
    }

    T find_set(T x) {
        if (x != p[x]) {
            p[x] = find_set(p[x]);
            rank[x] = 1;
        }
        return p[x];
    }
};

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);

    int n, q;
    cin >> n >> q;

    DisjointSet<int> tree(n);

    rep(i, 0, q) {
        int c, x, y;
        cin >> c >> x >> y;
        if (c == 0) {
            tree.unite(x, y);
        } else {
            cout << (tree.same(x, y) ? 1 : 0) << endl;
        }
    }

    return 0;
}


Measured memory_bytes: 3304
# coding:utf-8

import sys
import heapq
# from collections import Counter, defaultdict

INF = float('inf')
MOD = 10 ** 9 + 7

def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x) - 1 for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def II(): return int(sys.stdin.readline())
def SI(): return input()


n = II()
src = []
for i in range(n):
    a, b = LI()
    src.append((a + b, a, b))
src.sort()


# print(*src, sep='\n')


score_a, score_b = 0, 0
for i in range(n):
    if i % 2:
        x, a, b = src.pop()
        score_b += b

    else:
        x, a, b = src.pop()
        score_a += a

print(score_a - score_b)


Measured memory_bytes: 21036
#include <bits/stdc++.h>
using namespace std;
#define mp       make_pair
#define pb       push_back
#define all(x)   (x).begin(),(x).end()
#define YES() printf("YES\n")
#define NO() printf("NO\n")
#define Yes() printf("Yes\n")
#define No() printf("No\n")
#define in(x,y,h,w) x >= 0 && x < h && y >= 0 && y < w

#define int long long
//typedef    long long          ll;
typedef    vector<bool>       vb;
typedef    vector<int>        vi;
typedef    vector<vb>         vvb;
typedef    vector<vi>         vvi;
typedef    pair<int,int>      P;

template <typename T> T &chmin(T &a, const T &b) { return a = min(a, b); }
template <typename T> T &chmax(T &a, const T &b) { return a = max(a, b); }
 
const int INF=1e+18;
const double EPS=1e-9;
const int MOD=1000000007;
 
const int dx[]={1,0,-1,0},dy[]={0,-1,0,1};

int ask(int i){
	string s;
	cout << i << endl;
	cin >> s;
	if(s == "Male") return 0;
	else if(s == "Female") return 1;
	else return -1;
}

signed main(){
	int n,zero;
	cin >> n;
	int low = 1,up = n;
	for(int i = 0;i < n;i++){
		if(!i) zero = ask(0);
		else{
			int mid = (low + up) / 2;
			int tmp = ask(mid);
			if(tmp == -1) break;
			if((tmp + zero) % 2 != (mid - low) % 2){
				low = mid + 1;
				zero = tmp;
			}
			else up = mid;
		}
		if(zero == -1) break;
	}
	return 0;
}

Measured memory_bytes: 852
#include <bits/stdc++.h>

#define rep(i, n) for(int i = 0; i<(n); i++)
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
using namespace std;
typedef long long ll;

struct UnionFind {
    vector<int> par;

    UnionFind(int n) : par(n, -1) {}

    void init(int n) { par.assign(n, -1); }

    int root(int x) {
        if (par[x] < 0) return x;
        else return par[x] = root(par[x]);
    }

    bool issame(int x, int y) {
        return root(x) == root(y);
    }

    bool merge(int x, int y) {
        x = root(x);
        y = root(y);
        if (x == y) return false;
        if (par[x] > par[y]) swap(x, y); // merge technique
        par[x] += par[y];
        par[y] = x;
        return true;
    }

    int size(int x) {
        return -par[root(x)];
    }
};


typedef pair<int, int> P;
typedef pair<ll, P> Edge; // <cost, (x,y)座標>

int main() {
    int N;
    cin >> N;
    vector<ll> x(N), y(N);
    rep(i, N) cin >> x[i] >> y[i];

    vector<Edge> edges;

    // x 軸方向にソートして隣接している部分のみの辺を使用する
    vector<int> ids(N);
    iota(ids.begin(), ids.end(), 0);
    sort(ids.begin(), ids.end(), [&](int i, int j) { return x[i] < x[j]; });
    rep(i, N - 1) {
        int u = ids[i], v = ids[i + 1];
        edges.push_back(Edge(x[v] - x[u], P(u, v)));
    }

    // y 軸方向にソートして隣接している部分のみの辺を使用する
    sort(ids.begin(), ids.end(), [&](int i, int j) { return y[i] < y[j]; });
    rep(i, N - 1) {
        int u = ids[i], v = ids[i + 1];
        edges.push_back(Edge(y[v] - y[u], P(u, v)));
    }

    // Kruskal 法
    sort(edges.begin(), edges.end());
    UnionFind uf(N);
    ll ans = 0;
    for (auto e: edges) {
        int u = e.second.first, v = e.second.second;
        ll cost = e.first;
        if (uf.issame(u, v)) continue;
        uf.merge(u, v);
        ans += cost;
    }
    cout << ans << endl;
}

Measured memory_bytes: 8432
using System;
using System.Collections;
using System.Collections.Generic;

class Program
{
    public class UnionFind
    {
        private int[] data;

        public UnionFind(int size)
        {
            data = new int[size];
            for (int i = 0; i < size; i++) data[i] = -1;
        }

        public bool Unite(int x, int y)
        {
            x = Root(x);
            y = Root(y);

            if (x != y)
            {
                if (data[y] < data[x])
                {
                    var tmp = y;
                    y = x;
                    x = tmp;
                }
                data[x] += data[y];
                data[y] = x;
            }
            return x != y;
        }

        public bool IsSameGroup(int x, int y)
        {
            return Root(x) == Root(y);
        }

        private int Root(int x)
        {
            return data[x] < 0 ? x : data[x] = Root(data[x]);
        }
    }

    public static void Main()
    {
        int N = int.Parse(Console.ReadLine());
        bool[] IsBlack = new bool[N];

        UnionFind uf = new UnionFind(2 * N + 2);

        for (int i = 0; i < N - 1; i++)
        {
            string[] s = Console.ReadLine().Split(' ');
            int u = int.Parse(s[0]) - 1;
            int v = int.Parse(s[1]) - 1;
            if (int.Parse(s[2]) % 2 == 0)
            {
                uf.Unite(u, v);
                uf.Unite(u + N + 1, v + N + 1);
            }
            else {
                uf.Unite(u, v + N + 1);
                uf.Unite(u + N + 1, v );
            }
        }

        Console.WriteLine("0");
        for (int i = 1; i < N; i++) { 
            if (uf.IsSameGroup(0, i))
                Console.WriteLine("0");
            else
                Console.WriteLine("1");
        }
    }
}

Measured memory_bytes: 15932
#include <iostream>
#include<string>
#include<cmath>
#include<algorithm>
#include<cctype>
#include<queue>
#include<stack>
#include<stdio.h>
#include<vector>
#include<set>
#include<map>
#include<iomanip>
#define rep(i,n) for(double i=0;i<n;i++)
typedef int long long ll;
using namespace std;
int const INF = 1000000;
int long long  const  INFLL = 10000000000;
int main(){
    ll n;
    cin>>n;
    vector<ll> v(n);
    vector<ll> rui(n+1);
    rui[0]=0;
    ll sum=0;
    
    rep(i,n){
        cin>>v[i];
        rui[i+1]=rui[i]+v[i];
        sum+=v[i];
    }
    ll ansmin=INFLL;
    for(int i=1;i<=n-1;i++){
        ll sunuke=rui[i];
        ll arai=sum-sunuke;
        ll sa=abs(sunuke-arai);
        ansmin=min(ansmin,sa);
        
    }
    cout<<ansmin<<endl;
    
    
    
    return 0;
}


Measured memory_bytes: 3328
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

using namespace __gnu_pbds;
using namespace std;

#define ff first
#define ss second
#define pb push_back
#define pf push_front
#define mp make_pair
#define popb pop_back
#define popf pop_front
#define all(v) v.begin(), v.end()
#define fori(i, j, k) for (int i = (j); i < (int)(k); i++)
#define forb(i, j, k) for (int i = (j); i >= (int)k; i--)
#define lchild(ind) 2 * ind + 1
#define rchild(ind) 2 * ind + 2
#define bug(val) cout << "# " << val << endl;
#define bugs(val) cout << '_' << val;
#define bugl(val) cout << "## " << val << endl;

template<typename T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<int, ll> pil;
typedef pair<ll, int> pli;
typedef pair<ll, ll> pll;
typedef pair<int, pll> pip;
typedef pair<ll, pll> plp;
typedef pair<pll, int> ppi;
typedef pair<pll, ll> ppl;
typedef pair<pll, pll> ppp;
typedef vector<int> vi;
typedef vector<ll> vll;

const int maxn = 1e5 + 1;
const ll inf = 2e18, mod = 1e9 + 7;

int n;

int get(int val)
{
	int sum = 0;
	while (val)
	{
		sum += val % 10;
		val /= 10;
	}
	return sum;
}

int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(0);

	cin >> n;
	int ans = mod;
	fori (i, 1, n)
		ans = min(ans, get(i) + get(n - i));
	cout << ans << endl;
}

Measured memory_bytes: 892
# -*- coding: utf-8 -*-
"""
Created on Sat Apr 20 12:13:24 2019

@author: Yamazaki Kenichi
"""

N,T = map(int,input().split())
A = [list(map(int,input().split())) for i in range(N)]

ans = 10**9
for c in A:
    if c[1] <= T:
        ans = min(ans,c[0])

if ans == 10**9:
    print('TLE')
else:
    print(ans)

Measured memory_bytes: 3060
import numpy as np
N,M = map(int,input().split())
LR = [list(map(int,input().split())) for _ in range(M)]

# 軸ごとの計算をするためにnumpy配列に変換する
LRn = np.array(LR)


print(max(0, LRn.min(axis=0)[1] - LRn.max(axis=0)[0] + 1))

Measured memory_bytes: 37856
#include <iostream>
#include <iomanip>
#include <vector>
#include <algorithm>
#include <cstring>
#include <map>
#include <queue>
#include <cmath>
#include <complex> // complex<double> a(1.2 , 2.3);// real(): 1.2, imag()2.3
using namespace std;

#define MOD 1000000007
#define ll long long
#define ld long double
#define FOR(i,a,b) for(ll i=(ll)a;i<(ll)b;i++)
#define rep(i,n) FOR(i,0,n)
#define pb push_back
#define mp make_pair
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define rmsame(a) sort(all(a)),a.erase(unique(all(a)), a.end())
#define rmvector(a,b) rep(i,a.size())rep(j,b.size())if(a[i]==b[j]){a.erase(a.begin()+i);i--;break;}
template<typename X> bool exist(vector<X> vec, X item){return find(all(vec), item)!=vec.end();}

int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);

  ll N ,H , W;
  cin >> N >> H >> W;

  ll ans = 0;
  rep(i,N){
    ll a, b ;
    cin >> a >>  b ;
    if(a >= H && b >= W){
      ans ++;
    }
  }

  cout << ans << endl;


  return 0;
}


Measured memory_bytes: 256
import sys
sys.setrecursionlimit(2147483647)
INF=float("inf")
MOD=10**9+7
input=lambda:sys.stdin.readline().rstrip()
from itertools import groupby
def resolve():
    n,k=map(int,input().split())
    S=input()
    score=0
    for key,it in groupby(S):
        score+=len(list(it))-1

    ans=min(n-1,score+2*k)
    print(ans)
resolve()

Measured memory_bytes: 45168
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <string>
#include <sstream>
#include <complex>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
#include <numeric>
using namespace std;
typedef long long int ll;

#define EPS (1e-7)
#define INF 1e18
#define max(p,q)((p)>(q)?(p):(q))
#define min(p,q)((p)<(q)?(p):(q))
#define PI (acos(-1))

#define REP(i, n) for(int i = 0; i < (int)(n); i++)


int main() {

    int N;
    cin >> N;
    vector<int> A(N);
    int count = 0, tmp = N + 1;
    REP(i, N){
        cin >> A[i];
        if (A[i] < tmp){
            count++;
            tmp = A[i];
        }
    }
    cout << count << endl;
    return 0;
}


Measured memory_bytes: 1152
n=int(input())
dp=[0]*(n+1)
dp[0]=1
pbl=list(map(float,input().split()))
for i in range(n):
	for j in range(i+1,-1,-1):
		dp[j]=dp[j-1]*pbl[i]+dp[j]*(1-pbl[i])
	# print(dp)
ans=0
for i in range((n+1)//2,n+1):
	ans+=dp[i]
print(ans)

Measured memory_bytes: 41692
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
int main(){
 vector<int>a(3);
 for(int i=0;i<3;i++)cin>>a.at(i);
 sort(a.begin(),a.end());
 cout<<a.at(0)+a.at(1)<<endl;
}

Measured memory_bytes: 256
while True:
    N = int(input())
    if N == 0: break
    times = []
    for i in range(N):
        a,b = input().split()
        at = int(''.join(a.split(':')))
        bt = int(''.join(b.split(':')))
        times.append((at,1))
        times.append((bt,-1))
    ans = n = 0
    for t,d in sorted(times):
        n += d
        ans = max(ans,n)
    print(ans)

Measured memory_bytes: 7812
#include <bits/stdc++.h>
using namespace std;
#define REP(i,a,n) for(int i=(a); i<(int)(n); i++)
#define rep(i,n) REP(i,0,n)
#define FOR(it,c) for(__typeof((c).begin()) it=(c).begin(); it!=(c).end(); ++it)
#define ALLOF(c) (c).begin(), (c).end()
typedef long long ll;
typedef unsigned long long ull;


int main(){
  int N;
  cin >> N;
  vector<int> v;
  rep(i,N){
    int a;
    cin >> a;
    v.push_back(a);
  }

  int ret = 0;
  rep(i,N){
    if(i-1<0) continue;
    if(i+1>=N) continue;
    vector<int> w{v[i-1],v[i],v[i+1]};
    sort(ALLOF(w));
    if(w[1] == v[i]) ret++;
  }
  
  cout << ret << endl;
  return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

	public static Scanner scanner = new Scanner(System.in);

	public static void main(String[] args) {

		while (true) {

			int m = input();
			int f = input();
			int r = input();

			if (m == -1 && f == -1 && r == -1) {

				break;

			}

			if (m == -1 || f == -1) {

				System.out.println("F");

			} else if (80 <= m + f) {

				System.out.println("A");

			} else if (65 <= m + f && m + f < 80) {

				System.out.println("B");

			} else if (50 <= m + f && m + f < 65) {

				System.out.println("C");

			} else if (30 <= m + f && m + f < 50) {

				if (50 <= r ) {

					System.out.println("C");

				} else {

					System.out.println("D");

				}
			} else if (m + f < 30) {

				System.out.println("F");

			}
		}

		close();

	}

	public static int input() {

		return scanner.nextInt();

	}

	public static void close() {

		if (scanner != null) {

			scanner.close();

		}
	}
}

Measured memory_bytes: 26400
import java.util.Arrays;

public class Main {

  private static void solve() {
    int n = ni();
    int k = ni();
    char[][] p = new char[n][];
    for (int i = 0; i < n; i ++) {
      p[i] = ns();
    }
    
    int[] count = new int[26];
    for (char[] v : p) {
      count[v[0] - 'A'] ++;
    }
    
    int ret = 0;
    loop: while (true) {
      Arrays.sort(count);
      for (int i = 0; i < k; i ++) {
        int idx = 25 - i;
        if (count[idx] == 0) {
          break loop;
        } else {
          count[idx] --;
        }
      }
      ret ++;
    }
    out.println(ret);
  }

  public static void main(String[] args) {
    new Thread(null, new Runnable() {
      @Override
      public void run() {
        long start = System.currentTimeMillis();
        String debug = System.getProperty("debug");
        if (debug != null) {
          try {
            is = java.nio.file.Files.newInputStream(java.nio.file.Paths.get(debug));
          } catch (Exception e) {
            throw new RuntimeException(e);
          }
        }
        reader = new java.io.BufferedReader(new java.io.InputStreamReader(is), 32768);
        solve();
        out.flush();
        tr((System.currentTimeMillis() - start) + "ms");
      }
    }, "", 64000000).start();
  }

  private static java.io.InputStream is = System.in;
  private static java.io.PrintWriter out = new java.io.PrintWriter(System.out);
  private static java.util.StringTokenizer tokenizer = null;
  private static java.io.BufferedReader reader;

  public static String next() {
    while (tokenizer == null || !tokenizer.hasMoreTokens()) {
      try {
        tokenizer = new java.util.StringTokenizer(reader.readLine());
      } catch (Exception e) {
        throw new RuntimeException(e);
      }
    }
    return tokenizer.nextToken();
  }

  private static double nd() {
    return Double.parseDouble(next());
  }

  private static long nl() {
    return Long.parseLong(next());
  }

  private static int[] na(int n) {
    int[] a = new int[n];
    for (int i = 0; i < n; i++)
      a[i] = ni();
    return a;
  }

  private static char[] ns() {
    return next().toCharArray();
  }

  private static long[] nal(int n) {
    long[] a = new long[n];
    for (int i = 0; i < n; i++)
      a[i] = ni();
    return a;
  }

  private static int[][] ntable(int n, int m) {
    int[][] table = new int[n][m];
    for (int i = 0; i < n; i++) {
      for (int j = 0; j < m; j++) {
        table[i][j] = ni();
      }
    }
    return table;
  }

  private static int[][] nlist(int n, int m) {
    int[][] table = new int[m][n];
    for (int i = 0; i < n; i++) {
      for (int j = 0; j < m; j++) {
        table[j][i] = ni();
      }
    }
    return table;
  }

  private static int ni() {
    return Integer.parseInt(next());
  }

  private static void tr(Object... o) {
    if (is != System.in)
      System.out.println(java.util.Arrays.deepToString(o));
  }
}


Measured memory_bytes: 28104
#include <stdio.h>
#include <stdlib.h>
#define swap(type,a,b) do{type t=a;a=b;b=t;}while(0);
#define MAX(a,b) ((a)>(b)?(a):(b))
#define MIN(a,b) ((a)<(b)?(a):(b))
#define ll long long
#define INF 100000000
#define FOR(i,a,n) for(int i=a;i<n;i++)
int comp(const void* a,const void* b){
	return *(ll*)a-*(ll*)b;
}
void fill(int a[],int b,int c){
	for(int i=0;i<b;i++) a[i]=c;
	return;
}
int a[300000];
int main(void)
{
    int n;
    ll res=0;
    scanf("%d",&n);
    FOR(i,0,3*n) scanf("%d",&a[i]);
    qsort(a,3*n,sizeof(a[0]),comp);
    for(int i=n;i<3*n-1;i+=2){
        res += a[i];
    }
    printf("%lld\n",res);
	return 0;
}


Measured memory_bytes: 2556
#include <cstdio>
#include <cstdlib>
#include <string>
#include <iostream>

using namespace std;
static const int N=100;

int main()
{
    int n,k,v,u,j,i;
    int Adj[N+1][N+1]={0};

    cin>>n;
    for(int i=1;i<=n;i++){
        cin>>u>>k;
        for(j=0;j<k;j++){
            cin>>v;
            Adj[u][v]=1;
        }
    }
    for(i=1;i<=n;i++){
        for(j=1;j<=n;j++){
            if(j-1) cout<<" ";
            cout << Adj[i][j];
        }
        cout<<endl;
    }
    return 0;
}



Measured memory_bytes: 3116
/*
    -ensure correct output format
    -ensure printing required output
    -reread the problem statement
  */

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll,ll>pll;
typedef pair<ll,pair<ll,ll>>plll;
#define fastread() (ios_base:: sync_with_stdio(false),cin.tie(NULL));
#define vll(v) v.begin(),v.end()
#define all(x) x.rbegin(),x.rend()
#define min3(a, b, c)   min(a, min(b, c))
#define max3(a, b, c)   max(a, max(b, c))
#define F first
#define S second
#define in  freopen("input.txt", "r", stdin)
#define out  freopen("output.txt", "w", stdout)
#define minheap int,vector<int>,greater<int>
#define pb push_back
#define eb emplace_back
#define ischar(x)  (('a' <= x && x <= 'z') || ('A' <= x && x <= 'Z'))
#define isvowel(ch) ((ch=='a'||ch=='e'||ch=='i'||ch=='o'||ch=='u')||(ch=='A'|| ch=='E' || ch=='I'|| ch=='O'|| ch=='U'))
#define bug cout<<"BUG"<<endl;
const int Max = 2e6 + 10;
const int Mod = 1e9 + 7;
const double PI  =3.141592653589793238463;
bool compare(const pair<ll,ll> &a, const pair<ll,ll> &b)
{
       return (a.first > b.first);
}
ll lcm(ll a,ll b)
{
    if(a==0 || b==0)return 0;

    return a/__gcd(a,b)*b;
}

void input(ll ara[],ll n)
{
    for(ll i=0; i<n; i++)cin>>ara[i];
}
void print(ll ara[],ll n)
{
    for(ll i=0; i<n; i++)
        cout<<ara[i]<<" ";
    cout<<endl;
}


int main()
{

   fastread();

   ll i,j,n,m,p,a,sum=0,k,t,b,c,d,cnt=0,q,l,r,ans=0;

      bool flag=false;

      string str;





       cin>>n;

       ll mx=0,mi=1e18+10;


       vector<ll>v,s;


       for(i=0; i<n; i++)
       {
           cin>>a>>b;

           v.eb(a+b);

           s.eb((a-b));
       }

       sort(vll(v));

       sort(vll(s));

       sum=abs(v[0]-v[n-1]);

       sum=max(sum,abs(s[0]-s[n-1]));

       cout<<sum<<endl;










}



Measured memory_bytes: 6648
#include <iostream>
#include <cstring>
using namespace std;

typedef long long ll;

int main()
{
    int n;
    string s;
    cin >> n >> s;
    int i = 0;
    int temp = 0;
    while(true){
        if(i >= s.size()){
            break;
        }
        if(s.at(i) == '('){
            ++temp;
        }else{
            --temp;
        }
        if(temp < 0){
            s.insert(s.begin(),'(');
            ++temp;
            ++i;
        }
        ++i;
    }
    i = s.size()-1;
    temp = 0;
    while(true){
        if(i < 0){
            break;
        }
        if(s.at(i) == ')'){
            ++temp;
        }else{
            --temp;
        }
        if(temp < 0){
            s.insert(s.end(),')');
            ++temp;
        }
        --i;
    }
    cout << s << endl;
    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<string>
using namespace std;
int main(){
    string s;cin>>s;
    int a,b;
    for(int i=0;i<s.length();i++){
        if(s[i]=='C'){
            a=i;
            break;
        }
    }
    for(int i=a+1;i<s.length();i++){
        if(s[i]=='F'){
            cout<<"Yes"<<endl;
            return 0;
        }
    }
    cout<<"No"<<endl;
return 0;
}


Measured memory_bytes: 256
import java.util.*;

public class Main {
	public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    int n = sc.nextInt();
		int a = sc.nextInt();
		int b = sc.nextInt();

		int sum = 0;
		for (int i = 1; i <= n; i++) {
			if (check(i, a, b)) {
				sum += i;
			}
		}

		System.out.println(sum);
	}

	private static boolean check(int x, int a, int b) {
		int sum = 0;
		while (x > 0) {
			sum += x - (x / 10 * 10);
			x /= 10;
		}
		return sum >= a && sum <= b;
	}
}


Measured memory_bytes: 21716
/**
 * @copyright (c) 2020 Daisuke Hashimoto
 */

#include <bits/stdc++.h>
using namespace std;
using Pair = pair<int64_t, int64_t>;
constexpr int64_t kInf = INT64_MAX / 2L;

// std::cout << std::setprecision(20) << 1.1 << endl;

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);

  int64_t N;
  cin >> N;
  // const int64_t L = static_cast<int64_t>(T.length());
  vector<int64_t> A(N + 1, 0);
  for (int64_t i = 1; i <= N; ++i) {
    cin >> A[i];
  }
  vector<int64_t> result;
  vector<int64_t> B(N + 1, 0);
  for (int64_t i = N; i >= 1; --i) {
    int64_t temp = 0;
    for (int64_t j = 2 * i; j <= N; j += i) {
      temp += B[j];
      temp %= 2;
    }
    if (temp != A[i]) {
      B[i] = 1;
      result.emplace_back(i);
    }
  }
  cout << result.size() << endl;
  for (int64_t i = 0; i < static_cast<int64_t>(result.size()); ++i) {
    if (i != 0) {
      cout << " " << endl;
    }
    cout << result[i];
  }
  cout << endl;
  return 0;
}


Measured memory_bytes: 7408
#include <cstdio>
#include <cstring>
#include <iostream>
#include <string>
#include <cmath>
#include <bitset>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <algorithm>
#include <complex>
#include <unordered_map>
   
using namespace std;
typedef long long int ll;
typedef pair<int, int> P;
   
int main()
{
    string s;
	cin>>s;
	int n=s.size();
	set<P> st;
	st.insert(P(0, 0));
	int dp[200001];
	int a[200001];
	dp[0]=0;
	a[0]=0;
	for(int i=1; i<=n; i++){
		a[i]=a[i-1]^(1<<(s[i-1]-'a'));
		if(a[i]==0){
			dp[i]=1;
			st.insert(P(a[i], i));
			continue;
		}
		dp[i]=dp[i-1]+1;
		for(int j=0; j<26; j++){
			int a0=a[i]^(1<<j);
			if(a0==0){
				dp[i]=1;
				break;
			}
			auto itr=st.upper_bound(P(a0, 1e9));
			itr--;
			if((*itr).first==a0){
				int i0=(*itr).second;
				dp[i]=min(dp[i], dp[i0]+1);
			}
		}
		st.insert(P(a[i], i));
	}
	cout<<dp[n]<<endl;
    return 0;
}

Measured memory_bytes: 11396
const input=require('fs').readFileSync('/dev/stdin', 'utf8').split(/[\s]/);const nin=()=>{const r = input[0];input.shift();return Number(r)};const nrin=(n)=>{const a:number[]=[];rep(n,()=>a.push(nin()));return a};const sin=()=>{const r = input[0];input.shift();return String(r)};const out=(...a)=>{console.log(...a)};const floor=(a)=>{return Math.floor(a)};const abs=(a)=>{return Math.abs(a)};const min=(...a)=>{return Math.min(...a)};const max=(...a)=>{return Math.max(...a)};const rep=(n, callback)=>{for(let i = 0;i < n; i++){callback()}};const strrep=(s, i, v)=>{return s.slice(0, i)+v+s.slice(i+1);};const permutation=({result=[],pre=[],post,n=post.length})=>{if(n>0){post.forEach((_,i)=>{const rest=[...post];const elem=rest.splice(i, 1);permutation({result, pre: [...pre,...elem],post:rest,n:n-1})})}else{result.push(pre)}return result};const sw=(s,a:any[])=>{for(let i=0;i<a.length;i+=2)if(s==a[i])return a[i+1]};const or=(a,...b)=>{for(let i=0;i<b.length;i++)if(a==b[i])return true;return false};
const main = ()=>{
  let s= sin();
  out((s[0]=='1'?'9':'1')+(s[1]=='1'?'9':'1')+(s[2]=='1'?'9':'1'));
}
main();

Measured memory_bytes: 7372
#include <bits/stdc++.h>
using namespace std;

int main(){
	int N;
	cin >>N;
	bool pro =false;
	for(int i=1;i<10;i++){
		if(N%i ==0){
			int Q=N/i;
			if(Q<=9){
				pro =true;
				break;
			}
		}
	}
	if(pro){
		cout << "Yes"<<endl;
	}
	else {
		cout <<"No"<<endl;
	}
	
	
}




Measured memory_bytes: 256
#include<stdio.h>
int main(){
int n,a[1000],i;
scanf("%d",&n);
for(i=0;i<n;i++)
{
scanf("%d",&a[i]);
}
for(i=n-1;i>=1;i--)
{
printf("%d ",a[i]);
}
printf("%d\n",a[0]);
return 0;
}



Measured memory_bytes: 2124
#include <stdio.h>
#include <stdlib.h>
#include <iostream>
#include <math.h>
#include <algorithm>
#include <string>
#include <string.h>
#include <vector>
#include <functional>
#include <queue>
#include <unordered_set>
#include <climits>
#include <set>
#include <list>
#include <cmath>
#include <map>

using namespace std;
typedef long long ll;

int main()
{
	ll N;
	cin >> N;
	ll ans = 0;
	static ll Count[10010010];
	fill(Count, Count+10010010, 0);
	for(int i = 1; i <= 10000; i++){
		ll x = 1;
		while( i * x <= N){
			Count[i*x]++;
			if(x > 10000){
				Count[i*x]++;
			}
			x++;
		}
	}
	
	for(ll i = 1; i <= N; i++){
		ans += i * Count[i];
	}
	cout << ans << endl;
	
	return 0;
}


Measured memory_bytes: 81832
#include <bits/stdc++.h>
using namespace std;

int main(){
    int n;
    long long d;
    scanf("%d %lld", &n, &d);
    d = d * d;
    int ans = 0;
    for (int i = 1; i <= n; ++i){
        long long x, y;
        scanf("%lld %lld", &x, &y);
        if (x*x + y*y <= d) ++ans;
    }
    printf("%d\n", ans);
    return 0;
}

Measured memory_bytes: 3820
#include <bits/stdc++.h>
using namespace std;

int main(){
  int N,D;
  int count=0;
  cin >> N >> D;
  double p,q;
  double dis;  
  for(int i=0;i<N;i++){
    cin >> p >> q;
    dis = sqrt((p*p)+(q*q));
    if(dis <= D){
      count++;
    }
  }
  cout << count << endl;
}

Measured memory_bytes: 3776
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <iostream>
#include <map>
#include <queue>
#include <stack>
#include <string>
#include <vector>

using namespace std;

template <class T> inline bool chmin(T &a, T b) {
    if(a > b) {
        a = b;
        return true;
    }
    return false;
}
template <class T> inline bool chmax(T &a, T b) {
    if(a < b) {
        a = b;
        return true;
    }
    return false;
}

const long long INF = 1LL << 60;

#define rep(i, e) for(int i = 0; i < e; i++)
#define repp(i, s, e) for(int i = s; i < e; i++)
#define N_Max 100
#define Card_Max 36
#define p(a) printf("%d\n", a);
#define ll long long
#define ull unsigned long long
#define MAX 1e9
#define NIL -1

int main() {
    int N,K;
    ll h[100005] = {};
    ll dp[100005] = {};
    cin >> N >> K;
    rep(i, N) cin >> h[i];

    dp[0] = 0;

    ll minv; 
    repp(i,1,K){
        minv = MAX;
        rep(j,i){
            minv = min(minv, dp[j] + abs(h[i]-h[j]));
        }
        dp[i] = minv;
    }

    repp(i, K, N) {
        minv = MAX;
        repp(j,i-K,i){
            minv = min(minv, dp[j]+abs(h[i]-h[j]));
            // cout << "i: " << i << endl;
            // cout << "j: " << j << endl;
            // cout << "dp[j]: " << dp[j] << endl;
            // cout << "h[i]: " << h[i] << endl;
            // cout << "h[j]: " << h[j] << endl;
            // cout << "minv:  " << minv << endl;
        }
        dp[i] = minv;
    }

    // rep(i,N){
    //     cout << dp[i] << endl;
    // }
    
    cout << dp[N-1] << endl;
}


Measured memory_bytes: 1792
#[allow(unused_macros)]
macro_rules! scan {
    () => {
        {
            let mut line: String = String::new();
            std::io::stdin().read_line(&mut line).unwrap();
            line.trim().to_string()
        }
    };
    (;;) => {
        {
            let mut line: String = String::new();
            std::io::stdin().read_line(&mut line).unwrap();
            line.trim().split_whitespace().map(|s| s.to_string()).collect::<Vec<String>>()
        }
    };
    (;;$n:expr) => {
        {
            (0..$n).map(|_| scan!()).collect::<Vec<_>>()
        }
    };
    ($t:ty) => {
        {
            let mut line: String = String::new();
            std::io::stdin().read_line(&mut line).unwrap();
            line.trim().parse::<$t>().unwrap()
        }
    };
    ($($t:ty),*) => {
        {
            let mut line: String = String::new();
            std::io::stdin().read_line(&mut line).unwrap();
            let mut iter = line.split_whitespace();
            (
                $(iter.next().unwrap().parse::<$t>().unwrap(),)*
            )
        }
    };
    ($t:ty;;) => {
        {
            let mut line: String = String::new();
            std::io::stdin().read_line(&mut line).unwrap();
            line.split_whitespace()
                .map(|t| t.parse::<$t>().unwrap())
                .collect::<Vec<_>>()
        }
    };
    ($t:ty;;$n:expr) => {
        (0..$n).map(|_| scan!($t;;)).collect::<Vec<_>>()
    };
    ($t:ty; $n:expr) => {
        (0..$n).map(|_|
                    scan!($t)
        ).collect::<Vec<_>>()
    };
    ($($t:ty),*; $n:expr) => {
        (0..$n).map(|_|
                    scan!($($t),*)
        ).collect::<Vec<_>>()
    };
}

fn permutations(n: usize, m: usize) -> Vec<Vec<usize>> {
    if n == m {
        return vec![vec![m]];
    }

    let mut ret = vec![];
    for perm in permutations(n + 1, m) {
        let len = perm.len();

        for i in 0..len + 1 {
            let mut p = perm.clone();
            p.insert(i, n);
            ret.push(p);
        }
    }
    ret
}

fn main() {
    let (n, m) = scan!(usize, usize);

    let mut graph = vec![vec![false; n + 1]; n + 1];
    for _ in 0..m {
        let (a, b) = scan!(usize, usize);
        graph[a][b] = true;
        graph[b][a] = true;
    }
    let perms = permutations(2, n);

    let mut ans = 0;
    for perm in perms {
        let mut valid = true;
        let mut n = 1;
        for v in perm {
            if !graph[n][v] {
                valid = false;
                break;
            }
            n = v
        }
        if valid {
            ans += 1;
        }
    }
    println!("{}", ans);
}


Measured memory_bytes: 4352
import heapq
from math import ceil

def check(ls,mid,a,b):
    count = 0
    for now in ls:
        now -= mid*b
        count += ceil(max(now,0)/(a-b))
    if count<=mid:
        return True
    else:
        return False

def main():
    n,a,b = map(int,input().split())
    h = [int(input()) for _ in range(n)]
    can_l,can_r = 0,10**9
    while 1:
        if can_r==can_l:
            print(can_r)
            exit()
        elif abs(can_r-can_l)==1:
            if check(h,max(can_r,can_l),a,b):
                print(max(can_l,can_r))
                exit()
            else:
                print(min(can_l,can_r))
                exit()
        mid = ceil((can_l+can_r)/2)
        if check(h,mid,a,b):
            can_r = mid
        else:
            can_l = mid
        
if __name__ == "__main__":
    main()

Measured memory_bytes: 50264
#include <bits/stdc++.h>
 
using namespace std;

#define M 1000000007
#define pb emplace_back
#define f first
#define s second
#define rep(i, st, ed) for(ll i=st; i<ed; ++i)
#define repn(i, st, ed) for(ll i=st; i<=ed; ++i)
#define repb(i, ed, st) for(ll i=ed; i>=st; --i)
#define all(v) v.begin(),v.end()
#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() );
#define PI acosl(-1.0)

typedef long long ll;
typedef unsigned long long int llt;
typedef long double ld;
typedef pair<ll, ll> pll;
typedef vector<ll> vec;
typedef vector<pll> vecp;
typedef map<ll, ll> mpll;


const int N = 1e5 + 10;
const ll INF = 1LL << 60;

template<class T> void chmax(T &a,T b) { if (a<b) a=b;}
template<class T> void chmin(T &a,T b) { if (a>b) a=b;}

template <typename A, typename B>
string to_string(pair<A, B> p);
 
template <typename A, typename B, typename C>
string to_string(tuple<A, B, C> p);
 
template <typename A, typename B, typename C, typename D>
string to_string(tuple<A, B, C, D> p);
 
string to_string(const string& s) {
  return '"' + s + '"';
}
 
string to_string(const char* s) {
  return to_string((string) s);
}
 
string to_string(bool b) {
  return (b ? "true" : "false");
}
 
string to_string(vector<bool> v) {
  bool first = true;
  string res = "{";
  for (int i = 0; i < static_cast<int>(v.size()); i++) {
    if (!first) {
      res += ", ";
    }
    first = false;
    res += to_string(v[i]);
  }
  res += "}";
  return res;
}
 
template <size_t N>
string to_string(bitset<N> v) {
  string res = "";
  for (size_t i = 0; i < N; i++) {
    res += static_cast<char>('0' + v[i]);
  }
  return res;
}
 
template <typename A>
string to_string(A v) {
  bool first = true;
  string res = "{";
  for (const auto &x : v) {
    if (!first) {
      res += ", ";
    }
    first = false;
    res += to_string(x);
  }
  res += "}";
  return res;
}
 
template <typename A, typename B>
string to_string(pair<A, B> p) {
  return "(" + to_string(p.first) + ", " + to_string(p.second) + ")";
}
 
template <typename A, typename B, typename C>
string to_string(tuple<A, B, C> p) {
  return "(" + to_string(get<0>(p)) + ", " + to_string(get<1>(p)) + ", " + to_string(get<2>(p)) + ")";
}
 
template <typename A, typename B, typename C, typename D>
string to_string(tuple<A, B, C, D> p) {
  return "(" + to_string(get<0>(p)) + ", " + to_string(get<1>(p)) + ", " + to_string(get<2>(p)) + ", " + to_string(get<3>(p)) + ")";
}
 
void debug_out() { cerr << endl; }
 
template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
  cerr << to_string(H) << endl;
  debug_out(T...);
}
#define LOCAL 3
#ifdef LOCAL
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:" << endl, debug_out(__VA_ARGS__)
#else
#define debug(...) 42
#endif


void solve()
{
	ll n, k, s;
	cin>>n>>k>>s;
	rep(i, 0, k) cout<<s<<" ";
	if(s == 1e9) s = 1;
	else s++;
	rep(i, 0, n-k) cout<<s<<" ";
}


int main()
{
	ll Tests = 1;
    //cin>>Tests;
    while(Tests--)
    {
    	solve();
    }
    return 0;
}

Measured memory_bytes: 1280
#include <bits/stdc++.h>

using namespace std;

#define MAX 5010
#define MAX_N 12
typedef unsigned long long ull;
const ull B = 1000000007ULL;

vector<ull> rolling_hash(string &s)
{
    int N = s.size();
    vector<ull> hash(N+1);
    hash[0] = 0;
    
    for (int i = 0; i < N; i++) {
        hash[i+1] = hash[i] * B + s[i];        
    }
    return hash;
}

int main()
{
    ull p[MAX];
    p[0] = 1;
    for (int i = 0; i < MAX-1; i++) {
        p[i+1] = p[i] * B;
    }

    int N, M;
    while (cin >> N >> M, N) {
        int total = 0, len_e[12];
        string e;
        vector<vector<ull>> hash_e(N);
        for (int i = 0; i < N; i++) {
            cin >> e;
            hash_e[i] = rolling_hash(e);
            total += len_e[i] = e.size();
        }
        string str, t;
        for (int i = 0; i < M; i++) {
            cin >> t;
            str += t;
        }

        int n = str.size(), sum = 0;
        vector<ull> hash_t = rolling_hash(str);
        for (int i = 0; i <= n - total; i++) {
            bool dp[1<<MAX_N] = {};
            dp[0] = 1;
            for (int j = 0; j < (1<<N)-1; j++) {
                if (dp[j] == 0) continue;
                int pos = i;
                for (int k = 0; k < N; k++) {
                    if (j >> k & 1) {
                        pos += len_e[k];
                    }                    
                }
                for (int k = 0; k < N; k++) {
                    if (j >> k & 1) continue;
                    int L = pos, R = pos + len_e[k] - 1;
                    ull h = hash_t[R+1] - hash_t[L] * p[R - L + 1];
                    if (h == hash_e[k][len_e[k]]) {
                        dp[j|(1<<k)] = 1;
                    }
                }
            }
            sum += dp[(1<<N)-1];
        }        
        cout << sum << endl;
    }
    return 0;
}

Measured memory_bytes: 3212
nab = input()

nab = nab.split()

n = int(nab[0])
a = int(nab[1])
b = int(nab[2])

ans = 0

for i in range(1, n+1):
	q =  int(i / 10000)
	r = int( (i - q*10000)/1000 )
	s = int( (i - q*10000 - r*1000)/100 )
	t =  int( (i - q*10000 - r*1000 - s*100)/10 )
	u = int( (i - q*10000 - r*1000 - s*100 - t*10) )
	sum = q + r + s + t + u
	if sum >= a and sum <= b:
		ans = ans + i
		
print(ans)

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;

typedef long long ll;
#define maxn 100005
ll fa[maxn];
int n,q;

ll find_fa(ll x){
	if(x==fa[x]){
		return fa[x];
	}
	return find_fa(fa[x]);
}

int main(){
	while(cin>>n>>q){
		if(!n&&!q) break;
		char s[2];
		ll x;
		fa[1] = 1;
		for(int i=2;i<=n;i++){
			cin>>x;
			fa[i] = x;
		}
		ll ans = 0;
		while(q--){
			cin>>s>>x;
			if(s[0]=='M'){
				fa[x] = x;
			}
			else{
				ans += find_fa(x);
			}
			
		}
		cout<<ans<<endl;
	}
	return 0;
}


Measured memory_bytes: 3760
#include<bits/stdc++.h>
using namespace std;

int main()
{
    int n;
    cin>>n;
    int arr[n+5]={0};
    vector<pair<int,int> >v;
    int frr[n+5];
    for(int i=0;i<n;i++)
    {
        cin>>frr[i];
        v.push_back(make_pair(frr[i],i));
    }
    sort(v.begin(),v.end());

    int counter=0;
    for(int i=0;i<v.size();i++)
    {
        int a=v[i].first;
        int b=v[i].second;
        if(arr[b]<a)
        {
            int k=a-arr[b];
            counter+=k;
            for(int j=b;j<n;j++)
            {
                if(arr[j]+k<=frr[j])
                {
                   // counter++;
                    arr[j]+=k;
                }
                else
                {
                    break;
                }
            }
             for(int j=b-1;j>=0;j--)
            {
                if(arr[j]+k<=frr[j])
                {
                   // counter++;
                    arr[j]+=k;
                }
                else
                {
                    break;
                }
            }
        }
    }
   // for(int i=0;i<n;i++)cout<<arr[i]<<" ";
    cout<<counter<<endl;
}


Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;

// 定義
typedef long long         ll;
typedef pair<ll, ll>      P;
#define ALL(x)            (x).begin(),(x).end()
#define REP(i, n)         for(ll i = 0 ; i < (ll)n ; ++i)
#define REPN(i, m, n)     for(ll i = m ; i < (ll)n ; ++i)
#define REVREP(i, n)      for(ll i = n - 1; i >= 0 ; i--)
#define VL                vector<ll>
#define VVL               vector<vector<ll>>
#define VVVL              vector<vector<vector<ll>>>
#define VC                vector<char>
#define VVC               vector<vector<char>>
#define INF               (ll)2e9
#define INF_LL            1LL<<60
//#define MOD             998244353
#define MOD               1000000007

ll Ceil(ll val, ll div)   { return (val + div - 1) / div; }
ll CeilN(ll val, ll div)  { return Ceil(val, div) * div; }
ll FloorN(ll x, ll n)     { return (x - x % n); }
bool IsOdd(ll x)          { return ((x & 1) == 1); }
bool IsEven(ll x)         { return ((x & 1) == 0); }
template<class T> bool chmax(T& a, T b) { if (a <= b) { a = b; return 1; } return 0; }
template<class T> bool chmin(T& a, T b) { if (a >= b) { a = b; return 1; } return 0; }

void Solve()
{
	ll X, K, D;
	cin >> X >> K >> D;
	X = abs(X);
	ll nearCnt = min(X / D, K);
	ll nearDist = X - D * nearCnt;
	K -= nearCnt;
	if (K == 0) {
		cout << nearDist << endl;
		return;
	}

	ll ansOne;
	if (IsOdd(K)) {
		ansOne = D - nearDist;
	} else {
		ansOne = nearDist;
	}

	cout << ansOne << endl;
}

// メイン
int main()
{
	cin.tie(nullptr);
	ios_base::sync_with_stdio(false);
	cout << fixed << setprecision(15);
	Solve();
	return 0;
}


Measured memory_bytes: 3648
#include <stdio.h>
#include <stdlib.h>


int main(){
    int i, j, k, l, m, n;
    int N, M, L;
    
    scanf("%d", &N);
    scanf("%d", &M);
    
    int *K = (int *)malloc(sizeof(int) * M);
    int *mat, **Mat;
    mat = (int *)malloc(sizeof(int) * (N+1)*M);
    Mat = (int **)malloc(sizeof(int*) * M);
    for(i = 0; i < M; i++){
        Mat[i] = &mat[i*(N+1)];
    }


    for(i = 0; i < M; i++){
        scanf("%d", &K[i]);
        for(j = 0; j < K[i]; j++){
            scanf("%d", &k);
            Mat[i][k-1] = 1;
        }
    }
    for(i = 0; i < M; i++){
        scanf("%d", &Mat[i][N]);
    }
    
    // printf("\n");
    // for(i = 0; i < M; i++){
    //     for(j = 0; j < N+1; j++){
    //         printf("%d ", Mat[i][j]);
    //     }
    //     printf("\n");
    // }
    
    L = 1 << N;
    int result = 0;
    int testN[11];
    for(i = 0; i < L; i++){

        testN[ 0] = i & 0b0000000001;
        testN[ 1] = i & 0b0000000010;
        testN[ 2] = i & 0b0000000100;
        testN[ 3] = i & 0b0000001000;
        testN[ 4] = i & 0b0000010000;
        testN[ 5] = i & 0b0000100000;
        testN[ 6] = i & 0b0001000000;
        testN[ 7] = i & 0b0010000000;
        testN[ 8] = i & 0b0100000000;
        testN[ 9] = i & 0b1000000000;
        testN[N] = 1;
        
        for(j = 0; j < M; j++){
            int test = 0;
            for(k = 0; k < N+1; k++){
                if(testN[k]==0) continue;
                if(Mat[j][k]==1) test++;
            }
            if((test&1)==1){
                j = -1;
                break;
            }
        }
        if(j==-1) continue;
        result++;
        // printf("ok(%d/%d): ",i , N);
        // for(k = 0; k < N+1; k++){
        //     printf("%d ", testN[k]);
        // }
        // printf("\n");
    }
    
    printf("%d\n", result);
    
    return 0;
}


Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0, i##_len = (n); i < i##_len; ++i)
#define rep2(i, x, n) for(int i = x, i##_len = (n); i < i##_len; ++i)
#define all(n) begin(n), end(n)
using ll = long long;
using P = pair<ll, ll>;
using vi = vector<int>;
using vl = vector<ll>;
using vs = vector<string>;
using vc = vector<char>;
using vb = vector<bool>;
using vd = vector<double>;
vi dir = {-1, 0, 1, 0, -1, -1, 1, 1, -1};

struct edge {
  int from;  //出発点
  int to;    //到達点
  int cost;  //移動コスト
};

int main() {
  ll n, m, c;
  cin >> n >> m >> c;
  vector<edge> edges;
  vector<vl> g(n), h(n);
  rep(i, m) {
    edge e;
    ll a, b, cost;
    cin >> a >> b >> cost;
    a--;
    b--;
    e.from = a;
    e.to = b;
    e.cost = c - cost;
    edges.push_back(e);
    g[b].push_back(a);
    h[a].push_back(b);
  }
  vl ok0(n, false), okn(n, false), d(n, 1e18);
  ok0[0] = true;
  queue<int> q;
  q.push(0);
  while(!q.empty()) {
    int i = q.front();
    q.pop();
    for(auto v : h[i]) {
      if(ok0[v]) continue;
      ok0[v] = true;
      q.push(v);
    }
  }
  okn[n - 1] = true;
  q.push(n - 1);
  while(!q.empty()) {
    int i = q.front();
    q.pop();
    for(auto v : g[i]) {
      if(okn[v]) continue;
      okn[v] = true;
      q.push(v);
    }
  }
  d[0] = 0;
  rep(i, n) rep(j, m) {
    edge e = edges[j];
    if(!okn[i] || !okn[e.from] || !okn[e.to]) continue;
    if(!ok0[i] || !ok0[e.from] || !ok0[e.to]) continue;
    if(d[e.to] > d[e.from] + e.cost) {
      d[e.to] = d[e.from] + e.cost;
      if(i == n - 1) {
        cout << -1 << endl;
        return 0;
      }
    }
  }
  cout << max(0LL, -d[n - 1]) << endl;
}

Measured memory_bytes: 640
//2019/3/14
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {

		Scanner sc = new Scanner(System.in);

		int D = sc.nextInt();

		int N = sc.nextInt();

		int ans = 0;

		if(D==0 && N>=100) {

			ans = 101;

		}else if(D==0 && N<100) {

			ans = N;

		}else if(D==1 && N>=100) {

			ans = 101*100;

		}else if(D==1 && N<100) {

			ans = N*100;

		}else if(D==2 && N>=100) {

			ans = 101*10000;

		}else if(D==2 && N<100) {

			ans = N*10000;
		}

		System.out.println(ans);
	}

}


Measured memory_bytes: 23764
n,k = map(int,input().split())

MOD = 10**9+7

minus = sum(range(k))
plus  = sum(range(n+1-k,n+1))
count = plus - minus + 1

for i in range(k,n+1):
  plus += n-i
  minus += i
  
  count += plus - minus + 1
  count %= MOD
  
print(count)

Measured memory_bytes: 67508
#include <bits/stdc++.h>
using namespace std;

// 型定義
typedef long long ll;
typedef pair<ll, ll> P;

// forループ
#define REP(i,n) for(ll i=0; i<(ll)(n); ++i)

// 定数宣言
const int INF = 1e9;
const int MOD = 1e9+7;
const ll LINF = 1e18;

// グラフ表現
using Graph = vector<vector<int>>;

// グラフの辺表現
using Edge = map<pair<int,int>,int>;

// n次元配列の初期化。第２引数の型のサイズごとに初期化していく。
template<typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val){
    std::fill( (T*)array, (T*)(array+N), val );
}

// 最大公約数
ll gcd(ll a,ll b){
   if (a%b == 0) return(b);
   else return(gcd(b, a%b));
}

// 最小公倍数
ll lcm(ll a, ll b){
    return a*b/gcd(a, b);
}

int main()
{
    cout << fixed << setprecision(15);
    ll N, M;
    cin >> N >> M;

    if(N == 1 & M == 1){
        cout << 1 << endl;
        return 0;
    }
    if(N == 1){
        cout << M-2 << endl;
        return 0;
    }
    if(M == 1){
        cout << N-2 << endl;
        return 0;
    }

    cout << (M-2) * (N-2) << endl;

    return 0;
}

Measured memory_bytes: 256