akhauriyash/Code-Regression huggingface dataset:
#include<stdio.h>
int main(){
char s[4];
  scanf("%s",&s);
  int mae=(s[0]-'0')*10+(s[1]-'0');
  int ato=(s[2]-'0')*10+(s[3]-'0');
  int flag=0,flag2=0;
  if(mae>=1&&mae<=12)flag=1;
  if(ato>=1&&ato<=12)flag2=1;
  if(flag&flag2)printf("AMBIGUOUS");
 	else if(flag)printf("MMYY");
  else if(flag2)printf("YYMM");
  else printf("NA");
  return 0;
}


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

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

const long long INF = 1LL << 60;

int main() {

	int n;
	cin >> n;
	vector<long long> h(100010);
	for (int i = 0; i < n; i++) cin >> h[i];
	vector<long long> dp(100010);
	for (int i = 0; i < 100010; i++) dp[i] = INF;

	dp[0] = 0;

	for (int i = 1; i < n; i++) {
		chmin(dp[i], dp[i - 1] + abs(h[i] - h[i - 1]));
		if (i > 1) chmin(dp[i], dp[i - 2] + abs(h[i] - h[i - 2]));
	}
	cout << dp[n - 1] << endl;
}

Measured memory_bytes: 1792
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define f(i,a,n) for(ll i=a;i<n;i++)
#define w(_t) ll _t;cin>>_t;while(_t--)

int main() {
    ios::sync_with_stdio(false);cin.tie(0);
    string s,t;
    cin>>s>>t;
    ll n=s.length(),m=t.length();
    ll ans=10000;
    f(i,0,n-m+1){
        ll ct=0;
        f(j,i,i+m){
            if(s[j]!=t[j-i]) ct+=1;
        }
        ans=min(ans,ct);
    }
    cout<<ans;
    return 0;
}

Measured memory_bytes: 3628
#include <cstdio>
#include <algorithm>

using namespace std;

const int N = 5010;

int n, K, a[N];
bool c[N];

bool f(int p) {
    for (int i = 0; i <= K; i++) {
        c[i] = false;
    }
    c[0] = true;
    for (int i = 0; i < n; i++) {
        if (i != p) {
            for (int j = K; j >= a[i]; j--) {
                c[j] |= c[j - a[i]];
            }
        }
        for (int j = 0; j < K; j++) {
            if (c[j] && j + a[p] >= K) {
                return true;
            }
        }
    }
    return false;
}

int main() {

    scanf("%d %d", &n, &K);

    for (int i = 0; i < n; i++) {
        scanf("%d", &a[i]);
        a[i] = min(a[i], K);
    }

    sort(a, a + n);

    int l = 0;
    int r = n - 1;

    while (l <= r) {
        int m = (l + r) / 2;
        if (f(m)) {
            r = m - 1;
        } else {
            l = m + 1;
        }
    }

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

    return 0;

}


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

using namespace std;

int N;
int d[100];

void solve() {
    set<int> values;
    for (int i = 0; i < N; ++i) {
        values.insert(d[i]);
    }
    printf("%d\n", (int) values.size());
}

void another_solve() {
    int num[100];
    for (int i = 0; i < N; ++i) {
        num[d[i]]++;
    }
    int res = 0;
    for (int j = 1; j < 100; ++j) {
        if (num[j]) {
            ++res;
        }
    }
    printf("%d\n", res);
}

int main() {
    cin >> N;
    for (int i = 0; i < N; ++i) {
        cin >> d[i];
    }
    solve();
    return 0;
}

Measured memory_bytes: 3728
#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;

#ifndef bhartiya
    #pragma GCC optimize("Ofast")
    #pragma GCC optimize("unroll-loops")
    // #pragma GCC target ("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#endif

#define int long long
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef gp_hash_table<int, int> umap;
typedef tree<int, null_type, less<int>, rb_tree_tag,
		tree_order_statistics_node_update> oset;
// not that imp
typedef pair<pii, int> piii;
typedef vector<int> vi;
typedef vector<pii> vii;

#define inf 200000000000000
#define mod 1000000007
#define eps 1e-7
#define PI 3.1415926535897932385
// #define PI acos(-1)

#define pb push_back
#define bitc  __builtin_popcountll
#define mp make_pair
#define ff first
#define ss second
#define all(ar) ar.begin(), ar.end()
#define sz(x) (int)(x).size()

#define fr(i,a,b) for (int i = (a), _b = (b); i <= _b; i++)
#define rep(i,n) for (int i = 0, _n = (n); i < _n; i++)
#define repr(i,n) for (int i = n - 1; i >= 0; i--)
#define frr(i,a,b) for (int i = (a), _b = (b); i >= _b; i--)
#define foreach(it,ar) for (auto it = ar.begin(); it != ar.end(); it++)
#define fil(ar,val) memset(ar, val, sizeof(ar))

#ifdef bhartiya
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
	cout << name << " : " << arg1 << endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
	const char* comma = strchr(names + 1, ',');cout.write(names, comma - names) << " : " << arg1<<" | ";__f(comma+1, args...);
}
int begtime = clock();
#define end_routine() cout << "\n\nTime elapsed: " << (clock() - begtime)*1000/CLOCKS_PER_SEC << " ms\n\n";
#else
#define endl '\n'
#define trace(...)
#define end_routine()
#endif

mt19937 rng32(chrono::steady_clock::now().time_since_epoch().count());
inline bool equals(double a, double b) {return fabs(a - b) < 1e-9;}
int gcd(int a, int b){ return b==0 ? a : gcd(b, a%b); }
ll modpow(ll b, ll e) {
	ll ans=1; for(;e;b=b*b%mod,e/=2) if(e&1) ans=ans*b%mod; return ans;}

const int maxn = 300005;
vi factors[maxn];
int cnt[maxn], a[maxn];
vi ans;

void solve(){

	int n; cin>>n;
	fr(i,1,n) cin>>a[i];
	multiset<int> s;
	s.insert(a[1]);
	fr(i,2,n){
		auto it = s.begin();
		if(*it >= a[i]) s.insert(a[i]);
		else{
			s.insert(a[i]);
			auto it2 = s.lower_bound(a[i]-1);
			if(*it2 == a[i]){
				it2--;
			}
			s.erase(it2);
		}
		// trace(i,s.size());
	}
	cout<<s.size();
}

signed main() 
{ 
	ios_base::sync_with_stdio(false);
    cin.tie(0), cout.tie(0), cout.precision(10); //cout<<fixed;
    cin.exceptions(cin.failbit);
    #ifdef bhartiya
        freopen("input.txt", "r", stdin);
        freopen("output.txt", "w", stdout);
    #endif
    solve();
    end_routine();
}

