akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
typedef long long ll;
typedef long double ld;
using namespace std;

using Pii = pair<int, int>;
using Pll = pair<ll, ll>;

#define REP(i, l, n) for(int i=(l), i##_len=(n); i<i##_len; ++i)
#define ALL(x) (x).begin(),(x).end()
#define pb push_back

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

char alpha[26] = {'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z'};

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

int main(){
    ll a, b, c, k; cin >> a >> b >> c >> k;
    if(k % 2 == 0){
        cout << a-b << endl;
    }else{
        cout << b-a << endl;
    }
}

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

int main(){
  int N=0, K=0, sum=1;
  cin >> N >> K;
  
  for(int i=0; i<N; i++){
    if((sum * 2 - K) <= K){
      sum *= 2;
    }
    else
      sum += K;
  }
  cout << sum << endl;
  return 0;
}

Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main(void){
    int w,n,t[31][31],a,b,i,j;
    char ch;
    for(i = 0; i < 31; i++){
        for(j = 0; j < 31; j++){
            t[i][j] = j;
        }
    } 
    cin >> w >> n;
    for(i = 1; i <= n; i++){
        cin >> a >> ch >> b;
        t[i][a] = b;
        t[i][b] = a;
    }
    for(j = 1; j <= w; j++){
        a = j;
        for(i = n; i >= 0; i--){
            a = t[i][a];
        }
        cout << a << endl;
    }
}


Measured memory_bytes: 3060
n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
res = 0
pb = 0
for i in range(n):
    cur = b[i] + pb
    d = min(cur, a[i])
    res += d
    pb = max(0, b[i] - max(0, d - pb))
res += min(a[-1], pb)
print(res)

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

int main() {
	int n, k, q; cin >> n >> k >> q;
	vector<int> b(n, k);
	for (int i = 0; i < q; ++i) {
		int a; cin >> a;
		++(b[a - 1]);
	}
	for (int i = 0; i < n; ++i)
		cout << (b[i] - q <= 0 ? "No" : "Yes") << endl;
}

Measured memory_bytes: 1024
import sys,math,copy,queue,itertools
from fractions import gcd
sys.setrecursionlimit(10**7)
LI = lambda : [int(x) for x in sys.stdin.readline().split()]
_LI = lambda : [int(x)-1 for x in sys.stdin.readline().split()]
NI = lambda : int(sys.stdin.readline())
INF = 10**4
MOD = 10**9 + 7
DD = ((1,0),(0,1),(-1,0),(0,-1))
N,X,Y = LI()

c = [0 for _ in range(N+1)]

for k in range(1,N+1):
    j = 1
    m = [0 for _ in range(N+1)]
    # for i in range(k-1,0,-1):
    #     c[j] += 1
    #     m[i] = j
    #     j += 1
    j = 1
    for i in range(k+1,N+1):
        c[j] += 1
        m[i] = j
        j += 1
    if k <= X:
        j = X - k + 1
        a = 0
        while j + a < m[Y - a]:
            c[m[Y-a]] -= 1
            c[j + a] += 1
            m[Y -a] = j + a
            a += 1
        a = 1
        if Y + a <= N:
            while j + a < m[Y + a]:
                c[m[Y+a]] -= 1
                c[j + a] += 1
                m[Y + a] = j + a
                a += 1
                if Y + a > N : break
    elif k <= Y:
        j = k - X + 1
        a = 0
        while j + a < m[Y - a]:
            c[m[Y-a]] -= 1
            c[j + a] += 1
            m[Y -a] = j + a
            a += 1
        a = 1
        if Y + a <= N:
            while j + a < m[Y + a]:
                c[m[Y+a]] -= 1
                c[j + a] += 1
                m[Y + a] += 1
                a += 1
                if Y + a > N : break
for k in range(1,N):
    print (c[k])


Measured memory_bytes: 72920
import java.util.Scanner;

public class Main {
	public static void main(String args[]) {
		Scanner sc = new Scanner(System.in);
		
		int w, h, n, a, y, x;
		boolean ban[][];
		
		w = sc.nextInt();
		h = sc.nextInt();
		n = sc.nextInt();
		
		ban = new boolean[w][h];
		
		for(int i = 0; i < n; ++i) {
			x = sc.nextInt();
			y = sc.nextInt();
			a = sc.nextInt();
			if(a == 1) {
				for(int j = 0; j < x; ++j) {
					for(int k = 0; k < h; ++k) {
						ban[j][k] = true;
					}
				}
			}
			else if(a == 2) {
				for(int j = x; j < w; ++j) {
					for(int k = 0; k < h; ++k) {
						ban[j][k] = true;
					}
				}
			}
			else if(a == 3) {
				for(int j = 0; j < y; ++j) {
					for(int k = 0; k < w; ++k) {
						ban[k][j] = true;
					}
				}
			}
			else if(a == 4) {
				for(int j = y; j < h; ++j) {
					for(int k = 0; k < w; ++k) {
						ban[k][j] = true;
					}
				}
			}
		}
		
		int count = 0;
		
		for(int i = 0; i < w; ++i) {
			for(int j = 0; j < h; ++j) {
				if(ban[i][j] == false)++count;
			}
		}
		
		System.out.println(count);
		
		sc.close();
	}
}


Measured memory_bytes: 25160
#include <set>
#include <map>
#include <list>
#include <stack>
#include <cmath>
#include <ctime>
#include <cstdio>
#include <vector>
#include <string>
#include <bitset>
#include <cctype>
#include <cstdlib>
#include <cstring>
#include <utility>
#include <numeric>
#include <complex>
#include <sstream>
#include <fstream>
#include <iomanip>
#include <cassert>
#include <iostream>
#include <iterator>
#include <algorithm>
using namespace std;

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

	int all = 0;;

	for (int i = 1; i <= N; i += 2) {
		int cnt = 0;
		for (int j = 1; j <= i; ++j) {
			if (i % j == 0) {
				cnt++;
			}
		}
		if (cnt == 8) {
			all++;
		}
	}

	cout << all << endl;

	return 0;
}

Measured memory_bytes: 256
import java.util.*;

/**
 * 構築問題
 */
public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);

        int A = sc.nextInt();
        int B = sc.nextInt();
        char[][] ans = solve(A, B);

        System.out.println("100 100");
        for (int i=0; i<100; i++) {
            System.out.println(new String(ans[i]));
        }
    }

    private static char[][] solve(int A, int B) {
        char[][] list = new char[100][100];
        int lineIdx = 0;

        String white10  = "..........";
        String white100 = white10 + white10 + white10 + white10 + white10 + white10 + white10 + white10 + white10 + white10;
        String black10  = "##########";
        String black100 = black10 + black10 + black10 + black10 + black10 + black10 + black10 + black10 + black10 + black10;

        for (int i=0; i<50; i++) {
            list[i]    = white100.toCharArray();
            list[i+50] = black100.toCharArray();
        }
        A--; B--;

        while(B > 50) {
            list[lineIdx] = "#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.".toCharArray();
            lineIdx += 2;
            B   -= 50;
        }
        int posIdx = 0;
        while (B > 0) {
            list[lineIdx][posIdx] = '#';
            B--;
            posIdx += 2;
        }

        lineIdx = 51;
        while(A > 50) {
            list[lineIdx] = ".#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#".toCharArray();
            lineIdx += 2;
            A   -= 50;
        }
        posIdx = 0;
        while (A > 0) {
            list[lineIdx][posIdx] = '.';
            A--;
            posIdx += 2;
        }

        return list;
    }
}


