akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;
int p,sum;
#define MAXN 305
int f[MAXN][MAXN];

int gcd(int a,int b)
{
    //if(!b)return a;
    //return gcd(b,a%b);
    if(f[a][b]!=-1)return f[a][b];
    else
    {
        int aa=a,bb=b;
        int c;
        while(b)
        {
            c=a%b;
            a=b;
            b=c;
        }
        return f[aa][bb]=a;
    }
}
int main()
{
    memset(f,-1,sizeof f);
    scanf("%d",&p);
    for(int i=1;i<=p;i++)
    for(int j=1;j<=p;j++)
    for(int k=1;k<=p;k++)
    {
        sum+=gcd(gcd(i,j),k);
    }
    printf("%d\n",sum);
    return 0 ;
}


Measured memory_bytes: 4176
import java.util.*;
import java.io.*;
public class Main{
	static int find(int a,int parent[]){
		if(a == parent[a])return a;
		parent[a] = find(parent[a],parent);
		return parent[a];
	}
	static void merge(int a,int b,int parent[],int rank[]){
		int repa = find(a,parent);
		int repb = find(b,parent);
		if(repa == repb)return;
		if(rank[repa] > rank[repb])
			parent[repb] = repa;
		else parent[repa] = repb;
		if(rank[repa] == rank[repb])
			++rank[repb];
	}
	public static void main(String [] args)throws Exception{
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		StringTokenizer st = new StringTokenizer(br.readLine());
		int n = Integer.parseInt(st.nextToken());
		int k = Integer.parseInt(st.nextToken());
		int l = Integer.parseInt(st.nextToken());
		int parentA[] = new int[n + 1];
		int parentB[] = new int[n + 1];
		int rankA[] = new int[n + 1];
		int rankB[] = new int[n + 1];
		for(int i = 1;i <= n;i++){
			parentA[i] = i;
			parentB[i] = i;
		}
		for(int i = 1;i <= k;i++){
			st = new StringTokenizer(br.readLine());
			int a = Integer.parseInt(st.nextToken());
			int b = Integer.parseInt(st.nextToken());
			merge(a,b,parentA,rankA);
		}
		for(int i = 1;i <= l;i++){
			st = new StringTokenizer(br.readLine());
			int a = Integer.parseInt(st.nextToken());
			int b = Integer.parseInt(st.nextToken());
			merge(a,b,parentB,rankB);
		}
		//for(int i = 1;i <= n;i++)System.out.println(i + " " + parentA[i]);
		//	for(int i = 1;i <= n;i++)System.out.println(i + " " + parentB[i]);
		HashMap<Long,Integer>map = new HashMap<>();
		for(int i = 1;i <= n;i++){
           long temp = find(i,parentA)*1L*n + find(i,parentB);
           if(map.containsKey(temp))
           	map.put(temp,map.get(temp) + 1);
           else map.put(temp,1);
		}
		StringBuilder sb = new StringBuilder();
		for(int i = 1;i <= n;i++){
			long temp = find(i,parentA)*1L*n + find(i,parentB);
			sb.append(map.get(temp) + " ");
		}
		System.out.println(sb);
	}
}

Measured memory_bytes: 66288
#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  cin >> n;
  if(n<=8){
    cout<<n;
  }
  else if(9<=n&&n<100){
    cout<<9;
  }
  else if(100<=n&&n<1000){
    cout<<9+n-99;
  }
  else if(1000<=n&&n<10000){
    cout<<909;
  }
  else if(10000<=n&&n<100000){
    cout<<909+n-9999;
  }
  else{
    cout<<90909;
  }
}

Measured memory_bytes: 256
import heapq

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

left = A[:N]
lefty = sum(left)
right = [-A[i] for i in range(3*N-1, 2*N-1, -1)]
righty = sum(right)
left_list = [lefty]
right_list = [righty]

heapq.heapify(left)
heapq.heapify(right)


for i in range(N, 2*N):
    heapq.heappush(left, A[i])
    x = heapq.heappop(left)
    lefty += A[i] - x
    left_list.append(lefty)

for i in range(2*N-1, N-1, -1):
    heapq.heappush(right, -A[i])
    y = heapq.heappop(right)
    righty += -A[i] - y
    right_list.append(righty)

ans = - float('inf')
for i in range(len(left_list)):
    ans = max(ans, left_list[i]+right_list[len(right_list)-1-i])

print(ans)


Measured memory_bytes: 121896
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int INF = 1e9;
const double PI = acos(-1.0);

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

	int H, W;
	while(1) {
		cin >> H >> W;
		if(H == 0 && W == 0) break;
		for(int i = 0; i < H; i++) {
			for(int j = 0; j < W; j++) {
				cout << "#";
			}
			cout << "\n";
		}
		cout << "\n";
	}
	return 0;
}

Measured memory_bytes: 1176
class cxn():
    def __init__(self,start,end):
        self._start = start
        self._end = end
        self._removed = False

    def getStart(self):
        return self._start

    def getEnd(self):
        return self._end

    def isRemoved(self):
        return self._removed

    def remove(self):
        self._removed = True

N,M = map(int,input().split())

starts = []
ends = []
for i in range(M):
    s,e = map(int,input().split())
    c = cxn(s,e)
    starts.append(c)
    ends.append(c)

starts = sorted(starts,key = cxn.getStart)
ends = sorted(ends,key = cxn.getEnd)

ans = 0
temp = 0

p = 0
for i in range(M):
    rs = False
    while p < M and (not ends[i].isRemoved()) and starts[p].getStart() < ends[i].getEnd():
        temp += 1
        if starts[p] == ends[i]:
            rs = True
        else:
            starts[p].remove()
        p += 1

    if temp != 0:
        ans += 1

    if rs:
        ends[i].remove()

    temp = 0

print(ans)


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

int main() {
    int x, y, r;
    scanf("%d %d" ,&x, &y);
    if (x < y) swap(x, y);
    while(y > 0){
        r = x % y;
        x = y;
        y = r;
    }
    printf("%d\n", x);
    
    return 0;
}


Measured memory_bytes: 3224
#!/usr/bin/ruby
n,k=gets.split.map(&:to_i)
s=gets.chomp.chars.map{|c|c==?A ? 0 : 1}
f=0
i=0
while i<n&&k>0
	if (1-s[i]+f)%2>0
		s[i]=[1,0][f]
	else
		f^=1
		s[n+i]=[0,1][f]
		i+=1
	end
	k-=1
end
if 0<k
	if n%2>0
		print (1-s[i]+f+k)%2>0 ? ?A : ?B
	end
	puts 'BA'*(n/2)
else
	puts s[i,n].map{|c|(c==0)^(f==1) ? ?A : ?B}*''
end


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

typedef long long ll;

int main() {
    int H, W;
    cin >> H >> W;
    vector<string> s(H);
    rep(i, H) cin >> s[i];
    vector<vector<int>> a(H + 1, vector<int>(W + 1, 1e9));
    if (s[0][0] == '#') a[1][1] = 1;
    else a[1][1] = 0;
    rep(i, H) {
        rep(j, W) {
            if (i == 0 && j == 0) continue;
            int u = a[i][j + 1];
            if (i > 0 && s[i - 1][j] == '.' && s[i][j] == '#') u++;
            int l = a[i + 1][j];
            if (j > 0 && s[i][j - 1] == '.' && s[i][j] == '#') l++;
            a[i + 1][j + 1] = min(u, l);
        }
    }
    cout << a[H][W] << "\n";
}

