akhauriyash/Code-Regression huggingface dataset:
#include <vector>
#include <iostream>
#include <algorithm>
using namespace std;
vector<int> reverse_hash(int x, int b, int l) {
	vector<int> ret(l);
	int mul = 1;
	for (int i = 0; i < l; i++) {
		ret[i] = x / mul % b;
		mul *= b;
	}
	return ret;
}
int transform(int x, int f) {
	vector<int> v1 = reverse_hash(x, 5, 5);
	vector<int> v2 = reverse_hash(f, 4, 4);
	for (int i = 0; i < 4; i++) {
		for (int j = 0; j < 2; j++) {
			if (v1[i + j] != 0) v1[i + j] = (v1[i + j] - 1 + v2[i]) % 4 + 1;
		}
	}
	int ret = 0, mul = 1;
	for (int i = 0; i < 5; i++) {
		ret += v1[i] * mul;
		mul *= 5;
	}
	return ret;
}
int getscore(int x) {
	vector<int> v = reverse_hash(x, 5, 5);
	int ret = 0;
	for (int i = 0; i < 5; i++) {
		if (v[i] == 2) ret += 60;
		if (v[i] == 3) ret += 70;
		if (v[i] == 4) ret += 80;
	}
	return ret;
}
int Q, x;
int main() {
	cin >> Q;
	while (Q--) {
		vector<int> a(5);
		for (int i = 0; i < 5; i++) {
			int mul = 1;
			for (int j = 0; j < 5; j++) {
				cin >> x;
				a[i] += x * mul;
				mul *= 5;
			}
		}
		vector<vector<int> > dp(5, vector<int>(3125, -999999999));
		dp[0][a[0]] = 0;
		for (int i = 0; i < 4; i++) {
			for (int j = 0; j < 3125; j++) {
				if (dp[i][j] == -999999999) continue;
				for (int l = 0; l < 256; l++) {
					int z = transform(a[i + 1], l);
					dp[i + 1][z] = max(dp[i + 1][z], dp[i][j] + getscore(transform(j, l)));
				}
			}
		}
		int ret = 0;
		for (int i = 0; i < 3125; i++) ret = max(ret, dp[4][i] + getscore(i));
		cout << ret << endl;
	}
	return 0;
}

Measured memory_bytes: 3184
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
typedef vector<vector<int> > Graph;
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; }

int main(){
    int r;
    cin >> r;
    double ans;
    ans = r*2*3.1415926535;
    cout<<ans<<endl;

    return 0;
}

Measured memory_bytes: 3788
def to_list(num):
    ret = []
    while num != 0:
        ret.append(num % 10)
        num /= 10
    return ret[::-1]


def is_palindromic(lnum):
    return lnum[0] == lnum[-1] and lnum[1] == lnum[-2]


def increment(lnum):
    if lnum[2] < 9:
        lnum[2] += 1
    elif lnum[1] < 9:
        lnum[1] += 1
        lnum[-2] += 1
        lnum[2] = 0
    else:
        lnum[0] += 1
        lnum[-1] += 1
        lnum[1] = 0
        lnum[-2] = 0
        lnum[2] = 0
    return lnum


def find_first(lnum):
    orig = lnum[::]
    lnum[-1] = lnum[0]
    lnum[-2] = lnum[1]

    while lnum < orig:
        lnum = increment(lnum)

    return lnum


def solve(low, high):
    llow, lhigh = map(to_list, (low, high))
    if not is_palindromic(llow):
        llow = find_first(llow)


    total = 0
    while llow <= lhigh:
        total += 1
        llow = increment(llow)

    return total


def main():
    low, high = map(int, raw_input().strip().split())
    print solve(low, high)


main()


Measured memory_bytes: 2696
#include<bits/stdc++.h>
#define int long long 
using namespace std;
int32_t main(){
	ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int n,m,x;
    cin>>n>>m>>x;
    int mn=LLONG_MAX;
   	int cost[n][m+1];
   	for(int i=0;i<n;++i)
   		for(int j=0;j<=m;++j)
   			cin>>cost[i][j];
   	for(int i=0;i<(1<<n);++i){
   		int curr=0;
   		int temp[m]={0};
   		for(int j=0;j<n;++j){
   			if((i>>j)&1){
   				for(int k=1;k<=m;++k)
   					temp[k-1]+=cost[j][k];
   				curr+=cost[j][0];
   			}
   		}
   		bool poss=1;
   		for(int lp=0;lp<m;++lp)
   			if(temp[lp]<x) poss=0;
   		if(poss)
   		mn=min(mn,curr);
   	}
   	if(mn==LLONG_MAX) cout<<"-1\n";
   	else cout<<mn<<"\n";
    return 0;
}



Measured memory_bytes: 3656
N, M = map(int, input().split())
A = [list(input()) for _ in range(N)]
B = [list(input()) for _ in range(M)]
for i in range(N-M+1):
    for j in range(N-M+1):
        c = 1
        for k in range(M):
            if A[i+k][j:j+M] != B[k]:
                c = 0
        if c:
            print('Yes')
            exit()
print('No')


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

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

int main() {
	cin.tie(0); cout.tie(0); ios_base::sync_with_stdio(0);
	int n; cin>>n;
	int d,x; cin>>d>>x;
	int a, ret=x;
	for (int i=0; i<n; i++)
		cin>>a, ret+=1+(d-1)/a;
	cout << ret << endl;
	return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
template <typename A, typename B>
string to_string(pair<A, B> p);

template <typename A, typename B, typename C>
string to_string(tuple<A, B, C> p);

template <typename A, typename B, typename C, typename D>
string to_string(tuple<A, B, C, D> p);

string to_string(const string &s)
{
    return '"' + s + '"';
}

string to_string(const char *s)
{
    return to_string((string)s);
}

string to_string(bool b)
{
    return (b ? "true" : "false");
}

string to_string(vector<bool> v)
{
    bool first = true;
    string res = "{";
    for (int i = 0; i < static_cast<int>(v.size()); i++)
    {
        if (!first)
        {
            res += ", ";
        }
        first = false;
        res += to_string(v[i]);
    }
    res += "}";
    return res;
}

template <size_t N>
string to_string(bitset<N> v)
{
    string res = "";
    for (size_t i = 0; i < N; i++)
    {
        res += static_cast<char>('0' + v[i]);
    }
    return res;
}

template <typename A>
string to_string(A v)
{
    bool first = true;
    string res = "{";
    for (const auto &x : v)
    {
        if (!first)
        {
            res += ", ";
        }
        first = false;
        res += to_string(x);
    }
    res += "}";
    return res;
}

template <typename A, typename B>
string to_string(pair<A, B> p)
{
    return "(" + to_string(p.first) + ", " + to_string(p.second) + ")";
}

template <typename A, typename B, typename C>
string to_string(tuple<A, B, C> p)
{
    return "(" + to_string(get<0>(p)) + ", " + to_string(get<1>(p)) + ", " + to_string(get<2>(p)) + ")";
}

template <typename A, typename B, typename C, typename D>
string to_string(tuple<A, B, C, D> p)
{
    return "(" + to_string(get<0>(p)) + ", " + to_string(get<1>(p)) + ", " + to_string(get<2>(p)) + ", " + to_string(get<3>(p)) + ")";
}

void debug_out() { cerr << endl; }

template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T)
{
    cerr << " " << to_string(H);
    debug_out(T...);
}

