akhauriyash/Code-Regression huggingface dataset:
from __future__ import print_function
import sys
input = sys.stdin.readline

def eprint(*args, **kwargs):
    print(*args, file=sys.stderr, **kwargs)

# import numpy as np
# import numpypy as np

# import math
# import string
# import fractions
# import re
# import array
# import copy
# import functools
# import operator
# import queue
from queue import Queue
# from queue import PriorityQueue as PQueue

# import collections
# import itertools
# import bisect
# import heapq

from heapq import heappush
from heapq import heappop
from heapq import heapify
# from itertools import accumulate
# from collections import deque
# import random


class PQueue (Queue):
    '''Variant of Queue that retrieves open entries in priority order (lowest first).
    Entries are typically tuples of the form:  (priority number, data).
    '''
    def _init(self,maxsize=0):
        self.queue = []

    def set(self,x_queue):
        self.queue=x_queue
    def _qsize(self):
        return len(self.queue)

    def _put(self, item):
        heappush(self.queue, item)

    def _get(self):
        return heappop(self.queue)


def main():
    # 
    n,m = map(int, input().split())
    cards = list(map(lambda x:x,(map(int, input().split()))))
    # eprint(cards)
    heapify(cards)
    # eprint(sum(cards))
    # eprint("cards",cards)
    
    pq = PQueue()
    pq.set(cards)
    # print(pq)
    # eprint(pq.qsize())
    # while pq.qsize():
        # eprint(pq.get())


    # 
    tuple_list = []
    for i in range(m):
        b,c = map(int, input().split())
        tuple_list.append([c,b])
    tuple_list.sort()
    # eprint(tuple_list)



    cnt=0
    while cnt<n and len(tuple_list):
        temp=tuple_list.pop()
        # eprint(temp[1])
        while temp[1]>0:
            # eprint("WTF")
            pq.put(temp[0])
            if pq.qsize()>n:
                pq.get()
            cnt+=1
            temp[1]-=1

    print(sum(pq.queue))
if __name__ == '__main__':
    main()

###
# n==10^5枚のカードを，m==10^5回の操作で置き換えていく
# 
# 
# 


Measured memory_bytes: 103444
import qualified Data.ByteString.Char8 as BS
import qualified Data.List as L
import qualified Data.Set as S
import qualified Control.Monad as M
import Data.Maybe (fromJust)
import Data.Ord
import qualified Data.Vector.Unboxed as V

main = do
 [n,k] <- map read <$> words <$> getLine
 h <- V.fromList <$>(1:)<$>map (fst.fromJust.BS.readInt) <$> BS.words<$>BS.getLine
 ab <- L.groupBy (\(x:_) (y:_) -> x == y) <$>L.sortBy (comparing head)<$>concat <$>M.replicateM k gen
 let result = map (tester h) ab
 print ( (length$filter (null) result) + (n- (length result))  )

gen = do
 k<-map (fst.fromJust.BS.readInt) <$>BS.words<$>BS.getLine
 return [k,reverse k]

tester hlist list = filter (m<=) $map (hlist V.!) checker
 where
  checker = map last list
  m = hlist V.! (head $head list)


Measured memory_bytes: 70732
void main() {
	auto N = ri;
	auto h = readAs!(int[]);
	
	ulong cnt;
	while(h.sum != 0) {
		//h.writeln;
		bool last = false;
		foreach(i, v; h) {
			if(v > 0) {
				h[i]--;
				last = true;
			} else {
				if(last) cnt++;
				last = false;
			}
		}
		if(last) cnt++;
	}
	cnt.writeln;
}

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

import std.stdio;
import std.string;
import std.functional;
import std.algorithm;
import std.range;
import std.traits;
import std.math;
import std.container;
import std.bigint;
import std.numeric;
import std.conv;
import std.typecons;
import std.uni;
import std.ascii;
import std.bitmanip;
import core.bitop;

T readAs(T)() if (isBasicType!T) {
	return readln.chomp.to!T;
}
T readAs(T)() if (isArray!T) {
	return readln.split.to!T;
}

T[][] readMatrix(T)(uint height, uint width) if (!isSomeChar!T) {
	auto res = new T[][](height, width);
	foreach(i; 0..height) {
		res[i] = readAs!(T[]);
	}
	return res;
}

T[][] readMatrix(T)(uint height, uint width) if (isSomeChar!T) {
	auto res = new T[][](height, width);
	foreach(i; 0..height) {
		auto s = rs;
		foreach(j; 0..width) res[i][j] = s[j].to!T;
	}
	return res;
}

int ri() {
	return readAs!int;
}

double rd() {
	return readAs!double;
}

string rs() {
	return readln.chomp;
}


Measured memory_bytes: 256
N = int(input())
S = input()

dp = [[0 for _ in range(N)] for _ in range(N)]

ans = 0
for i in range(N):
    for j in range(i + 1, N):
        if S[i] == S[j]:
            tmp = 1
            if i > 0:
                tmp += dp[i - 1][j - 1]
            if j - i < tmp:
                continue
            dp[i][j] = tmp
        ans = max(ans, dp[i][j])
print(ans)

Measured memory_bytes: 247176
#include <iostream>
#include <vector>
#include <array>
#include <algorithm>
#include <cmath>
#include <cstdio>

using namespace std;
typedef long long ll;

int main(){
    ll n;
    cin >> n;
    vector<array<double, 3>> p;
    for(int i = 0; i < n; ++i){
        double x, y;
        cin >> x >> y;
        if(x == 0 && y == 0){ continue; }
        array<double, 3> tmp;
        tmp.at(0) = atan2(y, x);
        tmp.at(1) = x;
        tmp.at(2) = y;
        p.push_back(tmp);
    }
    sort(p.begin(), p.end());

    double ans = 0;
    for(int i = 0; i < p.size(); ++i){
        double x = 0, y = 0;
        for(int j = 0; j < p.size(); ++j){
            x += p.at((i + j) % p.size()).at(1);
            y += p.at((i + j) % p.size()).at(2);
            ans = max(ans, sqrt(x * x + y * y));
        }
    }
    printf("%.20f\n", ans);
    return 0;
}


Measured memory_bytes: 888
//=================================
// Created on: 2018/09/22 01:34:35
//=================================
#include <bits/stdc++.h>
using ll = long long;
using P = std::pair<ll, ll>;
constexpr ll INF = 1LL << 60;
int main()
{
    int N;
    std::cin >> N;
    const int M = 1 << N;
    std::vector<ll> A(M);
    for (int i = 0; i < M; i++) { std::cin >> A[i]; }
    auto update = [](const P& p1, const P& p2) {
        std::vector<ll> v{p1.first, p2.first, p1.second, p2.second};
        std::sort(v.begin(), v.end());
        return P{v[3], v[2]};
    };
    std::vector<P> B(M);
    for (int i = 0; i < M; i++) { B[i] = {A[i], 0}; }
    for (std::size_t i = 0; (1UL << i) < M; i++) {
        for (std::size_t j = 0; j < M; j++) {
            if (j & 1UL << i) { B[j] = update(B[j ^ 1UL << i], B[j]); }
        }
    }
    std::vector<ll> dp(M);
    auto sum = [](const P& p) { return p.second == 0 ? -INF : p.first + p.second; };
    for (int i = 0; i < M; i++) { dp[i] = sum(B[i]); }
    for (int i = 1; i < M; i++) { dp[i] = std::max(dp[i - 1], dp[i]); }
    for (int i = 1; i < M; i++) { std::cout << dp[i] << std::endl; }
    return 0;
}


