akhauriyash/Code-Regression huggingface dataset:
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;

internal static class CR
{
    public static string Get() { return Console.ReadLine(); }
    public static IEnumerable<string> GetTexts() { return Console.ReadLine().Split(' '); }
    public static int GetInteger() { return int.Parse(Console.ReadLine()); }
    public static IEnumerable<int> GetIntegers() { return Console.ReadLine().Split(' ').Select(x => int.Parse(x)); }
}

namespace AtCoderBeginnerContest
{
    internal class Program
    {
        public static int N { get; private set; }
        public static int M { get; private set; }

        private static void Main() { var r = GetResult(); Debug.WriteLine(r); Console.WriteLine(r); }

        private static object GetResult()
        {
            var inputs = CR.GetIntegers().ToList();
            N = inputs[0];
            M = inputs[1];
            var answers = NewMethod().ToList();

            var correctCount = 0;
            var penartyCount = 0;
            foreach (var answerGroup in answers.GroupBy(x => x.P))
            {
                if (answerGroup.Any(x => x.S))
                {
                    correctCount++;
                }
                else
                {
                    continue;
                }

                foreach (var item in answerGroup.OrderBy(x => x.Index))
                {
                    if (item.S)
                    {
                        break;
                    }
                    else
                    {
                        penartyCount++;
                    }
                }
            }

            return $"{correctCount} {penartyCount}";
        }

        private static IEnumerable<Answer> NewMethod()
        {
            for (int i = 0; i < M; i++)
            {
                var x = CR.GetTexts().ToList();
                yield return new Answer
                {
                    Index = i,
                    P = int.Parse(x[0]),
                    S = x[1] == "AC",
                };
            }
        }

        class Answer
        {
            public int P { get; set; }
            public bool S { get; set; }
            public int Index { get; internal set; }
        }
    }
}


Measured memory_bytes: 33540
#include <bits/stdc++.h>
using namespace std;
using i64 = long long;
#define rep(i,s,e) for(int (i) = (s);(i) <= (e);(i)++)
#define all(x) x.begin(),x.end()

int L;

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

int main() {
  cin >> L;
  int N = log2(L) + 1;
  vector<edge> ans;
  for(int i = 1;i < N;i++) {
    ans.push_back({ i, i + 1, 0 });
    ans.push_back({ i, i + 1, (1 << (i - 1)) });
  }

  for(int i = N - 1;i >= 1;i--) {
    if(L - (1 << (i - 1)) >= (1 << (N - 1))) {
      ans.push_back({ i, N, L - (1 << (i - 1)) });
      L = L - (1 << (i - 1));
    }
  }

  cout << N << " " << ans.size() << endl;
  for(auto e: ans) {
    cout << e.from << " " << e.to << " " << e.cost << endl;
  }
}


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

using namespace std;

#define ll             long long 
#define mod            1000000007
#define FIO            ios_base::sync_with_stdio(false); cin.tie(NULL);
                  
void initial()
{
	#ifndef ONLINE_JUDGE
	freopen("input.txt","r",stdin);
	freopen("output.txt","w",stdout);
	#endif
}


int main() 	 	
{
	initial();
	FIO;

	int n,m;
	cin>>n>>m;

	int arr[n];

	int sum=0;

	for(int i=0;i<m;i++)
	{
		cin>>arr[i];

		sum += arr[i];
	}

	if((n-sum)>=0)
		cout<<(n-sum)<<endl;
	else
		cout<<"-1"<<endl;

}



Measured memory_bytes: 3688
def main():
    n = int(input())
    X, Y = [], []
    for _ in range(n):
        x, y = map(int, input().split())
        X.append(x + y)
        Y.append(x - y)
    X.sort()
    Y.sort()
    print(max(X[-1] - X[0], Y[-1] - Y[0]))

if __name__ == '__main__':
    main()



Measured memory_bytes: 25668
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<(n);i++)
#define all(a) (a).begin(),(a).end()
#define ll long long
int main(){
  int N;
  cin>>N;
  vector<int> A(N);
  rep(i,N) cin>>A[i];
  sort(all(A));
  int X[3]={};
  int j=0;
  rep(i,N){
    if(i) if(A[i]!=A[i-1]){
      j++;
      if(j>=3) break;
    }
    X[j]++;
  }
  if(X[0]==N&&A[0]==0) cout<<"Yes"<<endl;
  else if(X[0]*2==X[1]&&X[2]==0&&A[0]==0) cout<<"Yes"<<endl;
  else if(X[0]==X[1]&&X[0]==X[2]&&X[0]+X[1]+X[2]==N&&(A[0]^A[N/3])==A[N/3*2]) cout<<"Yes"<<endl;
  else cout<<"No"<<endl;
}



Measured memory_bytes: 640
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <cassert>
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REP(i,n) FOR(i,0,n)
#define rep(i,n) FOR(i,0,n)
#define DEBUG(x) cout<<#x<<": "<<x<<endl
#define vint vector<int>
#define vdouble vector<double>
#define vstring vector<string>
using namespace std;

#include<map>
#include<set>
#include<queue>

typedef long long ll;
typedef unsigned long long ull;

const int MAX_N = 1000000;

int N;
int S[100];
int main() {
    cin >> N;
    rep(i, N) cin >> S[i];

    sort(&S[0], &S[N]);

    int ret = 0;
    rep(i, N) ret += S[i];

    if(ret % 10 == 0){
        bool flg = false;
        rep(i, N)
            if(S[i] % 10 != 0) {
                ret -= S[i];
                flg = true;
                break;
            }
        if(!flg) ret = 0;
    }

    cout << ret << endl;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ
		Scanner sc = new Scanner(System.in);
		String line = sc.nextLine();
		String[] lines = line.split(" ");
		int r = Integer.parseInt(lines[0]);
		int D = Integer.parseInt(lines[1]);
		int x_2000 = Integer.parseInt(lines[2]);

		for(int i = 0; i < 10; i++) {
			x_2000 = r * x_2000 - D;
			System.out.println(x_2000);
		}
	}

}


Measured memory_bytes: 35580
#include <bits/stdc++.h>
using namespace std;
int main() {
    
        int n;cin>>n;
        vector<int> dp(n+1),h(n+1);
        for(int i=1;i<=n;i++) cin>>h[i];
        dp[1]=0;dp[2]=abs(h[2]-h[1]);
        for(int i=3;i<=n;i++){
           dp[i]= min(abs(h[i]-h[i-1]) + dp[i-1], abs(h[i]-h[i-2]) + dp[i-2]);
           
        }
        cout<<dp[n]<<endl;
    
    return 0;
}

Measured memory_bytes: 3968
import heapq


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


hq = []
for val in lst_A:
    val *= -1
    heapq.heappush(hq, val)