typedef long long ll;
typedef pair<int, int> pii;
#define mp make_pair
#define fst first
#define snd second
#define fr(i, a, b) for(int i=a; i<b; i++)
template<class T = int> using V = vector<T>;
template<class T = int> using VV = V< V<T> >;

int main() {
    cin.tie(nullptr); ios::sync_with_stdio(false);
    ll n, k; cin >> n >> k;
    vector<int> a(n+1); for(int i=1; i<=n; i++) cin >> a[i];
    set<int> s;
    int t = 1; ll cnt = 0;
    while(!s.count(t)) {
        k--;
        
        s.insert(t); t = a[t];
        if(!k) {
            cout << t << endl; return 0;
        }
    }
    ll cnt2 = 0; int t2 = t;
    set<int> s2;
    while(!s2.count(t2)) {
        cnt2++;
        s2.insert(t2); t2 = a[t2];
    }
    // cout << cnt2 << endl;
    // k--;
    k %= cnt2;
    if(!k) {
        cout << t << endl; return 0;
    }
    set<int> s3;
    while(1) {
        k--;
        
        t = a[t];
        if(!k) {
            cout << t << endl; return 0;
        }
    }

}


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

signed main(void){
    int n,k,s; cin >> n >> k >>s;
    int cons;
    if(s<1e8) cons=s+1;
    else cons=s-1;
    for(int i=0;i<k;i++){
        cout << s;
        if(i!=k-1){
            cout << ' ';
        }
    }
    for(int i=0;i<n-k;i++){
        if(i==0){
            cout << ' ';
        }
        cout << cons;
        if(i!=n-k-1){
            cout << ' ';
        }
    }
    cout << endl;
    return 0;
}

Measured memory_bytes: 1280
import java.util.Scanner;

public class Main {

	public static void main (String[] args) {

		Scanner sc = new Scanner (System.in);
		
		String s = sc.next();
		boolean flag = false;
		
		if (s.charAt(0)==s.charAt(1)){
		    if (s.charAt(2)==s.charAt(3)){
		        if (s.charAt(0)==s.charAt(2)){
		        } else {
		        flag = true;
		        }
		    }
		} else if (s.charAt(0)==s.charAt(2)){
		    if (s.charAt(1)==s.charAt(3)){
		        if (s.charAt(0)==s.charAt(1)){
		        } else {
		        flag = true;
		        }
		    }
		} else if (s.charAt(0)==s.charAt(3)){
		    if (s.charAt(1)==s.charAt(2)){
		        if (s.charAt(0)==s.charAt(1)){
		        } else {
		        flag = true;
		        }
		    }
		}
		
		
		if (flag){
		    System.out.println("Yes");
		} else {
		    System.out.println("No");
		}
		

		sc.close();
	}
}


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

namespace AtCoder2 {
	class Program {
		static void Main(string[] args) {

			var inputArray = retreiveLongArray();
			var inputCount = 1;

			// 不正な入力は処理しない
			if (inputArray.Length != inputCount) {
				Console.WriteLine("invalid input");
				return;
			}
			long N = inputArray[0];

			var eigyouInfo = new Dictionary<int, int[]>();
			//午前と午後の区別は付けず0~9の時間帯と考える
			for (int i = 0; i < N; i++) {
				var inp = retreiveLongArray().Select(x =>(int)x).ToArray();
				eigyouInfo.Add(i, inp);
			}

			var profitInfo = new Dictionary<int, int[]>();

			for (int i = 0; i < N; i++) {
				var inp = retreiveLongArray().Select(x => (int)x).ToArray();
				profitInfo.Add(i, inp);
			}

			var maxProfit = int.MinValue;

			//bit全探索する
			for (int i = 1; i < Math.Pow(2, 10); i++) {//1つ以上開店する必要がある
				var openInfo=　new int[10];
				var profit = 0;
				for (int j = 0; j < 10; j++) {
					var x = (i >> j) & 1;//0001と&をとる
					openInfo[j] = x;
				}

				for (int k = 0; k < N; k++) {//各お店との利益影響を計算する
					var rivalInfo = eigyouInfo[k];

					var count = 0;
					for (int j = 0; j < 10; j++) {
						if(rivalInfo[j]==1 & openInfo[j] == 1) {
							count++;
						}
					}
					profit += profitInfo[k][count];

				}

				maxProfit = Math.Max(maxProfit, profit);

			}

			//答えの出力
			var ans = maxProfit;
			Console.WriteLine(ans);

		}

		/// <summary>
		/// スペースで区切られた文字列配列の入力を受け取る
		/// </summary>
		/// <returns></returns>
		private static string[] retreiveStringArray() {
			var inputArray = Console.ReadLine().Split(' ');
			return inputArray;
		}

		/// <summary>
		/// スペースで区切られた整数配列の入力を受け取る
		/// </summary>
		/// <returns></returns>
		private static long[] retreiveLongArray() {
			var inputArray = Console.ReadLine().Split(' ');
			var longArray = inputArray.Select(s => long.Parse(s));
			return longArray.ToArray();
		}
	}
}


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

#define ALL(a)  (a).begin(),(a).end()
#define ALLR(a)  (a).rbegin(),(a).rend()
#define spa << " " <<
#define lfs <<fixed<<setprecision(10)<<
#define test cout<<"test"<<endl;
#define fi first
#define se second
#define MP make_pair
#define PB push_back
#define EB emplace_back
#define rep(i,n,m) for(ll i = n; i < (ll)(m); i++)
#define rrep(i,n,m) for(ll i = n - 1; i >= (ll)(m); i--)
typedef long long ll;
typedef long double ld;
const ll MOD = 1e9+7;
//const ll MOD = 998244353;
const ll INF = 1e18;
using P = pair<ll, ll>;
template<typename T>
void chmin(T &a,T b){if(a>b)a=b;}
template<typename T>
void chmax(T &a,T b){if(a<b)a=b;}
void pmod(ll &a,ll b){a=(a+b)%MOD;}
void pmod(ll &a,ll b,ll c){a=(b+c)%MOD;}
void qmod(ll &a,ll b){a=(a*b)%MOD;}
void qmod(ll &a,ll b,ll c){a=(b*c)%MOD;}
ll median(ll a,ll b, ll c){return a+b+c-max({a,b,c})-min({a,b,c});}
void ans1(bool x){if(x) cout<<"Yes"<<endl;else cout<<"No"<<endl;}
void ans2(bool x){if(x) cout<<"YES"<<endl;else cout<<"NO"<<endl;}
void ans3(bool x){if(x) cout<<"Yay!"<<endl;else cout<<":("<<endl;}
template<typename T1,typename T2>
void ans(bool x,T1 y,T2 z){if(x)cout<<y<<endl;else cout<<z<<endl;}  
template<typename T>
void debug(vector<vector<T>>v,ll h,ll w){for(ll i=0;i<h;i++)
{cout<<v[i][0];for(ll j=1;j<w;j++)cout spa v[i][j];cout<<endl;}};
void debug(vector<string>v,ll h,ll w){for(ll i=0;i<h;i++)
{for(ll j=0;j<w;j++)cout<<v[i][j];cout<<endl;}};
template<typename T>
void debug(vector<T>v,ll n){cout<<v[0];
for(ll i=1;i<n;i++)cout spa v[i];cout<<endl;};
template<typename T>
vector<vector<T>>vec(ll x, ll y, T w){
  vector<vector<T>>v(x,vector<T>(y,w));return v;}