Measured memory_bytes: 11264
#include <iostream>
#include <iomanip> //! for setprecision(10)
#include <math.h>
#include <algorithm>
#include <functional> 
#include <string>
#include <vector>

#include <cstring>
#include <set>
#include <map>
#include <queue>
#include <utility>

using namespace std;

typedef long long LL;

#define dump(c) { for (auto it = c.begin(); it != c.end(); ++it) if (it == c.begin()) cout << *it; else cout << ' ' << *it; cout << endl; } 
#define rep(i,n) for (int i = 0; i < (n); ++i)

const int MOD = 1000000007;

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

    int N;
    cin >> N;

    for (int x = 1; x <= 50000; ++x) {
        if (x * 108 / 100 == N) {
            cout << x << endl;
            return 0;
        }
    }

    cout << ":(" << endl;

    return 0;
}


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

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

    int n, a, b; cin >> n >> a >> b;
    string s; cin >> s;

    int total = 0;
    int brank = 0;
    for (int i = 0; i < s.size(); i++) {
        char c = s[i];
        if (total >= a+b || c == 'c') {
            cout << "No\n";
            continue;
        }

        if (c == 'a') {
            cout << "Yes\n";
            ++total;
        }
        else if (c == 'b' && brank < b) {
            cout << "Yes\n";
            ++brank;
            ++total;
        }
        else {
            cout << "No\n";
        }
    }

    return 0;
}



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

int main()
{
	ll n,m;
	cin>>n>>m;
	ll x;
	priority_queue <ll> val;
	for(ll i=0; i<n; i++)
	{
		scanf("%lld",&x);
		val.push(x);
	}		
	while(m)
	{
		int b=val.top();
		val.pop();
		b=b/2;
		val.push(b);
		m--;
	}
	ll ans=0;
	while(!val.empty())
	{
		ans+=val.top();
		val.pop();
	}		
	cout<<ans;
	return 0;
}

Measured memory_bytes: 1400
typedef long long ll;
#include <bits/stdc++.h>
using namespace std;
template<typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val){
    std::fill( (T*)array, (T*)(array+N), val );
}

ll mod = 1000000000+7;
long long modpow(long long a, long long n, long long mod) {
  long long res = 1;
  while (n > 0) {
      if (n & 1) res = res * a % mod;
      a = a * a % mod;
      n >>= 1;
  }
  return res;
}

int main() {
    ll n,q;
    string s;
    std::cin >> n>>q;
    std::cin >> s;
    ll sum[100010];
    sum[0] = 0;
    sum[1] = 0;
    for (int i = 1; i < n; i++) {
        sum[i+1] = sum[i];
        if(s[i-1] == 'A' && s[i] == 'C'){
            sum[i+1]++;
        }
    }
    for (int i = 0; i < q; i++) {
        ll tmp_l,tmp_r;
        std::cin >> tmp_l>>tmp_r;
        tmp_l--;
        tmp_r--;
        if(tmp_l>0){
            if( s[tmp_l-1] == 'A' && s[tmp_l] == 'C' ){
                std::cout << sum[tmp_r+1] - sum[tmp_l+1] << std::endl;
            }else{
                std::cout << sum[tmp_r+1] - sum[tmp_l] << std::endl;
            }
        }else{
            std::cout << sum[tmp_r+1] - sum[tmp_l] << std::endl;
        }
    }
}


Measured memory_bytes: 1792
#include <bits/stdc++.h>
using namespace std;
int main(){
    int a,b,c;
    cin >> a >> b >> c;
    if(a+b==c || b+c==a || c+a==b){
        cout << "Yes" << endl;
    }
    else{
        cout << "No" << endl;
    }
}


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

using namespace std;

const int N = 17, M = (1 << 15) + 5, mod = 1e9 + 7;

int n, m;
int f[M], _cnt[M];
int G[N];
int p[N];

inline bool chk(int s) {
	return ((s&1) ^ ((s>>1) & 1));
}

int main() {
	int sz;
	cin >> n >> m;
	sz = (1 << n) - 1;
	for (int i=1, u, v; i<=m; ++i) { 
		cin >> u >> v;
		G[u] |= (1 << v-1);
	}
	for (int S = 0; S <= sz; ++S) 
		for (int i=0; i<n; ++i) if((S >> i) & 1) ++_cnt[S];
	f[0] = 1;
	for (int S = 1; S <= sz; ++S) {
		if(chk(S)) continue;
		for (int U = S; U; U = (U-1) & S) {
			if(chk(U)) continue;
			int T = (S ^ U), res = 1;
			for (int i=1, t; i<=n; ++i) {
				if(!((S >> i-1) & 1)) continue;
				if((T >> i-1) & 1) {
					t = (1 << _cnt[G[i] & U]) - 1;
					t %= mod;
					res = 1ll * res * t % mod;		
				} else {
					t = (1 << _cnt[G[i] & T]);
					t %= mod;
					res = 1ll * res * t % mod;
				}
			}
			f[S] += 1ll * res * f[T] % mod;
			if(f[S] >= mod) f[S] -= mod;
		}
	}
	int tot = 1;
	for (int i=1; i<=m; ++i) {
		tot <<= 1;
		if(tot >= mod) tot -= mod;
	}
	tot -= f[sz];
	if(tot < 0) tot += mod;
	cout << tot << endl;
	
	return 0;
}

 

Measured memory_bytes: 512
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cstring>
using namespace std;
typedef long long ll;

int main()
{
	//ios_base::sync_with_stdio(false); cin.tie(NULL);
	//freopen("input.in","r",stdin);
	int n, x; cin >> n >> x;
	int minCost = 99999;
	for (int i = 0; i < n; i++) {
		int mi; cin >> mi;
		minCost = min(minCost,mi);
		x -= mi;
	}
	int ans = n + (x/minCost);
	cout << ans << '\n';
	
	
	return 0;
}

Measured memory_bytes: 256
n, m = map(int, input().split())
ls = []
for _ in range(m):
    k, *s, = map(lambda x: int(x)-1, input().split())
    ls.append(s)
p = list(map(int, input().split()))
ans = 0


def dfs(x, s):
    global ans
    if x == n:
        for j in range(m):
            switchs = ls[j]
            cond = p[j]
            on_cnt = 0
            for switch in switchs:
                if int(s[switch]):
                    on_cnt += 1
            if on_cnt % 2 != cond:
                break
        else:
            ans += 1
    else:
        for c in "01":
            dfs(x+1, s+c)


dfs(0, "")
print(ans)


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

using namespace std;

typedef long long int lli;

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

    int n, q, a, b;
    cin >> n >> q;
    vector<vector<int>> tree(n+1, vector<int>());

    for (int i=0; i<n-1; i++) {
        cin >> a >> b;
        tree[a].push_back(b);
        tree[b].push_back(a);
    }

    int p, x;
    vector<int> ans(n+1, 0);
    for (int i=0; i<q; i++) {
        cin >> p >> x;
        ans[p] += x;
    }

    vector<int> used(n+1, 0);
    queue<int> qu;
    qu.push(1);
    while (!qu.empty()) {
        int crnt = qu.front(); qu.pop();
        
        used[crnt] = 1;
        for (auto x : tree[crnt]) {
            if (used[x]) continue;
            qu.push(x);
            ans[x] += ans[crnt];
        }
    }

    for (int i=0; i<n; i++) cout << ans[i+1] << ((i<n-1) ? ' ' : '\n');

    return 0;
}


