akhauriyash/Code-Regression huggingface dataset:
/*
 * FileName:     stack_model
 * CreatedDate:  2020-05-23 23:19:48 +0900
 * LastModified: 2020-05-23 23:31:24 +0900
 */

#include<stdio.h>
#include<stdlib.h>
static const int MAX_N = 1000;

typedef struct Node{
    int data;
    struct Node *under;
}node_str;
typedef struct Stack{
    node_str *top;
}stack_str;

stack_str *CreateStack(){
    stack_str *S = malloc(sizeof(stack_str));
    S->top = NULL;
    return S;
}
void push(stack_str *S, int x){
    if(S->top == NULL){
	S->top = malloc(sizeof(node_str));
	S->top->data = x;
	S->top->under = NULL;
    }else{
	node_str *bf = malloc(sizeof(node_str));
	bf->under = S->top;
	bf->data = x;
	S->top = bf;
    }
}
void top(stack_str *S){
    if(S->top == NULL) return;
    printf("%d\n", S->top->data);
}
void pop(stack_str *S){
    if(S->top == NULL) return;
    if(S->top->under == NULL){
	free(S->top);
	S->top = NULL;
	return;
    }
    node_str *bf = S->top->under;
    free(S->top);
    S->top = bf;
}
void deleteStack(stack_str *S){
    if(S->top == NULL) return;
    node_str *cur = S->top;
    for(;;){
	if(cur->under == NULL){
	    free(cur);
	    break;
        }
	node_str *bf = cur->under;
	free(cur);
	cur = bf;
    }
    free(S);
}

int main(){
    int n, q;
    scanf("%d %d", &n, &q);
    stack_str *S[MAX_N];
    for(int i = 0; i < n; i++) S[i] = CreateStack();
    for(int i = 0; i < q; i++){
	int op, t;
	scanf("%d %d", &op, &t);
	if(op == 0){
	    int x;
	    scanf("%d", &x);
	    push(S[t], x);
	}else if(op == 1){
	    top(S[t]);
	}else if(op == 2){
	    pop(S[t]);
	}
    }
    for(int i = 0; i < n; i++) deleteStack(S[i]);
    return 0;
}



Measured memory_bytes: 7968
#include<stdio.h>
int main(){
  char cm[36],sm[36],a,e[3];
  int n,i,j,c,m,d,f=0;
  int cn[36],sn[36];
  scanf("%d",&n);
  for(i=0;i<n;i++){
    scanf("%s",e);
    cm[i] = e[0];
    cn[i]  = e[1] - '0';
  }
  for(i=0;i<n;i++){
    sn[i]=cn[i];
    sm[i]=cm[i];
  }

  for(i=0;i<n;i++){
    for(j=n-1;j>i;j--){
      if(cn[j]<cn[j-1]){
	c=cn[j];
	cn[j]=cn[j-1];
	cn[j-1]=c;
	a=cm[j];
	cm[j]=cm[j-1];
	cm[j-1]=a;
      }
    }
  }
 
  for(i=0;i<n;i++){
    m=i;
    for(j=i;j<n;j++){
      if(sn[j]<sn[m]){
	m=j;
	d=1;
      }
    }
    if(d==1){
      c=sn[i];
      sn[i]=sn[m];
      sn[m]=c;
      a=sm[i];
      sm[i]=sm[m];
      sm[m]=a;
      d=0;
    }
  }
  for(i=0;i<n;i++){
    if(cm[i]!=sm[i]) f=1;
    if(cn[i]!=sn[i]) f=1;
  }

  for(i=0;i<n-1;i++){
    printf("%c%d ",cm[i],cn[i]);
  }
  printf("%c%d\n",cm[n-1],cn[n-1]);
  printf("Stable\n");
   
  
  for(i=0;i<n-1;i++){
    printf("%c%d ",sm[i],sn[i]);
  }
  printf("%c%d\n",sm[n-1],sn[n-1]);
  if(f==1) printf("Not stable\n");
  else printf("Stable\n");
  return 0;

 
}




Measured memory_bytes: 2108
#include<bits/stdc++.h>
using namespace std;
#define loop(i,L,R) for(int i=(L);i<=(R);i++)
#define rept(i,L,R) for(int i=(L);i<(R);i++)
#define isc(n) scanf("%d",&n)
#define llsc(n) scanf("%lld",&n)
#define dsc(n) scanf("%lf",&n)
#define enl cout<<endl
#define pb(x) push_back(x)
#define xx first
#define yy second
typedef long long ll;
typedef pair<int,int>PI;
typedef pair<pair<int,int>,int>PII;

int main()
{
    string s,t;
    cin>>s>>t;
    sort(t.begin(),t.end());
    reverse(t.begin(),t.end());
    sort(s.begin(),s.end());
    if(s<t)cout<<"Yes"<<endl;
    else cout<<"No"<<endl;
	return 0;
}


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

#define watch(x) cerr << (#x) << ": " << (x) << endl
#define int long long

struct item {
    int gain;
    int cost;

    bool operator<(const item& other) const {
        return gain*other.cost < other.gain*cost;
    }
};

item make_item(int g, int c) {
    item i;
    i.gain = g;
    i.cost = c;
    return i;
}