ll gcd(ll x,ll y){ll r;while(y!=0&&(r=x%y)!=0){x=y;y=r;}return y==0?x:y;}
template<typename T>
void emp(map<T,ll>&m, T x){m.emplace(x,0).first->second++;}
vector<ll>dx={1,0,-1,0,1,1,-1,-1};
vector<ll>dy={0,1,0,-1,1,-1,1,-1};

int main(){
  cin.tie(NULL);
  ios_base::sync_with_stdio(false);
  ll res=0,res1=INF,res2=-INF,buf=0;
  bool judge = true;
  ll n;cin>>n;
  vector<ll>b(n-1);
  rep(i,0,n-1)cin>>b[i];
  res=b[0]+b[n-2];
  //cout<<res<<endl;
  buf=b[0];
  rep(i,1,n-1){
    if(buf<=b[i]){
      res+=buf;
      buf=b[i];
    }
    else{
      res+=b[i];
      buf=b[i];
    }
  }
  cout<<res<<endl;

  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define endl '\n'
using namespace std;
typedef long long ll;
const int constant=1e5;
const ll mod=1e9+7;
/*bool p[1000];
void sieve(){
p[0]=p[1]=1;
for(int i=2;i<=100;i++){
    for(int j=i*i;j<=100;j+=i){
        p[j]=1;
    }
}
}*/
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    string s,t,ans="";
    int cntr1,cntr2;
    cin>>s>>t;
    int dp[s.size()+5][t.size()+5];
    for(int i=0;i<=s.size();i++){
        dp[i][0]=0;
    }
    for(int i=0;i<=t.size();i++){
        dp[0][i]=0;
    }
    for(int i=1;i<=s.size();i++){
            for(int j=1;j<=t.size();j++){
        if(s[i-1]==t[j-1]){
            dp[i][j]=1+dp[i-1][j-1];
        }
        else {
            dp[i][j]=max(dp[i-1][j],dp[i][j-1]);
        }
    }
    }
   //cout<<dp[s.size()][t.size()];
    cntr1=s.size();
    cntr2=t.size();
    while((cntr1>0)&&(cntr2>0)){
        if(dp[cntr1][cntr2]==dp[cntr1][cntr2-1]){
            cntr2--;
            continue;
        }
        else if(dp[cntr1][cntr2]==dp[cntr1-1][cntr2]){
            cntr1--;
            continue;
        }

            ans+=s[cntr1-1];
            cntr1--;
            cntr2--;

    }
    reverse(ans.begin(),ans.end());
    cout<<ans;
    return 0;
}


Measured memory_bytes: 35456
#include <algorithm>
#include <bitset>
#include <cmath>
#include <iostream>
#include <limits>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>

using namespace std;
using ll = long long;
const int IINF = 1e9;
const ll INF = 1e18;
const int MOD = 1e9 + 7;

#define dump(x) cout << #x << " = " << (x) << endl;
#define YES(n) cout << ((n) ? "YES" : "NO") << endl

template <typename T>
void dumpvec(vector<T> vec) {
  for (T cnt : vec) {
    cout << cnt << ", ";
  }
  cout << endl;
}

void chmin(ll &a, ll b) {
  if (a > b) {
    a = b;
  }
}
void chmax(ll &a, ll b) {
  if (a < b) {
    a = b;
  }
}

vector<string> split(string s, string delimiter) {
  int first = 0;
  int last = s.find_first_of(delimiter);
  vector<string> result;

  while (first < s.size()) {
    string sub = s.substr(first, last - first);
    result.push_back(sub);
    first = last + 1;
    last = s.find_first_of(delimiter, first);

    if (last == string::npos) {
      last = s.size();
    }
  }

  return result;
}

string join(vector<string> strings, string delimiter) {
  string result = "";
  for (int i = 0; i < strings.size(); i++) {
    if (result != "") result += delimiter;
    result += strings[i];
  }
  return result;
}

int main() {
  int N, K, X, Y;
  cin >> N >> K >> X >> Y;
  if (N <= K) {
    cout << (N * X) << endl;
  } else {
    cout << ((K * X) + ((N - K) * Y)) << endl;
  }
}

Measured memory_bytes: 256
#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <fstream>
#include <sstream>
#include <set>
#include <map>
#include <vector>
#include <list>
#include <algorithm>
#include <cstring>
#include <cmath>
#include <string>
#include <stack>
#include <queue>
#include <bitset>     //UWAGA - w czasie kompilacji musi byc znany rozmiar wektora - nie mozna go zmienic
#include <cassert>
#include <iomanip>        //do setprecision
#include <ctime>
#include <complex>
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 PF push_front
#define MP make_pair
#define LL long long
#define ULL unsigned LL
#define LD long double
#define pii pair<int,int>
#define pll pair<LL,LL>

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


//mod演算ライブラリ
//mod=1000000007

LL add(LL a,LL b){
  return (a+b)%mod;
}

LL sub(LL a,LL b){
  return (a+mod-b)%mod;
}

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

LL power(LL x,LL y){//繰り返し二乗法 単品利用可
  if(y==0)return 1;
  else if(y==1)return x%mod;
  else if(y%2==0){
    LL tmp=power(x, y/2) % mod;
    return tmp*tmp%mod;
  }else {
    LL tmp=power(x, y/2) % mod;
    return ((tmp*tmp)%mod)*x%mod;
  }
}

LL dvs(LL a,LL b){
  return mul(a,power(b,mod-2));
}

const int SIZE_mod=200005;
int invfact[SIZE_mod];
int fact[SIZE_mod];

LL factset(int a){//aまでの階乗%mod表を作成
  fact[0]=1;
  FORQ(i,1,a){
    fact[i]=mul(fact[i-1],i);
  }
}

LL cmbset(int a){//1~aまでの階乗と階乗数の逆元のmod(mod)を用意 O(a)
  factset(a);
  invfact[a]=power(fact[a],mod-2);
  invfact[0]=1;
  FORD(i,a,1){
    invfact[i]=mul(invfact[i+1],i+1);
  }

}

LL cmb(int n,int r){//nCr%mod  (cmbset後に使用)
  if(n<r||r<0||n<0)return 0;
  return mul(fact[n],mul(invfact[r],invfact[n-r]));
}

LL prm(int n,int r){//nPr%mod
    return mul(cmb(n,r),fact[n]);
}

LL homo(int n,int r){//nHr%mod
  return cmb(n+r-1,r);
}


