akhauriyash/Code-Regression huggingface dataset:
<?php
fscanf(STDIN,"%d %d",$N,$K);
$V = fgets(STDIN);
$arrayV = explode(" ",$V);
$max = 0;
$minusCounterL = 0;
$minusCounterR = 0;

//必ず1つは取り出すのでKが1の時は最大値が0より小さい可能性があるため別処理
if($K === 1){
  echo max($arrayV[0],$arrayV[$N-1]);
}else{
  //左から取り出す数、回数制限･配列の要素数を超えない
  for($i=0; $i<=$K && $i<=$N; $i++){
    if($i !== 0){
      if($arrayV[$i-1] < 0){
        $minusCounterL++;
      }
      //最大を求めるので取り出すのが0以下で止まることはない
      if($arrayV[$i-1] <= 0){
        continue;
      }
    }
    $minusCounterR = 0;
    //右から取り出す数、合計が回数制限･配列の要素数を超えない
    for($j=0; $j<=$K-$i && $j<=$N-$i; $j++){
      if($j !== 0){
        if($arrayV[$N-$j] < 0){
          $minusCounterR++;
        }
        //最大を求めるので取り出すのが0以下で止まることはない
        if($arrayV[$N-$j] <= 0){
          continue;
        }
      }
      //削除する数･合計が回数制限を越えない、左右取出数より少ない、負数の数を超えず削除
      for($m=0; $m<=$K-$i-$j && $m<$i+$j && $m<=$minusCounterL+$minusCounterR; $m++){
        $value = calculate($i,$j,$m,$arrayV,$N);
        //最大値更新
        if($value > $max){
          $max = $value;
        }
      }
    }
  }
  echo $max;
}

function calculate($left,$right,$delete,$array,$N){
  $arrayResult = array();
  for($i=0;$i<$left;$i++){
    $arrayResult[] = $array[$i];
  }
  for($i=0;$i<$right;$i++){
    $arrayResult[] = $array[$N-1-$i];
  }
  for($i=0;$i<$delete;$i++){
    //最小値を1つだけ配列から削除
    $mins = array_keys($arrayResult, min($arrayResult));
    unset($arrayResult[$mins[0]]);
  }
  //配列内の合計を返す
  return array_sum($arrayResult);
}


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

using ll = int_fast64_t;
#define rep(i,n) for(int i=0;i<int(n);++i)
#define repr(i,n) for(int i{n};i-->0;)

signed main(){

  int n,t;
  cin>>n>>t;
  vector<int> a(n),b(n);
  rep(i,n)cin>>a[i]>>b[i];

  auto solve = [](auto const& a,auto const& b,int n,int t){
    vector dp(n+1,vector(6010,0));
    rep(i,n)rep(j,min(t+1,3001)){
      dp[i+1][j] = max(dp[i+1][j],dp[i][j]);
      dp[i+1][j+a[i]] = max(dp[i+1][j+a[i]],dp[i][j]+b[i]);
    }
    return dp;
  };
  auto rev = [](auto vec){
    reverse(begin(vec),end(vec));
    return vec;
  };

  auto dp1 = solve(a,b,n,t);
  auto dp2 = solve(rev(a),rev(b),n,t);

  auto merge_dp = [&](int i){
    auto& previous = dp1[i];
    auto& following = dp2[n-i-1];
    int res = 0;
    rep(k,t){
      res = max(res,previous[k]+following[t-k-1]);
    }
    return res+b[i];
  };

  int ans = 0;
  rep(i,n){
    ans = max(ans,merge_dp(i));
  }
  cout<<(ans)<<endl;

  //cout<<endl;rep(i,n+1){rep(j,t+1)cout<<dp1[i][j]<<" ";cout<<endl;}
  //cout<<endl;rep(i,n+1){rep(j,t+1)cout<<dp2[i][j]<<" ";cout<<endl;}

}


Measured memory_bytes: 144420
using System;
using System.Collections.Generic;
using System.Text;

namespace AtTest.D_Challenge
{
    class ABC_070
    {
        static Node[] nodes;
        static long[] distances;
        static bool[] isMin;

        static void Main(string[] args)
        {
            Method(args);
            Console.ReadLine();
        }

        static void Method(string[] args)
        {
            int n = ReadInt();
            nodes = new Node[n];
            distances = new long[n];
            isMin = new bool[n];
            for (int i = 0; i < n; i++)
            {
                nodes[i] = new Node(n);
                distances[i] = long.MaxValue;
                isMin[i] = false;
            }
            for (int i = 0; i < n-1; i++)
            {
                int[] abc = ReadInts();
                nodes[abc[0] - 1].edges.Add(new Edge(abc[1] - 1, abc[2]));
                nodes[abc[1] - 1].edges.Add(new Edge(abc[0] - 1, abc[2]));
            }
            int[] qk = ReadInts();
            DFS(qk[1] - 1, 0);

            var res = new long[qk[0]];
            for (int i = 0; i < qk[0]; i++)
            {
                int[] xy = ReadInts();
                res[i] = distances[xy[0] - 1]
                    + distances[xy[1] - 1];
            }
            for(int i = 0; i < qk[0]; i++)
            {
                Console.WriteLine(res[i]);
            }
            /*for(int i = 0; i < n; i++)
            {
                Console.WriteLine(distances[i]);
            }*/
        }

        static void DFS(int index,long distance)
        {
            if (distances[index] < distance) return;
            distances[index] = distance;

            for(int i = 0; i < nodes[index].edges.Count; i++)
            {
                Edge edge = nodes[index].edges[i];
                DFS(edge.toIndex, distance + edge.distance);
            }
        }

        private static string Read() { return Console.ReadLine(); }
        private static int ReadInt() { return int.Parse(Read()); }
        private static long ReadLong() { return long.Parse(Read()); }
        private static double ReadDouble() { return double.Parse(Read()); }
        private static int[] ReadInts() { return Array.ConvertAll(Read().Split(), int.Parse); }
        private static long[] ReadLongs() { return Array.ConvertAll(Read().Split(), long.Parse); }
        private static double[] ReadDoubles() { return Array.ConvertAll(Read().Split(), double.Parse); }

        class Node
        {
            public List<Edge> edges;
            public Node(int length)
            {
                edges = new List<Edge>();
            }
        }

        class Edge
        {
            public int toIndex;
            public int distance;

            public Edge(int toIndex, int distance)
            {
                this.toIndex = toIndex;
                this.distance = distance;
            }
        }
    }
}

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

void b_some_sums(void) {
	int n, a, b;
	cin >> n >> a >> b;
	int sum = 0;
	int i_tmp;
	int i_sum = 0;
	for (int i = 1; i <= n; i++) {
		i_tmp = i;
		i_sum = 0;
		while (i_tmp>0) {
			i_sum += (i_tmp % 10);
			i_tmp /= 10;
		}
		if ((i_sum >= a) && (i_sum <= b)) {
			sum += i;
		}
	}
	cout << sum << endl;
}

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

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

