akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;

int main() {
  int n;
  cin >> n;
  int fx = 0, k = n;

  
  while (k > 0) {
    fx += k % 10;
    k /= 10;
  }
  
  if (n % fx == 0) 
    cout << "Yes" << endl;
  else
    cout << "No" << endl;
}


Measured memory_bytes: 3588
from operator import mul
from functools import reduce


def cmb(n, r):
    r = min(n - r, r)
    if r == 0:
        return 1
    over = reduce(mul, range(n, n - r, -1))
    under = reduce(mul, range(1, r + 1))
    return over // under


N = int(input())

cnt = {'M': 0, 'A': 0, 'R': 0, 'C': 0, 'H': 0}
chars = set()
for _ in range(N):
    S = input()
    if S[0] in cnt:
        cnt[S[0]] += 1


combs = [
    ['M', 'A', 'R'],
    ['M', 'A', 'C'],
    ['M', 'A', 'H'],
    ['M', 'R', 'C'],
    ['M', 'R', 'H'],
    ['M', 'C', 'H'],
    ['A', 'R', 'C'],
    ['A', 'R', 'H'],
    ['A', 'C', 'H'],
    ['R', 'C', 'H']
]
ans = 0
for c1, c2, c3 in combs:
    ans += cnt[c1] * cnt[c2] * cnt[c3]

print(ans)


Measured memory_bytes: 43624
(eval-when (:compile-toplevel :load-toplevel :execute)
  (defparameter OPT
    #+swank '(optimize (speed 3) (safety 2))
    #-swank '(optimize (speed 3) (safety 0) (debug 0)))
  #+swank (progn (ql:quickload '(:cl-debug-print :fiveam))
                 (shadow :run)
                 (use-package :fiveam)))
#+swank (cl-syntax:use-syntax cl-debug-print:debug-print-syntax)

;; BEGIN_INSERTED_CONTENTS
;; -*- coding:utf-8 -*-
(defstruct (queue (:constructor make-queue
                    (&optional list &aux (tail (last list)))))
  (list nil :type list)
  (tail nil :type (or null (cons t null))))

(declaim (inline enqueue))
(defun enqueue (obj queue)
  (symbol-macrolet ((list (queue-list queue))
                    (tail (queue-tail queue)))
    (if (null list)
        (setf tail (list obj)
              list tail)
        (setf (cdr tail) (list obj)
              tail (cdr tail))))
  queue)

(declaim (inline dequeue))
(defun dequeue (queue)
  (pop (queue-list queue)))

(defun empty-queue-p (queue)
  (null (queue-list queue)))

(declaim (inline enqueue-front))
(defun enqueue-front (obj queue)
  (symbol-macrolet ((list (queue-list queue))
                    (tail (queue-tail queue)))
    (if (null list)
        (setf tail (list obj)
              list tail)
        (push obj list))
    queue))

