akhauriyash/Code-Regression huggingface dataset:
#include<stdio.h>
#include<stdlib.h>
int main(void) {
	int n,k;
	int h[100000];
	int dp[10000];
	scanf("%d %d", &n,&k);
	for (int i = 0; i < n; i++) {
		scanf("%d", &h[i]);
	}

	int sum = 0;
	int min=0;
	int cnt = 0;
	int hako;
	//printf("%d\n", min);
	dp[0] = 0;
	dp[1] = abs(h[0] - h[1]);
	for (int i = 2; i < n; i++) {
		min = 999999999;
		cnt = 0;
		for (int j = i - 1; cnt < k && j >= 0; j--) {
			hako = dp[j] + abs(h[i] - h[j]);
			cnt++;
			if (min > hako) {
				min = hako;
				//printf("%d\n", min);
			}
		}
		dp[i] = min;
		//printf("%d\n", dp[min - 1]);
		/*
		if (dp[i - 2] + abs(h[i] - h[i - 2]) > dp[i - 1] + abs(h[i] - h[i - 1])) {
			dp[i] = dp[i - 1] + abs(h[i] - h[i - 1]);
		}else{
		    dp[i] =dp[i - 2] + abs(h[i] - h[i - 2]);
	    }
		*/
	}
	printf("%d\n",dp[n-1]);
	return 0;
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
#define rep(i, n) for(int i = 0; i < n; i++)
#define repr(i, n) for(int i = n; i >= 0; i--)
#define INF 2e9
#define ALL(v) v.begin(), v.end()
using namespace std;
typedef long long ll;
int main()
{
  int n;
  cin >> n;
  vector<pair<int, int>> vec(n);
  rep(i, n) {
    int x, y;
    cin >> x >> y;
    vec[i] = make_pair(x,y);
  }
  int p = 1;
  int nn = n;
  while(nn > 1) {
    p *= nn;
    nn--;
  }
  double sm = 0;
  int usd = (n - 1)*p;
  int es = n * (n-1) / 2;
  int freq = usd / es;
  double sum = 0;
  rep(i, n) {
    for(int j = i+1; j < n; j++) {
      int x = vec[i].first - vec[j].first;
      int y = vec[i].second - vec[j].second;
      sum += sqrt(x*x+y*y)*freq;
    }
  }  
  printf("%.8f", sum/p);
  
  return 0;
}

Measured memory_bytes: 3812
from collections import deque
from sys import exit
N = int(input())
H = deque(map(int, input().split()))
tmp = H.pop()
while H:
  nxt = H.pop()
  if nxt >= tmp + 2:
    print("No")
    exit()
  elif nxt == tmp + 1:
    nxt -= 1
  tmp = nxt
print("Yes")

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

int main() {
  string S, T;
  cin >> S >> T;
  int len = S.size();
  bool check = true;
  for (int i=0; i<len; i++)
    if (S[i] != T[i])
      check = false;
  if (check)
    cout << "Yes\n";
  else
    cout << "No\n";
  return 0;
}


Measured memory_bytes: 3628
N,A,B,C,*L=map(int,open(0).read().split())
ans=float("inf")
for i in range(2**(N*2)):
	a=b=c=0
	mp=0
	for j,x in enumerate(L):
		f=(i>>2*j)&3
		if f==0:
			if a:mp+=10
			a+=x
		elif f==1:
			if b:mp+=10
			b+=x
		elif f==2:
			if c:mp+=10
			c+=x
	if any([a==0,b==0,c==0]):
		continue
	mp+=abs(A-a)+abs(B-b)+abs(C-c)
	if ans>mp:
		ans=mp
	if ans==0:
		break
print(ans)

Measured memory_bytes: 3188
package main

import (
	"fmt"
	"strconv"
)

func main() {
	var n string
	fmt.Scanf(`%s`, &n)
	for len(n) != 1 {
		n = rec(n)
	}
	if n == `0` || n == `9` {
		fmt.Println(`Yes`)
	} else {
		fmt.Println(`No`)
	}
}

func rec(n string) string {
	var sum uint64
	for i := 0; i < len(n); i++ {
		sum += uint64(n[i] - '0')
	}
	return strconv.FormatUint(sum, 10)
}

Measured memory_bytes: 3280
#include<iostream>
#include<cstdio>
#include<cstring>
#include<map>
#include<algorithm>
using namespace std;
map<string,int>vis;
int n;
string s[222];
char last;
int main()
{
	scanf("%d",&n);
	for(int i=1;i<=n;i++)
	{
		cin>>s[i];
		if(i!=1)
			if(last!=s[i][0])
			{
				printf("No");
				return 0;
			}
		if(vis[s[i]])
		{
			printf("No");
			return 0;
		}
		vis[s[i]]=1;
		last=s[i][s[i].size()-1];
	}
	printf("Yes");
	return 0;
}

Measured memory_bytes: 256
import java.util.*;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);

        long n = sc.nextLong();

        long ans = n - 1;

        for (int i = 0; i < Math.sqrt(n); i++) {
            if (n % (i + 1) == 0) {
                if (ans > (n / (i + 1)) + i - 1) {
                    ans = (n / (i + 1)) + i - 1;
                }
            }
        }

        System.out.println(ans);

        sc.close();

    }

}

Measured memory_bytes: 35784
#include <algorithm>
#include <cmath>
#include <cstdint>
#include <cstdio>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
using namespace std;
#define rep(i, n) for(int(i) = 0; (i) < (n); (i)++)
#define FOR(i, m, n) for(int(i) = (m); (i) < (n); (i)++)
#define All(v) (v).begin(), (v).end()
#define pb push_back
#define MP(a, b) make_pair((a), (b))
using ll = long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
const int INF = 1 << 30;
const ll LINF = 1LL << 60;
const int MOD = 1e9 + 7;

int main() {
    int X;
    cin >> X;
    int res = 0;
    if(X <= 599) {
        res = 8;
    } else if(X <= 799) {
        res = 7;

    } else if(X <= 999) {
        res = 6;

    } else if(X <= 1199) {
        res = 5;

    } else if(X <= 1399) {
        res = 4;

    } else if(X <= 1599) {
        res = 3;

    } else if(X <= 1799) {
        res = 2;

    } else if(X <= 1999) {
        res = 1;
    }
    cout << res << endl;
    return 0;
}

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

int main()
{

#ifdef _d
    freopen("input.txt", "r", stdin);
    // freopen("output.txt", "w", stdout);
#endif

    int n, d;
    cin >> n >> d;
    int ans = 0;
    for (int i = 1; i <= n; ++i) {
        double x, y;
        cin >> x >> y;
        if (sqrt(x*x+y*y) <= d) {
            ++ans;
        }
    }
    cout << ans << "\n";

#ifdef _d
    cerr << "Time: " << 1000.0 * clock() / CLOCKS_PER_SEC << " ms\n";
#endif

    return 0;
}


