akhauriyash/Code-Regression huggingface dataset:
//string _(){
//    string s;
//    cin >> s;
//    int f = s[0] == s.back();
//    f = sz(s)-f;
//    if(f%2)
//        return "First";
//    return "Second";
//}
#include <iomanip>
#include <vector>
#include <utility>
#include <iostream>
#include <string>
#define all(v) (v).begin(), (v).end()
#define sz(v) ll(v.size())
#define T1 template<typename T> static
using namespace std;
typedef long long ll;
T1 ostream& operator<<(ostream& stream, const vector<T>& t);
T1 istream& read(T, T, istream& = cin);
string _(){
    string s;
    cin >> s;
    int f = s[0] == s.back();
    f = sz(s)-f;
    if(f%2)
        return "First";
    return "Second";
}
int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    cout << fixed << setprecision(15);
        cout << _() << '\n';
}


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

using namespace std;

int main(){
        int x;
        cin>>x;
        int x2=x;
        int f=0;
        while(x!=0){
                f+=x%10;
                x/=10;
        }
        if(x2%f==0){
                cout<<"Yes"<<endl;
        }
        else{
                cout<<"No"<<endl;
        }
        return 0;
}


Measured memory_bytes: 256
// -*- coding:utf-8-unix -*-

use proconio::input;
use proconio::fastout;

#[fastout]
fn main() {
    input! {
        n: usize,
        a: [usize; n],
    }

    let mut ans = 0;
    let mut start = 1;
    let mut mass = 0;

    const  MOD: usize = 1000000000 + 7;

    for elem in &a[..n-1] {
        mass += elem;
      
        ans += mass * &a[start];
        ans %= MOD; 
        mass %= MOD;
        start += 1;
    };


    println!("{}",ans);
    
    
}


Measured memory_bytes: 5672
#define _CRT_SECURE_NO_WARNINGS
#include<iostream>
#include<sstream>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<climits>
#include<cmath>
#include<string>
#include<vector>
#include<set>
#include<map>
#include<queue>
#include<numeric>
#include<functional>
#include<algorithm>
#include<bitset>
#include<tuple>
#include<unordered_set>
#include<unordered_map>
#include<random>
#include<array>
#include<cassert>
using namespace std;
#define INF (1<<29)
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define all(v) v.begin(),v.end()
#define uniq(v) v.erase(unique(all(v)),v.end())





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

	int n, k;
	cin >> n >> k;

	double ans = 0;

	for (int x = 1; x <= n; x++) {
		double p = 1.0 / n;

		int s = x;
		while (s < k) {
			s *= 2;
			p /= 2;
		}
		ans += p;
	}

	printf("%.10f\n", ans);



	return 0;
}

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

#define fs first
#define sc second
#define pb emplace_back
#define mp make_pair
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()

constexpr int mod = 1e9 + 7;
constexpr int32_t inf = 1001001001;
constexpr int64_t infll = 1001001001001001001ll;
constexpr int dx[] = {0, -1, 1, 0, -1, 1, -1, 1}, dy[] = {-1, 0, 0, 1, -1, -1, 1, 1};
const string YES = "YES", NO = "NO", Yes = "Yes", No = "No", yes = "yes", no = "no";

// clang-format off
// ostream &operator<<(ostream &os, __int128_t value) { if (ostream::sentry(os)) { __uint128_t tmp = value < 0 ? -value : value; char buffer[64]; char *d = end(buffer); do { --d; *d = "0123456789"[tmp % 10]; tmp /= 10; } while (tmp != 0); if (value < 0) { --d; *d = '-'; } int len = end(buffer) - d; if (os.rdbuf()->sputn(d, len) != len) { os.setstate(ios_base::badbit); }} return os; }
// istream &operator>>(istream &is, __int128_t &value) { string in; is >> in; value = 0; for (const char &c : in) { if ('0' <= c && c <= '9') value = 10 * value + (c - '0'); } if (in[0] == '-') value *= -1; return is; }
// ostream &operator<<(ostream &os, __uint128_t value) { if (ostream::sentry(os)) { char buffer[64]; char *d = end(buffer); do { --d; *d = "0123456789"[value % 10]; value /= 10; } while (value != 0); int len = end(buffer) - d; if (os.rdbuf()->sputn(d, len) != len) { os.setstate(ios_base::badbit); }} return os; }
// istream &operator>>(istream &is, __uint128_t &value) { string in; is >> in; value = 0; for (const char &c : in) { if ('0' <= c && c <= '9') value = 10 * value + (c - '0'); } return is; }
template <typename T> ostream &operator<<(ostream &os, vector<T> &v) { os << v[0]; for (int i = 1; i < v.size(); ++i) os << " " << v[i]; return os; }
template <typename T> istream &operator>>(istream &is, vector<T> &v) { for (T &in : v) is >> in; return is; }
template <typename T1, typename T2> ostream &operator<<(ostream &os, pair<T1, T2> p) { os << p.fs << " " << p.sc; return os; }
template <typename T1, typename T2> istream &operator>>(istream &is, pair<T1, T2> &p) { is >> p.fs >> p.sc; return is; }

struct IoSetup { IoSetup(){ cin.tie(0); ios::sync_with_stdio(0); cout << fixed << setprecision(10); cerr << fixed << setprecision(10); } } iosetup;

inline int64_t in() { int64_t x = 0; cin >> x; return x; }

template <typename T> void sort(vector<T> &v) { sort(all(v)); }
template <typename T> vector<T> make_v(size_t a, T b) { return vector<T>(a, b); }
template <typename... Ts> auto make_v(size_t a, Ts... ts) { return vector<decltype(make_v(ts...))>(a, make_v(ts...)); }
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); }
// clang-format on

signed main(int argc, char *argv[]) {
  int n = in();
  map<int, int> ushi;
  for (int i = 0; i < n; ++i) {
    ushi[in()]++;
  }

  int ans = 0;
  for (auto uku : ushi) ans += uku.sc & 1;

  cout << ans << endl;
}


Measured memory_bytes: 4992
#include <bits/stdc++.h>
#define pb push_back
#define mp make_pair
#define CLR(a) memset(a, 0, sizeof(a))
#define DBG(x) cout<<(#x)<<"="<<x<<endl
#define FOR(i, a, b)  for(int i=(a); i<(b); i++)
#define REP(i, a, b)  for(int i=(a); i<=(b); i++)
#define DOWN(i, a, b) for(int i=(a); i>=(b); i--)

using namespace std;

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

const double eps = 1e-8;
const int INF = 0x3f3f3f3f;
const ll LL_INF = 0x3f3f3f3f3f3f3f3f;
const ll mod = 1000000009;
const int N= 2e5 +10;

int n;
ll a[N], sum[N];
ll ans;
map<ll, int> M;

int main() {
	cin>>n;
	REP(i, 1, n) cin>>a[i];
	REP(i, 1, n) {
		sum[i]=sum[i-1]+a[i];
	}
	M[0]=1;
	REP(i, 1, n) {
		ans+=M[sum[i]];
		M[sum[i]]++;
	}
	cout<<ans<<endl;
	//cout<<1.*clock()/CLOCKS_PER_SEC<<"ms"<<"\n";
	return 0;
}

