akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
using Int = long long;
#define REP(i, n) for (Int i = 0, max_i = (n); i < max_i; i++)
#define REPI(i, a, b) for (Int i = (a), max_i = (b); i < max_i; i++)
#define ALL(obj) begin(obj), end(obj)
#define RALL(obj) rbegin(obj), rend(obj)
#define fi first
#define se second
using ii = pair<Int, Int>;
template <class T> inline bool chmax(T& a, const T& b) {
    if (a >= b) return false;
    a = b;
    return true;
}
template <class T> inline bool chmin(T& a, const T& b) {
    if (a <= b) return false;
    a = b;
    return true;
}
struct in {
    int n;
    in() {}
    in(int n_) : n(n_){};
    template <class T> operator T() {
        T ret;
        cin >> ret;
        return ret;
    }
    template <class T> operator vector<T>() {
        vector<T> ret(n);
        for (int i = 0; i < n; i++) cin >> ret[i];
        return ret;
    }
};
struct SetupIO {
    SetupIO() { cin.tie(nullptr), ios::sync_with_stdio(false), cout << fixed << setprecision(20); }
} setup_io;

#ifdef _MY_DEBUG
#include "/Users/knshnb/.competitive_local.hpp"
#else
#define dump(...)
#endif

/**
 *    author:  knshnb
 *    created: Tue Dec  3 00:11:37 JST 2019
 **/

signed main() {
    Int n = in();
    string s = in();
    Int ans = 0;
    REP (x, 10) {
        Int cur0 = 0;
        while (cur0 < n && s[cur0] != '0' + x) cur0++;
        REP(y, 10) {
            Int cur1 = cur0 + 1;
            while (cur1 < n && s[cur1] != '0' + y) cur1++;
            REP(z, 10) {
                Int cur2 = cur1 + 1;
                while (cur2 < n && s[cur2] != '0' + z) cur2++;
                if (cur2 < n) ans++;
            }
        }
    }
    cout << ans << endl;
}


Measured memory_bytes: 384
N,D=map(int,input().split())
X=[list(map(int,input().split())) for i in range(N)]
import math
def dis(X,Y):
  return math.sqrt(sum([pow((x-y),2) for x,y in zip(X,Y)]))
ans=0
for i in range(N):
  for j in range(i+1,N):
    if dis(X[i],X[j]).is_integer():
      ans+=1
print(ans)

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

int a[100001];

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

	int x = 0;
    for (int i=0; i<N; i++) {
		x ^= a[i];
    }
	if (x == 0) {
        cout << "Yes" << endl;
        return 0;
    }
	else {
        cout << "No" << endl;
        return 0;
	}
	
	return 0;
}


Measured memory_bytes: 640
package main

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

var (
	readString func() string
	stdout     *bufio.Writer
)

func init() {
	readString = newReadString(os.Stdin)
	stdout = bufio.NewWriter(os.Stdout)
}

func newReadString(ior io.Reader) func() string {
	r := bufio.NewScanner(ior)
	r.Buffer(make([]byte, 1024), int(1e+11))
	r.Split(bufio.ScanWords)

	return func() string {
		if !r.Scan() {
			panic("Scan failed")
		}
		return r.Text()
	}
}

func readInt() int {
	return int(readInt64())
}

func readInt64() int64 {
	i, err := strconv.ParseInt(readString(), 0, 64)
	if err != nil {
		panic(err.Error())
	}
	return i
}

func readIntSlice(n int) []int {
	b := make([]int, n)
	for i := 0; i < n; i++ {
		b[i] = readInt()
	}
	return b
}

func readLengthAndSlice() []int {
	n := readInt()
	return readIntSlice(n)
}

func printf(f string, args ...interface{}) (int, error) {
	return fmt.Fprintf(stdout, f, args...)
}

func println(args ...interface{}) (int, error) {
	return fmt.Fprintln(stdout, args...)
}

func minInt(a, b int) int {
	if a < b {
		return a
	}
	return b
}

func minUint(a, b uint) uint {
	if a < b {
		return a
	}
	return b
}

func minInt64(a, b int64) int64 {
	if a < b {
		return a
	}
	return b
}

func minUint64(a, b uint64) uint64 {
	if a < b {
		return a
	}
	return b
}

func maxInt(a, b int) int {
	if a < b {
		return b
	}
	return a
}

func maxUint(a, b uint) uint {
	if a < b {
		return b
	}
	return a
}
func maxInt64(a, b int64) int64 {
	if a < b {
		return b
	}
	return a
}

func maxUint64(a, b uint64) uint64 {
	if a < b {
		return b
	}
	return a
}

func absInt(a int) int {
	if a < 0 {
		return -a
	}
	return a
}

func absInt64(a int64) int64 {
	if a < 0 {
		return -a
	}
	return a
}

// readString() string
// readInt() int
// readIntSlice(n int) []int
// readLengthAndSlice() []int
func main() {
	defer stdout.Flush()

	k := readInt()
	s := readInt()

	var ans int64
	for x := 0; x <= k; x++ {
		s2 := s - x
		if 2*k < s2 {
			continue
		}
		for y := 0; y <= k; y++ {
			z := s2 - y
			if z < 0 {
				break
			}
			if y <= k && z <= k {
				ans++
			}
		}
	}
	println(ans)
}


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

using namespace std;

int main(void)
{
    int a[5], i, min=10, sum=0;

    for(i=0; i<5; i++){
        cin >> a[i];

        if(min > a[i]%10 && a[i]%10!=0){
            min = a[i]%10;
        }

        if(a[i]%10==0){
            sum += a[i];
        }

        else{
            sum += (a[i]/10+1)*10;
        }
    }

    cout << sum+min-10 << endl;

    return 0;
}

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

const ll INF = 1e18;

int main() {
  ll N, M, P;
  cin >> N >> M >> P;

  vector<ll> A(M), B(M), C(M), dist(N);
  for (int i = 0; i < M; i++) {
    cin >> A[i] >> B[i] >> C[i];
    A[i]--, B[i]--;
  }

  for (int i = 0; i < N; i++) {
    dist[i] = INF;
  }
  dist[0] = 0;

  for (int i = 0; i < 2 * N; i++) {
    for (int j = 0; j < M; j++) {
      if (dist[A[j]] != INF && dist[B[j]] > dist[A[j]] + (P - C[j])) {
        dist[B[j]] = dist[A[j]] + (P - C[j]);
        if (i >= N - 1) {
          dist[B[j]] = -INF;
          if (B[j] == N - 1) {
            cout << -1 << endl;
            return 0;
          }
        }
      }
    }
  }
  cout << max(-dist[N - 1], (ll)0) << endl;
}

Measured memory_bytes: 512
S = input()

if S == 'SUN':
  ans = 7
elif S == 'MON':
  ans = 6
elif S == 'TUE':
  ans = 5
elif S == 'WED':
  ans = 4
elif S == 'THU':
  ans = 3
elif S == 'FRI':
  ans = 2
elif S == 'SAT':
  ans = 1

print(ans)

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

int main()
{
	ll N;
	cin>>N; 
	ll value[N]; ll dp[N][N];
		
	for(ll i=0;i<N;i++)
	{
	cin>>value[i];
	dp[i][i]=value[i];
	}
	
	for(ll len=2;len<=N;len++)
	{
		for(ll i=0;i<=N-len;i++)
		{
		  dp[i][i+len-1]=max(value[i]-dp[i+1][i+len-1],value[i+len-1]-dp[i][i+len-2]);
		}
	}
	
cout<<dp[0][N-1]<<endl;
	    
	    
	
}



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