(defmacro dbg (&rest forms)
  #+swank
  (if (= (length forms) 1)
      `(format *error-output* "~A => ~A~%" ',(car forms) ,(car forms))
      `(format *error-output* "~A => ~A~%" ',forms `(,,@forms)))
  #-swank (declare (ignore forms)))

(defmacro define-int-types (&rest bits)
  `(progn
     ,@(mapcar (lambda (b) `(deftype ,(intern (format nil "UINT~A" b)) () '(unsigned-byte ,b))) bits)
     ,@(mapcar (lambda (b) `(deftype ,(intern (format nil "INT~A" b)) () '(signed-byte ,b))) bits)))
(define-int-types 2 4 7 8 15 16 31 32 62 63 64)

(defmacro println (obj &optional (stream '*standard-output*))
  `(let ((*read-default-float-format* 'double-float))
     (prog1 (princ ,obj ,stream) (terpri ,stream))))

(defconstant +mod+ 1000000007)

;; Body
(defun solve (k)
  ;; (num . cost)
  (declare #.OPT
           (uint31 k))
  (let ((queue (make-queue))
        (marked (make-array k :element-type 'bit :initial-element 0)))
    (enqueue (cons 1 1) queue)
    (loop until (empty-queue-p queue)
          for (num . cost) of-type (uint32 . uint62) = (dequeue queue)
          do (when (zerop num)
               (return cost))
             (when (zerop (aref marked num))
               (setf (aref marked num) 1)
               (let ((num*10 (mod (* 10 num) k)))
                 (when (zerop (aref marked num*10))
                   (enqueue-front (cons num*10 cost) queue)))
               (let ((num+1 (mod (+ num 1) k)))
                 (when (zerop (aref marked num+1))
                   (enqueue (cons num+1 (+ cost 1)) queue)))))))

(defun main ()
  (let* ((k (read)))
    (println (solve k))))

#-swank(main)


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

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

  vector<int> B(N - 1), A(N);
  for (int i = 0; i < (N - 1); i++) {
    int temp;
    cin >> temp;
    
    B.at(i) = temp;
  }

  for (int i = 0; i < N; i++) {
    int temp;

    if (i == 0) {
      temp = B.at(i);
    }
    else if (i == (N - 1)) {
      temp = B.at(i - 1);
    }
    else {
      temp = min(B.at(i), B.at(i - 1));
    }
    A.at(i) = temp;
  }

  int ans = 0;
  for (int i = 0; i < N; i++) {
    ans += A.at(i);
  }

  cout << ans << endl;
}


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

int main(){
  int64_t N;
  cin >> N;
  vector<int64_t> Sum(N+1);
  Sum.at(0)=0;
  int64_t S=0;
  int64_t A;
  for(int64_t i=0; i<N; i++){
    cin >> A;
    S+=A;
    Sum.at(i+1)=S;
  }
  int64_t Ans=0;
  int64_t count=1;
  sort(Sum.begin(), Sum.end());
  for(int64_t i=1; i<N+1; i++){
    if(Sum.at(i)==Sum.at(i-1)){
      count++;
    }
    else if(Sum.at(i)!=Sum.at(i-1)){
      Ans+=count*(count-1)/2;
      count=1;
    }
  }
  Ans+=count*(count-1)/2;
  cout << Ans << endl;
}

Measured memory_bytes: 1792
#include<bits/stdc++.h>
#define crap ios_base::sync_with_stdio(0);cin.tie(0)
#define ll long long
#define pb push_back
#define ff first
#define ss second
#define endl "\n"
#define int ll

using namespace std;

const int N = 1e5+5;
vector<int> G[N];
int n,m;
int dp[N];
int dfs(int u){
	if(dp[u]!=-1) return dp[u];
	dp[u]=0;
	for(auto i:G[u]){
		dp[u] = max(dp[u],1+ dfs(i));
	}
	return dp[u];
}

int32_t main()
{
    
   
    crap;
    memset(dp,-1,sizeof(dp));
    cin>>n>>m;
    for(int i=0;i<m;i++){
    	int x,y;
    	cin>>x>>y;
    	G[x].pb(y);
    }

    int ans=0;
    for(int i=1;i<=n;i++){
    		ans = max(ans, dfs(i));
    }
    cout<<ans<<endl;
   
   
}

Measured memory_bytes: 7936
//For higher stack size use g++ -O2 -std=c++11 -Wall -Wl,--stack=268435456 a.cpp -o a.exe in cmd
    #include <bits/stdc++.h>
    #include <cstdio>
    #include <cstring>
    #include <cmath>
    #include <cstring>
    #include <chrono>
    #include <complex>
    #define ll long long
    #define ld long double
    #define vi vector<int>
    #define vll vector<ll>
    #define vvi vector < vi >
    #define pii pair<int,int>
    #define pll pair<long long, long long>
    #define mod 1000000007
    #define inf 1000000000000000001;
    #define all(c) c.begin(),c.end()
    #define mp(x,y) make_pair(x,y)
    #define mem(a,val) memset(a,val,sizeof(a))
    #define eb emplace_back
    #define pb push_back
    #define f first
    #define s second
    
    using namespace std;
    int main()
    {
        std::ios::sync_with_stdio(false);
        int T;
        T=1;
        // cin.ignore(); must be there when using getline(cin, s)
        while(T--)
        {
            ll n,m,i,j,k;
            cin>>n>>m>>k;
            ll ar[n+1],ar2[m+1],ar3[n+1],ar4[m+1],ans=0,pos;
            ar3[0]=0,ar4[0]=0;
            for(i=1;i<=n;++i)
            {
                cin>>ar[i];
                ar3[i]=ar3[i-1]+ar[i];
            }
            // cout<<"HAI"<<endl;
            for(i=1;i<=m;++i)
            {
                cin>>ar2[i];
                ar4[i]=ar4[i-1]+ar2[i];
                if(ar4[i] <= k)
                    ans=max(ans,i);
            }
            for(i=0;i<=n;++i)
            {
                if(k<ar3[i])
                    break;

                pos = lower_bound(ar4+1, ar4+m+1, k-ar3[i]+1) - ar4;
                // cout<<i<<" "<<ar3[i]<<" "<<pos<<endl;
                --pos;
                ans=max(ans,i+pos);
            }
            cout<<ans<<endl;
        }
        return 0;
    }


Measured memory_bytes: 9904
n = int(input())
a = list(map(int, input().split()))
Sa = sorted(a)
if Sa[0] == 0:
  ans = 0
else:
  k = 0
  ans = 1
  for i in range(n):
    ans = ans*a[k]
    k += 1
    if ans > 10**18:
      ans = -1
      break
print(ans)

Measured memory_bytes: 21780
#include<stdio.h>
int main ()
{
    int flag=1,n1,n2,i,a;
    scanf("%d",&a);
    scanf("%d %d",&n1,&n2);
    for (i=n1;i<=n2;i++)
    {
        if (i%a==0)
        {
            flag=0;
            break;
        }
    }
    if (flag==1)
        printf("NG");
    else
        printf("OK");


}


Measured memory_bytes: 1728
#include <iostream>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <cmath>
#include <iomanip>
#include <algorithm>
using namespace std;
using ll = long long;

int main(){
    ll n, ans;
    cin >> n;
    ans = 1LL;
    for(int i = 1; i <= n; i++){
        ans = (ans*i) % 1000000007;
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll long long int
#define ld long double
#define f first
#define s second
#define pb push_back
#define eb emplace_back
#define mk make_pair
#define mt make_tuple
#define MOD 1000000007
#define fo(i,a,b) for(i=a;i<b;i++)
#define foe(i,a,b) for(i=a;i<=b;i++)
#define all(x) x.begin(), x.end()
#define vi vector<int>
#define vl vector <long long int>
#define pii pair <int,int>
#define pll pair <long long int, long long int>
#define vpii vector< pair<int,int> >
#define vpll vector < pair <long long int,long long int> >
#define boost ios::sync_with_stdio(false); cin.tie(0)
using namespace std;
const int inf = 2e9 + 5;
const ll inf64 = 1e18 + 5;

int main()
{
	boost;
	ll n, i;
	cin >> n;
	
	vector <pll> v(n);
	fo(i, 0, n)
	cin >> v[i].f >> v[i].s;
	
	sort(all(v), [&](const pll &p1, const pll &p2) {return p1.s < p2.s;});
	
	ll mx = -inf, my = -inf, ans = 0;	
	fo(i, 0, n) {
		ll x = v[i].f, y = v[i].s;
		ll c0 = y + x, c1 = y - x;
		ans = max(ans, max(c0 + mx, c1 + my));
		mx = max(mx, -y - x);
		my = max(my, -y + x);
	}
	
	mx = -inf, my = -inf;
	sort(all(v));
	
	fo(i, 0, n) {
		ll x = v[i].f, y = v[i].s;
		ll c0 = x + y, c1 = x - y;
		ans = max(ans, max(c0 + mx, c1 + my));
		mx = max(mx, -x - y);
		my = max(my, -x + y);
	}
	cout << ans;
}


Measured memory_bytes: 6336
A = int(input())
B = int(input())

if A == 1:
  if B == 2:
    print("3")
  else:
    print("2")
elif A == 2:
  if B == 1:
    print("3")
  else:
    print("1")
else:
  if B == 1:
    print("2")
  else:
    print("1")

Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
#define int long long
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
using P=pair<long long,long long>;
#define rep(i,n) for(long long i=0; i<(long long)n; i++)
#define FOR(i,a,b) for(long long i=a; i<b; i++)
#define ll long long
#define all(x) (x).begin(), (x).end()
#define SZ(x) ((long long)(x).size())
#define COUT(x) cout << x << endl
#define PB(x) push_back(x)
#define MP make_pair
#define vint vector<int>
#define vvint vector<vector<int>>
#define vstr vector<string>
#define SUM(x) accumulate(x.begin(),x.end(),0)
#define MAX(x) max_element(x.begin(),x.end())
#define MIN(x) min_element(x.begin(),x.end())
#define couty cout<<'Y'<<'e'<<'s'<<endl
#define coutn cout<<'N'<<'o'<<endl
#define coutY cout<<'Y'<<'E'<<'S'<<endl
#define coutN cout<<'N'<<'O'<<endl
//cout << std::fixed << std::setprecision(15);
long long gcd(long long a,long long b){return b?gcd(b,a%b):a;}
const long long dx[4]={1,0,-1,0};
const long long dy[4]={0,1,0,-1};
const long long INF = 1e12;
const long long MOD = 1e9+7;
signed main(){
    int n; cin >> n;
    vint ans;
    int a; cin >> a; ans.PB(a);
    FOR(i,1,n){
        int a; cin >> a;
        if(a<ans[ans.size()-1]) ans.PB(a);
    }
    cout<<ans.size()<<endl;
}

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

int main() {
	long long N, M, S;
	multiset<long long> MS;
	vector<long long> V;
	cin >> N;
	M = 1LL << N;
	for (int i = 0; i < M; i++) cin >> S, MS.insert(S);
	auto it = MS.end();
	it--;
	V.push_back(*it);
	MS.erase(it);
	for (long long i = 0; i < N; i++) {
		long long L = 1LL << i;
		for (long long j = 0; j < L; j++) {
			auto it2 = MS.lower_bound(V[j]);
			if (it2 == MS.begin()) {
				cout << "No" << endl;
				return 0;
			}
			it2--;
			V.push_back(*it2);
			MS.erase(it2);
		}
		sort(V.begin(), V.end(), greater<long long>());
	}
	cout << "Yes" << endl;
}

Measured memory_bytes: 14712
#include "bits/stdc++.h"

#define REP(i,num) for(int i=0;i<(num);++i)
#define LOOP(i) while(i--)
#define ALL(c) c.begin(),c.end()
#define PRINTALL(c) for(auto pitr=c.begin();pitr!=c.end();++pitr){cout<<*pitr;if(next(pitr,1)!=c.end())cout<<' ';}cout<<endl;
#define PAIRCOMP(c,comp) [](const pair<ll,ll>& lhs,const pair<ll,ll>& rhs){return lhs.c comp rhs.c;}

using namespace std;
using ll = long long;

constexpr ll atcoder_mod = 1e9+7;

template<typename T=int>
T in(){T x; cin >> x; return (x);}
template<typename T=int,typename C=vector<T>>
C vecin(int N){C x(N);REP(i,N){x[i]=in<T>();}return move(x);}

void vout(){cout << endl;}
template<typename Head,typename... Tail>
void vout(Head&& h,Tail&&... t){cout << ' ' << h;vout(forward<Tail>(t)...);}
void out(){cout << endl;}
template<typename Head,typename... Tail>
void out(Head&& h,Tail&&... t){cout << h;vout(forward<Tail>(t)...);}

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	cout<<fixed<<setprecision(10);
	
	int K=in(),T=in();
	auto A=vecin(T);

	sort(ALL(A),greater<int>());
	if(T==1){
		out(A[0]-1);
		return 0;
	}
	int diff = K-A[0];

	out(max(0,A[0]-diff-1));
	return 0;
}


Measured memory_bytes: 256
a(char *p){return((*p>'`')&&(*p<'{'));}
char b[82];
c(char *p,int d){return ((26+*p-*(p+1))%26==d);}
d(int s){char *p=b-1;while (*++p){if(a(p)){*p+=s;if((unsigned char)*p>'z')*p-=26;else if(*p<'a')*p+=26;}}}
main(s){while(gets(b)){char *p=b-1;s=0;while(*++p){if((c(p,12))&&((c(p+1,3)&&!a(p+3))||(c(p+1,7)&&c(p+2,7)&&!a(p+4))||(c(p+1,25)&&c(p+2,16)&&!a(p+4)))){s='t'-*p;p+=3;break;}else for(;a(p);p++);}d(s);puts(b);}}

Measured memory_bytes: 524
S = input()
N = len(S)
T = list(S)
i = 0
chack = 0

while i != int((N-1)/2):
    if T[i] != T[N-i-1]:
        chack = 1
        break
    else:
        i = i+1

i = 0
while i != int((N-1)/4):
    if T[i] != T[int((N-1)/2-i-1)]:
        chack = 1
        break
    else:
        i = i+1

i = 0
while i != int((N-1)/4):
    if T[int((N+1)/2)+i] != T[N-i-1]:
        chack = 1
        break
    else:
        i = i+1

if chack == 0:
    print("Yes")
else:
    print("No")

Measured memory_bytes: 3064
#include<stdio.h>

int main() {

	long long int N, A[100000], result;
	int i;

	result = 0;

	scanf("%llu", &N);
	for (i = 0; i < N; i++) {
		scanf("%llu", &A[i]);
	}

	result += A[0] / 2;
	A[0] %= 2;
	for (i = 1; i < N; i++) {
		if (A[i - 1] != 0 && A[i] != 0) {
			result++;
			A[i]--;
		}
		result += A[i] / 2;
		A[i] %= 2;
	}

	printf("%llu\n", result);

	return 0;
}

Measured memory_bytes: 896
#include <stdio.h>

int main(void){
	int a, b, d, r;
	double f;
	
	scanf("%d %d", &a, &b);
	
	d = a/b;
	r = a%b;
	f = (double)a / (double)b;
	
	printf("%d %d %.5lf\n", d, r, f);
	
	return(0);
	
}

Measured memory_bytes: 640
#include<stdio.h>
int main(){
  int a,b,c,d,e,i,j;
  scanf("%d %d %d %d %d",&a,&b,&c,&d,&e);
  int num[5] = {a,b,c,d,e};
  for(i=0;i<4;i++){
    for(j=0;j<4-i;j++){
      if(num[j]<num[j+1]){
	int temp = num[j];
	num[j] = num[j+1];
	num[j+1] = temp;
      }
    }
  }
  printf("%d %d %d %d %d\n",num[0],num[1],num[2],num[3],num[4]);
  return 0;
}

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

const long Day_num = 365;
const long type_num = 26;

class Scoring {
public:
    Scoring(const long arg_days, const std::vector<long>& arg_costs, const std::vector<std::vector<long>>& arg_incentives);
    std::vector<long> score(const std::vector<long>& arg_types);
private:
    long days;
    std::vector<long> costs;
    std::vector<std::vector<long>> incentives;
};

std::vector<long> Scoring::score(const std::vector<long>& arg_types) {
    std::vector<long> result(days);
    long satisfy = 0;
    std::vector<long> last_days(type_num, 0);


    for (long day = 1; day <= days; ++day) {
        const auto exe_type = arg_types[day-1];
        satisfy += incentives[day-1][exe_type-1];
        last_days[exe_type-1] = day;
        for (long type = 1; type <= type_num; ++type) {
            satisfy -= costs[type-1] * (day - last_days[type-1]);
        }
        result[day-1] = satisfy;
    }
    return result;
}

Scoring::Scoring(const long arg_days, const std::vector<long>& arg_costs, const std::vector<std::vector<long>>& arg_incentives) {
    days = arg_days;
    costs = arg_costs;
    incentives = arg_incentives;
}

int main() {
    clock_t start_clock = clock();
    std::mt19937 engine(10000000);
    std::uniform_int_distribution<> type_random(1, type_num);
    std::uniform_int_distribution<> day_random(1, Day_num);
    long D;
    std::cin >> D;
    std::vector<long> costs(type_num);
    for (long type = 1; type <= type_num; ++type) {
        std::cin >> costs[type-1];
    }
    std::vector<std::vector<long>> incentives(D, std::vector<long>(type_num));
    for (long day = 1; day <= D; ++day) {
        for (long type = 1; type <= type_num; ++type) {
            std::cin >> incentives[day-1][type-1];
        }
    }

    Scoring scoring(D, costs, incentives);

    std::vector<long> types(D);
    for (long day = 1; day <= D; ++day) {
        types[day-1] = type_random(engine);
    }

    while (static_cast<double>(clock() - start_clock)/CLOCKS_PER_SEC*1000.0 < 2000.0-100.0) {
        const auto old_types = types;
        types[day_random(engine)-1] = type_random(engine);
        if (scoring.score(old_types).back() > scoring.score(types).back()) {
            types = old_types;
        }
    }

    for (long day = 1; day <= D; ++day) {
        std::cout << types[day-1] << std::endl;
    }
    return 0;
}

Measured memory_bytes: 3864
#include<stdio.h>
int main(){
  int x, a, b;
  scanf("%d %d %d", &x, &a, &b);
  if(a>=b){
    printf("delicious\n");
  }else if(x < b-a){
    printf("dangerous\n");
  }else{
    printf("safe\n");
  }

  return 0;
}


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

int main() {
    long long N, M, ans;
    cin >> N >> M;
    if(N * 2 < M) {
        ans = N;
        M -= N * 2;
        ans += M / 4;
    } else {
        ans = M / 2;
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
{-# LANGUAGE FlexibleContexts #-}
{-# LANGUAGE UnboxedTuples #-}
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE BangPatterns #-}
{-# LANGUAGE LambdaCase #-}
{-# LANGUAGE ViewPatterns #-}
{-# LANGUAGE TupleSections #-}
{-# LANGUAGE MultiWayIf #-}

import Control.Monad
import Control.Applicative
import Control.Monad.ST
import Control.Monad.State
import Data.Array.ST
import Data.List
import Data.Array
import Data.Array.IO
import Data.Maybe
import Data.Bits
import Data.Ord
import Data.Ratio
import Data.Int
import Data.Char
import qualified Data.ByteString.Char8 as BS
import qualified Data.Set as Set
import Text.Printf
import Debug.Trace
import Numeric

modifyArray arr i f = readArray arr i >>= \x -> writeArray arr i (f x)

listToTuple2 [a,b] = (a,b)
listToTuple3 [a,b,c] = (a,b,c)
listToTuple4 [a,b,c,d] = (a,b,c,d)

getWords = getLine >>= return . words

readIntBS = fst . fromJust . BS.readInt

for = flip map

main :: IO ()
main = do
  (n,m) <- listToTuple2 . map read . words <$> getLine :: IO (Int,Int)
  es <- replicateM m $ listToTuple3 . map readIntBS . BS.words <$> BS.getLine :: IO [(Node,Node,Cost)]

  let
    graph = buildWeightedUndirectedGraph (1,n) es
    wf = warshall_floyd graph
    
  print $ length [edge | edge@(s,e,c) <- es, not $ or [wf!(i,j) == wf!(i,s) + c + wf!(e,j) | i<-[1..n], j<-[1..n]]]

  
type Node = Int
type Cost = Int
type Edge = (Node, Cost)
type Graph = Array Node [Edge]

inf = div maxBound 2 :: Int

warshall_floyd :: Graph -> Array (Node,Node) Cost
warshall_floyd graph = runST $ do
  let (s,e) = bounds graph
  dp <- newArray ((s,s),(e,e)) inf :: ST s (STUArray s (Node,Node) Cost)

  forM_ [s..e] $ \i -> do
    writeArray dp (i,i) 0

  forM_ [s..e] $ \i -> do
    forM_ (graph ! i) $ \(j,c) -> do
      writeArray dp (i,j) c

  forM_ [s..e] $ \k -> do
    forM_ [s..e] $ \i -> do
      forM_ [s..e] $ \j -> do
        a <- readArray dp (i,j)
        b <- readArray dp (i,k)
        c <- readArray dp (k,j)
        writeArray dp (i,j) $ min a (b+c)

  freeze dp

{-- 重み付き無向グラフ --}
buildWeightedUndirectedGraph :: (Int,Int) -> [(Int,Int,Int)] -> Array Int [(Int,Int)]
buildWeightedUndirectedGraph bound dat = runST $ do
  graph <- newArray bound [] :: ST s (STArray s Int [(Int,Int)])
  forM_ dat $ \(s,e,c) -> do
    modifyArray graph s ((e,c):)
    modifyArray graph e ((s,c):)
  freeze graph


Measured memory_bytes: 2556
import heapq
import os
import sys

import numpy as np

if os.getenv("LOCAL"):
    sys.stdin = open("_in.txt", "r")

sys.setrecursionlimit(2147483647)
INF = float("inf")

N = int(sys.stdin.readline())
A = list(map(int, sys.stdin.readline().split()))

A = np.array(A, dtype=int)

# 区切る場所を N -> 2N まで全探索
# 区切る場所より左は大きいやつを順に
# 区切る場所より右は小さいやつを順に取るのが最適
lefts = list(A[:N])
heapq.heapify(lefts)

L_sum = sum(lefts)
L_hist = [L_sum]
for div in range(N, 2 * N):
    if A[div] > lefts[0]:
        L_sum += A[div] - lefts[0]
        heapq.heapreplace(lefts, A[div])
    L_hist.append(L_sum)

rights = list(-A[N * 2:])
heapq.heapify(rights)
r_sum = -sum(rights)
r_hist = [r_sum]
for div in reversed(range(N, 2 * N)):
    if A[div] < -rights[0]:
        r_sum += A[div] - (-rights[0])
        heapq.heapreplace(rights, -A[div])
    r_hist.append(r_sum)
r_hist.reverse()

ans = -INF
for l, r in zip(L_hist, r_hist):
    ans = max(ans, l - r)
print(ans)


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

int main(int argc, char *argv[]) {

  int N, K;
  char S[50 + 1];

  scanf("%d%d\n",&N, &K);
  scanf("%s", S);

  K = K - 1; //先頭からの文字数に変換
  if(S[K] <=  'C') {
    S[K] += 0x20;
  } else {
    S[K] -= 0x20;
  }

  printf("%s",S);

}


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

char c[100][100];
char c1[200][100];

int main(void){
    // Your code here!
    int h,w;
    cin>>h>>w;
    
    for(int i=0; i<h; i++){
        for(int j=0; j<w; j++){
            cin>>c[i][j];
        }
    }
    
    for(int i=0; i<2*h; i++){
        for(int j=0; j<w; j++){
            c1[i][j]=c[(i)/2][j];
        }
    }
    
    
    for(int i=0; i<2*h; i++){
        for(int j=0; j<w; j++){
            cout<<c1[i][j];
        }
        cout<<endl;
    }
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (n); i++)
#define ALL(v) (v).begin(), (v).end()
using ll = long long;
using P = pair<int, int>;
constexpr int INF = 1e9;
constexpr long long LINF = 1e18;
constexpr long long MOD = 1e9 + 7;

map<long long, int> PrimeFactor(long long n) {
    map<long long, int> mp;
    for (int i = 2; (long long)i * i <= n; i++) {
        while (n % i == 0) {
            mp[i]++;
            n /= i;
        }
    }
    if (n != 1) mp[n]++;
    return mp;
}

signed main() {
    ll n;
    cin >> n;
    int ans = 0;
    auto pf = PrimeFactor(n);
    for(auto a : pf){
        int t = 1;
        while (a.second >= t){
            a.second -= t;
            t++;
            ans++;
        }
    }
    cout << ans << endl;
    return 0;
}

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

template<class T> void vin(vector<T>& v, int n) {
    v.resize(n);
    for (int i = 0; i < n; ++i) {
        cin >> v[i];
    }
}

int main() {
    int T, D, L;
    while (cin >> T >> D >> L and T and D and L) {
        int ans = 0;
        int cur = 0;
        rep(i, T) {
            cur--;
            int x;
            cin >> x;
            if (cur >= 0) {
                ans++;
            }
            if (x >= L) {
                cur = D;
            }
        }
        cout << ans << endl;
    }
    return 0;
}



Measured memory_bytes: 3004
//2019.3.23 by ljz
#include<bits/stdc++.h>
using namespace std;
#define res register int
#define RG register
#define LL long long
#define inf 0x3f3f3f3f
#define eps 1e-15
inline int read(){
    res s=0,w=1,ch=getchar();
    while(ch<'0'||ch>'9'){if(ch=='-')w=-1;ch=getchar();}
    while(ch>='0'&&ch<='9')s=s*10+ch-'0',ch=getchar();
    return s*w;
}
inline void swap(res &x,res &y){
    x^=y^=x^=y;
}
namespace MAIN{
    char str[20];
    inline void MAIN(){
        scanf("%s",str+1);
        res n=strlen(str+1),ans=0;
        for(res i=1;i<=n;i++){
            res ret=0;
            for(res j=i;j<=n;j++)
                if(str[j]=='A'||str[j]=='C'||str[j]=='G'||str[j]=='T')ret++;
                else break;
            ans=max(ans,ret);
        }
        printf("%d\n",ans);
    }
}
int main(){
    MAIN::MAIN();
    return 0;
}

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

static const int max_price = 2000;

int main() {
  int a, b;
  scanf("%d %d", &a, &b);
  
  bool succ = false;
  for (int i = 0; i < max_price; i++)
    if (static_cast<int>(floor(i * 0.08)) == a && static_cast<int>(floor(i * 0.1)) == b) {
      succ = true;
      printf("%d\n", i);
      break;
    }

  if (!succ)
    printf("-1\n");

  return 0;
}


Measured memory_bytes: 256
#pragma GCC optimize("O3")

#define _GLIBCXX_DEBUG
#include <iostream>
#include <vector>
#include <string>
#include <string_view>
#include <algorithm>
#include <cmath>
#include <iomanip>
#include <cassert>
#include <list>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <stack>
#include <bitset>
using namespace std;

/*----------macros----------*/

//output================
#define endl '\n'
#define fcout(a) cout << fixed << setprecision((int)(a))

//typedef===============
typedef long long       ll;
typedef long double     ld;
typedef vector<int>     Vi;
typedef vector<ll>      Vl;
typedef pair<int, int>  Pii;
typedef pair<ll, ll>    Pll;

//const number==========
constexpr ll INF9   = (ll)1e9 + 1;
constexpr ll INF18  = (ll)1e18 + 1;
constexpr ll MOD1    = 1000000007;
constexpr ll MOD2   = 998244353;
constexpr ld PI     = 3.141592653589793L;

//member================
#define psb push_back
#define epb emplace_back
#define psf push_front
#define mkp make_pair
#define fst first
#define scd second

//others================
#define all(x)          (x).begin(), (x).end()
#define rall(x)         (x).rbegin(), (x).rend()
#define rep(i, n)       for(int i = 0; (i) < (n); ++(i))
#define reps(i, n)      for(int i = 1; (i) <= (n); ++(i))
#define rrep(i, n)      for(int i = n - 1; (i) >= 0 ; --(i))
#define repbit(bit, n)  for(int bit = 0; (bit) < (1 << (n)); ++(bit))
#define ifbit(bit, i)   if((bit) & (1 << (i)))
#define CtoI(c)         int((c)) - int('0')
#define ItoC(c)         char((c) + '0')

//functions=============
template<typename T1, typename T2>
inline bool chmax(T1 &a, T2 b) { return a < b && (a = b, true); }

template<typename T1, typename T2>
inline bool chmin(T1 &a, T2 b) { return a > b && (a = b, true); }

//vector<int> dx = {1, 0, -1, 0}, dy = {0, 1, 0, -1};
//vector<int> dx2 = { 1,1,0,-1,-1,-1,0,1 }, dy2 = { 0,1,1,1,0,-1,-1,-1 };

/*--------additional--------*/



/*----------main------------*/

int main(int argc, char *argv[]) {
/*----------fastio----------*/
    std::cin.tie(nullptr);
    std::cout.tie(nullptr);
    std::ios::sync_with_stdio(false);
/*----------solve-----------*/

    int n, a, b; cin >> n >> a >> b;
    cout << min(n*a, b) << endl;

return 0;
}

Measured memory_bytes: 3588
#k = int(input())
#s = input()
#a, b = map(int, input().split())
#s, t = map(str, input().split())
#l = list(map(int, input().split()))
#l = [list(map(int,input().split())) for i in range(n)]
#a = [list(input()) for _ in range(n)]

o = input()
n = input()

for i in range(len(n)):
    print(o[i], end="")
    print(n[i], end="")

if len(o) - len(n) == 1:
    print(o[-1])



Measured memory_bytes: 8976
#include <bits/stdc++.h>
#include <math.h>
#include <vector>
#include <queue>
#include <iomanip>
#include <string>
using namespace std;
using Graph = vector<vector<int>>;
#define rep(i,n) for(int i=0;i<n;i++)
#define rep_1 (i,j,n) for(int i=j;i<n;i++)
typedef long long ll;
typedef long l;
const ll l_INF = 101010101000;
const int INF = 1010101010;
const int dx[4] = {-1,0,1,0};
const int dy[4] = {0,-1,0,1};
using vi = vector<int>;
using vvi = vector<vi>;
using pii = pair<int,int>;

int main(){
  int x,y;
  cin >> x >> y;
  rep(i,x+1){
    int l=i*2+(x-i)*4;
    //cout << l<<endl;
    if(l==y){
      cout << "Yes";
      return 0;
    }
  }
  cout << "No";
}

Measured memory_bytes: 3636
import sys
import math
def get_array(): return list(map(int, sys.stdin.readline().strip().split()))
def get_ints(): return map(int, sys.stdin.readline().strip().split())
def input(): return sys.stdin.readline().strip()
n=int(input())
if n%1000==0:
    print(0)
else:
    print(1000-n%1000)




Measured memory_bytes: 61908
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int arr[1020],i,n,p,k,j,res=0;
    cin>>n>>k;

    for(i=0;i<n;i++)
        cin>>arr[i];


    sort(arr,arr+n);

    for(i=0;i<k;i++)
        res+=arr[i];

    cout<<res<<endl;




return 0;

}


Measured memory_bytes: 3612
use proconio::input;
use proconio::marker::Chars;
#[allow(unused_imports)]
use std::cmp::{max, min};
#[allow(unused)]
const ALPHA_SMALL: [char; 26] = [
    'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's',
    't', 'u', 'v', 'w', 'x', 'y', 'z',
];
#[allow(unused)]
const ALPHA: [char; 26] = [
    'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S',
    'T', 'U', 'V', 'W', 'X', 'Y', 'Z',
];
#[allow(unused)]
fn main() {
    input!(X: i64);
    if X >= 30 {
        println!("Yes");
    } else {
        println!("No");
    }
}


Measured memory_bytes: 2116
#include <iostream>
#include <cmath>
int main(){
    int k;
    std::cin >> k;
    if(k%2 == 0) std::cout << std::pow(k/2, 2) << std::endl;
    else std::cout << (k/2)*(k/2 + 1) << std::endl;
    return 0;
}

Measured memory_bytes: 256
def comb(n, r):
  return n == ( r | (n - r) ) 
  
N=int(input())
S=input()
x=0;
b=1;
for i in range(N):
  s=int(S[i])%2;
  x=(x+s*(comb(N-1,i)))%2;
  b*=s%2;
if(x%2 or b==0):
  print(x%2);exit();
x=0;
for i in range(N):
  s=(int(S[i])//2)%2;
  x=(x+s*(comb(N-1,i)))%2;

print((x%2)*2);

Measured memory_bytes: 54108
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<set>

using namespace std;

int main()
{
	int n;
	cin >> n;
	vector<int> a(n);
	set<int> color;
	int count=0;
	for(int i=0;i<n;i++)
	{
		cin >> a[i];
		a[i]/=400;
//		cout << a[i] << endl;
		if(a[i]>=8)
		{
			count++;
		}
		else color.insert(a[i]);
	}

	cout << (color.size()==0 ? 1:color.size()) << " " << color.size()+count << endl;
	



	
}

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

using namespace std;

int n;
char str[100100];

int main() {
    scanf("%s",str);
    n = strlen(str);
    if ((n%2==1)^(str[0]==str[n-1])) printf("First\n");
    else printf("Second\n");

    return 0;
}


Measured memory_bytes: 384
#C
h, w, k = map(int, input().split())
c = [input() for _ in range(h)]
ans = 0
for i in range(2 ** h):
    
    T = [c[j] for j in range(h) if (i >> j) & 1]
    #iをjだけシフトしたときが1である時のcの配列の集まり -> 塗る列
    for j in range(2 ** w): #塗る行数
        x = 0
        #行で見る
        for m in range(w):
            #選んだマスの行を塗る
            #mビットシフトした値と1のANDが1である -> mビット目が1である
            if (j >> m) & 1:
                for n in range(len(T)):
                    if T[n][m] == "#":
                        x += 1
        # 選択したマスの#の数がk個
        if x == k:
            ans += 1
print(ans)

Measured memory_bytes: 9112
#include <bits/stdc++.h>
#define rep(i,n) for(int i=(0);i<(n);i++)

using namespace std;

typedef long long ll;

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

	int N;
	cin >> N;

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

	int ans = N;
	for(int i = 0; i < N; i++){
		for(int j = 0; j < N; j++){
			if(i == j) continue;
            int p = x[i] - x[j];
            int q = y[i] - y[j];

            int t = 0;
            for(int k = 0; k < N; k++){
                for(int l = k+1; l < N; l++){
                    if((x[k] - x[l] == p) && (y[k] - y[l] == q)) t++;
                    if((x[k] - x[l] == -p) && (y[k] - y[l] == -q)) t++;
                }
            }

            ans = min(ans, N - t);
        }
    }

    cout << ans << endl;
}


Measured memory_bytes: 256
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <string.h>

#define mod 1e9+7
#define ll long long int
#define epsilon 1e-7



int main(void){
    int n, y;
    scanf("%d %d", &n, &y);
    int ans = 0;
    int a, b, c;
    for(int i = 0;i <= n;i++){
        for(int j = 0;j <= n-i;j++){
            if(10000*i+5000*j+1000*(n-i-j)==y){
                ans = 1;
                a = i;
                b = j;
                c = n-i-j;
                break;
            }
        }
        if(ans)break;
    }
    if(ans)printf("%d %d %d\n", a, b, c);
    else printf("-1 -1 -1\n");
    return 0;
}

Measured memory_bytes: 128
#include<iostream>
#include<bits/stdc++.h>
using namespace std;
int main(){
    int N;
    cin >> N;
    vector<string> S(N);
    for(int i=0;i<N;i++){
        cin >> S.at(i);
    }
    sort(S.begin(),S.end());
    S.erase(unique(S.begin(), S.end()),S.end());
    cout << S.size() << endl;
}


Measured memory_bytes: 9532
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<math.h>


int main(void){

    int Aprice,Bprice,Cprice;
    int numA,numB;

    scanf("%d %d %d %d %d",&Aprice,&Bprice,&Cprice,&numA,&numB);

    long ans=5000000000;
    int numMAX=0;
    if(numA>numB) numMAX=numA;
    else numMAX=numB;

    long price;

    for(int i=0;i<=numMAX;i++){
        if(numA>=i && numB>=i) price=Aprice*(numA-i)+Bprice*(numB-i)+Cprice*2*i;
        else if(numA>=i && numB<i) price=Aprice*(numA-i)+Cprice*2*i;
        else if(numA<i && numB>=i) price=Bprice*(numB-i)+Cprice*2*i;
        
        if(price<ans) ans=price;
    }

    printf("%ld\n",ans);
    
    return 0;
}


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

#define REP(i,s,n) for(int i=s;i<n;++i)
#define rep(i,n) REP(i,0,n)
#define ALL(x) x.begin(),x.end()
#define EPS (1e-8)
#define equals(a,b) (fabs((a)-(b))<EPS)

using namespace std;

typedef long long ll;
bool LTE(double a,double b) { return equals(a,b) || a < b; }
bool LT(double a,double b) { return !equals(a,b) && a < b; }

void compute() {

}

int calc(int v) {
  int ret = 0;
  while( v ) {
    ret += ( v % 10 );
    v /= 10;
  }
  return ret;
}

int main() {
  int n;
  cin >> n;
  int mini = INT_MAX;
  REP(a,1,n) {
    int b = n - a;
    int sum = calc(a)+calc(b);
    mini = min(mini,sum);
  }
  cout << mini << endl;
  compute();
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pint = pair<int,int>;


const long long INFLL = 1LL << 60;
const int INFI = 1000000000;


int main() {
    int N; cin >> N;
    string S; cin >> S;
    int count=0;
    for(int i=1;i<S.size();i++){
        if(S[i]=='E')count++;
    }
    int ans=count;
    for(int i=1;i<S.size();i++){
        if(S[i-1]=='W')count++;
        if(S[i]=='E') count--;
        if(count<ans) ans=count;
    }
    cout << ans << endl;
}



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

using namespace std;

#define INF 1001000100010001000
#define MOD 1000000007
#define EPS 1e-10
#define int long long
#define rep(i, N) for (int i = 0; i < N; i++)
#define Rep(i, N) for (int i = 1; i < N; i++)
#define For(i, a, b) for (int i = (a); i < (b); i++)
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define pii pair<int, int>
#define vi vector<int>
#define vvi vector<vi >
#define vb vector<bool>
#define vvb vector<vb >
#define vp vector< pii >
#define all(a) (a).begin(), (a).end()
#define Int(x) int x; cin >> x;
#define int2(x, y) Int(x); Int(y);
#define int3(x, y, z) Int(x); int2(y, z);
#define in(x, a, b) ((a) <= (x) && (x) < (b))
#define fir first
#define sec second
#define ffir first.first
#define fsec first.second
#define sfir second.first
#define ssec second.second
#define Decimal fixed << setprecision(10)

//int dxy[5] = {0, 1, 0, -1, 0};
// cmd

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

    int3(a, b, c);

    cout << min({a + b, b + c, a + c}) << endl;

    return 0;
}


Measured memory_bytes: 256
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.io.IOException;
import java.util.NoSuchElementException;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        FasterScanner in = new FasterScanner(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        TaskA solver = new TaskA();
        solver.solve(1, in, out);
        out.close();
    }

    static class TaskA {
        public void solve(int testNumber, FasterScanner in, PrintWriter out) {
            String s = in.next();

            long[] countB = new long[s.length()];
            countB[0] = s.charAt(0) == 'B' ? 1 : 0;

            for (int i = 1; i < s.length(); i++) {
                countB[i] = countB[i - 1] + (s.charAt(i) == 'B' ? 1 : 0);
            }

            long ans = 0;
            for (int i = 0; i < s.length(); i++) {
                if (s.charAt(i) == 'W')
                    ans += countB[i];
            }
            out.println(ans);
        }

    }

    static class FasterScanner {
        private InputStream in;
        private byte[] buffer;
        private int bufPointer;
        private int bufLength;

        public FasterScanner(InputStream in) {
            this.in = in;
            buffer = new byte[1024];
        }

        private boolean hasNextByte() {
            if (bufPointer < bufLength) return true;
            bufPointer = 0;
            try {
                bufLength = in.read(buffer);
            } catch (IOException e) {
                e.printStackTrace();
            }
            return (bufLength > 0);
        }

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

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

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

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

    }
}



Measured memory_bytes: 25300
#include<iostream>
using namespace std;
int main(){
	int n,x,dem=0;
	do{
		dem=0;
	cin >>n>>x;
	if(n==0 && x==0)
		break;
	for(int i=1;i<n-1;i++)
		for(int j=i+1;j<n;j++)
			for(int k=j+1;k<=n;k++)
				if(i+j+k==x)
					dem++;
	cout <<dem<<endl;;
	}while(true);
	return 0;
}

Measured memory_bytes: 3076
#include <cstdio>
#include <algorithm>
using namespace std;
int main() {
	long long A, B, C, K, ans = 0;
	scanf("%lld %lld %lld %lld", &A, &B, &C, &K);
	ans += min(A, K);
	K -= min(A, K);
	K -= min(B, K);
	ans -= min(C, K);
	printf("%lld", ans);
	return 0;
}

Measured memory_bytes: 1736
/*
─────────────────────
───────────████████──
──────────███▄███████
──────────███████████
──────────███████████
──────────██████─────
──────────█████████──
█───────███████──────
██────████████████───
███──██████████──█───
███████████████──────
███████████████──────
─█████████████───────
──███████████────────
────████████─────────
─────███──██─────────
─────██────█─────────
─────█─────█─────────
─────██────██────────
─────────────────────
*/
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/detail/standard_policies.hpp>

#define int long long
#define read(a) int a; cin >> a;
#define readb(a, b) int a, b; cin >> a >> b;
#define readc(a, b, c) int a, b, c; cin >> a >> b >> c;
#define reads(s) string s; cin >> s;
#define readarr(a, n) int a[(n) + 1] = {}; fori (i, 1, (n)) {cin >> a[i];}
#define readmat(a, n, m) int a[n + 1][m + 1] = {}; fori (i, 1, n) {fori (j, 1, m) cin >> a[i][j];}

#define print(a) cout << a << endl;
#define printarr(a, n) fori (i, 1, n) cout << a[i] << " "; cout << endl;
#define printv(v) for (int i: v) cout << i << " "; cout << endl;
#define printmat(a, n, m) fori (i, 1, n) {fori (j, 1, m) cout << a[i][j] << " "; cout << endl;}
#define all(v) v.begin(), v.end()
#define sz(s) (int)(s.size())
#define pb push_back
#define fi first
#define se second
#define rz resize
#define fori(i, a, b) for (int i = (a); i <= (b); i++)
#define ford(i, a, b) for (int i = (a); i >= (b); i--)
#define endl '\n'
#define setprec(x) cout << fixed << setprecision(x);
 
using namespace std;
using namespace __gnu_pbds; 
 
typedef tree<long long,null_type,less<long long>,rb_tree_tag,tree_order_statistics_node_update> ordered_set;
typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef pair<int, int> pii;
typedef vector<pair <int, int>> vpi;
typedef vector < vector <int> > vvi;
 
const int INF = 4e18;
const int mod = 1e9+7; 

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


    //start from here

    readb(n, k) reads(s)

   	if(s[k-1] == 'A') s[k-1] = 'a';
   	else if(s[k-1] == 'B') s[k-1] = 'b';
   	else s[k-1] = 'c';

   	cout << s;

    return 0;
}


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

int dp[100001];

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

	int n,k,t;
	vector <int> v;

	cin >> n >> k;
	for(int i=0;i<n;i++)
	{
		cin >> t;
		v.push_back(t);
	}

	sort(v.begin(),v.end());

	for(int i=0;i<v[0];i++)
	{
		dp[i] = 0;
	}

	for(int i=v[0];i<=k;i++)
	{
		bool find = false;
		for(int j=0;j<n;j++)
		{
			if(i - v[j] < 0)
			{
				break;
			}
			if(dp[i - v[j]]==0)
			{
				find = true;
				break;
			}
		}
		if(find)
		{
			dp[i] = 1;
		}
		else
		{
			dp[i] = 0;
		}
	}

	if(dp[k]==0)
	{
		cout << "Second" << '\n';
	}
	else
	{
		cout << "First" << '\n';
	}

	return 0;
}

Measured memory_bytes: 640
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
#define pii pair<int,int>
#define pb push_back
#define fi first
#define se second
#define UP(a,b,c) for(ll (a)=(b);(a)<(c);(a)++)
#define UU(a,b,c) for(ll (a)=(b);(a)<=(c);(a)++)
#define DN(a,b,c) for(ll (a)=(b);(a)>(c);(a)--)
#define DU(a,b,c) for(ll (a)=(b);(a)>=(c);(a)--)

ll x,n,d;

void reset()
{
}

void input()
{
	cin>>x>>n>>d;
	
	x = abs(x);
	ll temp = x / d;
	
	temp = min(temp, n);
	n -= temp;
	x -= d*temp;
	
	n%=2;
	ll ans = abs(x);
	x-=d * n;
	
	cout<<abs(x)<<endl;
}

void solve()
{
}

void LetsRock()
{
	solve();	
}

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

	input();
	reset();
	LetsRock();
	
	return 0;
}


Measured memory_bytes: 3648
/**
 * code generated by JHelper
 * More info: https://github.com/AlexeyDmitriev/JHelper
 * @author
 */

#include <iostream>
#include <fstream>

#include <iostream>
#include "bits/stdc++.h"

using namespace std;
typedef unsigned long long ll;
typedef int                     integer;
#define int                     long long
#define ii                      pair<int,int>
#define vii                     vector<pair<int,int>>
#define vi                      vector<int>
#define vvi                     vector<vector<int>>
#define f(a,b,c)                for(int a=b;a<c;a++)
#define s(x)                    in>>x
#define s2(x,y)                 in>>x>>y
#define s3(x,y,z)               in>>x>>y>>z
#define s4(x,y,z,w)             in>>x>>y>>z>>w
#define p(x)                    out<<x<<endl
#define p2(x,y)                 out<<x<<' '<<y<<endl
#define p3(x,y,z)               out<<x<<' '<<y<<' '<<z<<endl
#define p4(x,y,z,w)             out<<x<<' '<<y<<' '<<z<<' '<<w<<endl
#define pl(x)                   out<<x
#define pll(x)                  out<<x<<' '
#define range(v)                v.begin(),v.end()
#define rst(x)                  memset(x, -1, sizeof(x))
#define UNVISITED               -1
#define VISITED                 0
#define EXPLORED                2

#define EACH(x, a) for (auto& x: a)
template<class T> void read_v(T& x, std::istream& in) {
    in >> (x);
}
template<class A> void read_vec(vector<A>& x, std::istream& in) {
    EACH(a, x)
        read_v(a, in);
}

bool sortpairbysec(const pair<int,int> &a,const pair<int,int> &b){return (a.second < b.second);}
template <typename T>
T factmod(T a, T modulus){ int res = 1, i; for (i = 2; i <= a; i++){ res *= i; res%=modulus;} return res; }
template <typename T>
int powmod(T a,T b,int m){ int ans=1; while(b>0){if(b&1){ans*=a;ans%=m;}a*=a;a%=m;b>>=1;} return ans; }
template <typename T>
int power(T a, T b){ int ans=1; while(b>0){if(b&1){ans*=a;}a*=a;b>>=1;}return ans;}

const int CMOD = 1e9 + 7;
void ssolve(std::istream& in, std::ostream& out){
    int n; s(n);
    vector<int> a(n);
    vector<int> cs(n + 1, 0);
    f(i, 0, n){
        s(a[i]);
        cs[i + 1] = cs[i] + a[i];
    }
    int ans = 0;
    for(int i = 0; i < n; i++){
        ans += (a[i] * ((cs[n] - cs[i + 1])%CMOD))%CMOD;
        ans %= CMOD;
    }
    p(ans);
}

class CSumOfProductOfPairs {
public:
void solve(std::istream& in, std::ostream& out) {
    ios_base::sync_with_stdio(false);
    in.tie(nullptr);out.tie(nullptr);
    int t;
    int READ = 0;
    if(READ) s(t);
    else t = 1;
    while(t--){
        ssolve(in, out);
    }
}
};

integer main() {
    CSumOfProductOfPairs solver;
    std::istream& in(std::cin);
     std::ostream& out(std::cout);
     solver.solve(in, out);
}

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

using namespace std;

typedef long long ll;
typedef pair<ll, ll> P;

#define MOD 1000000007
#define REP(i, N) for (int i = 0; i < N; ++i)
#define REP1(i, N) for (int i = 1; i <= N; ++i)
#define RREP(i, N) for (int i = N - 1; i >= 0; --i)
#define ALL(a) a.begin(), a.end()
#define ADD(a, b) a = (a + b) % MOD

// x^n
ll mod_pow(ll x, ll n) {
  if (n == 0) return 1;
  ll res = mod_pow(x * x % MOD, n / 2);
  if (n & 1) res = res * x % MOD;
  return res;
}

// x^{-1}
ll inv(ll x) { return mod_pow(x, MOD - 2); }

ll fact[500001];
ll fact_inv[500001];

void init_fact() {
  fact[0] = fact_inv[0] = 1;
  REP(i, 500000) {
    fact[i + 1] = fact[i] * (i + 1) % MOD;
    fact_inv[i + 1] = fact_inv[i] * inv(i + 1) % MOD;
  }
}

ll nCr(ll n, ll r) {
  if (n < r || n < 0 || r < 0) return 0;
  return fact[n] * fact_inv[r] % MOD * fact_inv[n - r] % MOD;
}

ll nPr(ll n, ll r) { return nCr(n, r) * fact[r] % MOD; }

int main() {
  init_fact();
  ll n, m, k;
  cin >> n >> m >> k;
  ll ans = 0;
  for (ll d = 1; d < n; ++d) {
    ADD(ans, d * (n - d) % MOD * m % MOD * m % MOD);
  }
  for (ll d = 1; d < m; ++d) {
    ADD(ans, d * (m - d) % MOD * n % MOD * n % MOD);
  }
  ans *= nCr(n * m - 2, k - 2);
  ans %= MOD;
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 8064