akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
using namespace std;
int n, m, mx, midx;
int a[333][333], idx[333], cnt[333], used[333];

int main() {
  cin.tie(0); ios_base::sync_with_stdio(false);
  cin >> n >> m;
  for(int i=0; i < n; ++i) for(int j=0; j < m; ++j) cin >> a[i][j];

  int ans = 1e9;
  while(true) {
    bool update = false;
    mx = 0, midx = 0;
    for(int i = 1; i <= m; ++i) cnt[i] = 0;
    for(int i = 0; i < n; ++i) {
      if(idx[i] == m) continue;
      else {
        ++cnt[a[i][idx[i]]];
        update = true;
      }
    }
    if(!update) break;

    for(int i = 1; i <= m; ++i) {
      if(mx < cnt[i]) {
        mx = cnt[i];
        midx = i;
      }
    }
    used[midx] = 1;
    for(int i = 0; i < n; ++i) while(used[a[i][idx[i]]]) ++idx[i];
    ans = min(ans, mx);
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < n; i++)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pi;
typedef pair<pi, pi> pp;
typedef pair<ll, ll> pl;
const double EPS = 1e-9;
const ll MOD = 1000000007;
const int inf = 1 << 30;
const ll linf = 1LL << 60;

const int M = 13;

char str[100000];
string s;
ll t = 1, ans;
ll dp[2][13];
int ho = 0, ge = 1;

int main() {
    /*
    cin.tie(0);
    ios::sync_with_stdio(false);
    cin >> s;
    */
    scanf("%s",str);
    s=str;
    dp[ho][0] = 1;
    for (int i = (int)s.size()-1; i >= 0; i--) {
        rep(j,M) dp[ge][j] = 0;
        if (s[i] != '?') {
            int x = s[i]-'0';
            rep(j,M) dp[ge][(t*x+j)%M] = dp[ho][j];
        } else {
            rep(j,10) {
                rep(k,M) dp[ge][(t*j+k)%M] += dp[ho][k];
            }
            rep(j,M) dp[ge][j] %= MOD;
        }
        t = t * 10 % M;
        swap(ho,ge);
    }
    printf("%d\n",dp[ho][5]);
    //cout << dp[ho][5] << endl;
}


Measured memory_bytes: 384
# N, K = 4, 5
# ARR = [3, 2, 4, 1]

# N, K = 6, 727202214173249351
# ARR = [6, 5, 2, 5, 3, 2]

import sys
sys.setrecursionlimit(100000000)

N,K = map(int,input().split())
ARR = list(map(int,input().split()))
NodeStatus = [False] * N
NodeFirstSteps = [0] * N
L = 0
STARTLINDEX = 0
OrderARR = []


def dfs(pos, arr, step):
    if NodeStatus[pos] == True:
        L = (step - NodeFirstSteps[pos])
        STARTLINDEX = NodeFirstSteps[pos]
        print(OrderARR[(K - STARTLINDEX) % L + STARTLINDEX] + 1)
        return

    if step == K:
        print(pos+1)
        return

    OrderARR.append(pos)
    NodeStatus[pos] = True
    NodeFirstSteps[pos] = step
    dfs(arr[pos] - 1, arr, step + 1)


dfs(0, ARR, 0)


Measured memory_bytes: 168060
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i = 0;i<n;i++)
#define erep(i,n) for(int i = 0;i<=n;i++)
#define rep1(i,n) for(int i = 1;i<n;i++)
#define erep1(i,n) for(int i = 1;i<=n;i++)
typedef long long ll;
#define vint vector<int>
#define vvint vector<vector<int>>
#define vstring vector<string>
#define vdouble vector<double>
#define vll vector<ll>:
#define vbool vector<bool>
#define INF 100000000000000009
#define int long long
using P = pair<int,int>;
signed main(){
  int n,k,s;
  cin >> n >> k >> s;
  rep(i,k){
    cout << s << " ";
  }
  int num = 1;
  while(s % num == 0){
    num++;
  }
  rep(i,n-k){
    cout << num << " ";
  }
}

Measured memory_bytes: 1280
#include<iostream>
#include<vector>
#include<algorithm>
#include<cctype>
#include<utility>
#include<string>
#include<cmath>
#include<cstring>
#include<queue>
#include<map>
#include<set>

#define REP(i, n) for(int i = 0;i < n;i++)
#define REPR(i, n) for(int i = n;i >= 0;i--)
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define FORR(i, m, n) for(int i = m;i >= n;i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define llong long long
#define pb(a) push_back(a)

using namespace std;

typedef long long int ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;


template<typename T>
vector<T> make_v(size_t a) { return vector<T>(a); }
template<typename T, typename... Ts>
auto make_v(size_t a, Ts... ts) {
	return vector<decltype(make_v<T>(ts...))>(a, make_v<T>(ts...));
}
template<typename T, typename V>
typename enable_if<is_class<T>::value == 0>::type
fill_v(T& t, const V& v) { t = v; }
template<typename T, typename V>
typename enable_if<is_class<T>::value != 0>::type
fill_v(T& t, const V& v) {
	for (auto& e : t) fill_v(e, v);
}


#define ARRAY_MAX 100005
const ll INF = 1e9;
const ll MOD = 1e9 + 7;

int dx[4] = { 1,0,0,-1 };
int dy[4] = { 0,1,-1,0 };




/******************************************************************************************/





int main() {

	

	int a, b, c;
	cin >> a >> b >> c;
	cout << max(0, (c - (a - b))) << endl;





	return 0;
}


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

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

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

// 4近傍、8近傍
int dx[] = {1, 0, -1, 0, 1, -1, -1, 1};
int dy[] = {0, 1, 0, -1, 1, 1, -1, -1};

int main() {
  // 入力
  int a, b, k;
  cin >> a >> b >> k;

  // 解答
  int i;
  for (i = a; i <= min(a + k - 1, b); i++) {
    cout << i << endl;
  }
  for (int j = max(i, b - k + 1); j <= b; j++) {
    cout << j << endl;
  }

  return 0;
}


Measured memory_bytes: 384
import sys
import decimal # 10進法に変換，正確な計算

def input():
    return sys.stdin.readline().strip()

def main():
    n = int(input())
    s = input()
    if n % 2 != 0:
        print("No")
        return
    for i in range(n//2):
        if s[i] != s[i + n//2]:
            print("No")
            return
    print("Yes")
    
    
main()


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

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

    vector<long> a(n);
    for(auto &e: a) cin >> e;

    vector<long> b(n+1);
    for(long i=1; i<=n; i++)
        b[i] = b[i-1] + a[i-1];


    long r = 1e18;
    for(long i=2; i<=n-2; i++) {
        // 0 1 ... i-1 | i ... n-1
        long ls = b[i], rs = b[n] - b[i];
        for(long lls : {
                *prev(upper_bound(b.begin(), b.begin()+i+1, ls/2)),
                *lower_bound(b.begin(), b.begin()+i+1, ls/2),
                })
        for(long rls : {
                *prev(upper_bound(b.begin()+i+1, b.end(), ls + rs/2)) - ls,
                *lower_bound(b.begin()+i+1, b.end(), ls + rs/2) - ls,
                }) {
            long lrs = ls - lls;
            long rrs = rs - rls;

            long mx = max(max(lls, lrs), max(rls, rrs));
            long mn = min(min(lls, lrs), min(rls, rrs));

            r = min(r, mx-mn);
        }
    }
    cout << r << endl;
}


Measured memory_bytes: 3328
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.StringTokenizer;
import java.io.IOException;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.InputStream;

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

    static class TaskB {
        public void solve(int testNumber, InputReader in, PrintWriter out) {
            int n = in.nextInt();
            int m = in.nextInt();
            int[][] a = new int[m][n];
            for (int i = 0; i < n; ++i) {
                for (int j = 0; j < m; ++j) {
                    a[in.nextInt() - 1][i] = j;
                }
            }
            boolean[] removed = new boolean[m];
            int ans = Integer.MAX_VALUE;
            for (int rep = 0; rep < m; ++rep) {
                int[] mins = new int[m];
                for (int i = 0; i < n; ++i) {
                    int min = Integer.MAX_VALUE;
                    int mj = -1;
                    for (int j = 0; j < m; ++j)
                        if (!removed[j]) {
                            if (a[j][i] < min) {
                                min = a[j][i];
                                mj = j;
                            }
                        }
                    ++mins[mj];
                }
                int maxMin = -1;
                int mj = -1;
                for (int j = 0; j < m; ++j)
                    if (mins[j] > maxMin) {
                        maxMin = mins[j];
                        mj = j;
                    }
                ans = Math.min(ans, maxMin);
                removed[mj] = true;
            }
            out.println(ans);
        }

    }

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

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

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

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

    }
}



