akhauriyash/Code-Regression huggingface dataset:
import java.util.*;

public class Main {
	static ArrayList<HashMap<Integer, Long>> list = new ArrayList<HashMap<Integer, Long>>();
	static long maze_cnt[];
	public static void main(String args[]) {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int a[] = new int[N];
		int b[] = new int[N];
		long c[] = new long[N];
		
		for(int i = 0; i < N; i++) {
			HashMap<Integer, Long> map = new HashMap<Integer, Long>();
			list.add(map);
		}
		
		for(int i = 0; i < N - 1; i++) {
			a[i] = sc.nextInt() - 1;
			b[i] = sc.nextInt() - 1;
			c[i] = (long)sc.nextInt();
			list.get(a[i]).put(b[i], c[i]);
			list.get(b[i]).put(a[i], c[i]);
		}
		
		int Q = sc.nextInt();
		int K = sc.nextInt() - 1;
		int x[] = new int[Q];
		int y[] = new int[Q];
		for(int i = 0; i < Q; i++) {
			x[i] = sc.nextInt() - 1;
			y[i] = sc.nextInt() - 1;
		}
		
		DFS(list, K);
		
		for(int i = 0; i < Q; i++) {
			System.out.println(maze_cnt[x[i]] + maze_cnt[y[i]]);
		}
	}
	
public static void DFS(ArrayList<HashMap<Integer, Long>> list, int now) {
		
		Deque<Integer> stack = new ArrayDeque<Integer>();
		stack.push(now);
		
		maze_cnt = new long[list.size()];
		boolean flag[] = new boolean[list.size()];
		
		for(int i = 0; i < list.size(); i++) {
			maze_cnt[i] = Long.MAX_VALUE;
			flag[i] = false;
		}
		flag[now] = true;
		
		maze_cnt[now] = 0;
		
		while(stack.size() != 0) {
			now = stack.poll();
			for(int key : list.get(now).keySet()) {
				if(maze_cnt[key] > maze_cnt[now] + list.get(now).get(key) && !flag[key]) {
					stack.push(key);
					maze_cnt[key] = maze_cnt[now] + list.get(now).get(key);
					flag[key] = true;
				}
			}
		}
	}
}

Measured memory_bytes: 190872
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <unordered_map>

using namespace std;

const int N = (int) 1e4 + 5;
const int M = (int) 1e9 + 7;

typedef long long ll;

int n, m;

int main() {
    cin >> n >> m;
  
  cout << (n * (n-1) / 2 + m * (m-1) / 2) << endl;
 

    return 0;
}

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

using namespace std;

int main()
{
    ios_base::sync_with_stdio(0);
    int n;
    cin >> n;
    double wyn = 0.0;
    for  (int i = 0; i < n; ++i)
    {
        double x;
        string u;
        cin >> x >> u;
        if (u == "JPY")
            wyn += x;
        else
            wyn += 380000.0 * x;
    }
    cout << fixed << setprecision(10);
    cout << wyn;
    return 0;
}


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

int main()
{
    
    string a; cin>>a;
    int n=a.length();
    vector<char> v;
    int r=0,c=0;
    for(int i=0;i<n;i++)
    {
        if(a[i]=='0') r--;
        else
        {
            if(r<0){
                c += 2;
                r++;
            }
            else v.push_back(a[i]);
        }
    }
    while(r<0) {v.push_back('0'); r++;}
    r=0;
    for(int i=0;i<v.size();i++)
    {
        if(v[i]=='1') r--;
        else
        {
            if(r<0){
                c += 2;
                r++;
            }
            
        }
    }
    
    cout<<c<<endl;
}

Measured memory_bytes: 640
#include <ctime>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cassert>
#include <algorithm>
#include <iostream>
#include <vector>
#include <queue>
#include <stack>
#include <deque>
#include <set>
#include <map>
using namespace std;

typedef long long ll;
typedef double lf;
typedef long double Lf;
typedef pair <int,int> pii;
typedef pair <ll, ll> pll;

#define TRACE(x) cerr << #x << "  " << x << endl
#define FOR(i, a, b) for (int i = (a); i < int(b); i++)
#define REP(i, n) FOR(i, 0, n)
#define all(x) (x).begin(), (x).end()
#define _ << " " <<

#define fi first
#define sec second
#define mp make_pair

const int MAXN = 100100;

int n, p[MAXN];

ll sol;
int dp[MAXN][3];

int rek(int x, int y) {
  if (y > p[x]) return -1234567;
  if (x >= n) return 0;
  if (dp[x][y] != -1) return dp[x][y];
  int ret = rek(x + 1, 0);
  ret = max(ret, rek(x, y + 2) + 1);
  if (p[x] - y) ret = max(ret, rek(x + 1, 1) + 1);
  return dp[x][y] = ret;
}

int main() {
  cin >> n;
  REP(i, n) cin >> p[i];
  REP(i, n) sol += p[i]/2;
  REP(i, n) {
    if (p[i] % 2) p[i] = 1;
    else if (p[i]) {
      p[i] = 2;
      sol--;
    }
  }

  memset(dp, -1, sizeof dp);
  sol += rek(0, 0);
  printf("%lld\n",sol);
}


Measured memory_bytes: 8064
#!/usr/bin/env python3
import sys
sys.setrecursionlimit(10**6)
input = sys.stdin.readline
INF = 10**9

n, u, v = [int(item) for item in input().split()]
u -= 1; v -= 1
edge = [[] for _ in range(n)]

for i in range(n-1):
    a, b = [int(item) for item in input().split()]
    a -= 1; b -= 1
    edge[a].append(b)
    edge[b].append(a)

depth = [0] * n
def calc_depth(p, v, d):
    depth[v] = d
    for nv in edge[v]:
        if nv == p:
            continue
        calc_depth(v, nv, d+1)

calc_depth(-1, v, 0)
frm = depth[v]
too = depth[u]
up = (too - frm - 1) // 2
max_depth = too 

def dfs(p, v, lim):
    global max_depth
    max_depth = max(max_depth, depth[v])
    for nv in edge[v]:
        if nv == p:
            continue
        if depth[v] < lim:
            continue
        dfs(v, nv, lim)
dfs(-1, u, too - up)
if too == 1 and max_depth == 1:
    print(0)
    exit()
if too == 2 and max_depth == 2:
    print(1)
    exit()

ans = 0
ans = max_depth - frm - 1
print(ans)

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

int main() {
	ios::sync_with_stdio(0);
	cin.tie(0);
	
	int n, W;
	cin >> n >> W;
	vector<int> w(n+1);
	vector<int> v(n+1);
	for (int i = 1; i <= n; i++) {
		cin >> w[i] >> v[i];
	}
	vector<ll> dp(W + 1);
	for (int k = 1; k <= n; k++) {
		for (int x = W; x >= w[k]; x--) {
			dp[x] = max(dp[x], dp[x - w[k]] + v[k]);
		}
	}
	ll ans = 0;
	for (int x = 0; x <= W; x++) {
		ans = max(dp[x], ans);
	}
	cout << ans << "\n";
	
	return 0;
}


