akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
using namespace std;

int extgcd(int a, int b, int &x, int &y){
    int g = a;
    x = 1, y = 0;
    if(b != 0){
        g = extgcd(b, a%b, y, x);
        y -= (a / b) * x;
    }
    return g;
}

int main(){
    int a, b, x, y, g;
    cin >> a >> b;
    g = extgcd(a, b, x, y);
    cout << x << " " << y << endl;
    return 0;
}





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

int main()
{
	int64_t n, m;
	cin >> n >> m;
	vector<int64_t> as(n), bs(m), cs(m);
	for (auto &a : as)
	{
		cin >> a;
	}
	for (int64_t i = 0; i < m; i++)
	{
		cin >> bs[i] >> cs[i];
	}

	vector<pair<int64_t, int64_t>> ds(m);
	for (int64_t i = 0; i < m; i++)
	{
		ds[i] = {cs[i], bs[i]};
	}
	sort(ds.begin(), ds.end());
	reverse(ds.begin(), ds.end());

	sort(as.begin(), as.end());

	for (int64_t i = 0, j = 0; i < n && j < m; i++)
	{
		if (as[i] < ds[j].first)
		{
			as[i] = ds[j].first;
			ds[j].second--;
		}

		if (ds[j].second == 0)
		{
			j++;
		}
	}

	cout << accumulate(as.begin(), as.end(), int64_t(0)) << endl;

	return 0;
}

Measured memory_bytes: 4224
n = int(input())
a = list(map(int, input().split()))
sum_a = sum(a)
sum_a2 = sum(a[0::2] * 2)
y1 = sum_a2 - sum_a
ans = [str(y1)]
cy = y1
for ai in a:
    yi = ai * 2 - cy
    ans.append(str(yi))
    cy = yi
print(" ".join(ans[:-1]))


Measured memory_bytes: 18124
def check(string):
    reversed_string = list(reversed(string))
    if list(string) == reversed_string:
        return True
    else:
        return False

def main():
    S = input()
    N = len(S)

    part1 = S[:int((N-1)/2)]
    part2 = S[int((N+3)/2)-1:]

    if check(S) and check(part1) and check(part2):
        print('Yes')
    else:
        print('No')

if __name__ == '__main__':
    main()

Measured memory_bytes: 3064
#include <iostream>
#include <iomanip>
#include <cmath>
#include <string>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <numeric>
#include <random>
#include <algorithm>
#include <functional>

using namespace std;
typedef long long ll;

const int INF = (1 << 30) - 1;
const ll INFLL= (1LL << 61) - 1;
const int MOD = 1000000007;
#define ALL(a) (a).begin(),(a).end()
#define rALL(a) (a).rbegin(),(a).rend()
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) FOR(i,0,n)

int main(){
  cin.tie(nullptr);
  ios::sync_with_stdio(false);
  int N;
  cin>>N;
  vector<int> A(N),B(N),C(N);
  REP(i,N)cin>>A[i];
  REP(i,N)cin>>B[i];
  REP(i,N)cin>>C[i];
  sort(ALL(A));sort(ALL(B));sort(ALL(C));
  ll ans=0;

  REP(i,N){
    ll a=lower_bound(ALL(A),B[i])-A.begin();
    ll c=C.end()-upper_bound(ALL(C),B[i]);
    ans+=a*c;
  }
  cout<<ans<<endl;
}


Measured memory_bytes: 1408
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define mp make_pair
#define pb push_back
#define rep(i,n) for(int i=0;i<n;i++)
#define rep1(i,n) for(int i=1;i<=(int)(n);i++)

int main(){

  int x;
  cin >> x;
  if(x==3 || x==5 || x==7) cout << "YES" << endl;
  else cout << "NO" << endl;
  
  return 0;

}


Measured memory_bytes: 256
//参考：http://ehafib.hatenablog.com/entry/2015/12/23/164517
//インクルード
#include<algorithm>//sort,二分探索,など
#include<bitset>//固定長bit集合
#include<cmath>//pow,logなど
#include<complex>//複素数
#include<deque>//両端アクセスのキュー
#include<functional>//sortのgreater
#include<iomanip>//setprecision(浮動小数点の出力の誤差)
#include<iostream>//入出力
#include<map>//map(辞書)
#include<numeric>//iota(整数列の生成),gcdとlcm(c++17)
#include<queue>//キュー
#include<set>//集合
#include<stack>//スタック
#include<string>//文字列
#include<unordered_map>//イテレータあるけど順序保持しないmap
#include<unordered_set>//イテレータあるけど順序保持しないset
#include<utility>//pair
#include<vector>//可変長配列

using namespace std;
typedef long long ll;

//マクロ
#define REP(i,n) for(ll i=0;i<(ll)(n);i++)
#define REPD(i,n) for(ll i=(ll)(n)-1;i>=0;i--)
#define FOR(i,a,b) for(ll i=(a);i<=(b);i++)
#define FORD(i,a,b) for(ll i=(a);i>=(b);i--)
#define ALL(x) (x).begin(),(x).end() //sortなどの引数を省略したい
#define SIZE(x) ((ll)(x).size()) //sizeをsize_tからllに直しておく
#define MAX(x) *max_element(ALL(x))
#define INF 1000000000000
#define MOD 10000007
#define PB push_back
#define MP make_pair
#define F first
#define S second

float float_max(float a, float b) {
  return (a>b)?a:b;
}

float float_min(float a, float b) {
  return (a < b) ? a:b;
}

