akhauriyash/Code-Regression huggingface dataset:
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Scanner;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 *
 * @author vdewansa
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        Scanner in = new Scanner(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        HGrid1 solver = new HGrid1();
        solver.solve(1, in, out);
        out.close();
    }

    static class HGrid1 {
        final int MOD = 1_000_000_000 + 7;

        int add(int a, int b) {
            return (a + b) % MOD;
        }

        public void solve(int testNumber, Scanner in, PrintWriter out) {
            int H = in.nextInt();
            int W = in.nextInt();
            boolean[][] walls = new boolean[H + 1][W + 1];
            for (int h = 1; h <= H; h++) {
                String row = in.next().trim();
                for (int w = 1; w <= W; w++) {
                    walls[h][w] = row.charAt(w - 1) == '#';
                }
            }
            int[][] ways = new int[H + 1][W + 1];
            ways[0][1] = 1;
            for (int h = 1; h <= H; h++) {
                for (int w = 1; w <= W; w++) {
                    if (!walls[h][w]) {
                        ways[h][w] = add(ways[h - 1][w], ways[h][w - 1]);
                    }
                }
            }
            out.println(ways[H][W]);
        }

    }
}



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

using namespace std;
typedef pair<string, int> P;

void solve()
{
	int n;
	while(cin >> n, n)
	{
		vector<P> Vec;
		set<int> Set;
		for(int i = 0; i < n; ++i)
		{
			string t;
			cin >> t;
			int sum = 0;
			for(int j = 0; j < n - 1; ++j)
			{
				int a;
				cin >> a;
				if(a == 0)
				{
					sum += 10000;
				}
				else if(a == 2)
				{
					sum += 100;
				}
			}
			Vec.push_back(P(t, sum));
			Set.insert(sum);
		}
		set<int>::reverse_iterator rit = Set.rbegin();
		while(rit != Set.rend())
		{
			for(int i = 0; i < n; ++i)
			{
				if(*rit == Vec[i].second)
				{
					cout << Vec[i].first << endl;
				}
			}
			++rit;
		}
	}
}

int main()
{
	solve();
	return(0);
}

Measured memory_bytes: 1204
#include <iostream>
#include <cstring>
#include <map>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <set>
#include <vector>
#include <queue>
#include <list>
#include <numeric>
#include <stdio.h>
#include <string>
#include <cstdlib>
#include <math.h>
#include <stack>
#include <climits>
#include <bitset>
#include <utility>


using namespace std;
typedef long long ll;

//最小公倍数
ll gcd(ll x, ll y) {
  ll tmp = 0;
  if (x < y){
    tmp=x;
    x=y;
    y=tmp;
  }
  while (y > 0) {
    ll r = x % y;
    x = y;
    y = r;
  }
  return x;
}

//最大公倍数
ll lcm(ll x,ll y){
  return x/gcd(x,y)*y;
}

//階乗
ll kaijo(ll k){
    ll sum = 1;
    for (ll i = 1; i <= k; ++i)
    {
        sum *= i;
        sum%=1000000000+7;
    }
    return sum;
}

//for(int i = ; i < ; i++){}

ll lmax(ll s,ll t){
  if(s>t){
    return s;
  }
  else{
    return t;
  }
}

ll lmin(ll s,ll t){
  if(s<t){
    return s;
  }
  else{
    return t;
  }
}


int main(){
  int n;
  cin>>n;
  int h[n];
  for(int i = 0; i < n; i++){
    cin>>h[i];
  }
  int mx = 0;
  int tmp = 0;
  for(int i = 0; i < n-1; i++){
    if(h[i]>=h[i+1]){
      tmp++;
    }
    else{
      mx = max(tmp,mx);
      tmp = 0;
    }
  }
  mx = max(tmp,mx);
  cout<<mx<<endl;
  return 0;
}


Measured memory_bytes: 640
#include <stdio.h>

int main(void)

{
int a, b, d, r;
double f;

scanf("%d %d", &a, &b);

r = a % b;
d = a / b;
f = 1.0 * a / b;

printf("%d %d %f\n", d, r, f);

return 0;

}



Measured memory_bytes: 2112
#include <cstdio>
#include <iostream>
#include <algorithm>
#define REP(i, n) for(int i = 0; i < (int)(n); ++i)
using namespace std;
typedef long long ll;

struct K {
  ll x, v;
};

K vs[100000+10];

ll cs[500000+10];
int OFFSET = 250000;

int main(void) {
  int N;
  ll C;
  scanf("%d%lld", &N, &C);
  REP(i, N) {
    scanf("%lld%lld", &vs[i].x, &vs[i].v);
  }

  ll res = 0;
  cs[OFFSET] = 0;
  REP(i, N) {
    cs[OFFSET+i+1] = cs[OFFSET+i] - (vs[i].x - (i > 0 ? vs[i-1].x : 0)) + vs[i].v;
    res = max(res, cs[OFFSET+i+1]);
  }
  REP(i, N) {
    cs[OFFSET-i-1] = cs[OFFSET-i] - ((i > 0 ? vs[N-i].x : C) - vs[N-i-1].x) + vs[N-i-1].v;
    res = max(res, cs[OFFSET-i-1]);
  }
  // 時計→反時計
  {
    ll maxi = 0;
    for(int i = N-1; i >= 0; --i) {
      ll cur = cs[OFFSET+i+1] - vs[i].x + maxi;
      res = max(res, cur);
      maxi = max(maxi, cs[OFFSET-N+i]);
    }
  }
  // 反時計→時計
  {
    ll maxi = 0;
    REP(i, N) {
      ll cur = cs[OFFSET-N+i] - (C-vs[i].x) + maxi;
      res = max(res, cur);
      maxi = max(maxi, cs[OFFSET+i+1]);
    }
  }
  cout << res << endl;
  return 0;
}


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

int main() {
  char c;
  cin >> c;
  if (c == 'a' || c == 'i' || c == 'u' || c == 'e' || c == 'o')
    cout << "vowel" << endl;
  else 
    cout << "consonant" << endl;
}


Measured memory_bytes: 256
n = gets.chomp
print n + ":"
n = n.to_i
k = Math::sqrt(n)
k = k.to_i
for i in 2..k
  while n%i == 0
    print " #{i}"
    n = n/i
  end
end
if n != 1
  puts " #{n}"
else
  puts ""
end

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

using namespace std;

int N, K;

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

  cin >> N >> K;

  vector<int64_t> acc(N + 1);
  unordered_map<int64_t, vector<size_t>> val_to_idx;
  val_to_idx[0].push_back(0);
  for (int i = 1; i <= N; ++i) {
    int64_t A;
    cin >> A;
    acc[i] = (A + K - 1 + acc[i - 1]) % K;
    val_to_idx[acc[i]].push_back(i + 1);
  }

  int64_t found = 0;
  for (auto& entry : val_to_idx) {
    auto& idxs = entry.second;
    auto left = idxs.begin();
    auto val = *left + K;
    if (entry.first != 0) val -= 1;
    auto right =
        lower_bound(idxs.rbegin(), idxs.rend(), val, greater<size_t>{})
            .base();
    for (int i = 1; i <= right - left - 1; ++i) {
      found += i;
    }
    while (right != idxs.end() && left < right) {
      left = lower_bound(left, right, *right - K + 1);
      found += right - left;
      ++right;
    }
  }

  cout << found << endl;
}


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

