akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;

using lnt = long long;
using Real = long double;

#define ALL(obj) (obj).begin(),(obj).end()
#define RALL(obj) (obj).rbegin(),(obj).rend()
#define REP(i, n) for(lnt i=0;i<(n);++i)
#define RANGE(i, a, b) for(lnt i=(a);i<(b);++i)
#define RREP(i, n) for(lnt i=(n)-1;i>= 0;--i)

#define ln '\n'
#define pb push_back
#define eb emplace_back
#define pque priority_queue
#define umap unordered_map
#define uset unordered_set
#define dcout cout<<fixed<<setprecision(20)
#define summon_tourist cin.tie(0);ios::sync_with_stdio(false)

constexpr int dx[]={1,0,-1,0,1,1,-1,-1}, dy[]={0,-1,0,1,1,-1,1,-1};
constexpr Real eps = 1e-9; const Real pi = acosl(-1);
constexpr lnt BIG = INT_MAX/10, BBIG = LLONG_MAX/10;

template<class T> inline T GCD(T a,T b){T c;while(b!=0){c=a%b;a=b;b=c;}return a;}
template<class T> inline T LCM(T a,T b){T c=GCD(a,b);a/=c;return a*b;}
template<class T> inline T nCr(T a,T b){T i,r=1;for(i=1;i<=b;i++){r*=(a+1-i);r/=i;}return r;}
template<class T> inline T nHr(T a,T b){return nCr(a+b-1,b);}
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;}

using pint = pair<int, int>; using plnt = pair<lnt, lnt>;
using vint = vector<int>; using vlnt = vector<lnt>;
constexpr lnt MOD = 1e9+7;

int main(){
	summon_tourist;

	int N, A; cin >> N;
	int cnt[200000] = {};
	REP(i, N-1){
		cin >> A; A--;
		cnt[A]++;
	}
	REP(i, N){
		cout << cnt[i] << ln;
	}
}