int main() {
  int n, m;
  cin >> n >> m;
  vector<int> a(n);
  rep(i, n) cin >> a[i];
  int s = 0;
  rep(i, n) s += a[i];
  int cnt = 0;
  rep(i, n) {
    if (a[i]*(4*m) >= s) cnt++;
  }
  if (cnt >= m) {
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }
  return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define _ ios_base::sync_with_stdio(0);cin.tie(0);
#define REP(i,n) for(int i=0;i<(int)(n);i++)

using namespace std;

const int MAX_V=102;
int vote[MAX_V];

int main(){ _;
  int n,q,m,tmp,result,resultCount;
  while(cin>>n>>q,(n|q)!=0){
    REP(i,MAX_V) vote[i]=0;
    REP(i,n){
      cin>>m;
      REP(j,m){
	cin>>tmp;
	vote[tmp]++;
      }
    }
    result=0;
    resultCount=q-1;
    REP(i,MAX_V){
      if(vote[i]>resultCount){
	result=i;
	resultCount=vote[i];
      }
    }
    cout<<result<<endl;
  }
}

Measured memory_bytes: 1196
#include <iostream>

using namespace std;

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

    int sn = 0;
    int tmp = n;
    while (tmp > 0) {
        sn += tmp % 10;
        tmp /= 10;
    }

    if (n % sn == 0)
        cout << "Yes\n";
    else
        cout << "No\n";
}


Measured memory_bytes: 256
k = 10000


def main():
    n = int(input())
    A = list(map(int, input().split(' ')))
    B = [-1] * n

    counting_sort(A, B, n, k)
    print(' '.join(map(str, B)))


def counting_sort(A, B, n, k):
    C = [0] * k

    for i in range(n):
        C[A[i]] += 1
    
    for i in range(1, k):
        C[i] = C[i] + C[i-1]
    
    for i in range(n-1, -1, -1):
        B[C[A[i]]-1] = A[i]
        C[A[i]] -= 1


if __name__ == '__main__':
    main()



Measured memory_bytes: 240324
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define REP(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define ALL(a) (a).begin(),(a).end()
#define umap unordered_map

int main(){
  ll N; cin>>N;
  umap<string,ll> mp;
  ll r = 0;
  string s;
  REP(i,N){
    cin >> s;
    sort(ALL(s));
    r += mp[s];
    mp[s]++;
  }
  cout <<r;
}


Measured memory_bytes: 10660
#include <stdio.h>

int main()
{
    int a,b,c,i,sum=0;

    scanf("%d %d %d",&a,&b,&c);

    for(i=a;i<=b;i++){
        if(c % i == 0) sum++;
    }

    printf("%d\n",sum);

    return 0;
}

Measured memory_bytes: 596
#include <iostream>
#include <cstdio>
#include <cmath>
#include <cstring>
#include <algorithm>
#include <vector>
#include <queue>
#include <deque>
#include <set>
#include <map>

#define mp make_pair
#define x first
#define y second
#define pb push_back
using namespace std;

const int N = 1e5+5;
int n, a[N], bit[N],
    p[N][2][2], l, r, L, R;
int64_t ans;

void update(int i,int x)
{
    for(; i>0; i-=i&-i) bit[i] = max(bit[i], x);
}
int get(int i)
{
    int res = 0; for(; i<=n; i+=i&-i)
    res = max(res, bit[i]); return res;
}
int main()
{
    cin >> n;
    for(int i=1; i<=n; ++i) cin >> a[i];
    for(int e = 0; e<2; ++e) {
        deque<int> de;
        for(int i=1; i<=n; ++i) bit[i] = 0;
        for(int i=1; i<=n; ++i) {
            while (!de.empty() && a[de.back()] < a[i]) {
                update(a[de.back()], de.back());
                de.pop_back();
            }
            p[i][0][e] = de.empty() ? 0 : de.back();
            p[i][1][e] = max(get(a[i]),p[p[i][0][e]][0][e]);
            de.push_back(i);
        }
        reverse(a+1, a+1+n);
    }

    for(int i=1; i<=n; ++i) {
        L = p[i][0][0];
        l = p[i][1][0];
        R = n+1 - p[n+1-i][0][1];
        r = n+1 - p[n+1-i][1][1];
        //cout << l <<' ' << L <<' ' << i << ' '<< R << ' ' << r << endl;
        ans += 1LL * a[i] * (1LL*(L-l)*(R-i) + 1LL*(r-R)*(i-L));
    }
    cout << ans;
}


Measured memory_bytes: 2944
import java.util.Scanner;

public class Main {

	static Scanner sc = new Scanner(System.in);

	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ

		// 入力
		int n = sc.nextInt();
		int m = sc.nextInt();

		// A行列の入力
		long[][] A = CreateVectorA(n, m);

		// B行列の入力
		long[] b = CreateVectorB(m);

		// 計算
		long[] C = IntegrationVector(A, b);

		//出力
		print(C);

	}

	//Aベクトルを生成
	static long[][] CreateVectorA(int n, int m) {
		long[][] vector = new long[n][m];
		for (int i = 0; i < n; i++) {

			for (int k = 0; k < m; k++) {

				vector[i][k] = sc.nextInt();
			}
		}
		return vector;
	}

	//bベクトルを生成
	static long[] CreateVectorB(int m) {
		long[] vector = new long[m];
		for (int j = 0; j < m; j++) {

			vector[j] = sc.nextInt();
		}
		return vector;
	}

	//Aベクトルとbベクトルの積を計算
	static long[] IntegrationVector(long[][] A, long[] b) {
		long C[]=new long[A.length];
		for (int i = 0; i < A.length; i++) {
			for (int j = 0; j < b.length; j++) {

				C[i] += A[i][j] * b[j];
			}
			
		}
		return C;
	}

	//表示処理
	static void print(long[] C) {
		for (int i = 0; i < C.length; i++) {
			//出力
			System.out.println(C[i]);
		}
	}

}



Measured memory_bytes: 41396
n,k=map(int,input().split())
h=[int(input()) for _ in range(n)]
h_sort=sorted(h)
a=0
b=10**20
for i in range(k, n+1):
	a=h_sort[i-1] - h_sort[i-k]
	if a<b:
		b=a
print(b)

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

int main() {
    int N, L; cin >> N >> L;
    vector<string> vector;
    for (int i = 0; i < N; i++) {
        string S; cin >> S;
        vector.push_back(S);
    }
    sort(vector.begin(), vector.end());
    for (int i = 0; i < N; i++) {
        cout << vector[i];
    }
    cout << endl;
}


Measured memory_bytes: 3572
#include <assert.h>
#include <limits.h>
#include <algorithm>
#include <bitset>
#include <cctype>
#include <cmath>
#include <complex>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <vector>
 
using ll = long long;
using P = std::pair<ll, ll>;
 
#define rep(i, a, b) for (ll(i) = (a); i < (b); i++)
#define all(i) i.begin(), i.end()
#define debug(i) std::cerr << "debug " << i << std::endl
 
template <typename T1, typename T2>
std::ostream& operator<<(std::ostream& os, std::pair<T1, T2> pa) {
  return os << pa.first << " " << pa.second;
}
 
template <typename T>
std::ostream& operator<<(std::ostream& os, std::vector<T> vec) {
  for (int i = 0; i < vec.size(); i++)os << vec[i] << (i + 1 == vec.size() ? "" : " ");
  return os;
}
 