Measured memory_bytes: 256
n = gets.strip.to_i
b = gets.strip.split.map(&:to_i)

a = Array.new(n)
sum = 0
a[n-1] = b[n-2]
a[0] = b[0]
sum += a[0] + a[n-1]

(-(n-2)..-1).each do |i|
  a[-i] = [b[-i],b[-i-1]].min
  sum += a[-i]
end
puts sum

Measured memory_bytes: 1788
package main

import "fmt"

func getGroup(a int) (b int){
	switch a{
	case 1,3,5,7,8,10,12: b = 0
	case 4,6,9,11: b = 1
	case 2: b = 2
	}
	return b
}

func main(){
	var x, y int
	fmt.Scan(&x, &y)
	if getGroup(x) == getGroup(y){
		fmt.Println("Yes")
	}else{
		fmt.Println("No")
	}
}

Measured memory_bytes: 512
num = input()
a = []

for i in range(3):
    a.append(num[i])
for i in range(3):
    if a[i] == '1':
        a[i] = '9'
    elif a[i] == '9':
        a[i] = '1'

print(a[0] + a[1] + a[2])


Measured memory_bytes: 2940
#include <bits/stdc++.h>
using namespace std;
int main(){
    string s, t;
    cin >> s >> t;
    int ans = 1001, c=0;
    for(int i=0; i<s.size() - t.size() + 1; i++){
        c = 0;
        for (int j=0; j<t.size(); j++){
            if (s.at(i+j) != t.at(j))c += 1;
        }
        ans = min(ans, c);

    }
    cout << ans << '\n';
}

Measured memory_bytes: 3624
<?php
  fscanf(STDIN, "%s", $S);
  $a = str_split($S);
  $ans = "Good";

  for ($i = 0; $i < 3; $i++) {
    if ($a[$i] === $a[$i + 1]) {
        $ans = "Bad";
    }
  }

  echo $ans;


Measured memory_bytes: 4728
#include <bits/stdc++.h>
#define l_ength size
const int inf = (1<<30);
const int mod = 1000000007;
using ll = long long;
using namespace std;

int main(){
	int n; cin >> n;
	vector<ll> a(n);
	for( auto &k : a ) cin >> k;
	a.push_back(0);
	ll ans = 0;
	for( int i = 0; i < n; ++i ){
		ans += a[i]/2;
		if( a[i]%2 == 1 and a[i+1] > 0 ){
			++ans;
			--a[i+1];
		}
	}
	cout << ans << endl;
}

Measured memory_bytes: 1792
package main

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

const MaxBuf = 200100
var buf []byte = make([]byte,MaxBuf)
var sc = bufio.NewScanner(os.Stdin)

func init() {
	sc.Split(bufio.ScanWords)
	sc.Buffer(buf,MaxBuf)
}

func readString() string {
	sc.Scan()
	return sc.Text()
}

func readInt() int {
	sc.Scan()
	r,_ := strconv.Atoi(sc.Text())
	return r
}

func readInt64() int64 {
	sc.Scan()
	r,_ := strconv.ParseInt(sc.Text(),10,64)
	return r
}

func readFloat64() float64 {
	sc.Scan()
	r,_ := strconv.ParseFloat(sc.Text(),64)
	return r
}

func main() {
	const MOD = 1e9+7
	n := readInt()
	a := make([]*big.Int,n)
	lcm := big.NewInt(1)
	for i := 0; i < n; i++ {
		a[i] = big.NewInt(readInt64())
		m := new(big.Int).Mul(lcm,a[i])
		//fmt.Println(m)
		d := new(big.Int)
		d.GCD(nil,nil,lcm,a[i])
		lcm.Div(m,d)
	}

    //fmt.Println(lcm)
	ans := big.NewInt(0)
	for i := 0; i < n; i++ {
	    d := new(big.Int)
		ans.Add(ans,d.Div(lcm,a[i]))
	}
	ans.Mod(ans,big.NewInt(MOD))
	fmt.Println(ans)
}

Measured memory_bytes: 7680
#include"bits/stdc++.h"

using namespace std;

#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
using P = pair<int, int>;

void Main()
{
	int a, b;
	cin >> a >> b;
	cout << a * b << ' ' << 2 * (a+b) << endl;
}

int main()
{
	std::cin.tie(nullptr);
	std::ios_base::sync_with_stdio(false);
	std::cout << std::fixed << std::setprecision(15);
	Main();
	return 0;
}



Measured memory_bytes: 3136
#![allow(unused_mut)]
#![allow(non_snake_case)]
#![allow(unused_imports)]
use std::collections::HashSet;
use std::collections::HashMap;
use std::collections::BTreeSet;
use std::collections::VecDeque;
use std::cmp::{max, min};

use std::io::prelude::*;

