akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define rep(i, n) for (ll i = 0; i < (ll)(n); ++i)
#define rep2(i, s, n) for (ll i = s; i < (ll)(n); i++)
#define repr(i, n) for (ll i = n; i >= 0; i--)
#define pb push_back
#define COUT(x) cout << (x) << endl
#define COUTF(x) cout << setprecision(15) << (x) << endl
#define ENDL cout << endl
#define DF(x) x.erase(x.begin())  // 先頭文字削除
#define ALL(x) x.begin(), x.end()
#define SORT(x) sort(ALL(x))
#define REVERSE(x) reverse(ALL(x))
#define init() \
  cin.tie(0);  \
  ios::sync_with_stdio(false)
#define debug(x) cerr << "[debug] " << #x << ": " << x << endl;
#define debugV(v)                       \
  cerr << "[debugV] " << #v << ":";     \
  rep(i, v.size()) cerr << " " << v[i]; \
  cerr << endl;
using namespace std;
using ll = long long;
using ld = long double;
using vll = vector<ll>;
using P = pair<ll, ll>;
constexpr ll INF = 0x3f3f3f3f3f3f3f3f;
constexpr ld PI = 3.141592653589793238462643383279;
ll get_digit(ll x) {
  return to_string(x).size();
}

ll gcd(ll x, ll y) {
  return y ? gcd(y, x % y) : x;
}

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

vector<P> factorize(ll n) {
  vector<P> result;
  for (ll i = 2; i * i <= n; ++i) {
    if (n % i == 0) {
      result.pb({i, 0});
      while (n % i == 0) {
        n /= i;
        result.back().second++;
      }
    }
  }
  if (n != 1) {
    result.pb({n, 1});
  }
  return result;
}

vll divisor(ll n) {
  vll ret;
  for (ll i = 1; i * i <= n; i++) {
    if (n % i == 0) {
      ret.push_back(i);
      if (i * i != n) ret.push_back(n / i);
    }
  }
  SORT(ret);
  return (ret);
}

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;
}

signed main() {
  init();
  ll A, B;
  cin >> A >> B;

  ll sa = B - A;

  vll X(1000);
  rep(i, 1000) {
    if (i == 0) {
      continue;
    }
    if (i == 1) {
      X[i] = 1;
      continue;
    }
    X[i] = X[i - 1] + i;

    if (i == sa) {
      COUT(X[i] - B);
      return 0;
    }
  }

  return 0;
}

Measured memory_bytes: 256
/*
　　　  ∧＿∧　やあ
　　 （´・ω・｀)　　　　　/　　　　　ようこそ、バーボンハウスへ。
　　 ／∇y:::::＼　　　 [￣]　　　　　このテキーラはサービスだから、まず飲んで落ち着いて欲しい。
　　 |:⊃:|:::::|　　　|──|
￣￣￣￣￣￣￣￣￣￣￣￣￣￣￣￣￣|　うん、「また」なんだ。済まない。
￣￣￣￣￣￣￣￣￣￣￣￣￣￣￣|￣　  仏の顔もって言うしね、謝って許してもらおうとも思っていない。
￣￣￣￣￣￣￣￣￣￣￣￣￣￣／|
　　　　∇　∇　∇　∇　　　／.／|　　　でも、この提出を見たとき、君は、きっと言葉では言い表せない
　　　　┴　┴　┴　┴　／ ／　  |　　　「ときめき」みたいなものを感じてくれたと思う。
￣￣￣￣￣￣￣￣￣￣|／　　  |　　　殺伐としたコンテストの中で、そういう気持ちを忘れないで欲しい
￣￣￣￣￣￣￣￣￣￣　　　　 |　　　そう思って、この提出を投げたんだ。
　　　(⊆⊇)　(⊆⊇)　(⊆⊇)　　|
　    ||　　 ||　　||　　|　　　 じゃあ、判定を聞こうか。
　　.／|＼　／|＼ ／|＼
*/

#include <iostream>
#include <cstdlib>
#include <algorithm>
#include <array>
#include <bitset>
#include <climits>
#include <cmath>
#include <cstdio>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <string>
#include <vector>
using namespace std;
#define fst first
#define snd second
#define ALL(obj) (obj).begin(),(obj).end()
#define debug(x) cerr << #x << " -> " << x << " (line:" << __LINE__ << ")" << '\n';
#define debugpair(x, y) cerr << "(" << #x << ", " << #y << ") -> (" << x << ", " << y << ") (line:" << __LINE__ << ")" << '\n';
typedef long long lint;
typedef priority_queue<int> p_que;
typedef priority_queue<int, vector<int>, greater<int>()> p_que_rev;
const int INF = INT_MAX;
const lint LINF = LLONG_MAX;
const int MOD = 1000000000 + 7;
const double EPS = 1e-9;
const double PI = acos(-1);
const int di[]{0, -1, 0, 1, -1, -1, 1, 1};
const int dj[]{1, 0, -1, 0, 1, -1, -1, 1};


int main()
{
    cin.tie(0);
    ios_base::sync_with_stdio(false);
    lint n;
    cin >> n;
    vector<lint> a(n);
    vector<lint> b(n);
    lint ans = 0;
    for (int i=0; i<n; ++i){
        scanf("%lld %lld", &a[i], &b[i]);
    }
    for (int i=n-1; i>=0; --i){
        // debug(ans + a[i]);
        if((a[i] + ans) % b[i] != 0){
            ans += b[i] - ((a[i] + ans) % b[i]);
        }
    }
    cout << ans << "\n";
    return 0;
}

Measured memory_bytes: 1792
#include "bits/stdc++.h"
typedef long long ll;
using namespace std;

int main() {
    string b;
    cin >> b;
    if (b == "A") cout << "T" << endl;
    else if (b=="C")cout << "G" << endl;
    else if (b=="G")cout << "C" << endl;
    else if (b=="T")cout << "A" << endl;
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <cmath>
#include <iomanip>
using namespace std;
using ll = long long;

const long double PI = acos(-1.0);
const int MOD = 1e9 + 7;

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

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

    for(int i = k; i < n; i++) {
        if(a[i - k] < a[i]) cout << "Yes" << endl;
        else cout << "No" << endl;
    }

    return 0;
}

