akhauriyash/Code-Regression huggingface dataset:
import java.util.*;
public class Main {
	public static void main(String[] args) {
		C();
	}
	
	public static void A() {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int A = sc.nextInt();
		int B = sc.nextInt();
		
		System.out.println(Math.min(A*N, B));
	}
	
	//calc harshad
	public static int calchar(int x) {
		int sum = 0;
		String num = ((Integer) x).toString();
		for(int i=0;i<num.length();i++) {
			sum += Character.getNumericValue(num.charAt(i));
		}
		return sum;
	}
	
	public static void B() {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int sum = calchar(n);
		if(n%sum==0) System.out.println("Yes");
		else System.out.println("No");
	}
	/*
	 *  F i,j,k 店iが曜日jの時間帯kに開いているか
	 *  ci 本店と店iが同時に開いている時間帯の数
	 *  店の利益 P_1,c1 + Pncn  利益の最大値を求める
	 *  全部で 2^10通り 1000なので容易に行うことが可能
	 *  というか、時間帯ごとに関係はないので、10こ確かめる　（利益が正ならひらく）
	 *  また、利益が最大の時間帯を保持しておき、どうやっても利益がマイナスならそれを返す
	 *  ではない、何個かぶるかが重要 以下では、2^10
	 */
	public static void C() {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int F[][] = new int[N][10];
		int P[][] = new int[N][11];
		for(int i=0;i<N;i++) {
			for(int j=0;j<10;j++) {
				F[i][j] = sc.nextInt();
			}
		}
		for(int i=0;i<N;i++) {
			for(int j=0;j<11;j++) {
				P[i][j] = sc.nextInt();
			}
		}
		int counter = 1;
		int ret = Integer.MIN_VALUE;
		for(;counter<1024;counter++) {
			int nowsc = calcscore(counter,F,P);
			//System.out.println(nowsc);
			if(ret < nowsc) ret = nowsc;
		}
		System.out.println(ret);
	}
	// 2進数を受け取り、対応する曜日、時間帯が開催されているとして、スコアを返す 10桁 0001.. ~ 111.. 00000はない
	public static int calcscore(int bin, int[][] F, int [][] P) {
		int score = 0;
		int[] c = new int[F.length]; // 各店と同時に開いている回数
		for(int i=0;i<10;i++) {
			// if open
			if((bin & (1<<i)) != 0) {
				for(int j=0;j<F.length;j++) {
					if(F[j][i] == 1) c[j]++; 
				}
			}
		}
		for(int i=0;i<F.length;i++) {
			score += P[i][c[i]];
		}
		return score;
	}
	
	public static void D() {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int C = sc.nextInt();
		List[] lis = new List[C];
		for(int i=0;i<C;i++) {
			lis[i] = new ArrayList<Integer>();
		}
		for(int i=0;i<N;i++) {
			int s = sc.nextInt();
			int t = sc.nextInt();
			int c = sc.nextInt()-1;
			//if(c>C) System.out.println("N");
			lis[c].add(s);
			lis[c].add(t);
		}
		int[] sum = new int[20000];
		for(int i=0;i<C;i++) {
			updatesum(sum,lis[i]);
		}
		int max = 0;
		for(int i=0;i<20000;i++) {
			if(max < sum[i]) max = sum[i];
		}
		System.out.println(max);
		
	}
	//チャネルのsitiのlistを受け取り、sumの配列を更新する
	public static void updatesum(int[] sum, List<Integer> sche) {
		int[] temp = new int[sum.length];
		for(int i=0;i<sche.size();i+=2) {
			int st = sche.get(i)*2-1;
			int ed = sche.get(i+1)*2;
			for(int j=st;j<ed;j++) {
				temp[j] = 1;
			}
		}
		for(int i=0;i<sum.length;i++) {
			sum[i] += temp[i];
		}
	}
}

Measured memory_bytes: 25984
#include<stdio.h>