Measured memory_bytes: 15872
#d
n,m=map(int, input().split())
ab = [list(map(int, input().split())) for _ in range(m)]
maze = []
inf = 9999999
dist = [inf]* n
dist[0] = 0
queue = []
answer = [0]*n

goto = [[] * 1 for i in range(n)]
for i in range(len(ab)):
    goto[ab[i][0]-1].append(ab[i][1]-1)
    goto[ab[i][1]-1].append(ab[i][0]-1)

queue.extend([0])

while queue != []:
    go = queue.pop(0)
    for h in goto[go]:
        if dist[h] == inf:
            queue.append(h)
            dist[h] = dist[go]+1
            answer[h] =go+1
            

            
print("Yes")
for i in answer[1:]:
    print(i)

Measured memory_bytes: 74176
using System;
using System.Collections.Generic;
class Program
{
	static void Main(string[] args)
	{
		string[] str = Console.ReadLine().Split();
		int N = int.Parse(str[0]);
		int M = int.Parse(str[1]);
		int C = int.Parse(str[2]);
		string[] str2 = Console.ReadLine().Split();
		int[]B = new int[M];
		for(var i=0;i<M;i++){
			B[i] = int.Parse(str2[i]);
		}
		int[,]A = new int[N,M];
		int ans = 0;
		for(var i=0;i<N;i++){
			string[] str3 = Console.ReadLine().Split();
			int ct = 0;
			for(var j=0;j<M;j++){
				A[i,j] = int.Parse(str3[j]);
				ct += A[i,j]*B[j];
			}
			ct += C;
			if(ct>0){
				ans++;
			}
		}
		Console.WriteLine(ans);
	}
}

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

using namespace std;

int main() {
    int n;
    cin>>n;
    //take positive and negative array to store x+y (+ +) and x-y (+ -)
    long long int pa[n], na[n];
    for(int i = 0; i < n; i++) {
        long long int a, b;
        cin>>a>>b;
        pa[i] = a+b;
        na[i] = a-b;
    }
    sort(pa, pa+n);
    sort(na, na+n);
    cout<<max(pa[n-1] - pa[0], na[n-1]-na[0])<<endl;
    return 0;
}

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

int main(void) {
	int A, B, C, K;
	cin >> A >> B >> C >> K;
	int xa = min(A, K);
	K -= xa;
	int xb = min(B, K);
	K -= xb;
	int xc = min(C, K);

	int ans = xa - xc;
	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 3632
parseInt(x) = parse(Int,x)
parseMap(x::Array{SubString{String}, 1}) = map(parseInt, x)

function main()
    N = parseInt(readline())
    n = N%10
    if n == 3 
        println("bon")
    elseif n*(n-1)*(n-6)*(n-8) == 0
        println("pon") 
    else
        println("hon")
    end
end

main()

Measured memory_bytes: 153068
from collections import deque

N,M=map(int,input().split())
graph=[[] for i in range(N+1)]
for i in range(M):
    A,B=map(int,input().split())
    graph[A].append(B)
    graph[B].append(A)
dist=[-1]*(N+1)
dist[0]=0
dist[1]=0
d=deque()
d.append(1)
ans=[0]*(N+1)
while d:
    v=d.popleft()
    for i in graph[v]:
        if dist[i]!=-1:
            continue
        dist[i]=dist[v]+1
        d.append(i)
        if ans[i]!=0:
            continue
        ans[i]+=v
print("Yes")
for i in ans:
    if i==0:
        continue
    print(i)     



    









        

    









    

        




    















    



    





    






        






    
















        


























            
    


    


    
    














    


    














Measured memory_bytes: 37496
#include<iostream>
using namespace std;
int main(){
	while(1){
		int h,w;
		cin >> h >> w;
		if(h == 0 && w == 0){
			break;
		}
		for(int i = 0; i < h; i++){
			for(int j = 0; j < w; j++){
				if(i == 0 || i == h -1 || j == 0 || j == w -1){
					cout << "#";
				}
				else cout << ".";
			}
			cout << endl;
		}
		cout << endl;
	}
	return 0;
}

Measured memory_bytes: 1152
from collections import defaultdict
from heapq import heapify, heappop
import heapq
n,m,s,t =list(map(int,input().split()))

MAX_VAL = 10**20
uvab =  [list(map(int,input().split())) for _ in range(m)]
jpy_cost = defaultdict(dict)
snuke_cost = defaultdict(dict)


for u,v,a,b in uvab:
    u=u-1
    v=v-1
    jpy_cost[u][v] = a
    jpy_cost[v][u] =a
    snuke_cost[u][v]=b
    snuke_cost[v][u]=b


# Dijktra's shortest path algorithm. Prints the path from source to target.


def dijkstra(adj, source):
    INF = MAX_VAL
    dist = [INF for x in range(n)]
    dist[source] = 0
    PQ = []
    heapq.heappush(PQ, [dist[source], source])

    while (PQ):
        u_dist,u_id = heapq.heappop(PQ)  # u is a tuple [u_dist, u_id]
        if u_dist == dist[u_id]:
            for v in adj[u_id]:
                w_uv = adj[u_id][v]
                if dist[u_id] + w_uv < dist[v]:
                    dist[v] = dist[u_id] + w_uv
                    heapq.heappush(PQ, [dist[v], v])
    return dist


jpy_dijk =  dijkstra(jpy_cost,s-1)
snuke_dijk = dijkstra(snuke_cost,t-1)
#
# print(s,t)
# print(jpy_dijk)
# print(snuke_dijk)
# print([jpy_dijk[i]+snuke_dijk[i] for i in range(n)])

#ord n
res = []
min_val = MAX_VAL
for i in reversed(range(n)):
    #都市  i で両替
    val = jpy_dijk[i]+ snuke_dijk[i]
    assert val < MAX_VAL
    min_val=min(min_val,val)
    res.append(min_val)
#ord n
for x in reversed(res):
    print(10**15-  x)


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

int main(){

  int n, maxv=-1000000000, minv;

  cin>>n;
  for(int i=0;i<n;i++){
    int x;
    cin>>x;
    if(!i) minv=x;
    else{
      maxv=max(maxv, x-minv);
      minv=min(minv, x);
    }
  }

  cout<<maxv<<endl;

  return 0;
}

Measured memory_bytes: 3104
let content = '';
process.stdin.resume();
process.stdin.setEncoding('utf8');
process.stdin.on('data', buf => {
  content += buf;
});
process.stdin.on('end', () => {
  const [matMeta, ...lines] = content.trim().split('\n');
  const [rowSize, colSize] = matMeta.split(' ').map(n => parseInt(n, 10));
  const matA = lines
    .slice(0, rowSize)
    .map(line => line.split(' ').map(n => parseInt(n, 10)));
  const matB = lines
    .slice(rowSize)
    .map(line => line.split(' ').map(n => parseInt(n, 10)));

  const result = multiply(matA, matB);
  console.log(result.join('\n'));
});

const multiply = (matA, matB) => {
  matB = matB.map(([n]) => n);
  return matA.map(row => row.reduce((prev, cur, i) => prev + cur * matB[i], 0));
};


Measured memory_bytes: 17596
#include <bits/stdc++.h>
using namespace std;
template<class T> void ckmin(T &a, T b) { a = min(a, b); }
template<class T> void ckmax(T &a, T b) { a = max(a, b); }
#define pb push_back
#define mp make_pair
#define Red ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define F first
#define S second
#define sz(x) (int)x.size()
#define all(x) (x).begin(), (x).end()
#define rep(i, n) for(ll i = 0; i < n; ++i)
#define repr(i,n) for(int i = n - 1; i >= 0; --i)
#define Rep(i, a, n) for(int i = (a); i <=(n); ++i)
#define repst(i, n) for(auto it = n.begin(); it != n.end(); ++it)
#define Repr(i, a, n) for(int i = (n); i >= (a); --i)
typedef long long ll;

const int inf = int(1e9);
const int mod = inf + 7;
const int N = 5e5 + 555;
void solve()
{
	int n;
	cin >> n;
	int p[n];
	int cnt = 0;
	rep(i, n) cin >> p[i];
	for(int i = 1; i < n - 1; ++i){
		if(p[i] > p[i - 1] && p[i] < p[i + 1]) cnt++;
		if(p[i] > p[i + 1] && p[i] < p[i - 1]) cnt++;
	}
	cout << cnt;
}
int main()
{
	Red;
	solve();
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define ll long long
#define P pair<int,int>
#define fi first
#define se second
#define rep(i,n) for(int i=0;i<n;i++)
#define all(v) v.begin(),v.end()
#define pb push_back
template<class T>void chmax(T &a,T b){if(a<b)a=b;}
template<class T>void chmin(T &a,T b){if(a>b)a=b;}
constexpr int INF=1000000000000000000;
constexpr int mod=1000000007;
int dx[]={0,1,0,-1},dy[]={1,0,-1,0};
int kaijo[2000010];
bool prime(int a){
    if(a==1)return false;
    for(int i=2;i*i<=a;i++){
        if(a%i==0)return false;
    }
    return true;
}
void init_fact(){
    kaijo[0]=1;
    for(int i=1;i<=2000001;i++){
        kaijo[i]=kaijo[i-1]*i;
        kaijo[i]%=mod;
    }
}
int modpow(int a,int b){
    if(b==0)return 1;
    if(b%2)return modpow(a,b-1)*a%mod;
    int memo=modpow(a,b/2);
    return memo*memo%mod;
}
int comb(int a,int b){
    if(!kaijo[0])init_fact();
    return kaijo[a]*modpow(kaijo[a-b],mod-2)%mod*modpow(kaijo[b],mod-2)%mod;
}
int inv(int x){return modpow(x,mod-2);}
bool kosa(double ax,double ay,double bx,double by,double cx,double cy,double dx,double dy){
    double ta=(cx-dx)*(ay-cy)+(cy-dy)*(cx-ax);
    double tb=(cx-dx)*(by-cy)+(cy-dy)*(cx-bx);
    double tc=(ax-bx)*(cy-ay)+(ay-by)*(ax-cx);
    double td=(ax-bx)*(dy-ay)+(ay-by)*(ax-dx);
    return tc*td<0&&ta*tb<0;
}
int b,w;
int p[200010],q[200010];
signed main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    init_fact();
    cin>>b>>w;
    int half=inv(2);
    rep(i,b+w){
        if(i<b)p[i]=0;
        else{
            p[i]=p[i-1]+comb(i-1,b-1)*modpow(half,i)%mod;
            p[i]%=mod;
        }
        if(i<w)q[i]=0;
        else{
            q[i]=q[i-1]+comb(i-1,w-1)*modpow(half,i)%mod;
            q[i]%=mod;
        }
    }
    rep(i,b+w){
        cout<<(1-p[i]+q[i]+mod)%mod*half%mod<<endl;
    }
    return 0;
}


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

using namespace std;
typedef long long ll;

#define REP(i,n) for(int i=0; i<int(n); i++)
#define FOR(i,m,n) for(int i=int(m); i<int(n); i++)
#define ALL(obj) (obj).begin(),(obj).end()
#define VI vector<int>
#define VP vector<pair<int,int>>
#define VPP vector<pair<int,pair<int,int>>>
#define VLL vector<long long>
#define VVI vector<vector<int>>
#define VVLL vector<vector<long long>>
#define VC vector<char>
#define VS vector<string>
#define VVC vector<vector<char>>
#define VB vector<bool>
#define VVB vector<vector<bool>>
#define fore(i,a) for(auto &i:a)
typedef pair <int, int> P;
template<typename T> using min_priority_queue = priority_queue<T, vector<T>, greater<T>>;
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; }

