akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define ll long long
#define pii std::pair<int,int>
#define pli std::pair<ll,int>
#define pil std::pair<int,ll>
#define psi std::pair<string,int>
#define pll std::pair<ll,ll>
#define pci std::pair<char,int>
#define sll(x) scanf("%lld",&x)
#define prll(x) printf("%lld ",x)
#define pri(x) printf("%d ",x)
#define si(x) scanf("%d",&x)
#define pb push_back
#define vll std::vector<ll>
#define vpi std::vector<std::pair<int,int>>
#define vi std::vector<int>
#define vvi std::vector<std::vector<int>>
#define vvpil std::vector<std::vector<std::pair<int,ll>>>
#define vlpii std::vector<std::list<pii>>
#define vlpil std::vector<std::list<pil>>
#define li std::list<int>
#define lpil std::list<pil>
#define Endl printf("\n")
#define vli vector<list<int>>
#define vvll vector<vector<ll>>
#define mp make_pair
#define x first
#define y second
#define ull uint64_t
#define ma 100000000
#define imie(...) "[" << #__VA_ARGS__": " << (__VA_ARGS__) << "] "
const ll  INF=10000000000000;
const ll mod =  1e9 + 7;
using namespace std;
void computeLPSArray(string pat, int M, int* lps); 
void add(ll& a , ll b){
	a += b;
	if(a >= mod) a -= mod;
}
ll mul(ll a , ll b){
	return (a * b) % mod;
}
ll Pow(ll a , ll b){
	if(b == 0) return 1 ;
	ll c = Pow(a , b / 2) ;
	if(b % 2) return (a * ((c * c)% mod )) % mod ;
	return (c * c) % mod ;
}
vector<int> KMPSearch(string pat, string txt) 
{ 
	int M = pat.length(); 
	int N = txt.length(); 
	vector<int> ans ;
	// create lps[] that will hold the longest prefix suffix 
	// values for pattern 
	int lps[M]; 

	// Preprocess the pattern (calculate lps[] array) 
	computeLPSArray(pat, M, lps); 

	int i = 0; // index for txt[] 
	int j = 0; // index for pat[] 
	while (i < N) { 
		if (pat[j] == txt[i]) { 
			j++; 
			i++; 
		} 

		if (j == M) { 
			ans.push_back(i - j) ;
			j = lps[j - 1]; 
		} 

		// mismatch after j matches 
		else if (i < N && pat[j] != txt[i]) { 
			// Do not match lps[0..lps[j-1]] characters, 
			// they will match anyway 
			if (j != 0) 
				j = lps[j - 1]; 
			else
				i = i + 1; 
		} 
	} 
	return ans ;
} 

// Fills lps[] for given patttern pat[0..M-1] 
void computeLPSArray(string pat, int M, int* lps) 
{ 
	// length of the previous longest prefix suffix 
	int len = 0; 

	lps[0] = 0; // lps[0] is always 0 

	// the loop calculates lps[i] for i = 1 to M-1 
	int i = 1; 
	while (i < M) { 
		if (pat[i] == pat[len]) { 
			len++; 
			lps[i] = len; 
			i++; 
		} 
		else // (pat[i] != pat[len]) 
		{ 
			// This is tricky. Consider the example. 
			// AAACAAAA and i = 7. The idea is similar 
			// to search step. 
			if (len != 0) { 
				len = lps[len - 1]; 

				// Also, note that we do not increment 
				// i here 
			} 
			else // if (len == 0) 
			{ 
				lps[i] = 0; 
				i++; 
			} 
		} 
	} 
} 
//check modulo
int main(){
	IOS;
	cout.precision(30) ;
	ll n ; cin >>  n;
	cout << (n * (n - 1)) / 2 << endl ;	
	return 0;
}


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

#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define ALL(obj) (obj).begin(), (obj).end()
#define INF 1e9
typedef long long ll;


int main() {
    ll N,K; cin >>N>>K;
    vector<ll> A(N+1);
    FOR(i,1,N+1){
        cin >> A[i];
    }

    ll start = 1;
    vector<ll> routes(N+1, -1);
    routes[1] = 0;
    
    ll roop_start, roop_end, roop_start_index;
    while(1){
        if(routes[A[start]] == -1){
            routes[A[start]] = routes[start] + 1;
            start = A[start];
        }else{
            roop_end = routes[start];
            roop_start = routes[A[start]];
            roop_start_index = A[start];
            break;
        }
    }


    ll ans = 1;
    if (K<=roop_end){
        REP(i,K){
            ans = A[ans];
        }

    }else{
        K -= roop_end+1;
        K %= (roop_end-roop_start+1);
    
        ans = roop_start_index;
        REP(i,K){
            ans = A[ans];
        }
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 6428
import itertools
import math
import fractions
import functools
n, m = map(int, input().split())
py = []
for i in range(m):
    l = list(map(int, input().split()))
    l.append(i)
    py.append(l)
 
# py = [p,y,index]
 
# yでsort
py.sort(key=lambda x: x[1])

ans = [0] * (m)
ans1 = [0] * (m)
memo = {}
for item in py:
    ken = item[0]
    year = item[1]
    idx = item[2]
    ith = memo.get(ken, 1)
    ans[idx] = ith
    ans1[idx] = ken
    memo[ken] = ith + 1

for i in range(m):
    print(str(ans1[i]).zfill(6) + str(ans[i]).zfill(6))


Measured memory_bytes: 103892
#include<stdio.h>

int main(){
	int Time[5];
	int LastOne = 10;
	for (int i = 0; i < 5; i++){
		if (scanf("%d", &Time[i]) == 1);
		if ((Time[i] % 10) != 0){
			if ((Time[i] % 10) < LastOne)
				LastOne = (Time[i] % 10);
			Time[i] += (10 - (Time[i] % 10));
		}
	}
	printf("%d",(Time[0] + Time[1] + Time[2] + Time[3] + Time[4])-(10-LastOne));
	return 0;
}

Measured memory_bytes: 128
import java.util.Scanner;

public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int a = sc.nextInt();
    if(a >= 3200) {
      String s = sc.next();
      System.out.println(s);
    } else {
      System.out.println("red");
    }
  }
}
    

Measured memory_bytes: 21716
#include <algorithm>
#include <cassert>
#include <cstdio>
#include <vector>
#define repeat(i, n) for (int i = 0; (i) < int(n); ++(i))
#define repeat_from(i, m, n) for (int i = (m); (i) < int(n); ++(i))
#define whole(x) begin(x), end(x)
using namespace std;