int32_t main() {

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

    int curSum = 0;
    for(int aa : a) curSum += aa;
    
    int p = 0;
    while(1ll << p <= k) {
        p++;
    }
    int x = 0;
    for(int i = p-1; i >= 0; --i) {
        int mask = 1ll << i;
        int count = 0;
        for(int aa : a) {
            if(aa & mask)
                count++;
        }
        if(count*2 < n) {
            if(x + mask <= k) x += mask;
        }
    }
    int ret = 0;
    for(int i = 0; i < n; ++i) ret += (a[i] ^ x);
    cout << ret << endl;
    return 0;
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define all(x) x.begin(), x.end()
#define sortvec(x) sort(all(x))
#define compress(x) x.erase(unique(all(x)), x.end())
using namespace std;
typedef long long LL;
typedef pair<int, int> pii;
typedef pair<LL, LL> pll;
typedef pair<int, LL> pil;
typedef pair<LL, int> pli;
const LL llinf=1987654321987654321;
const int inf=2000000000;
int n, k;
LL ans;
int main(){
    scanf("%d %d", &n, &k);
    if(k%2==0)ans=(LL)((n+k/2)/k)*((n+k/2)/k)*((n+k/2)/k);
    ans+=(LL)(n/k)*(n/k)*(n/k);
    printf("%lld", ans);
}


Measured memory_bytes: 256
N, M = map(int, input().split())
AB = [[int(i) for i in input().split()] for _ in range(M)]

class UnionFind :
  def __init__(self, N) :
    self.parent = [-1] * N
      
  def root(self, x) :
    while self.parent[x] >= 0:
      x = self.parent[x]
    return x

  def unite(self, x, y) :
    rx = self.root(x)
    ry = self.root(y)

    if rx != ry :
      if self.parent[rx] > self.parent[ry] :
        self.parent[rx] = ry
      else :
        if self.parent[rx] == self.parent[ry] :
          self.parent[rx] -= 1
        self.parent[ry] = rx

  def same(self, x, y) :
    return self.root(x) == self.root(y)
      
  def size(self, x) :
    return -self.parent[self.root(x)]
    
UF = UnionFind(N)
for A, B in AB :
  A -= 1
  B -= 1
  UF.unite(A, B)
  
c = [0] * N
for i in range(N) :
  c[UF.root(i)] += 1
print(max(c))

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

int dif='a'-'A';
void outU( string &s ){
  char c;
  for(unsigned int i=0;i<s.size();i++ ){
    c=s.at( i );
    if( i==0 ) c-= dif;
    cout << c;
  }
}

int main(){
  string name, type;
  string names[100];
  int nw;

  while( true ){
    cin >> name >> type;
    //    cout << name << "," << type << endl;

    if( type=="X" ) break;

    for( int i=0;i<100;i++ )names[i]="";

    nw=0;
    char c;
    for( unsigned int i=0; i<name.size();i++ ){
      c = name.at(i);
      if( c== '_' ) nw++;
      else if( c<='Z'){
	c+= dif;
	if( names[nw].size()!=0 ){
	  nw++; names[nw]="";
	}
	names[nw] += c;
      }else
	names[nw] += c;
    }
    if( c!='_' )
      nw++;

    //    cout << "\ndiv "<<name<<endl;
    // for( int i=0;i<nw;i++ )      cout << names[i] << endl;

    if( type=="D" ){
      int i;
      for( i=0;i<nw-1;i++ )
	cout << names[i] << "_" ;
      cout << names[i] << endl;
    }else{
      if( type=="U" ) // ツ渉可づ淞づ個閉カツ篠堋療アツづ債陛渉環キ
	outU( names[0] );
      else
	cout << names[0];
      for( int i=1;i<nw;i++ )
	outU( names[i] );
      cout << endl;
    }
  }

  return 0;
}

Measured memory_bytes: 0
import bisect
N = int(input())
count = 0
List = sorted(list(map(int, input().split())))
for i in range(N-2):
  for j in range(N-i-2):
    a = List[i]
    b = List[i+j+1]
    index = bisect.bisect_left(List, a+b)
    count += index-i-j-2
print(count)

Measured memory_bytes: 3188
#include <iostream>
#include<string>
#include<cmath>
#include<ciso646>
#include<cstring>
#include<iomanip>
#include<vector>
#include<algorithm>
#include<utility>
#include<map>
#include<math.h>

using ll = long long;
ll M = 1000000000000000;


using namespace std;
int main()
{

	ll a;
	int ama;
	cin >> a;
	int i = 0;
	string ss;
	vector<string> aa(100);
	vector<int> aa1(100);

	while (a > 0) {
		ama = a % 26;
		a /= 26;

		if (ama == 0) {
			aa[i] += "z";
			//cout << "z";
			a--;
			i++;
			continue;
		}

		else
		{
			char okasi = ama + 96;
			aa[i] = okasi;
			i++;
			//cout << okasi;
		}
	}
	
	reverse(aa.begin(), aa.begin() + i);
	for (int j = 0;j < i;j++)
		cout << aa[j];
	
}


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

int main(){
  int N,K;
  cin>>N>>K;
  
  int H[N];
  for(int i=0;i<N;i++)cin>>H[i];
  sort(H,H+N,greater<int>());
  
  long int ans=0;
  if(N>K){
    for(int i=K;i<N;i++){
      
      ans+=H[i];
    }
  }else{
    ans=0;
  }
  cout<<ans<<endl;
}


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

#define INF_LL (int64)1e18
#define INF (int32)1e9
#define REP(i, n) for(int64 i = 0;i < (n);i++)
#define FOR(i, a, b) for(int64 i = (a);i < (b);i++)
#define all(x) x.begin(),x.end()
#define fs first
#define sc second

using int32 = int_fast32_t;
using uint32 = uint_fast32_t;
using int64 = int_fast64_t;
using uint64 = uint_fast64_t;
using PII = pair<int32, int32>;
using PLL = pair<int64, int64>;

const double eps = 1e-10;

template<typename A, typename B>inline void chmin(A &a, B b){if(a > b) a = b;}
template<typename A, typename B>inline void chmax(A &a, B b){if(a < b) a = b;}

int main(void){
	cin.tie(0);
	ios::sync_with_stdio(false);
	string s;
	cin >> s;
	int32 cnt[26]={};
	REP(i, s.size())
		cnt[s[i]-'a']++;
	int32 out = 0;
	REP(i, 26){
		if(cnt[i]%2) out++;
	}
	cout << (out)/2 << endl;
}


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

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

#define FOR(i, n, m) for (ll(i) = (m); (i) < (n); ++(i))
#define REP(i, n) FOR(i, n, 0)
#define OF64 std::setprecision(10)

const ll MOD = 1000000007;
const ll INF = (ll)1e15;

struct Vertex
{
    vector<int> node;
};

Vertex V[100005];
ll C[100005];
bool U[100005];
ll A[100005];

int main()
{
    ll N;
    cin >> N;
    REP(i, N - 1)
    {
        ll a, b;
        cin >> a >> b;
        a--;
        b--;
        V[a].node.push_back(b);
        V[b].node.push_back(a);
    }
    REP(i, N)
    {
        cin >> C[i];
    }
    sort(C, C + N);

    if (N == 1)
    {
        cout << 0 << endl;
        cout << C[0] << endl;
        return 0;
    }
    else if (N == 2)
    {
        cout << std::min(C[0], C[1]) << endl;
        cout << C[0] << " " << C[1] << endl;
        return 0;
    }
    queue<int> q;

    int k = 0;
    REP(i, N)
    {
        if (V[i].node.size() > 1)
        {
            k = i;
            break;
        }
    }

    q.push(k);
    int index = N - 1;
    while (!q.empty())
    {
        int t = q.front();
        q.pop();
        if (U[t])
            continue;
        A[t] = C[index--];
        U[t] = true;
        REP(i, V[t].node.size())
        {
            int n = V[t].node[i];
            if (U[n])
                continue;
            q.push(n);
        }
    }

#if false
    REP(i, N)
    {
        if (V[i].node.size() == 1)
            q.push(i);
    }

    int index = 0;
    while (!q.empty())
    {
        int t = q.front();
        q.pop();
        if (U[t])
            continue;
        A[t] = C[index++];
        U[t] = true;
        REP(i, V[t].node.size())
        {
            int n = V[t].node[i];
            if (U[n])
                continue;
            q.push(n);
        }
    }
#endif

    ll M = 0;
    memset(U, 0, sizeof(U));
    q.push(0);
    U[0] = true;
    while (!q.empty())
    {
        ll t = q.front();
        q.pop();
        REP(i, V[t].node.size())
        {
            int n = V[t].node[i];
            if (U[n])
                continue;
            M += std::min(A[n], A[t]);
            U[n] = true;
            q.push(n);
        }
    }

    cout << M << endl;
    REP(i, N)
    {
        cout << A[i] << " ";
    }
    cout << endl;
    return 0;
}

Measured memory_bytes: 3328
import java.util.Scanner;

class Main {

	public static void main(String[] args) {
		Scanner scanner = new Scanner(System.in);
		
		while (true) {
			int H = scanner.nextInt();
			int W = scanner.nextInt();
			
			if (H == 0 && W == 0)
				break;
			
			for (int i = 0; i < H; i++) {
				for (int j = 0; j < W; j++)
					System.out.print('#');
				System.out.println();
			}
			System.out.println();
		}

	}

}



Measured memory_bytes: 38752
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int, int> P;
const ll mod = 1000000007;
const ll INF = 1e+14;
#define rep(i,n) for(int i=0;i<n;i++)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define per1(i,n) for(int i=n;i>=1;i--)
#define Rep1(i,sta,n) for(int i=sta;i<=n;i++)
#define _GLIBCXX_DEBUG

int main(){
    string s;
    cin>>s;

    int n=s.size();
    int ans=0;
    rep(i,n){
        int p=s[i]-'0';
        ans+=p;
        ans%=9;

    }
    if(ans==0) cout<<"Yes"<<endl;
    else cout<<"No"<<endl;
    
}

Measured memory_bytes: 3692
#include <string>
#include <iostream>
#include <algorithm>
using namespace std;
const int mod = 10000;
string a, b; int m, power[509], dp[509][11][2][509];
int solve(string s, int z) {
	// [1, s]
	int n = s.size();
	int ret1 = 0;
	for (int i = z; i < n - 1; i++) {
		for (int j = 1; j <= 9; j++) ret1 += dp[i][j][z][0];
		while (ret1 >= mod) ret1 -= mod;
	}
	int mod1 = 0;
	for (int i = n - 1; i >= 0; i--) {
		int r = s[i] - 48, tl = (i == n - 1 ? 1 : 0), tr = (i == 0 ? r : r - 1);
		if (i != n - 1) {
			if ((i + z) & 1) tl = max(tl, s[i + 1] - 48 + 1);
			else tr = min(tr, s[i + 1] - 48 - 1);
		}
		for (int j = tl; j <= tr; j++) ret1 += dp[i][j][z][mod1];
		while (ret1 >= mod) ret1 -= mod;
		mod1 = (mod1 - r * power[i] + r * m) % m;
		if (i != n - 1) {
			if (((i + z) & 1) && s[i + 1] >= s[i]) break;
			if (!((i + z) & 1) && s[i + 1] <= s[i]) break;
		}
	}
	return ret1;
}
int main() {
	cin >> a >> b >> m;
	reverse(a.begin(), a.end());
	reverse(b.begin(), b.end());
	a[0]--;
	for (int i = 0; i < a.size(); i++) {
		if (a[i] < 48) {
			a[i] += 10;
			a[i + 1]--;
		}
	}
	if (a.back() == 48) a.pop_back();
	if (a == "") a = "0";
	power[0] = 1 % m;
	for (int i = 1; i <= 500; i++) power[i] = power[i - 1] * 10 % m;
	for (int i = 0; i <= 9; i++) dp[0][i][0][i % m] = dp[0][i][1][i % m] = 1;
	for (int i = 1; i <= 500; i++) {
		for (int j = 0; j <= 9; j++) {
			for (int k = 0; k < m; k++) {
				int z = (k - j * power[i] + j * m) % m;
				if (i & 1) {
					for (int l = 0; l < j; l++) dp[i][j][0][k] += dp[i - 1][l][0][z];
					for (int l = 9; l > j; l--) dp[i][j][1][k] += dp[i - 1][l][1][z];
				}
				else {
					for (int l = 9; l > j; l--) dp[i][j][0][k] += dp[i - 1][l][0][z];
					for (int l = 0; l < j; l++) dp[i][j][1][k] += dp[i - 1][l][1][z];
				}
				while (dp[i][j][0][k] >= mod) dp[i][j][0][k] -= mod;
				while (dp[i][j][1][k] >= mod) dp[i][j][1][k] -= mod;
			}
		}
	}
	int ret1 = (solve(a, 0) + solve(a, 1)) % mod;
	int ret2 = (solve(b, 0) + solve(b, 1)) % mod;
	cout << (ret2 - ret1 + mod) % mod << endl;
	return 0;
}

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

int main() {
  char b;
  cin>>b;
  if(b=='A') cout<<"T"<<endl;
  if(b=='T') cout<<"A"<<endl;
  if(b=='G') cout<<"C"<<endl;
  if(b=='C') cout<<"G"<<endl;

  }


Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.StringTokenizer;

class Main {
    public static void main(String[] args) throws IOException{
            BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
            String line = br.readLine();
            StringTokenizer st = new StringTokenizer(line, " ");
            StringBuilder str = new StringBuilder();

            int x = Integer.parseInt(st.nextToken());
            int y = Integer.parseInt(st.nextToken());

            if(x < y) {
            	System.out.println("a < b");
            }
            else if(x > y) {
            	System.out.println("a > b");
            }
            else {
            	System.out.println("a == b");
            }
    }
}

Measured memory_bytes: 24424
#include <bits/stdc++.h>
#define ll long long
#define MODV 1000000007
#define INFLL (1LL<<62) // 9223372036854775807
#define EPS 1e-9
#define rep(i, n) for(ll i=0, i##_len=(ll)(n); i<i##_len; i++)
#define repf(i, n) for(ll i=1, i##_len=(ll)(n+1); i<i##_len; i++)
#define all(v) v.begin(), v.end()
#define endl "\n"
#define vi vector<ll>
#define vvi vector<vector<ll>>
#define Yes() cout << "Yes" << endl
#define YES() cout << "YES" << endl
#define No() cout << "No" << endl
#define NO() cout << "NO" << endl
#define Init() std::ios::sync_with_stdio(false); std::cin.tie(0); std::cout<<fixed<<setprecision(15);
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; }
using namespace std;