fn input<T>() -> T
    where T: std::str::FromStr {
    let stdin = std::io::stdin();
    let token: String = stdin
        .lock()
        .bytes()
        .map(|c| c.unwrap() as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().unwrap()
}

fn main() {
    let n: usize = input();
    let t: usize = input();
    let mut ts: Vec<usize> =
        (0..n).map(|_| input()).collect();
    let mut sum = 0;
    for i in 0..ts.len() - 1 {
        if ts[i + 1] - ts[i] > t {
            sum += t;
        } else {
            sum +=  ts[i + 1] - ts[i];
        }
    }
    println!("{}", sum + t);
    // println!("{}", ts.into_iter().sum::<usize>() + n * t as usize);
    /*
    if ts.len() == 1 {
        println!("{}", t);
        return;
    }
    let mut pre: usize = ts[0];
    let mut next: usize;
    let mut total: usize = 0;
    for time in ts.into_iter().skip(1) {
        next = time;
        if next - pre < t { 
            total += next - pre;
        } else { 
            total += t;
        }
    }
    println!("{}", total + t);
    */
}

Measured memory_bytes: 6396
#include <iostream> //中文注释
#include <stdio.h>
#include <math.h>
#include <string.h>
#include <time.h>
#include <stdlib.h>
#include <string>
#include <bitset>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <algorithm>
#include <sstream>
#include <stack>
#include <iomanip>
using namespace std;
#define pb push_back
#define mp make_pair
typedef pair<int,int> pii;
typedef long long ll;
typedef double ld;
typedef vector<int> vi;
#define fi first
#define se second
#define fe first
#define FO(x) {freopen(#x".in","r",stdin);freopen(#x".out","w",stdout);}
#define Edg int M=0,fst[SZ],vb[SZ],nxt[SZ];void ad_de(int a,int b){++M;nxt[M]=fst[a];fst[a]=M;vb[M]=b;}void adde(int a,int b){ad_de(a,b);ad_de(b,a);}
#define Edgc int M=0,fst[SZ],vb[SZ],nxt[SZ],vc[SZ];void ad_de(int a,int b,int c){++M;nxt[M]=fst[a];fst[a]=M;vb[M]=b;vc[M]=c;}void adde(int a,int b,int c){ad_de(a,b,c);ad_de(b,a,c);}
#define es(x,e) (int e=fst[x];e;e=nxt[e])
#define esb(x,e,b) (int e=fst[x],b=vb[e];e;e=nxt[e],b=vb[e])
#define VIZ {printf("digraph G{\n"); for(int i=1;i<=n;i++) for es(i,e) printf("%d->%d;\n",i,vb[e]); puts("}");}
#define VIZ2 {printf("graph G{\n"); for(int i=1;i<=n;i++) for es(i,e) if(vb[e]>=i)printf("%d--%d;\n",i,vb[e]); puts("}");}
#define SZ 666666
int n,m,a[SZ];
bool oo(int a,int b) {return (a&1)<(b&1);}
int main()
{
	scanf("%d%d",&n,&m); int o=0;
	for(int i=1;i<=m;++i)
		scanf("%d",a+i),o+=a[i]&1;
	if(o>2)
	{
		puts("Impossible");
		return 0;
	}
	sort(a+1,a+1+m,oo);
	reverse(a+1,a+1+m);
	if(m>1) swap(a[2],a[m]);
	for(int i=1;i<=m;++i) printf("%d ",a[i]);
	puts("");
	vector<int> vs;
	if(m>1)
	{
		vs.pb(a[1]-1); vs.pb(2);
		for(int i=2;i<m;++i) vs.pb(a[i]);
		vs.pb(a[m]-1);
	}
	else
	{
		vs.pb(a[1]-1); vs.pb(1);
	}
	vector<int> r;
	for(int i=0;i<vs.size();++i)
		if(vs[i]) r.pb(vs[i]);
	vs=r;
	printf("%d\n",int(r.size()));
	for(int i=0;i<r.size();++i) printf("%d ",r[i]);
	puts("");
}

Measured memory_bytes: 256
/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

import java.util.Scanner;

/**
 *
 * @author wnqmw
 */
public class Main {
    public static void main(String args[]) {
        Scanner kb = new Scanner(System.in);
        
        String k = kb.nextLine();
        boolean fin = false;
        int i = 0;
        int j = k.length()-1;
        
        while(i <= j){
            if(k.charAt(i) != k.charAt(j)){
                System.out.println("No");
                fin = true;
                break;
            }
            i++;
            j--;
        }
        i = 0;
        j = (k.length()-1)/2-1;
        while(i <= j && fin != true){
            if(k.charAt(i) != k.charAt(j)){
                System.out.println("No");
                fin = true;
                break;
            }
            i++;
            j--;
        }
        i = (k.length()+3)/2-1;
        j = k.length()-1;
        while(i <= j && fin != true){
            if(k.charAt(i) != k.charAt(j)){
                System.out.println("No");
                fin = true;
                break;
            }
            i++;
            j--;
        }
        if(fin == false){
            System.out.println("Yes");
        }
    }
}


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

typedef long long int ll;
typedef vector<long long>lve;
typedef vector<pair<ll,ll> > lvp;
typedef vector<vector<int> > ivve;

#define sp         ' '
#define endl       '\n'
#define F          first
#define S          second
#define pp         pop_back`
#define pb         push_back
#define mp         make_pair 
#define GCD(x,y)   __gcd(x,y)
#define lb         lower_bound
#define up         upper_bound
#define setp       setprecision
#define bs         binary_search
#define all(x)     x.begin(),x.end()
#define LCM(x,y)   ((x*y)/__gcd(x,y))
#define spc(x)     cout<<fixed<<setp(x)

const   long long  inf = 1e18;
const   long long  cs =  200005;
const   long long  mod = 1000000007;
const   double     PI =  2 * acos(0.0);
void solve()
{
    ll t,n=0,m,a,b,c,d,e=0,i,j,k,x,y,z,cnt=0,cnt1=0;
    bool flag = false;
    
    cin>>n;
    lve v(n);
    for(auto &ss:v) cin>>ss;
    for(i=0;i<n-1;i++)
    {
        for(j=i+1;j<n;j++)
        {
            cnt+=v[i]*v[j];
        }
    }
    cout<<cnt<<endl;
}
int32_t main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);    cout.tie(NULL);

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

    // int32_t tc;
    // cin>>tc;
    // while(tc--)
    solve();

    return 0;
}

Measured memory_bytes: 3596
#include<bits/stdc++.h>
using namespace std;
map<int, int>m1;
int main() {
	int n;
	scanf("%d", &n);
	int i;
	int flag = 0;
	for (i = 0; i < n; i++) {
		int q1;
		cin >> q1;
		if (m1[q1] != 1) {
			m1[q1] = 1;
		}
		else {
			flag = 1;
		}
	}
	if (flag)cout << "NO" << endl;
	else cout << "YES" << endl;
	return 0;
}

Measured memory_bytes: 9600
#include <bits/stdc++.h>
#define sp ' '
#define nyan "(=^・ω・^=)"
#define mkp make_pair
#define intmax 2147483647
#define llmax 9223372036854775807
#define lP pair<ll,ll>
#define iP pair<int,int>
typedef long long ll;
using namespace std;
const int mod = 1000000007;
const int mod998 = 998244353;

int N, X, Y, Z, Max;
bool B;
ll res, p10[18];
unordered_map<ll, ll>mp,mp2;

int main(){
	p10[0] = 1;
	for (int i = 1; i < 18; ++i) {
		p10[i] = p10[i - 1] * 10;
	}
	cin >> N >> X >> Y >> Z;
	Max = max({ X,Y,Z });
	mp[0] = 1;
	for (int i = 0; i <= N; ++i) {
		res *= 10;
		res %= mod;
		B ^= true;
		if (B) {
			mp2.clear();
			for (auto it = mp.begin(); it != mp.end(); ++it) {
				//cout << it->first << sp << it->second << endl;
				ll a = it->first;
				int s = 0;
				bool bx, by, bz;
				bx = by = bz = false;
				while (a) {
					s += a % 10;
					a /= 10;
					if (s == Z)bz = true;
					if (s == Y + Z)by = true;
					if (s == X + Y + Z)bx = true;
				}
				if (bx&&by&&bz) {
					res += it->second;
					res %= mod;
				}
				else {
					a = it->first;
					int p = Max;
					s = 0;
					for (int j = 0; j < 18 && a; ++j) {
						s += a % 10;
						for (; s + p > X + Y + Z&&p; --p) {
							mp2[it->first%p10[j] * 10 + p] = (mp2[it->first%p10[j] * 10 + p] + it->second) % mod;
						}
						a /= 10;
					}
					for (; p; --p) {
						mp2[it->first * 10 + p] = (mp2[it->first * 10 + p] + it->second) % mod;
					}
					mp2[0] = (mp2[0] + it->second*(10 - Max)) % mod;
				}
			}
		}
		else {
			mp.clear();
			for (auto it = mp2.begin(); it != mp2.end(); ++it) {
				//cout << it->first << sp << it->second << endl;
				ll a = it->first;
				int s = 0;
				bool bx, by, bz;
				bx = by = bz = false;
				while (a) {
					s += a % 10;
					a /= 10;
					if (s == Z)bz = true;
					if (s == Y + Z)by = true;
					if (s == X + Y + Z)bx = true;
				}
				if (bx&&by&&bz) {
					res += it->second;
					res %= mod;
				}
				else {
					a = it->first;
					int p = Max;
					s = 0;
					for (int j = 0; j < 18 && a; ++j) {
						s += a % 10;
						for (; s + p > X + Y + Z && p; --p) {
							mp[it->first%p10[j] * 10 + p] = (mp[it->first%p10[j] * 10 + p] + it->second) % mod;
						}
						a /= 10;
					}
					for (; p; --p) {
						mp[it->first * 10 + p] = (mp[it->first * 10 + p] + it->second) % mod;
					}
					mp[0] = (mp[0] + it->second*(10 - Max)) % mod;
				}
			}
		}
	}
	cout << res << endl;
	return 0;
}