Measured memory_bytes: 30172
#include<bits/stdc++.h>
#define endl "\n"
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define MOD 1000000007
#define MOD9 1000000009
#define pi 3.1415926535
#define ms(s, n) memset(s, n, sizeof(s))
#define prec(n) fixed<<setprecision(n)
#define eps 0.000001
#define all(v) v.begin(), v.end()
#define allr(v) v.rbegin(), v.rend()
#define forr(i,p,n) for(ll i=p;i<n;i++)
#define MAXN 500003
typedef long long ll;
inline ll mod(ll x,ll n)
{
    if(x<n)
    {
        return x;
    }
    return x-n;
}
using namespace std;
ll mult(ll a,ll b, ll p=MOD){return ((a%p)*(b%p))%p;}
ll add(ll a, ll b, ll p=MOD){return (a%p + b%p)%p;}
ll fpow(ll n, ll k, ll p = MOD) {ll r = 1; for (; k; k >>= 1) {if (k & 1) r = r * n%p; n = n * n%p;} return r;}
ll inv(ll a, ll p = MOD) {return fpow(a, p - 2, p);}
ll inv_euclid(ll a, ll m = MOD){ll m0 = m;ll y = 0, x = 1;if (m == 1)return 0;while (a > 1){ll q = a / m;ll t = m;m = a % m, a = t;t = y;y = x - q * y;x = t;}if (x < 0)x += m0;return x;}



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

vector<ll>v;
 ll sum=0,act=0,k,n,q,f;
ll w;
cin>>n>>w;
ll wt[n],val[n];
forr(i,0,n)cin>>wt[i]>>val[i];
ll dp[n+1][w+1];
forr(i,0,w+1)dp[0][i]=0;
forr(i,0,n+1)dp[i][0]=0;
forr(i,1,n+1)
{
    forr(j,1,w+1)
    {
        if(j-wt[i-1]>=0)dp[i][j]=max(val[i-1]+dp[i-1][j-wt[i-1]],dp[i-1][j]);
        else dp[i][j]=max(dp[i-1][j],dp[i][j-1]);
    }
}
cout<<dp[n][w]<<endl;

return 0;
}


Measured memory_bytes: 82420
#include <bits/stdc++.h>
#define owo(i,a, b) for(int i=(a);i<(b); ++i)
#define uwu(i,a, b) for(int i=(a)-1; i>=(b); --i)
#define senpai push_back
#define ttgl pair<int, int>
#define ayaya cout<<"ayaya~"<<endl
 
using namespace std;
/*#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
gp_hash_table<int, int> mp;*/
using ll = long long;
using ld = long double;
const ll MOD = 998244353;
int gcd(int a,int b){return b?gcd(b,a%b):a;}
ll binpow(ll a,ll b){ll res=1;while(b){if(b&1)res=(res*a)%MOD;a=(a*a)%MOD;b>>=1;}return res;}
ll modInv(ll a){return binpow(a, MOD-2);}
const double PI = acos(-1);
const double eps = -1e6;
const int INF = 0x3f3f3f3f;
const int NINF = 0xc0c0c0c0;
const ll INFLL = 0x3f3f3f3f3f3f3f3f;
const ll NINFLL = 0xc0c0c0c0c0c0c0c0;
ttgl arr[19];
int dp[1<<18][19];
int n;
int main()
{   
    //freopen("file.in", "r", stdin);
    //freopen("file.out", "w", stdout);
    mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
    cin.tie(0)->sync_with_stdio(0);
    cin>>n;
    memset(dp, INF, sizeof(dp));
    owo(i, 0, n) {
        cin>>arr[i].first;
    }
    owo(i, 0, n) {
        cin>>arr[i].second;
    }
    owo(i, 0, n) {
        dp[1<<i][i] = i;
    }
    owo(msk, 1, 1<<n) {
        int num = __builtin_popcount(msk);
        owo(j, 0, n) {
            if(dp[msk][j]==INF)continue;
            int last = abs(j-num-1);
            if(last&1) {
                last = arr[j].second;
            }else {
                last = arr[j].first;
            }
            int cnt = 0;
            owo(k, 0, n) {
                if((1<<k)&msk)continue;
                cnt++;
                int val = abs(k-num);
                if(val&1) {
                    val = arr[k].second;
                }else {
                    val = arr[k].first;
                }
                if(val<last)continue;
                dp[msk|(1<<k)][k] = min(dp[msk|(1<<k)][k], dp[msk][j] + cnt-1);
            }
        }
    }
    int best = INF;
    owo(i, 0, n) {
        best = min(best, dp[(1<<n)-1][i]);
    }
    cout<<(best==INF ? -1 : best)<<'\n';
    return 0;
}


Measured memory_bytes: 23040
#include <bits/stdc++.h>
#define rep(i,a,n) for(int i=a;i<n;i++)
#define repb(i,a,b) for(int i=a;i>=b;i--)
#define all(a) a.begin(),a.end()
#define o(a) cout<<a<<endl
#define int long long
#define fi first
#define se second
using namespace std;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int,int> pii;

int dp[110][3][2];
int num[110];