int main(){
    Init();
    ll n, x;
    cin >> n >> x;
    assert(1 <= x && x <= 2*n-1);

    // n段目は1～2n-1の数値の順列であり、ピラミッドの頂点として1と2n-1は頂点にはなれない
    if(x == 1 || x == 2*n-1){
        No();
        return 0;
    }

    // 3個の中央値であるため、2個以上ある場合は必ずその数値か中央値となる。
    // n段目の中心にxを入れ、左にxより小さい数、右にxより大きい数を置くことにより、
    // 必ず冗談にはxを2箇所以上残すことが可能である。
    // 上記を繰り返すと、必ず最終的にxが残ることになる。
    vi ans(2*n-1, -1);
    ans[n-1] = x, ans[n-2] = x-1, ans[n] = x+1;
    map<ll, bool> ok;
    ok[x] = true, ok[x-1] = true, ok[x+1] = true;
    ll next = 1;
    for(ll i=0; i<ans.size(); i++){
        if(ans[i] != -1) continue;
        while(ok[next]) next++;
        ans[i] = next;
        next++;
    }
    
    // 答えの出力
    Yes();
    for(auto &num: ans) cout << num << endl;
}

Measured memory_bytes: 17128
// Example program
#include <iostream>
#include <string>
using namespace std;
int main()
{
  int a,b,c,d;
  cin>>a>>b>>c>>d;
  if(a*b>c*d)cout<<a*b<<endl;
  else if(a*b<c*d)cout<<c*d<<endl;
  else if(a*b==c*d)cout<<a*b<<endl;
  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 REP(i,n) for(int i=1;i<=n;i++)
typedef long long ll;

//dp[i+1][j]はi番目の品物の中から重さwを超えないように選んだ時の価値の最大値
int dp[105][10005];

int main(){
	int N,W;
	cin >> N >> W;
	vector<int> v(N);
	vector<int> w(N);
	rep(i,N){
		cin >> v[i] >> w[i];
	}
	
	rep(i,N){
		rep(j,W+1){
			dp[i+1][j] = max(dp[i+1][j], dp[i][j]);
			if(j >= w[i]){
				dp[i+1][j] = max(dp[i+1][j],dp[i][j-w[i]]+v[i]);
			}
		}
	}
	
	cout << dp[N][W] << endl;
    return 0;
}




Measured memory_bytes: 6988
import std.stdio;
import std.string;
import std.conv;
import std.typecons;
import std.algorithm;
import std.functional;
import std.bigint;
import std.numeric;
import std.array;
import std.math;
import std.range;
import std.container;

void main() {
    while(true) {
        int N = readln.chomp.to!int;
        if (N==0) break;
        char[] str = readln.chomp.to!(char[]);
        int ba = 0;
        int[] huda = new int[N];
        for(int i=0, j=0; i<str.length; i++, j=(j+1)%N) {
            huda[j]++;
            switch(str[i]) {
            case 'M':
                break;
            case 'S':
                ba += huda[j];
                huda[j] = 0;
                break;
            case 'L':
                huda[j] += ba;
                ba = 0;
                break;
            default:
            }
        }
        writeln(huda.sort.to!string.tr("[],", "", "d"), " ", ba);
    }
}

Measured memory_bytes: 2492
#include <bits/stdc++.h>
//For ordered_set
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define MOD 1000000007
#define test int t; cin>>t; while(t--)
#define init(arr,val) memset(arr,val,sizeof(arr))
#define loop(i,a,b) for(int i=a;i<b;i++)
#define loopr(i,a,b) for(int i=a;i>=b;i--)
#define loops(i,a,b,step) for(int i=a;i<b;i+=step)
#define looprs(i,a,b,step) for(int i=a;i>=b;i-=step)
#define ull unsigned long{} long int
#define ll long long int
#define P pair
#define PLL pair<long long, long long>
#define PII pair<int, int>
#define PUU pair<unsigned long long int, unsigned long long int>
#define L list
#define V vector
#define D deque
#define ST set
#define MS multiset
#define M map
#define UM unordered_map
#define mp make_pair
#define pb push_back
#define pf push_front
#define MM multimap
#define F first
#define S second
#define IT iterator
#define RIT reverse_iterator
#define FAST ios_base::sync_with_stdio(false);cin.tie();cout.tie();
#define FILE_READ_IN freopen("input.txt","r",stdin);
#define FILE_READ_OUT freopen("output.txt","w",stdout);
#define all(a) a.begin(),a.end()
#define ld long double
using namespace std;
// For ordered_set
using namespace __gnu_pbds;
template <typename T>
using ord_set = tree<T,null_type,less<T>,rb_tree_tag,tree_order_statistics_node_update>;
const ll N = 1e6;
const ll inf = 1e9;
const double pi = acos(-1);
ll fact[N];
ll power(ll a, ll n){
   if(a == 1)return 1;
   if(n == 0)return 1;
   if(n == 1)return a%MOD;
   ll p = power(a,n/2);
   p*=p;
   p%=MOD;
   if(n & 1){
      p*=a;
      p%=MOD;
   }
   return p;
}
void precalculate_fact(){
   fact[0] = 1;
   loop(i,1,N){
      fact[i] = (fact[i-1] * i)%MOD;
   }
}
ll ncr(ll n, ll r){
   if(n > r)return 0;
   ll ans = fact[n];
   ans*=power(fact[r],MOD-2);
   ans%=MOD;
   ans*=power(fact[n-r],MOD-2);
   return ans%MOD;
}
int main(){
 	int n;
  cin >> n;
  V<ll> arr(n);
  loop(i,0,n)cin >> arr[i];
  ll ans = LLONG_MAX;
  ll mx = *max_element(all(arr));
  ll mn = *min_element(all(arr));
  loop(i,-100,101){
  	ll c = 0;
    loop(j,0,n){
      	c+=((arr[j]-i)*(arr[j]-i));
    }
    ans = min(ans,c);
  }
  cout << ans;
  return 0;
}

Measured memory_bytes: 256
import java.util.*;
public class Main {
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    
    int a = sc.nextInt();
    int b = sc.nextInt();
    int c = sc.nextInt();
    
    int total = a + b + c;
    
    if (total >= 22) {
      System.out.println("bust");
    } else {
      System.out.println("win");
    }
  }
}