int main() {
    // input
    int n; scanf("%d", &n);
    vector<int> p(n); repeat (i, n) scanf("%d", &p[i]);
    // solve
    vector<int> history;
    auto operate = [&](int k) {
        repeat_from (i, k, n) {
            swap(p[i], p[i - k]);
        }
        history.push_back(k);
    };
    while (p[0] != 0 or not is_sorted(whole(p))) {
        if (p[0] < p[n - 1] and p[0] != 0) {
            operate(n - 1);
        } else {
            operate(1);
        }
    }
    // output
    assert (is_sorted(whole(p)));
    assert (history.size() <= 100000);
    printf("%d\n", int(history.size()));
    for (int result_i : history) {
        printf("%d\n", result_i);
    }
    return 0;
}


Measured memory_bytes: 764
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for(int i = 0; i < (n); i++)
#define rep1(i, n) for(int i = 1; i <= (n); i++)
#define co(x) cout << (x) << "\n"
#define cosp(x) cout << (x) << " "
#define ce(x) cerr << (x) << "\n"
#define cesp(x) cerr << (x) << " "
#define pb push_back
#define mp make_pair
#define Would
#define you
#define please

//ほんと全く分からなかったなぁ

ll mod = 1e9 + 7;

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


	int N, M;
	cin >> N >> M;
	int A[1000], B[1000];
	rep(i, N) cin >> A[i];
	rep(i, M) cin >> B[i];
	sort(A, A + N);
	reverse(A, A + N);
	sort(B, B + M);
	reverse(B, B + M);

	int Aima = 0;
	int Bima = 0;
	ll kotae = 1;
	int nokori = 0;

	for (int i = N * M; i >= 1; i--) {
		if (Aima != N && A[Aima] == i && Bima != M && B[Bima] == i) {
			nokori += Aima + Bima;
			Aima++;
			Bima++;
		}
		else if (Aima != N && A[Aima] == i) {
			kotae = kotae * Bima % mod;
			nokori += Bima - 1;
			Aima++;
		}
		else if (Bima != M && B[Bima] == i) {
			kotae = kotae * Aima % mod;
			nokori += Aima - 1;
			Bima++;
		}
		else {
			kotae = kotae * nokori % mod;
			nokori--;
		}
		if (Aima != N && A[Aima] == i) kotae = 0;
		if (Bima != M && B[Bima] == i) kotae = 0;
	}

	co(kotae);

	Would you please return 0;
}

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

int main() {
  int N; 
  cin >> N;
  vector<int> V(N);
  for (int i = 0; i < N; i++)
    cin >> V.at(i);
  
  int count = 100000;
  for (int j = 0; j < N; j++) {
    int a = 0,b = 0;
    for (int k = 0; k < j + 1; k++)
      a += V.at(k);
    for (int l = j + 1; l < N; l++)
      b += V.at(l);
    if (abs(a - b) < count)
      count = abs(a - b);
  }
  
  cout << count << endl;
    
 
}

Measured memory_bytes: 3628
/*
Hanit Banga
Problem: 
*/

#include <iostream>
#include <vector>

using namespace std;

#define pb push_back
#define fast_cin() ios_base::sync_with_stdio(false)

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

const int N = 1e5 + 5;

ll a[N], best[N], sum[N];

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

	best[0] = 0;
	sum[0] = 0;
	for (int i = 1; i <= n; ++i)
	{
		cin >> a[i];
		best[i] = best[i-1];
		sum[i] += sum[i-1]  + a[i];

		if (a[i] > 0)
			best[i] += a[i];
	}

	ll ans = 0;

	for (int i = 1; i+k <= n+1; ++i)
	{
		int r = i+k-1;
		ans = max(ans, max(sum[r]-sum[i-1], 0ll) + best[i-1] + best[n] - best[r]);
	}

	cout << ans;
}

Measured memory_bytes: 2688
package main

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

func main() {
	scanner := bufio.NewScanner(os.Stdin)
	scanner.Split(bufio.ScanWords)
	var N, C int
	scanner.Scan()
	fmt.Sscanf(scanner.Text(), "%d", &N)
	scanner.Scan()
	fmt.Sscanf(scanner.Text(), "%d", &C)

	D := make([][]int, C+1)
	for i := 1; i <= C; i++ {
		D[i] = make([]int, C+1)
		for j := 1; j <= C; j++ {
			scanner.Scan()
			fmt.Sscanf(scanner.Text(), "%d", &D[i][j])
		}
	}

	color := make([][]int, N)
	for i := 0; i < N; i++ {
		color[i] = make([]int, N)
		for j := 0; j < N; j++ {
			scanner.Scan()
			fmt.Sscanf(scanner.Text(), "%d", &color[i][j])
		}
	}

	change := make([][]int, 3)
	for i := 0; i < len(change); i++ {
		change[i] = make([]int, C+1)
	}

	for i := 0; i < N; i++ {
		for j := 0; j < N; j++ {
			for nextCol := 1; nextCol <= C; nextCol++ {
				change[(i+j)%3][nextCol] += D[color[i][j]][nextCol]
			}
		}
	}
	//fmt.Println(change)

	ans := math.MaxInt64
	for c1 := 1; c1 < C+1; c1++ {
		for c2 := 1; c2 < C+1; c2++ {
			if c2 == c1 {
				continue
			}
			for c3 := 1; c3 < C+1; c3++ {
				if c3 == c1 || c3 == c2 {
					continue
				}
				ans = min(ans, change[0][c1]+change[1][c2]+change[2][c3])
			}
		}
	}
	fmt.Println(ans)
}

func min(ns ...int) int {
	ret := math.MaxInt64
	for _, n := range ns {
		if n < ret {
			ret = n
		}
	}
	return ret
}


Measured memory_bytes: 4864
#include<bits/stdc++.h>
#define rep(i,a,b) for(int i=a;i<b;i++)
#define rrep(i,a,b) for(int i=a;i>=b;i--)
#define fore(i,a) for(auto &i:a)
#define all(x) (x).begin(),(x).end()
//#pragma GCC optimize ("-O3")
using namespace std; void _main(); int main() { cin.tie(0); ios::sync_with_stdio(false); _main(); }
typedef long long ll; const int inf = INT_MAX / 2; const ll infl = 1LL << 60;
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; }
//------------------------------------------------------------------------------
const int MAX_DIGIT = 50;
ll dp[100][2]; // dp[上から i 桁まで][smaller]
//------------------------------------------------------------------------------
void _main()
{
    int N;
    ll K;
    cin >> N >> K;
    vector<ll> A(N);
    rep(i, 0, N) cin >> A[i];

    memset(dp, -1, sizeof(dp)); // DP 配列を -1 で初期化
    dp[0][0] = 0; // 初期条件
    rep(d, 0, MAX_DIGIT)
    {
        const ll mask = 1LL << (MAX_DIGIT - d - 1);

        // A で元々 d 桁目にビットが立っているものの個数
        int num = 0;
        rep(i, 0, N) if (A[i] & mask) ++num;

        // X の d 桁目を 0, 1 にしたときのコスト
        const ll cost0 = mask * num;
        const ll cost1 = mask * (N - num);

        // smaller -> smaller
        if (dp[d][1] != -1)
        {
            chmax(dp[d + 1][1], dp[d][1] + max(cost0, cost1)); // 0 でも 1 でも自在に大きい方
        }

        // exact -> smaller
        if (dp[d][0] != -1)
        {
            if (K & mask) // K の d 桁目が 1 だったら、X の d 桁目は 0 にする
            {
                chmax(dp[d + 1][1], dp[d][0] + cost0);
            }
        }

        // exact -> exact（K にぴったり合わせる）
        if (dp[d][0] != -1)
        {
            if (K & mask) chmax(dp[d + 1][0], dp[d][0] + cost1);
            else chmax(dp[d + 1][0], dp[d][0] + cost0);
        }
    }
    cout << max(dp[MAX_DIGIT][0], dp[MAX_DIGIT][1]) << endl;
}


