akhauriyash/Code-Regression huggingface dataset:
#include<algorithm>
#include<bitset>
#include<cassert>
#include<cfloat>
#include<climits>
#include<cmath>
#include<deque>
#include<functional>
#include<iomanip>
#include<iostream>
#include<map>
#include<queue>
#include<set>
#include<stack>
#include<string>
#include<unordered_map>
#include<unordered_set>
#include<utility>
#include<vector>

#define REP(i, n) for(int i = 0;i < n;i++)
#define REPR(i, n) for(int i = n;i >= 0;i--)
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define FORR(i, m, n) for(int i = m;i >= n;i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define llong long long
#define pb(a) push_back(a)

using namespace std;

typedef long long int ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;


template<typename T>
vector<T> make_v(size_t a) { return vector<T>(a); }
template<typename T, typename... Ts>
auto make_v(size_t a, Ts... ts) {
	return vector<decltype(make_v<T>(ts...))>(a, make_v<T>(ts...));
}
template<typename T, typename V>
typename enable_if<is_class<T>::value == 0>::type
fill_v(T& t, const V& v) { t = v; }
template<typename T, typename V>
typename enable_if<is_class<T>::value != 0>::type
fill_v(T& t, const V& v) {
	for (auto& e : t) fill_v(e, v);
}


// aよりもbが大きいならばaをbで更新する
// (更新されたならばtrueを返す)
template <typename T>
bool chmax(T & a, const T & b) {
	if (a < b) {
		a = b;  // aをbで更新
		return true;
	}
	return false;
}
// aよりもbが小さいならばaをbで更新する
// (更新されたならばtrueを返す)
template <typename T>
bool chmin(T & a, const T & b) {
	if (a > b) {
		a = b;  // aをbで更新
		return true;
	}
	return false;
}


#define ARRAY_MAX 100005
const int INF = 1e9 + 7;
const ll MOD = 1e9 + 7;

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


/******************************************************************************************/


int dp[105][10][10];//dp[桁][nと同じか][0以外の個数]

int main() {

	cin.tie(0);
	ios::sync_with_stdio(false);
	cout << fixed << setprecision(10);

	string s;
	int k;
	cin >> s >> k;
	int n = s.size();
	dp[0][0][0] = 1;

	//上からi桁目を見る
	for (int i = 0; i < n; i++)
	{
		//未満フラグ,1なら未満
		for (int smaller = 0; smaller < 2; smaller++)
		{
			//0以外の数字の個数
			for (int j = 0; j <= k; j++)
			{
				//使う数字
				for (int x = 0; x <= (smaller ? 9 : s[i] - '0'); x++)
				{
					dp[i + 1][smaller || x < s[i] - '0'][(x == 0) ? j : j + 1] += dp[i][smaller][j];
				}
			}
		}
	}


	//cout << n << endl;
	cout << dp[n][1][k] + dp[n][0][k] << endl;

	return 0;
}



Measured memory_bytes: 256
#include<bits/stdc++.h>
#include<algorithm>
using namespace std;
int main(){
//	freopen(".in","r",stdin);
//	freopen(".out","w",stdout);
	unsigned long long n,m;
	cin>>n>>m;
	if(n==1||m==1){
		cout<<1<<endl;
		return 0;
	}
	if(n*m%2==0)cout<<n*m/2<<endl;
	else cout<<n*m/2+1<<endl;
	return 0;
}


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

int H1,H2,M1,M2,K;
int end_t,start_t;
  
void input(){
  cin >> H1 >> M1 >> H2 >> M2 >> K;
  start_t = H1*60+M1;
  end_t = H2*60 + M2;
} 

int main(){
  input();
  if(end_t-start_t<=K){
    cout << 0 << endl;
  }
  else{
    cout << end_t-start_t-K << endl;
  }
  return 0;
}


Measured memory_bytes: 3636
import java.util.ArrayDeque;
import java.util.Deque;
import java.util.Scanner;

public class Main {

    public static String process(TestCase testCase) {
        final String S = testCase.S;

        final char[] chars = S.toCharArray();

        int count = 0;
        Deque<Character> stack = new ArrayDeque<>();
        for (char c : chars) {
            if (stack.isEmpty()) {
                stack.push(c);
            } else {
                if (stack.peek().equals(c)) {
                    stack.push(c);
                } else {
                    stack.pop();
                    count += 2;
                }
            }
        }

        return String.valueOf(count);
    }

    // Util func

    public static void main(String[] args) {
        TestCase testCase = readFromInput();

        final String result = process(testCase);

        output(result);
    }

    private static TestCase readFromInput() {
        Scanner sc = new Scanner(System.in);

        String S = sc.next();

        return new TestCase(S);
    }

    private static IllegalArgumentException unknownN(int N) {
        return new IllegalArgumentException("Unknown N: " + N);
    }

    private static void output(String result) {
        System.out.println(result);
    }

    public static class TestCase {
        final String S;

        public TestCase(String S) {
            this.S = S;
        }
    }
}


Measured memory_bytes: 27348
import java.util.*;
public class Main {
    public static class item{
        int weight;
        int value;
        item(int weight, int value) {
            this.weight = weight;
            this.value = value;
        }
    }
    public static void main(String[] args) {
        Scanner input = new Scanner(System.in);
        int n = input.nextInt();
        int w = input.nextInt();
        item[] items = new item[n];
        for(int i = 0; i < n; i++) {
            items[i] = new item(input.nextInt(), input.nextInt());
        }
        long[] dp = new long[w + 1];
        Arrays.fill(dp, -1);
        dp[0] = 0;
        for(int i = 0; i < n; i++) {
            for(int k = w; k >= 0; k--) {
                if(dp[k] != -1) {
                    try{
                        dp[k + items[i].weight] = Math.max(dp[k + items[i].weight], dp[k] + items[i].value);
                    } catch(Exception e) {

                    }
                }
            }
        }
        long max = 0;
        for(int i = 0; i <= w; i++) {
            max = Math.max(max, dp[i]);
        }
        System.out.println(max);
    }
}


Measured memory_bytes: 25940
#include <algorithm>
#include <cassert>
#include <cmath>
#include <climits>
#include <cstdlib>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <string>
#include <vector>
#define DEBUG 1
constexpr int kMod = 1000000007;
typedef long long LL;

int main() {
  int N; std::cin >> N;
  std::vector<LL> C(N);
  for (int i = 0; i < N; ++i) std::cin >> C[i];
  std::sort(C.begin(), C.end());

  if (N == 1) {
    std::cout << (C[0] * 2) % kMod << std::endl;
    return 0;
  }

  std::vector<LL> mod_pow(N + 1);
  mod_pow[0] = 1;
  for (int i = 1; i <= N; ++i) {
    mod_pow[i] = (2LL * mod_pow[i-1]) % kMod;
  }

  // The pattern of S: 2^N
  // The total score of T[n](n=0,1,2,...):
  //     2^L * {2^(R+1) + 2^R * R  s.t. L=n, R=N-2-n
  //   = 2^L * 2^R * {2 + R} = 2^(N-2) * (N+1-n)
  // So, answer = (2^N) * sum_{n=0}^{N-1} (Cn * 2^(N-2) * (N+1-n))

  LL total = 0;
  for (LL n = 0; n < N; ++n) {
    LL cost = (mod_pow[N-2] * (N+1-n)) % kMod;
    cost = (C[n] * cost) % kMod;
    total = (total + cost) % kMod;
  }

  total = (mod_pow[N] * total) % kMod;
  std::cout << total << std::endl;
}


Measured memory_bytes: 3328
import math

N, K = map(int, input().split())
prob = 0

for i in range(N):
    a = i + 1
    if(a < K):
        times = math.ceil(math.log2(K / a))
    else:
        times = 0
    prob += 1 / N * (1 / 2) ** times
print(prob)
    


Measured memory_bytes: 2940
import std.stdio;


void main() {
  auto xs = new int[4];
  int a, b;
  foreach (_; 0..3) {
    readf("%d %d\n", &a, &b);
    xs[a-1]++;
    xs[b-1]++;
  }

  int e = 0, o = 0;
  foreach (x; xs) {
    if (x % 2 == 0) {
      e++;
    } else {
      o++;
    }
  }

  if (o == 0 || o == 2) {
    writeln("YES");
  } else {
    writeln("NO");
  }
}


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

#define F first
#define S second
#define MP make_pair
#define pb push_back
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define LCM(a, b) (a) / __gcd((a), (b)) * (b)
#define CEIL(a, b) (a)/(b)+(((a)%(b))?1:0)
#define ln '\n'

using namespace std;
using LL = long long;
using ldouble = long double;
using P = pair<int, int>;
using LP = pair<LL, LL>;

static const int INF = INT_MAX;
static const LL LINF = LLONG_MAX;
static const int MIN = INT_MIN;
static const LL LMIN = LLONG_MIN;
static const int MOD = 1e9 + 7;
static const int SIZE = 200005;

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

vector<LL> Div(LL n) {
    vector<LL> ret;
    for(LL i = 1; i * i <= n; ++i) {
        if(n % i == 0) {
            ret.pb(i);
            if(i * i != n) ret.pb(n / i);
        }
    }
    sort(all(ret));
    return ret;
}

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

    int N, X, Y;
    cin >> N >> X >> Y;

    int cnt[2005] = {};
    for(int i = 1; i <= N; ++i) {
        for(int j = i + 1; j <= N; ++j) {
            if(j <= X || Y <= i) {
                cnt[j - i]++;
            } else if(i <= X && Y <= j) {
                cnt[X - i + j - Y + 1]++;
            } else {
                if(X <= i && j <= Y) {
                    cnt[min(j - i, i - X + Y - j + 1)]++;
                } else if(X <= i) {
                    cnt[min(j - i, i - X + j - Y + 1)]++;
                } else {
                    cnt[min(j - i, Y - j + X - i + 1)]++;
                }
            }
        }
    }

    for(int i = 1; i <= N - 1; ++i) {
        cout << cnt[i] << endl;
    }

    return 0;
}



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

