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

#define  ll long long int
#define pb push_back
#define f first
#define s second
#define mp make_pair
#define all(a) a.begin(),a.end()
#define si(a) a.size()
#define p pair< ll,ll >
#define v vector< ll >
#define vi vector<p>
#define mem(tabl,i) memset(tabl, i, sizeof(tabl))
#define sp(x,y) fixed<<setprecision(y)<<lf(x)
#define debug(c) cout << #c << " = " << c << endl;
#define  f(i,a,b) for(int i=a;i<b;i++)
#define fe(i,a,b) for(int i=a;i<=b;i++)
#define Mod 1000000007

const int N = 1e5 + 5;
ll an;
ll a[N];
ll dpi[N];
ll dp(ll n)
{
    if(n<=0)
        return 0;
     if(dpi[n]!=-1)
        return dpi[n];
    else if(n==1)
        return abs(a[n]-a[n-1]);
      //  debug(an);
    dpi[n]= min( dp(n-1) + abs(a[n]-a[n-1]) , dp(n-2) + abs(a[n]-a[n-2]));
    return dpi[n];
}

int main()
{
   ios_base::sync_with_stdio(false);
   cin.tie(NULL);

           string s;
           ll n,k,b,c,x,y,z;
           ll counter=0,counter1=0,counter2=0;
           ll sum=0,result=0,ans=0, flag=0;
           cin>>n;
           f(i,0,n)
           cin>>a[i];
           mem(dpi,-1);
           cout<<dp(n-1)<<endl;

}



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

int count(int n, int x){
    int number = 0;
    for(int i = 1; i <= n-2; i++){
        for(int j = i + 1; j <= n-1; j++){
            for(int k = j + 1; k <= n; k++){
                if(i + j + k == x) number++;
            }
        }
    }
    return number;
}

int main(){
    int n, x;
    while(1){
        cin >> n >> x;
        if(n == 0 && x == 0) break;
        cout << count(n, x) << endl;
    }
    return 0;
}


Measured memory_bytes: 3092
#include<iostream>
#include<algorithm>

using namespace std;



int main(){

	string s;
	cin >> s;
	bool isOK = true;
	if(s[0] != 'A')isOK = false;
	int cn = 0;
	for(int i = 2;i < s.length()-1;i++){
		if(s[i] == 'C')cn++;
	}
	if(cn != 1)isOK = false;
	int bn = 0;
	for(int i = 0;i < s.length();i++){
		if('A' <= s[i] && s[i] <= 'Z')bn++;
	}
	if(bn != 2)isOK = false;

	cout << (isOK?"AC":"WA") << endl;

	return 0;
}

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

int main() {
	int a,b;
	string p ("Positive");
	string n ("Negative");
	string z ("Zero");
	
	cin>>a>>b;
	if(a>0)cout<<p;
	else if(a<=0 && b>=0)cout<<z;
	else if(a==0 || b==0)cout<<z;
	else if(b<0){
		if((b-a+1)%2==0)cout<<p;
		else cout<<n;
	}
	return 0;
}

Measured memory_bytes: 256
#include <fcntl.h>
#include <unistd.h>
#include <sys/mman.h>
#include <string.h>
#include <stdio.h>

const char main_[] = {
	0x48, 0x89, 0xf8,
	0x48, 0x21, 0xf0,
	0x48, 0x83, 0xe0, 0x01,
	0xc3
};

int main(void){
	int fd = open("/dev/zero", O_RDONLY);
	int (*solve)(int, int) = mmap(NULL, sizeof main_, PROT_WRITE | PROT_EXEC, MAP_PRIVATE, fd, 0);
	memcpy(solve, main_, sizeof main_);

	int a, b;
	scanf("%d%d", &a, &b);
	puts(solve(a, b) ? "Odd" : "Even");

	close(fd);
	munmap(solve, sizeof main_);
	return 0;
}

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

int main()
{
  long a, b, k;
  cin >> a >> b >> k;
  a -= k;
  if (a < 0)
  {
    b += a;
    a = 0;
  }
  if (b < 0)
    b = 0;
  cout << a << "\t" << b << endl;
}

Measured memory_bytes: 256
def IsPrime(arr):
  arr[0] = 0
  arr[1] = 0
  i = 2
  while i**2 <= len(arr):
    if arr[i]:
      for j in range(i*2,len(arr),i):
        arr[j] = 0
    i += 1
  return arr

num = []
while True:
  try:
    line = int(input())
  except EOFError:
    break
  num.append(line)

n_max = max(num)
prime_array = IsPrime([1 for i in range(n_max+1)])
for i in range(len(num)):
  counter = 0
  for j in range(num[i]+1):
    counter += prime_array[j]
  print(counter)


Measured memory_bytes: 13324
import java.util.*;
import java.io.*;
import static java.util.Arrays.*;
import static java.util.Collections.*;
import static java.lang.Math.*;

public class Main {

	int INF = 1 << 29;
	//long INF = 1L << 62;
	double EPS = 1e-10;

	void run() {
		Scanner sc = new Scanner(System.in);
		for (;;) {
			int n = sc.nextInt(), m = sc.nextInt();
			if ((n|m) == 0) break;
			
			int[] c = new int[m], x = new int[n];
			for (int i=0;i<m;i++) c[i] = sc.nextInt();
			for (int i=0;i<n;i++) x[i] = sc.nextInt();
			
			int[][] dp = new int[n+1][256];
			for (int[] a : dp) fill(a, INF);
			
			dp[0][128] = 0;
			
			for (int i=0;i<n;i++) for (int j=0;j<256;j++) {
				for (int k=0;k<m;k++) {
					int next = j + c[k];
					if (next < 0) next = 0;
					if (next > 255) next = 255;
					dp[i+1][next] = min(dp[i+1][next], dp[i][j] + (next - x[i]) * (next - x[i]));
				}
			}
			
			int min = INF;
			for (int i=0;i<256;i++) min = min(min, dp[n][i]);
			System.out.println(min);
		}

	}

	void debug(Object... os) {
		System.err.println(Arrays.deepToString(os));
	}

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

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

typedef long long ll;

// static const int MAX = 1e6;
// static const int NIL = -1;
// static const ll INF = 1<<21;
// static const ll MOD = 1e9 + 7;

bool compPair(const pair<int, int>& arg1, const pair<int, int>& arg2) {
    return arg1.first > arg2.first;
}

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

    ll l, r;
    for(ll ih=1;ih<=3500;ih++) {
        for(ll in=1;in<=3500;in++) {
            l = n*ih*in;
            r = 4*ih*in-n*(ih+in);
            if(r==0) continue;
            if(l%r==0&&r>0) {
                cout << ih << " " << in << " " << l/r << endl;
                return 0;
            }
        }
    }

    return 0;
}


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