m1 = -(heapq.heappop(hq))
m2 = -(heapq.heappop(hq))


for v in lst_A:
    print(m2 if v == m1 else m1)

Measured memory_bytes: 20640
import java.util.*;

public class Main {
	public static void main ( String[] args ) {
		int n , m;
		Scanner sc = new Scanner(System.in);
		while ( true ) {
			int cost = 0;
			n = sc.nextInt();
			m = sc.nextInt();
			if ( n == 0 && m == 0 ) break;
			int[] deta = new int[1000];
			for ( int i = 0; i < n; i++ )
				deta[i] = sc.nextInt();
			Arrays.sort(deta,0,n);
			int index = n - 1 , count = 1;
			for ( int i = index; i >= 0; i-- ) {
				for ( ; i > i - m; i-- ) {
					if ( i < 0 ) break;
					if ( count % m != 0 )
						cost += deta[i];
					count++;
				}
			}
			System.out.println(cost);
		}
	}
}

Measured memory_bytes: 0
#include<functional>
#include<algorithm>
#include<iostream>
#include<iomanip>
#include<cstring>
#include<cstdlib>
#include<utility>
#include<string>
#include<cstdio>
#include<vector>
#include<bitset>
#include<cmath>
#include<ctime>
#include<queue>
#include<deque>
#include<stack>
#include<map>
#include<set>
using namespace std;
const int inf=2147483647,dx[]={-1,0,1,0},dy[]={0,-1,0,1};// 上 左 下 右
const int N=100005,M=1000005,K=200005,mod=1000000007;
const long long llinf=9223372036854775807ll;
//int & long long
int n;
double a,ans;
int main(){
	cin>>n;
	for(int i=1;i<=n;i++)
		cin>>a,ans+=(1.00/a);
	cout<<fixed<<setprecision(10)<<1.00/ans;
	return 0;
}

Measured memory_bytes: 256
#include<iostream>
using namespace std;
int main(){
  int n,poi[100],hit,hom,out;
  string exam;
  cin>>n;
  for(int j=0;j<100;j++){
    poi[j]=0;
  }
  for(int i=0;i<n;i++){
    hit=0,hom=0,out=0;
    while(1){
      cin>>exam;
      if(exam=="HIT"){
	hit++;
      }
      if(hit==4){
	hit--;
	poi[i]++;
      }if(exam=="OUT"){
	out++;
      }
      if(out==3){
	break;
      }if(exam=="HOMERUN"){
	poi[i]+=hit;
	poi[i]++;
	hit=0;
      }
    }
  }
  for(int i=0;i<n;i++){
    cout<<poi[i]<<endl;
  }
  return 0;
}
  

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

int main() {
  int A,B,C,D,L,R;
  cin >> A >> B >> C >> D;
  
  L=A+B;
  R=C+D;

  if (L > R ) {
    cout << "Left" << endl;
  }
  else if (L == R){
    cout << "Balanced" <<endl;
  }
  else {
    cout << "Right" << endl;
  }  
}

Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<cmath>
#include<cstdlib>
#include<vector>
#include<map>
#include<set>
#include<algorithm>
#include<queue>

using namespace std;


int main(){
  int n,a;cin>>n>>a;
  cout<<(n*n-a)<<endl;
  return 0;
}


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

namespace Sample101
{
    class Program
    {
        static void Main(string[] args)
        {
            var n = int.Parse(Console.ReadLine());
            var a = Console.ReadLine().Split(' ').Select(str => int.Parse(str)).ToArray();

            Array.Reverse(a);
            Console.WriteLine(string.Join(" ", a));
        }
    }
}


Measured memory_bytes: 16280
#include<iostream>
#include<vector>
#include<algorithm>
#include<cctype>
#include<utility>
#include<string>
#include<cmath>

#define REP(i, n) for(int i = 0;i < n;i++)
#define REPR(i, n) for(int i = n;i >= 0;i--)
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define FORR(i, m, n) for(int i = m;i >= n;i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define llong long long
#define pb(a) push_back(a)
#define INF 999999999
using namespace std;
typedef pair<int, int> P;
typedef pair<llong, llong> LP;
typedef pair<int, P> PP;
typedef pair<llong, LP> LPP;

int main(){

    int n,k;
    cin >> n >> k;

    vector<int> a(n);

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

    int count = 0;

    int i = 0;
    while(i < a.size()-1){
        i+=k-1;
        //cout << i << endl;
        count++;
    }
    cout << count << endl;



    return 0;
}

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

int main(){
  int H,W;
  cin>>H>>W;
  int N;
  cin>>N;
  int a[N];
  for(int i=0;i<N;++i) cin>>a[i];
  
  int cl[H*W];
  int cnt=0;
  for(int i=0;i<N;++i){
    for(int j=cnt;j<cnt+a[i];++j){
      cl[j]=i+1;
    }
    cnt += a[i];
  }


  cnt=0;
  for(int i=0;i<H;++i){
    if(i%2==0) cnt=0;
    else cnt=1;
    for(int j=0;j<W;++j){
      if(cnt==0){
        cout<<cl[j+i*W]<<" ";
        if(j==W-1) cout<<" "<<endl;
      }
      else{
        cout<<cl[W-1-j+i*W]<<" ";
        if(j==W-1) cout<<" "<<endl;
      }
    }
  }

}


Measured memory_bytes: 384
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <map>
#include <unordered_map>
#include <set>
#include <climits>
#include <cassert>
using namespace std;

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    long long N, L, T;
    cin >> N >> L >> T;
    vector<pair<long long, int>> XW(N);
    for(int i=0; i<N; i++) cin >> XW[i].first >> XW[i].second;
    vector<long long> rmover, lmover;
    for(int i=0; i<N; i++){
        if(XW[i].second == 1) rmover.push_back(L-1-XW[i].first);
        else lmover.push_back(XW[i].first);
    }
    sort(rmover.begin(), rmover.end());
    for(int i=0, j=rmover.size(); i<j; i++)
        rmover.push_back(rmover[i]+L);
    for(int i=0, j=lmover.size(); i<j; i++)
        lmover.push_back(lmover[i]+L);

    vector<long long> cross(N);
    for(int i=0; i<N; i++){
        if(XW[i].second == 1){
            long long X0 = XW[i].first;
            long long tmp1 = (2*T/L)*lmover.size()/2;
            long long tmp2 = (2*T)%L;
            long long tmp3 = upper_bound(lmover.begin(), lmover.end(), tmp2+X0) - lower_bound(lmover.begin(), lmover.end(), X0);
            cross[i] = tmp1 + tmp3;
        }else{
            long long X0 = L-1-XW[i].first;
            long long tmp1 = (2*T/L)*rmover.size()/2;
            long long tmp2 = (2*T)%L;
            long long tmp3 = upper_bound(rmover.begin(), rmover.end(), tmp2+X0) - lower_bound(rmover.begin(), rmover.end(), X0);
            cross[i] = tmp1 + tmp3;
        }
    }

    vector<long long> num(N);
    for(int i=0; i<N; i++){
        if(XW[i].second == 1)
            num[i] = (i + cross[i]) % N;
        else
            num[i] = (i - cross[i] + 2 * N * T) % N;
    }

    vector<long long> ans(N);
    for(int i=0; i<N; i++){
        int n = num[i];
        if(XW[i].second == 1)
            ans[n] = (XW[i].first + T) % L;
        else
            ans[n] = (XW[i].first - T + L * T) % L;
    }
    for(int i=0; i<N; i++)
        cout << ans[i] << endl;

    return 0;
}


