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

using namespace std;

typedef long long          ll;
typedef unsigned long long ull;
typedef vector<int>	       vi;
typedef vector<bool>       vb;
typedef map<int, int>      mii;
typedef pair<int, int>     ii;

#define INF                0x3f3f3f3f
#define INFLL              0x3f3f3f3f3f3f3f3f
#define each(x, s)         for(auto& x : s)
#define loop(x)	           for(int i = 0;i < x;i++)
#define vloop(v, x)        for(int v = 0;v < x;v++)
#define avg(l, r)          l + (r - l) / 2
#define iter(a)            a.begin(), a.end()
#define riter(a)           a.rbegin(), a.rend()
#define endl               "\n"

const ll mod = 1000000007;

pair<ll, ll> eucl(ll a, ll b) {
	if (b == 0) return make_pair(1ll, 0ll);
	ll x, y;
	tie(x, y) = eucl(b, a % b);
	return make_pair(y, x - a / b * y);
}

ll inv(ll x) {
	ll y;
	tie(y, ignore) = eucl(x, mod);
	return (y % mod + mod) % mod;
}

ll eval(pair<ll, ll>& p) {
	return p.first * inv(p.second) % mod;
}

int main() {
	ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);

	int h, w, a, b;
	cin >> h >> w >> a >> b;
	ll ans = 0;
	vector<pair<ll, ll>> c1(1, {1, 1}), c2(1, {1, 1});
	ll n1 = h - a - 1, n2 = a - 1;
	for (int i = 1;i <= w;i++) {
		c1.emplace_back(c1[i - 1].first * (n1 + i) % mod, c1[i - 1].second * i % mod);
		c2.emplace_back(c2[i - 1].first * (n2 + i) % mod, c2[i - 1].second * i % mod);
	}
	for (int i = b;i < w;i++) {
		ans += eval(c1[i]) * eval(c2[w - i - 1]) % mod;
		ans %= mod;
	}
	cout << ans << endl;
	return 0;
}



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

typedef unsigned long ul;
typedef unsigned long long ull;
typedef long long ll;
typedef vector<ll> vint;
typedef vector< vector<ll> > vvint;
typedef vector< vector< vector<ll> > > vvvint;
typedef vector<string> vstring;
typedef vector< vector<string> > vvstring;
typedef vector<char> vchar;
typedef vector< vector<char> > vvchar;
typedef vector<long double> vdouble;
typedef vector< vector<long double> > vvdouble;
typedef vector< vector< vector<long double> > > vvvdouble;
typedef pair<ll,ll> pint;
typedef vector<pint> vpint;
typedef vector<bool> vbool;

#define rep(i,n) for(ll i=0;i<n;i++)
#define repf(i,f,n) for(ll i=f;i<n;i++)
#define repr(i,n) for(ll i=n-1;i>=0;i--)
#define mp make_pair
#define mt make_tuple
#define pb push_back
#define pf push_front
#define fi first
#define se second
#define ALL(obj) (obj).begin(), (obj).end()
// #define LLONG_MAX 9223372036854775806
#define vmax(vec) *max_element(vec.begin(), vec.end())
#define vmin(vec) *min_element(vec.begin(), vec.end())
#define vsort(vec) sort(vec.begin(), vec.end())
#define vsortgr(vec) sort(vec.begin(), vec.end(), greater<ll>())
#define MOD 1000000007
// #define MOD 998244353
// #define MOD LLONG_MAX
const double PI=3.14159265358979323846;
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; }

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

void printv(vint &v){
    for(auto e:v) cout<<e<<" ";
        cout<<endl;
    }

// 繰り返し二乗法
ll power(ll a, ll b){
    if(a==1)return a;
    // if(a==0)re
    ll res=1;
    while(b>0){
        if(b&1) res=res*a%MOD;
        a=a*a%MOD;
        b>>=1;
    }
    return res;
}

const int MAX=2100000;

ll fact[MAX], fact_inv[MAX];

void init_fact(ll n){
    fact[0]=1;
    // 階乗の計算
    for(ll i=0; i<n; i++) fact[i+1]=fact[i]*(i+1)%MOD;
    fact_inv[n]=power(fact[n], MOD-2);
    // 逆元の計算
    for(ll i=n-1;i>=0;i--) fact_inv[i]=fact_inv[i+1]*(i+1)%MOD;
}

ll comb(ll n, ll r){
    return (fact[n]*fact_inv[r])%MOD*fact_inv[n-r]%MOD;
}

ll perm(ll n, ll r){
    return (fact[n]*fact_inv[n-r])%MOD;
}
template< typename T >
struct BinaryIndexedTree {
  vector< T > data;

  BinaryIndexedTree(int sz) {
    data.assign(++sz, 0);
  }

  T sum(int k) {
    T ret = 0;
    for(++k; k > 0; k -= k & -k) ret += data[k];
    return (ret);
  }

  void add(int k, T x) {
    for(++k; k < data.size(); k += k & -k) data[k] += x;
  }
};

int main() {
    cout<<fixed<<setprecision(10);
    ll n,k; cin>>n>>k;
    vint a(n); rep(i,n) cin>>a[i];


    vint rui(n+1,0);
    rep(i,n){
        rui[i+1] = rui[i] + a[i] - k;
    }
    set<ll> s;
    for(auto e:rui) s.insert(-e);
    // printv(rui);
    map<ll,ll> m;
    ll cnt = 0;
    for(auto e:s){
        m[e] = cnt;
        cnt++;
    }
    BinaryIndexedTree<ll> bit(s.size());

    ll ans = 0;

    repr(i,n){
        bit.add(m[-rui[i+1]], 1);
        // m[rui[i]] 以上の数を数える
        ll tmp = bit.sum(m[-rui[i]]);
        // cout<<tmp<<endl;
        ans += tmp;
    }


    cout<<ans<<endl;


    return 0;

}

Measured memory_bytes: 26752
S = input()
s = list(S)
nums = []
for i in s:
    nums.append(int(i))

sum = nums[0]
ans = ""
a = ""
check = False
for i in range(2):
    if check:
        break
    else:
        sum = nums[0]
        ans = s[0]
    if i == 0:
        sum += nums[1]
        ans += "+"
    else:
        sum -= nums[1]
        ans += "-"
    ans += s[1]
    for j in range(2):
        sum2 = sum
        ans2 = ans
        if j == 0:
            sum2 += nums[2]
            ans2 += "+"
        else:
            sum2 -= nums[2]
            ans2 += "-"
        ans2 += s[2]
        for k in range(2):
            sum3 = sum2
            ans3 = ans2
            if k == 0:
                sum3 += nums[3]
                ans3 += "+"
            else:
                sum3 -= nums[3]
                ans3 += "-"
            ans3 += s[3]
            if sum3 == 7:
                check = True
                a = ans3
