akhauriyash/Code-Regression huggingface dataset:
import Base.parse
import Base.StringVector
using Primes
using DataStructures

parse(::Type{String},  str::AbstractString) = str

isdelim(x::UInt8, xs::Set{UInt8}) = x in xs

function myreaduntil(s::IO, delims::Set{UInt8})::Vector{UInt8}
    out = StringVector(0)
    c::UInt8 = 0x00
    while !eof(s)
        c = read(s, UInt8)
        if !isdelim(c, delims)
            break
        end
    end
    push!(out, c)
    if eof(s)
        return out
    end
    while !eof(s)
        c = read(s, UInt8)
        if isdelim(c, delims)
            break
        end
        push!(out, c)
    end
    return out
end

delimset = Set([0x0a, 0x20])

function readword(io::IO = stdin, delims = delimset)::String
    word = myreaduntil(io, delims)
    i = length(word)
    if i == 0 || word[i] != 0x0a
        return String(word)
    elseif i < 2 || word[i-1] != 0x0d
        return String(resize!(word,i-1))
    else
        return String(resize!(word,i-2))
    end
end

pread(ty) = parse(ty, readword())

reads(tys...)::Tuple{tys...} = Tuple{tys...}(pread(ty) for ty in tys)

readvec(tys::Tuple , len::Signed)::Vector{Tuple{tys...}} = @inbounds Tuple{tys...}[reads(tys...) for i in 1:len]

readvec(ty::Type, len::Signed)::Vector{ty} = @inbounds ty[pread(ty) for i in 1:len]

function readmat(ty::Type, s...)::Matrix{ty}
    v = Matrix{ty}(undef, s...)
    @inbounds for i = 1:s[1]
        v[i,:] = readvec(ty, s[2])
    end
    v
end

function main()
    N = pread(Int)
    fs = factor(DataStructures.SortedDict, N)
    ans = 0
    for f in fs
        c = f[2]
        ans += (-1+sqrt(1+8c))÷2
    end
    println(Int(ans))
end

main()


Measured memory_bytes: 265384
import math
a,b,x = map(int, input().split())
if x>=a**2*b/2:
    tan = (2*(a*a*b-x))/(a**3)
    ans = math.degrees(math.atan(tan))
else:
    tan = (a*b*b)/(2*x)
    ans = math.degrees(math.atan(tan))
print(ans)

Measured memory_bytes: 9252
#include<stdio.h>

int main(void){
	int x , y;
	int t;
	while(1){
		scanf("%d %d", &x, &y);
		if(x == 0 && y == 0) break;
		if(x < y) printf("%d %d\n", x, y);
		else printf("%d %d\n", y, x);
	}
	return 0;
}


Measured memory_bytes: 2052
nums = gets.split.map(&:to_i)

def result(nums)
  a = nums[0]
  b = nums[1]

  str = 'No'
  (1..3).each do |c|
    str = 'Yes' if (a * b * c) % 2 == 1
  end
  str
end

puts result(nums)

Measured memory_bytes: 1788
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <cmath>
#include<bits/stdc++.h>
using namespace std;
#define sf scanf
#define pf printf
#define mem(a,b) memset(a,b,sizeof(a));
#define rep(i,a,b) for(int i=(a);i<=(b);++i)
#define MP make_pair
#define ULL unsigned long long
#define LL   long long
#define inf 0x3f3f3f3f
#define md ((ll+rr)>>1)
#define ls (i<<1)
#define rs (ls|1)
#define eps 1e-5
#define ree freopen("in.txt","r",stdin);
#define bug pf("----------------");
#define N 300010



int a[N];
int vis[N];
int main(){
    int n;sf("%d",&n);
    rep(i,1,n){sf("%d",&a[i]);vis[a[i]]++;}
    int ans=0;
    for(int i=0;i<=1e5;++i){
        ans=max(ans,vis[i-1]+vis[i]+vis[i+1]);
    }
    pf("%d\n",ans);



}


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

int main(){
	string s; cin>>s;
	int i = 0, ans = s.size(), n = ans - 1;
	while(1){
		if( s[i] == 'A' ){
			ans -= i;
			break;
			}
		
		++i;
	}
	
	i = 0;
	while(1){
		if( s[n - i] == 'Z' ){
			ans -= i;
			break;
		}
		
		++i;
		
	}
	
	cout<<ans<<endl;
}

Measured memory_bytes: 640
import java.util.*;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int M = sc.nextInt();
		Queue<Long> A = new PriorityQueue<>(Collections.reverseOrder());
		for (int i = 0; i < N; i++) {
			A.add(sc.nextLong());
		}
		sc.close();

		for (int i = 0; i < M; i++) {
			long max = A.poll();
			A.add(max / 2);
		}

		long ans = 0;
		while (!A.isEmpty()) {
			ans += A.poll();
		}
		System.out.println(ans);
	}
}


Measured memory_bytes: 60688
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.List;

public class Main{

    public static final int FIRST_NUMBER = 0;
    public static final int SECOND_NUMBER = 1;

    public static void main(String[] args) throws NumberFormatException, IOException {

	BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

	// ???????????°
	int vertical = Integer.parseInt(br.readLine());
	// ?¨?????????°
	int horizontal = Integer.parseInt(br.readLine());

	// ?????????????????°??????????????????
	List<int[]> changeRequests = new ArrayList<>();
	for (int i = 0; i < horizontal; i++) {
	    String[] changeRequestStr = br.readLine().split(",");
	    int[] changeRequest = new int[2];
	    changeRequest[FIRST_NUMBER] = Integer.parseInt(changeRequestStr[FIRST_NUMBER]);
	    changeRequest[SECOND_NUMBER] = Integer.parseInt(changeRequestStr[SECOND_NUMBER]);
	    changeRequests.add(changeRequest);
	}

	// ?????\???????????????????´???????????????????????????????
	int[] outputArray = getDrawedArray(changeRequests, vertical, horizontal);

	// ???????????????????????????????????¨?????\???????????????????????????????????????1??????????????????
	for (int i = 1; i < outputArray.length; i++) {
	    System.out.println(outputArray[i]);
	}

    }

    /**
     * ?????? ?????????????´???????????????\??????????????????
     * 
     * @param changeRequests
     * @param vertical
     * @param horizontal
     * @return ?????\?????????
     */
    private static int[] getDrawedArray(List<int[]> changeRequests, int vertical, int horizontal) {
	// ?????\?????????????????????????????????????????????
	// outputArray[0]????????¨?????????
	int[] outputArray = new int[vertical + 1];
	for (int i = 1; i < outputArray.length; i++) {
	    outputArray[i] = i;
	}

	// ?????????????????????????£????????????\????????????
	for (int[] changeRequest : changeRequests) {
	    int mediator = 0;
	    mediator = outputArray[changeRequest[FIRST_NUMBER]];
	    outputArray[changeRequest[FIRST_NUMBER]] = outputArray[changeRequest[SECOND_NUMBER]];
	    outputArray[changeRequest[SECOND_NUMBER]] = mediator;

	}

	return outputArray;

    }

}

