akhauriyash/Code-Regression huggingface dataset:
#![allow(unused_imports)]

use proconio::{input, fastout};
use proconio::marker::*;
use itertools::Itertools;
use nalgebra::min;

#[fastout]
fn main() {
    input! {
    n: usize,
    x: usize,
    mut d: [usize; n]
    }
    d.push(x);
    d.sort();
    let r = (0..n).map(|x| d[x + 1] - d[x]).collect::<Vec<usize>>();
    let ans = r.into_iter().fold1(|acc, x| gcd(&acc, &x)).unwrap();
    println!("{}", ans);
}

// O(log(N))
fn gcd(a: &usize, b: &usize) -> usize {
    let (mut x, mut y) = if a < b { (*b, *a) } else { (*a, *b) };
    let mut r = x % y;
    while r != 0 {
        x = y;
        y = r;
        r = x % y;
    }
    y
}


Measured memory_bytes: 4420
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        try (Scanner in = new Scanner(System.in)) {
            int a = in.nextInt();
            int b = in.nextInt();
            System.out.println((int) Math.ceil((a + b) / 2.0));
        }
    }
}


Measured memory_bytes: 27092
#include "bits/stdc++.h"
// Begin Header {{{
#define all(x) (x).begin(), (x).end()
#define rep(i, s, n) for (i64 i = (s), i##_limit = (n); i < i##_limit; ++i)
#define repr(i, s, t) for (i64 i = (s), i##_limit = (t); i >= i##_limit; --i)
#define repc(i, s, t) for (i64 i = (s), i##_limit = (t); i <= i##_limit; ++i)
#define var(type, ...) \
    type __VA_ARGS__;  \
    read(__VA_ARGS__);
#ifndef DBG
#define dump(...)
#endif
using namespace std;
using i64 = int_fast64_t;
using pii = pair<i64, i64>;
template <class T, class U>
inline bool chmax(T &a, const U &b) {
    return b > a && (a = b, true);
}
template <class T, class U>
inline bool chmin(T &a, const U &b) {
    return b < a && (a = b, true);
}
constexpr int INF = 0x3f3f3f3f;
constexpr i64 LINF = 0x3f3f3f3f3f3f3f3fLL;

template <class T>
inline vector<T> makeV(const T &initValue, size_t sz) {
    return vector<T>(sz, initValue);
}

template <class T, class... Args>
inline auto makeV(const T &initValue, size_t sz, Args... args) {
    return vector<decltype(makeV<T>(initValue, args...))>(
        sz, makeV<T>(initValue, args...));
}

template <class T>
inline istream &operator>>(istream &is, vector<T> &vec) {
    for (auto &e : vec) is >> e;
    return is;
}

inline void read() {}

template <class Head, class... Tail>
inline void read(Head &head, Tail &... tail) {
    cin >> head;
    read(tail...);
}

inline void print() { cout << "\n"; }

template <class Head, class... Tail>
inline void print(Head &&head, Tail &&... tail) {
    cout << head;
    if (sizeof...(tail)) cout << ' ';
    print(forward<Tail>(tail)...);
}

template <class T>
inline ostream &operator<<(ostream &os, const vector<T> &vec) {
    static constexpr const char *delim[] = {" ", ""};
    for (const auto &e : vec) os << e << delim[&e == &vec.back()];
    return os;
}

template <class Container>
struct Rev {
    Container &x_;
    inline Rev(Container &x) : x_(x) {}
    inline auto begin() { return rbegin(x_); }
    inline auto end() { return rend(x_); }
};
// }}} End Header

signed main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.setf(ios_base::fixed);
    cout.precision(12);

    var(i64, A, B, N);

    unordered_set<i64> used;
    i64 ans = 0;
    for (i64 x = B - 1; x <= N; x += B) {
        if (used.count(x % B)) {
            dump(x, x % B);
            break;
        }
        used.insert(x % B);
        chmax(ans, (A * x) / B - A * (x / B));
    }

    chmax(ans, (A * N) / B - A * (N / B));

    print(ans);

    return 0;
}


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

int main()
{
    int n, k;
    cin >> n >> k;
    if(k > (n - 1) * (n - 2) / 2){
        cout << -1 << endl;
        return 0;
    }
    cout << (n - 1) + (n - 1) * (n - 2) / 2 - k << endl;
    for(int i = 1; i < n; i++){
        cout << i << " " << n << endl;
    }
    int count = 0;
    for(int i = 1; i < n; i++){
        for(int j = i + 1; j < n; j++){
            if(count == (n - 1) * (n - 2) / 2 - k) return 0;
            cout << i << " " << j << endl;
            count++;
        }
    }
}

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

typedef long long ll;
typedef unsigned long long ull;
typedef string st;
typedef double db;
typedef vector<long long> vecll;
typedef vector<char> vechar;
typedef vector<string> vecst;

