akhauriyash/Code-Regression huggingface dataset:
n = int(input())
H = list(map(int, input().split()))
dp = [10**9 for i in range(n)]

dp[0] = 0
for i in range(n-1):
    if i < n-2:
        dp[i+2] = min(dp[i+2], dp[i] + abs(H[i+2]-H[i]))
    dp[i + 1] = min(dp[i + 1], dp[i] + abs(H[i + 1] - H[i]))
print(dp[n-1])

Measured memory_bytes: 13908
#include <bits/stdc++.h>
#define rep(i, n) for (ll i = 0; i < (n); i++)
#define all(x) (x).begin(), (x).end()
using ll = long long;
using namespace std;
template <typename T> using vec = std::vector<T>;

int main() {
    int N, M;
    cin >> N >> M;
    vec<int> Z(N,1);
    vec<bool> R(N,false);
    R[0] = true;

    int root = 0;
    rep(i,M){
      int x,y;
      cin >> x >> y;
      --x,--y;
      if(R[x]) R[y]=true;
      --Z[x],++Z[y];
      if(Z[x]==0) R[x] = false;
       
    }
    
    int ans = 0;
    rep(i,N){
      if(R[i]) ++ans;
    }
    cout << ans << '\n';
}


Measured memory_bytes: 3576
// includes {{{
#include<iostream>
#include<iomanip>
#include<algorithm>
#include<vector>
#include<stack>
#include<queue>
#include<map>
#include<set>
#include<tuple>
#include<cmath>
#include<random>
#include<cassert>
#include<bitset>
#include<cstdlib>
// #include<deque>
// #include<multiset>
// #include<cstring>
// #include<bits/stdc++.h>
// }}}
using namespace std;
using ll = long long;

int main() {
  std::ios::sync_with_stdio(false), std::cin.tie(0);
  int n;
  cin >> n;
  int ans = 0;
  for(;n > 1; ans++) {
    n = (n + 2) / 3;
  }
  cout << ans << "\n";
  return 0;
}



Measured memory_bytes: 3180
#include <iostream>
#include <vector>
#include <map>
#include <cmath>
#include <algorithm>
#define endl "\n"
using namespace std;

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

    string str;
    cin >> str;

    str[k - 1] = str[k - 1] + 32;
    cout << str << endl;
}

Measured memory_bytes: 256
A, B, H, M = [int(_) for _ in input().split()]

import math

ax = math.sin(2*math.pi * (H * 60 + M) / (12 * 60)) * A
ay = math.cos(2*math.pi * (H * 60 + M) / (12 * 60)) * A

bx = math.sin(2*math.pi * M / 60) * B
by = math.cos(2*math.pi * M / 60) * B

result = math.sqrt((ax - bx) ** 2 + (ay - by) ** 2)

print(result)

Measured memory_bytes: 9428
#include<iostream>
#include<string.h>
#include<vector>
#include<algorithm>
#include<map>
using namespace std;
#define ll long long 
#define ull unsigned long long
#define pb push_back
const int maxn = 200005;
const ll mod = 1000000007;
int fa[maxn], fb[maxn];
void init() {
    for (int i = 0; i < maxn; i++) fa[i] = i, fb[i] = i;
}
int fi(int* k, int x) {
    return x == k[x] ? x : k[x] = fi(k, k[x]);
}
void Union(int* k, int x, int y) {
    int fx = fi(k, x), fy = fi(k, y);
    if (fx != fy) k[fy] = fx;
}
map<pair<int, int>, int>mp;
int main() {
    ios::sync_with_stdio(0), cout.tie(0), cin.tie(0);
    int n, k, l, x, y;
    init();
    cin >> n >> k >> l;
    while (k--) {
        cin >> x >> y;
        Union(fa, x, y);
    }
    while (l--) {
        cin >> x >> y;
        Union(fb, x, y);
    }
    for (int i = 1; i <= n; i++)  mp[make_pair(fi(fa, i), fi(fb, i))]++;
    for (int i = 1; i <= n; i++) cout<<mp[make_pair(fi(fa, i), fi(fb, i))]<<" ";
    cout<< '\n';
    return 0;

}

Measured memory_bytes: 16636
<?php
fscanf(STDIN, "%d", $n);

for($i = 0; $i < $n; $i++){
  fscanf(STDIN, "%d%d", $a, $b);
  $A[] = $a;
  $B[] = $b;
}
array_multisort($B, $A);

$t = 0;
for($i = 0; $i < $n; $i++){
  $t+=$A[$i];
  if($t>$B[$i]){
    echo "No\n";
    exit;
  }
}
echo "Yes\n";
exit;


Measured memory_bytes: 41580
#include<bits/stdc++.h>
using namespace std;
#define DEBUG
// #define TIME
/*
Learn : -
Problem Type : -
Source : -
*/
#pragma GCC optimize ("Ofast")
#define sint(a) int a; qread(a);
#define sint2(a,b) int a,b; qread(a),qread(b);
#define sint3(a,b,c) int a,b,c; qread(a),qread(b),qread(c);
#define int1(a) qread(a);
#define int2(a,b) qread(a),qread(b);
#define int3(a,b,c) qread(a),qread(b),qread(c);
#define mkp make_pair
#define mkt make_tuple
#define pb emplace_back
#define inf INT_MAX
#define all(x) (x).begin(),(x).end()
#define F first
#define S second
#define sdouble(a) double a; scanf("%lf",&a);
#define slong(a) long long a; scanf("%lld",&a);
#define cstring(a,x) char a[x]; scanf("%s",a);
#define sstring(a) string a;cin>>a;
#define rev(s) reverse(all(s));
#define FOR(a,b,c) for(int a=b;a<c;a++)
#define ROF(a,b,c) for(int a=b;a>c;a--)
#define pause system("pause")
#define endl printf("\n")
#define fastio {ios::sync_with_stdio(false);cin.tie(NULL);}
#define null NULL
#ifdef DEBUG
#define debug(x) cout<< #x << " = " << x;endl;
#else
#define debug(x)
#endif
#define OPEN freopen("input.txt","r",stdin)
#define SEND freopen("output.txt","w",stdout)
#ifdef COM
#define IN(x)
#define OUT(x)
#else
#define IN(x) freopen(x,"r",stdin);
#define OUT(x) freopen(x,"w",stdout);
#endif
typedef pair<int,int> ii;
typedef vector<int> vi;
typedef vector<ii> vii;
typedef long long ll;
void qread(int &x){
	int neg=1;x=0;
	register char c=getchar();
	while(c<'0'||c>'9'){if(c=='-')neg=-1;c=getchar();}
	while(c>='0'&&c<='9')x=10*x+c-'0',c=getchar();
	x*=neg;
}
void Wl(int x)
{
    printf("%d\n",x);
}
void Wl(double x)
{
    printf("%lf\n",x);
}
void Wl(string x)
{
    printf("%s\n",x.c_str());
}
void Wl(ll x)
{
    printf("%lld\n",x);
}
void W(int x)
{
    printf("%d ",x);
}
void W(double x)
{
    printf("%lf ",x);
}
void W(string x)
{
    printf("%s ",x.c_str());
}
void W(ll x)
{
    printf("%lld ",x);
}

