akhauriyash/Code-Regression huggingface dataset:
#include <algorithm>
#include <climits>
#include <cmath>
#include <iostream>
#include <numeric>
#include <queue>
#include <unordered_map>
#include <vector>

const int mod = 1e9 + 7;

int main()
{
    int n, q;
    std::cin >> n >> q;

    std::vector<std::vector<int>> edges(n);
    for (int i = 0; i < n - 1; i++) {
        int a, b;
        std::cin >> a >> b;
        a--;
        b--;

        edges[a].push_back(b);
        edges[b].push_back(a);
    }

    std::vector<long long> values(n, 0);
    for (int i = 0; i < q; i++) {
        int p, x;
        std::cin >> p >> x;
        p--;

        values[p] += x;
    }

    auto dfs = [&](auto f, int idx, int parent) -> void {
        for (auto child : edges[idx]) {
            if (child == parent) {
                continue;
            }
            values[child] += values[idx];
            f(f, child, idx);
        }
    };

    dfs(dfs, 0, -1);

    for (auto elem : values) {
        std::cout << elem << std::endl;
    }
}


Measured memory_bytes: 22272
#include <iostream>
#include <string>
#include <vector>
#include <set>

using namespace std;

int main(){
  long n;
  cin >> n;
  string s;
  vector<string> ss;
  long flg;
  for(int i=0;i<n;i++){
    cin >> s;
    ss.push_back(s);
  }
  
  set<string> sss(ss.begin(),ss.end());
  cout << (long)(sss.size()) << endl;
  return 0;
}

Measured memory_bytes: 24888
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define mod 998244353 
#define pb push_back
#define mb make_pair
int main(){
	ios_base::sync_with_stdio(false); 
    cin.tie(NULL);
 	string s; cin >> s;
 	int l=0;
 	for(int i=0;i<s.length();i++)
 		if(s[i]=='x') l++;
 	if(l<=7)
 		cout << "YES";
 	else
 		cout << "NO";
    return 0;

}



Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int (i) = 0; (i) < (n); (i)++)
#define repe(i, n) for(int (i) = 0; i <= (n); (i)++)
#define repr(i, n) for(int (i) = (n); (i) > 0; --(i))
#define repre(i, n) for(int (i) = (n); (i) >= 0; --(i))
typedef long long ll;
typedef unsigned long long ull;
const ull MOD = 1000000007;
ull mpow(ull a, ull n);
ull inv_mod(ull a){return mpow(a, MOD-2);}

ull mpow(ull a, ull n)
{
    ull ans = 1;
    while(n){
        if(n & 1)(ans *= a)%= MOD;
        (a*=a)%MOD;
        n>>1;
    }
}

ull nCr(ull n, ull r)
{
    vector<ull> factorial(n+1);
    factorial[0]=1;
    rep(i, n)factorial[i+1] = factorial[i]*(i+1)%MOD;
    return factorial[n]*inv_mod(factorial[n-r]%MOD)*inv_mod(factorial[r]%MOD);
}

int main()
{
    ull r; cin >> r;
    cout << static_cast<ll>(pow(r, 2)) << endl;
    return 0;

}


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

int main()
{
    int H, W, K;
    cin >> H >> W >> K;

    vector<vector<bool>> cake(H, vector<bool>(W, false));
    string s;
    priority_queue<pair<int, int>, vector<pair<int, int>>, greater<pair<int, int>>> strawberry;
    for (int i = 0; i < H; i++)
    {
        cin >> s;
        for (int j = 0; j < W; j++)
        {
            if (s[j] == '#')
            {
                cake[i][j] = true;
                strawberry.push(make_pair(i, j));
            }
        }
    }

    vector<vector<int>> ans(H, vector<int>(W, 0));
    int current_h = 0;
    int current_w = 0;
    int color = 1;
    int h, w;
    while (!strawberry.empty())
    {
        pair<int, int> next = strawberry.top();
        strawberry.pop();
        h = next.first;
        w = next.second;
        if (strawberry.empty())
        {
            w = W;
        }
        else
        {
            if (h < strawberry.top().first)
            {
                w = W;
            }
            else
            {
                w = strawberry.top().second;
            }
        }
        for (int i = min(current_h, h); i <= h; i++)
        {
            for (int j = current_w; j < w; j++)
            {
                ans[i][j] = color;
            }
        }
        current_h = h + 1;
        current_w = w % W;
        color++;
    }

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

    for (auto x : ans)
    {
        for (int y : x)
        {
            cout << y << " ";
        }
        cout << endl;
    }
}


Measured memory_bytes: 1912
N,M = gets.split.map(&:to_i)
a = gets.split.map(&:to_i)
x = a.map{|ai| [1, ai]}
M.times do
  x << gets.split.map(&:to_i)
end
x.sort_by!{|xi| -xi[1]}
cnt = 0
ans = 0

x.each do |xi|
  cnt += xi[0]
  if cnt < N
    ans += xi[1]*xi[0]
  else
    ans += xi[1]*xi[0]
    ans -= (cnt-N)*xi[1]
    break
  end
end

puts ans




Measured memory_bytes: 24184
X, K, D = map(int, input().split())
X = abs(X)
if K * D <= X:
    print(X - K * D)
else:
    t1 = X // D
    t2 = X % D
    if (K - t1) % 2 == 0:
        print(t2)
    else:
        print(D - t2)

Measured memory_bytes: 9172
#include<bits/stdc++.h>
#define REP(i,a,b) for(int i=(a);i<(b);i++)
using namespace std;

int main() {
    int n, a, b, c, d;
    string s;
    cin >> n >> a >> b >> c >> d >> s;
    bool ng = false;
    REP(i, a, c) {
        if (s.substr(i-1, 2) == "##") ng = true;
    }
    REP(i, b, d) {
        if (s.substr(i-1, 2) == "##") ng = true;
    }
    if (c > d) {
        ng = true;
        REP(i, b, d+1) {
            if (s.substr(i-2, 3) == "...") ng = false;
        }
    }
    cout << (ng ? "No" : "Yes") << endl;
}

Measured memory_bytes: 640
#include <stdio.h>

#define MAX 200000

int max(int a,int b) { return a>b ? a: b;}
int min(int a,int b) { return a<b ? a: b;}

int main(void) {
    int R[MAX], i, n;
    
    scanf("%d",&n);
    for(i=0;i<n;i++) scanf("%d",&R[i]);
    
    int maxv = -2000000000;
    int minv = R[0];
    
    for(int i=1; i<n; i++) {
        maxv = max(maxv, R[i] - minv);
        minv = min(minv, R[i]);
    }
    
    printf("%d\n",maxv);

    return 0;
}



Measured memory_bytes: 2516
#include<bits/stdc++.h>
using namespace std;
#define fs first
#define sc second
#define mp make_pair
#define pb push_back
#define eb emplace_back
#define All(A) A.begin(),A.end()
#define RAll(A) A.rbegin(),A.rend()
typedef long long LL;
typedef pair<LL,LL> P;
const LL mod=1e9+7;
const LL LINF=1LL<<62;
const LL INF=1<<30;

string u;

