akhauriyash/Code-Regression huggingface dataset:
import math
h,w = map(int,input().split())
lis = []

a = math.floor(h/3)
b = math.ceil(h/3)
c = h-(a + b)
lis.append(w * (max(a,b,c)-min(a,b,c)))

biga = math.ceil(h/3)
smalla = math.floor(h/3)
if biga-(h/3) >= (h/3)-smalla:
    a = smalla
else:
    a = biga
b = math.ceil(w/2)
c = w - b
b *= (h-a)
c *= (h-a)
a *= w
lis.append(max(a,b,c)-min(a,b,c))

a = math.floor(w/3)
b = math.ceil(w/3)
c = w-(a + b)
lis.append(h * (max(a,b,c)-min(a,b,c)))

biga = math.ceil(w/3)
smalla = math.floor(w/3)
if biga-(w/3) >= (w/3)-smalla:
    a = smalla
else:
    a = biga
b = math.ceil(h/2)
c = h - b
b *= (w-a)
c *= (w-a)
a *= h
lis.append(max(a,b,c)-min(a,b,c))

print(min(lis))

Measured memory_bytes: 3064
#include <iostream>
#include <algorithm>
#include <utility>
#define rep(i,n) for(int i=0;i<n;i++)
using namespace std;

long gcd(long x,long y){
	if(y>x) swap(x,y);
	long tmp;
	while(x%y!=0){
		tmp=x;
		x=y; y=tmp%y;
	}
	return y;
}
long lcm(long x,long y){
	return (x/gcd(x,y)*y);
}

int main()
{
	int n; cin>>n;
	long t,ans; cin>>ans;
	rep(i,n-1){
		cin>>t;
		ans=lcm(t,ans);
	}
  	cout<<ans<<endl;
  	return 0;
}


Measured memory_bytes: 256
fn main() {
    let s: String = {
        let mut buffer = String::new();
        std::io::stdin().read_line(&mut buffer).unwrap();

        buffer.trim().to_string()
    };

    let mut unbalanced = None;
    let mut mae = (None, None);

    for (i, c) in s.chars().enumerate() {
        if let Some(mc) = mae.0 {
            if mc == c {
                unbalanced = Some((i - 1, i));
                break;
            }
        }

        if let Some(mc) = mae.1 {
            if mc == c {
                unbalanced = Some((i - 2, i));
                break;
            }
        }

        mae.1 = mae.0;
        mae.0 = Some(c);
    }

    if let Some((i, j)) = unbalanced {
        println!("{} {}", i + 1, j + 1);
    } else {
        println!("-1 -1");
    }
}


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

int main()
{
	ll n,k,r,s,p,i;
	cin>>n>>k>>r>>s>>p;
	string sr,t="";
	cin>>sr;
	ll ans=0;
	for(i=0;i<k;i++)
	{
		if(sr[i]=='r')
		{
			t=t+'p';
			ans+=p;
		}
		else if(sr[i]=='s')
		{
			t=t+'r';
			ans+=r;
		}
		else
		{
			t=t+'s';
			ans+=s;
		}
	}
	for(i=k;i<n;i++)
	{
		char ch=t[i-k];
		char w=sr[i-k];
		if(sr[i]=='p')
		{
			if(ch=='s')
			{
				if(w=='p')
				{
					t=t+'p';
				}
				else if(w=='s')
				{
					t[i-k]='r';
					t=t+'s';
					ans+=s;
				}
			}
			else
			{
				t=t+'s';
				ans+=s;
			}
		}
		else if(sr[i]=='s')
		{
			if(ch=='r')
			{
				if(w=='s')
				{
					t=t+'s';
				}
				else if(w=='r')
				{
					t[i-k]='p';
					t=t+'r';
					ans+=r;
				}
			}
			else
			{
				t=t+'r';
				ans+=r;
			}
		}
		else
		{
			if(ch=='p')
			{
				if(w=='r')
				{
					t=t+'r';
				}
				else if(w=='p')
				{
					t[i-k]='s';
					t=t+'p';
					ans+=p;
				}
			}
			else
			{
				t=t+'p';
				ans+=p;
			}
		}
	}
	cout<<ans<<endl;
}

Measured memory_bytes: 864
using System;
using System.Collections.Generic;
using System.Linq;
using static System.Console;
 
class Program
{
    static void Main()
    {
        var NM = ReadLine().Split().Select(int.Parse).ToArray();
        var N = NM[0];
        var M = NM[1];
        var L = new int[M];
        var R = new int[M];
        var D = new int[M];
        for (int i = 0; i < M; i++)
        {
            var LRD = ReadLine().Split().Select(int.Parse).ToArray();
            L[i] = LRD[0] - 1;
            R[i] = LRD[1] - 1;
            D[i] = LRD[2];
        }
        var uf = new WeightedUnionFind(N);
        for (int i = 0; i < M; i++)
        {
            if (uf.Same(L[i], R[i]))
            {
                if (D[i] != uf.Diff(L[i], R[i]))
                {
                    WriteLine("No");
                    return;
                }
            }
            else
            {
                uf.Unite(L[i], R[i], D[i]);
            }
        }
        WriteLine("Yes");
    }
}
 
public class WeightedUnionFind
{
    int[] parent;
    long[] weightDiff;
    int count;
    public int Count => count;
    public WeightedUnionFind(int size)
    {
        parent = new int[size];
        for (int i = 0; i < parent.Length; i++)
        {
            parent[i] = -1;
        }
        weightDiff = new long[size];
        count = size;
    }

    int Root(int x)
    {
        if (parent[x] < 0)
        {
            return x;
        }
        else
        {
            var r = Root(parent[x]);
            weightDiff[x] += weightDiff[parent[x]];
            return parent[x] = r;
        }
    }

    long Weight(int x)
    {
        Root(x);
        return weightDiff[x];
    }

    public long Diff(int x, int y) => Weight(y) - Weight(x);

    public bool Same(int x, int y) => Root(x) == Root(y);

    public void Unite(int x, int y, long w)
    {
        w += weightDiff[x] - weightDiff[y];
        x = Root(x);
        y = Root(y);
        if (x == y) return;
        count--;
        if (parent[x] > parent[y])
        {
            parent[y] += parent[x];
            parent[x] = y;
            weightDiff[x] = -w;
        }
        else
        {
            parent[x] += parent[y];
            parent[y] = x;
            weightDiff[y] = w;
        }
    }

    public int Size(int x) => -parent[Root(x)];
}


Measured memory_bytes: 20744
class Node
	attr_accessor :prev, :next, :value
	def initialize value
		@value = value
	end
end

class DoubllyLinkedList
	def initialize
		@nil_node = Node.new nil
		@nil_node.next = @nil_node.prev = @nil_node
	end

	def insert value
		node = Node.new value
		node.next = @nil_node.next
		node.prev = @nil_node
		@nil_node.next.prev = node
		@nil_node.next = node
	end

	def search value
		node = @nil_node.next
		node = node.next until node == @nil_node || node.value == value
		node
	end

	def deleteNode node
		node.prev.next = node.next
		node.next.prev = node.prev
	end

	def delete value
		node = search value
		deleteNode node unless node == @nil_node
	end

	def deleteFirst dummy
		deleteNode @nil_node.next
	end

	def deleteLast dummy
		deleteNode @nil_node.prev
	end

	def values
		arr = []
		node = @nil_node.next
		until node == @nil_node
			arr << node.value
			node = node.next
		end
		arr
	end
