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


int main()
{
	string str,ttr;
	cin>>str>>ttr;
	int nt=ttr.size();
	int st=str.size();
	if(nt==st+1)
	{
		string kk=ttr.substr(0,st);
		if(kk==str)
		{
			cout<<"Yes";
			return 0;
	    }
	}
	cout<<"No";
}

Measured memory_bytes: 3636
using System;

namespace B
{
    class Program
    {
        static void Main(string[] args)
        {
            string[] KX = Console.ReadLine().Split(' ');
            int K = int.Parse(KX[0]);
            int X = int.Parse(KX[1]);

            int start = X - K+1;
            int end = X + K - 1;
            for(int i = start;i<=end;i++)
            {
                Console.Write(i.ToString() + " ");

            }
            Console.WriteLine(" ");
        }
    }
}


Measured memory_bytes: 13140
#include <bits/stdc++.h>
using namespace std;
int main()
{
    char a[4],b[4];
    gets(a);
    gets(b);
    if(a[0]==b[2]&&a[1]==b[1]&&a[2]==b[0])
       cout<<"YES"<<endl;
    else
       cout<<"NO"<<endl;
    return 0;
}

Measured memory_bytes: 256
#include <cstdio>

int main() {
        int n, m;
        scanf("%d%d", &n, &m);
        int road_num[51];
        for (int i=0; i<51; ++i) {
                road_num[i] = 0;
        }
        int city_a, city_b;
        for (int i=0; i<m; ++i) {
                scanf("%d%d", &city_a, &city_b);
                road_num[city_a]++;
                road_num[city_b]++;
        }
        for (int i=1; i<=n; ++i) {
                printf("%d\n", road_num[i]);
        }
}


Measured memory_bytes: 128
open Scanf
open Printf

let s = sscanf (read_line ()) "%s" (fun n -> n);;
(*S.reverse!*)
let len = String.length s;;
let dp = Array.make_matrix (len + 1) 13 0;;
dp.(0).(0) <- 1;;
let digit = ref 1;;
let mm = 1000000000 + 7;;
let _ =
for i = 0 to (len - 1) do
    let idx = len - 1 - i in
    if s.[idx] != '?' then
        let c = int_of_string (Char.escaped s.[idx]) in
        for j = 0 to 12 do
            dp.(i+1).(((c * !digit) mod 13 + j) mod 13) <- dp.(i+1).(((c * !digit) mod 13 + j) mod 13) + dp.(i).(j);
            dp.(i+1).(((c * !digit) mod 13 + j) mod 13) <- dp.(i+1).(((c * !digit) mod 13 + j) mod 13) mod mm
        done
    else
        for c = 0 to 9 do
            for j = 0 to 12 do
                dp.(i+1).(((c * !digit) mod 13 + j) mod 13) <- dp.(i+1).(((c * !digit) mod 13 + j) mod 13) + dp.(i).(j);
                dp.(i+1).(((c * !digit) mod 13 + j) mod 13) <- dp.(i+1).(((c * !digit) mod 13 + j) mod 13) mod mm
            done
        done;
    digit := !digit * 10;
    digit := !digit mod 13
done

let _ = printf "%d\n" dp.(len).(5);;


Measured memory_bytes: 15488
#include <bits/stdc++.h>
using namespace std;
#define SORT(a) sort((a).begin(), (a).end())
#define RSORT(a) reverse((a).begin(), (a).end())
#define rep(i, n) for (int i = 0; i < n; i++)
typedef long long ll;
const long long INF = 1LL << 60;