int main(){
int A,B,C,D;
cin >> A >> B >> C >> D;
int L = A + B;
int R = C + D;
if (L > R) {
cout << "Left" << endl;
}
if (L == R) {
cout << "Balanced" << endl;
}
if (L < R) {
cout << "Right" << endl;
}
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <functional>
#include <algorithm>
using namespace std;
using ll = long long;
template<class T> using vec = vector<T>;
template<class T> using vvec = vector<vec<T>>;
constexpr ll inf = 1LL<<60;

template<typename Monoid>
class SegmentTree{
private:
    using F = function<Monoid(Monoid&,Monoid&)>;
    int sz;
    vector<Monoid> seg;
    const F op;//演算
    const Monoid e;//単位元
public:
    SegmentTree(int n,const F op,const Monoid &e):op(op),e(e){
        sz = 1;
        while(sz<n) sz <<= 1;
        seg.assign(2*sz,e);
    }
    //代入
    void set(int k, const Monoid &x){
        seg[k+sz] = x;
    }
    //前計算(?)
    void build(){
        for(int i=sz-1;i>0;i--){
            seg[i] = op(seg[2*i],seg[2*i+1]);
        }
    }
    void update(int k,const Monoid &x){
        k += sz;
        seg[k] = x;
        while(k>>=1){
            seg[k] = op(seg[2*k],seg[2*k+1]);
        }
    }
    Monoid query(int l,int r){
        Monoid L = e,R = e;
        for(l+=sz,r+=sz;l<r;l>>=1,r>>=1){
            if(l&1) L = op(L,seg[l++]);
            if(r&1) R = op(seg[--r],R);
        }
        return op(L,R);
    }
    Monoid operator[](const int &k)const{
        return seg[k+sz];
    }
};

struct state{
    ll sum,lma,rma,ma;
};

state op(state& l,state& r){
    ll sum = 0,ma = -inf,lma = -inf,rma = -inf;
    sum = l.sum+r.sum;
    ma = max({l.ma,r.ma,l.rma+r.lma});
    lma = max(l.lma,l.sum+r.lma);
    rma = max(r.rma,r.sum+l.rma);
    return (state){sum,lma,rma,ma};
}

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N,Q;
    cin >> N >> Q;
    SegmentTree<state> seg(N,op,(state){-inf,-inf,-inf});
    for(int i=0;i<N;i++){
        ll a;
        cin >> a;
        seg.set(i,(state){a,max(a,0LL),max(a,0LL),max(a,0LL)});
    }
    seg.build();
    cout << seg.query(0,N).ma << endl;
    for(int i=0;i<Q;i++){
        ll k,a;
        cin >> k >> a;
        k--;
        seg.update(k,(state){a,max(a,0LL),max(a,0LL),max(a,0LL)});
        cout << seg.query(0,N).ma << endl;
    }
}


Measured memory_bytes: 11032
N,K=map(int,input().split())
A=list(map(int,input().split()))
A.sort()

l=N
for i in range(0,N):
    if A[i]>=K:
        l=i
        break
A=A[:l]
N=l
#A[num]が必要な数か判定
def condition(num):
    if N-1>num:
        test=A[:num]+A[num+1:]
    else:
        test=A[:num]
    if A[num]>=K:
        return True
    else:
        check=0
        for i in range(K-A[num],K):
            check+=pow(2,i)

        for i in range(1,N):
            check=check|(check>>test[i-1])

        return check%2==1
        

#必要な数のうち最小のもの
if N==0:
    print(0)
elif N==1:
    if A[0]>=K:
        print(0)
    else:
        print(1)
else:
    start=0
    end=N-1
    while end-start>1:
        t=(end+start)//2
        if condition(t):
            end=t
        else:
            start=t

    if condition(start):
        print(start)
    elif condition(end):
        print(end)
    else:
        print(N)


Measured memory_bytes: 41452
#include <iostream>
#include <iomanip>

void Output(int arr[], int n) {
	for (int i = 0; i < n - 1; ++i) {
		std::cout << arr[i] << " ";
	}
	std::cout << arr[n - 1] << std::endl;
}

void Insection(int arr[], int n) {
	for (int i = 1; i < n; ++i) {
		int v = arr[i];
		int j = i - 1;
		while (j >= 0 && arr[j] > v) {
			arr[j + 1] = arr[j];
			j--;
		}
		arr[j + 1] = v;
		Output(arr, n);
	}

}

int main()
{
	int arr[100];
	int n;
	std::cin >> n;
	for (int i = 0; i < n; ++i) {
		std::cin >> arr[i];
	}
	Output(arr, n);
	Insection(arr, n);
}



Measured memory_bytes: 3104
#include<cstdio>
#include<cstring>
#include<cmath>
#include<bitset>
#include<iostream>
#include<algorithm>
#include<string>
#include<utility>
#include<tuple>
#include<vector>
#include<list>
#include<map>
#include<set>
#include<queue>
#include<stack>
#include<numeric>
#include<functional>
#include<iomanip>
#include<random>

#define IOS ios::sync_with_stdio(false),cin.tie(0)
#define REP(i,n) for(int i = 0;i < n;i++)
#define FOR(i,a,b) for(int i = a;i < b;i++)
#define MEM(a,b) memset(a,b,sizeof(a))
#define ALL(x) (x).begin(),(x).end()
#define LMAX 9223372036854775807
#define LMIN -9223372036854775808

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> P;
typedef pair<ull, ull> UP;
typedef tuple<int, int, int> T;

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

ll gcd(ll a, ll b) {
	if (a < b)swap(a, b);
	int k = a % b;
	if (k == 1)return 1;
	if (k == 0)return b;
	int ans = gcd(b, k);
	return ans;
}
ll digisum(ll a) {
	int sum = 0;
	while (a) {
		sum += a % 10;
		a /= 10;
	}
	return sum;
}
ll countpow(ll a, ll b) {
	int ans = 0;
	if (b == 0)return -1;
	while (1) {
		if (a % b == 0) {
			a /= b;
			ans++;
		}
		else break;
	}
	return ans;
}


