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

#define endl '\n'
#define pb push_back
#define mod 1000000007
typedef int integer;
#define int long long
#ifndef ONLINE_JUDGE
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
#else
#define trace(...) 0
#endif
using namespace std;

template<typename Arg1>
void __f(const char *name, Arg1 &&arg1) {
    cerr << name << ": " << arg1 << endl;
}

template<typename Arg1, typename... Args>
void __f(const char *names, Arg1 &&arg1, Args &&... args) {
    const char *comma = strchr(names + 1, ',');
    cerr.write(names, comma - names) << ": " << arg1 << " |";
    __f(comma + 1, args...);
}

int powmod(int a, int b) {
    int res = 1;
    a %= mod;
    assert(b >= 0);
    for (; b; b >>= 1) {
        if (b & 1)res = res * a % mod;
        a = a * a % mod;
    }
    return res;
}

int gcd(int a, int b) { return b ? gcd(b, a % b) : a; }

const integer NN = (int) 5e5 + 2;
int ar[NN];
int b[NN];
int n, m, k;
string s;

void paintr(vector<vector<char>>& v, int j){
    for (int i = 0; i < m; i++){
        v[j][i] = '-';
    }
}
void paintc(vector<vector<char>>& v, int j){
    for (int i = 0; i < n; i++){
        v[i][j] = '-';
    }
}

int get(vector<vector<char>>& v){
    int ans = 0;
    for (int i = 0; i < n; i++) {
        for (int j = 0; j < m; j++) {
            ans += (v[i][j] == '#');

        }
    }
    return ans;
}


integer main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0);

    cin >> n >> m >> k;
    vector<vector<char>> g(n, vector<char>(m));
    for (int i = 0; i < n; i++){
        for (int j = 0; j < m; j++){
            cin >> g[i][j];
        }
    }
    int ans = 0;
    for (int i = 0; i < (1 << n); i++){
        for (int j = 0; j < (1 << m); j++){
            auto v = g;
            for (int l = 0; l < n; l++){
                if ((1 << l) & i){
                    paintr(v, l);
                }
            }
            for (int l = 0; l < m; l++){
                if ((1 << l) & j){
                    paintc(v, l);
                }
            }
            ans += (get(v) == k);
        }
    }
    cout << ans << endl;


}

//2 9 1 1 2 4 4 2 9

Measured memory_bytes: 3616
#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() {
	ll A, B, K;
	cin >> A >> B >> K;

	if (A + B < K) {
		cout << "0 0" << endl;
	}
	else {
		if (K <= A) {
			cout << A - K << " " << B << endl;
		}
		else {
			cout << "0 " << B - (K - A) << endl;
		}
	}

}

Measured memory_bytes: 256
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

