akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;
#define pb push_back
#define ll long long
#define m3(a, b, c) min(c, min(a, b))
#define m4(a, b, c, d) min(d, min(c, min(a, b)))
#define test long long t; cin>>t; while(t--)
#define IOS ios::sync_with_stdio(0);cin.tie(0);
const ll maxn=1e16+100;
 


 int main()
 {  IOS;
   ll n;
   cin>>n;
   ll a[n];
   for(auto &i:a) cin>>i;
vector<ll>dp(n,maxn);
dp[0]=0;

for(int i=0;i<n;i++)
{
    for(int j=i+1;j<=i+2;j++)
    {
        if(j<n)
        {  
            dp[j]=min(dp[j],dp[i]+abs(a[i]-a[j]));
        }
    }
}
cout<<dp[n-1];
   
 }

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

int ans;
int w, h;
char map[20][20];
int dx[4] = { 1, 0, -1, 0 };
int dy[4] = { 0, 1, 0, -1 };

void solve(int x, int y)
{
	ans++;
	map[x][y] = '#';
	for (int i = 0; i < 4; i++)
	{
		int X = x + dx[i];
		int Y = y + dy[i];
		if (0 <= X && X < w && 0 <= Y && Y < h && map[X][Y] != '#')
		{
			solve(X, Y);
		}
	}
}

int main()
{
	while (cin >> w >> h, w + h)
	{
		ans = 0;
		for (int y = 0; y < h; y++)
		{
			for (int x = 0; x < w; x++)
			{
				cin >> map[x][y];
			}
		}

		for (int y = 0; y < h; y++)
		{
			for (int x = 0; x < w; x++)
			{
				if (map[x][y] == '@') solve(x, y);
			}
		}
		cout << ans << endl;
	}

	return 0;
}

Measured memory_bytes: 1168
#include <bits/stdc++.h>
using namespace std;
 
//#pragma GCC optimize("O3")
//#pragma GCC target("sse4")
 
#define FOR(i, a, b) for(int i = (a); i < (b); ++i)
#define RFOR(i, b, a) for(int i = (b) - 1; i >= (a); --i)
#define FILL(a, value) memset(a, value, sizeof(a))
 
#define SZ(a) (int)((a).size())
#define ALL(a) a.begin(), a.end()
 
typedef long long LL;
typedef pair<int, int> PII;

const int mod = 998244353;
const int MAX = 1 << 17;

int mult(int a, int b)
{
	return (LL)a * b % mod;
}

int c[MAX];

int main()
{
	ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
	int n;
	cin >> n;
	FOR(i, 0, n)
	{
		int d;
		cin >> d;
		if(i == 0 && d)
		{
			cout << "0\n";
			return 0;
		}
		c[d]++;
	}
	if(c[0] != 1)
	{
		cout << "0\n";
		return 0;
	}
	int s = 1, ans = 1;
	for(int i = 0; c[i + 1]; i++)
	{
		FOR(j, 0, c[i + 1])
			ans = mult(ans, c[i]);
		s += c[i + 1];
	}
	cout << (s == n ? ans : 0) << "\n";
	return 0;
}


Measured memory_bytes: 3976
#include <iostream>
#include <queue>

using namespace std;

typedef struct Point{
	int x, y;
	int n;
};

int H, W;
char G[55][55];
int arri[55][55];
bool arrived[55][55];

const int px[4] = {1, 0, -1, 0};
const int py[4] = {0, 1, 0, -1};

bool canReach(int x, int y){
	if(G[y][x] == '#') return false;

	if( (0 <= y && y < H) && (0 <= x && x < W) ) return true;
	else return false;
}

int main(){
	cin >> H >> W;
	
	int ndot = 0;
	
	for(int i = 0 ; i < H ; i++){
		for(int j = 0 ; j < W ; j++){
			cin >> G[i][j];
			if(G[i][j] == '.') ndot++;
		}
	}
	
	queue<Point> que;
	Point p;
	p.x = 0, p.y = 0, p.n = 0;
	que.push(p);
	
	int ans = (1<<29);
	
	
	while(!que.empty()){
		Point tmp = que.front();
		que.pop();
		
		if(tmp.x == W-1 && tmp.y == H-1) ans = min(ans, tmp.n);
		
		if(arrived[tmp.y][tmp.x]) continue;
		arrived[tmp.y][tmp.x] = true;
		arri[tmp.y][tmp.x] = tmp.n;

		for(int i = 0 ; i < 4 ; i++){
			Point tmp2 = tmp;
			tmp2.x += px[i];
			tmp2.y += py[i];
			tmp2.n += 1;
			if(canReach(tmp2.x, tmp2.y)){
				que.push(tmp2);
			}
		}
	}
	
	/*
	for(int i = 0 ; i < H ; i++){
		for(int j = 0 ; j < W ; j++){
			printf("%2d ", arri[i][j]);
		}
		cout << endl;
	}
	
	cout << "ndot = " << ndot << endl;
	cout << "ans = " << ans << endl;
	*/
	if(ans == (1<<29)) cout << -1 << endl;
	else cout << ndot - ans - 1 << endl;
	
	return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<iomanip>
#define prDouble(x) cout << fixed << setprecision(10) << x
using namespace std;
int main()
{
	ios_base::sync_with_stdio(false);
	int n;
	cin >> n;
	vector<double>prob(n+1);
	for(int i = 1;i <= n;++i)
		cin >> prob[i];
	int x = ((n+1)/2) + 1;
	double dp[n+1][x];
	for(int i = 0;i <= n;++i)
	{
		for(int j = 0;j < x;++j)
		{
			if(i == 0 && j == 0)
				dp[i][j] = 1;
			else if(i==0)
				dp[i][j] = 0;
			else if(j == 0)
				dp[i][j] = 1;
			else
				dp[i][j] = prob[i]*dp[i-1][j-1]+(1-prob[i])*dp[i-1][j];
		}
	}
	prDouble(dp[n][x-1]);
	cout << "\n";
	return 0;
}

Measured memory_bytes: 38956
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll INF = 1e18;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)

int main(){
    int X;
    cin>>X;
    if(X>=30)cout<<"Yes"<<endl;
    else cout<<"No"<<endl;
    return 0;
}

Measured memory_bytes: 3632
#include<bits/stdc++.h>
using namespace std;
int main(){
	int n, sum=0, max=1;
	cin >> n;
	for(int i=1;i<10;i++){
      	if(n%i==0){
          	if(max<i){
            	max=i;
            }
        }
    }
  
    if(n%max==0){
        if(0 < n/max  &&  n/max < 10){
            cout << "Yes" << endl;
         }
         else{
  			cout << "No" << endl;
  		}
    }
  	
  	/*if(sum=1){
  		cout << "Yes" << endl;
  	}
  	else{
  		cout << "No" << endl;
  	}*/
  
	return 0;
}