signed main(){
	int n,k;
	cin>>n>>k;
	memset(num,-1,sizeof(num));
	//rep(i,0,110) rep(j,0,3) rep(k,0,2) dp[i][j][k]=-1;
	rep(i,0,k){
		int a,b;
		cin>>a>>b;
		a--; b--;
		num[a]=b;
	}
	if(num[0]==-1) rep(i,0,3) dp[0][i][0]=1;
	else dp[num[0]][0][0]=1;

	rep(i,1,n){
		rep(j,0,3){
			if(!(num[i]==-1||num[i]==j)) continue;
			dp[i][j][1]=(dp[i][j][1]+dp[i-1][j][0])%10000;
			rep(k,0,3){
				if(j==k) continue;
				dp[i][j][0]=(dp[i][j][0]+dp[i-1][k][0]+dp[i-1][k][1])%10000;
			}
		}
	}
	int ans=0;
	rep(i,0,3) rep(j,0,2) ans+=dp[n-1][i][j];
	o(ans%10000);
}

Measured memory_bytes: 1160
/*suri_kumkaran*/

#include <bits/stdc++.h>

using namespace std;

#define UB upper_bound
#define LB lower_bound
#define BS binary_search
#define MP make_pair
#define EB emplace_back
#define endl "\n"
#define PI 3.1415926535897932384626433832795
#define MOD 1000000007
#define F first
#define S second
#define ALL(a) (a).begin(),(a).end()
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0)

typedef long long int int64;
typedef vector<int64> VI64;
typedef vector<pair<int64,int64>> VII64;
typedef vector<string> VS;
typedef vector<vector<int64>> VVI;

int64 dp[1002][10002];

int main()
{
    IOS;
    int64 T=1;
    //cin>>T;
    while(T--)
    {
        int64 h,n,i,j;
        cin>>h>>n;
        int64 a[n+1],b[n+1];
        for(i=1;i<=n;i++)
        {
            cin>>a[i]>>b[i];
        }
        for(i=0;i<=n;i++)
        {
            for(j=1;j<=h;j++)
            {
                dp[i][j]=1e12;
            }
        }
        for(i=1;i<=n;i++)
        {
            for(j=0;j<=h;j++)
            {
       
                dp[i][j]=min(dp[i-1][j],dp[i][max((int64)0,j-a[i])]+b[i]);
            }
        }
        int64 ans=1e12;
        for(i=0;i<=n;i++)
        {
            ans=min(ans,dp[i][h]);
        }
        cout<<ans;

    }

    return 0;
}

Measured memory_bytes: 78464
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cmath>
#include <cstdlib>
#include <cstring>
#include <deque>
#include <fstream>
#include <iomanip>
#include <iostream>
#include <limits>
#include <map>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <sstream>
#include <stack>
#include <unordered_map>
#include <unordered_set>
#include <vector>

#define len(X) ((int)(X).size())

#ifdef __LOCAL
#define DBG(X) cout << #X << "=" << (X) << '\n';
#define SAY(X) cout << (X) << '\n';
#else
#define DBG(X)
#define SAY(X)
#endif

#define M_PI       3.14159265358979323846

using namespace std;

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

const int INT_INF = (int)(2e9);
const ll  LL_INF = (ll)(2e18);

const int NIL = -1;
static mt19937 _g(time(nullptr));

std::string pad(int num)
{
    char buffer[4];
    std::snprintf(buffer, sizeof(buffer), "%03d", num);
    return buffer;
}

inline ll randint(ll a, ll b) { ll w = (_g() << 31LL) ^ _g(); return a + w % (b - a + 1); }
inline void fast_io() { ios_base::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr); };
template<typename T> inline T sign(T x) { return T(x > 0) - T(x < 0); }
template<typename T, typename S> inline ostream& operator<<(ostream& os, const pair<T, S> p) { cout << "[" << p.first << ";" << p.second << "]"; return os; }
template<typename T> inline ostream& operator<<(ostream& os, const vector<T>& v) { for (auto el : v) cout << el << " "; return os; }
template<typename T> inline T fetch() { T ret; cin >> ret; return ret; }
template<typename T> inline vector<T> fetch_vec(int sz) { vector<T> ret(sz); for (auto& elem : ret) cin >> elem; return ret; }

#ifdef _MSC_VER
#  include <intrin.h>
#  define __builtin_popcount __popcnt
#endif

int solve()
{
    ll a, b, k;
    cin >> a >> b >> k;

    if (k >= a)
    {
        k = k - a;
        a = 0;
    }
    else
    {
        a = a - k;
        k = 0;
    }

    if (k > 0)
    {
        if (k >= b)
        {
            b = 0;
        }
        else
        {
            b = b - k;
        }
    }

    cout << a << " " << b << endl;

    return 0;
}

int main()
{
    solve();

    return 0;
}

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

void printarray(int a[], int n){
	for (int i=0; i<n; i++){
		if (i==n-1){
			cout << a[i] << endl;
		}
		else{
			cout << a[i] << ' ';
		}
	}

}

void insertionsort(int a[], int n){
	for (int i=0; i<n; i++){
		int v = a[i];
		int j = i-1;
		while (j >= 0 && a[j] > v){
			a[j+1] = a[j];
			j--;
		}
		a[j+1] = v;
		printarray(a,n);
	}
}

int gcd(int a, int b){
	if (b==0){
		return a;
	}
	else{
		return gcd(b, a%b);
	}
}

bool prime(int n){
	if (n==2){
		return true;
	}
	else{
		int lim;
		lim = int(pow(n,0.5))+1;
		for (int i=2; i<lim; i++){
			if (n % i == 0){
				return false;
			}
		}
		return true;
	}
}

void bubblesort(int a[], int n, int& cnt){
	bool flag = true;
	while (flag){
		flag = false;
		for (int j=n-1; j>=0; j--){
			if (a[j]<a[j-1]){
				int tmp = a[j];
				a[j] = a[j-1];
				a[j-1] = tmp;
				cnt++;
				flag = true;

			}
		}
	}

}


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

	bubblesort(a,n,cnt);
	printarray(a,n);
	cout << cnt << endl;


	return 0;
}


Measured memory_bytes: 3128
#pragma GCC optimize("O3")
#include<bits/stdc++.h>
#define rc(x) return cout<<x<<endl,0
#define pb push_back
#define in insert
#define er erase
#define fr first
#define sc second
typedef long long ll;
const long long llinf=LLONG_MAX;
const int inf=INT_MAX;
const int nmax=1e5+5;
const int mod=1e9+7;
using namespace std;
int n,m,i,j,t,nr,x[]={-1,-1,-1,0,0,1,1,1},y[]={-1,0,1,-1,1,-1,0,1};
char ans[51][51],c[51][51];
int main()
{
    //freopen("sol.in","r",stdin);
	//freopen("sol.out","w",stdout);
	ios_base::sync_with_stdio(false);cin.tie(0);cerr.tie(0);cout.tie(0);
    cin>>n>>m;
    for(i=1;i<=n;i++)for(j=1;j<=m;j++)cin>>c[i][j];
    for(i=1;i<=n;i++)
     for(j=1;j<=m;j++)
     {
        if(c[i][j]=='.')
        {
            nr=0;
            for(t=0;t<=7;t++)if(c[i+x[t]][j+y[t]]=='#')nr++;
            ans[i][j]=(nr+'0');
        }
        else ans[i][j]='#';
     }
    for(i=1;i<=n;i++)
    {
        for(j=1;j<=m;j++)cout<<ans[i][j];
        cout<<endl;
    }
    return 0;
}