int main() {
	IOS;
	int n ,k,x,y;
	cin >> n >> k >> x >> y;
	if(n <= k)cout << x * n << endl;
	else cout << x * k + (n - k) * y << endl;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for(ll i = 0, i##_len = (n); i < i##_len; i++)
#define reps(i, s, n) for(ll i = (s), i##_len = (n); i < i##_len; i++)
#define rrep(i, n) for(ll i = (n) - 1; i >= 0; i--)
#define rreps(i, e, n) for(ll i = (n) - 1; i >= (e); i--)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define sz(x) ((ll)(x).size())
#define len(x) ((ll)(x).length())
#define endl "\n"

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    // ifstream in("input.txt");
    // cin.rdbuf(in.rdbuf());
    ll a, b, c, x, y;
    cin >> a >> b >> c >> x >> y;
    ll ans = LONG_LONG_MAX;
    rep(i, (x + y) * 2 + 1) {
        ll ac = max(0LL, x - i / 2);
        ll bc = max(0LL, y - i / 2);
        ll tmp = ac * a + bc * b + i * c;
        ans = min(ans, tmp);
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{ long long n,cnt=0;
  long double d,a,b,x,y;
cin>>n>>d;
while(n--)
{

    cin>>a>>b;
    x=a*a+b*b;
    y=sqrt(x);


    if(d>=y)
    {
        cnt++;
    }
}
cout<<cnt<<"\n";


}


Measured memory_bytes: 3676
import math
ab = list(map(int,input().split()))
a = ab[0]
b = ab[1]
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
a_div = make_divisors(a)
b_div = make_divisors(b)

def is_prime(n):
    if n == 1: return True
    for k in range(2, int(math.sqrt(n)) + 1):
        if n % k == 0:
            return False
    return True
def primer(n):
    an = []
    for i in range(0,len(n)):
        if is_prime(n[i]) == True:
            an.append(n[i])
    return an
a_pri = primer(a_div)
b_pri = primer(b_div)
c =[]
for i in range(0,len(a_pri)):
    if b_pri.count(a_pri[i]) > 0:
        c.append(a_pri[i])
print(len(c))


Measured memory_bytes: 3516
#include <iostream>
#include <algorithm>
#include <vector>
#include <functional>
#include <cstring>

int n, k;
std::vector<int> cat[10];

int dp[11][2010];

int main() {
    for(int i = 0; i < 10; ++i) {
        cat[i].push_back(0);
    }
    std::cin >> n >> k;

    for(int i = 0; i < n; ++i) {
        int a, b;
        std::cin >> a >> b;
        --b;
        cat[b].push_back(a);
    }
    for(int i = 0; i < 10; ++i) {
        std::sort(cat[i].begin() + 1, cat[i].end(), std::greater<int>());
    }
    memset(dp, -1, sizeof(dp));
    dp[0][0] = 0;
    for(int i = 0; i < 10; ++i) {
        for(int j = 1; j < cat[i].size(); ++j) {
            cat[i][j] += cat[i][j - 1] + (j - 1) * j - (j - 2) * (j - 1);
        }
        for(int m = 0; m <= k; ++m) {
            if(dp[i][m] != -1) {
                for(int j = 0; j < cat[i].size(); ++j) {
                    dp[i + 1][m + j] = std::max(dp[i + 1][m + j], dp[i][m] + cat[i][j]);
                }
            }
        }
    }

    std::cout << dp[10][k] << std::endl;
}

Measured memory_bytes: 3180
import Control.Monad
import Data.Maybe
import qualified Data.ByteString.Char8 as BS
import Data.List

readInt = fst . fromJust . BS.readInt
readIntList = map readInt . BS.words
getInt = readInt <$> BS.getLine
getIntList = readIntList <$> BS.getLine

main = do
    s <- getLine
    t <- getLine
    let ans = minimum . map (check t) . take (length s - length t + 1) $ tails s
    print ans

check t s = length . filter not $ zipWith (==) t s

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

int main() {
	int a,b;
  int m;
  	cin >> a >> b;
  m= max(a,b);
  for(int i=1;i<m;i++){
    if(abs(a-i)==abs(b-i)){
     cout << i << endl;
      return 0;
    }
  }
  cout << "IMPOSSIBLE" << endl;
  return 0;
}

Measured memory_bytes: 256
import sys
sys.setrecursionlimit(10 ** 9)
# input = sys.stdin.readline    ####
def int1(x): return int(x) - 1
def II(): return int(input())
def MI(): return map(int, input().split())
def MI1(): return map(int1, input().split())
def LI(): return list(map(int, input().split()))
def LI1(): return list(map(int1, input().split()))
def LLI(rows_number): return [LI() for _ in range(rows_number)]
def MS(): return input().split()
def LS(): return list(input())
def LLS(rows_number): return [LS() for _ in range(rows_number)]
def printlist(lst, k=' '): print(k.join(list(map(str, lst))))
INF = float('inf')
# from math import ceil, floor, log2
# from collections import deque, defaultdict
# from itertools import combinations as comb, combinations_with_replacement as comb_w, accumulate, product, permutations
# from heapq import heapify, heappop, heappush
# import numpy as np    # cumsum
# from bisect import bisect_left, bisect_right

def solve():
    N, D = MI()
    ans = 0
    while N > 0:
        N -= 1 + 2 * D
        ans += 1
    print(ans)

if __name__ == '__main__':
    solve()



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

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

    int ans = 0;
    while(*max_element(begin(h), end(h)) != 0) {
        const int l = max_element(begin(h), end(h)) - begin(h);
        int r = l + 1;
        while(r < n && h[r] == h[l]) {
            r++;
        }
        for(int i = l; i < r; ++i) {
            h[i] -= 1;
        }
        ans += 1;
    }

    cout << ans << endl;
}


Measured memory_bytes: 256
<?php
fscanf(STDIN, "%d %d %d", $N, $M, $X);
for ($i = 0; $i < $N; $i++) {
    $CA[$i] = array_map('intval', explode(' ', trim(fgets(STDIN))));
}
$ans = PHP_INT_MAX;
$pat = pow(2, $N);
for ($i = 1; $i < $pat; $i++) {
    $array = str_split(str_pad(base_convert($i, 10, 2), $N, '0', STR_PAD_LEFT));
    //echo implode('', $array) . ' ';
    $tmp = array_pad(array(), $M + 1, 0);
    for ($j = 0; $j < $N; $j++) {
        if ($array[$j] === '1') {
            for ($k = 0; $k < $M + 1; $k++) {
                $tmp[$k] += $CA[$j][$k];
            }
        }
    }
    $ac = 0;
    for ($j = 1; $j <= $M; $j++) {
        if ($tmp[$j] >= $X) $ac++;
    }
    if ($ac >= $M) {
        $ans = min($ans, $tmp[0]);
    }
}
echo $ans === PHP_INT_MAX ? '-1' : $ans;


Measured memory_bytes: 16180
x_plus = 100000000

def h_w_patterns(h, w)
  arr = []
  h1 = h
  while h1 < w
    h1= h1 + 1
    w1 = w
    while h1 < w1
      arr.push [h1, w1]
      w1 = w1 - 1
    end
  end
  arr
end

while line = gets do
  h, w = line.split(" ").map(&:to_i)
  x = h*h + w*w
  break if h == 0 && w == 0

  success = false

  h1 = h + 1
  w1 = w
  xx = 0
  while xx < x_plus do
    x1 = x + xx
    if x1 > x
      h1 = 0
      w1 = Math.sqrt(x1).floor
    end
    h_w_patterns(h1, w1).sort{|a, b| a[0]<=> b[0]}.each do |h2, w2|
      if x1 == h2 * h2 + w2 * w2 && !(h2 == h && w2 == w)
        success = true
        puts "#{h2} #{w2}\n"
        break
      end
    end
    break if success
    xx = xx + 1
  end
end

Measured memory_bytes: 7320
#include <iostream>
#include <cmath>
#include <stdio.h>
#include <algorithm>
#include <string>
#include <vector>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
#include <cstring>

using namespace std;

#define f first
#define s second
#define pb push_back
#define mp make_pair
#define ll long long
#define pii pair < int, int >
#define pll pair < long long, long long>
#define ull unsigned long long
#define vi vector < int >
#define vll vector < long long >
#define sz(a) (int)a.size()
#define forit(it, s) for(__typeof(s.begin()) it = s.begin(); it != s.end(); it++)
#define all(a) a.begin(), a.end()
#define sqr(x) ((x) * (x))
#define fname "searching"

const int inf = (int)1e9;
const ll INF = (ll)1e18;
const double eps = 1e-9;
const double pi = acos(-1.0);
const int mod = (int)1e9 + 7;

int n;
int cnt[100100];
int ans;

int solve(){
    cin >> n;
    for(int i = 0, x; i < n; ++i){
        cin >> x;
        if(x > n) ans++;
        else cnt[x]++;
    }
    for(int i = 0; i <= n; ++i){
        if(cnt[i] < i) ans += cnt[i];
        else if(cnt[i] > i) ans += cnt[i] - i;
    }
    return ans;
}

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

    cout << solve() << "\n";
    
    return 0;
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
int main(){
  string s;
  cin>>s;
  int n = s.size();
  bool ok = true;
  if(n%2!=0)ok=false;
  for(int i = 0; i < n-1; i+=2){
    if(s[i]!='h'||s[i+1]!='i')ok=false;
  }
  if(ok){
    cout<<"Yes"<<endl;
  }
  else{
    cout<<"No"<<endl;
  }

  return 0;
}


Measured memory_bytes: 256
#include <iostream>
using namespace std;
 
int main() {
	int n,rank;
	char mark;
	cin >> n;
	bool cards[4][14];
	//?????????
	for(int s = 0; s <= 4; s++){
		for(int t = 0; t <= 14; t++){
			cards[s][t] = {0};
		}
	}
	//????´???????
	for(int i = 0; i < n ; i++){
		cin >> mark >> rank ;
		if(mark == 'S')cards[0][rank] = 1;
		if(mark == 'H')cards[1][rank] = 1;
		if(mark == 'C')cards[2][rank] = 1;
		if(mark == 'D')cards[3][rank] = 1;
	}
	//????????????
	for(int m = 0; m < 4; m++)
		for(int r = 1; r < 14; r++){
			if(m == 0 && cards[m][r] == 0)cout << "S" << " " << r << endl;
			else if(m == 1 && cards[m][r] == 0)cout << "H" << " " << r << endl;
			else if(m == 2 && cards[m][r] == 0)cout << "C" << " " << r << endl;
			else if(m == 3 && cards[m][r] == 0)cout << "D" << " " << r << endl;
		}
	return 0;
}

Measured memory_bytes: 3064
use std::collections::BinaryHeap;
use text_io::read;

fn main() {
    let n: usize = read!();
    let mut a_vec: Vec<i64> = Vec::new();
    (0..n).for_each(|_| a_vec.push(read!()));
    a_vec.sort();
    let mut heap: BinaryHeap<i64> = BinaryHeap::new();
    let mut ans: i64 = 0;
    for a in a_vec.iter().rev() {
        let temp = heap.pop().unwrap_or(0);
        ans += temp;
        if ans == 0 {
            heap.push(*a);
        } else {
            (0..2).for_each(|_| heap.push(*a));
        }
    }
    println!("{}", ans);
}


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

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define repi(i, s, n) for (int i = (s); i < (int)(n); i++)
#define all(x) (x).begin(), (x).end()

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

const long long INF = 3e18 + 12;
const int inf = 1e9;

int calcNumOfCombination(int n, int r) {
  int num = 1;
  for (int i = 1; i <= r; i++) {
    num = num * (n - i + 1) / i;
  }
  return num;
}
int main() {
  int a, b;
  cin >> a >> b;

  int c = 0;
  if (a >= 2 && b >= 2) {
    c = calcNumOfCombination(a, 2) + calcNumOfCombination(b, 2);
  } else if (a >= 2 && b < 2) {
    c = calcNumOfCombination(a, 2);
  } else if (a < 2 && b >= 2) {
    c = calcNumOfCombination(b, 2);
  }
  cout << c << endl;

  return 0;
}

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

int funcX(int x)
{
 int r = 0; 
 while (x > 1)
 {
    if (x%2==0) {r++;  x/=2; /*cout << "x : "<<x << endl;*/ }
    else break;
 }
  return r;
}

int main() 
{
  int N;
  cin >> N;
  int t; 
  
  for (int i = 1; i <= N; i++) 
  {
    int A;
    cin >> A;
    int s = funcX(A);
    if (i ==1)  t = s;
    else t = min(t,s);
   }
  cout << t << endl;
  return 0;
}


Measured memory_bytes: 256
#include<iostream>
using namespace std;
long long int MOD = 1000000007;
long long modpow(long long a, long long n, long long mod);
long long modinv(long long a, long long mod);
int main() {

	//D
	long long int h, w, a, b;
	cin >> h >> w >> a >> b;
	long long int sum = 1;
	long long int i, j;
	for (i = 1; i <= h - a - 1 + b; i++) {
		sum = (sum * i) % MOD;
	}
	for (i = 1; i <= w - b - 1 + a - 1; i++) {
		sum = (sum * i) % MOD;
	}
	for (i = 1; i <= h - a - 1; i++) {
		sum = (sum * modinv(i, MOD)) % MOD;
	}
	for (i = 1; i <= b; i++) {
		sum = (sum * modinv(i, MOD)) % MOD;
	}
	for (i = 1; i <=w-b-1; i++) {
		sum = (sum * modinv(i, MOD)) % MOD;
	}
	for (i = 1; i <= a - 1; i++) {
		sum = (sum * modinv(i, MOD)) % MOD;
	}
	//cout << sum << endl;
	long long int sumsum = 0;
	for (i = b; i <= w - 1; i++) {
		sumsum = (sum + sumsum) % MOD;
		//cout << "sumsum" << sumsum;
		sum = (sum * (w - i - 1)) % MOD;
		sum = (sum * (h - a - 1 + i + 1)) % MOD;
		sum = (sum * modinv(w - i - 1 + a - 1, MOD)) % MOD;
		sum = (sum * modinv(i + 1, MOD)) % MOD;
		//cout << sum << endl;
	}
	cout << sumsum << endl;
	return 0;
	//C
	/*int n,k;
	int d[10];
	cin >> n >> k;
	int i;
	for (i = 0; i < k; i++) {
		cin >> d[i];
	}
	int x,j;
	int flag;
	for (i = n; i < 99999; i++) {
		x = i;
		flag = 0;
		while (x > 0) {
			for (j = 0; j < k; j++) {
				if ((x % 10) == d[j]) {
					flag = 1;
					break;
				}
			}
			if (flag == 1)break;
			x = (x - (x % 10)) / 10;
		}
		if (flag == 0) {
			cout << i << endl;
			return 0;
		}
	}*/



}
// a^n mod を計算する
long long modpow(long long a, long long n, long long mod) {
	long long res = 1;
	while (n > 0) {
		if (n & 1) res = res * a % mod;
		a = a * a % mod;
		n >>= 1;
	}
	return res;
}

// a^{-1} mod を計算する
long long modinv(long long a, long long mod) {
	return modpow(a, mod - 2, mod);
}

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

int main()
{
  string s;
  cin>>s;
  int n=s.length(),i;
  for(i=0;i<n;i++)
    if(s[i]=='?')
      s[i]='D';
  cout<<s;
  return 0;
}

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

#define ll long long
#define ld long double
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define lb lower_bound
#define ub upper_bound
#define loop(i,a,b) for(ll i=a;i<b;i++)
#define inf (long long int) 1e18
#define vl vector<ll> 
#define pll pair<ll, ll>
#define mll map<ll, ll> 
#define mod 1000000007
ll gcd(ll a,ll b);
ll palindrome(string s);
ll modexp(ll a,ll b,ll m);

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

    ll n,k;
    cin>>n>>k;
    if(k%2==1){
        ll x=0;
        loop(i,0,n){
            if((i+1)%k==0){
                x++;
            }
        }
        cout<<x*x*x<<endl;
    } else {
        ll a=0,b=0;
        loop(i,0,n){
            if((i+1)%k==0){
                a++;
            }
            else if((i+1)%k==k/2){
                b++;
            }
        }
        cout<<a*a*a+b*b*b<<endl;
    }
}


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

ll palindrome(string s){
    ll l = 0;
    ll h = s.length() - 1;
    while (h > l){
        if (s[l++] != s[h--]){
            return 0;
        }
    }
    return 1;
}

ll modexp(ll a, ll b, ll m){
    if (b==0)
        return 1;
    ll temp = modexp(a,b/2,m);
    temp = (temp*temp)%m;
    if (b&1)
        return (temp*(a%m))%m; // if b is odd a^b = a^(b/2)*a^(b/2)*a
    return temp;
}

Measured memory_bytes: 256
import java.util.ArrayList;
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
    	
		Scanner sc = new Scanner(System.in);
		// 整数の入力
		int N = sc.nextInt();
		
		ArrayList<Integer> list_m = new ArrayList<Integer>();//モンスター
		ArrayList<Integer> list_y = new ArrayList<Integer>();//討伐数


		for(int i = 0 ;i < N+1;i++){
			list_m.add(sc.nextInt());
			
		}
		for(int i = 0 ;i < N;i++){
			list_y.add(sc.nextInt());
			
		}

		long cnt = 0;
		for(int i = 0 ;i < N;i++){
			if(list_m.get(i) > list_y.get(i)) {
				cnt = cnt + list_y.get(i);
				list_m.set(i, list_m.get(i)-list_y.get(i));
				list_y.set(i, 0);
			}else {
				cnt = cnt + list_m.get(i);
				list_y.set(i, list_y.get(i)-list_m.get(i));
				list_m.set(i, 0);
			}

			if(list_m.get(i+1) > list_y.get(i)) {
				cnt = cnt + list_y.get(i);
				list_m.set(i+1, list_m.get(i+1)-list_y.get(i));
				list_y.set(i, 0);
			}else {
				cnt = cnt + list_m.get(i+1);
				list_y.set(i, list_y.get(i)-list_m.get(i+1));
				list_m.set(i+1, 0);
			}

		}

		
		
		
		
		
		
		
		
		
		
		
		
		
		System.out.println(cnt);

   		sc.close();
        return ;

    }
    
}



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