int main() {
  string s;
  ll k;
  cin >> s >> k;
  bool one = true;
  for (int i = 0; i < k; i++) {
    if (s[i] != '1') {
      one = false;
      cout << s[i] << endl;
      break;
    }
  }
  if (one) cout << 1 << endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(ll i=0;i<n;i++)
#define repl(i,l,r) for(ll i=(l);i<(r);i++)
#define per(i,n) for(ll i=n-1;i>=0;i--)
#define lper(i,r,l) for(ll i=r-1;i>=l;i--)
#define fi first
#define se second
#define mp make_pair
#define all(x) (x).begin(),(x).end()
#define CST(x) cout<<fixed<<setprecision(x)
using ll=long long;
using vl=vector<ll>;
using vvl=vector<vector<ll>>;
using pl=pair<ll,ll>;
const ll MOD=1000000007;
const ll MOD9=998244353;
const int inf=1e9+10;
const ll INF=4e18;
const ll dy[4]={1,0,-1,0};
const ll dx[4]={0,-1,0,1};
long long fac(ll a){
    long long ans=1;
    while(a>1){
        ans*=a;
        ans%=1000000007;
        a--;
    }
    return ans;
}
long long modinv(long long a, long long m) {
    long long b = m, u = 1, v = 0;
    while (b) {
        long long t = a / b;
        a -= t * b; swap(a, b);
        u -= t * v; swap(u, v);
    }
    u %= m; 
    if (u < 0) u += m;
    return u;
}
int main(){
    ll a,b;
    cin >> a >> b;
    if((a+b)%3!=0){
        cout << 0 << endl;
        return 0;
    }
    ll c=(a+b)/3;
    if(2*c<b||2*b<a){
        cout << 0 << endl;
        return 0;
    }
    ll count=0;
    rep(i,c+1){
        if(2*c-i==a&&c+i==b)count=i;
    }
    count=min(count,c-count);
    ll ans=1;
    rep(i,count){
        ans*=c-i;
        ans%=MOD;
    }
    rep(i,count){
        ans*=modinv(i+1,MOD);
        ans%=MOD;
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#define INF 100000000000
using namespace std;
int main() {
	long long n, t, q;
	cin >> n >> t >> q;
	vector<long long>a(n);
	vector<int>d(n);
	vector<long long>s(n);
	for (int i = 0; i < n; i++) {
		cin >> a[i] >> d[i];
	}
	for (int i = 0; i < n; i++) s[i] = INF;
	long long ha = 0;
	for (int i = 0; i < n-1; i++) {
		if (d[i] == 1 && d[i + 1] == 2) {
			ha = (a[i] + a[i + 1]) / 2;
			for (int j = i; j > -1; j--) {
				if (d[j] == 2) break;
				if (s[j] == INF) s[j] = ha;
			}
			for (int j = i + 1; j < n; j++) {
				if (d[j] == 1) break;
				if (s[j] == INF) s[j] = ha;
			}
		}
	}
	for (int i = 0; i < q; i++) {
		int x;
		cin >> x;
		x--;
		if (s[x] == INF) {
			if (d[x] == 1) cout << a[x] + t << endl;
			else cout << a[x] - t << endl;
		}
		else {
			if (abs(a[x] - s[x]) < t) {
				cout << s[x] << endl;
			}
			else {
				if (d[x] == 1) cout << a[x] + t << endl;
				else cout << a[x] - t << endl;
			}
		}
	}
	return 0;
}


Measured memory_bytes: 4624
#include <iostream>
#include <algorithm>
#include <vector>
using namespace std;
using ll = long long;
int main(int argc, char const *argv[]) {
  ll n;
  vector<ll>  v;

  cin>>n;
  for(int i=0;i<5;i++){
    ll tmp;
    cin>>tmp;
    v.push_back(tmp);
  }

  auto m=min_element(v.begin(),v.end());

  if(n%*m!=0){
    cout<<n/(*m)+5<<endl;
  }else{
    cout<<n/(*m)+4<<endl;
  }
  return 0;
}


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

#define rep(i,n) for(ll i=0;i<n;++i)
#define all_map(itr,mp) for(auto itr=mp.begin();itr!=mp.end();itr++)
#define ALL(a) (a).begin(),(a).end()

using namespace std;
using ll  = long long;
using pll = pair<ll, ll>;

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

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

Measured memory_bytes: 256
s=' '+input()+' '
for _ in range(int(input())):
    l=input().split()
    o=l[0]
    a=int(l[1])+1; b=int(l[2])+2
    if o=='print': print(s[a:b])
    if o=='reverse': s=s[:a]+s[b-1:a-1:-1]+s[b:]
    if o=='replace': s=s[:a]+l[3]+s[b:]


Measured memory_bytes: 5612
#include <bits/stdc++.h>
using namespace std;
#define mid ((left + right) >> 1)
#define lson rt<<1, left, mid
#define rson rt<<1|1, mid + 1, right

typedef long long ll;
const int N = 1e5 + 5;

ll lazy[N << 2], t[N << 2];
int n, q;

void push_up(int rt) {
    t[rt] = t[rt << 1] + t[rt << 1 | 1];
}

void push_down(int rt, int len) {
    if (lazy[rt]) {
        lazy[rt << 1] = lazy[rt];
        lazy[rt << 1 | 1] = lazy[rt];
        t[rt << 1] = (ll) lazy[rt] * (len - len / 2);
        t[rt << 1 | 1] = (ll) lazy[rt] * (len / 2);
        lazy[rt] = 0;
    }
}

void update(int rt, int left, int right, int l, int r, ll v) {
    if (l == left && r == right) {
        t[rt] = v * (right - left + 1);
        lazy[rt] = v;
        return;
    }
    push_down(rt, right - left + 1);
    if (mid >= r) update(lson, l, r, v);
    else if (mid < l) update(rson, l, r, v);
    else update(lson, l, mid, v), update(rson, mid + 1, r, v);
    push_up(rt);
}

void add(int rt, int left, int right, int l, int r) {
    if (l == left && r == right) {
        t[rt] += (right - left + 1);
        lazy[rt] += 1;
        return;
    }
    push_down(rt, right - left + 1);
    if (mid >= r) add(lson, l, r);
    else if (mid < l) add(rson, l, r);
    else add(lson, l, mid), add(rson, mid + 1, r);
    push_up(rt);
}

ll query(int rt, int left, int right, int l, int r) {
    if (l == left && r == right) {
        return t[rt];
    }
    push_down(rt, right - left + 1);
    if (mid >= r) return query(lson, l, r);
    else if (mid < l) return query(rson, l, r);
    else return query(lson, l, mid) + query(rson, mid + 1, r);
}

pair<ll, int> left_bound(int rt, int left, int right, int r, ll sum, ll water) {
    if (right <= 1) return {(water + sum)/ r, 1};
    if (left >= r) return {water + query(1, 1, n, r, r), r};
    if (mid >= r) return left_bound(lson, r, sum, water);

    int len = r - mid;
    ll orginal_sum = query(1,1,n,mid+1, r);
    ll filling_height_ceil = ((water + orginal_sum) + (len - 1ll)) / len;
    ll filling_height_floor = (water + orginal_sum) / len;
    ll val_mid = query(1, 1, n, mid, mid), val_mid_1 = query(1, 1, n, mid + 1, mid + 1);
    if (filling_height_ceil > val_mid) {
        return left_bound(lson, r, sum, water);
    } else if (filling_height_floor < val_mid_1) {
        return left_bound(rson, r, sum, water);
    } else return {filling_height_floor, mid + 1};
}

int main() {
    ios::sync_with_stdio(false);
    cin >> n >> q;
    while (q--) {
        int a;
        ll b;
        cin >> a >> b;
        ll cur_sum = query(1, 1, n, 1, a);
        auto res = left_bound(1, 1, n, a, cur_sum, b);
        ll original_sum = query(1, 1, n, res.second, a);
        update(1, 1, n, res.second, a, res.first);
        b -= res.first * (a - res.second + 1) - original_sum;
        if (b == 0) continue;
        add(1, 1, n, res.second, res.second + b - 1);
    }
    for (int i = 1; i <= n; i++) {
        cout << query(1, 1, n, i, i) << endl;
    }
    return 0;
}


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

int mod = 1000000007;
int64_t large = 9223372036854775807;
double PI = 3.141592653589793;

int main()
{
    int N;
    cin >> N;
    vector<int> list(N);
    for (int i = 0; i < N; i++)
        cin >> list[i];
    vector<int> ans(N);

    int now = N / 2, dis = -1;
    for (int i = 0; i < N; i++)
    {
        ans[now] = list[i];
        now += dis;
        dis *= -1;
        if (dis > 0)
            dis++;
        if (dis < 0)
            dis--;
    }
    if (N % 2 == 1)
        reverse(ans.begin(), ans.end());
    for (auto x : ans)
        cout << x << " ";
}

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

int solve(int n, int m, int l) {
    vector<vector<int>> dp(n, vector<int>(l + 1, 1e9));
    dp[0][l] = 0;
    vector<vector<tuple<int, int, int>>> adj(n);
    for (int i = 0; i < m; i++) {
        int a, b, d, e;
        cin >> a >> b >> d >> e;
        a--, b--;
        adj[a].emplace_back(b, d, e);
        adj[b].emplace_back(a, d, e);
    }

    priority_queue<pair<int, int>, vector<pair<int, int>>, greater<>> que;
    que.emplace(0, l);
    while (!que.empty()) {
        auto top = que.top();
        que.pop();
        int v = top.first, k = top.second;
        for (auto &t : adj[v]) {
            int u = get<0>(t), d = get<1>(t), e = get<2>(t);
            // 何も守らない
            if (dp[v][k] + e < dp[u][k]) {
                dp[u][k] = dp[v][k] + e;
                que.emplace(u, k);
            }
            if (d <= k && dp[v][k] < dp[u][k - d]) {
                dp[u][k - d] = dp[v][k];
                que.emplace(u, k - d);
            }
        }
    }
    int ret = 1e9;
    for (int i = 0; i <= l; i++) {
        ret = min(ret, dp.back()[i]);
    }
    return ret;
}

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

    while (1) {
        int n, m, l;
        cin >> n >> m >> l;
        if (n == 0) break;
        cout << solve(n, m, l) << '\n';
    }
}


Measured memory_bytes: 3436
#include <iostream>

using namespace std;

int main()
{
    int a;
    int b;
    int x;
    cin >> a >> b >> x;
    if (x >= a){
        if (x <= a + b){
            cout << "YES" << endl;
        }else{
            cout << "NO" << endl;
        }
    }else{
        cout << "NO" << endl;
    }
    return 0;
}


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

int main(){

    long long N,K;
    cin >> N >> K;
    
    long long num = N/K;

    long long A = N - num*K;
    long long B = abs(A - K);

    long long Ans = min(N,min(A,B));

    cout << Ans << endl;

}

Measured memory_bytes: 256
/*BISMILLAH
THE WHITE WOLF
NO DREAM IS TOO BIG AND NO DREAMER IS TOO SMALL*/

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef vector<long long> vll;
typedef vector<int> vi;

#define io ios_base::sync_with_stdio(false)
#define pb push_back
#define eb emplace_back
#define mod    1000000007
#define PI 2*acos(0.0)

bool ck(int n, int p)
{
    return (bool)(n &(1<<p));
}


int32_t main()
{
    io;
    int n;
    cin>>n;
    vi adj[n+1];
    for(int i = 0; i< n-1; i++)
    {
        int x, y;
        cin>>x>>y;
        if(x < y)
            swap(x, y);
        adj[x].pb(y);
    }
    ll ans = 0;
    for(ll i = 1; i<= n; i++)
        ans += i*(i+1)/2;
    for(int i = 1; i<=n; i++)
        for(auto x: adj[i])
            ans -= 1LL*x*(n-i+1);
    cout<<ans;
    return 0;
}

Measured memory_bytes: 14596
#include <iostream>

using namespace std;

int main() {
  char n;
  cin >> n;
  if(n=='A') cout << "T" << endl;
  if(n=='T') cout << "A" << endl;
  if(n=='C') cout << "G" << endl;
  if(n=='G') cout << "C" << endl;
}


Measured memory_bytes: 256
/**
 * Tunnel
 */

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

import static java.lang.Integer.parseInt;

public class Main {

	public static void main(String[] args) throws IOException {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		String line;

		int n = parseInt(br.readLine());
		int m = parseInt(br.readLine());
		int max = m;

		for (int i = 0; i < n; i++) {
			line = br.readLine();
			int a = parseInt(line.substring(0, line.indexOf(' ')));
			int b = parseInt(line.substring(line.indexOf(' ') + 1));
			m = m + a - b;
			if (m < 0) {
				max = 0;
				break;
			} else {
				max = Math.max(max, m);
			}
		}
		System.out.println(max);
	} //end main
}

Measured memory_bytes: 24872
#include<bits/stdc++.h> 
#define For(i,j,k) for (int i=(int)(j);i<=(int)(k);i++)
#define Rep(i,j,k) for (int i=(int)(j);i>=(int)(k);i--)
#define pii pair<int,int>
#define pll pair<ll,ll>
#define ll long long
#define fi first
#define se second
#define PB push_back
#define uint unsigned
#define ull unsigned ll 
using namespace std;
const int mo=998244353;
const int N=300005;
char s[N];
bool pre[N];
bool suf[N];
int n;
int F(char v1,char v2){
	int ans=1,rest=0;
	For(i,1,3*n)
		if (s[i]==v2) ans=1ll*ans*(rest--)%mo;
		else if (s[i]==v1) ++rest;
	return ans;
}
int main(){
	scanf("%d%s",&n,s+1);
	int ans=1;
	int S1=0,S2=0,S3=0;
	int S12=0,S13=0,S23=0;
	For(i,1,3*n){
		if (s[i]=='R'){
			++S1;
			if (S23){
				ans=1ll*ans*S23%mo;
				S23--; S1--;
			}
			else if (S2){
				ans=1ll*ans*S2%mo;
				S2--; S1--; S12++;
			}
			else if (S3){
				ans=1ll*ans*S3%mo;
				S3--; S1--; S13++;
			}
		}
		
		if (s[i]=='G'){
			++S2;
			if (S13){
				ans=1ll*ans*S13%mo;
				S13--; S2--;
			}
			else if (S1){
				ans=1ll*ans*S1%mo;
				S1--; S2--; S12++;
			}
			else if (S3){
				ans=1ll*ans*S3%mo;
				S3--; S2--; S23++;
			}
		}
		
		if (s[i]=='B'){
			++S3;
			if (S12){
				ans=1ll*ans*S12%mo;
				S12--; S3--;
			}
			else if (S1){
				ans=1ll*ans*S1%mo;
				S1--; S3--; S13++;
			}
			else if (S2){
				ans=1ll*ans*S2%mo;
				S2--; S3--; S23++;
			}
		}
		//printf("%d %d %d %d %d %d\n",S1,S2,S3,S12,S13,S23);
	}
	For(i,1,n) ans=1ll*ans*i%mo;
	printf("%d\n",ans);
} 

Measured memory_bytes: 512
patterns = [
    [1, 2, 3, 4, 5, 6],
    [1, 3, 5, 2, 4, 6],
    [1, 5, 4, 3, 2, 6],
    [1, 4, 2, 5, 3, 6],
    [2, 6, 3, 4, 1, 5],
    [2, 3, 1, 6, 4, 5],
    [2, 1, 4, 3, 6, 5],
    [2, 4, 6, 1, 3, 5],
    [3, 6, 5, 2, 1, 4],
    [3, 5, 1, 6, 2, 4],
    [3, 1, 2, 5, 6, 4],
    [3, 2, 6, 1, 5, 4],
    [4, 6, 2, 5, 1, 3],
    [4, 2, 1, 6, 5, 3],
    [4, 1, 5, 2, 6, 3],
    [4, 5, 6, 1, 2, 3],
    [5, 3, 6, 1, 4, 2],
    [5, 6, 4, 3, 1, 2],
    [5, 4, 1, 6, 3, 2],
    [5, 1, 3, 4, 6, 2],
    [6, 2, 4, 3, 5, 1],
    [6, 3, 2, 5, 4, 1],
    [6, 4, 5, 2, 3, 1], 
    [6, 5, 3, 4, 2, 1]
]


n = int(input())
dices = []

for _ in range(n):
    dice = list(map(int, input().split()))
    dices.append(dice)

p = []

for dice in dices:
    d = dict(zip(range(1,7), dice))
    s =[] 
    for pattern in patterns:
        c = [d.get(x) for x in pattern]
        c = tuple(c)
        s.append(c)
    s = tuple(s)
    p.append(s)

for i in range(len(p)):
    p2 = p[i][0]
    for j in range(i+1, len(p)):
        if p2 in p[j]:
            print('No')
            exit()

print('Yes')


Measured memory_bytes: 5868
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp> 
#include <ext/pb_ds/detail/standard_policies.hpp>
using namespace __gnu_pbds;
using namespace std;
#define getbit(n, i) (((n) & (1LL << (i))) != 0) 
#define setbit0(n, i) ((n) & (~(1LL << (i)))) 
#define setbit1(n, i) ((n) | (1LL << (i))) 
#define togglebit(n, i) ((n) ^ (1LL << (i))) 
#define lastone(n) ((n) & (-(n))) 
char gap = 32;
template<typename T> 
ostream& operator<<(ostream &os, const vector<T> &v) { 
    os << '{'; 
    for (const auto &x : v) os << gap << x;
        return os << '}'; 
}
template<typename A, typename B> 
ostream& operator<<(ostream &os, const pair<A, B> &p) {
        return os << '(' << p.first << gap << p.second << ')';
}

template <class T>
void read(T &x) {
    char c;
    for (c = getchar(); c < '0' || c > '9'; c = getchar())
        ;
    for (x = 0; c <= '9' && c >= '0'; c = getchar()) x = x * 10 + (c & 15);
}
#define ll long long 
#define lll __int128_t
#define pb push_back
#define mp make_pair
typedef pair < int,int> ii;
typedef vector<ii> vii;
typedef vector<ll>vl;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef tree<
int,
null_type,
less<int>,
rb_tree_tag,
tree_order_statistics_node_update>
ordered_set;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
ll hashPrime = 1610612741;

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    ll i, j, k, l, n, m;
    cin >> n;
    ll sum = 0;
    vector<ll> fre(2000005, 0);
    for (i = 1;i<=n;i++){
        cin >> k;
        sum += k;
        fre[k]++;
    }
    cin >> m;
    while(m--){
        cin >> k >> l;
        sum -= fre[k] * k;
        sum += fre[k] * l;
        fre[l] += fre[k];
        fre[k] = 0;
        cout << sum << "\n";
    }
    return 0;
}

Measured memory_bytes: 18724
import java.io.*;
import java.math.BigDecimal;

class Main{
public static void main(String[] args) throws IOException{
BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
String line="";
while((line=br.readLine())!=null){
String[] values=line.split(" ");
int a=Integer.parseInt(values[0]);
int b=Integer.parseInt(values[1]);
int n=Integer.parseInt(values[2]);
int sum=0;
for(int i=0;i<n;i++){
a*=10;
sum+=(a/b)%10;
a=a%b;
}
System.out.println(sum);
}
}
}

Measured memory_bytes: 16948
#include<cstdio>
#include<algorithm>
#include<vector>
using namespace std;
inline char tc(void){
	static char fl[10000],*A=fl,*B=fl;
	return A==B&&(B=(A=fl)+fread(fl,1,10000,stdin),A==B)?EOF:*A++;
}
inline int read(void){
	int a=0;static char c;
	while((c=tc())<'0'||c>'9');
	while(c>='0'&&c<='9')a=a*10+c-'0',c=tc();
	return a;
}
int n,k,mx;
vector<int>a[2001];
int dfs(int d,int x,int fa){
	if(d>k)return 0;
	int sum=1;
	for(int i=0;i<a[x].size();++i)
		if(a[x][i]!=fa)
			sum+=dfs(d+1,a[x][i],x);
	return sum;
}
int main(void){
	register int i,j,x,y;
	n=read(),k=read();
	for(i=1;i<n;++i)
		x=read(),y=read(),a[x].push_back(y),a[y].push_back(x);
	if(!(k&1))goto wjnsb;
	k>>=1;
	for(i=1;i<=n;++i)
		for(j=0;j<a[i].size();++j)
			if(a[i][j]>i)
				mx=max(mx,dfs(0,a[i][j],i)+dfs(0,i,a[i][j]));
	printf("%d",n-mx);
	return 0;
	wjnsb:
	k>>=1;
	for(i=1;i<=n;++i)
		mx=max(mx,dfs(0,i,0));
	printf("%d",n-mx);
	return 0;
}

Measured memory_bytes: 384
#include <cstdio>

using namespace std;

int main(){
	
	int a, b, c;
	scanf("%d%d%d", &a, &b, &c);

	int max;
	int sum = 0;

	max = a;
	sum += a;
	
	if(max < b) max = b;
	sum += b;

	if(max < c) max = c;
	sum += c;

	printf("%d\n", sum - max);

	return 0;
}

Measured memory_bytes: 128
#include<iostream>
using namespace std;
int main(void){
    for(;;){
        int n;
        cin >> n;
        if(n==0){return 0;}
        int a[n];
        for(int i=0;i<n;i++){
            cin >> a[i];
        }
        long long int sum=0;
        for(int i=0;i<n;i++){
            sum += a[i];
        }
        int ave = sum/n;
        int cnt = 0;
        for(int i=0;i<n;i++){
            if(a[i]<=ave){cnt++;}
        }
        cout << cnt << endl;
    }
}


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

int main() {
	int b;
	int a[10000];
	cin >> b;
	const int n = b;
	//??\??????????????????
	for (int i = 0; i < n; i++) {
		cin >> a[i];
	}
	//????????????????????¨???
	for (int i = 0; i < n; i++){
		cout << a[i] ;
		if (i + 1 == n){
			cout << endl;
		}else{
			cout << " ";
		}
	}
	/* ??????????????¨??? */
	for (int i = 0; i < n - 1; i++) {
		sort(a, a + i + 2);
		for (int i = 0; i < n; i++) {
			cout << a[i] ;
			if (i + 1 == n) {
				cout << endl;
			}
			else {
				cout << " ";
			}
		}
	}
}

Measured memory_bytes: 3084
def d_bouquet(MOD=10**9 + 7):
    N, A, B = [int(i) for i in input().split()]
    from operator import mul
    from functools import reduce

    def cmb(n, r):
        if n - r < r: r = n - r
        if r == 0: return 1
        if r == 1: return n

        numerator = [n - r + k + 1 for k in range(r)]
        denominator = [k + 1 for k in range(r)]

        for p in range(2, r + 1):
            pivot = denominator[p - 1]
            if pivot > 1:
                offset = (n - r) % p
                for k in range(p - 1, r, p):
                    numerator[k - offset] /= pivot
                    denominator[k] /= pivot

        result = 1
        for k in range(r):
            if numerator[k] > 1:
                result *= int(numerator[k])
                result %= MOD

        return result

    ans = pow(2, N, MOD) - 1
    ans -= cmb(N, A)
    ans -= cmb(N, B)

    return (ans + MOD) % MOD

print(d_bouquet())

Measured memory_bytes: 28328
#B - Judge Status Summary
N=int(input())
S={}
S['AC']=0
S['WA']=0
S['TLE']=0
S['RE']=0

for i in range(N):
    s=input()
    if s in S:
        S[s]+=1
    else:
        S[s]=1
 
print("AC x "+str(S['AC']))
print("WA x "+str(S['WA']))
print("TLE x "+str(S['TLE']))
print("RE x "+str(S['RE']))



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

ll ans,cnt[200005];
int a[200005],n;

int main()
{
    scanf("%d",&n);
    for(int i=0;i<n;i++) scanf("%d",a+i),cnt[a[i]]++;
    for(int i=1;i<=n;i++) ans+=cnt[i]*(cnt[i]-1)/2;
    for(int i=0;i<n;i++)
        printf("%lld\n",ans-cnt[a[i]]*(cnt[a[i]]-1)/2+(cnt[a[i]]-1)*(cnt[a[i]]-2)/2);
    return 0;
}

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

inline void Yes(){
    cout << "Yes" << "\n";
}
inline void No(){
    cout << "No" << "\n";
}
typedef pair<int,int> P;

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


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

#define REP(i, s, n) for (int i = s; i < n; ++i)
#define rep(i, n) REP(i, 0, n)
#define SORT(c) sort((c).begin(), (c).end())
#define IINF INT_MAX
#define LLINF LLONG_MAX
#define DEBUG false

int main()
{
    int a,b,c;
    cin>>a>>b>>c;
    if(a<=c && c<=b) cout<<"Yes"<<endl;
    else cout<<"No"<<endl;
    return 0;
}



Measured memory_bytes: 256
#include <iostream>
#include <string>
using namespace std;
 
bool isOdd(int i) {
  	i = i+1;
  	if(i%2 == 1) return true;
  	else return false;
}
 
int main(){
    string s;
    cin >> s;
    for(int i=0; i<s.size(); ++i) {
      	if(isOdd(i)) {
        	if(s[i] == 'L') {
              cout << "No" << "\n";
              return 0;
            }
        }else {
        	if(s[i] == 'R') {
              cout << "No" << "\n";
              return 0;
            }
        }
    }
    cout << "Yes" << "\n";
    return 0;
}

Measured memory_bytes: 256
/*
Written by Kabir Kanha Arora
@kabirkanha
 */

import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        String s1 = scanner.next();
        char[] arr1 = s1.toCharArray();
        String s2 = scanner.next();
        char[] arr2 = s2.toCharArray();
        int cnt = 0;
        for (int i = 0; i < s1.length(); ++i) {
            if (arr1[i] != arr2[i])
                cnt++;
        }
        System.out.println(cnt);
    }
}


