akhauriyash/Code-Regression huggingface dataset:
#include<stdio.h>

int main() {
	int h, w;
	int i, j;

	while (1) {
		scanf("%d %d" ,&h ,&w);

		if (h == 0 && w == 0) {
			break;
		}

		for (i = 0; i < h ;i++) {
			for (j = 0; j < w; j++) {
				printf("#");
			}
			printf("\n");
		}
		printf("\n");
	}

	return 0;
}


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

using namespace std;
using ll = long long;
using vec = vector<ll>;
using mat = vector<vec>;

#define INF (1LL << 60)
#define MOD 1000000007

#define REP(i,m,n) for(ll (i)=(m),i_len=(n);(i)<(i_len);++(i))
#define FORR(i,v) for(auto (i):v)
#define ALL(x) (x).begin(), (x).end()
#define PR(x) cout << (x) << endl
#define PS(x) cout << (x) << " "
#define SZ(x) ((ll)(x).size())
#define MAX(a,b) (((a)>(b))?(a):(b))
#define MIN(a,b) (((a)<(b))?(a):(b))
#define pb push_back
#define mp make_pair

int main()
{
    ll N, M;
    cin >> N >> M;
    vec f(N+1, true);
    REP(i,0,M) {
        ll a;
        cin >> a;
        f[a] = false;
    }

    vec csum(N+1, 0);
    csum[0] = 1;
    if(f[1]) csum[1] = 1;
    REP(i,2,N+1) {
        if(f[i]) csum[i] = (csum[i] + csum[i-1] + csum[i-2]) % MOD;

    }
    PR(csum[N]);

    return 0;
}

/*



*/

Measured memory_bytes: 1792
#include <cstdlib>

#include <iostream>
#include <string>
#include <vector>
using namespace std;
typedef long long LL;

int main() {
  int N; cin >> N;
  LL sum = 0;
  for (LL i = 1; i <= N; ++i) {
    if (i % 3 == 0 || i % 5 == 0) continue;
    sum += i;
  }
  cout << sum << endl;
}


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

using namespace std;
#define rep(i, n) for(int i = 0 ; i < (int)(n) ; i++)
typedef long long ll;
typedef long double Double;

#ifndef INPUTS_DIR
#define INPUTS_DIR "./"
#endif


void solve(ll N, vector<ll> P) {
    map<ll, int> dp;
    int ans = 0;
    for (int i = 0; i < P.size(); i++) {
        dp[P[i]] = dp[P[i] - 1] + 1;
        ans = max(ans, dp[P[i]]);
    }
    cout << N - ans << endl;
}


void main_(istream &cin) {
    ll N;
    cin >> N;
    vector<ll> P(N - 1 + 1);
    for (int i = 0; i <= N - 1; i++) {
        cin >> P[i];
    }
    solve(N, P);
}

int main() {
#ifdef INTELLIJ
    ifstream ifs(string(INPUTS_DIR) + "in_1.txt");
    if (ifs.is_open()) {
        main_(ifs);
        ifs.close();
    } else {
        cerr << "Error: no input." << endl;
    }
#else
    ios::sync_with_stdio(false);
    cin.tie(0);
    main_(cin);
#endif
}





Measured memory_bytes: 15872
#!/usr/bin/env python3
import sys
sys.setrecursionlimit(10**7)
import bisect
import heapq
import itertools
import math
from collections import Counter, defaultdict, deque
from copy import deepcopy
from decimal import Decimal
from math import gcd
from operator import add, itemgetter, mul, xor
def cmb(n,r,mod):
  bunshi=1
  bunbo=1
  for i in range(r):
    bunbo = bunbo*(i+1)%mod
    bunshi = bunshi*(n-i)%mod
  return (bunshi*pow(bunbo,mod-2,mod))%mod
mod = 10**9+7
def I(): return int(input())
def LI(): return list(map(int,input().split()))
def MI(): return map(int,input().split())
def LLI(n): return [list(map(int, input().split())) for _ in range(n)]

#bisect.bisect_left(list,key)はlistのなかでkey未満の数字がいくつあるかを返す
#つまりlist[i] < x となる i の個数
#bisect.bisect_right(list, key)はlistのなかでkey以下の数字がいくつあるかを返す
#つまりlist[i] <= x となる i の個数
#これを応用することで
#len(list) - bisect.bisect_left(list,key)はlistのなかでkey以上の数字がいくつあるかを返す
#len(list) - bisect.bisect_right(list,key)はlistのなかでkeyより大きい数字がいくつあるかを返す
#これらを使うときはあらかじめlistをソートしておくこと！

n = I()
cnt = 0
b = 0
num = 0
for i in range(n):
    d1,d2 = MI()
    if d1 == d2:
        cnt += 1
    else:
        cnt = 0
    if cnt == 3:
        b = 1
        break
if b == 1:
    print("Yes")
else:
    print("No")
        


Measured memory_bytes: 10096
import java.util.*;

public class Main {
    public static void main(String args[]) {
        Scanner scn = new Scanner(System.in);
        int n = scn.nextInt();
        int pay = 1000;

        while(n>pay){
            pay += 1000;
        }

        System.out.println(pay-n);


        scn.close();

    }


}

Measured memory_bytes: 27020
/*
digu_J - Digvijay Janartha
NIT Hamirpur - INDIA
*/

#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#pragma GCC optimize("O3")

using namespace std;
using namespace __gnu_pbds;

template < typename T > using ordered_set = tree < T, null_type, less < T >, rb_tree_tag, tree_order_statistics_node_update >;
template < typename T > using MinPriorityQueue = priority_queue < T, vector < T >, greater < T > >;

#ifdef HOME
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template < typename Arg1 >
void __f(const char* name, Arg1&& arg1) {
    cout << name << " : " << arg1 << std :: endl;
}
template < typename Arg1, typename... Args >
void __f(const char* names, Arg1&& arg1, Args&&... args) {
    const char* comma = strchr(names + 1, ',');
    int len = comma - names;
    for (int i = 0; i < len; ++i) {
        cout << names[i];
    }
    cout <<  " : " << arg1 << " | ";
    __f(comma + 1, args...);
}
#else
#define trace(...)
#endif

typedef double db;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair < ll, ll > pll;
typedef pair < int, int > pii;
typedef vector < ll > vll;
typedef vector < int > vi;
typedef complex < double > com;

#define eb emplace_back
#define pb push_back
#define F first
#define S second
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define unique_sort(x) (sort(x.begin(), x.end()), x.resize(distance(x.begin(), unique(x.begin(), x.end()))))
#define fast_io() ios_base :: sync_with_stdio(0); cin.tie(0); cout.tie(0)

const ll LINF = LLONG_MAX, base = 1e9, MOD = 1e9 + 7, N = 1e5 + 5, M = 1e3 + 5, LG = 20;
const int INF = INT_MAX;
const db PI = acos(-1), EPS = 1 / db(1e6);
mt19937_64 rang(chrono::high_resolution_clock::now().time_since_epoch().count());