const int  INF = 1 << 30;
const ll INFL = 1LL << 60;
const ll mod = 1e9 + 7;


vector<ll> divisor(ll n) {
	vector<ll> ret;
	for (ll i = 1; i * i <= n; i++) {
		if (n % i == 0) {
			if (i != 1)ret.push_back(i);
			if (i * i != n) ret.push_back(n / i);
		}
	}
	sort(begin(ret), end(ret));
	return (ret);
}


int main() {

	ll n;
	cin >> n;

	ll m = n;

	ll ans = 0;



	for (ll i = 2; i*i <= n; i++) {
		if (m%i != 0)continue;

		int cnt = 0;
		while (m%i == 0) {
			m /= i;
			cnt++;
		}

		int a = 0;
		while (a*(a + 1) / 2 <= cnt)a++;
		ans += a - 1;
	}
	if (m != 1)ans++;


	cout << ans << endl;



}


Measured memory_bytes: 3632
import sys

if __name__ == '__main__':
    N = int(input())
    T, A = map(int, input().split())
    H_list = list(map(int, input().split()))


    min_diff = sys.maxsize
    avg_T_list = list(map(lambda x: T - x * 0.006, H_list))

    answer = 0
    for i in range(len(avg_T_list)):
        if min_diff > abs(avg_T_list[i]-A):
            min_diff = abs(avg_T_list[i]-A)
            answer = i + 1
    print(answer)

Measured memory_bytes: 3064
#include <cstdio>
#include <iostream>
#include <sstream>
#include <fstream>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <string>
#include <vector>
#include <list>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <bitset>
#include <numeric>
#include <climits>
#include <cfloat>
#include <functional>
using namespace std;

int n;
vector<int> goal;

int solve(vector<int> x, vector<int> cnt)
{
    if(x == goal && *max_element(cnt.begin(), cnt.end()) == 0)
        return 0;

    int ret = INT_MAX / 4;
    for(int i=1; i<(1<<(n-1)); ++i){
        bitset<7> bs(i);
        bool ng = false;
        for(int j=0; j<n-2; ++j){
            if(bs[j] && bs[j+1])
                ng = true;
        }
        for(int j=0; j<n-1; ++j){
            if(bs[j] && cnt[j] == 0)
                ng = true;
        }
        if(ng)
            continue;

        vector<int> y = x;
        vector<int> cnt2 = cnt;
        for(int j=0; j<n-1; ++j){
            if(bs[j]){
                swap(y[j], y[j+1]);
                -- cnt2[j];
            }
        }
        ret = min(ret, solve(y, cnt2) + 1);
    }

    return ret;
}

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

    vector<int> init(n);
    goal.resize(n);
    for(int i=0; i<n; ++i)
        init[i] = goal[i] = i;

    vector<int> cnt(n-1, 0);
    for(int i=0; i<m; ++i){
        int a;
        cin >> a;
        swap(goal[a-1], goal[a]);
        ++ cnt[a-1];
    }

    cout << solve(init, cnt) << endl;
    return 0;
}