int x[200000];
int need(int n){
	return n*2-1;
}
int main(){
	int n;scanf("%d",&n);
	rep(i,n)scanf("%d",&x[i]);
	ll ans=1;
	int s=-1;
	rep(i,n){
		while(need(s+2-i)<=x[s+1])s++;
		if(s<n-1)s++;
		(ans*=(s+1-i))%=MOD;
	}
	cout<<ans<<endl;
}


Measured memory_bytes: 640
#include <iostream>

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

    if(n >= 10) {
        printf("%d\n", r);
        return 0;
    }else {
        printf("%d\n", r + 100 * (10-n));
        return 0;
    }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define fore(i,a,b) for(int i=int(a); i < int(b); i++)
#define foro(i,a,b) for(int i=int(a); i >= int(b); i--)
#define prnt(a) cout << a << endl

using namespace std;

int main() {
	int a, b; cin >> a >> b;
	prnt(6-a-b);
	
	return 0;
}


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

int main() {
	string s, t;
	cin >> s >> t;
	vector<string> st;
	int ns = s.size();
	int nt = t.size();
	rep(i, ns - nt + 1) {
		bool ok = true;
		rep(j, nt) {
			if (s[i+j] == '?') continue;
			if (s[i+j] != t[j]) {
				ok = false;
				break;
			}
		}
		if (ok) {
			string now = s;
			rep(k, nt) {
				now[k+i] = t[k];
			}
			rep(k, ns) if (now[k] == '?') now[k] = 'a';
			st.push_back(now);
		}
	}
	if (st.size() > 0) {
		sort(all(st));
		cout << st[0] << endl;
	} else {
		cout << "UNRESTORABLE" << endl;
	}
	return 0;
}

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