void test() {
    int n;
    cin >> n;
    vi a(n), b(n);
    for (int i = 0; i < n; ++i) {
        cin >> a[i];
    }
    for (int i = 0; i < n; ++i) {
        cin >> b[i];
    }
    if (a > b) {
        swap(a, b);
    }
    int ans = 0;
    while (a != b) {
        next_permutation(a.begin(), a.end());
        ++ans;
    }
    cout << ans << "\n";
}

int main() {
    fast_io();
    #ifdef HOME
        freopen("input.txt", "r", stdin);
        freopen("output.txt", "w", stdout);
    #endif
    cout << fixed << setprecision(15);
    test();
    #ifdef HOME
        cout << "Time: " << (int)(clock() * 1000. / CLOCKS_PER_SEC) << "ms";
    #endif
    return 0;
}


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

 
int main() {
    int N, ans=0, count=1;
    cin >> N;
    vector<int> a(N);
    for(int i=0; i<N; i++){
	cin >> a[i];
    }

    // for(int i=1; i<N/2+1; i++){
    // 	for(int j=i-1; j<2*i; j++){
    // 	    if(j>=N)
    // 		break;
    // 	    if(a[j]==i){
    // 		cout << i << endl;
    // 		return 0;
    // 	    }
    // 	}
    // }

    for(int i=0; i<N; i++){
	if(a[i]==count)
	    count++;
	else
	    ans++;	    
    }


    cout << (ans==N? -1: ans) << endl;
    
}


Measured memory_bytes: 1024
#include <vector>
#include <map>
#include <set>
#include <sstream>
#include <iostream>
#include <limits>

using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef pair<int, int> ii;
typedef vector<pair<int, int>> vii;
typedef stringstream ss;
const int mii = numeric_limits<int>::min();
const int mai = numeric_limits<int>::max();
const ll mil = numeric_limits<long long>::min();
const ll mal = numeric_limits<long long>::max();

#define REP(i, a, b) for(int i=a; i<=b; ++i)
#define RREP(i, a, b) for(int i=a; i>=b; --i)
#define PB(x) push_back(x)

int main(int argc, char **argv) {
    int x;

    cin >> x;

    ll res = 0;
    res += x/500 * 1000;
    x %= 500;
    res += x/5 * 5;

    cout <<res << endl;

    return 0;
}

Measured memory_bytes: 256
/*
Author: Fuadul Hasan(fuadul202@gmail.com)
BSMRSTU,Gopalganj
*/

#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <cmath>
#include <vector>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <queue>
#include <ctime>
#include <cassert>
#include <complex>
#include <string>
#include <cstring>
#include <chrono>
#include <random>
#include <queue>
#include <bitset>
//#include<bits/stdc++.h>
using namespace std;
 
int         cinn()              {int x; scanf("%d", &x); return x;}
long long   scll()              {long long x; scanf("%lld", &x); return x;}
double      scd()               {double x; scanf("%lf", &x); return x;}
void        coutt(int x)        {printf("%d ", x);}
 
#define  scll                   scll()
#define  gcd(a,b)               __gcd(a,b)
#define  lcm(a,b)               (a*b)/gcd(a,b)
#define  PI                     acos(-1.0)
#define  vi                     std::vector<int>
#define  vll                    std::vector<ll>
#define  vit                    vector<int> :: iterator
#define  sit                    set<int> :: iterator
#define  mpsi                   std::map<string, int>
#define  pb                     push_back
#define  ll                     long long int
#define  ld                     long double
#define  ull                    unsigned long long int
#define  min3(a,b,c)            min(a,min(b,c))
#define  min4(a,b,c,d)          min(d,min(a,min(b,c)))
#define  max3(a,b,c)            max(a,max(b,c))
#define  max4(a,b,c,d)          max(d,max(a,max(b,c)))
#define  nl                     printf("\n");
#define  no                     printf("No");
#define  yes                    printf("Yes");
#define  F                      first
#define  S                      second
 
const int mod           = 1e9 + 7;
const int inf           = (int)2e9 + 5;
const ll  Inf           = (ll)1e18 + 5;
const int N             = 1e6 + 5;
const int nn           = 2e5 + 5;


string p, h;

long long a[nn];
long long w[nn];


int solve()
{
	long long n,k,x,sum=0;
	cin>>n>>k;
	if(k>=n){
		cout<<0<<endl;
		return 0;
	}
	long long s = n-k;
	for(int i=0;i<n;i++){
		cin>>a[i];
	}
	sort(a,a+n);
	for(int i=0;i<s;i++){
		sum+=(long long)a[i];
	}
	cout<<sum<<endl;
}


int main()
{
    int test = 1, tc = 0;
    //scanf("%d", &test);
   // (void)getchar();
    //cin >> test;
    while (test--) {
        //printf("Case %d: ", ++tc);
        solve();
    }
 
    return 0;
}

Measured memory_bytes: 1792
#include<stdio.h>
#define MAX 101
#define INF 1000000
#define NIL -1
#define WHITE 0
#define GRAY 1
#define BLACK 2
int n,G[MAX][MAX];
void dijkstra();
int main(){
  int i,j,u,v,c,m;
  scanf("%d",&n);
  for(i=0;i<n;i++){
  scanf("%d %d",&u,&m);
  for(j=0;j<m;j++){
    scanf("%d %d",&v,&c);
    G[i][v]=c;
  }
  }
  for(i=0;i<n;i++){
    for(j=0;j<n;j++){
      if(G[i][j]==0) G[i][j]=NIL;
    }
  }
  dijkstra();
  return 0;
}

void dijkstra(){
  int i,u,mincost,color[MAX],d[MAX],pi[MAX];
  for(i=0;i<n;i++){
    d[i]=INF;
    pi[i]=NIL;
    color[i]=WHITE;
  }
  d[0]=0;
  while(1){
    mincost=INF;
    for(i=0;i<n;i++){
      if(color[i]!=BLACK && d[i]<mincost){
        mincost=d[i];
        u=i;
      }
    }
    if(mincost==INF) break;
    color[u]=BLACK;
    for(i=0;i<n;i++){
      if(G[u][i]!=NIL && color[i]!=BLACK && (G[u][i]+d[u])<d[i]){
	pi[i]=u;
	d[i]=G[u][i]+d[u];
      }
    }
  }
  for(i=0;i<n;i++){
    printf("%d %d\n",i,d[i]);
  }
}



Measured memory_bytes: 2052
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(10**7)

import operator

N,H,W = map(int,readline().split())
m = map(int,read().split())
RCA = sorted(zip(m,m,m),key=operator.itemgetter(2),reverse=True)

root = list(range(H+W))
size = [0] * (H+W)
no_cycle = [True] * (H+W)

def find_root(root,x):
    y = root[x]
    if x == y:
        return x
    path = [x]
    while y != root[y]:
        path.append(y)
        y = root[y]
    for p in path:
        root[p] = y
    return y

