akhauriyash/Code-Regression huggingface dataset:
import java.util.Scanner;

class Main {
	public static void main(String[] args) {

		Scanner sc = new Scanner(System.in);

		int n = sc.nextInt();
		int y = sc.nextInt();

		int yukichi;
		int ichiyo;
		int hideyo;

		int result;

		String ans = "";

		for (yukichi = 0; yukichi <= n; yukichi++) {
			for (ichiyo = 0; ichiyo <= n - yukichi; ichiyo++) {

				hideyo = n - yukichi - ichiyo;
				result = 10000 * yukichi + 5000 * ichiyo + 1000 * hideyo;

				if (yukichi + ichiyo + hideyo == n && result == y) {

					ans = yukichi + " " + ichiyo + " " + hideyo;
				}
			}
		}

		if (ans.equals("")) {
			System.out.println("-1 -1 -1");
		} else {
			System.out.println(ans);
		}

		sc.close();

	}
}

Measured memory_bytes: 23252
#include <bits/stdc++.h>
using namespace std;
int main(){
  int x,y,a=0;
  int A[7]={1,3,5,7,8,10,12};
  int B[4]={4,6,9,11};
  cin>>x>>y;
  for(int i=0;i<7;i++){
    if(x==A[i]){
      for(int j=0;j<7;j++) if(y==A[j]) a++;
    }
  }
  for(int i=0;i<7;i++){
    if(x==B[i]){
      for(int j=0;j<4;j++) if(y==B[j]) a++;
    }
  }
  cout<<((a==1)?"Yes":"No")<<endl;
  return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <cmath>
using namespace std;
int main(){
  int n;
  cin >> n;
  vector<int> x;
  int p,min=101,max=0;
  for(int i=0;i<n;i++){
    cin >> p;
    x.push_back(p);
    if(min>p){
      min = p;
    }
    if(max<p){
      max = p;
    }
  }
  int sum,sum_min=pow(100,2)*100;
  for(int i=min;i<=max;i++){
    sum = 0;
    for(int j=0;j<x.size();j++){
      sum += pow(x[j] - i,2);
    }
    if(sum_min>sum){
      sum_min = sum;
    }
  }
  cout << sum_min << endl;
  return 0;
}

Measured memory_bytes: 256
import java.util.*;

public class Main {

    public static void main(String[] args) {

        // write your code here
        Scanner sc = new Scanner(System.in);

        long x = sc.nextLong();
        long sum = 0;
        long i = 1;

        for (; sum < x ; i++) {
            sum += i;
        }

        System.out.println(i - 1);
    }
}

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

#define M 1000000007
#define FOR(i, s, n) for (ll i = (s); i < (n); ++i)
#define FORALL(i, n) for (ll i = 0; i < (n); ++i)
#define MOD 998244353
#define ff first
#define ss second
#define pll pair<long long, long long>
#define fast ios_base::sync_with_stdio(false)
#define countbits(x) __builtin_popcount(x)
#define pb(x) push_back((x))
#define vll vector<ll>
#define all(x) x.begin(),x.end()
#define print(x) cout << x << endl
#define debug print("reaching\n")
#define mll map<ll,ll>
#define lsb(i) i&(-i)
#define printv(x)            \
    FORALL(i, x.size())      \
    {                        \
        cout << x[i] << ' '; \
    }                        \
    cout << endl            \
;
#define input(v,x)  \
    FORALL(i,n)     \
    {               \
        cin>>v[i];  \
    }               \
;
#define printm(m) \
    for(auto i: m){\
        cout<<i.ff<<' '<<i.ss<<endl;        \
    }\
;
long long pow2(long long a, long long b) {
    long long res = 1;
    while (b > 0) {
        if (b & 1)
            res = ((res%MOD) * (a%MOD))%MOD;
        a = ((a%MOD) * (a%MOD));
        b >>= 1;
    }
    return res;
}

template <typename T>
T extGcd(T a, T b, T &x, T &y)
{
    if (b == 0)
    {
        x = 1;
        y = 0;
        return a;
    }
    else
    {
        int g = extGcd(b, a % b, y, x);
        y -= a / b * x;
        return g;
    }
}

template <typename T>
T modInv(T a, T m)
{
    T x, y;
    extGcd(a, m, x, y);
    return (x % m + m) % m;
}

int main()
{
    fast;
    // #ifndef ONLINE_JUDGE
    // // freopen("input.txt", "r", stdin);
    // // freopen("output.txt", "w", stdout);
    // #endif

    int t=1;
    // cin>>t;
    // ll tot=t;
    while(t--){
    	ll n,s;
    	cin>>n>>s;
    	ll dp[n+1][s+1];
    	memset(dp, 0, sizeof(dp));
    	vll v(n);
    	FORALL(i,n){
    		cin>>v[i];
    	}
    	int k = modInv(2, MOD);
    	dp[0][0] = pow2(2, n);
    	for(int i = 0; i<n;i++){
    		for(int j = 0; j<=s;j++){
    			dp[i+1][j] += dp[i][j];
    			dp[i+1][j]%=MOD;
    			if(j+v[i] <=s ) {
    				dp[i+1][j+v[i]] += (dp[i][j] * k )%MOD;
    				dp[i+1][j+v[i]]%=MOD;
    			}
    		}
    	}
    	print(dp[n][s]);
    }
    return 0;
}


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

int main()
{
    int a,b;
    cin>>a>>b;
    int x=a<b?a:b;
    int y=a>b?a:b;
    for(int i=0;i<y;i++)
    {
        cout<<x;
    }
    cout<<endl;
}


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

const int COMMAX = 1000000;
const int MOD = 1000000007;
vector<long long> fac, finv, inv;

void InitializeCombination(void){
    fac.push_back(1LL);
    fac.push_back(1LL);
    finv.push_back(1LL);
    finv.push_back(1LL);
    inv.push_back(0LL); //Though 0^(-1) cannot be defined, there should be some number in inv[0]
    inv.push_back(1LL);
    for (int i = 2; i < COMMAX; i++){
        fac.push_back(fac[i-1] * (long long)i % (long long)MOD);
        inv.push_back((long long)MOD - inv[MOD%i] * (long long)(MOD/i) % (long long)MOD);
        finv.push_back(finv[i-1] * inv[i] % (long long)MOD);
    }
}

long long Combination(int n, int r){
    if (n < r) return 0LL;
    if (n < 0 || r < 0) return 0LL;
    return fac[n] * (finv[r] * finv[n-r] % MOD) % MOD;
}

int main(void){
    int X, Y;
    cin >> X >> Y;

    if((X+Y) % 3 != 0){
        cout << 0 << endl;
        return 0;
    }

    int disX = (2*X - Y) / 3;
    int disY = (2*Y - X) / 3;

    InitializeCombination();
    cout << Combination(disX+disY, disX);

    return 0;
}

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

int main() {
	int t[5];

	for (int i = 0; i < 5; i++) {
		cin >> t[i];
	}

	int ans = 0;
	vector<int> mod(5);

	for (int i = 0; i < 5; i++) {
		if (t[i] % 10 == 0) {
			mod[i] = 0;
		}
		else {
			mod[i] = 10 - t[i] % 10;
		}
	}

	int max_mod = *max_element(mod.begin(), mod.end());

	for (int i = 0; i < 5; i++) {
		if (t[i] % 10 == 0) {
			ans += t[i];
		}
		else {
			ans += (t[i] / 10 + 1) * 10;
		}
	}

	ans = ans - max_mod;
	
	cout << ans;

	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    long long n,m;
    cin>>n>>m;
    long long sum=0;
    for(int i=0;i<m;i++)
    {
        int x;
        cin>>x;
        sum=sum+x;
    }
    if(sum>n){
        cout<<-1;
    }else{
    cout<<n-sum;
    }

}


Measured memory_bytes: 3636
<?php
list($n, $k) = explode(' ', trim(fgets(STDIN)));
$human = range(1, $n);
$have_sweets = [];
for ($i = 1; $i <= $k; ++$i) {
    list($d) = explode(' ', trim(fgets(STDIN)));
    $have_sweets = array_merge($have_sweets, explode(' ', trim(fgets(STDIN))));
}
$have_sweets = array_unique($have_sweets);
echo count(array_diff($human, $have_sweets));


Measured memory_bytes: 17284
import java.util.Scanner;

public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		int x = sc.nextInt();
		int a = sc.nextInt();
		int b = sc.nextInt();
		int f = 0 - a + b;

		if (x < f) {
			System.out.println("dangerous");;
		} else if (0 < f) {
			System.out.println("safe");
		} else {
			System.out.println("delicious");
		}
	}
}