int main(int argc, char const *argv[]) {
  float a, b;
  ll _min, _max;
  float min_a, min_b, max_a, max_b;
  float max_, min_;
  std::cin >> a >> b;

  min_a = (25./2.) * float(a);
  max_a = (25./2.) * float(a + 1);

  min_b = 10. * float(b);
  max_b = 10. * float(b + 1);

  max_ = float_min(max_a, max_b);
  min_ = float_max(min_a, min_b);

  _min = int(min_ + 0.5);
  _max = int(max_);

  if (_min >= _max) {
    std::cout << "-1" << '\n';
  } else {
    std::cout << _min << '\n';
  }
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <string>
#include <list>
#include<vector>
#include <sstream>
#include <stdio.h>
#include <valarray>
#include <iomanip>
#include <unordered_set>
#include <set>
using namespace std;

int main(void)
{
	char s;
	cin >> s;

	if (isupper(s))
	{
		cout << "A" << endl;
		return 0;
	}
	cout << "a" << endl;

	return 0;
}

Measured memory_bytes: 3072
from collections import defaultdict
import sys

h,w=map(int,input().split())
costs=[]
for _ in range(10):
  costs.append(list(map(int,input().split())))
dd=defaultdict(lambda:0)
for i in map(int,sys.stdin.read().split()):
  dd[i]+=1
  
min_costs=[0]*10
for y in range(10):
  min_costs[y]=costs[y][1]

for _ in range(100):
  for x in range(10):
    for y in range(10):
      min_costs[y]=min(min_costs[y], min_costs[x]+costs[y][x])

ans=0
for i in range(10):
  ans+=dd[i]*min_costs[i]
print(ans)


Measured memory_bytes: 12376
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int main(){
    int n;
    cin>>n;
    string s;
    map <string, ll> anagram;
    for(int i=0;i<n;i++){
        cin>>s;
        sort(s.begin(),s.end());
        anagram[s]++;
    }
    ll cnt=0;
    for(auto x: anagram){
        cnt+=(x.second)*(x.second-1)/2;
    }
    cout<<cnt;
    return 0;
}

Measured memory_bytes: 11136
N, D, A = gets.split.map(&:to_i)
XH = N.times.map { gets.split.map(&:to_i) }

sorted = XH.sort_by { |x, _| x }
sub_count = Array.new(N, 0)
count = 0
ans = 0
N.times do |i|
  x, h = sorted[i]
  count -= sub_count[i]
  sum = count * A
  rest = h - sum
  next if rest <= 0
  add_count = (rest + A - 1) / A
  count += add_count
  j = sorted.bsearch_index do |y, _|
    y > x + 2 * D 
  end
  sub_count[j] += add_count if j
  ans += add_count
end
puts ans

Measured memory_bytes: 22520
#include <bits/stdc++.h>
#include <atcoder/all>

using namespace std;
using namespace atcoder;
typedef long long ll;
const static ll INF = 1e15;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
// __uint128_t
const ll MOD = 998244353;

 
ll op(ll a, ll b) {
    return max(a, b);
}
 
ll e() {
    return 0;
}


int main(){
    ll N, K; cin >> N >> K;
    ll MAX = 0;
    vector<ll> V(N); for(int i = 0; i < N; i++) {
        cin >> V[i];
        MAX = max(V[i]+1, MAX);
    }
    segtree<ll, op, e> seg(MAX);
    //cout << seg.prod(1, 10) << endl;
    
    for(int i = 0; i < N; i++){
        ll l = max(0LL, V[i]-K);
        ll r = min(MAX, V[i]+K+1);
        ll x = seg.prod(l, r);
        seg.set(V[i], x+1);
    }
    cout << seg.prod(1, MAX) << endl;
}


Measured memory_bytes: 16228
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define inf 999999999999
#define N 666666
int arr[N];
map<int,int> vis;
signed main(){
	int n;cin>>n;
	for(int i=1;i<=n;i++) cin>>arr[i];
	int ans=1;
	vis[arr[1]]=1;
	int minx=arr[1];
	for(int i=2;i<=n;i++){
		if(arr[i]>minx){
			continue;
		} else{
			ans++;
			minx=min(minx,arr[i]);
		}
	}
	cout<<ans;
	return 0;
}

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


int N; ll W;
vector<ll> v,w;
vector<pair<ll,ll>> ps;

int main() {
  cin >>N >>W;
  v.assign(N, 0); w.assign(N, 0); rep(i, N) cin >>v[i] >>w[i];
  int n2 = N/2;
  ps.assign(1 << n2, {0,0});
  rep(i, 1 << n2){
    ll sv = 0, sw = 0;
    rep(j, n2){
      if ((i >> j) & 1){
        sv += v[j]; sw += w[j];
      }
    }
    ps[i] = {sw, sv};
  }
  sort(all(ps));
  // いらんやつらは端へ寄せて不要
  int m = 1; // いるやつらの配列の長さ
  for (int i=1; i<1 << n2; i++){
    if (ps[m-1].second < ps[i].second){
      ps[m++] = ps[i];
    }
  }

  ll res = 0;
  rep(i, 1 << (N-n2)){
    ll sv = 0, sw = 0;
    rep(j, N-n2){
      if ((i >> j) & 1){
        sv += v[n2+j]; sw += w[n2+j];
      }
    }
    if (sw > W) continue;
    ll tv = (lower_bound(ps.begin(), ps.begin() + m, make_pair(W-sw, INF)) - 1) -> second;
    chmax(res, sv + tv);
  }
  cout <<res <<endl;
}



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

#define MOD 1000000007
typedef pair<int,int> pi;
typedef long long ll;

double dist = 0;

double calc_dist(int x1, int y1, int x2, int y2)
{
    double val = sqrt((x1-x2)*(x1-x2) + (y1-y2)*(y1-y2));
    return val;
}

void permutation(vector<pi>&v, int size)
{
    if(size == 1)
    {
        for(int i=0; i<v.size()-1; i++)
            dist += calc_dist(v[i].first, v[i].second, v[i+1].first, v[i+1].second);
        return;
    }
    for(int i=0; i<size; i++)
    {
        permutation(v, size-1);
        if(size%2 == 0)
            swap(v[0], v[size-1]);
        else
            swap(v[i], v[size-1]);
    }
}

int factorial(int n)
{
    int val = 1;
    for(int i=1; i<=n; i++)
        val = val*i;
    return val;
}

int main()
{
    int n;
    cin>>n;
    vector<pi>v(n);
    for(int i=0; i<n; i++)
        cin>>v[i].first>>v[i].second;
    permutation(v, n);
    cout<<fixed<<setprecision(10)<<dist/factorial(n);

}



Measured memory_bytes: 256
import itertools
M, D = list(map(int, input().split()))

p = itertools.product(range(1, M+1), range(1, D+1))
c = 0
t_list = []
for m, d in p:
    d_10, d_1 = str(d).zfill(2)
    if int(d_10) == 1 or int(d_1) == 1:
        continue
    if m == int(d_10) * int(d_1):
        c += 1
        t_list.append((m, d_10, d_1))
print(c)

Measured memory_bytes: 3060
#include <iostream>
#include <climits>
#include <cmath>
using namespace std;

int main() {
	int n,k;
	cin>>n>>k;
	
	int arr[n];
	for(int i=0; i<n; i++) {
		cin>>arr[i];
	}
	
	int memo[n];
	for(int i=0; i<n; i++) {
		memo[i] = INT_MAX;
	}
	memo[0] = 0;

	for(int i=1; i<n; i++) {
		for(int j=1; j<=k; j++) {
			if(i-j >= 0) {
				memo[i] = min(memo[i], abs(arr[i] -arr[i-j]) + memo[i-j]);
			} else {
				memo[i] = memo[i];
			}
		}
	}
	
	cout<<memo[n-1];
	
	return 0;
}

Measured memory_bytes: 4368
#include <iostream>
#include <string>
#include <sstream>
#include <vector>
#include <cassert>
using namespace std;

int calc(vector<string> vec);

int main()
{
	//input
	vector<string> vec;
	while(1){
		string str;
		cin >> str;
		if(cin.eof()){
			break;
		}
		vec.push_back(str);
	}
	//calc
	int result = calc(vec);

	//output
	cout << result << endl;

	return 0;
}


//------------------------
//@func		calc
//@brif	
//input		??????????????????
//return	?¨??????????
//------------------------
int calc(vector<string> vec)
{
	vector<int> stack;
	
	for(int i =0; i < vec.size(); i++){
	//  cout << "i="<< i << "::" << vec[i] << endl;
		
		int res = 0;
		char c = vec[i][0];
		
		if(('0'<= c) && (c <= '9')){
			stack.push_back(stoi(vec[i]));
			continue;
		}
		int num1 = stack.back();
		stack.pop_back();
		int num2 = stack.back();
		stack.pop_back();
		
		switch(c){
			case '+':{
						res  = num1 + num2;
						stack.push_back(res);
						break;
					}
			case '-':{
						res  = num2 - num1;
						stack.push_back(res);
						break;
					}
			case '*':{
						res  = num1 * num2;
						stack.push_back(res);
						break;
					}
			case '/':{
						assert(num1 != 0);
						res  = num2 / num1;
						stack.push_back(res);
						break;
					}
			default:
				assert(false);
		}
	}
	return stack[0];
}

Measured memory_bytes: 3180
#include<stdio.h>


int a[100][100];
int b[100];
int time,n;
int d[100];
int c[100];


void visit(int u){
  int i;
  c[u] = 1;
  d[u] = ++time;
  for(i=0;i<n;i++){
    if(!a[u][i])continue;
    if(!c[i])visit(i);
  }
  c[u] = 2;
  b[u] = ++time;
}


void dfs(){
  int u;
  for(u=0;u<n;u++){
    c[u] = 0;
  }
  time = 0;
  for(u=0;u<n;u++){
    if(!c[u])visit(u);
  }
  for(u=0;u<n;u++){
    printf("%d %d %d\n",u+1,d[u],b[u]);
  }
}

int main(){
  int i,j,u,v,k;

  scanf("%d",&n);
  for(i=0;i<n;i++){
    for(j=0;j<n;j++){
      a[i][j] = 0;
    }
  }

  for(i=0;i<n;i++){
    scanf("%d%d",&u,&v);
    for(j=0;j<v;j++){
      scanf("%d",&k);
      a[u-1][k-1] = 1;
    }
  }

  dfs();
  return 0;
}



Measured memory_bytes: 2104
#include<bits/stdc++.h>
using namespace std;
int main(){
int r, c, w[101][101];
cin >> r >> c;
for( int i = 0; i < r; i++ )
 for( int j = 0; j < c; j++ ) cin >> w[i][j];
for( int i = 0; i <= r; i++ ) w[i][c] = 0;
for( int j = 0; j <= c; j++ ) w[r][j] = 0;

for ( int i = 0; i < r; i++ ){
 for ( int j = 0; j < c; j++ ){
  w[i][c] += w[i][j];
  w[r][j] += w[i][j];
  w[r][c] += w[i][j];
 }
}
for ( int i = 0; i <= r; i++ ){
 for ( int j = 0; j <= c; j++){
  if ( j ) cout << " ";
  cout << w[i][j];
 }
 cout << endl;
}
return 0;
}

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

namespace TYC
{
	typedef long long ll;

	const int N = 2e5 + 5, mod = 1e9 + 7;

	int n, m, cnt, A[N], B[N], R[N], X[N], Y[N], C[N];
	vector<int> P[N];

	inline int read()
	{
		int x = 0, f = 0, ch = getchar();
		while (!isdigit(ch))
			f |= (ch == '-'), ch = getchar();
		while (isdigit(ch))
			x = x * 10 + ch - '0', ch = getchar();
		return f ? -x : x;
	}

	void init()
	{
		int num = 0;
		for (int i = 1, j = 1; i <= n; i++)
			if (B[1] < A[i] && A[i] < B[m])
			{
				while (B[j + 1] <= A[i])
					j++;
				int x = A[i] - B[j], y = B[j + 1] - A[i];
				if (x && y)
				{
					R[++cnt] = X[++num] = x;
					R[++cnt] = Y[num] = y;
				}
			}
		sort(R + 1, R + 1 + cnt);
		cnt = unique(R + 1, R + 1 + cnt) - R - 1;
		for (int i = 1; i <= num; i++)
#define id(x) (lower_bound(R + 1, R + 1 + cnt, x) - R)
			P[id(X[i])].push_back(id(Y[i]));
#undef id
		for (int i = 1; i <= cnt; i++)
		{
			sort(P[i].begin(), P[i].end(), greater<int>());
			P[i].resize(unique(P[i].begin(), P[i].end()) - P[i].begin());
		}
		++cnt;
		P[cnt].push_back(cnt);
	}

#define lowbit(x) (x & (-x))

	inline int query(int x)
	{
		int sum = 0;
		for (; x; x -= lowbit(x))
			sum = (sum + C[x]) % mod;
		return sum;
	}

	inline void add(int x, const int v)
	{
		for (; x <= cnt; x += lowbit(x))
			C[x] = (C[x] + v) % mod;
	}

#undef lowbit

	void work()
	{
		n = read(), m = read();
		for (int i = 1; i <= n; i++)
			A[i] = read();
		for (int i = 1; i <= m; i++)
			B[i] = read();
		init();
		for (int i = 1; i <= cnt; i++)
			for (int p : P[i])
				add(p, (query(p - 1) + 1) % mod);	
		printf("%d\n", (query(cnt) - query(cnt - 1) + mod) % mod);
	}
}

int main()
{
	TYC::work();
	return 0;
}

Measured memory_bytes: 14160
use std::str::FromStr;
use std::fmt::Debug;
use std::cmp;

fn read_as_vec<T>() -> Vec<T>
where T: FromStr, <T as FromStr>::Err : Debug{
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).unwrap();
    s.trim().split_whitespace().map(|c| T::from_str(c).unwrap()).collect()

}