Measured memory_bytes: 4392
#include <bits/stdc++.h>
using namespace std;
#define lli long long int
#define uli unsigned long long int
#define rep(i, m, n) for (lli i = m; i < (n); i++)
#define repe(i, m, n) for (lli i = m; i <= (n); i++)
#define ALL(x) (x).begin(), (x).end()
#define SIZE(x) ((lli)(x).size())
#define MAX(x) *max_element(ALL(x))
#define _GLIBCXX_DEBUG
const lli INF = 2147483647;
const lli MINF = -2147483648;
const lli LINF = 9223372036854775807;
const lli MOD = 1000000007; //10^9+7
const long double PI = acos(-1);
#define SORT(n) sort(n.begin(), n.end())
#define SORTR(n) sort(n.begin(), n.end(), greater<int>())
#define REV(n) reverse(n.begin(), n.end())
#define Vec(K, L, N, S) vector<L> K(N, S)
#define rt sqrt
#define pb push_back
#define ppb pop_back
#define eb emplace_back
#pragma GCC optimize("Ofast")
using vi = vector<int>;
using vvi = vector<vi>;
using vvvi = vector<vvi>;
using vlli = vector<lli>;
using P = pair<lli, lli>;
// vector<P> vp;
// vp.emplace_back(a[i], b[i]);
using vs = vector<string>;
using ll = long long;
// vector入力
template <typename T>
istream &operator>>(istream &is, vector<T> &vec)
{
  for (T &x : vec)
    is >> x;
  return is;
}
// vector出力
template <typename T>
ostream &operator<<(ostream &os, vector<T> &vec)
{
  // os << '{';
  for (int i = 0; i < vec.size(); i++)
  {
    os << vec[i] << (i + 1 == vec.size() ? "" : "");
  }
  // os << '}';
  return os;
}
// aよりもbが大きいならばaをbで更新する(更新されたならばtrueを返す)
template <typename T>
bool chmax(T &a, const T &b)
{
  if (a < b)
  {
    a = b; // aをbで更新
    return true;
  }
  return false;
}
// aよりもbが小さいならばaをbで更新する(更新されたならばtrueを返す)
template <typename T>
bool chmin(T &a, const T &b)
{
  if (a > b)
  {
    a = b; // aをbで更新
    return true;
  }
  return false;
}

int main()
{
  ios::sync_with_stdio(false);
  cin.tie(0);
  lli a, b, c, h, k, q, n, w, ans = 0, count = 0;
  string s, t;
  cin >> n >> k >> q;
  vlli d(q), e(n, 0);
  rep(i, 0, q)
  {
    cin >> d[i];
    e[d[i] - 1]++;
  }
  rep(i, 0, n)
  {
    ans = 0;
    ans = k - (q - e[i]);
    if (ans > 0)
    {
      cout << "Yes"
           << "\n";
    }
    else
    {
      cout << "No"
           << "\n";
    }
  }
}

Measured memory_bytes: 2176
a = [int(input()) for _ in range(5)]
k = int(input())

flag = True

for i in range(4):
    for j in range(i+1, 5):
        if abs(a[i] - a[j]) > k:
            flag = False
            break

if flag:
    print("Yay!")
else:
    print(":(")

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

#define ll long long
#define MAX 300005
#define pp pair<int,pair<int,pair<int,int>>>
#define pb push_back
#define mod 1000000007

using namespace std;

/*
 * author: Kruti_20
 */

ll power(ll x, ll y);

ll gcd(ll a, ll b);

vector<int> v[MAX];

ll update[MAX];
ll counter[MAX];

void dfs(int node, int p, ll val) {
    counter[node] = val + update[node];
    for (int i = 0; i < v[node].size(); i++) {
        if (v[node][i] != p) {
            dfs(v[node][i], node, val + update[node]);
        }
    }
}

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int n, q;
    cin >> n >> q;
    for (int i = 0; i < n - 1; i++) {
        int a, b;
        cin >> a >> b;
        v[a].push_back(b);
        v[b].push_back(a);
    }
    for (int i = 0; i < q; i++) {
        int node;
        cin >> node;
        ll val;
        cin >> val;
        update[node] += val;
    }
    dfs(1, -1, 0ll);
    for (int i = 1; i <= n; i++) cout << counter[i] << " ";
    return 0;
}

ll power(ll x, ll y) {
    ll res = 1;
    x = x % mod;
    while (y > 0) {
        if (y & 1) res = (res * x) % mod;
        y = y >> 1;
        x = (x * x) % mod;
    }
    return res;
}

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

Measured memory_bytes: 35584
//#pragma GCC optimize("Ofast")
//#pragma GCC optimize("unroll-loops")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ull = unsigned long long;
using db = double;
using ld = long double;
template<typename T> using V = vector<T>;
template<typename T> using VV = vector<vector<T>>;
#define fs first
#define sc second
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define eb emplace_back
#define lb lower_bound
#define ub upper_bound
#define all(v) (v).begin(),(v).end()
#define siz(v) (ll)(v).size()
#define rep(i,a,n) for(ll i=a;i<(ll)(n);++i)
#define repr(i,a,n) for(ll i=n-1;(ll)a<=i;--i)
#define ENDL '\n'
typedef pair<int,int> Pi;
typedef pair<ll,ll> PL;
constexpr ll mod = 1000000007; // 998244353;
constexpr ll INF = 1000000099;
constexpr ll LINF = (ll)(1e18 +99);
const ld PI = acos((ld)-1);
const vector<ll> dx={-1,1,0,0},dy={0,0,-1,1};
template<typename T,typename U> inline bool chmin(T& t, const U& u){if(t>u){t=u;return 1;}return 0;}
template<typename T,typename U> inline bool chmax(T& t, const U& u){if(t<u){t=u;return 1;}return 0;}
template<typename T> inline T gcd(T a,T b){return b?gcd(b,a%b):a;}

template<typename T,typename Y> inline T mpow(T a, Y n) {
  T res = 1;
  for(;n;n>>=1) {
    if (n & 1) res = res * a;
    a = a * a;
  }
  return res;
}

template<typename T,typename Y>
ostream& operator<<(ostream& os,const pair<T,Y>& p){
  return os<<"{"<<p.fs<<","<<p.sc<<"}";
}
template<typename T> ostream& operator<<(ostream& os,const V<T>& v){
  os<<"{";
  for(auto e:v)os<<e<<",";
  return os<<"}";
}
template<typename ...Args>
void debug(Args&... args){
  for(auto const& x:{args...}){
    cerr<<x<<' ';
  }
  cerr<<ENDL;
}



signed main(){
  cin.tie(0);cerr.tie(0);ios::sync_with_stdio(false);
  cout<<fixed<<setprecision(20);
  string s;cin>>s;
  int ans=0,cnt=1;
  rep(i,1,3){
    if(s[i]==s[i-1])++cnt;
    else {
      if(s[i]=='S')chmax(ans,cnt);
      cnt=1;
    }
  }
  if(s.back()=='R')chmax(ans,cnt);

  cout<<ans<<ENDL;
}
//! ( . _ . ) ! 
//CHECK overflow,vector_size,what to output?

Measured memory_bytes: 3648
n = int(input())
ab = [list(map(int, input().split())) for _ in range(n - 1)]
mod = 10 ** 9 + 7

MAX = n

fact = [1] * (MAX + 1)
for i in range(1, MAX + 1):
    fact[i] = (fact[i-1] * i) % mod