int main(){
	int n, k, ans = 1001001001;
	cin >> n >> k;
	vector<int> h(n);
	rep(i, n){
		cin >> h.at(i);
	}
	sort(h.begin(), h.end());
	
	rep(i, n-k+1){
		ans = min(ans, h.at(i+k-1)-h.at(i));
	}
	
	cout << ans << endl;
	
	return 0;
}

Measured memory_bytes: 640
#include <iostream>
#include <string>
#include <algorithm>
#include <cmath>
#include <functional>
#include <vector>
#include <queue>
#include <deque>
#include <map>
#include <set>
#define nmax_def 1100
#define Cmax_def 2200
#define mod 1000000007
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
typedef vector<ll> vl;

int main() {
	int H, W;
	int ans = -1;
	cin >> H >> W;
	bool A[nmax_def][nmax_def];
	vector<pii> BFS_que;
	rep(i, H) {
		string S;
		cin >> S;
		rep(j, W) {
			if (S[j] == '#') {
				BFS_que.push_back(pii(i, j));
				A[i][j] = 1;
			}
			else
				A[i][j] = 0;
		}
	}
	while (BFS_que.size() != 0) {
		vector<pii> BFS_que_nxt;
		int N = BFS_que.size();
		rep(i, N) {
			vector<pii> Pnei;
			pii P = BFS_que[i];
			int X = P.first;
			int Y = P.second;
			if (X != 0) {
				Pnei.push_back(pii(X - 1, Y));
			}
			if (X != H - 1) {
				Pnei.push_back(pii(X + 1, Y));
			}
			if (Y != 0) {
				Pnei.push_back(pii(X, Y - 1));
			}
			if (Y != W - 1) {
				Pnei.push_back(pii(X, Y + 1));
			}
			rep(j, Pnei.size()) {
				int x = Pnei[j].first;
				int y = Pnei[j].second;
				if (!A[x][y]) {
					A[x][y] = 1;
					BFS_que_nxt.push_back(pii(x, y));
				}
			}
		}
		BFS_que = BFS_que_nxt;
		ans++;
	}
	cout << ans << endl;

	return 0;
}

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

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