template<typename T1,typename T2>
inline bool chmax(T1& a,T2 b){return a<b && (a=b,true);}
 
template<typename T1,typename T2>
inline bool chmin(T1& a,T2 b){return a>b && (a=b,true);}
 
ll pow_mod(ll a, ll b, ll mod=-1) {
  if ((a == 0)||(mod!=-1&&a%mod==0)) {
    return 0;
  }
 
  ll x = 1;
 
  while (b > 0) {
    if (b & 1) {
      x = (mod!=-1)?(x * a) % mod:x*a;
    }
    a = (mod!=-1)?(a * a) % mod:a*a;
    b >>= 1;
  }
  return x;
}
 
// const ll MOD = 998244353;
const ll MOD = 1e9 + 7;
 
 
 
int main() {
  std::cin.tie(0);
  std::ios::sync_with_stdio(false);

  ll n,m;
  std::cin>>n>>m;

  std::vector<std::vector<ll>> graph(n);

  rep(i,0,m){
    ll s,t;
    std::cin>>s>>t;
    s--;t--;
    graph[s].push_back(t);
  }

  std::vector<long double> dp(n);

  dp[n-1]=0;

  for(ll i=n-2;i>=0;i--){
    long double sum=0;
    for(ll next:graph[i])sum+=dp[next]+1;

    dp[i]=sum/(long double)graph[i].size();
  }

  long double ans=dp[0];

  for(ll i=n-2;i>=0;i--){
    if(graph[i].size()>1){
      std::vector<long double> dp2=dp;

      long double max=-1,sum=0;
      for(ll next:graph[i]){
        sum+=dp2[next]+1;
        chmax(max,dp2[next]);
      }

      dp2[i]=(sum-max-1)/(long double)(graph[i].size()-1);

      for(ll j=i-1;j>=0;j--){
        long double sum=0;
        for(ll next:graph[j])sum+=dp2[next]+1;

        dp2[j]=sum/(long double)graph[j].size();
      }

      chmin(ans,dp2[0]);
    }
  }

  std::cout<<std::setprecision(10)<<std::fixed<<ans;
 
  return 0;
}





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

int main() {
  int n;
  cin >> n;
  vector<int> vec(n);
  pair<int, int> max = {0, -1};
  for (int i=0; i<n; i++) {
    cin >> vec.at(i);
    if (max.first < vec.at(i)) {
      max.first = vec.at(i);
      max.second = i;
    }
  }
  sort(vec.begin(), vec.end());
  reverse(vec.begin(), vec.end());
  for (int i=0; i<n; i++) {
    if (i == max.second) cout << vec.at(1) << endl;
    else cout << max.first << endl;
  }
}


Measured memory_bytes: 2432
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
 
using namespace std;
using namespace __gnu_pbds;
#define  st first
#define  nd second
void debug_out() { cerr << endl; }
template<class T> ostream& prnt(ostream& out, T v) { out << v.size() << '\n'; for(auto e : v) out << e << ' '; return out;}
template<class T> ostream& operator<<(ostream& out, vector <T> v) { return prnt(out, v); }
template<class T> ostream& operator<<(ostream& out, set <T> v) { return prnt(out, v); }
template<class T1, class T2> ostream& operator<<(ostream& out, map <T1, T2> v) { return prnt(out, v); }
template<class T1, class T2> ostream& operator<<(ostream& out, pair<T1, T2> p) { return out << '(' << p.st << ' ' << p.nd << ')'; }
template <typename Head, typename... Tail> void debug_out(Head H, Tail... T) { cerr << " " << H; debug_out(T...);}
 
#define dbg(...) cerr << #__VA_ARGS__ << " ->", debug_out(__VA_ARGS__)
#define dbg_v(x, n) do{cerr<<#x"[]: ";for(int _=0;_<n;++_)cerr<<x[_]<<" ";cerr<<'\n';}while(0)
#define dbg_ok cerr<<"OK!\n"
 
 
#define MOD   1000000007
const int LN =19;
#define int long long
const int  MAXN = 100004;
 
template <typename T> using ordered_set =  tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
 
typedef cc_hash_table<int, int, hash<int > > ht;

int32_t main(){
  ios_base::sync_with_stdio(false);
  cin.tie(NULL); cout.tie(NULL);
  int n ; 
  cin >> n ; 
  int ans =  0;
  for(int i = 1 ; i<=n ; i++){
  if(i%3==0 and i%5==0){
      //cout<<"FizzBuzz"<<"\n";
  }
  else if(i%3==0){
      //cout<<"Fizz"<<"\n";
  }
  else if(i%5==0){
      //cout<<"Buzz"<<"\n";
  }
  else{
      ans+=i;
  }
  }
  cout<<ans;

}
 
 

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

#define int         long long
#define pb          push_back
#define pii         pair<int,int>
#define vi          vector<int>
#define vii         vector<pii>
#define mi          map<int,int>
#define mii         map<pii,int>
#define all(a)      (a).begin(),(a).end()
#define sz(x)       (int)x.size()
#define endl        "\n"
#define repp(i,a,b) for(int i=a;i<b;i++)
#define rep(i,a,b) 	for(int i=a;i<=b;i++)
#define IOS         ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);

int x,y;

vector<int> isPrime(int N)
{
	int i;
	vi v;
	int c=0;
	v.pb(1);
	for(i=2;i*i<=N;i++)    // O(sqrt(n))
	{
		if(N%i==0)
		{
			if(i*i==N)
			{
				v.pb(i);
			}
			else
			{
				v.pb(i);
				v.pb(N/i);
			}
		}
	}
	v.pb(N);
	return v;
}

int isPrimee(int N)
{
	if(N==1)
	{
		return 1;
	}
	int i;
	int c=0;
	for(i=2;i*i<=N;i++)    // O(sqrt(n))
	{
		if(N%i==0)
		{
			if(i*i==N)
			{
				c++;
			}
			else
			{
				c=c+2;
			}
		}
	}
	if(c==0)
	{
		return 1;
	}
	else
	{
		return 0;
	}
}

int32_t main()
{
	IOS;
	//memset(dp,-1,sizeof(dp));
	cin >> x >> y;
	vi v= isPrime(x);
	vi vv = isPrime(y);
	mi mp;
	vi ans;
	for(int xx:v)
	{
		mp[xx]++;
	}
	mi mpp;
	for(int xx:vv)
	{
		if(mp[xx]>=1 && mpp[xx]==0)
		{
			ans.pb(xx);
			mpp[xx]=1;
		}
	}
	int c=0;
	for(int xx:ans)
	{
		if(isPrimee(xx)==1)
		{
			c++;
		}
	}
	cout << c << endl;
}


Measured memory_bytes: 1280
N = int(input())
P = list(map(int,input().split()))
# print(P)      

ans = 0
for n1 in range(N-1):
    n2 = n1+1
    if P[n1] == n1+1 and P[n2] == n2+1:
        ans+=1
        P[n1],P[n2] = P[n2],P[n1]
        
# print(P,ans)       
for n1 in range(N-1):
    n2 = n1+1
    if P[n1] == n1+1 or P[n2] == n2+1:
        ans+=1
        P[n1],P[n2] = P[n2],P[n1]
        
# print(P)
print(ans)