Measured memory_bytes: 3844
using System.Collections.Generic;
using System.IO;
using System.Linq;
using static System.Console;
class Z { static void Main() => new K(); }
class K
{
	int[] G => ReadLine().Split().Select(int.Parse).ToArray();
	public K()
	{
		SetOut(new StreamWriter(OpenStandardOutput()) { AutoFlush = false });
		Solve();
		Out.Flush();
	}
	int V, Mod;
	List<int>[] es;
	int[] par;
	long[] dp0, dp1;
	void Solve()
	{
		var I = G;
		V = I[0];
		Mod = I[1];
		es = new List<int>[V];
		par = new int[V];
		dp0 = new long[V];
		dp1 = new long[V];
		for (var u = 0; u < V; u++) es[u] = new List<int>();
		for (var e = 0; e < V - 1; e++)
		{
			I = G;
			es[I[0] - 1].Add(I[1] - 1);
			es[I[1] - 1].Add(I[0] - 1);
		}
		DFS1Exe(0, -1);
		DFS2(0);
		DFS3(0);
		for (var u = 0; u < V; u++) WriteLine(dp0[u] * (dp1[u] + 1) % Mod);
	}
	void DFS1Exe(int u, int p)
	{
		var st = new Stack<object>();
		st.Push(new A0 { u = u, p = p });
		while (st.Count > 0)
		{
			var f = st.Pop();
			if (f is A0)
			{
				var g = (A0)f;
				par[g.u] = g.p;
				es[g.u].Remove(g.p);
				st.Push(new A1 { u = g.u, p = g.p, i = 0 });
			}
			else if (f is A1)
			{
				var g = (A1)f;
				if (g.i < es[g.u].Count)
				{
					st.Push(new A2 { u = g.u, p = g.p, i = g.i });
					st.Push(new A0 { u = es[g.u][g.i], p = g.u });
				}
			}
			else if (f is A2)
			{
				var g = (A2)f;
				st.Push(new A1 { u = g.u, p = g.p, i = g.i + 1 });
			}
		}
	}
	void DFS1(int u, int p)
	{
	a0:
		par[u] = p;
		es[u].Remove(p);
		var i = 0;
	a1:
		if (i < es[u].Count)
		{
			DFS1(es[u][i], u);
		a2:
			i++;
			goto a1;
		}
	}
	void DFS2(int u)
	{
	b0:
		dp0[u] = 1L;
		var i = 0;
	b1:
		if (i < es[u].Count)
		{
			DFS2(es[u][i]);
		b2:
			dp0[u] = dp0[u] * (dp0[es[u][i]] + 1) % Mod;
			i++;
			goto b1;
		}
	}
	void DFS3(int u)
	{
	c0:
		{
			var W = es[u].Count;
			var x = new long[W + 1];
			var y = new long[W + 1];
			x[0] = y[W] = 1;
			for (var i = 0; i < W; i++) x[i + 1] = x[i] * (dp0[es[u][i]] + 1) % Mod;
			for (var i = W - 1; i >= 0; i--) y[i] = y[i + 1] * (dp0[es[u][i]] + 1) % Mod;
			for (var i = 0; i < W; i++) dp1[es[u][i]] = (dp1[u] + 1) * x[i] % Mod * y[i + 1] % Mod;
			x = y = null;
		}
		var j = 0;
	c1:
		if (j < es[u].Count)
		{
			DFS3(es[u][j]);
		c2:
			j++;
			goto c1;
		}
	}
}
struct A0 { public int u, p; }
struct A1 { public int u, p, i; }
struct A2 { public int u, p, i; }
struct B0 { public int u; }
struct B1 { public int u, i; }
struct B2 { public int u, i; }
struct C0 { public int u; }
struct C1 { public int u, j; }
struct C2 { public int u, j; }

Measured memory_bytes: 41836
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i = 0; i < (int) n; i++)
using ll = long long;
template <class T>
using vt = vector<T>;
using vvi = vector<vt<int>>;

int main(){
  int n;  cin >> n;
  vt<int> a(n);
  rep(i,n){
    cin >> a[i];
  }

  int num = n - 1;
  bool f = false;
  rep(i,n){
    cout << a[num] << ' ';
    num += f ? 2 : -2;
    if(num == -2){
      f = true;
      num += 3;
    }
    else if(num == -1){
      f = true;
      ++num;
    }

  }

  cout << endl;
  return 0;
}


Measured memory_bytes: 2944
#include<iostream>
#include<algorithm>
#include<vector>
#include<queue>
#include<set>

using namespace std;

typedef long long in;

int main(){
int a,b;
cin >> a >> b;
int sum = a+b;
if(sum<=9)
    cout << sum << endl;
else
    cout << "error" << endl;
return 0;
}


Measured memory_bytes: 256
N = input()
A = list(map(int, input().split()))
count = 0
while True:
    exist_odd = False
    for a in A:
        if (a % 2) != 0:
            exist_odd = True
    if exist_odd:
        break
    for i in range(len(A)):
        A[i] /= 2
    count += 1
print(count)


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

int main() {
	string N;
	cin >> N;
	
	int mod = 0;
	REP(i, N.size()) mod += N[i] - '0';
	puts([&] {
		return mod % 9 == 0;
	}() ? "Yes": "No");
	return 0;
}


Measured memory_bytes: 3688
/*input
axyb
abyxb
*/
#include <bits/stdc++.h>
using namespace std;

#define pb push_back
#define f first
#define s second
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define int long long
int const mod = 1e9+7;
int power(int x, int y, int mod = 2e18){ int ans = 1;x %= mod;while(y){if(y&1)ans = (x * ans) % mod;x = (x * x) % mod;y >>= 1;}return ans;}
int gcd(int a , int b){if(a==0)return b;return gcd(b%a,a);}
string s,t;
string fi;
int dp[3001][3001];
signed main() {
  IOS;
  cin>>s>>t;
  dp[0][0]=0;
  string mx="" ; 
  for(int i=1;i<=s.size();i++){
    for(int j=1;j<=t.size();j++){
      if(s[i-1]==t[j-1]){
        dp[i][j] = dp[i-1][j-1] + 1 ;
      }
      else{
        dp[i][j] = max(dp[i-1][j],dp[i][j-1]);
      }
    }
  }
  int i = s.size();
  int j = t.size();
  while(i>0 && j>0){
    if(s[i-1]==t[j-1])
    {
      mx+=s[i-1];
      i--;j--;
      continue;
    }
    if(dp[i-1][j]>dp[i][j-1]){
      i--;
    }else j--;
  }
  reverse(mx.begin(), mx.end());
  cout << mx << endl;
return 0;
}