Measured memory_bytes: 4476
{-# LANGUAGE ScopedTypeVariables #-}
{-# LANGUAGE BangPatterns #-}

import Control.Applicative
import Control.Monad
import Control.Arrow
import Data.List
import Data.Maybe
import Data.Char
import qualified Data.ByteString.Char8 as B
import Text.Printf

readInt = ( readLn :: IO Int )
readInts = map ( read :: String -> Int ) . words <$> getLine

getList = map ( fst . fromJust . B.readInt ) . B.words <$> B.getLine

which a b f = if f then a else b
mp [ a, b ] = ( a, b )

main = do
	[ a, b ] <- readInts
	putStrLn $ which "Odd" "Even" $ a * b `mod` 2 == 1


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

#define ll long long
#define INF 99999999
#define rep(i,n) for(int i=0,temp=(int)(n);i<temp;++i) //vec.size()がnの時等の高速化
#define all(x) (x).begin(),(x).end()
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define vint vector<int>
#define vvint vector<vector<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; }
int gcd(int a,int b){return b?gcd(b,a%b):a;}

int n,t;
vector<pair<int,int>> ct;
int main(){
  cin >> n >> t;
  ct.resize(n);
  rep(i,n)cin >> ct[i].first >> ct[i].second;
  VSORT(ct);

  rep(i,n){
    if(ct[i].second <= t){ 
      cout << ct[i].first << endl;
      return 0;
    }
  }
  cout << "TLE" << endl;

  return 0;
}


Measured memory_bytes: 256
#include <iostream>

using namespace std;
typedef long long ll;
const int MAXN = 1e5+10;

int n;
ll h[MAXN];

void solve() {
  bool ok = true;
  ll prev = 0;
  for (int i=0;i<n;i++) {
    if (prev < h[i]) {
      h[i]--;
    }
    if (prev > h[i]) {
      ok = false;
      break;
    }
    prev = h[i];
  }
  cout << (ok ? "Yes" : "No") << endl;
}

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


Measured memory_bytes: 1024
#include <bits/stdc++.h>
typedef long long lint;

#define PI acos(-1)
#define INF64 1LL << 60
#define INF32 1 << 29
#define all(a) (a).begin(), (a).end()
#define INV ((long long int)1000000007)

using namespace std;

void execute()
{
	int N;
	string S;
	cin >> N;
	cin >> S;
	vector<int> data(N, 0);
	vector<bool> alphabet_right(26, false);
	vector<bool> alphabet_left(26, false);
	int ans = 0;
	int count = 0;

	for (int i = 0; i < N; i++)
	{
		data[i] = (int)S[i] - (int)'a';
	}

	for (int i = 0; i < N; i++)
	{
		for (int j = i + 1; j < N; j++)
		{
			alphabet_right[data[j]] = true;
		}

		for (int j = i; 0 <= j; j--)
		{
			alphabet_left[data[j]] = true;
		}

		for (int j = 0; j < 26; j++)
		{
			if (alphabet_right[j] && alphabet_left[j])
			{
				//cout << i << " " << j << endl;
				count++;
			}
		}
		//cout << count << " ";
		ans = max(ans, count);
		count = 0;
		for (int j = 0; j < 26; j++)
		{
			alphabet_right[j] = false;
			alphabet_left[j] = false;
		}
	}
	cout << ans << endl;
	return;
}

int main()
{
	cin.tie(0);
	ios_base::sync_with_stdio(false);
	std::cout << std::fixed << std::setprecision(15);
	execute();

	int stop;
	cin >> stop;

	return 0;
}

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

typedef long long ll;

int main(){
    string s;
    cin>>s;
    int ans = 0;
    int tmp = 0;
    for(auto a : s){

        if(a == 'R'){
            tmp++;
            ans = max(ans, tmp);
        }else{
            tmp=0;
        }
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 3616
#include <iostream>
#include <algorithm>
#include <cmath>
#include <stdio.h>
#include <stdlib.h>
#include <vector>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <string.h>
#include <stack>
#define Endl endl
#define mp make_pair
#define rep(N) for(int i=0;i<N;i++)
#define repj(N) for(int j=0;j<N;j++)
#define ll long long 
#define pii pair<int,int>
#define pll pair<ll,ll>
#define For(I,N) for(int I=0;I<N;I++)
#define cinone(N) int N;cin>>N;
#define scanfone(N) int N;cin>>N;
#define cinng(N,M) int N[M];for(int yiuytvnm=0;yiuytvnm<M;yiuytvnm++) cin>>N[yiuytvnm];
#define scanfng(N,M) int N[M];for(int qrwuoiq=0;qrwuoiq<M;qrwuoiq++) scanf("%d",&N[qrwuoiq]);
#define over(A) {cout<<A<<endl;exit(0);}
typedef unsigned long long ull;
const int inf=103974182;
using namespace std;
int n;
int a[200005];

int main()
{
//	freopen("input.txt","r",stdin);
	cin>>n;
	for(int i=0;i<n;i++)
	{
		scanf("%d",a+i);
		a[i]-=i+1;
	}
	sort(a,a+n);
	int x=a[n/2];
	ll res=0;
	for(int i=0;i<n;i++)
	{
		res+=abs(x-a[i]);
	}
	cout<<res<<endl;
	return 0;
}

Measured memory_bytes: 1024
n, k = gets.split().map(&:to_i)
r, s, p = gets.split().map(&:to_i)
t = gets.chomp.split('')

hand = {}
hand["r"] = p
hand["s"] = r
hand["p"] = s
array = []

t.each_with_index do |i, index|
  if index < k
    array << hand[i]
    next
  end
  if t[index-k] == i && array[index-k] != 0
    array << 0
  else
    array << hand[i]
  end
end

puts array.inject(&:+)

Measured memory_bytes: 7804
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define ft first
#define sd second
#define fr(i,n) for(int i=0;i<(n);++i)
#define Fr(i,n) for(int i=1;i<=(n);++i)
#define ifr(i,n) for(int i=(n)-1;i>=0;--i)
#define iFr(i,n) for(int i=(n);i>0;--i)

struct modint{
    ll a;
    const ll MOD=1e9+7;
    modint(ll a_=0){
        a=((a_%MOD)+MOD)%MOD;
    }
    modint inv()const{
        ll n=1,m=MOD-2,A=a;
        while(m){
            if(m&1)(n*=A)%=MOD;
            (A*=A)%=MOD;
            m>>=1;
        }
        modint y(n);
        return y;
    }
    bool operator==(const modint& x){
        return a==x.a;
    }
    bool operator!=(const modint& x){
        return a!=x.a;
    }
    modint& operator=(const modint& x){
        a=x.a;
        return *this;
    }
    modint operator+(const modint& x){
        modint y(a+x.a);
        return y;
    }
    modint operator-(const modint& x){
        modint y(a-x.a);
        return y;
    }
    modint operator*(const modint& x){
        modint y(a*x.a);
        return y;
    }
    modint operator/(const modint& x){
        return *this * x.inv();
    }
    modint& operator+=(const modint& x){
        *this=*this+x;
        return *this;
    }
    modint& operator-=(const modint& x){
        *this=*this-x;
        return *this;
    }
    modint& operator*=(const modint& x){
        *this=*this*x;
        return *this;
    }
    modint& operator/=(const modint& x){
        *this=*this/x;
        return *this;
    }
};
istream& operator>>(istream &in,modint& x){
    ll a_;
    in>>a_;
    modint y(a_);
    x=y;
    return in;
}
ostream& operator<<(ostream &out,const modint& x){
    out<<x.a;
    return out;
}
modint pwr(ll a,ll b){
    modint n(1),A(a);
    while(b){
        if(b&1) n*=A;
        A*=A;
        b>>=1;
    }
    return n;
}

int main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    string l;
    cin>>l;
    modint ka(1),ans(0);
    int n=l.length(),t=0;
    fr(i,n){
        if(l[i]-'0'){
            ans+=ka*pwr(3,n-i-1);
            ka*=2;
            ++t;
        }
    }
    ans+=pwr(2,t);
    cout<<ans<<endl;
}

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

const int K = 5003;
int d[K];

int hmt(int n, int k, int i) {
	int dr = (--n) / k;
	if(n % k >= i)
		++dr;
	return dr;
}

int ffp(int n, int x, int m, int k) {
	int dr = 0;
	for(int i = 1; i <= k; ++i) {
		if(d[i] == 0)
			dr += hmt(n, k, i);
	}
	int sgn = x / m, gn = sgn, ns = x % m;
	for(int i = 1; i <= k; ++i) {
		long long tmp = d[i];
		tmp *= hmt(n, k, i);
		tmp += ns;
		ns = tmp % m;
		gn += tmp / m;
	}
	dr += gn - sgn;
	dr = n - 1 - dr;
	return dr;
}

int k, q, rd[K], n, x, m;

int main() {
	ios::sync_with_stdio(0);
	cin.tie(0);
	cin >> k >> q;
	for(int i = 1; i <= k; ++i)
		cin >> rd[i];
	for(int qi = 1; qi <= q; ++qi) {
		cin >> n >> x >> m;
		for(int i = 1; i <= k; ++i)
			d[i] = rd[i] % m;
		cout << ffp(n, x, m, k) << "\n";
	}
	cout << flush;
	return 0;
}


Measured memory_bytes: 384
#include<stdio.h>
#include <algorithm>
#include <cassert>
#include <cctype>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <iostream>
#include <iterator>
#include <list>
#include <map>     
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <iomanip>
#include <stack>
#include <string>
#include <vector>
using namespace std;
#define ll long long
#define ld long double
#define rep(a,t) for(int a=0;a<t;a++) 
#define forever while(true)
#define Sort(a) sort(a.begin(),a.end())
#define Reverse(a) reverse(a.begin(),a.end())
#define pb push_back
long gcd(long a, long b)
{
	if (b == 0) { return a; }
	return gcd(b, a % b);
}
double ceil(double a) {
	if ((double)((int)a) == a) { return a; }

	return (double)((int)a+1);
}
int main()
{
	cin.tie(0);
	ios::sync_with_stdio(false);
	ll n1;
	cin >> n1;
	ll left = 1;
	ll right = 1;
	rep(i, n1) {
		ll n,x, y;
		cin >> x >> y;
		n = max((left + x - 1) / x, (right + y - 1) / y);
		left = n*x;
		right = n*y;
	}
	cout << left + right << endl;
	return 0;
}


Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
#define int long long
#define endl '\n'
int mod=1e9+7;

signed main(){
  int n,a,b;
  cin>>n>>a>>b;
  vector<int> p(n);
  vector<int> x(3,0);
  for(int i=0;i<n;i++){
    cin>>p[i];
    if(p[i]<=a)x[0]++;
    else if(p[i]<=b)x[1]++;
    else x[2]++;
  }
  cout<<min(x[0],min(x[1],x[2]))<<endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, n) for(int i = 0; i < (n); i++)
using namespace std;
using P = pair<int, int>;
using ll = long long;
 
int main(){
	int n;
  	cin >> n;
  	
  	bool ans = false;
  	for(int i = 1; i < 10; i++){
    	if(n % i == 0 && n / i < 10) ans = true; 	
    }
  
  	if(ans) cout << "Yes" << endl;
  	else cout << "No" << endl;
}

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

using namespace std;
int k[40500];
int main(){
    int n;
 	cin>>n;
    for(int i=0;i<n;i++){
        k[i]=i+1;
    }
    sort(k,k+n);
    int cnt=0;
    string a,b;
    cin.ignore();
    getline(cin,a);
    getline(cin,b);
    a=a+" ";
    b=b+" ";
    int first=0,second=0;
    do{
    	cnt++;
    	string s="";
        for(int i=0;i<n;i++){
            char c=(k[i]+'0');
            s+=c;
            s+=" ";
        }
        // cout<<s<<endl;
    	if(s==a)first=cnt;
    	if(s==b)second=cnt;
    }while(next_permutation(k,k+n));
    // cout<<first<<" "<<second<<endl;
    cout<<abs(first-second);
    return 0;
}

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

#define ALL(v) v.begin(), v.end()
#define V vector
#define P pair
#define ld long double
#define ll long long
#define mod 1000000007
#define IINF INT_MAX
#define INF 1LL << 30


int main() {
    int n; cin >> n;
    V<int> p(n);
    for(int i = 0; i < n; i++) cin >> p[i];
    V<int> q = p;
    sort(ALL(q));

    int cnt = 0;
    for(int i = 0; i < n; i++){
        if(p[i] != q[i]) cnt++;
    }
    if(cnt == 2 || cnt == 0) cout << "YES" << endl;
    else cout << "NO" << endl;

    return 0;
}


Measured memory_bytes: 3608
#include <stdio.h>

int main(void){
    int L, R, x, y;

    scanf("%d %d", &L, &R);

    if((R - L) >= 2019){
        printf("0\n");
        return 0;
    }
  
    y = 2018;

    for(int i = L; i < R; i++){
        for(int j = i + 1; j <= R; j++){
            x = (i%2019) * (j%2019) % 2019;
            if(x<y){
                y = x;
            }
        }
    }
    printf("%d\n",y);
    return 0;
}

Measured memory_bytes: 128
#include "bits/stdc++.h"
#define rep(i,n) for(int i=0;i<n;i++)
using namespace std;

typedef long long ll;

int main() {
    int N;
    cin >> N;
    vector<int> x(N), y(N), h(N);
    rep(i, N) cin >> x[i] >> y[i] >> h[i];
    rep(Cx, 101) {
        rep(Cy, 101) {
            int H = 2e9;
            rep(i, N) {
                H = min(H, h[i] + abs(x[i] - Cx) + abs(y[i] - Cy));
            }
            bool f = true;
            rep(i, N) {
                int h0 = h[i] + abs(x[i] - Cx) + abs(y[i] - Cy);
                if (h[i] == 0) {
                    if (h0 < H) f = false;
                } else {
                    if (h0 != H) f = false;
                }
            }
            if (f) {
                cout << Cx << " " << Cy << " " << H << endl;
                return 0;
            }
        }
    }
}

Measured memory_bytes: 256
#include<cstdio>
#include<iostream>
#include<algorithm>
#include<string>
#include<queue>
#include<vector>
#include<functional>
#include<cmath>
#include<map>
#include<stack>
#include<set>
#include<numeric>
#include<limits>
#include<iterator>

#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
#define rep(i,n) for(int i=0; i<n; i++)
#define INF (1<<20)

using namespace std;
typedef long long ll;
typedef pair<int, int> pi;
typedef pair<ll, ll> pl;
typedef pair<ll, char> plc;

ll dp[100010];
int n;
ll inf = (ll)(1e10);
vector<ll> a;

void solve() {
	fill(dp, dp + n, inf);
	rep(i, n) {
		*lower_bound(dp, dp + n, a[i]) = a[i];
	}
	cout << lower_bound(dp, dp + n, inf) - dp << endl;
}

int main() {
	cin >> n;
	a.resize(n);
	rep(i, n)cin >> a[i];
	solve();

	return 0;
}

Measured memory_bytes: 4372
#include<bits/stdc++.h>
using namespace std;
#define int long long
int a[200010],b[200010],sa[200010],sb[200010];
signed main()
{
	int n,m,k,i,maxv=0;
	cin>>n>>m>>k;
	for(i=1;i<=n;i++)
	{
		cin>>a[i];
		sa[i]=sa[i-1]+a[i];
	}
	for(i=1;i<=m;i++)
	{
		cin>>b[i];
		sb[i]=sb[i-1]+b[i];
	}
	for(i=0;i<=n;i++)
	{
		if(sa[i]>k)
			break;
		maxv=max(maxv,(int)(i+(upper_bound(sb+1,sb+m+1,k-sa[i])-sb)-1));
	}
	cout<<maxv;
	return 0;
}

Measured memory_bytes: 9864
#include <stdio.h>

int main(){
	double x1,x2,x3,x4,y1,y2,y3,y4,v1x,v1y,v2x,v2y;

	while(scanf("%lf %lf %lf %lf %lf %lf %lf %lf",&x1,&y1,&x2,&y2,&x3,&y3,&x4,&y4) != EOF){
		v1x = x2-x1;
		v1y = y2-y1;
		v2x = x4-x3;
		v2y = y4-y3;

		if(v1x*v2x+v1y*v2y == 0.0){
			printf("YES\n");
		}else{
			printf("NO\n");
		}
	}

	return 0;
}

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

public class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    int N = sc.nextInt();
    int L = sc.nextInt();
    String[] list = new String[N];
    for(int i=0;i<N;i++){
      list[i]=sc.next();
    }
    Arrays.sort(list);
    for(int i=0;i<N;i++){
      System.out.print(list[i]);
    }
  }
}

Measured memory_bytes: 24020
#include <unordered_map>
#include <iostream>
#include <iomanip>
#include <string>
#include <vector>

using namespace std;

using LL = long long;

class Solution {
private:
	LL c(LL n) {
		if (n < 2)
			return 0;
		return n * (n - 1) / 2;
	}
public:
	/* time: O(1), space: O(1) */
	vector<LL> bannedK(const vector<int>& A) {
		const int n = A.size();

		unordered_map<int, int> h;
		for (int num : A)
			++h[num];

		LL total = 0;
		unordered_map<int, LL> n_ways;
		for (const auto& it : h) {
			LL count = c(it.second);
			n_ways[it.first] = count;
			total += count;
		}

		vector<LL> ans(n);
		for (int i = 0; i < n; ++i) {
			const int num = A[i];
			ans[i] = total - n_ways[num] + c(h[num] - 1);
		}
		return ans;
	}
};

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

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

	Solution sol;
	const vector<LL> ans = sol.bannedK(A);
	for (LL n_ways : ans)
		cout << fixed << n_ways << endl;
	return 0;
}


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