Measured memory_bytes: 1024
def main():
  N, W = list(map(int, input().split()))
  Data = []
  su = 0
  for i in range(N):
    t = list(map(int, input().split()))
    su += t[1]
    Data.append(t)
  
  DP = [int(10e12) if i != Data[0][1] else Data[0][0] for i in range(su + 1)]
  DP[0] = 0
  
  for i in range(1, N):
    for j in range(su - Data[i][1], -1, -1):
      k = j + Data[i][1]
      DP[k] = min(DP[j] + Data[i][0], DP[k])
      
  for i in range(su, -1, -1):
    if DP[i] <= W:
      print(i)
      break
  
main()


Measured memory_bytes: 45936
/*																													   
 Templatka c++ Kacper Fis																							   																											   //
*/																													  																						   
#include <bits/stdc++.h>																							   
																													   
using namespace std; 																								   
																													   
const int INF = 1000000001;																						   
const float PI = 3.14;	
const int mod = 1e9+7;																							   
typedef long long LL;																								   
																													   
typedef vector<int> vi;																								   
typedef list<int> li;																								   
typedef queue<int> qi; 																								   
typedef pair<int,int> ii; 																							   
typedef map<string,int> msi; //np msi['nazwa'] = 'liczba'															   
typedef vector<ii> vii; //vector par<int>, do tworzenia tablicy dla grafów wagowych #dijkstra #Bellman_Ford			   
typedef priority_queue< ii, vector<ii>, greater<ii> > pq; //kolejka priorytetowa vectorów par(top()=min) #dijkstra																													   																				   list<int>::iterator it;																								   
																				   
vector<ii>::iterator iter;																							   
																													   																				   
#define print_list(x) for(it = (x).begin(); it != (x).end(); it++) {cout << *it << " ";}							   
#define print_vector(x) for(it2 = (x).begin(); it2 != (x).end(); it2++) {cout << *it2 << " ";}						   
#define search_list(x) for(it = (x).begin(); it != (x).end(); it++)													   
#define search_vector(x) for(it2 = (x).begin(); it2 != (x).end(); it2++);											   
#define pb(x) push_back(x) 																							   
#define pf(x) push_front(x)																							   
#define mp(x, y) make_pair(x, y)                                                                                       
///////////////////////////////////////////////GLOBAL DEFINITIONS//////////////////////////////////////////////////////


///////////////////////////////////////////////FUNCTIONS/////////////////////////////////////////////////////////////


/////////////////////////////////////////////////////MAIN////////////////////////////////////////////////////////////////
int main(int argc, char* argv[])																					 
{ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);                  												       
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
	
	int tab[3];
	for(int i = 0; i < 3; i++){
		cin >> tab[i];
	}
	
	sort(tab, tab+3);
	
	cout << (tab[0] * tab[1]) / 2 << endl;
	
	

						
	return 0;
}


Measured memory_bytes: 256
// Ver19.03
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#define INF 1 << 29
#define LLINF 4545454545454545454
#define MOD 1000000007
#define ll long long
#define ull unsigned long long
#define MAX(a, b) ((a) > (b) ? (a) : (b))
#define MIN(a, b) ((a) < (b) ? (a) : (b))
int upll(const void *a, const void *b) { return *(ll *)a < *(ll *)b ? -1 : *(ll *)a > *(ll *)b ? 1 : 0; }
int downll(const void *a, const void *b) { return *(ll *)a < *(ll *)b ? 1 : *(ll *)a > *(ll *)b ? -1 : 0; }
void sortup(ll *a, int n) { qsort(a, n, sizeof(ll), upll); }
void sortdown(ll *a, int n) { qsort(a, n, sizeof(ll), downll); }

int main()
{
  ll n, flag = 0;
  char c;
  scanf("%lld", &n);
  for (int i = 0; i < n; i++)
  {
    scanf("%c", &c);
    if (c == 'Y')
      flag++;
  }
  puts(flag ? "Four" : "Three");
  return 0;
}

Measured memory_bytes: 128
#include <stdio.h>

int main(void) {
  int a, b, ans;
  char c;
  while( 1 ) {
    scanf("%d %c %d", &a, &c, &b);
    if(c == '+') ans = a + b;
    else if(c == '-') ans = a - b;
    else if(c == '*') ans = a * b;
    else if(c == '/') ans = a / b;
    else break;
    printf("%d\n", ans);
  }
  return 0;
}


Measured memory_bytes: 2728
import math


def main():
    num = int(input())
    data = [list(map(int, input().split())) for i in range(num - 1)]

    for i in range(num - 1):
        c, s, f = data[i]
        now_time = s + c
        for j in range(i + 1, num - 1):
            c_now, s_now, f_now = data[j]
            if now_time <= s_now:
                now_time = s_now + c_now
            else:
                now_time = math.ceil(now_time / f_now) * f_now + c_now
        print(now_time)
    print(0)



if __name__ == '__main__':
    main()


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


int main() {
  string s;
  cin >> s;
  if(s.at(0)=='9'||s.at(1)=='9'){
    cout<<"Yes"<<endl;
  }
  else{
    cout<<"No"<<endl;
  }
}



Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define MAXN 3000
#define LL long long int

int N, a[MAXN + 3];
LL dp[MAXN + 3][MAXN + 3], total;

LL solve(int l, int r) {
    if (l > r)
        return 0;
    
    if (dp[l][r] != -1)
        return dp[l][r];

    LL lft = a[l] + min(solve(l + 2, r), solve(l + 1, r - 1));
    LL rght = a[r] + min(solve(l, r - 2), solve(l + 1, r - 1));

    return dp[l][r] = max(lft, rght);
}

int main() {
    cin >> N;

    total = 0;
    for (int i = 1; i <= N; i++) {
        cin >> a[i];
        total += a[i];
    }

    memset(dp, -1, sizeof(dp));

    cout << 2 * solve(1, N) - total << endl;
}


