akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <vector>
#include <cstdlib>
using namespace std;
void chmax(long long& a,long long b){
    if (a < b){
        a = b;
    }
}

// 入力
int N;
long long a[100010][3]; 

long long dp[100010][3];

int main(){
    int N;
    cin >> N;
    for (int i = 0;i < N;++i){
        for (int j = 0;j < 3;++j){
            cin >> a[i][j];
        }
    }
    for (int i = 0;i < N;++i){
        for (int j = 0;j < 3;++j){
            for (int k = 0;k < 3;++k){
                if (j == k) continue;
                chmax(dp[i+1][k],dp[i][j]+a[i][k]);
            }
        }
    }
    chmax(dp[N][0],dp[N][1]);
    chmax(dp[N][0],dp[N][2]);
    cout << dp[N][0] << endl;
}


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

int main(){
  long k,a,b, has=1;
  bool yen=false;
  scanf("%ld %ld %ld", &k,&a,&b);
  if(b-a<=2)  cout << 1+k;
  else{
    for(int i=0;i<k;i++){
      if(yen){
        yen = false;
        has += b;
      }
      else if(has>=a){
        if(i!=k-1){
          has -= a;
          yen = true;
        }else
          has += 1;
      }else{
         has += 1;
      }
    }
    cout << has;
  }
  return 0;
}


Measured memory_bytes: 256
#include<iostream>

int main()
{
	int a;
	while( std::cin >> a ){
		int i = 0;
		while( a > 0 ){
			if( a & 1 ) std::cout << ( 1 << i ) << ( ( a >> 1 ) & -( a >> 1 ) ? " " : "" );
			a >>= 1;
			i++;
		}
		
		std::cout << std::endl;
	}

 	return 0;
}

Measured memory_bytes: 1164
import java.util.*;

public class Main{
    static ArrayList<Long> arr;
    
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        
        int n = Integer.parseInt(sc.next());
        int k = Integer.parseInt(sc.next());
        
        int[] a = new int[n];
        for(int i=0; i<n; i++){
            a[i] = Integer.parseInt(sc.next());
        }
        
        arr = new ArrayList<>();
        for(int i=0; i<n; i++){
            long tmp = 0L;
            for(int j=i; j<n; j++){
                tmp += a[j];
                arr.add(tmp);
            }
        }
        
        long ans = 0L;
        for(int b = 63; b>=0; b--){
            int cnt = 0;
            for(int i=0; i<arr.size(); i++){
                long tmp = arr.get(i);
                if((tmp|(ans+(1L<<b))) == tmp){
                    cnt++;
                }
            }
            if(cnt >= k){
                ans |= 1L<<b;
            }
        }
        
        System.out.println(ans);
    }
}

Measured memory_bytes: 52252
#include<bits/stdc++.h>
    using namespace std;
    
    #define FAST ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);
    #include <ext/pb_ds/assoc_container.hpp> 
    #include <ext/pb_ds/tree_policy.hpp> 
    using namespace __gnu_pbds; 
    #define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>
    
    #define int long long 
    #define double long double
    
    #define all(a)      (a).begin(),(a).end()
    #define sz(x)       (int)x.size()
    
    #define ff first
    #define ss second
    #define mp make_pair
         
    #define pb push_back
    #define endl "\n" 
         
    #define f(i,l,r) for(int i=l;i<=r;i++)
    #define rf(i,r,l) for(int i=r;i>=l;i--)    

    #define bp __builtin_popcountll
    #define inf 3e18
    
    const int N=1e5+5; 
    const int M=1e9+7;
    #define pi 3.14159265359
    int modularExponentiation(int x,int n,int M)
{
    int result=1;
    while(n>0)
    {
        if(n % 2 ==1)
            result=(result * x)%M;
        x=(x*x)%M;
        n=n/2;
    }
    return result;
}
    void solve()
    {
    	int n,k;
    	cin>>n>>k;
    	int ans=0;
    	for(int i=k;i<=n+1;i++)
    	{
    		int xx=((i-1)*i)/2;
    		int yy=(i*(2*n+(1-i)))/2;
    		// cout<<xx<<" "<<yy<<endl;
    		ans+=(yy-xx+1);
    		ans%=M;
    	}
    	cout<<ans;
    	
    }
      signed main()  
    {
        FAST
        int t=1;
        // cin>>t;
        for(int tc=1;tc<=t;tc++)
        {
    		// cout<<"Case #"<<tc<<": ";
    		solve();
        }
    }



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

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

#define MOD 1000000007

int main(void) {
    ll N, K;
    vector<ll> gems;
    ll maxi = 0;
    cin >> N >> K;
    gems.resize(N);
    for(ll i = 0;i < N;i++) cin >> gems[i];
    for(ll a = 0;a <= min(N, K);a++) {
        for(ll b = 0;b <= min(N, K);b++) {
            vector<ll> v;
            ll count = 0;
            if(a + b > min(N, K)) break;
            for(ll i = 0;i < a;i++) v.push_back(gems[i]), count += gems[i];
            for(ll i = 0;i < b;i++) v.push_back(gems[gems.size() - 1 - i]), count += gems[gems.size() - 1 - i];
            sort(v.begin(), v.end());
            for(ll i = 0;i < min((ll)v.size(), K - (a + b));i++) {
                if(v[i] >= 0) break;
                count -= v[i];
            }
            maxi = max(maxi, count);
        }
    }
    cout << maxi << endl;
    return 0;
}


Measured memory_bytes: 256
S=list(str(input()))

judg=True
for i in range(len(S)):
    if not S[i]==S[len(S)-i-1]:
        judg=False
        break
if judg==False:
    print('No')
else:
    for i in range(int((len(S)-1)/2)):
        if not S[i]==S[int((len(S)-1)/2)-1-i]:
            judg=False
            break
    if judg==True:
        print('Yes')
    else:
        print('No')

Measured memory_bytes: 3064
//list index out of rangeエラー表示用
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
#define rep1(i, n) for (int i = 0; i < (int)(n); i++)
#define rep2(i, s, n) for (int i = (s); i < (int)(n); i++)


int main(){
  int n;
  cin >> n;
  vector<long long> A(n), A_copy(n), data(n);
  rep1(i, n){
    cin >> A[i];
    A_copy[i] = A[i];
  }
  
  sort(A.begin(), A.end());
  vector<long long> kaisu_lan_A; // 答えを格納
  for (int l = 0; l < n;) {
    int r = 0;
    for (; l+r < n && A[l] == A[l+r]; r++) {
      data[A[l]-1] += 1;
    }
    kaisu_lan_A.push_back(r);
    l += r;
  }

  long long sum = 0;
  rep1(i, kaisu_lan_A.size()){
  long long tem = kaisu_lan_A[i];
    sum += tem*(tem-1)/2;
  }

  rep1(i, n){
    long long tem = data[A_copy[i]-1];
    cout << sum - tem*(tem-1)/2 + (tem-1)*(tem-2)/2 << endl;
  }



}


Measured memory_bytes: 8996
#include <iostream>
#include <cstring>

using namespace std;

string field[9];

void vis(int x, int y){

	if(x<0 || 7<x || y<0 || 7<y || field[y][x]=='0'){
		return;
	}

	if(field[y][x]=='1'){
	
		field[y][x]='0';

		for(int t=1; t<=3; ++t){
		
			vis(x+t, y);
			vis(x-t, y);
			vis(x, y+t);
			vis(x, y-t);
		}
	}

	return;
}