def merge(root,size,x,y):
    x,y = find_root(root,x),find_root(root,y)
    if x == y:
        return
    sx,sy = size[x],size[y]
    if sx < sy:
        sx,sy = sy,sx
        x,y = y,x
    root[y] = x
    no_cycle[x] = no_cycle[x] and no_cycle[y]

answer = 0
for R,C,A in RCA:
    x,y = R-1,H+C-1
    rx,ry = find_root(root,x),find_root(root,y)
    if rx == ry:
        if not no_cycle[rx]:
            continue
        no_cycle[rx] = False
    else:
        if (not no_cycle[rx]) and (not no_cycle[ry]):
            continue
        merge(root,size,rx,ry)
    answer += A

print(answer)

Measured memory_bytes: 34680
a,b=map(int,input().split())
list = [0]*a
t_cnt = 0
f_cnt = [0]*a
for i in range(b):
  c, d = map(str,input().split())
  x = int(c) - 1
  if list[x] == 0:
    if d == 'AC':
        list[x] = 1
        t_cnt += 1
    else:
        f_cnt[x] += 1
for i in range(a):
  if list[i] ==0:
    f_cnt[i] = 0
print("{} {}".format(t_cnt, sum(f_cnt)))

Measured memory_bytes: 4596
#include <iostream>

using namespace std;
int main()
{
    int h,w;
    cin>>h>>w;
    while(h!=0)
    {
        int i,j;
        for(i=0; i<h; i++)
        {
            for(j=0; j<w; j++)
                if(i==0||i==h-1||j==0||j==w-1)
                    cout<<"#";
                else
                    cout<<".";
            cout<<endl;

        }
        cin>>h>>w;
        cout<<endl;

    }
    return 0;
}



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

int main() {
    int h, w;
    cin >> h >> w;
    vector<string> lines(h);

    string s;
    int cnt = 0;
    for (int hi = 0; hi < h; hi++) {
        cin >> s;
        if (s.find("#") != string::npos) {
            lines.at(cnt) = s;
            cnt++;
        }
    }

    for (int i = w-1; i > -1; i--) {
        string tmp = "";
        for (int j = 0; j < cnt; j++) {
            tmp += lines.at(j).at(i);
        }

        if (tmp.find("#") == string::npos) {
            for (int j = 0; j < cnt; j++) {
                lines.at(j).erase(i, 1);
                // cout << "erased: " << lines.at(j) << endl;
            }
        }

    }

    int i = 0;
    while (i < cnt) {
        cout << lines.at(i) << endl;
        i++;
    }
}


Measured memory_bytes: 256
num = input()
if num.isdecimal():
    if int(num) <= 999:
        first_class_num = int(num[-1])
        if first_class_num in {2, 4, 5, 7, 9}:
            print("hon")
        elif first_class_num in {0, 1, 6, 8}:
            print("pon")
        elif first_class_num is 3:
            print("bon")


Measured memory_bytes: 9124
#include<stdio.h>
#include <string>
#include <iostream>
#include <iomanip>

using namespace std;

int main(){
  int l;
  cin >> l;

  double v = (l*l*l) / 27.0;
  cout << fixed << setprecision(15) << (l*l*l/27.0);
  return 0;
}

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

int main(){
int a,k,b;
cin >> a >> k >> b;
if(a+k < b){
 cout <<"NA" << endl;
 return 0;
}
if(a < b){
cout << b-a << endl;
 return 0;
 }
cout << 0 << endl;
}



Measured memory_bytes: 3116
#include <cstdio>
#include <iostream>
using namespace std;
int main()
{
    int n,ans=0;
    int a[3010];
    scanf("%d",&n);
    for(int i=1;i<=n;i++)
    {
        scanf("%d",&a[i]);
        ans+=a[i];
    }

    cout<<ans-n<<endl;
    return 0;
}


Measured memory_bytes: 256
n_and_l = input()

n, l = map(int, n_and_l.split())


text = []

for num in range(0, n):
    text.append(input())


for object in range(1, n):
    for compare in range(0, object):
        if text[object] < text[compare]:
            tmp = text[object]
            text[object] = text[compare]
            text[compare] = tmp

answer = ""

for num in range(0, n):
    answer = answer + text[num]

print(answer)

Measured memory_bytes: 3064
N = int(input())
x_list = [0] * N
u_list = [0] * N
rate = 380000.0

total = 0.0
for i in range(N):
    x, u = input().split()
    x = float(x)
    if u == "BTC":
        total += rate * x
    else:
        total += x

print(total)\


Measured memory_bytes: 2940
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define mod 1000000007

//read question carefully!

int32_t main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int t = 1;
    //cin >> t;
    while (t--)
    {
        int l, r, d;
        cin >> l >> r >> d;
        int ct = 0;
        for (int i = l; i <= r; ++i)
        {
            if (i % d == 0)
                ct++;
        }
        cout << ct << "\n";
    }
}

Measured memory_bytes: 3640
local DBG = false
function dbgpr(...)
    if DBG then
        io.write("[dbg]")
        print(...)
    end
end

function dbgpr_t(tbl)
    if DBG then
        dbgpr(tbl)
        io.write("[dbg]")
        for i,v in ipairs(tbl) do
            io.write(i)
            io.write(":")
            io.write(tostring(v))
            io.write(" ")
        end
        print("")
    end
end


local A, B = io.read("n", "n")
local function bit0()
    local a, b = A & 1, B & 1
    local b_minus_a = B - A
    local mod4 = b_minus_a % 4
    dbgpr(A,B,a,b,b_minus_a,mod4)
    if a == 0 then
        local t = {0,1,1,0}
        return t[mod4 + 1]
    else
        local t = {1,1,0,0}
        return t[mod4 + 1]
    end
end
local bits = {}
bits[1] = bit0()
dbgpr("bit0:", bits[1])
--if true then return end
-- 10**12 => 40bits
for iplus1=2, 40 do
    local i = iplus1 - 1
    local bitpos = 1 << i
    local a_posi, b_posi = A & bitpos, B & bitpos
    local a_mod, b_mod = A & (bitpos - 1), B & (bitpos - 1)
    local a_ones, b_ones
    if a_posi ~= 0 then
        a_ones = a_posi - a_mod
    else
        a_ones = 0
    end
    if b_posi ~= 0 then
        b_ones = b_mod + 1
    else
        b_ones = 0
    end
    local c
    if ((a_ones + b_ones) & 1) ~= 0 then
        c = 1
    else
        c = 0
    end
    dbgpr(i, a_ones, b_ones, (a_ones + b_ones) & 1, c)
    bits[iplus1] = c
