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

#pragma GCC target("avx")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define REP(i, n) for (int i = 1; i <= (int)(n); i++)
#define repi(i, s, n) for (int i = (s); i < (int)(n); i++)
#define all(x) (x).begin(), (x).end()
#define uniqueV(x)          \
  sort(x.begin(), x.end()); \
  x.erase(unique(x.begin(), x.end()), x.end());
#define debug(x) cerr << #x << ": " << x << '\n'
#define debug2(x, y) cerr << "(" << #x << ", " << #y << ") = " \
                          << "(" << x << ", " << y << ")" << '\n'

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

const long long INF = 3e18 + 12;
const int inf = 1e9;

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

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

  char a;
  char b;

  cin >> a >> b;

  if (a == 'H') {
    if (b == 'H') {
      cout << 'H' << endl;
      return 0;
    } else {
      cout << 'D' << endl;
      return 0;
    }
  } else {
    if (b == 'H') {
      cout << 'D' << endl;
      return 0;
    } else {
      cout << 'H' << endl;
      return 0;
    }
  }

  return 0;
}

Measured memory_bytes: 256
from math import sqrt
n, d = map(int, input().split())
dots = []
for i in range(n):
    dot = list(map(int, input().split()))
    dots.append(dot)
cnt = 0
for i in range(n-1):
    for j in range(i+1, n):
        distance = 0
        for dm in range(d):
            distance += pow(dots[i][dm] - dots[j][dm],2)
        dis = sqrt(distance)
        if int(dis) - dis == 0:
            cnt += 1
print(cnt)

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

using namespace std;

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

#define fi first
#define se second
#define mp make_pair
#define fastIO ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);

const int N = (int)3e5 + 9;
const int MOD = 998244353;

int f[N];

int powr(int n, int k){
  if(k==0)return 1;
  int m = powr(n,k/2);
  m = (m * 1ll * m) % MOD;
  if(k&1) m = (m * 1ll * n) % MOD;
  return m;
}

int comb(int n, int k){
  int res = f[n];
  res = (res * 1ll * powr((f[k] * 1ll * f[n - k]) % MOD, MOD-2)) % MOD;
  return res;
}

int main(){
  fastIO;
  f[0] = 1;
  for(int i = 1; i < N ; i ++ ){
    f[i] = (f[i - 1] * 1ll * i) % MOD;
  }
  int n;
  cin >> n;
  ll a, b;
  cin >> a >> b;
  ll k;
  cin >> k;
  int ret = 0;
  ll v1, v2;
  for(int i = 0 ; i <= n; i ++ ){
    v1 = i * a;
    if(v1 > k){
      break;
    }
    v2 = k - v1;
    if(v2 % b != 0) continue;
    v1 /= a;
    v2 /= b;
    if(v1 <= n && v2 <= n){
      ret = (ret + (comb(n, v1) * 1ll * comb(n, v2)) % MOD) % MOD;
    }
  }
  cout << ret << "\n";
  return 0;
}

Measured memory_bytes: 1408
#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <fstream>
#include <string>
#include <algorithm>
#include <cstdlib>
#include <vector>
#include <stack>
#include <queue>
#include <complex>
#include <set>
#include <list>
#include <iomanip>
#include <map>
#include <memory.h>
#include <iterator>


using namespace std;
static const double EPS = 1e-9;
typedef long long ll;
typedef unsigned long long ull;
#define FOR(i,n) for(int i=0;i<(int)n;++i)
#define FORNUM(p, x) for (int num = p; num < (int)(x); ++num)
#define FORI(p, x) for (int i = p; i < (int)(x); ++i)
#define FORJ(p, x) for (int j = p; j < (int)(x); ++j)
#define FORK(p, x) for (int k = p; k < (int)(x); ++k)
#define FORL(p, x) for (int l = p; l < (int)(x); ++l)

typedef pair<int,int>P;
#define INF 1000000000
 

 
int V,E;

struct edge {
	int dst;
	int cost;
	edge(int dst, int cost) {
		this->dst = dst; this->cost = cost;
	}

};

typedef vector<edge> edges;
vector<edges> G;

int dist[100005];
int k;

void solve(int v) {

	fill(dist, dist + k, INF);
	dist[v] = 0;
	priority_queue<P, vector<P> > q;

	q.push(make_pair(0,v));
	while (q.size()) {
		P p = q.top(); q.pop();
		int v = p.second;
		if (dist[v] < -p.first)
			continue;
		dist[v] =- p.first;
		FORI(0,G[v].size()) {
			edge e = G[v][i];
			if (dist[e.dst] > dist[v] + e.cost) {
				dist[e.dst] = dist[v] + e.cost;
				q.push(make_pair(-dist[e.dst], e.dst));
			}
		}
	}
	cout << dist[0] + 1 << endl;
}

int main() {
	cin >> k;
	G.resize(k);
	FORI(0, k) {
		G[i].push_back(edge((i + 1)%k, 1));
		G[i].push_back(edge((i*10)%k, 0));
	}
	solve(1);
	return 0;
}


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


int main () {
	string s;

	lli a,z;
	cin >> s;

	a = s.size();
	z = 0;

	for(lli i=0;i<s.size();i++){
		if(s[i]=='A')a=min(a,i);
		if(s[i]=='Z')z=max(z,i);
	}

	cout << z-a+1 << endl;





    return 0;
}

Measured memory_bytes: 640
#include<stdio.h>

int A[20],M[200];
int flag=0,n;

void recursion(int p,int t){
  if(t==0)flag=1;
  if(p<n && t>0){
    p++;
    recursion(p,t); 
    t-=A[p];
    recursion(p,t);
  }
}



main(){
  int i,q;
  scanf("%d",&n);
  for(i=0;i<n;i++){
    scanf("%d",&A[i]);
  }

  scanf("%d",&q);
  for(i=0;i<q;i++){
    scanf("%d",&M[i]);
  }

  for(i=0;i<q;i++){
    recursion(-1,M[i]);
    if(flag==1) printf("yes\n");
    else printf("no\n");
    flag=0;
  } 
  return 0;
}

Measured memory_bytes: 580
#include <iostream>
#include <cmath>
#include <algorithm>

using namespace std;

