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

void rotation(int *dice, int a, int b);

int main(void){
    int dice[6], i;
    char op[101];
    
    scanf("%d%d%d%d%d%d%s", &dice[0], &dice[1], &dice[2], &dice[3], &dice[4], &dice[5], op);
    for(i = 0; op[i] != '\0'; i++) {
        switch(op[i]) {
            case 'N':
                rotation(dice, 1, 4);
                break;
                
            case 'E':
                rotation(dice, 3, 2);
                break;
                
            case 'W':
                rotation(dice, 2, 3);
                break;
                
            case 'S':
                rotation(dice, 4, 1);
                break;
                
            default:
                break;
        }
    }
    printf("%d\n", dice[0]);
    
}

void rotation(int *dice, int a, int b) {
    int tmp;
    tmp = dice[0];
    dice[0] = dice[a];
    dice[a] = dice[5];
    dice[5] = dice[b];
    dice[b] = tmp;
}


Measured memory_bytes: 2104
n = gets.to_i
m = n*(n+1)/2
for i in 2..n
    next if m%i != 0
    a = Array.new(i).map{[]}
    s = m/i
    used = Array.new(n,false)
    for j in 0..i-1
        t = 0
        n.downto(1) do |k|
            if t+k <= s && used[k-1] == false
                used[k-1] = true
                t += k
                a[j] << k
            end
        end
    end
    ls = Array.new(n).map{Array.new(n,true)}
    for j in 0..i-1
        a[j].each do |x|
            a[j].each do |y|
                ls[x-1][y-1] = false
            end
        end
    end
    cnt = 0
    for j in 0..n-1
        for k in j..n-1
            cnt += 1 if ls[j][k]
        end
    end
    puts cnt
    for j in 0..n-1
        for k in j..n-1
            puts "#{j+1} #{k+1}" if ls[j][k]
        end
    end
    break
end

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

using namespace std;

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

    int M; long K; cin>>M>>K;
    if (1ul<<M <= K) {
        cout << -1 << endl;
        return 0;
    }
    if (M == 0) {
        cout << 0 << ' ' << 0 << endl;
    } else if (M == 1 and K == 1) {
            cout << -1 << endl;
    } else if (K == 0) {
        for (long i = 0; i < 1ull<<M; i++) {
            cout << i << ' ' << i << ' ';
        }
        cout << '\n';
    } else {
        vector<long> a;
        for (long i = 0; i < 1ull<<M; i++)
            a.push_back(i);
        a.erase(a.begin() + K);
        vector<long> ret;
        ret.push_back(K);
        ret.insert(ret.end(), a.begin(), a.end());
        ret.push_back(K);
        ret.insert(ret.end(), a.rbegin(), a.rend());
        for (auto n : ret) cout << n << " ";
        cout << endl;
    }
    
    return 0;
}



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


int main(){
	std::cout<<std::fixed<<std::setprecision(10);
	int n,i;
	double deno = 0,x = 1,add,ans;
	cin >> n;
	double a[n];

	for(i = 0; i < n; i++){
		cin >> a[i];
	}
	for(i = 0; i < n; i++){
		add = x/a[i];
		deno = deno + add;
	}
	ans = x/deno;

	cout << ans;

	return 0;
}


Measured memory_bytes: 256
import sys
sys.setrecursionlimit(10 ** 9)
N, X = map(int, input().split())