int main(){
	 //cin.tie(0);
	//ios::sync_with_stdio(false);
	//std::cout << std::fixed;
	//std::cout << std::setprecision(12);
	//std::cout << std::defaultfloat;
	int n,m;
	cin>>n>>m;
	vector<int> v(n+3,0);
	vector<int> w(m+1,mod);
	int idx=0;
	v[0]=1;
	FOR(i,0,m){
		cin>>w[i];
	}
	FOR(i,0,n){
		if(i==w[idx]){
			idx++;
			continue;
		}else{
			v[i+2]=add(v[i+2],v[i]);
			v[i+1]=add(v[i+1],v[i]);
		}
	}
	cout<<v[n]<<endl;
	return 0;
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
 
int main(){
  int K; cin >> K;
  vector<int> m={1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51};
  cout << m[K-1] << endl;
  return 0;
}

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

using namespace std;

typedef long long ll;

const int INF = 1e9;
const ll LLINF = 1e18;
const ll MOD = (ll)1e9 + 7;

int main()
{
  int N, Ma, Mb; scanf("%d %d %d", &N, &Ma, &Mb);
  vector<int> A(N), B(N), C(N);
  for (int i = 0; i < N; ++i) {
    scanf("%d %d %d", &A[i], &B[i], &C[i]);
  }
  int upper = 400;
  vector<vector<vector<int>>> dp(N + 5, vector<vector<int>>(upper + 5,
                                                            vector<int>(upper + 5, INF)));
  dp[0][0][0] = 0;
  for (int i = 0; i < N; ++i) {
    for (int a = 0; a <= upper; ++a) {
      for (int b = 0; b <= upper; ++b) {
        dp[i + 1][a][b] = dp[i][a][b];
        if (a >= A[i] and b >= B[i]) {
          dp[i + 1][a][b] = min(dp[i + 1][a][b], dp[i][a - A[i]][b - B[i]] + C[i]);
        }
      }
    }
  }
  int ans = INF;
  for (int a = 0; a <= upper; ++a) {
    for (int b = 0; b <= upper; ++b) {
      if (a == 0 and b == 0) { continue; }
      if (a * Mb == b * Ma) {
        ans = min(ans, dp[N][a][b]);
      }
    }
  }
  if (ans == INF) { ans = -1; }
  printf("%d\n", ans);
  return 0;
}


Measured memory_bytes: 30336
#include<iostream>
#include<string>
#include<cstdio>
#include<cstring>
#include<vector>
#include<cmath>
#include<algorithm>
#include<functional>
#include<iomanip>
#include<queue>
#include<deque>
#include<ciso646>
#include<random>
#include<map>
#include<set>
#include<complex>
#include<bitset>
#include<stack>
#include<unordered_map>
#include<utility>
#include<cassert>
using namespace std;

typedef long long ll;
typedef unsigned long long ul;
typedef unsigned int ui;
typedef long double ld;
const int inf=1e9+7;
const ll INF=1LL<<60 ;
const ll mod=1e9+7 ;
#define rep(i,n) for(int i=0;i<n;i++)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define per1(i,n) for(int i=n;i>=1;i--)
#define Rep1(i,sta,n) for(int i=sta;i<=n;i++)
typedef complex<ld> Point;
const ld eps = 1e-8;
const ld pi = acos(-1.0);
typedef pair<int, int> P;
typedef pair<ld, ld> LDP;
typedef pair<ll, ll> LP;
#define fr first
#define sc second
#define all(c) c.begin(),c.end()
#define pb push_back
#define debug(x)  cout << #x << " = " << (x) << 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; }
#define int long long

void solve() {
	int n, k; cin >> n >> k;
    vector<int> a(n), sum(n + 1, 0);
    rep(i, n) {
        cin >> a[i];
        a[i] --;
        sum[i + 1] = (sum[i] + a[i] + k) % k;
    }
    rep(i, n) {
        sum[i + 1] %= k;
    }
    map<int, int> mp;
    int ans = 0;
    for(int i = 0; i <= n; ++i) {
        if(i - k >= 0) mp[sum[i - k]] --;
        ans += mp[sum[i]];
        mp[sum[i]] ++;
    }
    cout << ans << endl;
}

signed main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	//cout << fixed << setprecision(10);
	//init();
	solve();
	//cout << "finish" << endl;
    return 0;
}

Measured memory_bytes: 15872
A, B, C, D = map(int, input().split())


def gcd(a, b):
    if a < b:
        return gcd(b, a)
    if b == 0:
        return a
    else:
        return gcd(b, a % b)


def lcm(a, b):
    return a * b // gcd(a, b)


print(
    int(
        (B - A)
        - (
            B // C
            - (A - 1) // C
            + B // D
            - (A - 1) // D
            - (B // lcm(C, D) - (A - 1) // lcm(C, D))
        )
        + 1
    )
)


Measured memory_bytes: 3060
import java.util.*;

public class Main {
    public static void main(String[] args) {    
        Scanner sc = new Scanner(System.in);
        int n = 10;
        int[] a = new int[n];
        for (int i = 0; i < n; i++) {
            a[i] = sc.nextInt();
        }
        Arrays.sort(a);
        System.out.println(a[9]);
        System.out.println(a[8]);
        System.out.println(a[7]);
        
    }
        
}

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

using namespace std;

int main()
{
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	
	long long n, m, m1, a, j = 0;
	cin >> n;
	cin >> a;
	j = a;
	cin >> a;
	m = max(j, a);
	m1 = min(j, a);
	if(j > a) j = 0;
	else j = 1;
	for(long long i = 2; i < n; ++i){
		cin >> a;
		if(a > m){
			m1 = m;
			m = a;
			j = i;
		}
		else{
		    if(a == m) m1 = m;
		    else if(a > m1 and a < m) m1 = a;
		}
	}
//	cout << j << " " << m1 << " " << m << endl;
	for(long long i = 0; i < n; ++i){
		if(i == j) cout << m1 << endl;
		else cout << m << endl;
	}

	return 0;
}



Measured memory_bytes: 1664
#include <bits/stdc++.h>
#define rep(i, n) for(int i=0;i<(int)(n);i++)
#define rrep(i,n) for(int i=((int)(n)-1);i>=0;i--)
#define irep(i,n,m) for(int i=(int)(n);i<(int)(m);i++)
#define all(x) (x).begin(),(x).end()
typedef long long ll;
using namespace std;
int main() {
    int a,b;
    cin>>a>>b;
    cout<<(a+b)%24<<endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <queue>
#include <algorithm>
#include <cmath>
#include <bitset>
#include <iomanip>
#include <stack>
#include <list>
#include <map>
#include <unordered_map>
#include <chrono>
#include <numeric>
using namespace std;
using ll = long long;
const long long INF = (long long)1e18+1;
#define DIV 1000000007


int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
#ifdef TEST
    chrono::system_clock::time_point start, end;
    start = chrono::system_clock::now();
#endif
    long idx=0;
    long H, W;
    cin >> H >> W;
    std::vector<std::vector<string>> mat(H, vector<string>(W, ""));
    for(size_t i=0;i<H; i++)
    {
        string line;
        cin >> line;
        for(size_t j=0;j<W; j++)
        {
            mat[i][j] = line[j];
        }
    }
    std::vector<std::vector<long>> mat_count(H, vector<long>(W, 0));
    for(size_t i=0;i<H; i++)
    {
        long count = 0;
        for(size_t j=0;j<W; j++)
        {
            if(mat[i][j] == "#") count = 0;
            else count++;
            mat_count[i][j] += count;
        }
    }
    for(size_t i=0;i<H; i++)
    {
        long count = 0;
        for(size_t j=W-1;j>=0; j--)
        {
            if(mat[i][j] == "#") count = 0;
            else count++;
            mat_count[i][j] += count;
            if(j==0) break;
        }
    }
    for(size_t j=0;j<W; j++)
    {
        long count = 0;
        for(size_t i=0;i<H; i++)
        {
            if(mat[i][j] == "#") count = 0;
            else count++;
            mat_count[i][j] += count;
        }
    }
    for(size_t j=0;j<W; j++)
    {
        long count = 0;
        for(size_t i=H-1;i>=0; i--)
        {
            if(mat[i][j] == "#") count = 0;
            else count++;
            mat_count[i][j] += count;
            if(i==0) break;
        }
    }
    long max_path = 0;
    for(size_t i=0;i<H; i++)
    {
        for(size_t j=0;j<W; j++)
        {
            if(mat[i][j] == ".")
            {
                max_path = max(max_path, -3+mat_count[i][j]);
            }
        }
    }
    cout << max_path << endl;
#ifdef TEST
    end = chrono::system_clock::now();
    cerr << static_cast<double>(chrono::duration_cast<chrono::microseconds>(end - start).count() / 1000.0) << "[ms]" << endl;
#endif
    return 0;
}

Measured memory_bytes: 250496
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0; i < n; i++)
#define ALL(v) (v).begin(), (v).end()