int main(){
    ll N;
    cin >> N;
    vecst S(N);
    vecll P(N);
    for(ll i; i < N; i++) cin >> S.at(i) >> P.at(i);

    vecll ord(N);
    iota(ord.begin(), ord.end(), 0);
    sort(ord.begin(), ord.end(), [&](ll i, ll j){
        if(S.at(i) == S.at(j)) return P.at(i) > P.at(j);
        return S.at(i) < S.at(j);
    });
    for(auto& i : ord) cout << i  + 1<< endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <cmath>
#include <numeric>
#include <unordered_map>
#include <queue>
#include <sstream>
#include <cstring>
#include <iomanip>

using namespace std;

typedef long long ll;

const ll INF=1e13+7;

template<class T> inline bool chmin(T& a, T b) {if (a > b) {a = b;return true;}return false;}
template<class T> inline bool chmax(T& a, T b) {if (a < b) {a = b;return true;}return false;}

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

int main(){
    char A,B;
    cin>>A>>B;
    int a=A,b=B;
    if(a<b){
        cout<<"<"<<endl;
    }else if(a==b){
        cout<<"="<<endl;
    }else{
        cout<<">"<<endl;
    }
    return 0;
}

//a=97,z=122

Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;
using System.Numerics;
using System.Text;
using System.Threading;
using System.Threading.Tasks;

namespace ConsoleApp2
{
    class Program
    {
        static void Main(string[] args)
        {
            var X = decimal.Parse(Console.ReadLine());
            decimal ans = 0;
            decimal sum = 100;
            while(sum<X)
            {
                sum = Math.Floor(sum*(decimal)1.01);
                ans++;
            }
            Console.WriteLine(ans);
        }
    }
}

Measured memory_bytes: 18088
#include<cstdio>
#include<cmath>
int n,m,a[100][100],ans,sum,t;
int main()
{
	scanf("%d%d",&n,&m);
	for(int i=1;i<=n;i++)
	{
		for(int j=1;j<=m;j++)
			scanf("%d",&a[i][j]);
		for(int j=1;j<i;j++)
		{
			sum=0;
			for(int k=1;k<=m;k++)
				sum+=(a[i][k]-a[j][k])*(a[i][k]-a[j][k]);
			t=sqrt(sum);
			if(t*t==sum)ans++;
		}
	}
	printf("%d",ans);
	return 0;
}


Measured memory_bytes: 128
#include <bits/stdc++.h>
#include <iostream>
using namespace std;
int main() {
  int A, B, C, X;
  cin >> A >> B >> C >> X;
  int cnt = 0;
  for (int i = 0; i <= A; ++i) {
    for (int j = 0; j <= B; ++j) {
      for (int k = 0; k <= C; ++k) {
        int sum = 500 * i + 100 * j + 50 * k;
        if (sum == X) cnt++;
      }
    }
  }
  cout << cnt << endl;
  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define gcd __gcd
void solve(){
	long n;
	cin>>n;
	map<long,long> m1;
	long temp;
	int a=0;
	long g;
	long x;
	long cnt=0;
	for(int i=0;i<n;i++){
		cin>>temp;
		if(i==0){
			g=temp;
		}else{
			g=gcd(g,temp);
		}
		x=temp;
		cnt=0;
		while(x%2==0){
			if(cnt==0&&m1[2]){
				a=1;
				cnt++;
			}
			m1[2]=1;
			cnt++;
			x=x/2;
		}
		for(int j=3;j<=sqrt(x);j=j+2){
			cnt=0;
			while(x%j==0){
				if(cnt==0&&m1[j]){
					a=1;
					cnt++;
				}
				m1[j]=1;
				x=x/j;
				cnt++;
			}
		}
		if(x>1){
			if(m1[x]){
				a=1;
			}
			m1[x]=1;
		}
	}
	if(a==0){
		cout<<"pairwise coprime\n";
	}else if(a==1&&g==1){
		cout<<"setwise coprime\n";
	}else{
		cout<<"not coprime\n";
	}
}
int main(){
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	long t=1;
//	cin>>t;
	while(t--)
		solve();
}

Measured memory_bytes: 8528
#include <stdio.h>
#include <cmath>
#include <algorithm>
#include <cfloat>
#include <stack>
#include <queue>
#include <vector>
#include <string>
#include <iostream>
#include <set>
#include <map>
#include <time.h>
typedef long long int ll;
typedef unsigned long long int ull;
#define BIG_NUM 2000000000
#define MOD 1000000007
#define EPS 0.000000001
using namespace std;


#define NUM 200001

int N,K;
ll L;
int minimum,maximum;
int input_array[NUM],table[NUM];

bool isOK(int number){

	for(int i = minimum; i <= maximum; i++)table[i] = 0;

	int count = 0,loc;
	for(loc = 0; loc < N; loc++){
		if(input_array[loc] <= number){
			count++;
			if(count == K){
				break;
			}
		}
	}

	if(loc == N)return false;

	ll sum = (N-1)-loc+1;

	for(int left = 1; left+(K-1) <= N-1; left++){
		if(input_array[left-1] <= number)count--;
		while(loc < N && count < K){
			loc++;
			if(input_array[loc] <= number)count++;
		}
		if(loc == N)break;
		sum += (N-1)-loc+1;
	}

	return sum >= L;
}

int main(){

	scanf("%d %d %lld",&N,&K,&L);
	minimum = BIG_NUM;
	maximum = -1;

	for(int i = 0; i < N;i++){
		scanf("%d",&input_array[i]);
		minimum = min(minimum,input_array[i]);
		maximum = max(maximum,input_array[i]);
	}

	int left = minimum,right = maximum,m = (left+right)/2;
	int ans = maximum;

	while(left <= right){

		if(isOK(m)){
			ans = m;
			right = m-1;
		}else{
			left = m+1;
		}
		m = (left+right)/2;
	}

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

	return 0;
}




Measured memory_bytes: 4704
from sys import stdin
n = int(stdin.readline().rstrip())
sl = [stdin.readline().rstrip() for _ in range(n)]
m = int(stdin.readline().rstrip())
tl = [stdin.readline().rstrip() for _ in range(m)]
ans=[sl.count(s) - tl.count(s) for s in set(sl)]
if max(ans) < 0:
    print(0)
else:
    print(max(ans))

Measured memory_bytes: 3060
import sys
sys.setrecursionlimit(10000000)
def input():
    return sys.stdin.readline()[:-1]
# from bisect import *
# from collections import *
# from heapq import *
# import itertools
import math
# INF = 10**9
# MOD = 10**9+7

N = int(input())
n = int(math.sqrt(N))
for i in range(n, 0, -1):
    if N % i == 0:
        print(i+N//i-2)
        break


Measured memory_bytes: 40044
#include "bits/stdc++.h"
using namespace std;
using ll = long long;
template <typename T>
void printv(const vector<T> &v){
    int sz = v.size();
    for (int i = 0; i < sz; i++){
        cout << v[i] << " \n"[i == sz - 1];
    }
}

struct UnionFind{
    vector<int> data;
    UnionFind(int size) : data(size, -1) {}
    bool unite(int x, int y){
        x = root(x);
        y = root(y);
        if (x != y){
            if (data[y] < data[x])
                swap(x, y);
            data[x] += data[y];
            data[y] = x;
        }
        return x != y;
    }
    bool find(int x, int y){
        return root(x) == root(y);
    }
    int root(int x){
        return data[x] < 0 ? x : data[x] = root(data[x]);
    }
    int size(int x){
        return -data[root(x)];
    }
};

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n, m;cin >> n >> m;
    UnionFind uf(n);
    for (int i = 0; i < m; i++){
        int s, t;
        cin >> s >> t;
        uf.unite(s, t);
    }
    int q;cin >> q;
    while (q--){
        int s, t;
        cin >> s >> t;
        cout << (uf.find(s, t) ? "yes" : "no") << endl;
    }
}


Measured memory_bytes: 3340
def solve():
    s = input()
    t = input()
    d = dict()
    for sc, tc in zip(s, t):
        if d.get(sc, None) is None:
            d[sc] = tc
        else:
            if d[sc] != tc:
                return False

    d = {value: key for key, value in d.items()}
    for sc, tc in zip(s, t):
        if d.get(tc, None) is None:
            d[tc] = sc
        else:
            if d[tc] != sc:
                return False
    return True


if __name__ == '__main__':
    print('Yes' if solve() else 'No')


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

int main() {
  string S;;
  cin >> S;
  int N = S.size();
  int count1 =0; //白から始める
  int count2 =0; //黒から始める
  for (int i =0; i<N; i++) {
    if (i % 2 ==0) {
      if (S.at(i) == '0') count1++;
    }
    if (i % 2 ==1) {
      if (S.at(i) == '1') count1++;
    }
  }
  for (int i =0; i<N; i++) {
    if (i % 2 ==1) {
      if (S.at(i) == '0') count2++;
    }
    if (i % 2 ==0) {
      if (S.at(i) == '1') count2++;
    }
  }
  cout << min(count1,count2) << endl;
}

Measured memory_bytes: 3752
#include <algorithm>
#include <assert.h>
#include <bitset>
#include <cfloat>
#include <complex>
#include <deque>
#include <fstream>
#include <functional>
#include <iomanip>
#include <iostream>
#include <limits.h>
#include <list>
#include <map>
#include <math.h>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string>
#include <string.h>
#include <time.h>
#include <unordered_map>
#include <unordered_set>
#include <vector>
#define rep(i,n) for(int i = 0;i < n; i++)
#define REP(i,n) for(int i = 1;i <= n; i++)
// ----GCC ONLY---- //
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
// ----        ---- //
#define ll long long
#define MOD 10000007
#define PB push_back
#define PI 3.14159265359
 
using namespace std;

int main(){

    int n,m,a[10010];
    
    cin >> n >> m;
    rep(i,m) cin >> a[i];

    int p = 0;

    rep(i,m) p += a[i];

    if(n >= p){
        cout << n - p <<"\n";
    }else{
        cout << "-1" << "\n";
    }

    return 0;
}




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

vector<pair<int, int> > v;

int main() {
	int n; long long k; scanf("%d %lld", &n, &k);
	while (n--) {
		int a, b; scanf("%d %d", &a, &b);
		v.push_back({a, b});
	}
	sort(v.begin(), v.end());
	for (int i = 0; i < v.size(); i++) {
		k -= (long long)v[i].second;
		if (k <= 0ll) {
			printf("%d\n", v[i].first);
			break;
		}
	}
}

Measured memory_bytes: 1400
#include <bits/stdc++.h>
#define mod 1000000007
#define sp ' '
#define intmax 2147483647
#define llmax 9223372036854775807
#define mkp make_pair
typedef long long ll;
using namespace std;

int N;
ll ev, od;
vector<ll>a;
vector<int>res;

int main(){
	cin >> N;
	a = vector<ll>(N);
	for (int i = 0; i < N; ++i) {
		cin >> a[i];
	}
	for (int i = 0; i < N; i += 2) {
		ev += max(a[i], 0ll);
	}
	for (int i = 1; i < N; i += 2) {
		od += max(a[i], 0ll);
	}
	if (ev < od) {
		cout << od << endl;
		res.push_back(1);
		a.erase(a.begin());
		
	}
	else {
		if (ev) {
			cout << ev << endl;
		}
		else {
			ll t = -llmax;
			for (int i = 0; i < N; ++i) {
				t = max(t, a[i]);
			}
			cout << t << endl;
			for (int i = 0; i < N; ++i) {
				if (a[i] == t) {
					for (int j = 0; j < i; ++j) {
						res.push_back(1);
					}
					for (int j = N - i; j >= 2; --j) {
						res.push_back(j);
					}
					cout << res.size() << endl;
					for (int j:res) {
						cout << j << endl;
					}
					return 0;
				}
			}
		}
	}
	if (!(a.size() & 1)) {
		res.push_back(a.size());
		a.pop_back();
	}
	while (a.size() != 1) {
		if (a.back() < 0) {
			res.push_back(a.size());
			a.pop_back();
			res.push_back(a.size());
			a.pop_back();
		}
		else {
			if (a[a.size() - 3] < 0) {
				if (a.size() == 3) {
					res.push_back(1);
					res.push_back(1);
					a[0] = a.back();
					a.pop_back();
					a.pop_back();
				}
				else {
					res.push_back(a.size() - 2);
					a[a.size() - 3] = a.back();
					a.pop_back();
					a.pop_back();
				}
			}
			else {
				res.push_back(a.size() - 1);
				a[a.size() - 3] += a.back();
				a.pop_back();
				a.pop_back();
			}
		}
	}
	cout << res.size() << endl;
	for (int i : res) {
		cout << i << endl;
	}
	return 0;
}

Measured memory_bytes: 256
import std.stdio, std.algorithm, std.conv, std.array, std.string, std.math, std.typecons, std.bigint, std.container;

alias X = Tuple!(long, "a", long, "b");
alias E = Tuple!(int, "to", long, "s");

X[10^^5] XS;
E[][10^^5] G;
bool[10^^5] F;

void main()
{
    auto nm = readln.split.to!(int[]);
    auto N = nm[0];
    auto M = nm[1];
    foreach (i; 0..M) {
        auto uvs = readln.split.to!(int[]);
        auto u = uvs[0]-1;
        auto v = uvs[1]-1;
        auto s = uvs[2].to!long;
        G[u] ~= E(v, s);
        G[v] ~= E(u, s);
    }

    long[] rs;
    XS[0] = X(1, 0);
    auto ss = [0];
    F[0] = true;
    while (!ss.empty) {
        auto h = ss[0];
        auto a = XS[h].a;
        auto b = XS[h].b;
        ss = ss[1..$];
        foreach (n; G[h]) {
            if (F[n.to]) {
                auto xn = XS[n.to];
                auto aa = a + xn.a;
                auto bb = n.s - b - xn.b;
                if ((aa == 0 && bb != 0) || (aa != 0 && bb % aa != 0)) {
                    rs ~= -1;
                } else if (aa != 0 && bb % aa == 0) {
                    rs ~= bb / aa;
                }
            } else {
                F[n.to] = true;
                XS[n.to] = X(-a, n.s - b);
                ss ~= n.to;
            }
        }
    }
    long r = -1;
    if (!rs.empty) {
        auto rr = rs[0];
        if (rr == -1) {
            writeln(0);
            return;
        }
        foreach (rx; rs) {
            if (rx < 0 || rr != rx) {
                writeln(0);
                return;
            }
        }
        r = rr;
    }
    auto max_r = long.max, min_r = 1L;
    foreach (x; XS[0..N]) {
        if (x.a > 0 && x.b < 0) {
            min_r = max(min_r, -x.b / x.a + 1);
        } else if (x.a < 0 && x.b > 0) {
            max_r = min(max_r, x.b / -x.a - 1);
        } else if (x.a < 0 && x.b < 0) {
            writeln(0);
            return;
        }
    }
    if (min_r <= max_r) {
        if (r > 0) {
            writeln(min_r <= r && r <= max_r ? 1 : 0);
        } else {
            writeln(max_r - min_r + 1);
        }
    } else {
        writeln(0);
    }
}

Measured memory_bytes: 23804
#include<bits/stdc++.h>
using namespace std;
 
#define ff              first
#define ss              second
#define int             long long
#define pb              push_back
#define mp              make_pair
#define pii             pair<int, int>
#define vi              vector<int>
#define si              set<int>
#define usi             unordered_set<int>
#define mii             map<int, int>
#define umii            unordered_map<int, int>
#define pqb             priority_queue<int>
#define pqs             priority_queue<int, vi, greater<int> >
#define setbits(x)      __builtin_popcountll(x)
#define zrobits(x)      __builtin_ctzll(x)
#define mod             1000000007
#define inf             1e18
#define endl            '\n'
#define ps(x,y)         fixed<<setprecision(y)<<x
#define mk(arr,n,type)  type *arr=new type[n];
#define w(t)            int t; cin>>t; while(t--)
mt19937                 rng(chrono::steady_clock::now().time_since_epoch().count());
 
void jaiswal_sahil()
{
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
// #ifndef ONLINE_JUDGE
//     freopen("input.txt", "r", stdin);
//     freopen("output.txt", "w", stdout);
// #endif
}

const int N = 1e2 + 2, W = 1e5 + 5;
int dp[N][W];
int n;
int maxVal(int i, int w, int *wt, int *v){

    if(i == n)
        return 0;
    
    if(dp[i][w] != -1)
        return dp[i][w];
    
    int q1 = -inf, q2 = -inf;
    if(w >= wt[i]){
        q1 = v[i] + maxVal(i+1, w-wt[i], wt, v);
    }
    q2 = maxVal(i+1, w, wt, v);

    return dp[i][w] = max(q1, q2);

}
int32_t main()
{
    jaiswal_sahil();
    
    int w;
    cin>>n>>w;
    int wt[n], v[n];
    for(int i=0; i<n; i++)
        cin>>wt[i]>>v[i];

    memset(dp, -1, sizeof(dp));
    int ans = maxVal(0, w, wt, v);
    cout<<ans<<endl;
    return 0;

}

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

using i64=int64_t;

#define rep(i,x,y) for(i64 i=i64(x),i##_max_for_repmacro=i64(y); i<i##_max_for_repmacro; ++i)
#define debug(x) #x << "=" << (x)
 
#ifdef DEBUG
#define _GLIBCXX_DEBUG
#define print(x) std::cerr << debug(x) << " (L:" << __LINE__ << ")" << std::endl
#else
#define print(x)
#endif
 
const int inf=1.01e9;
const i64 inf64=4.01e18;
const double eps=1e-9;
 
template <typename T> ostream &operator<<(ostream &os, const vector<T> &vec){
    os << "[";
    for (const auto &v : vec) {
        os << v << ",";
    }
    os << "]";
    return os;
}

void solve(){
    i64 ai,ao,at,aj,al,as,az;
    cin >> ai >> ao >> at >> aj >> al >> as >> az;

    i64 ans=ai/2*2+aj/2*2+al/2*2;
    if(ai and aj and al) ans=max(ans,3+(ai-1)/2*2+(aj-1)/2*2+(al-1)/2*2);

    cout << ans+ao << endl;
}

int main(){
    std::cin.tie(0);
    std::ios::sync_with_stdio(false);
    cout.setf(ios::fixed);
    cout.precision(16);
    solve();
    return 0;
}


Measured memory_bytes: 256
#
# 5b
#

def main():
    while True:
        H, W = map(int, input().split())
        if H == W == 0:
            break
        for i in range(H):
            if i == 0 or i == H - 1:
                print("#" * W)
            else:
                print("#" + "." * (W-2) + "#")
        print()


if __name__ == '__main__':
    main()


Measured memory_bytes: 5616
#include <bits/stdc++.h>
#include <string>
#include <cmath>
#include <sstream>
#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define FORD(i, a, b) for(int i = (a); i > (b); i--)
#define pb(a) push_back(a)
#define mp(a,b) make_pair(a,b)
typedef long long int ll;
using namespace std;
ll mod1=1000000007;
ll mod2=67280421310721;
ll mod3=998244353;
ll INF=1e18;
ll po(ll a,ll b)
{
	ll res=1;
	while(b)
	{
		if(b%2==1)
		{
			res*=a;
			res%=mod3;
		}
		a*=a;
		a%=mod3;
		b>>=1;
	}
	return res;
}
int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	int test=1;
//	cin>>test;
	while(test--)
	{
		int k;
		cin>>k;
		ll s=0;
		FOR(i,1,k+1)
		{
			FOR(j,1,k+1)
			{
				FOR(l,1,k+1)
				{
					s+=__gcd(i,__gcd(j,l));
				}
			}
		}
		cout<<s;
	}
	return 0;
}

Measured memory_bytes: 3652
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); i++)
#define chmin(x, y) x = min(x, y)
#define chmax(x, y) x = max(x, y)
using namespace std;
typedef long long ll;
int main() {
  int N; cin >> N;
  vector<double> a(N);
  rep(i, N) cin >> a[i];
  sort(a.begin(), a.end());
  for(int i=0;i<N-1;i++) {
    a[i+1]=(a[i]+a[i+1])/2;
  
  }
cout << a[N-1] << endl;
}

