akhauriyash/Code-Regression huggingface dataset:
from sys import setrecursionlimit, stdin


def find(parent, i):
    t = parent[i]
    if t < 0:
        return i
    t = find(parent, t)
    parent[i] = t
    return t


def unite(parent, i, j):
    i = find(parent, i)
    j = find(parent, j)
    if i == j:
        return
    parent[j] += parent[i]
    parent[i] = j


readline = stdin.readline
setrecursionlimit(10 ** 6)

N, M = map(int, readline().split())

parent = [-1] * N
for _ in range(M):
    A, B = map(lambda x: int(x) - 1, readline().split())
    unite(parent, A, B)

print(sum(1 for i in range(N) if parent[i] < 0) - 1)


Measured memory_bytes: 10900
#include <bits/stdc++.h>
typedef long long ll;
#define forn(i, start, end) for (ll i = start; i < ll(end); i++)
#define input(arr, n) forn(i, 0, n) cin >> arr[i];
#define MOD 1000000007
#define vll vector<ll>
#define vpll vector<pair<ll,ll>>
#define vvll vector<vector<ll>>
#define mll map<ll, ll>
#define mcl map<char, ll>
#define sc set<char>
#define sll set<ll>
#define ssll stack<ll>
#define CHK(param) cout << #param << " is : " << param << "\n";
#define pb push_back
#define ppb pop_back
#define mk make_pair
#define f first
#define s second
#define all(x) (x).begin(), (x).end()
#define LAUV                          \
    ios_base::sync_with_stdio(false); \
    cin.tie(NULL);
#define TC       \
    ll TTTT;     \
    cin >> TTTT; \
    while (TTTT--)
using namespace std;

int32_t main()
{
    LAUV;
    {
        char c;cin>>c;if(c>='a' and c<='z')cout<<"a\n";
        else cout<<"A\n";
    }
    return 0;
}

Measured memory_bytes: 3556
#include <bits/stdc++.h>
typedef long long int lint;

#define PI acos(-1)
#define INF64 1LL << 60
#define INF32 1 << 29
#define all(a) (a).begin(), (a).end()
#define INV ((long long int)1000000007)

using namespace std;

void execute()
{
	int N, M;
	string input;
	cin >> N >> M;
	cin >> input;
	for (int i = 0; i < N; i++)
	{
		if (input[i] < '0' || '9' < input[i])
		{
			cout << "No" << endl;
			return;
		}
	}

	if (input[N] != '-')
	{
		cout << "No" << endl;
		return;
	}

	for (int i = N + 1; i < N + M + 1; i++)
	{
		if (input[i] < '0' || '9' < input[i])
		{
			cout << "No" << endl;
			return;
		}
	}
	cout << "Yes" << endl;

	return;
}

int main()
{
	cin.tie(0);
	ios_base::sync_with_stdio(false);
	std::cout << std::fixed << std::setprecision(15);
	execute();

	int stop;
	cin >> stop;

	return 0;
}

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

int sortfnc(const void *a,const void *b){
    if(*(long long*)a == *(long long*)b){return 0;}
    if(*(long long*)a > *(long long*)b){return -1;}
    return 1;
}

int main(void){
	long long i,j,n,k,a[8192],sum=0,jud,dp[8192];
	long long s,f,mem;
	scanf("%lld%lld",&n,&k);
	for(i = 0;i < n;i++){scanf("%lld",&a[i]);sum+=a[i];}
	if(sum < k){printf("%d\n",n);return 0;}
	if(sum == k){printf("0\n");return 0;}
	qsort(a,n,sizeof(long long),sortfnc);
	s = 0;f = n-1;
	while(s<=f){
		jud = (s+f)/2;
		if(a[jud] >= k){s = jud+1;continue;}
		for(i = 0;i <= 8191;i++){dp[i] = 0;}
		for(i = 0;i < n;i++){
			mem = a[i];
			if(i == jud){continue;}
			if(mem >= k){continue;}
			for(j = k-1;j > 0;j--){
				if(dp[j] == 1){
					if(j+mem < k){dp[j+mem] = 1;}
				}
			}
			dp[mem] = 1;
		}
		mem = a[jud];
		for(i = k-1;i >= k-mem;i--){
			if(dp[i] == 1){s = jud+1;break;}
			if(i == k-mem){f = jud-1;break;}
		}
	}
	printf("%d\n",n-s);
	return 0;
}

Measured memory_bytes: 380
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using vi=vector<int>;
using vvi=vector<vi>;
using pii=pair<int,int>;
const ll LINF=0x1fffffffffffffff;
const int INF=0x3fffffff;
const int MOD=1000000007;
#define VAR(type,...) type __VA_ARGS__;in(__VA_ARGS__)
#define VEC(type,name,size) vector<type> name(size);each(x, name)in(x)
#define rep(i,a,b) for(int i=(a);i<(b);++i)
#define rrep(i,a,b) for(int i=(a-1);i>=(b);--i)
#define each(x,v) for(auto &x:(v))
#define all(x) (x).begin(),(x).end()
#define print(x) cout<<(x)<<endl
void in(){} template<class T,class... U> void in(T &t,U &...u){cin>>t;in(u...);}
void solve();
int main(){cin.tie(0);ios::sync_with_stdio(0);solve();}