inv = [1] * (MAX + 1)
for i in range(2, MAX + 1):
    inv[i] = inv[mod % i] * (mod - mod // i) % mod

fact_inv = [1] * (MAX + 1)
for i in range(1, MAX + 1):
    fact_inv[i] = fact_inv[i-1] * inv[i] % mod


adj = [[] for _ in range(n + 1)]
for a, b in ab:
    adj[a].append(b)
    adj[b].append(a)

root = 1
stack = [root]
par = [0] * (n + 1)
order = []
while stack:
    u = stack.pop()
    order.append(u)
    for v in adj[u]:
        if v == par[u]:
            continue
        par[v] = u
        stack.append(v)

size_d = [0] * (n + 1)
dp_d = [1] * (n + 1)
for v in order[::-1]:
    dp_d[v] *= fact[size_d[v]]
    dp_d[v] %= mod
    
    s = size_d[v] + 1
    p = par[v]
    size_d[p] += s
    dp_d[p] *= fact_inv[s] * dp_d[v]
    dp_d[p] %= mod

size_u = [n - 2 - e for e in size_d]
dp_u = [1] * (n + 1)
for v in order[1:]:
    p = par[v]
    x = dp_d[p]
    x *= fact_inv[size_d[p]]
    x *= fact[size_d[v] + 1]
    x *= pow(dp_d[v], mod - 2, mod)
    x *= fact[size_u[v]]
    x *= fact_inv[size_u[p] + 1]
    x *= dp_u[p]
    dp_u[v] = x % mod

for eu, su, ed, sd in zip(dp_u[1:], size_u[1:], dp_d[1:], size_d[1:]):
    su += 1
    ans = eu * ed * fact[su + sd] * fact_inv[su] * fact_inv[sd] % mod
    print(ans)


Measured memory_bytes: 124836
#include <iostream>
#include <string>
#include <set>
#include <algorithm>

using namespace std;

int main(int argc, char* argv[]) {
    set<string> s;
    int n;
    cin >> n;
    for (int i = 0; i < n; ++i) {
        string command;
        string target;
        cin >> command >> target;
        if (command == "insert") {
            s.insert(target);
        }
        else if (command == "find") {
            if (s.find(target) != s.end()) {
                cout << "yes" << endl;
            }
            else {
                cout << "no" << endl;
            }
        }
    }

    return 0;
}



Measured memory_bytes: 32068
#include "iostream"
#include "climits"
#include "list"
#include "queue"
#include "stack"
#include "set"
#include "functional"
#include "algorithm"
#include "string"
#include "map"
#include "unordered_map"
#include "unordered_set"
#include "iomanip"
#include "cmath"
#include "random"
#include "bitset"
#include "cstdio"
#include "numeric"
#include "cassert"

using namespace std;

const long long int MOD = 1000000007;
//const int MOD = 998244353;
//const long long int MOD = 998244353;

int N, M, K, H, W, L, R;
//long long int N, M, K, H, W, L, R;


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

	cin >> N >> M;
	if (M == 1) {
		cout << 0 << endl;
		return 0;
	}
	cout << N - M << endl;
}

Measured memory_bytes: 256
#include <algorithm>
#include <cassert>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <vector>

#include <limits.h>

using namespace std;

typedef long long ll;

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

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

const int INF = INT_MAX / 4;
const int MAX_LEN = 1000;

int calc_min_mp(const int target, const vector<int> &bs) {
    int acc = 0;
    for (auto &b : bs) {
        acc += b;
    }
    return abs(target - acc) + ((int) bs.size() - 1) * 10;
}

string show_vec(const vector<int> &bs) {
    string s;
    s += "{";
    for (auto &b : bs) {
        s += to_string(b) + ", ";
    }
    s += "}";
    return s;
}

int pow(const int base, const int x) {
    int ans = 1;
    for (int i = 0; i < x; i++) {
        ans *= base;
    }
    return ans;
}

int main(void) {
    int N, A, B, C;
    cin >> N >> A >> B >> C;

    vector<int> bs(N);
    for (int i = 0; i < N; i++) {
        cin >> bs[i];
    }

    int ans = INF;
    int max_i = pow(4, N);
    for (int i = 0; i < max_i; i++) {
        int x = i;
        vector<int> bs1, bs2, bs3;
        for (int j = 0; j < N; j++) {
            int y = x % 4;
            if (y == 0) {
                bs1.push_back(bs[j]);
            } else if (y == 1) {
                bs2.push_back(bs[j]);
            } else if (y == 2) {
                bs3.push_back(bs[j]);
            }
            x /= 4;
        }

        int cost_a = (bs1.size() > 0) ? calc_min_mp(A, bs1) : INF;
        int cost_b = (bs2.size() > 0) ? calc_min_mp(B, bs2) : INF;
        int cost_c = (bs3.size() > 0) ? calc_min_mp(C, bs3) : INF;
        // printf("---\n");
        // cout << "[A] vec: " + show_vec(bs1) + ", cost: " << cost_a << endl;
        // cout << "[B] vec: " + show_vec(bs2) + ", cost: " << cost_b << endl;
        // cout << "[C] vec: " + show_vec(bs3) + ", cost: " << cost_c << endl;
        // cout << "sum: " << cost_a + cost_b + cost_c << endl;
        chmin(ans, cost_a + cost_b + cost_c);
    }

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 384
from numba import njit
import numpy as np

@njit
def main(n,x,a):
    a_ori=a.copy()
    ans=np.sum(a)
    for i in range(1,n):
        tmp=x*i
        for j in range(n):
            a[j]=min(a[j],a_ori[j-i])
            tmp+=a[j]
        ans=min(ans,tmp)
    print(ans)

if __name__=='__main__':
    n,x=map(int,input().split())
    a=np.array(list(map(int,input().split())),np.int32)
    main(n,x,a)

Measured memory_bytes: 113124
// https://atcoder.jp/contests/abc156/tasks/abc156_c

#include <bits/stdc++.h>

using namespace std;

int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n;
    cin >> n;
    vector<int> x(n);
    for (int i = 0; i < n; i++)
        cin >> x[i];

    long ans = (100 * 100) * 100 + 10;
    for (int p = 1; p < 100; p++)
    {
        int s = 0;
        for (int i = 0; i < n; i++)
            s += (x[i] - p) * (x[i] - p);

        if (ans > s)
            ans = s;
    }
    cout << ans << '\n';
    return 0;
}


Measured memory_bytes: 3620
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
using P = pair<int,int>;
const int INF = 1001001001;
const int di[] = {-1,0,1,0};
const int dj[] = {0,-1,0,1};
// const int INF = int(1e9);

int main(){
    int h,w,ch,cw,dh,dw;
    cin >> h >> w >> ch >> cw >> dh >> dw;
    ch--;cw--;dh--;dw--;
    vector<string> s(h);
    vector<vector<int>> dist(h,vector<int>(w,INF));
    rep(i,h) cin >> s.at(i);
    deque<P> deq;
    dist.at(ch).at(cw) = 0;
    deq.emplace_back(ch,cw);
    while(!deq.empty()){
        auto p = deq.front();
        int i = p.first;
        int j = p.second;
        int d = dist.at(i).at(j);
        deq.pop_front();
        rep(k,4){
            int ki = i + di[k];
            int kj = j + dj[k];
            if(ki < 0 || ki >= h || kj < 0 || kj >= w) continue;
            if(s.at(ki).at(kj) == '#') continue;
            if(dist.at(ki).at(kj) <= d) continue;
            dist.at(ki).at(kj) = d;
            deq.emplace_front(ki,kj);
        }
        for(int l = -2;l <= 2;l++){
            for(int m = -2;m <= 2;m++){
                int li = l + i;int mj = m + j;
                if(li < 0 || li >= h || mj < 0 || mj >= w) continue;
                if(s.at(li).at(mj) == '#') continue;
                if(dist.at(li).at(mj) <= d + 1) continue;
                dist.at(li).at(mj) = d + 1;
                // cout << "(" << li << "," << mj << ") = " << dist.at(li).at(mj) << endl;
                deq.emplace_back(li,mj);
            }
        }
        // cout <<  dist.at(dh).at(dw) << endl;
    }
    int ans = dist.at(dh).at(dw) == INF ? -1 : dist.at(dh).at(dw);
    // rep(i,h)rep(j,w) cout << dist.at(i).at(j) << endl;
    cout << ans << endl; 
}

