akhauriyash/Code-Regression huggingface dataset:
import sys

class Node:
    __slots__ = ['key', 'left', 'right']
    def __init__(self, key):
        self.key = key
        self.left = self.right = None

root = None

def insert(key):
    global root
    x, y = root, None
    while x is not None: x, y = x.left if key < x.key else x.right, x
    if y is None: root = Node(key)
    elif key < y.key: y.left = Node(key)
    else: y.right = Node(key)

def find(target):
    result = root
    while result and target != result.key:
        result = result.left if target < result.key else result.right
    return result is None

def delete(target):
    def remove_node(p, c, a):
        if p.left == c: p.left = a
        else: p.right = a
    p, c = None, root
    while c.key != target: p, c = c, c.left if target < c.key else c.right
    if c.left is None:
        remove_node(p, c, c.right)
    elif c.right is None:
        remove_node(p, c, c.left)
    elif c.right.left is None:
        c.right.left = c.left
        c.key = c.right.key
        c.right = c.right.right
    else:
        g = c.right
        while g.left.left is not None: g = g.left
        c.key = g.left.key
        g.left = g.left.right

def inorder(node):
    return inorder(node.left) + f' {node.key}' + inorder(node.right) if node else ''
def preorder(node):
    return f' {node.key}' + preorder(node.left) + preorder(node.right) if node else ''

input()
for e in sys.stdin:
    if e[0] == 'i': insert(int(e[7:]))
    elif e[0] == 'd': delete(int(e[7:]))
    elif e[0] == 'f': print(['yes','no'][find(int(e[5:]))])
    else: print(inorder(root)); print(preorder(root))


Measured memory_bytes: 56180
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <cmath>
#include <map>
#include <queue>
#include <iomanip>
#define MOD 1000000007
typedef long long ll;
using namespace std;

vector<int> g[100010];
int dp[100010];

int dfs(int now){
  if(dp[now]>=0) return dp[now];
  if(g[now].size()==0) return 0;

  int cnt=0;
  for(int i=0;i<g[now].size();i++){
    int u=g[now][i];
    if(dp[u]>=0) cnt=max(cnt,dp[u]+1);
    else cnt=max(cnt,dfs(u)+1);
  }

  return dp[now]=cnt;
}

int main(){
  int n,m;
  cin>>n>>m;
  for(int i=0;i<m;i++){
    int x,y;
    cin>>x>>y;
    g[x].push_back(y);
  }

  for(int i=0;i<=n;i++) dp[i]=-1;

  for(int i=1;i<=n;i++){
    if(dp[i]==-1){
      int z=dfs(i);
    }
  }

  int ans=0;
  for(int i=1;i<=n;i++) ans=max(ans,dp[i]);

  cout<<ans<<endl;

  return 0;
}


Measured memory_bytes: 8192
#include<iostream>
#include<stack>
#include<vector>
#include<stdio.h>

using namespace std;

typedef long double ldouble;
string in;

int main(){

  while(getline(cin,in)){
    stack <ldouble> st;
    for(int i = 0; i < in.size(); i++){

      if(i < in.size()-1 && in[i] == '-' && in[i+1] >= '0' && in[i+1] <= '9'){
	  double s = 0;
	  i++;
	  while(1){
	    if(in[i] < '0' || in[i] > '9') break;
	    s *= 10;
	    s += in[i]-'0';
	    i++;
	  }
	  st.push(-1*s);
	}
      if(in[i] >= '0' && in[i] <= '9') {
	vector <char> V;
	while(1){
	  if(in[i] < '0' || in[i] > '9') break;
	  V.push_back(in[i]);
	  i++;
	}
	double kake = 1,sum = 0;
	for(int j = V.size()-1; j >= 0; j--){
	  sum += (V[j]-'0')*kake;
	  kake *= 10;
	}
	st.push(sum);
	//st.push(in[i]-'0');
	//cout << "push " << sum << endl;
      }else if(in[i] == '+' || in[i] == '/' || in[i] == '*' || in[i] == '-'){
	double num[2];
	num[0] = st.top();
	st.pop();
	num[1] = st.top();
	st.pop();
	if(in[i] == '+') st.push(num[1]+num[0]);
	if(in[i] == '-') st.push(num[1]-num[0]);
	if(in[i] == '/') st.push(num[1]/num[0]);
	if(in[i] == '*') st.push(num[1]*num[0]);
      }
    }
    printf("%.6Lf\n",st.top());
    //cout << st.top() << endl;
  }
  return 0;
}

Measured memory_bytes: 0
#include <iostream>
using namespace std;
int main(void){
    // Your code here!
    int n;
    std::cin >> n;
    long long p=1;
    long long m=1000000007;
    for (int i = 1; i <= n; i++) {
        p=p*i%m;
    }
    std::cout << p << std::endl;
    
}

Measured memory_bytes: 256
h, w = map(int, input().split())
a = [''] * h

for i in range(h):
	a[i] = input()

#論理演算子で行列のチェックシートを作っている
#"#"がある行列をチェックしている
row = [False] * h

col = [False] * w
for i in range(h):
	for j in range(w):
		if a[i][j] == '#':
			row[i] = True
			col[j] = True

for i in range(h):
	if row[i]:
		for j in range(w):
			if col[j]:
				print(a[i][j], end = '')
		print()

Measured memory_bytes: 4468
N,K=list(map(int,input().strip().split(' ')))
graph=[[] for i in range(N)]
for _ in range(N-1):
    a,b=list(map(int,input().strip().split(' ')))
    a-=1
    b-=1
    graph[a]+=[b]
    graph[b]+=[a]

from collections import deque
q=deque([0])
parent=[-1]*N
Ans=K
MOD=10**9+7
while q:
    node=q.popleft()
    deduct=0
    if node==0:
        deduct=0
    else:
        deduct=1
    for adj in graph[node]:
        if adj!=parent[node]:
            deduct+=1
            #print(adj+1,K-deduct)
            Ans*=max(K-deduct,0)
            Ans%=MOD
            parent[adj]=node
            q+=[adj]
print(Ans)


Measured memory_bytes: 64672
N = int(input())
t0,x0,y0 = 0,0,0
for _ in range(N):
    t1,x1,y1 = list(map(int, input().split()))
    t = t1 - t0
    x = x1 - x0
    y = y1 - y0
    dis = abs(x)+abs(y)
    if dis<=t and (dis-t)%2 == 0:
        t0, x0, y0 = t1,x1,y1
    else:
        print('No')
        exit()
print('Yes')


Measured memory_bytes: 3060
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

public class Main {