using namespace std;
using ll = long long;

int main()
{
  int N; cin >> N;
  vector<int> d(N); REP(i, N) cin >> d[i];
  sort(ALL(d));
  cout << d[N/2] - d[N/2-1] << endl;
}

Measured memory_bytes: 640
#include<iostream>
#include<climits>
#include<math.h>
#include<vector>
#include<algorithm>
#include<cstdio>
#include<cstring>
#include<stdio.h>
#include <string>
#include <complex>
#include <functional>
#include <map>
#include <queue>
using namespace std;
using ll = long long;
//typedef pair<string,string> P;
//double dat[100][100];
//int dp[6][1010];//動的計画法
//int prime[100001];
//char str[1010][1010];
//typedef pair<ll,ll> A;
//vector<A> pc;
//int ABS(int a){return max(a,-a);}
int main() {
  int r,g,b,n,ans=0;
  cin>>r>>g>>b>>n;
  for(int i=0;i<=n/r;i++){
    for(int j=0;j<=n/g;j++){
      int k=(n-(i*r+j*g))/b;
      if(k<0) continue;
      if(i*r+j*g+k*b==n) {
        ans++;
        //cout<<i<<j<<k<<endl;
      }
    }
  }
  cout<<ans;
  return 0;
}

Measured memory_bytes: 256
//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
#define rep(i, n) for(int i=0; i<n; ++i)
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()
using namespace std;
using ll = int64_t;
using P = pair<int, int>;
using vi = vector<int>;
using vvi = vector<vi>;



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

    ll ans = h*((w-w/3+1)/2 - w/3);

    ans = min(ans, w*((h-h/3+1)/2 - h/3));

    ll x = w/3*h;
    ll y = (w-w/3)*((h+1)/2);
    ans = min(ans, y-x);
    x = max((w+2)/3*h, (w-(w+2)/3)*((h+1)/2));
    y = (w-(w+2)/3)*(h/2);
    ans = min(ans, x-y);

    x = h/3*w;
    y = (h-h/3)*((w+1)/2);
    ans = min(ans, y-x);
    x = max((h+2)/3*w, (h-(h+2)/3)*((w+1)/2));
    y = (h-(h+2)/3)*(w/2);
    ans = min(ans, x-y);

    cout << ans << endl;
}

Measured memory_bytes: 256
//DPコンテスト
#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;

int chmin(int a,int b){
  if(a<b)
    return a;
  else
    return b;
}

int main(){
  int N;
  cin >> N;
  vector<int> data(N);
  for (int i = 0; i < N;i++){
    cin >> data.at(i);
  }
  vector<int> dp(N);
  dp.at(0) = 0;
  dp.at(1) = abs(data.at(1)-data.at(0));
  //cout << dp.at(0) << dp.at(1)<<" ";
  for (int i = 2; i < N; i++)
  {
    int h1 = abs(data.at(i) - data.at(i - 2));
    int h2 = abs(data.at(i) - data.at(i - 1));
    dp.at(i) = chmin(dp.at(i - 2) + h1, dp.at(i - 1) +h2);
    //cout << dp.at(i) << " ";
  }
  cout << dp.at(N - 1) << endl;
}


Measured memory_bytes: 1024
#!/usr/bin/python3
# -*- coding:utf-8 -*-

def main():
  n, k = map(int, input().strip().split())
  vs = list(map(int, input().strip().split()))
  
  max = 0
  for i in range(k+1):
    if i > n:
      break
    for j in range(i+1):
      xs = sorted(vs[:j] + vs[n-(i-j):])
      cand = sum(xs)
      for ik in range(k - (i)):
        if ik >= len(xs):
          break
        if xs[ik] < 0:
          cand -= xs[ik]
      if max < cand:
        max = cand
  print(max)
    

if __name__=='__main__':
  main()



Measured memory_bytes: 3064
#include <stdio.h>
#include <iostream>
using namespace std;

int main(void){
  int n, room[12][10];
  cin >> n;
  for(int i=0; i<12; i++){
    for(int j=0; j<10; j++){
      room[i][j] = 0;
    }
  }
  for(int i=0; i<n; i++){
    int a0, a1, a2, a3;
    int x, y;
    cin >> a0 >> a1 >> a2 >> a3;
    x = (a0-1)*3 + (a1-1);
    y = a2-1;
    room[x][y] += a3;
    //printf("(%d,%d)=%d\n", x, y, a3);
    if(room[x][y] < 0) room[x][y] = 0;
    if(room[x][y] > 9) room[x][y] = 9;
  }
  for(int i=0; i<12; i++){
    if(i!=0 && i%3==0) printf("####################\n");
    for(int j=0; j<10; j++){
      printf(" %d", room[i][j]);
      if(j==9){
        printf("\n");
      }
    }
  }
  return 0;
}



Measured memory_bytes: 3224
def c(n):
  res = 0
  while n > 0:
    res += n % 10
    n //= 10
  return res

n, a, b = map(int, input().split())
ans = 0
for i in range(1, n+1):
  if a <= c(i) <= b:
    ans += i
print(ans)

Measured memory_bytes: 3060
//↓見なくていいよ！ここから--------------------------------------------------
var read = require('readline').createInterface({
  input: process.stdin,
  output: process.stdout
});
var obj;
var inLine = [];
read.on('line', function(input){inLine.push(input);});
read.on('close', function(){
  obj = init(inLine);
  console.error("\n");
  var start = new Date();
  Main();
  var end = new Date() - start;
  
  myerr("time : " + (end) + "ms");
  myerr("memory : " + Math.round(process.memoryUsage().heapTotal / 1024) + "KB");
});
function nextInt(){return myconv(next(),1);} function nextStrArray(){return myconv(next(),2);}
function nextIntArray(){return myconv(next(),4);} function nextCharArray(){return myconv(next(),6);}
function next(){return obj.next();} function hasNext(){return obj.hasNext();}
function init(input){  
  var returnObj = {
    list : input, index : 0, max : input.length,
    hasNext : function(){return (this.index < this.max);},
    next : function(){if(!this.hasNext()){throw "ArrayIndexOutOfBoundsException これ以上ないよ";}else{var returnInput = this.list[this.index];this.index++;return returnInput;}}
  };
  return returnObj;
}
function myout(s){console.log(s);}
function myerr(s){console.error("debug:" + require("util").inspect(s,false,null));}
//[no]要素の扱い。数値型
//不明値、異常時:引数そのまま返す 1:数値へ変換
//2:半角SPで分割 4:半角SPで分割し、数値配列へ
//6:1文字で分割  7:1文字で分割し、数値配列へ
//8:半角SPで結合 9:改行で結合 0:文字なしで結合
function myconv(i,no){try{switch(no){case 1:return parseInt(i);case 2:return i.split(" ");case 4:return i.split(" ").map(Number);case 6:return i.split("");case 7:return i.split("").map(Number);case 8:return i.join(" ");case 9:return i.join("\n");case 0:return i.join("");default:return i;}}catch(e){return i;}}