end

dll = DoubllyLinkedList.new
n = gets.to_i
n.times{
	line = gets.chomp.split
	dll.send line[0], line[1]
}
puts dll.values.join(" ")

Measured memory_bytes: 147212
using System;
using System.Linq;

namespace ConsoleApp1
{
    class Program
    {
        static void Main(string[] args)
        {
            var array = Console.ReadLine().Split().Select(int.Parse).ToArray();
            int n = array[0], m = array[1], x = array[2], y = array[3];
            int[] X = Console.ReadLine().Split().Select(int.Parse).ToArray();
            int[] Y = Console.ReadLine().Split().Select(int.Parse).ToArray();

            var answers = from z in Enumerable.Range(x + 1, y - x)
                          where X.All(v => v < z) && Y.All(v => v >= z)
                          select z;

            Console.WriteLine(answers.Any() ? "No War" : "War");
        }
    }
}

Measured memory_bytes: 13396
/*************************************************************************
  >         File: C.cc
  >       Author: lyyllyyl
  >         Mail: riho.yoshioka@yandex.com
  > Created Time: Mon 12 Sep 2016 11:19:31 PM CST
*************************************************************************/
#include <bits/stdc++.h>
using LL = long long;

LL Get(int x) {
  if (x <= 1) return 1;
  else return 1LL << (x - 1);
}

int main() {
  std::ios::sync_with_stdio(0);
  std::string string;
  std::cin >> string;
  LL answer = 0;
  for (int i = 0; i < (int) string.size(); ++i) {
    for (int j = i + 1; j <= (int) string.size(); ++j) {
      auto value = std::stoll(string.substr(i, j - i));
      answer += Get(i) * Get(string.size() - j) * value;
    }
  }
  std::cout << answer << std::endl;
  return 0;
}


Measured memory_bytes: 256
n,m=map(int,raw_input().split())
x=map(int,raw_input().split())
d={}
for i in xrange(m):
    d[i] = []
for i in xrange(n):
    d[x[i]%m].append(x[i])
c=0
c+=len(d[0])/2
if m%2==0:
    c+=len(d[m/2])/2
for i in xrange(1,(m-1)/2+1):
    a=d[i]
    b=d[m-i]
    if len(a)==len(b):
        c+=len(a)
    elif len(a)<len(b):
        b=sorted(b)
        tmp=0
        i=0
        while i<len(b)-1:
            if b[i] == b[i+1] and len(a)<=len(b)-(tmp+1)*2:
                tmp+=1
                i+=1
            i+=1
        c+=tmp+len(a)
    else:
        a=sorted(a)
        tmp=0
        i=0
        while i<len(a)-1:
            if a[i] == a[i+1] and len(b)<=len(a)-(tmp+1)*2:
                tmp+=1
                i+=1
            i+=1
        c+=tmp+len(b)

print c

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

public class Main {
	public static void main(String[] args) {
		BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
	    
		String x = "";
		try {
			int num = Integer.parseInt(in.readLine());
			
			x = in.readLine();
			String[] nums = x.split(" ");
			
			int[] a = new int[num];
			for (int i = 0; i < num; i++) {
				a[i] = Integer.parseInt(nums[i]);
			}

			System.out.print(a[0]);
			for (int j = 1; j < num; j++) {
				System.out.print(" " + a[j]);
			}
			System.out.println();
			
			for (int i = 1; i < num; i++) {
				int key = a[i];
				
				int j = i - 1;
				while ((j >= 0) && (a[j] > key)) {
					a[j + 1] = a[j];
					j--;
					a[j + 1] = key;
				}
				
				System.out.print(a[0]);
				for (j = 1; j < num; j++) {
					System.out.print(" " + a[j]);
				}
				System.out.println();
			}
		} catch (NumberFormatException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}
}

Measured memory_bytes: 30492
n,k=map(int,input().split())
a=list(map(int,input().split()))
a=sorted(a)
mod=10**9+7
ans=0
f=[1]
for i in range(1,n+1):
    f.append((f[-1]*i)%mod)
for i in range(n-k+1):
    ans+=(f[k+i-1]*pow(f[i],mod-2,mod)*pow(f[k-1],mod-2,mod))*(a[k-1+i]-a[n-k-i])
print(ans%mod)

Measured memory_bytes: 14040
#include <stdio.h>

int main(void){
  int i,j,prm[60000];

  for(i=0;i<60000;i++)  prm[i]=1;
  for(i=4;i<60000;i+=2)  prm[i]=0;
  
  prm[0]=0; prm[1]=0;
  
  for(i=3;i*i<60000;i+=2){
    if(prm[i]==1){
      for(j=i+i;j<60000;j+=i) prm[j]=0;
    }
  }

  int n;
  while(scanf("%d",&n)!=EOF){
    if(n==0)  break;
    else{
      int answer=0;
      if(prm[n-2]==1) answer++;
      if(n%2==0){
	for(i=3;i<=n/2;i+=2){
	  if(prm[i]==1&&prm[n-i]==1) answer++;
	}
      }
      printf("%d\n",answer);
    }
  }
  return 0;
}

Measured memory_bytes: 832
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define ull unsigned long long int
#define ld long double
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define endl "\n"
#define intarr(arr, n)  ll arr[n];  for (ll i = 0; i < n; i++)  cin >> arr[i]
#define inpvec(vec,n) for(ll i=0;i<n;i++){ll var;cin>>var;vec.push_back(var);}
#define ff first
#define ss second
#define pb push_back
#define mkp make_pair
#define vec vector<ll>
#define pi pair<ll,ll>
#define changeline cout<<endl
#define loop(i,a,b) for(ll i=a;i<b;i++)
#define rev(i,a,b) for(ll i=a;i>=b;i--)
#define all(v) v.begin(),v.end()
#define mod2 998244353
#define NO cout << "NO" <<endl
#define YES cout << "YES" <<endl
#define mem(arr,val) memset(arr,val,sizeof(arr));
const ll mod=1e9+7;
#define piii 3.14159265358979323846264338327950
#define print(a, n, m)     for (ll i = n; i < m; i++) {  cout << a[i] << " "; }  cout << endl
#define con continue

bool prime(ll n) 
{ 
    if (n <= 1)  return false; 
    if (n <= 3)  return true; 
    if (n%2 == 0 || n%3 == 0) return false; 
  
    for (ll i=5; i*i<=n; i=i+6) 
        if (n%i == 0 || n%(i+2) == 0) 
           return false; 
  
    return true; 
}
bool isPerfectSquare(ll x) {   
  long double sr = sqrt(x); 
  return ((sr - floor(sr)) == 0); 
} 
bool subsequence_checker(string str1, string str2, ll m, ll n) 
{ 
    if (m == 0) return true; 
    if (n == 0) return false; 
    if (str1[m-1] == str2[n-1]) 
        return subsequence_checker(str1, str2, m-1, n-1); 
    return subsequence_checker(str1, str2, m, n-1); 
}
bool cmp(const pair<int,int> &a,  const pair<int,int> &b) 
{ 
    if(a.ff == b.ff)
        return a.ss < b.ss;
    return (a.ff > b.ff); 
}
//////////////////////////////////////////////////// Lets Do It ////////////////////////////////////////////////////////

void solve()
{
    
    ll n;
    cin>>n;
    vec a;
    inpvec(a,n);

    sort(all(a));
    if(a[0]==0)
    {
            cout<<0; return;
    }

    ll ans = 1;

    loop(i,0,n)
    {
if(a[i ] <=1000000000000000000/ ans ){
// This condition is equivalent to prod*a[i] <=10ˆ18
ans *=a[i];
}else{
cout<<-1;
return;
}
    
    }

    cout<<ans;

    return;
}
 
int main()
{
#ifndef ONLINE_JUDGE
  freopen("input.txt", "r", stdin);
  freopen("output.txt", "w", stdout);
#endif
    IOS;
    ll t;
    //cin>>t;
    t=1;

    while(t--){
        solve();
        cout<<endl;
    }

    cerr << "\nTime elapsed: " << 1000 * clock() / CLOCKS_PER_SEC << "ms\n";
    return 0;
} 

Measured memory_bytes: 4248
import java.util.*;

public class Main {