    public static void main(String[] args) throws Exception {
        InputStreamReader is = new InputStreamReader(System.in);
        BufferedReader reader = new BufferedReader(is);

        List<String> mylist = new ArrayList<>();

        // 標準入力からの値を変数strinputに代入
        String strinput = reader.readLine();

        while (strinput != null) {

            mylist.add(strinput);
            strinput = reader.readLine();

        }

        List<String> list01 = Arrays.asList(mylist.get(0).split(" "));
        List<String> list02 = Arrays.asList(mylist.get(1).split(" "));

        int n = Integer.valueOf(list01.get(0));
        int k = Integer.valueOf(list01.get(1));

        int cnt = 0;

        for (String v : list02) {
            if (Integer.valueOf(v) >= k) {
                cnt += 1;
            }
        }

        System.out.println(cnt);

    }

}

Measured memory_bytes: 33488
#!python3.4
# -*- coding: utf-8 -*-
# abc159/abc159_b
import sys

s2nn = lambda s: [int(c) for c in s.split(' ')]
ss2nn = lambda ss: [int(s) for s in list(ss)]
ss2nnn = lambda ss: [s2nn(s) for s in list(ss)]
i2s = lambda: sys.stdin.readline().rstrip()
i2n = lambda: int(i2s())
i2nn = lambda: s2nn(i2s())
ii2ss = lambda n: [i2s() for _ in range(n)]
ii2nn = lambda n: ss2nn(ii2ss(n))
ii2nnn = lambda n: ss2nnn(ii2ss(n))