Measured memory_bytes: 21844
#include<bits/stdc++.h>
using namespace std;
int frog(std::vector<int> v,int n,int k)
{
    int dp[100001] = {0};
    dp[0] = 0;
    dp[1] = abs(v[0]-v[1]);
    for(int i=2;i<=n;i++)
    {
        int ans = INT_MAX;
        for(int j=1;j<=k;j++)
        {
            int a1 = 0;
            if((i-j)>=0)
            {
                 a1 = dp[i-j] + abs(v[i]-v[i-j]);
            }
            else
            {
                break;
            }
            ans = min(ans,a1);
        }

        dp[i] = ans;
    }

    return dp[n-1];

}
int main()
{
    int n;
    cin>>n;
    int k;
    cin>>k;
    std::vector<int> v;
    for(int i=0;i<n;i++)
    {
        int a;
        cin>>a;
        v.push_back(a);
    }

    int ans = frog(v,n,k);
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 4528
N,K=map(int,input().split())
d=[]
A=[]
for _ in range(K):
    d.append(int(input()))
    A.append(list(map(int,input().split())))
cnt=[0 for i in range(N)]
for i in range(K):
    for a in A[i]:
        cnt[a-1]+=1
print(cnt.count(0))


Measured memory_bytes: 9096
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <memory.h>
#include <cctype>
#include <cassert>
using namespace std;

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

const int MAX = 1023;
const int MIN = 0;
char ch[] = { '0', '1', '+', '-', '*', '(', ')'};
size_t cur;
string str;

int E(int &op_cnt);

int number(){
  int res = 0;
  while(cur < str.size() && isdigit(str[cur])){
    res = res * 2 + str[cur++] - '0';
    if(res > MAX) return -1;
  }
  return res;
}

int T(){
  int res;
  if(isdigit(str[cur])){
    res = number();
  }else if(str[cur] == '('){
    int cnt = 0;
    cur++;
    if(cur == str.size()) return -1;
    res = E(cnt);
    if(cur == str.size() || str[cur] != ')' || cnt == 0) res = -1;
    cur++;
  }else{
    res = -1;
  }
  return res;
}

int F(int &op_cnt){
  int res = 1;
  vector<int> v;
  v.push_back(T());
  
  while(cur < str.size() && str[cur] == '*'){
    cur++;
    op_cnt++;
    if(cur == str.size()) return -1;
    int tmp = T();
    if(tmp < 0) return -1;
    v.push_back(tmp);
  }
  
  rep(i, v.size()){
    res *= v[i];
    if(res < MIN || MAX < res) return -1;
  }
  return res;
}

int E(int &op_cnt){
  int res = 0, tmp;
  vector<int> v;
  tmp = F(op_cnt);
  
  if(tmp < 0) return -1;
  else v.push_back(tmp);
  
  while(cur < str.size() && (str[cur] == '+' || str[cur] == '-')){
    char op = str[cur];
    op_cnt++;
    cur++;
    if(cur == str.size()) return -1;
    tmp = F(op_cnt);
    if(tmp < 0) return -1;
    else v.push_back(op == '+' ? tmp : -tmp);
  }
  if(cur < str.size() && str[cur] != ')') return -1;
  rep(i, v.size()){
    res += v[i];
    if(res < MIN || MAX < res) return -1;
  }
  return res;
}


int dfs(string s, int c){
  int res = -1;
  int pos = find(s.begin(), s.end(), '.') - s.begin();
  
  if(c == 0){
    int cnt = 0;
    str = s;
    cur = 0;
    res = E(cnt);
    //cout << str << " " << res << endl;
    return cur == str.size() ? res : -1;
  }
  
  
  rep(i, 7){
    s[pos] = ch[i];
    res = max(res, dfs(s, c - 1));
    s[pos] = '.';
  }
  return res;
}

int main(){
  string s;
  cin >> s;
  cout << dfs(s, count(s.begin(), s.end(), '.')) << endl;
  return 0;
}

Measured memory_bytes: 1216
#! /usr/bin/python3
# 台形 / Trapezoids
"""
    1 ≤ a ≤ 100
    1 ≤ b ≤ 100
    1 ≤ h ≤ 100
    入力で与えられる値はすべて整数
    h は偶数
"""

def main():
    """
    台形の面積を出力する関数
    """
    a = int(input())
    b = int(input())
    h = int(input())

    print(int((a+b)*h/2))

if __name__ == '__main__':
    main()


Measured memory_bytes: 2940
def main():
    [N, M] = [int(i) for i in input().split()]

    E = []

    for i in range(M):
        E.append([int(i) for i in input().split()])

    dist = [-1*10**100 for i in range(N)]
    dist[0] = 0

    for i in range(N):
        for [a, b, c] in E:
            newLen = dist[a-1] + c
            if newLen > dist[b-1]:
                dist[b-1] = newLen

    dist2 = dist.copy()

    for i in range(N):
        for [a, b, c] in E:
            newLen = dist2[a-1] + c
            if newLen > dist2[b-1]:
                dist2[b-1] = newLen

    if dist[N-1] != dist2[N-1]:
        print('inf')
    else:
        print(dist[N-1])


if __name__ == '__main__':
    main()


Measured memory_bytes: 3444
#include<bits/stdc++.h>
using namespace std;
using vi = vector<int>; // intの1次元の型に vi という別名をつける
using vvi = vector<vi>; // intの2次元の型に vvi という別名をつける
typedef pair<int, int> pii;  // pair<int, int> に pii という別名を付ける

int main(){
  int N,X, count=1, sum=0;
  cin >> N >> X;
  vi L(N);
  X++;
  for (int i = 0; i < N; i++)
  {
    cin >> L.at(i);
  }
  for (int i = 0; i < L.size(); i++){
    sum += L.at(i);
    if(sum < X){
      count ++;
    }
  }
  cout << count << endl;
}

Measured memory_bytes: 256
use proconio::{input, fastout};

macro_rules! echo {
  ($val:expr) => {
    println!("{}", $val);
  }
}

#[fastout]
fn main() {
  input!{
    xs: [i64; 5]
  };
  for i in 0..5 {
    if xs[i] == 0 {
      echo!(i+1);
      return;
    }
  }
}


Measured memory_bytes: 2092
using namespace std;
#define _CRT_SECURE_NO_WARNINGS
#pragma target("avx")
#pragma optimize("O3")
#pragma optimize("unroll-loops")
#include<iostream>
#include<algorithm>
#include<ctime>
#include<vector>
#include<string>
#include<cmath>
#include<map>
#include<iomanip>
#include<numeric>
#include<queue>
#include<deque>
#include<cfloat>
#include<functional>
#include<tuple>
#include<math.h>
#include<bitset>
#include<stack>
#include<set>
#include<random>
#include<stdlib.h>
#define rip(i,n) for(ll i=0;i<n;i++)
#define Rip(i,n) for(ll i=1;i<n;i++)
#define all(V) V.begin(),V.end()
#define ll long long
#define ld long double
#define MOD 998244353
#define mod MOD
#define sec setprecision
constexpr double eps = 1e-9;
constexpr double PI = 3.141592653589793238462643383279;
ll gcd(ll a, ll b) {
	if (a % b == 0)	return(b);
	else return(gcd(b, a % b));
}
ll lcm(ll a, ll b)
{
	return a * b / gcd(a, b);
}
int ketasuu(ll h) {
	if (h < 0)return(-(ketasuu(-h)));
	else if (h < 10)return(1);
	else return(1 + ketasuu(h / 10));
}
const int MAX = 510000;
long long fac[MAX], finv[MAX], inv[MAX];
void cominit() {
	fac[0] = fac[1] = 1;
	finv[0] = finv[1] = 1;
	inv[1] = 1;
	for (ll i = 2; i < MAX; i++) {
		fac[i] = fac[i - 1] * i % MOD;
		inv[i] = MOD - inv[MOD % i] * (MOD / i) % MOD;
		finv[i] = finv[i - 1] * inv[i] % MOD;
	}
}
vector<ll> soinnsuubunnkai(ll n) {
	vector<ll>a;
	while (n % 2 == 0) {
		a.push_back(2);
		n /= 2;
	}
	ll f = 3;
	while (f * f <= n) {
		if (n % f == 0) {
			a.push_back(f);
			n /= f;
		}
		else f += 2;
	}
	if (n != 1)
		a.push_back(n);
	return(a);
}
// 二項係数計算
long long com(ll n, ll k) {
	if (n < k) return 0;
	if (n < 0 || k < 0) return 0;
	return fac[n] * (finv[k] * finv[n - k] % mod) % mod;
}
ll pow(ll a, ll b) {
	a = a % mod;
	if (b == 0)return(1);
	else if (b % 2 == 0)return(pow((a * a) % mod, b / 2));
	else return(a * (pow(a, b - 1)));
}
void solve() {
	int a; string s;
	cin >> a >> s;
	if (a >= 3200)cout << s << endl;
	else cout << "red" << endl;
}
int main() {
	solve();
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main{

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int ki = 0,gu = 0;
		for (int i = 0; i < n; i++) {
			if(i % 2 == 0) {
				gu++;
			}else {
				ki++;
			}
		}
		System.out.println(gu*ki);
	}

}


Measured memory_bytes: 23252
from itertools import accumulate, permutations, combinations, product, combinations_with_replacement, groupby
from math import sqrt, factorial, log
from bisect import bisect_left, bisect_right
from collections import Counter, defaultdict, deque
from heapq import heappop, heappush, heappushpop
import sys
stdin = sys.stdin
mod = 10**9 + 7

def ns(): return stdin.readline().rstrip()
def ni(): return int(ns())
def na(): return list(map(int, stdin.readline().split()))

a = list()
for i in range(1, 6):
    a.append("hi"*i)
s = ns()
if s in a:
    print("Yes")
else:
    print("No")

Measured memory_bytes: 3568
#include<bits/stdc++.h>
#include<iostream>
#include<cmath>
#include<vector>
#include<string>
#include<queue>
#include<set>
#include<map>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;
typedef pair<ll, ll> pll;
typedef pair<ull, ull> pullull;
typedef pair<ll, int> plli;
typedef pair<int, pii> pipii;
typedef vector<vector<int> > mati;
typedef vector<vector<double> > matd;

#define rep(i,x,y) for(int i=(x); i<(y); ++i)
const int INF = (1<<30);
const ll INFLL = 1LL<<62;
const long double EPS = 1e-12;

template <typename T>
void vec_print(vector<T> VEC){
  rep(i, 0, VEC.size()){
    cout << VEC[i] << " ";
  }
  cout << "\n";
};

template <typename T>
void mat_print(vector<vector<T> > MAT){
  rep(i, 0, MAT.size()){
    rep(j, 0, MAT[i].size()){
      cout << MAT[i][j] << " ";
    }
    cout << "\n";
  }
};

class HOGE{
  public:
    ll index;
    ll value;
    HOGE(ll index, ll value){
      this->index = index;
      this->value = value;
    };
    ~HOGE(void){
      return;
    };

    void print(void){
      cout << "index : " << index << ", value : " << value << "\n";
      return;
    };
    
    bool operator==(const HOGE &obj){
      return (this->value == obj.value);
    };
    bool operator<(const HOGE &obj){
      return (this->value < obj.value);
    };
    bool operator>(const HOGE &obj){
      return (this->value > obj.value);
    };
};

int main(){
  cin.tie(0); // cut the cin and cout (default, std::flush is performed after std::cin)
  ios::sync_with_stdio(false); // cut the iostream and stdio (DON'T endl; BUT "\n";)

  ll N;
  cin >> N;
  ll before=0;
  ll count=0;
  rep(i, 0, N){
    ll tmp;
    cin >> tmp;
    count += (tmp+before)/2;
    if((tmp+before)%2==1){
      if(tmp > 0){
        before = 1;
      }else{
        before = 0;
      }
    }else{
      before = 0;
    }
  }

  cout << count << "\n";

  return 0;
}


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

#define int long long
#define itn int
#define For(i, a, b) for (int i = (a); i <= static_cast<int>(b); i++)
#define Forr(i, a, b) for (int i = (a); i >= static_cast<int>(b); i--)
#define rep(i, n) For(i, 0, n - 1)
#define repall(i, arr) for (auto& i : (arr))
#define all(x) (x).begin(), (x).end()
#define pb push_back
#define dump(x) cerr << #x << " = " << (x) << '\n'
#define dump2(x, y) \
    cerr << #x << " = " << (x) << " " << #y << " = " << (y) << '\n'
#define SZ(x) ((int)(x).size())
#define bit(n) (1LL << (n))
constexpr int MOD = 1e9 + 7;

template <typename T>
using pq = priority_queue<T>;
template <typename T>
using pqr = priority_queue<T, vector<T>, greater<T>>;
const int INF = LLONG_MAX / 2;
using P = pair<int, int>;
using vec = vector<int>;
template <typename T>
using mat = vector<vector<T>>;

template <typename T1, typename T2>
ostream& operator<<(ostream& stream, const pair<T1, T2>& p) {
    return stream << p.first << " " << p.second;
}
template <typename T>
void print(const vector<T> vec) {
    unsigned int len = vec.size();
    rep (i, len - 1)
        cout << vec[i] << ' ';
    cout << vec[len - 1] << '\n';
}
template <typename Arg>
void print(const Arg arg) {
    cout << arg << '\n';
}
template <typename Head, typename... Args>
void print(const Head head, const Args... args) {
    cout << head << " ";
    print(args...);
}
template <typename T>
T sum_(vector<T> vec, T init = 0) {
    return std::accumulate(all(vec), T(init));
}

template <typename T>
void init(vector<T>& v) {
    rep (i, v.size())
        cin >> v[i];
}

template <typename T, typename U>
void init(vector<T>& v, vector<U>& w) {
    assert(v.size() == w.size());
    rep (i, v.size())
        cin >> v[i] >> w[i];
}

// clang-format off
template<typename T>
bool chmax(T& a, const T& b) { if (a < b) { a = b; return true; } return false; }
template<typename T>
bool chmin(T& a, const T& b) { if (a > b) { a = b; return true; } return false; }
template <typename T>
int index(const T& vec, const typename T::iterator it) { return distance(vec.begin(), it); }
template <typename T = int>
mat<T> mmat(int n, int m) { return mat<T>(n, vector<T>(m)); }
template <typename T = int>
vector<T> ivec(int n) { vector<T> v(n); init(v); return v; }
// clang-format on

void yn(bool tf) { print(tf ? "Yes" : "No"); }
void YN(bool tf) { print(tf ? "YES" : "NO"); }

int gcd(int a, int b) { return b ? gcd(b, a % b) : a; }

// -------------------------------------------------------------------
// sort 1 2 3 4
// pqr 1 2 3 must impl >

signed main() {
    cin.tie(0), cout.tie(0), ios::sync_with_stdio(false);
    vec v = ivec(5);
    int ma = -INF;
    repall (i, v) {
        chmax(ma, (1000 - i) % 10);
        i = (i + 9) / 10 * 10;
    }
    print(sum_(v) - ma);

    return 0;
}


Measured memory_bytes: 764
import java.util.Arrays;
import java.util.Scanner;

public class Main{
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = Integer.parseInt(sc.next());

		for (int i = 0; i < n; i++) {
			int a = Integer.parseInt(sc.next());
			int b = Integer.parseInt(sc.next());

			int[] x = new int[a];
			for (int j = 0; j < a; j++) {
				x[j] = Integer.parseInt(sc.next());

			}
			int[] y = new int[a - 1];
			for (int j = 0; j < y.length; j++) {
				y[j] = x[j + 1] - x[j];
			}
			Arrays.sort(y);
			if (b > y.length) {
				System.out.println(0);
			} else {
				int sum = 0;
				for (int j = 0; j < y.length - b + 1; j++) {
					sum += y[j];
				}
				System.out.println(sum);
			}
		}
	}
}

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