int main()
{
    int N;
    int64_t M;

    cin >> N >> M;

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

    int64_t dmax = 0;
    for (int64_t i = 1; i <= (int)floor(sqrt(M)); i++)
    {
        if (M % i == 0)
        {
            int64_t cand1 = i;
            int64_t cand2 = M / i;

            if (cand2 >= N)
            {
                dmax = max(dmax, cand1);
            }
            if (cand1 >= N)
            {
                dmax = max(dmax, cand2);
            }
        }
    }

    cout << dmax << endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <algorithm>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#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)
#define INF 999999999
using namespace std;
typedef pair<int, int> P;
typedef pair<llong, llong> LP;
typedef pair<int, P> PP;
typedef pair<llong, LP> LPP;

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

#define int long long

vector<vector<int> > dp(5000, vector<int>(5000, -1));
vector<int> v(6000);
int n;

int dfs(int l, int r){
  if(dp[l][r]!=-1) return dp[l][r];

  int ret;
  if(r-l-1==n) ret=0;
  else if((l-r-1)&1){
    if(v[l]>v[r]){
      ret=dfs(l-1, r);
    }
    else{
      ret=dfs(l, r+1);
    }
  }
  else{
    ret=max(dfs(l-1, r)+v[l], dfs(l, r+1)+v[r]);
  }

  return dp[l][r]=ret;
}

signed main(){
  scanf("%lld", &n);
  REP(i, n){
    int a;
    scanf("%lld", &a);
    v[i]=v[n+i]=v[n*2+i]=a;
  }
  
  int ans=0;
  REP(i, n){
    ans=max(ans, dfs(i+n-1, i+n+1)+v[i]);
  }

  printf("%lld\n", ans);
}

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

#define PII pair<int, int>
#define VI vector<int>
#define VPII vector<PII>
#define LL long long
#define LD long double
#define f first
#define s second
#define MP make_pair
#define PB push_back
#define endl '\n'
#define ALL(c) (c).begin(), (c).end()
#define SIZ(c) (int)(c).size()
#define REP(i, n) for (int i = 0; i < (int)(n); i++)
#define FOR(i, b, e) for (int i = (b); i <= (int)(e); i++)
#define FORD(i, b, e) for (int i = (b); i >= (int)(e); i--)
#define ll long long
#define st f
#define nd s
#define pb PB
#define eb emplace_back
#define mp make_pair				
#define siz(c) SIZ(c)
const int inf = 1e9 + 7;
const LL INF = 1e18L + 7;
 
#define sim template<class n
sim, class s> ostream & operator << (ostream &p, pair<n, s> x)
{return p << "<" << x.f << ", " << x.s << ">";}
sim> auto operator << (ostream &p, n y) ->
typename enable_if<!is_same<n, string>::value, decltype(y.begin(), p)>::type
{int o = 0; p << "{"; for (auto c : y) {if (o++) p << ", "; p << c;} return p << "}";}
void dor() {cerr << endl;}
sim, class...s> void dor(n p, s...y) {cerr << p << " "; dor(y...);}
sim, class s> void mini(n &p, s y) {if (p > y) p = y;}
sim, class s> void maxi(n &p, s y) {if (p < y) p = y;}

#ifdef DEB
#define debug(...) dor(__FUNCTION__, ":", __LINE__, ": ", __VA_ARGS__)
#else
#define debug(...)
#endif

#define I(x) #x " = ", (x), " "
#define A(a, i) #a "[" #i " = ", i, "] = ", a[i], " "

#ifndef LOCAL
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

using namespace __gnu_pbds;

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

#else
#include</Users/dawid/algo/mac/ordered_set>
#endif

int m, d, ans;

int32_t main()
{
	ios_base::sync_with_stdio(0);
	cin.tie(NULL);

	cin >> m >> d;

	for(int i = 1; i <= d; ++i)
	{
		int x = i/10;
		int y = i%10;

		if(x>=2 && y>=2 && x*y<=m)
			++ans;
	}

	cout << ans << endl;
}



Measured memory_bytes: 896
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;i++)
using namespace std;
const int INF=1<<29,MOD=1e9+7;

//0~10000の頂点のroot
int v[10010];
//初期化(n頂点バラバラ)
void init(int n){
	rep(i,n) v[i]=i;
}

//頂点aが属するrootを求める
int root(int a){
	if(v[a]==a) return a; //aはroot
	return (v[a]=root(v[a])); //aの親のroot
}

//頂点aとbが同一グループか?
bool is_same_set(int a,int b){
	return root(a)==root(b);
}

//頂点aとbを同一グループにまとめる
void unite(int a,int b){
	v[root(a)]=root(b);
}

int main(){
	int n,q; cin>>n>>q;
	init(n);
	rep(i,q){
		int com,x,y; cin>>com>>x>>y;
		if(com) cout<<is_same_set(x,y)<<endl;
		else unite(x,y);
	}
	return 0;
}



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

const int64_t MOD = 1000000007;

#define FOR(i, start, end) for(uint64_t i=start; i<end; i++)
#define REP(i, n) FOR(i, 0, n)

// 最大公約数gcd
// 最小公倍数lcm=m*n/gcd
uint64_t gcd(uint64_t m, uint64_t n) {
  uint64_t temp;
  while (m % n != 0){
    temp = n;
    n = m % n;
    m = temp;
  }
  return n;
}

uint64_t lcm(uint64_t m, uint64_t n) {
  return (m*n)/gcd(m,n);
}

// vector<vector<uint64_t> > v(n+1, vector<uint64_t>(n+1, 0))
// v[n][k]に組み合わせ数が入る。
void comb(vector<vector <uint64_t> > &v){
  for(uint64_t i = 0;i <v.size(); i++){
    v[i][0]=1;
    v[i][i]=1;
  }
  for(uint64_t k = 1;k <v.size();k++){
    for(uint64_t j = 1;j<k;j++){
      v[k][j]=(v[k-1][j-1]+v[k-1][j]);
      v[k][j] %= MOD;
    }
  }
}

// 掛け算オーバーフロー判定
bool is_product_overflow(uint64_t a, uint64_t b) {

	uint64_t prod = a * b;
	
	return (prod / b != a);
}

//素因数分解
void primeFactorization(uint64_t a, list<uint64_t> &factors){ //素因数分解を出力するプログラム
  long i,sq;
  if(a%2==0){ //偶数の場合
    factors.push_back(2);
    primeFactorization(a/2,factors); //2で割った値で再帰
    return;
  }
  sq = sqrt(a);
  for(i=3;i<=sq;i+=2){ //3以上√a以下の奇数の場合
	if(a%i==0){
	  factors.push_back(i);
      primeFactorization(a/i,factors); //割れた値で再帰
      return;
	}
  }
  //偶数でも3以上√a以下の奇数の場合でも割り切れない場合
  if(a!=1){ //aが1でないなら、a自身は素数
    factors.push_back(a);
  }
}

// フェルマーの小定理
// mod. m での a の逆元 a^{-1} を計算する
// (a/b)%m = a*movinv(b,m)%m  
int64_t modinv(int64_t a, int64_t m) {
    int64_t b = m, u = 1, v = 0;
    while (b) {
        int64_t t = a / b;
        a -= t * b; swap(a, b);
        u -= t * v; swap(u, v);
    }
    u %= m;
    if (u < 0) u += m;
    return u;
}

// 円周率
// M_PI

// #include <iomanip> // setprecisionを使用するのに必要
// cout << std::fixed << std::setprecision(15) << y << endl;

// 昇順
// priority_queue<int, vector<int>, greater<int> > queue;


signed main() {
  int n, k;
  cin >> n >> k;
  vector<vector<uint64_t> > v(n+1, vector<uint64_t>(n+1, 0));
  comb(v);
  
  for(int i=1;i<=k;i++){
  	cout << (v[n-k+1][i]*v[k-1][i-1])%MOD << endl;
  }
  return 0;
}



Measured memory_bytes: 34732
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using Pair = pair<int, int>;
using Vec = vector<int>;
using Graph = vector<Vec>;

#include <iostream>
using namespace std;

const int MAX = 1000000;
const int MOD = 1000000007;