int main(){

	int n, x, y, cnt=1;

	cin>>n;

	while(cnt<=n){
		
		for(int j=0; j<8; ++j){
			string s;
			cin>>s;
			field[j]=s;
		}
		
		cin>>x>>y;
		x--; y--;
		field[y][x]=='1';
		vis(x, y);
		
		cout << "Data "<< cnt << ":" << endl;
		
		for(int j=0; j<8; ++j){

			cout << field[j] << endl;
		}

		cnt++;
	}
		
	return 0;
}

Measured memory_bytes: 1216
// https://atcoder.jp/contests/abc166/tasks/abc166_d

#include <bits/stdc++.h>
using namespace std;
using ll = int64_t;

#define REP(i,n)   for(int i=0; i<(int)(n); i++)
#define FOR(i,b,e) for(int i=(b); i<=(int)(e); i++)
#define DEBUG 1
#if DEBUG
  #define _GLIBCXX_DEBUG
  #define DUMP(a) REP(_i, a.size()) cout << a[_i] << (_i + 1 == a.size() ? "\n" : " ")
  #define DUMP2D(b) REP(_j, b.size()) DUMP(b[_j]); cout << endl
#else
  #define DUMP(a)
  #define DUMP2D(b)
#endif

const int X_MAX = 1e9;

ll X;

int main() {
  cin >> X;

  for (ll A = 120L; A > 0; A--) {
    for (ll B = A - 1; B >= -120L; B--) {
      ll d = A * A * A * A * A - B * B * B * B * B;
      if (d == X) {
        cout << A << " " << B << endl;
        return 0;
      }
    }
  }
}


Measured memory_bytes: 3628
#include<iostream>
#include<vector>
#include<queue>
using namespace std;
#define INF (1<<24)

int n,m,a,b,c,R;
int r[1001];
char ch;
int t[201][201];
int u[201][201];
int dp[201][1001];
 
void init();
int solve();
  
int main(){
  while(cin>>n>>m){
    if(n==0&&m==0)break;
    init();
    for(int i=0;i<m;i++){
      cin>>a>>b>>c>>ch;
      a--;b--;
      if(ch=='L'){
	t[a][b]=min(t[a][b],c);
	t[b][a]=min(t[b][a],c);
      }else {
	u[a][b]=min(u[a][b],c);
	u[b][a]=min(u[b][a],c);
      }
    }
    cin>>R;
    for(int i=0;i<R;i++){
      cin>>r[i];
      r[i]--;
    }
 
    for(int k=0;k<n;k++){
      for(int i=0;i<n;i++){
	for(int j=0;j<n;j++){
	  u[i][j]=min(u[i][j],u[i][k]+u[k][j]);
	  t[i][j]=min(t[i][j],t[i][k]+t[k][j]);
	}
      }
    }
    cout<<solve()<<endl;
  }
  return 0;
}
  
int solve(){
  dp[r[0]][0]=0;
  for(int i=0;i<R-1;i++){
    for(int j=0;j<n;j++){
      if(dp[j][i]==INF)continue;

      for(int k=0;k<n;k++){
	dp[k][i+1]=min(dp[k][i+1],dp[j][i]+t[r[i]][j]+u[j][k]+t[k][r[i+1]]);
      }
      
      dp[j][i+1]=min(dp[j][i+1],dp[j][i]+t[r[i]][r[i+1]]);
      
      dp[r[i+1]][i+1]=min(dp[r[i+1]][i+1],dp[j][i]+t[r[i]][j]+u[j][r[i+1]]);

    }
  }
  int res=INF;
  for(int i=0;i<n;i++)res=min(res,dp[i][R-1]);
  return res;
}
  
void init(){
  for(int i=0;i<201;i++){
    for(int j=0;j<201;j++){
      if(i==j)u[i][j]=0;
      else u[i][j]=INF;
      t[i][j]=u[i][j];
    }
    for(int j=0;j<1001;j++)dp[i][j]=INF;
  }
}

Measured memory_bytes: 2264
import sys
stdin = sys.stdin
 
sys.setrecursionlimit(10**5) 
 
def li(): return map(int, stdin.readline().split())
def li_(): return map(lambda x: int(x)-1, stdin.readline().split())
def lf(): return map(float, stdin.readline().split())
def ls(): return stdin.readline().split()
def ns(): return stdin.readline().rstrip()
def lc(): return list(ns())
def ni(): return int(stdin.readline())
def nf(): return float(stdin.readline())

from functools import reduce

def gcd(a,b):
    if a%b == 0:
        return b
    else:
        return gcd(b, a%b)
    
n = ni()
a = list(li())
print(reduce(gcd, a))

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

int n, x;
int a[100001];

int main()
{
	cin >> n;

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

	int ans = 0, cnt = 0;
	for (int i = 0; i < 100000; ++i){
		if (a[i] == 0) continue;
		if (a[i] & 1) ans++;
		else cnt++;
	}
	
	cout << ans + cnt - (cnt & 1) << endl;
}


Measured memory_bytes: 640
#pragma region RegionDefs
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0,i##_len=(n);i<i##_len;++i)
#define reps(i,l,r) for(int i=(l),i##_len=(r);i<i##_len;++i)
#define all(x) begin(x),end(x)
using namespace std;
const int INF = 1e9;
template<class T=int> using V = vector<T>;
template<class T=int> using PQ = priority_queue<T>;
template<class T=int> using PQG = priority_queue<T, V<T>, greater<T>>;
typedef long long ll;
const ll MOD = 1000000007LL;
void in() {}
template<class Head, class... Tail>
void in(Head&& head, Tail&&... tail)
{
    cin >> head;
    in(move(tail)...);
}
#define IN(...) ll __VA_ARGS__; in(__VA_ARGS__)
#define INS(T, ...) T __VA_ARGS__; in(__VA_ARGS__)
#define VIN(T, v, n) V<T> v(n); for(auto& _elem:v)cin>>_elem
template<class T>bool chmax(T &a, const T &b) {if (a<b) {a=b; return 1;} return 0;}
template<class T>bool chmin(T &a, const T &b) {if (a>b) {a=b; return 1;} return 0;}
#define y0 y__0
#define y1 y__1
#define j0 j__0
#define j1 j__1
#define YN(e) cout << ((e) ? "YES" : "NO") << endl
#define yn(e) cout << ((e) ? "Yes" : "No") << endl
#pragma endregion RegionDefs

void solve()
{
    IN(x);
    vector<ll> v;
    for (ll i = 0; i <= 1000; ++i)
    {
        v.push_back(i * i * i * i * i);
    }
    rep(i, v.size())
    {
        rep(j, v.size())
        {
            if (v[i] + v[j] == x)
            {
                cout << i << " " << "-" << j << endl;
                return;
            }
            if (v[i] - v[j] == x)
            {
                cout << i << " " << j << endl;
                return;
            }
        }
    }
}

int main()
{
    cin.tie(0); cout.tie(0);
    ios::sync_with_stdio(false);
    cout << setprecision(numeric_limits<double>::max_digits10);

    solve();

    return 0;
}

Measured memory_bytes: 3660
#include <stdio.h>
#include <unistd.h>