Measured memory_bytes: 1024
#include <iostream>
#include <stack>
#include <math.h>
#include <vector>
#include <string>
#include <algorithm>
#include <map>

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

int main()
{
    int k;
    string s;
    cin >> k >> s;
    if (s.length() > k)
    {
        cout << s.substr(0,k) << "..." << endl;
    }
    else
    {
        cout << s << endl;
    }

    return 0;
}

Measured memory_bytes: 3632
N, M = map(int, input().split())
Hi = list(map(int,input().split(" ")))
#path = [list() for _ in range(M+1)]

Tallest = [0]*N

for i in range(M):
    a, b = map(int, input().split())
    a -= 1
    b -= 1
    Tallest[a] = max(Tallest[a], Hi[b])
    Tallest[b] = max(Tallest[b], Hi[a])

goodT = 0

for i in range(N):
    if Hi[i]>Tallest[i]:
        goodT +=1
    
print (goodT)
        

Measured memory_bytes: 20088
s = input()
n = len(s)
ans = [0] * n
cnt_even = 0
cnt_odd = 0
index = 0
for i in range(n - 1):
    if s[i] == 'R' and s[i + 1] == 'L':
        index = i
    if i % 2:
        cnt_odd += 1
    else:
        cnt_even += 1
    if s[i] == 'L' and s[i + 1] == 'R' or i == n - 2:
        if i == n - 2:
            if (i + 1) % 2:
                cnt_odd += 1
            else:
                cnt_even += 1
        if index % 2:
            ans[index] += cnt_odd
            ans[index + 1] += cnt_even
        else:
            ans[index] += cnt_even
            ans[index + 1] += cnt_odd
        cnt_even = 0
        cnt_odd = 0
print(*ans, sep=' ')


Measured memory_bytes: 6400
// 参考: https://qiita.com/tanakh/items/0ba42c7ca36cd29d0ac8

macro_rules! read_value {
    ($iter:expr, ( $($t:tt),* )) => {
        ( $(read_value!($iter, $t)),* )
    };

    ($iter:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($iter, $t)).collect::<Vec<_>>()
    };

    ($iter:expr, chars) => {
        read_value!($iter, String).chars().collect::<Vec<char>>()
    };

    ($iter:expr, usize1) => {
        read_value!($iter, usize) - 1
    };

    ($iter:expr, $t:ty) => {
        $iter.next().unwrap().parse::<$t>().expect("Parse error")
    };
}

macro_rules! input_inner {
    ($iter:expr) => {};
    ($iter:expr, ) => {};

    ($iter:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($iter, $t);
        input_inner!{$iter $($r)*}
    };
}

macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
    ($($r:tt)*) => {
        let mut s = {
            use std::io::Read;
            let mut s = String::new();
            std::io::stdin().read_to_string(&mut s).unwrap();
            s
        };
        let mut iter = s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
}


fn main() {
    input!{
        s: i64,
        w: i64,
    }
    if s > w {
        println!("safe");
    } else {
        println!("unsafe");
    }
}


Measured memory_bytes: 2132
#include <iostream>
#include <vector>
#include <algorithm>
#include <numeric>
#include <set>
#include <map>
#include <string>
#include <stack>
#include <queue>
#include <cmath>
#include <cstdio>
using namespace std;

int main(void) {
	int T, H;
	while (cin >> T >> H, T) {
		vector<int> taro(T);
		vector<int> hanako(H);
		for (int i = 0; i < T; i++) {
			cin >> taro[i];
		}
		for (int i = 0; i < H; i++) {
			cin >> hanako[i];
		}

		int tsam = accumulate(taro.begin(), taro.end(), 0);
		int hsam = accumulate(hanako.begin(), hanako.end(), 0);
		
		int ttrade = -1, htrade = -1;
		for (int ti = 0; ti < T; ti++) {
			for (int hi = 0; hi < H; hi++) {
				if (tsam - taro[ti] + hanako[hi] == hsam - hanako[hi] + taro[ti]){
					ttrade = ti;
					htrade = hi;
					ti = T; hi = H; //break
				}
			}
		}

		if (ttrade != -1){
			cout << taro[ttrade] << " " << hanako[htrade] << endl;
		} else {
			cout << -1 << endl;
		}
	}


	return 0;
}

Measured memory_bytes: 1192
#include <bits/stdc++.h>
#define rep(i, n) for (ll i = 0; i < (n); ++i)
#define repr(i, n) for (int i = (n); i >= 0; --i)
#define FOR(i, m, n) for (ll i = (m); i < (n); ++i)
#define FORR(i, m, n) for (int i = (m); i >= (n); --i)
#define equals(a, b) (fabs((a) - (b)) < EPS)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
const ll mod = 1000000007;
//const ll mod = 998244353;
const int inf = 1e9 + 10;
const ll INF = 1e18;
const ld EPS = 1e-10;
const int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
const int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};
template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return 1; } return 0; }



int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout << fixed << setprecision(25);

  ll n;
  cin >> n;
  vector<ll> a(n);
  rep(i, n) cin >> a[i];

  ll f = 0;
  FOR(i, 2, n) f ^= a[i];
  ll res = a[0] + a[1];
  //cout << f << '\n';
  vector<bool> flag(61, false);
  ll cnt = 0;
  repr(i, 50) {
    if (f >> i & 1LL) {
      flag[i] = true;
      cnt += (1LL << i);
    }
  }
  if (cnt > res) {
    cout << -1 << '\n';
    return 0;
  }
  if ((res - cnt) % 2 != 0) {
    cout << -1 << '\n';
    return 0;
  }
  ll ans = (res - cnt) / 2;
  if (ans > a[0]) {
    cout << -1 << '\n';
    return 0;
  }
  repr(i, 50) {
    if (!flag[i]) continue;
    if (ans >> i & 1LL) {
      cout << -1 << '\n';
      return 0;
    }
    ans += (1LL << i);
    if (ans > a[0]) ans -= (1LL << i);
  }
  if (ans == 0) {
    cout << -1 << '\n';
    return 0;
  }
  ans = a[0] - ans;
  cout << ans << '\n';






  




  
  return 0;
}

Measured memory_bytes: 3596
N,K = (int(T) for T in input().split())
X = [int(T) for T in input().split()]
Cost = [0]*(N-K+1)
for T in range(0,N-K+1):
    Left  = X[T]
    Right = X[T+K-1]
    Cost[T] = min(abs(Left)+abs(Left-Right),abs(Right)+abs(Right-Left))
print(min(Cost))

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

int main(){
    int N,M;
    cin>>N>>M;
    vector<int> A(N),B(N),C(M),D(M);
    for (int i=0;i<N;i++){
        cin>>A.at(i)>>B.at(i);
    }
    for(int i=0;i<M;i++){
        cin>>C.at(i)>>D.at(i);
    }
    
    for(int i=0;i<N;i++){
        int min=abs(A.at(i)-C.at(0))+abs(B.at(i)-D.at(0)),minNum=1;
        for(int j=0;j<M;j++){
            if(min>abs(A.at(i)-C.at(j))+abs(B.at(i)-D.at(j))){
                min =abs(A.at(i)-C.at(j))+abs(B.at(i)-D.at(j));
                minNum = j+1;
            }
        }
        cout<<minNum<<endl;
    }
}