fn read_as_string() -> String{
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).unwrap();
    s.trim().to_string()
}

fn solve(takahashi: &Vec<char>, aoki: &Vec<char>, command: (char, char), limit: i32) -> (i32, i32){
    let mut safety: (i32, i32) = (0, limit-1);
    //println!("safety = {:?}", safety);
    for i in (0..aoki.len()).rev(){
        //aoki phase
        if aoki[i] == command.0{
            safety.1 = cmp::min(safety.1+1, limit-1);   
        }else if aoki[i] == command.1{
            safety.0 = cmp::max(safety.0-1, 0);
        }

        //takahashi phase
        if takahashi[i] == command.0{
            if safety.0 == limit-1{
                return (0, -1);
            }else{
                safety.0 = cmp::min(safety.0+1,limit-1);
            }
        }else if takahashi[i] == command.1{
            if safety.1 == 0{
                return (0, -1);
            }else{
                safety.1 = cmp::max(safety.1-1, 0);
            }
        }
    }
    safety
}

fn main(){
    let line: Vec<i32> = read_as_vec();
    let (h, w, n) = (line[0], line[1], line[2]);
    let line: Vec<i32> = read_as_vec();
    let (sr, sc) = (line[0], line[1]);

    let takahashi = read_as_string().chars().collect::<Vec<char>>();
    let aoki = read_as_string().chars().collect::<Vec<char>>();

    let ver_safety = solve(&takahashi, &aoki, ('U', 'D'), h);
    let hori_safety = solve(&takahashi, &aoki, ('L', 'R'), w);

    if ver_safety.0 <= sr-1 && sr-1 <= ver_safety.1 && hori_safety.0 <= sc-1 && sc-1 <= hori_safety.1{
        println!("YES");
    }else{
        println!("NO");
    }
 }


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