def main():
    A, B, C, D = map(int, read().split())
    taka = -(-C//B)
    ao = -(-A//D)
    print('Yes' if taka <= ao else 'No')
    return

if __name__ == '__main__':
    main()



Measured memory_bytes: 9176
a, b, k = map(int, input().split())

if b - a + 1 <= 2 * k:
  for i in range(a, b + 1):
    print(i)

else:
  for i in range(a, a + k):
    print(i)
  for i in range(b - k + 1, b + 1):
    print(i)

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

int main()
{
	long long int q, h, s, d;
	long double n;
	cin >> q >> h >> s >> d >> n;
	long long int ans = 0;
	if (h >= 2 * q)
	{
		h = 2 * q;
	}
	if (s >= 2 * h)
	{
		s = 2 * h;
	}
	if (d >= 2 * s)
	{
		d = 2 * s;
	}
	while (n != 0)
	{
		if (n >= 2)
		{
			ans += (int)(n / 2)* d;
			n = (int)(n)%2;
		}
		if (n >= 1)
		{
			ans += s;
			n -= 1;
		}
		if (n >= 0.5)
		{
			ans += (n / 2)* d;
			n -= 0.5;
		}
		if (n >= 0.25)
		{
			ans += (n / 2)* d;
			n -= 0.25;
		}
	}
	cout << ans << endl;
	return 0;
}

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

const int N_MAX = 100000;
const int Q_MAX = 50000;

int main() {
  int n, q;
  int s[N_MAX], t[Q_MAX];
  cin >> n;
  for (int i = 0; i < n; i++) cin >> s[i];
  cin >> q;
  for (int i = 0; i < q; i++) cin >> t[i];

  int ans = 0;
  for (int i = 0; i < q; i++) {
    int left = 0;
    int right = n;
    while (left < right) {
      int mid = (left + right) / 2;
      if (s[mid] == t[i]) {
        ans++;
        break;
      } else if (s[mid] > t[i]) {
        right = mid;
      } else {
        left = mid + 1;
      }
    }
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 3668
#include <bits/stdc++.h>
using namespace std;
#define PII pair<int, int>
#define VI vector<int>
#define VPII vector<PII>
#define LL long long
#define LD long double
#define f first
#define s second
#define MP make_pair
#define PB push_back
#define endl '\n'
#define ALL(c) (c).begin(), (c).end()
#define SIZ(c) (int)(c).size()
#define REP(i, n) for(int i = 0; i < (int)(n); ++i)
#define FOR(i, b, e) for(int i = (b); i <= (int)(e); ++i)
#define FORD(i, b, e) for(int i = (b); i >= (int)(e); --i)

#define sim template<class n
sim, class s> ostream & operator << (ostream &p, pair<n, s> x)
{return p << "<" << x.f << ", " << x.s << ">";}
sim> auto operator << (ostream &p, n y) ->
typename enable_if<!is_same<n, string>::value, decltype(y.begin(), p)>::type 
{int o = 0; p << "{"; for(auto c: y) {if(o++) p << ", "; p << c;} return p << "}";}
void dor() {cerr << endl;}
sim, class...s> void dor(n p, s...y) {cerr << p << " "; dor(y...);}
sim, class s> void mini(n &p, s y) {if(p>y) p = y;}
sim, class s> void maxi(n &p, s y) {if(p<y) p = y;}
#ifdef DEB
#define debug(...) dor(__FUNCTION__, ":", __LINE__, ": ", __VA_ARGS__)
#else
#define debug(...)
#endif 

#define I(x) #x " =", (x), " "
#define A(a, i) #a "[" #i " =", i, "] =", a[i], " "
const int MXN = 1e6+6;
string s[MXN];
int mi[MXN];
int mi_rev[MXN];
int sum[MXN];

int main()
  {
  ios_base::sync_with_stdio(0); 
  int n;
  cin >> n;
  VI all;
  REP(i, n)
    {
    cin >> s[i];
    for(auto j: s[i])
        {
        sum[i] += (j == '(') ? 1 : -1;
        mini(mi[i], sum[i]);
        }
    all.PB(i);

    reverse(ALL(s[i]));
    int ss = 0;
    for(auto j: s[i])
      {
      ss += j == ')' ? 1 : -1;
      mini(mi_rev[i], ss);
      }
    }
  sort(ALL(all), [&](int a, int b){
    if((sum[a] >= 0) != (sum[b] >= 0))return (sum[a] >= 0) > (sum[b] >= 0);
    if(sum[a] >= 0)
      {
      return mi[a] > mi[b];
      }
    else
      {
//      return mi_rev[a] < mi_rev[b];
      return sum[b] + mi[a] < sum[a] + mi[b];        
      }
  });

  int s = 0;
  for(auto i: all)
    {
    if(s + mi[i] < 0)
      {
      puts("No");
      return 0;
      }
    s += sum[i];
    }
  if(s == 0)puts("Yes");
  else puts("No");
  }


Measured memory_bytes: 50384
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		@SuppressWarnings("resource")
		Scanner scan = new Scanner(System.in);

		int n = scan.nextInt();
		int k = scan.nextInt();

		int ans = k;
		for (int i = 0; i < n - 1; i++) {
			ans = ans * (k - 1);
		}
		System.out.println(ans);
	}

}


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

int main(){
  int n; cin >>n;
  vector<int> d(n);
  map<int, int> mpd;
  rep(i,n){
    cin >>d[i];
    mpd[d[i]]++;
  }
  int m; cin >>m;
  vector<int> t(m);
  rep(i,m) cin >>t[i];
  bool can = true;
  for(int x : t){
    if(mpd[x]==0) can = false;
    else mpd[x]--;
    if(!can) break;
  }
  if(can) cout << "YES" << endl;
  else cout << "NO" << endl;
  return 0; 
}

Measured memory_bytes: 13884
#include <bits/stdc++.h>
#define FASTIO ios::sync_with_stdio(false);cin.tie(0);
#define ADD +
#define SUBTRACT -
#define MULTIPLY *
#define DIVIDE /
#define MOD %
#define INCREMENT(x) ++x
#define DECREMENT(x) --x
#define in(a,b) cin>>a>>b;
#define out(a,b) cout<<a<<endl<<b<<endl;
#define scan(a) scanf("%d",&a);
#define print(a) printf("%d\n",a);
#define scanii(a,b) scanf("%d %d",&a,&b);
#define printii(a,b) printf("%d\n%d\n",a,b);
#define scaniii(a,b,c) scanf("%d %d %d",&a,&b,&c);
#define pub push_back
#define pob pop_back
#define puf push_front
#define pof pop_front
#define ll long long
#define ull unsigned long long
#define sll signed long long
#define pi acos(-1)
#define mod 1000000007
#define TRUE 1
#define FALSE 0
#define ZERO 0
#define MP make_pair
#define F first
#define S second
#define f1(i,a) for(int i=0;i<a;++i)
#define f2(i,a) for(int i=a-1;i>=0;--i)
#define en puts("");
#define elif else if
typedef ll int lli;
typedef sll int slli;
typedef ull int ulli;
const int sz=10000;
using namespace std;

int clue();
int result();
void show();
bool check(int n) {
    for(int i=2;i*i<=n;++i) {
        if(n%i==0)
        return false;
    }
    return true;
}


// bool cmp(pair<int,int>p,pair<int,int>q) {
//     // return p.first>q.first;//descending by first
//     // return p.first<q.first;//ascending by first
//     // return p.second>q.second;//descending by second
//     return p.second<q.second;//ascending by second
// }

bool cmp(int p,int q) {
    return p>q;//descending
    // return p<q;//ascending
}


int main() {

    int t;
    // cin>>t;
    t=1;
    while(t-->0) {
        clue();
    }

    return 0;
}
int clue() {

    int n;
    cin>>n;
    cout<<3*n*n<<endl;
    // ()?cout<<"YES"<<endl:cout<<"NO"<<endl;
    
    return 0;
}

Measured memory_bytes: 3584
# https://atcoder.jp/contests/abc127/tasks/abc127_c
N, M = list(map(int, input().split()))
L = 0
R = N
for _ in range(M):
    l, r = list(map(int, input().split()))
    L = max(L, l)
    R = min(R, r)

print(max(R - L + 1, 0))


Measured memory_bytes: 3060
n = int(input())
d = list(map(int, input().split()))
b = 1
ans = 1
dd=[0]*10**5
for i in d:
    dd[i]+=1
max = max(d)
if d[0] == 0 and d.count(0) == 1:
    for i in range(1, max+1):
        if dd[i] == 0:
            print(0)
            exit()
        if dd[i] == 1:
            ans *= b
        else:
            if b != 1:
                ans *= pow(b, dd[i], 998244353)
        b = dd[i]
    print(ans % 998244353)
else:
    print(0)

Measured memory_bytes: 14396
import copy
class SegmentTree:
    def __init__(self, N, func, I):
        self.sz = N
        self.func = func
        self.I = copy.deepcopy(I)
        self.seg = [copy.deepcopy(I) for i in range(self.sz * 2)]
 
    def assign(self, k, x):
        self.seg[k + self.sz] = copy.deepcopy(x)
 
    def build(self):
        for i in range(self.sz - 1, 0, -1):
            self.seg[i] = self.func(self.seg[2 * i], self.seg[2 * i + 1])
 
    def update(self, k, x):
        k += self.sz
        self.seg[k] = copy.deepcopy(x)
        while k > 1:
            k //= 2
            self.seg[k] = self.func(self.seg[2 * k], self.seg[2 * k + 1])
 
    def query(self, a, b):
        L = copy.deepcopy(self.I)
        R = copy.deepcopy(self.I)
        a += self.sz
        b += self.sz
        while a < b:
            if a % 2 == 1:
                L = self.func(L, self.seg[a])
                a += 1
            if b % 2 == 1:
                b -= 1
                R = self.func(self.seg[b], R)
            a //= 2
            b //= 2
        return self.func(L, R)

import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
from fractions import gcd
N = int(readline())
m = map(int,read().split())
seg = SegmentTree(N , gcd , 0)
for i in range(N):
    seg.assign(i , next(m))
seg.build()
ans = 1
for i in range(N):
    ans = max(ans,gcd(seg.query(0,i) , seg.query(i+1,N)))
print(ans)

Measured memory_bytes: 107040
using static System.Math;
using System;
 
public class ATC
{
	public static void Main()
	{
		string[] line = Console.ReadLine().Split(' ');
      
		var n = int.Parse(line[0]);
		var L = int.Parse(line[1]);
		var absmin = int.MaxValue;
		var min = 0;
      
		for (int i = 1; i <= n; i++)
		{
			var t = Abs(L + i - 1);
			if (t < absmin) { absmin = t; min = L + i - 1; }
		}
		var s = n * (n + 2 * L - 1) / 2;
		Console.WriteLine(s - min);
	}
}

Measured memory_bytes: 11092
using System;

class Program
{
    static void Main()
    {
        int c = int.Parse(Console.ReadLine());
        string result = "";
        int foundIndex;
        
        for (int i = 3; i <= c; i++ )
        {
            if (i % 3 == 0)
            {
                result = result + " " + i.ToString();
            }
            else
            {
                foundIndex = i.ToString().IndexOf("3");
                if (foundIndex >= 0)
                {
                    result = result + " " + i.ToString();
                }
            }
        }
        
        //結果を表示
        Console.WriteLine(result);
    }
}


Measured memory_bytes: 10012
#include<iostream>
#include<string>
#include<cstdio>
#include<vector>
#include<cmath>
#include<algorithm>
#include<functional>
#include<iomanip>
#include<queue>
#include<ciso646>
#include<random>
#include<map>
#include<set>
#include<complex>
#include<bitset>
#include<stack>
#include<unordered_map>
using namespace std;
typedef long long ll;
typedef unsigned int ui;
const ll mod = 998244353;
const ll INF = (ll)1000000007 * 1000000007;
typedef pair<int, int> P;
#define stop char nyaa;cin>>nyaa;
#define rep(i,n) for(int i=0;i<n;i++)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define per1(i,n) for(int i=n;i>=1;i--)
#define Rep1(i,sta,n) for(int i=sta;i<=n;i++)
typedef long double ld;
typedef complex<ld> Point;
const ld eps = 1e-3;
const ld pi = acos(-1.0);
typedef pair<ll, ll> LP;
typedef pair<ld, ld> LDP;

int n, m;
ld p[16][17];
ld memo[17][1 << 16];
bool used[17][1 << 16];
ld dfs(int i, int x) {
	if (i == m)return 1;
	if (used[i][x])return memo[i][x];
	used[i][x] = true;
	ld res = 0;
	rep(j, n) {
		if (x&(1 << j))continue;
		int nj = x ^ (1 << j);
		ld sum = 0; ld pro = 1;
		Rep1(k, i, m) {
			sum += dfs(k, nj)*pro*(1 - p[j][k]); pro *= p[j][k];
		}
		res = max(res, sum);
	}
	return memo[i][x] = res;
}

int main() {
	cout << fixed << setprecision(12);
	cin >> n >> m;
	rep(i, n) {
		rep(j, m) {
			cin >> p[i][j];
		}
	}
	cout << dfs(0, 0) << endl;
	return 0;
}



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

int main() {
  int n, m;
  while (true) {
    cin >> n >> m;
    if (n == 0 && m == 0) {
      break;
    }else if (n <= m) {
      cout << n << " " << m << endl;
    }else{
      cout << m << " " << n << endl;
    }
  }
}


Measured memory_bytes: 3068
#include<bits/stdc++.h>
#define ll long long
#define ld long double
#define mk make_pair
#define fi first
#define se second
#define vll vector<ll>
#define pii pair<ll,ll>
#define vvll vector< vector<ll> >
#define pb push_back
#define sz(v) (v).size()
#define inf 1e18
#define md 1000000007
#define all(v) (v).begin(),(v).end()
#define rep(i,a,b) for(ll i=a;i<b;++i)
#define tel(a){cout<<a<<"\n";}
#define tell(a,b){cout<<a<<" | "<<b<<"\n";}
#define telll(a,b,c){cout<<a<<" | "<<b<<" | "<<c<<"\n";}
#define teln(v,n){cout<<"v- ";rep(i,0,n)cout<<v[i]<<" ";cout<<"\n";}
#define IOS ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
using namespace std;
#define M 1000010

int main(){
	IOS;
	ll n;cin>>n;
	ll a[n];rep(i,0,n)cin>>a[i];
	sort(a,a+n);
	ll ans=0;
	ll m=a[n-1];
	rep(i,0,n){
		rep(j,i+1,n){
			rep(k,j+1,n){
				if(a[k]>=a[i]+a[j])break;
				ll f=1;
				if(a[i]>=a[j]+a[k] or a[j]>=a[i]+a[k] or a[k]>=a[j]+a[i])f=0;
				if(f)ans++;
			}
		}
	}
	cout<<ans;
	
	
	
	return 0;
}



Measured memory_bytes: 384
n, m, l = map(int, raw_input().split())
matrix_a = []
matrix_b = []

for i in range(n):
    line = map(int, raw_input().split())
    matrix_a.append(line)
for i in range(m):
    line = map(int, raw_input().split())
    matrix_b.append(line)


for i in range(n):
    result = []
    for j in range(l):
        tmp = 0
        for k in range(m):
            tmp += matrix_a[i][k] * matrix_b[k][j]
        result.append(tmp)
    print " ".join(map(str, result))

Measured memory_bytes: 6888
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define SORT(c) sort((c).begin(),(c).end())
#define REVERSE(c) reverse((c).begin(), (c).end());
const long long MOD = 1e9 + 7;
typedef long long ll;

int main(){
	string S;
	cin >> S;
	int N = S.size();
	bool J = false;
	int cnt = 0;
	int place;
	
	if(S[0] == 'A'){
		if(S[1] != 'C' && S[N - 1] != 'C'){
			SORT(S);
			if(S[1] == 'C' && S[2] >= 'a' && S[2] <= 'z'){
				J = true;
			}
		}
	}
	if(J)cout << "AC" << endl;
	else cout << "WA" << endl;
}

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

const int INF = 1e9 + 10;

int main() {
  int h, w, k;
  cin >> h >> w >> k;
  vector<vector<char>> c(h, vector<char>(w));
  for (int i = 0; i < h; i++) {
    string line;
    cin >> line;
    for (int j = 0; j < w; j++) {
      c[i][j] = line[j];
    }
  }
  int ans = 0;
  for (int r_bit = 0; r_bit < (1 << h); r_bit++) {
    for (int c_bit = 0; c_bit < (1 << w); c_bit++) {
      int cnt = 0;
      for (int i = 0; i < h; i++) {
        for (int j = 0; j < w; j++) {
          if (r_bit & (1<<i))continue;
          if (c_bit & (1<<j))continue;
          if (c[i][j] == '#') cnt++;
        }
      }
      if(cnt == k) ans++;
    }
  }
  cout << ans << endl;
}


Measured memory_bytes: 3628
#include <iostream>
#include <vector>

int main()
{
  uint q;
  std::cin >> q;
  std::vector<int> v;

  for (auto i = 0; i < q; i++) {
    int a, b;
    std::cin >> a;
    switch (a) {
    case 0:
      std::cin >> b;
      v.push_back(b);
      break;
    case 1:
      std::cin >> b;
      std::cout << v[b] << std::endl;
      break;
    case 2:
      v.pop_back();
      break;
    }
  }
}



Measured memory_bytes: 3904
#include <stdio.h>
#include <math.h>

int main(void)
{
  long int a,b,h,m;
  scanf("%ld %ld %ld %ld", &a, &b, &h, &m);
  long double deg,c;
  deg = fabsl(30*h+0.5*m-6*m);
  if(deg>180){
    deg = 360-deg;
  }
  c=sqrtl(a*a+b*b-2*a*b*cosl(deg*3.14159265359/180));
  printf("%16.11llf\n", c);
  return 0;
}

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

map< ll, ll > prime_factor(ll n) {
  map< ll, ll > ret;
  for(ll i = 2; i * i <= n; i++) {
    while(n % i == 0) {
      ret[i]++;
      n /= i;
    }
  }
  if(n != 1) ret[n] = 1;
  return ret;
}
int main(){
	ll n;
	cin >> n;
    ll ans = 0;
    int sum = 0;
  map<ll, ll> prime = prime_factor(n);
  
  for(auto p: prime){
      sum = 0;
    for(int j=0; j<=10; j++){
		sum += j;
        if (p.second <= sum){ 
          if(p.second == sum) ans += j;
          if(p.second < sum) ans += j-1;
         break;
        }
    }
  }
    cout << ans << endl;
    
    return 0;
}



Measured memory_bytes: 3644
import sys,collections as cl,bisect as bs
sys.setrecursionlimit(100000)
input = sys.stdin.readline
mod = 10**9+7
Max = sys.maxsize
def l(): #intのlist
    return list(map(int,input().split()))
def m(): #複数文字
    return map(int,input().split())
def onem(): #Nとかの取得
    return int(input())
def s(x): #圧縮
    a = []
    if len(x) == 0:
        return []
    aa = x[0]
    su = 1
    for i in range(len(x)-1):
        if aa != x[i+1]:
            a.append([aa,su])
            aa = x[i+1]
            su = 1
        else:
            su += 1
    a.append([aa,su])
    return a
def jo(x): #listをスペースごとに分ける
    return " ".join(map(str,x))
def max2(x): #他のときもどうように作成可能
    return max(map(max,x))
def In(x,a): #aがリスト(sorted)
    k = bs.bisect_left(a,x)
    if k != len(a) and a[k] ==  x:
        return True
    else:
        return False

def pow_k(x, n):
    ans = 1
    while n:
        if n % 2:
            ans *= x
        x *= x
        n >>= 1
    return ans

"""
def nibu(x,n,r):
    ll = 0
    rr = r
    while True:
        mid = (ll+rr)//2

    if rr == mid:
        return ll
    if (ここに評価入れる):
        rr = mid
    else:
        ll = mid+1
"""

a,b = m()

if a <= b:
    print("unsafe")
else:
    print("safe")

Measured memory_bytes: 65156
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<ll,ll> P;
typedef pair<int,int> Pi;
#define rep(i, n) for (ll i = 0; i < n; i++)
#define FOR(i, a, b) for (ll i = a; i < b; i++)
#define fi first
#define se second
#define endl "\n"

template<typename T> inline bool chmax(T &a, T b){if(a<b){a=b;return true;}return false;}
template<typename T> inline bool chmin(T &a, T b){if(a>b){a=b;return true;}return false;}
template<typename T> ostream& operator<<(ostream& s,const complex<T>& d) {return s<<"("<<d.real()<<", "<<d.imag()<< ")";}
template<typename T1, typename T2> ostream& operator<<(ostream& s,const pair<T1,T2>& d) {return s<<"("<<d.first<<", "<<d.second<<")";}
template<typename T> ostream& operator<<(ostream& s, const vector<T>& d){
	int len=d.size();
	rep(i,len){
		s<<d[i];if(i<len-1) s<<" ";
	}
	return s;
}
template<typename T> ostream& operator<<(ostream& s,const vector<vector<T>>& d){
	int len=d.size();
	rep(i,len){
		s<<d[i]<<endl;
	}
	return s;
}
template<typename T> ostream& operator<<(ostream& s,const set<T>& v){
	s<<"{ ";
	for(auto itr=v.begin();itr!=v.end();++itr) {
		if (itr!=v.begin()) {s<< ", ";}
		s<<(*itr);
	}
	s<<" }";
	return s;
}
template<typename T1, typename T2> ostream& operator<<(ostream& s,const map<T1,T2>& m){
	s<<"{"<<endl;
	for(auto itr=m.begin();itr!=m.end();++itr){
		s<<" "<<(*itr).first<<" : "<<(*itr).second<<endl;
	}
	s<<"}"<<endl;
	return s;
}

const ll mod=1e9+7;
const ll inf=1e17;
const int INF=1e9;
const double PI=acos(-1);
const double EPS=1e-10;

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	int s;
	cin>>s;
	set<int> cnt;
	cnt.insert(s);
	int ans=2;
	while(true){
		if(s%2==0){
			s/=2;
		}else{
			s=3*s+1;
		}
		if(cnt.count(s)){
			cout<<ans<<endl;
			return 0;
		}
		ans++;
		cnt.insert(s);
	}
}

Measured memory_bytes: 256
x = ['+++', '++-', '+-+', '+--', '-++', '-+-', '--+', '---']
a = input()
for i in range(8):
    ans = a[0] + x[i][0] + a[1] + x[i][1] + a[2] + x[i][2] + a[3]
    if eval(ans) == 7:
        print(ans + '=7')
        break


Measured memory_bytes: 2940
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using vb=vector<bool>;
using vvb=vector<vb>;
using vd=vector<double>;
using vvd=vector<vd>;
using vi=vector<int>;
using vvi=vector<vi>;
using vl=vector<ll>;
using vvl=vector<vl>;
using pll=pair<ll,ll>;
using tll=tuple<ll,ll>;
using vs=vector<string>;
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define rep(i,n) range(i,0,n)
#define rrep(i,n) for(int i=(n)-1;i>=0;i--)
#define range(i,a,n) for(int i=(a);i<(n);i++)

#define LINF    	((ll)1ll<<60)
#define INF     	((int)1<<30)
#define EPS     	(1e-9)
#define MOD     	(1000000007ll)
#define fcout(a)	cout<<setprecision(a)<<fixed
#define fs 			first
#define sc			second
#define PI			3.1415926535897932384

int dx[]={1,0,-1,0,1,-1,-1,1},dy[]={0,1,0,-1,1,1,-1,-1};
template<class S,class T>ostream&operator<<(ostream&os,pair<S,T>p){os<<"["<<p.first<<", "<<p.second<<"]";return os;};
template<class S>auto&operator<<(ostream&os,vector<S>t){bool a=1; for(auto s:t){os<<(a?"":" ")<<s; a=0;} return os;}
void OUT(bool b){cout<<(b?"YES":"NO")<<endl;}
void Out(bool b){cout<<(b?"Yes":"No")<<endl;}
void out(bool b){cout<<(b?"yes":"no")<<endl;}
int popcnt(int x) { return __builtin_popcount(x); }
int popcnt(ll x) { return __builtin_popcountll(x); }
int clz(int x) { return 31 - __builtin_clz(x); }
int clz(ll x) { return 63 - __builtin_clzll(x); }
int ctz(int x) { return __builtin_ctz(x); }
int ctz(ll x) { return __builtin_ctzll(x); }

class compare {
public:
	bool operator()(tuple<ll, ll> a, tuple<ll, ll> b) {
		return (get<1>(a) > get<1>(b));
	}
};

ll dp[1001][1001];

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	ll h,w;
	char c;
	cin>>h>>w;
	dp[0][0]=1;
	vvb g(h,vb(w,false));
	rep(i,h){
		rep(j,w){
			cin>>c;
			if(c=='.')g[i][j]=true;
		}
	}
	rep(i,h){
		rep(j,w){
			if(g[i][j]){
				if(i!=0)dp[i][j]+=dp[i-1][j];
				if(j!=0)dp[i][j]+=dp[i][j-1];
				dp[i][j]%=MOD;
			}
		}
	}
	cout<<dp[h-1][w-1]<<endl;
}

