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

#define int long long
#define pb push_back
#define ins insert
#define pii pair<int,int>
#define fs first
#define sc second
#define mpr make_pair
#define iter iterator
#define all(X) X.begin(),X.end()
#define sau(X) sort(all(X)),X.resize(unique(all(X))-X.begin())
#define exist(X,ele) binary_search(all(X),ele)
#define y0 I_love_Ryougi_Shiki_0
#define y1 I_love_Ryougi_Shiki_1

template<typename T1,typename T2>
ostream& operator << (ostream& out,const pair<T1,T2>& X)
{
	out<<"{"<<X.fs<<","<<X.sc<<"}";
	return out;
}

template<typename T>
ostream& operator << (ostream& out,const vector<T>& X)
{
	for(auto i:X) out<<i<<" ";
	return out;
}

template<typename T>
inline void cmin(T& x,T y)
{
	if(!(x<y)) x=y;
}

template<typename T>
inline void cmax(T& x,T y)
{
	if(x<y) x=y;
}

const int inf=5000000000000000ll;

int N,E,T;
int a[100010];
int dp[100010];

main()
{
	ios::sync_with_stdio(false);
	
	cin>>N>>E>>T;
	for(int i=1;i<=N;i++)
	{
		cin>>a[i];
	}
	int mint=inf,pos=0;
	for(int i=1;i<=N;i++)
	{
		while(2*(a[i]-a[pos+1])>=T)
		{
			cmin(mint,dp[pos]-2*a[pos+1]);
			pos++;
		}
		dp[i]=mint+2*a[i];
		if(pos!=i) cmin(dp[i],dp[pos]+T);
		
//		cout<<i<<" : "<<pos<<" "<<dp[i]<<endl;
	}
	cout<<dp[N]+E<<endl;
	
	return 0;
}





















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

using namespace std;

int main(){
	while(true){
		int n; cin >> n;
		if(n==0)break;

		vector<int> j(n);
		for(int i = 0; i < n; ++i)cin >> j[i];
		sort(j.begin(), j.end());
		int ans = 0;
		for(int i = 1; i < n-1; ++i){
			ans += j[i];
		}
		ans /= j.size()-2;
		cout << ans << endl;
	}
	return 0;
}

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

#define _GLIBCXX_DEBUG
#define all(v) (v).begin(),(v).end()

using namespace std;

using ll=long long;
using pii=pair<int, int>;
using vi=vector<int>;

const ll LINF=1LL<<60;
const int INF=1<<29;
const ll MOD=1e9+7;

template <typename T>
vector<T> divisor(T n){
    vector<T> ret;
    for(T i=2; i*i<=n; i++){
        if(n%i == 0){
            if(i*i == n) ret.push_back(i);
            else{
                ret.push_back(i);
                ret.push_back(n/i);
            }
        }
    }
    if(n != 1) ret.push_back(n);
    return ret;
}


int main(){
    ll N; cin >> N;
    vector<ll> d1, d2;
    d1=divisor(N);
    d2=divisor(N-1);
    ll res=0;
    for(int i=0; i<(int)d1.size(); i++){
        ll num=N;
        while(num%d1[i] == 0){
            num/=d1[i];
        }
        if(num%d1[i] == 1) res++;
    }
    res+=(int)d2.size();
    cout << res << endl;
    return 0;
}

Measured memory_bytes: 3636
package main

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

const size = 1000000

var reader = bufio.NewReaderSize(os.Stdin, size)

func nextLine() string {
	var line, buffer []byte
	isPrefix := true
	var err error
	for isPrefix {
		line, isPrefix, err = reader.ReadLine()
		if err != nil {
			panic(err)
		}
		buffer = append(buffer, line...)
	}
	return string(buffer)
}
func nextStringArray() []string {
	return strings.Split(nextLine(), " ")
}
func nextIntArray() []int {
	s := strings.Split(nextLine(), " ")
	n := len(s)
	a := make([]int, n)
	for i := 0; i < n; i++ {
		a[i], _ = strconv.Atoi(s[i])
	}
	return a
}

func main() {
	n, _ := strconv.Atoi(nextLine())

	// 0 1 2 3 4 5 6 7 8 9 10 11 12
	// 0 1 2 3 4 5 1 2 3 1  2  3  2
	dp := make([]int, n+1)
	for i := range dp {
		dp[i] = n
	}
	dp[0] = 0

	for i := 1; i <= n; i++ {
		dp[i] = min(dp[i], dp[i-1]+1)
		for j := 1; j < 9; j++ {
			if pow6 := int(math.Pow(6, float64(j))); i-pow6 >= 0 {
				dp[i] = min(dp[i], dp[i-pow6]+1)
			}

			if pow9 := int(math.Pow(9, float64(j))); i-pow9 >= 0 {
				dp[i] = min(dp[i], dp[i-pow9]+1)
			}
		}
	}
	fmt.Println(dp[n])
}

func min(i, j int) int {
	if i > j {
		return j
	}
	return i
}


Measured memory_bytes: 1408
#include <iostream>
#include <string>
using namespace std;
int main(){
    string s; cin >> s;
    int ans = 0;
    int tmp = 0;
    for(int i = 0; i < s.size(); i++){
        if(s[i] == 'A' || s[i] == 'C' || s[i] == 'G' || s[i] == 'T'){
            tmp++;
        }
        else{
            ans = max(ans, tmp);
            tmp = 0;
        }
    }
    cout << max(ans,tmp) << endl;
    return 0;
}

Measured memory_bytes: 256
def main():
    n = int(input())
    hts = list(map(int,input().split()))
    if n == 2:
        print(abs(hts[0]-hts[1]))
        return
    
    dp = [float('inf')]*n
    dp[0] = 0
    dp[1] = abs(hts[1]-hts[0])
##    for i in range(1,k):
##        dp[i]

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

    #print(dp)

    print(dp[-1])

main()


Measured memory_bytes: 13928
// Example program
#include <iostream>
#include <math.h>
#include <string>
using namespace std;
int main()
{
int x,a,b;
  cin>>x>>a>>b;
  if(abs(x-a)>abs(x-b)){
       cout<<"B";
       }
    else{
           cout<<"A";
           }
}


Measured memory_bytes: 256
#include <cstdio>
#include <iostream>
#include <cstring>
#include <algorithm>
#include <cmath>
using namespace std;

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


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define REP(i,n) for(int i=0;i<n;i++)
#define LOOP(i,x,n) for(int i=x;i<n;i++)
#define ALL(v) (v).begin(),(v).end()
#define PB push_back
#define MP make_pair
#define FIR first
#define SEC second
#define int long long
using namespace std;
const int MOD=1000000007;
const int INF=1000000009;

signed main(){
  int n;
  cin>>n;
  int N=3*n;

  vector<int> a(N);
  REP(i,N)cin>>a[i];
  sort(ALL(a));
  int sum=0;
  for(int i=N-1;i>n;i--){
    sum+=a[i-1];
    i--;
  }
  cout<<sum<<endl;
  return 0;
}


Measured memory_bytes: 2560
#include <bits/stdc++.h>
 
using namespace std;
 
#define ll long long int
 
