akhauriyash/Code-Regression huggingface dataset:
import java.io.*;
import java.util.*;

public class Main {

    public static void main(final String[] args) throws Exception {
        final Scanner sc = new Scanner(System.in);
        long X;
        X = sc.nextLong();

        final Solver solver = new Solver();
        solver.solve(X);
    }
}

class Solver {
    public void solve(long X) {
        while (!isPrime(X)) X++;
        System.out.println(X);
    }

    private boolean isPrime(long a) {
        if (a <= 1) return false;
        for (int i = 2; i * i < a; i++) {
            if (a % i == 0) return false;
        }
        return true;
    }
}



Measured memory_bytes: 21844
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <stdio.h>
#include <cstring>
#include <queue>
#include <stack>
#include <functional>
using namespace std;
#define Would
#define you


int main() {
	int a, b;
	cin >> a >> b;
	string prev = "kogakubu10gokan";
	for (int i = 0; i < a; ++i) {
		int n;
		string h;
		cin >> n >> h;
		if (b < n) { break; }
		prev = h;
	}
	cout << prev << endl;
}



Measured memory_bytes: 3228
#include <iostream>
#include <string>
#include <cmath>
#include <algorithm>

using namespace std;

int main(){
  int N;
  int A;
  int B;
  cin >> N >> A >> B;
  if(N*A<=B){
    cout << N*A << endl;
  }
  else{
    cout << B << endl;
  }
  return 0;
}

Measured memory_bytes: 256
//
//  main.cpp
//

#include <algorithm>
#include <array>
#include <assert.h>
#include <iostream>
#include <limits>
#include <math.h>
#include <memory>
#include <memory>
#include <queue>
#include <random>
#include <set>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <string>
#include <tuple>
#include <unordered_map>
#include <unordered_set>
#include <vector>

using namespace std;

using ll = long long;
using ull = unsigned long long;

int main() {
    int N, K;
    cin >> N >> K;
    vector<int> Ais;
    ll ais_sum = 0;
    for (int i = 0; i < N; i++) {
        int Ai;
        cin >> Ai;
        Ais.push_back(Ai);
        ais_sum += Ai;
    }
    set<ll> divisors;
    for (int d = 1; d * d <= ais_sum; d++) {
    	if (ais_sum % d == 0) {
    		divisors.insert(d);
    		divisors.insert(ais_sum / d);
    	}
    }
    for (auto d_it = divisors.rbegin(); d_it != divisors.rend(); d_it++) {
    	ll d = *d_it;
    	priority_queue<ll, vector<ll>, greater<ll>> up_cost;
    	priority_queue<ll, vector<ll>, greater<ll>> down_cost;
        ll diff = 0;
        ll cost = 0;
        for (int ai : Ais) {
            int ai_mod = ai % d;
            int ai_mod_up = d - ai_mod;
            if (ai_mod < ai_mod_up) {
                diff -= ai_mod;
                cost += ai_mod;
                up_cost.push(ai_mod_up - ai_mod);
            } else {
                diff += ai_mod_up;
                cost += ai_mod_up;
                down_cost.push(ai_mod - ai_mod_up);
            }
        }
        assert(diff % d == 0);
        if (diff < 0) {
        	swap(up_cost, down_cost);
        	diff = -diff;
        }
        while (!down_cost.empty() && diff > 0) {
        	ll c = down_cost.top();
        	down_cost.pop();
        	cost += c;
        	diff -= d;
        }
        cost += diff;
        if (cost <= K * 2) {
        	cout << d << endl;
        	return 0;
        }
    }
}


Measured memory_bytes: 384
def main():
	n, *cs = map(int, open(0))
	fwd = [0] * n
	mod = 10 ** 9 + 7
	d = {}
	for i, c in enumerate(cs[::-1], start=1):
		f = d.get(c, 0)
		if f:
			fwd[n - i] = f
		d[c] = n - i
	dp = [0] * (n + 1)
	dp[0] = 1
	for i, fwd in enumerate(fwd, start=1):
		dp[i] += dp[i - 1] % mod
		if fwd > i:
			dp[fwd + 1] += dp[i] % mod
	print(dp[-1] % mod)

if __name__=="__main__":
	main()

Measured memory_bytes: 38148
#include<iostream>
#include<cmath>
#include<cstdio>
using namespace std;

int main() {
	int n, A[1000];

	while (1) {
		cin >> n;
		if (n == 0)break;

		for (int i = 0; i < n; i++)cin >> A[i];
		int sum = 0;
		for (int i = 0; i < n; i++)sum+=A[i];
		double avg = 1.0*sum / n;
		double dist = 0.0;
		for (int i = 0; i < n; i++) {
			dist += (avg - A[i])*(avg - A[i]);
		}
		printf("%1f\n", sqrt(dist/n));
	}
}

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

int main()
{
    string s;
    cin >> s;
    
    int n = s.size();
    long long res = 0;
    
    for(int bit = 0; bit < 1 << (n - 1); ++bit)
    {
        long long tmp = 0;
        
        // move to next digit by multiplying 10
        for(int j = 0; j < n - 1; ++j)
        {
            tmp *= 10;
            tmp += s[j] - '0';
            
            // insert plus sign
            if(bit & (1 << j))
            {
                res += tmp;
                tmp = 0;
            }
        }
        // add tmp to result at the last digit
        tmp *= 10;
        tmp += s.back() - '0';
        res += tmp;
    }
    
    cout << res << "\n";
    return 0;
}

Measured memory_bytes: 3620
/* In the name of Allah */
#include<bits/stdc++.h>
using namespace std;

#define ll long long
#define ld long double
#define pb push_back
#define debug cout << "here!"
#define pii pair<int , int>
#define pdd pair<double , double>
#define F first
#define S second
const int maxn = 1e5 * 5 + 10 , inf = 1e9 , pi = 3.14159265;
int x[5];
void solve(){
    
}
void in(){
    for (int i = 0; i < 5; i ++){
        cin >> x[i]; if (x[i] == 0) cout << i + 1;
    }
}
int main(){
    ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    in();
    return 0;
}


Measured memory_bytes: 3640
#include <bits/stdc++.h>
using namespace std;
int main()
{
	ios::sync_with_stdio(false);
	cin.tie(NULL); cout.tie(NULL);
	int N, D; cin >> N >> D;
	D = D * 2 + 1;
	cout << (N + D - 1) / D << endl;
	return 0;
}


Measured memory_bytes: 256
#include <iostream>

using namespace std;

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

	int ans = 0;
	for (int i = 0; i < S.length(); ++i)
	{
		if (S[i] == T[i]);
		else ans++;
	}

	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 3828
