akhauriyash/Code-Regression huggingface dataset:
#include <string.h>
#include <cmath>
#include <stdio.h>

int main()
{
	int n;
	char a[10000],b[10000],sum[10000];
	int len_a,len_b,len_max;
	scanf("%d",&n);
	for(int i = 0; i < n; i++){
		scanf("%s",a);
		scanf("%s",b);
		len_a = strlen(a);
		len_b = strlen(b);
		
		if(len_a > 80 || len_b > 80){
			printf("overflow\n");
			continue;
		}

		if(len_a > len_b){
			len_max = len_a;
		}else{
			len_max = len_b;
		}
		for(int j = 1; j <= len_max; j++){
			if(len_a - j < 0){
				sum[len_max - j] = b[len_b - j];
			}else if(len_b - j < 0){
				sum[len_max - j] = a[len_a - j];
			}else{
				sum[len_max - j] = a[len_a - j] + b[len_b - j] - '0';
			}
		}
		sum[len_max] = '\0';
		for(int j = len_max - 1; j >= 0; j--){
			if(sum[j] > '9' && j > 0){
				sum[j] = sum[j] - 10;
				sum[j - 1]++;
			}
		}
		if(sum[0] > '9' && len_max == 80){
			printf("overflow\n");
			continue;
		}
		if(sum[0] > '9'){
			sum[0] = sum[0] - 10;
			printf("1");
		}
		printf("%s\n",sum);
	}
	return 0;
}

Measured memory_bytes: 1024
#include <iostream>
#include <algorithm>
#include <map>
#include <set>
#include <queue>
#include <string>
 
using namespace std;
 
#define rip(i, n, s) for (int i = (s);i < ( int )( n ); i++)
#define all(a) (a).begin(), (a).end()
typedef long long ll; 

template<typename T>
void vdeb(vector<T> &da){
    int size=da.size();
    for(int i=0;i<size;i++){
        if(i==size-1){
            cout << da[i] << endl;
        }
        else{
            cout << da[i] << ' ';
        }
    }
}
template<typename T>
void vvdeb(vector<T> &da){
    int size=da.size();
    for(int i=0;i<size;i++){
        vdeb(da[i]);
    }
}

int main(){
	int n;
	ll a,b,c,d;
	cin >> n >> a >> b >> c >> d;
	ll now=a+(ll)(n-1)*d;
	if(b>now || b<a-(ll)(n-1)*d){
		cout << "NO" << endl;
		return 0;
	}
	rip(i,n-1,0){
		now-=c+d;
		if(now < b){
			now+=c+d;
			break;
		}
	}
	now-=(ll)(n-1)*(d-c);
	if(now>b){
		cout << "NO" << endl;
	}
	else{
		cout << "YES" << endl;
	}
}

Measured memory_bytes: 256
/**
 * code generated by JHelper
 * More info: https://github.com/AlexeyDmitriev/JHelper
 * @author champon
 */

#include <iostream>
#include <fstream>

#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define inf 1e18
#define ceill(a, b) (a+b-1)/b
#define ok cout << "ok" << endl;
#define sp << " " <<
ll mod = 1e9+7;
void ans(bool b, ostream& out=cout){ out << (b ? "Yes" : "No") << endl; }
void ans2(bool b, ostream& out=cout){ out << (b ? "YES" : "NO") << endl; }
template<typename T> inline bool chmax(T &a, T b){ if(a<b) a=b; return a<b; }
template<typename T> inline bool chmin(T &a, T b){ if(b<a) a=b; return b<a; }
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[] = {1, 0, -1, 0, 1, -1, 1, -1};
int dy[] = {0, 1, 0, -1, 1, -1, -1, 1};

#ifndef INCLUDE_DEBUG_HPP
#define INCLUDE_DEBUG_HPP

class debug
{
public:
    template<typename T> void vdeb(T vec);
    template<typename T1, typename T2> void adeb(T1 *arr, T2 n);
    template<typename T> void mdeb(T mp);
};

#endif //INCLUDE_DEBUG_HPP

template<typename T> void debug::vdeb(T vec)
{
    cout << "#vector set debug" << endl;
    for(auto vv : vec) cout << vv << " ";
    cout << endl;
}

template<typename T1, typename T2> void debug::adeb(T1 *arr, T2 n)
{
    cout << "#adebug" << endl;
    for(int i=0; i<=n; i++) cout << arr[i] << " ";
    cout << endl;
}

template<typename T> void debug::mdeb(T mp)
{
    cout << "#map pair debug" << endl;
    for(auto const& m : mp) cout << m.first sp m.second << endl;
}
debug dbg;

class BCardGameForTwo {
public:
	void solve(std::istream& in, std::ostream& out)
	{
	    int n;
	    in >> n;
        vector<int> a(n);
        for(int i=0; i<n; i++){
            in >> a[i];
        }
        sort(a.begin(), a.end(), greater<int>());
        int res = 0;
        for(int i=0; i<n; i++){
            if(i % 2 == 0) res += a[i];
            else res -= a[i];
        }

        out << res << endl;
	}
};


int main() {
	BCardGameForTwo solver;
	std::istream& in(std::cin);
	std::ostream& out(std::cout);
	solver.solve(in, out);
	return 0;
}


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

long long n, sum = 0;
vector<long long> a;
long long dp[305][90005] = {0};
long long dphalf[305][90005] = {0};

long long solve();

int main() {
  cin >> n;
  a.resize(n);
  for(int i = 0; i < n; ++i) cin >> a[i];
  cout << solve() << endl;
  return 0;
}

long long solve() {
  long long ans = 1;
  for(int i = 0; i < n; ++i) {
    ans *= 3;
    ans %= N;
    sum += a[i];
  }
  dp[0][0] = 1;
  for(int i = 0; i < n; ++i)
    for(int j = 0; j <= 90000; ++j) {
      dp[i + 1][j] = dp[i][j] * 2 % N;
      if(j >= a[i]) dp[i + 1][j] += dp[i][j - a[i]];
      dp[i + 1][j] %= N;
    }
  dphalf[0][0] = 1;
  for(int i = 0; i < n; ++i)
    for(int j = 0; j <= 90000; ++j) {
      dphalf[i + 1][j] = dphalf[i][j] % N;
      if(j >= a[i]) dphalf[i + 1][j] += dphalf[i][j - a[i]];
      dphalf[i + 1][j] %= N;
    }
  if(sum % 2 == 0) ans += dphalf[n][sum / 2] * 3 % N;
  for(long long i = (sum + 1) / 2; i <= sum; ++i) {
    ans -= dp[n][i] * 3 % N;
    if(ans < 0) ans += N;
  }
  return ans;
}

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

//

#define RESIDUE(u,v) (capacity[u][v] - flow[u][v])
#define RCOST(u,v) (cost[u][v] + h[u] - h[v])
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)   FOR(i,0,n)
#define LL long long

