akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;

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

#define INF 2e9
#define ll long long

int main(){
    int n;
    cin>>n;
    while(1){
        if(n%111==0){
            break;
        }
        n++;
    }
    cout<<n<<endl;
    return 0;
}

Measured memory_bytes: 256
from sys import stdin
from itertools import groupby
import math 

n,k = [int(x) for x in stdin.readline().rstrip().split()]
r,s,p = [int(x) for x in stdin.readline().rstrip().split()]
t = stdin.readline().rstrip()
t = [i for i in t]
point = 0

for i in range(k):
    li = t[i::k]
    lin = []
    for key, value in groupby(li):
        lin.append((key,len(list(value))))
    for j in lin:
        if j[0] == "r":
            point += math.ceil(j[1]/2)*p
        elif j[0] == "s":
            point += math.ceil(j[1]/2)*r
        else:
            point += math.ceil(j[1]/2)*s

print(point)

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

int main()
{
  ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
  int n, m;
  cin >> n >> m;
  
  char c;
  
  cout << string(m+2, '#') << endl;
  for(int i = 0; i < n; i++)
  {
    cout << "#";
    for(int j = 0; j < m; j++)
    {
      cin >> c;
      cout << c;
    }
    cout << "#" << endl;
  }
      
  cout << string(m+2, '#') << endl;  
  return 0;
}


Measured memory_bytes: 256
package main

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

func nextInt(sc *bufio.Scanner) int {
	sc.Scan()
	s := sc.Text()
	n, err := strconv.Atoi(s)
	if err != nil {
		panic(err)
	}
	return n
}

func main() {
	sc := bufio.NewScanner(os.Stdin)
	sc.Split(bufio.ScanWords)
	n := nextInt(sc)
	s := make([]int, n)
	for i := 0; i < n; i++ {
		s[i] = nextInt(sc)
	}
	q := nextInt(sc)
	t := make([]int, q)
	for i := 0; i < q; i++ {
		t[i] = nextInt(sc)
	}

	result := 0
	for _, x := range t {
		exist := binarySearch(s, x)
		if exist {
			result++
		}
	}
	fmt.Println(result)
}

func binarySearch(as []int, x int) bool {
	for {
		if len(as) == 0 {
			return false
		} else if len(as) == 1 {
			return as[0] == x
		}
		m := len(as) / 2
		v := as[m]
		if x < v {
			as = as[:m]
		} else {
			as = as[m:]
		}
	}
}



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

using namespace std;

using ll = long long;
using ld = long double;

const int INF = (1 << 30) - 1;
const ll INF64 = ((ll)1 << 62) - 1;
const double PI = 3.1415926535897932384626433832795;

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

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

	int n;
	cin >> n;

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

	sort(a.begin(), a.end(), greater<int>());

	int alice = 0, bob = 0;
	for (int i = 0; i < n; i++) {
		if (i % 2 == 0) {
			alice += a[i];
		} else {
			bob += a[i];
		}
	}

	cout << alice - bob << endl;
	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <set>
#include <map>
using namespace std;

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

  int n;
  cin >> n;
  string s;
  cin >> s;

  int cnt = 0;
  for(int i = n - 1; i >= 0; i--){
    if(s[i] == '(') cnt--;
    else cnt++;
    if(cnt < 0){
      s += ")";
      cnt++;
    }
  }
  for(int i = 0; i < cnt; i++){
    s = "(" + s;
  }
  cout << s << endl;
}

Measured memory_bytes: 256
h,w = gets.split.map(&:to_i)
s = []
h.times{s << gets.chomp.split("")}

ans = 0
h.times do |x|
    w.times do |y|
        next if s[x][y] == "#"

        dp = Array.new(h){Array.new(w)}
        dp[x][y] = 0
        queue = [[x,y]]

        loop do
            sx, sy = queue.shift
            break if !sx || !sy

            if sx > 0 && s[sx-1][sy] != "#" && !dp[sx-1][sy] 
                dp[sx-1][sy] = dp[sx][sy] + 1
                queue << [sx-1,sy]
            end

            if sx < h-1 && s[sx+1][sy] != "#" && !dp[sx+1][sy] 
                dp[sx+1][sy] = dp[sx][sy] + 1
                queue << [sx+1,sy]
            end

            if sy > 0 && s[sx][sy-1] != "#" && !dp[sx][sy-1] 
                dp[sx][sy-1] = dp[sx][sy] + 1
                queue << [sx,sy-1]
            end

            if sy < w-1 && s[sx][sy+1] != "#" && !dp[sx][sy+1] 
                dp[sx][sy+1] = dp[sx][sy] + 1
                queue << [sx,sy+1]
            end
        end

        m = dp.map{|e| e.compact.max}.compact.max
        ans = m if ans < m
    end
end

puts ans

Measured memory_bytes: 1916
n = gets.to_i

c = (0..9).to_a.map { |a| Array.new(10, 0) }

1.upto(n) do |i|
  i_s = i.to_s
  c[i_s[0].to_i][i_s[-1].to_i] += 1
end

result = 0

10.times do |i|
  10.times do |j|
    result += c[i][j] * c[j][i]
  end
end

print result

Measured memory_bytes: 1788
import java.util.*;

import static java.lang.System.*;

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

        int[] x = new int[M];
        int[] y = new int[M];
        for (int i = 0; i < M; i++) {
            x[i] = sc.nextInt();
            y[i] = sc.nextInt();
        }

        boolean[] redExists = new boolean[N + 1];
        int[] nums = new int[N + 1];
        redExists[1] = true;
        Arrays.fill(nums, 1);

        for (int i = 0; i < M; i++) {
            if (redExists[x[i]]) {
                if (nums[x[i]] == 1) {
                    redExists[x[i]] = false;
                }

                redExists[y[i]] = true;
            }
            nums[x[i]]--;
            nums[y[i]]++;
        }

        int cnt = 0;
        for (int n = 1; n <= N; n++) {
            if(redExists[n]) {
                cnt++;
            }
        }

        out.println(cnt);
    }
}

Measured memory_bytes: 77260
#include <bits/stdc++.h>
#include <functional>
#include <algorithm>
#include <math.h>
using namespace std;

int main(){
  int64_t N;
  cin>>N;
  int F;
  F=10;
  for(int64_t A=1;A<=sqrt(N);++A){
    if(N%A==0){
      int64_t B=N/A;
      int a,b;
      a=log(A)/log(10);
      b=log(B)/log(10);
      if(F>max(a+1,b+1)){
        F=max(a+1,b+1);
      }
    }
    }
    cout<<F<<endl;
}

Measured memory_bytes: 256
package main

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