#define REP(i, n) for(int i = 0; i < (n); i++)
#define SREP(i, s) for(int i = 0; i < (s.size()); i++)
#define SORT(v, n) sort(v, v+n);
#define GSORT(v, n) sort(v, v+n, greater<int>());
#define VSORT(v) sort(v.begin(),v.end());
#define VGSORT(v) sort(v.begin(),v.end(),greater<int>());
#define REV(a) reverse(begin(a),end(a));

int main(){
	ios::sync_with_stdio(false);cin.tie(0);
////////////////////////////////////////////
	int h,w;
	cin >> h >> w;
	string s[h];
	int t[h][w]={};
	REP(i,h) cin >> s[i];
	int dx[8]={-1, 0, 1, 1, 1, 0,-1,-1};
	int dy[8]={-1,-1,-1, 0, 1, 1, 1, 0};
	REP(i,h){
		REP(j,w){
			if(s[i][j]=='#') continue;
			if(s[i][j]=='.'){
				REP(k,8){
					int ni=i+dx[k];
					int nj=j+dy[k];
					if(ni<0||ni>=h) continue;
					if(nj<0||nj>=w) continue;
					if(s[i+dx[k]][j+dy[k]]=='#') t[i][j]++;
				}
			}
		}
	}
	REP(i,h){
		REP(j,w){
			if(s[i][j]=='#'){
				cout << '#';
			}else{
				cout << t[i][j];
			}
		}
		cout << endl;
	}
//////////////////////////////////////////////
}


Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main(void){
    // Your code here!
   int A, B, C, D, P;
   cin >> A >> B >> C >> D >> P;
   //x
   int x = A * P;
   
   //y
   int y;
   if(P <= C) y = B;
   else y = B + D * (P - C);
   
   if(x > y) cout << y << endl;
   else cout << x << endl;
}



Measured memory_bytes: 3012
MOD=10**9+7
cnt=0; sum=0; prev=nil; can=true; h=Hash.new(0)
def gs() gets.chomp end
def gi() gets.to_i end
def gsmi() gets.chomp.split.map(&:to_i) end

def desc(ar) ar.sort!{|x,y|y<=>x} end
def min(a,b) a<=b ? a : b end
def max(a,b) a>=b ? a : b end
def sum(ar) ar.inject(:+) end

def C(a,b) b==0||a==b ? 1 : (b=a-b if a/2<b;(a-b+1..a).inject(:*)/(1..b).inject(:*)) end

def puts_yesno(can) puts(can ? 'Yes' : 'No') end
def putsend(s) puts s; exit end
def debug(k,v) puts "#{k}:#{v}" end
########### ( ˘ω˘ )ｽﾔｧ… ###########
n=gi
a=n.times.map{gi}

ms=a.max(2)

n.times do |i|
  puts a[i]==ms[0] ? ms[1] : ms[0]
end

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

#define ll long long int
#define pb push_back
#define mk make_pair
#define pq priority_queue

using namespace std;
typedef pair<int, int> P;
typedef pair<ll, int> Pl;
typedef pair<ll, ll> Pll;
const int inf = 1e9;
const ll linf = 1LL << 50;
set<string> st;

int main(int argc, char const* argv[])
{
  string s;
  int n;
  cin >> n;
  cin >> s;
  st.insert(s);
  for(int i = 0; i < n - 1; i++){
    string ss;
    cin >> ss;
    if(st.find(ss) != st.end() || s[s.size()-1] != ss[0]){
      cout << "No" << endl;
      return 0;
    }
    st.insert(ss);
    s = ss;
  }
  cout << "Yes" << endl;
	return 0;
}


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

struct Node {
  int parent, left, right;
};
int pos = 0;
vector<int> pre, in, post;

void reconst(int l, int r) {
  if (l >= r) return;
  int c = pre[pos++];
  int m = distance(in.begin(), find(in.begin(), in.end(), c));
  reconst(l, m);
  reconst(m+1, r);
  post.push_back(c);
}

int main() {
  int n;
  cin >> n;
  int val;
  for (int i = 0; i < n; i++) {
    cin >> val;
    pre.push_back(val);
  }
  for (int i = 0; i < n; i++) {
    cin >> val;
    in.push_back(val);
  }
  reconst(0, n);
  for (int i = 0; i < n; i++) {
    if(i) cout << " ";
    cout << post[i];
  }
  cout << endl;
  return 0;
}



Measured memory_bytes: 3168
n = int(input())
a = [int(input()) for i in range(n)]
a = a[::-1]

from bisect import bisect_left, bisect_right

def lis(a):
    length = [a[0]]
    for i in range(1, len(a)):
        if a[i] >= length[-1]:
            length.append(a[i])
        else:
            length[bisect_right(length, a[i])] = a[i]
    return len(length)


print(lis(a))

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

int gcd[201][201][201];
int gcd_(int a,int b){
   int tmp,r;
	  /* ���R�� a > b ���m�F�E���� */
  if(a<b){
    tmp = a;
    a = b;
    b = tmp;
  }
 
  /* ���[�N���b�h�̌ݏ��@ */
  r = a % b;
  while(r!=0){
    a = b;
    b = r;
    r = a % b;
  }
  return b;
}
	
	
int main(){

	int   i,j,k,z;
	int  N;
	long sum1=0,sum2=0;
	scanf("%d",&N);
	int m,n,o;
	for(i=1;i<=N;i++){
		for(j=1;j<=N;j++){
			for(k=1;k<=N;k++){
				if(gcd[i][j][k]==0){
					z=gcd_(j,k);
					gcd[i][j][k]=gcd_(i,z);
					//printf("%d,%d,%d:%d// ",i,j,k,gcd[i][j][k]);
					if(i==j&&j==k)sum2+=gcd[i][j][k];
					else{
						sum1+=gcd[i][j][k];
						gcd[i][k][j]=gcd[i][j][k];
						gcd[j][i][k]=gcd[i][j][k];
						gcd[j][k][i]=gcd[i][j][k];
						gcd[k][i][j]=gcd[i][j][k];
						gcd[k][j][i]=gcd[i][j][k];
					}
				}
				else {
					sum1+=gcd[i][j][k];
					//printf("%d,%d,%d:%d// ",i,j,k,gcd[i][j][k]);
				}
			}
		}
	}
	
	printf("%ld\n",sum1+sum2);
}

Measured memory_bytes: 33244
<?php
define("MOD", 10**9+7);
fscanf(STDIN, "%d%d", $N, $K);
for($i = 0; $i < $N-1; $i++){
  fscanf(STDIN, "%d%d", $f, $t);
  $map[$f][] = $t;
  $map[$t][] = $f;
}
$done = [];
$product = 1;
dfs(1, $K, 0, 0);
printf("%d", $product % MOD);
function dfs($from, $color, $depth, $i){
  global $map, $done, $product;
  $done[$from] = true;
  $product *= $color-min($depth,2)-$i;
  $product %= MOD;
  $j = 0;
  foreach($map[$from] as $to){
    if(isset($done[$to]))continue;
    dfs($to, $color, $depth+1, $j);
    $j++;
  }
}


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

using namespace std;