int main(void)
{
	int n,max=0,min=1000000000;
	int i,a;
	scanf("%d",&n);
	for(i=0;i<n;i++){
		scanf("%d",&a);
		if(a>max)
			max=a;
		if(a<min)
			min=a;
	}
	printf("%d",max-min);
	return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
#define maxn 1500000
#define int long long
#define INF 199999999
int W, H, n, top, top2, S[maxn], S2[maxn];
int ans, mark[maxn], mx[maxn];

int read()
{
	int x = 0, k = 1;
	char c; c = getchar();
	while(c < '0' || c > '9') { if(c == '-') k = -1; c = getchar(); }
	while(c >= '0' && c <= '9') x = x * 10 + c - '0', c = getchar();
	return x * k;
}

struct node
{
	int x, y;
	friend bool operator <(const node& a, const node& b)
	{ return a.y < b.y; }
}P[maxn];

void Push_Down(int p)
{
	if(!mark[p]) return;
	mark[p << 1] += mark[p], mark[p << 1 | 1] += mark[p];
	mx[p << 1] += mark[p], mx[p << 1 | 1] += mark[p];
	mark[p] = 0;
}

void Update(int p, int l, int r, int L, int R, int x)
{
	if(L > R) return;
	if(L <= l && R >= r)
	{
		mark[p] += x, mx[p] += x;
		return;
	}
	if(L > r || R < l) return;
	Push_Down(p);
	int mid = (l + r) >> 1;
	Update(p << 1, l, mid, L, R, x); Update(p << 1 | 1, mid + 1, r, L, R, x);
	mx[p] = max(mx[p << 1], mx[p << 1 | 1]);
}

int Query(int p, int l, int r, int L, int R)
{
	if(L <= l && R >= r) return mx[p];
	if(L > r || R < l) return 0;
	int mid = (l + r) >> 1; Push_Down(p);
	return max(Query(p << 1, l, mid, L, R), Query(p << 1 | 1, mid + 1, r, L, R));
}

void Work()
{
	memset(mx, 0, sizeof(mx)); memset(mark, 0, sizeof(mark));
	top = top2 = 0; int mid = W >> 1; 
	for(int i = 1; i <= n; i ++)
	{
		if(i > 1) ans = max(ans, (P[i].y + Query(1, 1, n, 1, i - 1)) * 2);
		Update(1, 1, n, i, i, W - P[i].y);
		if(P[i].x <= mid)
		{
			int last = 0, rec = i;
			while(top && P[S[top]].x <= P[i].x)
			{
				Update(1, 1, n, S[top], rec - 1, -(P[i].x - last));
				last = P[S[top]].x, rec = S[top]; top --;	
			}
			Update(1, 1, n, S[top], rec - 1, -(P[i].x - last));
			S[++ top] = i;
		}
		else
		{
			int last = W, rec = i;
			while(top2 && P[S2[top2]].x >= P[i].x)
			{
				Update(1, 1, n, S2[top2], rec - 1, P[i].x - last);
				last = P[S2[top2]].x, rec = S2[top2], top2 --;	
			}
			Update(1, 1, n, S2[top2], rec - 1, P[i].x - last);
			S2[++ top2] = i;
		}
	}
}

signed main()
{
	W = read(), H = read(), n = read();
	int X1 = 0, Y1 = 0, X2 = INF, Y2 = INF;
	for(int i = 1; i <= n; i ++) P[i].x = read(), P[i].y = read();
	for(int i = 1; i <= n; i ++)
	{
		X1 = max(X1, P[i].x), Y1 = max(Y1, P[i].y);
		X2 = min(X2, P[i].x), Y2 = min(Y2, P[i].y);
	}
	if(X2 && Y2) P[++ n].x = 0, P[++ n].y = 0;
	if(X1 != W && Y1 != H) P[++ n].x = W, P[++ n].y = H;
	ans = max(ans, (H + max(X2, (W - X1))) * 2);
	ans = max(ans, (W + max(Y2, (H - Y1))) * 2);
	sort(P + 1, P + 1 + n); Work();
	for(int i = 1; i <= n; i ++) swap(P[i].x, P[i].y);
	swap(W, H); sort(P + 1, P + 1 + n); Work();
	printf("%lld\n", ans);
	return 0;
}

Measured memory_bytes: 35072
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>

std::string solve(std::string str, int K){
  char tmp;
  int i = 0;
  int fin = str.size();
  
  while(K != 0){
    tmp = str[i];
    int diff = tmp - 'a';
    if(26 - diff <= K && tmp != 'a'){
      str[i] = 'a';
      K -= 26 - diff;
    }
    i++;
    if(i == fin){
      K %= 26;
      str[i-1] = str[i-1] + K;
      if(str[i-1] > 'z'){
        str[i-1] = 'a' + K - 1;
      }
      break;
    }
  }

  return str;
}

int main(){
  std::string str;
  int K;
  std::cin >> str;
  std::cin >> K;

  std::string result = solve(str, K);

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


Measured memory_bytes: 640
#include <bits/stdc++.h>
#define ll long long int

using namespace std;

int main ()
{
	string s, t;
	cin >> s ;
	cin >> t;
	int sum = 0;
	for (int i=0; i<3; i++){
		if (s[i] == t[i]){
			sum++;
		}
	}
	cout << sum << endl;
}

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

using namespace std;

inline int calc(int a,int b,int c,int d){
    return a*10+b*50+c*100+d*500;
}

int val(int arg, int &x1, int &x2, int &x3 , int &x4){
    int ret = 0, tmp;
    tmp = arg / 500;
    ret += tmp;
    x1 = tmp;
    arg -= tmp * 500;
    tmp = arg / 100;
    ret += tmp;
    x2 = tmp;
    arg -= tmp * 100;
    tmp = arg / 50;
    ret += tmp;
    x3 = tmp;
    arg -= tmp * 50;
    tmp = arg / 10;
    ret += tmp;
    x4 = tmp;
    return ret;
}

struct pay{
    int p,q,r,s,v,sum;

    pay(int vv, int pp, int qq, int rr, int ss, int xx){
        v = vv;
        p = pp;
        q = qq;
        r = rr;
        s = ss;
        sum = xx;
    }
};

int main(){
    int n;
    bool f = true;
    while(cin >> n && n){
        if(f){
            f = false;
        }else{
            cout << endl;
        }
        int a,b,c,d,y1=0,y2=0,y3=0,y4=0,x[4];
        vector<pay> v;
        int ret = 1 << 20;
        int ret2 = 1 << 20;
        cin >> a >> b >> c >> d;
        

        for(int p=0;p<=a;p++){
            for(int q=0;q<=b;q++){
                for(int r=0;r<=c;r++){
                    for(int s=0;s<=d;s++){
                        v.push_back(pay(calc(p,q,r,s), p,q,r,s,p+q+r+s));
                    }
                }
            }
        }
    
        for(int i=0;i<v.size();i++){
            if(v[i].v >= n){
                int tmpv = a+b+c+d + val(v[i].v-n,x[0],x[1],x[2],x[3]) - v[i].sum;
                int tmpv2 = v[i].v;
                if(ret > tmpv){
                    ret = tmpv;
                    ret2 = tmpv2;
                    y1 = v[i].p;
                    y2 = v[i].q;
                    y3 = v[i].r;
                    y4 = v[i].s;
                }else if(ret == tmpv && ret2 > tmpv2){
                
                }
            }
        }
        if(y1){
            cout << "10 " << y1 << endl;
        }
        if(y2){
            cout << "50 " << y2 << endl;
        }
        if(y3){
            cout << "100 " << y3 << endl;
        }
        if(y4){
            cout << "500 " << y4 << endl;
        }
    }
}

Measured memory_bytes: 4220
#include <cstdio>
#include <vector>
typedef long long lld;
const int MAXN = 1e5+5;
const int MOD = 1e9+7;
const int NOPE = -1;
std::vector<int> G[MAXN];
int dp[MAXN][2];
int up[MAXN];
int N;

void init() {
  for (int i = 1; i <= N; ++i) {
    for (int j = 0; j < 2; ++j) {
      dp[i][j] = NOPE;
    }
    G[i].clear();
    up[i] = NOPE;
  }
}

int dfs(int cur, bool black) {
  if (dp[cur][black] != NOPE) {
    return dp[cur][black];
  }
  int res = 1LL;
  for (int nxt: G[cur]) {
    if (nxt == up[cur]) continue;
    int cur = dfs(nxt, false);
    if (!black) {
      cur = (1LL * dfs(nxt, true) + cur) % MOD;
    }
    res = 1LL * cur * res % MOD;
  }
  return dp[cur][black] = res;
}

void dfs2(int cur) {
  for (int nxt: G[cur]) {
    if (nxt == up[cur]) continue;
    up[nxt] = cur;
    dfs2(nxt);
  }
}

int solve() {
  up[1] = 1;
  dfs2(1);
  return (1LL * dfs(1, false) + dfs(1, true)) % MOD;
}

int main() {
  scanf("%d", &N);
  init();
  for (int i = 1; i < N; ++i) {
    int x, y;
    scanf(" %d%d", &x, &y);
    G[x].push_back(y);
    G[y].push_back(x);
  }
  printf("%d\n", solve());
  return 0;
}

Measured memory_bytes: 13824
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {

		new Main().run();
	}

	private void run() {
		Scanner scanner = new Scanner(System.in);
		while (true) {
			int n = scanner.nextInt();
			if (n == 0)
				break;
			int[] a = new int[10];
			for (int i = 0; i < n; i++) {
				int b = scanner.nextInt();
				a[b]++;
			}
			int sum = 0;
			for (int i = 1; i < 5; i++) {
				int c = Math.min(a[i], a[10 - i]);
				sum += c;
				a[i] -= c;
				a[10 - i] -= c;
			}
			sum += a[5] / 2;
			a[5] %= 2;
			ans = 0;
			dfs(1, 0, a, 0);
			System.out.println(sum + ans);
		}

	}

	int ans;

	private void dfs(int i, int sum, int[] a, int now) {
		int rem = sum;
		int max = 0;
		for (int j = 1; j < 10; j++) {
			rem += a[j] * j;
			if(a[j]!=0)
				max=j;
		}
		if (now + rem / 10 <= ans)
			return;
		ans = Math.max(ans, now);
		if (sum == 10) {
			dfs(1, 0, a, now + 1);
			return;
		}
		if (i > max)
			return;
		dfs(i + 1, sum, a, now);
		if (a[i] > 0 && sum + i <= 10) {
			a[i]--;
			dfs(i, sum + i, a, now);
			a[i]++;
		}
	}
}

Measured memory_bytes: 30848
#pragma warning disable

using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Runtime.Serialization.Formatters.Binary;
using System.Text;
using System.Text.RegularExpressions;
using System.Diagnostics;
using System.Numerics;
using System.Collections;
using System.Timers;

static class MainClass
{
    public static void Main(string[] args)
    {
        Console.WriteLine((int)Math.Pow(Console.ReadLine().ToInt32(),3));
    }

    #region ライブラリ

    #region 文字列処理

    public static int ToInt32(this string str) => int.Parse(str);
    public static BigInteger ToBigInteger(this string str) => BigInteger.Parse(str);
    public static List<string> SplittedStringToList(this string str) => str.Split(new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries).ToList();
    public static List<int> SplittedStringToInt32List(this string str) => str.Split(new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries).Select(x => int.Parse(x)).ToList();

    public static List<BigInteger> SplittedStringToBigInteger(this string str) => str.Split(new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries).Select(x => BigInteger.Parse(x)).ToList();
    #endregion
    #region DeepClone
    public static T DeepClone<T>(this T src)
    {
        using (var memoryStream = new MemoryStream())
        {
            var binaryFormatter
              = new BinaryFormatter();
            binaryFormatter.Serialize(memoryStream, src);
            memoryStream.Seek(0, SeekOrigin.Begin);
            return (T)binaryFormatter.Deserialize(memoryStream);
        }
    }
    #endregion

    public static int Gcd(int a,int b)
    {
        if (b == 0)
            return a;
        return Gcd(b, a % b);
    }
    public static BigInteger Gcd(BigInteger a, BigInteger b)
    {
        if (b == 0)
            return a;
        return Gcd(b, a % b);
    }


    public static BigInteger Factorial(int n)
    {
        var dp = new BigInteger[n];
        dp[0] = 1;
        for (int i = 1; i < n; i++)
        {
            dp[i] = dp[i - 1] * (i + 1);
        }
        return dp[n - 1];
    }

    #endregion

}



Measured memory_bytes: 16032
#include <bits/stdc++.h>
#include <time.h>
#define int long long int
#define pb push_back
#define all(a) a.begin(), a.end()
#define scnarr(a, n) for (int i = 0; i < n; ++i) cin >> a[i]
#define vi vector<int>
#define si set<int>
#define pii pair <int, int>
#define sii set<pii>
#define vii vector<pii>
#define mii map <int, int>
#define faster ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL)
using namespace std;
using namespace chrono;
/* -------------------------------Solution Sarted--------------------------------------*/
//Constants
const int MOD = 1000000007; // 1e9 + 7
const int MAXN = 1000005; // 1e6 +5

void solve(){
	int l, r, d, ans = 0;
	cin >> l >> r >> d;

	if(l%d == 0)
		ans++;
	ans += (r/d - l/d);

	cout << ans << endl;
	
}

signed main()
{
	faster;
#ifndef ONLINE_JUDGE
	freopen("ip.txt", "r", stdin);
	freopen("op.txt", "w", stdout);
#endif
	// int t; cin >> t; while(t--)
		solve();
	return 0;
}


//Author : Ankit Raj
//Problem Link :

/*Snippets*/
/*
sieve - prime factorization using sieve and primes in range
zpower - pow with mod
plate - Initial template
bfs 
dfs
fenwik - BIT
binary_search
segment_tree
*/
	

Measured memory_bytes: 3628
import java.io.*;
import java.util.*;

public class Main {

    public static void main(String[] args) throws IOException {

        new Main().go();
    }

    PrintWriter out;
    Reader in;
    BufferedReader br;

    Main() throws IOException {

        try {

            //br = new BufferedReader( new FileReader("input.txt") );
            in = new Reader("input.txt");
            out = new PrintWriter( new BufferedWriter(new FileWriter("output.txt")) );
        }
        catch (Exception e) {

            //br = new BufferedReader( new InputStreamReader( System.in ) );
            in = new Reader();
            out = new PrintWriter( new BufferedWriter(new OutputStreamWriter(System.out)) );
        }
    }

    void go() throws IOException {

        int t = 1;
        while (t > 0) {
            solve();
            //out.println();
            t--;
        }

        out.flush();
        out.close();
    }

    int inf = 2000000000;
    int mod = 1000000007;
    double eps = 0.000000001;

    int n;
    int m;

    //ArrayList<Integer>[] g = new ArrayList[1000];

    void solve() throws IOException {

        int n = in.nextInt();
        int a = in.nextInt();
        int b = in.nextInt();

        out.println(Math.abs(a-b)%2==0 ? "Alice" : "Borys");

    }


    class Pair implements Comparable<Pair>{

        int a;
        int b;

        Pair(int a, int b) {

            this.a = a;
            this.b = b;
        }

        public int compareTo(Pair p) {

            if (a > p.a) return 1;
            if (a < p.a) return -1;
            if (b > p.b) return 1;
            if (b < p.b) return -1;
            return 0;
        }
    }

    class Item {

        int a;
        int b;
        int c;

        Item(int a, int b, int c) {
            this.a = a;
            this.b = b;
            this.c = c;
        }

    }

    class Reader {

        BufferedReader  br;
        StringTokenizer tok;

        Reader(String file) throws IOException {
            br = new BufferedReader( new FileReader(file) );
        }

        Reader() throws IOException {
            br = new BufferedReader( new InputStreamReader(System.in) );
        }

        String next() throws IOException {

            while (tok == null || !tok.hasMoreElements())
                tok = new StringTokenizer(br.readLine());
            return tok.nextToken();
        }

        int nextInt() throws NumberFormatException, IOException {
            return Integer.valueOf(next());
        }

        long nextLong() throws NumberFormatException, IOException {
            return Long.valueOf(next());
        }

        double nextDouble() throws NumberFormatException, IOException {
            return Double.valueOf(next());
        }


        String nextLine() throws IOException {
            return br.readLine();
        }

    }

}

Measured memory_bytes: 23124
def main():
    N, Q = map(int, input().split())
    S = input()

    count = [0 for i in range(N + 1)]
    c = 0
    for i in range(1, N):
        if S[i-1] == "A" and S[i] == "C":
            c += 1
        count[i + 1] = c
    
    Query = list()
    for q in range(Q):
        Query.append(input())

    for q in range(Q):
        l, r = map(int, Query[q].split())
        print(count[r] - count[l])

if __name__ == "__main__":
    main()

Measured memory_bytes: 18604
# import math
# import statistics
# import itertools
a=int(input())
#b,c=int(input()),int(input())
# c=[]
# for i in a:
#     c.append(int(i))
# e1,e2,e3,e4 = map(int,input().split())
#f = list(map(int,input().split()))
g = [int(input()) for _ in range(a)]

ma = max(g)
del g[g.index(ma)]
print(int(sum(g)+ma/2))

Measured memory_bytes: 9128
#include <stdio.h>

int main () {
	int x, a, b;
	int num1, num2;
	scanf("%d %d %d", &x, &a, &b);
	num1 = (a - x);
	num2 = (b - x);
	if (num1 < 0) {
		num1 = -num1;
	}
	if ( num2 < 0) {
		num2 = -num2;
	}
	
	if (num1 < num2) {
		printf("A");
	}
	else {
		printf("B");
	}
	return 0;
}

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

using namespace std;

#define ll 			long long
#define db			double
#define up(i,j,n)		for (int i = j; i <= n; i++)
#define down(i,j,n)	for (int i = j; i >= n; i--)
#define cadd(a,b)		a = add (a, b)
#define cpop(a,b)		a = pop (a, b)
#define cmul(a,b)		a = mul (a, b)
#define pr			pair<int, int>
#define fi			first
#define se			second
#define SZ(x)		(int)x.size()
#define bin(i)		(1 << (i))
#define Auto(i,node)	for (int i = LINK[node]; i; i = e[i].next)

template<typename T> inline bool cmax(T & x, T y){return y > x ? x = y, true : false;}
template<typename T> inline bool cmin(T & x, T y){return y < x ? x = y, true : false;}
template<typename T> inline T dmax(T x, T y){return x > y ? x : y;}
template<typename T> inline T dmin(T x, T y){return x < y ? x : y;}

const int MAXN = 1e5 + 5;

int N, K, a[MAXN];

int main(){
#ifdef cydiater
	freopen("input.in", "r", stdin);
#endif
	scanf("%d%d", &N, &K);
	up (i, 1, N) scanf("%d", &a[i]);
	int mn = a[1];
	up (i, 2, N) cmin(mn, a[i]);
	int ans = 0, cur = 0, equ = 0;
	up (i, 1, N) {
		if (a[i] != mn || cur != 0) {
			cur++;
			equ += a[i] == mn;
		}
		if (cur == K) {
			cur = equ == 0;
			equ = 0;
			ans++;
		}
	}
	ans += cur > 0;
	printf("%d\n", ans);
	return 0;
}



Measured memory_bytes: 640
#include "bits/stdc++.h"
using namespace std;

#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP0(i, n) for (int i = 0, i##_len = (n); i < i##_len; ++i)
#define REP1(i, n) for (int i = 1, i##_len = (n); i <= i##_len; ++i)

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

const int INTINF = int(1e9) + 1;
const LL LLINF   = LL(1e18) + 1;
#define pow10(n) int(1e##n + n)

void solve()
{
    string S;
    cin >> S;
    cout << (S[0] == S[1] and S[1] == S[2] ? "No" : "Yes") << endl;
}

int main(int argc, char const *argv[])
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    std::cout << std::fixed << std::setprecision(10);
    solve();
    return 0;
}


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