long long MOD = 10000000000 + 7;

int main(){
  cout << setprecision(10);
  int N; cin >> N;

  ll num = 0;
  ll now_max = 0;
  for(int i = 0; i < N; i++){
    ll tmp; cin >> tmp;
    if(i == 0){
      now_max = tmp;
    } else {
      if(now_max > tmp){
        num += now_max - tmp;
      } else {
        now_max = tmp;
      }
    }
  }
  cout << num << endl;
}


Measured memory_bytes: 3600
n, q = gets.split.map(&:to_i)
s = gets.chomp

conv = Array.new(n + 2, 0)

(n-1).times do |i|
  if s[i..i+1] == 'AC'
    conv[i+1] = conv[i] + 1
  else
    conv[i+1] = conv[i]
  end
end

q.times do
  l, r = gets.split.map(&:to_i)
  p conv[r-1] - conv[l-1]
end

Measured memory_bytes: 3452
#include <bits/stdc++.h>
using namespace std;
#define _GLIBCXX_DEBUG
#define rep2(i, m, n) for(int i=int(m); i<int(n); ++i)
#define drep2(i, m, n) for(int i=int(m-1); i>=int(n); --i)
#define rep(i, n) rep2(i, 0, n)
#define drep(i, n) drep2(i, n, 0)
#define all(a) a.begin(), a.end()
#define fst first
#define snd second
using ll = long long;
using ld = long double;
using V = vector<int>;
using Vll = vector<ll>;
using Vld = vector<ld>;
using VV = vector<V>;
using VVll = vector<Vll>;
using VVld = vector<Vld>;
using P = pair<int, int>;
using Pll = pair<ll, ll>;
using Pld = pair<ld, ld>;
const int INF = 1<<30;
const ll INFll = 1ll<<62;
const ld EPS = 1e-10;
const int MOD = int(1e9)+7;
template<typename T> inline bool chmin(T& a, T b) {if(a>b) {a=b; return true;} return false;}
template<typename T> inline bool chmax(T& a, T b) {if(a<b) {a=b; return true;} return false;}
template<typename T> inline int Log2(T& x) {int k; for(k=0; (T(1)<<k)<=x; ++k); return k;} // number of binary digits


// initialization
const int F_MAX = int(1e6)+10;
ll fac[F_MAX], finv[F_MAX], inv[F_MAX];
void binom_init() {
  fac[0] = fac[1] = 1;
  finv[0] = finv[1] = 1;
  inv[1] = 1;
  for (int i = 2; i < F_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;
  }
}

// binom mod MOD
ll binom(int n, int k) {
  if (k < 0 || n < k) return 0;
  return fac[n] * (finv[k] * finv[n-k] % MOD) % MOD;
}



VV G;


// DP
struct ReRooting {
  struct DP {
    ll dp;
    int size;
    DP(ll dp=1, int size=0) : dp(dp), size(size) {}
  };
  DP f_merge(DP a, DP b) {
    return DP((a.dp * b.dp) % MOD * binom(a.size + b.size, a.size) % MOD, a.size + b.size);
  }
  DP f_trans(DP a) {
    return DP(a.dp, a.size+1);
  }

  vector<vector<DP>> dp;
  vector<DP> ans;

  ReRooting(int N) : dp(N), ans(N) {}

  DP dfs(int u, int p=-1) {
    int d = G[u].size();
    dp[u] = vector<DP>(d);
    DP res;
    rep(i, d) {
      int v = G[u][i];
      if (v == p) continue;
      dp[u][i] = dfs(v, u);
      res = f_merge(res, dp[u][i]);
    }
    return f_trans(res);
  }

  void dfs2(int u, DP pval=DP(), int p=-1) {
    int d = G[u].size();
    rep(i, d) if (G[u][i] == p) dp[u][i] = pval;

    vector<DP> res_l(d+1), res_r(d+1);
    rep(i, d)  res_l[i+1] = f_merge(res_l[i], dp[u][i]);
    drep(i, d) res_r[i] = f_merge(res_r[i+1], dp[u][i]);

    ans[u] = res_l[d];

    rep(i, d) {
      if (G[u][i] == p) continue;
      dfs2(G[u][i], f_trans(f_merge(res_l[i], res_r[i+1])), u);
    }
  }

  void build() {
    dfs(0);
    dfs2(0);
  }
};


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

  G = VV(N);
  for (int i = 0; i < N-1; ++i) {
    int u, v; cin >> u >> v;
    u--; v--;
    G[u].push_back(v);
    G[v].push_back(u);
  }

  ReRooting reroot(N);
  reroot.build();

  rep(i, N) cout << reroot.ans[i].dp << endl;
  return 0;
}


Measured memory_bytes: 58868
#include <bits/stdc++.h>
using namespace std;
#define MOD 1000000007
//#define MOD 998244353
#define INF 100000000000000009
typedef long long ll;
#define REP(i,n) for(int i=0;i<(n);++i)
#define OREP(i,n) for(int i=1;i<=(n);++i)
#define ZREP(i,n) for(int i=1;i<(n);++i)
#define YES(s) s?cout << "YES" << endl:cout << "NO" << endl
#define Yes(s) s?cout << "Yes" << endl:cout << "No" << endl
#define out(s,t,u) s?cout << t << endl:cout << u << endl
#define int ll
#define Endl endl

int f(int b,int n){
    int r=0;
    while(n>0){
        r+=n%b;
        n/=b;
    }
    return r;
}

signed main(){
    int n,s;
    cin >> n >> s;
    if(n==s){
        cout << n+1 << endl;
        return 0;
    }
    for(int i=2;i*i<=n;i++){
        int r=f(i,n);
        if(r==s){
            cout << i << endl;
            return 0;
        }
    }
    int b;
    int bmin =INF;
    for(int p=1;p*p<=n;p++){
        b=1+(n-s)/p;
        if(p*(b-1)==n-s && b>=2){
            int r=f(b,n);
            if(r==s){
                bmin=min(bmin,b);
            }
        }
    }
    if(bmin!=INF){
        cout << bmin << endl;
    }else{
        cout << -1 << endl;
    }
    return 0;
}


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