#define int long long
#define ci(m)     for(int i=0;i<m;i++)
#define cj(m)     for(int j=0;j<m;j++)
#define ck(m)     for(int k=0;k<m;k++)
#define gcd            __gcd
#define endl           "\n"
#define pb             emplace_back
#define setbits(x)     __builtin_popcountll(x)
#define zrobits(x)     __builtin_ctzll(x)
#define mod            1000000007
#define mod2           998244353
#define maxe           *max_element
#define mine           *min_element
#define inf            1e18
#define deci(x, y)      fixed<<setprecision(y)<<x
#define w(t)           int t; cin>>t; while(t--)
#define nitin          ios_base::sync_with_stdio(false); cin.tie(NULL)
#define PI             3.141592653589793238
using namespace std;

int32_t main() {
    nitin;
    string s;
    cin>>s;
    int ans=0;
    int cnt=0;
    for(int i=0;i<s.length();i++)
    {
        if(s[i]=='B')
            cnt++;
        else
            ans+=cnt;
    }
    cout<<ans<<endl;
    return 0;
}

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

#define mod 1000000007

// F_mod 上でのべき乗, 蟻本p115
ll modPow(ll x, ll n) {
    ll res = 1;
    while(n > 0){
        if(n & 1) res = res * x % mod;
        x = x * x % mod;
        n >>= 1;
    }
    return res;
}

// Fermat の小定理を用いた F_mod 上での逆元計算x^(mod-2)
inline ll Inverse(ll x){
    return modPow(x, mod - 2);
}

// iの階乗 = fact[i]
// fact_init(); を追加
#define MAX_FACT 300001
ll fact[MAX_FACT];
void fact_init(){
    fact[0]=1;
    for(int i = 1; i < MAX_FACT; ++i) {
        fact[i] = fact[i-1] * i % mod;
    }
}

ll nCk(int n, int k){
    if (n < k) return 0;

    //　n_C_kの計算, 蟻本p.263
    ll ans = fact[n] * Inverse(fact[k] * fact[n-k] % mod);
    ans %= mod;
    return ans;
}

#define MAX_N 400005
ll pow2[MAX_N];
void pow2_init(){
    pow2[0] = 1;
    for (int i = 1; i < MAX_N; ++i) {
        pow2[i] = pow2[i-1] * 2 % mod;
    }
}

int main() {
    pow2_init();
    fact_init();
    int N, K;
    cin >> N >> K;
    vector<ll>A(N);
    for (int i = 0; i < N; ++i) {
        cin >> A[i];
    }
    sort(A.begin(), A.end());
    ll ans = 0;
    for (int i = 0; i < N; ++i) {
        ans += nCk(i, K-1) * A[i] % mod;
        ans -= nCk(N-1-i, K-1) * A[i] % mod;
    }
    ans %= mod;
    cout << ans << "\n";
    return 0;
}

Measured memory_bytes: 6528
#include "bits/stdc++.h"

#define REP(i,n) for(ll i=0;i<ll(n);++i)
#define RREP(i,n) for(ll i=ll(n)-1;i>=0;--i)
#define FOR(i,m,n) for(ll i=m;i<ll(n);++i)
#define RFOR(i,m,n) for(ll i=ll(n)-1;i>=ll(m);--i)
#define ALL(v) (v).begin(),(v).end()
#define UNIQUE(v) v.erase(unique(ALL(v)),v.end());
#define DUMP(v) REP(aa, (v).size()) { cout << v[aa]; if (aa != v.size() - 1)cout << " "; else cout << endl; }
#define INF 1000000001ll
#define MOD 1000000007ll
#define EPS 1e-9

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


using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vi> vvi;
typedef vector<vl> vvl;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
ll max(ll a, int b) { return max(a, ll(b)); }
ll max(int a, ll b) { return max(ll(a), b); }
ll min(ll a, int b) { return min(a, ll(b)); }
ll min(int a, ll b) { return min(ll(a), b); }


int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	int n,m;
	cin >> n >> m;
	cout << (m * 1900 + (n - m) * 100)*pow(2, m) << endl;
}


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

namespace Flow {
    struct Edge {
        int to, capacity, cost, reverse;
        Edge(int to, int capacity, int cost, int reverse) :
            to(to), capacity(capacity), cost(cost), reverse(reverse) {}
    };
    template <int MaxN> class PrimalDual {
        int n = MaxN;
        vector<Edge> g[MaxN];
    public:
        void clear(int n) {
            this->n = n;
            for (int i = 0; i < n; ++i)
                g[i].clear();
        }
        void push(int from, int to, int capacity = 1, int cost = 0) {
            g[from].emplace_back(to, capacity, cost, g[to].size());
            g[to].emplace_back(from, 0, -cost, g[from].size() - 1);
        }
        pair<int, int> flow(int s, int t, int f = 1 << 30) {
            int flow = f, cost = 0;
            static int prevv[MaxN], preve[MaxN], dist[MaxN], h[MaxN];
            fill(h, h + n, 0);
            while (flow > 0) {
                fill(dist, dist + n, 1 << 30);
                dist[s] = 0;
                using P = pair<int, int>;
                priority_queue<P, vector<P>, greater<P>> q;
                for (q.emplace(0, s); q.size(); ) {
                    auto p = q.top();
                    q.pop();
                    int v = p.second;
                    if (dist[v] < p.first) continue;
                    for (auto& e : g[v]) {
                        int d = dist[v] + e.cost + h[v] - h[e.to];
                        if (e.capacity > 0 && dist[e.to] > d) {
                            dist[e.to] = d;
                            prevv[e.to] = v;
                            preve[e.to] = &e - &g[v][0];
                            q.emplace(d, e.to);
                        }
                    }
                }
                if (dist[t] == 1 << 30) break;
                for (int v = 0; v < n; ++v)
                    h[v] += dist[v];
                int d = flow;
                for (int v = t; v != s; v = prevv[v])
                    d = min(d, g[prevv[v]][preve[v]].capacity);
                flow -= d;
                cost += d * h[t];
                for (int v = t; v != s; v = prevv[v]) {
                    auto& e = g[prevv[v]][preve[v]];
                    e.capacity -= d;
                    g[v][e.reverse].capacity += d;
                }
            }
            return { f - flow, cost };
        }
    };
}

int main() {
    int n, m, f;
    cin >> n >> m >> f;
    Flow::PrimalDual<100> pd;
    pd.clear(n);
    for (int i = 0; i < m; ++i) {
        int a, b, c, d;
        cin >> a >> b >> c >> d;
        pd.push(a, b, c, d);
    }
    auto p = pd.flow(0, n - 1, f);
    cout << (p.first == f ? p.second : -1) << endl;
    return 0;
}