Measured memory_bytes: 23124
#include<bits/stdc++.h>
using namespace std;
const long long INF = 1e16;

struct edge{
	long long from, to, cost;
};

int N, M;
edge E[2000];
long long ans, d[1000];

void bellman_ford(int s){
	fill(d, d+N, INF);
	d[s] = 0;
	for(int i=0; i<N-1; i++){
		for(int j=0; j<M; j++){
			edge e = E[j];
			if(d[e.from] != INF && d[e.to] > d[e.from] + e.cost){
				d[e.to] = d[e.from] + e.cost;
			}
		}
	}
	ans = -d[N-1];
	bool negative[1000];
	fill(negative, negative+N, false);
	for(int i=0; i<N; i++){
		for(int j=0; j<M; j++){
			edge e = E[j];
			if(d[e.from] != INF && d[e.to] > d[e.from] + e.cost){
				negative[e.from] = true;
			}
			if(negative[e.from]) negative[e.to] = true;
		}
	}
	if(negative[N-1]) cout << "inf" << endl;
	else cout << ans << endl;
}

int main(){
	cin >> N >> M;
	for(int i=0; i<M; i++){
		int a, b, c;
		cin >> a >> b >> c;
		a--; b--;
		edge e = {a, b, -c};
		E[i] = e;
	}
	bellman_ford(0);
	return 0;
}


Measured memory_bytes: 256
// AOJ 2241: Usaneko Matrix
// 2017.12.9

#include <stdio.h>
#include <string.h>

#define N1	9		// 512
#define N2  511
int us[1000002], rus[502], cus[502], dus[2];
int ne[1000002], rne[502], cne[502], dne[2];
char buf[4005], *p;

int getint()
{
	int n = 0;
	while (*p >= '0') n = (n<<3) + (n<<1) + (*p++ & 0xf);
	p++;
	return n;
}