Measured memory_bytes: 9492
N, M = map(int, input().split())

A = [-1] * N
ckeck = False
for _ in range(M):
    s, c = map(int, input().split())
    if A[s-1] == -1:
        A[s-1] = c
    elif A[s-1] != c:
        ckeck = True

if ckeck or (N > 1 and A[0] == 0):
    print(-1)
    exit(0)

ans = A[0] if A[0] != -1 else 1
if N == 1 and A[0] == -1:
    ans = 0

for i in range(1, N):
    if A[i] == -1:
        ans *= 10
        continue
    ans = ans * 10 + A[i]

print(ans)


Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<ll> vll;
#define all(x) (x).begin(), (x).end()
#define endl '\n'
ll inf = LLONG_MAX;
long double pi = M_PI;
void Yes() {cout << "Yes" << endl;}
void No() {cout << "No" << endl;}
void YES() {cout << "YES" << endl;}
void NO() {cout << "NO" << endl;}

bool is_ok(ll &n, ll &k, vll &a, vll &f, ll &m) {
  ll ans = 0;
  for (ll i = 0; i < n; i++) {
    ll score = a[i] * f[n - 1 - i];
    ll train = ceil((double)(score - m) / f[n - 1 - i]);
    ans += max(0LL, train);
  }
  return (ans <= k);
}

//二分探索
//main関数で呼び出す前に，min, maxの一方が条件を満たし他方が満たさないことを確認すること
ll binary_search(ll &min, ll &max, ll &n, ll &k, vll &a, vll &f) {
  if (min + 1 == max) { //解近傍の処理
    if (is_ok(n, k, a, f, min)) return min;
    return max;
  }

  ll med = (min + max) / 2;
  if (is_ok(n, k, a, f, med)) return binary_search(min, med, n, k, a, f);
  else return binary_search(med, max, n, k, a, f);
}

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

  vll a(n), f(n);
  for (ll i = 0; i < n; i++) cin >> a[i];
  for (ll i = 0; i < n; i++) cin >> f[i];
  sort(all(a));
  sort(all(f));

  ll min = 0, max = 1e12;
  if (is_ok(n, k, a, f, min)) {
    cout << min << endl;
    return 0;
  }
  cout << binary_search(min, max, n, k, a, f) << endl;
}

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

#define FOR(i,b,e) for(int i=(b); i <= (e); ++i)
#define FORD(i,b,e) for(int i=(b); i >= (e); --i)
#define SIZE(c) (int) (c).size()
#define FORE(i,c) FOR(i,0,SIZE(c)-1)
#define FORDE(i,c) FORD(i,SIZE(c)-1,0)

#define pb push_back
#define mp make_pair
#define st first
#define nd second


using namespace std;

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

typedef vector <int> VI;
typedef vector <bool> VB;
typedef vector <pii> VP;
typedef vector <ll> VL;
typedef vector <pll> VPL;

typedef vector <VI> VVI;
typedef vector <VL> VVL;
typedef vector <VB> VVB;
typedef vector <VP> VVP;

const int MOD = 1000000007;
const int INF = 1000000001;
const ll LINF = 1000000000000000001LL;


/*************************************************************************/

int main() {
    ios_base::sync_with_stdio(0);
    
    int k;
    cin >> k;
    
    VI a(k);
    FOR(i,0,k-1) cin >> a[i];
    
    ll l = 2, r = 2;
    FORD(i,k-1,0) {
        r = r / a[i] * a[i];
        l = (l + a[i] - 1) / a[i] * a[i];
        
        if (l > r) {
            cout << -1;
            return 0;
        }
        
        r += a[i] - 1;
    }
    
    cout << l << ' ' << r;

    return 0;
}

/*************************************************************************/


Measured memory_bytes: 640
import java.util.Scanner;

class Main{
    public static void main(String args[]){
        Scanner sc = new Scanner(System.in);

        int n = sc.nextInt();

        int x = 1;

        boolean th = false;

        for(int i = 1; i <= n; i++){
            x = i;
            if(i % 3 == 0){
                System.out.print(" ");
                System.out.print(i);
                continue;
            }

            while(x > 0 && th == false){
                if(x % 10 == 3){
                    th = true;
                }
                x /= 10;
            }
            if(th == true){
                th = false;
                System.out.print(" ");
                System.out.print(i);
            }
        }
        System.out.println();
    }
}


Measured memory_bytes: 32732
#include<iostream>
#include<string>
#include<map>
using namespace std;
#define int long long
#define rep(i,n) for(int i = 0; i < n; i++)
#define INF (long long)(1e18)
#define MOD (int)(1e9+7)
#define MAX_N 103
#define MAX_V 10
#define MAX_M 101
#define yn(f) (f?"Yes":"No")
#define YN(f) (f?"YES":"NO")
#define pro "はいプロ　世界一○○が上手　○○界のtourist　○○時代の終焉を告げる者　実質○○　○○するために生まれてきた男"

struct Cube{
	string co[10];
};


Cube huga(Cube b){
	Cube a = b;
	string temp = a.co[1];
	a.co[1] = a.co[5];
	a.co[5] = a.co[6];
	a.co[6] = a.co[2]; 
	a.co[2] = temp;
	return a;
}

Cube hoge(Cube b){
	Cube a = b;
	string temp = a.co[1];
	a.co[1] = a.co[4];
	a.co[4] = a.co[6];
	a.co[6] = a.co[3];
	a.co[3] = temp;
	return a;
}

Cube hugahuga(Cube b){
	Cube a = b;
	string temp = a.co[3];
	a.co[3] = a.co[5];
	a.co[5] = a.co[4];
	a.co[4] = a.co[2]; 
	a.co[2] = temp;
	return a;
}

Cube foo(Cube c, int b){
	Cube a = c;
	switch(b){
	case 1:
		break;
	case 2:
		a=huga(a);a=huga(a);a=huga(a);
		break;
	case 3:
		a=hoge(a); a=hoge(a);a=hoge(a);
		break;
	case 4:
		a=hoge(a);
		break;
	case 5:
		a=huga(a);
		break;
	case 6:
		a=huga(a);a=huga(a);
		break;
	}
	return a;
}

int cou(Cube a,Cube b){
	int count = 0;
	for(int i = 1; i <= 6; i++){
		if(a.co[i] != b.co[i])count++;
	}
	return count;
}

int ans(int cc[10][10],int n,int used[],int k){
	int count = 0;
	for(int i = 1; i <= n; i++) count+=cc[k][i];
	return count;
}