int n;
LL a[200000];
int trans[200000];

int main(){
  cin >> n;
  REP(i,n)
    cin>>a[i];
  int tmp;
  int i = 0;
  while(1){
    if(i >= n) break;
    if(a[i] != 0)
      trans[i] = i;
    else{
      FOR(j,i,n){
	tmp = j;
	if(a[j] != 0){
	  tmp--;
	  break;
	}
      }
      FOR(j,i,tmp+1){
	trans[j] = tmp;
      }
      i = tmp+1;
      continue;
    }
    i++;
  }
  LL cnt=0,num=0,idx2=0,xor_sum=0;
  REP(idx,n){
    idx2 = idx;
    xor_sum = a[idx];
    while(1){
      idx2++;
      if(idx2>=n) break;
      if(trans[idx2] != idx2){
	idx2 = trans[idx2];
	continue;
      }
      //cout << idx << " " << idx2 << "  " << (xor_sum ^ a[idx2]) << " " << (xor_sum + a[idx2])<< endl;
      if((xor_sum ^ a[idx2]) != (xor_sum + a[idx2])) break;
      xor_sum += a[idx2];
    }
    //cout<<"dbg "<<idx<<" "<<idx2<<endl;
    cnt+=idx2-idx;
  }
  cout<<cnt<<endl;
  return 0;
}


Measured memory_bytes: 2560
#include<iostream>
#include<string>
#include<algorithm>

using namespace std;

int main()
{
	int a,b;
	cin>>a>>b;
	string s[100];
	for(int i=0;i<a;i++){
		cin>>s[i];
	}
	sort(s,s+a);
	for(int i=0;i<a;i++){
		cout<<s[i];
	}
	cout<<endl;
}

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

int main() {
	string str;

	getline(cin, str);

	for(int i = 0; i < str.size(); i++){
		if (str[i] >= 'A' && str[i] <= 'Z') {
			cout << (char)(str[i] + 0x20);
		} else if (str[i] >= 'a' && str[i] <= 'z'){
			cout << (char)(str[i] - 0x20);
		} else{
			cout << str[i];
		}			 
	}

	cout << endl;

	return 0;
}


Measured memory_bytes: 3156
n,m = map(int,input().split())
d = [[] for _ in range(n+1)]
for i in range(m):
    a,b = map(int,input().split())
    #a,b = a-1,b-1
    d[a].append(b)
    d[b].append(a)
#print(d)  
from collections import deque
q = deque([1])
visited = [False]*(n+1)
visited[1] = True
signpost = [False]*(n+1)

while q:
    k = q.popleft()
    for j in d[k]:
        if visited[j] != False:
            continue
        visited[j] = True
        signpost[j] = k
        q.append(j)
#print(visited,signpost)
if signpost[2:]:
    print("Yes")
for i in range(2,n+1):
    print(signpost[i])


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

int main(){
  int ans = 0;
  string s;
  cin >> s;
  if(s[0] == '1'){
    ans++;
  } 
  if(s[1] == '1'){
    ans++;
  }
  if(s[2] == '1'){
    ans++;
  }
  cout << ans << endl;
}
     
  
 


Measured memory_bytes: 256
#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 << "Balanced\n";
	}else if(a+b > c+d){
		cout << "Left\n";
	}else{
		cout << "Right\n";
	}

	return 0;
}


Measured memory_bytes: 256
N = int(input())
S = input()
Q = int(input())
QUERY = [input().split() for _ in range(Q)]
# N = 4
# S = "abcd"
# QUERY = [s.split() for s in [
#     "2 1 4", # 4
#     "2 1 3", # 3
#     "2 3 4", # 2
#     "2 4 4", # 1
#     "1 2 a", # aacd
#     "2 1 2", # 1
#     "2 1 3", # 2
# ]]
# Q = len(QUERY)

def or_more_pow_two(n):
    if (n & (n-1)) == 0:
        return n
    return 1<<(len(bin(n))-2)