int main()
{
  int n, l;
  cin >> n >> l;
  int sum = 0;
  int eat_apple = l;
  for (int i = 0; i < n; i++)
  {
    int taste = l + i;
    sum += taste;

    int abs_eat_apple = eat_apple, abs_taste = taste;
    if (abs_eat_apple < 0)
      abs_eat_apple *= -1;
    if (abs_taste < 0)
      abs_taste *= -1;

    if (abs_eat_apple > abs_taste)
      eat_apple = taste;
  }
  sum -= eat_apple;
  cout << sum << endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
    char a[200];
    int len,ans=0;
    scanf("%s",a);
    len=strlen(a);
    for(int i=0;a[i]!='\0';i++)
    {
        if(a[i]!=a[len-i-1])
            ans++;
    }
    printf("%d",ans/2);
    return 0;
}


Measured memory_bytes: 256
#include <stdio.h>

int main( void )
{
  	int a, b;
  
  	scanf( "%d %d\n", &a, &b );
  
  	if( ( ( a * b ) % 2 ) == 0 ) {
     	printf( "Even\n" );
    }
  	else {
  		printf( "Odd\n" );
    }
    
 	return 0; 
}


Measured memory_bytes: 128
#include <stdio.h>

int main(void) {
	int N,M,C,temp,ans;
	int B[21];
	int A[21][21];
	temp = ans = 0;
	
	scanf("%d %d %d",&N,&M,&C);
	
	
	for(int i = 0; i < M;i++){
	    scanf("%d",&B[i]);
	}
	for(int i = 0; i < N;i++){
	    for(int j = 0;j < M;j++){
	        scanf("%d",&A[i][j]);
	    }
	}
	 for(int i = 0;i < N;i++){
	     for(int j = 0;j < M;j++){
	         temp += (A[i][j] * B[j]);
	         
	     }
	     temp = temp + C;
	     if(temp > 0){
	         ans++;
	     }
	     temp = 0;
	 }
	
	
	printf("%d",ans);
	return 0;
}



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

#define repi(i, a, n) for (int i = a; i < (int)(n); ++i)
#define rep(i, n) repi(i, 0, n)
#define all(v) begin(v), end(v)

using ll = long long;

int main() {
  // freopen("1.txt", "rb", stdin);
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);

  int N;
  cin >> N;

  vector<int> D1(N), D2(N);
  rep(i, N) {
    cin >> D1[i] >> D2[i];
  }

  repi(i, 2, N) {
    if (D1[i - 2] == D2[i - 2] && D1[i - 1] == D2[i - 1] && D1[i] == D2[i]) {
      cout << "Yes" << '\n';
      return 0;
    }
  }

  cout << "No" << '\n';

  return 0;
}


Measured memory_bytes: 3596
#include <bits/stdc++.h>
#include <algorithm>
#define _GLIBCXX_DEBUG
#define rep(i,n) for(int i=0;i<(n);++i)
#define all(x) (x).begin(), (x).end()
#define PB(x) push_back(x)
#define MP(x,y) make_pair(x,y)
using namespace std;
using P =pair<int,int>;
typedef long long ll;
 
int main() {

  int n;
  cin >> n;
  int ans=0;
  rep(i,n+1) {
    ans+=i;
  }
  cout<<ans<<endl;

  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i,s,n) for(int i = s;i<n;i++)
#define repe(i,s,n) for(int i = s;i<=n;i++)
#define pb push_back
#define fi first
#define se second
typedef long long ll;
typedef pair<int,int>pint;
typedef vector<int>vint;
typedef vector<pint>vpint;
static const ll maxLL = (ll)1 << 62;
const int MOD=1000000007,INF=1001001001;
int dy[]={-1,0,1,0};
int dx[]={0,1,0,-1};

//#define int ll

int n,T=0,nowT=0,t1,t2;

signed main(){
    cin>>n;
    vector<double> t(n),v(n);
    rep(i,0,n)cin>>t[i];
    rep(i,0,n)cin>>v[i];
    
    //全体のT秒を求める
    rep(i,0,n)T+=t[i];
    
    vector<double> maxV(2*T+1,(double)INF);
    
    //maxのスピードをv[i]で初期化
    rep(i,0,n){
        rep(ti,0,t[i]){
            t1=nowT+ti*2;
            t2=nowT+ti*2+1;
            maxV[t1]=min(maxV[t1],v[i]);
            maxV[t2]=min(maxV[t2],v[i]);
        }
        nowT+=t[i]*2;
        maxV[nowT]=min(maxV[nowT],v[i]);
    }
    
    maxV[0]=maxV[T*2]=0.0;
    
    rep(ti,0,2*T+1){
        maxV[ti+1]=min(maxV[ti+1],maxV[ti]+0.5);
    }
    for(int ti=2*T;ti>=0;ti--){
        maxV[ti]=min(maxV[ti],maxV[ti+1]+0.5);
    }
    double ans=0.0;
    rep(i,0,2*T+1){
        ans+=(maxV[i]+maxV[i+1])*0.5/2.0;
    }
    cout<<fixed << setprecision(15)<<ans<<endl;
    return 0;
}

Measured memory_bytes: 512
N,M=map(int,input().split())
h=list(map(int,input().split()))
li=[1]*N
for i in range(M):
    a,b=list(map(int,input().split()))
    if h[a-1]>h[b-1]:
        li[b-1]*=0
    elif h[a-1]==h[b-1]:
        li[a-1]*=0
        li[b-1]*=0
    else:
        li[a-1]*=0

ans=li.count(1)
print(ans)


Measured memory_bytes: 20112
N = int(input())
A={}
for i in range(N):
    tmp=input()
    if tmp in A:
        A[tmp]+=1
    else:
        A[tmp]=1
        
B=max(A.values())
keys = [k for k, v in A.items() if v == B]
nk=sorted(keys)

print(*nk,sep='\n')


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

#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define ITR(x,c) for(__typeof(c.begin()) x=c.begin();x!=c.end();x++)
#define RITR(x,c) for(__typeof(c.rbegin()) x=c.rbegin();x!=c.rend();x++)
#define setp(n) fixed << setprecision(n)

#define lf double
#define ll long long
#define vll vector<ll>
#define vi vector<int>
#define pll pair<ll,ll>
#define pi pair<int,int>

#define all(a) (a.begin()),(a.end())
#define rall(a) (a.rbegin()),(a.rend())
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define ins insert

#define INF 1e15

using namespace std;

ll dp[301][302][302];