int ha(Cube a[], int n){//cout<<" a "<<endl;
	int ans = 0;
	for(int i = 1; i <= 6; i++){
		int ma = 0;
		map<string,int> m;
		for(int j = 1; j <= n; j++){
			ma = max(ma, ++m[a[j].co[i]]);
		}
		ans += n-ma;
	}
	
	return ans;
}

int so(Cube a[], int n, int k){//cout<<k<<" "<<n<<endl;
	Cube tt = a[k];
	int ans = INF;
	//if(n+1== k) return ha(a,n);
	for(int i = 1; i <= 6; i++){
		Cube temp = foo(tt,i);
		for(int j = 1; j <= 4;j++){
			temp = hugahuga(temp);
			a[k] = temp;
			if(k<n-1)ans = min(ans,so(a,n,k+1));
			else ans = min(ans,ha(a,n));
		}
	}
	return ans;
}

signed main(){
	while(true){
		int n;
		Cube s[5];
		cin>>n;
		if(!n)break;

		for(int i = 1; i <= n; i++)
			for(int j = 1; j <= 6; j++)
				cin>>s[i].co[j];
	
		cout<<so(s,n,1)<<endl;
	}

	return 0;
}


Measured memory_bytes: 3028
#include <bits/stdc++.h>
using namespace std;
using ll = long long int;
using ull = unsigned long long int;

#define MATHPI acos(-1)

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

using Mat = vector<vector<ll>>;
using Column = vector<ll>;

int main(int argc, char const *argv[])
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);

    string S;
    cin>>S;
    if (S=="AAA" || S=="BBB") {
        cout <<"No"<<"\n";
    } else {
        cout <<"Yes"<<"\n";
    }

    return 0;
}

Measured memory_bytes: 256
n = int(input())
a = list(map(int,input().split()))
b = []
v = 0
for i in range(n):
    if a[i] < 3200:
        b.append(int(a[i]/400))
    else:
        v += 1
c = set(b)
mi = max(1,len(c))
ma = len(c)+v
print(mi,ma)

Measured memory_bytes: 3064
#include <iostream>
#include <string>
#include <array>
#include <vector>
#include <queue>
#include <stack>
#include <list>
#include <set>
#include <map>
#include <algorithm>
#include <cmath>
#include <iomanip>

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

typedef long long ll;
typedef unsigned long long ull;
typedef unsigned int uint;

using namespace std;

#ifdef INPUT
#include <sstream>
stringstream input(R"(
81 58
)");
#define cin input
#endif

int main()
{
    char dp[2][8096] = {};
    int sum[2] = {};

    string s;
    int x, y;
	cin >> s >> x >> y;

    dp[0][0] = dp[1][0] = 1;
    size_t i = s.find('T');
    if (i == string::npos)
        i = s.size();
    x -= i;
    size_t p = i;
    int cur = 0;
    while (p != s.size())
    {
        i = s.find('T', i + 1);
        if (i == string::npos)
            i = s.size();
        ++cur;
        cur %= 2;
        int d = i - p - 1;
        sum[cur] += d;
        for (int i = 0; i < min(sum[cur] + 1, 8096 - d); ++i)
            dp[cur][i + d] |= dp[cur][i];
        p = i;
    }
    
	cout << (abs(x) <= sum[0] && (sum[0] % 2 == abs(x) % 2) && dp[0][(x + sum[0]) / 2] && abs(y) <= sum[1] && (sum[1] % 2 == abs(y) % 2) && dp[1][(y + sum[1]) / 2] ? "Yes" : "No") << endl;

	return 0;
}


Measured memory_bytes: 256
##agc034_a
N,A,B,C,D = map(int, input().split()) #A→C、B→D #4≤N≤200,000
S = [0] + list(input())

#すれ違うには . の3連続が必要
#すれ違わなくても、#が2連続であるとアウト

#すれ違いが必要かを判定する
#  A<B
#  A<C
#  B<D
#を利用すると下記の3パターンしかない。
if A < B < D < C:
    need_passing = True
elif (A < B < C < D) or (A < C < B < D):
    need_passing = False

#下記のように考える
#すれ違いが必要
    #Yes
        #すれ違い可能点(. . .)を列挙
        #A/B→すれ違い可能点へ行ける = 左記の区間に # # な並びがない
            #すれ違い可能点→C/Dへ行ける? = 左記の区間に # # な並びがない
    #No
        #A→CとB→Dで通行可能 = 左記の区間に # # な並びがない

passing_point_set = set() #すれ違い場所の始点のset
imos_stop = list() # "#"が2連続している場所で増加する。
imos_stop.append(0)

for i in range(1,N-1):
    if S[i] == S[i+1] == "#":
        imos_stop.append(imos_stop[-1] + 1)
    else:
        imos_stop.append(imos_stop[-1])

    if S[i] == S[i+1] == S[i+2] == ".":
        passing_point_set.add(i)

i = N-1
if S[i] == S[i+1] == "#":
    imos_stop.append(imos_stop[-1] + 1)
else:
    imos_stop.append(imos_stop[-1])
#i = N
#右側はない。
imos_stop.append(imos_stop[-1]) #   .##.

#print(imos_stop)
#print(passing_point_set)

def is_reachable(start,goal):
    if imos_stop[start] == imos_stop[goal] and start <= goal: #右に1か2マスにジャンプさせる ∴右方向にしか進めない
        return True
    else:
        return False

if need_passing == True: #A < B < D < C が成立している
    for passing_point in passing_point_set:
        if ((is_reachable(A,passing_point) == True and is_reachable(passing_point,C) == True and is_reachable(B,passing_point) == True and is_reachable(passing_point,D) == True and D != passing_point) or
            (B-1 in passing_point_set and is_reachable(A,C) == True and is_reachable(B,D) == True)):
            #passing pointの範囲内にDがある場合、passingできない場合がある
            #ex.   A#..D#  …これはOK。A#.BD#.  として、追い抜かせてからB→D
            #ex.   A#.D.# …これはOK。ただし、.D.がpassing_pointになる
            #ex.   A#D..#  …NG
                #↓のパターンが考察不足だった
                #  ##AB.#D..#C#  …start <= goal条件により、追い越し不可扱いになるが実際はできる
                #  ##A.B#D..#C#  …これはNG
                #  ##A.B#.D.#C#  …これはOK。.D.がpassing_pointになる
                #  ##A.B.#D..#C# …これはOK
            
            print("Yes")
            break
    else:
        print("No")
else:
    if is_reachable(A,C) == True and is_reachable(B,D) == True:
        print("Yes")
    else:
        print("No")
        
        


Measured memory_bytes: 12192
#include <stdio.h>
int main(){
	
	int m, f, r, som;
	
	while(1){	
	scanf("%d", &m);
	scanf("%d", &f);
	scanf("%d", &r);
	
	som = m + f;
	
	if(m == -1 && f == -1 && r == -1)
		return 0;
	
	if(m == -1 || f == -1)
		printf("F\n");
	else if(som >= 80)
		printf("A\n");
	else if(80 > som && som >= 65)
		printf("B\n");
	else if(65 > som && som >= 50)
		printf("C\n");
	else if(50 > som && som >= 30){
		if(r >= 50)
			printf("C\n");
		else
			printf("D\n");
	}else if(r >= 50)
		printf("C\n");
	else if(30 > som)
		printf("F\n");
	}

  return 0;
}

