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

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

int main(int argc, char const *argv[])
{
    int N; cin >> N;
    string ans = "No\n";
    for(int i = 0; i <= N / 7; i++) {
        int sum7 = 7*i;
        if((N - sum7)%4 == 0) {
            ans = "Yes\n";
            break;
        }
    }
    cout << ans << "\n";
    return 0;
}


Measured memory_bytes: 256
import Data.Maybe
import Data.List

main = do
    k <- readLn :: IO Int
    let x = elemIndex 0 $ take k (iterate (\i -> (i * 10 + 7) `mod` k) (7 `mod` k))
    if x == Nothing
        then print $ -1
        else print $ (fromJust x) + 1


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

int main()
{
    int n;
    string s, t, ans = "";
    cin >> n >> s >> t;
    rep(i, n) {
        ans.push_back(s[i]);
        ans.push_back(t[i]);
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
import Foundation

let inputs = readLine()!.components(separatedBy: " ").map{ Int($0)! }
let A = inputs[0]
let B = inputs[1]
let C = inputs[2]
let D = inputs[3]

var ARemain = A
var CRemain = C

for i in 1...100 {
    CRemain = CRemain - B
    
    if CRemain <= 0 {
        print("Yes")
        break
    }
    ARemain = ARemain - D
    
    if ARemain <= 0 {
        print("No")
        break
    }
    
}

Measured memory_bytes: 14076
#include <bits/stdc++.h>
#define ll long long


using namespace std;

const ll mod = 1e9 + 7;

vector<int> filho[100005];
ll dp[100005][2];


ll dfs(int pai, int cor, int pos)
{

	if(dp[pos][cor] > 0)
		return dp[pos][cor];

	for (int i = 0; i < (int)filho[pos].size(); ++i)
	{
		int viz = filho[pos][i];
		ll valor = 0;
		if(viz != pai)
		{
			if(cor == 0) // put color = white
			{
				valor += (dfs(pos, 0, viz) % mod);
				valor += (dfs(pos, 1, viz) % mod);
			}
			else if(cor == 1) // put color = black
			{
				valor += (dfs(pos, 0, viz) % mod);
			}

			//tem q multiplicar os resultados
			if(dp[pos][cor] == 0)	
				dp[pos][cor] = valor;
			else
				dp[pos][cor] = (dp[pos][cor] * valor) % mod;
		}
		
	}


	//se é folha
	if(dp[pos][cor] == 0)
		return dp[pos][cor] = 1;
	
	return dp[pos][cor];

}



	

int main()
{

	int n, u, v;
	cin >> n;

	
	memset(dp, 0, sizeof(dp));

	for (int i = 0; i < n - 1; ++i)
	{
		cin >> u >> v;

		filho[u].push_back(v);
		filho[v].push_back(u);
	}

	ll resp = (dfs(-1, 0, 1) + dfs(-1, 1, 1)) % mod;

	

	cout << resp << endl;





    return 0;
}

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

int main() {
  int N, M, X;
  cin >> N >> M >> X;
  int num = 0;
  for (int i = 0; i < M; ++i) {
    int A;
    cin >> A;
    if (A < X) ++num;
  }
  cout << min(num, M - num) << endl;
}

Measured memory_bytes: 3584
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.HashSet;
import java.util.Set;

public class Main {

	public static void main(String[] args) throws Exception {
        // TODO ?????????????????????????????????????????????
		
		try (BufferedReader br = new BufferedReader(new InputStreamReader(System.in))) {
            String line;
            int n=0,i=0;
            boolean first=true;
            Set<String> set=new HashSet<String>();
            while ((line = br.readLine()) != null) {
             	if(first){
            		n=Integer.parseInt(line);
            		i=0;
            		first=false;
            	}else{
            		String[] str=line.split(" ");
            		if(str[0].equals("insert")){
            			set.add(str[1]);
            		}else{
            			System.out.println(set.contains(str[1])?"yes":"no");
            		}
            		i++;
            		if(i==n){
            			break;
            		}
            	}
            }
        }
	}

}

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

int main() {
  string S;
  cin >> S;
  int ones = 0;
  int num = 1;
  bool f = false;
  for(char s: S) {
    if(!f) {
      if(s == '1') ones++;
      else {
        num = s - '0';
        f = true;
      }
    }
  }

  int k;
  cin >> k;
  if(k <= ones) cout << 1 << endl;
  else cout << num << endl;
}


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

#define repeat(i,n) for (int i = 0; i < n; ++i)
#define repeat1_eq(i,n) for (int i = 1; i <= n; ++i)

#define MAX_N 50000
#define MAX_M 20
int n, m;
int d[MAX_M];
int dp[MAX_N+1];

int main() {
    cin >> n >> m;
    repeat (i,m) cin >> d[i];
    dp[0] = 0;
    repeat1_eq (i,n) {
        dp[i] = MAX_N;
        repeat (j,m) {
            int ix = i - d[j];
            if (0 <= ix) dp[i] = min(dp[i], dp[ix]+1);
        }
    }
    cout << dp[n] << endl;
    return 0;
}

Measured memory_bytes: 1356
#include <bits/stdc++.h>
#define reg register
#define ll long long
#define ull unsigned long long
#define db double
#define pi pair<int, int>
#define pl pair<ll, ll>
#define vi vector<int>
#define vl vector<ll>
#define vpi vector<pi>
#define vpl vector<pl>
#define pb push_back
#define er erase
#define SZ(x) (int) x.size()
#define lb lower_bound
#define ub upper_bound
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define mkp make_pair
#define dmin(x, y) ((x) < (y) ? (x) : (y))
#define dmax(x, y) ((x) > (y) ? (x) : (y))
#define checkmax(x, y) ((x) < (y) ? ((x) = (y)) : (x))
#define checkmin(x, y) ((x) > (y) ? ((x) = (y)) : (x))
#define ms(data_name) memset(data_name, 0, sizeof(data_name))
#define msn(data_name, num) memset(data_name, num, sizeof(data_name))
#define For(i, j) for(reg int (i) = 1; (i) <= (j); ++(i))
#define For0(i, j) for(reg int (i) = 0; (i) < (j); ++(i))
#define Forx(i, j, k) for(reg int (i) = (j); (i) <= (k); ++(i))
#define Forstep(i , j, k, st) for(reg int (i) = (j); (i) <= (k); (i) += (st))
#define fOR(i, j) for(reg int (i) = (j); (i) >= 1; (i)--)
#define fOR0(i, j) for(reg int (i) = (j) - 1; (i) >= 0; (i)--)
#define fORx(i, j, k) for(reg int (i) = (k); (i) >= (j); (i)--)
#define tour(i, u) for(reg int (i) = head[(u)]; (i) != -1; (i) = nxt[(i)])
using namespace std;
char ch, B[1 << 20], *S = B, *T = B;
#define getc() (S == T && (T = (S = B) + fread(B, 1, 1 << 20, stdin), S == T) ? 0 : *S++)
#define isd(c) (c >= '0' && c <= '9')
int rdint() {
  int aa, bb;
  while(ch = getc(), !isd(ch) && ch != '-');
  ch == '-' ? aa = bb = 0 : (aa = ch - '0', bb = 1);
  while(ch = getc(), isd(ch))
    aa = aa * 10 + ch - '0';
  return bb ? aa : -aa;
}
ll rdll() {
  ll aa, bb;
  while(ch = getc(), !isd(ch) && ch != '-');
  ch == '-' ? aa = bb = 0 : (aa = ch - '0', bb = 1);
  while(ch = getc(), isd(ch))
    aa = aa * 10 + ch - '0';
  return bb ? aa : -aa;
}
const int MAXN = 1100;
int n, m, a[MAXN];
inline void work() {
  n = rdint(), m = rdint();
  int sum = 0;
  For(i, n) a[i] = rdint(), sum += a[i];
  int tot = 0;
  For(i, n) if((double) a[i] >= (double) sum / (4 * m)) ++tot;
  if(tot >= m) puts("Yes");
  else puts("No");
}
int main() {
  // freopen("input.txt", "r", stdin);
  work();
  return 0;
}

Measured memory_bytes: 256
#include  <functional>
#include  <algorithm>
#include  <exception>
#include  <stdexcept>
#include  <streambuf>
#include  <iterator>
#include  <string.h>
#include  <stdlib.h>
#include  <typeinfo>
#include  <valarray>
#include  <iostream>
#include  <sstream>
#include  <istream>
#include  <stdio.h>
#include  <climits>
#include  <clocale>
#include  <complex>
#include  <csetjmp>
#include  <csignal>
#include  <cstdarg>
#include  <cstddef>
#include  <ctype.h>
#include  <cassert>
#include  <cstdlib>
#include  <utility>
#include  <cstring>
#include  <numeric>
#include  <ostream>
#include  <cwctype>
#include  <fstream>
#include  <iomanip>
#include  <math.h>
#include  <bitset>
#include  <cctype>
#include  <string>
#include  <vector>
#include  <limits>
#include  <locale>
#include  <memory>
#include  <cerrno>
#include  <time.h>
#include  <iosfwd>
#include  <cfloat>
#include  <cstdio>
#include  <cwchar>
#include  <cmath>
#include  <ctime>
#include  <deque>
#include  <queue>
#include  <stack>
#include  <list>
#include  <ios>
#include  <map>
#include  <set>
#include  <new>
#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define ll long long
#define pii pair<int,int>
using namespace std;
const int maxn=2005;
int n,m,q;
string s[maxn];
int a[2010][2010];
int sum[2010][2010];
int col[2010][2010],lin[2010][2010];
int main()
{
    cin>>n>>m>>q;
    for(int i=1;i<=n;i++)
    {
        cin>>s[i];
        for(int j=1;j<=s[i].size();j++)
        a[i][j]=(s[i][j-1]=='1');
    }
    for(int i=1;i<=n;i++)
    {
        for(int j=1;j<=m;j++)
        {
            sum[i][j]=sum[i-1][j]+sum[i][j-1]-sum[i-1][j-1]+a[i][j];
            col[i][j]=col[i-1][j]+col[i][j-1]-col[i-1][j-1]+(a[i][j] && a[i-1][j]);
            lin[i][j]=lin[i-1][j]+lin[i][j-1]-lin[i-1][j-1]+(a[i][j] && a[i][j-1]);
        }
    }
    /*for(int i=1;i<=n;i++)
    {
        for(int j=1;j<=m;j++)
        {
            cout<<col[i][j]<<" ";
        }
        cout<<endl;
    }
    for(int i=1;i<=n;i++)
    {
        for(int j=1;j<=m;j++)
        {
            cout<<lin[i][j]<<" ";
        }
        cout<<endl;
    }*/
    for(int i=0;i<q;i++)
    {
        int x,y,u,v;
        cin>>x>>y>>u>>v;
        int sum1=sum[u][v]+sum[x-1][y-1]-sum[x-1][v]-sum[u][y-1];
        int sum2=col[u][v]+col[x][y-1]-col[x][v]-col[u][y-1],sum3=lin[u][v]+lin[x-1][y]-lin[x-1][v]-lin[u][y];
        cout<<sum1-sum2-sum3<<endl;
    }
    return 0;
}


Measured memory_bytes: 68992
#ifndef _GLIBCXX_NO_ASSERT
#include <cassert>
#endif
#include <cctype>
#include <cerrno>
#include <cfloat>
#include <ciso646>
#include <climits>
#include <clocale>
#include <cmath>
#include <csetjmp>
#include <csignal>
#include <cstdarg>
#include <cstddef>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#ifdef __GXX_EXPERIMENTAL_CXX0X__
#include <ccomplex>
#include <cfenv>
#include <cinttypes>
#include <cstdbool>
#include <cstdint>
#include <ctgmath>
#include <cwchar>
#include <cwctype>
#endif

#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>
#ifdef __GXX_EXPERIMENTAL_CXX0X__
#include <array>
#include <atomic>
#include <chrono>
#include <condition_variable>
#include <forward_list>
#include <future>
#include <initializer_list>
#include <mutex>
#include <random>
#include <ratio>
#include <regex>
#include <system_error>
#include <thread>
#include <tuple>
#include <typeindex>
#include <type_traits>
#include <unordered_map>
#include <unordered_set>
#endif

 size_t strlen(const char *s);
#define rep(i,n) for(long long int i=0;i<n;i++)
#define sz(x) ((int)(x).size())

using namespace std;
std::vector<int> graph[10050];//graph頂点数のsize
const int N=200010;
const int P=1000000007;
using ll = long long;
vector<ll> prime;

//絶対値
int ze(int a, int b){
	if(a>b){
		return a-b;
	}else{
		return b-a;
	}
}
//小さい方
long long int min(long long int a,long long int b){
	if(a>b){
		return b;
	}else{
		return a;
	}
}
//大きい方
long long int max(long long int a,long long int b){
	if(a>b){
		return a;
	}else{
		return b;
	}
}
// a^n mod 
long long modpow(long long a, long long n, long long mod) {
    long long res = 1;
    while (n > 0) {
        if (n & 1) res = res * a % mod;
        a = a * a % mod;
        n >>= 1;
    }
    return res;
}

// a^{-1} mod 
long long modinv(long long a, long long mod) {
    return modpow(a, mod - 2, mod);
}

//mod掛け算
long long mt(long long a, long long b, long long mod){
	return (a*b)%mod;
}

//メモ

/*
	memset(b, '\0', sizeof(b));
初期化*/


/*
	string s;
	s.size()
*/

/*
	char s[N];
	strlen(s)
*/
/*
	if(  <  )puts("Yes");
	else puts("No");
*/

/*文字列比較
if(strcmp(name[i],s)==0)
*/

/*
	graph[a].push_back(b);//graph[a][i番目に入れた]==b
	graph[j].size()	//forで回すときとか

*/


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

	string s;
    cin>>s;
//  cout<<sz(s);
    if(sz(s)<=k){
    cout<<s<<endl;
    }else{
    rep(i, k){
    cout<<s.at(i);
    }
    cout<<"..."<<endl;
    }

///////////2
}


Measured memory_bytes: 3772
#include <iostream>
#include <algorithm>
#include <vector>
#include <climits>

using namespace std;

int main() {
	int n,x;
	cin >> n >> x;
	while (n!=0 || x!=0) {
		int count=0;
		for(int i=1;i<=n;i++) 
			for(int j=i+1;j<=n;j++) 
				for(int k=j+1;k<=n;k++) {
					if ( (i+j+k) == x) {
						count++;
					}
				}
		cout << count << endl;	
		cin >> n >> x;
	}
	return 0;
}




Measured memory_bytes: 3080
#d=["a","b","c","d","e","f","g","h","i","j","k","l","m","n","o","p","q","r","s","t","u","v","w","x","y","z"]
#import numpy as np
import math
#n=int(input())
#li=input().split()
#S=input()

n=int(input())
lis=list(map(int,input().split()))

l=[0,0,0,0,0,0,0,0,0]

for i in range(n):
    a=math.floor(lis[i]/400)
    if a<8:
        l[a]=1
    else:
        l[-1]+=1

if sum(l[:8])==0:
    print(1,l[8])
else:
    print(sum(l[:8]),sum(l))


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

using namespace std;
typedef long long ll;

ll by_bit_brute_force(const string &s)
{
    int n = s.size()-1;
    ll ans = 0, k = 1, sum;
    for(int i=0; i < (1 << n); ++i){
        sum = 0;
        k = 1;
        for(int j=0;j<n;++j){
            if((i >> j) & 1){
                ans += (sum + (s[n-j] - '0') * k);
                k = 1;
                sum = 0;
            }
            else{
                sum += (s[n-j] - '0') * k;
                k *= 10;
            }
        }
        ans += (sum + (s[0] - '0') * k);
    }
    return ans;
}

ll dfs(string s, int index, ll sum, ll k)
{
    if(index == 0){
        return k * (s[index] - '0') + sum;
    };
    sum += (s[index] - '0') * k;
    return dfs(s, index-1, sum, k*10) + dfs(s, index-1, sum, 1);
}

int main()
{
    string s;
    cin >> s;
    //cout << by_bit_brute_force(s) << endl;
    cout << dfs(s, s.size()-1, 0, 1) << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n) FOR(i,0,n)
#define all(x) (x).begin(),(x).end()
#define PRINT(V) cout << V << "\n"
#define SORT(V) sort((V).begin(),(V).end())
#define RSORT(V) sort((V).rbegin(), (V).rend())
using namespace std;
using ll = long long;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }

int dp[100010];
int cost[100010];
int main(){
    int n;
    cin >> n;
    rep(i,n){
        cin >> cost[i];
    }
    dp[0] = 0;
    dp[1] = abs(cost[1] - cost[0]);
    FOR(i,2,n){
        dp[i] = min(dp[i-1] + abs(cost[i] - cost[i-1]),dp[i-2] + abs(cost[i] - cost[i-2]));
    }
    PRINT(dp[n-1]);
}


Measured memory_bytes: 1024
package main

import (
	"fmt"
	"math"
)

func minFn(nums []int) int {
	res := nums[0]
	for i := 1; i < len(nums); i++ {
		res = int(math.Min(float64(res), float64(nums[i])))
	}
	return res
}

func main() {
	var n, a, b, c, d, e int
	fmt.Scan(&n)
	fmt.Scan(&a)
	fmt.Scan(&b)
	fmt.Scan(&c)
	fmt.Scan(&d)
	fmt.Scan(&e)
	min := minFn([]int{a, b, c, d, e})
	amari := n%min != 0
	z := uint64(n) / uint64(min)
	if amari {
		z++
	}
	fmt.Println(z + 4)
}


Measured memory_bytes: 512
import re
import sys
for a in (l.rstrip().split() for l in sys.stdin):
    stack = []
    for op in a:
        if re.match(r"(-|)[\d]+$", op):
            stack.append(int(op))
        else:
            n1, n2 = stack.pop(), stack.pop()
            stack.append(
                n2 + n1 if op == "+"
                else n2 - n1 if op == "-"
                else n2 * n1 if op == "*"
                else n2 / n1
            )
    print(stack[0])