Measured memory_bytes: 3156
import numpy
import re
import math

def main():
	"""
	テストコード実行
	:return:
	"""
	h, w = map(int, input().split())
	src = [input() for i in range(h)]

	ans = []
	for row in src:
		ans.append(list(row))

	dxy = [(-1, -1), (-1, 0), (-1, 1), (0, 1), (0, -1), (1, -1), (1, 0), (1, 1)] #8近傍の位置
	for y in range(h):
		for x in range(w):
			if src[y][x] is "#": continue
			c = 0
			for dx, dy in dxy:
				if x + dx < 0 or x + dx > w - 1 or y + dy < 0 or y + dy > h - 1: continue #枠外の時
				if src[y + dy][x + dx] is "#": c += 1
			ans[y][x] = c
	for row in ans:
		print(''.join(list(map(str, row))))

if __name__ == '__main__':
	main()


Measured memory_bytes: 12504
// eddy1021
#include <bits/stdc++.h>
using namespace std;
typedef double D;
typedef long double LD;
typedef long long ll;
typedef long long LL;
typedef pair<int,int> PII;
typedef pair<LL,LL> PLL;
typedef pair<LD,LD> Pt;
typedef tuple<int,int,int> tiii;
typedef tuple<LL,LL,LL> tlll;
#define mod9 1000000009ll
#define mod7 1000000007ll
#define INF  1023456789ll
#define INF16 10000000000000000ll
#define FI first
#define SE second
#define X FI
#define Y SE
#define PB push_back
#define MP make_pair
#define MT make_tuple
#define eps 1e-9
#define SZ(x) (int)(x).size()
#define ALL(x) (x).begin(), (x).end()
#ifndef ONLINE_JUDGE
#define debug(...) printf(__VA_ARGS__)
#else 
#define debug(...)
#endif
inline ll getint(){
  ll _x=0,_tmp=1; char _tc=getchar();    
  while( (_tc<'0'||_tc>'9')&&_tc!='-' ) _tc=getchar();
  if( _tc == '-' ) _tc=getchar() , _tmp = -1;
  while(_tc>='0'&&_tc<='9') _x*=10,_x+=(_tc-'0'),_tc=getchar();
  return _x*_tmp;
}
inline ll add( ll _x , ll _y , ll _mod = mod7 ){
  ll _ = _x + _y;
  if( _ >= _mod ) _ -= _mod;
  return _;
}
inline ll sub( ll _x , ll _y , ll _mod = mod7 ){
  ll _ = _x - _y;
  if( _ < 0 ) _ += _mod;
  return _;
}
inline ll mul( ll _x , ll _y , ll _mod = mod7 ){
  ll _ = _x * _y;
  if( _ >= _mod ) _ %= _mod;
  return _;
}
ll mypow( ll _a , ll _x , ll _mod ){
  if( _x == 0 ) return 1ll;
  ll _tmp = mypow( _a , _x / 2 , _mod );
  _tmp = mul( _tmp , _tmp , _mod );
  if( _x & 1 ) _tmp = mul( _tmp , _a , _mod );
  return _tmp;
}
ll mymul( ll _a , ll _x , ll _mod ){
  if( _x == 0 ) return 0ll;
  ll _tmp = mymul( _a , _x / 2 , _mod );
  _tmp = add( _tmp , _tmp , _mod );
  if( _x & 1 ) _tmp = add( _tmp , _a , _mod );
  return _tmp;
}
inline bool equal( D _x ,  D _y ){
  return _x > _y - eps && _x < _y + eps;
}
int __ = 1 , _cs;
/*********default*********/
#define N 2222
void build(){

}
int n , k;
vector<int> v[ N ];
void init(){
  n = getint();
  k = getint();
  for( int i = 1 ; i < n ; i ++ ){
    int ai = getint();
    int bi = getint();
    v[ ai ].push_back( bi );
    v[ bi ].push_back( ai );
  }
}
int mx , cnt , sv[ N ];
int dfs( int now , int prt , int dep ){
  if( ( k % 2 ) && dep == ( k + 1 ) / 2 ){
    return sv[ now ] = 1;
  }
  if( dep > k / 2 ) return sv[ now ] = 0;
  cnt ++; sv[ now ] = 0;
  for( int son : v[ now ] ){
    if( son == prt ) continue;
    sv[ now ] += dfs( son , now , dep + 1 );
  }
  return sv[ now ];
}
inline int cal( int now ){
  cnt = 0;
  dfs( now , -1 , 0 );
  if( k % 2 ){
    int bst = 0;
    for( int son : v[ now ] )
      bst = max( bst , sv[ son ] );
    cnt += bst;
  }
  return cnt;
}
void solve(){
  mx = 1;
  for( int i = 1 ; i <= n ; i ++ )
    mx = max( mx , cal( i ) );
  printf( "%d\n" , n - mx );
}
int main(){
  build();
  //__ = getint();
  while( __ -- ){
    init();
    solve();
  }
}


Measured memory_bytes: 384
import fractions

N = int(input())
a = list(map(int,input().split()))

ans = 0

lf = [0]*N
rf = [0]*N

for i in range(1,N):
    lf[i] = fractions.gcd(lf[i-1],a[i-1])
    rf[i] = fractions.gcd(rf[i-1],a[-i])

ans = 0
for i in range(N):
    ans = max(ans,fractions.gcd(lf[i],rf[-i-1]))

print(ans)


Measured memory_bytes: 16148
#include <iostream>
#include <iomanip>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <algorithm>
#include <cstdio>
#include <utility>
#include <string>
#include <cmath>
#include <cstdlib>
#include <cstring>

using namespace std;

typedef uint64_t u64;
typedef int64_t s64;
typedef uint32_t u32;
typedef int32_t s32;
typedef vector<s32> vs32;
typedef vector<u32> vu32;
typedef vector<s64> vs64;
typedef vector<u64> vu64;

const double PI=3.14159265358979323846;

#define MAX(x, y) ((x) < (y) ? (y) : (x))
#define MIN(x, y) ((x) > (y) ? (y) : (x))

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

#define CEIL(x, y) (((x) + (y) - 1) / (y))
#define MOD 1000000007ULL

long long extGCD(long long a, long long b, long long &x, long long &y) {
    if (b == 0) {
        x = 1;
        y = 0;
        return a;
    }
    long long d = extGCD(b, a%b, y, x);
    y -= a / b * x;
    return d;
}

inline long long mod(long long a, long long m) {
    return (a % m + m) % m;
}

long long modinv(long long a, long long m) {
    long long x, y;
    extGCD(a, m, x, y);
    return mod(x, m); // 気持ち的には x % m だが、x が負かもしれないので
}