	public static void main(String[] args) {
			
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int M = sc.nextInt();
		int A = 0;
		for (int i = 0; i < M; i++) {
			A += sc.nextInt();
		}
		if (N < A)
			System.out.println(-1);
		else 
			System.out.println(N-A);
	}
}

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

void change_to_plural(char* input_string, char* output_string) 
{
    int n;
    n = strlen(input_string);
    
    if (input_string[n - 1] == 's' ) 
    {
        input_string[n] = 'e';
        input_string[n + 1] = 's';
        input_string[n + 2] = '\0';
    }
    else 
    
    {
        input_string[n] = 's';
        input_string[n + 1] = '\0';
    }
   

    output_string = input_string;
    n = strlen(input_string);
    for (int i = 0; i < n; i++)
    cout << output_string[i];
}


int main() {

    char in[1000], out[1000];

    cin >> in;
    
    change_to_plural(in, out);
        
        
    cout << endl;
}

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

long long N,A[100010];

int main(void)
{
  long long b,i,cnt=0;
  
  cin >> N;
  for(i=0;i<=N;i++) {
    cin >> A[i];
  }
  for(i=0;i<N;i++) {
    cin >> b;
    if(b<=A[i]) {
      cnt+=b;
    } else {
      cnt+=A[i];
      b-=A[i];
      if(b>=A[i+1]) {
        cnt+=A[i+1];
        A[i+1]=0;
      } else {
        cnt+=b;
        A[i+1]-=b;
      }
    }
  }
  cout << cnt;
}
      
      
      

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

#define mk make_pair
#define sc second
#define fr first
#define pb push_back
#define int long long

using namespace std;

const int N = (1e6 + 5);
const int inf = (1e18 + 7);

int n;
double a[N],ans;
double dp[3000][3000];

main() {
    cin >> n;

    for (int i = 1; i <= n; i ++)
        cin >> a[i];

    dp[1][1] = a[1];
    dp[1][0] = 1 - a[1];

    for (int i = 2; i <= n; i ++) {
        for (int j = 0; j <= i; j ++) {
            if (j == 0) dp[i][j] = dp[i - 1][j] * (1 - a[i]);
            else
            dp[i][j] = dp[i - 1][j] * (1 - a[i]) + dp[i - 1][j - 1] * a[i];
        }
    }
    for (int i = (n + 1) / 2; i <= n; i ++)
        ans += dp[n][i];

    cout <<fixed << setprecision(9) << ans << endl;
}


Measured memory_bytes: 70272
s = int(input())
f = lambda n : n // 2 if n % 2 == 0 else 3 * n + 1
a = [s]
i = 2
while True:
    if f(a[-1]) in a:
        break
    else:
        a.append(f(a[-1]))
    i += 1
print(i)

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

int main() {
	int n;
	cin >> n;
	int a[4][3][10];
	for (int i = 0; i < 4; i++)
		for (int j = 0; j < 3; j++)
			for (int k = 0; k < 10; k++)
				a[i][j][k] = 0;
	for (int i = 0; i < n; i++) {
		int b, f, r, v;
		cin >> b >> f >> r >> v;
		a[b - 1][f - 1][r - 1] += v;
	}
	for (int i = 0; i < 4; i++) {
		for (int j = 0; j < 3; j++) {
			for (int k = 0; k < 10; k++)
				cout << ' ' << a[i][j][k];
			cout << endl;
		}
		if (i != 3)
			cout << "####################" << endl;
	}
}


Measured memory_bytes: 3120
n=int(input())


# ==================================================-
# modを考慮したべき乗
# a**n%modを高速に出力
def power_func(a, n, mod=10 ** 9 + 7):
    bi = str(format(n, "b"))
    res = 1
    for i in range(len(bi)):
        res = (res * res) % mod
        if bi[i] == "1":
            res = (res * a) % mod
    return res

mod=10**9+7
all_situation=power_func(10,n)

non_zero_situation=power_func(9,n)

non_nine_situation=power_func(9,n)

non_zero_and_nine_situation=power_func(8,n)

answer=(all_situation-non_zero_situation-non_nine_situation+non_zero_and_nine_situation)%mod
print(answer)

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

//#define int long long
#define fi first
#define se second
#define rep(i,n) for(int i=0;i<(int)(n);++i)
#define rep1(i,n) for(int i=1;i<=(int)(n);++i)
#define rep11(i,n) for(int i=1;i<(int)(n);++i)
#define repo(i,o,n) for(int i=o;i<(int)(n);++i)
#define repm(i,n) for(int i=(int)(n)-1;i>=0;--i)
#define all(v) (v).begin(),(v).end()
#define rall(v) (v).rbegin(),(v).rend()
#define pb(n) push_back(n)
#define mp make_pair
#define MOD 1002000007
#define INF LONG_LONG_MAX

int main(){
    int n;
    int su=0;
    cin>> n;
    int tab1[n],tab2[n];
    for (int i = 0; i < n; ++i)
    {
        cin >> tab1[i];
    }
    for (int i = 0; i < n; ++i)
    {
        cin >> tab2[i];
    }
    for (int i=0; i<n; i++){
        if (tab1[i]>tab2[i]){
            su+=tab1[i]-tab2[i];
        }
    }
    cout << su <<endl;
    return 0;
}

Measured memory_bytes: 384
#include<bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;++i)
#define reps(i,o,n) for(int i=o;i<n;++i)
#define eb emplace_back
#define pb push_back
#define X first
#define Y second
#define all(X) X.begin(), X.end()

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

int main(){
  int n;
  ll a,b;
  cin>>n>>a>>b;
  vector<pll> vs[5];
  rep(i,n){
    ll t,x,y;
    cin>>t>>x>>y; --t;
    vs[t].eb(x,y);
  }
  sort(vs,vs+5,[](const vector<pll> &a,const vector<pll> &b){return a.size()<b.size();});
  map<ll,vector<ll>> ps{{0,{0}}},qs{{0,{0}}};
  
  rep(i,3) for(pll p:vs[i]) qs[p.X].pb(p.Y);
  for(pll p:vs[0])for(pll q:vs[1])for(pll r:vs[2]) qs[p.X+q.X+r.X].pb(p.Y+q.Y+r.Y);
  for(pll p:vs[0])for(pll q:vs[1]) qs[p.X+q.X].pb(p.Y+q.Y);
  for(pll p:vs[0])for(pll r:vs[2]) qs[p.X+r.X].pb(p.Y+r.Y);
  for(pll q:vs[1])for(pll r:vs[2]) qs[q.X+r.X].pb(q.Y+r.Y);
  for(auto &p:qs) sort(all(p.Y));
  
  reps(i,3,5) for(pll p:vs[i]) ps[p.X].pb(p.Y);
  for(pll p:vs[3])for(pll q:vs[4]) ps[p.X+q.X].pb(p.Y+q.Y);
  for(auto &p:ps) sort(all(p.Y));
  //rep(i,5){for(pll x:vs[i]) cout<<x.X<<","<<x.Y<<"  ";cout<<endl;}
  
  // for(auto p:ps){cout<<p.X<<":"; for(int y:p.Y) cout<<y<<",";cout<<endl;}
  // for(auto p:qs){cout<<p.X<<":"; for(int y:p.Y) cout<<y<<",";cout<<endl;}
  map<ll,ll> cnt;
  auto l=ps.rbegin(),r=l;
  for(auto &p:qs){
    for(;r!=ps.rend();++r){
      if(r->X < a-p.X) break;
      for(ll y:r->Y) ++cnt[y];
    }
    for(;l!=ps.rend();++l){
      if(l->X <= b-p.X) break;
      vector<ll> rm;
      for(ll y:l->Y) if(--cnt[y]==0) rm.pb(y);
      for(ll y:rm) cnt.erase(y);
    }
    // cout<<p.X<<endl;
    // for(pll x:cnt)cout<<x.X<<","<<x.Y<<"  ";cout<<endl;
    for(ll y:p.Y){
      auto it=cnt.lower_bound(a-y);
      if(it!=cnt.end() && it->X<=b-y){
	cout<<"Yes"<<endl;
	return 0;
      }
    }
  }
  cout<<"No"<<endl;
  return 0;
}

Measured memory_bytes: 117540
#include <bits/stdc++.h>
#pragma GCC target("avx2")
#pragma GCC optimize("03")
#pragma GCC optimize("unroll-loops")
#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()
#define rall(a) (a).rbegin(),(a).rend()
#define dunk(a) cout << (a) << "\n"
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
const int inf = 1001001001;
const int mod = 1000000007;

int modPow(long long a, long long n, long long p) {
	if (n == 1) return a % p;
	if (n % 2 == 1) return (a * modPow(a, n - 1, p)) % p;
	long long t = modPow(a, n / 2, p);
	return (t * t) % p;
}

ll comb(ll n, ll p) {
	if (p * 2 > n) p = n - p;
	if (p > n - p) p = n - p;
	ll a = 1, b = 1;
	rrep(i, p + 1) {
		a = (a * (n - i + 1)) % mod;
		b = (b * i) % mod;
	}
	return a * (modPow(b, mod - 2, mod)) % mod;
}

int main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	int x, y;
	cin >> x >> y;
	if ((x + y) % 3 != 0) {
		dunk(0);
		return 0;
	}
	if ((2 * x - y) < 0 || (2 * y - x) < 0) {
		dunk(0);
		return 0;
	}
	ll res1 = (2 * x - y) / 3;
	ll res2 = (2 * y - x) / 3;
	ll ans = comb(res1 + res2, res1);
	dunk(ans);
	return 0;
}


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