using namespace std;

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

using ll = long long;
using ld = long double;

const ll INF = 1e18;
const int Inf = 1e9;
const double EPS = 1e-9;
const ll MOD = 1e9 + 7;

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(0);
	int r;
	cin >> r;
	cout << 3 * r * r << endl;
    
    return 0;
}



Measured memory_bytes: 3644
//int a = stoi(c); 文字列をintへ
//小文字から大文字
//transform(a.begin(), a.end(), a.begin(), ::toupper);
//途中の出力をそのまま残さない
//数値計算 個数以外はdouble
//map<キー,値> p は辞書。p[キー] = 値
//map 全探索
//auto begin = p.begin(), end = p.end();
//for (auto it = begin; it != end; it++) {}
//mapのキー：it->first mapのバリュー：it->second
//絶対値 abs()
//入力は空白で切れる
//大文字判定 isupper(文字) 小文字判定 islower(文字)
//do{}while(next_permutation(ALL(配列)))
//while(N)で回すとき、Nはコピーを作っておく
//小文字に対応する文字コード：S[i] - 'a'
//文字コード→小文字：(char)(数字+'a')
//グラフの距離:隣接行列で扱う
//等価なものに変換する思考
//bool型　初期値はTrue
//島渡りの問題：中間ノードに着目
//配列はvector<>を使う：意味わからないエラーがなくなる。
//背反な事象にちゃんとわける
//チェックリストはマップを使う
//数が大きい時の比較はstring型で行う
//全て0になったか調べたい->0になるたびにcntする
//またはかかつか
//例外処理は最初にする
#include <bits/stdc++.h>
#define rep(i,N) for(int i = 0; i < N;i++)
#define ALL(a) (a).begin(),(a).end()
#define ll long long int
using namespace std;

//円周率
const double PI = 3.14159265358979323846;
//割るやつ
const ll M = (pow(10, 9) + 7);

// K進数でのNの桁数
ll dig(ll N, ll K) {
	ll dig = 0;
	while (N) {
		dig++;
		N /= K;
	}
	return dig;
}
// a,bの最大公約数
ll gcd(ll a, ll b) {
	if (b == 0) return a;
	return gcd(b, a%b);
}

ll lcm(ll a, ll b) {
	ll g = gcd(a, b);
	return a / g * b;
}

//nC2の計算
ll C(ll N) {
	return N * (N - 1) / 2;
}

//階乗計算
ll f(ll n) {
	if (n == 0 || n == 1) return 1;
	else return (n * f(n - 1)) % M;
}

int main() {
	string S; cin >> S;
	ll K; cin >> K;

	rep(i, S.size()) {
		if (S[i] != '1') {
			cout << S[i] << endl;
			return 0;
		}
		if (i == K - 1) {
			cout << 1 << endl;
			return 0;
		}
	}
}

Measured memory_bytes: 256
S = input()
K = int(input())

flag = False

itr = 0
cnt = 1
len_cnt = []
for x in S :
  if itr == 0 :
    pre = x
    itr += 1
    continue
  now = x
  if pre == now :
    cnt += 1
    itr += 1
    if itr == len(S) :
      len_cnt.append(cnt)
    continue
  if pre != now :
    len_cnt.append(cnt)
    itr+=1
    if itr == len(S) and cnt == 1 :
      len_cnt.append(cnt)
    cnt = 1
    pre = x
    continue

if sum(len_cnt) != len(S) :
  len_cnt.append(1)

if len(len_cnt) == 1 :
  print(int(len_cnt[0] * K / 2))
  exit()

ans = 0
for x in len_cnt :
  if x == 1 :
    continue
  else :
    ans += int(x / 2)

# if S[0] == S[-1] and len_cnt[-1] > 1 and len_cnt[-1] % 2 == 1 and K > 1:
#   ans += 1
if S[0] == S[-1] and len_cnt[-1] % 2 == 1 and len_cnt[0] % 2 == 1 :
  ans += 1
  flag = True

ANS = K * ans
# print (ANS, len_cnt)
if flag :
  ANS -= 1

# if S[0] ==S[-1] and len_cnt[-1] % 2 == 1 and len_cnt[-1] != 1 :
#   ANS -= 1
print(ANS)

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n)  for(long long i=0;i<(long long)(n);i++)
#define REP(i,k,n) for(long long i=k;i<(long long)(n);i++)
#define all(a) a.begin(),a.end()
#define pb push_back
typedef long long ll;
typedef pair<ll,ll> P;
using vi=vector<ll>;
using vvi=vector<vi>;
using vvvi=vector<vvi>;
#define MAX 100000


int main(){
    string s,t;
    cin>>s>>t;
    if(s.size()<t.size())cout<<"UNRESTORABLE";
    else{ 
        int size=s.size()-t.size();
        int index=-1;
        for(int i=size;i>=0;i--){
            bool flag=false;
            rep(j,t.size()){
                if(s[j+i]!=t[j]&&s[i+j]!='?'){
                    flag=true;
                    break;
                }
            }
            if(!flag){
                index=i;
                break;
            }
        }
        if(index==-1)cout<<"UNRESTORABLE";
        else{
            rep(i,s.size()){
                if(index<=i&&i<index+t.size()){
                    cout<<t[i-index];
                }
                else {
                    if(s[i]=='?')cout<<'a';
                    else cout<<s[i];
                } 
            }
        }
        cout<<endl;
    }
    return 0;
}
    



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

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
const int INF = (1<<30) - 1;
const ll LINF = (1LL<<60) - 1;

int n, q;
vector<vector<int>> G;
vector<int> cnt;
vector<int> res;

void dfs(int v, int p, int add = 0) {
    res[v] = add + cnt[v];
    for (auto nv : G[v]) {
        if (nv == p) continue;
        dfs(nv, v, add + cnt[v]);
    }
}

int main(){
    cin >> n >> q;
    G.resize(n);
    for (int i = 0; i < n-1; ++i) {
        int a, b;
        cin >> a >> b;
        --a; --b;
        G[a].push_back(b);
        G[b].push_back(a);
    }

    cnt.assign(n, 0);
    for (int i = 0; i < q; ++i) {
        int p, x;
        cin >> p >> x;
        --p;
        cnt[p] += x;
    }

    res.resize(n);
    dfs(0, -1);
    for (int i = 0; i < n; ++i) {
        cout << res[i] << endl;
    }
}

Measured memory_bytes: 28232
import java.util.Scanner;

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

        if(a < b){
            System.out.println("a < b");
        }else if (a > b){
            System.out.println("a > b");
        }else if (a == b) {
            System.out.println("a == b");
        }
    }
}

Measured memory_bytes: 26108
#include<bits/stdc++.h>
using namespace std;
int main(){
    int n;
    cin >> n;
    vector<int> t(n);
    int sum=0;
    for(int i=0; i<n; i++){
        cin >> t[i];
        sum+=t[i]; 
    }
    int m;
    cin >> m;
    vector<int> p(m);
    vector<int> x(m);
    int ans;
    for(int i=0; i<m; i++){
         cin >> p[i] >> x[i];
    }
    for(int i=0; i<m; i++){
         ans = sum - t[p[i]-1] + x[i];
         cout << ans << endl;
    }
    
}