public class Main {

    int n;
    P[] ps;


    void run() {
        Scanner sc = new Scanner(System.in);
        n = sc.nextInt();
        ps = new P[n];

        long t = 0;
        for (int i = 0; i < n; i++) {
            ps[i] = new P(sc.nextLong(), sc.nextLong());
            t += ps[i].a;
        }

        Arrays.sort(ps);
        for (int i = 0; i < n; i++) {
            if (t > ps[i].b) t = ps[i].b;
            if (t - ps[i].a < 0) {
                System.out.println("No");
                return;
            }
            t -= ps[i].a;
        }

        System.out.println("Yes");
    }

    class P implements Comparable<P> {
        long a, b;
        P(long a, long b) {
            this.a = a;
            this.b = b;
        }

        @Override
        public int compareTo(P o) {
            return (int)(o.b - b);
        }
    }


    void debug(Object...os) {
        System.err.println(Arrays.deepToString(os));
    }

    public static void main(String[] args) {
        new Main().run();
    }
}


Measured memory_bytes: 108036
#include <bits/stdc++.h>
using namespace std;
 
#define REP(i, s) for (int i = 0; i < s; ++i)
#define ALL(v) (v.begin(), v.end())
#define COUT(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << endl
#define EACH(i, s) for (__typeof__((s).begin()) i = (s).begin(); i != (s).end(); ++i)
 
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
template<class T1, class T2> ostream& operator << (ostream &s, pair<T1,T2> P)
{ return s << '<' << P.first << ", " << P.second << '>'; }
template<class T> ostream& operator << (ostream &s, vector<T> P)
{ for (int i = 0; i < P.size(); ++i) { if (i > 0) { s << " "; } s << P[i]; } return s; }
template<class T> ostream& operator << (ostream &s, vector<vector<T> > P)
{ for (int i = 0; i < P.size(); ++i) { s << endl << P[i]; } return s << endl; }
template<class T> ostream& operator << (ostream &s, set<T> P)
{ EACH(it, P) { s << "<" << *it << "> "; } return s << endl; }
template<class T1, class T2> ostream& operator << (ostream &s, map<T1,T2> P)
{ EACH(it, P) { s << "<" << it->first << "->" << it->second << "> "; } return s << endl; }
typedef long long ll;

