akhauriyash/Code-Regression huggingface dataset:
import Data.List
import qualified Data.ByteString.Char8 as B

main :: IO ()
main = breads >>= print . solve
    where
        solve [n, m] = (100 * n + 1800 * m) * 2 ^ m

breads :: IO [Int]
breads = unfoldr uff <$> B.getLine
    where
        uff b = check <$> B.readInt b
        check (a, b)
            | B.null b = (a, b)
            | otherwise = (a, B.tail b)

Measured memory_bytes: 380
def solve():
    data = read()
    result = think(data)
    write(result)


def read():
    return [read_line(), read_line()]


def read_int(n):
    return list(map(lambda x: int(x), read_line().split(' ')))[:n]


def read_float(n):
    return list(map(lambda x: float(x), read_line().split(' ')))[:n]


def read_line(n=0):
    if n == 0:
        return input().rstrip()
    else:
        return input().rstrip()[:n]


def think(data):
    d1, d2 = data[0], data[1]
    count = 0
    for i in range(len(d1)):
        if d1[i] == d2[i]:
            count += 1
    return count


def write(result):
    print(result)


if __name__ == '__main__':
    solve()

Measured memory_bytes: 38384
//In The Name of Allah
#include <bits/stdc++.h>

using namespace std;

typedef long long ll;

const int N = 1e6 + 10;
const ll mod = 1e9 + 7;

ll dp[N];

int main(){
    ios::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);
    ll n;
    cin >> n;
    dp[0] = 1;
    dp[1] = n;
    ll ps = n - 1;
    for (ll i = 2; i <= n; i ++){
        dp[i] = (dp[i - 1] + (n - 1) * (n - 1) % mod + ps) % mod;
        ps = (ps + dp[i - 2] - 1) % mod;
    }
    dp[n] = (dp[n] + mod) % mod;
    cout << dp[n];
    return 0;
}


Measured memory_bytes: 11404
fn main() {
    let (a, b, c): (usize, usize, usize) = (read::<usize>(), read::<usize>(), read::<usize>());
    let mut v: Vec<usize> = vec![a, b, c];
    v.sort();
    println!("{} {} {}", v[0], v[1], v[2]);
}

// =========
#[allow(unused_imports)]
use std::cmp::{max, min};
#[allow(unused_imports)]
use std::collections::{HashMap, HashSet};
#[allow(unused_imports)]
use std::process::exit;

#[allow(dead_code)]
const MOD: usize = 1000000007;