a += "=7"
print(a)


Measured memory_bytes: 3064
import random
import time
import copy
start = time.time()
D = int(input())
s = [[0 for j in range(26)] for i in range(D)]
c = list(map(int, input().split(" ")))
result = []
total = -10000000
for i in range(D):
    a = list(map(int, input().split(" ")))
    for j, k in enumerate(a):
        s[i][j] = int(k)
cnt=0
score = [0 for i in range(26)]

while(1):
    cnt+=1
    result_tmp = []
    total_tmp = 0
    last = [0 for i in range(26)]
    for i in range(D):
        for j in range(26):
            score[j] = s[i][j]
            for k in range(26):
                if j != k:
                    score[j] -= (i + 1 - last[k]) * c[k]

        score_max = max(score)
        tmp = []
        
        for j in range(26):
            if score_max >= 0 and score_max*0.8 <= score[j]:
                tmp.append(j)
            if score_max < 0 and score_max*1.1 <= score[j]:
                tmp.append(j)

        score_max = random.choice(tmp)
        result_tmp.append(score_max)
        last[score_max] = i + 1
        total_tmp += score[score_max]
    if total < total_tmp:
        total = total_tmp
        result = result_tmp.copy()
    end = time.time()
    
    if end - start > 1.8:
        break
#print("total",total,cnt)
for i in range(D):
    print(result[i]+1)

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

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  
  int n;
  cin >> n;
  
  int p, keep = 1e9, ans = 0;
  for(int i = 0; i < n; i++){
    cin >> p;
    if(keep > p){
      keep = p;
      ans++;
    }
  }
  
  cout << ans << '\n';
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define rrep(ri,n) for(int ri = (int)(n-1); ri >= 0; ri--)
#define rep2(i,x,n) for(int i = (int)(x); i < (int)(n); i++)
#define repit(itr,x) for(auto itr = x.begin(); itr != x.end(); itr++)
#define rrepit(ritr,x) for(auto ritr = x.rbegin(); ritr != x.rend(); ritr++)
#define ALL(n) begin(n), end(n)
using ll = long long;
using namespace std;

int main(){
	int n;
	cin >> n;
	rep(i, n){
		char in;
		cin >> in;
		if(in == 'Y'){
			cout << "Four" << endl;
			return 0;
		}
	}
	cout << "Three" << endl;
	return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<math.h>
  
using namespace std;
  
int main(){
int a,b,c;
cin >> a >>b >>c;
if (a<b&&b<c){
    cout <<"Yes" <<endl ;
}

else {cout << "No"<<endl;
}
return 0;
}


Measured memory_bytes: 3080
n = int(input())
blue = {}
for i in range(n):
    w = input()
    blue[w] = blue.get(w, 0) + 1

m = int(input())
red = {}
for i in range(m):
    w = input()
    red[w] = red.get(w, 0) + 1

pt_lst = []
for i in blue:
    pt = blue[i] - red.get(i, 0)
    pt_lst.append(pt)

pt = max(pt_lst)
if pt < 0:
    pt = 0

print(pt)


Measured memory_bytes: 3064
#include <iostream>
#include <vector>
#include <algorithm>
#include <utility>
using namespace std;
#define ll long long

ll gcd(ll a, ll b) {
	if (b == 0)return a;

	return gcd(b, a % b);
}

ll lcm(ll a, ll b) {
	return a * b / gcd(a, b);
}

int main() {
	ll n, a[200010], b[200010], time = 0;
	pair<ll, ll> p[200010];
	cin >> n;
	for (int i = 0; i < n; i++) {
		cin >> p[i].second >> p[i].first;
	}
	sort(p, p + n);
	for (int i = 0; i < n; i++) {
		time += p[i].second;
		if (time > p[i].first) {
			cout << "No" << endl;
			return 0;
		}
	}
	cout << "Yes" << endl;
	return 0;
}

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

using namespace std;

int main(){
    int n; cin >> n;
    vector<int>a(n);
    vector<int>b(n);

    for(int i=0; i<n; i++) cin >> a[i];
    for(int i=0; i<n; i++) cin >> b[i];

    int ans=0, w;

    for(int i=0; i<n; i++){
        w = 0;
        for(int t=0; t<=i; t++){
            w += a[t];
        }
        for(int s=n-1; s >= i; s--){
            w += b[s];
        }
        ans = max(ans, w);
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 3632
let n = Int(readLine()!)!
let a = readLine()!.split(separator: " ").map { Int($0)! }

var iDict = [Int: Int]()
var jDict = [Int: Int]()

a.enumerated().forEach { (i, v) in
  iDict[i+v] = iDict[i+v] ?? 0
  iDict[i+v]? += 1
  jDict[i-v] = jDict[i-v] ?? 0
  jDict[i-v]? += 1
}

var c = 0
iDict.forEach { (v, iIndicesNum) in
  let jIndicesNum = jDict[v] ?? 0
  c += iIndicesNum * jIndicesNum
}

print(c)


Measured memory_bytes: 26188
#include <stdio.h>

int main(){

  int W,H,x,y,r;
  scanf("%d %d %d %d %d",&W,&H,&x,&y,&r);

  // if(x > 0 && y > 0){
    if(x - r >= 0 && y - r >= 0 && x + r <= W && y + r <= H){
      printf("Yes\n");
    }
    else{
      printf("No\n");
    }
    //}
  
    //  else{
    //printf("No\n");
    //}

  return 0; 
}

Measured memory_bytes: 584
<?php
fscanf(STDIN, "%d", $N);
$b = array_map('intval', explode(" ", trim(fgets(STDIN))));

$ans = [];

while ($b) {
    $cnt = count($b);
    $bingo = null;
    for ($i = $cnt - 1; $i >= 0; $i--) {
        if ($b[$i] === $i + 1) {
            $bingo = $i;
            break;
        }
    }
    if ($bingo === null) {
        echo "-1";
        exit;
    } else {
        $ans[] = $i + 1;
        array_splice($b, $i, 1);
    }
}
echo implode(PHP_EOL, array_reverse($ans));


Measured memory_bytes: 4728
#include <iostream>

int main(){
   int N;
   std::cin >> N;
   int d[N];
   for(int i=0; i<N; ++i) std::cin >> d[i];

   long long ans = 0;
   for(int i=0; i<N; ++i){
      for(int j=i+1; j<N; ++j)
	 ans += d[i]*d[j];
   }
   std::cout << ans << std::endl;
   return 0;
}


Measured memory_bytes: 256
#[allow(unused_macros)]
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

#[allow(unused_macros)]
macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

    ($next:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };

    ($next:expr, mut $var:ident : $t:tt $($r:tt)*) => {
        let mut $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
}

#[allow(unused_macros)]
macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };

    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };

    ($next:expr, usize1) => {
        read_value!($next, usize) - 1
    };

    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}