Measured memory_bytes: 13312
#include<cstdio>
#include<queue>
#include<utility>
#include<cstring>
#include<stack>
#include<algorithm>
#include<cmath>
#include<iostream>
#include<map>
#define MAX_N 100001
#define INF_INT 2147483647
#define INF_LL 9223372036854775807
#define REP(i,n) for(int i=0;i<(int)(n);i++)
using namespace std;
typedef long long int ll;
typedef pair<ll,ll> P;
void init(int n);
int find(int n);
void unite(int x,int y);
bool same(int x, int y);
ll bpow(ll,ll,ll);
typedef vector<int> vec;
typedef vector<vec> mat;
mat mul(mat &A,mat &B);
mat pow(mat A,ll n);
int dx[4] = {1,0,0,-1};
int dy[4] = {0,1,-1,0};


bool cmp_P(const P &a,const P &b){
  return a.second < b.second;
}
ll N,M;
bool solve(ll n){
  ll nn = N;
  ll nm = M;
  if(nn >= n){
    if(nm >= n*2)
      return true;
    else{
      return false;
    }
  }else{
    nm -= 2*(n-nn);
    if(nm >= n*2)
      return true;
    else
      return false;
  }
}

int main()
{
  
  cin >> N >> M;
  ll ok = 0 , ng = 10E12;
  while(abs(ok-ng) > 1){
    ll mid =(ok+ng)/2;
    if(solve(mid))
      ok = mid;
    else
      ng = mid;
  }
  if(solve(ng))
    cout << ng << endl;
  else
    cout << ok << endl;
  return 0;
}

int par[MAX_N];
int ranks[MAX_N];

//n要素で初期化
void init(int n){
  REP(i,n){
    par[i] = i;
    ranks[i] = 0;
  }

}

//木の根を求める
int find(int x){
  if(par[x] == x){
    return x;
  }else{
    return par[x] = find(par[x]);
  }
}

void unite(int x,int y){
  x = find(x);
  y = find(y);
  if(x == y) return ;
  if(ranks[x] < ranks[y]){
    par[x] = y;
  }else{
    par[y] = x;
    if(ranks[x] == ranks[y]) ranks[x]++;
  }
}

bool same(int x, int y){
  return find(x) == find(y);
}

ll bpow(ll a, ll n,ll mod){
  int i = 0;
  ll res=1;
  while(n){
    if(n & 1)
      res = (res*a) % mod;
    a = (a*a) % mod;
    n >>= 1;
  }
  return res;
}
const int MOD = 1000000007;
mat mul(mat &A, mat &B){
  mat C(A.size(),vec(B[0].size()));
    REP(i,A.size())REP(k,B.size())REP(j,B[0].size()){
    C[i][j] = (C[i][j] + A[i][k] * B[k][j]) % MOD;
  }
  return C;
}