Measured memory_bytes: 256
n = int(input())
dic = {0: 0}
ans = 0
for _ in range(n):
    si = int(input())
    tmp = {}
    for k, v in dic.items():
        tmp[(k + si) % 10] = v + si
    for k, v in tmp.items():
        if k in dic:
            dic[k] = max(dic[k], v)
        else:
            dic[k] = v
        if 0 < k:
            ans = max(ans, v)

print(ans)

Measured memory_bytes: 38576
#include<bits/stdc++.h>
using ll  = long long;
#define int ll
#define rep(i,n) for(int i=0;i<n;i++)
#define loop(i,s,n) for(int i=s;i<n;i++)
#define erep(e,v) for(auto && e :v)
#define all(in) in.begin(), in.end()
#define MP make_pair
#define INF (sizeof(int) == 4 ? (int)1e9:(int)1e18)
#define EPS 0.0000000001
using namespace std;
template<class T, class S> void cmin(T &a, const S &b) { if (a > b)a = b; }
template<class T, class S> void cmax(T &a, const S &b) { if (a < b)a = b; }
template<typename Head, typename Value> auto vectors(const Head &head, const Value &v) { return vector<Value>(head, v); }
template<typename Head, typename... Tail> auto vectors(Head x, Tail... tail) { auto inner = vectors(tail...); return vector<decltype(inner)>(x, inner); }
template<class T> void join(T &a){int t = 0;for(auto itr :a){if(t++)cout << " "; cout << itr;} cout <<endl; }
using ld  = long double;
using pii = pair<int,int>;
using piii = pair<int,pii>;
int W,H;
int dx[]={0,0,1,-1}, dy[]={1,-1,0,0};
bool valid(int x,int y){return (0<=x&&x<W)&&(0<=y&&y<H);}
string alpha = "abcdefghijklmnopqrstuvwxyz";
signed main(){
    string s; cin >> s;
    int k; cin >> k;
    map<char,int>mp;
    for(auto c : alpha){
        mp[c] = 26 - (c - 'a');
    }
    for(auto && c : s){
        if(c == 'a')continue;
        if(k - mp[c] >= 0){
            k -= mp[c];
            c = 'a';
        } else {
            
        }
    }
    int n = s.size();
    k %= 26;
    s[n-1] = alpha[(k + s[n-1] - 'a')%26];
    cout << s << endl;
}




Measured memory_bytes: 512
#include <iostream>
#include<bits/stdc++.h>
#define ll long long
#define int long long
using namespace std;
//const ll INF=1018LL+5;
const int MAX=1e5+5;
vector<int> graph[MAX];
int in_degree[MAX];
int dist[MAX];
vector<bool>vis(MAX,false);
template<typename T> void max_self(T& a, T b) {//template of anything
    a = max(a, b);
}


void min_self(ll& a, ll b) {
    a = min(a, b);
}
void dfs(int a)
{
    if(vis[a])return;
    vis[a]=true;
  for(auto b: graph[a])
  {
      dist[b]=max(dist[b],dist[a]+1);
      --in_degree[b];
      if(in_degree[b]==0)
        dfs(b);

  }

}
//G -Longest Path
int LongestPath()
{
  int n;cin>>n;
   int m;cin>>m;
   while(m--)
   {
       int u,v;
       cin >> u >> v;
       graph[u].push_back(v);
       ++in_degree[v];
   }
   for(int i=1;i<=n;i++)
   {

       if(!vis[i] && in_degree[i]==0)
        dfs(i);
   }
   int answer=0;
   for(int i=1;i<=n;i++)
    answer=max(answer,dist[i]);
   cout<<answer;


}
int32_t main() {
   LongestPath();
    return 0;
}


Measured memory_bytes: 10368
#pragma GCC optimize ("O3")
#pragma GCC target ("tune=native")
#pragma GCC target ("avx")

#include <bits/stdc++.h>

// 汎用マクロ
#define ALL_OF(x) (x).begin(), (x).end()
#define REP(i,n) for (long long i=0, i##_len=(n); i<i##_len; i++)
#define RANGE(i,is,ie) for (long long i=(is), i##_end=(ie); i<=i##_end; i++)
#define DSRNG(i,is,ie) for (long long i=(is), i##_end=(ie); i>=i##_end; i--)
#define UNIQUE(v) { sort((v).begin(), (v).end()); (v).erase(unique((v).begin(), (v).end()), (v).end()); }
template<class T> bool chmax(T &a, const T &b) {if (a < b) {a = b; return true;} return false; }
template<class T> bool chmin(T &a, const T &b) {if (a > b) {a = b; return true;} return false; }
#define INF 0x7FFFFFFF
#define LINF 0x7FFFFFFFFFFFFFFFLL
#define Yes(q) (q ? "Yes" : "No")
#define YES(q) (q ? "YES" : "NO")
#define DUMP(q) cerr << "[DEBUG] " #q ": " << (q) << " at " __FILE__ ":" << __LINE__ << endl
#define DUMPALL(q) { cerr << "[DEBUG] " #q ": ["; REP(dumpall_i, (q).size()) { cerr << q[dumpall_i] << (dumpall_i == (q).size() - 1 ? "" : ", "); } cerr << "] at " __FILE__ ":" << __LINE__ << endl; }
template<class T> T gcd(const T &a, const T &b) { return a < b ? gcd(b, a) : b ? gcd(b, a % b) : a; }
template<class T> T lcm(const T &a, const T &b) { return a / gcd(a, b) * b; }

// gcc拡張マクロ
#define popcount __builtin_popcount
#define popcountll __builtin_popcountll

// エイリアス
using  ll = long long;
using ull = unsigned long long;
using  ld = long double;
using namespace std;

// モジュール


// 処理内容
int main() {
    
    ll h, w; cin >> h >> w;
    vector<string> c(h);
    REP(i, h) cin >> c[i];
    
    vector<pair<ll, ll>> cand;
    REP(i, h) REP(j, w) {
        if (c[i][j] == 'B') {
            cand.emplace_back(i, j);
        }
    }
    
    ll n = cand.size();
    ll ans = 0;
    REP(i, n) RANGE(j, i+1, n-1) {
        chmax(ans, abs(cand[i].first - cand[j].first) + abs(cand[i].second - cand[j].second));
    }
    cout << ans << endl;

}


Measured memory_bytes: 3248
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <map>
#include <numeric>
using namespace std;
typedef long long ll;

int main(){
   int n;cin>>n;
   vector<int> v(n),a(n),b(n);
   for(int i=0;i<n;i++)cin>>v[i];
   a[0]=v[0];b[n-1]=v[n-1];
   for(int i=1;i<n;i++)a[i]=max(a[i-1],v[i]);
   for(int i=n-2;i>=0;i--)b[i]=max(b[i+1],v[i]);
   cout<<b[1]<<endl;
   for(int i=1;i<n-1;i++)cout<<max(a[i-1],b[i+1])<<endl;
   cout<<a[n-2]<<endl;
}

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