#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define FOR(i, a, b) for(int i=(a);i<(b);i++)
#define REP(i, n) FOR(i, 0, n)
#define RFOR(i, a, b) for(int i=(a);i>=(b);i--)
#define RREP(i, n) RFOR(i, n, 0)
#define MFOR(i, m) for(auto i=(m).begin();i!=(m).end();i++)
#define ALL(a) (a).begin(), (a).end()
#define SZ(x) ((int)(x).size())

typedef long long int ll;
typedef pair<int, int> P;
typedef pair<ll, ll> Pll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vll;
typedef vector<vll> vvll;

const double eps = 1e-10;
const int MOD = 1000000007;
const int INF = 1000000000;
const ll LINF = 1 << 30;

template<typename T>
void printv(vector<T> const& s) {
  REP(i, SZ(s)) {
    cout << s[i] << " ";
  }
  cout << endl;
}

int main () {
  cin.tie(0);
  cout << setprecision(10);
  map<string, int> m;
  m["Vacant"] = -1;

  int n; cin >> n;
  cout << 0 << endl;
  string s0; cin >> s0;
  if(s0 == "Vacant") {
    return 0;
  } else if(s0 == "Male") {
    m["Male"] = 0;
    m["Female"] = 1;
  } else {
    m["Female"] = 0;
    m["Male"] = 1;
  }

  int l = 1, r = n;
  while(1) {
    int mid = (l+r)/2;
    cout << mid << endl;
    string res; cin >> res;
    if(m[res] == -1) {
      return 0;
    } else if(m[res] == mid % 2) {
      l = mid;
    } else {
      r = mid;
    }
  }
}


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

int main() {
    int n;
    cin >> n;
    vector<int> a(n);
    vector<int64_t> b(n);
    
    for(int i = 0; i<n; i++){
        cin >> a.at(i);
    }
    
    int64_t ans_1 = 0;
    int64_t ans_2 = 0;
    
    b.at(0)=a.at(0);
    if (b.at(0) <= 0){
        ans_1 += 1-b.at(0);
        b.at(0)=1;
    }
        
    for(int i=1; i<n; i++){
        b.at(i) = b.at(i-1) + a.at(i);
        if ((i%2)==1){
            if (b.at(i)>=0){
                ans_1 += 1+b.at(i);
                b.at(i)= -1;
            }
        }
        else{
            if (b.at(i)<=0){
                ans_1 += 1-b.at(i);
                b.at(i)=1;
            }
        }
    }
    
    b.at(0)=a.at(0);
    if (b.at(0) >= 0){
        ans_2 += 1+b.at(0);
        b.at(0)=-1;
    }
        
    for(int i=1; i<n; i++){
        b.at(i) = b.at(i-1) + a.at(i);
        if ((i%2)==1){
            if (b.at(i)<=0){
                ans_2 += 1-b.at(i);
                b.at(i)= 1;
            }
        }
        else{
            if (b.at(i)>=0){
                ans_2 += 1+b.at(i);
                b.at(i)=-1;
            }
        }
    }
    cout << min(ans_1, ans_2) << endl;
}


Measured memory_bytes: 1408
#include <cctype>
#include <cerrno>
#include <cfloat>
#include <ciso646>
#include <climits>
#include <clocale>
#include <cmath>
#include <csetjmp>
#include <csignal>
#include <cstdarg>
#include <cstddef>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>

#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>
#include <regex>
#define rep(i,n) for(int i = 0; i < n; i++)
#define reps(i,j,n) for(int i = j; i < n; i++)
#define rrep(i,j,n) for(int i = j-1; i >= n; i--)
#define prec(n) fixed << setprecision(n)
#define print_array(v) rep(__k, v.size()) { cout << v[__k]; if(__k != v.size()-1) cout << " "; else cout << endl; }
#define YesorNo(a) printf(a?"Yes\n":"No\n")
#define fi first
#define se second
using namespace std;

int inf = 2147483647;
int64_t inf64 = 9223372036854775807;
int mod = 1e+7;

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

  string s;
  cin >> s;

  int cnt1 = 0;
  rep(i,s.size()) {
    if(i % 2 == 0 && s[i] == '1') cnt1++;
    if(i % 2 == 1 && s[i] == '0') cnt1++;
  }
  int cnt2 = 0;
  rep(i,s.size()) {
    if(i % 2 == 0 && s[i] == '0') cnt2++;
    if(i % 2 == 1 && s[i] == '1') cnt2++;
  }
  cout << min(cnt1, cnt2) << endl;
  return 0;
}

Measured memory_bytes: 512
# 入力
Vn, En, r = map(int, input().split())

Ve = [ [] for _ in range(Vn)]

for _ in range(En):
    s, t, c = map(int, input().split())
    Ve[s].append((t,c))

# 初期化
INF = 10**4 * 10**5
dp = [INF] * Vn
dp[r] = 0

# ダイクストラ
from heapq import heappush, heappop

q = [(0, r)]
while q:
    du, u = heappop(q)
    
    for v, dv in Ve[u]:
        if dp[v] > du + dv:
            dp[v] = du + dv
            heappush(q, (du + dv, v))

# 解答
for i in range(Vn):
    if not dp[i] == INF:
        print(dp[i])
    else:
        print("INF")


Measured memory_bytes: 90288
#include <bits/stdc++.h>
#define ll long long
#define rep(i, begin, end) for (__typeof(end) i = (begin) - ((begin) > (end)); i != (end) - ((begin) > (end)); i += 1 - 2 * ((begin) > (end))) // rep(i, 1, 5) --> {1,2,3,4} // rep(i, 5, 1) --> {4,3,2,1} // rep(it, end(v), begin(v)) --> *it

using namespace std;

int main()
{
    ll x;
    cin >> x;
    ll a = 100;
    rep(i, 1, 10000)
    {
        a = a + a * 0.01;
        if (a >= x)
            return cout << i, 0;
    }
    return 0;
}

Measured memory_bytes: 3600
#include <bits/stdc++.h>
using namespace std;
int64_t gcd(int64_t a, int64_t b) {
    int64_t c;
    while (a) {
        c = a;
        a = b % a;
        b = c;
    }
    return b;
}

int64_t lcm(int64_t a, int64_t b) {
    return (a / gcd(a, b) * b);
}
int64_t solve(int64_t x, int64_t y, int64_t z) {
    int64_t l = lcm(y, z);
    return x - (x / y + x / z - x / l);
}

int main() {
    #ifdef DEBUG
    std::ifstream in("/home/share/inputf.in");
    std::cin.rdbuf(in.rdbuf());
    #endif
    int64_t A, B, C, D;
    cin >> A >> B >> C >> D;
    
    cout << solve(B, C, D) - solve(A - 1, C, D) << endl;

    return 0;
}

Measured memory_bytes: 256
while 1:
    t = int(input())
    if t == 0: break
    n = int(input())
    i = 0
    sum = 0
    while i < n:
        s, f = map(int, input().split())
        a = f - s
        sum = sum + a
        i += 1
    if sum < t:
        print(t - sum)
    else:
        print("OK")


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

using ll = long long;
using ull = unsigned long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vvvi = vector<vvi>;

#define REPS(i, a, n) for (int i = (a); i < (n); ++i)
#define REP(i, n) REPS(i, 0, n)
#define RREP(i, n) REPS(i, 1, n + 1)
#define DEPS(i, a, n) for (int i = (a); i >= n; --i)
#define DEP(i, n) DEPS(i, n, 0)