Measured memory_bytes: 10056
#include <bits/stdc++.h>
typedef long long ll;
const int INF = 1e9;
const int MOD = 1e9 + 7;
using namespace std;

int cnt[200010];

int main() {
  int n, k;
  cin >> n >> k;
  for (int i = 0; i < n; i++) {
    int a;
    cin >> a;
    cnt[a - 1]++;
  }
  sort(cnt, cnt + n);
  int ans = 0;
  for (int i = 0; i < n - k; i++) ans += cnt[i];
  cout << ans << endl;
}

Measured memory_bytes: 1024
//C
#ifndef _GLIBCXX_NO_ASSERT
#include <cassert>
#endif
#include <cctype>
#include <cerrno>
#include <cfloat>
#include <ciso646>
#include <climits>
#include <clocale>
#include <cmath>
#include <csetjmp>
#include <csignal>
#include <cstdarg>
#include <cstddef>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>

#if __cplusplus >= 201103L
#include <ccomplex>
#include <cfenv>
#include <cinttypes>
#include <cstdalign>
#include <cstdbool>
#include <cstdint>
#include <ctgmath>
#include <cwchar>
#include <cwctype>
#endif

// C++
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>

#if __cplusplus >= 201103L
#include <array>
#include <atomic>
#include <chrono>
#include <condition_variable>
#include <forward_list>
#include <future>
#include <initializer_list>
#include <mutex>
#include <random>
#include <ratio>
#include <regex>
#include <scoped_allocator>
#include <system_error>
#include <thread>
#include <tuple>
#include <typeindex>
#include <type_traits>
#include <unordered_map>
#include <unordered_set>
#endif

//ここまで毎回include
//以下プログラム

using namespace std;

int main() {
	long N, A, B, C, D, E;
	cin >> N >> A >> B >> C >> D >> E;
	long result = 0;
	long x = min({ A, B, C, D, E });
	int check = 0;
	if (x == A && check == 0) {
		if (N % A == 0) {
			cout << N / A + 4 << endl;
		}
		else {
			cout << N / A + 5 << endl;
		}
		check = 1;
	}
	if (x == B && check == 0) {
		if (N % B == 0) {
			cout << N / B + 4 << endl;
		}
		else {
			cout << N / B + 5 << endl;
		}
		check = 1;
	}
	if (x == C && check == 0) {
		if (N % C == 0) {
			cout << N / C + 4 << endl;
		}
		else {
			cout << N / C + 5 << endl;
		}
		check = 1;
	}
	if (x == D && check == 0) {
		if (N % D == 0) {
			cout << N / D + 4 << endl;
		}
		else {
			cout << N / D + 5 << endl;
		}
		check = 1;
	}
	if (x == E && check == 0) {
		if (N % E == 0) {
			cout << N / E + 4 << endl;
		}
		else {
			cout << N / E + 5 << endl;
		}
		check = 1;
	}
}


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

int N,L;