def main():
    S = i2s()
    N = len(S)
    if is_kaibun(S) and is_kaibun(S[:(N-1)//2]) and is_kaibun(S[(N+3)//2-1:]):
        print('Yes')
    else:
        print('No')
    return

def is_kaibun(S):
    return S == ''.join(reversed(S))

main()


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

#define trace(...) __f( #__VA_ARGS__ , __VA_ARGS__ )
template <typename Arg1>
void __f( const char* name , Arg1&& arg1 ) {
        cerr << name << " : " << arg1 << "\n";
}
template <typename Arg1, typename... Args>
void __f( const char* na , Arg1&& arg1 , Args&&... args ) {
        const char* c = strchr( na + 1 , ',' );
        cerr.write( na , c - na ) << " : " << arg1 << " , ";
        __f( c + 1 , args... );
}
#define endl "\n"
#define all(V) V.begin(),V.end()
#define Unique(V) sort(all(V)),V.erase(unique(all(V)),V.end())
#define IO ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
typedef long long int LL;
typedef pair <int,int> pii;
const int MOD = 1e9 + 7;
const int inf = 1e9;
const double EPS = 1e-9;
const double PI = acos(-1.0);
const long long INF = 1e18;
const int N = 2e5 + 5;

int n , a[ N ];

int main( ) {
        IO;
        #ifdef LOCAL
            //freopen( "input.txt" , "r" , stdin );
        #endif // LOCAL
        cin >> n;
        cout << 3 * n * n << endl;
        return 0;
}










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

// main.cpp

int main() {
  std::array<bool, 100001> is_prime;
  std::fill(is_prime.begin(), is_prime.end(), true);
  is_prime[0] = false;
  is_prime[1] = false;
  for (std::int_fast64_t i = 2; i <= 317; ++i) {
    if (is_prime[i]) {
      for (std::int_fast64_t j = 2 * i; j <= 100000; j += i) {
        is_prime[j] = false;
      }
    }
  }

  std::array<bool, 100001> is_2017like;
  std::fill(is_2017like.begin(), is_2017like.end(), false);
  for (std::int_fast64_t i = 3; i <= 100000; i += 2) {
    is_2017like[i] = is_prime[i] && is_prime[(i + 1) / 2];
  }

  std::array<std::int_fast64_t, 100001> helper = {0};
  for (std::int_fast64_t i = 1; i <= 100000; ++i) {
    helper[i] = helper[i - 1] + (is_2017like[i] ? 1 : 0);
  }

  std::int_fast64_t q;
  std::cin >> q;
  for (std::int_fast64_t i = 0; i < q; ++i) {
    std::int_fast64_t l_i, r_i;
    std::cin >> l_i >> r_i;
    std::cout << helper[r_i] - helper[l_i - 1] << std::endl;
  }

  return 0;
}

Measured memory_bytes: 1664
/*
 * atcoder/abc119_2nd/c.cpp
 */

// C++ 14
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <cstring> // memset
#include <cassert>
using namespace std;
#define ll long long
#define loop(__x, __start, __end) for(int __x = __start; __x < __end; __x++)
template <class T> bool chmin(T &a, T b) { if (a > b) {a = b; return true; } return false; }
template <class T> bool chmax(T &a, T b) { if (a < b) {a = b; return true; } return false; }

const ll INF = 100000000000000000;
const int MAX = 9;
int N, A, B, C;
vector<int> L(MAX, 0);

ll rec(int n=0, int a = 0, int b = 0, int c = 0) {
  if (n == N) {
    if (a == 0 or b == 0 or c == 0) return INF;
    return abs(A-a) + abs(B-b) + abs(C-c);
  }

  ll ways = rec(n+1, a, b, c);
  chmin(ways, rec(n+1, a + L[n], b, c) + (a ? 10 : 0));
  chmin(ways, rec(n+1, a, b + L[n], c) + (b ? 10 : 0));
  chmin(ways, rec(n+1, a, b, c + L[n]) + (c ? 10 : 0));
  return ways;
}

void solve() {
  cin >> N >> A >> B >> C;
  loop(n,0,N) cin >> L[n];
  cout << rec() << endl;
}
int main() {
  // cout.precision(15);
  // cout << fixed << double

  solve();

  return 0;
}


Measured memory_bytes: 256
n, m, x, y = map(int, input().split())
X = sorted(list(map(int, input().split())))
Y = sorted(list(map(int, input().split())))

mixture = X + Y
sorted_mix = sorted(mixture)
if x > y:
    print("War")
    exit()

for i, j in zip(mixture, sorted_mix):
    if i != j:
        print("War")
        exit()

max_X = max(max(X), x)
min_Y = min(min(Y), y)

if max_X >= min_Y:
    print("War")
    exit()

print("No War")


Measured memory_bytes: 3064
#include<bits/stdc++.h>
#define pir pair<int,int>
#define qmin(x,y) (x=min(x,y))
#define qmax(x,y) (x=max(x,y))
#define rsort(x,y) sort(x,y),reverse(x,y)
#define fr first
#define se second
using namespace std;
typedef long long ll;
const int Maxn=2100000;
const int inf=0x3f3f3f3f;

int a[Maxn],n,k;

signed main() {
    // freopen("test.in","r",stdin);
    scanf("%d%d",&n,&k);
    for(int i=1;i<=n;i++) scanf("%d",&a[i]);
    for(int i=k+1;i<=n;i++) if(a[i]>a[i-k]) puts("Yes");
    else puts("No");
    return 0;
}

Measured memory_bytes: 4536
#include <bits/stdc++.h>
using namespace std;
int main()
{
    
    string color1,color2,choice;
    int num1,num2;
    cin>>color1>>color2;
    cin>>num1>>num2;
    cin>>choice;
    
    if(choice == color1){
        num1--;
    }else{
        num2--;
    }
    cout<<num1<<" "<<num2;
    return 0;
}


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

int main(){
    int N;
    cin>>N;
    string S,T,X="";
    cin>>S>>T;
    for (int i=0;i<N;i++){
       X+=S[i];
       X+=T[i]; 
    }
    cout<<X<<endl;
    return 0;
}

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

using namespace std;
typedef long long ll;
typedef pair<ll, ll> p_ll;

template<class T>
void debug(T itr1, T itr2) { auto now = itr1; while(now<itr2) { cout << *now << " "; now++; } cout << endl; }
#define repr(i,from,to) for (int i=(int)from; i<(int)to; i++)
#define all(vec) vec.begin(), vec.end()
#define rep(i,N) repr(i,0,N)
#define per(i,N) for (int i=(int)N-1; i>=0; i--)

const ll MOD = pow(10,9)+7;
const ll LLINF = pow(2,61)-1;
const int INF = pow(2,30)-1;

vector<ll> fac;
void c_fac(int x=pow(10,6)+10) { fac.resize(x,true); rep(i,x) fac[i] = i ? (fac[i-1]*i)%MOD : 1; }
ll inv(ll a, ll m=MOD) { ll b = m, x = 1, y = 0; while (b!=0) { int d = a/b; a -= b*d; swap(a,b); x -= y*d; swap(x,y); } return (x+m)%m; }
ll nck(ll n, ll k) { return fac[n]*inv(fac[k]*fac[n-k]%MOD)%MOD; }
ll gcd(ll a, ll b) { if (a<b) swap(a,b); return b==0 ? a : gcd(b, a%b); }
ll lcm(ll a, ll b) { return a/gcd(a,b)*b; }


int main() {
  ll A; double B; cin >> A >> B;
  ll tb = (ll)(B*100+1e-8);
  ll result = A*tb/100;
  cout << result << endl;
  return 0;
}

Measured memory_bytes: 3720
#include <iostream>
#include <iomanip>
#include <vector>
#include <algorithm>
#include <cmath>

using namespace std;

const double sqrt3 = sqrt(3);

struct point {
    double x;
    double y;
    point(double _x, double _y) : x(_x), y(_y) {}
    
    point operator+(point a) const {
        return point(this->x + a.x, this->y + a.y);
    }
    
    point operator-(point a) const {
        return point(this->x - a.x, this->y - a.y);
    }
};

point operator*(double t, point p) {
    return point(t * p.x, t * p.y);
}

point rotate60(point p) {
    return point((p.x - sqrt3 * p.y)/2, (sqrt3 * p.x + p.y)/2);
}

vector<point> koch(int n) {
    vector<point> ps;
    ps.push_back(point(0, 0));
    ps.push_back(point(100, 0));
    for(int i=0; i<n; i++) {
        vector<point> nxt;
        nxt.push_back(ps[0]);
        for(int j=1; j<ps.size(); j++) {
            point dir = ps[j] - ps[j-1];
            point fst = (1/3.0) * dir;
            point trd = (2/3.0) * dir;
            point snd = rotate60(trd - fst) + fst;
            nxt.push_back(ps[j-1] + fst);
            nxt.push_back(ps[j-1] + snd);
            nxt.push_back(ps[j-1] + trd);
            nxt.push_back(ps[j]);
        }
        ps = nxt;
    }
    return ps;
}


int main() {
    int n;
    cin >> n;
    vector<point> ps = koch(n);
    for(auto&& p : ps) {
        cout << fixed << setprecision(10) << p.x << " " << p.y << endl;
    }
}


Measured memory_bytes: 3308
#include <bits/stdc++.h>
#define MOD %1000000007
#define md %998244353
#define INF 2e9

#define EPS 1e-9
#define MAX LLONG_MAX
#define MIN LLONG_MIN
#define F first
#define S second
#define MP make_pair
#define PB push_back
#define EB emplace_back
#define endl "\n"
#define FOR(i,a,b) for (long long i = a; i < b; i++)
#define REV(i,a,b) for (long long i = a; i > b; i--)
#define mset(a, v) memset(a, v, sizeof(a))
#define fd(n) fixed<<setprecision(n)
typedef std::pair<int, int> pii;
typedef std::vector<long long> vi;
typedef std::vector<vi> vvi;
typedef long long ll;
typedef unsigned long long ull;
using namespace std;
const ll p=1e9 + 7 ;
ll solve(ll x,ll y) {
    ll res = 1;
    x = x % p;
    while (y > 0) {
        if (y & 1)
            res = (res*x) % p;
        y = y>>1;
        x = (x*x) % p;
    }
    return res;
}



int main() {
    ios::sync_with_stdio(false);
    cin.tie(NULL);
 
   ll t;
   cin>>t;
  
   
  ll n,i,j,k=0,flag=0,m,ans=0,x=0,y=0,c=0,a;
   
  string s;
  cin>>s;
  n=s.length();
  
  if(n<=t)
   cout<<s;
  else
   {
   	for(i=0;i<t;i++)
   	  cout<<s[i];
   	  
   	  cout<<"...";
   }

cout<<endl;
}



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



using namespace std;

typedef vector<int> VI;
typedef vector<string> VS;


//container util
#define SORT(c) sort((c).begin(),(c).end())

//repetition
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)

const int N_MAX = 101;


int main(void){

	int N; cin >> N;
	int adj[N_MAX][N_MAX];
	REP(i,N) REP(j,N) adj[i][j] = 0;

	REP(i,N){
		int u,k; cin >> u >> k; u--;
		REP(j,k){
			int v; cin >> v; v--;
			adj[u][v] = 1;
		}
	}

	REP(i,N){
		int j;
		for(j=0;j<N-1;++j){
			cout << adj[i][j] << ' ';
		}
		cout << adj[i][j] << endl;
	}


	return 0;

}



Measured memory_bytes: 3096
using System;
using System.Collections.Generic;

class Program
{
    #region library
    static int n = 0;
    static int m = 0;
    static int r = 0;
    static int c = 0;
    static int x = 0;
    static int y = 0;
    static int[] arr;
    static string s = "";
    static string[] ss;
    static string alpha = "abcdefghijklmnopqrstuvwxyz";
    static long sum = 0;
    static long cnt = 0;
    static long max = -1;
    static long min = 2147483647;
    static bool flg = false;
    static bool flg2 = false;
    static char[,] map;
    static int[,] imap;
    static string rl()
    {
        return Console.ReadLine();
    }
    static string[] rls()
    {
        return Console.ReadLine().Split();
    }
    static void wl(object obj = null)
    {
        Console.WriteLine(obj);
    }
    static void w(object obj)
    {
        Console.Write(obj);
    }
    static int Int(string s)
    {
        return int.Parse(s);
    }
    static long Max(long a, long b)
    {
        return Math.Max(a, b);
    }
    static long Min(long a, long b)
    {
        return Math.Min(a, b);
    }
    static long Abs(long a)
    {
        return Math.Abs(a);
    }
    static void yes()
    {
        wl("YES");
    }
    static void no()
    {
        wl("NO");
    }
    static void Sum()
    {
        wl(sum);
    }
    static void Cnt()
    {
        wl(cnt);
    }
    static void setarray(int num = -1)
    {
        arr = new int[n];
        if(num == -1) ss = rls();
        for (int i = 0; i < n; i++)
        {
            if (num == -1)
                arr[i] = Int(ss[i]);
            else
                arr[i] = num;
        }
    }
    static void setmap(char def = '@')
    {
        if (r == 0 && c == 0)
        {
            ss = rls();
            r = Int(ss[0]);
            c = Int(ss[1]);
        }
        map = new char[r, c];
        for (int i = 0; i < r; i++)
        {
            if (def == '@') s = rl();
            for (int j = 0; j < c; j++)
            {
                map[i, j] = (def == '@') ? s[j] : def;
            }
        }
    }
    static void setimap(int def = -1)
    {
        if (r == 0 && c == 0)
        {
            ss = rls();
            r = Int(ss[0]);
            c = Int(ss[1]);
        }
        imap = new int[r, c];
        for (int i = 0; i < r; i++)
        {
            if (def == -1) s = rl();
            for (int j = 0; j < c; j++)
            {
                imap[i, j] = (def == -1) ? Int(s[j].ToString()) : def;
            }
        }
    }
    #endregion

    static void Main(string[] args)
    {
        ss = rls();
        n = Int(ss[0]);
        int k = Int(ss[1]);

        n--;
        k--;
        int ans = n / k;
        if (n % k > 0) ans++;
        wl(ans);
    }
}



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

using namespace std;
typedef long long ll;
#define all(x) (x).begin(), (x).end()
typedef vector<bool> vb;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vector<bool>> vvb;
typedef vector<vector<int>> vvi;
typedef vector<vector<ll>> vvl;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
void debugF(ostream &os) {os << endl;}
template <typename Head, typename... Tail>
void debugF(ostream &os, Head H, Tail... T) { os << " " << H; debugF(os, T...); }
#define debug(...) cout << "[" << #__VA_ARGS__ << "]:", debugF(cout, __VA_ARGS__)
template<typename T> istream &operator>>(istream &is, vector<T> &v){ for (auto &x : v) is >> x; return is; }
template<typename T> ostream &operator<<(ostream &os, vector<T> &v){ for(int i = 0; i < v.size(); os << (i>0 ? " ":"") << v[i++]); return os;}



int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    vector<string> v = {"AC", "WA", "TLE", "RE"};
    vi cnt(4,0);
    int n, i, j;
    cin >> n;
    for(i=0;i<n;i++){
        string s;
        cin >> s;
        for(j=0;j<4;j++) if(s == v[j]) break;
        cnt[j]++;
    }
    for(j=0;j<4;j++){
        cout << v[j] << " x " << cnt[j] << "\n";
    }
    return 0;
}