int n,m;
char a[15][15];
bool checkDown(int x,int y)
{
	if(x+1 >=n || a[x+1][y]!='#')return false;
	return true;
}
bool checkRight(int x,int y)
{
	if(y+1 >=m || a[x][y+1]!='#')return false;
	return true;
}
int main()
{
    int2(n,m);
	FOR(i,0,n)
	{
		scanf("%s",a[i]);
	}
	FOR(i,0,n)FOR(j,0,m)
	{
		if(i==0 && j==0 && a[i][j]=='#')
		{
			a[i][j]='$';
		}
		if(a[i][j]=='#')
		{
			Wl("Impossible");
			return 0;
		}
		if(a[i][j]=='$')
		{
			if(i==n-1 && j==m-1)
			{
				Wl("Possible");
				return 0;
			}
			if(checkDown(i,j) ^ checkRight(i,j))
			{
				if(checkDown(i,j))a[i+1][j]='$';
				else a[i][j+1]='$';
			}
			else
			{
				Wl("Impossible");
				return 0;
			}
			a[i][j]='.';
		}
		// for(int k=0;k<n;k++)
		// {
		// 	printf("%s\n",a[k]);
		// }
		// pause;
	}
	Wl("Possible");
}
/*

*/


Measured memory_bytes: 256
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
int main(void){
char num_str[1002];
	int num;
	long sum=0;
	int i;
	char tmp;
	while(1){
		fgets(num_str,sizeof(num_str),stdin);
		if(num_str[0]=='0')break;
		for(i=0;i<strlen(num_str)-1;i++){
			tmp=num_str[i];
			num=atoi(&tmp);
			sum=sum+num;
		}
		printf("%ld\n",sum);
		sum=0;
		memset(num_str,1002,0);
	}
return 0;
}

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

int main(){
	int n,m,r,q;
	static int cnt[10000][1261];
	while(cin >> n >> m,n){
		for(int i = 0;i < m;i++){
			for(int j = 0;j <= 1260;j++) cnt[i][j] = 0;
		}
		cin >> r;
		for(int i = 0;i < r;i++){
			int t,a,b,s;
			cin >> t >> a >> b >> s; b--;
			if(s) cnt[b][t]++;
			else cnt[b][t]--;
		}
		for(int i = 0;i < m;i++){
			for(int j = 1;j <= 1260;j++){
				cnt[i][j] += cnt[i][j - 1];
				//if(j >= 774 && j <= 881) cout << cnt[i][j] << " ";
			}
			//cout << endl;
		}
		for(int i = 0;i < m;i++){
			for(int j = 1;j <= 1260;j++){
				if(cnt[i][j]) cnt[i][j] = 1;
			}
		}
		for(int i = 0;i < m;i++){
			for(int j = 1;j <= 1260;j++){
				cnt[i][j] += cnt[i][j - 1];
			}
		}
		cin >> q;
		for(int i = 0;i < q;i++){
			int s,t,b;
			cin >> s >> t >> b; b--;
			cout << cnt[b][t - 1] - cnt[b][s - 1] << endl;
		}
	}
	return 0;
}

Measured memory_bytes: 50764
cumulative :: [Int] -> [Int]
cumulative xs = f xs 0
  where
    f [] a = []
    f (x:xs) a = (x + a):(f xs $ x + a)

main = do
  _ <- getLine
  s <- getLine
  let en = reverse $ cumulative $ reverse $ map (\c -> if c == 'E' then 1 else 0) s
  let wn = cumulative $ map (\c -> if c == 'W' then 1 else 0) s
  print $ subtract 1 $ minimum $ zipWith (+) en wn


Measured memory_bytes: 95996
#include <iostream>
#include <algorithm>
#include <cmath>
#include <map>
#include <vector>
#include <queue>
#include <functional>
#include <string>
#include <stack>
#include <set>
#include <sstream>
#include <iomanip>
#include <limits>
#include <cstring>

using namespace std;
using ll = long long;
typedef unsigned long long ull;
typedef pair<ll, ll> P;
typedef pair<double, double >pd;
typedef pair<string, string> sP;
typedef pair<ll, pair<ll, ll>> PP;


const ll mod = 1e4;
const ll MOD = 1e9 + 7;
const ll MOD2 = 998244353;
const ll INF = 1 << 30;
const ll INF2 = 9e18;
const double INF3 = 9e14;
const double eps = 1e-10;
const double PI = 3.14159265358979323846;
const int dx[4] = { 1,0,-1,0 }, dy[4] = { 0,1,0,-1 };
const int tx[8] = { -1,0,1,-1,1,-1,0,1 }, ty[8] = { -1,-1,-1,0,0,1,1,1 };

#define ALL(x) (x).begin(),(x).end()
#define ALLR(x) (x).rbegin(),(x).rend()
#define pb push_back
#define eb emplace_back
#define fr first
#define sc second


int main() {
	ll I, O, T, J, L, S, Z, ans = 0;
	cin >> I >> O >> T >> J >> L >> S >> Z;
	if (min({ J, L,I }) >= 1) {
		ans += 6;
		I -= 1, L -= 1, J -= 1;
		ans += (I / 2) * 4;
		ans += O * 2;
		ans+= (J / 2) * 4;
		ans += (L / 2) * 4;
		I++, L++, J++;
	}
	ll ret = 0;
	ret += (I / 2) * 4;
	ret += O * 2;
	ret += (J / 2) * 4;
	ret += (L / 2) * 4;
	cout << max(ans / 2, ret / 2) << endl;
	return 0;
}



Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<vector>
#include<map>
#include<set>
#include<string>
#include<algorithm>
#include<math.h>
#include<numeric>
#include<iomanip>
#include<queue>
#include<functional>

using namespace std;

typedef vector<int> vi;
typedef pair<int, int> pii;
typedef long long ll;
typedef vector<long long> vll;
typedef pair<long long, long long> pll;

//const ll INF = 1e15;
const ll MOD = 1e9 + 7;

int main(){
	ll N;
	cin >> N;
	ll i, j;
	vll A, B;
	for (i = 0; i < N; i++){
		ll a;
		cin >> a;
		A.push_back(a);
	}
	for (i = 0; i < N; i++){
		ll b;
		cin >> b;
		B.push_back(b);
	}
	ll ma = 0;
	ll mb = 0;
	for (i = 0; i < N; i++){
		if (A[i] < B[i]){
			ma += ((B[i] - A[i]) / 2) * 2;
		}
		if (A[i] > B[i]){
			mb += A[i] - B[i];
		}
	}
	if (ma >= 2 * mb){
		cout << "Yes" << endl;
	}
	else{
		cout << "No" << endl;
	}

	return 0;
}