int main(){
    cin>>N>>L;
    int trg=L,sum=L;
    for(int i=1;i<N;i++){
        sum+=L+i;
        if(abs(L+i)<abs(trg))trg=L+i;
    }
    cout<<sum-trg<<endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <functional>
#include <queue>
#include <set>
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define rep1(i,n) for(int i=1;i<=(int)(n);i++)

using namespace std;
typedef long long int lli;

int main(){
	int a,b,h;
	cin>>a>>b>>h;
	cout<<(a+b)*h/2;
}

Measured memory_bytes: 256
import itertools
import math

n = int(input())
a = [list(map(int, input().split())) for i in range(n)]

seq = list()
for i in range(n):
    seq.append(i)

seq_all = list(itertools.permutations(seq))

ans = 0
for i in seq_all:
    for j in range(n - 1):
        end = i[j + 1]
        start = i[j]
        ans += math.sqrt((a[end][0] - a[start][0]) ** 2 + (a[end][1] - a[start][1]) ** 2)

print(ans / len(seq_all))


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

using namespace std;

#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REP(i,n) FOR(i,0,n)
#define ALL(v) (v).begin(),(v).end()

template<typename A, typename B> inline bool chmax(A &a, B b) { if (a<b) { a=b; return 1; } return 0; }
template<typename A, typename B> inline bool chmin(A &a, B b) { if (a>b) { a=b; return 1; } return 0; }

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

const ll INF = 1<<29;
const ll MOD = 1000000007;
const double EPS  = 1e-10;

int main() {
	ll n;
	cin >> n;
	
	int ans = INF;
	
	for (ll i = 1; i * i <= n; i++) {
		ll a = i, b = n / i;
		if (a * b != n) continue;
		
		chmin(ans, max<int>(log10(a) + 1, log10(b) + 1));
	}
	cout << ans << endl;
	
	return 0;
}

Measured memory_bytes: 256
result = []
loop do
    input = gets.chomp!.to_i
    ary = []
    break unless input != 0

    input.times do
        ary << gets.chomp!.to_i
    end

    ary.sort!{|a, b| a<=>b}
    ary.delete_at(0)
    ary.delete_at(ary.length-1)
    
    sum = 0
    ary.each do |i|
        sum += i
    end
    
    result << sum / ary.length
end

result.each do |r|
    p r
end

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

void sort(char str[]) {
	int i, j, tmp;

	for (i = 3; i > 0; --i) {
		for (j = 0; j < i; ++j) {
			if (str[j] < str[j + 1]) {
				tmp = str[j];
				str[j] = str[j + 1];
				str[j + 1] = tmp;
			}
		}
	}
}

int main() {
	char str[10];

	cin >> str;

	sort(str);

	if(str[0] == str[1] && str[2] == str[3] && str[1] != str[2])
	cout << "Yes" << endl;	
	else
	cout << "No" << endl;

	return 0;
}

Measured memory_bytes: 256
N, = (int(x) for x in input().split())
A_arr = []
for _ in range(N):
    A_arr.append(int(input()))

A2_arr = sorted(A_arr, reverse=True)

for a in A_arr:
    if a == A2_arr[0]:
        print(A2_arr[1])
    else:
        print(A2_arr[0])



Measured memory_bytes: 14112
package main

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

func main() {
	sc.Split(bufio.ScanWords)
	a := nextInt()
	b := nextInt()
	c := nextInt()
	if a <= b && a <= c && b < c {
		fmt.Println(a, b, c)

	} else if a <= b && a <= c {
		fmt.Println(a, c, b)
	} else if b <= a && b <= c && a <= c {
		fmt.Println(b, a, c)
	} else if b <= a && b <= c && a > c {
		fmt.Println(b, c, a)
	} else if c <= a && a <= b {
		fmt.Println(c, a, b)
	} else {
		fmt.Println(c, b, a)
	}
}

var sc = bufio.NewScanner(os.Stdin)

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



Measured memory_bytes: 1092
from collections import deque

n, q = map(int, input().split())
rg = [[] for _ in range(n)]
for _ in range(n-1):
    a, b = map(int, input().split())
    rg[a-1].append(b-1)
    rg[b-1].append(a-1)

deq = deque()
pnt = [0] * n

for _ in range(q):
    p, x = map(int, input().split())
    pnt[p-1] += x

visited = set()

deq.append(0)
visited.add(0)

while deq:
    ptr = deq.pop()
    for item in rg[ptr]:
        if item not in visited:
            visited.add(item)
            pnt[item] += pnt[ptr]
            deq.append(item)

print(' '.join(map(str, pnt)))


Measured memory_bytes: 73704
#!/usr/bin/env python3
# -*- Coding: utf-8 -*-

import sys


def main():
    S = input()

    ary = [0]
    now = "<"

    for s in S:
        if s == now:
            ary[-1] += 1
        else:
            ary.append(1)
            now = s

    ans = 0
    for i in range(1, len(ary), 2):
        mi, ma = sorted([ary[i], ary[i-1]])
        ans += ma*(ma+1)//2
        ans += (mi-1)*mi//2
    if len(ary) % 2 == 1:
        ans += ary[-1]*(ary[-1]+1)//2
    print(ans)


if __name__ == '__main__':
    main()


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

const int N = 1e6 + 5;

char A[N];

int main(void) {
	scanf("%s", A + 1);
	int n = strlen(A + 1);
	int cnt[4] = {0,0,0,0};
	for (int i = 1; i <= n; ++ i) {
		if (A[i] == 'W') cnt[0] = 1;
		if (A[i] == 'E') cnt[1] = 1;
		if (A[i] == 'N') cnt[2] = 1;
		if (A[i] == 'S') cnt[3] = 1;
	}
	if (cnt[0] && ! cnt[1]) return 0 * puts("No");
	if (!cnt[0] && cnt[1]) return 0 * puts("No");
	if (cnt[2] && ! cnt[3]) return 0 * puts("No");
	if (!cnt[2] && cnt[3]) return 0 * puts("No");
	puts("Yes");
	return 0;
}

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

#define For(i, j, k) for(int i = j; i <= k; i++)
#define Forr(i, j, k) for(int i = j; i >= k; i--)
#define pb push_back

using namespace std;

const int N = 8010;

int n, m, k = 2;
int w[N];
bool go[N][N << 1];
char S[N];

int main(){

	scanf("%s%d%d", S + 1, &n, &m);
	int l = 1, Sx = 0;
	while(S[l] == 'F') ++l, ++Sx;
	while(S[l] == 'T'){
		++k, ++l;
		while(S[l] == 'F') ++w[k], ++l;
	}

	go[2][Sx + N] = true;
	for(int i = 4; i <= k; i += 2)
		For(j, -N + 1, N - 1) if(go[i - 2][j + N]){
			if(j - w[i] > -N) go[i][j - w[i] + N] = true;
			if(j + w[i] < N) go[i][j + w[i] + N] = true;
		}

	go[1][N] = true;
	for(int i = 3; i <= k; i += 2)
		For(j, -N + 1, N - 1) if(go[i - 2][j + N]){
			if(j - w[i] > -N) go[i][j - w[i] + N] = true;
			if(j + w[i] < N) go[i][j + w[i] + N] = true;
		}

	bool ans = k & 1 ? go[k][m + N] && go[k - 1][n + N] : go[k][n + N] && go[k - 1][m + N];
	puts(ans ? "Yes" : "No");

	return 0;
}

Measured memory_bytes: 123648
#include <bits/stdc++.h>
using namespace std;
 
#define ll long long int
#define rep(i, n) for(int i = 0; i < n; i++)
#define repp(i, n) for(int i = 1; i <= n; i++)
#define sort(v) sort((v).begin(), (v).end())
#define pb push_back
#define riverse(v) reverse((v).begin(), (v).end())
using vi = vector<int>;
using vs = vector<string>;
using vvi = vector<vi>;
using vll = vector<ll>;
const int MOD = 1e9+7;

int main() {
    int H, W, N;
    cin >> H >> W >> N;
    vi a(N);
    rep(i, N) cin >> a[i];
    vi ans;
    rep(i, N) {
        rep(j, a[i]) ans.pb(i + 1);
    }
    vvi img(H, vi(W));
    rep(i, H) {
        rep(j, W) {
            img[i][j] = ans[i * W + j];
        }
    }
    rep(i, H) {
        if (i % 2 == 1)riverse(img[i]);
    }
    rep(i, H) {
        rep(j, W) {
            cout << img[i][j] << " ";
        }
        cout << endl;
    }
}

Measured memory_bytes: 384
use std::io::*;
use std::str::FromStr;
 
pub fn read<T: FromStr>() -> T {
  let stdin = stdin();
  let stdin = stdin.lock();
  let token: String = stdin
    .bytes()
    .map(|c| c.expect("failed to read char") as char)
    .skip_while(|c| c.is_whitespace())
    .take_while(|c| !c.is_whitespace())
    .collect();
  token.parse().ok().expect("failed to parse token")
}
 
// use std::cmp::{max, min};
 
fn main() {
  let n = read::<u64>();
  let n_str = n.to_string();
  let mut sum = 0;
 
  sum += dfs(String::from("3"), n_str.len(), n);
  sum += dfs(String::from("5"), n_str.len(), n);
  sum += dfs(String::from("7"), n_str.len(), n);
 
  println!("{}", sum);
}
 
fn dfs(num: String, l_keta: usize, limit: u64) -> u64 {
  let num_i = num.parse::<u64>().unwrap();
 
  let mut sum = 0;
 
  if num.contains('3') && num.contains('5') && num.contains('7') && num_i <= limit {
    sum += 1;
  }
  if num.len() > l_keta {
    return 0;
  }
  let num_3 = num.clone();
  let num_5 = num.clone();
  let num_7 = num.clone();
  sum += dfs(num_3 + "3", l_keta, limit);
  sum += dfs(num_5 + "5", l_keta, limit);
  sum += dfs(num_7 + "7", l_keta, limit);
  sum
}

Measured memory_bytes: 4352
#include <iostream>
#include <climits>
#include <string>
#include <vector>
#include <cmath>
using namespace std;

#define ll long long

void solve()
{
	ll h, a;
	cin >> h >> a;

	cout << ceil(static_cast<double>(h) / a);
}

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

	solve();

	return 0;
}

Measured memory_bytes: 256
N = int(input())
L_list = list(map(int, input().split()))
c = 0
if len(L_list) < 3:
    print(c)
else:
    for i in range(N):
        for j in range(i,N):
            for k in range(j,N):
                if L_list[i] == L_list[j] or L_list[i] == L_list[k] or L_list[j] == L_list[k]:
                    continue
                else:
                    n1 = L_list[i]
                    n2 = L_list[j]
                    n3 = L_list[k]                   
                    if n1 + n2 > n3 and n1 + n3 > n2 and n3 + n2 > n1:
                        c += 1
    print(c)