Measured memory_bytes: 70656
#include<bits/stdc++.h>
#define rep(i,a,b) for(int i=a;i<=b;i++)
#define ll long long
using namespace std;
const int maxn=200000+66;
struct monster
{
    ll x,h;
}mon[maxn];
bool cmp(monster a,monster b)
{
    return a.x<b.x;
}
ll c[maxn];
int main()
{
    ll n,d,a;
    cin>>n>>d>>a;
    rep(i,1,n)
    {
        cin>>mon[i].x>>mon[i].h;
    }
    sort(mon+1,mon+n+1,cmp);
    ll ans=0;
    //尺取法
    for(int i=1,j=1;i<=n;i++)
    {
        while(j<=n&&mon[j].x<=mon[i].x+2*d)
            j++;//找到不能炸到的
        ll need=max((mon[i].h-c[i]*a+a-1)/a,0ll);
        c[i]+=need;
        c[j]-=need;
        c[i+1]+=c[i];
        ans+=need;
    }
    cout<<ans<<endl;
}


Measured memory_bytes: 4992
#define _CRT_SECURE_NO_WARNINGS
#include <iostream>	
#include <time.h>
#include <vector>
#include <stdio.h>
#include <memory.h>
#include <string>
#include <string.h>
#include <map>
#include <algorithm>
#include <queue>
#include <set>
#include <time.h>
#include <assert.h>
#include <sstream>
//#include <unordered_map>
#include <bitset>
#include <utility>
#include <iomanip>
#include <climits>
#include <cstdio>
#include <cstdlib>
#include <ctime>
#include <numeric>
#include <math.h>
#include <cmath>
#include <complex>
using namespace std;
typedef long long ll;
typedef complex<double> point;

int n, a[100010];
int ask(int x) {
	printf("%d\n", x);
	fflush(stdout);
	char s[10];
	scanf("%s", s);
	if(strcmp(s, "Male") == 0)
		return 0;
	if(strcmp(s, "Female") == 0)
		return 1;
	exit(0);
}

int main() {

	scanf("%d", &n);
	a[0] = ask(0);
	for(int i = 1; i < n; ++i)
		a[i] = 1 ^ a[i - 1];
	int l = 1, r =  n - 2;
	while(l <= r) {
		int mid = (l + r) >> 1;
		int res = ask(mid);
		if(res != a[mid])
			r = mid - 1;
		else
			l = mid + 1;
	}
	ask(n - 1);

	return 0;
}

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

using namespace std;

const int mod = 1e9 + 7;

int a[100010];
int dp[110][100010];

int main()
{
    int n, k;
    cin >> n >> k;
    dp[0][0] = 1;
    for(int i = 1; i <= n; i++){
        cin >> a[i];
    }
    for(int i = 1; i <= n; i++){
        int pre[k + 1];
        pre[0] = dp[i - 1][0];
        for(int j = 1; j <= k; j++){
            pre[j] = pre[j - 1] + dp[i - 1][j];
            pre[j] %= mod;
        }
        for(int j = 0; j <= k; j++){
            dp[i][j] = pre[j];
            int tmp = j - a[i] - 1;
            if (tmp >= 0){
                dp[i][j] -= pre[tmp];
                dp[i][j] = (dp[i][j] + mod) % mod;
            }
        }
    }
    cout << dp[n][k];
    return 0;
}


Measured memory_bytes: 43264
#include <bits/stdc++.h>
using namespace std;
int main () {
  int H ,W;
  cin >> H >> W;
  vector<vector<char>> data(H + 2, vector<char> (W + 2, '#'));
  for(int i = 0; i < H; i++) {
    for(int j = 0; j < W; j++) {
      cin >> data.at(i + 1).at(j + 1);
    }
  }
  for(int i = 0; i < H + 2; i++) {
    for(int j = 0; j < W + 2; j++) {
      cout << data.at(i).at(j);
    }
    cout << endl;
  }
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
using namespace std;
typedef long long ll;
ll X[100005];
ll Y[100005];
int main() {
  ios::sync_with_stdio(false);
  int N, M;
  cin >> N >> M;
  for (int i=0; i<M; i++) {
    cin >> X[i];
  }
  sort(X, X+M);
  for (int i=0; i<M-1; i++) {
    Y[i] = X[i+1] - X[i];
  }
  sort(Y, Y+M-1);
  ll s = 0;
  for (int i=0; i<M-N; i++) {
    s += Y[i];
  }
  cout << s << endl;
}

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

using namespace std;

int main()
{
	string s;
	stack<int> st;
	while (cin >> s)
	{
		if (s == "+")
		{
			int a = st.top();
			st.pop();
			int b = st.top();
			st.pop();
			st.push(b + a);
		}
		else if (s == "-")
		{
			int a = st.top();
			st.pop();
			int b = st.top();
			st.pop();
			st.push(b - a);
		}
		else if (s == "*")
		{
			int a = st.top();
			st.pop();
			int b = st.top();
			st.pop();
			st.push(b * a);
		}
		else
		{
			st.push(stoi(s));
		}
	}
	cout << st.top() << endl;
}


Measured memory_bytes: 3184
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <complex>
#include <utility>
#include <vector>
#include <string>
#include <stack>
#include <queue>
#include <tuple>
#include <cmath>
#include <bitset>
#include <cctype>
#include <set>
#include <map>
#include <unordered_map>
#include <numeric>
#include <functional>
#define _overload3(_1,_2,_3,name,...) name
#define _rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(ll i=ll(a);i<ll(b);++i)
#define rep(...) _overload3(__VA_ARGS__,repi,_rep,)(__VA_ARGS__)
#define all(x) (x).begin(),(x).end()
#define PRINT(V) cout << V << "\n"
#define SORT(V) sort((V).begin(),(V).end())
#define RSORT(V) sort((V).rbegin(), (V).rend())
using namespace std;
using ll = long long;
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; }
inline void Yes(bool condition){ if(condition) PRINT("Yes"); else PRINT("No"); }
template<class itr> void cins(itr first,itr last){
    for (auto i = first;i != last;i++){
        cin >> (*i);
    }
}
template<class itr> void array_output(itr start,itr goal){
    string ans = "",k = " ";
    for (auto i = start;i != goal;i++) ans += to_string(*i)+k;
    if (!ans.empty()) ans.pop_back();
    PRINT(ans);
}
ll gcd(ll a, ll b) {
    return a ? gcd(b%a,a) : b;
}
const ll INF = 1e15;
const ll MOD = 1000000007;
const ll MOD2 = 998244353;
typedef pair<ll,ll> P;
const ll MAX = 200010;
constexpr ll nx[8] = {1,0,-1,0,-1,-1,1,1};
constexpr ll ny[8] = {0,1,0,-1,-1,1,-1,1};
int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll a,b,c;
    cin >> a >> b >> c;
    Yes(a <= c && c <= b);
}

Measured memory_bytes: 256
// https://atcoder.jp/contests/abc122/tasks/abc122_b

package main

import "fmt"
import "bufio"
import "os"
import "strconv"

var _sw = bufio.NewScanner(os.Stdin)