void solve(int k,LL N,bool f){
    LL t=0;
    if(f){
        string s="";
        for(int i=0;i<k;i++){
            int a=u[0]-'0',b=u[u.size()-1]-'0';
            if(a<b) swap(a,b);
            if((N-1)>>i&1) s.pb((char)(a+'0'));
            else s.pb((char)(b+'0'));
        }
        reverse(All(s));
        u=u+s;
        return;
    }   
    else if(k==1){
        int c=0;
        for(int i=0;i<=k;i++){
            if(i==u[0]-'0') continue;
            c++;
            if(c==N){
                u.pb((char)(i+'0'));
                return;
            }
        }
    }
    for(int i=0;i<=9;i++){
        if(u[0]-'0'==i){
            if(t+((1LL<<(k-1))-1)*9>N){
                u.pb(u[0]);
                solve(k-1,N-t,false);
                return;
            }
            t+=((1LL<<(k-1))-1)*9;
        }
        else{
            if(t+(1LL<<(k-1))>N){
                u.pb((char)(i+'0'));
                solve(k-1,N-t,true);
                return;
            }
            t+=1LL<<(k-1);
        }
        if(N-t==0){
            u.pb((char)(i+'0'));
            if(u[0]==u[u.size()-1]){
                for(int j=0;j<k-1;j++){
                    if(u[0]=='9'&&j==k-2) u.pb('8');
                    else u.pb('9');
                }
            }
            else{
                for(int j=0;j<k-1;j++){
                    if(u[0]>u[u.size()-1]) u.pb(u[0]);
                    else u.pb(u[u.size()-1]);
                }
            }
            return;
        }
    }
}



int main(){
    LL N;
    while(cin >> N){
        if(!N) break;
        u="";
        LL s=0;
        int k=2;
        while(1){
            if(s+81LL*((1LL<<(k-1))-1)>=N) break;
            s+=81LL*((1LL<<(k-1))-1);
            k++;
        }
        LL t=(N-s)/(9*((1LL<<(k-1))-1));
        if((N-s)%(9*((1LL<<(k-1))-1))==0){
            u.pb((char)(t+'0'));
            for(int i=0;i<k-1;i++){
                if(u[0]=='9'&&i==k-2) u.pb('8');
                else u.pb('9');
            }
            cout << u << endl;
            continue;
        }
        else u.pb((char)(t+1+'0'));
        solve(k-1,(N-s)%(9*((1LL<<(k-1))-1)),false);
        cout << u << endl;
    }
    return 0;
}


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

using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef pair<int,int> pi;
#define nl "\n" 

void solve(){
	int tot_animals,tot_legs;
	cin >> tot_animals >> tot_legs;
	if(tot_legs%2){
		cout << "No";
		return;
	}
	int y = (tot_legs/2) - tot_animals;
	int x = tot_animals -y;
	if(x >= 0 && y >= 0){
		cout << "Yes";
	}
	else{
		cout << "No";
	}
}
	

int main(){
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    //int t;//testcases
    //cin>>t;
    //while(t--){
		solve();
	//}
	return 0;
}


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

using namespace std;

struct Matrix
{
  vector< vector< long long > > a;

  Matrix(int N)
  {
    a.resize(N, vector< long long >(N));
  }

  Matrix operator+(const Matrix &kj)
  {
    Matrix ret(a.size());
    for(int i = 0; i < a.size(); i++) {
      for(int j = 0; j < a.size(); j++) {
        ret.a[i][j] = a[i][j] + kj.a[i][j];
      }
    }
    return (ret);
  }

  Matrix operator*(const Matrix &kj)
  {
    Matrix ret = Matrix::Zero(a.size());
    for(int i = 0; i < a.size(); i++) {
      for(int j = 0; j < a.size(); j++) {
        for(int k = 0; k < a.size(); k++) {
          ret.a[i][j] = (ret.a[i][j] + 1LL * a[i][k] * kj.a[k][j]);
        }
      }
    }
    return (ret);
  }

  Matrix operator^(long long n)
  {
    Matrix ret = Matrix::I(a.size());
    Matrix x = *this;
    while(n > 0) {
      if(n & 1) (ret = ret * x);
      x = x * x;
      n >>= 1;
    }
    return (ret);
  }

  static Matrix Zero(int N)
  {
    Matrix ret(N);
    for(int i = 0; i < N; i++) {
      for(int j = 0; j < N; j++) ret.a[i][j] = 0;
    }
    return (ret);
  }

  static Matrix I(int N)
  {
    Matrix ret(N);
    for(int i = 0; i < N; i++) {
      for(int j = 0; j < N; j++) ret.a[i][j] = i == j;
    }
    return (ret);
  }
};

int main()
{
  int n;
  while(cin >> n, n) {
    Matrix tt(3);
    tt.a = {{1, 1, 1},
            {1, 0, 0},
            {0, 1, 0}};
    tt = tt ^ n;
    cout << (tt.a[2][0] * 2 + tt.a[2][1] + tt.a[2][2] + 3649) / 3650 << endl;
  }
}

Measured memory_bytes: 2984
package main

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

var stdin = bufio.NewScanner(os.Stdin)

func main() {
	var count int
	a500, b100, c50, x :=
		func() int { stdin.Scan(); i, _ := strconv.Atoi(stdin.Text()); return i }(),
		func() int { stdin.Scan(); i, _ := strconv.Atoi(stdin.Text()); return i }(),
		func() int { stdin.Scan(); i, _ := strconv.Atoi(stdin.Text()); return i }(),
		func() int { stdin.Scan(); i, _ := strconv.Atoi(stdin.Text()); return i }()
	for a := 0; a <= a500; a++ {
		for b := 0; b <= b100; b++ {
			for c := 0; c <= c50; c++ {
				if x == a*500+b*100+c*50 {
					count++
				}
			}
		}
	}
	fmt.Println(count)
}


Measured memory_bytes: 640
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll MOD = 1000000007;

ll a[2001];

ll solve(ll s) {
  if(s >= 1 && s<=2) {
    return 0;
  }
  a[0] = 1;
  a[3] = 1;

  for(int i=4;i<2001;i++) {
    a[i] = a[i-3] + a[i-1];
    a[i] %= MOD;
  }
  return a[s];
}

int main() {
  ll s;
  cin >> s;
  cout << solve(s);
}

Measured memory_bytes: 3644
S=input()
e=S[0::2]
o=S[1::2]
for i in range(len(e)):
    if e[i]=="L":
        print("No")
        break
else:
    for j in range(len(o)):
        if o[j]=="R":
            print("No")
            break 
    else:
        print("Yes")    

Measured memory_bytes: 3060
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using VI = vector<ll>;
using VV = vector<VI>;
using VS = vector<string>;
using PII = pair<ll, ll>;

template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }

#define FOR(i,a,b) for(ll i=(a);i<(b);++i)
#define rep(i,b) FOR(i, 0, b)
#define ALL(v) (v).begin(), (v).end()
#define p(s) cout<<(s)<<'\n'
#define p2(s, t) cout << (s) << " " << (t) << '\n'
#define br() p("")
#define pn(s) cout << (#s) << " " << (s) << '\n'
#define SZ(x) ((int)(x).size())
#define SORT(A) sort(ALL(A))
#define RSORT(A) sort(ALL(A), greater<ll>())
#define MP make_pair