Measured memory_bytes: 1220
N = int(input())
edge = [{} for _ in range(N + 1)]
dist = [-1] * (N + 1)
for _ in range(N - 1):
    a, b, c = map(int, input().split())
    edge[a][b] = c
    edge[b][a] = c

Q, K = map(int, input().split())
dist[K] = 0
dfs_stack = [(K, 0)]
while dfs_stack:
    s, s_dist = dfs_stack.pop()
    for t, t_dist in edge[s].items():
        if dist[t] == -1:
            dist[t] = s_dist + t_dist
            dfs_stack.append((t, dist[t]))

for _ in range(Q):
    x, y = map(int, input().split())
    print(dist[x] + dist[y])

Measured memory_bytes: 58208
#include<iostream>
using namespace std;
int a[10005];
int main()
{
    int n;
    cin>>n;
    a[0]=a[1]=1;
    for(int i=2;i<=n;i++)
        {
            a[i]=a[i-1]+a[i-2];
        }
    cout<<a[n]<<endl;
    return 0;
}



Measured memory_bytes: 3096
#include<iostream>

using namespace std;

#define REP(i, n) for(int i=0; i<n; i++)

int main(){
    int n;
    cin >> n;
    int a[100000];
    bool gone[100000];
    REP(i, n){
        cin >> a[i];
        a[i] -= 1;
        gone[i] = false;
    }

    int l = 0;
    int output = -1;
    int i = 1;
    while(1){
        gone[l] = true;
        if(a[l] == 1){
            output = i;
            break;
        }

        l = a[l];
        if(gone[l]){
            break;
        }
        i += 1;
    }

    cout << output << endl;
}


Measured memory_bytes: 768
#include <iostream>
#include <algorithm>
#include <vector>
#define BEGIN std::ios_base::sync_with_stdio(0);std::cin.tie(0);
#define END return EXIT_SUCCESS;

inline void solve() {
  int N, K;
  std::cin >> N >> K;
  K--;
  std::vector<int> h(N);
  int t;
  for (int i = 0; i < N; i++) {
    std::cin >> t;
    h[i] = t;
  }
  std::sort(h.begin(), h.end());
  N -= K;
  int a = 1000000000;
  for (int i = 0; i < N; i++) {
    a = std::min(a, h[i+K] - h[i]);
  }
  std::cout << a << std::endl;
}

int main(int argc,char**argv) {
  BEGIN
  solve();
  END
}


Measured memory_bytes: 640
#include<bits/stdc++.h>
using namespace std;
using Int = long long;
template<typename T1,typename T2> inline void chmin(T1 &a,T2 b){if(a>b) a=b;}
template<typename T1,typename T2> inline void chmax(T1 &a,T2 b){if(a<b) a=b;}


//INSERT ABOVE HERE
signed main(){
  int d,e;
  while(cin>>d>>e,d){
    using D = double;
    D res=1e9;
    for(int x=0;x<=d;x++){
      int y=d-x;
      chmin(res,abs(hypot(D(x),D(y))-D(e)));
    }
    cout<<fixed<<setprecision(12)<<res<<endl;
  }
  return 0;
}



Measured memory_bytes: 3260
public class Main{
  static int infi = 1000000001;
  public void run(java.io.InputStream in, java.io.PrintStream out){
    java.util.Scanner sc = new java.util.Scanner(in);
/*answer*/
    int n;
    int[] a;
    int i, count;

    n = sc.nextInt();
    a = new int[n];
    for(i = 0;i < n;i++)a[i] = sc.nextInt();

    count = mergesort(a, 0, n);
    for(i = 0;i < n - 1;i++)System.out.print(a[i] + " ");
    System.out.println(a[i]);
    System.out.println(count);

    sc.close();
  }
  public static void main(String[] args){
    (new Main()).run(System.in, System.out);
  }

  private static int mergesort(int[] a, int l, int r){
    int m, c;
    if(l + 1 >= r)return 0;
    else{
      m = (l + r) / 2;
      c = mergesort(a, l, m);
      c += mergesort(a, m, r);
      c += merge(a, l, m, r);
      return c;
    }
  }

  private static int merge(int[] a, int l, int m, int r){
    int nl, nr, count;
    int i, j, k;
    int[] al, ar;

    nl = m - l;
    nr = r - m;
    al = new int[nl + 1];
    ar = new int[nr + 1];
    for(i = 0;i < nl;i++)al[i] = a[l + i];
    for(i = 0;i < nr;i++)ar[i] = a[m + i];
    al[nl] = infi;
    ar[nr] = infi;

    i = 0;j = 0;count = 0;

    for(k = l;k < r;k++){
      if(al[i] <= ar[j]){
        a[k] = al[i++];
        count++;
      }else{
        a[k] = ar[j++];
        count++;
      }
    }

    return count;

  }
}

Measured memory_bytes: 165788
#include <stdio.h>

int main(void)
{
    int a[5], t;
    int i, j;

    scanf("%d %d %d %d %d", &a[0], &a[1], &a[2], &a[3], &a[4]);
    for (i = 0; i < 4; i++) {
        for (j = 4 - 1; j >= i; j--) {
            if (a[j] < a[j + 1]) {
                t = a[j];
                a[j] = a[j + 1];
                a[j + 1] = t;
            }
        }
    }

    printf("%d %d %d %d %d\n", a[0], a[1], a[2], a[3], a[4]);

    return 0;
}

Measured memory_bytes: 596
#include <iostream>
#include <cstdlib>
#include <vector>
#include <algorithm>
#include <cstring>
using namespace std;

int main(int argc, char *argv[])
{
        int i, j;
        int n, m;
        int k;
        int tmp, ret;

        cin >> n >> m;

        char lis[m];
        char temp[m];

        for (i = 0; i < m; i++) {
                lis[i] = 'a';
                temp[i] = 'b';
        }

        for (i = 0; i < n; i++) {
                cin >> k;
                for (j = 0; j < k; j++) {
                    cin >> tmp;
                        temp[tmp - 1] = 'a';
                }

                for (j = 0; j < m; j++) {
                        if (lis[j] == 'a' && temp[j] == 'a') {
                                lis[j] = 'a';
                        } else {
                                lis[j] = 'b';
                        }
                        temp[j] = 'b';
                }
        }

        ret = 0;
        for (i = 0; i < m; i++) {
                if (lis[i] == 'a')
                        ret++;
        }

        cout << ret << endl;

        return 0;
}