func main() {
	b := []byte(nextString())

	maxLen := 0
	for i := 0; i < len(b); i++ {
		if !isACGT(b[i]) {
			continue
		}
		curr := 0
		for ; i < len(b); i++ {
			if isACGT(b[i]) {
				curr++
			} else {
				break
			}
		}
		maxLen = max(curr, maxLen)
	}

	fmt.Println(maxLen)
}

func isACGT(b byte) bool {
	return b == 'A' || b == 'C' || b == 'G' || b == 'T'
}

func init() {
	_sw.Split(bufio.ScanWords)
}

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

func nextString() string {
	if _sw.Scan() == false {
		panic(_sw.Err())
	}
	return _sw.Text()
}

func max(x, y int) int {
	if x > y {
		return x
	}
	return y
}

func min(x, y int) int {
	if x > y {
		return y
	}
	return x
}


Measured memory_bytes: 640
#include <cstdio>
#include <cmath>
int n;
double x[1005], y[1005], X, Y, d, e;
double dist(double a, double b) {
	return a*a + b*b;
}
int main() {
	scanf("%d", &n);
	for (int i = 0; i < n; i++) {
		scanf("%lf%lf", &x[i], &y[i]);
		X += x[i]; Y += y[i];
	}
	X /= n; Y /= n;
	double P = 0.1;
	for (int i = 0; i < 30000; i++) {
		int f = 0;
		d = dist(X - x[0], Y - y[0]);
		for (int j = 1; j < n; j++) {
			e = dist(X - x[j], Y - y[j]);
			if (d < e) { d = e; f = j; }
		}
		X += (x[f] - X)*P;
		Y += (y[f] - Y)*P;
		P *= 0.999;
	}
	printf("%.9lf\n", sqrt(d));
}

Measured memory_bytes: 128
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int x[] = new int[4];
		int y[] = new int[4];

		for (int i = 0; i < 2; i++) {
			x[i] = sc.nextInt();
			y[i] = sc.nextInt();
		}

		x[2] = y[0] - y[1] + x[1];
		y[2] = -x[0] + x[1] + y[1];

		x[3] = y[1] - y[2] + x[2];
		y[3] = -x[1] + x[2] + y[2];

		System.out.print(x[2] + " " + y[2] + " " + x[3]  + " " + y[3]);
	}
}


Measured memory_bytes: 23892
#include<bits/stdc++.h>
using std::max;
const int N=3e5+5;
int n,L,x[N],t[N],i,j,y,st[N],w,q[N],he=1,ta,P,Q,c,mx2,mx,qq[N],ww;
bool fl,fr;
long long ans;
int main(){
	scanf("%d%d",&n,&L);
	for(i=1;i<=n;++i)scanf("%d",x+i);
	for(i=1;i<=n;++i){
		scanf("%d",t+i),y=t[i],t[i]%=L*2,ans+=y-t[i];if(!t[i]){mx2=max(mx2,i);continue;}
		fl=x[i]*2>=t[i];fr=(L-x[i])*2>=t[i];
		if(fl && fr)q[++ta]=i;else if(fl)st[++w]=i,mx2=max(mx2,i);
			else if(fr){if(st[w]>0)--w,c+=2;else st[++w]=-i;}else ans+=L*2,mx2=max(mx2,i);
	}
	for(i=1,j=he;i<=w;++i)if(st[i]>0){
		for(;j<=ta && q[j]<st[i];qq[++ww]=q[j],++j);if(j<=ta && q[j]>st[i])c+=2,mx2=max(mx2,st[i]),++j;else ++Q;
	}
	for(;j<=ta;qq[++ww]=q[j],++j);
	he=1;ta=ww;memcpy(q+1,qq+1,ww<<2);
	int mxx=0;
	for(i=1;i<=w;++i)if(st[i]<0){if(he<=ta && q[he]<-st[i])c+=2,mx2=max(mx2,q[he]),++he;else ++P,mx=-st[i];mxx=-st[i];}
	y=ta-he+1;c+=y>>1<<1;y&=1;
	for(i=he;i+1<=ta;i+=2)mx2=max(mx2,q[i]);if(y)mx=max(mx,q[ta]);
	c+=2*(P+y+Q);
	if(!Q && P+y && ((P+y==n) || mx2<mx || (y && mx2<mxx)))c-=2;
	ans+=1ll*(c+2)*L;
	printf("%lld\n",ans);
	return 0;
}

Measured memory_bytes: 6144
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <unordered_set>
#include <map>
#include <unordered_map>
#include <cstdlib>
#include <set>
#include <utility>
#include <climits>
#include <cstdio>
#include <cmath>
#include <queue>
#include <stack>
#include <iomanip>

#define ll long long
#define ull unsigned long long
using namespace std;

int main()
{
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	
	ll x;
	cin >> x;
	ll t = 100, cnt = 0;
	while (t < x) {
		t += t / 100;
		++cnt;
	}
	cout << cnt;
}

Measured memory_bytes: 3636
N = int(input())
A = list(map(int, input().split()))

maxA = max(A)
minA = min(A)
argmax = -1
argmin = -1
print(2*N - 1)

for i in range(N):
  if maxA == A[i]:
    argmax = i
  if minA == A[i]:
    argmin = i

if abs(maxA) >= abs(minA):
  for i in range(N):
    print(argmax+1, i+1)
  for i in range(N-1):
    print(i+1,i+2)

else:
  for i in range(N):
    print(argmin+1, i+1)
  for i in range(N-1):
    print(N-i,N-1-i)

Measured memory_bytes: 3064
#pragma GCC target("avx2")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
#include<iostream>
#include<string>
#include<algorithm>
using namespace std;
using i32 = int_fast32_t;
using i64 = int_fast64_t;
#define rep(i, n) for (i32 i = 0; i < (i32)(n); i++)
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
using P = pair<i64,i64>;

int main(){
ios::sync_with_stdio(false);
std::cin.tie(nullptr);
string s;
string t;
cin >> s >> t;
i64 ans = 1000000;
rep(i,s.size() - t.size() + 1){
    string S = s.substr(i,t.size());
    i64 cnt = 0;
    rep(j,t.size()){
        if(S[j] != t[j])cnt++;
    }
    ans = min(cnt,ans);
}
cout << ans << endl;
}

Measured memory_bytes: 3660
/**
 * File    : B.cpp
 * Author  : Kazune Takahashi
 * Created : 2018-11-14 21:42:15
 * Powered by Visual Studio Code
 */

#include <iostream>
#include <iomanip>   // << fixed << setprecision(xxx)
#include <algorithm> // do { } while ( next_permutation(A, A+xxx) ) ;
#include <vector>
#include <string> // to_string(nnn) // substr(m, n) // stoi(nnn)
#include <complex>
#include <tuple>
#include <queue>
#include <stack>
#include <map> // if (M.find(key) != M.end()) { }
#include <set>
#include <functional>
#include <random> // auto rd = bind(uniform_int_distribution<int>(0, 9), mt19937(19920725));
#include <chrono> // std::chrono::system_clock::time_point start_time, end_time;
// start = std::chrono::system_clock::now();
// double elapsed = std::chrono::duration_cast<std::chrono::milliseconds>(end_time-start_time).count();
#include <cctype>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <cstdlib>
using namespace std;