template <class T> ostream &operator<<(ostream &os, vector<T> &v) {
  for (auto i = v.begin(); i != v.end(); i++) {
    os << *i << " ";
  }
  return os;
}

const long long MOD = 1000000007;

vector<int> dis(int v, int n, map<int,vector<int>> &m) {
  queue<int> q;
  q.push(v);
  vector<int> level(n,-1);
  level[v] = 0;
  while(!q.empty()) {
    int now = q.front();
    q.pop();
    for(auto next : m[now]) {
      if(level[next]!=-1) continue;
      q.push(next);
      level[next] = level[now]+1;
    }
  }
  return level;
}

int main(){
  int n, u, v;
  cin>>n>>u>>v;
  map<int,vector<int>> m;
  rep(i,n)
    m[i] = vector<int>();
  for(int i=0; i+1<n; i++) {
    int a, b;
    cin>>a>>b;
    a--;
    b--;
    m[a].push_back(b);
    m[b].push_back(a);
  }
  vector<int> fromv = dis(v-1,n,m);
  vector<int> fromu = dis(u-1,n,m);
  int ans = 0;
  rep(i,n) {
    if(fromv[i] > fromu[i])
      ans = max(ans, fromv[i]-1);
  }
  std::cout << ans << std::endl;
  return 0;
}


Measured memory_bytes: 12160
#include <bits/stdc++.h>
#define ll long long
#define rep(X,N) for(ll X = 0; X < (N); X++)
#define PI (acos(-1.0))
#define pback push_back
#define mpair make_pair
#define divceil(A, B) ((A + (B - 1)) / B)
#define MODN 1000000007
#define ALL(V) (V).begin(),(V).end()
#define CERR if(false) cerr

using namespace std;

int main(){

    int n;
    cin >> n;

    vector<pair<string, pair<int,int>>> v;

    rep(i,n){
        string s;
        int t;
        cin >> s >> t;

        v.pback(mpair(s,mpair(-1 * t, i + 1)));
    }

    sort(ALL(v));

    rep(i,n){
        cout << v[i].second.second << endl;
    }

}


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

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

int main() {
  int n, a, b;
  cin >> n >> a >> b;
  int total = 0;
  for (int i=1; i<=n; i++) {
      int sum = findSumOfDigits(i); // iの各桁の和
      if (sum >= a && sum <= b) { // iの各桁の和がA以上B以下かどうか
        total += i;
      }
  }
  cout << total << endl;
}

Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.StringTokenizer;

/**
 * @author Pavel Mavrin
 */
public class Main {

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

    private void solve() throws IOException {
        int n = nextInt() - 1;
        int m = nextInt();
        int k = nextInt();
        int[][] cc = new int[m][n];
        for (int i = 0; i < k; i++) {
            cc[nextInt() - 1][nextInt() - 1] = nextInt() + 1;
        }
        int[][] d = new int[n + 1][1 << n];
        d[0][0] = 1;
        for (int i = 0; i < m; i++) {
            for (int j = 0; j < n; j++) {
                Arrays.fill(d[j + 1], 0);
                for (int x = 0; x < (1 << n); x++) {
                    if (d[j][x] > 0) {
                        int y = (x >> j) & 1;
                        if (cc[i][j] != 2 && y == 0) {
                            d[j + 1][x] += d[j][x];
                            if (d[j + 1][x] >= MOD) {
                                d[j + 1][x] -= MOD;
                            }
                        }
                        if (cc[i][j] != 1) {
                            int xx = y == 1 ? x : (x - (1 << j)) & x + (1 << j);
                            d[j + 1][xx] += d[j][x];
                            if (d[j + 1][xx] >= MOD) {
                                d[j + 1][xx] -= MOD;
                            }
                        }
                    }
                }
            }
            for (int x = 0; x < (1 << n); x++) {
                d[0][x] = d[n][x];
            }
        }
        int res = 0;
        for (int x = 0; x < (1 << n); x++) {
            res += d[0][x];
            if (res >= MOD) {
                res -= MOD;
            }
        }
        out.println(res);

    }

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

    BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
    StringTokenizer st;
    PrintWriter out = new PrintWriter(System.out);

    String next() throws IOException {
        while (st == null || !st.hasMoreTokens()) {
            st = new StringTokenizer(br.readLine());
        }
        return st.nextToken();
    }

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

    public static void main(String[] args) throws IOException {
        new Main().run();
    }

    private void run() throws IOException {
        solve();
        out.close();
    }

}


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

long f(long i, long n, long m){
  long r = (n+1) * i - i*i + 1;
  return r % m;
}


int main(){
  long n, k;  cin >> n >> k;
  long m = 1e9+7, ans = 0;
  for(long i=k; i<=n+1; i++){
    ans = (ans + f(i, n, m)) % m;
  }

  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 3636
#include<bits/stdc++.h>
using namespace std;
#define int long long
signed main(){
    int N;
    cin >> N;
    int A[100010];
    int min = 99999999999;
    int sum = 0;
    int cnt = 0;
    for(int i = 0;i < N;i++){
        cin >> A[i];
        if(abs(A[i]) < min)min = abs(A[i]);
        sum += abs(A[i]);
        if(A[i] < 0)cnt++;
    }
    if(cnt % 2 == 1)cout << sum - 2 * abs(min);
    else cout << sum;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;

void chmin(ll &a, ll b) {
    if (a > b) a = b;
}

int main() {
    int N, W;
    cin >> N >> W;

    vector<int> w(N), v(N);
    for (int i = 0; i < N; i++) {
        cin >> w[i] >> v[i];
    }

    int sum_v = accumulate(v.begin(), v.end(), 0);
    vector<vector<ll>> dp(N + 1, vector<ll>(sum_v + 1, 1e9));
    dp[0][0] = 0;
    for (int i = 0; i < N; i++) {
        for (int j = 0; j <= sum_v; j++) {
            if (j + v[i] <= sum_v + 1) chmin(dp[i + 1][j + v[i]], dp[i][j] + w[i]);
            chmin(dp[i + 1][j], dp[i][j]);
        }
    }

    int ans = 0;
    for (int i = 0; i <= sum_v; i++) {
        if (dp[N][i] <= W) ans = i;
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 80256
// Package main provides
//
// File:  b.go
// Author: ymiyamoto
//
// Created on Mon Jan  7 01:55:15 2019
//
package main

import "fmt"

func main() {
	var H, W int
	fmt.Scan(&H, &W)

	board := make([]string, H)
	for i := range board {
		fmt.Scan(&board[i])
	}

	for i := range board {
		for j := range board[i] {
			if board[i][j] == '#' {
				fmt.Print("#")
			} else {
				num := 0
				for _, dx := range []int{-1, 0, 1} {
					for _, dy := range []int{-1, 0, 1} {
						if dx == 0 && dy == 0 {
							continue
						}
						x, y := i+dx, j+dy
						if 0 <= x && x < H && 0 <= y && y < W {
							if board[x][y] == '#' {
								num++
							}
						}
					}
				}
				fmt.Print(num)
			}
		}
		fmt.Println()
	}
}


Measured memory_bytes: 512
import java.util.*;
public class Main {

	public static void main(String[] args) {
		Scanner sc=new Scanner(System.in);
		int n=sc.nextInt(), l=sc.nextInt();
		sc.nextLine();
		String res="";
		String[] str=new String[n];
		for(int i=0; i<n; ++i) str[i]=sc.nextLine(); 
		Collections.sort(Arrays.asList(str));
		for(int i=0; i<n; ++i) res+=str[i];
		System.out.println(res);
		sc.close(); 
	}

}

Measured memory_bytes: 40620
import math

def a():
    x = int(input())
    if x == 0:
        print(1)
    else:
        print(0)


def b():
    a,b,c,d = map(int,input().split())
    m=[a*c,a*d,b*c,b*d]
    print(max(m))



def c():
    pass



def d():
    pass


# a()
b()
# c()
# d()

Measured memory_bytes: 9052
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Scanner;

public class Main {
	public static void main(String[] args) throws IOException {
		//Scanner sc = new Scanner(System.in);
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		
		int N = Integer.parseInt(br.readLine());
		int[] arr = new int[N];
		for(int i = 0; i<N; i++){
			arr[i] = Integer.parseInt(br.readLine());
		}
		
		if(N == 1){
			System.out.println(arr[0]/2);
			System.exit(0);
		}
		
		long total = 0;
		for(int i = 1; i<N; i++){
			int sum = arr[i-1] + arr[i];
			if(sum%2==0){
				//even
				total += sum/2;
				arr[i-1] = 0;
				arr[i] = 0;
			}
			else{
				//odd
				total += sum/2;
				if(arr[i]>0){
					arr[i] = 1;
					arr[i-1] = 0;
				}
				else{
					arr[i-1] = 1;
					arr[i] = 0;
				}
			}
		}
		System.out.println(total);
	}
}

Measured memory_bytes: 18164
# input()
# int(input())
# map(int, input().split())
# list(map(int, input().split()))
# list(map(int, list(input()))) # スペースがない数字リストを読み込み
import math
import fractions
import sys
import bisect
import heapq  # 優先度付きキュー(最小値取り出し)
import collections
from collections import Counter
from collections import deque
import pprint
import itertools

sr = lambda: input()
ir = lambda: int(sr())
lr = lambda: list(map(int, sr().split()))

"""nを素因数分解"""
"""2以上の整数n => [[素因数, 指数], ...]の2次元リスト"""


def factorization(n):
    arr = []
    temp = n
    if n == 1:
        return arr

    for i in range(2, int(-(-n ** 0.5 // 1)) + 1):
        if temp % i == 0:
            cnt = 0
            while temp % i == 0:
                cnt += 1
                temp //= i
            arr.append([i, cnt])

    if temp != 1:
        arr.append([temp, 1])

    if arr == []:
        arr.append([n, 1])

    return arr


# a^n
def power(a, n, mod):
    x = 1
    while n:
        if n & 1:
            x *= a % mod
        n >>= 1
        a *= a % mod
    return x % mod


# n*(n-1)*...*(l+1)*l
def kaijo(n, l, mod):
    if n == 0:
        return 1
    a = n
    tmp = n - 1
    while (tmp >= l):
        a = a * tmp % mod
        tmp -= 1
    return a

# Union Find
class UnionFind():
    def __init__(self, n):
        self.n = n
        self.parents = [-1] * n

    def find(self, x):
        if self.parents[x] < 0:
            return x
        else:
            self.parents[x] = self.find(self.parents[x])
            return self.parents[x]

    def union(self, x, y):
        x = self.find(x)
        y = self.find(y)

        if x == y:
            return

        if self.parents[x] > self.parents[y]:
            x, y = y, x

        self.parents[x] += self.parents[y]
        self.parents[y] = x

    def size(self, x):
        return -self.parents[self.find(x)]

    def same(self, x, y):
        return self.find(x) == self.find(y)

    def members(self, x):
        root = self.find(x)
        return [i for i in range(self.n) if self.find(i) == root]

    def roots(self):
        return [i for i, x in enumerate(self.parents) if x < 0]

    def group_count(self):
        return len(self.roots())

    def all_group_members(self):
        return {r: self.members(r) for r in self.roots()}

    def __str__(self):
        return '\n'.join('{}: {}'.format(r, self.members(r)) for r in self.roots())

# 約数生成
def make_divisors(n):
    divisors = []
    for i in range(1, int(n**0.5)+1):
        if n % i == 0:
            divisors.append(i)
            if i != n // i:
                divisors.append(n//i)

    divisors.sort()
    return divisors


inf = 10 ** 18
mod = 10 ** 9 + 7

n = ir()
primes = set(range(2, 55555+1))
for i in range(2, int(55555**0.5+1)):    #nのルート+1
    primes.difference_update(range(i*2, 55555+1, i))
primes=list(primes)
ans = []
for num in primes:
    if num % 5 == 1:
        ans.append(num)
print(*ans[:n], sep=' ')

Measured memory_bytes: 93100
/*
#pragma GCC optimize("Ofast,unroll-loops")
#pragma GCC target("avx,avx2,fma")
*/
#include <bits/stdc++.h>
#define LL              long long
#define ll              long long
#define SL(n)           scanf("%lld",&n)
#define LF              double
#define SF(n)           scanf("%lf",&n)
 
#define pb              push_back
#define mp              make_pair
 
#define ON(n,i)         (n|(1LL<<i))
#define OFF(n,i)        (n&(~(1LL<<i)))
#define CHK(n,i)        (n&(1LL<<i))
 
#define ff              first
#define ss              second
 
#define SET(arr)        memset( arr , -1 , sizeof arr)
#define RESET(arr)      memset( arr,0,sizeof arr)
 
#define srt(v)          sort(v.begin(),v.end())
#define uniq(v)			v.resize(distance(v.begin(),unique(v.begin(),v.end())))
#define found( s,d )    (s.find(d) != s.end())
 
#define FOR(i,s,e)      for( LL i = s ; i<=e ; i++ )
#define RFOR(i,e,s)     for( LL i = e ; i>=s ; i-- )
         
 
#define FILEIN          freopen("in.txt","r",stdin)
#define FILEOUT         freopen("WA.txt","w",stdout)
 
#define DEBUG(x)        cerr<<#x<<" = "<<x<<endl
#define PRINTALL(v)     {cerr<<endl<<"Printing: "<<#v<<endl;for(LL i = 0 ; i<v.size(); i++) DEBUG(v[i]); cerr<<endl;}
 
#define sz(v)			((LL)v.size())
#define pi 				(acos(-1.0));
using namespace std;

LL val[3010][3010];

LL dp[3010][3010][4];

LL F( LL R, LL C, LL taken ){
	if(R<1) return 0;
	if(C<1) return 0;
	LL &ret  = dp[R][C][taken];
	if(ret!=-1) return ret;
	ret = 0;
	
	if(taken){
		ret = max( ret , val[R][C] + F(R-1,C,3));
		ret = max( ret , val[R][C] + F(R,C-1,taken - 1) );
	}
	
	ret = max( ret, F(R-1,C,3) );
	ret = max( ret, F(R,C-1,taken));
	return ret;
}

int main(){ 
	
	SET(dp);
	
	LL R,C,K;
	SL(R); SL(C); SL(K);
	FOR(i,1,K){
		LL r,c,v;
		SL(r); SL(c); SL(v);
		val[r][c] = v;
	}
	
	cout<<F(R,C,3)<<endl;
	
return 0;}


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

#pragma GCC target ("avx2")
#pragma GCC optimization ("O3")
#pragma GCC optimization ("unroll-loops")

//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/tree_policy.hpp>
//using namespace __gnu_pbds;
//#define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>

#define XX              first
#define YY              second
#define PB              push_back
#define MP              make_pair

#define NEWLINE         cerr << "\n";
#define HOISE           cerr << "hoise " << __LINE__ << "\n"
#define PAUSE           system("pause")
#define DEBUG(x)        cerr << #x << " = " << x << "\n"
#define FASTIO          ios_base::sync_with_stdio(false);cin.tie(NULL)

typedef long long ll;
typedef pair<int, int > pii;
typedef pair<ll, ll> pll;

const int INF = 1e9 + 23;
const ll INFL = 2e18 + 23;

int32_t main()
{
    FASTIO;

    int n;
    cin >> n;
    int ans = ((n + 1000 - 1)/1000)*1000 - n;
    cout << ans;

    return 0;
}	

Measured memory_bytes: 3644
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
#define all(x) (x).begin(),(x).end()
#define SZ(x) ((int)(x).size())
using namespace std;
typedef long long ll;
typedef long double ld;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1;} return 0;}
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1;} return 0;}
int const INF = 1 << 30;


int main()
{
    string s;
    int gx,gy;
    cin >> s >> gx >> gy;
    s = s + 'T';

    int dir = 0, f = 0;
    vector<int> fx,fy;
    for(char c : s) {
        if(c == 'T') {
            if(dir == 0) fx.push_back(f);
            if(dir == 1) fy.push_back(f);
            f = 0;
            dir = 1 - dir;
        }
        if(c == 'F') f++;
    }

    vector<vector<bool>> dpx(SZ(fx)+1,vector<bool>(16060,false));
    vector<vector<bool>> dpy(SZ(fy)+1,vector<bool>(16060,false));
    dpx[0][8030] = true; dpy[0][8030] = true;
    rep(i,SZ(fx)) {
        rep(j,16060) {
            if(!dpx[i][j]) continue;
            dpx[i+1][j+fx[i]] = true;
            if(i != 0) dpx[i+1][j-fx[i]] = true;
        }
    }

    rep(i,SZ(fy)) {
        rep(j,16060) {
            if(!dpy[i][j]) continue;
            dpy[i+1][j+fy[i]] = true;
            dpy[i+1][j-fy[i]] = true;
        }
    }

    if(dpx[SZ(fx)][gx+8030] && dpy[SZ(fy)][gy+8030]) cout << "Yes" << endl;
    else cout << "No" << endl;
}

Measured memory_bytes: 19244
#include <bits/stdc++.h>
#define rep(i,a,b) for(ll i=ll(a);i<ll(b);i++)
#define irep(i,a,b) for(ll i=ll(a);i>=ll(b);i--)
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
#define pb push_back
#define mp make_pair
#define F .first
#define S .second 
#define pll pair<ll,ll>
using ll=long long;
using ld=long double;
const ll INF = 1LL<<60;
const ll mod=1e9+7;
using namespace std;
ll gcd(ll a, ll b) { return b ? gcd(b, a%b) : a; }

ll p[110000];
int main(){
    ll n,k;
    cin>>n>>k;
    rep(i,0,n)cin>>p[i];
    sort(p,p+n);
    ll ans=0;
    rep(i,0,k)ans+=p[i];
    cout<<ans;
}



Measured memory_bytes: 3644
#include<bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds ;
#define ll long long
#define ld float
#define rep(i,a,b) for(ll i=a;i<b;i+=1)
#define all(c) (c).begin(),(c).end()
#define pb push_back
#define sz(a) int((a).size())
#define hell (ll)1000000007
#define f first
#define s second
#define sll(x) scanf("%lld",&x)
#define si(x) scanf("%d",&x)
typedef tree< ll , null_type , less<ll> , rb_tree_tag , tree_order_statistics_node_update > ordered_set ;
ll t = 1 ;
void solve()
{
    ll n , k , ans = 0 ;
    cin >> n >> k ;
    vector<ll> v(n) ;
    rep( i , 0 , n )
        cin >> v[i] ;
    ll up = min(n,k) + 1 ;
    rep( i , 0 , up )
    {
        rep( j , 0 , up ){
			if(i+j>up-1)continue;
            ll cur = 0 ;
            vector<ll> tmp ;
            rep( _ , 0 , i )
                tmp.pb(v[_]);
            for( ll _ = n - 1 ; _ >= n - j ; _-- ){
                tmp.pb(v[_]);
            }
            sort(all(tmp));
            for(auto u : tmp ) cur += u ;
            //cout << endl;
            rep( _ , 0 , min(i+j,k-i-j) ){
                if(tmp[_]<0)cur-=tmp[_];
            }
            ans = max(ans,cur);
        }
    }
    cout << ans ;
}
signed main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);
    //cin>>t;
    while(t--)
        solve() ;
    return 0 ;
}


Measured memory_bytes: 256
//
// Created by 肖龙 on 2020/3/18.
//

#include<iostream>
#include <cmath>
#include <iomanip>

using namespace std;

typedef struct point{
    double x,y;
}Point,Vector;

typedef struct line{
    Point x;
    Vector k;
}Line;

//点积
double dot(Vector x,Vector y){
    return x.x*y.x+x.y*y.y;
}

//叉积
double cross(Vector x,Vector y){
    return x.x*y.y-x.y*y.x;
}

double getlen(Vector x){
    return sqrt(dot(x,x));
}

Vector getV(Point x,Point y){
    Vector v;
    v.x=y.x-x.x;
    v.y=y.y-x.y;
    return v;
}
//点在直线的投影
Point Projection(Line x,Point y){
    Point answ;
    answ = x.x;

    double len = dot(x.k,getV(x.x,y));
    len/=sqrt(x.k.x*x.k.x+x.k.y*x.k.y);
    Vector temp  = x.k;
    temp.x /=sqrt(x.k.x*x.k.x+x.k.y*x.k.y);
    temp.y/=sqrt(x.k.x*x.k.x+x.k.y*x.k.y);
    answ.x+=temp.x*len;
    answ.y+=temp.y*len;
    return answ;
}
//点与直线的对称点
Point Reflection(Line x,Point y){
    Point half = Projection(x,y);
    Point answ;
    answ.x=y.x+2*(half.x-y.x);
    answ.y=y.y+2*(half.y-y.y);
    return answ;
}

int main(){
    int t;
    cin>>t;
    Point x,y;
    Vector v1,v2;
    while(t--){
        cin>>x.x>>x.y>>y.x>>y.y;
        v1=getV(x,y);
        cin>>x.x>>x.y>>y.x>>y.y;
        v2=getV(x,y);
        if(dot(v1,v2)==0){
            cout<<1<<endl;
        }else if(cross(v1,v2)==0){
            cout<<2<<endl;
        }
        else cout<<0<<endl;
    }
    return 0;
}


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

int main() {
  int N;
  cin >> N;
  vector<int> A(N, 0);  
  
  int a;
  
  for (int i = 0; i < N; i++) {  //Aに２で割れる回数を入れる
  	cin >> a;
    for (int j = 0; j < 512; j++) {
    	if (a % 2 == 0) {
        	A[i] = j + 1;
          	a /= 2;
        }
        else {break;}
    }
    
    
  	
  }
  sort(A.begin(), A.end());
  
  cout << A[0] << endl;
 
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef vector<ll> vl;
typedef pair<ll, ll> PP;
#define rep(i, n) for (ll i = 0; i < ll(n); i++)
#define all(v) v.begin(), v.end()
bool chmin(ll& a, ll b) {
    if (b < a) {
        a = b;
        return 1;
    }
    return 0;
}
bool chmax(ll& a, ll b) {
    if (b > a) {
        a = b;
        return 1;
    }
    return 0;
}
const ll INF = 999999999999999;
const ll MOD = 1000000007;
const ll MAX_N = 500010;
ll a, b, c, d, e, f, p, t, x, y, z, q, m, n, r, h, k, w, l, ans;
struct edge {
    ll to, cost;
};
vector<edge> g[MAX_N];
vl visited(MAX_N, 0);
vector<vl> bubunki(MAX_N), ruisekiL(MAX_N), ruisekiR(MAX_N);
vl par(MAX_N), oya(MAX_N), oya_zibun(MAX_N);
vl dfs_takasa(MAX_N, 0), ANS(MAX_N, 0);
ll dfs(ll x) {
    visited[x] = 1;
    bubunki[x] = vl(g[x].size(), 0);
    ll t = 0;
    rep(i, g[x].size()) {
        ll to = g[x][i].to, cost = g[x][i].cost;
        if (visited[to] == 0) {
            par[to] = x;
            oya_zibun[to] = i;
            dfs(to);
            bubunki[x][i] = dfs_takasa[to] + cost;
            chmax(t, bubunki[x][i]);
        } else
            oya[x] = i;
    }

    return dfs_takasa[x] = t;
}

void dfs2(ll x) {
    visited[x] = 1;

    ll a = 0, b = 0;
    ruisekiL[x].push_back(0);
    ruisekiR[x].push_back(0);
    rep(i, g[x].size()) {
        a = max(a, bubunki[x][i]);
        b = max(b, bubunki[x][g[x].size() - 1 - i]);

        ruisekiL[x].push_back(a);
        ruisekiR[x].push_back(b);
    }

    reverse(all(ruisekiR[x]));

    for (edge i : g[x]) {
        if (visited[i.to] == 0) {
            ANS[i.to] = dfs_takasa[i.to];
            ll b = oya_zibun[i.to];
            bubunki[i.to][oya[i.to]] =
                max(ruisekiL[x][b] + i.cost, ruisekiR[x][b + 1] + i.cost);
            ANS[i.to] = max({dfs_takasa[i.to], bubunki[i.to][oya[i.to]]});
            dfs2(i.to);
        }
    }
}

int main() {
    cin >> n;
    rep(i, n - 1) {
        cin >> x >> y >> c;
        g[x].push_back({y, c});
        g[y].push_back({x, c});
    }

    dfs(0);
    visited = vl(n, 0);

    ANS[0] = dfs_takasa[0];
    dfs2(0);

    rep(i, n) { cout << ANS[i] << endl; }
}


Measured memory_bytes: 74900
N = int(input())
array = list(map(int, input().strip().split()))
array.sort()
ansarray = []
ansnum = 1
ans = 0
ansindex = 0
for i in range (1,N):
    for j in range(ansindex,N-1):
        if (array[j] == i):
            ans += 1
            ansindex += 1
        else:
            ansarray.append(ans)
            ans = 0
            break
        if(j == N-2):
            ansarray.append(ans)
            ansindex += 1
for i in range(N-len(ansarray)):
    ansarray.append("0")
for i in range(N):
    print(ansarray[i])

Measured memory_bytes: 32244
import sys

readline = sys.stdin.readline
MOD = 10 ** 9 + 7
INF = float('INF')
sys.setrecursionlimit(10 ** 5)


def main():
    from collections import deque
    import bisect
    n, k = map(int, readline().split())
    a = list(map(int, readline().split()))
    a.sort()
    que = deque()

    if n == k:
        que.extend(a)
    elif a[-1] < 0 and k % 2 == 1:
        que.extend(a)
        for _ in range(n - k):
            que.popleft()
    else:
        pos_ = []
        neg_ = []
        for x in a:
            if x >= 0:
                pos_.append(x)
            else:
                neg_.append(x)
        pos = deque(sorted(pos_, reverse=True))
        neg = deque((sorted(neg_)))
        while len(que) < k:
            if len(pos) >= 2:
                pp = pos[0] * pos[1]
            else:
                pp = -1
            if len(neg) >= 2:
                np = neg[0] * neg[1]
            else:
                np = -1
            if (pp > np) or len(que) == (k-1):
                que.append(pos.popleft())
            else:
                que.append(neg.popleft())
                que.append(neg.popleft())

    while len(que) > 1:
        que.append(que.popleft() * que.popleft())

    print(que.popleft() % MOD)


if __name__ == '__main__':
    main()


Measured memory_bytes: 148948
class UnionFind:
    def __init__(self, n):
        self.par = [i for i in range(n)]
        self.rank = [0] * (n)
        self.total = n
    def find(self, x):
        if self.par[x] == x:
            return x
        else:
            self.par[x] = self.find(self.par[x])
            return self.par[x]
    def same_check(self, x, y):
        return self.find(x) == self.find(y)
    def unite(self, x, y):
        if self.same_check(x, y):
            return
        x = self.find(x)
        y = self.find(y)
        if self.rank[x] < self.rank[y]:
            self.par[x] = y
            self.total -= 1
        else:
            self.par[y] = x
            self.total -= 1
            if self.rank[x] == self.rank[y]:
                self.rank[x] += 1
n,m = map(int, input().split())
union = UnionFind(n)
for i in range(m):
    x,y,z = map(int, input().split())
    union.unite(x-1, y-1)
print(union.total)


Measured memory_bytes: 7856
#include<iostream>
#include<algorithm>
#include<string>
#include<cmath>
#include<vector>
#include<map>
#include<iomanip>
#include<sstream>
#include<list>
#include<iterator>
#include<queue>
#include<stack>

#define ll long long
#define ull unsigned long long
#define pi acos(-1)
#define el cout<<"\n"
#define pb push_back
#define f1(i, n)        for (ll i = 1; i <= n; i++)
#define f0(i, n)        for (ll i = 0; i < n; i++)
#define fo(i, s, n)     for (ll i = s; i <= n; i++)


using namespace std;


//**************  MY CODE STARTS HERE  **************************//


int main()
{
    ll k,n,max1=0,dif;
    cin>>k>>n;
    ll a[n];
    for(ll i=0;i<n;i++)
    {
        cin>>a[i];
        if(i!=0)
        {
            dif=a[i]-a[i-1];
            max1=max(max1,dif);
        }
    }
    dif=a[0]+(k-a[n-1]);
    max1=max(max1,dif);
    cout<<k-max1;el;
    
}


Measured memory_bytes: 1792
#include <bits/stdc++.h>
#include <sys/types.h>
#include <unistd.h>

#define _overload(_1,_2,_3,name,...) name
#define _rep(i,n) _range(i,0,n)
#define _range(i,a,b) for(int i=int(a);i<int(b);++i)
#define rep(...) _overload(__VA_ARGS__,_range,_rep,)(__VA_ARGS__)

#define _rrep(i,n) _rrange(i,n,0)
#define _rrange(i,a,b) for(int i=int(a)-1;i>=int(b);--i)
#define rrep(...) _overload(__VA_ARGS__,_rrange,_rrep,)(__VA_ARGS__)

#define _all(arg) begin(arg),end(arg)
#define uniq(arg) sort(_all(arg)),(arg).erase(unique(_all(arg)),end(arg))
#define getidx(ary,key) lower_bound(_all(ary),key)-begin(ary)
#define clr(a,b) memset((a),(b),sizeof(a))
#define bit(n) (1LL<<(n))
#define popcount(n) (__builtin_popcountll(n))

using namespace std;

template<class T>bool chmax(T &a, const T &b) { return (a<b)?(a=b,1):0;}
template<class T>bool chmin(T &a, const T &b) { return (b<a)?(a=b,1):0;}

using ll=long long;
using R=long double;
const R EPS=1e-9L; // [-1000,1000]->EPS=1e-8 [-10000,10000]->EPS=1e-7
inline int sgn(const R& r){return(r > EPS)-(r < -EPS);}
inline R sq(R x){return sqrt(max(x,0.0L));}

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

const pid_t pid = getpid();
// Problem Specific Parameter:

void NG(){
	puts("-1");
	exit(0);
}

int main(void){
	string s;
	cin >> s;
	const int n = s.size();

	if(s[n-1] == '1') NG();
	if(s[0] == '0' or s[n-2]=='0') NG();

	rep(i,1,n){
		const int j = n - i;
		if(s[i-1] == '1' and s[j-1] == '0') NG();
		if(s[i-1] == '0' and s[j-1] == '1') NG();
	}

	vector<int> ary;
	rep(i,1,n) if(s[i-1]=='1') ary.push_back(i);

	const int m = ary.size();
	rep(i,1,m+1) cout << i << " " << i+1 << endl;

	int nxt = m + 2;
	rep(i,2,m+1){
		const int diff = ary[i-1] - ary[i-2] - 1;
		rep(loop,diff){
			cout << i << " " << nxt << endl;
			nxt++;
		}
	}
	
	return 0;
}

Measured memory_bytes: 2040
#include<cstdio>
#include<cstring>
#include<vector>
#include<queue>
#include<algorithm>
#include<cmath>
#include<climits>
#include<string>
#include<numeric>
#include<set>
#include<map>
#include<iostream>
using namespace std;
#define rep(i,n) for(int i = 0;i<((int)(n));i++)
#define reg(i,a,b) for(lli i = ((int)(a));i<=((int)(b));i++)
#define irep(i,n) for(int i = ((int)(n)-1);i>=0;i--)
#define ireg(i,a,b) for(int i = ((int)(b));i>=((int)(a));i--)
typedef long long int lli;
typedef pair<int, int> mp;
#define fir first
#define sec second
#define IINF INT_MAX
#define LINF LLONG_MAX
#define eprintf(...) fprintf(stderr,__VA_ARGS__)
#define pque(type) priority_queue<type,vector<type>,greater<type> >
#define memst(a,b) memset(a,b,sizeof(a))

int main(void){
	int n; cin >> n;
	vector<int> v(n);
	rep(i, n) cin >> v[i];
	sort(v.begin(), v.end());
	if(v.back() - v.front() > 1){
		cout << "No" << endl;
	}else if(v.back() - v.front() == 0){
		if(n == v.front()+1 || n >= 2*v.front()) cout << "Yes" << endl;
		else cout << "No" << endl;
	}else{
		int m = upper_bound(v.begin(), v.end(), v.front()) - v.begin();
		if(v.back() > m && n+m >= 2*v.back()) cout << "Yes" << endl;
		else cout << "No" << endl;
	}
	return 0;
}

Measured memory_bytes: 640
import sys
X,A,B = map(int,input().split())
if X < 0 or A < 0 or B < 0 or X > 10 ** 9 or A > 10 ** 9 or B > 10 ** 9:
    sys.exit()

if B - A < X + 1 and B - X > 0:
    print("safe")
if B - A < X + 1 and B - X < 0:
    print("delicious")
if B - A >= X + 1:
    print("dangerous")


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

int main(int argc, char const* argv[])
{
  int m=0,n,ans=0;
  cin >> n;
  for (int i=0;i<n;i++){
    int temp;
    cin >> temp;
    if (m<=temp)ans++;
    else continue;
    m = max(temp,m);
  }
  cout << ans<< endl;
  return 0;
}


Measured memory_bytes: 256
import collections
N, K, Q = map(int, input().split())
A = [int(input()) for _ in range(Q)]
count = [0 for _ in range(N)]
for a in A:
    count[a-1] += 1
for c in count:
    print('Yes' if(K-Q+c) > 0 else 'No')

Measured memory_bytes: 8920
# coding: utf-8
import heapq
n=int(input())
p=[]
d=[[] for i in range(n)]
for i in range(n):
    p.append(tuple(map(int,input().split()))+tuple([i]))
x_sorted=sorted(p,key=lambda x:x[0])
y_sorted=sorted(p,key=lambda x:x[1])
for i in range(n-1):
    d[x_sorted[i][2]].append((x_sorted[i+1][0]-x_sorted[i][0],x_sorted[i+1][2]))
    d[x_sorted[i+1][2]].append((x_sorted[i+1][0]-x_sorted[i][0],x_sorted[i][2]))
    d[y_sorted[i][2]].append((y_sorted[i+1][1]-y_sorted[i][1],y_sorted[i+1][2]))
    d[y_sorted[i+1][2]].append((y_sorted[i+1][1]-y_sorted[i][1],y_sorted[i][2]))
h=[]
for q in d[0]:
    heapq.heappush(h,q)
used=[False for i in range(n)]
used[0]=True
cost=0
while len(h):
    q=heapq.heappop(h)
    if used[q[1]]:
        continue
    used[q[1]]=True
    cost+=q[0]
    for r in d[q[1]]:
        heapq.heappush(h,r)
print(cost)




Measured memory_bytes: 75752
arr = $stdin.gets.chomp.split(" ")
arr.map! do |a_j|
a_j.to_i
end

if
  arr[0] + arr[1] > arr[2] + arr[3]
  puts "Left"
elsif
  arr[0] + arr[1] < arr[2] + arr[3]
  puts "Right"
else
  puts "Balanced"
end

Measured memory_bytes: 1788
#include <bits/stdc++.h>
using namespace std;
#define repd(i,a,b) for (int i=(a);i<(b);i++)
#define rep(i,n) repd(i,0,n)
#define all(x) (x).begin(),(x).end()
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; }
typedef long long ll;
const long long INF = 1LL << 60;
typedef pair<int, int> P;
int main()
{
    int a, b;
    cin >> a >> b;
    cout << ((a * b) % 2 ? "Odd" : "Even") << endl;
    return 0;
}

Measured memory_bytes: 256
N,M = list(map(int,input().split()))
p=10**9+7
A = [0]*(N+1)
flag = 0
for i in range(M):
    tmp = int(input())
    A[tmp]=1
    if A[tmp]*A[tmp-1]>0:
        flag=1
        break
if flag==1:
    print(0)
else:
    dp = [0]*(N+1)
    dp[0] = 1
    dp[1] = 1-A[1]
    for i in range(2,N+1):
        if A[i]==1:
            continue
        dp[i]=(dp[i-1]+dp[i-2])%p
    print(dp[-1])

Measured memory_bytes: 76256
#include<bits/stdc++.h>
using namespace std;
#define MOD 1000000007
#define ll long long
#define pb push_back
bool isPrime(ll n) 
{ 
   
   if (n <= 1)  return false; 
   if (n <= 3)  return true; 
 
   if (n%2 == 0 || n%3 == 0) return false; 
 
   for (ll i=5; i*i<=n; i=i+6) 
       if (n%i == 0 || n%(i+2) == 0) 
          return false; 
 
   return true; 
} 
ll minthis(ll a, ll b){
if(a < b){
return a;
}
return b;
}
ll maxthis(ll a, ll b){
if(a > b){
return a;
}
return b;
}
int gcd(int a, int b){
   if( a<0 ) a = -a;
   if( b<0 ) b = -b;
   while( b!=0 ){
       a %= b;
       if( a==0 ) return b;
       b %= a;
   }
   return a;
}
 
int findLargestDivisor(int n) 
{ 
int max = 1;
   for (int i = 2; i < n; i++) {        
       if(n %(i) == 0) { 
           max = i;
       } 
    }
   return max;     
} 
 
 
ll power(ll x, ll y)  
{  
   ll temp;  
   if(y == 0)  
       return 1;  
   temp = power(x, y / 2);  
   if (y % 2 == 0)  
       return temp * temp;  
   else
   {  
       if(y > 0)  
           return x * temp * temp;  
       else
           return (temp * temp) / x;  
   }  
} 
bool sortbysec(const pair<int, int>& a, 
               const pair<int, int>& b) 
{ 
   return (a.second < b.second); 
} 
void solve(){
    ll x,k,d;
    cin >> x >> k >> d;
    ll dist0 = abs(x);
    ll temp = dist0/d;    
    ll stepsused = dist0/d;
    temp = minthis(k,temp);
    ll newx = dist0-(d*(temp));
    if(k){
        k -= temp;
        newx = abs(newx);
        if((k)%2 != 0){
            newx = abs(newx-d);
        }
    }
    cout << newx << "\n"; 
}
int main(){ 
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    int t = 1;
    //cin >> t;
    while(t--){
    solve();
    }
  return 0; 
}



  



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

using namespace std;

#define ll long long
#define fo(i,b,n) for(int i=(b); i<(n) ; i++)
#define xx first
#define yy second
#define pb push_back
#define sz(n) int(n.size())
#define pii pair
#define MP make_pair

#define read(x) scanf("%d",&x)
#define read2(x,y) scanf("%d%d",&x,&y)
#define readl(x) scanf("%lld",&x)
#define readl2(x,y) scanf("%lld%lld",&x,&y)
#define readd(x) scanf("%lf",&x)
#define readd2 scanf("%lf%lf",&x,&y)

#define pr(n) printf("%d",n)
#define prn(n) printf("%d\n",n)
#define prl(n) printf("%ld",n)
#define prln(n) printf("%ld\n",n)
#define prd(x) printf("%lf",x)
#define prdn(x) printf("%lf\n",x)




int main()
{
    int n;
    read(n);
    prn( (n*(n+1))>>1 );
    return 0;
}
















Measured memory_bytes: 256
#include <stdio.h>

#define LENGTH 256

int main( void ) {
  char input[LENGTH];
  int L,R,d,x,y;
  
  fgets(input, 256, stdin);
  sscanf(input,"%d %d %d", &L,&R,&d);
  x = (int)R/(int)d;
  y = (int)(L-1)/(int)d;
  
  printf("%d\n", x-y);
  return 0;
}


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

int main() {
    int n, m;
    std::cin >> n >> m;
    std::vector<std::vector<int>> a(n, std::vector<int>(m));
    for (int i = 0; i < n; i++) for (int j = 0; j < m; j++) std::cin >> a[i][j];

    std::set<int> s;
    auto ret = 300;
    for (int i = 1; i <= m; i++) s.insert(i);
    while (!s.empty()) {
        std::vector<int> cnt(m + 1);
        for (auto& p : a) {
            for (int i = 0; i < m; i++) {
                if (s.find(p[i]) != s.end()) {
                    cnt[p[i]]++;
                    break;
                }
            }
        }
        auto it = std::max_element(cnt.begin() + 1, cnt.end());
        s.erase(it - cnt.begin());
        ret = std::min(ret, *it);
    }

    std::cout << ret << std::endl;

    return 0;
}

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

int main() {
int64_t n;
  cin>>n;
  vector<int64_t> vec(n);
  for(int64_t j=0;j<n;j++){cin>>vec.at(j);}
 int64_t m,k;
  m=1000;
  k=0;
  for(int64_t i=0;i<n-1;i++){
  if(vec.at(i)<vec.at(i+1)){
    int64_t a=m/vec.at(i);
  m-=a*vec.at(i);
    k+=a;
    }
   if(vec.at(i)>vec.at(i+1)){
    m+=vec.at(i)*k;
        k=0;
    }
  }
  
  
  cout<<m+k*vec.at(n-1)<<endl;
}


Measured memory_bytes: 3588
#include <bits/stdc++.h>
  
#define FOR(i,a,b) for( ll i = (a); i < (ll)(b); i++ )
#define REP(i,n) FOR(i,0,n)
#define YYS(x,arr) for(auto& x:arr)
#define ALL(x) (x).begin(),(x).end()
#define SORT(x) sort( (x).begin(),(x).end() )
#define REVERSE(x) reverse( (x).begin(),(x).end() )
#define UNIQUE(x) (x).erase( unique( ALL( (x) ) ) , (x).end() )
#define PW(x) (1LL<<(x))
#define SZ(x) ((ll)(x).size())
#define SHOW(x) cout << #x << " = " << x << endl
 
#define pb emplace_back
#define fi first
#define se second

using namespace std;
 
typedef long double ld;
typedef long long int ll;
typedef pair<int,int> pi;
typedef pair<ll,ll> pl;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<bool> vb;
typedef vector<ld> vd;
typedef vector<pi> vpi;
typedef vector<pl> vpl;
typedef vector<vpl> gr;
typedef vector<vl> ml;
typedef vector<vd> md;
typedef vector<vi> mi;
 
const ll INF = (ll)1e9 + 10;
const ll INFLL = (ll)1e18 + 10;
const ld EPS = 1e-8;
const ll MOD = 1e9+7;

template<class T> T &chmin( T &a , const T &b ){ return a = min(a,b); }
template<class T> T &chmax( T &a , const T &b ){ return a = max(a,b); }
template<class T> inline T sq( T a ){ return a * a; }
ll in(){ ll x; scanf( "%lld" , &x ); return x; }
 
// head

char s[72];

int main(){

  scanf( "%s" , s );
  REP( i , 4 ) printf( "%c" , s[i] );
  printf( " " );
  FOR( i , 4 , 12 ) printf( "%c" , s[i] );
  printf( "\n" );

  return 0;
}


Measured memory_bytes: 256
//SAIKH SERAJ FAHIM, CSE-19-HSTU, BANGLADESH.

#include<iostream>
using namespace std;
int main()
{
    int n,k,i,count=0;
    cin>>n>>k;
    int ar[100000];
    for(i=0; i<n; i++)
        cin>>ar[i];
    for(i=0; i<n; i++)
    {
        if(ar[i]>=k)
            count++;
    }
    cout<<count<<endl;
    return 0;
}

Measured memory_bytes: 640
class Q1044
  CONS = ?a - ?A
  def change name,type
    names = divStr name
    len = names.length
    ans = ""
    #cons = ?a - ?A
    if(type == "U")
      for i in 0..len-1
        names[i][0] = (names[i][0] - CONS).chr
        ans += names[i]
      end
    elsif(type == "L")
        ans += names[0]
      for i in 1..len-1
        names[i][0] = (names[i][0] - CONS).chr
        ans += names[i]
      end
    else
      ans += names[0]
      for i in 1..len-1
        ans += "_" + names[i]
      end
    end
    puts ans
  end
  def divStr str
    ary = Array.new
    tmp = ""
    len = str.length
    i = 0
    while(i < len)
      c = str[i]
      if(c == ?_)
        ary.push tmp
        tmp = ""
      elsif(?A <= c && c <= ?Z)
        if(tmp != "")
          ary.push tmp
        end
        tmp = ""
        tmp += (c + CONS).chr
      else
        tmp += c.chr
      end
      i += 1
      #puts tmp
=begin
      print "tmp = "
      puts tmp
      print "ary = "
      puts ary
=end
    end
    ary.push tmp
    return ary
  end
  
  def doIt
    s = gets.split " "
    while(s[1] != "X")
      change s[0],s[1]
      s = gets.split " "
    end
  end
end

Q1044.new.doIt

Measured memory_bytes: 2448