def solve(N: int, X: int, m: "List[int]"):
    X -= sum(m)
    ret = N + X // min(m)
    print(ret)
    return


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
    X = int(next(tokens))  # type: int
    m = [ int(next(tokens)) for _ in range(N) ]  # type: "List[int]"
    solve(N, X, m)

if __name__ == '__main__':
    main()


Measured memory_bytes: 3060
//#pragma GCC optimize ("-O3","unroll-loops")
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<queue>
#include<map>
#include<math.h>
#include<iomanip>
#include<set>
#include<numeric>
#include<cstring>
#include<cstdio>
#include<functional>
#include<bitset>
#include<limits.h>
#include<cassert>
#include<iterator>
#include<complex>
#include<stack>
#include<unordered_map>
#include<unordered_set>
#include<time.h>
#include <random>

using namespace std;

#define REP(i, n) for(int i = 0;i < n;i++)
#define REPR(i, n) for(int i = n;i >= 0;i--)
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define FORR(i, m, n) for(int i = m;i >= n;i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define REVERSE(v,n) reverse(v,v+n);
#define VREVERSE(v) reverse(v.begin(), v.end())
#define ll long long
#define pb(a) push_back(a)
#define print(x) cout<<x<<'\n'
#define pe(x) cout<<x<<" "
#define lb(v,n) lower_bound(v.begin(), v.end(), n)
#define ub(v,n) upper_bound(v.begin(), v.end(), n)
#define int long long
#define all(x) (x).begin(), (x).end()
#define print_space(v) REP(i,v.size())cout << v[i] << ((i == v.size() - 1) ? "\n" : " ")
#define double long double

template<typename T1, typename T2> inline void chmin(T1 & a, T2 b) { if (a > b) a = b; }
template<typename T1, typename T2> inline void chmax(T1& a, T2 b) { if (a < b) a = b; }
typedef pair<int, int>P;
int MOD = 1e9+7;

const int MAX = 200060;
const double pi = acos(-1);
const double EPS = 1e-12;


void solve(){
	int N, K; cin >> N >> K;
	vector<int>A(N);
	REP(i, N) {
		cin >> A[i];
	}
	vector<int>B(N);
	REP(i, N)cin >> B[i];
	VSORT(A); VSORT(B);
    //VREVERSE(B);
	VREVERSE(A);
	ll ok = 1e14, ng = -1;
	while (abs(ok - ng) > 1) {
		int mid = (ok + ng) / 2;
		int rem = K;
		bool can = true;
		REP(i, N) {
			if (A[i] * B[i] <= mid)continue;
			else {
				int nxt = mid / B[i];
				int dif = A[i] - nxt;
				if (rem >= dif) {
					rem -= dif;
				}
				else {
					can = false;
					break;
				}
			}
		}
		if (can)ok = mid;
		else ng = mid;
	}
	print(ok);

}


signed main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	solve();
}


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