o,f,i=998244353,[1],1
while i<o/399:f+=[f[-1]*i%o];i+=1
c=lambda n,k:f[n]*pow(f[n-k],o-2,o)*pow(f[k],o-2,o)
n,m=map(int,input().split())
w,u=3*m,n-1
a=c(w+u,u)-n*c(n+m-2,u)
m+=1
if w-m&1:m+=1
while m<=min(w,n):a-=c(n,m)*c((w-m)//2+u,u);m+=2
print(a%o)

Measured memory_bytes: 115300
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<long long,long long> pll;
#define ep emplace_back
#define pb push_back
#define mp make_pair
#define rep(i,n) for(int i=0;i<(n);++i)
#define all(v) v.begin(), v.end()
#define revall(v) v.rbegin(), v.rend()
constexpr int mod=1000000007;
constexpr int mod1=998244353;
vector<int> dx={0,1,0,-1},dy={-1,0,1,0};
bool inside(int y,int x,int h,int w){ if(y<h && y>=0 && x<w && x>=0) return true; return false; }
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(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	int a,b;cin >> a >> b;
	cout << max(a + b, max(a - b, a * b)) << endl;
}


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

    cin >> N ;


    int ans =0;
    repr(i,1,N+1){
        int waru =0;
        int b = i;
        while(b%2 == 0){
            waru ++;
            b /=2;
        }

        ans = max(ans,waru);
    }

    cout << pow(2,ans) << endl;
}

    


Measured memory_bytes: 384
// hhttps://atcoder.jp/contests/apg4b/tasks/APG4b_ca
// g++ -std=c++11 ex22.cpp && ./a.out
#include <vector>
#include <tuple>
#include <iostream>
#include <algorithm>
#include <map>
#include <set>
#include <bitset>
#include <queue>
#include <cstdio>
#include <cmath>
#include <climits>

using namespace std;

int main()
{
    int N;
    cin >> N;
    vector<int> X(N);
    for (int &xi : X)
    {
        cin >> xi;
    }

    int minsum = INT_MAX;
    for (int p = 1; p <= 100; p++)
    {
        int sum = 0;
        for (int xi : X)
        {
            sum += (xi - p) * (xi - p);
        }
        minsum = min(sum, minsum);
    }

    cout << minsum << endl;

    return 0;
}

Measured memory_bytes: 256
#define _CRT_SECURE_NO_WARNINGS
#include<bits/stdc++.h>
using namespace std;
#ifndef FAST_IO
 #define IOS ios_base::sync_with_stdio(false);cin.tie(nullptr);
#endif

#define FILE_IO freopen("input.txt","r",stdin)
#define int long long
#define f first
#define s second
#define endl '\n'
#define all(c) c.begin(),c.end()
#define debug(x) cerr << #x << " = " << x << endl;

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

mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
template<typename T>void print(T t){for(auto &it:t)cout<<it<<" ";}
inline int powerexp(int a,int b,int m=MOD){int res=1;while(b){if(b&1)res=res*a%m;a=a*a%m,b>>=1;}return res%m;}
inline int modinv(int a){return powerexp(a,MOD-2,MOD);}
inline int lcm(int a,int b){int g=__gcd(a,b);return a/g*b;}

//-------------------< start here >-------------------------//
void solve(){
   int n;
   cin>>n;
   vector<pair<int,int>> v(n);
   
   for(int i=0;i<n;i++){
	     cin>>v[i].s>>v[i].f;
	  }
   sort(all(v));
   bool ok=true;
   int sum=0;
   for(int i=0;i<n;i++){
	      sum+=v[i].s;
	      if(sum>v[i].f){
			  //crossed deadline
		  ok=false;
		  break;	
		} 
	  }
	if(ok)cout<<"Yes";
	else cout<<"No";
}
//-----------------------------
//comment from here for TOPCODER 
int32_t main(){
   IOS;
   solve();
   #ifdef LOCAL_DEFINE
   cerr<<"time elapsed "<<(double)clock()/CLOCKS_PER_SEC<<endl;
   #endif
}


Measured memory_bytes: 3456
N = int(input())
A = list(map(int,input().split()))

cumsum1 = 0
ans1 = 0

for n in range(N):
  cumsum1 += A[n]
  if n % 2 == 0:
    if cumsum1 >= 0:
      ans1 += abs(cumsum1)+1
      cumsum1 = -1
  else:
    if cumsum1 <= 0:
      ans1 += abs(cumsum1)+1
      cumsum1 = 1
      
      
cumsum2 = 0
ans2 = 0

for n in range(N):
  cumsum2 += A[n]
  if n % 2 == 0:
    if cumsum2 <= 0:
      ans2 += abs(cumsum2)+1
      cumsum2 = 1
  else:
    if cumsum2 >= 0:
      ans2 += abs(cumsum2)+1
      cumsum2 = -1
      
print(min(ans1,ans2))

Measured memory_bytes: 19992
N, M, K = map(int, input().split())
A = list(map(int, ('0 ' + input()).split()))
B = list(map(int, ('0 ' + input()).split()))

for i in range(1, N + 1): A[i] += A[i - 1]
for i in range(1, M + 1): B[i] += B[i - 1]
ans, j = 0, M

for i in range(N + 1):
    if A[i] > K: break
    while B[j] > K - A[i]: j -= 1
    ans = max(ans, i + j)
print(ans)


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

#define forn(i, n) for (int i = 0; i < (int)n; ++i)
#define for1(i, n) for (int i = 1; i <= (int)n; ++i)
#define fore(i, l, r) for (int i = (int)(l); i <= (int)(r); ++i)
#define ford(i, n) for (int i = (int)(n) - 1; i >= 0; --i)
#define pb push_back
#define fi first
#define se second
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()

using namespace std;

typedef long long i64;
typedef vector<int> vi;
typedef vector<i64> vi64;
typedef vector<vi> vvi;
typedef vector<vi64> vvi64;
typedef double ld;