Measured memory_bytes: 24128
N = int(input())
S = [0 if s == "#" else 1 for s in list(input())]
ruisekiwa = [0]*(N+2)
i = 1
r = 0
while i <= N:
  r = r+S[i-1]
  ruisekiwa[i] = r
  i += 1
ruisekiwa[N+1] = ruisekiwa[N]
ans = 10**10
i = 1
while i <= N+1:
  towhite = (i-1)-(ruisekiwa[i-1]-ruisekiwa[0])
  toblack = ruisekiwa[N+1]-ruisekiwa[i-1]
  ans = min(ans, towhite+toblack)
  i += 1
print(ans)

Measured memory_bytes: 63560
#include <iostream>
#include <algorithm>
#include <cstdio>
#include <string>
#include <cstring>
#include <cctype>
#include <cstdlib>
#include <cmath>
#include <vector>
#include <set>
#include <queue>
#include <stack>
#include <map>
using namespace std;

#define REP(i, s, e) for (int i = (s); i < (e); i++)
#define REPI(i, s, e) for (int i = (s); i <= (e); i++)
#define rep(i, n) REP(i, 0, n)
#define repi(i, n) REPI(i, 0, n)
#define ALL(v) (v).begin(), (v).end()

#define dump(x) (cout << #x << " = " << x << endl)
#define dump2(x, y) (cout << "(" << #x << ", " << #y << ") = (" << x << ", " << y << ")" << endl)
#define dump3(x, y, z) (cout << "(" << #x << ", " << #y << ", " << #z << ") = (" << x << ", " << y << ", "<< z << ")" << endl)

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

#define VACANT 0
#define BLOCK 1
#define START 2
#define GOAL 3

#define INF (1<<29)
#define MAX 21

int w, h;
int brd[MAX][MAX];
int ans;

int sx, sy;
int gx, gy;

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

void dfs(int depth, int y, int x)
{
/*
rep(j, h) {
	rep(i, w) {
		char ch;
		switch(brd[j][i]) {
		case VACANT: ch = '.'; break;
		case BLOCK: ch = '#'; break;
		}
		if (j == y && i == x)
			ch = 'X';
		if (j == gy && i == gx)
			ch = 'G';
		printf("%c ", ch);
	}
	puts("");
}
puts("-------");
*/
	if (depth >= 10) return;

	rep(i, 4) {
		REP(t, 1, max(w, h)) {
			int ny = y+dy[i]*t, nx = x+dx[i]*t;
			if (ny == gy && nx == gx) {
				ans = min(ans, depth+1);
				return;
			}
			if (!(0 <= ny && ny < h)) goto NEXT;
			if (!(0 <= nx && nx < w)) goto NEXT;
			if (t == 1 && brd[ny][nx] == BLOCK) goto NEXT;
			if (brd[ny][nx] == BLOCK) {
				int ty = ny-dy[i], tx = nx-dx[i];
				brd[ny][nx] = VACANT;
				dfs(depth+1, ty, tx);
				brd[ny][nx] = BLOCK;
				break;
			}
		}
NEXT:
		;
	}
}

int main(void)
{
	while (cin >> w >> h, w|h) {
		rep(j, h)
			rep(i, w) {
				cin >> brd[j][i];
				if (brd[j][i] == START) {
					brd[j][i] = VACANT;
					sx = i, sy = j;
				} else if (brd[j][i] == GOAL) {
					brd[j][i] = VACANT;
					gx = i, gy = j;
				}
			}

		ans = INF;
		dfs(0, sy, sx);
		printf("%d\n", ans==INF?-1:ans);
	}
	return 0;
}

Measured memory_bytes: 1144
#pragma once
#include <stdio.h>
#include <sstream>
#include <string>
#include <string.h>
#include <vector>
#include <map>
#include <algorithm>
#include <iostream>
#include <utility>
#include <set>
#include <cctype>
#include <queue>
#include <stack>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <deque>
#include <limits>
#include <iomanip>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
#define bit(x,v) ((ll)x << v)

const ll INF = 1000000007;
const int MAX = 210000;
const int MOD = 1000000007;

long long fac[MAX], finv[MAX], inv[MAX];
void COMinit() {
	fac[0] = fac[1] = 1;
	finv[0] = finv[1] = 1;
	inv[1] = 1;
	for (int i = 2; i < MAX; i++) {
		fac[i] = fac[i - 1] * i % MOD;
		inv[i] = MOD - inv[MOD % i] * (MOD / i) % MOD;
		finv[i] = finv[i - 1] * inv[i] % MOD;
	}
}
ll gcd(ll a, ll b) {
	if (b == 0) return a;
	return gcd(b, a % b);
}
int pr[100010];
void uini(int n) {
	for (size_t i = 0; i <= n; i++)
	{
		pr[i] = i;
	}
}

int parent(int x) {
	if (x == pr[x]) return x;
	return pr[x] = parent(pr[x]);
}

bool unit(int x, int y) {
	int px = parent(x);
	int py = parent(y);

	if (px == py) return false;
	if (px < py) {
		pr[py] = px;
	}
	else {
		pr[px] = py;
	}
	return true;
}

// res[i][c] := i 文字目以降で最初に文字 c が登場する index (存在しないときは n)
vector<vector<int> > calcNext(const string& S) {
	int n = (int)S.size();
	vector<vector<int> > res(n + 1, vector<int>(26, n));
	for (int i = n - 1; i >= 0; --i) {
		for (int j = 0; j < 26; ++j) res[i][j] = res[i + 1][j];
		res[i][S[i] - 'a'] = i;
	}
	return res;
}
// mod 1000000007 の世界で a += b する関数
void add(long long& a, long long b) {
	a += b;
	if (a >= MOD) a -= MOD;
}

void solv() {
	int n;
	cin >> n;
	string s;
	cin >> s;
	int fc = 0;
	int ba = 0;
	for (size_t i = 0; i < n; i++)
	{
		if (s[i] == ')') {
			if (ba - 1 < 0) fc++;
			else ba--;
		}
		else ba++;
	}
	cout << string(fc, '(') << s << string(ba, ')') << endl;
}

int main() {
	//COMinit();
	solv();

	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;

int order(int n){
        vector<int> v;
        for (int i = 1; i <= n; ++i){
                v.push_back(i);
        }

        int o = 1;
        int sum;
        int x;
        for (int i = 1; i <= n; ++i){
                cin >> x;

                int index;
                for (int j = 0; j < v.size(); ++j){
                        if(v[j] == x) {
                                index = j;
                        }
                }

                sum = 1;
                for (int j = 1; j <= n-i; ++j){
                        sum *= j;
                }
                sum *= index;
                v.erase(remove(v.begin(), v.end(), x), v.end());
                o += sum;
        }
        return o;
}


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

        p = order(n);
        q = order(n);

        cout << max(p,q) - min(p,q) << endl;

}

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

import sys
import numpy as np
from collections import defaultdict
int1 = lambda x: int(x) - 1
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(500000)

N = int(readline())
A = list(map(int, readline().split()))

Q = int(readline())
m = map(int, read().split())
B, C = zip(*zip(m, m))

dicts = defaultdict(int)
s = 0
for a in A:
    dicts[a] += 1
    s += a