#define vint(v, n) vector<int> v(n); REP(i,n) cin >> v[i];
#define vvint(v, w, n) vector<int> v(n); vector<int> w(n); REP(i,n) cin >> v[i] >> w[i];
#define vlint(v, n) vector<ll int> v(n); REP(i,n) cin >> v[i];
#define vdouble(v, n) vector<double> v(n); REP(i,n) cin >> v[i];
#define vvdoube(v, n1, n2) vector<vector<double> > v(n1, vector<double>(n2, 0)); REP(i,n1) REP(j,n1) cin >> v[i][j];
#define string(x) string x; cin >> x;
#define vstring(v, n) vector<string> v(n); REP(i,n){string a; std::cin >> a; v.push_back(a); }

#define all(v) (v).begin(), (v).end()
#define rall(v) (v).begin(), (v).end(), std::greater<int>()
#define len(v) (v).length()
#define FIND(s, n) (s.find(n) != s.end())
#define SORT(a) sort(all(a))

static const string abet("abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ");
static const long long int MOD = 1000000007;
static const double PI=3.1415926535897932;
static const int INF = 0x3f3f3f3f;
static const int INFTY = (1 << 29);
static const long long LINFTY = (1LL << 32);

static const int dy4[]={0, 0, 1, -1};
static const int dx4[]={1, -1, 0, 0};
static const int dx8[] = {1, 1, 1, 0, 0, -1, -1, -1};
static const int dy8[] = {-1, 0, 1, -1, 1, -1, 0, 1};

int knapsack_01_hugeW(int N,int W,vector<int> v,vector<int> w) {

  int MAX_V = *max_element(v.begin(), v.end());
  int dp[N+1][N*MAX_V+1];
//std::vector<std::vector<int> > dp(N + 1, std::vector<int>(W + 1, 0));

  REP(j, N*MAX_V+1) dp[0][j] = INF;
  dp[0][0] = 0;

  REP(i, N) REP(j, N*MAX_V+1){
      if (j < v[i]) dp[i+1][j] = dp[i][j];
      else dp[i+1][j] = min(dp[i][j], dp[i][j - v[i]] + w[i]);
  }
  int max = 0;
  REP(i, N*MAX_V+1) if(dp[N][i] <= W) max = i;

  return max;
}

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

  int N, W;
  cin >> N >> W;
  vvint(v, w, N);

  cout << knapsack_01_hugeW(N, W, v, w) << endl;

}

Measured memory_bytes: 7084
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
int main(){
  int N;
  cin>>N;
  N %= 10;
  switch(N){
    case 2:
    case 4:
    case 5:
    case 7:
    case 9: cout<<"hon\n"; break;
    case 0:
    case 1:
    case 6:
    case 8: cout<<"pon\n"; break;
    case 3: cout<<"bon\n"; break;
  }
  return 0;
}

Measured memory_bytes: 3636
#include <bits/stdc++.h>
#define REP(i, a, n) for (int i = (a); i < (int)(n); ++i)
#define REPC(i, a, n) for (int i = (a); i <= (int)(n); ++i)
#define ALL(t) t.begin(), t.end()
#define RALL(t) t.rbegin(), t.rend()
#define MATINIT(type, row, col, init) \
  vector<vector<type>>(row, vector<type>(col, init));
#define Yes(cond) cout << (cond ? "Yes" : "No") << endl;
#define YES(cond) cout << (cond ? "YES" : "NO") << endl;
using namespace std;
using LL = long long;
using ULL = unsigned long long;
template <class T>
using VEC = std::vector<T>;
template <class T>
using MAT = std::vector<std::vector<T>>;
void DUMP() { cerr << endl; }
template <class Head, class... Tail>
void DUMP(Head &&head, Tail &&... tail) {
  cerr << head << ", ";
  DUMP(std::move(tail)...);
}
template <typename T>
ostream &operator<<(ostream &os, vector<T> &vec) {
  os << "{";
  for (auto v : vec) os << v << ",";
  os << "}";
  return os;
}
template <typename T>
ostream &operator<<(ostream &os, set<T> &s) {
  os << "{";
  for (auto p : s) os << p << ",";
  os << "}";
  return os;
}
template <typename T1, typename T2>
ostream &operator<<(ostream &os, map<T1, T2> &m) {
  os << "{";
  for (auto p : m) os << p << ",";
  os << "}";
  return os;
}
template <typename T1, typename T2>
ostream &operator<<(ostream &os, pair<T1, T2> p) {
  os << "[" << p.first << " " << p.second << "]";
  return os;
}