Measured memory_bytes: 8320
#include<bits/stdc++.h>
using namespace std;
using Graph=vector<vector<int>>;
#define rep(i,n) for(int i=0;i<(int)(n);i++)
typedef long long ll;
template<class T> inline bool chmin(T& a, T b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
}
template<class T> inline bool chmax(T& a, T b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}
ll gcd(ll x,ll y){
    if(x<y) swap(x,y);
    //xの方が常に大きい
    ll r;
    while(y>0){
        r=x%y;
        x=y;
        y=r;
    }
    return x;
}

int main(){
    ll a,b,c,d;
    cin>>a>>b>>c>>d;
    cout<<max(max(a*c,b*d),max(a*d,b*c))<<endl;
}

Measured memory_bytes: 3628
#pragma once
#include <sstream>
#include <string>
#include <vector>
#include <map>
#include <algorithm>
#include <iostream>
#include <utility>
#include <set>
#include <cctype>
#include <queue>
#include <stack>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <deque>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
const int INF = 10e9;
void PalindromicNumber() {
	int N;
	cin >> N;
	int v = N % 10 * 100;
	v += (N / 10) % 10 * 10;
	v += (N / 100) % 10;
	if (N == v) {
		cout << "Yes" << endl;

	}
	else {
		cout << "No" << endl;
	}
}
int main() {
	PalindromicNumber();
	return 0;
}



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

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