Measured memory_bytes: 3672
N = int(input())
h = list(map(int, input().split()))
dp = [10**8 for i in range(N)]

for i in range(N):
    if i == 0:
        dp[i] = 0
    elif i == 1:
        dp[i] = abs(h[i] - h[i-1])
    else:
        a =dp[i-1] + abs(h[i]-h[i-1])
        b = dp[i-2] + abs(h[i]-h[i-2])
        dp[i] = min(a, b)

print(dp[N-1])

Measured memory_bytes: 13976
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <cctype>
#include <cassert>
#include <climits>
#include <string>
#include <bitset>
#include <cfloat>
#include <unordered_set>
#include <cstring>
#pragma GCC optimize("Ofast")
using namespace std;
typedef long double ld;
typedef long long int ll;
typedef unsigned long long int ull;
typedef vector<int> vi;
typedef vector<char> vc;
typedef vector<bool> vb;
typedef vector<double> vd;
typedef vector<string> vs;
typedef vector<ll> vll;
typedef vector<pair<int, int>> vpii;
typedef vector<vector<int>> vvi;
typedef vector<vector<char>> vvc;
typedef vector<vector<string>> vvs;
typedef vector<vector<ll>> vvll;
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define rrep(i, n) for (int i = 1; i <= (n); ++i)
#define irep(it, stl) for (auto it = stl.begin(); it != stl.end(); it++)
#define drep(i, n) for (int i = (n)-1; i >= 0; --i)
#define fin(ans) cout << (ans) << '\n'
#define mp(p, q) make_pair(p, q)
#define pb(n) push_back(n)
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define Sort(a) sort(a.begin(), a.end())
#define Rort(a) sort(a.rbegin(), a.rend())
#define MATHPI acos(-1)
#define itn int;
int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};
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;
}
struct io
{
    io()
    {
        ios::sync_with_stdio(false);
        cin.tie(0);
    }
};
const int INF = INT_MAX;
const ll LLINF = 1LL << 60;
const ll MOD = 1000000007;
const double EPS = 1e-9;

int main(void)
{

    string a;
    cin >> a;

        if (a == "ABC") {
            a = "ARC";
        } else a = "ABC";
    
    
    

    cout << a;
}

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

char a[10];
int main()
{
	scanf("%s", a + 1);
	int len = strlen(a + 1);
	if(len == 2) printf("%s\n", a + 1);
	else {
		char q;
		q = a[1];
		a[1] = a[3];
		a[3] = q;
		printf("%s\n", a + 1);
	}
}

Measured memory_bytes: 128
#include <stdio.h>
#define BUILDING 4
#define FLOOR 3
#define ROOM 10

int main(void)
{
    int rooms[BUILDING][FLOOR][ROOM] = {{{0}}};
    int b, f, r, v;
    int n;

    scanf(" %d", &n);

    for (; n>0; n--) {
        scanf(" %d %d %d %d", &b, &f, &r, &v);
        rooms[b-1][f-1][r-1] += v;
    }

    for (b=0; b<BUILDING; b++) {
        for (f=0; f<FLOOR; f++) {
            for (r=0; r<ROOM; r++) {
                printf(" %d", rooms[b][f][r]);
            }
            printf("\n");
        }
        if (b != BUILDING-1) {
            printf("####################\n");
        }
    }

    return 0;
}


Measured memory_bytes: 2108
#include <iostream>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <algorithm>
using namespace std;
template <typename T = int>
T in() {
    T temp;
    cin >> temp;
    return temp;
}

bool ACGT(char b) {
    switch(b) {
        case 'A':
        case 'C':
        case 'G':
        case 'T':
            return true;
    }
    return false;
}

int main() {
    string S(in<string>());
    int maxim = 0, count = 0;
    for (int i = 0; i < S.size(); i++) {
        if (ACGT(S[i])) {
            count++;
        } else if (maxim < count) {
            maxim = count;
            count = 0;
        }
    }
    cout << max(maxim, count) << endl;
    return 0;
}




Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<ll,ll>;
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define rep2(i,m,n) for(int (i)=(m);(i)<(n);(i)++)
const ll INF = 1LL<<60;
const ll MOD = 1e9+7;