int main(){

    int a,b,c;cin >> a >> b >> c;
    if(a > b){
        cout << 0 << endl;
    }else if(a*c > b){
        cout << b/a << endl;
    }else{
        cout << c << endl;
    }


    return 0;
}

Measured memory_bytes: 256
d=dict()
n=int(input())
ans=0
special=0
for i in range(1,n+1):
  ii=str(i)
  if (ii[0],ii[-1]) in d.keys():
    d[(ii[0],ii[-1])]+=1
  else:
    d[(ii[0],ii[-1])]=1
  if (ii[-1],ii[0]) in d.keys():
    ans+=d[(ii[-1],ii[0])]
  if (ii[0]==ii[-1]):
    special+=1
  #print(i,ans)
#print(special)
print(2*(ans-special)+special)


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

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

using namespace std;

using ll = long long;

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

    int K;
    cin >> K;
    --K;

    vector<vector<ll>> dp;

    function<void(int, int)> f = [&](int i, int d) {
        cout << d;
        if (i == 0) {
            return;
        }
        FOR(d_next, max(0, d - 1), min(9, d + 1) + 1) {
            if (K >= dp[i - 1][d_next]) {
                K -= dp[i - 1][d_next];
            } else {
                f(i - 1, d_next);
                return;
            }
        }
    };
    
    while (true) {
        int i = dp.size();
        dp.push_back(vector<ll>(10));
        REP(d, 10) {
            if (i > 0) {
                ll tmp = dp[i - 1][d];
                if (d + 1 < 10) {
                    tmp += dp[i - 1][d + 1];
                }
                if (d - 1 >= 0) {
                    tmp += dp[i - 1][d - 1];
                }
                dp[i][d] = tmp;
            } else {
                dp[0][d] = 1;
            }
            if (d > 0) {
                if (K >= dp[i][d]) {
                    K -= dp[i][d];
                } else {
                    f(i, d);
                    cout << endl;
                    return 0;
                }
            }
        }
    }

    return 0;
}