int main() {
  double sum =0;
  LL rate = 380000;
  int N;
  cin>>N;
  REP(i,0,N){
    double x;
    string u;
    cin>>x>>u;
    if(u=="JPY"){
      sum+=x;
    }else{
      sum+=x*rate;
    }
  }
  printf("%lf\n",sum);

  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
inline int G() {
	int o=0;bool f=0;char t=getchar();
	while(t<48||t>57) f|=t=='-',t=getchar();
	while(t>47&&t<58) o=(o<<1)+(o<<3)+t-48,t=getchar();
	return f?-o:o;
}
map<int,int,greater<int> > M;
vector<ll> V;
ll ans=0;
int main() {
	int n=G();
	while(n--) M[G()]++;
	for(auto i=M.begin();i!=M.end();i++)
	if(i->second>1) {ans=i->first,i->second-=2;break;}
	for(auto i=M.begin();i!=M.end();i++)
	if(i->second>1) return ans*=i->first,cout<<ans,0;
	cout<<0;
} 


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


int main(){
   int n,a[101]={},k,x,d;
   cin>>n>>k;
   while(k--){
       cin>>d;
       while(d--){
           cin>>x;
           a[x]=1;
       }
   }
   int rez=0;
   for(int i=1;i<=n;i++){
       if(a[i]==0) rez++;
   }
   cout<<rez;
}

    
    


Measured memory_bytes: 3640
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define dup(x,y) (((x)+(y)-1)/(y))
#define ALL(x) (x).begin(), (x).end()
typedef long long ll;
typedef pair<int, int> pii;
const double EPS = 1e-10;
const int INF = 1e9;
const ll LINF = 1e15;
const int MOD = 1e9+7;
const double PI = acos(-1);
int dx[4] = {0,1,0,-1};
int dy[4] = {1,0,-1,0};
typedef pair<ll, ll> pll;

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

int main() {
    int n;
    cin >> n;
    printf("%d\n", n == 0 ? 1 : 0);
    
}


Measured memory_bytes: 3744
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
ll mod = 1e9+7;
#define rep(i,n) for(int i = 0; i < (n); ++i)

struct edge {
    int to;
    ll  cost;
};

vector<ll> dijkstra ( int a, vector<vector<edge>> &g, int n ) {
    vector<ll> cost(n, 1e18);
    priority_queue<pair<ll, int>, vector<pair<ll, int>>, greater<pair<ll, int>>> que;
    que.push({0LL, a});
    cost[a] = 0;
    while(!que.empty()) {
        pair<ll, int> now = que.top(); que.pop();
        ll now_cost = now.first;
        int now_p = now.second;
        if ( cost[now_p] < now_cost ) continue;
        for ( auto tmp_v : g[now_p] ) {
            if ( cost[tmp_v.to] > cost[now_p] + tmp_v.cost ) {
                cost[tmp_v.to] = cost[now_p] + tmp_v.cost;
                que.push({cost[tmp_v.to], tmp_v.to});
            }
        }
    }
    return cost;
}

int main(){
    int n, m, s, t;
    cin >> n >> m >> s >> t;
    --s, --t;
    vector<vector<edge>> g(n);
    vector<vector<edge>> h(n);
    rep(i, m) {
        int u, v;
        ll a, b;
        cin >> u >> v >> a >> b;
        --u, --v;
        g[u].push_back((edge){v, a});
        g[v].push_back((edge){u, a});
        h[u].push_back((edge){v, b});
        h[v].push_back((edge){u, b});
    }
    auto cost_g = dijkstra(s, g, n);
    auto cost_h = dijkstra(t, h, n);
    ll money = 1e15;
    vector<ll> ans(n+1, 1e18);
    for ( int i = n - 1; i >= 0; --i ) {
        ans[i] = min(ans[i+1], cost_g[i] + cost_h[i]);
    }
    rep(i, n) {
        cout << money - ans[i] << endl;
    }
    return 0;
}


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

#define int long long

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

int N;
int mod = 1e9 + 7;
int is_prime[1001] = {};
int exponent[1001] = {};

signed main() {
    cin >> N;
    for (int i = 2; i <= 1000; i++) {
        for (int j = 2; j <= sqrt(i); j++) {
            if (i % j == 0) {
                goto check;
            }
        }
        is_prime[i] = true;
check:  ;
    }
    for (int i = 2; i <= N; i++) {
        int cur = i;
        for (int j = 2; j <= 1000; j++) {
            if (is_prime[j] && cur % j == 0) {
                cur /= j;
                exponent[j]++;
                j--;
            }
        }
    }
    int ans = 1;
    for (int i = 2; i <= 1000; i++) {
        ans = ans * (exponent[i] + 1) % mod;
    }
    cout << ans << endl;
    return 0;
}


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

using namespace std;
#ifdef _DEBUG
#define _GLIBCXX_DEBUG
#include "dump.hpp"
#else
#define dump(...)
#endif

#define int long long
#define ll long long
#define DBG 1
#define rep(i, a, b) for (int i = (a); i < (b); i++)
#define rrep(i, a, b) for (int i = (b)-1; i >= (a); i--)
#define loop(n) rep(loop, (0), (n))
#define all(c) begin(c), end(c)
const int INF = sizeof(int) == sizeof(long long) ? 0x3f3f3f3f3f3f3f3fLL : 0x3f3f3f3f;
const int MOD = (int)(1e9) + 7;
#define fi first
#define se second
#define pb push_back
#define eb emplace_back
using pii = pair<int, int>;
// template<class T> ostream &operator<<(ostream &os,T &t){dump(t);return os;}
template <typename T, typename S>istream &operator>>(istream &is, pair<T, S> &p) { is >> p.first >> p.second; return is; }
//template <typename T, typename S>ostream &operator<<(ostream &os, pair<T, S> &p) {os << p.first << " " << p.second;return os;}

template <typename T> void printvv(const vector<vector<T>> &v) {
	cerr << endl;
	rep(i, 0, v.size()) rep(j, 0, v[i].size()) {
		if (typeid(v[i][j]).name() == typeid(INF).name() and v[i][j] == INF) {
			cerr << "INF";
		}
		else
			cerr << v[i][j];
		cerr << (j == v[i].size() - 1 ? '\n' : ' ');
	}
	cerr << endl;
}

#ifndef _DEBUG
#define printvv(...)
#endif
void YES(bool f) { cout << (f ? "YES" : "NO") << endl; }
void Yes(bool f) { cout << (f ? "Yes" : "No") << endl; }
template <class T, class U>bool chmin(T& a, U b) { if (a > b) { a = b; return true; }return false; }
template <class T, class U>bool chmax(T& a, U b) { if (a < b) { a = b; return true; }return false; }

signed main(signed argc, char *argv[]) {
	cin.tie(0);
	ios::sync_with_stdio(false);
	cout << fixed << setprecision(12);

	int N; cin >> N;
	vector<int>p(4); rep(i, 0, 4) { cin >> p[i]; }
	vector<int>t(4); rep(i, 0, 4) { cin >> t[i]; }

	int ans = INF;
	int x = 101;
	rep(i, 0, x) {
		rep(j, 0, x) {
			rep(k, 0, x) {
				int T = t[0] * i + t[1] * j + t[2] * k;
				int re = max(0ll, N - T);
				int l = (re + t[3] - 1) / t[3];
				chmin(ans, p[0] * i + p[1] * j + p[2] * k + p[3] * l);
			}
		}
	}
	cout << ans << endl;

	return 0;
}



Measured memory_bytes: 3204
import sys,collections,math,random;sys.setrecursionlimit(10**7)
def Is(): return [int(x) for x in sys.stdin.readline().split()]
def Ss(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def S(): return input()

H,W = Is()
mat = [[0]*W for i in range(H)]
inp = []
for i in range(H):
    inp.append(list(S()))
for i in range(H):
    t = 0
    for j in range(W):
        if inp[i][j] == ".":
            t += 1
            if j == W-1:
                for k in range(j+1-t,j+1):
                    mat[i][k] += t
        elif inp[i][j] == "#":
            for k in range(j-t,j):
                mat[i][k] += t
            t = 0
#print(*mat)
for j in range(W):
    t = 0
    for i in range(H):
        if inp[i][j] == ".":
            t += 1
            if i == H-1:
                for k in range(i+1-t,i+1):
                    mat[k][j] += t
        elif inp[i][j] == "#":
            for k in range(i-t,i):
                mat[k][j] += t
            t = 0    
#print(*mat)
ans = 0
for e in mat:
    ans = max(ans,max(e))
print(max(0,ans-1))

Measured memory_bytes: 217224
#include <iostream>
#include <list>
#include <string>
using namespace std;
int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	int n,x;
	string str;
	list <int> lst;
	list<int>::iterator it;
	cin >> n;
	while (n--){
		cin >> str;
		if (str == "insert")     {cin >> x; lst.push_front(x);}
   else if (str == "deleteFirst") lst.pop_front();		
   else if (str == "deleteLast")  lst.pop_back();			
   else{    cin >> x;
         	for (it = lst.begin(); it!=lst.end(); ++it){
		   		 if (*it == x){
					  lst.erase(it); break;
			    	}				 	
			  }
	    }
	}
	for (it = lst.begin(); it != --lst.end(); ++it)cout << *it<<" ";
	cout <<*it<<endl;
	return 0;
}

Measured memory_bytes: 32476
N=int(input())
import math
A=list(map(int,input().split()))
b=math.ceil(math.log(max(max(A),1),2)) 
B=[0 for i in range(b)] #0のリスト
C=[0 for i in range(b)] #1のリスト
for i in A:
  for j in range(b):
    if ((i>>j) & 1):
      C[j]+=1
    else:
      B[j]+=1
 # print(B,C,i)
mod =10**9+7
ans=[(B[i]*C[i])*2**i % mod for i in range(b)]
print(sum(ans)%mod)

Measured memory_bytes: 125624
/*
 *  Lang    : C++
 *  Author  : little_angel
 */
#include <bits/stdc++.h>

#include <random>

using namespace std;
#define int long long


string sol(int n) {
    if (n <= 26)return string(1, 'a' + n - 1);
    int x = (n - 1) % 26;
    return sol((n - 1) / 26) + string(1, 'a' + x);
}

signed main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);

    int n;
    cin >> n;
    vector<int> a(n), b(n - 1);
    for (auto &i:a)cin >> i;
    int s = 0;
    for (int i = 0; i < n - 1; ++i)b[i] = a[i] ^ a[i + 1];
    for (int i = 0; i < n - 1; i += 2)s ^= b[i];
    for (int i = 0; i < n; ++i) cout << (s ^ a[i]) << " ";
}

