akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<iomanip>
#include<math.h>
#include<complex>
#include<queue>
#include<deque>
#include<stack>
#include<map>
#include<set>
#include<bitset>
#include<functional>
#include<assert.h>
#include<numeric>
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(ll i=(int)(m) ; i < (int) (n) ; ++i )
#define rep(i,n) REP(i,0,n)
#define F first
#define S second
constexpr char ln = '\n';

const int mx=100010;
const ll mod=1e9+7;

int main(){
  string s;
  rep(i,3){
    cin >> s;
    cout << char(s[0]+('A'-'a'));
  }
  cout << ln;

  return 0;
}

Measured memory_bytes: 3608
#include <iostream>
#include <string>
#include <algorithm>
#include <numeric>
#include <queue>
#include <utility>
#include <cmath>
#include <iomanip>
#include <map>
using namespace std;

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define ALL(a)  (a).begin(),(a).end()

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


int main(){
    // エラトステネスのふるい
    int MAX = 100010;
    vector<int> is_prime(MAX, 1);
    is_prime[0] = 0, is_prime[1] = 0;
    for (int i = 2; i < MAX; ++i) {
        if (!is_prime[i]) continue;
        for (int j = i*2; j < MAX; j += i) is_prime[j] = 0;
    }

    vector<int> a(MAX, 0);
    REP(i,MAX){
    	if(i%2==0) continue;
    	if(is_prime[i] && is_prime[(i+1)/2]) a[i]=1;
    }

    vector<int> s(MAX+1,0);
    REP(i,MAX+1) s[i+1] = s[i] + a[i];

    int Q;
    cin >> Q;
    
    REP(i,Q){
    	int l,r;
    	cin >> l >> r;
    	
    	cout << s[r+1] - s[l] << endl;
    }

	return 0;
}


Measured memory_bytes: 1792
package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
)

func out(x ...interface{}) {
	fmt.Println(x...)
}

var sc = bufio.NewScanner(os.Stdin)

func getInt() int {
	sc.Scan()
	i, e := strconv.Atoi(sc.Text())
	if e != nil {
		panic(e)
	}
	return i
}

func getString() string {
	sc.Scan()
	return sc.Text()
}

// min, max, asub, absなど基本関数
func max(a, b int) int {
	if a > b {
		return a
	}
	return b
}

func min(a, b int) int {
	if a < b {
		return a
	}
	return b
}

func asub(a, b int) int {
	if a > b {
		return a - b
	}
	return b - a
}

func abs(a int) int {
	if a >= 0 {
		return a
	}
	return -a
}

func main() {
	sc.Split(bufio.ScanWords)
	N := getInt()
	a := make([]int, N)
	for i := 0; i < N; i++ {
		a[i] = getInt()
	}
	if a[0] != 0 {
		out(-1)
		return
	}
	for i := 1; i < N; i++ {
		if a[i] > a[i-1]+1 {
			out(-1)
			return
		}
	}

	ans := 0
	for i := 1; i < N; i++ {
		if a[i] == a[i-1]+1 {
			ans++
		} else {
			ans += a[i]
		}
	}

	out(ans)
}


Measured memory_bytes: 4608
#include<bits/stdc++.h>
typedef long long int ll;
typedef unsigned long long int ull;
#define BIG_NUM 2000000000
#define HUGE_NUM 99999999999999999
#define MOD 1000000007
#define EPS 0.000000001
using namespace std;


#define NUM 10005

int N,W;
int dp[NUM];

int main(){

	dp[0] = 0;
	for(int i = 1; i < NUM; i++){

		dp[i] = BIG_NUM;
	}

	scanf("%d %d",&N,&W);

	int value,weight;

	for(int loop = 0; loop < N; loop++){

		scanf("%d %d",&value,&weight);

		for(int i = NUM-1; i >= 0; i--){
			if(i-value < 0)break;

			dp[i] = min(dp[i],dp[i-value]+weight);
		}
	}

	for(int i = NUM-1; i >= 0; i--){

		if(dp[i] <= W){

			printf("%d\n",i);
			return 0;
		}
	}

	return 0;
}




Measured memory_bytes: 3252
#include<bits/stdc++.h>
using namespace std;
using ull=unsigned long long;
#define mod 1000000007
#define mod2 998244353 
#define PI 3.14159265
#define ll long long
#define ld long double
#define pi pair<ll,ll>
#define pb push_back
#define vi vector<ll>
#define sz size()
#define setbits(x)  __builtin_popcount(x)
#define fi first
#define se second
#define lz length()
#define all(x) (x).begin(),(x).end()
#define scf(x) scanf("%lld",&x)
#define rep(i,n) for(ll i=0;i<n;i++)
const int INF = (int)1e9;
const ll IINF=1LL<<62;
const int maxn=10000005;

//int divr[maxn];
/**/
/*void divisor()
{for(int i=2;i<sqrt(maxn);i++)
     {
          if(!divr[i])
          {
               for(int j=i*i;j<maxn;j+=i)if(!divr[j])divr[j]=i;     
          }
     }
     for(int i=1;i<maxn;i++)if(!divr[i])divr[i]=i;
}*/
 
/*const int N=1000005;
ll n;
struct line {
    long long m, c;
    long long eval(long long x) { return m * x + c; }
    long double intersectX(line l) { return (long double) (c - l.c) / (l.m - m); }
};
vector<pair<pi,ll>> rect;
deque<line> dq;
*/
ll modexpo(ll a,ll b)
{
     ll res=1LL;
     while(b>0)
     {
          if(b&1)res=(res*a)%mod;
          a=(a*a)%mod;
          b>>=1;
     }
     return res;
}
 
 
 
 
 
 
 







int dp[200][200];
int x[100][100],y[100][100];
int main()
{
    int h,w;
    cin>>h>>w;
    vector<string> str(h);
    for(int i=0;i<h;i++){
         cin>>str[i];
    }
    int a[26]={0};
    for(int i=0;i<h;i++){
         for(int j=0;j<str[i].length();j++){
              a[str[i][j]-'a']++;
         }
    }
    int g4=0,g2=0,g1=0;
    for(int i=0;i<h;i++){
         for(int j=0;j<w;j++){
              if(h-1-i<i)continue;
              if(w-1-j<j)continue;
              int c=0;
              if(h-1-i==i)c++;
              if(w-1-j==j)c++;
              if(c==0)g4++;
              else if(c==1)g2++;
              else g1++;
         }
    }
    int t=0;
    for(int i=0;i<26;i++){
        t=a[i]/4;
        t=min(t,g4);
        g4-=t;
        a[i]-=t*4;
        t=a[i]/2;
        t=min(t,g2);
        g2-=t;
        a[i]-=t*2;
        t=a[i]/1;
        t=min(t,g1);
        g1-=t;
        a[i]-=t*1;
        if(a[i]!=0){cout<<"No";return 0;}
     }
     cout<<"Yes";
     
}


