void solve() {
  VAR(int, n);
  VEC(string, s, n);
  map<char, int> m;

  each(x, s[0]) {
    m[x]++;
  }

  rep(i, 1, n) {
    map<char, int> tmp;
    each(x, s[i]) {
      tmp[x]++;
    }
    each(x, m) {
      m[x.first] = min(x.second, tmp[x.first]);
    }
  }

  string ans = "";

  each(x, m) {
    while(x.second--) ans += x.first;
  }

  print(ans);
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <numeric>
#include <map>
#include <iomanip>
#include <limits.h>
#include <queue>

using namespace std;    
typedef long long ll;
typedef pair<ll, ll> pll;
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
const bool DEBUG = false;

int head( int n ){
    while(n >= 10){
        n /= 10;
    }
    return n;
}

int tail(int n){
    return n % 10;
}



int main(){

    ll n;
    cin >> n;


    ll v[10][10];
    for(int i = 0; i <= 9; i++){
        for(int j = 0; j <= 9; j++){
            v[i][j] = 0;
        }
    }

    for(int i = 1; i <= n; i++){
        int h = head(i);
        int t = tail(i);
        /*
        if(h < 0 || h >= 10 || t < 0 || t >= 10){
            cout << h << " " << t << endl;
            cout << "ERROR" << endl;
        } 
        */
        v[h][t] ++;
    }


    ll ans = 0;
    for(int i = 1; i <= 9; i++){
        for(int j = 1; j <= 9; j++){
            ans += (v[i][j] * v[j][i] );
        }
    }
    cout << ans << endl;



}

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

#define mp       make_pair
#define mt	 make_tuple
#define pb       push_back
#define rep(i,n) for(int i=0;i<(n);i++)

using namespace std;

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

const int INF=1<<29;
const double EPS=1e-9;
const int MOD = 100000007;

const int dx[]={1,0,-1,0},dy[]={0,-1,0,1};
int N,W;
int v[1010];
int w[1010];
int dp[1010][10010];
int memo(int pos, int sum){
  //cout << pos << " " << sum << endl;
  if (pos >= N){
    return 0;
  }
  // if (sum > W){
  //   return 0;
  // }

  if (dp[pos][sum] >= 0){
    return dp[pos][sum];
  }
  int res = 0;
  if (sum + w[pos] <= W){
    res = max(res, memo(pos, sum + w[pos]) + v[pos]);
    res = max(res, memo(pos + 1, sum + w[pos]) + v[pos]);
  }
  res = max(res, memo(pos + 1, sum));
  dp[pos][sum] = res;
  return res;
}
int main(){
  cin >> N >> W;
  memset(dp, -1, sizeof(dp));
  for (int i = 0; i < N; i++){
    cin >> v[i] >> w[i];
  }
  cout << memo(0, 0) << endl;
}

Measured memory_bytes: 41136
#include <stdio.h>
#include <string.h>

int main()
{
    char s[500];
    char sub1[200];
    int m, h;
    int i, j;
    while (1)
    {
        for (int i = 0; i < 500; i++)
        {
            s[i] = 0;
        }
        scanf("%s", s);
        int len = strlen(s);
        if (strcmp(s, "-") == 0)
        {
            break;
        }
        scanf("%d", &m);
        for (int x = 0; x < m; x++)
        {
            for (int j = 0; j < 200; j++)
            {
                sub1[j] = 0;
            }
            scanf("%d", &h);
            for (i = 0; i < h; i++)
            {
                sub1[i] = s[i];
            }
            for (i = 0; i < len - h; i++)
            {
                s[i] = s[h + i];
            }
            s[len - h] = '\0';
            strcat(s, sub1);
        }
        printf("%s\n", s);
    }
}


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

int main(){
    //FILE *inp = freopen("in.txt", "r", stdin);
    int n, q, key;
    scanf("%d", &n);
    long arr[n];
    for(int i = 0; i < n; ++i) scanf("%ld", &arr[i]);
    scanf("%d", &q);
    int cnt = 0;
    for(int i = 0; i < q; ++i){
        scanf("%ld", &key);
        int low, mid, high;
        low = 0;
        high = n-1;
        while(low <= high){
            mid = low + (high-low)/2;
            if(arr[mid]==key){
                cnt++;
                break;
            }
            else if(arr[mid]<key) low = mid+1;
            else high = mid-1;
        }
    }
    printf("%d\n", cnt);
    //fclose(inp);
    return 0;
}

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

int main(void) {
	string S, T;
	cin >> S >> T;
	int A, B;
	cin >> A >> B; 
	string U;
	cin >> U;





	if (S == U) {
		A -= 1;
	}
	else {
		B -= 1;
	}

	cout << A << " "<< B << endl;
}

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

int N, M;
vector<int> p, back, cmp;

int find_cmp(int a){
  if(cmp[a] != a)
    cmp[a] = find_cmp(cmp[a]);
  return cmp[a];
}

void merge(int a, int b){
  cmp[find_cmp(a)] = find_cmp(b);
}

int main(){
  cin >> N >> M;
  p.resize(N);
  back.resize(N);
  for(int i=0; i<N; i++){
    cin >> p[i];
    p[i]--;
    back[p[i]] = i;
  }

  cmp.resize(N);
  iota(cmp.begin(), cmp.end(), 0);
  for(int i=0; i<M; i++){
    int a, b;
    cin >> a >> b;
    a--; b--;
    merge(a, b);
  }

  int res = 0;
  for(int i=0; i<N; i++){
    if(find_cmp(i) == find_cmp(back[i])){
      res++;
    }
  }
  cout << res << endl;

  return 0;
}

Measured memory_bytes: 1408
import java.util.Scanner;

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

		int r = Integer.parseInt(sc.next());

		if (r < 1200){
			System.out.println("ABC");
		}else if (r < 2800){
			System.out.println("ARC");
		}else {
			System.out.println("AGC");
		}
	}
}


Measured memory_bytes: 22484
#include<iostream>
#include<string>
#include<algorithm>
#include<stdio.h>
#include<math.h>
#define FOR(i, a, b) for(int i=(a);i<=(b);i++)
#define RFOR(i, a, b) for(int i=(a);i>(b);i--)
using namespace std;
 
int main(void) {
	long long int x, t;
	cin >> x >> t;
	if (x - t < 0) {
		cout << 0 << endl;
	}
	else {
		cout << x - t << endl;
	}
	
 
 
	return 0;
}

Measured memory_bytes: 256
#include <stdio.h>

int main(void)
{
	long i, N, k, small, x, y;
	
	scanf("%ld", &N);
	scanf("%ld", &k);
	
	for (i = 0; i < k; i++){
		scanf("%ld %ld", &x, &y);
		
		small = x - 1;
		if (small > N - x){
			small = N - x;
		}
		if (small > y - 1){
			small = y - 1;
		}
		if (small > N - y){
			small = N - y;
		} 
		
		printf("%ld\n", small % 3 + 1);
	}
	
	return 0;
}

Measured memory_bytes: 596
#include <iostream>
#include <iomanip>
#include <cmath>
#include <queue>
#include <map>
#include <cstdlib>
#include <algorithm>
#include <utility>
#include <queue>
#include <string>
#include <functional>
#define rep(i, a, b) for(int i=a;i<b;++i)
#define MOD 1000000007
#define N 100
#define RAND 1000
using namespace std;

int main(void)
{
	int a, b, c, cnt = 0;
	cin >> a >> b >> c;
	for (int i = a; cnt < 10000; i += a, ++cnt) {
		if (i % b == c) {
			cout << "YES" << endl;
			return 0;
		}
	}
	cout << "NO" << endl;

	return 0;
}

Measured memory_bytes: 256
#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 FDS(i, n) for(int i = 0; i < n; ++i)
#define FDSR(i, n) for(int i = n; i >= 0; ++i)
#define FOR(i, m, n) for(int i = m; i < n; ++i)
#define FORR(i, m, n) for(int i = m;i >= n;--i)
#define VSORT(v) sort(v.begin(), v.end());
#define INF 999999999
#define itn int
#define ednl endl
using namespace std;
typedef long long ll;
int main(){
	int N;
	cin>>N;
	vector<ll> v(N);
	vector<ll> t(N);
	FDS(i,N){
		cin>>v[i];
		t[i]=v[i];
	}
	VSORT(v);
	int a,b;
	a=v[N/2-1];
	b=v[(N/2)];
	FDS(i,N){
		if(t[i]>=b){
			cout<<a<<endl;
			continue;
		}
		if(t[i]<=a){
		    cout<<b<<endl;
		}
	}
}

