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

using namespace std;
using ll = long long;
using ull = unsigned long long;
using P = pair<int,int>;
using Pl = pair<ll,ll>;
#define rep(i,n) for(ll i = 0;i < (ll)n;i++)
#define ALL(x) (x).begin(),(x).end()
#define MOD 1000000007



int main(){
  
  int h,w;
  cin >> h >> w;
  vector<string> s(h);
  rep(i,h)cin >> s[i];
  vector<vector<bool>> is(h,vector<bool>(w,1));
  rep(i,h){
    bool ok = true;
    rep(j,w)if(s[i][j] == '#')ok = false;
    if(ok)rep(j,w)is[i][j] = false;
  }
  rep(i,w){
    bool ok = true;
    rep(j,h)if(s[j][i] == '#')ok = false;
    if(ok)rep(j,h)is[j][i] = false;
  }
  rep(i,h){
    rep(j,w)if(is[i][j])cout << s[i][j];
    cout << endl;
  }






  

  return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ll long long
#define pb push_back
using namespace std;

const long long N = 1e5 + 17;
ll cnt, lnt, mn = N, mx, a[N], n, m,k, x, y, ans, sum;
pair<ll,ll>pr[N];
vector<ll>v,v2,v3;
map<ll,ll>mp;
bool used[N], t1, t2;
vector<string>sv;
vector<char>vi;

int main()
{
    string s;
    cin >> s;
    for(ll i = 0; i < s.size(); i ++)
    {
        vi.pb(s[i]);
        while(vi.size() > 1)
        {
            if(vi.back() != vi[vi.size() - 2])
            {
                vi.pop_back();
                vi.pop_back();
                cnt += 2;
            }
            else
            {
                break;
            }
        }
    }
    cout << cnt;
}


Measured memory_bytes: 640
/**
 * @author      : omgursocute
 * @file        : 149/C.cpp
 * @created     : 30/12/2019
 */

#include <bits/stdc++.h>

using namespace std;

typedef int64_t ll;
typedef uint64_t ull;
typedef long double ld;

const int N = 1e5+5;
int marked[N/64];

bool ismarked(int x) {
	return marked[x/64] & (1 << (x >> 1));
}

void mark(int x) {
	marked[x/64] |= (1 << ((x >> 1) & 31));
}

int main() {
	ios::sync_with_stdio(false);
	cin.tie(NULL); cout.tie(NULL);
	
	for(int i = 3; i*i <= N; i+=2) {
		if(!ismarked(i))
			for(int j = i*i; j < N; j += (i << 1)) mark(j);
	}

	int i = 3;
	int n; cin >> n;
	int res = 2;
	while(i <= n) {
		if(!ismarked(i)) res = i;
		i += 2;
	}
	if(res == n) cout << res;
	else {
		while(ismarked(i)) i += 2;
		cout << i;
	}

	return 0;
}



Measured memory_bytes: 256
#include <iostream>
#include <fstream>
#include <cstdio>
#include <cmath>
#include <vector>
#include <string>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <deque>
#include <bitset>
#include <algorithm>
#include <complex>
#include <array>
#include <functional>
using namespace std;
 
#define REP(i,n) for(int i=0; i<n; ++i)
#define FOR(i,a,b) for(int i=a; i<=b; ++i)
#define FORR(i,a,b) for (int i=a; i>=b; --i)
#define ALL(c) (c).begin(), (c).end()
 
typedef long long ll;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef vector<double> VD;
typedef vector<VI> VVI;
typedef vector<VL> VVL;
typedef vector<VD> VVD;
typedef pair<int,int> P;
typedef pair<ll,ll> PL;

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

int in() { int x; scanf("%d", &x); return x; }
ll lin() { ll x; scanf("%lld", &x); return x; }

const int b = 8;
VI e[100];
int par[100][b], depth[100], id[100];
int cnt;

void dfs(int now, int past){
    REP(i,e[now].size()){
        int next = e[now][i];
        if (next == past) continue;
        id[next] = cnt++;
        par[next][0] = now;
        depth[next] = depth[now] + 1;
        dfs(next, now);
    }
}

int lca(int x, int y){
    if (depth[y] > depth[x]) swap(x,y);
    int d = depth[x] - depth[y];
    REP(i,b){
        if ((d>>i) & 1){
            x = par[x][i];
        }
    }
    if (x == y) return x;
    FORR(i,b-1,0){
        if (par[x][i] != par[y][i]){
            x = par[x][i];
            y = par[y][i];
        }
    }
    return par[x][0];
}

int main() {
    int n, m;
    cin >> n;
    REP(i,n-1){
        int u = in() - 1, v = in() - 1;
        e[u].push_back(v);
        e[v].push_back(u);
    }
    dfs(0, -1);
    FOR(i,1,b-1){
        REP(j,n){
            par[j][i] = par[par[j][i-1]][i-1];
        }
    }
    cin >> m;
    VI u(m), v(m);
    VVI path(m, VI(n - 1));
    REP(i,m){
        u[i] = in() - 1, v[i] = in() - 1;
        int a = lca(u[i], v[i]);
        int x = u[i];
        while (x != a){
            path[i][id[x]] = 1;
            x = par[x][0];
        }
        x = v[i];
        while (x != a){
            path[i][id[x]] = 1;
            x = par[x][0];
        }
    }
    ll ans = 0;
    REP(mask,1<<m){
        int c = 0;
        VI ok(n, 1);
        REP(i,m){
            if ((mask >> i) & 1){
                c++;
                REP(j,n-1) if (path[i][j]) ok[j] = 0;
            }
        }
        ll x = 1;
        REP(j,n-1) if (ok[j]) x = 2 * x;
        if (c % 2 == 0) ans += x;
        else ans -= x;
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <string>
#include <sstream>
#include <complex>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
#include <iterator>
#include <numeric>
#include <bitset>
#include <cassert>
#include <functional>

using namespace std;
typedef long long ll;
inline ll min(ll x, ll y) { return x < y ? x : y; }
inline ll max(ll x, ll y) { return x > y ? x : y; }

#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define rep1(i,n) for(int i=1;i<(int)(n);i++)
#define all(c) c.begin(),c.end()
#define pb push_back
#define fs first
#define sc second
#define show(x) cout << #x << " = " << (x) << endl
#define chmin(x,y) x=min(x,y)
#define chmax(x,y) x=max(x,y)

int main() {
	int W, a, b;
	cin >> W >> a >> b;
	if (a + W < b) {
		cout << b - (a + W) << endl;
	}
	else if (b + W < a) {
		cout << a - (b + W) << endl;
	}
	else {
		cout << 0 << endl;
	}
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define FOR(i, begin, end) for(int i=(begin);i<(end);i++)
#define REP(i, n) FOR(i,0,n)
#define IFOR(i, begin, end) for(int i=(end)-1;i>=(begin);i--)
#define IREP(i, n) IFOR(i,0,n)
#define SORT(a) sort(a.begin(), a.end())
#define REVERSE(a) reverse(a.begin(), a.end())
#define int long long
#define INF 1000000000000000000
using namespace std;

typedef vector<int> vec;
typedef vector<vec> mat;
typedef pair<int, int> Pii;

template<typename T>
void readvec(vector<T> &a);
void readindex(vector<int> &a);



signed main(){

    int N, A, B; cin >> N >> A >> B;
    vec h(N); readvec(h);
    A -= B;

    int ans1 = 0, ans2 = 1000000000;
    while(ans2 - ans1 > 1){
        int ans = (ans1 + ans2 + 1) / 2;
        int n = 0;
        REP(i, N) if(h[i] > B * ans) n += (h[i] - B * ans) / A + min(1LL, (h[i] - B * ans) % A);
        if(n <= ans) ans2 = ans; else ans1 = ans;
    }

    cout << ans2;
    
    return 0;
}


template<typename T>
void readvec(vector<T> &a){
    REP(i, a.size()){
        cin >> a[i];
    }
}
void readindex(vector<int> &a){
    REP(i, a.size()){
        cin >> a[i];
        a[i]--;
    }
}

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

int sod(int N) {
  int sum = 0;
  while (N > 0) {
    sum += N % 10;
    N /= 10;
  }
  return sum;
}

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

  cout << ((N % sod(N) == 0) ? "Yes" : "No") << endl;
}

Measured memory_bytes: 256
/*
[abc129] C - Typical Stairs
*/

#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef pair<int, int> pii;
typedef pair<ll, int> pli;
typedef pair<ll, ll> pll;

const int MAX_N = 1e5;
const int MAX_M = MAX_N - 1;
const int MOD = 1e9 + 7;

class gf {
public:
    int n;
    gf() : n(0) {}
    gf(int n) : n(n % MOD) {}
    gf operator+(gf x) { return gf((n + x.n) % MOD); }
    gf operator-(gf x) { return gf((n - x.n + MOD) % MOD); }
    gf operator*(gf x) { return gf((1LL * n * x.n) % MOD); }
};

int N, M;
bool broken[MAX_N + 1];
gf dp[MAX_N + 1];

ll solve() {
    dp[0] = 1;
    if (!broken[1]) {
        dp[1] = 1;
    }
    for (int i = 2; i <= N; i++) {
        if (!broken[i]) {
            dp[i] = dp[i - 1] + dp[i - 2];
        }
    }
    return dp[N].n;
}

int main() {
    cin >> N >> M;
    for (int i = 0; i < M; i++) {
        int a;
        cin >> a;
        broken[a] = true;
    }

    cout << solve() << endl;

    return 0;
}


Measured memory_bytes: 768
# 数直線上を N+1 回跳ねるボールがあり、
# 1 回目は 座標 D1=0, i 回目は 座標 Di=Di−1+Li−1(2≤i≤N+1) で跳ねます。
# 数直線の座標が X 以下の領域でボールが跳ねる回数は何回でしょうか。

nx = gets.chomp.split
n = nx[0].to_i
x = nx[1].to_i

l = gets.chomp.split
n.times do |i|
    l[i] = l[i].to_i
end

d_array = [0]
(1..n).each do |i|
    d = d_array[i-1]
    d += l[i-1]
    d_array << d
end

count = 0
(n+1).times do |i|
    count += 1 if d_array[i] <= x
end

puts count

Measured memory_bytes: 1788
#include <iostream>
#include <algorithm>
using namespace std;
 
int main(){
  int n,h,m,s;
  cin >> n;
 
  h = n / 3600;
  m = n % 3600 / 60;
  s = n % 3600 % 60;
 
  cout << h << ':' << m << ':' << s << endl;
}

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


 int main(){
int a,b,c,d;
   string n;
   cin >> n;
   a= n.at(0)-48;
   b=n.at(1)-48;
   c=n.at(2)-48;
   d= n.at(3)-48;
   if(a+b+c+d==7){
     cout << a << '+' << b << '+' << c << '+' << d << '=' << 7 << endl;
   }
   else if(a+b+c-d==7){
     cout << a << '+' << b << '+' << c << '-' << d << '=' << 7 << endl;
   }
   else if(a+b-c+d==7){
     cout << a << '+' << b << '-' << c << '+' << d << '=' << 7 << endl;
   }
   else if(a-b+c+d==7){
     cout << a << '-' << b << '+' << c << '+' << d << '=' << 7 << endl;
   }
   else if(a+b-c-d==7){
     cout << a << '+' << b << '-' << c << '-' << d << '=' << 7 << endl;
   }
   else if(a-b+c-d==7){
     cout << a << '-' << b << '+' << c << '-' << d << '=' << 7 << endl;
   }
   else if(a-b-c+d==7){
     cout << a << '-' << b << '-' << c << '+' << d << '=' << 7 << endl;
   }
   else cout << a << '-' << b << '-' << c << '-' << d << '=' << 7 << endl;
 }
   


Measured memory_bytes: 256
#include <iostream>

using namespace std;
int n,m,lmax=0,rmin=1e5+1;
int main()
{
    //freopen("C.INP","r",stdin);
    cin >> n >> m;
    for (int i=1;i<=m;i++)
    {
        int x,y;
        cin >> x >> y;
        lmax=max(lmax,x);
        rmin=min(rmin,y);
    }
    if (rmin<lmax) cout << 0;
    else cout << rmin-lmax+1;
}


Measured memory_bytes: 256
import java.util.Scanner;
 
public class Main {
 
    public static final int BIG_NUM  = 2000000000;
    public static final int MOD  = 1000000007;
 
    public static void main(String[] args) {
 
        Scanner scanner = new Scanner(System.in);
 
        double x[] = new double[100];
        double y[] = new double[100];
        double p_1 = 0,p_2 = 0,p_3 = 0,p_infinity = -1;
 
        int N = scanner.nextInt();
 
        for(int i = 0; i < N; i++)x[i] = scanner.nextDouble();
        for(int i = 0; i < N; i++)y[i] = scanner.nextDouble();
 
        for(int i = 0; i < N; i++){
            p_1 += Math.abs(x[i]-y[i]);
            p_2 += (x[i]-y[i])*(x[i]-y[i]);
            p_3 += Math.abs((x[i]-y[i])*(x[i]-y[i])*(x[i]-y[i]));
            p_infinity = Math.max(p_infinity, Math.abs(x[i]-y[i]));
        }
 
        System.out.printf("%.10f\n", p_1);
        System.out.printf("%.10f\n", Math.sqrt(p_2));
        System.out.printf("%.10f\n", Math.cbrt(p_3));
        System.out.printf("%.10f\n", p_infinity);
    }
}


Measured memory_bytes: 29180
S = input()
flag = "Yes"
even = {"R","U","D"}
odd = {"L","U","D"}
N = len(S)
for i in range(N):
  if i%2 == 0 and S[i] in even:
    continue
  elif i%2 == 1 and S[i] in odd:
    continue
  else:
    flag = "No"
    break
print(flag)

Measured memory_bytes: 3060
/*  ex7_3
    Rikuta  */

#include <stdio.h>

int main(void)
{   
    //変数とポインタの宣言
    int height, width, flag;
    char **matrix_given;
    int **on_off_matrix;

    //与えられる行列の高さと幅の入力
    scanf("%d %d\n", &height, &width);

    //height*(width+1)の行列の動的確保．確保できなかったらエラー処理
    matrix_given = (char **)calloc(height, sizeof(char *));
    if (matrix_given==NULL)
    {
        exit(1);
    }
    for (int i = 0; i < height; i++)
    {
        matrix_given[i] = (char *)calloc(width+1, sizeof(char));
        if (matrix_given[i]==NULL)
        {
            exit(1);
        }
        
    }

    //height*(width+1)の行列の動的確保．確保できなかったらエラー処理
    on_off_matrix = (int **)calloc(height, sizeof(int *));
    if (on_off_matrix == NULL)
    {
        exit(1);
    }
    for (int i = 0; i < height; i++)
    {
        on_off_matrix[i] = (int *)calloc(width+1, sizeof(int));
        if (on_off_matrix[i] == NULL)
        {
            exit(1);
        }
    }
    for (int i = 0; i < height; i++)
    {
        for (int j = 0; j < width + 1; j++)
        {
            //改行込みで与えられた行列を受け取る
            scanf("%c", &matrix_given[i][j]);
        }
    }
    for (int i = 0; i < height; i++)
    {
        //フラグを立てる
        flag = 1;
        for (int j = 0; j < width; j++)
        {
            if (matrix_given[i][j] == '#')
            {
                //i行について着目したときに#が一個でもあればフラグを0とする
                flag = 0;
            }
        }
        //もしi行について#がいっこもなければ
        if (flag)
        {
            for (int j = 0; j < width + 1; j++)
            {
                //on_off_matrixのi行目を1にする
                on_off_matrix[i][j] = 1;
            }
        }
    }
    for (int i = 0; i < width; i++)
    {
        //フラグを立てる
        flag = 1;
        for (int j = 0; j < height; j++)
        {
            if (matrix_given[j][i] == '#')
            {
                //i列について着目したときに#が一個でもあればフラグを0にする
                flag = 0;
            }
        }
        //i列について，#がなければ
        if (flag)
        {
            for (int j = 0; j < height; j++)
            {
                //on_off_matrixのi列目を1にする
                on_off_matrix[j][i] = 1;
            }
        }
    }

    for (int i = 0; i < height; i++)
    {
        for (int j = 0; j < width + 1; j++)
        {
            if (!on_off_matrix[i][j])
            {
                //与えられた行列の要素に対応するon_off_matrixが0ならばそれを出力する．
                printf("%c", matrix_given[i][j]);
            }
        }
    }

    //メモリの開放
    for (int i = 0; i < height; i++)
    {
        free(matrix_given[i]);
        free(on_off_matrix[i]);
    }
    free(matrix_given);
    free(on_off_matrix);

    return 0;
}

Measured memory_bytes: 1696
import java.util.Scanner;

public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		String n = sc.next();
		char c = n.charAt(n.length()-1);
		if(c!='s'){n=n+"s";}
		else{n=n+"es";}
		System.out.println(n);
       	}
}

Measured memory_bytes: 38420
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
ll n,max_wt;
ll w[101], v[101];
const ll INF =1e18L+5;
void max_self(ll& a, ll b){
    a = max(a,b);
}
void min_self(ll& a, ll b){
    a = min(a,b);
}
int main() {
    cin>>n>>max_wt;
    ll sum_value = 0;
    for(int i =0;i<n;i++){
        cin>>w[i]>>v[i];
        sum_value += v[i];
    }
    vector<ll> dp(sum_value+1,INF);
    dp[0]=0;
    for(int i =0; i<n;i++){
        for(int j=sum_value-v[i];j>=0;j--){
            min_self(dp[j+v[i]],dp[j]+w[i]);
        }
    }
    ll ans = 0;
    for(int i=0;i<=sum_value;i++){
        if(dp[i]<=max_wt){
            ans = max(ans, ll(i));
        }
    }
    cout<<ans<<endl;
}


Measured memory_bytes: 1024
x, k, d = input().split()
x = int(x)
k = int(k)
d = int(d)
x = abs(x)
if x > d:
  if  x // d > k:
    x = x - k*d
    print(x)
    exit()
  else:
  	k -= x // d
  	x = x % d
    
    
if k % 2 == 1:
  x = abs(x-d)

print(x)
    

Measured memory_bytes: 9184
#include <iostream>
#include <algorithm>
#include <cmath>
#include <string>
#include <array>
#include <vector>
#include <functional>
#include <unordered_map> 
#include <map> 
#include <numeric>
#include <limits>
#include <utility>
#include <queue>
#include <random>
using namespace std;
typedef long long LL;

int main(void) {
	LL i, j, n, x = 0, count = 0;
	string s, a;
	cin >> s;

	for (i = 0; i < s.size(); i++) {
		if (s[i] != 'x') {
			a += s[i];
		}
	}
	for (i = 0; i < a.size() / 2; i++) {
		
		if (a[i] != a[a.size() - i-1]) {
			cout << -1 << endl;
			return 0;
		}
	}
	if (a.size() == s.size()) {
		cout << 0 << endl;
		return 0;
	}
	i = 0; j = s.size() - 1;
	while (1) {
		if (i >= j) {
			break;
		}
		if (s[i] == 'x'&&s[j] == 'x') {
			i++; j--;
		} else if (s[i] == 'x') {
			i++;
			count++;
		} else if (s[j] == 'x') {
			j--;
			count++;
		} else {
			i++; j--;
		}
	}
	cout << count << endl;



	return 0;
}

Measured memory_bytes: 640
#include<iostream>
#include<cstdio>
#include<string>
#include<math.h>
#include<vector>
using namespace std;

int main()
{
	int i,A,H;
	cin>>H>>A;
	i=0;
	do{
		H-=A;
		i++;
	}while(H>0);
	cout<<i<<endl;
	return 0;
}


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

inline int read()
{
	int x=0,f=1; char ch=getchar();
	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;
}
map<int,int> M1,M2,W1;
int s1[200010],pa[200010];
signed main()
{
	int n=read();
	for(int i=1;i<=n;i++)
	{
		int x=read();
		M1[x]=i; M2[x]=1;
		s1[i]=x; W1[x]=0;
	}
	sort(s1+1,s1+1+n);
	for(int i=n;i>1;i--)
	{
		int id=M1[s1[i]],sz=M2[s1[i]],td=s1[i]+2*sz-n;	
		if(td==s1[i]) continue;	
		pa[id]=M1[td]; M2[td]+=sz; W1[td]+=W1[s1[i]]+sz;
	}
	if(M2[s1[1]]!=n||W1[s1[1]]!=s1[1]) puts("-1"),exit(0);
	for(int i=1;i<=n;i++) if(pa[i])
		printf("%lld %lld\n",i,pa[i]);
	return 0;
}

Measured memory_bytes: 33408
S = list(input())
N = len(S)
T = list(input())
M = len(T)
S.sort()
T.sort(reverse = True)
mmm = min(N, M)

for i in range(mmm):
    if S[i] > T[i]:
        print("No")
        exit()
    elif S[i] < T[i]:
        print("Yes")
        exit()
    else:
        continue

if N < M:
    print("Yes")
else:
    print("No")


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

// 隣接リストを用いた幅優先探索 O(|V|+|E|)
int n;
vector<int> G[100000], d(100000, 100000000); // 始点sから頂点iまでの最短距離をd[i]に記録
/*
* main関数からこれらを削除すること
* 隣接リストGの頂点数と最短距離dの要素数はnの最大値を整数で入力すること
*/
 
void bfs(int s) {
  queue<int> q;
  q.push(s);
  d[s] = 0;
  while(!q.empty()){
    int u = q.front();
    q.pop();
    for(int v = 0; v < G[u].size(); v++){
    if(d[G[u][v]] == 100000000){
        d[G[u][v]] = d[u] + 1;
        q.push(G[u][v]);
      }
    }
  }
}

int main() {
// 無向(有向)グラフの隣接リスト
  int m, u, v, w;
  cin >> n >> m;
  
  for(int i = 0; i < m; i++){
    cin >> u >> v >> w;
    u--;
    v--;
    G[u].push_back(v);
    G[v].push_back(u); // 有向グラフではこの行をコメントアウト
  }
  
  int ans = 0;
  for(int i = 0; i < n; i++){
    if(d[i] == 100000000){
      bfs(i);
      ans++;
    }
  }
  
  cout << ans << endl;
}

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

#define rep2(x,fr,to) for(int (x)=(fr);(x)<(to);(x)++)
#define rep(x,to) for(int (x)=0;(x)<(to);(x)++)
#define repr(x,fr,to) for(int (x)=(fr);(x)>=(to);(x)--)
#define all(c) (c).begin(),(c).end()
#define sz(v) (int)(v).size()

using namespace std;
typedef long long ll; typedef vector<int> VI; typedef pair<int,int> pii;
const int mod = (int)1e9 + 7;
void dbg(){ cerr << "\n"; }  
template <typename T,typename ...T2>
void dbg(const T& fst, const T2&...rst){ cerr << fst << ": "; dbg(rst...); }

int main()
{
	
	//cin.tie(0); ios_base::sync_with_stdio(false);
	string s;
	int k;
	cin >>s >>k;
	
	int n=sz(s);
	set<string> st;
	
	rep2(len, 1, min(6,n+1)){
		rep(i, n-len+1) st.insert(s.substr(i, len));
	}
	//for(auto x :st) cout << x <<" "; puts("");
	auto it = st.begin();
	rep(i,k-1) it++;
	cout << *it <<"\n";
	return 0;
}


Measured memory_bytes: 1664
#include <iostream>
using namespace std;
main(){
  int N, L, result;
  cin >> N >> L;
  if(L >= 0){
    result = (int)((N-1) * (L+1 + L+N-1) / 2);
  } else {
    if ((L+N-1) >= 0){
      result = (int)(N * (L+L+N-1)/2);
    } else {
      result = (int)((N-1) * (L+L+N-2) / 2);
    }
  }

  cout << result << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <string>
#include <algorithm>
#include <string.h>
#include <ctype.h>
#include <math.h>
#include <float.h>
#include <iomanip>
#include <iostream>
using namespace std;


int main(){

    int N,M,P[100100]={},f[100100]={},A[100100]={},ac=0,pe=0;
    string S[100100]={};
    cin >> N >>M;

    for(int i=1;i<=N;i++){
        f[i]=0;
        A[i]=0;
    }

    for(int i=1;i<=M;i++){
        cin >> P[i]>>S[i];
        if(S[i]=="AC"){
            A[P[i]]=1;
        }
    }

    for(int i=1;i<=M;i++){
        if(S[i]=="AC"){
            if(f[P[i]]!=1){
                ac+=1;
                f[P[i]]=1;
            }
        }else{
            if(f[P[i]]!=1
                && A[P[i]]==1)pe+=1;
        }

    }

    cout << ac<<" " << pe;

    return 0;
}


Measured memory_bytes: 6912
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int N , A;
  int x = 0;
  int y = 30;
  // ここにプログラムを追記

    cin >> N;
    for (int i = 0; i < N; i++) {
    cin >> A;
   if (A % 2 != 0)
   {y = 0;  break;}    

  for (int j = 0; j < 30; j++) {
    if (A % 2 != 0) 
       break;
    
     A = A / 2;
      x++;
  //    cout << x  << "x" << endl;
  }
  if (x <= y) {
    y = x;}
    x = 0;
 //     cout << y << "y" << endl;
    }
  cout << y << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
using namespace std;
int main(){
    int N; cin >> N;
    vector<int> P(N);
    for(int i = 0; i < N; i++){
        cin >> P[i];
    }
    int ans = 0;
    int min = P[0];
    for(int i = 0; i < N; i++){
        if(P[i] <= min){
            min = P[i];
            ans++;
        }
    }
    cout << ans << endl;
}

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

#define rep(i,n) for(long long int (i)=0;(i)<(int)(n);(i)++)
#define rrep(i,a,b) for(long long int i=(a);i<(b);i++)
#define rrrep(i,a,b) for(long long int i=(a);i>=(b);i--)
#define all(v) (v).begin(), (v).end()
#define pb(q) push_back(q)
#define P pair<int,int>
#define Abs(a,b) max(a,b)-min(a,b)
#define YES(condition) if(condition){cout << "YES" << endl;}else{cout << "NO" << endl;}
#define Yes(condition) if(condition){cout << "Yes" << endl;}else{cout << "No" << endl;}
#define Cout(x) cout<<(x)<<endl
#define POSSIBLE(n) cout << ((n) ? "POSSIBLE" : "IMPOSSIBLE"  ) << endl
#define Possible(n) cout << ((n) ? "Possible" : "Impossible"  ) << endl
#define possible(n) cout << ((n) ? "possible" : "impossible"  ) << endl
#define Size(n) (n).size()

typedef long long ll;

using namespace std;

const int INF = 1e9,MOD = 1e9 + 7;
const ll LINF = 1e18;

//long long int kaizyo(long long int hh){
  //  cmp=1;
    //while(hh>1){
      //  cmp=(cmp*hh)%MOD;
        //hh--;
    //}
    //return cmp;
//}

//while(x!=0){
            //sum+=x%10;
           // x/=10;
        //}
        //各桁の和

//pair<int,int> p[100000];
//P r[100000];
//cin >> tmp;
//p[i]=make_pair(tmp,i);
//cout << p[i].second+1 << endl;//ペアの右側つまりiを出力

//s.find(w[i])==string::npos
//findの使い方

//for(int i=0;i<n;i++){
   // b[i]=x%2;
    //x/=2;
  //}二進数

//visited=vector<vector<bool>>(10,vector<bool>(10,false));アを全部falseに


long long int n,cnt=0,ans=0,a[10000000],b,c,cmp,cmpp,m,h,w,x,y,sum=0,pos;
int dy[]={1,0,-1,0};
int dx[]={0,1,0,-1};
string alph("abcdefghijklmnopqrstuvwxyz"),s;
bool fl=true;

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

       cin >> n;
       rep(i,n)cin >> a[i];
       sort(a,a+n);
       reverse(a,a+n);
       rep(i,n){
           if(i%2==0){
               cnt+=a[i];           }
               else{
                   ans+=a[i];
               }
       }
       Cout(cnt-ans);
return 0;
}


Measured memory_bytes: 256
import sys

read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

x = int(input())

if x >= 400 and x <= 599:
    print("8")
elif x >= 600 and x <= 799:
    print("7")
elif x >= 800 and x <= 999:
    print("6")
elif x >= 1000 and x <= 1199:
    print("5")
elif x >= 1200 and x <= 1399:
    print("4")
elif x >= 1400 and x <= 1599:
    print("3")
elif x >= 1600 and x <= 1799:
    print("2")
else:
    print("1")


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

#define rep(i,begin,end) for(int i=begin; i<end; i++)
#define lld long long int

int main(){
    int n;
    lld t, p, ans;
    scanf("%d %lld %lld", &n, &t, &p);
    ans = t;
    rep(i, 1, n){
        lld x;
        scanf("%lld", &x);
        if(x > p+t){
            ans += t;
        }else{
            ans += t - (p+t - x);
        }
        p = x;
    }
    printf("%lld", ans);

    return 0;
}

Measured memory_bytes: 128
#include <iostream>
#include <cstring>
#include <stdlib.h>
#include <vector>
#include <algorithm>
#include <cmath>
#include <stack>
#include <queue>
#include <math.h>
#include <string>
#include <map>
using namespace std;

typedef long long ll;

int main()
{
    string s;
    cin >> s;
    if(s[0]=='A'){
        bool flag1=false;
        int flag2=0;
        for(int i=2; i<s.size()-1; i++){
            if(s[i]=='C'){
                if(flag1){
                    flag1=false;
                    break;
                }else{
                    flag1=true;
                }
            }
        }
        for(int i=0; i<s.size(); i++){
            if(s[i]-'A'<=25){
                flag2++;
            }
        }
        if(flag1==true && flag2==2){
            cout << "AC";
            return 0;
        }
    }

    cout << "WA";
    return 0;
}

Measured memory_bytes: 888
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define repr(i, a, b) for(int i = a; i < b; i++)
#define  all(x) (x).begin(),(x).end()     // 昇順ソート
#define  rall(v) (v).rbegin(), (v).rend() // 降順ソート
#define  FastIO ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0)
typedef long long ll;
typedef long long int lli;
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; }

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