Measured memory_bytes: 256
from sys import stdin
import fractions

A, B, C, D = [int(x) for x in stdin.readline().rstrip().split()]


def div(n, x, y):
    lcs = int(x * y / fractions.gcd(x, y))
    return n - int(n // x) - int(n // y) + int(n // lcs)


print(div(B, C, D) - div(A - 1, C, D))


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

#define check(val) std::cout << "\033[31m" << #val << ": " << val << "\033[m" << std::endl
#define check_v(vec) \
  std::cout << "\033[31m" << #vec << ": [ ";\
  for(auto it=vec.begin(); it!=vec.end(); it++){cout << *it << " ";}\
  cout << "]"<< "\033[m" << endl;

int main() {
  int n, m;
  cin >> n >> m;
  cout << (n*(n-1) / 2) + (m * (m-1)) /2 << endl;
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using vl = vector<ll>;
using vll = vector<vl>;
using Pll = pair<ll, ll>;
#define rep(i,n) for(ll i=0;i<(ll)(n);i++)
#define all(v) v.begin(), v.end()
#define sz(x) ((int) x.size())
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define F first
#define S second
const int MOD = 1e9+7;
const ll INF = 2e15;
template<class T> void print(const T& t){ cout << t << endl; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}

int main(){
  ll n,d;
  cin >> n >> d;
  ll count = 0;
  rep(i,n){
    ll x, y;
    cin>>x>>y;
    ll a=x*x+y*y;
    if(a<=d*d){
      count++;
    }
  }
  print(count);
}

Measured memory_bytes: 3672
#include<bits/stdc++.h>
#define forr(i, a, b) for(int i = (a); i < (b); i++)
#define rep(i,n) for(int i = 0; i < (n); i++)
#define rrep(i,n) for(int i = 1; i <= (n); i++)
#define ALL(a) (a.begin()),(a.end())
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
typedef pair<ll, ll> LP;
const ll LINF = 1LL<<60;
const int INF = 1001001001;
const int MOD = 1000000007;

/* --------------------------------------------------- */

int main() {
    int n; cin >> n;
    bool ans = false;
    rep(i, n) {
        rep(j, n) {
            if(i * 4 + j * 7 == n) ans = true;
        }
    }
    cout << (ans ? "Yes" : "No") << endl;
    
    return 0;
}

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

void print(std::vector<int> readVec){
    int sz = readVec.size();
    for(int i = 0; i < sz; ++i){
        std::cout << readVec.at(i);
        if(sz - 1 != i){
            std::cout << " ";
        }else{
            std::cout << std::endl;
        }
    }
}

int main(){
    int n;
    std::cin >> n;

    std::vector<std::vector<int>> matrix(26, std::vector<int>(n, 0));
    for(int i = 0; i < n; ++i){
        std::string s;
        std::cin >> s;
        int sz = s.size();
        for(int j = 0; j < sz; ++j){
            ++matrix.at(s.at(j) - 97).at(i);
        }
    }

//    print(matrix.at(0));

    std::string ans = "";
    for(int i = 0; i < 26; ++i){
        int val = *std::min_element(matrix.at(i).begin(), matrix.at(i).end());
        for(int j = 0; j < val; ++j){
            ans += (char)(i + 97);
        }
    }

    std::cout << ans << std::endl;    

    return 0;
}

Measured memory_bytes: 384
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, groupby
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()))
def ZIP(n): return zip(*(MAP() for _ in range(n)))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7

l = [INT() for _ in range(5)]
k = INT()

if l[4]-l[0] > k:
	print(":(")
else:
	print("Yay!")

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

int main(){
    string a;
    cin >> a;
    char tmp = a[0];
    for(int i = 1;i<4;i++){
        if(tmp == a[i]){
            cout << "Bad" << endl;
            return 0;
        }
        tmp = a[i];
    }
    cout << "Good" << endl;
    return 0;
}

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

#define int long long

#define rep(i,n) for(int i=0;i<(n);i++)
#define pb push_back
#define eb emplace_back
#define all(v) (v).begin(),(v).end()
#define fi first
#define se second

using vint=vector<int>;
using pint=pair<int,int>;
using vpint=vector<pint>;

template<typename A,typename B>inline void chmin(A &a,B b){if(a>b)a=b;}
template<typename A,typename B>inline void chmax(A &a,B b){if(a<b)a=b;}

template<class A,class B>
ostream& operator<<(ostream& ost,const pair<A,B>&p){
    ost<<"{"<<p.first<<","<<p.second<<"}";
    return ost;
}

template<class T>
ostream& operator<<(ostream& ost,const vector<T>&v){
    ost<<"{";
    for(int i=0;i<v.size();i++){
        if(i)ost<<",";
        ost<<v[i];
    }
    ost<<"}";
    return ost;
}

inline int topbit(unsigned long long x){
    return x?63-__builtin_clzll(x):-1;
}

inline int popcount(unsigned long long x){
    return __builtin_popcountll(x);
}

inline int parity(unsigned long long x){
    return __builtin_parity(x);
}

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

int H,W,K;
int sy,sx,gy,gx;
vector<string>fld;
vector<vint>dist;