Measured memory_bytes: 5376
#include <bits/stdc++.h>
using namespace std;
#define ll long long int
#define ul unsigned long int
#define ld long double
#define f(t) for(ll i =0;i<t;i++)
#define vi vector<int>
#define vl vector<ll>
#define pri pair<int,int>
#define mpi map<int,int>
#define prl pair<ll,ll>
#define mp make_pair
#define mpl map<ll,ll>
#define umpl unordered_map<ll,ll>
#define pb push_back
#define ff first
#define ss second
#define MOD 1000000007
#define inf 2e18
#define EPS 1e-3
#define PI 3.1415926535897932385
const double h = 1e-6;
const int MAX_  = 100005;
#define display(v) f(v.size())cout << v[i] << " "
#define all(v) v.begin(),v.end()

inline ll mul(ll a, ll b){ return (a * 1ll * b) % MOD; }
inline ll sub(ll a, ll b){ ll c = a - b; if(c < 0) c += MOD; return c; }
inline ll add(ll a, ll b){ ll c = a + b; if(c > MOD) c -= MOD; return c; }
 //////////////////////*********CODE***********/////////////////////
 //////////////////////////////////////////////////////////////////

int main()
{
   ios_base::sync_with_stdio(false);
   cin.tie(NULL);
   cout.tie(NULL);
   int k;  cin>>k;  queue<ll> q;
   f(9)q.push(i+1);
   int c = 0;
   ll x;
   while(1)
   {
       x = q.front();  q.pop(); c++;
       if(c==k)break;
      ll mo = x%10;
      ll val = 10*x + mo  ;  
      if(mo != 0)q.push(val-1);
      q.push(val);
      if(mo != 9)q.push(val+1);
   }
   cout << x;
   return 0;
}     

Measured memory_bytes: 1792
#include <bits/stdc++.h>
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define FORR(i, m, n) for(int i = m;i >= n;i--)
#define SORT(v, n) sort(v, v+n);
#define SORTR(v,n) sort(v, v+n, greater<int>());
// #define int long long    // %d=>%lld
#define pb push_back
#define INF (1e9+7)
#define llINF 1e17
#define EPS 1e-9
#define pi acos(-1)

using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<int, pii> piii;
typedef pair<ll, pll> plll;

int H,W,h,w;



signed main(){
    cin >> H>>W>>h>>w;

    if(H%h == 0 && W%w == 0){
        cout << "No"<< endl;
        return 0;
    }

    cout << "Yes"<< endl;

    for(int i = 0;i < H;i++){
        for(int j = 0;j < W;j++){
            if(i%h == 0 && j%w == 0)
                printf("%d ", 100000000-1);
            else if(i%h == h-1 && j%w == w-1)
                printf("%d ", -100000000);
            else
                printf("%d ", 0);
        }
        printf("\n");
    }
    return 0;
}

Measured memory_bytes: 2688
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define FOR(i,a,b) for(int i=(a); i<=(b); i++) 
#define rep(i,n); for(int i = 0; i < (n); i++)
#define chmin(a,b) if((a)>(b)) (a)=(b); 
#define chmax(a,b) if((a)<(b)) (a)=(b);
#define vi vector<int>
#define all(v) (v).begin(),(v).end()
#define pb push_back
int gcd(int a,int b){/*a>=0,b>=0,￢(a=b=0)*/
  while(min(a,b)>0){if(a<b)swap(a,b);a%=b;}return max(a,b);
}
int dx[]={0,1,0,-1,1,-1,-1,1};
int dy[]={1,0,-1,0,1,1,-1,-1};
const int MOD = 1e9+7;
const int INF = 1e18+10;

/*----------------------------------------------*/
signed main(){
  int n,k;
  cin>>n>>k;
  n%=k;
  chmin(n,abs(n-k));
  cout<<n<<endl;
  return 0;
}


Measured memory_bytes: 256
unittest
{
	assert( [ "3", "1 2 3" ].parse.expand.solve == 1 );
	assert( [ "4", "2 5 2 5" ].parse.expand.solve == 0 );
}



import std.algorithm;
import std.conv;
import std.math;
import std.range;
import std.stdio;
import std.typecons;

void main()
{
	stdin.byLineCopy.parse.expand.solve.writeln;
}

auto parse( Range )( Range input )
if( isInputRange!Range && is( ElementType!Range == string ) )
{
	input.popFront;
	auto as = input.front.split.to!( long[] );
	return tuple( as );
}

auto solve( long[] as )
{
	auto m = as.sum;		// 割って平均値にすると誤差が出るので割らない
	auto d = long.max;
	auto ans = 0L;
	foreach( i, a; as )
	{
		auto d2 = abs( m - a * as.length.signed );		// mを割らない代わりにaを掛ける
		if( d <= d2 ) continue;
		d = d2;
		ans = i;
	}
	return ans;
}


Measured memory_bytes: 256
from collections import deque

s=input()
query=int(input())

li_q = []
for _ in range(query):
    li_q.append(input().split())

rev = False
q_str = deque([s])
for q in li_q:
    if q[0] == '1':
        rev = not rev
    else:
        if q[1] == '1':
            if rev:
                q_str.append(q[2])
            else:
                q_str.appendleft(q[2])
        else:
            if rev:
                q_str.appendleft(q[2])
            else:
                q_str.append(q[2])

li_str = list(q_str)
ans = ''.join(li_str)
if rev:
    ans = ans[::-1]
    
print(ans)

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

using namespace std;

#define rep(i,m,n) for(int (i)=(int)(m);i<(int)(n);i++)
#define rep2(i,m,n) for(int (i)=(int)(n)-1;i>=(int)(m);i--)
#define REP(i,n) rep(i,0,n)
#define REP2(i,n) rep2(i,0,n)
#define FOR(i,c) for(decltype((c).begin())i=(c).begin();i!=(c).end();++i)
#define ll long long
#define ull unsigned long long
#define all(hoge) (hoge).begin(),(hoge).end()
#define en '\n'
template <class T> using vec = vector<T>;
template <class T> using vvec = vector<vec<T>>;
typedef pair<ll, ll> P;
constexpr long long INF = 1LL << 60;
constexpr int INF_INT = 1 << 25;
constexpr long long MOD = (ll) 1e9 + 7;
typedef vector<ll> Array;
typedef vector<Array> Matrix;
constexpr int loose = 0;
constexpr int tight = 1;


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

struct Edge {
	ll to, cap, rev;
	Edge(ll _to, ll _cap, ll _rev) {
	to = _to; cap = _cap; rev = _rev;
	}
};
typedef vector<Edge> Edges;
typedef vector<Edges> Graph;

void add_edge(Graph& G, ll from, ll to, ll cap, bool revFlag, ll revCap) {
	G[from].push_back(Edge(to, cap, (ll)G[to].size()));
	if (revFlag)G[to].push_back(Edge(from, revCap, (ll)G[from].size() - 1));
}

void solve(){
	ll n;
	cin>>n;
	Array h(n);
	REP(i,n) cin>>h[i];
	
	Array dp(n+1,INF);
	dp[0]=0;
	REP(i,n){
		chmin(dp[i+1],dp[i]+abs(h[i]-h[i+1]));
		chmin(dp[i+2],dp[i]+abs(h[i]-h[i+2]));
	}
	cout<<dp[n-1]<<en;
}

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

    solve();
    return 0;
}