int main()
{
	int n, u, v, m, r, c, a, uu, vv, b;

	fgets(p=buf, 40, stdin);
	n = getint(), u = getint(), v = getint(), m = getint();
	for (r = 1; r <= n; r++) {
		fgets(p=buf, 4005, stdin);
		for (c = 1; c <= n; c++) us[getint()] = (r << 9) | c;
	}
	for (r = 1; r <= n; r++) {
		fgets(p=buf, 4005, stdin);
		for (c = 1; c <= n; c++) ne[getint()] = (r << 9) | c;
	}

	uu = vv = 0;
	while (m--) {
		fgets(p=buf, 40, stdin);
		a = getint();
		if (b = us[a]) {
			r = b >> N1, c = b & N2;
			if (++rus[r] == n) uu++;
			if (++cus[c] == n) uu++;
			if (r   == c)   { if (++dus[0] == n) uu++; }
			if (r+c == n+1) { if (++dus[1] == n) uu++; }
		}
		if (b = ne[a]) {
			r = b >> N1, c = b & N2;
			if (++rne[r] == n) vv++;
			if (++cne[c] == n) vv++;
			if (r   == c)   { if (++dne[0] == n) vv++; }
			if (r+c == n+1) { if (++dne[1] == n) vv++; }
		}
		if (n == 1) {
			if (uu > 1) uu = 1;
			if (vv > 1) vv = 1;
		}
		if (uu >= u && vv >= v) { puts("DRAW"); return 0; }
		else if (uu >= u) { puts("USAGI"); return 0; }
		else if (vv >= v) { puts("NEKO"); return 0; }
	}		
	puts("DRAW");
	return 0;
}

Measured memory_bytes: 9492
#include <algorithm>
#include <array>
#include <bitset>
#include <cassert>
#include <climits>
#include <cmath>
#include <cstdint>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <memory>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <valarray>
#include <vector>

using namespace std;

void solution()
{
    int n;
    cin >> n;
    cout << (n >= 30 ? "Yes" : "No") << '\n';
}

int main()
{
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout << fixed << setprecision(10);
    solution();
    return 0;
}


Measured memory_bytes: 3644
#include <stdio.h>
#define bit(n,m)(((n)>>(m))&1)

int main(){
	int n,c;
	scanf("%d%d",&n,&c);
	int s=0;
	while(c--){
		int t;
		scanf("%d",&t);
		s|=1<<t;
	}
	for(int x=0;x<1<<n;x++)if((x&s)==x){
		printf("%d:",x);
		for(int k=0;k<n;k++)if(bit(x,k))printf(" %d",k);
		puts("");
	}
}


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

const int INF = 1e9;
const int MOD = 1e9 + 7;

int main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	
	int x;
	cin >> x;
	if (x >= 30)
		cout << "Yes" << endl;
	else
		cout << "No" << endl;
	
	return 0;
}

Measured memory_bytes: 3576
N, L = map(int, input().split())
a = list(map(int, input().split()))

ok = 0
for i in range(1, N):
    if a[i-1] + a[i] >= L:
        ok = 1
        break

if ok:
    print('Possible')
    for j in range(1, i):
        print(j)
    for j in range(N-1, i, -1):
        print(j)
    print(i)
else:
    print('Impossible')


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

using namespace std;

int main(){
    
    string S,T;
    cin >> S >> T;
    pair<char, char> st[S.length()];
    
    for (int i = 0; i < S.length(); i++) {
        st[i].first = T[i];
        st[i].second = S[i];
    }
    
    sort(st, st+S.length());
    char a = st[0].first;
    char b = st[0].second;
    bool yes = true;
    for (int i = 0; i < S.length()-1; i++) {
        if (st[i].first != st[i+1].first) {
            a = st[i+1].first;
            b = st[i+1].second;
        }else{
            if (b != st[i+1].second) {
                yes = false;
                break;
            }
            
        }
    }
    
    for (int i = 0; i < S.length(); i++) {
        st[i].first = S[i];
        st[i].second = T[i];
    }
    sort(st, st+S.length());
    a = st[0].first;
    b = st[0].second;
    for (int i = 0; i < S.length()-1; i++) {
        if (st[i].first != st[i+1].first) {
            a = st[i+1].first;
            b = st[i+1].second;
        }else{
            if (b != st[i+1].second) {
                yes = false;
                break;
            }
            
        }
    }
    
    if (yes) {
        cout << "Yes" << endl;
    }else{
        cout << "No" << endl;
    }
    
}




Measured memory_bytes: 1160
#include<iostream>
#include<string>
#include<algorithm>
#include<map>
#include<set>
#include<utility>
#include<vector>
#include<cmath>
#include<cstring>
#include<cstdio>
#include<time.h>
#define loop(i,a,b) for(int i=a;i<b;i++) 
#define rep(i,a) loop(i,0,a)
#define pb push_back
#define mp make_pair
#define all(in) in.begin(),in.end()
const double PI=acos(-1);
const double EPS=1e-10;
using namespace std;
typedef long long ll;
typedef vector<int> vi;
int main(){
	int a,n;
	cin>>a>>n;
	rep(i,n){
		int x,y;
		cin>>x>>y;
		x=min(x,a-x+1);
		y=min(y,a-y+1);
		int out=min(x,y)-1;
		cout<<1+out%3<<endl;;
	}
}

Measured memory_bytes: 1160
#include<stdio.h>

long keta1(long n){
  long num = 0;
  while(n%10!=0){
    n--;
    num++;
  }
  return num;
}

int main(){
  long n;
  scanf("%ld", &n);

  long N = n;
  long S = 0;

  while(1){
    long keta = keta1(n);
    S += keta;
    n /= 10.0;
    //    printf("n=%ld, keta=%ld, S=%ld\n", n, keta, S);
    if(n<=0) break;
  }

  if(N%S == 0) printf("Yes\n");
  else printf("No\n");

  return 0;
}


Measured memory_bytes: 128
#include <bits/stdc++.h>
#define fast ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define ll long long
using namespace std;
int p[100010];
void iniciar(int n){
    for(int i = 1; i <= n; i++)
        p[i] = i;
}
int find(int a){
    if(p[a] == a) return a;
    return p[a] = find(p[a]);
}
void unir(int a, int b){
    p[find(b)] = find(a);
}
bool mismoConjunto(int a, int b){
    return find(a) == find(b);
}
void solve(){
    int n, m, a, b;
    cin >> n >> m;
    iniciar(n);
    int nro = n;
    for(int i = 0; i < m; i++){
        cin >> a >> b;
        if(!mismoConjunto(a, b)){
            unir(a, b);
            nro--;
        }
    }
    cout << (nro - 1) << "\n";
}
int main(){
    fast;
    int t = 1;
    //cin >> t;
    while(t--){
        solve();
    }
    return 0;
}


Measured memory_bytes: 4032
#include <iostream>
#include <cstdio>
#include <string>
#include <algorithm>
#include <utility>
#include <cmath>
#include <vector>
#include <queue>
#include <set>
#include <map>
#define rep(i, n) for(int i = 0; i < n; i++)
using namespace std;
using Graph = vector<vector<int>>;
typedef long long ll;
const ll mod = 1000000007;

vector<bool> visited;

void dfs(const Graph &G, int v) {

    visited[v] = true;

    for(auto u : G[v]) { 
        if(visited[u]) {
            continue;
        }
        dfs(G, u);
    }
}

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

    Graph G(n+m);
    rep(i, n) {
        int k;
        cin >> k;
        rep(j, k) {
            int L;
            cin >> L;
            L--;
            G[i].push_back(L+n);
            G[L+n].push_back(i);
        }
    }

    visited.assign(n+m, false);

    dfs(G, 0);

    int flag = 0;
    rep(i, n) {
        if(!visited[i]) {
            flag = 1;
        }
    }

    if(!flag) {
        cout << "YES";
    }
    else {
        cout << "NO";
    }

    cout << endl;
    return 0;
}