Measured memory_bytes: 6892
#include <iostream>
#include <vector>
#include <algorithm>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <cstdlib>
#include <string>
#include <cstring>
#include <cmath>
#include <climits>
#include <ctime>
#define endl '\n'
#define ll long long
#define mod 10007
#define NCONS 200001
//#define NCONS 100001
//#define NCONS 1001
//#define NCONS 101
#define MCONS 2001
#define LIMIT 1000000000
#define TRUE 1
#define FALSE 0

using namespace std;

// a > b
ll gcd(ll a, ll b)
{
    return b ? gcd(b, a % b) : a;
}

bool prime(ll a)
{
    if(a == 2) return true;
    for(ll i = 2; i * i <= a; i++)
        if(a % i == 0) return false;
    return true;
}

ll dp[NCONS][2];

int main(void)
{
    cin.tie(NULL); ios_base::sync_with_stdio(false);
    int n; cin >> n; vector<ll> vec(n, 0);
    for(int i = 0; i < n; i++) cin >> vec[i];
    
    
    
    dp[1][0] = vec[0] + vec[1];
    dp[1][1] = vec[0] * -1 + vec[1] * -1;
    for(int i = 2; i < n; i++)
    {
        dp[i][0] = max(dp[i-1][0], dp[i-1][1]) + vec[i];
        dp[i][1] = max(dp[i-1][0] - (2 * vec[i-1]), dp[i-1][1] + (2 * vec[i-1])) + (vec[i] * -1);
    }
  
    
    
    
    
    
    
    
    cout << max(dp[n-1][0], dp[n-1][1]) << endl;
    

    
    return 0;
}


Measured memory_bytes: 2560
#include <cstdio>
#include <queue>

using std::priority_queue;


int main(void)
{

    priority_queue<int> Q;
    int N,M,i,an,v;
    long long s;
    scanf("%d%d",&N,&M);
    for(i=0;i<N;i++)
    {
        scanf("%d",&an);
        Q.push(an);
    }
    for(i=0;i<M;i++)
    {
        v=Q.top();
        Q.pop();
        Q.push(v/2);
    }
    s=0;
    while(!Q.empty())
    {
        s+=Q.top();
        Q.pop();
    }
    printf("%lld\n",s);


    return 0;
}


Measured memory_bytes: 892
#include<bits/stdc++.h>
#define forr(i, a, b) for(int i = (a); i < (b); i++)
#define rep(i,n) for(int i = 0; i < (n); i++)
#define rrep(i,n) for(int i = 1; i <= (n); i++)
#define ALL(a) (a.begin()),(a.end())
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
typedef pair<ll, ll> LP;
const ll LINF = 1LL<<60;
const int INF = 1001001001;
const int MOD = 1000000007;

/* --------------------------------------------------- */

int main() {
    string s;
    cin >> s;
    int l = s.size();
    int ans = l;
    rep(i, 200) {
        if(l % 2 != 0) {
            l--;
            continue;
        }
        else {
            bool check = true;
            rep(j, l / 2 - 1) {
                if(s[j] != s[j + l / 2]) {
                    check = false;
                    break;
                }
            }
            if(check && ans != l) {
                ans = l;
                break;
            } else l--;
        }
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256
#C
n = int(input())
x = [0]*n
y = [0]*n
kyori = 0
for i in range(n):
    x[i],y[i] = map(int,input().split())
import math
for j in range(n):
    for k in range(n):
        kyori += math.sqrt((x[j]-x[k])**2+(y[j]-y[k])**2)
print(kyori/n)

Measured memory_bytes: 3188
#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 ALL(a)     (a).begin(),(a).end()
#define VI         vector<int>
#define MOD 1000000007

using ll = long long int;
using P = pair<int,int>;

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

const ll INF=(ll)1e19;
//const int INF=(1<<30);

int main(){
  int n;
  cin >> n;
  VI h(n);
  REP(i,n)cin >> h[i];

  bool flag=true;
  int ans=0;
  while(flag){
    REP(i,n){
      if(i>0){
        if(h[i]>0 && h[i-1]==0)ans++;
      }else{
        if(h[i]>0)ans++;
      }
    }
    flag=false;
    REP(i,n){
      if(h[i]>0)h[i]--;
      if(h[i]>0)flag=true;
    }
  }
  cout << ans << endl;
}



Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<vector>
#include<queue>
#include<set>
#include<unordered_set>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
typedef unordered_set<ll> uset;
#define rep(i,n) for(int i=0;i<n;i++)
#define rrep(i,n) for(int i=0;i<=n;i++)
#define chmin(a,b) a=min(a,b)
#define chmax(a,b) a=max(a,b)
#define all(x) x.begin(),x.end()
#pragma gcc optimize("O3")
#pragma gcc optimize("unroll-loops")
#pragma gcc target("avx2,see4")

int main(){
	int n;
	cin>>n;
	vector<P> ans;
	rep(i,n)for(int j=i+1;j<n;j++){
		string s;
		rep(k,n)s+="0";
		s[i]=s[j]='1';
		cout<<"? "<<s<<"\n"<<flush;
		ll res;
		cin>>res;
		if(res==1)ans.push_back(make_pair(i,j));
	}
	cout<<"!";
	for(auto e:ans){
		cout<<" ("<<e.first<<","<<e.second<<")";
	}
	cout<<"\n"<<flush;
}


Measured memory_bytes: 852
for i in range(10**6):
    N=int(input())
    if N==0:
        exit()
    D={}
    for j in range(N):
        s,g=input().split()
        S=s.split(":")
        G=g.split(":")
        ST=int(S[0])*60*60+int(S[1])*60+int(S[2])
        GT=int(G[0])*60*60+int(G[1])*60+int(G[2])
        if ST not in D:
            D[ST]=1
        else:
            D[ST]+=1
        if GT not in D:
            D[GT]=-1
        else:
            D[GT]-=1
    LD=list(D.items())    
    LD.sort()
    MAX=0
    cnt=0
    for t,c in LD:
        cnt+=c
        if MAX<cnt:
            MAX=cnt
    print(MAX)
    #print(LR)


Measured memory_bytes: 8404
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define mod 998244353 
#define pb push_back
#define mb make_pair
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
vector<int> adj[100010];
vector<int> ts;
set<int> vs;
void topo(int i){
	vs.insert(i);
	for(auto u:adj[i]){
		if(vs.find(u)!=vs.end())
			continue;
		topo(u);
	}
	ts.pb(i);

}
int main(){
	IOS;
	
	for(auto u:adj)
		u.clear();
	vs.clear();
	ts.clear();

	int n,m; cin >> n >> m;

	for(int i=0;i<m;i++){
		int a,b; cin >> a >> b;
		adj[a].pb(b);
	}
	for(int i=1;i<=n;i++){
		if(vs.find(i)==vs.end())
			topo(i);
	}
	reverse(ts.begin(),ts.end());
	// for(auto u:ts)
	// 	cout << u << " ";
	// cout << endl;
	int arr[n+1];
	memset(arr,0,sizeof(arr));
	int mx=INT_MIN;
	for(auto u:ts){
		for(auto u1:adj[u]){
			arr[u1]=max(arr[u1],arr[u]+1);
			mx=max(mx,arr[u1]);
		}
	}
	cout << mx << endl;
	

	return 0;
}




Measured memory_bytes: 12920
import java.util.*;

public class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    int N = sc.nextInt();
    String ans = "No";

    for(int i = 0; i * 4 <= N; i++){
      int M = N - i * 4;
      if(M % 7 == 0){
        ans = "Yes";
        break;
      }
    }

    System.out.println(ans);
  }
}


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

