akhauriyash/Code-Regression huggingface dataset:
import java.io.*;

public class Main {
	public static void main(String[] args) throws Exception {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		int n = Integer.parseInt(br.readLine());
		String a[] = br.readLine().split(" ");
		int[] A = new int[n];
		for (int i = 0; i < n; i++) {
			A[i] = Integer.parseInt(a[i]);
		}
		count = 0;
		margeSort(A, 0, n);
		System.out.println(count);
	}
	public static void marge(int[] A, int left, int middle, int right) {
		int n1 = middle - left;
		int n2 = right - middle;
		int[] L = new int[n1 + 1];
		int[] R = new int[n2 + 1];
		for (int i = 0; i < n1; i++) {
			L[i] = A[left + i];
		}
		for (int i = 0; i < n2; i++) {
			R[i] = A[middle + i];
		}
		L[n1] = Integer.MAX_VALUE;
		R[n2] = Integer.MAX_VALUE;
		int i = 0;
		int j = 0;
		for (int k = left; k < right; k++) {
			if (L[i] <= R[j]) {
				A[k] = L[i];
				i++;
				count += j;
			} else {
				A[k] = R[j];
				j++;
			}
		}
	}
	public static void margeSort(int[] A, int left, int right) {
		if ((left + 1) < right) {
			int middle = (left + right) / 2;
			margeSort(A, left, middle);
			margeSort(A, middle, right);
			marge(A, left, middle, right);
		}
	}
	public static long count;
}

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

void writeRectangle(int w, int h)
{
    const char sharp = '#';
    const char dot = '.';

    char c = ' ';
    for (int i=0; i<w; ++i)
    {
        for (int j=0; j<h; ++j)
        {
            c = (((i%2 == 0)&&(j%2 == 0)) || ((i%2 == 1)&&(j%2 == 1))) ? sharp : dot;
            cout << c;
        }
        cout << endl;
    }
}

int main()
{
    int w=0, h=0;
    
    while(true)
    {
        cin >> w >> h;
        if (w == 0 && h == 0)   break;

        writeRectangle(w, h);
        cout << endl;
    }
    
    return 0;
}

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

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; }

int main()
{
    int h,w;
    cin >> h >> w;
    string s[h];
    for (int i = 0; i < h; i++)
    {
        cin >> s[i];
    }
    
    vector<vector<int>> dp(h, vector<int>(w, INT_MAX - 100));
    int dx[] = {0, 1, 0, -1};
    int dy[] = {1, 0, -1, 0};

    dp[0][0] = (s[0][0] == '#');
    for (int i = 0; i < h; i++)
    {
        for (int j = 0; j < w; j++)
        {
            for (int k = 0; k < 2; k++)
            {
                if(0 <= i + dy[k] && i + dy[k] < h && 0 <= j + dx[k] && j + dx[k] < w)
                {
                    if(s[i + dy[k]][j + dx[k]] == '#' && s[i][j] == '#')chmin(dp[i + dy[k]][j + dx[k]],  dp[i][j]);
                    else if(s[i + dy[k]][j + dx[k]] == '#' && s[i][j] == '.')chmin(dp[i + dy[k]][j + dx[k]], dp[i][j] + 1);
                    else if(s[i + dy[k]][j + dx[k]] == '.' && s[i][j] == '#')chmin(dp[i + dy[k]][j + dx[k]], dp[i][j]);
                    else chmin(dp[i + dy[k]][j + dx[k]], dp[i][j]);
                }
            }
        }
    }
/*
    for (int i = 0; i < h; i++)
    {
        for (int j = 0; j < w; j++)cout << dp[i][j] << " ";
        cout << endl;
    }
*/
    cout << dp[h - 1][w - 1] << endl;
}

Measured memory_bytes: 256
import sys
input = sys.stdin.readline

def ceil(a, b):
    if a%b == 0:
        return a//b
    else:
        return a//b + 1

def main():
    N = int(input())
    a = list(map(int, input().split()))
    b = list(map(int, input().split()))

    count = sum(b) - sum(a)

    one = 0
    two = 0
    for i in range(N):
        if a[i] >= b[i]:
            one += a[i] - b[i]
        else:
            two += ceil(b[i]-a[i], 2)
    
    if one <= count and two <= count:
        print("Yes")
    else:
        print("No")

if __name__ == "__main__":
    main()

Measured memory_bytes: 4596
#include<stdio.h>
#include<stdlib.h>
#include<stdint.h>
#include<inttypes.h>

typedef int32_t i32;
typedef uint64_t u64;

#define MIN(a,b) ((a)<(b)?(a):(b))

u64 mod = 0;

u64 digit (u64 n) {
  u64 p = 1;
  while (n > 0) {
    p = 10 * p;
    n /= 10;
  }
  return p;
}

const u64 f = 3;

void matmul (u64 *c, u64 *a, u64 *b) {
  u64 tmp[9] = {0,0,0,0,0,0,0,0,0};
  for (u64 i = 0; i < f; ++i) {
    for (u64 k = 0; k < f; ++k) {
      for (u64 j = 0; j < f; ++j) {
        tmp[i * f + j] += a[i * f + k] * b[k * f + j];
      }
    }
  }
  for (u64 i = 0; i < f * f; ++i) {
    c[i] = tmp[i] % mod;
  }
}

//c <- a^n
void mat_pow (u64 *c, u64 *a, u64 n) {
  u64 t[9] = {1,0,0,0,1,0,0,0,1};
  u64 s[9];
  for (u64 i = 0; i < f * f; ++i) {
    s[i] = a[i];
  }
  while (n > 0) {
    if (n & 1) matmul (t, t, s);
    matmul (s, s, s);
    n >>= 1;
  }
  for (u64 i = 0; i < f * f; ++i) {
    c[i] = t[i];
  }
}

void run (void) {
  u64 l, a, b;
  scanf ("%" SCNu64 "%" SCNu64 "%" SCNu64 "%" SCNu64, &l, &a, &b, &mod);
  u64 ans[9] = {1,0,0,0,1,0,0,0,1};
  u64 buf = 0;
  while (buf < l) {
    u64 p = digit (a + buf * b);
    u64 n = MIN(l - buf, (p - 1 - (a + buf * b)) / b + 1);
    buf += n;
    u64 mat[9] = {1,1,0,
                  0,1,0,
                  1,0,p%mod};
    mat_pow (mat, mat, n);
    matmul (ans, mat, ans);
  }
  printf ("%" PRIu64 "\n", (ans[6] * (a % mod) + ans[7] * (b % mod)) % mod);
}

int main (void) {
  run();
  return 0;
}


Measured memory_bytes: 128
#include <iostream>
#include <string>
#include <vector>
#include <utility>
#include <algorithm>
#include <functional>
#include <memory.h>
 
using namespace std;
using ll = long long;
using pll = pair<ll,ll>;
 
#define reps(i,s,n) for(int (i) = (s) ;(i) < (n); (i)++)
#define rep(i,n) reps(i,0,n)
 
struct edge{ int from, to; ll cost;};
const int MAX_E = 1e6;
vector<edge> es;//辺
vector<ll> d;//最短距離
const ll INF = 1e16;
int V,E;//Vは頂点数、Eは辺の数
 