int main()
{
	int i;
	int n;
	int w;
	int r;

	r = 0;
	w = 0;
	scanf("%d", &n);
	char str[n + 1];
	scanf("%s", str);
	i = 0;
	while (str[i])
	{
		if (str[i] == 'R')
			r++;
		i++;
		n--;
	}
	i = 0;
	while (r)
	{
		if (str[i] == 'W')
			w++;
		i++;
		r--;
	}
	printf("%d", w);
	return (0);
}

Measured memory_bytes: 1888
import sys
def input(): return sys.stdin.readline().strip()
def mapint(): return map(int, input().split())
sys.setrecursionlimit(10**9)

N = int(input())
S, T = input().split()
ans = ''
for s, t in zip(list(S), list(T)):
    ans += s+t
print(ans)

Measured memory_bytes: 61968
#include <stdio.h>
#include <string.h>
#define f(X) ((X)%3==0?3:(X)%3)
#define F(X, Y) (f(X)>f(Y))
int func(char* s, int n, int isleft)
{
    int i, left=-1, right=-1;
    int res=0;
    if (isleft) left=s[0]; else right=s[0];
    isleft=!isleft;
    for(i=1;i<n;++i) {
        if (isleft) {
            if (F(s[i], right)) { ++res; right=s[i]; }
            else { left=s[i]; isleft=!isleft; }
        }
        else {
            if (F(left, s[i])) { ++res; left=s[i]; }
            else { right=s[i]; isleft=!isleft; }
        }
    }
    return res;
}

char s[100001];
int main(void)
{
    while (scanf("%s", s), *s!='#') {
        int n=strlen(s), i;
        int L, R;
        for(i=0;i<n;++i) s[i]-='0';
        L=func(s, n, 1);
        R=func(s, n, 0);
        printf("%d\n", L<R?L:R);
    }
    return 0;
}

Measured memory_bytes: 636
#include <bits/stdc++.h>
  using namespace std;
#define ll long long
#define fw(p) for(int w=0;w<(p);w++)
#define fx(p) for(int x=0;x<(p);x++)
#define fy(p) for(int y=0;y<(p);y++)
#define fz(p) for(int z=0;z<(p);z++)
#define fyg(p,g) for(int y=(g);y<(p);y++)
#define fzg(p,g) for(int z=(g);z<(p);z++)
#define ce(d) cout<<d<<endl;
#define vecp(p) int aa;cin>>aa;(p).push_back(aa);
#define vecpl(p) long long aa;cin>>aa;(p).push_back(aa);
#define vecps(p) string aa;cin>>aa;(p).push_back(aa);
#define vecp2(p) int ab;cin>>ab;(p).push_back(ab);
#define vecpl2(p) long long ab;cin>>ab;(p).push_back(ab);
#define vecps2(p) string ab;cin>>ab;(p).push_back(ab);
#define set0(k,n) for(int nn=0;nn<(n);nn++){ (k).push_back(0); }
#define sorts(c) sort((c).begin(),(c).end());
#define reverses(c) reverse((c).begin(),(c).end());
#define vec(b) vector<int> (b);
#define vecl(b) vector<long long> (b);
#define vecs(b) vector<string> (b);
#define vecsize(b,size) vector<int> (b)((size));
#define pb(b,a) (b).push_back((a));
#define doublece(a,b) cout<<(a)<<' '<<(b)<<endl;

 		
int main() {


int X,Y;
cin>>X>>Y;
int ans=X+Y/2;
ce(ans)

}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define FASTIO ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);
#define ll long long
#define pb push_back
#define F first
#define S second
#define ld long double
#define rep(i,n) for (int i =0;i < (n); ++i)
#define vi vector<ll>
#define all(v) (v).begin(),(v).end()
const int inf = 1e9 + 10;
ll n, a, b, c;
map<char, ll> cnt;
string s, ans, t = "ABC";
vector<string> v;
char get(string s) {
	char np;
	for (int i = 0; i < 3; i++) {
		if (find(all(s), t[i]) == s.end()) {
			np = t[i];
			break;
		}
	}
	return np;
}
void solve() {
	cin >> n;
	cin >> a >> b >> c;
	cnt['A'] = a; cnt['B'] = b; cnt['C'] = c;
	for (int i = 0; i < n; i++) {
		cin >> s;
		v.pb(s);
	}

	for (int i = 0; i < n; i++) {
		s = v[i];
		char np = get(s);
		//cout << np << " ";
		if (cnt[s[0]] == 0 && cnt[s[1]] == 0) {
			cout << "No";
			return;
		}
		else if (cnt[s[0]] == 1 && cnt[s[1]] == 1 && cnt[np] == 0) {
			char p = s[1], m = s[0];

			if (i + 1 < n)
				if (find(all(v[i + 1]), s[0]) != v[i + 1].end()) p = s[0], m = s[1];

			cnt[p]++;
			cnt[m]--;
			ans += p;
		}
		else {
			if (cnt[s[0]] < cnt[s[1]]) {
				cnt[s[0]]++;
				cnt[s[1]]--;
				ans += s[0];
			}
			else {
				cnt[s[1]]++;
				cnt[s[0]]--;
				ans += s[1];
			}
		}
		//cout << cnt[s[0]] << " " << cnt[s[1]] << endl;
	}
//cout << endl;
	bool f = true;
	for ( auto c : cnt) if (c.S < 0) f = false;
	if (f) {
		cout << "Yes" << endl;
		for (int i = 0; i < n; i++) cout << ans[i] << endl;
	}
	else
		cout << "No";
}

int main() {

	FASTIO;


	cout << fixed << setprecision(25);
	int t = 1;
	//cin >> t;
	while (t--) {
		solve();
	}
	return 0;
}

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

int main(void) {
  int H,W,N;
  int Sr,Sc;
  string S,T;
  cin >> H >> W >> N >> Sr >> Sc >> S >> T;
  Sr--; Sc--;
  int mem[2][2]={{-1,H},{-1,W}};
  rep(i,N){
    if(T[N-1-i]=='U'&&mem[0][1]<H) mem[0][1]++;
    if(S[N-1-i]=='D'&&mem[0][1]>-1) mem[0][1]--;
    if(mem[0][1]==0) break;
  }
  rep(i,N){
    if(T[N-1-i]=='D'&&mem[0][0]>-1) mem[0][0]--;
    if(S[N-1-i]=='U'&&mem[0][0]<H) mem[0][0]++;
    if(mem[0][0]==H-1) break;
  }
  rep(i,N){
    if(T[N-1-i]=='L'&&mem[1][1]<W) mem[1][1]++;
    if(S[N-1-i]=='R'&&mem[1][1]>-1) mem[1][1]--;
    if(mem[1][1]==0) break;
  }
  rep(i,N){
    if(T[N-1-i]=='R'&&mem[1][0]>-1) mem[1][0]--;
    if(S[N-1-i]=='L'&&mem[1][0]<W) mem[1][0]++;
    if(mem[1][0]==W-1) break;
  }
  if(mem[0][0]<Sr&&mem[0][1]>Sr&&mem[1][0]<Sc&&mem[1][1]>Sc)
    cout << "YES" << endl;
  else cout << "NO" << endl;
  return 0;
}

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

#define fst(t) std::get<0>(t)
#define snd(t) std::get<1>(t)
#define thd(t) std::get<2>(t)
#define unless(p) if(!(p))
#define until(p) while(!(p))