Measured memory_bytes: 3580
D = [int(input()) for _ in range(5)]
D.sort(key=lambda x: 10 - (x - 1) % 10)
ans = 0
for i in range(4):
    while(D[i] % 10 != 0):
        D[i] += 1
    ans += D[i]
ans += D[-1]
print(ans)

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

int main(){
  string S;
  int Q;
  cin >> S >> Q;
  bool flag = false;
  rep(i, Q){
    int t;
    cin >> t;
    if(t == 1){

    flag = !flag;
    }
    else {
      int f;
      char c;
      cin >> f >> c;
      if(f == 1 && flag){
        //反転
        f = 2;
      }else if(f == 2 && flag){
        //反転
        f = 1;
      }
      if(f == 1){
        S.insert(0, 1, c);
      }else{
        S.push_back(c);
      }
    }
  }
  if(flag){
    for(int i = S.size()-1; i >= 0; i--){
      cout << S[i];
    }
    cout << endl;
  }else{
    cout << S << endl;
  }

}


Measured memory_bytes: 1028
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<ll> V;
#define rep(i,e) for(ll i=0;i<e;i++ )
typedef pair<ll,ll> P;
const ll mod = 1e9+7;
const ll INF = INT64_MAX;
ll i;



int main(){
    ll n,m;
    cin>>n>>m;
    cout<<(n-1)*(m-1)<<endl;
}