int main(){
    int x, y;
    cin >> x >> y;
    for (int i = 0; i <= x; i++){
        int j = x - i;
        if ((2*i + 4*j) == y){
            cout << "Yes" << endl;
            return 0;
        } 
    }
    cout << "No" << endl;
}

Measured memory_bytes: 3636
#include <bits/stdc++.h>
using namespace std;
#define INF 1<<30
#define endl '\n'
#define maxn 100005
#define tc printf("Case %d: ", cs)
#define tcn printf("Case %d:\n", cs);
#define FASTIO ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);
typedef long long ll;
const double PI = acos(-1.0);
#define dbg(x) cerr << #x << " = " << x << endl;
#define dbg2(x, y) cerr << #x << " = " << x << ", " << #y << " = " << y << endl;
#define dbg3(x, y, z) cerr << #x << " = " << x << ", " << #y << " = " << y << ", " << #z << " = " << z << endl;
#define dbg4(w,x, y, z) cerr << #w << " = " << w << ", " <<#x << " = " << x << ", " << #y << " = " << y << ", " << #z << " = " << z << endl;


int main()
{
    FASTIO
    /*
    //double start_time = clock();
#ifndef ONLINE_JUDGE
    freopen("in.txt", "r", stdin);
    freopen("out.txt", "w", stdout);
    freopen("error.txt", "w", stderr);
#endif
//*/
    int T;
    //cin >> T;
    T = 1;
    for (int cs = 1; cs <= T; cs++) {
        int n;
        cin >> n;
        vector<int> v(n);
        for (int i = 0; i < n; i++) cin >> v[i];
        for (int i = n - 1; i > 0; i--) {
            if (v[i] < v[i - 1])
                v[i - 1]--;
        }

        bool flag = true;
        for (int i = 0; i < n - 1; i++) {
            if (v[i] > v[i + 1]) {
                flag = false;
                break;
            }
        }
        if (flag) cout << "Yes\n";
        else cout << "No\n";
    }

    //double end_time = clock();
    //printf( "Time = %lf ms\n", ( (end_time - start_time) / CLOCKS_PER_SEC)*1000);
    return 0;
}