Measured memory_bytes: 256
#include <algorithm>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <stack>
#include <set>
#include <string>
#include <utility>
#include <vector>

using namespace std;

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

const ll M = 1e9+7;
const ll INF = 1e9+7;

ll n, m, ans;
ll a[110000];

ll binary_search(ll m) {
  ll xl = 0, xr = 1e6, x;
  while (xl < xr) {
    x = (xl+xr)/2;
    ll cnt = 0;
    for (ll i = 0; i < n; i++) {
      ll l = 0, r = n, mid;  
      while (l < r) {
        mid = (l + r) / 2;
        if (a[i] + a[mid] >= x) r = mid;
        else l = mid + 1;
      }
      cnt += n-l;
    }
    
    if (cnt <= m) {
      xr = x;
    } else {
      xl = x+1;
    }
  }
  return xl;
}

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

  for (ll i = 0; i < n; i++) {
    cin >> a[i];
  }
  sort(a, a+n);
  
  ll x = binary_search(m);
  
  ll idx = n-1;
  ll sum = 0;
  ll cnt = 0;
  for (ll i = 0; i < n; i++) {
    while (idx >= 0 and a[i] + a[idx] >= x and cnt + n - idx - 1 < m) {
      sum += a[idx];
      idx--;
    }
    ans += a[i] * (n-idx-1) + sum;
    cnt += n - idx - 1;
  }
  
  ans += (x-1) * (m - cnt);
  
  cout << ans << endl;
  return 0;
}

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

int main(void){
    int a, b, c, d, e, f, sai[6][6], n, x, y;
    cin >> a >> b >> c >> d >> e >> f;
    sai[a][b]=c;
    sai[a][c]=e;
    sai[a][d]=b;
    sai[a][e]=d;
    sai[b][a]=d;
    sai[b][c]=a;
    sai[b][d]=f;
    sai[b][f]=c;
    sai[c][a]=b;
    sai[c][b]=f;
    sai[c][e]=a;
    sai[c][f]=e;
    sai[d][a]=e;
    sai[d][b]=a;
    sai[d][e]=f;
    sai[d][f]=b;
    sai[e][a]=c;
    sai[e][c]=f;
    sai[e][d]=a;
    sai[e][f]=d;
    sai[f][b]=d;
    sai[f][c]=b;
    sai[f][d]=e;
    sai[f][e]=c;
    
    cin >> n;
    for(int i=0; i<n; i++){
        cin >> x >> y;
        cout << sai[x][y] << endl;
    }
    return 0;
}



Measured memory_bytes: 3088
from itertools import product


def main():
    """
    1 ≦ A < B ≦ 30
    1 ≦ C < D ≦ 30
    1 ≦ E ≦ 100
    100A ≦ F ≦ 3000 より
       A,B: 30回まで
       C,D: 100回まで
    """
    A, B, C, D, E, F = map(int, input().split())

    ans_w = 0
    ans_s = 0
    for a, b, c in product(range(31),
                           range(31),
                           range(101)):
        for d in range(101):
            w = (100 * A * a) + (100 * B * b)
            s = C * c + D * d

            if w == 0 or (w + s) > F:
                break

            # Sugar: Water = E: 100
            if s * 100 == w * E:
                print(w + s, s)
                return

            # Sugar: Water > E: 100 なら溶け切らない
            # s/w > E/100
            if s * 100 > E * w:
                break

            # 以前の最大濃度との比較(基準の100, Eを置き換え)
            # s: w > a_w: a_s
            if (ans_w, ans_s) == (0, 0) or \
                    s * ans_w > ans_s * w:
                ans_w, ans_s = w, s

    print(ans_w + ans_s, ans_s)

if __name__ == '__main__':
    main()


Measured memory_bytes: 3064
#include <iostream>
#include <fstream>
#include <climits>
#include <cstring>
#include <algorithm>
#include <vector>
#include <string>
#include <cmath>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <deque>
#include <cstdio>
#include <unordered_map>
#include <unordered_set>
#include <iomanip>
#include <list>

#define FOR(i,n)	for(int i = 0 ; i < n ; i++)
#define FORrev(i,n)	for(int i = n - 1 ; i >= 0 ; i--)
#define ALL(a)		a.begin(),a.end()
#define pii			pair<int , int>
#define mp(a , b)	make_pair(a , b)


typedef long long int ll; 

using namespace std;

int main() {
	int n , k;
	cin>>n>>k;
	int a[n];
	FOR(i , n)
		cin>>a[i];
	int count = 0;
	FOR(i , n)
		if(a[i] >= k)
			count++;
	cout<<count;
}

Measured memory_bytes: 640
#![allow(unused_imports)]
use proconio::{input, fastout};

fn main() {
  input! {
    n: usize,
    mut l: [usize;n]
  }
  l.sort();
   
  let mut sum = 0;
  for i in 0..n {
    for ii in i+1..n {
      let mut left = 0;
      let mut right = i;
      while left < right {
        let middle = (left + right) / 2;
        if l[ii] < l[i] + l[middle] {
          right = middle;
        } else {
          left = middle + 1;
        }
      }
      sum += i - left;
    }
  }

  println!("{}", sum);
}

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

void solve()
{
    int h, a;
    cin>>h>>a;
    if(h%a==0) cout<<h/a<<endl;
    else cout<<h/a+1<<endl;
}
int main()
{
    int t;
    t=1;
    while(t--)
    {
        solve();

    }
return 0;
}


Measured memory_bytes: 256
def f(nums, l):
  out=sum(nums[:l])
  tmp=sum(nums[:l])
  n=len(nums)
  i=2
  while i+l-1<n:
    tmp=tmp-nums[i-2]-nums[i-1]+nums[i+l-2]+nums[i+l-1]
    out=max(out, tmp)
    i+=2
  return out

N, K=map(int, input().split())
S=input()

i=0
j=1
nums=[]
while i<N:
  while j<N and S[i]==S[j]:
    j+=1
  nums.append(j-i)
  i=j
  j=i+1
  
if S[0]=='0':
  nums=[0]+nums
  
if S[-1]=='0':
  nums=nums+[0]
  
ans=f(nums, 2*K+1)
print(ans)

Measured memory_bytes: 4980
#define _USE_MATH_DEFINES
#include <cstdio>
#include <iostream>
#include <sstream>
#include <fstream>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <complex>
#include <string>
#include <vector>
#include <list>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <bitset>
#include <numeric>
#include <limits>
#include <climits>
#include <cfloat>
#include <functional>
#include <iterator>
using namespace std;