signed main(){
	cin>>H>>W>>K;
	cin>>sy>>sx>>gy>>gx;
	sy--;sx--;gy--;gx--;
	fld=vector<string>(H);
	rep(i,H)cin>>fld[i];

	dist=vector<vint>(H,vint(W,INF));
	queue<pint>que;
	que.emplace(sy,sx);
	dist[sy][sx]=0;


	while(que.size()){
		int y,x;
		tie(y,x)=que.front();
		que.pop();
		rep(d,4){
			for(int c=1;c<=K;c++){
				int ny=y+dy[d]*c;
				int nx=x+dx[d]*c;
				if(ny<0||ny>=H||nx<0||nx>=W||fld[ny][nx]=='@')break;
				int nc=dist[y][x]+1;
				if(dist[ny][nx]<nc)break;
				if(dist[ny][nx]==nc)continue;
				dist[ny][nx]=nc;
				que.emplace(ny,nx);
			}
		}
	}
	int ans=dist[gy][gx];
	if(ans==INF)cout<<-1<<endl;
	else cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 19996
s = input() + 'T'
x, y = [int(i) for i in input().split()]

dire = True
xi = []
yi = []
ctr = 0
for i in range(len(s)):
    if s[i] == 'F':
        ctr += 1
        continue
    if dire:
        xi.append(ctr)
    else:
        yi.append(ctr)
    ctr = 0
    dire = not dire
ans = 'Yes'
X = (sum(xi)-x)//2
x0 = xi.pop(0)
Hx = {0: True}
for i in xi:
    for j in Hx.copy().keys():
        Hx[j+i] = True
Y = (sum(yi)-y)//2
Hy = {0: True}
for i in yi:
    for j in Hy.copy().keys():
        Hy[j+i] = True
        
if (x0+sum(xi)-x)%2 != 0 or (sum(yi)-y)%2 != 0:
    ans = 'No'
if not Hx.get(X, False) or not Hy.get(Y, False):
    ans = 'No'
print(ans)

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

using namespace std;

int main(){
vector<int> d(3);
  cin>>d[0]>>d[1]>>d[2];
  sort(d.begin(),d.end());
  reverse(d.begin(),d.end());
  cout<<d[0]*10 + d[1]+d[2];
  


return 0;
}

Measured memory_bytes: 256
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <stack>
#include <queue>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;

static const double EPS = 1e-8;
static const double PI = 4.0 * atan(1.0);
static const double PI2 = 8.0 * atan(1.0);

#define REP(i,n)	for(int i=0;i<(int)n;++i)
#define ALL(c)		(c).begin(),(c).end()
#define CLEAR(v)	memset(v,0,sizeof(v))
#define MP(a,b)		make_pair((a),(b))
#define ABS(a)		((a)>0?(a):-(a))
#define FOR(i,s,n)	for(int i=s;i<(int)n;++i)

int n, k;
ll a[100000];
ll s[100001], ps[100001];

int main(int argc, char **argv) {
	cin >> n >> k;
	REP(i, n) cin >> a[i];
	s[0] = ps[0] = 0;
	REP(i, n) {
		s[i + 1] = s[i] + a[i];
		ps[i + 1] = ps[i];
		if (a[i] > 0) ps[i + 1] += a[i];
	}
	ll res = 0;
	REP(i, n - k + 1) {
		ll v = (ps[i] - ps[0]) + (ps[n] - ps[i + k]);
		if (s[i + k] - s[i] > 0) v += s[i + k] - s[i];
		res = max(res, v);
	}
	cout << res << endl;
	return 0;
}


Measured memory_bytes: 2688
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); i++)
using namespace std;
typedef long long ll;
int main()
{
  ll L, R;
  cin >> L >> R;
  R = min(R, L + 4038);
  int ans = 2018;
  for (ll i = L; i <= R; i++)
  {
    for (ll j = i + 1; j <= R; j++)
    {
      int x = i * j % 2019;
      ans = min(ans, x);
    }
  }
  cout << ans << endl;
  return 0;
}

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

typedef int HeapElementType;
typedef bool (*CompareFunc)(HeapElementType, HeapElementType);

void heapify(HeapElementType*, int, CompareFunc, int);
void buildHeap(HeapElementType*, int, CompareFunc);
bool compare(HeapElementType, HeapElementType);

int main () {
  int H;
  HeapElementType *heap = NULL;
  
  scanf("%d", &H);
  heap = (HeapElementType*)malloc(sizeof(HeapElementType)*(H+1));
  for (int i = 1; i <= H; ++i) {
    scanf("%d", &heap[i]);
  }

  buildHeap(heap, H, compare);

  for (int i = 1; i <= H; ++i) {
    printf(" %d", heap[i]);
  }
  printf("\n");
  
  return 0;
}

bool compare(HeapElementType x, HeapElementType y) {
  return x > y;
}

void heapify(HeapElementType* heap, int H, CompareFunc cmp, int i) {
  int left  = 2*i;
  int right = 2*i + 1;

  int target;
  if (left <= H && cmp(heap[left], heap[i])) {
    target = left;
  } else {
    target = i;
  }

  if (right <= H && cmp(heap[right], heap[target])) {
    target = right;
  }

  if (target != i) {
    HeapElementType t = heap[i];
    heap[i] = heap[target];
    heap[target] = t;
    heapify(heap, H, cmp, target);
  }
}

void buildHeap(HeapElementType* heap, int H, CompareFunc cmp) {
  for (int i = H/2; i >= 1; --i) {
    heapify(heap, H, cmp, i);
  }
}



Measured memory_bytes: 3652
#include <bits/stdc++.h>
using namespace std;
using LL  = long long;
using VI  = vector<LL>;
using VVI = vector<VI>;
using VB  = vector<bool>;
using VS  = vector<string>;
using PII = pair<LL, LL>;
using VP  = vector<PII>;
#define PB           push_back
#define MP           make_pair
#define SZ(a)        LL((a).size())
#define EACH(x, c)   for (auto x : (c))
#define ALL(c)       (c).begin(), (c).end()
#define REVERSE(c)   reverse(ALL(c))
#define SORT(c)      stable_sort(ALL(c))
#define RSORT(c)     stable_sort((c).rbegin(), (c).rend())
#define FSORT(c)     stable_sort(ALL(c), [] (auto& x, auto& y) {return x.first < y.first;});
#define FRSORT(c)    stable_sort(ALL(c), [] (auto& x, auto& y) {return x.first > y.first;});
#define SSORT(c)     stable_sort(ALL(c), [] (auto& x, auto& y) {return x.second < y.second;});
#define SRSORT(c)    stable_sort(ALL(c), [] (auto& x, auto& y) {return x.second > y.second;});
#define FOR(i, a, b) for (LL i = (a); i < (b); ++i)
#define REP(i, n)    FOR(i, 0, n)
#define $(x) {cout << #x << " = " << (x) << endl;}


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

    VVI dp(SZ(s) + 1, VI(SZ(t) + 1));
    VVI bt(SZ(s) + 1, VI(SZ(t) + 1));
    FOR(i, 1, SZ(s) + 1) {
        FOR(j, 1, SZ(t) + 1) {
            dp[i][j] = max(dp[i - 1][j], max(dp[i][j - 1], dp[i - 1][j - 1] + (s[i - 1] == t[j - 1] ? 1 : 0)));
            if (dp[i][j] == dp[i - 1][j - 1] + (s[i - 1] == t[j - 1] ? 1 : 0)) {
                bt[i][j] = 0;
            } else if (dp[i][j] == dp[i - 1][j]) {
                bt[i][j] = 1;
            } else {
                bt[i][j] = 2;
            }
        }
    }

    /*
    REP(i, SZ(s) + 1) {
        REP(j, SZ(t) + 1) {
            cout << bt[i][j] << " ";
        }
        cout << endl;
    }
    */

    string ans = "";
    LL i = SZ(s), j = SZ(t);
    while (i > 0 && j > 0) {
        if (bt[i][j] == 0) {
            if (s[i - 1] == t[j - 1]) {
                ans = s[i - 1] + ans;
            }
            i--;
            j--;
        } else if (bt[i][j] == 1) {
            i--;
        } else {
            j--;
        }
    }
    cout << ans << endl;
	
    return 0;
}