#define DEBUG 0 // change 0 -> 1 if we need debug.

typedef long long ll;

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

// const int C = 1e6+10;
// const ll M = 1000000007;

int main()
{
  string S, T;
  cin >> S >> T;
  sort(S.begin(), S.end());
  sort(T.begin(), T.end());
  reverse(T.begin(), T.end());
  if (S < T)
  {
    cout << "Yes" << endl;
  }
  else
  {
    cout << "No" << endl;
  }
}

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


#define endl            '\n'
#define ll              long long
#define ld              long double 
#define ull             unsigned long long int
#define MOD             (ll)(1e9 + 7)
#define vi              vector<int>
#define vl              vector<long>
#define vll             vector<ll>
#define vs              vector<string>
#define pll             pair<ll,ll>
#define mll             map<ll,ll>
#define len(x)          x.length()
#define all(x)          x.begin(),x.end()
#define deb1(x)         cout<<#x<<" "<<x<<endl;
#define deb2(x,y)       cout<<#x<<" "<<x<<'	'<<#y<<" "<<y<<endl;
#define deb3(x,y,z)     cout<<#x<<" "<<x<<'	'<<#y<<" "<<y<<'	'<<#z<<" "<<z<<endl;
#define debug1(x)       cerr<<#x<<" "<<x<<endl;
#define debug2(x,y)     cerr<<#x<<" "<<x<<'	'<<#y<<" "<<y<<endl;
#define debug3(x,y,z)   cerr<<#x<<" "<<x<<'	'<<#y<<" "<<y<<'	'<<#z<<" "<<z<<endl;
#define info(s)         cerr<<s<<" "<<endl;
#define fr(a,b,c)       for(auto a=b;b<c?a<c:a>c;b<c?a++:a--)
#define frc(a,b,c)      for(auto a=b;a!=c;a++)
#define tr(it, a)       for(auto it = a.begin(); it != a.end(); it++)
#define lb(v,x)         lower_bound(v.begin(), v.end(), x)
#define ub(v,x)         upper_bound(v.begin(), v.end(), x)
#define clr(x)          memset(x, 0, sizeof(x))
#define GR              (double)(1 + sqrt(5)) / 2
#define fib(n)          (ll)round(pow(GR,n) / sqrt(5))
#define FIO             ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define out1(x)         cout<<x<<" "<<endl
#define out2(x,y)       cout<<x<<" "<<y<<endl
#define SORT(a)         sort(all(a));
#define SORTR(a)        sort(all(a),greater<ll>());
#define ARRAY(a,n)      vll a; fr(i,0,n) { ll temp; cin>>temp; a.pb(temp); }  
#define PRINT(a)        for(auto x:a)cout<<x<<" ";cout<<endl
#define MAX             100050
#define pb              push_back
#define mp              make_pair
#define F               first
#define S               second


template<typename T>
ostream& operator<<(ostream &out,const vector<T> &v);


template<typename T>
istream& operator>>(istream &in,vector<T> &v);





void solve()
{
    int n;cin>>n;vi v(n+1);for(int i=1;i<=n;i++)cin>>v[i];
    vi dp(n+1);
    dp[1]=0;dp[2]=abs(v[2]-v[1]);
    for(int i=3;i<=n;i++)
    dp[i]=min(abs(v[i]-v[i-1])+dp[i-1],abs(v[i]-v[i-2])+dp[i-2]);
    cout<<dp[n]<<endl;

    // for(int i=1;i<=n;i++ )
    // cout<<dp[i]<<" ";cout<<endl;
} 


int main()
{   
    #ifndef ONLINE_JUDGE 
        freopen("input.txt", "r", stdin); 
        freopen("output.txt", "w", stdout); 
    #endif 
    FIO;
    ll test;test=1;
    // cin>>test;for(ll i=1;i<=test;i++)
    solve();
    return 0;
}





template<typename T>
ostream& operator<<(ostream &out,const vector<T> &v){
    int i=0;
    for(T x:v){
        out<<x;
        (i++!=v.size())?out<<' ':out<<'\n';    
    }
    return out;
}


template<typename T>
istream& operator>>(istream &in,vector<T> &v){
    for(T &i:v)
        in>>i;
    return in;
}

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

bool odd(int n){
      int ans = 0;
      for(int i = 1;i <= n;i += 2){
            if(n % i == 0)ans++;
      }
      return ans == 8;
}

int main(){
      int n;cin >> n;
      int ans = 0;
      for(int i = 1;i <= n;i++){
            if(odd(i))ans++;
      }
      cout << ans;
}

Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main(){
	int n;	cin>>n;
	int data[n];
	for(int i=0;i<n;i++)	cin>>data[i];
	for(int i=0;i<n;i++){
		cout<<"node "<<i+1<<": key = "<<data[i]<<", ";
		if(i>0)	cout<<"parent key = "<<data[(i+1)/2-1]<<", ";
		if((i+1)*2-1<n)	cout<<"left key = "<<data[(i+1)*2-1]<<", ";
		if((i+1)*2<n)	cout<<"right key = "<<data[(i+1)*2]<<", ";
		cout<<endl;
	}
	return 0;
}

Measured memory_bytes: 1160
#include <bits/stdc++.h>
#define MOD 1000000007LL
using namespace std;
typedef long long ll;
typedef pair<int,int> P;

int s,w;

int main(void){
	scanf("%d%d",&s,&w);
	printf("%s\n",s>w?"safe":"unsafe");
	return 0;
}


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

using namespace std;
typedef long long ll;
int main()
{
    vector<ll> l1, l2, l3, l4;
    ll N, W;

    ll w1, v1, wi, vi;
    cin >> N >> W >> w1 >> v1;
    l1.push_back(v1);
    for (int i = 1; i < N; i++)
    {
        cin >> wi >> vi;
        if (wi == w1)
            l1.push_back(vi);
        else if (wi - w1 == 1)
            l2.push_back(vi);
        else if (wi - w1 == 2)
            l3.push_back(vi);
        else
            l4.push_back(vi);
    }

    sort(l1.rbegin(), l1.rend());
    sort(l2.rbegin(), l2.rend());
    sort(l3.rbegin(), l3.rend());
    sort(l4.rbegin(), l4.rend());

    ll pre = 0, ans = 0, wei = 0;
    for (int i1 = l1.size(); i1 >= 0; i1--)
    {
        for (int i2 = l2.size(); i2 >= 0; i2--)
        {
            for (int i3 = l3.size(); i3 >= 0; i3--)
            {
                for (int i4 = l4.size(); i4 >= 0; i4--)
                {
                    pre = 0;
                    wei = 0;
                    for (int j1 = 0; j1 < i1; j1++)
                    {
                        wei += w1;
                        pre += l1[j1];
                    }
                    for (int j2 = 0; j2 < i2; j2++)
                    {
                        wei += w1 + 1;
                        pre += l2[j2];
                    }
                    for (int j3 = 0; j3 < i3; j3++)
                    {
                        wei += w1 + 2;
                        pre += l3[j3];
                    }
                    for (int j4 = 0; j4 < i4; j4++)
                    {
                        wei += w1 + 3;
                        pre += l4[j4];
                    }
                    // cout <<"{"<<i1<<i2<<i3<<i4<<"} "<< wei << " " << pre << endl; //確認用
                    if (wei <= W && ans < pre)
                        ans = pre;
                }
            }
        }
    }
    cout << ans << endl;
    return 0;
}

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