//↑見なくていいよ！ここまで--------------------------------------------------
function Main(){
	var N = nextInt();
	var list = nextIntArray();
	var check = JSON.parse(JSON.stringify(list));
	check.sort(function(a,b){
		return a - b;
	});
	myerr(check);
	var output = new Array(N);
	var max1 = check[(N / 2)];
	var max2 = check[(N / 2) - 1];
	myerr({max1,max2});
	for(var i = 0; i < N; i++){
		if(max2 == max1){
			output[i] = max1;
		}else{
			if(max2 >= list[i]){
				output[i] = max1;
			}else{
				output[i] = max2;
			}
		}
	}
	myout(myconv(output,9));
}


Measured memory_bytes: 64068
#include <stdio.h>
 
int main()
{
    while (1) {
        int a, b, sol;
        char op;
        scanf("%d %c %d", &a, &op, &b);
        switch (op) {
        case '?' :
            return 0;
        case '*' :
            sol = a * b;
            break;
        case '/' :
            sol = a / b;
            break;
        case '+' :
            sol = a + b;
            break;
        case '-' :
            sol = a - b;
            break;
        }
        printf("%d\n", sol);
    }
}

Measured memory_bytes: 600
t, x, y = 0, 0, 0
for i in range(int(input())):
    next_t, next_x, next_y = map(int, input().split())
    diff = abs(x - next_x) + abs(y - next_y)
    if diff > (next_t - t) or (diff - (next_t - t)) % 2 == 1:
        print("No")
        exit(0)
    t, x, y, = next_t, next_x, next_y
print("Yes")

Measured memory_bytes: 3060
n=int(input())
a=[int(i) for i in input().split()]

t=0
f=0

for i in a:
    if i%4==0:
        f+=1
    elif i%2==0:
        t+=1

if t==0:
    t=1
if n-t+1<=2*f+1:
    print("Yes")
else:
    print("No")




Measured memory_bytes: 14252
// G++ MACRO.CPP -STD=C++14
#include <bits/stdc++.h>
typedef long long ll;
const int INF = 1e9;
const int MOD = 1e9+7;
const ll LINF = 1e18;
using namespace std;

#define dump(x)  cout << #x << " = " << (x) << endl;
#define YES(n) cout << ((n) ? "YES" : "NO"  ) << endl
#define Yes(n) cout << ((n) ? "Yes" : "No"  ) << endl
#define POSSIBLE(n) cout << ((n) ? "POSSIBLE" : "IMPOSSIBLE"  ) << endl
#define Possible(n) cout << ((n) ? "Possible" : "Impossible"  ) << endl
#define possible(n) cout << ((n) ? "possible" : "impossible"  ) << endl

#define SANKOU(n,a,b) cout << ((n) ? (#a) : (#b) ) << endl

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

#define FOREACH(x,a) for(auto& (x) : (a) )

#define WFA(d,v) REP(k,v)REP(i,v)REP(j,v)d[i][j]=min(d[i][j],d[i][k]+d[k][j])

#define SCOUT(x) cout<<(x)<<" "
#define ENDL cout<<endl

#define VECCIN(x) for(auto&youso_: (x) )cin>>youso_
#define VECIN2(x,y) REP(i,x.size())cin>>x[i]>>y[i]
#define VECCOUT(x) for(auto tt=x.begin();tt!=x.end();tt++){if(tt!=x.begin())cout<<" ";cout<<(*tt);}cout<<endl

#define ALL(obj) (obj).begin(),(obj).end()

#define EXIST(n,x) (find(ALL(n),x)!=n.end())
#define UNIQUE(obj) sort(ALL( obj )); obj.erase(unique(ALL(obj)),obj.end())
#define COUT(x) cout<<(x)<<endl
void CINT(){}
template <class Head,class... Tail>
void CINT(Head&& head,Tail&&... tail){
    cin>>head;
    CINT(move(tail)...);
}
#define CIN(...) int __VA_ARGS__;CINT(__VA_ARGS__)
#define LCIN(...) ll __VA_ARGS__;CINT(__VA_ARGS__)
#define SCIN(...) string __VA_ARGS__;CINT(__VA_ARGS__)

template <class T = ll>
T IN(){T x;cin>>x;return (x);}

template <class Head>
void VT(Head head){}
template <class Head,class Seco,class... Tail>
void VT(Head&& head,Seco&& seco,Tail&&... tail){
    seco.resize(head);
    VT(head,move(tail)...);
}
void VT2(){}
template <class Head,class... Tail>
void VT2(Head&& head,Tail&&... tail){
  VECCIN(head);
  VT2(move(tail)...);
}

template <class Head>
void VT3(Head&& head){}
template <class Head,class Seco,class... Tail>
void VT3(Head&& head,Seco&& seco,Tail&&... tail){
  seco[head]=IN();
  VT3(head,move(tail)...);
}

#define VC1(n,...) V __VA_ARGS__;VT(n,__VA_ARGS__);VT2(__VA_ARGS__); //aaabbbccc
#define VC2(n,...) V __VA_ARGS__;VT(n,__VA_ARGS__);REP(i,n)VT3(i,__VA_ARGS__); //abcabcabc

// #include <boost/multiprecision/cpp_int.hpp>
// using namespace boost::multiprecision; // cpp_int

#define P pair<int,int>
#define V vector<int>
#define M map<int,int>
#define S set<int>
#define PQ priority_queue<int>
#define PQG priority_queue<int,V,greater<int>>

#define str string

#define pb(a) push_back(a)
#define mp make_pair

int main(){

  LCIN(s);
  V v;
  while(s){
    v.pb(s%10);
    s/=10;
  }


  ll ans=accumulate(ALL(v),0LL);
  REPR(i,v.size()-1){
    ll k = 0;
    k = v[i]-1;
    REPR(j,i-1){
      k += 9;
    }
    ans = max(ans,k);
  }


  COUT(ans);

  return 0;
}





Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <set>
#include <math.h>
using namespace std;

int main(){
    int N, X;
    int m[110];
    int total = 0;
    int m_min = 1000;

    cin >> N >> X;
    for(int i =0; i < N; ++i){
        cin >> m[i];
        total += m[i];
        m_min = min(m_min, m[i]); 
    }
    cout << N + ( X - total ) / m_min << endl;
}

Measured memory_bytes: 888
#include <bits/stdc++.h>
#define long long long
#define up(i,a,b) for (int i=a; i<=b; i++)
#define down(i,a,b) for (int i=a; i>=b; i--)
#define endl '\n'
#define X first
#define Y second
#define II pair<int, int>
#define III pair<int, pair<int, int> >
#define debug(X) cerr<< #X << " = " <<X << endl
#define debug2(X,Y) cerr<< #X << " = " <<X << ","<<#Y<<" = "<<Y<<endl
#define show(X,a,b) {cerr << #X << " = "; up(__,a,b) cerr << X[__] << ' '; cerr << endl;}
#define gc getchar
#define pc putchar
using namespace std;