Measured memory_bytes: 9208
#include <stdio.h>

int main()
{
	int iNum[3] = {0};
	int iCount;
	int iCount2;
	int iSort;
	scanf("%d %d %d",&iNum[0],&iNum[1],&iNum[2]);

	for (iCount = 1; iCount < 3; iCount++)
	{
		for (iCount2 = 0; iCount2 < 3 - iCount; iCount2++)
		{
			if (iNum[iCount2] > iNum[iCount2+1])
			{
				iSort = iNum[iCount2];
				iNum[iCount2] = iNum[iCount2+1];
				iNum[iCount2+1] = iSort;
			}
		}
	}
	printf("%d %d %d\n",iNum[0], iNum[1], iNum[2]);
	return 0;
}


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

#define fr first
#define sc second
#define mk make_pair

using namespace std;

int n, a, b, u[1000001];

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

    if(a == 1)
    {
        if(b == n)
        {
            for(int i = n; i >= 1; i--)
                cout << i << " ";
        }else
        {
            cout << -1;
        }
        return 0;
    }
    if(b == 1)
    {
        if(a == n)
        {
            for(int i = 1; i <= n; i++)
                cout << i << " ";
        }else
        {
            cout << -1;
        }
        return 0;
    }

    if(a + b - 1 > n || a == 0 || b == 0)
    {
        cout << -1;
        return 0;
    }
    vector<int> vec, ans;
    int t = 0;
    if(a > b)
        t = 1, swap(a, b);

    for(int i = n; i >= 1; i--)
        vec.push_back(i);

    int l = 0, r = vec.size() - 1, kol1 = 0, kol2 = 0;
    while(ans.size() < n && a > 0 && b > 0)
    {
        int y = vec.size();
        for(int j = min(l + a - 1, y - 1); j >= l; j--)
        {
            if(u[vec[j]] == 0)
                ans.push_back(vec[j]);
            u[vec[j]] = 1;
        }

        l += a;
        b--;
        if(ans.size() >= n || b <= 0)
            break;

        for(int j = max(0, r - b + 1); j <= r; j++)
        {
                if(u[vec[j]] == 0)
                    ans.push_back(vec[j]);
                u[vec[j]] = 1;
        }
        r -= b;
        a--;
    }
    if(ans.size() != n)
    {
        cout << -1;
        return 0;
    }
    //cout << kol1 << " " << kol2 << endl;
    if(t == 1)
    {
        //cout << "*";
        for(int i = 0; i < ans.size(); i++)
            ans[i] = n - ans[i] + 1;
        //swap(kol1, kol2);
    }
    for(int i = 0; i < ans.size(); i++)
    {
        cout << ans[i] << " ";
    }

    return 0;
}


Measured memory_bytes: 5872
#include<iostream>
#include<algorithm>
#include<string>
#include<map>
#include<vector>
using namespace std;
int main()
{
	multimap<string,int> ans;
	string in; int num;
	while(cin>>in>>num) 
	{
		ans.insert(multimap<string,int>::value_type(in,num));
	}

	multimap<string,int>::iterator it=ans.begin();
	while(1) 
	{
		int cnt=ans.count((*it).first);
		cout<<(*it).first<<endl;
		bool f=false;
		vector<int> nums(0,0);
		while(cnt--) 
		{
			//cout<<(*it).second<<endl;
			nums.push_back((*it).second);
			it++;
		}
		sort(nums.begin(),nums.end());
		for(int i = 0; i < nums.size(); ++i)
		{
			if(f) cout<<" ";
			cout<<nums[i];
			f=true;
		}
		cout<<endl;
		if(it==ans.end()) break;
	}
  return 0;
}

Measured memory_bytes: 1244
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ull = unsigned long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
#define INF 2100000000
#define MOD 1000000007

bool dbgflag = false; //debug

struct abridge {
  int height;
  set<int> nxt;
};

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

  int n, m;
  cin >> n >> m;
  vector<abridge> bridge(n);
  for (int i = 0; i < n; i++) cin >> bridge[i].height;
  for (int i = 0; i < m; i++) {
    int a, b;
    cin >> a >> b;
    a--; b--;
    bridge[a].nxt.insert(b);
    bridge[b].nxt.insert(a);
  }

  int cnt = 0;
  for (auto br: bridge) {
    bool f = true;
    for (auto nbr: br.nxt) {
      if (bridge[nbr].height >= br.height) {
        f = false;
        break;
      }
    }
    if (f) cnt++;
  }

  cout << cnt << endl;
}


Measured memory_bytes: 18196
#include <string>
#include <vector>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <algorithm>
#include <queue>
#include <map>
#include <set>
#include <iostream>
#include <sstream>
#include <cstring>
#include <numeric>
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
#define F0(i,n) for (int i = 0; i < n; i++)
#define F1(i,n) for (int i = 1; i <= n; i++)
#define CL(a,x) memset(x, a, sizeof(x));
#define SZ(x) ((int)x.size())
const double eps = 1e-10;
const int MOD = 1000000007;
int i, j, k, m, n, l;

int ans;

int a[100001];

int main() {
	//freopen("x.in", "r", stdin);

	cin >> n;
	int x = 0;
	F0(i, n) {
		cin >> a[i];
		x ^= a[i];
	}

	for (int i = 60; i >= 0; i--) if ((1LL << i)&x) {
		ll mask = (1LL << (i + 1)) - 1;
		int good = 0;
		F0(j, n) {
			if ((a[j] & mask) == (1LL << i)) {
				good = 1;
				ans++;
				x ^= mask;
				break;
			}
		}
		if (!good) { ans = -1; break; }
	}
	cout << ans << endl;

	return 0;
}


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

#define pp push_back
#define pf push_front
#define mp make_pair
#define fs first
#define sc second
#define sf scanf

typedef long long ll;
typedef unsigned long long ull;

using namespace std;

const int N = (int) 1e9;

int main(int argc, char *argv[])
{
	// ios_base::sync_with_stdio(false);
	// cin.tie(NULL);

	char x, y;
	cin >> x >> y;
	if (x > y) {
		cout << ">";
	}
	else if (x < y) {
		cout << "<";
	}
	else {
		cout << "=";
	}

	return 0;
}


Measured memory_bytes: 256
#include<iostream>
using namespace std;
#define rep(i, n) for ( int i = 0; i < n; i++ )
#define MAX 10

struct Cell{ int i, j, x, id; };

int H, W, n, b, k; 
Cell P[MAX*MAX], M[MAX][MAX], A[MAX][MAX];
int V[MAX+1];

int ans;

bool check(int si, int sj, int r, int c ){
    rep(i, r) rep(j, c){
	int ii = si + i;
	int jj = sj + j;
	if ( ii < 0 || jj < 0 || ii >= H || jj >= W ) return false;
	if ( M[ii][jj].x ) return false;
    }
    return true;
}