Measured memory_bytes: 3664
#include<bits/stdc++.h>
using namespace std;
int main(){
  int n;
  cin>>n;
  vector<int> a(n+5);
  vector<int> b(n+5);
  vector<int> c(n+5);
  for(int i=0;i<n;i++){
    cin>>a[i+1]>>b[i+1]>>c[i+1];
  }
  
  vector<vector<long long> > dp(n+5,vector<long long>(4,0));  
  for(int i=1;i<=n;i++){
    dp[i][1]=max(dp[i-1][2],dp[i-1][3])+a[i];
    dp[i][2]=max(dp[i-1][1],dp[i-1][3])+b[i];
    dp[i][3]=max(dp[i-1][2],dp[i-1][1])+c[i];
  }
  cout<<max(dp[n][1],max(dp[n][2],dp[n][3]))<<'\n';
}

Measured memory_bytes: 11384
#include <bits/stdc++.h>
using namespace std;
long long x,y,z,t,m,n,i,j,k,c,cnt,d,sum,mn,mx;
int main()
{
    ios_base::sync_with_stdio(0);
//    cin.tie(0);
//    cout.tie(0);
    cin>>n>>k;
    n--, k--;
    d=k/n;
    if(k%n) d++;
    cout<<d;
}



Measured memory_bytes: 256
#include <stdio.h>
#define trade(a,b)      (a)+=(b);(b)=(a)-(b);(a)-=(b);
main(){
        int N,ln=1,hn=1,l=-1,h=-1,tmp,i;
        scanf("%d",&N);
        for(i=0;i<N;i++){
                scanf("%d",&tmp);
                if(tmp==l)
                        ln++;
                else{
                        if(tmp==h)
                                hn++;
                        else if(l==-1)
                                l=tmp;
                        else if(h==-1){
                                h=tmp;
                                if(h<l){
                                        trade(h,l);
                                        trade(hn,ln);
                                }
                        }else{
                                puts("No");
                                return 0;
                        }
                }
        }
        if(l+1==h && ln+1<=h && h<=ln+hn/2){
                puts("Yes");
        }else if(ln==N && (l<=N/2 || l==N-1)){
                puts("Yes");
        }else{
                puts("No");
        }
        return 0;
}

Measured memory_bytes: 128
#include<iostream>
#include<string>
#include<vector>
#include<queue>
#include<algorithm>
#include<map>
#include<set>
#include<cmath>
#include<iomanip>
#include<stack>
#include<string.h>
#include<cstring>
typedef long long ll;
#define rep(i,n) for(int i=0;i<(n);i++)
#define pb push_back
#define sz(a) (int)a.size()
using namespace std;

int main() {
    int n;
    cin >> n;
    vector<int> a(n);
    set<int> se;
    vector<int> cnt(10000000);
    rep(i, n) {
        cin >> a[i];
        se.insert(a[i]);
        cnt[a[i]] ++;
    }

    int ans = 0;
    rep(i, n) {
        bool flag = true;
        vector<int> resi = {};
        for (int j = 1; j * j <= a[i]; j++) {
            if (a[i] % j == 0) {
                resi.push_back(j);
                if (a[i] / j != j) resi.push_back(a[i] / j);
            }
        }

        rep(k, sz(resi)) {
            if (resi[k] != a[i]) {
                if (se.count(resi[k])) flag = false;
            }
            else {
                if (cnt[a[i]] > 1) flag = false;
            }
        }
        if (flag) ans++;
    }
    cout << ans << endl;
}


Measured memory_bytes: 52620
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

public class Main {
	public static void main(String[] args) throws NumberFormatException, IOException {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		
		String[] nk = br.readLine().split(" ");
		int n = Integer.parseInt(nk[0]);
		int k = Integer.parseInt(nk[1]);
		
		List<List<Integer>> list = new ArrayList<>();
		
		for (int i = 0; i < n; i++) {
			list.add(new ArrayList<>());
		}
		
		for (int i = 0; i <k; i++) {
			String[] input = br.readLine().split(" ");
			int m = Integer.parseInt(input[0])-1;
			int o = Integer.parseInt(input[1])-1;
			
			list.get(m).add(o);
		}
		
		int longestPath = getLongestPath(list);
		
		System.out.println(longestPath);
	}

	private static int getLongestPath(List<List<Integer>> list) {
		
		Map<Integer,Integer> map = new HashMap<>();
		
		int max = 0;
		
		for (int i = 0; i < list.size(); i++) {
			max = Math.max(max, helper(list, i, map));
		}
		
		return max;
		
	}

	private static int helper(List<List<Integer>> list, int curr, Map<Integer, Integer> map) {
		
		if(curr==list.size())
			return 0;
		
		if(map.containsKey(curr))
			return map.get(curr);
		
		int max = 0;
		
		for(int k : list.get(curr)) {
			max = Math.max(max, 1+helper(list, k, map));
		}
		
		map.put(curr, max);
		
		return max;
	}
}

Measured memory_bytes: 83228
#include<iostream>

int gcd(int a, int b) {
  if(a < b) return gcd(b, a);
  int r;
  while ((r=a%b)) {
    a = b;
    b = r;
  }
  return b;
}

int main(){
    int a, b;
    std::cin >> a >> b;
    
    int ans = gcd(a,b);
    std::cout << ans << std::endl;
    return 0;
}


Measured memory_bytes: 3116
s_1 = gets.chomp.split("")
n = s_1.size
s_2 = s_1[0...(n - 1) / 2]
s_3 = s_1[((n + 3) / 2 - 1)...n]
if s_1 == s_1.reverse && s_2 == s_2.reverse && s_3 == s_3.reverse
  puts "Yes"
else
  puts "No"
end