Measured memory_bytes: 1792
#include <iostream>
#include <iomanip>
#include <cmath>
#include <vector>
#include <algorithm>
#include <set>
#include <unordered_set>
#include <queue>
#include <stack>
#include <map>
#include <unordered_map>
#define rep(i, n) for (int i = 0; i < n; i++)
#define ALL(a) (a).begin(), (a).end()
typedef long long ll;
using namespace std;
const int N = 2e5 + 5;

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

    char c[h][w];
    for (int i = 0; i < h; ++i)
    {
        for (int j = 0; j < w; ++j)
        {
            cin >> c[i][j];
        }
    }
    int ans = 0;
    for (int maskR = 0; maskR < (1 << h); ++maskR)
    {
        for (int maskC = 0; maskC < (1 << w); ++maskC)
        {
            int ct = 0;
            for (int k = 0; k < h; ++k)
            {
                for (int l = 0; l < w; ++l)
                {
                    if ((maskR & (1 << k)) == 0 && (maskC & (1 << l)) == 0 && c[k][l] == '#')
                    {
                        ++ct;
                    }
                }
            }
            if (ct == k)
            {
                ans++;
            }
        }
    }
    cout << ans << endl;
}


Measured memory_bytes: 3640
import itertools
from collections import Counter
from math import factorial

N = int(input())


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

    if temp != 1:
        arr[temp] = 1

    if not arr and n != 1:
        arr[n] = 1

    return arr


ans = 0
ct = Counter()
for i in range(2, N + 1):
    ct += Counter(factorization(i))


def solve(*exps):
    ret = 0
    for t in itertools.permutations(ct.values(), len(exps)):
        if all(t[i] - exps[i] >= 0 for i in range(len(exps))):
            ret += 1
    for x in Counter(exps).values():
        ret //= factorial(x)
    return ret


print(solve(2, 4, 4) + solve(14, 4) + solve(24, 2) + solve(74))


Measured memory_bytes: 3316
#include <bits/stdc++.h>
#include <boost/multiprecision/cpp_dec_float.hpp>

int main(){
    using namespace std;
    unsigned long N;
    cin >> N;
    vector<pair<long, long>> eng(N);
    for(auto& i : eng)cin >> i.first >> i.second;
    auto d = static_cast<unsigned long>(partition(eng.begin(), eng.end(), [](auto i){return i.first == 0 ? i.second > 0 : i.first > 0;}) - eng.begin());
    for(unsigned long i = 0; i < N; ++i)eng.emplace_back(-eng[i].first, -eng[i].second);
    for(unsigned long i = 0; i < d; ++i)eng.emplace_back(eng[i].first, eng[i].second);
    auto cmp = [](auto i, auto j){return i.first * j.second > i.second * j.first;};
    sort(eng.begin(), eng.begin() + d, cmp);
    sort(eng.begin() + d, eng.begin() + d + N, cmp);
    sort(eng.begin() + d + N, eng.end(), cmp);
    long a{0}, b{0};
    unsigned long ans{0};
    for(unsigned long i = 0; i < 2 * N + d; ++i){
        a += eng[i].first;
        b += eng[i].second;
        ans = max<unsigned long>(ans, a * a + b * b);
    }
    boost::multiprecision::cpp_dec_float_100 t(ans), k(boost::multiprecision::sqrt(t));
    cout << k.str() << endl;
    return 0;
}

Measured memory_bytes: 256
#include<cstdio>

int main() {
    int a, b, d, r;
    double f;
    scanf("%d %d", &a, &b);

    d = a / b;
    r = a % b;
    f = (double)a / (double)b;

    printf("%d %d %1f\n", d, r, f);
    // cout << d << " " << r << " " << f << "\n";
    return 0;
}


Measured memory_bytes: 2748
//g++ -std=gnu++14 a.cpp

#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <iostream>
#include <istream>
#include <iterator>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
#include <tuple>
#include <iomanip>
#include <random>
#include <math.h>
//#include <ostream>


using namespace std;

#define ll long long
#define rep(i, n) for(ll i = 0; i < (n); i++)
ll MOD = 1e9 + 7;
int INF = 1 << 30;
ll INFL = 1LL << 60;

int main(){
  ll N,M;
  cin >> N >> M;
  vector<int> H(N);
  rep(i,N)cin >> H[i];
  vector<int> A(M);
  vector<int> B(M);
  rep(i,M)cin >> A[i] >> B[i];

  vector<vector<ll>> data(N+10);
  rep(i,M){
    data[A[i]].push_back(B[i]);
    data[B[i]].push_back(A[i]);
  }
  ll ans = 0;
  for(int i = 1;i <= N;i++){
    if(data.at(i).size()==0){
      ans++;
      continue;
    }
    bool hantei = true;
    rep(j,data.at(i).size()){
      if(H[i-1] <= H[data[i][j]-1]) hantei = false;
    }
    if(hantei){
      ans++;
      //cout << i << "!" << endl;
    }
  }

  cout << ans << endl;

 }


Measured memory_bytes: 10388
#include <iostream>
#include <vector>
#define rep(i, n) for(int i = 0; i < (int)(n); ++i)
#define REP(i, n) for(int i = 1; i < (int)(n); ++i)
using namespace std;

int main() {
    int N;
    cin >> N;
    vector<int> V(N), C(N);
    rep(i, N) cin >> V[i];
    rep(i, N) cin >> C[i];
    
    int ans = -1000000000;
    for (int bit = 0; bit < (1 << N); ++bit) {
        vector<int> S;
        rep(i, N) {
            if (bit & (1 << i)) S.push_back(i);
        }
        int X = 0;
        int Y = 0;
        for (int i : S) {
            X += V[i];
            Y += C[i];
        }
        ans = max(ans, X - Y);
    }
    cout << ans << endl;
    return 0;
}


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

using namespace std;

int m, n;

int search(int x, int y, bool map[100][100]){
	if(x < 0 || y < 0 || x >= n || y >= m){
		return 0;
	}
	if(!map[x][y]){
		return 0;
	}
	map[x][y] = false;
	int ans = 0;
	int ans1, ans2, ans3, ans4;
	ans1 = search(x - 1, y, map);
	ans2 = search(x + 1, y, map);
	ans3 = search(x, y - 1, map);
	ans4 = search(x, y + 1, map);
	if(ans1 > ans){
		ans = ans1;
	}
	if(ans2 > ans){
		ans = ans2;
	}
	if(ans3 > ans){
		ans = ans3;
	}
	if(ans4 > ans){
		ans = ans4;
	}
	map[x][y] = true;
	return ans + 1;
}

int main(){
	
	int ans, d;
	
	bool map[100][100];

	while(true){
		cin >> m >> n;
		if(m == 0 && n == 0){
			break;
		}
		for(int i = 0; i < n; i++){
			for(int j = 0; j < m; j++){
				cin >> d;
				if(d == 0){
					map[i][j] = false;
				}else{
					map[i][j] = true;
				}
			}
		}
		ans = 0;
		for(int i = 0; i < n; i++){
			for(int j = 0; j < m; j++){
				d = search(i, j, map);
				if(ans < d){
					ans = d;
				}
			}
		}
		printf("%d\n", ans);
	}
	
	return 0;
}