Measured memory_bytes: 256
/*
 * あなたは、X 円を持ってケーキとドーナツを買いに出かけました。
 * 
 * あなたはまずケーキ屋で 1 個 A 円のケーキを 1 個買いました。 次に、ドーナツ屋で 1 個 B 円のドーナツをできるだけたくさん買いました。
 * 
 * これらの買い物のあと手元に残っている金額は何円ですか。 
 */

import java.util.*;
	public class Main{
        public static void main(String[] args){
            Scanner sc = new Scanner(System.in);
            //入力
            int x = Integer.parseInt(sc.next());
            int a = Integer.parseInt(sc.next());
            int b = Integer.parseInt(sc.next());
            //出力
            System.out.println(x-a-((x-a)/b)*b);
            sc.close();
        }
    }
	

Measured memory_bytes: 22100
#include<iostream>
#include<cstdio>
using namespace std;
long long int a[100+2],b[100+2],c[100+2],d[100+2],w[100+2],n;

long long int s(int x){
	long long int ans;
	if(w[x]!=-1)return w[x];
	else {
		long long int e=a[x]*s(c[x]),f=b[x]*s(d[x]);
		long long int g=e,h=f,gcd;
		while(1){
			g%=h;
			if(g==0)break;
			h%=g;
			if(h==0)break;
		}
		gcd=e*f/max(g,h);
		ans=gcd/a[x]+gcd/b[x];
	}
	w[x]=ans;
	return ans;
}