void comdiv(map<int, s64>& x, s64 y)
{
    map<int, s64> vy;
    for (int i = 2; i * i <= y; ++i)
    {
        s64 temp = 0;
        if (y % i == 0)
        {
            while (y % i == 0)
            {
                temp++;
                y /= i;
            }
            x[i] = MAX(x[i], temp);
        }
    }
    x[y] = MAX(x[y], 1);
}

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

    s64 N;
    s64 a;
    vs64 ainv;
    cin >> N;
    ainv.resize(N);
    map<int, s64> com;
    com[1] = 0;
    rep (i, N)
    {
        cin >> a;
        comdiv(com, a);
        ainv[i] = modinv(a, MOD);
    }

    s64 g = 1;
    for (auto mcom : com)
    {
        rep (i, mcom.second)
        {
            g *= mcom.first;
            g %= MOD;
        }
    }

    s64 ans = 0;
    rep (i, N)
    {
        ans += (g * ainv[i]) % MOD;
        ans %= MOD;
    }

    cout << ans << "\n";
    return 0;
}



Measured memory_bytes: 1024
// {{{
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cmath>
#include <complex>
#include <cstdint>
#include <cstdio>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <limits>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <tuple>
#include <utility>
#include <vector>
using namespace std;
// }}}

using ll = long long;

int main() {
    ll N, M; cin >> N >> M;
    if (N > M) swap(N, M);
    if (N == 1) {
        cout << (M == 1 ? 1 : max(0LL, M-2)) << endl;
    } else {
        cout << (N-2) * (M-2) << endl;
    }
    return 0;
}


Measured memory_bytes: 256
N = int(input())
Ai = list(map(int, input().split()))
l = []
for i in range(N):
  li = [i+1,Ai[i]]
  l.append(li)
  

l = sorted(l, key=lambda x: x[1])

#print(l)
ans = []
for j in range(len(l)):
  if(j!=len(l)):
    print(l[j][0], end=" ")
  else:
    print(l[j][0])


Measured memory_bytes: 23164
#include <iostream>
#include <string>
#include <vector>
#include <math.h>
#include <stdio.h>
#include <algorithm>
#include <utility>
#include <functional>
#include <map>
#include <queue>
#include <list>
#define rep(i,n) for(int i=0;i<(n);i++)
#define crep(i) for(char i='a';i<='z';i++)
#define psortsecond(A,N) sort(A,A+N,[](const pii &a, const pii &b){return a.second<b.second;});
#define psortfirst(A,N) sort(A,A+N,[](const pii &a, const pii &b){return a.first<b.first;});
#define All(x) (x).begin(),(x).end()
int ctoi(const char c){
  if('0' <= c && c <= '9') return (c-'0');
  return -1;
}
using namespace std;
using pii  = pair<int,int>;
long long gcd(long long a, long long b){return (b == 0 ? a : gcd(b, a%b));}
long long lcm(long long a, long long b){return a*b/gcd(a,b);}
typedef long long ll;
#define MOD 1e9
#define EPS 10e-8

int main(){
  char S[100007];
  cin >> S;
  int C=0;
  rep(i,strlen(S)-1){
    if(S[i]!=S[i+1]){
      C++;
    }
  }
  cout << C << endl;
}

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

int main(){
	int a,b,c,d;
  	cin >> a>>b>>c>>d;
	int s =a+b,t=c+d;
  	if(s>t)
		printf("Left\n");
	else if(s<t)
		printf("Right\n");
    else
		printf("Balanced\n");
}



Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include<cmath>
#define rep(i,n) for(int i = 0;i < (n);i++)
using namespace std;

int main(){
    int N,M;
    cin >> N >> M;
    
    int cnt[100001];
    rep(i,N){
        cnt[i] = 0;
    }
    int ans = 0;
    int res[100001];
    int p[100001];
    rep(i,M){
        string s;
        cin >> p[i];
        cin >> s;
        if(s == "AC"){
            if(cnt[p[i]] == 0){
                ans++;
                cnt[p[i]]++;
            }
        }
        else{
            if(cnt[p[i]] == 0){
                res[p[i]]++;
            }
        }
    }
    
    int pen = 0;
    rep(i,N){
        if(cnt[i+ 1] != 0){
            pen += res[i + 1];
        }
    }
    cout << ans << " "  << pen <<  endl;
}


Measured memory_bytes: 1408
#include <iostream>
#include <vector>
#include <string>
#include <queue>

using namespace std;

int main()
{
    uint32_t kk;
    uint64_t temp;
    cin >> kk;

    queue<uint64_t> q1;

    for(int l = 1; l < 10; l++){
        q1.push(l);
    }

    for(int i = 0; i < kk; i++){
        temp = q1.front();
        q1.pop();
        if(temp % 10)
            q1.push(10 * temp + (temp % 10) - 1);
        q1.push(10 * temp + (temp % 10));
        if(!((temp % 10) == 9))
            q1.push(temp * 10 + (temp % 10) + 1);
    }
    cout << temp << endl;

    return 0;
}

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

using namespace std;

int n, m;

int a[100001];
int u[100001];
int kol = 0;

int main () {
	cin >> n;
	for (int i = 1;i <= n;i ++) cin >> a[i];
	sort (a + 1, a + n + 1);
	for (int i = 1;i <= n;i ++) {
		u[a[i]] ++;
	}
	int len = a[n] + 1;
	for (int i = 1;i <= len;i ++) {
		int di = max (i - 1, len - i);
		if (!u[di]) {
			cout << "Impossible";
			return 0;
		}
		u[di] --;
	}
	for (int i = 1;i < (len / 2) + 1;i ++) {
		if (u[i]) {
			cout << "Impossible";
			return 0;
		}
	}
	cout << "Possible";
	return 0;
}

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

int main(){
    set<int> s;
    int n;cin>>n;
    int k=0;
    rep(i,n){
        int a;cin>>a;
        if(a>=3200)k++;
        else s.insert(a/400);
    }
    cout<<max((int)s.size(),1)<<' '<<k+s.size()<<endl;
    return 0;
}


Measured memory_bytes: 256
H, W = map(int, input().split())
campus = list(input() for i in range(H))


def check_around(x, y):
    if 0 < y and campus[y - 1][x] == '#':
        return True
    elif 0 < x and campus[y][x - 1] == '#':
        return True
    elif x < W - 1 and campus[y][x + 1] == '#':
        return True
    elif y < H - 1 and campus[y + 1][x] == '#':
        return True
    return False


can = True
for y in range(H):
    for x in range(W):
        if campus[y][x] == '#':
            can = check_around(x, y)
            if not can:
                print('No')
                exit()
print('Yes')


Measured memory_bytes: 3064
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <map>
using namespace std;
typedef long long  ll;
#define rep(i,s,n)for(ll i=s;i<n;i++)
#define repe(i,s,n)for(ll i=s;i<=n;i++)