Measured memory_bytes: 512
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define REP(i,m,n) for(int i=(m);i<(n);i++)
#define rep(i,n) REP(i,0,n)
#define pb push_back
#define all(a) a.begin(),a.end()
#define rall(c) (c).rbegin(),(c).rend()
#define mp make_pair
#define endl '\n'
#define vec vector<ll>
#define mat vector<vector<ll> >
#define fi first
#define se second
typedef long long ll;
typedef pair<ll,ll> pll;
typedef long double ld;
const ll inf=1e9+7;
const ll mod=1e4+7;

int MAX=2000100;
vector<vector<int> >trie(MAX,vector<int>(26));
vector<int>leaf(MAX);

int sz=1;
void add_string(string s){
    int v=0;
    for(auto c:s){
        if(!trie[v][c-'a']){
            trie[v][c-'a']=sz;
            sz++;
        }
        v=trie[v][c-'a'];
    }
    leaf[v]=1;
}

signed main(){
    ll n;cin>>n;
    vector<string>a(n);
    rep(i,n){
        cin>>a[i];
        reverse(all(a[i]));
        add_string(a[i]);
    }
    ll ans=0;
    rep(i,n){
        string s;
        s=a[i];
        vector<ll>cnt(26);
        for(auto c:s){
            cnt[c-'a']++;
        }
        ll v=0;
        rep(j,s.size()){
            rep(x,26){
                if(cnt[x]&&trie[v][x]){
                    ans+=leaf[trie[v][x]];
                }
            }
            cnt[s[j]-'a']--;
            v=trie[v][s[j]-'a'];
        }
        ans--;
    }
    cout<<ans<<endl;
}

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

int abs(int num){
    if(num < 0)return -num;
    else return num;
}

int main(){
    int N, L, i, abs_min, max, abs_num;
    int *azi;
    scanf("%d %d", &N, &L);
    azi = (int *)malloc(sizeof(int) * N);
    max=0;
    for(i=0; i<N; i++){
        azi[i] = L + i;
        //printf("%d\n", azi[i]);
        max += azi[i];
    }

    abs_min = 1000;

    for(i=0; i<N; i++){
        abs_num = abs(azi[i]);
        if(abs_num < abs_min)abs_min = abs_num;
    }

    if(max < 0)printf("%d\n", max+abs_min);
    else printf("%d\n", max-abs_min);
    return 0;
}

Measured memory_bytes: 128
#include <algorithm>
#include <iostream>
#include <cstring>
#include <cstdio>
#include <vector>
using namespace std;

inline int getint()
{
	static char c;
	while ((c = getchar()) < '0' || c > '9');

	int res = c - '0';
	while ((c = getchar()) >= '0' && c <= '9')
		res = res * 10 + c - '0';
	return res;
}

const int MaxN = 200000;

int n;
int fa[MaxN + 1];

vector<int> adj[MaxN + 1];

int cir_l = 0;
int cir[MaxN + 1];

bool vis[MaxN + 1];

int f[MaxN + 1];

int li_n;
int li[MaxN + 1];

void dfs(const int &u)
{
	for (int v : adj[u])
		if (!vis[v])
			dfs(v);

	li_n = 0;
	li[li_n++] = -1;
	li[li_n++] = MaxN << 8;
	for (int v : adj[u])
		if (!vis[v])
			li[li_n++] = f[v];

	sort(li, li + li_n);
	li_n = unique(li, li + li_n) - li;
	for (int i = 0; i < li_n; ++i)
		if (li[i + 1] != li[i] + 1)
		{
			f[u] = li[i] + 1;
			break;
		}
}

inline bool check()
{
	for (int i = 1; i < cir_l; ++i)
	{
		int u = cir[i];
		int v = cir[i - 1];
		if (f[u] != f[v])
			return true;
	}

	return ~cir_l & 1;
}

int main()
{
	cin >> n;
	for (int v = 1; v <= n; ++v)
	{
		fa[v] = getint();
		adj[fa[v]].push_back(v);
	}

	int sv = 1;
	for (int i = 0; i < n; ++i)
		sv = fa[sv];

	while (!vis[sv])
	{
		cir[cir_l++] = sv;
		vis[sv] = true;
		sv = fa[sv];
	}

	for (int i = 0; i < cir_l; ++i)
		dfs(cir[i]);

	puts(check() ? "POSSIBLE" : "IMPOSSIBLE");

	return 0;
}

Measured memory_bytes: 12672
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define sz(x) int(x.size())
#define show(x) {for(auto i: x){cout << i << " ";} cout << endl;}
using namespace std;
using ll = long long;
using P = pair<int, int>;

const int MOD = 1'000'000'007;
struct mint {
    ll x; // typedef long long ll;
    mint(ll x=0):x((x%MOD+MOD)%MOD){}
    mint operator-() const { return mint(-x);}
    mint& operator+=(const mint a) {
        if ((x += a.x) >= MOD) x -= MOD;
        return *this;
    }
    mint& operator-=(const mint a) {
        if ((x += MOD-a.x) >= MOD) x -= MOD;
        return *this;
    }
    mint& operator*=(const mint a) { (x *= a.x) %= MOD; return *this;}
    mint operator+(const mint a) const { return mint(*this) += a;}
    mint operator-(const mint a) const { return mint(*this) -= a;}
    mint operator*(const mint a) const { return mint(*this) *= a;}
    mint pow(ll t) const {
        if (!t) return 1;
        mint a = pow(t>>1);
        a *= a;
        if (t&1) a *= *this;
        return a;
    }

    // for prime MOD
    mint inv() const { return pow(MOD-2);}
    mint& operator/=(const mint a) { return *this *= a.inv();}
    mint operator/(const mint a) const { return mint(*this) /= a;}
};
istream& operator>>(istream& is, mint& a) { return is >> a.x;}
ostream& operator<<(ostream& os, const mint& a) { return os << a.x;}
// combination MOD prime
struct combination {
    vector<mint> fact, ifact;
    combination(int n):fact(n+1),ifact(n+1) {
        assert(n < MOD);
        fact[0] = 1;
        for (int i = 1; i <= n; ++i) fact[i] = fact[i-1]*i;
        ifact[n] = fact[n].inv();
        for (int i = n; i >= 1; --i) ifact[i-1] = ifact[i]*i;
    }
    mint operator()(int n, int k) {
        if (k < 0 || k > n) return 0;
        return fact[n]*ifact[k]*ifact[n-k];
    }
    mint p(int n, int k) {
        if (k < 0 || k > n) return 0;
        return fact[n]*ifact[n-k];
    }
}; //comb(10000007);
// comb(5, 2) → 10, comb.p(5, 2) → 20
// comb.fact[4] → 24, 2のN乗 → mint(2).pow(N)

mint ans;
vector<int> graph[200005]; // 0-indexed
int N;

int dfs(int x, int pa = -1) {
    // 部分木のサイズを返す、自分含む
    mint add = mint(2).pow(N-1) - 1;
    int res = 1;
    for (int a : graph[x]) {
        if (a == pa) continue;
        int y = dfs(a, x);
        res += y;
        add -= mint(2).pow(y) - 1;
    }
    if (pa != -1) {
        add -= mint(2).pow(N-res) - 1;
    }
    ans += add;
    return res;
}