fn read<T: std::str::FromStr>() -> T {
    use std::io::Read;
    let stdin = std::io::stdin();
    let stdin = stdin.lock();
    let token: String = stdin
        .bytes()
        .map(|c| c.expect("failed to read char") as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().expect("failed to parse token")
}

// =========



Measured memory_bytes: 5028
#include<cstdio>
#include<cstring>
#include<iostream>
#include<cmath>
using namespace std;
typedef int ll;
const ll maxn=100;
double sum=0.0;
double cnt=1;
ll pos[maxn][2]={0};
double distance(ll x1,ll y1,ll x2,ll y2){
	return sqrt( ( (x1-x2)*(x1-x2) )+((y1-y2)*(y1-y2) ));
} 

int main(){

	ios::sync_with_stdio(false);
	ll n;
	cin>>n;
	for(ll i=1;i<=n;i++){
		cnt*=i;
		cin>>pos[i][0]>>pos[i][1];	
	}
	int cs=0;
	for(ll i=1;i<=n;i++){
		for(ll j=i+1;j<=n;j++){		
			sum+=(distance(pos[i][0],pos[i][1],pos[j][0],pos[j][1]))*2/n;
		}
	}
	printf("%.10lf\n",sum);
	return 0;
}
//8
//-406 10
//512 859
//494 362
//-955 -475
//128 553
//-986 -885
//763 77
//449 310


Measured memory_bytes: 888
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define all(v) v.begin(),v.end()
#define rall(v) v.rbegin(),v.rend()
typedef long long ll;
#define _GLIBCXX_DEBUG
typedef vector<int> vec;
typedef vector<ll> lvec;
typedef vector<char>cvec;
typedef pair<ll, ll> LP;
typedef tuple<ll, ll, ll> LT;
typedef pair<int, int> P;
typedef tuple<int, int, int> T;
ll f(ll x){
  if(x==1){
    return 1;
  }
  else{
    return 2*f(x/2)+1;
  }
}  
int main()	{
  ll h;
  cin>>h;
  cout<<f(h)<<endl;
}

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

int main(){
  string s, t;
  cin >> s >> t;
  bool found = false;
  for(int i=(int)(s.length()-(t.length()-2)); i>=0; i--){
    bool isfit = true;
    for(int j=0; j<(int)t.length(); j++){
      if(!(s[i+j] == t[j] || s[i+j] == '?')){
        isfit = false;
        break;
      }
    }
    if(isfit){
      for(int j=0; j<(int)t.length(); j++) s[i+j] = t[j];
      found = true;
      break;
    }
  }
  for(int i=0; i<(int)s.length(); i++){
    if(s[i] == '?') s[i] = 'a';
  }
  if(found) cout << s << endl;
  else cout << "UNRESTORABLE" << endl;
  return 0;
}
  
  
  


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

using namespace std;

#define ll long long
#define X first
#define Y second
#define all(x) x.begin(), x.end()

const int MX = (int)1e5 + 10;
// const int mod = (int)1e9 + 7;

int main(int argc, char* argv[]){

    cin.tie(0); cout.tie(0);
    ios_base::sync_with_stdio(0);

    int n;
    cin >> n;

    string a[n];
    map<string, int> cnt;
    for(int i = 0; i < n ; ++i){
        cin >> a[i];
        sort(all(a[i]));
        cnt[a[i]]++;
    }

    ll res = 0;
    for(auto &p : cnt){
        int y = p.Y;
        res += (y * (y - 1LL) / 2);
    }

    cout << res << endl;


 
    return 0;
}

Measured memory_bytes: 16640
defmodule Main do
  def main do
    [n, m, l] = IO.gets("") |> String.trim |> String.split
    n = String.to_integer(n)
    m = String.to_integer(m)
    l = String.to_integer(l)
   	a = IO.gets("") |> String.trim |> String.split
    b = Enum.map(a, fn x -> String.to_integer(x) end)
    IO.puts(min(Enum.filter(b, fn x -> x < l end) |> length, Enum.filter(b, fn x -> x > l and l < n end) |> length))
  end
end


Measured memory_bytes: 30840
#include<bits/stdc++.h>
#define rep(i,n) for(int i=0;n>i;++i)
using namespace std;
using ll=long long;
using P=pair<int,int>;
//pとqの最大公約数
int gcd(int p,int q){
    if(p%q==0)
    return q;
    return gcd(q,p%q);
}
int main(){
    ll n,k;
    cin>>n>>k;
    ll ans=n-k*(n/k);
    cout<<min(abs(ans),abs(ans-k))<<endl;
}

Measured memory_bytes: 3608
#include<stdio.h>
#include<stdlib.h>
#include<math.h>
#define rep(i,n) for(i=0;i<n;i++)
#define PI 3.14159265358979323846264338327950L
int main(){
    int n,i,j,num=1;
    scanf("%d",&n);
    int a[n];
    rep(i,n) scanf("%d",&a[i]);
    int all=n;
    rep(i,n){
        if(a[i]==num){
            all--;
            num++;
        }
    }
    if(all==n) printf("-1");
    else printf("%d",all);
    return 0;
}

Measured memory_bytes: 2508
#include<iostream>
using namespace std;
int main(){
    int A,B;
    cin >> A >> B;
    if(A>B){
        cout << A-B << endl;
    }else if(B>A){
        cout << B-A << endl;
    }else if(A==B){
        cout << 0 <<endl;
    }
    return 0;
}


Measured memory_bytes: 3120
n, m = map(int, input().split())
drink = []
for i in range(n):
    a, b = map(int, input().split())
    drink.append([a, b])

money = 0
count = 0

drink.sort()
for i in range(n):
    if m <= drink[i][1]:
        break
    m -= drink[i][1]
    money += drink[i][0] * drink[i][1]
    count += 1

money += drink[count][0] * m
print(money)


Measured memory_bytes: 20048
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <numeric>
#include <queue>
#include <vector>
#include <cmath>
#include <cctype>
#include <cstring>
#include <cstdio>
#include <set>
#include <map>
#include <stack>

using namespace std;

typedef long long LL;
typedef pair<int, int> PII;

#define all(x) (x).begin(), (x).end()
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define repl(i, n) for(LL i = 0; i < (LL)(n); i++)

int main(void){
  int n;
  cin >> n;
  vector<int> h(n);

  rep(i, n) cin >> h[i];
  vector<int> dp(n);

  for (int i = 0; i < n; i++) {
    if (i == 0) dp[i] = 0;
    else if (i == 1) dp[i] = abs(h[i] - h[i-1]);
    else {
      int diff_1 = abs(h[i] - h[i-1]);
      int diff_2 = abs(h[i] - h[i-2]);
      dp[i] = min(diff_1 + dp[i-1], diff_2 + dp[i-2]);
    }
  }

  cout << dp[n-1] << endl;

  return 0;
}

Measured memory_bytes: 1024
#include <iostream>
#include <cstdio>
#include <string>
#include <algorithm>
#include <utility>
#include <cmath>
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <tuple>
#include <numeric>
#include <functional>
using namespace std;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
typedef pair<ll, ll> P;
#define rep(i, n) for(ll i = 0; i < n; i++)
#define exrep(i, a, b) for(ll i = a; i <= b; i++)
#define out(x) cout << x << endl
#define exout(x) printf("%.10f\n", x)
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define pb push_back
#define re0 return 0
const ll mod = 1000000007;
const ll INF = 1e16;
const double pi = acos(-1);

int main() {
    ll a;
    cin >> a;

    ll b = a*a;
    ll c = a*a*a;
    
    out(a + b + c);
    re0;
}

Measured memory_bytes: 3632
#include <bits/stdc++.h>
using namespace std;
int main() {
    char S[3]; cin>>S;
    int count=0;
    for(int i=0;i<3;i++){
        if(S[i]=='o'){
            count++;
        }
    }
    int ans=700+count*100;
    cout<<ans;
    return 0;
}

Measured memory_bytes: 256
SD=gets.strip
T=gets.strip
ans=SD
(0..SD.size-T.size).to_a.reverse.each do |i|
    judge=true
    for j in i...i+T.size
        judge=false if SD[j]!=T[j-i] && SD[j]!="?"
    end
    if judge
        ans[i,T.size]=T
        ans.gsub!("?","a")
        puts ans
        exit 0
    end
end
puts "UNRESTORABLE"


Measured memory_bytes: 1916
import sys
input = sys.stdin.readline
s = int(input())
dp = [0] * (10 ** 6 + 1)
dp[0] = s
x = 0

for i in range(10 ** 6):
  if dp[i] % 2: dp[i + 1] = 3 * dp[i] + 1
  else: dp[i + 1] = dp[i] // 2
  for j in range(i + 1):
    if dp[j] == dp[i + 1]:
      x = i + 2
      break
  if x > 0: break
print(x)

Measured memory_bytes: 46320
#include<iostream>
using namespace std;
int main(){
  int a,b;
  cin >> a >> b;
  
  if(a < b){
    cout << "a < b" << "\n";
  }else if(a > b){
    cout << "a > b" << "\n";
  }else if(a == b){
    cout << "a == b" << "\n";
  }

  return 0;
}



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

int main(){
  int A,B,C, D;
  cin >> A >> B >> C >> D;
  if (A+B > C+D){
    cout << "Left" <<endl;
  }
  else if (A+B == C+D){
    cout << "Balanced" <<endl;
  }
  else {
    cout << "Right" <<endl;
  }
}

  

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

# from numba import njit

# input = stdin.readline

def calcDivision(s):
  res = 0
  prev = ""
  for i in range(len(s)):
    if s[i] == prev:
      pass
    else:
      if prev == "":
        pass
      else:
        res += 1
    prev = s[i]
  return res

# @njit
def solve(s):
  return calcDivision(s)



def main():
  s = input()
  print(solve(s))
  return

if __name__ == '__main__':
  main()


Measured memory_bytes: 9172
#include <iostream>
#include <cmath>

using namespace std;

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

	if (n % 2 == 1) {
		cout << 0 << endl;
		return 0;
	}

	long long ans = 0;
	for(long long i = 5; i <= n; i*=5){
		ans += n / i / 2;
	}
	
	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main() {
	int n, m, sum = 0;
	int p[100], t[10000], x[10000];

	cin >> n;
	for (int i = 0; i < n ; i++) {
		cin >> t[i];
	}
	cin >> m;
	for (int i = 0; i < m ; i++) {
		cin >> p[i] >> x[i];
	}
	for (int i = 0; i < m ; i++) {
		for (int j = 0; j < n; j++) {
			sum += t[j];
		}
		cout << (sum - (t[p[i] - 1] - x[i]) ) << endl;
		sum = 0;
	}
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>

using namespace std;

int main() {
    long long n;    cin >> n;
    char v[] = {'M', 'A', 'R', 'C', 'H'};
    long long cnt[5] = {0};
    for (int i = 0; i < n; i++) {
        string s;   cin >> s;
        for (int j = 0; j < 5; j++) {
            if (s[0] == v[j])
                cnt[j]++;
        }
    }

    long long ans = 0;
    for (int i = 0; i < 5; i++) {
        for (int j = i+1; j < 5; j++) {
            for (int k = j+1; k < 5; k++)
                ans += cnt[i]*cnt[j]*cnt[k];
        }
    }

    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include <cstdio>
#include <functional>
#include <algorithm>
#include <vector>
#include <limits>
#include <numeric>
#include <type_traits>
#include <iostream>
#include <queue>
#include <math.h>
#include <bits/stdc++.h>
#include <queue>
#include <map>

using namespace std;

#define INF (1ll<<60)
#define INFint (1<<30)
#define MOD 1000000007
#define BOUND 27182818284

typedef long long ll;
typedef long long int lli;
typedef pair<int,int> P;

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

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

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

// gcd
template<typename T>
T gcd(T a, T b){
    if(a==0)
        return b;
    return gcd(b%a,a);
}

// gcd array
int findGCD(int arr[], int n){
    int result = arr[0];
    for (int i=1; i < n; i++)
        result = gcd(arr[i], result);
    return result;
}

template<typename T>
T lcm( T m, T n ){
    // 引数に0がある場合は0を返す
    if ( ( 0 == m ) || ( 0 == n ) )
        return 0;
    return ((m/gcd(m, n)) * n); // lcm = m * n / gcd(m,n)
}

template<typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val){
    fill( (T*)array, (T*)(array+N), val );
}


int dx[5]={1,0,-1,0};
int dy[5]={0,1,0,-1};
// v.front() = -BOUND;
// v.back() = BOUND;

int main(){
    ll N,H;
    cin >> N >>H;
    vector<ll>a(N), b(N);
    ll sumthrow=0;
    rep(i,N){
        cin >> a[i] >> b[i];
    }

    sort(a.begin(),a.end(), greater<ll>());
    sort(b.begin(),b.end());
    auto itr=upper_bound(b.begin(),b.end(), a.front());
    for(auto temp=itr; temp<b.end(); temp++){
        sumthrow+=*temp;
    }

    if(H-sumthrow<=0){
        ll sum=0;
        ll trial=0;
        reverse(b.begin(), b.end());
        auto itr_b=b.begin();
        while(H>sum && itr_b!=b.end()){
            sum+=*itr_b;
            trial++;
            itr_b++;
        }
        cout << trial << endl;
    }else{
        if( (H-sumthrow)% a[0]==0){
            cout << b.end()-itr +(H-sumthrow)/a[0] << endl;
        }else{
            cout << b.end()-itr +(H-sumthrow)/a[0]+1 << endl;
        }
    }

    return 0;
}



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

int main(){
	cin.tie(0);
   	ios::sync_with_stdio(false);
	ll N,K;
	cin>>N>>K;
	vector<ll> A(N);
	ll a;
	rep(i,N){
		cin>>a;
		--a;
		A[i] = a;
	}
	vector<ll> d(N);
	rep(i,N){
		d[i]= -1;
	}
	d[0] = 0;
	ll p = 0;
	ll next_p;
	ll itr = 0;
	ll c;
	ll flag = true;
	if(A[0]==0){
		goto fin;
	}

	while(K>itr){
		next_p = A[p];
		// cout<<next_p<<"\n";
		++itr;
		if(d[next_p]==-1 || flag == false){
			p = next_p;
			d[next_p] = itr;
		}else{
			// cout<<next_p<<"\n";
			flag = false;
			c = itr-d[next_p];
			K = (K-itr)%c + itr;
			if(K==0){
				break;
			}
			p = next_p;
		}
	}
	fin:
	cout<<p+1<<"\n";
	return 0;
}


Measured memory_bytes: 6372
T=int(input())
a,b=map(int,input().split())
ll=list(map(int,input().split()))
mins=0
for i in range(len(ll)):
    ans=a-0.006*ll[i]
    if abs(ans-b)<abs((a-0.006*ll[mins])-b):
        mins=i

print(mins+1)

Measured memory_bytes: 3060
#pragma comment(linker, ¡°/STACK:1024000000,1024000000¡±)
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<iostream>
#include<string>
#include<vector>
#include<stack>
#include<bitset>
#include<cstdlib>
#include<cmath>
#include<set>
#include<list>
#include<deque>
#include<map>
#include<queue>
using namespace std;
typedef long long ll;
const double PI = acos(-1.0);
const double eps = 1e-6;
const int INF = 0x3f3f3f3f;

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

const int MAXN = 1e2+10;
ll D,G,p[MAXN],c[MAXN];

int main(){
	scanf("%lld %lld",&D,&G);
	for(int i=0;i<D;i++){
		scanf("%lld %lld",&p[i],&c[i]);
	}
	ll ans = INF;
	for(int mask =0;mask<(1<<D);mask++){
		ll s = 0,num = 0,rest_max = -1;
		for(int i=0;i<D;i++){
			if(mask >> i & 1){
                s += 100 * (i+1) * p[i] + c[i];
                num += p[i];
            }else{
                rest_max = i;
            }
		}
		if(s < G){
            int s1 = 100 * (rest_max + 1);
            int need = (G - s + s1 - 1) / s1;
            if(need >= p[rest_max]){
                continue;
            }
            num += need;
        }
        ans = min(ans, num);
	}
	printf("%lld\n",ans);
	
	return 0;
}


Measured memory_bytes: 256
#include <stdio.h>

int main(void) {
	char w[120];
	int judge = 0;
	int cnt = 0;
	scanf("%s", w);
	for (int j = 0; w[j] != '\0'; j++) {
		for (int i = 0; w[i] != '\0'; i++) {
			if (w[j] == w[i]) {
				cnt++;
			}
		}
		if (cnt % 2) {
			judge = 1;
			break;
		}
		cnt = 0;

	}
	judge == 1 ? printf("No") : printf("Yes");
	return 0;
}

Measured memory_bytes: 2104
#include <stdio.h>
int main() {
    for(int x=0;x<1000;x++){
	int a = 0;
	scanf("%d", &a);
	int g[1000] = {};
	for (int i = 0; i < a; i++) {
		scanf("%d", &g[i]);
	}
	int sd = 0;
	int ss = 0;

	sd = g[1];
	ss = g[1];
	for (int i = 0; i < a; i++) {
		if (g[i] > sd) {
			sd = g[i];
		}
		if (g[i] < ss) {
			ss = g[i];
		}
	}
	int g1 = 0;
	for (int i = 0; i < a; i++) {
		g1 = g1 + g[i];
	}
	int g2 = 0;
	g2 = g1 - sd - ss;
	a = a - 2;
	g2 = g2 / a;
	if(g2==0){
	    
	}else {
	printf("%d\n", g2);
	}
}
return 0;
}


Measured memory_bytes: 2548
local read = setmetatable({}, {__index = function(t, k) local a = {} for i=1,#k do table.insert(a, '*'..string.sub(k, i, i)) end local r = io.read local u = table.unpack or unpack return function() return r(u(a)) end end})
read.N = function(N) local t={} for i=1,N do t[i]=read.n() end return t end
string.totable = function(s) local t={} local u=string.sub for i=1,#s do t[i] = u(s, i, i) end return t end
string.split = function(s) local t={} for w in string.gmatch(s, "[^%s]+") do table.insert(t, w) end return (table.unpack or unpack)(t) end
----
-- B
local S = read.l()
print(("x"):rep(#S))

Measured memory_bytes: 760
#include <bits/stdc++.h>
#define MOD 1000000007
#define INF 1000000000
#define LINF 1000000000000000000
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define bit(n) (1LL<<(n))
using namespace std;

typedef pair<int, int> P;
typedef pair<long long, long long> LLP;

/*
  階乗計算（MODで割った余りで返す）
*/

class Factorial {
    private:
        vector<long long> fac;
    public:
        Factorial();
        Factorial(long long n_max);
        void initialization(long long n_max);
        long long getFactorial(long long n);
};

Factorial::Factorial() {}
Factorial::Factorial(long long n_max) {
    fac.clear();
    fac.push_back(1);
    fac.push_back(1);
    for (long long i = 2; i <= n_max; i++) {
        fac.push_back(fac[i-1] * i % MOD);
    }
}
void Factorial::initialization(long long n_max) {
    fac.clear();
    fac.push_back(1);
    fac.push_back(1);
    for (long long i = 2; i <= n_max; i++) {
        fac.push_back(fac[i-1] * i % MOD);
    }
}
long long Factorial::getFactorial(long long n) {
    return fac[n];
}

/*
  MOD計算
*/
// 割り算のための逆元を求める（mod m での a の逆元）
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 % m;
}

/*
    順列と組み合わせ (P, C, H)
*/

class PCH {
    private:
        Factorial fact;
    
    public:
        PCH(long long n_max);
        long long P(long long n, long long r);
        long long C(long long n, long long r);
        long long H(long long n, long long r);
};
PCH::PCH(long long n_max) {
    fact.initialization(n_max);
}
long long PCH::P(long long n, long long r) {
    return fact.getFactorial(n) % MOD * modinv(fact.getFactorial(r), MOD) % MOD;
}

long long PCH::C(long long n, long long r) {
    return fact.getFactorial(n) % MOD * modinv(fact.getFactorial(r), MOD) % MOD * modinv(fact.getFactorial(n - r), MOD) % MOD;
}

long long PCH::H(long long n, long long r) {
    return C(n - 1 + r, r);
}

int main() {

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

    long long ans = 0;
    PCH pch(n);

    for (int i = 0; i <= min(k, n - 1); i++) ans = (ans + pch.C(n, i) * pch.H(n - i, i) % MOD) % MOD;

    cout << ans << endl;
    
    return 0;
}

Measured memory_bytes: 2420
#include <stdio.h>

int main(void)
{
    int W, H, x, y, r;
    scanf("%d %d %d %d %d", &W, &H, &x, &y, &r);
    
    if (x >= -100 && x <= 100 &&
        y >= -100 && y <= 100 &&
        W >= 0 && W <= 100 &&
        H >= 0 && H <= 100 &&
        r >= 0 && r <= 100) {
        if (x - r >= 0 && x + r <= W && y - r >= 0 && y + r <= H) {
            printf("Yes\n");
        } else {
            printf("No\n");
        }
    }

    return 0;
}

Measured memory_bytes: 584
#include<bits/stdc++.h>
using namespace std;
#define ll long long 
// memo  fixed  setprecision(20);
using vvll = vector<vector<ll>>;
ll mod =1000000007;
/*"itob" int to "N"base */           template<typename TypeInt> string itob(const TypeInt v, int base){static const char table[] = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ";string ret;static numeric_limits<TypeInt> t;TypeInt n = v;if (t.is_signed) {if (v < 0) n *= -1;}while (n >= base) {ret += table[n%base];n /= base;}ret += table[n];if (t.is_signed) {if (v < 0 && base == 10) ret += '-';}reverse(ret.begin(), ret.end());return ret;}
/*"chmin" a = MAX*/                  template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
/*"chmax" a = MIN*/                  template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
/*"ctoi"  char to int*/              int ctoi(char c) {return c-'0';}
/*"gcd"   MAX*/                      int gcd(ll a,ll b){return b?gcd(b,a%b):a;}
/*"lcm"   MIN*/                      int lcm(ll a,ll b){return a*b/gcd(a,b);}
/*"primecheck"If prime,return true.*/bool primecheck(ll n){if(n < 2) return false;else{for(int i = 2; i * i <= n; i++){if(n % i == 0) return false;}return true;}}
string  reverserange(string s,ll a,ll b){reverse(s.begin()+a-1,s.begin()+b); return s;}

int main(){
    int n,m;
    cin >> n >> m;
    ll ans = m*1900+(n-m)*100;
    ans*=pow(2,m);
    cout << ans << endl;
}



Measured memory_bytes: 256
import java.util.Scanner;
import java.util.Stack;

public class Main {
	public static void main(String[] args) {
		try (Scanner scan = new Scanner(System.in)) {
			int n = scan.nextInt();
			int[][] map = new int[n][n];
			int[] state = new int[n];
			int[] discovery = new int[n];
			int[] finish = new int[n];
			for(int i=0; i<n; i++) {
				int from = scan.nextInt()-1;
				int m = scan.nextInt();
				for(int j=0; j<m; j++) {
					int to = scan.nextInt()-1;
					map[from][to] = 1;
				}
			}
			
			int time = 0;
			for(int i=0; i<n; i++) {
				if(state[i] >= 1) continue;
				time++;
				Stack<Integer> stack = new Stack<>();
				stack.push(i);
				state[i] = 1;
				discovery[i] = time;
			
				while(!stack.isEmpty()) {
					int now = stack.peek();
					time++;
					boolean findConnect = false;
					for(int j=0; j<n; j++) {
						if(now == j) continue;
						if(map[now][j] == 1 && state[j] == 0) {
							stack.push(j);
							state[j] = 1;
							discovery[j] = time;
							findConnect = true;
							break;
						}
					}
					if(!findConnect) {
						stack.pop();
						state[now] = 2;
						finish[now] = time;
					}
				}
			}
			for(int i=0; i<n; i++) {
				System.out.println((i+1) + " " + discovery[i] + " " + finish[i]);
			}
		}
	}
}



Measured memory_bytes: 28180
#include <bits/stdc++.h>
#define rep(i, n) for (int i=0; i<(int)(n); i++)
#define all(v) v.begin(), v.end()
#define PRINT(v) for (auto x : (V)) cout <<x <<" " <<endl;
using namespace std;
using ll = long long;
using Graph = vector<vector<int>>;
const ll MOD = 1000000007;
const ll INF = 10000000000000000;
vector<int> x4 = {0, 1, 0, -1}, x8 = {0, 1, 1, 1, 0, -1, -1, -1};
vector<int> y4 = {1, 0, -1, 0}, y8 = {1, 1, 0, -1, -1, -1, 0, 1};
template<class T> struct edge { int from, to; T cost;};
template<class T> inline bool chmin(T& a, T b){if (a>b){a = b; return true;}return false;}
template<class T> inline bool chmax(T& a, T b){if (a<b){a = b; return true;}return false;}
template<class T> inline T powerM(T a,T b){if (b==0) return 1;
T tmp = powerM(a,b/2); if (b%2==0) return tmp*tmp%MOD; else return tmp*tmp%MOD*a%MOD; }
template<class T> inline T power(T a,T b,T m){ if (b==0) return 1;
  T tmp = power(a,b/2,m); if (b%2==0) return tmp*tmp%m; else return tmp*tmp%m*a%m; }
template<class T> inline T gcd(T a, T b){if (b==0) return a; return gcd(b, a%b);}
template<class T> inline T lcm(T a, T b){return a / gcd(a,b) * b;}
// ax+by=gcd(a,b)を解く
template<class T> inline T extgcd(T a,T b,T &x,T &y){if (b==0){x=1; y=0; return a;} T d=extgcd(b,a%b,y,x); y -= a/b*x; return d;}
void hey(){ cout <<"hey" <<endl; }


int N, M;
Graph G;

void input() {
  cin >>N >>M;
  G.assign(N, vector<int>());
  rep(i, M){
    int a,b; cin >>a >>b; a--; b--;
    G[a].push_back(b);
    G[b].push_back(a);
  }
}

void dfs(int v, vector<bool> &seen, int a, int b){
  for (int nv : G[v]){
    if (seen[nv]) continue;
    if (v == a && nv == b) continue;
    if (v == b && nv == a) continue;
    seen[nv] = true;
    dfs(nv, seen, a, b);
  }
}

int main() {
  input();
  int res = 0;
  vector<bool> seen;
  rep(a, N){ for(int b : G[a]){
    seen.assign(N, false);
    seen[0] = true;
    dfs(0, seen, a, b);
    rep(i, N){
      if (!seen[i]){
        res++; break;
      }
    }
  }}

  res /= 2;
  cout <<res <<endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int maxN = 200 + 9;
const int INF = 1e9;
const double EPS = 1e-9;

int n;
ll a[2][maxN], memo[2][maxN];

void read(){
  cin >> n;
  for(int i = 0; i < 2; i++)
    for(int j = 0; j < n; j++)
      cin >> a[i][j];
}

int dr[4] = {0, 1};
int dc[4] = {1, 0};

bool inside(int i, int j){
  return (0 <= i) && (i < 2) && (0 <= j) && (j < n);
}

ll dp(int i, int j){
  //cerr << i << ' ' << j << '\n';
  if(i == 1 && j == n - 1)
    return a[i][j];

  if(memo[i][j] != -1)
    return memo[i][j];

  ll ans = 0;
  for(int k = 0; k < 2; k++){
    int nxi = i + dr[k];
    int nxj = j + dc[k];
    if(inside(nxi, nxj)){
      ans = max(ans, dp(nxi, nxj));
    }
  }

  return (memo[i][j] = ans + a[i][j]);
}

void solv(){
  for(int i = 0; i < 2; i++)
    fill_n(memo[i], maxN, -1);

  cout << dp(0, 0) << '\n';
}

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

  #ifdef DEBUG
    freopen("in.txt", "r", stdin);
  #endif

  read();
  solv();

  return 0;
}


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

ans = []
maxim = A[0]
for i in range(1,n):
    if A[i] < maxim:
        ans.append(maxim-A[i])
    else:
        ans.append(0)
        maxim = A[i]
print(sum(ans))

Measured memory_bytes: 106812
#include <iostream>
#include <cstdlib>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <set>
#include <cstring>
#include <cmath>


#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define REP(i, k, n) for (int i = (int)(k); i < (int)(n); i++)
#define rrep(i, n) for (int i = (int)(n) - 1; i >= 0; i--)
#define rREP(i, k, n) for (int i = (int)(n) - 1; i >= k; i--)

#define debug(x) cerr <<#x << ": " << x << endl;

#define fi first
#define se second

#define vi vector<int>
#define pb push_back
#define mp make_pair

#define pcnt __builtin_popcount

typedef long long ll;
const ll inf = 900900900100100100;
const int MOD = (int)1e9 + 7;
const double EPS = 1e-9;
const int MID = 255;
using namespace std;


const int MAX_N = 1000000;
int prime[MAX_N + 10];
bool is_prime[MAX_N + 10];
int sieve(int n){
    int p = 0;
    rep(i,n + 1) is_prime[i] = true;
    is_prime[0] = is_prime[1] = false;
    REP(i,2,n + 1){
        if(is_prime[i]) {
            prime[p++] = i;
            for(int j = 2 * i; j <= n; j += i)
                is_prime[j] = false;
        }
    }
    return p;
}

int main(){
    int N,P;
    while(cin >> N >> P,N != -1) {
        int p = sieve(MAX_N);
        int k = 0;
        vector<int> pp;
        rep(i,p){
            if(prime[i] <= N) continue;
            int l = 0;
            REP(j,i,p){
                pp.pb(prime[i] + prime[j]);
                l++;
                if(l > P) break;
            }
            k++;
            if(k > P) break;
        }
        sort(pp.begin(),pp.end());
        // rep(i,P) debug(pp[i]);
        cout << pp[P - 1] << endl;
    }


    return 0;
}



Measured memory_bytes: 4444
import java.io.IOException;
import java.io.InputStream;
import java.util.ArrayDeque;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Deque;
import java.util.List;
import java.util.NoSuchElementException;
import java.util.PriorityQueue;
import java.util.Queue;
import java.util.Scanner;
 
 
public class Main {
	
	public static void main(String[] args) {
		// TODO Auto-generated method stub
		
		Scanner sc = new Scanner(System.in);
		
		
		//int N = Integer.parseInt(sc.next());
		//int Q = Integer.parseInt(sc.next());
		//long L = Long.parseLong(sc.next());
		char[] c = sc.next().toCharArray();
		int count = c.length;
		int win = 0;
		for(char c_ : c){
			if (c_=='o')win++;
		}
		if(15-count >= 8-win){
			System.out.println("YES");
		}else{
			System.out.println("NO");
		}
		
		//System.out.println(ans);
		
		
		
	}
	
}



Measured memory_bytes: 21460
/* Coached by rainboy */
#include <math.h>
#include <stdio.h>

double PI;

void init() {
	PI = acos(-1);
}

int main() {
	double a, b, x, h;

	init();
	scanf("%lf%lf%lf", &a, &b, &x);
	x /= a;
	if (x <= a * b / 2) {
		h = x * 2 / b;
		printf("%.10f\n", 90 - atan(h / b) * 180 / PI);
	} else {
		h = (a * b - x) * 2 / a;
		printf("%.10f\n", atan(h / a) * 180 / PI);
	}
	return 0;
}


Measured memory_bytes: 256
# 高橋くんは、自動販売機でジュースを買ったときの音が好きです。
# その音は 1 回 A 円で聞くことができます。
# 高橋くんは B 円持っていますが、お気に入りの音を C 回聞くと満足するため、
# B 円で最大 C 回まで聞けるだけ聞きます。
# 高橋くんはお気に入りの音を何回聞くことになるでしょうか。

input = gets.chomp.split
a = input[0].to_i
b = input[1].to_i
c = input[2].to_i

if b / a > c
  puts c
else
  puts b / a
end


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

// GNU C Compiler
//template<class T> inline string toString(T x) { ostringstream sout; sout << x; return sout.str(); }

// type
using ll = int_fast64_t;
using ull = uint_fast64_t;
using LL = long long;
using ULL = unsigned long long;
using PII = pair<int, int>;
//using pair<T1, T2> = p12;

//container
#define PB emplace_back
#define MP make_pair 
#define SZ(a) int((a).size())
#define ALL(v) v.begin(),v.end()

//repetition
#define REP(n) for(ll i=0; i<(n); i++)
#define REPj(n) for(ll j=0; j<(n); j++)
#define REPinit(i,a,n) for(ll i=(a); i<(n); i++)
#define REPinitj(j,a,n) for(ll j=(a); j<(n); j++)

//algorithm
#define SORT(c) sort((c).begin(),(c).end())
#define CONTAINER_ALL(a) a.begin(),a.end()

//constant

//clear memory
#define CLR(a) memset((a), 0 ,sizeof(a))

//Optimizer
// #pragma GCC optimize("Ofast")
// #pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")

std::string repeatStr(int N, const char* c) {
    std::ostringstream os;
    REPinit(i, 0, N) os << c;
    return os.str();
}


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

    int D;
    cin >> D;

    std::ostringstream os;
    
    cout << ("Christmas" + repeatStr(25 - D, " Eve")) << endl;
    
    return 0;
}


Measured memory_bytes: 3568
#include <bits/stdc++.h>
using namespace std;
 
#define FOR(i, x, n) for(ll i = x; i < n; i++) 
#define pb push_back
#define pf push_front
#define ll long long
#define hii cout << "hii" << endl
#define pii pair<int, int>
#define pll pair<ll, ll>
#define int ll
#define mpp make_pair
#define endl '\n'
#define ff first 
#define ss second
#define vi vector<int>
#define all(s) s.begin(), s.end()
#define si size()

const int N = 1e5 + 5;
double arr[N];

int solve()
{
	int n, m;
	cin >> n >> m;
	priority_queue<long double> pq;
	for(int i = 0; i < n; i++)
	{
		cin >> arr[i];
		pq.push(arr[i]);
	}
	while(m--)
	{
		int curr = pq.top();
		// cout << curr << endl;
		pq.pop();
		curr = curr / 2.0;
		pq.push(curr);
	}
	int cnt = 0;
	while(pq.size())
	{
		cnt += lround(pq.top());
		pq.pop();
	}
	cout << cnt << endl;
}

int32_t main()
{
	ios_base:: sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	// #ifndef ONLINE_JUDGE
 //    freopen("input.txt", "r", stdin);
 //    freopen("output.txt", "w", stdout);
	// #endif
	solve();
	return 0;
}          

Measured memory_bytes: 2932
n = int(input())
alist = [int(a) for a in input().split()]
#print(alist)
def div2(b):
  return b//2
count = 0

f = 0
while(1):
  for i in alist:
    if i % 2 == 1:
      f = 1
  if f == 0:
    alist = list(map(div2,alist))
    count+=1
  else:
    break
  
print(count)

Measured memory_bytes: 3060
#include<stdio.h>
#define MAX 1000

typedef struct{
  int p;
  int l;
  int r;
}Binary;

Binary tree[MAX];

void print(int);

int getheight(int i){
  int x=0,y=0;
  if(tree[i].l!=-1)
    x=getheight(tree[i].l)+1;
  if(tree[i].r!=-1)
    y=getheight(tree[i].r)+1;
  if(x>y)
    return x;
  else
    return y;
}

int getdepth(int i){
  int d=0;
  while(tree[i].p>=0){
    i=tree[i].p;
    d++;
  }
  return d;
}

int getsibling(int i){
  if(tree[i].p==-1)
    return -1;
  else if(tree[tree[i].p].r==i)
    return tree[tree[i].p].l;
  else
    return tree[tree[i].p].r;
}

int getdeg(int i){
  int d=0;
  if(tree[i].l!=-1)
    d++;
  if(tree[i].r!=-1)
    d++;
  return d;
}

int main(){
  int i,n,k;
  int id;

  scanf("%d",&n);
  for(i=0;i<n;i++){
    tree[i].l=tree[i].r=tree[i].p=-1;
  }
  for(i=0;i<n;i++){
    scanf("%d",&id);
    scanf("%d%d",&tree[id].l,&tree[id].r);
    if(tree[id].l!=-1)
      tree[tree[id].l].p=id;
    if(tree[id].r!=-1)
      tree[tree[id].r].p=id;
  }

  for(i=0;i<n;i++){
    print(i);
  }
  return 0;
}

void print(int i){
    int h=getheight(i);
    int dep=getdepth(i);

    printf("node %d: parent = %d, sibling = %d, degree = %d, ",i,tree[i].p,getsibling(i\
),getdeg(i));

    printf("depth = %d, height = %d, ",dep,h);
    if(dep==0)
      printf("root\n");
    else if(h==0)
      printf("leaf\n");
    else
      printf("internal node\n");
}

Measured memory_bytes: 612
n,m  = map(int,input().split())

coins = list(map(int,input().split()))

dp = [20**10]*(n+1)
dp[0] = 0
for coin in coins:
    for price in range(coin,n+1):
        dp[price]  = min(dp[price],dp[price-coin]+1)
        
print(dp[n])


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

using namespace std;

int main()
{
  int n, d, x;
  cin >> n >> d >> x;
  int p[10][10];
  for(int i = 0; i < d; i++){
    for(int j = 0; j < n; j++) cin >> p[i][j];
  }
  int dp[100001];
  for(int i = 0; i < d-1; i++){
    fill(dp, dp + 100001, 0);
    for(int j = 0; j <= x; j++) dp[j] = j;
    for(int j = 0; j < n; j++){
      for(int k = 0; k <= x; k++){
	if(k - p[i][j] >= 0) dp[k] = max(dp[k], dp[k-p[i][j]] + p[i+1][j]);
      }
    }
    int y = 0;
    for(int j = 0; j <= x; j++) y = max(y, dp[j]);
    x = y;
  }
  cout << x << endl;
  return 0;
}

Measured memory_bytes: 1552
#include <bits/stdc++.h>
using namespace std;
using pint = pair<int,int>;

const long long INFLL = 1LL << 60;
const int INFI = 1000000000;


int main(){
    int N;cin >> N;
    vector<long long> a(N+1);
    vector<long long> b(N);
    for(int i=0;i<N+1;i++) cin >> a[i];
    for(int i=0;i<N;i++) cin >> b[i];
    long long ans =0;

    long long m = min(a[0],b[0]);
    a[0] -= m; b[0] -= m; ans+=m;
    //cout << m << endl;
    for(int i=1;i<N;i++){
        m = min(a[i],b[i-1]);
        //cout << m << endl;
        a[i]-=m; ans+=m;
        m = min(a[i], b[i]);
        //cout << m << endl;
        a[i]-=m; b[i]-=m; ans+=m;
    }
    m = min(a[N],b[N-1]); ans+=m;

    cout << ans << endl;

}




Measured memory_bytes: 1792
// practice with kaiboy
import java.io.*;
import java.util.*;

public class Main extends PrintWriter {
	Main() { super(System.out); }
	Scanner sc = new Scanner(System.in);
	public static void main(String[] $) {
		Main o = new Main(); o.main(); o.flush();
	}

	static final long INF = 0x3f3f3f3f3f3f3f3fL;
	static final int A = 50;
	int[] oo; int[][] oh;
	void link(int i, int h) {
		int o = oo[i];
		if (o >= 2 && (o & o - 1) == 0)
			oh[i] = Arrays.copyOf(oh[i], o << 1);
		oh[i][oo[i]++] = h;
	}
	int[] aa, bb, ij;
	void init(int n, int m) {
		oo = new int[n]; oh = new int[n][2];
		aa = new int[m + n]; bb = new int[m + n]; ij = new int[m + n];
	}
	long[] dd; int[] pq, iq; int cnt;
	boolean lt(int i, int j) {
		return dd[i] < dd[j];
	}
	int p2(int p) {
		return (p *= 2) > cnt ? 0 : p < cnt && lt(iq[p + 1], iq[p]) ? p + 1 : p;
	}
	void pq_up(int i) {
		int j, p, q;
		for (p = pq[i]; (q = p / 2) > 0 && lt(i, j = iq[q]); p = q)
			iq[pq[j] = p] = j;
		iq[pq[i] = p] = i;
	}
	void pq_dn(int i) {
		int j, p, q;
		for (p = pq[i]; (q = p2(p)) > 0 && lt(j = iq[q], i); p = q)
			iq[pq[j] = p] = j;
		iq[pq[i] = p] = i;
	}
	void pq_add_last(int i) {
		iq[pq[i] = ++cnt] = i;
	}
	int pq_remove_first() {
		int i = iq[1], j = iq[cnt--];
		if (j != i) {
			pq[j] = 1; pq_dn(j);
		}
		pq[i] = 0;
		return i;
	}
	void main() {
		int n = sc.nextInt();
		int m = sc.nextInt();
		int s = sc.nextInt();
		init(n, m);
		for (int h = 0; h < m; h++) {
			int i = sc.nextInt() - 1;
			int j = sc.nextInt() - 1;
			aa[h] = -sc.nextInt();
			bb[h] = sc.nextInt();
			ij[h] = i ^ j;
			link(i, h);
			link(j, h);
		}
		for (int h = m, i = 0; i < n; h++, i++) {
			aa[h] = sc.nextInt();
			bb[h] = sc.nextInt();
			link(i, h);
		}
		int md = n * A + 1;
		s = Math.min(s, md - 1);
		pq = new int[n * md]; iq = new int[1 + n * md];
		dd = new long[n * md]; Arrays.fill(dd, INF);
		dd[s] = 0; pq_add_last(s);
		while (cnt > 0) {
			int u = pq_remove_first(), i = u / md; s = u % md;
			for (int o = 0; o < oo[i]; o++) {
				int h = oh[i][o], j = i ^ ij[h], t = s + aa[h];
				if (t < 0)
					continue;
				t = Math.min(t, md - 1);
				int v = j * md + t;
				long d = dd[u] + bb[h];
				if (dd[v] > d) {
					if (dd[v] == INF)
						pq_add_last(v);
					dd[v] = d; pq_up(v);
				}
			}
		}
		for (int i = 1; i < n; i++) {
			long d = INF;
			for (s = 0; s < md; s++) {
				int u = i * md + s;
				d = Math.min(d, dd[u]);
			}
			println(d);
		}
	}
}


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

using namespace std;

typedef long long ll;

const int xx[]={1, 0, -1, 0}, yy[]={0, 1, 0, -1};

int n;
int arrX[250002], arrY[250002];
int DP[502][502];
int ans;

bool chk[502][502];
bool chk2[502][502];
queue<pair<int, int> > que;

int main(){
    scanf("%d", &n);
    for(int i=1; i<=n*n; i++){
        int tmp;
        scanf("%d", &tmp);
        arrX[i] = (tmp + n - 1) / n;
        arrY[i] = (tmp - 1) % n + 1;
    }

    for(int i=1; i<=n; i++){
        for(int j=1; j<=n; j++){
            chk[i][j] = 1;
            DP[i][j] = min({i, j, n-i+1, n-j+1});
        }
    }

    for(int tc=1; tc<=n*n; tc++){
//        printf("turn %d\n", tc);
        int tx = arrX[tc], ty = arrY[tc];
        ans += DP[tx][ty] - 1;
//        printf("DP is %d\n", DP[tx][ty]);
        chk[tx][ty] = 0;
        chk2[tx][ty] = 1;

        que.push(make_pair(tx, ty));
        while(!que.empty()){
            pair<int, int> tmp = que.front(); que.pop();
            tx = tmp.first, ty = tmp.second;
//            printf("now: %d %d\n", tx, ty);
            DP[tx][ty]--;
            chk2[tx][ty] = 0;

            for(int d=0; d<4; d++){
                int ttx = tx + xx[d], tty = ty + yy[d];
                if(chk2[ttx][tty] || ttx<1 || ttx>n || tty<1 || tty>n ||
                   DP[ttx][tty] - chk[ttx][tty] != DP[tx][ty] + 1) continue;
                que.push(make_pair(ttx, tty));
                chk2[ttx][tty] = 1;
            }
        }

//        for(int i=1; i<=n; i++){
//            for(int j=1; j<=n; j++){
//                printf("%d ", DP[i][j]);
//            }
//            puts("");
//        }
    }

    printf("%d", ans);
}


Measured memory_bytes: 7176
import sys
input = sys.stdin.readline
sys.setrecursionlimit(100000)

tree = {}
N = 0

def assign(assignment, u, prev_color):
    color = 1
    for v in tree[u]:
        if color == prev_color:
            color += 1
        assignment[u,v] = color
        assign(assignment, v, color)
        color += 1

def main():
    global tree, N
    N = int(input())
    tree = {i: [] for i in range(1,N+1)}
    edges = []
    for _ in range(N-1):
        a, b = map(int, input().split())
        tree[a].append(b)
        edges.append((a, b))
    ans = {}
    assign(ans, 1, None)
    print(max(ans.values()))
    for edge in edges:
        print(ans[edge])

if __name__ == "__main__":
    main()

Measured memory_bytes: 83556
#include <bits/stdc++.h>
using namespace std;
template<typename T> inline bool chmax(T& a,T b) { if (a < b) { a = b; return true; } return false; }
template<typename T> inline bool chmin(T& a,T b) { if (a > b) { a = b; return true; } return false; }

template<int mod> struct ModInt {
    int x;
    ModInt() : x(0) {}
    ModInt(long long y) : x(y >= 0 ? y % mod : (mod - (-y) % mod) % mod) {}
    ModInt &operator+=(const ModInt &p) { if((x += p.x) >= mod) x -= mod; return *this; }
    ModInt &operator-=(const ModInt &p) { if((x += mod-p.x) >= mod) x -= mod; return *this; }
    ModInt &operator*=(const ModInt &p) { x = (int)(1LL*x*p.x%mod); return *this; }
    ModInt &operator/=(const ModInt &p) { *this *= p.inverse(); return *this; }
    ModInt operator-() const { return ModInt(-x); }
    ModInt operator+(const ModInt &p) const { return ModInt(*this) += p; }
    ModInt operator-(const ModInt &p) const { return ModInt(*this) -= p; }
    ModInt operator*(const ModInt &p) const { return ModInt(*this) *= p; }
    ModInt operator/(const ModInt &p) const { return ModInt(*this) /= p; }
    bool operator==(const ModInt &p) const { return x == p.x; }
    bool operator!=(const ModInt &p) const { return x != p.x; }
    ModInt inverse() const {
        int a = x, b = mod, u = 1, v = 0, t;
        while(b > 0) { t = a / b; a -= t * b; swap(a, b); u -= t * v; swap(u, v); }
        return ModInt(u);
    }
    ModInt pow(int e){
        long long a = 1, p = x;
        while(e > 0) {
            if(e%2 == 0) {p = (p*p) % mod; e /= 2;}
            else {a = (a*p) % mod; e--;}
        }
        return ModInt(a);
    }
    friend ostream &operator<<(ostream &os, const ModInt<mod> &p) {
        return os << p.x;
    }
    friend istream &operator>>(istream &is, ModInt<mod> &a) {
        long long x;
        is >> x;
        a = ModInt<mod>(x);
        return (is);
    }
};

constexpr int MOD = 1e9+7;

int main() {
    int n, k;
    cin >> n >> k;
    
    vector<long long> val(n + 1, 0);
    for (long long i = 1; i <= n; i++) val[i] = val[i - 1] + i;
    
    ModInt<MOD> ans = 1;
    for (int i = k; i <= n; i++) {
        long long a = val[i - 1]; // 上位 i 個の下限
        long long b = val[n] - val[n - i]; // 上限
        ans += ((b - a + 1) % MOD);
    }
    
    cout << ans << '\n';
    return 0;
}

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

long long gcd(long long A, long long B)
{
    if (B == 0)
    {
        return A;
    }
    else
    {
        return gcd(B, A % B);
    }
}

void solve(long long A, long long B)
{
    const long long GCD = gcd(A, B);

    long long rem = GCD, num_prime = 0;
    for (long long i = 2; i * i <= rem; i++)
    {
        if (rem % i != 0)
        {
            continue;
        }
        else
        {
            while (rem % i == 0)
            {
                rem /= i;
            }
            num_prime++;
        }
    }
    cout << (rem == 1 ? (num_prime + 1) : (num_prime + 2)) << endl;
}

// Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
int main()
{
    long long A;
    scanf("%lld", &A);
    long long B;
    scanf("%lld", &B);
    solve(A, B);
    return 0;
}


Measured memory_bytes: 256
import sys
def input():
	return sys.stdin.readline()

N, Q = map(int, input().split())
S = input()
p = []
for _ in range(Q):
	p.append(tuple([int(_)-1 for _ in input().split()]))

L = [0] * N
l = 0

for i in range(N-1):
	if S[i] == 'A' and S[i+1] == 'C':
		l += 1
	L[i] = l

for i in range(Q):
	print(L[p[i][1]-1] - L[p[i][0]-1])

Measured memory_bytes: 19980
#include <stdio.h>
#include <string>
#include <cstring>
#include <stdlib.h>
#include <math.h>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <list>
#include <iterator>
#include <assert.h>
#pragma warning(disable:4996) 

typedef long long ll;
#define MIN(a, b) ((a)>(b)? (b): (a))
#define MAX(a, b) ((a)<(b)? (b): (a))
#define LINF 9223300000000000000
#define INF 2140000000
const long long MOD = 1000000007;
using namespace std;


char str[3005];
ll dp[3005][3005];
ll sdp[3005][3005];

int main(int argc, char* argv[])
{
    int n;
    scanf("%d", &n);
    scanf("%s", str);

    dp[0][0]=1;
    sdp[0][1]=1;
    int i, j;
    for(i=1; i<n; i++) {
        for(j=0; j<=i; j++) {
            if(str[i-1]=='<') {
                dp[i][j] = (dp[i][j] + sdp[i-1][j])%MOD;
            }
            else {
                dp[i][j] = (dp[i][j] + sdp[i-1][i] - sdp[i-1][j] +MOD)%MOD;
            }
            sdp[i][j+1]=(sdp[i][j]+dp[i][j])%MOD;
        }
    }
    printf("%lld\n", sdp[n-1][n]);

    return 0;
}


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

using namespace std;

#define rep(i, n) for(int i = 0; i < (n); ++i)
#define eee(a) (cerr << (#a) << ": " << (a) << endl);
#define ppp(a) (cout << (a) << endl);
#define cop(a) for(auto x:(a)){cout << x << endl;}


using ll = long long;
using pint = pair<int, int>;
using pll = pair<ll, ll>;
using mint = map<int, int>;

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

constexpr char sp = ' ';
constexpr char cmm = ',';
constexpr int MOD = 1e9+7;
constexpr int INF = 1e9;
constexpr ll LINF = 1e18;

ll mod(ll a, ll b){return (a%b+b)%b;}
ll gcd(ll a, ll b){return b?gcd(b,a%b):a;}
ll lcm(ll a, ll b){return a*b/gcd(a,b);}
void Yes(){cout << "Yes" << endl;}
void No(){cout << "No" << endl;}
void Judge(bool b){b?Yes():No();}
void YES(){cout << "YES" << endl;}
void NO(){cout << "NO" << endl;}
void JUDGE(bool b){b?YES():NO();}
ll powmod(ll b, ll e){ll r=1;while(e>0){if(e&1)r=(r%MOD)*(b%MOD)%MOD;b=(b%MOD)*(b%MOD)%MOD;e>>=1;}return r;}
double distance(ll x1, ll y1, ll x2, ll y2){return sqrt((x1-x2)*(x1-x2) + (y1-y2)*(y1-y2));}

template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
template<typename T1, typename T2> ostream& operator<<(ostream& s, const pair<T1, T2>& p) {return s << "(" << p.first << ", " << p.second << ")";}
template<typename T> ostream& operator<<(ostream& s, const vector<T>& v) {
    int len = v.size();
    s << '[';
    for (int i = 0; i < len; ++i) {
        s << v[i]; if (i < len-1) s << ", ";
    }
    s << ']';
    return s;
}

struct aaa{
    aaa(){
        // comment this out when you use scanf or printf
        // cin.tie(0); ios::sync_with_stdio(0);
        cout<<fixed<<setprecision(15);
    };
}fastio;

int main(){

    int n,m;
    cin >> n >> m;
    vector<ll> a(n);
    priority_queue<ll> pq;
    rep(i, n) {
        ll a;
        scanf("%lld", &a);
        pq.push(a);
    }

    while(!pq.empty() and m > 0){
        int x = pq.top(); pq.pop();
        x /= 2;
        pq.push(x);
        --m;
    }
    ll sum = 0;
    while(!pq.empty()){
        sum += pq.top(); pq.pop();
    }

    ppp(sum);
    
    


    return 0;
}


Measured memory_bytes: 2168
#include <bits/stdc++.h>
using namespace std;
#include <math.h>
#include <iomanip>
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
const int INF=1001001001;
vector<pair<int64_t,int64_t>>prime_factorize(int64_t x){
  vector<pair<int64_t,int64_t>>p;
  for(int64_t i=2;i*i<=x;i++){
    int cnt=0;
    if(x%i==0){
    while(x%i==0){cnt++;x/=i;}
    p.push_back(make_pair(i,cnt));
    }
  }
  if(x!=1){p.push_back(make_pair(x,1));}
  return p; 
}
int main() {
  int N;
  cin>>N;
  vector<int>a(N),b(N);
  for(int i=0;i<N;i++){
    cin>>a[i];
  }
  for(int i=0;i<N;i++){
    cin>>b[i];
  }
  int64_t cntp=0,cntm=0;
  for(int i=0;i<N;i++){
   if(a[i]>b[i]){cntp+=(a[i]-b[i]);}
   if(b[i]>a[i]){cntm+=(b[i]-a[i])/2;}
  }
  if(cntp<=cntm){cout<<"Yes"<<endl;}
  else{cout<<"No"<<endl;}
  return 0;
}

Measured memory_bytes: 3708