Measured memory_bytes: 640
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <utility>
#include <tuple>
#include <queue>
#include <deque>
#include <map>
#include <set>
#include <cmath>
#include <iomanip>
#define rep(i, n) for(int i = 0; i < (int)(n); ++i)
using namespace std;
using lint = int64_t;

int main() {
    const int INF = 1000000000;
    int N, S;
    cin >> N >> S;
    vector<int> a(N);
    rep(i, N) cin >> a[i];
    int ans = INF, right = 0, sum = 0;
    rep(left, N) {
        while (right < N && sum < S) {
            sum += a[right];
            ++right;
        }
        if (sum >= S) ans = min(ans, right - left);
        if (left == right) ++right;
        else sum -= a[left];
    }
    if (ans == INF) cout << 0 << "\n";
    else cout << ans << "\n";
    return 0;
}



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

int main(){
  	int N;
  	cin >> N;
  	while(N>=10){
    	N%=10;
    }
  	if(N==3){
    	cout << "bon" << endl;
    }else if(N==0 || N==1 || N==6 || N==8){
    	cout << "pon" << endl;
    }else{
    	cout << "hon" << endl;
    }
	return 0;
}

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

#define is_uruu leapyear
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define ROF(i,a,b) for(int i=(a);i>(b);--i)

typedef struct pp{
	char name[100];
	int t;
} P;