for b, c in zip(B, C):
    cnt = dicts[b]
    dicts[b] = 0
    dicts[c] += cnt
    s += cnt * (c - b)
    print(s)


Measured memory_bytes: 57932
import bisect
N,M,K=map(int,input().split())
a = list(map(int,input().split()))
b = list(map(int,input().split()))
A=[0]*N
A[0]=a[0]
ans=0
for i in range(N-1):
 A[i+1]=A[i]+a[i+1]
B=[0]*M
B[0]=b[0]
for i in range(M-1):
 B[i+1]=B[i]+b[i+1]
for i in range(N):
 if A[i]<=K:
  ans=max(bisect.bisect_right(B,K-A[i])+i+1,ans)
ans=max(bisect.bisect_right(B,K),ans)
print(ans)

Measured memory_bytes: 110996
S = list(input())
N = len(S)
import sys
if N < 3:
    print(0)
    sys.exit()

cnt = 0
BClist = [0] * N
Alist = [0] * N
idx = N-1
while idx-1 >= 0:
    if S[idx-1] == 'B' and S[idx] == 'C':
        cnt += 1
        BClist[idx] = cnt
        BClist[idx-1] = cnt
        idx -= 1
    elif S[idx] != 'A':
        BClist[idx] = 0
        cnt = 0
        
    idx -= 1
    
idx = 0
cnt = 0
while idx < N:
    if S[idx] == 'A':
        cnt += 1
        Alist[idx] = cnt
    else:
        cnt = 0
        
    idx += 1
    
idx = 0
ans = 0
flag = False
while idx < N:
    if Alist[idx] <= 0:
        idx += 1
        continue
    while Alist[idx] > 0:
        idx += 1
        if idx >= N:
            flag = True
            break
    if flag:break
    tmp = Alist[idx-1]
    if BClist[idx] <= 0:
        idx += 1
    else:
        ans += tmp * BClist[idx]
        idx += 1
    
print(ans)


Measured memory_bytes: 14116
r, c = map(int, input().split())
data = [list(map(int, input().split())) for i in range(r)]
for i in range(len(data)):
  data[i].append(sum(data[i]))

data.append([])

for i in range(c + 1):
  val = 0
  for j in range(r):
    val += data[j][i]
  data[r].append(val)

for li_int in data:
  li = [str(a) for a in li_int]
  li = ' '.join(li)
  print(li)



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

#define int long long
#define For(i, a, b) for (int i = (a); i <= static_cast<int>(b); i++)
#define Forr(i, a, b) for (int i = (a); i >= static_cast<int>(b); i--)
#define rep(i, n) For(i, 0, n - 1)
#define repall(i, arr) for (auto& i : (arr))
#define all(x) (x).begin(), (x).end()
#define pb push_back
#define dump(x) cerr << #x << " = " << (x) << '\n'
#define dump2(x, y) \
    cerr << #x << " = " << (x) << " " << #y << " = " << (y) << '\n'

template <typename T>
using pq = priority_queue<T>;
template <typename T>
using pqr = priority_queue<T, vector<T>, greater<T>>;
const int INF = LLONG_MAX / 2;
constexpr int MOD = 1e9 + 7;
using P = pair<int, int>;
using vec = vector<int>;
using mat = vector<vec>;

template <typename T1, typename T2>
ostream& operator<<(ostream& stream, const pair<T1, T2>& p) {
    return stream << p.first << " " << p.second;
}
template <typename T>
void print(const vector<vector<T>> matrix) {
    repall (vec, matrix)
        print(vec);
}
template <typename T>
void print(const vector<T> vec) {
    unsigned int len = vec.size();
    rep (i, len - 1)
        cout << vec[i] << ' ';
    cout << vec[len - 1] << '\n';
}
template <typename Arg>
void print(const Arg arg) {
    cout << arg << '\n';
}
template <typename Head, typename... Args>
void print(const Head head, const Args... args) {
    cout << head << " ";
    print(args...);
}
template <typename T>
T sum_(vector<T> vec, T init = 0) {
    return std::accumulate(all(vec), T(init));
}

void yn(bool tf) { print(tf ? "Yes" : "No"); }
void YN(bool tf) { print(tf ? "YES" : "NO"); }

template <typename T>
void init(vector<T>& v) {
    rep (i, v.size())
        cin >> v[i];
}

template <typename T, typename U>
void init(vector<T>& v, vector<U>& w) {
    assert(v.size() == w.size());
    rep (i, v.size())
        cin >> v[i] >> w[i];
}

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

// -------------------------------------------------------------------
// sort 1 2 3 4
// pqr 1 2 3 must impl >

signed main() {
    cin.tie(0), cout.tie(0), ios::sync_with_stdio(false);
    int a, b;
    cin >> a >> b;
    print(a >= 13 ? b : a >= 6 ? b / 2 : 0);

    return 0;
}


Measured memory_bytes: 256
N = int(input())
a = list()
for i in range(N):
	a.append(int(input()))

temp = 1
count = 0
while temp != 2 and count <= 100001:
	temp = a[temp - 1]
	count += 1

if count > 100000:
	print(-1)
else:
	print(count)


Measured memory_bytes: 7084
#include<bits/stdc++.h>
using namespace std;
 
const int N = 505;

int n, m;
char s[N][N], s1[N][N], s2[N][N];
 
int main () {
	scanf("%d%d", &n, &m);
	for (int i = 1; i <= n; ++i) scanf("%s", s[i] + 1);
	memset(s1, '.', sizeof s1);
	memset(s2, '.', sizeof s2);
	for (int i = 2; i < n; ++i) {
		for (int j = 1; j <= m; ++j) {
			if (j & 1) s1[i][j] = '#';
			else s2[i][j] = '#';
		}
	}
	for (int j = 1; j <= m; ++j) s1[1][j] = '#';
	for (int j = 1; j <= m; ++j) s2[n][j] = '#';
//	for (int i = 1; i <= n; ++i) for (int j = 1; j <= m; ++j) if (s1[i][j] == '.') s2[i][j] = '#';
	for (int i = 1; i <= n; ++i) for (int j = 1; j <= m; ++j) if (s[i][j] == '#') s2[i][j] = s1[i][j] = '#';
//	putchar('\n');
	for (int i = 1; i <= n; ++i, putchar('\n')) for (int j = 1; j <= m; ++j) putchar(s1[i][j]);
	putchar('\n');
	for (int i = 1; i <= n; ++i, putchar('\n')) for (int j = 1; j <= m; ++j) putchar(s2[i][j]);
	for (int i = 1; i <= n; ++i) for (int j = 1; j <= m; ++j) if ((s[i][j] == '#') != (s1[i][j] == '#' && s2[i][j] == '#'))
	puts("A");
	return 0;
}
/*
5 5
#####
#####
#####
#...#
#####
*/

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

#define int long long
typedef pair<int, int> P;
#define rep(i, n) for (int i=0; i<(n); i++)
#define all(c) (c).begin(), (c).end()
#define uniq(c) c.erase(unique(all(c)), (c).end())
#define index(xs, x) (int)(lower_bound(all(xs), x) - xs.begin())
#define _1 first
#define _2 second
#define pb push_back
#define INF 1145141919
#define MOD 1000000007