Measured memory_bytes: 8440
import java.util.*
import kotlin.collections.ArrayList

class Flow(val to: Int, var flow: Int) {
    private var mPair: Flow? = null
    var pair: Flow
        get() = mPair!!
        set(value) {
            mPair = value
        }
}



fun calMaxFlow(nodes: Array<Array<Flow>>, source: Int, sink: Int): Int {
    val depth = IntArray(nodes.size){-1}
    val searching = IntArray(nodes.size){0}
    val queue: Queue<Int> = ArrayDeque<Int>()
    fun bfs(): Unit {
        depth.fill(-1)
        depth[source] = 0
        queue.add(source)
        while (queue.isNotEmpty()) {
            val top = queue.poll()
            for (flow in nodes[top]) if (flow.flow > 0 && depth[flow.to] == -1) {
                depth[flow.to] = depth[top] + 1
                queue.add(flow.to)
            }
        }
    }
    fun dfs(current: Int, min: Int = Int.MAX_VALUE): Int {
        if (current == sink) return min
        while(searching[current] < nodes[current].size) {
            val flow = nodes[current][searching[current]]
            if (flow.flow > 0 && depth[current] < depth[flow.to]) {
                val f = dfs(flow.to, minOf(min, flow.flow))
                if (f > 0) {
                    flow.flow -= f
                    flow.pair.flow += f
                    return f
                }
            }
            ++searching[current]
        }
        return 0
    }
    var flow = 0
    var hasFlow = true
    while (hasFlow) {
        hasFlow = false
        bfs()
        searching.fill(0)
        var f = dfs(source)
        while(f > 0) {
            flow += f
            hasFlow = true
            f = dfs(source)
        }
    }
    return flow
}

fun makeGraph(counts: Array<IntArray>, base: Int): Array<Array<Flow>> {
    val nodes = Array(28){ArrayList<Flow>()}
    fun setNode(from: Int, to: Int, flow: Int): Unit {
        nodes[from].add(Flow(to, flow))
        nodes[to].add(Flow(from, 0))
        nodes[from].last().pair = nodes[to].last()
        nodes[to].last().pair = nodes[from].last()
    }
    for (i in 0 until 26) if (i != base) {
        for (j in 0 until 26) if (j != base) {
            if (counts[i][j] != 0) setNode(i, j, counts[i][j])
        }
    }
    for (i in 0 until 26) if (i != base) {
        if (counts[base][i] != 0) setNode(26, i, counts[base][i])
        if (counts[i][base] != 0) setNode(i, 27, counts[i][base])
    }
    if (counts[base][base] != 0) setNode(26, 27, counts[base][base])
    return nodes.map{it.toTypedArray()}.toTypedArray()
}
fun main(args: Array<String>) {
    val n = readLine()!!.trim().toInt()
    val words = Array(n){readLine()!!.trim()}
    val counts = Array(26){IntArray(26){0} }
    for (word in words) {
        ++counts[word.first() - 'a'][word.last() - 'a']
    }
    for (c in 'a' .. 'z') {
        if (counts.sumBy{it[c - 'a']} == 0) continue
        if (counts[c - 'a'].sum() == 0) {
            println(c)
            continue
        }
        val graph = makeGraph(counts, c - 'a')
        val flow = calMaxFlow(graph, 26, 27)
        if (counts[c - 'a'].sum() <= flow) {
            println(c)
        }
    }
}


Measured memory_bytes: 38640
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n)   FOR(i,0,n)
#define pb emplace_back
typedef long long ll;
typedef pair<int,int> pint;

int sum[100002],c[100001];
int main(){
    int n,q;
    string s;
    cin>>n>>q;
    cin>>s;
    FOR(i,1,n){
        if(s[i-1]=='A'&&s[i]=='C') c[i]=1;
    }
    FOR(i,1,n){
        sum[i+1]=c[i]+sum[i];
    }
    int l,r;
    rep(i,q){
        cin>>l>>r;
        int ret=sum[r]-sum[l-1];
        if(l-1>=1){
            if(s[l-1]=='C'&&s[l-2]=='A') --ret;
        }
        cout<<ret<<endl;
    }
    return 0;
}


Measured memory_bytes: 1792
#include <vector>
#include <array>
#include <queue>
#include <deque>
#include <set>
#include <list>
#include <map>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <random>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>
#include <stdio.h>
#include <string.h>
#include <math.h>
#include <ctype.h>

using namespace std;

#define _CRT_SECURE_NO_WARNINGS
#define REP(i, n) for(int i=0; i<(n); i++)
#define LLREP(i,n) for(LL i=0; i<(n); i++)
#define FOR(i, m, n) for(int i=(m);i<(n);i++)
#define ALL(x) (x).begin(),(x).end()
#define SZ(x) ((int)(x).size())
#define SORT(x) sort(ALL(x))
#define REVE(x) reverse(ALL(x))
#define MP make_pair
#define PB push_back
#define INF INT_MAX

typedef vector<int> VI;
typedef vector<string> VS;
typedef vector<bool> VB;
typedef vector<vector<int>> VVI;
typedef vector<vector<bool>> VVB;
typedef pair<int, int> PII;
typedef vector<pair<int, int>> VPII;
typedef queue<int> QI;
typedef long long LL;

int main() {
	int n, ans = -1;
	string s, t;
	cin >> n >> s >> t;
	
	//i -> 文字の長さ
	FOR(i, n, n * 2) {

		bool flag = true;
		FOR(j, i - n, n) {
			if (s[j] != t[j - (i - n)])flag = false;
		}
		if (flag&&ans == -1)ans = i;

	}
	if (ans == -1)ans = n * 2;
	cout << ans << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#pragma GCC optimize("unroll-loops,no-stack-protector")
#pragma GCC target("sse,sse2,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#define watch(x) cout << (#x) << " is " << (x) << endl
#define debug cout << "hi" << endl

using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;

ll gcd(ll a, ll b) {return (!b ? a : gcd(b, a % b));}
bool cmp(int a,int b){return a>b;}

const ll mod = 1e9 + 7;
const int INF32 = 1<<30;
const ll INF64 = 1LL<<60;
const ld pi = 3.141592653589793;
const int N = 5e5 + 10;

void solve(){
     int n,k;cin >> n >> k;
     vector<int>a(n);
     for(int i = 0;i<n;i++) cin >> a[i];
     sort(a.begin(),a.end());
     int mini = INT_MAX;
     for(int i = k-1;i<n;i++) mini = min(mini,a[i]-a[i-k+1]);
     cout << mini;
}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);cout.tie(NULL);
    solve();
    return 0;
}

Measured memory_bytes: 3684
#define _USE_MATH_DEFINES
#include  <iostream>
#include  <algorithm>
#include  <climits>
#include  <vector>
#include  <string>
#include  <cstring>
#include  <stack>
#include  <queue>
#include  <cmath>
#include  <iomanip>
#include  <set>
#include  <map>
#include  <new>
#include <cstdint>
#include <cctype>
#include  <cstdio>
#include  <sstream>
#include  <bitset>
using namespace std;
#define rep(i,n)  for(int i = 0; i < n; i++)
#define lrep(i,n,m)  for(int i = n; i < m; i++)