end
dbgpr(#bits)
local ans_r = table.concat(bits)
local ans = string.reverse(ans_r)
dbgpr("ans in bin:",ans)
local Adec = 0
for i=0,39 do
    Adec = Adec + (bits[i+1] << i)
end
print(Adec)

Measured memory_bytes: 760
#include<map>
#include<set>
#include<cmath>
#include<stack>
#include<queue>
#include<deque>
#include<ctime>
#include<vector>
#include<bitset>
#include<string>
#include<cstdio>
#include<numeric>
#include<utility>
#include<sstream>
#include<cstdlib>
#include<iomanip>
#include<cstring>
#include<iostream>
#include<algorithm>
#include<functional>
#include<unordered_map>
#define _USE_MATH_DEFINES
#define inf 999999999999999999
#define rep(i,n,m) for(lli i=(lli)(n);i<(lli)(m);++i)
#define reep(i,n,m) for(int i=(int)(n);i<=(int)(m);++i)
#define per(i,m,n) for(lli i=(int)(m)-1;i>=(int)(n);--i)
#define st(n) sort(n.begin(), n.end())
#define rev(n) reverse(n.begin(),n.end())
#define ou(S) cout << S << endl
#define pb(n) push_back(n)
#define ue(N) N.erase(unique(N.begin(),N.end()),N.end());
#define nou(S) cout << S
#define hou(S) cout << setprecision(30) << S << endl
#define vec(K,L,N,S) vector<L> K(N,S)
#define dv(K,L,N,M,S) vector<vector<L>> K(N,vector<L>(M,S))
#define tv(K,L,N,M,R,S) vector<vector<vector<L>>> K(N,vector<vector<L>>(M,vector<L>(R,S)))
#define pint pair<lli,lli>
#define paf(L,R) pair<L,R>
#define maxx 5100000
#define chmax(a, b) a = (((a)<(b)) ? (b) : (a))
#define chmin(a, b) a = (((a)>(b)) ? (b) : (a))
#define endl "\n"
typedef long long int lli;
typedef unsigned long long int uli;
const uli mod = 1e9 + 7;
using namespace std;
int main() {
    ios::sync_with_stdio(false);
    cin.tie(NULL);

    double r;
    cin >> r;
    cout << fixed << setprecision(15) << r * 2 * 3.14159265358979 << endl;
}

Measured memory_bytes: 3804
#include<bits/stdc++.h>
using namespace std;
long long ans;
int n,x,atas,bawah;
vector<int> arr,tmp;

int main(){
	scanf("%d",&n);
	for(int i = 0;i<n;i++){
		scanf("%d",&x);
		arr.push_back(x);
		for(int j = 0;j<i;j++){
			tmp.push_back(arr[i]+arr[j]);
		}
	}
	sort(arr.begin(),arr.end());
	for(int i = 0;i<n;i++){
		for(int j = i+1;j<n;j++){
			atas = lower_bound(arr.begin(),arr.end(),arr[i]+arr[j])-arr.begin()-1;
			bawah = j;
//			printf("%d %d\n",atas,bawah);
			if(atas>bawah) ans += atas-bawah;
		}
	}
	
	printf("%lld\n",ans);
	return 0;
}

Measured memory_bytes: 10348
#include <iostream>
#include <cstdio>
using namespace std;

size_t diviser_cnt(const int start, const int end, const int target) {
  size_t cnt = 0;
  for (int i = start; i <= end; i++) {
    if (target % i == 0) cnt++;
  }
  return cnt;
}

int main() {
  int a,b,c;
  cin >> a >> b >> c;
  cout << diviser_cnt(a,b,c) << endl;
  return 0;
}


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

	#define itn int
	#define LL long long
	#define pb push_back
	#define mp make_pair
	#define x first
	#define y second
	#define all(x) (x).begin(), (x) end()
	#define sz(x) (int)((x).size())

	using namespace std;
	inline int GetInt(){
		int x;
		scanf("%d" , &x );
		return x;
	}
	inline string GetString(void){
		char x[100005];
		scanf("%s",x); string s = x;
		return s;
	}
	void solve(){
		int a = GetInt();
		int b = GetInt();
		int c = GetInt();

		if(b - a == c - b) cout << "YES";
		else{
			cout << "NO";
		}
	}	
	int main(){
	 
		/*#ifndef ONLINE_JUDGE
		freopen("input.txt", "r", stdin);
		freopen("output.txt", "w", stdout);
		#endif
		*/
		int T = 1;
	  	while(T--){
	    solve();
	  }
	  	
	  	return 0;
	}


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

using namespace std;

int main()
{
  int N, K;
  cin >> N >> K;
  if(N < 2*K) {
    cout << -1 << endl;
    return 0;
  }
  typedef pair<int, int> P;
  vector<P> edges;
  int u = 0, v = N-1;
  for(int i = 0; u < v; i++) {
    edges.emplace_back(u, v);
    if(i % 2) v--;
    else u++;
    tie(u, v) = minmax(u, v);
  }
  for(int i = 0; i < K; i++) {
    if(i) cout << endl;
    for(P &e : edges) {
      cout << e.first+1 << " " << e.second+1 << endl;
      e.first = (e.first - 1 + N) % N;
      e.second = (e.second - 1 + N) % N;
    }
  }
  return 0;
}

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

using namespace std;
using ll = long long;

#define rep(i, a) for (int i = 0; (i) < (int) (a); (i)++)
#define reps(i, a, b) for (int i = (int) (a); (i) < (int) (b); (i)++)
#define rrep(i, a) for (int i = (int) a-1; (i) >= 0; (i)--)
#define rreps(i, a, b) for (int i = (int) (a)-1; (i) >= (int) (b); (i)--)
#define MP(a, b) make_pair((a), (b))
#define PB(a) push_back((a))
#define all(v) (v).begin(), (v).end()
#define PERM(v) next_permutation(all(v))
#define UNIQUE(v) sort(all(v));(v).erase(unique(all(v)), v.end())
#define CIN(type, x) type x;cin >> x
#define TRUE__  "YES"
#define FALSE__ "NO"
#define PRINT(f) if((f)){cout << (TRUE__) << endl;}else{cout << FALSE__ << endl;}
#define RS resize
#define CINV(v, N) do {\
	v.RS(N);\
	rep(i, N) cin >> v[i];\
} while (0);
#define RCINV(v, N) do {\
	v.RS(N);\
	rrep(i, N) cin >> v[i];\
} while (0);

#define MOD 1000000007

void init();
void solve();

signed main()
{
	init();
	solve();
}

int N;
vector<vector<int> > v;
vector<vector<bool> > f;

void init()
{
	cin >> N;
	rep(i, N) {
		v.PB(vector<int>(N));
		f.PB(vector<bool>(N, true));
		rep(j, N) {
			cin >> v[i][j];
		}
	}
}

ll calc()
{
	ll res = 0;
	rep(k, N) {
		rep(i, N) {
			rep(j, N) {
				if (k == i || k == j) continue;
				int l = v[i][j];
				int r = v[i][k] + v[k][j];
				if (l > r) return -1;
				if (l == r) {
					f[i][j] = false;
				}
			}
		}
	}
	rep(i, N) reps(j, i+1, N) {
		if (f[i][j]) {
			res += v[i][j];
		}
	}
	return res;
}

void solve()
{
	cout << calc() << endl;
}





Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int mod = 1000000007;

int main()
{
	string s, t;
	cin >> s >> t;
	t.pop_back();
	if (s == t) cout << "Yes" << endl;
	else cout << "No" << endl;
}