int main(void)
{
	cin.tie(0);
	ios::sync_with_stdio(false);
    int n, k; cin>>n>>k;
	unordered_map<int, ll> Map, RMap;
	set<ll> Set; Set.ins(0);
	vll h(n);
	rep(i, n){
		cin>>h[i];
		Set.ins(h[i]);
	}
	int idx=0;
	for(auto e:Set){
		Map[idx] = e;
		RMap[e] = idx;
		idx++;
	}

	rep(i, n+1)rep(j, k+2)rep(l, Map.size()){
		dp[i][j][l] = INF;
	}
	dp[0][0][0] = 0ll;
	for(int i=0; i<n; i++){
		for(int j=0; j<=k; j++){
			for(int l=0; l<Map.size(); l++){
				dp[i+1][j][RMap[h[i]]] = min(dp[i+1][j][RMap[h[i]]], dp[i][j][l]+max(0ll, h[i]-Map[l]));
				dp[i+1][j+1][l] = min(dp[i+1][j+1][l], dp[i][j][l]);
			}
		}
	}

	ll ans = INF;
	for(int l=0; l<Map.size(); l++){
		ans = min(ans, dp[n][k][l]);
	}
	cout << ans << "\n";
	return 0;
}

Measured memory_bytes: 214784
#include <iostream>
#include <string.h>
#include <algorithm>
#include <vector>
#include <queue>
#include <stack>
#include <map>
using namespace std;
int main(void){
   int N;
   cin>>N;
   stack<int> istack; int i=0;
   if(N==0){cout<<'0';}
   while(N){
       if(N%2==0){N=N/(-2); istack.push(0);}
       else {N=(N-1)/(-2); istack.push(1);}
       i++;
   }
   while(!istack.empty()){
       cout<<istack.top();
       istack.pop();
   }
   return 0;
}


Measured memory_bytes: 256
d = int(input())
c = list(map(int,input().split()))
s = [list(map(int,input().split())) for i in range(365)]

now = [0]*26
for i in range(365):
    no = -1
    score = -10**10
    for j in range(26):
        count = s[i][j]
        for k in range(26):
            if j == k:
                continue
            count -= (i+1-now[k])*c[k]
        if count > score:
            no = j
            score = count
    print(no+1)
    now[no] = i
    
    


Measured memory_bytes: 9392
#include <bits/stdc++.h>
#define f first
#define s second
#define MOD 1000000007
#define PMOD 998244353
#define pb(x) push_back(x)
using namespace std;

typedef long long int ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> plii;
typedef pair<int, pii> piii;
const int INF = 1e9+10;
const ll LINF = 1LL*INF*INF;
const int MAXN = 2e5+10;
const int MAXM = 5e3+10;

priority_queue<int> pq;
vector<vector<int> > graph;
queue<int> que;

int A[MAXN];
pii B[MAXN];
char S[MAXN];

int main()
{
    int n,m,k,a,b,x,y,q;
    int sum = 0;
    int cnt = 0;
    int mx = 0;
    int mn = INF;
    int cur = 0, idx = -1;
    int tc;

    ios_base::sync_with_stdio(false);
    cin.tie(NULL);

    cin>>n>>m;

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

    sort(A+1,A+n+1);

    for(int i=1;i<=m;i++)
        cin>>B[i].s>>B[i].f;

    sort(B+1,B+m+1);

    idx = m;

    for(int i=1;i<=n;i++){
        if(B[idx].s==0)idx--;
        if(idx==0)break;
        if(B[idx].f<=A[i])break;
        A[i] = B[idx].f;
        B[idx].s--;
    }

    ll res = 0;

    for(int i=1;i<=n;i++)
        res+=(ll)A[i];

    cout<<res<<"\n";

    return 0;
}


Measured memory_bytes: 1408
import java.util.*;

public class Main {
    public static void main(String[] args){
        Scanner sc=new Scanner(System.in);
        int n=sc.nextInt();
        int d=sc.nextInt();
        int[][]nums=new int[n][d];
        for(int i=0;i<n;i++)
        for(int j=0;j<d;j++)nums[i][j]=sc.nextInt();
        int count=0;
        for(int i=0;i<n-1;i++){
            for(int j=i+1;j<n;j++){
                int ans=0;
                for(int k=0;k<d;k++){
                    ans+=(nums[i][k]-nums[j][k])*(nums[i][k]-nums[j][k]);
                }
                int pow=(int)Math.sqrt(ans);
                if(pow*pow==ans)count++;
            }
        }
        System.out.println(count);
    }
}


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

typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;