bool find_negative_loop(int s){
    rep(i,d.size()) d[i] = INF;
    d[s] = 0;
    rep(i,V){
        rep(j,E){
            edge e = es[j];
            if(d[e.from]== INF) continue;
            if(d[e.to] > d[e.from] + e.cost){
                d[e.to] = d[e.from] + e.cost;
                if(i == V-1 && e.to == V-1) return true;
            }
        }
    }
    return false;
}
 
int main(){
    cin >> V >> E;//V,Eの数を取得
    d.resize(V);
    int f,t;
    ll c;//from,to,cost
    rep(i,E){
        cin >> f >> t >> c;
        f--; t--;
        es.push_back({f,t,-c});
    }
 
    if(find_negative_loop(0)) cout << "inf" << endl;
    else cout << -d[V-1] << endl;
 
    return 0;
}


Measured memory_bytes: 256
n, m, x = map(int, input().split())
li = [list(map(int, input().split())) for _ in range(n)]
ans = 10**18

for i in range(2 ** n):
    check = [0] * n

    for j in range(n):
        if ((i >> j) & 1):
            check[n - 1 - j] = 1

    total = 0
    skill = [0] * m
    for k in range(n):
        if check[k] == 0:
            continue
        total += li[k][0]

        for l in range(m):
            skill[l] += li[k][l+1]

    skill.sort()
    if skill[0] >= x:
        ans = min(ans,total)

if ans == 10**18:
    print(-1)
else:
    print(ans)

Measured memory_bytes: 9264
from collections import Counter
N = int(input())

S = []
sum_ana = 0
for _ in range(N):
  s = sorted(input())
  S.append("".join(s))

S.sort()
ana = 0
for i in range(N-1):
  if S[i] == S[i+1]:
    ana+= 1
    continue
  sum_ana += (ana*(ana+1))//2
  ana = 0
sum_ana += (ana*(ana+1))//2
print(sum_ana)



Measured memory_bytes: 58072
from sys import setrecursionlimit
setrecursionlimit(10**9)
MOD = 10**9 + 7

n = int(input())

neighbor = {}
for i in range(1,n+1):
    neighbor[i] = []

for i in range(n-1):
    x,y = map(int, input().split())
    neighbor[x].append(y)
    neighbor[y].append(x)

def calc(next, base):
    edges = neighbor[next]

    white, black = 1, 1
    for edge in edges:
        if(edge != base):
            white_e, black_e = calc(edge, next)
            white = white *  (white_e + black_e) % MOD
            black = black * white_e % MOD
    return white, black

white, black = calc(1,0)
print((white + black) % MOD )

Measured memory_bytes: 108264
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <cmath>
#include <cstring>

using namespace std;

const int N=100005;
const int P=998244353;

int n,k;

void init(){
	scanf("%d%d",&n,&k);
	printf("%d\n",(n-1+k-2)/(k-1));
}

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

Measured memory_bytes: 256
def combinations(n, r):
    res = 1
    for i in range(n - r + 1, n + 1):
        res *= i
    for i in range(2, r + 1):
        res //= i
    return res

N, A, B = map(int, input().split())
v = list(map(int, input().split()))
v.sort(reverse = True)

mx = sum(v[:A])
ans1 = mx/A
a = v[A - 1]
cnt = v.count(a)

ans2 = 0
for i in range(A, B + 1):
    if A*sum(v[:i]) < i*mx:
        break
    ans2 += combinations(cnt, v[:i].count(a))

print(ans1)
print(ans2)


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

using namespace std;

int main()
{
	string S;
	cin >> S;
	
	int N = S.size();
	vector<string> S_Array(N);
	for (int i = 0; i < N; i++)
	{
		S_Array[i] = S.substr(i, 1);
	}
	
	// 偶数が黒、奇数が白の場合のカウント数を計算
	int count = 0;
	for (int i = 0; i < N; i++)
	{
		if (i % 2 == 0 && S_Array[i] == "0")
		{
			count++;
		}
		else if (i % 2 == 1 && S_Array[i] == "1")
		{
			count++;
		}
	}
	
	// 偶数が白、奇数が黒の場合のカウント数を計算
	int count2 = 0;
	for (int i = 0; i < N; i++)
	{
		if (i % 2 == 0 && S_Array[i] == "1")
		{
			count2++;
		}
		else if (i % 2 == 1 && S_Array[i] == "0")
		{
			count2++;
		}
	}
	
	int answer = min(count, count2);
	
	cout << answer << endl;
	
	return 0;
}

Measured memory_bytes: 5760
#![allow(non_snake_case)]
#![allow(unused_variables)]
#![allow(dead_code)]

fn main() {
    let N: usize = {
        let mut line: String = String::new();
        std::io::stdin().read_line(&mut line).unwrap();
        line.trim().parse().unwrap()
    };
    let S: Vec<Vec<char>> = (0..N).map(|_| {
        let mut line: String = String::new();
        std::io::stdin().read_line(&mut line).unwrap();
        line.trim().chars().collect()
    }).collect();

    // グラフが二部グラフならば真を返す
    fn f(i: usize, c: i64, cs: &mut Vec<i64>, N: usize, S: &Vec<Vec<char>>) -> bool {
        if cs[i] != 0 {
            c == cs[i]
        } else {
            cs[i] = c;
            (0..N).all(|j| S[i][j] == '0' || f(j, -c, cs, N, S))
        }
    }
    let mut cs = vec![0; N];
    let ans = if f(0, 1, &mut cs, N, &S) {
        const INF: i64 = 1_000_000_000;
        let mut dp = vec![vec![INF; N]; N];
        for i in 0..N { dp[i][i] = 0; }
        for i in 0..N { for j in 0..N { if S[i][j] == '1' { dp[i][j] = 1; } } }
        for k in 0..N { for i in 0..N { for j in 0..N { dp[i][j] = std::cmp::min(dp[i][j], dp[i][k] + dp[k][j]); } } }
        1 + (0..N).map(|i| *dp[i].iter().max().unwrap()).max().unwrap()
    } else {
        -1
    };

    println!("{}", ans);
}

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

int N;
int A[20];
int x[20][20];
int y[20][20];

int counter(int x) {
    if(x == 0) return 0;
    return counter(x >> 1) + (x & 1);
}

void solve() {
    cin >> N;
    for(int i = 1; i <= N; i++) {
        cin >> A[i];
        for(int j = 1; j <= A[i]; j++) {
            cin >> x[i][j] >> y[i][j];
        }
    }
    int ans = 0;
    for(int bits = 1; bits < (1 << N); bits++) {
        bool ok = true;
        for(int i = 1; i <= N; i++) {
            if(!(bits & (1 << (i-1)))) continue;
            for(int j = 1; j <= A[i]; j++) {
                if(((bits >> (x[i][j]-1)) & 1) ^ y[i][j]) ok = false;
            }
        }
        if(ok) ans = max(ans, counter(bits));
    }
    cout << ans << endl;
    return;
}

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