Measured memory_bytes: 6556
#include<iostream>

using namespace std;

int main(){
	int a[2][5];
	char ans[5]={'A','B','C','D','E'};
	int max,s,m;
	while(cin>>a[0][0]>>a[1][0],a[0][0]!=0){
		max=a[0][0]+a[1][0];
		m=0;
		for(int i=1;i<5;i++){
			cin>>a[0][i]>>a[1][i];
				s=a[0][i]+a[1][i];
				if(s>max){max=s;m=i;}
		}
		cout<<ans[m]<<" "<<max<<endl;
	}

}

Measured memory_bytes: 1160
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
#define rep(i,n) for(ll i=0;i<(ll)(n);i++)
#define all(a) (a).begin(),(a).end()
#define pb emplace_back
#define INF (1e9+1)

//verified AOJ GRL_1
#define MAX_V 100000
struct edge{int to,cost;};

void dijkstra(int s, vector<int> &d, vector<edge> G[MAX_V]){
    priority_queue< pii,vector<pii>,greater<pii> > que;
    rep( i,d.size() )d[i]=INF;
    d[s] = 0;
    que.push( pii(0,s) );
    
    while( que.size() ){
        pii p=que.top();
        que.pop();
        
        int v=p.second;
        if(d[v]<p.first)continue;
        
        rep(i,G[v].size()){
            edge e=G[v][i];
            if(d[e.to]>d[v]+e.cost){
                d[e.to]=d[v]+e.cost;
                que.push(pii(d[e.to],e.to));
            }
        }
    }
}

int main(){
    int v,e;
    cin>>v>>e;
    
    int s,t;
    cin>>s>>t;
    s--,t--;
    
    vector<int> d(v);
    rep(i,v)cin>>d[i];
    
    vector<edge> G[MAX_V];
    
    rep(i,e){
        int a,b;
        cin>>a>>b;
        a--,b--;
        G[a].pb(edge{b,d[b]});
    }
    
    for(int i=v-1;i>0;i--){
        G[i].pb(edge{i-1,0});
    }
    
    vector<int> dir(v);
    dijkstra(s, dir, G);
    
    cout<<dir[t]<<endl;
}

Measured memory_bytes: 11300
class Factorial:
    def __init__(self,n,mod):
        self.f=[1]
        for i in range(1,n+1):
            self.f.append(self.f[-1]*i%mod)
        self.i=[pow(self.f[-1],mod-2,mod)]
        for i in range(1,n+1)[::-1]:
            self.i.append(self.i[-1]*i%mod)
        self.i.reverse()
    def factorial(self,i):
        return self.f[i]
    def ifactorial(self,i):
        return self.i[i]
    def comb(self,n,k):
        return self.f[n]*self.i[n-k]*self.i[k]