#define REP(i, n) for(int (i)=0;(i)<(n);++(i))
#define REPV(iter, v) for(auto (iter)=(v).begin(); (iter)!=(v).end();++(iter))
#define ALL(v) (v).begin(),(v).end()

#define MOD 1000000007

using namespace std;

typedef long long ll;

ll gcd(ll a, ll b)
{
    if (b == 0)
    {
        return a;
    }

    return gcd(b, a % b);
}

int main()
{
    ll N, K;
    cin >> N >> K;
    vector<ll> A(N);
    ll aMax = 0;
    REP(i, N)
    {
        cin >> A[i];
        if (aMax < A[i])
        {
            aMax = A[i];
        }
    }

    ll G = A[0];
    REP(i, N - 1)
    {
        G = gcd(G, A[i + 1]);
    }
    string ans;
    if (K <= aMax && K % G == 0)
    {
        ans = "POSSIBLE";
    }
    else
    {
        ans = "IMPOSSIBLE";
    }

    cout << ans << endl;
}


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


int main()
{
	int n,ans=0;
	cin>>n;
	for(int i=1;i<=n;i+=2)
	{
		int sum=0;
		for(int j=1;j<=i;j++)
		{
			if(i%j==0)sum++;
		}
		if(sum==8)ans++;
	}
	cout<<ans<<endl;
	return 0;
}

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