Measured memory_bytes: 256
import std.stdio, std.string, std.conv, std.range;
import std.algorithm, std.array, std.typecons, std.container;
import std.math, std.numeric, std.random, core.bitop;

enum inf = 1_001_001_001;
enum infl = 1_001_001_001_001_001_001L;
enum mod = 1_000_000_007L;

alias Edge = Tuple!(int, "to", int, "idx");

void main() {
    int N;
    scan(N);
    auto ans = new int[](N - 1);
    ans[] = -1;
    auto adj = new Edge[][](N, 0);
    foreach (i ; 0 .. N - 1) {
        int ai, bi;
        scan(ai, bi);
        ai--, bi--;
        adj[ai] ~= Edge(bi, i);
        adj[bi] ~= Edge(ai, i);
    }

    int K = 0;
    void dfs(int v, int p, int pc) {
        int col = 1;
        foreach (e ; adj[v]) if (e.to != p) {
            if (col == pc) col++;
            ans[e.idx] = col;
            K = max(K, col);
            dfs(e.to, v, col);
            col++;
        }
    }

    dfs(0, -1, -1);

    writeln(K);
    ans.each!(ansi => writeln(ansi));
}



void scan(T...)(ref T args) {
    import std.stdio : readln;
    import std.algorithm : splitter;
    import std.conv : to;
    import std.range.primitives;

    auto line = readln().splitter();
    foreach (ref arg; args) {
        arg = line.front.to!(typeof(arg));
        line.popFront();
    }
    assert(line.empty);
}

void fillAll(R, T)(ref R arr, T value) {
    static if (is(typeof(arr[] = value))) {
        arr[] = value;
    }
    else {
        foreach (ref e; arr) {
            fillAll(e, value);
        }
    }
}

bool chmin(T, U...)(ref T x, U args) {
    bool isChanged;

    foreach (arg; args) {
        if (x > arg) {
            x = arg;
            isChanged = true;
        }
    }

    return isChanged;
}

bool chmax(T, U...)(ref T x, U args) {
    bool isChanged;

    foreach (arg; args) {
        if (x < arg) {
            x = arg;
            isChanged = true;
        }
    }

    return isChanged;
}


Measured memory_bytes: 12028
#include<bits/stdc++.h>
//ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
//clock_t start=clock();clock_t end=clock();cout<<(double)(end-start)/CLOCKS_PER_SEC<<endl;
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef unsigned int ui;
typedef pair<int,int> pii;
typedef pair<pii,int> ppii;
typedef pair<int,pii> pipi;
typedef pair<ll,ll> pll;
typedef pair<pll,ll> ppll;
typedef pair<ll,pll> plpl;
typedef tuple<ll,ll,ll> tl;
typedef pair<double,double> pdd;
typedef vector<vector<ll>> mat;
ll mod=1000000007;
ll mod2=998244353;
ll mod3=1000003;
ll mod4=998244853;
ll mod5=1000000009;
ll inf=1LL<<60;
double pi=3.141592653589793238462643383279L;
double eps=1e-14;
#define rep(i,m,n) for(int i=m;i<n;i++)
#define rrep(i,n,m) for(int i=n;i>=m;i--)
#define srep(itr,st) for(auto itr=st.begin();itr!=st.end();itr++)
#define mrep(itr,mp) for(auto itr=mp.begin();itr!=mp.end();itr++)
#define Max(a,b) a=max(a,b)
#define Min(a,b) a=min(a,b)
int dh[4]={1,-1,0,0};
int dw[4]={0,0,1,-1};
int ddh[8]={-1,-1,-1,0,0,1,1,1};
int ddw[8]={-1,0,1,-1,1,-1,0,1};
ll gcd(ll a,ll b){
    if(a<b)swap(a,b);
    if(b==0)return a;
    if(a%b==0)return b;
    return gcd(b,a%b);
}
ll Pow(ll n,ll k){
    ll ret=1;
    ll now=n;
    while(k>0){
        if(k&1)ret*=now;
        now*=now;
        k/=2;
    }
    return ret;
}
ll beki(ll n,ll k,ll md){
  ll ret=1;
  ll now=n;
  while(k>0){
    if(k%2==1){
      ret*=now;
      ret%=md;
    }
    now*=now;
    now%=md;
    k/=2;
  }
  return ret;
}
ll gyaku(ll n,ll md){
  return beki(n,md-2,md);
}
ll popcount(ll n){
    ll ret=0;
    ll u=n;
    while(u>0){
        ret+=u%2;
        u/=2;
        
    }
    return ret;
}
int main(){
    ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
    int h,w;cin>>h>>w;
    string s[h];
    rep(i,0,h)cin>>s[i];
    int dp[h][w];
    rep(i,0,h)rep(j,0,w)dp[i][j]=1000000000;
    if(s[0][0]=='#')dp[0][0]=1;
    else dp[0][0]=0;
    rep(i,0,h){
        rep(j,0,w){
            if(i==0&&j==0)continue;
            int ph=i-1,pw=j;
            if(ph>=0){
                if(s[i][j]=='#'&&s[ph][pw]=='.')Min(dp[i][j],dp[ph][pw]+1);
                else Min(dp[i][j],dp[ph][pw]);
            }
            ph=i,pw=j-1;
            if(pw>=0){
                if(s[i][j]=='#'&&s[ph][pw]=='.')Min(dp[i][j],dp[ph][pw]+1);
                else Min(dp[i][j],dp[ph][pw]);
            }
        }
    }
    cout<<dp[h-1][w-1]<<endl;
}








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

int main() {
	int A, B, C, X, Y, ans = 1000000000;
	cin >> A >> B >> C >> X >> Y;
	for (int i = 0; i <= max(X, Y); i++) {
		int Z = 2 * C * i + A * max(0, X - i) + B * max(0, Y - i);
		ans = min(ans, Z);
	}
	cout << ans;
}


Measured memory_bytes: 256
#include<stdio.h>

int main(){
  int n,x,c,i,j,k;
  scanf("%d%d",&n,&x);
  while(n*n+x*x){
    c=0;
    for(i=1;i<=n-2;i++){
      for(j=i+1;j<=n-1;j++){
        for(k=j+1;k<=n;k++){
          if(x==i+j+k) c=c+1;}
        }
      }
    printf("%d\n",c);
    scanf("%d%d",&n,&x);}
  return 0;}

Measured memory_bytes: 600
parseInt(x) = parse(Int, x)
parseMap(x::Array{SubString{String},1}) = map(parseInt, x)

function main()
	a,b = readline() |> split |> parseMap
	s = ""
	t = ""
	for i in 1:b
		s = s*string(a)
	end
	for i in 1:a
		t = t*string(b)
	end
	println(s<t?s:t)
end

main()

Measured memory_bytes: 110216
main :: IO ()
main = do
    [a, b, k] <- fmap (map read . words) getLine :: IO [Int]
    print $ solve a b k

solve :: Int -> Int -> Int -> Int
solve a b k =
    (filter (\x -> (a `mod` x == 0) && (b `mod` x == 0)) [100, 99 .. 1])
        !! (k - 1)