Measured memory_bytes: 23892
#include <iostream>
#include <string>
#include <map>
#include <queue>
#include <algorithm>
#include <vector>
#include <math.h>
#include <bitset>
#include <cmath>
#include <set>

#define rep(i,s,n)for(int i = s;i<n;i++)
#define repe(i,s,n)for(int i = s;i<=n;i++)
#define rep_r(i,s,n)for(int i = n-1;i>=0;i--)
#define rep_re(i,s,n)for(int i = n;i>=0;i--)
using namespace std;
typedef long long ll;
static const ll MOD = 1e9 + 7;
static const ll INF = 1e25;
static const ll MAX_M = 100001;

int main() {
	ll k, a, b; cin >> k >> a >> b;
	if (b - a <= 2 || k < a - 1)cout << k + 1 << endl;
	else {
		ll ans = a;
		k -= a - 1;

		ans += (b - a)*(k / 2);
		if (k & 1)ans++;
		cout << ans << endl;
	}

	return 0;
}

Measured memory_bytes: 256
def tanri(ganri, y, r)
  ganri * (1 + y * r * 0.01) 
end

def fukuri(ganri, y, r)
  ganri * (1 + r * 0.01) ** y
end

while line = gets
  n = line.chomp.to_i
  break if n == 0

  y = gets.chomp.to_i

  max_n = 0
  max_g = -Float::INFINITY
  n.times do
    b, r, t = gets.chomp.split.map(&:to_i)

    if t == 1
      g = tanri(10000, y, r)
    elsif t == 2
      g = fukuri(10000, y, r)
    end

    if g > max_g
      max_n = b
      max_g = g
    end
  end

  puts max_n
end

Measured memory_bytes: 9028
#include<stdio.h>
#define N 100
int main(){
  int i, j, A[N], num,key;
  scanf("%d",&num);

  for(i = 0;i < num;i++){
    scanf("%d", &A[i]);
  }
  for(i = 0;i < num-1;i++){
    printf("%d ",A[i]);
  }
  printf("%d\n",A[num - 1]);

  for(i = 1;i <= num-1;i++){
    key = A[i];
    j = i -1; 
    while(j >= 0 && A[j] > key){
      A[j+1] = A[j];
      j--;
      A[j+1] = key;
  }
    for(j = 0;j < num-1;j++){
       printf("%d ",A[j]);
  }
    printf("%d\n",A[num-1]);
  }
  
  return 0;
}



Measured memory_bytes: 2060
#include <iostream>
#include <cmath>
#include <vector>

int main()
{
    std :: ios_base :: sync_with_stdio(false);

    int N , Dimention , a{};
    std :: cin >> N >> Dimention;

    std :: vector <int> points[N];
    for(int i = 0 ; i < N ; i++)
    {
        for(int j = 0 ; j < Dimention ; j++)
        {
            int x;
            std :: cin >> x;
            points[i].push_back(x);
        }
    }

    for(int i = 0 ; i < N - 1 ; i++)
    {
        for(int j = i + 1 ; j < N ; j++)
        {
            int d{};
            for(int k = 0 ; k < Dimention ; k++)
                d += (points[i].at(k) - points[j].at(k)) * (points[i].at(k) - points[j].at(k));
            ///std :: cout << d << '\n';
            if(sqrt(d) == (int)sqrt(d))
                a++;
        }
    }

    std :: cout << a << '\n';
}


Measured memory_bytes: 256
def dfs(n,s):
    if int(s)>n:
        return 0
    res=0
    if s.count('7') and s.count('5') and s.count('3')>0:
        res+=1
    for c in '753':
        res+=dfs(n,s+c)
    return res

n=int(input())
print(dfs(n,'0'))


Measured memory_bytes: 3060
#include <bits/stdc++.h>
#define repz(i, z, n) for (decltype(n) i = (z); i < (n); i++)
#define rep(i, n) for (decltype(n) i = 0; i < (n); i++)

#define REPZ(i, z, n) for (decltype(n) i = (z); i <= (n); i++)
#define REP(i, n) for (decltype(n) i = 0; i <= (n); i++)
#define ALL(v) v.begin(), v.end()
#define SIZE(v) ((ll)(v).size())
#define MAX(v) (*max_element(ALL(v)))
#define MIN(v) (*min_element(ALL(v)))
#define INF 1000000000000  // 1E+12

// 略
#define PB push_back
#define F first
#define S second
#define MP make_pair
#define READ cin >>
#define PRINT cout <<
#define PYES cout << "Yes" << endl;
#define POK cout << "OK" << endl;
#define PNO cout << "No" << endl;
#define PNG cout << "NG" << endl;

using namespace std;

// デバッグ用
void debug_out() { cout << endl; }
template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
  cout << H << " ";
  debug_out(T...);
}

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

#ifdef _DEBUG
#define debug(...) debug_out(__VA_ARGS__)
#else
#define debug(...)
#endif

// typedef
typedef long long ll;
typedef unsigned long long ul;
typedef long double ld;
typedef pair<ll, ll> pl;

// const
// 円周率
const ld pi = acos(-1);
// mod用
// 1E+9 +7
const ll mod = (int)1e+9 + 7;
// 1s間で可能なループ回数2E+8回
// int        最大値2147483647         〜2E+9
// long long  最大値9223372036854775807〜9E+18
// 総和accumulate
// 単純リストvector<type> push_back
// 連想配列map<key,value> insert,
// 集合set<type>
// pair キーとバリューを格納 firstとsecondでアクセス
// 小数点指定 cout << fixed << setprecision(15) << endl;
// to_string<->stoi
// stoll(longlong)
// stod(double)
// deep copy v1->v2 copy(v1.begin(), v1.end(), back_inserter(v2) );
// 大文字65-90(-32)
// 小文字97-122(+32)
//  priority_queue<pair<ll, ll>, vector<pair<ll, ll>>, greater<pair<ll, ll>>>
//  ba;
signed main() {
  // faster
  // C言語流の入出力は使用できない
  ios::sync_with_stdio(false);
  std::cin.tie(nullptr);
  vector<string> a = {"Sunny", "Cloudy", "Rainy"};
  string s; cin >> s;
  if(s==a[0]) cout << a[1] << endl;
  if(s==a[1]) cout << a[2] << endl;
  if(s==a[2]) cout << a[0] << endl;
  return 0;
}


Measured memory_bytes: 256
a1 = gets.split.map &:to_i
a2 = gets.split.map &:to_i
a3 = gets.split.map &:to_i
check1 = [0,0,0]
check2 = [0,0,0]
check3 = [0,0,0]
n = gets.to_i
n.times do |a|
    b = gets.to_i
    if a1.include?(b)
        check1[a1.index(b)] = 1
    elsif a2.include?(b)
        check2[a2.index(b)] = 1
    elsif a3.include?(b)
        check3[a3.index(b)] = 1
    end