int main() {
    
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.precision(10);
    cout << fixed;

    int N, K;
    cin >> N >> K;
    vi64 a(N);
    forn(i, N) cin >> a[i];

    vvi dp1(5001, vi(5001)), dp2(5001, vi(5001));

    dp1[0][0] = 1;
    dp2[0][0] = 1;

    for1(i, N) {
        forn(j, K + 1) {
            dp1[i][j] |= dp1[i - 1][j];
            int idx = j - a[i - 1];
            if (0 <= idx and idx <= 5000) {
                dp1[i][j] |= dp1[i - 1][idx];
            }
        }
    }

    for1(i, N) {
        forn(j, K + 1) {
            dp2[i][j] |= dp2[i - 1][j];
            int idx = j - a[N - i];
            if (0 <= idx and idx <= 5000) {
                dp2[i][j] |= dp2[i - 1][idx];
            }
        }
    }

    int ans = N;

    /*
    forn(i, N + 1) {
        cout << i << " ";
        forn(k, K + 1) {
            cout << dp1[i][k] << " ";
        }
        cout << endl;
    }

    forn(i, N + 1) {
        cout << i << " ";
        forn(k, K + 1) {
            cout << dp2[i][k] << " ";
        }
        cout << endl;
    }
    */

    forn(i, N) {

        if (K < a[i]) {
            ans--;
            continue;
        }
        
        bool isok = false;
        fore(j, K - a[i], K - 1) {
            forn(k, j + 1) {
                if ( dp1[i][k] and dp2[N - i - 1][j - k] ) {
                    ans--;
                    isok = true;
                    break;
                } 
            }
            if (isok) break;
        }
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 196096
/**
 * code generated by JHelper
 * More info: https://github.com/AlexeyDmitriev/JHelper
 * @author tatsumack
 */

#include <iostream>
#include <fstream>

#include <bits/stdc++.h>

#define int long long
#define REP(i, n) for (int i = 0, i##_len = (n); i < i##_len; ++i)
#define FOR(i, a, b) for (int i = (a), i##_len = (b); i <= i##_len; ++i)
#define REV(i, a, b) for (int i = (a); i >= (b); --i)
#define CLR(a, b) memset((a), (b), sizeof(a))
#define DUMP(x) cout << #x << " = " << (x) << endl;
#define INF 1001001001001001001ll
#define fcout cout << fixed << setprecision(12)

using namespace std;

typedef pair<int, int> P;

class AStudyScheduling {
public:
    void solve(std::istream& cin, std::ostream& cout) {
        int H1, M1, H2, M2, K;
        cin >> H1 >> M1 >> H2 >> M2 >> K;

        int difm = 0;
        if (H2 == H1) {
            difm = M2 - M1;
        } else {
            difm = 60 - M1 + M2 + (H2-H1-1) * 60;
        }
        if (difm <= K) {
            cout << 0 << endl;
            return;
        }

        int H3 = K / 60;
        int M3 = K % 60;
        H2 -= H3;
        M2 -= M3;
        if (M2 < 0) {
            M2 += 60;
            H2--;
        }
        if (H2 == H1) {
            difm = M2 - M1;
        } else {
            difm = 60 - M1 + M2 + (H2-H1-1) * 60;
        }
        cout << difm << endl;
    }
};


signed main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);
    std::istream& in(std::cin);
    std::ostream& out(std::cout);

    AStudyScheduling solver;
    solver.solve(in, out);
    return 0;
}


Measured memory_bytes: 3636
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>

#define ABS(x) ( (x)>0 ? x : -(x) )
#define MIN(x,y) ( (x) < (y) ? (x) : (y) )
#define MAX(x,y) ( (x) > (y) ? (x) : (y) )

#define INF 1000000000

void swap(int* x, int *y)
{
	int t;

	t = *x;
	*x = *y;
	*y = t;
}

int binary_search(int p[], int n, int key)
{
	int left, right, middle;

	left = 0;
	right = n-1;


	while (left <= right)
	{
		middle = (left + right) / 2;

		if (p[middle] == key)
			return middle;
		else if (p[middle] > key)
		{
			right = middle - 1;
		}
		else if (p[middle] < key)
		{
			left = middle + 1;
		}
	}

	return -1;

}

void bubble_sort(int p[], int n)
{
	int i, j;

	for (i = 0; i < n-1; i++)
	{
		for (j = 0; j < n - i - 1; j++)
		{
			if (p[j] > p[j + 1])
				swap(&p[i], &p[i + 1]);
		}
	}
}