Measured memory_bytes: 83836
#include <bits/stdc++.h>
using namespace std;
 
int main() {
	int A, B, C, K, cnt = 0;
	cin >> A >> B >> C >> K;
  	assert(1 <= A && A <= 7);
  	assert(1 <= B && B <= 7);
  	assert(1 <= C && C <= 7);
  	assert(1 <= K && K <= 7);
	while (A >= B) { cnt += 1; B *= 2; }
	while (B >= C) { cnt += 1; C *= 2; }
 
	if (cnt <= K) cout << "Yes" << endl;
	else cout << "No" << endl;
	return 0;
}

Measured memory_bytes: 3600
S = input()

num = len(S)
flag = False
for i in range(num):
    s = S[i]
    if i%2 == 0:
        if s ==  'R' or s ==  'U' or s ==  'D':
            continue
        else:
            flag = True
            break
    else:
        if s ==  'L' or s ==  'U' or s ==  'D':
            continue
        else:
            flag = True
            break

if flag:
    print('No')
else:
    print('Yes')

Measured memory_bytes: 3060
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair< ll, ll > Pi;
#define rep(i,n) for(int i=0;i<(n);i++)
#define rep2(i,n) for(int i=1;i<=(n);i++)
#define rep3(i,i0,n) for(int i=i0;i<(n);i++)
#define pb push_back
#define mod 1000000007
const ll INF = 1LL << 60;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
ll gcd(ll a, ll b) {return b?gcd(b,a%b):a;}
ll lcm(ll a, ll b) {return a/gcd(a,b)*b;}
#define all(x) x.begin(), x.end()
#define mp make_pair
bool compare(Pi a, Pi b) {
    if(a.first != b.first){
        return a.first < b.first;
        
    }else{
        return a.second < b.second;
    }
}


bool In_map(ll y,ll x,ll h,ll w){
    if(y<0 || x<0 || y>=h || x>=w){
        return 0;
    }else{
        return 1;
    }
}
const vector<ll> dx{1,0,-1,0};
const vector<ll> dy{0,1,0,-1};


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

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

    sort(all(h));
    ll ans = INF; 
    rep(i,N-K+1){
        ll tmp = h[K+i-1]-h[i];
        chmin(ans,tmp);
    }
    
    cout << ans << endl;


    return 0;
    

}

Measured memory_bytes: 4024
#include<iostream>
#include<iomanip>
#include<vector>
#include<map>
#include<stack>
#include<queue>
#include<string>
#include<utility>
#include<algorithm>
#include<cmath>
#include<climits>
using namespace std;

using ll = long long;

void read();
template<typename First, typename... Rest> void read(First& first, Rest&... rest);
void write();
template<typename First, typename... Rest> void write(First first, Rest... rest);
template<typename T> void write_vec(vector<T>& v, char divider);

int main(){
    int S, W;
    read(S, W);
    if(S <= W) write("unsafe");
    else write("safe");
    return 0;
}

//配列以外の入力を受け取る
void read(){

}
template<typename First, typename... Rest>
void read(First& first, Rest&... rest){
    cin >> first;
    read(rest...);
}
//
//配列以外を出力する
void write(){

}
template<typename First, typename... Rest>
void write(First first, Rest... rest){
    cout << first << " ";
    write(rest...);
}
//
//配列を区切って出力する
template<typename T>
void write_vec(vector<T>& v, char divider){
    for(size_t i = 0; i < v.size(); i++){
        cout << v[i] << divider;
    }
}
//

Measured memory_bytes: 3636
#include <iostream>
#include <cmath>
#include <string>
#include <algorithm>
using namespace std;

#define INF 10000

int main() {
  int N, X, min = INF, res = 0;
  cin >> N >> X;

  int m[N+1];
  for(int i=0; i<N; ++i) {
    cin >> m[i];
    if(min > m[i]) min = m[i];
  }

  for(int i=0; i<N; ++i) {
    X -= m[i];
    ++res;
  }

  cout << res+X/min << endl;

  return 0;
}


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

int main(){
	int N;
	bool flag=false;
	cin >> N;
	
	if(N==3){
		printf("2\n1 3\n2 3\n");
		return 0;
	}
	
	if(N%2==1){
		N--;
		flag=true;
	}
	
	if(flag)cout << N*(N-2)/2+N << endl;
	else cout << N*(N-2)/2 << endl;
	
	for(int i=1;i<N;i++){
		for(int j=i+1;j<=N;j++)if(i+j!=N+1)printf("%d %d\n",i,j);
	}
	
	if(flag){
		for(int i=1;i<=N;i++)cout << i << " " << N+1 << endl;
	}
	
	return 0;
}

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

int main(){
    while(1){
        int n;
        cin >> n;
        if(n==0) break;

        string d1,d2;
        cin >> d1 >> d2;
        map<string, int> dp;
        dp[d1] = 0;
        for(int i=0; i<n; i++){
            map<string, int> tmp;
            for(map<string, int>::iterator itr=dp.begin(); itr!=dp.end(); itr++){
                string s = itr->first;
                int cost = itr->second;
                int f = ( d2[i] -s[i] +10 )%10;
                if(f==0){
                    tmp[s] = cost;
                    continue;
                }
                for(int j=i; j<n; j++){
                    s[j] = (s[j]-'0' +f)%10 +'0';
                    if(tmp.count(s)==0){
                        tmp[s] = cost +1;
                    }else if(tmp[s] > cost +1){
                        tmp[s] = cost +1;
                    }
                }
            }
            dp = tmp;
        }
        cout << dp[d2] << endl;
    }
    return 0;
}



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

int main(){
    int N, K;
    cin >> N >> K;
    int i = 0;
    int d = 0;
    while (pow(K,i) <= N){ 
        //割れるまで桁を増やす
        // このような条件式は"/"を含めず、割り算も積の形に直して書くべき
        i += 1;
    }
    cout << i << endl;
}

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

int main(void) {
	int a[3],tmp,i,j;
	cin >> a[0] >> a[1] >> a[2];
	cout << max({ a[0],a[1],a[2] }) - min({ a[0],a[1],a[2] }) << endl;
	return 0;
}

Measured memory_bytes: 384
import sys
N = int(sys.stdin.readline().rstrip())
S = list(sys.stdin.readline().rstrip())

count = []
cnt_b = 0
cnt_w = 0
for s in S:
    if s == "#":
        cnt_b += 1
    else:
        cnt_w += 1
    count.append((cnt_b, cnt_w))

ans_1 = N - cnt_b
ans_2 = N - cnt_w
ans_3 = float("inf")

for i, j in count:
    ans_3 = min(ans_3, i + cnt_w - j)

print(min(ans_1, ans_2, ans_3))

Measured memory_bytes: 25508
#include<iostream>
#include<cmath>
using namespace std;
int i,s,t,m,n,w[114];
int main()
{
	for(m=99,cin>>n;i<n;cin>>w[i],t+=w[i++]);
	for(i=0;i<n;i++)
	{
		s+=w[i],t-=w[i];
		m=min(m,abs(s-t));
	}
	cout<<m<<endl;
}

Measured memory_bytes: 256
MOD = 10**9 + 7
K = input()
N = len(K)
D = int(input())