Measured memory_bytes: 41844
#include <iostream>

using namespace std;

int main(){
  int cnt=0;
  int n; cin >> n;
  int a[n];
  for(int i=0;i<n;i++) cin >> a[i];
  int q; cin >> q;
  for(int i=0;i<q;i++){
    int x; cin >> x;
    for(int j=0;j<n;j++){
      if(x==a[j]){
        cnt++;
        break;
      }
    }
  }
  cout << cnt << endl;
}

Measured memory_bytes: 3068
import sys

sys.setrecursionlimit(10 ** 6)
INF = float("inf")
MOD = 10 ** 9 + 7


def input():
    return sys.stdin.readline().strip()


def main():
    N = int(input())

    ans = []
    S = sum(range(1, N + 1))
    if N % 2 == 0:
        S -= N + 1
        for i in range(1, N + 1):
            for j in range(i + 1, N + 1):
                if i + j == N + 1:
                    continue
                else:
                    ans.append((i, j))
    else:
        S -= N
        for i in range(1, N + 1):
            for j in range(i + 1, N + 1):
                if i + j == N:
                    continue
                else:
                    ans.append((i, j))

    M = len(ans)
    print(M)
    for i, j in ans:
        print(i, j)


if __name__ == "__main__":
    main()


Measured memory_bytes: 3996
#include <bits/stdc++.h>
using namespace std;
typedef pair<int,int> pi;
typedef long long lint;
const int offset = 2500;