Measured memory_bytes: 3080
#
# 　　  ⋀_⋀　 
#　　  (･ω･)  
# .／ Ｕ ∽ Ｕ＼
#  │＊　合　＊│
#  │＊　格　＊│ 
#  │＊　祈　＊│ 
#  │＊　願　＊│ 
#  │＊　　　＊│ 
#      ￣
#
import sys
sys.setrecursionlimit(10**6)
input=sys.stdin.readline
from math import floor,sqrt,factorial,hypot,log #log2ないｙｐ
from heapq import heappop, heappush, heappushpop
from collections import Counter,defaultdict,deque
from itertools import accumulate,permutations,combinations,product,combinations_with_replacement
from bisect import bisect_left,bisect_right
from copy import deepcopy
from fractions import gcd
from random import randint
def ceil(a,b): return (a+b-1)//b
inf=float('inf')
mod = 10**9+7
def pprint(*A): 
    for a in A:     print(*a,sep='\n')
def INT_(n): return int(n)-1
def MI(): return map(int,input().split())
def MF(): return map(float, input().split())
def MI_(): return map(INT_,input().split())
def LI(): return list(MI())
def LI_(): return [int(x) - 1 for x in input().split()]
def LF(): return list(MF())
def LIN(n:int): return [I() for _ in range(n)]
def LLIN(n: int): return [LI() for _ in range(n)]
def LLIN_(n: int): return [LI_() for _ in range(n)]
def LLI(): return [list(map(int, l.split() )) for l in input()]
def I(): return int(input())
def F(): return float(input())
def ST(): return input().replace('\n', '')
def main():
    A,B=MI()
    print(A*B)
if __name__ == '__main__':
    main()

Measured memory_bytes: 83460
import java.lang.Math.abs
import java.lang.Math.min

fun main(args: Array<String>) {
    val n = readLine()!!.toInt()
    val hs = readLine()!!.split(" ").map(String::toInt)

    val inf = 10000000000;

    var dp = Array(n) { inf }
    dp[0] = 0

    for (index in 0 until n) {
        for (i in index + 1..index + 2) {
            if (i < n)
                dp[i] = min(dp[i], dp[index] + abs(hs[i] - hs[index]));
        }
    }

    println(dp.last())
}

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

#define rep(X,N) for(ll X = 0LL; X < (N); X++)
#define ALL(V) (V).begin(),(V).end()
#define endl "\n"

using namespace std;
typedef long long ll;

const double PI = 3.1415926535897932384626;
const ll MODN = 1000000007;
const ll MODN2 = 998244353;
const double EPS = 1e-10;