using namespace std;

#define int long long
#define FOR(i, a, b) for(ll i = (a); i < (b); ++i)
#define FORR(i, a, b) for(ll i = (a); i > (b); --i)
#define REP(i, n) for(ll i = 0; i < (n); ++i)
#define REPR(i, n) for(ll i = n; i >= 0; i--)
#define FOREACH(x, a) for(auto &(x) : (a))
#define VECCIN(x)                                                              \
    for(auto &youso_ : (x)) cin >> youso_
#define bitcnt __builtin_popcount
#define SZ(x) ((ll)(x).size())
#define fi first
#define se second
#define All(a) (a).begin(), (a).end()
template <typename T = long long> inline T IN() {
    T x;
    cin >> x;
    return (x);
}
inline void CIN() {}
template <class Head, class... Tail>
inline void CIN(Head &&head, Tail &&... tail) {
    cin >> head;
    CIN(move(tail)...);
}
#define CINT(...)                                                              \
    int __VA_ARGS__;                                                           \
    CIN(__VA_ARGS__)
#define LCIN(...)                                                              \
    ll __VA_ARGS__;                                                            \
    CIN(__VA_ARGS__)
#define SCIN(...)                                                              \
    string __VA_ARGS__;                                                        \
    CIN(__VA_ARGS__)
#define Yes(a) cout << (a ? "Yes" : "No") << "\n"
#define YES(a) cout << (a ? "YES" : "NO") << "\n"
#define Printv(v)                                                              \
    {                                                                          \
        FOREACH(x, v) { cout << x << " "; }                                    \
        cout << "\n";                                                          \
    }
template <typename T = string> inline void eputs(T s) {
    cout << s << "\n";
    exit(0);
}
template <typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val) {
    std::fill((T *)array, (T *)(array + N), val);
}
template <typename T> using PQG = priority_queue<T, vector<T>, greater<T>>;
template <typename T> using PQ = priority_queue<T>;

typedef long long ll;
typedef unsigned long long ul;
typedef vector<ll> VL;
typedef pair<ll, ll> PL;

const int INF = 1e9;
const int MOD = 1e9 + 7;
// const int MOD = 998244353;
const ll LINF = 1e18 + 1;
const ll dx[] = {1, -1, 0, 0};
const ll dy[] = {0, 0, 1, -1};

string s;

signed main() {
    cin >> s;
    REP(i, s.length() - 1) {
        if(s[i + 1] == s[i]) eputs("Bad");
    }
    cout << "Good"
         << "\n";
}

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


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

    double t, x;
    cin >> t >> x;
    printf("%5f", t/x);
}


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

void main() {
    const tmp = readln.split.to!(long[]);
    const N = tmp[0], M = tmp[1];
    const xyzs = N.iota.map!(_ => readln.split.to!(long[])).array;

    cartesianProduct([-1,+1],[-1,+1],[-1,+1])
    .map!(signs =>
        xyzs.map!(xyz => dotProduct(xyz, [signs.expand]))
            .array
            .sort!((a,b) => a > b).take(M).sum)
    .reduce!max.writeln;
}



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

#define _USE_MATH_DEFINES
#include<cstdio>
#include <cstring>
#include <cmath>
#include <cstdlib>
#include <deque>
#include <algorithm>
#include <functional>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>
#include <iterator>
#include<iomanip>
#include<unordered_set>
#include<bitset>
#include<complex>

using namespace std;

#define rep(i,a,b) for(int i=(a), i##_len=(b);i<i##_len;i++)
#define rrep(i,a,b) for(int i=(b)-1;i>=(a);i--)
#define all(c) begin(c),end(c)

#define int ll
#define SZ(x) ((int)(x).size())
#define pb push_back
#define mp make_pair

//typedef unsigned long long ull;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<ll, int> pli;
typedef pair<double, double> pdd;
typedef vector< vector<int> > mat;

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 (b < a) { a = b; return true; } return false; }

const int INF = sizeof(int) == sizeof(long long) ? 0x3f3f3f3f3f3f3f3fLL : 0x3f3f3f3f;
const int MOD = (int)1e9 + 7;
const double EPS = 1e-9;

struct Edge
{
	int s, t, cost;
	Edge(int s, int t, int cost) :s(s), t(t), cost(cost) {}
	Edge() :Edge(-1, -1, -1) {}
};

vector<Edge> G[100010];
int d[100010];
int V;

void shortest_path(int s)
{
	rep(i, 0, V)d[i] = INF;
	d[s] = 0;

	priority_queue<pii, vector<pii>, greater<pii>> pq;
	pq.push(mp(0, s));

	while (!pq.empty())
	{
		pii p = pq.top(); pq.pop();
		if (d[p.second] < p.first)
		{
			continue;
		}
		for (auto& e : G[p.second])
		{
			if (d[e.t] > d[e.s] + e.cost)
			{
				d[e.t] = d[e.s] + e.cost;
				pq.push(mp(d[e.t], e.t));
			}
		}
	}
}

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

	cin >> V;

	rep(i, 0, V)
	{
		G[i].push_back(Edge(i, (i + 1) % V, 1));
		G[i].push_back(Edge(i, (i * 10) % V, 0));
	}

	shortest_path(1);

	cout << d[0] + 1 << endl;

	return 0;
}

Measured memory_bytes: 10748
import java.util.*;

public class Main {

    public static void canPay(int N, int A) {
        if ((N % 500) <= A) {
            System.out.println("Yes");
        } else {
            System.out.println("No");
        }
    }

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        int A = sc.nextInt();
        canPay(N, A);
    }

}


Measured memory_bytes: 23764
import qualified Data.ByteString.Lazy.Char8 as B
import Data.Maybe
import qualified Data.Vector.Unboxed as V
import qualified Data.Vector.Unboxed.Mutable as VM
import Data.Char
import Data.List
import Control.Monad

bsReadInts :: B.ByteString -> [Int]
bsReadInts = map (fst . fromJust . B.readInt) . B.words

solve :: String -> Int
solve a = 1 + answer
  where
    vec = V.create $ do
      v <- VM.replicate 26 0
      forM a $ \c -> do
        let idx = ord c - ord 'a'
        when (idx >= 0 && idx < 26) (VM.modify v (+ 1) idx)
      return v
    lst = V.toList vec
    answer = sum $ zipWith (*) lst $ map sum $ tail (tails lst)

main :: IO ()
main = do
  cont <- B.getContents
  let answer = solve (B.unpack cont)
  putStrLn $ show answer
  


Measured memory_bytes: 6780
///
// File:  alds1_7_d.cpp
// Author: ymiyamoto
//
// Created on Sat Oct 14 19:07:05 2017
//

#include <cstdint>
#include <iostream>
#include <vector>

using namespace std;
#define SIZE 100

struct tree_t {
  uint32_t left;
  uint32_t right;
};

static vector<uint32_t> pre;
static vector<uint32_t> in;
static vector<uint32_t> post;
static uint32_t pos;

