akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
#include<string>
#include<algorithm>
#include<stdio.h>
#include<queue>
#include<stack>
#include<map>
#include<set>
using namespace std;

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<double,double> pdd;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<vi> vvi;
typedef set<int> si;
typedef map<int, int> mii;
#define INF (1<<29)
int a[100000+100];
int n;
int main() {	
	cin>>n;
	for (int i = 1; i <= n; i++) {
		cin >> a[i];
	}
	sort(a+1, a+1+n); 
	
	long long s = 1;
	int num = 0;
	for (int i=n; i >= 2; i--) {
		if (a[i] == a[i-1]) {
			s = s*a[i];
			num = num+1;
			i--;
		}
		if (num==2) {
			break;
		}
	}
	if (num == 2) {
		cout<<s<<endl;
	}else {
		cout<<0<<endl;
	}
	return 0;
}

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


/*
sの中で、
・aまでの距離がk以下であるもののうち、もっとも左にあるものを選ぶ
・全てaになれば、もっとも右にあるもので残りを回す
*/


void solve(){
    string s;
    cin >> s;
    int k;
    cin >> k;
    int i=0;
    int siz = s.size();
    while(i<siz){
        if((26-(s[i]-'a'))<=k&&s[i]!='a'){
            k = k-(26-(s[i]-'a'));
            //cout << k << endl;
            s[i]='a';
            //i=0;
            //break;
        }
        else{
            i++;
        }
    }
    char c = s[siz-1];
    //c-'a'とkの和が26を超えていたら、26で割った余りをとる
    c = ((c-'a')+k)%26 + 'a';
    s[siz-1] = c;

    cout << s << endl;
}

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


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

using namespace std;
typedef long long ll;
typedef vector<ll> vl ;
typedef vector<int> vi;
typedef pair<int, int> pi;
typedef pair<ll,ll> pl;

#define rep(i,N) for(int i=0; i < (int)N; i++)
#define all(v) (v).begin(),(v).end()

const int INF = 100000002;

int main(){
	ll x; cin >> x;
	ll a = 100;
	int i = 1;
	while(x>a){
		a *= 1.01;
		i++;
	}
	cout << i-1 << endl;
}

Measured memory_bytes: 3632
N, M = map(int, input().split())

Info = [[] for i in range(10 ** 5 + 1)]
for i in range(M):
    p, y = map(int, input().split())
    Info[p].append((y, i))

ans = []
for pre_id, info in enumerate(Info):
    info = sorted(info)
    for i in range(len(info)):
        ans.append((info[i][1], str(pre_id).rjust(6, '0'), str(i + 1).rjust(6, '0')))

ans.sort()
for i, x, y in ans:
    print(str(x) + str(y))


Measured memory_bytes: 47888
import itertools

ACGT = ['A', 'C', 'G', 'T', '']
MOD = 10 ** 9 + 7

N = int(input())

dp = [[[[0] * 5
        for _ in range(5)]
       for _ in range(5)]
      for _ in range(N + 1)]
dp[0][4][4][4] = 1

for i, p, q, r, s in itertools.product(range(N), range(5), range(5), range(5), range(4)):
    if ACGT[q] + ACGT[r] + ACGT[s] not in {'AGC', 'GAC', 'ACG'} \
            and ACGT[p] + ACGT[r] + ACGT[s] != 'AGC' \
            and ACGT[p] + ACGT[q] + ACGT[s] != 'AGC':
        dp[i + 1][q][r][s] += dp[i][p][q][r]
        dp[i + 1][q][r][s] %= MOD

print(sum(sum(sum(y) for y in x) for x in dp[N]) % MOD)


Measured memory_bytes: 3572
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <cmath>
#include <map>
#define rep(i,n) for(int i = 0;i < (n);i++)
using namespace std;

int main(){
    int N;
    cin >> N;
    
    vector<pair<int,int>> pairs(N);
    
    rep(i,N){
        int a;
        cin >> a;
        pairs[i] = make_pair(a,i + 1);
    }
    
    sort(pairs.begin(),pairs.end());
    
    rep(i,N){
        cout << pairs[i].second << endl;
    }
}


Measured memory_bytes: 1664
#include<stdio.h>
#include<algorithm>
using namespace std;
int b[60];
int dp[1010000];
int main(){
    int a;
    int tc=0;
    while(scanf("%d",&a),a){
        tc++;
        for(int i=0;i<a;i++)scanf("%d",b+i);
        int m=b[a-1]*b[a-1]+100;m=min(m,100000);
        if(b[0]!=1){
            printf("Case #%d: Cannot pay some amount\n",tc);
            continue;
        }
        for(int i=0;i<m;i++)dp[i]=i;
        for(int i=1;i<a;i++){
            for(int j=0;j<m-b[i];j++){
                dp[j+b[i]]=min(dp[j+b[i]],dp[j]+1);
            }
        }
        bool ok=true;
        for(int i=0;i<m;i++){
            int s=i;
            int t=0;
            for(int j=a-1;j>=0;j--){
                t+=s/b[j];
                s%=b[j];
            }
            if(t>dp[i]){ok=false;break;}
        }
        if(ok)printf("Case #%d: OK\n",tc);
        else printf("Case #%d: Cannot use greedy algorithm\n",tc);
    }
}

Measured memory_bytes: 1424
import Control.Monad
import Data.Maybe
import Debug.Trace
import Data.List
import qualified Data.Map.Strict as Map
import qualified Data.IntMap.Strict as IntMap
import qualified Data.Set as Set
import qualified Data.IntSet as IntSet
import Data.Functor
import Data.Array

main :: IO ()
main = do
  abs <- replicateM 3 $ map read . words <$> getLine :: IO [[Int]]
  putStrLn $ solve abs

solve abs = if foldr (||) False [ all (elem i) abs | i <- [1..4] ]
            then "NO"
            else "YES"

Measured memory_bytes: 508
n = int(input())
V = list(map(int, input().split()))

from collections import Counter

v = Counter(V).most_common()