using ll = std::int64_t;
using P = std::tuple<int,int>;

template <typename T>
std::tuple<T, T, T> extgcd(T a, T b){
    T s1 = 1, t1 = 0, s2 = 0, t2 = 1;
    while(b != 0){
        std::tie(s1, t1, s2, t2) = std::make_tuple(s2, t2, s1 - (a / b) * s2, t1 - (a / b) * t2);
        std::tie(a, b) = std::make_tuple(b, a % b);
    }
    return std::make_tuple(s1, t1, a);
}

// 注意: a と mod が互いに素である必要がある
template <typename T>
T mod_inverse(T a, T mod){
    T b;
    std::tie(b, std::ignore, std::ignore) = extgcd(a, mod);
    if(b < 0){b += mod;}
    return b;
}

template <typename T>
struct Combinatorics{
    T modulo;
    std::vector<T> fact, inv_fact;

    Combinatorics(T max, T modulo) : modulo(modulo), fact(max + 1), inv_fact(max + 1) {
        fact[0] = 1;
        for(T i=1;i<=max;++i){
            fact[i] = i * fact[i - 1] % modulo;
        }

        inv_fact[max] = mod_inverse(fact[max], modulo);
        for(T i=max;i>0;--i){
            inv_fact[i - 1] = i * inv_fact[i] % modulo;
        }
    }

    T nPk(T n, T k){
        if(n < k){return 0;}
        return fact[n] * inv_fact[n - k] % modulo;
    }

    T nCk(T n, T k){
        if(n < k){return 0;}
        return fact[n] * inv_fact[k] % modulo * inv_fact[n - k] % modulo;
    }

    T nHk(T n, T k){
        if(n == 0 && k == 0){return 1;}
        return nCk(n + k - 1, k);
    }
};

constexpr ll MOD = 1'000'000'007;
Combinatorics<ll> comb(400100, MOD);
ll N, M, K;

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

    std::cin >> N >> M >> K;

    ll r1 = 0, r2 = 0;

    for(int d=1;d<N;++d){
        r1 = (r1 + 1ll * d * (N - d)) % MOD;
    }

    r1 = r1 * M % MOD * M % MOD * comb.nCk(N * M - 2, K - 2) % MOD;

    for(int d=1;d<M;++d){
        r2 = (r2 + 1ll * d * (M - d)) % MOD;
    }

    r2 = r2 * N % MOD * N % MOD * comb.nCk(N * M - 2, K - 2) % MOD;

    ll res = (r1 + r2) % MOD;

    std::cout << res << std::endl;
}