Measured memory_bytes: 256
import java.util.ArrayDeque;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner stdIn = new Scanner(System.in);
		int n = stdIn.nextInt();
		int m = stdIn.nextInt();
		int[] p = new int[n];
		int[] b = new int[m];
		int[] t = new int[n];
		for(int i = 0; i < n; i++) {
			p[i] = stdIn.nextInt();
		}
		for(int i = 0; i < m; i++) {
			b[i] = stdIn.nextInt();
		}
		for(int i = 0; i < m; i++) {
			for(int j = 0; j < n; j++) {
				if(p[j] <= b[i]) {
					t[j]++;
					break;
				}
			}
		}
		int ans = 0;
		int max = 0;
		for(int i = 0; i < n; i++) {
			if(t[i] > max) {
				max = t[i];
				ans = i;
			}
		}
		System.out.println(ans+1);
	}

}

Measured memory_bytes: 25176
#include <bits/stdc++.h>
#define fi first
#define se second
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
#define srep(i,s,t) for (int i = s; i < t; ++i)
#define rng(a) a.begin(),a.end()
#define rrng(a) a.rbegin(),a.rend()
#define maxs(x,y) (x = max(x,y))
#define mins(x,y) (x = min(x,y))
#define isin(x,l,r) ((l) <= (x) && (x) < (r))
#define pb push_back
#define eb emplace_back
#define sz(x) (int)(x).size()
#define pcnt __builtin_popcountll
#define uni(x) x.erase(unique(rng(x)),x.end())
#define snuke srand((unsigned)clock()+(unsigned)time(NULL));
#define show(x) cout<<#x<<" = "<<x<<endl;
#define PQ(T) priority_queue<T,v(T),greater<T> >
#define bn(x) ((1<<x)-1)
#define dup(x,y) (((x)+(y)-1)/(y))
#define newline puts("")
#define v(T) vector<T>
#define vv(T) v(v(T))
using namespace std;
typedef long long int ll;
typedef unsigned uint;
typedef unsigned long long ull;
typedef pair<int,int> P;
typedef tuple<int,int,int> T;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<P> vp;
typedef vector<T> vt;
inline int getInt() { int x; scanf("%d",&x); return x;}
template<typename T>inline istream& operator>>(istream&i,v(T)&v)
{rep(j,sz(v))i>>v[j];return i;}
template<typename T>string join(const v(T)&v)
{stringstream s;rep(i,sz(v))s<<' '<<v[i];return s.str().substr(1);}
template<typename T>inline ostream& operator<<(ostream&o,const v(T)&v)
{if(sz(v))o<<join(v);return o;}
template<typename T1,typename T2>inline istream& operator>>(istream&i,pair<T1,T2>&v)
{return i>>v.fi>>v.se;}
template<typename T1,typename T2>inline ostream& operator<<(ostream&o,const pair<T1,T2>&v)
{return o<<v.fi<<","<<v.se;}
template<typename T>inline ll suma(const v(T)& a) { ll res(0); for (auto&& x : a) res += x; return res;}
const double eps = 1e-10;
const ll LINF = 1001002003004005006ll;
const int INF = 1001001001;
#define dame { puts("-1"); return 0;}
#define yn {puts("Yes");}else{puts("No");}
const int MX = 200005;
int a,b,c,d;

map<ll,ll> mem;
ll f(ll x) {
    if (!x) return 0;
    if (mem.count(x)) return mem[x];
    ll res = LINF;
    if (LINF/d > x) res = x*d;
    auto f2 = [&](ll y) {
        if (y >= x) return LINF;
        return f(y);
    };
    {
        ll l= x/2*2,r = l+2;
        mins(res,f2(l/2)+a+(x-l)*d);
        mins(res,f2(r/2)+a+(r-x)*d);
    }
    {
    ll l = x/3*3, r = l+3;
    mins(res, f2(l/3)+b+(x-l)*d);
    mins(res, f2(r/3)+b+(r-x)*d);
  }
    {
        ll l= x/5*5,r = l+5;
        mins(res,f2(l/5)+c+(x-l)*d);
        mins(res,f2(r/5)+c+(r-x)*d);
    }
    return mem[x] = res;
}

void solve() {
    ll n;
    cin >> n;
    cin >> a >> b >> c >> d;
    mem = map<ll,ll>();
    cout << f(n) << endl;
}
int main(void){
    // Your code here!
    int ts;
    cin >> ts;
    rep(ti,ts) solve();
    return 0;
}


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

int n;

int main() {
    for(int i=0; i<10000; i++) {
        cin >> n;
        if(n == 0) return 0;
        cout << "Case " << (i+1) << ": " << n << endl;
    }
}



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

using namespace std;

#define ll long long

#define DEBUG (0)

ll getgcd(ll a, ll b);

int main()
{
  ll N = 0;
  cin >> N;

  vector<ll> A(N+1,0);
  for(ll i = 2; i < N+1; i++){
    cin >> A[i];
  }

  //部下の数
  vector<ll> B(N+1,0);

  for(ll i = 2; i < N+1; i++){
    B[A[i]]++;
  }

  for(ll i = 1; i < N+1; i++){
    cout << B[i] << "\n";
  }

#if DEBUG
  for(ll i = 1; i < N+1; i++){
    cout << i << ": A: " << A[i] << ", B:" << B[i] << endl;
  }
#endif
}


Measured memory_bytes: 6428
#!usr/bin/env python3
from collections import defaultdict
from collections import deque
from heapq import heappush, heappop
import sys
import math
import bisect
import random
import itertools
sys.setrecursionlimit(10**5)
stdin = sys.stdin
def LI(): return list(map(int, stdin.readline().split()))
def LF(): return list(map(float, stdin.readline().split()))
def LI_(): return list(map(lambda x: int(x)-1, stdin.readline().split()))
def II(): return int(stdin.readline())
def IF(): return float(stdin.readline())
def LS(): return list(map(list, stdin.readline().split()))
def S(): return list(stdin.readline().rstrip())
def IR(n): return [II() for _ in range(n)]
def LIR(n): return [LI() for _ in range(n)]
def FR(n): return [IF() for _ in range(n)]
def LFR(n): return [LI() for _ in range(n)]
def LIR_(n): return [LI_() for _ in range(n)]
def SR(n): return [S() for _ in range(n)]
def LSR(n): return [LS() for _ in range(n)]
mod = 1000000007

#A
def A():
    a, b, c = LI()
    if a + b >= c:
        print("Yes")
    else:
        print("No")
    return

#B
def B():
    n = II()
    s = SR(n)
    m = II()
    t = SR(m)
    ans = 0
    for si in s:
        ans = max(ans, s.count(si) - t.count(si))
    print(ans)
    return

#C
def C():
    n = II()
    ab = LIR(n)
    cd = LIR(n)
    ab.sort()
    cd.sort()
    check = [0 for i in range(n)]
    ans = 0
    for _, c in enumerate(cd):
        d = c[1]
        c = c[0]
        maxy = -1
        x = -1
        for k, a in enumerate(ab):
            b = a[1]
            a = a[0]
            if maxy < b and c > a and check[k] == 0 and d > b:
                maxy = b
                x = k
        if x != -1:
            ans += 1
            check[x] += 1
    print(ans)


    return