#[allow(unused_macros)]
macro_rules! debug {
    ($($a:expr),*) => {
        #[cfg(debug_assertions)]
        writeln!(&mut std::io::stderr(), concat!("[DEBUG] ", $(stringify!($a), "={:?} "),*), $($a),*);
    }
}

#[allow(unused_imports)]
use std::cmp::{min, max};

#[allow(unused_imports)]
use std::io::Write;

fn main() {
    input!{
      n: usize,
      a: usize,
      xs: [usize; n],
    }
    // O(N^3*X)
    let mut dp = vec![vec![vec![0; 50*n+1]; n+1]; n+1];
    dp[0][0][0] = 1;
    for i in 0..n {
        for j in 0..n+1 {
            for k in 0..50*n+1 {
                dp[i+1][j][k] = dp[i][j][k];
                if k>=xs[i] && j >= 1 {
                    dp[i+1][j][k] += dp[i][j-1][k-xs[i]];
                }
            }
        }
    }

    let mut ans = 0u64;
    for j in 1..n+1 {
        ans += dp[n][j][j*a];
    }
    println!("{}", ans);
}


Measured memory_bytes: 67836
#include<bits/stdc++.h>
using namespace std;
#define N 50005
#define ll long long
int a[110];
int main()
{
    int n;
    int sum=0,maxx=0;
    scanf("%d",&n);
    sum=0;
    for(int i=1;i<=n;i++)
    {
        scanf("%d",&a[i]);
        if(a[i]>a[i-1])
            sum+=a[i]-a[i-1];
    }

    printf("%d",sum);
    return 0;
}


Measured memory_bytes: 256
N, K = map(int, input().split())
L, R = [], []
for _ in range(K):
    tmpl, tmpr = map(int, input().split())
    L.append(tmpl)
    R.append(tmpr)
MOD = 998244353

dp = [0] * (N + 1)
dp[1] = 1
dp[2] = -1
for i in range(1, N + 1):
    dp[i] = dp[i - 1] + dp[i]
    for l, r in zip(L, R):
        if i + l < N + 1:
            dp[i + l] += dp[i]
            dp[i + l] %= MOD
        if i + r + 1 < N + 1:
            dp[i + r + 1] -= dp[i]
            dp[i + r + 1] %= MOD
print(dp[N] % MOD)


Measured memory_bytes: 20828
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < n; i++)
#define rrep(i, n) for (int i = n - 1; i >= 0; i--)
using namespace std;
using Graph = vector<vector<int>>;
#define MOD 1000000007
#define MOD2 998244353
#define INF ((1<<30)-1)
#define LINF (1LL<<60)
#define EPS (1e-10)
typedef long long ll;
typedef pair<ll, ll> P;


map<ll, ll> prime_factor(ll n) {
    map<ll, ll> ret;
    for (ll j = 2; j <= n; j++){
        ll J = j;
        for(ll i = 2; i * i <= j; i++) {
            while(J % i == 0) {
                ret[i]++;
                J /= i;
            }
        }
        if(J != 1) ret[J]++;
    }
    return ret;
}

int main(){
    int n;
    cin >> n;
    map<ll, ll> tmp = prime_factor(n);
    int a = 0, b = 0, c = 0, d = 0, e = 0;
    for(auto p : tmp) {
        // cout << p.first << " " << p.second << endl;
        if (p.second >= 2) a++;
        if (p.second >= 4) b++;
        if (p.second >= 14) c++;
        if (p.second >= 24) d++;
        if (p.second >= 74) e++;
    }

    // cout << a << " " << b << endl;
    // cout << b * (b - 1) / 2 * (a - 2) << endl;

    ll ans = 0;
    ans += max(b * (b - 1) / 2 * (a - 2), 0);
    ans += max(d * (a - 1), 0);
    ans += max(c * (b - 1), 0);
    ans += e;

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

Measured memory_bytes: 256
#include <stdio.h>
int main (void){
	int W=0;
	int H =0;

	while(scanf("%d %d",&W,&H)==2 && (W!=0 || H!=0)){
		if(W==0 && H==0){
			break;
		}else{
			for(int i=0; i<W; i++){
				if(i==0||i==W-1){
					for(int j=0; j<H; j++){
									printf("#");
								}
								printf("\n");
				}else{

					for(int j=0; j<H; j++){
											if(j==0||j==H-1){
												printf("#");
											}else{
												printf(".");
											}
										}
										printf("\n");
				}


			}
			printf("\n");
			fflush(stdout);
		}
}
}



Measured memory_bytes: 2048
#[allow(unused_macros)]
macro_rules! input { (source = $s:expr, $($r:tt)*) => { let mut iter = $s.split_whitespace(); let mut next = || { iter.next().unwrap() }; input_inner!{next, $($r)*} }; ($($r:tt)*) => { let stdin = std::io::stdin(); let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock())); let mut next = move || -> String{ bytes.by_ref().map(|r|r.unwrap() as char).skip_while(|c|c.is_whitespace()).take_while(|c|!c.is_whitespace()).collect() }; input_inner!{next, $($r)*} }; }
macro_rules! input_inner { ($next:expr) => {}; ($next:expr, ) => {}; ($next:expr, $var:ident : $t:tt $($r:tt)*) => { let $var = read_value!($next, $t); input_inner!{$next $($r)*} };}
macro_rules! read_value { ($next:expr, ( $($t:tt),* )) => { ( $(read_value!($next, $t)),* ) }; ($next:expr, [ $t:tt ; $len:expr ]) => { (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>() }; ($next:expr, chars) => { read_value!($next, String).chars().collect::<Vec<char>>() }; ($next:expr, bytes) => { read_value!($next, String).into_bytes() }; ($next:expr, usize1) => { read_value!($next, usize) - 1 }; ($next:expr, $t:ty) => { $next().parse::<$t>().expect("Parse error") }; }

#[allow(unused_imports)]
use std::cmp::{min,max};

fn main(){
    input!{
        d: u32,
        n: u32,
    }
    let n = if n==100 { 101 }else{ n };
    println!("{}", 100_u32.pow(d)*n);
}


Measured memory_bytes: 4352
#include <bits/stdc++.h>
#include <math.h>
#define _GLIBCXX_DEBUG
using namespace std;
int main() {
  
  int N;
  cin>>N;
  
  vector<long long> vec(N);
  for(int i=0;i<N;i++){
    cin>>vec[i];
  }
  
  
  sort(vec.begin(),vec.end());
  
  cout<<(long long)vec[N-1]-vec[0]<<endl;
}

Measured memory_bytes: 3644
#include<stdio.h>
#include<stdlib.h>
#include<math.h>
#include<string.h>
#include <time.h>
typedef long long llint;
typedef long double ldouble;
// 小大
int compare(const void *a, const void *b){return *(llint *)a - *(llint *)b;}
typedef struct{
    llint aa;
    llint bb;
}frequent;
// 小大
int cmp( const void *p, const void *q ) {
    return ((frequent*)p)->bb - ((frequent*)q)->bb;
}


int main(void){
    llint n,k,i,ans=0;
    scanf("%lld%lld",&n,&k);
    // llint [n];
    // for(i=0;i<n;i++){
    //     scanf("%lld",&[i]);
    // }
    if(n<k){
        for(i=0;i<k;i++){
            ans+=pow(10,i)*n;
        }
    }else{
        for(i=0;i<n;i++){
            ans+=pow(10,i)*k;
        }  
    }


    printf("%lld\n",ans);
    return 0;
}


Measured memory_bytes: 256
#[allow(unused_macros)]
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}
 