mat pow(mat A,ll n)
{
  mat B(A.size(),vec(A.size()));
  REP(i,A.size()){
    B[i][i] = 1;
  }
  while(n > 0){
    if ( n & 1) B = mul(B,A);
    A = mul(A,A);
    n >>= 1;
  }
  return B;
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <cctype>
#include <cstring>
using namespace std;

string s;
string buf;
int p;
int q;

int nextint() {
    string t;
    while (isdigit(s[p])) {
        t.push_back(s[p]);
        p++;
    }
    return atoi(t.c_str());
}

void solve() {
    if (p == s.size()) return;
    if (buf.size() > q) return;
    if (isupper(s[p])) {
        buf.push_back(s[p]);
        p++;
        solve();
    }
    if (isdigit(s[p])) {
        int n = nextint();
        //cout << "n: " << n << ' ';
        //cout << s[p] << ' ';
        if (s[p] != '(') {
            for (int i = 0; i < n; i++) {
                buf.push_back(s[p]);
            }
            p++;
            solve();
            return;
        }
        p++;
        int o = p;
        for (int i = 0; i < n-1; i++) {
            solve();
            p = o;
            if (buf.size() > q) return;
        }
        solve();
        if (s[p] == ')') p++;
        solve();
    }
}

int main() {
    while (cin >> s >> q) {
        if (s == "0" && q == 0) break;
        p = 0;
        buf = "";
        solve();
        //cout << buf << ' ';
        cout << (buf.size() > q ? buf[q] : '0') << endl;
    }
    return 0;
}

Measured memory_bytes: 2116
using System;

class Tester
{
    static void Main(string[] args)
    {
        string input = Console.ReadLine();
        int W, H, x, y, r;
        string[] result;

        const char Space = ' ';
        char[] delimiters = new char[] { Space };
        result = input.Split(delimiters);

        W = int.Parse(result[0]);
        H = int.Parse(result[1]);
        x = int.Parse(result[2]);
        y = int.Parse(result[3]);
        r = int.Parse(result[4]);

        if(0<=x&&x<=100&&0<=y&&y<=100&&0<W&&W<=100&&0<H&&H<=100&&0<r&&r<=100&&x+r<=W&&y+r<=H)
        {
            Console.WriteLine("Yes");
        }
        else
        {
            Console.WriteLine("No");
        }
    }
}


Measured memory_bytes: 8844
import fractions
def multi_lcm(a):
    ans = a[0]
    for i in range(1, len(a)):
        ans = ans * a[i] // fractions.gcd(ans, a[i])
    return ans

N = int(input())
T = [int(input()) for _ in range(N)]
print(multi_lcm(T))

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

#define int long long
#define endl "\n"
#define REP(i,a,n) for(int i=a;i<n;++i)
#define REPR(i,a,n) for(int i=a;i>n;--i)
#define RUP(a,b) ((a+b-1)/(b))
#define ALL(v) (v).begin(),(v).end()
#define pb push_back
#define mp make_pair
#define mt make_tuple

typedef long long ll;
typedef pair<int,int> Pii;
typedef tuple<int,int,int> Tiii;
typedef vector<int> Vi;
typedef vector<Vi> VVi;
typedef vector<Pii> VPii;
typedef vector<string> Vs;

template<class T> inline bool chmax(T& a,T b){if(a<b){a=b;return 1;}return 0;}
template<class T> inline bool chmin(T& a,T b){if(a>b){a=b;return 1;}return 0;}
template<class T> void YesNo(T a) {cout<<(a?"Yes":"No")<<endl;}
template<class T> void YESNO(T a) {cout<<(a?"YES":"NO")<<endl;}
int gcd(int a,int b){return b?gcd(b,a%b):a;}
int lcm(int a,int b){return a/gcd(a,b)*b;}
void uniq(Vi &v){sort(v.begin(),v.end()); v.erase(unique(v.begin(),v.end()),v.end());}
const int MOD=1000000007;
const int INF=LLONG_MAX/2;


signed main() {cin.tie(0);cout.tie(0);ios::sync_with_stdio(false);
    int n;
    cin>>n;
    Vi a(n);
    REP(i,0,n) cin>>a[i];
    int count=a[0];
    REP(i,1,n){
        count=a[i]-count;
    }
    Vi ans(n);
    ans[0]=count;
    REP(i,1,n){
        count=2*a[i-1]-count;
        ans[i]=count;
    }
    REP(i,0,n){
        cout<<ans[i];
        if(i<n-1) cout<<" ";
    }
    cout<<endl;
    return 0;
}


Measured memory_bytes: 2944
import java.util.*;
public class Main {
	public static void main(String[] args) {
		 Scanner scan = new Scanner(System.in);
		 call(scan.nextInt());//callへ引数を渡す
	}//main
	public static void call(int n){
		for(int i = 1; i <= n; i++){
			int x = i;
			if(x % 3 == 0){
				//xが3で割り切れる時に出力をする
				System.out.print(" " + i);
			}else{
				while(x != 0){
					if(x % 10 == 3){
						//x/10の余りが3だった時、出力しbreakする
						System.out.print(" " + i);
						break;
					}//if
					x /= 10;
				}//while
			}//if
		}//for
		System.out.println();
	}//call
}

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

std::vector<bool> IsPrime;

void sieve(size_t max){
    if(max+1 > IsPrime.size()){     // resizeで要素数が減らないように
        IsPrime.resize(max+1,true); // IsPrimeに必要な要素数を確保
    } 
    IsPrime[0] = false; // 0は素数ではない
    IsPrime[1] = false; // 1は素数ではない

    for(size_t i=2; i*i<=max; ++i) // 0からsqrt(max)まで調べる
        if(IsPrime[i]) // iが素数ならば
            for(size_t j=2; i*j<=max; ++j) // (max以下の)iの倍数は
                IsPrime[i*j] = false;      // 素数ではない
}

void Main()
{
    int x;
    cin >> x;
    sieve(2*x);
    for (int i = x; i < 2*x; i++)
    {
        if (IsPrime[i]) {
            cout << i << endl;
            return;
        }
    }
}

int main(int argc, char **argv)
{
    ios::sync_with_stdio(false);
    std::cin.tie(nullptr);
    Main();
    return 0;
}


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

int main() {
  string S;
  cin >> S;
  int ans1 = 0, ans2 = 0;
  for (int i = 0; i < S.size(); i += 2) {
    if (S.at(i) == '1') ans2++;
    else ans1++;
  }
  for (int i = 1; i < S.size(); i += 2) {
    if (S.at(i) == '0') ans2++;
    else ans1++;
  }
  cout << min(ans1, ans2) << endl;
}

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

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

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

// #undef DEBUG  // Uncomment this line to forcefully disable debug print.
#if DEBUG
template <typename T>
void debug(T value) {
  std::cerr << value;
}
template <typename T, typename... Ts>
void debug(T value, Ts... args) {
  std::cerr << value << ", ";
  debug(args...);
}
#define dbg(...)                              \
  do {                                        \
    cerr << #__VA_ARGS__ << ": ";             \
    debug(__VA_ARGS__);                       \
    cerr << " (L" << __LINE__ << ")" << endl; \
  } while (0)
#else
#define dbg(...)
#endif

void read_from_cin() {}
template <typename T, typename... Ts>
void read_from_cin(T& value, Ts&... args) {
  std::cin >> value;
  read_from_cin(args...);
}
#define in(type, ...) \
  type __VA_ARGS__;   \
  read_from_cin(__VA_ARGS__);

template <typename T>
void write_to_cout(const T& value) {
  std::cout << value << std::endl;
}
template <typename T, typename... Ts>
void write_to_cout(const T& value, const Ts&... args) {
  std::cout << value << ' ';
  write_to_cout(args...);
}
#define out(...) write_to_cout(__VA_ARGS__);

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

using ll = long long;

using namespace std;

int main() {
  in(int, n, k);
  out(n % k == 0 ? 0 : 1);
}

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

int main() {
	string S;
	cin >> S;
	int min = S.size(), max, c;
	for (int i = 'a';i <= 'z';i ++) {
		c = 0;
		max = 0;
		for (int j = 0;j < S.size();j ++) {
			if (S[j]-i) c ++;
			else c = 0;
			if (max < c) max = c;
		}
		if (min > max) min = max;
	}
	cout << min;
	return 0;
}
// ある文字における手数を求めたいとする。
// この時、これは指定文字間の文字数の最大値に等しい
// 例:whb r jpjyhs r ywlqjxdb r baomnw は3,6,8,6より、8手
// 後は26文字中最小になるものを探せばおｋ

Measured memory_bytes: 256
#include <cstdio>
#include <iostream>
#include <vector>
#include <map>
#include <string>

using namespace std;

int main(void)
{
    int n;
    string s;

    cin >>n;
    cin >>s;

    for(int i = 0; i < s.size(); i++){
        s[i] = 'A' + ((s[i] - 'A' + n) % 26);
    }
    printf("%s\n", s.c_str());

    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <set>

using namespace std;


int main() {

  int n;

  set<int> taro,hanako;
  int stage;
  int winner;
  
  int flag;
  int used[201];


  while(cin >> n,n) {

    taro.clear();

    hanako.clear();

    for(int i=0;i<=200;i++) used[i]=0;

    for(int i=0;i<n;i++) {

      int tmp;

      cin >> tmp;

      used[tmp]=1;

    }

    for(int i=1;i<=2*n;i++) {

      if(used[i]==1) taro.insert(i);

      else hanako.insert(i);

    }

    stage=0;

    while(1) {
      
      // for(set<int>::iterator it=taro.begin();it!=taro.end();it++) cout << *it << " ";

      // cout << " ";

      // for(set<int>::iterator it=hanako.begin();it!=hanako.end();it++) cout << *it << " ";

      // cout << " " << stage << endl;

      //太郎のターン

      //場にカードがない
      if(stage==0) {

	set<int>::iterator it=taro.begin();

	stage=*it;

	taro.erase(it++);

      }

      //場にカードが出ている
      else {

	set<int>::iterator min=taro.begin();
	
	set<int>::iterator max=taro.end();

	flag=0;

	//カードが出せる
	for(set<int>::iterator it=min;it!=max;it++) {

	  if(stage<*it) {

	    stage=*it;

	    taro.erase(it++);
	      
	    flag=1;

	    break;

	  }

	}

	//カードが出せない
	if(flag==0) stage=0;
    
      }

      if(taro.empty()==true) {

	break;

      }

      // for(set<int>::iterator it=taro.begin();it!=taro.end();it++) cout << *it << " ";

      // for(set<int>::iterator it=hanako.begin();it!=hanako.end();it++) cout << *it << " ";

      // cout << " " << stage << endl;

      //花子のターン

      //場にカードがない
      if(stage==0) {

	set<int>::iterator it=hanako.begin();

	stage=*it;

	hanako.erase(it++);

      }

      //場にカードがある
      else {

	set<int>::iterator min=hanako.begin();

	set<int>::iterator max=hanako.end();
	
	flag=0;

	for(set<int>::iterator it=min;it!=max;it++) {

	    //カードが出せる
	    if(stage<*it) {

	      stage=*it;

	      hanako.erase(it++);

	      flag=1;

	      break;

	    }

	  }

	//カードが出せない
	if(flag==0) stage=0;

      }  

      if(hanako.empty()==true) {

	break;

      }
	
    }

    cout << hanako.size() << endl;

    cout << taro.size() << endl;

  }

  return 0;

}
  

Measured memory_bytes: 0
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
deque<char> q;
string s;
int n,t,f,flag=1;
char c;
int main()
{
	ios::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
  	cin>>s;
  	for(int i=0;i<s.size();i++)
  		q.push_back(s[i]);
  	cin>>n;
  	while(n--)
  	{
  		cin>>t;
  		if(t==1) flag=3-flag;
  		else 
  		{
  			cin>>f>>c;
  			if(f==flag)
  			{
  				q.push_front(c);
			}
			else q.push_back(c);
		}
	}
	//cout<<flag<<endl;
	if(flag==1)
	{
		while(q.size())
		{
			cout<<q.front();
			q.pop_front();
		}
	}
	else
	{
		while(q.size())
		{
			cout<<q.back();
			q.pop_back();
		}
	}
  	return 0;
}


Measured memory_bytes: 976
// This amazing code is by Eric Sunli Chen.
#include <algorithm>
#include <bitset>
#include <cmath>
#include <cstring>
#include <cstdio>
#include <cstdlib>
#include <ctime>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <utility>
#include <vector>
using namespace std;
template<typename T> void get_int(T &x)
{
	char t=getchar();
	bool neg=false;
	x=0;
	for(; (t>'9'||t<'0')&&t!='-'; t=getchar());
	if(t=='-')neg=true,t=getchar();
	for(; t<='9'&&t>='0'; t=getchar())x=x*10+t-'0';
	if(neg)x=-x;
}
template<typename T> void print_int(T x)
{
	if(x<0)putchar('-'),x=-x;
	short a[20]= {},sz=0;
	while(x>0)a[sz++]=x%10,x/=10;
	if(sz==0)putchar('0');
	for(int i=sz-1; i>=0; i--)putchar('0'+a[i]);
}
#define ff first
#define ss second
#define pb push_back
#define mp make_pair
#define get1(a) get_int(a)
#define get2(a,b) get1(a),get1(b)
#define get3(a,b,c) get1(a),get2(b,c)
#define printendl(a) print_int(a),puts("")
typedef long long LL;
typedef unsigned long long uLL;
typedef pair<int,int> pii;
const int inf=0x3f3f3f3f;
const LL Linf=1ll<<61;
const double pi=acos(-1.0);

const int mod=1e9+7;

int dp[4111][2111],n,m,k,t;
int main()
{
	get3(n,m,k);
	t=(n+m-1)/(k-1);
	dp[0][0]=1;
	for(int i=0;i<=t;i++)
	{
		for(int j=0;j<=n;j++)
		{
			if(dp[i][j]==0)continue;
			for(int k2=0;k2<k;k2++)
			{
				int nj=j+k2,nj2=(i+1)*(k-1)-nj;
				if(nj>n||nj2>m)continue;
				dp[i+1][nj]+=dp[i][j];
				if(dp[i+1][nj]>=mod)dp[i+1][nj]-=mod;
			}
		}
	}
	int ans=0;
	for(int i=1;i<=t;i++)
	{
		for(int j=n;j>0;j-=k-1)
		{
			if(i==t&&j!=n)continue;
			int j2=i*(k-1)-j;
			if(j2>=m)continue;
			ans+=dp[i][j];if(ans>=mod)ans-=mod;
			ans-=dp[i-1][j];if(ans<0)ans+=mod;
		}
	}
	printendl(ans);
	return 0;
}

Measured memory_bytes: 32128
using System;

namespace track
{
    class Program
    {
        static void Main(string[] args)
        {
            var splitted = System.Console.ReadLine().Split(' ');
            var a = int.Parse(splitted[0]);
            var b = int.Parse(splitted[1]);
            var c = int.Parse(splitted[2]);
            var k = int.Parse(splitted[3]);
            if (k <= a)
            {
                Console.WriteLine(k);
            }
            else if ((a < k)&&(k <= b))
            {
                Console.WriteLine(a);
            }
            else if (b < k)
            {
                var minus = k - ( a + b );
                Console.WriteLine(a - minus);
            }

        }
    }
}

Measured memory_bytes: 27316
import bisect
n,m,k = map(int,input().split())
*a, = map(int,input().split())
*b, = map(int,input().split())

sa = [0] * (n+1)
sa[0] = 0
for i in range(1,n+1):
    sa[i] = sa[i-1] + a[i-1]
sb = [0] * m
sb[0] = b[0]
for i in range(1,m):
    sb[i] = sb[i-1] + b[i]

ans = 0
for i in range(n+1):
    rest = k - sa[i]
    if rest < 0:break
    a_s = i
    b_s = bisect.bisect(sb,rest) 
    ans = max(ans, a_s + b_s)
print(ans)


Measured memory_bytes: 123668
use std::io::*;
use std::str::FromStr;

#[allow(dead_code)]
fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let stdin = stdin.lock();
    let token: String = stdin
        .bytes()
        .map(|c| c.expect("failed to read char") as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().expect("failed to parse token")
}

fn main() {
    let s = read::<String>().chars().collect::<Vec<char>>();
    for i in 0..3 {
        print!("{}", if s[i] == '1' { '9' } else { '1' });
    }
    println!("");
}


Measured memory_bytes: 4352
import java.util.Scanner;

public class Main {
    public static void main(String[] args)
    {
        Scanner input = new Scanner(System.in);
        int K = input.nextInt();
        int X = input.nextInt();
        if(K*500>=X)
            System.out.println("Yes");
        else
            System.out.println("No");
    }
}


Measured memory_bytes: 22612
import java.util.*;

public class Main {
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        while(true){
            int n = sc.nextInt();
            int m = sc.nextInt();
            if(n == 0 && m == 0){
                break;
            }else{
                for(int i = 0; i < n; i++){
                    if(i == 0 || i == n - 1){
                        for(int j = 0; j < m; j++){
                            System.out.print("#");
                        }
                        System.out.println("");
                    }else{
                        for(int j = 0; j < m; j++){
                            if(j == 0 || j == m - 1){
                                System.out.print("#");
                            }else{
                                System.out.print(".");
                            }
                        }
                        System.out.println("");
                    }
                }
                
            }
            System.out.println();
            
        }
    }
}


Measured memory_bytes: 32272
#include<stdio.h>
int main(){
  
    int A;
    int B;
  
    if(2<=A<=100, 2<=B<=100){
  	   scanf("%d", &A);
       scanf("%d", &B);
  
       printf("%d\n", (A - 1) * (B - 1));
    }
  
return 0;
}


Measured memory_bytes: 128
//AtCoder 
#include <bits/stdc++.h>
using namespace std;
using ll=int64_t;
int main() {
#if LOCAL&0
    std::ifstream in("./test/sample-1.in"); //input.txt
    std::cin.rdbuf(in.rdbuf());
#endif
    ll l,r; cin>>l>>r;
    ll modmin=20000;
    ll modmin2=20000;
    for(ll i=l;i<=r;++i){
        if(i%2019==0) {
            cout<<0<<endl;
            return 0;
        }
    }
    ll ans=2000000;
    ll tl=l%2019;
    ll tr=r%2019;
    for(ll i=tl;i<=tr;++i){
        for(ll j=tl;j<=tr;++j){
            if(i<j) {
                ll tmp= i*j%2019;
                ans=min((i*j)%2019,ans);
            }
        }
    }
    cout<<ans<<endl;
    return 0;
}

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

int main()
{
  string S;
  cin >> S;
  bool ans = true;
  if (S[0] != 'A')
    ans = false;
  string substr = S.substr(2, S.size() - 3);
  int ccnt = 0;
  int cindex = 0;
  for (int i = 0; i < substr.size(); i++)
  {
    if (substr[i] == 'C')
    {
      ccnt++;
      cindex = i + 2;
    }
  }
  if (ccnt != 1)
    ans = false;
  for (int i = 0; i < S.size(); i++)
  {
    if (i == 0 or i == cindex)
      continue;
    if (islower(S[i]) == 0)
      ans = false;
  }
  if (ans)
    cout << "AC" << endl;
  else
    cout << "WA" << endl;
}


Measured memory_bytes: 256
N = int(input())
Already = []
W = input()
Already.append(W)
prevWord = W
flag = True
for i in range(N-1):
    W = input()
    for j in Already:
        if j == W:
            flag = False

    if W[0] != prevWord[-1]:
        flag = False
    
    Already.append(W)
    prevWord = W

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

Measured memory_bytes: 3064
using System;
using System.Collections.Generic;
using System.IO.Pipes;
using System.Linq;
using System.Text;

namespace cswork
{
    class Program
    {
        class Scanner
        {
            string[] s;
            int i;

            char[] cs = new char[] { ' ' };

            public Scanner()
            {
                s = new string[0];
                i = 0;
            }

            public string next()
            {
                if (i < s.Length) return s[i++];
                string st = Console.ReadLine();
                while (st == "") st = Console.ReadLine();

                s = st.Split(cs, StringSplitOptions.RemoveEmptyEntries);
                i = 0;
                return next();
            }

            public int nextInt()
            {
                return int.Parse(next());
            }

            public long nextLong()
            {
                return long.Parse(next());
            }

            public double nextDouble()
            {
                return double.Parse(next());
            }
        }

        public Program() { }

        static void Main(string[] args)
        {
            new Program().Omame();
        }

        Scanner cin;
        const int MAXIN = 1024;
        bool[] used = new bool[MAXIN];
        int[] perm = new int[MAXIN];

        List<int[]> permList = new List<int[]>();

        public void Permutation(int pos, int n, int length)
        {
            if (pos == n)
            {
                permList.Add((int[])perm.Clone());
            }

            for (int i = 0; i < n; i++)
            {
                if (!used[i])
                {
                    perm[pos] = i;
                    used[i] = true;
                    Permutation(pos + 1, n, length);
                    used[i] = false;
                }
            }
        }

        void Omame()
        {
            cin = new Scanner();
            long N = cin.nextLong();
            long A = cin.nextLong();
            long B = cin.nextLong();

            long count = N / (A + B) * A;
            if(N%(A+B) >= A)
            {
                count += A;
            }
            else
            {
                count += N % (A + B);
            }
            Console.Write(count);
        }

    }
}


Measured memory_bytes: 13268
# できるだけ正数が多いほうが良い。隣り合う負数は正にできる
# あと-+++++は+++++-のように-を移動できるので隣り合わせられる
# -が奇数なら0以上の最小の数に-を割り当ててあとは合計
# 偶数ならすべての-を+にできる

from functools import reduce

n = int(input())
minn = 10**9
arr = list(map(int, input().split()))
minus = 0
ans = reduce(lambda x, y: abs(x) + abs(y), arr)
for i in range(n):
    if arr[i] < 0:
        minus += 1
    if minn > abs(arr[i]):
        minn = abs(arr[i])
if minus % 2 == 0:
    print(ans)
else:
    print(ans-minn*2)


Measured memory_bytes: 64752
#pragma GCC optimize("Ofast")
#include<bits/stdc++.h>
#include <boost/multiprecision/cpp_dec_float.hpp>
#include <boost/multiprecision/cpp_int.hpp>
#include <boost/numeric/interval.hpp>
#include <boost/numeric/interval/io.hpp>
#include <boost/any.hpp>
using namespace::std;
namespace mp = boost::multiprecision;
typedef mp::number<mp::cpp_dec_float<32,int64_t>> cfloat;
typedef mp::cpp_int cint;
typedef long long lint;
typedef long long ll;
typedef long double ldouble;
typedef vector<lint> vec;
typedef vector<vector<lint>> mat;
typedef vector<vector<vector<lint>>> mat3;
typedef vector<double> dvec;
typedef vector<vector<double>> dmat;
typedef vector<vector<vector<double>>> dmat3;
typedef vector<string> svec;
typedef vector<vector<string>> smat;
typedef vector<vector<vector<string>>> smat3;
typedef vector<pair<lint,lint>> pvec;
typedef vector<vector<pair<lint,lint>>> pmat;
typedef vector<vector<vector<pair<lint,lint>>>> pmat3;
#define rep(i, n) for(lint i = 0; i < (lint)(n); i++)
#define irep(i) for(lint i = 0;; i++)
#define irep1(i) for(lint i = 1;; i++)
#define irep2(i) for(lint i = 2;; i++)
#define rrep(i, n) for(lint i = (lint)(n-1); i >-1; i--)
#define rrepi(i,a,b) for(lint i = (lint)(b-1); i >a-1; i--)
#define repi(i,a,b) for(lint i=lint(a);i<lint(b);i++)
#define rep2(i,a,b,c) for(lint i=lint(a);i>lint(b);i+=c)
#define all(x) (x).begin(),(x).end()
#define PI 3.141592653589793
#define cout (cout<<fixed<<setprecision(15))
#define dist(x1,y1,x2,y2) (pow(pow(x2-x1,2)+pow(y2-y1,2),0.5))
#define output(v) do{bool f=0;for(auto i:v){cout<<(f?" ":"")<<i;f=1;}cout<<"\n";}while(0)
#define output2(v) for(auto i:v)output(i);
#define input(a,n) lint n;cin>>n;vector<lint>a(n);rep(i,n)cin>>a[i];
#define sum(v) accumulate(all(v),0LL)
#define INF (1LL<<60)
#define IINF (1<<30)
#define LINF 9223372036854775807
#define MOD 1000000007
vector<lint> dx={-1,1,0,0,1,1,-1,-1};
vector<lint> dy={0,0,-1,1,1,-1,1,-1};
inline lint gcd(lint a,lint b){return b?gcd(b,a%b):a;}
inline lint lcm(lint a,lint b){return a*b/gcd(a,b);}
int main(){
    lint n;
    cin>>n;
    dvec v(n);
    rep(i,n)cin>>v[i];
    sort(all(v));
    double ans=v[0];
    repi(i,1,n){
        ans=(ans+v[i])*0.5;
    }
    cout<<ans;
}

Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main(void){
    int r, c;
    cin >> r >> c;
    
    int *table;
    table = new int[(r + 1) * (c + 1)];
    
    int i, j;
    int rowsum, colsum;
    
    for(i = 0; i < r; i++){
        rowsum = 0;
        for(j = 0; j < c; j++){
            cin >> table[(c + 1) * i + j];
            rowsum += table[(c + 1) * i + j];
        }
        table[(c + 1) * i + c] = rowsum;
    }
    
    for(j = 0; j <= c; j++){
        colsum = 0;
        for(i = 0; i < r; i++){
            colsum += table[(c + 1) * i + j];
        }
        table[(c + 1) * r + j] = colsum;
    }
    
    for(i = 0; i <= r; i++){
        for(j = 0; j <= c; j++){
            if(j) cout << " ";
            cout << table[(c + 1) * i + j];
        }
        cout << endl;
    }
    delete[] table;
    return 0;
}

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

  int n,m,p[1000],sum=0,sum1=0,i,j,blank;

  while(1){

  scanf("%d %d",&n,&m);
  if(n == 0 && m == 0) break;
  sum=0;
  sum1=0;

  for(i = 0; i < n; i++){

    scanf("%d",&p[i]);
    sum	+= p[i];

  }

  for(i = 0; i < n-1; i++){

    for(j = 0; j < n-1; j++){

      if(p[j] < p[j+1]){
	
        blank=p[j];
        p[j]=p[j+1];
        p[j+1]=blank;

      }

    }

  }

  for(i = m-1; i < n; i += m) sum1 += p[i];

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

  }


  return 0;

}