S = [[0, 0] for i in range(D)]
S[0][0] = 1
for i in range(N):
    c = int(K[i])
    T = [[0, 0] for i in range(D)]
    for d in range(D):
        w0, w1 = S[d]
        w0 %= MOD
        w = S[d][0] % MOD
        for v in range(c):
            T[(d+v)%D][1] += w0
        T[(d+c)%D][0] += w0

        w1 %= MOD
        for v in range(10):
            T[(d+v)%D][1] += w1
    S = T
print((sum(S[0])-1) % MOD)

Measured memory_bytes: 45020
#include <bits/stdc++.h>
#pragma GCC target("sse4.2")
using namespace std;
using ll = long long;

const ll MOD = 1e9 + 7;
const int N = 21;

ll a[N][N];
ll dp[1 << N];

int main() {
    ios::sync_with_stdio(false);
    int n;
    cin >> n;
    for (int i=0; i<n; i++) {
        for (int j=0; j<n; j++) {
            cin >> a[i][j];
        }
    }
    dp[0] = 1;
    for (int mask=0; mask<(1<<n); mask++) {
        int k = __builtin_popcount(mask);
        for (int j=0; j<n; j++) {
            int bit = 1<<j;
            if (!(mask&bit) && a[k][j]) {
                dp[mask|bit] = (dp[mask|bit] + dp[mask]) % MOD;
            }
        }
    }
    cout << dp[(1<<n)-1] << '\n';
}


Measured memory_bytes: 16768
//~ while (clock()<=69*CLOCKS_PER_SEC)
//~ #pragma comment(linker, "/stack:200000000")
#pragma GCC optimize("O3")
//~ #pragma GCC target ("avx2")
//~ #pragma GCC optimize("Ofast")
//~ #pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
//~ #pragma GCC optimize("unroll-loops")
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

using namespace __gnu_pbds;
using namespace std;

template <typename T>
using ordered_set =
    tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

#define sim template < class c
#define ris return * this
#define dor > debug & operator <<
#define eni(x) sim > typename \
  enable_if<sizeof dud<c>(0) x 1, debug&>::type operator<<(c i) {
sim > struct rge { c b, e; };
sim > rge<c> range(c i, c j) { return rge<c>{i, j}; }
sim > auto dud(c* x) -> decltype(cerr << *x, 0);
sim > char dud(...);
struct debug {
#ifdef LOCAL
~debug() { cerr << endl; }
eni(!=) cerr << boolalpha << i; ris; }
eni(==) ris << range(begin(i), end(i)); }
sim, class b dor(pair < b, c > d) {
  ris << "(" << d.first << ", " << d.second << ")";
}
sim dor(rge<c> d) {
  *this << "[";
  for (auto it = d.b; it != d.e; ++it)
    *this << ", " + 2 * (it == d.b) << *it;
  ris << "]";
}
#else
sim dor(const c&) { ris; }
#endif
};
#define imie(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "

#define shandom_ruffle random_shuffle

using ll=long long;
using pii=pair<int,int>;
using pll=pair<ll,ll>;
using vi=vector<int>;
using vll=vector<ll>;
const int nax=1000*1007;

int n;
int k;

ll tab[nax];
ll dp[nax];

int main()
{
	scanf("%d%d", &n, &k);
	for (int i=1; i<=n; i++)
	{
		scanf("%lld", &tab[i]);
	}
	for (int i=2; i<=n; i++)
	{
		dp[i]=1e18;
		for (int j=1; j<=k && j<i; j++)
			dp[i]=min(dp[i], dp[i-j]+abs(tab[i]-tab[i-j]));
	}
	printf("%lld\n", dp[n]);
	return 0;
}


Measured memory_bytes: 5120
buff = input().split()

stack = []
for b in buff:
    try:
        num = int(b)
        stack.append(num)
    except ValueError:
        op = b
        right = stack.pop()
        left = stack.pop()
        if op == '+':
            res = left + right
        elif op == '-':
            res = left - right
        else:
            res = left * right
        stack.append(res)

print(stack.pop())



Measured memory_bytes: 5600
function Main(input) {
  var dataList = input.split("\n");
  var data = dataList[0].split(" ");
  var n = data[0];
  var d = data[1];
  var checkNum = (d * 2) + 1;
  var num = Math.floor(n/checkNum);
  var rest = n % checkNum;
  if (rest > 0) num += 1;
  console.log(num);
  
}

//*この行以降は編集しないでください（標準入出力から一度に読み込み、Mainを呼び出します）
Main(require("fs").readFileSync("/dev/stdin", "utf8"));

Measured memory_bytes: 7372
import sys
INF = 1 << 60
MOD = 10**9 + 7 # 998244353
sys.setrecursionlimit(2147483647)
input = lambda:sys.stdin.readline().rstrip()
from collections import Counter
def resolve():
    n = int(input())
    C = Counter(map(int, input().split()))
    total = 0
    for key, val in C.items():
        total += key * val

    for _ in range(int(input())):
        b, c = map(int, input().split())
        num = C[b]
        total += (c - b) * num
        C[b] = 0
        C[c] += num
        print(total)
resolve()

Measured memory_bytes: 92512
#include<iostream>
#include<algorithm>
#include<string>
#include<vector>
#include<cstdlib>
#include<queue>
#include<set>
#include<cstdio>

using namespace std;

#define ll long long
#define rep(i, n) for(int i = 0; i < n; i++)
#define P pair<int, int>

typedef vector<int> vec;
typedef vector<vec> mat;

const ll mod = 1000000007;

int main(){
    string s;
    cin >> s;
    string a[] = {"SUN","MON","TUE","WED","THU","FRI","SAT"};
    rep(i, 7){
        if(a[i] == s){
            cout << 7 - i << endl;
        }
    }
}

Measured memory_bytes: 3612
#include <iostream>
#include <queue>
#include <algorithm>
using namespace std;
using point = pair<int, int>;
using info = pair<point, int>;
const point Start = make_pair(0, 0);
int N;
int A[2][100];
int ans;
int main(void) {
	cin >> N;
	for (int i = 0; i < 2; ++i) for (int n = 0; n < N; ++n) cin >> A[i][n];
	queue<info> poses; poses.push(make_pair(Start, 0));
	while (!poses.empty()) {
		info p = poses.front(); poses.pop();
		p.second += A[p.first.first][p.first.second];
		ans = max(ans, p.second);
		if (p.first.first + 1 < 2) poses.push(make_pair(make_pair(p.first.first + 1, p.first.second), p.second));
		if (p.first.second + 1 < N) poses.push(make_pair(make_pair(p.first.first, p.first.second + 1), p.second));
	}
	cout << ans << endl;
	return 0;
}

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

using namespace std;
typedef long long ll;
typedef long double lb;
#define rep(i,j,n) for (ll i = j; i < (n); i++)
#define repr(i,j,n) for(ll i = j; i >= (n); i--)
#define each(i,mp) for(auto& i:mp)
#define all(x) (x).begin(),(x).end()
#define CLR(mat,f) memset(mat, f, sizeof(mat))
#define IN(a, b, x) (a<=x&&x<b)
#define out(ans) cout << ans << 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; }
typedef pair<ll,ll>P;
const lb pi=acos(-1);
const ll mod=1e9+7;
const ll INF = 1LL<<60;
const ll m=1LL<<32;