end
yes = 0
3.times do |a|
    yes = 1 if (check1[a] + check2[a] + check3[a]) == 3
end
yes = 1 if (check1[0] + check2[1] + check3[2]) == 3
yes = 1 if (check1[2] + check2[1] + check3[0]) == 3
if yes == 1
    print "Yes"
elsif ((check1.inject(:+) == 3) || (check2.inject(:+) == 3) || (check3.inject(:+) == 3))
    print "Yes"
else
    print "No"
end


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

#define rep(i,n) for(i = 0;i < n;++i)
#define all(v) v.begin(), v.end()
using ll = long long;

int main()
{
    ll i,j;
    ll n,W;
    cin >> n >> W;
    vector<ll> v(n);
    vector<ll> w(n);
    for(i = 0;i < n;++i){
        cin >> v.at(i) >> w.at(i);
    }

    ll n2 = n/2;
    vector<pair<ll,ll>> tmp_sum1;
    for(ll bit = 0;bit < (1 << n2);++bit){
        ll w_sum = 0;
        ll v_sum = 0;
        for(i = 0;i < n2;++i){
            if(bit & (1 << i)){
                w_sum += w.at(i);
                v_sum += v.at(i);
            }
        }
        if(w_sum <= W) tmp_sum1.emplace_back(w_sum,-v_sum);
    }
    sort(all(tmp_sum1));
    vector<pair<ll,ll>> sum1;
    for(i = 0;i < tmp_sum1.size();++i){
        ll w_sum = tmp_sum1.at(i).first;
        ll v_sum = -tmp_sum1.at(i).second;
        if(i == 0){
            sum1.emplace_back(w_sum, v_sum);
        }else{
            if(sum1.back().second < v_sum) sum1.emplace_back(w_sum, v_sum);
        }
    }

    ll n22 = n - n2;
    vector<pair<ll,ll>> tmp_sum2;
    for(ll bit = 0;bit < (1 << n22);++bit){
        ll w_sum = 0;
        ll v_sum = 0;
        for(i = 0;i < n22;++i){
            if(bit & (1 << i)){
                w_sum += w.at(i + n2);
                v_sum += v.at(i + n2);
            }
        }
        if(w_sum <= W) tmp_sum2.emplace_back(w_sum,-v_sum);
    }
    sort(all(tmp_sum2));
    vector<pair<ll,ll>> sum2;
    for(i = 0;i < tmp_sum2.size();++i){
        ll w_sum = tmp_sum2.at(i).first;
        ll v_sum = -tmp_sum2.at(i).second;
        if(i == 0){
            sum2.emplace_back(w_sum, v_sum);
        }else{
            if(sum2.back().second < v_sum) sum2.emplace_back(w_sum, v_sum);
        }
    }

    ll ans = 0;
    for(i = 0;i < sum1.size();++i){
        ll w_sum = sum1.at(i).first;
        ll v_sum = sum1.at(i).second;
        auto itr = lower_bound(all(sum2), make_pair(W-w_sum+1, 0ll));
        if(itr != sum2.begin()) ans = max(ans, v_sum + (*--itr).second);
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 43672
#include <iostream>
#include <algorithm>
#include <string> 
#include <vector>
#include <iomanip>
#include <math.h>
#include <map>
using namespace std;

int main()
{
	int A, B, C, D;
	cin >> A >> B >> C >> D;
	cout << min(A, B) + min(C, D) << endl;
}

Measured memory_bytes: 256
{-# LANGUAGE ScopedTypeVariables #-}
{-# LANGUAGE BangPatterns #-}

import Control.Applicative
import Control.Monad
import Control.Arrow
import Data.List
import Data.Maybe
import Data.Char
import qualified Data.ByteString.Char8 as B
import Text.Printf

readInt = ( readLn :: IO Int )
readInts = map ( read :: String -> Int ) . words <$> getLine

getList = map ( fst . fromJust . B.readInt ) . B.words <$> B.getLine

which a b f = if f then a else b
mp [ a, b ] = ( a, b )

main = getLine >>= print . pred . length . group


Measured memory_bytes: 4988
#include<stdio.h>

int main(){
  int n,i,j,kotae=1,amari,min=1000000001;
  scanf("%d",&n);
  int a[n];
  for(i=0;i<n;i++){
    scanf("%d",&a[i]);
    if(a[i]<min){min=a[i];}
  }
  if(min==1){
    printf("1");
  return 0;
  }
  amari=0;
  for(i=0;i<n;i++){
    amari+=a[i]%min;
  }
  if(amari==0){
    printf("%d",min);
    return 0;
  } 
  for(j=2;j<=min/2;){
    amari=0;
    for(i=0;i<n;i++){
      amari+=a[i]%j;
    }
    if(amari==0){
      for(i=0;i<n;i++){
        a[i]/=j;
      }
      min/=j;
      kotae*=j;
      j=2;
      if(min==1){
        printf("%d",kotae);
        return 0;
      }
    }else{
      if(j==2)j=3; else j+=2;
    }
  }
  printf("%d",kotae);
  return 0;
}


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

#define st first
#define nd second
#define all(x) (x).begin(), (x).end()

using namespace std;
using namespace placeholders;

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

template <class T> void mini(T &l, T r){l = min(l, r);}
template <class T> void maxi(T &l, T r){l = max(l, r);}

template <class TH> void _dbg(const char *sdbg, TH h){cerr << sdbg << "=" << h << "\n";}
template <class TH, class ...TA> void _dbg(const char *sdbg, TH h, TA... a){
	while (*sdbg != ','){cerr << *sdbg++;}cerr << "=" << h << ","; _dbg(sdbg + 1, a...);
}
template <class T> ostream &operator <<(ostream &os, vector<T> V){
	os << "["; for (auto vv: V) os << vv << ","; return os << "]";
}
template <class L, class R> ostream &operator <<(ostream &os, pair<L, R> P){
	return os << "(" << P.st << "," << P.nd << ")";
}

#ifdef SFIC
	#define eput(...) _dbg(#__VA_ARGS__, __VA_ARGS__)
#else
	#define eput(...) 218
#endif

const int N = 1E2 + 10;

int a[N];

int main(){
	int n;
	scanf("%d", &n);
	for (int i = 0; i < n; ++i)
		scanf("%d", a + i);
	int ans = 0;
	for (int i = 0, j; i < n; i = j){
		for (j = i + 1; j < n && a[j] == a[i]; ++j);
		ans += j - i >> 1;
	}
	printf("%d\n", ans);
	return 0;
}


Measured memory_bytes: 256
#include <cstdio>
#include <cstdint>
#include <vector>
#include <algorithm>
#include <string>

int main() {
  size_t N;
  scanf("%zu", &N);

  if (N == 1) return puts("Yes\n2\n1 1\n1 1"), 0;
  if (N == 2) return puts("No"), 0;
  if (N == 3) return puts("Yes\n3\n2 1 2\n2 3 1\n2 2 3"), 0;
  if (N == 4) return puts("No"), 0;

  for (size_t i=1; i<1000; ++i) {
    size_t w=i*(i+1)/2;
    if (w > N) return puts("No"), 0;
    if (w < N) continue;

    size_t k=i+1;
    std::vector<std::vector<size_t>> res(k);
    size_t a=1;
    for (size_t j=0; j<i; ++j) {
      for (size_t m=0; m<=j; ++m) {
        // size_t a=j*(j+1)/2+1+m;
        res[m].push_back(a);
        res[j+1].push_back(a);
        ++a;
      }
    }
    puts("Yes");
    printf("%zu\n", k);
    for (size_t i=0; i<k; ++i) {
      printf("%zu", res[i].size());
      for (size_t a: res[i])
        printf(" %zu", a);
      printf("\n");
    }
    return 0;
  }
}


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

int main()
{
	int N,ans = 0;

	cin >> N;

	map<int, int>mp;

	for (int n = 0; n < N; n++) {
		int a;
		cin >> a;
		mp[a]++;
		if (mp[a] < a) {
			ans++;
		}
		if (mp[a] == a) {
			ans -= a - 1;
		}
		if (mp[a] > a) {
			ans++;
		}
	}

	cout << ans;

	return 0;
}

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

using namespace std;

const int N = 123;
int n;
int d[N][N];
bool vis[N];
vector<int> e[N];
long long sol(vector<int>& src, int init) {

  long long deg = init;
  
  memset(vis, 0x00, sizeof(vis));

  bool very_first = true;

  while (src.size() > 0) {

    int max_deg = 1;
    for (int i = 0; i < src.size(); ++i) {
      vis[src[i]] = true;
      max_deg = max(max_deg, (int)e[src[i]].size() -  (very_first && src.size() == 1 ? 0 : 1));
 //     cout << " " << src[i];
    }
   // cout << endl;

    very_first = false;

//    cout << "max_deg: " << max_deg << endl;
    deg *= max_deg;


    vector<int> n_src;
    for (int i = 0; i < src.size(); ++i) {
      int u = src[i];
      for (int j = 0; j < e[u].size(); ++j) {
        int v = e[u][j];
        if (vis[v]) continue;
        n_src.push_back(v); 
      }
    }

    src = n_src;
  }

  return deg;
}

int main() {
  cin >> n;

  memset(d, 0xff, sizeof(d));

  for (int i = 1; i <= n; ++i) d[i][i] = 0;

  for (int i = 0, u, v; i < n - 1; ++i) {
    cin >> u >> v;
    e[u].push_back(v);
    e[v].push_back(u);
    d[u][v] = d[v][u] = 1;
  }

  for (int k = 1; k <= n; ++k) {
    for (int i = 1; i <= n; ++i) {
      for (int j = 1; j <= n; ++j) {
        if (d[i][k] != -1 && d[k][j] != -1) {
          if (d[i][j] == -1) d[i][j] = d[i][k] + d[k][j];
          else d[i][j] = min(d[i][j], d[i][k] + d[k][j]);
        }
      }
    }
  }

  int max_d = 0, U, V;
  for (int i = 1; i <= n; ++i) {
    for (int j = i + 1; j <= n; ++j) {
      if (d[i][j] > max_d) {
        max_d = d[i][j];
        U = i;
        V = j;
      }
    }
  }

  vector<int> path;
//  cout << U << "," << V << endl;
  path.push_back(U);
  for (int i = 0, u; i < max_d; ++i) {
    u = path.back();
    for (int j = 0; j < e[u].size(); ++j) {
      int v = e[u][j];
      if (d[v][V] == d[u][V] - 1) {
        path.push_back(v);
        break;
      }
    }
  }

//  for (int i = 0; i < path.size(); ++i) cout << path[i] << " ";
//  cout << endl;
  
  int res = (path.size() + 1) / 2;
  long long deg;
 
  vector<int> src;
  if (path.size() & 1) {
    int u = path[path.size() / 2];
    src.push_back(u);
    deg = sol(src, 1);

    for (int i = 0; i < e[u].size(); ++i) {
      vector<int> n_src;
      n_src.push_back(e[u][i]);
      n_src.push_back(u);

//      cout << u << "," << e[u][i] << ":" << sol(n_src, 2) <<  endl;      

      deg = min(deg, sol(n_src, 2));
//      cout << deg << endl;
    }
  
  } else {
    src.push_back(path[path.size() / 2 - 1]);
    src.push_back(path[path.size() / 2]);
    deg = sol(src, 2);
  }


  cout << res << " " << deg << endl;


  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define M 500005
#define bug printf("bug\n")
#define ll long long
ll n,arr[M],dp[M];
int main()
{
    scanf("%lld",&n);
    for(int i=1;i<=n;i++) scanf("%lld",&arr[i]);
    dp[2] = abs(arr[2]-arr[1]);
    for(int i=3;i<=n;i++)
    {
        int r1 = dp[i-1]+abs(arr[i-1]-arr[i]);
        int r2 = dp[i-2]+abs(arr[i-2]-arr[i]);
        dp[i] = min(r1,r2);
    }
    cout << dp[n] << "\n";
    return 0;
}


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

int main() {
	int x,y,a,b,c;
	cin>>x>>y>>a>>b>>c;
	int aa[a],bb[b],cc[c];
	for(int i=0;i<a;i++)
	cin>>aa[i];
	for(int i=0;i<b;i++)
	cin>>bb[i];
	for(int i=0;i<c;i++)
	cin>>cc[i];
	sort(aa,aa+a);
	sort(bb,bb+b);
	int ans[x+y+c];
	int j=a-1;
	for(int i=0;i<x;i++)
	{
	ans[i]=aa[j];
	j--;
	}
	j=b-1;
	for(int i=x;i<x+y;i++)
	{
	    ans[i]=bb[j];
	    j--;
	}
	j=0;
	for(int i=x+y;i<x+y+c;i++)
	{
	ans[i]=cc[j];
	j++;
	}
	sort(ans,ans+x+y+c);
	
	long long int sweetness=0;
	int count=0;
	for(int i=x+y+c-1;count<x+y;i--)
	{
	    sweetness=sweetness+ans[i];
	    count++;
	}
	cout<<sweetness;
	return 0;
}

Measured memory_bytes: 2560
#include <bits/stdc++.h>
#define rep(i, a) for (int i = 0; i < (a); ++i)
#define REP(i, a, b) for (int i = (a); i < (b); ++i)
#define pb push_back
typedef long long ll;
typedef long double la;
using namespace std;

int main(){
    int a,b;
    string s;
    cin >> a >> b;
    cin >> s;
    if(s.size() == a + b + 1 && s[a] == '-'){
        rep(i,s.size()){
            if(s[i] == '-' && i != a){
                cout << "No" << endl;
                return 0;
            }
        }
        cout << "Yes" << endl;
        return 0;
    }
    cout << "No" << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REP(i,a) FOR(i,0,a)
typedef long long ll;
typedef pair<double,int> P;
const double EPS=1e-10;
#define EQ(a,b) fabs(a-b)<EPS

const int MAX_N=1e3;

int N;
int X[MAX_N+2],Y[MAX_N+2],R[MAX_N+2];

struct edge{
	int to;
	double cost;
};

vector<edge> G[MAX_N+2];
double dist[MAX_N+2];

void dijkstra(){
	priority_queue<P,vector<P>,greater<P> > pque;
//	memset(dist,-1,sizeof(dist));
	fill(dist,dist+N+2,-1);
	dist[0]=0;
	pque.push(P(0,0));
	while(!pque.empty()){
		P p=pque.top();
		pque.pop();
		int v=p.second;
		if (dist[v]+EPS<p.first) continue;
		REP(i,(int)G[v].size()){
			edge e=G[v][i];
			if (EQ(dist[e.to],-1) || dist[e.to]>dist[v]+e.cost+EPS){
				dist[e.to]=dist[v]+e.cost;
				pque.push(P(dist[e.to],e.to));
			}
		}
	}
}

double cost(int i,int j){
	double d=(double)abs(X[i]-X[j])*(double)abs(X[i]-X[j])+(double)abs(Y[i]-Y[j])*(double)abs(Y[i]-Y[j]);
	d=sqrt(d)-R[i]-R[j];
	return max<double>(d,0);
}

int main(){
	int xt,yt;
	scanf("%d %d %d %d",&X[0],&Y[0],&xt,&yt);
	scanf("%d",&N);
	X[N+1]=xt;
	Y[N+1]=yt;
	R[0]=R[N+1]=0;
	REP(i,N){
		scanf("%d %d %d",&X[i+1],&Y[i+1],&R[i+1]);
	}
	REP(i,N+2){
		FOR(j,i+1,N+2){
			double c=cost(i,j);
			G[i].push_back(edge{j,c});
			G[j].push_back(edge{i,c});
		}
	}
	dijkstra();
	printf("%.16f\n",dist[N+1]);
	return 0;
}


Measured memory_bytes: 20756
#include <bits/stdc++.h>
 
const double pi = 3.141592653589793238462643383279;
 
 
using namespace std;
//typedef
//------------------------------------------
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef pair<long long, long long> PLL;
typedef pair<int, PII> TIII;
typedef long long LL;
typedef unsigned long long ULL;
typedef vector<LL> VLL;
typedef vector<VLL> VVLL;
 
 
//container util
//------------------------------------------
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define SQ(a) ((a)*(a))
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())
 
 
//repetition
//------------------------------------------
#define FOR(i,s,n) for(int i=s;i<(int)n;++i)
#define REP(i,n) FOR(i,0,n)
#define MOD 1000000007
 
 
#define rep(i, a, b) for(int i = a; i < (b); ++i)
#define trav(a, x) for(auto& a : x)
#define all(x) x.begin(), x.end()
#define sz(x) (int)(x).size()
 
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
const double EPS = 1E-8;
 
#define chmin(x,y) x=min(x,y)
#define chmax(x,y) x=max(x,y)

// ここから編集

auto build_SA(string s){

    vector<pair<string, int>> v;

    int len = s.size();
    string t = "$";
    v.emplace_back(t, len--);
    for(int i=s.size()-1; i>=0; i--){
        t = s[i] + t;
        v.emplace_back(t, len--);
    }

    sort(all(v));

    vector<int> SA;
    for(int i=0; i<v.size(); i++) SA.push_back(v[i].second);

    for(auto e: SA) cout << e << endl;
    return SA;
}
void BWT(string s){

    auto SA = build_SA(s);

    vector<char> v;
    for(int i=0; i<SA.size(); i++){
        if(SA[i] == 0){
            v.push_back('$');
        }else{
            v.push_back(s[SA[i]-1]);
        }
    }
    
    for(int i=0; i<v.size(); i++){
        cout << SA[i] << " " << v[i] << endl;
    }
}

int N;

int cnt[200010][4];
int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(12);
    
    int n; cin >> n;

    map<int, int> mp;
    vector<int> a(n);
    int mi=INT_MAX, mx=0;
    REP(i,n)cin >> a[i],mx=max(mx,a[i]),mi=min(mi,a[i]),mp[a[i]]++;
    if(mx-mi >= 2){
        cout << "No"<< endl;
    }else{
        if(mi == mx){
            if(2*mi <= n){
                cout << "Yes" << endl;
            }else if(mi == n-1){
                cout << "Yes" << endl;
            }else{
                cout << "No" << endl;
            }
        }else{
            int A = mx;
            int x = mp[A-1];
            int y = mp[A];
            if(x < A && 2*(A-x) <= y){
                cout << "Yes" << endl;
            }else{
                cout << "No" << endl;
            }
        }
    }
    

    //最小が 1: 全体の種類数高々2種類
    //       2: 
    // len() = n && 全ての要素がn-1 -> true


    return 0;
}


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

int main() {
  int a, b, c, x, ans = 0;

  cin >> a >> b >> c >> x;

  for (int i = 0; i <= a; i++) {
    for (int j = 0; j <= b; j++) {
      for (int k = 0; k <= c; k++) {
        if (i * 500 + j * 100 + k * 50 == x) ans++;
      }
    }
  }

  cout << ans;
  return 0;
}

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

int main(){
    using namespace std;
    size_t N;
    cin >> N;
    vector<pair<pair<size_t, size_t>, pair<size_t, size_t>>> A(1 << N);
    size_t cnt{0};
    for(auto& i : A){
        cin >> i.first.first;
        i.first.second = ++cnt;
    }
    auto add = [](auto& a, auto b){
        if(a.first < b.first){
            swap(a.first, a.second);
            a.first = b.first;
        }else if(a.first != b.first && a.second < b.first) a.second = b.first;
        if(a.second < b.second)a.second = b.second;
    };
    for(size_t i = 0; i < N; ++i)for(size_t j = 0; j < 1UL << N; ++j)if(1 & (j >> i))add(A[j], A[j ^ (1 << i)]);
    vector<size_t> ans;
    transform(A.begin() + 1, A.end(), back_inserter(ans), [](auto a){return a.first.first + a.second.first;});
    partial_sum(ans.begin(), ans.end(), ans.begin(), [](auto a, auto b){return max(a, b);});
    for(const auto i : ans)cout << i << endl;
}

Measured memory_bytes: 13424
#include<iostream>
#include<string>
#include<stack>/*** LIFO *** stack<type> var;
push(), top():to get data, pop():to remove, size(), empty() ***/
using namespace std;

#define Fp(I, STAT, END) for(int I = STAT; I < END; I++)
#define Fm(I, STAT, END) for(int I = STAT; I > END; I--)

int main(){
    string S;
    cin >> S;
    int size = S.size(), hug = 0;
    int half = (int)(size / 2);
    Fp(i, 0, half){
        if(S[i] != S[(size - 1) - i]) hug++;
        //cout << "i: " << i << ", " << hug << endl;
    }
    cout << hug << endl;

    return 0;
}


Measured memory_bytes: 256
a, b, q = gets.strip.split.map(&:to_i)
s = a.times.map { gets.strip.to_i }
t = b.times.map { gets.strip.to_i }
x = q.times.map { gets.strip.to_i }

rs = s.reverse
rt = t.reverse

x.each do |xx|
  right_s = s.bsearch {|e| e>=xx }
  right_s = right_s-xx if right_s

  left_s = rs.bsearch {|e| e<= xx}
  left_s = xx - left_s if left_s

  right_t = t.bsearch {|e| e>=xx }
  right_t = right_t - xx if right_t

  left_t = rt.bsearch {|e| e<=xx }
  left_t = xx - left_t if left_t

  result = 10**120
  if right_s && right_t
    current = right_s > right_t ? right_s : right_t
    result = current if current < result
  end

  if left_s && left_t
    current = left_s > left_t ? left_s : left_t
    result = current if current < result
  end

  if left_s && right_t
    llr = left_s*2 + right_t
    rrl = left_s + right_t*2
    current = llr < rrl ? llr : rrl
    result = current if current < result
  end

  if left_t && right_s
    llr = left_t *2+ right_s
    rrl = left_t + right_s*2
    current = llr < rrl ? llr : rrl
    result = current if current < result
  end

  p result
end


Measured memory_bytes: 7420
#include <iostream>
#include <cstdio>
#include <string>
#include <vector>
#include <algorithm>
#include <list>
#include <iomanip>
#include <queue>
#include <functional>
#include <cassert>
#include <cmath>
#include <set>
#include <map>
#include <numeric>

#define rep(i, n) for(int i = 0; i < (n); i++)
#define repe(i, n) for(int i = 0; i <= (n); i++)
#define fo(i, a, b) for(int i = (a); i < (b); i++)
#define foe(i, a, b) for(int i = (a); i <= (b); i++)
#define NL << endl

using namespace std;
using ll = long long;
const int INFINT = numeric_limits<int>::max();
const ll INFLL = numeric_limits<long long>::max();
const int MOD = 1000000007;
int gcd(int a, int b) { return b ? gcd(b, a%b) : a; }

using namespace std;


int main() {

	ll n, k;

	cin >> n >> k;

	ll r = n / k;
	ll ans = r * r * r;

	if (!(k & 1)) {
		r = n / (k / 2) - n / k;
		ans += r * r * r;
	}

	cout << ans NL;
	

	return 0;

}

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

long long gcd(long long a, long long b) {
    long long x,y;
    if(a > b){
        y = b;
        x = a;
    }else{
        y = a;
        x = b;
    }

    return ((y==0)? x : gcd(y,x%y));
}

int main(){
    long long N;
    cin >> N;
    long long n = N, tmp=2, cnt=0,cnt2=0,cnt5=0;
    if(n % 2 == 0){
        while(n >= tmp){
            cnt2 += n/tmp;
            tmp *= 2;
        }
    }
    tmp = 5;
    while(n >= tmp){
        cnt5 += (n/tmp)/2;
        tmp *= 5;
    }
    cout << min(cnt2,cnt5) << endl;
    /*
    while(n >= 2){
        tmp = n;
        while(tmp % 10 == 0){
            cnt++;
            tmp /= 10;
        }
        while(tmp % 2 == 0){
            cnt2++;
            tmp /= 2;
        }
        while(tmp % 5 == 0){
            cnt5++;
            tmp /= 5;
        }
        n -= 2;
    }
    long long sum = cnt + min(cnt2, cnt5);
    cout << sum << endl;*/
}



Measured memory_bytes: 256
program name
    implicit none
    integer(4):: n,m
    integer(4),allocatable:: l(:), r(:)
    integer(4):: i,j

    read*, n,m
    allocate(l(m), r(m))

    do i=1,m
        read*, l(i), r(i)
    end do

    print*, max(0, minval(r) - maxval(l)+1)
end program name

Measured memory_bytes: 1024
#include <iostream>
#include <iomanip>
#include <fstream>
#include <vector>
#include <algorithm>
#include <math.h>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <stack>
#include <bitset>

#define _GLIBCXX_DEBUG
#define rep(i, n) for (int64_t i = 0; i < (int64_t)(n); i++)
using namespace std;
using vi = vector<int64_t>;
using vvi = vector<vi>;

int main(int argc, const char * argv[]) {
    // fasten cin
    cin.tie(0);
    ios::sync_with_stdio(false);
    // implement
    double t,x;
    cin >> t >> x;
    cout << setprecision(8) << t/x << endl;
}


Measured memory_bytes: 256
n, k = map(int, input().split())
h = [int(i) for i in input().split()]

dp = [0] * n

for i in range(n - 2, -1, -1):
    dp[i] = min(abs(h[i] - h[min(n - 1, j)]) + dp[min(n - 1, j)] for j in range(i + 1, i + k + 1))

print(dp[0])


Measured memory_bytes: 54368
#include <algorithm>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>
#define MOD 1000000007
using namespace std;

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

int main() {
    int N, M;
    string S;
    cin >> N >> M >> S;
    
    int now = N;
    vector<int> res;

    while (now > 0) {
        if (now - M <= 0) {
            res.push_back(now);
            now = 0;
        } else {
            int i = M; 
            while (i > 0 && S[now - i] == '1') i--;
            if (i == 0) {
                cout << -1 << endl;
                return 0;
            }
            res.push_back(i);
            now -= i;
        }
    }

    for (int i = res.size() - 1; i >= 0; i--) {
        cout << res[i];
        if (i != 0) cout << " ";
    }

    cout << endl;

    return 0;
}

Measured memory_bytes: 1144
#include<iostream>
#include<cstdio>
#include<cstring>
#include<string>
#include<vector>
#include<cmath>
#include<algorithm>
#include<map>
#include<queue>
#include<deque>
#include<iomanip>
using namespace std;
typedef long long int LL;
typedef pair<int,int> P;
typedef pair<int,pair<int,int> > PP;
typedef pair<LL,int> LP;
const int INF=1<<30;
const LL MAX=1e9+7;

void array_show(int *array,int array_n,char middle=' '){
	for(int i=0;i<array_n;i++)printf("%d%c",array[i],(i!=array_n-1?middle:'\n'));
}
void array_show(LL *array,int array_n,char middle=' '){
	for(int i=0;i<array_n;i++)printf("%lld%c",array[i],(i!=array_n-1?middle:'\n'));
}
void print_YES_NO(bool answer){cout<<(answer?"YES":"NO")<<endl;}
void print_Yes_No(bool answer){cout<<(answer?"Yes":"No")<<endl;}
void print_POSSIBLE_IMPOSSIBLE(bool answer){cout<<(answer?"POSSIBLE":"IMPOSSIBLE")<<endl;}

vector<LL> pri;
const LL N=1e5+5;
bool bp[N+2];
LL t[N+2];

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	LL n,m;
	LL i,j,k;
	LL a,b,c;
	pri.push_back(1);
	memset(bp,true,sizeof(bp));
	for(i=2;i<=1e5;i++){
		if(bp[i]){
			pri.push_back(i);
			for(j=i*2;j<=N;j+=i)bp[j]=false;
		}
	}
	memset(bp,true,sizeof(bp));
	for(i=0;i<pri.size();i++){
		for(j=i;j<pri.size();j++){
			a=pri[i]*pri[j];
			if(a>N)break;
			bp[a]=false;
		}
		a=pri[i]*pri[i]*pri[i];
		if(a<N)bp[a]=false;
	}
	for(i=1;i<=1e5;i++){
		t[i]=t[i-1];
		if(bp[i])t[i]++;
	}
	cin>>n;
	for(i=0;i<n;i++){
		cin>>a;
		cout<<t[a]<<endl;
	}
}



Measured memory_bytes: 4192
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        int n = in.nextInt();
        int cur = 0;
        for(int i=0; i<n; i++) {
            int a = in.nextInt();
            if(a == cur + 1) {
                cur = a;
            }
        }
        System.out.println(cur==0?-1:(n-cur));
    }
}


Measured memory_bytes: 64816
import java.util.*;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int[] a = new int[n];

		long sunu = 0;
		long arai = 0;
		for (int i = 0; i < n; i++) {
			a[i] = sc.nextInt();
			arai += a[i];
		}

		long min = 20000000000l;
		for (int i = 0; i < n - 1; i++) {
			sunu += a[i];
			arai -= a[i];
			if (min > Math.abs(sunu - arai)) {
				min = Math.abs(sunu - arai);
			}
		}
		System.out.println(min);
		sc.close();
	}
}