#[allow(unused_macros)]
macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};
 
    ($next:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
}
 
#[allow(unused_macros)]
macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };
 
    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };
 
    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };
 
    ($next:expr, bytes) => {
        read_value!($next, String).into_bytes()
    };
 
    ($next:expr, usize1) => {
        read_value!($next, usize) - 1
    };
 
    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}
use std::cmp::min;
fn main() {
    input! {
        n: usize,
        k: usize,
        h: [i64; n]
    }
 
    let mut h = h;
    h.sort();
    
    let mut ans = h[n-1];
    for x in 0..(h.len() - k+1){
        ans = min(ans, h[x+k-1]- h[x]);
    }  
    println!("{}", ans);
}



Measured memory_bytes: 4352
import java.util.*;

class Main {
  public static void main(String args[]) {
    Scanner sc = new Scanner(System.in);

    while (true) {
      int N = sc.nextInt();
      if (N == 0) return;

      int info[][] = new int[N+1][N];
      int index[] = new int[N+1];
      for (int i = 1; i < N+1; i++) {
        index[i] = sc.nextInt();
        for (int j = 0; j < index[i]; j++) {
          info[i][j] = sc.nextInt();
          //System.out.println("info["+(i)+"]["+j+"]:"+info[i][j]);
        }
      }

      int n = sc.nextInt();
      int a[] = new int[n];
      for (int i = 0; i < n; i++) {
        a[i] = sc.nextInt();
      }

      int ansCount = N;
      boolean isHannin[] = new boolean[N+1];
      for (int i = 1; i <= N; i++) {
        if (index[i] == 0) {
          isHannin[i] = false;
          ansCount--;
        }
        else isHannin[i] = true;
      }

      for (int i = 0; i < n; i++) {
        for (int j = 1; j < N+1; j++) {
          if (isHannin[j] == false) continue;
          for (int k = 0; k < index[j]; k++) {
            if (info[j][k] == a[i]) break;
            if (k == index[j]-1) {
              //System.out.println("false:" + j);
              isHannin[j] = false;
              ansCount--;
            }
          }
        }
      }

      if (ansCount == 1) {
        for (int i = 1; i <= N; i++) {
          if (isHannin[i] == true)
            System.out.println(i);
        }
      }
      else System.out.println("-1");
    }
  }
}



Measured memory_bytes: 77200
#include <bits/stdc++.h>
using namespace std;
using lint = long long;
using P = pair<int, int>;
using vec = vector<int>;
using mat = vector<vector<int>>;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(v) v.begin(), v.end()
#define endl "\n"

constexpr int MOD = 1000000007;
const int INF = 1 << 30;

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

    char c = 'a';
    string res = "";

    lint m_base = 26;

    while (n > 0) {
        n--;
        char d = c;
        d += (n % 26);
        res += d;
        n /= 26;
    }
    reverse(all(res));
    cout << res << endl;
    return 0;
}

Measured memory_bytes: 3628
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
			while (sc.hasNext()){
				String str = sc.nextLine();
					if (str.equals("END OF INPUT")) {
						break;
					}
				String[] strs = str.split(" ");

					for (int i = 0; i < strs.length; i++) {
						System.out.print(strs[i].length());
					}
				System.out.println();
			}
		sc.close();

	}
}


Measured memory_bytes: 26132
import java.util.Scanner;
import java.util.Arrays;
import java.util.ArrayList;
import java.util.List;
import java.util.Collections;

public class Main {
	public static void main(String args[]) throws InterruptedException {
		    Scanner sc = new Scanner(System.in);	
			
			int n = sc.nextInt();
			int[] mem = new int[n];
			int[] ar = new int[100005];
			int ans = 0;
			for (int i = 0; i < n; i++) {
				mem[i] = sc.nextInt();
				if(mem[i] > 100000){
					mem[i] = 0;
					ans++;
				}
			}
			for (int i = 0; i < n; i++) {
				ar[mem[i]]++;
			}
			for (int i = 1; i < 100005; i++) {
				if (ar[i] > i) {
					ans += (ar[i]-i);
				}else if(ar[i] == i){
					continue;
				}else{
					ans += ar[i];
				}	
			}
			System.out.println(ans);

		    sc.close(); }

	public static boolean isEven(int n ) {
		if (n % 2 == 0) {
			return true;
		}else{
			return false;
		}
	}
}

Measured memory_bytes: 61152
#include <bits/stdc++.h>
using namespace std;
int main() {
  int a, b;
  cin >> a >> b;
  int c[5];
  c[a] = 1;
  c[b] = 1;
  for(int i=1; i<=3; i++){
    if(c[i]!=1) cout << i << endl;
  }
}

Measured memory_bytes: 256
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<cmath>
#include<algorithm>
#include<iostream>
#include<string>
#include<vector>
#include<queue>
#include<map>
using namespace std;
typedef long long LL;
#define M(a,b) memset(a,b,sizeof(a))
#define pb push_back
const int maxn = 100000+10;
const LL mod = 1000000007;
int main() {

    LL n,m;
    scanf("%lld%lld",&n,&m);
    LL ans=0;
    if (n<<1 >= m) {
        ans=m>>1;
    }
    else {
        ans=n+(m-(n<<1))/4;
    }
    printf("%lld\n",ans);
    return 0;
}