int main()
{
	int a, b, c;
	int i, j;
	int count = 0;

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

	for (i = a; i <= b; i++)
	{
		if (c % i == 0)
			count++;
	}

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


Measured memory_bytes: 2144
def main():
    n,k = map(int,input().split())
    if n * k == 0:
        return False
    ans = [0 for _ in range(n)]
    for _ in range(k):
        a = list(map(int,input().split()))
        for i in range(n):
            ans[i] += a[i]
    print(max(ans))
    return True

while main():
    pass


Measured memory_bytes: 5656
#include <stdio.h>

void a(char c, char map[101][101], int i, int j, int H, int W) {
	if (c == map[i][j]) map[i][j] = '0';
	if (i+1 < H && map[i+1][j] == c) a(c,map,i+1,j,H,W);
	if (j+1 < W && map[i][j+1] == c) a(c,map,i,j+1,H,W);
	if (i-1 >= 0 && map[i-1][j] == c) a(c,map,i-1,j,H,W);
	if (j-1 >= 0 && map[i][j-1] == c) a(c,map,i,j-1,H,W);
}

int main() {
	int out, H, W, i, j;
	char map[101][101];
	while (1) {
		out = 0;
		scanf("%d%d", &H, &W);
		if (H == W && H == 0) break;
		for (i=0; i < H ;i++) {
			for (j=0; j < W ;j++) {
				scanf("%c", &map[i][j]);
				if (map[i][j] == '\n') {
					scanf("%c", &map[i][j]);
				}
			}
		}
		for (i=0; i < H ;i++) {
			for (j=0; j < W ;j++) {
				if (map[i][j] != '0') {
					a(map[i][j], map, i, j, H, W);
					out++;
				}
			}
		}
		printf("%d\n", out);
	}
	return 0;
}

Measured memory_bytes: 1532
import java.util.*;
import java.io.*;

public class Main {

	public static void main(String[] args) {
		FastScanner sc = new FastScanner();
		PrintWriter out = new PrintWriter(System.out);
		char[] str = sc.next().toCharArray();
		long k = sc.nextLong();
		char ans = '1';
		int cnt = 0;
		for(char c: str) {
			if (c != '1') {
				ans = c;
				break;
			} else
				cnt++;
		}
		if (cnt < k)
		out.println(ans);
		else
			out.println('1');
		
		out.close();
	}

static class FastScanner {
    private final InputStream in = System.in;
    private final byte[] buffer = new byte[1024];
    private int ptr = 0;
    private int buflen = 0;
    private boolean hasNextByte() {
        if (ptr < buflen) {
            return true;
        }else{
            ptr = 0;
            try {
                buflen = in.read(buffer);
            } catch (IOException e) {
                e.printStackTrace();
            }
            if (buflen <= 0) {
                return false;
            }
        }
        return true;
    }
    private int readByte() { if (hasNextByte()) return buffer[ptr++]; else return -1;}
    private static boolean isPrintableChar(int c) { return 33 <= c && c <= 126;}
    public boolean hasNext() { while(hasNextByte() && !isPrintableChar(buffer[ptr])) ptr++; return hasNextByte();}
    public String next() {
        if (!hasNext()) throw new NoSuchElementException();
        StringBuilder sb = new StringBuilder();
        int b = readByte();
        while(isPrintableChar(b)) {
            sb.appendCodePoint(b);
            b = readByte();
        }
        return sb.toString();
    }
    public long nextLong() {
        if (!hasNext()) throw new NoSuchElementException();
        long n = 0;
        boolean minus = false;
        int b = readByte();
        if (b == '-') {
            minus = true;
            b = readByte();
        }
        if (b < '0' || '9' < b) {
            throw new NumberFormatException();
        }
        while(true){
            if ('0' <= b && b <= '9') {
                n *= 10;
                n += b - '0';
            }else if(b == -1 || !isPrintableChar(b)){
                return minus ? -n : n;
            }else{
                throw new NumberFormatException();
            }
            b = readByte();
        }
    }
    public int nextInt() {
        long nl = nextLong();
        if (nl < Integer.MIN_VALUE || nl > Integer.MAX_VALUE) throw new NumberFormatException();
        return (int) nl;
    }
    public double nextDouble() { return Double.parseDouble(next());}
}
}


Measured memory_bytes: 22612
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll MOD = 1e9 + 7;
const int inf = 1e9;
const ll INF = 1e18;
const double pi = 3.14159265358979323846;
#define rep(i, n) for (int i = 0; i < n; i++)
using Graph = vector<vector<int>>;
using pint = pair<int, int>;
int dx[4] = { 1, 0, -1, 0 }, dy[4] = { 0, 1, 0, -1 };
int dxx[8] = { 1, 1, 1, 0, 0, -1, -1, -1 }, dyy[8] = { -1, 0, 1, -1, 1, -1, 0, 1 };

int main() {
    int n;
    ll k;
    cin >> n >> k;
    int a[n + 1];
    for (int i = 1; i <= n; i++) cin >> a[i];
    int s[n + 1] = {};
    s[0] = 1;
    ll l = inf, amari, l_s;
    map<int, int> mp;
    mp[1]++;
    rep (i, n) {
        s[i + 1] = a[s[i]];
        mp[s[i + 1]]++;
        if (mp[s[i + 1]] > 1) {
            l = i + 1;
            l_s = s[i + 1];
            break;
        }
    }
    rep (i, l) if (l_s == s[i]) amari = i;
    //for (int i = amari; i < l; i++) cout << s[i] << " ";
    //cout << l - amari << "\n";
    ll ans;
    if (k > amari) ans = (k - amari) % (ll) (l - amari);
    else {
        ans = k - amari;
    }
    //cout << amari;
    cout << s[amari + ans] << "\n";
}


Measured memory_bytes: 14440
#include <iostream>
#include <string>
#include <vector>
#include <queue>
#include <cmath>
#include <iomanip> //cout << fixed << setprecision() <<
using namespace std;
using ll = long long;
vector<vector<int>> v; //入力値
ll mint = 10000000000;
int c=0;

void monmo(int y,int n,int m,int x,vector<vector<int>> vv){
    vector<int> ten;
    int flag1=0;
    for(int i=0;i<m+1;i++){
        ten.push_back(0);
        ten[i]+=vv[y][i];
    }//flag1がたつと次の再帰に行く
    for(int i=0;i<m;i++){
        if(ten[i+1]<x)flag1=1;
    }
    
    if(y>=n){
        //処理なし
    }else{
        
    if(flag1==1){
        for(int i=y;i<n-1;i++){
            vector<vector<int>> v2;
            v2=vv;
            for(int j=0;j<m+1;j++){
                v2[i+1][j]+=vv[y][j];
            }
            monmo(i+1,n,m,x,v2);
        }
    }
    else{
        if(mint>ten[0])mint=ten[0];
        c++;
    }
    
    }
}

int main() {
    int n,m,x,num;
    cin>>n>>m>>x;
    for(int i=0;i<n;i++){
        v.emplace_back();
        for(int j=0;j<m+1;j++){
            cin>>num;
            v[i].push_back(num);
        }
    }
    for(int i=0;i<n;i++){
        monmo(i,n,m,x,v);
    }
    if(c==0)mint=-1;
    cout<<mint;
}

Measured memory_bytes: 3660
#include <iostream>
#include <cmath>
#include <climits>
#include <cstring>
#include <vector>
#include <string>
#include <queue>
#include <map>
#include <algorithm>
#include <numeric>

typedef long long ll;
const ll INF = (ll)1e18 + 1;
const ll MOD = 1e9 + 7;

// Grid
ll H, W;

void print(){ std::cout << std::endl; }
template <typename Head> void print(Head&& head) { std::cout << head << std::endl; }
template <typename Head, typename... Tail> void print(Head&& head, Tail&&... tail)
{
  std::cout << head << " ";
  print(std::forward<Tail>(tail)...); // or print(tail...);
}
template <typename Iterator> void printVec(Iterator begin, Iterator end)
{
  for (Iterator it = begin; it != end; it++) {
    std::cout << "[" << std::distance(begin, it) << "] " << *it << " ";
    if (std::distance(begin, it) % 20 == 19) { std::cout << std::endl; }
  }
  std::cout << std::endl;
}

typedef struct {
  ll y;
  ll x;
  ll ny;
  ll nx;
} S_Operation;

int main(int argc, char* argv[])
{
  std::cin.tie(nullptr);
  std::ios::sync_with_stdio(false);

  std::cin >> H >> W;
  std::vector< std::vector<ll> > grid(H, std::vector<ll>(W,0));
  for (ll y = 0; y < H; y++) {
    for (ll x = 0; x < W; x++) {
      std::cin >> grid[y][x];
    }
  }

  std::vector< S_Operation > vope;
  for (ll y = 0; y < H; y++) {
    if (y % 2 == 0) { // 右に操作
      for (ll x = 0; x < W; x++) {
	ll nx = x + 1 < W ? x + 1 : x;
	ll ny = x + 1 < W ? y : y + 1;
	if (ny < H && grid[y][x] % 2 == 1) {
	  S_Operation ope;
	  grid[ny][nx]++;
	  ope.x = x; ope.y = y; ope.nx = nx; ope.ny = ny;
	  vope.push_back(ope);
	}
      }
    } else { // 左に操作
      for (ll x = W-1; x >= 0; x--) {
	ll nx = x - 1 >= 0 ? x - 1 : x;
	ll ny = x - 1 >= 0 ? y : y + 1;
	if (ny < H && grid[y][x] % 2 == 1) {
	  S_Operation ope;
	  grid[ny][nx]++;
	  ope.x = x; ope.y = y; ope.nx = nx; ope.ny = ny;
	  vope.push_back(ope);
	}
      }
    }
  }

  print(vope.size());
  std::vector< S_Operation >::iterator it;
  for (it = vope.begin(); it != vope.end(); it++) {
    print(it->y + 1, it->x + 1, it->ny + 1, it->nx + 1);
  }
  return 0;
}


Measured memory_bytes: 8304
N, M = list(map(int, input().split()))
Location = list(map(int, input().split()))

Location.sort()
Distance = []
for i in range(M-1):
	Distance.append(Location[i+1] - Location[i])
Distance.sort()

if M - N > 0:
	print(sum(Distance[0:M-N]))
else:
	print(0)

Measured memory_bytes: 13960
//#pragma once
#include <stdio.h>
#include <string>
#include <iostream>
#include <queue>
#include <algorithm>
#include <sstream>
#include <vector>
#include <math.h>
#include <set>
#include <map>
#include <numeric>
#include <bitset>
#include <iomanip>
#include <cctype>


using namespace std;
#define modd 1000000007


typedef pair<long long, long long> pl;


typedef string::const_iterator State;
class ParseError {};




#define ll long long




class UnionFind {
public:
	vector <ll> par;
	vector <ll> siz;

	// Constructor
	UnionFind(ll sz_) : par(sz_), siz(sz_, 1LL){
		for (ll i = 0; i < sz_; ++i) par[i] = i;
	}
	void init(ll sz_) {
		par.resize(sz_);
		siz.assign(sz_, 1LL);  // resize だとなぜか初期化されなかった
		for (ll i = 0; i < sz_; ++i) par[i] = i; // 初期では親は自分自身
	}

	// Member Function
	// Find
	ll root(ll x) { // 根の検索
		while (par[x] != x) {
			x = par[x] = par[par[x]]; // x の親の親を x の親とする
		}
		return x;
	}

	// Union(Unite, Merge)
	bool merge(ll x, ll y) {
		x = root(x);
		y = root(y);
		if (x == y) return false;

		// merge technique（データ構造をマージするテク．小を大にくっつける）
		if (siz[x] < siz[y]) swap(x, y);
		siz[x] += siz[y];
		par[y] = x;
		return true;
	}



	bool issame(ll x, ll y) { // 連結判定
		return root(x) == root(y);
	}

	ll size(ll x) { // 素集合のサイズ
		return siz[root(x)];
	}


};


class SegmentTree {
private:
	int n;
	vector <ll> node;

public:
	// 元の配列　v をセグメントツリーで表現する。
	SegmentTree(vector<ll> v) {
		//最下段のノード数は元配列のサイズ以上になる最小の2冪->これをnとおく。
		//セグ木全体で必要なノード数は2n-1個である。
		int sz = v.size();
		n = 1; 
		while (n < sz)n *= 2;

	}

};




long long N, M, K, a, b, c, d, e, H, W, L;
ll A[300005] = {};
ll B[300005] = {};
ll C[300005] = {};
bool f, ff;
string S,T;
set <long long>sll;
pl bufpl;
vector <long long>vl[100005];
vector <long long>vll;
vector <pl>vpl;
vector <string> vs;
set<ll> llset;
multiset<ll> llmset;


/*
struct ST
{
	long long Kati;
	int bangou;

	bool operator<(const ST& another) const
	{
		return Kati < another.Kati;//比較
	};

};



/*vector <ST> vst;
ST st[200005];
ST bufst;
bitset<5000> bits;*/


long long modinv(long long aa, long long mm) {
	long long bb = mm, uu = 1, vv = 0;
	while (bb) {
		long long tt = aa / bb;
		aa -= tt * bb; swap(aa, bb);
		uu -= tt * vv; swap(uu, vv);
	}
	uu %= mm;
	if (uu < 0) uu += mm;
	return uu;
}



ll minn, maxx;
double ansa;
bool fl[30] = {};



string ss, sss;


int main() {


	cin >> N >> c >> K;

	for (int i = 0; i < N; i++) {
		cin >> A[i];
		vll.push_back(A[i]);
	}

	sort(vll.begin(), vll.end());

	e = 1;
	a = vll[0] + K;
	b = 1;

	for (int i = 1; i < N; i++) {
		if (b >= c) {
			e++;
			a = vll[i] + K;
			b = 1;
		}
		else if(a<vll[i]){
			e++;
			a = vll[i] + K;
			b = 1;
		}
		else {
			b++;
		}

	}

	cout << e << endl;
	return 0;

}


Measured memory_bytes: 7544
#include<stdio.h>
int main(){
  int n,x,i;
  scanf("%d%d",&n,&x);
  int a[n+1];
  a[0]=0;
  for(i=1;i<=n;i++)
    scanf("%d",&a[i]);
  long long sum=0;
  for(i=1;i<=n;i++)
    if(a[i]+a[i-1]>x){
      long long temp=a[i]+a[i-1]-x;
      sum+=temp;
      a[i]=x-a[i-1];
    }
  printf("%lld\n",sum);
  return 0;
}

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

namespace kozaiyApp
{
    public class Vacation
    {
        static void Main()
        {
            int N = int.Parse(Console.ReadLine());
            int[,] DP = new int[N,3];

            for (int i = 0; i < N; i++)
            {
                string[] input = Console.ReadLine().Split(' ');
                int[] v = Array.ConvertAll(input, int.Parse); // 価値　a b c

                if (i == 0)
                {
                    DP[i, 0] = v[0];
                    DP[i, 1] = v[1];
                    DP[i, 2] = v[2];
                }
                else
                {
                    DP[i, 0] = Math.Max(v[0] + DP[i - 1, 1], v[0] + DP[i - 1, 2]);
                    DP[i, 1] = Math.Max(v[1] + DP[i - 1, 0], v[1] + DP[i - 1, 2]);
                    DP[i, 2] = Math.Max(v[2] + DP[i - 1, 1], v[2] + DP[i - 1, 0]);
                }

            }

            int[] r = { DP[N - 1, 0], DP[N - 1, 1], DP[N - 1, 2] };
            Console.WriteLine(r.Max());
        }
    }
}


Measured memory_bytes: 18364
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<utility>
#include<cmath>
#include<climits>
#include<queue>
#include<stack>
#include<numeric>
#include<tuple>
using namespace std;


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

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

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


int main(){
	int n;
	cin >> n;
	
	vector<int> a(n);

	ll ans = 0;
	rep(i, n){
		int c;
		cin >> c;
		a[i] = c;
	}

	int count = 1;
	for(int i = 0; i < n; ++i){
		if(a[i] == count)	count++;
		else	ans++;
	}

	if(count == 1){
		cout << -1 << endl;
	} else {
		cout << ans << endl;
	}

}

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

Measured memory_bytes: 1024
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<bitset>
#include<set>
#include<map>
#include<stack>
#include<queue>
#include<deque>
#include<list>
#include<iomanip>
#include<cmath>
#include<cstring>
#include<functional>
#include<cstdio>
#include<cstdlib>
#include<unordered_map>
#include<unordered_set>
using namespace std;

#define repr(i, a, b) for (int i = (int)(a); i < (int)(b); i++)
#define rep(i, n) repr(i, 0, n)
#define INF 2e9
#define MOD 1000000007
//#define MOD 998244353
#define LINF (long long)4e18
#define jck 3.141592
#define PI acos(-1.0);

const double EPS = 1e-10;

using ll = long long;
using Pi = pair<int,int>;
using Pl = pair<ll,ll>;


int main(){
	int N,M; cin >> N >> M;
	vector<int> s(M),c(M);
	rep(i,M){
		cin >> s[i] >> c[i];
		s[i]--;
	}
	string ans = "-1";
	rep(i,1000){
		string t = to_string(i);
		if(t.size() != N) continue;
		bool ok = true;
		rep(j,M){
			if(t[s[j]] != c[j]+'0') ok = false;
		}
		if(ok){
			ans = t;
			break;
		} 
	}
	cout << ans << endl;
}



Measured memory_bytes: 256
typedef long long ll;
typedef long double ld;
#define mod 1000000007
#define INF 1000000000
#include <bits/stdc++.h>
using namespace std;

int main() {
	ios::sync_with_stdio(0);
	cin.tie(0);
	
	vector<ll> a(100005);
	int n;
	cin >> n;
	ll sum = 0;
	for (int i = 0; i < n; ++i) {
		int k;
		cin >> k;
		sum += (ll) k;
		++a[k];
	}
	int q;
	cin >> q;
	while (q--) {
		ll b, c;
		cin >> b >> c;
		sum -= (a[b] * b);
		sum += (a[b] * c);
		a[c] += a[b];
		a[b] = 0;
		cout << sum << '\n';
	}
	
	return 0;
}


Measured memory_bytes: 3912
#include <iostream>

using namespace std;

int n, m;
int c[20];
int dp[50000];

int main(void)
{
	cin >> n;
	cin >> m;
	for (int i = 0; i < m; i++) {
		cin >> c[i];
	}
	for (int i = 1; i <= n; i++) {
		int mini = i;
		for (int j = 0; j < m; j++) {
			if (i >= c[j]) {
				if (mini > dp[i - c[j]] + 1) {
					mini = dp[i - c[j]] + 1;
				}
			}
		}
		dp[i] = mini;
	}
	cout << dp[n] << endl;
	return 0;
}

Measured memory_bytes: 3296
n, m, c = map(int,input().split())
b = list(map(int,input().split()))
a = [0]*n
count = 0

for i in range(0,n):
    a[i] = list(map(int,input().split()))
    sum = c
    for j in range(0,m):
        sum = sum + a[i][j]*b[j]
    if sum > 0:
        count = count + 1

print(count)

Measured memory_bytes: 3064
#include<bits/stdc++.h>
using namespace std;
#define ll long long int 
#define pi pair<int ,int >
#define pl pair<ll ,ll >
#define pb push_back
#define vl vector <long long int >
#define vi vector <int >
#define vp vector <pi>
#define mod 1000000007
#define eps 1e-9
#define fi first
#define se second
#define all(x) x.begin(), x.end()
#define _ <<" "<<
#define forn(x,	n) for(int x = 0; x < n ;++ x) 
#define forn1n(x,n) for(int x = 1; x <= n ;++ x)
#define forn1(x,n) for(int x = 1; x < n ;++ x)
#define IOS ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#pragma GCC optimize ("Ofast")
void scan(){}
template<typename F, typename... R> void scan(F &f,R&... r){cin>>f;scan(r...);}
int di_; string dnms_, co_ = ",";
void debug_(){cout<<endl;}
template<typename F, typename... R> void debug_(F &f, R&... r){while(dnms_[di_] != ',')cout<<dnms_[di_++];di_++;cout<<": "<<f<<",";debug_(r...);}
#define debug(...) dnms_=#__VA_ARGS__+co_,di_=0,debug_(__VA_ARGS__)

template<class A, class B> ostream& operator<<(ostream& out, const pair<A, B> &a){
    return out<<"("<<a.first<<","<<a.second<<")";}
template<class A> ostream& operator<<(ostream& out, const vector<A> &a){
	out<<"";for(auto it=a.begin();it!=a.end();it++){if(it!=a.begin())out<<" ";out<<*it;}out<<"";
	return out;}
template<class A, class B> istream& operator>>(istream& in, pair<A,B> &a){in>>a.first>>a.second;return in;}
template<class A> istream& operator>>(istream& in, vector<A> &a){for(A &i:a)in>>i;return in;}
#define PI 3.14159265
#define epsilon 0.1
int main(){
	IOS

	double a,h,y;

	cin>>a>>h>>y;

	if(2*y<(a*a*h))
	{
		double num = 2*y;
		double den = a*h*h;

		double theta = atan2(num,den);
		theta = 90 - (theta*180)/PI;
		cout<<fixed<<setprecision(10)<<theta;
		return 0;
	}
	double num = 2*((a*a)*h - y);
	double den = a*a*a;
	//debug(num,den);
 	double theta = atan2(num,den);
 	//debug(theta);
 	theta = (theta*180)/PI;

 	cout<<fixed<<setprecision(10)<<theta;
	return 0;	
}

Measured memory_bytes: 384
#include <stdio.h>
#include <string>
#include <cstring>
#include <stdlib.h>
#include <math.h>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <list>
#include <iterator>
#include <assert.h>
#include <bitset>
#pragma warning(disable:4996) 
 
typedef long long ll;
#define MIN(a, b) ((a)>(b)? (b): (a))
#define MAX(a, b) ((a)<(b)? (b): (a))
#define LINF 9223300000000000000
#define INF 2140000000
const long long MOD = 1000000007;
using namespace std;


int main(int argc, char* argv[])
{
    char str[55]={0};
    scanf("%s", str);
    int n=strlen(str);

    int  cnt0[6]={1,0,0,1,1,1};
    int  cnt[55]={0};
    char str2[55]={0};
    int curr=0;
    int i;
    for(i=0; i<n; i++) {
        if(str[i]=='A') {
            cnt[curr]++;
        }
        else {
            str2[curr]=str[i];
            curr++;
        }
    }
    if(curr==5 && strcmp(str2, "KIHBR")==0) {
        for(i=0; i<6; i++) {
            if(cnt[i]>cnt0[i]) {
                printf("NO\n"); return 0;
            }
        }
        printf("YES\n"); return 0;
    }
    printf("NO\n");

    return 0;
}

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


public class Main {
	
	public static class Path implements Comparable<Path>{
		int prize;
		int size;
		
		public Path(int prize, int size) {
			super();
			this.prize = prize;
			this.size = size;
		}

		@Override
		public int compareTo(Path arg0) {
			if(this.size != arg0.size){
				return this.size - arg0.size;
			}else if(this.prize != arg0.prize){
				return this.prize - arg0.prize;
			}else{
				return 0;
			}
		}
	}
	
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		
		while(true){
			final int n = sc.nextInt();
			
			if(n == 0){
				break;
			}
			
			Path[] array = new Path[n];
			
			for(int i = 0; i < n; i++){
				array[i] = new Path(sc.nextInt(), sc.nextInt());
			}
			
			Arrays.sort(array);
			
			boolean over = false;
			int cur = 0;
			for(int i = 0; i < n; i++){
				cur += array[i].prize;
				
				//System.out.println(cur + " " + array[i].size);
				
				if(array[i].size < cur){
					over = true;
					break;
				}
			}
			
			if(over){
				System.out.println("No");
			}else{
				System.out.println("Yes");
			}
		}
	}

}