int main() {
	ll n; cin >> n;
	ll a[100000] = {};
	ll maxV = 0;
	rep(i, 0, n) {
		cin >> a[i];
		maxV = max(maxV, a[i]);
	}

	ll index = 0;
	ll minV = 1e20;
	rep(i, 0, n) {
		if (a[i] != maxV) {
			if (minV > abs(maxV - 2 * a[i])) {
				minV = abs(maxV - 2 * a[i]);
				index = i;
			}
		}
	}
	cout << maxV << " " << a[index] << endl;

	return 0;
}

Measured memory_bytes: 1024
// #include {{{
#include <iostream>
#include <cassert>
#include <cstring>
#include <cstdlib>
#include <cstdio>
#include <cctype>
#include <cmath>
#include <ctime>
#include <queue>
#include <set>
#include <map>
#include <stack>
#include <string>
#include <bitset>
#include <vector>
#include <complex>
#include <algorithm>
using namespace std;
// }}}
// #define {{{
typedef long long ll;
typedef double db;
typedef pair<int,int> pii;
typedef vector<int> vi;
#define de(x) cout << #x << "=" << x << endl
#define rep(i,a,b) for(int i=a;i<(b);++i)
#define per(i,a,b) for(int i=(b)-1;i>=(a);--i)
#define all(x) (x).begin(),(x).end()
#define sz(x) (int)(x).size()
#define mp make_pair
#define pb push_back
#define fi first
#define se second
// }}}

const int N = 1010 , P = 1e9 + 7;
int n;
vi g[N];

void dfs(int c,int fa,int dep,int &maxdep) {
  maxdep = max(maxdep , dep);
  for(auto t : g[c]) if(t != fa) {
    dfs(t , c , dep + 1 , maxdep);
  }
}

int f[N][N<<1];

void dp(int c,int fa,int dep,int maxdep,int p) {
  int r=maxdep-dep,l=-r;
  l+=p,r+=p;
  rep(i,l,r+1) f[c][i+N]=1;
  for(auto t : g[c]) if(t != fa) {
    dp(t , c , dep + 1 , maxdep , p);
    rep(i,l,r+1) f[c][i+N]=ll(f[c][i+N])*(f[t][i-1+N]+f[t][i+1+N])%P;
  }
}

vi solve(int rt,int fa,int maxdep,int p) {
  memset(f,0,sizeof(f));
  dp(rt , fa , 0 , maxdep , p);
  return vi(f[rt],f[rt]+N+N);
}

void solve(int u,int v,int maxu,int maxv,int pu,int pv,int sig,int &ans) {
  vi F = solve(u , v , maxu , pu);
  vi G = solve(v , u , maxv , pv);
  int l=-maxu+pu,r=maxu+pu;
  rep(i,l,r+1){
    ans=((ans+ll(F[i+N])*(G[i+1+N]+G[i-1+N])*sig%P)%P+P)%P;
  }
}


int main(){
  cin >> n;
  rep(i,1,n) {
    int u , v;
    cin >> u >> v;
    --u,--v;
    g[u].pb(v);
    g[v].pb(u);
  }
  vi dis(n , 0);
  rep(i,0,n) dfs(i , -1 , 0 , dis[i] = 0);
  int mindeep = *min_element(all(dis));
  vi center;
  rep(i,0,n) if(dis[i] == mindeep)
    center.pb(i);
  if(sz(center) == 1) {
    int rt = center[0];
    vi F = solve(rt , -1 , dis[rt] , 0);
    int ans=0;
    rep(i,-dis[rt],dis[rt]+1)
      (ans+=F[i+N])%=P;
    printf("%d\n",ans);
  } else {
    int u = center[0] , v = center[1];
    int ans = 0 , d = dis[u];
    solve(u , v , d - 1 , d , 0 , 0 , 1 , ans);
    solve(u , v , d , d - 1 , 0 , 0 , 1 , ans);
    solve(u , v , d - 1 , d - 1 , 0 , -1 , -1 , ans);
    solve(u , v , d - 1 , d - 1 , 0 , 1 , -1 , ans);
    printf("%d\n",ans);
  }
  return 0;
}


Measured memory_bytes: 8320
#include<stdio.h>
#include<algorithm>

using namespace std;

int main(){
  char S[5];
  char T[5];
  scanf("%s",S);
  scanf("%s",T);

  int count=0;

  for(int i=0;i<3;i++)
    if(S[i]==T[i])
      count++;
  printf("%d",count);
return 0;
}

Measured memory_bytes: 128
import sys,queue,math,copy,itertools,bisect,collections,heapq