Measured memory_bytes: 508
import java.util.Scanner;
class Main{
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int x = sc.nextInt();
        int y = sc.nextInt();
        int[] out = new int[n];
        for(int i = 1; i <= n; i++){
            for(int j = i + 1; j <= n; j++){
                out[Math.min(j - i, Math.abs(x - i) + 1 + Math.abs(y - j))]++;
            }
        }
        for(int i = 1; i <= n - 1; i++) System.out.println(out[i]);
    }
}

Measured memory_bytes: 23764
#include <iostream>
#include <algorithm>
#include <vector>
#define rep(i,n) for(int i=0;i<n;++i)
#define rep1(i,n) for(int i=1;i<=n;++i)
using namespace std;
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(a > b){ a = b; return 1; } return 0; }
int main()
{
  int n; cin >> n;
  n = n % 1000;
  if(n == 0) n = 1000;
  cout << 1000 - n << "\n";
  return 0;
}


Measured memory_bytes: 3632
#include <bits/stdc++.h>
using namespace std;
vector <int> refrig;
vector <int> microwave;
vector <int> discontos;
int main(int argc, char const *argv[])
{
	refrig.clear();
	microwave.clear();
	int a,b,m;
	cin >> a >> b >> m;
	int minRef, minMicro;
	for (int i = 0; i < a; ++i)
	{
		int x;
		cin >> x;
		refrig.push_back(x);
		if (i == 0)
			minRef = x;
		else if (x < minRef)
			minRef = x;
	}
	for (int i = 0; i < b; ++i)
	{
		int x;
		cin >> x;
		microwave.push_back(x);
		if (i == 0)
			minMicro = x;
		else if (x < minMicro)
			minMicro = x;
	}
	for (int i = 0; i < m; ++i)
	{
		int x,y,c;
		cin >> x >> y >> c;
		discontos.push_back(refrig[x-1] + microwave[y-1] - c);
		//cout << x << " " << refrig[x-1] << " " << microwave[y-1] << endl;
	}
	sort (discontos.begin(), discontos.end());
	cout << min(discontos[0], minRef+minMicro) << endl;

	return 0;
}

Measured memory_bytes: 1784
#![allow(unused_imports)]
use itertools::Itertools;
use num::clamp;
use proconio::{fastout, input, marker::*};
use std::cmp::*;
use std::collections::*;
use superslice::*;

#[fastout()]
fn main() {
    input! {
        n: usize, k: usize,
        v: [i64; n]
    }

    let lim = min(n, k);
    let mut ans = -1<<60;
    for left in 0..=lim {
        for right in 0..=lim - left {
            let mut jewels = v
                .iter()
                .take(left)
                .chain(v.iter().rev().take(right))
                .cloned()
                .collect_vec();
            jewels.sort();
            let rest = k - left - right;
            let sub = jewels.iter().take(rest).filter(|v| **v < 0).sum::<i64>();
            let sum = jewels.iter().sum::<i64>() - sub;
            ans = max(ans, sum);
        }
    }
    println!("{}", ans);
}


Measured memory_bytes: 2156
#include <iostream>

using namespace std;
#define rep(i, n) for (int i = 1; i <= n; i++)

float A[100];

int main()
{
	int N;
	float ans = 0;

	cin >> N;
	rep(i, N) cin >> A[i];

	rep(i, N) ans += 1 / A[i];
	cout << 1 / ans << endl;

	return 0;
}


Measured memory_bytes: 256
#define _CRT_SECURE_NO_WARNINGS
//#define DEBUG
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
#include<math.h>

int main(void) {
#ifdef DEBUG
	printf("");
#endif

	char N[11];
	char ans[11];
	int i=0,j=0;

	memset(N, '\0', 11);
	memset(ans, '\0', 11);

	scanf("%s", &N);
	
	while (N[i] != '\0') {
		if (N[i] == '1') {
			ans[j] = '1';
		}
		else if (N[i] == '0') {
			ans[j] = '0';
		}
		else {
			j--;
			if (j >= 0) {
				ans[j] = '\0';
				j--;
			}
		}
		i++;
		j++;
	}

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

	return 0;
}

Measured memory_bytes: 128
#include <string>
#include<queue>
#include<iostream>
#include<set>
#include<vector>
#include<algorithm>
#include<map>
#include<tuple>

using namespace std;

typedef long long ll;
typedef pair<int,int> pii;
typedef tuple<int,int,int> t3;
typedef tuple<int,int,int,int> t4;

const int MX = 205;
const int MM = 1000000007;

ll D[MX][9];
char A[2][MX];

ll add(ll a, ll b){ return (a+b) % MM; }