long long fac[MAX], finv[MAX], inv[MAX];

// テーブルを作る前処理
void COMinit() {
	fac[0] = fac[1] = 1;
	finv[0] = finv[1] = 1;
	inv[1] = 1;
	for (int i = 2; i < MAX; i++){
		fac[i] = fac[i - 1] * i % MOD;
		inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
		finv[i] = finv[i - 1] * inv[i] % MOD;
	}
}

long long COM(int n, int k){
	if (n < k) return 0;
	if (n < 0 || k < 0) return 0;
	return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

int		main(void)
{
	COMinit();
	int x, y;
	cin >> x >> y;
	if ((x + y) % 3)
	{
		cout << 0 << endl;
		return (0);
	}
	int step = (x + y) / 3;
	int right = x - step;
	int down = y - step;
	if (right < 0 || down < 0)
	{
		cout << 0 << endl;
		return (0);
	}
	cout << (((fac[step] * finv[right]) % MOD) * finv[down]) % MOD << endl;
}



Measured memory_bytes: 23680
import bisect

N = int(input())
A = [int(input()) for i in range(N)]

ans = 1
X = [-A[0]]
for i in range(1,N):
    if -X[ans-1] >= A[i]:
        X.append(-A[i])
        ans += 1
    else:
        pos = bisect.bisect_right(X,-A[i])
        X[pos] = -A[i]

print(ans)


Measured memory_bytes: 10968
//kruskal tree
#include <iostream>
#include <algorithm>
using namespace std;
#define M 999
int parent[M],a[M],b[M];
pair<int,int>node[M];
int root(int a){
	return parent[a]==a?a:parent[a]=root(parent[a]);
}
int unite(int a,int b){
	int x=root(a),y=root(b);
	if(x==y)return 0;
	parent[x]=y;
	return 1;
}
int main(){
	int i,s,n,m;
	for(;cin>>n>>m,n;cout<<s<<endl){
		for(i=0;i<m;i++)cin>>a[i]>>b[i]>>node[i].first,node[i].second=i;
		sort(node,node+m);
		for(i=0;i<n;i++)parent[i]=i;
		for(s=i=0;i<m;i++)if(unite(a[node[i].second],b[node[i].second]))s+=node[i].first;
	}
}

Measured memory_bytes: 1180
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>

#define INF 1000000000

using namespace std;

int main() {
    vector<int> prev(26, -1), m(26, 0);
    string s;
    cin >> s;
    for (int i = 0; i < s.size(); ++i) {
        m.at(s.at(i) - 'a') = max(m.at(s.at(i) - 'a'), i - prev.at(s.at(i) - 'a') - 1);
        prev.at(s.at(i) - 'a') = i;
    }
    for (int i = 0; i < 26; ++i) m.at(i) = max(m.at(i), int(s.size() - prev.at(i) - 1));
    cout << *min_element(m.begin(), m.end()) << endl;
    return 0;
}


Measured memory_bytes: 256
import sys
import numpy as np


input = sys.stdin.readline
N,W  = map(int,input().split())
dp = np.zeros((N+1,W+1),dtype=int)
w,v = [],[]
for _ in range(N):
    w_,v_ = map(int,input().split())
    w.append(w_)
    v.append(v_)

for row in range(N):
    dp[row+1,:w[row]] = dp[row,:w[row]]
    dp[row+1,w[row]:] = np.maximum(dp[row,w[row]:],v[row]+dp[row,:-w[row]])
print(dp[N,-1])

Measured memory_bytes: 92060
#include <bits/stdc++.h>
using namespace std;
#define rep(i,a,b) for(auto i = (a); i < (b); i++)
#define iter(it,c) for(auto it = (c).begin(); it != (c).end(); ++it)
typedef long long ll;
typedef vector<ll> vi;
typedef pair<ll,ll> ii;
typedef vector<ii> vii;
const ll INF = ~(1<<31);
#define fs first
#define sc second
#define pb push_back

const double EPS = 1e-9;
const double pi = acos(-1);
typedef unsigned long long ull;
typedef vector<vi> vvi;
typedef vector<vii> vvii;
template <class T> T smod(T a, T b) {
    return (a % b + b) % b;
}

ll n;
ll T[22][22];
ll memo[22][1<<22];
ll md = 1000000000+7;
ll dp(ll at, ll bt) {
    if(at == n) {
        return bt == (1<<n)-1;
    }
    if(memo[at][bt] != -1) return memo[at][bt];
    ll tots = 0;
    rep(i,0,n) {
        if(!(bt & (1<<i)) && T[at][i]) {
            tots += dp(at+1, bt | (1<<i));
            tots %= md;
        }
    }
    return memo[at][bt] = tots;
}

int main() {
    cin.sync_with_stdio(false);
    cin >> n;
    memset(memo,-1,sizeof(memo));
    rep(i,0,n) rep(j,0,n) cin >> T[i][j];
    cout << dp(0,0) << endl;
    return 0;
}



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

#define ll long long
#define all(x) (x).begin(), (x).end()
const long long INF = 1LL << 60;

#define rep(i, n) for (int i = 0; i < (int)(n); i++)  //(i, 10) i=0～i=9まで
#define repr(i, n) for (int i = n; i >= 0; i--)   // (i, 10) i=10～i=0まで
#define FOR(i, m, n) for (int i = m; i < n; i++)  // (i, 3, 10) i=3～i=9まで

int main() {
    // cin.tie(0);
    // ios::sync_with_stdio(false);
    // cout << fixed << setprecision(5);

    // 入力
    int    N, K;
    string str;

    cin >> N >> K;
    cin >> str;

    // 処理
    str[K - 1] = tolower(str[K - 1]);

    // 出力
    cout << str << " ";
    return 0;
}


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

using namespace std;

char swapc(char c) {
	if (c == '#')
		return '.';
	else if (c == '.')
		return '#';
	else
		return ' ';
}

int main() {
	int H, W;
	while (cin >> H >> W && (H || W)) {
		for (int i = 0; i < H; i++) {
			char c;
			if (i % 2 == 0)
				c = '#';
			else
				c = '.';
			for (int j = 0; j < W; j++) {
				cout << c;
				c = swapc(c);
			}
			cout << endl;
		}
		cout << endl;
	}
	return 0;
}

Measured memory_bytes: 3068
#include <stdio.h>
int main (void){
    int a,b,c,tyou=0,hisi=0;
    while(scanf("%d,%d,%d",&a,&b,&c)!=EOF){
        if(a*a+b*b==c*c){
            tyou++;
        }
        else if(a==b){
            hisi++;
        }
    }
    printf("%d\n%d\n",tyou,hisi);
return 0;
}

Measured memory_bytes: 596
#include <cstdio>
#include <vector>
using namespace std;

long long gcd(long long a, long long b)
{
	return b ? gcd(b, a % b) : a;
}

int f(long long x)
{
	int r = 1;
	for (long long i = 2; i * i <= x; i++) if (x % i == 0){
		while (x % i == 0) x /= i;
		r++;
	}
	if (x > 1) r++;
	return r;
}

int main()
{
	long long a, b;
	scanf ("%lld %lld", &a, &b);
	printf ("%d\n", f(gcd(a, b)));
	return 0;
}

Measured memory_bytes: 128
// 見せてやるぜ、奇跡ってやつをよぉ……
#include <iostream>
#include <array>
#include <algorithm>
#include <vector>
#include <set>
#include <unordered_set>
#include <cmath>
#include <complex>
#include <deque>
#include <iterator>
#include <numeric>
#include <map>
#include <unordered_map>
#include <queue>
#include <stack>
#include <string>
#include <tuple>
#include <utility>
#include <limits>
#include <iomanip>
#include <functional>
#include <cassert>
using namespace std;

using ll=long long;
template<class T> using V = vector<T>;
template<class T, class U> using P = pair<T, U>;
using vll = V<ll>;
using vvll = V<vll>;
#define rep(i, k, n) for (ll i=k; i<(ll)n; ++i)
#define REP(i, n) rep(i, 0, n)
#define ALL(v) v.begin(),v.end()
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 DEBUG_VLL(vec) REP(i, vec.size()) cerr<<vec[i]<<(i==vec.size()-1?'\n':' ');

const ll MOD = 1000000007;
const ll HIGHINF = (ll)1e18;

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll n, k; cin >> n >> k;
    vll a(n), f(n);
    REP(i, n) cin >> a[i];
    sort(ALL(a));
    reverse(ALL(a));
    REP(i, n) cin >> f[i];
    sort(ALL(f));

    ll l=0, r=HIGHINF;
    while (l < r) {
        ll mid = (l+r)/2;
        ll tmpk = 0;
        REP(i, n) {
            if (a[i]*f[i] > mid) {
                tmpk += ((a[i]*f[i]-mid)+f[i]-1) / f[i];
                if (tmpk > k) break;
            }
        }
        if (tmpk > k) l = mid+1;
        else r = mid;
    }
    cout << l << '\n';
    return 0;
}