Measured memory_bytes: 1012
#include <cstdio>
#include <climits>
#include <cstdlib>
#include <cmath>
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <list>
#include <set>
#include <bitset>
#include <iterator>
#define loop(i, a, b) for(int i = (int)(a); i < (int)(b); i++)
#define rep(i, n) for(long long i = 0; i < (long long)(n); i++)
#define debug(x)  cout << #x << " = " << (x) << endl;

using namespace std;
using LL = long long int;
using ULL = unsigned long long;

LL fact(LL x) {
    LL ret = 1;
    if (x <= 0) {
        return 1;
    }
    loop(i, 1, x + 1) {
        ret *= i;
    }
    return ret;
}
int main() {
    int n;
    string s;
    cin >> s;
    n = stoi(s);

    reverse(s.begin(), s.end());

    LL ans = 0;
    for (int i = s.length(); i >= 1; i--) {
        if (i % 2 == 1) {
            if (i == s.length()) {
                int digit = s[i - 1] - '0';
                if (i == 1) {
                    ans += digit;
                    continue;
                }
                int x =  (n % (int)pow(10, i - 1));
                int y = (digit - 1) * pow(10, i - 1);
                ans += x + 1 + y;
            } else {
                if (i == 1) {
                    ans += 9;
                    continue;
                }
                ans += 9 * pow(10, i - 1);
            }
        } else {
            continue;
        }
    }
    cout << ans << endl;
    return 0;
}


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

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

int main() {
  int num,k;
  int Min = 1;
  int tmp = 1;
  cin >> num >> k;
  
  for(int i = 0; i < num; i++){
    tmp = Min;
    Min = min(tmp * 2, tmp + k);
  }
  
  cout << Min;
}


Measured memory_bytes: 256
a = 'ABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZ'
d = {'A':0,'B':1,'C':2,'D':3,'E':4,'F':5,'G':6,'H':7,'I':8,'J':9,'K':10,'L':11,'M':12,'N':13,'O':14,'P':15,'Q':16,'R':17,'S':18,'T':19,'U':20,'V':21,'W':22,'X':23,'Y':24,'Z':25}
n = int(input())
s = input()

for i in range(len(s)):
  print(a[d[s[i]] + n], end='')

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

using namespace std;

long long n,q,cnt,mx,a,b,m,temp,c,k;
long long arr[100101];
long long table[100101];
string str;
long long N,K;

long long solve(int i){
    
    if(i>=N)return 0;

    if(table[i]!=-1) return table[i];
    table[i]=INT_MAX;
    for(int j=1;j<=k;j++){
        table[i] =min( abs(arr[i]-arr[i+j])+solve(i+j) ,table[i]);
    }
    return table[i];
}

int main()
{
    cin>>n>>k;
    N=n;
    K=k;
    for(int i=0;i<n;i++){
        table[i]=-1;
    }
    
    for(int i=0;i<n;i++){
        cin>>arr[i];
    }
    for(int i=n;i<=n+k;i++){
        arr[i]=arr[n-1];
    }
    
    cout<<solve(0);
    
    return 0;
}


Measured memory_bytes: 6528
#include <iostream>
#include <cmath>
#include <string>
#include <vector>
#include <algorithm>
#include <list>
using namespace std;
typedef long long ll;
typedef vector<pair<int, char> > P;

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

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

const int p=998244353;
int fac[500005],ifac[500005],inv[500005];
int N,M;
int qpow(int a,int k){
	int ans=1;
	while(k){
		if(k&1) ans=1LL*ans*a%p;
		a=1LL*a*a%p;
		k>>=1;
	}
	return ans;
}
int C(int n,int m){if(n<m) return 0;return 1LL*fac[n]*ifac[m]%p*ifac[n-m]%p;}

int main(){
	scanf("%d%d",&N,&M);
	fac[0]=fac[1]=ifac[0]=ifac[1]=inv[1]=1;
	for(int i=2;i<=500000;i++)
		inv[i]=1LL*(p-p/i)*inv[p%i]%p,
		fac[i]=1LL*fac[i-1]*i%p,
		ifac[i]=1LL*ifac[i-1]*inv[i]%p;
	int ans=0; 
	for(int i=0;i<=N&&i<=M;i++){
		int tmp=1LL*C(N,i)*C(M,i)%p*qpow(N+1,M-i)%p*qpow(M+1,N-i)%p*fac[i]%p;
		if(i&1) ans=(ans-tmp+p)%p;
		else ans=(ans+tmp)%p;
	}
	printf("%d\n",ans);
}

Measured memory_bytes: 9676
#include <iostream>
#include <algorithm>
#include <cstdio>
#include <cstdlib>
#include <sstream>
#include <cstring>
#include <string>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <numeric>
#include <functional>
#include <array>
#include <cmath>

#define rep2(x,fr,to) for(int (x)=(fr);(x)<(to);(x)++)
#define rep(x,to) for(int (x)=0;(x)<(to);(x)++)
#define repr(x,fr,to) for(int (x)=(fr);(x)>=(to);(x)--)
#define all(c) (c).begin(),(c).end()
#define sz(v) (int)(v).size()

using namespace std;
typedef long long ll; typedef vector<int> VI; typedef pair<int,int> pii;
const int mod = (int)1e9 + 7;

int main()
{
	
	//cin.tie(0); ios_base::sync_with_stdio(false);
	string s; cin >>s;
	int j=0, n=sz(s), cnt=0;
	rep(i, n){
		if(s[i]=='S'){
			if(j<i+1) j=i+1;
			for(;j<n;j++) if(s[j]=='T'){ cnt++; j++; break;}
		}
	}
	cout << n - cnt * 2 << endl;
	return 0;
}


Measured memory_bytes: 640
from collections import deque
from bisect import bisect_left

N = int(input())
A = [int(input()) for _ in range(N)]

t = deque([A[0]])
for a in A[1:]:
    if a <= t[0]:
        t.appendleft(a)
    else:
        t[bisect_left(t, a) - 1] = a
print(len(t))


Measured memory_bytes: 8828
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define repr(i,n) for(int i = (int)(n); i >= 0; i--)
#define all(v) v.begin(),v.end()
typedef long long ll;

int gcd(int a, int b){
    int r,temp;
    if (a < b){
        temp = a;
        a = b;
        b = temp;
    }
    while ( (r = a % b) != 0){
        a = b;
        b = r;
    }
    return b;
}

int main(){
    int N,X;
    cin >> N >> X;
    vector<int> vec(N);
    rep(i,N){
        cin >> vec[i];
    }
    vector<int> vect(N);
    rep(i,N){
        vect[i] = max(vec[i] - X, X - vec[i]);
    }
    int ans;
    if (N == 1){
        ans = vect[0];
    }
    else{
        ans = gcd(vect[0],vect[1]);
        rep(i,N - 2){
            ans = gcd(ans, vect[i + 2]);
        }
    }
    cout << ans << endl;
}