Measured memory_bytes: 3628
#include <stdio.h>
#define MAX 100000

int parent(int);
int left(int);
int right(int);

int main(){
    int n,i;
    int A[MAX+1];
    scanf("%d",&n);
    for(i=1;i<=n;i++) scanf("%d",&A[i]);
    for(i=1;i<=n;i++){
        printf("node %d: key = %d, ",i,A[i]);
        if(parent(i)>=1) printf("parent key = %d, ",A[parent(i)]);
        if(left(i)<=n) printf("left key = %d, ",A[left(i)]);
        if(right(i)<=n) printf("right key = %d, ",A[right(i)]);
        printf("\n");
    }
    return 0;
}
int parent(int i){
    return i/2;
}
int left(int i){
    return i*2;
}
int right(int i){
    return i*2+1;
}


Measured memory_bytes: 2048
#include<map>
#include<set>
#include<list>
#include<cmath>
#include<queue>
#include<stack>
#include<cstdio>
#include<string>
#include<vector>
#include<complex>
#include<cstdlib>
#include<cstring>
#include<numeric>
#include<sstream>
#include<iostream>
#include<algorithm>
#include<functional>
#include <cstdlib>
#include <cctype>
#include <cstdio>
#include <iostream>
using namespace std;
int main(){
	string S;
	while(cin>>S){
	int joi=0;
	for(int j=0;j<S.size();j++){
			if(S[j]=='J' && S[j+1]=='O' && S[j+2]=='I'){
				joi++;
			}
	}
	int ioi=0;
	for(int i=0;i<S.size();i++){
			if(S[i]=='I' && S[i+1]=='O' && S[i+2]=='I'){
				ioi++;
			}
	}
	cout<<joi<<endl<<ioi<<endl;
    }
	return 0;
}

Measured memory_bytes: 1200
n = input()
P = set()
gx = gy = 0
for i in xrange(n):
    x, y = map(int, raw_input().split())
    P.add((n*x, n*y))
    gx += x; gy += y
ok = 1
for x, y in P:
    x += 2*(gx - x)
    y += 2*(gy - y)
    if (x, y) not in P:
        ok = 0
if ok:
    print "%.08f %.08f" % (gx/float(n), gy/float(n))
else:
    print "NA"

Measured memory_bytes: 6464
#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;

int main(){
    while(1){
        int n; cin>>n;
        if(n == 0) return 0;

        vector<int> b(n);
        for(int i=0; i<n; i++) cin>>b[i];

        for(int i=0; i<=10001; i++){
            if(i == 10001){
                cout << -1 << endl;
                break;
            }

            bool valid = true;
            for(int j=0; j<b.size(); j++){
                if(j + 1 != b[j]) valid = false;
            }

            if(valid){
                cout << i << endl;
                break;
            }

            for(int j=0; j<b.size(); j++){
                b[j]--;
            }

            b.emplace_back(b.size());
            b.erase(remove(b.begin(), b.end(), 0), b.end());
        }
    }
}


Measured memory_bytes: 3148
/*The woods are lovely, dark and deep,
But I have promises to keep,
And miles to go before I sleep,
And miles to go before I sleep.*/

//PRABHJOT SINGH A.K.A. PRABHI
//~~~~~conquizztador~~~~~


#include<bits/stdc++.h>
using namespace std;
using lli = long long int;
#define pb push_back
#define eb emplace_back
#define fi first
#define se second
const int MOD = 1000000007;
const int MOD1 = 998244353;
const int maxn = 100010;
const int lim = (int)1e9;
vector<int> parent;
int FIND(int node)
{
	if (node == parent[node])
		return node;
	return parent[node] = FIND(parent[node]);
}
void DSU(int a, int b)
{
	a = FIND(a); b = FIND(b);
	if (a != b)
		parent[a] = b;
}
int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	int n = 0, q = 0, ch = 0, x = 0, y = 0;
	cin >> n >> q;
	parent.resize(n);
	for (int i = 0; i < n; ++i)
		parent[i] = i;
	for (int i = 0; i < q; ++i)
	{
		cin >> ch >> x >> y;
		if (ch == 0)
			DSU(FIND(x), FIND(y));
		else
		{
			if (FIND(x) == FIND(y))
				cout << "1\n";
			else
				cout << "0\n";
		}
	}
}

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

#define rep(i, n) for(int i = 0; i < (int)(n); i++)
using ll = long long int;

int main() {

    int A,B;
    cin >> A >> B;

    int ans;

    ans = ceil(((double)B-1)/((double)A-1));

    cout << (int)ans << endl;

    return 0;
}


Measured memory_bytes: 256
class Combination:
    """
  O(n)の前計算を1回行うことで，O(1)でnCr mod mを求められる
  n_max = 10**6のとき前処理は約950ms (PyPyなら約340ms, 10**7で約1800ms)
  使用例：
  comb = Combination(1000000)
  print(comb(5, 3))  # 10
  """

    def __init__(self, n_max, mod=10 ** 9 + 7):
        self.mod = mod
        self.modinv = self.make_modinv_list(n_max)
        self.fac, self.facinv = self.make_factorial_list(n_max)

    def __call__(self, n, r):
        if n < r or n < 0 or r < 0:
            return 0
        return self.fac[n] * self.facinv[r] % self.mod * self.facinv[n - r] % self.mod

    def make_factorial_list(self, n):
        # 階乗のリストと階乗のmod逆元のリストを返す O(n)
        # self.make_modinv_list()が先に実行されている必要がある
        fac = [1]

        facinv = [1]
        for i in range(1, n + 1):
            fac.append(fac[i - 1] * i % self.mod)
            facinv.append(facinv[i - 1] * self.modinv[i] % self.mod)
        return fac, facinv

    def make_modinv_list(self, n):
        # 0からnまでのmod逆元のリストを返す O(n)
        modinv = [0] * (n + 1)
        modinv[1] = 1
        for i in range(2, n + 1):
            modinv[i] = self.mod - self.mod // i * \
                modinv[self.mod % i] % self.mod
        return modinv


MOD = 10**9 + 7

r1, c1, r2, c2 = map(int, input().split())
c = Combination(2000006)
ans = 0
for r in range(r1, r2 + 1):
    temp = c(c2 + r + 1, r + 1) - c(c1 + r + 1 - 1, r + 1)
    temp %= MOD
    ans += temp
    ans %= MOD
print(ans)


Measured memory_bytes: 211764
/// In the name of God
#include <bits/stdc++.h>
#define int long long
using namespace std;
typedef pair<int,int> pii;
typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
#define X first
#define Y second
#define all(o) o.begin(), o.end()
#define IOS ios::sync_with_stdio(0), cin.tie(0)
const int maxn =1e6;
int a[maxn], ps[maxn], good[maxn];
main(){
    int n, k;
    cin >> n >> k;
    for(int i=0; i<n; i++)
        cin >> a[i];
    for(int i=0; i<n; i++)
        ps[i + 1] = ps[i] + a[i];
    for(int i=0; i<n; i++)
        good[i + 1] = good[i] + (a[i] >= 0 ? a[i] : 0);
    int ans = 0;
    for(int i=0; i+k<=n; i++){
        int t1 = good[i];
        int t2 = good[n] - good[i + k];
        int t3 = max(0LL, ps[i + k] - ps[i]);
        ans = max(ans, t1 + t2 + t3);
    }
    cout << ans << endl;
}