func main() {
	// https://emtubasa.hateblo.jp/entry/2019/03/31/015542
	nq := nextIntArray()
	n, q := nq[0], nq[1]
	s := nextLine()
	t, d := make([]byte, q), make([]byte, q)
	for i := 0; i < q; i++ {
		a := nextLine()
		t[i], d[i] = a[0], a[2]
	}

	// 消滅しないロボットの左端、右端
	l, r := 0, n-1
	// 後ろから見る
	for i := q - 1; i >= 0; i-- {
		if s[l] == t[i] && d[i] == 'L' {
			l++
		} else if l > 0 && s[l-1] == t[i] && d[i] == 'R' {
			l--
		}

		if s[r] == t[i] && d[i] == 'R' {
			r--
		} else if r < n-1 && s[r+1] == t[i] && d[i] == 'L' {
			r++
		}

		// 一度クロスしたらもとに戻らないので
		if l > r {
			fmt.Println(0)
			return
		}
	}
	fmt.Println(r - l + 1)
}

func lcm(a, b int64) int64 {
	return (a / gcd(a, b)) * b
}

func gcd(a, b int64) int64 {
	for b != 0 {
		a, b = b, a%b
	}
	return a
}

const size = 1000000

var reader = bufio.NewReaderSize(os.Stdin, size)

func nextLine() string {
	var line, buffer []byte
	isPrefix := true
	var err error
	for isPrefix {
		line, isPrefix, err = reader.ReadLine()
		if err != nil {
			panic(err)
		}
		buffer = append(buffer, line...)
	}
	return string(buffer)
}
func nextStringArray() []string {
	return strings.Split(nextLine(), " ")
}
func nextInt() int {
	n, _ := strconv.Atoi(nextLine())
	return n
}

func nextIntArray() []int {
	s := strings.Split(nextLine(), " ")
	n := len(s)
	a := make([]int, n)
	for i := 0; i < n; i++ {
		a[i], _ = strconv.Atoi(s[i])
	}
	return a
}

func min(i, j int) int {
	if i > j {
		return j
	}
	return i
}

func max(i, j int) int {
	if i < j {
		return j
	}
	return i
}


Measured memory_bytes: 5504
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;++i)
#define rrep(i,n) for(int i=n-1;i>=0;--i)
#define fi first
#define se second
#define sz(x) (int)(x).size()
#define all(v) v.begin(),v.end()
#define rall(v) v.rbegin(),v.rend()
using namespace std;
using ll = long long;
using P = pair<int, int>;
template<typename T> inline bool chmax(T &a,T b){if(a<b){a=b;return 1;}return 0;}
template<typename T> inline bool chmin(T &a,T b){if(b<a){a=b;return 1;}return 0;}
template<typename T> vector<T> make_vec(size_t a){return vector<T>(a);}
template<typename T,typename... Ts>
auto make_vec(size_t a,Ts... ts){return vector<decltype(make_vec<T>(ts...))>(a,make_vec<T>(ts...));}
template<typename T,typename U,typename... V>
typename enable_if<is_same<T,U>::value>::type fill_v(U &u,const V... v){u=U(v...);}
template<typename T,typename U,typename... V>
typename enable_if<!is_same<T,U>::value>::type fill_v(U &u,const V... v){for(auto &e:u)fill_v<T>(e,v...);}

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

    int n, t;
    cin >> n >> t;
    vector<int> a(n);
    rep(i, n) cin >> a[i];
    vector<int> rev_mx(n);
    rev_mx[n-1] = a[n-1];
    rrep(i, n-1) rev_mx[i] = max(a[i], rev_mx[i+1]);
    map<int, int> mp;
    rep(i, n) {
        mp[rev_mx[i] - a[i]]++;
    }
    cout << mp.rbegin()->second << endl;
}


Measured memory_bytes: 8632
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); i++)
#define repf(i,a,b) for (int i = (a); i < (b); i++)
#define repi(i,a,b) for (int i = (a); i <= (b); i++)
#define repr(i,a,b) for (int i = (a); i >= (b); i--)
#define all(x) (x).begin(),(x).end()
#define debug(x)  cout << #x << " = " << (x) << endl;
using namespace std;
using uint = unsigned int;
using ll = long long;
using ull = unsigned long long;
using vi = vector<int>;
using vvi = vector<vi>;
using pii = pair<int, int>;
using vc = vector<char>;
using vvc = vector<vc>;
using vs = vector<string>;
using tiii = tuple<int, int, int>;

int main() {
  int A, B, C, K;
  cin >> A >> B >> C >> K;
  cout << A + B + C + max({A,B,C})*((1<<K) - 1) << endl;
}

Measured memory_bytes: 256
using System;
using System.Linq;
using System.Collections.Generic;

namespace program
{
    class Program
    {
        static void Main()
        {
          int[] n = Input.ScanIntArray();
          if((n[0]+1)/2 >= n[1])
          Console.WriteLine("YES");
          else
            Console.WriteLine("NO");
          
        }
    }

    static class Input
    {
        static public int ScanInt() { return int.Parse(Console.ReadLine()); }
        static public uint ScanUint() { return uint.Parse(Console.ReadLine()); }
        static public double ScanDouble() { return double.Parse(Console.ReadLine()); }
        static public long ScanLong() { return long.Parse(Console.ReadLine()); }
        static public ulong ScanUlong() { return ulong.Parse(Console.ReadLine()); }
        static public int[] ScanIntArray() { return Console.ReadLine().Split(' ').Select(x => int.Parse(x)).ToArray(); }
        static public uint[] ScanUintArray() { return Console.ReadLine().Split(' ').Select(x => uint.Parse(x)).ToArray(); }
        static public double[] ScanDoubleArray() { return Console.ReadLine().Split(' ').Select(x => double.Parse(x)).ToArray(); }
        static public long[] ScanLongArray() { return Console.ReadLine().Split(' ').Select(x => long.Parse(x)).ToArray(); }
        static public ulong[] ScanUlongArray() { return Console.ReadLine().Split(' ').Select(x => ulong.Parse(x)).ToArray(); }

        static public string ScanStr() { return Console.ReadLine(); }
        static public string[] ScanStrArray() { return ScanStr().Split(' '); }
    }

    static class MyMath
    {
        public static int GCD(int a, int b)
        {
            Func<int, int, int> gcd = null;
            gcd = (x, y) => y == 0 ? x : gcd(y, x % y);
            return a > b ? gcd(a, b) : gcd(b, a);
        }
        public static ulong GCD(ulong a, ulong b)
        {
            Func<ulong, ulong, ulong> gcd = null;
            gcd = (x, y) => y == 0 ? x : gcd(y, x % y);
            return a > b ? gcd(a, b) : gcd(b, a);
        }
        public static int LCM(int a, int b)
        {
            return a * b / GCD(a, b);
        }
        public static ulong LCM(ulong a, ulong b)
        {
            return a * b / GCD(a, b);
        }
    }
}


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

using namespace std;