int main()
{
	int N;
	scanf("%d%s%s", &N, A[0]+1, A[1]+1);
	if( A[0][1] == A[1][1] ) D[1][0] = D[1][4] = D[1][8] = 1;
	else D[1][1] = D[1][2] = D[1][3] = D[1][5] = D[1][6] = D[1][7] = 1;
	for(int i = 2; i <= N; i++){
		if( A[0][i] == A[1][i] ){
			for(int j = 0; j < 9; j += 4){
				for(int k = 0; k < 9; k++){
					if( j%3 == k%3 || j/3 == k/3) continue;
					D[i][j] = add(D[i][j], D[i-1][k]);
				}
			}
		}
		else if( A[0][i-1] == A[0][i] ){
			for(int j = 0; j < 9; j++) D[i][j] = D[i-1][j];
		}
		else{
			for(int j = 0; j < 9; j++){
				for(int k = 0; k < 9; k++){
					if( j%3 == k%3 || j/3 == k/3 || k%3 == k/3) continue;
					D[i][k] = add(D[i][k], D[i-1][j]);
				}
			}
		}
	}
	ll ans = 0;
	for(int i = 0; i < 9; i++) ans = add(ans, D[N][i]);
	printf("%lld\n", ans);
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
// #define int long long
using ll=long long;
using vi=vector<int>;
using vl=vector<long long>;
using pii=pair<int,int>;
using pll=pair<ll,ll>;
#define ITR(v,c) for(auto v=begin(c);v!=end(c);v++)
#define FORE(x,c) for(auto &x:c)
#define FOR(v,a,n) for(int v=a;v<(int)(n);v++)
#define REP(v,n) FOR(v,0,n)
#define RREP(v,n) for(int v=((int)(n)-1);v>=0;v--)
#define ALL(c) begin(c),end(c)
#define RALL(c) rbegin(c),rend(c)
#define SZ(c) ((int)c.size())
const int DX[9]={0,1,0,-1,1,1,-1,-1,0}, DY[9]={-1,0,1,0,-1,1,1,-1,0};
const int INF=1e9; const long long INFLL=1e18;
template<class T> ostream& operator << (ostream &os, const vector<T> &v) {
    ITR(i,v) os<<*i<<(i==end(v)-1?"":" "); return os; }
template<class T> istream& operator >> (istream &is, vector<T> &v) {
    ITR(i,v) is>>*i; return is; }
//------------------------------------------------------------------------------

struct union_find {
    vector<int> par;
    union_find(int size) {
        par.resize(size);
        for(int i=0;i<size;i++) {
            par[i]=i;
        }
    }
    void unite(int x,int y) {
        x=root(x); y=root(y);
        if(x!=y) par[x]=y;
    }
    int root(int x) {
        if(par[x]==x) return x;
        return par[x]=root(par[x]);
    }
    bool same(int x,int y) {
        return root(x)==root(y);
    }
};
signed main() {
    int n,q;
    cin>>n>>q;
    union_find uf(n);
    REP(i,q) {
        int com,x,y;
        cin>>com>>x>>y;
        if(com==0) uf.unite(x,y);
        else {
            cout<<uf.same(x,y)<<endl;
        }
    }
    return 0;
}

Measured memory_bytes: 3176
n,k=map(int,input().split())
s=list(input())
if s[k-1]=='A':
  s[k-1]='a'
elif s[k-1]=='B':
  s[k-1]='b'
elif s[k-1]=='C':
  s[k-1]='c'
print(''.join(s))

Measured memory_bytes: 3060
#include <iostream>
#include <stdio.h>
#include <vector>
#include <queue>
#include <functional>
#include <algorithm>
using namespace std;

vector< vector< vector< int > > > costs;

struct data_t {
	int m_d, m_x, m_y;
	data_t(int d, int y, int x) { m_d = d; m_y = y; m_x = x; }
};

int solve(void);

int main(void) {
		
	while (solve());

	return 0;

}

int solve(void) {

	//	input

	int w, h;

	cin >> w >> h;
	if (!(w | h)) { return 0; }

	vector< vector< int > > s(h, vector< int > (w, (1<<30)));
	costs.clear();
	costs.resize(4, s);
	vector<int> c(4);

	// right, down, left, up
	int d[4][2] = { {0,1}, {1,0}, {0,-1},{-1,0} };

	for (int i = 0; i < h; i++)
		for (int j = 0; j < w; j++)
			cin >> s[i][j];

	for (int i = 0; i < 4; i++)
		cin >> c[i];

	//0: ?????´????????????
	//1 : ??????????????????
	//2 : ????????¢?????????
	//3 : ??????????????????
	//4 : ????????¢?????????

	costs[0][0][0] = 0;

	queue< data_t > q;
	q.push(data_t(0, 0, 0));

	while (!q.empty()) {

		data_t doneNode = q.front();

		q.pop();

		for (int i = 0; i < 4; i++) {

			data_t to = doneNode;
			int cost = costs[doneNode.m_d][doneNode.m_y][doneNode.m_x] + c[i];
			if (i == s[to.m_y][to.m_x]) { cost = costs[doneNode.m_d][doneNode.m_y][doneNode.m_x]; }

			to.m_d = (to.m_d + i) % 4;
			to.m_y += d[to.m_d][0];
			to.m_x += d[to.m_d][1];
			
			if (to.m_x >= 0 && to.m_x < w && to.m_y >= 0 && to.m_y < h) {
				if (cost < costs[to.m_d][to.m_y][to.m_x]) {
					costs[to.m_d][to.m_y][to.m_x] = cost;
					q.push(to);
				}
			}

		}
	}
	
	int ans = costs[0][h - 1][w - 1];

	for (int i = 0; i < 4; i++)
		ans = min(ans, costs[i][h - 1][w - 1]);

	cout << ans << endl;

	return 1;

}

Measured memory_bytes: 3100
package main

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

var sc = bufio.NewScanner(os.Stdin)

func init() {
	sc.Buffer(make([]byte, 101000), 101000)
}

func rb() []byte {
	sc.Scan()
	return sc.Bytes()
}

func smaller(a, b int) int {
	if a < b {
		return a
	}
	return b
}

func main() {
	s := rb()

	x := 0
	for i, v := range s {
		if i&1 == 0 && v == '0' { // Odd
			x++
		} else if i&1 != 0 && v == '1' {
			x++
		}
	}

	y := 0
	for i, v := range s {
		if i&1 == 0 && v == '1' { // Odd
			y++
		} else if i&1 != 0 && v == '0' {
			y++
		}
	}

	fmt.Println(smaller(x, y))
}


Measured memory_bytes: 768
//@formatter:off
#include<bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < int(n); ++i)
#define rrep(i,n) for (int i = int(n)-1; i >= 0; i--)
#define rep2(i,s,n) for (int i = int(s); i < int(n); ++i)
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define pb push_back
#define eb emplace_back
#define vi vector<int>
#define vvi vector<vector<int>>
#define vl vector<ll>
#define vvl vector<vector<ll>>
#define vd vector<double>
#define vvd vector<vector<double>>
#define vs vector<string>
#define vc vector<char>
#define vvc vector<vector<char>>
#define vb vector<bool>
#define vvb vector<vector<bool>>
#define vp vector<P>
#define vvp vector<vector<P>>
using namespace std;
using ll = long long;
using P = pair<int,int>;
using LP = pair<ll,ll>;
template<class S,class T> istream& operator>>(istream &is,pair<S,T> &p) { return is >> p.first >> p.second; }
template<class S,class T> ostream& operator<<(ostream &os,const pair<S,T> &p) { return os<<'{'<<p.first<<","<<p.second<<'}'; }
template<class T> istream& operator>>(istream &is,vector<T> &v) { for(T &t:v){is>>t;} return is; }
template<class T> ostream& operator<<(ostream &os,const vector<T> &v) { os<<'[';rep(i,v.size())os<<v[i]<<(i==int(v.size()-1)?']':','); return os; }
void Yes(bool b) { cout << (b ? "Yes" : "No") << '\n'; }
void YES(bool b) { cout << (b ? "YES" : "NO") << '\n'; }
template<class T> bool chmin(T& a,T b) {if(a > b){a = b; return true;} return false;}
template<class T> bool chmax(T& a,T b) {if(a < b){a = b; return true;} return false;}
const int inf = 1001001001;
const ll linf = 1001001001001001001;
//@formatter:on

ll dp[3010][3010];

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);
    int R, C, k;
    cin >> R >> C >> k;
    vvp item(R);
    rep(_, k) {
        int r, c, v;
        cin >> r >> c >> v;
        r--;
        item[r].eb(c, v);
    }
    rep(i, R) sort(all(item[i]));
    rep(i, R) rep(j, C + 1) {
            chmax(dp[i + 1][j], dp[i][j]);
            auto it = lower_bound(all(item[i]), j,
                                  [](P &p,int val){ return p.first < val; });
            vi ls;
            while (it != item[i].end()) {
                ls.pb(it->second);
                if (ls.size() > 3) {
                    ls.erase(min_element(all(ls)));
                }
                ll sum = accumulate(all(ls), 0LL);
                chmax(dp[i + 1][it->first], dp[i][j] + sum);
                it++;
            }
        }
    ll ans = 0;
    rep(i, 3010) rep(j, 3010) chmax(ans, dp[i][j]);
    cout << ans << endl;
}

Measured memory_bytes: 76932
#include <bits/stdc++.h>
#define int long long
#define endl '\n'
#define FOR(i, a, n) for (int i = (a); i < (n); ++i)
#define REP(i, n) FOR(i, 0, n)
using namespace std;

void _main() {
    int N, M;
    cin >> N >> M;
    vector<string> A(N), B(N);
    REP (i, N) cin >> A[i];
    REP (i, N) cin >> B[i];
    int ans = 0;
    REP (i, N) REP (j, M) {
        ans += (A[i][j] != B[i][j]);
    }
    cout << ans << endl;
}

signed main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout << fixed << setprecision(10);
    _main();
    return 0;
}