Measured memory_bytes: 12000
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define rep1(i, n) for (int i = 1; i < (n); ++i)
using namespace std;
using ll = long long;
using P = pair<int, int>;
const double PI=acos(-1);
const int INF = numeric_limits<int>::max();

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

    vector<int> p(n);
    rep(i,n) cin >> p[i];

    vector<int> q(n);
    rep(i,n) cin >> q[i];

    vector<int> a(n);
    rep(i,n) a[i]=i+1;
    map<vector<int>,int> mp;
    do{
        mp[a]=mp.size();
    } while(next_permutation(a.begin(),a.end()));
 
    int ans=abs(mp[p]-mp[q]);
    
    cout<<ans<<endl;

    return 0;
    
}

Measured memory_bytes: 5248
//高知能系Vtuberの高井茅乃です。
//Twitter: https://twitter.com/takaichino
//YouTube: https://www.youtube.com/channel/UCTOxnI3eOI_o1HRgzq-LEZw

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

#define INF 1999999999
#define REP(i,n) for(int i=0;i<n;i++)
#define REP1(i,n) for(int i=1;i<=n;i++)
#define MODA 1000000007 

int main() {
	int ans = 0;
	int tmp;
	bool f = false;
	int n;
	cin >> n;
	char c;
	REP(i, n){
		cin >> c;
		if(c == 'Y') f = true;
	}
	if (f) cout << "Four" << endl;
	else cout << "Three" << endl;
	
//	cout << ans << endl;
}