Measured memory_bytes: 6272
#include<bits/stdc++.h>
#pragma GCC target ("avx2")
#pragma GCC optimization ("Ofast")
#pragma GCC optimization ("unroll-loops")
#pragma comment(linker, "/stack:200000000")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
using namespace std;

typedef pair<int,int>pi;
typedef vector<int>vi;

const int MAXN=100005;
const int MOD=1000000007;

#define FOR(i,a,b) for(int i=(a);i<=(b);i++)
#define DEC(i,a,b) for(int i=(a);i>=(b);i--)
#define pb push_back
#define mp make_pair
#define sz(v) ((int)(v).size())
#define all(v) (v).begin(),(v).end()
#define db(x) cerr<<#x<<" = "<<x<<"\n"
#define LOW(v,x) (lower_bound(all(v),(x))-(v).begin())
#define UP(v,x) (upper_bound(all(v),(x))-(v).begin())

int L,N,edges;
vector<pi> adj[MAXN];

main(){
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cin>>L;
	N=__builtin_clz(L)+1;
	FOR(i,1,N-1) {
		edges += 2;
		adj[i].pb({i+1, 0});
		adj[i].pb({i+1, (1<<(i-1)) });
	}
	int curmin = 1<<(N-1);
	int tl=L-(1<<(N-1));
	while (tl > 0){
		int x=__builtin_clz(tl)+1;
		tl -= (1<<(x-1));
		edges++;
		adj[x].pb({N, curmin});
		curmin += (1<<(x-1));
	}
	cout << N << " " << edges << "\n";
	FOR(u,1,N-1){
		for (auto v:adj[u]){
			cout<<u<<" "<<v.first<<" "<<v.second<<"\n";
			assert(v.second <= 1e6);
		}
	}
}


Measured memory_bytes: 2560
#include <stdio.h>

int main(){
  double x;
  while (scanf("%lf",&x)!=EOF){
    if (x<=48.00){
      puts("light fly");
    }else if (x<=51.00){
      puts("fly");
    }else if (x<=54.00){
      puts("bantam");
    }else if (x<=57.00){
      puts("feather");
    }else if (x<=60.00){
      puts("light");
    }else if (x<=64.00){
      puts("light welter");
    }else if (x<=69.00){
      puts("welter");
    }else if (x<=75.00){
      puts("light middle");
    }else if (x<=81.00){
      puts("middle");
    }else if (x<=91.00){
      puts("light heavy");
    }else{
      puts("heavy");
    }
  }
  return 0;
}

Measured memory_bytes: 608
#include <algorithm>
#include <bits/stdc++.h>
#include <cstdint>
#include <iostream>
#include <iterator>
#include <vector>

// lib/detail/ceil_and_floor.hpp
#ifndef DETAIL_CEIL_AND_FLOOR_HPP
#define DETAIL_CEIL_AND_FLOOR_HPP

namespace tools {
  template <typename T>
  constexpr T floor(T lhs, T rhs);

  template <typename T>
  constexpr T ceil(T lhs, T rhs);

  template <typename T>
  constexpr T floor(const T lhs, const T rhs) {
    return
      lhs >= 0 && rhs >= 0 ?
        lhs / rhs :
      lhs < 0 && rhs >= 0 ?
        -ceil<T>(-lhs, rhs) :
      lhs >= 0 && rhs < 0 ?
        -ceil<T>(lhs, -rhs) :
        floor<T>(-lhs, -rhs);
  }

  template <typename T>
  constexpr T ceil(const T lhs, const T rhs) {
    return
      lhs >= 0 && rhs >= 0 ?
        (lhs - 1 + rhs) / rhs :
      lhs < 0 && rhs >= 0 ?
        -floor<T>(-lhs, rhs) :
      lhs >= 0 && rhs < 0 ?
        -floor<T>(lhs, -rhs) :
        ceil<T>(-lhs, -rhs);
  }
}

#endif

// lib/util.hpp
#ifndef UTIL_HPP
#define UTIL_HPP


typedef ::std::int_fast64_t i64;
typedef ::std::uint_fast64_t u64;
typedef ::std::int_fast32_t i32;
typedef ::std::uint_fast32_t u32;

namespace tools {
  template <typename T>
  void read(::std::istream& is, ::std::vector<T>& vector, const typename ::std::vector<T>::size_type size) {
    vector.reserve(size);
    ::std::copy_n(::std::istream_iterator<T>(is), size, ::std::back_inserter(vector));
  }
  template <typename T>
  void read(::std::vector<T>& vector, const typename ::std::vector<T>::size_type size) {
    ::tools::read(::std::cin, vector, size);
  }

  template <typename T, ::std::size_t N>
  void read(::std::istream& is, ::std::array<T, N>& array) {
    ::std::copy_n(std::istream_iterator<T>(is), N, array.begin());
  }
  template <typename T, ::std::size_t N>
  void read(::std::array<T, N>& array) {
    ::tools::read(::std::cin, array);
  }
}

#endif

// lib/ceil.hpp
#ifndef CEIL_HPP
#define CEIL_HPP


/*
usage:

tools::ceil(5, 3) // => 2 (i.e., ceil(5 / 3))
*/

#endif

// main.cpp

int main() {
  i64 H, W;
  std::cin >> H >> W;
  std::cout << (H == 1 || W == 1 ? 1 : tools::ceil<i64>(H * W, 2)) << std::endl;
  return 0;
}

Measured memory_bytes: 256
module ABC130

  ! <module>s to import
  use, intrinsic :: iso_fortran_env

  ! require all variables to be explicitly declared
  implicit none

  ! accessibility of <subroutine>s and <function>s in this <module>
  public  :: task_A

  ! contained <subroutine>s and <function>s are below
  contains

  subroutine task_A

    ! variables for this <subroutine>
    integer(INT8) :: X, A

    ! STEP.01
    ! read out the given integer
    read(unit=INPUT_UNIT, fmt=*) X, A

    ! STEP.02
    ! output the result
    if (X .lt. A) then
      write(unit=OUTPUT_UNIT, fmt='(I0)', advance='yes') 0_INT8
    else
      write(unit=OUTPUT_UNIT, fmt='(I0)', advance='yes') 10_INT8
    end if

    ! STEP.END
    return

  end subroutine task_A

end module ABC130