int main(){

    int n;
    cin >> n;

    string s;
    cin >> s;

    vector<int> count(n + 1);

    for(int i = 1; i <= n; i++){
        int pcount = __builtin_popcount(i);

        int tmp = i % pcount;
        count[i] = count[tmp] + 1;
    }

    int pcount = 0;

    rep(i, n){
        if(s[i] == '1') pcount++;
    }

    cerr << "popcount : " << pcount << endl;

    if(pcount == 0){
        rep(i, n){
            cout << 1 << endl;
        }
    }else{
        //mod pcount + 1
        vector<int> modplus(n + 1);
        //mod pcount - 1
        vector<int> modminus(n + 1);

        //pcount - 1 == 0ならなにもしない
        if(pcount - 1 != 0){
            modminus[1] = 1 % (pcount - 1);

            for(int i = 2; i <= n; i++){
                modminus[i] = (modminus[i - 1] * 2) % (pcount - 1);
            }
        }

        modplus[1] = 1 % (pcount + 1);

        for(int i = 2; i <= n; i++){
            modplus[i] = (modplus[i - 1] * 2) % (pcount + 1);
        }

        vector<int> summinus(n + 1);
        vector<int> sumplus(n + 1);

        rep(i, n){
            if(s[n - 1 - i] == '1'){
                if(pcount - 1 != 0) summinus[i + 1] = (summinus[i] + modminus[i + 1]) % (pcount - 1);
                sumplus[i + 1] = (sumplus[i] + modplus[i + 1]) % (pcount + 1);
            }else{
                summinus[i + 1] = summinus[i];
                sumplus[i + 1] = sumplus[i];
            }
        }

        int summi = summinus[n];
        int sumpl = sumplus[n];

        cerr << summi << " " << sumpl << endl;

        rep(i, n){
            if(s[i] == '0'){
                //plus
                cout << count[(sumpl + modplus[n - i]) % (pcount + 1)] + 1 << endl;
            }else{
                //minus
                if(pcount > 1){
                    cout << count[((summi - modminus[n - i]) < 0? (summi - modminus[n - i]) + (pcount - 1) : (summi - modminus[n - i])) % (pcount - 1)] + 1 << endl;
                }else{
                    cout << 0 << endl;
                }
            }
        }
    }

    

    return 0;
}


Measured memory_bytes: 7616
#include <iostream>
#include <vector>
using namespace std;
typedef long long int LLI;

int main()
{
	int n, tmp;
	cin >> n;
	tmp = n;
	int sum = 0;
	while( tmp > 0 )
	{
		sum += tmp % 10;
		tmp /= 10;
	}
	if( n % sum == 0 )
		cout << "Yes";
	else
		cout << "No";
}

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

int main() {
  int N, a, b, num, i;
  cin >> N;
  num = 1;
  a = 0;
  
  for(i=0; i<9; i++){
    if(num >= N) break;
    num *= 10;
  }
  
  b = N;
  while(num>0){
    a += b / num;
    b %= num;
    num /= 10;
  }
  
  if(N % a == 0) cout << "Yes" << endl;
  else cout << "No" << endl;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
int main(void){
int n;
long long int l[100];
l[0]=2;
l[1]=1;
scanf("%d",&n);
if(n==0){printf("2"); return 0;}
else if(n==1){printf("1");return 0;}
for(int count=2;count<=n;count++){
l[count]=l[count-1]+l[count-2];
}
printf("%lld",l[n]);
}

Measured memory_bytes: 128
//my vegetable has exploded. :(
#include<bits/stdc++.h>
#define max(x,y) (x>y?x:y)
#define min(x,y) (x<y?x:y)
#define MM(x,y) memset(x,y,sizeof(x))
#define MCPY(a,b) memcpy(a,b,sizeof(b))
#define pb push_back
#define rep(i,a,b) for(int i=a;i<=b;i++)
#define per(i,a,b) for(int i=b;i>=a;i--)
#define fi first
#define se second
using namespace std;
#define int long long

inline int quickpow(int m,int n,int p){int b=1;while(n){if(n&1)b=b*m%p;n=n>>1;m=m*m%p;}return b;}
inline int getinv(int x,int p){return quickpow(x,p-2,p);}
inline int read(void){
    int x=0,f=1;char ch=getchar();
    while(!isdigit(ch)){f=ch=='-'?-1:1;ch=getchar();}
    while(isdigit(ch)){x=(x<<3)+(x<<1)+ch-'0';ch=getchar();}
    return x * f;
}
const int MAXN = 2e5+10;

///------------------head------------------
int a[MAXN],n,ans=0;
signed main(signed argc, char *argv[]){
    n=read();
    rep(i,1,n) a[i]=read()-i;
    sort(a+1,a+n+1);
    rep(i,1,n) ans+=abs(a[i]-a[(n+1)>>1]);
    printf("%lld\n",ans);
    return 0;
}

/* Examples: */
/*

*/

/*

*/


Measured memory_bytes: 1792
N, M, X = map(int, input().split())
A = list(map(int, input().split()))
if X < min(A):
	print(0)
else:
	cost_left = cost_right = 0 
	for i in A:
		if X >= i:
			cost_left += 1
		else:
			cost_right += 1
	print(min(cost_left, cost_right))

Measured memory_bytes: 3060
import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        List<Integer> num = new ArrayList<>();

        for (int i = 0; i < 5; i++) {
            num.add(Integer.parseInt(sc.next()));
        }
        
        num.sort((o1, o2) -> {
            if (o1 > o2) return -1;
            if (o1 < o2) return 1;
            return 0;
        });
        
        for (int i = 0; i < 5; i++) {
            if (i == 4) {
                System.out.println(num.get(i));
            } else {
                System.out.printf("%d ", num.get(i));
            }
        }
    }
}

Measured memory_bytes: 31956
#include <bits/stdc++.h>
#define de(x) cout<<#x<<'='<<x<<endl
#define inf 0x3f3f3f3f
#define ninf 0xc0c0c0c0
#define ll long long
using namespace std;
int main()
{
    int a,b,c,d,e,f,i,j,k,l,ans1=0,ans2=0;
    double dt,dmax=0;
    cin>>a>>b>>c>>d>>e>>f;
    for(i=0;i<=30;i++)
    {
    	if(100*a*i>f)break;
    	for(j=0;j<=30;j++)
    	{
    		if(i==0&&j==0)continue;
    		if(100*(a*i+j*b)>f)break;
    		for(k=0;k<=3000;k++)
    		{
    			if(100*(a*i+j*b)+k*c>f)break;
    			if((a*i+j*b)*e<k*c)break;
    			
    			int t=((a*i+j*b)*e-k*c)/d;
    			if((a*i+j*b)*100+k*c+t*d<=f)
    			l=t;
    			else
    			l=(f-(a*i+j*b)*100-k*c)/d;
    			
    			dt=1.0*(k*c+l*d)/(100*(a*i+b*j)+k*c+l*d);
    			if(dt>=dmax)
				{
				    //de(i);de(j);de(k);de(l);
					dmax=dt;
					ans1=100*(a*i+b*j)+(c*k+d*l);
					ans2=c*k+d*l;
					//de(ans1);de(ans2);
			    }
 			}
		}
	}
	cout<<ans1<<' '<<ans2<<endl;
	return 0;
}



Measured memory_bytes: 256
#include<iostream>
using namespace std;
const int maxn=1e6+7;
int a[maxn];
int n;
int main()
{
    cin>>n;
    for(int i=0;i<n;i++){
        cin>>a[i];
    }
    sort(a,a+n);
    if((unique(a, a+n)-a)!=n){
        cout<<"NO";
    }
    else{
        cout<<"YES";
    }
    return 0;
}



Measured memory_bytes: 1024
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Arrays;
import java.util.Comparator;
import java.util.PriorityQueue;
import java.util.regex.Pattern;