Measured memory_bytes: 1916
def resolve():
    from collections import Counter
    mod = 10**9 + 7
    N = int(input())
    A = sorted([int(i) for i in input().split()])
    if N % 2 == 0:
        pattern = sorted([i for i in range(1, N, 2)] * 2)
    else:
        pattern = [0] + sorted([i for i in range(2, N, 2)] * 2)
    if A != pattern:
        print(0)
    else:
        ans = 1
        for _ in range(N // 2):
            ans = ans * 2 % mod
        print(ans % mod)

resolve()


Measured memory_bytes: 20876
#include <iostream>
#include <numeric>

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

int main() {
  int n, k;
  std::cin >> n >> k;

  int *a = new int[n + 1];
  rep(i, n + 1) a[i] = i;

  long long sum = 0;

  for (long long i = k; i <= n + 1; ++i) {
    long long min = i * (i - 1) / 2;
    long long max = i * (2 * n - i + 1) / 2;

    long long m = max - min + 1;

    sum += m;
  }

  std::cout << sum % (1000000000 + 7) << '\n';

  return 0;
}


Measured memory_bytes: 4348
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<int, int>;
using Vec  =vector<int>;

int		main(void)
{
	int n, k;
	cin >> n >> k;
	long double ans = 0;

	for (int i = 1; i <= n; i++)
	{
		long double tmp = i;
		int c = 0;
		while (tmp < k)
		{
			tmp *= 2;
			c++;
		}
		ans += pow(0.500000000000, c);
	}
	ans /= n;
	printf("%.10Lf\n", ans);
}


	



Measured memory_bytes: 256
#include <iostream>
#include <unordered_map>

int main()
{
    std::string s;
    std::cin >> s;

    std::unordered_map<char, int> m;
    for (auto c : s) {
        m[c]++;
    }

    for (auto i = m.begin(); i != m.end(); i++) {
        if (i->second != 2) {
            std::cout << "No" << std::endl;
            return 0;
        }
    }

    std::cout << "Yes" << std::endl;
}


Measured memory_bytes: 384
//============================================================================
// Name        : JOI.cpp
// Author      :
// Version     :
// Copyright   : Your copyright notice
// Description : Hello World in C++, Ansi-style
//============================================================================

#include <iostream>
#include <cstdio>
#include <string>
#include <algorithm>
#include <math.h>
#include <stdio.h>
#include <vector>
using namespace std;
typedef long long ll;
int N;
int main() {
	cin>>N;

	if(N/10==9 || N%10==9)cout<<"Yes"<<endl;
	else cout<<"No"<<endl;

	return 0;
}


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

using namespace std;

#define mp make_pair
#define pb push_back
#define fi first
#define se second
#define ALL(x) (x).begin(), (x).end()
#define SZ(x) ((int)((x).size()))

typedef pair<int, int> PII;
typedef vector<int> VI;
typedef long long int64;
typedef unsigned int uint;
typedef unsigned long long uint64;

#define gi(x) ((x) = F())
#define gii(x, y) (gi(x), gi(y))
#define giii(x, y, z) (gii(x, y), gi(z))

int F()
{
	char ch;
	int x, a;
	while (ch = getchar(), (ch < '0' || ch > '9') && ch != '-');
	if (ch == '-') ch = getchar(), a = -1;
	else a = 1;
	x = ch - '0';
	while (ch = getchar(), ch >= '0' && ch <= '9')
		x = (x << 1) + (x << 3) + ch - '0';
	return a * x;
}

const int N = 1e5 + 10; 

int n;

int siz[N];

VI edge[N];

bool ok;

void dfs(int u, int fa)
{
	siz[u] = 1;
	int cnt = 0;
	for (auto v : edge[u])
	{
		if (v == fa) continue;
		dfs(v, u);
		siz[u] += siz[v];
		cnt += (siz[v] & 1);
	}
	cnt += ((n - siz[u]) & 1);
	if (cnt > 1) ok = 1;
}

int main()
{
	gi(n);
	for (int i = 1; i < n; ++i)
	{
		int u, v;
		gii(u, v);
		edge[u].pb(v);
		edge[v].pb(u); 
	}
	dfs(1, 0);
	if (n & 1) ok = 1;
	puts(ok ? "First" : "Second");
	return 0;
}

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

void main()
{
  char ids[256];
  char idt[256];
  int i = 0;
  int count = 1;
  scanf("%s", ids);
  scanf("%s", idt);
  while ( ids[i] != '\0')
  {
    if(ids[i] != idt[i])
    {
      printf("No\n");
      count = 0;
      break;
    }
    i++;
  }
  if( count == 1)
  {
    printf("Yes\n");
  }
}

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

int main() {
    int mod=1e9+7;
    int n;cin>>n;
    ll a[n];
    for (int i=0;i<n;i++)
        cin>>a[i];
    int ans=0;
    for (int i=0;i<60;i++) {
        int c=0;
        for (int j=0;j<n;j++)
            c+=a[j]>>i&1;
        ans=(ans+(1LL<<i)%mod*c%mod*(n-c)%mod)%mod;
    }
    cout<<ans<<endl;
}

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


int main() {
	int n, d;
	int count = 0;
	long long int a,b;
	scanf("%d %d", &n, &d);

	int* x = (int*)malloc(sizeof(int) * n);
	int* y = (int*)malloc(sizeof(int) * n);

	for (int i = 0; i < n; i++) {
		scanf("%d %d", x + i, y + i);
	}

	for (int i = 0; i < n; i++) {
		a = pow(*(x + i), 2);
		b = pow(*(y + i), 2);
		if (sqrt(a+b) <= d) {
			count++;
		}
	}

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

Measured memory_bytes: 3724
#include <cstdio>
#include <cstring>
#include <iostream>
#include <string>
#include <cmath>
#include <bitset>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <algorithm>
#include <complex>
#include <unordered_map>
#include <unordered_set>
#include <random>
#include <cassert>
#include <fstream>
#include <utility>
#include <functional>
#include <time.h>
#include <stack>
#include <array>
#include <list>
#define popcount __builtin_popcount
using namespace std;
typedef long long int ll;
typedef pair<int, int> P;

int main()
{
	int n;
	cin>>n;
	ll a[200020];
	for(int i=0; i<n; i++) cin>>a[i];
	ll dp[4][200020];
	for(int i=0; i<4; i++) fill(dp[i], dp[i]+n+1, -1e18);
	dp[0][0]=0;
	for(int i=0; i<=3 && i<n; i++){
		dp[(i+2)/2-1][i+1]=a[i];
	}
	for(int i=0; i<n; i++){
		for(int j=0; j<4; j++){
			if((i+1)/2-j<0) continue;
			for(int k=i+1; k<=i+3 && k<n; k++){
				int t=(k+2)/2-((i+1)/2-j+1);
				if(t<0 || t>=4) continue;
				dp[t][k+1]=max(dp[t][k+1], dp[j][i]+a[k]);
			}
		}
	}
	ll ans=-1e18;
	for(int i=n; i>=0; i--){
		if((i+1)/2-n/2<0) break;
		ans=max(ans, dp[(i+1)/2-n/2][i]);
	}
	cout<<ans<<endl;
	return 0;
}


Measured memory_bytes: 11436
import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {
        
        Scanner sc = new Scanner(System.in);
        int[] array = {Integer.parseInt(sc.nextLine()),
                        Integer.parseInt(sc.nextLine()),
                        Integer.parseInt(sc.nextLine()),
                        Integer.parseInt(sc.nextLine()),
                        Integer.parseInt(sc.nextLine())};
        
        int result = 0;
        int p = 0;
        int q = 0;
        int tmp = 0;
        
        for(int i = 0; i < array.length - 1; i++){
            for(int j = i; j < array.length; j++){
                p = array[i] % 10;
                if(p == 0){
                    p = 10;
                }
                q = array[j] % 10;
                if(q == 0){
                    q = 10;
                }
                
                if(p < q){
                    tmp = array[i];
                    array[i] = array[j];
                    array[j] = tmp;
                }
            }
        }
        
        
        for(int i = 0; i < array.length; i++){
            if(i > 0 && array[i - 1] % 10 != 0){
                result += 10 - (array[i - 1] % 10);
            }
            result += array[i];
        }
        
        System.out.println(result);
        
    }
}


Measured memory_bytes: 20948
#include <iostream>
#include <cstring>
#include <set>
using namespace std;

int op[10][10];
int cache[100000];

int calc(int i) {
  int res = op[0][(i / 10000) % 10];
  res = op[res][(i / 1000) % 10];
  res = op[res][(i / 100) % 10];
  res = op[res][(i / 10) % 10];
  res = op[res][i % 10];
  return res;
}

int construct(int a, int b, int c, int d, int e) {
  return a * 10000 + b * 1000 + c * 100 + d * 10 + e;
}

bool check(int x) {
  int a = (x / 10000) % 10;
  int b = (x / 1000) % 10;
  int c = (x / 100) % 10;
  int d = (x / 10) % 10;
  int e = x % 10;

  // check swaps
  if (construct(b, a, c, d, e) != x &&
      calc(construct(b, a, c, d, e)) == 0) return false;
  if (construct(a, c, b, d, e) != x &&
      calc(construct(a, c, b, d, e)) == 0) return false;
  if (construct(a, b, d, c, e) != x &&
      calc(construct(a, b, d, c, e)) == 0) return false;
  if (construct(a, b, c, e, d) != x &&
      calc(construct(a, b, c, e, d)) == 0) return false;

  for (int i = 0; i < 10; ++i) {
    if (construct(i, b, c, d, e) != x &&
        calc(construct(i, b, c, d, e)) == 0) return false;
    if (construct(a, i, c, d, e) != x &&
        calc(construct(a, i, c, d, e)) == 0) return false;
    if (construct(a, b, i, d, e) != x &&
        calc(construct(a, b, i, d, e)) == 0) return false;
    if (construct(a, b, c, i, e) != x &&
        calc(construct(a, b, c, i, e)) == 0) return false;
    if (construct(a, b, c, d, i) != x &&
        calc(construct(a, b, c, d, i)) == 0) return false;
  }

  return true;
}

int main() {
  memset(op, 0, sizeof(op));

  for (int i = 0; i < 10; ++i) {
    for (int j = 0; j < 10; ++j) {
      cin>>op[i][j];
    }
  }

  for (int i = 0; i < 100000; ++i) {
    cache[i] = calc(i);
  }

  std::set<int> no;
  int ans = 0;
  for (int i = 0; i < 100000; ++i) {
    if (cache[i] == 0 && !check(i)) {
      no.insert(i/10);
    }
  }
  cout << no.size() << endl;
}

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

int main() {
  int n;
  cin >> n;
  vector<int> a(n);
  for (auto &&w : a) {
    cin >> w;
  }
  vector<int> cnt(8, 0);
  int b = 0;
  for (auto &&w : a) {
    int t = w / 400;
    if (t < 8)
      cnt[t]++;
    else
      b++;
  }
  int num = 0;
  for (auto &&w : cnt) {
    if (w > 0) {
      num++;
    }
  }
  int mn, mx;
  mn = (num == 0) ? 1 : num;

  mx = num + b;
  cout << mn << " " << mx << endl;
}

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

signed main() {
	string a, b ; cin >> a >> b; 
	int n = a.length() ; 
	int m = b.length() ; 
	std::vector<vector<int> >dp(n+1,vector<int>(m+1,0)) ; 
	int ans = 0 ; 
	for (int i = 1; i <= n; ++i) {
		int temp  = INT_MIN ;
		for (int j = 1; j <= m; ++j) {
			if ( a[i-1] == b[j-1] ) {
				dp[i][j] = dp[i-1][j-1] + 1; 
			}
			else {
				dp[i][j] = max(dp[i-1][j],dp[i][j-1]) ; 
			}
		}
	}
	int i = n, j = m ; 
	string str = "" ; 
	while ( i > 0 && j > 0 ) {
		if ( a[i-1] == b[j-1] ) {
			str += a[i-1] ; 
			--i ; --j ; 
		}
		else if ( dp[i][j-1] > dp[i-1][j] ) {
			--j ; 
		}
		else {
			--i ; 
		}
	}
	reverse(str.begin(),str.end()) ;
	cout << str << endl ; 
	return 0 ; 
}

Measured memory_bytes: 35584
count = [0 for i in range(4)]
for i in range(3):
    a, b = map(int, input().split(" "))
    count[a-1] += 1
    count[b-1] += 1

for n in count:
    if n == 0 or n == 3:
        print("NO")
        exit()
print("YES")



Measured memory_bytes: 2940
class UF():
  def __init__(self, N):
    self.par = [-1]*N
 
  def find(self, x):
    if self.par[x] < 0:
      return x
    else:
      self.par[x] = self.find(self.par[x])
      return self.par[x]
 
  def union(self, x,y):
    p1,p2 = self.find(x),self.find(y)
    if p1 == p2: return
    if p1 > p2:
      p1,p2 = p2,p1
    self.par[p1] += self.par[p2]
    self.par[p2] = p1
 
  def same(self, x,y):
    return self.find(x) == self.find(y)

n = int(input())
coords = []
for i in range(n):
  x,y = map(int,input().split())
  coords.append((i,x,y))

edges = []

sorted_x = sorted(coords, key=lambda x: x[1])
for i in range(n-1):
  c = abs(sorted_x[i][1] - sorted_x[i+1][1])
  u,v = sorted_x[i][0], sorted_x[i+1][0]
  edges.append((c,u,v))

sorted_y = sorted(coords, key=lambda x: x[2])
for i in range(n-1):
  c = abs(sorted_y[i][2] - sorted_y[i+1][2])
  u,v = sorted_y[i][0], sorted_y[i+1][0]
  edges.append((c,u,v))

edges.sort()

uf = UF(n)
res = 0
for c,u,v in edges:
  if not uf.same(u,v):
    uf.union(u,v)
    res += c
 
print(res)

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

int main(){
  int a;
  string b[120];
    cin>>a;
  for(int i=0;i<a;i++){
  cin >>b[i];
  }
  int c ;
  cin >>c;
  string d[120];
  for(int i =0;i<c ;i++){
    cin >>d[i];
  }
  
  int e =0;
  for(int i =0;i<a;i++){
     int f = 0;
    for(int j=0;j<a;j++){
     
      if(b[i] == b[j]){
         f++;
      }
    }
    for(int j =0;j<c;j++){
       if(b[i] == d[j]){ 
         f--;
       }
    }
    
     e = max(f,e);
  }
  cout << e << endl;
  }
  


Measured memory_bytes: 256
def main(piece, c):
    for h in range(n-m+1):
        for w in range(n-m+1):
            if f(piece, h, w):
                break
    if c != 4:
        move(piece, c)
    else:
        if ans:
            print ans[0], ans[1]
        else:
            print 'NA'

def f(piece, h, w):
    global ans
    coordinate = None
    for _h in range(m):
        for _w in range(m):
            if piece[_h][_w] != '-1':
                if piece[_h][_w] == picture[h+_h][w+_w]:
                    if coordinate is None:
                        coordinate = (int(w+_w+1), int(h+_h+1))
                        if ans:
                            if coordinate[1] > ans[1]:
                                return
                            elif coordinate[1] == ans[1]:
                                if coordinate[0] > ans[0]:
                                    return
                else:
                    return
    else:
        ans = coordinate
        return True
    
def move(piece, c):
    _piece = []
    for w in range(m):
        lis = []
        for h in range(m):
            lis.append(piece[h][w])
        else:
            lis.reverse()
            _piece.append(lis)
    else:
        main(_piece, c+1)

while True:
    n, m = map(int, raw_input().split())
    if n == m == 0: break
    picture = [raw_input().split() for i in range(n)]
    piece = [raw_input().split() for i in range(m)]
    ans = None
    main(piece, 1)

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

const int N = 1e5 + 10, M = 2e5 + 30;
int n, m;
struct edge {
	int y, nxt, id;
}e[M << 1];
int lin[M], len;
int dis[N], pos[N];
bool vis[N];
set<int> c[N];

inline int read() {
	int s = 0, f = 1;
	char ch;
	for(; ch < '0' || ch > '9'; ch = getchar())	if(ch == '-')	f = -1;
	for(; ch >= '0' && ch <= '9'; ch = getchar())	s = (s << 1) + (s << 3) + ch - '0';
	return s * f;
}

inline void add(int xx, int yy, int vv) {
	e[++len] = (edge){yy, lin[xx], vv};
	lin[xx] = len;
}

inline void Dijkstra() {
	priority_queue< pair < int, int > > q;
	memset(dis, 0x3f, sizeof(dis));
	memset(vis, 0, sizeof(vis));
	dis[1] = 0;
	q.push(make_pair(0, 1));
	while(!q.empty()) {
		int x = q.top().second; q.pop();
		if(vis[x])	continue;
		vis[x] = 1;
		for(int i = lin[x]; i; i = e[i].nxt) {
			int y = e[i].y, v = c[x].count(e[i].id) ? 0 : 1;
			if(dis[y] > dis[x] + v) {
				dis[y] = dis[x] + v;
				q.push(make_pair(-dis[y], y));
				c[y].clear();
				c[y].insert(e[i].id);
			} else if(dis[y] == dis[x] + v)	c[y].insert(e[i].id);
		}
	}
}

int main() {
	n = read(), m = read(); 
	if(m == 0) { puts("-1"); return 0; }
	for(int i = 1; i <= m; ++i) {
		int xx = read(), yy = read(), vv = read();
		add(xx, yy, vv);
		add(yy, xx, vv);
	}
	Dijkstra();
	printf("%d\n", dis[n] == 0x3f3f3f3f ? -1 : dis[n]);
	return 0;
}

Measured memory_bytes: 20984
n, k = map(int, input().split())
a = list(map(int, input().split()))
dig=[0 for i in range(40)] # 10^12 < 2^40

for i in range(n) :
    temp = a[i] 
    for j in range(40) :
        if temp <= 0 :
            break
        if temp % 2 == 1 :
            dig[j] += 1
        temp = temp // 2

bin = 1 << 39 # 2^39
sum0 = 0
i = 39
# leading_zero of k
while(bin > k) :
    sum0 += bin * dig[i]
    bin //= 2
    i += -1

memo={}

def solve (k, bin, i) :
    if i < 0 :
        return 0, 0
    if (k,bin) in memo:
        return memo[(k,bin)]
    if k >= bin :  # this digit can be 1 or 0
        sum1, ans1 = solve(k-bin, bin//2, i-1)
        sum1 += bin * (n- dig[i]) 
        sum0, ans0 = solve(bin-1,bin//2, i-1)
        sum0 += bin * dig[i]
        if sum1 >= sum0 :
            sum = sum1
            ans = ans1 + bin
        else :
            sum = sum0
            ans = ans0
    else :         # this digit must be 0
        sum, ans = solve(k,bin//2, i-1)
        sum += bin * dig[i]
    memo[(k,bin)] = sum, ans
    return sum, ans

sum, ans = solve(k, bin, i)

print (sum+sum0)
#print(sum, sum0)
#print (ans)




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

struct StNode
{
  StNode* m_poParnt;
  StNode* m_poLeft;
  StNode* m_poRigt;
  int m_nKey;

  StNode(int nNo) :
    m_poParnt(nullptr), m_poLeft(nullptr), m_poRigt(nullptr), m_nKey(nNo)
  { }
};

void fnInsert(StNode*& rpoRoot, StNode* poNewNod)
{
  StNode* poParnt = nullptr;
  StNode* poNode = rpoRoot;

  while (poNode != nullptr)
  {
    poParnt = poNode;
    if (poNewNod->m_nKey < poNode->m_nKey)
      poNode = poNode->m_poLeft;
    else
      poNode = poNode->m_poRigt;
  }

  poNewNod->m_poParnt = poParnt;
  if (poParnt == nullptr)
    rpoRoot = poNewNod;
  else if (poNewNod->m_nKey < poParnt->m_nKey)
    poParnt->m_poLeft = poNewNod;
  else
    poParnt->m_poRigt = poNewNod;
}

StNode* fnFind(StNode* poRoot, int nNo)
{
  StNode* poNode = poRoot;
  while (poNode != nullptr)
    if (nNo == poNode->m_nKey)
      return poNode;
    else if (nNo < poNode->m_nKey)
      poNode = poNode->m_poLeft;
    else
      poNode = poNode->m_poRigt;

  return nullptr;
}

void fnInOrder(StNode* poNode)
{
  if (poNode == nullptr)  return;

  fnInOrder(poNode->m_poLeft);
  cout << " " << poNode->m_nKey;
  fnInOrder(poNode->m_poRigt);
}

void fnPreOrder(StNode* poNode)
{
  if (poNode == nullptr)  return;

  cout << " " << poNode->m_nKey;
  fnPreOrder(poNode->m_poLeft);
  fnPreOrder(poNode->m_poRigt);
}

void fnBinSchTree(StNode*& rpoRoot)
{
  int nMaxSiz;
  cin >> nMaxSiz;

  for (int i = 0; i < nMaxSiz; ++i)
  {
    string sCmd;
    cin >> sCmd;
    if (sCmd[0] == 'i')
    {
      int nNo;
      cin >> nNo;
      StNode* poNewNod = new StNode(nNo);
      fnInsert(rpoRoot, poNewNod);
    }
    if (sCmd[0] == 'f')
    {
      int nNo;
      cin >> nNo;
      if (fnFind(rpoRoot, nNo))
        cout << "yes" << endl;
      else
        cout << "no" << endl;
    }
    if (sCmd[0] == 'p')
    {
      fnInOrder(rpoRoot);
      cout << endl;
      fnPreOrder(rpoRoot);
      cout << endl;
    }
  }
}

void fnPstOrder(StNode* poNode)
{
  if (poNode == nullptr)  return;

  fnPstOrder(poNode->m_poLeft);
  fnPstOrder(poNode->m_poRigt);
  delete poNode;
}

int main()
{
  cin.tie(0);
  ios::sync_with_stdio(false);
  StNode* poRoot = nullptr;

  fnBinSchTree(poRoot);
//fnPstOrder(poRoot);
  return 0;
}

Measured memory_bytes: 21776
#include <bits/stdc++.h>
using namespace std;
typedef int64_t Int;
#define dump(x) cout << (x) << '\n'
Int mod = 998244353; // 1e9+7;

Int dp[301][90001];
Int dp2[301][90001];

int main() {
    Int n;
    cin >> n;
    vector<Int> a(n);
    Int sum = 0;
    for (Int i = 0; i < n; i++) {
        cin >> a[i];
        sum += a[i];
    }
    dp[0][0] = 1;
    for (Int i = 0; i < n; i++) {
        for (Int j = 0; j <= sum; j++) {
            dp[i + 1][j] += dp[i][j] * 2;
            dp[i + 1][j] %= mod;
            if (j + a[i] <= sum) {
                dp[i + 1][j + a[i]] += dp[i][j];
                dp[i + 1][j + a[i]] %= mod;
            }
        }
    }
    Int res = 1;
    for (Int i = 0; i < n; i++) res = (res * 3) % mod;
    Int sub = 0;
    Int s = sum / 2;
    if (sum % 2 == 1) s++;
    for (Int i = s; i <= sum; i++) sub = (sub + dp[n][i]) % mod;
    sub = (sub * 3) % mod;
    if (sum % 2 == 0) {
        dp2[0][0] = 1;
        for (Int i = 0; i < n; i++) {
            for (Int j = 0; j <= sum; j++) {
                dp2[i + 1][j] += dp2[i][j];
                dp2[i + 1][j] %= mod;
                if (j + a[i] <= sum) {
                    dp2[i + 1][j + a[i]] += dp2[i][j];
                    dp2[i + 1][j + a[i]] %= mod;
                }
            }
        }
        res = res + (dp2[n][sum / 2] * 3) % mod;
        res %= mod;
    }
    dump((res - sub + mod) % mod);
    return 0;
}

Measured memory_bytes: 422784
#include <algorithm>
#include <bitset>
#include <cctype>
#include <complex>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>

using namespace std;

inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}
template<class T> inline T sqr(T x) {return x*x;}

typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<string> vs;
typedef pair<int, int> pii;
typedef long long ll;

#define all(a)  (a).begin(),(a).end()
#define rall(a) (a).rbegin(), (a).rend()
#define pb push_back
#define mp make_pair
#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 range(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n)  range(i,0,n)
#define clr(a,b) memset((a), (b) ,sizeof(a))
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

const double eps = 1e-10;
const double pi  = acos(-1.0);
const ll INF =1LL << 62;
const int inf =1 << 29;

struct Sphere{
    double x;
    double y;
    double z;
    double r;
};

int n;
vector< vector<double> > costs;

int main(void){
    double res;
    for(; cin >> n, n; printf("%.3f\n", res)){
        res = 0.;
        vector<Sphere> spheres(n);
        rep(i, n) cin >> spheres[i].x >> spheres[i].y >> spheres[i].z >> spheres[i].r;

        costs = vector< vector<double> >(n, vector<double>(n));
        rep(u, n){
            range(v, u, n){
                double d = sqrt(sqr(spheres[u].x - spheres[v].x) 
                              + sqr(spheres[u].y - spheres[v].y) 
                              + sqr(spheres[u].z - spheres[v].z));
                costs[u][v] = costs[v][u] = max(0., d - (spheres[u].r + spheres[v].r));
            }
        }

        vector<double> minCost(n, inf);
        vi used(n);

        minCost[0] = 0;
        while(1){
            int v = -1;
            rep(u, n){
                if(!used[u] && (v == -1 || minCost[u] < minCost[v])) v = u;
            }
            if(v == -1) break;

            used[v] = true;
            res += minCost[v];

            rep(u, n){
                minCost[u] = min(minCost[u], costs[v][u]);
            }
        }
    }

	return 0;
}

Measured memory_bytes: 1428
#include <iostream>
#include <vector>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <algorithm>
#include <iomanip>
#include <numeric>
#include <queue>
#include <cmath>
using namespace std;

int main() {        
    const int mod = 1e9 + 7;
    int n;
    cin >> n;
    string s1, s2;
    cin >> s1 >> s2;
    int last = 0;
    long long int res = 0;
    int index = 0;
    if (s1[0] == s2[0]) {
        last = 1;
        res = 3;
        index = 1;
    } else {
        last = 2;
        res = 6;
        index = 2;
    }
    while (index < n) {
        if (s1[index] == s2[index]) {
            if (last == 1) {
                res *= 2;
            } else {
                res *= 1;
            }
            last = 1;
            index++;
        } else {
            if (last == 1) {
                res *= 2;
            } else {
                res *= 3;
            }
            last = 2;
            index += 2;
        }
        res %= mod;
    }
    cout << res << endl;
}


Measured memory_bytes: 3628
#include<bits/stdc++.h>
#define rep(i,a,b) for(int i=(a);i<=(b);i++)
#define per(i,a,b) for(int i=(a);i>=(b);i--)
#define forE(i,x) for(int i=head[x];i!=-1;i=ne[i])
using namespace std;
typedef long long i64;
typedef unsigned long long u64;
typedef unsigned u32;
typedef pair<int,int> pin;
#define mk(a,b) make_pair(a,b)
#define lowbit(x) ((x)&(-(x)))
#define sqr(a) ((a)*(a))
#define clr(a) (memset((a),0,sizeof(a)))
#define ls(x) ((x)<<1)
#define rs(x) (((x)<<1)|1)
#define mid (((l)+(r))>>1)
#define pb push_back
#define w1 first
#define w2 second
inline void read(int &x){
	x=0;int f=1;char ch=getchar();
	while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
	while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();}
	x*=f;
}
inline void judge(){
	freopen("in.txt","r",stdin);
	freopen("out.txt","w",stdout);
}
/*******************************head*******************************/
const int maxn=200005;
int n,m;
pin a[maxn];
namespace seg{
	int mx[maxn<<3],tag[maxn<<3],l[maxn<<3],r[maxn<<3];
	inline void update(int x){
		mx[x]=max(mx[ls(x)],mx[rs(x)]);
	}
	inline void addtag(int x,int v){
		mx[x]+=v;tag[x]+=v;
	}
	inline void build(int x,int lq,int rq){
		l[x]=lq;r[x]=rq;tag[x]=0;
		if(lq==rq){
			mx[x]=lq;
			return;
		}int md=(lq+rq)>>1;
		build(ls(x),lq,md);
		build(rs(x),md+1,rq);
		update(x);
	}
	inline void pushdown(int x){
		if(tag[x]){
			addtag(ls(x),tag[x]);
			addtag(rs(x),tag[x]);
			tag[x]=0;
		}
	}
	inline void add(int x,int lq,int rq){
		if(lq<=l[x]&&r[x]<=rq){
			addtag(x,1);return;
		}int md=(l[x]+r[x])>>1;
		pushdown(x);
		if(lq<=md)add(ls(x),lq,rq);
		if(rq> md)add(rs(x),lq,rq);
		update(x);
	}
	inline int query(int x,int lq,int rq){
		if(lq<=l[x]&&r[x]<=rq)return mx[x];
		int md=(l[x]+r[x])>>1;pushdown(x);
		int res=-1e9;
		if(lq<=md)res=max(res,query(ls(x),lq,rq));
		if(rq> md)res=max(res,query(rs(x),lq,rq));
		update(x);
		return res;
	}
}
inline bool cmp(pin a,pin b){
	return a.w1<b.w1||(a.w1==b.w1&&a.w2>b.w2);
}
int main(){
	read(n);read(m);
	rep(i,1,n)read(a[i].w1),read(a[i].w2);
	sort(a+1,a+1+n,cmp);
	int res=max(n-m,0);
	seg::build(1,0,m+1);
	rep(i,1,n){
		seg::add(1,1,a[i].w2);
		if(a[i].w1<=m)res=max(res,seg::query(1,a[i].w1+1,m+1)-a[i].w1-(m+1));
	}
	printf("%d\n",res);
	return 0;
}


Measured memory_bytes: 18176
#include "bits/stdc++.h"

using namespace std;

void solve()
{
	int N, H;
	cin >> N >> H;
	vector<pair<int, int>> as(N), bs(N);
	vector<int> mp(N);
	for (int i = 0; i < N; i++)
	{
		cin >> as[i].first >> bs[i].first;
		as[i].second = i;
		bs[i].second = i;
		mp[i] = bs[i].first;
	}
	sort(as.rbegin(), as.rend());
	sort(bs.rbegin(), bs.rend());
	int a = as[0].first, i = as[0].second, ans = 1, H2 = H;
	H -= mp[i];
	for (auto p : bs)
	{
		if (p.second == i) continue;
		if (H <= 0 || a >= p.first) break;
		H -= p.first;
		ans++;
	}
	if (H > 0) ans += (H + a - 1) / a;
	int ans2 = 0;
	for (auto p : bs)
	{
		if (H2 <= 0) break;
		H2 -= p.first;
		ans2++;
	}
	if (H2 <= 0) ans = min(ans, ans2);
	cout << ans << endl;
}

int main(void)
{
	solve();
	//cout << "yui(*-v・)yui" << endl;
	return 0;
}


Measured memory_bytes: 2176
#include<iostream>
#include<algorithm>
#include<vector>
#include<string>
#include<utility>
#include<map>
#include<set>
#include<queue>
#include<math.h>
using namespace std;
#define mod (1000000000+7)
#define N (10007)
#define INF 1e16
typedef long long ll;
typedef pair<ll,ll> P;
 

int main(void){
    int a,b,c;
    cin>>a>>b>>c;
    if(a+b+c>=22)cout<<"bust"<<endl;
    else cout<<"win"<<endl;
    return 0;
}

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

int main(){ 
  int a,b,n,x=0,y=0,ans=100000,c=0;
  cin>>a>>b;
  if(a>0&&b>0) co("Positive");
  else if(a<=0 && b>0) co("Zero");
  else if(a==0||b==0) co("Zero");
  else if(a<0&&b<0){
    if((b-a)%2==0) co("Negative");
    else co("Positive");
  }
  return 0;
}

Measured memory_bytes: 256
#include<cstdio>
long long a[200010],ans;
long long Abs(long long x)
{
	if (x>=0) return x;
	return -x;
}
int main()
{
	int n;
	scanf("%d",&n);
	for (int i=1;i<=n;i++)
	{
		scanf("%lld",&a[i]);
		a[i]+=a[i-1];
	}
	ans=Abs(a[n]-a[1]-a[1]);
	for (int i=1;i<n;i++)
	if (Abs(a[n]-a[i]-a[i])<ans)
		ans=Abs(a[n]-a[i]-a[i]);
	printf("%lld",ans);
	return 0;
} 

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

using namespace std;
using llong = long long;
using ldbl = long double;
using P = pair<llong, llong>;

#define ALL(x) x.begin(), x.end()

const llong inf = 1100100100100100ll;
const llong mod = 1e9+7;

llong N;
vector<vector<llong> > edges;

P dfs(int start) {
	queue<P> q;
	vector<bool> use(N, false);
	P lst;

	q.push(P(start, 1));
	while(q.size()) {
		P now = q.front();
		q.pop();

		lst = now;
		for (auto edge : edges[now.first]) {
			if (use[edge]) continue;
			use[edge] = true;
			P next(edge, now.second+1);
			q.push(next);
		}
	}

	return lst;
}

int main(){

	cin >> N;
	edges.resize(N);
	llong a, b;
	for (int i = 0; i < N-1; i++) {
		cin >> a >> b;
		a--, b--;
		edges[a].push_back(b);
		edges[b].push_back(a);
	}

	P n = dfs(0);
	n = dfs(n.first);
	if (n.second%3 == 2)
		cout << "Second" << endl;
	else
		cout << "First" << endl;

	return 0;
}

/*

ある頂点をrootとしてすべての枝を1短くする操作
逆操作；枝を1張る

*/

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

int main() {
  char c;
  cin >> c;
  char vowel[5] = {'a', 'i', 'u', 'e', 'o'};

  for (int i=0; i < 5; i++) {
      if (c == vowel[i]) {
          cout << "vowel" << endl;
          return 0;
      }
  }
  cout << "consonant" << endl;
  return 0;
}


Measured memory_bytes: 3632
#include<iostream>
#include<iomanip>
//#include<cstdio>
#include<vector>
#include<map>
#include<queue>
#include<algorithm>
#include<cmath>
#include<cassert>
using namespace std;
typedef long long ll;
const int Nmax = 1e5;
int N, K;
ll H[Nmax];

int main(){
	cin >> N >> K;
	for(int i=0; i<N; i++) cin >> H[i];

	sort(H, H+N);

	ll ans = H[K-1]-H[0];
	for(int i=0; i<=N-K; i++) ans = min(ans, H[i+K-1]-H[i]);
	cout << ans << endl;

	return 0;
}


Measured memory_bytes: 1024
#include <iostream>
using namespace std;
 
int a[100];
 
int main()
{
	int n;
	cin >> n;
	for (int i = 0; i < n; ++i)
	{
		cin >> a[i];
	}
	int najmanji = a[0];
	for (int i = 0; i < n; ++i)
	{
		if (a[i] < najmanji)
			najmanji = a[i];
	}
	int najveci = a[0];
	for (int i = 0; i < n; ++i)
	{
		if (a[i] > najveci)
			najveci = a[i];
	}
	cout << najveci - najmanji;
}

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


int main()
{
  int n;
  cin>>n;
  
  string s;
  cin>>s;
  
  bool flag=false;
  if(n%2!=0)
    cout<<"No"<<endl;
  else if(n==2){
    if(s.at(0)==s.at(1))
      cout<<"Yes"<<endl;
    else
      cout<<"No"<<endl;
  }  
  else{
    for(int i=0;i<n/2-1;i++){
      if(s.at(i)==s.at(i+n/2)){
        flag=true;
      }
      else{
        flag=false;
        break;
      }
    }
  
  if(flag)
    cout<<"Yes"<<endl;
  else
    cout<<"No"<<endl;
  }
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll long long
using namespace std;
const int N = 200010, Mod = 998244353;
int f[N]; char st[N];
int main() {
	ios::sync_with_stdio(false);
	int n; cin >> n >> st;
	for (int i = 1; i <= n; i += 2) {
		if (n % i != 0) continue;
		int m = n / i, fl = 1;
		for (int j = 0; j < m; j++) f[i] = (2ll * f[i] % Mod + st[j] - '0') % Mod;
		for (int j = m; j < n; j++)
			if (st[j] != (st[j % m] ^ (j / m & 1))) {fl = st[j] > (st[j % m] ^ (j / m & 1)); break;}
		(f[i] += fl) %= Mod;
	}
	int ans = 0;
	for (int i = n; i; i--) {
		for (int j = i + i; j <= n; j += i)
			(f[i] += Mod - f[j]) %= Mod;
		(ans += 2ll * f[i] % Mod * (n / i) % Mod) %= Mod;
	}
	cout << ans << '\n';
	return 0;
}

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

vector<int> adj[100000];
int n, m, a, b, dist[100000], par[100000];
bool proc[100000];

void solve() {
	cin >> n >> m;
	for (int i = 0; i < m; i++) {
		cin >> a >> b;
		adj[a - 1].push_back(b - 1);
		adj[b - 1].push_back(a - 1);
	}
	fill(dist, dist + 100000, 1e9);
	fill(proc, proc + 100000, 0);
	priority_queue<pair<int, int>> q;
	q.push({0, 0});
	dist[0] = 0;
	while (!q.empty()) {
		int cur = q.top().second;
		q.pop();
		if (proc[cur]) continue;
		proc[cur] = 1;
		for (int nbr : adj[cur]) {
			if (dist[cur] + 1 < dist[nbr]) {
				dist[nbr] = dist[cur] + 1;
				par[nbr] = cur;
				q.push({-dist[nbr], nbr});
			}
		}
	}
	cout << "Yes\n";
	for (int i = 1; i < n; i++) {
		cout << par[i] + 1 << "\n";
	}
}

int main() {
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	solve();
	return 0;
}

Measured memory_bytes: 11168
import java.util.Scanner;
public class Main {
	public static void main(String[] args) {
		ABC054DSolve solve = new ABC054DSolve();
		solve.main();
	}
}

class ABC054DSolve {
	
	int N;
	int Ma;
	int Mb;
	Drug[] drugs;
	
	int maxA = 0;
	int maxB = 0;
	int[][][] dp;
	
	int INF = Integer.MAX_VALUE / 2;
	
	ABC054DSolve() {
		Scanner cin = new Scanner(System.in);
		this.N = cin.nextInt();
		this.Ma = cin.nextInt();
		this.Mb = cin.nextInt();
		this.drugs = new Drug[N];
		
		for (int i = 0; i < N; i++) {
			int a = cin.nextInt();
			int b = cin.nextInt();
			int cost = cin.nextInt();
			drugs[i] = new Drug(a, b, cost);
			
			maxA += a;
			maxB += b;
		}
	}
	
	void main() {
		
		// initialize dp
		this.dp = new int[N][maxA + 1][maxB + 1];
		for (int k = 0; k < N; k++) {
			for (int i = 0; i <= maxA; i++) {
				for (int j = 0; j <= maxB; j++) {
					dp[k][i][j] = INF;
				}
			}
		}
		dp[0][0][0] = 0;
		dp[0][drugs[0].a][drugs[0].b] = drugs[0].cost;
		
		// solve recurrence relation
		for (int i = 0; i < N; i++) {
			for (int x = 0; x <= maxA; x++) {
				for (int y = 0; y <= maxB; y++) {
					if (i - 1 >= 0) {
						dp[i][x][y] = dp[i - 1][x][y];
						if (x - drugs[i].a >= 0 && y - drugs[i].b >= 0) {
							dp[i][x][y] = Math.min(dp[i][x][y], dp[i - 1][x - drugs[i].a][y - drugs[i].b] + drugs[i].cost);
						}
					}
				}
			}
		}
		
		
		int minCost = Integer.MAX_VALUE / 2;
		for (int i = 1; i <= maxA; i++) {
			for (int j = 1; j <= maxB; j++) {				
				if (i*Mb == j*Ma) {
					minCost = Math.min(minCost, dp[N - 1][i][j]);
				}
			}
		}
		System.out.println(minCost != INF ? minCost : -1);	
	}
	
	class Drug {
		int a;
		int b;
		int cost;
		
		Drug(int a, int b, int cost) {
			this.a = a;
			this.b = b;
			this.cost = cost;
		}
	}
	
}


Measured memory_bytes: 21028
#include <bits/stdc++.h>
using namespace std;
long long a[100010],b[100010],n,tot;
int main(){
    cin>>n;
    for(int i=1;i<=n+1;i++){
    	cin>>a[i];
	}
	for(int i=1;i<=n;i++){
		cin>>b[i];
		if(b[i]<a[i]) tot+=b[i];
		else if(b[i]>=a[i]&&b[i]<a[i]+a[i+1]) {
			tot+=b[i];
			a[i+1]=a[i+1]+a[i]-b[i];
		}
		else {
			tot+=a[i]+a[i+1];
			a[i+1]=0;
		}
	}
    cout<<tot;
    return 0;
}

Measured memory_bytes: 1920
import math
from itertools import permutations
n = int(input())
xy = [list(map(int, input().split())) for i in range(n)]
ans = 0
for i in permutations(list(range(n))):
    for j in range(n-1):
        ans += math.sqrt((xy[i[j]][0]-xy[i[j+1]][0])**2+(xy[i[j]][1]-xy[i[j+1]][1])**2)
print(ans/(math.factorial(n)))

Measured memory_bytes: 9108
#include <iostream>
#include <stack>
#include <algorithm>
#include <vector>
#include <math.h>
#include <stdio.h>
#include <functional>
#include <string>
#include <cstdlib>
#include <numeric>
#include <cstdbool>
#include <cstring>
#include <map> 
#include <set>
#include <queue>
#include <iomanip>
#include <sstream>
typedef long long ll;

#define rep(i,n) for(ll i=0;i<n;i++)
using namespace std;

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

const long long INF = 1000000000000000;
const ll inf = -1e18;
typedef pair<ll, ll> P;
ll ma = 1000000000 + 7;
ll mx = 1000003;
ll h,n, w,m,t; string s;
ll R, C;
ll sy, sx, gy, gx;
char maze[510][510];
ll dis[20][20];
int dx[4] = { 1, 0, -1, 0 };
int dy[4] = { 0, 1, 0, -1 };
ll gcd(ll x, ll y) {
	if (x % y == 0) return y;
	return gcd(y, x % y);
}
ll lcm(ll a,ll b) {
	ll g = gcd(a, b);
	return a / g * b;
}
void comb(vector<vector <ll> >& v) {
	for (ll i = 0; i < v.size(); i++) {
		v[i][0] = 1;
		v[i][i] = 1;
	}
	for (ll k = 1; k < v.size(); k++) {
		for (int j = 1; j < k; j++) {
			v[k][j] = (v[k - 1][j - 1] + v[k - 1][j])%ma;
		}
	}
}

ll GetDigit(ll num) {
	return log10(num) + 1;
}
ll Combination(int n, int r)
{
	if (n - r < r) r = n - r;
	if (r == 0) return 1;
	if (r == 1) return n;

	vector<ll> numerator(r);
	vector<ll> denominator(r);

	for (int k = 0; k < r; k++)
	{
		numerator[k] = n - r + k + 1;
		denominator[k] = k + 1;
	}

	for (int p = 2; p <= r; p++)
	{
		int pivot = denominator[p - 1];
		if (pivot > 1)
		{
			int offset = (n - r) % p;
			for (int k = p - 1; k < r; k += p)
			{
				numerator[k - offset] /= pivot;
				denominator[k] /= pivot;
			}
		}
	}

	ll result = 1;
	for (int k = 0; k < r; k++)
	{
		if (numerator[k] > 1) result *= numerator[k];
		result %= ma;
	}

	return result;
}
/*
ll bfs() {
	queue<P> que;
	for (int i = 0; i < R; i++) {
		for (int j = 0; j < C; j++) dis[i][j] = INF;
	}
	que.push(P(sy - 1, sx - 1));
	dis[sy - 1][sx - 1] = 0;

	while (que.size() > 0) {
		P p = que.front();
		que.pop();
		if (p.first == gy - 1 && p.second == gx - 1) break;
		for (ll i = 0; i < 4; i++) {
			ll ny = p.first + dy[i];
			ll nx = p.second + dx[i];
			if (0 <= ny && ny < R && 0 <= nx && nx < C && maze[ny][nx] == '.' && dis[ny][nx] == INF) {
				que.push(P(ny, nx));
				dis[ny][nx] = dis[p.first][p.second] + 1;
			}
		}
	}
	return dis[gy - 1][gx - 1];
}*/
int main() {
	char ch[3][3];
	rep(i, 3) {
		rep(j, 3) {
			cin >> ch[i][j];
		}
	}
	cout << ch[0][0] << ch[1][1] << ch[2][2] << endl;
}


Measured memory_bytes: 256