Measured memory_bytes: 141184
#include<bits/stdc++.h>
    using namespace std;
    int main(){
		string s,t;
		int b=-1;
		cin>>s>>t;
		if(s.size()<t.size()){
			cout<<"UNRESTORABLE"<<endl;
			return(0);
		}
		for(int i=0;i<=s.size()-t.size();i++){
			int a=0;
			for(int j=0;j<t.size();j++){
				if(s[i+j]=='?' || s[i+j]==t[j])
					a++;
			}
			if(t.size()==a){
				b=i;
			}
		}
		if(b==-1){
			cout<<"UNRESTORABLE"<<endl;
		}
		else{
			for(int j=0;j<t.size();j++){
				s[j+b]=t[j];
			}
			for(int i=0;i<s.size();i++){
				if(s[i]=='?'){
					cout<<"a";
				}
				else{
					cout<<s[i];
				}
			}
		}
		cout<<endl;
      return(0);
	}

Measured memory_bytes: 256
N = int(input())
A = [int(a) for a in input().split()]
B = [int(a) for a in input().split()]
AA = [A[i] ^ A[i-1] for i in range(N)]
BB = [B[i] ^ B[i-1] for i in range(N)]
P = 8128812823
K = 8128
invK = pow(K, P-2, P)
KN = pow(K, N, P)

s = 0
for i in range(N):
    s = (s * K + AA[i]) % P

t = 0
for b in BB:
    t = (t * K + b) % P
ans = 0
for i in range(N)[::-1]:
    if t == s:
        j = N - 1 - i
        print(j, A[j] ^ B[0])
    t = (t + BB[i] * (KN - 1)) * invK % P


Measured memory_bytes: 128208
#include<cstdio>
#include<queue>
#include<vector>
using namespace std;
const int N=1e5+10;
vector<int>f[N],a;
queue<int>q;
int n,m,p,x,y,in[N],ans,dp[N];
int main()
{
	scanf("%d%d",&n,&m);
	while(m--)
	{
		scanf("%d%d",&x,&y);
		f[x].push_back(y);
		in[y]++;
	}
	for(int i=1;i<=n;i++)
		if(!in[i])q.push(i);
	while(!q.empty())
	{
		p=q.front();
		q.pop();
		a.push_back(p);
		for(int j=0;j<f[p].size();j++)
			if(!--in[f[p][j]])q.push(f[p][j]);
	}
	for(int i=0;i<n;i++)
	{
		for(int j=0;j<f[a[i]].size();j++)
			dp[f[a[i]][j]]=dp[a[i]]+1;
		ans=max(ans,dp[a[i]]);
	}
	printf("%d",ans);
	return 0;
}

Measured memory_bytes: 7032
#include <cstdio>
using namespace std;
int k[15];
int main()
{
    int a, b, c;
    scanf("%d%d%d", &a, &b, &c);
    int sum = c * 3;
    k[1] = a;
    k[2] = b;
    k[3] = sum - k[1] - k[2];
    k[5] = c;
    k[8] = sum - k[2] - k[5];
    k[9] = sum - k[1] - k[5];
    k[6] = sum - k[3] - k[9];
    k[4] = sum - k[5] - k[6];
    k[7] = sum - k[8] - k[9];
    for( int i = 1; i <= 9; i++)
    {
        printf("%d ", k[i]);
        if( i % 3 == 0) puts(" ");
    }
    return 0;
}


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

int main() {
    string s; cin >> s;
    unordered_set<int> a;
    for(int i = 0; i < s.size(); i ++) a.insert(s[i]);
    cout << (s.size()==a.size() ? "yes" : "no") << endl;
}

Measured memory_bytes: 256
local s = {}
local t = {}
local checkt = {}
local checks = {}

for v in string.gmatch(io.read(), "%w") do
  table.insert(s, v)
end

for v in string.gmatch(io.read(), "%w") do
  table.insert(t, v)
end

local result = "Yes"
for i = 1, #s do
  local ct = checkt[t[i]]
  local cs = checks[s[i]]
  if ct ~= s[i] and ct ~= nil then
      result = "No"
      break
  elseif cs ~= t[i] and cs ~= nil then 
      result = "No"
      break
  else
    checkt[t[i]] = s[i]
    checks[s[i]] = t[i]
  end
end

print(result)

Measured memory_bytes: 9396
#include <stdio.h>

int main(){
  int A,B,C;
  scanf("%d %d %d",&A,&B,&C);
  if(A==7 && B==5){
    A=5;
    B=7;
  }
   if(C==7 && B==5){
    C=5;
    B=7;
  }
  if(A==5 && B==7){
    if(C==5) printf("YES");
    else printf("NO");
    return 0;
  }
  else printf("NO");
  return 0;
}

Measured memory_bytes: 128
#pragma comment(linker, "/stack:20000000")
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
using namespace std;

#define rep(i,n) for(int (i)=0;(i)<(int)(n);++(i))
#define For(i,l,u) for(int (i)=(int)(l);(i)<=(int)(u);++(i))
#define all(o) (o).begin(), (o).end()
#define pb(x) push_back(x)
#define mp(x,y) make_pair((x),(y))
#define sz(x) ((int)(x).size())
#define mset(m,v) memset(m,v,sizeof(m))
#define INF 0x3f3f3f3f
#define INFL 0x3f3f3f3f3f3f3f3fLL
typedef vector<int> vi;
typedef pair<int,int> pii;
typedef vector<pair<int,int> > vpii;
typedef long long ll;
typedef unsigned long long ull;

const int inf = 1e9;

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

  int n,m; cin>>n>>m;
  vi a(m),b(m);
  rep(i,m) {
    int mask = 0, r;
    cin>>a[i]>>r;
    rep(j,r) {
      int x; cin>>x; --x;
      mask |= (1<<x);
    }
    b[i] = mask;
  }
  vi dp(1<<n,inf);
  dp[0] = 0;
  rep(i,m) {
    rep(mask,1<<n) {
      dp[b[i]|mask] = min(dp[b[i]|mask], dp[mask]+a[i]);
    }
  }
  int ans = dp[(1<<n)-1];
  if(ans==inf) ans = -1;
  cout<<ans<<endl;
}

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

#define ld long double
#define int long long int
#define ps push_back
#define fi first
#define so second
#define mod 1000000007
#define pii pair<int,int>
#define TT int t;cin>>t;while(t--)
#define ina for(i=0;i<n;i++){cin>>a[i];}

pii solve(int s,vector<int> v[],int p)
{
    if(v[s].size()==1 && v[s][0]==p) return {1,1};
    int pw=1,pb=1;
    pii pc;
    for(int i=0;i<v[s].size();i++)
    {
        if(v[s][i]==p) continue;
        pc = solve(v[s][i],v,s);
        pw = ((pw%mod)*(((pc.fi%mod)+(pc.so%mod))%mod));
        pb = ((pb%mod)*(pc.fi%mod))%mod;
    }
    return {pw,pb};
}

signed main()
{
    int n;
   cin>>n;
   int x,y,i,j,m;
   vector<int> v[n];

   for(i=0;i<n-1;i++)
   {
       cin>>x>>y;
       x--;y--;
       v[x].ps(y);
       v[y].ps(x);
   }
   int vis[n]={0};
   pii p = solve(0,v,-1);
   int ans=0;
   ans = ((p.fi%mod)+(p.so%mod))%mod;
   cout<<ans;
}