using namespace std;

typedef long long ll;
#define SWAP(x,y,z) {if ( y > z ) swap(y,z); if ( x > y ) swap(x,y); if (y > z) swap(y,z);}


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

    unsigned short int x;
    cin >> x;
    if ( x < 1200 ) cout << "ABC";
    else cout << "ARC";
    
    return 0;
    // 274751WM
}


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

int main(){
  
  std::string S,T;
  std::cin>>S>>T;
  
  bool check=false;
  if(S==T) check=true;
  
  int i=0;
  while(i<T.length()){
    S=S.substr(S.length()-1)+S.substr(0,S.length()-1);
    if(S==T) check=true;
    i++;
  }
  std::cout<<std::endl;
  if(check) std::cout<<"Yes"<<std::endl;
  else std::cout<<"No"<<std::endl;
  
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
int main()
  {
double n;
cin>>n;
double ans=0;
for(int i=1;i<=n;i++) if(i&1) ans++;
cout<<setprecision(9)<<fixed<<ans/n<<endl;
  }









Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <cmath>
#include <queue>
#include <map>
#include <unordered_map>
#include <set>
#include <functional>
#include <iomanip>
#include <bitset>
using namespace std;

typedef long long ll;

int n;
ll a[20][20];
ll dp[(1 << 16) + 3];

ll f(int s) {
	ll ret = 0;
	for (int i = 0; i < n; i++) {
		if (!((s >> i) & 1)) continue;
		for (int j = 0; j < n; j++) {
			if (!((s >> j) & 1)) continue;
			ret += a[i][j];
		}
	}
	return ret / 2;
}

int main() {
	cin >> n;
	for (int i = 0; i < n; i++) {
		for (int j = 0; j < n; j++) cin >> a[i][j];
	}
	for (int s = 1; s < (1 << n); s++) {
		dp[s] = f(s);
		for (int t = 1; t < s; t++) {
			if ((s&t) != t) continue;
			dp[s] = max(dp[s], dp[s&~t] + dp[t]);
		}
	}
	cout << dp[(1 << n) - 1] << endl;
	return 0;
}

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

int main() {
  //vector<int> b(101);
  //b.at(0)=1;
  int H, W, h, w;
  cin >> H >> W >> h >> w;
  cout << (H-h)*(W-w) << endl;
  return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
int main(void){
	
	double r;
	scanf("%lf",&r);
	double a,b;
	a=r*r*3.141592653589793;
	b=2*r*3.141592653589793;
	printf("%lf %lf\n",a,b);
	
	return 0;
}


Measured memory_bytes: 2056
#include<stdio.h>
int main(void){
    int L,A,B,C,D;
    int i;
    scanf("%d",&L);
    scanf("%d",&A);
    scanf("%d",&B);
    scanf("%d",&C);
    scanf("%d",&D);
    int n=A/C;
    if(A%C!=0)n=n+1;
    int m=B/D;
    if(B%D!=0)m=m+1;
    if(n<m)n=m;
    int c=L-n;
    printf("%d\n",c);
return 0;
}

Measured memory_bytes: 1024
#include<iostream>
#include<cstdio>
#include<string>
#include<algorithm>
#include<vector>
#include<cmath>
#include<map>
#include<bitset>
#include<queue>
using namespace std;
#define FOR(i,a,b) for (int i=(a);i<(b);i++)
#define rep(i,n) FOR(i,0,n)
typedef long long ll;
int main(){

	int n,c,k,a;
	vector<int> v;
	cin >>n>>c>>k;
	rep(i,n){
		cin >> a;
		v.push_back(a);
	}
	sort(v.begin(),v.end());
	a = v[0];
	int t;
	int cnt =1,bus=1;
	FOR(i,1,n){
		t = v[i];
		if (cnt >= c||t>a+k){
			a=t;
			cnt=1;
			bus++;
		}
		else{
			cnt++;
		}
//		cout << bus << " " << i << " " << v[i] <<  endl;
	}
	cout << bus << endl;
	return 0;
}


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

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

using namespace std;

const int inf = 1e9 + 7;

int main() {
	int a,b;
	cin >> a >> b;
	cout << max(a+b,max(a-b,a*b)) << endl;
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstring>

using namespace std;

struct vector2 {
    int cap = 128;
    int *data;
    int pos = 0;

    vector2() {
        data = new int[cap];
    }
};

void pushBack(vector2 &t, int x) {
    if (t.pos == t.cap) {
        t.cap *= 2;
        int *new_data = new int[t.cap];
        memcpy(new_data, t.data, t.pos * sizeof(int));
        delete[] t.data;
        t.data = new_data;
    }
    t.data[t.pos++] = x;
}

void dump(vector2 &t) {
    if (t.pos > 0) {
        for (int i = 0; i < t.pos; i++) {
            cout << (i == 0 ? "" : " ");
            cout << t.data[i];
        }
    }
    cout << endl;
}

void clear(vector2 &t) {
    t.pos = 0;
}

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

    vector2 A[n];

    while (Q--) {
        int q, t, x;
        cin >> q;
        switch (q) {
            case 0:
                cin >> t >> x;
                pushBack(A[t], x);
                break;
            case 1:
                cin >> t;
                dump(A[t]);
                break;
            case 2:
                cin >> t;
                clear(A[t]);
                break;
        }
    }
}



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


int main()
{

  ios::sync_with_stdio(0);
  cin.tie(0);
  int n;
  cin>>n;
  vector<int> h(n+1,0);
  for(int i=1; i<=n; i++){
    cin>>h[i];
  }
  ll dp[n+1];
  dp[0]=0;
  dp[1]=0;
  dp[2]=abs(h[1]-h[2]);
  for(int i=3; i<=n; i++){
        dp[i]=min(dp[i-1]+abs(h[i]-h[i-1]),dp[i-2]+abs(h[i]-h[i-2]));
  }
  cout<<dp[n];

  return 0;
}

Measured memory_bytes: 4516
A=int(input())
B=int(input())
if (A==1 and B==2) or (A==2 and B==1):
    print(3)
elif (A==2 and B==3) or (A==3 and B==2):
    print(1)
elif (A==3 and B==1) or (A==1 and B==3):
    print(2)

Measured memory_bytes: 9180
#include <iostream>
#include <complex>
#include <sstream>
#include <string>
#include <algorithm>
#include <deque>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <vector>
#include <set>
#include <limits>
#include <cstdio>
#include <cctype>
#include <cmath>
#include <cstring>
#include <cstdlib>
#include <ctime>
using namespace std;
#define REP(i, j) for(int i = 0; i < (int)(j); ++i)
#define FOR(i, j, k) for(int i = (int)(j); i < (int)(k); ++i)
#define SORT(v) sort((v).begin(), (v).end())
#define REVERSE(v) reverse((v).begin(), (v).end())
typedef complex<double> P;

vector<string> split(string &str, char delim){
  stringstream ss(str);
  string tmp;
  vector<string> res;
  while(getline(ss, tmp, delim)) res.push_back(tmp);
  return res;
}

int main() {
  string s;
  while(getline(cin, s) && s != "END OF INPUT"){
    vector<string> ws = split(s, ' ');
    REP(i, ws.size()) cout <<ws[i].length();
    cout <<endl;
  }
  return 0;
}

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

class Merge {
public:
	Merge() : count(0){}

	void mergeSort(int A[], int left, int right) {
		if (left + 1 >= right) {
			return;
		}
		int mid = (left + right) / 2;
		mergeSort(A, left, mid);
		mergeSort(A, mid, right);
		merge(A, left, mid, right);
	}

	int getCount() {
		return count;
	}

private:
	void merge(int A[], int left, int mid, int right) {
		int numL = mid - left;
		int numR = right - mid;

		//?????§A??????????????´??°???????????§??\?????????????????????????????????
		int L[250002];
		int R[250002];
		for (int i = 0; i < numL; i++) {
			L[i] = A[left + i];
		}
		for (int i = 0; i < numR; i++) {
			R[i] = A[mid + i];
		}
		//??????????????¨????????\???????????????
		L[numL] = 1000000001; 
		R[numR] = 1000000001;
		int iL = 0;
		int iR = 0;
		for (int j = left; j < right; j++) {
			if (L[iL] <= R[iR]) {
				A[j] = L[iL];
				iL++;
			}
			else {
				A[j] = R[iR];
				iR++;
			}
			count++;
		}
	}

	int count;
};

int main() {
	int A[500000];
	int numA;
	Merge mer;
	cin >> numA;
	for (int i = 0; i < numA; i++) {
		cin >> A[i];
	}

	mer.mergeSort(A, 0, numA);

	for (int i = 0; i < numA; i++) {
		if (i) cout << " ";
		cout << A[i];
	}
	cout << endl;
	cout << mer.getCount() << endl;
	return 0;
}

Measured memory_bytes: 6900
#include <bits/stdc++.h>
#define pb push_back
#define mp make_pair

using namespace std;

const int INF = 2000000000;
const double pi = 3.1415926;
const int base = 1000000007;


set <int> s;

int main()
{
    //ifstream cin ("input.txt");
    //ofstream cout ("output.txt");
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    int a, b, c;
    cin >> a >> b >> c;
    s.insert(a);
    s.insert(b);
    s.insert(c);
    if (s.size() == 2)
    {
        cout << "Yes";
    }
    else cout << "No";
    return 0;
}


Measured memory_bytes: 256
#include<iostream>
using namespace std;
int main(){
  int i;
  int a[5];
  for(i=0;i<5;++i)
    cin>>a[i];
  cout<<min(min(a[0],a[1]),a[2])+min(a[3],a[4])-50<<endl;
  return 0;
}

Measured memory_bytes: 0
import java.io.*;
import java.util.*;
import java.lang.Math;
import java.util.Arrays;

public class Main {
    public static void main(final String[] args) {

        Scanner sc = new Scanner(System.in);

        int n;
        n = sc.nextInt();
        int[] ar = new int[n];
        for (int i = 0; i < n; i++) {
            ar[i] = sc.nextInt();
        }
        for (int i = ar.length - 1; i >= 0; i--) {
            System.out.print(ar[i]);
            if (i != 0)
                System.out.print(" ");
        }
        System.out.println();
    }
  
}


Measured memory_bytes: 26492
#include <bits/stdc++.h>
typedef long long int ll;
typedef long double ld;
using namespace std;
ll mod=998244353;
const ll inf = (ll)1e17;
const ld eps = 1e-12;
const ld PI = 3.14159265358979323846;
ll mul(ll a, ll b, ll m = mod) { return (ll)(a * b) % m;}
ll gcd(ll a,ll b) { return b?gcd(b,a%b):a;}
ll powmod(ll a,ll b){ll res=1;a%=mod;assert(b>=0);for(;b;b>>=1){if(b&1)res=res*a%mod;a=a*a%mod;}return res%mod;}
long modInverse(long a) {return powmod(a, mod-2);}
ll my_rand(){ll a=rand();ll b=rand();return (a*RAND_MAX+1)+b;}
typedef pair<int, int> pi;
typedef pair<ll,ll> pl;
typedef pair<ld,ld> pd;

typedef vector<int> vi;
typedef vector<ld> vd;
typedef vector<ll> vl;
typedef vector<pi> vpi;
typedef vector<pl> vpl;

#define mp make_pair
#define pb push_back
#define f first
#define s second
#define lb lower_bound
#define ub upper_bound
#define all(x) x.begin(), x.end()



int main(){
    ios::sync_with_stdio(false);
    srand(chrono::steady_clock::now().time_since_epoch().count());
    cin.tie(0);
    cout.tie(0);
    ll x,k;
    cin>>x>>k;
    if(x<=k){
        ll res=min(x,k-x);
        cout<<res<<endl;
    }
    else{
        ll ans=x/k;
        x-=(ans*k);
        ll res=min(x,k-x);
        cout<<res<<endl;
    }
    return 0;
    }


Measured memory_bytes: 256
h, w, k = map(int, input().split())
s = [list(map(int, input())) for _ in range(h)]
ans = float("inf")

for sep in range(1 << (h-1)):
    g_id = [0] * h
    cur = 0
    for i in range(h-1):
        g_id[i] = cur
        if sep >> i & 1: cur += 1
    g_id[h-1] = cur
    g_num = cur+1

    ng = False
    for i in range(w):
        tmp = [0] * g_num
        for j in range(h): tmp[g_id[j]] += s[j][i]
        if any([x > k for x in tmp]): ng = True; break
    if ng: continue

    res = g_num-1
    
    gs = [0] * g_num
    for i in range(h):
        gs[g_id[i]] += s[i][0]
    
    for i in range(1, w):
        tmp = gs[::]
        for j in range(h):
            tmp[g_id[j]] += s[j][i]
        if any([x > k for x in tmp]):
            res += 1
            gs = [0] * g_num
        for j in range(h): gs[g_id[j]] += s[j][i]

    ans = min(ans, res)

print(ans)


Measured memory_bytes: 51676
#include<iostream>
#include<vector>
#include<cmath>
#include<algorithm>
#include<string>
#include<climits>
#include<stack>
#include<queue>
#include<unordered_map>
#include<map>
#include<set>
#include<fstream>
#include<list>
#include<sstream>

#define loopi(x,y) for(int i = x;i<(y);i++)
#define loopj(x,y) for(int j = x;j<(y);j++)
#define rloopi(x,y) for(int i = x;i>=(y);i--)
#define rloopj(x,y) for(int j = x;j>=(y);j--)


#define nl cout<<"\n";
#define ll long long int
#define mod  1000000007

using namespace std;

void generatePrimeFactors(vector<int> &factor)
{
	int n = factor.size();
	factor[1] = 1;

	for (int i = 2; i < n; i++)
		factor[i] = i;

	for (int i = 4; i < n; i += 2)
		factor[i] = 2;

	for (int i = 3; i * i < n; i++) {

		if (factor[i] == i) {
			for (int j = i * i; j < n; j += i) {
				if (factor[j] == j)
					factor[j] = i;
			}
		}
	}
}

int calculateNoOFactors(int n, vector<int> &factor)
{
	if (n == 1)
		return 1;

	int ans = 1;

	int dup = factor[n];

	int c = 1;

	int j = n / factor[n];

	while (j != 1) {

		if (factor[j] == dup)
			c += 1;
		else
		{
			dup = factor[j];
			ans = ans * (c + 1);
			c = 1;
		}
		j = j / factor[j];
	}
	ans = ans * (c + 1);

	return ans;
}

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

#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif

	int n;
	cin >> n;
	vector<int> factor(n, 0);
	generatePrimeFactors(factor);
	long long count = 0;
	for (int i = 1; i < n; i++)
		count += calculateNoOFactors(i, factor);

	cout << count;

	return 0;
}

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

int main(){
  string S,T;
  cin >> S;
  cin >> T;
  int ans=0;
  for(int i=0; i<S.size(); i++){
      if(S[i] != T[i]) ans++;
  }
  cout << ans;
  return 0;
}

Measured memory_bytes: 3848
#include<iostream>
#include<string>
#include<algorithm>

using namespace std;

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

int main(){
    int n;
    cin >> n;
    int s[n];
    rep(i, n) cin >> s[i];
    sort(s, s + n);
    int ans = 0;
    rep(i, n) ans += s[i];
    if(ans % 10 != 0){
        cout << ans << endl;
        return 0;
    }else{
        rep(i, n){
            if(s[i] % 10 != 0){
                cout << ans - s[i] << endl;
                return 0;
            }
        }
        cout << 0 << endl;
    }

}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define ll long long
#define fi first
#define se second
#define pb push_back
#define rep(i, s, n) for (int i = s; i < n; i++)
#define rrep(i, s, n) for (int i = (n)-1; i >= (s); i--)
#define REP(i,n) for(int i = 0;i < n; i++)
#define all(a) a.begin(),a.end()
typedef pair<int,int>pint;
typedef vector<int>vint;
typedef vector<pint>vpint;
const long long MOD = 1000000007, INF = 1e18;

#define endl '\n'
#define IOS() ios_base::sync_with_stdio(0);cin.tie(0)
 
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;}
template<typename T>vector<T>
make_v(size_t a){return vector<T>(a);}
template<typename T,typename... Ts>
auto make_v(size_t a,Ts... ts){
	return vector<decltype(make_v<T>(ts...))>(a,make_v<T>(ts...));
}