Measured memory_bytes: 256
#include <cstdio>
#include <cstring>

const int DIC_SIZE = 1000000;

struct tuple{
  int num;
  tuple* left;
  tuple* right;
};

tuple dic[DIC_SIZE];
int dic_count = 0;
tuple* root = NULL;

int encode(char* str){
  int num = 0;
  for(int i = 0;; i++){
    if(str[i] == 'A') {
      num = num * 5 + 1;
    } else if (str[i] == 'T') {
      num = num * 5 + 2;
    } else if (str[i] == 'C') {
      num = num * 5 + 3;
    } else if (str[i] == 'G') {
      num = num * 5 + 4;
    } else {
      break;
    }
  }
  return num;
}

void insert(char* str){
  tuple* p = &(dic[dic_count++]);
  p->num = encode(str);
  p->left = NULL;
  p->right = NULL;
  if(root == NULL){
    root = p;
    return;
  }
  tuple* q = root;
  for(;;){
    if(q->num > p->num){
      if(q->left == NULL){
	q->left = p;
	break;
      } else {
	q = q->left;
      }
    } else if(q->num < p->num){
      if(q->right == NULL){
	q->right = p;
	break;
      } else {
	q = q->right;
      }
    } else {
      break;
    }
  }
}
int find(char* str){
  int n = encode(str);
  tuple* p = root;
  if(p == NULL) { return 0; }
  for(;;){
    if(p->num == n){
      return 1;
    } else if(p->num > n){
      if(p->left == NULL) { break; }
      p = p->left;
    } else if(p->num < n){
      if(p->right == NULL) { break; }
      p = p->right;
    }
  }
  return 0;
}