const ll mod = 1e9 + 7;
const ll inf = 1e18;
const double PI = acos(-1);

VI SG;
VI dp;
ll A[16][16];

ll score(VI& V){
  ll sum = 0;
  ll N = V.size();
  rep(i, N){
    FOR(j, i+1, N){
      ll k = V[i];
      ll l = V[j];
      sum += A[k][l];
    }
  }
  return sum;
}

ll rec(ll f){
  if(f==0) return 0;
  if(dp.at(f)!=inf) return dp[f];

  // fの部分集合を全探索する
  // 蟻本p144
  ll sup = f;
  ll sub = sup;
  ll ma = 0;
  do{
    if(sub==0) break; // これを入れないと無限ループ
    // 処理
    // subとして1グループとる
    ll rest = f ^ sub;
    ll score = SG.at(sub) + rec(rest);
    chmax(ma, score);

    sub = (sub-1)&sup;
  }while(sub!=sup);

  return dp.at(f) = ma;
}

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

    // input
    ll N; cin >> N;
    SG.resize(1LL<<N);
    dp.resize(1LL<<N, inf);

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

    rep(i, 1<<N){
      VI V;
      rep(j, N){
        if(i>>j&1){
          V.push_back(j);
        }
      }
      SG.at(i) = score(V);
    }

    dp[0] = 0;
    rep(i, N){
      dp[1LL<<i] = 0;
    }

    ll ans = rec((1LL<<N)-1);
    p(ans);
    
    return 0;
}

Measured memory_bytes: 1280
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<numeric>
#include<utility>
#include<cmath>

using namespace std;

typedef long long int ll;
const int INF = 1<<30;
const long long LINF = 1LL<<60;

int main(){
    int n, ans = 0;
    cin >> n;
    vector<int> p(n), q(n), x(n);
    for(int i = 0; i < n; i++){
        cin >> p[i];
    }
    for(int i = 0; i < n; i++){
        cin >> q[i];
    }
    for(int i = 0; i < n; i++){
        x[i] = i + 1;
    }
    int cnt = 1, a = -1, b = -1;
    do{
        if(a == -1){
            for(int i = 0; i < n; i++){
                if(x[i] != p[i]){
                    break;
                }
                if(i == n - 1){
                    a = cnt;
                }
            }
        }
        if(b == -1){
            for(int i = 0; i < n; i++){
                if(x[i] != q[i]){
                    break;
                }
                if(i == n - 1){
                    b = cnt;
                }
            }
        }
        cnt++;
    }while(next_permutation(begin(x), end(x)));
    ans = abs(a - b);
    cout << ans << endl;
    return 0;
}


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

#define rep(i, n) for(int i = 0; i<(n); i++)
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
using namespace std;
typedef long long ll;

int main() {
    int N, H;
    cin >> N >> H;
    vector<int> a(N), b(N);
    rep(i, N) cin >> a[i] >> b[i];

    sort(a.rbegin(), a.rend());
    sort(b.rbegin(), b.rend());

    int b_i = 0;
    int ans = 0;
    while (H > 0) {
        if (b_i < b.size() && b[b_i] > a[0]) {
            H -= b[b_i];
            b_i++;
            ans++;
        } else {
            ans += H / a[0];
            if (H % a[0]) ans++; // 切り上げ
            break;
        }
    }
    cout << ans << endl;
}

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

int main() {
  int a,b;
  cin >> a >> b;
  int N;
  if (1<=a && a<=9 && 1<=b && b<=9){
    N=a*b;
  }
  else{
    N=-1;
  }
  cout << N << endl;
}


Measured memory_bytes: 256
from collections import deque

INF = float('inf')

H, W = map(int, input().split())
Sss = ['#'*(W+2)] + ['#'+input()+'#' for _ in range(H)] + ['#'*(W+2)]

def bfsGridGraph(Sss, xS, yS, INF):
    dxys = [(-1,0), (1,0), (0,-1), (0,1)]
    distss = [[(INF if S != '#' else -1) for S in Ss] for Ss in Sss]
    distss[xS][yS] = 0
    Q = deque([(xS, yS)])
    while Q:
        x, y = Q.popleft()
        dist = distss[x][y]
        for dx, dy in dxys:
            x2, y2 = x+dx, y+dy
            if distss[x2][y2] == INF:
                distss[x2][y2] = dist + 1
                Q.append((x2, y2))
    return distss

ans = 0
for i in range(1, H+1):
    for j in range(1, W+1):
        if Sss[i][j] == '#': continue
        distss = bfsGridGraph(Sss, i, j, INF)
        maxDist = max(map(max, distss))
        ans = max(ans, maxDist)

print(ans)


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

#define REP(i, x, n) for (int i = x; i < (int)(n); i++)
#define rep(i, n) REP(i, 0, n)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define sz(x) (int)(x.size())
#define popcount(x) __builtin_popcount(x)
#define popcountll(x) __builtin_popcountll(x)
#define uniq(x) x.erase(unique(x.begin(), x.end()), x.end())
#define F first
#define S second
#define mp make_pair
#define eb emplace_back
#define pii pair<int, int>
#define pll pair<ll, ll>

using namespace std;

typedef long long ll;

/* --- INFの値が適切か確認する --- */
// const int INF = 1 << 30;
// const ll INF = 1LL << 60;
// const int MOD = 1000000007;

int main() {
  int n;
  cin >> n;
  vector<vector<int>> A(n, vector<int>(n, 0));
  rep(i, n) rep(j, n) cin >> A[i][j];

  vector<vector<int>> dp = A;
  rep(k, n) rep(i, n) rep(j, n) dp[i][j] = min(dp[i][j], dp[i][k] + dp[k][j]);

  bool f = true;
  rep(i, n) rep(j, n) if (A[i][j] != dp[i][j]) f = false;

  if (!f) {
    cout << "-1" << endl;
    return 0;
  }

  ll ans = 0;
  rep(i, n) rep(j, n) if (i < j) {
    f = true;
    rep(k, n) if (i != k && j != k && A[i][j] == A[i][k] + A[k][j]) f = false;
    if (f) ans += A[i][j];
  }

  cout << ans << endl;
}