lint n, s;

lint sum(lint x, lint b){
	if(x == 0) return 0;
	return sum(x/b, b) + x%b;
}

int main(){
	cin >> n >> s;
	for(int i=2; i<=1000000; i++){
		if(sum(n, i) == s){
			printf("%d\n", i);
			return 0;
		}
	}
	// two zarry
	if(n > s){
		lint w = n - s;
		lint ret = 1e18;
		for(lint i=1; i*i<=w; i++){
			if(w%i != 0) continue;
			if(sum(n, i+1) == s){
				ret = min(ret, i+1);
			}
			if(sum(n, w/i+1) == s){
				ret = min(ret, w/i+1);
			}
		}
		if(ret <= 1e17){
			printf("%lld\n", ret);
			return 0;
		}
	}
	if(n != 1 && n == s) printf("%lld\n", n+1);
	else puts("-1");
}


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

typedef long long ll;
typedef unsigned long long ull;
typedef pair<bool,bool> P;

#define fi first
#define se second
#define repl(i,a,b) for(ll i=(ll)(a);i<(ll)(b);i++)
#define rep(i,n) repl(i,0,n)
#define each(itr,v) for(auto itr:v)
#define pb push_back
#define all(x) (x).begin(),(x).end()
#define dbg(x) cout<<#x"="<<x<<endl
#define mmax(x,y) (x>y?x:y)
#define mmin(x,y) (x<y?x:y)
#define maxch(x,y) x=mmax(x,y)
#define minch(x,y) x=mmin(x,y)
#define uni(x) x.erase(unique(all(x)),x.end())
#define exist(x,y) (find(all(x),y)!=x.end())
#define bcnt __builtin_popcount