int main(){
  int n;
  scanf("%d", &n);
  char command[256], str[16];
  for(int i = 0; i < n; i++){
    scanf("%s", command);
    scanf("%s", str);
    if(strcmp(command, "insert") == 0){
      insert(str);
    }else if (strcmp(command, "find") == 0){
      if(find(str)){
	puts("yes");
      } else {
	puts("no");
      }
    }
  }
  return 0;
}

Measured memory_bytes: 15324
#include <stdio.h>

int main(){
  int i,j,n,u,k,v,g[100][100];
  scanf("%d",&n);
  for(i = 0; i < n; i++){
    for(j = 0; j < n; j++) g[i][j] = 0;
  }
  for(i = 0; i < n; i++){
    scanf("%d%d",&u,&k);
    for(j = 0; j < k; j++){
      scanf("%d",&v);
      g[u - 1][v - 1]=1;
    }
  }
  for(i = 0; i < n; i++){
    for(j = 0; j < n; j++){
      if(j) printf(" ");
      printf("%d",g[i][j]);
    }
    printf("\n");
  }
  return 0;
}



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

using namespace std;
#define all(x) (x).begin(),(x).end()
#define rep(i, n) for (int i = 0; i < (n); i++)
#define chmin(x, y) (x) = min((x), (y))
#define chmax(x, y) (x) = max((x), (y))
#define endl "\n"
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

template <typename T> ostream &operator<<(ostream &os, const vector<T> &vec) {os << "["; for (const auto &v : vec) {os << v << ","; } os << "]"; return os;}
template <typename T, typename U> ostream &operator<<(ostream &os, const pair<T, U> &p) {os << "(" << p.first << ", " << p.second << ")"; return os;}

void solve() {
    int N, M;
    cin >> N >> M;
    vector<int> imos(N + 1);
    for (int i = 0; i < M; i++) {
        int l, r;
        cin >> l >> r;
        l--;
        imos[l]++;
        imos[r]--;
    }
    int sum = 0;
    for (int i = 0; i < N; i++) {
        sum += imos[i];
        imos[i] = sum;
    }
    int cnt = 0;
    for (int i = 0; i < N + 1; i++) {
        if (imos[i] == M) {
            cnt++;
        }
    }
    cout << cnt << endl;


}

int main() {
    #ifdef LOCAL_ENV
    cin.exceptions(ios::failbit);
    #endif
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout.setf(ios::fixed);
    cout.precision(16);
    
    solve();
}

Measured memory_bytes: 640
import sys
from heapq import *
def input(): return sys.stdin.readline().strip()


def main():
    """
    文字列のソートをする際には計算量に要注意！
    数字の大小比較と違って文字列の比較の場合は１文字１文字左から順番に見ないといけない。
    そのため一回の比較でO(比較文字列の長さ)分の計算量がかかる。
    特に長さMの文字列N個をソートするのにかかる時間は
            ❌O(NlogN)
            ⭕️O(MNlogN)

    そこで文字列のソート時には文字数をなるべく小さくするのがポイント。
    今回K<=5なので、「答えはK<=5文字以下になる」のがミソ。
    """

    s = input()
    L = len(s)
    K = int(input())
    string = set([])
    for i in range(L):
        for j in range(i + 1, min(i + K, L) + 1):
            string.add(s[i:j])

    string = list(string)
    heapify(string)
    for _ in range(K):
        ans = heappop(string)
    print(ans)


if __name__ == "__main__":
    main()