Measured memory_bytes: 256
// Marcin Knapik
#include<bits/stdc++.h>
#pragma GCC optimize("O3")
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")

using namespace std;

// #include <ext/pb_ds/assoc_container.hpp> // order_of_key
// #include <ext/pb_ds/tree_policy.hpp> // find by order
// using namespace __gnu_pbds; 
// #define ordered_set tree< int , null_type,less< int >, rb_tree_tag,tree_order_statistics_node_update>  

// const ll MAX_LL = 0xFFFFFFFFFFFFFFFF;
// mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
#define losuj(a, b) uniform_int_distribution<ll>(a, b)(rng)

typedef long double             ld;
// typedef long long               ll;
#define ll unsigned long long
typedef pair<int, int>          ii;
typedef vector<int>             vi;
typedef vector<ll>              vll;
typedef vector<vll>             vvll;
typedef vector<ii>              vii;
typedef vector<vi>              vvi;
typedef vector<vii>             vvii;
#define pll pair<long long, long long>

#define sz(a)                   (int)(a).size()
#define pb                      push_back
#define all(c)                  (c).begin(), (c).end()
#define rall(c)                 (c).rbegin(), (c).rend()
#define FOR(i, a)               for (int i = 0; i < (a); i++)
#define f                       first
#define s                       second

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

template<class T> inline T fast(T a,T b,T mod) {ll res = 1; while(b){if(b&1) res = (res*a)%mod;a = (a*a)%mod;b >>= 1;}return res;}
template<class T> istream &operator>>(istream &os, vector<T> &container){for (auto &u : container)os >> u;return os;}
template<class T> ostream &operator<<(ostream &os, const vector<T> &container){for (auto &u : container)os << u << " ";return os;}
template<class T> inline T gcd(T a, T b) { while (b)swap(a %= b, b); return a; }

const ll INF = 1e9 + 7;
const ll mod = 998244353;
const ll BIG_INF = 1e18 + 7;
const ll N = 1e6+7;
const ll T = 1<<20;
const ld inf = 1e18;

ll n, a, b, c, d;

ll dziel[] = {2, 3, 5};
ll koszt[3];
map<ll, ll> mapa;


ll req(ll x){
    if(x == 0)
        return 0;
    if(x == 1)
        return d;
    if(mapa.count(x))
        return mapa[x];
    ll ret = BIG_INF * 10;
    if(x < BIG_INF / d)
        ret = x * d;

    FOR(i, 3){
        ll _ = ((x / dziel[i]) * dziel[i]);
        ret = min(ret, koszt[i] + req(_ / dziel[i]) + d * (x - _));
        _ = (((x + dziel[i] - 1) / dziel[i]) * dziel[i]);
        ret = min(ret, koszt[i] + req(_ / dziel[i]) + d * (_ - x));
    }
    return mapa[x] = ret;
}

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

    int q;
    cin >> q;
    while(q--){
        mapa.clear();
        cin >> n >> koszt[0] >> koszt[1] >> koszt[2] >> d;

        cout << req(n) << '\n';
    }
}       

Measured memory_bytes: 4396
#include <bits/stdc++.h>
#define ll long long
#define ld long double
#define pii pair <int, int>
#define pll pair <ll, ll>
#define vll vector <pll>
#pragma 03
using namespace std; 
int main(){
	int n, k;
	string s;
	cin >> n >> k >> s;
	s[k-1] = tolower(s[k-1]);
	cout << s;
}

 


Measured memory_bytes: 256
;; -*- coding:utf-8 -*-