#define INF INT_MAX/3

int n;
vector<int> g[111111];

P dfs(int v,int pre){
  if(g[v].size()==1&&g[v][0]==pre){
    return P(true,false);
  }
  int cnt=0;
  for(int nv: g[v]){
    if(nv!=pre){
      P tmp=dfs(nv,v);
      if(!tmp.fi)return P(false,false);
      if(!tmp.se)cnt++;
    }
  }
  return P(cnt<=1,cnt==1);
}

int main(){
	cin.sync_with_stdio(false);
  cin>>n;
  rep(i,n-1){
    int a,b;
    cin>>a>>b;
    a--; b--;
    g[a].pb(b); g[b].pb(a);
  }
  P res=dfs(0,-1);
  if(res.fi&&res.se)cout<<"Second"<<endl;
  else cout<<"First"<<endl;
	return 0;
}


Measured memory_bytes: 6144
#include <iostream>
#include <map>
#include <string>

using namespace std;
using ll = long long;

void solve() {
    int a[26];
    string s;
    cin >> s;

    for(int i = 0; i < 26; i++){
        a[i] = 0;
    }
    for(int i = 0; i < s.length(); i++){
        a[s[i]-'a']++;
    }
    for(int i = 0; i < 26; i++){
        if(a[i] == 0){
            //cout << 0x << endl;
            printf("%c", i+97);
            return;
        }
    }
    cout << "None" << endl;
}

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

Measured memory_bytes: 512
/*
      author  : nishi5451
      created : 14.08.2020 13:11:10
*/

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


int main(){
    string s;
    cin >> s;
    vector<int> dp(26);
    rep(i,int(s.size())){
        dp[s[i]-'a']++;
    }
    rep(i,26){
        if(dp[i]>1){
            cout << "no" << endl;
            return 0;
        }
    }
    cout << "yes" << endl;
    return 0;
}

Measured memory_bytes: 3640
#include <iostream>
#include <string>
#include <vector>
#include <map>
#include <cmath>
#include <algorithm>
#include <functional>
#include <stack>
typedef long long ll;
using namespace std;
//#define int long long

//素数判定
inline bool IsPrime(int p) {
	if (p == 1) return false;
	for (int i = 2; i <= sqrt(p); i++) {
		if (p%i == 0) return false;
	}
	return true;
}

//10進数の自然数の桁数を返す
inline int GetDigit(int num) {
	return (int)log10(num) + 1;
}

//各位の和を返す
int GetDigitsSum(int num) {
	int N = 0;
	while (num > 0) {
		N += num % 10;
		num /= 10;
	}
	return N;
}

//互除法
ll gcd(ll a, ll b) {
	if (a < b) {
		return gcd(b, a);
	}
	else if (a%b) {
		return gcd(b, a%b);
	}
	else {
		return b;
	}
}

//最小公倍数
ll lcm(ll a, ll b) {
	ll g = gcd(a, b);
	return a / g * b; // Be careful not to overflow

}

//異なるn個からr個の整数を取り出す組合せの数を求める
int combination(int n, int r) {
	if (r == 0 || n == r) {
		return 1;
	}
	else if (r == 1) {
		return n;
	}
	else {
		return combination(n - 1, r - 1) + combination(n - 1, r);
	}

}