def main():
    LI = lambda : [int(x) for x in sys.stdin.readline().split()]

    N,K = LI()
    A = LI()

    s = sum(A)
    d = [s]
    for i in range(2,int(math.sqrt(s))+1):
        if s % i == 0:
            d.append(i)
            if s // i != i:
                d.append(s//i)

    ans = 1
    for x in d:

        B = []
        s = 0
        for y in A:
            c1 = x - y % x
            B.append((c1,y))
            s += c1

        B.sort(reverse=True)
        cnt = 0
        for y,_ in B[s//x:]:
            cnt += y
        if cnt <= K:
            ans = max(ans,x)
    print(ans)

if __name__ == '__main__':
    main()

Measured memory_bytes: 71044
use core::cmp;
use proconio::input;

fn main() {
    input! {
        x: usize,
        y: usize,
        a: usize,
        b: usize,
        c: usize,
        mut p: [usize; a],
        mut q: [usize; b],
        mut r: [usize; c],
    }

    p.sort_by(|a, b| b.cmp(a));
    q.sort_by(|a, b| b.cmp(a));
    r.sort_by(|a, b| b.cmp(a));

    let mut sum: usize = p.iter().take(x).sum::<usize>() + q.iter().take(y).sum::<usize>();

    let mut count_x = x;
    let mut count_y = y;
    for r in &r {
        if count_x == 0 && count_y == 0 {
            break;
        }
        let index_x = count_x-1;
        let index_y = count_y-1;
        if count_x == 0 {
            if *r > q[index_y] {
                sum += r - q[index_y];
                count_y -= 1;
            }
        } else if count_y == 0 {
            if *r > p[index_x] {
                sum += r - p[index_x];
                count_x -= 1
            }
        } else if *r > cmp::min(p[index_x], q[index_y]) {
            if p[index_x] < q[index_y] {
                sum += r - p[index_x];
                count_x -= 1;
            } else {
                sum += r - q[index_y];
                count_y -= 1;
            }
        } else {
            break;
        }
    }
    println!("{}", sum);
}

Measured memory_bytes: 7712
#include <iostream>

int main()
{
    long long A, B;
    int N;
    std::cin >> A >> B >> N;
    
    long long res = std::max(A, B);
    for (int i = 1; i <= N; i++) {
        for (int j = 1; j <= N; j++) {
            if ((B * i) % j != 0LL) continue; 
            res = std::min(res, llabs(A - B * i / j));
        }
    }
    
    std::cout << res << std::endl;    
    return 0;
}

Measured memory_bytes: 3084
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.StringTokenizer;
import java.io.IOException;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 *
 * @author kessido
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        InputReader in = new InputReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        CMinimization solver = new CMinimization();
        solver.solve(1, in, out);
        out.close();
    }

    static class CMinimization {
        public void solve(int testNumber, InputReader in, PrintWriter out) {
            int n = in.NextInt();
            int k = in.NextInt();
            int[] a = in.NextIntArray(n);
            if (n == 1) {
                out.println(0);
                return;
            }
            n -= k;
            k--;
            int res = 1;
            while (n > 0) {
                n -= k;
                res++;
            }
            out.println(res);
        }

    }

    static class InputReader {
        BufferedReader reader;
        StringTokenizer tokenizer;

        public InputReader(InputStream stream) {
            reader = new BufferedReader(new InputStreamReader(stream), 32768);
            tokenizer = null;
        }

        public String next() {
            while (tokenizer == null || !tokenizer.hasMoreTokens()) {
                try {
                    tokenizer = new StringTokenizer(reader.readLine(), " \t\n\r\f,");
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }
            return tokenizer.nextToken();
        }

        public int NextInt() {
            return Integer.parseInt(next());
        }

        public int[] NextIntArray(int n) {
            return NextIntArray(n, 0);
        }

        public int[] NextIntArray(int n, int offset) {
            int[] a = new int[n];
            for (int i = 0; i < n; i++) {
                a[i] = NextInt() + offset;
            }
            return a;
        }

    }
}



Measured memory_bytes: 35604
#include<iostream>

using namespace std;

int S[14], H[14], C[14], D[14];

inline void solve(int arr[], char ch){
    for(int i = 1; i <= 13; ++i){
        if(arr[i] == 0) cout << ch << " " << i << endl;
    }
}

int n;
int a;
char ch;
int main(){
    cin >> n;
    for(int i = 1; i <= n; ++i){
        cin >> ch >> a;
        switch(ch){
            case 'S': S[a] = 1; break;
            case 'H': H[a] = 1; break;
            case 'C': C[a] = 1; break;
            case 'D': D[a] = 1; break;
        }
    }
    solve(S, 'S');
    solve(H, 'H');
    solve(C, 'C');
    solve(D, 'D');
    return 0;
}


Measured memory_bytes: 3084
#include <bits/stdc++.h>
#define ll long long int
#define MOD 1000000007
#define INF 1e18
#define PI 3.14159265358979

using namespace std;

int main(void){
  ll n, c, k;
  cin >> n >> c >> k;
  
  vector<ll> t(n);
  for (int i = 0; i < n; i++){
    cin >> t[i];
  }
  sort(t.begin(), t.end());
  
  ll res = 0;
  int id = 0;
  while (id < n){
    ll a = t[id] + k;
    ll tc = 1;
    while (tc <= c && id < n && t[id] <= a){
      tc++;
      id++;
    }
    res++;
  }
  
  cout << res << endl;

  return 0;
}


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

using namespace std;
typedef tuple<int, int, int> T;

int main(){
    int N;
    cin >> N;
    while(N--) {
        vector<T> v;
        int x = 0, y = 0;
        int a, b;
        while(cin >> a >> b) {
            if(a == 0 && b == 0) break;
            x += a;
            y += b;
            int d = x*x+y*y;
            v.push_back(T(d, x, y));
        }
        auto t = *max_element(v.begin(), v.end());
        printf("%d %d\n", get<1>(t), get<2>(t));
    }
    return 0;
}

Measured memory_bytes: 1192
#include <iostream>
#include <stdio.h>
using namespace std;

int main(){
	int year, month, day;

	while( cin >> year >> month >> day ){
		if(year<1868){
			cout << "pre-meiji" << endl; 
		}else if(year==1868 && ( month<9 || ( month==9 && day<8 ) ) ){
			cout << "pre-meiji" << endl; 
		}else if(year<1912){
			cout << "meiji " << year-1867 << " " << month << " " << day << endl;
		}else if(year==1912 && ( month<7 || ( month==7 && day<30 ) ) ){
			cout << "meiji " << year-1867 << " " << month << " " << day << endl;
		}else if(year<1926){
			cout << "taisho " << year-1911 << " " << month << " " << day << endl;
		}else if(year==1926 && ( month<12 || ( month==12 && day<25 ) ) ){
			cout << "taisho " << year-1911 << " " << month << " " << day << endl;
		}else if(year<1989){
			cout << "showa " << year-1925 << " " << month << " " << day << endl;
		}else if(year==1989 && ( month<1 || ( month==1 && day<8 ) ) ){
			cout << "showa " << year-1925 << " " << month << " " << day << endl;
		}else{
			cout << "heisei " << year-1988 << " " << month << " " << day << endl;
		}
	}

	return 0;
}

Measured memory_bytes: 0
#include <iostream>
#include <sstream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <ctime>
#include <cstring>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <map>
#include <set>
#include <bitset>
#include <numeric>
#include <utility>
#include <iomanip>
#include <algorithm>
#include <functional>
#include <unordered_map>
using namespace std;

#define REP(i, s) for (int i = 0; i < s; ++i)
#define ALL(v) (v.begin(), v.end())
#define COUT(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << endl
#define EACH(i, s) for (__typeof__((s).begin()) i = (s).begin(); i != (s).end(); ++i)

template <class T>
inline bool chmax(T &a, T b)
{
    if (a < b)
    {
        a = b;
        return 1;
    }
    return 0;
}
template <class T>
inline bool chmin(T &a, T b)
{
    if (a > b)
    {
        a = b;
        return 1;
    }
    return 0;
}
template <class T1, class T2>
ostream &operator<<(ostream &s, pair<T1, T2> P)
{
    return s << '<' << P.first << ", " << P.second << '>';
}
template <class T>
ostream &operator<<(ostream &s, vector<T> P)
{
    for (int i = 0; i < P.size(); ++i)
    {
        if (i > 0)
        {
            s << " ";
        }
        s << P[i];
    }
    return s;
}
template <class T>
ostream &operator<<(ostream &s, vector<vector<T>> P)
{
    for (int i = 0; i < P.size(); ++i)
    {
        s << endl
          << P[i];
    }
    return s << endl;
}
template <class T>
ostream &operator<<(ostream &s, set<T> P)
{
    EACH(it, P) { s << "<" << *it << "> "; }
    return s << endl;
}
template <class T1, class T2>
ostream &operator<<(ostream &s, map<T1, T2> P)
{
    EACH(it, P) { s << "<" << it->first << "->" << it->second << "> "; }
    return s << endl;
}
typedef long long ll;

#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))

int func(long long num){
    int cnt = 0;
    while (num > 0)
    {
        num /= 10;
        cnt++;
    }
    return cnt;
}

int main()
{
    long long  n;
    cin >> n;
    int ans = INF;
    for (int i = 1; i <= sqrt(n) + 1; i++)
    {
        int tmp=INF;
        if (n % i == 0)
        {
            tmp = max(func(i), func(n / i));
            
        }
        ans = min(ans, tmp);
    }
    cout << ans << endl;
}

Measured memory_bytes: 256