Measured memory_bytes: 85500
#include <iostream>
#include <vector>
#include <map>
#include <tuple>
using namespace std;

int main()
{
    bool p=false,w=false,g=false,y=false;
    int N;
    cin >> N;
    string s;
    for (int i = 0; i < N; i++)
    {
        cin >> s;
        if (s=="P")
        {
            p=true;
        }
        else if (s=="W")
        {
            w=true;
        }
        else if (s=="G")
        {
            g=true;
        }
        else if (s=="Y")
        {
            y=true;
        }
        
    }
    if (p && w && g && y)
    {
        cout << "Four" << endl;
    }
    else
    {
        cout << "Three" << endl;
    }
}


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

int main(){
  int x,y;
  cin >> x >> y;
  int a=min(x,y);
  int b=max(x,y);
  if((b-a)%2==1)
    cout << "IMPOSSIBLE" << endl;
  else
    cout << b-(b-a)/2 << endl;
}

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

int solve(int n, int d){
  if(n == 0 and d == 0) return 1;
  vector<vector<int>> M(n);
  vector<int> P(n);
  int m_sum = 0;
  for(int i = 0; i < n; ++i){
    int m;
    cin >> m;
    m_sum += m;
    for(int j = 0; j < m; ++j){
      int c;
      cin >> c;
      P[i] += c;
      M[i].push_back(c);
    }
  }
  string ans = "Yes";
  while(m_sum > 0){
    int m_ = m_sum;
    vector<int> F(n+1), B(n+1);
    for(int i = 0; i < n; ++i){
      F[i+1] = max(F[i],P[i]);
    }
    for(int i = n-2; i >= 0; --i){
      B[i] = max(B[i+1],P[i+1]);
    }
    for(int i = 0; i < n; ++i){
      if(M[i].empty()) continue;
      int ma = max(F[i],B[i]);
      if(P[i]-M[i].back() >= ma-d){
        --m_sum;
        P[i] -= M[i].back();
        M[i].pop_back();
      }
    }
    if(m_ == m_sum){
      ans = "No";
      break;
    }
  }
  cout << ans << endl;
  return 0;
}