//Ｏ(√n)
//素因数分解
map<int, int> prime_factor(int n) {
	map<int, int> res; // map[i]:=ｎを素因数分解したときiは何乗か。
	for (int i = 2; i * i <= n; i++) {
		if (n % i == 0) {
			while (n % i == 0) {
				res[i]++;
				n /= i;
			}
		}
	}
	if (n != 1)
		res[n] = 1;
	return res;
}

//Ｏ(√n)
//素因数分解
map<int, int> prime_factor_ver2(int n, map<int, int> res) {
	for (int i = 2; i * i <= n; i++) {
		if (n % i == 0) {
			while (n % i == 0) {
				res[i]++;
				n /= i;
			}
		}
	}
	if (n != 1)
		res[n]++;
	return res;
}


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

	int H, W;
	int cnt = 0;
	cin >> H >> W;

	for (int i = 0; i < H; i++)
	{
		string s;
		cin >> s;
		for (int j = 0; j < W; j++)
		{
			if (s[j] == '#') {
				cnt++;
			}
		}
	}

	if (H + W - 1 == cnt) {
		cout << "Possible" << endl;
	}
	else {
		cout << "Impossible" << endl;
	}

	return 0;
}


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

int main(){
  string s;
  cin >> s;
  int sum = 0;
  for(ll i=0;i<s.size();i++){
    char c = s[i];
    sum += c - '0';
  }
  if(sum%9 == 0) cout << "Yes" << endl;
  else  cout << "No" << endl;
  return 0;
}

Measured memory_bytes: 3720
#coding :utf-8
N = int(input())

aka = []
for i in range(N):
    aka.append(list(map(int, input().split())))


ao = []
for i in range(N):
    ao.append(list(map(int, input().split())))


memo = [0 for i in range(N)]
memoB = [0 for i in range(N)]

_aka = sorted(aka, key=lambda x: x[0])
_ao = sorted(ao, key=lambda x: x[0])
ans = 0
for j in range(N):
    _i = -1
    _y = -1
    for i in range(N): 
        if _ao[j][0] > _aka[i][0] and _ao[j][1] > _aka[i][1] and memo[i] == 0:
            if _y < _aka[i][1]:
                _y = _aka[i][1]
                _i = i
    if not _i == -1:
        ans += 1
        memo[_i] = 1
        

print(ans)



Measured memory_bytes: 3064
#include <bits/stdc++.h>
typedef long long ll;
using namespace std;
#define all(x) (x).begin(), (x).end()
#define MOD 1000000007
int main() {
    int h, w, n;
    cin >> h >> w >> n;
    cout << min((n + h - 1) / h, (n + w - 1) / w) << endl;
}

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

const int inf = 1e9;
int n, m;
const int table[10] = {-1000, 2, 5, 5, 4, 5, 6, 3, 7, 6};
vector<int> a;

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

int main() {
    cin >> n >> m; a.resize(m);
    for (int i = 0; i < m; i++) cin >> a[i];
    sort(a.begin(), a.end(), greater<int>());
    vector<int> dp(20000);
    for (int i = 0; i < 20000; i++) dp[i] = -inf;
    dp[0] = 0;
    for (int i = 0; i < n; i++) {
        for (int j = 0; j < m; j++) {
            int cost = table[a[j]];
            chmax(dp[i+cost], dp[i]+1);
        }
    }
    string res;
    int digit = dp[n];
    for (int i = 0; i < digit; i++) {
        for (int j = 0; j < m; j++) {
            int cost = table[a[j]];
            if (n-cost >= 0 && dp[n-cost] + 1 == dp[n]) {
                res += a[j] + '0';
                n -= cost;
                break;
            }
        }
    }
    cout << res << endl;
    return 0;
}

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

vector<int> & insertionSort(vector<int> & A, int const & n, int const & g, int & cnt){
    int v;

    for (int i = g; i < n; i++){
        v = A[i];
        int j = i - g;
        while (j >= 0 && A[j] > v){
            A[j+g] = A[j];
            j = j - g;
            ++cnt;
        }
        A[j+g] = v;
    }
    return A;
}

vector<int> & shellSort(vector<int> & A, int const & n){
    int cnt = 0;

    vector<int> G;
    if(n==1){
        G.push_back(1);
    }
    for(int i = 1; (pow(3,i)-1)/2 < n; ++i ){
        G.push_back( (pow(3,i)-1)/2 );
    }

    reverse(G.begin(), G.end());

    int m = G.size();

    cout << m << "\n";

    for (int i = 0; i < m-1; ++i){
        cout << G[i] << " ";
    }
    cout << G[m-1] << "\n";

    for (int i = 0; i < m; ++i){
        insertionSort(A, n, G[i], cnt);
    }

    cout << cnt << "\n";

    return A;
}

// main
int main(){
   // 入力
    int N;
    cin >> N;
    vector<int> A(N, 0);
    for (int i = 0; i < N; ++i){
        cin >> A[i];
    }

    shellSort(A, N);

    

    for (vector<int>::iterator A_itr = begin(A); A_itr!=end(A); ++A_itr ){
                cout << *A_itr << "\n";
            }
    return 0;
}





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

int main(){
  int H, W;
  cin >> H >> W;
  vector<vector<char>> map(H,vector<char>(W));
  
  for(int i = 0; i < H; i++){
    for(int j = 0; j < W; j++){
      cin >> map.at(i).at(j);
  	}
  }
  
  char base;
  char same = false;
  for(int i = 0; i < H; i++){
    same = true;
    for(int j = 0; j < W; j++){
      if(map.at(i).at(j) == '#')
        same = false;
    }
    if(same){
      for(int j = 0; j < W; j++){
        map.at(i).at(j) = 'x';
      }
    }
  }



  for(int i = 0; i < W; i++){
    same = true;
    for(int j = 0; j < H; j++){
      if(map.at(j).at(i) == '#')
        same = false;
    }
    if(same){
      for(int j = 0; j < H; j++){
        map.at(j).at(i) = 'x';
      }
    }
  }
  
  bool out;
  for(int i = 0; i < H; i++){
    out = false;
    for(int j = 0; j < W; j++){
      if(map.at(i).at(j) != 'x'){
        cout<< map.at(i).at(j);
        out = true;
      }
  	}
    if(out){
      cout << endl;
    }
  }

  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (int)(n); i++)
#define REP(i,n) for (int i = 1; i < (int)(n); i++)
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(),x.rend()
#define vout(x) rep(i,x.size()) cout << x[i] << " "
template<class T> bool chmin(T &a, T b) {if(a>b) {a=b;return 1;}return 0;}
template<class T> bool chmax(T &a, T b) {if(a<b) {a=b;return 1;}return 0;}
using namespace std;
using vint = vector<int>;
using vvint = vector<vector<int>>;
using ll = long long;
using vll = vector<ll>;
using vvll = vector<vector<ll>>;
using P = pair<int,int>;
const int inf = 1e9+7;
const ll inf_l = 1e18;
const int MAX = 1e6;

int main() {
    string x; cin >> x;
    int ct = 0;
    int n = x.size();
    int ct_s = 0;
    rep(i,n) {
        if (x[i] == 'S') ct_s++;
        if (x[i] == 'T') {
            if (ct_s == 0) continue;
            else {
                ct++;
                ct_s--;
            }
        }
    }
    cout << n-ct*2 << endl;
}

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

void input(int& rnMaxNum)
{
  cin >> rnMaxNum;
}