P queue[100000];
int head, tail, n;

void enqueue(P x){
	queue[tail] = x;
	tail = (tail+1)%100000;
}

P dequeue(){
	P x = queue[head];
	head = (head+1)%100000;
	return x;
}
    
int main() {
	int q, time=0;
	P tmp;
	cin >> n >> q;
	FOR(i, 0, n) cin >> queue[i].name >> queue[i].t;
	head = 0;
	tail = n;
	
	while(head != tail){
		P tmp = dequeue();
		if(tmp.t > q){
			tmp.t -= q;
			enqueue(tmp);
			time += q;
		} else {
			time += tmp.t;
			cout << tmp.name << " " << time << endl;
		}
	}
    return 0;
}


Measured memory_bytes: 13172
#include <bits/stdc++.h>
#define ft first
#define sc second
#define lb lower_bound
#define ub upper_bound
#define pb push_back
#define pt(sth) cout << sth << "\n"
#define chmax(a, b) {if(a<b) a=b;}
#define chmin(a, b) {if(a>b) a=b;}
#define moC(a, s, b) (a)=((a)s(b)+MOD)%MOD
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
static const ll INF=1e18;
static const ll MAX=1e5+7;
static const ll MOD=1e9+7;
ll max(ll a, ll b) {return a>b?a:b;}
ll min(ll a, ll b) {return a<b?a:b;}

