akhauriyash/Code-Regression huggingface dataset:
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rrep(i, n) for (int i = 1; i < (int)(n); i++) 
#define dunk(n) cout << n << endl
#define all(a) (a).begin(),(a).end()
typedef pair<int,int> P;
typedef long long ll;

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

    /*
    int array[n];
    rep(i,n){
        array[i] = i+1;
    }
    */

    int p[n],q[n];
    rep(i,n) cin >> p[i];
    rep(i,n) cin >> q[i];

    /*
    rep(i,n){
        if(p[i] > q[i]){
            rep(j,n){
                swap(p[j],q[j]);
            }
            break;
        }
    }
    */

    int a = 0, b = 0;
    do{
        a++;
    }while(next_permutation(p,p+n));

    do{
        b++;
    }while(next_permutation(q,q+n));

    int ans = abs(b-a);

    dunk(ans);
    return 0;
}

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

#define ll long long int
#define mp make_pair
#define ff first
#define ss second
#define fr(i,l,r) for (long long int i = l; i < r; ++i)
#define frr(i,l,r) for (long long int i = r; i >= l; --i) 
#define sortarr sort(arr,arr+n) //sorts array in asc order
#define sortarr_r sort(arr, arr+n, greater<long long int>()) //sorts array in desc order
#define make_set set<long long int>s //Set arranges in asc order
#define make_set_r set<long long int, greater <long long int>>s ////Set arranges in desc order
#define make_vector vector<long long int>v; 
#define pb push_back


// string size = str.size()

// stack <int> s; 
// queue <int> gquiz; 
// __gcd(m, n) 

// ll arr[10e5 + 5];
// char arr[10e5 + 5];

// printf ("%.9f\n",x);

bool compare(string &s1,string &s2) 
{ 
    return s1.size() < s2.size(); 
} 
void yes()
{
    cout << "YES" << endl;
}
void no()
{
    cout << "NO" << endl;
}


int main(void)
{
    // ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    ll n,k;
    cin >> n >>k;
    if(n < k)
    {
        if(abs(n-k) < n)
            cout << abs(n-k) << endl;
        else
        {
            cout << n << endl;
        }
        
    }
    else
    {
        ll rem = n%k;
        if(rem < abs(rem-k))
        {
            cout << rem << endl;
        }
        else
        {
            cout << abs(rem-k) << endl;
        }
    }
    return 0;
}   

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <utility>
#include <queue>
#include <string>
#include <set>
#include <bitset>
#include <unordered_map>

using namespace std;
using ll = long long;
using Pii = pair<int, int>;
using Pll = pair<ll, ll>;
template <class T>
using Vvec = vector<vector<T> >;

int main()
{
    int N, Q;
    cin >> N;
    string S;
    cin >> S >> Q;
    vector<int> k(Q);
    for(int i=0; i<Q; i++) cin >> k[i];

    vector<ll> M(N);
    M[0] = (S[0]=='M') ? 1 : 0;
    for(int i=1; i<N; i++){
        M[i] = M[i-1];
        if(S[i]=='M') M[i]++;
    }

    for(int q=0; q<Q; q++){
        ll dp = 0;
        ll cd = (S[0]=='D') ? 1 : 0;
        ll sm = 0;
        for(int i=1; i<N; i++){
            if(i-k[q]>=0 && S[i-k[q]]=='D'){
                sm -= M[i-k[q]]; cd--;
            }
            if(S[i]=='D'){
                sm += M[i]; cd++;
            }
            if(S[i]=='C') dp += cd*M[i] - sm;
        }
        cout << dp << endl;
    }
}

Measured memory_bytes: 9220
import sys

N=int(input())
amat=[[-1]]
for i in range(N):
  alist=list(map(int,input().split()))
  amat.append(list(reversed(alist)))
  
#print(amat)
cleared_num=0
new_search_index=set(range(1,N+1))
for answer in range(1,N**3):
  matched_set=set()
  unchanged=True

  search_index=new_search_index;
  new_search_index=set()
  for i in search_index:
    if i in matched_set:
      continue
      
    ai_next = amat[i][-1]
    if amat[ai_next][-1]==i and not ai_next in matched_set:
      #print(i,ai_next,answer)
      matched_set.add(amat[i].pop())
      matched_set.add(amat[ai_next].pop())
      if len(amat[i])==0:
        cleared_num+=1
      else:
        new_search_index.add(i)  
      if len(amat[ai_next])==0:
        cleared_num+=1
      else:
        new_search_index.add(ai_next)
      unchanged=False
      
  if unchanged:
    print(-1)
    sys.exit()
  elif cleared_num==N:
    print(answer)
    sys.exit()

Measured memory_bytes: 36564
import sys
 
stdin = sys.stdin
 
ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
ns = lambda: stdin.readline()
 
abcd = ns()
a = int(abcd[0])
b = int(abcd[1])
c = int(abcd[2])
d = int(abcd[3])

l = [
  [1, 1, 1],
  [-1, 1, 1],
  [1, -1, 1],
  [1, 1, -1],
  [-1, -1, 1],
  [-1, 1, -1],
  [1, -1, -1],
  [-1, -1, -1],
]

counter = 0
for i in range(8):
  if a + l[i][0] * b + l[i][1] * c + l[i][2] * d == 7:
    break
  counter += 1

out = []
out.append(str(a))
if l[counter][0] == 1:
  out.append('+')
else:
  out.append('-')
out.append(str(b))
if l[counter][1] == 1:
  out.append('+')
else:
  out.append('-')
out.append(str(c))
if l[counter][2] == 1:
  out.append('+')
else:
  out.append('-')
out.append(str(d))
out.append('=7')
print(''.join(out))

Measured memory_bytes: 3188
package main

import "fmt"

func main() {
	var s string
	var first, last int
	fmt.Scan(&s)
	for i := 0; i < len(s); i++ {
		if s[i] == 'A' {
			first = i
			break
		}
	}
	for i := len(s) - 1; i > 0; i-- {
		if s[i] == 'Z' {
			last = i
			break
		}
	}
	fmt.Println(last - first + 1)
}

Measured memory_bytes: 1920
#include <vector>
#include <algorithm>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <iostream>
#include <cstdio>
#include <cmath>
#include <cstring>
//#include <chrono> //1e+9で割る auto end= chrono::system_clock::now()-st;  cout<<end.count()%1e+9<<endl;
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
typedef pair<ll,ll> LP;
typedef long double db;

#define fr first
#define sc second
#define pb push_back
#define rep(i,x) for(int i=0;i<x;i++)
#define rep1(i,x) for(int i=1;i<=x;i++)
#define rrep(i,x) for(int i=x-1;i>=0;i--)
#define rrep1(i,x) for(int i=x;i>0;i--)

ll N,K;
ll ans;
ll x;
int main()
{
	cin>>N>>K;
	if(K==0){
		ans=N*N;
	}
	else{
		ans=N*N;
		ll a=0,r=0;
		rep1(m,N){
			r=0;
			x=min((ll)(m-1),K-1); //N以下で mでわった あまり x以下
			if(x==0){
				r=N/m;
			}
			else{
				r+=(N/m)*(x+1);
				r+=min(N%m,x);
			}
			a+=r;
		}
		ans-=a;
		
	}
	cout<<ans<<endl;
}