void reconstruct(uint32_t l, uint32_t r)
{
  if (l >= r) {
    return;
  }

  uint32_t top = pre[pos];
  pos++;
  uint32_t mid = 0;
  for (uint32_t i = 0; i < in.size(); i++) {
    if (in[i] == top) {
      mid = i;
    }
  }

  reconstruct(l, mid);
  reconstruct(mid + 1, r);

  post.push_back(top);
}

int32_t main()
{
  uint32_t n;
  cin >> n;

  for (uint32_t i = 0; i < n; i++) {
    uint32_t n;
    cin >> n;
    pre.push_back(n);
  }

  for (uint32_t i = 0; i < n; i++) {
    uint32_t n;
    cin >> n;
    in.push_back(n);
  }

  reconstruct(0, pre.size());

  for (uint32_t i = 0; i < post.size(); i++) {
    if (i != 0) cout << " ";
    cout << post[i];
  }

  cout << endl;

  return 0;
}

Measured memory_bytes: 3132
#include <iostream>
#include <cstdlib>
#include <string>
#include <typeinfo>
#include <cstring>
#include <iostream>
#define MAX 100005
#define NIL -1
using namespace std;
struct Node{int p,l,r;};
Node T[MAX];
int n,D[MAX];

void print(int u){
    int i,c;
    cout << "node " << u << ": ";
    cout << "parent = " << T[u].p << ", ";
    cout << "depth = " << D[u] << ", ";
    
    if(T[u].p == NIL)cout << "root, ";
    else if(T[u].l == NIL)cout << "leaf, ";
    else cout << "internal node, ";
    
    cout << "[";
    for(i = 0, c = T[u].l; c != NIL; i++, c = T[c].r){
        if(i) cout << ", ";
        cout << c;
    }
    cout << "]" << endl;
}

int rec(int u,int p){
    D[u] = p;
    if(T[u].r != NIL) rec(T[u].r,p);
    if(T[u].l != NIL) rec(T[u].l,p + 1);
}

int main(){
    int i,j,d,c,l,r,v;
    cin >> n;
    for(i = 0; i < n; i++)T[i].p = T[i].l = T[i].r = NIL;
    for(i = 0;i < n; i++){
        cin >> v >> d;
        for(j = 0; j < d ; j++){
            cin >> c;
            if(j == 0) T[v].l = c;
            else T[l].r = c;
            l = c;
            T[c].p = v;
        }
    }
    for(i = 0; i < n; i++)if(T[i].p == NIL)r = i;
    rec(r,0);
    for(i = 0; i < n; i++)print(i);
    return 0;
}
    
    
    
    




Measured memory_bytes: 7704
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using P = pair<int, int>;
using vi = vector<int>;
using vvi = vector<vector<int>>;
using vll = vector<ll>;
using vvll = vector<vector<ll>>;
const double eps = 1e-10;
const int MOD = 1000000007;
const int INF = 1000000000;
const ll LINF = 1ll<<50;
template<typename T>
void printv(const vector<T>& s) {
  for(int i=0;i<(int)(s.size());++i) {
    cout << s[i];
    if(i == (int)(s.size())-1) cout << endl;
    else cout << " ";
  }
}
int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout << fixed << setprecision(10);
  int h, w, k; cin >> h >> w >> k;
  vector<vector<char>> b(h, vector<char>(w));
  vector<int> pos(k);
  vector<int> cnt(h);
  int now = 0;
  for(int i=0;i<h;++i) {
    for(int j=0;j<w;++j) {
      cin >> b[i][j];
      if(b[i][j] == '#') {
        pos[now] = i;
        cnt[i]++;
        now++;
      }
    }
  }
  now = 0;
  vvi dp(h, vi(w, -1));
  for(int i=0;i<h;++i) {
    int tmp = 0;
    bool init = true;
    for(int j=0;j<w;++j) {
      if(cnt[i] == 0) {
        if(i != 0) {
          dp[i][j] = dp[i-1][j];
        }
      } else {
        if(b[i][j] == '#') {
          if(init) {
            init = false;
          } else {
            tmp++;
          }
        }
        dp[i][j] = now + tmp;
      }
    }
    if(!init) now += tmp + 1;
  }
  for(int i=h-2;i>=0;--i) {
    for(int j=0;j<w;++j) {
      if(cnt[i] == 0 && dp[i][j] == -1) {
        dp[i][j] = dp[i+1][j];
      }
    }
  }
  for(int i=0;i<h;++i) {
    for(int j=0;j<w;++j) {
      cout << dp[i][j]+1;
      if(j == w-1) cout << endl;
      else cout << " ";
    }
  }
}


Measured memory_bytes: 1664
#include <iostream>
#include <bitset>
#include <cstring>
#include <algorithm>
using namespace std;
int r,c,ans,num;
bitset<10005> g[15];

int main()
{
   cin>>r>>c;
	while(r&&c)
	{
	    for (int i = 1; i <= r; i++) {
        for (int j = 1; j <= c; j++) {
            cin>>num;
			g[i][j]=num;
        }
        }
       ans=0;
   //每一行都有是否翻转这2种情况，最多2的r次方种。
		//从0000000000～1111111111，等于1的，对应行翻身，等于0的，对应行不翻身
        for(int i=0;i<(1<<r);i++)
		{
			 
			//把i表示成二进制字符串,从右数第row_id位上的数字是否为1
			for(int row_id=0;row_id<=9;row_id++)
			{
				if(!(i>>row_id)) break;
				if((i>>row_id)&1) g[row_id+1].flip();
			}
			//不必真的翻转列。取每一列朝向数较多的
			int temp=0;
			int shang;
			int xia;
			for(int j=1;j<=c;j++)
			{
				shang=0;
				
				for(int k=1;k<=r;k++)
				{
					if(g[k][j]) shang++;
					
				}
				xia=r-shang;
				if(shang>=xia) temp+=shang;
				else temp+=xia;
			}
			ans=ans>temp?ans:temp;
			//恢复原状
			for(int row_id=0;row_id<=9;row_id++)
			{
				if(!(i>>row_id)) break;
				if((i>>row_id)&1) g[row_id+1].flip();
			}
		}
		cout<<ans<<endl;
		cin>>r>>c;
	}

	
	
   return 0;
}


Measured memory_bytes: 3112
#include<bits/stdc++.h>
#define rep(i,a,...) for(int i = (a)*(strlen(#__VA_ARGS__)!=0);i<(int)(strlen(#__VA_ARGS__)?__VA_ARGS__:(a));++i)
#define per(i,a,...) for(int i = (strlen(#__VA_ARGS__)?__VA_ARGS__:(a))-1;i>=(int)(strlen(#__VA_ARGS__)?(a):0);--i)
#define foreach(i, n) for(auto &i:(n))
#define pii pair<int, int>
#define pll pair<long long, long long>
#define all(x) (x).begin(), (x).end()
#define bit(x) (1ll << (x))
using ll = long long;
//const ll MOD = (ll)1e9+7;
const ll MOD = 998244353;
const int INF = (ll)1e9+7;
const ll INFLL = (ll)1e18;
using namespace std;
template<class t>
using vvector = vector<vector<t>>;
template<class t>
using vvvector = vector<vector<vector<t>>>;
template<class t>
using priority_queuer = priority_queue<t, vector<t>, greater<t>>;
template<class t, class u> bool chmax(t &a, u b){if(a<b){a=b;return true;}return false;}
template<class t, class u> bool chmin(t &a, u b){if(a>b){a=b;return true;}return false;}
#ifdef DEBUG
#define debug(x) cout<<"LINE "<<__LINE__<<": "<<#x<<" = "<<x<<endl;
#else
#define debug(x) (void)0
#endif

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