Measured memory_bytes: 1024
#include <array>
#include <cstdlib>
#include <iostream>
#include <string>
#include <queue>
#include <vector>
class SSF {
private:
	void ScanLine(std::vector<std::string> *map, const char lx, const char rx, const char y, const char oy, std::array<std::queue<char>, 4> *buffer) {
		unsigned char i = lx;
		while (i <= rx) {
			while (i < rx) {
				if (map->at(y).at(i) != '0') {
					break;
				}
				++i;
			}
			if (map->at(y).at(i) == '0') {
				break;
			}
			buffer->at(0).push(i);
			while (i <= rx) {
				if (map->at(y).at(i) == '0') {
					break;
				}
				++i;
			}
			buffer->at(1).push(i - 1);
			buffer->at(2).push(y);
			buffer->at(3).push(oy);
		}
		return;
	}
public:
	unsigned char SeedFill(std::vector<std::string> *map, const unsigned char x, const unsigned char y) {
		std::array<std::queue<char>, 4> buffer;
		unsigned char lx, rx, ly, oy;
		if (map->at(y).at(x) == '0' || map->empty() == true) {
			return 0;
		}
		buffer.at(0).push(x);
		buffer.at(1).push(x);
		buffer.at(2).push(y);
		buffer.at(3).push(y);
		while (buffer.front().empty() == false) {
			char lxsav = buffer.at(0).front() - 1, rxsav = buffer.at(1).front() + 1;
			lx = buffer.at(0).front();
			buffer.at(0).pop();
			rx = buffer.at(1).front();
			buffer.at(1).pop();
			ly = buffer.at(2).front();
			buffer.at(2).pop();
			oy = buffer.at(3).front();
			buffer.at(3).pop();
			if (map->at(ly).at(lx) == '0') {
				continue;
			}
			while (rx < map->at(ly).size() - 1) {
				if (map->at(ly).at(rx + 1) == '0') {
					break;
				}
				++rx;
			}
			while (lx > 0) {
				if (map->at(ly).at(lx - 1) == '0') {
					break;
				}
				--lx;
			}
			for (unsigned char i = lx; i <= rx; ++i) {
				map->at(ly).at(i) = '0';
			}
			if (ly - 1 >= 0) {
				if (ly - 1 == oy) {
					ScanLine(map, lx, lxsav, ly - 1, ly, &buffer);
					ScanLine(map, rxsav, rx, ly - 1, ly, &buffer);
				}
				else {
					ScanLine(map, lx, rx, ly - 1, ly, &buffer);
				}
			}
			if (ly + 1 <= map->size() - 1) {
				if (ly + 1 == oy) {
					ScanLine(map, lx, lxsav, ly + 1, ly, &buffer);
					ScanLine(map, rxsav, rx, ly + 1, ly, &buffer);
				}
				else {
					ScanLine(map, lx, rx, ly + 1, ly, &buffer);
				}
			}
		}
		return 1;
	}
};
int main() {
	while (1) {
		SSF ssf;
		std::vector<std::string> map;
		unsigned short count = 0;
		do {
			map.resize(count + 1);
			std::getline(std::cin, map.at(count));
			if (map.at(count).empty() == true) {
				std::getline(std::cin, map.at(count));
				if (map.at(count).empty() == true) {
					return EXIT_SUCCESS;
				}
			}
			map.at(count).resize(map.front().size(), '0');
			map.at(count).shrink_to_fit();
		} while (++count < map.front().size());
		map.shrink_to_fit();
		count = 0;
		for (unsigned char j = 0; j < map.size(); ++j) {
			for (unsigned char i = 0; i < map.at(j).size(); ++i) {
				count += ssf.SeedFill(&map, i, j);
			}
		}
		std::cout << count << std::endl;
	}
	return EXIT_SUCCESS;
}

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

int main() {
  int N,sum,i;
  cin >> N;
  sum=0;
  for(i=0; i<N; i++){
    int a,b;
    cin >> a >> b;
    sum+=(b-a+1);
  }
  cout << sum << endl;;
}


Measured memory_bytes: 384
#include<stdio.h>
int main(){
  int h,n,i,count=0;
  scanf("%d%d",&h,&n);
  int a[n+1];
  for(i=0;i<n;i++){
    scanf("%d",&a[i]);
    count+=a[i];
  }
  if(count>=h)
    printf("Yes\n");
  else
    printf("No\n");
  return 0;  
}


Measured memory_bytes: 512
#include "bits/stdc++.h"
#define ALL(x) x.begin(),x.end()
#define rep(i,n) for(int i=0;i<n;++i)
 
using namespace std;
typedef long long ll;
 

 

 
 
int main(void){
    vector<vector<ll>>dp(1e5+10);
    ll n,a,b,c;
    cin>>n;
    vector<vector<ll>>h(n); //happy
    rep(i,n){
        cin>>a>>b>>c;
        h[i].push_back(a);
        h[i].push_back(b);
        h[i].push_back(c);
    }
    dp[0].push_back(h[0][0]);
    dp[0].push_back(h[0][1]);
    dp[0].push_back(h[0][2]);
    for(int i=1;i<n;++i){
        dp[i].push_back(max(dp[i-1][1],dp[i-1][2])+h[i][0]);
        dp[i].push_back(max(dp[i-1][0],dp[i-1][2])+h[i][1]);
        dp[i].push_back(max(dp[i-1][1],dp[i-1][0])+h[i][2]);
    }
 
    cout<<*(max_element(ALL(dp[n-1])));
}

Measured memory_bytes: 14336
#include<bits/stdc++.h>
using namespace std;
int main(){

  string a;
  int n;
  

  while(1){
    
    cin >>a>>n;

    if(a=="0" && n==0)break;
    
    map<string,int> m;
    
    m[a]=0;
    int b=1;
    int ans1,ans2;

    while(1){

      while(a.size() < n){
	a="0"+a;
      }
      
      string s_max=a,s_min=a;
      sort(s_max.begin(),s_max.end(),greater<char>());
      sort(s_min.begin(),s_min.end());
      
      stringstream ss1,ss2; 
     
      ss1<<s_max;
      ss2<<s_min;

      int max,min;

      ss1>>max;
      ss2>>min;

      int x;

      x=max-min;

      stringstream s_x;

      s_x<<x;

      s_x>>a;
      
      if(m.count(a) != 0){
	ans1=m[a];
	ans2=b-ans1;
	break;
      }
      
      m[a]=b;
      b++;

    }
    
    cout <<ans1<<" "<<a<<" "<<ans2<<endl;

  }
  

  return 0;
}

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


public class B
{
	public static void Main()
	{
		string[] args;
		
		args = Console.ReadLine().Split(' ');
		int A = Int32.Parse(args[0]);
		int B = Int32.Parse(args[1]);
		int K = Int32.Parse(args[2]);

		if(2 * K < B - A + 1)
		{
			for(int i = 0; i < K; i++)
				Console.WriteLine(A + i);
			for(int i = K - 1; i >= 0; i--)
				Console.WriteLine(B - i);
		}
		else
		{
			for(int i = 0; i <= B - A; i++)
				Console.WriteLine(A + i);
		}
	}
}





Measured memory_bytes: 13140
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

#define ll              long long
#define pb              push_back
#define ppb             pop_back
#define endl            '\n'
#define mii             map<ll,ll>
#define pii             pair<ll,ll>
#define vi              vector<ll>
#define vs              vector<string>
#define all(a)          (a).begin(),(a).end()
#define F               first
#define S               second
#define sz(x)           (ll)x.size()
#define hell            1000000007
#define inf             (ll)1e18 + 5
#define PI              (double)3.14159265358979323844
#define DECIMAL(n)      cout << fixed << setprecision(n);
#define rep(i,a,b)      for (ll i=a;i<b;i++)
#define repr(i,a,b)     for (ll i=a-1;i>=b;i--)
#define bitcount(a)     (ll)__builtin_popcount(a)
#define lbnd            lower_bound
#define ubnd            upper_bound
#define mp              make_pair
#define ios             ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define ordered_set     tree<ll, null_type,less<ll>, rb_tree_tag,tree_order_statistics_node_update>
#define trace(...)      __f(#__VA_ARGS__, __VA_ARGS__)