int main(){
    vector<int>a;
    int n;
    cin>>n;
    REP(i,3*n){
        int x;
        cin>>x;
        a.push_back(x);
    }
    sort(a.rbegin(),a.rend());
    ll cnt=0;
   for(int i=0;i<n;i++){
       cnt+=a[2*i+1];
   }
    cout<<cnt<<endl;
    return 0;
}

Measured memory_bytes: 2420
#include<bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < n ; i++)
#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define whole(f, x, ...) ([&](decltype((x)) whole) { return (f)(begin(whole), end(whole), ## __VA_ARGS__); })(x) // decltypeで型取得、引数があればva_argsのところに入れる
#define Fill(x, v, y) fill(x, x + v, y);
using namespace std;
typedef long long ll; // long longをllでかけるようにした
const int INF = 1e9;
const long long INFTY = (1LL<<32);
const double PI = 3.1415926535;
const int MOD = 1000000007; // 計算してからmodで割る ans = (ans * a) % mod
#define int long long
template <typename T = long long > T in () { T x; cin >> x; return(x);}
// int a = in() のように使うlong long以外の型の時はstirng s = in<string>()のように型を指定する

// ここから
class UnionFind{
    public:
        vector<int> rank, p;

        UnionFind() {}
        UnionFind(int size){
            rank.resize(size, 0);
            p.resize(size, 0);
            REP(i, size) makeSet(i);
        }

        void makeSet(int x){
            p[x] = x;
            rank[x] = 0;
        }

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

        void unite(int x, int y){
            link(findSet(x), findSet(y));
        }

        void link(int x, int y){
            if(rank[x] > rank[y]){
                p[y] = x;
            }else{
                p[x] = y;
                if(rank[x] == rank[y]){
                    rank[y]++;
                }
            }
        }

        int findSet(int x){
            if(x != p[x]){
                p[x] = findSet(p[x]);
            }
            return p[x];
        }
};

signed main(void){
    
    int n, q; cin >> n >> q;

    UnionFind uf = UnionFind(n);

    REP(i, q){
        int t, a, b;
        cin >> t >> a >> b;
        if(t == 0) uf.unite(a, b);
        else if(t == 1){
            if(uf.same(a, b)) cout << 1 << endl;
            else cout << 0 << endl;
        }
    }
}


Measured memory_bytes: 3236
#include<iostream>
#include<string>
#include<algorithm>
using namespace std;
 
int main(){
  string str;
  int q;
  cin >> str;
  cin >> q;
  while(q--){
    string s;
    cin >> s;
    if(s == "print"){
      int a, b;
      cin >> a >> b;
      cout << str.substr( a, b - a + 1) << endl;
    } else if(s == "reverse"){
      int a, b;
      cin >> a >> b;
      reverse( str.begin() + a, str.begin() + b + 1);
    } else {
      int a, b;
      string p;
      cin >> a >> b >> p;
      str.replace( a, b - a + 1, p);
    }
  }
}


Measured memory_bytes: 3164
#include <bits/stdc++.h>
#define repp(i,l,r)for(long long i=(l);i<(r);i++)
#define rep(i,n) for (long long i = 0; i < (n); ++i)
#define per(i,n) for (long long i = (n); i >= 0; --i)
const int INF = 2147483647;//int max
const long long int MOD = 1000000007;
using namespace std;
using ll = long long;
using P = pair<int,int>;
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }


//ミョ(-ω- ?)
int main() {
    ll n;
    cin >> n;
    vector<ll> a(n,0);
    vector<ll>  cnt(1001010,0);
    rep(i,n){
        cin >> a[i];
        cnt[a[i]]++;
    }
    vector<bool> ok(1000005,true);
  	ll x = 0;
    for(ll i = 0;i<1000001;i++){
      	x = i;
      	if(cnt[x] < 1)continue;
      	//ll x = a[i];
        if(cnt[x] > 1)ok[x] = false;
        for(ll i = 2*x;i < 1000001;i += x)ok[i]=false;
    }
    ll res = 0;
    rep(i,n)if(ok[a[i]])res++;
    cout << res << "\n";
    return 0;
}


Measured memory_bytes: 12764
#include <iostream>
#include <map>
#include <string>
#include <vector>
#include <algorithm>
using namespace std;

vector<string> f(string const& s, string& group) {
    group.clear();
    string item;
    vector<string> res;
    for(int i=0; i<s.size(); ++i) {
        if(s[i] == ':') {
            group = item;
            item.clear();
        } else if(s[i] == ',' || s[i] == '.') {
            res.push_back(item);
            item.clear();
        } else {
            item += s[i];
        }
    }
    return res;
}