ll modinv(ll x){
  return modpow(x, MOD-2);
}

bool was_output = false;
template<class t>
void output(t a){
  if(was_output)cout << " ";
  cout << a;
  was_output = true;
}
void outendl(){
  was_output = false;
  cout << endl;
}
ll in(){
  ll res;
  scanf("%lld", &res);
  return res;
}

template<class t>
istream& operator>>(istream&is, vector<t>&x){
  for(auto &i:x)is >> i;
  return is;
}

template<class t, class u>
istream& operator>>(istream&is, pair<t, u>&x){
  is >> x.first >> x.second;
  return is;
}

template<class t>
void in(t&x){
  cin >> x;
}

int n;
vector<int> ns(3);
vector<string> strs(3);

void init(){
  rep(i,3){
    in(strs[i]);
    ns[i]=strs[i].size();
  }
  n = *max_element(all(ns));
}

int isok(int s1,int s2,int dis){
  static vvvector<int> dp(3,vvector<int>(3,vector<int>(n*2+1,-1)));
  int &it = dp[s1][s2][dis];
  if(it>=0)return it;

  int res = 1;
  rep(i,dis,ns[s1]){
    int p1 = i;
    int p2 = i-dis;
    if(ns[s2]<=p2)break;
    if(strs[s1][p1]=='?'||strs[s2][p2]=='?')continue;
    if(strs[s1][p1]==strs[s2][p2])continue;
    res = 0;
    break;
  }
  return it = res;
}