int main()
{
    int k, t;
    cin >> k >> t;
    vector<int> a(t);
    for(int i=0; i<t; ++i)
        cin >> a[i];

    sort(a.rbegin(), a.rend());
    int ans = a[0] - (k - a[0]);
    if(ans <= 0)
        ans = 0;
    else
        -- ans;
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
int main()
{
	char a[10], b[10], x[1000], y[1000], z[1000], s[1000];
	int n, i, m, i2;
	
	scanf("%d", &n);
	while (n != 0){
		for (i = 0; i < n; i++){
			scanf("%s %s", a, b);
			x[i] = a[0];
			y[i] = b[0];
		}
		scanf("%d", &m);
		for (i = 0; i < m; i++){
			scanf("%s", z);
			for (i2 = 0; i2 < n; i2++){
				if (z[0] == x[i2]){
					z[0] = y[i2];
					break;
				}
			}
			printf("%c", z[0]);
		}

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

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

int main(){
  //cout<<'z'-'a'<<endl;
  int n;
  cin>>n;
  int ch[26];
  int chmax[26];
  for(int i=0;i<26;i++){
    ch[i]=0;
  }
  for(int i=0;i<26;i++){
    chmax[i]=50;
  }
  string s[n];
  
  for (int i=0;i<n;i++){
    cin>>s[i];
    for(int j='a';j<='z';j++){
      ch[j-'a']=0;
      for(int k=0;k<s[i].length();k++){
        if(s[i].at(k)==j){
          ch[j-'a']++;
        }
      }
      chmax[j-'a']=min(chmax[j-'a'],ch[j-'a']);
    }
  }

  for(int i=0;i<26;i++){
    cout<<string(chmax[i],'a'+i);
  }
  cout<<endl;
  return 0;
}

  

Measured memory_bytes: 256
N, C, K = gets.strip.split(/ /).collect{|num| num.to_i}

if C == 1
	puts N
	exit
end

t_list = N.times.collect{
	gets.to_i
}.sort


count = 0
last_left = nil
last_time = nil
t_list.each{|t|
	if last_time && last_time >= t
		last_left -= 1
		if last_left == 0
			last_time = nil
		end
		next
	end
	count += 1
	last_time = t + K
	last_left = C - 1
}
puts count



Measured memory_bytes: 4656
#include <stdio.h>

int judge(int*, int);

int n;

int main(){
  int q, S[10001], T[500];
  int i, cnt = 0;

  scanf("%d", &n);

  
  for(i = 0; i < n; i++){
    scanf("%d", &S[i]);
  }

  scanf("%d", &q);

  for(i = 0; i < q; i++){
    scanf("%d", &T[i]);
  }

  for(i = 0; i < q; i++){
    cnt += judge(S, T[i]);
  }

  printf("%d\n", cnt);

  return 0;
  
}


int judge(int *A, int key){
  int i = 0;
  
  A[n] = key;

  while(A[i] != key) i++;
  
  if(i == n) return 0;

  return 1;
}



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

int main() {
	int n, cnt = 1;
	int arr[1005];
	cin>>n;
	for(int i = 0;i<n;i++) {
		cin>>arr[i];
	}
	sort(arr,arr+n);
	for(int i = 1;i<n;i++) {
		if(arr[i]!=arr[i-1]) {
			cnt++;
		}
	}
	cout<<cnt<<endl;
	return 0;
}

Measured memory_bytes: 256
#include <stdio.h>

int days[] = {0, 31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30};
char weeks[7][10] = {"Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"};

int main(){

  int i;
  for(i=1;i<12;i++) days[i] += days[i-1];

  int m,d;
  while(1){
    scanf("%d%d", &m, &d);
    if(m==0) break;
    
    d += days[m-1]+3;
    d %= 7;

    printf("%s\n", weeks[d]);
  }
}

Measured memory_bytes: 0
#include<bits/stdc++.h>
#define ll long long int
#define l(i,a,b) for(ll i=a;i<b;i++)
using namespace std;
int main(){
	ll a,b,n;
	cin>>a>>b>>n;
	ll value = min(b-1,n);
	
	double num = (double)(a*value/b);
	cout<<(ll)floor(num)<<"\n";
	
	
}

Measured memory_bytes: 3624
#include<stdio.h>
  
#define MAX_COUNT 10000
#define MIN_X     1
#define MAX_X     10000
  
int main(void)
{
    int x[MAX_COUNT];
    int i, j, tmp;
  
    for(i=0;i<MAX_COUNT;i++)
    {
        scanf("%d", &tmp);
 
        if(tmp == 0) break; 
        if(tmp < MIN_X || tmp > MAX_X) return -1;
  
        x[i] = tmp;
    }
  
    for(j=0;j<i;j++)
    {
        printf("Case %d: %d\n", j+1, x[j]);
    }
  
    return 0;
}


Measured memory_bytes: 2056
# coding: utf-8
import sys

n,k = map(int, input().split())
H = sorted(map(int, sys.stdin.readlines()))
ans = 10**9
for i in range(n-k+1):
    dif = H[i+k-1] - H[i]
    if dif == 0:
        print(0)
        break
    elif dif < ans:
        ans = dif
else:
    print(ans)

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

#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()

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



int main(){
	int d,g,p[11],c[11];
	cin>>d>>g;
	for (int i = 0; i < d; i++){
		cin>>p[i]>>c[i];
	}

	int ans=1e+9;
	for (int i = 0; i < (1<<d); i++){
		int s=0,num=0,res=-1;
		for (int j = 0; j < d; j++){
			if(i&(1<<j)){
				s+=100*(j+1)*p[j]+c[j];
				num+=p[j];
			}else{
				res=j;
			}
		}
		if(s<g){
			int s1=100*(res+1);
			int need=(g-s+s1-1)/s1;
			if(need>=p[res])continue;
			num+=need;
		}
		ans=min(ans,num);
	}

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

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

using namespace std;
typedef long long ll;
const int N=2e5+100;

int main()
{
   int k,n;
   int a[N];
   cin>>k>>n;
   int m=0;
   ll ans1=0;
   for(int i=1;i<=n;i++)
    scanf("%d",&a[i]);
   for(int i=1;i<n;i++){
      m=max(a[i+1]-a[i],m);
      ans1+=a[i+1]-a[i];
   }
   int ml=a[1]+k-a[n];
   if(m>ml) ans1=ans1-m+ml;
   cout<<ans1<<endl;
   return 0;
}


Measured memory_bytes: 1024
// inputに入力データ全体が入る
// 7
// zenkoku
// touitsu
// program

function Main(input) {
	// 1行目がinput[0], 2行目がinput[1], …に入る
	inputList = input.split("\n");
    inputNum = parseInt(inputList[0], 10);
    firstList = inputList[1].split("");
    secondList = inputList[2].split("");
    thirdList = inputList[3].split("");
    count = 0;
    for (var i = 0; i < inputNum; i++) {
        if(firstList[i] == secondList[i] && secondList[i] == thirdList[i]) {
            continue;
        }
        if(firstList[i] == secondList[i] || secondList[i] == thirdList[i] || thirdList[i] == firstList[i]) {
            count++;
            continue;
        }
        count++;
        count++;
    }
	console.log(count);
}
//*この行以降は編集しないでください（標準入出力から一度に読み込み、Mainを呼び出します）
Main(require("fs").readFileSync("/dev/stdin", "utf8"));

Measured memory_bytes: 21064
/*
Dont BLUNDER
*/
#include<bits/stdc++.h>
using namespace std;
/*#include <ext/pb_ds/assoc_container.hpp> // Common file
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
 
 
 */
//#define d long double
#define int long long
#define pii pair<int,int>
#define pb push_back
#define endl '\n'
#define pi acos(-1)
#define inf (int)1e18
#define init(x,a) memset(x,a,sizeof(x))
#define all(c) c.begin(),c.end()
int const mod1=998244353;
int const mod=1000000007;
#define l first
#define r second
int toint(const string &s) {stringstream ss; ss << s; int x; ss >> x; return x;}
string tostring ( int number ) {stringstream ss; ss << number; return ss.str();}
#define out(x) cout<<#x<<" = "<<" "<<x<<"\n";
#define trace1(x)                cerr<<#x<<": "<<x<<endl
#define trace2(x, y)             cerr<<#x<<": "<<x<<" | "<<#y<<": "<<y<<endl
#define trace3(x, y, z)          cerr<<#x<<":" <<x<<" | "<<#y<<": "<<y<<" | "<<#z<<": "<<z<<endl
 #define haha ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
// *** Using PBDS ***
 /*typedef tree<int, null_type, less<int>, rb_tree_tag, 
             tree_order_statistics_node_update> 
                os; */


 
int modexp(int x, int n){
	if(n==0){
		return 1;
	}
	else if(n&1){
		return (modexp((x*x)%mod, n/2)%mod * x%mod)%mod;
	}
	else{
		return (modexp((x*x)%mod, n/2)%mod);
	}
}
 
int modinv(int n)
{
	return modexp(n,mod-2);
}


signed main()
{
	int x,y;
	cin>>x>>y;
	int f=0;
	if(y-2*x<0)
	f=1;
	int a=(y-2*x)/2;
	if(a*2!=(y-2*x))
	f=1;
	int b=x-a;
	if(b<0)
	f=1;
	if(f==1)
	cout<<"No";
	else
	cout<<"Yes";


}

Measured memory_bytes: 3628
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vs = vector<string>;
using msi = map<string, int>;
using mii = map<int, int>;
using psi = pair<string, int>;
using pii = pair<int, int>;
using vlai = valarray<int>;
#define rep(i,n) for(int i=0;i<n;i++)
#define range(i,s,n) for(int i=s;i<n;i++)
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define fs first
#define sc second
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define INF 1E9
#define EPS 1E-9
#define MOD 1000000007
#define PI 3.1415926535897932384

std::ostream &operator<<(std::ostream &out, const vector<int> &tgt)
{
	string s;
	for (int i = 0; i<tgt.size(); i++) {
		s += (to_string(tgt[i]) + ((i != tgt.size() - 1) ? " " : ""));
	}
	out << s;
	return out;
}

int main() {
	string a, b;
	cin >> a >> b;
	sort(all(a));
	sort(all(b));
	reverse(all(b));
	cout << (a < b ? "Yes" : "No") << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int n,a[100001],x,res;
int main()
{
	scanf("%d",&n);
	for(int i=1;i<=n;++i)
	{
		scanf("%d",&x);
		if(x<=1e5)++a[x];
		else ++res;
	}
	for(int i=1;i<=1e5;++i)
		if(a[i])res+=a[i]>=i?a[i]-i:a[i];
	printf("%d\n",res);
	return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
//#include <atcoder/all>
#define ll long long int
#define vec vector<ll>
#define mat vector<vector<ll>>

using namespace std;
//using namespace atcoder;

const ll mod=1000000007;
const ll inf=LONG_LONG_MAX;
ll dx4[4]={1,0,-1,0};
ll dy4[4]={0,-1,0,1};
ll dx8[8]={1,0,-1,1,-1,1,0,-1};
ll dy8[8]={1,1,1,0,0,-1,-1,-1};

int main(){

  ll a,b,c,d;
  cin >> a >> b >> c >> d;
  ll x[4];
  x[0]=a*c;
  x[1]=a*d;
  x[2]=b*c;
  x[3]=b*d;
  sort(x,x+4);
  cout << x[3]  << endl;

  return 0;
}

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

int main() {
    int N;
    cin >> N;
    vector<int> s(N);
    rep(i, N) {
        char c;
        cin >> c;
        if (c == 'R') s[i] = 0;
        if (c == 'G') s[i] = 1;
        if (c == 'B') s[i] = 2;
    }

    int count[3] = {0};
    ll sum = 0;
    for (int i = N - 1; i >= 0; i--) {
        switch (s[i]) {
        case 0:
            count[0]++;
            sum += count[1] * count[2];
            break;
        case 1:
            count[1]++;
            sum += count[0] * count[2];
            break;
        case 2:
            count[2]++;
            sum += count[0] * count[1];
            break;
        }
    }
    for (int i = 0; i < N; i++) {
        for (int j = i+1; j < N; j++) {
            int k = j + j - i;
            if (k >= N) break;
            if (s[i] != s[j] && s[i] != s[k] && s[j] != s[k]) sum--;
        }   
    }
    cout << sum << endl;
    return 0;
}


Measured memory_bytes: 3584
#include<iostream>
#include<string>
#include<algorithm>
using namespace std;
int main() {
	int N; cin >> N;
	int a[114514]; for (int i = 1; i <= N; i++)cin >> a[i];
	long sum = 0;
	for (int i = 1; i <= N; i++)
		if (a[a[i]] == i)sum++;
	cout << sum / 2 << endl;
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
#define int long long
#define mod (int)(1e9+7)
#define inf (int)(3e18+7)
#define rep(i,n) for(int i=0;i<n;i++)
#define REP(i,n) for(int i=1;i<n;i++)
#define P pair<int,int>
#define PiP pair<int,pair<int,int>>
#define all(v) v.begin(),v.end()
#define mkp make_pair
#define mkt make_tuple
#define prique(T) priority_queue<T,vector<T>,greater<T>>
#define vecunique(vec) sort(vec.begin(), vec.end());decltype(vec)::iterator result = std::unique(vec.begin(), vec.end());vec.erase(result, vec.end())
using namespace std;

bool prime(int x) {
	for (int i = 2; i * i <= x; i++) {
		if (x % i == 0)return false;
	}
	return x > 1;
}
int gcd(int x, int y) {
	if (y == 0)return x;
	return gcd(y, x % y);
}
int lcm(int x, int y) {
	return x / gcd(x, y) * y;
}
int kai(int x, int y) {
	int res = 1;
	for (int i = x - y + 1; i <= x; i++) {
		res *= i; res %= mod;
	}
	return res;
}
int mod_pow(int x, int y) {
	int res = 1;
	while (y > 0) {
		if (y & 1) {
			res = res * x % mod;
		}
		x = x * x % mod;
		y >>= 1;
	}
	return res;
}
int comb(int x, int y) {
	if (y > x)return 0;
	return kai(x, y) * mod_pow(kai(y, y), mod - 2) % mod;
}
/*--------Library Zone!--------*/


signed main() {
	double w, h, x, y; cin >> w >> h >> x >> y;
	printf("%.12lf", w * h / 2);
	if (x == w / 2 && y == h / 2)cout << " 1" << endl;
	else cout << " 0" << endl;
}

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

typedef long long ll;
typedef pair<ll, ll> P;
typedef vector<ll> vll;


int main() {
    int n, m;
    cin >> n >> m;
    ll ans = 0;
    vector<int> nums(m + 1);
    int k;
    int x;
    for (int i = 0; i < n; ++i) {
        cin >> k;
        for (int j = 0; j < k; ++j) {
            cin >> x;
            nums[x]++;
        }
    }
    for (int i = 1; i <= m; ++i) {
        if (nums[i] == n) {
            ans++;
        }
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;

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

        int total = 0;
        for (int i = 0; i < n; i++) {
            total += in.nextInt();
        }

        if (total >= h) {
            System.out.println("Yes");
        } else {
            System.out.println("No");
        }
    }
}


Measured memory_bytes: 46552
#include <bits/stdc++.h>
using namespace std;
#define ll int64_t
#define ALL(a) (a).begin(), (a).end()

const ll mod = 1000000007;
const ll LINF = 1e13;
const ll LLINF = 1e18;
const ll ALPHABET = 26;

template <class T>
void Swap(T &r, T &l) {
  T tmp = r;
  r = l;
  l = tmp;
}

template <typename T>
istream &operator>>(istream &is, vector<T> &vec) {
  for (T &x : vec)
    is >> x;  // for(int i=0; i<vec.size(); i++) is >> x[i]; とかでもいい
  return is;
}

int main() {
  ll n;
  cin >> n;
  vector<string> s(n);
  cin >> s;

  for (ll i = 0; i < n; i++) {
    sort(s[i].begin(), s[i].end());
  }

  ll ans = 0;
  ll count = 1;
  sort(s.begin(),s.end(),[](const string& l,const string&  r){
      return l > r;
  });

  for (ll i = 1; i < n; i++) {
    if (s[i] == s[i-1]) {
      count++;
    } else {
      if (count > 1) {
        for (ll j = 1; j < count; j++) {
          ans += j;
        }
      }
      count = 1;
    }
    cerr << s[i] <<count <<endl;
  }

        if (count > 1) {
        for (ll j = 1; j < count; j++) {
          ans += j;
        }
      }

  cout << ans;



  //   vector<pair<string, vector<ll>>> sp(n);
  //   for (ll i = 0; i < n; i++) {
  //     vector<ll> alph(27, 0);
  //     for (ll j = 0; j < 10; j++) {
  //       alph[s[i][j] - 'a']++;
  //     }
  //     sp[i] = make_pair(s[i], alph);
  //   }

  //   sort(
  //       sp.begin(), sp.end(),
  //       [](const pair<string, vector<ll>> &l, const pair<string, vector<ll>>
  //       &r) {
  //         bool ret = false;
  //         for (ll i = 0; i < 27; i++) {
  //           if (l.second[i] > r.second[i]) {
  //             ret = true;
  //             cerr << "swap" << i<< endl;
  //             break;
  //           }
  //         }

  //         return ret;
  //       });

  //     for (ll i = 0; i < n; i++) {
  //         cerr << sp[i].first <<endl;
  //         cerr << sp[i].second[0] <<endl;
  //     }

  // //   ll ans = 0;
  // //   ll count = 1;

  // //   for (ll i = 1; i < n; i++) {
  // //     bool tmp = true;
  // //     for (ll j = 0; j < 27; j++) {
  // //       if (sp[i].second[j] != sp[i - 1].second[j]) tmp = false;
  // //     }
  // //     if (tmp == true) {
  // //       count++;
  // //     } else {
  // //       if (count > 1) {
  // //         for (ll j = 1; j < count; j++) {
  // //           ans += j;
  // //         }
  // //       }
  // //       count = 1;
  // //     }
  // //     // cerr << sp[i].first <<count <<endl;
  // //   }

  //   cout << ans;
}

Measured memory_bytes: 7296
X,N = map(int,input().split())
p = list(map(int,input().split()))

i = 0
j = 0
flag = 0
while True:
    if(X - i in p):
        i += 1
    else:
        flag = 1
        break
    if(X + j in p):
        j += 1
    else:
        flag = 2
        break
if(flag == 1):
    print(X - i)
elif(flag == 2):
    print(X + j)

Measured memory_bytes: 9140
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.HashMap;

public class Main {

	public static void main(String[] args) throws IOException {
		// TODO ?????????????????????????????????????????????
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		
		while(true){
			String input = br.readLine();

			if(input == null){
				break;
			}
			Translator tr = new Translator();
			Solver sv = new Solver();

			System.out.println(sv.generateString(tr.genelrateBits(input)));
		}
	}

}

class Translator {
	private String[] code = new String[256];

	public Translator(){
		code[' '] = "101";
		code['\''] = "000000";
		code[','] = "000011";
		code['-'] = "10010001";
		code['.'] = "010001";
		code['?'] = "000001";
		code['A'] = "100101";
		code['B'] = "10011010";
		code['C'] = "0101";
		code['D'] = "0001";
		code['E'] = "110";
		code['F'] = "01001";
		code['G'] = "10011011";
		code['H'] = "010000";
		code['I'] = "0111";
		code['J'] = "10011000";
		code['K'] = "0110";
		code['L'] = "00100";
		code['M'] = "10011001";
		code['N'] = "10011110";
		code['O'] = "00101";
		code['P'] = "111";
		code['Q'] = "10011111";
		code['R'] = "1000";
		code['S'] = "00110";
		code['T'] = "00111";
		code['U'] = "10011100";
		code['V'] = "10011101";
		code['W'] = "000010";
		code['X'] = "10010010";
		code['Y'] = "10010011";
		code['Z'] = "10010000";
		
	}
	
	public String genelrateBits(String input){
		StringBuffer sb = new StringBuffer();
		for(int i = 0; i < input.length(); i++){
			sb.append(code[input.charAt(i)]);
		}
		//0??????
		while(sb.length()%5 != 0){
			sb.append("0");
		}
		return sb.toString();
	}
}

class Solver{
	HashMap<String, String> map = new HashMap<String, String>();
	
	public Solver(){
		map.put("00000", "A");
		map.put("00001", "B");
		map.put("00010", "C");
		map.put("00011", "D");
		map.put("00100", "E");
		map.put("00101", "F");
		map.put("00110", "G");
		map.put("00111", "H");
		map.put("01000", "I");
		map.put("01001", "J");
		map.put("01010", "K");
		map.put("01011", "L");
		map.put("01100", "M");
		map.put("01101", "N");
		map.put("01110", "O");
		map.put("01111", "P");
		map.put("10000", "Q");
		map.put("10001", "R");
		map.put("10010", "S");
		map.put("10011", "T");
		map.put("10100", "U");
		map.put("10101", "V");
		map.put("10110", "W");
		map.put("10111", "X");
		map.put("11000", "Y");
		map.put("11001", "Z");
		map.put("11010", " ");
		map.put("11011", ".");
		map.put("11100", ",");
		map.put("11101", "-");
		map.put("11110", "'");
		map.put("11111", "?");
	}
	
	public String generateString(String bits){
		int n = bits.length()/5;
		
		StringBuffer sb = new StringBuffer();
		for(int i = 0; i < n; i++){
			sb.append(map.get(bits.substring(i*5, i*5+5)));
		}
		
		return sb.toString();
	}
}

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

int main() {
  int N;
  int count = 0;
  cin >> N;
  for (int i=0;i<N;i++){
    int l,r;
    cin >> l >> r;
    count += (r-l+1);
  }
  cout << count << endl;
}



Measured memory_bytes: 256
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,sse3,sse4,popcnt,abm,mmx")
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define pb push_back
#define F first
#define S second
#define ins insert
#define mp make_pair
#define fo(i, n1, n, x) for(int i = n1; i <= n; i += x)
#define foo(i, n, n1, x) for(int i = n; i >= n1; i -= x)
#define bit __builtin_popcount
#define md (l + ((r - l) / 2))
#define all(x) x.begin(),x.end()
#define eb emplace_back
#define ub upper_bound
#define lb lower_bound
#define ios ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define file(s) if (fopen(s".in", "r")) freopen(s".in", "r", stdin), freopen(s".out", "w", stdout)

using namespace std;
using namespace __gnu_pbds;

typedef long long ll;
typedef long double ld;

const int N = 2e5 + 11, mod = 1e9 + 7, mod2 = 998244353;
const int MAX = 3e5 + 11;
const int INF1 = 2e9 + 11;
const ll INF2 = 2e18 + 11;
const double INF3 = 1e8 + 11;
const int base = 500;
const int P = 31;
const int dx[] = {1, -1, 0, 0, 1, 1, -1, -1};
const int dy[] = {0, 0, 1, -1, 1, -1, 1, -1};
const double EPS = 1e-6;
const double PI = acos(-1.0);

#define int ll

template<typename T> using ordered_set = tree <T, null_type, less <T>, rb_tree_tag, tree_order_statistics_node_update>;
template<typename T1, typename T2> inline void chmin(T1 &a, T2 b) { if (a > b) a = b; }
template<typename T1, typename T2> inline void chmax(T1 &a, T2 b) { if (a < b) a = b; }


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

mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

string s,t;
int n,m,ans;
vector <int> v[33];
main() {
    file("walk");
    //ios;
    cin>>s>>t;
    n=s.size();
    m=t.size();
    s='#'+s;
    t='#'+t;
    int cur=0;
    fo(i,1,n,1) {
        int num=(s[i]-'a');
        v[num].eb(i);
    }
    fo(i,1,m,1) {
        int num=t[i]-'a';
        if (v[num].empty()) return !(cout<<-1);
        auto it=ub(all(v[num]),cur);
        if (it!=v[num].end() and s[*it]==t[i]) {
            ans+=*it-cur;
            cur=*it;
        } else {
            int id=v[num][0];
            if (s[id]==t[i]) {
                ans+=n-cur+id;
                cur=id;
            } else return !(cout<<-1);
        }
    }
    cout<<ans;
    return 0;
}
/**

*/


Measured memory_bytes: 1628
#pragma GCC optimize ("O3")
#pragma GCC target ("sse4")

#include <bits/stdc++.h>
using namespace std;

using ii = pair<int,int>;
using ll = long long;

const int N = 2e3 + 5;
const int mod = 998244353;

/*
 * thinking about it
 * if dist(u,v) > k they can't be in the same graph
 * however if dist(u,v) <= k they can be in the same graph
 * so now it just becomes a problem of finding the maximal clique
 * in a graph where there is an edge between u and v if dist(u,v) <= k
 * one problem NP-Complete :"D this is an O(2 ^ N)
 * lol a really easier solution would be to try all the diameters then
 * choose all nodes with max(dist[u][x], dist[v][x]) <= k
 * so let's iterate on all nodes u and get nodes where dist[u][x] <= k
 * now iterate over them i need to know which nodes in the list have
 * distance > k this an O(N^3) solution
 * so now i have Set(u) and Set(v) i have to find the maximum SetIntersection
 * i can speed it up to O(N^3/32) using BIT Sets let's try it XD
 */

bitset<2005> bt[N];
vector<int>adj[N];
vector<int>to[N];
int cnt = 0;
void dfs(int u, int p, int master, int lft){
	cnt++;
	bt[master][u] = 1;
	if(lft == 0){
		to[master].push_back(u);
		return;
	}
	for(auto v : adj[u])
		if(v != p)
			dfs(v,u,master,lft-1);
}
int main() {
#ifdef ONLINE_JUDGE
	ios_base::sync_with_stdio(0);
	cin.tie(0);
#endif

	int n, k;
	cin >> n >> k;

	for(int i = 1, u, v; i < n; i++){
		cin >> u >> v;
		adj[u].push_back(v);
		adj[v].push_back(u);
	}
	int mn = n;
	for(int i = 1; i <= n; i++){
		cnt = 0;
		dfs(i,i,i,k);
		mn = min(mn,cnt);
	}

	if(mn == n){
		cout << 0 << '\n';
		return 0;
	}

	int ans = 0;
	for(int i = 1; i <= n; i++)
		for(auto j : to[i])if(i < j){
//			cout << i << ' ' << j << ' ' << ((bt[i]&bt[j]).count()) << '\n';
			ans = max(ans,(int) (bt[i]&bt[j]).count());
		}
	cout << n-ans << '\n';



	return 0;
}


Measured memory_bytes: 16896
#include "bits/stdc++.h"
using namespace std;

/*
int imp_A(int);
int imp_B(int, int);
*/

int main(void) {
    int N, K;
    cin >> N >> K;
    int start = 1;
    std::vector<int> vec;

    if (K <= 0) {
        cout << 1 + (N * K) << endl;
    } else {
        // N が1以上、Kが正の数
        for (int i = 0; i <= N; i++) {
            int num = 1;
            num = pow(2, i) + (K * (N-i));
            vec.push_back(num);
        }
        int min = *std::min_element(vec.begin(), vec.end());
        std::cout << min << endl;
    }
    
    return 0;
}

/*
int imp_A(int num) {
    return num * 2;
}

int imp_B(int num, int K) {
    return num + K;
}
*/


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

using namespace std;

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

    int a[n];
    fill(a, a + n, k);

    for (int i = 0; i < q; ++i) {
        int x;
        cin >> x;

        ++a[x-1];
    }

    for (int i = 0; i < n; ++i) {
        a[i] -= q;
        if (a[i] <= 0) {
            cout << "No" << "\n";
        } else {
            cout << "Yes" << "\n";
        }
    }

}


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

using namespace std;
#define _GLIBCXX_DEBUG
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using ll = long long;
#define rep2(i, s, n) for (int i = (s); i < (int)(n); i++)
#define rep3(i, n) for (int i = 1; i < (int)(n+1); i++)
#define stlen(s) ll s.size()-1
#define all(v) v.begin(), v.end()
int main() {
const ll INF = 100100100100100100;
int N,K;
cin>>N>>K;
vector<int> sunuke(N+1,0);
int A,d;
rep3(i,K){
  cin>>d;
  rep(j,d){
    cin >> A;
    sunuke[A] ++;

  }
}
int count =0;
rep3(i,N){
  if(sunuke[i]==0){
    count++;
  }
}
cout<<count<<endl;
}


Measured memory_bytes: 3580
#include <iostream>
using namespace std;
int main(void){
    int N, i;
    double S = 0, result = 0;
    
    cin >> N;
    
    double A[N];
    
    for(int i = 0; i < N; i++){
        cin >> A[i];
    }
    
    for(i = 0; i < N; i++){
        S += 1 / A[i];
    }
    
    result = 1 / S;
    
    cout << result;
    
    return 0;
    
}


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

using namespace std;

int main()
{

    long long int n, i, j, k, r = 0, g = 0, b = 0, cont=0;

    cin >> n;


    string s;

    cin>>s;
    for(i=0;i<n;i++)
    {
        if(s[i]=='R')
            r++;
        else if(s[i]=='G')
            g++;
        else
            b++;
    }

    //cout<<"Hello"<<endl;
    cont=r*g*b;

    for(i=0;i<n-2;i++)
    {
        for(j=i+1;j<n-1;j++)
        {
            k=2*j-i;
            if(k<n)
            {
                if((s[i] != s[j]) && (s[j] != s[k]) && (s[k] != s[i]))
                {
                    cont--;
                }
            }

        }
    }

    cout << cont << endl;

    return 0;
}


Measured memory_bytes: 3644
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <queue>
#include <cstring>
#include <vector>
#include <map>
#include <algorithm>
#include <cctype>
#include <cmath>
#include <bitset>
#include <set>
using namespace std;

#define REP(i,n) for(int i=0;i<(int)(n);i++)
#define RREP(i,n) for(int i=n-1;i>=0;i--)
#define FOR(i,k,n) for(int i=(k);i<(int)(n);i++)
#define all(i,n) (i),(i+n)

int dx4[4]={1,0,-1,0};
int dy4[4]={0,-1,0,1};
int dx8[8]={1,0,-1,1,-1,1,0,-1};
int dy8[8]={1,1,1,0,0,-1,-1,-1};

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

const int INF = 1e9;
const ll LLINF = 1e18;
const int MAX_V = 1e6+1;
const ll mod = 1000000007;

// --------------------------------------
int n;
vector<string> s;
int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);

  cin >> n;
  REP(i, n) {
    string ss;
    cin >> ss;
    sort(ss.begin(), ss.end());
    s.push_back(ss);
  }

  string ss = s[0];

  FOR(i, 1, n) {
    int sl = ss.length();
    string sss = "";
    vector<bool> f(sl, true);
    REP(j, sl) {
      REP(k, s[i].length()) {
        if(ss[j] == s[i][k] && f[k]) {
          sss.push_back(ss[j]);
          f[k] = false;
          break;
        }
      }
    }
    ss = sss;
  }

  cout << ss << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define sz(x) int(x.size())
#define show(x) {for(auto i: x){cout << i << " ";} cout << endl;}
using namespace std;
using ll = long long;
using P = pair<int, int>;

const ll INF = 1e9;
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};

int main() {
  int H, W;
  cin >> H >> W;
  vector<string> S(H);  // 0-indexed
  rep(i, H) cin >> S[i];
  int ans = 0;  
  rep(si, H) rep(sj, W) {
    if (S[si][sj] == '#') continue;
    vector<vector<int>> dist(H, vector<int>(W, INF));
    queue<P> que;
    auto update = [&] (int i, int j, int x) {
      if (dist[i][j] != INF) return;
      dist[i][j] = x;
      que.push(P(i, j));
    };
    update(si, sj, 0);
    while (!que.empty()) {
      int ci = que.front().first;
      int cj = que.front().second; que.pop();
      int cx = dist[ci][cj];
      for (int k = 0; k < 4; k++) {
        int ni = ci + dx[k];
        int nj = cj + dy[k];
        if (0<=ni && ni<H && 0<=nj && nj<W && (S[ni][nj] != '#')) {
          update(ni, nj, cx+1);
        }
      }
    }
    rep(i, H) rep(j, W) {
      if (dist[i][j] == INF) continue;
      ans = max(ans, dist[i][j]);
    }
  }
  cout << ans << '\n';
  return 0;
}



Measured memory_bytes: 3644
import java.util.*;
 interface aisatu{
	final String str="こんにちは";
	void mesod();
}

public class Main {
	static public void main(String args[]){
		Scanner sc=new Scanner(System.in);
		
		int n=sc.nextInt();
		long aa=1L;
		for(int i=0;i<n;i++){
			long a=sc.nextLong();
			if(Math.log10(a)+Math.log10(aa)>18||
			aa*a>1000000000000000000L){
			   //1000000000000000000L
				aa=-1;
			}
			else if(a==0){
				aa*=0;
			}
			else if(aa!=-1){
				aa*=a;
			}
		}
		System.out.println(aa);
	}
}



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

int ans[4] = {0};
int a, b, c;
vector<int> v;

int main() {
  while(1) {
    cin >> a >> b >> c;
    v.push_back(a);
    v.push_back(b);
    v.push_back(c);
    sort(v.begin(), v.end());
    if(v[0] + v[1] <= v[2]) break;
    ++ans[0];
    a = v[0] * v[0] + v[1] * v[1];
    b = v[2] * v[2];
    if(a == b)
      ++ans[1];
    else if(a > b)
      ++ans[2];
    else
      ++ans[3];
    v.erase(v.begin(), v.end());
  }
  cout << ans[0] << " " << ans[1] << " " << ans[2] << " "
       << ans[3] << endl;
  return 0;
}


Measured memory_bytes: 3120
#include <iostream>
#include <algorithm>
#include <cassert>
#include <cctype>
#include <complex>
#include <cstdio>
#include <map>
#include <math.h>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
using namespace std;

int n,a,b;

int gcd(int a,int b){
	if(!b)return a;
	else return gcd(b,a%b);
}

int main(){
	while(cin>>n>>a>>b&&n){
		set<int> s;
		int d=gcd(a,b),m=a*b/d;
		for(int i=0;i<=m/a;i++)for(int j=0;j<=m/b;j++){
			if(i*a+j*b&&i*a+j*b<=m)s.insert(i*a+j*b);
		}
		if(n>=m)cout<<n-n/d+m/d-s.size()<<endl;
		else{
			set<int>::iterator ite;
			int ans=n;
			for(ite=s.begin();ite!=s.end();ite++)if(*ite<=n)ans--;
			cout<<ans<<endl;
		}
	}
}

Measured memory_bytes: 12000