int main(){
	int N, M; //N;Switch, M;light

	cin >> N >> M;
	int K;
	int s;

	vector<vector<int>> data(N, vector<int>(0));
	for (int m=0; m<M; m++){
		cin >> K;

		for (int k=0; k<K; k++){
			cin >> s;
			data[s-1].push_back(m);
		}
	}

	vector<int> P(M);
	for (int m=0; m<M; m++){
		cin >> P[m];
	}

	int ans = 0;

	//bit全探索
	for (int bit = 0; bit < (1<<N); ++bit){
		vector<int> count(M, 0);

		for (int i = 0; i < N; ++i) {
            if (bit & (1<<i)) {
                for (int ms : data[i]){
                	count[ms] += 1;
                }
            }
        }
                    // 要素の判断
        int check = 0;
        for (int m=0; m<M; m++){
        	check += abs(count[m]-P[m])%2;
        }
        if (check == 0){
        	ans += 1;
        }
	}

	cout << ans << endl;
}

Measured memory_bytes: 256
import sys

rln=lambda:next(sys.stdin)
rfs=lambda:rln().split()
ris=lambda:list(map(int,rfs()))

n,m=ris()
adj=[[] for _ in range(n)]
for _ in range(m):
    a,b=ris()
    a,b=a-1,b-1
    adj[a].append(b)
    adj[b].append(a)

ans=0
vis=[0]*n
for i in range(n):
    if vis[i]:
        continue
    vis[i]=1
    k=0
    stk=[i]
    while stk:
        u=stk.pop()
        k+=1
        for v in adj[u]:
            if vis[v]:
                continue
            vis[v]=1
            stk.append(v)
    ans=max(ans,k)

print(ans)


Measured memory_bytes: 109704
import Control.Monad
import Data.List
main = do
  [n,m] <- map read . words <$> getLine
  abs <- replicateM n (map read . words <$> getLine)
  let sortedABs = sortOn fst $ map (\[a,b] -> (a,b)) abs
  print $ f 0 m sortedABs
  
f acc m ((a,b):xs)
  | m <= b = acc + m * a
  | m > b  = f (acc + b * a) (m-b) xs

Measured memory_bytes: 138620
#include <iostream>
#include <string>

int main() {

  int length = 0;
  std::cin >> length;

  std::string s, t;
  std::cin >> s >> t;

  std::string finalString = "";

  for (int i = 0; i < length; ++i) {
    finalString += s.at(i);
    finalString += t.at(i);
  }

  std::cout << finalString << std::endl;
}

Measured memory_bytes: 256
#include <cstdio>
#include <cstring>
#include <cctype>
#include <algorithm>
#include <vector>
using namespace std;

namespace zyt
{
	template<typename T>
	inline bool read(T &x)
	{
		char c;
		bool f = false;
		x = 0;
		do
			c = getchar();
		while (c != EOF && c != '-' && !isdigit(c));
		if (c == EOF)
			return false;
		if (c == '-')
			f = true, c = getchar();
		do
			x = x * 10 + c - '0', c = getchar();
		while (isdigit(c));
		if (f)
			x = -x;
		return true;
	}
	template<typename T>
	inline void write(T x)
	{
		static char buf[20];
		char *pos = buf;
		if (x < 0)
			putchar('-'), x = -x;
		do
			*pos++ = x % 10 + '0';
		while (x /= 10);
		while (pos > buf)
			putchar(*--pos);
	}
	int k;
	int work()
	{
		read(k);
		if (k == 1)
			puts("1"), puts("1");
		else
		{
			int n = (k + 3) / 4 * 2;
			printf("%d\n", n);
			for (int i = 0; i < n; i++)
			{
				for (int j = 0; j < n; j++)
					if (i & 1)
						printf("%d ", (i + j) % n + 1);
					else
						printf("%d ", ((i + j) % n + n < k ? (i + j) % n + n : (i + j) % n) + 1);
				puts("");
			}
		}
		return 0;
	}
}
int main()
{
	return zyt::work();
}

Measured memory_bytes: 1152
#include <iostream>
#include <string>

using namespace std;

string s;