#D
def D():
    N = II()
    a = LI()
    b = LI()
    ans = 0
    for i in range(29):
        t = 1 << i
        a2 = [A & ((t << 1) - 1) for A in a]
        b2 = [B & ((t << 1) - 1) for B in b]
        a2.sort()
        b2.sort()
        ansb = 0
        r1 = r2 = r3 = 0
        for A in reversed(a2):
            while r1 < N and A + b2[r1] < t:
                r1 += 1
            while r2 < N and A + b2[r2] < 2*t:
                r2 += 1
            while r3 < N and A + b2[r3] < 3*t:
                r3 += 1
            ansb += (r2 - r1) + (N - r3)
        ans += ((ansb & 1) << i)
    print(ans)
    return

#Solve
if __name__ == '__main__':
    D()


Measured memory_bytes: 140408
string_values = list(input())
size = len(string_values)
half_size = int((size - 1) / 2)
half_last_size = int((size + 3) / 2)

count = 0
is_true = True
for string_value in string_values:
    if string_value != string_values[size - count - 1]:
        is_true = False
    if count > half_size:
        break
    count += 1

count = 0
for string_value in string_values:
    if string_value != string_values[half_size - count - 1]:
        is_true = False
    if count + 1 == half_size:
        break
    count += 1

count = 0
check_count = 0
for string_value in string_values:
    if count + 1 < half_last_size:
        count += 1
        continue
    if string_value != string_values[size - check_count - 1]:
        is_true = False
    check_count += 1
    count += 1


answer = "No"
if is_true:
    answer = "Yes"
print(answer)


Measured memory_bytes: 3064
#include<bits/stdc++.h>
using namespace std;
int main(){
    #ifndef ONLINE_JUDGE
        freopen("input.txt","r",stdin);
        freopen("output.txt","w",stdout);
   	#endif
    string s;
    cin>>s;
    int sum=0;
    for(int i=0;i<s.size();++i) sum+=s[i]-'0';
    int x=stoi(s);
	cout<<((x%sum==0)?"Yes":"No");
   return 0;
}

Measured memory_bytes: 3620
#include <bits/stdc++.h>
using namespace std;
#define all(x) x.begin, x.end
#define mkp make_pair
#define trav(x, i) for(auto& i : x)
typedef long long ll;
typedef unsigned int uint;

int main(){
  string a, b;
  int n;
  cin >> n >> a >> b;
  string ans;
  for(int i = 0;i < n; i++){
    ans += a[i], ans += b[i];
  }
  cout << ans; 
  return 0;
}


Measured memory_bytes: 3604
import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        long[] a = new long[n];
        for (int i=0; i<n; i++) {
            a[i] = sc.nextInt();
        }

        long[][] dp = new long[n][n];
        for (int i=0; i<n; i++) {
            dp[i][i] = a[i];
        }

        for (int i = n - 2; i > -1; i--) {
            for (int j = i + 1; j < n; j++) {
                dp[i][j] = Math.max(a[i] - dp[i + 1][j], a[j] - dp[i][j - 1]);
            }
        }
        System.out.println(dp[0][n - 1]);
    }
}

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

int64_t n,m,C[3],Col[100005];
vector<int> g[100005];

void DFS(int u,int col)
{
    Col[u]=col;
    C[col]++;
    for(int i=0;i<g[u].size();i++)
        if(Col[g[u][i]]==0)
            DFS(g[u][i],3-col);
        else
        if(Col[g[u][i]]==Col[u])
        {
            cout<<n*(n-1)/2-m;
            exit(0);
        }
}

int main()
{
    cin>>n>>m;
    int u,v;
    for(int i=1;i<=m;i++)
    {
        cin>>u>>v;
        g[u].push_back(v);
        g[v].push_back(u);
    }
    DFS(1,1);
    cout<<C[1]*C[2]-m;
}


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

typedef struct d{
  private:
    static const int max = 1000001;/*量に応じて変更*/
    int head,tail;
    int a[max];
  public:
    void initialize(){
      head=0;tail=0;
    }
    bool isEmpty(){
      return head==tail;
    }
    void print(){
      if (head<tail){
        for (int i=tail-1;i>=head;i--){
          if (i!=tail-1)std::cout  << ' ';
          std::cout << a[i] ;
        }
        std::cout << '\n';
      }else {
        for (int i=tail+max-1;i>=head;i--){
          if (i!=tail+max-1)std::cout  << ' ';
          std::cout << a[i%max] ;
      }
      std::cout << '\n';
    }
  }
    void insert(int x){
      if (tail==max)tail=0;
      a[tail]=x;
      tail++;
    }
    void deleteFirst(){
      tail--;
      if (tail==0)tail=max;
    }
    void deleteLast(){
      head++;
      if (head==max)head=0;
    }
    void del(int x){
      if (head<tail){
        for (int i=tail-1;i>=head;i--){
          if (a[i]==x){
            for (int j=i+1;j<tail;j++){
              a[j-1]=a[j];
            }
            tail--;
            break;
          }
        }
      }else {
        for (int i=tail+max-1;i>=head;i--){
          if (a[i%max]==x){
            for (int j=i+1;j<tail+max;j++){
              a[(j-1)%max]=a[j%max];
            }
            tail--;
            if (tail==0)tail=max;
            break;
          }
        }
      }
    }

}dlList;

int main(){
  int n,x;
  dlList l;
  l.initialize();
  std::string req;
  std::cin >> n;
  for (int i=0;i<n;i++){
    std::cin >> req;
    if (req=="insert"){
      std::cin >> x;
      l.insert(x);
    }else if (req=="delete"){
      std::cin >> x;
      l.del(x);
    }else if (req=="deleteFirst"){
      l.deleteFirst();
    }else if (req=="deleteLast"){
      l.deleteLast();
    }
  }
  l.print();
}



Measured memory_bytes: 7100
#include <iostream>
#include <sstream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <ctime>
#include <cstring>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <map>
#include <set>
#include <bitset>
#include <numeric>
#include <utility>
#include <iomanip>
#include <algorithm>
#include <functional>
using namespace std;

typedef long long ll;
typedef vector<int> vint;
typedef vector<long long> vll;
typedef pair<int,int> pint;
typedef pair<long long, long long> pll;

#define MP make_pair
#define PB push_back
#define ALL(s) (s).begin(),(s).end()
#define EACH(i, s) for (__typeof__((s).begin()) i = (s).begin(); i != (s).end(); ++i)
#define COUT(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << 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; }
template<class T1, class T2> ostream& operator << (ostream &s, pair<T1,T2> P) 
{ return s << '<' << P.first << ", " << P.second << '>'; }
template<class T> ostream& operator << (ostream &s, vector<T> P) 
{ for (int i = 0; i < P.size(); ++i) { if (i > 0) { s << " "; } s << P[i]; } return s << endl; }
template<class T1, class T2> ostream& operator << (ostream &s, map<T1,T2> P) 
{ EACH(it, P) { s << "<" << it->first << "->" << it->second << "> "; } return s << endl; }



int n, a[4], ax[4], ay[4];