class SegmentTree:
    def __init__(self, n, l):
        self.n = or_more_pow_two(n)*2
        self.tree = [0]*self.n
        for i, l_i in enumerate(l):
            self.tree[self.n//2+i] = l_i
        for i in reversed(range(1, self.n//2)):
            self.node_update(i)
            # print(self.tree[i])

    # 1-indexed: [l, r)
    def find(self, l, r, fl=1, fr="self.n//2+1", node=1):
        if fr == "self.n//2+1":
            fr = self.n//2+1
        # print(f"find: ({l}, {r}), ({fl}, {fr}), {node}")
        if l <= fl and fr <= r:
            # print("in", bin(self.tree[node])[2:])
            return self.tree[node]
        elif fr <= l or r <= fl:
            # print("out")
            return 0
        else:
            # print("overlap")
            mid = (fl+fr)//2
            a = self.find(l, r, fl=fl, fr=mid, node=2*node)
            b = self.find(l, r, fl=mid, fr=fr, node=2*node+1)
            return a | b

    def update(self, index, v):
        # print("update:", index, v)
        x = self.n//2+index-1
        self.tree[x] = v
        while x > 0:
            x >>= 1
            self.node_update(x)

    def node_update(self, index):
        # print(index, [2*index, 2*index+1], list(map(bin, [self.tree[2*index], self.tree[2*index+1], self.tree[2*index] | self.tree[2*index+1]])))
        self.tree[index] = self.tree[2*index] | self.tree[2*index+1]

def char_to_bit(c):
    i = ord(c) - 97
    return (1 << i)
def bit_to_type_count(b):
    # print(bin(b)[2:])
    r = bin(b)[2:].count("1")
    # print(r)
    return r
# def bit_to_char(b):
#     for i in range(26):


segtree = SegmentTree(N, map(char_to_bit, S))

for t, *query in QUERY:
    t = int(t)
    if t == 1:
        i, c = query
        i, c = int(i), c
        segtree.update(i, char_to_bit(c))
    elif t == 2:
        l, r = map(int, query)
        l, r = l, r+1
        r = segtree.find(l, r)
        r = bit_to_type_count(r)
        print(r)
    # print(list(map(bin, segtree.tree)))


Measured memory_bytes: 92908
n =int(input())
H = list( map(int,input().split()))

for i in range(n-1,0,-1):
    if H[i]<H[i-1]:
        H[i-1] -=1
ans="Yes"
for i in range(n-1):
    if H[i]>H[i+1]:
        ans="No"

print(ans)

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

void solve() {
  std::string str;
  int q;
  std::string e;
  std::cin >> str >> q;
  std::reverse(str.begin(), str.end());
  for (int i = 0; i < q; i++) {
    int t;
    std::cin >> t;
    if (t == 1) swap(str, e);
    else {
      int f;
      char c;
      std::cin >> f >> c;
      if (f == 1) str += c;
      else e += c;
    }
  }
  std::reverse(str.begin(), str.end());
  str += e;
  std::cout << str;
  
}

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

Measured memory_bytes: 1128
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(ll i=0;i<n;i++)
#define repl(i,l,r) for(ll i=(l);i<(r);i++)
#define per(i,n) for(ll i=n-1;i>=0;i--)
#define lper(i,r,l) for(ll i=r-1;i>=l;i--)
#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define ins insert
#define all(x) (x).begin(),(x).end()
#define CST(x) cout<<fixed<<setprecision(x)
using ll=long long;
using vl=vector<ll>;
using vvl=vector<vector<ll>>;
using pl=pair<ll,ll>;
const ll MOD=1000000007;
const ll MOD9=998244353;
const int inf=1e9+10;
const ll INF=4e18;
const ll dy[4]={1,0,-1,0};
const ll dx[4]={0,-1,0,1};
ll modfac(ll a){
    ll ans=1;
    while(a>1){
        ans*=a;
        ans%=1000000007;
        a--;
    }
    return ans;
}
ll modinv(ll a,ll m) {
    ll b = m, u = 1, v = 0;
    while (b) {
        ll t = a / b;
        a -= t * b; swap(a, b);
        u -= t * v; swap(u, v);
    }
    u %= m; 
    if (u < 0) u += m;
    return u;
}
struct UnionFind {
    vector<int> par;
    
    UnionFind(int n) : par(n, -1) {}

    int root(int x) {
        if (par[x] < 0) return x;
        else return par[x] = root(par[x]);
    }
    
    bool same(int x, int y) {
        return root(x) == root(y);
    }
    
    bool merge(int x, int y) {
        x = root(x); y = root(y);
        if (x == y) return false;
        if (par[x] > par[y]) swap(x, y);
        par[x] += par[y];
        par[y] = x;
        return true;
    }
    
    int size(int x) {
        return -par[root(x)];
    }
};
ll modpow(ll a, ll n, ll mod) {
    ll res = 1;
    while (n > 0) {
        if (n & 1) res = res * a % mod;
        a = a * a % mod;
        n >>= 1;
    }
    return res;
}
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;
}
int main(){
    ll a,b,m;cin >> a >>b >>m;
    vl r(a),d(b);
    rep(i,a)cin >> r[i];
    rep(i,b)cin >> d[i];
    auto iter=min_element(all(r));
    ll x=*iter;
    auto itrr=min_element(all(d));
    ll y=*itrr;
    vl ans;
    ans.pb(x+y);
    rep(i,m){
        ll p,q;cin >> p >>q;
        p--;q--;
        ll minus;cin >> minus;
        ans.pb(r[p]+d[q]-minus);
    }
    auto itr=min_element(all(ans));
    cout << *itr <<endl;
}


Measured memory_bytes: 2936
N = int(input())
h = list(map(int, input().split())) 

cost = [0] * N # 各地点に着くまでにかかる最小のコスト
cost[1] = abs(h[1] - h[0]) # 一つ前からしかたどり着けない

for i in range(2, N):
    cost[i] = min(cost[i-1] + abs(h[i] - h[i-1]), 
                  cost[i-2] + abs(h[i] - h[i-2])) # コストが低い方を採用

print(cost[N - 1])

Measured memory_bytes: 13980
import math

n = int(input())
p = "".join(list(input().split()))
q = "".join(list(input().split()))

def f(x):
  y = 1
  z = []
  for i in range(len(x)):
    y += (int(x[i])-len(list(filter(lambda k:k<int(x[i]),z)))-1)*math.factorial(n-i-1)
    z.append(int(x[i]))
  return y

print(abs(f(p)-f(q)))

Measured memory_bytes: 38384
#include <algorithm>
#include <cctype>
#include <cstdio>
#include <cstring>
#include <map>

typedef long long LL;

LL read() {
  LL ans = 0; int c, f = 1;
  while (!isdigit(c = getchar()))
    if (c == '-') f *= -1;
  do ans = ans * 10 + c - '0';
  while (isdigit(c = getchar()));
  return ans * f;
}

const int N = 100050;
std::map<LL, int> M;

int n, siz[N], fa[N];
LL p[N];

int main() {
  n = read();
  for (int i = 1; i <= n; ++i)
    siz[M[read()] = i] = 1;
  for (std::map<LL, int>::iterator it = --M.end(); it != M.begin(); --it) {
    LL D = it->first;
    int i = it->second;
    LL t = D - n + 2 * siz[i];
    if (t >= D || !M.count(t)) { puts("-1"); return 0; }
    int j = M[t];
    siz[fa[i] = j] += siz[i];
    p[j] += siz[i] + p[i];
  }
  if (p[M.begin()->second] != M.begin()->first) {
    puts("-1"); return 0;
  }
  for (int i = 1; i <= n; ++i) if (fa[i])
    printf("%d %d\n", fa[i], i);
}


Measured memory_bytes: 9216
import java.math.BigDecimal;
import java.util.Scanner;

/*
 * プログラミングコンテスト解答(0007 Debt Hell)
 */
class Main {

    /*
     * 借金元金
     */
    public static final BigDecimal DEPT = new BigDecimal(100000);

    /*
     * 利子
     */
    public static final BigDecimal INTEREST = new BigDecimal("0.05");

    public static void main(String[] args) {
        Scanner s = new Scanner(System.in);
        int week = Integer.parseInt(s.next());
        /*
         * 借金残高計算
         */
        BigDecimal repay = DEPT;
        for (int i = 0; i < week; ++i) {
            repay = repay.add(repay.multiply(INTEREST)).setScale(-3,
                    BigDecimal.ROUND_CEILING);
        }
        s.close();
        System.out.println(repay.toPlainString());
    }
}

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

int N, K, a[5000];

bool C(int idx) {
    vector<vector<bool> > dp(N+1, vector<bool>(K+1, false));
    dp[0][0] = true;
    for(int i=0; i<N; i++) {
        for(int j=0; j<=K; j++) {
            if(dp[i][j]) {
                dp[i+1][j] = true;
                if(i != idx && j + a[i] <= K) dp[i+1][j+a[i]] = true;
            }
        }
    }
    int j = K - a[idx];
    if(j < 0) j = 0;
    for(; j<K; j++) {
        if(dp[N][j]) return true;
    }
    return false;
}

int main() {
    cin >> N >> K;
    for(int i=0; i<N; i++) cin >> a[i];
    sort(a, a+N, greater<int>());
    int l = 0, h = N + 1;
    while(h - l > 1) {
        int m = (l + h) / 2;
        if(C(m-1)) l = m;
        else h = m;
    }
    cout << N - l << endl;
    return 0;
}


Measured memory_bytes: 3636
import java.io.*;
class Main {
    public static void main(String[] args) throws IOException {
        BufferedReader r =
            new BufferedReader(new InputStreamReader(System.in), 1);
        String is = r.readLine();
        if(!is.contains(" "))
            return;
        String[] sp = is.split(" ");
        int a = Integer.parseInt(sp[0]);
        int b = Integer.parseInt(sp[1]);
        if(a>b)
            System.out.println("a > b");
        else if(a<b)
            System.out.println("a < b");
        else if (a==b)
            System.out.println("a == b");
        else;
      }
}

Measured memory_bytes: 24060
#include<bits/stdc++.h>
#define ll long long
#define rep1(i,a,b) for(int i=a;i<=b;i++)
#define eps 1e-8
#define int_inf 0x3f3f3f3f
#define ll_inf 0x7f7f7f7f7f7f7f7f
#define lson curPos<<1
#define rson curPos<<1|1
using namespace std;
const int maxn=1e5+10;
int fa[maxn],ans=0,n,m;
int find(int x)
{
  return fa[x]==x?x:fa[x]=find(fa[x]);
}
int main()
{
  cin>>n>>m;
  rep1(i,1,n) fa[i]=i;
  rep1(i,1,m)
  {
    int x, y, k;
    cin>>x>>y>>k;
    int px=find(x),py=find(y);
    fa[px]=py;
  }
  rep1(i,1,n) if(find(i)==i) ans++;
  cout<<ans<<'\n';
  return 0;
}


Measured memory_bytes: 1152
#include <stdio.h>
#include <string.h>

int main() {

  char str[1050] = {0};
  char ch[1050] = {0};
  char mei[30] = {0};
  char pl[1050]={0};
  int i,j,k,l,m,n,o,p;

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

  j=0;
  o=0;
  k=l=0;

  for ( i = 0; i < n; i++ ){
    scanf("%s", mei);
    scanf("%d %d", &k, &l);
    // printf("mei= %s",mei);
  
    
    if(mei[2] =='p') {
     
      scanf("%s", pl);

      for(m=0;m<l-k+1;m++) {

	//	printf("str[%d]%c = pl[%d]%c\n",m+k,str[m+k] ,m,pl[m]);
	str[m+k] = pl[m];	
      }
    }

    else if(mei[2] == 'v') {
      
      for(m=0; m<strlen(str);m++) {
	ch[m] = str[m];
      }
      
      for(m=0;m<l-k+1;m++) {
	//	printf("str[%d]%c = ch[%d]%c\n",k+m,str[k+m],l-m,ch[l-m]);
	str[k+m] = ch[l-m];
      }
    
    }

    else if(mei[0] = 'p') {   
      
      for(m=k; m<=l;m++) {
	printf("%c" ,str[m]);
      }
      printf("\n");
    }
    
  }

   
  return 0;

}


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

using ll = long long;

const ll MOD = 998244353;

ll mod_pow(ll x, ll n, ll mod) {
    ll res = 1;
    while (n > 0) {
        if (n & 1) res = res * x % mod;
        x = x * x % mod;
        n >>= 1;
    }
    return res;
}

int main() {
    ll N, A, B, K, ans = 0;
    cin >> N >> A >> B >> K;
    vector<ll> f(N + 1, 1) ;
    rep(i, N) f[i + 1] = (f[i] * (i + 1)) % MOD;
    rep(i, N + 1) {
        ll x = K - A * i;
        if (x < 0) break;
        if (x % B != 0) continue;
        ll j = x / B;
        if (j > N) continue;
        //cout << i << j << endl;
        ll c1 = ((f[N] * mod_pow(f[i], MOD - 2, MOD)) % MOD * mod_pow(f[N - i], MOD - 2, MOD)) % MOD;
        ll c2 = ((f[N] * mod_pow(f[j], MOD - 2, MOD)) % MOD * mod_pow(f[N - j], MOD - 2, MOD)) % MOD;
        ans = (ans + c1 * c2) % MOD;
    }
    cout << ans << endl;
}

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


using namespace std;
typedef long long ll;
typedef vector<ll> vll;
typedef vector<bool> vb;
typedef pair<ll,ll> pll;

#define rep(i,m,n) for(ll i=m;i<n;i++)

const ll mod=1000000007; 
const ll nmax=100005;
const ll inf=10000000000;

vb flag(3*nmax,false);
vll d(3*nmax,inf);
vector<vll> G(3*nmax);

int main(){
  ll n,m;
  cin >> n >> m;
   rep(i,0,m){
    ll u,v; 
     cin >> u >> v;
    G[3*(u-1)].push_back(3*(v-1)+1);
    G[3*(u-1)+1].push_back(3*(v-1)+2);
    G[3*(u-1)+2].push_back(3*(v-1));
   }
  ll s,t;
   cin >> s >> t;
  d[3*(s-1)]=0;
 
  queue<ll> que;


que.push(3*(s-1));
while(!que.empty()){
 ll v=que.front();
  que.pop();
 for(ll nv:G[v]){
  if(d[nv]!=inf) continue;
  d[nv]=d[v]+1;
  que.push(nv);
} 
}
  if(d[3*(t-1)]!=inf) cout << d[3*(t-1)]/3 << endl;
  else cout << -1 << endl;
}

Measured memory_bytes: 19072
import sys
input = sys.stdin.readline
rs = lambda: input().strip()
ri = lambda: int(input())
rl = lambda: list(map(int, input().split()))
mod = 10**9 + 7

N = ri()
P = rl()

s = 1
m = P[0]
for i in range(1, N):
    if m >= P[i]:
        s += 1
    m = min(m, P[i])
print(s)

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

int main(){
    int n;
    cin >> n;
    vector<int> ans(n,0);
    for(int x=1; x<100; x++){
        for(int y=1; y<100; y++){
            for(int z=1; z<100; z++){
                int out;
                out = x*x+y*y+z*z+x*y+y*z+z*x;
                if(out<=n) ans.at(out-1)++;
            }
        }
    }
    for(int i=0; i<n; i++){
        cout << ans.at(i) << endl;
    }
}


Measured memory_bytes: 3488
#include<stdio.h>

int main()
{
    int a[3],b[3],i,k;
    for(i=0;i<3;i++){
        scanf("%d",&b[i]);
    }
    a[0]=b[0]+b[1];
    a[1]=b[1]+b[2];
    a[2]=b[0]+b[2];
    k=a[0];
    for(i=0;i<3;i++){
        if(k>a[i]){
            k=a[i];
        }
    }
    printf("%d\n",k);

}


Measured memory_bytes: 128
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using Graph = vector<vector<int>>;
#define ALL(x) (x).begin(), (x).end()
#define REP(i ,n) for(int i = 0; i < (int)(n); i++)
#define pb push_back
typedef vector<int>vint;
typedef vector<ll>vll;
template<typename T> istream &operator>>(istream &is, vector<T> &vec){ for (auto &v : vec) is >> v; return is; }
template<typename A,typename B>inline bool chmin(A &a,const B &b){if(a>b){a=b;return true;}else{return false;}}
template<typename A,typename B>inline bool chmax(A &a,const B &b){if(a<b){a=b;return true;}else{return false;}}

int main()
{
    string S,T;
    cin >> S >> T;
    int ans = T.size();
    if(S.size() == T.size()){
        REP(i,S.size()){
            if(S[i] == T[i])ans--;
        }
    }else{
        for(int i=0;i<(int)S.size()-(int)T.size();i++){
            int cnt = T.size();
            for(int j=0;j<(int)T.size();j++){
                if(S[i+j] == T[j])cnt--;
            }
            chmin(ans,cnt);
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 3628
S = input()
T = input()

match_idx = []
for i in range(len(S)):
    is_match = True
    for j in range(len(T)):
        if i + j >= len(S):
            is_match = False
            break
        s = S[i + j]
        t = T[j]
        if not (s == '?' or s == t):
            is_match = False
            break
    if is_match:
        match_idx.append(i)

if len(match_idx) > 0:
    match_idx = match_idx[len(match_idx) - 1]
    ans_S = []
    j = 0
    for i, s in enumerate(S):
        if s == '?':
            if i == match_idx and j < len(T):
                ans_S.append(T[j])
                j += 1
                match_idx += 1
            else:
                ans_S.append('a')
        elif i == match_idx and j < len(T):
            ans_S.append(T[j])
            j += 1
            match_idx += 1
        else:
            ans_S.append(s)
    print(''.join(ans_S))
else:
    print('UNRESTORABLE')

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

#define pb push_back
#define mp make_pair
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef complex<double> point;
#define xx real()
#define yy imag()

#define REP(i, a, b) for(int i = (a); i < (int)(b); i++)
#define REPN(i, a, b) for(int i = (a); i <= (int)(b); i++)
#define FA(it, x) for(__typeof((x).begin()) it = (x).begin(); it != (x).end(); it++)
#define SZ(x) (int)(x).size()
#define BE(x) (x).begin(), (x).end()
#define SORT(x) sort(BE(x))
#define _1 first
#define _2 second

#define x1 gray_cat_x1
#define y1 gray_cat_y1

template<class T> T gcd(T a, T b) { return b ? gcd(b, a % b) : a; }

#define file "I1"

const double EPS = 1e-9;
const double PI = acos(-1.);
const int INF = 1e9;
const ll MOD = 1e9 + 7;

const int MAXN = 1e5 + 5;

void solve(){
	int a[3];
	int ans;
	scanf("%d%d%d", &a[0], &a[1], &a[2]);
	for(ans = 0; ; ans++) {
		REP(i, 0, 3) {
			if (a[i] % 2) {
				printf("%d\n", ans);
				return;
			}
		}
		
		sort(a, a + 3);
		if (a[0] == a[2]) {
			printf("-1\n");
			return;
		}
		
		int a0 = (a[1] + a[2]) / 2;
		int a1 = (a[0] + a[2]) / 2;
		int a2 = (a[0] + a[1]) / 2;
		a[0] = a0, a[1] = a1, a[2] = a2;
	}
}   

int main(){

    //freopen(file".in", "r", stdin); freopen(file".out", "w", stdout);
    int t = 1;
    //cin >> t;
    while(t--){
        solve();    
    }
}


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

int main()
{
   ll n;cin>>n;
   vector<ll> a(n);
   unordered_map<ll,ll> mp;
   for(int i=0;i<n;i++) 
   {
       cin>>a[i];
       mp[i-a[i]]++;
   }
   ll ans=0;
   for(int i=0;i<n;i++) ans+=mp[i+a[i]];
   cout<<ans<<"\n";
   
}

Measured memory_bytes: 20036
#include "bits/stdc++.h"
using namespace std;
#define INF 1e9
#define rep(i, n) for (int i = 0; i < n; i++)
#define rep2(i, l, r) for (int i = (l); i < (r); i++)
#define ALL(x) (x).begin(), (x).end()     //昇順
#define RALL(x) (x).rbegin(), (x).rend()  // 降順
#define FOR(i, c) \
  \ for (__typeof((c).begin()) i = (c).begin(); i != (c).end(); ++i)
const long long mod = 1e9 + 7;
typedef long long ll;  // ll とdoubleは違う
typedef priority_queue<int> PQ;
typedef vector<long long> VL;
typedef vector<bool> VB;
typedef vector<int> VI;  // VI a(n);
typedef vector<double> VD;
typedef vector<string> VS;
typedef vector<char> VC;
typedef vector<VS> VSS;
typedef vector<VC> VCC;
typedef vector<VI> VII;  // VII a(n,vector<int>(m)) n * m
typedef vector<VL> VLL;
typedef pair<int, int> PII;
typedef map<int, int> MP;  // MP a;
typedef vector<pair<ll, ll>> PS;

template <class T, class U>  // chmax(max, a);
bool chmax(T &a, U b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T, class U>  // chmin(min,a)
bool chmin(T &a, U b) {
  if (a > b) {
    a = b;
    return 1;
  }
  return 0;
}
template <typename T>  // operator << (cout,a);
ostream &operator<<(ostream &os, vector<T> &v) {
  os << "{";
  rep(i, (int)v.size()) { os << v[i] << (i < v.size() - 1 ? ", " : ""); }
  os << "}";
  return os;
}

// g++ -std=c++11 prac.cpp

int main() {
  int x,y,z=0,k,n,m,h,w,sum=0,Max=-1e9,Min=1e9+1;
  string s,t,u;
  bool ok = false;
  cin >> h >> w; 
  VS grid(h);
  rep(i,h) cin >> grid[i];
  const int dx[] = {0,1,0,-1}, dy[] = {1,0,-1,0}; //移動する方向
  
  rep(k,h){
    rep(j,w){
      if(grid[k][j] == '#') continue;

      VII ans(h,VI(w,-1));
      queue<pair<int,int>> que;
      ans[k][j]=0;  
      que.push(make_pair(k,j));
      while(!que.empty()){
        auto q = que.front(); que.pop();
        int nx = q.first, ny = q.second;
        rep(i,4){
            int x = nx + dx[i], y = ny + dy[i];
            if(x>=0 && x<h && y>=0 && y<w && grid[x][y] == '.' && ans[x][y] == -1){
              ans[x][y] = ans[nx][ny] + 1;
              que.push(make_pair(x,y));
              chmax(Max,ans[x][y]);
            }
            
        }
      }
    }
  }
  cout << Max << endl;
  return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
#include<stdlib.h>
#include<string.h>



int main()
{
	int n, k;
	scanf("%d%d", &n, &k);
	if (k == 1)
	{
		printf("0\n");
	}
	else {
		printf("%d\n",(n-k+1)-1 );
	}

	return 0;
}

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

int main(void) {
  ll N;
  cin >> N;
  REP(_, 0, N) {
    ll n = 0;
    vector<ll> A;
    while(1) {
      ll x; cin >> x;
      if(x == 0) break;
      if(x > 0) n++;
      A.push_back(x);
    }

    vector<vector<ll>> E(n);
    vector<pll> stk;
    ll idx = 0;
    REP(i, 0, A.size()) {
      if(A[i] > 0) {
        stk.push_back(pll(idx++, A[i]));
        if(stk.size() > 1) {
          ll u = stk[stk.size() - 2].first, v = stk[stk.size() - 1].first;
          E[u].push_back(v);
          E[v].push_back(u);
          stk[stk.size() - 1].second--;
          stk[stk.size() - 2].second--;
        }
      } else {
        ll u = stk[stk.size() - 1].first, v = stk[stk.size() - 1 + A[i]].first;
        E[u].push_back(v);
        E[v].push_back(u);
        stk[stk.size() - 1].second--;
        stk[stk.size() - 1 + A[i]].second--;
      }
      while(stk.size() > 0 && stk.back().second == 0) {
        stk.resize(stk.size() - 1);
      }
    }

    REP(i, 0, n) {
      sort(E[i].begin(), E[i].end());
      cout << i + 1;
      REP(j, 0, E[i].size()) cout << " " << E[i][j] + 1;
      cout << endl;
    }
  }
}


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

#define fast                     ios::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define int                      long long 
#define mk                       make_pair
#define pb                       push_back
#define pob                      pop_back
#define pii                      pair<int,int>
#define vi                       vector<int>
#define vii                      vector<pii>
#define mi                       map<int,int>
#define mii                      map<pii,int>
#define all(a)                   (a).begin(),(a).end()
#define x                        first
#define y                        second
#define sz(x)                    (int)x.size()
#define endl                     '\n'
#define MOD                      1000000007
#define loop(i,a,b)              for(int (i)=(a);(i)<(b);(i)++)
#define rloop(i,a,b)             for(int (i)=(a);(i)>=(b);(i)--)
#define Unique(A)                (A).resize(distance((A).begin(),unique(all((A)))));
#define mxe(A)                   *max_element(all(A))
#define mne(A)                   *min_element(all(A))
#define debv(x)                  for(auto i : (x)) cout << i << ' ';cout << endl;
#define SP(x,y)                  cout << fixed << setprecision((y)) << (x) << endl;
#define setBits(x)               __builtin_popcountll(x)
#define zroBits(x)               __builtin_ctzll(x)
#define trace1(x)                cerr<<#x<<": "<<x<<endl
#define trace2(x, y)             cerr<<#x<<": "<<x<<" | "<<#y<<": "<<y<<endl
#define trace3(x, y, z)          cerr<<#x<<": "<<x<<" | "<<#y<<": "<<y<<" | "<<#z<<": "<<z<<endl
#define trace4(a, b, c, d)       cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<endl
#define trace5(a, b, c, d, e)    cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<" | "<<#e<< ": "<<e<<endl
#define trace6(a, b, c, d, e, f) cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<" | "<<#e<< ": "<<e<<" | "<<#f<<": "<<f<<endl
#define Max(x,y,z)               max(x,max(y,z))
#define Min(x,y,z)               min(x,min(y,z))
#define clr(x)                   memset(x,0,sizeof(x)) // not sure work for 2D arrya or not

using namespace std;

const int N = 1100000 , inf = 1e18l + 10;
int v[110],w[110],dp[2][N];

int32_t main(){
    int a , b; cin >>a >> b; 
    loop(i,0,a) cin >> w[i] >> v[i];
    loop(i,1,N) dp[0][i] = inf;

    loop(i,1,a+1){
        int ii = i%2;
        loop(j,0,N) dp[ii][j] = inf;
        loop(j,0,N){
            dp[ii][j] = min(dp[ii][j],dp[!ii][j]);
            if(j-v[i-1]>=0) 
                dp[ii][j] = min(dp[ii][j],dp[!ii][j-v[i-1]]+w[i-1]);
        }
    }
    int ans = 0 ;
    loop(i,0,N) if(dp[a%2][i]<=b) ans = i;
    cout << ans << endl;
    return 0;
}

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

typedef long long int ll;

ll f[10005];

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

	ll i,j,t,k,l,m,n,c,r,d;

	cin >> n;

	for(i=1;i<105;i++)
	{
		for(j=1;j<105;j++)
		{
			for(k=1;k<105;k++)
			{
				l = i*i+j*j+k*k+k*j+j*i+k*i;

				if(l < 10005)
					f[l]++;
			}
		}
	}

	for(i=1;i<=n;i++)
		cout << f[i] << '\n';

	

	
	

}

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

#define rp(i, k, n) for (int i = k; i < n; i++)
typedef long long ll;
typedef double ld;



template<class T>inline bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>inline bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
const ll INF = 1ll << 60;
const ll MOD = 1e9 + 7ll;
const double PI=3.14159265358979323846;

int main() {
    int N, K;
    cin >> N >> K;
    vector<ld> p;
    rp(i, 0, N) {
        ld pi;
        scanf("%lf", &pi);
        p.emplace_back((pi+1.0) / 2.0);
    }
    ld sum = 0;
    ld res = 0;
    rp(i, 0, K) {
        sum += p.at(i);
    }
    res = sum;
    for(int i = 0; i + K < N; i++){
        sum -= p.at(i);
        sum += p.at(i+K);
        chmax(res, sum);
    }
    printf("%.10lf\n", res);
    return 0;
}

Measured memory_bytes: 5408
#include<iostream>
#include<algorithm>
#include<string>
using namespace std;
typedef long long ll;
int main() {
	string s; cin >> s;
	int f = 0, cnt = 0;
	while (s.size() > f) {
		if (s[f] == s.back()) {
			f++;
			s.pop_back();
		}
		else {
			if (s[f] == 'x') f++;
			else if (s.back() == 'x')s.pop_back();
			else {
				cout << "-1\n";
				return 0;
			}
			cnt++;
		}
	}
	cout << cnt << endl;
	char ch; cin >> ch;
}

Measured memory_bytes: 512
inp1 = int(input())
inp2 = int(input())

if(inp1 != 1 and inp2 != 1):
  	print(str(1))

if(inp1 != 2 and inp2 != 2):
  	print(str(2))

if(inp1 != 3 and inp2 != 3):
	print(str(3))



Measured memory_bytes: 2940
from math import sqrt
n,d = input().split()
n = int(n)
d = int(d)
count=0
for i in range(0,n):
  p,q = input().split()
  p = int(p)
  q = int(q)
  res = sqrt((p**2)+(q**2))
  if res<=d:
    count += 1
print(count)

Measured memory_bytes: 9216
import java.util.Scanner;

public class Main {

  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int num = sc.nextInt();
    int[] myArgs = new int[num];
    for (int i = 0;i < myArgs.length;i++) {
      myArgs[i] = sc.nextInt();
    }

    Main logic = new Main();
    String output = logic.exec(myArgs);
    System.out.print(output);
  }

  private String exec(int[] myArgs) {
    long limit = 0;
    for (int i = 0;i < myArgs.length;i++) {
      limit += myArgs[i] - 1;
    }
    return String.valueOf(limit);
  }
}


Measured memory_bytes: 26032
import java.util.Scanner;
 
public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int s,m,h;
        s = sc.nextInt();
        h = s / 3600;
        m = (s%3600) / 60;
        s = s % 60;
        System.out.println(h + ":" + m + ":" + s);
        sc.close();
    }
}


Measured memory_bytes: 26216
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<cmath>
#include<cstdlib>
#include<tuple>
#define int long long
using namespace std;

signed main() {
	int N,M;
	cin >> N >> M;
	vector<pair<int,int>> vec(N);
	for(int i = 0;i < N;i++) {
		int A,B;
		cin >> A >> B;
		vec.at(i) = make_pair(A,B);
	}
	sort(vec.begin(),vec.end());
	int answer = 0;
	for(int i = 0;i < N;i++) {
		if(M <= vec[i].second) {
			answer += M * vec[i].first;
			break;
		}
		answer += vec[i].first * vec[i].second;
		M -= vec[i].second;
	}
	cout << answer << endl;
}

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

int main(void)
{
    int ans=0;
    int N;
    int a,b;
    char str[10];
    int count[10][10]; //頭、末尾の組み合わせごとの個数を数える
    int atama,matubi;

    for(int i=0;i<10;i++){
        for(int j=0;j<10;j++){
            count[i][j] =0;
        }
    }

    scanf("%d",&N);

    for(int i=1;i<=N;i++){
        sprintf(str,"%d",i);
        atama = str[0]-'0';
        matubi = i%10;
        count[atama][matubi]++;
    }

    for(int i=1;i<=N;i++){
        sprintf(str,"%d",i);
        atama = str[0]-'0';
        matubi = i%10;

        ans += count[matubi][atama];
    }

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

    return 0;

    for(int i=0;i<10;i++){
        for(int j=0;j<10;j++){
            printf("%d ",count[i][j]);
        }
        printf("\n");
    }

    return 0;
}

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

int main(){
	int i,j,k,n,m,l,f,x,y,z; string s;
	cin >> n;
	int v[100010];

	rep(i, n) cin >> v[i];

	int odd[100010]  = {0};
	int even[100010] = {0};

	rep(i, n){
		//odd
		if(i % 2 == 0){
			odd[v[i] - 1] += 1;
		}else{
			even[v[i] -1] += 1;
		}
	}

	int odd_1, odd_2, even_1, even_2;

	odd_1  = 0;
	odd_2  = 0;
	even_1 = 0;
	even_2 = 0;

	rep(i,100000){
		if(odd_1 < odd[i]){
			odd_2 = odd_1;
			odd_1 = odd[i];
			
			x = i;
		}else if(odd_2 < odd[i]){
			odd_2 = odd[i];
		}
		if(even_1 < even[i]){
			even_2 = even_1;
			even_1 = even[i];
			
			y = i;
		}else if(even_2 < even[i]){
			even_2 = even[i];
		}
	}

	//cout << "odd_1: " << odd_1 << endl << "even_1: " << even_1 << endl << "x: " <<  x << endl << "y: " << y << endl << "odd_2: " << odd_2 << endl << "even_2: " << even_2 << endl;;

	if(x == y){
		cout << min(n - odd_1 - even_2, n - even_1 - odd_2);
	}else{
		cout << n - odd_1 - even_1 << endl;
	}

}

Measured memory_bytes: 1408
#include<iostream>
#include<vector>
#include<queue>
#include<string>
#define rep(i,n) for (int i = 0; i < n; i++)
using namespace std;
using ll = long long;
using P = pair<int,int>;

int main() {
  ll n,m;
  cin >> n >> m;
  vector<ll> h(n);
  rep(i,n) cin >> h[i];
  vector<ll> k(n);

  rep(i,m) {
    ll a,b;
    cin >> a >> b;

    if (h[a-1] > h[b-1]) {
      k[b-1]--;
    }else if(h[a-1] < h[b-1]) {
      k[a-1]--;
    }else {
      k[a-1]--;
      k[b-1]--;
    }

  }

  ll ans =0;
  rep(i,n) {
    if (k[i] == 0) ans++;
  }  
  
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 4408
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)*}
    };

    ($next:expr, mut $var:ident : $t:tt $($r:tt)*) => {
        let mut $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, [ $t:tt ]) => {
        {
            let len = read_value!($next, usize);
            (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_imports)]
use std::cmp::{min, max};

fn main() {
    input!{
        n: usize,
        k: usize,
        es: [(usize1, usize1); n - 1]
    }
    let mut t = vec![vec![]; n];
    for &(a, b) in &es {
        t[a].push(b);
        t[b].push(a);
    }
    let mut ans = n;
    if k % 2 == 0 {
        for i in 0..n {
            ans = min(ans, dfs(i, i, k / 2, &t));
        }
    } else {
        for &(a, b) in &es {
            ans = min(ans, dfs(b, a, k / 2, &t) + dfs(a, b, k / 2, &t))
        }
    }
    println!("{}", ans);
}

fn dfs(v: usize, p: usize, d: usize, t: &Vec<Vec<usize>>) -> usize {
    let mut ret = 0;
    for &c in &t[v] {
        if c == p {
            continue;
        }
        if d > 0 {
            ret += dfs(c, v, d - 1, t);
        } else {
            ret += 1 + dfs(c, v, 0, t);
        }
    }
    ret
}


Measured memory_bytes: 4476
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define REP(i,m,n) for(int i=(int)(m); i<(int)(n); i++)
#define rep(i,n) REP(i,0,n)
const int inf = 1e9+7;
const ll longinf = 1LL<<60;
const ll mod = 1e9+7;

int main() {
  int N;
  cin >> N;
  int a[100];
  int b[100];
  int c[100];
  for(int i=0; i < N; i++) {
    cin >> a[i];
  }
    for(int i=0; i < N; i++) {
    cin >> b[i];
  }
  for(int i=0; i < N-1; i++) {
    cin >> c[i];
  }

  // for(int i=0; i < N; i++) {
  //   cout << a[i] << endl;
  // }

  // for(int i=0; i < N; i++) {

  //   cout << b[i] << endl;

  // }
  // for(int i=0; i < N-1; i++) {
  //   cout << c[i] << endl;
  // }


  int m = 0; // manzoku
  int pre_food = -2;
  for(int i=0; i < N; i++) {
    m = m + b[a[i]-1];
    if (a[i] == pre_food + 1) {
      m = m + c[a[i]-2];
    }
    pre_food = a[i];
    // cout  << a[i] << endl;
    // cout << c[a[i]] << endl;
  }

  cout << m << endl;

  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
const int maxn = 1e5 + 5;
int n;
int a[maxn];
multiset<int> p;
int main() {
    scanf("%d",&n);
    for(int i=1;i<=n;i++) scanf("%d",&a[i]);
    int d = 0;
    for(int i=1;i<=n;i++) d = max(d, a[i]);
    for(int i=1;i<=n;i++) p.insert(a[i]);
    if(d%2==0) {
        for(int i=d/2+1;i<=d;i++) {
            if(p.find(i)==p.end()) return !printf("Impossible");
            else p.erase(p.find(i));
        }
        for(int i=d/2;i<=d;i++) {
            if(p.find(i)==p.end()) return !printf("Impossible");
            else p.erase(p.find(i));
        }
        for(auto t : p) {
            if(t<=d/2) return !printf("Impossible");
        }
    }
    else {
        for(int i=d/2+1;i<=d;i++) {
            if(p.find(i)==p.end()) return !printf("Impossible");
            else p.erase(p.find(i));
        }
        for(int i=d/2+1;i<=d;i++) {
            if(p.find(i)==p.end()) return !printf("Impossible");
            else p.erase(p.find(i));
        }
        for(auto t : p) {
            if(t<=d/2+1) return !printf("Impossible");
        }
    }
    printf("Possible");
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

using namespace std;
using namespace __gnu_pbds;

typedef long long ll;
typedef pair<ll,ll> ii;
typedef vector<ll> vi;
typedef long double ld;
typedef tree<ll, null_type, less<ll>, rb_tree_tag, tree_order_statistics_node_update> pbds;

#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define fbo find_by_order
#define ook order_of_key
#define INF (ll)1e18
#define PI (ld)3.14159265358979323846
#define print(a); for(auto x:a)cout<<x<<" "; cout<<"\n";
#define mset(a); memset(a,0,sizeof(a));

int main(){
	ios_base::sync_with_stdio(0);cin.tie(0);
    ll n;cin>>n;
    ll arr[n+1];
    ll sum=0;
    for(int i=0;i<=n;i++){
        cin>>arr[i];
        sum+=arr[i];
    }
    ll he[n];
    for(int i=0;i<n;i++){
        cin>>he[i];
    }
    for(int i=0;i<n;i++){
        if(he[i]<=arr[i])arr[i]-=he[i];
        else{
            he[i]-=arr[i];
            arr[i+1]=max(0ll,arr[i+1]-he[i]);
            arr[i]=0;
        }
    }
    for(int i=0;i<=n;i++){
        sum-=max(0ll,arr[i]);
    }
    cout<<sum<<"\n";
}


Measured memory_bytes: 1792
#include <algorithm>
#include <stdio.h>
#include <math.h>
#include <string>
#include <iostream>
#include <vector>
#include <iomanip>
using namespace std;

int m;
const int NMAX = 100010;

int dp[NMAX];
vector <int> adia[NMAX];
int ans[NMAX];

void dfs(int nod, int tata)
{
    dp[nod] = 1;
    for (auto i : adia[nod]) {
        if (i == tata)
            continue;
        dfs(i, nod);
        dp[nod] = 1LL * dp[nod] * (dp[i] + 1) % m;
    }
}

void dfsup(int nod, int tata, int modstata)
{
    if (tata)
        adia[nod].erase(find(adia[nod].begin(), adia[nod].end(), tata));

    ans[nod] = 1LL * dp[nod] * modstata % m;

    vector <int> vl(adia[nod].size()), vr(adia[nod].size());

    for (int i = 0; i < vl.size(); i++) {
        vl[i] = dp[adia[nod][i]] + 1;
        vr[i] = dp[adia[nod][i]] + 1;

        if (i)
            vl[i] = 1LL * vl[i] * vl[i - 1] % m;
    }

    for (int i = (int)vr.size() - 2; i >= 0; i--)
        vr[i] = 1LL * vr[i] * vr[i + 1] % m;

    for (int i = 0; i < adia[nod].size(); i++) {
        int oth = 1;
        if (i)
            oth = 1LL * oth * vl[i - 1] % m;
        if (i + 1 < vr.size())
            oth = 1LL * oth * vr[i + 1] % m;

        oth = 1LL * oth * modstata % m;

        dfsup(adia[nod][i], nod, (oth + 1) % m);
    }
}

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

    for (int i = 1; i < n; i++) {
        scanf("%d%d", &a, &b);

        adia[a].push_back(b);
        adia[b].push_back(a);
    }

    dfs(1, 0);
    dfsup(1, 0, 1);

    for (int i = 1; i <= n; i++)
        printf("%d\n", ans[i]);

    return 0;
}


Measured memory_bytes: 17664
import java.io.*;
import java.nio.CharBuffer;
import java.util.NoSuchElementException;

public class Main {

    public static void main(String[] args) {
        SimpleScanner scanner = new SimpleScanner(System.in);
        PrintWriter writer = new PrintWriter(System.out);

        final int MOD = 1000000007;
        int n = scanner.nextInt();
        int k = scanner.nextInt();
        int m = Math.max(k - 1, n - k + 1);
        int[][] c = new int[m + 1][m + 1];
        c[0][0] = 1;
        for (int i = 1; i <= m; ++i) {
            c[i][0] = 1;
            for (int j = 1; j <= i; ++j) {
                c[i][j] = (c[i - 1][j - 1] + c[i - 1][j]) % MOD;
            }
        }
        for (int i = 1; i <= k; ++i)
            writer.println(i <= n - k + 1 ? (long) c[k - 1][i - 1] * c[n - k + 1][i] % MOD : 0);

        writer.close();
    }

    private static class SimpleScanner {

        private static final int BUFFER_SIZE = 10240;

        private Readable in;
        private CharBuffer buffer;
        private boolean eof;

        SimpleScanner(InputStream in) {
            this.in = new BufferedReader(new InputStreamReader(in));
            buffer = CharBuffer.allocate(BUFFER_SIZE);
            buffer.limit(0);
            eof = false;
        }


        private char read() {
            if (!buffer.hasRemaining()) {
                buffer.clear();
                int n;
                try {
                    n = in.read(buffer);
                } catch (IOException e) {
                    n = -1;
                }
                if (n <= 0) {
                    eof = true;
                    return '\0';
                }
                buffer.flip();
            }
            return buffer.get();
        }

        void checkEof() {
            if (eof)
                throw new NoSuchElementException();
        }

        char nextChar() {
            checkEof();
            char b = read();
            checkEof();
            return b;
        }

        String next() {
            char b;
            do {
                b = read();
                checkEof();
            } while (Character.isWhitespace(b));
            StringBuilder sb = new StringBuilder();
            do {
                sb.append(b);
                b = read();
            } while (!eof && !Character.isWhitespace(b));
            return sb.toString();
        }

        int nextInt() {
            return Integer.valueOf(next());
        }

        long nextLong() {
            return Long.valueOf(next());
        }

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

Measured memory_bytes: 52052