Measured memory_bytes: 70784
parseInt(x) = parse(Int, x)
parseMap(x::Array{SubString{String},1}) = map(parseInt, x)
function root(uf::Array{Int,1},x)
	s=x
	while uf[s]>0
		s=uf[s]
	end
	s
end
function same(uf::Array{Int,1},x,y)
	root(uf,x)==root(uf,y)?true:false
end
function unite(uf::Array{Int,1},x,y)
	l = root(uf,x)
	r = root(uf,y)
	if l < r
		uf[l] += uf[r]
		uf[r] = l
	elseif l > r
		uf[r] += uf[l]
		uf[l] = r
	end
end


function main()
	mod = 10^9+7
	n,k = readline() |> split |> parseMap
	if n == 1
		println(k)
	else
	e = [Int[] for i in 1:n]
	for i in 1:n-1
		a,b = readline() |> split |> parseMap
		push!(e[a],b)
		push!(e[b],a)
	end
	head = [i for i in 1:n]
	npr = zeros(Int,n)
	npr[1] = n
	for i in 2:n
		npr[i] = (npr[i-1]*i)%mod
	end
	d = Int[length(e[i]) for i in 1:n]
	x = -ones(Int,n)
	z = k-1
	for i in 1:d[1]-1
		z = (z*(k-1-i))%mod
	end
	x[1] = z
	stack = Int[]
	for i in e[1]
		push!(stack,i)
	end
	while !isempty(stack)
		now = shift!(stack)
		z = k-2
		for i in 1:d[now]-2
			z = z*(k-2-i)%mod
		end
		for i in e[now]
			if x[i] < 0
				push!(stack,i)
				head[i] = now
			end
		end
		if length(e[now])==1&&now!=1
			x[now] = 1
		else
			x[now] = z
		end
	end
	s = k
	for i in 1:n
		s = s*x[i]%mod
	end
	println(s)
end
end

main()

Measured memory_bytes: 174352
//g++  7.4.0

#include <bits/stdc++.h>
using namespace std;

void dfs(vector<int> g[],bool visited[],int dp[],int x){
    visited[x] = true;
    for(int i=0;i<g[x].size();i++){
    if(!visited[g[x][i]])
             dfs(g,visited,dp,g[x][i]);
                
    dp[x] = max(dp[x],1+dp[g[x][i]]);
      //cout<<dp[x]<<" ";
   }
}
int main()
{
   int n,m;
    cin>>n>>m;
    vector<int> g[n+1];
    int start =1;
    for(int i =0;i<m;i++){
        int u,v;
        cin>>u>>v;
        
        g[u].push_back(v);
    }
  
    int dp[n+1];
   memset(dp,0,sizeof dp);
    bool visited[n+1];
    memset(visited,false,sizeof visited);
    
    for(int i =1;i<=n;i++)
    {
        if(!visited[i])
            dfs(g,visited,dp,i);
    }
    int res = 0;
    for(int i =1;i<=n;i++){
      //cout<<dp[i]<<" ";
            res = max(res,dp[i]);
    }
    cout<<res;
}

Measured memory_bytes: 9600
n, m = gets.strip.split.map(&:to_i)
ab = readlines.map {|line| line.strip.split.map(&:to_i) }
ab = ab.sort_by(&:last)

result = 0
until ab.empty?
  cb = ab.shift.last
  cut = cb
  result += 1
  ab = ab.reject {|a, _| a < cut }
end

p result


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

int main(){
  int N, M;
  cin >> N >> M;
  int A[N];
  rep(i, N)
    cin >> A[i];

  int sum = 0;
  rep(i, N)
    sum += A[i];

  double jud = (double)sum/(4*M);

  int count = 0;

  rep(i, N)
    if(A[i] >= jud)
      count++;

  if(count>=M)
    cout <<"Yes"<<endl;
  else
    cout<<"No"<<endl;
    
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <string.h>
#include <vector>
#include <math.h>
//s#define rep(i, n) for (int i = 0; i < (n); i++)
#define MAX 10000

using namespace std;

#define ll long long
#define pb push_back
#define mp make_pair
#define all(a) (a).begin(),(a).end()
#define rep(i,a,n) for(int i=a; i<n; i++)
#define r0 return 0
#define INF (int)1e15
#define MOD 1000000007

#define access(i) a[i/3][i%3]

int main(){

  long long n,d;
  cin>>n>>d;

  long long cnt=0;

  while(n--){

   long long x,y;
   cin>>x>>y;

   long long ans = x*x+y*y;

   double ani = sqrt(ans);

   if(ani <= d)
    cnt++;
  }

  cout<<cnt<<endl;

return 0;
}


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

class Dice{
public:
    int s[6];
    // s[0] : top
    // s[1] : south  front
    // s[2] ; east  right
    // s[3] : west  left
    // s[4] : north  back
    // s[5] : bottom
    string str = "EWNSRL";
    int d[6][4] = {{0, 3, 5, 2}, {0, 2, 5, 3}, {0, 1, 5, 4}, {0, 4, 5, 1}, {1, 2, 4, 3}, {1, 3, 4, 2}};
    void roll(char c){
        //  N
        // W E
        //  S
        int idx = str.find(c);
        int b = s[d[idx][0]];
        for(int i = 0; i < 3; i++){
            s[d[idx][i]] = s[d[idx][i + 1]];
        }
        s[d[idx][3]] = b;
    }
    int hash(){
        int res = 0;
        for(int i = 0; i < 6; i++) res = res * 256 + s[i];
        return res;
    }
};

/*
verified
https://onlinejudge.u-aizu.ac.jp/courses/lesson/2/ITP1/all/ITP1_11_A
*/

int main(){
    Dice d;
    for(int i = 0; i < 6; i++){
        cin >> d.s[i];
    }
    string s;
    cin >> s;
    for(int i = 0; i < s.size(); i++){
        d.roll(s[i]);
    }
    cout << d.s[0] << endl;
}


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

typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef pair<int,int> ii;
typedef pair<int, ii> iii;
typedef vector<ii> vii;
typedef vector<vi> vvi;

#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define LSOne(i) ((i) & -(i))

const int MAXN = 1e5+100;
ll n, a[MAXN], b[MAXN], ans = 0;

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

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

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

    for (int i = 0; i < n; i++) {
        int kl = min(a[i], b[i]);
        ans += kl;
        a[i] -= kl;
        b[i] -= kl;
        kl = min(a[i+1], b[i]);
        ans += kl;
        a[i+1] -= kl;
    }

    cout << ans << endl;

    return 0;
}


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

#define be(v) (v).begin(),(v).end()
#define pb(q) push_back(q)
typedef long long ll;
using namespace std;

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll n;
    cin>>n;
    ll dp[n+1];
    dp[0]=0;
    for(int i=1;i<=n;i++){
        dp[i]=dp[i-1]+1;
    }
    for(int i=1;i<=n;i++){
        for(int j=1;j<=i;j*=6){
            dp[i]=min(dp[i-j]+1,dp[i]);
        }
        for(int j=1;j<=i;j*=9){
            dp[i]=min(dp[i-j]+1,dp[i]);
        }
    }
    cout << dp[n]<<endl;
    return 0;
}



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