Measured memory_bytes: 6528
#pragma GCC optimize(2)
#pragma GCC optimize(3)
#pragma GCC optimize("Ofast")
#pragma GCC optimize("inline")
#pragma GCC optimize("-fgcse")
#pragma GCC optimize("-fgcse-lm")
#pragma GCC optimize("-fipa-sra")
#pragma GCC optimize("-ftree-pre")
#pragma GCC optimize("-ftree-vrp")
#pragma GCC optimize("-fpeephole2")
#pragma GCC optimize("-ffast-math")
#pragma GCC optimize("-fsched-spec")
#pragma GCC optimize("unroll-loops")
#pragma GCC optimize("-falign-jumps")
#pragma GCC optimize("-falign-loops")
#pragma GCC optimize("-falign-labels")
#pragma GCC optimize("-fdevirtualize")
#pragma GCC optimize("-fcaller-saves")
#pragma GCC optimize("-fcrossjumping")
#pragma GCC optimize("-fthread-jumps")
#pragma GCC optimize("-funroll-loops")
#pragma GCC optimize("-fwhole-program")
#pragma GCC optimize("-freorder-blocks")
#pragma GCC optimize("-fschedule-insns")
#pragma GCC optimize("inline-functions")
#pragma GCC optimize("-ftree-tail-merge")
#pragma GCC optimize("-fschedule-insns2")
#pragma GCC optimize("-fstrict-aliasing")
#pragma GCC optimize("-fstrict-overflow")
#pragma GCC optimize("-falign-functions")
#pragma GCC optimize("-fcse-skip-blocks")
#pragma GCC optimize("-fcse-follow-jumps")
#pragma GCC optimize("-fsched-interblock")
#pragma GCC optimize("-fpartial-inlining")
#pragma GCC optimize("no-stack-protector")
#pragma GCC optimize("-freorder-functions")
#pragma GCC optimize("-findirect-inlining")
#pragma GCC optimize("-fhoist-adjacent-loads")
#pragma GCC optimize("-frerun-cse-after-loop")
#pragma GCC optimize("inline-small-functions")
#pragma GCC optimize("-finline-small-functions")
#pragma GCC optimize("-ftree-switch-conversion")
#pragma GCC optimize("-foptimize-sibling-calls")
#pragma GCC optimize("-fexpensive-optimizations")
#pragma GCC optimize("-funsafe-loop-optimizations")
#pragma GCC optimize("inline-functions-called-once")
#pragma GCC optimize("-fdelete-null-pointer-checks")
#include<algorithm>
#include<iostream>
#include<iomanip>
#include<cstring>
#include<cstdio>
#include<cmath>
#define re register
using namespace std;
char s[10002];
signed main(){
	scanf("%s",s+1);
	int n=strlen(s+1);
	if(n&1){
		puts("No");
		return 0;
	}
	for(re int i=1;i<=n;i+=2){
		if(s[i]!='h'||s[i+1]!='i'){
			puts("No");
			return 0;
		}
	}
	puts("Yes");
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main() {
 
  int n,k,sum;
  cin >> n >> k;
  for(int i =0;i < n;i++) {
    int x;
    cin >> x;
    
    if(x*x >(k-x)*(k-x) ) sum+=(k-x)*2;
    else sum+=x*2;
}
  cout << sum <<endl;
}

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

// iterator
#define REP(i,from, to) for(lli i=from;i<to;i++)
#define REPE(i,from, to) for(lli i=from;i<=to;i++)
#define REP_R(i,from, to) for(lli i=from;i>to;i--)
#define REPE_R(i,from, to) for(lli i=from;i>=to;i--)
#define REPIT(it,container) for(auto it = container.begin(); it != container.end(); it++)
#define REPIT_R(it,container) for(auto it = container.rbegin(); it != container.rend(); it++)

// input
#define cin1(x)             cin >> x
#define cin2(x, y)          cin >> x >> y
#define cin3(x, y, z)       cin >> x >> y >> z
#define ncin1(n, x)         REP(i, 0, n) {cin1(x[i]);}
#define ncin2(n, x, y)      REP(i, 0, n) {cin2(x[i], y[i]);}
#define ncin3(n, x, y, z)   REP(i, 0, n) {cin3(x[i], y[i], z[i]);}

// output
#define cout1(x)         cout << #x << ": " << x << endl;
#define cout2(x, y)      cout << #x << ": " << x << ", " << #y << ": " << y << endl;
#define cout3(x, y, z)   cout << #x << ": " << x << ", " << #y << ": " << y << ", " << #z << ": " << z << endl;;
#define ncout1(n, x)     REP(i, 0, n) {cout << #x << "[" << i << "]: "<< x[i] << endl;}

#define coutp(p)         cout << #p << ":" <<  " (" << p.first << ", " << p.second << ")" << endl;

// sort
#define sort_r(x, y)        sort(x, y, greater<lli>()); // 降順(5,4,3,,,)

#define ARRAY_LENGTH(array) (sizeof(array) / sizeof(array[0]))

typedef long long int lli;
typedef pair<lli, lli> P;
typedef tuple<lli, lli, lli> tup;

int main() {
    lli n;
    cin1(n);
    if (n % 2 == 0)
        cout << fixed << 1 / 2.0 << endl;
    else
        cout << fixed <<  ((n+1)/2.0) / (double)n << endl;
}


Measured memory_bytes: 256
import sys 
n = int(input())

a = list(map(int, sys.stdin.readline().split()))

sorted_a = sorted(a)
reversed_a = sorted(a, reverse=True)

aa = []
for i in range(n):
    sorted_a.pop(-1)
    reversed_a.pop(-1)
    aa.append(sorted_a.pop(-1))

print(sum(aa))

Measured memory_bytes: 37084
#include <iostream>
#include <string>
#include <map>
#include <vector>
#include <utility>
#include <set>
#include <stack>
#include <queue>
#include <deque>
#include <algorithm>
#include <cmath>

#define rep(i,j,k) for(int i=(int)j;i<(int)k;i++)
#define itrep(i,x) for(auto i=(x).begin(); i!=(x).end();i++)
#define Sort(x) sort((x).begin(),(x).end())
#define all(x) (x).begin(),(x).end()
#define fi first
#define se second
#define vec vector
#define INF (int)1e9
#define INFL 1e18
#define MOD 1000000007
#define pb push_back
#define MP make_pair
#define PI 3.1415926535
typedef long long int ll;
typedef std::pair<int,int> P;
int D=1;
int dx[4]={0,1,0,-1},dy[4]={-1,0,1,0};

using namespace std;

int main(){
    int n,m;
    while(cin>>n>>m&&n&&m){
        vector<int> h(1500010,0),w(1500010,0);
        vector<int> vh(n),vw(m);

        rep(i,0,n){
            cin>>vh[i];
            if(i){
                vh[i]+=vh[i-1];
                h[vh[i]]++;
            }
        }

        rep(i,0,m){
            cin>>vw[i];
            if(i){
                vw[i]+=vw[i-1];
                w[vw[i]]++;
            }

        }

        rep(i,0,n)rep(j,0,i){
            h[vh[i]-vh[j]]++;
        }
        rep(i,0,m)rep(j,0,i){
            w[vw[i]-vw[j]]++;
        }
        w[vw[0]]++;
        h[vh[0]]++;

        ll ans=0;
        rep(i,1,1500010){
            if(h[i]&&w[i]&&0){
                cout<<h[i]<<" "<<w[i]<<" "<<i<<endl;
            }
            ans+=h[i]*w[i];
        }
        cout<<ans<<endl;
    }

    
    return 0;
}



Measured memory_bytes: 14496
#include <bits/stdc++.h>
using namespace std;
 
int main () {
  int N, A, B;
  cin >> N >> A >> B;
  
  int plan1, plan2;
  plan1 = A * N;
  plan2 = B;
  
  if (plan1 < plan2) cout << plan1 << endl;
    else cout << plan2 << endl;
}

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

// int main()
// {
//     ll N, A, B, C, D, E;
//     cin >> N >> A >> B >> C >> D >> E;
//     ll ans = max((N - 1) / A, max((N - 1) / B, max((N - 1) / C, max((N - 1) / D, (N - 1) / E )))) + 5;

//     cout << ans << endl;
//     return 0;
// }

int main(){
    ll N, A, B, C, D, E;
    cin >> N >> A >> B >> C >> D >> E;
    ll mini = min(A,min(B,min(C,min(D,E))));
    ll ans;
    if(N%mini == 0)  ans = N/mini;
    else  ans = N/mini + 1;

    cout << ans + 4 << endl;
    return 0;
}

Measured memory_bytes: 256
#include <cstdio>
#include <iostream>
#include <cmath>
#include <cstring>
#include <sstream>
#include <algorithm>
#include <cstdlib>
#include <map>
#include <queue>
#include <utility>
#include <vector>
#include <set>
#include <memory.h>
#include <iomanip>
#include <bitset>
#include <list>
#include <stack>

using namespace std;

#define mod 1000000007

double kyori(double x1, double y1, double x2, double y2)
{
    return sqrt(pow(x1 - x2, 2) + pow(y1 - y2, 2));
}

int main()
{
    double xs, ys, xt, yt;
    int n;
    cin >> xs >> ys >> xt >> yt >> n;
    double x[1001], y[1001], r[1001];
    for(int i = 0; i < n; i++){
        cin >> x[i] >> y[i] >> r[i];
    }
    double minkyori[1001];
    for(int i = 0; i < n; i++){
        minkyori[i] = -1.0;
    }
    priority_queue<pair<double, int> > qu;
    for(int i = 0; i < n; i++){
        qu.push(make_pair(-(max(0.0, kyori(xs, ys, x[i], y[i]) - r[i])), i));
    }
    while(!qu.empty()){
        int nowbaria = (qu.top()).second;
        double nowkyori = -(qu.top()).first;
        qu.pop();
        if(minkyori[nowbaria] != -1.0 && minkyori[nowbaria] < nowkyori) continue;
        minkyori[nowbaria] = nowkyori;
        for(int i = 0; i < n; i++){
            double tmp = max(0.0, kyori(x[nowbaria], y[nowbaria], x[i], y[i]) - (r[nowbaria] + r[i]));
            if(minkyori[i] == -1.0 || minkyori[i] > nowkyori + tmp){
                minkyori[i] = nowkyori + tmp;
                qu.push(make_pair(-nowkyori - tmp, i));
            }
        }
    }
    double ans = kyori(xs, ys, xt, yt);
    for(int i = 0; i < n; i++){
        ans = min(ans, minkyori[i] + max(0.0, kyori(xt, yt, x[i], y[i]) - r[i]));
    }
    printf("%.10f\n", ans);
    return 0;
}

Measured memory_bytes: 4464
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (int)(n); i ++)
#define irep(i,n) for (int i = (int)(n) - 1;i >= 0;--i)
using namespace std;
using ll = long long;
using PL = pair<ll,ll>;
using P = pair<int,int>;
constexpr int INF = 1000000000;
constexpr long long HINF = 1000000000000000;
constexpr long long MOD = 1000000007;// = 998244353;
constexpr double EPS = 1e-4;
constexpr double PI = 3.14159265358979;

int main() {
    int a,b,c; cin >> a >> b >> c;
    int K; cin >> K;
    int cnt = 0;
    while (b <= a) {
        b *= 2;
        cnt += 1;
    }
    while (c <= b) {
        c *= 2;
        cnt += 1;
    }
    if (cnt <= K) cout << "Yes" << '\n';
    else cout << "No" << '\n';
    return 0;
}

Measured memory_bytes: 3632
d = int(input())
c = list(map(int, input().split()))
s = [list(map(int, input().split())) for _ in range(d)]
t = [int(input()) - 1 for _ in range(d)]

def scoring(d, c, s, t):
    v = []
    memo = [0 for _ in range(26)]
    for i in range(d):
        if i == 0:
            score = 0
        else:
            score = v[-1]
        score += s[i][t[i]]
        memo[t[i]] = i + 1
        for j in range(26):
            score -= c[j] * (i+1 - memo[j])

        v.append(score)

    return v[-1]