Measured memory_bytes: 11392
#include <bits/stdc++.h>
#define double long double
#define int long long
#define inf 1000000007 
#define sort(vec) sort(vec.begin(),vec.end());
#define rever(vec) reverse(vec.begin(),vec.end());
#define unsort(vec) sort(vec); rever(vec);
#define rep(i,n) for(int i=0;i<n;i++)
#define cend cout<<endl;
#define F first
#define S second
using namespace std;

int gcd(int a,int b) {
	if(b==0) return a;
	return gcd(b,a%b);
}
int lcm(int a,int b) {
	return a/gcd(a,b)*b;
}
signed main() {
	int n;
	cin>>n;
	int a[n];
	rep(i,n) cin>>a[i];
	int ans=1;
	rep(i,n) {
		if(ans==a[i]) continue;
		ans=lcm(ans,a[i]);
	}
	cout<<ans<<endl;
}


Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main() {
  int a,b,c,x;
  cin >> a >> b >> c >> x;
  int res=0,i,j,k;
  for (i=0;i<=a;i++){
    for (j=0;j<=b;j++){
      for (k=0;k<=c;k++){
        int total = 500*i+100*j+50*k; 
        if (total==x) res++;
      }
    }
  }
  cout << res << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
const int64_t INF = 1e18;
 
struct Dinic{
    struct edge {
        int64_t to, cap, rev;
        edge(int64_t to, int64_t cap, int64_t rev):to(to), cap(cap), rev(rev){}
    };
 
    int N, S, T;
    int64_t flow = 0;
    vector<int> level, iter;
    vector<vector<edge>> G;
 
    Dinic(int N, int S, int T):N(N), S(S), T(T){
        flow = 0;
        level.resize(N);
        iter.resize(N);
        G.resize(N);
    }
 
    void add_edge(int from, int to, int64_t cap){
        G[from].emplace_back(to, cap, G[to].size());
        G[to].emplace_back(from, 0, G[from].size()-1);
    }
 
    void bfs(int s){
        fill(level.begin(), level.end(), -1);
        queue<int> que;
        level[s] = 0;
        que.push(s);
        while(que.size()){
            int v = que.front(); que.pop();
            for(auto& e : G[v]){
                if(e.cap > 0 && level[e.to] < 0){
                    level[e.to] = level[v] + 1;
                    que.push(e.to);
                }
            }
        }
    }
 
    int64_t dfs(int v, int t, int64_t f){
        if(v == t) return f;
        for(int& i=iter[v]; i<G[v].size(); i++){
            auto& e = G[v][i];
            if(e.cap > 0 && level[v] < level[e.to]){
                int64_t d = dfs(e.to, t, min(f, e.cap));
                if(d > 0){
                    e.cap -= d;
                    G[e.to][e.rev].cap += d;
                    return d;
                }
            }
        }
        return 0;
    }
 
    int64_t max_flow(){
        while(true){
            bfs(S);
            if(level[T] < 0) return flow;
            fill(iter.begin(), iter.end(), 0);
            while(true){
                int64_t f = dfs(S, T, INF);
                if(f == 0) break;
                flow += f;
            }
        }
    }
};
 
int main(){
    int N, A[101];
    cin >> N;
    for(int i=1; i<=N; i++) cin >> A[i];
 
    int S = 101, T = 102;
    Dinic solver(T+1, S, T);
 
    int64_t pre_gain = 0;
 
    for(int i=1; i<=N; i++){
        if(A[i] >= 0){
            pre_gain += A[i];
            solver.add_edge(S, i, 0);
            solver.add_edge(i, T, A[i]);
        }else{
            solver.add_edge(S, i, -A[i]);
            solver.add_edge(i, T, 0);
        }
    }
 
    for(int i=1; i<=N; i++) for(int k=2; i*k<=N; k++){
        solver.add_edge(i, k*i, INF);
    }
 
    int64_t ans = pre_gain - solver.max_flow();
    cout << ans << endl;
}

Measured memory_bytes: 3668
#include <bits/stdc++.h>
using namespace std;
#define _GLIBCXX_DEBUG
#define rep(i, N) for(int i = 0; i < N; i++)
#define rep2(i, N, a, b) for(int i = a; i < N; i += b)

int main(){
	int A, B;
	cin >> A >> B;


	cout << A * B << endl;
}

Measured memory_bytes: 3596
#include<stdio.h>
#include <iostream>
using namespace std;

int main() {
	while (1) {
		int n, s, t, b, sum = 0;
		int ai[16][3][3] = { 0 };
		char a, d, c;
		scanf("%d", &n);
		if (n == 0) break;
		cin >> a >> d >> c;
		s = a - 'A';  t = d - 'A'; b = c - 'A';
		ai[0][s / 3][s % 3] = 1;
		for (int i = 1; i <= n; ++i) {
			for (int j = 0; j < 3; ++j) {
				for (int l = 0; l < 3; ++l) {
					if (j - 1 >= 0 && (j-1) * 3 + l != b) ai[i][j - 1][l] += ai[i - 1][j][l];
					else ai[i][j][l] += ai[i - 1][j][l];
					if (j + 1 < 3 && (j + 1) * 3 + l != b) ai[i][j + 1][l] += ai[i - 1][j][l];
					else ai[i][j][l] += ai[i - 1][j][l];

					if (l - 1 >= 0 && j * 3 + l - 1 != b) ai[i][j][l - 1] += ai[i - 1][j][l];
					else ai[i][j][l] += ai[i - 1][j][l];
					if (l + 1 < 3 && j * 3 + l + 1 != b) ai[i][j][l + 1] += ai[i - 1][j][l];
					else ai[i][j][l] += ai[i - 1][j][l];					
				}
			}
		}
		for (int i = 0; i < 3; ++i) {
			for (int j = 0; j < 3; ++j) {
				sum += ai[n][i][j];
			}
		}
		printf("%f\n", (double)ai[n][t / 3][t % 3] / sum);
	}

}

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

long n,m,aga;
vector<long> a(200000);
vector<long> b(200000);
vector<vector<long>> aaa(200000,vector<long>(0));
vector<long> ans(200000,-1);
vector<long> kaisu(200000,99999999);

int main() {
  cin >> n >> m;
  for(long i=0;i<m;i++) {
    cin >> a[i] >> b[i];
    aaa[a[i]-1].push_back(b[i]-1);
    aaa[b[i]-1].push_back(a[i]-1);
  }
  ans[0]=0;
  kaisu[0]=0;
  queue<long> x;
  queue<long> y;
  x.push(0);
  y.push(0);
  while(x.size()!=0) {
    for(long i=0;i<aaa[x.front()].size();i++) {
      if(ans[aaa[x.front()][i]]==-1) {
        ans[aaa[x.front()][i]]=x.front()+1;
        x.push(aaa[x.front()][i]);
        y.push(y.front()+1);
      }
    }
    x.pop();
    y.pop();
  }
  cout << "Yes" << endl;
  for(long i=1;i<n;i++) cout << ans[i] << endl;
}

Measured memory_bytes: 21292
#include<bits/stdc++.h>
using namespace std;
const int N = 1e5 + 11;
int n, hei[N], f[N];
int main(){
    cin>>n;
    for(int i = 1;i <= n; i++)scanf("%d", &hei[i]);
    int ans = 0;
    for(int i = n - 1;i >= 1; i--){
        if(hei[i] >= hei[i+1]){
            f[i] = f[i+1] + 1;
        }
        else f[i] = 0;
        ans = max(ans, f[i]);
    }
    printf("%d\n", ans);
    return 0;
}


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

#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

#define sf scanf
#define pf printf
#define pb push_back
#define mp make_pair
#define PI ( acos(-1.0) )
#define mod 1000000007LL
#define maxn 100005
#define IN freopen("C.in","r",stdin)
#define OUT freopen("output.txt","w",stdout)
#define FOR(i,a,b) for(i=a ; i<=b ; i++)
#define DBG pf("Hi\n")
#define INF 2000000000
#define i64 long long int
#define eps (1e-8)
#define xx first
#define yy second
#define ln 17
#define off 2

using namespace __gnu_pbds;
using namespace std ;

typedef tree< i64, null_type, less<i64>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;
typedef pair<i64, i64> pii;

int main()
{
    int n ;

    scanf("%d",&n) ;

    vector< pair<int,int> > vp ;

    for(int i=1 ; i<=n ; i++)
    {
        int x , l ;
        scanf("%d %d",&x,&l) ;
        vp.pb( mp(x+l,x-l) ) ;
    }

    sort(vp.begin() , vp.end()) ;

    int last = -INF ;
    int ans = 0 ;

    for(int i=0 ; i<n ; i++)
    {
        if( vp[i].yy >= last )
        {
            ans++ ;
            last = vp[i].xx ;
        }
    }

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


    return 0 ;
}


Measured memory_bytes: 1400
x = input()
count = 0
if x[0] == 'S':
    if x[1] == 'R':
        count+= 1
        if x[2] == 'R':
            count += 1
        if x[2] == 'S':
            count = count

    if x[1] == 'S':
        if x[2] == 'R':
            count += 1
        if x[2] == 'S':
            count = count

if x[0] == 'R':
    count += 1
    if x[1] == 'R':
        count+= 1
        if x[2] == 'R':
            count += 1
        if x[2] == 'S':
            count = count

    if x[1] == 'S':
        if x[2] == 'R':
            count = 1
        if x[2] == 'S':
            count = count

print(count)

Measured memory_bytes: 9020
from collections import defaultdict


def solve():
    N, M = map(int, input().split())
    ac_dict = defaultdict(int)
    wa_dict = defaultdict(int)
    ac_p, wa_p = set(), set()
    for _ in range(M):
        p, s = map(str, input().split())
        p = int(p)
        if s == 'AC':
            ac_p.add(p)
            ac_dict[p] = 1
        else:
            if ac_dict[p] != 1:
                wa_p.add(p)
                wa_dict[p] += 1
    
    wa = 0
    for pi in ac_p:
        if pi in wa_p:
            wa += wa_dict[pi]
    
    print(sum(ac_dict.values()), wa)


if __name__ == '__main__':
    solve()


Measured memory_bytes: 19620
from collections import Counter
from collections import defaultdict as dd

h, w, n = map(int, input().split())
d = dd(int)

for _ in range(n):
  a, b = map(int, input().split())
  for i in range(3):
    for j in range(3):
      if a-i>0 and b-j>0 and a-i<=h-2 and b-j<=w-2:
        d[(a-i, b-j)] += 1
d = dict(d)
con = Counter(d.values())
con[0] = (h-2)*(w-2) - sum(con.values())
for i in range(10):
  print(con[i])

Measured memory_bytes: 216072
def fac(n):
    arr = []
    temp = n
    for i in range(2, int(-(-n**0.5//1))+1):
        if temp%i==0:
            cnt=0
            while temp%i==0:
                cnt+=1
                temp //= i
            arr.append([i, cnt])

    if temp!=1:
        arr.append([temp, 1])

    if arr==[]:
        arr.append([n, 1])

    return arr
N=int(input())
if N==1:
    print(0)
else:
    ans=0
    for i in range(len(fac(N))):
        a=fac(N)[i][1]
        b=int((2*a+1/4)**0.5-1/2)
        ans+=b
    print(ans)

Measured memory_bytes: 9488
#include<iostream>
#include<string>
#include<algorithm>
#include<set>
#include<vector>

#define rep(i,n) for(int i=0;i<int(n);i++)
#define sint(n) scanf("%d",&n);
#define sintt(n,m) scanf("%d%d",&n,&m);
#define sinttt(n,m,k) scanf("%d%d%d",&n,&m,&k);

using namespace std;

int ans;
int xx,yy;
int masu[90][90];
void saiki(int x,int y,int dep){
	if(x>=xx || y>=yy || x<0 || y<0){
		ans=max(ans,dep);
		return;
	}
	
	if(masu[x][y]==0){
		ans=max(ans,dep);
		return;
	}
	
	masu[x][y]=0;
	
	saiki(x+1,y,dep+1);
	saiki(x-1,y,dep+1);
	saiki(x,y+1,dep+1);
	saiki(x,y-1,dep+1);
	
	masu[x][y]=1;
}

int main(){
	while(1){
		sintt(xx,yy);
		if(xx==0)break;
		rep(i,yy)rep(j,xx){
			sint(masu[i][j]);
		}
		
		ans=0;
		
		rep(i,xx)rep(j,yy)
		saiki(i,j,0);
		
		printf("%d\n",ans);
	}
}

Measured memory_bytes: 0
#include<iostream>
#include<iomanip>
#include<cstdio>

#include<vector>
#include<queue>
#include<set>
#include<map>
#include<string>

#include<algorithm>
#include<cmath>
#include<numeric>

using namespace std;
typedef long long ll;
template <class T> inline bool chmax(T& a, T b) {if (a < b) {a = b; return 1;} return 0;}
template <class T> inline bool chmin(T& a, T b) {if (a > b) {a = b; return 1;} return 0;}
const ll INF = 1e18+1;


//パティの枚数 P[i]

//P[0] = 1
//P[i+1] = 2 * P[i] + 1

//P[n] = 2 ^ (n+1) - 1


//層の個数 S[i]

//S[0] = 1
//S[i+1] = 2 * S[i] + 3

//S[n] = 2 ^ (n+2) - 3


//レベルNバーガーを作るので
//層数は2^(n+2) - 3
//このX層まで食べる
//
//バーガーのデカいほうから、貪欲に数えていく
//カウントするたびにそのパティの数を加算

ll f(ll N, ll X, vector<ll> &S, vector<ll> &P) {
    if (N == 0) {
        if (X <= 0) return 0;
        return 1;
    } else if (X <= 1 + S[N-1]) {
        return f(N-1,X-1,S,P);
    }
    return P[N-1] + 1 + f(N-1,X-2-S[N-1],S,P);
}

int main() {
    ll N, X;
    cin >> N >> X;
    vector<ll> P(N+1,0),S(N+1,0);
    P[0] = S[0] = 1;
    for (int i = 1; i <= N; i++) {
        P[i] = 2 * P[i-1] + 1;
        S[i] = 2 * S[i-1] + 3;
    } 
    

    cout << f(N,X,S,P) << endl;

}

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

int main(){
  string S;
  cin >> S;

  vector<int64_t> cnts;
  int64_t cnt= 0;
  char c_prev= ' ';
  for(size_t i=0; i<S.size(); i++){
    char c_tmp= S.at(i);
    if(c_prev != c_tmp){
      cnts.emplace_back(cnt);
      cnt= 0;
    }

    cnt++;
    c_prev= c_tmp;
  }
  cnts.emplace_back(cnt);
  cnts.emplace_back(0);

  int64_t ans= 0;
  size_t id_peak_mod2= (S.at(0)=='>') ? 1
                                      : 0;
  for(size_t i=1; i< cnts.size(); i++){
    ans+= cnts.at(i)*(cnts.at(i)-1)/ 2;
    if(i%2==id_peak_mod2){
      ans+= max(cnts.at(i-1), cnts.at(i));
    }
  }

  cout << ans << endl;
}

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

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int[] odd = new int[100001];
		int[] even = new int[100001];
		Arrays.fill(odd, 0);
		Arrays.fill(even, 0);
		for (int i = 0; i < n; i++) {
			int v = sc.nextInt();
			if ( i%2 == 0 ) {
				odd[v]++;
			} else {
				even[v]++;
			}
		}

		int odd_max1 = 0;
		int odd_max2 = 0;
      	int even_max1 = 0;
		int even_max2 = 0;
		for (int i = 1; i <= 100000; i++) {
			if (odd[i] > odd[odd_max1]) {
				odd_max2 = odd_max1;
				odd_max1 = i;
			} else if (odd[i] > odd[odd_max2]) {
            	odd_max2 = i; 
            }
			if (even[i] > even[even_max1]) {
				even_max2 = even_max1;
				even_max1 = i;
			}
            else if (even[i] > even[even_max2]) {
            	even_max2 = i; 
            }
		}
      	/*
      	System.out.println(odd_max1);
      	System.out.println(odd_max2);
      	System.out.println(even_max1);
      	System.out.println(even_max2);
      	*/
		int rewrite = n;
		if (odd_max1 == even_max1) {
			rewrite = Math.min(n - odd[odd_max1] - even[even_max2], rewrite - odd[odd_max2] - even[even_max1]);
		} else {
			rewrite = n - odd[odd_max1] - even[even_max1];
		}
		System.out.println(rewrite);
	}
}

Measured memory_bytes: 62800
#include<cstdio>
#include<cstdlib>
#include<algorithm>
#include<iostream>
#include<queue>
#include<vector>
#include <bitset>
#include<math.h>
using namespace std;
#define INF 1100000000000000
#define MOD 1000000007
typedef long long ll;
typedef pair<int,ll> P;

const int MAX_C=100;
ll Com[MAX_C][MAX_C];
vector<int> V;

void calc_com(){
    memset(Com,0,sizeof(Com));
    Com[0][0]=1;
    for(int i=1;i<MAX_C;i++){
        Com[i][0]=1;
        for(int j=1;j<MAX_C;j++){
            Com[i][j]=Com[i-1][j-1]+Com[i-1][j];
        }
    }
}


int main(){
    calc_com();
    int N,A,B;
    cin>>N>>A>>B;
    ll v[60];
    for(int i=0;i<N;i++){
        cin>>v[i];
    }
    sort(v,v+N,greater<ll>());
    ll ans=0;

    for(int i=0;i<A;i++){
        ans+=v[i];
    }
    v[N]=0;
    int count=1;
    for(int i=1;i<=N;i++){
        if(v[i-1]==v[i]) count++;
        else{
            V.push_back(count);
            count=1;
        }
    }
    ll sum=0;
    if(V[0]>=A){
        for(int i=A;i<=min(B,V[0]);i++){
            sum+=Com[V[0]][i];
        }
    }else{
        int temp=0,num;
        for(int i=0;i<(int)V.size();i++){
            if(temp+V[i]>=A){
                num=i;
                break;
            }else temp+=V[i];
        }
        sum=Com[V[num]][A-temp];
    }
    printf("%.6lf\n",(double)ans/A);
    cout<<sum<<endl;
}


Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
int n,x[100010],L,f[100010][22],Q,g[100010][22];
int main()
{
	scanf("%d",&n);
	for (int i=1;i<=n;i++)
	  scanf("%d",&x[i]);
	scanf("%d",&L);
	int k=1; 
	for (int i=1;i<=n;i++) {
	  while (x[k]-x[i]<=L&&k<=n) k++;
	  f[i][0]=k-1;
    }
    k=n;
    for (int i=n;i;i--) {
    	while (x[i]-x[k]<=L&&k>=1) k--;
    	g[i][0]=k+1;
    }
    for (int i=1;i<=20;i++)
      for (int j=1;j<=n;j++)
        f[j][i]=f[f[j][i-1]][i-1],g[j][i]=g[g[j][i-1]][i-1];
    scanf("%d",&Q);
    for (int i1=1;i1<=Q;i1++) {
    	int a,b;
    	int ans=0;
    	scanf("%d%d",&a,&b);
    	if (a<b) {
    		for (int i=20;i>=0;i--)
    	  	  if (f[a][i]<b) ans+=1<<i,a=f[a][i];
    		ans++;
    	}
    	else {
    		for (int i=20;i>=0;i--)
    		  if (g[a][i]>b) ans+=1<<i,a=g[a][i];
    		ans++;
    	}
    	printf("%d\n",ans);
	}
	return 0;
}

Measured memory_bytes: 18432
#include<bits/stdc++.h>
#define all(v) v.begin(),v.end()
using namespace std;
int main(){
	long long a,b,c,x,y;
	cin>>a>>b>>c>>x>>y;
	long long ans=a*x+b*y,d=min(x,y),e=max(x,y);
	if(ans>d*c*2+a*(x-d)+b*(y-d)){
		ans=d*c*2+a*(x-d)+b*(y-d);
	}
	if(ans>e*c*2){
		ans=e*c*2;
	}
	cout<<ans<<endl;
    return(0);
}

Measured memory_bytes: 3592
#include<stdio.h>
#include<iostream>
#include<algorithm>
#include<string>
#include<string.h>
#include<math.h>
#include<stdlib.h>
#include<vector>
#include<queue>
#include<map>
#include<iomanip>
#include<set>
#define rep(index,num) for(int index=0;index<num;index++)
#define rep1(index,num) for(int index=1;index<=num;index++)
#define scan(argument) cin>>argument
#define prin(argument) cout<<argument<<endl
#define kaigyo cout<<endl
#define eps 1e-7
#define mp(a1,a2) make_pair(a1,a2)
typedef long long ll;
typedef long double ld;
using namespace std;
typedef pair<ll,ll> pll;
typedef pair<int,int> pint;
typedef vector<int> vint;
typedef vector<ll> vll;
typedef vector<pint> vpint;
typedef vector<pll> vpll;
ll INFl=1e+18+1;
int INF=1e+9+1;
int main(){
	int N,v[55];
	scan(N);
	rep(i,N){
		scan(v[i]);
	}
	sort(v,v+N);
	ld ans=0;
	rep(i,N){
		int beki;
		if(i==0) beki=N-1;
		else beki=N-i;
		ans+=(ld)v[i]/pow(2.0,beki);
	}
	prin(setprecision(10)<<ans);
	return 0;
}


Measured memory_bytes: 384
import math

H=int(input())
W=int(input())
N=int(input())

if W>H :
    if N%W==0:
        k=N/W
    else:
        k=math.ceil(N/W)
else:
    if N%H==0:
        k=N/H
    else:
        k=math.ceil(N/H)

k=int(k)
print(k)

Measured memory_bytes: 3060