int main(){
  init();
  int ans = INF;
  rep(s1,3){
    rep(s2,3){
      if(s1==s2)continue;
      rep(dis1,n+1){
        if(!isok(s1,s2,dis1))continue;
        int s3 = 3 - s1 - s2;
        rep(dis2,n+1){
          if(!isok(s1,s3,dis1+dis2)||!isok(s2,s3,dis2))continue;
          chmin(ans,max({ns[s1],dis1+ns[s2],dis1+dis2+ns[s3]}));
          break;
        }
      }
    }
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
 
#define int long long
const int MOD = 1e9 + 7;
using ll = long long;
using ld = long double;
using intpair = pair<int, int>;
struct Fast {Fast(){cin.tie(0);ios::sync_with_stdio(0);}} fast;
inline int mod (ll a, int m = MOD) { return (a % m + m) % m; }
 
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define reps(i, n, m) for (int i = (int)(n); i <= (int)(m); i++)
#define ALL(obj) (obj).begin(), (obj).end()
#define rALL(obj) (obj).rbegin(), (obj).rend()
#define ceiv(a, b) ((ll)((a) + (b) - 1)/(ll)(b))

int binom_max = 2e5+1;
vector<int> fact(binom_max), inv_fact(binom_max), inv(binom_max);
void modbinom_init() {
    fact[0] = fact[1] = 1;
    inv_fact[0] = inv_fact[1] = 1;
    inv[1] = 1;
    for(int i=2; i<binom_max; i++){
        fact[i] = fact[i-1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        inv_fact[i] = inv_fact[i-1] * inv[i] % MOD;
    }
}

int modbinom(int n, int k){
    if (n<k) return 0;
    if (n<0 || k<0) return 0;
    return fact[n] * (inv_fact[k] * inv_fact[n-k] % MOD) % MOD;
}

signed main(){
    modbinom_init();
    int n, k;
    cin >> n >> k;
    vector<int> a(n);
    rep(i,n) cin >> a[i];
    
    ll ans = 0;
    
    sort(ALL(a));
    reps(i,k-1,n-1){
        ans = mod(ans + mod(a[i] * modbinom(i, k-1)));
    }
    
    sort(rALL(a));
    reps(i,k-1,n-1){
        ans = mod(ans - mod(a[i] * modbinom(i, k-1)));
    }
    
    cout << ans << endl;
}

Measured memory_bytes: 5760
N = int(input())
H = list(map(int, input().split()))

cost = [0] * N
for i in range(1, N):
  d1 = cost[i-1] + abs(H[i] - H[i-1])
  d2 = cost[i-2] + abs(H[i] - H[i-2]) if i > 1 else 1e6
  cost[i] = min(d1, d2)
#print(cost)
ans = cost[N-1]
print(ans)

Measured memory_bytes: 13980
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
int main(void){
    int a,b,c;
    scanf("%d %d %d",&a,&b,&c);
    printf("%d\n",max(max(a,b),c)-min(min(a,b),c));
}
 
int min(int a,int b){
    int ans;
    if(a>b){return b;}
    else {return a;}
}
 
int max(int a,int b){
    int ans;
    if(a>b){return a;}
    else {return b;}
}

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

#define dbg(a)	cerr << __LINE__ << ": " << #a << " = " << a << '\n'

int main(){
	int n, k;	cin >> n >> k;
	string s;	cin >> s;
	s[k-1] = s[k-1]+32;
	cout << s << endl;
	return 0;
}		

Measured memory_bytes: 256
import numpy as np
from functools import *
import sys
sys.setrecursionlimit(100000)
input = sys.stdin.readline




def acinput():
    return list(map(int, input().split(" ")))


def II():
    return int(input())

directions=np.array([[1,0],[0,1],[-1,0],[0,-1]])
directions = list(map(np.array, directions))

mod = 10**9+7


def factorial(n):
    fact = 1
    for integer in range(1, n + 1):
        fact *= integer
    return fact


ascii_lowercase = 'abcdefghijklmnopqrstuvwxyz'

res=[]
def search(seq,k,n):
    global N
    
    if k==N+1:

        tmp=[ascii_lowercase[s-1] for s in seq[1:]]
        res.append("".join(tmp))
        return 
    
    seq[k]=n
    search(seq,k+1,n+1)
    
    for l in range(1,n):
        seq[k] = l
        search(seq, k+1,n)
    

def cmb(n, r):
    if n - r < r:
        r = n - r
    if r == 0:
        return 1
    if r == 1:
        return n

    numerator = [n - r + k + 1 for k in range(r)]
    denominator = [k + 1 for k in range(r)]

    for p in range(2, r+1):
        pivot = denominator[p - 1]
        if pivot > 1:
            offset = (n - r) % p
            for k in range(p-1, r, p):
                numerator[k - offset] /= pivot
                denominator[k] /= pivot

    result = 1
    for k in range(r):
        if numerator[k] > 1:
            result *= int(numerator[k])

    return int(result)


def nCr(n, r):
    """
    Calculate the number of combination (nCr = nPr/r!).
    The parameters need to meet the condition of n >= r >= 0.
    It returns 1 if r == 0, which means there is one pattern
    to choice 0 items out of the number of n.
    """

    # 10C7 = 10C3
    r = min(r, n-r)

    # Calculate the numerator.
    numerator = 1
    for i in range(n, n-r, -1):
        numerator *= i

    # Calculate the denominator. Should use math.factorial?
    denominator = 1
    for i in range(r, 1, -1):
        denominator *= i

    return numerator // denominator


N=int(input())
A=acinput()


y=[0]*(max(A)+1)
for i in range(N):
    y[A[i]]+=1

cb=[0]*len(y)

b=0
for i in range(1,len(y)):
    if y[i] >= 2:
        cb[i]=cmb(y[i],2)
    
        b+=cb[i]
    
for i in range(N):
    k=A[i]
    #print(i,k,y)
    tmp=0
    if y[k]-1>=2:
        tmp = nCr(y[k]-1, 2)
    tmp2=b-cb[k]+tmp
    #print("y",y[k],nCr(y[k]-1, 2))
    print(tmp2)
    
#print(cb)
    
#print(y)
#print(b)



Measured memory_bytes: 42532
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<map>
#include<set>
#include<utility>
#include<cmath>
#include<cstring>
#include<cstdio>
#define loop(i,a,b) for(int i=a;i<b;i++) 
#define rep(i,a) loop(i,0,a)
#define pb push_back
#define mp make_pair
#define all(in) in.begin(),in.end()
const double PI=acos(-1);
const double EPS=1e-10;
const int inf=1e8;
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
int main(){
	int n;
	cin>>n;
	int m=100010;
	vi in(m,0);
	rep(i,n){
		int a,b;
		cin>>a>>b;
		in[a]++;
		in[b+1]--;
	}
	int ma=-1;
	int co=0;
	rep(i,m){
		co+=in[i];
		//cout<<i<<" "<<co<<endl;
		if(i-1<=co)ma=max(ma,i-1);
	}
	cout<<ma<<endl;
}

Measured memory_bytes: 1536
#include<stdio.h>
int main()
{
    int A,B;
    scanf("%d %d",&A,&B);
    int sum;
    sum =A+B;
    if(sum%2==0){
        sum=sum/2;
        printf("%d",sum);
    }
    else {
        printf("IMPOSSIBLE");

    }return 0;
}


Measured memory_bytes: 128
n,m=map(int,input().split())
a=[]
b=[]
f=list(range(m+1))
for _ in range(n):
  a.append(list(map(int,input().split()))[1:])
for i in range(1,m+1):
  g=0
  for j in range(n):
    if i not in a[j]:
      g=1
      break
  if g==0:
    b.append(i)
print(len(b))

Measured memory_bytes: 3064
#include<iostream>
using namespace std;
 
int main(){
  int a, b, c, d, e;
  cin >> a >> b;
  c = a + b;
  d = a - b;
  e = a * b;
  if(c >= d && c >= e){
    cout << c;
  }
  else if(d >= c&& d >= e){
    cout << d;
  }
  else if(e >= c&& e >= d){
    cout << e;
  }
}

Measured memory_bytes: 3636
#include <iostream>
#include <algorithm>
#include <vector>
#include <deque>

using namespace std;

bool to(int &x, int y) {
  if (x > y) {
    x = y;
    return true;
  }
  return false;
}

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

  deque<int> q;
  q.push_back(1);

  vector<int> dp(K, 1e9);
  dp[1] = 1;

  while (!q.empty()) {
    int u = q.front(); q.pop_front();
    int d = dp[u];
    if (to(dp[u * 10 % K], dp[u])) {
      q.push_front(u * 10 % K);
    }
    if (to(dp[(u + 1) % K], dp[u] + 1)) {
      q.push_back((u + 1) % K);
    }
  }

  cout << dp[0] << endl;
}


Measured memory_bytes: 896
#include<stdio.h>

int n;
int A[2000001], B[2000001];
void countingSort(int*, int*, int);

int main(){
  int i;
  scanf("%d", &n);
  for(i = 0 ; i < n ; i++){
    scanf("%d", &A[i]);
  }
  countingSort(A, B, 10001);
  for(i = 1 ; i <= n ; i++){
    printf("%d", B[i]);
    if(i != n) printf(" ");
    else printf("\n");
  }
}

void countingSort(int* A, int* B, int k){
  int C[k], i;
  for(i = 0 ; i < k ; i++) C[i] = 0;
  for(i = 0 ; i < n ; i++) C[A[i]]++;
  for(i = 1 ; i < k ; i++) C[i] = C[i] + C[i-1];
  for(i = n-1 ; i >= 0 ; i--){
    B[C[A[i]]] = A[i];
    C[A[i]]--;
  }
}



Measured memory_bytes: 17400
#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <cmath>
#include <algorithm>
#include <vector>
#include <numeric>
#include <queue>
#include <stack>
#include <map> 
#include <set>
#include <string>
#include <functional>
#include <list>
#include <random>
#include <time.h>
#include <iomanip>
#include <assert.h>
#include <numeric>
#include <new>
#include <sstream>
#include <complex>
#define BIT(nr) (1ULL << (nr))
#define int long long
#define ll long long
#define double complex<long double>
#define mod 1000000007
#define MAXN (int)1e+5 * 2+1
#define LL_MAX 9223372036854775807	
#define LL_HALFMAX 9223372036854775807 / 2	
#define MIN -(9223372036854775807 / 2)
#define REP(i,a,n) for(int i=(a); i<(int)(n); i++)
#define rep(i,n) REP(i,0,n)
#define FOR(it,c) for(__typeof((c).begin()) it=(c).begin(); it!=(c).end(); ++it)
#define ALLOF(c) (c).begin(), (c).end()
#define REPS(i,x) for(int i=1;i<=(int)(x);i++)
#define RREP(i,x) for(int i=((int)(x)-1);i>=0;i--)
#define RREPS(i,x) for(int i=((int)(x));i>0;i--)
#define repl(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define mp make_pair
template<typename T1, typename T2> inline void chmin(T1 & a, T2 b) { if (a > b) a = b; }
template<typename T1, typename T2> inline void chmax(T1& a, T2 b) { if (a < b) a = b; }

using namespace std;



signed main() {
	int N;
	cin >> N;
	vector<int> A(N), B(N), C(N);
	rep(i, N) {
		cin >> A[i];
	}
	rep(i, N) {
		cin >> B[i];
	}
	rep(j, N) {
		cin >> C[j];
	}
	sort(ALLOF(A));
	sort(ALLOF(B));
	sort(ALLOF(C));

	int ans = 0;
	// B 全探索
	rep(i, N) {
		auto ait = lower_bound(ALLOF(A), B[i]);
		auto cit = upper_bound(ALLOF(C), B[i]);

		int acnt = ait - A.begin();
		int ccnt = C.end() - cit;
		ans += acnt * ccnt;
	}

	cout << ans << "\n";

	return 0;
}

Measured memory_bytes: 5636