int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    int r; cin>>r;
    cout<<r*r<<endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ft first
#define sc second
#define lb lower_bound
#define ub upper_bound
#define pb push_back
#define pt(sth) cout << sth << "\n"
#define chmax(a, b) {if(a<b) a=b;}
#define chmin(a, b) {if(a>b) a=b;}
#define moC(a, s, b) (a)=((a)s(b)+MOD)%MOD
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
static const ll INF=1e18;
static const ll MAX=1e5+7;
static const ll MOD=1e9+7;
ll max(ll a, ll b) {return a>b?a:b;}
ll min(ll a, ll b) {return a<b?a:b;}


int main(void) {
  ll R, G, B, N;
  cin >> R >> G >> B >> N;
  ll i, j, k;
  ll ans=0;
  ll cnt[3333]={};
  
  map<ll, ll> mp;
  for(i=0; i<=N; i++) {
    for(j=0; j<=N; j++) {
      if(i*R+j*G>3000) continue;
      cnt[i*R+j*G]++;
    }
  }
  
  for(i=0; i<=N; i++) {
    if(N-i*B<0) continue;
    ans+=cnt[N-i*B];
  }
  
  pt(ans);
}









Measured memory_bytes: 256
N, *K = $<.read.split.map(&:to_i)
puts K.reverse_each.inject([2,3]){|r,a|
	r.map!{|_| (_+a-1)/a*a }
	break [0] if r[0] == r[1]
	r
}.tap{|r| r[-1]-=1 }*' '


Measured memory_bytes: 9340
n,a,b = map(int, input().split())

n_list = list(range(0,n + 1))

result_sum = 0
for i in n_list :
    i_str = list(str(i))
    #print(i_str)
    i_sum = 0
    for t in i_str :
        i_sum = i_sum + int(t)
    #print(i_sum)
    if i_sum >= a and i_sum <= b :
        result_sum = result_sum + i
print(result_sum)


Measured memory_bytes: 3316
A,V=map(int,input().split())
B,W=map(int,input().split())
T = int(input())

#逃げるほうが早い
if V <= W:
  print('NO')
  exit()
else:
  soutaikyori=abs(A-B)
  soutaiV=V-W
  #距離を詰めきれない
  if soutaikyori / soutaiV > T:
    print("NO")
    exit()
  else:
    print("YES")
    exit()
  #距離を詰めきれる?
    #割り切れる
    """
    print("YES")
    exit()
    if soutaikyori%soutaiV==0:
      print("YES")
    else:
      #割り切れない
      amari = soutaikyori % soutaiV
      keikazikan = soutaikyori / soutaiV
      nokorizikan = T - keikazikan
      if A > B:
        A += V * keikazikan
        B += W * keikazikan
      else:
        A -= V * keikazikan
        B -= W * keikazikan

      for t in range(nokorizikan):
        #Aは近づく，Bは離れる
        if A == B:
          print("YES")
          exit()
        elif A > B:
          A -= V
          B -= W
        else:
          A += V
          B += W
      
      print("NO")
    """

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

int main() {
  char c;
  cin >> c;
  
  vector<char> v={'a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z'}
  rep(i,v.size()){
    if(c == v.at(i))
      cout << v.at(i+1) << endl;
  }
}

Measured memory_bytes: 3580
import math
def g(a,b,c):
    return math.gcd(math.gcd(a,b),math.gcd(b,c))
sum = 0
k = int(input())
for i in range(1,k+1):
    for j in range(1,k+1):
        m = math.gcd(i,j) 
        for l in range(1,k+1):
            sum += math.gcd(m,l)
print(sum)



Measured memory_bytes: 67716
#include <stdio.h>
int main()
{

    int a, b;
    int min = 0;
    int max = 0;
    long sum = 0;
    int i = 1;
    scanf("%d", &a);
    scanf("%d", &b);
    min = b;
    max = b;
    for (i; i <= a; i++)
    {
        if (b < min)
        {
            min = b;
        }
        if (b > max)
        {
            max = b;
        }
        sum = sum + b;
        scanf("%d", &b);
    }
    printf("%d %d %li\n", min, max, sum);
}


Measured memory_bytes: 2108
n, m = map(int, raw_input().split())
ppp = []
ppm = []
pmp = []
mpp = []

for _ in range(n):
    x,y,z = map(int, raw_input().split())
    ppp.append(x+y+z)
    ppm.append(x+y-z)
    pmp.append(x-y+z)
    mpp.append(-x+y+z)
p0 = abs(sum(sorted(ppp)[:m]))
p1 = abs(sum(sorted(ppm)[:m]))
p2 = abs(sum(sorted(pmp)[:m]))
p3 = abs(sum(sorted(mpp)[:m]))
p4 = abs(sum(sorted(ppp, reverse=True)[:m]))
p5 = abs(sum(sorted(ppm, reverse=True)[:m]))
p6 = abs(sum(sorted(pmp, reverse=True)[:m]))
p7 = abs(sum(sorted(mpp, reverse=True)[:m]))
print(max(p0, p1, p2, p3, p4, p5, p6, p7))

Measured memory_bytes: 2948
h,w = map(int, input().split())
S = [input() for i in range(h)]

def count(x,y):
  p = 0
  if x >= 1 and y >= 1 and S[x-1][y-1] == "#":
    p += 1
  if x >= 1 and S[x-1][y] == "#":
    p += 1
  if x >= 1 and y <= w - 2 and S[x-1][y+1] == "#":
    p += 1
  if y >= 1 and S[x][y-1] == "#":
    p += 1
  if y <= w - 2 and S[x][y+1] == "#":
    p += 1
  if x <= h - 2 and y >= 1 and S[x+1][y-1] == "#":
    p += 1
  if x <= h - 2 and S[x+1][y] == "#":
    p += 1
  if x <= h - 2 and y <= w - 2 and S[x+1][y+1] == "#":
    p += 1
  p = str(p)
  return(p)

for i in range(h):
  ans = ""
  for j in range(w):
    if S[i][j] == "#":
      ans += "#"
    else:
      ans += count(i,j)
  print(ans)

Measured memory_bytes: 3064
#include <iostream>
#include <cstdio>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <iomanip>
#include <stdlib.h>
#include <string.h>
#include <cstring>
#include <cmath>
#include <map>
#include <queue>
#include <deque>
#include <stack>
#include <set>
#include <stdio.h>
#include <tuple>
#include <bitset>
#include <cfloat>
#include <fstream>
#include <limits.h>
#include <list>
#include <math.h>
#include <random>
#include <unordered_map>
#include <unordered_set>
#include <bitset>
#include <numeric>
#include <utility>
#include <sstream>

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