int Q;
int g(int x, int A, int B) {
  //xy<AB
  int y = (A*B+x-1)/x-1;
  return y - (y>=B);
}
int f(int x, int A, int B) {
  int num = A*B-x+1 - (x <= A);
  return A*B-1-(num-g(x, A, B));
}
int solve(int A, int B) {
  //for (int x=1; x<=A*B; x++) cout<<f(x,A,B)<<",";cout<<"\n";
  long long lo = 1, hi = A*B;
  while (hi-lo>=30000) {
    long long a = (0LL+lo+lo+hi)/3,
              b = (0LL+lo+hi+hi)/3;
    if (f(a, A, B) <= f(b, A, B)) hi = b;
    else lo = a;
  }
  int m = A*B-1;
  for (int i=max(1LL, lo-30000); i<=min(A*B, hi+30000); i++) m = min(m, f(i, A, B));
  return m;
}

signed main() {
  ios::sync_with_stdio(false); cin.tie(0);
  cin >> Q;
  rep(i, Q) {
    long long a, b;
    cin >> a >> b;
    long long m = solve(a, b);
    m = min(m, solve(b, a));
    cout << m << "\n";
  }
  return 0;
}


Measured memory_bytes: 384
#include <stdio.h>

int oturi(int i) {
    int t;
    t = i % 1000;
    if(t == 0) {
        return 0;
    } else {
        return 1000 - t;
    }
}

int main(void) {
    int r, n;
    if(scanf("%d", &n) == 1);
    if(1 <= n && n <= 10000) {
        r = oturi(n);
        printf("%d\n", r);
    }
    return 0;
}

Measured memory_bytes: 1720
#include <bits/stdc++.h>
#define rep(i, l, r) for(int i = (l); i <= (r); i++)
#define per(i, r, l) for(int i = (r); i >= (l); i--)
#define mem(a, b) memset(a, b, sizeof a)

using namespace std;

int n, m, u, v, fa[100005];
int find(int x) { return x == fa[x] ? x : fa[x] = find(fa[x]); }
int main() {
	cin >> n >> m;
	rep(i, 1, n) fa[i] = i;
	int ans = n - 1;
	while(m--) {
		scanf("%d%d", &u, &v);
		if(find(u) ^ find(v)) ans--, fa[fa[u]] = fa[v];
	}
	return !(cout << ans);
}

Measured memory_bytes: 4132
N,M=gets.chomp.split(" ").map(&:to_i)
paths=Array.new(N-1,0)
M.times do
    a,b=gets.chomp.split(" ").map(&:to_i)
    if a==1
        paths[b-2]+=1
    elsif b==1
        paths[a-2]+=1
    else
        paths[b-2]+=1
        paths[a-2]+=1
    end
end
puts paths.all?{|i| i.even? } ? "YES" : "NO"


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

#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define rep3(i,m,n) for(int (i)=m;(i)<=(n);(i)++)
#define rep3rev(i,m,n) for(int (i)=m;(i)>=(n);(i)--)
#define all(a) (a.begin()),(a.end())
#define rall(a) (a.rbegin()),(a.rend())
#define fi first
#define se second

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

void Main()
{
	int a, b, c;
  	cin >> a >> b >> c;
 	if(a-b > c) cout << 0 << endl;
	else cout << c-a+b << endl;
	return;
}

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


Measured memory_bytes: 384
#include<algorithm>
#include<climits>
#include<cmath>
#include<iomanip>
#include<iostream>
#include<list>
#include<map>
#include<numeric>
#include<queue>
#include<set>
#include<stack>
#include<utility>
#include<vector>
 
#define lint long long
#define REP(i, x, n) for(int i = x ; i < n ; i++)
#define REPR(i, x, n) for(int i = n - 1 ; i >= x ; i--)
#define rep(i, n) REP(i, 0, n)
#define repr(i, n) REPR(i, 0, n)
#define SORT(c) sort((c).begin(), (c).end())
#define SORT_INV(c) sort((c).begin(), (c).end(), greater<int>())
#define IINF INT_MAX
#define LLINF LLONG_MAX

using namespace std;