char aa[5];
int a[5];
int d[5];
void input()
{
    up(i,1,4) cin>>aa[i];
    up(i,1,4) a[i]= (int)(aa[i]- '0');
}
void duyet(int x,int sum)
{
    if (x== 5)
	{
		if (sum== 7)
		{
            up(i,1,3)
            {
            	cout<<a[i];
            	if (d[i]== 0) cout<<'-';
            	else cout<<'+';
            };
            cout<<a[4]<<'='<<7;
			exit(0);
		}
		return;
	}
    d[x-1]= 0;
    duyet(x+1,sum- a[x]);
    d[x-1]= 1;
    duyet(x+1, sum+ a[x]);
}
void solve()
{
    duyet(2,a[1]);
}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);// don't use when interactive

    #ifdef I_Love_Pork
    #define TASK "tmp"
    freopen(TASK".inp","r",stdin);
    freopen(TASK".out","w",stdout);
	  #endif

    input();
    solve();

    return 0;
}


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

int main() {
  int A, B;
  cin >> A >> B;
  if (A > 8)
  {
    cout << ":(" << endl;
  }
  else if (B > 8)
  {
    cout << ":(" << endl;
  }
  else
  {
    cout << "Yay!" << endl;
  }
}

Measured memory_bytes: 3584
import java.util.*;

@SuppressWarnings("unchecked")
public class Main {
	// public static void printArray(int[] a) {
	// 	for (int i = 0; i < a.length; i++) {
	// 		System.out.print(a[i] + ", ");
	// 	}
	// 	System.out.println();
	// }

	// public static<T> void printArrayT(T[] a) {
	// 	for (int i = 0; i < a.length; i++) {
	// 		System.out.print(a[i] + ", ");
	// 	}
	// 	System.out.println();
	// }

	public static String joinInt(int[] a, String separator) {
		StringBuilder sb = new StringBuilder();
		for (int i = 0; i < a.length; i++) {
			if (i > 0) {
				sb.append(separator);
			}
			sb.append(a[i]);
		}
		return sb.toString();		
	}

	static int[] nextIntArray(Scanner sc, int N) {
		int[] arr = new int[N];
		for (int i = 0; i < N; i++) {
			arr[i] = sc.nextInt();
		}
		return arr;
	}

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		double A = sc.nextInt();
		double B = sc.nextInt();
		double X = sc.nextInt();
		if (X >= A*A*B/2) {
			double x = X / A;
			double space = A*B - x;
			double h = 2 * space / A;
			double rad = Math.atan(h/A);
			System.out.println(rad * 180 / Math.PI);
		} else {
			double x = X / A;
			double h = 2 * x / B;
			double rad = Math.atan(B/h);
			System.out.println(rad * 180 / Math.PI);
		}
	}
}


Measured memory_bytes: 23764
#include <stdio.h>
#include <iostream>
#include <math.h>
#include <string>
#include <vector>
#include <algorithm>
#include <iomanip>

//#include <tuple>

//#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < (int)n; i++)
#define ll long long
#define pb push_back

int main() {
  int N, K;
  cin >> N >> K;
  vector<int> h(N);

  rep(i, N){
    cin >> h[i];
  }

  sort(h.begin(), h.end());
  int ans = h[N-1]-h[0];
  for(int i = K-1; i < N; i++){
    ans = min(ans, abs(h[i]-h[i-K+1]));
  }
  
  cout << ans << endl;

}


Measured memory_bytes: 640
#include<bits/stdc++.h>
using namespace std;
bool zhishu(int x)
{
    for(int i=2;i<=sqrt(x);i++)
    if(x%i==0)
    return 0;
    return 1;
}
int main()
{
	int n;
	cin>>n;
	vector<int> a;
	for(int i=3;i<66666666;i++)
	{
		if(zhishu(i)==1&&i%5==1)
		a.push_back(i); 
		if(a.size()==n)
		{
			for(int i=0;i<n;i++)
			cout<<a[i]<<" ";
			return 0;
		}
	}
}

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

int main() {
  int N;
  cin >> N;
  vector<int> vec(N);
  for (int i = 0; i < N; i++){
    cin >> vec.at(i);
  }
  int64_t sum = 0;
  for (int i = 1; i < N; i++){
    if (vec.at(i - 1) > vec.at(i)){
      sum += (vec.at(i - 1) - vec.at(i));
      vec.at(i) = vec.at(i - 1);
    }
  }
  cout << sum << endl;
}



Measured memory_bytes: 4056
#include <bits/stdc++.h>
using namespace std;
#define MAX 260
int main() {
	int mx, n;
	while (cin >> mx, mx) {
		cin >> n;
		vector<int> v(n + 2, 0);
		for (int i = 1; i <= n; i++) {
			cin >> v[i];
		}
		bool vs[MAX] = { 0 };
		vs[0] = 1;
		queue<int> Q;
		Q.push(0);

		while (!Q.empty()) {
			int now = Q.front();
			Q.pop();
			if (now == n + 1) {
				continue;
			}

			for (int i = 1; i <= mx; i++) {
				int next = min(n + 1, now + i);
				next += v[next];
				if (next < 0) {
					next = 0;
				} else if (next > n + 1) {
					next = n + 1;
				}
				if (!vs[next]) {
					vs[next] = 1;
					Q.push(next);
				}
			}
		}
		bool flg = 1;
		for (int i = 0; i <= n; i++) {
			if (!vs[i]) {
				continue;
			}
			bool ng = 1, vs2[MAX] = { 0 };
			queue<int> Q2;
			Q2.push(i);
			vs2[i] = 1;
			while (!Q2.empty()) {
				int now = Q2.front();
				Q2.pop();
				if (now == n + 1) {
					ng = 0;
					break;
				}
				for (int i = 1; i <= mx; i++) {
					int next = min(n + 1, now + i);
					next += v[next];
					if (next < 0) {
						next = 0;
					} else if (next > n + 1) {
						next = n + 1;
					}
					if (!vs2[next]) {
						vs2[next] = 1;
						Q2.push(next);
					}
				}
			}
			if (ng) {
				flg = 0;
				break;
			}
		}
		cout << (flg && vs[n + 1] ? "OK" : "NG") << endl;
	}
	return 0;
}

Measured memory_bytes: 3132
import java.util.*;
public class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);

    int N = sc.nextInt();
    int a[] = new int[N];
    for(int i=0;i<N;i++){
      a[i]=sc.nextInt();
    }
    int x[] = new int[100002];
    for(int i=0;i<N;i++){
      x[a[i]]++;
      x[a[i]+2]++;
      x[a[i]+1]++;
    }
    Arrays.sort(x);
  System.out.println(x[100001]);
  }
    


}


Measured memory_bytes: 48948
#include <bits/stdc++.h>
#define REP(i,n) for(int i=0;i<n;i++)
#define REPP(i,n) for(int i=1;i<=n;i++)
const double PI = acos(-1);
const double EPS = 1e-15;
long long INF=(long long)1E17;
#define i_7 (long long)(1E9+7)
long mod(long a){
    long long c=a%i_7;
    if(c>=0)return c;
    return c+i_7;
}
using namespace std;
bool prime_(int n){
  if(n==1){
    return false;
  }else if(n==2){
    return true;
  }else{
    for(int i=2;i<=sqrt(n);i++){
      if(n%i==0){
        return false;
      }
    }
    return true;
  }
}