#define rep(i, n) for(ll i = 0; i < (ll)(n); i++)
template<typename T> void view(T cont) {std::cout << cont << std::endl;}
template<typename T> void view(T* cont, ll sz) {rep(i, sz) std::cout << cont[i] << " "; std::cout << std::endl;}
template<typename T> void view(const std::vector<T>& v) {for (const auto& f: v) std::cout << f << " "; std::cout << std::endl;}
template<typename T> void view(const std::vector<std::vector<T> >& vv) { for (const auto& v: vv) {view(v);}}
const long long INF = 1LL<<60;
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(){
    int A, B, K; cin >> A >> B >> K;
    int minAB = min(A, B);
    int count = 0;
    for (int i = minAB; i >= 1; i--) {
        if (A % i == 0 && B % i == 0) {
            count++;
            // cout << i << endl;
            if (count == K) {
                cout << i << endl;
                break;
            }
        }
    }
}

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

using namespace std;
#define REP(i, n) for(ll i = 0;i < n;i++)
#define ll long long
#define MOD 1000000007LL
#define llMAX 9223372036854775807LL
#define llMIN -9223372036854775808LL
using vi = vector<ll>; // intの1次元の型に vi という別名をつける
using vvi = vector<vi>; // intの2次元の型に vvi という別名をつける

ll D=365;
vi c(26);
vi last(26,-1);
vvi dat(D, vi(26));  // N * M の2次元配列
vvi AAlist(D, vi(D));  // N * M の2次元配列




ll calcscore(vi &Alist)
{
  for(ll i=0;i<26;i++){
    last[i]=-1;
  }
  

  ll sc=0;
  ll sct=0;
  ll l;
  ll id;
  ll factscore=0;
  for(ll i=0;i<D;i++){
    sc=-922337203685477580LL;
    for(ll j=0;j<26;j++){
      if (Alist[i]==j)continue;
      l=i-last[j];
      sct=l*c[j];
      factscore-=sct;
    }

    id=Alist[i];
    factscore+=dat[i][id];
    last[id]=i;
  }

  return factscore;
}



void makeseed(int xid,int startoffset)
{

  ll sc=0;
  ll sct=0;
  ll maxid=-1;
  ll factscore=0;
  
  for(ll i=0;i<26;i++){
    last[i]=startoffset-1;
  }

  for(ll i=startoffset;i<D;i++){
    sc=-922337203685477580LL;
    maxid=0;
    
    for(ll j=0;j<26;j++){
      ll l=i-last[j];
      
      l*=(l-1-l*5/6);
      sct=l*c[j];
      factscore-=sct;
      sct=dat[i][j]+sct;
      if (sc<sct){
        sc=sct;
        maxid=j;
      }
    }
    factscore+=sc;
    last[maxid]=i;
    AAlist[startoffset][i]=maxid;
    //cout<<(maxid+1)<<endl;
  }


}





int main(){
  ll ans=0;
  ll debug=0;//本番では0に
  cin>>ans;
  ll factscore=0;


  for(ll i=0;i<26;i++){
    cin>>c[i];
  }
  for(ll i=0;i<D;i++){
    for(ll j=0;j<26;j++){
      cin>>dat[i][j];
    }
  }


  for(ll i=0;i<100;i++){
    makeseed(0,i);
  }
  



  for(ll i=1;i<100;i++){
    for(ll j=0;j<i;j++){
      AAlist[i][j]=AAlist[i-1][j];
    }
  }
  
  ll score=-922337203685477580LL;
  ll ansid=0;




  score=-922337203685477580LL;
  
  for(ll i=0;i<100;i++){
    if (score<calcscore(AAlist[i])){
      score=calcscore(AAlist[i]);
    }
  }




  random_device rnd;
  ll loopcnt=0;
  for(ll i=100;i<D;i++){
    ll aaa=rnd()%D;
    ll ref1=rnd()%100;
    ll ref2=rnd()%100;
    loopcnt++;
    if (loopcnt>120000)break;
    for(ll j=0;j<aaa;j++){
      AAlist[i][j]=AAlist[ref1][j];
    }
    
    for(ll j=aaa;j<D;j++){
      AAlist[i][j]=AAlist[ref2][j];
    }

    if (score>calcscore(AAlist[i]))
    {
      i--;
      continue;
    }
    
  }


















  score=-922337203685477580LL;
  ansid=0;
  for(ll i=0;i<D;i++){
    if (score<calcscore(AAlist[i])){
      score=calcscore(AAlist[i]);
      ansid=i;
    }

    if (debug==1){
      cout<<calcscore(AAlist[i])<<endl;
    }

  }



  if (debug==0)
  {
    for(ll i=0;i<D;i++){
      cout<<(AAlist[ansid][i]+1)<<endl;
    }
  }else{
    cout<<calcscore(AAlist[ansid])<<endl;
  }
    

  return 0;
}

/*
1万
36万
92万
*/

Measured memory_bytes: 4772
#include <stdio.h>
#include<stdlib.h>
#define N 2000000

struct P{
  int key;
  struct P *prev,*next;
};
typedef struct P* node;
node F,L;

void insert(int x) {
  node z = F->next;
  node v = malloc(sizeof(struct P));
  v->key = x;
  F->next = v;
  v->prev = F;
  v->next = z;
  z->prev = v;
}

void delete(int x) {
  node z = F;
  while(z -> key != x && z != L) z = z->next;
  node l=z->prev,r=z->next;
  l->next = r;
  r->prev = l;
}

void deleteFirst() {
  node z = F->next->next;
  F->next = z;
  z->prev = F;
}

void deleteLast() {
  node z = L->prev->prev;
  L->prev = z;
  z->next = L;
}

int main() {
  int n;
  char c[10];
  int x;

  scanf("%d",&n);
  if(n > N)exit(1);

  F = malloc(sizeof(struct P));
  L = malloc(sizeof(struct P));
  F->next=L;F->prev=F;
  L->prev=F;L->next=L;
  while(n--) {
    scanf("%s",c);
    if(c[0] == 'i') {
      scanf("%d",&x);
      insert(x);
    } else if(c[6] == 'F') deleteFirst();
    else if(c[6] == 'L') deleteLast();
    else {
      scanf("%d",&x);
      delete(x);
    }
  }
  node z = F -> next;
  while(z != L) {
    if(z != F -> next) printf(" ");
    printf("%d",z -> key);
    z = z -> next;
  }
  printf("\n");
  return 0;
}



Measured memory_bytes: 36112
#include <bits/stdc++.h>   
#define rep(i, n) for(long long int i = 0; i < n; i++)
#define _rep(i, m, n) for(long long int i = m; i < n; i++)
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
const ll mod = 1000000007;
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
string Yes[2] = {"Yes", "No"};
     