if len(v)==1:
    print(n//2)
    
else:
    even = [V[2*i] for i in range(n//2)]
    odd = [V[2*j+1] for j in range(n//2)]
    
    e = Counter(even).most_common()
    o = Counter(odd).most_common()
    
    if e[0][0]!=o[0][0]:
        print(n-e[0][1]-o[0][1])
    else:
        sec = v[1][0]
        esec = even.count(sec)
        osec = odd.count(sec)
        if esec>osec:
            print(n-esec-o[0][1])
        else:
            print(n-osec-e[0][1])

Measured memory_bytes: 28248
#include<cstdio>
#include<bits/stdc++.h>
typedef long long int ll;
#define REP(i, n) for(int i = 0; i < (n); i++)
#define FOR_IN(i, a, b) for(int i = (a); i < (b); i++)
#define BETWEEN(x, a, b) ((x) >= (a) && (x) <= (b))
#define BIT(b, i) (((b) >> (i)) & 1)
#define LOG_F 1
#define LOG(...) if(LOG_F) fprintf(stderr, __VA_ARGS__)

using namespace std;

ll pow(int x, int n){
  return n == 0 ? 1 : x * pow(x, n - 1);
}


/*

 */
int a,b;

int main(){
  cin>>a>>b;
  cout<< (a+b)%24 << endl;

  return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<queue>
#include<functional>
#include<cmath>
#include<set>
#include<random>
#include<map>
using namespace std;
#define int long long
#define rep(i,n) for(int i=0;i<n;i++)
const long long mod = 1000000007;
typedef pair<int, int> P;
typedef pair<int, P> PP;
struct edge {int to, cost;};
int c[30];
vector<string>S,ans;
signed main() {
	string s; cin >> s; int K; cin >> K;

	for (int x = 1; x <= 5; x++) {
		string sa;
		rep(i, (int)s.size() - x+1) {
			for(int j=i;j<i+x;j++)sa.push_back(s[j]);
			S.push_back(sa);
			sa.clear();
		}
		sort(S.begin(), S.end());
		S.erase(unique(S.begin(), S.end()), S.end());
		rep(j, min(5, (signed)S.size()))ans.push_back(S[j]);
	}
	sort(ans.begin(), ans.end());
	ans.erase(unique(ans.begin(), ans.end()), ans.end());
	cout << ans[K - 1] << endl;
}

Measured memory_bytes: 1024
use std::cmp;

fn main() {
    let s = std::io::stdin();
    let mut sc = Scanner { stdin: s.lock() };
    let n: usize = sc.read();
    let mut count: Vec<usize> = vec![0; n];
    for _ in 0..n {
        let a = sc.read::<usize>() - 1;
        count[a] += 1;
    }

    let mut count_count = vec![0; n + 1];
    for count in count.into_iter() {
        count_count[count] += 1;
    }

    let mut rows = count_count
        .into_iter()
        .enumerate()
        .filter(|&(count, num)| count > 0 && num > 0)
        .collect::<Vec<_>>();
    rows.sort();
    let mut ans = vec![0; n + 1];
    let mut sum = rows.iter().map(|&(count, num)| count * num).sum::<usize>();
    let mut popped = 0;
    for height in (1..(n + 1)).rev() {
        while let Some((max, num)) = rows.pop() {
            if max >= height {
                sum -= max * num;
                popped += num;
            } else {
                rows.push((max, num));
                break;
            }
        }

        let columns = sum / height + popped;
        ans[columns] = cmp::max(ans[columns], height);
    }
    for k in (0..n).rev() {
        ans[k] = cmp::max(ans[k], ans[k + 1]);
    }

    for k in 1..(n + 1) {
        println!("{}", ans[k]);
    }
}

pub struct Scanner<R> {
    stdin: R,
}

impl<R: std::io::Read> Scanner<R> {
    pub fn read<T: std::str::FromStr>(&mut self) -> T {
        use std::io::Read;
        let buf = self
            .stdin
            .by_ref()
            .bytes()
            .map(|b| b.unwrap())
            .skip_while(|&b| b == b' ' || b == b'\n')
            .take_while(|&b| b != b' ' && b != b'\n')
            .collect::<Vec<_>>();
        unsafe { std::str::from_utf8_unchecked(&buf) }
            .parse()
            .ok()
            .expect("Parse error.")
    }
    pub fn vec<T: std::str::FromStr>(&mut self, n: usize) -> Vec<T> {
        (0..n).map(|_| self.read()).collect()
    }
    pub fn chars(&mut self) -> Vec<char> {
        self.read::<String>().chars().collect()
    }
}


Measured memory_bytes: 12540
#include <cstdio>
#include <cctype>
#include <utility>
#include <vector>
#include <algorithm>
using namespace std;

const auto gcu = getchar_unlocked;
const auto pcu = putchar_unlocked;
#define _T template <typename T>
#define _HT template <typename H, typename... T>
#define _il inline
#define _sc _il bool scan
_T T in(int c){T n=0;int m=1;while(isspace(c)){c=gcu();}if(c=='-')m=-1,c=gcu();
	do{n=10*n+(c-'0'),c=gcu();}while(c>='0'&&c<='9');return m*n;}
_il int in() {return in<int>(gcu());}
_T T scan(T &n){int c=gcu();return c==EOF?false:(n=in<T>(c),true);}
_sc(char &c){c=gcu();gcu();return c!=EOF;}
#ifdef _GLIBCXX_STRING
_sc(string &s){int c;s="";
	for(;;){c=gcu();if(c=='\n'||c==' ')return true;else if(c==EOF)return false;s+=c;}}
#endif
_HT _sc(H &h, T&&... t){return scan(h)&&scan(t...);}
#define _ot _il void out
#define _ol _il void outl
_ot(bool b) {pcu('0'+b);}
_ot(const char *s){while(*s)pcu(*s++);}
_ot(char c){pcu(c);}
#ifdef _GLIBCXX_STRING
_ot(string s){for(char c:s)pcu(c);}
#endif
_T _ot(T n){static char b[20];char *p=b,m=n<0?pcu('-'),-1:1;
	if(!n)*p++='0';else while(n)*p++=n%10*m+'0',n/=10;while(p!=b)pcu(*--p);}
_ol(){out('\n');}
#ifdef _GLIBCXX_VECTOR
_T _ot(vector<T> &v){for(T &x:v)out(&x == &v[0]?"":" "),out(x);outl();}
#endif
_HT _ot(H&& h, T&&... t){out(h);out(move(t)...);}
template <typename... T> _ol(T&&... t){out(move(t)...);outl();}

int main() {
	for (int N, M; N = in(), M = in();) {
		vector<int> t(N), u;
		for (int &p: t)
			p = in();
		t.push_back(0);
		sort(t.begin(), t.end());
		for (auto i = t.begin(); i != t.end(); i++)
			for (auto j = i; j != t.end(); j++)
				if (*i + *j <= M)
					u.push_back(*i + *j);
		sort(u.begin(), u.end());
		u.erase(unique(u.begin(), u.end()), u.end());
		int r = 0;
		for (auto i = u.begin(), e = u.end() - 1; i <= e; i++) {
			for (; *i + *e >= M; e--)
				;
			if (*i + *e > r)
				r = *i + *e;
		}
		outl(r);
	}
}


Measured memory_bytes: 6256
#include<bits/stdc++.h>
using namespace std;
#define Mod(n) n % 1000000007
const int dx[8] = {1, 0, -1, 0, -1, 1, -1, 1};
const int dy[8] = {0, 1, 0, -1, 1, -1, -1, 1};


int main()
{
    long long A,B;
    cin >> A >> B;
    if(__gcd(A,B) == 1)
        cout << A * B << '\n';
    else
        cout << A * B / __gcd(A,B) << '\n';

}


Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.IOException;

public class Main {
    public static void main(String[] args) {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        try {
            int loop = Integer.parseInt(br.readLine());

            int[] nums = new int[loop];
            for(int i=0; i<loop; i++){
                nums[i] = Integer.parseInt(br.readLine());
            }
            
            int count = 0;
            for(int i=0; i<loop; i++){
                if(isPrime(nums[i])){
                    // System.out.println(String.valueOf(arr[i]));
                    count++;
                }
            }
            System.out.println(String.valueOf(count));
        } catch(IOException e){
            e.printStackTrace();
        }
    }
    
    static boolean isPrime(int x){
        if((x%2==0&&x!=2) || (x%3==0&&x!=3) || (x%5==0&&x!=5) || (x%7==0&&x!=7)){
            return false;
        }
        for(int i=2; i<(int)Math.sqrt(x)+1; i++){
            if(x%i==0){
                return false;
            }
        }
        return true;
    }
}



Measured memory_bytes: 30328
#include <cstdio>
#include <iostream>
#include <algorithm>
using namespace std;
typedef const int let;
#define rep(i,n) for(int i=0; i<(n); ++i)
#define reps(i,f,n) for(int i=(f); i<=(n); ++i)
#define outl(x) cout<< (x) << '\n'

int main()
{
   cin.tie(0), ios::sync_with_stdio(false);
   int N;
   int a[128];

   cin >> N;
   rep(i, N) {
      cin >> a[i];
   }

   sort(a, a+N);

   int x = 0, y =0;
   rep(i ,N) {
      if (i & 1) x += a[i];
      else y += a[i];
   }

   outl( abs(x - y) );
}




Measured memory_bytes: 256
#include <stdio.h>

typedef unsigned long long int ULLI;

#define MAX 100001

ULLI input(int *, int);
ULLI work(int*, int,ULLI );

int main()
{
	ULLI sum = 0;
	int n, q;
	int data[MAX] = { 0 };

	scanf("%d", &n);
	sum=input(data, n);

	scanf("%d", &q);
	for (int i = 0; i < q; i++) {
		sum=work(data, n, sum);
		printf("%llu\n", sum);
	}

	return 0;
}

ULLI input(int *data, int n)
{
	ULLI sum = 0;
	int a;

	for (int i = 0; i < n; i++) {
		scanf("%d", &a);
		data[a - 1]++;
		sum += a;
	}

	return sum;
}

ULLI work(int *data, int n,ULLI sum)
{
	int a, b;
	ULLI dif=0;
	ULLI count = 0;

	scanf("%d %d", &a, &b);
	dif = b - a;

	count = data[a - 1];

	if (data[a - 1] != 0) {
		data[b - 1] += count;
		data[a - 1] = 0;
	}

	sum += count * dif;

	return sum;
}

Measured memory_bytes: 2120
#include <bits/stdc++.h>
using namespace std;
#define REP(i,n) for(int i=0;i<(n);i++)
#define N 100000
typedef long long ll;
#define ALL(v) (v).begin(),(v).end()
#define SZ(x) int(x.size())
#define OUT(a) cout<<(a)<<endl
#define VECIN(type, c, n) vector<type> c(n);for(auto& i:c) cin>>i;

int main(){
	int n;
    cin>>n;
    vector<int> a(n);
    
    REP(i,n){
        cin>>a[i];
    }
    int ans=0;
    REP(i,n){
        if(a[i]==(i+1)){
            if(i==n-1){
                swap(a[i],a[i-1]);
            }else{
                swap(a[i],a[i+1]);
            }
            ans++;
            i++;
        }
    }
    OUT(ans);
	return 0;
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
#define sz(arr) (int)arr.size()
#define all(arr) arr.begin(), arr.end()

using namespace std;

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

  string s = "Christmas";
  for (; d < 25; d++) s += " Eve";

  puts(s.c_str());

  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
char s[200005];
int a[256];
int main()
{
    scanf("%s",s);
    int l=strlen(s);
    long long ans=1;
    for(int i=0;i<l;i++)
    ans+=i-a[s[i]],a[s[i]]++;
    cout<<ans;
    return 0;
}


Measured memory_bytes: 384
import java.util.Arrays;
import java.util.List;
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		// 標準入力
		Scanner sc = new Scanner(System.in);

		String line1 = sc.nextLine();

		List<String> rates = Arrays.asList(line1.split(","));

		System.out.println(rates.get(0) + " " + rates.get(1) + " " + rates.get(2));

	}

}

Measured memory_bytes: 21588
#include <stdio.h>
int main(void)
{
    int n,i,j;
    scanf("%d",&n);
    for(i=1;i<=n;i++){
        if(i%3==0){
            printf(" %d",i);
        }else{
            for(j=i;j;j/=10){
                if(j%10==3){
                    printf(" %d",i);
                    break;
                }
            }
        }
    }
	printf("\n");
    return 0;
}

Measured memory_bytes: 600
#include <iostream>
#include <string>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <numeric>

using namespace std;

int main() {
    int N,m;
    cin >> N;
    m = N;
    vector<int> a;
    int Max = 0;
    while(N--){
        int x;
        scanf("%d",&x);
        
        //if(find(a.begin(),a.end(),x) == a.end() || (Max < x)){
        a.push_back(x);
            //Max = max(x,Max);
        //}else{
            //a.erase(find(a.begin(),a.end(),x));
        //}
        
    }
    sort(a.begin(),a.end());
    long big = 0,small = 0;
    for(int i=m-2; i>=0;--i){
        if(a[i] == a[i+1]){
            big = a[i];
            a.erase(a.begin()+i);
            a.erase(a.begin()+i);
            break;
        }
        
    }
    for(int i=m-4; i>=0;--i){
        if(a[i] == a[i+1]){
            small = a[i];
            
            break;
        }
        
    }
    /*
    for(int i=0; i<m;i++){
        if(a[i] == i+1){
            Max++;
        }
        
    }*/
    cout << big*small << endl;
    return 0;
}


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

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

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

#define DEBUG(x) cout << #x << ": " << (x) << endl
#define DEBUG_VEC(v) cerr<<#v<<": ";REP(__i,(v).size())cerr<<((v)[__i])<<", ";cerr<<endl
#define PRINT(x) cout << x << endl
#define all(x) x.begin(),x.end()

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

    string s = to_string(N);
    int digit = s.size();

    vector<vi> P(10,vi(10,0));
    //P[head][tail]=何パターンあるか

    for(int i=1;i<=N;i++){
        int head,tail;
        tail = i%10;
        int digit = floor(log10(i))+1;
        if(i<10) head = tail;
        else head = i/int(pow(10,digit-1));
        P[head][tail]++;
    }

    ll ans =0;

    for(int i=1;i<=9;i++){
        for(int j=1;j<=9;j++){
           ans+=P[i][j]*P[j][i];
        }
    }

    cout << ans << endl;

}



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

#define mp make_pair
#define mt make_tuple
#define fi first
#define se second
#define pb push_back
#define eb push_back
#define endl '\n'
#define all(x) (x).begin(), (x).end()
#define output(x) cout<<x<<endl;
#define fre(i, a, b) for (int i = (int)(a); i <= (int)(b); ++i)
#define frd(i, a, b) for (int i = (int)(a); i >= b; --i)

using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<pair<int,int> > vpi;
typedef vector<vi> vvi;
typedef long long i64;
typedef vector<i64> vi64;
typedef vector<vi64> vvi64;
typedef pair<i64, i64> pi64;
typedef double ld;
const ll mod=1e9+7;
const int maxn = 1<<18;

ll dp[maxn],a[20][20];

ll g(int mask){
	vi v;
	for (int i = 0; i < 17; ++i)
	{
		if((mask&(1<<i))) v.pb(i);
	}
	int k=v.size();
	ll ans=0;
	for (int i = 0; i < k; ++i)
	{
		for (int j = i+1; j < k; ++j)
		{
			ans+=a[v[i]][v[j]];
		}
	}
	return ans;
}

ll f(int mask){
	if(mask==0) return 0;
	if(dp[mask]!=-ll(4e18)) return dp[mask];
	dp[mask]=g(mask);
	for(int i=(mask-1)&mask; i>0; i=(i-1)&mask){
		dp[mask] = max(dp[mask] , f(i) + f(mask^i));
	}
	return dp[mask];
}

int main(){
	cin.tie(0);ios_base::sync_with_stdio(0);	
	int n;
	cin>>n;
	for (int i = 0; i < n; ++i)
	{
		for (int j = 0; j < n; ++j)
		{
			cin>>a[i][j];
		}
	}
	for (int i = 0; i < maxn; ++i)
	{
		dp[i]=-4e18;
	}
	output(f((1<<n)-1));
	return 0;
}

Measured memory_bytes: 2304
let (n1, n2, n_limit) = (4, 16, 45)

let area =
  [| [1; 4]; [0; 2; 5]; [1; 3; 6]; [2; 7]
   ; [0; 5; 8]; [1; 4; 6; 9]; [2; 5; 7; 10]; [3; 6; 11]
   ; [4; 9; 12]; [5; 8; 10; 13]; [6; 9; 11; 14]; [7; 10; 15]
   ; [8; 13]; [9; 12; 14]; [10; 13; 15]; [11; 14] |]

let goal = Array.init n2 (fun i -> (i + 1) mod n2)

let md = Array.make_matrix n2 n2 0

let initialize_md () =
  for i = 0 to n2 - 2 do
    for j = 0 to n2 - 1 do
      md.(i+1).(j) <- abs (i / n1 - j / n1) + abs (i mod n1 - j mod n1)
    done
  done

let idastar a limit space lower =
  let rec doit i space moved lower =
    if i = limit then
      if a <> goal then ()
      else begin
        Printf.printf "%d\n" limit;
        exit 0;
      end
    else
      List.iter (fun j ->
        let x = a.(j) in
        if x = moved then ()
        else
          let lower = lower - md.(x).(j) + md.(x).(space) in
          if lower + i > limit then ()
          else begin
            a.(j) <- 0;
            a.(space) <- x;
            doit (i + 1) j x lower;
            a.(j) <- x;
            a.(space) <- 0;
          end)
      area.(space) in
  doit 0 space (-1) lower

let findi a x =
  let n = Array.length a in
  let rec doit i =
    if i = n then assert false
    else if a.(i) = x then i
    else doit (i + 1) in
  doit 0

let () =
  initialize_md ();
  let a = Array.init n2 (fun _ -> Scanf.scanf "%d " (fun i -> i)) in
  let space = findi a 0 in
  let lower =
    Array.fold_left (fun (i, sum) e -> (i + 1, sum + md.(e).(i))) (0, 0) a |> snd in
  for limit = lower to n_limit do
    idastar a limit space lower
  done

Measured memory_bytes: 4444
#include <bits/stdc++.h>
#define INF 1000000000
using namespace std;

int main() {

string A,B;
  cin>>A>>B;
  for(int i=0;i<A.size();i++){
    A.push_back(A.at(0));
    A.erase(A.begin());
    if(A==B){cout<<"Yes"<<endl;break;}
    if(i==A.size()-1){cout<<"No"<<endl;}}
}


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

/*2進数配列+1*/
vector<int> twoadd(vector<int> v, int N){
    v[N-1]+=1;
    int ind = N-1;
    int j=N-1;
    for(j=N-1;j>=1;j--){
        if(v[j]>1){
            v[j-1]+=1;
            v[j]=0;
        }
    }
    return v;
}

/*フィボナッチ*/
long long fibonatti(long long d){
    long long count = 0;
    long long f1 = 1;
    long long f2 = 1;/*ここを変える*/
    long long temp;
    if(d == 1){
        count = f1;
    }else if(d == 2){
        count = f2;
    }else if(d==0){
        count = 1;
    }else{
        for(int i=0;i<d-2;i++){
            temp = f1+f2;
            f1 = f2;
            f2 = temp;
        }
        count = temp;
    }
    return count;
}

/*最大公約数*/
unsigned long long GCD(long long L,long long R){
    if(L>R){
        long long temp=R;
        R = L;
        L = temp;
    }
    unsigned long long pp=0,ppt=0;
    unsigned long long ans=0;
    if(R%L==0){
        ans = L;
    }else{
        while(true){
            ppt = pp;
            pp=R%L;
            if(pp == 0){
                ans = ppt;
                break;
            }
            R = L;
            L = pp;
        }
    }    
    return ans;    
}

/*最小公倍数*/
unsigned long long LCM(long long L,long long R){
    unsigned long long ans;
    unsigned long long gcd = GCD(L,R);
    ans = (L/gcd)*R;
    return ans;
}

/*Combination set*/
#define mod 1000000007
#define maxcomb 3000/*大きいものを求めるときはここを変える*/
vector<long long> fc(maxcomb+1);
vector<long long> ifc(maxcomb+1);
long long modpow(long long x,long long n){
    long long ans = 1;
    while(n > 0){
        if(n & 1) {
            ans = ans*x%mod;
        }
        x = x*x%mod;
        n >>= 1;
    }
    return ans;
}
void Conb(){
    fc[0]= 1;
    ifc[0]=1;
    for(long long i=0;i<maxcomb;i++){
        fc[i+1] = fc[i]*(i+1)%mod;//n!(mod)
        ifc[i+1] = ifc[i]*modpow(i+1,mod-2)%mod;//k!^{M-2} (mod)
    }
}
unsigned long long Combination(long long L,long long R){
    unsigned long long up=1,ans;
    Conb();
    if(L==0&&R==0){
        return 1;
    }else if(L<R||L<0){
        return 0;
    }else{
        long long t = ifc[L-R]*ifc[R]%mod;
        ans = t*fc[L]%mod;
    }
    return ans;
}
/*Combination set ここまで*/

/*ここから*/
int main() {
    int N,D;
    cin >> N >> D;
    int count = 0;
    vector<vector<double>> x(N,vector<double>(D));
    for(int i=0;i<N;i++){
        for(int j=0;j<D;j++){
            cin >> x[i][j];
        }
    }
    for(int i=0;i<N-1;i++){
        for(int j=i+1;j<N;j++){
            double ans = 0;
            int ans1 = 0;
            for(int k=0;k<D;k++){
                ans += (x[i][k]-x[j][k])*(x[i][k]-x[j][k]);
            }
            ans = sqrt(ans);
            ans1 = ans;
            //cout << ans1 << endl;
            ans = ans-ans1;
            //cout << ans << endl;
            if(ans==0){
                count++;
            }
        }
    }
    cout << count << endl;
    return 0;
}

Measured memory_bytes: 3632
#include <stdio.h>
#include <ctype.h>
#include <stdlib.h>
 
int main()
{
    int b, f, r, v;;
    int house[5][4][11];
    int i, n;
 
    for (b = 1; b <= 4; b++) {
        for (f = 1; f <= 3; f++) {
            for (r = 1; r <= 10; r++) house[b][f][r] = 0;
        }
    }
    scanf("%d", &n);
    for (i = 0; i < n; i++) {
        scanf("%d%d%d%d", &b, &f, &r, &v);
        house[b][f][r] += v;
    }
 
    for (b = 1; b <= 4; b++) {
        for (f = 1; f <= 3; f++) {
            for (r = 1; r <= 10; r++) printf(" %d", house[b][f][r]);
            putchar('\n');
        }
        if (b < 4) puts("####################");
    }
    return 0;
}




Measured memory_bytes: 2052
#include<iostream>
#include<algorithm>
#include<vector>
#include<functional>
#include<string>
#include<cmath>
#include<map>
#include<set>
#include<queue>
#include<stack>
#include<cstdio>
using namespace std;
using ll = long long;
int main(){
  int n;
  cin >> n;
  vector<int> a(n);
  for(int i = 0; i < n; i++) {
    cin >> a[i];
  }
  int ans = 0;
  for(int i = 0; i < n; i++) {
    if(a[i] == i + 1){
      ans++;
      if(i < n - 1 && a[i + 1] == i + 2){
        a[i + 1] = i + 1;
        
      }
    }
  }
  cout << ans << '\n';

  return 0;
}

Measured memory_bytes: 640
import sys
sys.setrecursionlimit(10**6)



N = int(input())

T = [[]for i in range(N)]

for i in range(N):
	a = int(input())
	for j in range(a):
		x,y = map(int,input().split())
		T[i].append([x-1,y])


ans = 0
def judge():
	global ans
	f=True
	for i in range(N):
		if l[i]==1:
			for g in T[i]:
				if l[g[0]] != g[1]:
					f=False
					break

	if f:
		ans = max(ans, sum(l))





def dfs(x):
	if x>=N:
		judge()
		return

	l[x] = 1
	dfs(x+1)
	l[x] = 0
	dfs(x+1)

l=[0]*N
dfs(0)
print(ans)


Measured memory_bytes: 3064
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <vector>
#include <cmath>
#include <queue>

#define endl '\n'
#define fi first
#define se second
#define pb push_back
#define debug(x) cout << "[debug] " << #x << ": " << x << endl
using namespace std;
typedef long long ll;
typedef pair<int, int> PII;
const int MOD = 1e9 + 7;
const int maxn = 1e6 + 5;
const int inf = 0x3f3f3f3f;
const ll INF = 0x3f3f3f3f3f3f3f3f;
const double eps = 1e-8;

int main() {
    string s; cin >> s;
    int a, b, c, d;
    a = (int)(s[0] - '0');
    b = (int)(s[1] - '0');
    c = (int)(s[2] - '0');
    d = (int)(s[3] - '0');
    int x = a * 10 + b;
    int y = c * 10 + d;
    if(x > 0 && x <= 12 && y > 0 && y <= 12) cout << "AMBIGUOUS" << endl;
    else if((x > 0 && x < 13) && (y < 1 || y >12))
            cout << "MMYY" << endl;
    else if((x < 1 || x > 12) && (y > 0 && y < 13))
            cout << "YYMM" << endl;
    else cout << "NA" << endl;
	return 0;
}

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

int main() {
    int A, B; cin >> A >> B;
    for (int i = 1; i <= 1000; i++) {
        int x = i * 0.08;
        int y = i * 0.1;
        if (x == A && y == B) {
            cout << i << endl;
            return 0;
        }
    }
    cout << -1 << endl;
}

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

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        String s = sc.next();
        int count = 0;
        for(int i = 0;i < s.length()/2;i++){
            if(s.charAt(i) != s.charAt(s.length()-1-i)){
                count += 1;
            }
        }
        System.out.println(count);
    }
}

Measured memory_bytes: 35572
N = int(input())
A = list(map(int, input().split()))

ans = 0
f = True
while f:
    f = False
    for i in range(N - 1, 0, -1):
        if A[i-1] > A[i]:
            A[i], A[i-1] = A[i-1], A[i]
            ans += 1
            f = True
s = ''
for a in A:
    s += str(a) + ' '
print(s.rstrip())
print(ans)



Measured memory_bytes: 5600
#include<bits/stdc++.h>
using namespace std;
int main()
{
	int n,m;
	int a[110],b[110];
	b[0]=0;
	cin>>n>>m;
	for(int i=1;i<=n;i++)
	{
		cin>>a[i];
		b[i]=b[i-1]+a[i];
	}
	int sum=0;
	for(int i=0;i<=n;i++)
	{
		if(b[i]<=m)sum++;
		else break;
	}
	cout<<sum<<endl;
	return 0;
 } 
 

Measured memory_bytes: 256
[N,M] = list(map(int,input().split()))
AB = []
for i in range(N):
    [A,B] = list(map(int,input().split()))
    AB.append([A,B])

AB.sort(key=lambda x:x[0],reverse=False)

t=0
cnt=0
while M>0:
    A = AB[t][0]
    B = AB[t][1]
    if M>B:
        M = M-B
        cnt+=A*B
        t+=1
    else:
        cnt += A*M
        M = 0

print(cnt)

Measured memory_bytes: 63424
n,a,b=map(int,input().split())
cnt=0
for i in range(1,n+1):
  ans=0
  i=str(i)
  for j in range(len(i)):
    x=int(i[j])
    ans+=x
  if a<=ans<=b:
    i=int(i)
    cnt+=i
    

print(cnt)


Measured memory_bytes: 9184
#include <bits/stdc++.h>
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()
#define rep(i,n) for (int i=0;i<(int)(n);i++)
#define codefor int test;scanf("%d",&test);while(test--)
#define INT(...) int __VA_ARGS__;in(__VA_ARGS__)
#define LL(...) ll __VA_ARGS__;in(__VA_ARGS__)
#define yn(ans) if(ans)printf("Yes\n");else printf("No\n")
#define YN(ans) if(ans)printf("YES\n");else printf("NO\n")
#define vector1d(type,name,...) vector<type>name(__VA_ARGS__)
#define vector2d(type,name,h,...) vector<vector<type>>name(h,vector<type>(__VA_ARGS__))
#define umap unordered_map
#define uset unordered_set
using namespace std;
using ll = long long;
const int MOD=1000000007;
//入力系
void scan(int& a){scanf("%d",&a);}
void scan(long long& a){scanf("%lld",&a);}
template<class T> void scan(T& a){cin>>a;}
template<class T> void scan(vector<T>& vec){for(auto&& it:vec)scan(it);}
void in(){}
template <class Head, class... Tail> void in(Head& head, Tail&... tail){scan(head);in(tail...);}
//出力系
void print(const int& a){printf("%d",a);}
void print(const long long& a){printf("%lld",a);}
void print(const double& a){printf("%.15lf",a);}
template<class T> void print(const T& a){cout<<a;}
template<class T> void print(const vector<T>& vec){if(vec.empty())return;print(vec[0]);for(auto it=vec.begin();++it!= vec.end();){putchar(' ');print(*it);}}
void out(){putchar('\n');}
template<class T> void out(const T& t){print(t);putchar('\n');}
template <class Head, class... Tail> void out(const Head& head,const Tail&... tail){print(head);putchar(' ');out(tail...);}
//デバッグ系
template<class T> void dprint(const T& a){cerr<<a;}
template<class T> void dprint(const vector<T>& vec){if(vec.empty())return;cerr<<vec[0];for(auto it=vec.begin();++it!= vec.end();){cerr<<" "<<*it;}}
void debug(){cerr<<endl;}
template<class T> void debug(const T& t){dprint(t);cerr<<endl;}
template <class Head, class... Tail> void debug(const Head& head, const Tail&... tail){dprint(head);cerr<<" ";debug(tail...);}
ll intpow(ll a, ll b){ ll ans = 1; while(b){ if(b & 1) ans *= a; a *= a; b /= 2; } return ans; }
ll modpow(ll a, ll b, ll p){ ll ans = 1; while(b){ if(b & 1) (ans *= a) %= p; (a *= a) %= p; b /= 2; } return ans; }
ll updivide(ll a,ll b){if(a%b==0) return a/b;else return (a/b)+1;}

bool kaibunhantei(string s){
    int l=0,r=s.length()-1;
    while(l<r){
        if(s[l]==s[r]){
            l++;
            r--;
        }else{
            return false;
        }
    }
    return true;
}

int main(){
    string s;
    cin>>s;
    yn(kaibunhantei(s)&&kaibunhantei(s.substr(0,(s.length()-1)/2))
    &&kaibunhantei(s.substr((s.length()+3)/2-1,s.length()-(s.length()+3)/2+2)));
}

Measured memory_bytes: 3612
function main() {
  var
  c1 = 0, c2 = 0;
  input.forEach(function(line) {
    if(line.trim() === '') return;
    line = line.split(',').map(parseFloat);
    if(line[0]*line[0] + line[1]*line[1] === line[2]*line[2]){
      c1++;
    }else if(line[0] === line[1]) {
      c2++;
    }
  });
  console.log('%d\n%d', c1, c2);
}

var
input = '';

process.stdin.resume();
process.stdin.setEncoding('utf8');
process.stdin.on('data', function(chunk) {
  input += chunk;
});
process.stdin.on('end', function() {
  input = input.split('\n');
  main();
});

Measured memory_bytes: 7652
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
using pint = pair<int,int>;
ll mod = 1000000007;
int dx[8] = {1,0,-1,0,1,1,-1,-1};
int dy[8] = {0,1,0,-1,1,-1,1,-1};
void chmin(long long &a, long long b) { if (a > b) a = b; }
const long long INF = 1LL<<60;
ll gcd(ll a,ll b){
    if(b == 0) return a;
    else return gcd(b,a%b);
}
int l[2100][2100],r[2100][2100],up[2100][2100],down[2100][2100];
int main() {
    int h,w,ans = 0;
    cin >> h >> w;
    vector<string> s(h);
    for (int i = 0; i < h; ++i) {
        cin >> s[i];
    }
    for (int i = 0; i < h; ++i) {
        int tmp = 0;
        for (int j = 0; j < w; ++j) {
            if(s[i][j] == '#') tmp = 0;
            else tmp++;
            l[i][j] = tmp;
        }
    }
    for (int i = 0; i < h; ++i) {
        int tmp = 0;
        for (int j = w-1; j >= 0; --j) {
            if(s[i][j] == '#') tmp = 0;
            else tmp++;
            r[i][j] = tmp;
        }
    }
    for (int j = 0; j < w; ++j) {
        int tmp = 0;
        for (int i = 0; i < h; ++i) {
            if(s[i][j] == '#') tmp = 0;
            else tmp++;
            up[i][j] = tmp;
        }
    }
    for (int j = 0; j < w; ++j) {
        int tmp = 0;
        for (int i = h-1; i >= 0; --i) {
            if(s[i][j] == '#') tmp = 0;
            else tmp++;
            down[i][j] = tmp;
        }
    }

    for (int i = 0; i < h; ++i) {
        for (int j = 0; j < w; ++j) {
            if(s[i][j] == '#') continue;
            ans = max(ans,l[i][j]+r[i][j]+down[i][j]+up[i][j]-3);
        }
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 72448
{-# LANGUAGE OverloadedStrings #-}
module Main where

import           Data.List
import           Control.Monad
import           Debug.Trace
import qualified Data.ByteString.Char8         as BC
import           Data.Maybe                     ( fromJust )
import qualified Data.Set                      as S
import qualified Data.IntMap.Strict            as IM
import qualified Data.Map.Strict               as M
import           Data.Char


readTuple2 :: IO (Int, Int)
readTuple2 = do
    [a, b] <- map (fst . fromJust . BC.readInt) . BC.words <$> BC.getLine
    return (a, b)

readTuple3 :: IO (Int, Int, Int)
readTuple3 = do
    [a, b, c] <- map (fst . fromJust . BC.readInt) . BC.words <$> BC.getLine
    return (a, b, c)

readInt :: IO Int
readInt = fst . fromJust . BC.readInt <$> BC.getLine

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

split :: (a -> Bool) -> [a] -> [[a]]
split f [] = []
split f as =
    let (fo, la) = span f as
        las      = case la of
            [] -> []
            xs -> split f $ tail xs
    in  case fo of
            [] -> las
            xs -> xs : las

isNum :: Int -> Bool
isNum a 
    | a `mod` 5 == 0 = False
    | a `mod` 3 == 0 = False
    | otherwise = True

solve :: Int -> Int
solve k = sum $ do
    a <- [1..k]
    b <- [1..k]
    let g = gcd a b
    c <- [1..k]
    pure $ gcd g c

main = do
    k <- readInt
    print $ solve k





Measured memory_bytes: 3812
#include<bits/stdc++.h>
///...................................*****.................................................///
///        Author :  MD. Rakibul Islam ( mmdrakibul2912@gmail.com )                         ///
///                  Department of Computer Science                                         ///
///                  & Engineering,                                                         ///
///                  Comilla University , Bangladesh.                                       ///
///...................................*****.................................................///
#define lli long long int
using namespace std;
int main()
{
    int n, m, i, j, k, l;
    cin>>n;
    int a[n+2];
    for(i=0; i<n; i++)
    {
        cin>>a[i];
    }
    lli sum=0;
    for(i=0; i<n-1; i++)
    {
        for(j=i+1; j<n; j++)
        {
            sum+=(a[i]*a[j]);
        }
    }
    cout<<sum<<endl;
    return 0;
}


Measured memory_bytes: 256
#include <cstdio>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <cstdlib>
using namespace std;
typedef long long LL;
const int Maxn = 1e5 + 5;
int main ()
{
	int x,y,z;
	scanf("%d%d%d",&x,&y,&z);
	if ((x-z)%(y+z) == 0) printf("%d",x/(y+z));
	else printf("%d",x/(y+z)-1);
	return 0;
}

Measured memory_bytes: 128
package main

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

func main() {
	N := nextInt()
	ss := make([]int, N)
	var total int
	for i := 0; i < N; i++ {
		ss[i] = nextInt()
		total += ss[i]
	}

	dp := make([][]bool, N+1)
	for i := 0; i <= N; i++ {
		dp[i] = make([]bool, total+1)
	}
	dp[0][0] = true
	for i := 0; i < N; i++ {
		for j := 0; j <= total; j++ {
			if dp[i][j] {
				dp[i+1][j] = true
				dp[i+1][j+ss[i]] = true
			}
		}
	}
	var ans int
	for score, ok := range dp[N] {
		if ok && score%10 != 0 {
			ans = max(ans, score)
		}
	}
	fmt.Println(ans)
}

// Input. ----------

var sc = bufio.NewScanner(os.Stdin)

func init() {
	sc.Buffer([]byte{}, math.MaxInt64)
	sc.Split(bufio.ScanWords)
}

func nextInt() int {
	sc.Scan()
	i, err := strconv.Atoi(sc.Text())
	if err != nil {
		panic(err)
	}

	return i
}

func nextString() string {
	sc.Scan()
	if err := sc.Err(); err != nil {
		panic(err)
	}

	return sc.Text()
}

// ---------- Input.

// Util. ----------

func min(x, y int) int {
	return int(math.Min(float64(x), float64(y)))
}

func max(x, y int) int {
	return int(math.Max(float64(x), float64(y)))
}

// ---------- Util.


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

int curr[15];
int nums[15];
int abcd[55][4];
int n, m, q;
int ans;

void backtrack(int curr_ind, int nums_ind) {
    if (curr_ind >= n) {
        //for (int i = 0; i < curr_ind; i++)
            //cout << curr[i] << " ";
        //cout << endl;
        
        int temp_ans = 0;
        for (int i = 0; i < q; i++) {
            if (curr[abcd[i][1] - 1] - curr[abcd[i][0] - 1] == abcd[i][2])
                temp_ans += abcd[i][3];
        }
        
        ans = max(ans, temp_ans);
    }
    else if (nums_ind <= m) {
        for (int ind = nums_ind; ind <= m; ind++) {
            curr[curr_ind] = nums[ind];
            backtrack(curr_ind + 1, ind);
        }
    }
}

int main() {
    ans = 0;
    cin >> n >> m >> q;
    
    for (int i = 0; i < q; i++) {
        cin >> abcd[i][0] >> abcd[i][1] >> abcd[i][2] >> abcd[i][3];
    }
    
    for (int i = 0; i <= m; i++) {
        nums[i] = i;
    }
    
    backtrack(0, 1);
    cout << ans;
}


Measured memory_bytes: 3620
#include<bits/stdc++.h>
#define LL long long
#define mod 1000000007
#define maxn 25
using namespace std; 

int len(int x){
	int ret = 0;
	while(x){
		x = x / 10;
		ret++;
	}
	return ret;
}

int main(){
	string s;
	int n;
	cin >> n;
	int ans = 0;
	for(int i = 1; i <= n; ++i){
		if(len(i) % 2 == 1){
			ans++;
		}
	}
	cout << ans << endl;
	return 0;
}


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

using namespace std;

int arr[55];

int main() {
#ifndef ONLINE_JUDGE
    //freopen("input.txt", "r", stdin);
#endif
    int n, k;
    scanf("%d %d", &n, &k);
    for (int i = 0; i < n; i++)
        scanf("%d", arr + i);

    int res = 0;
    for (int taken = 1; taken <= min(k, n); taken++) {
        for(int pre=0; pre<=taken; pre++){
            vector<int> cur;
            for(int j =0; j<pre; j++){
                cur.push_back(arr[j]);
            }
            for(int j=n-1, cnt=1; cnt + pre <= taken; cnt++, j--){
                cur.push_back(arr[j]);
            }
            sort(cur.begin(), cur.end());
            int sum = 0;
            for(int i=cur.size()-1; i>=k-taken; i--){
                sum += cur[i];
            }
            res = max(res, sum);
            for(int i=min(k-taken-1, (int)cur.size()-1); i>=0; i--){
                sum += cur[i];
                res = max(res, sum);
            }
        }
    }
    printf("%d\n", res);
    return 0;
}

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

void trace(int a[], int n) {
  int i;
  for (i = 0; i < n; i++) {
    if (i != 0) cout << " ";
    cout << a[i];
  }
  cout << endl;
}

int selectionSort(int a[], int n) {
  int i, j, minj, swnum = 0;
  for (i = 0; i < n; i++) {
    minj = i;
    for (j = i; j < n; j++) {
      if (a[j] < a[minj]) minj = j;
    }
    swap(a[i], a[minj]);
    if (a[i] != a[minj]) swnum++;
  }
  return swnum;
}

int main(void) {
  int i, n, j, k, v;
  cin >> n;
  int a[n];
  for (i = 0; i < n; i++) cin >> a[i];
  int swnum = selectionSort(a, n);
  trace(a, n);
  cout << swnum << endl;
  return 0;
}

Measured memory_bytes: 1160
// Author : Nachiket Kanore
// Institute : PICT, Pune

/*
 * 	Heart beats fast
 * 		Colors and promises
 * 			How to be brave
 * 				How can I love when I am afraid to fall...
 */

#include <stdexcept>
#include <iostream>
#include <iomanip>
#include <sstream>
#include <fstream>
#include <cassert>
#include <cstring>
#include <cstdarg>
#include <cstdio>
#include <memory>
#include <random>
#include <cmath>
#include <ctime>
#include <unordered_map>
#include <unordered_set>
#include <functional>
#include <algorithm>
#include <complex>
#include <numeric>
#include <limits>
#include <bitset>
#include <vector>
#include <string>
#include <queue>
#include <deque>
#include <array>
#include <list>
#include <map>
#include <set>

using namespace std;

#define int long long
#define endl '\n'
#define rep(x,s,e) for(int x=s;x<=(e);x++)
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(), x.rend()
#define precise(x) cout << fixed << setprecision(x)
#define bits(x) __builtin_popcount(x)
#define pb push_back
#define mp make_pair
#define test int t; cin>>t; while(t--)
#define FAST                          \
    ios_base::sync_with_stdio(false); \
    cin.tie(NULL);                    \
    cout.tie(NULL)
 
 
typedef vector<int> vi;
typedef vector<pair<int,int>> vii;
typedef pair<int,int> pii;
 
const int mod = 1e9+7;
const int inf = 1e18;
const int N = 2e5+20;


int32_t main(){
    FAST;

    int sum =0;
    int mx = 0;
    test{
        int f;  cin >> f;
        sum += f;
        mx = max(mx , f);
    }

    cout << (sum - mx + mx/2) << '\n';
    
    return 0;
}

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

int main(){
  int n; cin >> n;
  int k; cin >> k;
  int q; cin >> q;
  int a[q]; for(int i = 0; i < q; i++) cin >> a[i];
  int ans[n]; for(int i = 0; i < n; i++) ans[i] = 0;
  
  for(int i = 0; i < q; i++){
    ans[a[i]-1] += 1;
  }
  
  for(int i = 0; i < n; i++){
    if((k - q + ans[i]) > 0) cout << "Yes" << endl;
    else cout << "No" << endl;
  }
}

Measured memory_bytes: 1408
#include<bits/stdc++.h>
using namespace std;
#define fs first
#define sc second
#define pb push_back
#define mp make_pair
#define eb emplace_back
#define ALL(A) A.begin(),A.end()
#define RALL(A) A.rbegin(),A.rend()
typedef long long LL;
typedef pair<LL,LL> P;
const LL mod=1000000007;
const LL LINF=1LL<<60;
const int INF=1<<30;



int main(){
    int n;cin >> n;
    vector<pair<double,P>> v;
    for (int i = 0; i < n; i++) {
        int x,y;cin >> x >> y;
        if(!x&&!y) continue;
        v.pb(mp(atan2(x,y),mp(x,y)));
    }
    sort(ALL(v));
    vector<LL> xcum(2*v.size()+1,0),ycum(2*v.size()+1,0);
    for (int i = 0; i < 2*v.size(); i++) {
        xcum[i+1] = xcum[i] + v[i%v.size()].sc.fs;
        ycum[i+1] = ycum[i] + v[i%v.size()].sc.sc;
    }
    double ans = 0.0;
    for (int i = 0; i <= v.size(); i++) {
        for (int j = i+1; j-i <= v.size(); j++) {
            LL xx = xcum[j] - xcum[i];
            LL yy = ycum[j] - ycum[i];
            ans = max(ans, sqrt(xx*xx+yy*yy));
        }
    }
    cout << setprecision(30) << ans << endl;
    return 0;
}



Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
 
typedef long long   ll;
typedef long double ld;
const int N  = 2e5+10;
const ll mod = 1e9+7;
const ll inf = 1e18;
 
#define fast            ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define pb              push_back
#define mp              make_pair
#define ub              upper_bound                 // first element >  val(itr)
#define lb              lower_bound                 // first element >= val(itr) 
#define all(x)          (x).begin(),(x).end()
#define reset(a,x)      memset(a,x,sizeof(a))       // x can be 0 or -1
#define leadzero(a)     __builtin_clz(a)            // count leading zeroes
#define trailzero(a)    __builtin_ctz(a)            // count trailing zeroes
#define bitcount(a)     __builtin_popcount(a)       // count set bits
#define test            int t; cin>>t; while(t--)
#define forn(i,a,e)     for(ll i = a; i < e; i++)
#define pii             pair<int,int>
#define pll             pair<ll,ll>
#define sp              <<" "<<

ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a;    }
ll powm(ll base,ll exp){ll ans=1;while(exp){if(exp&1) ans=(ans*base)%mod;exp>>=1,base=(base*base)%mod;}return ans;}
ll add(ll a,ll b)  { return (a%mod+b%mod)%mod;        }
ll sub(ll a, ll b) { return (a%mod+mod-b%mod)%mod;    }
ll mult(ll a,ll b) { return ((a%mod)*(b%mod))%mod;    }

int main()
{
    fast
    ll a,b;
    cin>>a>>b;

    ll ans=max(2*a-1,max(2*b-1,a+b));
    cout<<ans;
    return 0;
} 

Measured memory_bytes: 256
class Node
  def initialize(parent, key)
    @key = key
    @parent = parent
    @left = nil
    @right = nil
  end

  attr_accessor :left, :right, :parent
  attr_reader :key
end

require 'set'
class BinarySearchTree
  def initialize
    @first = nil
    @visited_node = []
    @keys = Set.new
  end

  def insert(node)
    unless @first.nil?
      current = @first
      until current.nil?
        node.parent = current
        if node.key < current.key
          current = current.left
        else
          current = current.right
        end
      end
    end
    if @first.nil?
      @first = node
    elsif node.key < node.parent.key
      node.parent.left = node
    else
      node.parent.right = node
    end
    @keys << node.key
  end

  def find(key)
    if @keys.include? key
      puts 'yes'
    else
      puts 'no'
    end
  end

  def preorder_tree_walk(node)
    @visited_node << node.key
    return if node.nil?
    preorder_tree_walk node.left unless node.left.nil?
    preorder_tree_walk node.right unless node.right.nil?
  end

  def inorder_tree_walk(node)
    return if node.nil?
    inorder_tree_walk node.left unless node.left.nil?
    @visited_node << node.key
    inorder_tree_walk node.right unless node.right.nil?
  end

  def print
    inorder_tree_walk @first
    puts " #{@visited_node.join ' '}"
    @visited_node = []
    preorder_tree_walk @first
    puts " #{@visited_node.join ' '}"
    @visited_node = []
  end
end

n = gets.to_i
tree = BinarySearchTree.new
n.times do
  input = gets.split ' '
  case input[0]
  when 'insert'
    tree.insert Node.new nil, input[1].to_i
  when 'find'
    tree.find input[1].to_i
  when 'print'
    tree.print
  end
end



Measured memory_bytes: 82176
#include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n - 1; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i <= n; i++)
#define FORR(i, m, n) for(int i = m; i >= n; i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
 
using ll = long long;
using vll = vector<ll>;
using vvll = vector<vector<ll>>;
using P = pair<ll, ll>;

int main(){
	string s;
    cin >> s;
    ll n = s.size(), res1 = 0, flg = 0;
    if(s[0] == '1'){
        s[0] = '0';
        res1++;
        flg++;
    }
    REP(i, n - 1){
        if(i % 2){
            if(s[i + 1] == '1') res1++;
        }
        else{
            if(s[i + 1] == '0') res1++;
        }
    }
    ll res2 = 0;
    if(flg) s[0] = '1';
    if(s[0] == '0'){
        s[0] = '1';
        res2++;
    }
    REP(i, n - 1){
        if(i % 2){
            if(s[i + 1] == '0') res2++;
        }
        else if(s[i + 1] == '1') res2++;
    }
    ll ans = min(res1, res2);
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 512