program main

  ! <module>s to import
  use, non_intrinsic :: ABC130

  ! require all variables to be explicitly declared
  implicit none

  call task_A

end program main

Measured memory_bytes: 640
#include<cstdio>
#include<queue>
#include<cstring>
using namespace std;
const int N=2e5+10,mod=1e9+7;
typedef long long ll;
int h[N],ne[N],e[N],idx;
bool st[N];
queue<int>q;
void add(int a,int b)
{
    e[idx]=b,ne[idx]=h[a],h[a]=idx++;
}
int main()
{
    memset(h,-1,sizeof h);
    int n,k,a,b;
    scanf("%d%d",&n,&k);
    for(int i=1;i<n;i++)
    {
        scanf("%d%d",&a,&b);
        add(a,b);add(b,a);
    }
    int root=1;
    st[1]=true;
    ll res=1;
    res=res*k%mod;
    int cnt=0;
    for(int i=h[1];~i;i=ne[i])
    {
        int j=e[i];
        if(st[j])   continue;
        q.push(j);
        st[j]=true;
        if(k-cnt-1<=0)  res=0;
        res=res*(k-cnt-1)%mod;
        cnt++;
    }
    while(q.size())
    {
        int cnt=0;
        int t=q.front();
        q.pop();
        for(int i=h[t];~i;i=ne[i])
        {
            int j=e[i];
            if(st[j])   continue;
            q.push(j);
            st[j]=true;
            if(k-cnt-2<=0)  res=0;
            res=res*(k-cnt-2)%mod;
            cnt++;
        }
    }
    printf("%lld",res);
}

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

const int N = 52;
int n;
vector<int> G1[N], G2[N], T[N];
int fix[N], fa[N], vis[N], ins[N];
void dfs1(int x, int pre, int ign) {
  fa[x] = pre;
  for (auto y : G1[x]) if (y != pre && y != ign) {
    dfs1(y, x, ign);
  }
}
void dfs2(int x, int pre) {
  if (fa[x] != pre) return;
  fix[x] = 1;
  for (auto y : G2[x]) if (y != pre) {
    dfs2(y, x);
  }
}
void dfs3(int x, int pre, int ign) {
  if (!fix[x] && !fix[pre]) T[x].push_back(pre);
  for (auto y : G1[x]) if (y != pre && y != ign) {
    dfs3(y, x, ign);
  }
}
void dfs4(int x, int pre) {
  if (!fix[x] && !fix[pre]) T[pre].push_back(x);
  for (auto y : G2[x]) if (y != pre) {
    dfs4(y, x);
  }
}
int dfs5(int x) {
  vis[x] = ins[x] = 1;
  for (auto y : T[x]) {
    if (ins[y]) {
      return 1;
    } else if (!vis[y] && dfs5(y)) {
      return 1;
    }
  }
  ins[x] = 0;
  return 0;
}
inline int solve(int rt, int rt2) {
  memset(fix, 0, sizeof fix);
  memset(fa, 0, sizeof fa);
  memset(vis, 0, sizeof vis);
  memset(ins, 0, sizeof ins);
  for (int i = 1; i <= n; i++) {
    T[i].clear();
  }
  dfs1(rt2, rt, rt);
  dfs2(rt, 0);
  dfs3(rt2, rt, rt);
  dfs4(rt, 0);
  for (int i = 1; i <= n; i++) {
    if (!vis[i] && dfs5(i)) return -1;
  }
  return n - accumulate(fix + 1, fix + 1 + n, 0);
}
inline void Main() {
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) {
    G1[i].clear();
    G2[i].clear();
  }
  for (int i = 1, x, y; i < n; i++) {
    scanf("%d%d", &x, &y);
    G1[x].push_back(y);
    G1[y].push_back(x);
  }
  for (int i = 1, x, y; i < n; i++) {
    scanf("%d%d", &x, &y);
    G2[x].push_back(y);
    G2[y].push_back(x);
  }
  int ans = 999;
  for (int i = 1; i <= n; i++) if (G1[i].size() == 1) {
    for (int j = 1; j <= n; j++) if (j != i) {
      int x = solve(i, j);
      if (~x) ans = min(ans, x + (j != G1[i][0]));
    }
  }
  printf("%d\n", ans == 999 ? -1 : ans);
}
int main() {
  int Test;
  scanf("%d", &Test);
  while (Test--) {
    Main();
  }
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define int long long
#define rep(i,a,b) for(int i=a;i<b;i+=1)
#define reps(i,a,b) for(int i=a;i>=b;i-=1)
#define vi vector<int>
#define vvi vector<vector<int>>
#define pb push_back
#define pi pair<int, int>
#define mp make_pair
#define ff first
#define ss second
#define in1(x) int x; cin>>x;
#define in2(x, y) int x, y; cin>>x>>y;
#define in3(x, y, z) int x, y, z; cin>>x>>y>>z;
#define in4(x, y, z, w) int x, y, z, w; cin>>x>>y>>z>>w;
#define mi unordered_map<int,int>
#define mem(x) memset(x, 0, sizeof(x))
#define IOS ios_base::sync_with_stdio(0); cin.tie(NULL); cout.tie(NULL);
using namespace std;

int32_t main(void){
	IOS;
	
	in4(a, b, c, k);
	
	if(k <= a) cout<<k<<endl;
	else{
		int ans = a;
		k -= a;
		if(k<=b) cout<<ans<<endl;
		else
		{
			k-=b;
			ans -= k;
			cout<<ans<<endl;
		}
	}
	
}

Measured memory_bytes: 3640
import java.io.*;
import java.util.*;

public class Main {
  private static int solve(int n, int[] as) {
    Set<Integer> set = new HashSet<>();
    int sum = 0;
    for (int a : as) {
      sum = sum ^ a;
      set.add(a ^ (a - 1));
    }
    int count = 0;
    for (int i = 31; i > 0; i--) {
      if (((sum >> i) & 1) != ((sum >> (i - 1)) & 1)) {
        if (!set.contains((1 << i) - 1)) {
          return -1;
        }
        count++;
      }
    }
    return count;
  }
  
  private static void execute(ContestReader reader, PrintWriter out) {
    int n = reader.nextInt();
    int[] as = reader.nextInt(n);
    out.println(solve(n, as));
  }
  
  public static void main(String[] args) {
    ContestReader reader = new ContestReader(System.in);
    PrintWriter out = new PrintWriter(System.out);
    execute(reader, out);
    out.flush();
  }
}

class ContestReader {
  private BufferedReader reader;
  private StringTokenizer tokenizer;
  
  ContestReader(InputStream in) {
    reader = new BufferedReader(new InputStreamReader(in));
  }
  
  public String next() {
    while (tokenizer == null || !tokenizer.hasMoreTokens()) {
      try {
        tokenizer = new java.util.StringTokenizer(reader.readLine());
      } catch (Exception e) {
        throw new RuntimeException(e);
      }
    }
    return tokenizer.nextToken();
  }
  
  public int nextInt() {
    return Integer.parseInt(next());
  }
  
  public long nextLong() {
    return Long.parseLong(next());
  }
  
  public double nextDouble() {
    return Double.parseDouble(next());
  }
  
  public String[] next(int n) {
    String[] array = new String[n];
    for (int i = 0; i < n; i++) {
      array[i] = next();
    }
    return array;
  }
  
  public int[] nextInt(int n) {
    int[] array = new int[n];
    for (int i = 0; i < n; i++) {
      array[i] = nextInt();
    }
    return array;
  }
  
  public long[] nextLong(int n) {
    long[] array = new long[n];
    for (int i = 0; i < n; i++) {
      array[i] = nextLong();
    }
    return array;
  }
  
  public double[] nextDouble(int n) {
    double[] array = new double[n];
    for (int i = 0; i < n; i++) {
      array[i] = nextDouble();
    }
    return array;
  }
  
  public char[] nextCharArray() {
    return next().toCharArray();
  }
  
  public int[][] nextInt(int n, int m) {
    int[][] matrix = new int[n][m];
    for (int i = 0; i < n; i++) {
      for (int j = 0; j < m; j++) {
        matrix[i][j] = nextInt();
      }
    }
    return matrix;
  }
  
  public long[][] nextLong(int n, int m) {
    long[][] matrix = new long[n][m];
    for (int i = 0; i < n; i++) {
      for (int j = 0; j < m; j++) {
        matrix[i][j] = nextLong();
      }
    }
    return matrix;
  }
  
  public double[][] nextDouble(int n, int m) {
    double[][] matrix = new double[n][m];
    for (int i = 0; i < n; i++) {
      for (int j = 0; j < m; j++) {
        matrix[i][j] = nextDouble();
      }
    }
    return matrix;
  }
  
  public char[][] nextCharArray(int n) {
    char[][] matrix = new char[n][];
    for (int i = 0; i < n; i++) {
      matrix[i] = next().toCharArray();
    }
    return matrix;
  }
}


Measured memory_bytes: 37344
#include "bits/stdc++.h"
using namespace std;
long long mod=1e9+7;

int main(){
  int n,m,q;
  cin>>n>>m>>q;
  int l,r;
  vector<vector<int> > lr(501,vector<int>(501,0));
  for(int i=0;i<m;i++){
    cin>>l>>r;
    lr[l][r]++;
  }

  vector<vector<int> > rui(501,vector<int>(501,0));

  for(int i=0;i<501;i++){
    int tmp=0;
    for(int j=0;j<501;j++){
      tmp+=lr[i][j];
      rui[i][j]=tmp;
    }
  }

  for(int i=0;i<q;i++){
    int x,y;
    cin>>x>>y;
    int ans=0;
    for(int i=x;i<=y;i++){
      ans+=rui[i][y]-rui[i][x-1];
      //for(int j=x;j<=y;j++)ans+=lr[i][j];
    }
    cout<<ans<<endl;
  }
}


Measured memory_bytes: 2944
#include<bits/stdc++.h>
#include<algorithm>
using namespace std;
int main()
{
    int i,j,n,m;
    cin>>n>>m;
    for(i=m-n+1;i<m+n;i++){
        cout<<i;
        if(i!=m+n-1)
            cout<<" ";
    }
}


Measured memory_bytes: 764
N, K = [int(i) for i in input().split()]
A = [int(i) for i in input().split()]
A.sort()
MOD = 10 ** 9 + 7


def combination(mod=MOD):
    fact = [1] * (N + 1)
    inv_fact = [1] * (N + 1)
    r = 1
    for i in range(1, N + 1):
        fact[i] = r = r * i % mod
    inv_fact[N] = r = pow(fact[N], mod - 2, mod)
    for i in range(N, 0, -1):
        inv_fact[i - 1] = r = r * i % mod

    def _wrapper(n, k):
        nonlocal fact, inv_fact, mod
        if n == 0 or k == 0:
            return 1
        return fact[n] * inv_fact[k] * inv_fact[n - k] % mod

    return _wrapper


def main():
    if K == 1:
        print(0)
        exit()
    comb = combination()
    sum_max = 0
    sum_min = 0
    for i, A_i in enumerate(A):
        if i >= K - 1:
            sum_max += comb(i, K - 1) * A_i % MOD
        if N - i >= K:
            sum_min += comb(N - i - 1, K - 1) * A_i % MOD
    ans = (sum_max - sum_min) % MOD
    print(ans)


if __name__ == '__main__':
    main()


Measured memory_bytes: 63472
#!/usr/bin/env python3

n = int(input())
a = list(map(int, input().split()))

num_minus = 0
for i in range(n):
    if a[i] < 0:
        num_minus += 1

a_plus = [abs(i) for i in a]

# print(num_minus)
# print(a_plus)
if num_minus % 2 == 0:
    print(sum(a_plus))
else:
    print(sum(a_plus)-2*min(a_plus))


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

#define REP(i,n) for(int i=0;i<(n);i++)
#define REAP(i,a,n) for(int i=(a);i<(n);i++)
#define YES cout<<"Yes"<<endl
#define NO cout<<"No"<<endl
#define fr first
#define sc second
#define pb push_back
#define All(v) v.begin(),v.end()
typedef long long ll;

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

    int sum;
    while(cin >> sum,sum){
        int a;
        REP(i,9){
            cin >> a;
            sum-=a;
        }
        cout << sum << endl;
    }
}



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