public class Main {
    public static void main(String[] args) throws IOException {
        BufferedReader stdin = new BufferedReader(new InputStreamReader(System.in));
        String[] line = stdin.readLine().split(" ");
        int n = Integer.parseInt(line[0]);
        int m = Integer.parseInt(line[1]);
        long[] a = Pattern.compile(" ").splitAsStream(stdin.readLine()).mapToLong(Long::parseLong).toArray();
        
        PriorityQueue<Long> pq = new PriorityQueue<>(Comparator.reverseOrder());
        Arrays.stream(a).forEach(pq::add);
        for (int i = 0; i < m; i++) {
            pq.add(pq.poll() / 2L);
        }
        
        long ans = pq.stream().mapToLong(Long::longValue).sum();
        System.out.println(ans);
    }
}


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

int main(void){
  int n;
  scanf("%d", &n);

  double v[n];
  int i, j, tmp;
  for(i=0;i<n;i++){
    scanf("%lf",&v[i]);
  }

  
  for (i=0; i<n; ++i) {
    for (j=i+1; j<n; ++j) {
      if (v[i] > v[j]) {
        tmp =  v[i];
        v[i] = v[j];
        v[j] = tmp;
      }
    }
  }

  double ave;
  for (i=0; i<n-1; i++) {
    ave = (v[i] + v[i+1])/2;
    v[i+1] = ave;
  }
  printf("%lf", v[n-1]);





  
  
  
  
}

Measured memory_bytes: 128
#include<cstdio>
#include<cstring>
#include<cmath>
#include<cstdlib>
#include<ctime>
#include<algorithm>
#include<vector>
#include<queue>
#define ll long long
ll read()
{
	ll tmp=0;char c=getchar(),f=1;
	while(c<'0'||'9'<c){if(c=='-')f=-1;c=getchar();}
	while('0'<=c&&c<='9'){tmp=tmp*10+c-48;c=getchar();}
	return tmp*f;
}
using namespace std;
int n;
int main()
{
	int i,x;
	n=read();
	int ans=0,flag=0;
	for(i=1;i<=n;i++){
		x=read();
		if(flag)flag=0;
		else if(x==i)++ans,flag=1;
	}
	printf("%d\n",ans);
	return 0;
}

Measured memory_bytes: 128
#include<iostream>
#include<algorithm>
#include<queue>

using namespace std;

pair<int,pair<int,int> > E[200005];

int n,m;

int getPoz(int x, int y) //pozitia de pe border
{
    if(x==0)
        return m-y;
    if(y==0)
        return m+x;
    if(x==n)
        return n+m+y;
    return n+2*m+(n-x);
}

deque<int> Q;

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

    int num;
    cin>>n>>m>>num;

    int nr=0;
    for(int i=1; i<=num; i++)
    {
        int x,y,xx,yy;
        cin>>x>>y>>xx>>yy;

        if((x!=0 && x!=n && y!=0 && y!=m) || (xx!=0 && xx!=n && yy!=0 && yy!=m))
            continue;

        int ind1=getPoz(x,y);
        int ind2=getPoz(xx,yy);
        E[++nr]={min(ind1,ind2),{1,i}};
        E[++nr]={max(ind1,ind2),{-1,i}};
    }

    sort(E+1,E+nr+1);

    bool ok=1;
    for(int i=1; i<=nr; i++)
    {
        int tip=E[i].second.first;
        int el=E[i].second.second;

        if(tip==1)
            Q.push_back(el);
        else
        {
            if(Q.back()!=el)
            {
                ok=0;
                break;
            }
            Q.pop_back();
        }
    }

    if(ok)
        cout<<"YES\n";
    else
        cout<<"NO\n";
    return 0;
}


Measured memory_bytes: 2816
#include <algorithm>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <fstream>
#include <iostream>
#include <map>
#include <queue>
#include <string>
#include <stack>
#include <vector>
#include <set>
#include <tuple>
#include <utility>
#include <functional>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
typedef tuple<int,int,int> T;
const int INF = 1000000000;
const int MOD = 1000000007;

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

	if(n >= 2 && m >= 2)cout << (n-2) * (m-2) << endl;
	else{
		if(n == 1 && m == 1)cout << 1 << endl;
		else if(n == 1)cout << m-2 << endl;
		else cout << n-2 << endl;
	}
}


Measured memory_bytes: 256
#include <stdio.h>
#define LL long long
LL ans;
int main(){
	int n,i,m,a,b;
	scanf("%d",&n);
	for(i=1;i<=n;i++){
		m=n/i;
		a=i,b=a+(m-1)*i;
		ans+=(LL)(a+b)*m/2;
	}
	printf("%lld\n",ans);
	return 0;
}

Measured memory_bytes: 3200
#include <iostream>
#include <string>
#include <cstring>
#include <vector>
#include <algorithm>
#include <cmath>
#include <set>
#include <utility>
#include <cstdlib>
#include <queue>
#include <stack>
#include <iomanip>
#include <cstdio>
#include <map>
#include <list>

using namespace std;

typedef long long ll;
typedef pair<ll,ll> P;

#define _upgrade ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define rep(i,x) for(ll i = 0; i < (ll)(x); i++)
#define all(x) (x).begin(), (x).end()
#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() );
#define pb push_back

//ll gcd(ll a, ll b){return b?gcd(b,a%b):a;}
//ll lcm(ll x, ll y) {return x / gcd(x, y) * y;}

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

const ll mod = 1e9 + 7;
const ll inf = 1<<29;
const long double pi = 3.14159265358979323846;

// ****************************************CODE***************************************//

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

    if(s == u){
        cout << a-1 << " " << b;
    }
    else{
        cout << a << " " << b-1;
    }

    return 0;
}

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

typedef long long ll;

const ll INTEG = pow(10,9) + 7;

int main(){
  double W,H,x,y;
  cin >> W >> H >> x >> y;

  cout<<fixed<< W * H / 2 <<setprecision(10) << " ";

  if(2*x == W && 2*y == H){
    cout << 1 << endl;
  }
  else{
    cout << 0 << endl;
  }
}

Measured memory_bytes: 256
import Foundation

func readInts() -> [Int]{
    readLine()!.split(separator: " ").map { Int($0)! }
}

func main(){
    
    let k = Int(readLine()!)!
    let ab = readInts()
    
    for i in 1...1000{
        if k*i >= ab[0] && k*i <= ab[1]{
            print("OK")
            return
        }
    }
    print("NG")
    
    
    
}
main()


Measured memory_bytes: 13652
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<string>
#include<cstring>
#include<cmath>
#include<ctime>
#include<algorithm>
#include<utility>
#include<stack>
#include<queue>
#include<vector>
#include<set>
#include<map>
#include<bitset>
#define EPS 1e-9
#define PI acos(-1.0)
#define INF 0x3f3f3f3f
#define LL long long
const int MOD = 1E9+7;
const int N = 200000+5;
const int dx[] = {-1,1,0,0,-1,-1,1,1};
const int dy[] = {0,0,-1,1,-1,1,-1,1};
using namespace std;
int a[N];
int main() {
    int n;
    scanf("%d",&n);

    int num4=0,num2=0;
    for(int i=1;i<=n;i++){
        scanf("%d",&a[i]);
        if(a[i]%4==0)
            num4++;
        else if(a[i]%2==0)
            num2++;
    }
    if(n>2*num4+num2+1)
       printf("No\n");
    else if(2*num4+num2+1==n&&num2!=0)
        printf("No\n");
    else
        printf("Yes\n");

    return 0;
}