template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
    std::cerr << name << " : " << arg1 << endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
    const char* comma = strchr(names + 1, ',');std::cerr.write(names, comma - names) << " : " << arg1<<" | ";__f(comma+1, args...);
}

using namespace std;
using namespace __gnu_pbds;

/*----------------------Graph Moves----------------*/
//const int fx[]={+1,-1,+0,+0};
//const int fy[]={+0,+0,+1,-1};
//const int fx[]={+0,+0,+1,-1,-1,+1,-1,+1};   // Kings Move
//const int fy[]={-1,+1,+0,+0,+1,+1,-1,-1};  // Kings Move
//const int fx[]={-2, -2, -1, -1,  1,  1,  2,  2};  // Knights Move
//const int fy[]={-1,  1, -2,  2, -2,  2, -1,  1}; // Knights Move
/*------------------------------------------------*/

//primes for hashing 937,991,1013,1409,1741

void solve() {
    string s;
  cin>>s;
  if (s[1]=='R'){
      cout<<"ABC"<<endl;
      }
      else{
        cout<<"ARC"<<endl;
      }
}

signed main() {
    ios
    ll test=1;
    //cin>>test;
    while (test--) solve();
    return 0;
}


Measured memory_bytes: 3600
import sys

read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines
sys.setrecursionlimit(10 ** 9)
INF = 1 << 60
MOD = 1000000007


def main():
    N, A, *X = map(int, read().split())

    M = sum(X)
    dp = [[0] * (M + 1) for j in range(N + 1)]
    dp[0][0] = 1

    for i in range(N):
        for j in range(N, 0, -1):
            for k in range(X[i], M + 1):
                dp[j][k] += dp[j - 1][k - X[i]]

    ans = 0
    for j in range(1, N + 1):
        if A * j > M:
            break
        ans += dp[j][A * j]

    print(ans)
    return


if __name__ == '__main__':
    main()


Measured memory_bytes: 68792
#include <bits/stdc++.h>
typedef long long int ll;
typedef long double ld;
using namespace std;

int main(){
    ll k,n;
    cin>>k>>n;
    vector<ll> a(n);
    for(ll i=0;i<n;++i){
        cin>>a[i];
    }
    ll flag=0;
    ll sum=0;
    for(ll i=1;i<n;++i){
        flag=max(flag, a[i]-a[i-1]);
        sum+=a[i]-a[i-1];
    }
    flag=max(flag, k-a[n-1]+a[0]);
    sum+=k-a[n-1]+a[0];

    sum-=flag;
    cout<<sum<<endl;
}

Measured memory_bytes: 1792
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <string>
#include <sstream>
#include <complex>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>

using namespace std;

#define REP(i,n) for(int i=0;i<n;i++)
#define all(x) (x).begin(),(x).end()
#define pb(a) push_back(a)
#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))

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

int main(){
	int N;
	cin >> N;
	
	cout << N/2 + N%2 << endl;
}

Measured memory_bytes: 256
#include<stdio.h>
int main(){
    int A,N,i,j,p[51],c=0;
    scanf("%d",&N);
    for(i=0;i<N;i++){
        scanf("%d",&p[i]);}
      for(i=0;i<N;i++){

    for(j=N-1;j>i;j--)
    {
        if(p[i]>p[j]){
            A = p[i];
            p[i]=p[j];
            p[j]=A;
        c=c+1;
        i=0;
        if(c>1){
            break;
        }

    }}
    if(c>1){break;}}
    if(c>1){
        printf("NO\n");
    }
    else {printf("YES\n");}



    }


Measured memory_bytes: 128
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>


using namespace std;
using namespace __gnu_pbds;


#define LL long long
#define N 100005
#define MOD 1000000007
#define dd double
#define rep(i, n) for(int i = 0; i < n; i++)
#define REP(i,a,b) for(int i=a;i<b;i++)
#define rep1(i,b) for(int i=1;i<=b;i++)
#define pb push_back
#define mp make_pair
#define clr(x) x.clear()
#define sz(x) ((int)(x).size())
#define F first
#define S second
typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update>ordered_set;