int main() {
    // warp and weft 一つの頂点に注目して何回選ばれるか、最後に2^Nで割る
    cin >> N;
    rep(i, N-1) {
        int a, b;
        cin >> a >> b;
        --a; --b;
        graph[a].push_back(b);
        graph[b].push_back(a);
    }
    dfs(0);
    ans /= mint(2).pow(N);
    cout << ans.x << '\n';
    return 0;
}


Measured memory_bytes: 27804
#include<bits/stdc++.h>
using namespace std;
int n, m[10001];
bool p(int x){
  if(m[x]>=0) return m[x];
  for(int i=2;i*i<=n;i++) {
    if(x%i==0) return m[x]=0;
  }
  return m[x]=1;
}
main() {
  memset(m,-1,sizeof(m));
  while(cin>>n&&n) {
    int mx=5;
    for(int i=2;i<=n-2;i++)if((p(i)&p(i+2)))mx = i;
    printf("%d %d\n",mx,mx+2);
  }
  return 0;
}

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

int main() {
	int N;
	cin>>N;
	
	vector<int> a(N);
	for(int i=0;i<N;i++) cin>>a[i];
	
	sort(a.begin(),a.end());
	
	
	int p=0;
	for(int i=0;i<a.size();i++){
	    int num=1;
	    while(a[i]==a[i+num]){
	        num++;
	    }
	    
	    if(num<a[i]){
	        p+=num;
	    }else if(num>a[i]){
	        p+=num-a[i];
	    }
	    
	    i+=num-1;
	}
	
	cout<<p<<endl;
}

Measured memory_bytes: 640
#include<algorithm>
#include<cmath>
#include<deque>
#include<iomanip>
#include<iostream>
#include<list>
#include<map>
#include<numeric>//xとyの最大公約数は__gcd(x,y),xとyの最小公倍数は(x*y)/__gcd
#include<queue>
#include<set>
#include<stack>
#include<string>
#include<vector>

#include<bits/stdc++.h>
#include<cstdio>
#include<cstdlib>
#include<tuple>
#include<utility>
typedef long long ll;
#define rep(i,n) for(ll i=0; i<n; i++)
#define vll vector<ll>
#define vi vector<int>
#define all(x) (x).begin(),(x).end()
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define mod 1000000007
using namespace std;

int main(){
  int a,n;  cin >> n;
  double ans = 0.0;
  rep(i,n){
    cin >> a;
    ans += 1.0/a;
  }
  ans = 1.0/ans;
  cout << ans;
  return 0;
}


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

using namespace std;

int main()
{
	int x1, y1, x2, y2;
	cin >> x1 >> y1 >> x2 >> y2;

	int dx = x2 - x1;
	int dy = y2 - y1;

	int x3 = x2 - dy;
	int y3 = y2 + dx;
	int x4 = x3 - dx;
	int y4 = y3 - dy;

	cout << x3 << " " << y3 << " " << x4 << " " << y4 << endl;
}


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

int main() {
    int N, temp;
    std::cin >> N;
    
    std::vector<int> d;
    for (int i=0; i<N; ++i) {
        std::cin >> temp;
        d.push_back(temp);
    }
    
    std::sort(d.begin(), d.end());
    d.erase(std::unique(d.begin(), d.end()), d.end());
    
    std::cout << d.size() << std::endl;
}

Measured memory_bytes: 256
def main():
    N = input()
    B_l = [int(i) for i in input().split()]
    A_l = []
    for i in range(len(B_l)):
        if i == 0:
            A_l.append(B_l[i])
        elif i < len(B_l):
            A_l.append(min(B_l[i - 1], B_l[i]))

    A_l.append(B_l[-1])
    print(sum(A_l))


if __name__ == "__main__":
    main()

Measured memory_bytes: 3064
import java.util.*;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int a=sc.nextInt();
        int b=sc.nextInt();
        for(double i=1;i<10000;i+=1){
            if((int)(i*0.08)==a&&(int)(i*0.1)==b){
                System.out.println((int)i);
                return;
            }
        }
        System.out.println(-1);
        
        
 
    }



}

Measured memory_bytes: 23764
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i, n) for(i = 0; i < n; i++)
//2D::rep(i,j)rep(j,j)cin>>bin[i][j];
//vector<int> a(n)
#define A1 cout<<"No"<<endl
#define A2 cout<<"Yes"<<endl
#define A3 cout<<ans<<endl
#define AA(i) cout<<i<<endl
const int U=2e5+5;
const ll MOD=1000000007;
const int INF = 1001001001;

int main(){
  int N; cin >> N;
  vector<ll> A(N);
  int i;
  ll ans=1,aans;
  rep(i,N) cin >> A[i];
  sort(A.begin(), A.end());
  rep(i,N-1){
    ans *= A[i];
    if(A[i] == 0){
      ans = 0;
      break;
    }
    if(1000000000000000000 / ans < A[i+1]){
      ans = -1;
      break;
    }
  }
  if(ans>0)ans *= A[N-1];
  AA(ans);
  return 0;
}

Measured memory_bytes: 4052
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import accumulate, permutations, combinations, product
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left
from fractions import gcd
from heapq import heappush, heappop
from functools import reduce
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7

def comb_count(n, r):
    return factorial(n) // (factorial(n - r) * factorial(r))

N = INT()
S = [input() for _ in range(N)]
for i in range(N):
	S[i] = sorted(S[i])
S = sorted(S)

ku = []
kugiri = 0
for i in range(N - 1):
	if S[i] == S[i + 1]:
		kugiri += 1
		if i == N - 2:
			ku.append(kugiri + 1)

	else:
		ku.append(kugiri + 1)
		kugiri = 0

wa = 0
for i in range(len(ku)):
	if ku[i] == 1:
		continue
	wa += comb_count(ku[i], 2)

print(wa)

Measured memory_bytes: 27544
#include <bits/stdc++.h>
using namespace std;
int main(){
    long long n,ans=0,c=0;
    cin >> n;
    long long a[n],b[10]={};
    for(int i=0;i<n;i++){
      cin >> a[i];
      if(a[i]<400){
        b[0]++;
      }else if(a[i]>=400&&a[i]<800){
        b[1]++;
      }else if(a[i]>=800&&a[i]<1200){
        b[2]++;   
      }else if(a[i]>=1200&&a[i]<1600){
        b[3]++;
      }else if(a[i]>=1600&&a[i]<2000){
        b[4]++;
      }else if(a[i]>=2000&&a[i]<2400){
        b[5]++;
      }else if(a[i]>=2400&&a[i]<2800){
        b[6]++;
      }else if(a[i]>=2800&&a[i]<3200){
        b[7]++;
      }else if(a[i]>=3200){
        c++;
      }
    }
    for(int i=0;i<8;i++){
      if(b[i]>0){
        ans++;
      }
    }
    if(ans==0){
      cout << 1 << ' ' << c << endl;
      return 0;
    }
    cout << ans << ' ' << ans+c << endl;
    return 0;
}