int main() {
    int n;
    while(cin >> n, n) {
        vector<string> first;
        map<string, vector<string>> m;
        {
            string s;
            cin >> s;
            string group;
            first = f(s, group);
        }
        for(int i=1; i<n; ++i) {
            string s;
            cin >> s;
            string group;
            vector<string> v = f(s, group);
            m[group] = v;
        }
        vector<string> res;
        while(true) {
            vector<string> tmp;
            bool update = false;
            for(auto& s : first) {
                if(m.count(s) == 1) {
                    update = true;
                    for(auto& s2 : m[s]) {
                        tmp.push_back(s2);
                    }
                } else {
                    tmp.push_back(s);
                }
            }
            sort(tmp.begin(), tmp.end());
            tmp.erase(unique(tmp.begin(), tmp.end()), tmp.end());
            if(!update) {
                res = tmp;
                break;
            }
            first = tmp;
        }
        cout << res.size() << endl;
    }
}


Measured memory_bytes: 3276
#![allow(unused_imports)]
#![allow(unused_macros)]

use std::cell::RefCell;
use std::cmp::{max, min, Ordering};
use std::collections::*;
use std::fmt::{Debug, Formatter, Write as FmtWrite};
use std::io::{stderr, stdin, BufRead, Write};
use std::mem::{replace, swap};
use std::ops::*;
use std::rc::Rc;


//
// Macro debug!
//

#[cfg(debug_assertions)]
include!{"./procon/debug.rs"}

#[cfg(not(debug_assertions))]
macro_rules! debug {
    ($($arg:expr),*) => {};
}


//
// Macro input!
//

macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
    ($($r:tt)*) => {
        let s = {
            use std::io::Read;
            let mut s = String::new();
            std::io::stdin().read_to_string(&mut s).unwrap();
            s
        };
        let mut iter = s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
}

macro_rules! input_inner {
    ($iter:expr) => {};
    ($iter:expr, ) => {};

    ($iter:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($iter, $t);
        input_inner!{$iter $($r)*}
    };
}

macro_rules! read_value {
    ($iter:expr, ( $($t:tt),* )) => {
        ( $(read_value!($iter, $t)),* )
    };

    ($iter:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($iter, $t)).collect::<Vec<_>>()
    };

    ($iter:expr, chars) => {
        read_value!($iter, String).chars().collect::<Vec<char>>()
    };

    ($iter:expr, usize1) => {
        read_value!($iter, usize) - 1
    };

    ($iter:expr, $t:ty) => {
        $iter.next().unwrap().parse::<$t>().expect("Parse error")
    };
}


//
// IteratorExt
//

trait IteratorExt: Iterator + Sized {
    fn vec(self) -> Vec<Self::Item> {
        self.collect()
    }
}

impl<T: Iterator> IteratorExt for T {}


//
// Main
//

fn main() {
    input! {
        a: usize,
        b: usize,
        c: usize,
    }

    let ans = c - min(a - b, c);
    println!("{}", ans);
}


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

#define forn(i,n) for(int i=0;i<(int)(n);i++)
#define si(c) ((int)(c).size())
#define forsn(i,s,n) for(int i = (int)(s); i<((int)n); i++)
#define dforsn(i,s,n) for(int i = (int)(n)-1; i>=((int)s); i--)
#define all(c) (c).begin(), (c).end()
#define D(a) cerr << #a << "=" << (a) << endl;
#define pb push_back
#define eb emplace_back
#define mp make_pair

typedef long long int ll;
typedef vector<int> vi;
typedef pair<int,int> pii;

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

    int n; cin >> n;
    vi a(n);
    forn(i,n) cin >> a[i];

    ll l,r; l = r = 2;
    dforsn(i,0,n) {
        ll k = a[i];
        ll st = (l+k-1)/k*k;
        ll en = r/k*k + k-1;
        l = st; r = en;
    }
    if (l > r) cout << -1;
    else cout << l << " " << r << endl;

    return 0;
}


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

typedef long long int ll;

int main () {
	ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    
    ll n;
    cin >> n;
    
    ll a[n];
    for (ll i=0 ; i<n ; i++) {
		cin >> a[i];
	}
	
	sort(a,a+n);
	
	ll ans = 0;
	
	for (ll i=0 ; i<n ; i++) {
		for (ll j=i+1 ; j<n ; j++) {
			if (a[i]==a[j]) continue;
			for (ll k=j+1 ; k<n ; k++) {
				if (a[i]==a[k] || a[j]==a[k]) continue;
				if ((a[i]+a[j])>a[k]) ans++;
			}
		}
	}
	
	cout << ans << "\n";
}


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

int h, w;
long long smin = (1<<30);

int main() {
    cin >> h >> w;
    if (h % 3 == 0 || w % 3 == 0) {
        cout << 0;
        return 0;
    }
    if (h >= 3) smin = min(smin,1LL*h);
    if (w >= 3) smin = min(smin,1LL*w);
    
    int a = w/2;
    long long x = 1LL * a * h / (w + a);
    long long maxn = max({x*w,1LL*a*h-a*x,1LL*(w-a)*h-(w-a)*x});
    long long minn = min({x*w,1LL*a*h-x*a,1LL*(w-a)*h-(w-a)*x});
    smin = min(smin,maxn-minn);
    x++;
    maxn = max({x*w,1LL*a*h-a*x,1LL*(w-a)*h-(w-a)*x});
    minn = min({x*w,1LL*a*h-x*a,1LL*(w-a)*h-(w-a)*x});
    smin = min(smin,maxn-minn);
    swap(w,h);
    a = w/2;
    x = 1LL * a * h / (w + a);
    maxn = max({x*w,1LL*a*h-a*x,1LL*(w-a)*h-(w-a)*x});
    minn = min({x*w,1LL*a*h-x*a,1LL*(w-a)*h-(w-a)*x});
    smin = min(smin,maxn-minn);
    x++;
    maxn = max({x*w,1LL*a*h-a*x,1LL*(w-a)*h-(w-a)*x});
    minn = min({x*w,1LL*a*h-x*a,1LL*(w-a)*h-(w-a)*x});
    smin = min(smin,maxn-minn);
    cout << smin;
}

Measured memory_bytes: 256
#include<cstdio>
#include<queue>
#include<cmath>
#include<map>
#include<iostream>
#include<cstring>
#include<cmath>
using namespace std;
char s[4];
int main(){
	scanf("%s",s);
	for(int i=0;i<3;i++){
		if(s[i]==57)printf("1");
		else {
			if(s[i]==49)printf("9");
			else printf("%c",s[i]);
		}
	}
	getchar();
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#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 equals(a, b) (fabs((a) - (b)) < EPS)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
const ll mod = 1000000007;
//const ll mod = 998244353;
const int inf = 1e9 + 10;
const ll INF = 1e18;
const ld EPS = 1e-10;
const int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
const int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};
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 (a>b) { a=b; return 1; } return 0; }

ll s[405][405];
ll dp[405][405];

void init() {
  rep(i, 405) s[i][0] = 1;
  rep(i, 405) {
    rep(j, 404) {
      s[i][j + 1] = s[i][j] * i % mod;
    }
  }
  rep(j, 405) {
    rep(i, 404) {
      s[i + 1][j] = (s[i + 1][j] + s[i][j]) % mod;
    }
  }
}