Measured memory_bytes: 2560
#include<iostream>
#include<vector>
#include<cmath>
using namespace std;
int main() {
  int n,d,ans=0;
  cin >> n >> d;
  vector<vector<int>> X(n,vector<int>(d));
  for(int i=0;i<n;i++){
    for(int j=0;j<d;j++){
      cin >> X[i][j];
    }
  }
  // 全てのiとjについての探索
  for(int i=0;i<n;i++){
    for(int j=i+1;j<n;j++){
      int ddist=0; // 2点間の距離の二乗
      for(int k=0;k<d;k++){
        int dist = abs(X[i][k]-X[j][k]); // 2点間の距離
        ddist += dist*dist;
      }
      // ddistが平方数であるかどうかの判定
      bool flag = false;
      for(int k=0;k<=ddist;k++){
        if(k*k==ddist) flag = true;
      }
      if(flag) ans++;
    }
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256
#include <algorithm>
#include <iostream>
#include <iomanip>
#include <cassert>
#include <cstring>
#include <string>
#include <vector>
#include <random>
#include <bitset>
#include <queue>
#include <cmath>
#include <unordered_map>
#include <set>
#include <map>
#define INCANT cin.tie(0), cout.tie(0), ios::sync_with_stdio(0)
#define rep(i,n) for (int i=0; i<n;++i)
#define ALL(a)  (a).begin(),(a).end()
typedef long long ll;
using namespace std;
ll N, K;

int main() {
  INCANT;
  cin >> N >> K;
  ll cnt=0ll;
  for (ll b=K+1; b<=N; b++) {
    ll tmp=0ll;
    ll syo=N/b;
    ll amari =N%b;
    tmp+=max(amari-K+1ll,0ll);
    tmp+=(b-K)*syo;
    cnt+=tmp;
    if (!K) cnt--;
  }

  cout << cnt << "\n";
  return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<algorithm>
#include<math.h>
#include<string>
#include<map>
#include<queue>

using namespace std;

int main(void) {
	int n, m;
	cin >> n >> m;
	priority_queue<int>q;
	for (int i = 0; i < n; i++) {
		int a;
		cin >> a;
		q.push(a);
	}
	for (int i = 0; i < m; i++) {
		int a;
		a = q.top();
		q.pop();
		q.push(a / 2);
	}
	long long int ans = 0;
	for (int i = 0; i < n; i++) {
		ans += q.top();
		q.pop();
	}
	cout << ans << endl;
}

Measured memory_bytes: 892
while 1:
    N=int(input())
    if not N:break
    cd={tuple(map(int,input().split())) for _ in range(N)}
    c=set()
    x,y=10,10
    M=int(input())
    for _ in range(M):
        d,l=input().split()
        l=int(l)
        if d=="N":
            sc={(x+i,y+j) for i in range(1) for j in range(0,l+1,1)}
            y+=l
        elif d=="S":
            sc={(x+i,y+j) for i in range(1) for j in range(0,-l-1,-1)}
            y-=l
        elif d=="E":
            sc={(x+i,y+j) for i in range(0,l+1,1) for j in range(1)}
            x+=l
        else:
            sc={(x+i,y+j) for i in range(0,-l-1,-1) for j in range(1)}
            x-=l
        c=c|(sc&cd)
    if c==cd:
        print("Yes")
    else:
        print("No")



Measured memory_bytes: 5752
#include <bits/stdc++.h>
using namespace std;
#define fo(i, n) for (i = 0; i < n; i++)
#define Fo(i, k, n) for (i = k; k < n ? i < n : i > n; k < n ? i += 1 : i -= 1)
#define ll long long
#define si(x) scanf("%d", &x)
#define sl(x) scanf("%lld", &x)
#define ss(s) scanf("%s", s)
#define pi(x) printf("%d\n", x)
#define pl(x) printf("%lld\n", x)
#define ps(s) printf("%s\n", s)
#define deb(x) cout << #x << "=" << x << endl
#define deb2(x, y) cout << #x << "=" << x << ", " << #y << "=" << y << endl
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define all(x) x.begin(), x.end()
#define clr(x) memset(x, 0, sizeof(x))
#define sortall(x) sort(all(x))
#define tr(it, a) for (auto it = a.begin(); it != a.end(); it++)
#define PI 3.1415926535897932384626
typedef pair<int, int> pii;
typedef pair<ll, ll> pl;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<pii> vpii;


int main()
{
    ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
    srand(chrono::high_resolution_clock::now().time_since_epoch().count());
    int m = 1e9 + 7;
    int n, i;
    cin>>n;
    ll x = 1;
    for(i = 1; i<=n; i++) {
        x = (x*i)%m;
    }

    cout<<x;

return 0;
}

Measured memory_bytes: 3648
N=int(input())
A=list(map(int,input().split()))
B=list(map(int,input().split()))
C=list(map(int,input().split()))
s=0
for i in range(0,N):
    s=s+B[i]
for k in range(0,N-1):
    if A[k+1]-A[k]==1:
        s=s+C[A[k]-1]
    else:
        continue
print(s)


Measured memory_bytes: 3064
# -*- coding: utf-8 -*-
n = int(input())
al = list(map(int, input().split()))

s = 0
res = 0
l = r = 0
while l<n:
    while r<n and s^al[r]==s+al[r]:
        s += al[r]
        r += 1

    res += r-l

    if r==l:
        r += 1
    else:
        s -= al[l]

    l += 1

print(res)

Measured memory_bytes: 24424
#include <iostream>
#include <vector>
#include <algorithm>
#include <thread>
#include <sstream>
#include <unordered_set>
#include <future>
using namespace std;



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

  int n;
  cin >> n;
  std::vector<int> v(3 * n);

  for (auto& el : v) {
    cin >> el;
  }
  std::sort(v.begin(), v.end());
  int64_t sum = 0;
  for (int i = 3 * n - 2, j = 0; j < n; j++, i -= 2) {
    sum += v[i];
  }
  cout << sum << endl;

}

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

int main(void) {
    int N,T,A;
    int h;
    int diff,pos,mindiff = INT_MAX;
    cin >> N >> T >> A;

    A *= 1000;
    T *= 1000;
    for(int i=0;i<N;i++) {
        cin >> h;
        diff = (T-h*6) - A;
        if(mindiff > abs(diff)) {
            mindiff = abs(diff);
            pos = i+1;
        }
    }
    
    cout << pos << endl;
    return 0;
}


Measured memory_bytes: 256
#![allow(unused_imports)]
#![allow(non_snake_case)]
use std::cmp::*;
use std::collections::*;
use std::io::Write;

#[allow(unused_macros)]
macro_rules! debug {
    ($($e:expr),*) => {
        #[cfg(debug_assertions)]
        $({
            let (e, mut err) = (stringify!($e), std::io::stderr());
            writeln!(err, "{} = {:?}", e, $e).unwrap()
        })*
    };
}

fn main() {
    let v = read_vec::<i64>();
    let (n, mut a, mut b) = (v[0], v[1], v[2]);
    if (a - b).abs() % 2 == 0 {
        println!("{}", (a - b).abs() / 2);
    } else {
        if a < b {
            std::mem::swap(&mut a, &mut b);
        }
        let temp1 = (n - b + 1 + n - a) / 2;
        let temp2 = (b + a - 1) / 2;
        println!("{}", min(temp1, temp2));
    }
}

fn read<T: std::str::FromStr>() -> T {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim().parse().ok().unwrap()
}

fn read_vec<T: std::str::FromStr>() -> Vec<T> {
    read::<String>()
        .split_whitespace()
        .map(|e| e.parse().ok().unwrap())
        .collect()
}


Measured memory_bytes: 4352
#include <bits/stdc++.h>
#define int long
#define ll long long
#define rep(i, n) for(int i = 0; i < n; i++)
using namespace std;

main() {
    int N,M; cin >> N >> M;
    int A[N],B[N],C[M],D[M];
    rep(i,N){
        cin >> A[i] >> B[i];
    }
    rep(i,M){
        cin >> C[i] >> D[i];
    }
    rep(i,N){
        int ans=1000000000; int pos;
        rep(j,M){
            if(ans>abs(A[i]-C[j])+abs(B[i]-D[j])){
                ans=abs(A[i]-C[j])+abs(B[i]-D[j]);
                pos=j+1;
            }
        }
        cout << pos << endl;
    }

    return 0;
}

Measured memory_bytes: 256
package main

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

var sc = bufio.NewScanner(os.Stdin)

func nextInt() int {
	sc.Scan()
	i, e := strconv.Atoi(sc.Text())
	if e != nil {
		panic(e)
	}
	return i
}

func main() {
	var n int

	sc.Split(bufio.ScanWords)
	n = nextInt()

	r := n % 10

	if r == 3 {
		fmt.Println("bon")
	} else if r == 0 || r == 1 || r == 6 || r == 8 {
		fmt.Println("pon")
	} else {
		fmt.Println("hon")
	}
}

Measured memory_bytes: 1776
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
using namespace std;

int top, S[1000];

void push(int x) {
    //topをインクリメントしてからその位置へ挿入
    S[++top] = x;
}

int pop() {
    top--;
    //topが示していた要素を返す
    return S[top+1];
}

int main() {
    int a, b;
    top = 0;
    char s[100];

    while(scanf("%s", s) != EOF) {
        if(s[0] == '+') {
            a = pop();
            b = pop();
            push(a + b);
        } else if (s[0] == '-') {
            b = pop();
            a = pop();
            push(a - b);
        } else if( s[0] == '*') {
            a = pop();
            b = pop();
            push(a * b);
        } else {
            push(atoi(s));
        }
    }
    printf("%d\n", pop());

    return 0;
}


Measured memory_bytes: 2732
#include <iostream>
#include<algorithm>
#include<cstdio>
#include<math.h>
using namespace std;
int main()
{
    int a[100+5],n,i,sum=0;
    scanf("%d",&n);
    for(i=0;i<n;i++)
    {
        scanf("%d",&a[i]);
        sum+=a[i];
    }
    int s1=0,s2,ans=1000;
    for(i=0;i<n;i++)
    {
        s1+=a[i];
        s2=sum-s1;
        ans=min(ans,abs(s2-s1));
        if(ans==0)
            break;
    }
    printf("%d\n",ans);
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <map>
#include <cstring>
#include <iomanip>

using namespace std;

int main(){
    long long X,Y;
    cin >> X >> Y;
    if(X%Y==0){
        cout << -1 << endl;
    }
    else{
        cout << X << endl;
    }
    return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main{
    public static void main(String[] args){
	Scanner sc = new Scanner(System.in);
	int n, r, p, c;
	int[] num;
	int[] pc;
	while(true){
	    n = sc.nextInt();
	    r = sc.nextInt();
	    if(n==0 && r==0) break;
	    num = new int[n];
	    for(int i=0;i<n;i++) num[i] = n-i;
	    for(int i=0;i<r;i++){
		p = sc.nextInt();
		c = sc.nextInt();
		pc = new int[p-1];
		for(int j=0;j<p-1;j++) pc[j]  = num[j];
		for(int j=0;j<c;j++) num[j] = num[j+p-1];
		for(int j=0;j<p-1;j++) num[j+c] = pc[j];	 
	    }
	    System.out.println(num[0]);
	}
    }
}

Measured memory_bytes: 36856
#include <iostream>
#include <vector>
#include <climits>
#include <algorithm>
#include <cmath>
#include <map>
#include <set>
#include <string>
#include <bitset>
#include <utility>
#include <numeric>
#include <queue>
#include <stack>

using ll = long long;
using namespace std;

constexpr int MOD = 1e9 + 7;
constexpr ll MOD_LL = ll(1e9) + 7;

int main(void) {
	int N, T;
	cin >> N >> T;
	
	int ans = MOD;
	bool yes = false;
	for(int i = 0; i < N; ++i) {
		int c, t;
		cin >> c >> t;
		
		if( t <= T ) {
			ans = min(ans, c);
			yes = true;
		}
	}
	
	if( yes ) cout << ans << endl;
	else cout << "TLE" << endl;
	
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) FOR(i,0,n)
#define ALL(v) begin(v),end(v)
#define fi first
#define se second
template<typename A, typename B> inline bool chmax(A &a, B b) { if (a<b) { a=b; return 1; } return 0; }
template<typename A, typename B> inline bool chmin(A &a, B b) { if (a>b) { a=b; return 1; } return 0; }
using ll = long long;
using pii = pair<int, int>;
constexpr ll INF = 1ll<<30;
constexpr ll longINF = 1ll<<60;
constexpr ll MOD = 1000000007;
constexpr bool debug = 0;
//---------------------------------//

int main() {
	ll X, K, D;
	cin >> X >> K >> D;
	X = abs(X);
	ll cnt = min(K, X / D);
	X -= cnt * D;
	K -= cnt;
	
	if (K == 0) {
		cout << X << endl;
		return 0;
	}
	
	ll ans = K & 1 ? -(X - D) : X;
	cout << ans << endl;
	
	return 0;
}


Measured memory_bytes: 3664
#include <iostream>

using namespace std;

int josephus(int n, int k)
{
	if(n == 1)
	{
		return(0);
	}
	return((josephus(n - 1, k) + k) % n);
}

void solve()
{
	int n, k, m;
	while(cin >> n >> k >> m, n || k || m)
	{
		m = (m - k + 1 + n) % n;
		cout << (josephus(n, k) + m - 1 + n) % n + 1 << endl;
	}
}

int main()
{
	solve();
	return(0);
}

Measured memory_bytes: 1468
#include<cstdio>
#include<iostream>
#include<cstring>
#include<algorithm>
#define LL long long
using namespace std;
const int NN=310;
const int MM=1<<7;
int read(){
	int fl=1,x;char c;
	for(c=getchar();(c<'0'||c>'9')&&c!='-';c=getchar());
	if(c=='-'){fl=-1;c=getchar();}
	for(x=0;c>='0'&&c<='9';c=getchar())
		x=(x<<3)+(x<<1)+c-'0';
	return x*fl;
}
LL dp[NN][MM][NN]={};
int n;
int l;
int a[12]={};
void get_ans(){
	memset(dp,0,sizeof dp);
	dp[0][0][n*a[n]]=1;
	for(int i=0;i<n*l;++i){
		for(int s=0;s<(1<<(n-1));++s){
			for(int j=i;j<=n*l;++j){
				dp[i+1][s][j]+=dp[i][s][j];
			}
			if(i%n!=0&&(s&(1<<(i%n-1)))==0){
				for(int j=i;j<=n*l;++j){
					dp[i+1][s|(1<<(i%n-1))][min(n*l,max(j,i+a[i%n]*n))]+=dp[i][s][j];
				}
			}
		}
	}
}
int main(){
	//freopen("test.in","r",stdin);
	n=read();
	l=read();
	for(int i=1;i<=n;++i){
		a[i]=read();
	}
	sort(a+1,a+n+1);
	LL cas=1;
	LL cnt=1;
	long double ans=0;
	for(int i=1;i<n;++i){
		cas*=i;
		cnt*=l;
	}
	for(int i=1;i<=cas;++i){
		next_permutation(a+1,a+n);
		get_ans();
		ans+=(long double)dp[n*l][(1<<(n-1))-1][n*l]/cnt;
	}
	ans/=cas;
	printf("%.13Lf\n",ans);
}

Measured memory_bytes: 96512
#include <cstdio>
#include <iostream>
#include <cmath>
#include <cstring>
#include <sstream>
#include <algorithm>
#include <cstdlib>
#include <map>
#include <queue>
#include <utility>
#include <vector>
#include <set>
#include <memory.h>
#include <iomanip>
#include <bitset>
#include <list>
#include <stack>

using namespace std;

#define mod 1000000007

int main()
{
	int a, b, c;
	map<int, int> m;
	cin >> a >> b >> c;
	m[a] = 1;
	m[b] = 1;
	m[c] = 1;
	cout << m.size() << endl;
	return 0;
}

Measured memory_bytes: 256
inp = require('fs').readFileSync('/dev/stdin', 'utf8').trim().split('\n')
N = inp.shift() * 1
S = inp.shift()

x = []
y = []
a = {}
b = {}

for (i=0;i<N;i++) {
    a[S[i]] = 1
    b[S[N-i-1]] = 1
    x[i] = Object.keys(a).sort()
    y[N-i-1] = Object.keys(b).sort()
}
max = 0
for (i=0; i<N-1; i++) {
    k = 0
    cnt = 0
    for (j=0;j<x[i].length && k<y[i+1].length; j++) {
        if (y[i+1].indexOf(x[i][j]) >= 0) {
            cnt++
        }
    }
    if (max < cnt) {
        max = cnt
    }
}
console.log(max)

Measured memory_bytes: 20296
#include<iostream>
#include<string>
using namespace std;


int main(){
    int N,val;
    cin>>N;
    int ans=50;
    for(int i=0;i<N;i++){
        cin>>val;
        int tmp=0;
        while(val%2==0){
            val/=2;
            tmp++;
        }
        ans=min(ans,tmp);
    }
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 256
#ifndef __cplusplus
    cat << EOF
#endif
#include <bits/stdc++.h>
using namespace std;

#define rep(...) overload_rep(__VA_ARGS__, rep_1, rep_0)(__VA_ARGS__)
#define rep_0(i, end) for(int i = 0; i < (end); ++i)
#define rep_1(i, fr, ba) for(int i = (fr); i <= (ba); ++i)
#define overload_rep(arg0, arg1, arg2, name, ...) name
#define all(box) box.begin(), box.end()

template <class T, class U> inline bool chmax(T& lhs, const U& rhs) { if(lhs < rhs) { lhs = rhs; return 1; } return 0; }
template <class T, class U> inline bool chmin(T& lhs, const U& rhs) { if(lhs > rhs) { lhs = rhs; return 1; } return 0; }

int main() {

    int n, m;
    cin >> n >> m;
    cout << n * m << '\n';

}



Measured memory_bytes: 3108
import java.util.Scanner
import java.lang.Math

fun main(args: Array<String>) {
    val sc = Scanner(System.`in`)
    val N = sc.nextLong()
    val A = sc.nextLong()
    val B = sc.nextLong()
    var ans = N / (A + B) * A + Math.min(A, N % (A + B))
    println(ans)
}

Measured memory_bytes: 31396
#include<iostream>
#include<cstdlib>
#include<string>
#include<vector>
#include<algorithm>
#include<cmath>
#include<set>
#include<utility>
using namespace std;
 
typedef long long ll;
 
int main(){
  int a[32] = {1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51};
  int b;
  cin >> b;
  cout << a[b-1];
}

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

int main() {
	int n; cin >> n;

	int sum = 0;
	int a = n;
	while (a > 0) {
		sum += a % 10;
		a /= 10;
	}

	if (n % sum == 0) cout << "Yes" << endl;
	else cout << "No" << endl;

	return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
int main(){
	int n;
	int candies = 0;
	
	scanf("%d", &n);	//children
						//1 candy first line, 2 candy second line, n candy to n line
	for(int i=0; i<=n; i++){	//selama i <= n, i nambah, danutk tiap line, si candy nambah
		candies += i;
	}
	printf("%d", candies);
	
	return 0;
}

Measured memory_bytes: 1696
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define vr vector
#define pb push_back
#define watch(x) cout << (#x) << " is " << (x) << endl
#define mod 1000000007
#define all(v) v.begin(),v.end()

bool check(ll j,ll x)
{
    if(x&(1<<j))
        return true;
    else
        return false;
}


  int main()
{
     ios_base::sync_with_stdio(false);
     cin.tie(NULL);
     //ll t;
     // cin>>t;
      //while(t--)
      {
        ll s,w;
        cin>>s>>w;
        if(w>=s)
            cout<<"unsafe";
        else
            cout<<"safe";

          cout<<endl;

      }
 return 0;
  }



Measured memory_bytes: 3640
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using p = pair<int, int>;
#define INF 1001001001
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define repX(i, n ,x) for (int i = x; i < (int)(n); i++)
#define repBack(i, n) for (int i = n; i >= 0; i--)
#define dup(x,y) (((x)+(y)-1)/(y))

int main() {
    int K,X;
    cin >> K >> X;
    rep(i,K*2-1){
        cout << X-(K-1)+i << endl;
    }

    return 0;
}

Measured memory_bytes: 256