Measured memory_bytes: 3328
#include <bits/stdc++.h>
using namespace std;
#define PI 3.141592653589793
#define MOD 1000000007
#define rep(i, n) for (ll i = 0; i < n; i++)
#define all(v) v.begin(), v.end()

typedef long long ll;
typedef long double ld;


int main(){
    ll N, X, T;
    cin >> N >> X >> T;

    if(N % X != 0){
        cout << ((N / X) + 1) * T << endl;
    }
    else{
        cout << ((N / X)) * T << endl;
    }
}


Measured memory_bytes: 3668
/*
これを入れて実行
g++ code.cpp
./a.out
 */
 
#include <iostream>
#include <stdio.h>
#include <vector>
#include <string>
#include <queue>
#include <deque>
#include <algorithm>
#include <utility>
#include <set>
#include <map>
#include <cmath>
#include <math.h>
#include <tuple>
#include <iomanip>
#include <bitset>
 
using namespace std;
typedef long long ll;
typedef long double ld;
 
int dy4[4] = {-1, 0, +1, 0};
int dx4[4] = {0, +1, 0, -1};
int dy8[8] = {-1, -1, 0, 1, 1, 1, 0, -1};
int dx8[8] = {0, 1, 1, 1, 0, -1, -1, -1};
 
const long long INF = 1LL << 60;
const ll MOD = 1e9 + 7;
 
bool greaterSecond(const pair<int, int>& f, const pair<int, int>& s){
    return f.second > s.second;
}
 
ll gcd(ll a, ll b){
	if (b == 0)return a;
	return gcd(b, a % b);
}
 
ll lcm(ll a, ll b){
    return a / gcd(a, b) * b;
}
 
ll nCr(ll n, ll r){
    if(r == 0 || r == n){
        return 1;
    } else if(r == 1){
        return n;
    }
    return (nCr(n - 1, r) + nCr(n - 1, r - 1));
}
 
ll nPr(ll n, ll r){
    r = n - r;
    ll ret = 1;
    for (ll i = n; i >= r + 1; i--) ret *= i;
    return ret;
}
 
//-----------------------ここから-----------