int main(){
	ios::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	cout<<setprecision(32);

	ll x; cin>>x; x = abs(x);
	ll n = 1;
	while(n*(n + 1)/2 < x)n++;
	cout<<n<<endl;

	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using i64 = long long;
#define endl "\n"

int main()
{
  i64 N, K;
  cin >> N >> K;
  vector<i64> p(N);
  for (i64 i = 0; i < N; i++)
    cin >> p[i];
  sort(p.begin(), p.end());
  i64 ans = 0;
  for (i64 i = 0; i < K; i++)
    ans += p[i];
  cout << ans << endl;
  return 0;
}


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

using namespace std;
#define ll long long
#define ull unsigned long long
#define i128 __int128
#define mp make_pair
#define ld long double
typedef pair<int, int> pii;
typedef priority_queue<int, vector<int>, greater<int> > small_heap;
typedef priority_queue<int> big_heap;
const int N = 1e6 + 100;
int T;
char str[N];

int main() {
    scanf("%s", str + 1);
    int len = strlen(str + 1);
    for (int i = 1; i <= len; i++) {
        if (str[i] == '?')str[i] = 'D';
    }
    printf("%s", str + 1);
    return 0;
}

Measured memory_bytes: 3968
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep2(i, s, n) for (int i = (s); i < (int)(n); i++)
#define all(v) v.begin(), v.end()
typedef long long ll;
typedef pair<int, int> P;
typedef pair<long long, long long> Pll;
typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef vector<long long> vll;
typedef vector<vector<long long>> vvll;
const long long INF = 1LL << 60;
const int INT_INF = 1 << 30;
const double PI = acos(-1.0);

int main() {
    int n, m; cin >> n >> m;
    map<ll, ll> M;
    rep(i, n){
        int a; cin >> a;
        M[-a]++;
    }
    rep(i, m){
        int b, c;
        cin >> b >> c;
        M[-c] += b;
    }
    ll ans = 0;
    ll nums = 0;
    auto itr = M.begin();
    while(nums < n){
        ans += -(*itr).first * min(n - nums, (*itr).second);
        nums += (*itr).second;
        itr++;
        }
    cout << ans << endl;
}

Measured memory_bytes: 16160
#include <bits/stdc++.h>
#define IOS ios::sync_with_stdio(false); cin.tie(0); cout.tie(0)
#define ll long long int
#define pii pair<int,int>
#define pll pair<long long int,long long int>
#define pci pair<char,int
#define mii map<int,int>
#define mll map<long long int,long long int>
#define mci map<char,int>
#define umii unordered_map<int,int>
#define umll unordered_map<long long int,long long int>
#define umci unordered_map<char,int>
#define F first
#define S second
#define pb push_back
#define endl '\n'
    
using namespace std;
bool sortin(const pair<ll,ll> &a,  
               const pair<ll,ll> &b) 
{ 
       return (a.first < b.first); 
} 
bool isPrime(ll k){
    if(k<=1){return false;}
    if(k==2){return true;}
    if(k%2==0){return false;}
    ll i = 3;
   while (i*i <= k) {if (k % i == 0) {return false;}i += 2;}
return true;
}
 
ll de(ll N) 
{ 
  
    // To store the binary number 
    ll B_Number = 0; 
    ll cnt = 0; 
    while (N != 0) { 
        int rem = N % 2; 
        ll c = pow(10, cnt); 
        B_Number += rem * c; 
        N /= 2; 
  
        // Count used to store exponent value 
        cnt++; 
    } 
  
    return B_Number; 
} 
  
  
int main(){
    IOS;
ll n,k;cin>>n>>k;
ll a[n];for(ll i=0;i<n;i++) cin>>a[i];
sort(a,a+n);ll sum=0;
for(ll i=0;i<k;i++){sum=sum+a[i];}
cout<<sum;
    return 0;}

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


int main(){
    ll N ,K, ans = 1e11;
    cin >> N >> K;
    vector<ll> tree(N,0);
    for(int i = 0; i < N; i++) cin >> tree[i];
    sort(tree.begin(), tree.end());
    for(int i = 0; i < N; i++){
        if(i + (K - 1) == N) break;
        ans = min(ans, abs(tree[i + (K - 1)] - tree[i]));
    }
    cout << ans << endl;
}


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

#define F first
#define S second
#define PB push_back

using namespace std;

typedef long long ll;

int h, w;
char grid[1005][1005];
ll memo[1005][1005];

const ll mod = 1e9 + 7;

ll dp(int i, int j){
	if(i > h)	return 0;
	if(j > w)	return 0;
	if(i == h and j == w)	return 1;
	if(memo[i][j] != -1)	return memo[i][j];
	if(grid[i][j] == '#')	return 0;
	return memo[i][j] = (dp(i,j+1) + dp(i+1, j))%mod;
}

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

	memset(memo, -1, sizeof(memo));

	cin >> h >> w;

	for(int i = 1; i <= h; i++){
		for(int j = 1; j <= w; j++){
			cin >> grid[i][j];
		}
	}

	cout << dp(1, 1);

	return 0;
}

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

#define all(s) s.begin(), s.end()
#define vi vector<int>
#define pb push_back
#define ii pair<int, int>
#define x first
#define y second

const int N = 205;

int color[N];
int d[N][N];
vi g[N];

bool dfs(int u, int col) {
    if (color[u] != 0 && color[u] != col) return false;
    if (color[u]) return 1;
    color[u] = col;
    bool flag = 1;
    for (int v : g[u]) {
        flag &= dfs(v, 3 - col);
    }
    return flag;
}

int main() {
    ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
    int n;
    cin >> n;
    for (int i = 1; i <= n; i++) {
        string s;
        cin >> s;
        for (int j = 0; j < n; j++) {
            if (s[j] == '0') {
                d[i][j + 1] = 1e9;
            } else {
                d[i][j + 1] = 1;
                g[i].pb(j + 1);
            }
        }
    }
    if (!dfs(1, 1)) return cout << -1, 0;
    for (int i = 1; i <= n; i++) d[i][i] = 0;
    for (int k = 1; k <= n; k++) {
        for (int i = 1; i <= n; i++) {
            for (int j = 1; j <= n; j++) {
                d[i][j] = min(d[i][j], d[i][k] + d[k][j]);
            }
        }
    }
    int mx = 0;
    for (int i = 1; i <= n; i++) {
        for (int j = 1; j <= n; j++) {
            if (d[i][j] == 1e9) continue;
            mx = max(mx, d[i][j]);
        }
    }
    cout << mx + 1;
    return 0;
}

Measured memory_bytes: 640
#include<bits/stdc++.h>
#define ll long long
#define speed_up    ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define rep(i,a,b) for(ll i=a;i<b;i++)
#define pb push_back
#define MAX 1000000007
using namespace std;
int main()
{
 	speed_up
    ll p,q,r;cin>>p>>q>>r;
    cout<<min(q+r,min(p+q,p+r));
	
	
	
	
 return 0;
}

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

using namespace std;
typedef long long ll;
typedef unsigned long long ull;
#define FOR(i, n) for (int i = 0; i < int(n); i++)
#define FOR1(i, m, n) for (int i = int(m); i < int(n); i++)
#define MAX(a, b) ((a) >= (b) ? (a) : (b))
#define MIN(a, b) ((a) <= (b) ? (a) : (b))

struct custom_compare {
  bool operator()(const pair<ll, int>& lhs, const pair<ll, int>& rhs) {
    return lhs.first < rhs.first;
  }
};