Measured memory_bytes: 604
//pragma
//#pragma GCC optimize("Ofast")
//#pragma GCC optimize("unroll-loops")

#include <bits/stdc++.h>

#define YOU using
#define DONT namespace
#define SAY std

YOU DONT SAY;

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

#define REPP(i,a,b,d) for(int i=a;i<=b;i+=d)
#define REP(i,a,b) REPP(i,a,b,1)
#define REVV(i,a,b,d) for(int i=a;i>=b;i-=d)
#define REV(i,a,b) REVV(i,a,b,1)

#define FOR(i,a) for(int i=0; i<a; i++)
#define FORD(i,a) for(int i=(int)a-1; i>=0; i--)

#define pb push_back
#define F first
#define S second

const int OO = 1e9;
const ll INF = 1e18;

const int irand(int lo,int hi){
	return ((double)rand()/(RAND_MAX + 1.0)) * (hi-lo+1) + lo;
}

const ll lrand(ll lo,ll hi){
	return ((double)rand()/(RAND_MAX + 1.0)) * (hi-lo+1) + lo;
}

#define getc getchar
template<typename T>
T getnum(){
	int sign = 1;
	T ret = 0;
	char c;

	do{
		c = getc();
	}while(c == ' ' || c == '\n');
	if(c == '-')sign = -1;
	else ret = c-'0';
	while(1){
		c = getc();
		if(c < '0' || c > '9')break;
		ret = 10*ret + c-'0';
	}
	return sign * ret;
}