int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout << fixed << setprecision(25);

  init();

  ll n, c;
  cin >> n >> c;
  vector<ll> a(n), b(n);
  rep(i, n) cin >> a[i];
  rep(i, n) cin >> b[i];

  dp[0][c] = 1;
  rep(i, n) {
    rep(j, c + 1) {
      rep(k, j + 1) {
        ll res = (s[b[i]][k] - s[a[i] - 1][k] + mod) % mod;
        dp[i + 1][j - k] = (dp[i + 1][j - k] + dp[i][j] * res) % mod;
      }
    }
  }
  cout << dp[n][0] << '\n';
  
  


  




  
  return 0;
}

Measured memory_bytes: 6184
import queue

INFTY=1<<21

#ダイクストラ法
def dijkstra(n,EdgeMatrix,start):

    NodeList=queue.PriorityQueue() #探索対象の頂点
    Distance=[INFTY]*n #頂点0からの最短経路
    used=[False]*n #頂点の使用情報

    Distance[start]=0 #0から0までの距離は0
    used[start]=True #0から探索を始める
    LastNode=start #最新の頂点
    count=1 #つないだ頂点の数

    while count<n:
        for i in range(len(EdgeMatrix[LastNode])):
            #探索していない頂点へ距離の短い辺があればキューに追加
            Edge=EdgeMatrix[LastNode][i]
            if used[Edge[0]]==False and Distance[Edge[0]]>Distance[LastNode]+Edge[1]:
                    Distance[Edge[0]]=Distance[LastNode]+Edge[1]
                    NodeList.put([Distance[Edge[0]],Edge[0]])

        #最も近い探索していない頂点
        while True:
            minNode=NodeList.get()
            if used[minNode[1]]==False:
                break

        LastNode=minNode[1] #最新の頂点を更新
        used[minNode[1]]=True #頂点の使用情報を更新
        count+=1 #つないだ頂点の数を更新
    return Distance

#入力
n=int(input())

#辺の隣接行列
EdgeMatrix=[[] for i in range(n)]
for i in range(n):
    l=(list(map(int,input().split())))
    for j in range(l[1]):
        EdgeMatrix[l[0]].append([l[2*j+2],l[2*j+3]])

#頂点0からの最短経路
Distance=dijkstra(n,EdgeMatrix,0)

for node,distance in enumerate(Distance):
    print(node,distance)



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

int main()
{

  int N;
  int i,j,k=111;
  
  scanf("%d",&N);
  
  for(i=0;k<N;k+=111){
  }
  
  printf("%d\n",k);
  
  return 0;
}
  

Measured memory_bytes: 128
let rec take n = function
  | [] -> []
  | x :: xs ->
      if n = 0 then []
      else x :: take (n - 1) xs