Measured memory_bytes: 3620
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define REP(i, n) for (int i = 0; i < (n); ++i)
#define SORT(v) sort((v).begin(), (v).end())
#define RSORT(v) sort((v).rbegin(), (v).rend())
const ll MOD = 1000000007;
const int nmax = 8;
bool graph[nmax][nmax];
const int INF = 1e9;
vector<vector<ll>> dist = vector<vector<ll>>(nmax, vector<ll>(nmax, INF));
void warshall_floyd(ll n)
{
    for (size_t i = 0; i < n; i++)
    {
        for (size_t j = 0; j < n; j++)
        {
            for (size_t k = 0; k < n; k++)
            {
                dist[j][k] = min(dist[j][k], dist[j][i] + dist[i][k]);
            }
        }
    }
}
ll gcd(ll a, ll b)
{
    if (b == 0)
        return a;
    return gcd(b, a % b);
}

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

ll mulMod(ll a, ll b)
{
    return (((a % MOD) * (b % MOD)) % MOD);
}

ll powMod(ll a, ll p)
{
    if (p == 0)
    {
        return 1;
    }
    else if (p % 2 == 0)
    {
        ll half = powMod(a, p / 2);
        return mulMod(half, half);
    }
    else
    {
        return mulMod(powMod(a, p - 1), a);
    }
}

void solve(long long a, long long b)
{
    if (a <= 0 && 0 <= b)
    {
        cout << "Zero" << endl;
        return;
    }
    else if (0 < a && a <= b)
    {
        cout << "Positive" << endl;
        return;
    }
    else if (a <= b && b < 0)
    {
        if ((b - a + 1) % 2 != 0)
        {
            cout << "Negative" << endl;
            return;
        }
        else
        {
            cout << "Positive" << endl;
            return;
        }
    }
}