int main(void)
{
	cin >> s;
	
	int ans = s.size();
	for(char c = 'a'; c <= 'z'; c++){
		string t = s;
		for(int i = 0; i < s.size(); i++){
			bool flag = true;
			for(int j = 0; j < t.size(); j++) flag &= (t[j] == c);
			if(flag){
				ans = min(ans, i);
				break;
			}
			for(int j = 0; j < t.size()-1; j++){
				if(t[j] == c || t[j+1] == c) t[j] = c;
			}
			t.erase(t.end()-1);
			
		}
	}
	cout << ans << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using Graph = vector<vector<int>>;
#define rep(i,a,b) for (int i = (a); i < (b); i++ )
typedef pair<int,int> P;
typedef long long ll;
const int INF = 100000000;
const double PI=3.14159265358979323846;

ll ans = 0;
void dfs(vector<int> &a, vector<ll> &S) {
    
    if (a.size()==4) {
        ll tmp = 1;
        rep(i,1,4) {
            //cout << a[i] << " ";
            tmp *= S[a[i]-1];
        }
        ans+=tmp;
        return;
    }
    else {
        int t = a.back()+1;
        for (int i=t; i<=5; i++) {
            a.push_back(i);
            dfs(a,S);
            a.pop_back();
        }
        return;
    }
}

int main (){
    ll N;
    vector<ll> S(5,0);
    vector<char> M = {'M','A','R','C','H'};

    cin >> N;
    rep(i,0,N) {
        string tmp;
        cin >> tmp;

        rep(j,0,5) {
            if (tmp[0] == M[j]) {
                S[j]++;
            }
        }

    }
    vector<int> a(1,0);
    dfs(a,S);
    cout << ans << endl;
}





Measured memory_bytes: 256
//#include <bits/stdc++.h>
//#include <stdio.h>
#include<iostream>
#include<cstdio>
#include<bitset>
#include<algorithm>
#include<vector>
#include<list>
#include<queue>
#include<stack>
#include<string>
#include<string.h>
#include<cmath>
#include<utility>
#include<functional>
#include<map>
#include<set>
#include<cctype>
#include<fstream>


#define FOR(i, a, b) for( int i=(a);i<=(b);i++)
#define RFOR(i, a, b) for( int i=(a);i>=(b);i--)
#define LFOR(i, a, b) for( long long int i=(a);i<=(b);i++)
#define LRFOR(i, a, b) for(long long int i=(a);i>=(b);i--)
#define MOD 1000000007
#define INF 1000000000 //2000000000
#define LLINF 1000000000000000000 //9000000000000000000
#define PI 3.14159265358979
#define MAXI 7500000

using namespace std;
typedef long long int ll;
typedef pair< long long int, long long  int> P;
typedef string::const_iterator State;

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


int main(void) {

	string s;
	int count[26] = {};
	int mini;
	bool flag = false;

	cin >> s;
	FOR(i, 0, s.size() - 1) {
		count[s[i] - 'a']++;
	}
	if (s.size() == 26) {
		flag = true;
	}

	if (flag) {
		mini = s[25] - 'a';
		count[s[25]-'a']--;
		RFOR(i, 24, 0) {
			//cout << s[i] << endl;
			if (s[i] <mini+'a') {
				s.erase(s.begin()+i+1,s.end());
				//cout << s << endl;
				//cout << i << endl;
				//cout << s[i] << endl;
				FOR(j, s[i] - 'a', 25) {
					//cout << j << endl;
					if (count[j] == 0) {
						s[i] = 'a' + j;
						break;
					}
				}
				break;
			}
			mini = s[i] - 'a';
			count[s[i] - 'a']--;
			if (i == 0) {
				s = "-1";
			}
		}
	}
	else {
		FOR(i, 0, 25) {
			if (count[i] == 0) {
				s.push_back('a' + i);
				break;
			}
		}
	}

	cout << s << endl;

	return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
int main(){
  int i;
  while(1){
    char str[1000];
    int s=0;
    scanf("%s\n",str);
    if(str[0]=='0') break;
    for(i=0;str[i]!='\0';i++){
      s+=str[i]-'0';
    }
    printf("%d\n",s);
  }
  return 0;
}


Measured memory_bytes: 2720
#include <iostream>
#include <cstdio>
#include <cstring>
#include <climits>
#include <string>
#include <algorithm>
#include <cmath>
#include <vector>
#include <stack>
#include <queue>
#include <map>
#include <unordered_map>
#include <set>
#include <unordered_set>
#include <sstream>
#include <numeric>
#include <iomanip>
// #include <boost/multiprecision/cpp_dec_float.hpp>
// #include <boost/multiprecision/cpp_int.hpp>

///////////////////////////////////////////////////////////////
// namespace
///////////////////////////////////////////////////////////////
using namespace std;
// namespace mp = boost::multiprecision;

///////////////////////////////////////////////////////////////
// types
///////////////////////////////////////////////////////////////
using ll = long long int;
using ld = long double;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
// using mpi = mp::cpp_int;
// using mpf = mp::number<mp::cpp_dec_float<1024>>;

///////////////////////////////////////////////////////////////
// mod https://qiita.com/drken/items/3b4fdf0a78e7a138cd9a
///////////////////////////////////////////////////////////////
// ll MOD = 1000000007;
//
//  ll mod(ll val) {
//      ll res = val % MOD;
//      if (res < 0) res += MOD;
//      return res;
//  }
//
// ll modinv(ll a) {
//     ll b = MOD, u = 1, v = 0;
//     while (b) {
//         ll t = a / b;
//         a -= t * b; swap(a, b);
//         u -= t * v; swap(u, v);
//     }
//     u %= MOD;
//     if (u < 0) u += MOD;
//     return u;
// }
//
// const int MAX = -1;
// ll fac[MAX], finv[MAX], inv[MAX];
// void com_init() {  // initialize nCk table with O(N)
//     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;
//     }
// }
// ll com(int n, int k){  // nCk
//     if (n < k) return 0;
//     if (n < 0 || k < 0) return 0;
//     return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
// }


int main() {
    int A, B, C, K; cin >> A >> B >> C >> K;
    if (K <= A) {
        cout << K << endl;
        return 0;
    } else if (K <= A + B) {
        cout << A << endl;
        return 0;
    } else {
        cout << A - (K - A - B) << endl;
        return 0;
    }

    // cout << setprecision(10);
    return 0;
}


Measured memory_bytes: 3636
#include <stdio.h>

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


int main(void) {

    int N; scanf("%d", &N);
    long dp[N][3];

    int a[N], b[N], c[N];
    for(int i = 0; i < N; i++) {
        scanf("%d %d %d", &a[i], &b[i], &c[i]);
    }

    dp[0][0] = a[0];
    dp[0][1] = b[0];
    dp[0][2] = c[0];

    for(int i = 0; i < N-1; i++) {
        dp[i+1][0] = max(dp[i][1] + a[i+1], dp[i][2] + a[i+1]);
        dp[i+1][1] = max(dp[i][0] + b[i+1], dp[i][2] + b[i+1]);
        dp[i+1][2] = max(dp[i][0] + c[i+1], dp[i][1] + c[i+1]);
    }

    int ans = max(max(dp[N-1][0], dp[N-1][1]), dp[N-1][2]);

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

    return 0;
}

Measured memory_bytes: 3712
#include <cstdio>
#include <vector>
using namespace std;

const int N = 100005, M = 200005, inf = 0x3f3f3f3f;
int n, p[N], fa[N];
vector<int> E[N], F[N];

namespace flow {
	const int V = 2 * N, E = 2 * (M + 2 * N);
	int ans, S, T, tot = 1, nxt[E], fst[V], to[E], f[E], cur[V], d[V];
	void addedge(int u, int v, int w) {
		nxt[++tot] = fst[u]; fst[u] = tot; to[tot] = v; f[tot] = w;
		nxt[++tot] = fst[v]; fst[v] = tot; to[tot] = u; f[tot] = 0;
	}
	bool bfs() {
		static int q[E];
		int st = 0, ed = 0;
		q[ed++] = S;
		for (int i = 1; i <= T; i++) d[i] = -1, cur[i] = fst[i];
		d[S] = 0;
		while (st < ed) {
			int u = q[st++];
			for (int i = fst[u]; i; i = nxt[i])
				if (f[i] && d[to[i]] == -1) {
					d[to[i]] = d[u] + 1;
					if (to[i] == T) return true;
					q[ed++] = to[i];
				}
		}
		return false;
	}
	int aug(int u, int flow) {
		if (u == T || !flow) return flow;
		int used = 0;
		for (int &i = cur[u], w; i; i = nxt[i])
			if (d[to[i]] == d[u] + 1 && (w = aug(to[i], min(f[i], flow - used)))) {
				f[i] -= w, f[i ^ 1] += w;
				if ((used += w) == flow) break;
			}
		if (!used) d[u] = -1;
		return used;
	}
	int dinic() {
		while (bfs()) ans += aug(S, inf);
		return ans;
	}
}

void dfs(int u) {
	for (int v : F[u])
		if (!fa[p[v]]) {
			fa[p[v]] = u;
			dfs(p[v]);
		}
}

int main() {
	scanf("%d", &n);
	flow::S = 2 * (n - 1) + 1, flow::T = 2 * (n - 1) + 2;
	for (int i = 1, k; i < n; ++i) {
		scanf("%d", &k);
		E[i].resize(k);
		for (int j = 0; j < k; ++j) {
			scanf("%d", &E[i][j]);
			if (E[i][j] != n)
				flow::addedge(E[i][j], n - 1 + i, 1);
			F[E[i][j]].push_back(i);
		}
		flow::addedge(flow::S, i, 1);
		flow::addedge(n - 1 + i, flow::T, 1);
	}
	int x = flow::dinic();
	if (x != n - 1) return !puts("-1");
	for (int i = 2; i <= flow::tot; i += 2)
		if (!flow::f[i] && flow::to[i] != flow::T && flow::to[i ^ 1] != flow::S)
			p[flow::to[i] - n + 1] = flow::to[i ^ 1];
	fa[n] = -1, dfs(n);
	for (int i = 1; i < n; ++i)
		if (!fa[i]) return !puts("-1");
	for (int i = 1; i < n; ++i)
		printf("%d %d\n", fa[p[i]], p[i]);
	return 0;
}


Measured memory_bytes: 29056
#include <bits/stdc++.h>
 
#define f(i,a,b) for( ll i = a; i < b ; i++ )
#define af(i,a,b) for( ll i = a; i >= b ; i--)
#define rep(i,a,b,k) for(ll i = a; i < b ; i+= k )
#define arep(i,a,b,k) for( ll i = a; i >= b ; i-= k)
#define ones(x) (ll) __builtin_popcount(x)
#define fs first
#define sc second
#define pb push_back
#define po pop_back
#define mp make_pair 
#define sz(a) (ll) a.size()
#define all(a) a.begin(), a.end()
#define sor(a) sort( a.begin(), a.end() )
#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL)
#define ller ios::sync_with_stdio(false);cin.tsie(nullptr);cout.tie(nullptr)
#define watch(x) cout << (#x) << " is " << (x) <<"\n"
#define PI 3.1415926535
using namespace std;
typedef long long ll;
typedef long double ld; 
typedef pair<ll,ll> ii ;
typedef vector<ll>  vi ;
typedef vector<ii> vii ;
const ll mod = 1e9;
const ll MAX = 1e5+10;
const ll inf = 1e18+7;

int main(){
	fastio;
	string s;
	cin>>s;
	if(*s.rbegin()=='s') s+="es";
	else s.pb('s');
	cout<<s<<"\n";
    return 0; 
}

Measured memory_bytes: 3616
N,M=list(map(int, input().split()))
ans=1
for i in range(1,int(M**0.5)+1):
  if M%i==0:
    j=M//i
    if i>=N:
      ans=max(ans,j)
    if j>=N:
      ans=max(ans,i)
print(ans)

Measured memory_bytes: 63080
#include<stdio.h>
#include<stdlib.h>

int main(){

    int n,k,q,i,j,a,po[100000];
    

    scanf("%d %d %d",&n,&k,&q);
    for(i=1;i<=n;i++){
        po[i]=0;
    }
    for(i=0;i<q;i++){
        scanf("%d",&a);
        po[a]++;
    }
    for(i=1;i<=n;i++){
        if(k-q+po[i]>0){
            printf("Yes\n");
        }else{
            printf("No\n");
        }
    }

    return 0;
}

Measured memory_bytes: 896
#include <cstdio>
#include <cstring>
#include <iostream>
#include <string>
#include <cmath>
#include <bitset>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <algorithm>
#include <complex>
#include <unordered_map>
#include <unordered_set>
#include <random>
#include <cassert>
#include <fstream>
#include <utility>
#include <functional>
#define popcount __builtin_popcount
using namespace std;
typedef long long int ll;
typedef pair<int, int> P;

int main()
{
	int n, k; cin>>n>>k;
	int ans=0;
	for(int i=0; i<n; i++){
		int h; cin>>h;
		if(h>=k) ans++;
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 256
#pragma GCC optimize(3, "Ofast", "inline")
#include <bits/stdc++.h>
#define ll long long

using namespace std;

const int maxn = 1e5 + 5;

int n;

int main() {
	ios::sync_with_stdio(false);
	cin.tie(nullptr), cout.tie(nullptr);
	int d, t, s;
	cin >> d >> t >> s;
	cout << ((d <= t * s) ? "Yes" : "No");
	return 0;
}

Measured memory_bytes: 3648
#include <bits/stdc++.h>
using namespace std;
const int mod=1000000007;
#define rep(i,n) for(int i = 0; i < (n); i++)
#define FOR(i,a,b) for(int i = (a); i < (b); i++)
#define FORQ(i,a,b) for(int i = (a); i <= (b); i++)
#define FORD(i,a,b) for(int i = (a)-1; i >= b; i--)
using vi = vector<int>;

bool isin(int x, int y){
  return (0 <= x) and (x < 8) and (0 <= y) and (y < 8);
}

vi dx = {1,0,-1,0,1,1,-1,-1}, dy = {0,1,0,-1,1,-1,1,-1};

int main(){
  vector<string> board(8);
  rep(i,8) cin >> board[i];
  bool ismami = true;
  int notchanged = 0;

  while(1){
    //cerr << ismami << endl;
    vector<string> prev = board; // 前の盤面を取っておくよう
    vector<string> next = board; // 数最大の候補
    int rnum = 0; // 最大のひっくり返せる数

    if(ismami){
      rep(i,8) rep(j,8){ // (i,j)に置くことを試す
	board = prev;
	int tmp = 0; // (i,j)に置くときにひっくり返せる数
	if(board[i][j] != '.') continue;
	rep(k,8) FORQ(l,1,8){
	  int nx = i + l * dx[k], ny = j + l * dy[k];
	  if(not isin(nx,ny)) break;
	  if(board[nx][ny] == 'x') continue;
	  if(board[nx][ny] == 'o'){
	    //cerr << i << "\t" << j << "\t" << l << endl;
	    tmp += l - 1;
	    FOR(m, 0, l) board[i+m*dx[k]][j+m*dy[k]] = 'o';
	    break;
	  }
	  if(board[nx][ny] == '.') break;
	}
	if(tmp > rnum){
	  //cerr << tmp << endl;
	  rnum = tmp;
	  next = board;
	}
      }
    }else{
      FORD(i,8,0) FORD(j,8,0){ // (i,j)に置くことを試す
	board = prev;
	int tmp = 0; // (i,j)に置くときにひっくり返せる数
	if(board[i][j] != '.') continue;
	rep(k,8) FORQ(l,1,8){
	  int nx = i + l * dx[k], ny = j + l * dy[k];
	  if(not isin(nx,ny)) break;
	  if(board[nx][ny] == 'o') continue;
	  if(board[nx][ny] == 'x'){
	    tmp += l - 1;
	    FOR(m, 0, l) board[i+m*dx[k]][j+m*dy[k]] = 'x';
	    break;
	  }
	  if(board[nx][ny] == '.') break;
	}
	if(tmp > rnum){
	  //cerr << tmp << endl;
	  rnum = tmp;
	  next = board;
	}
        
      }
    }

    board = next;
    ismami = not ismami;
    
    if(prev == next) notchanged++;
    else notchanged = 0;
    if(notchanged == 2) break;
    // rep(i,8){
    //   rep(j,8) cerr << board[i][j];
    //   cerr << endl;
    // }
  }
  rep(i,8){
    rep(j,8) cout << board[i][j];
    cout << endl;
  }
}


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

int main(){
 int H, W;
    while(1){
     cin >> H >> W;
     if( H == 0 && W  == 0 ) break;

        for( int i = 0; i < H; i++ ){
            for( int j = 0; j < W; j++ ){
                if( i == 0 || i == H - 1 || j == 0 || j == W-1 ){
                 cout << "#";
                } else {
                  cout << ".";
                }
            }
           cout << "\n";
        }
        cout << endl;
     }
    
 return 0;
}

Measured memory_bytes: 1152
#include <iostream>
#include <string>
#include <cstdlib>
#include <cstdio>
#include <queue>
#include <stack>
#include <list>
#include <utility>
#include <vector>
#include <set>
#include <algorithm>
#include <cmath>
#include <climits>
#include <map>
#include <unordered_map>
#include <string.h>
#include<iomanip>
#include <iterator>
#include <locale>

#define all(a) a.begin(),a.end()
#define VV(T) vector<vector< T > >
#define rep(i,N) for(int i = 0; i <N; i++)
#define repsg(i,s,g) for(int i = s; i <g; i++)
#define name(x) #x
using namespace std;

const int INF = INT_MAX;
const long long INFL = 1LL<<40;
const double PI = atan(1)*4;
const long long MOD = pow(10,9)+7;
int dy[]={0, 0, 1, -1, 0};
int dx[]={1, -1, 0, 0, 0};

typedef long long ll,LL;
typedef vector<int> vint;
typedef vector<vector<int> > vvint;
typedef vector<long long> vll, vLL;
typedef vector<vector<long long> > vvll, vvLL;
typedef pair<int,int> pii;
typedef pair<LL, LL> pLL;


// vector入力
template<typename T>
istream& operator >> (istream& is, vector<T>& vec){
    for(T& x: vec) is >> x;
    return is;
}
// vector出力
template<typename T>
ostream& operator << (ostream& os, vector<T>& vec){
    for(int i=0; i<vec.size(); i++){
        os << vec[i] << ( i+1 == vec.size() ? "" : " " );
    }
    return os;
}



ll dp[101][10];


ll cnt(ll len){
    
    if(len<=0)return 1LL;
    
    return cnt(len-1)+cnt(len-2);
}

int main() {
    ll h,w,k;cin>>h>>w>>k;
    
    dp[0][1]=1LL;
    
    repsg(i,1,h+1){
        dp[i][1]  = dp[i-1][2]*cnt(w-3) + dp[i-1][1]*cnt(w-2);
        dp[i][1]%=MOD;
        repsg(j,2,w){
            dp[i][j] = dp[i-1][j-1]*cnt(j-3)*cnt(w-(j+1))+dp[i-1][j+1]*cnt(j-2)*cnt(w-(j+2)) + dp[i-1][j]*cnt(j-2)*cnt(w-(j+1));
            dp[i][j]%=MOD;
        }
        dp[i][w]=dp[i-1][w-1]*cnt(w-3)+dp[i-1][w]*cnt(w-2);
        dp[i][w]%=MOD;
    }
    
    cout<<dp[h][k]<<endl;
    
    
    
    return 0;
}






Measured memory_bytes: 256
#include <bits/stdc++.h>
#define INF 1e8

using namespace std;
typedef long long int ll;


int main()
{
    int H,W; cin >> H >> W;
    vector<vector<char>>G(H,vector<char>(W));
    vector<vector<int>>d(H,vector<int>(W,-1));
    queue<pair<int,int>>que;
    for(int i = 0; i < H; i++)
    {
        for(int j = 0; j < W; j++)
        {
            cin >> G[i][j];
            if(G[i][j] == '#') 
            {
                d[i][j] = 0;
                que.push(pair(i,j));
            }
        }
    }
    int dh[4] = {1,0,-1,0};
    int dw[4] = {0,1,0,-1};
    while(!que.empty())
    {
        auto p = que.front();
        que.pop();
        int h = p.first;
        int w = p.second;
        for(int i = 0; i < 4; i++)
        {
            int nh = h + dh[i];
            int nw = w + dw[i];
            if(nh >= H || nh < 0 || nw < 0 || nw >= W) continue;
            if(d[nh][nw] != -1) continue;
            d[nh][nw] = d[h][w] + 1;
            que.push(pair(nh,nw));
        }
    }
    int ans = 0;
    for(int i = 0; i < H; i++) for(int j = 0; j < W; j++) ans = max(ans,d[i][j]);
    cout << ans << endl;
}

Measured memory_bytes: 16072
#include<bits/stdc++.h>
using namespace std;
#define reg register

const int MAXN=500+5;

int n,K;
int a[MAXN][MAXN];

int main(void){
	scanf("%d",&K);
    if(K<=500){
    	printf("%d\n",K);
    	for(reg int i=1;i<=K;++i)
    		for(reg int j=1;j<=K;++j)
				printf("%d%c",i,j==K?'\n':' ');
	}
	else{
		n=500;
		for(reg int i=0;i<n;++i)
			for(reg int j=0;j<n;++j)
				a[i][j]=(i+j)%n+1;
		for(reg int i=n+1;i<=K;++i)
			for(reg int j=0;j<n;++j)
				if((j&1)==0)
					a[(i-1-j+n)%n][j]=i;
		printf("%d\n",n);
		for(reg int i=0;i<n;++i)
			for(reg int j=0;j<n;++j)
				printf("%d%c",a[i][j],j==n-1?'\n':' ');
	}
	return 0;
}

Measured memory_bytes: 2176
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <functional>
#include <queue>
#include <set>
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define rep1(i,n) for(int i=1;i<=(int)(n);i++)

using namespace std;
typedef long long int lli;

int main() {
	int N;
	cin >> N;
	int q = N / 8;
	int r = N % 8;
	if (N == 3)cout << 2 << " " << 5 << " " << 63;
	else if (N == 4)cout << 2 << " " << 5 << " " << 20 << " " << 63;
	else {
		rep(i, q) {
			cout << 12 * i + 2 << " ";
			cout << 12 * i + 3 << " ";
			cout << 12 * i + 4 << " ";
			cout << 12 * i + 6 << " ";
			cout << 12 * i + 8 << " ";
			cout << 12 * i + 9 << " ";
			cout << 12 * i + 10 << " ";
			cout << 12 * i + 12 << " ";
		}
		if (r == 1)cout << 12 * q + 6;
		if (r == 2)cout << 12 * q + 2 << " " << 12 * q + 4 << " ";
		if (r == 3)cout << 12 * q + 2 << " " << 12 * q + 4 << " " << 12 * q + 6 << " ";
		if (r == 4)cout << 12 * q + 2 << " " << 12 * q + 4 << " " << 12 * q + 6 << " " << 12 * q + 12 << " ";
		if (r == 5)cout << 12 * q + 2 << " " << 12 * q + 3 << " " << 12 * q + 6 << " " << 12 * q + 9 << " " << 12 * q + 10 << " ";
		if (r == 6)cout << 12 * q + 2 << " " << 12 * q + 3 << " " << 12 * q + 6 << " " << 12 * q + 9 << " " << 12 * q + 10 << " " << 12 * q + 12 << " ";
		if (r == 7)cout << 12 * q + 2 << " " << 12 * q + 3 << " " << 12 * q + 4 << " " << 12 * q + 6 << " " << 12 * q + 8 << " " << 12 * q + 9 << " " << 12 * q + 10 << " ";
	}
}

Measured memory_bytes: 384
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace C
{
    class Program
    {
        static void Main(string[] args)
        {
            int[] nm = RArInt();
            int n = nm[0];
            int m = nm[1];

            int min = int.MinValue;
            int max = int.MaxValue;

            for (int i = 0; i < m; i++)
            {
                int[] vs = RArInt();
                min = Math.Max(min, vs[0]);
                max = Math.Min(max, vs[1]);
            }

            if (max - min >= 0)
            {
                Console.WriteLine(max - min + 1);
            }
            else
            {
                Console.WriteLine(0);
            }
        }
        static string RSt() { return Console.ReadLine(); }
        static int RInt() { return int.Parse(Console.ReadLine().Trim()); }
        static long RLong() { return long.Parse(Console.ReadLine().Trim()); }
        static double RDouble() { return double.Parse(Console.ReadLine()); }
        static string[] RArSt(char sep = ' ') { return Console.ReadLine().Trim().Split(sep); }
        static int[] RArInt(char sep = ' ') { return Array.ConvertAll(Console.ReadLine().Trim().Split(sep), e => int.Parse(e)); }
        static long[] RArLong(char sep = ' ') { return Array.ConvertAll(Console.ReadLine().Trim().Split(sep), e => long.Parse(e)); }
        static double[] RArDouble(char sep = ' ') { return Array.ConvertAll(Console.ReadLine().Trim().Split(sep), e => double.Parse(e)); }
        static string WAr<T>(IEnumerable<T> array, string sep = " ") { return string.Join(sep, array.Select(x => x.ToString()).ToArray()); }
    }
}


Measured memory_bytes: 15292
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < n; i++)
#define rep2(i, x, n) for(int i = x; i <= n; i++)
#define rep3(i, x, n) for(int i = x; i >= n; i--)
#define elif else if
typedef long long ll;
typedef pair<ll, ll> P;
const ll MOD = 1e9+7;
const ll MOD2 = 998244353;
const ll INF = LLONG_MAX;
const string alpha = "abcdefghijklmnopqrstuvwxyz";

int main(){
    char C;
    cin >> C;
    rep(i, 26){
        if(alpha[i] == C){
            cout << alpha[i+1] << endl;
            exit(0);
        }
    }
}

Measured memory_bytes: 256
import java.util.*;

public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int a = sc.nextInt();
    int b = sc.nextInt();
    int hight = 0;
    for (int i = b - a; i >=1; i--) {
      hight += i;
    }
    System.out.println(hight - b);
  }
}

Measured memory_bytes: 22740
import java.math.BigInteger;
import java.util.Scanner;

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

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

int divide2(int x)
{
    int ret = 0;
    while (1)
    {
        if (x % 2 == 0)
        {
            ret++;
            x /= 2;
        }
        else
        {
            break;
        }
    }

    return ret;
}

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

    int ans = 1;
    int max_divide = 0;
    for (int i = 1; i <= N; i++)
    {
        int tmp = divide2(i);
        if (tmp > max_divide)
        {
            max_divide = tmp;
            ans = i;
        }
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<set>
#include<queue>
#include<vector>
#include<map>
#include<stack>
#include<algorithm>
#include <sstream>
using namespace std;
long long inf=100000000000007;
#define int long long
#define rep(i,n) for(int i=0;i<n;++i)
typedef pair<int,int>  P;
string alph("abcdefghijklmnopqrstuvwxyz");
struct edge{int to,cost;};
vector<edge> G[22];
char fi[1005][1005];
P sg[10];
int d[1005][1005];
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};
pair<int,double> s[1005];
int c=0;
int n,k;
signed main(){
    int n,k;cin>>n>>k;
    int count=1;
    for(int i=0; i<n; i++){
        if(count<=k)count*=2;
        else count+=k;
    }
    cout<<count<<endl;
    return 0;
}


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

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

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define ld double
#define ff first
#define ss second
int main(){
	ll ans=1;
	ll n,k;
	cin>>n>>k;
	ans=k;
	for(int i=1;i<n;++i) ans*=(k-1);
	cout<<ans<<"\n";
	return 0;
}


Measured memory_bytes: 3640
#include<bits/stdc++.h>
using namespace std;
#define int long long int 

// #include <ext/pb_ds/assoc_container.hpp> 
// #include <ext/pb_ds/tree_policy.hpp> 
// using namespace __gnu_pbds; 
  
// #define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update> 
signed main()
{
	int n;
	cin>>n;

	set<string> s;

	string str;

	for(int i=0;i<n;i++)
	{
		cin>>str;
		s.insert(str);
	}
	cout<<s.size();
	return 0;
}

Measured memory_bytes: 19156
import sys,heapq
from collections import deque,defaultdict
printn = lambda x: sys.stdout.write(x)
inn = lambda : int(input())
inl   = lambda: list(map(int, input().split()))
inm   = lambda:      map(int, input().split())
DBG = True # and False
def ddprint(x):
  if DBG:
    print(x)

n = inn()
d = inl()
d.sort()
k = n//2
if d[k-1]==d[k]:
    print(0)
else:
    print(d[k]-d[k-1])


Measured memory_bytes: 52684
#include <vector>
#include <list>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <cstring>

using namespace std;

#define INF 2140000000
#define MOD 1000000007

int main() {
	int n;
	int a = 0, b = 0, ab = 0;
	long long cnt = 0;

	cin >> n;

	vector<string> str(n);

	for (int i = 0; i < n; ++i) {
		cin >> str[i];

		if (str[i][0] == 'B' && str[i][(int) str[i].size() - 1] == 'A') {
			ab++;
		}
		else if (str[i][0] == 'B') {
			b++;
		}
		else if (str[i][(int) str[i].size() - 1] == 'A') {
			a++;
		}

		for (int j = 0; j < (int) str[i].size() - 1; ++j) {
			if (str[i][j] == 'A' && str[i][j + 1] == 'B') {
				cnt++;
			}
		}
	}

	if (ab > 1) {
		cnt += ab - 1;	
	}

	if (ab >= 1 && a > 0) {
		cnt += 1;
		a--;
	}

	if (ab >= 1 && b > 0) {
		cnt += 1;
		b--;
	}

	cnt += min(a, b);

	cout << cnt << endl;

	return 0;
}

Measured memory_bytes: 768
#include <stdio.h>

bool is_up(const float x1, const float y1,
			const float x2, const float y2,
			const float xp, const float yp){
	float y = 0.0;
	y = (y2 - y1)/(x2 - x1)*(xp - x1) + y1;
	return yp > y;
}

int main(void){
	float x[4];
	float y[4];
	while(scanf("%f,%f,%f,%f,%f,%f,%f,%f",
		x, y, x+1, y+1, x+2, y+2, x+3, y+3) != EOF){
		if(is_up(x[0], y[0], x[2], y[2], x[1], y[1]) ^
			is_up(x[0], y[0], x[2], y[2], x[3], y[3]) == 0){
			puts("NO");
		}else if(is_up(x[1], y[1], x[3], y[3], x[2], y[2]) ^
			is_up(x[1], y[1], x[3], y[3], x[0], y[0]) == 0){
			puts("NO");
		}else{
			puts("YES");
		}
	}
	return 0;
}

Measured memory_bytes: 0
'use strict'

function main(input) {
    let nums = input.split('\n')[1].split(' ').map(n => parseInt(n, 10));
    let count = 0;
    while (nums.every(n => n % 2 === 0)) {
        count++;
        nums = nums.map(n => n / 2);
    }
    console.log(count);
}
 
main(require('fs').readFileSync('/dev/stdin', 'utf8'));

Measured memory_bytes: 21192
#include<stdio.h>
int main(void)
{
	int n,i,mot=100000;
	scanf("%d",&n);
	for(i=0;i<n;i++){
		mot=mot*1.05;
		if(mot%1000>0){
			mot=mot-(mot%1000)+1000;
		}
	}
	printf("%d\n",mot);
	return 0;
}

Measured memory_bytes: 592
#define _CRT_SECURE_NO_WARNINGS
#include <stdio.h>
#include <math.h>

int main(void)
{
	int a, b, buff;

	scanf("%d %d", &a, &b);

	buff = b;

	while (1)
	{
		a *= 10;
		buff /= 10;
		if (buff == 0)
		{
			break;
		}
	}

	double buff_f, buff_i;
	buff_f = sqrt((double)(a + b));
	buff_i = (double)((int)(buff_f));

	if (fabs(buff_f - buff_i) < 1e-6)
	{
		printf("Yes");
	}
	else
	{
		printf("No");
	}
	printf("\n");

	return 0;
}

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

#define ll long long int

using namespace std;

ll solve(ll n) {
    ll res = 0;
    for (ll x = 1; x * x < n; ++x) {
        for (ll y = 1; x * x + y * y + x * y < n; ++y) {
            for (ll z = 1; x * x + y * y + z * z + x * y + y * z + z * x <= n; ++z) {
                if ((x * x + y * y + z * z + x * y + y * z + z * x) == n) ++ res;
            }
        }
    }
    return res;
}

int main() {
    ll n;
    cin >> n;
    for (ll i = 1; i <= n; ++i) {
        cout << solve(i) << endl;
    }
}



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

int main() {
  int n, tot = 0;
  cin >> n;
  vector<int> a(n), b(n);
  for (int i = 0; i < n; i++) cin >> a[i];
  for (int i = 0; i < n; i++) cin >> b[i];
  for (int i = 0; i < n; i++) {
    tot += max(0, a[i] - b[i]);
  }
  cout << tot << '\n';
  return 0;
}

Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.*;

public class Main {

    static Parser parser = new Parser();

    public static void main(String[] args) {
        int N = parser.parseInt();

        int[] a = new int[N * 3];
        for(int i = 0; i < N * 3; i++){
            int v = parser.parseInt();
            a[i] = v;
        }

        long preSum = 0;
        long[] preSums = new long[N + 1];
        PriorityQueue<Integer> priorityQueue = new PriorityQueue<>();
        for(int i = 0; i < N; i++){
            int v = a[i];
            preSum += v;
            priorityQueue.add(v);
        }
        preSums[0] = preSum;

        for(int i = 0; i < N; i++){
            int v = a[N + i];
            if(!priorityQueue.isEmpty() && priorityQueue.peek() < v){
                preSum -= priorityQueue.poll();
                preSum += v;
                priorityQueue.add(v);
            }
            preSums[i + 1] = preSum;
        }
        priorityQueue.clear();

        long postSum = 0;
        long[] postSums = new long[N + 1];
        PriorityQueue<Integer> reversePriorityQueue = new PriorityQueue<>(Comparator.reverseOrder());

        for(int i = 0; i < N; i++){
            int v = a[3 * N - 1 - i];
            postSum += v;
            reversePriorityQueue.add(v);
        }
        postSums[0] = postSum;

        for(int i = 0; i < N; i++){
            int v = a[N * 2 - 1 - i];
            if(!reversePriorityQueue.isEmpty() && reversePriorityQueue.peek() > v){
                postSum -= reversePriorityQueue.poll();
                postSum += v;
                reversePriorityQueue.add(v);
            }
            postSums[i + 1] = postSum;
        }

        long ans = Long.MIN_VALUE;
        for(int i = 0; i <= N; i++){
            ans = Math.max(ans, preSums[i] - postSums[N - i]);
        }

        System.out.println(ans);
    }

}

class Parser {
    private static final BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
    private static final Iterator<String> stringIterator = br.lines().iterator();
    private static final Deque<String> inputs = new ArrayDeque<>();

    void fill() {
        if(inputs.isEmpty()){
            if(!stringIterator.hasNext()) throw new NoSuchElementException();
            inputs.addAll(Arrays.asList(stringIterator.next().split(" ")));
        }
    }

    Integer parseInt() {
        fill();
        if(!inputs.isEmpty()) {
            return Integer.parseInt(inputs.pollFirst());
        }
        throw new NoSuchElementException();
    }

    Long parseLong() {
        fill();
        if(!inputs.isEmpty()) {
            return Long.parseLong(inputs.pollFirst());
        }
        throw new NoSuchElementException();
    }

    Double parseDouble() {
        fill();
        if(!inputs.isEmpty()) {
            return Double.parseDouble(inputs.pollFirst());
        }
        throw new NoSuchElementException();
    }

    String parseString() {
        fill();
        return inputs.removeFirst();
    }

}

Measured memory_bytes: 95276
from collections import defaultdict


def main():
    A = input()
    B = input()
    if A == B:
        print("EQUAL")
    elif len(A) == len(B):
        if A > B:
            print("GREATER")
        else:
            print("LESS")
    elif len(A) > len(B):
        print("GREATER")
    else:
        print("LESS")


if __name__ == '__main__':
    main()


Measured memory_bytes: 3316
#include <stdio.h>
#include <stdlib.h>

long long int getans(int n,long long int x);
long long int a[50],p[50];

 
int main(void){
 
  	int n,i;
  	unsigned long long int x;
  	
  	scanf("%d %lld",&n,&x);
	
  	a[0]=1;
  	p[0]=1;
  	for(i=1;i<50;i++){
    	a[i] = 2*a[i-1]+1;
      	p[i] = 2*p[i-1]+3;
    }
	printf("%lld",getans(n,x));
  
	return 0;
}

long long int getans(int n,long long int x){

	if(n == 0){
    	if(x <= 0)
      		return 0;
  		else
          	return 1;
    }
 	else if(x <=1+  p[n-1]){
    	return getans(n-1,x-1);
    }
  	else{
    	return a[n-1] +1  + getans(n-1, x-2-p[n-1]);
    }


}



Measured memory_bytes: 128