let () = Scanf.scanf "%d %d\n" @@ fun n m ->
  let xyzs = Array.to_list @@ Array.init n @@ fun _ ->
    Scanf.scanf "%d %d %d\n" @@ fun x y z -> x, y, z in
  begin List.concat @@ List.map (fun sx ->
    List.concat @@ List.map (fun sy ->
      List.map (fun sz ->
        List.sort (fun (x, y, z) (x', y', z') ->
          compare (sx * x' + sy * y' + sz * z') (sx * x + sy * y + sz * z)) xyzs
        |> take m
        |> List.fold_left (fun (x, y, z) (x', y', z') -> (x + x', y + y', z + z')) (0, 0, 0)
        |> (fun (x, y, z) -> abs x + abs y + abs z)) [ 1; -1 ]) [ 1; -1 ]) [ 1; -1 ] end
  |> List.fold_left max min_int 
  |> Printf.printf "%d\n"

Measured memory_bytes: 4736
# ABC 088: B – Card Game for Two
n = int(input())
a = [int(s) for s in input().split()]
a.sort()
a.reverse()

alice = 0
bob = 0

while len(a) > 0:
    alice += a.pop(0)
    if len(a) > 0:
        bob += a.pop(0)

print(alice - bob)

Measured memory_bytes: 3060
#include<bits/stdc++.h>
using namespace std;
int main(){
  int N;cin>>N;
  vector<int> a(N);
  for(int i=0;i<N;i++)cin>>a.at(i);
  int count=0,sum=0,p=a.at(0);
  for(int i=0;i<N;i++){
    if(p==a.at(i)){
      count++;
    }
    else{
      sum+=count/2;
      p=a.at(i);
      count=1;
    }
  }
  if(a.at(N-2)==a.at(N-1))sum+=count/2;
  cout<<sum<<endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define Boost ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);

void Crack() {
	string S;
	cin >> S;
	int ans = 0;
	if(S[0]=='R' && S[1]=='R' && S[2]=='R') ans = 3;
	else if(S[0]=='R' && S[1]=='R') ans = 2;
	else if(S[1]=='R' && S[2]=='R') ans = 2;
	else if(S[0]=='R' || S[1]=='R' || S[2]=='R') ans = 1;
	else ans = 0;
	cout << ans << endl;
}

int main() {
	Boost;
    Crack();
	return 0;
}

Measured memory_bytes: 3632
#include <bits/stdc++.h>
 
using namespace std;
#define fr(i,a,b) for (long long int i = (a), _b = (b); i <= _b; i++)
#include<bits/stdc++.h>
#include<ratio>
#include <set> 
#include <iterator>
using namespace std;
#define ll long long
#define VV vector
#define vi vector <int>
#define pb push_back
#define bitc  __builtin_popcountl
#define m_p make_pair
#define inf 200000000000000
#define MAXN 100001
#define eps 0.0000000001
#define prime 1000000007
#define ll long long
#define int ll int
using namespace std;
#define S second
#define F first
#define float double 
ll MOD=1e9+7;
#define rep(i,n) for (long long i = 0, _n = (n); i < _n; i++)
long long StringToInteger(string NumberAsString)
{
  long long NumberAsInteger;
  stringstream ss;
  ss << NumberAsString;
  ss >> NumberAsInteger;
  return NumberAsInteger;
}
float ks[3001][6003];
float dp (int n,vector <float> &ps){
    for(int i=0;i<=n;i++)
    {
        for(int j=-n;j<=n;j++)
        {
            if(i==0)
             {
                 ks[i][j+n]=0;
             }
             else
             {
                ks[i][j+n]=ks[i-1][j+n-1]*ps[i-1]+ks[i-1][j+n+1]*(1-ps[i-1]);
            // cout<<i<<" "<<j+n<<" "<<ks[i][j+n]<<" 2"<<"\n";
             }
             if(i==0&&j==0)
             ks[i][j+n]=1;
        }
    }
    float sum=0.0;
    for(int j=0;j<=n;j++)
    {
        sum+=ks[n][j+n];
    }
    return sum;
 }
 int32_t main()
{   
    float n;
    cin>>n;
    vector <float> ps(n);     
    for(int i=0;i<n;i++)
    {
        cin>>ps[i];  
    }
    cout<<fixed<<setprecision(10)<<dp(n,ps);
}

Measured memory_bytes: 140928
public class Main {
public static void main(String[] args){
	
	String[] input = new java.util.Scanner ( System.in). nextLine().split(" ");
	int a = Integer.parseInt(input[0]);
	int b = Integer.parseInt(input[1]);
	
	System.out.println((a * b) + " " + ( 2 * a + 2 * b));
	
}
}

Measured memory_bytes: 17128
n,k=map(int,input().split())
d=[]
a=set()
for i in range(k):
    nu=int(input())
    d.append(nu)
    m=set(map(int,input().split()))
    a |=m
    
b=set()
for i in range(1,n+1):
    b |= {i}

count=0
for v1 in b:
    if not v1 in a:
        count+=1
print(count)

Measured memory_bytes: 9156
import sys, re, os
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import permutations, combinations, product, accumulate
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from fractions import gcd
import heapq

def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def S_MAP(): return map(str, input().split())
def LIST(): return list(map(int, input().split()))
def S_LIST(): return list(map(str, input().split()))

sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7

N, M = MAP()
A = LIST()
L = [LIST() for i in range(M)]
L = sorted(L, key=lambda x : x[1], reverse=True)
default_sum = sum(A)

heapq.heapify(A)  # リストを優先度付きキューへ

for max_cnt, target in L:
    cnt = 0
    while cnt < max_cnt and len(A) != 0:
        min_num = heapq.heappop(A) # pop min
        default_sum += max(target - min_num, 0)
        cnt += 1
    
print(default_sum)



    

exit()
print(heapq.heappop(a))  # 最小値の取り出し

heapq.heappush(a, -2)  # 要素の挿入
print(a)
for i in range(M):
    a = heapq.heappop(A) * (-1)
    a = a // 2
    heapq.heappush(A, -a)
A = list(map(lambda x: x * (-1), A))
print(sum(A))




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

int main(){
    int h, w, si, sj, ti, tj;
    cin >> h >> w >> si >> sj >> ti >> tj;
    --si; --sj; --ti; --tj;
    vs maze(h);
    rep(i,h) cin >> maze[i];
    vvi dist(h, vi(w,INF));
    dist[si][sj] = 0;
    deque<P> q;
    q.emplace_back(si,sj);

    while (!q.empty()){
        int i = q.front().first, j = q.front().second;
        q.pop_front();
        int d = dist[i][j];
        rep(k,4){
            int ni = i+di[k], nj = j+dj[k];
            if (ni < 0 || ni >= h || nj < 0 || nj >= w) continue;
            if (maze[ni][nj] == '#') continue;
            if (dist[ni][nj] <= d) continue;
            dist[ni][nj] = d;
            q.emplace_front(ni,nj);
        }
        for (int ei = -2; ei <= 2; ei++){
            for (int ej = -2; ej <= 2; ej++){
                int ni = i+ei, nj = j+ej;
                if (ni < 0 || ni >= h || nj < 0 || nj >= w) continue;
                if (maze[ni][nj] == '#') continue;
                if (dist[ni][nj] <= d+1) continue;
                dist[ni][nj] = d+1;
                q.emplace_back(ni,nj);
            }

        }
    }
    int ans = dist[ti][tj];
    if (ans == INF) ans = -1;
    cout << ans << endl;
}

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

int main() {
    int n; cin >> n;
    int best = 0;
    for(int i = 0, k = 0, prev = 0, cur = 0; i < n; i++) {
        cin >> k;
        if(prev != -1 && prev >= k) cur++;
        else cur = 0;
        best = max(best, cur);
        prev = k;
    }
    cout << best << endl;
    return 0;
}

Measured memory_bytes: 256
#pragma GCC optimize ("O3")
#include <iostream>
#include <vector>
using namespace std;
typedef int64_t int64;
#define print(x) cout << (x) << '\n'
 
int main(){
 int n, k; cin >> n >> k;
 int64 a[n];
 for (int i = 0; i < n; ++i) cin >> a[i];
 
 int64 s[n]; s[0] = a[0];
 for (int i = 1; i < n; ++i) s[i] = s[i - 1] + a[i];
 vector<int64> v;
 
 for (int i = 0; i < n; ++i) v.push_back(s[i]);
 for (int i = 0; i < n; ++i){
   for (int j = i + 1; j < n; ++j) v.push_back(s[j] - s[i]);
 }
 
 int64 ans = 0;
 for (int bit = 38; bit >= 0; --bit){
   int64 p = ((int64)1<<bit);
   int cnt = 0;
   
   for (int i = 0; i < (int) v.size(); ++i){
     if (((ans + p) & v[i]) == ans + p) ++cnt;
   }
   if (cnt >= k) ans += p;
 }
 print(ans);
 
 return 0;
}

Measured memory_bytes: 6384
using System;
using System.Collections.Generic;
using System.Linq;
using System.IO;
//using System.Text;
//using System.Text.RegularExpressions;
//using System.Globalization;
//using System.Diagnostics;
using static System.Console;
//using System.Numerics;
//using static System.Math;
//using pair = Pair<int, int>;

class Program
{
    static void Main()
    {
        //SetOut(new StreamWriter(OpenStandardOutput()) { AutoFlush = false });
        new Program().solve();
        Out.Flush();
    }
    Scanner cin = new Scanner();
    readonly int[] dd = { 0, 1, 0, -1, 0 }; //→↓←↑
    readonly int mod = 1000000007;
    void chmax<T>(ref T a, T b) where T : IComparable<T> { a = a.CompareTo(b) < 0 ? b : a; }
    void chmin<T>(ref T a, T b) where T : IComparable<T> { a = a.CompareTo(b) < 0 ? a : b; }

    void solve()
    {
        var S = ReadLine();
        int K = cin.nextint;
        var P = new SortedSet<string>();
        for (int i = 0; i < S.Length; i++)
        {
            var L = "";
            for (int j = 0; j < K; j++)
            {
                if (i + j == S.Length)
                {
                    break;
                }
                L += S[i + j];
                P.Add(L);
            }
        }

        WriteLine(P.ElementAt(K - 1));

    }

}

class Scanner
{
    string[] s; int i;
    char[] cs = new char[] { ' ' };
    public Scanner() { s = new string[0]; i = 0; }
    public string[] scan { get { return ReadLine().Split(); } }
    public int[] scanint { get { return Array.ConvertAll(scan, int.Parse); } }
    public long[] scanlong { get { return Array.ConvertAll(scan, long.Parse); } }
    public double[] scandouble { get { return Array.ConvertAll(scan, double.Parse); } }
    public string next
    {
        get
        {
            if (i < s.Length) return s[i++];
            string st = ReadLine();
            while (st == "") st = ReadLine();
            s = st.Split(cs, StringSplitOptions.RemoveEmptyEntries);
            i = 0;
            return next;
        }
    }
    public int nextint { get { return int.Parse(next); } }
    public long nextlong { get { return long.Parse(next); } }
    public double nextdouble { get { return double.Parse(next); } }
}

Measured memory_bytes: 15796
#include <iostream>
#include <cstdio>
#include <cmath>

using namespace std;

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

	 for (int n = 1; n <= N; ++n) {
	 	int res = 0;
	 	for (int a = 2; a <= floor(sqrt(2*n-2)); ++a)
	 		for(int b = 2; b <= floor(sqrt(2*n-1-a*a)); ++b) {
	 			float remain = 2*n - a*a - b*b;
	 			float c = floor(sqrt(remain));
	 			if (c*c == remain){
	 				int cc = (int) c;

	 				int x = a+b-cc;
	 				int y = a-b+cc;
	 				int z = cc+b-a;

	 				if (x%2==0 && x>=2 && y%2==0 &&y>=2 && z%2==0 && z>=2)
		 				res++;

	 			}
	 		}
	 	// cout << "f(" << n << ") = " << res << endl;
	 	cout << res << endl;

	 }

	return 0;
}


Measured memory_bytes: 3628
#include <stdio.h>

int main(void)
{
    char str[88];
    int sum = 0;
    int i = 0;
    int num = 0;
    
    while (scanf("%s", str) != EOF) {
    i = 0;
    num = 0;
    while (str[i] != '\0'){
        if (str[i] >= '0' && str[i] <= '9'){
                num = num * 10 + str[i] - '0';
        }
        else {
            sum += num;
            num = 0;
        }
        i++;
        
    }
    sum += num;
    }
    
    printf("%d\n", sum);
    
    return (0);
}

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

int n,m,k;

int main()
{
	scanf("%d %d %d",&n,&m,&k);
	for(int i=0;i<=n;i++){
		for(int j=0;j<=m;j++){
			if(m*i+n*j-2*i*j==k){
				puts("Yes");
				return 0;
			}
		}
	}
	puts("No");
	return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
int main(){
  int tai,n,i,count;
  char c[100][3];
  while(1){
    count=0;
    tai=0;
    scanf("%d",&n);
    if(n==0)break;
 
    for(i=0;i<n;i++){
      scanf(" %s", c[i]);
    }

    
    if(n==1){printf("0\n");continue;}
  else if(n!=0){
  for(i=1;i<n;i++){
    if(tai==0 && c[i-1][0]=='l' && c[i-1][1]=='u' && c[i][0]=='r' && c[i][1]=='u'){count++;tai=1;}
    if(tai==0 && c[i-1][0]=='r' && c[i-1][1]=='u' && c[i][0]=='l' && c[i][1]=='u'){count++;tai=1;}
    if(tai==1 && c[i-1][0]=='l' && c[i-1][1]=='d' && c[i][0]=='r' && c[i][1]=='d'){count++;tai=0;}
    if(tai==1 && c[i-1][0]=='r' && c[i-1][1]=='d' && c[i][0]=='l' && c[i][1]=='d'){count++;tai=0;}
  }
  }
  






  printf("%d\n",count);
  }
  
  return 0;
}

Measured memory_bytes: 616
#!/usr/bin/ruby
n,m=gets.split.map &:to_i
a=gets.split.map(&:to_i).sort.map.with_index{|e,i|e*(2*i+1-n)}.reduce(:+)
b=gets.split.map(&:to_i).sort.map.with_index{|e,i|e*(2*i+1-m)}.reduce(:+)
p a*b%(10**9+7)

Measured memory_bytes: 19816
#include <stdio.h>

int main(void)
{
    long ans=0,N,ai,i,max=0;
    scanf("%ld",&N);
    for(i=0;i<N;i++){
    	scanf("%ld",&ai);
    	if(ai>max) max=ai;
    	else if(ai<max) ans+=(max-ai);
    }
    printf("%ld\n",ans);
    return 0;
}

Measured memory_bytes: 1704
n,m = map(int,input().split())
data = [0 for i in range(m)]
for i in range(n):
    k,*a = map(int,input().split())
    for x in a:
        data[x-1] += 1
ans = 0
for i in range(m):
    if data[i] == n:
        ans += 1

print(ans)

Measured memory_bytes: 3060
#include <algorithm>
#include <cassert>
#include <cmath>
#include <cstring>
#include <ctime>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>
#include <queue>

#define CHECK_IMPL1(cond)                \
    if (!(cond)) {                       \
      DEBUG("expected cond: " << #cond); \
      assert(cond);                      \
    }

#define CHECK_IMPL2(cond, message)                                              \
    if (!(cond)) {                                                              \
      DEBUG("expected cond: " << #cond << " failed with message: " << message); \
      assert(cond);                                                             \
    }

#define CHECK_IMPL(_1, _2, NAME, ...) NAME
#define CHECK(...) CHECK_IMPL(__VA_ARGS__, CHECK_IMPL2, CHECK_IMPL1, CHECK_IMPL0)(__VA_ARGS__)

#ifdef __APPLE__
#define DEBUG(message) std::cerr << message << std::endl;
#else
#define DEBUG(message)
#endif

class Dsu {
public:
  Dsu(int n): p_(n, -1), sz_(n) {
  }

  void make_set(int i) {
    p_[i] = i;
    sz_[i] = 1;
  }

  int get(int v) {
    if (v == p_[v]) {
      return v;
    }
    return p_[v] = get(p_[v]);
  }

  int sz(int v) {
    return sz_[get(v)];
  }

  void merge(int a, int b) {
    a = get(a);
    b = get(b);

    if (a == b) {
      return;
    }

    if (rand() % 2) {
      std::swap(a, b);
    }

    p_[a] = b;
    sz_[b] += sz_[a];
  }

private:
  std::vector<int> p_;
  std::vector<int> sz_;
};

void solve() {
  int n, m;
  std::cin >> n >> m;

  Dsu dsu(n);
  for (int i = 0; i < n; ++i) {
    dsu.make_set(i);
  }

  for (int i = 0; i < m; ++i) {
    int u, v;
    std::cin >> u >> v;
    --u;
    --v;
    dsu.merge(u, v);
  }

  int ans = 0;
  for (int i = 0; i < n; ++i) {
    ans = std::max(ans, dsu.sz(i));
  }
  std::cout << ans << std::endl;
}

int main() {
#ifdef __APPLE__
  //freopen("input.txt", "r", stdin);
  //freopen("output.txt", "w", stdout);
#endif
  int t = 1;
  //std::cin >> t;
  while (t--) {
    solve();
  }
  return 0;
}


Measured memory_bytes: 7400