using namespace std;
#define int long long
#define ll long long
#define rep(i, n) for (ll i = 0; i < (n); i++)
#define FOR(i,a,b) for(ll i=(a);i<(b);i++)
#define FORR(i,a,b)for(ll i=(a);i<=(b);i++)
#define repR(i,n) for(ll i=n;i>=0;i--)
#define P pair<ll, ll>
#define sz(x) (ll)x.size()
#define ALL(x) (x).begin(),(x).end()
#define ALLR(x) (x).rbegin(),(x).rend()
#define VE vector<ll>
#define COUT(x) cout<<(x)<<endl
#define MA map<ll,ll>
#define SE set<ll>
#define PQ priority_queue<ll>
#define PQR priority_queue<ll,VE,greater<ll>>
#define COUT(x) cout<<(x)<<endl
#define YES(n) cout << ((n) ? "YES" : "NO"  ) << endl
#define Yes(n) cout << ((n) ? "Yes" : "No"  ) << endl
#define EPS (1e-10)
ll gcd(ll a, ll b) {
	if (a < b)swap(a, b);
	if (b == 0) return a;
	return gcd(b, a % b);
}
ll lcm(ll a, ll b) {
	ll g = gcd(a, b);
	return a / g * b;
}
bool prime(ll n) {
	for (ll i = 2; i <= sqrt(n); i++) {
		if (n%i == 0)return false;
	}
	return n != 1;
}


const long long MOD = 1000000007;
const long long INF = 1LL << 60;


const int MAX_N = 100010;


signed main() {
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	int n; cin >> n;
	FORR(i, 1, n) {
		if (i * 108 / 100 == n) {
			cout << i << endl; return 0;
		}
	}
	cout << ":(" << endl;
	return 0;
}


Measured memory_bytes: 256
a,b,c,x = [int(input()) for _ in range(4)]
an = 0
 
for i in range(a+1):
    for j in range(b+1):
        for k in range(c+1):
            if 500*i + 100*j + 50*k == x:
                an+=1
 
print(an)

Measured memory_bytes: 3060
n = int(input())
a = list(map(int,input().split()))
b = [a[n]]
for i in range(1,n+1):
    b += [b[i-1] + a[n-i]]
b.reverse()
k = 1
ans = 0
for i in range(n):
    if a[i] > k:
        print(-1)
        exit()
    ans += k
    k = min((k - a[i]) * 2, b[i+1])
if a[n] > k:
    print(-1)
else:
    print(ans+k)


Measured memory_bytes: 20000
#include<iostream>
#include<math.h>
#include<vector>
#include<algorithm>
#include<string.h>
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
long long int mod=1e9+7;
typedef long long ll;
bool debug=false;
long long int gcd(long long int a,long long int b){
	if(a<b){
		if(a==0)return b;
		else return gcd(b%a,a);
	}else{
		if(b==0)return a;
		else return gcd(a%b,b);
	}
}

int main(){
	long long int a,b,c,d;
	cin>>a>>b>>c>>d;
	long long int e=c*d;
	e=e/gcd(c,d);
	a--;
	long long int k=(b/c)-(a/c)+(b/d)-(a/d)-(b/e)+(a/e);
	if(debug){
	cout<<(b/c)-(a/c)<<endl;
	cout<<(b/d)-(a/d)<<endl;
	cout<<(b/e)-(a/e)<<endl;
	}
	cout<<b-a-k<<endl;
	return 0;
}

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

namespace AtCoder.AtCoderBeginnerContest.ABC120
{
    public class C
    {
        public static void Solve()
        {
            var s = Console.ReadLine();
            var count1 = s.Count(x => x == '1');
            var count0 = s.Count(x => x == '0');

            Console.WriteLine(Math.Min(count1, count0) * 2);

        }

        static void Main(string[] args)
        {
            Solve();
        }
    }
}


Measured memory_bytes: 11360
#include<bits/stdc++.h>
#define ff first
#define ss second
#define len(x) (int)(x.size())
#define all(x) x.begin(), x.end()
using namespace std;
using ll = long long;
using ii = pair<int, int>;

int main(){
	ios::sync_with_stdio(0);
	int n;
	cin >> n;
	string st;
	cin >> st;
	for(auto &c:st){
		int k = c-'A';
		c = (k+n)%26+'A';
	}
	cout << st << endl;
}


Measured memory_bytes: 256
import sys
from math import log2,floor,ceil,sqrt
# import bisect
# from collections import deque

Ri = lambda : [int(x) for x in sys.stdin.readline().split()]
ri = lambda : sys.stdin.readline().strip()
 