int main()
{
    long long a;
    scanf("%lld", &a);
    long long b;
    scanf("%lld", &b);
    solve(a, b);
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <string>
#include <math.h>
#include <functional>
#include <algorithm>
#include <utility>

typedef long long Int;
#define REP(i,n) for(int i = 0 ; i < n ; ++i)
using namespace std;

Int aa[120];

int main(){
	int a  = -1;
	while (cin >> a){
		++aa[a];
	}

	Int b = 0;

	REP(i, 120){
		b = max(b, aa[i]);
	}

	REP(i, 120){
		if (aa[i] == b)
			cout << i << endl;
	}

	return 0;
}

Measured memory_bytes: 1156
import java.util.Scanner;


public class Main 
{
    static boolean isPalindrome(String str) 
    { 
        int i = 0, j = str.length() - 1; 
        while (i < j) 
        { 
            if (str.charAt(i) != str.charAt(j)) 
                return false; 
            i++; 
            j--; 
        } 
        return true; 
    } 
    public static void main(String[] args) 
    {
        Scanner sc = new Scanner(System.in);
        String s = sc.next();
        boolean v = isPalindrome(s);
        String n = s.substring(0, ((s.length()-1)/2));
        boolean t = isPalindrome(n);
        String p = s.substring(((s.length()+3)/2)-1, s.length());
        boolean b = isPalindrome(p);
        if(v==true&&t==true&&b==true)
        {
            System.out.println("Yes");
        } 
        else
        {
            System.out.println("No");
        }
    }
}


Measured memory_bytes: 23124
#include <iostream>

int main()
{
        int a ,b, c;
        while(std::cin >> a >> b)
        {
                a += b;
                b = 0;
                do
                {
                        b++;
                }while(a /= 10);
                std::cout << b << std::endl;
        }
        return 0;
}

Measured memory_bytes: 1160
import java.util.*;

public class Main {
	public static void main(String[] args) {
		Scanner scn = new Scanner(System.in);
		int cont = 0;
		for(int i = scn.nextInt();i>0;i--) {
			cont+=i;
		}System.out.println(cont);
		scn.close();
	}
}

Measured memory_bytes: 21716
n = gets.to_i
a = n.times.map{gets.to_i}
ans = 0
for i in 0..n-1
    if i > 0 && a[i-1] == 1 && a[i] > 0
        a[i] -= 1
        ans += 1
    end
    ans += a[i]/2
    a[i] %= 2
end
puts ans

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

int main()
{
	int N;
	cin >> N;
	ll ans = 0;
	rep(i,N)
	{
		ll a;
		cin >> a;
		while(a % 2 == 0)
		{
			a /= 2;
			ans++;
		}
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 3612
import math
import fractions

a,b = map(int,input().split())

a = fractions.gcd(a,b)

i = 2
ans = 1

while i <= a**0.5:
  tmp = a
  while a%i==0:
    a /= i
  if not a == tmp:
    ans += 1
  i += 1
if a >1 :
  ans += 1
  
print(ans)

Measured memory_bytes: 5176
#include<bits/stdc++.h>
using namespace std;
#define fs first
#define sc second
#define pb push_back
#define mp make_pair
#define eb emplace_back
#define ALL(A) A.begin(),A.end()
#define RALL(A) A.rbegin(),A.rend()
typedef long long LL;
typedef pair<int,int> P;
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<typename T> T gcd(T a,T b){return b?gcd(b,a%b):a;}
const LL mod=1000000007;
const LL LINF=1LL<<62;
const int INF=1<<30;
int dx[]={1,0,-1,0,1,-1,1,-1};
int dy[]={0,1,0,-1,1,-1,-1,1};



int main(){
    int n;cin >> n;
    vector<int> x(n);
    for (int i = 0; i < n; i++) {
        cin >> x[i];
    }
    sort(ALL(x));
    int ans = INF;
    for (int i = 0; i <= 100; i++) {
        int tmp = 0;
        for (int j = 0; j < n; j++) {
            tmp += (x[j]-i)*(x[j]-i);
        }
        chmin(ans,tmp);
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
n = int(input())
a = list(map(int,input().split()))
x = a[0]
y = sum(a[1:])
mn = abs(x - y)
for i in range(1,n-1):
    d = a[i]
    x += d
    y -= d
    mn_candidate = abs(x - y)
    if mn > mn_candidate:
        mn = mn_candidate


print(mn)


Measured memory_bytes: 24832
from collections import deque
h, w, m = map(int, input().split())
hl=[0]*h
wl=[0]*w
mh=0
mw=0
mhi=deque([])
dic = {}
mwi=deque([])
#ans =[[0]*w for i in range(h)]
s = [list(map(int, input().split())) for i in range(m)]
 
for i in range(m):
  a, b = s[i]
  a-=1
  b-=1
  if not a in dic:
    dic[a] = {}
    dic[a][b]=1
  else:
    dic[a][b]=1
 
  hl[a]+=1
  if hl[a]>mh:
    mh=hl[a]
    mhi = [a]
  elif hl[a]==mh:
    mhi.append(a)
  
  wl[b]+=1
  if wl[b]>mw:
    mw=wl[b]
    mwi=[b]
  elif wl[b]==mw:
    mwi.append(b)
 
  #ans[a][b]+=1

for i in mhi:
  for j in mwi:
    if not j in dic[i]:
      print(mw+mh)
      quit()

print(mh+mw-1)

Measured memory_bytes: 224396
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using db = double;
using ld = long double;
template<typename T> using V = vector<T>;
template<typename T> using VV = vector<vector<T>>;
#define fs first
#define sc second
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define eb emplace_back
#define all(v) (v).begin(),(v).end()
#define siz(v) (ll)(v).size()
#define rep(i,a,n) for(ll i=a;i<(ll)(n);++i)
#define repr(i,a,n) for(ll i=n-1;(ll)a<=i;--i)
#define lb lower_bound
#define ub upper_bound
typedef pair<int,int> P;
typedef pair<ll,ll> PL;
const ll mod = 1000000007;
const ll INF = 1000000099;
const ll LINF = (ll)(1e18 +99);
vector<ll> dx={-1,1,0,0},dy={0,0,-1,1};
template<typename T,typename U> void chmin(T& t, const U& u){if(t>u)t=u;}
template<typename T,typename U> void chmax(T& t, const U& u){if(t<u)t=u;}
template<typename T>T gcd(T a,T b){return b?gcd(b,a%b):a;}
template<typename T>T mpow(T a, T n) {
  T res = 1;
  for(;n;n>>=1) {
    if (n & 1) res = res * a;
    a = a * a;
  }
  return res;
}



signed main(){
  cin.tie(0);ios::sync_with_stdio(false);
  cout<<fixed<<setprecision(20);
  ll t1,t2,a1,a2,b1,b2;cin>>t1>>t2>>a1>>a2>>b1>>b2;
  ll d1=a1*t1-b1*t1;
  ll d2=a1*t1-b1*t1+a2*t2-b2*t2;

  //cerr<<"d"<<" "<<d1<<" "<<d2<<endl;

  if((d1>0 && d2>0) || (d1<0 && d2<0)){
      cout<<0<<endl;
      return 0;
  }else if(d2==0){
      cout<<"infinity"<<endl;
      return 0;
  }
  

    ll ans;
  if(d2>0){
      ans=((-d1)/d2)*2 +1;
  }else{

      d2*=-1;
      ans=(d1/d2)*2 +1;
  }
  if(d1%d2==0)ans--;
  cout<<ans<<endl;

}
//( ・ __ ・ ) KEEP BEING ORGANIZED
//CHECK overflow,vector_size,what to output?

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <math.h>
#include<bits/stdc++.h>
using namespace std;
long long int A[2000],B[2000],C[2000];
vector<long long> ans;
int main() {
int x,y,z,k;
cin >>x>>y>>z>>k;
for (int i = 0; i < x; ++i) cin >> A[i];
for (int i = 0; i < y; ++i) cin >> B[i];
for (int i = 0; i < z; ++i) cin >> C[i];
sort (A, A+x,greater<long long>());
sort (B, B+y,greater<long long>());
sort (C, C+z,greater<long long>());
for (int i = 0; i < x; ++i){
	for (int j = 0; j < y; ++j){
		for (int l = 0; l < z; ++l){
			if((i+1)*(j+1)*(l+1)<=k) ans.push_back(A[i]+B[j]+C[l]);
			else break;

		}
	}

}
sort (ans.begin(), ans.end(),greater<long long>());
for (int i = 0; i < k; ++i) cout << ans[i] << endl;
return 0;

}


Measured memory_bytes: 1400
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <numeric>
#include <string>
#include <sstream>
#include <complex>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
using namespace std;
typedef long long unsigned int ll;

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

int main(){

   int a, b;
   cin >> a >> b;
   if(b % a == 0){cout<<a+b<<endl;}
   else{cout <<b - a<<endl;}

   return 0;
}

Measured memory_bytes: 256
import std.functional,
       std.algorithm,
       std.bigint,
       std.string,
       std.traits,
       std.array,
       std.range,
       std.stdio,
       std.conv;

void main() {
  ulong[] NM = readln.chomp.split.to!(ulong[]);
  ulong n = NM[0],
        m = NM[1];
  ulong s, c;

  if (n <= m / 2) {
    writeln(n + (m - 2*n) / 4);
  } else {
    writeln(m / 2);
  }
}


Measured memory_bytes: 256
object Main extends App {
  val input = io.Source.stdin.getLines.toSeq.head.split(' ').map(_.toInt).toArray
  val A = input(0)
  val B = input(1)
  val C = input(2)
  val D = input(3)
  private def eval():Int={
    if( B <= C ) return 0
    if( D <= A ) return 0
    
    val s = input.sorted
    return s(2) - s(1)
    //A C B D
    //if( A<=C && C<=B && B<=D ) return B-C
    //C A D B
    //if( C<=A && A<=D && D<=B ) return D-A
    //A C D B
    
    //C A B D
  } 
  println(eval())
}


Measured memory_bytes: 27072
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<utility>
#include<cmath>
#include<climits>
#include<queue>
#include<stack>
#include<numeric>
#include<set>
#include<iomanip>
#include<map>
#include<type_traits>
#include<tuple>
#include<deque>
#include<cassert>
#include<bitset>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
#define rep(i,N) for(ll (i)=0;(i)<(N);(i)++)
#define chmax(x,y) x=max(x,y)
#define chmin(x,y) x=min(x,y)
const int mod = 1000000007;
const int INF = 1001001001;

int main() {
  int n;
  cin >> n;
  vector<P> v(n);
  rep(i, n) cin >> v[i].first >> v[i].second;
  sort(v.begin(), v.end());
  int cost = 1;
  int sub = 0;
  rep(i, n) rep(j, n) {
    if(i == j) continue;
    int p = v[i].first - v[j].first;
    int q = v[i].second - v[j].second;
    int t = 0;
    rep(k, n) rep(l, n) {
      if(k == l) continue;
      if(v[k].first - v[l].first == p && v[k].second - v[l].second == q) ++t;
    }
    sub = max(sub, t);
  }
  cout << n - sub << endl;

}


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

int main(){
    ll N;
    cin >> N;
    rep(n, 1, 3501){
        rep(w, 1, 3501){
            ll si = N*n*w;
            ll bo = 4*w*n - N*(n+w);
            if(bo == 0) continue;
            if(si % bo != 0) continue;
            ll h = si / bo;
            //cerr << h << endl;
            if(h > 0){
                cout << h << " " << n << " " << w << endl;
                return 0;
            }
        }
    }
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main(void){
    int t,n;
    int s[22], f[22];
 
    while(true){
        cin >> t;
        if(t == 0) {
            break;
        }
 
        cin >> n;
        for(int i = 0; i < n; i++){
            cin >> s[i] >> f[i];
        }
         
        int time = 0;
        for(int i = 0; i < n; i++){
            time += f[i] - s[i];
        }
        if(time >= t) 
            cout << "OK" << endl;
        else{
            cout << t - time << endl;
        }
    }
}


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


vector<vector<pair<int,int>>> G(100001);
stack<int> s;

void dfs(vector<int>&k){
  if(s.empty()==0){
    int a=s.top();
    if(G.at(a).size()==0){
      s.pop();
    }
    else{
      if(k.at(G.at(a).at(G.at(a).size()-1).first)==2){
        k.at(G.at(a).at(G.at(a).size()-1).first)=(k.at(a)+G.at(a).at(G.at(a).size()-1).second)%2;
        s.push(G.at(a).at(G.at(a).size()-1).first);
      }
      G.at(a).pop_back();
    }
    dfs(k);
  }
}

int main() {
  int N;
  cin >> N;
  vector<int> k(N+1,2);
  for(int i=0; i<N-1; i++){
    long a,b,c;
    cin >> a >> b >> c;
    G.at(a).push_back(make_pair(b,c%2));
    G.at(b).push_back(make_pair(a,c%2));
  }
  s.push(1);
  k.at(1)=0;
  dfs(k);
  for(int i=1; i<=N; i++){
    cout << k.at(i) << endl;
  }
}

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

int main() {
  int K,S;
  cin >> K >> S;
  int count=0;
  for(int x=0;x<=K;x++){
    for(int y=0;y<=K;y++){
      if(x+y<=S && S-x-y<=K){
        count++;
      }
    }
  }
  cout << count << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using Graph = vector<vector<int>>;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
const long long MOD=1e9+7;

int main() {
  int n;
  cin>>n;
  vector<int> prime;
  vector<bool> seen(1009,false);
  seen[0]=true;
  seen[1]=true;
  rep(i,1009) if(!seen[i]){
    prime.push_back(i);
    int k=i;
    while(k<=1000){
      seen[k]=true;
      k+=i;
    }
  }
  //for(auto p:prime) cout<<p<<endl;
   
  vector<long long> soinsu(prime.size(),0);
  for(int i=n;i>0;--i){
    rep(j,prime.size()){
      int k=i;
      while(k%prime[j]==0 && k!=0){
        soinsu[j]++;
        k/=prime[j];
        //cout<<k<<" "<<P[j]<<endl;
      }
    }
  }
  
  long long ans=1;
  rep(i,prime.size()) if(soinsu[i]>0) ans=(ans*(soinsu[i]+1))%MOD;
  cout<<ans<<endl;    
  return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <assert.h>
#include <complex>
#include <utility>
#include <vector>
#include <string>
#include <stack>
#include <queue>
#include <tuple>
#include <cmath>
#include <bitset>
#include <cctype>
#include <set>
#include <map>
#include <unordered_map>
#include <numeric>
#include <functional>
#define _overload3(_1,_2,_3,name,...) name
#define _rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(ll i=ll(a);i<ll(b);++i)
#define rep(...) _overload3(__VA_ARGS__,repi,_rep,)(__VA_ARGS__)
#define rrep(i,a) for(ll i=ll(a-1);i>=0;--i)
#define all(x) (x).begin(),(x).end()
#define PRINT(V) cout << V << "\n"
#define SORT(V) sort((V).begin(),(V).end())
#define RSORT(V) sort((V).rbegin(), (V).rend())
using namespace std;
using ll = long long;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
inline void Yes(bool condition){ if(condition) PRINT("Yes"); else PRINT("No"); }
template<class itr> void cins(itr first,itr last){
    for (auto i = first;i != last;i++){
        cin >> (*i);
    }
}
template<class itr> void array_output(itr start,itr goal){
    string ans = "",k = " ";
    for (auto i = start;i != goal;i++) ans += to_string(*i)+k;
    if (!ans.empty()) ans.pop_back();
    PRINT(ans);
}
ll gcd(ll a, ll b) {
    return a ? gcd(b%a,a) : b;
}

const ll INF = 1e18;
const ll MOD = 1000000007;
const ll MOD2 = 998244353;
const ll EPS = 1e-10;
int sgn(const double a){
    return (a < -EPS ? -1 : (a > EPS ? +1 : 0));
}
typedef pair<ll,ll> P;
typedef tuple<ll,ll,ll> tri;
typedef pair<double,double> point;
typedef complex<double> Point;
const ll MAX = 30000;
constexpr ll nx[5] = {-2,-1,0,1,2};
constexpr ll ny[5] = {-2,-1,0,1,2};
int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll h,w,m;
    cin >> h >> w >> m;
    vector<ll> x(h,0),y(w,0);
    map<P,bool> ex;
    ll s,t;
    rep(i,m){
        cin >> s >> t;
        s--;t--;
        x[s]++;
        y[t]++;
        ex[P(s,t)] = 1;
    }
    ll mx = 0,my = 0,mi,mj;
    rep(i,h){
        if (chmax(mx,x[i])) mi = i;
    }
    rep(i,w){
        if (chmax(my,y[i])) mj = i;
    }
    ll ans = 0;
    rep(i,w){
        ll c = mx+y[i];
        if (ex[P(mi,i)]) c--;
        chmax(ans,c);
    }
    rep(i,h){
        ll c = my+x[i];
        if (ex[P(i,mj)]) c--;
        chmax(ans,c);
    }
    PRINT(ans);

}



Measured memory_bytes: 64140
import math
X, K, D = map(int, input().split())

if abs(X) >= K*D:
    print(abs(X) - K*D)
else:
    quo = X // D
    rem = X % D
    opp = D - rem
    if (K - quo) % 2 == 0:
        print(rem)
    else:
        print(opp)


Measured memory_bytes: 9176
#include<iostream>
#include<stdio.h>
#include<string>
#include<vector>
#include<map>
#include<tuple>
#include<algorithm>
#include<cmath>
#include<limits>
#include<set>
#include<queue>
using namespace std;
#define int long  long int
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
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; }
typedef pair<int, int>P;
const int INF = 1e8;

signed main() {
	int A, B;
	cin >> A >> B;
	if (A <= 8 && B <= 8)cout << "Yay!";
	else cout << ":(";
}

Measured memory_bytes: 256
#ifndef CLion
#pragma GCC optimize ("O3")
#endif

#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> // Common file
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/numeric>

#define F first
#define S second
#define pb push_back
#define ll long long
#define all(x) x.begin() , x.end()
#define rep(i,s,e) for (int i = s; i < e; ++i)
#define rev(i,s,e) for (int i = s; i > e; --i)
#define mem(a,v) memset(a , v , sizeof a)
//#define mod(x,m) ((x%m + m)%m)
using namespace std;
using namespace __gnu_pbds;
using namespace __gnu_cxx;

template<typename T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag,
        tree_order_statistics_node_update>;

void Main(int cse , bool last){
    int a , b,  c;
    cin >> a >> b >> c;
    int div = a / b + (a % b ? 1 : 0);
    cout << div * c ;
}

int main(){
#ifndef CLion
    ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#endif
#ifdef CLion
    freopen( "in.txt" , "r" , stdin  );
//    freopen( "out.txt", "w" , stdout );
    clock_t st = clock();
#endif

    int t = 1;
//    cin >> t;
    for ( int cse = 1; cse <= t; ++cse ) Main(cse, cse == t);

#ifdef CLion
    clock_t en = clock();
    cout << "\n\nTime: " << fixed << (en - st - 0.0) / CLOCKS_PER_SEC;
#endif
    return 0;
}


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

using namespace std;
typedef long long int LL;
typedef long long int ll;
typedef pair<long long int, long long int> pii;
typedef pair<double, double> pdd;

#define SORT(c) sort((c).begin(),(c).end())
#define BACKSORT(c) sort((c).begin(),(c).end(),std::greater<LL>())
#define FOR(i,a,b) for(LL i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define SP << " " <<

LL mod = 1000000007;

int main()
{
  cin.tie(0);
  ios::sync_with_stdio(false);
  
  LL N,M;
  cin >> N >> M;
  vector<vector<LL>> graph(N);
  
  REP(i,M){
    LL u, v;
    cin >> u >> v;
    u--;
    v--;
    graph[u].push_back(v);
  }

  LL S, T;
  cin >> S >> T;
  S--;
  T--;
  vector<vector<LL>> toutatsu(N, vector<LL>(3, 1145141919));

  priority_queue<pii,vector<pii>,greater<pii>> pq;

  pq.push({0, S});
  toutatsu[S][0] = 0;

  while(!pq.empty()){
    auto a = pq.top();
    pq.pop();
    LL cost = a.first + 1;
    REP(i, graph[a.second].size())
    {
      LL next = graph[a.second][i];
      if(toutatsu[next][cost%3]>cost){
        toutatsu[next][cost % 3] = cost;
        pq.push({cost,next});
      }
    }
  }
  
  if(toutatsu[T][0]!=1145141919){
    cout<<toutatsu[T][0]/3<<endl;
  }else{
    cout<<-1<<endl;
  }
}


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

int n, m, ans, h[100005], v[100005];
int main() {
	int i, t1, t2;
	cin >> n >> m;
	for(i=1; i<=n; i++) scanf("%d", &h[i]);
	while(m--) {
		scanf("%d%d", &t1, &t2);
		if(h[t1] > h[t2]) v[t2] = 1;
		else if(h[t2] > h[t1]) v[t1] = 1;
		else v[t1] = v[t2] = 1;
	}
	for(i=1; i<=n; i++) ans += 1 - v[i];
	cout << ans;
	return 0;
}

Measured memory_bytes: 4468
#include <iostream>
#include<algorithm>
using namespace std;
int a[500][500];
int tomo[500];
int nitomo[500];
int main() {
while(1){
	int n,m;
	cin>>n;
	cin>>m;
	if(n==0 and m==0){break;}
	for(int i=0;i<=499;i++){
		tomo[i]=0;
		nitomo[i]=0;
		for(int j=0;j<=499;j++){
			a[i][j]=0;
		}
	}
	for(int i=0;i<m;i++){
		int u,j;
		cin>>u>>j;
		a[u-1][j-1]=1;
		if(u==1){
			tomo[j-1]=1;
			}
	}
	for(int i=1;i<n;i++){
		if(tomo[i]==1){
			for(int j=1;j<n;j++){
				if(a[j][i]==1){nitomo[j]=1;}
				if(a[i][j]==1){nitomo[j]=1;}
			}
		}
	}
	for(int i=1;i<n;i++){
		if(nitomo[i]==1){tomo[i]=1;}
	}
	int ans=0;
	for(int i=1;i<n;i++){
		if(tomo[i]==1)ans++;
	}
	cout<<ans<<endl;
}
	return 0;
}

Measured memory_bytes: 2140
a,b,c,x,y = map(int,input().split(" "))

if x>=y:
    tmp = min(c*y*2+a*(x-y), x*c*2)
else:
    tmp = min(c*x*2+b*(y-x), y*c*2)

print(min(tmp, a*x+b*y))

Measured memory_bytes: 3060
using System;
using static System.Console;
using static System.Math;
using System.Numerics;
using System.Collections.Generic;
using System.Linq;


namespace AtCoder
{
    public class Program
    {
        public static void Main(string[] args)
        {
            var s = myRead.readLongArray();
            var d = s[1] * s[1];
            var ans = 0;
            for (int i = 0; i < s[0]; i++)
            {
                var k = myRead.readLongArray();
                if ((k[0] * k[0] + k[1] * k[1]) <= d)
                    ans++;
            }
            WriteLine(ans);
            Out.Flush();
        }
    }
    public static class myRead
    {
        public static int readInt() { return int.Parse(ReadLine()); }
        public static long readLong() { return long.Parse(ReadLine()); }
        public static string reatStr() { return ReadLine(); }
        public static int[] readIntArray() { return ReadLine().Split(' ').Select(int.Parse).ToArray(); }
        public static long[] readLongArray() { return ReadLine().Split(' ').Select(long.Parse).ToArray(); }
        public static string[] readStrArray() { return ReadLine().Split(' '); }
    }


    public static class MyMath
    {
        public static long Factorical(long n)
        { return n <= 1 ? 1L : n * Factorical(n - 1); }
        public static long Permutation(long n, long m)
        { return m == 0 ? 1L : (m == n) ? Permutation(n, m - 1) : n * Permutation(n - 1, m - 1); }
        public static long Combination(long n, long m)
        { return n - m > m ? Permutation(n, m) / Factorical(m) : Permutation(n, n - m) / Factorical(n - m); }
        public static long Gcd(long n, long m)
        { return n % m == 0 ? m : Gcd(m, n % m); }
        public static long Lcm(long n, long m)
        { return n * m / Gcd(n, m); }
        public static long Pow(long n, long m)
        { return (m == 1 || m == 0) ? 1L : n * Pow(n, m - 1); }
    }


}

Measured memory_bytes: 41292
from sys import stdin
nii=lambda:map(int,stdin.readline().split())
lnii=lambda:list(map(int,stdin.readline().split()))

n=int(input())
xy=[lnii() for i in range(n)]
xy.sort(key=lambda x:x[0])

ans=n

pq=[]
for i in range(n-1):
  for j in range(i+1,n):
    t_p=xy[j][0]-xy[i][0]
    t_q=xy[j][1]-xy[i][1]
    pq.append([t_p,t_q])

for p,q in pq:
  cnt=0
  for x,y in xy:
    if [x+p,y+q] in xy:
        cnt+=1
  ans=min(ans,n-cnt)

print(ans)

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

#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

#define sf scanf
#define pf printf
#define pb push_back
#define mp make_pair
#define PI ( acos(-1.0) )
#define mod 1000000007LL
#define maxn 100005
#define IN freopen("C.in","r",stdin)
#define OUT freopen("output.txt","w",stdout)
#define FOR(i,a,b) for(i=a ; i<=b ; i++)
#define DBG pf("Hi\n")
#define INF 1000000000
#define i64 long long int
#define eps (1e-8)
#define xx first
#define yy second
#define ln 17
#define off 2

using namespace __gnu_pbds;
using namespace std ;

typedef tree< i64, null_type, less<i64>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;
typedef pair<i64, i64> pii;

int dp[2005][2005][2] ;

int a[2005] , n ;

int f(int i, int j ,int w)
{
    if(i==n) return abs( a[i]-a[j] ) ;
    if(dp[i][j][w]!=-1) return dp[i][j][w] ;

    if(w==0) return dp[i][j][w] = max( f(i+1,j,w) , f(i+1,i,w^1) ) ;
    else return dp[i][j][w] = min( f(i+1,j,w) , f(i+1,i,w^1) ) ;
}

int main()
{
    int i , j , k , l , m ;
    int noNeed ;

    scanf("%d %d",&n,&noNeed) ;
    n++ ;

    for(i=1 ; i<=n ; i++) scanf("%d",&a[i]) ;

    memset(dp,-1,sizeof(dp)) ;

    cout<<f(2,1,0)<<endl ;

    return 0 ;
}


Measured memory_bytes: 31744
//int a = stoi(c); 文字列をintへ
//小文字から大文字
//transform(a.begin(), a.end(), a.begin(), ::toupper);
//途中の出力をそのまま残さない
//数値計算 個数以外はdouble
//map<キー,値> p は辞書。p[キー] = 値
//map 全探索
//auto begin = p.begin(), end = p.end();
//for (auto it = begin; it != end; it++) {}
//mapのキー：it->first mapのバリュー：it->second
//絶対値 abs()
//入力は空白で切れる
//大文字判定 isupper(文字) 小文字判定 islower(文字)
//do{}while(next_permutation(ALL(配列)))
//while(N)で回すとき、Nはコピーを作っておく
//小文字に対応する文字コード：S[i] - 'a'
//文字コード→小文字：(char)(数字+'a')
//グラフの距離:隣接行列で扱う
//等価なものに変換する思考
//bool型　初期値はTrue
//島渡りの問題：中間ノードに着目
//配列はvector<>を使う：意味わからないエラーがなくなる。
//背反な事象にちゃんとわける
//チェックリストはマップを使う
//数が大きい時の比較はstring型で行う
//全て0になったか調べたい->0になるたびにcntする
//またはかかつか
//例外処理は最初にする
#include <bits/stdc++.h>
#define rep(i,N) for(int i = 0; i < N;i++)
#define ALL(a) (a).begin(),(a).end()
#define ll long long int
using namespace std;

//円周率
const double PI = 3.14159265358979323846;
//割るやつ
const ll M = (pow(10, 9) + 7);

// K進数でのNの桁数
ll dig(ll N, ll K) {
	ll dig = 0;
	while (N) {
		dig++;
		N /= K;
	}
	return dig;
}
// a,bの最大公約数
ll gcd(ll a, ll b) {
	if (b == 0) return a;
	return gcd(b, a%b);
}

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

//nC2の計算
ll C(ll N) {
	return N * (N - 1) / 2;
}

//階乗計算
ll f(ll n) {
	if (n == 0 || n == 1) return 1;
	else return (n * f(n - 1)) % M;
}

int main() {
	ll a, b, c, d; cin >> a >> b >> c >> d;

	if (abs(b - d) != 1) cout << 1 << endl;
	else cout << 0 << endl;
}

Measured memory_bytes: 256
//0015 National Budget
//80ÜÅÌ2ÂÌ®Ì«µZÊðoÍ¹æ
//1sÚÉf[^Zbgnª^¦çêé
//^¦çê½â»Ìaª80ð´¦½êAoverflowÆoÍµÄ­¾³¢

#include<iostream>
#include<string>
#include<cstring>
#include<algorithm>
using namespace std;


int main(void)
{
	int n;
	cin >> n;
	while(n--)
	{
		const int N = 80;
		int i;
		string a, b;
		//0ú»@æ­í©çÈ¢ÌÅKÉå«­
		char c[N+10] = "";

		cin >> a >> b;

		//vZµâ·¢æ¤É½]
		reverse(a.begin(), a.end());
		reverse(b.begin(), b.end());

		int aSize, bSize;
		aSize = a.size();
		bSize = b.size();

		//Ü¸ÍAcÉ»ÌÜÜlðüêÄ¢­
		for(int i = 0; i < min( max(aSize, bSize), N+1); i++)
		{
			int s = 0;
			if(i < aSize)
				s += a[i] - '0';
			if(i < bSize)
				s += b[i] - '0';

			c[i] += s;
			c[i+1] += c[i]/10;
			c[i] %= 10;
		}

		//ã©ç©Ä¢ÁÄA0ÈOÌ¶ª»ê½ç¶»·é
		bool isAnswer = false;
		for(i = sizeof(c)-1; i >= 0; i--)
		{
			if(c[i])
				isAnswer = true;
			if(isAnswer)
				c[i] += '0';
		}
		//½]µÄ®¬
		reverse(c, c+strlen(c));

		//àµà80¶ÚªNULL¶Å êÎI[o[t[
		if(c[N])
			cout << "overflow" << endl;
		//dlãA¦ª0ÈçNULL¶ÅÜéÌÅËÁÞ
		else if(c[0] == '\0')
			cout << '0' << endl;
		else
			cout << c << endl;
	}
	return 0;
}

Measured memory_bytes: 0
def WorkloadCalculation(arr,P):
    D=0
    for a in range(len(arr)):
        d=abs(arr[a]-P)
        D += d**2
    return D

N=int(input())
Xlist=[]
X=input().split()
for x in X:
    _x=int(x)
    Xlist.append(_x)

Xlist.sort()
P=Xlist[0]

workload=10000000
STOPflg=False
    
while STOPflg==False:
    _wl=WorkloadCalculation(Xlist,P)
    if _wl < workload:
        workload=_wl
        P+=1
    else:
        print(workload)
        STOPflg=True
        exit()
        
print(workload)

Measured memory_bytes: 3064
#include <iostream>
#include <string>
#include <algorithm>
#include <cstdio>
#include <vector>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <numeric>
#include <cmath>

using namespace std;

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

#define all(x) x.begin(),x.end()

const ll mod = 1e9+7;
const ll INF = 1e9;
const ll MAXN = 1e9;

int main()
{
	int n,x;
	cin>>n>>x;
	vector<int> l(n);
	for (int i = 0; i < n; i++){
		cin>>l[i];
	}
	vector<int> sum(n+1,0);
	int ans = 0;
	for ( int i = 1; i <= n; i++){
		sum[i] = sum[i-1] + l[i-1];
	}
	for (int i = 0; i <= n; i++){
		if(sum[i]<=x) ans++;
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 256
#pragma GCC optimize("Ofast") 
#include<bits/stdc++.h>
using namespace std;
#define pb push_back
#define fi first
#define se second
#define mp make_pair
#define all(a) a.begin(),a.end()
#define lb lower_bound
#define ub upper_bound
#define owo ios_base::sync_with_stdio(0);cin.tie(0);
#define MOD (ll)(1e6+3)
#define INF (ll)(1e18)
#define debug(...) fprintf(stderr, __VA_ARGS__),fflush(stderr)
#define time__(d) for(long blockTime = 0; (blockTime == 0 ? (blockTime=clock()) != 0 : false);\
debug("%s time : %.4fs\n", d, (double)(clock() - blockTime) / CLOCKS_PER_SEC))
typedef long long int ll;
typedef long double ld;
typedef pair<ll,ll> PII;
typedef pair<int,int> pii;
typedef vector<vector<int>> vii;
typedef vector<vector<ll>> VII;
ll dp[3001][3001];
string s,t;
string ans;
int n,m;
int main()
{
	cin>>s>>t;
	n = s.length();
	m = t.length();
	for(int i=0;i<n;i++)
	    for(int j=0;j<m;j++)dp[i][j] = -1;
	    
	for(int i=0;i<=n;i++){
		for(int j=0;j<=m;j++){
			if(!i || !j)dp[i][j] = 0;
			else if(s[i-1] == t[j-1])dp[i][j] = dp[i-1][j-1]+1;
			else{
				dp[i][j] = max(dp[i-1][j],dp[i][j-1]);
			}
		}
	}
	int i = n,j = m;
	while(i > 0 && j > 0){
		if(s[i-1] == t[j-1]){
			ans+=s[i-1];
			i--;
			j--;
		}
		else if(dp[i][j-1] > dp[i-1][j])j--;
		else i--;
	}
	reverse(all(ans));
	cout<<ans;
	
	
}


Measured memory_bytes: 73984
/*
confirm 0LL and 1LL
confirm cornercases such as 0
confirm times of cin < 10^6
*/
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using P = pair<ll, ll>;
using Pld = pair<ld, ld>;
using Vec = vector<ll>;
using VecP = vector<P>;
using VecB = vector<bool>;
using VecC = vector<char>;
using VecD = vector<ld>;
using VecS = vector<string>;
using Graph = vector<VecP>;
template <typename T>
using Vec1 = vector<T>;
template <typename T>
using Vec2 = vector<Vec1<T> >;
#define REP(i, m, n) for(ll i = (m); (i) < (n); ++(i))
#define REPN(i, m, n) for(ll i = (m); (i) <= (n); ++(i))
#define REPR(i, m, n) for(ll i = (m)-1; (i) >= (n); --(i))
#define REPNR(i, m, n) for(ll i = (m); (i) >= (n); --(i))
#define rep(i, n) REP(i, 0, n)
#define repn(i, n) REPN(i, 1, n)
#define repr(i, n) REPR(i, n, 0)
#define repnr(i, n) REPNR(i, n, 1)
#define all(s) (s).begin(), (s).end()
#define pb push_back
#define fs first
#define sc second
template <typename T>
bool chmax(T &a, const T b){if(a < b){a = b; return true;} return false;}
template <typename T>
bool chmin(T &a, const T b){if(a > b){a = b; return true;} return false;}
template <typename T>
ll pow2(const T n){return (1LL << n);}
template <typename T>
void cosp(const T n){cout << n << ' ';}
void co(void){cout << '\n';}
template <typename T>
void co(const T n){cout << n << '\n';}
template <typename T1, typename T2>
void co(pair<T1, T2> p){cout << p.fs << ' ' << p.sc << '\n';}
template <typename T>
void co(const Vec1<T> &v){for(T i : v) cosp(i); co();}
template <typename T>
void co(initializer_list<T> v){for(T i : v) cosp(i); co();}
template <typename T>
void ce(const T n){cerr << n << endl;}
void sonic(){ios::sync_with_stdio(false); cin.tie(0);}
void setp(const ll n){cout << fixed << setprecision(n);}
constexpr int INF = 1e9+1;
constexpr ll LINF = 1e18+1;
constexpr ll MOD = 1e9+7;
//constexpr ll MOD = 998244353;
constexpr ld EPS = 1e-11;
const ld PI = acos(-1);

ll n, m, x;
ll c[15];
ll a[15][15];

ll dfs(ll p, Vec s){
	if(p == n){
		rep(i, m) if(s[i] < x) return LINF;
		return 0;
	}

	ll res = LINF;
	chmin(res, dfs(p + 1, s));
	rep(i, m) s[i] += a[p][i];
	chmin(res, c[p] + dfs(p + 1, s));
	return res;
}

int main(void){
	cin >> n >> m >> x;
	rep(i, n){
		cin >> c[i];
		rep(j, m) cin >> a[i][j];
	}

	Vec s(m);
	ll ans = dfs(0, s);
	if(ans == LINF) co(-1);
	else co(ans);

	return 0;
}


Measured memory_bytes: 3624
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep1(i, n) for (int i = 1; i <= (int)(n); i++)
typedef int64_t Int;
typedef pair<int,int> pii;
const int INF = 1e8;

vector<vector<int>> G(100010);

void bfs(int s, vector<int> &dist){
    queue<int> Q;
    Q.push(s); dist[s] = 0;

    while(!Q.empty()){
        int now = Q.front(); Q.pop();
        rep(i,G[now].size()){
            int to = G[now][i];
            if(dist[now] + 1 < dist[to]){
                dist[to] = dist[now] + 1;
                Q.push(to);
            }
        }
    }
}

int main(){ 
    int N, u, v; cin >> N >> u >> v; u--; v--;

    rep(i,N-1){
        int A, B; cin >> A >> B; A--; B--;
        G[A].push_back(B);
        G[B].push_back(A);
    }

    vector<int> dist_u(100010, INF), dist_v(100010, INF);
    bfs(u, dist_u);
    bfs(v, dist_v);

    vector<int> leaves;
    rep(i,N){
        if(G[i].size() == 1) leaves.push_back(i);
    }

    int ans = 0;
    rep(i,leaves.size()){
        //cout << leaves[i] << " " << dist_u[leaves[i]] << " " << dist_v[leaves[i]] << endl;
        if(dist_u[leaves[i]] < dist_v[leaves[i]]){
            ans = max(ans, dist_v[leaves[i]]);
        }
    }

    cout << ans -1 << endl;
}

Measured memory_bytes: 7040
#include <iostream>
#include <algorithm>
#include <vector>
#include <cmath>
#include <cstdio>
#include <string>
#include <map>
#include <set>
#include <queue>
#include <stack>
using namespace std;
#define MOD 1000000007
typedef long long ll;


int main(void) {
  int n;
  cin >> n;
  int ans=0;
  for(int i = 1; i <= n; ++i) {
    int cnt=0;
    int a = i;
    while(a != 0) {
      a /= 10;
      ++cnt;
    }
    if((cnt%2) != 0) ++ans;
  }

  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 256
#pragma GCC optimize ("Ofast","unroll-loops")
#include <bits/stdc++.h>
#define pb push_back
#define eb emplace_back
#define MP make_pair
#define F first
#define S second
#define MEM(a,b) memset(a,b,sizeof a)
#define Tie ios::sync_with_stdio(0),cin.tie(0);
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;

ll n,m,a[101],dp[101][100001];
const ll MOD=1e9+7;

int main()
{Tie
	cin>>n>>m,dp[0][0]=1;
	for(int i=1;i<=n;i++)
		cin>>a[i],dp[i][0]=1;
	for(int i=1;i<=m;i++)
		dp[0][i]=1;
	for(int i=1;i<=n;i++)
		for(int j=1;j<=m;j++)
		{
			dp[i][j]=(dp[i][j-1]+dp[i-1][j])%MOD;
			if(j-a[i]>0)
				dp[i][j]=((dp[i][j]-dp[i-1][j-a[i]-1])%MOD+MOD)%MOD;
		}
	cout << (dp[n][m]-dp[n][m-1]+MOD)%MOD<<'\n';
}

Measured memory_bytes: 79232