int main(){

  string s;cin>>s;

  rep(i,0,3){
    cout<<s[i];
  }
  cout<<endl;

  return 0;
}


Measured memory_bytes: 3612
#include<bits/stdc++.h>
using namespace std;
int main()
{  int a,b,c,k,he=0,max=0;
   cin>>a>>b>>c>>k;
   he=a+b+c;
   for(int i=1;i<=k;i++)
   { 
     if(a>max)  max=a;
     if(b>max)  max=b;
     if(c>max)  max=c;
     he=he+max;
     if(c==max)  c*=2;
     if(b==max)  b*=2;
     if(a==max)  a*=2;
     max=0;
   }
   cout<<he<<endl;
   return 0;
} 

Measured memory_bytes: 256
program prob57
    implicit none
    character(16) :: s,t
    integer :: i, c
    read(*,*) s
    t = 'CODEFESTIVAL2016'
    c = 0
    do i = 1, 16
        if(s(i:i) /= t(i:i)) then
            c = c + 1
        end if
    end do
    write(*,*) c
    stop
contains
end program prob57

Measured memory_bytes: 2796
#include<stdio.h>

int main(void){
  char S[11];  scanf("%s",S);
  int month=0;
  month=(S[5]-'0')*10+(S[6]-'0');

  if(month<=4){
    printf("Heisei\n");
  }else{
    printf("TBD\n");
  }

  return 0;
}


Measured memory_bytes: 128
#include <iostream>
#define rep(i, n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
using P = pair<int, int>;

int n;
int a[101];

int main() {
    cin >> n;
    rep(i, n) cin >> a[i];

    int flag = 1;
    int changeNum = 0;
    while (flag) {
        flag = 0;
        for (int j = n - 1; j > 0; j--) {
            if (a[j] < a[j - 1]) {
                swap(a[j], a[j - 1]);
                flag = 1;
                changeNum++;
            };
        }
    }
    rep(i, n - 1) cout << a[i] << " ";
    cout << a[n - 1] << endl << changeNum << endl;
    return 0;
}



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