Measured memory_bytes: 1152
#include<iostream>
#include<stdio.h>
#include<cctype>
#include<string>
#include<cmath>
using namespace std;
int main() {
	
	int n;
	double s[1000];
	double m, a, a2, sup = 0, sum = 0;
	for(int a=0;a<1000;a++){
		
	cin >> n;

	if (n == 0) {
		break;
	}

	for (int i = 0; i < n; i++) {
		cin >> s[i];
		sum += s[i];

	}
	m = sum / n;
	for (int i = 0; i < n; i++) {

		sup += pow(s[i] - m, 2);
	}
	a2 = sup / n;
	printf("%.8lf\n", sqrt(a2));

	sup = 0;
	sum = 0;


}
	return 0;
}


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

int n,m,dp[100010],ans[100010],sz[100010];
bool yes[10];
int num[10]= {0,2,5,5,4,5,6,3,7,6};

int main()
{
	memset(ans,-1,sizeof(ans));
	cin>>n>>m;
	for(int i=0;i<m;i++)
	{
		int a;
		cin>>a;
		yes[a]=1;
	}
	ans[0]=0;
	for(int i=1;i<=n;i++)
		for(int j=9;j>=1;j--) 
			if(i-num[j]>=0 && yes[j] && ans[i-num[j]]!=-1)
				if(sz[i-num[j]]+1>sz[i])
				{
					sz[i]=sz[i-num[j]]+1;
					ans[i]=j;
					dp[i]=i-num[j];
				}
	for(int i=n,j=sz[n];j>0;i=dp[i],j--)
		cout<<ans[i];
	return 0;
}


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

#define int long long
#define str string
#define rep(x,y) for(int i=x;i<y;i++)
#define REP(x,y) for(int j=x;j<y;j++)
#define all(x) x.begin(),x.end()
#define vint vector<int>
#define vchar vector<char>
#define vstr vector<string>
#define pb(n) push_back(n)

signed main(){
  int A,B,N,M,count=0,count2=0,count3=0;
  str S,W,T;
  int C='A'-'a';
  cin>>N;
  vint p(N);
  rep(0,N){
    cin>>p.at(i);
    count+=p.at(i);
  }
  sort(all(p));
  A=p.at(N-1)/2;
  cout<<count-A<<endl;
}


Measured memory_bytes: 256
/*
bit演算

AND OR
int a = 45 = 0b101101;
int b = 25 = 0b011001;

a&b 	   = 0b001001
a|b 	   = 0b111101

出力
cout << bitset<8>(a) << " AND " << bitset<8>(b) << " = " << bitset<8>(a&b) << endl;
00101101 AND 00011001 = 00001001

ビットシフト演算子
a 番目のフラグが立っている状態は (1<<a) 
やりたいこと	実装
ビット bit に i 番目のフラグが立っているかどうか	if (bit & (1<<i))
ビット bit に i 番目のフラグが消えているかどうか	if (!(bit & (1<<i)))
ビット bit に i 番目のフラグを立てる				bit｜= (1<<i)
ビット bit に i 番目のフラグを消す					bit &= ~(1<<i)
ビット bit に何個のフラグが立っているか				__builtin_popcount(bit)
ビット bit に i 番目のフラグを立てたもの			bit｜(1<<i)
ビット bit に i 番目のフラグを消したもの			bit & ~(1<<i)


*/
typedef long long ll;
#include <iostream>
#include <set>
#include <map>
#include <string>
#include <math.h>
#include <algorithm>
#include <vector>
#include <bitset>

using namespace std;

int main() {
	// 入力
    string C;
    cin >> C;
    int ABCD[4];
    // char -> int
	for (int i = 0; i < 4; ++i) ABCD[i] = (int)(C[i]- '0');
	
	// cout << C << endl;
	// for (int i = 0; i < 4; ++i) cout << ABCD[i] << " ";
	// cout << endl;
    
    int ans = 0;
	for (int bit = 0; bit < (1<<3); ++bit){
		// cout << bitset<3>(bit)<< endl;
    	int sum = ABCD[0];
	    for (int i = 0; i < 3; ++i) {
	        if (bit & (1<<i))sum += ABCD[i+1];
	        else sum -= ABCD[i+1];
	    }
		// cout << "sum " << sum << endl;
	    if (sum==7){
	    	ans = bit;
	    	break;
	    }
	}
        
	// 出力
	// cout << "ans " << ans << endl;
	cout << ABCD[0];
    for (int i = 0; i < 3; ++i) {
        if (ans & (1<<i)) cout << "+";
        else  cout << "-";
		cout << ABCD[i+1];
    }
	cout << "=7" <<endl;
}
 


Measured memory_bytes: 256
#include<bits/stdc++.h>
    #include<chrono>
     
    using namespace std;
    using namespace std::chrono;
    typedef long long ll;
    typedef vector<int> vi;
    typedef pair<int,int> pi;
    #define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0)    
    #define F first
    #define S second
    #define PB push_back
    #define EB emplace_back
    #define MP make_pair
    #define REP(i,a,b) for(i=a;i<=b;i++)
    #define RAP(i,a,b) for(i=a;i>=b;i--)
    ll mod=1000000007;
    const int MX=0x3f3f3f3f;
    
    int main(){
        IOS;
        int n,i;
        cin>>n;
        int a[n],dp[n];
        memset(dp,MX,sizeof(dp));
        REP(i,0,n-1) cin>>a[i];
        dp[0]=0;
        REP(i,0,n-2){
            dp[i+1]=min(dp[i+1],dp[i]+abs(a[i+1]-a[i]));
            if(i+2<n)
            dp[i+2]=min(dp[i+2],dp[i]+abs(a[i+2]-a[i]));
        } 
        cout<<dp[n-1];
        return 0;
    }

Measured memory_bytes: 1024
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using static System.Console;

class Program
{
    static void Main(string[] args)
    {
        new Program().Calc();
    }

    Scanner cin;

    public Program() { }

    bool chmax<T>(ref T a, T b) where T : IComparable<T> { if (a.CompareTo(b) < 0) { a = b; return true; } return false; }
    bool chmin<T>(ref T a, T b) where T : IComparable<T> { if (b.CompareTo(a) < 0) { a = b; return true; } return false; }

    void Calc()
    {
        cin = new Scanner();

        long n = cin.nextLong();

        long ans = 0;

        if (n % 2 == 1)
        {
            WriteLine(0);
        }
        else
        {
            n /= 2;

            while (n / 5 > 0)
            {
                ans += n / 5;

                n /= 5;
            }

            WriteLine(ans);
        }
    }
}

public static class StringExtension
{
    public static char GetChar1(this string str, int indexOneBase)
    {
        return str[indexOneBase - 1];
    }
}

class Scanner
{
    string[] s;
    int i;

    char[] cs = new char[] { ' ' };

    public Scanner()
    {
        s = new string[0];
        i = 0;
    }