Measured memory_bytes: 256
#include <iostream>
#include<stdio.h>
#include<cmath>
#include<vector>
#include<map>
#include<sstream>
#include<deque>
#include<iomanip>
#include<algorithm>
#include<set>
#include<queue>
#include<bitset>
#include<stack>
#include<unordered_set>
#include<cstring>
#include<list>
using namespace std;
int dx[] = { -1,0,0,1 };
int dy[] = { 0,1,-1 ,0 };
#define endl '\n'
#define mod 1000000007
const long double P = 3.141592653589793238L;
void GAME_OVER()
{
	ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
	//freopen("input.in", "r", stdin);
	//freopen("ouput.txt", "w", stdout);

}
long long gcd(long long x, long long y)
{
	if (x == 0)
		return y;
	return gcd(y%x, x);
}
long long fast_power(long long x, long long y)
{
	long long p = 1;
	while (y)
	{
		if (y & 1)
			p = (p*x) % mod;
		y = (y >> 1); //y/=2
		x = (x*x) % mod;
	}

	return p;
}


long long com(long long n, long long r) {
	long long p = 1, p1 = 1;
	for (long long i = r + 1; i <= n; i++) {
		p = (p * i);
		p /= p1;
		p1++;
	}
	return p;
}
int n; long long k,mp[101][100000]; pair<long long, long long>p[100001];
long long dp(int x, long long k) {
	if (x == n)
		return 0;
	if (mp[x][k] != -1)
		return mp[x][k];
	long long l = dp(x + 1, k);
	if (p[x].first<=k) {
		l=max(l, p[x].second+dp(x + 1, k - p[x].first));
	}
	return mp[x][k] = l;

}
int main()
{
	GAME_OVER();
	memset(mp, -1, sizeof mp);
	cin >> n >> k;
	for (int i = 0; i < n; i++) {
		long long a, b;
		cin >> a >> b;
		p[i] = { a,b };
	}
	cout << dp(0, k) << endl;
	//system("pause");
	return 0;

}



Measured memory_bytes: 82572
main = do
  li <- getLine
  let k = read li
  li <- getLine
  let [a,b] = map read $ words li
  let ans = compute k a b
  putStrLn $ if ans then "OK" else "NG"

compute :: Int -> Int -> Int -> Bool
compute k a b = a1 <= b
  where
    a1 = (a + k - 1) `div` k * k


Measured memory_bytes: 3788
word = input()

ATCG =['A', 'T', 'C', 'G']
count = 0
countlist = []

for x in word:
    if x in ATCG:
        count+=1
    elif count!=0:
        countlist.append(count)
        count = 0

countlist.append(count)
print (max(countlist))


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

int num[100000];

int main() {
	while(1){
		int n, k;
		cin >> n >> k;
		if(n == 0 && k == 0)break;
		
		int sum = 0;
		for(int i = 0; i < k; i++){
			cin >> num[i];
			sum += num[i];
		}
			
		int ans = 0;
		for(int i = k; i < n; i++){
			cin >> num[i];
			sum -= num[i - k];
			sum += num[i];
			if(ans < sum)
				ans = sum;
		}
		
		cout << ans << endl;
	}
	return 0;
}

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

int main()
{
	int n; cin >> n;	
	double sum = 0;
	for (int i = 0; i < n; i++) {
		double tmp_a; cin >> tmp_a;
		sum += 1 / tmp_a;
	}
	cout << fixed << setprecision(11) << 1 / sum << endl;
	return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
int main(){
    int a[4];
    int i=0;
    int A;
    scanf("%d",&A);
    a[0]=A/1000;
    a[1]=(A-a[0]*1000)/100;
    a[2]=(A-a[0]*1000-a[1]*100)/10;
    a[3]=(A-a[0]*1000-a[1]*100-a[2]*10);
    while(1){
        if(a[i]==a[i+1]){
            printf("Bad\n");
            break;
        }
        else if(i==2){
            printf("Good\n");
            break;
        }
        i++;
    }

    return 0;
}

Measured memory_bytes: 128
#include <iostream>
#include <string>
#include <vector>
#include <deque>
#include <queue>
#include <algorithm>
#include <set>
#include <map>
#define vv(a, b, c, d) vector<vector<d> >(a, vector<d>(b, c))
#define vvi std::vector<std::vector<int> >
#define vvl std::vector<std::vector<ll> >
#define MODs 1000000007;
typedef long long int ll;
using namespace std;

////////////////////////////////
#define P 1000000007
#define N_MAX 2000000
typedef long long int ll;
ll fac[N_MAX+1];
ll inv[N_MAX+1];
ll finv[N_MAX+1];

ll comb(ll n, ll k){return (((fac[n]*finv[n-k])%P)*finv[k])%P;}
void init(){
    fac[0] = finv[0] = fac[1] = finv[1] = inv[1] = 1;
    for(int i = 2; i <= N_MAX; i++){
        fac[i] = (fac[i-1]*i)%P;
        inv[i] = ((-(P/i)*inv[P%i])%P+P)%P;
        finv[i] = (finv[i-1]*inv[i])%P;
    }
}
ll pp(ll a, ll b){return (a * b)%P;}
ll pd(ll a, ll b){return (a*inv[b])%P;}
//////////////////////////////////////
int main(int argc, char const *argv[]) {
  ll N, A, B, C, ans = 0;
  std::cin >> N >> A >> B >> C;
  std::vector<ll> Ap(N+1), Bp(N+1);
  init();
  A = pp(A, pd(100,100-C));
  B = pp(B, pd(100,100-C));
  Ap[0] = Bp[0] = 1;
  Ap[1] = pd(A, 100), Bp[1] = pd(B, 100);
  for(int i=2;i<=N;i++) Ap[i]=pp(Ap[i-1],pd(A,100)),Bp[i]=pp(Bp[i-1],pd(B,100));
  for(int i=N;i<2*N;i++){
    ans = (ans + pp(pp(pd(100,100-C), i), pp(comb(i-1, N-1),((pp(Ap[N],Bp[i-N])+pp(Ap[i-N], Bp[N]))%P))))%P;
  }
  std::cout << ans << '\n';
  return 0;
}


Measured memory_bytes: 48640
#include <bits/stdc++.h>
#define ll long long

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

	int a,b,c;
	cin>>a>>b>>c;

	if((a==b && b==c) || (a!=b && b!=c && a!=c))
        cout<<"No";
    else
        cout<<"Yes";
	return 0;
}


Measured memory_bytes: 256
def get_row_sum(l):
    sums = 0
    for num in l:
        sums += num
    return sums

num_rows, num_columns = map(int, input().split())

result_table = list()
sum_row = [0 for _ in range(num_columns+1)]

for i in range(num_rows):
    row = list(map(int, input().split()))
    row_sum = get_row_sum(row)
    row.append(row_sum)
    result_table.append(row)
    
    for i in range(len(row)):
        sum_row[i] += row[i]