int main(){
    string s; cin >> s;
    bool f1 = false, f2 = false;
    int len = s.length();
    for(int i = 0; i < len; i++){
        if(s[i] == 'C' && !f2) f1 = true;
        if(s[i] == 'F' && f1) f2 = true;
    }
    cout << ( (f1 && f2) ? "Yes" : "No") << endl;
    return 0;
}

Measured memory_bytes: 256
let hash = Hashtbl.create 1000000;;

let _ =
  let n = read_int ()
  in
  let rec read = function
      0 -> ()
    | i ->
       let (op, key) = Scanf.scanf "%s %s\n" (fun x y -> (x,y)) in
       if op = "insert" then
         Hashtbl.add hash key key
       else if op = "find" then
         if Hashtbl.mem hash key then print_endline "yes"
         else print_endline "no"
       ;read (i-1)
  in read n;;

Measured memory_bytes: 43876
#include <iostream>
#include <string>
#include <algorithm>
#include <utility>
#include <iomanip>
#include <functional>
#include <queue>
#include <stack>
#include <cmath>
#define INF 10000000000000000
#define MOD 1000000007
using namespace std;




int main(){
    string S;
    cin >> S;
    int K;
    cin >> K;
    
    pair<char, int> s[S.length()];
    for(int i=0; i<S.length(); i++){
        s[i].first=S[i];
        s[i].second=i;
    }
    
    sort(s,s+S.length());
    
    string k[5];
    for(int i=0; i<5; i++){
        k[i]="zzzzzzzzzzz";
    }
    
    
    for(int i=0; i<S.length(); i++){
        string temp="";
        for(int p=0; p<5; p++){
            if(i+p>=S.length()){break;}
            temp+=S[i+p];
            
            int tikan=0;
            if(k[4]>temp){tikan=1;}
            for(int n=0; n<5; n++){
                if(k[n]==temp){
                    tikan=0;
                    break;
                }
            }
            if(tikan==1){
                k[4]=temp;
                sort(k,k+5);
            }
        }
        
    }
    
    
    cout<<k[K-1]<<endl;
    
    
    
    
    return 0;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define ll long long
int main(){
  ll n,m;
  cin >> n >> m;
  priority_queue<ll, vector<ll>, greater<ll>> pq;
  rep(i,n){
    ll a;
    cin >> a;
    pq.push(a);
  }
  vector<pair<ll,ll>> b(m);
  rep(i,m){
    ll c,d;
    cin >> c >> d;
    b.at(i)=make_pair(d,c);
  }
  sort(b.begin(),b.end());
  reverse(b.begin(),b.end());
  ll i,j;
  for(i=0;i<m;i++){
    for(j=0;j<b.at(i).second;j++){
      ll q=pq.top();
      if(q<b.at(i).first){
        pq.pop();
        pq.push(b.at(i).first);
      }else{
        break;
      }
    }
  }
  ll sum=0;
  while(!pq.empty()){
    ll cp=pq.top();
    sum+=cp;
    pq.pop();
  }
  cout << sum;
}

Measured memory_bytes: 5628
#include <iostream>

using namespace std;

int n, y;

int main() {
	cin >> n >> y;
	y /= 1000;
	for (int i = 0; i <= y / 10; i ++)
		for (int j = 0; j <= (y - i * 10) / 5; j ++) {
			if ((i + j <= n) && (i * 10 + j * 5 + (n - i - j) == y)) {
				cout << i << ' ' << j << ' ' << n - i - j <<  endl;
				return 0;
			}
		}
	cout << "-1 -1 -1" << endl;

	return 0;
}

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

int main()
{
    ll a, b, c, d;
    cin >> a >> b >> c >> d;
    ll x = max(a*c, b*c);
    ll y = max(a*d, b*d);
    ll ans = max(x, y);
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 3632
import collections
n=int(input())
a=list(map(int,input().split()))
b=0
for i in a:
  b^=i
c=collections.Counter(a)
if len(c)>3:
  print('No')
elif len(c)==1:
  if a[0]==0:
    print('Yes')
  else:
    print('No')
elif b==0:
  print('Yes')
else:
  print('No')

Measured memory_bytes: 20716
import java.util.Scanner;

public class Main{
    
    public static void main (String []args){
        
        Main main = new Main();
        main.solve();
    }
    
    private void solve(){
        
        Scanner sc = new Scanner(System.in);
        
        int A = sc.nextInt();
        int B = sc.nextInt();
        int C = sc.nextInt();
        
        if (A<C&&C<B){
            System.out.println("Yes");
        } else if (A>C&&C>B){
            System.out.println("Yes");
        } else {
            System.out.println("No");
        }
    }
}

Measured memory_bytes: 22740
// Problem : F - Range Set Query
// Contest : AtCoder - AtCoder Beginner Contest 174
// URL : https://atcoder.jp/contests/abc174/tasks/abc174_f
// Memory Limit : 1024 MB
// Time Limit : 2000 ms
// Powered by CP Editor (https://github.com/cpeditor/cpeditor)

#define _CRT_SECURE_NO_WARNINGS
#include <cstdio>
#include <cstring>
#include <cmath>
#include <algorithm>
using namespace std;

const int N = 1e6+7;
int a[N],belong[N],cnt[N],res[N];
int quasize,bnum,now;
struct _Node
{
	int l,r,id;
	bool operator<(const _Node& b)	const
	{
		if(belong[l] == belong[b.l])	return r < b.r;
		return belong[l] < belong[b.l];
	}
}q[N];
inline void del(int pos)
{
	--cnt[a[pos]];
	if(!cnt[a[pos]])	--now;
}
inline void add(int pos)
{
	if(!cnt[a[pos]])	++now;
	++cnt[a[pos]];
}
int main()
{
	int n,m;scanf("%d%d",&n,&m);
	quasize = sqrt(n);
	bnum = ceil(double(n) / quasize);
	
	for(int i = 1;i <= bnum;++i)
		for(int j = (i - 1) * quasize + 1;j <= i * quasize;++j)
			belong[j] = i;
	for(int i = 1;i <= n;++i)	scanf("%d",&a[i]);
	for(int i = 1;i <= m;++i)	scanf("%d%d",&q[i].l,&q[i].r),q[i].id = i;
	sort(q+1,q+m + 1);
	
	int l = 1,r = 0;
	for(int i = 1;i <= m;++i)
	{
		int ql = q[i].l,qr = q[i].r;
		while(l < ql)	del(l++);
		while(l > ql)	add(--l);
		while(r < qr)	add(++r);
		while(r > qr)	del(r--);
		res[q[i].id] = now;
	}
	for(int i = 1;i <= m;++i)	printf("%d\n",res[i]);
	return 0;
}



Measured memory_bytes: 17492
#include<iostream>
#include<vector>
#include<cstring>
using namespace std;
const int MAX_DIGIT = 50;
template<class T> inline bool chmax(T& a, T b){
  if(a < b){
    a = b;
    return 1;
  }
  return 0;
}
long long dp[100][2];
vector<long long> A;
int main(){
  int N = 0;
  long long K = 0;
  cin >> N >> K;
  A.resize(N);
  for(int i=0;i<N;i++){
    cin >> A[i];
  }
  memset(dp,-1,sizeof(dp));
  dp[0][0] = 0;

  for(int d=0;d<MAX_DIGIT;d++){
    long long mask = 1LL << (MAX_DIGIT - d - 1);
    int num = 0;
    for(int i=0;i<N;i++){
      if(A[i] & mask) num++;
    }
    long long cost0 = mask * (num);
    long long cost1 = mask * (N - num);

    if(dp[d][1] != -1){
      chmax(dp[d+1][1],dp[d][1]+max(cost0,cost1));
    }
    if(dp[d][0] != -1){
      if(K & mask){
        chmax(dp[d+1][1],dp[d][0] + cost0);
      }
    }
    if(dp[d][0] != -1){
      if(K & mask){
        chmax(dp[d+1][0],dp[d][0] + cost1);
      }
      else{
        chmax(dp[d+1][0],dp[d][0] + cost0);
      }
    }
  }

  cout << max(dp[MAX_DIGIT][0],dp[MAX_DIGIT][1]) << endl;

}


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

int main() { 
  int A,B;
  cin >> A;
  cin >> B;
  
  if (A+B >= A+A-1 && A+B >= B+B-1){
    cout << A+B <<endl;}
  else if (A+A-1 >= A+B && A+A-1 >= B+B-1){
    cout << A+A-1 <<endl;}
 else if (B+B-1 >= A+B &&  B+B-1 >= A+A-1 ){
   cout <<  B+B-1 << endl;}
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <queue>
#include <set>
#include <map>
#include <string.h>
#include <cmath>

using namespace std;
typedef long long i64;
typedef long double ld;
typedef pair<i64,i64> P;
#define rep(i,s,e) for(int (i) = (s);(i) <= (e);++(i))

string s;
int x;
int y;

bool f = true;

bool ok(vector<int>& d , int A)
{
	vector<bool> dp(20000,false);
	auto acc = [](int i){
		return i + 10000;
	};

	dp[acc(0)] = true;

	for(int i = 0;i < d.size();i++)
	{
		vector<bool> before = move(dp);
		dp.assign(20000,false);
		for(int j = -10000;j < 10000;j++)
		{
			int index = acc(j);
			if(index + d[i] < dp.size() && !f)
				dp[index] = dp[index] || before[index + d[i]];
			if(0 <= index - d[i])
				dp[index] = dp[index] || before[index - d[i]];
		}
      	f =  false;
	}


	return dp[acc(A)];
}
int main()
{
	cin >> s >> x >> y;

	vector<int> d[2];


	int now = 0;
	int cou = 0;

	for(char c : s)
	{
		if(c == 'T')
		{
			d[now].push_back(cou);
			now = 1 - now;
			cou = 0;
		}
		else
		{
			cou++;
		}
	}

	if(cou != 0)
	{
		d[now].push_back(cou);
	}

	if(ok(d[0],x) && ok(d[1] , y))
	{
		cout << "Yes" << endl;
	}
	else
	{
		cout << "No" << endl;
	}

}




Measured memory_bytes: 384
#input
N, M = map(int, input().split())
A = list(map(int, input().split()))

#output
import numpy as np
A = np.array(A)
A.sort()

def number_of_shake(K):
    p = np.searchsorted(A, K-A)
    return N*N - p.sum()

left = 0
right = 10**6
while left + 1 < right:
    mid = (left + right) // 2
    if number_of_shake(mid) >= M:
        left = mid
    else:
        right = mid

L = np.searchsorted(A, right-A)
Acum = np.zeros(N+1, np.int64)
Acum[1:] = np.cumsum(A)

shake = N*N - L.sum()
happy = (Acum[-1] - Acum[L]).sum() + (A*(N-L)).sum()
happy += (M-shake)*left

print(happy)


Measured memory_bytes: 17176
import java.awt.geom.AffineTransform;
import java.awt.geom.Point2D;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main {

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

		String[] tmpArray = br.readLine().split(" ");
		double px1 = Double.parseDouble(tmpArray[0]);
		double py1 = Double.parseDouble(tmpArray[1]);
		double px2 = Double.parseDouble(tmpArray[2]);
		double py2 = Double.parseDouble(tmpArray[3]);

		Point2D p1 = new Point2D.Double(px1, py1);
		Point2D p2 = new Point2D.Double(px2, py2);

		int q = Integer.parseInt(br.readLine());

		for(int i = 0; i < q; i++){
			tmpArray = br.readLine().split(" ");
			double x = Double.parseDouble(tmpArray[0]);
			double y = Double.parseDouble(tmpArray[1]);

			Point2D p = new Point2D.Double(x,y);

			Point2D result = calcReflection(p, p1, p2);
			System.out.printf("%.10f %.10f\n", result.getX(), result.getY());
		}

	}

	static Point2D calcReflection(Point2D p, Point2D p1, Point2D p2){
		double theta = Math.PI/2;

		//直線のなす角が90度ではないときはここで計算
		if(p1.getX() != p2.getX()){
			theta = Math.atan((p1.getY() - p2.getY()) / (p1.getX() - p2.getX()));
		}


		AffineTransform affine = AffineTransform.getTranslateInstance(p1.getX(), p1.getY());
		affine.concatenate(AffineTransform.getRotateInstance(theta));
		//y座標を反転する
		affine.concatenate(new AffineTransform(1, 0, 0, -1, 0, 0));
		affine.concatenate(AffineTransform.getRotateInstance(-theta));
		affine.concatenate(AffineTransform.getTranslateInstance(-p1.getX(), -p1.getY()));

		Point2D result = new Point2D.Double();
		result = affine.transform(p, result);

		return result;

	}

}



Measured memory_bytes: 35412
import java.io.IOException;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) throws IOException {
		Scanner sc = new Scanner(System.in);
		
		String s = sc.next();
		String t = sc.next();
		
		String u = t.substring(0, s.length());
		
		System.out.println( s.equals(u) ? "Yes" : "No");
	}
}