Measured memory_bytes: 16372
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define PI arccos(-1)
#define rep(i, N) for (int i = 0; i < (N); i++)
#define REP(i, a, N) for (int i = a; i < (N); i++)
#define rrep(i, N, k) for (int i = (N); i >= (k); i--);
#define all(x) (x).begin(), (x).end()
#define vi vector<int>
#define pi pair<int, int>
#define pl pair<ll, ll>
template<class T> istream &operator>>(istream&is,vector<T>&v){for(auto &elemnt:v)is>>elemnt;return is;}
template<class T,class U> istream &operator>>(istream&is,pair<T,U>&p){is>>p.first>>p.second;return is;}
const int MOD = 1e9+ 7;
const int INF = numeric_limits<int>::max() - (int)1e8;
const ll INFLL = numeric_limits<ll>::max() - (ll)1e17;

int main() {
    int N;
    cin >> N;
    vector<pair<ll, int>> A(N);
    for (int i = 0; i < N; i++) {
        int temp;
        cin >> temp;
        A[i] = {temp, i + 1};
    }
    sort(A.rbegin(), A.rend());
    vector<vector<ll>> dp(N + 1, vector<ll>(N + 1, 0));
    for (int i = 0; i < N; i++) {
        for (int right = 0; right <= i; right++) {
            int left = i - right;
            dp[left + 1][right] = max(dp[left + 1][right], dp[left][right] + A[i].first * abs((left + 1) - A[i].second));
            dp[left][right + 1] = max(dp[left][right + 1], dp[left][right] + A[i].first * abs((N - right) - A[i].second));
        }
    }
    ll ans = 0;
    for (int i = 0; i <= N; i++) ans = max(ans, dp[i][N - i]);
    cout << ans << endl;
}


Measured memory_bytes: 34672
#include<bits/stdc++.h>
using namespace std;
char sth[4][15]={"dream","dreamer","erase","eraser"},s[100005],len[4],cnt;
int dp[100005],n;
int main()
{
	scanf("%s",s+1);
	for(int i=1;s[i];i++)
	{
		++n;
	}
	for(int i=0;i<4;i++)
	{
		len[i]=strlen(sth[i]);
	}
	dp[0]=1;
	for(int i=1;i<=n;i++)
	{
		for(int j=0;j<4;j++)
		{
			if(i-len[j]>=0)
			{
				cnt=0;
				for(int k=0;k<len[j];k++)
				{
					if(sth[j][k]==s[i-len[j]+k+1])
					{
						++cnt;
					}
				}
				if(cnt==len[j])
				{
					dp[i]=dp[i-len[j]];
				}
			}
		}
	}
	if(dp[n]==1)
	{
		printf("YES");
	}else
	{
		printf("NO");
	}
}

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

#define MEM(a, b) memset(a, (b), sizeof(a))
#define PI 3.1415926535897932384626433832795
#define endl '\n'
#define exists(s, e) (s.find(e)!=s.end())
#define WHILE(n)
#define pb push_back
#define f first
#define s second
#define UNI(vec) vec.erase(std::unique(vec.begin(), vec.end()),vec.end());
#define scan(x) do{while((x=getchar())<'0'); for(x-='0'; '0'<=(_=getchar()); x=(x<<3)+(x<<1)+_-'0');}while(0)
char _;
typedef long long ll;
typedef long double ld;
typedef std::pair<int, int> pii;
typedef std::pair<int, pii> piii;

const int INF = 0x3f3f3f3f;
#define MAXN 3001
using namespace std;
int n,m,ans;
int dp[MAXN][MAXN];

int main(){
    cin.sync_with_stdio(0);
    cin.tie(0); cout.tie(0);
    string s,ss;
    cin>>s>>ss;
    for (int i =1; i <= s.length(); i++){
        for(int j = 1; j <= ss.length(); j++){
            if(s[i-1] == ss[j-1]){
                dp[i][j] = dp[i-1][j-1] + 1;
            }
            else{
                dp[i][j] = max(dp[i-1][j], dp[i][j-1]);
            }
        }
    }
    stack<char> a;
    int i = s.length(), j = ss.length();
    while(i!=0 && j!=0){
        if(max(dp[i][j-1], dp[i-1][j]) < dp[i][j]){
            a.push(s[i-1]);
            i--; j--;
        }
        else{
            if(dp[i-1][j] >= dp[i][j-1]){
                i--;
            }
            else{
                j--;
            }
        }
    }
    while(!a.empty()){
        cout<<a.top();
        a.pop();
    }
    //cout<<dp[s.length()][ss.length()];


}


Measured memory_bytes: 35456
#!/usr/bin/env python3
import sys


def solve(N: int, A: "List[int]", B: "List[int]"):

    s = [0] * N
    for i in range(N):
        s[i] = A[i]-B[i]

    s.sort()
    minus = sum([i for i in s if i < 0])
    minus_len = len([i for i in s if i < 0])
    plus =  sum([i for i in s if i >= 0])

    if(minus+plus < 0):
        print(-1)
        exit()

    s.sort(reverse=True)

    ans = 0
    while minus < 0:
        minus += s[ans]
        ans += 1

    print(ans + minus_len)

    return


# Generated by 1.1.5 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    A = [int(next(tokens)) for _ in range(N)]  # type: "List[int]"
    B = [int(next(tokens)) for _ in range(N)]  # type: "List[int]"
    solve(N, A, B)

if __name__ == '__main__':
    main()


Measured memory_bytes: 23592
#include <bits/stdc++.h>
#include <algorithm>
#include <stdio.h>
#include <math.h>
using namespace std;

#define INF 1.1e9
#define LINF 1.1e18
#define FOR(i,a,b) for (int i = (a); i < (b); ++i)
#define REP(i,n) FOR(i,0,n)
#define ALL(v) (v).begin(), (v).end()
#define pb push_back
#define pf push_front
#define fi first
#define se second
#define BIT(x,n) bitset<n>(x)

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

struct edge {
	int to,cost;
	edge(int t,ll c):to(t),cost(c) {}
};

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

ll mypow(ll x,ll n,ll m) {	//xのn乗をmで割った余り
	if(n==0) return 1;
	if(n%2==0) return mypow(x*x%m,n/2,m);
	else return x*mypow(x,n-1,m)%m;
}

//-----------------------------------------------------------------------------

string s;
int g,p;
int w,l;

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

	cin>>s;
	REP(i,s.size()) {
		int flg=0;
		if(s[i]=='p') {
			if(g-p>=1) p++,flg=1;
			else g++,l++;
		}
		else {
			if(g-p>=1) p++,w++,flg=1;
			else g++;
		}
	}
	cout<<w-l<<endl;

	return 0;
}


Measured memory_bytes: 512
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<stack>
#include<queue>
#include<map>
using namespace std;

int main(){
    int l,r,d;
    cin>>l>>r>>d;
    int ans=0;
    for(int i=l;i<=r;++i){
        if(i%d==0) ++ans;
    }

    cout<<ans<<endl;
}

Measured memory_bytes: 3588
import sys
n=int(input())
A=list(map(int,input().split()))
for i in range(n):
    A[i]=A[i]-(i+1)
if n==1:
    print(0)
    sys.exit(0)