Measured memory_bytes: 256
from itertools import product

ans = -10**9 - 1

N = int(input())
F = []
for _ in range(N):
  F.append(list(map(int, input().split())))

P = []
for _ in range(N):
  P.append(list(map(int, input().split())))

all_x = True
for ox in product((0, 1), repeat=10):
  if all_x:
    all_x = False
  else:
    temp = 0
    for n in range(N):
      cnt = 0
      for i, j in zip(F[n], ox):
        cnt += i*j
      temp += P[n][cnt]
    ans = max(ans, temp)

print(ans)

Measured memory_bytes: 9196
let input = readLine()!.split(separator: " ").map { Int($0)! }
let N = input[0]
let K = input[1]

var snukes = Array(repeating: 0, count: N)
for _ in 0 ..< K {
    let _ = readLine()
    readLine()!.split(separator: " ").map { Int($0)! }.forEach {
        snukes[$0 - 1] = 1
    }
}

print(snukes.filter { $0 == 0 }.count)


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

int main()
{
  int n;
  std::cin >> n;
  std::vector<int> a(n);
  for (size_t i = 0; i < n; i++)
  {
    std::cin>>a[i];
  }
  std::vector<int> b(n);
  for (size_t i = 0; i < n; i++)
  {
    // int ai = a[i];
    b[a[i]-1] = i;
  }

  for(const auto& i: b)
  {
    std::cout << i+1<<" ";
  }
  std::cout<< std::endl;
}


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