Measured memory_bytes: 13440
# -*- coding: utf-8 -*-
import numpy as np

N = np.int64(input())
a = []
for i in range(N):
    a.append([int(x) for x in input().split()])
a = np.array(a)

lowest_person = a[:,0].max()
lowest_score = a[:,1].min()

num_people = lowest_person + lowest_score

print(num_people)

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

#define REP(i,n) for(ll i=0;i<ll(n);++i)
#define RREP(i,n) for(ll i=ll(n)-1;i>=0;--i)
#define FOR(i,m,n) for(ll i=m;i<ll(n);++i)
#define RFOR(i,m,n) for(ll i=ll(n)-1;i>=ll(m);--i)
#define ALL(v) (v).begin(),(v).end()
#define UNIQUE(v) v.erase(unique(ALL(v)),v.end());
#define INF 1000000001ll
#define MOD 1000000007ll
#define EPS 1e-9

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


using namespace std;

using ll = long long;
using vi = vector<int>;
using vl = vector<ll>;
using vvi = vector<vi>;
using vvl = vector<vl>;
using pii = pair<int, int>;
using pll = pair<ll, ll>;

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


int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	int n;
	cin >> n;
	vi v(n);
	REP(i, n)cin >> v[i];
	sort(ALL(v));
	deque<int> q;
	REP(i, n)q.push_back(v[i]);
	int cnta, cntb;
	if (*min_element(ALL(v)) >= 0) {
		cnta = 1;
		cntb = n - 1;

	}
	else  if (*max_element(ALL(v)) <= 0) {
		cnta = n - 1;
		cntb = 1;
	}
	else {
		int c = lower_bound(ALL(v), 0) - v.begin();
		cnta = c, cntb = n - c;
		
	}
	if (cnta < cntb) {
		vector<pii> ans;
		int r = v.back();
		q.pop_back();
		cntb--;
		while (cnta < cntb) {
			int a = q.front(), b = q.back();
			q.pop_front();
			q.pop_back();
			ans.push_back({ a,b });
			q.push_front(a - b);
			cntb--;
		}
		while (q.size() > 1) {
			int a = q.front(), b = q.back();
			q.pop_front();
			q.pop_back();
			if (q.size() % 2 == 0) {
				ans.push_back({ a,b });
				q.push_front(a - b);
			}
			else {
				ans.push_back({ b,a });
				q.push_back(b - a);
			}
		}
		ans.push_back({ r,q.front() });
		cout << r - q.front() << endl;
		REP(i, ans.size()) {
			cout << ans[i].first << " " << ans[i].second << endl;
		}
	}
	else {
		vector<pii> ans;
		while (cnta > cntb) {
			int a = q.front(), b = q.back();
			q.pop_front();
			q.pop_back();
			ans.push_back({ b,a });
			q.push_back(b - a);
			cnta--;
		}
		while (q.size() > 1) {
			int a = q.front(), b = q.back();
			q.pop_front();
			q.pop_back();
			if (q.size() % 2 == 0) {
				ans.push_back({ b,a });
				q.push_back(b - a);
			}
			else {
				ans.push_back({ a,b });
				q.push_front(a - b);
			}
		}
		cout << q.front() << endl;
		REP(i, ans.size()) {
			cout << ans[i].first << " " << ans[i].second << endl;
		}
	}

}

Measured memory_bytes: 3576
#include <iostream>

using namespace std;

int main () {
	int a, b, c;
	int n;
	cin >> n;
	long long a1, b1, c1;
	cin >> a1 >> b1 >> c1;
	for (int i = 1; i < n;  i ++) {
		cin >> a >> b >> c;
		a = a + max(b1, c1);
		b = b + max (a1, c1);
		c = c + max (a1, b1);
		a1 = a;
		b1 = b;
		c1 = c;
	}
	long long ans = max(a1, b1);
	ans = max(ans, c1);
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 3604
using System;
using System.Linq;
using System.Collections.Generic;

public class Program{
    public static void Main(){
        int[] A=Console.ReadLine().Split(' ').Select(x=>int.Parse(x)).ToArray();
        List<int> b=new List<int>();
        b.Add(A[0]+A[1]);
        b.Add(A[0]-A[1]);
        b.Add(A[0]*A[1]);
        Console.WriteLine(b.Max());
    }
}


Measured memory_bytes: 13396
#include <cstdio>
int main()
{
	char ch;
	int a[30] = {0};
	for (int i = 0; i < 4; i++) {
		a[(ch = getchar()) - 'A']++;
	}
	int cnt = 0;
	for (int i = 0; i < 26; i++) {
		if (a[i] == 2)
			cnt++;
	}
	if (cnt == 2)
		printf("Yes\n");
	else
		printf("No\n");
	return 0;
}

Measured memory_bytes: 128
n = int(input())
s = []
alp='abcdefghijklmnopqrstuvwxyz'
con = []
for i in range(n):
    s =input()
    for j in range(26):
        con.append(s.count(alp[j]))
    

ans = ''

for i in range(26):
    num = []
    for j in range(n):
        num.append(int(con[i+j*26]))
    ans += alp[i] * min(num)
print(ans)

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

int main()
{
    const std::string str_false = "Hoshino";
    const std::string str_true = "Hoshina";

    u_int num_of_data;
    std::cin >> num_of_data;
    std::cin.ignore();
    
    for(u_int i = 0; i < num_of_data; ++i){
        std::string text;
        getline(std::cin, text);
        
        int index = 0;
        while((index = text.find(str_false, index)) != std::string::npos){
            text.replace(index, str_false.size(), str_true);
            index += str_false.size();
        }
        std::cout  << text << std::endl;
    }
    
    return 0;
}

Measured memory_bytes: 1212
N,M = map(int,input().split())
AB = [list(map(int,input().split())) for i in range(M)]
 
ans = [-1] * (N+1)
graph = [[] for _ in range(N+1)]
for a,b in AB:
    graph[a].append(b)
    graph[b].append(a)
    

from collections import deque
import sys
ans = [-1] * (N+1)
todo = deque([(1,0)])
while todo:
    x,parent = todo.popleft()
    # ans[x] = parent
    for y in graph[x]:
        if y == parent:
            continue
        if ans[y] != -1:
            continue
        ans[y] = x
        todo.append((y,x))
        

if -1 in ans[2:]:
    print('No')
else:
    print('Yes')
    for i in range(2,N+1):
        print(ans[i])

Measured memory_bytes: 62064
#include <iostream>
#include <string>
#include <vector>
#include <cstdlib>
#include <algorithm>
#include <cmath>
#include <iomanip>
#define rep(i,n) for(int i=0;i<n;i++)
#define rop(i,n) for(int i=1;i<n+1;i++)

using namespace std;
using std::swap;

//vector<long long int> p;
vector<long long int> q;



int main() {

	int r;
	cin >> r;
	cout << pow(r, 2) << "\n";

	return 0;
}

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

A.append(K+A[0])
d = list()
for i in range(0, N):
    d.append(abs(A[i] - A[i+1]))

#print(A)
#print(d)
print(sum(d) - max(d))

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

int main() {
  int H,W;
  cin >> H >> W;
  string s[H];
  int score[H+2][W+2];
  for(int i=0;i<H+2;i++){
    for(int j=0;j<W+2;j++){
      score[i][j]=0;
    }
  }
  for(int i=0;i<H;i++){
    cin >> s[i];
    for(int j=0;j<W;j++){
      if(s[i].at(j)=='#'){
        score[i][j]++;
        score[i][j+1]++;
        score[i][j+2]++;
        score[i+1][j]++;
        score[i+1][j+2]++;
        score[i+2][j]++;
        score[i+2][j+1]++;
        score[i+2][j+2]++;
      }
    }
  }
  for(int i=0;i<H;i++){
    for(int j=0;j<W;j++){
      if(s[i].at(j)=='#'){
        score[i+1][j+1]=-1;
      }
    }
  }
  for(int i=1;i<H+1;i++){
    for(int j=1;j<W+1;j++){
      if(score[i][j]==-1){
        cout << '#';
      }
      else{
        cout << score[i][j];
      }
      if(j==W){
        cout << endl;
      }
    }
  }
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);

    int a, b, x;
    cin >> a >> b;
    for(x=min(a/8*100, 10*b); ; x++){
        if(x*8/100 == a && x/10 == b)
            break;
        if(x*8/100 > a || x/10 > b){
            cout << -1 << '\n';
            exit(0);
        }
    }
    cout << x << '\n';
    return 0;
}


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