int main() {
    while (cin >> n >> a[0] >> a[1] >> a[2] >> a[3]) {
        --a[0]; --a[1]; --a[2]; --a[3];
        int res = 1<<29;
        for (int w = 1; w <= n; ++w) {
            for (int i = 0; i < 4; ++i) {
                ax[i] = a[i] / w;
                ay[i] = a[i] % w;
            }
            int tmp = abs(ax[0]-ax[1]) + abs(ay[0]-ay[1]) + abs(ax[2]-ax[3]) + abs(ay[2]-ay[3]);
            chmin(res, tmp);
        }
        cout << res << endl;
    }
    
    return 0;
}


Measured memory_bytes: 1164
#include<bits/stdc++.h>
using namespace std;
string s, t;
long long n, m, l;
int main(void)
{
	cin>>n>>m>>s>>t, l = n*m/__gcd(n, m);
	for(int i=0;i<n;i++)
		if(i*m%n == 0&&s[i]!=t[i*m/n]){
				cout<<-1;
				return 0;
			}
	cout<<l;
}


Measured memory_bytes: 512
/* be name khoda */

// #define stream_enable
#define long_enable
#include <iostream>
#include <algorithm>
#include <cstring>
#include <numeric>
#include <iomanip>
#include <sstream>
#include <vector>
#include <queue>
#include <set>
#include <map>
using namespace std;

#ifdef stream_enable
#define cin sss
#endif
#ifdef long_enable
typedef long long int ll;
#else
typedef int ll;
#endif

typedef pair<ll, ll> pii;
typedef pair<pii, ll> ppi;
typedef pair<ll, pii> pip;
typedef vector<ll> vi;
typedef vector<pii> vpii;

const ll MOD = 1000000007;
const long long BIG = 1446803456761533460;
const int Big = 336860180;

#define F first
#define S second
#define pb push_back
#define eb emplace_back
#define all(x) (x).begin(), (x).end()

#define debug(x) cout << #x << " -> " << (x) << endl;
#define debug2(x, y) cout << #x << ' ' << #y << " -> " << (x) << ' ' << (y) << endl;
#define debug3(x, y, z) cout << #x << ' ' << #y << ' ' << #z << " -> " << (x) << ' ' << (y) << ' ' << (z) << endl;
#define debug4(x, y, z, t) cout << #x << ' ' << #y << ' ' << #z << ' ' << #t << " -> " << (x) << ' ' << (y) << ' ' << (z) << ' ' << (t) << endl;
#define debugp(x) cout << #x << " -> " << "(" << (x).F << ", " << (x).S << ")" << endl;
#define debuga(x, n) cout << #x << " -> "; fori (i1_da, n) { cout << (x)[i1_da] << ' '; } cout << endl
#define debugap(x, n) cout << #x << " ->\n"; fori (i1_dap, n) { cout << "(" << (x)[i1_dap].F << ", " << (x)[i1_dap].S << ")\n"; } cout << endl
#define debugaa(x, n, m) cout << #x << " ->\n"; fori (i1_daa, n) { fori (i2_daa, m) { cout << (x)[i1_daa][i2_daa] << ' '; } cout << '\n'; } cout << endl
#define debugav(x, n) cout << #x << " ->\n"; fori (i1_dav, n) { fori (i2_dav, (x)[i1_dav].size()) { cout << (x)[i1_dav][i2_dav] << ' '; } cout << '\n'; } cout << endl
#define debugia(x, n) cout << #x << " ->\n"; fori (i1_dia, n) { cout << i1_dia << " : " << (x)[i1_dia] << '\n'; } cout << endl

#define forifrom(i, s, n) for(ll i = (s); i < (n); ++i)
#define forirto(i, n, e) for(ll i = (n) - 1; i >= (e); --i)
#define fori(i, n) forifrom (i, 0, n)
#define forir(i, n) forirto (i, n, 0)

#define smin(a, b) a = min(a, (b))
#define smax(a, b) a = max(a, (b))

#define Add(a, b) a = (a + (b)) % MOD
#define Mul(a, b) a = (a * (b)) % MOD

stringstream sss;

// -----------------------------------------------------------------------

const ll maxn = 100010;

ll n, b, ar[maxn];

void MAIN() {

    ll s = 0;
    cin >> b >> n;
    fori (i, n) {
        ll x; cin >> x;
        s += x;
    }
    cout << ((s < b) ? "No" : "Yes") << '\n';

}

// -----------------------------------------------------------------------

int main() {
    ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);
    cout << fixed << setprecision(10);
    sss << R"(

    )";
    MAIN();
    return 0;
}


Measured memory_bytes: 256
// AtCoder Beginner Contest 115 - Problem A: Christmas Eve Eve Eve (https://atcoder.jp/contests/abc115/tasks/abc115_a)
#include <bits/stdc++.h>

using namespace std;

using ll = long long;
using ii = pair<ll, ll>;

#define REP(i, a, b) for (int (i) = (a); (i) <= (b); (i)++)
#define REPN(i, N) for (int (i) = 0; (i) < N; (i)++)
#define DEC(i, b, a) for (int (i) = (b); (i) >= (a); (i)--)
#define DECN(i, N) for (int (i) = N - 1; (i) >= 0; (i)--)

#define LOG(var, sep) (cerr << #var << " = " << (var) << (sep))
#define LOGM(msg) (cerr << (msg))
#define LOGV(vec, sep) { cerr << #vec << " ="; for (const auto& v : (vec)) cerr << " " << v; cerr << (sep); }
#define LOGA(arr, N, sep) { cerr << #arr << " ="; for (int i = 0; i < N; ++i) cerr << " " << (arr)[i]; cerr << (sep); }
#define LOGA2(arr, N, M, sep) { cerr << #arr << " =\n"; for (int i = 0; i < N; ++i) { for (int j = 0; j < M; ++j) cerr << (arr)[i][j] << " "; cerr << endl; } cerr << (sep); }

ostream& operator<<(ostream& os, const ii& p)
{
    os << "(" << p.first << ", " << p.second << ")";
    return os;
}

const int MAX { 2000010 };
const int oo { 2000000010 };
const int MOD { 1000000007 };

void solve(int D)
{
    cout << "Christmas";

    REP(i, D, 24)
        cout << " Eve";

    cout << '\n';
}

int main()
{
    ios::sync_with_stdio(false);

    int D;
    cin >> D;

    solve(D);

    return 0;
}


Measured memory_bytes: 256
/*
これを入れて実行
g++ code.cpp
./a.out
*/

#include <iostream>
#include <vector>
#include <string>
#include <queue>
#include <deque>
#include <algorithm>
#include <utility>
#include <set>
#include <map>
#include <cmath>
#include <math.h>
#include <tuple>
#include <iomanip>
#include <stack>

using namespace std;
typedef long long ll;
typedef long double ld;

int dy4[4] = { -1, 0, +1, 0 };
int dx4[4] = { 0, +1, 0, -1 };
int dy8[8] = { -1, -1, 0, 1, 1, 1, 0, -1 };
int dx8[8] = { 0, 1, 1, 1, 0, -1, -1, -1 };

const long long INF = 1LL << 60;
const ll MOD = 1e9 + 7;

bool greaterSecond(const pair<int, int>& f, const pair<int, int>& s){
	return f.second > s.second;
}

ll gcd(ll a, ll b){
	if (b == 0)return a;
	return gcd(b, a % b);
}

ll lcm(ll a, ll b){
	return a / gcd(a, b) * b;
}