template<typename T,typename V>
typename enable_if<is_class<T>::value==0>::type
fill_v(T &t,const V &v){t=v;}

template<typename T,typename V>
typename enable_if<is_class<T>::value!=0>::type
fill_v(T &t,const V &v){
	for(auto &e:t) fill_v(e,v);
}


signed main(){
	IOS();
	vector<int>ans;
	while(1){
		int e;
		cin>>e;
		if(e==0)break;
		int mi = INF;
		rep(i,0,111){
			rep(j,0,1111){
				if(i*i*i+j*j>e)continue;
				int k = e-i*i*i-j*j;
				chmin(mi,i+j+k);				
			}
		}
		ans.push_back(mi);
	}
	for(auto e:ans){
		cout<<e<<endl;
	}
}


Measured memory_bytes: 3072
from collections import deque

n = int(input())

roots = [[] for _ in range(n)]
for _ in range(n-1):
    a,b = map(int,input().split())
    roots[a-1].append(b-1)
    roots[b-1].append(a-1)

d1 = [-1] * n
d2 = [-1] * n
d1[0] = 0
d2[-1] = 0

q1 = deque([0])
q2 = deque([n-1])

while q1:
    l = q1.pop()
    for i in roots[l]:
        if d1[i] == -1:
            d1[i] = d1[l] + 1
            q1.append(i)