def rec(a, b):
    a, b = min(a, b), max(a, b)
    if b % a == 0:
        return (2 * a) * (b // a) - a
    else:
        return (2 * a) * (b // a) + rec(a, b % a)


print(X + N - X + rec(X, N - X))


Measured memory_bytes: 2940
N, M = gets.split.map(&:to_i)
max = [N, M].max
min = [N, M].min

MOD = 10**9 + 7

if max - min > 1
    puts 0
    exit
else
    prod = 1
    (1..max).each do |i|
        prod = prod * i % MOD
    end
    (1..min).each do |i|
        prod = prod * i % MOD
    end
    prod = prod * 2 % MOD if max == min
    puts prod
end

Measured memory_bytes: 1916
#include <iostream>
#include <queue>
#include <map>
#include <bitset>
#include <string>
#include <set>
#include <cstdio>
#include <cmath>
#include <algorithm>
#include <cstring>
#include <iomanip>
#include <ctime>
#include <stack>
#include <cstdlib>
#include <numeric>
#include <cassert>
#include <complex>
#include <iterator>
//#include <unordered_map>
using namespace std;
#define maxn 100007
#define maxm 400007
#define maxq 1000007
#define maxl 1234
#define modn 1000000007
#define scan(a) scanf("%d",&a)
#define scanl(a) scanf("%lld",&a)
#define scanl2(a,b) scanf("%lld%lld",&a,&b)
#define scans(a) scanf("%s",a)
#define scans2(a,b) scanf("%s%s",a,b)
#define scand(a) scanf("%lf",&a)
#define scan2(a,b) scanf("%d%d",&a,&b)
#define scand2(a,b) scanf("%lf%lf",&a,&b)
#define scan3(a,b,c) scanf("%d%d%d",&a,&b,&c)
#define scan4(a,b,c,d) scanf("%d%d%d%d",&a,&b,&c,&d)
#define scan5(a,b,c,d,e) scanf("%d%d%d%d%d",&a,&b,&c,&d,&e)
#define print(a) printf("%d\n",a);
#define printl(a) printf("%lld\n",a);
#define rep(i,a,b) for(int i=a;i<=b;i++)
#define rrep(i,a,b) for(int i=a;i>= b;i--)
#define fscan(a) fscanf(stream,"%d", &a);
#define mp      make_pair	
#define pb      push_back
#define eb      emplace_back
#define mm(a,b) memset(a,b,sizeof a)
#define log2(n) (double)(log(n) / log(2.0))
#define _crt_disable_perfcrit_locks
#define bll __int128
#pragma warning(disable:4996)
typedef long long ll;
typedef unsigned long long ull;
const int inf = 0x3f3f3f3f;
typedef vector <int> vi;
typedef vector <ll> vll;
typedef map <ll, ll> mll;
typedef pair <ll, ll> pll;
typedef map <int, int> mii;
typedef pair <int, int> pii;
typedef map <char, int> mci;
typedef map <char, char> mcc;
typedef pair <char, int> pci;
typedef complex<double> cd;
typedef vector<complex<double> > vcd;
const double eps = 1e-8;
const double PI = 2 * acos(0.0);

int cc, bb; char ch; inline int F() {
	while (ch = getchar(), (ch < 48 || ch> 57) && ch != '-'); ch == '-' ? cc = bb = 0 : (cc = ch - '0', bb = 1);
	while (ch = getchar(), ch > 47 && ch < 58)cc = (cc << 1) + (cc << 3) + (ch ^ 48); return bb ? cc : -cc;
}
void write(int x) {
	int y = 10, len = 1;
	while (y <= x) { y *= 10; len++; }
	while (len--) { y /= 10; putchar(x / y + 48); x %= y; }
}

int main() {
	//ios::sync_with_stdio(0);
	//cin.tie(0);
	//FILE* stream = fopen("L:/20.in", "rb+")
	int x, y, z;
	cin >> x >> y >> z;
	swap(x, y);
	swap(x, z);
	cout << x << " " << y << " " << z << endl;
	
	
	
	return 0;
}

Measured memory_bytes: 256
n, a, b = list(map(int, input().split()))

MOD = 10 ** 9 + 7


def ncr(n, r, p):
    # initialize numerator
    # and denominator
    num = den = 1
    for i in range(r):
        num = (num * (n - i)) % p
        den = (den * (i + 1)) % p
    return (num * pow(den, p - 2, p) + p) % p


print((pow(2, n, MOD) - 1 - ncr(n, a, MOD) - ncr(n, b, MOD)) % MOD)



Measured memory_bytes: 3060
#099_C
n=int(input())
def Count(x,p):
    res=0
    while x:
        res+=x%p
        x=x//p
    return res

ans=10**6+1
for i in range(0,n+1):
    ans=min(ans,Count(i,6)+Count(n-i,9))
    
print(ans)

Measured memory_bytes: 3060
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.IO;
using System.Text;
using System.Globalization;
using System.Diagnostics;
 
 
 
class Solve
{
    public Solve() { }
    public static int Main()
    {
        new Solve().calc();
        return 0;
    }
 
 
    Scanner cin;
 
    void calc()
    {
        cin = new Scanner();
        int N = cin.nextInt();
        int[] A = new int[N+2];

        A[0] = 0;
        A[N + 1] = 0; 
        for (int i = 0; i < N; i++){
            A[i+1] = cin.nextInt();
        }
        int sum = 0;
        for (int i = 0; i < N+1; i++){
            sum += Math.Abs(A[i] - A[i+1]);
        }
        for (int i = 1; i < N+1; i++)
        {
            int minus = Math.Abs(A[i - 1] - A[i]) + Math.Abs(A[i] - A[i + 1]);
            int plus = Math.Abs(A[i - 1] - A[i + 1]);
            int result = sum - minus + plus;
            Console.WriteLine(result.ToString());
        }
    }
}
public class Point
{
    public int Color;
    public int X;
    public int Y;
    public Point(int color, int x, int y)
    {
        Color = color;
        X = x;
        Y = y;
    }
}
 
class Scanner
{
    string[] s;
    int i;
 
    char[] cs = new char[] { ' ' };
 
    public Scanner()
    {
        s = new string[0];
        i = 0;
    }
 
    public string next()
    {
        if (i < s.Length) return s[i++];
        string st = Console.ReadLine();
        while (st == "") st = Console.ReadLine();
        s = st.Split(cs, StringSplitOptions.RemoveEmptyEntries);
        if (s.Length == 0) return next();
        i = 0;
        return s[i++];
    }
 
    public int nextInt()
    {
        return int.Parse(next());
    }
    public int[] ArrayInt(int N, int add = 0)
    {
        int[] Array = new int[N];
        for (int i = 0; i < N; i++)
        {
            Array[i] = nextInt() + add;
        }
        return Array;
    }
 
    public long nextLong()
    {
        return long.Parse(next());
    }
 
    public long[] ArrayLong(int N, long add = 0)
    {
        long[] Array = new long[N];
        for (int i = 0; i < N; i++)
        {
            Array[i] = nextLong() + add;
        }
        return Array;
    }
 
    public double nextDouble()
    {
        return double.Parse(next());
    }
 
 
    public double[] ArrayDouble(int N, double add = 0)
    {
        double[] Array = new double[N];
        for (int i = 0; i < N; i++)
        {
            Array[i] = nextDouble() + add;
        }
        return Array;
    }
}

Measured memory_bytes: 26840
// reference: https://qiita.com/tanakh/items/0ba42c7ca36cd29d0ac8
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
    ($($r:tt)*) => {
        let mut 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, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($iter, $t);
        input_inner!{$iter $($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) => {
        read_value!($iter, String).chars().collect::<Vec<char>>()
    };

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

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

fn main() {
    input! {
        s: chars
    }

    let y = s[..4]
        .iter()
        .cloned()
        .collect::<String>()
        .parse::<i64>()
        .unwrap();
    let m = s[5..7]
        .iter()
        .cloned()
        .collect::<String>()
        .parse::<i64>()
        .unwrap();
    let d = s[8..]
        .iter()
        .cloned()
        .collect::<String>()
        .parse::<i64>()
        .unwrap();
    let x = y * 10000 + m * 100 + d;
    let ans = if x <= 20190430 { "Heisei" } else { "TBD" };

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


Measured memory_bytes: 4352
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Text;

class Program

{
    public Program() { }
    public static int Main()
    {
        cin = new Scanner();
        new Program().calc();
        return 0;
    }
    static Scanner cin;

    void calc()
    {
        long N, A, B;
        N = cin.nextLong();

        long count = 0;
        long now = 100;
        while (now < N)
        {
            count++;
            now = (long)(now * 1.01);
        }


        Console.WriteLine(count);


    }



}


class Scanner
{
    string[] s;
    int i;

    char[] cs = new char[] { ' ' };

    public Scanner()
    {
        s = new string[0];
        i = 0;
    }

    public string next()
    {
        if (i < s.Length) return s[i++];
        string st = Console.ReadLine();
        while (st == "") st = Console.ReadLine();
        s = st.Split(cs, StringSplitOptions.RemoveEmptyEntries);
        if (s.Length == 0) return next();
        i = 0;
        return s[i++];
    }

    public int nextInt()
    {
        return int.Parse(next());
    }
    public int[] ArrayInt(int N, int add = 0)
    {
        int[] Array = new int[N];
        for (int i = 0; i < N; i++)
        {
            Array[i] = nextInt() + add;
        }
        return Array;
    }

    public long nextLong()
    {
        return long.Parse(next());
    }

    public long[] ArrayLong(int N, long add = 0)
    {
        long[] Array = new long[N];
        for (int i = 0; i < N; i++)
        {
            Array[i] = nextLong() + add;
        }
        return Array;
    }

    public double nextDouble()
    {
        return double.Parse(next());
    }


    public double[] ArrayDouble(int N, double add = 0)
    {
        double[] Array = new double[N];
        for (int i = 0; i < N; i++)
        {
            Array[i] = nextDouble() + add;
        }
        return Array;
    }
}


class XRand
{
    uint x, y, z, w;


    public XRand()
    {
        init();
    }

    public XRand(uint s)
    {
        init();
        init_xor128(s);
    }

    void init()
    {
        x = 314159265; y = 358979323; z = 846264338; w = 327950288;

    }

    public void init_xor128(uint s)
    {
        z ^= s;
        z ^= z >> 21; z ^= z << 35; z ^= z >> 4;
        z *= 736338717;
    }

    uint next()
    {
        uint t = x ^ x << 11; x = y; y = z; z = w; return w = w ^ w >> 19 ^ t ^ t >> 8;
    }

    public long nextLong(long m)
    {
        return (long)((((ulong)next() << 32) + next()) % (ulong)m);
    }

    public int nextInt(int m)
    {
        return (int)(next() % m);
    }

    public int nextIntP(int a)
    {
        return (int)Math.Pow(a, nextDouble());
    }

    public int nextInt(int min, int max)
    {
        return min + nextInt(max - min + 1);
    }


    public double nextDouble()
    {
        return (double)next() / uint.MaxValue;
    }

    public double nextDoubleP(double a)
    {
        return Math.Pow(a, nextDouble());
    }
}

Measured memory_bytes: 27552
#include <bits/stdc++.h>
using namespace std;
 
int arr[100010];
 
int main() {
  int N, M;
  cin >> N >> M;
  int l[M], r[M];
  for (int i = 0; i < M; i++) cin >> l[i] >> r[i];
  
  for (int i = 0; i < M; i++) {
    arr[l[i]]++;
    arr[r[i]+1]--;
  }
  
  for (int i = 1; i < 100010; i++) arr[i] += arr[i-1];
  
  int ans = 0;
  for (int i = 0; i < 100010; i++) if (arr[i] == M) ans++;
  
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 1408
package main

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

func main() {
	scanInit()

	n := nextInt()
	p := nextStr()
	s := nextStr()
	maxm := 0
	for i := 0; i < n; i++ {
		matchp := 0
		for j := 0; i+j < n; j++ {
			if p[i+j] != s[j] {
				break
			}
			matchp++
		}
		maxm = max(maxm, matchp)
	}

	fmt.Println(2*n - maxm)

}
func max(a, b int) int {
	if a > b {
		return a
	}
	return b
}

// ---- readfunc
var sc = bufio.NewScanner(os.Stdin)

func scanInit() {
	const cap = 200 * 1024 // default=64*1024
	var buf = make([]byte, cap)
	sc.Buffer(buf, cap)
	sc.Split(bufio.ScanWords)
	return
}
func nextInt() int {
	sc.Scan()
	i, _ := strconv.Atoi(sc.Text())
	return i
}
func nextStr() string {
	sc.Scan()
	return sc.Text()
}


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

using namespace std;
const int mod = 1e9 + 7;
int n;
long long k;
void add(int &a, int b){
    a = (a + b) % mod;
}
int mul(int a, int b){
    return (a * 1ll * b) % mod;
}
struct M{
    vector < vector < int > > v;
    M(){
        v.resize(n, vector < int > (n, 0));
    }
    M operator*(const M& b) const {
        M c;
        for(int i = 0; i < n; i++){
            for(int j = 0; j < n; j++){
                for(int t = 0; t < n; t++){
                    add(c.v[i][t], mul(v[i][j], b.v[j][t]));
                }
            }
        }
        return c;
    }
};
int main(){
    cin >> n >> k;
    vector < vector < int > > v(n, vector < int > (n, 0));
    for(int i = 0; i < n; i++){
        for(int j = 0; j < n; j++){
            cin >> v[i][j];
        }
    }
    M answer;
    for(int i = 0; i < n; i++){
        answer.v[i][i] = 1;
    }
    M m;
    m.v = v;
    while(k > 0){
        if(k % 2 == 1){
            answer = answer * m;
        }
        m = m * m;
        k /= 2;
    }
    int ans = 0;
    for(int i = 0; i < n; i++){
        for(int j = 0; j < n; j++){
            add(ans, answer.v[i][j]);
        }
    }
    cout << ans;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
  using namespace std;
#define ll long long
#define fw(p) for(int w=0;w<(p);w++)
#define fx(p) for(int x=0;x<(p);x++)
#define fy(p) for(int y=0;y<(p);y++)
#define fz(p) for(int z=0;z<(p);z++)
#define fyg(p,g) for(int y=(g);y<(p);y++)
#define fzg(p,g) for(int z=(g);z<(p);z++)
#define ce(d) cout<<d<<endl;
#define vecp(p) int aa;cin>>aa;(p).push_back(aa);
#define vecpl(p) long long aa;cin>>aa;(p).push_back(aa);
#define vecps(p) string aa;cin>>aa;(p).push_back(aa);
#define vecp2(p) cin>>aa;(p).push_back(aa);
#define vecpl2(p) long long a	b;cin>>ab;(p).push_back(ab);
#define vecps2(p) string ab;cin>>ab;(p).push_back(ab);
#define set0(k,n) for(int nn=0;nn<(n);nn++){ (k).push_back(0); }
#define sorts(c) sort((c).begin(),(c).end());
#define reverses(c) reverse((c).begin(),(c).end());
#define vec(b) vector<int> (b);
#define vecl(b) vector<long long> (b);
#define vecs(b) vector<string> (b);
#define vecsize(b,size) vector<int> (b)((size));
#define pb(b,a) (b).push_back((a));
#define doublece(a,b) cout<<(a)<<' '<<(b)<<endl;
#define pairs(s) vector<pair<int,int>> (s);
#define pairsl(s) vector<pair<ll,ll>> (s);
#define pairss(s) vector<pair<string,string>> (s);
#define pairsp(s) int aa,bb;cin>>aa>>bb;(s).push_back(make_pair(aa,bb));
#define pairspl(s) ll aa,bb;cin>>aa>>bb;(s).push_back(make_pair(aa,bb));
#define pairsps(s) string aa,bb;cin>>aa>>bb;(s).push_back(make_pair(aa,bb));
#define pairsREV(s) (s).push_back(make_pair(bb,aa));
#define pairslREV(s) (s).push_back(make_pair(bb,aa));
#define pairssREV(s) (s).push_back(make_pair(bb,aa));
#define MOD 1000000007

int main() {
		
	int N;
	vec(L)
	cin>>N;
	fx(N*2){
		vecp(L)
	}
	sorts(L)
	int ans=0;
	for(int x=0;x<N*2;x+=2){
		ans+=L.at(x);
	}
	ce(ans)
	
}

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

int main(){
  int N;
  cin >> N;
  map<int, set<pair<int, int>>> mp;
  for (int i=0; i<N; i++){
    int u, v, w;
    cin >> u >> v >> w;
    mp[u].insert(make_pair(v,w));
    mp[v].insert(make_pair(u,w));
  }
  vector<long long> dst(N+1,-1);
  queue<int> q;
  q.push(1);
  dst[1] = 0;
  while (!q.empty()){
    int check = q.front();
    q.pop();
    for (auto k: mp[check]){
      if (dst[k.first]<0){
        q.push(k.first);
        dst[k.first] = dst[check]+k.second;
      }
    }
  }
  for (int i=1; i<=N; i++){
    cout << dst[i]%2 << endl;
  }
}


Measured memory_bytes: 19968
N, M = map(int, input().split())
H = list(map(int, input().split()))
H.insert(0, 0)
t = [True] * (N+1)

for i in range(M):
    a, b = map(int, input().split())
    if H[a] <= H[b]:
        t[a] = False
    if H[b] <= H[a]:
        t[b] = False

c = 0
for i in range(1, N+1, 1):
    if t[i]:
        c += 1

print(c)

Measured memory_bytes: 20052
#include <cstdio>
using namespace std;
int n;
int a[11];
int main() {
    scanf("%d", &n);
    for (int t = 0; t < n; ++t) {
        int l = 0, r = 0;
        for (int i = 0; i < 10; ++i) scanf("%d", &a[i]);
        bool flag=false;
        for (int i = 0; i < 10; ++i) {
            if (r > l) {
                if (a[i] > r) r = a[i];
                else if (a[i] > l) l = a[i];
                else flag=true;
            } else {
                if (a[i] > l) l = a[i];
                else if (a[i] > r) r = a[i];
                else flag=true;
            }
        }
        if (flag) printf("NO\n");
        else printf("YES\n");

    }
    return 0;
}



Measured memory_bytes: 2576
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <vector>
#include <queue>
#include <map>
using namespace std;

int main() {
	
	int N;
	cin >> N;
	
	string str[500];
	
	for(int i = 0; i < N; i++){
		cin >> str[i];
	}
	
	int ans = 0;
	
	for(int loop = 0; loop < N; loop++){
		string ss = str[0];
		for(int i = 0; i < N - 1; i++){
			str[i] = str[i + 1];
		}
		str[N - 1] = ss;
		
		bool flag = true;
		for(int i = 0; i < N; i++){
			for(int j = 0; j < N; j++){
				if(str[i][j] != str[j][i]){
					flag = false;
				}
			}
		}
		if(flag){
			ans += N;
		}
	}
	
	cout << ans << endl;
	
	return 0;
}



Measured memory_bytes: 384
#include <iostream>
#include <algorithm>
#include <cstdio>
#include <vector>
#include <math.h>
#include <iomanip>
#include <bitset>
#include <string>
#include <cstring>
#include <stdlib.h>
#include <utility>
#include <set>
#include <queue>
using namespace std;
typedef long long int ll;
typedef long double ld;
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; }
const long long INF = 1LL << 60;
typedef pair<ll,ll> pairs;
vector<pairs> p;
bool pairCompare(const pair<double,ll>& firstElof, const pair<double,ll>& secondElof){
    return firstElof.first < secondElof.first;
}
bool pairCompareSecond(const pair<double,ll>& firstElof, const pair<double,ll>& secondElof){
    return firstElof.second < secondElof.second;
}
#define MAX_N 100100
#define MOD 1000000007
bool x[MAX_N];
ll num[MAX_N];
ll fibl[MAX_N]={0};
// 四方向への移動ベクトル
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};

ll fib(ll a){
    if (fibl[a]!=0)return fibl[a];
    if (a==0){
        return 0;
    }else if (a==1){
        return 1;
    }
    return fibl[a]=fib(a-1)+fib(a-2);
}
 
ll eratosthenes(ll n) {
    int p = 0;
    for (ll i=0; i<=n; ++i) x[i] = true;
    x[0] = x[1] = false;
    for(int i=2; i<=n; ++i) {
        if(x[i]) {
            p++;
            for(int j=2*i; j<=n; j+=i) x[j] = false;
        }
        
        num[i] = p;
    }
    return p;
}
 
ll gcd(ll a,ll b){
    if (a%b==0)return(b);
    else return(gcd(b,a%b));
}
 
ll keta(ll N){
    int tmp{};
    while( N > 0 ){
        tmp += ( N % 10 );
        N /= 10;
    }
    N = tmp;
    return N;
}

int main(){
    ll n,k,ans=INF;
    cin >> n>> k;
    ll tree[n];
    for (ll i=0;i<n;i++)cin >> tree[i];
    sort(tree,tree+n);
    for (ll i=k-1;i<n;i++){
        ans=min(ans,tree[i]-tree[i-k+1]);
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 1024
#include <iostream>
#include <map>
#include <set>
#include <string>
using namespace std;

int main()
{
    map<string,set<int>> p;
    string str;
    int t;
    while (cin >> str >> t) p[str].insert(t);
    for (auto it = p.begin(); it != p.end(); it++) {
        auto s = it->second.begin();
        cout << it->first  << endl << *s;
        for (++s; s != it->second.end(); s++)
            cout << " " << *s;
        cout << endl;
    }

    return 0;
}

Measured memory_bytes: 1228
#include<algorithm>
#include<cstring>
#include<iostream>

using namespace std;

int main() {
	int n, k;
	scanf("%d%d", &n, &k);

	int a[n];
	for(int i=0; i<n; i++) {
		scanf("%d", &a[i]);
	}
	sort(a, a+n);
	int dp[k+1];
	memset(dp, 0, sizeof dp);
	for(int i=1; i<=k; i++) {
		for(int j=0; j<n && i-a[j]>=0; j++) {
			if(dp[i-a[j]]==0) {
				dp[i] = 1;
				break;
			}
		}
	}
	if(dp[k]) printf("First\n");
	else printf("Second\n");
    return 0;
}

Measured memory_bytes: 640
n = int(input())
l = sorted(list(map(int, input().split())))
ans = 0
for a in range(len(l)):
  i = l[a]
  for b in range(a+1,len(l)):
    j = l[b]
    for c in range(b+1,len(l)):
      k = l[c]
      if i<j<k and i+j>k and j+k>i and k+i>j:
        ans += 1
print(ans)

Measured memory_bytes: 9228
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#ifdef tabr
#include "library/debug.cpp"
#else
#define debug(...)
#endif

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    string s;
    int k;
    cin >> s >> k;
    int n = s.size();
    vector<vector<vector<int>>> dp(n, vector<vector<int>>(n, vector<int>(k + 1)));
    for (int i = n - 1; i >= 0; i--) {
        for (int j = i; j <= n - 1; j++) {
            for (int l = 0; l <= k; l++) {
                if (i == j) {
                    dp[i][j][l] = 1;
                } else if (i + 1 == j) {
                    dp[i][j][l] = 2;
                    if (l == 0 && s[i] != s[j]) {
                        dp[i][j][l] = 1;
                    }
                } else {
                    dp[i][j][l] = max(dp[i + 1][j][l], dp[i][j - 1][l]);
                    // dp[i][j][l] = max(dp[i][j][l], dp[i + 1][j - 1][l] + 1);
                    if (s[i] == s[j]) {
                        dp[i][j][l] = max(dp[i][j][l], dp[i + 1][j - 1][l] + 2);
                    } else if (l != 0) {
                        dp[i][j][l] = max(dp[i][j][l], dp[i + 1][j - 1][l - 1] + 2);
                    }
                }
            }
        }
    }
    cout << dp[0][n - 1][k] << '\n';
    return 0;
}


Measured memory_bytes: 109568
#include<iostream>
#include<vector>
#include<algorithm>
#include<math.h>
#include<iomanip>
#include<map>
#include<deque>
using namespace std;
typedef long long ll;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define erep(i, n) for (int i = 0; i <= (int)(n); i++)
using p = pair<int, int>;

int main() {
    string s, t; cin >> s >> t;
    vector<string> vec(0);
    rep (i, s.size()) {
        if (s[i] == '?' || s[i] == t[0]) {
            string tmp = s;
            bool flag = true;
            rep (j, t.size()) {
                if (tmp[i + j] == '?' || tmp[i + j] == t[j]) tmp[i + j] = t[j];
                else flag = false;
            }
            if (flag) {
                replace(tmp.begin(), tmp.end(), '?', 'a');
                vec.push_back(tmp);
            }
        }
    }
    if (vec.size() == 0) cout << "UNRESTORABLE" << endl; 
    else {
        sort(vec.begin(), vec.end());
        cout << vec[0] << endl;
    }
}


Measured memory_bytes: 256
#include <stdio.h>

#define N 100
#define NIL -1

int Pre(int t);
int In(int t);
int Post(int t);

struct Node{
  int p, left, right;
};
struct Node A[N];

int main(){

  int i, j;
  int n, id, h, d;

  scanf("%d", &n);

  for(i = 0; i < n; i++){
   A[i].p = NIL;
   A[i].left = NIL;
   A[i].right = NIL;
  }

  for(i = 0; i < n; i++){
    scanf("%d %d %d", &id, &h, &d);
    A[h].p = id;
    A[d].p = id;
    A[id].left = h;
    A[id].right = d;
  }

  for(i = 0; i < n; i++)
    if(A[i].p == NIL) break;

  printf("Preorder\n");
  Pre(i);
  printf("\n");

  printf("Inorder\n");
  In(i);
  printf("\n");

  printf("Postorder\n");
  Post(i);
  printf("\n");

  return 0;
}

int Pre(int t){

  printf(" %d",t);

  if(t != NIL){
    if(A[t].left != NIL)Pre(A[t].left);
    if(A[t].right != NIL)Pre(A[t].right);
  }

 return 0;
}

int In(int t){

  if(t != NIL){
    if(A[t].left != NIL) In(A[t].left);

    printf(" %d",t);

    if(A[t].right != NIL) In(A[t].right);
  }

  return 0;
}

int Post(int t){

  if(t != NIL){
    if(A[t].left != NIL)Post(A[t].left);

    if(A[t].right != NIL)Post(A[t].right);
  }

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

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



using namespace std;

typedef vector<int> VI;
typedef vector<string> VS;


//container util
#define SORT(c) sort((c).begin(),(c).end())

//repetition
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)



int main(void){

	string S; cin >> S;

	vector<int> cnt(4,0);

	REP(i,S.length()){
		if(S[i] == 'N') cnt[0]++;
		else if(S[i] == 'S') cnt[1]++;
		else if(S[i] == 'W') cnt[2]++;
		else if(S[i] == 'E') cnt[3]++;
	}

	bool ans = true;
	
	if(cnt[0] > 0 and cnt[1] == 0) ans = false;
	else if(cnt[1] > 0 and cnt[0] == 0) ans = false;
	if(cnt[2] > 0 and cnt[3] == 0) ans = false;
	else if(cnt[3] > 0 and cnt[2] == 0) ans = false;

	cout << (ans ? "Yes" : "No") << endl;
	return 0;

}


Measured memory_bytes: 256
import java.util.Scanner;
public class Main{
	public static  void main(String[] args){
		Scanner scan = new Scanner(System.in);
		int a[] = new int[3];
		for(int i=0;i<a.length;i++){
		a[i] = scan.nextInt();
		}
		for(int i=0;i<a.length-1;i++){
			for(int j=a.length-1;j>i;j--){
				if(a[j]<a[j-1]){
					int t=a[j];
					a[j]=a[j-1];
					a[j-1]=t;
				}
			}
		}
				System.out.println(a[0]+" "+a[1]+" "+a[2]);
	}
}

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

using std::pair;
using std::vector;
using std::string;

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

#define fst first
#define snd second
#define pb(a) push_back(a)
#define mp(a, b) std::make_pair(a, b)
#define debug(...) fprintf(stderr, __VA_ARGS__)

template <typename T> bool chkmax(T& a, T b) { return a < b ? a = b, 1 : 0; }
template <typename T> bool chkmin(T& a, T b) { return a > b ? a = b, 1 : 0; }

const int oo = 0x3f3f3f3f;

string procStatus() {
    std::ifstream t("/proc/self/status");
    return string(std::istreambuf_iterator<char>(t), std::istreambuf_iterator<char>());
}

template <typename T> T read(T& x) {
    int f = 1; x = 0;
    char ch = getchar();
    for(;!isdigit(ch); ch = getchar()) if(ch == '-') f = -1;
    for(; isdigit(ch); ch = getchar()) x = x * 10 + ch - 48;
    return x *= f;
}

ll n;

int main() {
#ifdef Wearry
    freopen("in", "r", stdin);
    freopen("out", "w", stdout);
#endif

    read(n);

    ll t = 1, p;
    while(t <= n) t *= 10;
    p = t, -- t;

    while (p) {
        while(t > n && t >= p) t -= p;
        p /= 10;
    }

    int ans = 0;
    while (t) {
        ans += t % 10;
        t /= 10;
    }

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

    return 0;
}


Measured memory_bytes: 256
N = int(input())

if N >= 64:
    print(64)
elif N >= 32:
    print(32)
elif N >= 16:
    print(16)
elif N >= 8:
    print(8)
elif N >= 4:
    print(4)
elif N >= 2:
    print(2)
else:
    print(1)

Measured memory_bytes: 3060
#!/usr/bin/env python3

import sys
import math
from bisect import bisect_right as br
from bisect import bisect_left as bl
sys.setrecursionlimit(2147483647)
from heapq import heappush, heappop,heappushpop
from collections import defaultdict
from itertools import accumulate
from collections import Counter
from collections import deque
from operator import itemgetter
from itertools import permutations
mod = 10**9 + 7
inf = float('inf')
def I(): return int(sys.stdin.readline())
def LI(): return list(map(int,sys.stdin.readline().split()))

n,m = LI()
ab = [LI() for _ in range(n)]
ab.sort()
ans = 0
cnt = 0
for a,b in ab:
    if cnt + b <= m:
        cnt += b
        ans += a*b
    else:
        ans += (m-cnt)*a
        break
print(ans)


Measured memory_bytes: 56668
N, X = map(int,input().split())
lLst = list(map(int, input().split()))
D = 0
ansLst = []
ansLst.append(D)
tmp1 = 0
for i in range(N):
    tmp = tmp1 + lLst[i]
    if tmp <= X:
        ansLst.append(tmp)
        tmp1 = tmp
    else:
        break

print(len(ansLst))

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

int find_sum_of_digits(int n){
  int total = 0;
  while(n > 0){
    total += n % 10;
    n /= 10;
  }
  return total;
}

int main(){
  int n;
  cin >> n;
  int sum = n;
  for (int i = 1; i < n; i++) {
      int j = n - i;
      int a = find_sum_of_digits(i);
      int b = find_sum_of_digits(j);
      int chlngr = a + b;
      (sum > chlngr)? sum = chlngr : sum = sum;
  }
  cout << sum << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define _GLIBCXX_DEBUG
#define rep(i,n) for(int i=0;i<(n);++i)
#define repi(i,a,b) for(int i=int(a);i<int(b);++i)
#define all(x) (x).begin(), (x).end()
#define PI 3.14159265358979323846264338327950L
using namespace std;
typedef long long ll;
typedef long double ld;
int main() {
    int a,b;
    cin>>a>>b;
    cout<<max(0,a-2*b);
}

Measured memory_bytes: 3616
s = [1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51]
k = int(input()) - 1
print(s[k])

Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
int main(void){
    // Your code here!
    double a,b,c,d;
    double u;
    cin >> a >> b >> c >> d;
    u=a*b/2;
    printf("%.10lf", u);
    cout << " ";
    if (c==a/2 && d==b/2) cout << 1 << endl;
    else cout << 0 << endl;
}


Measured memory_bytes: 256
S=input()
T=input()
a=int(len(S))
b=int(len(T))
count=0
c=0
if a==b:
    for j in range(b):
        if S[j]==T[j]:
            count+=1
    c=count
else:
    for i in range(a-b):
        for j in range(b):
            if S[i+j]==T[j]:
                count+=1
        if c<count:
            c=count
        count=0
print(b-c)

Measured memory_bytes: 9148
def inside_circle(s):
    w, h, x, y, r = map(int, s.split())

    res = "Yes"

    if (x < r) or (y < r) or ((h - y) < r or (w - x) < r):  
        res = "No"

    return res

if __name__ == "__main__":
    print(inside_circle(input()))


Measured memory_bytes: 5600
#include <bits/stdc++.h>
#define For(i, a, b) for(int (i)=(int)(a); (i)<(int)(b); ++(i))
#define rFor(i, a, b) for(int (i)=(int)(a)-1; (i)>=(int)(b); --(i))
#define rep(i, n) For((i), 0, (n))
#define rrep(i, n) rFor((i), (n), 0)
#define fi first
#define se second
using namespace std;
typedef long long lint;
typedef unsigned long long ulint;
typedef pair<int, int> pii;
typedef pair<int, lint> pil;
typedef pair<lint, lint> pll;
template<class T>bool chmax(T &a, const T &b){if(a<b){a=b; return true;} return false;}
template<class T>bool chmin(T &a, const T &b){if(a>b){a=b; return true;} return false;}

constexpr lint mod = 1e9+7;
constexpr lint INF = mod*mod;
constexpr int MAX = 100010;

int f(vector<string> &s, int cur, int L){
    int len = 0, ret = 0;
    while(cur < s.size() && len < L){
        len += s[cur].size();
        ++cur;
        ++ret;
    }
    return len == L ? ret : -1;
}

int main(){
    int n;
    while(scanf("%d", &n) && n){
        vector<string> s(n);
        for(auto &i: s) cin >> i;
        vector<int> a(n), b(n);
        rep(i, n){
            a[i] = f(s, i, 5);
            b[i] = f(s, i, 7);
        }
        int ans;
        rep(i, n){
            int cur = i;
            if(a[cur] < 0) continue;
            cur += a[cur];
            if(b[cur] < 0) continue;
            cur += b[cur];
            if(a[cur] < 0) continue;
            cur += a[cur];
            if(b[cur] < 0) continue;
            cur += b[cur];
            if(b[cur] < 0) continue;
            cur += b[cur];
            ans = i;
            break;
        }
        printf("%d\n", ans+1);
    }
}


Measured memory_bytes: 3308
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef set<int> si;
typedef set<ll> sl;
typedef pair<int,int> pii;
#define rep(i,a,b) for(int i=(a); i<(b); ++i)
#define per(i,a,b) for(int i=(b)-1; i>=(a); --i)
#define all(x) (x).begin(),(x).end()
#define sz(x) (int)(x).size()
#define mp make_pair
#define pb push_back
#define F first
#define S second

int n;
ll a, b;
vl h;

bool canKill(ll k) {
	vl p(n);
	rep(i,0,n) {
		ll x = h[i] - b * k;
		if(x <= 0) continue;
		ll y = a - b;
		p[i] = x/y;
		if(x%y) {
			p[i]++;
		}
	}
	ll loc = 0;
	rep(i,0,n) {
		loc += max(p[i],0LL);
	}
	return loc <= k;
}

int main(void) {
	ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
	//freopen("in.txt", "r", stdin);
	cin >> n >> a >> b;
	h.resize(n);
	rep(i,0,n) {
		cin >> h[i];
	}
	sort(all(h));
	ll low = 1;
	ll hig = h.back();
	while(low < hig) {
		ll mid = (low+hig)/2;
		if(canKill(mid)) {
			hig = mid;
		} else {
			low = mid + 1;
		}
	}
	cout << low << '\n';
	return 0;
}


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

// macros
#define ll long long int
#define pb emplace_back
#define mk make_pair
#define pq priority_queue
#define FOR(i, a, b) for(int i=(a);i<(b);++i)
#define rep(i, n) FOR(i, 0, n)
#define rrep(i, n) for(int i=((int)(n)-1);i>=0;i--)
#define all(x) (x).begin(),(x).end()
#define sz(x) ((int)(x).size())
#define UNIQUE(v) v.erase(unique(v.begin(), v.end()), v.end())
#define FI first
#define SE second
using namespace std;

//  types
typedef pair<int, int> P;
typedef pair<ll, int> Pl;
typedef pair<ll, ll> Pll;
typedef pair<double, double> Pd;
 
// constants
const int inf = 1e9;
const ll linf = 1LL << 50;
const double EPS = 1e-10;
const int mod = 1e9 + 7;

// solve
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(a > b){a = b; return 1;} return 0;}
template <typename T> istream &operator>>(istream &is, vector<T> &vec){for(auto &v: vec)is >> v; return is;}


int main(int argc, char const* argv[])
{
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  string s;
  cin >> s;
  set<char> st;
  st.insert('A');
  st.insert('T');
  st.insert('C');
  st.insert('G');
  int res = 0;
  int curr = 0;
  rep(i, sz(s)){
    if(st.find(s[i]) != st.end()){
      curr++;
      res = max(res, curr);
    }else{
      curr = 0;
    }
  }
  cout << res << endl;
	return 0;
}


Measured memory_bytes: 256
ret = 'UNRESTORABLE'
sd = input()
t = input()
idxs = []
for i in range(len(sd)-len(t)+1):
    ext_s = sd[i:len(t)+i]
    mach_flag = True
    for j in range(len(t)):
        if( ext_s[j] != t[j] and  ext_s[j] != '?' ):
            mach_flag = False
            break
    if mach_flag :
        idxs.append(i)

            
if len(idxs) == 0:
    print('UNRESTORABLE')
else:
    sList = []
    for idx in idxs:
        s = sd[:idx] + t + sd[idx+len(t):]
        s = s.replace('?', 'a')
        sList.append(s)
    sList.sort()
    print(sList[0])

Measured memory_bytes: 3064
#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 a,b;
  cin>>a>>b;
  if (a>9||b>9) cout<<-1<<endl;
  else cout<<a*b<<endl;
  return 0;
}



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

using namespace std;

const int MX = 800005;

template <typename T> void cmin(T &x, const T &y)
{
	if(y < x) x = y;
}

template <typename T> void cmax(T &x, const T &y)
{
	if(y > x) x = y;
}

template <typename T> void read(T &x)
{
	x = 0; char c = getchar(); bool f = 0;
	while(!isdigit(c) && c!='-') c = getchar();
	if(c == '-') f = 1, c = getchar();
	while(isdigit(c)) x = x*10+c-'0', c = getchar();
	if(f) x = -x;
}

struct GRAPH
{
	int fst[MX], nxt[MX], v[MX], w[MX], lnum;

	GRAPH () {memset(fst, 0xff, sizeof(fst)), lnum = -1;}

	void addeg(int nu, int nv, int nw)
	{
		nxt[++lnum] = fst[nu];
		fst[nu] = lnum;
		v[lnum] = nv;
		w[lnum] = nw;
	}

	int dep[MX],q[MX];
	int bfs(int frm,int to)
	{
		int h=0,t=1,x,y;
		memset(dep,0xff,sizeof(dep));
		q[++h]=frm;
		dep[frm]=0;
		while(h>=t)
		{
			x=q[t++];
			for(int i=fst[x];i!=-1;i=nxt[i])
			{
				y=v[i];
				if(dep[y]==-1&&w[i])
				{
					dep[y]=dep[x]+1;
					q[++h]=y;
				}
			}
		}
		return (dep[to]>=0);
	}

	int cur[MX];
	int dinic(int x,int mn,int tar)
	{
		if(x==tar)return mn;
		int y,a,now=0;
		for(int &i=cur[x];i!=-1;i=nxt[i])
		{
			y=v[i];
			if(w[i]&&dep[y]==dep[x]+1)
			{
				a=dinic(y,min(mn-now,w[i]),tar);
				now+=a;
				w[i]-=a,w[i^1]+=a;
				if(mn==now)return now;
			}
		}
		return now;
	}

	int mxflow(int s, int t)
	{
		int tot=0;
		while(bfs(s,t))
		{
			memmove(cur,fst,sizeof(fst));
			tot+=dinic(s,MX,t);
		}
		return tot;
	}
} G;

int n;
int P[MX], Q[MX];

void input()
{
	read(n);
	for(int i=1; i<=n; i++) read(P[i]), P[i]++;
	for(int i=1; i<=n; i++) read(Q[i]), Q[i]++;
}

int idp[MX], idq[MX], vp[MX], vq[MX], cp, cq;

void build()
{
	for(int i=1; i<=n; i++)
	{
		if(!vp[i])
		{
			cp++;
			int x = i;
			while(!vp[x])
			{
				vp[x] = 1;
				idp[x] = cp;
				x = P[x];
			}
		}
		if(!vq[i])
		{
			cq++;
			int x = i;
			while(!vq[x])
			{
				vq[x] = 1;
				idq[x] = cq;
				x = Q[x];
			}
		}
	}
	int s = cp+cq+1, t = cp+cq+2;
	int ans = n;
	for(int i=1; i<=n; i++)
	{
		int ip = idp[i], iq = idq[i];
		if(P[i]==i && Q[i]==i)
		{
			ans--;
		}
		else if(P[i]==i && Q[i]!=i)
		{
			G.addeg(s, cp+iq, 1);
			G.addeg(cp+iq, s, 0);
		}
		else if(P[i]!=i && Q[i]==i)
		{
			G.addeg(ip, t, 1);
			G.addeg(t, ip, 0);
		}
		else if(P[i] != Q[i])
		{
			G.addeg(ip, cp+iq, 1);
			G.addeg(cp+iq, ip, 0);
		}
		else
		{
			G.addeg(ip, cp+iq, 1);
			G.addeg(cp+iq, ip, 1);
		}
	}
	printf("%d\n", ans-G.mxflow(s, t));
}

int main()
{
	input();
	build();
	return 0;
}


Measured memory_bytes: 32640
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
typedef pair<int, int> i_i;

#define reps(i,s,n) for(int i = s; i < n; i++)
#define rep(i,n) reps(i,0,n)
#define ALL(v) v.begin(), v.end()
#define SZ(x) ((int)(x).size())

const double PI  = acos(-1.0);
const double EPS = 1e-9;
const ll INF = 1e9+10;
const ll mod = 998244353;
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; }
#define print(x) cerr << #x << " is " << x << endl;
//#define print(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl; 
int main()
{
    ll N;
    cin >> N;
    vector<int> A(N);
    int ave = 0;
    rep(i, N){ 
        cin >> A[i];
        ave += A[i];
    }
    ave/=N;
    
    sort(ALL(A));
    ll ans = 0, ans2 = 0;
    //print(ave);
    rep(i, N){
        ans +=  (A[i] - ave) * (A[i] - ave);
    }
    ave+=1;
    rep(i, N){
        ans2 +=  (A[i] - ave) * (A[i] - ave);
    }
    
    
    
    cout << min(ans, ans2);
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
#define INF = 2e9
#define LINF = 1e18
#define rep(i, n) for(int i = 0; i < (int)(n); ++i)
#define all(x) (x).begin(),(x).end()
#define dump(x) cout << #x << "=" << (x) << endl
#define YES(n) cout << ((n) ? "YES" : "NO")
#define Yes(n) cout << ((n) ? "Yes" : "No")
#define PI 3.141592653589793

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

    int ans = 0;

    for(int i = 1; i <= n; i+=2){
        int cnt = 0;
        for(int j = 1; j <= n; ++j){
            if(i%j == 0)cnt++;
        }
        if(cnt == 8)ans++;
    }

    cout << ans << endl;

}

Measured memory_bytes: 3644
#include"bits/stdc++.h"
#include"cstdio"
#include"map"
#include"set"
#include"cmath"
#include"queue"
#include"vector"
#include"string"
#include"ctime"
#include"stack"
#include"deque"
#include"cstdlib"
#include"cstring"
#include"iostream"
#include"algorithm"

#define db double
#define ll long long
#define vl vector<ll>
#define ci(x) scanf("%d",&x)
#define cd(x) scanf("%lf",&x)
#define cl(x) scanf("%lld",&x)
#define pi(x) printf("%d\n",x)
#define pd(x) printf("%f\n",x)
#define pl(x) printf("%lld\n",x)
#define rep(i, a, n) for (int i=a;i<n;i++)
#define per(i, a, n) for (int i=n-1;i>=a;i--)
#define fi first
#define se second
using namespace std;
typedef pair<int, int> pii;
const int N = 3e3 + 5;
const int mod = 1e9 + 5;
const int MOD = 992353;
const db PI = acos(-1.0);
const db eps = 1e-10;
const int inf = 0x3f3f3f3f;
const ll INF = 0x3fffffffffffffff;
int n;
int a[N];
vector<int> e[N];
int dfs(int u,int pre){
    for(int i=0;i<e[u].size();i++){
        int v=e[u][i];
        if(v==pre) continue;
        if(a[u]>a[v]&&!dfs(v,u)) return 1;
    }
    return 0;
}
int main() {
    ci(n);
    for(int i=1;i<=n;i++) ci(a[i]);
    for(int i=1;i<=n;i++) e[i].clear();
    for(int i=1;i<n;i++){
        int x,y;
        ci(x),ci(y);
        e[x].push_back(y);
        e[y].push_back(x);
    }
    for(int i=1;i<=n;i++) if(dfs(i,0)) printf("%d ",i);
    puts("");
    return 0;
}






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

int main(){
    int n;cin>>n;int dp[n+1];
    for(int i=0;i<n+1;i++) dp[i]=100100;dp[0]=0;
    for(int i=0;i<n;i++){
        dp[i+1]=min(dp[i+1],dp[i]+1);
        if(i+1>=6){
            for(int j=1;pow(6,j)<=i+1;j++){
                int k=pow(6,j);
                dp[i+1]=min(dp[i+1],dp[i+1-k]+1);
            }
            if(i+1>=9){
                for(int j=1;pow(9,j)<=i+1;j++){
                int k=pow(9,j);
                dp[i+1]=min(dp[i+1],dp[i+1-k]+1);
                }
            }
        }
    }
    cout<<dp[n]<<endl;
}

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

using namespace std;

using ll = long long;

const ll MOD = 1000000007;

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

ll f[100005], fi[100005];

ll comb(int r, int c) {
    if (r < c) return 0;
    return f[r] * fi[c] % MOD * fi[r - c] % MOD;
}

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    int n, K;
    cin >> n >> K;
    vector<ll> a(n);
    for (int i = 0; i < n; ++i) {
        cin >> a[i];
    }
    sort(a.begin(), a.end());

    f[0] = 1;
    for (int i = 1; i <= n; ++i) {
        f[i] = f[i - 1] * i % MOD;
    }
    fi[n] = modpow(f[n], MOD - 2);
    for (int i = n; i > 0; --i) {
        fi[i - 1] = fi[i] * i % MOD;
    }

    ll ans = 0;
    for (int i = K - 1; i < n; ++i) {
        (ans += comb(i, K - 1) * a[i] % MOD) %= MOD;
    }
    for (int i = 0; i <= n - K; ++i) {
        (ans += MOD - comb(n - 1 - i, K - 1) * a[i] % MOD) %= MOD;
    }
    cout << ans << "\n";
    return 0;
}

Measured memory_bytes: 2560
#include <bits/stdc++.h>
#define REP(i,n) for (long i=0;i<(n);i++)
#define FOR(i,a,b) for (long i=(a);i<(b);i++)
#define RREP(i,n) for(long i=n;i>=0;i--)
#define RFOR(i,a,b) for(long i=(a);i>(b);i--)
#define dump1d_arr(array) REP(i,array.size()) cerr << #array << "[" << (i) << "] ==> " << (array[i]) << endl;
#define dump2d_arr(array) REP(i,array.size()) REP(j,array[i].size()) cerr << #array << "[" << (i) << "]" << "[" << (j) << "] ==> " << (array[i][j]) << endl;
#define dump(x)  cerr << #x << " => " << (x) << endl;
#define CLR(vec) { REP(i,vec.size()) vec[i] = 0; } 
#define llINF (long long) 9223372036854775807
#define loINF (long) 2147483647
#define shINF (short) 32767
#define SORT(c) sort((c).begin(),(c).end())
#define DEBUG

using namespace std;
typedef vector<long> VI;
typedef vector<VI> VVI;
typedef pair<long,long> pr;
typedef map<double,pr> mp;

typedef map<string,int> ms;

short N, M;
string t;

vector<string> data;

int main(void){
    cin >> N;
    short ans = 0;

    REP(i, N){
        cin >> t;
        data.push_back(t);
    }

    cin >> M;
    REP(j,M){
        cin >> t;
        REP(i, N){
            if (t == data[i]){
                data.erase(data.begin() + i);
                break;
            }
        }
    }
    int max = 0, count;
    REP(i,data.size()){
        count = 0;
        REP(j, data.size()){
            if (data[i] == data[j]) count++;
        }
        if (count > max) max = count;
    }

    cout << max;
    return 0; 
}

Measured memory_bytes: 256
#include <cstdio>
#include <iostream>
#include <string>
#include <vector>
#include <sstream>
#include <map>
#include <set>
#include <queue>
#include <algorithm>
#include <cmath>
#include <cstdlib>
#include <cstring>
#include <typeinfo>
#include <numeric>
#include <functional>
#include <unordered_map>
#include <bitset>


using namespace std;
using ll = long long;
using ull = unsigned long long;

const ll INF = 1e16;
const ll MOD = 1e9 + 7;

#define REP(i, n) for(ll i = 0; i < n; i++)



vector<bool> f;

int main() {
    int m, n;
    cin >> m >> n;
    
    while(m | n){
        int k = 0;
        f.assign(8000000, false);
        for(int i = 2; i < 8000000; i++){
            if(!f[i] && i >= m){
                if(k < n){
                    k++;
                    for(int j = i; j < 8000000; j += i){
                        f[j] = true;
                    }
                }
                
                if(!f[i]){
                    cout << i << '\n';
                    break;
                }
            }
        }
        
        cin >> m >> n;
    }
}


Measured memory_bytes: 3884
sumt=0
sumh=0

n=int(input())
for i in range(n):
    t,h=input().split()
    if t<h:
        sumh+=3
    if t>h:
        sumt+=3
    if t==h:
        sumh+=1
        sumt+=1
print(f'{sumt} {sumh}')



Measured memory_bytes: 5608