Measured memory_bytes: 256
s=int(input())
a=[]
a.append(s)
cnt=2
t=0

while cnt<1000000:
    if a[cnt-2]%2==0:
        a.append(int(a[cnt-2]/2))
    else:
        a.append(int(3*a[cnt-2]+1))
    cnt+=1
    
    if a[cnt-2]==4:
        t+=1
        if t==2:
            b=len(a)
            break


for i in range(len(a)):
    if 2<=a.count(a[i]):
        Key=a[i]
        break
    
a.remove(Key)

print(min(a.index(Key)+2,b))
    

Measured memory_bytes: 3064
using System;
using System.Text;
using System.Collections.Generic;
using System.Linq;
using E = System.Linq.Enumerable;
 
class Program
 {
  
        static void Main(string[] args)
        {
          //入力を受け取る
          int N = int.Parse(Console.ReadLine());
          var S = Console.ReadLine();
          long sum = 0;
          for(int i = 1; i < N+1 ;i++){
            if(i == N+1){
              sum++;
            }
            while( i < N && S[i-1] == S[i]){
              i++;
            }
            sum++;
          }
          Console.Write(sum);
        }
  
 }

Measured memory_bytes: 11232
#include<iomanip>
#include<limits>
#include<thread>
#include<utility>
#include<iostream>
#include<string>
#include<algorithm>
#include<set>
#include<map>
#include<vector>
#include<stack>
#include<queue>
#include<cmath>
#include<numeric>
#include<cassert>
#include<random>
#include<chrono>
#include<unordered_set>
#include<unordered_map>
#include<fstream>
#include<list>
#include<functional>
#include<bitset>
#include<complex>
#include<tuple>
using namespace std;
typedef unsigned long long int ull;
typedef long long int ll;
typedef pair<ll,ll> pll;
typedef pair<int,int> pi;
typedef pair<double,double> pd;
typedef pair<double,ll> pdl;
#define F first
#define S second
const ll E=1e18+7;
const ll MOD=1000000007;





int main(){
    ll n,t,l,b;
    while(cin>>n>>t>>l>>b){
        if(n==0){break;}
    vector<ll> A(n+1,0);
    for(int i=0;i<l;i++){
        ll a;
        cin>>a;
        A[a]=1;
    }
    for(int i=0;i<b;i++){
        ll a;
        cin>>a;
        A[a]=2;
    }
    vector<vector<double>> dp(t+2,vector<double>(n+1,0));
    dp[0][0]=1;
    for(int i=0;i<t;i++){
        dp[i+1][n]+=dp[i][n];
        for(int t=0;t<n;t++){
            for(int h=1;h<=6;h++){
                ll next=t+h;
                if(next>n){next=n-(next-n);}
                if(A[next]==1){dp[i+2][next]+=dp[i][t]/6;}
                else if(A[next]==2){dp[i+1][0]+=dp[i][t]/6;}
                else{dp[i+1][next]+=dp[i][t]/6;}
            }
        }
    }
    cout<<fixed<<setprecision(12)<<dp[t][n]<<endl;
    }
    
    return 0;
}



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

int main()
{
  int N;
  cin >> N;
  vector<int> A(N + 1);//葉の数
  
  int64_t D = 0;//Dは分岐点の数
  int64_t T = 0;//深さiの頂点数
  int64_t P = 1;//深さi+1の頂点数
  bool imp = false;//２分木がつくれないときtrue
  
  for(int i = 0; i < N + 1; i++)
  {
    cin >> A.at(i);
    D += A.at(i);
  }
  
  D--;
  
  //ここまでOK
  
  for(int j = 0; j < N + 1; j++)
  {
    T += P;
    P -= A.at(j);//深さjで分岐できる頂点の数
    if(P < 0)
    {
      imp = true;
      break;
    }
    if(D >= P)
    {
      D -= P;
      P *= 2;
    }
    else
    {
      P += D;
      D = 0;
    }
  }
  
  if(imp){cout << "-1" << endl;}
  else{cout << T << endl;}
}

Measured memory_bytes: 3652
#include <iostream>
#include <cstdio>
#include <vector>
#include <queue>
#include <string>
#include <cmath>
#include <algorithm>

using namespace std;

#define pb push_back
#define mp make_pair
#define ff first
#define ss second

typedef long long ll;
typedef vector<ll> vi;
typedef vector<vi> vvi;
typedef pair<ll, ll> pii;
typedef vector<pii> vii;
typedef priority_queue<ll> pq;

const int MOD = 1e9+7;
const int INF = 2e9;
const int MAX_P = 55555;

vector<bool> isPrime(MAX_P, true);
vi ans;

void init() {
  isPrime[0] = isPrime[1] = false;
  for (int i = 2; i <= MAX_P; i++) {
    if (isPrime[i]) {
      if (i % 5 == 1) {
        ans.pb(i);
      }
      for (int j = 2*i; j <= MAX_P; j+=i) {
        isPrime[j] = false;
      }
    }
  }
}

int main() {
  int N;
  cin >> N;
  init();
  for (int i = 0; i < N-1; i++) {
    cout << ans[i] << " ";
  } cout << ans[N-1] << endl;
  return 0;
}


Measured memory_bytes: 256
n,k = map(int,input().split())
mod = 10**9+7

a = [1 for i in range(2010)]

memo = 1
for i in range(1,2001):
    memo *= i
    a[i] = memo



for i in range(1,k+1):
    if not((n-k+2 > i)):
        print(0)

    else:
        memo1 = a[n-k+1]*a[k-1]
        memo2 = a[i]*a[n-k+1-i]*a[i-1]*a[k-i]

        ans2 = memo1//memo2
        print(ans2%mod)
    


Measured memory_bytes: 5748
n = int(input())
s = list(input())

r, g, b = 0, 0, 0

for i in list(s):
    if i == 'R':
        r += 1
    elif i == 'G':
        g += 1
    else:
        b += 1

ans = r * g * b

for i in range(n):
    for j in range(i + 1, n):
        k = 2 * j - i

        if k >= n:
            continue

        if s[i] != s[j] and s[j] != s[k] and s[k] != s[i]:
            ans -= 1

print(ans)