void solve(int pos){
    if ( pos >= n ){ 
	rep(i, H) rep(j, W) if ( M[i][j].x == 0 ) return;
	rep(i, H) rep(j, W) A[i][j] = M[i][j];
	ans++;
	return;
    }

    for(int r = 1; r <= P[pos].x; r++){
	if ( P[pos].x % r != 0 ) continue;
	int c = P[pos].x / r;
	rep(di, r) rep(dj, c){
	    int si = P[pos].i - di;
	    int sj = P[pos].j - dj;
	    if ( check( si, sj,  r, c ) ){
		rep(i, r) rep(j, c) M[si+i][sj+j] = P[pos];
		solve( pos + 1 );
		rep(i, r) rep(j, c) M[si+i][sj+j].x = 0;
	    }
	}
    }
}

int main(){
    int x;
    while( cin >> W >> H && H && W ){
	cin >> n;
	rep(i, n){
	    cin >> b >> k;
	    P[b-1].x = k;
	}

	rep(i, H) rep(j, W){
	    cin >> x;
	    if ( x ){  P[x-1].i = i; P[x-1].j = j; P[x-1].id = x-1; }
	    M[i][j].x = 0;
	}
	ans = 0;
	solve(0);
	if ( ans == 1 ) {
	    rep(i, H){
		rep(j, W){
		    if ( j ) cout << " ";
		    cout << A[i][j].id+1;
		}
		cout << endl;
	    }
	} else {
	    cout << "NA" << endl;
	}
    }
    return 0;
}

Measured memory_bytes: 868
n = gets.chomp.to_i
a = gets.chomp.split().map(&:to_i)
b = []
i = 0
while(true)
    j = a[i]
    if !b[j]
        b[j] = 1
    else 
        b[j] = b[j] + 1
    end
    i = i + 1
    if i == n
        break
    end
end
sum = 0
c = b.compact
c.each do |num|
    sum = sum + 0.5*num*(num - 1)
end
k = 0
while(true)
    l = a[k]
    bl = b[l]
    puts (sum - 0.5*bl*(bl - 1) + 0.5*(bl-1)*(bl - 2)).to_i
    k = k + 1
    if k == n
        break
    end
end

Measured memory_bytes: 37416
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define ALL(x) (x).begin(), (x).end()
typedef long long ll;
typedef pair<int, int> pii;
const int INF = 1e9;
const int MOD = 1000000007;
const double PI = acos(-1);
int dx[4] = {0,1,0,-1};
int dy[4] = {1,0,-1,0};

void solve() {
	ll n, k;
	cin >> n >> k;
	vector<ll> v(200002);
	rep(i,n) {
		ll a;
		cin >> a;
		v[a]++;
	}
	sort(ALL(v), greater<>());
	ll num = 0;
	rep(i,k) {
		num += v[i];
	}
	cout << n - num << endl;
}

int main() {
	solve();
	return 0;
}

Measured memory_bytes: 4844
def main():
    n = int(input())
    a = list(map(int, input().split()))

    from heapq import heapify, heappushpop

    # first half
    fh = []
    l = a[:n]
    fh.append(sum(l))
    heapify(l)
    for i in a[n:2*n]:
        if l[0] < i:
            fh.append(fh[-1] + i - heappushpop(l, i))
        else:
            fh.append(fh[-1])

    # latter half
    lh = []
    l = [-i for i in a[2*n:]]
    lh.append(sum(l))
    heapify(l)
    for i in a[2*n-1:n-1:-1]:
        if l[0] < -i:
            lh.append(lh[-1] - i - heappushpop(l, -i))
        else:
            lh.append(lh[-1])

    ans = fh[0] + lh[n]
    for i in range(1, n+1):
        if ans < fh[i] + lh[n-i]:
            ans = fh[i] + lh[n-i]

    print(ans)

main()

Measured memory_bytes: 41896
N = gets.to_i
A = gets.split.map(&:to_i)
Q = gets.to_i
query = Q.times.map { gets.split.map(&:to_i) }

sum = A.sum
counter = Hash.new(0)
A.each do |a|
  counter[a] += 1
end

query.each_with_index do |(a, b), idx|
  diff = counter[a] * (b - a)
  sum += diff
  puts sum

  counter[b] += counter[a]
  counter[a] = 0
end


Measured memory_bytes: 27740
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
#define mfill(x,y) memset(x,y,sizeof(x))
#define all(v) v.begin(), v.end()
#define in(x,y,h,w) if(0<=x&&x<h&&0<=y&&y<w)
#define y0 y12345
#define y1 y54321

#ifdef LOCAL
#define debug(...) fprintf(stderr,__VA_ARGS__)
#else
#define debug(...) 42
#endif

using ul = unsigned long;
using ll = long long;
using P = pair<int, int>;
using vint = vector<int>;using vvint = vector<vector<int>>;
using vll = vector<ll>;using vvll = vector<vector<ll>>;
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;}
template <class T>void initvv(vector<vector<T> > &v, int a, int b, const T &t = T()){
    v.assign(a, vector<T>(b, t));
}
template <class T>T gcd(T &a, T &b){if(a<b){swap(a,b);} T r = a%b; while(r!=0){a=b;b=r;r=a%b;} return b;}

vint dx = {-1, 0, 1, 0}, dy = {0, -1, 0, 1};
vint dx8 = {-1, -1, -1, 0, 1, 1, 1, 0}, dy8 = {-1, 0, 1, 1, 1, 0, -1, -1};

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    debug("debug test\n");
    int n,m;cin>>n;
    double l = (double)n/3.0;
    printf("%.10f\n", l*l*l);

    return 0;
}


Measured memory_bytes: 256
N = int(input())
V = [i for i in map(int, input().split())]
C = [i for i in map(int, input().split())]

max_value = 0
for i in range(N):
  if V[i] > C[i]:
    max_value += V[i] - C[i]
    
print(max_value)

Measured memory_bytes: 3060
fun main(args: Array<String>) {
    val n = readLine()?.toInt() ?: return
    1.until(n + 1).map {
        var count = 0
        var r = it
        while (r % 2 == 0 && r / 2 > 0) {
            count++
            r /= 2
        }
        Pair(it, count)
    }.maxBy { it.second }?.let {
        println(it.first.toString())
    }
}

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



int main() {
    string s;
    cin >> s;
    int ans = 0;
    for (int i = 0; i < s.size(); i++) {
        int j = s.size()-1-i;
        if (s[i] != s[j] && i < j) ans++; 
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 3592
#include<bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i=0; i<n; i++)
#define rep1(i, n) for(int i=1; i<=n; i++)
#define repr(i, n) for(int i=n-1; i>=0; i--)
#define repr1(i, n) for(int i=n; i>=1; i--)
#define all(v) v.begin(),v.end()
using ll = long long;
using pii = pair<int, int>;
using pil = pair<int, ll>;
using pli = pair<ll, int>;
using pll = pair<ll, ll>;
const int INF = 1e9;
const ll LLINF = 1e18;
const ll MOD = 1e9+7;
const double EPS = 1e-10;
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; }

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

    vector<int> num(n, 1);
    set<int> s = {0};
    rep(i, m) {
        int x, y; cin >> x >> y;
        x--; y--;
        if (s.find(x) != s.end()) {
            s.insert(y);
            if (num[x] == 1) s.erase(x);
        }
        num[x]--; num[y]++;
    }
    cout << s.size() << endl;
}