int main(){
    int n, k;
    cin >> n >> k;
    vector< pair<lint, lint> > p(n);
    rep(i, n){
        lint x, y;
        cin >> x >> y;
        p[i] = make_pair(x, y);
    }
    SORT(p);
    lint ans = LLINF;
    p.push_back(make_pair(LLINF, LLINF));
    rep(i, n-1){
        REP(j, i+1, n){
            lint hi = max(p[i].second, p[j].second), lo = min(p[i].second, p[j].second);
            int l = 0, r = 0, cnt = 0;
            while(r <= n){
                if(cnt < k){
                    if(lo <= p[r].second && p[r].second <= hi){
                        cnt++;
                    }
                    r++;
                }else{
                    ans = min(ans, (hi - lo) * (p[r-1].first - p[l].first));
                    if(lo <= p[l].second && p[l].second <= hi){
                        cnt--;
                    }
                    l++;
                }
            }
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define syosu(x) fixed<<setprecision(x)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> P;
typedef pair<double,double> pdd;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<string> vs;
typedef vector<P> vp;
typedef vector<vp> vvp;
typedef vector<pll> vpll;
typedef pair<P,int> pip;
typedef vector<pip> vip;
const int inf=1<<30;
const ll INF=1ll<<60;
const double pi=acos(-1);
const double eps=1e-8;
const ll mod=1e9+7;
const int dx[4]={-1,0,1,0},dy[4]={0,-1,0,1};

class Graph{
	private:
	int n;
	vvi g;
	public:
	vi match,used;
	bool BM_dfs(int v){
		used[v]=1;
		for(auto u:g[v]){
			int w=match[u];
			if(w<0||!used[w]&&BM_dfs(w)){
				match[v]=u;
				match[u]=v;
				return 1;
			}
		}
		return 0;
	}
	int BM(){
		int res=0;
		match=vi(n,-1);
		for(int i=0;i<n;i++) if(match[i]<0){
			used=vi(n);
			if(BM_dfs(i)) res++;
		}
		return res;
	}
	Graph(int v){
		n=v;
		g=vvi(v);
	}
	void add_edge(int s,int t){
		g[s].push_back(t);
		g[t].push_back(s);
	}
};

int n,A,B;
vi a,b;

int main(){
	cin>>n>>A>>B;
	a=b=vi(n);
	Graph g(n);
	for(int i=0;i<n;i++) cin>>a[i]>>b[i];
	int res=0;
	vi c(n);
	for(int i=0;i<n;i++){
		int t=abs(a[i]-b[i]);
		if(t<=A||B<=t&&t<=2*A) res++,c[i]++; 
	}
	for(int i=0;i<n;i++) for(int j=0;j<i;j++) if(!c[i]&&!c[j]){
		int t=abs(a[i]+a[j]-b[i]-b[j]);
		if(t<=A||B<=t&&t<=2*A) g.add_edge(i,j);
	}
	cout<<res+g.BM()<<endl;
}


Measured memory_bytes: 3412
package main

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

////////////////////////////////////////
///        templates                 ///
////////////////////////////////////////

var sc = bufio.NewScanner(os.Stdin)

func nextLine() string {
	sc.Scan()
	return sc.Text()
}

var rdr = bufio.NewReaderSize(os.Stdin, 1000000)

func readBigLine() string {
	buf := make([]byte, 0, 1000000)
	for {
		l, p, e := rdr.ReadLine()
		if e != nil {
			panic(e)
		}
		buf = append(buf, l...)
		if !p {
			break
		}
	}
	return string(buf)
}

func strSprit(str string) []string {
	cols := strings.Split(str, " ")
	return cols
}

func parseInt(str string) int {
	n, _ := strconv.Atoi(str)
	return n
}

func intSprit(str string) []int {
	strs := strSprit(str)
	cols := make([]int, len(strs))
	for i, v := range strs {
		cols[i] = parseInt(v)
	}
	return cols
}

func bitCount(n uint) int {

	x := uint64(n)

	const m = 1<<64 - 1
	const m0 = 0x5555555555555555
	const m1 = 0x3333333333333333
	const m2 = 0x0f0f0f0f0f0f0f0f

	x = x>>1&(m0&m) + x&(m0&m)
	x = x>>2&(m1&m) + x&(m1&m)
	x = (x>>4 + x) & (m2 & m)
	x += x >> 8
	x += x >> 16
	x += x >> 32

	return int(x) & (1<<7 - 1)
}

func bitExist(n, i int) bool {
	return ((n >> uint(i)) & 1) == 1
}

////////////////////////////////////////
///        end templates             ///
////////////////////////////////////////
func cmpStrNum(a, b string) bool {
	if a == "---" {
		return true
	}
	if len(a) < len(b) {
		return true
	} else if len(a) > len(b) {
		return false
	}
	return a < b
}

func main() {
	line := nextLine()

	spl := intSprit(line)

	N := spl[0]

	a := intSprit(nextLine())
	tb := []int{2, 5, 5, 4, 5, 6, 3, 7, 6}

	dp := make([]string, 100000)
	for i := 1; i < len(dp); i++ {
		dp[i] = "---"
	}
	dp[0] = ""

	for i := 0; i <= N; i++ {
		if dp[i] == "---" {
			continue
		}
		for _, v := range a {
			if cmpStrNum(dp[i+tb[v-1]], dp[i]+strconv.Itoa(v)) {
				dp[i+tb[v-1]] = dp[i] + fmt.Sprint(v)
			}
		}
	}
	fmt.Println(dp[N])
}


Measured memory_bytes: 131136
#include<iostream>
#include<cstdio>
using namespace std;
int main()
{
	int n;
	cin>>n;
	if(n<1200)	cout<<"ABC";
	if(n>=1200&&n<2800)		cout<<"ARC";
	if(n>=2800)		cout<<"AGC";
	return 0;
}

Measured memory_bytes: 256
#include <iostream>

using namespace std;

int main()
{
    int X;
    int n_500;
    int n_5;
    int total;
    cin >> X;
    n_500=X/500;
    X=X%500;
    n_5=X/5;
    total=n_500*1000+n_5*5;
    cout << total << endl;
    return 0;
}


Measured memory_bytes: 256
import math

def f(A, B):
    digit_A = len(str(A))
    digit_B = len(str(B))

    return max(digit_A, digit_B)

n = int(input())

ans = 99999

for i in range(1, math.floor(math.sqrt(n)) + 1):
    if n % i != 0:
        continue
    A = i
    B = n // i
    ans = min(ans, f(A, B))

print(ans)


Measured memory_bytes: 3060
#include<iostream>
#include<algorithm>
#include<cmath>
using namespace std;
int main()
{
	long long n, res = 0, tmp, ka = 0, cnt = 1;
	cin >> n;
	for (int i = 1; i <= sqrt(n); i++)
	{
		ka = (n - 1) / cnt;
		tmp = ka - i;
		if (tmp >= 1) res += tmp * 2 + 1;
		else if (tmp == 0) res += 1;
		cnt++;
	}
	cout << res << endl;
	return 0;
}

Measured memory_bytes: 3152
#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")
#define pb push_back
#define pi pair<int, int>
#define l first
#define r second
#define all(x) x.begin(), x.end()
#define fori(a, b, step) for (int i = a; i < b; i += step)
#define forj(a, b, step) for (int j = a; j < b; j += step)
#define int long long

const int maxn = 1e6 + 1, mod = 1e9 + 7;

using namespace std;

int a[maxn];

signed main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);
    int k; cin >> k;
    if (k % 2 == 0 || k % 5 == 0) {
        cout << -1;
        return 0;
    }
    int cs = 0;
    for (int i = 0; ; i++) {
        cs = (10 * cs + 7) % k;
        if (!cs) {
            cout << i + 1;
            return 0;
        }
    }
    return 0;
}


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

int main(){
  int a;
  cin >> a;
  int mod = 1000000007;
  long long sum = 0;
  vector<int> s(a);
  for (int i=0;i<a;i++){
    cin >> s.at(i);
    sum += s.at(i);
    sum %= mod;
  }
  long long ans =0;
  for (int i=0;i<a-1;i++){
    sum -= s.at(i);
    if (sum < 0) sum += mod;
    ans += s.at(i)*sum;
    ans %= mod;
  }
  cout << ans << endl;
}


Measured memory_bytes: 4028
#include <iostream>
using namespace std ;
int main () {
int x,y,z,w;
cin >> x >> y >>z>>w;
if (x+y > z+w){
    cout << "Left";
}
else if (x+y < z+w){
    cout << "Right";
}
else {
    cout << "Balanced";
}
return 0 ;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
ll gcd(ll a,ll b)
{
	if (a%b==0)
	{
		return(b);
    }
	else
	{
		return(gcd(b,a%b));
    }
}
 
ll lcm(ll a, ll b)
{
    return a * b / gcd(a, b);
}

int main(){
  ll n; cin >> n;
  vector<vector<ll>> tb(10,vector<ll>(10,0));
  for(ll i=1; i<n+1; i++){
    string tmp = to_string(i);
    tb.at(tmp.at(0)-'0').at(tmp.at(tmp.size()-1)-'0')++;
  }
  ll ans =0;
  for(ll i=1; i<10; i++){
    for(ll j=1; j<10; j++){
      ans += tb.at(i).at(j)*tb.at(j).at(i);
  }
  }

  cout << ans << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
/* 
int get(int x)
{
	if(x==fa[x])	return x;
	return fa[x]=get(fa[x]);
}//路径压缩 
int merge(int x,int y)
{
	fa[get(x)]=get(y);
}//合并 */ 
int main()
{
	int n,a[100010];
	cin>>n;
	for(int i=1;i<=n;i++)
	{
		int p;
		cin>>p;
		a[p]=i;
	}
	for(int i=1;i<=n;i++)	cout<<a[i]<<" ";
	return 0;
}

Measured memory_bytes: 1152
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using PII = pair<ll, ll>;
#define FOR(i, a, n) for (ll i = (ll)a; i < (ll)n; ++i)
#define REP(i, n) FOR(i, 0, n)
#define ALL(x) x.begin(), x.end()
template<typename T> void chmin(T &a, const T &b) { a = min(a, b); }
template<typename T> void chmax(T &a, const T &b) { a = max(a, b); }
struct FastIO {FastIO() { cin.tie(0); ios::sync_with_stdio(0); }}fastiofastio;
#ifdef DEBUG_ 
#include "../program_contest_library/memo/dump.hpp"
#else
#define dump(...)
#endif
const ll INF = 1LL<<60;

int main(void) {
    ll n, k;
    cin >> n >> k;
    vector<ll> a(n);
    REP(i, n) cin >> a[i], a[i]--;

    ll ret = a[0]!=0;
    vector<vector<ll>> g(n);
    FOR(i, 1, n) {
        g[i].push_back(a[i]);
        g[a[i]].push_back(i);
    }

    function<ll(ll,ll,ll)> dfs = [&](ll v, ll p, ll d) {
        ll ma = 1;
        for(auto to: g[v]) if(p != to) {
            ll val = dfs(to, v, d+1);
            dump(v, to, val);
            chmax(ma, val+1);
        }
        bool flag = false;
        if(ma == k && d+ma-1 > k) {
            ma = 0;
            ret++;
            flag = true;
        }
        dump(v, d, ma, flag);
        return ma;
    };
    dfs(0, -1, 0);

    cout << ret << endl;

    return 0;
}

Measured memory_bytes: 17408
#include <iostream>
#include<string>
#include<algorithm>
#include<vector>

using namespace std;

int main()
{
	string str;
	vector<int> num;
	vector<string> space;

	getline(cin, str);

	//Split
	string cut = "";
	for (int i = 0; i < str.length(); i++) {
		if (str[i] != ' ') {
			cut += str[i];
		}
		else {
			space.push_back(cut);
			cut = "";
		}
	}
	space.push_back(cut);
	
	for (int i = 0; i < space.size(); i++) {
		if (space[i] == "+") {
			num[num.size() - 2] += num[num.size() - 1];
			num.pop_back();
		}
		else if (space[i] == "-") {
			num[num.size() - 2] -= num[num.size() - 1];
			num.pop_back();
		}
		else if (space[i] == "*") {
			num[num.size() - 2] *= num[num.size() - 1];
			num.pop_back();
		}
		else {
			num.push_back(atoi(space[i].c_str()));
		}
	}

	cout << num[0] << endl;

	return 0;
}



Measured memory_bytes: 3188
X = int(input())

if 400 <= X <= 599:
    print("8")

elif 600 <= X <= 799:
    print("7")

elif 800 <= X <= 999:
    print("6")

elif 1000 <= X <= 1199:
    print("5")

elif 1200 <= X <= 1399:
    print("4")

elif 1400 <= X <= 1599:
    print("3")

elif 1600 <= X <= 1799:
    print("2")

elif 1800 <= X <= 1999:
    print("1")


Measured memory_bytes: 9176
#include<stdio.h>
#include<iostream>
#include<algorithm>
#include<string>
#include<string.h>
#include<math.h>
#include<stdlib.h>
#include<vector>
#include<queue>
#include<map>
#include<iomanip>
#include<set>
#include<bitset>
#define rep(index,num) for(int index=0;index<num;index++)
#define rep1(index,num) for(int index=1;index<=num;index++)
#define brep(index,num) for(int index=num-1;index>=0;index--)
#define brep1(index,num) for(int index=num;index>0;index--)
#define scan(argument) cin>>argument
#define prin(argument) cout<<argument<<endl
#define kaigyo cout<<endl
#define eps 1e-7
#define mp(a1,a2) make_pair(a1,a2)
#define ALL(a) (a).begin(),(a).end()
#define rALL(a) (a).rbegin(),(a).rend()
typedef long long ll;
typedef long double ld;
using namespace std;
typedef pair<ll,ll> pll;
typedef pair<int,int> pint;
typedef vector<int> vint;
typedef vector<ll> vll;
typedef vector<pint> vpint;
typedef vector<pll> vpll;
ll INFl=(ll)1e+18+1;
int INF=1e+9+1;
ll gojo(ll a){
	return a*a*a*a*a;
}
int main(){
	ll X;
	scan(X);
	for(ll A=0;A<=1000;A++){
		for(ll B=-A;B<=A;B++){
			if(gojo(A)-gojo(B)==X){
				printf("%lld %lld\n",A,B);
				return 0;
			}
		}
	}
	return 0;
}


Measured memory_bytes: 3768
import java.util.*;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		long N = sc.nextLong();
		sc.close();

		long A = N / 500; // 500yen
		long B = (N - (500 * A)) / 5; // 5yen

		System.out.println(1000 * A + 5 * B);

	}
}


Measured memory_bytes: 22996
#include <bits/stdc++.h>
using namespace std;
static const long long MOD=1000000007;
static const int MAX = 2010;

long long fac[MAX], finv[MAX], inv[MAX];

// テーブルを作る前処理
void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}