Measured memory_bytes: 256
import sys
sys.setrecursionlimit(2147483647)
INF=float("inf")
MOD=10**9+7
input=sys.stdin.readline
def resolve():
    n=int(input())
    H=list(map(int,input().split()))
    dp=[0]*n
    dp[1]=abs(H[1]-H[0])
    for i in range(2,n):
        dp[i]=min(dp[i-1]+abs(H[i]-H[i-1]),dp[i-2]+abs(H[i]-H[i-2]))
    print(dp[n-1])
resolve()

Measured memory_bytes: 50288
#define _USE_MATH_DEFIMES
#include <algorithm>
#include <array>
#include <bitset>
#include <cassert>
#include <cctype>
#include <climits>
#include <clocale>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <ctime>
#include <deque>
#include <fstream>
#include <functional>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <regex>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <tuple>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>

const int MOD = 1'000'000'007;
const int INF = 1'000'000'000; //1e9
const int NIL = -1;
const long long LINF = 1'000'000'000'000'000'000; // 1e18
const long double EPS = 1E-10;

template<class T, class S> inline bool chmax(T &a, const S &b){
    if(a < b){
        a = b; return true;
    }
    return false;
}
template<class T, class S> inline bool chmin(T &a, const S &b){
    if(b < a){
        a = b; return true;
    }
    return false;
}




long long power(long long a, unsigned long long b, long long m){
    long long ret(1);
    while(b){
        if(b & 1) ret = (ret * a) % m;
        a = (a * a) % m;
        b /= 2;
        if(ret < 0) ret += m;
        if(a < 0) a += m;
    }
    return ret;
}


long long power(long long a, unsigned long long b) {
    return power(a, b, MOD);
}

long long inv(int a, long long m){ // GCD(a, m) = 1
    return power(a, m-2);
}

long long inv(int a){
    return inv(a, MOD);
}

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

int main(){
    int X, N; std::cin >> X >> N;
    std::vector<bool> okay(102, true);
    {
        int p;
        for(int i(0); i < N; ++i){
            std::cin >> p;
            okay[p] = false;
        }
    }
    for(int i(0); i <= 101; ++i){
        if(X >= i){
            if(okay[X-i]){
                std::cout << X - i << std::endl;
                return 0;
            }
        }
        if(X+i <= 101){
            if(okay[X+i]){
                std::cout << X + i << std::endl;
                return 0;
            }
        }
    }
    return 0;
}


Measured memory_bytes: 3592
#include <iostream>
#include <fstream>
#include <sstream>
#include <cstdlib>
#include <iomanip>
#include <string>
#include <cstring>
#include <algorithm>
#include <cmath>
#include <climits>
#include <functional>
/* Data Structure */
#include <vector>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <set>
#include <stack>
#include <queue>

using namespace std;

#define inf 0x3f3f3f3f
#define INF 0x3f3f3f3f3f3f3f3fLL
#define debug cerr << "======= GOT_HERE ======\n"
#define endl "\n"

typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<long long> vll;
typedef map<int,int> mii;
typedef map<long long,long long> mll;
typedef set<int> si;
typedef set<long long> sll;

long long n,k;

int count(int a, int b)
{
	string s = to_string(a), t = to_string(b);
	if(s[0]==t[t.length()-1] && s[s.length()-1]==t[0])
	{
		return 1;
	}
	return 0;
}

int main()
{
	ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
	cin>>n;
	if(n<10)
	{
		cout << n << endl;
	}
	else
	{
		ll h = n;
		n/=10;
		ll ans =  powl(n,2)+8LL;
		for(int i=n*10+1;i<=h;++i)
		{
			for(int j=1;j<=h;++j)
			{
				if(i!=j) ans+=2*count(i,j);
				else ans+=count(i,j);
			}
		}
		cout << ans << endl;

	}
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <climits>
#include <cstdlib>
#include <vector>
using namespace std;
#define ALL(a) (a).begin(),(a).end()
#define FOR(i,a,b) for (int i=(a);i<(b);i++)
#define RFOR(i,a,b) for (int i=(b)-1;i>=(a);i--)
#define REP(i,n) for (int i=0;i<(n);i++)
#define RREP(i,n) for (int i=(n)-1;i>=0;i--)
#define INF (INT_MAX/3)
#define PSB push_back
typedef long long LL;
//#define int long long

//booooooooooooost
/*
#include <boost/multiprecision/cpp_int.hpp>
namespace mp = boost::multiprecision;	//多倍長整数(mp::cpp_int)
*/


signed main() {

	/*int a, b, c;

	cin >> a >> b >> c;

	if ((a == 5 && b == 7 && c == 5) || (a == 7 && b == 5 && c == 5) || (a == 5 && b == 5 && c == 7)) {
		cout << "YES" << endl;
	}
	else {
		cout << "NO" << endl;
	}*/

	int N, L;
	vector<string> s;
	cin >> N >> L;
	REP(i, N) {
		string tmp;
		cin >> tmp;
		s.PSB(tmp);
	}

	sort(ALL(s));
	REP(i, N) cout << s[i];
	cout << endl;

	return 0;
}

Measured memory_bytes: 256
S = input()
T = input()

# 例abcdefg...のように文字列が1対1の矢印関係の場合は、
# どのような場合でも置き換えできる。問題は同じ文字が複数現れる場合

# S上に同じ文字sのある場所には
# T上にも同じ文字tがなくてはならない
# つまり、同じ値になっているインデックスの集合を取れば
# 全部同じになっているはず

# 文字種ごとにインデックスの集合を求める
ns = len(S)
indexS = {}
for i in range(ns):
    s = S[i]
    if s in indexS:
        indexS[s].append(i)
    else:
        indexS[s] = [i]
indexT = {}
for i in range(ns):
    t = T[i]
    if t in indexT:
        indexT[t].append(i)
    else:
        indexT[t] = [i]
# 先頭の文字から、インデックスの集合が等しいかチェック
for i in range(ns):
    s = S[i]
    t = T[i]
    i_s = len(indexS[s])
    i_t = len(indexT[t])
    if i_s != i_t:
        print("No")
        break
else:
    print("Yes")


Measured memory_bytes: 20400
main :: IO ()
main = do
  n <- (read :: String -> Int) <$> getLine
  strs <- getLine
  let answers = solve n $ encode strs
  if null answers then print $ -1
                  else putStrLn.decode.drop 1 $ reverse.drop 1 $head answers
encode :: String -> [Bool]
encode str = map (== 'o') str
 
decode :: [Bool] -> String
decode [] = "-1"
decode bs = map (\b -> if b then 'S' else 'W') bs
 
 
xor :: Bool -> Bool -> Bool
xor a b = (not a && b) || (not b && a)
 
solve :: Int -> [Bool] -> [[Bool]]
solve n input = filter check $ search input [[True, True]
                     ,[True, False]
                     ,[False, True]
                     ,[False, False]]
  where
    search :: [Bool] -> [[Bool]] -> [[Bool]]
    search [] result = result
    search (x:xs) result = search xs $ map next result 
      where
        next :: [Bool] -> [Bool]
        next (s1:s2:s3) = if xor x s1
                          then not s2:s1:s2:s3
                          else s2:s1:s2:s3 
    check :: [Bool] -> Bool
    check bs = and $ zipWith (==) (take 2 bs) (drop n bs)

Measured memory_bytes: 31100
#include <iostream>
#include <map>
#include <vector>
#include <string>
#include <algorithm>
#include <cmath>
#define REP(i, n) for(int i = 0; i < n; ++i)
#define RANGE(i, x, n) for(int i = x; i < n; ++i)

using namespace std;

const int INF = 0x3f3f3f3f;

int main()
{
    int N, M;
    cin >> N >> M;
    vector<int> sx(N, 0);
    vector<int> sy(N, 0);
    REP(i, N) {
        cin >> sx[i] >> sy[i];
    }
    vector<int> cx(M, 0);
    vector<int> cy(M, 0);
    REP(i, M) {
        cin >> cx[i] >> cy[i];
    }
    vector<int> ans(N, 0);
    REP(i, N) {
        int mind = INF, tmp;
        REP(j, M) {
            tmp = abs(cx[j] - sx[i]) + abs(cy[j] - sy[i]);
            if(tmp < mind) {
                mind = tmp;
                ans[i] = j;
            }
        }
    }
    REP(i, N) {
        cout << ans[i] + 1 << endl;
    }
}

Measured memory_bytes: 256
#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+2; i++) {
            for(int j = 0; j < w+2; j++) {
                data.at(i).at(j) = '#';
            }
        }

        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;
        }
}

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