int main(){
while(1){
	long long int an=0,aaa;
	scanf("%lld",&n);
if(n==0)break;
	w[0]=1;
	for(int i=1;i<=n;i++){scanf("%lld%lld%lld%lld",&a[i],&b[i],&c[i],&d[i]); w[i]=-1;}
	for(int i=1;i<=n;i++){
		if(w[i]==-1)aaa=s(i);
		if(an<w[i])an=w[i];
	}
	printf("%lld\n",an);
}
}

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

int main(){
  int H,W;
  cin >> H >> W;

  char x[H][W];
  rep(a,H)rep(b,W)cin >> x[a][b];

  rep(i,W+2)cout << "#";
  cout << endl;

  rep(a,H){
    cout << "#";
    rep(b,W)cout << x[a][b];
    cout << "#" << endl;
  }
  
  rep(i,W+2)cout << "#";
  cout << endl;
  
}

Measured memory_bytes: 256
#include <stdbool.h>
#include <stdio.h>
#include <stdlib.h>
#include <inttypes.h>
#include <stdint.h>
#include <string.h>
#include <wchar.h>

#define MIN(a, b) (a < b ? a : b)
#define MAX(a, b) (a > b ? a : b)
#define ABSS(a, b) (a > b ? a - b : b - a)

static uint32_t a[3000];