inline void ini(int& x){
	x = getnum<int>();
}

inline void scani(int& x){
	scanf("%d",&x);
}

//end of macro

const int N = 1e5 + 5;

int x,k,q;
vi r;

vii qq;
int t[N], a[N];
int ans[N];

int main(){
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    #define endl '\n'
    cout.setf(ios::fixed);
    cout.setf(ios::showpoint);
    cout.precision(10);
    
    cin>>x>>k;
    REP(i,1,k){
    	int t;
    	cin>>t;
    	r.pb(t);
	}
	cin>>q;
	REP(i,1,q){
		cin>>t[i]>>a[i];
		qq.pb({t[i], i});
	}
	sort(qq.begin(), qq.end());
	
	int lo = 0, hi = x, vlo = 0;
	int dir = -1, prev = 0;
	int p = 0;
	
	FOR(i,k){
		while(p < qq.size() && qq[p].F <= r[i]){
			int qid = qq[p++].S;
//			printf("solve %d\n",qid);
			int curr = lo;
			if(a[qid] > vlo)curr += a[qid] - vlo;
			if(curr > hi)curr = hi;
//			printf("curr %d\n",curr);
			
			curr += dir * (t[qid] - prev);
			curr = max(0, min(x, curr));
			ans[qid] = curr;
		}
		
		int dif = r[i] - prev;
		prev = r[i];
		lo += dir * dif;
		hi += dir * dif;
		hi = max(0, min(x, hi));
		if(lo < 0){
			vlo += -lo;
			if(vlo > x)vlo = x;
			lo = 0;
		}
		if(lo > x)lo = x;
		
		if(dir == -1)dir = 1;
		else dir = -1;
		
//		printf("at %d, lo %d hi %d, vlo %d\n",r[i],lo,hi,vlo);
	}
	
	while(p < qq.size()){
		int qid = qq[p++].S;
//		printf("solve %d\n",qid);
		int curr = lo;
		if(a[qid] > vlo)curr += a[qid] - vlo;
		if(curr > hi)curr = hi;
//		printf("curr %d\n",curr);
		
		curr += dir * (t[qid] - prev);
		curr = max(0, min(x, curr));
		ans[qid] = curr;
	}
	
	REP(i,1,q)cout << ans[i] << endl;
    
    return 0;
}