int main(){
  int n, d;
  while(cin >> n >> d){
    if(solve(n,d)) break;
  }
}



Measured memory_bytes: 3092
#include <bits/stdc++.h>
using namespace std;
///////////////////////////////////////////
const long long int INF = 1LL<<60;
const long long int Mod = 1000000007;
using ll = long long int; using ci = const int;
using vi = vector<int>;  using Vi = vector<long long int>;
using P = pair<int, int>;  using PLL = pair<ll, ll>;
using matrix = vector<vector<ll>>;
#define pb(x) push_back(x)
#define mp(x,y) make_pair(x,y)
#define all(x) (x).begin(),(x).end()
#define rp(i,N) for(ll i = 0; i < (ll)N; i++)
#define repi(i,a,b) for(ll i = ll(a); i < ll(b); ++i)
template<class T>bool chmax(T &former, const T &b) { if (former<b) { former=b; return true; } return false; }
template<class T>bool chmin(T &former, const T &b) { if (b<former) { former=b; return true; } return false; }
template<class T>T sqar(T x){ return x*x; }//sqrt(x)は平方根;
#define Sort(v) std::sort(v.begin(), v.end(), std::greater<decltype(v[0])>()) //降順でVをソート
#define p_queue(v) priority_queue<v, vector<v>, greater<v> >
template<class T> inline void princ(T x){cout<<x<<" ";}; 
template<class T> inline void print(T x){cout<<x<<"\n";};
template<class T> inline void Yes(T condition){ if(condition) cout << "Yes" << endl; else cout << "No" << endl; }
template<class T> inline void YES(T condition){ if(condition) cout << "YES" << endl; else cout << "NO" << endl; }
///////////////////////////////////////////////////////////////////////////////////