Measured memory_bytes: 9204
// Author--> darklight13
#define _CRT_SECURE_NO_DEPRECATE
#include<bits/stdc++.h>
using namespace std;
#define int long long int
#define pb push_back
std::vector<int>adj[100009];
int dp[100009];
int dfs(int node)
{
	if(dp[node]!=-1){
		return dp[node];
	}
	int mx=0;
	for(auto it:adj[node])
	{
		mx = max(dfs(it),mx);
	}
	dp[node] = 1+mx;
	return 1+mx;
}
int32_t main()
{
	int n,m;cin>>n>>m;
	memset(dp,-1,sizeof dp);
	for(int i=0;i<m;i++)
	{
		int u,v;cin>>u>>v;
		adj[u].pb(v);
	}
	int ans=0;
	for(int i=1;i<=n;i++)
	{
		ans = max(ans,dfs(i));
	}
	cout<<ans-1;
    return 0;
}

Measured memory_bytes: 8576
#include <bits/stdc++.h>
#define REP(i,n) for (int i=0;i<(n);i++)
#define RREP(i,n) for (int i=(n)-1;i>=0;i--)
using namespace std;

int gcd(int a, int b) {
    if (a % b == 0)
        return b;
    else 
        return gcd(b, a % b);
}

int main()
{
    int N, K;
    cin >> N >> K;
    vector<int> A(N);
    REP(i, N) cin >> A[i];

    int m = 0, r = 0;
    REP (i, N) {
        m = max(m, A[i]);
        r = gcd(r, A[i]);
    }

    if (K % r == 0 && K <= m) {
        cout << "POSSIBLE" << endl;
    } else {
        cout << "IMPOSSIBLE" << endl;
    }
}


Measured memory_bytes: 640
#pragma GCC optimize("O3")
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <string>
#include <cstring>
#include <deque>
#include <list>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <complex>
#include <cmath>
#include <limits>
#include <cfloat>
#include <climits>
#include <ctime>
#include <cassert>
#include <numeric>
#include <fstream>
#include <functional>
#include <bitset>
using namespace std;

using ll = long long;
using P = pair<int, int>;
using T = tuple<int, int, int>;

template <class T> inline T chmax(T &a, const T b) {return a = (a < b) ? b : a;}
template <class T> inline T chmin(T &a, const T b) {return a = (a > b) ? b : a;}

constexpr int MOD = 1e9 + 7;
constexpr int inf = 1e9;
constexpr long long INF = 1e18;
constexpr double pi = acos(-1);
constexpr double EPS = 1e-10;

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

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

    ll a, b, x; cin>>a>>b>>x;

    if(a == 0){
        cout << b / x + 1 << endl;
        return 0;
    }

    cout << (b / x - (a - 1) / x) << endl;

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(){
	int n,m;
	while(1){
		cin>>n>>m;
		if(!n&&!m)break;
		int data[11];
		memset(data,0,sizeof(data));
		while(n--){
			int d,p;
			cin>>d>>p;
			data[p]+=d;
		}
		int k=11,ans=0;
		while(--k){
			if(data[k]>0){
				if(data[k]>=m){
					data[k]-=m;
					for(int i=k;i>0;i--){
						ans+=i*data[i];
					}
					break;
				}else{
					m-=data[k];
				}
			}
		}
		cout<<ans<<endl;
	}
}
		

Measured memory_bytes: 1160
x1, y1 = map(int, input().split())
x2, y2 = map(int, input().split())
x3, y3 = map(int, input().split())

e12 = ((x2-x1)**2 + (y2-y1)**2)**0.5
e23 = ((x3-x2)**2 + (y3-y2)**2)**0.5
e31 = ((x1-x3)**2 + (y1-y3)**2)**0.5

s = (e12 + e23 + e31)/2
S = (s * (s-e12) * (s-e23) * (s-e31)) ** 0.5
r=2*S/(e12+e23+e31)
A=max(e12,e23,e31)
print(A*r/(2*r+A))

Measured memory_bytes: 38640
#include<iostream>
#include<vector>
#include<algorithm>
#include<cmath>
#include<unordered_set>
#define cs ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
typedef long long ll;

using namespace std;

int div(ll a){
    ll k=a;
    int t=1,q=sqrt(k);
    
    if(k%2==0){
        int g=1;
        while(k%2==0){g++;k/=2;}
        t*=g;
    }
    for(int i=3;i<=q;i+=2){
        if(k%i==0){
            int g=1;
            while(k%i==0){g++;k/=i;}
            t*=g;
        }
    }
    if(k>1) t*=2;
    t--;
    return t;

}
void f(ll a){
    int ans=div(a-1)+1,q=sqrt(a);
    unordered_set<ll> s;
    for(int i=2;i<=q;i++)
    if(a%i==0) {
        s.insert(i);
        s.insert(a/i);
    }
    for(auto i:s) {
        ll t=a;
        while(t%i==0) t/=i;
        if(t%i==1) ans++;    
    }
    cout<<ans;
}
int main(){
    
    cs;
    ll x;
    cin>>x;
    f(x);
    
}

Measured memory_bytes: 512
#include<iostream>
#include<algorithm>
#include<vector>
#include<cstdio>
#include<list>
#include<queue>
#include<string.h>
#include<functional>
#include<stack>
#include<deque>
#include<string>
#include<limits.h>
#include<map>
#include<set>
#include<unordered_map>
#include<unordered_set>
#define int long long
using namespace std;

signed main(){
	int a; cin >> a;
	cout << "ABC" << a << endl;
}

Measured memory_bytes: 256
#include<map>
#include<cstdio>
#include<iostream>
int main(){
    int n;
    scanf("%d", &n);
 
    long long ans = 1;
    const long long mod = 1e9 + 7;
 
    std::map<int, long long> factors;
    for(int i = 2; i <= n; i++){
        int d=i;
        for(int j=2;d>=j*j;j++){
            while(d % j == 0){
                factors[j]++;
                d /= j;
            }
        }
        if(d!=1)factors[d]++;
    }
 
    for(auto p : factors) ans = ans *(1 + p.second) % mod;
    printf("%ld\n", ans);
    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<unordered_map>
#include<bitset>
#include<math.h>
#include<vector>
#include<set>
#include<algorithm>
#include<ctype.h>
#include<unordered_set>
#include<string>
#include<iomanip>
#include<queue>
#include<climits>
#include<map>
#include<stack>
#include<iterator>
#include<cstring>
#include<deque>
#include<chrono>
using namespace std;
#define pi 3.141592653589793238

#define MOD 1000000007
#define INF 999999999999999999 
#define pb push_back
#define ff first
#define ss second
#define mt make_tuple
#define ll long long
#define fast ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define f0 get<0>
#define f1 get<1>
#define f2 get<2>
typedef vector<ll> vi;
typedef vector<vi> vvi;


////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
int main() {
    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);
    fast;
    ll T = 1, i, j;
    
    
    //cin >> T;
    while (T--) {
        ll n;
        cin >> n;
        cout << (1000 - n % 1000) % 1000;
    }

    return 0;
}