Measured memory_bytes: 3700
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <map>
#include <queue>
#include <cmath>
#include <stack>


int main (void){

	int grid[3][3];

	for (size_t i = 0; i < 3; i++)
	{
		for (size_t j = 0; j < 3; j++)
		{
			std::cin >> grid[i][j];
		}
	}

	for (size_t a1 = 0; a1 < 101; a1++)
	{
		int b1 = grid[0][0] - a1;
		int b2 = grid[0][1] - a1;
		int b3 = grid[0][2] - a1;

		if (grid[1][0] - b1 != grid[1][1] - b2 || grid[1][1] - b2 != grid[1][2] - b3) {
			continue;
		}

		if (grid[2][0] - b1 != grid[2][1] - b2 || grid[2][1] - b2 != grid[2][2] - b3) {
			continue;
		}

		std::cout << "Yes" << std::endl;
		return 0;
	}

	std::cout << "No" << std::endl;

	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define syosu(x) fixed<<setprecision(x)
using namespace std;
typedef long long ll;
typedef unsigned int uint;
typedef unsigned long long ull;
typedef pair<int,int> P;
typedef pair<double,double> pdd;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<string> vs;
typedef vector<P> vp;
typedef vector<vp> vvp;
typedef vector<pll> vpll;
typedef pair<int,P> pip;
typedef vector<pip> vip;
const int inf=1<<30;
const ll INF=1ll<<60;
const double pi=acos(-1);
const double eps=1e-8;
const ll mod=1e9+7;
const int dx[4]={-1,0,1,0},dy[4]={0,-1,0,1};

int n;

int main(){
	cin>>n;
	vl dp(n,0);
	dp[0]++;
	int t=0;
	for(int i=0;i<n;i++){
		char c;
		cin>>c;
		if(c=='-') continue;
		vl DP(n);
		if(c=='U'){
			for(int j=0;j<n;j++) if(dp[j]){
				(DP[j]+=dp[j]*j)%=mod;
				if(j+1<n) (DP[j+1]+=dp[j]*(t-j+1))%=mod;
			}
			t++;
		}
		else{
			for(int j=0;j<n;j++) if(dp[j]){
				(DP[j]+=dp[j]*(t-j))%=mod;
				if(j) (DP[j-1]+=dp[j]*j)%=mod;
			}
		}
		dp=DP;
	}
	cout<<dp[0]<<endl;
}


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

typedef long long ll;

ll N, M;

ll lcm(ll number1, ll number2){
	return number1 * number2 / std::__gcd(number1, number2);	
}

ll f(ll x) {
    ll ans = 0;
    while (x % 2 == 0 && x > 0) {
        x /= 2;
        ans++;
    }

    return ans;
}

int main() {
    // cout << (14 >> 2) << endl;
    // return 0;
    // int d = f(0);
    // int d2 = f(12);
    // cout << d << endl;
    // cout << d2 << endl;
    // return 0;

    cin >> N >> M;
    vector<ll> a(N);

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

    rep(i, N) {
        a[i] /= 2;
    }

    // 奇数で計算できるようにするため 2で何回割れるか数える    
    ll t = f(a[0]);
    for (int i = 0; i < a.size(); i++) {
        ll tmp = f(a[i]);    
        if (t != tmp) {
            cout << 0 << endl;
            return 0;
        }

        a[i] >> t;
    }
    M >> t;

    ll num = a[0];
    for (int i = 1; i <= a.size() - 1; i++) {
        // if (num > M) {
        //     cout << 0 << endl;
        //     return 0;
        // }
        num = lcm(num, a[i]);    
    }

    ll x = M / num;
    cout << (x + 1) / 2 << endl;
}

Measured memory_bytes: 1024
{-# LANGUAGE BangPatterns #-}

module Main
  ( main
  )
where

import           Control.Applicative
import           Control.Monad
import           Data.Bits
import qualified Data.ByteString.Char8         as BS
import           Data.Char
import           Data.List
import           Data.Maybe
import qualified Data.Vector                   as V
import qualified Data.Vector.Mutable           as MV
import           Control.Monad.ST
import           Data.Ord
import qualified Data.Vector.Unboxed           as UV

parse = fst . fromJust
parseInt = parse . BS.readInt
parseInteger = parse . BS.readInteger
readInt = parseInt <$> BS.getLine
readInteger = parseInteger <$> BS.getLine
readIntList = map parseInt . BS.words <$> BS.getLine
readIntegerList = map parseInteger . BS.words <$> BS.getLine

main = do
  r <- (read::String -> Double) <$> getLine
  print $ 2.0 * pi * r


Measured memory_bytes: 4056
#include <iostream>
#include <stdint.h>
#include <memory>

using namespace std;
#define REP(I,SIZE) for(int64_t I = 0;I < (int64_t)SIZE;I++)

using group = pair<int,int>;

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

  // unique_ptr<group[]> g(new group[N]);

  int sum = 0;

  REP(i,N){
    int tmp[2];
    cin >> tmp[0];
    cin >> tmp[1];
    sum += tmp[1] - tmp[0] + 1;
    // cin >> g[i].first;
    // cin >> g[i].second;
  }

  cout << sum << "\n";


}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
// C - Traveling Salesman around Lake

int main()
{
    long long A, B, C, a, b, c;
    cin >> A >> B >> C;
    if (A == B && B == C)
    {
        if (A % 2 != 0 )
        {
            cout << 0 << endl;
            return 0;
        }
        else
        {
            cout << -1 << endl;
            return 0;
        }
    }

    int count = 0;
    
    while (1)
    {
        if (A % 2 != 0 || B % 2 != 0 || C % 2 != 0)
            break;
        count++;

        a = B / 2 + C / 2;
        b = C / 2 + A / 2;
        c = A / 2 + B / 2;
        A = a;
        B = b;
        C = c;
    }

    cout << count << endl;
}

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

int main() {
    int A, B, K;
    cin >> A >> B >> K;

    for (int i = 0; i < K; i++) {
        if (i % 2) {
            if (B % 2) {
                B--;
            }
            A += (B / 2);
            B = B / 2;
        }
        else {
            if (A % 2) {
                A--;
            }
            B += (A / 2);
            A = A / 2;
        }

    }

    cout << A << " " << B << endl;
}

Measured memory_bytes: 256
//#include <bits/stdc++.h>
#include<iostream>
#include<iomanip>
#include<numeric>
#include<cstdio>
#include<cmath>
#include<string>
#include<algorithm>
#include<vector>
#include<map>
#include<stack>
#include<queue>
#include<ctype.h>
#include <fstream>
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REP(i,n) FOR(i,0,n)
using namespace std;
typedef long long ll;//int64
typedef unsigned long long ull;
int gcd(int a,int b){return b?gcd(b,a%b):a;}
int lcm(int a,int b){return a*b/gcd(a,b);}
int dy[4]={0,1,0,-1};
//----------program from here----------

int main(){
  ull N=0,K=0,m=1000000000;
  cin >> N >> K;

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

  sort(h, h+N);

  --K;
  for(int i=0;i<N-K;++i){
    m = min(m, h[i+K]-h[i]);
  }
  cout << m << endl;

  return 0;
}

Measured memory_bytes: 1024
use proconio::{input, fastout};
use proconio::marker::{Chars};
use proconio::marker::Usize1;
use std::cmp::*;

macro_rules! debug {
      ($($a:expr),*) => {
          eprintln!(concat!($(stringify!($a), " = {:?}, "),*), $($a),*);
    }
}

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

    for i in 0..n {
        let mut sum = 0;
        for j in 0..n {
            if i!=j {
                sum += l[j];
            }
        }
        if l[i]>=sum {
            println!("No");
            return;
        } 
    }
    println!("Yes");
}