Measured memory_bytes: 35752
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <cmath>
#include <stack>
#include <queue>
#include <set>
#include <map>
using namespace std;
#define rep(i,n) for(int i=0;i<(n);i++)
#define all(a) (a).begin(),(a).end()
typedef long long ll;
typedef vector<int> VI;
typedef vector< vector<int> > VII;
typedef pair<int,int> PII;

int main(){
  int A,B;
  cin>>A>>B;
  if(abs(A-B)%2) cout<<"IMPOSSIBLE"<<endl;
  else cout<<abs(A+B)/2<<endl;
}


Measured memory_bytes: 256
#include<iostream>
#include<string.h>
#include<vector>
#include<list>
#include<stdio.h>
#include<math.h>
#include<iomanip>
#include<map>
#include<stack>
#include<queue>
#define range(i,a,b) for(int i = (a); i < (b); i++)
#define rep(i,b) range(i,0,b)
#define debug(x) cout << "debug " << x << endl;
using namespace std;

int main(){
    int N, K;
    while(cin >> N >> K){
        bool out[55] = {false};
        int m, R, bunny[55][55];
        rep(i, 55)
            rep(j, 55)
                bunny[i][j] = -1;
        rep(i, K){
            cin >> m;
            rep(j, m){
                cin >> bunny[i][j];
            }
        }
        cin >> R;
        rep(i, R){
            int p, q;
            bool check = false;
            cin >> p >> q;
            rep(j, K){
                rep(k, N){
                    if(bunny[j][k] == -1) break;
                    if(bunny[j][k] == p){
                        rep(l,N){
                            if(bunny[j][l] == q){
                                out[p] = out[q] = true;
                            }
                        }
                        check = true;
                    }
                }
                if(check) break;
            }
        }
        int ans = 0;
        rep(i, 55){
            if(out[i]){
                ans++;
            }
        }
        cout << ans << endl;
    }
}

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