void solve(){
    string s;
    int k;
    cin >> s >> k;
    set<string> se;
    set<char> strse;
    int n=s.size();
    rp(i,n){
        strse.insert(s[i]);
    }
    auto chite=strse.begin();
    int ctr=0;
    rp(loop,3){
        rp(i,n){
            if(s[i]==*chite){
                for(int j=1; j<=5&&i+j-1<n; j++){
                    if(!se.count(s.substr(i,j))) ctr++;
                        se.insert(s.substr(i,j));
                }
            }
        }
        if(ctr>=k) break;
        chite++;
    }
    auto ansite=se.begin();
    rp(i,k-1) ++ansite;
    print(*ansite);
    return;
}
int main(){
    cin.tie(0);ios::sync_with_stdio(false);
    std::cout<<std::fixed<<std::setprecision(30);
    solve();
    return 0;
}

Measured memory_bytes: 384
#include <stdio.h>

int main(void){
  long long L,R,i,j;
  int min=2020;
  scanf("%lld %lld",&L,&R);
  if(R-L>=2019){
    printf("0\n");
    return 0;
  }
  for(i=L;i<=R;i++){
    for(j=i+1;j<=R;j++){
      if(min>(i*j)%2019) min=(i*j)%2019;
    }
  }
  printf("%d\n",min);

  return 0;
}

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