score = scoring(d, c, s, t)

m = int(input())
memo = [[0 for _ in range(26)]]
for i in range(d):
    l = memo[-1]
    l[t[i]] = i+1
    memo.append(l)

for _ in range(m):
    x, y = map(int, input().split())
    x -= 1
    y -= 1
    before_ti, after_ti = 0, d+1
    before_y, after_y = 0, d+1

    for i in range(x):
        if t[i] == t[x]:
            before_ti = i+1
        if t[i] == y:
            before_y = i+1

    for i in range(x+1, d):
        if t[i] == t[x]:
            after_ti = i+1
            break
    for i in range(x+1, d):
        if t[i] == y:
            after_y = i+1
            break

    score -= s[x][t[x]]
    score += s[x][y]
    score -= c[t[x]] * (x + 1 - before_ti) * (after_ti - x - 1)
    score += c[y] * (x + 1 - before_y) * (after_y - x - 1)

    t[x] = y

    print(score)

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

int main(){
    int a,b;
    cin>>a>>b;
    if(a>=10||b>=10){
        cout << -1 <<endl;
        return 0;
    }
    cout<<a*b<<endl;
}

Measured memory_bytes: 3640
#include<iostream>
using namespace std;
int main(){
    string S;
    cin>>S;
    int N=S.size();
    for(int i=0;i<N;++i){
        
        if(i%2==0){
            if(S[i] == 'L'){
            cout<<"No"<<endl;
            return 0;
            }
        }
        
        else{
            if(S[i] == 'R'){
            cout<<"No"<<endl;
            return 0;
            }
        }

    }
    cout<<"Yes"<<endl;

}


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


int main() {
  int n, T; cin >> n >> T;
  int m = 10000;
  for(int i = 0; i < n; i++){
    int c, t;
    cin >> c >> t;
    if(t <= T && c < m){
      m = c;
    }
  }
  if(m == 10000) cout << "TLE" << endl;
  else cout << m << endl;

}


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

public class Main {

	BufferedReader br;
	PrintWriter out;
	StringTokenizer st;
	boolean eof;
	
	char getChar(int k) {
		return (char)('a' + k);
	}

	void solve() throws IOException {
		String s = nextToken();
		int k = nextInt();
		
		StringBuilder sb = new StringBuilder();
		
		for (int i = 0; i < s.length() - 1; i++) {
			int cur = s.charAt(i) - 'a';
			if (cur == 0) {
				sb.append('a');
				continue;
			}
			int toA = 26 - cur;
			if (k >= toA) {
				k -= toA;
				sb.append('a');
			} else {
				sb.append(getChar(cur));
			}
		}
		
		k %= 26;
		int cur = s.charAt(s.length() - 1) - 'a';
		cur = (cur + k) % 26;
		sb.append(getChar(cur));
		out.println(sb.toString());
	}

	Main() throws IOException {
		br = new BufferedReader(new InputStreamReader(System.in));
		out = new PrintWriter(System.out);
		solve();
		out.close();
	}

	public static void main(String[] args) throws IOException {
		new Main();
	}

	String nextToken() {
		while (st == null || !st.hasMoreTokens()) {
			try {
				st = new StringTokenizer(br.readLine());
			} catch (Exception e) {
				eof = true;
				return null;
			}
		}
		return st.nextToken();
	}

	String nextString() {
		try {
			return br.readLine();
		} catch (IOException e) {
			eof = true;
			return null;
		}
	}

	int nextInt() throws IOException {
		return Integer.parseInt(nextToken());
	}

	long nextLong() throws IOException {
		return Long.parseLong(nextToken());
	}

	double nextDouble() throws IOException {
		return Double.parseDouble(nextToken());
	}
}

Measured memory_bytes: 11860
#include<bits/stdc++.h>
using namespace std;
#define ll long long
const double PI=3.1415926535;
ll a[500000];
int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    ll n;
    cin>>n;
    for(int i=1;i<=n;i++)
    {
       cin>>a[i];
    }
    sort(a+1,a+1+n);
    ll ans=a[n/2+1]-a[n/2];
    cout<<ans<<'\n';







}



Measured memory_bytes: 1024
n = int(input())
x = [int(i) for i in input().split()]
sortx = sorted(x)

ai = sortx[n-1]
mid = float(ai)/2
x2 = sorted(abs(k - mid)for k in x)[0]

if (mid - x2) in x:
    aj = int(mid - x2)
else:
    aj = int(mid + x2)

print(ai," ",aj)


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

#define EPS (1e-10)
#define rep(i, a, b) for (int i = a; i < (int)(b); ++i)
#define rrep(i, a, b) for (int i = b - 1; i >= (int)(a); --i)
#define all(a) a.begin(), a.end()

using namespace std;
using ll = long long;
using vi = vector<int>;
using vb = vector<bool>;
using vll = vector<ll>;
using vd = vector<double>;
using vvi = vector<vi>;
using vvb = vector<vb>;

constexpr int MOD = 1000000007;

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

    string s, t;
    cin >> s >> t;

    int ans = 0;
    rep(i, 0, 3) {
        if (s[i] == t[i]) { ++ans; }
    }
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define db(x) cout << #x << " = " << (x) << "\n";
using ll = long long;
using ld = long double;

int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(NULL);
    ll n, k;
    cin >> n >> k;
    vector<int> h(n + 2 + k);
    for (int i = 1; i <= n; i++)
    {
        cin >> h[i];
    }
    vector<int> dist(n + k + 1, INT_MAX);
    dist[1] = 0;
    for (int i = 1; i < n; i++)
    {
        for (int j = 1; j <= k; j++)
        {
            dist[i + j] = min(dist[i + j], dist[i] + abs(h[i + j] - h[i]));
        }
    }
    cout << dist[n];
    return 0;
}


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

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

using namespace std;

using ll = long long;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n;
  cin >> n;
  vector<int> a(n), b(n), c(n);
  rep(i, n) {
    cin >> a[i];
  }
  rep(i, n) {
    cin >> b[i];
  }
  rep(i, n) {
    cin >> c[i];
  }
  sort(a.begin(), a.end());
  sort(c.begin(), c.end());
  ll ans = 0;
  rep(i, n) {
    int ok_a = lower_bound(a.begin(), a.end(), b[i]) - a.begin();
    int ok_c = n - (upper_bound(c.begin(), c.end(), b[i]) - c.begin());
    ans += (ll)ok_a * ok_c;
  }
  cout << ans;
  return 0;
}

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



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

    int ans = 0;

    if (x < 500) {
        ans = (x / 5) * 5;
    } else {
        int remainder = x % 500;
        ans = (x / 500) * 1000 + (remainder / 5) * 5;
    }

    cout << ans << endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define double long double
#define SZ(x) ((int)(x).size())
#define rep(i,m,n) for(int i=(m);i<(n);++i)
#define fore(i,a) for(auto &i:a)
#define Yes cout << "Yes" << endl;
#define No cout << "No" << endl;
#define answer cout << ans << endl;
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; }
template<class T> using v = vector<T>;
template<class T> using vv = vector<v<T>>;
const int MOD=1e9+7;
const long long INF = 1LL << 60;
signed _main(); signed main() { cin.tie(0); ios::sync_with_stdio(false); _main(); }