def main():
    N,A,B = map(int,input().split())
    X = list(map(int,input().split()))
    walk = B//A
    fatigue = 0
    for i in range(N-1):
        dif = X[i+1]-X[i]
        if dif <= walk:
            fatigue += dif*A
        else:
            fatigue += B

    print(fatigue)

if __name__ == "__main__":
    main()

Measured memory_bytes: 14252
#include "bits/stdc++.h"
//http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=2613&lang=jp
typedef long long ll;
using namespace std;
#define LINF 1LL<<63;
ll solve(string expr, map<char, ll>& op);
ll check(int& i, string& expr);

ll solve(string expr, map<char, ll>& op) {

	/* <expr> <op> <expr> ??? ( <expr> <op> <expr> )*/
	for (int p = 1; p <= 3;p++) {
		for (int i = 0; i < (int)expr.length();i++) {
			if (expr[i] >= '0' && expr[i] <= '9')continue;
			if (op[expr[i]] != p) continue;

			int parentheses = 0;
			for (int left = i - 1; left >= 0; left--) {
				if (left == 0) { expr = "(" + expr; i++; break; }
				if (expr[left] >= '0' && expr[left] <= '9')continue;
				if (expr[left] == ')') { parentheses++; }
				if (expr[left] == '(') { parentheses--; }
				if (parentheses > 0) continue;
				expr.insert(expr.begin() + left + 1, '('); i++; break;
			}
			parentheses = 0;
			for (int right = i + 1; right < expr.length();right++) {
				if (right == expr.length() - 1) { expr = expr + ")"; break; }
				if (expr[right] >= '0' && expr[right] <= '9')continue;
				if (expr[right] == '(') { parentheses++;}
				if (expr[right] == ')') { parentheses--;}
				if (parentheses > 0) continue;
				expr.insert(expr.begin() + right, ')'); break;
			}
		}
	}
	//cout << op['+'] << " " << op['-'] << " " << op['*'] << endl;
	//cout << expr << endl;
	int i = 0;
	ll ret = check(i, expr);
	//cout << ret << endl;
	return ret;
}

ll check(int& i, string& expr) {
	ll l_expr, r_expr;
	if (expr[i] == '(') {
		/* "( ~ )" op ~ */
		i++;
		l_expr = check(i, expr);
	}
	else {
		/* "number" op ~ */
		l_expr = 0;
		while (expr[i] >= '0' && expr[i] <= '9') {
			l_expr = l_expr * 10 + (expr[i] - '0');
			i++;
		}
	}
	/* (expr) or (number) */
	char option;
	if (i == expr.length() || expr[i] == ')') { i++; return l_expr; }
	else {
		option = expr[i];
		i++;
	}

	if (expr[i] == '(') {
		/* ~ op "( ~ )"*/
		i++;
		r_expr = check(i, expr);
	}
	else {
		/* ~ op "number" */
		r_expr = 0;
		while (expr[i] >= '0' && expr[i] <= '9') {
			r_expr = r_expr * 10 + (expr[i] - '0');
			i++;
		}
	}
	if (expr[i] == ')') {
		i++;
		if (option == '+') return l_expr + r_expr;
		if (option == '-') return l_expr - r_expr;
		if (option == '*') return l_expr * r_expr;
	}
	return 0;
}

int main() {
	cin.tie(0); ios::sync_with_stdio(false);
	string expr; cin >> expr;
	map<char, ll> op; op['('] = op[')'] = 0;

	ll ans = -LINF;
	for (int i = 1; i <= 3;i++) {
		for (int j = 1; j <= 3;j++) {
			for (int k = 1; k <= 3;k++) {
				if (i != 1 && j != 1 && k != 1) continue;
				int x = 0;
				op['+'] = i; op['-'] = j; op['*'] = k;
				ans = max(ans, solve(expr, op));
			}
		}
	}
	cout << ans << endl;
}

Measured memory_bytes: 3248
#include <iostream>

int main()
{
  int X, Y;
  std::cin >> X >> Y;
  if (Y%2==1) std::cout << "No" << std::endl;
  else {
    if (2*X - Y/2 >= 0 && Y/2 - X >= 0) std::cout << "Yes" << std::endl;
    else std::cout << "No" << std::endl;
  }
  return 0;
}


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

int main()
{
    int n;
    cin >> n;
    
    int arrSize = n * 3;
    unsigned long long* arr = new unsigned long long[arrSize];
    
    for(int i = 0; i < arrSize; i++)
    {
        cin >> arr[i];
    }
    
    sort(arr, arr + arrSize, greater<int>());
    
    unsigned long long sum = 0;
    
    for(int i = 0; i < n; i++)
    {
        int index = i * 2 + 1;
        sum += arr[index];
    }
    
    cout << sum << endl;
    
    return 0;
}