int main() {

ios_base::sync_with_stdio(false);
cin.tie(NULL);
	
	int t=1;
	//cin>>t;
	while(t--){
		long long n,a,b;
		cin>>n>>a>>b;
		LL ans = (n/(a+b))*a+min(a,n%(a+b));
		cout<<ans;
	}



return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll uint64_t 
int main(){
  ll n,a,b;
  cin>>n>>a>>b;
  ll d=a+b/2;
  ll c=d-min(a,b);
  if((max(a,b)-min(a,b))%2==0)cout<<(max(a,b)-min(a,b))/2;
  else cout<<min(a-1,n-b)+(max(a,b)-min(a,b)+1)/2;
}


Measured memory_bytes: 256
## tmp experiment
import math


def chinese_reminder(x1, y1, x2, y2):
    g = math.gcd(y1, y2)
    if (x2 - x1) % g != 0:
        return (float("inf"), float("inf"))
    else:
        K = (x2 - x1) // g
        y1, y2 = y1 // g, y2 // g
        t = -K * modinv(y2, y1)
        m = x2 + t * g * y2
        return (m % (g * y1 * y2), g * y1 * y2)


def xgcd(a, b):
    x0, y0, x1, y1 = 1, 0, 0, 1
    while b != 0:
        q, a, b = a // b, b, a % b
        x0, x1 = x1, x0 - q * x1
        y0, y1 = y1, y0 - q * y1
    return a, x0, y0


def modinv(a, m):
    g, x, y = xgcd(a, m)
    if g != 1:
        return False
    else:
        return x % m


def divisors(X):
    res = set([])
    for i in range(1, X + 1):
        if i ** 2 > X:
            break
        else:
            if X % i == 0:
                res.add(i)
                res.add(X // i)
    return res


def main():

    N = int(input())
    d = divisors(2*N)
    ans = 10 ** 20
    for n in d:
        u, v = n, (2*N) // n
        if math.gcd(u, v) == 1:
            v, m = chinese_reminder(0, u, v-1, v)
            if v == 0:
                ans = min(m, ans)
            else:
                ans = min(v, ans)
    print(ans)


if __name__ == "__main__":
    main()


Measured memory_bytes: 71320
#include<stdio.h>
int main()
{
	int N,A,B,T;
	scanf("%d %d %d",&N,&A,&B);
	if(N>=1 && N<=20 && A>=1 && A<=50 && B>=1 && B<=50)
	{
		if(N*A>B)
			printf("%d\n",B);
		else
			printf("%d\n",N*A);
	}
	return 0;
}


Measured memory_bytes: 128
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for(int i = 0; i < (n); i++)
#define rep1(i, n) for(int i = 1; i <= (n); i++)
#define co(x) cout << (x) << "\n"
#define cosp(x) cout << (x) << " "

int main(void){
    string s,t;cin>>s>>t;
    cout<<t<<s<<endl;
}


Measured memory_bytes: 256
#include <stdio.h>
int main()
{
    int sum = 0, a[101][101] = {0}, r, c;
    scanf("%d %d", &r, &c);
    for (int i = 0; i < r; i++)
    {
        for (int j = 0; j < c; j++)
        {
            scanf("%d", &a[i][j]);
        }
    }
    for (int i = 0; i < r; i++)
    {
        for (int j = 0; j < c; j++)
        {
            a[i][c] = a[i][c] + a[i][j];
            a[r][j] = a[r][j] + a[i][j];
        }
    }
    for (int i = 0; i < r; i++)
    {
        a[r][c] = a[r][c] + a[i][c];
    }

    for (int i = 0; i < r + 1; i++)
    {
        for (int j = 0; j < c + 1; j++)
        {
            if (j == 0)
            {
                printf("%d", a[i][j]);
            }
            else
            {
                printf(" %d", a[i][j]);
            }
        }
            printf("\n");
    }

    return 0;
}


Measured memory_bytes: 2112
#include<stdio.h>

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

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

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

  return 0;
}

Measured memory_bytes: 1732
s=input()
s=s[::-1]

for i in range(100000):
    if s[:5] == 'maerd':
        s = s[5:]
    if s[:5] == 'esare':
        s = s[5:]
    if s[:6] == 'resare':
        s = s[6:]
    if s[:7] == 'remaerd':
        s = s[7:]

if len(s)==0:
    print('YES')
else:
    print('NO')

Measured memory_bytes: 9232
import java.util.Scanner;
public class Main
{
	public static void main(String arg[])
	{
		Scanner in = new Scanner(System.in);
		while(in.hasNext())
		{
			String str=in.next();
			int a[]=new int[10];
			for(int i=0;i<str.length();i++)
				a[str.charAt(i)-'0']++;
			int ans[]=new int[10];
			for(int i=1;i<=9;i++)
			{
				if(a[i]==4)
					continue;
				a[i]++;
				for(int j=1 ; j <= 9 ; j++ )
				{
					if( a[j] >= 2 )
					{
						a[j] -= 2;
						sol(a,i,ans);
						a[j] += 2;
					}
				}
				a[i]--;
			}
			int j=0;
			for(int i=1;i<=9;i++)
			{
				if(ans[i]==1)
				{
					if(j!=0)
						System.out.print(" ");
					System.out.print(i);
					j=1;
				}
			}
			if(j==0)
				System.out.print(0);
			System.out.println();
		}
	}

	public static void sol(int a[],int n,int ans[])
	{
		int s=0;
		for(int i=1;i<=9;i++)
			s+=a[i];
		if(s==0)
			ans[n]=1;

		for(int i=1; i <= 9 ; i++ )
		{
			if( a[i] >= 3 )
			{
				a[i] -= 3;
				sol( a , n , ans );
				a[i] += 3;
			}
		}
		for(int i=1 ; i <= 7 ; i++ )
		{
			if(a[i]>=1&&a[i+1]>=1&&a[i+2]>=1)
			{
				a[i]--;
				a[i+1]--;
				a[i+2]--;
				sol( a , n , ans );
				a[i]++;
				a[i+1]++;
				a[i+2]++;
			}

		}
	}
}

Measured memory_bytes: 12000
#include <bits/stdc++.h>
#define int long long
#define ll long long
using ull = unsigned long long;
using namespace std;
const int INF = 1ll << 50;
const int MOD = 1e9 + 7;
#define dump(x)                             \
    if (dbg) {                              \
        cerr << #x << " = " << (x) << endl; \
    }
#define overload4(_1, _2, _3, _4, name, ...) name
#define FOR1(n) for (ll i = 0; i < (n); ++i)
#define FOR2(i, n) for (ll i = 0; i < (n); ++i)
#define FOR3(i, a, b) for (ll i = (a); i < (b); ++i)
#define FOR4(i, a, b, c) for (ll i = (a); i < (b); i += (c))
#define FOR(...) overload4(__VA_ARGS__, FOR4, FOR3, FOR2, FOR1)(__VA_ARGS__)
#define FORR(i, a, b) for (int i = (a); i <= (b); ++i)
#define bit(n, k) ((n >> k) & 1) /*nのk bit目*/
template <class T>
bool chmin(T& a, const T& b) {
    if (a > b) {
        a = b;
        return 1;
    } else
        return 0;
}
template <class T>
bool chmax(T& a, const T& b) {
    if (a < b) {
        a = b;
        return 1;
    } else
        return 0;
}
void Yes(bool flag = true) {
    if (flag)
        cout << "Yes" << endl;
    else
        cout << "No" << endl;
}
void No(bool flag = true) {
    Yes(!flag);
}
void YES(bool flag = true) {
    if (flag)
        cout << "YES" << endl;
    else
        cout << "NO" << endl;
}
void NO(bool flag = true) {
    YES(!flag);
}
#define pb push_back
#define mp make_pair
#define eb emplace_back
#define lb lower_bound
#define ub upper_bound
#define all(v) (v).begin(), (v).end()
#define SZ(x) ((int)(x).size())
#define vi vector<int>
//#define P pair<int, int>
//#define V vector<int>
//#define S set<int>
#define itn int
#define asn ans
bool dbg = false;

string S;
map<int, int> m;
int s;

void solve() {
    int N = S.size();
    m[0] = 1;
    int ans = INF;
    FOR(N) {
        int c = S[i];
        s ^= (1 << c);
        int res;
        if (m[s] == 0)
            res = INF;
        else
            res = m[s];
        FOR(x, 0, 26) {
            int tmp = m[s ^ (1 << x)];
            if (tmp != 0)
                chmin(res, tmp + 1);
        }
        m[s] = res;
        if (i == N - 1)
            ans = res - 1;
        //cerr << i + 1 << " : " << res - 1 << endl;
    }
    if (!ans)
        ans++;
    cout << ans << endl;
}

signed main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    cin >> S;

    for (auto& c : S)
        c -= 'a';

    solve();
    return 0;
}


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

using namespace std;

#define YES cout << "YES" << endl;
#define NO  cout << "NO"  << endl;
#define Yes cout << "Yes" << endl;
#define No  cout << "No"  << endl;
 
#define INF INT_MAX
#define MOD 1000000007
#define PI  acos(-1)

using ll  = long long;
using ull = unsigned long long;
using Pii = pair<int, int>;
using Pll = pair<ll, ll>;

#define rep(i, n) for (ll i = 0; i < (n); i++)
#define rrep(i, n) for (ll i = (n)-1; i >= 0; i--)

int main(int argc, char *argv[])
{
    cin.tie(0);
    ios::sync_with_stdio(false);

    ll S;
    cin >> S;

    const ll v = 1000000000;

    ll x = (v-S%v)%v;
    ll y = (S+x)/v;

    cout << "0 0 1000000000 1 " << x << " " << y << endl;
    return 0;
}