Measured memory_bytes: 74964
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<cmath>
#include<stack>
#include<queue>
#include<deque>
#include<map>
#include<set>
using namespace std;
typedef long long ll;
typedef vector<int> VI;
#define FOR(i,a,n) for(int (i)=(a);(i)<(n);(i)++)
#define eFOR(i,a,n) for(int (i)=(a);(i)<=(n);(i)++)
#define SORT(i) sort((i).begin(),(i).end())
#define rSORT(i,a) sort((i).begin(),(i).end(),(a))
constexpr auto INF = 1000000000;
constexpr auto LLINF = 1LL << 62;
constexpr auto mod = 1000000007;
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; }

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

    int n, m;
    cin >> n >> m;
    VI a(n);
    FOR(i, 0, n)cin >> a[i];
    map<int, int> map;
    int b, cnt = 0;
    VI c(m);
    FOR(i, 0, m) {
        cin >> b >> c[i];
        map[c[i]] += b;
        cnt += b;
    }

    SORT(a);
    rSORT(c, [](int a, int b) {return a > b; });
    ll ans = 0;
    int j = 0;
    FOR(i, 0, n) {
        while (j < c.size() && !map[c[j]])j++;
        if (j >= c.size())ans += a[i];
        else {
            if (a[i] < c[j])map[c[j]]--;
            ans += max(a[i], c[j]);
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 5760
#include<bits/stdc++.h>
long long i,a,N,s,A=INT_MAX,l,r,S[100002];int main(){scanf("%ld%ld",&N,&s);for(;i<N;i++){scanf("%ld",&a);S[i+1]+=S[i]+a;}for(;;){if(S[r]-S[l]>=s){A=std::min(A,r-l);l++;}else r++;if(r>N){if(A==INT_MAX)A=0;printf("%ld\n",A);return 0;}}}

Measured memory_bytes: 3968
#include <algorithm>
#include <chrono>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <numeric>
#include <queue>
#include <unordered_map>
#include <vector>
using namespace std;
using ll = int64_t;
#define rep(i, j, n) for (int i = j; i < (int)n; ++i)
#define rrep(i, j, n) for (int i = (int)n - 1; j <= i; --i)

constexpr ll MOD = 1000000007;
constexpr int INF = 0x3f3f3f3f;
constexpr ll INFL = 0x3f3f3f3f3f3f3f3fLL;

ll inv(ll x) {
  ll e = MOD - 2;
  ll res = 1;
  while (e) {
    if (e & 1) res = res * x % MOD;
    x = x * x % MOD;
    e >>= 1;
  }
  return res;
}

int main() {
  int n, k;
  cin >> n >> k;
  ll a;
  vector<ll> minus;
  vector<pair<ll, ll>> item;
  rep(i, 0, n) {
    cin >> a;
    item.emplace_back(abs(a), a);
    if (a < 0) minus.push_back(a);
  }

  ll ans = 1;
  if ((int)minus.size() == n) {
    if (k & 1)
      sort(minus.rbegin(), minus.rend());
    else
      sort(minus.begin(), minus.end());
    rep(i, 0, k) ans = (MOD + ans * minus[i] % MOD) % MOD;
  } else {
    sort(item.rbegin(), item.rend());
    int used_minus = 0;
    ll p = INFL, m = INFL;
    rep(i, 0, k) {
      ll x = item[i].second;
      if (x < 0) {
        used_minus++;
        m = item[i].second;
      } else
        p = item[i].second;

      ans = (MOD + ans * x % MOD) % MOD;
    }

    if (n != k && used_minus % 2 == 1) {
      ll mx = -1;
      rep(i, k, n) if (item[i].second >= 0) mx = max(mx, item[i].second);
      // m nozoku, mx tuika

      ll mn = INFL;
      rep(i, k, n) if (item[i].second < 0) mn = min(mn, item[i].second);
      // p nozoku, mn tuika
      // ans / m * mx < ans / p * mn
      // p * mx < m * mn
      if (p != INFL && mn != INFL && abs(p * mx) <= abs(m * mn))
        ans = (MOD + ans * inv(p) % MOD * (MOD + mn)) % MOD;
      else
        ans = (MOD + ans * inv(MOD + m) % MOD * mx) % MOD;
    }
  }
  cout << ans << '\n';
#ifdef LOCAL
  cerr << "Time elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << " s.\n";
#endif
  return 0;
}

Measured memory_bytes: 10072
import java.util.Scanner;

class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int n = sc.nextInt();
    double r = Math.ceil(n / 1.08);
    if (Math.floor(r * 1.08) == n) {
      System.out.println((int) r);
    } else {
      System.out.println(":(");
    }
    sc.close();
  }
}


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

int main(){
  int a, b, c, d, e, f;
  cin >> a >> b >> c >> d >> e >> f;
  double res = 0;
  int max_s = 0;
  int max_w = 0;
  for(int i = 0; i * a * 100 < f; ++i){
    for(int j = 0; j * b * 100 < f; ++j){
      double w = i * a * 100 + j * b * 100;      
      if(w > f) break;
      for(int l = 0; l * c < f; ++l){
        for(int m = 0; m * d < f; ++m){      
          double s = l * c + m * d;
          if(w + s > f) break;
          if((100 * s) / w <= e){          
            if(res <= (100 * s) / (s + w)){            
              res = (100 * s) / (s + w);
              max_s = s;            
              max_w = w;
            }
          }
        }
      }    
    }
  }
  cout << max_s + max_w << " " << max_s << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define maxn ((int)(1e5+1))
using namespace std;
int n;
long long a[maxn],res=0;
int main()
{
	cin>>n;
	for(int i=0;i<n;i++)
		cin>>a[i];
	for(int i=0;i<n;i++)
	{
		res+=a[i]/2;
		a[i]%=2;
		if(a[i]&&a[i+1])
		{
			++res;
			--a[i];
			--a[i+1];
		} 
	}
	cout<<res<<endl;
	return 0;
}

Measured memory_bytes: 1024
def solve(string):
    n, *x = map(int, string.split())
    mid = n // 2
    x = [(i, _x) for i, _x in enumerate(x)]
    x = sorted(x, key=lambda x: x[1])
    ans = [[] for _ in range(n)]
    for i, _x in enumerate(x):
        ans[_x[0]] = str(x[mid][1]) if i < mid else str(x[mid - 1][1])
    return "\n".join(ans)


if __name__ == '__main__':
    print(solve('\n'.join([input(), input()])))


Measured memory_bytes: 133716
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <vector>
#include <queue>
#include <ctime>
#include <map>
#include <iomanip>
using namespace std;
 
#define FOR(i,a,b) for (ll i = (a); i < (b); i++)
#define REP(i,n) FOR(i,0,n)
 
long gcd(long long a, long long b){
	if (a%b==0){
		return b;
	}
	else{
		return gcd(b,a%b);
	}
}
 
long lcm(long long a, long long b){
	return a / gcd(a,b) * b;
}
 
template<typename A, typename B> inline bool chmax(A &a, B b) { if (a < b) { a = b; return 1; } return 0; }
template<typename A, typename B> inline bool chmin(A &a, B b) { if (a > b) { a = b; return 1; } return 0; }
 
typedef long long ll;
 
const ll INF = 1ll<<60;
const ll MOD = 1000000007;
const double EPS = 1e-10;

string S, T;
int f, idx;

int main(){
	cin >> S >> T;
	
	int TL = T.length();
	int SL = S.length();
	
	REP(i,SL-(TL-1)){
		f = 1;
		REP(j,TL){
			if (S[(SL-1)-(i+j)] == T[(TL-1)-j] || S[(SL-1)-(i+j)] == '?') continue;
			
			f = 0;
			break;
		}
		
		if (f){
			idx = (SL-1)-i-(TL-1);
			break;
		}
	}
	
	if (f){
		REP(i,TL) S[idx+i] = T[i];
		REP(i,SL) if (S[i] == '?') S[i] = 'a';
		
		cout << S << endl;
		
		return 0;
	}
	
	cout << "UNRESTORABLE" << endl;
	
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll long long
#define pll pair<ll,ll>
#define pil pair<int,ll>
#define pli pair<ll,int>
#define pii pair<int,int>
#define mk make_pair
#define pb push_back
#define eps 1e-12
#define MAXN 200009
using namespace std;
bool reached[MAXN];
int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	int n;
	cin>>n;
	int a[n+1];
	for(int i=1;i<=n;i++)
	{
		cin>>a[i];
	}
	int curr=1,ans=0;
	while(1)
	{
		reached[curr]=true;
		curr=a[curr];
		ans++;
		if(reached[curr])
		{
			break;
		}
		if(reached[2])
		{
			break;
		}
	}
	if(reached[2])
	{
		cout<<ans-1<<"\n";
	}
	else
	{
		cout<<"-1\n";
	}
}

Measured memory_bytes: 768