int main() {
	// your code goes here
    cin>>n;
    int h[n+1];
    for(int i = 1; i<=n;++i) cin>>h[i];
    int dp1=0, dp2= abs(h[2]-h[1]),dp3;
    for(int i=3;i<=n;++i)
    {   dp3= min( abs(h[i]-h[i-2])+dp1,  abs(h[i]-h[i-1])+dp2 );

        dp1=dp2;
        dp2=dp3;
    }
    
    if(n==2) cout<<abs(h[2]-h[1]);
    else cout<<dp3;
	return 0;
}


Measured memory_bytes: 640
// inputに入力データ全体が入る
function Main(input) {
	// 1行目がinput[0], 2行目がinput[1], …に入る
	input = input.split("\n");
    const numStrListList = input.map(str => str.split(" "));
    const numListList = numStrListList.map(ls => (ls.map(x => parseInt(x, 10))));
  
    const N = numListList[0][0];
    const M = numListList[0][1];

    const shopInfoList = [];
    // リストを作る
    for (var i = 1; i < 1 + N; i++) {
        shopInfoList.push({
          price: numListList[i][0],
          count: numListList[i][1]
        });
    }
    // ソートする
    shopInfoList.sort((a, b) => a.price - b.price);
  
    var totalPrice = 0;
    var totalCount = 0;
	for (var i = 0; i < shopInfoList.length; i++) {
      var price = shopInfoList[i].price;
      var count = shopInfoList[i].count;
      
      var buyCount = Math.min(count, M - totalCount);
      totalPrice += buyCount * price;
      totalCount += buyCount;
      
      if (totalCount >= M) {
        break;
      }
    }
  
    console.log(totalPrice);
}
//*この行以降は編集しないでください（標準入出力から一度に読み込み、Mainを呼び出します）
Main(require("fs").readFileSync("/dev/stdin", "utf8"));

Measured memory_bytes: 65180
n, a, b = map(int, input().split())
l = list(map(int, input().split()))
ans = 0
for i in range(n-1):
  if (l[i+1]-l[i])*a <= b:
    ans += (l[i+1]-l[i])*a
  else:
    ans += b
print(ans)

Measured memory_bytes: 14252
import numpy as np

n = int(input())
a = input().split()
nl=np.array(a, dtype=int)
count=0

for i in range(0,n-2):
  for j in range(i+1,n-1):
    for k in range(j+1,n):
      three=[nl[i],nl[j],nl[k]]
      three.sort()
      if (three[0] != three[1] and three[1]!=three[2] and three[2] < three[0]+three[1]): count+=1

print (count)

Measured memory_bytes: 27136
/*
auth - @sportykush
*/

#include <bits/stdc++.h>
using namespace std;
// #include <ext/pb_ds/assoc_container.hpp> 
// #include <ext/pb_ds/tree_policy.hpp> 
// typedef tree<ll,null_type,less<ll>,rb_tree_tag,tree_order_statistics_node_update> ordered_set; 
// using namespace __gnu_pbds;

typedef long long int ll;
typedef long double ld;

//#define mp make_pair
#define bug(v)                    cerr<<#v<<" = "<<(v)<<endl;
#define bug2(v1,v2)               cerr<<#v1<<" = "<<(v1)<< ' ' << #v2<<" = "<<(v2)<<endl;
#define ERASE(x)                  x.erase(unique(x.begin(),x.end()),x.end())
#define pb                        emplace_back
#define vii                       vector<int>
#define vll                       vector<ll>
#define vpll                      vector< pair <ll,ll> >
#define pll                       pair <ll,ll>
#define pii                       pair <int,int>
#define pq                        priority_queue< int >
#define khtm                      "\n"
#define F                         first
#define S                         second
#define fr(i,a,n)                 for(i=a;i<n;i++)
#define mem(arr,l)                memset(arr,l,sizeof arr)
#define ALL(x)                    x.begin(), x.end()
#define frr(i,a,n)                for(i=n-1;i>=a;i--)
#define fast                      ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define testcase                  ll T; cin>>T; while(T--)


const double pi = 3.14159265359;
const int MAX = 1e6 +2;
const ll inf =  1e18;
const int N = 1010;
const int dx[] = {-1, 0, 1, 0, 1, -1, -1, 1};
const int dy[] = {0, 1, 0, -1, 1, -1, 1, -1};
//const ll mod = 998244353;
const ll mod = 1000000007;
inline ll add(ll a,ll b){a+=b;if(a>=mod)a-=mod;return a;}
inline ll mul(ll a,ll b){return (((a+mod)%mod)*(b+mod)%mod)%mod;}
inline ll power(ll a,ll b){ll rt=1;while(b>0){if(b&1)rt=mul(rt,a);a=mul(a,a);b>>=1;}return rt;}
inline ll modInverse(ll n, ll p){ return power(n, p-2)%p; }

/*
important builtin functions
__gcd(value1, value2)
__builtin_ffs(x)
  Number of leading zeroes: __builtin_clz(x)
  Number of trailing zeroes : __builtin_ctz(x)
  Number of set bits: __builtin_popcount(x)
*/
 
void stArt()
{
	#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
	#endif
}
void eNd()
{
	#ifndef ONLINE_JUDGE
  	cout<<"\nTime Elapsed : " << 1.0*clock() / CLOCKS_PER_SEC << " s";
  	#endif
}

//////////////////// start /////////////////////////////////
 

ll i,j,k,l,m,r,n;
// ll a[MAX],b[MAX];
ld arr[3000];
ld dp[3000][3000];
ld solve(ll pos, ll cnthead) {
	if (pos >= n) 
	{
		if (cnthead >= (n + 1)/2)
			return 1;
		return 0;
	}
	ld &ans = dp[pos][cnthead];
	if (ans > -1)
		return ans;
 
	return ans = arr[pos] * solve(pos + 1, cnthead + 1) + (1 - arr[pos]) * solve(pos + 1, cnthead);
}

int main()
{
 
stArt();
fast
//cout << setprecision(15) << fixed;

cin >> n;
 
	fr(i,0,n)
		cin >> arr[i];
	mem(dp,-1);
	cout << setprecision(10) << fixed;
	cout << solve(0, 0);
  
eNd();
	return 0;
 
}

Measured memory_bytes: 144716
use std::str::FromStr;
use std::collections::{HashMap,HashSet,VecDeque,BinaryHeap};
use std::cmp::{max,min,Ordering};
use std::io::Read;