#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define ll long long
#define INF 999999999
#define MOD 1000000007

using namespace std;
typedef pair<int, int> P;
typedef pair<ll, ll> LP;
typedef pair<int, P> PP;
typedef pair<ll, LP> LPP;

int iy[]={0, 0, 1, -1};
int ix[]={1, -1, 0, 0};

int n, h[100010], dp[100010];

int main(){
	cin >> n;
	for(int i=1;i<=n;i++){
		cin >> h[i];
	}
	dp[2] = abs(h[1]-h[2]);
	for(int i=3;i<=n;i++){
		dp[i] = min(dp[i-1]+abs(h[i]-h[i-1]), dp[i-2]+abs(h[i]-h[i-2]));
	}
	cout << dp[n] << endl;
	return 0;
}

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

using namespace std;
#define sqr(x) ((x)*(x))
#define cube(x) ((x)*(x)*(x))
#define GCD(a, b) (__gcd(a, b))
#define LCM(a, b) ((a)/GCD(a,b)*(b))
#define PI (3.141592653589793238462643383279502884197169399375105820974944)
#define MP make_pair
#define n1 first
#define n2 second
#define ALL(x) (x).begin(), (x).end()
#define PII pair<int,int>
#define PLL pair<ll,ll>
#define PDB pair<db,db>
#define SI set<int>
#define SL set<ll>
#define MS multiset
#define MSI multiset<int>
#define MSLL multiset<ll>
#define PB push_back
#define PF push_front
#define VI vector<int>
#define VPI vector<pair<int,int>>
#define VLL vector<ll>
#define VS vector<string>
#define SZ(x) ((int)x.size())