// 二項係数計算
long long COM(int n, int k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

int main(){
  COMinit();
  long long N,K;
  cin>>N>>K;
  long long ans;
  for(int i=1;i<=K;i++){
    ans=COM(N-K+1,i)*COM(K-1,i-1)%MOD;
  cout<<ans<<endl;    
  }
  return 0;
}


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

int main(){
	string s;
	cin >> s;
  	rep(i, s.size() - 1){
      if(s[i] == s[i+1]){
        cout << i+1 << " " << i+2 << endl;
        return 0;
      }
    }
	rep(i, s.size() - 2){
      if(s[i] == s[i+2]){
        cout << i+1 << " " << i+3 << endl;
        return 0;
      }
    }
	cout << "-1 -1" << endl;
	return 0;
}


Measured memory_bytes: 512
import math

N, K = (int(a) for a in input().split())
A = [int(a) for a in input().split()]

def isOK(X):
    cutcount = 0
    for i in range(N):
        cutcount += math.ceil(A[i] / X) - 1
    if cutcount <= K:
        return True
    else:
        return False

def binary_search():
    left = 0
    right = max(A) + 1

    while (right - left) > 1:
        mid = left + (right - left) // 2
        if (isOK(mid)):
           right = mid;
        else:
            left = mid;

    return right

print(binary_search())

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

int main() {
	string stn; int N,ans = 0; cin >> N >> stn;
	for(int i = 0 ; i < N ; i++){
		if(stn[i] == '.') ans++;
	}
	int akari = ans;
	for(int i = 0 ; i < N ; i++){
		if(stn[i] == '#') akari++;
		if(stn[i] == '.') akari--;
		ans = min(akari,ans);
	}
	cout << ans << endl;
}

Measured memory_bytes: 640
// #include <bits/stdc++.h>
#include <iostream>
#include <vector>
#include <map>
#include <math.h>
#include <map>
#include <algorithm>
#include <set>
#include <climits>
#define mod 1000000007
#define ll long long int
#define ld long double
#define fastio ios_base::sync_with_stdio(false)
#define fastcin cin.tie(NULL)
using namespace std;
int main(){

	fastio;
	fastcin;	
	
    
    // freopen("small_input.txt", "r", stdin);
    
    // freopen("small_output.txt", "w", stdout);
    
    
    int a,b,c;
    cin>>a>>b>>c;

    int ans=0;
    if(c<=a+b){
        ans = c+b;
    }else{
        ans = a+2*b;
        c = c - a - b;
        if(c>=1){
            ans++;
        }
    }
    cout<<ans;

    
}

Measured memory_bytes: 256
/*
      author : nishi5451
      created: 11.08.2020 20:26:43
*/

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


int main(){
    int n;
    cin >> n;
    if(n>999){
        n-=999;
        char a = '0' + n/100;
        char b = '0' + (n%100)/10;
        char c = '0' + (n%10);
        cout << "ABD" << endl;
    }  
    else{
        char a = '0' + n/100;
        char b = '0' + (n%100)/10;
        char c = '0' + (n%10);
        cout << "ABC" << endl;
    }
    return 0;
}

Measured memory_bytes: 3544
#include <bits/stdc++.h>
#include <math.h>
#include <cmath>
 
using namespace std;
using std::cout;
using ll =long long;
bool is_int_lround(double x){
  return std::lround(x)==x;
}
int ketasuu(int x){
  int n=0;
  while(x>0){
    x /=10 ;
    n ++;
  }
  return n;
}
ll gcd11(ll x, ll y){
  long long a= max(x,y), b=min(x,y), c=a%b;
  while( c!=0){
    a =b;
    b =c;
    c = a%b;
  }
  return b;
}

int ab(int x, int y){
  if(x>=y){
    return x-y;
  }
  else if(y>x){
    return y-x;
  }
}
int main(){
  int c[3][3];
  for(int i =0; i<3;i++){
    for(int j=0; j<3 ;j++){
      cin >> c[i][j];
    }
  }
  bool ans =false ;
  for(int i=0; i<= min( min(c[0][0],c[1][0]),c[2][0])    ; i++ ){
    int a_0 = c[0][0]-i;
    int a_1 = c[1][0]-i;
    int a_2 = c[2][0]-i;
    if(c[0][1]-a_0 == c[1][1] -a_1 && c[2][1] -a_2 == c[0][1]-a_0 && c[0][2]-a_0 == c[1][2] -a_1 && c[2][2] -a_2 == c[0][2]-a_0){
        ans =true;
      break;
    }
  }
  if(ans){
    cout << "Yes" <<endl;
  }
  else{
    cout <<"No" <<endl;
  }


}


Measured memory_bytes: 256
#include<iostream>
using namespace std;
int main() {
	//A
	/*
	int a, b;
	cin >> a;
	cin >> b;

	if ((a <= 0) && (b >= 0)) {
		cout << "Zero";
	}
	else if(a>0){
		cout << "Positive";
	}
	else {
		if ((b - a) % 2 == 0) {
			cout << "Negative";
		}
		else {
			cout << "Positive";
		}
	}
	
	return 0;*/

	//B
	int n, m;
	int x;
	int y;
	int flag[100000];
	int ball[100000];
	cin >> n;
	cin >> m;
	int i,c;
	
	for (i = 0; i < 100000; i++) {
		flag[i] = 0;
		ball[i] = 1;
	}
	flag[0] = 1;
	for (i = 0; i < m; i++) {
		cin >> x;
		cin >> y;

		if (flag[x-1] == 1) {
			flag[y-1] = 1;
		}
		ball[x - 1]--;
		if (ball[x - 1] == 0) {
			flag[x - 1] = 0;
		}
		ball[y - 1]++;
	}
	c = 0;
	for (i = 0; i < n; i++) {
		if (flag[i] == 1) {
			c++;
		}
	}
	cout << c;
	return 0;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<(int)(n);i++)
int main(){
    long long a,b,c,k;
    cin>>a>>b>>c>>k;
    if(k<=a) cout<<k;
    if(a<k && k<=a+b) cout<<a;
    if(k>a+b) cout<<a-(k-a-b);
}

Measured memory_bytes: 3648
import sys, os, math, bisect, itertools, collections, heapq, queue
# from scipy.sparse.csgraph import csgraph_from_dense, floyd_warshall
from decimal import Decimal
from collections import defaultdict, deque

# import fractions

sys.setrecursionlimit(10000000)

ii = lambda: int(sys.stdin.buffer.readline().rstrip())
il = lambda: list(map(int, sys.stdin.buffer.readline().split()))
fl = lambda: list(map(float, sys.stdin.buffer.readline().split()))
iln = lambda n: [int(sys.stdin.buffer.readline().rstrip()) for _ in range(n)]

iss = lambda: sys.stdin.buffer.readline().decode().rstrip()
sl = lambda: list(map(str, sys.stdin.buffer.readline().decode().split()))
isn = lambda n: [sys.stdin.buffer.readline().decode().rstrip() for _ in range(n)]

lcm = lambda x, y: (x * y) // math.gcd(x, y)
# lcm = lambda x, y: (x * y) // fractions.gcd(x, y)

MOD = 10 ** 9 + 7
MAX = float('inf')


def main():
    if os.getenv("LOCAL"):
        sys.stdin = open("input.txt", "r")

    N, K = il()
    T = il()

    ret = K
    for n in range(N-1):
        ret += min(T[n + 1] - T[n], K)
    print(ret)


if __name__ == '__main__':
    main()


Measured memory_bytes: 29104
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <cstring>

using std::cin;
using std::cout;
using std::cerr;
using std::endl;

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

  int N;
  std::string s;

  cin >> N;
  cin >> s;

  int west[300001], east[300001];
  std::memset(west, 0, sizeof west);
  std::memset(east, 0, sizeof east);

  for (int i = 0; i < N; ++i) {
    if (s[i] == 'W') {
      west[i] = 1;
    }
    else {
      east[i] = 1;
    }
  }

  for (int i = 0; i < N - 1; ++i) {
    west[i + 1] += west[i];
    east[i + 1] += east[i];
  }

  int ans = int(1e9);

  for (int i = 0; i < N; ++i) {
    if (i == 0) {
      ans = std::min(ans, east[N - 1] - east[i]);
    }
    else if (i == N - 1) {
      ans = std::min(ans, west[N - 2]);
    }
    else {
      ans = std::min(ans, west[i - 1] + east[N - 1] - east[i]);
    }
  }

  cout << ans << endl;

  return 0;
}