Measured memory_bytes: 1024
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        try (Scanner in = new Scanner(System.in)) {
            String S = in.next();

            int N = S.length();

            boolean[] isATCG = new boolean[N];
            for (int i = 0; i < N; i++) {
                char c = S.charAt(i);
                isATCG[i] = c == 'A' || c == 'T' || c == 'C' || c == 'G';
            }

            int max = 0;
            int count = 0;
            for (int i = 0; i < N; i++) {
                if (isATCG[i]) {
                    count++;
                    max = Math.max(max, count);
                } else {
                    count = 0;
                }
            }
            System.out.println(max);
        }
    }
}


Measured memory_bytes: 26940
package main

import (
	"bufio"
	"fmt"
	"io"
	"os"
	"strconv"
)

const (
	initialBufSize = 100000
	maxBufSize     = 1000000
)

var sc *bufio.Scanner

func initScanner(r io.Reader) *bufio.Scanner {
	buf := make([]byte, initialBufSize)

	sc := bufio.NewScanner(r)
	sc.Buffer(buf, maxBufSize)
	sc.Split(bufio.ScanWords) // bufio.ScanLines
	return sc
}

func main() {
	sc = initScanner(os.Stdin)
	fmt.Println(resolve(parseProblem()))
}

func parseProblem() (int, []int) {
	n := scanInt(sc)
	hs := nextIntSlice(sc, n)
	return n, hs
}

func nextInt(sc *bufio.Scanner) int {
	sc.Scan()
	a, _ := strconv.Atoi(sc.Text())
	return int(a)
}

func nextString(sc *bufio.Scanner) string {
	sc.Scan()
	return sc.Text()
}

func nextIntSlice(sc *bufio.Scanner, n int) (a []int) {

	a = make([]int, n)
	for i := 0; i < n; i++ {
		a[i] = nextInt(sc)
	}
	return a
}

func resolve(n int, hs []int) int {
	max := 0
	steps := 0
	for i := 1; i < len(hs); i++ {
		if hs[i-1] >= hs[i] {
			steps++
		} else {
			steps = 0
		}
		if max < steps {
			max = steps
		}
	}
	return max
}

// snip-scan-funcs
func scanInt(sc *bufio.Scanner) int {
	sc.Scan()
	i, _ := strconv.Atoi(sc.Text())
	return int(i)
}


Measured memory_bytes: 4296
import java.io.*;
public class Main {
	public static void main(String[] args) throws IOException{
		BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
		String line = reader.readLine();
		String[] str1 = line.split(" ", -1);
		int a = Integer.parseInt(str1[0]);
		int b = Integer.parseInt(str1[1]);
		int d = a / b;
		int r = a % b;
		double f = ((double)a / (double)b);
		System.out.println(d);
		System.out.println(r);
		System.out.printf("%.5f",f);
		System.out.println();
	}
}

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

#define DEBUG(x) 			   cout << '>' << #x << ':' << x << endl;
#define D(x)        		   cerr << __LINE__ << ": " << #x << " = " << (x) << '\n'
#define DD(x,y)     		   cerr << __LINE__ << ": " << #x << " = " << x << "   " << #y << " = " << y << '\n'
#define DDD(x,y,z)  		   cerr << __LINE__ << ": " << #x << " = " << x << "   " << #y << " = " << y << "   " << #z << " = " << z << '\n'
#define DBG         		   cerr << __LINE__ << ": Hi" << '\n'
#define fresh                  {ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);}
#define read                   freopen("in.txt","rt",stdin)
#define write                  freopen("out.txt","wt",stdout)
#define PI                     3.1415926535897932384626433832795
#define mems(ds_name,val)      memset(ds_name,val,sizeof(ds_name))
#define ll					   long long



int main()
{
//    write;
    fresh;
//    read;

    int n,k;
    cin>>n>>k;
    int arr[n+5];
    for(int i=0;i<n;i++){
        cin>>arr[i];
    }
    sort(arr,arr+n);
    int minm=INT_MAX;
    for(int i=0;i<n-k+1;i++){
            int j=i+k-1;
            minm=min(minm,arr[j]-arr[i]);
    }
    cout<<minm<<endl;
}



Measured memory_bytes: 640
#include <iostream>
#include <vector>
#include <string>
 
using namespace std;
 
int main() {
  int H, W;
  cin >> H >> W;

  int dist[10][10];
  for(int i = 0; i < 10; i++) {
    for(int j = 0; j < 10; j++) {
      cin >> dist[i][j];
    }
  }

  for(int k = 0; k < 10; k++) {
    for(int i = 0; i < 10; i++) {
      for(int j = 0; j < 10; j++) {
        dist[i][j] = min(dist[i][j], dist[i][k] + dist[k][j]);
      }
    }
  }

  int ans = 0;
  for(int i = 0; i < H; i++) {
    for(int j = 0; j < W; j++) {
      int num = 0;
      cin >> num;
      if (num == -1) continue;
      ans += dist[num][1];
    }
  }

  cout << ans << endl;

  return 0;
}

Measured memory_bytes: 256
N = gets.to_i

count = 0
(1..N).each do |i|
  if i.odd? then
    count_yakusu = 0
    (1..i).each do |j|
      if i.modulo(j) == 0 then
        count_yakusu += 1
      end
    end
    if count_yakusu == 8 then
      count += 1
    end
  end
end

puts count

Measured memory_bytes: 1788
#include <iostream>
#include <vector>

#define REP(i, a, b) for ( int i = (a); i < (b); i++ )
#define REVREP(i, a, b) for ( int i = (a); i >= (b); i--)
#define DEBUG_INT(var) printf("the value of "#var" is %d\n", var)
#define PRINT_ARRAY(name, i) printf("the value of "#name"[%d] is %d\n", (i), name[(i)])
#define DEBUG_ARRAY(name, begin, end) REP(i, begin, end) PRINT_ARRAY(name, i)

using namespace std;

typedef long long ll;

int N;
vector<int> v; //N以下の6のべき乗と9のべき乗
int dp[100005]; //i円を引き出す場合の最小枚数

int solve() {
	dp[0] = 0;

	REP(i, 1, N+1) {
		dp[i] = dp[i-1] + 1; //1円引き出した場合
		REP(j, 0, v.size()) {
			// 
			if (i - v[j] >= 0) dp[i] = min(dp[i], dp[i - v[j]] + 1);
		}
	}
	return dp[N];
}

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

    for (int i = 6; i <= N; i *= 6) v.push_back(i);
    for (int i = 9; i <= N; i *= 9) v.push_back(i);

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

	return 0;
}


Measured memory_bytes: 640
private const val YES = "Yes"
private const val NO = "No"

fun main(args: Array<String>) {
    val N = readLine()!!.toInt()
    val a = readLine()!!.split(" ").map{it.toLong()}.sorted()

    if (a.last() - a.first() > 1) {
        println(NO)
    } else if (a.first() == a.last()) {
        println(if (a.first() * 2 <= N || a.first() == N - 1L) YES else NO)
    } else {
        val m = a.indexOfFirst { it == a.last() }.toLong()
        val k = a.last()
        val l = k - m

        if (m > a.first()) {
            println(NO)
        } else if (2 * l > N - m) {
            println(NO)
        } else {
            println(YES)
        }
    }
}