using ll = long long;
using ld = long double;
using Vii = vector<vector<int> >;
using Gjudge = vector<vector<bool>>;
using Vi = vector<int>;
using Vl = vector<ll>;
using Vd = vector<double>;
using Vld = vector<long double>;
using Vll = vector<vector<ll> >;
using Vldd = vector<vector<ld> >;
using Vs = vector<string>;
using Vb = vector<bool>;
using Pi = pair<int, int>;
using Pl = pair<ll, ll>;
using Pli = pair<ll, int>;
using VPi = vector<Pi>;
using VPl = vector<Pl>;
using VPli = vector<Pli>;
using Ti = tuple<int, int, int>;
using Tl = tuple<ll, ll, ll>;

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

const int Mod = static_cast<int>(1e9 + 7);
const int INF = INT_MAX;
const ll LINF = LLONG_MAX;
const int dx[4] = { 1,0,-1,0 };
const int dy[4] = { 0,1,0,-1 };

int main()
{
	int n, x, t;
	cin >> n >> x >> t;
	if (n % x == 0) {
		cout << n / x * t << endl;
	}
	else {
		cout << ((n / x) + 1) * t << endl;
	}
}


Measured memory_bytes: 3616
#include<bits/stdc++.h>
#define rep(i, n) for (int i=0;i<(n);i++)
using namespace std;
typedef long long ll;
 
int main(void){
    int d, n;
    cin>>d>>n;
    int ans;
    if(d == 0){
        ans = n;
        if(n==100) ans =101;
    }
    else if(d == 1) {
        ans = 100+(n-1)*100;
        if(n == 100) ans = 10100;
    }
    else {
        ans = 10000+(n-1)*10000;
        if(n==100) ans = 1010000;
    }
    cout<<ans<<endl; 
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define fi first
#define se second

int db2(int x){
    if(abs(x)%2==0){
        return x/(-2);
    }else{
        return db2(x-1);
    }

}
int rb2(int x){
    if(abs(x)%2==0){
        return 0;
    }else{
        return 1;
    }
}

int main(){
    int n;
    vector<int> v(0);
    cin >> n;
    if(n==0){
        cout << 0 << endl;
        return 0;
    }

    while(n!=0){
        v.push_back(rb2(n));
        n = db2(n);
    }

    reverse(v.begin(),v.end());
    
    for(int i=0;i < v.size();i++)
    {
        cout << v.at(i);
    }
    cout << endl;
}
/* 1110 1111 1100 1101 10 11 0 1 110 111 100  101 11010
   -110 -101 -100 -11 -10 -1 0 1 10 11   100  101 110
10 2 -2 でやれば

2:0 110
7:1 1010
-2:0*/

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

int H, W, N, x, y, a, b[105][105];
int main()
{
	cin >> H >> W >> N;
	
	x = 1, y = 1;
	for (int i = 1; i <= N; i++)
	{
		cin >> a;
		while (a--)
		{
			b[x][y] = i;
			if (y == W && x % 2 == 1)
				y = W, x++;
			else if (y == 1 && x % 2 == 0)
				y = 1, x++;
			else if (x % 2 == 1)
				y++;
			else
				y--;
		}
	}

	for (int i = 1; i <= H; i++)
		for (int j = 1; j <= W; j++)
		{
			cout << b[i][j];
			if (j == W)
				cout << endl;
			else
				cout << " ";
		}
	return 0;
}

Measured memory_bytes: 384
#include<bits/stdc++.h>
#define int int64_t
using namespace std;

const int M = 1e9+7;

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

    int k;
    cin >> k;
    int res = 0;
    for(int a = 1; a <= k; a++) {
        for(int b= 1; b <= k; b++) {
            for(int c = 1; c <= k; c++) {
                res += __gcd(a , __gcd(b , c));
            }
        }
    }
    cout << res << '\n';
    return 0;
}


Measured memory_bytes: 3652
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < n; i++)
using namespace std;
using ll = long long;
int INF = 1000000009;
int main()
{
    int n,k;
    cin >> n >> k;
    vector<int> h(n);
    rep(i,n){
        cin >> h[i];
    }
    sort(h.begin(),h.end());
    int ans = INF;
    rep(i, n - k + 1)
    {
        ans = min(ans, h[i + k - 1] - h[i]);
    }
    cout << ans << endl;
}

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

string s, t;
set<int> pos[30];

/*

0 1 2 3 4 5 6 7
a b c d e f g

*/

pair<int, int> cfind(int x, int from) {
	auto it = pos[x].lower_bound(from);

	if(it == pos[x].end()) {
		it = pos[x].lower_bound(0);
		if(it == pos[x].end())
			return make_pair(-1, -1);
		//cerr << "*" << endl;
		return make_pair((int)s.size()-from+*it+1, *it);
	}

	return make_pair(*it-from+1, *it); 
}

int main() {
	cin >> s >> t;

	for(int i = 0; i < s.size(); ++i)
		pos[s[i]-'a'].insert(i);

	ll pos = 0, len = 0;
	for(int i = 0; i < t.size(); ++i) {
		auto p = cfind(t[i]-'a', pos);
		//cout << p.first << " " << p.second << endl;

		if(p.first == -1) {
			cout << "-1\n";
			return 0;
		}

		pos = (p.second+1)%s.size();
		len += p.first;
	}

	cout << len << endl;
	return 0;
}

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

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

int main() {
    long double a, b;
    cin >> a >> b;

    ll ans = (ll) (a * b);
    cout << ans << endl;
    

    return 0;
}

Measured memory_bytes: 3724
#include <bits/stdc++.h>
using namespace std;
typedef int64_t ll;

int main(){
  int x,y;
  cin>>x>>y;
  cout<<(((y-2*x)%2==0 && (4*x-y)%2==0 && (y-2*x)>=0 && (4*x-y)>=0) ? "Yes" : "No")<<endl;
}


Measured memory_bytes: 3636
import sys
n = int(input())
def calc(x):
    if x%2 == 0:
        return int(x/2)
    else:
        return 3*x+1
li = [n]
flg = 0
ans = n
count = 1
while flg == 0:
    ans = calc(ans)
    if ans in li:
        print(count+1)
        flg += 1
        sys.exit()
    else:
        li.append(ans)
        count += 1

Measured memory_bytes: 3064
/*
   Creator - Glitched
   Yeet!!
*/
#include "bits/stdc++.h"
using namespace std;

#define testcases ll T;cin>>T;while(T--)
#define ll long long
#define loop(i,x,n) for(ll i=x;i<n;i++)
#define loopr(i,x,n) for(ll i=n-1;i>=x;i--)
#define ff first
#define ss second
#define pb push_back
#define elif else if
#define flush cout<<"\n"
#define mod 1000000007
#define L LONG_MAX
#define fastio ios_base::sync_with_stdio(false)