ll N, K;
ll v[55];
ll mem[111][55][55];

ll rec(ll c, ll l, ll r) {
  if(mem[c][l][r]!=-1) return mem[c][l][r];
  if(l>=r) return 0;
  if(c>=K) return 0;
  
  ll res=0;
  chmax(res, v[l]+rec(c+1, l+1, r));
  chmax(res, v[r-1]+rec(c+1, l, r-1));
  chmax(res, rec(c+2, l+1, r));
  chmax(res, rec(c+2, l, r-1));
  
  return mem[c][l][r]=res;
}

int main(void) {
  cin >> N >> K;
  memset(mem, -1, sizeof(mem));
  for(ll i=0; i<N; i++) cin >> v[i];
  
  pt(rec(0, 0, N));
}



Measured memory_bytes: 2816
#include <bits/stdc++.h>
#define MAX_N N
#define rank fdfuhsfd
using namespace std;
typedef pair<int,int> P;
using namespace std;

class UF{
public:
  vector<int> par,rank;
  UF(){};
  UF(int n){
    rank.resize(n,0);
    par.resize(n);
    for(int i=0;i<n;i++)par[i]=i;
  }
  
  int find(int x){
    if(par[x]==x)return x;
    return par[x]=find(par[x]);
  }
  
  void unite(int x,int y){
    x=find(x);
    y=find(y);
    if(x==y)return;
    if(rank[x]<rank[y])par[x]=y;
    else{
      par[y]=x;
      if(rank[x]==rank[y])rank[x]++;
    }
  }
  