    public string next()
    {
        if (i < s.Length) return s[i++];
        string st = Console.ReadLine();
        while (st == "") st = Console.ReadLine();
        s = st.Split(cs, StringSplitOptions.RemoveEmptyEntries);
        if (s.Length == 0) return next();
        i = 0;
        return s[i++];
    }

    public int nextInt()
    {
        return int.Parse(next());
    }
    public int[] ArrayInt(int N, int add = 0)
    {
        int[] Array = new int[N];
        for (int i = 0; i < N; i++)
        {
            Array[i] = nextInt() + add;
        }
        return Array;
    }

    public long nextLong()
    {
        return long.Parse(next());
    }

    public long[] ArrayLong(int N, long add = 0)
    {
        long[] Array = new long[N];
        for (int i = 0; i < N; i++)
        {
            Array[i] = nextLong() + add;
        }
        return Array;
    }

    public double nextDouble()
    {
        return double.Parse(next());
    }


    public double[] ArrayDouble(int N, double add = 0)
    {
        double[] Array = new double[N];
        for (int i = 0; i < N; i++)
        {
            Array[i] = nextDouble() + add;
        }
        return Array;
    }
}


Measured memory_bytes: 11092
from collections import Counter
N = int(input())
D = list(map(int, input().split()))
M = int(input())
T = list(map(int, input().split()))

c = Counter(D)
flag = True
for t in T:
  if c[t] > 0:
    c[t] -= 1
  else:
    flag = False
    break
    
if flag:
  print('YES')
else:
  print('NO')

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

long long solve() {
  long long x, k, d;
  std::cin >> x >> k >> d;
  
  x = std::abs(x);

  long long ans;
  /* 往復できない */
  if (x / d >= k) {
    ans = x - k*d; 
  }
  /* 往復できる */
  else {
    ans = x % d;
    if ((k-x/d)%2==1) ans = std::abs(ans-d);
  }
  return ans;

}

int main() {
  std::cout << solve() << std::endl; 
  return 0;
}


Measured memory_bytes: 3628
import math

def main():
	H, W = [int(a) for a in input().split(" ")]

	cand = []
	# case 1. w 3 split, h 3 split
	if W % 3 == 0 or H % 3 == 0:
		print(0)
		return 0
	# W % 3 !== 0 and H % 3 !== 0
	cand.append(H)
	cand.append(W)
	# case 2. w split -> h split
	cand += split_3(H, W)
	cand += split_3(W, H)

	print(min(cand))
	return 0

def split_3(a, b):
	a_f = math.floor(a/3)
	a_c = math.ceil(a/3)
	b_f = math.floor(b/2)
	b_c = math.ceil(b/2)

	a1 = [b * a_f, (a - a_f) * b_f, a * b - (a - a_f) * b_f - b * a_f]
	a2 = [b * a_c, (a - a_c) * b_f, a * b - (a - a_c) * b_f - b * a_c]
	a3 = [b * a_f, (a - a_f) * b_c, a * b - (a - a_f) * b_c - b * a_f]
	a4 = [b * a_c, (a - a_c) * b_c, a * b - (a - a_c) * b_c - b * a_c]

	return [max(a1) - min(a1), max(a2) - min(a2), max(a3) - min(a3), max(a4) - min(a4)]

main()


Measured memory_bytes: 9288
#include <iostream>
#include <fstream>
#include <vector>
#include <algorithm>
using namespace std;

int main() {

    // cinを高速にするためのおまじない
    cin.tie(0);
    ios::sync_with_stdio(false);

    /////////////////////
    // Write code below /
    int A=0,W=0,T=0,R=0;
    int N;
    string S;
    cin >> N;
    for(int i=0;i<N;i++){
        cin >> S;
        if(S == "AC"){
            A = A+1;
        }else if(S == "WA"){
            W = W+1;
        }else if(S == "TLE"){
            T = T+1;
        }else if(S == "RE"){
            R = R+1;
        }
    }
    cout << "AC x " << A << endl;
    cout << "WA x " << W << endl;
    cout << "TLE x " << T << endl;
    cout << "RE x " << R << endl;
    /////////////////////


    return 0;
}


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

int int_len(int n) {
  int s=0;
  while(n!=0) s++, n/=10;
  return s;
}

int int_sum(int n) {
  int m=0,s=0,a=n;
  while(a!=0) s++, a/=10;
  for(int i=s-1;i>=0;i--) m+=n/((int)pow(10,i))-(n/((int)pow(10,i+1)))*10;
  return m;
}






int gcd(int a,int b)
{
 
  int r, tmp;
 
  
 
  /* 自然数 a > b を確認・入替 */
  if(a<b){
    tmp = a;
    a = b;
    b = tmp;
  }
 
  /* ユークリッドの互除法 */
  r = a % b;
  while(r!=0){
    a = b;
    b = r;
    r = a % b;
  }
 
 
 
  return b;
}







int fac(int n){
  int m=1;
  while(n>=1) m*=n,n--;
  return m;
}

int vec_sum(vector<int> v){
  int n=0;
  for(int i=0;i<v.size();i++) n+=v[i];
  return n;
}
///////////////////////////
int main() {
  long long int a,b,c,x,y,ans=0;
  cin>>a>>b>>c>>x>>y;
  if(a+b>2*c){
    ans+=c*min(x,y)*2;
    if(x>=y){
      if(a>=c*2){
        ans+=c*(x-y)*2;
      }else{
        ans+=a*(x-y);
      }
    }else{
      if(b>=c*2){
        ans+=c*(y-x)*2;
      }else{
        ans+=b*(y-x);
      }
    }
    cout<<ans<<endl;
  }else{
    cout<<a*x+b*y<<endl;
  }
  
  
  
}
///////////////////////////



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

const double EPS = 1e-9;
bool equal(double x,double y){
    return (fabs(x-y) < EPS);
}

class Point{
public:
    double x,y;

    Point(double x=0,double y=0) : x(x),y(y){}
    Point operator + (Point p){
        return Point(x+p.x,y+p.y);
    }
    Point operator - (Point p){
        return Point(x-p.x,y-p.y);
    }
    Point operator * (double k){
        return Point(k*x,k*y);
    }

    double norm(Point p){
        return p.x*p.x+p.y*p.y;
    }
    double norm(){
        return x*x+y*y;
    }
};

class Segment{
public:
    Point p1,p2;
    Segment(Point a,Point b) : p1(a) , p2(b) {}
};

typedef Point Vector;

double dot(Vector a,Vector b){
    return a.x*b.x+a.y*b.y;
}

// ?????? s1 -> s2?????????p????°???± ????±???????
Point project(Segment s,Point p){
    Vector b = s.p2-s.p1;
    Vector a = p - s.p1;
    return s.p1 + b * (dot(a,b) / b.norm());
}

int main(){
    double xp1,yp1,xp2,yp2;
    cin >> xp1 >> yp1 >> xp2 >> yp2;
    int q;
    cin >> q;
    Segment seg(Point(xp1,yp1),Point(xp2,yp2));

    for(int i=0;i<q;i++){
        double x,y;cin>>x>>y;

        Point p = project(seg,Point(x,y));
        printf("%.20f %.20f\n",p.x,p.y);
    }
}

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