int main(int argc, char* argv[]) {
  int N;
  vector<ll> part_sum;
  ll ans = LLONG_MAX;

  cin >> N;

  part_sum.resize(N + 1);

  part_sum[0] = 0;
  FOR(i, N) {
    int tmp;

    cin >> tmp;

    part_sum[i + 1] = part_sum[i] + tmp;
  }

  FOR(i, N - 1) { ans = MIN(ans, abs(part_sum[N] - 2 * part_sum[i + 1])); }

  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 1792
import sys
sys.setrecursionlimit(10 ** 7)
input = sys.stdin.readline

n = int(input())
b = list( map(int, input().split()))
ans = []

while b:
    for i in reversed(range(len(b))):
        if b[i] == i+1:

            ans.append(b.pop(i))
            break

    else:
        print(-1)
        exit()

print(*reversed(ans),sep='\n')


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

using ll=long long;
#define int ll

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

int read(){
	int i;
	scanf("%lld",&i);
	return i;
}

signed main(){
	int N=read();
	int s[N];
	bool dec[N]={false};
	int ans=0;
	int mini=10000;
	REP(i,N){
		s[i]=read();
		if(s[i]%10==0) dec[i]=true;
		else{
			ans+=s[i];
			mini = min(mini,s[i]);
		}
	}
	
	if(ans==0){
		cout << 0;
		return 0;
	}
	
	if(ans%10==0) ans-=mini;
	
	
	REP(i,N){
		if(dec[i]==true) ans+=s[i];
	}
	
	cout << ans;
	
}

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

using namespace std;

int main() {
    int N, K;
    cin >> N >> K;
    set<int> D;
    int d;
    for (int i = 0; i < K; i++) {
        cin >> d;
        D.insert(d);
    }
    int num = N;
    string numS;
    bool correct = false;
    while (correct == false) {
        correct = true;
        stringstream ss;
        ss << num;
        ss >> numS;
        for (int i = 0; i < numS.length(); i++) {
            if (D.count(numS[i]-'0') == 1) {
                correct = false;
            }
        }
        if (correct == false) {
            num += 1;
        }
    }
    cout << num;

    return 0;
}


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


// ============union_find_tree===============
ll MAX_N = 100;
vector<ll> par(MAX_N);//MAX_N == num of node
vector<ll> tree_rank(MAX_N);

void init(ll n)
{
  for (ll i = 0; i < n; ++i)
  {
    par.at(i) = i;
    tree_rank.at(i) = 0;
  }
}

ll find(ll x)
{
  if (par.at(x) == x)
  {
    return x;
  }
  else
  {
    return par.at(x) = find(par.at(x));
  }
}

void unite(ll x, ll y)
{
  x = find(x);
  y = find(y);
  if (x == y)
  {
    return;
  }
  if (tree_rank.at(x) < tree_rank.at(y))
  {
    par.at(x) = y;
  }
  else
  {
    par.at(y) = x;
    if (tree_rank.at(x) == tree_rank.at(y))
    {
      tree_rank.at(x)++;
    }
  }
}

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

// ==============kruskal==================

struct edge{ll u, v; double cost;}; // 辺u, v をつなぐコストが cost
bool comp(const edge& e1, const edge& e2)
{
  return e1.cost < e2.cost;
}
const ll MAX_E = 100 * (99) / 2;
edge es[MAX_E];
ll V, E; // V 頂点、E 辺　の数

double kruskal()
{
  sort(es, es + E, comp);
  init(V);
  double ans = 0;
  for (ll i = 0; i < E; ++i)
  {
    edge e = es[i];
    if (!same(e.u, e.v))
    {
      unite(e.u, e.v);
      ans += e.cost;
    }
  }
  return ans;
}


// =======================================

double calc(tuple<double, double, double, double> a, tuple<double, double, double, double> b)
{
  double dist = sqrt(pow(get<0>(a) - get<0>(b), 2) + pow(get<1>(a) - get<1>(b), 2) + pow(get<2>(a) - get<2>(b), 2)) - get<3>(a) - get<3>(b);
  return max(dist, 0.0);
}

int main()
{
  while (true)
  {

    ll N;
    cin >> N;
    if (N == 0)
    {
      break;
    }
    V = N;
    E = N * (N - 1) / 2;
    vector<tuple<double, double, double, double>> station(N);
    double x, y, z, r;
    for (ll i = 0; i < N; ++i)
    {
      cin >> x >> y >> z >> r;
      station.at(i) = make_tuple(x, y, z, r);
    }
    ll cnt = 0;
    for (ll i = 0; i < N - 1; ++i)
    {
      for (ll j = i + 1; j < N; ++j)
      {
        es[cnt] = {i, j, calc(station.at(i), station.at(j))};
        cnt += 1;
      }
    }
    cout << fixed << setprecision(3) << kruskal() << endl;
  }
}



Measured memory_bytes: 3368
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0; i<(n); i++)
#define reps(i,s,n) for(int i=(s); i<(n); i++)
#define all(v) v.begin(),v.end()
#define res(n) resize(n)
#define rev(v) reverse(v.begin(),v.end())
#define so(v) sort(v.begin(),v.end())
#define outve(v) for(auto i : v) cout << i << " ";cout << endl
#define in(n,v) for(int i=0; i<(n); i++){cin >> v[i];}
#define out(n) cout << (n) << endl
#define fi first
#define se second
#define ve vector
#define pa pair
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
typedef vector<string> vs;
typedef vector<vector<int>> vvi;
typedef vector<pair<int,int>> vpi;
typedef vector<pair<ll,ll>> vpl;
typedef vector<vector<pair<int,int>>> vvp;




int main()
{
    int N;cin>>N;
    vi a(N);in(N,a);
    int inf = 1000000009;
    vi dp(N,inf);
    rev(a);
    rep(i,N){
        auto k = upper_bound(all(dp),a[i]) - dp.begin();
        if(k < N) dp[k] = a[i];
    }
    cout << lower_bound(all(dp),inf)-dp.begin()<< endl;

    
   
    
    
    
    return 0;
}



Measured memory_bytes: 1024
#include<bits/stdc++.h>
#define _GLIBCXX_DEBUG
#define rng(i,a,b) for(int i=int(a);i<int(b);i++)
#define rep(i,b) rng(i,0,b)
#define gnr(i,a,b) for(int i=int(b)-1;i>=int(a);i--)
#define per(i,b) gnr(i,0,b)
#define bg begin()
#define ed end()
#define rbg rbegin()
#define red rend()
#define all(x) x.bg,x.ed
#define rall(x) x.rbg,x.red
#define pb push_back
#define pf push_front
#define eb emplace_back
using namespace std;
typedef long long ll;
template<class t,class u> bool chmax(t&a,u b){if(a<b){a=b; return true;} return false;}
template<class t,class u> bool chmin(t&a,u b){if(a>b){a=b; return true;} return false;}
template<class t,class u> t MAX(t a,u b){if(a>=b) return a; return b;}
template<class t,class u> t MIN(t a,u b){if(a<=b) return a; return b;}
template<class t> int SIZE(t s){return (int)s.size();}
template<class t> using vc=vector<t>;
template<class t> using vvc=vc<vc<t>>;
using vvi=vc<vc<int>>;
using pi=pair<int,int>;
using vi=vc<int>;
void yes(){ cout << "Yes" << endl; }
void no(){ cout << "No" << endl; }
const long long INF = 1LL << 60;