using namespace std;

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

        if (n == 0) {
            return 0;
        }
        vector<int> v;
        for (int i = 0; i < n; ++i) {
            int w;
            cin >> w;
            v.push_back(w);
        }

        vector<vector<int>> dp(n, vector<int>(n, 0));
        for (int l = 2; l <= n; ++l) {
            for (int i = 0; i < n - l + 1; ++i) {
                int j = i + l - 1;
                if (dp[i + 1][j - 1] == j - i - 1 && abs(v[i] - v[j]) <= 1) {
                    dp[i][j] = j - i + 1;
                }
                else {
                    for (int k = i; k < j; ++k) {
                        dp[i][j] = max(dp[i][j], dp[i][k] + dp[k + 1][j]);
                    }
                }
            }
        }
        cout << dp[0][n - 1] << endl;
    }
}

Measured memory_bytes: 3256
def main(a,b,k):
    takahasi = a
    total = a+b
    if 0 <= k <= a:
        return [a-k,b]
    elif a < k <= total:
        return [0, a+b-k]
    else:
        return [0,0]

a,b,k = map(int,input().split())
print(*main(a,b,k))

Measured memory_bytes: 3060
{-# LANGUAGE FlexibleInstances    #-}
{-# LANGUAGE TypeSynonymInstances #-}

import           Control.Applicative
import           Control.DeepSeq
import           Control.Monad
import           Control.Monad.ST
import qualified Data.Array                    as A
import qualified Data.Array.IArray             as IA
import qualified Data.Array.IO                 as AI
import qualified Data.Array.MArray             as MA
import qualified Data.Array.ST                 as STA
import qualified Data.Array.Unboxed            as AU
import           Data.Bits
import qualified Data.ByteString.Char8         as BS
import           Data.Char
import qualified Data.Graph                    as G
import           Data.Int
import qualified Data.IntMap                   as IM
import qualified Data.IntSet                   as IS
import           Data.List
import qualified Data.Map.Strict               as M
import           Data.Maybe
import           Data.Ord
import qualified Data.Sequence                 as SQ
import qualified Data.Set                      as S
import           Data.Time
import qualified Data.Tree                     as T
import qualified Data.Vector                   as V
import qualified Data.Vector.Mutable           as VM
import qualified Data.Vector.Unboxed           as VU
import qualified Data.Vector.Unboxed.Mutable   as VUM

readInt :: IO [Int]
readInt = map (fst . fromJust . BS.readInt) . BS.words <$> BS.getLine

readInts :: Int -> IO [[Int]]
readInts n = replicateM n readInt

readInteger :: IO [Integer]
readInteger = map (fst . fromJust . BS.readInteger) . BS.words <$> BS.getLine

readIntegers :: Int -> IO [[Integer]]
readIntegers n = replicateM n readInteger

readString :: IO [String]
readString = map BS.unpack . BS.words <$> BS.getLine

readStrings :: Int -> IO [[String]]
readStrings n = replicateM n <$> readString

toPair :: [a] -> (a, a)
toPair [x, y] = (x, y)

count :: Eq a => a -> [a] -> Int
count a as = length $ filter (== a) as

put :: Show a => a -> IO ()
put = putStr . show

putList :: Show a => [a] -> IO ()
putList [n     ] = put n
putList (n : ns) = do
  put n
  putStr " "
  putList ns

putStrList :: [String] -> IO ()
putStrList [n     ] = putStr n
putStrList (n : ns) = do
  putStr n
  putStr " "
  putStrList ns

yesNoUpper b | b         = putStrLn "YES"
             | otherwise = putStrLn "NO"

yesNo b | b         = putStrLn "Yes"
        | otherwise = putStrLn "No"

main = do
  c <- getLine
  let b =not (any ((\x->x/='a'&&x/='i'&&x/='u'&&x/='e'&&x/='o') . head) (group $ sort c)) in if b then putStrLn  "vowel" else putStrLn "consonant"


Measured memory_bytes: 380
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using vll = vector<ll> ;
using vs = vector<string> ;
#define all(v) v.begin(),v.end()

int main(){
  ll N;cin>>N;
  ll tmp_t,tmp_a;cin>>tmp_t>>tmp_a;
  ll ans=0;
  rep(i,N-1){
    ll t,a;cin>>t>>a;
    if(tmp_t*a==tmp_a*t) continue;
    else {
      ll prod = max((tmp_t+t-1)/t,(tmp_a+a-1)/a);
      tmp_t = t*prod;
      tmp_a = a*prod;
    }
  }
  cout << tmp_t + tmp_a << endl;
}

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

using namespace std;

int main(){
    int n, k;
    cin >> n >> k;
    vector<int> v(n);
    for (int i = 0; i < n; i++)
    {
        cin >> v[i];
    }
    priority_queue<int, vector<int>, greater<int>> pq;
    int lim = min(n, k);
    int maxv = 0;
    for (int i = 0; i <= lim; i++)
    {
        for (int j = 0; j+i <= lim; j++)
        {
            for (int a = 0; a < i; a++)
            {
                pq.push(v[a]);
            }
            for (int b = 0; b < j; b++)
            {
                pq.push(v[n - 1 - b]);
            }
            for (int c = 0; c < k-i-j; c++)
            {
                if(!pq.empty() && (pq.top()<0))
                {
                    pq.pop();
                }
                else
                {
                    break;
                }
            }
            int cnt = 0;
            while (!pq.empty())
            {
                cnt += pq.top();
                pq.pop();
            }
            maxv = max(maxv, cnt);
        }
    }
    cout << maxv << endl;

    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <math.h>
#include <string.h>

typedef long long ll;
using namespace std;

int main()
{
    int n;
    string s;

    cin >> n;
    if (n == 0) {
        cout << 0 << endl;
        return 0;
    }

    while (n) {
        if (n % 2) {
            s += '1';
            n -= 1;
        } else {
            s += '0';
        }
        n /= -2;
    }
    reverse(s.begin(), s.end());
    cout << s << endl;
    return 0;
}

Measured memory_bytes: 768
import java.util.*

fun main(args: Array<String>) {
    val sc = Scanner(System.`in`)
    var s = sc.next()
    val a_regex = Regex("A")
    val b_regex = Regex("B")
    val result1 = a_regex.containsMatchIn(s)
    val result2 = b_regex.containsMatchIn(s)

    if (result1 && result2) {
        println("Yes")
    } else {
        println("No")
    }
}

Measured memory_bytes: 31900
#include <iostream>
#include <string>
#include <math.h>
using namespace std;

int main() {
	int n;
	cin >> n;
	int a[100], b[100], c[100];
	
	int ans = 0;
	for (int i = 0; i< n; i++) {
		cin >> a[i];
	}
	for (int i = 0; i < n; i++) {
		cin >> b[i];
		ans += b[i];
	}
	for (int i = 0; i < n-1; i++) {
		cin >> c[i];
	}
	for (int i = 1; i < n; i++) {
		if (a[i] - a[i - 1] == 1) {
			ans += c[a[i] - 2];
		}
	}
	/*
	for (int i = 0; i < n; i++) {
		ans += b[a[i] - 1];
		cout << ans << endl;//
		if (i >= 1) {
			if (a[i]-a[i-1]==1) {
				ans += c[a[i]-1];
			}
		}
	}
	*/
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(k,i,n) for(ll i=k;i<n;++i)
int main(void){
    ll s,w;
    cin>>s>>w;
    if(s>w){
        cout<<"safe";
    }else{
        cout<<"unsafe";
    }
}


Measured memory_bytes: 3636
#include<cstdio>
#include<math.h>
#include<algorithm>
#include<vector>

using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
#define INF 1001001001;
#define LLINF 1001001001001001001001;


int main(){
    int N;int A[100002];
    scanf("%d",&N);
    rep(i,N){
        scanf("%d",&A[i]);
    }
    sort(A,A+N);
    int ai=0,aj=0;
        int _C=A[N-1];ai=_C;
        int C_big=min(_C, int(lower_bound(A,A+N,(_C+1)/2) -A) );
        int C_small=max(C_big-1,0);
       // printf("%d %d %d\n",_C,A[C_big],A[C_small]);
       if(A[C_big]==_C){
           aj=A[C_small];
       }else{
           if(_C%2==0){
            if(abs(A[C_big] - _C/2)>abs(_C/2 - A[C_small] )){
                aj=A[C_small];
            }else{
                aj=A[C_big];
            }
        }else{
            if(abs(A[C_big] - (_C/2+1) )>abs( (_C/2) - A[C_small])){
                aj=A[C_small];
            }else{
                aj=A[C_big];
            }
            
        }
       }
        
    printf("%d %d\n",ai,aj);
}

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

int main(){
    int n, a[105], max = INT_MIN, min = INT_MAX;
    cin >> n;
    for(int i = 0; i < n; ++i){
        cin >> a[i];
        if(a[i] > max){
            max = a[i];
        }
        if(a[i] < min){
            min = a[i];
        }
    }
    cout << max - min << endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <string>
#include <stack>
#include <vector>
#include <math.h>
#include <stdio.h>
#include <algorithm>
#include <utility>
#include <functional>
#include <iterator>
#include <map>
#include <set>
#include <queue>
#include <list>
#include <regex>
#include <time.h>
#include <complex>
using namespace std;
using pii  = pair<int,int>;
using ll=long long;
using ld=long double;
#define pb push_back
#define mp make_pair
#define sc second
#define fr first
#define stpr setprecision
#define cYES cout<<"YES"<<endl
#define cNO cout<<"NO"<<endl
#define cYes cout<<"Yes"<<endl
#define cNo cout<<"No"<<endl
#define rep(i,n) for(ll i=0;i<(n);++i)
#define Rep(i,a,b) for(ll i=(a);i<(b);++i)
#define rrep(i,n) for(int i=n-1;i>=0;i--)
#define rRep(i,a,b) for(int i=a;i>=b;i--)
#define crep(i) for(char i='a';i<='z';++i)
#define psortsecond(A,N) sort(A,A+N,[](const pii &a, const pii &b){return a.second<b.second;});
#define ALL(x) (x).begin(),(x).end()
#define debug(v) cout<<#v<<":";for(auto x:v){cout<<x<<' ';}cout<<endl;
#define endl '\n'
int ctoi(const char c){
  if('0' <= c && c <= '9') return (c-'0');
  return -1;
}
ll gcd(ll a,ll b){return (b == 0 ? a : gcd(b, a%b));}
ll lcm(ll a,ll b){return a*b/gcd(a,b);}
constexpr ll MOD=1000000007;
constexpr ll INF=1000000011;
constexpr ll MOD2=998244353;
constexpr ll LINF = 1001002003004005006ll;
constexpr ld EPS=10e-8;
template <class T, class U> inline bool chmax(T& lhs, const U& rhs) { if (lhs < rhs) { lhs = rhs; return 1; } return 0; }
template <class T, class U> inline bool chmin(T& lhs, const U& rhs) { if (lhs > rhs) { lhs = rhs; return 1; } return 0; }
template<typename T> istream& operator>>(istream& is,vector<T>& v){for(auto&& x:v)is >> x;return is;}
template<typename T,typename U> istream& operator>>(istream& is, pair<T,U>& p){ is >> p.first; is >> p.second; return is;}
template<typename T,typename U> ostream& operator>>(ostream& os, const pair<T,U>& p){ os << p.first << ' ' << p.second; return os;}
template<class T> ostream& operator<<(ostream& os, vector<T>& v){
  for(auto i=begin(v); i != end(v); ++i){
    if(i !=begin(v)) os << ' ';
    os << *i;
  }
  return os;
}

ll A[10007],B[10007],C,D,E,F,K,G,H,L,M,N,P,Q,R,W,X,Y,Z;
string S,T;
ll dp[1007][10007];

int main(){
  cin >> S;
  S[0]++;
  cout  << S[0] << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll long long int
#define ull unsigned long long int
#define ld long double
#define mod 1000000007
#define FT() int t; scanf("%d",&t); while(t--)
#define pb push_back
#define nl printf("\n")
#define fi(i,start,end) for(int i=start; i < (int)end ; ++i)
#define ip(n)   scanf("%d",&n)
#define mz(a)   memset(a,0,sizeof(a))
#define inpArr(A,n) fi(i,0,n)   ip(A[i]);
#define print(a)  for(auto i : a)   cout<<i<<" "; nl;
#define Fastio ios_base::sync_with_stdio(false); cin.tie(NULL);
using namespace std;
ll max(ll a,ll b) { return a>b?a:b;}
ll min(ll a,ll b) { return a<b?a:b;}
void solve()
{   int x,n,e;
    cin>>x>>n;
    unordered_map<int,int> m;
    fi(i,0,n)
    {
        cin>>e;
        m[e]=1;
    }
    int dist = 0;
    do
    {
        int ele = x-dist;
        if(!m.count(ele))
        {
            cout<<ele;
            return;
        }
        
        ele = x+dist;
        if(!m.count(ele))
        {
            cout<<ele;
            return;
        }
        
        dist++;
    }while(1);
}
int main() {
    #ifndef ONLINE_JUDGE
    freopen("input.txt","r",stdin);
    //freopen("output.txt","w",stdout);
    #endif
    
    
        solve();

    #ifndef ONLINE_JUDGE
    cout<<"\nTime Elapsed : " << 1.0*clock() / CLOCKS_PER_SEC << " s";
    #endif
    return 0;
}


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

using namespace std;

int main(void)
{
    int N, i, j, judge, ans=1;
    string W[101];

    cin >> N;

    for(i=1; i<=N; i++){
        judge = 1;

        cin >> W[i];

        if(i>=2){
            for(j=1; j<i; j++){
                if(W[i]==W[j]){
                    judge = 0;
                }
            }

            if(W[i-1][W[i-1].size()-1] != W[i][0]){
                judge = 0;
            }
        }

        if(judge == 0){
            ans = 0;
            break;
        }
    }

    if(ans == 1){
        cout << "Yes" << endl;
    }

    else{
        cout << "No" << endl;
    }

    return 0;
}

Measured memory_bytes: 256