A2=sorted(A)
ans=0
center=A2[(n-1)//2]
for i in range(n):
    ans+=abs(A2[i]-center)
print(ans)

Measured memory_bytes: 25196
// Author: wlzhouzhuan
#pragma GCC optimize(2)
#pragma GCC optimize(3)
#include <bits/stdc++.h>
using namespace std;

#define ll long long
#define ull unsigned long long
#define rint register int
#define rep(i, l, r) for (rint i = l; i <= r; i++)
#define per(i, l, r) for (rint i = l; i >= r; i--)
#define mset(s, _) memset(s, _, sizeof(s))
#define pb push_back
#define pii pair <int, int>
#define mp(a, b) make_pair(a, b)
#define debug(x) cerr << #x << " = " << x << '\n';
#define pll pair <ll, ll>
#define fir first
#define sec second

inline int read() {
  int x = 0, neg = 1; char op = getchar();
  while (!isdigit(op)) { if (op == '-') neg = -1; op = getchar(); }
  while (isdigit(op)) { x = 10 * x + op - '0'; op = getchar(); }
  return neg * x;
}
inline void print(int x) {
  if (x < 0) { putchar('-'); x = -x; }
  if (x >= 10) print(x / 10);
  putchar(x % 10 + '0');
}

const int N = 10;
char tmp[N][N];
int a[N][N], b[N][N];
int n, m, k, ans;

int main() {
  scanf("%d%d%d", &n, &m, &k);
  for (rint i = 1; i <= n; i++) {
    scanf("%s", tmp[i] + 1);
    for (rint j = 1; j <= m; j++) {
      if (tmp[i][j] == '#') a[i][j] = 0;
      else a[i][j] = 1;
    }
  }
  int st1 = 1 << n, st2 = 1 << m;
  for (rint i = 0; i < st1; i++) {
    for (rint j = 0; j < st2; j++) {
      for (rint t = 1; t <= n; t++) {
        for (rint tt = 1; tt <= m; tt++) {
          b[t][tt] = a[t][tt];
        }
      }
      for (rint k = 0; k < n; k++) {
        if (i >> k & 1) {
          for (rint t = 1; t <= m; t++)
            b[k + 1][t] = 2;
        }
      }
      for (rint k = 0; k < m; k++) {
        if (j >> k & 1) {
          for (rint t = 1; t <= n; t++)
            b[t][k + 1] = 2;
        }
      }
      int tot = 0;
      for (rint t = 1; t <= n; t++) {
        for (rint tt = 1; tt <= m; tt++) {
          if (!b[t][tt]) {
            tot++;
          }
        }
      }
      if (tot == k) ans++;
    }
  }
  cout << ans;
}

Measured memory_bytes: 3760
#include <iostream>
#include <stdlib.h>
#include <vector>
#include <algorithm>
#include <queue>
#include <string>
using namespace::std;

int main(){
    int n,i,k;
    long long int a[1000000];

    cin >> n;
    for(i = 0;i<n;i++){
        cin >> k;
        a[k-1] = i+1;
    }

    for ( i = 0;i<n;i++){
        cout << a[i] << " ";
    }
}

Measured memory_bytes: 3200
N = int(input())
S = list(input())

count = []

if len(S) == 2:
    if S[0] == S[1]:
        count.append(1)
    else:
        count.append(0)
else:
    for i in range(1,N-1):
        sum = 0
        sita = S[0:i]
        usiro = S[i:N]

        #print(sita,usiro)
        sita = list(set(sita))
        usiro = list(set(usiro))

        #print(sita,usiro)
        for x in range(len(sita)):
            if sita[x] in usiro:
                sum += 1

        count.append(sum)

print(max(count))


Measured memory_bytes: 3064
#include <iostream> 
#include <string> 
#include <vector> 
#include <cmath> 
#include <algorithm> 
#include <cstdlib> 
#include <ctime> 
#include <cstdio> 
#include <functional> 
#include <set> 
#include <sstream> 
#include <cctype>
#include <stack>
#include <queue>
#include <cstring>
#include <map>
#include <list>
#include <cassert>
 
using namespace std; 

int main(){

	string s;
	cin>>s;

	int n=s.size()-1;
	long long sum=0;

	for(int bit=0;bit<(1<<n);bit++){
		string eq;
		int cnt=__builtin_popcount(bit);
		for(int i=0;i<n;i++){
			eq+=s[i];
			if(bit&(1<<i)) eq+='+';
		}
		eq+=s[n];
		stringstream ss;
		ss<<eq;

		long long x;
		for(int i=0;i<=cnt;i++){
			ss>>x;
			sum+=x;
		}

	}
	cout<<sum<<endl;

}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
using namespace std;
int n, m, mn=1e9, a[35][35], b, c[5][35];

int f(int p, int q, int r) {
	int i, re = 0;
	for (i = 1; i <= m; i++) re += c[0][i] * a[i][p] + c[1][i] * a[i][q] + c[2][i] * a[i][r];
	return re;
}

int main() {
	int i, j, k, t;
	scanf("%d%d", &n, &m);
	for(i=1; i<=m; i++) for(j=1; j<=m; j++) scanf("%d", &a[i][j]);
	for(i=1; i<=n; i++) for(j=1; j<=n; j++) {
		scanf("%d", &t);
		c[(i+j) % 3][t]++;
	}
	for(i=1; i<=m; i++)
		for(j=1; j<=m; j++)
			for(k=1; k<=m; k++)
				if (i != j && i != k && j != k)
					mn = min(mn, f(i, j, k));
	printf("%d", mn);
	return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
const int maxn = 205;

int n, m, Tst, t[30];
char s[maxn][maxn];

void work1()
{
	int res = 0;
	for(int i = 1; i <= 26; ++i)
		res += (t[i] & 1);
	if(res != 1)
	{
		printf("No\n");
		return ;
	}
	res = 0;
	for(int i = 1; i <= 26; ++i)
		res += ((t[i] % 4) == 2 || (t[i] % 4) == 3);
	if(res > ((n + m - 2) >> 1))
	{
		printf("No\n");
		return ;
	}	
	printf("%s\n", ((((n + m - 2) >> 1) - res) & 1) == 0? "Yes": "No");
}

void work2()
{
	int res = 0;
	for(int i = 1; i <= 26; ++i)
		res += (t[i] & 1);
	if(res != 0)
	{
		printf("No\n");
		return ;
	}
	for(int i = 1; i <= 26; ++i)
		res += ((t[i] % 4) == 2);
	if(res > (m >> 1))
	{
		printf("No\n");
		return ;
	}	
	printf("Yes\n", (((m >> 1) - res) & 1) == 0? "Yes": "No");
}

void work3()
{
	int res = 0;
	for(int i = 1; i <= 26; ++i)
		res += (t[i] & 1);
	if(res != 0)
	{
		printf("No\n");
		return ;
	}
	for(int i = 1; i <= 26; ++i)
		res += ((t[i] % 4) == 2);
	if(res > (n >> 1))
	{
		printf("No\n");
		return ;
	}	
	printf("Yes\n", (((n >> 1) - res) & 1) == 0? "Yes": "No");
}

void work4()
{
	for(int i = 1; i <= 26; ++i)
		if((t[i] % 4) != 0)
		{
			printf("No\n");
			return ;
		}
	printf("Yes\n");
}

int main()
{
	scanf("%d%d", &n, &m);
	for(int i = 1; i <= n; ++i)
	{
		scanf("%s", s[i] + 1);
		for(int j = 1; j <= m; ++j)
			++ t[s[i][j]-'a'+1];
	}
	if((n & 1) == 1 && (m & 1) == 1)
		work1();
	else if((n & 1) == 1 && (m & 1) == 0)
		work2();
	else if((n & 1) == 0 && (m & 1) == 1)
		work3();
	else
		work4();
	return 0;
}


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

int map[52][52];

void Serch(int i,int j){
  int dis[3] = {-1,0,1};
  map[i][j] = 0;
  for(int p=0;p<3;p++){
      for(int q=0;q<3;q++){
        if(p == 1 && q == 1) continue;
        if(map[i+dis[p]][j+dis[q]] == 1) Serch(i+dis[p],j+dis[q]);
      }
  }

 return;
}

int main(){
  int w,h;

  while(cin >> w >> h){
    int count = 0;
    if(!(w|h)) break;

    for(int i=0;i<w+2;i++)map[0][i] = map[h+1][i] = 0;
    for(int i=0;i<h+2;i++)map[i][0] = map[i][w+1] = 0;

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

    for(int i = 1;i<h+1;i++){
      for(int j = 1;j<w+1;j++){
        if(map[i][j] == 1){
          Serch(i,j);count++;
        }
      }
    }

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

  return 0;
}

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

int main() {
	int n;
	cin >> n;
	vector<P> a(n);
	rep(i,n) {
		a[i].second = i + 1;
		cin >> a[i].first;
	}
	sort(a.begin(), a.end());
	rep(i,n) {
		cout << a[i].second << " ";
	}
	return 0;
}


Measured memory_bytes: 1536
#include<bits/stdc++.h>
using namespace std;
int A[11];
int a[51],b[51],c[51],d[51];
int n,m,q,cnt=0,maxc=0;
void dfs(int t,int k)
{
//	cout<<t<<" "<<k<<endl;
	if(t==1)
	{
		for(int i=k;i>=1;i--)
		{
			cnt=0;
			A[1]=i;
			for(int j=0;j<q;j++)
			{
				if(A[b[j]]-A[a[j]]==c[j])
					cnt+=d[j];
			}
			maxc=max(maxc,cnt);
		}
		return;
	}
	else
	{
	
		for(int i=k;i>=1;i--)
		{
			A[t]=i;
			dfs(t-1,i);
		}
	}
}
int main()
{
	cin>>n>>m>>q;
	for(int i=0;i<q;i++)
	{
		cin>>a[i]>>b[i]>>c[i]>>d[i];
	}
	dfs(n,m);
	cout<<maxc;
	return 0;
 } 

Measured memory_bytes: 3624
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<cmath>
#include<map>
#include<cstdio>
#include<stack>
#include<queue>
#include<fstream>
#include<cstdio>
#include<deque>
#include<iomanip>
#include <numeric>
//#include<bits/stdc++.h>

using namespace std;
#define ok1 printf("ok1\n");
#define ok2 printf("ok2\n");
#define M 1000000000000000000LL
#define rep(i,n) for(int i=0;i<n;i++)
#define REP(i,s,n) for(int i=(s);i<(n);i++)
#define repr(i,n) for(int i=n-1;i>=0;i--)
#define REPR(i,s,n) for(int i=(s);i>=(n);(i)--)
#define all(a) (a).begin(),(a).end()
#define reall(a) (a).rbegin(),(a).rend()
#define pb push_back
#define pf push_front
#define MIN(a,b) a=min((a),(b))
#define MAX(a,b) a=max((a),(b))
#define SIZE(v) (int)v.size()
const double pi = acos(-1.0);

typedef vector<int> vi;
typedef vector<string> vs;
typedef long long ll;
typedef vector<ll> vll;
typedef vector<vi> vvi;
typedef deque<ll> dll;
typedef pair<ll, ll> P;
#define mod 1e9 + 7;
ll gcd(ll x, ll y)
{
	ll r;
	while ((r = x % y) != 0)
	{
		x = y;
		y = r;
	}
	return y;
}
ll lcm(ll x, ll y)
{
	x /= gcd(x, y);
	y /= gcd(x, y);
	return (x * y);
}


int main() {
	ll n;
	ll a, b;
	while (cin >> n) {
		ll ans = 0;
		vi v, w;
		rep(i, n) {
			cin >> a >> b;
			v.pb(a);
			w.pb(b);
		}


		rep(i, n) {
			ans += (w[i] - v[i] + 1);
		}

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

Measured memory_bytes: 256
n = int(input())
i = 0

l = list(map(int, input().split()))
Max = l[0]
Min = l[0]
sum = 0
for i in range(0,n):
	sum += l[i]
	a = l[i]#変数の値が下の行の処理で変わってしまうのでaとかにしておく
	if a > Max:
		a,Max = Max,a
	if  a < Min:
		a,Min = Min,a
	
	
print(f"{Min} {Max} {sum}")
	


Measured memory_bytes: 6612
#include <bits/stdc++.h>
using namespace std;
typedef pair<int,int> P;
typedef long long ll;
typedef long double ld;
const int inf=1e9+7;
const ll longinf=1LL<<60;
#define REP(i,m,n) for(int i=(int)(m) ; i < (int) (n) ; ++i )
#define rep(i,n) REP(i,0,n)
#define F first
#define S second
 
const int mx=100010;
const ll mod=1e9+7;


int main(){
  int n,a,b;
  cin >> n >> a >> b;
  cout << min(n*a,b) << endl;
  return 0;
}

Measured memory_bytes: 256
from sys import exit
S = input()
N = len(S)
if S != S[::-1]:
    print("No")
    exit()
if S[:(N - 1) // 2] != S[:(N - 1) // 2:-1]:
    #print(S[:(N - 1) // 2],)
    print("No")
    exit()
if S[(N + 3) // 2 - 1:] != S[(N + 3) // 2 - 1:][::-1]:
    #print(S[(N + 3) // 2 - 1:],S[(N + 3) // 2 - 1:][::-1])
    print("No")
    exit()
print("Yes")


Measured memory_bytes: 38384
#include <stdio.h>
#define MAX 2000001
#define INF 10000000
#define size 20

int H,A[MAX];

void swap(int *a,int *b){
  int temp;
  temp=*a;
  *a=*b;
  *b=temp;
}

void maxHeapify(int i){
  int l,r,largest;
  l=2*i;
  r=2*i+1;

  //????????????????????????????????§???????????§????????????????????¶
  if(l<=H&&A[l]>A[i]) largest=l;
  else largest = i;
  if(r<=H&&A[r]>A[largest]) largest=r;

  if(largest!=i){
    swap(&A[i],&A[largest]);
    maxHeapify(largest);
  }
}

int extract(){
  int max;
  if(H<1) return -INF;
  max=A[1];
  A[1]=A[H--];
  maxHeapify(1);
  return max;
}

void increaseKey(int i, int key){
  if(key<A[i]) return;
  A[i]=key;
  while(i>1&&A[i/2]<A[i]){
    swap(&A[i],&A[i/2]);
    i/=2;
  }
}

void insert(int key){
  H++;
  A[H]=-INF;
  increaseKey(H,key);
}

int main(){
int key;
char str[size];

  while(1){
    scanf("%s",str);
    if(str[0]=='e'&&str[1]=='n') break;
    if(str[0]=='i'){
      scanf("%d",&key);
      insert(key);
    } else{
      printf("%d\n", extract());
    }
  }
  return 0;
}

Measured memory_bytes: 4696
import java.util.*;
import java.io.PrintWriter;
public class Main{
	public static void main(String[] args){
		Scanner sc=new Scanner(System.in);
		String s=sc.next();
		int counta=0;
		int countb=0;
		for(int i=0; i<3; i++){
			if(s.charAt(i)=='A'){
				counta++;
			}else{
				countb++;
			}
		}
		if(counta==3 || countb==3){
			System.out.println("No");
		}else{
			System.out.println("Yes");
		}
	}
}


Measured memory_bytes: 21588
const main = (inputs) => {
  var N = inputs[0].split(" ")[0]-0;
  var ans = 0;
  for(var i=1;i<=N;i++){
    if((i).toString().length%2==1)
      ans++; 
  }
  
  console.log(ans);
}

main(require('fs').readFileSync('/dev/stdin', 'UTF-8').trim().split("\n"));


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

ll a[MAX_N],N,S,W,Q;
map<ll,ll> mp;

int main(){
  while(1){
    cin>>N>>S>>W>>Q;
    if(N==0&&S==0&&W==0&&Q==0)break;
    ll g = S;
    for(int i=0; i<N; i++) {
      a[i] = (g/7) % 10;
      if( g%2 == 0 ) { g = (g/2); }
      else           { g = (g/2) ^ W; }
    }
    if(Q==2||Q==5){
      int ans=0,cnt=0;
      for(int i=0;i<N;i++){
        if(a[i]!=0)cnt++;
        if(a[i]%Q==0)ans+=cnt;
      }
      cout<<ans<<endl;
      continue;
    }
    
    mp.clear();
    mp[0]=1;
    ll B=1,k=0,ans=0;
    for(int i=N-1;i>=0;i--){
      k+=(B*a[i])%Q;
      k%=Q;
      B=(B*10)%Q;
      if(a[i]>0)ans=(ans+mp[k]);
      mp[k]++;
    }
    cout<<ans<<endl;
  }
  return 0;
}

Measured memory_bytes: 7600
#include <iostream>
#include <algorithm>
#include <vector>
#include <math.h>
#include <bitset>
#include <tuple>
using namespace std;
typedef long long ll;

int main() {
    int n, h[100010];
    vector<pair<int, int>> v;
    cin >> n;
    for (int i = 0; i < n; i++) {
        cin >> h[i];
        v.emplace_back(h[i], i);
    }
    sort(v.begin(), v.end());

    int m[100010] = {};
    for (int i = 0; i < n; i++) {
        int k = v[i].second;
        while (k >= 0 && m[k] == 0) {
            m[k] = v[i].first;
            k--;
        }
    }

    bool ans = 1;
    for (int i = 0; i < n; i++) {
        if (h[i] - m[i] > 1) ans = 0;
    }

    cout << (ans ? "Yes" : "No") << endl;
}


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

void call(int n)
{
  int i = 1;

    do {
        do {

            int x = i;
            if ( x % 3 == 0 ) {
                cout << " " << i;
            } else {
                do {
                    if ( x % 10 == 3 ) {
                        cout << " " << i;
                        break;
                    }
                    x /= 10;
                } while ( x );
            }
        } while ( ++i <= n );

    } while (++i <= n);

  cout << endl;
}

int main()
{
    int n;

    cin >> n;

    if (n >= 3 && n <= 10000) {
        call(n);
    }

    return 0;
}


Measured memory_bytes: 3108
pi = 3.1415926535897931e+00
pos = [0.0, 0.0]
vec = [0.0, 1.0]
theta = 90.0
while line = gets
  break if line.chomp == "0,0"
  d, a = line.split(",").map(&:to_i)
  pos[0] += vec[0] * d
  pos[1] += vec[1] * d
  theta -= a
  vec = [Math.cos(theta/180.0*pi), Math.sin(theta/180.0*pi)]
end
puts pos[0].to_i
puts pos[1].to_i

Measured memory_bytes: 9000
n,k = map(int,input().split())
import math
s = 0
for i in range(n):
    if i>=k:
        s += (1/n)
    else:
        r  = int(math.ceil(math.log2(k/(i+1))))
        s += (1/n)*((1/2)**r)
print(s)

Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int, int>;

int e[300010];
int w[300010];

int main() {
  cin.tie(0);
  ios_base::sync_with_stdio(false);
  cout << fixed << setprecision(10);
  
  int N;
  string S;
  cin >> N >> S;

  int sz = S.size();
  for (int i = 0; i < sz; i++) {
    if (i == 0) w[i] = S[i] == 'W';
    else w[i] = w[i - 1] + (S[i] == 'W');
  }
  for (int i = sz - 1; i >= 0; i--) {
    if (i == sz - 1) e[i] = S[i] == 'E';
    else e[i] = e[i + 1] + (S[i] == 'E');
  }
  int ans = 1 << 30;
  for (int i = 0; i < sz; i++) {
    int sum = 0;
    if (i != 0) sum += w[i - 1];
    if (i != sz - 1) sum += e[i + 1];
    ans = min(ans, sum);
  }
  cout << ans << endl;

  return 0;
}

Measured memory_bytes: 2964
#include <bits/stdc++.h>
#define ll long long
#define N 200010
using namespace std;
int a[N];
ll l[N], r[N];
int n, L;
ll ans;
void solve()
{
    ll sum = 0;
    for (int i=1; i<n; i++) {
        sum += a[i];
        l[i] = sum;
    }
    sum = 0;
    for (int i=n-1; i; i--) {
        sum += L - a[i];
        r[i] = sum;
    }
    for (int x=1; x<n; x++) {
        int t = n-x;
        if (t&1) {
            int mid = n-((n-x)>>1)-1;
            // printf("ji %d : %d ", x, mid);
            ans = max(ans, ((l[mid] - l[x-1] + r[mid+1]) << 1) - a[mid]);
        } else {
            int mid = n-((n-x)>>1)-1;
            // printf("odd %d : %d ", x, mid);
            ans = max(ans, ((l[mid] - l[x-1] + r[mid+1]) << 1) - (L - a[mid+1]));
        }
        // printf("%lld\n", ans);
    }
}

int main()
{
    scanf("%d%d", &L, &n);
    n++;
    for (int i=1; i<n; i++)
        scanf("%d", &a[i]);
    solve();
    for (int i=1; i<n; i++)
        a[i] = L -a[i];
    reverse(a+1, a+n);
    solve();
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 4096
n = int(input())
a = input().split()
a_int = [int(s) for s in a]

cnt = [0]*n
j = 0
for i in a_int:
    m = i
    while m%2==0:
        m = m/2
        cnt[j] += 1
    j += 1
print(min(cnt))

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

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

	for(int i = 0; i < n; i++){
		int s;
		cin >> s;
		int max = 0, min = 0;
		vector<int> vec;
		int p = 10000000;
		for(int j = 0; j < 8; j++){
			vec.push_back(s / p);
			s = s % p;
			p /= 10;
		}
		sort(vec.begin(), vec.end());
		int maxP = 1;
		int minp = 10000000;
		for(int j = 0; j < 8; j++){
			min += vec[j] * minp;
			minp /= 10;
			max += vec[j] * maxP;
			maxP *= 10;
		}
		cout << max - min << endl;

	}
	return 0;
}

Measured memory_bytes: 1216
MOD=10**9+7
s=gets.chomp.chars.reverse
slen = s.size

#s=("?"*(10**5)).chars
#slen = s.size


dp1 = Array.new(13, 0)
dp2 = Array.new(13, 0)

dp1[0] = 1
kakeru = 1
slen.times do |i|
  kakeru = (kakeru*10) % 13 if i != 0
  if s[i] == "?"
    10.times do |n|
      t = (n * kakeru) % 13
      13.times do |j|
        dp2[(j+t) % 13] += dp1[j]
      end
    end
  else
    t = (s[i].to_i * kakeru) % 13
    13.times do |j|
      dp2[(j+t) % 13] += dp1[j] 
    end
  end
  13.times do |i|
    dp1[i] = dp2[i] % MOD
    dp2[i] = 0
  end
end
p dp1[5]

=begin
dp=Array.new(slen+1){Array.new(13, 0)}
dp[0][0] = 1
kakeru=1
slen.times do |i|
  kakeru = (kakeru*10) % 13 if i != 0
  if s[i] != "?"
    t = (s[i].to_i * kakeru) % 13
    13.times do |j|
      nj = (j+t)%13
      dp[i+1][nj] = (dp[i+1][nj] + dp[i][j]) % MOD
    end
  else
    10.times do |n|
      t = (n * kakeru) % 13
      13.times do |j|
        nj = (j+t)%13
        dp[i+1][nj] = (dp[i+1][nj] + dp[i][j]) % MOD
      end
    end
  end
end

p dp[slen][5]
=end

Measured memory_bytes: 12308
#![allow(unused, non_snake_case, dead_code, non_upper_case_globals)]
use {
    proconio::{marker::*, *},
    std::{cmp::*, collections::*, mem::*},
};
fn main() {
    input! {//
        h:usize,w:usize,
        c:[[i64;10];10],
        a:[[i64;w];h],
    }

    let mut dp = c.clone();
    for k in 0..10 {
        for i in 0..10 {
            for j in 0..10 {
                dp[i][j] = min(dp[i][j], dp[i][k] + dp[k][j]);
            }
        }
    }
    let mut ans = 0;
    for i in 0..h {
        for j in 0..w {
            if a[i][j] == -1 {
                continue;
            }
            ans += dp[a[i][j] as usize][1];
        }
    }
    println!("{}", ans);
}
const INF: i64 = 1 << 60;


Measured memory_bytes: 2580
import itertools
n, C = map(int, input().split())
lst = [[0] * 100002 for _ in range(C)]
end = []
for _ in range(n):
  s, t, c = map(int, input().split())
  c -= 1
  lst[c][s] += 1
  lst[c][t + 1] -= 1

for c in range(C):
  lst[c] = list(itertools.accumulate(lst[c]))
  for i in range(100002):
    if lst[c][i] >= 2:
      lst[c][i] = 1

ans = 0
for i in range(100002):
  tmp = 0
  for c in range(C):
    tmp += lst[c][i]
  ans = max(ans, tmp)
print(ans)

Measured memory_bytes: 28928
#include<bits/stdc++.h>
using namespace std;
const int N=1e5+7,mod=1e9+7;
int n,a[N],ans=1;
char s[N];
int main()
{
	scanf("%d",&n);
	scanf("%s",s+1);
	for(int i=1;i<=n;i++)a[s[i]-'a'+1]++;
	for(int i=1;i<=26;i++)ans=1ll*ans*(a[i]+1)%mod;
	ans=(ans-1+mod)%mod;
	cout<<ans<<endl;
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
#define rep(i, a, n) for (int i = a; i < n; i++)
#define repr(i, a, n) for (int i = n - 1; i >= a; i--)
using namespace std;
using ll = long long;
using P = pair<int, int>;
template <typename T>
void chmin(T &a, T b) { a = min(a, b); }
template <typename T>
void chmax(T &a, T b) { a = max(a, b); }

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

  string s;
  int k, n = 0;
  cin >> s >> k;
  n = s.size();

  set<string> dset;
  rep(i, 0, n)
  {
    string x = string() + s[i];
    dset.insert(x);
    rep(j, i + 1, i + k)
    {
      if (j >= n)
        break;
      x += s[j];
      dset.insert(x);
    }
  }

  int i = 0;
  for (auto d : dset)
  {
    i++;
    if (i == k)
    {
      cout << d << endl;
      return 0;
    }
  }
}


Measured memory_bytes: 1664
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <sstream>
#include <cstring>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <numeric>
#include <cctype>
#include <tuple>
#include <array>
#include <climits>

// BEGIN CUT HERE
#ifdef _MSC_VER
#include <agents.h>
#endif
// END CUT HERE 

#define FOR(i, a, b) for(int i = (a); i < (int)(b); ++i)
#define rep(i, n) FOR(i, 0, n)
#define ALL(v) v.begin(), v.end()
#define REV(v) v.rbegin(), v.rend()
#define MEMSET(v, s) memset(v, s, sizeof(v))
#define MP make_pair
#define MT make_tuple

using namespace std;

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

struct state{
	int lev, r, c, swit, dist;

	void pp(int k){
		string s;
		int x = swit;
		rep(i, k) s += '0' + !!(x&(1<<i));
		printf("lev = %d, pos = (%d, %d), swit = %s, dist = %d\n", lev, r, c, s.c_str(), dist);
	}
};

int pos[50][50][1 << 10];
int vis[2][50][50][1 << 10];

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

int grid(char c){
	return c == '^' || !!isupper(c);
}

void go(state &s, queue<state> &q){
	if (vis[s.lev][s.r][s.c][s.swit]) return;
	vis[s.lev][s.r][s.c][s.swit] = 1;
	q.push(s);
}

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

	int w, h;
	cin >> w >> h;
	vector<string> v(h);
	rep(i, h) cin >> v[i];

	int n;
	cin >> n;
	vector<vector<string>> sw(n);
	rep(i, n){
		sw[i].resize(h);
		rep(j, h) cin >> sw[i][j];
	}

	int sr = -1, sc = -1;
	int gr = -1, gc = -1;
	rep(i, h) rep(j, w){
		char &c = v[i][j];
		if (c == '%') sr = i, sc = j;
		if (c == '&') gr = i, gc = j;
		if (c == '#') continue;
		if (c == '|') continue;
		int def = grid(c);
		if (isupper(c)) c += 'a' - 'A';
		rep(k, 1 << n){
			int &x = pos[i][j][k];
			x = def;
			rep(l, n) if ((k>>l&1) && sw[l][i][j] == '*') x ^= 1;
		}
	}

	queue<state> q;
	state init{ 0, sr, sc, 0, 0 };
	go(init, q);

	while (!q.empty()){
		auto s = q.front();
		q.pop();

		//s.pp(n);

		if (s.r == gr && s.c == gc){
			cout << s.dist << endl;
			return 0;
		}

		++s.dist;
		if (v[s.r][s.c] == '|'){
			auto nxt = s;
			nxt.lev ^= 1;
			go(nxt, q);
		}

		if (isalpha(v[s.r][s.c])){
			auto nxt = s;
			nxt.swit ^= 1 << v[s.r][s.c] - 'a';
			if (pos[s.r][s.c][nxt.swit] != nxt.lev) nxt.lev ^= 1;
			go(nxt, q);
		}

		rep(d, 4){
			auto nxt = s;
			nxt.r += dx[d], nxt.c += dy[d];
			if (v[nxt.r][nxt.c] == '#') continue;
			if (v[nxt.r][nxt.c] != '|' && pos[nxt.r][nxt.c][nxt.swit] != nxt.lev) continue;
			go(nxt, q);
		}
	}
	cout << -1 << endl;

	return 0;
}

Measured memory_bytes: 31660
N = int(input())
h = list(map(int, input().split()))
dp = [0] + [abs(h[0] - h[1])] + [0] * (N-2)

for i in range(2, N):
    dp[i] = min(dp[i-2] + abs(h[i] - h[i-2]), dp[i-1] + abs(h[i] - h[i-1]))
print(dp[N-1])
    

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

using namespace std;
using ll = long long;
using ii = pair<ll, ll>;

const int MAXH { 10010 }, MAXN { 1010 };
const ll MOD { 1000000007 }, oo { 1LL << 35 };

ll st[MAXH][MAXN];

ll dp(int h, int i, int N, const vector<ii>& xs)
{
    if (h <= 0)
        return 0;

    if (i == N)
        return h < 0 ? 0 : oo; 

    if (st[h][i] != -1)
        return st[h][i];

    ll res = dp(h, i + 1, N, xs);

    if (h > 0)
    {
        res = min(res, dp(h - xs[i].first, i, N, xs) + xs[i].second);
        res = min(res, dp(h - xs[i].first, i + 1, N, xs) + xs[i].second);
    }

    st[h][i] = res;
    return res;
}

ll solve(int H, int N, const vector<ii>& xs)
{
    memset(st, -1, sizeof st);

    return dp(H, 0, N, xs);
}

int main()
{
    ios::sync_with_stdio(false);

    int H, N;
    cin >> H >> N;

    vector<ii> xs(N);

    for (int i = 0; i < N; ++i)
        cin >> xs[i].first >> xs[i].second;

    auto ans = solve(H, N, xs);

    cout << ans << '\n';

    return 0;
}


Measured memory_bytes: 80128
/*input
-100 100 100
*/
#include <bits/stdc++.h>
using namespace std;

int main(int argc, char const *argv[])
{
  int a, b, c;
  cin >> a >> b >> c;
  if (a == b) cout << c;
  else if (a == c) cout << b;
  else cout << a;
  return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
#define N 100
#define INF 100000
 
int main(){
  int i,j,l,m[N+1][N+1],n,p[N+1],k,r;
  scanf("%d",&n);
  for(i=1;i<=n;i++){
    scanf("%d%d",&p[i-1], &p[i]);
  }
 
  for(i=1;i<=n;i++){
    m[i][i] = 0;
  }
 
  for(l=2;l<=n;l++){
    for(i=1;i<=n-l+1;i++){
      j = i+l-1;
      m[i][j] = INF;
      for(k=i;k<j;k++){
    r = m[i][k] + m[k+1][j] + p[i-1] * p[k] * p[j];
    if(m[i][j] > r) m[i][j] = r; 
      }
    }
  }
  printf("%d\n",m[i-1][j]);
  return 0;
}

Measured memory_bytes: 636
#include <iostream>
#include <string>
#include <algorithm>
#include <cmath>
#include <map>
#include <vector>
#include <set>
#include <cstdlib>
#include <deque>

using namespace std;

int main() {
  int n;
  cin >> n;
  int a[n];
  deque<int> deq;
  deque<int>::iterator itr;
  int flag = n % 2;
  if(flag == 1) {
    for(int i = 1; i <= n; i++) {
      cin >> a[i-1];
      if(i % 2 == 1) {
        deq.push_front(a[i-1]);
      }else {
        deq.push_back(a[i-1]);
      }
    }
  }else {
    for(int i = 1; i <= n; i++) {
      cin >> a[i-1];
      if(i % 2 == 1) {
        deq.push_back(a[i-1]);
      }else {
        deq.push_front(a[i-1]);
      }
    }
  }
  for(itr = deq.begin(); itr != deq.end(); itr++) {
    cout << *itr << " ";
  }
  return 0;
}

Measured memory_bytes: 3840
#include <iostream>
#include <string>
#include <algorithm>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <cmath>
#include <time.h>
#include <stdio.h>
#include <vector>
#define int long long
#define endre getchar();getchar();return 0
int inf = 1000000000;
using namespace std;
int gcd(int x, int y) {
	if (y == 0)return x;
	return gcd(y, x%y);
}
int lcm(int x, int y) {
	return x / gcd(x, y)*y;
}
int mypow(int x, int y) {
	if (y == 0)return 1;
	if (y % 2)return mypow(x, y - 1)*x;
	else return mypow(x, y / 2)*mypow(x, y / 2);
}
int Max(int x, int y) {
	if (x > y)return x;
	else return y;
}
int Min(int x, int y) {
	if (x < y)return x;
	else return y;
}
int kai(int x) {
	int cnt = 1;
	if (x == 0)return 1;
	cnt = kai(x - 1);
	return x * cnt;
}
int prime(int n) {
	for (int i = 2; i*i <= n; i++) {
		if (n%i == 0)return false;
	}
	return n != 1;
}
void prime_factor(int n) {
	int cnt = 1;
	map<int, int>res;
	int m = n;
	for (int i = 2; i <= n; i++) {
		if (prime(i)) {
			while (m%i == 0) {
				++res[i];
				m /= i;
			}
		}
	}
	cout << n << ":" << endl;
	for (int i = 2; i <= n; i++) {
		if (res[i]) {
			cout << i << " " << res[i] << endl;
		}
	}
	cout << endl;
}
/*Library End!*/

int n, a[100005], memo, maememo, cnt,maecnt;
signed main() {
	cin >> n;
	for (int i = 0; i < n; i++)cin >> a[i];
	sort(a, a + n);
	if (n % 2) {
		maememo = a[n / 2];
		maecnt = maememo;
		for (int j = 1; j < n; j++) {
			if (j % 2) {
				cnt += abs(maecnt - a[n - 1 - j / 2]);
				maecnt = a[n - 1 - j / 2];
				memo += abs(maememo - a[j / 2]);
				maememo = a[j / 2];
			}
			else {
				cnt += abs(maecnt - a[j / 2 - 1]);
				maecnt = a[j / 2 - 1];
				memo += abs(maememo - a[n - j / 2]);
				maememo = a[n - j / 2];
			}
		}
		cnt = max(memo, cnt);
	}
	else {
		maecnt = a[n / 2 - 1];
		maememo = a[n / 2];
		for (int j = 1; j < n; j++) {
			if (j % 2) {
				cnt += abs(maecnt - a[n - 1 - j / 2]);
				maecnt = a[n - 1 - j / 2];
				memo += abs(maememo - a[j / 2]);
				maememo = a[j / 2];
			}
			else {
				cnt += abs(maecnt - a[-1 + j / 2]);
				maecnt = a[-1 + j / 2];
				memo += abs(maememo - a[n - j / 2]);
				maememo = a[n - j / 2];
			}
		}
		cnt = max(cnt, memo);
	}
	cout << cnt << endl;
	endre;
}


Measured memory_bytes: 1024
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		String a = sc.next();
		String b = sc.next();
		int c = Integer.valueOf(a + b);
		boolean ok = false;
		for(int i = 1 ; i <= 1010 ; i++) {
			if(c == i * i) ok = true;
		}
		if(ok) {
			System.out.println("Yes");
		} else {
			System.out.println("No");
		}
	}
}


Measured memory_bytes: 22100