typedef long long ll;

typedef unsigned long long ull;
typedef long double ld;
typedef double db;
const db eps = 0.000001;
const int INF = 1000000007;
const ll LINF = 1000000000000000555;
const int N = 450555;
const int M = 1125;

int a[N];
void solve() {
    int n;
    cin >> n;

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

    sort(a+1, a+n+1);

    ll sum = a[n], x = n-2;
    for (int i = n-1; i >= 1; i--){
        if (x == 0) break;
        sum += a[i];
        x--;
        if (x == 0) break;
        sum += a[i];
        x--;
    }

    cout << sum;

}

int main() {
    ios_base::sync_with_stdio(false);
#ifdef dxz05
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#else

#endif

    int T = 1;
    //cin >> T;

    while (T--) {
        solve();
    }

    return 0;
}

Measured memory_bytes: 4424
n = int(input())
A, B, C = [], [], []

for i in range(n):
  a, b, c = map(int, input().split())
  A.append(a)
  B.append(b)
  C.append(c)

dp_a, dp_b, dp_c = [0] * n, [0] * n, [0] * n
dp_a[0] = A[0]
dp_b[0] = B[0]
dp_c[0] = C[0]

for i in range(1, n):
  dp_a[i] = max(dp_b[i-1], dp_c[i-1]) + A[i]
  dp_b[i] = max(dp_c[i-1], dp_a[i-1]) + B[i]
  dp_c[i] = max(dp_a[i-1], dp_b[i-1]) + C[i]
print(max(dp_a[-1], dp_b[-1], dp_c[-1]))

Measured memory_bytes: 93056
def main():
    n, k = map(int, input().split())
    a = list(map(int, input().split()))
    to = [[None]*n for _ in range(60)]
    to[0] = a[:]
    for i in range(1, 60):
        for j in range(n):
            to[i][j] = to[i-1][to[i-1][j]-1]
    p = 1
    for i in range(59, -1, -1):
        num = 1 << i
        if k >= num:
            k -= num
            p = to[i][p-1]
    print(p)
        

if __name__ == "__main__":
    main()

Measured memory_bytes: 184348
#include <iostream>
#include <string>
#include <vector>
#include <map>
#include <algorithm>
#include <cmath>
#include <sstream>
#include <iomanip>
#include <set>
using namespace std;
typedef long long int ll;

#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define YES cout << "YES" << endl
#define Yes cout << "Yes" << endl
#define yes cout << "yes" << endl
#define NO cout << "NO" << endl
#define No cout << "No" << endl
#define no cout << "no" << endl

const int INF = 1001001001;
const int mod = 1000000007;
#define PI 3.14159265359;

void P(int x) {cout << x << endl;}
void P(long x) {cout << x << endl;}
void P(double x) {cout << x << endl;}
void P(ll x) {cout << x << endl;}
void P(string x) {cout << x << endl;}
void P(char x) {cout << x << endl;}

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

int main() {
  int d;
  cin >> d;
  if (d == 25) P("Christmas");
  else if (d == 24) P("Christmas Eve");
  else if (d == 23) P("Christmas Eve Eve");
  else if (d == 22) P("Christmas Eve Eve Eve");



  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include<cmath>
#include<iomanip>
using namespace std;
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int X,Y;
    cin>>X>>Y;
    int count1=X;
    int count2=0;
    int d=0;
    while(count2<=X)
    {
    	if(((count1)*2)+((count2)*4)==Y)
    	{
    		d=1;
    		break;
    	}
    	else
    	{
    		count1--;
    		count2++;
    	}
    }
    if(d==1)
    {
      cout<<"Yes";
    }
    else
    {
    	cout<<"No";
    }
}

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

using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int,int> pii;

typedef int _loop_int;
#define REP(i,n) for(_loop_int i=0;i<(_loop_int)(n);++i)
#define FOR(i,a,b) for(_loop_int i=(_loop_int)(a);i<(_loop_int)(b);++i)
#define FORR(i,a,b) for(_loop_int i=(_loop_int)(b)-1;i>=(_loop_int)(a);--i)

#define VIN(v) for(auto&elem_: (v) )cin>>elem_
#define VOUT(v, sep) for(_loop_int idx=0; idx<(_loop_int)v.size(); idx++) {cout<<v[idx]; if(idx<(_loop_int)v.size()-1) cout<<sep;} cout<<endl
#define ALL(a) (a).begin(),(a).end()

#define DEBUG(x) cout<<#x<<": "<<x<<endl
#define DEBUG2(x,y) cout<<#x<<": "<<x<<" "<<#y<<": "<<y<<endl
#define DEBUG_VEC(v) cout<<#v<<":";REP(debugidx,v.size())cout<<" "<<v[debugidx];cout<<endl
#define DEBUG_ARR(v,n) cout<<#v<<":";REP(debugidx,n)cout<<" "<<v[debugidx];cout<<endl

const ll MOD = 1000000007ll;
const int IINF = numeric_limits<int>::max()/2-1;
const ll LINF = numeric_limits<ll>::max()/2-1;

template<class T> inline bool chmin(T& a, const T b) { if (a>b) { a=b; return true; } return false; }
template<class T> inline bool chmax(T& a, const T b) { if (a<b) { a=b; return true; } return false; }


int a,b,c,x,y;
int main() {
    ios::sync_with_stdio(false); cin.tie(0);
    cin>>a>>b>>c>>x>>y;

    ll ans = 0;
    int price = 0;
    if(c*2 >= a+b){
        price = a+b;
    }else{
        price = c*2;
    }
    while(x>0 && y>0){
        ans += price;
        x--;
        y--;
    }
    //DEBUG(ans);

    //aのみ
    if(c*2 >= a){
        price = a;
    }else{
        price = c*2;
    }
    while(x>0){
        ans += price;
        x--;
    }

    //bのみ
    if(c*2 >= b){
        price = b;
    }else{
        price = c*2;
    }
    while(y>0){
        ans += price;
        y--;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3544