#define DEBUG(x) cout << '>' << #x << ':' << x << endl;
#define mem(x,val) memset((x),(val),sizeof(x))
#define all(x) x.begin(),x.end()
#define pb push_back
#define mp make_pair
#define PI acos(-1.0) 
#define N 111111

const int INF = 1 << 30 ;
typedef long long ll ;
typedef pair < int , int > pii ;

int a[N] ;

int main() {
  int n, k, sum = 0 ;
  scanf("%d %d", &n, &k) ;

  for(int i = 0 ;i<n ;i++)scanf("%d", &a[i]) ;
  sort(a, a+n) ;

  for(int i =1 ; i<=k ; i++){
    sum+=a[n-i] ;
  }
  cout << sum << endl ;

	
  return 0 ;
}



Measured memory_bytes: 256
// #include {{{
#include <iostream>
#include <cassert>
#include <cstring>
#include <cstdlib>
#include <cstdio>
#include <cctype>
#include <cmath>
#include <ctime>
#include <queue>
#include <set>
#include <map>
#include <stack>
#include <string>
#include <bitset>
#include <vector>
#include <complex>
#include <algorithm>
using namespace std;
// }}}
// #define {{{
typedef long long ll;
typedef double db;
typedef pair<int,int> pii;
typedef vector<int> vi;
#define de(x) cout << #x << "=" << x << endl
#define rep(i,a,b) for(int i=a;i<(b);++i)
#define per(i,a,b) for(int i=(b)-1;i>=(a);--i)
#define all(x) (x).begin(),(x).end()
#define sz(x) (int)(x).size()
#define mp make_pair
#define pb push_back
#define fi first
#define se second
// }}}

int N;
string str(ll n){
    stringstream ss;
    ss << n;
    string s;
    ss >> s;
    return s;
}

bool check(ll n,ll N) {
    return (n <= N && str(n) <= str(N)) ||
        (n > N && str(n) > str(N));
}

bool ask(ll n){
    printf("? %lld\n",n);
    fflush(stdout);
#ifdef LOCAL
    return check(n , N);
#endif
    static char s[100];
    scanf("%s",s);
    return s[0] == 'Y';
}

void answer(ll x){
    printf("! %lld\n",x);
    exit(0);
}

int main(){
    srand(time(NULL));
    N = rand() + 1;
    ll x = 1 , l = -1 , r = -1;
    rep(i,0,11) {
        if(!ask(x) && l == -1) {
            l = x , r = x * 10;
        }
        x *= 10;
    }
    if(l == -1) {
        for(ll x=10;;x*=10) {
            if(ask(x - 1)) {
                answer(x / 10);
            }
        }
    } else {
        while(l + 1 < r) {
            ll m = (l + r) >> 1;
            if(ask(m)) r = m;
            else l = m;
        }
        answer(r / 10);
    }
    return 0;
}


Measured memory_bytes: 596
macro_rules! scan {
    () => {
        {
            let mut line: String = String::new();
            std::io::stdin().read_line(&mut line).unwrap();
            line.trim().to_string()
        }
    };
    (;;$n:expr) => {
        (0..$n).map(|_| scan!()).collect::<Vec<_>>()
    };
    ($t:ty) => {
        {
            let mut line: String = String::new();
            std::io::stdin().read_line(&mut line).unwrap();
            line.trim().parse::<$t>().unwrap()
        }
    };
    ($($t:ty),*) => {
        {
            let mut line: String = String::new();
            std::io::stdin().read_line(&mut line).unwrap();
            let mut iter = line.split_whitespace();
            (
                $(iter.next().unwrap().parse::<$t>().unwrap(),)*
            )
        }
    };
    ($t:ty;;) => {
        {
            let mut line: String = String::new();
            std::io::stdin().read_line(&mut line).unwrap();
            line.split_whitespace()
                .map(|t| t.parse::<$t>().unwrap())
                .collect::<Vec<_>>()
        }
    };
    ($t:ty;;$n:expr) => {
        (0..$n).map(|_| scan!($t;;)).collect::<Vec<_>>()
    };
    ($t:ty; $n:expr) => {
        (0..$n).map(|_|
                    scan!($t)
        ).collect::<Vec<_>>()
    };
    ($($t:ty),*; $n:expr) => {
        (0..$n).map(|_|
                    scan!($($t),*)
        ).collect::<Vec<_>>()
    };
}

struct Node {
    children: Vec<(usize, i64)>,
}

fn dfs(tree: &[Node], dists: &mut [i64], parent: usize) {
    for &(n, c) in tree[parent].children.iter() {
        if dists[n] == 1 << 60 {
            dists[n] = dists[parent] + c;
            dfs(tree, dists, n);
        }
    }
}

