akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
 
using namespace std;
typedef long long ll;
 
const ll MOD = 1000000007;
 
ll fact[100005];
 
int N, K;
ll A[100005];
 
void init_fact() {
    ll f = 1;
    fact[0] = 1;
    for (int i = 1; i <= 100004; i ++) {
        f = (f * i) % MOD;
        fact[i] = f;
    }
}
 
void extgcd(ll a, ll b, ll *x, ll *y) {
    ll xx, yy;
    if (b == 0) {
        *x = 1;
        *y = 0;
    } else {
        ll q = a / b;
        ll r = a % b;
        extgcd(b, r, &xx, &yy);
        *x = yy;
        *y = xx - q * yy;
    }
}
 
ll inv(ll a) {
    ll x, y;
    extgcd(a, MOD, &x, &y);
    return (x + MOD) % MOD;
}
 
ll combination(int n, int r) {
    return fact[n] * inv(fact[r]) % MOD * inv(fact[n - r]) % MOD;
}
 
int main() {
    init_fact();
    cin >> N >> K;
    rep(i, N) cin >> A[i];
    sort(A, A + N);
    ll ans = 0;
    for (int i = K - 1; i < N; i ++) {
        ll c = combination(i, K - 1);
        ans = (ans + c * A[i] % MOD) % MOD;
    }
    for (int i = 0; i <= N - K; i ++) {
        ll c = combination(N - 1 - i, K - 1);
        ans = (ans + MOD - c * A[i] % MOD) % MOD;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 1792
#include <stdio.h>

int main(){
  	int N;
  	char S[100][11], tmps[11];
  	int P[100], pos[100];
  	int tmp;
  	
  	scanf("%d",&N);
  	for(int i = 0; i < N; i++){
    	scanf("%s %d\n",S[i], &P[i]);
      	pos[i] = i;
      	//printf("%s %d\n", S[i], P[i]);
    }
  	for(int i=1;i<N;i++){
    	for(int j=1;j<N;j++){
      		if(strcmp(S[j-1], S[j])>0){
              	//printf("%d:%s %d:%s\n",j-1,S[j-1],j,S[j]);
        		strcpy(tmps, S[j-1]);
              	//strcpy(tmpd, P[j-1]);
        		strcpy(S[j-1], S[j]);
              	//strcpy(P[j-1], P[j]);
        		strcpy(S[j], tmps);
              	//strcpy(P[j], tmpd);
              	tmp = P[j-1];
              	P[j-1] = P[j];
              	P[j] = tmp;
              	tmp = pos[j-1];
              	pos[j-1] = pos[j];
              	pos[j] = tmp;
      		}else if(strcmp(S[j-1], S[j])==0 && (P[j-1] < P[j])){
            	tmp = P[j-1];
              	P[j-1] = P[j];
              	P[j] = tmp;
              	tmp = pos[j-1];
              	pos[j-1] = pos[j];
              	pos[j] = tmp;
            }
    	}
  	}
  
  	for(int i = 0; i < N; i++){
    	//printf("%s %d %d\n",S[i], P[i], pos[i]+1);
      	printf("%d\n",pos[i]+1);
    }
	return 0;
}

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

public class Main {
	FastScanner in = new FastScanner(System.in);
	PrintWriter out = new PrintWriter(System.out);
	
	public void run() {
		int n = in.nextInt();
		int[][] map = new int[n][];
		for (int i = 0; i < n; i++) {
			map[i] = in.nextIntArray(n);
		}

		long res = 0;
		for (int i = 0; i < n; i++) for (int j = i + 1; j < n; j++) {
			res += Math.min(map[i][j], map[j][i]);
		}
		System.out.println(res);
		
		out.close();
	}

	public static void main(String[] args) {
		new Main().run();
	}

	public void mapDebug(int[][] a) {
		System.out.println("--------map display---------");

		for (int i = 0; i < a.length; i++) {
			for (int j = 0; j < a[i].length; j++) {
				System.out.printf("%3d ", a[i][j]);
			}
			System.out.println();
		}

		System.out.println("----------------------------");
		System.out.println();
	}

	public void debug(Object... obj) {
		System.out.println(Arrays.deepToString(obj));
	}

	class FastScanner {
		private InputStream stream;
		private byte[] buf = new byte[1024];
		private int curChar;
		private int numChars;

		public FastScanner(InputStream stream) {
			this.stream = stream;
			//stream = new FileInputStream(new File("dec.in"));

		}

		int read() {
			if (numChars == -1)
				throw new InputMismatchException();
			if (curChar >= numChars) {
				curChar = 0;
				try {
					numChars = stream.read(buf);
				} catch (IOException e) {
					throw new InputMismatchException();
				}
				if (numChars <= 0)
					return -1;
			}
			return buf[curChar++];
		}

		boolean isSpaceChar(int c) {
			return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
		}

		boolean isEndline(int c) {
			return c == '\n' || c == '\r' || c == -1;
		}

		int nextInt() {
			return Integer.parseInt(next());
		}

		int[] nextIntArray(int n) {
			int[] array = new int[n];
			for (int i = 0; i < n; i++)
				array[i] = nextInt();

			return array;
		}

		long nextLong() {
			return Long.parseLong(next());
		}

		long[] nextLongArray(int n) {
			long[] array = new long[n];
			for (int i = 0; i < n; i++)
				array[i] = nextLong();

			return array;
		}

		double nextDouble() {
			return Double.parseDouble(next());
		}

		double[] nextDoubleArray(int n) {
			double[] array = new double[n];
			for (int i = 0; i < n; i++)
				array[i] = nextDouble();

			return array;
		}

		String next() {
			int c = read();
			while (isSpaceChar(c))
				c = read();
			StringBuilder res = new StringBuilder();
			do {
				res.appendCodePoint(c);
				c = read();
			} while (!isSpaceChar(c));
			return res.toString();
		}

		String[] nextStringArray(int n) {
			String[] array = new String[n];
			for (int i = 0; i < n; i++)
				array[i] = next();

			return array;
		}

		String nextLine() {
			int c = read();
			while (isEndline(c))
				c = read();
			StringBuilder res = new StringBuilder();
			do {
				res.appendCodePoint(c);
				c = read();
			} while (!isEndline(c));
			return res.toString();
		}
	}
}

Measured memory_bytes: 24860
#include <stdio.h>
#include <string.h>
#define MAX 500000000
#define INF 2000000001

void swap(int, int);
int parent(int);
int left(int);
int right(int);
void risePriority(int);
void maxHeapify(int);
void insert(int);
int extract();

int A[MAX];
int length;

int main()
{
  int key;
  char order[8];
	
  length = 0;
  A[0] = INF;
	
  while(1)
    {
      scanf("%s", order);
		
      if(strcmp(order, "insert") == 0)
	{
	  scanf("%d", &key);
	  insert(key);
	}
      if(strcmp(order, "extract") == 0)
	{
	  printf("%d\n", extract());
	}
      if(strcmp(order, "end") == 0)
	{
	  break;
	}
    }
	
  return 0;
}

void swap(int i1, int i2)
{
  int tmp;

  tmp = A[i1];
  A[i1] = A[i2];
  A[i2] = tmp;
}

int parent(int i)
{
  return i / 2;
}

int left(int i)
{
  return 2 * i;
}

int right(int i)
{
  return 2 * i + 1;
}

void risePriority(int i)
{
  int p;
  p = parent(i);
	
  if(A[i] > A[p])
    {
      swap(i, p);
      risePriority(p);
    }
}

void maxHeapify(int i)
{
  int l, r;
  int largest;

  l = left(i);
  r = right(i);

  largest = i;
  if(l <= length && A[l] > A[largest])
    largest = l;
  if(r <= length && A[r] > A[largest])
    largest = r;

  if(largest != i)
    {
      swap(i, largest);
      maxHeapify(largest);
    }
}

void insert(int k)
{
  length++;
  A[length] = k;
	
  risePriority(length);
}

int extract()
{
  int ret;
	
  ret = A[1];
  swap(1, length);
  length--;
  maxHeapify(1);
	
  return ret;
}

Measured memory_bytes: 4692
#include<iostream>
#include<cstdio>
#include<cmath>
#include<algorithm>
#define ll long long
#define re register
using namespace std;
struct ios{
	template <typename ty> inline ios& operator >> (ty &x)
	{
		register int f=1;x=0;register char c=getchar();
		for(;c<'0'||c>'9';c=getchar()) if(c=='-') f=-1;
		for(;c>='0'&&c<='9';c=getchar()) x=(x<<1)+(x<<3)+(c^48);
		x*=f;return *this;
	}
	template <typename ty>  inline ios& operator << (ty x)
	{
		if(x<0) x=-x,putchar('-');
		if(x>9) *this << x/10;
		putchar(x%10+48);
		return *this;
	}
	inline ios& operator << (char x){putchar(x);return *this;}
}io;
const int N = 2e5+5;
int n,a[N];
int maxn = -1,smaxn=0;
int main()
{
	io>>n;
	for(register int i=1;i<=n;i++)
	{
		io>>a[i];
		if(a[i] >= maxn) smaxn = maxn,maxn = a[i];
		else smaxn = max(smaxn,a[i]);
	}
	for(register int i=1;i<=n;i++)
	{
		if(a[i]==maxn) io<<smaxn<<'\n';
		else io<<maxn<<'\n';
	}
	
	return 0;
}

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

int main() {
    int n, mi = 100, ma = 0;
    std::cin >> n;
    std::vector<int> a(n), count(n+1);
    for (int i = 0; i < n; i++) {
        std::cin >> a[i];
        count[a[i]]++;
        if (a[i] > ma) ma = a[i];
        if (a[i] < mi) mi = a[i];
    }

    if ((ma - 1) / 2 + 1 != mi) {
        std::cout << "Impossible" << std::endl;
        return 0;
    } else {
        if (count[mi] != ((ma % 2 == 0) ? 1 : 2)) {
            std::cout << "Impossible" << std::endl;
            return 0;
        }
        for (int i = mi + 1; i <= ma; i++) {
            if (count[i] < 2) {
                std::cout << "Impossible" << std::endl;
                return 0;
            }
        }
    }

    std::cout << "Possible" << std::endl;

    return 0;
}

Measured memory_bytes: 256
#pragma GCC optimize("O3")
//#pragma GCC target("avx2")
//#pragma GCC optimize("unroll-loops")

#include <bits/stdc++.h>

using namespace std;

#ifdef LOCAL
#include <prettyprint.hpp>
#define debug(...)  cerr << "[" << #__VA_ARGS__ << "]: ", d_err(__VA_ARGS__);
#else
#define debug(...) 83;
#endif

void d_err() {
    cerr << endl;
}

template <typename H, typename... T>
void d_err(H h, T... t) {
    cerr << h << " ";
    d_err(t...);
}

template <typename T>
void print(T x) {
    cout << x << "\n";
}

#define ALL(x) (x).begin(), (x).end()
#define FOR(i, m, n) for (int i = (m); i < (n); ++i)
#define REVFOR(i, m, n) for (int i = (n - 1); i >= (m); --i)
#define REP(i, n) FOR(i, 0, n)
#define REVREP(i, n) REVFOR(i, 0, n)
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define eb emplace_back
#define bcnt __builtin_popcountll

typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef pair<ll,ll> Pll;
typedef pair<int,int> Pin;

ll INF = 1e16;
int inf = 1e9;
ll MOD = 1e9+7;

int main(){
    cin.tie(0);
    ios_base::sync_with_stdio(false);
    cout << fixed << setprecision(20);

    int r, g; cin >> r >> g;

    print(2 * g - r);
}

Measured memory_bytes: 3608
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) FOR(i,0,n)
#define ALL(v) begin(v),end(v)
#define fi first
#define se second
template<typename A, typename B> inline bool chmax(A &a, B b) { if (a<b) { a=b; return 1; } return 0; }
template<typename A, typename B> inline bool chmin(A &a, B b) { if (a>b) { a=b; return 1; } return 0; }
using ll = long long;
using pii = pair<int, int>;
constexpr ll INF = 1ll<<30;
constexpr ll longINF = 1ll<<60;
constexpr ll MOD = 1000000007;
constexpr bool debug = 0;
//---------------------------------//

int main() {
	int N;
	cin >> N;
	vector<int> x(N), y(N);
	REP(i, N) cin >> x[i] >> y[i];
	
	double ans = 0;
	REP(i, N) REP(j, N) {
		if (i == j) continue;
		
		int dx = x[i] - x[j];
		int dy = y[i] - y[j];
		
		ans += hypot(dx, dy) / N;
	}
	printf("%.18lf\n", ans);
	return 0;
}


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

int main() {
  int a, b;
  cin >> b >> a;
  int N = 100;
  int fill = (N - 1) / 2;
  vector<string> grid;
  for (int i = 0; i < N; i++) {
    string line;
    for (int j = 0; j < N; j++) {
      if (j == 0) {
        line += ".";
        continue;
      }
      if (j == N - 1) {
        line += "#";
        continue;        
      }
      if (i % 2 == 0) {
        line += ".";
      } else {
        line += "#";
      }
    }
    grid.push_back(line);
  }
  int a_counter = 0;
  while(a > 1) {
    grid[1 + (a_counter / fill) * 2][2 + (a_counter % fill) * 2] = '.';
    a--;
    a_counter++;
  }
  int b_counter = 0;
  while (b > 1) {
    grid[N - 1 - (1 + (b_counter / fill) * 2)][N - 1 - (2 + (b_counter % fill) * 2)] = '#';
    b--;
    b_counter++;    
  }
  cout << 100 << ' ' << 100 << endl;
  for (int i = 0; i < N; i++) {
    cout << grid[i] << endl;
  }
  return 0;
}


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

using namespace std;

int main()
{
	string S;
	cin >> S;

	int a = stoi(S.substr(0, 2));
	int b = stoi(S.substr(2));

	bool x = 1 <= a && a <= 12;
	bool y = 1 <= b && b <= 12;

	if (x) {
		if (y) {
			cout << "AMBIGUOUS" << endl;
		}
		else {
			cout << "MMYY" << endl;
		}
	}
	else {
		if (y) {
			cout << "YYMM" << endl;
		}
		else {
			cout << "NA" << endl;
		}
	}
}


Measured memory_bytes: 256
#include<set>
#include<map>
#include<queue>
#include<cmath>
#include<string>
#include<cstdio>
#include<vector>
#include<cstring>
#include<iostream>
#include<algorithm>
#define rep(i,a,b) for (int i=a; i<=b; i++)
#define per(i,a,b) for (int i=a; i>=b; i--)
using namespace std;
typedef long long LL;
 
inline int read() {
    int x=0,f=1; char ch=getchar();
    while (!(ch>='0'&&ch<='9')) {if (ch=='-')f=-1;ch=getchar();}
    while (ch>='0'&&ch<='9') {x=x*10+(ch-'0'); ch=getchar();}
    return x*f;
}
 
const int N = 500005;
const double eps = 1e-8;
 
int n,head=0,tail=0;
double L,q[N][2];
 
int main() {
 
    n=read(); L=read();
    double S=0,V=0;
    rep(i,1,n) {
        int t=read(),v=read();
        V+=v; S+=(double)t*v;
        while (V>L&&head<tail) {
            if (V-L>=q[head][0]) {
                V-=q[head][0]; S-=q[head][0]*q[head][1];
                head++;
            } else {
                q[head][0]-=V-L; S-=(V-L)*q[head][1]; V=L;
                break;
            }
        }
        q[tail][0]=v; q[tail++][1]=t;
        printf("%lf\n",S/L);
        while (tail-head>=2) {
            if (q[tail-1][1]>q[tail-2][1]) break;
            q[tail-2][1]=(q[tail-2][0]*q[tail-2][1]+q[tail-1][0]*q[tail-1][1])/(q[tail-2][0]+q[tail-1][0]);
            q[tail-2][0]+=q[tail-1][0];
            tail--;
        }
    }
 
    return 0;
}

Measured memory_bytes: 16384
from fractions import gcd
# from datetime import date, timedelta
# from heapq import *
import heapq
import math
from collections import defaultdict, Counter, deque
from bisect import *
import itertools
import fractions
import sys
sys.setrecursionlimit(10 ** 7)
MOD = 10 ** 9 + 7
# input = sys.stdin.readline


def make_divisors(n):
    divisors = []
    for i in range(1, int(n**0.5)+1):
        if n % i == 0:
            divisors.append(i)
            if i != n // i:
                divisors.append(n//i)

    divisors.sort()
    return divisors


def main():

    # print(100, 100)
    # for i in range(100):
    #     s=""
    #     for j in range(100):
    #         if j % 2 == 0:
    #             if i % 2 == 0:
    #                 s += "#"
    #             else:
    #                 s += "."
    #         else:
    #             if i % 2 == 0:
    #                 s += "."
    #             else:
    #                 s += "#"
    #     print(s)



    h, w = map(int, input().split())
    maze = [input() for i in range(h)]
    ans = 0
    # if maze[0][0] == "#":
    #     ans+=1
    

    def Dijkstra_search(sx, sy):
        H = h
        W = w
        visited = [[False for i in range(W)] for j in range(H)]
        d = [[float("inf") for i in range(W)] for j in range(H)]  # now cost
        d[sx][sy] = 0

        queue = []
        heapq.heappush(queue, (0, (sx, sy)))
        while len(queue):
            cost, (x, y) = heapq.heappop(queue)

            if visited[x][y]:
                continue
            visited[x][y] = True

            for dx, dy in [[1, 0], [0, 1]]:
                nx = x + dx
                ny = y + dy
                if nx >= 0 and ny >= 0 and nx < H and ny < W:
                    if visited[nx][ny]:
                        continue

                    vd=cost
                    if maze[nx][ny] =="." and maze[x][y]=="#":
                        vd+=1
                    if d[nx][ny] > vd:
                        d[nx][ny] = vd
                        heapq.heappush(queue, (vd, (nx, ny)))

        if maze[h - 1][w - 1] == "#":
            d[h-1][w-1]+=1
        return d[h-1][w-1]

    ans += Dijkstra_search(0,0)
    print(ans)
 


if __name__ == '__main__':
    main()


Measured memory_bytes: 88408
n = input()
a = map(int, raw_input().split())
count = 0
for i in xrange(n):
	r = range(i+1, n)
	r.reverse()
	for j in r:
		if a[j] < a[j-1]:
			a[j], a[j-1] = a[j-1], a[j]
			count += 1
print ' '.join(map(str, a))
print count

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

using namespace std;

typedef long long LL;
const int MAXN=1024;
const int MAXW=2e4+10;
LL dp[MAXN][MAXW];
struct data{
	int w,s,t;
	LL v;
}a[MAXN];
int n;
LL ans;

bool cmp(data x,data y){
	return x.t<y.t;
}

int main(){
	cin>>n;
	for(int i=1;i<=n;i++){
		cin>>a[i].w>>a[i].s>>a[i].v;
		a[i].t=a[i].s+a[i].w;
	}
	
	sort(a+1,a+n+1,cmp);
	
	for(int i=1;i<=n;i++){
		for(int j=0;j<=a[i].t;j++){
			dp[i][j]=dp[i-1][j];
			if(j>=a[i].w){
				dp[i][j]=max(dp[i][j],dp[i-1][j-a[i].w]+a[i].v);
			}
			ans=max(ans,dp[i][j]);
		}
	}
	cout<<ans<<endl;
	return 0;
}
 

Measured memory_bytes: 157824
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define pai 3.14159265358979

int main()
{
    double long_length;
    double short_length;
    double long_angle;
    double short_angle;
    cin >> short_length >> long_length;
    double h, m;
    cin >> h >> m;

    // 長針の角度を計算(6度/分)
    long_angle = 6 * m;
    // 短針の角度を計算(0.5度/分)
    short_angle = 0.5 * m + (h * (360 / 12));

    double diff_angle = abs(long_angle - short_angle);
    diff_angle = min(diff_angle, 360 - diff_angle);

    double a = short_length;
    double c = long_length;
    double diff = diff_angle;
    double ans = a * a + c * c - 2 * a * c * cos(diff * (pai / 180));
    ans = sqrt(ans);
    cout << fixed << setprecision(15) << ans << endl;

    return 0;
}

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

int main() {
  
  int N;
  cin >> N;
  
  int max = 0;
  int ans = 1;
  
  for(int i = 0; i < N ; i++){
    
    int tmp = i +1 ;
    int counter = 0;
    
  	while(tmp % 2 == 0){
      tmp /= 2;
      counter++;
  	}
    
    if(max < counter){
      ans = i + 1;
      max = counter;
    }
   }
  cout << ans << endl;
}


           

Measured memory_bytes: 256
import java.io.IOException;
import java.io.InputStream;
import java.util.*;

public class Main {

    public static void main(String[] args) {
        FastScanner fs = new FastScanner();
        int n = fs.nextInt();
        int[] arr1 = new int[n];
        for (int i = 0; i < n; ++i) arr1[i] = fs.nextInt();

        int q = fs.nextInt();
        int res = 0;
        for (int i = 0; i < q; ++i) {
            int key = fs.nextInt();
            int left = -1;
            int right = arr1.length;
            while (right - left > 1) {
                int mid = (right + left) / 2;
                if (key<= arr1[mid]) right = mid;
                else left = mid;
            }
            if (right < n && arr1[right] == key) ++res;
        }

        System.out.println(res);
    }
}

class FastScanner {
    private final InputStream in = System.in;
    private final byte[] buffer = new byte[1024];
    private int ptr = 0;
    private int buflen = 0;

    private boolean hasNextByte() {
        if (ptr < buflen) {
            return true;
        }else{
            ptr = 0;
            try {
                buflen = in.read(buffer);
            } catch (IOException e) {
                e.printStackTrace();
            }
            if (buflen <= 0) {
                return false;
            }
        }
        return true;
    }

    private int readByte() { if (hasNextByte()) return buffer[ptr++]; else return -1;}
    private static boolean isPrintableChar(int c) { return 33 <= c && c <= 126;}
    public boolean hasNext() { while(hasNextByte() && !isPrintableChar(buffer[ptr])) ptr++; return hasNextByte();}

    public String next() {
        if (!hasNext()) throw new NoSuchElementException();
        StringBuilder sb = new StringBuilder();
        int b = readByte();
        while(isPrintableChar(b)) {
            sb.appendCodePoint(b);
            b = readByte();
        }
        return sb.toString();
    }

    public long nextLong() {
        if (!hasNext()) throw new NoSuchElementException();
        long n = 0;
        boolean minus = false;
        int b = readByte();
        if (b == '-') {
            minus = true;
            b = readByte();
        }
        if (b < '0' || '9' < b) {
            throw new NumberFormatException();
        }
        while(true){
            if ('0' <= b && b <= '9') {
                n *= 10;
                n += b - '0';
            }else if(b == -1 || !isPrintableChar(b)){
                return minus ? -n : n;
            }else{
                throw new NumberFormatException();
            }
            b = readByte();
        }
    }

    public int nextInt() {
        long nl = nextLong();
        if (nl < Integer.MIN_VALUE || nl > Integer.MAX_VALUE) throw new NumberFormatException();
        return (int) nl;
    }

    public double nextDouble() { return Double.parseDouble(next());}
}


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

int main() {
	double H, W, X, Y;
	cin >> H >> W >> X >> Y;
	printf("%.12lf ", H * W / 2);
	double MIDH, MIDW;
	MIDH = H / 2;
	MIDW = W / 2;
	if (MIDH == X && MIDW == Y) cout << 1;
	else cout << 0;
}

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

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

int n,m;
template<typename T> class Weighted_UnionFind
{
public:
    vector<int> par,nrank;
    vector<T> wd;
    int V;
    Weighted_UnionFind(int node_size){
        V = node_size;
        par.resize(V),wd.resize(V,0),nrank.resize(V,0);
        rep(i,V){
            par[i] = i;
        }
    }
    int find(int x){
        if(par[x] == x){
            return x;
        }else{
            int parent = find(par[x]);
            wd[x] += wd[par[x]];
            return par[x] = parent;
        }
    }
    T weight(int x){
        find(x);
        return wd[x];
    }
    void unite(int x,int y,T w){
        w += weight(x), w -= weight(y);
        x = find(x),y = find(y);
        if(x == y) return;
    	if(nrank[x] < nrank[y]){
            swap(x,y);
            w = -w;
        }
        nrank[x] += (nrank[x] == nrank[y]);
        par[y] = x;
        wd[y] = w;
    }
    bool same(int x,int y){
        return find(x)==find(y);
    }
    T diff(int x,int y){
        return weight(y)-weight(x);
    }
};


int main(){
    while(cin>>n>>m&&n!=0){
        Weighted_UnionFind<ll> wuf(n);
        rep(t,m){
            char c;
            cin >> c;
            if(c=='!'){
                int a,b;
                ll w;
                cin >> a>> b >> w;
                a--,b--;
                wuf.unite(a,b,w);
            }else{
                int a,b;
                cin >> a >> b;
                a--,b--;
                if(wuf.same(a,b)){
                    cout << wuf.diff(a,b) << endl;
                }else{
                    cout << "UNKNOWN" << endl;
                }
            }
        }
    }
    return 0;
}


Measured memory_bytes: 4420
#include<iostream>
using namespace std;
char s[105][105],x[105][105];
int xx(int x,int y){
	int s1=0;
	if(s[x-1][y-1]=='#') s1++;
	if(s[x-1][y]=='#') s1++;
	if(s[x-1][y+1]=='#') s1++;
	if(s[x][y+1]=='#') s1++;
	if(s[x][y-1]=='#') s1++;
	if(s[x+1][y-1]=='#') s1++;
	if(s[x+1][y]=='#') s1++;
	if(s[x+1][y+1]=='#') s1++;
	return s1;
}
int main(){
	int a,b;
	cin>>a>>b;
	for(int i=1;i<=a;i++){
		for(int j=1;j<=b;j++){
			cin>>s[i][j];
		} 
	}
	for(int i=1;i<=a;i++){
		for(int j=1;j<=b;j++){
			if(s[i][j]!='#') x[i][j]=xx(i,j)+'0';
			else x[i][j]='#';
		}
	}
	for(int i=1;i<=a;i++){
		for(int j=1;j<=b;j++){
			cout<<x[i][j];
		}
		cout<<endl;
	}
    return 0;
}

Measured memory_bytes: 256
#include<stdio.h>

int a, b, c, x, y;

void search(int i, int *no, int *min){
  if(i==3){
    int tmp = no[0]*2*c + no[1]*a + no[2]*b;
//    printf("%d %d %d %d\n",no[0],no[1],no[2],tmp);
    if(*min>tmp){
      *min = tmp;
    }
  }
  else if(i==0){
    if(x>y){
      for(int j=0;j<=x;j++){
        no[i] = j;
        search(i+1, no, min);
      }
    }
    else{
      for(int j=0;j<=y;j++){
        no[i] = j;
        search(i+1, no, min);
      }
    }    
  }
  else if(i==1){
    if(x<no[0]){
      no[i] = 0;
    }
    else{
      no[i] = x-no[0];
    }
    search(i+1, no, min);    
  }
  else{
    if(y<no[0]){
      no[i] = 0;
    }
    else{
      no[i] = y-no[0];
    }
    search(i+1, no, min);
  }  
}

int main(){
  int noPizza[3], minPrice=2000000000; 
  // noPizza[0]:AB pizza, noPizza[1]:A pizza, noPizza[2]:B pizza, 
  scanf("%d %d %d %d %d", &a, &b, &c, &x, &y);
  
  search(0, noPizza, &minPrice);
  printf("%d",minPrice);
  
  return 0;
}

Measured memory_bytes: 128
#include<bits/stdc++.h> 
//#define <- プログラムの文字列を置換する
//typedef <- 新しい型に名前を付けるためのキーワード

using namespace std;

#define MAX_N 1

typedef long long ll;

const double PI = 3.141592653589793;
const long long MOD = 1e9 + 7;
const long long INF = 1e15;
const int INF_INT = 1e9;


int main(){
    int n,m,x;
    cin >> n >> m >> x;
    int cost[n];
    int score[n][m];
    for(int i = 0; i < n ; i++){
        cin >> cost[i];
        for(int j = 0; j < m; j++){
            cin >> score[i][j];
        }
    }
    int ans = INF_INT;
    for(int bit = 0; bit < (1<<n); bit++){
        int temp = bit;
        int sum[m];
        int tempans = 0;
        memset(sum,0,sizeof sum);
        for(int i = 0; i < n; i++){
            int check = temp & 1;
            if(check){
                tempans += cost[i];
                for(int j = 0; j < m; j++){
                    sum[j] += score[i][j];
                }
            }
            temp >>= 1;
        }
        bool flag = true;
        for(int i = 0; i < m ; i++){
            if(sum[i] < x) flag = false; 
        }
        if(flag) ans = min(ans,tempans);
    }
    if(ans == INF_INT) cout << -1 << endl;
    else cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3632
from collections import Counter,defaultdict,deque
from heapq import heappop,heappush
from bisect import bisect_left,bisect_right 
import sys,math,itertools,fractions,pprint
sys.setrecursionlimit(10**8)
mod = 10**9+7
INF = float('inf')
def inp(): return int(sys.stdin.readline())
def inpl(): return list(map(int, sys.stdin.readline().split()))

n,m = inpl()
a = [False] * (n+1)
cnt = [0] * (n+1)
for _ in range(m):
    x,y = input().split()
    x = int(x)
    if y == 'AC':
        a[x] = True
    else:
        if not a[x]:
            cnt[x] += 1
pena = 0
for i in range(1,n+1):
    if a[i]: pena += cnt[i]
print(sum(a), pena)

Measured memory_bytes: 81464
import math
from operator import mul
from functools import reduce
N = int(input())
ll = []
def cmb(n,r):
    r = min(n-r,r)
    if r == 0: return 1
    over = reduce(mul, range(n, n - r, -1))
    under = reduce(mul, range(1,r + 1))
    return over // under

for i in range(N):
    l = list(input())
    l.sort()
    s = ''.join(l)
    ll.append(s)
ll.sort()
k = 0
ans = 0
for j in range(N-1):
    if ll[j]==ll[j+1]:
        k += 1
    elif k>0:
        ans += cmb(k+1, 2)
        k = 0
if k>0:
    ans += cmb(k+1, 2)
print(int(ans))


Measured memory_bytes: 11256
#!usr/bin/env python3
from collections import defaultdict,deque
from heapq import heappush, heappop
import sys
import math
import bisect
import random
def LI(): return [int(x) for x in sys.stdin.readline().split()]
def I(): return int(sys.stdin.readline())
def LS():return [list(x) for x in sys.stdin.readline().split()]
def S(): return list(sys.stdin.readline())[:-1]
def IR(n):
    return [I() for i in range(n)]
def LIR(n):
    return [LI() for i in range(n)]
def SR(n):
    return [S() for i in range(n)]
def LSR(n):
    return [LS() for i in range(n)]

sys.setrecursionlimit(1000000)
mod = 1000000007


#A
"""
a,b = LS()
if a == b:
    print("H")
else:
    print("D")
"""

#B
"""
w,a,b = LI()
print(max(max(a,b)-min(a,b)-w,0))
"""

#C
"""

x = I()
a = 0
i = 1
while a < x:
    a += i
    i += 1
print(i-1)
"""

#D
n,k = LI()
a = LI()
a.sort()
a = a[:bisect.bisect_left(a,k)]
n = len(a)
a = a[::-1]
l = -1
r = n
while r-l > 1:
    m = (l+r)//2
    k_ = k-a[m]
    dp = [0]*k
    dp[0] = 1
    ma = 0
    for i in range(n):
        if i == m:continue
        ai = a[i]
        for j in range(min(ma+1,k-ai))[::-1]:
            j_ = j+ai
            if dp[j]:
                if k_ <= j_:
                    l = m
                    break
                dp[j_] = 1
                if j_ > ma:
                    ma = j_
        else:
            continue
        break
    else:
        r = m
print(n-r)
#E

#F

#G

#H

#I

#J

#K

#L

#M

#N

#O

#P

#Q

#R

#S

#T


Measured memory_bytes: 43868
#include <bits/stdc++.h>
#define rep(i, n) for(int i=0; i<(n); ++i)
#define rep1(i,n) for(int i=1; i<=(n); ++i)
#define repi(i,a,b) for(int i=a; i<=(b); ++i)
#define rrep(i,n) for(int i=(n-1); i>=0; --i)
#define ALL(obj) (obj).begin(), (obj).end()
#define RALL(obj) (obj).rbegin(), (obj).rend()
#define pb push_back
#define mp make_pair
#define to_s to_string
#define sz(v) (int)v.size()
#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() );
#define pr(x) cout<<(x)<<'\n'
#define debug(x) cout << #x << ": " << (x) << '\n'
#define yes "Yes"
#define no "No"
using ll = long long;
using namespace std;
typedef pair<int,int> P;
struct aaa{aaa(){ cin.tie(0); ios::sync_with_stdio(0); cout<<fixed<<setprecision(20);};}aaaaaaa;
int MOD = 1e9 + 7;
int gcd(int a,int b){return b?gcd(b,a%b):a;}
int lcm(int a,int b){return (a*b)/gcd(a,b);}
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};

ll N,K;
int main(){
    cin >> N >> K;
    vector<ll> V(N);
    rep(i,N) cin >> V[i];
    ll ans = 0;
    rep(A,51) rep(B,51) rep(C,101) if(A + B <= N && A+B+C <= K && A+B >= C){
        vector<ll> item = {};
        rep(i,A) item.pb(V[i]);
        rep(i,B) item.pb(V[sz(V)-1-i]);
        sort(ALL(item));
        rep(i,C) item.erase(item.begin());
        ll sum = 0;
        rep(i,sz(item)) sum += item[i];
        ans = max(ans,sum);
    }
    pr(ans);
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using lint = long;
using ll = long long;
#define rep(i,n) for(lint (i) = 0;(i) < (lint)(n);(i)++)
#define repInRange(i,start,end) for(lint (i) = (start);(i) < (end);++(i))
using lpair = pair<lint,lint>;
using Vecint = vector<lint>;
using Llist = list<lint>;

ll pow(ll k,ll l) {
	ll ret = 1;
	rep(i,l) {
		ret *= k;
	}
	return ret;
}

template <typename T>
T sum(vector<T> vec) {
	ll ret = 0;
	rep(i,vec.size()) {
		ret += vec.at(i);
	}
	return ret;
}

void Main() {
	string s;
	cin >> s;
	if ((s[0] == s[1])&&(s[2] == s[1])&&(s[0] == s[2])) {
		cout << "No" << '\n';
		return;
	}
	cout << "Yes" << '\n';
}

signed main() {
	cin.tie(nullptr);
	ios::sync_with_stdio(false);
	Main();
	return 0;
}

Measured memory_bytes: 384
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
main(){
    int n,q,b,c;
    cin>>n;
    ll sum=0;
    map<int,ll>m;
    int a[n];for(int i=0;i<n;i++)cin>>a[i],sum+=a[i],m[a[i]]++;
    cin>>q;
    while(q--){
        cin>>b>>c;
        sum+=(c-b)*m[b];
        m[c]+=m[b],m[b]=0;
        cout<<sum<<endl;
    }
    //cout<<sum;
}


Measured memory_bytes: 9752
using System;
using System.Collections;
using System.Collections.Generic;
using System.IO;
using System.Linq;

namespace C
{
    public class Program
    {
        static void Main(string[] args)
        {
            var sw = new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false };
            Console.SetOut(sw);
            Solve();
            Console.Out.Flush();
        }

        public static void Solve()
        {
            var ABCDEF = Console.ReadLine().Trim().Split(' ').Select(int.Parse).ToArray();
            var A = ABCDEF[0];
            var B = ABCDEF[1];
            var C = ABCDEF[2];
            var D = ABCDEF[3];
            var E = ABCDEF[4];
            var F = ABCDEF[5];

            var answerVolume = 100 * A;
            var answerSugar = 0;
            double max = 0;

            for (var i = 0; 100 * A * i <= F; i++)
            {
                for (var j = 0; 100 * A * i + 100 * B * j <= F; j++)
                {
                    var water = 100 * (A * i + B * j);
                    for (var k = 0; water + C * k <= F; k++)
                    {
                        for (var l = 0; water + C * k + D * l <= F; l++)
                        {
                            var sugar = C * k + D * l;
                            if (100 * sugar <= E * water)
                            {
                                var tmp = (double)(100 * sugar) / (water + sugar);
                                if (tmp > max)
                                {
                                    max = tmp;
                                    answerVolume = water + sugar;
                                    answerSugar = sugar;
                                }
                            }
                        }
                    }
                }
            }

            Console.WriteLine($"{answerVolume} {answerSugar}");
        }
    }
}


Measured memory_bytes: 28112
#include<iostream>
#include<cmath>

using namespace std;

int countDigits(int n)
{
	int count = 0;
	while(n>0)
	{
		n = n/10;
		count++;
	}

	return max(1, count);
}

int main()
{
	long long int n; cin>>n;
	int limit = (int) sqrt(n);
	int ans = 1;
	for(int i = 1; i<=limit; i++)
	{
		if(n%i == 0)
		{
			ans = i;
		}
	}
	if(ans==1)
		cout<<countDigits(n)<<endl;
	else
		cout<<max(countDigits(n/ans), countDigits(ans))<<endl;
	return 0;
}

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

using namespace std;

long long f(vector<int> &v, long long x) {
    long long sum = 0;
    for (auto e : v) {
        sum += abs(e - x);
    }
    return sum;
}

int main() {
    int n;
    cin >> n;
    vector<int> v(n);
    for (int i = 0; i < n; ++i) cin >> v[i];
    for (int i = 0; i < n; ++i) v[i] -= i + 1;

    sort(v.begin(), v.end());
    cout << f(v, v[n/2]) << endl;

    return 0;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define mk make_pair
#define mod 1000000007
#define ll long long
#define lb lower_bound
#define ub upper_bound
#define endl "\n"
#define ff first
#define ss second
#define prec(y,x) fixed<<setprecision(y)<<x
#define inf 1e18
#define pi 3.1415926535

int main()
{
	ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif

	ll n;
	cin >> n;
	ll ans = 1e13;
	ll q = sqrt(n);
	q += 2;
	for (int i = 1; i <= q; i++)
	{
		if (n % i == 0)
		{
			ll ans1 = i + n / i; ans1--; ans1--;
			ans = min(ans, ans1);
		}
	}
	cout << ans;
	return 0;
}

Measured memory_bytes: 3716
L = int(input())
A = int(input())
B = int(input())
C = int(input())
D = int(input())

day_k = 0
day_s = 0
if A % C == 0:
    day_k = A // C
else:
    day_k = A // C + 1
if B % D == 0:
    day_s = B // D
else:
    day_s = B // D + 1

print(L - max(day_k, day_s))



Measured memory_bytes: 5588
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const double PI = acos(-1);
const ll MOD = 1000000007;
using Graph = vector<vector<int>>;



int main() {
  int N; cin >> N;
  string s;
  if (N == 0 || N == 1) cout << N << endl;
  else {
    while (N != 0 && N != 1) {
      int r;
      if (N >= 0) {
        r = N % 2;
        N = -(N / 2);
      } else {
        r = (-N) % 2;
        N = ((-N)+1) / 2;
      }
      s = char(r + '0') + s;
    }
    if (N == 1) s = '1' + s;
    
    cout << s << endl;
  }
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <iomanip>
#include <stdlib.h>
#include <string.h>
#include <cstring>
#include <cmath>
#include <map>
#include <queue>
#include <deque>
#include <stack>
#include <set>
#include <stdio.h>
#include <tuple>
#include <bitset>
#include <cfloat>
#include <fstream>
#include <limits.h>
#include <list>
#include <math.h>
#include <random>
#include <unordered_map>
#include <unordered_set>
#include <bitset>
#include <numeric>
#include <utility>
#include <sstream>
 
template<class T> inline bool chmin(T& a, T b) {
	if (a > b) {
		a = b;
		return true;
	}
	return false;
}
template<class T> inline bool chmax(T& a, T b) {
	if (a < b) {
		a = b;
		return true;
	}
	return false;
}
 
using namespace std;
#define int long long
#define ll long long
#define rep(i, n) for (ll i = 0; i < (n); i++)
#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 repr(i,n) for(ll i=n;i>=0;i--)
#define P pair<ll, ll>
#define sz(x) (ll)x.size()
#define ALL(x) (x).begin(),(x).end()
#define ALLR(x) (x).rbegin(),(x).rend()
#define VE vector<ll>
#define COUT(x) cout<<(x)<<endl
#define MA map<ll,ll>
#define SE set<ll>
#define PQ priority_queue<ll>
#define PQR priority_queue<ll,VE,greater<ll>>
#define COUT(x) cout<<(x)<<endl
#define YES(n) cout << ((n) ? "YES" : "NO"  ) << endl
#define Yes(n) cout << ((n) ? "Yes" : "No"  ) << endl
#define EPS (1e-10)
 
 
const long long MOD = 1000000007;
//const long long MOD = 998244353;
const long long INF = 1LL << 60;
 
 
long long modinv(long long a, long long m) {
	long long b = m, u = 1, v = 0;
	while (b) {
		long long t = a / b;
		a -= t * b; swap(a, b);
		u -= t * v; swap(u, v);
	}
	u %= m;
	if (u < 0) u += m;
	return u;
}
ll gcd(ll a, ll b) {
	if (a < b)swap(a, b);
	if (b == 0) return a;
	unsigned r;
	while ((r = a % b)) {
		a = b;
		b = r;
	}
	return b;
}
ll lcm(ll a, ll b) {
	ll g = gcd(a, b);
	return a * g / b;
}
bool prime(ll n) {
	for (ll i = 2; i <= sqrt(n); i++) {
		if (n%i == 0)return false;
	}
	return n != 1;
}
 
 
 
 
const long double PI = 3.14159265359;
const int MAX_N = 100010;
int n;
int ans = 0;
 
void dfs(int x, int a, int b, int c) {
	if (x > n)return;
	if (a&&b&&c) {
		ans++;
	}
	dfs(x * 10 + 3, 1, b, c);
	dfs(x * 10 + 5, a, 1, c);
	dfs(x * 10 + 7, a, b, 1);
}
 
signed main() {
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	cin >> n;
	dfs(0, 0, 0, 0);
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
// clang-format off

#include <bits/stdc++.h>

#define int long long

#define main signed main()

// #define main int main()

#define loop(i, a, n) for (int i = (a); i < (n); i++)

#define rep(i, n) loop(i, 0, n)

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

#define rall(v) (v).rbegin(), (v).rend()

#define prec(n) fixed << setprecision(n)

#define stlice(from, to) substr(from, (to) - (from) + 1)

#define pb push_back

#define mp make_pair

#define mt make_tuple

#define fi first

#define se second

using namespace std;

typedef pair<int, int> pii;

typedef vector<int> vi;

typedef vector<double> vd;

typedef vector<char> vc;

typedef vector<bool> vb;

typedef vector<string> vs;

typedef vector<pii> vpii;

typedef vector<vi> vvi;

typedef vector<vb> vvb;

typedef vector<vpii> vvpii;

const int INF = sizeof(int) == sizeof(long long) ? 1000000000000000000LL : 1000000000;

const int MOD = 1000000007;

const double PI = acos(-1);

template<typename A, typename B> bool cmin(A &a, const B &b) { return a > b ? (a = b, true) : false; }

template<typename A, typename B> bool cmax(A &a, const B &b) { return a < b ? (a = b, true) : false; }

bool odd(const int &n) { return n & 1; }

bool even(const int &n) { return !odd(n); }

void solve();

main { solve(); return 0; }

// clang-format on



void solve() {

  int a, b, c, d, p;

  cin >> a >> b >> c >> d >> p;

  cout << min(p * a, b + (p > c) * (p - c) * d) << endl;

}

Measured memory_bytes: 3124
#include <bits/stdc++.h>
#define MAX 100005
#define INF 1e9
using namespace std;

typedef long long ll;
int n, A, B, C, arr[10];

int solve(int pos, int a, int b, int c)
{
    if(pos >= n){
        if(min(a, min(b, c)) > 0)
            return abs(A - a) + abs(B - b) + abs(C - c) - 30;
        else
            return INF;
    }
    int ret = solve(pos + 1, a, b, c);
    ret = min(ret, solve(pos + 1, a + arr[pos], b, c) + 10);
    ret = min(ret, solve(pos + 1, a, b + arr[pos], c) + 10);
    ret = min(ret, solve(pos + 1, a, b, c + arr[pos]) + 10);

    return ret;
}

int main()
{
    ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
    // #ifndef ONLINE_JUDGE
    //     freopen("input.txt", "r", stdin);
    //     freopen("output.txt", "w", stdout);
    // #endif
    cin>>n>>A>>B>>C;
    for(int i =  0; i < n; i++){
        cin>>arr[i];
    }

    int res = solve(0, 0, 0, 0);

    cout<<res<<endl;

    return 0;
}

Measured memory_bytes: 256
#define _GLIBCXX_DEBUG
#define _USE_MATH_DEFINES
#include <iostream>
#include <string>
#include <vector>
#include <stdio.h>
#include <cmath>
#include <algorithm>
#include <math.h> //円周率はM_PI
#include <map>
#include <bitset>
using namespace std;


int main() {
	int64_t x;
	cin >> x;
	int64_t tmp = 0, ans = 0;
	bool flag = true;

	tmp = 100;
	while (flag) {
		if (tmp >= x) {
			flag = false;
		}
		ans++;
		tmp = (int64_t)(tmp * 1.01);
	}
	cout << ans-1 << endl;

	
}

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

namespace ALDS_1_4_B
{
    class Program
    {
        static void Main(string[] args)
        {
            //
            int targetCount = int.Parse(Console.ReadLine());

            //
            int[] targetArray = Console.ReadLine()
                                          .Split(' ')
                                          .Select(s => int.Parse(s))
                                          .ToArray();

            //捨て行
            Console.ReadLine();

            //
            List<int> missingList = Console.ReadLine()
                                           .Split(' ')
                                           .Select(s => int.Parse(s))
                                           .ToList();

            Console.WriteLine(missingList.Count(i => Program.IsBinSearch(targetArray, 0, targetCount - 1, i)));
        }

        private static bool IsBinSearch(int[] targetArray, int leftIndex, int rightIndex, int missing)
        {
            int midIndex = (leftIndex + rightIndex) / 2;

            if (targetArray[midIndex] == missing)
            {
                return true;
            }
            else if (leftIndex > rightIndex)
            {
                return false;
            }
            else if (leftIndex == rightIndex && targetArray[midIndex] != missing)
            {
                return false;
            }
            else if (missing < targetArray[midIndex])
            {
                return Program.IsBinSearch(targetArray, leftIndex, midIndex - 1, missing);
            }
            else
            {
                return Program.IsBinSearch(targetArray, midIndex + 1, rightIndex, missing);
            }
        }
    }
}



Measured memory_bytes: 33196
#include <stdio.h>
#include <math.h>

#define f(x,q) x - (x * x * x - (double)q) / (3.0 * x * x)
 
int main(void){
    int q;
    double x;
    while(1){
        scanf("%d", &q);
        if(q==-1) break;
        
        x=(double)q/2.0;
        while(1){
            if(fabs(x*x*x-(double)q)<0.00001*(double)q) break;
            x = f(x,q);
        }
        printf("%f\n",x);
    }
    return 0;
}


Measured memory_bytes: 1916
#include<bits/stdc++.h>
using namespace std;
bool comp(pair<long long int,long long int>a,pair<long long int,long long int>b)
{
    if(a.first==b.first)
    {
        if(a.second<=b.second)
        return true;
        else
        return false;
    }
    if(a.first>b.first)
    return true;
    else return false;
}
long long int gcd(long long int bdda,long long int chota)
{
    if(chota==0)
        return bdda;
    return gcd(chota,bdda%chota);
}
void solve()
{
    long long int n,k;
    cin>>n>>k;
    long long int x[n];
    for(long long int i=0;i<n;i++)cin>>x[i];
    long long int ans=0;
    for(long long int i=0;i<n;i++)ans+=2*(min(x[i],k-x[i]));
    cout<<ans;
}
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int t;    
    t=1;

    //cin>>t;
    while(t--)
    {
        solve();
    }
}


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

//#define int long long
#define DBG 0
#define dump(o) if(DBG){cerr<<#o<<" "<<o<<endl;}
#define dumpc(o) if(DBG){cerr<<#o; for(auto &e:(o))cerr<<" "<<e;cerr<<endl;}
#define rep(i,a,b) for(int i=(a);i<(b);i++)
#define rrep(i,a,b) for(int i=(b)-1;i>=(a);i--)
#define each(it,c) for(auto it=(c).begin();it!=(c).end();it++)
#define all(c) c.begin(),c.end()
const int INF = sizeof(int) == sizeof(long long) ? 0x3f3f3f3f3f3f3f3fLL : 0x3f3f3f3f;
const int MOD = (int)(1e9 + 7);

string A(string s) {
	reverse(all(s));
	return s;
}

string J(string s) {
	return s[s.size() - 1] + s.substr(0, s.size() - 1);
}

string M(string s) {
	rep(i, 0, s.size()) {
		if (isdigit(s[i])) {
			s[i] = char((s[i] - '0' + 1 + 10) % 10 + '0');
		}
	}
	return s;
}

string P(string s) {
	rep(i, 0, s.size()) {
		if (isdigit(s[i])) {
			s[i] = char((s[i] - '0' - 1 + 10) % 10 + '0');
		}
	}
	return s;
}

string E(string s) {
	int h = s.size() / 2;
	if (s.size() % 2)return s.substr(h + 1) + s[h] + s.substr(0, h);
	return s.substr(h) + s.substr(0, h);
}

string C(string s) {
	return s.substr(1, s.size()) + s[0];
}

signed main() {
	int n; cin >> n;
	rep(h, 0, n) {
		string o; cin >> o;
		string m; cin >> m;
		rrep(i, 0, o.size()) {
			if (o[i] == 'J')m = J(m);
			if (o[i] == 'C')m = C(m);
			if (o[i] == 'E')m = E(m);
			if (o[i] == 'A')m = A(m);
			if (o[i] == 'P')m = P(m);
			if (o[i] == 'M')m = M(m);
			dump(m);
		}
		cout << m << endl;
	}
	return 0;
}

Measured memory_bytes: 2996
#include <iostream>
using namespace std;
int main() {
   int X;
   cin >> X;
   switch (X) {
   case 3:
   case 5:
   case 7:
      cout << "YES";
      break;
   default:
      cout << "NO";
      break;
   }
   cout << endl;
   return 0;
}

Measured memory_bytes: 256
#include<iostream>
using namespace std;
int main()
{
    int n;
    cin >> n;
    int ans = 1;
    for(int i = 0; i < n; i ++)
    {
        int b;
        cin >> b;
        if(b % 2 == 0)  ans *= 2;
    }
    int bla = 1;
    for(int i = 0; i < n; i ++) bla *= 3;
    cout << bla - ans;
}


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

const ll MAX = 1000000;
const ll MOD = 1000000007;

ll fac[MAX];

// テーブルを作る前処理
/*
void COMinit() {
    fac[0] = fac[1] = 1;
    for (int i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % MOD;
    }
}
*/

ll pow_kai(ll a,ll n){//aのn乗を計算します。
  ll x = 1;
  while(n > 0){//全てのbitが捨てられるまで。
    if(n&1){//1番右のbitが1のとき。
      x = x*a%MOD;
    }
    a = a*a%MOD;
    n >>= 1;//bit全体を右に1つシフトして一番右を捨てる。
  }
  return x;
}

// 二項係数計算
ll COM(int n, int k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    ll tmp=1;
    for(ll i=n;i>=n-k+1;i--) tmp = (tmp*i)%MOD;

    return (tmp * pow_kai(fac[k],MOD-2)) % MOD;
}



int main()
{
    ll N,M,X;
    cin >> N >> M >> X;

    ll C[N],A[N][M],n=1,chk,mi=10000000,ans2=-1,charge;

    rep(i,N){
        cin >> C[i];
        rep(j,M){
            cin >> A[i][j];
        }
        n=n*2;
    }

    ll skill[M];

    for (int bit = 0; bit < (1<<N); ++bit)
    {
        chk=1;
        charge=0;
        
        rep(i,M){
            skill[i]=0;
        }
        rep(i,N){
            if (bit & (1<<i)) { // iが入っていたら足す
                rep(j,M){
                    skill[j] += A[i][j];
                }
                charge += C[i];
            }
        }

        rep(i,M){
            if(skill[i]<X){
                chk=-1;
            }
        }
        if(chk!=-1){
            ans2=1;
            if(mi>charge){
                mi=charge;
            }
        }
        
    }

    if(ans2==-1){
        cout << ans2 << endl;
    }else{
        cout << mi << endl;
    }
 
    return 0;

}

Measured memory_bytes: 3612
#include<iostream>
#include<algorithm>
#include<string>
#include<numeric>
#define int long long int
using namespace std;
int i, j, k, a, b, c, d, p[100][100], n, f;
signed main() {
	string s;
	cin >> n>>a>>b>>s;
	for (i = 0; i < s.size(); i++) {
		if (s[i] == 'a'&&c < a + b) {
			cout << "Yes" << endl;
			c++;
		}
		else if (s[i] == 'b'&&c < a + b&&d < b) {
			cout << "Yes" << endl;
			c++;
			d++;
		} else {
			cout << "No" << endl;
		}
	}
}

Measured memory_bytes: 896