(eval-when (:compile-toplevel :load-toplevel :execute)
  (defparameter OPT
    #+swank '(optimize (speed 3) (safety 1))
    #-swank '(optimize (speed 3) (safety 0) (debug 0))))

(defmacro print-line (obj &optional (stream '*standard-output*))
  `(prog1 (princ ,obj ,stream) (terpri ,stream)))


;; Hauptteil

(deftype uint nil `(integer 0 ,(expt 10 9)))
(defun main ()
  (let ((n (read)))
    (loop for sum from 0 by 7 to n
          when (zerop (mod (- n sum) 4))
            do (write-line "Yes")
               (return-from main)
          finally (write-line "No"))))

#-swank(main)


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

int32_t main(){
int n;
  cin>>n;
  int a[n+1];
  for(int i=0;i<n;i++) cin>>a[i];
  int ans =0;
  int ma=a[0];
	for(int i=1;i<n;i++){
    	if(a[i]>ma)ma=a[i];
      else{
      	ans+=ma - a[i];
      }
    }
  cout<<ans;
return 0;
}

Measured memory_bytes: 5172
#include<cstdlib>
#include<iostream>
#include<string>

int main(){
  int n, m, a, b;
  std::cin >> n >> m;
  int city[n];
  for(int i = 0; i < n; i++)
    city[i] = 0;
  for(int i = 0; i < m; i++){
    std::cin >> a >> b;
    city[a - 1] += 1;
    city[b - 1] += 1;
  }
  for(int i = 0; i < n; i++)
    std::cout << city[i] << std::endl;
  return 0;
}


Measured memory_bytes: 256
import math
n = int(input())
lis = [list(map(int,input().split())) for i in range(n)]
num = 0
for i in range(n):
    for j in range(n):
        num += math.sqrt((lis[i][0]-lis[j][0])**2 + (lis[i][1]-lis[j][1])**2)
print(num/n)

Measured memory_bytes: 3060
#include<iostream>
#include<cstdlib>
#include<cmath>

using namespace std;
typedef long long llong;
typedef unsigned long long ullong;

int n; 

llong mod_pow(ullong x, ullong n, ullong mod) {
  ullong res = 1;
  while ( n > 0 ) {
    if ( n & 1) {
      res = res * x % mod;
    }
    x = x * x % mod;
    n >>= 1;
  }
  return res;
}

int main()
{
  int m, n;
  cin >> m >> n;
  cout << mod_pow(m, n, 1000000007) << endl;
  return 0;
}
 
 

Measured memory_bytes: 3100
while 1:
	H = int(raw_input())
	if H == 0:
		break
	Board = [[0 for j in range(H+1)] for i in range(6)]
	for j in range(H):
		inputs = map(int,raw_input().split(" "))
		for i in range(5):
			Board[i][H-j] = inputs[i]
	total_score = 0
	tmp_score = -1
	while tmp_score != 0:
		tmp_score = 0
		tmpBoard = [[0 for j in range(H+1)] for i in range(6)]
		for j in range(1,H+1):
			con_num = 1
			for i in range(1,6):
				if Board[i][j] == Board[i-1][j]:
					con_num += 1
				else :
					if con_num >= 3:
						tmp_score += con_num * Board[i-1][j]
					else :
						for h in range(con_num):
							tmpBoard[i-1-h][0] += 1
							tmpBoard[i-1-h][tmpBoard[i-1-h][0]] = Board[i-1-h][j]
					con_num = 1
		total_score += tmp_score
		Board = tmpBoard
	print total_score
	

Measured memory_bytes: 4280
#include <stdio.h>

int main(void){

  int n;
  scanf("%d", &n);

  double odd;
  double all = n;
  if (n % 2 != 0) {
    odd = (all+1)/2;
  } else {
    odd = all/2;
  }
  double answer = odd/all;
  printf("%lf\n", answer);

  return 0;
}

Measured memory_bytes: 128
def solve():
  N = int(input())
  A = [-float('inf')]+list(map(int, input().split()))
  A.sort()
  ans = [A[-1]]
  n = A[-1]//2
  for i in range(1,N+1):
    if A[i]>n or i==N-1:
      if A[i]-n>n-A[i-1]:
        ans.append(A[i-1])
      else:
        ans.append(A[i])
      break
  return ans
print(*solve())

Measured memory_bytes: 20116
#include <bits/stdc++.h>
#define _GLIBCXX_DEBUG
using namespace std;
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define rep2(i, s, n) for (ll i = s; i < (ll)(n); i++)
typedef long long ll;
typedef vector<vector<ll>> vvl;
typedef vector<ll> vl;
typedef vector<vector<char>> vvc;
typedef vector<char> vc;
typedef pair<ll,ll> pll;
ll max(ll x,ll y){
if(x>y)return x;
else return y;
}
ll min(ll x,ll y){
  return x+y-max(x,y);
}
const double pi=3.1415926535;

int main(){
  ll x,a,b;
  cin >> a >> b >> x;
  ll ans=b/x-a/x;
  if(a%x==0)ans++;
  cout << ans << endl;
}

Measured memory_bytes: 256
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
int main(){
    char *s;
    int i,draw0=0,draw1=0,cnt;
    s=(char*)malloc(sizeof(char));
    scanf("%s",s);
    cnt=strlen(s);
    for(i=0;i<cnt;i++){
        if(s[i]=='0')draw0++;
        if(s[i]=='1')draw1++;
    }
    printf("%d\n",(draw0<draw1)?draw0*2:draw1*2);
    return 0;
}

Measured memory_bytes: 256
#include <algorithm>
#include <iostream>
#include <vector>
using namespace std;
const int MAX = 100000 + 1; // 1-indexed

vector<int> par(MAX);
vector<bool> marked(MAX);

struct UnionFind {
    vector<int> data;
    UnionFind(int size) : data(size, -1) { }
    bool unionSet(int x, int y) {
        x = root(x); y = root(y);
        if (x != y) {
            //if (data[y] < data[x]) swap(x, y);
            data[x] += data[y]; data[y] = x;
        }
        return x != y;
    }
    bool findSet(int x, int y) { return root(x) == root(y); }
    int root(int x) { return data[x] < 0 ? x : data[x] = root(data[x]); }
};

int main() {
    int N, Q;
    while (cin >> N >> Q, N) {
        fill(marked.begin(), marked.end(), false);
        marked[1] = true;
        for (int v = 2; v <= N; v++) cin >> par[v];
        vector<pair<char, int>> query(Q);
        for (int i = 0; i < Q; i++) {
            char cmd; int v;
            cin >> cmd >> v;
            // 同じ部分にマークした場合は，初回以外を無視
            if (cmd == 'M' && marked[v]) continue;
            query.emplace_back(cmd, v);
            // 1. M(v) で指定された全部の頂点を塗る
            if (cmd == 'M') marked[v] = true;
        }
        // 2. 塗られていない頂点については，その親と併合する
        UnionFind uf(N + 1);    // 1-origin
        for (int v = 1; v <= N; v++) if (!marked[v]) uf.unionSet(par[v], v);
        // 3. クエリを逆回しする
        reverse(query.begin(), query.end());
        long long sum = 0;
        for (auto p : query) {
            char cmd = p.first; int v = p.second;
            if (cmd == 'Q') sum += uf.root(v);      // v の根を sum に加える
            if (cmd == 'M') uf.unionSet(par[v], v); // v と v の親を併合する
        }
        cout << sum << endl;
    }
    return 0;
}


Measured memory_bytes: 5600
A, B, C, X, Y = map(int, input().split())

# Cを買った個数とA、B単品で買った場合のコストを愚直に試す
total = 1<<60
for i in range(10**5+1):
  cost = 2*C*i + max(X-i, 0)*A + max(Y-i, 0)*B
  total = min(cost, total)

print(total)

Measured memory_bytes: 3060
from collections import Counter
s=input()
t=input()
cs=Counter(s).most_common()
ct=Counter(t).most_common()
if len(cs)==len(ct):
    for i in range(len(cs)):
        if cs[i][1]!=ct[i][1]:
            print("No")
            break
    else:print("Yes")
else:print("No")

Measured memory_bytes: 4144
#include <cstdint>
#include <algorithm>
#include <iostream>
#include <list>


void mondai_a()
{
    uint32_t a, b;
    std::cin >> a >> b;

    std::list<uint32_t> c{1,2,3};

    c.remove(a);
    c.remove(b);

    std::cout << *(c.begin());

    return;    
}



int main()
{
    mondai_a();


    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define int long long
#pragma GCC optimize("O3,Ofast,no-stack-protector,unroll-loops,fast-math")
#pragma GCC target("avx,avx2,sse")
using namespace std;

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

    int n;
    int arr[3];
    cin >> n >> arr[0] >> arr[1] >> arr[2];
    vector<string> kek(n);
    vector<char> choices;
    for (int i = 0; i < n; i++) {
        cin >> kek[i];
    }
    for (int i = 0; i < n; i++) {
        int a = kek[i][0] - 'A';
        int b = kek[i][1] - 'A';
        if (arr[a] == 0 && arr[b] == 0) {
            cout << "No" << '\n';
            return 0;
        } else if (arr[a] == 0) {
            arr[a]++;
            arr[b]--;
            choices.push_back('A' + a);
        } else if (arr[b] == 0) {
            arr[a]--;
            arr[b]++;
            choices.push_back('A' + b);
        } else if (i != n - 1 && kek[i] == kek[i + 1]) {
            choices.push_back(kek[i][0]);
            choices.push_back(kek[i][1]);
            i++;
        } else if (i == n - 1) {
            arr[a]++;
            arr[b]--;
            choices.push_back('A' + a);
        } else {
            int c = kek[i + 1][0] - 'A';
            int d = kek[i + 1][1] - 'A';
            if (b == c || b == d) {
                arr[b]++;
                arr[a]--;
                choices.push_back('A' + b);
            } else {
                arr[a]++;
                arr[b]--;
                choices.push_back('A' + a);
            }
        }
    }
    cout << "Yes" << '\n';
    for (char ch : choices) {
        cout << ch << '\n';
    }

    fflush(stdout);
    return 0;
}


Measured memory_bytes: 6640
#include <iostream>
#include <string>
#include <stack>
#include <queue>
#include <vector>
#include <algorithm>
#include <list>
#include <set>
#include <map>

using namespace std;

#define ARRAY_LENGTH(array) (sizeof(array) / sizeof(array[0]))

int main(){
	cin.tie(0);                       
   	ios::sync_with_stdio(false);
   	int N,K;
   	cin >> N;
   	cin >> K;
   	int rslt = 1;
   	for(int i = 0;i < N;i++){
   		rslt = min(rslt * 2,rslt + K);
   	}
   	cout << rslt << endl;
   	return 0;
}

Measured memory_bytes: 256
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<iostream>
#include<string>
#include<vector>
#include<stack>
#include<bitset>
#include<cstdlib>
#include<cmath>
#include<set>
#include<list>
#include<deque>
#include<map>
#include<queue>
#define F(x) for(int i=1;i<=(x);i++)
#define fer(i,n) for(int i=1;i<=(n);i++)
#define FIN  {freopen("1.in","r",stdin);}
#define FOUT {freopen("1.out","w",stdout);}
#define OUT(x)  {cout<<"#x"<<" : "<<x<<endl;}
#define ERR(x)  {cout<<"#error:"<<x;while(1);}
typedef long long ll;
typedef unsigned long long ull;
#define se second
#define fi first
#define make_pair mkp
#define mid ((l+r)>>1)
const int MaxInt = -1u>>1;
const int Max_ = 0x3f3f3f;
const double eps = 1e-6;
const double pi = acos(-1);
using namespace std;
inline int read()
{
    char ch=getchar();int f=1,g=0;
    for(;!isdigit(ch);ch=getchar()) if(ch=='-') f=-1;
    for(;isdigit(ch);ch=getchar()) g=g*10+(ch^48);
    return g*f;
}
const int N = 2005;
int n,k;
int head[N*2],nt[N*2],to[N*2],cnt=0,num=0,ans=0;
inline void add(int u,int v)
{
    nt[++cnt]=head[u];
    head[u]=cnt;
    to[cnt]=v;
}
void dfs(int x,int f,int now)
{
    num++;if(now==0)return;
    for(int y,i=head[x];i;i=nt[i])
        if((y=to[i])!=f)
            dfs(y,x,now-1);
}
int main()
{
    n=read(),k=read();
    F(n-1) {int a=read(),b=read();add(a,b),add(b,a);}
    if(!(k&1))
    {
        F(n) {
            num=0;dfs(i,0,k/2);ans=max(num,ans);
        }
    }
    else
    {
        F(n) for(int j=head[i];j;j=nt[j]) {
            num=0;int y=to[j];
            dfs(y,i,k/2);
            dfs(i,y,k/2);
            ans=max(num,ans);
        }
    }
    cout<<n-ans<<endl;
    return 0;
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
#define MOD 1000000007LL
using namespace std;
typedef long long ll;
typedef pair<int,int> P;


ll labs(ll x){
	if(x<0LL)return -x;
	return x;
}
int n;
ll a[100005];

int main(void){
	scanf("%d",&n);
	for(int i=0;i<n;i++){
		scanf("%lld",&a[i+1]);
	}
	n+=2;
	ll sum=0;
	for(int i=0;i<n-1;i++){
		sum+=labs(a[i+1]-a[i]);
	}
	for(int i=1;i<=n-2;i++){
		if(a[i-1]<=a[i] && a[i]<=a[i+1]){
			printf("%lld\n",sum);
		}else if(a[i+1]<=a[i] && a[i]<=a[i-1]){
			printf("%lld\n",sum);
		}else{
			ll po=labs(a[i+1]-a[i-1]);
			ll vi=labs(a[i+1]-a[i])+labs(a[i]-a[i-1]);
			printf("%lld\n",sum+po-vi);
		}
	}
	return 0;
}

Measured memory_bytes: 2048
#include <bits/stdc++.h>
using namespace std;
#define inf 999999999
#define loop(i, a, b) for (int i = (a), i##len = (b); i < i##len; ++i)
#define rep(i, n) loop(i, 0, n)
#define lin long long
#define lfl long double

int n;
int a[101];

int main(void)
{
    cin >> n;
    rep(i,n)
    {
        cin >> a[i];
    }
    a[n] = -1;
    int res = 0;

    rep(i, n-1)
    {
        if(a[i] == a[i+1])
        {
            if(a[i+1] != a[i+2])
                a[i] = -i;
            else
                a[i+1] = -i;

            res++;
        }
    }

    cout << res << endl;

    return 0;
}


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

typedef long long ll;
typedef pair<ll, int> pii;
const int N = 2e5 + 10;
ll n, a[N], b[N], c[N], tot, k;
int pre[N], nxt[N];
bool mark[N];
priority_queue<pii> q;

bool chk() {
    rep(i, 1, n) if (a[i] != c[i]) return 0;
    return 1;
}

int main() {
    cin >> n;
    rep(i, 1, n) scanf("%lld", &a[i]);
    int cnt = 0;
    rep(i, 1, n) {
        scanf("%lld", &b[i]);
        pre[i] = i - 1, nxt[i] = i + 1;
        if (a[i] != b[i]) q.push(make_pair(b[i], i));
    }
    pre[1] = n, nxt[n] = 1;
    while (q.size()) {
        pii u = q.top(); q.pop();
        int x = u.second;
        if (b[x] == a[x]) continue;
        if (b[x] - b[pre[x]] - b[nxt[x]] < a[x]) { puts("-1"); return 0; }
        ll k = (b[x] - a[x]) / (b[pre[x]] + b[nxt[x]]);
        b[x] = (b[x] - a[x]) % (b[pre[x]] + b[nxt[x]]) + a[x];
        tot += k;
        if (a[x] != b[x]) q.push(make_pair(b[x], x));
    }
    printf("%lld\n", tot);
    return 0;
}


Measured memory_bytes: 11632
// B - Collecting Balls (Easy Version)
#include <bits/stdc++.h>
using namespace std;

int main(){
	int N,K; cin>>N>>K;
	int ans = 0;
	while(N--){
		int x; cin>>x;
		ans += min(x, K-x) * 2;
	}
	cout<< ans <<endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define INF 1000000000
#define LINF 1000000000000000000
#define MOD 1000000007
#define mod 998244353
#define INF63 1061109567
#define INF127 9187201950435737471
#define UINF 18446744073709551615
#define F first
#define S second
#define ll long long
#define N 100010
using namespace std;
ll n,m,dep[N],lw[N],ans;
bool vis[N];
vector<ll> vt[N];
void dfs(ll x,ll lst,ll d)
{
	vis[x]=true;
	lw[x]=d;
	dep[x]=d;
	ll i;
	for(i=0;i<vt[x].size();i++)
	{
		if(vt[x][i]!=lst)
		{
			if(vis[vt[x][i]])
			{
				lw[x]=min(lw[x],dep[vt[x][i]]);
			}
			else
			{
				dfs(vt[x][i],x,d+1);
				lw[x]=min(lw[x],lw[vt[x][i]]);
			}
		}
	}
	return;
}
int main(){
	ll i,x,y;
	scanf("%lld%lld",&n,&m);
	for(i=0;i<m;i++)
	{
		scanf("%lld%lld",&x,&y);
		x--;
		y--;
		vt[x].push_back(y);
		vt[y].push_back(x);
	}
	dfs(0,-1,0);
	for(i=0;i<n;i++)
	{
		if(lw[i]==dep[i])
		{
			ans++;
		}
	}
	printf("%lld\n",ans-1);
	return 0;
}

Measured memory_bytes: 6196
#include <iostream>
#include <algorithm>
#include <cstring>
#include <cmath>
#include <vector>
#include <set>
#include <queue>
#include <map>
#include <string>

#define rep(i, a, b) for ( int i = (a); i < (b); i++ )
#define per(i, a, b) for ( int i = (b)-1; i >= (a); i--)
#define pb push_back
#define mp make_pair
#define bg begin()
#define en end()
#define all(v) (v).begin(), (v).end()
#define rall(v) (v).rbegin(), (v).rend()
#define sz(v) (int)(v).size()

using namespace std;

typedef long long ll;
typedef long double ld;

using P = pair<int, int>;

static const long long MOD = 1000000007;
static const long long LINF = (ll)(1e18+99);
static const int INF = 1e9+99;

ll ans = LINF;

int main(void) {
  int N;
  cin >> N;
  vector<ll> A(N, 0);
  rep(i, 0, N) cin >> A[i];
  
  vector<ll> S(N+5);
  rep(i, 0, N) S[i+1] = S[i]+A[i];
  
  rep(i, 2, N-1) {
    int l = upper_bound(S.bg, S.bg+i+1, S[i]/2) - S.bg;
    ll p = S[l-1], q = S[i] - S[l];
    if (p<q) p += A[l-1];
    else q += A[l-1];
    
     int _r = upper_bound(S.bg+i+1, S.bg+N, (S[N]-S[i])/2+S[i]) - S.bg;
     //printf("_r:%d\n", _r);
     ll r = S[_r-1]-S[i], s = S[N] - S[_r];
    if (r<s) r += A[_r-1];
    else s += A[_r-1];
    
    //printf("p:%lld  q:%lld  r:%lld  s:%lld\n", p, q, r, s);
    
    ll mx = max(max(p, q), max(r, s));
    ll mn = min(min(p, q), min(r, s));
    
    ll dif = abs(mx-mn);
    ans = min(ans, dif);
  
  }
    
  cout << ans << endl;
    return 0;
}





Measured memory_bytes: 6368
// https://atcoder.jp/contests/abc174/tasks/abc174_a
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define REP(i, n) FOR(i, 0, n)
#define REPR(i, n) for (int i = n - 1; i >= 0; i--)
#define FOR(i, s, n) for (int i = (s), i##_len = (n); i < i##_len; ++i)
#define ALL(obj) (obj).begin(), (obj).end()
#define ALLR(obj) (obj).rbegin(), (obj).rend()
#define DIV(a, b) ((a - 1) / b + 1)

signed main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    int N;
    cin >> N;
    if (N >= 30) {
        cout << "Yes" << endl;
    } else {
        cout << "No" << endl;
    }

    return 0;
}


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

using namespace std;

typedef long long ll;

int main(int argc, char *argv[])
{
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);

  int n; cin >> n;
  ll k; cin >> k;
  vector<int> v(n);
  for (int i = 0; i < n; ++i) {
    cin >> v[i];
    --v[i];
  }

  int t = 0;
  map<int, int> mp;
  mp[0] = 0;
  for (int time = 1; time <= n; ++time) {
    if (k == 0) {
      break;
    }
    k--;
    t = v[t];
    if (mp.find(t) != mp.end()) {
      k = k%(time-mp[t]);
      break;
    }
    else {
      mp[t] = time;
    }
  }

  while (k--) {
    t = v[t];
  }

  cout << t+1 << endl;


  
  return 0;
}




Measured memory_bytes: 11596
package main

import "fmt"

func main(){
	var n,k int
	fmt.Scan(&n,&k)
	a := make([]int,n)
	for i:=0 ; i<n ; i++ {
		fmt.Scan(&a[i])
	}
	for i:=k;i<n;i++ {
		if a[i-k] < a[i] {
			fmt.Println("Yes")
		} else {
			fmt.Println("No")
		}
	}
}


Measured memory_bytes: 6488
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;

class hoge{
    public:
    string s;
    int p;
    int idx;
    bool operator < (const hoge &h)const{
        if(s != h.s)return s < h.s;
        return -p < -h.p;
    }
    bool operator > (const hoge &h)const{
        if(s != h.s)return s > h.s;
        return p < h.p;
    }
};

int main(){
    
    ll N;
    cin >> N;
    // vector<hoge>v(N);
    // for(int i = 0; i < N; i++){
    //     cin >> v[i].s >> v[i].p;
    //     v[i].idx = i + 1;
    // }
    // sort(v.begin(), v.end());
    // for(int i = 0; i < N; i++){
    //     cout << v[i].idx << endl;
    // }

    priority_queue<hoge, vector<hoge>, greater<hoge> >Q;
    for(int i = 1; i <= N; i++){
        hoge h;
        cin >> h.s >> h.p;
        h.idx = i;
        Q.push(h);
    }
    while(!Q.empty()){
        cout << Q.top().idx << endl;
        Q.pop();
    }

    return 0;
}

Measured memory_bytes: 256