Measured memory_bytes: 2156
#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;
int a, b;
vector<pair<int, int> >a1, a2;
int main() {
	while (true) {
		a1.clear(); a2.clear();
		cin >> a >> b; if (a == 0 && b == 0)break;
		for (int i = 1; i*i <= a; i++) {
			if (a%i == 0)a1.push_back(make_pair(i, a / i));
		}
		for (int i = 1; i*i <= b; i++) {
			if (b%i == 0)a2.push_back(make_pair(i, b / i));
		}
		int minx = 1 << 30;
		for (int i = 0; i < a1.size(); i++) {
			for (int j = 0; j < a2.size(); j++) {
				int p[4] = { a1[i].first,a1[i].second,a2[j].first,a2[j].second };
				sort(p, p + 4);
				int W = (p[3] - p[2])*(p[3] - p[2]) + (p[2] - p[1])*(p[2] - p[1]) + (p[1] - p[0])*(p[1] - p[0]);
				minx = min(minx, W);
			}
		}
		cout << minx << endl;
	}
	return 0;
}

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

int main(){
  int n,q,a[10000+1],key,cnt=0;
  cin >> n;
  for(int i=0;i<n;i++) cin >> a[i];
  cin >> q;
  for(int j=0;j<q;j++){
    cin >> key;
    for(int i=0;i<n;i++){
      if(a[i]==key){
        cnt++;
        break;
      }
    }
  }
  cout << cnt << endl;
  return 0;
}