int main(void) {
	uint32_t N;
	uint32_t fMax = 0;

	scanf("%"PRIu32, &N);
	for (uint32_t idx = 0; idx < N; idx++) {
		scanf(idx != N - 1 ? "%"PRIu32" " : "%"PRIu32, &(a[idx]));
		fMax += a[idx] - 1;
	}

	printf("%"PRIu32, fMax);

	return 0;
}


Measured memory_bytes: 128
#include <cstdio>
#include <iostream>
#define int long long
using namespace std;
int n,ans;
signed main(){
	scanf("%lld",&n);
	// 0+1+2+...+(n-1) 
	if(n & 1){
		ans=(n-1)/2*n;
	}
	else{
		ans=(n)/2*(n-1);
	}
	printf("%lld\n",ans);
	return 0;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;  // NOLINT
using LL = int64_t;
int main() {
    int n;
    string s, t;
    cin >> n >> s;
    stack<char> st;
    for (auto& i : s) {
        if (i == '(') {
            st.push(i);
            t += i;
        } else if (st.empty()) {
            t = '(' + t;
            t += ")";
        } else {
            st.pop();
            t += ')';
        }
    }
    while (!st.empty()) {
        t += ')';
        st.pop();
    }
    cout << t << '\n';
}


Measured memory_bytes: 256
#include <iostream>
#include<algorithm>
using namespace std;
int main(void){
    // Your code here!
    int s[20],n,ans=0;
    cin>>n;
    for(int i=0;i<n;i++){
        cin>>s[i];
    }
    for(int i=1;i<n-1;i++){
        int r=(s[i]+s[i-1]+s[i+1])-max({s[i],s[i-1],s[i+1]})-min({s[i],s[i-1],s[i+1]});
        if(s[i]==r){
            ans++;
        }
    }
    
    cout<<ans<<endl;
    
    
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <set>
#include <stack>
#include <queue>
#include <map>
#include <algorithm>
#include <iomanip>
#include <math.h>
#include <string.h>
using namespace std; using ll = long long; using pll = pair<ll, ll>;
using vl = vector<ll>; using vll = vector<vl>; using vpll = vector<pll>;
int ctoi(char c) {
	switch (c) {
	case '0': return 0; case '1': return 1; case '2': return 2;
	case '3': return 3; case '4': return 4; case '5': return 5;
	case '6': return 6; case '7': return 7; case '8': return 8;
	case '9': return 9;  default: return 0;
	}
}
bool pairCompare(const pll firstElof, pll secondElof)
{
	return firstElof.first > secondElof.first;
}
//**Snippetリスト**//
//rep, vin, all, iteLoop//
//gcdlcm, isPrime, eratos, divisor, modinv, bitSearch, bitList, dfs, bfs//
//dijkstra, UnionFind, COM, digitDP//
ll i, j, k, l; ll N, M, K, H, W, L;
ll MOD = 1000000007; ll INF = 9999999999999; ll ans = 1;
vl flag, color, D; vll path;
//***********//
int main() {
	cin >> H >> W;
	vector<string> A(H);
	vl P(26);
	ll a = 'a';
	for (i = 0; i < H; i++) {
		cin >> A[i];
		for (j = 0; j < W; j++) {
			P[A[i][j] - a]++;
		}
	}
	ll one = 0;
	ll two = 0;
	ll four = 0;
	if (W % 2 == 1 && H % 2 == 1) {
		one = 1;
		two = W / 2 + H / 2;
		four = (W / 2) * (H / 2);
	}
	else if (W % 2 == 1 && H % 2 == 0) {
		two = H / 2;
		four = (W / 2) * (H / 2);
	}
	else if (W % 2 == 0 && H % 2 == 1) {
		two = W / 2;
		four = (W / 2) * (H / 2);
	}
	else {
		four = (W * H) / 4;
	}
	ll now = 0;
	ll noChange = 0;
	ll one2 = 0;
	ll two2 = 0;
	ll four2 = 0;
	while (true) {
		noChange ++;
		if (P[now]>0 && (P[now] % 4 == 1 || P[now] % 4 == 3)) {
			P[now]--; one2++; noChange = 0;
		}
		if (P[now]>0 && P[now] % 4 == 2) {
			P[now] -= 2; two2++; noChange = 0;
		}
		if (P[now]>0 && P[now] % 4 == 0) {
			P[now] -= 4; four2++; noChange = 0;
		}
		now = (now + 1) % 26;
		if (noChange > 10000) {
			break;
		}
	}
	//cout << one << " " << one2 << endl;
	//cout << two << " " << two2 << endl;
	//cout << four << " " << four2 << endl;
	for (i = 0; i < 26; i++) {
		if (P[i] != 0) ans = 0;
	}
	if (two2 > two) ans = 0;
	if (one2 > one) ans = 0;
	if (ans) cout  << "Yes";
	else cout << "No";
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc =new Scanner(System.in);
		int N = sc.nextInt();
		int M = sc.nextInt();
		int[] k = new int[M];
		int[][] s = new int[M][N];
		int[] p = new int[M];
		for(int i = 0;i < M;i++) {
			k[i] = sc.nextInt();
			for(int j = 0;j < k[i];j++) {
				s[i][j] = sc.nextInt();
			}
		}
		for(int i = 0;i < M;i++) {
			p[i] = sc.nextInt();
		}
		sc.close();

		int ans = 0;
		for(int i = 0;i < 1 << N;i++) {
			int[] swi = new int[N];
			boolean bool = true;
			for(int j = 0;j < N;j++) {
				if((1 & i >> j)==1) {
					swi[j] = 1;
				}
			}
			for(int x = 0;x < M;x++) {
				int row = 0;
				for(int y = 0;y < k[x];y++) {
					row += swi[s[x][y]-1];
				}
				if(row%2 != p[x]) {
					bool = false;
				}
			}
			if(bool) {
				ans++;
			}
		}
		System.out.println(ans);
	}
}

Measured memory_bytes: 23380
#include <iostream>
#include <stdio.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < n;i++ )

int main(){
    int x = 0,n,max=0;
    char s;
    cin >> n;
    rep(i, n){
        cin >> s;
        s == 'I' ? x++ : x--;
        if(x>max)max = x;

    }
    cout << max << endl;
    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<map>
#include<queue>
#include<set>
#include<stack>
#include<string>
#include<sstream>
#include<vector>
#define inf 2147483647
#define rep(i,a,b) for(int i=a;i<b;i++)
#define  rr read()
#define ll long long
#define repb(i,a,b) for(int i=a;i<=b;i++)
#define CloseIo   ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0)
using namespace std;
int read()
{
    char ch = getchar();
	int x = 0, f = 1;
    while(ch < '0' || ch > '9') {if(ch == '-') f = -1; ch = getchar();}
    while('0' <= ch && ch <= '9') {x = x * 10 + ch - '0'; ch = getchar();}
    return x * f;
}
int main()
{
int n;
cin>>n;
getchar();
string s;
cin>>s;
int m;
cin>>m;
for(int i=0;i<s.length();i++)
{
	 if(s[m-1]!=s[i])printf("*");
	 else
	 printf("%c",s[i]);
}
}



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


class UnionFind:
    def __init__(self, n):
        self.n = n
        self.parents = [-1] * n

    def find(self, x):
        if self.parents[x] < 0:
            return x
        else:
            self.parents[x] = self.find(self.parents[x])
            return self.parents[x]

    def union(self, x, y):
        x = self.find(x)
        y = self.find(y)

        if x == y:
            return

        if self.parents[x] > self.parents[y]:
            x, y = y, x

        self.parents[x] += self.parents[y]
        self.parents[y] = x

    def size(self, x):
        return -self.parents[self.find(x)]

    def same(self, x, y):
        return self.find(x) == self.find(y)

    def members(self, x):
        root = self.find(x)
        return [i for i in range(self.n) if self.find(i) == root]

    def roots(self):
        return [i for i, x in enumerate(self.parents) if x < 0]

    def group_count(self):
        return len(self.roots())

    def all_group_members(self):
        return {r: self.members(r) for r in self.roots()}

    def __str__(self):
        return '\n'.join('{}: {}'.format(r, self.members(r)) for r in self.roots())


n, m = map(int, input().split())
p = list(map(int, input().split()))
uf = UnionFind(n + 1)
cnt = 0
for i in range(m):
    x, y = map(int, input().split())
    uf.union(x, y)
for i in range(n):
    if uf.same(i + 1, p[i]):
        cnt += 1
print(cnt)


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

ll MOD = 1e9 + 7;
ll ans = 0;
int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  ll N;
  cin >> N;
  vector<int> A(N);
  REP(i, N) cin >> A[i];
  sort(A.begin(), A.end());
  bool ok = true;
  if(N == 1) {
    if(A[0] == 0) {
      cout << 1 << endl;
      return 0;
    } else {
      cout << 0 << endl;
      return 0;
    }
  }
  if(N % 2 != 0) {
    if(A[0] != 0) { ok = false; }
    for(int i = 1; i < N; i++) {
      if(i % 2 == 0) {
        if(A[i] != i) { ok = false; }
      } else {
        if(A[i] != i + 1) { ok = false; }
      }
    }
    if(ok) {
      ans = 2;
      for(int i = 1; i < (N - 1) / 2; i++) {
        ans = (ans * 2) % MOD;
      }
    }
  } else {
    for(int i = 0; i < N; i++) {
      if(i % 2 == 0) {
        if(A[i] != i + 1) { ok = false; }
      } else {
        if(A[i] != i) { ok = false; }
      }
    }
    if(ok) {
      ans = 2;
      for(int i = 1; i < N / 2; i++) {
        ans = (ans * 2) % MOD;
      }
    }
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 640
#include "bits/stdc++.h"
using namespace std;
const int maxn = 200100;
long long w[maxn], b[maxn], od[maxn];
int main(){
    int n, p;
    scanf("%d %d", &n, &p);
    for(int e = 0; e < n; e++) scanf("%lld %lld", w + e, b + e);
    for(int e = 0; e < n; e++) od[e] = e;
    sort(od, od + n, [&](long long u, long long v){
        return (w[u]*(100 - p) + b[u]*p) > (w[v]*(100 - p) + b[v]*p);
    });
    int lo = 0, hi = n - 1, ans = -1;
    while(lo <= hi){
        int mid = (lo + hi)>>1;
        long long wh = 0, bl = 0, su = 0;
        for(int e = 0; e < n; e++){
            if(e <= mid) wh += w[od[e]], su += w[od[e]];
            else bl += b[od[e]], su += b[od[e]];
        }
        long long re = (wh * 100) / su;
        if(re >= p) hi = mid - 1, ans = mid;
        else lo = mid + 1;
    }
    assert(~ans);
    cout << ans+1 << endl;
    return 0;
}


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

using namespace std;
using namespace __gnu_pbds;

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

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

int main(){
	ios_base::sync_with_stdio(0);cin.tie(0);
	string s;cin>>s;
    ll n=s.size()-1;
    if(s[n]=='3'){cout<<"bon\n";return 0;}
    if(s[n]=='0'||s[n]=='1'||s[n]=='6'||s[n]=='8')cout<<"pon\n";
    else cout<<"hon\n";
}


Measured memory_bytes: 3648
#include <bits/stdc++.h>
#define typeof(x) __typeof__(x)
#define int long long int
#define double long double
#define mod(x) ((x % MOD) + MOD) % MOD
#define rep(i,a,b) for(int i=(a);i<(b);++i)
#define rrep(i,a,b) for(int i=(b)-1;i>=(a);--i)

#define ALL(c) (c).begin(),(c).end()
#define RALL(c) (c).rbegin(),(c).rend()
#define SZ(c) (int)((c).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define SORT(c) sort(ALL(c))
#define RSORT(c) sort(RALL(c))
#define LB(c,x) (int)(lower_bound(ALL(c),x)-(c).begin())
#define UB(c,x) (int)(upper_bound(ALL(c),x)-(c).begin())
#define COUNT(c,x) UB(c,x)-LB(c,x)
#define UNIQUE(c) SORT(c); (c).erase(unique(ALL(c)),(c).end());
#define COPY(c1,c2) copy(ALL(c1),(c2).begin())
#define EXIST(s,e) (s).find(e)!=(s).end()
#define PB push_back
#define MP make_pair
#define vec vector

#define dump(x)  cerr << #x << " = " << (x) << endl;

using namespace std;

typedef pair<int,int> P;
struct edge { int to, cost; };

const int INF = 1e18;
const int MOD = 1e9+7;

template<typename T> ostream& operator << (ostream& s, const vector<T>& v) {
   s << "[";
   for (int i = 0; i < v.size(); i++) { s << v[i]; if (i < v.size() - 1) s << " "; }
   s << "]";
   return s;
}
template<typename T1, typename T2> ostream& operator << (ostream& s, const pair<T1,T2>& p) {
   s << "(" << p.first << "," << p.second << ")";
   return s;
}
template<typename T1, typename T2> ostream& operator << (ostream& s, const map<T1,T2>& m) {
   s << "{";
   for (auto i = m.begin(); i != m.end(); ++i) {
      s << i->first << ":" << i->second;
      if (next(i) != m.end()) s << ", ";
   }
   s << "}";
   return s;
}

signed main()
{
   string s; cin >> s;
   int n = SZ(s);
   vec<vec<int>> index(26, vec<int>());

   rep(i, 0, 26) {
      index[i].PB(-1);
   }
   rep(i, 0, n) {
      index[s[i]-'a'].PB(i);
   }
   rep(i, 0, 26) {
      index[i].PB(n);
   }

   vec<int> MAX(26, -1);
   rep(i, 0, 26) {
      rep(j, 0, SZ(index[i])-1) {
         MAX[i] = max(MAX[i], index[i][j+1] - index[i][j] - 1);
      }
   }

   int ans = INF;
   rep(i, 0, 26) {
      ans = min(ans, MAX[i]);
   }

   cout << ans << endl;

   return 0;
}


Measured memory_bytes: 256
def selectionSort( nums ):
	cnt = 0
	for i in range( 0, len( nums ) ):
		mini = i
		for j in range( i , len( nums ) ):
			if nums[j] < nums[ mini ]:
				mini = j
		if mini != i:
			cnt += 1
			nums[i], nums[ mini ] = nums[ mini ], nums[i]

	print( " ".join( map( str, nums) ) )
	print( cnt )


n = int( raw_input( ) )
nums = [ int( val ) for val in raw_input( ).split( " " ) ]
selectionSort( nums )

Measured memory_bytes: 4228
from itertools import accumulate
N, W = map( int, input().split())
o, k = map( int, input().split())
A = [k]
B, C, D = [], [], []
for _ in range(N-1):
    w, v = map( int, input().split())
    if w == o:
        A.append(v)
    elif w == o+1:
        B.append(v)
    elif w == o+2:
        C.append(v)
    else:
        D.append(v)
A.sort(key=None, reverse = True)
B.sort(key=None, reverse = True)
C.sort(key=None, reverse = True)
D.sort(key=None, reverse = True)
A = [0] + list(accumulate(A))
B = [0] + list(accumulate(B))
C = [0] + list(accumulate(C))
D = [0] + list(accumulate(D))
# print(A)
# print(B)
# print(C)
# print(D)
ans = 0
for i in range( len(A)):
    for j in range( len(B)):
        for k in range( len(C)):
            for l in range( len(D)):
                if i*o + j*(o+1) + k*(o+2) + l*(o+3) <= W:
#                    print('{} {} {} {}'.format(i,j,k,l))
                    ans = max( ans, A[i]+B[j]+C[k]+D[l])
print(ans)

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

int main(){
	int n,k,num;
	int black[10];
	cin >> n>> k;
	for(int i=0;i<k;i++){
		cin>> black[i];
	}
	bool flag;
	for(int i=n;;i++){
		flag = true;
		string str = to_string(i);
		for(int j=0;j<k;j++){
			if(str.find(to_string(black[j])) != string::npos){
				flag = false;
				break;
			}
		}
		if(flag){
			cout << i << endl;
			break;
		}
	}
}

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

struct Flood{
	int area;
	int left_position;
};

int main ()
{
    string str = "";
    int A = 0;  // 總面積 
    stack <Flood> L;  // 存洪水的面積與數量 
    stack <int> Left; // 儲存 '\' 
    
    // 輸入 
    cin >> str;
    
    // 處理 
    for (int i = 0;i < str.size();i++)
    {
    	if (str[i] == '\\')
    	{
    		Left.push(i);
		}
		else if (str[i] == '/' && !Left.empty())
		{
			int l = Left.top();
			Left.pop();
			int a = i - l;
			
			A += a;
			
			while(!L.empty() && L.top().left_position > l)
			{
				a += L.top().area;
				L.pop();
			}
			
			Flood F {a, l};
			L.push(F);
		}
	}
	
	// 輸出 
	cout << A << endl;
	int k = L.size();
	cout << k;
	int arr[k+1];
	while(!L.empty())
	{
		Flood f = L.top();
		L.pop();
		arr[L.size()] = f.area;
	}
	for (int i = 0;i < k;i++)
	{
		cout << " " << arr[i];
	}
	cout << endl;
    return 0;
}


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

using namespace std;

typedef long long int ll;

ll fifth(ll x)
{
    ll y = 1;

    for (int i = 0; i < 5; i++)
        y = y * x;

    return y;
}

int main()
{
    ll x;

    cin >> x;

    vector <ll> divisors;

    for (ll d = 1; d*d <= x; d++)
    {
        if (x % d == 0)
        {
            divisors.push_back(d);

            if (x != d*d)
                divisors.push_back(x / d);
        }
    }

    for (ll d: divisors)
    {
        for (int b = 0; b <= 4000; b++)
        {
            if (fifth(b+d) - fifth(b) == x)
            {
                cout << b + d << " " << b << "\n";
                return 0;
            }

            ll c = -1LL * b;

            if (fifth(c+d) - fifth(c) == x)
            {
                cout << c + d << " " << c << "\n";
                return 0;
            }
        }
    }
  
    return 0;
}

Measured memory_bytes: 3628
#!/usr/bin/env python3
import sys


def solve(N: int, A: int, B: int, X: "List[int]"):
    e = 0
    for i in range(1, N):
        d = X[i] - X[i-1]
        if d * A >= B:
            e += B
        else:
            e += d * A
    print(e)
    return


# Generated by 1.1.5 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    A = int(next(tokens))  # type: int
    B = int(next(tokens))  # type: int
    X = [int(next(tokens)) for _ in range(N)]  # type: "List[int]"
    solve(N, A, B, X)

if __name__ == '__main__':
    main()


Measured memory_bytes: 15384
firstLineInput = gets.to_s
numOfTree = firstLineInput.split(" ")[0].to_i
numOflightedTree = firstLineInput.split(" ")[1].to_i

arrayOfTrees = []
for times in 1.. numOfTree do
  arrayOfTrees<<gets.to_i
end

arrayOfTrees.sort!
arrayOfDiffs = []

for times in 0..arrayOfTrees.size - numOflightedTree do 
   arrayOfDiffs << arrayOfTrees[times + numOflightedTree -1] - arrayOfTrees[times]
end

puts arrayOfDiffs.min

Measured memory_bytes: 4640
#include <bits/stdc++.h>
#define MAXN 100100
using namespace std;

int alt[MAXN];
int pd[MAXN];
int n;

int main (){
	cin >> n;
	
	int i;
	
	for(i = 1; i <= n; i++){
		cin >> alt[i];
	}
	
	for(i = 2; i <= n; i++){
		if(i == 2) pd[i] = abs(alt[i]-alt[i-1]);
		else pd[i] = min(pd[i-1] + abs(alt[i]-alt[i-1]), pd[i-2] + abs(alt[i]-alt[i-2]) );
	}
	
	cout << pd[n] << endl;
}


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

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

    int n;
    cin >> n;

    map<int, int> a;
    REP(i, n) {
        int tmp;
        cin >> tmp;
        a[tmp]++;
    }

    ll ans = 0;
    for (auto i : a) {
        int diff = abs(i.first - i.second);
        if (i.first > i.second) ans += i.second;
        else ans += diff;
    }

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


Measured memory_bytes: 4736
#include<bits/stdc++.h>
#include<algorithm>
#include<math.h>
#include<string>
#include<iostream>
#include<vector>
#include<cstdlib>
using namespace std;
 
template <class T> using V = vector<T>;
 
template<class T> inline bool chmin(T& a, T b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
}
template<class T> inline bool chmax(T& a, T b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}
 
const long long INF = 1LL << 60;
 
using ll = long long;
using db = double;
using st = string;
using ch = char;
using bl = bool;
using vll = V<ll>;
using vpll =V<pair<ll,ll>>;
using vst = V<st>;
using vdb = V<db>;
using vch = V<ch>;
using vbl = V<bl>;
 
 
#define FOR(i,a,b) for(ll i=(a);i<(b);i++)
#define rFOR(i,a,b) for(ll i=(a);i>(b);i--)
#define oFOR(i,a,b) for(ll i=(a);i<(b);i+=2)
#define bgn begin()
#define en end()
#define SORT(a) sort((a).bgn,(a).en)
#define REV(a) reverse((a).bgn,(a).en)
#define M(a,b) max(a,b)
#define rM(a,b) min(a,b)
#define fi first
#define se second
#define sz size()
#define gcd(a,b) __gcd(a,b)
#define co(a) cout<<a<<endl;
#define ci(a) cin>>a;
 

vll dp(100100);

ll sum(ll n) {
  ll m=0;
  FOR(i,0,20){
    m+=n%10;
    n/=10;
    if(n==0){
      break;
    }
  }
  return m;
}
 
 
const int MAX = 510000;
const int MOD = 1000000007;
 
long long fac[MAX], finv[MAX], inv[MAX];
 
void Comuse() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}
 
 
#define comuse Comuse()
 
ll combi(int n, int k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}
 
 
 
 
ll lcm(ll a,ll b){
  ll n;
  n=a/gcd(a,b)*b;
  return n;
}
 
 
/****************************************\
| Thank you for viewing my code:)        |
| Written by RedSpica a.k.a. RanseMirage |
| Twitter:@asakaakasaka                  | 
\****************************************/
 
 
signed main() {
  ll n,w,h;
  	ci(n>>w>>h);
  co((n-h+1)*(n-w+1))
}

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

ll ll_min(ll a, ll b){
    if (a < b) return b;
    else return b;
}

ll ll_max(ll a, ll b){
    if (a > b) return a;
    else return b;
}

int main(void){
    ll A,B,C,X,Y; cin >> A >> B >> C >> X >> Y;
    ll C_ = C * 2;
    
    ll ans = 999999999999;
    for (int i = 0; i <= max(X,Y); i++){
        ll tmp_cost = 0;
        tmp_cost += C_ * i;
        tmp_cost += ll_max(0, (X-i) * A);
        tmp_cost += ll_max(0, (Y-i) * B);
        ans = min(ans, tmp_cost);
    }
    cout << ans << endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
const int INF = 1e9;
const int MOD = 1e9+7;
using LL = long long;
const LL LINF = 1e18;
using namespace std;
#define COUT(v) cout<<(v)<<endl
#define CIN(n)  int(n);cin >> (n)
#define LCIN(n) LL(n);cin >> (n)
#define SCIN(n) string(n);cin >> (n)
#define YES(n) cout<<((n)? "YES" : "NO")<<endl
#define Yes(n) cout<<((n)? "Yes" : "No")<<endl
#define POSSIBLE(n) cout << ((n) ? "POSSIBLE" : "IMPOSSIBLE"  ) << endl
#define Possible(n) cout << ((n) ? "Possible" : "Impossible"  ) <<endl

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) for(int i=0;i<(n);++i)
#define REPR(i,n) for(int i=n;i>=0;i--)

#define FOREACH(x,a) for(auto& (x) : (a) )

#define ALL(obj) (obj).begin(),(obj).end()

#define P pair<int,int>
#define I vector<int>
#define S set<int>
#define pb(v) push_back(v)
#define V vector
#define rt return
#define rmsame(a) sort(ALL(a)),a.erase(unique(ALL(a)), a.end())

typedef string::const_iterator State;
class PalseError {};
class Edge{
public:
    int from,to,value;
    Edge(int a,int b,int c){
        from = a;
        to = b;
        value = c;
    }
    Edge(int a,int b){
        from = a;
        to = b;
    }
};
int main(){
    CIN(N);
    CIN(K);
    V<LL> vec_x1,vec_y1,vec_x2,vec_y2;
    V<pair<LL,LL>> vec;
    REP(a,N){
        LCIN(X);
        LCIN(Y);
        vec_x1.pb(X);
        vec_x2.pb(X);
        vec_y1.pb(Y);
        vec_y2.pb(Y);
        vec.pb(make_pair(X,Y));
    }
    sort(ALL(vec_x1));
    sort(ALL(vec_x2),greater<LL>());
    sort(ALL(vec_y1));
    sort(ALL(vec_y2),greater<LL>());

    LL ans = LINF*5;
    REP(a,N){
        REP(b,N){
            REP(c,N){
                REP(d,N){
                    LL co = 0;
                    REP(w,N){
                        if(vec_x1.at(a)<=vec.at(w).first&&vec.at(w).first<=vec_x2.at(b)&&vec_y1.at(c)<=vec.at(w).second&&vec.at(w).second<=vec_y2.at(d)){
                            co++;
                        }
                    }
                    if(co>=K){
                        //cout<<abs(vec_x1.at(a)-vec_x2.at(b))<<" "<<abs(vec_y1.at(c)-vec_y2.at(d))<<endl;
                        ans = min(abs(vec_x1.at(a)-vec_x2.at(b))*abs(vec_y1.at(c)-vec_y2.at(d)),ans);
                    }
                }
            }
        }
    }
    COUT(ans);
    return 0;
}


Measured memory_bytes: 256
//
//  main.cpp

#include <iostream>
using namespace std;


int main(){	
	int x;
	while(1){
		cin >> x;
		if(x == 0)break;
		x = 1000 - x;
		int answer = 0;
		answer += x / 500;
		x %= 500;
		answer += x / 100;
		x %= 100;
		answer += x / 50;
		x %= 50;
		answer += x / 10;
		x %= 10;
		answer += x / 5;
		x %= 5;
		answer += x;
		cout << answer << endl;
	}
	return 0;
}

Measured memory_bytes: 3040
n = int(input())
s = [int(input()) for _ in range(n)]
mod = [x % 10 for x in s]
fraction = [x for x in s if x % 10 > 0]
if len(set(mod)) == 1 and mod[0] == 0:
    ans = 0
elif sum(mod) % 10 != 0:
    ans = sum(s)
else:
    ans = sum(s) - min(fraction)
print(ans)


Measured memory_bytes: 3064