result_table.append(sum_row)

for r in result_table:
    for i, num in enumerate(r):
        print(num, end='')
        if i != num_columns:
            print(end=' ')
    print()


Measured memory_bytes: 6492
#include <bits/stdc++.h>
#define FOR(i,a,b) for (int i = (a); i < (b); ++i)
#define RFOR(i,a,b) for (int i = (b)-1; i >= (a); --i)
#define rep(i,n) FOR(i,0,(n))
#define REPS(i,n) FOR(i,1,(n)+1)
#define RREP(i,n) RFOR(i,0,(n))
#define ALL(x) (x).begin(),(x).end()
#define RALL(x) (x).rbegin(),(x).rend()
#define DEBUG(x)  cout << #x << " = " << (x) << endl;
#define SORT(x) sort(ALL(x));
#define RSORT(x) sort(RALL(x));
#define SUM(x) accumulate(ALL(x),0);
#define fi first
#define se second
#define pb push_back
#define eb emplace_back
#define sz(x) (int)(x).size()
#define bn(x) ((1<<x)-1)
#define dup(x,y) (((x)+(y)-1)/(y))
using namespace std;
using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vll = vector<ll>;
using pii = pair<int, int>;
using tiii = tuple<int, int, int>;
const ll mod = 1e9+7;
const int INF = (1<<30)-1;
const ll INFLL = (1LL<<62)-1;
const int dx[4] = {1,0,-1,0};
const int dy[4] = {0,1,0,-1};
//cout << fixed << setprecision(10);

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

template<class T> inline int sgn(T n) { if (n > 0) return 1; else if (n < 0) return -1; else return 0; }

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 n;
  cin >> n;
  vector<ll> a(n);
  rep(i,n) cin >> a[i];

  ll ans = INFLL;

  ll s = 0;
  ll cnt = 0;
  rep(i,n) {
    // i%2==0 -> +, i%2!=0 -> -
    s += a[i];
    if (i%2==0 && s<=0) {
      cnt += -s+1;
      s += -s+1;
    }
    else if (i%2!=0 && s>=0) {
      cnt += s+1;
      s -= s+1;
    }
  }
  ans = min(ans,cnt);

  s = 0;
  cnt = 0;
  rep(i,n) {
    // i%2==0 -> -, i%2!=0 -> +
    s += a[i];
    if (i%2==0 && s>=0) {
      cnt += s+1;
      s -= s+1;
    }
    else if (i%2!=0 && s<=0) {
      cnt += -s+1;
      s += -s+1;
    }
  }
  ans = min(ans,cnt);

  cout << ans << endl;
}

Measured memory_bytes: 1024
#include <iostream>
#include <string>

using namespace std;

int main() {
  string ring;
  string keyWord;
  cin >> ring;
  cin >> keyWord;
  ring += ring;
  string::size_type pos = ring.find(keyWord);
  cout << (pos != string::npos? "Yes" :  "No" ) << endl;
  return 0;
}



Measured memory_bytes: 3224
penki = input().split(" ")
if penki[0] == penki[1]:
    if penki[1] == penki[2]:
        print("1")
    else:
        print("2")
elif penki[1] == penki[2]:
    print("2")
elif penki[0] == penki[2]:
    print("2")
else:
    print("3")

Measured memory_bytes: 3064
n, q = map(int, input().split())
s = input()
lst = [0] * q
for i in range(q):
    l, r = map(int, input().split())
    lst[i] = (l, r)

cum = [0] * (n + 1)
for i in range(n):
    cum[i + 1] = cum[i]
    if i < n - 1 and s[i] == 'A' and s[i + 1] == 'C':
        cum[i + 1] += 1

for x in lst:
    print(cum[x[1]-1] - cum[x[0]-1])


Measured memory_bytes: 19796
#include<time.h>
#include<string.h>
#include<stdlib.h>
#include<stdio.h>
char gyu(char x)
{
	int t;
	t=x;
	if(t<65 || t>122)
		return x;
	if(t>90 && t<97)
		return x;

	if(t<94)
		return x+32;
	return x-32;
}
int main()
{
	char a[1300];
	int i,len;
	scanf("%[^\n]",a);
	len=strlen(a);
	for(i=0;i<=len-1;i++)
		printf("%c",gyu(a[i]));
	printf("\n");
	return 0;
}


Measured memory_bytes: 2044
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace AtCoderTest
{
    public class Program
    {
        public static void Main(string[] args)
        {
            string[] input = Console.ReadLine().Split();
            var s = input.Select(f => f.First());
            Console.WriteLine(string.Concat(s));
        }
    }
}


Measured memory_bytes: 3032
void main(){
	
	BigInt deposit = 100;
	auto X = readln().chomp().BigInt();
		
	
	for( ulong y=1 ; ; y++ ){
		deposit = deposit + deposit/100;
		if( deposit >= X ){
			writeln( y ); return;
		}
	}
	X.writeln();
	return;
}


import std.stdio, std.string, std.conv;
import std.math, std.algorithm, std.array, std.bigint;

Measured memory_bytes: 2924
n = int(input())
l = [int(x) for x in input().split()]

a = list(map(abs, l))
s = sum(a)

ptv = 0
ntv = 0
for x in l:
    if x > 0:
        ptv += 1
    elif x < 0:
        ntv += 1
        

if ntv % 2 == 0:
    print(s)
else:
    print(s-min(a)*2)

Measured memory_bytes: 14412
#include <bits/stdc++.h>
using namespace std;
#define MOD 1000000007
#define INF 1000000009
typedef long long ll;
#define REP(i,n) for(int i=0;i<(n);i++)
#define RREP(i,n) for(int i=(n)-1;i>=0;i--)
#define rollcall cout<<"I'm Sucu."<<endl
#define YES(s) s?cout << "YES" << endl:cout << "NO" << endl
#define Yes(s) s?cout << "Yes" << endl:cout << "No" << endl
#define Taka(s) s?cout << "Takahashi" << endl:cout << "Aoki" << endl
#define int ll

int dp[60][60][2700]={};

signed main(void){
    int N,A,x[52]={},X=0;
    int Ans=0;
    dp[0][0][0]=1;
    cin >> N >> A;
    X=A;
    REP(i,N){
        cin >> x[i+1];
        X=max(X,x[i+1]);
    }
    
    REP(i,N+1){
        if(i==0)continue;
        REP(j,N+1){
            REP(k,N*X+1){
                if(k<x[i]){
                    dp[i][j][k]=dp[i-1][j][k];
                }else if((k>=x[i])&&(j>=1)){
                   dp[i][j][k]=dp[i-1][j][k]+dp[i-1][j-1][k-x[i]];
                }
            }
        }
    }
    
    /*REP(i,N+1){
        REP(j,N+1){
            REP(k,N*X+1){
                cout << dp[i][j][k]<< " ";
            }cout << endl;
        }cout << endl<<endl;
    }cout << endl;*/
    
    REP(i,N+1){
        if(i==0)continue;
        Ans+=dp[N][i][A*i];
    }
    
    cout << Ans << endl;
  return 0;
}