int main(){
    cout << fixed << setprecision(20);
    int n; cin >> n;
    map<int,int> m;
    vi a(n);
    int ans = n;
    rep(i,n){
        int x; cin >> x;
        m[x]++;
        a[i] = x;
    }
    rep(i,n){
        int x = a[i];
        if(m[x] >= 2){
            ans--;
        } else {
            if(a[i] != 1 && m[1] != 0){
                ans--;
                continue;
            }
            for(int j = 2; j*j <= a[i]; j++){
                if(x % j == 0){
                    if(m[j] != 0 || m[x/j] != 0){
                        ans--;
                        break;
                    }
                }
            }
        }
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 32672
#include <bits/stdc++.h>
#define IOS                                                                    \
  ios::sync_with_stdio(0);                                                     \
  cin.tie(0);                                                                  \
  cout.tie(0)
#define pb push_back
#define ff first
#define ss second
#define all(x) (x).begin(), (x).end()
#define sz(x) (int)(x).size()
using namespace std;
using ll = long long;
using vi = vector<int>;
using pii = pair<ll, ll>;
const int INF = 0x3f3f3f3f;
const ll LINF = 0x3f3f3f3f3f3f3f3fLL;
ll bpow(ll b, ll p, ll m = 1000000007LL) {
  ll rt = 1;
  for (; p; p >>= 1, b = b * b % m)
    if (p & 1)
      rt = rt * b % m;
  return rt;
}
int main() {
  IOS;
  int n;
  int ans = 0;
  cin >> n;
  for (int i = 1; i <= n; i++) {
    int x;
    cin >> x;
    if ((i & 1) && (x & 1))
      ans++;
  }
  cout << ans << endl;
}

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

int main(){
  srand((unsigned)time(NULL));

  int n, strong = -1;
  char t[12][12];
  cin >> n;

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

    int cnt = 0;

    for(int j = 0; j < n; j++){
      if(t[i][j] == 'o'){
        cnt++;
      }
    }

    if(cnt == n - 1){
      strong = i + 1;
    }
  }

  for(int i = 0; i < 1000; i++){
    if(strong == -1){
      cout << rand() % n + 1 << endl;
    }
    else{
      cout << strong << endl;
    }

    fflush(stdout);
  }
}

Measured memory_bytes: 0
import java.io.*;
import java.util.StringTokenizer;

public class Main{

    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        InputReader in = new InputReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        Twinkle little = new Twinkle();
        little.star(1, in, out);
        out.close();


    }
static class Twinkle {
        public void star(int testNumber, InputReader in, PrintWriter out) {
            int x = in.nextInt();
            if(x==5|| x==3 || x==7)
                System.out.println("YES");
            else
                System.out.println("NO");
}
}
  


    static class InputReader {
        public BufferedReader reader;
        public StringTokenizer tokenizer;

        public InputReader(InputStream stream) {
            reader = new BufferedReader(new InputStreamReader(stream), 32768);
            tokenizer = null;
        }

        public String next() {
            while (tokenizer == null || !tokenizer.hasMoreTokens()) {
                try {
                    tokenizer = new StringTokenizer(reader.readLine());
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }
            return tokenizer.nextToken();
        }
      public   String nextLine()
        {
            String str = "";
            try
            {
                str = reader.readLine();
            }
            catch (IOException e)
            {
                e.printStackTrace();
            }
            return str;
        }

        public int nextInt() {
            return Integer.parseInt(next());
        }

        public long nextLong() {
            return Long.parseLong(next());
        }

        public double nextDouble() {
            return Double.parseDouble(next());
        }

        public boolean hasNext() {
            while (tokenizer == null || !tokenizer.hasMoreTokens()) {
                try {
                    String line = reader.readLine();
                    if (line == null) {
                        return false;
                    }
                    tokenizer = new StringTokenizer(line);
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }
            return true;
        }
    }
}


Measured memory_bytes: 23380
import numpy as np
n,m=map(int,input().split())
A=np.array([list(input()) for _ in range(n)])
B=np.array([list(input()) for _ in range(m)])
for i in range(n-m+1):
    for j in range(n-m+1):
        if np.all(A[i:i+m,j:j+m]==B):
            print('Yes')
            exit()
print('No')

Measured memory_bytes: 12428
#include<iostream>
#include<math.h>
#include<algorithm>
#include<utility>
#include<queue>
#include<string.h>
#include<string>
#include<set>
#include<map>
#include<vector>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
const ll INF=2e18;

map<char,int> mp;
typedef string::const_iterator SC;
string s;

ll NumParse(SC& it){
    ll ret;
    if(isdigit(*it)){
        ret=*it-'0';
    }else{
        ret=mp[*it];
    }
    it++;
    return ret;
}
ll Form(SC &it){
    if(*it=='-'){
        it++;
        return 2-Form(it);
    }else if(*it=='('){
        it++;
        ll l=Form(it);
        char op=*it;
        it++;
        ll r=Form(it);
        ll ret;
        if(op=='+'){
            if(l==1 && r==1){
                ret=1;
            }else{
                ret=min(2LL,l+r);
            }
        }else{
            ret=(l*r+1)/2;
        }
        it++;
        return ret;
    }else{
        return NumParse(it);
    }
}
int main(){
    while(cin>>s,s[0]!='.'){
        ll ans=0;
        ll a,b,c;
        /*for(ll i=0;i<27;i++){
        cin>>a>>b>>c;
        mp['P']=a;
        mp['Q']=b;
        mp['R']=c;
        SC it=s.begin();
        cout<<Form(it)<<endl;
        }*/

        for(ll i=0;i<3;i++)
            for(ll j=0;j<3;j++)
                for(ll k=0;k<3;k++){
                    mp['P']=i;
                    mp['Q']=j;
                    mp['R']=k;
                    SC it=s.begin();
                    if(Form(it)==2){
                        ans++;
                    }
                }
        cout<<ans<<endl;
    }
    
    return 0;
}


Measured memory_bytes: 3116
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<(n);i++)
int N;
vector<int> t[20];
int dp[1<<16];
int dp2[1<<16];

int dfs(int S) {
    if(S == (1<<N)-1) return 0;
    if(dp[S] != -1) return dp[S];
    int ret = 1000000000;

    //i番目をj番目の装備で攻略
    rep(i,N) {
        if((S>>i)&1) continue;
        rep(j,N) {
            if(i==j) continue;
            if(!((S>>j)&1)) continue;

            ret = min(ret, dfs(S|(1<<i)) + t[i][j+1]);
        }
        ret = min(ret, dfs(S|(1<<i)) + t[i][0]);
    }
    return dp[S]=ret;

}

void solve() {
    rep(i,1<<16) dp[i]=-1;
    rep(i,N) {
        t[i].resize(N+1);
        rep(j,N+1) {
            int a;
            cin>>a;
            t[i][j]=a;
        }
    }
    /*
    rep(i,1<<16) dp2[i]=100000000;
    dp2[0]=0;
    rep(i,1<<N) {
        rep(j,N) {
            //状態i でjを攻略
            if(!((i>>j)&1)) {
                rep(k,N) {
                    if((i>>k)&1) dp2[i|(1<<j)] = min(dp2[i|(1<<j)], dp2[i]+t[j][k+1]);
                }
                dp2[i|(1<<j)] = min(dp2[i|(1<<j)], dp2[i] + t[j][0]);
            }
        }
    } 
    cout<<dp2[(1<<N)-1]<<endl;

    */
    int ans = 1000000000;
    ans = dfs(0);
    cout<<ans<<endl;

    rep(i,N) t[i].clear();

}
int main() {

    while(cin>>N) {
        if(!N) return 0;
        solve();
    }

    return 0;
}

Measured memory_bytes: 1456
#include <iostream>
using namespace std;
typedef unsigned long long u64;

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

  int r, g, b;
  cin >> r >> g >> b;
  int a = r * 100 + g * 10 + b;
  if (a % 4 == 0) {
    cout << "YES" << endl;
  } else {
    cout << "NO" << endl;
  }
  return 0;
}



Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<cmath>

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