int main(void){
    int h, w;
    cin >> h >> w;

    vector<string> s(h);
    for(int i = 0; i < h; i++){
        cin >> s[i];
    }

    int ans = 0;

    for(int si = 0; si < h; si++){
        for(int sj = 0; sj < w; sj++){

            pair<int,int> start = make_pair(si, sj);
            
            if(s[start.first][start.second] == '#'){
                continue;
            }

            vector<vector<int>> dist(h, vector<int>(w, 0));

            vector<vector<int>> visited(h, vector<int>(w, 0));

            queue<pair<pair<int,int>, int>> q;

            q.push(make_pair(start, 0));
            while(!q.empty()){
                pair<int,int> now = q.front().first;
                int nowdist = q.front().second;
                q.pop();
                for(int i = 0; i < 4; i++){
                    pair<int,int> next = make_pair(now.first + dy4[i], now.second + dx4[i]);

                    if(next.first < 0 || next.first >= h || next.second < 0 || next.second >= w){
                        continue;
                    }

                    if(s[next.first][next.second] == '#'){
                        continue;
                    }

                    if(visited[next.first][next.second] == 1){
                        continue;
                    }
                    
                    visited[next.first][next.second] = 1;
                    dist[next.first][next.second] = nowdist + 1;
                    q.push(make_pair(next, nowdist + 1));
                }
            }
            for(int gi = 0; gi < h; gi++){
                for(int gj = 0; gj < w; gj++){
                    if(s[gi][gj] == '#'){
                        continue;
                    }
                    if(start == make_pair(gi, gj)){
                        continue;
                    }
                    ans = max(ans, dist[gi][gj]);
                }
            }
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
constexpr long long MOD = 1000000007;
constexpr long long INF = 1LL << 60;
const long double PI = acosl(-1.0);
constexpr long double EPS = 1e-11;
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;
}
int main(){
ll n;
cin>>n;
vector<ll> a(n);
vector<ll> mp(1e6+1);
for (ll i = 0; i < n; i++) cin >> a[i];
sort(a.begin(), a.end());
for (ll i = 0; i < n; i++) mp[a[i]]++;
ll ans = 0;
for (ll i = 0; i < n; i++) {
    bool flag = true;
    mp[a[i]]--;
    for (ll j = 1; j * j <= a[i]; j++) {
        if (a[i]%j==0){
            if (mp[j]) flag = false;
            if (j * j != a[i] && mp[a[i] / j]) flag = false;
        }
    }
    if (flag) ans++;
    mp[a[i]]++;
}
cout << ans << endl;
}

Measured memory_bytes: 12764
#[allow(unused_imports)]
use std::cmp;

// Input macro from https://qiita.com/tanakh/items/0ba42c7ca36cd29d0ac8
macro_rules! input {
  (source = $s:expr, $($r:tt)*) => {
    let mut iter = $s.split_whitespace();
    input_inner!{iter, $($r)*}
  };
  ($($r:tt)*) => {
    #[allow(unused_mut)]
    let mut s = {
      use std::io::Read;
      let mut s = String::new();
      std::io::stdin().read_to_string(&mut s).unwrap();
      s
    };
    let mut iter = s.split_whitespace();
    input_inner!{iter, $($r)*}
  };
}

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

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

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

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

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

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

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

fn main() {
  input! {
    n: usize,
    k: usize,
    query: [(usize, usize, chars); n],
  }
  let m = k * 2;
  let mut field = vec![vec![0i64; k * 3]; k * 2];
  for &(x, y, ref c) in &query {
    let y = match *c.first().unwrap() {
      'B' => y,
      _ => y + k,
    };
    let (x, y) = if (x % m) < k { (x % m, y % m) } else { ((x + k) % m, (y + k) % m) };
    field[y][x] += 1;
    field[(y + k) % m][x + k] += 1;
    field[y][x + m] += 1;
  }
  for i in 1 .. 2 * k {
    for j in 0 .. 3 * k {
      field[i][j] += field[i-1][j];
    }
  }
  for i in 0 .. 2 * k {
    for j in 1 .. 3 * k {
      field[i][j] += field[i][j-1];
    }
  }
  let mut ans = 0;
  for i in 0 .. k {
    for j in 0 .. 2 * k {
      ans = cmp::max(ans, field[i + k][j + k] - field[i][j + k] - field[i + k][j] + field[i][j]);
    }
  }

  println!("{}", ans);
}


Measured memory_bytes: 69876
fn main() {
    let v = read_vec::<u64>();
    let n = v[0];
    let k = v[1];
    let mut ans = 1;
    for i in 0..n {
        if i == 0 {
            ans *= k;
        } else {
            ans *= k - 1;
        }
    }
    println!("{}", ans);
}

#[allow(dead_code)]
fn read<T: std::str::FromStr>() -> T {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim().parse().ok().unwrap()
}
#[allow(dead_code)]
fn read_vec<T: std::str::FromStr>() -> Vec<T> {
    read::<String>()
        .split_whitespace()
        .map(|e| e.parse().ok().unwrap())
        .collect()
}
#[allow(dead_code)]
fn read_vec2<T: std::str::FromStr>(n: u32) -> Vec<Vec<T>> {
    (0..n).map(|_| read_vec()).collect()
}
#[allow(dead_code)]
fn yn(result: bool) {
    if result {
        println!("Yes");
    } else {
        println!("No");
    }
}


Measured memory_bytes: 4352
#include <bits/stdc++.h>
#define ll long long
#define MODV 1000000007
#define INFLL LLONG_MAX // 9223372036854775807
#define EPS 1e-9
#define rep(i, n) for(ll i=0, i##_len=(ll)(n); i<i##_len; i++)
#define repf(i, n) for(ll i=1, i##_len=(ll)(n+1); i<i##_len; i++)
#define all(v) v.begin(), v.end()
#define endl "\n"
#define vi vector<ll>
#define vvi vector<vector<ll>>
#define Yes() cout << "Yes" << endl
#define YES() cout << "YES" << endl
#define No() cout << "No" << endl
#define NO() cout << "NO" << endl
#define Init() std::ios::sync_with_stdio(false); std::cin.tie(0); std::cout<<fixed<<setprecision(15);
template<class T>bool chmax(T &a, const T &b){ if(a<b){ a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b){ if(b<a){ a=b; return 1; } return 0; }
using namespace std;

int main(){
    Init();
    long long n, k; cin >> n >> k;
    vector<long long> a(n);
    for(long long i=0; i<n; i++) cin >> a[i];


    // 0;自分が負け　1;自分が勝ち
    vector<long long> dp(k+1, 0); dp[0] = 0;
    for(long long i=0; i<=k; i++){
        for(long long j=0; j<n; j++){
            // i個の状態からa[j]個取って負けに遷移させれるなら勝ち
            long long tmp = i-a[j];
            if(tmp < 0) break;
            if(dp[tmp] == 0) dp[i] = 1;
        }
    }
    cout << ((dp[k] == 1) ? "First" : "Second") << endl;
}

Measured memory_bytes: 1024
N,M = map(int,input().split()) #n:頂点数　w:辺の数


way = [[] for i in range(N)]
depth = [float("inf") for i in range(N)]
visited = [False for i in range(N)]
que=[0]

for i in range(M):
    x,y = map(int,input().split())
    way[x-1].append(y-1)
    way[y-1].append(x-1)

for i in que:
  for j in way[i]:
    if visited[j]:
      continue
    que.append(j)
    visited[j]=True
    depth[j] = min(i+1,depth[j])
print("Yes")
for i in range(1,N):
  print(depth[i])

Measured memory_bytes: 38412
import math
import sys

x = int(input())
r = math.ceil(x ** 0.2)
# print(r)
def reverse_num(x):
    return r - x
def calc_b(aa):
    bb = aa - x
    bbb = abs(bb) ** 0.2
    if bb < 0:
        b = -1
    else:
        b = 1
    # print(bb,b * int(bbb.real + bbb.imag))
    return b * int(bbb.real + bbb.imag)
def check(a):
    aa = a ** 5
    b = calc_b(aa)
    # print(a,b)
    if aa - b ** 5 == x:
        print(a,b)
        return True
    else:
        return False
for a in range(r // 2 + 1):
    if check(a) or check(reverse_num(a)):
        sys.exit()
a = r + 1
while True:
    if check(a):
        sys.exit()
    a += 1

Measured memory_bytes: 9444
use std::io::Read;
     
fn main() {
	let mut buf = String::new();
 	let stdin = std::io::stdin();
	stdin.lock().read_to_string(&mut buf).unwrap();
	let mut iter = buf.split_whitespace();
	let a = iter.next().unwrap().parse::<String>().unwrap();
 	let c: Vec<char> = a.chars().collect();
 	let mut cnt = 0;
 	if c[0] == '1' { cnt += 1; };
	if c[1] == '1' { cnt += 1; };
	if c[2] == '1' { cnt += 1; };
	println!("{}", cnt);
}

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

using namespace std;

// A, B, S
// B = S - A
// X, X+D, X+2D, X+3D, ... X+(N-1)D
// X+iD = nX+sD ( s = \sigma ^ n)
// (m-n)X + (s-t)D = 0


int main(void) {
    long n, x, d;
    cin >> n >> x >> d;
    if(d==0) {
        if(x==0) {
            cout << 1 << endl;
        } else {
            cout << n+1 << endl;
        }
        return 0;
    }
    if(d < 0) x = -x, d = -d;

    map<long, vector<pair<long,long>>> v;

    for(long c=0; c<=n; c++) {
        long a = c*(c-1)/2;
        long b = c*(n-1 + n-c)/2;

        v[(100*d+((c*x)%d))%d].push_back({c*x/d + a, c*x/d + b + 1});
    }

    long r = 0;
    for(auto &w: v) {
        auto &l = w.second;
        sort(l.begin(), l.end());
        long b = -1e18;
        long a = b;
        for(auto &x: l) {
            a = max(x.first, b);
            b = max(x.second, a);
            r += b - a;
        }
    }
    cout << r << endl;
}


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

#define REP(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define all(x) (x).begin(),(x).end()
using ll = long long;
string char_to_string(char val) {
  return string(1, val);
}
int char_to_int(char val) {
  return val - '0';
}
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;
}
int vector_finder(std::vector<ll> vec, int number) {
  auto itr = std::find(vec.begin(), vec.end(), number);
  size_t index = std::distance( vec.begin(), itr );
  if (index != vec.size()) { // 発見できたとき
    return 1;
  }
  else { // 発見できなかったとき
    return 0;
  }
}

int main() {
  int N, M; cin >> N >> M;
  vector<string> A(N); REP(i, N) cin >> A[i];
  vector<string> B(M); REP(i, M) cin >> B[i];
  string ans = "No";
  REP(i, N - M + 1) {
    REP(j, N - M + 1) {
      bool flag = true;
      REP(k, M) {
        REP(m, M) {
          if(A[i + k][j + m] != B[k][m]) {
            flag = false;
            break;
          }
          if(k == M - 1 && m == M - 1 && flag == true) ans = "Yes";
        }
      }
    }
  }
  cout << ans << endl;
}

Measured memory_bytes: 3596
/*
edit : Le Duy Dat
team : THree Wolves
Task:
Link:
*/
#include <bits/stdc++.h>

#define f0(i,a,b) for(int i= a; i<= b; ++i)
#define f1(i,a,b) for(int i= a; i>= b; --i)
#define DEBUG(x) cerr << #x << " = " << x << endl
#define X first
#define Y second
using namespace std;
const int base=1e9+7;
typedef long long ll;
typedef pair<ll, ll> ii;
typedef pair<ll, ii> iii;
const long long MAX_N = 1000000;
/*

 End of Template

*/

/* Action  */
int dp[101][101][201];
void Solves(){
    ll n;
    cin >> n;
    ll a[n + 1];
    ll sumOdd = 0;
    ll sumEven = 0;
    for(int i = 1; i <= n;i ++){
        cin >> a[i];
        sumEven += a[i]*(i%2 == 0);
        sumOdd += a[i]*(i % 2);
    }

    ll ans[n + 1];
    ans[1] = sumOdd - sumEven;
    //DEBUG(sumOdd);
    for(int i = 2; i <= n;i ++){
        ans[i] = 2*a[i - 1] - ans[i - 1];
    }
    for(int i = 1; i <= n;i ++) cout << ans[i] << " ";
}
int main(){

	Solves();
}


Measured memory_bytes: 2816
//四則演算 #pragma GCC target("avx")
//並列計算 #pragma GCC optimize("O3")
//条件分岐を減らす #pragma GCC optimize("unroll-loops")
//浮動小数点演算 #pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using VI = vector<int>;
using VL = vector<ll>;
using VS = vector<string>;
template<class T> using PQ = priority_queue<T, vector<T>, greater<T>>;
#define FOR(i,a,n) for(int i=(a);i<(n);++i)
#define eFOR(i,a,n) for(int i=(a);i<=(n);++i)
#define rFOR(i,a,n) for(int i=(n)-1;i>=(a);--i)
#define erFOR(i,a,n) for(int i=(n);i>=(a);--i)
#define each(i, a) for(auto &i : a)
#define SORT(i) sort(i.begin(),i.end())
#define rSORT(i) sort(i.rbegin(),i.rend())
#define fSORT(i,a) sort(i.begin(),i.end(),a)
#define all(i) i.begin(),i.end()
#define out(y,x) ((y)<0||h<=(y)||(x)<0||w<=(x))
#define line cout << "-----------------------------\n" 
#define ENDL(i,n) ((i) == (n) - 1 ? "\n" : " ")
constexpr ll INF = 1000000000;
constexpr ll LLINF = 1LL << 60;
constexpr ll mod = 1000000007;
constexpr ll MOD = 998244353;
constexpr ld eps = 1e-10;
constexpr ld pi = 3.1415926535897932;
template<class T>inline bool chmax(T& a, const T& b) { if (a < b) { a = b; return true; }return false; }
template<class T>inline bool chmin(T& a, const T& b) { if (a > b) { a = b; return true; }return false; }
inline void init() { cin.tie(nullptr); cout.tie(nullptr); ios::sync_with_stdio(false); cout << fixed << setprecision(15); }
template<class T>inline istream& operator>>(istream& is, vector<T>& v) { for (auto& a : v)is >> a; return is; }
template<class T>inline istream& operator>>(istream& is, deque<T>& v) { for (auto& a : v)is >> a; return is; }
template<class T, class U>inline istream& operator>>(istream& is, pair<T, U>& p) { is >> p.first >> p.second; return is; }
template<class T>inline vector<T> vec(size_t a) { return vector<T>(a); }
template<class T>inline vector<T> defvec(T def, size_t a) { return vector<T>(a, def); }
template<class T, class... Ts>inline auto vec(size_t a, Ts... ts) { return vector<decltype(vec<T>(ts...))>(a, vec<T>(ts...)); }
template<class T, class... Ts>inline auto defvec(T def, size_t a, Ts... ts) { return vector<decltype(defvec<T>(def, ts...))>(a, defvec<T>(def, ts...)); }
inline void print() { cout << "\n"; }
template<class T, class... Ts>inline void print(const T& a, const Ts&... ts) { cout << a << " "; print(ts...); }
template<class T>inline void print(const vector<T>& v) { for (int i = 0; i < v.size(); ++i)cout << v[i] << (i == v.size() - 1 ? "\n" : " "); }
template<class T>inline void print(const vector<vector<T>>& v) { for (auto& a : v)print(a); }
inline string reversed(const string& s) { string t = s; reverse(all(t)); return t; }

void solve(int x, int y) {
    if (x < y)swap(x, y);
    int cnt = 0;
    while (y != 0) {
        x %= y;
        swap(x, y);
        ++cnt;
    }
    cout << x << " " << cnt << "\n";
}

int main() {
    init();

    for (int x, y; cin >> x >> y && x != 0;)solve(x, y);

    return 0;
}


Measured memory_bytes: 3156
#include<bits/stdc++.h>
using namespace std;
typedef pair<int,int> pii;
#define F first
#define S second
int r,c,n;
pii w[112345];
int read()
{
    int x,y;
    cin >> x >> y;
    if (!x)
        return y;
    if (y == c-1)
        return c+x;
    if (x == r-1)
        return c+r+c-1-y;
    if (y == 0)
        return c+r+c+r-x-1;
    return -1;
}
int main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
    cin >> r >> c >> n;
    ++r,++c;
    vector<pii> v;
    for (int i = 0; i < n; ++i) {
        int a=read(),b=read();
        if (a > b)
            swap(a,b);
        w[i] = {a,b};
        if (a >= 0 && b >= 0) {
            v.push_back({a,i});
            v.push_back({b,i});
        }
    }
    sort(begin(v),end(v));
    vector<pii> s;
    for (auto p : v) {
        if (p.F == w[p.S].F) 
            s.push_back(p);
        else {
            if (s.back() != pii{w[p.S].F,p.S}) {
                cout << "NO\n";
                return 0;
            }
            s.pop_back();
        }
    }
    cout << "YES\n";
}


Measured memory_bytes: 3568
#include <iostream>
#include <string>

using namespace std;

const int MOD = 1000000007;
int countAll[10001][100];

int main() {
	string k;
	int D;
	cin >> k >> D;
	countAll[0][0] = 1;
	for (int n = 0; n + 1 < k.size(); n++) {
		for (int r = 0; r < D; r++) {
			for (int x = 0; x < 10; x++)
			{
				countAll[n + 1][(r + x) % D] += countAll[n][r];
				countAll[n + 1][(r + x) % D] %= MOD;
			}
		}
	}
	int answer = MOD - 1;
	int r = 0;
	for (int defined = 1; defined <= k.size(); defined++) {
		for (int x = 0; x < (k[defined - 1] - '0'); x++) {
			answer += countAll[k.size() - defined][r];
			answer %= MOD;
			// r = (r - 1 + D) % D;
			if (r == 0) {
				r = D - 1;
			}
			else {
				r--;
			}
		}
	}
	// consider k (count k if its sum of digits is a multiple of D)
	answer += countAll[0][r];
	answer %= MOD;
	cout << answer << '\n';
	return 0;
}


Measured memory_bytes: 4224
#include<stdio.h>

int M[50][50];

void visit(int i, int j, int x, int y){
  
  M[i][j] = 0; 
  
  
  if(M[i][j+1] == 1 && j+1<x){ 
    visit(i,j+1,x ,y);
    // M[i][j+1]=0;
  }
  if(M[i+1][j+1] == 1&& j+1<x && i+1<y){
    visit(i+1,j+1,x,y);
    // M[i+1][j+1]=0;
  }
  if(M[i+1][j] == 1 && i+1<y){
    visit(i+1,j, x, y);
    // M[i+1][j]=0;
  }
  if(M[i+1][j-1] == 1&& i+1<y && j-1>=0){
    visit(i+1,j-1,x, y);
    // M[i+1][j-1]=0;
  }
  if(M[i][j-1] == 1 && j-1>=0){
    visit(i,j-1, x,y);
    // M[i][j-1]=0;
  }
  if(M[i-1][j-1] == 1 && i-1>=0 && j-1>=0){
    visit(i-1,j-1, x, y);
    // M[i-1][j-1]=0;
  }
  if(M[i-1][j] == 1 && i-1>=0){
    visit(i-1,j, x, y);
    // M[i-1][j]=0;
  }
  if(M[i-1][j+1] == 1 && i-1>=0 && j+1<x){
    visit(i-1,j+1, x, y);
    //M[i-1][j-1]=0;
  }
  

}





int main(void){

  int x, y, a, b, is;

  while(1){
    
    is = 0;
    
    scanf("%d %d", &x, &y);
   
    if(x==0 && y==0)break;


    for(a=0; a<y; a++){
      for(b=0; b<x; b++){
	
	scanf("%d", &M[a][b]);
	
      }     
    }
    

    for(a=0; a<y; a++){
      for(b=0; b<x; b++){
	
	if(M[a][b]==1){
	  is++;
	  visit(a,b,x,y);
	}
      }
    }
    
    printf("%d\n", is);
    
  }
  
  
  
  
  
  return 0;
}

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

int main() {
  ll x, k, d;
  cin >> x >> k >> d;
  x = abs(x);

  ll ans;
  ll num = x / d;
  if (num > k) {
    ans = x - k * d;
  } else {
    k -= num;
    x -= num * d;
    if (k % 2 == 0) ans = x;
    else ans = abs(x - d);
  }

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

Measured memory_bytes: 3596
#include <bits/stdc++.h>
using namespace std;
 
int main(){
  
  int R;
  cin >> R;
  
  if(R<1200) cout << "ABC" << endl;
  else if(R<2800) cout << "ARC" << endl;
  else cout << "AGC" << endl;
    
  
  
  
  
}

Measured memory_bytes: 256
#include<cstdio>
#include<iostream>
#include<cstring>
using namespace std;
const long long Maxn=60,Maxm=1000000+10;
long long f[Maxn],n,m,ans;
bool vis[Maxm];
inline long long read()
{
	long long s=0,w=1;
	char ch=getchar();
	while(ch<'0'||ch>'9'){if(ch=='-')w=-1;ch=getchar();}
	while(ch>='0' && ch<='9')s=(s<<3)+(s<<1)+(ch^48),ch=getchar();
	return s*w;
}
long long dp(long long cnt)
{
	memset(f,0,sizeof(f));
	for(long long i=1;i<=cnt;++i)
	for(long long j=cnt;j>=i;--j)
	f[j]=max(f[j],f[j-i]+1);
	return f[cnt];
}
bool check(long long x)
{
	if(x==1)return 0;
	for(long long i=2;i*i<=x;++i)
	if(x%i==0)return 0;
	return 1;
}
int main()
{
//	freopen("in.txt","r",stdin);
	n=read();
	for(long long i=2;i*i<=n;++i)
	{
		if(vis[i])continue;
		for(long long j=(i<<1);j*j<=n;j+=i)
		vis[j]=1;
	}
	vis[1]=1,dp(55),m=n;
	while(n!=1)
	{
		for(long long i=2;i*i<=n;++i)
		{
			if(n%i || vis[i])continue;
			long long cnt=0;
			while(m%i==0 && m)++cnt,m/=i;
			long long tmp=f[cnt];
			ans+=tmp;
		}
		if(n==m)break;
		n=m;
	}
	if(check(n))++ans;
	printf("%lld\n",ans);
	return 0;
}

Measured memory_bytes: 4724
#include <iostream>
#include <vector>
#include <queue>
#include <algorithm>

using namespace std;
using Graph = vector<vector<int>>;

int	main()
{
	int	N, M, K;
	cin >> N >> M >> K;
	Graph	friends(N), blocks(N);
	int	a, b;
	for (int i = 0; i < M; ++i) {
		cin >> a >> b;
		friends[a-1].push_back(b-1);
		friends[b-1].push_back(a-1);
	}
	for (int i = 0; i < K; ++i) {
		cin >> a >> b;
		blocks[a-1].push_back(b-1);
		blocks[b-1].push_back(a-1);
	}
	queue<int> que;
	vector<int>	group_size_vec(N, 0);
	vector<int> group_id_vec(N, -1);
	vector<int> members;
	int	group_id = 0;
	int	group_size = 0;
	for (int i = 0; i < N; ++i) {
		if (group_id_vec[i] >= 0)
			continue;
		group_id_vec[i] = group_id;
		members.assign(1, i);
		que.push(i);
		group_size = 0;
		while (!que.empty()) {
			int v = que.front();
			que.pop();
			for (int u : friends[v]) {
				if (group_id_vec[u] >= 0)
					continue;
				members.push_back(u);
				group_id_vec[u] = group_id;
				que.push(u);
				++group_size;
			}	
		}
		for (int j : members) {
			group_size_vec[j] = group_size;
			for (int u : blocks[j]) {
				if (group_id_vec[j] == group_id_vec[u])
					--group_size_vec[j];
			}
		}
		++group_id;
	}
	for (int i = 0; i < N; ++i) {
		group_size = group_size_vec[i] - friends[i].size();
		if (i != 0)
		   cout << " ";	
		cout << group_size;
	}
	cout << endl;
	return (0);
}	


Measured memory_bytes: 13560
#include <iostream>
#include <algorithm>
#include <vector>
#define int long long
using namespace std;

signed main(){
	ios::sync_with_stdio(0);
	cin.tie(0);
	
	int n,a,b;
	cin>>n>>a>>b;
	int ans=max(a-1,b-1);
	ans=min(ans,max(n-a,n-b));
	if((a-b)%2==0)
		ans=min(ans,abs(a-b)/2);
	ans=min(ans,min((a+b-1)/2,(n-b+n-a+1)/2));
	cout<<ans<<'\n';
	
	return 0;
}

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

using namespace std;

int n;
long long k;
string s;
long long f[105];
char ch[105];

int main() 
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    cin >> s;
    cin >> k;
    n = s.size();
    if (n == 1)
    {
        cout << k / 2;
        return 0;
    }
    bool check = true;
    for (int i = 1; i < n; i++)
    {
        if (s[i] != s[i - 1])
        {
            check = false;
        }
    }
    if(check)
    {
        cout << (k * n) / 2;
        return 0;
    }
    f[0] = 0;
    ch[0] = s[0];
    for (int i = 1; i < n; i++)
    {
        if (s[i] == ch[i - 1])
        {
            f[i] = f[i - 1] + 1;
            ch[i] = ' ';
        }
        else
        {
            ch[i] = s[i];
            f[i] = f[i - 1];
        }
    }
    long long res = k * f[n - 1];
    if (ch[0] == ch[n - 1])
        res = res + k - 1;
    f[0] = 1;
    ch[0] = ' ';
    for (int i = 1; i < n; i++)
    {
        if (s[i] == ch[i - 1])
        {
            f[i] = f[i - 1] + 1;
            ch[i] = ' ';
        }
        else
        {
            ch[i] = s[i];
            f[i] = f[i - 1];
        }
    }
    long long res2 = k * f[n - 1];
    if (ch[0] == ch[n - 1])
        res2 = res2 + k - 1;
    cout << min(res, res2);
    return 0;
}

Measured memory_bytes: 256
#include<iostream>
using namespace std;
int main(){
	int l,a,b,c,d,h1,h2;
	cin >> l;
	cin >> a;
	cin >> b;
	cin >> c;
	cin >> d;
	if(a%c==0)h1=a/c;
	else h1=a/c+1;
	if(b%d==0)h2=b/d;
	else h2=b/d+1;
	if(h1>h2)cout << l-h1 << endl;
	else if(h1<h2)cout << l-h2 << endl;
	else cout << l-h2 << endl;
	return 0;
}

Measured memory_bytes: 1160
#include <iostream>
#include <vector>
#include<string>
#include <set>
#include <map>
#include <algorithm>
#include <math.h>
using namespace std;
int main()
{
	int K;
	std::string S;
	cin >> K >> S;
	
	if(S.size()>K){
		S = S.substr(0, K) + "...";
	}
	std::cout << S << endl; 
	return 0;
}


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

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



    cin.tie(0);
    ios::sync_with_stdio(false);

    /////////////////////
    // Write code below /
    /////////////////////
    int A,B,sum=0;

    cin>>A>>B;

    rep(i,2){
        if(A>B){
            sum+=A;
            A-=1;
        }
        else{
            sum+=B;
            B-=1;
        }
    }
    cout<<sum<<endl;


    return 0;
}


Measured memory_bytes: 256
n, m = map(int,input().split())
h = list(map(int,input().split()))
li = [1]*n

for i in range(m):
    a, b = map(int,input().split())
    if li[a-1] == 1 and h[a-1] <= h[b-1]:
        li[a-1] = 0
    if li[b-1] == 1 and h[b-1] <= h[a-1]:
        li[b-1] = 0

print(sum(li))

Measured memory_bytes: 20064
n = int(input())

def defs(n):
    l0 = 2
    l1 = 1
    ans = 1
    if n == 1:
        return ans
    else:
        for i in range(2, n + 1):
            ans = l0 + l1
            l0 = l1
            l1 = ans
        return ans

print(defs(n))


Measured memory_bytes: 2940
#include <bits/stdc++.h>
using namespace std;
#pragma GCC optimize("Ofast")

#define rep(i,n) for(int i = 0;i<n;i++)
const long long MOD = 1000000007;

int main(){
  int n; cin >> n;
  int a[n];
  for(int i = 0; i<n;i++) cin >> a[i];
  int ans = 0;
  for(int i = 1; i<n;i++){
    int j = i;
    while(j < n && j >= 1){
      if(a[j] < a[j-1]){
        swap(a[j], a[j-1]);
        ans++;
      }
      j--;
    }
  }
  rep(i, n-1) cout << a[i] << " ";
  cout << a[n-1] << "\n";
  cout << ans << "\n";
}


Measured memory_bytes: 3120
def examA():
    R = I()
    if R<1200:
        ans = "ABC"
    elif R<2800:
        ans = "ARC"
    else:
        ans = "AGC"
    print(ans)
    return

def examB():
    S = SI(); N = len(S)
    ans = "AC"
    if not S[0]=="A":
        ans = "WA"
    flag = False
    for i in range(2,N-1):
        if S[i]=="C":
            flag = True
    if not flag:
        ans = "WA"
    num = 0
    for i in S:
        if ord("A")<=ord(i)<=ord('Z'):
            num +=1
    if not num==2:
        ans = "WA"
    print(ans)
    return

def examC():
    return

def examD():
    return

def examE():
    return

def examF():
    return

import sys,copy,bisect,itertools,heapq,math
from heapq import heappop,heappush,heapify
from collections import Counter,defaultdict,deque
def I(): return int(sys.stdin.readline())
def LI(): return list(map(int,sys.stdin.readline().split()))
def LSI(): return list(map(str,sys.stdin.readline().split()))
def LS(): return sys.stdin.readline().split()
def SI(): return sys.stdin.readline().strip()
global mod,mod2,inf,alphabet
mod = 10**9 + 7
mod2 = 998244353
inf = 10**18
alphabet = [chr(ord('a') + i) for i in range(26)]

if __name__ == '__main__':
    examB()


Measured memory_bytes: 3700
#include <bits/stdc++.h>
#define ss second
#define ff first
#define all(x) x.begin(), x.end()
 
using namespace std;
using ll = long long;
using pii = pair<int, int>;
 
const int oo = 1e9 + 7;
const int mod = 1e9 + 7, maxn = 100000;
const long double PI = acos(-1);

int main (){
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    double l;
    cin >> l;
    l/=3.0;

    cout << fixed << setprecision(10) << l*l*l << endl;
    return 0;
}

Measured memory_bytes: 3684
# -*- coding: utf-8 -*-
"""
http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=ITP1_8_C&lang=jp

"""
import sys
from sys import stdin
from collections import defaultdict
input = stdin.readline


def main(args):
    word = defaultdict(int)
    for line in sys.stdin:
        line = line.strip()
        for c in line:
            if c.isalpha():
                c = c.lower()
                word[c] += 1

    for c in 'abcdefghijklmnopqrstuvwxyz':
        print('{} : {}'.format(c, word[c]))


if __name__ == '__main__':
    main(sys.argv[1:])
    

Measured memory_bytes: 7760