int main() {
    string s;
    cin >> s;
    int ans = 0;
    int cur = 0;
    for(char& c : s) {
        if(c == 'R') {
            cur++;
        } else {
            ans = max(ans, cur);
            cur = 0;
        }
    }
    ans = max(ans, cur);
    cout << ans;
}

Measured memory_bytes: 3552
import sys
import math
import collections
from collections import deque
from functools import reduce
import heapq
#k = int(input())
a, b, h, m = map(int, sys.stdin.readline().split())
#s = input()
#a = list(map(int, sys.stdin.readline().split()))

x = (h * 60 + m) * 5.5
y = x % 360
c = min(y, 360-y)
d = math.radians(c)


e = (b * math.sin(d)) ** 2
f = (b * math.cos(d) - a) ** 2
ans = math.sqrt(e + f)
print(ans)

        


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

int op[10][10];

int f(string s){
    int ret = 0;
    for(int i = 0; i < s.length(); i++){
        ret = op[ret][s[i]-'0'];
    }
    return ret;
}

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

    int ans = 0;
    for(int x = 0; x < 10000; x++){
        string base = to_string(x);
        while(base.length() != 4)   base = "0" + base;
        base += (char)(f(base) + '0');

        bool correct = true;

        // altering one single digit
        for(int i = 0; i < 5; i++){
            base[i] = (char)((base[i]-'0'+1)%10 + '0');
            for(int j = 1; j < 10; j++){
                if(f(base) == 0)    correct = false;
                base[i] = (char)((base[i]-'0'+1)%10 + '0');
            }
        }
        
        // transposing two adjacent digits
        for(int i = 0; i < 4; i++){
            if(base[i] == base[i+1])    continue;
            swap(base[i], base[i+1]);
            if(f(base) == 0)    correct = false;
            swap(base[i], base[i+1]);
        }

        if(!correct)  ans++;
    }

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 3292
#include <iostream>
#include <algorithm>
#include <string>
#include <math.h>
#include <bitset>
#include <vector>
#include <queue>
#include <map>

#define i64 int64_t
#define ff(ii,nn,mm) for(int ii=nn;ii<mm;ii++)
#define sort(vvv) sort(vvv.begin(),vvv.end())
#define rvs(vvv) reverse(vvv.begin(),vvv.end())

using namespace std;