ll nCr(ll n, ll r){
	if (r == 0 || r == n){
		return 1;
	}
	else if (r == 1){
		return n;
	}
	return (nCr(n - 1, r) + nCr(n - 1, r - 1));
}

ll nPr(ll n, ll r){
	r = n - r;
	ll ret = 1;
	for (ll i = n; i >= r + 1; i--) ret *= i;
	return ret;
}

//-----------------------ここから-----------

ll factorial[201000];
ll invfactorial[201000];

ll extGCD(ll a, ll b, ll &x, ll &y){
	if (b == 0){
		x = 1;
		y = 0;
		return a;
	}

	ll d = extGCD(b, a % b, y, x);
	y -= a / b * x;
	return d;
}


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

	vector<ll> a(n);
	for (int i = 0; i < n; i++) cin >> a[i];

	factorial[0] = 1;

	for (int i = 1; i < 201000; i++){
		factorial[i] = (factorial[i - 1] * i) % MOD;
	}



	for (int i = 0; i < 201000; i++){
		ll x, y;
		ll g = extGCD(factorial[i], MOD, x, y);
		while (x < 0) x += MOD;
		x %= MOD;
		invfactorial[i] = x;
	}

	ll tp = 0;
	ll ans = 0;
	for (int i = 1; i < n; i++){
		ll x, y;
		ll g = extGCD(i, MOD, x, y);
		while (x < 0) x += MOD;
		x %= MOD;
		tp += 1 * x;
		tp %= MOD;
		ans += tp * (a[i] - a[i - 1]);
		ans %= MOD;
	}

	cout << ans * factorial[n - 1] % MOD << endl;
}



Measured memory_bytes: 4224
#include <bits/stdc++.h>
#include <vector>
#include <numeric>
#define PI 3.14159265358979323846
#define MAXINF (1e18L)
#define INF (1e9L)
#define EPS (1e-9)
#define MOD (1'000'000'007)
#define REP(i, n) for(int i=0;i<int(n);++i)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define RREP(i, n) for(int i=int(n)-1;i>=0;--i)
#define ALL(v) v.begin(),v.end()
#define FIND(v,x) (binary_search(ALL(v),(x)))
#define SORT(v) sort(ALL(v))
#define RSORT(v) sort(ALL(v));reverse(ALL(v))
#define DEBUG(x) cerr<<#x<<": "<<x<<endl;
#define DEBUG_VEC(v) cerr<<#v<<":";for(int i=0;i<v.size();i++) cerr<<" "<<v[i]; cerr<<endl
#define Yes(n) cout<<((n)?"Yes":"No")<<endl
#define YES(n) cout<<((n)?"YES":"NO")<<endl
#define pb push_back
#define fi first
#define se second
using namespace std;
template<class A>void pr(A a){cout << (a) << endl;}
template<class A,class B>void pr(A a,B b){cout << a << " "  ;pr(b);}
template<class A,class B,class C>void pr(A a,B b,C c){cout << a << " " ;pr(b,c);}
template<class A,class B,class C,class D>void pr(A a,B b,C c,D d){cout << a << " " ;pr(b,c,d);}
typedef long long ll;
typedef pair<int, int> pii;

vector<vector<int>> graph;
vector<int> color;

bool dfs(int c, int p){
    color[p]=c;
    for(int cc : graph[p]){
        if(color[cc]==c) return false;
        if(color[cc]==0) if(!dfs(-c, cc)) return false;
    }    
    return true;
}

int main(void)
{
    ll n,m;
    cin >> n >> m;
    graph.resize(n, vector<int>());
	color.resize(n, 0);
    REP(i, m){
        int a,b;
        cin >> a >> b;
        a--;b--;
        graph[a].pb(b);
        graph[b].pb(a);
    }

    ll ans=0;
    if(dfs(1,0)){
        ll w=0;
        REP(i, n){
            if(color[i]==1) w++;
        }
        ans = w * (n-w) - m; 
    }else{
        ans = n*(n-1)/2 - m;
    }

    pr(ans);
}

Measured memory_bytes: 6528
import math
from functools import reduce

def resolve():
	k = int(input())
	ans = 0
	for i in range(1, k+1):
		for j in range(1, k + 1):
			for k in range(1, k + 1):
				ans += reduce(math.gcd, [i, j, k])
	print(ans)

resolve()

Measured memory_bytes: 74580
#include <bits/stdc++.h>
#include <atcoder/all>
using namespace std;
using namespace atcoder;
#define rep(i, n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define reps(i, n) for(int i=1, i##_len=(n); i<=i##_len; ++i)
#define rrep(i, n) for(int i=((int)(n)-1); i>=0; --i)
#define rreps(i, n) for(int i=((int)(n)); i>0; --i)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define sz(x) ((int)(x).size())
#define pl(s) cout << (s) << "\n";
#define pls(...) {bool space = false; for(auto i : __VA_ARGS__) (cout << (space?" ":"") << i), space = true; cout << "\n";}
#define plexit(s) {cout << (s) << "\n"; exit(0);}
#define yes(s) cout << ((s)?"Yes":"No") << "\n";
#ifdef __LOCAL
#include <dump.hpp>
#define dump(...) DUMPOUT << "  " << string(#__VA_ARGS__) << ": " << "[" << to_string(__LINE__) << ":" << __FUNCTION__ << "]" << endl << "    ", dump_func(__VA_ARGS__)
#else
#define dump(...)
#endif
template<typename T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<typename T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
struct IOInit { IOInit() { cin.tie(nullptr); ios::sync_with_stdio(false); dump("READY"); /*cout << unitbuf;*/} } IO_INIT;
using ll = long long; using ull = unsigned long long; using ld = long double;
template<typename T = int> using V = vector<T>; template<typename T = int> using P = pair<T, T>;
using Vi = V<int>; using Vl = V<ll>; using Vd = V<ld>; using VVi = V<Vi>; using VVl = V<Vl>; using Pi = P<int>; using Pl = P<ll>; using Pd = P<ld>;
constexpr ll MOD = 1000000007; constexpr int INF = (1 << 30) - 1; constexpr ll INFL = 1LL << 60; constexpr ld EPS = 1e-12; constexpr ld PI = 3.141592653589793238462643383279;



signed main(void) {
  int n, k; cin >> n >> k;
  mcf_graph<int, ll> g(2 * n + 2);
  int s = 2 * n, t = 2 * n + 1;

  g.add_edge(s, t, n * k, INFL);

  rep(i,n) {
    g.add_edge(s, i, k, 0);
    g.add_edge(n + i, t, k, 0);
  }

  rep(i,n) rep(j, n) {
    ll a; cin >> a;
    g.add_edge(i, n + j, 1, INFL - a);
  }

  auto result = g.flow(s, t, n * k);
  pl(1LL * n * k * INFL - result.second);

  V<string> grid(n, string(n, '.'));

  auto edges = g.edges();
  for (auto e : edges) {
    if (e.from == s || e.to == t || e.flow == 0) continue;
    grid[e.from][e.to - n] = 'X';
  }

  rep(i,n) pl(grid[i])


  return 0;
}


Measured memory_bytes: 3924