Measured memory_bytes: 3624
#include<bits/stdc++.h>
using namespace std;
#define debug(x) cout << '>' << #x << ':' << x << endl;
#define ll long long

bool cmp(int a, int b) {
	if (a % 10 != 0 && b % 10 != 0 && a % 10 != b % 10)
		return a % 10 < b % 10;
	else if (a % 10 == b % 10)
		return a < b;
	else
		return a % 10 > b % 10;

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

	sort(arr, arr + n, cmp);

	int i = 0;
	while (ans % 10 == 0 && i < n) {
		ans -= arr[i];
		i++;
	}
	cout << ans << endl;

}


Measured memory_bytes: 3652
object Main extends App {
  val in = scala.io.Source.stdin.getLines.toSeq
  val S = in.tail.head
  val Q = in.tail.tail.map(_.split(' ').map(_.toInt))
  val A = (0 to S.size).toArray.map(_ => 0)
  (0 until S.size-1).foreach{ i =>
    if( S(i)=='A' && S(i+1)=='C' ) A(i+1) = A(i) + 1 else A(i+1) = A(i)
  }
  //println(A.toSeq)
  Q.foreach{ q =>
    val l = q(0)-1
    val r = q(1)-1
    val ret = A(r) - A(l)
    println(ret)
  }
}


Measured memory_bytes: 74380
#include<iostream>

using namespace std;


int retDigSum(int n){
    if(n/10==0){
        return n%10;
    }
    return retDigSum(n/10)+(n%10);
}


int main(){
    int n;
    int res;

    cin>>n;
    res=retDigSum(n);

    if(n%res==0){
        cout<<"Yes"<<endl;
    }
    else{
        cout<<"No"<<endl;
    }
    


}

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

struct Point{double x,y;};//点
struct Segment{Point p1,p2;};//線
double dot(Point a,Point b){//内積
    return a.x*b.x+a.y*b.y;
}
double cross(Point a,Point b){//外積
    return a.x*b.y-a.y*b.x;
}
double norm(Point a){
    return a.x*a.x+a.y*a.y;
}
Point project(Segment s,Point p){
    Point base,q;
    Point ans;
    base.x=s.p2.x-s.p1.x;
    base.y=s.p2.y-s.p1.y;
    q.x=p.x-s.p1.x;
    q.y=p.y-s.p1.y;
    double r=dot(q,base)/norm(base);
    ans.x=s.p1.x+base.x*r;
    ans.y=s.p1.y+base.y*r;
    return ans;
}
/*Point reflect(Segment s,Point p){
    return p+(project(s,p)-p)*2.0;
}*/

int main(void){
    int n;
    Segment a;
    Point p,ans;
    cin>>a.p1.x>>a.p1.y>>a.p2.x>>a.p2.y;
    cin>>n;
    for(int i=0;i<n;i++){
        cin>>p.x>>p.y;
        ans=project(a,p);
        cout<<fixed<<setprecision(10)<<ans.x<<" "<<ans.y<<endl;
    }
    return 0;
}



Measured memory_bytes: 3288
#include <iostream>
#include <iomanip>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <array>
#include <tuple>
#include <string>
#include <algorithm>
#include <functional> // greater など
#include <cmath>      // abs など
#include <numeric>    // accumulate, gcd など
#include <cassert>    // assert
#include <stdexcept>
#include <bitset>
using namespace std;

// #include <boost/multiprecision/cpp_int.hpp>
// using namespace boost::multiprecision;

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
typedef long long ll;
// typedef int128_t ll;
// typedef cpp_int ll;

// GCC, 配列のアクセスなど
#define _GLIBCXX_DEBUG
// Clang, 配列のアクセスなど
#define _LIBCPP_DEBUG 0

// #define NDEBUG 1
// debug用出力 https://trap.jp/post/998/
void debug_out() { cerr << endl; }
template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T)
{
    cerr << H << " ";
    debug_out(T...);
}
#ifdef NDEBUG
#define debug(...)
#else
#define debug(...) debug_out(__VA_ARGS__)
#endif

//////////////// //////////////// //////////////// //////////////// ////////////////
//////////////// //////////////// //////////////// //////////////// ////////////////

// 別の書き方を使ってみる

// constexpr inline ll mod = 1'000'000'007;
constexpr int max_n = 200'000 + 5;

int n, q;
vector<int> p, x;
vector<int> cnts;

vector<vector<int>> edges;

vector<int> hd; // max_n
vector<int> nxt, to; // 2*max_n
int edge_cnt;
void add_edge(int u, int v) { // u to v
    edge_cnt++; // 辺が1つ増える
    to[edge_cnt] = v; // edge_cnt本目の辺の行き先はv
    nxt[edge_cnt] = hd[u]; // edge_cnt本目の辺の次に見る(uから出る)辺は、はじめに見ていた(uから出る)辺であるhd[u]本目の辺
    hd[u] = edge_cnt; // 新しくはじめに見る(uから出る)辺はedge_cnt本目の辺
}

void dfs(int cur = 0, int parent = -1)
{
    for (int e = hd[cur]; e > 0; e = nxt[e]) {
       int child = to[e];
       if (child == parent) { continue; }
       cnts[child] += cnts[cur];
       dfs(child, cur);
   }
}

int main()
{
    // 入出力
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    cout << setprecision(10); // 浮動小数の表示の精度

    cin >> n >> q;
    edges.resize(n);
    p.resize(q);
    x.resize(q);
    cnts.resize(n);
    hd.resize(n);
    nxt.resize(2*n);
    to.resize(2*n);
    rep(i, n - 1)
    {
        int a, b;
        cin >> a >> b;
        a--;
        b--;
        add_edge(a,b);
        add_edge(b,a);
    }
    rep(j, q)
    {
        cin >> p[j] >> x[j];
        p[j]--;
    }

    // q回足す
    rep(j, q)
    {
        cnts[p[j]] += x[j];
    }

    // 集計
    dfs();

    rep(i, n)
    {
        cout << cnts[i] << endl;
    }

    return 0;
}


Measured memory_bytes: 26604
import sys
import bisect
from collections import defaultdict

n = int(input())
arr = []
d = defaultdict(list)
lines = sys.stdin.readlines()
ans = [None] * n