Measured memory_bytes: 5376
#include <iostream>
#include<math.h>
using namespace std;
int kyori[1000];
int tennki[1000];
int dp[1000];
int main() {
	int n,m;
	cin>>n>>m;
	for(int i=0;i<n;i++){
		cin>>kyori[i];
	}
	for(int i=0;i<m;i++){
		cin>>tennki[i];
	}
	for(int i=0;i<1000;i++){
		dp[i]=-1;
	}
	for(int day=0;day<m;day++){
		for(int city =n-1;city>=0;city--){
			if(city==0){
				if(dp[city]==-1){dp[city]=kyori[city]*tennki[day];}
				else{dp[city]=min(dp[city],kyori[city]*tennki[day]);}
			}
			else{
				if(dp[city]==-1&&dp[city-1]!=-1){dp[city]=dp[city-1]+(kyori[city]*tennki[day]);}
				else{dp[city]=min(dp[city],dp[city-1]+(kyori[city]*tennki[day]));}
			}
		}
	}
	cout<<dp[n-1]<<endl;
	return 0;
}

Measured memory_bytes: 1172
a,v=map(int,input().split())
b,w=map(int,input().split())
t=int(input())
if v<=w:
    print("NO")
    exit()
if a<b:
    a+=(v*t)
    b+=(w*t)
    if a>=b:
       print("YES")
       exit()
    print("NO")
    exit()
else:
    a-=(v*t)
    b-=(w*t)
    if a<=b:
        print("YES")
        exit()
    print("NO")
    exit()

Measured memory_bytes: 9212
use std::io;
use std::cmp;

// read a line(without line feed)
fn read_line() -> String {
    let mut in_str = String::new();
    io::stdin().read_line(&mut in_str).unwrap();
    return in_str.trim().to_string();
}

// read wods on a line
pub fn read_words_in_line() -> Vec<String> {
    let s = read_line();
    return s.split_whitespace().map(|x| x.to_string()).collect::<Vec<String>>()
}

// read type t on a line
pub fn read_t_in_line<T : std::str::FromStr>() -> Vec<T> {
    let mut v : Vec<T> = Vec::new();
    for e in read_words_in_line().iter().map(|x| x.parse::<T>()) {
        if let Ok(r) = e {
            v.push(r);
        }
        else{
            return Vec::new();
        }
    }
    return v;
}

// sort slice
pub fn sort<T : std::cmp::Ord>(slice : &mut [T]) {
    slice.sort();
}
// sort slice by reverse order
pub fn sort_rev<T : std::cmp::Ord>(slice : &mut [T]) {
    slice.sort_by(|x, y| y.cmp(x));
}

pub fn min<T : std::cmp::Ord>(a : T, b : T) -> T{
    return cmp::min(a, b);
}

pub fn max<T : std::cmp::Ord>(a : T, b : T) -> T{
    return cmp::max(a, b);
}


fn main() {
    let v_x_y = read_words_in_line();
    let (x, y) = (v_x_y[0].clone(), v_x_y[1].clone());
    if x < y {
        println!("<");
    }
    else if x > y {
        println!(">");
    }
    else{
        println!("=");
    }
}


Measured memory_bytes: 4352
# coding: utf-8

import sys
import math
import collections
import itertools
def input(): return sys.stdin.readline().strip()
def gcd(x, y): return y if x % y == 0 else gcd(y, x % y)
def lcm(x, y): return (x * y) // gcd(x, y)
MOD = 10 **9 + 7

N = int(input())
# S = input()
# N, M = map(int, input().split())
# 横
A = [int(x) for x in input().split()]
# 縦
# A = [int(input()) for _ in range(N)]
# 多次元
# L = [[int(x) for x in input().split()] for _ in range(N)]

ans = 0
for a in A :
        ans += (1 / a)

print(1 / ans)


Measured memory_bytes: 38256
k = gets.to_i
exit 0&p(k+9)  if 4 > k-=9
F =->(n,i,d) {
  a = [i-1,i,i+1]
  a.shift  if i<1
  a.pop  if i>8
  if d > 0
    a.each {|j| F[(n+i)*10,j,d-1]}
  else
    exit 0&p((n+i)*10 + a[k-1])  if k <= a.size
    k -= a.size
  end
}
0.upto(9) {|d|
  1.upto(9) {|i| F[0,i,d]}
}

Measured memory_bytes: 1788
#include <iostream>
#include <cstdio>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <iomanip>
#include <stdlib.h>
#include <string.h>
#include <cstring>
#include <cmath>
#include <map>
#include <queue>
#include <deque>
#include <stack>
#include <set>
#include <stdio.h>
#include <tuple>
#include <bitset>
#include <cfloat>
#include <fstream>
#include <limits.h>
#include <list>
#include <math.h>
#include <random>
#include <unordered_map>
#include <unordered_set>
#include <bitset>
#include <numeric>
#include <utility>
#include <sstream>

template<class T> inline bool chmin(T& a, T b) {
	if (a > b) {
		a = b;
		return true;
	}
	return false;
}
template<class T> inline bool chmax(T& a, T b) {
	if (a < b) {
		a = b;
		return true;
	}
	return false;
}

using namespace std;
#define int long long
#define ll long long
#define rep(i, n) for (ll i = 0; i < (n); i++)
#define FOR(i,a,b) for(ll i=(a);i<(b);i++)
#define FORR(i,a,b)for(ll i=(a);i<=(b);i++)
#define repr(i,n) for(ll i=n;i>=0;i--)
#define P pair<ll, ll>
#define sz(x) (ll)x.size()
#define ALL(x) (x).begin(),(x).end()
#define ALLR(x) (x).rbegin(),(x).rend()
#define VE vector<ll>
#define COUT(x) cout<<(x)<<endl
#define MA map<ll,ll>
#define SE set<ll>
#define PQ priority_queue<ll>
#define PQR priority_queue<ll,VE,greater<ll>>
#define COUT(x) cout<<(x)<<endl
#define YES(n) cout << ((n) ? "YES" : "NO"  ) << endl
#define Yes(n) cout << ((n) ? "Yes" : "No"  ) << endl
#define EPS (1e-10)
ll gcd(ll a, ll b) {
	if (a < b)swap(a, b);
	if (b == 0) return a;
	unsigned r;
	while ((r = a % b)) {
		a = b;
		b = r;
	}
	return b;
}
ll lcm(ll a, ll b) {
	ll g = gcd(a, b);
	return a / g * b;
}
bool prime(ll n) {
	for (ll i = 2; i <= sqrt(n); i++) {
		if (n%i == 0)return false;
	}
	return n != 1;
}
map<ll, ll> prime_factor(ll n) {
	map<ll, ll> ret;
	for (ll i = 2; i * i <= n; i++) {
		while (n % i == 0) {
			ret[i]++;
			n /= i;
		}
	}
	if (n != 1) ret[n] = 1;
	return ret;
}

const long long MOD = 1000000007;
//const long long MOD = 998244353;
const long long INF = 1LL << 60;


const int MAX_N = 100010;

signed main() {
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	int n; cin >> n;
	n--;
	cout << n * (n + 1) / 2 << endl;
	return 0;
}

Measured memory_bytes: 256