int main(){
    ll a,b,c,d;
    cin >> a >> b >> c >> d;
    vector<ll> prd(0);
    prd.push_back(a*c);
    prd.push_back(a*d);
    prd.push_back(b*c);
    prd.push_back(b*d);
    ll ans = *max_element( prd.begin(), prd.end() );
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3616
#![allow(unused_imports, unused_macros, dead_code)]

macro_rules! min {
    (.. $x:expr) => {{
        let mut it = $x.iter();
        it.next().map(|z| it.fold(z, |x, y| min!(x, y)))
    }};
    ($x:expr) => ($x);
    ($x:expr, $($ys:expr),*) => {{
        let t = min!($($ys),*);
        if $x < t { $x } else { t }
    }}
}
macro_rules! max {
    (.. $x:expr) => {{
        let mut it = $x.iter();
        it.next().map(|z| it.fold(z, |x, y| max!(x, y)))
    }};
    ($x:expr) => ($x);
    ($x:expr, $($ys:expr),*) => {{
        let t = max!($($ys),*);
        if $x > t { $x } else { t }
    }}
}
macro_rules! ewriteln {
    ($($args:expr),*) => { let _ = writeln!(&mut std::io::stderr(), $($args),*); };
}
macro_rules! trace {
    ($x:expr) => { ewriteln!(">>> {} = {:?}", stringify!($x), $x) };
    ($($xs:expr),*) => { trace!(($($xs),*)) }
}
macro_rules! flush {
    () => {
        std::io::stdout().flush().unwrap();
    };
}
macro_rules! put {
    (.. $x:expr) => {{
        let mut it = $x.iter();
        if let Some(x) = it.next() { print!("{}", x); }
        for x in it { print!(" {}", x); }
        println!("");
    }};
    ($x:expr) => { println!("{}", $x) };
    ($x:expr, $($xs:expr),*) => { print!("{} ", $x); put!($($xs),*) }
}

const M: i64 = 1_000_000_007;

fn main() {
    let mut sc = Scanner::new();
    let a: usize = sc.cin();
    let b: usize = sc.cin();
    for x in 1..1000000 {
        if x * 8 / 100 == a && x * 10 / 100 == b {
            put!(x);
            return;
        }
    }
    put!(-1);
}

use std::collections::VecDeque;
use std::io::{self, Write};
use std::str::FromStr;

struct Scanner {
    stdin: io::Stdin,
    buffer: VecDeque<String>,
}
impl Scanner {
    fn new() -> Self {
        Scanner {
            stdin: io::stdin(),
            buffer: VecDeque::new(),
        }
    }
    fn cin<T: FromStr>(&mut self) -> T {
        while self.buffer.is_empty() {
            let mut line = String::new();
            let _ = self.stdin.read_line(&mut line);
            for w in line.split_whitespace() {
                self.buffer.push_back(String::from(w));
            }
        }
        self.buffer.pop_front().unwrap().parse::<T>().ok().unwrap()
    }
    fn chars(&mut self) -> Vec<char> {
        self.cin::<String>().chars().collect()
    }
    fn vec<T: FromStr>(&mut self, n: usize) -> Vec<T> {
        (0..n).map(|_| self.cin()).collect()
    }
}


Measured memory_bytes: 4352
/*=============================================================================================================================/*
                                               Bismillahir Rahmanir Rahim

      _     ____  ___  ____   _   _  _         ___  ____   _         _     __  __
     / \   / ___||_ _|| __ ) | | | || |       |_ _|/ ___| | |       / \   |  \/  |
    / _ \  \___ \ | | |  _ \ | | | || |        | | \___ \ | |      / _ \  | |\/| |
   / ___ \  ___) || | | |_) || |_| || |___     | |  ___) || |___  / ___ \ | |  | |
  /_/   \_\|____/|___||____/  \___/ |_____|   |___||____/ |_____|/_/   \_\|_|  |_|

   _   __           __  __  __
  |_) (_  _  o__   /   (_  |_
  |_)o__)(_  || |  \__ __) |__

    ___                    _   _      _                _ _               __   ___                 _         _        _
   / __|_ _ ___ ___ _ _   | | | |_ _ (_)_ _____ _ _ __(_) |_ _  _   ___ / _| | _ ) __ _ _ _  __ _| |__ _ __| |___ __| |_
  | (_ | '_/ -_) -_) ' \  | |_| | ' \| \ V / -_) '_(_-< |  _| || | / _ \  _| | _ \/ _` | ' \/ _` | / _` / _` / -_|_-< ' \
   \___|_| \___\___|_||_|  \___/|_||_|_|\_/\___|_| /__/_|\__|\_, | \___/_|   |___/\__,_|_||_\__, |_\__,_\__,_\___/__/_||_|
                                                            |__/                           |___/


   FB: https://facebook.com/SIAsibul
   Gmail: asibulislam8@gmail.com

/*=============================================================================================================================*/

#include<bits/stdc++.h>
using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<ll, int> pli;
typedef pair<int, ll> pil;
typedef vector<pii> vii;
typedef vector<pil> vil;
typedef vector<pli> vli;
typedef vector<pll> vll;

#define ff first
#define ss second
#define pb push_back
#define mp make_pair
#define sz size()
#define all(a)  a.begin(), a.end()
#define mem(a, b)     memset(a, b, sizeof(a))
#define f0(i,n) for(ll i=0;i<(n);i++)
#define f1(i,n) for(ll i=1;i<=(n);i++)
#define f2(i,a,n) for(ll i=(a);i<=(n);i++)
#define fr(i,n,a) for(ll i=(n);i>=(a);i--)
#define rep(i,a,b,c) for(ll i=(a);i!=(b);i+=(c))
#define nl "\n"


const int INF = 1e9 + 5;
const int MXN = 2e5 + 5;
const int MOD = 1e9 + 7;

void solve(){
    int x; cin >> x;
    if(x >= 30) cout << "Yes" << nl;
    else cout << "No" << nl;
}



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


Measured memory_bytes: 3636
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.List;

/*Atcoder用
 * 		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		String[] tmp = br.readLine().split(" ");
		int a = Integer.parseInt(tmp[0]);
		int b = Integer.parseInt(tmp[1]);
		int c = Integer.parseInt(tmp[2]);


		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		String get = br.readLine();
		char[] s = get.toCharArray();
		for(char c:s)System.out.println(c);
 */

public class Main {
	public static void main(String[] args) throws IOException {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		String str = br.readLine();
		int N = Integer.parseInt(str);

		List<Long> als = new ArrayList<Long>();
		String[] tmp = br.readLine().split(" ");
		for (int n = 0; n < N; n++) {
			als.add((long)Integer.parseInt(tmp[n]));
		}
		int sum = 0;
		for(int i = 0;i<als.size();i++){
			sum += als.get(i)-1;
		}

		System.out.println(sum);
	}

	static long gcd (long a, long b) {
		long temp;
		while((temp = a%b)!=0) {
			a = b;
			b = temp;
		}
		return b;
	}


	//最小公倍数lcm
	private static long lcm(long m, long n) {
	    long tmp =  m  / gcd(m, n);
	    return tmp*n;
	}
}


Measured memory_bytes: 21716
H, W = map(int, input().split())
l = [list(input()) for _ in range(H)]

from collections import deque
q = deque()
for i, r in enumerate(l):
    for j, c in enumerate(r):
        if c == '#':
            l[i][j] = 0
            q.append((i, j))
d = [(0, 1), (0, -1), (1, 0), (-1, 0)]

while q:
    y, x = q.popleft()
    for dy, dx in d:
        if (0 <= y+dy < H) and (0 <= x+dx < W) and l[y+dy][x+dx] == '.':
            l[y+dy][x+dx] = l[y][x] + 1
            q.append((y+dy, x+dx))

m = 0
for r in l:
    for c in r:
        if m < c:
            m = c
print(m)

Measured memory_bytes: 137052
#include <stdio.h>
#include <cmath>
#include <algorithm>
#include <cfloat>
#include <stack>
#include <queue>
#include <vector>
#include <string>
#include <iostream>
typedef long long int ll;
typedef unsigned long long int ull;
#define BIG_NUM 2000000000
#define MOD 1000000007
#define EPS 0.000000001
using namespace std;

int main() {

	int N;
	scanf("%d",&N);

	char* buf = new char[N+1];

	scanf("%s",buf);

	int ans = 0;

	char pre = '@';

	for(int i = 0; buf[i] != '\0'; i++){
		if(buf[i] == 'o'){
			ans++;
		}else if(buf[i] == 'x' && pre != 'x'){
			ans++;
		}else{
			break;
		}
		pre = buf[i];
	}

	printf("%d\n",ans);

	return 0;
}

Measured memory_bytes: 3312
#include <stdio.h>
#include <stdlib.h>
#include <math.h>


int main(void)
{
    int a, b, k;
    scanf("%d %d %d", &a, &b, &k);

    int num = 0;
    int res;
    for (int i=100; ; i--){
        if (a%i == 0 && b%i == 0){
            num++;
        }
        if (num == k){
            res = i;
            break;
        }
    }


    printf("%d\n", res);


    

    return 0;
} 



Measured memory_bytes: 128
#include<iostream>
#include<fstream>

//http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=1154&lang=jp


using namespace std;


ifstream fin;
ofstream fout;

int main(){

	fin.open("input.txt");
	fout.open("output.txt");

	int n;			//input
	int a[2];		//月曜土曜素因数
	int b[30] = {};		//因数記憶
	int j = 0;
	bool isPrime = true;


	while (true){
		cin >> n;

		//初期化
		a[0] = 6;
		a[1] = 8;
		b[0] = 7;
		j = 0;

		if (n == 1)break;
		
		//cout << n << ':';
		fout << n << ':';

		while (a[0] <= n / 6){
			for (int k = 0; k < 2; k++){

				isPrime = true;

				if (n%a[k] == 0){
					for (int m = 0; m < j; m++)
						if (a[k] % b[m] == 0)isPrime = false;
					if (isPrime == true){
						//cout << ' ' << a[k];
						fout << ' ' << a[k];
						b[j] = a[k];
//						//cout << " b[" << j << "]= " << b[j] << endl;
						j++;
					}
				}
				a[k] += 7;
			}
		}

		if (b[0] == 7){
			//cout << ' ' << n;
			fout << ' ' << n;
		}
		//cout << endl;
		fout << endl;
	}

	return 0;
}

Measured memory_bytes: 1236
from itertools import combinations

N = int(input())

M = 0
A = 0
R = 0
C = 0
H = 0

for i in range(N):
    s = input()
    if s[0] == 'M':
        M += 1
    elif s[0] == 'A':
        A += 1
    elif s[0] == 'R':
        R += 1
    elif s[0] == 'C':
        C += 1
    elif s[0] == 'H':
        H += 1

lst = [M,A,R,C,H]
# lst = [2,3,4]
# print(lst)
x = list(combinations(lst, 3))
# print(x)

ans = 0
for a,b,c in x:
    ans += a * b * c
print(ans)

Measured memory_bytes: 3064
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < n; ++i)
#define FOR(i, a, b) for (int i = a; i < b; ++i)
#define ALL(vec) vec.begin(), vec.end()
#define rALL(vec) vec.rbegin(), vec.rend()
using namespace std;
using ll = long long;

int gcd(int x, int y) {
    int tmp = x % y;
    while (tmp != 0) {
        x = y;
        y = tmp;
        tmp = x % y;
    }
    return y;
}

int main() {
    int N, X;
    cin >> N >> X;
    vector<int> x(N);
    rep(i, N) {
        int tmp;
        cin >> tmp;
        x[i] = abs(X - tmp);
    }
    int ans = x[0];
    if (N == 1) {
        cout << x[0] << endl;
        return 0;
    }
    rep(i, N) {
        ans = gcd(ans, x[i]);
    }
    cout << ans << endl;
    return 0;
}

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

#define _ub upper_bound

using namespace std;

typedef long long ll;

const int MAXN = 1000 + 23, MAXX = 1000 * 1000 + 123, D = 1000 * 1000 * 1000 + 7;








void inpre();

int n, m, a[MAXN], b[MAXN];
bool mark[MAXX];
ll ans = 1;