Measured memory_bytes: 53824
#include<bits/stdc++.h>
using namespace std;
#define rep(i,a,b) for(int i=a;i<=b;i++)
#define per(i,a,b) for(int i=a;i>=b;i--)
#define clr(a,x) memset(a,x,sizeof(a))
#define SZ(x) ((int)(x).size())
#define lson rt<<1
#define rson rt<<1|1
#define pb push_back
#define fi first
#define se second
#define what_is(x) cerr<<#x<<" "<<x<<endl;
typedef long long ll;
typedef pair<int,int> pii;
typedef vector<int> vi;
template <typename T>
inline void _read(T& x){
    cin>>x;
}
void R(){}
template <typename T,typename... U>
void R(T&head,U&... tail){
    _read(head);
    R(tail...);
}

template <typename T>
inline void _write(const T& x){
    cout<<x<<' ';
}
void W(){cout<<endl;}
template <typename T,typename... U>
void W(const T&head,const U&... tail){
    _write(head);
    W(tail...);
}

void go();
int main(){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);
    go();
    return 0;
}
/****************ackun*********************/
ll fun(ll xx){
    ll x=xx;
    if(x&1){
        x+=1;
        x/=2;
        if(x&1){
            return 1;
        }else{
            return 0;
        }
    }else{
        x/=2;
        if(x&1){
            return 1^xx;
        }else{
            return 0^xx;
        }
    }
}
void go(){
    ll x,y;
    R(x,y);
    if(x==0){
        W(fun(y));
    }else{
        W(fun(y)^fun(x-1));
    }
}


Measured memory_bytes: 256
x = input()
a = int(x[0])
b = int(x[1])
c = int(x[2])
d = int(x[3])
if a + b + c + d == 7:
  print(str(a) + "+" + str(b) + "+" + str(c) + "+" + str(d) + "=7")
elif a + b + c - d == 7:
  print(str(a) + "+" + str(b) + "+" + str(c) + "-" + str(d) + "=7")
elif a + b - c + d == 7:
  print(str(a) + "+" + str(b) + "-" + str(c) + "+" + str(d) + "=7")
elif a + b - c - d == 7:
  print(str(a) + "+" + str(b) + "-" + str(c) + "-" + str(d) + "=7")
elif a - b + c + d == 7:
  print(str(a) + "-" + str(b) + "+" + str(c) + "+" + str(d) + "=7")
elif a - b + c - d == 7:
  print(str(a) + "-" + str(b) + "+" + str(c) + "-" + str(d) + "=7")
elif a - b - c + d == 7:
  print(str(a) + "-" + str(b) + "-" + str(c) + "+" + str(d) + "=7")
elif a - b - c - d == 7:
  print(str(a) + "-" + str(b) + "-" + str(c) + "-" + str(d) + "=7")


Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
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)++)
#define ALL(obj) (obj).begin(), (obj).end()
#define rALL(obj) (obj).rbegin(), (obj).rend()
const ll INF = 1LL<<60;
const ll MOD = 1e9+7;


int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    ll n,k;cin>>n>>k;
    vector<ll> p(n);rep(i,n)cin>>p[i];
    sort(ALL(p));
    ll ans = 0;
    rep(i,k){
        ans += p[i];
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 3652
n = int(input())
rootn = int(n**0.5) +1
ans = [0] * (n+1)
for x in range(1, rootn):
  for y in range(1, rootn):
    for z in range(1, rootn):
      cur = x**2 + y**2 + z**2 + x*y + y*z + z*x
      if cur <= n:
        ans[cur] += 1
print('\n'.join(map(str, ans[1:])))

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

int main() {
    int N;
    long max, min, tmp;

    cin >> N;
    cin >> max;
    min = max;
    
    for (int i=1; i<N; i++) {
	    cin >> tmp;
	    if(tmp > max) {
	        max = tmp;
	    }
	    if(tmp < min) {
	        min = tmp;
	    }
    }

    cout << max-min << endl;

    return 0;
}

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

#define REP(i, x) REPI(i, 0, x)
#define REPI(i, a, b) for (int i = int(a); i < int(b); ++i)
#define ALL(x) (x).begin(), (x).end()

typedef long long ll;
using namespace std;

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

  string S;
  cin >> S;
  int s = -1;
  int l = (int)S.length();

  int ans = 0;
  REP(i, l) {
    if (S.at(i) == 'A' || S.at(i) == 'T' || S.at(i) == 'G' || S.at(i) == 'C') {
      if (s == -1) {
        s = i;
      }
    } else {
      if (s != -1) {
        ans = max(ans, i - s);
        s = -1;
      }
    }
  }

  if (s != -1) {
    ans = max(ans, l - s);
  }

  cout << ans << endl;

  return 0;
}


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

using namespace std;

typedef long long ll;
typedef long double ld;

const int MX = 1007;
const int MAXVAL = 5007;
const int INF = 50 * 1000 + 7;
vector<int> g[MX];
int x[MX];

int solve(vector<pair<int, int> > a, int x) {
    bitset<MAXVAL> bs;
    bs[0] = 1;
    for (auto &e : a) {
        bs = (bs << e.first) | (bs << e.second);
    }
    int mx = -1;
    for (int i = 0; i <= x; i++) {
        if (bs[i]) mx = i;
    }
    if (mx == -1) return INF;
    int res = -mx;
    for (auto &e : a) {
        res += e.first + e.second;
    }
    return min(INF, res);
}

int dp[MX];

void dfs(int v, int p = -1) {
    vector<pair<int, int> > a;
    for (int to : g[v]) {
        if (to == p) continue;
        dfs(to, v);
        a.push_back(make_pair(x[to], dp[to]));
    }
    dp[v] = solve(a, x[v]);
}

int main() {
#ifdef LOCAL
    freopen("input.txt", "r", stdin);
#endif
    int n;
    cin >> n;
    for (int i = 2; i <= n; i++) {
        int p;
        scanf("%d", &p);
        g[p].push_back(i);
        g[i].push_back(p);
    }
    for (int i = 1; i <= n; i++) {
        scanf("%d", &x[i]);
    }
    dfs(1);
    if (dp[1] < INF) {
        printf("POSSIBLE\n");
    } else {
        printf("IMPOSSIBLE\n");
    }
}



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

using namespace std;
 
#define MD 1000000007
typedef long long int ll;

int main(){
    int ii=1;
    vector<int> data9;
    while(ii<=100000){
        ii*=9;
        data9.push_back(ii);
    }
    int jj=1;
    vector<int> data6;
    while(jj<=100000){
        jj*=6;
        data6.push_back(jj);
    }
    int n;
    cin>>n;
    vector<int> dp(n+1,0);
    for(int i=1;i<=n;i++){
        int tmp=i-1;
        for(int j=0;j<data9.size();j++){
            if(i-data9[j]>=0){
                tmp=min(tmp,dp[i-data9[j]]);
            }
        }
        for(int j=0;j<data6.size();j++){
            if(i-data6[j]>=0){
                tmp=min(tmp,dp[i-data6[j]]);
            }
        }
        dp[i]=1+tmp;
    }
    
    cout<<dp[n]<<endl;
    
    return 0;
}

Measured memory_bytes: 640