Measured memory_bytes: 1196
#include <cstdio>
#include <iostream>
#include <cstring>
#include <string>
#include <cstdlib>
#include <utility>
#include <cctype>
#include <algorithm>
#include <bitset>
#include <set>
#include <map>
#include <vector>
#include <queue>
#include <deque>
#include <stack>
#include <cmath>
#define ll long long
#define lb long double
#define x first
#define y second
#define pair pair<int,int>
#define pb push_back
#define pf push_front
#define mp make_pair
#define lowbit(x) x & (-x)
using namespace std;

const int mod=1e9+7;
const ll linf=2e16;
const int inf=2e9;
const int magic=348;
const double eps=1e-10;
const double pi=3.14159265;

inline int getint()
{
    char ch;int res;bool f;
    while (!isdigit(ch=getchar()) && ch!='-') {}
    if (ch=='-') f=false,res=0; else f=true,res=ch-'0';
    while (isdigit(ch=getchar())) res=res*10+ch-'0';
    return f?res:-res;
}

int n;
int a[200048],b[200048],bb[200048];
ll cnt[48];

inline int binsearch_down(int cmp)
{
	int l=1,r=n,mid,res=n+1;
	while (l<=r)
	{
		mid=(l+r)>>1;
		if (bb[mid]>=cmp) res=mid,r=mid-1; else l=mid+1;
	}
	return res;
}

inline int binsearch_up(int cmp)
{
	int l=1,r=n,mid,res=0;
	while (l<=r)
	{
		mid=(l+r)>>1;
		if (bb[mid]<cmp) res=mid,l=mid+1; else r=mid-1;
	}
	return res;
}

int main ()
{
	int i,bit,cc;n=getint();
	for (i=1;i<=n;i++) a[i]=getint();
	for (i=1;i<=n;i++) b[i]=getint();
	memset(cnt,0,sizeof(cnt));
	for (bit=1;bit<=30;bit++)
	{
		for (i=1;i<=n;i++) bb[i]=(b[i]&((1<<bit)-1));
		sort(bb+1,bb+n+1);
		for (i=1;i<=n;i++)
		{
			cc=(((1<<(bit-1))-1)&a[i]);
			if (a[i]&(1<<(bit-1)))
				cnt[bit]+=binsearch_up((1<<(bit-1))-cc)+(n-(binsearch_down((1<<bit)-cc)-1));
			else
				cnt[bit]+=binsearch_up((1<<bit)-cc)-binsearch_down((1<<(bit-1))-cc)+1;
		}
	}
	int ans=0;
	for (i=1;i<=30;i++)
		if (cnt[i]%2==1) ans^=(1<<(i-1));
	printf("%d\n",ans);
	return 0;
}


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

using namespace std;
vector<int> N[100009];
int p[100009], d[100009], deepest[100009];

int calc_deepest(int k){
  if(deepest[k]!=-1)return deepest[k];
  int ret=d[k];
  for(int i=0;i<N[k].size();i++){
    if(N[k][i]!=p[k]){
      ret=max(ret, calc_deepest(N[k][i]));
    }
  }
  return deepest[k] = ret;
}

int main(){
  int n, u, v;
  cin >> n >> u >> v;
  u--;v--;
  for(int i=0;i<n-1;i++){
    int a, b;
    cin >> a >> b;
    a--;b--;
    N[a].push_back(b);
    N[b].push_back(a);
  }
  memset(d, -1, sizeof(d));
  memset(deepest, -1, sizeof(deepest));
  p[v]=-1;
  d[v]=0;
  queue<int> q;
  q.push(v);
  while(!q.empty()){
    int t=q.front();q.pop();
    for(int i=0;i<N[t].size();i++){
      if(d[N[t][i]]==-1){
        d[N[t][i]]=d[t]+1;
        p[N[t][i]]=t;
        q.push(N[t][i]);
      }
    }
  }
  calc_deepest(v);
  int c=u, a=0;
  int cnt=0;
  while(d[c]-1>a+1){
    c=p[c];
    a++;
    cnt++;
  }
  int t=d[c];
  int deep=deepest[c];
  while(t!=a){
    if(t==deep){
      t--;
    }
    else t++;
    if(t==a)break;
    a++;
    cnt++;
  }
  cout << cnt << endl;
}


Measured memory_bytes: 13916
#include <stdio.h>

int bubble_sort(int *a, int n);
void swap(int *a, int *b);

int main(int argc, char const *argv[])
{
  int i,n, a[100],count;
  scanf("%d", &n);
  for(i=0;i<n;i++) {
    scanf("%d", a+i);
  }
  count=bubble_sort(a,n);
  for(i=0;i<n-1;i++) {
    printf("%d ", *(a+i));
  }
  printf("%d\n", *(a+i));
  printf("%d\n", count);
  return 0;
}

int bubble_sort(int *a, int n)
{
  int i, count=0, flag;
  flag = 1;
  while (flag) {
    flag = 0;
    for(i=n-1;i>0;i--) {
      if(a[i] < a[i-1]) {
        swap(a+i,a+i-1);
        count++;
        flag=1;
      }
    }
  }
  return count;
}

void swap(int *a, int *b)
{
  int temp;
  temp = *a;
  *a = *b;
  *b = temp;
}

Measured memory_bytes: 2696
import sys

sys.setrecursionlimit(10 ** 7)


def dfs(v, parent, odd):
    hi = INF
    lo = -INF
    if fixed[v] != INF:
        if odd_even[v] != odd:
            print('No')
            exit()
        hi = lo = fixed[v]
    for u in links[v]:
        if u == parent:
            continue
        chi, clo = dfs(u, v, odd ^ 1)
        if hi < clo or chi < lo:
            print('No')
            exit()
        hi = min(hi, chi)
        lo = max(lo, clo)
    upper[v] = hi
    lower[v] = lo
    return hi + 1, lo - 1


def fill(v, parent, pp):
    if pp + 1 > upper[v]:
        assert pp - 1 >= lower[v]
        vp = fixed[v] = pp - 1
    else:
        vp = fixed[v] = pp + 1
    for u in links[v]:
        if u == parent:
            continue
        fill(u, v, vp)


inp = list(map(int, sys.stdin.buffer.read().split()))
n = inp[0]
links = [set() for _ in range(n)]
for a, b in zip(inp[1:2 * n - 1:2], inp[2:2 * n - 1:2]):
    a -= 1
    b -= 1
    links[a].add(b)
    links[b].add(a)
INF = 10 ** 9
k = inp[2 * n - 1]
fixed = [INF] * n
odd_even = {}
fixed_v = 0
for v, p in zip(inp[2 * n::2], inp[2 * n + 1::2]):
    v -= 1
    fixed[v] = p
    odd_even[v] = p % 2
    fixed_v = v

lower = [-INF] * n
upper = [INF] * n
dfs(fixed_v, -1, odd_even[fixed_v])
fill(fixed_v, -1, fixed[fixed_v] + 1)
print('Yes')
print('\n'.join(map(str, fixed)))


Measured memory_bytes: 151964