int main() {
	inpre();
	for (int i = n * m; i; i--) {
		if (mark[i])
			continue;
		int x = _ub(b, b + m + 1, i) - b, y = _ub(a, a + n + 1, i) - a;
		ans *= (m - x) * (n - y) - n * m + i;
		ans %= D;
	}
	cout << ans;
	return 0;
}
void inpre() {
	cin >> n >> m;
	bool bad[MAXX] = {}, bid[MAXX] = {};
	for (int i = 0; i < n; i++) {
		cin >> a[i];
		if (bad[a[i]]) {
			cout << 0;
			exit(0);
		}
		bad[a[i]] = true, mark[a[i]] = true;
	}
	for (int i = 0; i < m; i++) {
		cin >> b[i];
		if (bid[b[i]]) {
			cout << 0;
			exit(0);
		}
		bid[b[i]] = true, mark[b[i]] = true;
	}
	sort(a, a + n), sort(b, b + m);
	b[m] = a[n] = INT_MAX; 
	for (int i = 0; i < n; i++) {
		int x = _ub(b, b + m + 1, a[i]) - b;
		if (x > 0 && b[x - 1] == a[i])
			continue;
		ans *= m - x;
		ans %= D;
	}
	for (int i = 0; i < m; i++) {
		int x = _ub(a, a + n + 1, b[i]) - a;
		if (x > 0 && a[x - 1] == b[i])
			continue;
		ans *= n - x;
		ans %= D;
	}
}

Measured memory_bytes: 2176
#include<iostream>
using namespace std;
#include<cstdio>
#include<cmath>

struct Point{ double x, y; };

Point set_p(double a, double b)
{
    Point p;
    p.x = a; p.y = b;
    return p;
}

struct Vector{ double vx, vy; };

Vector set_v(const Point &p1, const Point &p2)
{
    Vector v;
    v.vx = p2.x - p1.x;
    v.vy = p2.y - p1.y;
    return v;
}

int ccw(const Point &p0, const Point &p1, const Point &p2) // P0, P1, P2 counter_clockwise.
{
	double d1 = (p1.x - p0.x) * (p2.y - p0.y);
	double d2 = (p2.x - p0.x) * (p1.y - p0.y);
	if(d1 == d2) return 0;
	return (d1 > d2 ? 1 : -1);
}

double inpro(const Vector &v1, const Vector &v2)
{
    return (v1.vx * v2.vx) + (v1.vy * v2.vy);
}

double det2(const Vector &v1, const Vector &v2)
{
	return (v1.vx * v2.vy) - (v1.vy * v2.vx);
}

bool crit(const Point &p0, const Point &p1, const Point &p2, const Point &p3)
{
	if((p0.x > p2.x) && (p0.x > p3.x) && (p1.x > p2.x) && (p1.x > p3.x)) return true;
	if((p0.x < p2.x) && (p0.x < p3.x) && (p1.x < p2.x) && (p1.x < p3.x)) return true;

	if((p0.y > p2.y) && (p0.y > p3.y) && (p1.y > p2.y) && (p1.y > p3.y)) return true;
	if((p0.y < p2.y) && (p0.y < p3.y) && (p1.y < p2.y) && (p1.y < p3.y)) return true;
	return false;
}

int main()
{
    int q;
    scanf("%d", &q);
    double x0, y0, x1, y1, x2, y2, x3, y3;
    for(int i = 0; i < q; i++){
        scanf("%lf %lf %lf %lf %lf %lf %lf %lf", &x0, &y0, &x1, &y1, &x2, &y2, &x3, &y3);
        Point P0 = set_p(x0, y0), P1 = set_p(x1, y1), P2 = set_p(x2, y2), P3 = set_p(x3, y3);
		Vector V01 = set_v(P0, P1), V23 = set_v(P2, P3);
		if(ccw(P0, P1, P2) * ccw(P0, P1, P3) > 0 || ccw(P2, P3, P0) * ccw(P2, P3, P1) > 0){
			printf("0\n");
		}else {
			if(det2(V01, V23) == 0 && crit(P0, P1, P2, P3)){
				printf("0\n");
			}else{
				printf("1\n");
			}
		}
    }
    return 0;
}

Measured memory_bytes: 1204
#include <iostream>
using namespace std;
#include <string>
#include <vector>
#include <algorithm>
#include <map>
typedef long long ll;
#include <cmath>
#include <iomanip>

const int MOD = 1000000007;


ll POWER(ll x,ll y)
{
	ll ret=1;
	ll p=x;
	for (ll i=y;i>0;i/=2)
	{
		if (i%2) ret=(ret*p)%MOD;
		p=(p*p)%MOD;
	}
	return ret;
}
ll gcm(ll a, ll b)
{
	if (b>a) {ll c=a; a=b; b=c;}
	while (b>0)
	{
		ll r=a%b;
		a=b;
		b=r;
	}
	return a;
}


int main(int argc, char *argv[])
{
	int d,t,s;
	cin>>d>>t>>s;
	cout<<((d<=t*s)?"Yes":"No")<<endl;
	return 0;
}



Measured memory_bytes: 3620
N, X, Y = map(int, input().split())
X -= 1
Y -= 1
ans = [0] * N
for i in range(N):
    for j in range(i + 1, N):
        c = min(j - i, abs(X - i) + abs(Y - j) + 1)
        ans[c] += 1
for i in ans[1:]:
    print(i)


Measured memory_bytes: 3444
function Main(input) {
    var A = parseInt(input[0], 10);
    var B = parseInt(input[1], 10);

    console.log(A > 9 || B > 9 ? '-1' : A * B);
}

Main(require("fs").readFileSync("/dev/stdin", "utf8").trim().split(/\n|\s/));

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

int main(){
    // 制約見て！！！デカかったらlong longにすること！
    int n;
    cin >> n;
    while(n != 0){
        if(n %10 == 7){
            cout << "Yes"<<endl;
            return 0;
        }else{
            n /= 10;
        }
    }
    cout<<"No"<<endl;
}   

Measured memory_bytes: 3508
program weather_prediction
  implicit none
  character(1) :: s
  read(*,*) s
  select case (s)
  case ("S")
    write(*,'(a)') "Cloudy"
  case ("C")
    write(*,'(a)') "Rainy"
  case ("R")
    write(*,'(a)') "Sunny"
  end select
end program weather_prediction

Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<cmath>
#include<algorithm>
using namespace std;
const int maxn=25;
int main(){
    int a,m[maxn],now,ans=1;
    cin>>a;
    cin>>now;

    for(int i=2;i<=a;i++){
        cin>>m[i];
        if(m[i]>=now){
            now=m[i];
            ans++;
        }
    }
    cout<<ans<<endl;
    return 0;
}

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

using namespace std;

const int MAXN = 105;

int n, x, a[MAXN];

int main() {
  cin >> n >> x;
  for(int i = 1; i <= n; i++) {
    cin >> a[i];
  }
  sort(a + 1, a + n + 1);
  int ans = 0;
  for(int i = 1; i <= n; i++) {
    if(x - a[i] >= 0) {
      x -= a[i];
      ++ans;
    } else {
      break;
    }
  }
  if(ans == n && x != 0) --ans;
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256