llong toInt(const vector<char>& cnrvcNum)
{
  const vector<int> cnvnDgt = {0, 3, 5, 7};
  llong nRtn = 0;
  int nNumPos = 0;

  for (int i = cnrvcNum.size() - 1; i >= 0; i--)
  {
    if (cnrvcNum[i] == '0') break;
    llong nNum = cnvnDgt[ cnrvcNum[i] - '0' ];
    
    for (int n = 0; n < nNumPos; n++) nNum *= 10;

    nRtn += nNum;
    nNumPos++;
  }
  return nRtn;
}

int isDgt753(const vector<char>& cnrvcNum)
{
  int nDgt3 = 0, nDgt5 = 0, nDgt7 = 0;

  for (int i = 0; i < cnrvcNum.size(); i++)
    if      (cnrvcNum[i] == '1') nDgt3++;
    else if (cnrvcNum[i] == '2') nDgt5++;
    else if (cnrvcNum[i] == '3') nDgt7++;

  if (nDgt3 && nDgt5 && nDgt7)
    return 1;
  else
    return 0;
}

int countDgt753(int nMaxNum)
{
  int nDgt753Cnt = 0;
  int nDgtSiz = to_string(nMaxNum).size();
  vector<char> vcNum(nDgtSiz + 1, '0');

  while (toInt(vcNum) <= nMaxNum) 
  {
    if (isDgt753(vcNum)) nDgt753Cnt++;

    vcNum[vcNum.size() - 1]++;
    for (int i = vcNum.size() - 1; i > 0; i--)
      if (vcNum[i] > '3')
      {  
        vcNum[i - 1]++;
        vcNum[i] = '1';
      }
      else
        break;
  }
  return nDgt753Cnt;
}

int main()
{
  int nMaxNum;

  input(nMaxNum);
  cout << countDgt753(nMaxNum) << endl;

  return 0;
}

Measured memory_bytes: 3692
h, n = map(int, input().split())
inf = 10**11

# dp[i]: 体力iを減らす魔力の最小値
dp = [inf] * 20000
dp[0] = 0

for _ in range(n):
    a, b = map(int, input().split())
    for j in range(h):
        dp[j+a] = min(dp[j] + b, dp[j+a])

print(min(dp[h:]))


Measured memory_bytes: 43740
import java.util.Scanner;

class Main{
	public static void main(String[] args) {
		Scanner scan=new Scanner(System.in);
		int n=scan.nextInt(),m=scan.nextInt(),x=scan.nextInt(),a,l=0,r=0,i;
		for(i=0;i<m;i++) {
			a=scan.nextInt();
			if(a>x) r++;
			else l++;
		}
		System.out.print(r>l?l:r);
	}
}

Measured memory_bytes: 23764
N = int(input().rstrip())

H = [ int(n) for n in input().rstrip().split() ]

C = 0

def Maxmam(H):
    if len(H) > 0:
        M = [i for i, x in enumerate(H) if x == max(H)]
        global C
        C += len(M)

        H = H[:min(M)]
        Maxmam(H)
    else:
        C

Maxmam(H)


print(C)


Measured memory_bytes: 3060
import core.bitop;
import std.algorithm;
import std.ascii;
import std.bigint;
import std.conv;
import std.functional;
import std.math;
import std.numeric;
import std.range;
import std.stdio;
import std.string;
import std.random;
import std.typecons;

alias sread = () => readln.chomp();
alias Point2 = Tuple!(long, "y", long, "x");

T lread(T = long)()
{
    return readln.chomp.to!T();
}

T[] aryread(T = long)()
{
    return readln.split.to!(T[])();
}

void scan(TList...)(ref TList Args)
{
    auto line = readln.split();
    foreach (i, T; TList)
    {
        T val = line[i].to!(T);
        Args[i] = val;
    }
}

void minAssign(T, U = T)(ref T dst, U src)
{
    dst = cast(T) min(dst, src);
}

void maxAssign(T, U = T)(ref T dst, U src)
{
    dst = cast(T) max(dst, src);
}

void main()
{
    long A, B, C, D;
    scan(A, B, C, D);
    bool b = abs(A - B) <= D && abs(B - C) <= D;
    bool c = abs(A - C) <= D;
    writeln((b || c) ? "Yes" : "No");
}


Measured memory_bytes: 256
n=int(input())
x=[0]*n
y=[0]*n
for i in range(n):
    x[i],y[i]=input().split()
ans=0
for i in range(n):
    if y[i]=='JPY':
        ans+=float(x[i])
    else:
        ans+=float(x[i])*380000.0
print(ans)

Measured memory_bytes: 3064
#include <bits/stdc++.h>
#include <string>
#include <math.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define ll long long
 
int main()
{
    int n,ans;
 
    cin >> n; 
    vector<int> b(n-1);
    rep(i, n-1) {
        cin >> b[i];
    }
 
    ans = b[0];
    for (int i = 1;i < n - 1;++i) {
        ans += min(b[i-1], b[i]);
    }
    ans += b[n-2];
    cout << ans << endl;
 
    return 0;
}

Measured memory_bytes: 3524
n,m = map(int, input().split())
flag=[0]*n
flag[0]=1
ball=[1]*n
count=0

for i in range(m):
    xi, yi = map(int, input().split())
    xi-=1
    yi-=1
    ball[xi] = ball[xi] - 1
    ball[yi] = ball[yi] + 1
    if(flag[xi]==1):
        flag[yi] = 1
    if(ball[xi]==0):
        flag[xi]=0
for i in range(len(flag)):
    if(flag[i]==1):
        count+=1
print(count)

Measured memory_bytes: 4596
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int max_n = 1e6;
int d[max_n];
int N;
int rec(int n){
  if(n == 0)  return 0;
  if(d[n]!= -1) return d[n];
  int res = n;

  for(int pow6=1 ; pow6<=n ; pow6*=6){
    res = min(res, rec(n-pow6)+1);
  }
  for(int pow9=1 ; pow9<=n ; pow9*=9){
    res = min(res, rec(n-pow9)+1);
  }
  return d[n] = res;
}

int main(){
  cin >> N;
  fill(d, d+N+1, -1);
  cout << rec(N) << endl;
  return 0;
}


Measured memory_bytes: 3712
def main():
    from collections import deque
    S = input()
    Sd = deque(list(S))
    Q = int(input())
    Query = [input().split() for i in range(Q)]
    flag = 0
    for q in Query:
        if q[0] == "1":
            flag += 1
        elif q[0] == "2":
            if q[1] == "1":
                if flag % 2 == 1:
                    Sd.append(q[2])
                elif flag % 2 == 0:
                    Sd.appendleft(q[2])
            elif q[1] == "2":
                if flag % 2 == 1:
                    Sd.appendleft(q[2])
                elif flag % 2 == 0:
                    Sd.append(q[2])

    if flag % 2 == 1:
        Sd.reverse()
        print("".join(Sd))
    elif flag % 2 == 0:
        print("".join(Sd))

if __name__ == "__main__":
    main()


Measured memory_bytes: 44772
while True:
    n, m = int(input()), int(input())
    if m == 0:
        break
    d = {k+1:[] for k,_ in enumerate(range(m))}
    for _ in range(m):
        a, b = map(int, input().split())
        d[a].append(b)
        d[b].append(a)
    ans = d[1].copy()
    for k in d[1]:
        ans += d[k]
    print(len(set(ans))-1)