fn main() {

    let mut buf = String::new();
    std::io::stdin().read_to_string(&mut buf).unwrap();
    let mut buf_it = buf.split_whitespace();

    let N = buf_it.next().unwrap().parse::<usize>().unwrap();
    let A = (0..N).map(|_| buf_it.next().unwrap().parse::<isize>().unwrap()).collect::<HashSet<_>>();

    let M = buf_it.next().unwrap().parse::<usize>().unwrap();
    let B = (0..M).map(|_| buf_it.next().unwrap().parse::<isize>().unwrap()).collect::<HashSet<_>>();

    let ans = A.intersection(&B).collect::<HashSet<_>>().len();
    println!("{}",ans);
}


Measured memory_bytes: 11076
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10 ** 7)

n = int(input())

def binary_search(ok, ng, cond):
    while abs(ok - ng) > 1:
        mid = (ok + ng) // 2
        if cond(mid):
            ok = mid
        else:
            ng = mid
    return ok

candidate = binary_search(n, 0, lambda x: x * 1.08 >= n)
if n == int(candidate * 1.08):
    print(candidate)
else:
    print(':(')


Measured memory_bytes: 61940
#include <cstdlib>
#include <cctype>
#include <cstring>
#include <cstdio>
#include <cmath>
#include <algorithm>
#include <vector>
#include <string>
#include <iostream>
#include <sstream>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <fstream>
#include <numeric>
#include <iomanip>
#include <bitset>
#include <list>
#include <stdexcept>
#include <functional>
#include <utility>
#include <ctime>
using namespace std;
typedef long long LL;
typedef unsigned long long ULL;;
#define MEM(a,b) memset((a),(b),sizeof(a))
const LL INF = 1e9 + 7;
const int N = 1e3 + 10;
LL dis[N];
vector<tuple<int, int, int>> vp;
LL refrain(int n, int cnt = 1)
{
	while (cnt--)
	{
		for (auto& p : vp)
		{
			int x, y, w;
			tie(x, y, w) = p;
			dis[y] = max(dis[y], dis[x] + w);
		}
	}
	return dis[n];
}
int main()
{
	//freopen("input.txt", "r", stdin);
	//freopen("output.txt", "w", stdout);
	int n, m;
	cin >> n >> m;
	MEM(dis, 0xdf);
	dis[1] = 0;
	while (m--)
	{
		int a, b, c;
		cin >> a >> b >> c;
		vp.emplace_back(a, b, c);
	}
	LL ans1 = refrain(n, 2 * n);
	LL ans2 = refrain(n, 2 * n);
	if (ans1 == ans2) cout << ans1 << endl;
	else cout << "inf" << endl;
	return 0;
}

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

using namespace std;

int main(){
	int A,B,C,X,Y;
	int ans=0;
	int temp;

	scanf("%d %d %d %d %d",&A,&B,&C,&X,&Y);

	if(2*C<A+B){
		temp = min(X,Y);
		ans += C*2*temp;
		X -= temp;
		Y -= temp;
		if(X!=0){
			if(2*C<A){
				ans += C*2*X;
			}else{
				ans += A*X;
			}
		}else{
			if(2*C<B){
				ans += C*2*Y;
			}else{
				ans += B*Y;
			}
		}
	}else{
		ans = (A*X) + (B*Y);
	}
	printf("%d",ans);

	return 0;
}

Measured memory_bytes: 128
macro_rules! input {
  (source = $s:expr, $($r:tt)*) => {
    let mut iter = $s.split_whitespace();
    input_inner!{iter, $($r)*}
  };
  ($($r:tt)*) => {
    let mut s = {
      use std::io::Read;
      let mut s = String::new();
      std::io::stdin().read_to_string(&mut s).unwrap();
      s
    };
    let mut iter = s.split_whitespace();
    input_inner!{iter, $($r)*}
  };
}

macro_rules! input_inner {
  ($iter:expr) => {};
  ($iter:expr, ) => {};

  ($iter:expr, $var:ident : $t:tt $($r:tt)*) => {
    let $var = read_value!($iter, $t);
    input_inner!{$iter $($r)*}
  };
}

macro_rules! read_value {
  ($iter:expr, ( $($t:tt),* )) => {
    ( $(read_value!($iter, $t)),* )
  };

  ($iter:expr, [ $t:tt ; $len:expr ]) => {
    (0..$len).map(|_| read_value!($iter, $t)).collect::<Vec<_>>()
  };

  ($iter:expr, chars) => {
    read_value!($iter, String).chars().collect::<Vec<char>>()
  };

  ($iter:expr, usize1) => {
    read_value!($iter, usize) - 1
  };

  ($iter:expr, $t:ty) => {
    $iter.next().unwrap().parse::<$t>().expect("Parse error")
  };
}

fn main() {
  input! {
    a: usize, b: usize,
  }
  
  use std::iter;
  let sa: String = iter::repeat(format!("{}", a)).take(b).collect();
  let sb: String = iter::repeat(format!("{}", b)).take(a).collect();
  println!("{}", if sa < sb { sa } else { sb });
}

Measured memory_bytes: 4352
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		
		
		Scanner sc = new Scanner(System.in);
		
		int n = sc.nextInt();
		
		double num;
		num = Math.pow(n,3);
		
		System.out.println((int)num);
		
		
		
	}
}



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

int main(){
    int n, temp, count = 0;
    cin >>n;
    int num[n];
    for(int i = 0; i < n; i++){
        cin >>num[i];
    }
    bool flg = 1;
    while(flg){
        flg = 0;
        for(int i = sizeof(num)/sizeof(int); i>0; i--){
            if(num[i] < num[i-1]){
                temp = num[i-1];
                num[i-1] = num[i];
                num[i] = temp;
                flg = 1;
                count++;
            }
        }
    }
    for(int i = 0; i < sizeof(num)/sizeof(int); i++){
        if(i != 0)cout << " ";
        cout << num[i];
    }
    cout << endl;
    cout << count << endl;
}


Measured memory_bytes: 3080
#include<iostream>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<queue>
#include<stack>
#include<vector>
#include<map>
using namespace std;
const int maxn = 1e5+10;

int read(){
	int x=0,f=1;
	char c=getchar();
	while(!isdigit(c)){if(c=='-')f=-1;c=getchar();}
	while(isdigit(c)){x=(x<<3)+(x<<1)+c-48;c=getchar();}
	return x*f;
}

int to[maxn<<1],net[maxn<<1],h[maxn],e=1;
inline void add(int x,int y){
	to[++e]=y;net[e]=h[x];h[x]=e;
}

int k,m,n,u,v;
int fa[maxn][21],max_[maxn][21],dep[maxn];
inline void dfs(int x){
	dep[x]=dep[fa[x][0]]+1;max_[x][0]=dep[x];
	for(register int i=1;i<=19;i++){
		fa[x][i]=fa[fa[x][i-1]][i-1];
	}
	for(register int i=h[x];i;i=net[i]){
		int y=to[i];
		if(y==fa[x][0])continue;
		fa[y][0]=x;
		dfs(y);
		max_[x][0]=max(max_[x][0],max_[y][0]);
	}
	return;
}