Measured memory_bytes: 256
s = input()
K = "keyence"

def solve():
    if s.startswith(K) or s.endswith(K):
        return "YES"
    else:
        for i in range(len(K)):
            head = K[:i]
            tail = K[i:]
            if s.startswith(head) and s.endswith(tail):
                return "YES"
    return "NO"

print(solve())


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

int N, W;
int w0;
vector<vector<long long>> wv;
long long maxv;
void dfs(int n, long long w, long long v) {
  if (n == 4) {
    maxv = max(v, maxv);
    return;
  }
  dfs(n + 1, w, v);
  for (int i = 0; i < wv[n].size(); i++) {
    long long nw = w + (long long)(w0 + n) * (i + 1);
    if (nw <= W) dfs(n + 1, nw, v + wv[n][i]);
  }
}

int main(void) {
  cin >> N >> W;
  vector<int> w(N), v(N);
  wv = vector<vector<long long>>(4);
  for (int i = 0; i < N; i++) {
    cin >> w[i] >> v[i];
  }
  w0 = w[0];
  for (int i = 0; i < N; i++) {
    wv[w[i] - w0].push_back(v[i]);
  }
  for (int i = 0; i < 4; i++) {
    sort(wv[i].begin(), wv[i].end(), greater<int>());
  }
  for (int i = 0; i < 4; i++) {
    for (int j = 1; j < wv[i].size(); j++) {
      wv[i][j] += wv[i][j - 1];
    }
  }
  dfs(0, 0, 0);
  cout << maxv << endl;

  return 0;
}

Measured memory_bytes: 256
package main

import "fmt"

func min(x, y int) int{
	if x < y {
		return x
	}
	return y
}

func main() {

	var a, b, c, n int
	fmt.Scan(&a, &b, &c)
	n = 0

	for i := a; i <= b; i++ {
		if c % i == 0 {
			n++
		}
	}
	fmt.Println(n)
}


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

using VI = vector<int>;
using VVI = vector<VI>;
using PII = pair<int, int>;
using LL = long long;
using VL = vector<LL>;
using VVL = vector<VL>;
using PLL = pair<LL, LL>;
using VS = vector<string>;

#define ALL(a)  begin((a)),end((a))
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define EB emplace_back
#define MP make_pair
#define SZ(a) int((a).size())
#define SORT(c) sort(ALL((c)))
#define RSORT(c) sort(RALL((c)))
#define UNIQ(c) (c).erase(unique(ALL((c))), end((c)))

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

#define FF first
#define SS second
template<class S, class T>
istream& operator>>(istream& is, pair<S,T>& p){
  return is >> p.FF >> p.SS;
}
template<class S, class T>
ostream& operator<<(ostream& os, const pair<S,T>& p){
  return os << p.FF << " " << p.SS;
}
template<class T>
void maxi(T& x, T y){
  if(x < y) x = y;
}
template<class T>
void mini(T& x, T y){
  if(x > y) x = y;
}


const double EPS = 1e-10;
const double PI  = acos(-1.0);
const LL MOD = 1e9+7;

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

  string S;
  cin >> S;
  string tmp = S;
  SORT(tmp);
  UNIQ(tmp);

  cout << (SZ(S) == SZ(tmp)? "yes": "no") << endl;

  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(){
	int A,B,C;
	cin >> A >> B >> C;
	bool result = false;
	for (int i = 0; i < B; ++i)
	{
		if((A * i) % B == C){
			result = true;
			break;
		}
	}
	if(result){
		cout << "YES" << endl;
	}else{
		cout << "NO" << endl;
	}
}

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

public class Main {

	public static void main(String args[]) {

		Scanner sc = new Scanner(System.in);
		String s = sc.nextLine();

		int N = Integer.parseInt(s.split(" ")[0]);
		int M = Integer.parseInt(s.split(" ")[1]);

		s = sc.nextLine();
		String[] xs = s.split(" ");
		int[] x = new int[M];
		for (int i = 0; i < M; i++) {
			x[i] = Integer.parseInt(xs[i]);
		}

		Arrays.sort(x);

		int[] diff = new int[M - 1];
		for (int i = 0; i < M - 1; i++) {
			diff[i] = x[i + 1] - x[i];
		}
		Arrays.sort(diff);

		int ans = 0;
		for (int i = 0; i < M - N; i++) {
			ans += diff[i];
		}

		System.out.println(ans);

	}

}

Measured memory_bytes: 48168
fun main(args: Array<String>) {
    val (N, K) = readLine()!!.split(" ").map(String::toInt)
    val h = (1..N).map { readLine()!!.toInt() }.sorted()
    print((0..h.size - K).map { h[it + K - 1] - h[it] }.min())
}

Measured memory_bytes: 47508
import java.io.*;
import java.util.*;

public class Main {
    public static void main (String[]args)throws IOException {
        Scanner scanner = new Scanner(System.in);
        long n = scanner.nextLong();
        long k = scanner.nextLong();
        n=n%k;
        System.out.println(Math.min(n,Math.abs(n-k)));
    }
}


Measured memory_bytes: 21844
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep1(i, n) for (int i = 1; i <= (int)(n); i++)
typedef int64_t Int;

int main(){ 
  Int A, B; cin >> A >> B;
  if (A == 1 || B == 1) cout << 1 << endl;
  else if (A % 2 == 1 && B % 2 == 1) cout << A * B / 2 + 1 << endl;
  else cout << A * B / 2 << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <cmath>
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)

using namespace std;



int main()
{
  int a,b,c,x;
  cin >> a >> b >> c;
  cout << min(a+b, min(a+c, b+c));
}


Measured memory_bytes: 256
import math
A,B = map(int,input().split())
ans = -1
start =math.floor(A / 0.1)
end = math.ceil(B /0.08)

for i in range (start,end+10):
    if  math.floor(i*0.08) == A and math.floor(i*0.1) == B:
        ans = i
        break

print(ans) 

Measured memory_bytes: 3060
//家で書いたO(MN)、外周の変更時の数え上げも一括でできることが判明.
//というか、なぜ本選でバグったし…、0点の割に解説内容が自分の考え
//と全くいっしょだっだのがショック
//実装：約30分
#include <iostream>
using namespace std;

int M,N;
char str1[1002],str2[4];
int JOI[1002][1002],mon[2][2];	//外周は0,Jは1,Oは2,Iは3であらわす。
int data[1002][1002];			//data[i][j]は左上(j,i)から紋章をいくつ作れるか(0or1)を記録

int ctoi(char c){
	char str[4] = "JOI";
	for(int i = 0;i < 3;i++){
		if(c == str[i])
			return i+1;
	}
	return 0;
}
int make(int i,int j){
	for(int a = 0;a < 2;a++){
		for(int b = 0;b < 2;b++){
			if(JOI[i+a][j+b] != mon[a][b])
				return 0;
		}
	}
	return 1;
}
int new_makecount(int i,int j);