int main()
{
    fastio;
    ll n,ct=0, c = 0;
    cin>>n;

    vector<ll> v(n);

    loop(i,0,n){
        cin>>v[i];

        if(v[i]%2 == 0){
            ct++;

            if(v[i]%3 == 0 || v[i]%5 == 0)
                c++;
        }

    }
    if(c==ct){
        cout<<"APPROVED";
    }
    else
        cout<<"DENIED";
    flush;
}


    

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


ll single(ll x){
  if (x%2){
    ll half=(x+1)/2;
    return half%2;
  }
  else{
    return single(x-1)^x;
  }
}

int main(){
  ll A, B;cin>>A>>B;
  ll xora_=single(A-1);
  ll xorb=single(B);
  ll ans= xora_^xorb;
  cout << ans <<endl;
  return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#ifndef ONLINE_JUDGE
#define dbg(x...) do { cout << "\033[32;1m " << #x << " -> "; err(x); } while (0)
void err() { cout << "\033[39;0m" << endl; }
template<template<typename...> class T, typename t, typename... A>
void err(T<t> a, A... x) { for (auto v: a) cout << v << ' '; err(x...); }
template<typename T, typename... A>
void err(T a, A... x) { cout << a << ' '; err(x...); }
#else
#define dbg(...)
#endif
typedef long long ll;
typedef pair<int,int> pi;
typedef vector<int> vi;
template<class T> using vc=vector<T>;
template<class T> using vvc=vc<vc<T>>;
template<class T> void mkuni(vector<T>&v)
{
    sort(v.begin(),v.end());
    v.erase(unique(v.begin(),v.end()),v.end());
}
template<class T>
void print(T x,int suc=1)
{
    cout<<x;
    if(suc==1) cout<<'\n';
    else cout<<' ';
}
template<class T>
void print(const vector<T>&v,int suc=1)
{
    for(int i=0;i<v.size();i++)
    print(v[i],i==(int)(v.size())-1?suc:2);
}
const int maxn=105;
int dp[maxn][maxn][maxn];
int w[maxn],v[maxn];
int c[5];
int main()
{
    int n,W;
    cin>>n>>W;
    for(int i=0;i<n;i++)
        cin>>w[i]>>v[i];
    vi big;
    for(int i=0;i<n;i++)
    {
        if(w[i]-w[0]==3)
        {
            big.push_back(v[i]);
            continue;
        }
        c[w[i]-w[0]]++;
        for(int j=c[0];j>=0;j--)
        {
            for(int k=c[1];k>=0;k--)
            {
                for(int l=c[2];l>=0;l--)
                {
                    if(w[i]==w[0])
                    {
                        if(j)
                            dp[j][k][l]=max(dp[j][k][l],dp[j-1][k][l]+v[i]);
                    }
                    else if(w[i]==w[0]+1)
                    {
                        if(k)
                            dp[j][k][l]=max(dp[j][k][l],dp[j][k-1][l]+v[i]);
                    }
                    else if(w[i]==w[0]+2)
                    {
                        if(l)
                            dp[j][k][l]=max(dp[j][k][l],dp[j][k][l-1]+v[i]);
                    }
                }
            }

        }
    }
    sort(big.begin(),big.end(),greater<int>());
    vi pre(big.size()+1);
    pre[0]=0;
    for(int i=1;i<=big.size();i++) pre[i]=pre[i-1]+big[i-1];
    int ans=0;
    for(int i=0;i<=c[0];i++)
    {
        for(int j=0;j<=c[1];j++)
        {
            for(int k=0;k<=c[2];k++)
            {
                for(int l=0;l<=pre.size();l++)
                {
                    ll curw=1LL*i*w[0]+1LL*j*(w[0]+1)+1LL*k*(w[0]+2)+1LL*l*(w[0]+3);
                    if(curw>W) break;
                    ans=max(ans,dp[i][j][k]+pre[l]);
                }
            }
        }
    }
    cout<<ans<<'\n';
    
}

Measured memory_bytes: 2560
import java.util.Scanner;

//THE BYDOLM@STER
public class Main{

	void run(){
		Scanner sc = new Scanner(System.in);
		while(sc.hasNext()){
			int n = sc.nextInt();
			int M = sc.nextInt();
			int[] c = new int[n];
			int[][] p = new int[n][3];
			for(int i=0;i<n;i++){
				sc.nextLine();sc.nextLine();
				c[i] = sc.nextInt();
				for(int j=0;j<3;j++)p[i][j] = sc.nextInt();
			}
			int[][][] dp = new int[3][n][M+1];
			for(int x=0;x<3;x++){
				for(int i=0;i<n;i++){
					for(int j=1;j<=M;j++){
						dp[x][i][j] = dp[x][i][j-1];
						if(j-c[i]>=0)dp[x][i][j] = Math.max(dp[x][i][j], dp[x][i][j-c[i]]+p[i][x]);
						if(i>0)dp[x][i][j] = Math.max(dp[x][i][j], dp[x][i-1][j]);
					}
				}
			}
			int max = 0;
			for(int i=0;i<3;i++)max = Math.max(max, dp[i][n-1][M]);
			System.out.println(max);
		}
	}
	
	public static void main(String[] args) {
		new Main().run();
	}
}

Measured memory_bytes: 17000
#include <stdio.h>

int main(void)
{
	int S=0,h=0,m=0,s=0;
	scanf("%d",&S);
	s=S%60;
	m=S%3600/60;
	h=S/3600;
	printf("%d:%d:%d\n",h,m,s);
	return 0;
}

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

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

#define REP(i, n) for (int i = 0, i##_len = (n); i < i##_len; ++i)
#define ALL(x) ((x).begin()), ((x).end())

#define READ(x) (cin >> (x))
#define WRITE_N(x) (cout << (x) << endl)
#define WRITE(x) (cout << (x))
#define WRITE_YESNO(x) (WRITE_N((x) ? "Yes" : "No"))

#define PRECISE_COUT std::cout << std::setprecision(15) << std::fixed

bool xor_logic(bool x, bool y) { return (x && y) || (!x && !y); }

ll solve(ll N, ll X, ll M) {
  vector<ll> a_vec{0, X};

  ll a_i = X;
  ll i = 1;
  ll loop_l_i = 1;
  vector<ll> a_sum_vec{0, X};

  while (i < N) {
    a_i = (a_i * a_i) % M;
    auto itr_found = find(a_vec.begin() + 1, a_vec.end(), a_i);

    if (itr_found != a_vec.end()) {
      loop_l_i = distance(a_vec.begin(), itr_found);
      break;
    }

    a_vec.push_back(a_i);
    a_sum_vec.push_back(a_sum_vec.back() + a_i);
    i++;
  }

  ll loop_sum = a_sum_vec.back() - a_sum_vec[loop_l_i - 1];
  ll loop_count = (N - loop_l_i + 1) / (i - loop_l_i + 1);
  ll single_r_i = loop_l_i - 1 + (N - loop_l_i + 1) % (i - loop_l_i + 1);
  ll ans = loop_sum * loop_count + a_sum_vec[single_r_i];
  return ans;
}

int main() {
  // get values from input
  cin.tie(0);
  ios::sync_with_stdio(false);

  ll N, X, M;
  cin >> N >> X >> M;

  // main procedure
  ll ans = solve(N, X, M);

  // output
  cout << ans << endl;

  return 0;
}

Measured memory_bytes: 4252