Measured memory_bytes: 2560
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int p[11],k[11],s[11][11];
int get_bit(int x,int i){return (x>>i)&1;}
int main()
{
    int n,m;
    cin>>n>>m;
    for(int i=0;i<m;i++) {
        scanf("%d",&k[i]);
        for (int j = 0; j <k[i];j++)
            scanf("%d",&s[i][j]);
    }
    for(int i=0;i<m;i++)cin>>p[i];
    int sum=0;
    for(int i=0;i<(1<<n);i++)
    {
        int f=0;
        for(int r=0;r<m;r++) {
            int ans=0;
            for(int l=0;l<k[r];l++)
                if (i&(1<<(s[r][l]-1)))
                    ans++;
            if(ans%2==p[r])
            {
                f++;
            }
        }
        if(f==m)
            sum++;
    }
    cout<<sum<<endl;
    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<set>
#include<map>
#include<vector>
#include<queue>
#include<cstring>
#include<cmath>
#include<cstdio>
#include<cstdlib>
using namespace std;
#define REP(i,a,n) for(int i = a ; i < n ; i++)
#define rep(i,n) REP(i,0,n)

typedef long long ll;

const int N = 1000000;  //MAXPRIME
const int M = 1000; //SQRT(N)
const int K = 600000;   //NUMBER OF PRIMES, CHOOSE 9/8 * N / LOG(N)

vector<int> iterativeSieve(){
  static int p[K],table[M];
  REP(i,2,M) p[i] = i;
  for(int i=2;i*i<M;i++)
    if(p[i])
      for(int j=i*i;j<M;j+=i)
        p[j] = 0;
  p[0] = p[1] = 0;

  int num = remove(p,p+M,0) - p;
  for(int m=M;m<N;m+=M){
    for(int x=m;x<m+M;x++)
      table[x-m] = x;
    for(int i=0,j;p[i]*p[i]<m+M;i++){
      if(p[i] >= m) j = p[i] * p[i];
      else if(m % p[i] == 0) j = m;
      else j = m - (m % p[i]) + p[i];
      for(;j<m+M;j+=p[i]) table[j-m] = 0;
    }
    num = remove_copy(table,table+M,p+num,0) - p;
  }
  return vector<int>(p,p+num);
}

int main(){
  vector<int> p = iterativeSieve();
  int n;
  while(cin>>n){
    cout<<upper_bound(p.begin(),p.end(),n) - p.begin()<<endl;
  }
}

Measured memory_bytes: 0
#include<iostream>
using namespace std;
int n,a,x[55];
long dp[55][5555];
main()
{
	cin>>n>>a;
	for(int i=0;i<n;i++)cin>>x[i];
	dp[0][2500]=1;
	for(int i=0;i<n;i++)
	{
		x[i]-=a;
		for(int j=0;j<=5000;j++)
		{
			dp[i+1][j]+=dp[i][j];
			if(j<=5000-x[i])dp[i+1][j+x[i]]+=dp[i][j];
		}
	}
	cout<<dp[n][2500]-1<<endl;
}

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

// @@ !! LIM()

int main(int argc, char *argv[]) {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
  cout << setprecision(20);

  ll N, K; cin >> N >> K;
  vector<ll> acc(N+1);
  for (ll i = 0; i < N; i++) {
    ll p; cin >> p;
    acc.at(i+1) = acc.at(i) + p;
  }
  ll vm = 0;
  for (ll i = K; i <= N; i++) {
    vm = max(vm, acc.at(i) - acc.at(i - K));
  }
  double ans = ((double)vm + K) / 2.0;
  cout << ans << endl;

  return 0;
}



Measured memory_bytes: 1792
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
double dp[310][310][310];

signed main(){
	int n, a = 0, b = 0, c = 0;
	cin >> n;
	for(int i = 0; i < n; i++){
		int x; cin >> x;
		if(x == 1) a++;
		if(x == 2) b++;
		if(x == 3) c++;
	}
	double N = n;
	dp[1][0][0] = double(n);
	for(int k = 0; k <= n; k++){
		for(int j = 0; j <= n; j++){
			for(int i = 0; i <= n ; i++){
				if((i == 0 || i == 1) && j == 0 && k == 0) continue;
				if(i){
					dp[i][j][k] += dp[i - 1][j][k] * (i / N);
				}
				if(j){
					dp[i][j][k] += dp[i + 1][j - 1][k] * double(j / N);
				}
				if(k){
					dp[i][j][k] += dp[i][j + 1][k - 1] * double(k / N);
				}
			  dp[i][j][k] *= double(N / (i + j + k));
				dp[i][j][k] += double(N / (i + j + k));
			}
		}
	}
	cout << setprecision(10) << dp[a][b][c] << endl;
}

	

Measured memory_bytes: 224308
# -*- coding: utf-8 -*-

from collections import defaultdict

N = int(input())
lhs = [int(num) for num in input().split()]
lhs_first = lhs.pop(0)
rhs = lhs.pop()

calc_table = {lhs_first:1}
for num in lhs:#last num is rhs
    new_calc_table = defaultdict(int)
    for calcs,patterns in calc_table.items():
        if (calcs+num <= 20):
            new_calc_table[calcs+num] = new_calc_table.get(calcs+num,0) + patterns
        if (calcs-num >=  0):
            new_calc_table[calcs-num] = new_calc_table.get(calcs-num,0) + patterns
    calc_table = new_calc_table

print(str(calc_table[rhs]))

Measured memory_bytes: 6728
#include <bits/stdc++.h>
#include <math.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;
typedef pair<int, int> P;
const int INF = 1001001001;
const int mINF = -1001001001;


int main() {
int n;
cin >> n;
int a;
a=n%4;
string ans = "No";
if(a==0) ans="Yes";
if(a==1&&n>=21) ans="Yes";
if(a==2&&n>=14) ans="Yes";
if(a==3&&n>=7) ans="Yes";

cout << ans << endl;
return 0;
}


Measured memory_bytes: 256
#include <cstdio>

char S[101010];

int main()
{
	scanf("%s", S);

	bool app[26];
	for (int i = 0; i < 26; ++i) {
		app[i] = false;
	}
	for (int i = 0; S[i] != '\0'; ++i) {
		app[S[i] - 'a'] = true;
	}
	for (int i = 0; i < 26; ++i) {
		if (!app[i]) {
			printf("%c\n", (char)(i + 'a'));
			return 0;
		}
	}
	puts("None");
	return 0;
}


Measured memory_bytes: 1752
#include<bits/stdc++.h>
using namespace std;
 
int main(){
  string str;
  cin >> str;
  sort(str.begin(), str.end());
  for(int i=0; i+1<str.size(); i++){
    if(str[i]==str[i+1]){
      cout <<"no"<<endl;
      return 0;
    }
  }
  cout << "yes"<<endl;
}

Measured memory_bytes: 256
<?php
function sumEle($arr)
{
    $sum=0;
    for($i=0;$i<sizeof($arr);$i++)
        $sum+=$arr[$i];
    return $sum;
}

fscanf(STDIN,"%d",$n);
$h = explode(" ", rtrim(fgets(STDIN)));
$result=0;
while(sumEle($h)!=0)
{
    for($i=0;$i<$n;$i++)
    {
        if($h[$i]!=0)
        {
            $start=$i;
            break;
        }
    }

    $end=$n-1;
    for($j=$i;$j<$n;$j++)
    {
        if($h[$j]==0)
        {
            $end=$j-1;
            break;
        }
    }

    $count=200;
    for($i=$start;$i<$end+1;$i++)
        $count=min($count,$h[$i]);
    for($i=$start;$i<$end+1;$i++)
        $h[$i]-=$count;
    $result+=$count;
}
echo($result);

Measured memory_bytes: 3576
n = int(input())
a = list(map(lambda x:int(x)-1,input().split()))
count = [0]*n
for i in a:
    count[i]+=1
sum=0
for i in count:
    sum += i*(i-1)//2

for i in a:
    ans = sum-count[i]+1
    print(ans)

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

#define REP(i, n) for (ll i = 0; i < (ll)(n); i++)
#define RREP(i, n) for (ll i = n - 1; i >= 0; i--)
#define FOR(i, a, b) for (ll i = a; i <= (ll)(b); i++)
#define RFOR(i, a, b) for (ll i = a; i >= (ll)(b); i--)
#define ALL(x) (x).begin(), (x).end()
#define MAX(x) *max_element(ALL(x))
#define MIN(x) *min_element(ALL(x))

template <typename T>
ostream &operator<<(ostream &os, const vector<T> &v) {
    os << "[ ";
    for (auto a : v) os << a << " ";
    os << "]";
    return os;
}

int main() {
    ll N, M, K;
    cin >> N >> M >> K;
    vector<ll> A(N), B(M);
    REP(i, N) {
        cin >> A[i];
        if (i > 0) A[i] += A[i - 1];
    }
    REP(i, M) {
        cin >> B[i];
        if (i > 0) B[i] += B[i - 1];
    }

    ll ans = (upper_bound(ALL(B), K) - B.begin());
    REP(i, N) {
        if (K - A[i] < 0) continue;
        ll j = (upper_bound(ALL(B), K - A[i]) - B.begin());
        ans = max(ans, i + 1 + j);
    }

    cout << ans << endl;

    return 0;
}

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

using namespace std;

typedef long long ll;
typedef long double ld;
typedef complex<ld> point;
#define F first
#define S second



int main()
{
	//freopen("a.txt", "r", stdin);
	ios_base::sync_with_stdio(0), cin.tie(0);

	int n; ll mod;
	cin >> n >> mod;
	vector<vector<int>> adj(n), pref(n), suf(n);
	for (int i = 1, u, v; i < n; ++i)
	{
		cin >> u >> v;
		--u, --v;
		adj[u].push_back(v);
		adj[v].push_back(u);
	}

	vector<int> p(n), where(n);
	vector<ll> ans(n), up(n), down(n);
	function<void(int)> dfs = [&](int u)
	{
		down[u] = 1;
		for (auto v : adj[u])
			if (v != p[u])
			{
				where[v] = pref[u].size();
				pref[u].push_back(v);
				suf[u].push_back(v);

				p[v] = u;
				dfs(v);
				down[u] = down[u] * (down[v]+1) % mod;
			}
	};

	p[0] = -1;
	dfs(0);

	for (int u = 0; u < n; ++u)
		if (!pref[u].empty())
		{
			pref[u][0] = (down[pref[u][0]]+1) % mod;
			for (int i = 1; i < pref[u].size(); ++i)
				pref[u][i] = pref[u][i-1] * (down[pref[u][i]]+1) % mod;

			suf[u].back() = (down[suf[u].back()]+1) % mod;
			for (int i = suf[u].size()-2; i >= 0; --i)
				suf[u][i] = suf[u][i+1] * (down[suf[u][i]]+1) % mod;
		}

	function<void(int)> dfs2 = [&](int u)
	{
		if (p[u] != -1)
		{
			up[u] = (up[p[u]]+1);
			if (where[u] > 0)
				up[u] = up[u] * pref[p[u]][where[u]-1] % mod;
			if (where[u]+1 < suf[p[u]].size())
				up[u] = up[u] * suf[p[u]][where[u]+1] % mod;
		}

		for (auto v : adj[u])
			if (v != p[u])
				dfs2(v);
	};

	dfs2(0);

	function<void(int, ll)> calc = [&](int u, ll dp)
	{
		ans[u] = dp;
		for (auto v : adj[u])
			if (v != p[u])
				calc(v, (dp - up[v] + down[v] + mod) % mod);
	};

	calc(0, down[0]);
	for (auto &i : ans)
		cout << (i+mod)%mod << "\n";

	return 0;
}


Measured memory_bytes: 26624
loop do
  x,y = gets.split.map(&:to_i)
  break if x == 0 and y == 0
  n = gets.to_i
  data = gets.split.map(&:to_i).each_slice(2).to_a

  d = [-2,2].product([-1,0,1]) + [-1,0,1].product([-2,2])
  nexts = [[x,y]]

  loop do
    sx,sy = data.shift
    if sx.nil? and sy.nil?
      puts "OK"
      break
    end
    nexts = d.map{|dx,dy| nexts.map{|x,y| [x+dx,y+dy]}}.flatten(1).uniq.select do |x,y|
      (0..9) === x and (0..9) === y and (x-sx).abs <= 1 and (y-sy).abs <= 1
    end
    if nexts == []
      puts "NA"
      break
    end
  end
end

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

int main(){
  long long a,b,c,num;
  long long tmpMax;
  long long tmpA,tmpB;
  long long kekka;
  
  cin >> a >> b >> c >> num;
  
  if(a == b && b == c){
    cout << 0;
  }else if(num == 1){
    tmpA = b + c;
    tmpB = a + c;
    kekka = tmpA - tmpB;
    
    if(kekka > 1000000000000000000) cout << "Unfair";
    else cout << kekka;
  }else{
    if(num % 2 == 0){
      //偶数回は自分だけ回数+1倍
      tmpA = ((num+1) * a) + (num * b) + (num * c);
      tmpB = (num * a) + ((num+1) * b) + (num * c);
      kekka = tmpA - tmpB;
      
      if(kekka > 1000000000000000000) cout << "Unfair";
      else cout << kekka;
    }else{
      //奇数回は自分だけ回数-1倍
      tmpA = ((num-1) * a) + (num * b) + (num * c);
      tmpB = (num * a) + ((num-1) * b) + (num * c);
      kekka = tmpA - tmpB;
      
      if(kekka > 1000000000000000000) cout << "Unfair";
      else cout << kekka;
    }
  }
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <functional>
#include <map>

#define REP(i, a, b) for (int i = int(a); i < int(b); i++)
#define dump(val) cerr << __LINE__ << ":\t" << #val << " = " << (val) << endl

using namespace std;

typedef long long int lli;

template<typename T>
vector<T> make_v(size_t a, T b) {
    return vector<T>(a, b);
}

template<typename... Ts>
auto make_v(size_t a, Ts... ts) {
    return vector<decltype(make_v(ts...))>(a, make_v(ts...));
}

int main() {
    int n;
    while (cin >> n, n) {
        vector<string> v(n);
        vector<char> cv;
        int isF[26] = {0};
        lli coef[26] = {0LL};
        REP(i, 0, n) {
            cin >> v[i];
            for (char &c : v[i]) {
                cv.push_back(c);
            }
            if (v[i].size() != 1) {
                isF[v[i][0] - 'A'] = 1;
            }
            for (int j = v[i].size() - 1, bs = 1; j >= 0; j--, bs *= 10) {
                coef[v[i][j] - 'A'] += (2 * (i + 1 != n) - 1) * bs;
            }
        }
        sort(begin(cv), end(cv));
        cv.erase(unique(begin(cv), end(cv)), end(cv));
        map<lli, vector<int>> mp1, mp2;

        int arr[26] = {0};
        function<void(int, int, int, int, map<lli, vector<int>> &)> dfs = [&](int srt, int pos, int tar, int used, map<lli, vector<int>> &mp) {
            if (pos == tar) {
                lli sum = 0;
                REP(i, srt, pos) {
                    sum += coef[cv[i] - 'A'] * arr[cv[i] - 'A'];
                }
                mp[sum].push_back(used);
                return;
            }
            REP(i, 0, 10) {
                if (isF[cv[pos] - 'A'] && i == 0) continue;
                int u = 1 << i;
                if ((used & u) == u) continue;
                arr[cv[pos] - 'A'] = i;
                dfs(srt, pos + 1, tar, used | u, mp);
            }
        };
        dfs(0, 0, cv.size() / 2, 0, mp1);
        dfs(cv.size() / 2, cv.size() / 2, cv.size(), 0, mp2);
        int ans = 0;
        for (auto &p : mp1) {
            auto &q = mp2[-p.first];
            for (auto i1 : p.second) {
                for (auto i2 : q) {
                    if ((i1 & i2) == 0) {
                        ans++;
                    }
                }
            }
        }
        cout << ans << endl;
    }
    return 0;
}



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

using namespace std;

int main(){
    string s, t;
    cin>>s>>t;

    unsigned long len_s = s.length();
    unsigned long len_t = t.length();

    set<char> set_s;
    for(int i=0; i<len_s; i++){
        set_s.insert(s[i]);
    }
    set<char> set_t;
    for(int i=0; i<len_t; i++){
        set_t.insert(t[i]);
    }
    set<char> result;
    set_difference(set_t.begin(), set_t.end(),
                    set_s.begin(), set_s.end(),
                    inserter(result, result.end()));
    if(result.size()>0){
        cout<<-1<<endl;
        return 0;
    }


    vector<vector<unsigned long>> s_sort(26);
    for(int i=0; i<len_s; ++i){
        s_sort[s[i]-'a'].push_back(i);
    }

    unsigned long s_count = 0;
    unsigned long now_index = 0;
    unsigned long t_index = 0;
    while(t_index < len_t){
        if(now_index == 0 && s_sort[t[t_index]-'a'][0] == 0){
            now_index = 1; /////
            t_index += 1;
        }else{

        auto itr = lower_bound(s_sort[t[t_index]-'a'].begin(), s_sort[t[t_index]-'a'].end(), now_index);
        if(itr == s_sort[t[t_index]-'a'].end()){
            s_count += 1;
            now_index = 0;
        }else{
            now_index = *itr;
            now_index += 1;
            t_index += 1;
        }
        //cerr<<s_count<<" "<<now_index<<" "<<t_index<<endl;
        }
    }

    cout<<s_count*len_s+now_index<<endl;

    return 0;
}

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


const int MAXN = 1005;

int main() {
  int x,y,a,b,c;
  cin>>x>>y>>a>>b>>c;
  vector<ll>p(a);
  vector<ll>q(b);
  vector<ll>r(c);
  rep(i,a)cin>>p[i];
  rep(i,b)cin>>q[i];
  priority_queue<ll> q2;
  rep(i,c){
    cin>>r[i];
    q2.push(r[i]);
  }
  sort(p.begin(),p.end());
  sort(q.begin(),q.end());
  sort(r.begin(),r.end());
  priority_queue<int, vector<int>, greater<int> > que;
  rep(i,x)que.push(p[a-1-i]);
  rep(i,y)que.push(q[b-1-i]);
  //cout<<q2.top()<<endl;

  while (!q2.empty()){
    if (que.top()>q2.top()) break;
    int temp1,temp2;
    temp1=que.top();
    temp2=q2.top();
    que.pop();
    q2.pop();
    que.push(temp2);
  }
  ll ans=0;
  while (!que.empty()){
    ans+=que.top();
  //  cout<<que.top()<<endl;
    que.pop();
  }
  cout<<ans;



}


Measured memory_bytes: 4852
#include<stdio.h>
#define N 10

int search(int *x, int *r, int *l){
  int ans = 0;
  if(!*x)return 1;
  if(*x>*l){
    *(l+1) = *x;
    ans = search(x+1,l+1,r);
  }
  if(*x>*r){
    *(r+1) = *x;
    ans = ans||search(x+1,l,r+1);
  }
  else return ans;
}

int main(){
  int x[11],l[11],r[11],i,j,n;
  scanf("%d",&n);
  for(i=0;i<n;i++){
    l[0] = 0; r[0] = 0; x[10] = 0;
    for(j=0;j<N;j++)scanf("%d",&x[j]);
    printf("%s\n",search(x,l,r)?"YES":"NO");
  }
  return 0;
}

Measured memory_bytes: 580
#include <bits/stdc++.h>
using namespace std;
int main() {
	ios::sync_with_stdio(false);
	cin.tie(0);  
	long long  h, w;
	cin >> h >> w;
	long long ans = 1LL << 60;
	for(int i = 1; i < w; i++) {
		long long v1 = h * i, v2 = (w - i) / 2 * h, v3 = (w - i + 1) / 2 * h;
		long long h1 = h / 2 * (w - i), h2 = (h + 1) / 2 * (w - i);
		long long vmax = max({v1, v2, v3}), vmin = min({v1, v2, v3});
		long long hmax = max({v1, h1, h2}), hmin = min({v1, h1, h2});
		if(i == w - 1) ans = min(ans, hmax - hmin);
		else ans = min({ans, vmax - vmin, hmax - hmin});
		//cerr << "i " << i << "   " << vmax << " " << vmin << " " << hmax << " " << hmin << endl;
	}
	//cerr << endl;
	for(int i = 1; i < h; i++) {
		long long h1 = w * i, h2 = (h - i) / 2 * w, h3 = (h - i + 1) / 2 * w;
		long long v1 = w / 2 * (h - i), v2 = (w + 1) / 2 * (h - i);
		long long hmax = max({h1, h2, h3}), hmin = min({h1, h2, h3});
		long long vmax = max({h1, v1, v2}), vmin = min({h1, v1, v2});
		if(i == h - 1) ans = min(ans, vmax - vmin);
		else ans = min({ans, hmax - hmin, vmax - vmin});
		//cerr << "i " << i << "   " << vmax << " " << vmin << " " << hmax << " " << hmin << endl;
	}
	cout << ans << endl;
	return 0;	
}

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

#define rep(i,n) for (int i = 0; i< (n); ++i)
#define vvec(m,n) vector<vector<int>> (int(m), vector<int>(n))
#define ALL(a) (a).begin(), (a).end()

using ll = long long;

int main(){
    string s;
    cin >> s;
    int ans = 0;
    rep(i,s.size()/2){
        if(s.at(i) != s.at(s.size()-i-1)){
            ans++;
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
#define rep(i, a, b) for(ll i = a; i < (b); ++i)
#define trav(a, x) for(auto& a : x)
#define all(x) x.begin(), x.end()
#define sz(x) (ll)(x).size()
typedef pair<ll, ll> pii;
typedef vector<ll> vi;
int main()
{
	// #ifndef ONLINE_JUDGE
 //    freopen("input.txt", "r", stdin);
 //    freopen("output.txt", "w", stdout);
	// #endif
    cin.sync_with_stdio(0);
    cin.tie(0); cin.exceptions(cin.failbit);
	ll a,b,c,k;
	cin>>a>>b>>c>>k;
	if(k<=a)
		cout<<k;
	else if(k<=a+b)
		cout<<a;
	else if(k<=a+b+c)
		cout<<a+(a-k+b);
	else
		cout<<a+c;
}


Measured memory_bytes: 3648