using namespace std;
int main() {
	int a, b, c;
	cin >> a >> b >> c;
	if (a <= c && a + b >= c)
		cout << "YES" << endl;
	else
		cout << "NO" << endl;

	return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <stdlib.h>

typedef struct {
	long long key;
	int color;
} apple;

typedef struct {
	apple *data;
	int size;
} max_heap;

void push(apple x, max_heap* h)
{
	int i = h->size;
	apple tmp;
	h->data[(h->size)++] = x;
	while (1) {
		if (i == 0) break;
		else if (h->data[i].key > h->data[(i-1)/2].key) {
			tmp = h->data[i];
			h->data[i] = h->data[(i-1)/2];
			h->data[(i-1)/2] = tmp;
			i = (i - 1) / 2;
		} else break;
	}
}

apple pop(max_heap* h)
{
	int i = 0, j;
	apple tmp, output = h->data[0];
	h->data[0] = h->data[--(h->size)];
	while (1) {
		if (i * 2 + 1 >= h->size) break;
		else if (i * 2 + 2 >= h->size) j = i * 2 + 1;
		else if (h->data[i*2+1].key > h->data[i*2+2].key) j = i * 2 + 1;
		else j = i * 2 + 2;
		if (h->data[j].key > h->data[i].key) {
			tmp = h->data[i];
			h->data[i] = h->data[j];
			h->data[j] = tmp;
			i = j;
		} else break;
	}
	return output;
}

int main()
{
	int i, X, Y, A, B, C;
	long long p[100001], q[100001], r[100001];
	scanf("%d %d %d %d %d", &X, &Y, &A, &B, &C);
	for (i = 1; i <= A; i++) scanf("%lld", &(p[i]));
	for (i = 1; i <= B; i++) scanf("%lld", &(q[i]));
	for (i = 1; i <= C; i++) scanf("%lld", &(r[i]));
	
	apple a[300001];
	for (i = 1; i <= A; i++) {
		a[i].key = p[i];
		a[i].color = 1;
	}
	for (i = 1; i <= B; i++) {
		a[A+i].key = q[i];
		a[A+i].color = 2;
	}
	for (i = 1; i <= C; i++) {
		a[A+B+i].key = r[i];
		a[A+B+i].color = 0;
	}
	
	max_heap h;
	h.data = (apple*)malloc(sizeof(apple) * (A + B + C + 1));
	h.size = 0;
	for (i = 1; i <= A + B + C; i++) push(a[i], &h);
	
	int Z = X + Y;
	long long sum = 0;
	for (i = 0; i < Z; i++) {
		a[0] = pop(&h);
		if (a[0].color == 1 && X > 0) {
			X--;
			sum += a[0].key;
		} else if (a[0].color == 2 && Y > 0) {
			Y--;
			sum += a[0].key;
		} else if (a[0].color == 0) sum += a[0].key;
		else i--;
	}
	
	printf("%lld\n", sum);
	fflush(stdout);
	return 0;
}

Measured memory_bytes: 11904
N=int(input())
A=[int(i) for i in input().split()]
ans=0
#i%2が正
s=0
for i in range(N):
    s+=A[i]
    if i%2==0:
        if s<=0:
            ans+=1-s
            s=1
    else:
        if s>=0:
            ans+=s+1
            s=-1
    #print(s,ans)
nums=0
s=0
for i in range(N):
    s+=A[i]
    if i%2!=0:
        if s<=0:
            nums+=1-s
            s=1
    else:
        if s>=0:
            nums+=s+1
            s=-1
    #print(s,nums)
print(min(nums,ans))

Measured memory_bytes: 63216
#include <bits/stdc++.h>
using namespace std;
const int inf = (1 << 30) - 1;

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

  // string の substring を抽出
  int a = stoi(S.substr(0, 2));
  int b = stoi(S.substr(2, 2));

  if (a >= 1 && a <= 12) {
    if (b >= 1 && b <= 12)
      cout << "AMBIGUOUS" << endl;
    else
      cout << "MMYY" << endl;
  } else {
    if (b >= 1 && b <= 12)
      cout << "YYMM" << endl;
    else
      cout << "NA" << endl;
  }
  return 0;
}

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

using namespace std;

#ifdef DEBUG_MODE
	#define DBG(n) n;
#else
	#define DBG(n) ;
#endif
#define REP(i,n) for(ll (i) = (0);(i) < (n);++i)
#define rep(i,s,g) for(ll (i) = (s);(i) < (g);++i)
#define rrep(i,s,g) for(ll (i) = (s);i >= (g);--(i))
#define PB push_back
#define MP make_pair
#define FI first
#define SE second
#define SHOW1d(v,n) {for(int W = 0;W < (n);W++)cerr << v[W] << ' ';cerr << endl << endl;}
#define SHOW2d(v,i,j) {for(int aaa = 0;aaa < i;aaa++){for(int bbb = 0;bbb < j;bbb++)cerr << v[aaa][bbb] << ' ';cerr << endl;}cerr << endl;}
#define ALL(v) v.begin(),v.end()
#define Decimal fixed<<setprecision(20)
#define INF 1000000000
#define MOD 1000000007


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

int main(){
	string str;
	cin >> str;
	int k;cin >> k;
	int cou = 0;
	set<string> v;
	REP(i,26){
		REP(j,str.size()){
			if(str[j] == (char)('a' + i)){
				for(int k = j;k < str.size();k++){
					v.insert(str.substr(j,k-j+1));
					if(v.size() > 5){
						auto it = v.begin();
						REP(i,5)it++;
						if(*it <= str.substr(j,k-j+1))break;
					}
				}
			}
		}
		DBG(cout << v.size() << endl;);
		if(v.size() >= k){
			auto it = v.begin();
			REP(i,k-1)it++;
			cout << *it << endl;
			return 0;
		}
	}
			
	return 0;
}



Measured memory_bytes: 256
#include <algorithm>
#include <array>
#include <vector>
#include <iostream>
#include <fstream>
#include <string>
#include <cmath>
#include <functional>
#include <queue>

using namespace std;

void Show(vector<vector<int>> S) {
	for (int i = 0; i < S.size(); i++) {
		for (int j = 0; j < S[i].size(); j++) {
			cout << "[" << i << "," << j << "]" << S[i][j] << endl;
		}
	}
}