//sort(v.rbegin(), v.rend(), [](auto& x, auto& y){return x[1] < y[1];});
typedef long long ll;

int main(){
    int N,a,b_a,r=0;

    cin >> N;

    for (int i=0;i<N;++i){
        cin >> a;
        if (a==b_a) {r+=1;b_a=10001;}
        else b_a = a;
    }
    cout << r << endl;
  }


Measured memory_bytes: 256
#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>
#define pb push_back 
#define YES cout<<"YES"<<endl
#define Yes cout<<"Yes"<<endl
#define NO cout<<"NO"<<endl
#define No cout<<"No"<<endl
typedef long long ll;
const int INF = 100000000, mod = 1000000007;
const ll LLINF = 1LL << 50;
using namespace std;


int main() {
    ll n, m;
    cin >> n >> m;
    if (n == 1 && m == 1)cout << "1" << endl;
    else if (n == 1 || m == 1)cout << n*m - 2 << endl;
    else cout << (n - 2)*(m - 2) << endl;
    return 0;
}


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

#define endl '\n'
#define int long long

const int N = 3009;
int cache[N][N], ls, lt;
string s, t;

int dp(int i, int j) {
	if(i == ls or j == lt) 
		return 0;
	int &ans = cache[i][j];
	if(ans != -1)
		return ans;
	if(s[i] == t[j])
		ans = 1 + dp(i+1, j+1);
	else 
		ans = max(dp(i+1, j), dp(i, j+1));
	return ans;
}

int32_t main()
{
	ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
	for(int i = 0; i < N; i ++) {
		for(int j = 0; j < N; j ++) {
			cache[i][j] = -1;
		}
	}
	cin >> s >> t;
	if(s.size() > t.size()) 
		swap(s,t);
	ls = s.size(); lt = t.size();
	int a = dp(0,0);
	// cout << dp(0,0) << endl;
	// for(int i = 0; i <= ls; i ++) {
	// 	for(int j = 0; j <= lt; j ++) {
	// 		cout << cache[i][j] << " ";
	// 	}
	// 	cout << endl;
	// }
	string ans = "";
	for(int i = 0, j = 0; i < lt and j < ls; i ++) {
		if(cache[j][i+1] == cache[j][i]) {
			continue;
		}
		if(cache[j+1][i] == cache[j][i]) {
			j ++, i --;
			continue;
		}
		if(cache[j+1][i+1] < cache[j][i]) {
			ans += t[i];
			j ++;
		}
	}
	for(int i = 0; i < a; i ++) {
		cout << ans[i];
	}

	return 0;
}


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

int main() {
  int n, k;
  string s;
  cin >> n >> k >> s;
  
  int count = 1;
  vector<int> v;
  for(int i = 1; i < s.size(); i++){
    if(s.at(i - 1) == s.at(i)){
      count++;
    }
    else{
      v.push_back(count);
      count = 1;
    }
  }
  v.push_back(count);
  
  int ans = 0;
  for(int i = 0; i < v.size(); i++) ans += v.at(i);
  
  int keep = v.size();
  while(k > 0 && keep > 1){
    keep -= 2;
    k--;
  }
  
  if(keep <= 1) cout << ans - 1 << endl;
  else cout << ans - keep << endl;
}

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

template<typename T, typename U>
using pv=vector<pair<T,U>>;
template<typename T>
using matrix=vector<vector<T>>;
template<typename T>
using pque=priority_queue<T>;
template<typename T>
using lpque=priority_queue<T,vector<T>,greater<T>>;

using ll=long long;
using intpair=pair<int,int>;
using llpair=pair<ll,ll>;
using ilpair=pair<int,ll>;
using lipair=pair<ll,int>;
using intvec=vector<int>;
using llvec=vector<ll>;
using intq=queue<int>;
using llq=queue<ll>;
using intmat=vector<intvec>;
using llmat=vector<llvec>;

#define PI 3.141592653589793
#define INTINF ((1<<30)-1)
#define LLINF ((1LL<<62)-1)
#define MPRIME 1000000007
#define MPRIME9 998244353
#define MMPRIME ((1ll<<61)-1)

#define len length()
#define pushb push_back
#define fi first
#define se second

#define setpr fixed<<setprecision(15)
#define all(name) name.begin(),name.end()
#define rall(name) name.rbegin(),name.rend()
#define gsort(vbeg,vend) sort(vbeg,vend,greater<>())

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

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

template<class T>
inline void init(T& v) {
	for(auto &a: v) cin>>a;
}
template<class T, class U>
inline void init(vector<pair<T,U>>& v) {
	for(auto &a: v) cin>>a.first>>a.second;
}
template<class T, class N>
inline void init(T& v, N n) {
	v.resize(n);
	for(auto &a: v) cin>>a;
}
template<class T, class U, class N>
inline void init(vector<pair<T,U>>& v, N n) {
	v.resize(n);
	for(auto &a: v) cin>>a.first>>a.second;
}

inline void out() {
	cout<<endl;
}
template<class T, class... U>
inline void out(T a, U... alist) {
	cout<<a<<" ";
	out(forward<U>(alist)...);
}

template<class N>
void resiz(N n) {
	//empty
}
template<class N, class T, class... U>
void resiz(N n, T&& hd, U&&... tl) {
	hd.resize(n);
	resiz(n,forward<U>(tl)...);
}

bool isout(int h, int w, int H, int W) {
	return ( h<0 || h>=H || w<0 || w>=W );
}

ll binpow(ll a, ll ex, ll p) {
	ll result=1;
	while(ex>0) {
		if(ex&1) result=result*a%p;
		ex>>=1;
		a=a*a%p;
	}
	return result;
}


int N,K;
intvec A;
int maxa=-1;

void input() {
	cin>>N>>K;
	A.resize(N);
	for(int i=0; i<N; i++) {
		cin>>A[i];
		chmax(maxa, A[i]);
	}
}

bool check(int x) {
	int n=0;
	for(int i=0; i<N; i++) {
		n += (A[i]-1)/x;
	}
	return K>=n;
}

void solve() {
	int ng=0,ok=maxa;
	while(ok-ng>1) {
		int mid=(ok+ng)/2;
		if(check(mid)) ok=mid;
		else ng=mid;
	}
	cout<<ok<<endl;
}

int main() {
	cin.tie(nullptr);
	ios_base::sync_with_stdio(false);
	cout<<fixed<<setprecision(15);
	int t=1;
	while(t) {
		input();
		solve();
		t--;
	}
}


Measured memory_bytes: 3896
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0; i<n; i++)
#define PI 3.14159265359
#define INF 1000100100
#define all(x) (x).begin(),(x).end()
typedef long long ll;
using namespace std;
 
