akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for(int i = 0; i < (n); i++)
#define rep1(i, n) for(int i = 1; i <= (n); i++)
#define co(x) cout << (x) << "\n"
#define cosp(x) cout << (x) << " "
#define ce(x) cerr << (x) << "\n"
#define cesp(x) cerr << (x) << " "
#define Would
#define you
#define please

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

	int N;
	cin >> N;

	int t[100001] = {};
	int x[100001] = {};
	int y[100001] = {};

	rep1(i, N) {
		cin >> t[i] >> x[i] >> y[i];
	}

	int OK = 1;

	rep(i, N) {
		if (t[i + 1] - t[i] < abs(x[i + 1] - x[i]) + abs(y[i + 1] - y[i])) {
			OK = 0;
		}
		int td = (t[i + 1] - t[i]) % 2;
		int xy = (abs(x[i + 1] - x[i]) + abs(y[i + 1] - y[i])) % 2;
		if (td != xy) OK = 0;
	}

	if (OK) co("Yes");
	else co("No");

	Would you please return 0;
}

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

int main() {
    //<Code>
    string s;
    cin >> s;
    if (s[2]==s[3] && s[4]==s[5]) {
        cout << "Yes" << endl;
    } else {
        cout << "No" << endl;
    }
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <cmath>
#include <queue>
#include <map>
#include <unordered_map>
#include <set>
#include <functional>
#include <bitset>
#include <cassert>
#include <random>
using namespace std;
using ll = long long;

int bcnt(int a) {
	int ret = 0;
	while (a > 0) {
		ret += a & 1;
		a >>= 1;
	}
	return ret;
}

int main() {
	int n, m; cin >> n >> m;
	vector<int> b(m), p(m);
	for (int i = 0; i < m; i++) {
		int k; cin >> k;
		for (int j = 0; j < k; j++) {
			int a; cin >> a;
			b[i] += 1 << (a - 1);
		}
	}
	for (int i = 0; i < m; i++) cin >> p[i];
	int ans = 0;
	for (int i = 0; i < (1 << n); i++) {
		bool flag = true;
		for (int j = 0; j < m; j++) {
			flag &= (bcnt(b[j] & i) & 1) == p[j];
		}
		ans += flag;
	}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#include<unordered_set>
#include<unordered_map>
using namespace std;
#define REP(i,m,n) for(int i=(m);i<(n);i++)
#define rep(i,n) REP(i,0,n)
#define pb push_back
#define all(a) a.begin(),a.end()
#define rall(c) (c).rbegin(),(c).rend()
#define mp make_pair
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef long double ld;
const ll inf=1e9+7;
const ll mod=1e9+7;
int main(){
    ll n,a,b,c;cin>>n>>a>>b>>c;
    vector<ll>l(n);
    rep(i,n){
        cin>>l[i];
    }
    vector<vector<ll> >dp(4,vector<ll>(1<<n,inf));
    dp[0][0]=0;
    rep(i,3){
        rep(j,1<<n){
            rep(k,1<<n){
                if(j&k)continue;
                ll cnt=0;
                rep(h,n){
                    if((1<<h)&k)cnt+=l[h];
                }
                if(cnt==0)continue;
                ll s;
                if(i==0)s=abs(cnt-a);
                if(i==1)s=abs(cnt-b);
                if(i==2)s=abs(cnt-c);
                dp[i+1][j|k]=min(dp[i+1][j|k],dp[i][j]+s);
            }
        }
    }
    ll ans=inf;
    rep(i,1<<n){
        ll cnt=0;
        rep(j,n){
            if((1<<j)&i)cnt++;
        }
        cnt-=3;
        ans=min(ans,dp[3][i]+cnt*10);
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 256
//{{{
#include<algorithm>
#include<cmath>
#include<deque>
#include<fstream>
#include<iomanip>
#include<iostream>
#include<map>
#include<numeric>
#include<queue>
#include<random>
#include<set>
#include<sstream>
#include<sys/time.h>
#include<unordered_map>
#include<unordered_set>
#include<vector>
using ll = long long;
enum : int { M = (int)1e9 + 7 };
enum : ll { MLL = (ll)1e18L + 9 };
using namespace std;
#ifdef LOCAL
#include"rprint2.hpp"
#else
#define FUNC(name) template <ostream& out = cout, class... T> void name(T&&...){ }
FUNC(printde) FUNC(printdbe) FUNC(printdwe) FUNC(printdu);
#endif
template <template <class T, class = std::allocator<T>> class V, class E>
istream& operator >> (istream& in, V<E>& v){ for(auto& e : v){ in >> e; } return in; }
//}}}

int main(){
    cin.tie(0); ios::sync_with_stdio(false);
    int a, b;
    cin >> a >> b;
    cout << (a <= 9 && b <= 9 ? a * b : -1) << '\n';
}


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

using namespace std;

using LL = long long;

template<typename T>
ostream& operator << (ostream& out, const vector<T>& v) {
    out << "[";
    for(const auto& x : v) {
        out << x << ", ";
    }
    return out << "]";
}

template<typename S, typename T>
ostream& operator << (ostream& out, const pair<S, T>& p) {
    return out << "{" << p.first << ", " << p.second << "}";
}

const LL MOD = 1000000007;


int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    
    vector<LL> inv(2e6, 0);
    inv[1] = 1;
    for(int i = 2; i < 2e6; ++i) {
        inv[i] = (MOD - (MOD / i) * inv[MOD % i] % MOD) % MOD;
    }
    
    LL K;
    string S;
    cin >> K >> S;
    LL N = S.length();
    vector<LL> pow25(K + 1, 1), pow26(K + 1, 1), binom(K + 1, 1);
    for(int i = 1; i <= K; ++i) {
        pow25[i] = (pow25[i - 1] * 25) % MOD;
        pow26[i] = (pow26[i - 1] * 26) % MOD;
        binom[i] = (binom[i - 1] * (N - 1 + i) % MOD) * inv[i] % MOD;
    }
    
    LL ans = 0;
    for(int i = 0; i <= K; ++i) {
        ans = (ans + (pow26[i] * pow25[K - i] % MOD) * binom[K - i] % MOD) % MOD;
    }
    cout << ans << "\n";
    
    return 0;
}


Measured memory_bytes: 43332
//#pragma GCC optimize("Ofast")

#pragma GCC optimize("O3")
#pragma GCC target("avx,avx2,fma")
#include<iostream>
#include<algorithm>
#include<string>
#include<cmath>
#include<cstdlib>
#include<set>
#include<vector>
#include<sstream>
#include<queue>
#include <iomanip>
#include<unordered_set>
#include <stack>
#include <unordered_map>
#include <map>
constexpr auto INF = 9223372036854775807;
typedef long long int ll;
typedef unsigned long long int ull;
typedef unsigned long int ul;
#define f(i,a,b) for(ll i=(ll)a;i<(ll)b;i+=1)
#define rf(i,a,b) for(ll i=(ll)a;i>=(ll)b;i-=1)
#define endl '\n'
#define N 1000000007 // prime modulo value 
#define M 998244353
#define all(x) x.begin(),x.end()
using namespace std;
// From Geeksforgeeks
inline ll gcd(ll a, ll b)
{
	if (b == 0)
		return a;
	return gcd(b, a % b);
}
// Power function took from geeksforgeeks
ll power(ll x, ll y)
{
	ll res = 1;

	x = x%N;
	if (x == 0) return 0;
	while (y > 0)
	{
		if (y & 1)
			res = (res * x)%N;
		y = y >> 1;
		x = (x * x)%N;
	}
	return res;
}
double dist(ll x1,ll y1, ll x2,ll y2)
{
	double ans = sqrt((x1 - x2) * (x1 - x2) + (y1 - y2) * (y1 - y2));
	return ans;
}
int main()
{
	ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
	string s;
	cin >> s;
	if (s[0] == 'S')
		cout << "Cloudy";
	else if (s[0] == 'C')
	{
		cout << "Rainy";
	}
	else
		cout << "Sunny";
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<string, int> psi;
#define rep(i, n) for(ll i = 0;i < n;i++)
#define FOR(i, m, n) for(ll i = m;i < n;i++)

int maxn = 1e5;

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

  int n;
  cin >> n;
  map<int, int> m;
  rep(i, n) {
    int a;
    cin >> a;
    m[a]++;
  }

  int ans = 0;
  for (auto&& i : m) {
    if (i.first > i.second) {
      ans += i.second;
    } else if (i.second > i.first) {
      ans += i.second-i.first;
    }
  }
  cout << ans << endl;
}

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

int main(){
  string s,t,u;
  cin >> s >> t;
  int a,b;
  cin >> a >> b;
  cin >> u;
  if(s==u) cout << a-1 << " " << b << endl;
  if(t==u) cout << a << " " << b-1 << endl;
}


Measured memory_bytes: 256
#include<cstdio>
#include<functional>
#include<algorithm>
using namespace std;
int main(void)
{
	int n,d,x,a,sum,i,y;
	scanf("%d",&n);
	scanf("%d %d",&d,&x);
	sum=x;
	for(i=0;i<n;i++)	{
		scanf("%d",&a);
		y=(d-1)/a+1;
//		printf("y%d\n",y);
		sum+=y;
	}
	printf("%d\n",sum);
	return 0;
}

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

#define rep(i, n) for(int i=0; i < n; i++)
#define reps(i, n) for(int i=1; i <= n; i++)
#define INF 1e9
#define ALL(v) v.begin(), v.end()
#define pb(x) push_back(x)
#define mp(x,y) make_pair(x,y)
#define rALL(x) x.rbegin(),x.rend()

using namespace std;
using ll=long long;

int inf=1000000;

bool isprime(int n){
  bool flag=true;
  if(n==1)return false;
  for(ll i=2; i*i<=n; i++){
    if(n%i==0){
      flag = false;
      break;
    }
  }
  return flag;
}

int MAX=100005;

int main(){
  int q;cin>>q;
  vector<int> sumc(MAX);
  sumc[0]=0;
  reps(i,MAX){
    sumc[i]=sumc[i-1];
    if(i%2){
      if(isprime(i) && isprime((i+1)/2))sumc[i]++;
    }
  }
  rep(i,q){
    int l,r;cin>>l>>r;
    cout<<sumc[r]-sumc[l-1]<<endl;
  }

}

Measured memory_bytes: 1024
#include<stdio.h>
#include<tuple>
#include<string>
#include <queue>
#include <iostream>

using namespace std;


int main(){
	int n, q;
	int time=0;
	scanf("%d %d", &n, &q);

	string temps;
	int tempv;
	queue< tuple<string,int> > processes;
	for(int i=0; i<n; ++i){
		cin >> temps >> tempv;
		tuple<string, int> tempt = make_tuple(temps, tempv);
		processes.push(tempt);	
	}

	int i = 0;
	while(n != 0){

		tuple<string, int> &process = processes.front();
		int &temp = get<1>(process);

		if(temp <= q){
			string &name = get<0>(process);
			time += temp;
			cout << name << " " << time << endl;
			processes.pop();
			n -= 1;
		}else{
			time += q;
			temp -= q;
			processes.push(make_tuple(get<0>(process), temp));
			processes.pop();
		}
	}

	return 0;
}


Measured memory_bytes: 6424
#include <bits/stdc++.h>
#define FOR(i, begin, end) for(int i=(begin);i<(end);i++)
#define REP(i, n) FOR(i,0,n)
#define int long long
using namespace std;

typedef pair<int, int> Pii;

void readint(int N, vector<int> &a);
void readdouble(int N, vector<double> &a);
void readindex(int N, vector<int> &a);



signed main(){

    int MAX_N = 55555;

    
    vector<bool> is_prime(MAX_N + 1, true);

    is_prime[0] = false;
    is_prime[1] = false;

    FOR(i, 2, MAX_N + 1){
        if(is_prime[i]){
            int tmp = i * 2;
            while(tmp <= MAX_N){
                is_prime[tmp] = false;
                tmp += i;
            }
        }
    }

    int N;
    cin >> N;
    vector<int> a(N);

    a[0] = 11;
    FOR(i, 1, N){
        FOR(p, a[i - 1] + 1, MAX_N){
            if(is_prime[p] && p % 5 == 1){
                a[i] = p;
                break;
            }
        }
    }

    REP(i, N){
        cout << a[i];
        if(i != N - 1) cout << " ";
    }
    
    return 0;
}








void readint(int N, vector<int> &a){
    string s;
    for(int i = 0; i < N - 1; i++){
        getline(cin, s, ' ');
        a[i] = atoi(s.c_str());
    }
    getline(cin, s, '\n');
    a[N - 1] = atoi(s.c_str());
}
void readdouble(int N, vector<double> &a){
    string s;
    for(int i = 0; i < N - 1; i++){
        getline(cin, s, ' ');
        a[i] = atof(s.c_str());
    }
    getline(cin, s, '\n');
    a[N - 1] = atof(s.c_str());
}
void readindex(int N, vector<int> &a){
    string s;
    for(int i = 0; i < N - 1; i++){
        getline(cin, s, ' ');
        a[i] = atoi(s.c_str()) - 1;
    }
    getline(cin, s, '\n');
    a[N - 1] = atoi(s.c_str()) - 1;
}

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

using namespace std;
typedef long long ll;

const int pmod = 1e9 + 7;
const int qmod = 1e9 + 9;

struct hash_t {
  int p, q;
  hash_t() {
    
  }
  hash_t(int x, int y) : p(x), q(y) {
  } 
  
  bool operator < (const hash_t &b) const {
    return make_pair(p, q) < make_pair(b.p, b.q);
  }
};

void exgcd(int a, int b, int &x, int &y) {
  if (!b)
    x = 1, y = 0;
  else
    exgcd(b, a % b, y, x), y -= (a / b) * x;
}

int mod_inv(int a, int p) {
  int x, y;
  exgcd(a, p, x, y);
  assert((ll) (x % p + p) % p * a % p == 1);
  return (x % p + p) % p;
}
hash_t operator + (hash_t x, hash_t y) {
  return hash_t((x.p + y.p) % pmod, (x.q + y.q) % qmod);
}
hash_t operator - (hash_t x, hash_t y) {
  return hash_t((x.p + pmod - y.p) % pmod, (x.q + qmod - y.q) % qmod);
} 
hash_t operator * (hash_t x, hash_t y) {
  return hash_t((ll) x.p * y.p % pmod, (ll) x.q * y.q % qmod);
}
hash_t operator / (hash_t x, hash_t y) {
  return hash_t((ll) x.p * mod_inv(y.p, pmod) % pmod, (ll) x.q * mod_inv(y.q, qmod) % qmod);
}

const int MaxN = 250010;

int n; char s[MaxN];
hash_t a[MaxN], b[MaxN];
hash_t x = hash_t(20010403, 20010423);

int main() {
  scanf("%d%s", &n, s + 1);
  a[n + 1] = hash_t(1, 1);
  for (int i = n; i; i--) {
    char c = s[i];
    if (c == '+') {
      a[i] = a[i + 1];
      b[i] = b[i + 1] + hash_t(1, 1);
    }
    if (c == '-') {
      a[i] = a[i + 1];
      b[i] = b[i + 1] - hash_t(1, 1);
    }
    if (c == '>') {
      a[i] = a[i + 1] * x;
      b[i] = b[i + 1] * x;
    } 
    if (c == '<') {
      a[i] = a[i + 1] / x;
      b[i] = b[i + 1] / x;
    }
  } 
  
  map<hash_t, int> h;
  
  ll ans = 0;
  for (int i = n; i; i--) {
    ++h[b[i + 1] / a[i + 1]];
    ans += h[(b[i] - b[1]) / a[i]];
  }
  cout << ans << "\n";
  return 0;
}



Measured memory_bytes: 35584
package main

import (
    "fmt"
    "strconv"
)

func main() {
    var A, B, cnt int
    fmt.Scan(&A, &B)
    for i:=A; i<=B; i++ {
        istr := strconv.Itoa(i)
        if istr[0] == istr[4] && istr[1] == istr[3] {
            cnt++
        }        
    }
    fmt.Println(cnt)
}

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

#define rep(i, a) for (int i = 0; i < (a); ++i)
#define REP(i, a, b) for (int i = (a); i < (b); ++i)
#define vi vector<int>

#define CHOOSE(a) CHOOSE2 a
#define CHOOSE2(a0, a1, a2, a3, a4, x, ...) x
#define debug_1(x1) cerr << #x1 << ": " << x1 << endl
#define debug_2(x1, x2) cerr << #x1 << ": " << x1 << ", " #x2 << ": " << x2 << endl
#define debug_3(x1, x2, x3) cerr << #x1 << ": " << x1 << ", " #x2 << ": " << x2 << ", " #x3 << ": " << x3 << endl
#define debug_4(x1, x2, x3, x4) cerr << #x1 << ": " << x1 << ", " #x2 << ": " << x2 << ", " #x3 << ": " << x3 << ", " #x4 << ": " << x4 << endl
#define debug_5(x1, x2, x3, x4, x5) cerr << #x1 << ": " << x1 << ", " #x2 << ": " << x2 << ", " #x3 << ": " << x3 << ", " #x4 << ": " << x4 << ", " #x5 << ": " << x5 << endl
#define debug(...) CHOOSE((__VA_ARGS__, debug_5, debug_4, debug_3, debug_2, debug_1, ~)) (__VA_ARGS__)

using namespace std;
using ll = long long;
using P = pair<int, int>;

void Main() {
  int n;
  cin >> n;
  vector<int> A(n);
  rep(i, n) cin >> A[i];
  map<int, int> M;
  rep(i, n) M[A[i]]++;
  ll ans = 0;
  for (auto itr=M.begin();itr!=M.end();++itr) {
    ll v=itr->second;
    ans += v*(v-1)/2;
  }
  rep(i, n) cout << ans - M[A[i]] + 1 << endl;
}

int main() {
  std::cin.tie(nullptr);
  std::ios_base::sync_with_stdio(false);
  std::cout << std::fixed << std::setprecision(15);
  Main();
  return 0;
}


Measured memory_bytes: 10240
#pragma region Header

#include <iostream>
#include <iomanip>
#include <vector>
#include <unordered_map>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <array>
#include <tuple>
#include <string>
#include <algorithm>
#include <functional>
#include <cmath>
#include <numeric>
#include <bitset>
#include <cstdint>
#include <stdexcept>
using namespace std;

// 整数型

using i32 = int32_t;
using i64 = int64_t;
using u32 = uint32_t;
using u64 = uint64_t;

// [0,n)を昇順/降順でループ

#define rep(i, n) for (int i = 0; i < static_cast<int>(n); ++i)
#define repd(i, n) for (int i = static_cast<int>(n) - 1; i >= 0; --i)

// [a,b)を昇順/降順でループ

#define FOR(i, a, b) for (int i = static_cast<int>(a); i < static_cast<int>(b); ++i)
#define FORD(i, a, b) for (int i = static_cast<int>(b) - 1; i >= static_cast<int>(a); --i)

template <typename T>
int SZ(T x)
{
    return static_cast<int>(x.size());
}

#pragma endregion

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    cout << fixed << setprecision(15);

    int n;
    cin >> n;
    bool good = true;
    rep(i, n)
    {
        int a;
        cin >> a;
        good = good and (a % 2 == 1 or a % 3 == 0 or a % 5 == 0);
    }
    cout << (good ? "APPROVED" : "DENIED") << endl;

    return 0;
}


Measured memory_bytes: 3624
#include<stdio.h>
#include<stdlib.h>

struct node{
  struct node *right;
  struct node *left;
  struct node *parent;
  int key;
};
typedef struct node * Node;
#define NIL NULL

Node root;

void insert(int k){
  Node y = NIL;
  Node x = root;
  Node z;

  z = malloc(sizeof(struct node));
  z->key = k;
  z->left = NIL;
  z->right = NIL;

  while(x!=NIL){
    y = x;
    if(z->key < x->key){
      x = x->left;
	}

    else {
      x = x->right;
    } 
  }

  z->parent=y;
  if(y == NIL){ 
    root = z;
  }
  else if(z->key < y->key){
    y->left = z ;
  }
  else {
    y->right = z;
  } 
}

void inorder(Node u){

  if(u->left != NIL){
    inorder(u->left);
  }

  printf(" %d",u->key);

  if(u->right != NIL){
    inorder(u->right);
  }

}

void preorder(Node u){

  printf(" %d",u->key);

  if(u->left != NIL){
    preorder(u->left);
  }

  if(u->right != NIL){
    preorder(u->right);
  }

}


int main(){
  int n, i, x;
  char com[20];
  scanf("%d", &n);

  for ( i = 0; i < n; i++ ){
    scanf("%s", com);
     if ( com[0] == 'i' ){
      scanf("%d", &x);
      insert(x);
    } else if ( com[0] == 'p' ){
      inorder(root);
      printf("\n");
      preorder(root);
      printf("\n");
    }
  }

  return 0;
}

Measured memory_bytes: 24040
h,w,n = map(int, input().split())
stage = [input() for i in range(h)]
starts = [str(i) for i in range(n)]
goals = [str(i+1) for i in range(n)]
starts_y = [0 for i in range(n)]
starts_x = [0 for i in range(n)]
goals_y = [0 for i in range(n)]
goals_x = [0 for i in range(n)]

starts[0] = "S"
for y in range(h):
	for x in range(w):
		if stage[y][x] in starts:
			starts_y[starts.index(stage[y][x])] = y
			starts_x[starts.index(stage[y][x])] = x
		if stage[y][x] in goals:
			goals_y[goals.index(stage[y][x])] = y
			goals_x[goals.index(stage[y][x])] = x

move_y = [1,-1,0,0]
move_x = [0,0,1,-1]
sum = 0

for start_y, start_x, goal_y, goal_x in zip(starts_y, starts_x, goals_y, goals_x):
	bfs_map = [[-1 for j in range(w)] for i in range(h)]
	data_y = [start_y]
	data_x = [start_x]
	bfs_map[start_y][start_x] = 0
	goal = False
	
	while len(data_y) != 0 and not goal:
		y = data_y.pop(0)
		x = data_x.pop(0)
		goal = False
	
		for i in range(4):
			y += move_y[i]
			x += move_x[i]
			
			if y >= 0 and y < h and x >= 0 and x < w:
				if bfs_map[y][x] == -1 and stage[y][x] != "X":
					bfs_map[y][x] = bfs_map[y-move_y[i]][x-move_x[i]]+1
					data_y.append(y)
					data_x.append(x)
				if bfs_map[goal_y][goal_x] != -1:
					sum += bfs_map[goal_y][goal_x]
					goal = True
					break
			y -= move_y[i]
			x -= move_x[i]

print(sum)


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

struct node{
	int u, v, w, next;
	node(){}
	node(int _u, int _v, int _w, int _next){
		u = _u;
		v = _v;
		w = _w;
		next = _next;
	}
}Edge[333333];

int Count, head[333333];

int n;
int q, k, a, b, u, v, w;
bool vis[111111];
long long dis[111111];

void AddEdge(int u, int v, int w){
	Count++;
	Edge[Count] = node(u, v, w, head[u]);
	head[u] = Count;
}

void dfs(int x){
	vis[x] = 1;
	for(int i = head[x]; i; i = Edge[i].next){
		int v = Edge[i].v;
		if(vis[v]) continue;
		dis[v] = dis[x] + Edge[i].w;
		dfs(v);
	}
}

int main(){
	scanf("%d", &n);
	for(int k = 1; k < n; k++){
		scanf("%d%d%d", &u, &v, &w);
		AddEdge(u, v, w);
		AddEdge(v, u, w);
	}
		
	scanf("%d%d", &q, &k);
	dfs(k);
	while(q--){
		scanf("%d%d", &a, &b);
		printf("%lld\n", dis[a] + dis[b]);
	}
	return 0;
}

Measured memory_bytes: 10240
#include <stdio.h>

int A[2000];
int n;

int main(){
  int q,i,anser;

  scanf("%d",&n);

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

  scanf("%d",&q);

  int m[q];

  for(i=0; i < q; i++){
    scanf("%d",&m[i]);
    anser = solve(0,m[i]);
    if(anser == -1){
      printf("no\n");
    } else {
      printf("yes\n");
    }
  }
  
  return 0;
}

solve(int i,int m){
  if(m == 0){
    return 1;
  }
  if(i >= n){
    return -1;
  }
  if(solve(i+1,m) == 1){
    return 1;
  } else if(solve(i+1,m-A[i]) == 1){
    return 1;
  } else {
    return -1;
  }
}



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

int main(){
    int n;cin>>n;
    string p = "";
    string q = "";
    string temp;
    for(int i=0;i<n;i++){
        cin>>temp;
        p += temp;
        }
    for(int i=0;i<n;i++){
        cin>>temp;
        q += temp;
        }

    vector<int> original(n);
    for (int i=0;i<n;i++){
        original[i] = i+1;
    }
    vector<string> original_string;
    do {
        string target = "";
        for (auto i : original){
            target += to_string(i);
        }
        original_string.push_back(target);
    } while (next_permutation(original.begin(), original.end()));

    sort(original_string.begin(), original_string.end());

    int p_ind;
    int q_ind;
    for (int i=0;i<original_string.size();i++){
        if (original_string[i] == p){
            p_ind = i + 1;
        }
        if (original_string[i] == q){
            q_ind = i + 1;
        }
    }
    cout << abs(p_ind - q_ind) << endl;
    return 0;

}

Measured memory_bytes: 2424
#include<bits/stdc++.h>
using namespace std;
#define REP(i,N) for(int (i)=0;(i)<(N);(i)++)
#define FOR (i,m,n) for(int (i)=m;(i)<(n);(i)++)

int main(){
  int num;
  string spc;
  bool y=0;
  cin >> num;
  
  REP(i,num){
    cin >> spc;
    if(spc == "Y"){
      y=1;
      cout << "Four" << endl;
      break;
    }
    if(i==(num-1))cout << "Three" << endl;
  }
}

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

int main() {
	int x1, y1, x2, y2;
	int x3, y3, x4, y4;
	cin >> x1 >> y1 >> x2 >> y2;

	x3 = x2 - (y2 - y1);
	y3 = y2 + (x2 - x1);
	x4 = x3 - (x2 - x1);
	y4 = y3 - (y2 - y1);

	cout << x3 << " " << y3 << " " << x4 << " " << y4 << endl;

	return 0;
}

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

using namespace std;

int main() {
  int n,k,a[300000],num[300000];
  cin >> n >> k;
  for(int i = 0; i <= n; i++)
    num[i] = 0;
  for(int i = 0; i < n; i++) {
    cin >> a[i];
    num[a[i]]++;
  }

  int cnt = 0;
  for(int i = 0; i <= n; i++)
    if(num[i] != 0) cnt++;
  
  if(cnt <= k) {
    cout << 0 << endl;
    return 0;
  }

  sort(num,num+n+1,greater<int>());
  int ans = 0;
  for(int i = k; i <= n; i++)
    ans += num[i];

  cout << ans << endl;
}

Measured memory_bytes: 5228
import java.io.IOException;
import java.io.InputStream;
import java.util.NoSuchElementException;

public class Main {

	public static void main(String[] args) {
		FScanner sc = new FScanner();
		int A = sc.nextInt();
		int B = sc.nextInt();
		int C = sc.nextInt();
		if (A + B + C >= 22) {
			System.out.println("bust");
		} else {
			System.out.println("win");
		}
	}

}

class FScanner {
	private final InputStream in = System.in;
	private final byte[] buffer = new byte[1024];
	private int ptr = 0;
	private int buflen = 0;

	private boolean hasNextByte() {
		if (ptr < buflen) {
			return true;
		} else {
			ptr = 0;
			try {
				buflen = in.read(buffer);
			} catch (IOException e) {
				e.printStackTrace();
			}
			if (buflen <= 0) {
				return false;
			}
		}
		return true;
	}

	private int readByte() {
		if (hasNextByte())
			return buffer[ptr++];
		else
			return -1;
	}

	private boolean isPrintableChar(int c) {
		return 33 <= c && c <= 126;
	}

	public boolean hasNext() {
		while (hasNextByte() && !isPrintableChar(buffer[ptr]))
			ptr++;
		return hasNextByte();
	}

	public String next() {
		if (!hasNext())
			throw new NoSuchElementException();
		StringBuilder sb = new StringBuilder();
		int b = readByte();
		while (isPrintableChar(b)) {
			sb.appendCodePoint(b);
			b = readByte();
		}
		return sb.toString();
	}

	public long nextLong() {
		if (!hasNext())
			throw new NoSuchElementException();
		long n = 0;
		boolean minus = false;
		int b = readByte();
		if (b == '-') {
			minus = true;
			b = readByte();
		}
		if (b < '0' || '9' < b) {
			throw new NumberFormatException();
		}
		while (true) {
			if ('0' <= b && b <= '9') {
				n *= 10;
				n += b - '0';
			} else if (b == -1 || !isPrintableChar(b)) {
				return minus ? -n : n;
			} else {
				throw new NumberFormatException();
			}
			b = readByte();
		}
	}

	public int nextInt() {
		long nl = nextLong();
		if (nl < Integer.MIN_VALUE || nl > Integer.MAX_VALUE)
			throw new NumberFormatException();
		return (int) nl;
	}

	public double nextDouble() {
		return Double.parseDouble(next());
	}
}

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

int main(){
  ll N,M;
  cin >>N>>M;
  
  ll S=1;
  for(int i=0;i<N;i++){
    if(i==0){
      S*=M;
    }
    else{
      S*=M-1;
    }
  }
  
  cout << S <<endl;
}


Measured memory_bytes: 3632
// On the Way

#include <iostream>
#include <vector>
#include <math.h>
#include <string>

using namespace std;

int main()
{
    int A,B,C;
    cin >> A >> B >> C;
    if (A>B) {
        swap(A,B);
    }
    if (C >= A && C <= B) {
        cout << "Yes";
    }
    else {
        cout << "No";
    }


    return 0;
}

Measured memory_bytes: 256
n,*a=map(int,open(0).read().split())
mod=10**9+7
inv=[0]*(n+1)
for i in range(n):
	inv[i+1]=(inv[i]+pow(i+1,mod-2,mod))%mod
ans=0
for i,x in enumerate(a):
	ans+=x*(inv[i+1]+inv[n-i]-1)
	ans%=mod
for i in range(1,n+1):
	ans*=i
	ans%=mod
print(ans)

Measured memory_bytes: 14052
s = gets
N = s.count('N')
S = s.count('S')
W = s.count('W')
E = s.count('E')

if (N > 0 && S == 0) || (S > 0 && N == 0)  || (W > 0 && E == 0) || (E > 0 && W == 0) then
  puts("No")
else
  puts("Yes")
end


Measured memory_bytes: 1788
# D - Cake 123
x,y,z,k=map(int,input().split())
a=list(map(int,input().split()))
b=list(map(int,input().split()))
c=list(map(int,input().split()))

a.sort(reverse=True)
b.sort(reverse=True)
c.sort(reverse=True)

ab=[i+j for j in b for i in a]
ab.sort(reverse=True)
abc=[i+j for j in c[:k] for i in ab[:k]]
abc.sort(reverse=True)

print(*abc[:k],sep='\n')

Measured memory_bytes: 207540
#include <iostream>
using namespace	std;
int h,w,c[50][50];
void dfs(int y,int x){
  c[y][x]=0;
  for(int i=-1;i<=1;i++)
    for(int j=-1;j<=1;j++)
      if(0<=y+i&&y+i<h&&0<=x+j&&x+j<w)
        if(c[y+i][x+j]) dfs(y+i,x+j);
}

int main(){

  for(;cin>>w>>h,w;){
    int r=0;
    for(int i=0;i<h;i++) for(int j=0;j<w;j++) cin>>c[i][j];
    for(int i=0;i<h;i++) for(int j=0;j<w;j++){
        if(c[i][j]){
          r++;
          dfs(i,j);
        }
      }
    cout<<r<<endl;
  }
  return 0;

}

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

int main(){
  ll n,p,a,sum=1;
  cin >> n >> p;
  vector<int> v(n,0);
  r(i,n){
    cin >> a;
    v.at(i)=a%2;
  }
  sort(v.begin(),v.end());
  r(i,n-1)sum*=2;
  if(p==1&&v.at(n-1)==0)cout << 0<<endl;
  else if(p==0&&v.at(n-1)==0)cout << sum*2<<endl;
  else cout << sum << endl;
}

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

using namespace std;

#define mp make_pair
#define fi first
#define se second
#define all(v) v.begin(),v.end()
#define allarr(a) a , a + n
#define ll long long
#define ull unsigned long long 
#define pb push_back
#define fastio ios_base::sync_with_stdio(false) ; cin.tie(NULL); cout.tie(NULL)
typedef pair<int, int> pi;
typedef pair<ll,ll> pll; 
typedef pair<int,pi> trp ;
typedef vector<pi> vpi;
typedef vector<pll> vpll ;
// int ab  (int  x ) { return (x>0?x:-x); }
const int N = 1e5+5 ;
const ll mod = 1e9+7 ; 
ll dp[N][13]; 
int main(){
string s; 
cin >> s ;

dp[0][0]=1 ; 
for(int i = 0 ; i < (int)s.length() ; i++ ){
	for(int j = 0 ; j < 13 ; j++ ){
		for(int c = 0 ; c < 10 ; c++ ){
			if( int(s[i]-'0') == c || s[i]=='?'){
				dp[i+1][(j*10+c)%13] = (dp[i+1][(j*10+c)%13]+dp[i][j])%mod ;  
			}
		}
	}
}
cout << dp[(int)s.length()][5]<<endl; 

}

Measured memory_bytes: 10624
#include<bits/stdc++.h>
#define REP(i,n) for(int i=0,i##_len=(n);i<i##_len;++i)
#define int long long
using namespace std;
const int MAX_N = 3000;
deque<int> a;
int N;
int dp[2][MAX_N+1][MAX_N+1];

signed main(){
    cin>>N;
    a.resize(N);
    REP(i, N) cin >> a[i];
    for(int i=N-1;i>=0;--i){
        for(int j=N-1;j>=0;--j){
            REP(k,2){
                if(i+j<N) dp[k][i][j]=k?min(dp[1-k][i+1][j]-a[i],dp[1-k][i][j+1]-a[N-1-j])
                                       :max(dp[1-k][i+1][j]+a[i],dp[1-k][i][j+1]+a[N-1-j]);
            }
        }
    }
    cout<<dp[0][0][0]<<endl;
}

Measured memory_bytes: 139776
#include<bits/stdc++.h>
using namespace std;
                       ///****   Hasebul Hassan Chowdhury ***////
#define ms(a,v)        memset(a,v,sizeof a)
#define lll            long long
#define FOR(i,a,b)     for(int i=a;i<=b;i++)
#define fast           ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define Read           freopen("input.txt", "r", stdin)
#define Write          freopen("output.txt", "w", stdout)
#define INF            1e18


void solve()
{
  int x;
  cin>>x;
  if(x>=30) cout<<"Yes"<<endl;
  else cout<<"No"<<endl;
}

int main()
{
    fast
    #ifndef ONLINE_JUDGE
    //Read;
    //Write;
    #endif
    //sieve();
    //int cnt=1;
    //int t; scanf("%d",&t); while(t--) solve();
    solve();
}


Measured memory_bytes: 3656
from collections import Counter
from itertools import product

N=int(input())
S=list(input())
S_rev=list(reversed(S[N:])) #右側から読んだ右半分の文字を考える


leftlist=[] #左半分の分け方の組み合わせを格納
rightlist=[] #右半分について同様

for bit in product(range(2),repeat=N):
  #左半分、右半分について赤と青に塗り分ける
  red_left='' 
  blue_left=''
  red_right=''
  blue_right=''
  for j in range(N):
    if bit[j] == 1:
      red_left+=S[j] #bitに1が立っているところを赤に
      blue_right+=S_rev[j]
    else:
      blue_left+=S[j]
      red_right+=S_rev[j]
  leftlist.append("".join(red_left + "|" + blue_left)) #左の塗り方をリストに格納
  rightlist.append("".join(blue_right + "|" + red_right)) #右について同様
left=Counter(leftlist)
right=Counter(rightlist)

answer=0

for key,value in left.items():
  answer+= value * right[key] #同じkey(分け方）に対するredとblueの通りを掛け合わせる
print(answer)

Measured memory_bytes: 81776
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
#define MOD 1000000007
#define PI 3.141592653589793

int main(){
    int a, b, c;
    cin >> a >> b >> c;
    cout << (b-a == c-b ? "YES" : "NO") << endl;
}


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

#define ll long long

int main() {
  int N;
  cin >> N;
  string S;
  cin >> S;
  
  ll r = 0;
  ll g = 0;
  ll b = 0;
  
  for (int i = 0; i < N; i++) {
    if (S.at(i) == 'R') r++;
    if (S.at(i) == 'G') g++;
    if (S.at(i) == 'B') b++;
  }
  
  ll ans = r * g * b;
  for (int i = 1; i <= N / 2; i++) {
    int j = 0;
    while (j + 2 * i < N) {
      if (S.at(j) != S.at(j+i) && S.at(j+i) != S.at(j+2*i) && S.at(j+2*i) != S.at(j)) {
        ans--;
      }
      j++;
    }  
  }
  
  cout << ans << endl;

}




Measured memory_bytes: 3604
#include<bits/stdc++.h>
using namespace std;
int main()
{
  int n,k;
  cin>>n>>k;
  int A[n];
  for(int i=0;i<n;i++)
  {
    cin>>A[i];
  }
  int arr[n]={0};
  if(n==1)
  {
    cout<<0<<endl;
    return 0;
  }
  for(int i=1;i<n;i++)
  {
    int ans=abs(A[i]-A[i-1])+arr[i-1];
    for(int j=1;j<=k;j++)
    {
      ans=min(ans,i-j>=0?abs(A[i]-A[i-j])+arr[i-j]:INT_MAX);
    }
    arr[i]=ans;
  }
  cout<<arr[n-1];

}


Measured memory_bytes: 1024
using System;
using System.Linq;
using System.Collections.Generic;
using static System.Console;
using System.Text;
using System.IO;
using static System.Math;
using System.Numerics;

namespace AtCoder
{
    public class Program
    {
        public static void Main(string[] args)
        {
            //SetOut(new StreamWriter(OpenStandardOutput()) { AutoFlush = false });
            Solve();
            //Out.Flush();
            Read();
        }

        static void Solve()
        {
            var (N, K) = Slice2<long>();
            var ans = (long)Pow(N / K, 3);
            if (K % 2 == 0 && K / 2 <= N)
                ans += (long)Pow((N - K / 2) / K + 1, 3);
            WriteLine(ans);
        }


        static long Mod = (long)1e9 + 7;
        static public long[] Sarray() { return ReadLine().Split().Select(long.Parse).ToArray(); }
        static public List<long> Slist() { return ReadLine().Split().Select(long.Parse).ToList(); }
        static public (T1 a, T2 b) Slice<T1, T2>()
        {
            var t = ReadLine().Split();
            return (
            (T1)Convert.ChangeType(t[0], typeof(T1)),
            (T2)Convert.ChangeType(t[1], typeof(T2)));
        }
        static public (T a, T b) Slice2<T>()
        {
            var t = ReadLine().Split();
            return (
            (T)Convert.ChangeType(t[0], typeof(T)),
            (T)Convert.ChangeType(t[1], typeof(T)));
        }
        static public (T a, T b, T c) Slice3<T>()
        {
            var t = ReadLine().Split();
            return (
            (T)Convert.ChangeType(t[0], typeof(T)),
            (T)Convert.ChangeType(t[1], typeof(T)),
            (T)Convert.ChangeType(t[2], typeof(T)));
        }
    }
}

Measured memory_bytes: 27840
#include <bits/stdc++.h>
typedef long long ll;
#define rep(i,m,n) for(ll i = (m); i < (n); i++)
#define rrep(i,m,n) for(ll i = (m); i >= (n); i--)
#define print(x) cout << (x) << endl;
#define print2(x,y) cout << (x) << " " << (y) << endl;
#define printa(x,n) for(ll i = 0; i < n; i++){ cout << (x[i]) << " \n"[i == n-1];}
#define printp(x,n) for(ll i = 0; i < n; i++){ cout << "(" << x[i].first << ", " << x[i].second << ") "; } cout << endl;
#define INF (1e18)
using namespace std;
const ll MOD = 1e9 + 7;
typedef pair<ll, ll> lpair;

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll N;
    ll T[100010], A[100010];
    cin >> N;
    bool flg = true;
    rep(i,0,N) cin >> T[i];
    rep(i,0,N) cin >> A[i];
    ll h[100010] = {};
    h[0] = T[0];
    rep(i,0,N-1){
        if(T[i] != T[i+1]){
            h[i+1] = T[i+1];
        }
    }
    if(h[N-1] != 0 && h[N-1] != A[N-1]) flg = false;

    h[N-1] = A[N-1];
    rrep(i,N-1,1){
        if(A[i] != A[i-1]){
            if(h[i-1] == 0){
                h[i-1] = A[i-1];
            }else if(h[i-1] != A[i-1]){
                flg = false;
            }
        }
    }
    rep(i,0,N){
        if(h[i] > T[i] || h[i] > A[i]) flg = false;
    }
    if(!flg){
        print(0);
        return 0;
    }
    ll ans = 1;
    rep(i,0,N){
        if(h[i] == 0){
            ans *= min(T[i], A[i]);
            ans %= MOD;
        }
    }
    print(ans);
}


Measured memory_bytes: 2560
#include <iostream>
#include <vector>
#include <map>
typedef long long ll;
using namespace std;
ll mod = 1000000007;
ll gcd(ll n1, ll n2){
    return n2 == 0 ? n1 : gcd(n2, n1 % n2);
}

ll lcm(ll n1,ll n2){
    return n1 / gcd(n1, n2) * n2;
}

ll inverse(ll a,ll m){
    ll b = m,u = 1,v = 0;
    while(b){
        ll t = a /b;
        swap(a -= t * b,b);
        swap(u -= t * v,v);
    }
    return (u % m + m) % m;
}

map<ll,ll> divisor(ll a){
    map<ll, ll> mp;
    for (ll i = 2; i * i <= a;i++){
        while(a % i == 0){
            mp[i]++;
            a /= i;
        }
    }
    if (a > 1)
        mp[a]++;
    return mp;
}

int main(){
    int N;
    ll ans = 0;
    cin >> N;
    vector<ll> A(N);
    map<ll, ll> mp;

    for(int i = 0;i < N;i++){
        cin >> A[i];
        map<ll,ll> p = divisor(A[i]);
        for(auto v :p){
            mp[v.first] = max(mp[v.first], v.second);
        }
    }
    ll L = 1;
    for(auto v: mp){
        while(v.second){
            L *= v.first % mod;
            L %= mod;
            v.second--;
        }
    }
    for(int i = 0;i < N;i++){
        ans += (L % mod *inverse(A[i],mod) % mod) % mod;
    }
    ans = ans % mod;
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 896
#include<iostream> 
#include<algorithm> 
using namespace std; 
#define N 100010 
int main(){
int n,m,h[N],ma[N];
cin>>n>>m;
for(int i=1;i<=n;i++){
cin>>h[i];
ma[i]=0; 
}
for(int i=0;i<m;i++)
{ int a,b;
cin>>a>>b;
 ma[a]=max(ma[a],h[b]);
 ma[b]=max(ma[b],h[a]);
}
int ans=0;
for(int i=1;i<=n;i++){
ans+=h[i]>ma[i]; 
}
cout<<ans<<endl;
}

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

using ll = long long;

int main() {
  // 入力
  int N, K;
  cin >> N >> K;
  int x[N], y[N];
  for (int i = 0; i < N; i++) cin >> x[i] >> y[i];

  ll ans = 9 * 1e18;
  for (int i = 0; i < N; i++) { // x座標の左端
    for (int j = 0; j < N; j++) { // x座標の右端
      for (int k = 0; k < N; k++) { // y座標の下端
        for (int l = 0; l < N; l++) { // y座標の上端
          if (x[i] > x[j]) continue;
          if (y[k] > y[l]) continue;
          // 4点で作られる長方形に囲まれる点の数を数える
          int cnt = 0;
          for (int m = 0; m < N; m++) {
            if (x[i] <= x[m] && x[m] <= x[j] && y[k] <= y[m] && y[m] <= y[l]) cnt++;
          }

          if (cnt >= K) ans = min(ans, 1LL * (x[j] - x[i]) * (y[l] - y[k]));
        }
      }
    }
  }

  // 解答
  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 256
//Created by Kira

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

#define IOS cin.sync_with_stdio(0);cin.tie(0); cout.tie(0);
#define all(x) x.begin(), x.end()
#define sz(x) (int)x.size()
#define pii pair<int,int> 
#define pb push_back
#define vi vector<int> 
using ll = long long;

const int mod = 1e9 + 7;

ll pwr(ll a, ll b);
    



int main(){
   IOS

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

   vector<int> h(n);

   for(int & x : h)cin>>x;

   sort(all(h));

   ll c = 0;

   for(int i = 0; i < n-k; i++){
       c += h[i];
   }  

   cout<<c<<"\n";







}

ll pwr(ll a, ll b){
   a %= mod;	//Remove mod if not required
   ll res = 1;
   while(b > 0){
    if(b&1)
        res = res * a % mod;
        a = a * a % mod;
    b >>= 1;
    }

    return res;
}




Measured memory_bytes: 1024
N, M = map(int, input().split())
G = [[0] * N for _ in range(N)]
for _ in range(M):
    a, b = map(lambda x: int(x)-1, input().split())
    G[a][b] = G[b][a] = 1
visited = [False] * N


def dfs(v):
    visited[v] = True
    if all(visited):
        visited[v] = False
        return 1
    ret = 0
    for u in range(N):
        if v == u or visited[u] or G[v][u] == 0:
            continue
        ret += dfs(u)
    visited[v] = False
    return ret


print(dfs(0))


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

const long long MOD = 1e9 + 7;

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

    long long pow = 1;
    for (int i = 1; i <= n; i++) {
        pow *= (long long) i;
        pow %= MOD;
    }

    cout << pow << endl;

    return 0;
}


Measured memory_bytes: 384
kis = input()
gus = input()
a = len(kis)
b = len(gus)
c = ""
if a == b:
 for i in range(a) :
  c += kis[i] + gus[i]
else:
  for i in range(b): 
   c += kis[i] + gus[i]
  c += kis[a-1]

print(c)

Measured memory_bytes: 3060
#include<iostream>
using namespace std;
int main()
{
	int n,k;
	cin>>n>>k;
	int x=1;
	for(int i=1;i<=n;i++)
	{
		if(x<k)
			x*=2;
		else
			x+=k;
	}
	cout<<x<<endl;
}

Measured memory_bytes: 256
#include <algorithm>
#include <cassert>
#include <cfloat>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <deque>
#include <iostream>
#include <iterator>
#include <limits>
#include <map>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string>
#include <tuple>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>

#define FOR(i,k,n) for(int(i)=(k);(i)<(n);++(i))
#define rep(i,n) FOR(i,0,n)
#define all(v) begin(v),end(v)
#define debug(x) std::cerr<<#x<<": "<<x<<"\n"
#define debug2(x,y) std::cerr<<#x<<": "<<x<<", "<<#y<<": "<<y<<"\n"
#define debug3(x,y,z) std::cerr<<#x<<": "<<x<<", "<<#y<<": "<<y<<", "<<#z<<": "<<z<<"\n"

using ll=long long;
using vi=std::vector<int>;
using vvi=std::vector<vi>;
using vll=std::vector<ll>;
using vvll=std::vector<vll>;
template<typename T> using vvec=std::vector<std::vector<T>>;
template<typename T>
auto make_v(size_t sz){return std::vector<T>(sz);}
template<typename T,typename... Ts>
auto make_v(size_t sz,Ts...ts){return std::vector<decltype(make_v<T>(ts...))>(sz,make_v<T>(ts...));}
template<typename T>
void fill_v(T&var,const T&x){var=x;}
template<typename V,typename T>
void fill_v(V&v,const T&x){for(auto&& w:v){fill_v(w,x);}}

template<typename T> std::ostream& operator<<(std::ostream&s,const std::vector<T>&v){
  int sz=v.size();s<<"\n";rep(i,sz){s<<v[i];if(i<sz-1){s<<"\t";}}s<<"\n";return s;}
template<typename T> std::ostream& operator<<(std::ostream&s,const std::vector<std::vector<T>>&v){
  for(auto&& w:v){s<<w;}return s;}
template<typename T> std::ostream& operator<<(std::ostream&s,const std::deque<T>&v){
  int sz=v.size();s<<"\n";rep(i,sz){s<<v[i];if(i<sz-1){s<<"\t";}}s<<"\n";return s;}
template<typename T> std::ostream& operator<<(std::ostream&s,const std::deque<std::deque<T>>&v){
  for(auto&& w:v){s<<w;}return s;}
template<typename T> std::ostream& operator<<(std::ostream&s, const std::set<T>&v){
  s<<"\n";for(auto&& elm:v){s<<elm<<"\t";}s<<"\n";return s;}

inline void scan(int&a){scanf("%d",&a);}
inline void scan(ll&a){scanf("%lld",&a);}
inline void scan(char&a){scanf(" %c",&a);}
inline void scan(double&a){scanf("%lf",&a);}
template<typename T>
inline void scan(std::vector<T>&v){for(auto&& sv:v){scan(sv);}}
template<typename First,typename...Args>
inline void scan(First&f,Args&...args){scan(f);scan(args...);}
inline void scan(std::string&s){char BUF[3000000];scanf(" %s",BUF);s=std::string(BUF);}
inline void print(int a){printf("%d\n",a);}
inline void print(ll a){printf("%lld\n",a);}
inline void print(double a){printf("%.12f\n",a);}
inline void print(std::string s){std::cout<<s<<"\n";}

using namespace std;

int calc(vi& a, int i) {
  int ret = a[0];
  rep (j, 3) {
    if ((i >> j) & 1) {
      ret += a[j+1];
    } else {
      ret -= a[j+1];
    }
  }
  return ret;
}

int main() {
  vi a(4);
  rep (i, 4) {
    char c;
    scan(c);
    a[i] = c - '0';
  }
  rep (i, 8) {
    if (calc(a, i) == 7) {
      rep (j, 3) {
        printf("%d%c", a[j], "-+"[(i >> j) & 1]);
      }
      printf("%d=7\n", a[3]);
      return 0;
    }
  }

  return 0;
}


Measured memory_bytes: 256
package main

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

var sc = bufio.NewScanner(os.Stdin)

func main() {
	sc.Split(bufio.ScanWords)

	a := nextInt()
	b := nextInt()

	if a-2*b <= 0 {
		fmt.Println(0)
		return
	}
	fmt.Println(a - 2*b)
}

// ---- readfunc
func nextInt() int {
	sc.Scan()
	i, e := strconv.Atoi(sc.Text())
	if e != nil {
		panic(e)
	}
	return i
}
func nextStr() string {
	sc.Scan()
	return sc.Text()
}


Measured memory_bytes: 1772
D, G = map(int,input().split())
p,c = {},{}
for i in range(1,D+1):
  pi,ci = map(int,input().split())
  p[i] = pi
  c[i] = ci
ans = sum(p.values())

for i in range(2**D):
  cmp = {i:False for i in range(1,D+1)}
  score = 0
  ans_tmp = 0
  for j in range(D):
    if (i >> j) & 1:
      cmp[j+1] = True
      score += (j+1)*100*p[j+1]+c[j+1]
      ans_tmp += p[j+1]
  keys = [k for k,v in cmp.items() if v == False]
  if G > score and len(keys) > 0:
    if (G-score) // (max(keys)*100) <= p[max(keys)]:
      ans_tmp += (G-score) // (max(keys)*100)
      if (G-score) % (max(keys)*100) != 0:
        ans_tmp += 1 
    else:
      ans_tmp = sum(p.values())
  ans = min(ans, ans_tmp)
        
print(ans)

Measured memory_bytes: 3064
#include <bits/stdc++.h> 
#include <vector>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define size_of_array(array) (sizeof(array)/sizeof(array[0]))
using ll =long long;
using namespace std;
using Graph=vector<vector<int>>;
using Field=vector<vector<int>>;

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

const double PI=(acos(-1));

int main(){
    int x;
    cin>>x;
    x/=200;
    int ans;
    ans=10-x;
    cout<<ans<<endl;

}

Measured memory_bytes: 3592
#include<bits/stdc++.h>
 
#define rep(i,n) for(ll i = 0;i < n;++i)
#define all(v) v.begin(),v.end()
using namespace std;
using ll = long long;
typedef pair<int,int> P;
 
const int INF = 1001001001;
const long double PI = (acos(-1));
const int mod = 1e9+7;

int vx[4] = {0,1,0,-1};
int vy[4] = {1,0,-1,0};
int re[1002][1002];
queue<int> qx;
queue<int> qy;


void bfs(vector<vector<char>>& map){
    while(!qx.empty()){
        int x = qx.front();qx.pop();
        int y = qy.front();qy.pop();
        rep(i,4){
            int nx = x + vx[i];
            int ny = y + vy[i];
            if(re[nx][ny] != 0) continue;
            if(map[nx][ny] != '#'){
                re[nx][ny] = re[x][y] + 1;
                qx.push(nx);
                qy.push(ny);
            }
        }
    } 
}

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



    int h,w;
    cin >> h >> w;
    vector<vector<char>> map(h+2,vector<char> (w+2));
    rep(i,h+2)rep(j,w+2){
        map[i][j] = '#';
    }
    for(int i = 1;i < h+1;++i){
        for(int j = 1;j < w+1;++j){
            char c;
            cin >> c;
            map[i][j] = c;
        }
    }
    bool flag = false;
    for(int i = 1;i < h+1;++i){
        for(int j = 1;j < w+1;++j){
            if(map[i][j] == '#'){
                qx.push(i);
                qy.push(j);
            }
        }
    }
    bfs(map);
    int ans = 0;
    for(int i = 1;i < h+1;++i){
        for(int j = 1;j< w+1;++j){
            ans = max(ans,re[i][j]);
        }
    }
    cout << ans << endl;

    cout << endl;
    return 0;
}


Measured memory_bytes: 9984
import           Control.Monad
import           Control.Applicative

main :: IO ()
main = do
  o <- getLine
  e <- getLine

  putStrLn $ gen o e
 where
  gen o e =
    concatMap (\(a, b) -> a : [b]) (zip o e)
      ++ if length o > length e then [last o] else ""

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

using namespace std;

const long INFTY = (long(1) << 40);

class Node
{
public:
    int v, cost;
    Node(int n = 0, int c = 0) : v(n), cost(c) {}
};

bool operator<(const Node &n1, const Node &n2)
{
    return n1.cost < n2.cost;
}

class WF
{
public:
    vector<vector<long>> pairs;
    WF(int N = 0, int Q = 0)
    {
        pairs.resize(N);
        for (int i = 0; i < N; i++)
        {
            pairs[i].resize(N, INFTY);
            pairs[i][i] = 0;
        }
        load_cost(Q);
    }

    void load_cost(int Q)
    {
        int u, v, c;
        for (int i = 0; i < Q; i++)
        {
            cin >> u >> v >> c;
            pairs[u][v] = c;
        }
    }

    void wf()
    {
        int N = pairs.size();
        for (int k = 0; k < N; k++)
        {
            for (int i = 0; i < N; i++)
            {
                if (pairs[i][k] == INFTY)
                    continue;
                for (int j = 0; j < N; j++)
                {
                    if (pairs[k][j] == INFTY)
                        continue;
                    if (pairs[i][j] > pairs[i][k] + pairs[k][j])
                    {
                        pairs[i][j] = pairs[i][k] + pairs[k][j];
                    }
                }
            }
        }
    }

    bool negative()
    {
        for (int i = 0; i < pairs.size(); i++)
            if (pairs[i][i] < 0)
                return true;
        return false;
    }
};

int main()
{
    int N, Q;
    cin >> N >> Q;
    WF wf(N, Q);
    wf.wf();
    if (wf.negative())
    {
        cout << "NEGATIVE CYCLE" << endl;
    }
    else
    {
        for (int i = 0; i < N; i++)
        {
            for (int j = 0; j < N; j++)
            {
                if (j)
                    cout << " ";
                if (wf.pairs[i][j] == INFTY)
                {
                    cout << "INF";
                }
                else
                {
                    cout << wf.pairs[i][j];
                }
            }
            cout << endl;
        }
    }
}


Measured memory_bytes: 3208
X,Y,A,B,C=map(int,input().split())
a=sorted(list(map(int,input().split())),reverse=True)
b=sorted(list(map(int,input().split())),reverse=True)
c=sorted(list(map(int,input().split())))
ans=sum(sorted(a[0:X]+b[0:Y]+c,reverse=True)[0:(X+Y)])
print(ans)

Measured memory_bytes: 110444