int main() {
	int N, i;
//	string S;
	cin >> N >> i;
//	cin >> S;
	cout << (N - i+1) << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
#define all(x) x.begin(), x.end()

int main() {
  ll h, ans = 1;
  cin >> h;
  if (h == 1)
    cout << 1 << endl;
  else {
    while (h > 1) {
      ans++;
      h /= 2;
    }
    ll x = pow(2, ans);
    cout << x - 1 << endl;
  }
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
#define LL long long
#define pb push_back
#define mp make_pair
#define fi first
#define sc second
using namespace std;

LL n,a[300100],ans;

int main() {
	cin>>n;
	for(int i=0;i<n*3;i++){
		scanf("%lld",&a[i]);
	}
	sort(a, a+n*3);
	reverse(a, a+n*3);
	for(int i=0;i<n*2;i+=2){
		ans += a[i+1];
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 2560
import sys, math
def input():
    return sys.stdin.readline()[:-1]
from itertools import permutations, combinations
from collections import defaultdict, Counter
from math import factorial

sys.setrecursionlimit(10**7)
S, T = input().split()
A, B = map(int, input().split())
s = input()

if s == S:
    print(A-1, B)
else:
    print(A, B-1)




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

int main()
{
    int n,q,b,m,e;
    cin>>n;
    vector<int>a(n);
    REP(i,n)cin>>a[i];
    cin>>q;
    REP(i,q)
    {
        cin>>b>>m>>e;
        auto bb=a.begin(),mm=a.begin(),ee=a.begin();
        bb+=b;mm+=m;ee+=e;
        swap_ranges(bb,mm,ee);
    }
    REP(i,n)
    {
        if(i!=0)cout<<" ";
        cout<<a[i];
    }cout<<endl;
}


Measured memory_bytes: 3104
#include <cstdio>
#include <cstdint>
#include <vector>
#include <algorithm>
#include <string>
#include <utility>
#include <numeric>
#include <queue>
#include <deque>
#include <tuple>
#include <map>
#include <set>

int main() {
  intmax_t W, H, x, y;
  scanf("%jd %jd %jd %jd", &W, &H, &x, &y);

  double S = W*H/2.0;
  bool f = ((x*2 == W) && (y*2 == H));
  printf("%.12f %d\n", S, f);
}


Measured memory_bytes: 128
#include<iostream>
#include<algorithm>
#include<string>

using namespace std;

int dp[1001][1001];

int main(){

    string s1,s2;
    cin >> s1 >> s2;
    for(int i=0;i<=s1.length();i++) dp[i][0] = i;
    for(int j=0;j<=s2.length();j++) dp[0][j] = j;

    for(int i=1;i<=s1.length();i++){
	for(int j=1;j<=s2.length();j++){
	    int k=0;
	    if(s1[i-1] == s2[j-1]) k = 0;
	    else k=1;
	    dp[i][j] = min( dp[i-1][j]+1, min(dp[i][j-1]+1,dp[i-1][j-1]+k));
	}
    }
    cout << dp[s1.length()][s2.length()] << endl;
    return 0;
}

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

int main() {
	int a, b, c, x, y;
	cin >> a >> b >> c >> x >> y;
	int p, q, r;
	p = max(x, y) * 2 * c;
	q = a * x + b * y;
	if (x > y)r = y * 2 * c + (x - y)*a;
	else r = x * 2 * c + (y - x)*b;
	cout << min(p, min(q,r)) << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
const int64_t INF=9999999999999999;

int main() {
   int A,B,C;
   cin>>A>>B>>C;
   int ma=max({A,B,C});
   if((3*ma-(A+B+C))%2==0){cout<<(3*ma-(A+B+C))/2<<endl;}
   else{cout<<(3*(ma+1)-(A+B+C))/2<<endl;}
return 0;}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define rep(i,n) for (int i = 0; i < n; ++i)
#define REP(i,k,n) for (int i = k; i <= n; ++i)
#define REPR(i,k,n) for (int i = k; i >= n; --i)
#define pb push_back
#define F first
#define mp make_pair
#define debug1(a) cout<<" a : "<<a<<"\n"
#define debug2(a,b) cout<<" a : "<<a<<" b : "<<b<<"\n"
#define debug3(a,b,c) cout<<" a : "<<a<<" b : "<<b<<" c : "<<c<<"\n"
#define M 1000000007

signed main()
{
	//ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
	int n,k;
	cin>>k>>n;
	int a[k+1];
	rep(i,k) cin>>a[i+1];
	int dp[n+1];
	rep(j,n+1)
	{
		rep(i,k+1)
		{
			if (j==0 || i==0) dp[j]=0;
			else if (j>=a[i] && dp[j-a[i]]==0)
			{
				dp[j]=1;
			}
		}
	}
	//rep(i,n+1) cout<<dp[i]<<" ";
	cout<<(dp[n]?"First":"Second");
}

Measured memory_bytes: 1024
#line 1 "/mnt/c/Users/leafc/dev/compro/lib/union_find.hpp"
#include <iostream>
#include <vector>
#ifndef UNION_FIND
#define UNION_FIND
class UnionFind {
private:
  std::vector<int> parent;
  std::vector<int> _size;

  int root(int x) {
    if (parent[x] == -1)
      return x;
    return parent[x] = root(parent[x]);
  }

public:
  UnionFind(const int s) {
    parent = std::vector<int>(s, -1);
    _size = std::vector<int>(s, 1);
  }

  void merge(int x, int y) {
    int rx = root(x), ry = root(y);
    if (rx == ry)
      return;
    if (_size[rx] < _size[ry])
      std::swap(rx, ry);
    parent[ry] = rx;
    _size[rx] += _size[ry];
    _size[ry] = _size[rx];
  }

  int size(int x) { return _size[x]; }

  bool isSame(int x, int y) { return root(x) == root(y); }
};
#endif
#line 1 "/mnt/c/Users/leafc/dev/compro/lib/template.hpp"

template <class T> struct kruskal_edge {
  int from;
  int to;
  T cost;
};

#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < n; i++)
#define FOR(i, m, n) for (int i = m; i < n; i++)
#define ALL(v) (v).begin(), (v).end()
#define coutd(n) cout << fixed << setprecision(n)
#define ll long long int
#define vl vector<ll>
#define vi vector<int>
#define MM << " " <<

using namespace std;

template <class T> void say(bool val, T yes = "Yes", T no = "No") { cout << (val ? yes : no) << endl; }

template <class T> void chmin(T &a, T b) {
  if (a > b)
    a = b;
}

template <class T> void chmax(T &a, T b) {
  if (a < b)
    a = b;
}

#line 3 "tmp.cpp"

double distance(double x, double y, double z) {
    return sqrt(x*x + y*y + z*z);
}

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

  while (true) {
    int n;
    cin >> n;
    if (n == 0)
      break;
    vector<double> x(n), y(n), z(n), r(n);

    REP(i, n) { cin >> x[i] >> y[i] >> z[i] >> r[i]; }

    vector<kruskal_edge<double>> es;
    UnionFind uf(n);
    REP(i, n) {
      FOR(j, i + 1, n) {
        double d = distance(x[i] - x[j], y[i] - y[j], z[i] - z[j]);
        if (d > r[i] + r[j]) {
          es.push_back({i, j, d - r[i] - r[j]});
        } else {
          uf.merge(i, j);
        }
      }
    }

    double ans = 0;
    sort(ALL(es), [](kruskal_edge<double> a, kruskal_edge<double> b) { return a.cost < b.cost; });
    for (const auto e : es) {
      if (uf.isSame(e.from, e.to))
        continue;
      uf.merge(e.from, e.to);
      ans += e.cost;
    }

    coutd(3) << ans << endl;
  }

  return 0;
}



Measured memory_bytes: 3376