def input(): return sys.stdin.readline().strip()
def list2d(a, b, c): return [[c] * b for i in range(a)]
def list3d(a, b, c, d): return [[[d] * c for j in range(b)] for i in range(a)]
def list4d(a, b, c, d, e): return [[[[e] * d for j in range(c)] for j in range(b)] for i in range(a)]
def ceil(x, y=1): return int(-(-x // y))
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(N=None): return list(MAP()) if N is None else [INT() for i in range(N)]
def Yes(): print('Yes')
def No(): print('No')
def YES(): print('YES')
def NO(): print('NO')
INF = 10 ** 18
MOD = 10**9+7

n,k = Ri()
a = Ri()
a= [0]+a
ans = []
# ans.append(0)
dic = {}
prev = 1
# dic[0] = 0
ite  = 0
flag = -1
for i in range(n):
    if a[prev] not in dic:
        ans.append(a[prev])
        dic[a[prev]] = ite
        prev = a[prev]
        ite+=1
    else:
        flag = a[prev]
        break
start = dic[flag]
# print(ans,dic)
if k-1 < start:
    print(ans[k-1])
else:
    # print(start,ans)
    cyclen = len(ans)-start
    k-=1
    k -= start
    k%=cyclen
    print(ans[start+k])



Measured memory_bytes: 126720
#include<bits/stdc++.h>
using namespace std;
#define fastio() ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define ll long long
#define ull unsigned long long
#define vi vector<int>
#define pi pair<int, int>
#define F first
#define S second
#define PB push_back
#define MP make_pair
#define deb(x) cout << #x << ":" << x << endl;
/* freopen("input.txt", "r", stdin); */
/* freopen("output.txt", "w", stdout); */
const int MOD = 1000000007;

int main() {
	fastio();
	int n, m, x;
	cin >> n >> m >> x;
	vi c(n, 0); vector<vi> a(n);
	for(int i=0;i<n;i++) {
		cin >> c[i];
		int aij;
		for(int j=0;j<m;j++) {
			cin >> aij;
			a[i].PB(aij);
		}
	}
	/* cout << "cost: " << endl; */
	/* for(auto i: c)    cout << i << " "; */
	/* cout << endl; */
	/* cout << "a: "; */
	/* for(auto i: a) */
	/* 	for(auto j: i) */
	/* 		cout << j << " "; */
	/* cout << endl; */
	// generate bit strings
	int ans = INT_MAX;
	for(int p=0;p<(1<<n);p++) {
		int pp = p, pos=0;
		int cost=0; vi skill(m, 0);
		/* deb(pp); */
		do {
			/* deb(pos); */
			if(pp & 1) {
				cost += c[pos];
				for(int j=0;j<m;j++)
					skill[j] += a[pos][j];
			}
			pp >>= 1;
			pos++;
		} while(pp);
		int j;
		for(j=0;j<m;j++)
			if(skill[j] < x)
				break;
		if(j == m)
			ans = min(ans, cost);
	}
	if(ans != INT_MAX)
		cout << ans << "\n";
	else
		cout << -1 << "\n";
	return 0;
}





Measured memory_bytes: 3644
#include <iostream>
#include <string>
#include <sstream>
#include <iomanip> 
#include <math.h>
#include <stdio.h>
#include <string.h>
#include <queue>
#include <stack>
#include <vector>
#include <map>
#include <set>
#include <functional>
#include <algorithm>
#include <unordered_map>
#include <unordered_set>
#include <bitset>

using namespace std;


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

	long long n, i, j, k, ans, c, x, a;
	cin >> n >> c;
	vector<vector<long long>> d(c + 1, vector<long long>(c + 1));
	for (i = 1; i <= c; i++) {
		for (j = 1; j <= c; j++) cin >> d[i][j];
	}
	vector<vector<long long>> cc(n + 1, vector<long long>(n + 1));
	vector<vector<long long>> ct(3, vector<long long>(c + 1, 0));
	for (i = 0; i < n; i++) {
		for (j = 0; j < n; j++) {
			cin >> cc[i][j];
			ct[(i + j) % 3][cc[i][j]]++;
		}
	}

	ans = 1LL << 61;
	for (i = 1; i <= c; i++) {
		for (j = 1; j <= c; j++) 
			for (k = 1; k <= c; k++) {
				if ((i == j) || (j == k) || (i == k)) continue;
				x = 0;
				for (a = 1; a <= c; a++) x += ct[0][a] * d[a][i];
				for (a = 1; a <= c; a++) x += ct[1][a] * d[a][j];
				for (a = 1; a <= c; a++) x += ct[2][a] * d[a][k];
				if (x < ans) {
					ans = x;
				}
			}
	}

	cout << ans << "\n";
	return 0;
}


Measured memory_bytes: 2304
import java.util.Scanner;
public class Main {
	static Scanner scan=new Scanner(System.in);
	static int gcd (int a, int b) {return b>0?gcd(b,a%b):a;}
	static long lcm (int a, int b) {return a*b/gcd(a,b);}
	static int max(int a,int b) {return a>b?a:b;}
	static int min(int a,int b) {return a<b?a:b;}
	static long factorial(int i) {return i==1?1:i*factorial(i-1);}
	static int lower_bound(int a[],int key) {
		int low=0,high=a.length;
		while(low<high) {
			int mid=((high-low)/2)+low;
			if(a[mid]<=key)low=mid+1;
			else high=mid;
		}
		return high;
		}
	static int upper_bound(int a[],int key) {
		int low=0,high=a.length;
		while(low<high) {
			int mid=((high-low)/2)+low;
			if(a[mid]<key)low=mid+1;
			else high=mid;
		}
		return high;
		}
	static boolean isPrime (int n) {
		if (n==2) return true;
		if (n<2 || n%2==0) return false;
		double d = Math.sqrt(n);
		for (int i=3; i<=d; i+=2)if(n%i==0){return false;}
		return true;
	}
	static int upper_division(int a,int b) {
		if(a%b==0) {
			return a/b;
		}
		else {
			return a/b+1;
		}
	}
	static long lupper_division(long a,long b) {
		if(a%b==0) {
			return a/b;
		}
		else {
			return a/b+1;
		}
	}
	static long lmax(long a,long b) {return Math.max(a, b);}
	static long lmin(long a,long b) {return Math.min(a, b);}
	
		public static void main(String[] args) {
			int a=scan.nextInt()*100+scan.nextInt()*10+scan.nextInt();
			System.out.println(a%4==0?"YES":"NO");
		}
}


Measured memory_bytes: 25044
#include <bits/stdc++.h> 
using namespace std;
#define rep(i,n) for(ll i=0;i<n;i++)
#define all(vec) vec.begin(), vec.end()
#define tmax(x,y,z) max((x),max((y),(z)))
#define tmin(x,y,z) min((x),min((y),(z)))
typedef long long ll;ll MM = 1000000000;ll mod = MM + 7; ll MMM=9223372036854775807;//2^63 -1
ll GCD(ll x, ll y) {if (y == 0) return x;else return GCD(y, x % y);}
ll LCM(ll x, ll y) { return x / GCD(x, y) * y;}
//cout << fixed << setprecision(10);

int main(){
 ll n,i; cin>>n>>i;
  cout<<n-i+1<<endl;
  
}

Measured memory_bytes: 256
#include<iostream>
#include<iomanip>
#include<string>
#include<cmath>
#include<algorithm>
#include<vector>


#define rep(i,n) for(int i = 0; i < n; ++i)
#define all(x) x.begin(),x.end()
using namespace std;

int main(void){
  int a,b,c;
  int d,e,f,g,h,i;

  cin >> a >> b >> e;
  c = 0;
  //a b c
  //d e f
  //g h i

  while(true){
    int sum = a + b + c;
    h = sum - b - e;
    i = sum - e - a;
    f = sum - c - i;
    d = sum - e - f;
    g = sum - h - i;
    if( a+b+c==sum && d+e+f==sum && g+h+i==sum && a+d+g==sum && b+e+h==sum && c+f+i==sum && a+e+i==sum && c+e+g==sum){
      cout << a << " " << b << " " << c << endl;
      cout << d << " " << e << " " << f << endl;
      cout << g << " " << h << " " << i << endl;
      break;
    }
    c++;
  }
  return 0;
}



Measured memory_bytes: 256
import java.util.Arrays;
import java.util.Scanner;

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

		Arrays.sort(h);
		int ans = Integer.MAX_VALUE;
		for (int i = k - 1; i < n; i++) {
			int d = h[i] - h[i - k + 1];
			ans = Math.min(ans, d);
		}
		System.out.println(ans);
	}
}


Measured memory_bytes: 51028
#include <bits/stdc++.h>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/assoc_container.hpp>
#define black_tree tree<ll,null_type,less_equal<ll>,rb_tree_tag,tree_order_statistics_node_update>
#define pair_black_tree tree<pair<ll,ll>,null_type,less<pair<ll,ll> >,rb_tree_tag,tree_order_statistics_node_update>
#define gp __gnu_pbds
#define INF 1e18
#define MOD 1000000007
#define MAX 501
#define endl '\n'
#define ll long long
#define ld long double
#define lli long long int
#define ull unsigned long long
#define ulli unsigned long long int
#define pb push_back
#define pf push_front
#define ook order_of_key
#define fbo find_by_order
#define np next_permutation
#define mp make_pair
#define eb emplace_back 
#define mae max_element
#define mie min_element
#define lb lower_bound 
#define ub upper_bound
#define bs binary_search
#define ff first
#define ss second
using namespace std;
using namespace gp;
string s;
ll ans;
int main(){
	ios::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	cin>>s;
	for(int i=0;i<s.size();i++){
		ans+=s[i]-48;
	}
	if(ans%9==0){
		cout<<"Yes";
	}
	else{
		cout<<"No";
	}
}