int main(){
    string s,t;  cin >> s >> t;
    int sll=s.length(); int tll=t.length();
    vector<pair<int,string> > dp(sll+1);
    rep(i,sll+1){
        dp[i].first=-1;
        dp[i].second="";
    }
    vector<vector<int> > al(26);
    rep(i,tll) al[t[i]-'a'].push_back(i);
 
    for(int i=1; i<sll+1; i++){
        for(int j=i; j>=1; j--){
            bool p=false;
            if(al[s[i-1]-'a'].empty()) continue;
          	if(dp[j-1].first==-1 && j!=1) continue;
            auto next=upper_bound(all(al[s[i-1]-'a']),dp[j-1].first);
            if(next!=al[s[i-1]-'a'].begin()+al[s[i-1]-'a'].size()){
                if(*next<dp[j].first || dp[j].first==-1){
                    dp[j].first=*next;
                    dp[j].second=dp[j-1].second+s[i-1];
                    p=true;
                }
            }
         // cout << i << j << ' ' << dp[j].second << endl;
        }
    }
 
        for(int j=sll; j>=0; j--){
            if(dp[j].first!=-1){
              cout << dp[j].second << endl;
                return 0;
            }
        }
    return 0;
}

Measured memory_bytes: 7808
#include <iostream>
#include <boost/range/algorithm/sort.hpp>
#include <vector>
#include <cmath>
#include <deque>

struct monster {
  int64_t x;
  int64_t h;
};

int main() {
  int64_t n, d, a;
  std::cin >> n;
  std::cin >> d;
  std::cin >> a;

  std::vector<monster> ms(n);
  for (int64_t i = 0; i < n; ++i) {
    std::cin >> ms[i].x;
    std::cin >> ms[i].h;
  }

  boost::sort(ms, [](auto x, auto y) {return x.x < y.x;});

  std::deque<std::pair<int64_t, int64_t>> damages;

  int64_t nbomb = 0;
  int64_t dam = 0;
  for (int64_t i = 0; i < n; ++i) {
    while (!damages.empty() && std::get<1>(damages.front()) < ms[i].x) {
      dam -= damages.front().first;
      damages.pop_front();
    }

    if (ms[i].h - dam > 0) {
      const auto b =
          static_cast<int64_t>(std::ceil(static_cast<double>(ms[i].h - dam) / a));
      damages.push_back(std::make_pair(b * a, ms[i].x + d * 2));
      dam += b * a;
      nbomb += b;
    }

    //for (const auto& t : damages)
    //  std::cout << t.first << " " << t.second << std::endl;
    //std::cout << "----------------" << std::endl;
  }

  std::cout << nbomb << std::endl;

  return 0;
}

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

using ll = long long;
const int INF = 1e9+100;
const int S = 3e5;

vector<int> adj[S];
int vis[S] = {0};
int cnt[S] = {0};
void dfs(int u, int c){
	vis[u] = 1;
	cnt[c]++;
	for (auto it: adj[u]){
		if (!vis[it]){
			dfs(it, c);
		}
	}
}
int main(){
	ios::sync_with_stdio(false);
	cin.tie(NULL);
	
	int n, m;
	cin>>n>>m;
	for (int i = 0; i < m; i++){
		int u, v;
		cin>>u>>v;
		adj[u].push_back(v);
		adj[v].push_back(u);
	}
	int ans = 0;
	for (int i = 0; i < n; i++){
		if (!vis[i]){
			dfs(i, i);
			ans = max(ans, cnt[i]);
		}
	}
	cout<<ans<<'\n';
	return 0;
}

Measured memory_bytes: 27092
import sys

sys.setrecursionlimit(100000)
input=lambda : sys.stdin.readline().rstrip('\n')

n,m=map(int,input().split())
g=[[]for i in range(n)]
s=set()
for i in range(m):
    a,b,c=map(int,input().split())
    g[a-1].append((c,b-1))
    g[b-1].append((c,a-1))
    if a>b:
        a,b=b,a
    s.add((a-1,b-1))

def dijkstra(g,st,s):
    from heapq import heappush, heappop, heapify
    inf=10**18
    dist=[inf for i in range(len(g))]
    visited=[False for i in range(len(g))]
    dist[st]=0
    que=[]
    heappush(que,(0,st,-1))
    while que:
        c,v,past=heappop(que)
        if visited[v]:
            continue
        visited[v]=True
        try:
            s.remove((v,past) if v<past else (past,v))
        except:
            pass
        for x in g[v]:
            tmp=x[0]+c
            if tmp<dist[x[1]] and not visited[x[1]]:
                dist[x[1]]=tmp
                heappush(que,(tmp,x[1],v))

for i in range(n):
    dijkstra(g,i,s)
print(len(s))


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

#define FOR(i,b,e) for(int i=(b);i<(e);++i)
#define FORQ(i,b,e) for(int i=(b);i<=(e);++i)
#define FORD(i,b,e) for(int i=(b)-1;i>=(e);--i)
#define REP(x, n) for(int x = 0; x < (n); ++x)

#define ST first
#define ND second
#define PB push_back
#define MP make_pair
#define LL long long
#define ULL unsigned LL
#define LD long double

const double pi = 3.141592653589793238462643383279502884197169399375105820974944592307816406286208998628034825342;
const int mod=1000000007;

int main(){

    LL x,y;

    cin >> x >> y;

    if((x >= 0 && y > 0) || (x < 0 && y <= 0)){
        if(x <= y)cout << y - x;
        else cout << x - y + 2;
    } else {
        if(x+y < 0)cout << (x+y) * (-1) + 1;
        else cout << x + y + 1;
    }

    return 0;
}


Measured memory_bytes: 256
N=int(input())
*h,=map(int,input().split())
INF=10**12

dp = [0]*N

for i in range(1,N):
  if i == 1:
    dp[i] = dp[0] + abs(h[i]-h[0])
    continue
  dp[i] = min(dp[i-1]+abs(h[i]-h[i-1]), dp[i-2]+abs(h[i]-h[i-2]))
  
print(dp[-1])

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

//conversion
//------------------------------------------
inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}

//math
//-------------------------------------------
template<class T> inline T sqr(T x) {return x*x;}

//typedef
//------------------------------------------
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<bool> VB;
typedef vector<double> VD;
typedef vector<string> VS;
typedef vector<char> VC;
typedef pair<int, int> PII;
typedef long long LL;
typedef vector<LL> VLL;
typedef vector<VLL> VVLL;

//container util
//------------------------------------------
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define SQ(a) ((a)*(a))
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())
#define LB lower_bound
#define UB upper_bound

//repetition
//------------------------------------------
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)

//constant
//--------------------------------------------
const double EPS = 1e-10;
const double PI  = acos(-1.0);
const LL INF = 1e9;
const LL MOD = 1e9+7;

//other
//-------------------------------------------
#define chmin(x,y) x=min(x,y)
#define chmax(x,y) x=max(x,y)
#define FI first
#define SE second

//memo
// setprecision()


int main() {
  char a,b,c;
  cin >> a >> b >> c;
  
  if(a!=b && b!=c && c!=a) cout << "Yes" << endl;
  else cout << "No" << endl;
  
  return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<string>
using namespace std;
int main() {
	int a, b;
	cin >> a >> b;
	if (a > b) {
		cout << "a > b" << endl;
	}
	if (a < b) {
		cout << "a < b" << endl;
	}
	if (a == b) {
		cout << "a == b" << endl;
	}
}


Measured memory_bytes: 3068