long long gcd_(long long a, long long b){
  if(a<b){
    swap(a,b);
  }
  if(a%b==0){
    return b;
  }else{
    return gcd_(b,a%b);
  }
}
 
long long lcm_(long long x, long long y){
  return (x/gcd_(x,y))*y;
}
 
class UnionFind {
    public:
    //各頂点の親の番号を格納する。その頂点自身が親だった場合は-(その集合のサイズ)を入れる。
    vector<int> Parent;
    
    //クラスを作るときは、Parentの値を全て-1にする。
    //以下のようにすると全てバラバラの頂点として解釈できる。
    UnionFind(int N) {
        Parent = vector<int>(N, -1);
    }
    
    //Aがどのグループに属しているか調べる
    int root(int A) {
        if (Parent[A] < 0) return A;
        return Parent[A] = root(Parent[A]);
    }
    
    //自分のいるグループの頂点数を調べる
    int size(int A) {
        return -Parent[root(A)];//先祖をrootで取っておきたい。
    }
    
    //AとBをくっ付ける
    bool connect(int A, int B) {
        //AとBを直接つなぐのではなく、root(A)にroot(B)をくっつける
        A = root(A);
        B = root(B);
        if (A == B) {
            //すでにくっついてるからくっ付けない
            return false;
        }
        
        //大きい方(A)に小さいほう(B)をくっ付けたい
        //大小が逆だったらAとBをひっくり返す。
        if (size(A) < size(B)) swap(A, B);
        
        //Aのサイズを更新する
        Parent[A] += Parent[B];
        //Bの親をAに変更する
        Parent[B] = A;
        
        return true;
    }
};

int main(){
  
  int n,x;
  cin>>n>>x;
  if(x==1 || x==2*n-1){
    cout<<"No"<<endl;
    return 0;
  }
  
  vector<int> ans(2*n, -1);//1~(2*n-1)の範囲のみ使う
  vector<bool> used(2*n,false);//1~(2*n-1)の範囲のみ使う
  ans[n] = x;
  used[x] = true;
  ans[n-1] = x - 1;
  used[x-1] = true;
  ans[n+1] = x + 1;
  used[x+1] = true;
  
  int next_ = 1;
  REPP(i,2*n-1){
    if(ans[i]>0)continue;
    while(used[next_])next_++;
    ans[i] = next_;
    used[next_] = true;
  }
  
  cout<<"Yes"<<endl;
  REPP(i,2*n-1){
    cout<<ans[i]<<endl;
  }
  
  return 0;
}


Measured memory_bytes: 2304
#include <bits/stdc++.h>
#include <algorithm>
using namespace std;
typedef long long ll;
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;}

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

    ll ans = n - 1;

    for(ll i = 2; i * i <= n; i++){
        if(n % i == 0){
            ll b = n / i;
            ans = min(ans, i + b - 2);
        }
    }

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
main(){
  int n,h,i,j,k,smp=0;
  n<=50;
  while(scanf("%d",&n) != EOF){
  for(h=0;h<=9;h++){
    for(i=0;i<=9;i++){
      for(j=0;j<=9;j++){
	for(k=0;k<=9;k++){
	  if(n==h+i+j+k)smp++;
	}
      }
    }
  }
  printf("%d\n",smp);
  smp=0;
  }
 return 0;
}

Measured memory_bytes: 596
#include <iostream>
#include <bits/stdc++.h>
#define mp make_pair
#define pb push_back
using namespace std;
using ll = long long int;
const int p = 1e9 + 7;
void solve(){
    int n;
    cin>>n;
    vector<vector<int>> adj(n);
    for(int i=0;i<n-1;i++){
        int u,v;
        cin>>u>>v;
        --u;--v;
        adj[u].pb(v);
        adj[v].pb(u);
    }
    vector<ll> dpblack(n, 1);
    vector<ll> dpwhite(n, 1);
    function<void(int,int)> dfs = [&](int u, int par){
        ll &w = dpwhite[u];
        ll &b = dpblack[u];
        for(const auto &e : adj[u]){
            if(e==par){
                continue;
            }
            dfs(e, u);
            w*=(dpblack[e] + dpwhite[e]);
            b*=dpwhite[e];
            w%=p;
            b%=p;
        }
    };
    dfs(0,-1);
    cout<<(dpblack[0] + dpwhite[0])%p;
}
int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    solve();
}

Measured memory_bytes: 18408
#include <iostream>
#include <string>
#include <vector>

#define MAX_V 100010
using namespace std;

vector<int> G[MAX_V];
bool used[MAX_V];
long long ans=0,l;
char a[MAX_V];
int div2(long long n){
	int k = 1;
	while(n%2==0){
		k++;
		n /= 2;
	}
	return k;
}

void dfs(int s, long long d){
	used[s] = true;
	if(G[s].size()==1){
		ans ^= div2(l - d);
	}
	for(int i=0;i<G[s].size();i++){
		if(!used[G[s][i]]){
			dfs(G[s][i],d+1);
		}
	}
}

int main(){
	int i,j,n,k=0;
	cin >> n >> l;
	for(i=0;i<n;i++){
		string s;
		cin >> s;
		int y = 0;
		for(j=0;j<s.size();j++){
			if(G[y].size()==0){
				k++;
				G[y].push_back(k);
				a[k] = s[j];
			}
			for(int x = 0; x<G[y].size();x++){
				if(a[G[y][x]]==s[j]){
					y = G[y][x];
					break;
				}
				if(x==G[y].size()-1){
					k++;
					G[y].push_back(k);
					a[k] = s[j];
					y = k;
				}
			}
		}
	}
	
	dfs(0,0);
	if(ans!=0){
		cout << "Alice" << endl;
	}else{
		cout << "Bob" << endl;
	}
}


Measured memory_bytes: 10752
#include <iostream>
typedef long long ll;
using namespace std;

int n, w;
ll W[101];
ll V[101];

int main(void){
    // Your code here!
    cin >> n >> w;
    for(int i = 0; i < n; i++) cin >> W[i] >> V[i];
    
    ll dp[n+1][w+1];
    for(int i = 0; i <= n; i++) for(int j = 0; j <= w; j++) dp[i][j] = 0;
    
    for(int i = 0; i < n; i++){
        for(int j = 0; j <= w; j++){
            dp[i+1][j] = max(dp[i+1][j], dp[i][j]);
            if(j-W[i] >= 0) dp[i+1][j] = max(dp[i+1][j], dp[i][j - W[i]] + V[i]);
        }
    }
    
    cout << dp[n][w] << endl;
    return 0;
}


Measured memory_bytes: 79104
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		
		double W = sc.nextDouble();
		double H = sc.nextDouble();
		int x = sc.nextInt();
		int y = sc.nextInt();
		
		String s = "";
		if(x == W/2 && y == H/2) {
			s = "1";
		}else {
			s = "0";
		}
		
		double face = W*H/2;
		
		System.out.println(face + " " + s);
		
		sc.close();
	}

}

Measured memory_bytes: 25172