fn dists(tree: Vec<Node>, root: usize) -> Vec<i64> {
    let mut dists = vec![1 << 60; tree.len()];
    dists[root] = 0;
    dfs(&tree, &mut dists, root);

    dists
}
fn main() {
    let n = scan!(i64);
    let mut tree: Vec<Node> = (0..n).map(|_| Node { children: vec![] }).collect();

    for _ in 0..(n - 1) {
        let (a, b, c) = scan!(usize, usize, i64);
        tree[a - 1].children.push((b - 1, c));
        tree[b - 1].children.push((a - 1, c));
    }
    let (q, k) = scan!(i64, usize);
    let dists = dists(tree, k - 1);
    for _ in 0..q {
        let (x, y) = scan!(usize, usize);
        println!("{}", dists[x - 1] + dists[y - 1])
    }
}


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

int main()
{
  int n;
  for(;cin>>n,n;)
    {
      string name[21];
      vector<int> d[21];
      int score[n];
      int point[30];
      for(int i=0;i<n;i++)
	  score[i]=0;
      for(int i=0;i<30;i++)
	  point[i]=n+1;
      for(int i=0;i<n;i++)
	{
	  cin>>name[i];
	  int m;
	  cin>>m;
	  for(int j=0;j<m;j++)
	    {
	      int tmp;
	      cin>>tmp;
	      d[i].push_back(tmp);
	      point[tmp]--;
	    }
	}
      int ansp=999999;
      string ansname;
      for(int i=0;i<n;i++)
	{
	  int tmpp=0;
	  for(int j=0;j<d[i].size();j++)
	    {
	      tmpp+=point[d[i][j]];
	    }
	  if(tmpp<ansp||(tmpp==ansp&&ansname>name[i]))
	    {
	      ansp=tmpp;
	      ansname=name[i];
	    }
	}
      cout<<ansp<<" "<<ansname<<endl;
      
    }

}

Measured memory_bytes: 1244
#include <iostream>
#include <string>
#include <vector>
#include <climits>
#include <algorithm>
using namespace std;

int main() {
  int N, D, X;
  cin >> N >> D >> X;
  int ans = X;
  for (int i=0; i<N; i++) {
    int tmp;
    cin >> tmp;
    ans += (D-1)/tmp + 1;
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
from collections import deque

def bfs(board, visited, gh, gw):
    turn = 0
    queue = deque([[0, 0, turn]])
    while queue:
        h, w, turn = queue.popleft()
        if h == gh-1 and w == gw-1:
            return turn
        for i, j in ([1,0],[-1,0],[0,1],[0,-1]):
            new_h, new_w = h+i, w+j
            if new_h >= gh or new_h < 0 or new_w >= gw or new_w < 0:
                continue
            elif board[new_h][new_w] != "#" and visited[new_h][new_w] == "x":
                visited[new_h][new_w] = "o"
                queue.append([new_h, new_w, turn+1])
    return -1

def main():
    H, W = map(int,input().split())
    board = []
    for _ in range(H):
        board.append(list(input()))
    black = 0
    for i in range(H):
        for j in range(W):
            if board[i][j] == "#":
                black += 1
    visited = [["x"]*W for _ in range(H)]
    path_area = bfs(board, visited, H, W) + 1
    if path_area:
        print(H*W-path_area-black)
    else:
        print(-1)
                
    
    
if __name__ == "__main__":
    main()

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

int main()
{
    int N;
    cin >> N;
    int ct = 0, cx = 0, cy = 0;
    rep(i, N)
    {
        int t, x, y;
        cin >> t >> x >> y;
        int d = abs(x + y - (cx + cy));
        int dt = t - ct;
        cx = x;
        cy = y;
        ct = t;
        if (!(dt >= d && (dt % 2 == d % 2)))
        {
            cout << "No" << endl;
            return 0;
        }
    }
    cout << "Yes" << endl;
    return 0;
}

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

using ll = long long;
using ull = unsigned long long;
#define rep(i, n) for(int i = 0; i < (n); i++)
#define rep1(i, n) for(int i = 1; i < (n); i++)
#define all(a) begin(a),end(a)
template<class T> inline void sort_uniq(T& c) { sort(ALL(c)); c.erase(unique(ALL(c)), c.end()); }
template<class T> istream& operator >> (istream& s, vector<T>& v)
{ for (T& x: v) { s >> x; } return s;}
template<class T> void cout_v(const vector<T>& c)
{ for (int i = 0; i < c.size(); i++) cout << c[i] << endl; }
template<class K, class V> void cout_v(map<K, V>& m)
{ for(auto it=m.begin();it!=m.end();it++)cout<<it->first<<":"<<it->second<<endl;}
template<class T> void cout_h(const vector<T>& c)
{ for (int i = 0; i < c.size(); i++) cout << c[i] << (i==c.size()-1?"\n":" "); }
template<class T> inline bool chmin(T& a, T b) {return a>b?a=b,true:false;}
template<class T> inline bool chmax(T& a, T b) {return a<b?a=b,true:false;}
inline int powi(int x,int y) {int p=1; while(y--) p*=x; return p;}
inline ll powll(ll x,ll y) {ll p=1; while(y--) p*=x; return p;}
template<class T> inline bool is_overlap(const T& a, const T& b, const T& p, const T& q)
{ return p <=b && a <= q; }
#define MOD = 1000000007;
#define SP << " " <<
#define FMT(a) #a<<":"<<a 
#define FMT2(a,b) #a<<":"<<a<<", "<<#b<<":"<<b 
#define FMT3(a,b,c) #a<<":"<<a<<", "<<#b<<":"<<b<<", "<<#c<<":"<<c 
#define FMT4(a,b,c,d) #a<<":"<<a<<", "<<#b<<":"<<b<<", "<<#c<<":"<<c<<", "<<#d<<":"<<d 
void yes(bool f){cout<<(f?"yes":"no")<<endl;}
void Yes(bool f){cout<<(f?"Yes":"No")<<endl;}
void YES(bool f){cout<<(f?"YES":"NO")<<endl;}

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

    int N, K; cin >>N>>K;
    vector<int> h(N); cin >> h;
    sort(all(h));
    
    int ans = INT_MAX;
    for (int i = 0; i <= N - K; i++) {
        chmin(ans, h[i + K - 1] - h[i]);
    }

    cout << ans << endl;
}


Measured memory_bytes: 640
#include <iostream>
using namespace std;
string a;
int main() {
	cin>>a;
	for(int i=1; i<a.size(); i++) {
		if(a[i]==a[i-1]) {cout<<i<<' '<<i+1; return 0;}
		if(a[i]==a[i-2]) {cout<<i-1<<' '<<i+1; return 0;}
	}
	cout<<"-1 -1";
	return 0;
}

Measured memory_bytes: 512
a,b = map(int, input().split())
# n >= (b-1)/(a-1)を満たす最小のnを求める。
ans = 0
if (b-1)%(a-1) == 0:
    ans = (b-1)/(a-1)
elif (b-1)%(a-1) != 0:
    ans = (b-1)//(a-1) + 1
print(int(ans))

Measured memory_bytes: 3060
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace EDPCF2
{
    class Program
    {
        public static int[,] TBL;
        static void Main(string[] args)
        {
            string s = Console.ReadLine();
            string t = Console.ReadLine();
            TBL = new int[s.Length+1, t.Length+1];
            //文字列sのi番目と文字列tのj番目を比べて
            //同じならTBLの値を１プラスする
            //違っているなら上の段または一つ前のTBLの値の大きい方を採用する
            for (int i = 0; i < s.Length; i++)
            {
                for (int j = 0; j < t.Length; j++)
                {
                    if (s.Substring(i,1)==t.Substring(j,1))
                    {
                        TBL[i + 1, j + 1] = TBL[i, j] + 1;
                    }
                    else
                    {
                        TBL[i + 1, j + 1] = Math.Max(TBL[i, j + 1], TBL[i + 1, j]);
                    }
                }
            }
            /*
            for (int i = 0; i <=s.Length; i++)
            {
                for (int j = 0; j <= t.Length; j++)
                {
                    Console.Write(TBL[i,j]);
                }
                Console.WriteLine();
            }
            */
            //TBLの値を逆に辿っていく
            string ans = "";
            int n = s.Length;
            int m = t.Length;
            while(n>0&&m>0)
            {
                    if (TBL[n,m]==TBL[n-1,m])//ひとつ前から来た場合
                    {
                        n--;
                    }
                    else if (TBL[n,m]==TBL[n,m-1])//ひとつ上段から来た場合
                    {
                        m--;
                    }
                    else
                    {
                        ans = s.Substring(n - 1, 1) + ans;//文字が同じだったので値を増やした場合
                        n--;
                        m--;
                    }
            }
            Console.WriteLine(ans);
        }
    }
}


Measured memory_bytes: 50356
#include <cstdio>
#include <iostream>
#include <cstring>
#include <cmath>
#include <algorithm>
using namespace std;

const int N=55;

int n,a[N],h=0;

int main(){
	scanf("%d",&n);
    for(int i=0;i<n;i++){
    	scanf("%d",&a[i]);
        if(abs(a[i])>abs(a[h]))h=i;
    }
    //printf("%d\n",2*n-1);
    cout<<2*n-1<<'\n';
    for(int i=0;i<n;i++){
        cout<<h+1<<' '<<i+1<<'\n';
    }
    if(a[h]>0){
        for(int i=0;i<n-1;i++){
            cout<<i+1<<' '<<i+2<<'\n';
        }
    }else{
        for(int i=n;i>1;i--){
            cout<<i<<' '<<i-1<<'\n';
        }
    }
    return 0;
}


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


int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    int a,b;
    cin>>a>>b;
    ll res=a*3+b;
    res/=2;
    cout<<res<<endl;
    return 0;
    }



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

