akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define all(x) (x).begin(),(x).end()
const int mod=1000000007,MAX=100001,INF=1<<30;

ll rui(ll a,ll b){
    if(b==1) return a%mod;
    else if(b==0) return 1;
    else if(b%2==0) return (rui(a,b/2)*rui(a,b/2))%mod;
    else return (rui(a,b-1)*a)%mod;
}

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

void make(){
    
    fac[0]=fac[1]=1;
    finv[0]=finv[1]=1;
    inv[1]=1;
    
    for(int i=2;i<MAX;i++){
        inv[i]=mod-inv[mod%i]*(mod/i)%mod;
        fac[i]=fac[i-1]*(ll)i%mod;
        finv[i]=finv[i-1]*inv[i]%mod;
    }
    
}

ll comb(ll a,ll b){
    if(a<b) return 0;
    return fac[a]*(finv[b]*finv[a-b]%mod)%mod;
}

int main(){

    int N,K;cin>>N>>K;
    make();
    ll dp[N+1][K+1];
    for(int i=0;i<N+1;i++){
        for(int j=0;j<K+1;j++){
            dp[i][j]=0;
        }
    }
    
    dp[1][1]=1;
    for(int i=1;i<=N;i++){
        for(int j=1;j<=K;j++){
            if(i==1&&j==1) continue;
            dp[i][j]=(dp[i-1][j]*j+dp[i-1][j-1])%mod;
        }
    }
    
    cout<<dp[N][K]<<endl;
}




Measured memory_bytes: 13264
#include <iostream>
using namespace std;
int main(void){
  int h,m,s;
  cin >> s;
  h=s/3600;
  s-=h*3600;
  m=s/60;
  s-=m*60;
  printf("%d:%d:%d\n",h,m,s);
  return 0;
}



Measured memory_bytes: 3196
import math
from functools import reduce
def gcd(*numbers):
    return reduce(math.gcd, numbers)
K=int(input())
sum = 0
for a in range(1,K+1):
    for b in range(1,K+1):
        for c in range(1,K+1):
            sum = sum + gcd(a,b,c)
print(sum)

Measured memory_bytes: 69544
#include<bits/stdc++.h>
using namespace std;
#define REP(i,st,ed) for(register int i=st,i##end=ed;i<=i##end;++i)
#define DREP(i,st,ed) for(register int i=st,i##end=ed;i>=i##end;--i)
typedef long long ll;
template<typename T>inline bool chkmin(T &x,T y){return (y<x)?(x=y,1):0;}
template<typename T>inline bool chkmax(T &x,T y){return (y>x)?(x=y,1):0;}
inline int read(){
    int x;
    char c;
    int f=1;
    while((c=getchar())!='-' && (c>'9' || c<'0'));
    if(c=='-') f=-1,c=getchar();
    x=c^'0';
    while((c=getchar())>='0' && c<='9') x=(x<<1)+(x<<3)+(c^'0');
    return x*f;
}
inline ll readll(){
    ll x;
    char c;
    int f=1;
    while((c=getchar())!='-' && (c>'9' || c<'0'));
    if(c=='-') f=-1,c=getchar();
    x=c^'0';
    while((c=getchar())>='0' && c<='9') x=(x<<1ll)+(x<<3ll)+(c^'0');
    return x*f;
}
const int maxn=2e5+10;
int a[maxn];
ll sum[maxn];
int main(){
	int n=read(),m=read();
	ll ans=1e18;
	REP(i,1,n) a[i]=read(),sum[i]=sum[i-1]+a[i];
	REP(i,1,n){
		ll res=0;
		REP(j,1,n/i+1){
			res+=(sum[n-(j-1)*i]-sum[max(n-j*i,0)])*(j==1?5:(j+1)*2-1);
			if(res>ans) break;
		}
		res+=(ll)i*m;
		chkmin(ans,res);
	}
	printf("%lld\n",ans+(ll)n*m);
    return 0;
}


Measured memory_bytes: 2560
#include <algorithm>
#include <boost/optional.hpp>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <functional>
#include <iostream>
#include <limits>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <string>
#include <tuple>
#include <type_traits>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>

#define REP(i, n) for(int i = 0, i##_MACRO = (n); i < i##_MACRO; i++)
#define RANGE(i, a, b) for(int i = (a), i##_MACRO = (b); i < i##_MACRO; i++)
#define EACH(e, a) for(auto&& e : a)
#define ALL(a) std::begin(a), std::end(a)
#define RALL(a) std::rbegin(a), std::rend(a)
#define FILL(a, n) memset((a), n, sizeof(a))
#define FILLZ(a) FILL(a, 0)
#define INT(x) (static_cast<int>(x))

using namespace std;

using ll = long long;
using VI = vector<int>;
using VI2D = vector<vector<int>>;

constexpr int INF = 2e9;
constexpr double EPS = 1e-10;
constexpr double PI = acos(-1.0);

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

template <typename T>
constexpr int sign(T x) {
	return x < 0 ? -1 : x > 0 ? 1 : 0;
}

template <>
constexpr int sign(double x) {
	return x < -EPS ? -1 : x > EPS ? 1 : 0;
}

template <typename T, typename U>
constexpr void chmax(T& m, U x) {
	m = max(m, x);
}

template <typename T, typename U>
constexpr void chmin(T& m, U x) {
	m = min(m, x);
}

template <typename T>
constexpr T square(T x) {
	return x * x;
}

int main() {
	int s, w;
	cin >> s >> w;
	cout << (s>w ? "safe" : "unsafe") << endl;
	return 0;
}


Measured memory_bytes: 3624
while s = gets do
  ans = 0
  n = s.to_i

  for a in 0..9 do
    for b in 0..9 do
      for c in 0..9 do
        for d in 0..9 do
          if a + b + c + d == n then
            ans += 1
          end
        end
      end
    end
  end

  puts ans
end

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

using namespace std;

int main()
{
  int n;
  int a[50];
  
  int max_abs_pos = 0;
  scanf("%d", &n);
  for (int i = 0; i < n; i++) {
    scanf("%d", &a[i]);
    if (i && abs(a[i]) > abs(a[max_abs_pos])) {
      max_abs_pos = i;
    }
  }
  
  printf("%d\n", 2 * (n - 1));
  for (int i = 0; i < n; i++) {
    if (i != max_abs_pos) printf("%d %d\n", max_abs_pos + 1, i + 1);
  }
  
  for (int i = 0; i < n - 1; i++) {
    if (a[max_abs_pos] >= 0) {
      printf("%d %d\n", i + 1, i + 2);
    }
    else {
      printf("%d %d\n", n - i, n - i - 1);
    }
  }
  
  return 0;
}

Measured memory_bytes: 256
import sys, re, os
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians, gcd
from itertools import permutations, combinations, product, accumulate
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from functools import reduce
from bisect import bisect_left, insort_left
from heapq import heapify, heappush, heappop

INPUT = lambda: sys.stdin.readline().rstrip()
INT = lambda: int(INPUT())
MAP = lambda: map(int, INPUT().split())
S_MAP = lambda: map(str, INPUT().split())
LIST = lambda: list(map(int, INPUT().split()))
S_LIST = lambda: list(map(str, INPUT().split()))

sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7


def main():
    H, W = MAP()
    S = []
    walls = 0
    for _ in range(H):
        line = INPUT()
        walls += line.count('#')
        S.append(line)

    dist = [[INF]*W for _ in range(H)]
    dist[0][0] = 1
    queue = deque([[0, 0]])
    while queue:
        y, x = queue.popleft()
        if y == H - 1 and x == W - 1:
            print(H*W - walls - dist[y][x])
            break

        for dy, dx in [(y, x-1), (y-1, x), (y, x+1), (y+1, x)]:
            if 0 <= dy < H and 0 <= dx < W and S[dy][dx] == '.' and dist[dy][dx] == INF:
                dist[dy][dx] = dist[y][x] + 1
                queue.append([dy, dx])
    else:
        print(-1)


if __name__ == '__main__':
    main()


Measured memory_bytes: 10068
#include <bits/stdc++.h>
using i64 = long long;
using std::cout;
using std::endl;
using std::cin;

int main() {
	i64 k, a, b; scanf("%lld%lld%lld", &k, &a, &b);
	
	if(b <= a + 1) printf("%lld\n", k + 1);
	else {
		if(k < a + 1) {
			printf("%lld\n", k + 1);
			return 0;
		} else {
			i64 ans = 0;
			k -= a + 1;
			ans += b + (b - a) * (k / 2) + k % 2;
			printf("%lld\n", std::max(k + a + 2, ans));
		}
	}
	return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
#include<iostream>

using namespace std;

int main(void){
    int With,Height,Metropolice;
    int AllRoad=0;
    int i,j;
    int x,y,Now_x,Now_y,dx,dy;
    cin>>Height>> Height>> Metropolice;
    cin>>Now_x>> Now_y;
    for(i=0;i<Metropolice-1;i++){
        cin>>x>> y;
        dx=x-Now_x;
        dy=y-Now_y;
        if(dx*dy>=0){
            if(dx<0)dx=-1*dx;
            if(dy<0)dy=-1*dy;
            dx>dy ? AllRoad+=dx : AllRoad+=dy;
        }
        else{
            if(dx<0)dx=-1*dx;
            if(dy<0)dy=-1*dy;
            AllRoad+=(dx+dy);
        }
        Now_x=x;
        Now_y=y;
    }
    cout<<AllRoad<<endl;
}

Measured memory_bytes: 1160
#include <string>
#include <iostream>
#include <algorithm>
using namespace std;
int n; string s;
int main() {
	cin >> n >> s;
	int cnti = 0;
	for (int i = 0; i < s.size(); i++) {
		if (s[i] == 'I') cnti++;
	}
	int sumj = 0, sumi = cnti, sumo = 0;
	long long ret = 0;
	for (int i = 0; i < s.size(); i++) {
		if (s[i] == 'J') sumj++;
		if (s[i] == 'O') sumo++, ret += 1LL * sumj * sumi;
		if (s[i] == 'I') sumi--;
	}
	long long resj = 0, reso = 0, resi = 0;
	sumi = cnti, sumj = 0;
	for (int i = 0; i < s.size(); i++) {
		if (s[i] == 'J') sumj++;
		if (s[i] == 'I') sumi--;
		if (s[i] == 'O') {
			resj += sumi;
			resi += sumj;
		}
		reso = max(reso, 1LL * sumj * sumi);
	}
	cout << ret + max({ resj, reso, resi }) << endl;
	return 0;
}

Measured memory_bytes: 3324
n, m = map(int,input().split())
ab = [list(map(int,input().split())) for _ in range(n)]

ab.sort(key=lambda x: x[0])
ans = 0
c = 0
for i in range(n):
    for j in range(ab[i][1]):
        ans += ab[i][0]
        c += 1
        if c == m:
            print(ans)
            quit()

Measured memory_bytes: 64984
# -*- coding: utf-8 -*-

def main():
    while True:
        H, W = map(int, input().split())

        if H == 0 and W == 0:
            break

        for i in range(H):
            mark = i % 2
            s = ""
            for j in range(W):
                s += "#" if mark % 2 == 0 else "."
                mark += 1

            print(s)

        print()

if __name__ == "__main__":
    main()



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

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

using namespace std;

char str[1005][1005];

int main(int argc, char* argv[])
{
    long h, w;
    scanf("%ld%ld", &h, &w);

    long i, j;
    for(i=0; i<h; i++) {
        scanf("%s", str[i]);
    }

#define P(i,j) ((i)*w+(j))
    vector<long> dist(w*h);
    for(i=0; i<w*h; i++) {
        dist[i]=-1;
    }

    queue<pair<long,long> > que;
    for(i=0; i<h; i++) {
        for(j=0; j<w; j++) {
            if(str[i][j]=='#') {
                dist[P(i,j)]=0;
                que.push(make_pair(i,j));
            }
        }
    }

    long max=0;
    while(!que.empty()) {
        auto tmp = que.front();
        que.pop();
        long p=tmp.first;
        long q=tmp.second;

        if(p>0 && dist[P(p-1,q)]<0) {
            dist[P(p-1,q)]=dist[P(p,q)]+1;
            que.push(make_pair(p-1,q));
            max = MAX(max,dist[P(p,q)]+1);
        }
        if(p<h-1 && dist[P(p+1,q)]<0) {
            dist[P(p+1,q)]=dist[P(p,q)]+1;
            que.push(make_pair(p+1,q));
            max = MAX(max,dist[P(p,q)]+1);
        }
        if(q>0 && dist[P(p,q-1)]<0) {
            dist[P(p,q-1)]=dist[P(p,q)]+1;
            que.push(make_pair(p,q-1));
            max = MAX(max,dist[P(p,q)]+1);
        }
        if(q<w-1 && dist[P(p,q+1)]<0) {
            dist[P(p,q+1)]=dist[P(p,q)]+1;
            que.push(make_pair(p,q+1));
            max = MAX(max,dist[P(p,q)]+1);
        }
    }

    printf("%ld\n", max);

    return 0;
}


Measured memory_bytes: 25396
#include <bits/stdc++.h>
 
#define fr first
#define sc second
 
using namespace std;
typedef long long ll;
typedef pair<int, int> ii;
const int NMAX = 2e5 + 1, INF = 1e9 + 19, MOD = 1e9;
ll LINF = 1e18;
const double EPS = 1e-8;
long double PI = 3.141592653589793238462643;
 
char cc[NMAX];
 
string getString() {
    scanf("%s", cc);
    return string(cc);
}
 
bool cmp(ii a, ii b) {
    return a.fr < b.fr;
}
 
main() {
//    freopen("input.txt", "r", stdin);
    int x1, y1, x2, y2;
    scanf("%d%d%d%d", &x1, &y1, &x2, &y2);
    if (x1 > x2 || x1 == x2 && y1 > y2) {
        swap(x1, x2), swap(y1, y2);
    }
    bool isNorm = (y1 < y2);
    if (x1 > x2) {
        swap(x1, x2);
    }
    if (y1 > y2) {
        swap(y1, y2);
    }
    int n;
    scanf("%d", &n);
    vector<ii> arr;
    for (int i = 0; i < n; ++i) {
        int x, y;
        scanf("%d%d", &x, &y);
        if (x >= x1 && x <= x2 && y >= y1 && y <= y2) {
            arr.push_back({x, y});
        }
    }
    n = arr.size();
    int d = x2 - x1 + y2 - y1;
    if (n == 0) {
        printf("%lld", 100ll * d);
        return 0;
    }
    cout.precision(40);
    cout.fixed;
    sort(arr.begin(), arr.end(), &cmp);
    vector<int> dp(n + 1, INF);
    dp[0] = -INF;
    int kek = 0;
    if (!isNorm) {
        for (int i = 0; i < n; ++i) {
            arr[i].sc = -arr[i].sc;
        }
    }
    for (int i = 0; i < n; ++i) {
        int j = lower_bound(dp.begin(), dp.end(), arr[i].sc) - dp.begin();
        dp[j] = arr[i].sc;
        if (kek < j) {
            kek = j;
        }
    }
    int mn = min(x2 - x1, y2 - y1) + 1;
    long double ans = 100ll * d - 20 * kek + kek * 5 * PI + 5 * PI * (kek == mn);
    cout << ans;
}

Measured memory_bytes: 3444
from collections import defaultdict
n = int(input())
li_a = list(map(int, input().split()))
dd = defaultdict(lambda:0)
for i in li_a:
    dd[i] += 1
cnt = 0
tyo = 0
for key in dd:
    cnt += 1
    if dd[key] > 1:
        tyo += dd[key]-1
print(n-((tyo+1)//2)*2)

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

#define MOD (1000000007)

using namespace std;

typedef long long int Int;

constexpr Int TEN(int n) { return n == 0 ? 1 : 10 * TEN(n-1); }

int main(void) {
    int N,D;
    cin>>N>>D;

    cout<<(int)ceil(1.0*N/(2.0*D+1))<<endl;        

    return 0;
}





Measured memory_bytes: 256
import sys

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

mydict = {}

for i in range(1, N+1):
    mydict[i] = 0

for i in range(len(A)):
    mydict[A[i]] += 1

for i in range(1,N+1):
    print(mydict[i])

Measured memory_bytes: 38928
#include<iostream>
#include<vector>

int main(void){
	int n;
	std::cin >> n;
	std::string s;
	std::cin >> s;
	int count = 0;

	for(int i = 0; i < n; i++){
		if(s[i] == 'A'){
			if(s.substr(i, 3) == "ABC") count++;
		}
	}

	std::cout << count << std::endl;
	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <array>
#include <unordered_map>
#include <unordered_set>
#include <queue>
#include <algorithm>
#include <iomanip>
#include <cmath>
#include <limits>

using namespace std;

typedef long long ll;

int main (int argc, char* argv[]) {
	ll n;
	cin >> n;
	ll abs_sum = 0;
	ll smallest_abs_val = numeric_limits<ll>::max();
	ll total_negatives = 0;
	for (ll i = 0; i < n; i++) {
		ll n;
		cin >> n;
		if (n < 0) {
			total_negatives++;
			n = -n;
		}
		abs_sum += n;
		smallest_abs_val = min(smallest_abs_val, n);
	}
	if (total_negatives & 1) {
		cout << abs_sum - 2 * smallest_abs_val << endl;
	} else {
		cout << abs_sum << endl;
	}
}


Measured memory_bytes: 256
K=int(input())
import math

sum=0

sum+=K*(K+1)//2

for i in range(1,K+1):
    for j in range(1,K+1):
        if j<=i:
            continue
        else:
            sum+=6*math.gcd(i,j)

for i in range(1,K+1):
    for j in range(1,K+1):
        if j<=i:
            continue
        else:
            for k in range(1,K+1):
                if k<=j:
                    continue
                else:
                    sum+=6*math.gcd(math.gcd(i,j),k)

print(sum)

Measured memory_bytes: 9168
#pragma GCC optimize("Ofast")
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>

#define F first
#define S second
#define int long long
//#define ll long long
//#define int  unsigned long long
#define pb push_back
#define double long double

using namespace std;
using namespace __gnu_pbds;
typedef  tree< int , null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;
const int N = 300000;
int mod = 998244353;
int d[N], cnt[N];
int binpow(int x, int y){
    if (y == 0) return 1;
    if (y % 2 == 1) return x * binpow(x, y - 1) % mod;
    int z = binpow(x, y / 2);
    return z * z % mod;
}
main(){
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    //freopen("input.txt", "r", stdin);
    int n;
    cin >> n;
    int m = 0;
    for (int i = 1; i <= n; i++){
        cin >> d[i];
        m = max(m, d[i]);
        cnt[d[i]]++;
    }
    if (cnt[0] != 1 || d[1] != 0){
        cout << 0;
        return 0;
    }
    int ans = 1;
    for (int i = 1; i <= m; i++){
        ans = ans * binpow(cnt[i - 1], cnt[i]) % mod;
    }
    cout << ans;
}


Measured memory_bytes: 3072
#include<bits/stdc++.h>
#define For(a,b,c) for(int a=b;a<=c;++a)
using namespace std;
const int N=200007; 
int n,a,b,c,d;
char S[N];
void Bang() {
	puts("Yes");
	exit(0);
}
void Boom() {
	puts("No");
	exit(0);
}
int main() {
	scanf("%d%d%d%d%d%s",&n,&a,&b,&c,&d,S+1);
	For(i,a,c-1) if(S[i]=='#'&&S[i+1]=='#') Boom();
	For(i,b,d-1) if(S[i]=='#'&&S[i+1]=='#') Boom();
	if(c<d) Bang();
	For(i,b,d) if(S[i-1]=='.'&&S[i]=='.'&&S[i+1]=='.') Bang();
	Boom();
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
//make_tuple emplace_back next_permutation push_back make_pair second first setprecision

#if MYDEBUG
#include "lib/cp_debug.h"
#else
#define DBG(...) ;
#endif

using LL = long long;
constexpr LL LINF=334ll<<53;
constexpr int INF=15<<26;
constexpr LL  MOD=1E9+7;

struct Problem{
    int n;
    Problem(LL n):n(n){};

    void solve(){
        vector<string> s(2);
        for(int i=0; i<2; ++i){
            cin >> s[i];
        }
        LL ans =1,prev=0;
        for(int i=0; i<n; ++i){
            if(s[0][i]==s[1][i]){
                ans=(ans*(3ll-prev))%MOD;
                prev=1;
            }else{
                if(prev==0){
                    ans=(ans*6ll)%MOD;
                }else if(prev==1){
                    ans=(ans*2ll)%MOD;
                }else{
                    ans=(ans*3ll)%MOD;
                }
                prev=2;
                ++i;
            }
        }
        cout << ans << "\n";
    }
};

int main(){
    cin.tie(0);
    ios_base::sync_with_stdio(false);
    long long n=0;
    cin >> n;
    Problem p(n);
    p.solve();
    return 0;
}



Measured memory_bytes: 256
#include "bits//stdc++.h"
using namespace std;
typedef long long ll;
const ll INF = 1LL << 60;
const ll MOD = 1e9 + 7;

#define ALL(v) v.begin(), v.end()
int main() {
	ll N;
	cin >> N;
	vector<ll> div;
	for (ll i = 1; i*i <= N; i++) {
		if (N%i == 0) {
			div.push_back(i);
			if (i != N / i) div.push_back(N / i);
		}
	}
	ll ans = 0;
	for (ll d : div) {
		if (N / d - 1 > d) {
			ans += N / d - 1;
		}
	}
	cout << ans << endl;
}


Measured memory_bytes: 384
#include<iostream>
#include<vector>
#include<stack>
#include<queue>
#include<map>
#include<set>
#include<unordered_set>
#include<unordered_map>
#include<algorithm>
#include<cmath>
#include<tuple>
#include<iomanip>
#include<list>
#include<climits>
#define endl '\n'
#define ll long long
#define ld long double
#define sp fixed<<setprecision
#define bp __builtin_popcountll
#define mod 1000000007
#define mod1 998244353
#define PI acos(-1)
using namespace std;

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);cout.tie(NULL);
    
    
    string s,t;
    cin>>t>>s;
    if(s.substr(0,s.length()-1)==t)
       cout<<"Yes"; 
    else
    {
        cout<<"No";
    }
    
    return 0;
}

Measured memory_bytes: 3648
from heapq import heappop,heappush

X,Y,Z,K=map(int,input().split())
A=sorted(list(map(int,input().split())),reverse=True)
B=sorted(list(map(int,input().split())),reverse=True)
C=sorted(list(map(int,input().split())),reverse=True)

l=[]
for a in A:
  for b in B:
    l.append(-a-b)

l.sort()
l=l[:K] if len(l)>=K else l+[0]*(K-len(l))
ans=[]
for c in C:
  for i in l:
    heappush(ans,i-c)
    
for i in range(K):
  print(-heappop(ans))

Measured memory_bytes: 186296
class UnionFind:
    def __init__(self, n):
        self.parent = list(range(n)) #親ノード
        self.size = [1]*n #グループの要素数
 
    def root(self, x): #root(x): xの根ノードを返す．
        while self.parent[x] != x:
            self.parent[x] = self.parent[self.parent[x]]
            x = self.parent[x]
        return x 
 
    def merge(self, x, y): #merge(x,y): xのいる組とyのいる組をまとめる
        x, y = self.root(x), self.root(y)
        if x == y: return False
        if self.size[x] < self.size[y]: x,y=y,x #xの要素数が大きいように
        self.size[x] += self.size[y] #xの要素数を更新
        self.parent[y] = x #yをxにつなぐ
        return True
 
    def issame(self, x, y): #same(x,y): xとyが同じ組ならTrue
        return self.root(x) == self.root(y)
        
    def getsize(self,x): #size(x): xのいるグループの要素数を返す
        return self.size[self.root(x)]

# coding: utf-8
# Your code here!
import sys
readline = sys.stdin.readline
read = sys.stdin.read

n,m = map(int, readline().split())
yoko = [list(map(int, readline().split())) for _ in range(n)]
tate = [list(map(int, readline().split())) for _ in range(m)]

INF = 10**9+5
xcoord = [-INF,0,INF]
ycoord = [-INF,0,INF]

for a,b,c in yoko: # (a,c) to (b,c)
    xcoord.append(a)
    xcoord.append(b)
    ycoord.append(c)
for d,e,f in tate: # (d,e) to (d,f)
    ycoord.append(e)
    ycoord.append(f)
    xcoord.append(d)

xcoord = list(sorted(set(xcoord)))
ycoord = list(sorted(set(ycoord)))

zaatu_x = {a:i for i,a in enumerate(xcoord)}
zaatu_y = {a:i for i,a in enumerate(ycoord)}

P = len(xcoord)
Q = len(ycoord)
QQ=Q-1


# (i,j) から右 or 上 に行けるか？
ok_up = [[0]*P for _ in range(Q)]
ok_ri = [[0]*Q for _ in range(P)]

for a,b,c in yoko: # (a,c) to (b,c)
    xa = zaatu_x[a]
    xb = zaatu_x[b]
    yc = zaatu_y[c]
    ok_up[yc-1][xa] += 1
    ok_up[yc-1][xb] -= 1


for d,e,f in tate: # (d,e) to (d,f)
    ye = zaatu_y[e]
    yf = zaatu_y[f]
    xd = zaatu_x[d]
    ok_ri[xd-1][ye] += 1
    ok_ri[xd-1][yf] -= 1

#print(ok_up)
#print(ok_ri)
"""
from itertools import accumulate
for i in range(Q):
    ok_up[i] = list(accumulate(ok_up[i]))
for j in range(P):
    ok_ri[j] = list(accumulate(ok_ri[j]))
"""
for i in range(Q):
    for j in range(P-1):
        ok_up[i][j+1] += ok_up[i][j]

for j in range(P):
    for i in range(Q-1):
        ok_ri[j][i+1] += ok_ri[j][i]

#print(*[i for i in ok_ri],sep="\n")

UF = UnionFind((P-1)*QQ)
for i in range(P-1):
    for j in range(Q-2):
        v = i*QQ+j
        if ok_up[j][i]==0: UF.merge(v,v+1)
for i in range(P-2):
    for j in range(Q-1):
        v = i*QQ+j
        if ok_ri[i][j]==0: UF.merge(v,v+QQ)
        
x0 = zaatu_x[0]
y0 = zaatu_y[0]

#print([UF.root(i) for i in range((P-1)*(Q-1))])
r = UF.root(x0*QQ+y0) 
if UF.root(0) == r:
    print("INF")
else:
    ans = 0
    for i in range(P-1):
        for j in range(Q-1):
            if UF.root(i*QQ+j) == r:
                ans += (xcoord[i+1]-xcoord[i])*(ycoord[j+1]-ycoord[j]) 
    print(ans)

#print(xcoord)
#print(ycoord)




Measured memory_bytes: 354028
#include <algorithm>
#include <cmath>
#include <iostream>
#include <vector>
#include <map>

typedef long long ll;

using namespace std;
const int N_MAX = 1e5 + 10;

int N;
int a[N_MAX];

struct BIT {
    vector< int > bit;
    int M;

    BIT(int M) : bit(vector< int >(M + 1, 0)), M(M) {}

    int sum(int i) {
        if (!i) return 0;
        return bit[i] + sum(i - (i & -i));
    }

    void add(int i, int x) {
        if (i > M) return;
        bit[i] += x;
        add(i + (i & -i), x);
    }
};

bool check(int x) {
    // cout << "check: " << x << endl;

    int tot = 0;
    const int offset = 1e5;
    ll sum = 0;
    BIT bit(N_MAX * 2);

    bit.add(offset, 1);
    for (int i = 0; i < N; i++) {
        if (x <= a[i]) tot++;
        else tot--;

        // cout <<  "  i = " << i << ": " << bit.sum(tot + offset) << endl;
        sum += bit.sum(tot + offset);
        bit.add(tot + offset, 1);
    }

    // cout << "sum = " << sum << endl;
    return sum >= ceil((1LL * N * (N - 1) / 2 + N) / 2);
}

int main() {
    cin >> N;
    for (int i = 0; i < N; i++) {
        cin >> a[i];
    }

    int r = *max_element(a, a + N);
    int l = 0;
    while (r != l) {
        // cout << "----- l=" << l << ", r=" << r << " ------" << endl;
        int mid = (r + l) / 2 + 1;
        if (check(mid)) {
            l = mid;
            // cout << "return true" << endl;
        } else {
            r = mid - 1;
            // cout << "return false" << endl;
        }
    }

    cout << r << endl;
}

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

struct Card { char suit, value; };

void bubble(struct Card A[], int N) {
	for (int i = 0; i < N; i++) {
		for (int j = N - 1; j >= i; j--) {
			if (A[j].value < A[j - 1].value) {
				Card t = A[j]; A[j] = A[j - 1]; A[j - 1] = t;
			}
		}
	}
}

void selection(struct Card A[], int N) {
	for (int i = 0; i < N; i++) {
		int minj = i;
		for (int j = i; j < N; j++) {
			if (A[j].value < A[minj].value)minj = j;
		}
		Card t = A[i]; A[i] = A[minj]; A[minj] = t;
	}
}

void print(struct Card A[], int N) {
	for (int i = 0; i < N; i++) {
		if (i > 0)cout << " ";
		cout << A[i].suit << A[i].value;
	}
	cout << endl;
}

bool isStable(struct Card C1[], struct Card C2[], int N) {
	for (int i = 0; i < N; i++) {
		if (C1[i].suit != C2[i].suit)return false;
	}
	return true;
}

int main() {
	Card C1[100], C2[100];
	int N;
	char ch;

	cin >> N;
	for (int i = 0; i < N; i++) {
		cin >> C1[i].suit >> C1[i].value;
	}

	for (int i = 0; i < N; i++)C2[i] = C1[i];

	bubble(C1, N);
	selection(C2, N);

	print(C1, N);
	cout << "Stable" << endl;
	print(C2, N);
	if (isStable(C1, C2, N)) {
		cout << "Stable" << endl;
	}
	else {
		cout << "Not stable" << endl;
	}
	return 0;
}

Measured memory_bytes: 3076
n = int(input())
a = list(map(int,input().split()))
mod = 10**9+7
dp = [[0]*3 for _ in range(n+1)]
ans = 1
for i in range(n):
    ans *= dp[i].count(a[i])
    ans %= mod
    for j in range(3):
        dp[i+1][j] = dp[i][j]
        if dp[i][j] == a[i]:
            dp[i+1][j] += 1
            a[i] = -1
print(ans)

Measured memory_bytes: 23736
/*
This code By @1353055672(Ligen)
[Warning]You're not excepted to understand this code!
RP++
*/
#pragma GCC optimize(3)
#include<iostream>
#include<stdio.h>
#include<algorithm>
#include<cmath>
#include<cstring>
#include<queue>
#include<map>
#define ll long long
#define ull unsigned long long
#define mn 5000020
#define mod (int)(1e9+7)
#define FOR(a,b,c) for (register ll a=b;a<=c;a++)
#define FORD(a,b,c) for (register ll a=b;a>=c;a--)
using namespace std;
inline ll read(){
    ll x=0,f=1;
    char c=getchar();
    while (c<'0'||c>'9'){
        if (c=='-')f=-1;
        c=getchar();
    }
    while (c>='0'&&c<='9'){
        x=x*10+c-'0';
        c=getchar();
    }
    return x*f;
}
inline ll Max(ll a,ll b){return (a>b)?a:b;}
inline ll Min(ll a,ll b){return (a<b)?a:b;}
inline ll Abs(ll x){return (x<0)?-x:x;}
inline ll gcd(ll a,ll b){return (!a)?b:gcd(b%a,a);}
ll a[100020],b[100020];
int main(){
	ll n=read(),x=read(),gc=0,tot=0;
	FOR(i,1,n)a[i]=read(),gc=(!gc)?Abs(x-a[i]):((x==a[i])?gc:gcd(gc,Abs(x-a[i])));
	FOR(i,1,sqrt(gc))if(gc%i==0){
		b[++tot]=i;
		if(i*i!=gc)b[++tot]=gc/i;
	}
	printf("%lld\n",gc);
	return 0;
}


Measured memory_bytes: 1024
pub struct Scanner {
    line: Vec<String>,
    idx: usize,
}

#[allow(dead_code)]
impl Scanner {
    fn new() -> Scanner {
        return Scanner {
            line: vec![],
            idx: 0,
        };
    }
    fn next<T: std::str::FromStr>(&mut self) -> T {
        if self.idx == self.line.len() {
            let mut buffer = String::new();
            std::io::stdin().read_line(&mut buffer).ok();
            let a: Vec<&str> = buffer.trim().split(' ').collect();
            self.line = a.iter().map(|&s| String::from(s)).collect();
            self.idx = 0;
        }
        let ret: T = self.line[self.idx].parse::<T>().ok().expect("Parse error.");
        self.idx += 1;
        ret
    }
    fn next_string(&mut self) -> Vec<char> {
        let s: String = self.next();
        return s.chars().collect::<Vec<char>>();
    }
    fn next_vec<T: std::str::FromStr>(&mut self, n: usize) -> Vec<T> {
        let mut v: Vec<T> = Vec::with_capacity(n);
        for _i in 0..n {
            v.push(self.next());
        }
        v
    }
}


fn main(){
    let mut scan = Scanner::new();
    let n:usize = scan.next();
    let a : Vec<i64> = scan.next_vec(n);

    let skip: usize;
    if n%2==0{
        skip = 1;
    }else{
        skip = 2;
    }
    let mut dp:Vec<Vec<i64>> = vec![vec![i64::min_value() / 2; skip + 1]; n+2];

    dp[0][0] = 0;
    for i in 0..n{
        for j in 0..skip + 1 {
            if j < skip {
                dp[i + 1][j + 1] = std::cmp::max(dp[i + 1][j + 1], dp[i][j]);
            }
            dp[i + 2][j] = std::cmp::max(dp[i + 2][j], dp[i][j] + a[i]);
        }
    }
    let mut ans = i64::min_value();
    for i in n..n+2{
        for j in skip-1..skip+1{
            ans = std::cmp::max(ans, dp[i][j]);
        }
    }
    println!("{}", ans);
}


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

using namespace std;
#define INF 1000007
#define MOD 1000000007
#define maxn 101
#define maxh 1001
#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define rep(i, n) FOR(i, 0, n)
const int dx[4] = {0, 1, -1, 0}, dy[4] = {1, 0, 0, -1};
typedef std::pair<int, int> P;

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

vector<bool> prime(maxn + 1, true); //素数テーブル
void prime_table(void) {
    prime[0] = false;
    prime[1] = false;
    for (int i = 2; i * i <= maxn; i++) {
        if (!prime[i]) {
            continue;
        }
        for (int j = i + i; j <= maxn; j += j + i) {
            prime[j] = false;
        }
    }
}

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

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

bool IsPrime(int num) //素数判定
{
    if (num < 2)
        return false;
    else if (num == 2)
        return true;
    else if (num % 2 == 0)
        return false;

    double sqrtNum = sqrt(num);
    for (int i = 3; i <= sqrtNum; i += 2) {
        if (num % i == 0) {
            return false;
        }
    }

    return true;
}

vector<int> divisor(int n) //約数列挙
{
    vector<int> ret;
    for (int i = 1; i * i <= n; i++) {
        if (n % i == 0) {
            ret.push_back(i - 1);
            if (i * i != n) {
                ret.push_back((n / i) - 1);
            }
        }
    }
    sort(ret.begin(), ret.end());
    return (ret);
}

int a, b;

void f(int x) {
    while (x) {
        a++;
        b = x;
        x /= 10;
    }
}

signed main() {
    int A, B;
    char op;
    cin >> A >> op >> B;
    if (op == '+') {
        cout << A + B << endl;
    } else {
        cout << A - B << endl;
    }
}



Measured memory_bytes: 256
def Knapsack2(W,w,v): # n個の品物(重さw[i],価値v[i]) 総重量W以内での価値の最大化
    n=len(w)
    v_max=10**5+5
    # dp[i] : 価値iの組み合わせを達成する重量の最小値
    dp=[0]+[float('inf') for _ in range(v_max+1)]
    for i in range(n):
        for j in range(v_max,v[i]-1,-1):
            if j >= v[i]:
                dp[j]=min(dp[j],dp[j-v[i]]+w[i])
    ans=0
    for i in range(v_max+1):
        if dp[i]<=W:
            ans=i
    print(ans)

def main():
    n,W = map(int,input().split())
    w=[0 for _ in range(n)]
    v=[0 for _ in range(n)]
    for i in range(n):
        w[i],v[i] = map(int,input().split())
    Knapsack2(W,w,v)
if __name__ == "__main__":
    main()


Measured memory_bytes: 72524
import java.util.Scanner;

public class Main {
	int N,M,P,X,ans;
	int sum = 0;
	int[] T;

	void run() {
		Scanner sc = new Scanner(System.in);
		N = sc.nextInt();
		T = new int[N+1];
		for(int i = 1; i <= N; i++) {
			T[i] = sc.nextInt();
			sum += T[i];
		}
		M = sc.nextInt();
		for(int i = 0; i < M; i++) {
			P = sc.nextInt();
			X = sc.nextInt();
			ans = sum - (T[P] - X);
			System.out.println(ans);
		}
		sc.close();
	}

	public static void main(String[] args) {
		new Main().run();
	}
}

Measured memory_bytes: 21844
#include<iostream>
#include<algorithm>
#include<string>
#include<sstream>
using namespace std;
int main() {
  int n;
  cin >> n;
  long count=0;
  for(int i=0;i<n;i++){
    int a;
    cin >> a;
    while(a%2==0){
      a/=2;
      count++;
    }
  }
  cout << count << endl;
  return 0;
}


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

using namespace std;

int main() {
    int N;
    cin >> N;
    
    vector<long long int> A(N);
    vector<long long int> d(N+1);
    vector<long long int> dsum(N+2, 0);
    vector<long long int> t(N);
    for(int n=0; n<N; n++) {
        cin >> A[n];
        if(n==0) {
            d[n] = abs(A[n]);
        } else {
            d[n] = abs(A[n]-A[n-1]);

            if(n==1) {
                t[n-1] = abs(A[n]);
            } else {
                t[n-1] = abs(A[n]-A[n-2]);
            }
        }
        dsum[n+1] = dsum[n]+d[n];
    }
    d[N] = abs(A[N-1]);
    dsum[N+1] = dsum[N] + d[N];
    t[N-1] = abs(A[N-2]);
    
    long long int ans;
    for(int n=0; n<N; n++) {
        ans=0;

        ans += t[n];
        ans += dsum[n]-dsum[0];
        ans += dsum[N+1]-dsum[n+2];
        
        cout << ans << endl;
    }

    return 0;
    
}

Measured memory_bytes: 4352
#include <iostream>
#include <vector>
using namespace std;
int main()
{
    int n, m, c, ans, h=0;
    cin >> n >> m >>c;
    vector <int> b(m);
    vector <vector<int> > a(n,vector<int>(m));
    for(int i=0;i<m;i++)
        cin >> b[i];
    for(int i=0;i<n;i++)
    {
        for(int s=0;s<m;s++)
            cin >> a[i][s];
    }
    for(int i=0;i<n;i++)
    {
        ans=0;
        for(int s=0;s<m;s++)
            ans+=a[i][s]*b[s];
        ans+=c;
        if(ans>0)
            h++;
    }
    cout << h <<'\n';
}

Measured memory_bytes: 256
#include <iostream>
#include <cstring>
#include <vector>
#include <cstdio>
using namespace std;
const int M = 1e5 + 10;
vector<int>vc[M];
int dp[M];
int dfs(int u , int pre) {
    int len = vc[u].size();
    for(int i = 0 ; i < len ; i++) {
        int v = vc[u][i];
        if(v == pre) continue;
        dp[u] ^= dfs(v , u) + 1;
    }
    return dp[u];
}
int main() {
    int n;
    scanf("%d" , &n);
    for(int i = 1 ; i < n ; i++) {
        int u , v;
        scanf("%d%d" , &u , &v);
        vc[u].push_back(v);
        vc[v].push_back(u);
    }
    memset(dp , 0 , sizeof(dp));
    if(dfs(1 , -1)) printf("Alice\n");
    else printf("Bob\n");
    return 0;
}

Measured memory_bytes: 12288
#include <iostream>
#include <stdio.h>
#include <string>
#include <cstdlib>
#include <cmath>
#include <algorithm>
#include <string.h>
#include <queue>
#include <stack>
#define _USE_MATH_DEFINES
#define LL long long
#define front top
using namespace std;
const double PI = acos(-1.0);

int smax(int ary[]) {
	int m = 0;
	for (int i = 0; i < sizeof(ary) / sizeof(ary[0]); i++)
		if (m < ary[i]) m = ary[i];
	return m;
}

int nmax(int ary[]) {
	int max = 0, num;
	for (int i = 0; i < sizeof(ary) / sizeof(ary[0]); i++)
		if (max < ary[i]) {
			max = ary[i];
			num = i;
		}
	return max, num;
}

bool dfs(int q, int value) {
	return false;
}

int max2(int a, int b) {
	if (a < b) a = b;
	return a;
}

int min2(int a, int b) {
	if (a > b) a = b;
	return a;
}

int max3(int a, int b, int c) {
	return max2(a, max2(b, c));
}

int min3(int a, int b, int c) {
	return min2(a, min2(b, c));
}

int main() {
	int n, k, l[50], sum = 0;
	cin >> n >> k;
	for (int i = 0; i < n; i++) cin >> l[i];
	sort(l, l + n);
	for (int i = 0, j = n - 1; i < k; i++, j--) {
		sum += l[j];
	}
	cout << sum << endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define repd(i,a,b) for (int i=(a);i<(b);i++)
#define rep(i,n) repd(i,0,n)
#define all(x) (x).begin(),(x).end()
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; }
typedef long long ll;
const long long INF = 1LL << 60;
typedef pair<int, int> P;
int main()
{
    int N;
    cin >> N;
    vector<int> A(N), B(N);

    rep(i, N) {
        cin >> A[i];
        B[i] = A[i];
    }

    sort(all(B));
    reverse(all(B));

    rep(i, N) {
        if (A[i] == B[0]) cout << B[1] << endl;
        else cout << B[0] << endl;
    }
    return 0;
}

Measured memory_bytes: 4796
#include <bits/stdc++.h>
#include <stdio.h>
#include <algorithm>
using namespace std;
#define r(i,n) for(int i=0;i<n;i++)
#define ll long long
#define rn(i,n) for(int i=1;i<=n;i++)

int main(){
  int n;
  cin>>n;
  string s;
  vector<ll> a(5,0);
  r(i,n){
    cin>>s;
    if(s.at(0)=='M')a.at(0)++;
    else if(s.at(0)=='A')a.at(1)++;
    else if(s.at(0)=='R')a.at(2)++;
    else if(s.at(0)=='C')a.at(3)++;
    else if(s.at(0)=='H')a.at(4)++;
  }
  //cout<<a.at(0)<<endl;
  ll sum=0;
  for(int i=0;i<3;i++){
    for(int j=i+1;j<4;j++){
      for(int k=j+1;k<5;k++){
        sum+=a.at(i)*a.at(j)*a.at(k);
      }
    }
  }

cout<<sum<<endl;
return 0;}


Measured memory_bytes: 256
#coding:utf-8
#1_2_C

def BubbleSort(cards, n):
    for i in range(n):
        for j in range(n-1, i, -1):
            if cards[j][1] < cards[j-1][1]:
                cards[j], cards[j-1] = cards[j-1], cards[j]
    return cards

def SelectionSort(cards, n):
    for i in range(n):
        minj = i
        for j in range(i, n):
            if cards[minj][1] > cards[j][1]:
                minj = j
        cards[i], cards[minj] = cards[minj], cards[i]
    return cards

n = int(input())
cards = input().split()
copy = list(cards)

print(*BubbleSort(cards, n))
print("Stable")
print(*SelectionSort(copy, n))
print("Stable" if cards == copy else "Not stable")

Measured memory_bytes: 7800
#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 int64 = int64_t;

constexpr int64 MOD = 1000000007;

int N, K;
int64 a[100000];

int main() {
    while (true) {
        cin >> N >> K;
        if (N == 0 && K == 0) break;
        for (int j = 0; j < N; ++j) {
            cin >> a[j];
        }
        for (int j = 0; j < N-1; ++j) {
            a[j+1] += a[j];
        }

        int64 ans = a[K-1];
        for (int j = K; j < N; ++j) {
            ans = max(ans, a[j] - a[j-K]);
        }
        cout << ans << endl;
    }
    return 0;
}

Measured memory_bytes: 3776
macro_rules ! input { ( source = $ s : expr , $ ( $ r : tt ) * ) => { let mut iter = $ s . split_whitespace ( ) ; input_inner ! { iter , $ ( $ r ) * } } ; ( iter = $ iter : ident , $ ( $ r : tt ) * ) => { let s = { use std :: io :: Read ; let mut s = String :: new ( ) ; std :: io :: stdin ( ) . read_to_string ( & mut s ) . unwrap ( ) ; s } ; let mut $ iter = s . split_whitespace ( ) ; input_inner ! { $ iter , $ ( $ r ) * } } ; ( $ ( $ r : tt ) * ) => { let s = { use std :: io :: Read ; let mut s = String :: new ( ) ; std :: io :: stdin ( ) . read_to_string ( & mut s ) . unwrap ( ) ; s } ; let mut iter = s . split_whitespace ( ) ; input_inner ! { iter , $ ( $ r ) * } } ; }
macro_rules ! input_inner { ( $ iter : expr ) => { } ; ( $ iter : expr , ) => { } ; ( $ iter : expr , mut $ var : ident : $ t : tt $ ( $ r : tt ) * ) => { let mut $ var = read_value ! ( $ iter , $ t ) ; input_inner ! { $ iter $ ( $ r ) * } } ; ( $ iter : expr , mut $ var : ident $ ( $ r : tt ) * ) => { input_inner ! { $ iter , mut $ var : usize $ ( $ r ) * } } ; ( $ iter : expr , $ var : ident : $ t : tt $ ( $ r : tt ) * ) => { let $ var = read_value ! ( $ iter , $ t ) ; input_inner ! { $ iter $ ( $ r ) * } } ; ( $ iter : expr , $ var : ident $ ( $ r : tt ) * ) => { input_inner ! { $ iter , $ var : usize $ ( $ r ) * } } ; }
macro_rules ! read_value { ( $ iter : expr , ( $ ( $ t : tt ) ,* ) ) => { ( $ ( read_value ! ( $ iter , $ t ) ) ,* ) } ; ( $ iter : expr , [ $ t : tt ; $ len : expr ] ) => { ( 0 ..$ len ) . map ( | _ | read_value ! ( $ iter , $ t ) ) . collect ::< Vec < _ >> ( ) } ; ( $ iter : expr , { chars : $ base : expr } ) => { read_value ! ( $ iter , String ) . chars ( ) . map ( | c | ( c as u8 - $ base as u8 ) as usize ) . collect ::< Vec < usize >> ( ) } ; ( $ iter : expr , { char : $ base : expr } ) => { read_value ! ( $ iter , { chars : $ base } ) [ 0 ] } ; ( $ iter : expr , chars ) => { read_value ! ( $ iter , String ) . chars ( ) . collect ::< Vec < char >> ( ) } ; ( $ iter : expr , char ) => { read_value ! ( $ iter , chars ) [ 0 ] } ; ( $ iter : expr , usize1 ) => { read_value ! ( $ iter , usize ) - 1 } ; ( $ iter : expr , $ t : ty ) => { $ iter . next ( ) . unwrap ( ) . parse ::<$ t > ( ) . unwrap ( ) } ; }
use std::cmp::max;
fn main() {
    input! { n, m, edges: [(usize1, usize1); m], q, querys: [(usize1, usize, usize); q] };
    let dmax = querys.iter().map(|&(_, d, _)| d).max().unwrap();
    let mut graph = vec![vec![]; n];
    for &(a, b) in &edges {
        graph[a].push(b);
        graph[b].push(a);
    }
    let mut dp = vec![vec![-1isize; dmax + 1]; n];
    for (i, &(v, d, _c)) in querys.iter().enumerate() {
        dp[v][d] = max(dp[v][d], i as isize);
    }
    for i in (0..dmax).rev() {
        for u in 0..n {
            dp[u][i] = max(dp[u][i], dp[u][i + 1]);
            for &v in graph[u].iter() {
                dp[v][i] = max(dp[v][i], dp[u][i + 1]);
            }
        }
    }
    for u in 0..n {
        let x = dp[u][0];
        let ans = if x < 0 { 0 } else { querys[x as usize].2 };
        println!("{}", ans);
    }
}


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

using namespace std;

int main() {
    int N, Y;
    int x, y, z;

    cin >> N >> Y;

    for (int l = 0; l <= N; ++l) {
        for (int m = 0; m <= (N - l); ++m) {
            int n = N - m - l;
            int sum = 10000 * l + 5000 * m + 1000 * n;
            if (n >= 0 && Y == sum) {
                x = l;
                y = m;
                z = n;
                cout << x << " " << y << " " << z << endl;
                return 0;
            }
        }
    }

    cout << "-1 -1 -1" << endl;

    return 0;
}


Measured memory_bytes: 256
xs,ys,xg,yg = map(int,input().split())

ans = ''
for i in range(yg-ys):
    ans += 'U'
for i in range(xg-xs):
    ans += 'R'

for i in range(yg-ys):
    ans += 'D'
for i in range(xg-xs + 1):
    ans += 'L'

for i in range(yg-ys+1):
    ans += 'U'
for i in range(xg-xs+1):
    ans += 'R'
ans += 'DR'

for i in range(yg-ys+1):
    ans += 'D'
for i in range(xg-xs + 1):
    ans += 'L'

ans += 'U'
print(ans)


Measured memory_bytes: 3064
#include <stdio.h>
#include <math.h>

main()
{
    long long int sum;
    int n,m,min,max;
    
    scanf("%d %d",&n,&m);
    min=m;
    max=m;
    sum=m;
    n--;
    
    while(n--){
        scanf("%d",&m);
        if(min>m)min=m;
        if(max<m)max=m;
        sum+=m;
    }
    printf("%d %d %lld\n",min,max,sum);
}


Measured memory_bytes: 2120
import java.util.Scanner;

//ABC111-A

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

		String line1 = sc.nextLine();
		char[] tmp = new char[line1.length()];

		for(int i = 0; i < line1.length(); i++){
			char ch = line1.charAt(i);

			if(ch == '1'){
				tmp[i] = '9';
			}else if(ch == '9'){
				tmp[i] = '1';
			}else{
				//ignore
			}
		}

			System.out.println(tmp);
	}
}

Measured memory_bytes: 21712
#include <bits/stdc++.h>
#define rep(i,n) for(ll i=0;i<(n);i++)
#define rrep(i,n) for(ll i = 1; i <= (n); ++i)
#define drep(i,n) for(ll i = (n)-1; i >= 0; --i)
#define all(v) v.begin(),v.end()
#define len(x) (ll)(x).length()
#define maxs(x,y) x = max(x,y)
#define mins(x,y) x = min(x,y)
#define pb push_back
#define sz(x) (ll)(x).size()
#define v(T) vector<T>
#define vv(T) vector<vector<T>>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<P> vp;
ll gcd(ll a,ll b){if(a%b==0){return b;}else{return(gcd(b,a%b));}}
ll lcm(ll a,ll b){return a/gcd(a,b)*b;}
const int INF=1e9;
const ll MX = 1e18;
const ll MOD=INF+7;
const int di[] = {-1,0,1,0};
const int dj[] = {0,-1,0,1};
const double PI=acos(-1);
const string tr="abcdefghijklmnopqrstuvwxyz";
#define dame { puts("-1"); return 0;}
#define yn {puts("Yes");}else{puts("No");}
#define YN {puts("YES");}else{puts("NO");}
const ll MAX = 1000001;
long long fac[MAX], finv[MAX], inv[MAX];
void COMinit() {fac[0] = fac[1] = 1;finv[0] = finv[1] = 1;inv[1] = 1;for (ll i = 2; i < MAX; i++){fac[i] = fac[i - 1] * i % MOD;inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;finv[i] = finv[i - 1] * inv[i] % MOD;}}
long long COM(ll n, ll k){if (n < k) return 0;if (n < 0 || k < 0) return 0;return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;}
ll llpow(ll n,ll i){ll cnt=n;  for(ll j=0;j<i-1;j++){n*=cnt;}return n;}
bool is_prime(long long N) {if (N == 1) return false;for (long long i = 2; i * i <= N; ++i) {if (N % i == 0) return false;}return true;}
int digit(ll N) {int ans = 0;while (N) {++ans;N /= 10;}return ans;}
vector<pair<ll,ll>> pf/*prime_factorize*/(ll n){vector<pair<ll,ll>> res;for(ll a=2;a*a<=n;a++){if(n%a!=0) continue;ll ex=0;while(n%a==0){ex++;n/=a;}res.pb({a,ex});}if(n!=1) res.pb({n,1});return res;}

int main() {
  ll n;
  cin>>n;
  ll res=1;
  map<ll,ll> mp;
  for(ll i=2;i<=n;i++){
    vector<pair<ll,ll>> ans=pf(i);
    for(auto x:ans){
      mp[x.first]+=x.second;
    }
  }
  for(auto x:mp){
    res*=x.second+1;
    res%=MOD;
  }
  if(res<0) res+=MOD;
  cout<<res<<endl;
}

Measured memory_bytes: 3588
import java.util.*;

public class Main {

    public static void main(String[] args) {

        Scanner scanner = new Scanner(System.in);

        int N = scanner.nextInt();
        HashSet<String> hashSet = new HashSet<>();

        char past = '_';

        for(int i=0; i<N; i++){
            String S = scanner.next();
            if(i != 0){
                if(past != S.charAt(0) || hashSet.contains(S)){
                    System.out.println("No");
                    return;
                }
            }
            past = S.charAt(S.length()-1);
            hashSet.add(S);
        }

        System.out.println("Yes");

    }
}


Measured memory_bytes: 21844
#include <iostream>

using namespace std;
const int kBalln = 10;
int ball[kBalln];

bool ExistAsceOrder(int i, int a, int b){
  if (i == kBalln)  return true;

  if (a < ball[i]) 
    {
      if(ExistAsceOrder(i+1,ball[i],b)) return true;
    }

  if (b < ball[i])
    {
      if(ExistAsceOrder(i+1,a,ball[i])) return true;
    }

  return false;
}

int main(){
  int n;

  cin >> n;
  for (int j = 0; j < n; ++j)
    {
      for (int i = 0; i < kBalln; ++i)
        {
          cin >> ball[i];
        }
      cout << (ExistAsceOrder(0,0,0)? "YES" : "NO") << endl;
    }
  return 0;
}

Measured memory_bytes: 1152
package main

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

var scanner = bufio.NewScanner(os.Stdin)

func main() {
	for scanner.Scan() {
		n, _ := strconv.Atoi(scanner.Text())
		if n == 0 {
			break
		}
		scanner.Scan()
		buf := strings.Split(scanner.Text(), " ")
		input := make([]int, len(buf))
		for i := range input {
			input[i], _ = strconv.Atoi(buf[i])
		}
		fmt.Println(31)
		i, k := 0, 31
		for k > 1 {
			k -= input[i]
			fmt.Println(k)
			k = k - (k-1)%5
			fmt.Println(k)
			i++
			if i >= n {
				i = 0
			}
		}
		fmt.Println(0)
	}
}



Measured memory_bytes: 1088
n = gets.to_i
max = -1000000
min = 1000000
sum = 0
gets.split( " " ).map { | val | 
	a = val.to_i
	if max < a
		max = a
	end
	if a < min
		min = a
	end
	sum += a
}
puts( "#{min} #{max} #{sum}" ) 

Measured memory_bytes: 6416