for i in range(n):
    q, *arg = lines[i].split()
    key = arg[0]
    l_idx = bisect.bisect_left(arr, arg[0])
    r_idx = bisect.bisect_right(arr, arg[0])
    if q == '0':    # insert
        if l_idx == len(arr) or arr[l_idx] != key:
            arr.insert(l_idx, key)
        d[key].append(arg[1])
    elif q == '1':  # get
        if l_idx != r_idx:
            ans[i] = '\n'.join(d[key])
    elif q == '2':  # delete
        arr[l_idx:r_idx] = []
        if l_idx != r_idx:
            del d[key]
    elif q == '3':  # dump L R
        r_idx = bisect.bisect_right(arr, arg[1])
        if l_idx != r_idx:
            keys = arr[l_idx:r_idx]
            ans[i] = '\n'.join(['\n'.join([f'{k} {x}' for x in d[k]]) for k in keys])

[print(x) for x in ans if x is not None]


Measured memory_bytes: 72316
def factorize(M):
    fact=[]
    for i in range(2,10**5):
        tmp=[1]
        if M==1:
            break
        while M%i==0:
            M//=i
            tmp.append(tmp[-1]*i)
        if len(tmp)>1:
            fact.append(tmp)
    if M!=1:
        fact.append([1,M])
    return fact

def divisor(fact,arr,i,p):
    if i == len(fact):
        arr.append(p)
        return 0
    for x in fact[i]:
        divisor(fact,arr,i+1,p*x)
    
N,M=list(map(int,input().split()))

fact = factorize(M)
arr=[]
divisor(fact,arr,0,1)
arr=sorted(arr)
ans=1
for x in arr:
    if x>M//N:
        break
    ans=x
print(ans)

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

int main() {
	int N;
	cin >> N;
	if ((N / 1000 == N % 1000 / 100 && N % 1000 / 100 == N % 100 / 10) || (N % 1000 / 100 == N % 100 / 10 && N % 100 / 10 == N % 10)) {
		puts("Yes");
	}
	else {
		puts("No");
	}
	return 0;
}

Measured memory_bytes: 256
import sys
def ii(): return int(sys.stdin.readline())
def mi(): return map(int, sys.stdin.readline().split())
def li(): return list(map(int, sys.stdin.readline().split()))
def li2(N): return [list(map(int, sys.stdin.readline().split())) for i in range(N)]
def dp2(ini, i, j): return [[ini]*i for i2 in range(j)]
def dp3(ini, i, j, k): return [[[ini]*i for i2 in range(j)] for i3 in range(k)]
#import bisect #bisect.bisect_left(B, a)
#from collections import defaultdict #d = defaultdict(int) d[key] += value

sys.setrecursionlimit(10**6)

def rec(x):
    global dp
    if dp[x]!=-1:
        return dp[x]
    num = 0
    for a in adj[x]:
        num = max(num, rec(a)+1)
    dp[x] = num
    return num


#入力受け取り
N, M = mi()
x = li2(M)

#隣接リスト作成
adj = [[] for i in range(N)]
for i in range(M):
    x[i][0] -= 1
    x[i][1] -= 1
    adj[x[i][0]].append(x[i][1])

dp = [-1]*N
for i in range(N):
    rec(i)

print(max(dp))

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

//string型文字列をint型整数にして返す
int str_to_num(string s) {return atoi(s.c_str());}
//約数の総数を返す
int count_divisor(int n){int c[n/2] = {1}; int n_half = n/2; for(int i=2;i<n_half;i++){if(n%i==0){n /= i;c[i]+=1;i--;if(n>1) continue;else break;}  }int r = 1;for(int i=2;i<n_half;i++){r *= c[i];}return r;}
//各桁の数の和を返す
int dig_num(int n){return (n<10) ? n: dig_num(n/10) + n%10;}

int dig_ord(int n){return (n<10) ? 1: dig_ord(n/10) + 1;}

int main(){
  int N; cin >> N;
  int a[N]; REP(i,N){cin >> a[i];}
  int b[N]; REP(i,N){cin >> b[i];}
  int c[N]; REP(i,N){cin >> c[i];}
  
  int r = 0;
  int idx_p = -10;
  REP(i,N){
    int idx = a[i]-1;
    r += b[idx];
    if(idx==idx_p+1){r+=c[idx_p];}
    idx_p = idx;
  }
  cout << r << '\n';
}
  

Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main()
{
int A, B, o, m, y;
	cin >> A >> B;
	 o = A + B;
	 m = A - B;
	 y = A * B;
	if (o >= m&& o >= y)
	{
		cout << o << endl;
	}
	else if (m >= o&& m >= y)
	{
		cout << m << endl;
	}
	else 
	{
		cout << y << endl;
	}
}

Measured memory_bytes: 256
///                                   ahmocs
#include <bits/stdc++.h>
typedef long long ll;
#define ahmocs  ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
const ll N=1e3+5;
char grid[N][N];
int ans[N][N];
using namespace std;
int main()
{
    ahmocs
    int h,w; cin>>h>>w;
    for (int i=0; i<h; ++i)
        for (int j=0; j<w; ++j)
            cin>>grid[i][j];
    ans[0][0]=1;
    for (int i=0; i<h; ++i)
    {
        for (int j=0; j<w; ++j)
        {
            if(grid[i][j]=='#')
                ans[i][j]=0;
            if (i && grid[i][j]=='.')
                ans[i][j]+=ans[i-1][j];
            if (j && grid[i][j]=='.')
                ans[i][j]+=ans[i][j-1];
            ans[i][j]%=1000000007;
        }
    }
    cout<<ans[h-1][w-1];
    return 0;
}



Measured memory_bytes: 5248
#include <iostream>
#include <string>
#include <vector>
#include <deque>
#include <list>
#include <set>
#include <unordered_set>
#include <map>
#include <unordered_map>
#include <array>
#include <algorithm>
#include <tuple>
#include <numeric>

int main()
{
	int N, M;
	std::vector<int> K;
	std::vector<std::vector<int>>A;

	std::cin >> N >> M;
	K.resize(N);
	A.resize(N);
	for (int i = 0; i < N; ++i) {
		std::cin >> K[i];
		A[i].resize(K[i]);
		for (int j = 0; j < K[i]; ++j) {
			std::cin >> A[i][j];
			--A[i][j];
		}
	}

	std::vector<int> L;
	L.resize(M);
	for (int i = 0; i < N; ++i) {
		for (int j = 0; j < K[i]; ++j) {
			++L[A[i][j]];
		}
	}

	int x = 0;
	for (auto l : L) {
		if (l == N)
			++x;
	}
	std::cout << x << "\n";

	return 0;
}


Measured memory_bytes: 256