ll gcd(ll A, ll B){
    if(B == 0)return A;
    return gcd(B, A % B);
}
ll lcm(ll A, ll B){
    return A * B / gcd(A, B);
}
template <typename T>
T pow(T a, ll n, T e = 1) {
    T ret = e;
    while (n) {
        if (n & 1) ret *= a;
        a *= a;
        n >>= 1;
    }
    return ret;
}
 
template <int mod>
struct ModInt {
    int x;
    ModInt() : x(0) {}
    ModInt(long long x_) {
        if ((x = x_ % mod + mod) >= mod) x -= mod;
    }
    ModInt& operator+=(ModInt rhs) {
        if ((x += rhs.x) >= mod) x -= mod;
        return *this;
    }
    ModInt& operator-=(ModInt rhs) {
        if ((x -= rhs.x) < 0) x += mod;
        return *this;
    }
    ModInt& operator*=(ModInt rhs) {
        x = (unsigned long long)x * rhs.x % mod;
        return *this;
    }
    ModInt& operator/=(ModInt rhs) {
        x = (unsigned long long)x * rhs.inv().x % mod;
        return *this;
    }
 
    ModInt operator-() const { return -x < 0 ? mod - x : -x; }
    ModInt operator+(ModInt rhs) const { return ModInt(*this) += rhs; }
    ModInt operator-(ModInt rhs) const { return ModInt(*this) -= rhs; }
    ModInt operator*(ModInt rhs) const { return ModInt(*this) *= rhs; }
    ModInt operator/(ModInt rhs) const { return ModInt(*this) /= rhs; }
    bool operator==(ModInt rhs) const { return x == rhs.x; }
    bool operator!=(ModInt rhs) const { return x != rhs.x; }
    ModInt inv() const { return pow(*this, mod - 2); }
 
    friend ostream& operator<<(ostream& s, ModInt<mod> a) {
        s << a.x;
        return s;
    }
    friend istream& operator>>(istream& s, ModInt<mod>& a) {
        s >> a.x;
        return s;
    }
};

using mint = ModInt<1000000007>;
using Graph = vector<vector<int>>;
Graph G;

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

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

    ll n; cin >> n;
    vector<mint> ans(n + 1);
    ans[1] = ans[2] = 0;
    ans[3] = ans[4] = ans[5] = 1;
    _rep(i, 6, n + 1) ans[i] = ans[i - 1] + ans[i - 3];
    cout << ans[n] << endl;
}


Measured memory_bytes: 3660
#include<stdio.h>
int main()
{
long int n=2000000;
long long int a[n],ans,i,x;
  scanf("%lld",&x);
  for(i=0;i<n;++i)
  {
  a[i]=(i*(i+1))/2;
  }

  for(i=0;i<n;++i)
  {
  if(a[i]<x && a[i+1]>=x) ans=i+1;
  }
  printf("%d",ans);
return 0;}

Measured memory_bytes: 17356
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
ll isP(ll k){
	for(ll i = 2;i * i <= k;i++){
		if(k % i == 0) return 0;
	}
	return 1;
}
ll gcd(ll a,ll b){
    while(b){
        ll t = b;
        b = a % b;
        a = t;
    }
    return a;
}
int main(){
	ll a,b;
	cin >> a >> b;
	ll t = gcd(a,b);
	if(t == 1){
		cout << 1 << endl;
		return 0;
	}
	ll cnt = 0;
	for(ll i = 1;i <= sqrt(t);i++){
		ll j = t / i;
		if(i * j == t){
			if(isP(i))
				cnt++;
			if(isP(j))
				cnt++;
		}		
	}
	printf("%lld\n",cnt);
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0; i < (n);++i)
using namespace std;
using ll = long long; 
using P = pair<ll,ll>;
using vv = vector<vector<ll>>;
template <class _T> inline bool chmax (_T& a,_T b){if(a<b){a=b;return true;}return false;}
template <class _T> inline bool chmin (_T& a,_T b){if(a>b){a=b;return true;}return false;}

const long long INF = 1LL << 60;
const long long mod = 1000000007;

int main(void){
    int n,m;cin >> n >>m;
    vector<vector<int>> a(n);
    for(int i=0;i<m;i++){
	int c,d; cin >> c >> d;
	c--;d--;
	a[c].push_back(d);
	a[d].push_back(c);
    }
    vector<int> per(n);
    rep(i,n) per[i] = i;
    int ans=0;
    do{
	bool ok = true;
	if(per[0] != 0) ok = false;
	for(int i=0;i<n-1;i++){
	    bool ok2 = false;
	    for(int j=0;j<a[per[i]].size();j++){
		if(a[per[i]][j]==per[i+1]) ok2 = true;
	    }
	    if(ok2==false){ 
		ok = false;
		break;
	    }
	}    
	if(ok) ans++;
    }while( next_permutation(per.begin(),per.end()) );
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < n; i++)
#define REP(i, n) for(int i = 1; i < n; i++)
#define all(v) v.begin(),v.end()
#define rall(v) v.rbegin(), v.rend()
#define P pair<int, int>
typedef long long ll;
const ll mod = 1e9+7;

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

//繰り返し自乗法による累乗計算
//a**n
ll pow(ll a, ll n){
  if(n == 0) return 1;
  if(n%2 == 0){
    ll res = pow(a, n/2);
    return res * res;
  }
  return a * pow(a, n-1);
}
//繰り返し自乗法によるmod累乗計算
//a**n (mod)
ll modpow(ll a, ll n){
  if(n == 0) return 1;
  if(n%2 == 0){
    ll res = modpow(a, n/2);
    return res * res % mod;
  }
  return a * modpow(a, n-1) % mod;
}
//組み合わせ
//nCa
ll com(ll n, ll a){
  ll x = 1, y = 1;
  rep(i,a){
    x *= n-i;
    y *= i+1;
  }
  ll res = x / y;
  return res;
}
//組み合わせ(mod)
//nCa (mod)
ll modcom(ll n, ll a){
  ll x = 1, y = 1;
  rep(i, a){
    x = x * (n-i) % mod;
    y = y * (i+1) % mod;
  }
  ll ans = x * modpow(y, mod-2) % mod;
  return ans;
}
//gcd 最大公約数
ll gcd(ll x, ll y){
  if(x % y == 0) return y;
  return gcd(y, x%y);
}
//lcm 最小公倍数
ll lcm(ll x, ll y){
  return x * y / gcd(x, y);
}
//ngcd n個の最大公約数
ll ngcd(vector<ll> a){
  ll res;
  res = a[0];
  for(ll i = 1; i < a.size() && res != 1; i++) {
    res = gcd(a[i], res);
  }
  return res;
}
//nlcm n個の最小公倍数
ll nlcm(vector<ll> a) {
  ll res;
  res = a[0];
  for (ll i = 1; i < a.size(); i++) {
    res = lcm(res, a[i]);
  }
  return res;
}
// 素数判定
bool isprime(ll x){
  ll i;
  if(x < 2) return false;
  else if(x == 2) return true;
  if(x % 2 == 0) return false;
  for(i = 3; i*i <= x; i += 2){
    if(x % i == 0) return false;
  }
  return true;
}
// 桁和
ll digsum(ll x){
  ll res = 0;
  while(x > 0){
    res += x % 10;
    x /= 10;
  }
  return res;
}