int main(){
	int sum = 0,maxsum = 0;
	cin >> M >> N;
	for(int i = 1;i <= M;i++){
		cin >> str1;
		for(int j = 1;j <= N;j++){
			JOI[i][j] = ctoi(str1[j-1]);	//マイナスを忘れるな！！
		}
	}
	for(int i = 0;i < 2;i++){
		cin >> str2;
		for(int j = 0;j < 2;j++){
			mon[i][j] = ctoi(str2[j]);
		}
	}
	//最初の数え上げ(monとの一致を調べる左上の座標が(j,i)である)
	for(int i = 1;i <= M;i++){
		for(int j = 1;j <= N;j++){
			data[i][j] = make(i,j);
			sum += data[i][j];
			//cout << data[i][j] << " ";
		}
		//cout<<endl;
	}
	maxsum = sum;
	int delta;		//紋章の数の増減
	int memo;
	//一つ変える
	for(int i = 1;i <= M;i++){
		for(int j = 1;j <= N;j++){
			memo = JOI[i][j];
			//(j,i)を変えたときにどれだけ紋章が増えるのか
			delta = new_makecount(i,j);
			if(maxsum < delta+sum){
				maxsum = delta+sum;
			}
			JOI[i][j] = memo;
		}
	}
	cout << maxsum << endl;
	return 0;
}
int new_makecount(int i,int j){
	int del,maxdel = -5;
	for(int k = 1;k < 4;k++){
		JOI[i][j] = k;
		del = 0;
		for(int l = i-1;l < i+1;l++){
			for(int m = j-1;m < j+1;m++){
				del += make(l,m)-data[l][m];
			}
		}
		if(maxdel < del)
			maxdel = del;
	}
	return maxdel;
}

Measured memory_bytes: 9008
h, w = map(int, input().split())
s_h_list = []
for i in range(1, h):
	sa = w * i
	sb = (w//2) * (h-i)
	sc = h*w - (sa + sb)
	s_list = [sa, sb, sc]
	s_h_list.append(max(s_list) - min(s_list))
	sb = ((h-i)//2) * w
	sc = h*w - (sa + sb)
	s_list = [sa, sb, sc]
	s_h_list.append(max(s_list) - min(s_list))
s_h_list.sort()
s_w_list = []
for i in range(1, w):
	sa = h * i
	sb = (h//2) * (w-i)
	sc = h*w - (sa + sb)
	s_list = [sa, sb, sc]
	s_w_list.append(max(s_list) - min(s_list))
	sb = h * ((w-i)//2)
	sc = h*w - (sa + sb)
	s_list = [sa, sb, sc]
	s_w_list.append(max(s_list) - min(s_list))
s_w_list.sort()
print(min([s_h_list[0], s_w_list[0]]))

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

int main(void){
    int n=0;
    scanf("%d",&n);
    int i;
    int j;
    int m=0;
    int num=0;
    int f=1;
    char a[50][50];
    char b[50][50];
    char c[50];
    for(i=0;i<n;i++){
        scanf("%s",a[i]);
        strcpy(b[i],a[i]);
    }
    int k;
    int l;
    for(k=0;k<n-1;k++){
        for(l=0;l<n-k-1;l++){
            if(a[l][1]>a[l+1][1]){
                strcpy(c,a[l]);
                strcpy(a[l],a[l+1]);
                strcpy(a[l+1],c);
            }
        }
    }

    for(i=0;i<n;i++){
      if(i!=n-1){printf("%s ",a[i]);}
              else{
            printf("%s\n",a[i]);
        }
    }
    printf("Stable\n");

    for(i=0;i<n-1;i++){
        m = b[i][1];
        num = i;
        for(j=i+1;j<n;j++){
            if(m>b[j][1]){
                m = b[j][1];
                num = j;
            }
        }
        if(num!=i){
            strcpy(c,b[i]);
            strcpy(b[i],b[num]);
            strcpy(b[num],c);
        }
    }
    for(i=0;i<n;i++){
      if(i!=n-1){printf("%s ",b[i]);}
      else{printf("%s\n",b[i]);}

    }
    int d=0;
    for(d=0;d<n;d++){
        if(strcmp(a[d],b[d])!=0){
            printf("Not stable\n");
            f = 2;
            break;
        }
    }
    if(f==1){
        printf("Stable\n");
    }

    return 0;
}



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

using namespace std;

int main() {
    int n, a, b;
    cin >> n >> a >> b;
    int res = 0;
    for (int i = 1; i <= n; i++) {
        int hold = i, sum = 0;
        while (hold) {
            sum += hold % 10;
            hold /= 10;
        }
        if (a <= sum && sum <= b) {
            res += i;
        }
    }
    cout << res;
    return 0;
}

Measured memory_bytes: 3600
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<utility>
#include<cstdlib>
#include<cmath>
#include<queue>
#include<stack>
#include<map>
#define REP(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define REPS(i,n) for(int i=1, i##_len=(n); i<i##_len; ++i)
#define all(x) (x).begin(),(x).end()
using ll = long long;
using namespace std;
long long combi(long long n, long long k) {
	if (n == k || k == 0)
		return 1;
	else {
		return combi(n - 1, k - 1) + combi(n - 1, k);
	}
}
long long gcd(long long a, long long b) {
	return a % b ? gcd(b, a%b) : b;
}
long long isPrime(long long x) {
	if (x <= 1) return 0;
	if (x == 2) return 1;
	for (int i = 2; i < sqrt(x); i++) {
		if (x % i == 0) return 0;
	}
	return 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; }
int main() {
	int n, m;
	cin >> n >> m;
	vector<int> a(m), b(m);
	vector<vector<int> > c(m, vector<int>(n));
	REP(i, m) {
		cin >> a[i] >> b[i];
		REP(j, b[i]) {
			cin >> c[i][j];
		}
	}
	ll INF = 1LL << 60;
	vector<vector<ll> > dp(m + 1, vector<ll>((1LL << n) + 1, INF));
	dp[0][0] = 0;
	REP(i, m) {
		REP(j, 1LL << n) {
			ll sumc = 0;
			REP(k, b[i]) {
				sumc += 1LL << (c[i][k]-1);
			}
			chmin(dp[i + 1][j], dp[i][j]);
			chmin(dp[i + 1][j | sumc], dp[i][j] + a[i]);
		}
	}
	if (dp[m][(1LL << n) - 1] == INF) {
		cout << -1 << endl;
	}
	else cout << dp[m][(1LL << n) - 1] << endl;
	return 0;
}

Measured memory_bytes: 32384
fun main(args: Array<String>) {
    val inputs = readInputLine().split(" ").map { Integer.parseInt(it) }
    
    val N = inputs[0]
    val K = inputs[1]
    
    // N - K + 1が選択可能個数(先頭K-1個を除いて、末尾を移動するイメージ)
    println(N - K + 1)
}
 
fun readInputLine(): String {
    return readLine()!!
}


Measured memory_bytes: 37864
# coding: utf-8

def main():
    _ = int(input())
    A = list(map(int, input().split()))
    ans = 0
    tmp = 0
    total = sum(A)
    for a in A:
        tmp += a
        if tmp >= total // 2:
            ans = min(2 * tmp - total, total - 2 * (tmp - a))
            break

    print(ans)

if __name__ == "__main__":
    main()


Measured memory_bytes: 31640