int rec(int l,int r,vv<int> &dp,v<int> &s){
  if(dp[l][r]!=-1) return dp[l][r];
  if(abs(l-r)<=1) return 0;
  int res=INF;
  for(int mid=l+1;mid<=r-1;mid++){
    chmin(res,rec(l,mid,dp,s)+rec(mid,r,dp,s)+s[r]-s[l]);
  }
  return dp[l][r]=res;
}

signed _main(){
  int N; cin >> N;
  v<int> w(N);
  rep(i,0,N) cin >> w[i];

  // 累積和
  vector<int> s(N+1, 0); // s[0] = 0 になる
  for (int i = 0; i < N; ++i) s[i+1] = s[i] + w[i];

  vv<int> dp(410,v<int>(410,-1));
  cout << rec(0,N,dp,s) << endl;
  return 0;
}


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

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

int main(){
    int N;
    string s;
    cin >> N >> s;
    bool is = true;
    rep(i, N-1) if(s[i] != s[i+1]) is = false;
    if(is){
        cout << 1 << endl;
        return 0;
    }
    int ans = 0;
    rep(i, N){
        if(s[i] == s[i+1]){
            while(s[i] == s[i+1] && i < N) i++;
        }
        ans++;
    }
    cout << ans << endl;
    return 0;
}

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



int main()
{
	long long a[4];
	cin>>a[0]>>a[1]>>a[2];
	if(a[0]%2==0||a[1]%2==0||a[2]%2==0)
	cout<<0<<endl;
	else
	{
		sort(a,a+3);
		cout<<a[0]*a[1]<<endl; 
	}
}

Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <vector>
#include <algorithm>
#include <cstring>
#include <map>
#include <queue>
#include <cmath>
#include <complex> // complex<double> a(1.2 , 2.3);// real(): 1.2, imag()2.3
using namespace std;

#define MOD 1000000007
#define ll long long
#define ld long double
#define FOR(i,a,b) for(ll i=(ll)a;i<(ll)b;i++)
#define rep(i,n) FOR(i,0,n)
#define pb push_back
#define mp make_pair
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define rmsame(a) sort(all(a)),a.erase(unique(all(a)), a.end())
#define rmvector(a,b) rep(i,a.size())rep(j,b.size())if(a[i]==b[j]){a.erase(a.begin()+i);i--;break;}
#define pq_pair_tB priority_queue <pair<ll,ll>, vector<pair<ll,ll> > , greater<pair<ll,ll> > >
#define pq_pair_ts priority_queue <pair<ll,ll> > //第二成分の大きさが関係ない
template<typename X> bool exist(vector<X> vec, X item){return find(all(vec), item)!=vec.end();}
ll gcd(ll a, ll b){if(b==0)return a;return gcd(b,a%b);}
ll lcm(ll a, ll b){return a/gcd(a,b)*b;}


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


    ll A, B ;
    ll ans = 0;
    cin >> A >> B ;

    if(A%2 != 0){
        ans = A;
        A++;
    }

    while(A+4 <B){A += 4;}

    for(ll i = A; i <= B ; i++){
        ans ^= i;
    }
    cout << ans << endl;


	//cout << fixed << setprecision(16) << ans << endl;
	return 0;
}


Measured memory_bytes: 256
#include<vector>
#include<iostream>
#include<algorithm>
#include<tuple>
#include<string>
#include<bits/stdc++.h>
using namespace std;
string s;
vector<string> n;

void printVec(vector<string> &vec) {
  cout << "";
  for (auto it = vec.begin(); it != vec.end(); ++it) {
    cout << *it << " ";
  }
  cout << endl;
}
void solve(){
    int K;
    cin>>s>>K;
    for(int i=0;i<s.size();i++){
       int num=s.size()-i; 
        for(int j=1;j<=K;j++){
            n.push_back(s.substr(i,j));
        }
    }
    sort(n.begin(),n.end());
    n.erase(unique(n.begin(),n.end()),n.end());
    cout<<n[K-1]<<endl;
}

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

Measured memory_bytes: 1660
N, M = map(int, input().split())

gridA = [[v for v in input()] for _ in range(N)]
gridB = [[v for v in input()] for _ in range(M)]

for x_A in range(N):
    for y_A in range(N):
        ok = True
        for x_B in range(M):
            for y_B in range(M):
                if x_A+x_B >= N or y_A+y_B >= N:
                    break
                if gridA[x_A+x_B][y_A+y_B] == gridB[x_B][y_B]:
                    continue
                else:
                    ok = False
                    break
            else:
                continue
            break
        else:
            print("Yes")
            exit()
print("No")


Measured memory_bytes: 40560
#include<stdio.h>
int main()
{
    long long int a,b;
    scanf("%lld",&a);
    b=a;
    long long int temp=0;
    while(a!=0)
    {
        temp+=a%10;
        a=a/10;
    }
    if(b%temp==0) printf("Yes\n");
    else printf("No\n");
    return 0;
}


Measured memory_bytes: 128
#include <algorithm>
#include <cassert>
#include <cstring>
#include <iostream>
#include <vector>

using namespace std;

#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i, n) FOR(i, 0, n)
#define TRACE(x) cout << #x << " = " << x << endl
#define _ << " _ " <<

typedef long long llint;