Measured memory_bytes: 2948
n=int(input())
start={"M","A","R","C","H"}
import collections
d=collections.defaultdict(set)
for i in range(n):
    a=input()
    if a not in d[a[0]] and a[0] in start:
        d[a[0]].add(a)

lis=[len(i) for i in d.values() if len(i)>0]

num=len(lis)
if num<3:
    print(0)
    exit()
ans=0
for x in range(num-2):
    for y in range(x+1,num-1):
        for z in range(y+1,num):
            ans+=lis[x]*lis[y]*lis[z]
print(ans)

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

#define F first
#define S second
#define MP make_pair
#define pb push_back
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define LCM(a, b) (a) / __gcd((a), (b)) * (b)
#define CEIL(a, b) (a)/(b)+(((a)%(b))?1:0)
#define ln '\n'

using namespace std;
using LL = long long;
using ldouble = long double;
using P = pair<int, int>;
using LP = pair<LL, LL>;

static const int INF = INT_MAX;
static const LL LINF = LLONG_MAX;
static const int MIN = INT_MIN;
static const LL LMIN = LLONG_MIN;
static const int MOD = 1e9 + 7;
static const int SIZE = 200005;

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

vector<LL> Div(LL n) {
    vector<LL> ret;
    for(LL i = 1; i * i <= n; ++i) {
        if(n % i == 0) {
            ret.pb(i);
            if(i * i != n) ret.pb(n / i);
        }
    }
    sort(all(ret));
    return ret;
}