  bool same(int x,int y){return find(x)==find(y);}

};


void dfs(int pos,vector<vector<int> >&G,UF &U){
  for(int i=0;i<G[pos].size();i++){
    int nx=G[pos][i];
    if(U.same(pos,nx))continue;
    U.unite(pos,nx);
    dfs(nx,G,U);
  }
}

int main(){
  int n,k,l;
  cin>>n>>k>>l;

  vector<vector<int> > GK(n),GL(n);
  for(int i=0,a,b;i<k;i++){
    cin>>a>>b;
    a--,b--;
    GK[a].push_back(b);
    GK[b].push_back(a);
  }
  
  for(int i=0,a,b;i<l;i++){
    cin>>a>>b;
    a--,b--;
    GL[a].push_back(b);
    GL[b].push_back(a);
  }
  

  UF K(n),L(n);
  for(int i=0;i<n;i++)if(K.find(i)==i)dfs(i,GK,K);
  for(int i=0;i<n;i++)if(L.find(i)==i)dfs(i,GL,L);
  
  map<P,int> ans;
  for(int i=0;i<n;i++)ans[P(K.find(i),L.find(i))]++;
  for(int i=0;i<n;i++)cout<<ans[P(K.find(i),L.find(i))]<<endl;
  return 0;
}


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

int main(void) {
  int n;
  string s;
  cin >> n >> s;

  bool flag = true;
  if (n % 2 == 1) {
    flag = false;
  }
  else {
    rep (i, n / 2) {
      if (s[i] != s[i + n / 2]) flag = false;
    }
  }
  cout << (flag ? "Yes" : "No") << endl;
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
 
using namespace std;
 
#define all(x) x.begin(), x.end()
#define sz(x) (int) x.size()
#define pb push_back
#define endl '\n'
#define snd second
#define fst first
#define fastio cin.tie(NULL),cout.sync_with_stdio(true)

typedef long long int ll;
typedef unsigned long long int ull;
typedef vector <int> vi;
typedef pair <ll,ll> ii; 
typedef pair <ii,int> iii;
 
const int inf = 0x3F3F3F3F;
const ull mod = 998244353;

ll __mmc(ll a, ll b){
	return (a*b)/__gcd(a,b);
}

void solve(){
	ll a,b;
	cin >> a >> b;
	cout << __mmc(a,b) << endl;
}

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


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


int checkPalindrome(char str[],int len,int start) {
  int flag = 1;
  for(int i=start;i<len/2;i++) {
    if(str[i] != str[len-1-i]) {
      flag = 0;
    }
  }
  if(flag == 1) return 1;
  else return 0;
}

int main() {
  char str[100];
  scanf("%s",str);
  int len = strlen(str);
  int t1= checkPalindrome(str,len , 0);
  int t2 = checkPalindrome(str,(len-1)/2,0);
  int t3 = checkPalindrome(str,len,((len+3)/2)-1);
  if(t1&&t2&&t3) {
      printf("Yes");
  }
  else printf("No");
  return 0;
}


Measured memory_bytes: 128
require 'matrix'

n,m,l = gets.split.map{ |e| e.to_i}

a = Array.new(n)
b = Array.new(m)

n.times { |index|
  a[index] = gets.split.map{ |e| e.to_i}
}

m.times{ |index|
  b[index] = gets.split.map{ |e| e.to_i}
}

A = Matrix.rows(a)
B = Matrix.rows(b)

(A*B).to_a.each do |elem|
  puts elem.join(" ")
end

Measured memory_bytes: 7436
#include <iostream>
#include <fstream>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <vector>
#include <string>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <set>
#include <map>
#include <bitset>
#include <sstream>
#include <iomanip>

using namespace std;

typedef long long ll;
typedef vector <int> vi;
typedef vector <vector <int>> vii;
typedef vector <long long> vll;
typedef vector <string> vs;
typedef vector <char> vc;
typedef set <int> si;
typedef set <string> ss;
typedef queue <int> qi;
typedef queue <long long> qll;
typedef queue <string> qs;
typedef queue <char> qc;
typedef struct board board;
typedef pair <int, int> pi;
typedef pair <long long, long long> pll;
typedef pair <int, pair<int, int>> pii;

#define eb emplace_back
#define ppb pop_back
#define clr(a) a.clear()
#define F first
#define S second
#define mkp make_pair

#define sz(x) (int)(x).size()
#define all(x) (x).begin(), (x).end()

#define left(x) x * 2
#define right(x) x * 2 + 1

#define meme(a, b, c) fill(a + 1, a + 1 + b, c)

#define max(a, b) (a > b ? a : b)
#define min(a, b) (a > b ? b : a)
#define abs(a) (a > 0? a : -(a))

#define move(s) s += "#"

#define fr(i, a, b) for (ll i = a; i <= b; ++ i)
#define rf(i, a, b) for (ll i = a; i >= b; -- i)

#define eprintf(...) fprintf(stderr, __VA_ARGS__);

void to_pray() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    cerr << "Ready\n";
}