Measured memory_bytes: 9424
n = int(input())
A = list(map(int, input().split()))

maxV = (10 ** 6 + 1)

sieve = [i for i in range(maxV)]
p = 2

while p*p < maxV:
    if sieve[p] == p:
        for q in range(p*2, maxV, p):
            if sieve[q] == q:
                sieve[q] = p
    p += 1

from math import gcd

g = 0
primes = set()
for a in A:
    g = gcd(g, a)

    v = a


if g > 1:
    print('not coprime')
    exit()

for a in A:
    temp_prime = set()
    while a > 1:
        prime = sieve[a]
        temp_prime.add(prime)
        a = a // prime

    for t in temp_prime:
        if t in primes:
            print('setwise coprime')
            exit()
        primes.add(t)

print('pairwise coprime')

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

#define int long long

typedef pair<int,int>pint;
typedef vector<int>vint;
typedef vector<pint>vpint;
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define all(v) (v).begin(),(v).end()
#define rep(i,n) for(int i=0;i<(n);i++)
#define reps(i,f,n) for(int i=(f);i<(n);i++)
#define each(it,v) for(__typeof((v).begin()) it=(v).begin();it!=(v).end();it++)
template<class T,class U>void chmin(T &t,U f){if(t>f)t=f;}
template<class T,class U>void chmax(T &t,U f){if(t<f)t=f;}

int N,M;
int P[100000];
int A[100000],B[100000],C[100000];
int sum[111111];
signed main(){
    cin>>N>>M;
    rep(i,M)cin>>P[i],P[i]--;
    rep(i,N-1)cin>>A[i]>>B[i]>>C[i];

    rep(i,M-1){
        int a=min(P[i],P[i+1]),b=max(P[i],P[i+1]);
        sum[a]++;sum[b]--;
    }

    rep(i,N)sum[i+1]+=sum[i];

    int ans=0;
    rep(i,N-1)ans+=min(A[i]*sum[i],B[i]*sum[i]+C[i]);
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 5068
import sys
input = sys.stdin.readline


def main():
    H,W,K = map(int,input().split())
    grid = []
    for _ in range(H):
        row = input().strip()
        grid.append(row)
    
    ans = 0
    
    for maskH in range((1<<H)-1):
        for maskW in range((1<<W)-1):
            blacks = 0
            for i in range(H):
                for j in range(W):
                    if (maskH >> i & 1)==0 and (maskW >> j & 1)==0 and grid[i][j] == '#':
                        blacks += 1
            if blacks == K:
                ans += 1
    print(ans)
    
    
main()

Measured memory_bytes: 9180
#include<bits/stdc++.h>
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstring>
#include<vector>
#define rep(a,b,c) for(ll a=b;a<=c;a++)
#define per(a,b,c) for(ll a=b;a>=c;a--)
#define pb push_back
#define mk make_pair
#define pii pair<int,int>
#define mem(a,b) memset(a,b,sizeof(a))
using namespace std;
typedef long long ll;
typedef double db;
const int inf = 0x3f3f3f3f;
const int N = 1e5 + 5;
const int M = 2e5 + 5;

int n;
int a[N];

int main(){
    cin >> n;
    rep(i,1,n) cin >> a[i];
    bool flag = 1;
    a[1]--;
    rep(i,2,n){
        if(a[i] < a[i-1]){
            flag = 0;
            break;
        }
        else if(a[i] > a[i-1]) a[i]--;
    }
    printf("%s\n", flag ? "Yes" : "No");
    return 0;
}


Measured memory_bytes: 640
#include <cstdio>
 
int main() {
  int N;
  scanf("%d\n", &N);
  int T[100];
  for (int i = 0; i < N; i++)
    scanf(" %d", &T[i]);
  int M;
  scanf("\n%d\n", &M);
  int P[100], X[100];
  for (int i = 0; i < M; i++)
    scanf("%d %d\n", &P[i], &X[i]);
  int sum = 0;
  for (int i = 0; i < N; i++)
    sum += T[i];
  for (int i = 0; i < M; i++)
    printf("%d\n", sum - T[P[i]-1] + X[i]);
  return 0;
}


Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
#define rep(i,a,b) for (int i = (a); i <= (b); ++ i)
#define rrp(i,a,b) for (int i = (a); i >= (b); -- i)
#define gc() getchar()
#define fir first
#define sec second
typedef pair<int,int> pii;
typedef long double db;
typedef long long ll;
template <typename tp>
inline void read(tp& x) {
  x = 0; char tmp; bool key = 0;
  for (tmp = gc(); !isdigit(tmp); tmp = gc())
    key = (tmp == '-');
  for (; isdigit(tmp); tmp = gc())
    x = (x << 3) + (x << 1) + (tmp ^ '0');
  if (key) x = -x;
}
template <typename tp>
inline void ckmn(tp& x,tp y) {
  x = x < y ? x : y;
}
template <typename tp>
inline void ckmx(tp& x,tp y) {
  x = x < y ? y : x;
}

const int N = 100010;
struct edge {
  int la,b;
} con[N << 1];
int tot, fir[N];
void add(int from,int to) {
  con[++tot] = (edge) {fir[from], to};
  fir[from] = tot;
}
int n,deg[N],del[N],num,ans,val[N];
char col[N];
int dp[N];
void dfs(int pos,int fa) {
  dp[pos] = val[pos];
  for (int i = fir[pos]; i; i = con[i].la) {
    if (con[i].b == fa) continue;
    if (del[con[i].b]) continue;
    dfs(con[i].b, pos);
    ans = max(ans, dp[pos] + dp[con[i].b]);
    dp[pos] = max(dp[pos], dp[con[i].b] + val[pos]);
  }
}
void prework() {
  queue<int> q;
  rep (i, 1, n) if (col[i] == 'B' && deg[i] == 1)
    q.push(i);
  for (int pos; !q.empty(); q.pop()) {
    pos = q.front();
    ++ num;
    del[pos] = 1;
    for (int i = fir[pos]; i; i = con[i].la) {
      if (--deg[con[i].b] == 1 && !del[con[i].b]) {
	if (col[con[i].b] == 'B')
	  q.push(con[i].b);
      }
    }
  }
}
int main() {
  int x,y;
  read(n);
  rep (i, 1, n-1) {
    read(x), read(y);
    add(x, y);
    add(y, x);
    ++ deg[x], ++ deg[y];
  }
  scanf("%s", col+1);
  if (n == 1) {
    if (col[1] == 'B') return puts("0"), 0;
    else return puts("1"), 0;
  }
  prework();
  if (num == n) return puts("0"), 0;
  if (num == n-1) return puts("1"), 0;
  int rt = 1;
  rep (i, 1, n) if (del[i] == 0) rt = i;
  rep (i, 1, n) if (del[i] == 0) {
    if (col[i] == 'W' && deg[i] % 2 == 0) val[i] = 1;
    else if (col[i] == 'B' && (deg[i]&1)) val[i] = 1;
    else val[i] = 0;
  }
  // - 2 * num1
  dfs(rt, 0);
  ans = 2 * (n - num - 1) - 2 * ans;
  rep (i, 1, n) ans += val[i];
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 7936