void dfs(int pos);

vector<int> tree[SIZE];
vector<LL> dp;
LL node_num[SIZE];
LL res[SIZE];
bool isvisit[SIZE];

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

    int N;
    cin >> N;
    dp.resize(N);
    for(int i = 0; i < N; ++i) {
        dp[i] = LINF;

    }

    for(int i = 1; i <= N; ++i) {
        cin >> node_num[i];

    }

    for(int i = 0; i < N - 1; ++i) {
        int u, v;
        cin >> u >> v;
        tree[u].pb(v);
        tree[v].pb(u);

    }

    dfs(1);
    for(int i = 1; i <= N; ++i) {
        cout << res[i] << endl;

    }

    return 0;
}

void dfs(int pos) {
    if(isvisit[pos]) return;
    isvisit[pos] = true;

    int p = lower_bound(all(dp), node_num[pos]) - dp.begin();
    LL tmp = dp[p];
    dp[p] = node_num[pos];
    res[pos] = lower_bound(all(dp), LINF) - dp.begin();

    for(int i = 0; i < tree[pos].size(); ++i) {
        dfs(tree[pos][i]);

    }

    dp[p] = tmp;
    return;
}


Measured memory_bytes: 27508
#include<stdio.h>

int main(){
  int i, j=0, n, q, S[10000], T[10000], count=0, key;

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

  for(i=0;i<q;i++){
    key=T[i];
    S[n]=key;
    while(S[j]!=key){
	j++;
      }
    if(j!=n)count++;
    j=0;
  }

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

  return 0;
}

Measured memory_bytes: 648
#include <iostream>
#include <string>
#include <vector>

#define rep(i,n) for (int i = 0; i < (n); ++i)

using std::cin;
using std::cout;
using std::endl;
using std::string;
using std::vector;

int main() {
  int N, K, X, Y;
  cin >> N >> K >> X >> Y;

  int sum = 0;
  rep(i, N) {
    if (i < K) sum += X;
    else sum += Y;
  }

  cout << sum << endl;

  return 0;
}


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

int main() {
  int arr[3];
  vector<int> vc;
  for(int i=0; i<3; i++) {
    cin >> arr[i];
    vc.push_back(arr[i]);
  }
  sort(vc.begin(), vc.end());
  printf("%d %d %d\n", vc[0], vc[1], vc[2]);

}

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

using namespace std;

static const int INF = 1e9 + 7;

template<typename T>
using Vec = vector<T>;

template<typename T, typename T2>
using P = pair<T, T2>;

template<typename... Args>
using Tup = tuple<Args...>;

template<typename T>
using qp = priority_queue<T, Vec<T>, greater<T> >;

template<typename T>
using pq = priority_queue<T>;

using llong = long long;
using ullong = unsigned long long;
using uint = unsigned int;

template<typename T>
T gcd(T x, T y)
{
	return y ? gcd(y, x % y) : x;
}

void hawawa()
{
	int a, b, q;
	cin >> a >> b >> q;
	Vec<llong> s(a), t(b);
	for (auto&& i : s) {
		cin >> i;
	}
	for (auto&& i : t) {
		cin >> i;
	}
	s.push_back(99999999999);
	s.push_back(-99999999999);
	t.push_back(99999999999);
	t.push_back(-999999999999);
	sort(begin(s), end(s));
	sort(begin(t), end(t));
	while (q--) {
		llong x;
		cin >> x;
		auto sp = lower_bound(begin(s), end(s), x);
		auto tp = lower_bound(begin(t), end(t), x);
		llong ans = min(max(*sp, *tp) - x, x - min(*(sp - 1), *(tp - 1)));
		ans = min({ ans, *sp - *(tp - 1) + *sp - x, *sp - *(tp - 1) + x - *(tp - 1) });
		ans = min({ ans, *tp - *(sp - 1) + *tp - x, *tp - *(sp - 1) + x - *(sp - 1) });
		cout << ans << "\n";
	}
}

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


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

N = int(input())
A = list(map(int, input().split()))
B = list(map(int, input().split()))

# resort list X O(len(X))
def sorting(X, l):
    eX = []
    oX = []
    for x in X:
        if x&(1<<l):
            oX.append(x)
        else:
            eX.append(x)
    return eX + oX

ans = 0
for shift in range(30):
    A = sorting(A, shift)
    B = sorting(B, shift)
    div = (1<<(shift+1))
    count = 0
    l1 = N
    r1 = N
    l2 = N
    r2 = N
    for a in A:
        while a%div + B[l1-1]%div >= div//2 and l1 > 0:
            l1 -= 1
        while a%div + B[r1-1]%div >= div and r1 > 0:
            r1 -= 1
        while a%div + B[l2-1]%div >= div//2*3 and l2 > 0:
            l2 -= 1
        while a%div + B[r2-1]%div >= 2*div and r2 > 0:
            r2 -= 1
        count += (r1-l1) + (r2-l2)
    if count%2 == 1:
        ans += (1<<shift)

print(ans)

Measured memory_bytes: 140256
#include <iostream>
#include <string>
#include <vector>
#include <utility>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <algorithm>
#include <bitset>
#include <cstdio>
#include <cmath>

using namespace std;

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


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

int main()
{
    int a=0,l, r, d;
    cin >> l >> r >> d;
    for (int i = l; i <= r;i++)
    {
        if(i%d==0)
        {
            a++;
        }
    }

        cout << a << endl;
}


Measured memory_bytes: 3620
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <numeric>
#define ll long long int
using namespace std;

int main(){
    ll h, w, n;
    ll a, b;
    cin >> h >> w >> n;
    vector<vector<ll>> dots;
    for(ll i=0; i<n; i++){
        cin >> a >> b;
        for(int j=0; j<3; j++){
            for(int k=0; k<3; k++){
                if(1 < a+j-1 && a+j-1 <= h-1 && 1 < b+k-1 && b+k-1 <= w-1){
                    vector<ll> dot {a+j-1, b+k-1};
                    dots.push_back(dot);
                }
            }
        }
    }
    sort(dots.begin(), dots.end());
    vector<ll> ans(10, 0);
    if((int)dots.size() != 0){
        int count = 1;
        for(ll i=1; i<(int)dots.size(); i++){
            if(dots[i-1] == dots[i]){
                count++;
            }
            else{
                ans[count]++;
                count = 1;
            }
        }
        ans[count]++;
    }
    cout << (h-2) * (w-2) - accumulate(ans.begin()+1, ans.end(), 0) << "\n";
    for (int i=1; i<(int)ans.size(); i++){
        cout << ans[i] << "\n";
    }
    return 0;
}

Measured memory_bytes: 51364