int main() {
	int n;
	cin >> n;
	int ans = 0;
	vector<pair<int, deque<pair<int, int>>>> data(n);
	ff(i, 0, n) {
		int a;
		cin >> a;
		data.at(i).first = a;
		ff(j, 0, a) {
			int x, y;
			cin >>x >>y;
			pair<int, int> pp(x, y);
			data.at(i).second.push_back(pp);
		}
	}
	int brk = 0;
	ff(j, 1, 1 << n) {
		bitset<15> pre(j);
		//cout << pre << endl;
		ff(i, 0, n) {
			//cout << i << " : ";
			if (!pre.test(i)) {
				//cout << "a" << endl;
				continue;
			}
			int a = data.at(i).first;
			ff(k, 0, a) {
				int x = data.at(i).second.at(k).first;
				int y = data.at(i).second.at(k).second;
				x--;
				//cout << x << " " << y <<" "<<pre.test(x)<< " : ";
				if (pre.test(x) != y) {
					//cout << "x" << endl;
					brk++;
					break;
				}
				//cout << "o" << endl;
			}
			if (brk == 1) { 
				break; 
			}
		}
		if (brk == 1) {
			brk--;
			continue;
		}
		else {
			int pr = 0;
			ff(i, 0, n) {
				if (pre.test(i))pr++;
			}
			if (pr > ans)ans = pr;
		}
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<math.h>
#include<vector>
#include<algorithm>
#include<numeric>
#include<map>
#include<queue>
using namespace std;

int main(){
    long long dp[1000010];cin>>dp[1];
    map<long long,int> mp;
    mp[dp[1]]++;

    for(int i=2;i<=1000000;++i){
        if(dp[i-1]%2==0)dp[i]=dp[i-1]/2;
        else            dp[i]=3*dp[i-1]+1;
        mp[dp[i]]++;
        if(mp[dp[i]]==2){
            cout<<i<<endl;
            break;
        }
    }
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define mod 1000000007
#define oo 2000000000
const double PI = acos(-1);
const int N = 100010 , K = 201;

int ask(int idx){
	cout << idx << endl;
	fflush(stdout);
	string s;
	cin >> s;
	if(s[0] == 'M')
		return 0;
	if(s[0] == 'F')
		return 1;
	return 2;
}

int main(){
	int n;
	scanf("%d",&n);
	int a = ask(0);
	if(a == 2) return 0;
	int low = 1 , high = n - 1;
	while(high >= low){
		int mid = (low + high) / 2;
		int cur = ask(mid);
		if(cur == 2) break;
		if(mid % 2 == 0){
			if(cur == a)
				low = mid + 1;
			else
				high = mid - 1;
		}
		else{
			if(cur == a)
				high = mid - 1;
			else
				low = mid + 1;
		}
	}
 	return 0;
}

Measured memory_bytes: 852
using System;
using System.Linq;
using System.Diagnostics;
using System.Collections.Generic;
using static System.Math;

class P
{
    static void Main()
    {
        //その他の要素の和の最大公約数は1ではない
        //要素数n すべての最大公約数1 どの要素も<=30000
        //n <= 20000
        //0 2 3 4 (mod 6)
        //Sum = 9 : 3で割れる
        //     2 3 4 6 8 9 10 12....
        //mod2 0 1 0 0 0 1  0  0
        //mod3 2 0 1 0 2 0  1  0
        //mod6 2 3 4 0 2 3  4  0
        //---------sum----------
        //mod2 0 1 1 1 1 0  0  0 
        //mod3 2 2 0 0 2 2  0  0
        //---------add----------
        //mod6 4 1 3 3 1 4  0  0
        //-----difffromlast------
        //

        //一個前まで全部周期で立てて、最後だけ調整

        //テスト
        /*for (int i = 3; i <= 20000; i++)
        {
            List<int> r = solve(i);
            int rsum = r.Sum();
            if (r.Count != i)
            {
                Console.WriteLine($"Ultra Yabai {i}");
            }
            if (rsum % 6 != 0)
            {
                Console.WriteLine($"Very Yabai {i}");
            }
            if(r.All(x => x % 2 == 0) || r.All(x => x % 3 == 0))
            {
                Console.WriteLine($"Warito Yabai {i}");
            }
        }*/
        //ここまでテスト
        int n = int.Parse(Console.ReadLine());
        List<int> res = solve(n);
        if (n == 3)
        {
            res = new List<int> { 2, 5, 63 };
        }
        Console.WriteLine(string.Join(" ", res));
    }
    static List<int> solve(int n)
    {
        int[] mod = { 2, 3, 4, 6 };
        List<int> res = new List<int>();
        for (int i = 0; i < n - 1; i++)
        {
            res.Add((i / 4) * 6 + mod[i % 4]);
        }
        int last = res.Last();
        switch (n % 8)
        {
            case 0:
                //10 -> 12
                res.Add(last + 2);
                break;
            case 1:
                //12 -> 6
                res.Add(last + 6);
                break;
            case 2:
                //2 -> 4 
                res.Add(last + 2);
                break;
            case 3:
                //最後の要素を消して4,6
                //3 -> 4,6
                res.RemoveAt(res.Count - 1);
                res.Add(last + 1);
                res.Add(last + 3);
                break;
            case 4:
                //4 -> 9
                res.Add(last + 5);
                break;
            case 5:
                //6 -> 9
                res.Add(last + 3);
                break;
            case 6:
                //最後の要素を消して9,12
                res.RemoveAt(res.Count - 1);
                //8 -> 9,12
                res.Add(last + 1);
                res.Add(last + 4);
                break;
            case 7:
                //9
                //9 -> 10
                res.Add(last + 1);
                break;
        }
        return res;
    }
}

Measured memory_bytes: 14048
//D - Face Produces Unhappiness
//2019/09/09

#include <stdio.h>
#include <stdlib.h>

int main(void) {
    int num,count,ans=0,turn=0,i;
    char *direction;
    scanf("%d %d",&num,&count);
    direction=malloc(sizeof(char)*100001);
    scanf("%s",direction);
    for (i=0;i<num-1;i++) {
        if (direction[i]==direction[i+1]) {
            ans++;
        }
        else {
            turn++;
        }
    }
    free(direction);
    for (i=0;i<count;i++) {
        if (turn==0) break;
        else if (turn-2>=0) {
            ans+=2;
            turn-=2;
        }
        else if (turn-1==0) {
            ans+=1;
            turn--;
        }
    }
    printf("%d\n",ans);
    return 0;
}

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

#define DUMP(x) cerr << #x << "=" << x << endl
#define DUMP2(x, y) cerr<<"("<<#x<<", "<<#y<<") = ("<<x<<", "<<y<<")"<< endl
#define BINARY(x) static_cast<bitset<16> >(x)

#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define REP(i,m,n) for (int i=m;i<(int)(n);i++)

#define in_range(x, y, w, h) (0<=(int)(x) && (int)(x)<(int)(w) && 0<=(int)(y) && (int)(y)<(int)(h))
#define ALL(a) (a).begin(),(a).end()

typedef long long ll;
const int INF = 1e9;
typedef pair<int, int> PII;
int dx[4]={0, -1, 1, 0}, dy[4]={-1, 0, 0, 1};

int main()
{
    ios::sync_with_stdio(false);

    int N, C, K;
    cin >> N >> C >> K;
    vector<int> T(N);
    rep(i, N) cin >> T[i];
    sort(ALL(T));

    int ans = 1;
    int t = T[0], c = 1;

    REP(i, 1, N) {
        int now = T[i];
        if (t + K < now) {
            ans++;
            c = 1;
            t = now;
        } else {
            if (c < C) {
                c++;
            } else {
                ans++;
                c = 1;
                t = now;
            }
        }
    }
    cout << ans << endl;
}

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

int main() {

  int N, M;
  cin >> N >> M;
  vector<int> popular(N);
  for(int i = 0; i < N; i++){
  cin >> popular.at(i);
  }
  int sum = 0;
  for(int i = 0; i < N; i++){
    sum += popular.at(i);
  }
  double a = 4*M;
  double tokuhyo = sum/a;
  int count = 0;
  for(int i = 0; i < N; i++){
    if(popular.at(i) >= tokuhyo){
      count++;
    }
  }
  if(count >= M){
    cout << "Yes" << endl;
  }
  else{
    cout << "No" << endl;
  }
  
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define int long long
typedef pair<int,int> P;
int INF = 1e18+7;
int mod = 1e9+7;
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};
signed main() {
    int N;
    cin >> N;
    vector<int>x(N),y(N);
    vector<int>nx(N),ny(N);
    for(int i = 0; i < N; i++) {
        cin >> x[i] >> y[i];
        nx[i] = x[i]-y[i];
        ny[i] = x[i]+y[i];
    }
    sort(nx.begin(),nx.end());
    sort(ny.begin(),ny.end());
    cout << max({nx[N-1]-nx[0],abs(ny[0]-ny[N-1])}) << endl;
}


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

int main(){
  int N,T,A; cin>>N; cin>>T>>A;
  vector<int> h(N);
  for(x:h)
    cin>>x;
  
  vector<int> check(N);
  for(int i=0; i<N; i++){
    check.at(i) = T*1000-h.at(i)*6-A*1000;
    if(check.at(i)<0)
      check.at(i) *= -1;
  }
  
  int answer = 1; int inspect = check.at(0);
  for(int i=1; i<N; i++){
    if(check.at(i) < inspect){
      answer = i+1;
      inspect = check.at(i);
    }
  }
  
  cout<<answer<<endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ALL(v) (v).begin(),(v).end()
#define REP(i,p,n) for(int i=p;i<(int)(n);++i)
#define rep(i,n) REP(i,0,n)
#define INF 999999999
using ll = long long;
using VI = vector<int>;
typedef long long int Int;
int main(){
  ll n;cin >> n;

  VI ue(n),tyuu(n),sita(n);
  rep(i,n) cin >> ue.at(i);
  rep(i,n) cin >> tyuu.at(i);
  rep(i,n) cin >> sita.at(i);
  sort(ue.begin(),ue.end());
  sort(sita.begin(),sita.end());
  sort(tyuu.begin(),tyuu.end());
    ll ans = 0;

    rep(i,n) {
        long long int x = lower_bound(ue.begin(),ue.end(),tyuu[i]) - ue.begin();
        long long int y = n-(upper_bound(sita.begin(), sita.end(),tyuu[i]) - sita.begin());
        ans += x * y;
    }
    cout << ans << endl;
}


Measured memory_bytes: 1408
#include <cstdio>
#define MAX 10000
#define NIL -1

struct Node {
    int parent;
    int left;
    int right;
};

Node T[MAX];

int n, D[MAX], H[MAX];

void setDepth(int u, int d) {
    if (u == NIL ) return;
    D[u] = d;
    setDepth(T[u].left, d + 1);
    setDepth(T[u].right, d + 1);
}

int setHeight(int u) {
    int h1 = 0, h2 = 0;
    if ( T[u].left != NIL )
        h1 = setHeight(T[u].left) + 1;
    if ( T[u].right != NIL )
        h2 = setHeight(T[u].right) + 1;
    return H[u] = (h1 > h2 ? h1 : h2);
}

//??????u ??????????????????
int getSibling(int u) {
    if ( T[u].parent == NIL) return NIL;
    if ( T[T[u].parent].left != u && T[T[u].parent].left != NIL)
        return T[T[u].parent].left;
    if ( T[T[u].parent].right != u && T[T[u].parent].right != NIL)
        return T[T[u].parent].right;
    return NIL;
}


void print(int u) {
    printf("node %d: ", u);
    printf("parent = %d, ", T[u].parent);
    printf("sibling = %d, ", getSibling(u));
    int deg = 0;
    if ( T[u].left != NIL ) deg++;
    if ( T[u].right != NIL ) deg++;
    printf("degree = %d, ", deg);
    printf("depth = %d, ", D[u]);
    printf("height = %d, ", H[u]);


    if ( T[u].parent == NIL ) {
        printf("root\n");
    } else if ( T[u].left == NIL && T[u].right == NIL ) {
        printf("leaf\n");
    } else {
        printf("internal node\n");
    }
}


int main() {
    int v, l, r, root = 0;
    scanf("%d", &n);

    for ( int i = 0; i < n; i++ ) T[i].parent = NIL;

    for ( int i = 0; i < n; i++ ) {
        scanf("%d %d %d", &v, &l, &r);
        T[v].left = l;
        T[v].right = r;
        if ( l != NIL ) T[l].parent = v;
        if ( r != NIL ) T[r].parent = v;
    }

    for ( int i = 0; i < n; i++ ) if ( T[i].parent == NIL ) root = i;

    setDepth(root, 0);
    setHeight(root);


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

    return 0;
}

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

struct Node
{
    int key;
    Node *right, *left, *parent;
};
Node *root, *NIL;
void insert(int k)
{
    Node *y = NIL;
    Node *x = root;
    Node *z;
    z = (Node *)malloc(sizeof(Node));
    z->key = k;
    z->left = NIL;
    z->right = NIL;

    while(x != NIL)
    {
        y = x;
        if(z->key < x->key)
        {
            x = x->left;
        }
        else
        {
            x = x->right;
        }
    }
    z->parent = y;
    if(y == NIL)
    {
        root = z;
    }
    else
    {
        if(z->key < y->key)
            y->left = z;
        else
            y->right = z;
    }
}
void inorder(Node *u)
{
    if(u == NIL)   return;
    inorder(u->left);
    cout << " " << u->key;
    inorder(u->right);
}
void preorder(Node *u)
{
    if(u == NIL)    return;
    cout << " " << u->key;
    preorder(u->left);
    preorder(u->right);
}
Node *find(Node *x, int k)
{
    while(x != NIL && k != x->key)
    {
        if(k<x->key)
            x = x->left;
        else
            x = x->right;
    }
    return x;
}
int main()
{
    int n, m;
    string s;
    cin >> n;

    while(cin >> s)
    {
        if(s[0] == 'i')
        {
            cin >> m;
            insert(m);
        }
        else if(s[0] == 'p')
        {
            inorder(root);
            cout << endl;
            preorder(root);
            cout << endl;
        }
        else if(s[0] == 'f')
        {
            cin >> m;
            if(find(root, m) != NIL)
                cout << "yes" << endl;
            else
                cout << "no" << endl;

        }
    }
    return 0;
}

Measured memory_bytes: 21912