inline void dfss(int x){
	for(register int i=1;i<=19;i++){
		max_[x][i]=max(max_[x][i-1],max_[fa[x][i-1]][i-1]);
	}
	for(register int i=h[x];i;i=net[i]){
		int y=to[i];
		if(y==fa[x][0])continue;
		dfs(y);
	}
}
	
int main(){
	n=read();u=read();v=read();
	for(register int i=1;i<n;i++){
		int x=read(),y=read();
		add(x,y);add(y,x);
	}
	dfs(v);
	dfss(v);
	int p=(dep[u]+dep[v])/2+1,ans=0,x=u;
	for(register int i=19;i>=0;i--){
		if(dep[fa[x][i]]<p)continue;
		ans=max(ans,max_[x][i]);
		x=fa[x][i];
	}
	ans=max(ans,max_[x][0]);
	if(ans==2){puts("0");return 0;}
	if(dep[u]%2==1)printf("%d\n",ans-2);
	else printf("%d\n",ans-2);
	return 0;
}

Measured memory_bytes: 21504
#include <stdio.h>
 
int main() {
 
  int n,m,p;
  int b,c;
  int i,j,k;
  int sum;
 
  while (1) {
    b = 0;
    sum = 0;
    int a[101] = {0};
    double p;
    c = 0;
    
 
    scanf("%d %d %lf",&n,&m,&p);
 
    if(n == 0 && m ==0 && p ==0)break;
 
    for(i = 0; i<n; i++) {
      scanf("%d", &a[i]);
      b = b + a[i];
    }
 
    b = b * 100;
    p = p / 100;
    //printf("p = %f",p);
 
    if(a[m-1] == 0) {
      c = 0;
    } else {
      p = b - b*p;
      c = p / a[m-1];
    }
 
    printf("%d\n",c);
     
 
  }
 
  return 0;
}

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

using namespace std;

const int maxN = 1 << 18;

int n;
int a[maxN][2];

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

    cin >> n;

    for(int i = 0; i < 1 << n; ++i)
        cin >> a[i][0];

    for(int i = 0; i < n; ++i){
        for(int j = 0; j < 1 << n; ++j){
            if((j & (1 << i)) == 0){
                int tmp = j | (1 << i);
                if(a[tmp][0] < a[j][0]){
                    a[tmp][1] = max(a[tmp][0], a[j][1]);
                    a[tmp][0] = a[j][0];
                }
                else
                    a[tmp][1] = max(a[tmp][1], a[j][0]);
            }
        }
    }

    int res = 0;
    for(int i = 1; i < 1 << n; ++i){
        res = max(res, a[i][0] + a[i][1]);
        cout << res << endl;
    }
}



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