n,m,k=map(int,input().split())
M=10**9+7
print((sum(m*m*i*(n-i)for i in range(n))+sum(n*n*i*(m-i)for i in range(m)))*Factorial(n*m,M).comb(n*m-2,k-2)%M)

Measured memory_bytes: 18964
#from collections import defaultdict
#from pprint import pprint
#from collections import deque
#from collections import Counter
#from copy import deepcopy
#from itertools
#import sys 
#sys.setrecursionlimit(N) #N回まで再起を許可する。
#import numpy as np
#import math
# = map(int,input().split())

# = list(map(int,input().split()))

# = [list(map(int,input().split())) for _ in range(XXXX)]

def func(i):
    if i == 0:
        return 0
    elif i == 1:
        return d
    elif i in memo:
        return memo[i]
    else:
        min_val = int(min(
            d*i,
            d*abs(i-i//2*2) + a + func(i//2),
            d*abs(i-(i+1)//2*2) + a + func((i+1)//2),
            d*abs(i-i//3*3) + b + func(i//3),
            d*abs(i-(i+2)//3*3) + b + func((i+2)//3),
            d*abs(i-i//5*5) + c + func(i//5),
            d*abs(i-(i+4)//5*5) + c + func((i+4)//5)
        ))

    memo[i] = min_val
    return min_val



t = int(input())

nabcd = [list(map(int,input().split())) for _ in range(t)]


for i in range(t):
    n = nabcd[i][0]
    a = nabcd[i][1]
    b = nabcd[i][2]
    c = nabcd[i][3]
    d = nabcd[i][4]

    memo = {}


    print(func(n))
    #print(memo)


Measured memory_bytes: 91048
while True:
    a,op,b=input().split()
    a=int(a)
    b=int(b)
    if op == "?":
        break
    if op == '+': print(a+b)
    elif op == '-': print(a-b)
    elif op == '*': print(a*b)
    elif op == '/': print(a//b)
    else: break



Measured memory_bytes: 5596
#include <iostream>
#include <queue>
using namespace std;
int main(){
    priority_queue<int,vector<int>,greater<int>>pq;
    string s;
    int ans=0,temp;
    cin>>s;
    int cnt[26];
    for(int i=0;i<26;i++)cnt[i]=0;
    for(char i:s)cnt[i-'a']++;
    for(int i=0;i<26;i++)if(cnt[i]>0)pq.push(cnt[i]);
    if(pq.size()==1){
        printf("%d\n",pq.top());
        return 0;
    }
    while(pq.size()>1){
        temp=pq.top();
        pq.pop();
        ans+=temp+pq.top();
        pq.push(temp+pq.top());
        pq.pop();
    }
    printf("%d\n",ans);
}


Measured memory_bytes: 3464
package main

import (
	"fmt"
)

func pow(x int, y int64) int64 {
	ret := int64(1)
	for i := int64(0); i < y; i++ {
		ret *= int64(x)
	}
	return ret
}

func main() {
	var n int64
	fmt.Scan(&n)
	if n == 0 {
		fmt.Println(0)
		return
	}
	if (n%2 == 1) || (n < 10) {
		fmt.Println(0)
		return
	}

	m := n / 2
	ans := m / 5
	for i := int64(2); pow(5, i) <= m; i++ {
		ans += m / pow(5, i)
	}
	fmt.Println(ans)
}


Measured memory_bytes: 512
#include <algorithm>
#include <cstdio>
#include <functional>
#include <iostream>
#include <cfloat>
#include <climits>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <time.h>
#include <complex>
#include <vector>
#include<limits>
#include<iomanip>

using namespace std;

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

const long double pi = 3.141592653589793;

#define debug(x) cout << #x << " = " << (x) << endl;
#define rep(i, n) for(int i = 0;i < n;i++)
#define pb push_back
#define mp make_pair
#define mod 1000000007
#define F first
#define S second

// #define COMMENT

/*   nCr % mod

const int N = 2000099;
ll fact[N];
ll finv[N];
ll inv[N];

void inverse_modulao() {
  fact[0] = fact[1] = 1;
  finv[0] = finv[1] = 1;
  inv[1] = 1;

  for(int i = 2;i < N;i++) {
    fact[i] = fact[i-1]*i%mod;
    inv[i] = mod-mod/i*inv[mod%i]%mod;
    finv[i] = finv[i-1]*inv[i]%mod;
  }
}

ll nCr(int n, int r) {
  return fact[n]*finv[r]%mod*finv[n-r]%mod;
}

*/

unordered_set<ll> divisors(ll X) {
  unordered_set<ll> divs;
  for(ll i = 1; i*i <= X;i++) {
    if(X % i == 0) {
      divs.insert(i);
      divs.insert(X/i);
    }
  }

  divs.erase(1);
  return divs;
}

ll N;

int main() {

//  freopen("input.in","r",stdin);
  //freopen("output.out","w",stdout);

  cin >> N;

  unordered_set<ll> nd = divisors(N);
  unordered_set<ll> nm1d = divisors(N-1);

  int ans = nm1d.size();
  for(auto x : nm1d) {
    if(nd.find(x) != nd.end()) { ans--; }
  }

  for(auto x : nd) {
    ll z = N;
    while(z % x == 0) z /= x;
    if(z % x == 1) ans++;
  }
  cout << ans << endl;

  return 0;
}


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

#define rep(i, a, b) for(int i = a; i < (b); ++i)
#define all(x) begin(x), end(x)
#define sz(x) (int)(x).size()
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;

template<typename H> bool chmin(H& v1, const H v2) { if (v1 > v2) { v1 = v2; return true; } return false; }
template<typename H> bool chmax(H& v1, const H v2) { if (v1 < v2) { v1 = v2; return true; } return false; }
template<typename H> void read(H& head) { cin >> head; }
template<typename H, typename ...T> void read(H& head, T& ...tail) { cin >> head; read(tail...); }
template<typename H> void write(H head) { cout << head << '\n'; }
template<typename H, typename ...T> void write(H head, T ...tail) { cout << head << " "; write(tail...); }
template<typename ...T> void die(T ...tok) { write(tok...); exit(0); }

ll a[100005], b[100005];

int main() {
	cin.tie(0)->sync_with_stdio(0);
	cin.exceptions(cin.failbit);

	int n; read(n);
	rep(i, 0, n) read(a[i], b[i]);
	ll ans = 0;
	for (int i = n - 1; i >= 0; i--) {
		if ((a[i] + ans) % b[i] != 0) {
			ans += (b[i] - (a[i] + ans) % b[i]);
		}
	}
	die(ans);
}


Measured memory_bytes: 1792
#include "bits/stdc++.h"
using namespace std;
using ll = long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using vi = vector<int>;
using vl = vector<ll>;
using vvi = vector<vi>;
using vvl = vector<vl>;
const ll INF = 1LL << 60;
const ll MOD = 1000000007;
template <class T>
bool chmax(T &a, const T &b) {
    return (a < b) ? (a = b, 1) : 0;
}
template <class T>
bool chmin(T &a, const T &b) {
    return (b < a) ? (a = b, 1) : 0;
}

int main() {
    int n;
    cin >> n;
    vl a(n);
    for (int i = 0; i < n; ++i) {
        cin >> a[i];
    }
    for (int i = 1; i < n; ++i) {
        a[i] += a[i - 1];
    }
    map<ll, int> ma;
    ma[0]++;
    ll ret = 0;
    for (int i = 0; i < n; ++i) {
        ret += ma[a[i]];
        ma[a[i]]++;
    }
    cout << ret << "\n";
    return 0;
}

Measured memory_bytes: 14336
#include <iostream>
#include <complex>
#include <sstream>
#include <string>
#include <algorithm>
#include <deque>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <vector>
#include <set>
#include <limits>
#include <cstdio>
#include <cctype>
#include <cmath>
#include <cstring>
#include <cstdlib>
#include <ctime>
using namespace std;
#define REP(i, j) for(int i = 0; i < (int)(j); ++i)
#define FOR(i, j, k) for(int i = (int)(j); i < (int)(k); ++i)
#define SORT(v) sort((v).begin(), (v).end())
#define REVERSE(v) reverse((v).begin(), (v).end())
typedef complex<double> P;
const int INF = 1e5;

int H, W;
int my[] = {0, 0, 1, -1};
int mx[] = {1, -1, 0, 0};

void dfsA(int t, int y, int x, vector<string> &v, vector< vector<int> > &cnt){
  REP(i, 4){
    int ny = y + my[i], nx = x + mx[i];
    if(ny >= 0 && nx >= 0 && ny < H && nx < W && v[ny][nx] != '#' && cnt[ny][nx] > t + 1){
      cnt[ny][nx] = t + 1;
      dfsA(t + 1, ny, nx, v, cnt);
    }
  }
}

int main() {
  while(cin >>H >>W && H){
    vector<string> v(H); REP(i, H) cin >>v[i];
    vector< vector<int> > cntA(H, vector<int>(W, INF));
    REP(i, H) REP(j, W) if(v[i][j] == 'A') { cntA[i][j] = 0; dfsA(0, i, j, v, cntA); }
    string pattern; cin >>pattern;
    int y, x, ay, ax, ans = INF, pl = pattern.length();
    REP(i, H) REP(j, W) if(v[i][j] == 'B') { y = i; x = j; }
    REP(i, INF){
      if(cntA[y][x] <= i) { ans = i; ay = y; ax = x; break; }
      //cout <<y <<", " <<x <<", " <<cntA[y][x] <<", " <<i <<endl;
      if(pattern[i % pl] == '8') { y = max(0, y - 1); }
      else if(pattern[i % pl] == '6') { x = min(W - 1, x + 1); }
      else if(pattern[i % pl] == '4') { x = max(0, x - 1); }
      else if(pattern[i % pl] == '2') { y = min(H - 1, y + 1); }
    }
    if(ans == INF) cout <<"impossible" <<endl;
    else cout <<ans <<" " <<ay <<" " <<ax <<endl;
  }
  return 0;
}

Measured memory_bytes: 1264
#include <stdio.h>

int	diff(int a, int b)
{
	if (a < b)
		return (b - a);
	else
		return (a - b);
}

void ft_sort(int *a, int n)
{
	int i = 1;
	int j;
	int tmp;
	while (i < n)
	{
		j = 0;
		while (j < n)
		{
			if (a[i] < a[j])
			{
				tmp = a[i];
				a[i] = a[j];
				a[j] = tmp;
			}
			j++;
		}
		i++;
	}
}

int main(void)
{
	int alice = 0;
	int bob = 0;
	int n;
	scanf("%d", &n);
	int a[n + 1];
	int i;
	for (i = 0; i < n; i++)
		scanf("%d", &a[i]);
	ft_sort(a, n);
	i = 0;
	while (i < n)
	{
		if (i % 2 == 0)
			alice += a[i];
		else
			bob += a[i];
		i++;
	}
	printf("%d", diff(alice, bob));
	return (0);
}


Measured memory_bytes: 128
n=int(input())

minx=10**10
maxx=-10**10
miny=10**10
maxy=-10**10

for _ in range(n):
    x,y=map(int,input().split())

    maxx=max(maxx,x+y)
    minx=min(minx,x+y)
    maxy=max(maxy,x-y)
    miny=min(miny,x-y)

print(max(maxx-minx,maxy-miny))

Measured memory_bytes: 69856
//MADE BY Y_is_sunshine;
//#include <bits/stdc++.h>
//#include <memory.h>
#include <algorithm>
#include <iostream>
#include <cstdlib>
#include <cstring>
#include <sstream>
#include <cstdio>
#include <vector>
#include <string>
#include <cmath>
#include <queue>
#include <stack>
#include <map>
#include <set>

#define INF 0x3f3f3f3f
#define MAXN 100005

typedef long long ll;

const ll mod = 1e9 + 7;
const double PI = acos(-1);

using namespace std;

int N, M, K;

int main(void)
{
#ifdef Sunshine
	freopen("data.txt", "r", stdin);
#endif

	ios_base::sync_with_stdio(false);
	cin.tie(NULL);

	string s1;
	cin >> s1;

	int ans = 0;
	int len = (s1.size() - 1) / 2;
	N = s1.size();

	for (int i = 0; i <= len; i++) {
		if (s1[i] != s1[N - 1 - i])
			ans++;
	}

	cout << ans << '\n';




#ifdef Sunshine
	freopen("CON", "r", stdin);
	system("pause");
#endif
	return 0;
}



Measured memory_bytes: 256
# coding: utf-8
# Your code here!
def comb(num):
    return num*(num-1)//2

N=int(input())
A=list(map(int,input().split()))

log=[0]*N
for item in A:
    log[item-1]+=1

sm=[0]*N
for index,item in enumerate(log):
    sm[index]=comb(item)

temp=sum(sm)

for k in range(N):
    ans=temp
    #print(log[A[k]-1])
    ans-=sm[A[k]-1]
    ans+=comb(log[A[k]-1]-1)
    print(ans)

#print(log)
#print(sm)


Measured memory_bytes: 26140
#include <iostream>
#include <map>
using namespace std;
typedef long long ll;

int main()
{
    ll n, m;
    cin >> n >> m;
    ll a[100001];
    ll sum = 0;
    map<ll, ll> mp;
    for(int i = 0; i < n; i++){
        cin >> a[i];
        sum = (sum + a[i]) % m;
        mp[sum]++;
    }
    ll ans = 0;
    for(auto itr = mp.begin(); itr != mp.end(); itr++){
        ll s = itr->second;
        if(itr->first == 0){
            ans += (s + 1) * s / 2;
        }
        else{
            ans += s * (s - 1) / 2;
        }
    }
    cout << ans << endl;
}

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

signed main() {
  int n;
  while (true) {
    cin >> n;
    if (n == 0) return 0;
    auto sum = 0;
    for (int i = 2;; i++) {
      auto base = i * (i + 1) / 2;
      if (base > n) break;
      if ((base - n) % i == 0) sum++;
    }
    cout << sum << endl;
  }
}

Measured memory_bytes: 3048
import java.util.*;
public class Main {
	public static void main(String args[]){
		Scanner sc=new Scanner(System.in);
		while(sc.hasNext()){
			double[] a=new double[8];
			for(int i=0;i<8;i++)a[i]=sc.nextDouble();
			a[0]-=a[2]; a[1]-=a[3];
			a[4]-=a[6]; a[5]-=a[7];
			if(a[0]*a[4]+a[1]*a[5]==0)System.out.println("YES");
			else System.out.println("NO");
			
		}
	}
}

Measured memory_bytes: 12000
import java.util.*;

public class Main {
    private static int W;
    private static int H;

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        H = sc.nextInt();
        W = sc.nextInt();
        int[][] s = new int[H + 2][W + 2];
        int count = 0;
        for (int row = 1; row <= H; row++) {
            String cur = sc.next();
            for (int col = 1; col <= W; col++) {
                char temp = cur.charAt(col - 1);
                if (temp == '.') {
                    s[row][col] = 1;
                    count++;
                }
            }
        }
        /*
        boolean[] record = new boolean[(H + 2) * (W + 2)];
        record[W + 3] = true;
        int r1 = dfs(s, 1, 1, 2, record);
        int r2 = dfs(s, 1, 2, 1, record);
        int ans;
        if (r1 == -1 && r2 == -1) ans = -1;
        else {
            int min = Integer.MAX_VALUE;
            if (r1 != -1) min = Math.min(min, r1);
            if (r2 != -1) min = Math.min(min, r2);
            ans = count - min;
        }*/
        int res = bfs(s);
        if (res == -1) System.out.println(-1);
        else System.out.println(count - res);
    }

    /*private static int dfs(int[][] m, int level, int row, int col, boolean[] record){
         if(m[row][col]==0) return -1;
         if(record[col+row*(W+2)]) return -1;
         if(row==H&&col==W) return level+1;
         boolean[] newRecord = new boolean[record.length];
         System.arraycopy(record,0,newRecord,0,record.length);
         newRecord[col+row*(W+2)] = true;
         int r1=dfs(m,level+1,row-1,col,newRecord);
         int r2=dfs(m,level+1,row+1,col,newRecord);
         int r3=dfs(m,level+1,row,col-1,newRecord);
         int r4=dfs(m,level+1,row,col+1,newRecord);
         int min = Integer.MAX_VALUE;
         int[] res = new int[]{r1,r2,r3,r4};
         for(int i=0;i<4;i++){
             if(res[i]==-1) continue;
             min = Math.min(min,res[i]);
         }
         if(min==Integer.MAX_VALUE) return -1;
         else return min;
    }*/
    static int bfs(int[][] s) {
        boolean[][] record = new boolean[H + 2][W + 2];

        int count = 1;
        LinkedList<int[]> cur = new LinkedList<>();
        LinkedList<int[]> next = new LinkedList<>();
        cur.add(new int[]{1, 1});
        while (cur.size() > 0) {
            int[] now = cur.remove();
            if (now[0] == H && now[1] == W) return count;
            if ((!record[now[0]][now[1]]) && s[now[0]][now[1]] != 0) {
                record[now[0]][now[1]] = true;
                next.add(new int[]{now[0] - 1, now[1]});
                next.add(new int[]{now[0] + 1, now[1]});
                next.add(new int[]{now[0], now[1] - 1});
                next.add(new int[]{now[0], now[1] + 1});
            }
            if (cur.size() == 0) {
                count++;
                cur = next;
                next = new LinkedList<>();
            }

        }
        return -1;
    }
}

Measured memory_bytes: 22228
#include <bits/stdc++.h>
#define rep(i,n) for(int i=(0);i<(n);i++)

using namespace std;

typedef long long ll;

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

	int n;
	cin >> n;

	int a[n];
	rep(i, n) cin >> a[i];
	sort(a, a + n);

	int sm = 0;
	rep(i, n - 1) sm += a[i+1] - a[i];
	cout << sm << endl;
}


Measured memory_bytes: 256
import sys
import copy
import  math
import bisect
from collections import *
from operator import itemgetter
"""
from fractions import gcd
def lcm(x, y):
    return (x * y) // gcd(x, y)
"""
stdin = sys.stdin
ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
ns = lambda: stdin.readline()

s = input()
l = len(s)
print(s[0] + str(l - 2) + s[-1])

Measured memory_bytes: 3572
#include <bits/stdc++.h>
#define all(x) (x).begin(), (x).end()
typedef long long ll;
#define MOD 1000000007
using namespace std;

int main() {
    int k;
    cin >> k;
    for(int i = 0; i < k; i++) {
        cout << "ACL";
    }
    cout << endl;
}


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

typedef struct P{
    int parent;
    int left;
    int right;
}Node;

int depth(Node node[],int n){
    if(node[n].parent==-1){
        return 0;
    }
    return depth(node,node[n].parent)+1;
}

int height(Node node[],int n){
    int a,b;
    if(n==-1){return -1;}
    a = height(node,node[n].left);
    b = height(node,node[n].right);
    return a>b ? a+1 : b+1;
}

int sibling(Node node[],int n){
    if(node[n].parent==-1){return -1;}
    if(node[node[n].parent].left==n){
        return node[node[n].parent].right;
    }else{
        return node[node[n].parent].left;
    }
}

int degree(Node node[],int n){
    int count = 0;
    if(node[n].left!=-1){count++;}
    if(node[n].right!=-1){count++;}
    return count;
}

int main(void){
    int n,i,j,k,l,m;
    Node *node;
    scanf("%d",&n);
    node = (Node*)malloc(sizeof(Node)*n);
    for(i=0;i<n;i++){
        node[i].parent = -1;
        node[i].left = -1;
        node[i].right = -1;
    }
    for(i=0;i<n;i++){
        scanf("%d",&k);
        scanf("%d",&l);
        node[k].left = l;
        node[l].parent = k;
        scanf("%d",&l);
        node[k].right = l;
        node[l].parent = k;
    }
    
    for(i=0;i<n;i++){
        printf("node %d: ",i);
        printf("parent = %d, ",node[i].parent);
        printf("sibling = %d, ",sibling(node,i));
        printf("degree = %d, ",degree(node,i));
        printf("depth = %d, ",depth(node,i));
        printf("height = %d, ",height(node,i));
        if(node[i].parent==-1){  printf("root");  }
        else if(node[i].left==-1&&node[i].right==-1){  printf("leaf");  }
        else{  printf("internal node");  }
        printf("\n");
    }
}


Measured memory_bytes: 2036
#include<bits/stdc++.h>
#define ll long long
using namespace std;
const int mod=1e9+7;
map<ll,ll>ans;
ll cl(ll x){
    if(ans[x])return ans[x];
    else{
        return ans[x]=(cl(x/2)+cl((x-1)/2)+cl((x-2)/2))%mod;
    }
}
ll n;
int main()
{
    scanf("%lld",&n);
    ans[0]=1,ans[1]=2;
    printf("%lld\n",cl(n));
}


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

int main(){
//srandom((unsigned long)time(NULL));
int n;
cin>>n;
vector<int> p(n),q(n);
rep(i,n) cin>>p[i];
rep(i,n) cin>>q[i];
vector<int> a(n);
rep(i,n) a[i]=i+1;

map<vector<int>, int> mp;
do {
    mp[a]=mp.size();
} while(next_permutation(a.begin(),a.end()));

int ans=abs(mp[p]-mp[q]);
cout<<ans<<endl;

return 0;
}

Measured memory_bytes: 5248
#include <vector>
#include <queue>
#include <cstdint>
#include <tuple>

using namespace std;

struct E{
  int to;
  int_fast64_t cost;
};

vector<vector<E>>prim(vector<vector<E>>g){
  vector<vector<E>>res(g.size());
  using T=tuple<int_fast64_t,int,int>;
  using C=vector<T>;
  using Cmp=greater<T>;
  priority_queue<T,C,Cmp>q;
  q.push(T(0,0,-1));
  vector<bool>used(g.size(),false);
  while(!q.empty()){
    int_fast64_t cost=get<0>(q.top());
    int now=get<1>(q.top());
    int par=get<2>(q.top());
    q.pop();
    if(used[now])continue;
    used[now]=true;
    if(par!=-1)res[par].push_back({now,cost});
    for(auto e:g[now]){
      q.push(T(e.cost,e.to,now));
    }
  }
  return res;
}

#include <bits/stdc++.h>

int main(){
  int v,e;
  cin>>v>>e;
  vector<vector<E>>g(v);
  for(int i=0;i<e;i++){
    int s,t,w;
    cin>>s>>t>>w;
    g[s].push_back({t,w});
    g[t].push_back({s,w});
  }
  auto G=prim(g);
  int_fast64_t ans=0;
  for(int i=0;i<v;i++){
    for(auto it:G[i]){
      ans+=it.cost;
    }
  }
  cout<<ans<<endl;
}



Measured memory_bytes: 15772
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n)for(int i=0;i<(n);i++)
#define ALL(a) (a).begin(), (a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define pb push_back
using ll = long long;
using P = pair<int, int>;

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

int main(){
    int n, x; cin >> n >> x;
    vector<int> diffs;
    rep(i,n){
        int a; cin >> a;
        diffs.push_back(abs(a - x));
    }
    int ans = gcd(diffs[0], diffs[1]);
    for(int i = 2; i < n; i++){
        ans = gcd(ans, diffs[i]);
    }
    cout << ans << endl;
}

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

using ll = long long int;

const int MAX = (int)(1e5 + 5);
const ll INF = (ll)(1e10 + 5);

const int MAX_N = (int)(1e5 + 5);

int n;

int h[MAX_N];

int ans;

int main(void) {
  // Here your code !
  scanf("%d", &n);

  for (int i = 0; i < n; ++i) {
    scanf("%d", &(h[i]));
  }

  ans = 1;

  for (int i = 1; i < n; ++i) {
    bool flg = true;
    for (int j = 0; j < i; ++j) {
      if (h[j] > h[i]) {
        flg = false;
        break;
      }
    }
    if (flg) ans += 1;
  }

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

  return 0;
}


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

#define CEIL(a,b) ((a) / (b) + ((a) % (b) == 0 ? 0 : 1))

using namespace std;
using ll = long long;
using pii = pair<int, int>;

constexpr int MOD = 1'000'000'007;
constexpr int INF = 1'000'000'001;
constexpr ll LLINF = 4'000'000'000'000'000'001;
// constexpr int INF = 2147483647; // 2 * 1e9
// constexpr ll LLINF = 9223372036854775807; // 9 * 1e18

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

int main(){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout << fixed << setprecision(10);
    int a, b;
    cin >> a >> b;
    cout << (b == 1 ? 0 : a-b) << "\n";
    return 0;
}

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

using namespace std;

int main(){
  int x,y;
  cin >> x >> y;
  int count=0;
  if(x<y){
    if(x==y*-1){
      count +=1;
    }else if(x<0&&y<0){
      count+=y-x;
    }else if(x<=0&&y>0){
      if(y>x*-1){
        count +=min(y-x,y+x+1);
      }else if(y<x*-1){
        count +=y*-1-x+1;
      }
    }else{
      count+=y-x;
    }
  }else if(x>y){
    if(x==y*-1){
      count +=1;
    }else if(x<0&&y<0){
      count+=x-y+2;
    }else if(x>=0&&y<0){
      if(x>y*-1){
        count += y-x*-1+1;
      }else if(x<y*-1){
        count +=y*-1-x+1;
      }
    }else{
      count+=min(x+y+1,x-y+2);
    }
  }
  cout << count << endl;
  return 0;
}


Measured memory_bytes: 256
#include<iostream>
using namespace std;
char v[256];int n,m;
int main(){
	while(true){
		cin>>n;for(int i=32;i<127;i++){v[i]=i;}
		if(n==0)break;
		for(int i=0;i<n;i++){char p,q;cin>>p>>q;v[p]=q;}
		cin>>m;
		for(int i=0;i<m;i++){
			char f;cin>>f;cout<<v[f];
		}
		cout<<endl;
	}
	return 0;
}

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

int main() {
    int x1, x2, x3=0, x4=0,y1,y2,y3=0,y4=0, def_x, def_y;
    cin >> x1 >> y1 >> x2 >> y2;
    
    
    def_x = abs(x1 - x2);
    def_y = abs(y1 - y2);
    
    if(x1 == x2 && y1 < 2){
        x3 = x2 - def_y;
        y3 = y2;
        x4 = x3;
        y4 = y3 - def_y;
    }
    else if(x1 == x2 && y1 > y2){
        x3 = x2 + def_y;
        y3 = y2;
        x4 = x3;
        y4 = y3 + def_y;
    }
    else if(x1 < x2 && y1 == y2){
        x3 = x2;
        y3 = y2 + def_x;
        x4 = x3 - def_x;
        y4 = y3;
    }
    else if(x1 > x2 && y1 == y2){
        x3 = x2;
        y3 = y2 - def_x;
        x4 = x3 + def_x;
        y4 = y3;
    }
    else if(x1 < x2 && y1 < y2){
        x3 = x2 - def_y;
        y3 = y2 + def_x;
        x4 = x3 - def_x;
        y4 = y3 - def_y;
    }
    else if(x1 > x2 && y1 < y2){
        x3 = x2 - def_y;
        y3 = y2 - def_x;
        x4 = x3 + def_x;
        y4 = y3 - def_y;
    }
    else if(x1 < x2 && y1 > y2){
        x3 = x2 + def_y;
        y3 = y2 + def_x;
        x4 = x3 - def_x;
        y4 = y3 + def_y;
    }
    else if(x1 > x2 && y1 > y2){
        x3 = x2 + def_y;
        y3 = y2 - def_x;
        x4 = x3 + def_x;
        y4 = y3 + def_y;
    }
    
    cout << x3 <<" "<<y3 << " " << x4 << " " << y4 << " " << endl;
    
}

Measured memory_bytes: 256
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cstring>

#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <unordered_map>
#include <unordered_set>

#include <functional>
#include <cassert>

typedef long long ll;
using namespace std;

#define debug(x) cerr << #x << " = " << x << endl;


#define mod 1000000007 //1e9+7(prime number)
#define INF 1000000000 //1e9
#define LLINF 2000000000000000000LL //2e18
#define SIZE 100010


int main(){
  int a,b,c;

  cin >> a >> b >> c;

  cout << ((a <= c && b >= c)?"Yes":"No") << endl;
  
  return 0;
}


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

#define PI 3.14159265359
#define rep(i,a,n) for(int i=a;i<(int)n;++i)
#define SZ(x) ((int)(x).size())	//size() unsigned -> int
#define descsort(a) sort(a.begin(),a.end(),std::greater<int>())
using namespace std;
typedef long long ll;
const ll INF = 1e9 + 7;

int main(void)
{
    int x;
    cin>>x;
    int ans;
    if(400<=x&&x<=599)ans=8;
    else if(600<=x&&x<=799)ans=7;
    else if(800<=x&&x<=999)ans=6;
    else if(1000<=x&&x<=1199)ans=5;
    else if(1200<=x&&x<=1399)ans=4;
    else if(1400<=x&&x<=1599)ans=3;
    else if(1600<=x&&x<=1799)ans=2;
    else if(1800<=x&&x<=1999)ans=1;
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 3632
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <cmath>
#include <set>
#include <map>
using namespace std;
#define rep(i,n) for(int i = 0;i<n;i++)
const long long MOD = 1000000007LL;
int main(){
    int n;
    cin >> n;
    int h[n];
    int tem;
    int ans = 0;
    rep(i,n){
        cin >> h[i];
        if(i == 0){
            tem = h[0];
            ans++;
        }
        else{
            if(tem <= h[i]){
                ans++;
                tem = h[i];
            }
        }
    }
    cout << ans << endl;
}


Measured memory_bytes: 256
open Printf
open Scanf

let id x = x

let a, b = scanf "%d %d" (fun a b -> a, b)

let () =
  let n1 = a * b * 1 in
  let n2 = a * b * 2 in
  let n3 = a * b * 3 in
  if n1 mod 2 = 1 || n2 mod 2 = 1 || n3 mod 2 = 1 then
    print_endline "Yes"
  else
    print_endline "No"



Measured memory_bytes: 384
#include <bits/stdc++.h>
#define LL long long
using namespace std;
const int maxn = 1010;
int n;
LL x[maxn],y[maxn],u[maxn],v[maxn],bs[35];

void work() {
  cin >> n;
  for (int i = 0; i < n; i++) cin >> x[i] >> y[i];

  LL sum = (x[0] + y[0]) % 2;
  for (int i = 0; i < n; i++) if ((x[i] + y[i] - sum) % 2 != 0) {cout<<"-1"<<endl;return;}

    if (sum == 0) {
        cout << 32 << endl;
        for (int i = 30; i > -1; i--) cout << bs[i] << " ";
        cout << 1 << endl;
        for (int i = 0; i < n; i++) x[i]++;
    } else {
        cout << 31 << endl;
        for (int i = 30; i > -1; i--) cout << bs[i] << " ";
        cout << endl;
    }

    for (int i = 0; i < n; i++) u[i] = x[i] + y[i], v[i] = x[i] - y[i];

    for (int i = 0; i < n; i++) {
        for (int j = 30; j > -1; j--) {
            if (u[i] > 0 && v[i] > 0) {cout << 'R'; u[i] -= bs[j]; v[i] -= bs[j]; }
            else if (u[i] > 0 && v[i] < 0) { cout << 'U'; u[i] -= bs[j]; v[i] += bs[j]; }
            else if (u[i] < 0 && v[i] > 0) { cout << 'D'; u[i] += bs[j]; v[i] -= bs[j]; }
            else { cout << 'L'; u[i] += bs[j]; v[i] += bs[j];}
        }
        if (sum == 0) cout << 'L';
        cout << endl;
    }
}
int main(){
    bs[0] = 1;
    for (int i=1;i<32;i++) bs[i] = bs[i-1] << 1;
    work();
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <cstdlib>
#include <cmath>
#include <vector>
#include <map>
#include <set>
#include <algorithm>
#include <queue>
#include <stack>
#include <functional>
#include <bitset>
using namespace std;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<char> vc;
typedef vector<string> vs;
typedef vector<bool> vb;
typedef vector<double> vd;
typedef pair<ll,ll> P;
typedef vector<P> vpl;
typedef tuple<ll,ll,ll> tapu;
#define rep(i,n) for(ll i=0; i<(n); i++)
#define REP(i,a,b) for(ll i=(a); i<(b); i++)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
const int inf = 1<<30;
const ll linf = 1LL<<62;
const int MAX = 510000;
ll dy[8] = {0,1,0,-1,1,-1,1,-1};
ll dx[8] = {1,0,-1,0,1,-1,-1,1};
const double pi = acos(-1);
const double eps = 1e-7;
template<typename T1,typename T2> inline bool chmin(T1 &a,T2 b){
	if(a>b){
		a = b; return true;
	}
	else return false;
}
template<typename T1,typename T2> inline bool chmax(T1 &a,T2 b){
	if(a<b){
		a = b; return true;
	}
	else return false;
}
template<typename T1,typename T2> inline void print2(T1 a, T2 b){cout << a << " " << b << endl;}
template<typename T1,typename T2,typename T3> inline void print3(T1 a, T2 b, T3 c){
	cout << a << " " << b << " " << c << endl;
}
const int mod = 1e9 + 7;
//const int mod = 998244353;

int main(){
	ll x,y,a,b,c; cin >> x >> y >> a >> b >> c;
	vl p(a),q(b),r(c);
	rep(i,a) cin >> p[i];
	rep(i,b) cin >> q[i];
	rep(i,c) cin >> r[i];
	sort(rall(p)); sort(rall(q));
	sort(rall(r));
	priority_queue<P> pq; 
	rep(i,x) pq.emplace(p[i],1);
	rep(i,y) pq.emplace(q[i],2);
	rep(i,min(c,x+y)) pq.emplace(r[i],0);
	ll ans = 0;
	ll red = 0, green = 0;
	ll cnt = x+y;
	while(cnt){
		P p = pq.top(); pq.pop();
		if(p.second==1){
			if(red == x) continue;
			else{
				ans += p.first;
				red++;
				cnt--;
			}
		}else if(p.second==2){
			if(green == y) continue;
			else{
				ans += p.first;
				green++;
				cnt--;
			}
		}else{
			ans += p.first;
			cnt--;
		}
	}
	cout << ans << endl;
}


Measured memory_bytes: 12524
N = int(input())
S = input()

r = S.count("R")
g = S.count("G")
b = S.count("B")

cnt = 0
for i in range(N):
    for j in range(i+1, N):
        k = j + j - i
        if 0 <= k < N:
            if S[i] != S[j] and S[j] != S[k] and S[k] != S[i]:
                cnt += 1

print(r*g*b - cnt)

Measured memory_bytes: 9212