int main(){
  char a, b;
  cin >> a >> b;
  if(a == b){
    cout << 'H' << endl;
  }
  else{
    cout << 'D' << endl;
  }
} 






Measured memory_bytes: 256
#include <stdio.h>

#define NUM 200000

int main(void)
{
	int island, bin;
	int place_a, place_b;
	int pickup_a[NUM] = { 0 };
	int pickup_b[NUM] = { 0 };
	int i;
	
	/* ----- input ----- */
	scanf("%d %d", &island, &bin);
	for(i=0; i<bin; i++){
		scanf("%d %d", &place_a, &place_b);
		
		if(place_a == 1)
			pickup_b[place_b-1] = 1;
		if(place_b == island)
			pickup_a[place_a-1] = 1;
	}
	
	/* ----- to_do & output  ----- */
	for(i=0; i<island; i++){
		if(pickup_a[i]==1 && pickup_b[i]==1){
			printf("POSSIBLE");
			return 0;
		}
	}
	
	printf("IMPOSSIBLE");
	
	return 0;
}


Measured memory_bytes: 1664
#include<cstdio>
#include<iostream>
#include<cstring>
#define RG register
#define ll long long
using namespace std;
const int N=2e5+10 ,base=2e3+2 ,M=8010;
const ll mod=1e9+7;
int n;
ll a[N],b[N],fac[M]={1},inv[M],dp[M/2][M/2],ans;
inline ll read(){
	char ch=getchar(); ll x=0, f=1;
	while(ch<'0' || ch>'9') {if(ch=='-') f=-1;ch=getchar();}
	while(ch>='0' && ch<='9') {x=x*10+ch-'0'; ch=getchar();}
	return x*f;}
inline ll powe(ll aa,ll tt)
{
	ll ans=1;
	for(ll i=tt;i;i>>=1,aa=aa*aa%mod) if(i&1) (ans*=aa)%=mod;
	return ans;
}
inline ll C(int nn,int mm){return fac[nn]*inv[mm]%mod*inv[nn-mm]%mod;}
int main()
{
//	freopen("BBQ Hard.in","r",stdin);
	n=read();
	for(RG int i=1;i<=M;i++) fac[i]=fac[i-1]*i%mod;
	inv[M]=powe(fac[M],mod-2);
	for(RG int i=M-1;i>=0;i--) inv[i]=inv[i+1]*(i+1)%mod;
	for(RG int i=1;i<=n;i++)
	{
		a[i]=read(); b[i]=read();
		dp[base-a[i]][base-b[i]]++;
	}
	for(RG int i=1;i<=base*2;i++)
	 for(RG int j=1;j<=base*2;j++)
	  (dp[i][j]+=dp[i-1][j]+dp[i][j-1])%=mod;
	for(RG int i=1;i<=n;i++) (ans+=dp[base+a[i]][base+b[i]]-C(2*a[i]+2*b[i],a[i]*2)+mod)%=mod;
	printf("%lld",ans*inv[2]%mod);
	return 0;
}

Measured memory_bytes: 128768
#include <iostream>
#include <vector>
#include <algorithm>
#include <numeric>
#include <cstdint>
#include <map>
#include <set>
#include <cmath>
#include <cstdlib>
#include <sstream>

#include <boost/range/irange.hpp>
using boost::irange;

#include <boost/utility/string_ref.hpp>
using boost::string_ref;

using namespace std;

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

    size_t k;
    string s;
    cin >> s >> k;
    
    set<string_ref> substrs;
    
    for(size_t l = 1; l <= s.size(); ++l)
    {
       for(size_t i = 0; i < s.size() - l + 1; ++i)
        {
            const auto ss = string_ref(&s[i], l);
            //cout << '(' << i << ',' << l << ')' << ' ' << ss << '\n';
            if(substrs.size() < k)
            {
                substrs.insert(ss);                
            }
            else if(ss < *--end(substrs))
            {
                substrs.insert(ss);
                substrs.erase(--end(substrs));
            }
            //copy(begin(substrs), end(substrs), ostream_iterator<string>(std::cout, " ")); cout << endl;
        }
    }
    
    cout << *next(begin(substrs), k-1) << '\n';

    return 0;
}



Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
	public static void main(String[] args) throws Exception {
        Scanner sc = new Scanner(System.in);
        Main m = new Main(sc);
        m.show(m.solve());
        sc.close();
    }
    
	//フィールド
    Scanner sc;
    int N;
    int R;
    
    //入力
    Main(Scanner sc) {
        this.sc = sc;
        this.N = sc.nextInt();
        this.R = sc.nextInt();
    }
    
    //解答処理
    private int solve() {
        int rate = 0;
        
        if (N >= 10) {
        	rate = R;
        } else {
        	int K = N;
        	rate = R + (100 * (10-K));
        }
        
        return rate;
    }
    
    //出力
    public void show(int answer) {
        System.out.println(answer);
    }

}


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

typedef long long ll;

const int N = 200005;
int n;
int A[N];
vector<int> edges[N];
vector<int> V(N, INT_MAX);
int res[N];

void dfs(int par, int u) {
    for (auto v : edges[u]) {
        if (v == par) continue;
        int pos = lower_bound(V.begin(), V.end(), A[v]) - V.begin();

        res[v] = max(res[u], pos + 1);

        int temp = V[pos];
        V[pos] = A[v];
        dfs(u, v);
        V[pos] = temp;
    }
}

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

    cin >> n;
    for (int i = 1; i <= n; ++i) {
        cin >> A[i];
    }
    int u, v;
    for (int i = 0; i < n - 1; ++i) {
        cin >> u >> v;
        edges[u].push_back(v);
        edges[v].push_back(u);
    }
    res[1] = 1;
    V[0] = A[1];
    dfs(0, 1);

    for (int i = 1; i <= n; ++i) {
        cout << res[i] << endl;
    }

    return 0;
}



Measured memory_bytes: 30836
#include <iostream>
#include <vector>

using namespace std;

int foo(vector<vector<int>>& m)
{
    int n=m.size();
    vector<vector<int>> dp(n);
    for (int i=0;i<n;++i) dp[i].resize(3);
    for (int j=0;j<3;++j) dp[0][j] = m[0][j];

    for (int day=1;day<n;++day)
    {
        for (int act=0;act<3;++act)
        {
            dp[day][act] = max(dp[day-1][(act+1)%3],dp[day-1][(act+2)%3]) + m[day][act];
        }
    }

    return max(max(dp[n-1][0],dp[n-1][1]),dp[n-1][2]);
}

int main()
{
    int n;
    cin>>n;
    vector<vector<int>> m(n);
    for (int i=0;i<n;++i) m[i].resize(3);

    for (int day=0;day<n;++day)
    {
        for (int act=0;act<3;++act)
        {
            cin>>m[day][act];
        }
    }

    cout<<foo(m)<<endl;


    return 0;
}