const int inf = 1e9;
const ll linf = 1e18;

template<typename T = int>
class WeightedUnionFind
{
public:
    WeightedUnionFind(int n = 0, T unity = 0) : m_data(n, -1), m_weight(n, unity), m_count(n) {}

    int find(int x)
    {
        if (m_data[x] < 0) return x;

        int root = find(m_data[x]);
        m_weight[x] += m_weight[m_data[x]];
        return m_data[x] = root;
    }

    T weight(int x)
    {
        find(x);
        return m_weight[x];
    }

    bool unite(int x, int y, T w)
    {
        w += weight(x), w -= weight(y);
        x = find(x), y = find(y);
        if (x == y) return false;

        if (m_data[x] > m_data[y]) {
            swap(x, y);
            w = -w;
        }
        m_data[x] += m_data[y];
        m_data[y] = x;
        m_weight[y] = w;
        m_count--;
        return true;
    }

    bool same(int x, int y) { return find(x) == find(y); }

    T diff(int x, int y) { return weight(y) - weight(x); }

    int size(int x) { return -m_data[find(x)]; }

    int count(void) const { return m_count; }

private:
    vector<int> m_data;
    vector<T>   m_weight;
    int m_count; 
};

int main()
{
    int n, q; cin >> n >> q;
    WeightedUnionFind<int> uf(n);
    for (int i = 0; i < q; i++) {
        int p; cin >> p;
        if (!p) {
            int x, y, z; cin >> x >> y >> z;
            uf.unite(x, y, z);
        } else {
            int x, y; cin >> x >> y;
            if (uf.same(x, y)) cout << uf.diff(x, y) << endl;
            else cout << "?" << endl;
        }
    }
    return 0;
}



Measured memory_bytes: 3636
#include<iostream>
using namespace std;
int main()
{
    int n,m;
 	string s;
 	
    // 入力
    cin >>n>>m;
    
    if (n==m){
    	s="Yes";
    }else{
    	s="No";
    }
    // 出力
    cout <<s<< endl;
    return 0;
}


Measured memory_bytes: 256