int main(void) {
  char s[30];
  scanf("%s", s);

  int n = strlen(s);
  vector<bool> have(26, false);
  REP(i, n) have[s[i]-'a'] = true;

  if (n < 26) {
    int j = 0;
    while (have[j]) j++;

    printf("%s%c\n", s, (j+'a'));
    return 0;
  }

  int p = 25;
  while (p > 0 && s[p-1] > s[p]) p--;

  if (p == 0) {
    puts("-1");
    return 0;
  }

  assert(s[p-1] < s[p]);
  for (int i = n-1; i >= p; --i) {
    if (s[i] > s[p-1]) {
      swap(s[p-1], s[i]);
      s[p] = '\0';
      puts(s);
      return 0;
    }
  }
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main()
{
	long long n,a,b;
	cin>>n>>a>>b;
	if ((b-a)%2==0)  cout<<abs((b-a))/2<<endl;
	else cout<<min(a-1,n-b)+(abs(b-a)+1)/2<<endl;
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
  double p;
  int n;
  while(cin>>p>>n,n){
    double t=sqrt(p);
    int x=0,y=1,u=1e9,v=1;
    for(int i=1;i<n;i++){
      int l=0,r=n+1,m;
      while(l<r){
    m=(l+r)/2;
    if(t<(1.0*m/i))r=m;
    else l=m+1;
      }
      if(x*i<(r-1)*y)x=r-1,y=i;
      if(r!=n+1&&u*i>v*r)u=r,v=i;
    }
    cout<<u<<'/'<<v<<' '<<x<<'/'<<y<<endl;
  }
  return 0;
}

Measured memory_bytes: 3132
#include <iostream>
#include <cstring>
#include <cstdio>
#include <algorithm>
using namespace std;

int main(){
	char str[10000];
	int len;
	int JOI, IOI;

	while(scanf("%s", str) != EOF){
		len = strlen(str);
		JOI = IOI = 0;
		for(int i = 0; i < len; i++){
			if(str[i] == 'J' && str[i+1] == 'O' && str[i+2] == 'I'){
				JOI++;
			}else if(str[i] == 'I' && str[i+1] == 'O' && str[i+2] == 'I'){
				IOI++;
			}
		}
	
		cout << JOI << endl << IOI << endl;
	}
	return 0;
}

Measured memory_bytes: 1168
N = int(input())
A = list(map(int, input().split()))
tmp = 10**10
minus = 0
zeros = 0
ans = 0
for a in A:
  if a > 0:
    ans += a
    tmp = min(tmp, a)
  elif a == 0:
    zeros += 1
  else:
    a = -a
    ans += a
    minus += 1
    tmp = min(tmp, a)
if minus % 2 == 1 and zeros == 0:
  ans -= tmp*2
print(ans)

Measured memory_bytes: 20016
n=int(input())
d={}
totl=0

for i in range(n):
  s=list(input())
  s.sort()
  t=''.join(s)
  
  if t in d:
    d[t]+=1
  else:
    d[t]=1

for t in d:
  totl+=d[t]*(d[t]-1)/2

print(int(totl))


Measured memory_bytes: 17808
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
/* clang-format off */
#define MOD 1000000007
#define INF 1000000000000000000
#define REP(i, n) for (ll i = 0, i##_len = (n); i < i##_len; ++i)
#define ALL(a) (a).begin(), (a).end()
// #define __DEBUG__
#ifdef __DEBUG__
#define CH_P(a) cout <<"check_point("<<#a<<")" << "\n";
#define DEBUG(x) cout<<#x<<":"<<x<<"\n"
#define DEBUGS(v) cout << #v << ":";for(auto x:v){cout<<x<<" ";}cout<<"\n"
#endif
#ifndef __DEBUG__
#define CH_P(a) 
#define DEBUG(x) 
#define DEBUGS(v) 
#endif
/* clang-format on */

struct edge {
  ll from;
  ll to;
  ll cost;
};

ll bellman_ford(vector<edge> edges, ll v, ll s, ll g) {
  ll e = edges.size();
  vector<ll> cost(v, INF);  // sからiまでのコスト
  cost[s] = 0;

  REP(i, v) {
    REP(j, e) {
      ll to = edges[j].to, from = edges[j].from, c = edges[j].cost;
      //未踏の地へのコストはINFのまま
      if (cost[from] + c < cost[to] && cost[from] != INF) {
        cost[to] = cost[from] + c;
        if (i == v - 1 && to == v - 1) {
          return -1;
        }
      }
    }
  }
  return cost[g];
}

int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  // v=頂点数,e=辺の数,s=始点,g=終点
  ll e, v;
  cin >> v >> e;
  ll s = 0, g = v - 1;
  vector<edge> edges(e);
  REP(i, e) {
    cin >> edges[i].from >> edges[i].to >> edges[i].cost;
    edges[i].from--, edges[i].to--, edges[i].cost *= -1;
  }
  ll ans = bellman_ford(edges, v, s, g);
  if (ans == -1)
    cout << "inf\n";
  else
    cout << -ans << endl;
  return 0;
}


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

int main() {
	int N;
	long long int cnt = 0;
	int A[100000] = {}, B[100000] = {};

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

	for (int i = N - 1; i >= 0; i--) {
		cnt += (B[i] - (A[i] + cnt) % B[i]) % B[i];
	}

	cout << cnt << endl;


	return 0;
}

Measured memory_bytes: 1152
#include<stdio.h>

int main(void){
    char num[1000];
    int sum;
    scanf("%s", num);
    
    while(num[0] != '0'){
        sum = 0;
        for(int i=0; num[i]!='\0'; i++){
            num[i] -= '0';
            sum += num[i];
        }
        printf("%d\n", sum);
        scanf("%s", num);
    }
}


Measured memory_bytes: 2100
n = int(input())
b = list(map(lambda x:int(x),input().split()))
ans = 0
a = [float('inf')]*n
for i in range(1,len(a)-1):
    a[i] = min(b[i-1],b[i])
a[0] = b[0]
a[-1] = b[-1]
print(sum(a))

Measured memory_bytes: 3064
#include <iostream>
#include <iomanip>
#include <string>
#include <sstream>
#include <fstream>
#include <cassert>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <numeric>
#include <utility>
#include <vector>
#include <queue>
#include <map>
#include <set>
#include <unordered_map>
#include <unordered_set>
#include <bitset>
#include <complex>

using namespace std;

using ll = long long;
using ld = long double;
using pii = pair<int, int>;

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

    int n, m, q;
    scanf(" %d %d %d", &n, &m, &q);
    vector<vector<int>> freq(n, vector<int>(n, 0));
    int l, r;
    while (m-- > 0) {
        scanf(" %d %d", &l, &r);
        --l; --r;
        ++freq[l][r];
    }
    vector<vector<int>> ans(n, vector<int>(n, 0));
    for (int i = 0; i < n; ++i) {
        ans[i][i] = freq[i][i];
        for (int j = i + 1; j < n; ++j) {
            ans[i][j] = ans[i][j - 1] + freq[i][j];
        }
    }

    vector<vector<int>> ans2(n, vector<int>(n, 0));
    for (int j = 0; j < n; ++j) {
        ans2[j][j] = ans[j][j];
        for (int i = j - 1; i >= 0; --i) {
            ans2[i][j] = ans2[i + 1][j] + ans[i][j];
        }
    }

    while (q-- > 0) {
        scanf(" %d %d", &l, &r);
        --l; --r;
        printf("%d\n", ans2[l][r]);
    }

    return 0;
}


Measured memory_bytes: 3968
import sys
from collections import deque

def solve():
    input = sys.stdin.readline
    N = int(input())
    A = [[int(a) for a in input().split()] for _ in range(2)]
    move = ((1, 0), (0, 1))
    maxN = [[0 for _ in range(N)] for i in range(2)]
    q = deque()
    q.append((0, 0, A[0][0]))
    while q:
        nx, ny, np = q.popleft()
        maxN[nx][ny] = max(maxN[nx][ny], np)
        for dx, dy in move:
            if 0 <= nx + dx < 2 and 0 <= ny + dy < N:
                q.append((nx + dx, ny + dy, maxN[nx][ny] + A[nx + dx][ny + dy]))
    print(maxN[1][N - 1])


    return 0

if __name__ == "__main__":
    solve()

Measured memory_bytes: 3316
#include <iostream>
#include <fstream>
#include <vector>
#include <cmath>
#include <ctime>
#include <cassert>
#include <cstdio>
#include <queue>
#include <set>
#include <map>
#include <fstream>
#include <cstdlib>
#include <climits>
#include <string>
#include <cstring>
#include <algorithm>
#include <numeric>

using namespace std;
#define fast ios::sync_with_stdio(false);cin.tie(nullptr);
#define pb push_back
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#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 ford(i, n) for (int i = (int)(n) - 1; i >= 0; --i)

typedef long long ll;
typedef pair<ll, ll> pll;
typedef vector<ll> vi;
//const int mod=1e9+7;
//const ll inf = (ll)1e16 + 7;
const int N=1e5+7;

int main(){
    fast;
    string s;
    cin>>s;
    forn(i,19){
        if(s[i]==',') s[i]=' ';
    }
    cout<<s<<endl;
    return 0;
}


Measured memory_bytes: 256