Measured memory_bytes: 3708
#include <iostream>


using namespace std;


using ull = unsigned long long;


int main()
{
    ull N, M;
    cin >> N >> M;

    ull p = 1;
    for (auto i = 0; i < M; i++)
        p *= 2;

    ull tmp = 1900 * M;
    tmp += 100 * (N - M);
    cout << p * tmp << endl;
}


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

int main(int argc, char const *argv[])
{
	int n,k;
	cin>>n>>k;
	if ((n-1)*(n-2)/2<k)
	{
		cout<<"-1\n";
		return 0;
	}
	int ans=n-1+(n-1)*(n-2)/2-k;
	cout<<ans<<endl;
	for (int i = 2; i <= n; ++i)
	{
		cout<<"1 "<<i<<endl;
	}
	int del=(n-1)*(n-2)/2-k,now=2;
	while (del>0)
	{
		for (int i = now+1; i <= n; ++i)
		{
			cout<<now<<" "<<i<<endl;
			--del;
			if (del==0)
			{
				break;
			}
		}
		++now;
	}
	return 0;
}


Measured memory_bytes: 256
#include <stdio.h>

int main(void)
{
	int N;
	int a;

	char colorFlag[8];
	int overCount;
	int colorCount;

	int min, max;

	int i;

	for (i = 0; i < 8; i++) colorFlag[i] = 0;

	scanf("%d", &N);
	overCount = 0;
	for (i = 0; i < N; i++){
		scanf("%d", &a);

		if (a >= 3200) overCount++;
		else colorFlag[a / 400] = 1;
	}

	colorCount = 0;
	for (i = 0; i < 8; i++) colorCount += colorFlag[i];

	min = colorCount;
	if (min == 0) min = 1;

	max = colorCount + overCount;
	printf("%d %d\n", min, max);

	return 0;
}


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


public class Test
{

	public static void Main()
	{
        int[] nums = Console.ReadLine().Split(' ').Select(s => int.Parse(s)).ToArray();
        int K = nums[0];
        int S = nums[1];
        int ans = 0;
        
        for(int x = 0 ; x <= K ; x++)
        {
            for(int y = 0 ; y <= K ; y++)
            {
                if(S-x-y >= 0 && S-x-y <= K)
                {
                    ans++;
                }
            }
        }
        
        Console.WriteLine(ans);  
    }

}

Measured memory_bytes: 13268
//package BeginnerContest141;

import java.util.*;
import java.io.*;

public class Main {

    public static void main(String[] args) throws IOException {
        FastReader sc = new FastReader();
        PrintWriter pw = new PrintWriter(System.out);
        int n = sc.nextInt();
        int m = sc.nextInt();
        TreeMap<Long, Long> map = new TreeMap<>();
        long sum = 0;
        for(int i = 0; i<n; i++){
            long k = sc.nextLong();
            if(map.containsKey(k)){
                map.put(k, map.get(k)+1);
            }
            else{
                map.put(k, 1L);
            }
        }
        for(int i = 0; i<m; i++){
            long k = map.lastKey();
            if(map.get(k) == 1){
                map.remove(k);
            }
            else {
                map.put(k, map.get(k) - 1);
            }

            if(map.containsKey(k/2)){
                map.put(k/2, map.get(k/2)+1);
            }
            else{
                map.put(k/2, 1L);
            }
        }
        for(long l : map.keySet()){
            sum+=l*map.get(l);
        }
        pw.println(sum);
        //pw.println(prices);
        pw.close();
    }

    static class FastReader {
        BufferedReader br;
        StringTokenizer st;

        public FastReader() {
            br = new BufferedReader(new
                    InputStreamReader(System.in));
        }

        String next() {
            while (st == null || !st.hasMoreElements()) {
                try {
                    st = new StringTokenizer(br.readLine());
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
            return st.nextToken();
        }

        int nextInt() {
            return Integer.parseInt(next());
        }

        long nextLong() {
            return Long.parseLong(next());
        }

        double nextDouble() {
            return Double.parseDouble(next());
        }

        String nextLine() {
            String str = "";
            try {
                str = br.readLine();
            } catch (IOException e) {
                e.printStackTrace();
            }
            return str;
        }
    }
}

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

vector<int> e[100010];

int a[100010];
long long int dp[100010];
bool flag = true;
void dfs(int x,int p){
	if(e[x].size()==1)	dp[x]=a[x];
	else	dp[x]=a[x]*2;
	for(int it:e[x])
		if(it!=p){
			dfs(it,x);
			dp[x]-=dp[it];
			if(e[x].size()>1&&dp[it]>a[x])	flag = false;
		}
	if(dp[x]<0)	flag = false;
	if(e[x].size()>1&&dp[x]>a[x])	flag = false;
}

int main(){
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	int n;
	cin>>n;
	for(int i=1;i<=n;i++)
		cin>>a[i];
	for(int i=1,u,v;i<n;i++)
		cin>>u>>v,e[u].emplace_back(v),e[v].emplace_back(u);
	dfs(1,0);
	if(dp[1]!=0)
		flag = false;
	if(flag)
		cout<<"YES\n";
	else
		cout<<"NO\n";
}	


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


#define T_LEN (1000)
#define P_LEN (1000)
#define false (-1)

static int t_len;
static char T[T_LEN];
static char P[P_LEN];

int
kmp(int p_len, int t_i)
{
        int p_i;

        if (t_len - (p_len - 1) <= t_i)
                return false;

        for(p_i = 0;p_i < p_len; p_i++) {
                if (T[t_i + p_i] != P[p_i]) {
                        if (t_len - (p_len - 1) <= t_i)
                                return false;
                        t_i++;
                        p_i = -1;
                }
        }

        return t_i;
}

int
main(void)
{
        int match = -1;
        int p_len;
        int i;

        scanf("%s", T);
        scanf("%s", P);

        p_len = strlen(P);
        t_len = strlen(T);

        for (;;) {
                match = kmp(p_len, match + 1);
                if (match == false)
                        break;
                printf("%d\n", match);
        }
        return 0;
}



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

class A
{
    static void Main()
    {
        var a = Console.ReadLine().Split().Select(int.Parse).ToArray();
        Console.WriteLine(Math.Max(Math.Max(a[0] + a[1], a[0] - a[1]), a[0] * a[1]));
    }
}


Measured memory_bytes: 11220