Measured memory_bytes: 640
#define _USE_MAT_DEFINES
#include<iostream>
#include <iomanip>
#include<stdio.h>
#include<string>
#include<vector>
#include<algorithm>
#include<cmath>
#include <queue>
#include <utility>
#include <map>
#include <set>
#include <stack>
#include <deque>
#include <numeric>
#include <functional>
using namespace std;

#define INF 1e9
#define MOD 1000000007;//1e9+7

void solve() {
    int A, B, C;
    set<int>st;
    cin >> A >> B >> C;
    st.insert(A);
    st.insert(B);
    st.insert(C);
    if (st.size() == 2)cout << "Yes";
    else cout << "No";
}

int main() {
    solve();
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ll long long int
#define ff first
#define ss second
#define pb push_back
#define mp make_pair
#define all(x) x.begin(),x.end() 
#define MOD 1000000007
#define N 100005
#define pll pair<ll,ll>
#define FAST ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);srand(time(NULL));


void solve()
{ 
     ll k;
     cin >> k;
     ll ans = 0;
     for(ll i=1;i<=k;i++)
     {
          for(ll j=1;j<=k;j++)
          {
               ll g = __gcd(i,j);
               for(ll l=1;l<=k;l++)
               {
                    ll go = __gcd(g,l);
                    ans += go;
               }
          }
     }
     cout<<ans;
}

int main()
{
     FAST;
     ll t = 1;
  ///   cin >> t;
     while(t--)
     {     
          solve();
     }
}

Measured memory_bytes: 3660
/*氏名：保坂優介, 学籍番号：200441141
  概要：*/

#include<stdio.h>

int main(void)
{
    int i, j, k, n, b, f, r, v, num[5][4][11] = { 0 };

    scanf("%d", &n);
    for (i = 0; i < n; i++)
    {
        scanf("%d%d%d%d", &b, &f, &r, &v);
        num[b][f][r] = num[b][f][r] + v;
    }

    for (i=1;i<=4;i++)
    {
        for (j = 1; j <= 3; j++)
        {
            for (k = 1; k <= 10; k++)
            {
                printf(" %d", num[i][j][k]);
            }
            printf("\n");
        }

        if (i != 4)
        {
            for (j = 0; j < 20; j++)
            {
                printf("#");
            }
            printf("\n");
        }
    }
    return 0;
}


Measured memory_bytes: 2100
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define repR(i, n) for(int i = n; i >= 0; i--)
#define For(i, m, n) for(int i = m; i < n; i++)
#define ALL(v) v.begin(), v.end()
typedef long long ll;
typedef long double ld;
using namespace std;
struct Fast {Fast(){std::cin.tie(0);std::ios::sync_with_stdio(false);}} fast;
template <class T = int> T in(){T x; cin >> x; return (x);}

int main() {
    ll result = 0;
    int N;
    int M;
    cin >> N;
    cin >> M;
    vector<ll> A;
    vector<ll> B;
    rep(i, N){
        int in;
        cin >> in;
        A.push_back(in);
        cin >> in;
        B.push_back(in);
    }
    
    vector<int> index(A.size());
    std::iota(index.begin(), index.end(), 0);
    std::sort(
              index.begin(),
              index.end(),
              [&](int x, int y){return A[x] < A[y];}
              );
    
    rep(i, A.size()){
                    if((M > B[index[i]])){
                        result += A[index[i]] * B[index[i]];
                        M -= B[index[i]];
                    }else{
                        result += A[index[i]] * M;
                        cout << result << endl;
                        return 0;
                    }
                }
    
    return 0;
}

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

map<int,int> m;
vector<int> v;

int main()
{
	ios::sync_with_stdio(false);
	int n;
	cin>>n;
	
	for(int i=1;i<=n;i++){
		int x;
		cin>>x;
		if(m[x]==0) v.push_back(x);
		m[x]++;
	}
	
	int ans=0;
	for(int i=0;i<v.size();i++)
		if(v[i]>m[v[i]]) ans+=m[v[i]];
		else if(v[i]<m[v[i]]) ans+=m[v[i]]-v[i];
	
	cout<<ans;
	return 0; 
}

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

int main(){
    int N,K,M;
    M=1000000000;
    cin >> N >> K;
    int h[N];
    for (int i=0; i<N; ++i) cin >> h[i];
    sort (h,h+N);
    for (int i=0; i<=N-K; ++i){
        M=min(M,h[i+K-1]-h[i]);
    }
    cout << M << endl;
}


Measured memory_bytes: 640
n = int(input())
p = []
t = 0
ans = 'Yes'
for _ in range(n):
    a,b = map(int,input().split())
    p.append([a,b])
#print(p)
p = sorted(p, key=lambda x:x[1])
for a,b in p:
    t += a
    if t > b:
        ans = 'No'
        break

print(ans)

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


typedef long long ll;
typedef pair<int,int> ii;
typedef vector<int> vi;
typedef vector<ii> vii;
typedef long double ld;

typedef set<int>::iterator sit;
typedef map<int,int>::iterator mit;
typedef vector<int>::iterator vit;

const int INF = 1e9 + 7;
const int MOD = 1e9 + 7;
const int MAXN = 1e6 + 3;

#define _  %  MOD
#define __ %= MOD

#define      each(it,s)        for(auto it = s.begin(); it != s.end(); ++it)
#define      sortA(v)          sort(v.begin(), v.end())
#define      sortD(v)          sort(v.begin(), v.end(), greater<auto>())
#define      fill(a)           memset(a, 0, sizeof (a))

#define      swap(a,b)        {a=a+b;b=a-b;a=a-b;}
#define      rep(i, n)         for(ll i = 0; i < (n); ++i)
#define      repA(i, a, n)     for(ll i = a; i <= (n); ++i)
#define      repD(i, a, n)     for(ll i = a; i >= (n); --i)
#define watch(x) cout << (#x) << " is " << (x) <<endl

#define fi first
#define se second
#define mp make_pair
#define pb push_back

#define fbo find_by_order
#define ook order_of_key

ll gcd(ll a,ll b){if(b==0) return a; else return gcd(b,a%b);}
ll power(ll x,ll y){ll res=1; while(y>0){if(y&1) res=res*x;y=y>>1;x=x*x;}return res;} // modular exponent

int main()
{
    ios_base::sync_with_stdio(false); // don't use printf and scanf
    cin.tie(NULL); // cout<<fixed<<setprecision
int n,i,j;
cin>>n;
ld p[n];
ld ans=0.0;
for(i=0;i<n;i++) cin>>p[i];
vector<vector<long double> > M(n+1,vector<long double>(n+1,-1.0));
//cout<<"initially M = \n";
/*for(i=0;i<=n;i++)
{
cout<<"\n";
	for(j=0;j<=n;j++)
	cout<<M[i][j]<<" ";
}*/
for(i=0;i<=n;i++)
	for(j=0;j<n;j++) M[i][j]=-1;
M[0][0] = 0;
M[1][0] = 100*(1-p[0]); 
M[1][1] = 100*p[0]; 
for(i=2;i<=n;i++)
{
	for(j=0;j<=n;j++)
	{
		if(j==0) M[i][j] = (1-p[i-1])*M[i-1][j];
		else if(j<i)
		{
			M[i][j] = M[i-1][j]*(1-p[i-1]) + M[i-1][j-1]*(p[i-1]);
		}
		else if(j==i) M[i][j] = M[i-1][j-1]*p[i-1];
	}
}
for(i=n/2+1;i<=n;i++) 
{
ans+=M[n][i];
}
ans = ans/100;
/*cout<<"\n\n";
for(i=0;i<=n;i++)
{
cout<<"\n";
	for(j=0;j<=n;j++)
	cout<<M[i][j]<<" ";
}*/
cout<<setprecision(12)<<ans<<"\n";

}



Measured memory_bytes: 141056
n = int(input())
a = list(map(int, input().split()))

dic = {}
for i in range(n):
    if str(a[i]) not in dic:
        dic[str(a[i])] = 1
    else:
        dic[str(a[i])] += 1

dic2 = {}
maxi = 0
for key, num in dic.items():
    temp = 0
    if num>=2:
        temp = (num)*(num-1)//2
    dic2[key] = temp
    maxi += temp

for k in range(n):
    temp = maxi
    num = dic[str(a[k])]
    nCr = 0
    if num-1>=2:
        nCr = (num-1)*(num-2)//2
    print(temp - dic2[str(a[k])] + nCr)

Measured memory_bytes: 38592
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<iomanip>
#include<math.h>
#include<complex>
#include<queue>
#include<deque>
#include<stack>
#include<map>
#include<set>
#include<bitset>
#include<functional>
#include<assert.h>
#include<numeric>
using namespace std;
#define REP(i,m,n) for(int i=(int)(m) ; i < (int) (n) ; ++i )
#define rep(i,n) REP(i,0,n)
using ll = long long;
const int inf=1e9+7;
const ll longinf=1LL<<60 ;
const ll mod=1e9+7 ;

int main(){
    int n;
    cin>>n;
    cout<<180*(n-2)<<endl;
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
    using namespace std;
    #define 	ll 			long long
    #define 	w(t)		int t; cin>>t; while(t--)  
	#define 	AsmShuvo()  ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
			
    int main()
    {
    AsmShuvo()
    	
    	ll L;
    	cin>>L;
    	double x = (L/3.0)*(L/3.0)*(L/3.0);
    	cout<<setprecision(9)<<x<<endl;
			

	}
	


Measured memory_bytes: 3704
#include <iostream>
#include <vector>
#include <algorithm>
#include <set>
#include <map>

using namespace std;

typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int,int> ii;

#define sz(a) int((a).size())
#define pb push_back
#define all(c) (c).begin(),(c).end()
#define tr(c,i) for(typeof((c).begin()) i = (c).begin(); i != (c).end(); i++)
#define present(c,x) ((c).find(x) != (c).end()) // container with member function find
#define cpresent(c,x) (find(all(c),x) != (c).end()) // for vector

/* PRINT */
void print_vector(const std::vector<int>& v) {
    // Traverse all container, from begin() to end()
    for(vector<int>::const_iterator it = v.begin(); it != v.end(); it++) {
        std::cout << *it << " ";
    }
    std::cout << std::endl;
}


int main() {
    /* code */
    string str1;
    std::cin >> str1;

    string str2 = "CODEFESTIVAL2016";
    int ans = 0;

    for (int i = 0; i < 16; i++) {
        if(str1[i] != str2[i])
            ans ++;
    }

    std::cout << ans << std::endl;
    return 0;
}


Measured memory_bytes: 256
Module Module1

    Sub Main()
        'Dim a As Integer
        'Dim s As String

        'a = Console.ReadLine()
        's = Console.ReadLine()

        'If a >= 3200 Then
        '    Console.WriteLine(s)
        'Else
        '    Console.WriteLine("red")
        'End If

        Dim n As Integer
        Dim a() As String
        Dim c As Integer
        Dim b As Double

        n = Console.ReadLine()

        a = Split(Console.ReadLine())

        For c = 0 To n - 1
            b = b + 1 / Integer.Parse(a(c))
        Next

        Console.WriteLine(1 / b)
    End Sub

End Module


Measured memory_bytes: 13536
/*input
2 2 2 2 2
8 6
9 1
2 1
*/
#include <bits/stdc++.h>
#pragma GCC optimize("unroll-loops,no-stack-protector")
#pragma GCC target("sse,sse2,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#define watch(x) cout << (#x) << " is " << (x) << endl
#define debug cout << "hi" << endl

using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;

const int MOD = 1e9 + 7;
const int INF32 = 1<<30;
const ll INF64 = 1LL<<60;

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int x, y, a, b, c; cin >> x >> y >> a >> b >> c;
    ll ans = 0;
    vector<ll> p(a);
    vector<ll> q(b);
    vector<ll> r(c);
    vector<ll> chosen;
    for(int i = 0; i < a; i++) cin >> p[i];
    for(int i = 0; i < b; i++) cin >> q[i];
    for(int i = 0; i < c; i++) cin >> r[i];
    sort(p.begin(), p.end());
	sort(q.begin(), q.end());
	sort(r.begin(), r.end());
	for(int i = a - 1; i > a - 1 - x; i--) chosen.emplace_back(p[i]);
	for(int i = b - 1; i > b - 1 - y; i--) chosen.emplace_back(q[i]);
	sort(chosen.begin(), chosen.end());
	int i = 0;
	int j = c - 1;
	while(i < x + y && j > -1 && r[j] > chosen[i])
	{
		chosen[i] = r[j];
		j--;
		i++;
	}
	for(int i = 0; i < x + y; i++) ans += chosen[i];
	cout << ans;

    return 0;
}

Measured memory_bytes: 4852
#include <iostream>
using namespace std;
int main(void){
    // Your code here!
    int A,B,C;
    cin>>A>>B>>C;
    
    for(int i=1;i<=B;i++){
        if(A*i%B==C){
            cout<<"YES"<<endl;
            return 0;
        }
    }
    
    cout<<"NO"<<endl;
}


Measured memory_bytes: 256
Q,H,S,D=map(int,input().split())
N=int(input())

H=min(H,Q*2)
S=min(S,H*2)
D=min(D,S*2)

ans=0

ans+=N//2*D
N%=2
N*=2
ans+=N//2*S
N%=2
N*=2
ans+=N//2*H
N%=2
N*=2
ans+=N//2*Q

print(ans)

Measured memory_bytes: 38256
#include <bits/stdc++.h>
using namespace std;
#define data_type long long
#define endl "\n"

int main()
{
    string str,ttr;
    int ans=0;
    cin>>str>>ttr;
    for(int i=0; i<=str.size()-ttr.size(); i++)
        {
            int c=0;
            for(int j=i; j<ttr.size()+i; j++)
                if(str[j]==ttr[j-i])
                    c++;
            ans=max(ans,c);
        }

    cout<<ttr.size()-ans<<endl;

    return 0;

}



Measured memory_bytes: 3628