const int N = 4e6 + 10;
const int NN = 1e3 + 10;
const int NNN = 2e3 + 9;
const int MOD = 1e9 + 7;
const int INF = 1e9 + 7;
const ll LLINF = 1e12 + 7;
const ll P = 53;
const int EPS = 1e-9 - 8;
const int vN = 2e4 + 10;
const int sz = (1 << 22) - 1;
const double PI = acos(-1);

int main () {
    to_pray();

    int n;
    cin >> n;
   	
    string s;
    cin >> s;
    
    if (n & 1)
    	return cout << "No", 0;
    
    
   	int len = n / 2;
   	
   	for (int i = 0; i < len; ++ i) {
   		if (s[i] != s[i + len])
   			return cout << "No", 0;
   	}
   	cout << "Yes";
    
    //eprintf("%.18lf seconds\n", (double)clock() / CLOCKS_PER_SEC);
    cout << '\n';
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include<cmath>
#define N 100005
#define A 1000005
#define MOD 1000000007 // //100000000 998244353 //
#define inf 1000000000000000000
#define ll long long
//#define M_PI 3.141592653589793238463

using namespace std;

#define pii pair<ll, ll>
#define piii pair<ll, pii>
#define ft first
#define sd second
#define pb push_back
#define rep(i, n) for(ll i = 0; i < n; i++)
#define repr(i, n) for(ll i = n-1; i >= 0; i--)
#define itr(it, x) for(auto it = x.begin(); it != x.end(); it++)
#define mem(a, b) memset(a, (ll)b, sizeof(a))
#define all(v) v.begin(), v.end()
#define allr(v) v.rbegin(), v.rend()
#define edge(v, x, y) v[x].pb(y); v[y].pb(x);
#define popcount __builtin_popcount
#define ANS(s) {cout << s << "\n"; return;}

//~~~~~~fancy print~~~~~~~//
#define printpii(a) cout << a.ft << " " << a.sd << endl;
#define printpiii(a) cout << a.ft << " " << a.sd.ft << " " << a.sd.sd << endl;
#define print(a, n) rep(i, n) cout << a[i] << " "; cout << endl;
#define printv(v) for(auto x: v)cout << x << " "; cout << endl;
#define printm(a, n, m) rep(i, n) { rep(j, m) cout << a[i][j] << "\t"; cout << endl;}

ll lx[4] = {0, 0, 1, -1};
ll ly[4] = {1, -1, 0, 0};
ll dx[8] = {0, 0, 1, -1, 1, -1, 1, -1};
ll dy[8] = {1, -1, 0, 0, 1, 1, -1, -1};
void fast(){ios_base::sync_with_stdio(false);cin.tie(0);cout << setprecision(12) << fixed;}
ll lcm(ll a, ll b) {return (a*b)/__gcd(a, b); }

void solve()
{
    ll n;
    cin >> n;
    ll a[n];
    rep(i, n)cin >> a[i];
    ll ans = 0;
    for(ll i = 0; i < n; i++)
    {
        if(a[i] == i+1) ans++, swap(a[i], a[i+1]);
    } //print(a, n);
    if(a[n-1] == n) ans++;
    cout << ans;
}
int main(){
    /*#ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
    #endif*/
    fast();
    ll t = 1; //cin >> t;
    while(t--){
        solve();
    }
    return 0;
}


Measured memory_bytes: 1024
#include<cstdio>
#include<algorithm>
#include<cstring>
using namespace std;
char s[105],t[105];
int main()
{
	scanf("%s%s",s+1,t+1);
	int ans=0;
	for(int i=1;i<=3;i++)
	  if(s[i]==t[i])
	    ans++;
	printf("%d\n",ans);
	return 0;
}

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

#define ll long long

using namespace std;

int main(){
   string s;
   cin>>s;
   int n=s.length(),c=0;
   for(int i=0; i<n; i++){
       if(s[i]!=s[n-1-i]){
           c++;
       }
   }

cout<<c/2<<endl;

}


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

#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <queue>
#include <stack>
#include <map>
#include <set>

#include <functional>
#include <cassert>

typedef long long ll;
using namespace std;

#define debug(x) cerr << #x << " = " << x << endl;


#define mod 1000000007 //1e9+7(prime number)
#define INF 1000000000 //1e9
#define LLINF 2000000000000000000LL //2e18
#define SIZE 100010

/* Minimum Cost Flow */

struct MinimumCostFlow{

  typedef pair<int,int> P;
  
  struct edge {
    int to, cap, cost, rev;
    edge(int a, int b, int c, int d):to(a),cap(b),cost(c),rev(d){}
  };
  
  vector<vector<edge> > G;
  vector<int> h, dist, prevv, preve;
  int V;
  
  MinimumCostFlow(int v):G(v,vector<edge>()),prevv(v,0),preve(v,0),V(v){}
  
  int add_edge(int from,int to,int cap, int cost){
    int id = G[from].size();
    
    G[from].push_back(edge(to,cap,cost,G[to].size()));
    G[to].push_back(edge(from,0,-cost,G[from].size() - 1));
    
    return id;
  }

  int solve(int s, int t, int f){
    int res = 0;
    h.assign(V,0);
    while(f > 0){
      priority_queue<P, vector<P>, greater<P> > pq;
      dist.assign(V, INF);
      dist[s] = 0;
      pq.push(P(0, s));
      while(pq.size()){
        P p = pq.top(); pq.pop();
        int v = p.second;
        if(dist[v] < p.first) continue;

        for(int i = 0; i < G[v].size(); i++){
          edge &e = G[v][i];
          int d = dist[v] + e.cost + h[v] - h[e.to];
          if(e.cap > 0 && dist[e.to] > d){
            dist[e.to] = d;
            prevv[e.to] = v;
            preve[e.to] = i;
            pq.push(P(dist[e.to], e.to));
          }
        }
      }
      if(dist[t] == INF) return -1;

      for(int v = 0; v < V; v++) h[v] += dist[v];

      int d = f;
      for(int v = t; v != s; v = prevv[v])
        d = min(d, G[prevv[v]][preve[v]].cap);

      f -= d;
      res += d * h[t];

      for(int v = t; v != s; v = prevv[v]){
        edge &e = G[prevv[v]][preve[v]];
        e.cap -= d;
        G[v][e.rev].cap += d;
      }
    }

    return res;
  }

};


int main(){
  int v,e,f;
  int a,b,c,d;
  
  scanf("%d%d%d",&v,&e,&f);

  MinimumCostFlow flow(v);
  
  for(int i=0;i<e;i++){
    scanf("%d%d%d%d",&a,&b,&c,&d);

    flow.add_edge(a,b,c,d);
  }

  cout << flow.solve(0, v-1, f) << endl;
  
  return 0;
}

Measured memory_bytes: 3308
from sys import stdin
from sys import setrecursionlimit
from collections import Counter, deque, defaultdict
from math import floor, ceil
from bisect import bisect_left
from itertools import combinations
setrecursionlimit(100000)

INF = int(1e10)
MOD = int(1e9 + 7)

def main():
    from builtins import int, map
    N = int(input())
    A = list(map(int, input().split()))
    A.sort(reverse=True)
    total = 0
    for k in range(1, len(A)):
        # print(total, k, A[k], k // 2)
        total += A[k // 2]
    print(total)

if __name__ == '__main__':
    main()

Measured memory_bytes: 94268
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using PII = pair<ll, ll>;
#define FOR(i, a, n) for (ll i = (ll)a; i < (ll)n; ++i)
#define REP(i, n) FOR(i, 0, n)
#define ALL(x) x.begin(), x.end()
template<typename T> void chmin(T &a, const T &b) { a = min(a, b); }
template<typename T> void chmax(T &a, const T &b) { a = max(a, b); }
struct FastIO {FastIO() { cin.tie(0); ios::sync_with_stdio(0); }}fastiofastio;
#ifdef DEBUG_ 
#include "../program_contest_library/memo/dump.hpp"
#else
#define dump(...)
#endif
const ll INF = 1LL<<60;

int main(void) {
    ll h, w, q;
    cin >> h >> w >> q;
    vector<string> s(h);
    REP(i, h) cin >> s[i];

    vector<vector<ll>> v1(h+1, vector<ll>(w+1));
    REP(i, h) REP(j, w) v1[i+1][j+1] = s[i][j]-'0';
    REP(i, h) REP(j, w) v1[i+1][j+1] += v1[i][j+1]+v1[i+1][j]-v1[i][j];
    vector<vector<ll>> v2(h+1, vector<ll>(w));
    REP(i, h) REP(j, w-1) v2[i+1][j+1] = s[i][j]==s[i][j+1] && s[i][j]=='1';
    REP(i, h) REP(j, w-1) v2[i+1][j+1] += v2[i][j+1]+v2[i+1][j]-v2[i][j];
    vector<vector<ll>> v3(h, vector<ll>(w+1));
    REP(i, h-1) REP(j, w) v3[i+1][j+1] = s[i][j]==s[i+1][j] && s[i][j]=='1';
    REP(i, h-1) REP(j, w) v3[i+1][j+1] += v3[i][j+1]+v3[i+1][j]-v3[i][j];

    dump(v1);
    dump(v2);
    dump(v3);

    while(q--) {
        ll sx, sy, gx, gy;
        cin >> sy >> sx >> gy >> gx;

        ll vcnt = v1[gy][gx]-v1[sy-1][gx]-v1[gy][sx-1]+v1[sy-1][sx-1];
        ll ecnt = 0;
        if(sx < gx) ecnt += v2[gy][gx-1]-v2[gy][sx-1]-v2[sy-1][gx-1]+v2[sy-1][sx-1];
        if(sy < gy) ecnt += v3[gy-1][gx]-v3[gy-1][sx-1]-v3[sy-1][gx]+v3[sy-1][sx-1];

        cout << vcnt-ecnt << endl;
    }

    return 0;
}

Measured memory_bytes: 101888
#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;

int main()
{
  int N, T, A;
  cin >> N ;
  cin >> T >> A;
  
  vector<int> H(N+1);
  vector<int> Tem(N+1);
  vector<int> B(N+1);
  
  for (int i = 1; i < N+1; i++) {
    cin >> H.at(i) ;
  }
  
  for (int i = 1; i < N+1; i++) {
    Tem.at(i) = 1000 * T - H.at(i) * 6;
    B.at(i) = abs(1000 * A - Tem.at(i));
    }
  
  int C = B.at(1);
  int ans = 1;
    
  for (int i = 1; i < N ; i++) {
    if(C > B.at(i+1)) {
      C = B.at(i+1);
      ans = i+1;
    }
  }
  
  cout << ans << endl;
  return 0;
}



Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ll long long
#define pii pair<int,int>
#define F first
#define S second
#define mp make_pair
#define rep(i,n) for(int i=0;i<n;i++)
#define FOR(i,n,m) for(int i=n;i<=m;i++)
#define read(n) cin>>n;
#define write(n) cout<<n;
using namespace std;
int n,m;
int main()
{
	read(n);
	read(m);
	cout<<(n*(n-1)+m*(m-1))/2;
	return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<algorithm>
#include<set>
#include<cstdio>
#include<map>
using namespace std;
int main()
{
    string s,t,temp;
    set<string>S;
    int i,j;
    int lens,lent;
    bool can;
    cin>>s>>t;
    lens=s.size();
    lent=t.size();
    for(i=0;i<lens;i++)
    {
        temp=s;
        if(temp[i]=='?'||temp[i]==t[0])
        {
            can=false;
        for(j=0;j<i;j++)
        {
            if(temp[j]=='?')temp[j]='a';
        }
        for(j=0;j<lent;j++)
        {
            if(temp[i+j]!='?'&&temp[i+j]!=t[j])break;
            if(j==lent-1)can=true;
        }
        if(can)
        {
            for(j=0;j<lent;j++)
            {
                if(temp[i+j]=='?')temp[i+j]=t[j];
            }
            for(j=i+lent;j<lens;j++)
            {
                if(temp[j]=='?')temp[j]='a';
            }
            S.insert(temp);
        }
        }
    }
    if(S.size()==0)cout<<"UNRESTORABLE"<<endl;
    else cout<<*S.begin()<<endl;
}


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

typedef long long ll;
#define rep(i,n) for(int (i)=0;(i)<(int)(n);++(i))
#define each(itr,c) for(__typeof(c.begin()) itr=c.begin(); itr!=c.end(); ++itr)
#define all(x) (x).begin(),(x).end()
#define mp make_pair
#define pb push_back
#define fi first
#define se second

//???i?????§??????????±???????,?????¨??????j
int dp[3010][3010]={0};

int main()
{
    int n,t,s;
    cin >>n >>t >>s;
    vector<int> a(n),b(n);
    rep(i,n) cin >>a[i] >>b[i];


    rep(i,n)
    {
        rep(j,t+1)
        {
            //?????°??????
            dp[i+1][j]=max(dp[i+1][j],dp[i][j]);
            //?????¶
            int nx=j+b[i];
            if(nx>t || (j<s && s<nx)) continue;
            dp[i+1][nx]=max(dp[i+1][nx],dp[i][j]+a[i]);
        }
    }

    int ans=0;
    rep(i,t+1) ans=max(ans,dp[n][i]);
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 38420
#include <iostream>
 
using namespace std;
 
int main(){
  int a_input, b_input, c_input, d_input;
  cin >> a_input >> b_input >> c_input >> d_input;
  int comb_cnt = 0;
  for(int yen_500 = 0; yen_500 <= a_input; ++yen_500){
    for(int yen_100 = 0; yen_100 <= b_input; ++yen_100){
      for(int yen_50 = 0; yen_50 <= c_input; ++yen_50){
        if(yen_500 * 500 + yen_100 * 100 + yen_50 * 50 == d_input) ++comb_cnt;
      }
    }
  }
  cout << comb_cnt << endl;
 return 0; 
}

Measured memory_bytes: 256