//typedef
//------------------------------------------
typedef int64_t LL;
typedef vector<LL> VL;
typedef vector<VL> VVL;
typedef vector<string> VS;
typedef pair<LL, LL> PLL;

//container util
//------------------------------------------
#define whole(f,x,...) ([&](decltype((x)) whole) { return (f)(begin(whole), end(whole), ## __VA_ARGS__); })(x)
#define rwhole(f,x,...) ([&](decltype((x)) whole) { return (f)(rbegin(whole), rend(whole), ## __VA_ARGS__); })(x)
#define EACH(i,c) for(decltype((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) whole(sort, c)
#define RSORT(c) rwhole(sort, c)

//constant
//--------------------------------------------
constexpr double EPS = 1e-10;
constexpr double PI  = M_PI;
constexpr int MOD = 1000000007;

// grid
//--------------------------------------------
VL dx = {0, 1, 0, -1};
VL dy = {1, 0, -1, 0};
VL dx2 = {-1, 0, 1, -1, 1, -1, 0, 1};
VL dy2 = {-1, -1, -1, 0, 0, 1, 1, 1};

//debug
//--------------------------------------------
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

//IO accelerate
//--------------------------------------------
struct InitIO {
    InitIO() {
        cin.tie(nullptr);
        ios_base::sync_with_stdio(false);
        cout << fixed << setprecision(30);
    }
} init_io;

//template
//--------------------------------------------
template<typename T>
istream& operator >>(istream& is, vector<T>& vec) {
  for(T& x: vec) is >> x;
  return is;
}
template<typename T>
ostream& operator <<(ostream& os, const vector<T>& vec) {
  for(int i=0; i<vec.size(); i++){
    os << vec[i] << ( i+1 == vec.size() ? "" : "\t" );
  }
  return os;
}
template<typename T>
ostream& operator <<(ostream& s, const vector<vector<T>>& vv) {
	for (int i = 0; i < vv.size(); ++i) {
		s << vv[i] << endl;
	}
	return s;
}

// 多重vector
// auto dp=make_v<int>(4,h,w) みたいに使える
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...));
}

// 多重vectorのためのfill
// fill_v(dp,0) みたいに使える
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);
}

template<class T,class U> void chmax(T&a,U b){if(a<b)a=b;}
template<class T,class U> void chmin(T&a,U b){if(b<a)a=b;}
LL gcd(LL a, LL b) { return b?gcd(b,a%b):a;}
LL lcm(LL a, LL b) { return a/gcd(a,b)*b;}

//main code

int main(int argc, char *argv[])
{
	int n,k,x,y;
	cin >> n >> k >> x >> y;
	int ans = 0;
	for (int i = 1; i <= n; i++) {
		if (i > k) {ans += y;}
		else {ans += x;}
	}
	cout << ans << endl;
	return 0;
}


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

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

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


int main(){
    int sx, sy, tx, ty;
    cin >> sx >> sy >> tx >> ty;
    int x = tx - sx;
    int y = ty - sy;
    //往路1
    for(int i=0;i<x;i++)
        cout << 'R';
    for(int i=0;i<y;i++)
        cout << 'U';
    //復路1
    for(int i=0;i<x;i++)
        cout << 'L';
    for(int i=0;i<y;i++)
        cout << 'D';
    //往路2
    cout << 'D';
    for(int i=0;i<x+1;i++)
        cout << 'R';
    for(int i=0;i<y+1;i++)
        cout << 'U';
    cout << 'L';
    //復路2
    cout << 'U';
    for(int i=0;i<x+1;i++)
        cout << 'L';
    for(int i=0;i<y+1;i++)
        cout << 'D';
    cout << 'R';
    cout << endl;
    return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <math.h>
int main(){
	int N,X,x;
	double r=0,h;
	scanf("%d%d",&N,&X);
	for(int i=0;i<N;i++){
		scanf("%d%lf",&x,&h);
		r=fmax(r,h/x);
	}
	printf("%f\n",r*X);
}

Measured memory_bytes: 1820
import sys
import heapq as q

sys.setrecursionlimit(10 ** 8)

n, m, x = [int(i) for i in input().split()]
H = [0] + [int(input()) for i in range(n)]
A = [[int(i) for i in input().split()] for j in range(m)]

INF = 10 ** 16

Q = []
path = [[] for i in range(n+1)]
used = [False] * (n+1)

def bfs():
    q.heappush(Q, (0, 1, x)) #(cost, node, high)
    while Q:
        cost, node, h = q.heappop(Q)
        if node == n:
            if h == H[n]:
                return cost
            q.heappush(Q, (cost+H[n]-h, n, H[n]))
            continue
        if used[node]: continue
        used[node] = True
        for a, t in path[node]:
            if 0 <= h - t <= H[a]:
                q.heappush(Q, (cost+t, a, h-t))
            elif h - t > H[a]:
                q.heappush(Q, (cost+h-H[a], a, H[a]))
            elif H[node] - t >= 0:
                q.heappush(Q, (cost+t-h+t, a, 0))

    return -1
        

for a, b, t in A:
    path[a].append((b, t))
    path[b].append((a, t))

print(bfs())


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

#define ALL(v) v.begin(), v.end()
#define V vector
#define P pair
#define ld long double
#define ll long long
#define IINF INT_MAX
#define INF 1LL << 30

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

    // nが奇数の時は2,5で割れる数はないので末尾の0は必ず0個
    if(n % 2 != 0){
        cout << 0 << endl;
        return 0;
    }

    // 偶数の二乗階乗の場合、結局(n/2)!を5で何回割れるかに帰着
    // 10*8*6*4*2=2^5(5*4*3*2*1)=2^5(5!)
    // min(2で何回割れるか=a, 5で何回割れるか=b)だが、a>=bなのは明らか
    n /= 2;
    ll ans = 0;
    while(n){
        ans += n / 5;
        n /= 5;
    }
    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 3632
import java.util.*;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int x[] = new int[n];
		int tmp[] = new int[n];
		for (int i = 0; i < n; ++i) {
			x[i] = sc.nextInt();
			tmp[i] = x[i];
		}
		sc.close();
		Arrays.sort(tmp);
		int s = n / 2;
		int ans = 0;
		for (int i = 0; i < n; ++i) {
			if (tmp[s - 1] < x[i])
				ans = tmp[s - 1];
			else
				ans = tmp[s];
			System.out.println(ans);
		}
	}

}