while q2:
    l = q2.pop()
    for i in roots[l]:
        if d2[i] == -1:
            d2[i] = d2[l] + 1
            q2.append(i)

f = 0
s = 0

for i in range(n):
    if d1[i] <= d2[i]:
        f += 1
    else:
        s += 1

if f > s:
    print('Fennec')
else:
    print('Snuke')


Measured memory_bytes: 29336
#include<bits/stdc++.h>
#include <iostream>
#include<string>
#define ll long long int
using namespace std;

int main() {
	string s;
	cin>>s;
	ll n =s.size();
	if(s[n-1]=='s')
	{
		cout<<s<<"es\n";
	}
	else cout<<s<<"s\n";
	
	
	
	
	return 0;
}

Measured memory_bytes: 3628
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define mp make_pair
#define pb push_back
#define F first
#define S second
#define mod 1000000007
#define all(a) a.begin(),a.end()
#define dbg(n) cout<<#n<<' '<<n<<endl;
#define dbg_v(v) cout<<#v<<":";for(auto x:v) cout<<" "<<x; cout<<endl;
int power(ll x,ll y){ll res = 1;while(y>0){if(y&1)res = (res*x)%mod;y=y>>1;x=(x*x)%mod;}return res;}
int dx[4]={0,1,-1,0};
int dy[4]={1,0,0,-1};
int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);	
	int T=1;
	//cin>>T;
	while(T--){
		double n,x,t;
		cin>>n>>x>>t;
		int ans=0,val=0;
		while(val<n){
			val+=x;
			ans+=t;
		}
			
		cout<<ans<<endl;
	}
}


Measured memory_bytes: 3728
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int A,B,i,j,N, cnt=0;
  cin >> N >> A >> B;
 
  for(i=1;i<=N;i++){
    int num = i;
    int sum = 0;
    for(j=0;j<5;j++){
    	sum += (num % 10);
      	num /= 10;
  	}
    if(sum >= A && sum <= B){cnt+=i;}
  }

  cout << cnt << endl;

  return 0;
}


Measured memory_bytes: 256