Measured memory_bytes: 64512
{-# LANGUAGE OverloadedLists     #-}
{-# LANGUAGE OverloadedStrings   #-}
{-# LANGUAGE ScopedTypeVariables #-}

import           Control.Monad
--import           Control.Monad.Loops
import           Data.IORef
import           Data.Maybe
import qualified Data.Text     as T
import qualified Data.Text.IO  as T
import           GHC.Base
import           System.IO

import qualified Data.Array    as A
import qualified Data.IntMap   as I
import           Data.List
import qualified Data.Map      as M
import qualified Data.Set      as S
import qualified Data.Vector   as V

-- for Text
(+.+) = T.append
(!.!) = T.index

-- for Vector
count :: (a -> Bool) -> V.Vector a -> Int
count p = V.length . V.filter p

-- for IO
readT :: Read a => T.Text -> a
readT = read . T.unpack

getLineSpc :: Read a => IO [a]
getLineSpc = do
  t <- T.getLine
  let xs = map readT $ T.split (== ' ') t
  return xs

getLineSpcVec :: Read a => IO (V.Vector a)
getLineSpcVec = do
  t <- T.getLine
  let xs = V.fromList $ map readT $ T.split (== ' ') t
  return xs

----------
-- main --
----------
main :: IO ()
main = traveling

traveling :: IO ()
traveling = do
  n :: Int <- readLn
  txys' :: [[Int]]  <- replicateM n getLineSpc
  let txys = V.fromList $ [0, 0, 0] : txys'
  bools <- newIORef []
  forM_ ([1..n] :: [Int]) $ \i ->
     modifyIORef bools (isPossibleRoute (txys V.! (i - 1)) (txys V.! i) :)
  bools <- readIORef bools
  if and bools
    then
    putStrLn "Yes"
    else
    putStrLn "No"

isPossibleRoute :: [Int] -> [Int] -> Bool
isPossibleRoute txy1 txy2
  | diff >= 0  && even diff = True
  | otherwise               = False
 where
   diff = (t2 - t1) - abs (x2 - x1) - abs (y2 - y1)
   [t1, x1, y1] = txy1
   [t2, x2, y2] = txy2

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

using namespace std;

const int N = 4e3 + 5;

struct edge {
    int v;
    edge *next;
} pool[N], *h[N];

int ans, top = -1;
int n, k;
vector <int> A, B;

inline void addedge(int u, int v) {
    edge *tmp = &pool[++top];
    tmp -> v = v; tmp -> next = h[u]; h[u] = tmp;
}

int dfs(int u, int pre, int len) {
    int res = 1;
    if(len == 0) return res;
    for(edge *tmp = h[u]; tmp != NULL; tmp = tmp -> next) {
        int v = tmp -> v;
        if(v == pre) continue;
        res += dfs(v, u, len - 1);
    }
    return res;
}

void init() {
    int x, y;
    scanf("%d%d", &n, &k);
    for(int i = 1; i < n; i++) {
        scanf("%d%d", &x, &y);
        addedge(x, y);
        addedge(y, x);
        A.push_back(x), B.push_back(y);
    }
    if(k % 2 == 0) {
        for(int u = 1; u <= n; u++) {
            ans = max(ans, dfs(u, 0, k / 2));
        }
    }
    else {
        for(int i = 0; i < A.size(); i++) {
            int u = A[i], v = B[i];
            ans = max(ans, dfs(u, v, k / 2) + dfs(v, u, k / 2));
        }
    }
    printf("%d\n", n - ans);
}

int main() {
    init();
    return 0;
}

//22:25:20

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

int main() {
    ios_base::sync_with_stdio(0); cin.tie(0);
    int t = 1;
    while(t--){
        int x,y;
        cin>>x>>y;
        cout<<x*y;
    }
    return 0;
}


Measured memory_bytes: 3636
using System;
using System.Collections;
using System.Collections.Generic;
using System.Text;
using System.Linq;
using static MyIO;


public class F
{
	public static void Main() => (new Solver()).Solve();
}


public class Solver
{
	public static readonly int MAX = 100000;

	public void Solve()
	{
		int N = GetInt();
		int[] x = new int[N];
		int[] y = new int[N];
		for(int i = 0; i < N; i++)
		{
			x[i] = GetInt() - 1;
			y[i] = GetInt() - 1 + MAX;
		}

		var uf = new UnionFind(2 * MAX);
		for(int i = 0; i < N; i++)
		{
			if(!uf.IsSame(x[i], y[i]))
				uf.Merge(x[i], y[i]);
		}

		var set = new HashSet<int>();
		var cntX = new Dictionary<int, long>();
		var cntY = new Dictionary<int, long>();
		for(int i = 0; i < MAX; i++)
		{
			long tmpX = 0;
			cntX.TryGetValue(uf.Root(i), out tmpX);
			cntX[uf.Root(i)] = tmpX + 1;
			set.Add(uf.Root(i));
		}

		for(int i = MAX; i < 2 * MAX; i++)
		{
			long tmpY = 0;
			cntY.TryGetValue(uf.Root(i), out tmpY);
			cntY[uf.Root(i)] = tmpY + 1;
			set.Add(uf.Root(i));
		}

		long ans = 0;
		foreach(int r in set)
		{
			long tmpX = 0;
			cntX.TryGetValue(r, out tmpX);
			long tmpY = 0;
			cntY.TryGetValue(r, out tmpY);
			ans += tmpX * tmpY;
		}

		Console.WriteLine(ans - N);
	}
}


public class UnionFind
{
	private int[] par = null;
	private int[] rank = null;
	private int[] ccSize = null;
	
	public UnionFind(int n)
	{
		par = new int[n];
		rank = new int[n];
		ccSize = new int[n];
		for(int i = 0; i < n; i++)
		{
			par[i] = i;
			rank[i] = 0;
			ccSize[i] = 1;
		}
	}

	public bool IsSame(int x, int y)
	{
		return (Root(x) == Root(y));
	}

	public int Root(int x)
	{
		if(par[x] == x)
			return x;

		int r = Root(par[x]);
		par[x] = r;
		return r;
	}
	
	public bool Merge(int x, int y)
	{
		int rx = Root(x);
		int ry = Root(y);
		if(rx == ry)
			return false;
		
		if(rank[rx] < rank[ry])
		{
			int tmp = rx;
			rx = ry;
			ry = tmp;
		}
		else if(rank[rx] == rank[ry])
			rank[rx]++;

		par[ry] = rx;
		ccSize[rx] = ccSize[rx] + ccSize[ry];
		return true;
	}

	public int Size(int x)
	{
		return ccSize[Root(x)];
	}
}


public static class MyIO
{
	private static string[] args = null;
	private static int num = -1;
	private static int used = -1;

	private static string getArg()
	{
		if(used == num)
		{
			args = Console.ReadLine().Split(' ');
			num = args.Length;
			used = 0;
		}
		return args[used++];
	}

	public static int GetInt() => int.Parse(getArg());
	public static long GetLong() => long.Parse(getArg());
	public static double GetDouble() => double.Parse(getArg());
	public static string GetString() => getArg();
	public static char GetChar() => getArg()[0];
	public static int[] GetInts(int N) => Enumerable.Range(0, N).Select(_ => GetInt()).ToArray();
	public static long[] GetLongs(int N) => Enumerable.Range(0, N).Select(_ => GetLong()).ToArray();
	public static double[] GetDoubles(int N) => Enumerable.Range(0, N).Select(_ => GetDouble()).ToArray();
	public static string[] GetStrings(int N) => Enumerable.Range(0, N).Select(_ => GetString()).ToArray();
}


Measured memory_bytes: 36672
#include<iostream>
#include<iomanip>
#include<vector>
#include<algorithm>
#include<set>
#include<map>
#include<stack>
#include<queue>
using namespace std;
using ll = long long;
using ld = long double;
using pint = pair<int, int>;
using pll = pair<ll, ll>;
#define MOD 1000000007LL
#define INF 1000000000LL
#define EPS 1e-10
#define FOR(i,n,m) for(ll i=n;i<(int)m;i++)
#define REP(i,n) FOR(i,0,n)
#define DUMP(a) REP(d,a.size()){cout<<a[d];if(d!=a.size()-1)cout<<" ";else cout<<endl;}
#define ALL(v) v.begin(),v.end()
#define UNIQUE(v)  sort(ALL(v));v.erase(unique(ALL(v)),v.end());
#define pb push_back

int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	ll h, w, n;
	cin >> h >> w >> n;
	ll sum = (h - 2) * (w - 2);
	vector<ll> ans(10, 0);
	map<pll, int> m;
	REP(i, n) {
		ll a, b;
		cin >> a >> b;
		a--; b--;
		for(ll da = -1; da <= 1; da++) {
			for(ll db = -1; db <= 1; db++) {
				ll na = a + da, nb = b + db;
				if(na > 0 && na < h - 1 && nb > 0 && nb < w - 1) m[pll(na, nb)]++;
			}
		}
	}
	ans[0] = sum - (ll)m.size();
	for(auto x: m) {
		ans[x.second]++;
	}
	REP(i, 10) cout << ans[i] << endl;
	return 0;
}
/* --------------------------------------- */


Measured memory_bytes: 56576
#include <iostream>
#include <string>
using namespace std;
string s;
int main()
{
	cin >> s;
	int si = s.size();
	int i;
	int ans = 0;
	for (i = 0; i < si; i++)
	{
		if (s[i] != s[si - i - 1])
			ans++;
	}
	cout << ans / 2;
}

Measured memory_bytes: 256
import itertools

n=int(input())
p=[int(x) for x in input().split()]
q=[int(x) for x in input().split()]
dic={}
cnt=0
a=0
b=0
for i in itertools.permutations(range(1,n+1)):
    dic[cnt]=i
    if list(i) == p:
        a=cnt
    if list(i) == q:
        b=cnt
    cnt+=1
print(abs(a-b))

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

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

int main(){
 
    int k,x;
    cin>>k>>x;
    if (k*500>=x)
    {
        /* code */
        cout<<"Yes"<<endl;
    }
    else
    {
        cout<<"No"<<endl;
    }
    
    
    
    }

Measured memory_bytes: 256
#include<iostream>
#include<cstring>
#include<cstdio>
#include<algorithm>
#include<cmath>
#include<set>
#include<bitset>
#include<map>

#define fo(i,a,b) for(int i=a;i<=b;i++)
#define fd(i,a,b) for(int i=a;i>=b;i--)

using namespace std;

typedef long long LL;
typedef double db;

int get(){
	char ch;
	while(ch=getchar(),(ch<'0'||ch>'9')&&ch!='-');
	if (ch=='-'){
		int s=0;
		while(ch=getchar(),ch>='0'&&ch<='9')s=s*10+ch-'0';
		return -s;
	}
	int s=ch-'0';
	while(ch=getchar(),ch>='0'&&ch<='9')s=s*10+ch-'0';
	return s;
}

const int N = 200005;

int n;
int a[N];
int b[N];

int main(){
	n=get();
	fo(i,1,n)a[i]=b[i]=get();
	sort(b+1,b+1+n);
	int v1=b[n/2],v2=b[n/2+1];
	fo(i,1,n){
		if (a[i]<=v1)printf("%d\n",v2);
		else printf("%d\n",v1);
	}
	return 0;
}

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

const int N = 55;

int n;
long long a[N];

void init() {
	std::cin >> n;
	for (int i = 1; i <= n; i++) {
		scanf("%lld", &a[i]);
	}
}

bool check(long long mid) {
	long long t = 0;
	for (int i = 1; i <= n; i++) {
		t += (a[i] + mid + 1) / (n + 1);
	}
	return t <= mid;
}

void work() {
	long long answer = -1;

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

	for (int i = 0; i < n; i++) {
		long long low = 0, high = a[n];
		while (low <= high) {
			long long mid = (low + high) >> 1;
			if (check(mid * n + i)) {
				if (answer == -1 || mid * n + i < answer) {
					answer = mid * n + i;
				}
				high = mid - 1;
			} else {
				low = mid + 1;
			}
		}
	}
	std::cout << answer << std::endl;
}

int main() {
	init();
	work();

	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <utility>
#include <cmath>
#include <random>
#include <vector>
#include <map>
#include <set>
#include <deque>
#include <queue>
#include <stack>
#include <string>
#include <algorithm>
using namespace std;

#define rep(i,n) for(int i = 0; i<n; ++i)
#define REP(i,n) for(int i = 1; i<=n; ++i)
#define all(x) begin(x),end(x)
#define show(obj) {for(auto x:obj)cout<<x<<' ';cout<<endl;}
#define line "----------"
typedef long long ll;
typedef pair<int,int> P;
const int inf = 1001001000;
const ll INF = 1LL<<60;
const ll MOD = 1e9 + 7;

int main(){
	int N; cin>>N;
	vector<ll> a(N);
	vector<ll> b(N);
	rep(i,N)cin>>a[i]>>b[i];
	vector<pair<ll, int>> dish(N);
	rep(i,N){
		dish[i].first = a[i] + b[i];
		dish[i].second = i;
	}
	sort(all(dish), greater<pair<ll,int>>());
	ll sum_a = 0, sum_b = 0;
	rep(i,N){
		if(i % 2 == 0){
			sum_a += a[dish[i].second];
		}else{
			sum_b += b[dish[i].second];
		}
	}
	cout<<sum_a - sum_b<<endl;
	return 0;
}

Measured memory_bytes: 3328
open Printf
open Scanf

let id x = x
             
module Dice =
  struct
    type t = {tp:int; ft:int; lt:int; rt:int; bk:int; bm:int}

    let create x1 x2 x3 x4 x5 x6 =
      {tp = x1; ft = x2; lt = x3; rt = x4; bk = x5; bm = x6}

    let roll d = function
        'S' -> {d with tp = d.bk; ft = d.tp; bm = d.ft; bk = d.bm}
      | 'E' -> {d with tp = d.rt; lt = d.tp; bm = d.lt; rt = d.bm}
      | 'W' -> {d with tp = d.lt; rt = d.tp; bm = d.rt; lt = d.bm}
      | 'N' -> {d with tp = d.ft; bk = d.tp; bm = d.bk; ft = d.bm}
      | _ -> failwith "roll"

    let rollx d dirs =
      let rd = ref d in
      String.iter (fun c -> rd := roll !rd c) dirs;
      !rd

    let equal d1 d2 =
      let ht = Hashtbl.create 100 in
      let rec dfs d =
        if Hashtbl.mem ht d then false
        else
          if d1 = d then true
          else begin
              Hashtbl.add ht d true;
              List.fold_left (fun b c ->
                              if b then b
                              else dfs (roll d c)
                             ) false ['N';'E';'W';'S']
            end
      in dfs d2
          
    let top d = d.tp
    let front d = d.ft
    let left d = d.lt
  end

let () =
  let n = scanf "%d " id in
  let rec read x =
    if x = 0 then []
    else let d = scanf "%d %d %d %d %d %d " Dice.create in
         d :: (read (x-1)) in
  let ds = read n in
  let rec iter = function
      [] -> "Yes"
    | h :: t -> if List.exists (fun d -> Dice.equal h d) t then "No" else iter t in
  iter ds |> printf "%s\n"

Measured memory_bytes: 4404
#include<bits/stdc++.h>
using namespace std;
const int mod = 1e9+7;
int main()
{
    #ifdef LOCAL_FILE
    freopen("in.txt","r",stdin);
    #endif // LOCAL_FILE
    ios_base::sync_with_stdio(0);
    cin.tie(0),cout.tie(0);
    char s1[105],s2[105];
    int n,last,i=0;
    long long ans = 1;
    cin>>n;
    cin>>s1;
    cin>>s2;
    while(i<n)
    {
        if(i == 0)
        {
            if(s1[i] == s2[i])
            {
                ans = ans*3;
                last = 1;
                i++;
            }
            else
            {
                ans = ans*6;
                last = 2;
                i+=2;
            }
        }
        else
        {
            if(s1[i] == s2[i])
            {
                if(last == 1) ans = (ans*2)%mod; //X->X
                else if(last == 2) ans = (ans*1)%mod; //Y->X
                last = 1;
                i++;
            }
            else
            {
                if(last == 1) ans = (ans*2)%mod;//X->Y
                else if(last == 2) ans = (ans*3)%mod; //Y->Y
                last = 2;
                i+=2;
            }
        }
    }
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 256
N, K = [int(i) for i in input().split()]
R, S, P = [int(i) for i in input().split()]
T=list(input())
score=[[0,0,0]*K]
for i in range(N-K):
    if T[i]==T[i+K]:
        T[i+K]="."

print(T.count("p")*S + T.count("s")*R + T.count("r")*P )


Measured memory_bytes: 5932
S = input()

head = int(S[0:2])
tail = int(S[2:4])

if head >= 1 and head <= 12:
    if tail >= 1 and tail <= 12:
        print('AMBIGUOUS')
    elif tail <=99:
        print('MMYY')
elif head <= 99:
    if tail >= 1 and tail <= 12:
        print('YYMM')
    elif tail <= 99:
        print('NA')

Measured memory_bytes: 3060
function Main(input) {
  const data = input.split("\n").map((val) => parseInt(val, 10));
  const k = data[5];
  var result = "Yay!";

  for(var i=0 ;i< 4;i++){
    if(k < data[4] - data[i]) {
      result = ":(";
    }
  }
  console.log(result);

}
Main(require("fs").readFileSync("/dev/stdin", "utf8"));

Measured memory_bytes: 7372
Scanf.scanf "%d" (fun k ->
    let c = k mod 50 in
    Printf.printf "50\n";
    for j = 0 to 49 do
        Printf.printf "%d " @@
            if j < c then (49 - j) + (k / 50) + 1
                     else (49 - j) + (k / 50)
    done;
    print_newline ()
)

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

using namespace std;

int main(){
	int x1,x2, x3,x4, x5;
  	cin >> x1>>x2>>x3>>x4>>x5;
  	if(x1 == 0)
      cout << 1<<endl;
	else if(x2 == 0)
      cout << 2<<endl;
 	else if(x3 == 0)
      cout << 3<<endl;
  	else if(x4 == 0)
      cout << 4<<endl;
 	else
      cout << 5<<endl;
}

Measured memory_bytes: 3568
n = int(input())
a = list(map(int, input().split()))
mod = 1000000007
color = [0,0,0]
ans = 1
for i in a:
  mini = 0
  al = 0
  for key,j in enumerate(color):
    if i == j:
      if al == 0:
        al = 1
        color[key] += 1
      mini += 1
  ans = (ans * mini) % mod
print(ans)

Measured memory_bytes: 52952
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int main() {
	ios::sync_with_stdio(0);
	cin.tie(0);
	int x,y;
	cin>>x>>y;
	int h = x*2;
	if(y<h)
	{
		cout<<"No";
	}
	else if(h == y)
	{
		cout<<"Yes";
	}
	else
	{
		int g = y-h;
		if((g%2==0)&&((g/2)<=x))
		{
			cout<<"Yes";
		}
		else
		{
			cout<<"No";
		}
	}
	return 0;
}

Measured memory_bytes: 3640
/*
   AUTHOR :- Gaurang_Kothiya
   
   Quote:-" Great things never come from comfort zones."                                                                                                                
*/
 
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>  
#include <ext/pb_ds/tree_policy.hpp> 
#include <functional>
 
using namespace std;
using namespace __gnu_pbds;  

typedef tree<int, null_type, less<int>, rb_tree_tag,tree_order_statistics_node_update> data_set; 
#define speed ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define ll long long  
#define ld long double
#define f(i,x,n) for(ll i=x;i<=n;i++)
#define fe(x,v)   for(auto &x :v)
#define nf(i,x,n) for(ll i=n;i>=x;i--)
#define all(a)   a.begin(),a.end()
#define b_s(a,b)   binary_search( all(a),b)
#define lb(v,n)  lower_bound(all(v) ,n )
#define ub(v,n)  upper_bound( all(v) , n)
#define gcd(a,b) __gcd(a,b)
#define pub push_back
#define pob pop_back
#define puf push_front
#define pof pop_front
#define B begin()
#define E end()
#define acc(v, x) accumulate(all(v), x)
#define p(a,b) pair<a,b>
#define F first
#define S second
#define sz size()
#define v(x) vector<x>
#define m(a,b) map<a,b>
#define u_m(a,b) unordered_map<a,b>
#define mm(a,b) multimap<a,b>
#define s(a) set<a>
#define us(a) unordered_set<a>
#define ms(a) multiset<a>
#define maxy __LONG_LONG_MAX__
#define miny INT_MIN
#define PI 3.14159265358979323846
#define MOD 1000000007



void solver()
{
	ll a,b;
	cin>>a>>b;
	
	f(i,1,2000000)
	{
		if(   floor( i*(0.08)) ==a  && floor(i*(0.1))==b)
		{
			cout<<i;
			return;
		}
	}
	cout<<-1;
}

signed main() 
{
	speed	
		
	ll q=1;	
	//cin>>q;	
	
	while(q--)	
	solver();	
	
	//cout << "\n\n"<<"Time elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << " seconds.\n";
	return 0;
}

 
 

Measured memory_bytes: 256
def main():
    N, M = [int(i) for i in input().split()]

    pos = 0
    ans = 1

    fib = [1 for _ in range(N+1)]
    for i in range(2, N+1):
        fib[i] = fib[i-1] + fib[i-2]

    for _ in range(M):

        a = int(input())

        if a == pos:
            ans = 0
            pos = N
            break
        elif a == pos + 1:
            pos = a + 1
        else:
            ans *= fib[(a - 1 - pos)]
            pos = a + 1

    if pos + 1 < N:
        ans *= fib[(N - pos)]

    print(ans % 1_000_000_007)



if __name__ == "__main__":
    main()

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

using namespace std;

int main() {
  int H, N;
  cin >> H >> N;
  vector<int> A(N), B(N);
  for (int i = 0; i < N; i++) cin >> A[i] >> B[i];

  vector<int> dp(H + 10, -1);
  dp[H] = 0;

  for (int i = 0; i < N; i++) {
    for (int h = H; h >= 0; h--) {
      if (dp[h] == -1) continue;
      int next_hp = max(h - A[i], 0);
      int next_sum = dp[h] + B[i];
      if ((dp[next_hp] == -1) ||
	  dp[next_hp] > next_sum) {
	dp[next_hp] = next_sum;
      }
    }
  }

  cout << dp[0] << endl;

  return 0;
}


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

#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define rep2(i,a,b) for(int i=a;i<b;i++)
#define each(it,v) for(auto it : v)
#define mod 1000000007
#define All(v) (v).begin(),(v).end()
#define ll long long
#define vi vector<int>
#define vll vector<ll>
#define vpii vector<pair<int,int>>
#define vvi vector<vector<int>>
#define vvll vector<vetor<ll>>
template<class T> T gcd(T a,T b) {return b?gcd(b,a%b):a;}
template<class T> T lcm(T a,T b) {return a/gcd(a,b)*b; }
template<class T> bool isPrime(T num)
{
    if (num < 2) return false;
    else if (num == 2) return true;
    else if (num % 2 == 0) return false;

    double sqrtNum = sqrt(num);
    for (T i = 3; i <= sqrtNum; i += 2)
    {
        if (num % i == 0)
        {
            return false;
        }
    }
    return true;
}

using namespace std;

int a,b,c;
int n,m,p,cnt;
ll ans;
string s,t;

main()
{
        cin>>n>>p;
        bool f=false;
        vi v(n);
        each(&it,v)
        {
            cin>>it;
            if(it%2)f=true;
        }

        ll ans;
        if(!f&&p)ans=0;
        else if(!f)ans=pow(2,n);
        else ans=pow(2,n-1);
        cout<<ans<<endl;
}

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

const ll LINF = 1e18;
const int INF = 1e9;
const ll MOD = 1000000007;

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

ll func(ll n){
    return n*(n+1)/2;
}
int main(){

    ll x;
    cin >> x;

    ll ans = 0;
    for(int i = 1; i <= x; i++){
        if(func(i) >= x){
            ans = i;
            break;
        }
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 3588
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Collection;
import java.io.IOException;
import java.util.Deque;
import java.io.InputStreamReader;
import java.util.StringTokenizer;
import java.io.BufferedReader;
import java.util.ArrayDeque;
import java.io.InputStream;

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

    static class TaskC {
        public void solve(int testNumber, InputReader in, PrintWriter out) {
            int n = in.nextInt();
            int[] a = new int[n];
            for (int i = 0; i < n; ++i) a[i] = in.nextInt();
            Deque<Integer> res = new ArrayDeque<>();
            for (int i = 0; i < n; ++i) {
                if (i % 2 == 0) {
                    res.addLast(a[i]);
                } else {
                    res.addFirst(a[i]);
                }
            }
            if (n % 2 == 0) {
                for (Object x : res.toArray()) out.print(x + " ");
            } else {
                for (int i = 0; i < n; ++i) {
                    out.print(res.getLast() + " ");
                    res.removeLast();
                }
            }
        }

    }

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

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

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

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

    }
}



Measured memory_bytes: 70332
#include <iostream>

using namespace std;

int main(){
    int N, K;
    cin >> N >> K;
    long long h[N];
    for(int i = 0; i < N; i++){
        cin >> h[i];
    }

    // 足場 0 ~ N-1
    long long dp[N]; // dp[i] := 足場i番目までの最小コスト
    for(int i = 0; i < N; i++){
        dp[i] = __LONG_LONG_MAX__; // 十分大きな値で初期化
    }
    dp[0] = 0; // 足場 0
    dp[1] = abs(h[1]-h[0]); // 足場 1
    for(int i = 2; i < N; i++){
        for(int j = 1; (j <= K && i-j >= 0); j++){
            dp[i] = min(dp[i], dp[i-j]+abs(h[i]-h[i-j]));
        }
    }

    cout << dp[N-1] << endl;


    return 0;
}

Measured memory_bytes: 1792
import java.util.Scanner;
public class Main{
  public static void main(String[] args){
  Scanner sc = new Scanner(System.in);
  int N = sc.nextInt();
  double c=0;
  for(int i=1;i<=N;i++){
    if(i%2==1){
      c++;
    }
  }
  System.out.println(c/N);
 }
}


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

using namespace std;

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

const int N = 55;

int n, m;
bool Pass[N][N];
vector <pii> Adj[N];

bool DFS(int x, int y, int i, int p = 0)
{
    if(x == y)  return true;

    for(int k = 0; k < Adj[x].size(); k++)
    {
        int z = Adj[x][k].first;
        int j = Adj[x][k].second;

        if(z == p)  continue;

        Pass[i][j] = true;

        if(DFS(z, y, i, x)) return true;

        Pass[i][j] = false;
    }

    return false;
}

int Cnt[N];

ll Rec(int i = 0, int k = 0)
{
    if(i == m)
    {
        ll Res = 0;

        for(int j = 1; j < n; j++)
            if(!Cnt[j])
                Res++;

        Res = 1LL << Res;

        return k & 1 ? -Res : +Res;
    }

    ll Res = Rec(i + 1, k);

    for(int j = 1; j < n; j++)
        if(Pass[i][j])
            Cnt[j]++;

    Res += Rec(i + 1, k + 1);

    for(int j = 1; j < n; j++)
        if(Pass[i][j])
            Cnt[j]--;

    return Res;
}

int main()
{
    cin >> n;

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

        Adj[x].emplace_back(y, i);
        Adj[y].emplace_back(x, i);
    }

    cin >> m;

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

        DFS(x, y, i);
    }

    cout << Rec() << endl;
}


Measured memory_bytes: 384
/**
 *    author:  tourist
 *    created: 26.11.2019 22:59:30       
**/
#include <bits/stdc++.h>

using namespace std;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n;
  cin >> n;
  vector<int> a(n), b(n);
  for (int i = 0; i < n; i++) {
    cin >> a[i] >> b[i];
  }
  if (a[0] != 0 || b[1] != 0 || a[1] == 0 || a[1] != b[0]) {
    cout << -1 << '\n';
    return 0;
  }
  int d = a[1];
  vector<int> was(d + 1, 0);
  for (int i = 0; i < n; i++) {
    if ((i >= 2 && min(a[i], b[i]) == 0) || a[i] + b[i] < d) {
      cout << -1 << '\n';
      return 0;
    }
    if (a[i] + b[i] == d) {
      was[a[i]] = 1;
    }
  }
  if (*min_element(was.begin(), was.end()) == 0) {
    cout << -1 << '\n';
    return 0;
  }
  set<pair<int, int>> s;
  for (int i = 0; i < n; i++) {
    s.emplace(a[i], b[i]);
  }
  map<pair<int, int>, tuple<int, int, int>> mp;
  int ans = 0;
  for (int i = 0; i < n; i++) {
    get<0>(mp[make_pair(a[i], b[i])]) += 1;
    get<2>(mp[make_pair(a[i], b[i])]) += 1;
    ans += (a[i] > 0) + (b[i] > 0);
    if (s.find({a[i] - 1, b[i] - 1}) != s.end()) {
      get<1>(mp[make_pair(a[i], b[i])]) += 1;
    } else {
      if (a[i] > 0 && s.find({a[i] - 1, b[i]}) == s.end() && s.find({a[i] - 1, b[i] + 1}) == s.end()) {
        cout << -1 << '\n';
        return 0;
      }
      if (b[i] > 0 && s.find({a[i], b[i] - 1}) == s.end() && s.find({a[i] + 1, b[i] - 1}) == s.end()) {
        cout << -1 << '\n';
        return 0;
      }
    }
  }
  for (auto& p : mp) {
    int t = min(get<0>(p.second), get<1>(p.second));
    get<2>(p.second) -= t;
    ans -= t;
    auto it = mp.find(make_pair(p.first.first + 1, p.first.second - 1));
    if (it != mp.end()) {
      t = min(get<2>(p.second), get<0>(it->second));
      get<0>(it->second) -= t;
      ans -= t;
    }
  }
  cout << ans << '\n';
  return 0;
}


Measured memory_bytes: 12416
#include <bits/stdc++.h>
#define syosu(x) fixed<<setprecision(x)
using namespace std;
typedef long long ll;
typedef unsigned int uint;
typedef unsigned long long ull;
typedef pair<int,int> P;
typedef pair<double,double> pdd;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<string> vs;
typedef vector<P> vp;
typedef vector<vp> vvp;
typedef vector<pll> vpll;
typedef pair<int,P> pip;
typedef vector<pip> vip;
const int inf=1<<29;
const ll INF=1ll<<60;
const double pi=acos(-1);
const double eps=1e-11;
const ll mod=1e9+7;
//const int dx[4]={-1,0,1,0},dy[4]={0,-1,0,1};
const int dx[6]={-1,0,1,0,1,-1},dy[6]={0,-1,0,1,1,-1};

const int h=200,w=200;
const int M=100000;

vvi a;

int main(){
	while(1){
		int m,n;
		cin>>m>>n;
		if(m==0) break;
		a=vvi(h,vi(w));
		for(int i=0;i<n;i++){
			int x,y;
			cin>>x>>y;
			a[x+100][y+100]++;
		}
		int x,y;
		cin>>x>>y;
		queue<pip> q;
		q.push({0,{x+100,y+100}});
		a[x+100][y+100]++;
		int res=1;
		while(!q.empty()){
			auto pp=q.front();
			q.pop();
			if(pp.first==m) continue;
			P p=pp.second;
			x=p.first,y=p.second;
			for(int i=0;i<6;i++){
				int cx=x+dx[i],cy=y+dy[i];
				if(!a[cx][cy]){
					a[cx][cy]=1;
					res++;
					q.push({pp.first+1,{cx,cy}});
				}
			}
		}
		cout<<res<<endl;
	}
}


Measured memory_bytes: 3272
#include <iostream>

using namespace std;

int b[3][3];

int main(){
	int tmp;
	for(int i=0;i<3;i++){
		for(int j=0;j<3;j++){
			cin >>tmp;
			b[i][j]=tmp;
		}			
	}
	int n;
	cin >> n;
	int ris=0;
	for(int i=0;i<n;i++){
		cin >> tmp;
		for(int i=0;i<3;i++){
			for(int j=0;j<3;j++){
				if(b[i][j]==tmp){
					b[i][j]=0;
				}
			}			
		}	
	}
	int j=0;
	for(int i=0;i<3;i++){
		bool isc=true;
		for(j=0;j<3;j++){
			if(b[i][j]!=0){
				isc=false;
			}
		}
		if(isc){
			printf("Yes\n");
			return 0;
		}	
	}	
	
	for(int i=0;i<3;i++){
		bool isc=true;
		for(j=0;j<3;j++){
			if(b[j][i]!=0){
				isc=false;
			}
		}
		if(isc){
			printf("Yes\n");
						return 0;
		}	
	}	

	if(b[1][1]==0){
		if(b[0][0]==0&&b[2][2]==b[0][0]){printf("Yes\n");return 0;}
		if(b[0][2]==0&&b[2][0]==b[0][2]){printf("Yes\n");return 0;}
	}

	printf("No\n");

}

Measured memory_bytes: 256
#include <cstdio>
#include <vector>
#include <algorithm>
#include <queue>
#include <map>

using namespace std;

vector<pair<int, int>> GetHighestRecurringElements(const vector<int> &S, int startIndex) {
  map<int, int> frequencyOf;
  for (int i = startIndex; i < S.size(); i += 2) {
    frequencyOf[S[i]]++;
  }

  priority_queue<pair<int, int>> pq;
  for (auto node : frequencyOf) {
    int el = node.first;
    int frequency = node.second;
    pq.push(make_pair(frequency, el));
  }
  pq.push(make_pair(0, -100 + startIndex));

  vector<pair<int, int>> highest;
  highest.push_back(pq.top()); pq.pop();
  highest.push_back(pq.top());

  return highest;
}

int MinimumStepsToMakeVVV(const vector<int> &S) {
  auto odd_elements = GetHighestRecurringElements(S, 1);
  auto even_elements = GetHighestRecurringElements(S, 0);

  int answer = 100000000;
  for (auto odd : odd_elements) {
    for (auto even : even_elements) {
      if (odd.second != even.second) {
        answer = min(answer, (int)S.size() - odd.first - even.first);
      }
    }
  }

  return answer;
}

int main(void) {
  int N;
  scanf("%i", &N);

  vector<int> S(N);
  for (int &el : S) {
    scanf("%i", &el);
  }

  printf("%i\n", MinimumStepsToMakeVVV(S));

  return 0;
}


Measured memory_bytes: 3952
#include <cstdlib>
#include <iostream>


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

  int k;
  std::cin >> k;
  auto l = k / 2;
  std::cout << (k % 2 == 0 ? l * l :  (l + 1) * l) << std::endl;

  return EXIT_SUCCESS;
}


Measured memory_bytes: 256