Measured memory_bytes: 86960
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef pair<int ,int> pii;
typedef pair<ll ,ll> pll;
#define F first
#define S second
#define pb push_back
#define mp make_pair
#define all(X) (X).begin(), (X).end()
#define sll(n) scanf("%lld",&n)
#define sll2(x,y) scanf("%lld%lld",&x,&y)
#define sll3(x,y,z) scanf("%lld%lld%lld",&x,&y,&z)
#define REP(i,x,y) for(ll i = x;i <= y;++i)
#define debug(x) cerr<<#x<<"::"<<x<<endl
#define debug2(x,y) cerr<<#x<<" :: "<<x<<"\t"<<#y<<" :: "<<y<<"\n"
#define debug3(x,y,z) cerr<<#x<<" :: "<<x<<"\t"<<#y<<" :: "<<y<<"\t"<<#z<<" :: "<<z<<"\n"
#define debug4(x,y,z,w) cerr<<#x<<" :: "<<x<<"\t"<<#y<<" :: "<<y<<"\t"<<#z<<" :: "<<z<<"\t"<<#w<<" :: "<<w<<"\n"
ll power(ll x,ll y,ll z) {
	ll ret = 1;
	while(y > 0) {
		if(y & 1) ret = (ret*x)%z;
		x = (x*x)%z;
		y >>= 1;
	}
	return ret;
}
const ll N = 1e5 + 5;
ll dp[N], A[N];
int main() {
	
	ll n,k;
	sll2(n,k);
	REP(i,1,n) sll(A[i]);
	REP(i,2,n) {
		dp[i] = 1e16;
		for(ll j = i - 1;j >= max(1LL, i - k);--j) {
			dp[i] = min(dp[i], dp[j] + abs(A[j] - A[i]));
		}
	} 
	printf("%lld\n", dp[n]);

	return 0;
}

Measured memory_bytes: 1792
#include <iostream>
#include <cctype>
#include <algorithm>
#include <vector>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <utility>
#include <string>
#include <functional>
#include <cctype>
#include <cstring>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <iomanip>
#define pb push_back 
#define YES cout<<"YES"<<endl
#define Yes cout<<"Yes"<<endl
#define NO cout<<"NO"<<endl
#define No cout<<"No"<<endl
#define INF (1<<30)
#define MOD 1000000007
using namespace std;

int main() {
    int n, ans = 0;
    cin >> n;
    for (int i = 0; i < n; i++) {
        int t;
        cin >> t;
        while (t % 2 == 0) {
            t /= 2;
            ans++;
        }
    }
    cout << ans << endl;
    return 0;
}


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

using namespace std;
#define ll long long int