signed main(){
  string O,E;
  cin>>O>>E;
  rep(i,O.size()){
    cout<<O[i];
    if(i<E.size())cout<<E[i];
  }
  cout<<endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <math.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep2(i, s, n) for (int i = (s); i < (int)(n); i++)
using ll = long long;
using vec = vector<int>;
using vec2 = vector<vector<int>>;
ll inf = pow(2, 62);

int main()
{
    int n;
    cin >> n;
    vec a(n);
    rep(i, n)
    {
        cin >> a[i];
    }
    int count = 0;
    rep(i, n)
    {
        if (i % 2 == 0 && a[i] % 2 == 1)
        {
            count++;
        }
    }
    cout << count;
}

Measured memory_bytes: 3628
#include<iostream>
#include<vector>
#include<string>
#include<map>
#include<algorithm>
#include<cmath>
using namespace std;

typedef long long int llint;

int main(){
	int N;
	cin >> N;
	llint A[N];
	for(int i=0;i<N;i++){
		cin>>A[i];
	}

	llint S=0;
	for(int i=0;i<N;i++){
		S^=A[i];
	}
	for(int i=0;i<N;i++){
		cout << (A[i]^S) << " ";
	}
	cout << endl;
	return 0;
}


Measured memory_bytes: 5084
#include<bits/stdc++.h>
using namespace std;
int read()
{
   int x=0,f=1;char ch=getchar();
   while (ch<'0'||ch>'9') {if (ch=='-') f=-1;ch=getchar();}
   while (ch>='0'&&ch<='9') x=(x<<1)+(x<<3)+ch-'0',ch=getchar();
   return x*f;
}
const int N=1005;
const int M=200005; 
vector<int> vec[N];
int now,x[M],y[M],n,m,vis1[N][N],vis2[N][N];
void dfs1(int x,int fa)
{
	for (int i=0;i<vec[x].size();i++)
	  if (vec[x][i]!=fa)
	  	 if (!vis1[now][vec[x][i]]) vis1[now][vec[x][i]]=x,dfs1(vec[x][i],x);
}
void dfs2(int x,int fa)
{
	for (int i=vec[x].size()-1;i>=0;i--)
	  if (vec[x][i]!=fa)
	  	 if (!vis2[now][vec[x][i]]) vis2[now][vec[x][i]]=x,dfs2(vec[x][i],x);
}
int main()
{
	n=read();m=read();
	for (int i=1;i<=m;i++) x[i]=read(),y[i]=read(),vec[x[i]].push_back(y[i]);
	for (int i=1;i<=n;i++) 
	{ 
	  now=i;vis1[now][now]=vis2[now][now]=1;//注意把起点的vis标记！ 
	  dfs1(i,-1);
	  dfs2(i,-1);
	}
	for (int i=1;i<=m;i++)
		puts(((vis1[y[i]][x[i]]!=0)^(vis1[x[i]][y[i]]!=x[i]||vis2[x[i]][y[i]]!=x[i]))?"diff":"same");
   return 0;
}


Measured memory_bytes: 12288
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <climits>
#include <cfloat>
#include <ctime>
#include <cassert>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <memory>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <sstream>
#include <complex>
#include <stack>
#include <queue>
#include <numeric>
#include <list>
#include <iomanip>


using namespace std;

#ifdef _MSC_VER
#define __typeof__ decltype
template <class T> int __builtin_popcount(T n) { return n ? 1 + __builtin_popcount(n & (n - 1)) : 0; }
#endif

#define foreach(it, c) for (__typeof__((c).begin()) it=(c).begin(); it != (c).end(); ++it)
#define all(c) (c).begin(), (c).end()
#define rall(c) (c).rbegin(), (c).rend()
#define CL(arr, val) memset(arr, val, sizeof(arr))

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

template <class T> void max_swap(T& a, const T& b) { a = max(a, b); }
template <class T> void min_swap(T& a, const T& b) { a = min(a, b); }

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

const double EPS = 1e-8;
const double PI = acos(-1.0);
const int dx[] = { 0, 1, 0, -1 };
const int dy[] = { 1, 0, -1, 0 };
bool valid_pos(int x, int y, int w, int h) { return 0 <= x && x < w && 0 <= y && y < h; }



int main()
{
	ios::sync_with_stdio(false);

	const int MAX = 1000000;
	static int phi[MAX + 1];

	for (int i = 0; i <= MAX; ++i)
		phi[i] = i;
	for (int i = 2; i <= MAX; ++i)
		if (phi[i] == i)
			for (int j = i; j <= MAX; j += i)
				phi[j] = phi[j] / i * (i - 1);

	static ll f[MAX + 1];
	f[1] = 2;
	for (int i = 2; i <= MAX; ++i)
		f[i] = f[i - 1] + phi[i];

	int t, n;
	cin >> t;
	while (t--)
	{
		cin >> n;
		cout << f[n] << endl;
	}
}

Measured memory_bytes: 12000
package main

import (
	"fmt"
)

func main() {
	var a, b int
	fmt.Scanf("%d %d", &a, &b)
	answer := leastCommonMultiple(a, b)
	fmt.Println(answer)
}

func leastCommonMultiple(a, b int) int {
	g := gcd(a, b)
	return a / g * b
}

func gcd(a, b int) int {
	if a < b {
		a, b = b, a
	}
	if b == 0 {
		return a
	}
	return gcd(b, a%b)
}


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

int n, m;
int p[200000];
int r[200000];
int Rank[200000];

int root(int x) {
    if (r[x] == x) {
        return x;
    } else {
        //r[x] = root(r[x]);
        //return r[x];
        return root(r[x]);
    }
}

void marge(int x, int y) {
    x = root(x);
    y = root(y);
    if (Rank[x] < Rank[y]) {
        r[x] = y;
    } else {
        r[y] = x;
        if (Rank[x] == Rank[y]) {
            Rank[x]++;
        }
    }
}

bool same(int x, int y) {
    return root(x) == root(y);
}

int main() {
    cin >> n >> m;
    for (int i = 1; i <= n; i++) {
        cin >> p[i];
        r[i] = i;
        Rank[i] = 0;
    }
    while (m--) {
        int x, y;
        cin >> x >> y;
        marge(x, y);
    }
    int ans = 0;
    for (int i = 1; i <= n; i++) {
        if (same(i, p[i])) {
            ans++;
        }
    }
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 1408
#include <iostream>
#include<stdio.h>
using namespace std;
void call(int n){
  int i = 1;
  while( ++i <= n ){
    int x = i;
    if ( x % 3 == 0 ){
        cout << " " << i;
        continue;
        }
    while(x){
        if ( x % 10 == 3 ){
            cout << " " << i;
            break;
        }
    x /= 10;
    }
  }
  cout << endl;
}
int main(){
    int n;
    cin >> n;
    call(n);
}


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

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

  map<int,int> mp;
  for(int i = 0; i < n; i++){
    int a;
    cin >> a;
    mp[a]++;
  }

  int c = 0;
  for(auto p: mp){
    int b = p.second;
    if(b % 2 == 0){
      c++;
    }
  }
  cout << mp.size() - c << endl;
}

Measured memory_bytes: 4992
from collections import defaultdict, Counter
from itertools import product, permutations, combinations, accumulate
from bisect import bisect_left, bisect
from heapq import heappop, heappush
from fractions import gcd
from math import ceil, floor


def input_list():
    return list(map(int, input().split()))


def input_int():
    return int(input())


N = int(input())
A_LI = input_list()
A_ACC = list(accumulate(A_LI))
MOD = 10 ** 9 + 7
ans = 0
for i in range(1, N):
    ans += A_LI[i] * A_ACC[i - 1]
print(ans % MOD)


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

int main(){

  
  int a;
  char s[10];
  scanf("%d", &a );
  scanf("%s", s );
  
  if(a>=3200){
    printf("%s",s);
  }else{printf("red");}
  
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <stdio.h>
#include <cmath>
#include <cctype>

using namespace std;

int main()
{
    string s;
    vector<int> cnt(30, 0);
    while (cin >> s)
    {
        for (int i = 0; i < s.size(); i++)
        {
            if (isalpha(s[i]))
            {
                if (islower(s[i]))
                {
                    s[i] = toupper(s[i]);
                }

                cnt[s[i] - 'A']++;
            }
        }
    }

    for (int i = 0; i < 26; i++)
    {
        cout << char('a' + i) << " : " << cnt[i] << endl;
    }

    return 0;
}


Measured memory_bytes: 3172
#include <iostream>
#include <string>
#include <algorithm>
#include <cstring>

using namespace std;

void CheckSameString(string w, char *q, int *count)
{
	if (w.size() == strlen(q) && strncmp(w.c_str(), q, w.size()) == 0)
		(*count)++;
}

int main()
{
	string w, t;
	getline(cin, w);
	
	while (1) 
	{
		string buf;
		getline(cin, buf);
		t += (buf + "\n");
		if (buf == "END_OF_TEXT")
			break;
	}
	
	std::transform(w.begin(), w.end(), w.begin(), ::tolower);
	std::transform(t.begin(), t.end(), t.begin(), ::tolower);
	
	char *TOKEN = " \t\n";
	
	char *q = strtok((char *)t.c_str(), TOKEN);
	if (q == NULL)
		return -1;
	int count = 0;
	CheckSameString(w, q, &count);
	
	while (1)
	{
		q = strtok(NULL, TOKEN);
		if (q == NULL)
			break;
		
		CheckSameString(w, q, &count);
	}
	
	cout << count << endl;
	
	return 0;
}

Measured memory_bytes: 1204
n, x = list(map(int, input().split()))

sizes = [1]

for i in range(n):
    sizes.append(2*sizes[i]+3)

prev = {}

def solve(n, x):
    if (n, x) in prev:
        return prev[(n, x)]
    else:
        if n == 0:
            return 1 if x == 1 else 0
        else:
            ans = 0
            if x == sizes[n]:
                ans = 2*solve(n-1, sizes[n-1]) + 1
            else:
                mid = sizes[n]//2 + 1

                if x == mid:
                    ans = solve(n-1, sizes[n-1]) + 1
                elif x < mid:
                    ans = solve(n-1, x-1)
                else:
                    ans = solve(n-1, sizes[n-1]) + 1 + solve(n-1, x-mid)

            prev[(n, x)] = ans
            return ans

print(solve(n, x))

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

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

	int n,k;
	cin>>n>>k;
	vector<int> A(n);
	for (int& e : A) cin >> e;
		sort(A.begin(), A.end());
	int ans = 0;
	for (int i = 0; i < k; ++i) ans += A[i];
	cout << ans << endl;
}

Measured memory_bytes: 3620