int main()
{
  int l,r,d;
   cin>>l>>r>>d;
  int ans=0;
  for(int i=l;i<=r;i++)
  {
    if(i%d==0)
      ans++;
  }
  cout<<ans;
}


Measured memory_bytes: 3632
import java.util.*;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		double a = sc.nextDouble();
		sc.close();
		System.out.println(a % 2 == 0 ? "0.5" : (a - ((a - 1.0) / 2.0)) / a);
	}

	public static int[] arrayInt(Scanner sc, int n) {
		int[] array = new int[n];
		for (int i = 0; i < n; i++) {
			array[i] = sc.nextInt();
		}
		return array;
	}

	public static long[] arrayLong(Scanner sc, int n) {
		long[] array = new long[n];
		for (int i = 0; i < n; i++) {
			array[i] = sc.nextLong();
		}
		return array;
	}

	public static double[] arrayDouble(Scanner sc, int n) {
		double[] array = new double[n];
		for (int i = 0; i < n; i++) {
			array[i] = sc.nextDouble();
		}
		return array;
	}
}


Measured memory_bytes: 24788
#include <stdio.h>

int main()
{
	int a,b;
	char op;

	while(scanf("%d %c %d",&a,&op,&b)!=EOF&&op!='?')
	{
		if(op=='+')printf("%d\n",a+b);

		if(op=='-')printf("%d\n",a-b);

		if(op=='*')printf("%d\n",a*b);

		if(op=='/')printf("%d\n",a/b);
	
	}
	return 0;
}


Measured memory_bytes: 2060
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
//const ll MOD = 1e9 + 7;
//const ll MOD = 998244353;
//const ll MOD = ;
ll mod(ll A, ll M) {return (A % M + M) % M;}
const ll INF = 1LL << 60;
template<class T> bool chmin(T& a, T b) {if (a > b) {a = b; return true;} return false;}
template<class T> bool chmax(T& a, T b) {if (a < b) {a = b; return true;} return false;}
ll divceil(ll A, ll B) {return (A + (B - 1)) / B;}
ll myctoi(char C) {return C - '0';}
char myitoc(ll N) {return '0' + N;}
#define FINALANS(A) {cout << (A) << '\n'; exit(0);}

int main()
{
  ll N;
  cin >> N;
  vector<ll> A(N);
  for (ll i = 0; i < N; i++)
  {
    cin >> A.at(i);
  }

  for (ll i = 1; i < N; i++)
  {
    A.at(i) += A.at(i - 1);
  }

  ll ans = INF;
  for (ll i = 0; i < N - 1; i++)
  {
    ll tmp = abs((A.back() - A.at(i)) - A.at(i));
    chmin(ans, tmp);
  }
  cout << ans << endl;
}

Measured memory_bytes: 1792
fn read<T: std::str::FromStr>(
    stdin_lock: &mut std::io::StdinLock,
    buf: &mut Vec<u8>,
    delimiter: u8,
) -> T {
    buf.clear();
    let l = std::io::BufRead::read_until(stdin_lock, delimiter, buf).unwrap();
    buf.truncate(l - 1); // remove delimiter
    let s = unsafe { std::str::from_utf8_unchecked(&buf) };
    s.parse().unwrap_or_else(|_| panic!("read"))
}

fn main() {
    let stdin = std::io::stdin();
    let mut stdin_lock = stdin.lock();
    let mut buf: Vec<u8> = Vec::new();
    let n: i64 = read(&mut stdin_lock, &mut buf, b'\n');
    let a: i64 = read(&mut stdin_lock, &mut buf, b'\n');
    let b: i64 = read(&mut stdin_lock, &mut buf, b'\n');
    let c: i64 = read(&mut stdin_lock, &mut buf, b'\n');
    let d: i64 = read(&mut stdin_lock, &mut buf, b'\n');
    let e: i64 = read(&mut stdin_lock, &mut buf, b'\n');

    let xv = vec![a, b, c, d, e];
    let min_x = xv.iter().min().unwrap();
    let ans = n / min_x + if n % min_x == 0 { 0 } else { 1 } + 4;
    println!("{}", ans);
}


Measured memory_bytes: 4352