Measured memory_bytes: 11136
#include<iostream>
using namespace std;
int main(){
    int W,H,x,y,r;
    cin >> W >> H >> x >> y >> r;
    
    if (r <= x && x <= W-r){
        if(r <= y && y <= H-r){
            cout << "Yes" << endl;
        }else{
            cout << "No" << endl;
        }
        
    }else{
        cout << "No" << endl;
    }

    return 0;
}



Measured memory_bytes: 3116
n=int(input())
s=[0]*n

for _ in range(n):
    s[_]=input()


ac=0
wa=0
tle=0
re=0

for i in range(n):
    if s[i]=="AC":
        ac+=1
    if s[i]=="WA":
        wa+=1
    if s[i]=="TLE":
        tle+=1
    if s[i]=="RE":
        re+=1


print("AC x "+str(ac))
print("WA x "+str(wa))
print("TLE x "+str(tle))
print("RE x "+str(re))

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

int main() {
  char str[3][4];
  
  for(int i = 0;i < 3;i++){
    for(int j = 0; j < 3; j++){
      cin >> str[i][j];
    }
  } 
  
  for(int k = 0;k<3;k++)
  cout << str[k][k];
}


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

int n, m;
char mat[1055][1055];

const int MOD = 1e9 + 7;

inline void add(int &a, int b) {
	a += b;
	if (a >= MOD) a -= MOD;
}

int dp[3055][3055];

int main() {
	scanf("%d %d", &n, &m);
	
	for (int i = 0; i < n; i++) {
		scanf("%s", mat[i]);
	}
	
	dp[0][0] = 1;
	
	for (int i = 0; i < n; i++) for (int j = 0; j < m; j++) {
		if (mat[i][j] == '#') continue;
		
		if (i > 0) {
			add(dp[i][j], dp[i - 1][j]);
		}
		if (j > 0) {
			add(dp[i][j], dp[i][j - 1]);
		}
	}
	
	cout << dp[n - 1][m - 1];
}


Measured memory_bytes: 14464
// C
#ifndef _GLIBCXX_NO_ASSERT
#include <cassert>
#endif
#include <cctype>
#include <cerrno>
#include <cfloat>
#include <ciso646>
#include <climits>
#include <clocale>
#include <cmath>
#include <csetjmp>
#include <csignal>
#include <cstdarg>
#include <cstddef>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>

#if __cplusplus >= 201103L
#include <ccomplex>
#include <cfenv>
#include <cinttypes>
// #include <cstdalign>
#include <cstdbool>
#include <cstdint>
#include <ctgmath>
#include <cwchar>
#include <cwctype>
#endif

// C++
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>

#if __cplusplus >= 201103L
#include <array>
#include <atomic>
#include <chrono>
#include <condition_variable>
#include <forward_list>
#include <future>
#include <initializer_list>
#include <mutex>
#include <random>
#include <ratio>
#include <regex>
#include <scoped_allocator>
#include <system_error>
#include <thread>
#include <tuple>
#include <typeindex>
#include <type_traits>
#include <unordered_map>
#include <unordered_set>
#endif

using namespace std;
typedef long long int ll;
typedef unsigned long long ull;
typedef long double ld;
#define REP(i,n) for(ll i=0; i<(n); i++)
#define REPR(i, n) for(ll i = n;i >= 0;i--)
#define FOR(i, m, n) for(ll i = m;i < n;i++)
#define ALL(n) begin(n),end(n)
#define IN(a, x, b) (a<=x && x<b)
#define INIT std::ios::sync_with_stdio(false);std::cin.tie(0);
template<class T> inline T CHMAX(T & a, const T b) { return a = (a < b) ? b : a; }
template<class T> inline T CHMIN(T & a, const T b) { return a = (a > b) ? b : a; }

const long double EPS = 1e-10;
const long long INF = 1e18;
const long double PI = acos(-1.0L);
const long long MOD = 1000000007;

int main(void){
    ll n,m;
    cin >> n >> m;
    ll ans =0;
    if( n==1 && m ==1){
        ans = 1;
    }else if( n==1){
        ans = m-2;
    }else if(m == 1){
        ans = n-2;
    }else if(n==2 || m == 2){
        ans =0;
    }else{
        ans = (n-2) * (m-2);
}
    cout << ans << endl;
    return 0;
}

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

int main(void){
    long long int a,b,c,d,output1,output2,output3,output4,output;
    cin >>a>>b>>c>>d;

    output1 = a*c;
    output2 = a*d;
    output3 = b*c;
    output4 = b*d;

    output = output1;
    if(output1<output2){
        output = output2;
    }
    if(output < output3){
        output = output3;
    }
    if(output <output4){
        output = output4;
    }

    cout<<output<<endl;


}

Measured memory_bytes: 3200
#include<iostream>
#include<math.h>
#include <algorithm>
#include<float.h>
#include <limits>
#include <vector> 
#include <numeric>
#include <string.h>

#define rep(i,a,n) for(ll int (i) = (a);(i) < (n);(i)++)
#define urep(i,a,n) for(ll int (i) = (a);(i) > (n);(i)--)
#define MOD 1000000007
#define ll long long

using namespace::std;

int jo(ll int jxo, ll int jyo){
	ll int jhogeo = 1;
	rep(jinto,0,jyo) jhogeo=jhogeo*jxo;
	return jhogeo;
}
char tobig(char toxbig){
  return (toxbig-0x20);
}
char tolow(char toxlow){
  return (toxlow+0x20);
}
  


int main(){
  string a,b,c;
  cin>>a>>b>>c;
  cout<<a[0]<<b[1]<<c[2];

}
// int *p = new int[N];

//  vector<int> 変数名(要素数);
//  sort(変数名.begin(),変数名.end());//昇順ソート

// vector<vector<int>> 変数名(左の個数, vector<int>(右の個数));

//


Measured memory_bytes: 384
import collections
class UnionFind:
    def __init__(self, n):
        self.parent = list(range(n))
 
    def root(self, i):
        if self.parent[i] == i:
            return i
        else:
            self.parent[i] = self.root(self.parent[i])
            return self.parent[i]
    
    def find(self, x, y):
        return self.root(x) == self.root(y)
 
    def union(self, i, j):
        i = self.root(i)
        j = self.root(j)
        if j >= i:
            self.parent[j] = i
        else:
            self.parent[i] = j
N, K, L = map(int, input().split())
road = UnionFind(N)
train = UnionFind(N)
for _ in range(K):
    p, q = map(int, input().split())
    road.union(p-1, q-1)
for _ in range(L):
    r, s = map(int, input().split())
    train.union(r-1, s-1)
for i in range(N):
    road.root(i)
    train.root(i)
lst = []
for i in range(N):
    lst.append((road.parent[i], train.parent[i]))
c = collections.Counter(lst)
ans = []
for i in range(N):
    ans.append(c[lst[i]])
print(*ans)

Measured memory_bytes: 117596