int main(void) {

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

	ll n, m;
	cin >> n >> m;
	
	n %= m;
	n = (n < abs(n - m)) ? n : abs(n - m);


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

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

const ll MOD=LLONG_MAX;
const int INF=0x3f3f3f3f;
const ll INFL=0x3f3f3f3f3f3f3f3f;

ll ppow(ll a,ll b){
	a%=MOD;
	ll res=1;
	while(b){
		if(b&1)res=(res*a)%MOD;
		a=(a*a)%MOD;
		b>>=1;
	}
	return res;
}

int main(){
	ll x;cin>>x;
	vector<pair<ll,ll>>v,u;
	v.push_back({0,0});
	for(ll i=1;;i++){
		ll x=ppow(i,5);
		if(!v.empty()&&x-v.back().second>1e9){
			break;
		}
		v.push_back({i,ppow(i,5)});
	}
	u=v;
	for(auto p:u){
		v.push_back({-p.first,-p.second});
	}
	rep(i,v.size())rep(j,v.size()){
		if(v[i].second-v[j].second==x){
			cout<<v[i].first<<' '<<v[j].first<<endl;
			return 0;
		}
	}
}

Measured memory_bytes: 3640
#include<cstdio>
#define ll long long
int main()
{
    ll a,b;
    int k;
    scanf("%lld%lld%d",&a,&b,&k);
    for(int i=0; i<k; i++)
    {
        if(i%2==0)
        {
            if(a%2==1)
            {
                a--;
                b+=a/2;
                a/=2;
            }
            else
            {
                b+=a/2;
                a/=2;
            }
        }
        else
        {
            if(b%2==1)
            {
                b--;
                a+=b/2;
                b/=2;
            }
            else
            {
                a+=b/2;
                b/=2;
            }
        }
    }
    printf("%lld %lld\n",a,b);
    return 0;
}


Measured memory_bytes: 128
N, M = map(int, input().split())
ans = [-1]*N
for i in range(M):
    s, c = map(int, input().split())
    if ans[s-1] == -1:
        ans[s-1] = c
    elif ans[s-1] != c:
        print(-1)
        exit()
if N == 1:
    if ans[0] == -1:
        print(0)
    else:
        print(int(''.join(map(str,ans))))
else:
    if ans[0] == 0:
        print(-1)
        exit()
    elif ans[0] == -1:
        ans[0] = 1
    for i in range(N):
        if ans[i] == -1:
            ans[i] = 0
    print(int(''.join(map(str,ans))))

Measured memory_bytes: 3064
#include <iostream>
#include <string>
#include <cstdlib>
#include <cmath>
#include <vector>
#include <map>
#include <set>
#include <algorithm>
#include <queue>
#include <stack>
#include <functional>
#include <bitset>
#include <assert.h>
using namespace std;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<char> vc;
typedef vector<string> vs;
typedef vector<bool> vb;
typedef vector<double> vd;
typedef pair<ll,ll> P;
typedef vector<P> vpl;
typedef tuple<ll,ll,ll> tapu;
#define rep(i,n) for(ll i=0; i<(n); i++)
#define REP(i,a,b) for(int i=(a); i<(b); i++)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
const int inf = 1<<30;
const ll linf = 1LL<<62;
const int MAX = 510000;
ll dy[8] = {0,1,0,-1,1,-1,1,-1};
ll dx[8] = {1,0,-1,0,1,-1,-1,1};
const double pi = acos(-1);
const double eps = 1e-7;
template<typename T1,typename T2> inline bool chmin(T1 &a,T2 b){
	if(a>b){
		a = b; return true;
	}
	else return false;
}
template<typename T1,typename T2> inline bool chmax(T1 &a,T2 b){
	if(a<b){
		a = b; return true;
	}
	else return false;
}
template<typename T1,typename T2> inline void print2(T1 a, T2 b){cout << a << " " << b << "\n";}
template<typename T1,typename T2,typename T3> inline void print3(T1 a, T2 b, T3 c){
	cout << a << " " << b << " " << c << "\n";
}
const int mod = 1e9 + 7;
//const int mod = 998244353;

int main(){
	ll n,m; cin >> n >> m;
	vl a(n); rep(i,n) cin >> a[i];
	sort(all(a));
	vl sum(n+1,0);
	rep(i,n) sum[i+1] = sum[i] + a[i];
	ll prev;
	ll ok = 0, ng = 1e6;
	while(ng-ok > 1){
		ll mid = (ng+ok)/2;
		ll cnt = 0;
		rep(i,n){
			auto itr = lower_bound(all(a),mid-a[i]);
			cnt += a.end() - itr;
		}
		if(cnt >= m){
			ok = mid;
		}
		else{
			ng = mid;
			prev = mid;
		}
	}
	ll ans = 0;
	ll cnt = 0;
	rep(i,n){
		ll d = a.end() - lower_bound(all(a),ok-a[i]);
		ans += d * a[i] + sum[n] - sum[n-d];
		cnt += d;
	}
	cout << ans + ok * (m-cnt) << endl;
}

Measured memory_bytes: 1792
require 'set'

class Hash
  def push(key, value)
    self[key] = [] if self[key] == nil
    self[key].push(value)
  end
end

def get_ints
  gets.split.map(&:to_i)
end

def get_ints_minus_one
  get_ints.map { |x| x - 1 }
end

def get_int
  gets.chomp.to_i
end

N, K = get_ints
D = []
A = Array.new(K) { [] }
K.times do |i|
  D[i] = get_int
  A[i] = get_ints
end

sunukes = Array.new(N) { false }

K.times do |i|
  A[i].each do |x|
    sunukes[x-1] = true
  end
end

puts sunukes.count { |x| !x }


Measured memory_bytes: 14524
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main{
	public static void main(String[] args)throws IOException{
		InputStreamReader isr = new InputStreamReader(System.in);
		BufferedReader reader = new BufferedReader(isr);
		String string;
		double x, q;
		
		while(!(string = reader.readLine()).equals("-1")){
			q = Double.valueOf(string);
			x = q / 2.0;
			while(true){
				x -= (x * x * x - q) / (3 * x * x);
				if(Math.abs(x * x * x - q) < .00001 * q) break;
			}
			System.out.printf("%.6f\n", x);
		}	
		reader.close();
	}
}

Measured memory_bytes: 24672
#include<iostream>
#include<cstddef>
#include<cstdint>
#include<vector>
#include<algorithm>
#include<set>
using usize=std::size_t;
using i64 = std::int_fast64_t;

int main(){
  usize n;
  std::cin>>n;
  std::set<i64> a;
  for(usize i=0;i<n;++i){
    i64 t;
    std::cin>>t;
    a.insert(t);
  }
  std::cout<<a.size()<<std::endl;
}



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

int main(){
    string s,t,u;
    int a,b;
    
    cin>>s>>t;
    cin>>a>>b;
    cin>>u;
    
    if (s == u) {
        a--;
    }
    else{
        b--;
    }
    cout<<a<<" "<<b;
    return 0;
    
}

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

int main() {
  string s;
  cin >> s;

  int tmp = 0;
  for (int i = 0; i < s.size(); i++) {
    if (s[i] == '0') {
      tmp++;
    }
  }

  int ans;
  if (tmp <= s.size() / 2) {
    ans = tmp * 2;
  }
  else {
    ans = (s.size() - tmp) * 2;
  }

  cout << ans << endl;
}

Measured memory_bytes: 512
use std::io::*;
use std::str::FromStr;

fn read<T: FromStr>() -> T {
  let stdin = stdin();
  let stdin = stdin.lock();
  let token: String = stdin
    .bytes()
    .map(|c| c.expect("failed to read char") as char)
    .skip_while(|c| c.is_whitespace())
    .take_while(|c| !c.is_whitespace())
    .collect();
  token.parse().ok().expect("failed to parse token")
}

fn tast(l: i64, i: i64) -> i64 {
  l + i -1
}

fn get_close_0(a: i64, b: i64) -> i64 {
  if a.abs() > b.abs() {
    b
  } else {
    a
  }
}

fn main() {
  let n = read::<i64>();
  let l = read::<i64>();

  let mut sum = 0;
  let mut close_0 = tast(l, 1);

  for i in 1..n+1 {
    let add_num = tast(l, i);
    sum += add_num;
    close_0 = get_close_0(add_num, close_0);
  }
  println!("{}", sum - close_0);
}


Measured memory_bytes: 4352
#include <bits/stdc++.h>
using namespace std;
 
typedef long long ll;
typedef pair<int,int> P;
 
const int INF = 1e9;
const int mod = 1e9+7;
const double EPS = 1e-10;
const double PI = acos(-1.0);


int main()
{
    string s;
    cin >> s;
    for(int i = 0; i < s.size(); i++){
        cout << (s[i] == '1' ? 9 : 1);
    }
    cout << endl;
    return 0;
}

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


using namespace std;


int main(){
    int a[32] = {1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51};
    int k;
    cin >> k;
    cout<<a[k-1]<<endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0, i##_len = (n); i < i##_len; ++i)
#define rep2(i, x, n) for(int i = x, i##_len = (n); i < i##_len; ++i)
#define all(n) begin(n), end(n)
using ll = long long;
using P = pair<int, int>;
using vi = vector<int>;
using vl = vector<ll>;
using vs = vector<string>;
using vc = vector<char>;
using vb = vector<bool>;
using vd = vector<double>;
vi dir = {-1, 0, 1, 0, -1, -1, 1, 1, -1};

int main() {
  int n, m;
  cin >> n >> m;
  cout << (n - 1) * (m - 1) << endl;
}

Measured memory_bytes: 256
n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
k = 0
for i in range(n):
    if a[i] > b[i]:
        k += b[i]
    elif a[i] + a[i+1] < b[i]:
        k += a[i] + a[i+1]
        a[i+1] = 0
    else:
        a[i+1] = a[i+1] + a[i] - b[i]
        k += b[i]
print(k)

Measured memory_bytes: 82020