akhauriyash/Code-Regression huggingface dataset:
fn main() {
    let s = std::io::stdin();
    let mut sc = Scanner { stdin: s.lock() };
    let mut l: usize = sc.read();

    let mut r = 0;
    while (1 << (r + 1)) <= l {
        r += 1;
    }

    let n = r + 1;
    let mut graph = vec![vec![]; n];
    for i in 0..r {
        graph[i].push((i + 1, 1 << i));
        graph[i].push((i + 1, 0));
    }

    let sum = (1 << r) - 1;
    for i in (0..(n - 1)).rev() {
        let to_i = (1 << i) - 1;
        if l >= to_i + 1 {
            let new_edge = l - to_i - 1;
            if new_edge > sum {
                // add paths [new_edge, new_edge+1, ..., l-1]
                graph[i].push((n - 1, new_edge));
                l = new_edge;
            }
        }
    }

    println!("{} {}", n, graph.iter().map(|e| e.len()).sum::<usize>());

    for (from, to, w) in graph
        .into_iter()
        .enumerate()
        .flat_map(|(i, e)| e.into_iter().map(move |(to, w)| (i, to, w)))
    {
        println!("{} {} {}", from + 1, to + 1, w);
    }
}

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

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


Measured memory_bytes: 4352
#include <bits/stdc++.h>
#define rep(i, n) for(int i=0; i<(n); ++i)
#define rep1(i,n) for(int i=1; i<=(n); ++i)
#define ALL(obj) (obj).begin(), (obj).end()
#define sz(v) (int)v.size()
#define pb push_back

using namespace std;
string a,b;
int main(){
    cin >> a >> b;
    string n = a+b;
    int num = stoi(n);
    int sq = sqrt(num);
    cout << ((sq*sq == num)? "Yes" : "No") << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
#include <map>
#include <math.h>
using namespace std;
int main() {
	int n, l;
	cin >> n >> l;
	string s[110];
	for (int i = 0; i < n; i++)cin >> s[i];
	sort(s, s + n);
	for (int i = 0; i < n; i++)cout << s[i];
	cout << endl;
	return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<map>
#include<string>
#include<utility>
#include<algorithm>
#include<cstdio>
#include<iomanip>
using namespace std;
#define ll int64_t
#define REP(i, n) for (ll i=0; i<n; i++)

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

    vector<ll> N(4);
    REP(i, 4) cin >> N[i];

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

    if (N[0] == 1 && N[1] == 4 && N[2] == 7 && N[3] == 9) cout << "YES" << endl;
    else cout << "NO" << endl;
}

Measured memory_bytes: 256
package main

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

func main() {
	io, flush := NewIO()
	defer flush()

	n := io.ScanInt()
	a := io.ScanInts(n)

	sort.Ints(a)

	max := a[len(a)-1]

	var count int
	divisibleMap := map[int]bool{}
	for i := 0; i < n; i++ {
		curNum := a[i]
		if divisibleMap[curNum] {
			continue
		}
		var divisible bool
		for j := i + 1; j < n; j++ {
			if curNum < a[j] {
				break
			}
			if curNum%a[j] == 0 {
				divisible = true
				break
			}
		}
		if !divisible {
			count++
		}
		num := curNum
		for num < max+1 {
			divisibleMap[num] = true
			num += curNum
		}
	}

	fmt.Println(count)
}


type IO struct {
	scanner *bufio.Scanner
	writer  *bufio.Writer
}

func NewIO() (*IO, func()) {
	io := &IO{
		scanner: newScanner(),
		writer:  newWriter(),
	}
	return io, func() { io.writer.Flush() }
}

func newScanner() *bufio.Scanner {
	s := bufio.NewScanner(os.Stdin)
	s.Buffer(make([]byte, 10000000), 10000000)
	s.Split(bufio.ScanWords)
	return s
}

func newWriter() *bufio.Writer {
	return bufio.NewWriter(os.Stdout)
}

func (io *IO) ScanBytes() []byte {
	if !io.scanner.Scan() {
		panic("scan string failed")
	}
	return io.scanner.Bytes()
}

func (io *IO) ScanString() string {
	if !io.scanner.Scan() {
		panic("scan string failed")
	}
	return io.scanner.Text()
}

func (io *IO) ScanStrings(n int) []string {
	strs := make([]string, n)
	for i := 0; i < n; i++ {
		strs[i] = io.ScanString()
	}
	return strs
}

func (io *IO) Scan2DStrings(y, x int) [][]string {
	strings := make([][]string, y)
	for i := 0; i < y; i++ {
		strings[i] = io.ScanStrings(x)
	}
	return strings
}

func (io *IO) Scan2DGraph(y int) [][]string {
	strs := make([][]string, y)
	for i := 0; i < y; i++ {
		strs[i] = strings.Split(io.ScanString(), "")
	}
	return strs
}

func (io *IO) ScanInt() int {
	return int(io.ScanInt64())
}

func (io *IO) ScanInt2() (int, int) {
	return int(io.ScanInt64()), int(io.ScanInt64())
}

func (io *IO) ScanInt3() (int, int, int) {
	return int(io.ScanInt64()), int(io.ScanInt64()), int(io.ScanInt64())
}

func (io *IO) ScanInt4() (int, int, int, int) {
	return int(io.ScanInt64()), int(io.ScanInt64()), int(io.ScanInt64()), int(io.ScanInt64())
}

func (io *IO) ScanInts(n int) []int {
	ints := make([]int, n)
	for i := 0; i < n; i++ {
		ints[i] = io.ScanInt()
	}
	return ints
}

func (io *IO) Scan2DInts(y, x int) [][]int {
	ints := make([][]int, y)
	for i := 0; i < y; i++ {
		ints[i] = io.ScanInts(x)
	}
	return ints
}

func (io *IO) ScanInt64() int64 {
	i, err := strconv.ParseInt(io.ScanString(), 10, 64)
	if err != nil {
		panic(err)
	}
	return i
}

func (io *IO) ScanFloat64() float64 {
	i, _ := strconv.ParseFloat(io.ScanString(), 64)
	return i
}

func (io *IO) ScanFloat64s(n int) []float64 {
	floats := make([]float64, n)
	for i := 0; i < n; i++ {
		floats[i] = io.ScanFloat64()
	}
	return floats
}

func (io *IO) Println(a ...interface{}) {
	fmt.Fprintln(io.writer, a...)
}


Measured memory_bytes: 55232
#include<bits/stdc++.h>
#define pb          push_back
#define endl        '\n'
#define pll         pair<int,int>
#define vll          vector<int>
#define all(a)      (a).begin(),(a).end()
#define x           first
#define y           second
#define hell        1000000007
#define lbnd        lower_bound
#define ubnd        upper_bound
#define bs          binary_search
#define gcd(a,b)    __gcd((a),(b))
#define lcm(a,b)    ((a)*(b)) / gcd((a),(b))
#define int	    int64_t
#define ios     ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
using namespace std;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count()); 
int n,i,j,k,l,sum=0,flag=0,ans=0,a[3001],v[101],m;
int dp[3005][3005][2];
int is[3005][3005][2];
int f(int i, int j,int turn){
	if(i>j)
		return 0;
	if(i==j)
		return (turn==1?a[i]:-a[i]);
	if(is[i][j][turn]!=-1)
		return dp[i][j][turn];
	is[i][j][turn]=1;
	if(turn){
		return dp[i][j][turn] = max(a[i]+f(i+1,j,turn^1), a[j]+f(i,j-1,turn^1));
	}else{
		return dp[i][j][turn] = min(-a[i]+f(i+1,j,turn^1), -a[j]+f(i,j-1,turn^1));
	}
}
void solve(){
	memset(is,-1,sizeof dp);
	cin>>n;
	for(int i=0;i<n;i++){
		cin>>a[i];
	}
	cout<<f(0,n-1,1)<<endl;
}
signed main()
{
    ios
    int test = 1;
    //cin>>test;
    while(test--){
    	solve();
    }
    return 0;
}

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

using namespace std;

typedef long long ll;

const int N = 100100;

vector<int> g[N];
vector<int> path;

int way[N], last[N], used[N];

void dfs(int v) {
    for (int u : g[v]) {
        if (way[u] == 0) {
            way[u] = v;
            last[v] = 1;
            dfs(u);
        }
    }
}

void go(int v) {
    used[v] = 1;
    if (v != 1) {
        path.push_back(v);
    }
    for (int u : g[v]) {
        if (!used[u]) {
            go(u);
            break;
        }
    }
}

int main() {
    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    int n, m;
    cin >> n >> m;
    for (int i = 0; i < m; ++i) {
        int a, b;
        cin >> a >> b;
        g[a].push_back(b);
        g[b].push_back(a);
    }
    way[1] = -1;
    dfs(1);
    for (int i = 1; i <= n; ++i) {
        if (!last[i]) {
            for (int j = i; j != -1; j = way[j]) {
                path.push_back(j);
                used[j] = 1;
            }
            go(1);
            break;
        }
    }
    cout << path.size() << '\n';
    for (int i : path) {
        cout << i << ' ';
    }
    return 0;
}

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

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

macro_rules! read_value {
    ($iter:expr, ( $($t:tt),* )) => {
        ( $(read_value!($iter, $t)),* )
    };
    ($iter:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($iter, $t)).collect::<Vec<_>>()
    };
    ($iter:expr, chars) => {
        read_value!($iter, String).chars().collect::<Vec<char>>()
    };
    ($iter:expr, usize1) => {
        read_value!($iter, usize) - 1
    };
    ($iter:expr, $t:ty) => {
        $iter.next().unwrap().parse::<$t>().expect("Parse error")
    };
}

use std::collections::VecDeque;

fn main() {
    input! {
        n: usize,
        x: usize1,
        y: usize1,
    }
    let mut res: Vec<usize> = vec![0;n];
    for i in 0..n {
        let mut q: VecDeque<usize> = VecDeque::new();
        let mut d = vec![std::usize::MAX;n];
        q.push_front(i);
        d[i] = 0;
        while !q.is_empty() {
            let u = q.pop_front().unwrap();
            let mut push = |v: usize| {
                if d[v] != std::usize::MAX { return; }
                d[v] = d[u] + 1;
                q.push_back(v);
            };
            if u > 0   { push(u-1); }
            if u < n-1 { push(u+1); }
            if u == x  { push(y); }
            if u == y  { push(x); }
        }
        for j in i..n {
            res[d[j]] += 1;
        }
    }
    for i in res.iter().skip(1) {
        println!("{}", i);
    }
}


Measured memory_bytes: 4352
#include <bits/stdc++.h>
using namespace std;
#define ll int64_t
#define ALL(a) (a).begin(), (a).end()

const ll mod = 1000000007;
const ll LINF = 1e13;
const ll LLINF = 1e18;
const ll ALPHABET = 26;

template <class T>
void Swap(T& r, T& l) {
  T tmp = r;
  r = l;
  l = tmp;
}

template <typename T>
istream& operator>>(istream& is, vector<T>& vec) {
  for (T& x : vec)
    is >> x;  // for(int i=0; i<vec.size(); i++) is >> x[i]; とかでもいい
  return is;
}

int main() {
  // ll a,b,c;
  // string s;
  // cin >> s;
  ll n;
  cin >> n;

  ll dig = 1;  //桁数
  ll tmp = n;
  for (ll i = 0; i < 10; i++) {
    if (tmp / 10 > 0) {
      dig++;
      tmp /= 10;
    }
  }

  ll ans = 0;

  ans = n;
  if (dig % 2 == 0) {
    n = pow(10, dig - 1) - 1;
    dig--;
    ans = n;
  }
  cerr << dig << endl;
  cerr << ans << endl;

  for (ll i = dig; i > 0; i--) {
    if (i % 2 == 0) {
      ans -= ((pow(10, i) - 1) - pow(10, i - 1) + 1);
    }
  }

  cout << ans;
}


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

char pt[8][8];

void put90(){
	for(int i=0; i<8; i++){
		for(int j=7; j>=0; j--)
			cout << pt[j][i];
		cout << endl;
	}
}

void put180(){
	for(int i=7; i>=0; i--){
		for(int j=7; j>=0; j--)
			cout << pt[i][j];
		cout << endl;
	}
}

void put270(){
	for(int i=7; i>=0; i--){
		for(int j=0; j<8; j++)
			cout << pt[j][i];
		cout << endl;
	}
}

int main(){
	for(int i=0; i<8; i++)
		for(int j=0; j<8; j++)
			cin >> pt[i][j];
	cout << 90 << endl;
	put90();
	cout << 180 << endl;
	put180();
	cout << 270 << endl;
	put270();
	return 0;
}

Measured memory_bytes: 0
found = dict()
def getsums(n):
  if n==0:return 1
  elif n<3:return 0
  elif n==3:return 1
  num = 0
  for x in range(3,n+1):
    if n-x in found:
      num+=found[n-x]
    else:
      g = getsums(n-x)
      found[n-x]=g
      num+=g
  return num

print(getsums(int(input()))%((10**9)+7))

Measured memory_bytes: 9440
#include <bits/stdc++.h>
#define ll long long
#define endl "\n"
using namespace std;

int main(){
	ios::sync_with_stdio(0);
	cin.tie(0);
	
	string s1, s2;
	cin >> s1 >> s2;
	int n1 = s1.size();
	int n2 = s2.size();
	int ans=n1;
	for(int i=0; i<=n1-n2; i++){
		int k = 0;
		for(int j=0; j<n2; j++){
			if(s1[i+j]!=s2[j]){
				k++;
			}
		}
		if(i==0){
			ans = k;
		}else{
			ans = min(ans, k);
		}
	}
	if(s1==s2){
		cout << 0;
	}else{
		cout << ans;
	}
	
}

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

typedef long long ll;

int main () {
	ll n; cin >> n; --n;
	ll mx = ll(1e15) + 1;
	ll now = 26;
	vector<ll> v;
	while (now < mx * 26) {
		v.push_back(now);
		now *= 26;
	}
	int len = 1;
	for (ll i: v) {
		if (n < i) {
			string ans = "";
			for (int j = 0; j < len; ++j) {
				ans.push_back(char('a' + n % 26));
				n /= 26;
			}
			reverse(ans.begin(), ans.end());
			cout << ans << endl;
			break;
		}
		else {
			n -= i;
			++len;
			continue;
		}
	}
}


Measured memory_bytes: 3592
/*
 * @Author: RBQRBQ
 * @Date: 2020-04-09 19:07:43
 * @LastEditors: RBQRBQ
 * @LastEditTime: 2020-04-09 19:51:50
 */
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<int> VI;
typedef pair<int,int> pii;
namespace IO{
    template<typename T>inline void read(T &x){
        x=0;ll f=1;char ch=getchar();
        while(!isdigit(ch)){if(ch=='-')f=-f;ch=getchar();}
        while(isdigit(ch)){x=x*10+ch-48;ch=getchar();}
        x=x*f;
    }
}
using namespace IO;
const int maxn=200;
ll K;
string s,p;
ll q(string s)
{
    int len=s.length();
    vector<ll> ans;
    ans.clear();
    int now=s[0];
    int res=1;
    for(int i=1;i<len;i++)
    {
        if(s[i]==now) res++;
        else
        {
            now=s[i];
            ans.push_back(res);
            res=1;
        }
    }
    ans.push_back(res);
    ll sum=0;
    for(auto p:ans)
    {
        sum+=(p/2);
    }
    return sum;
}
int main()
{
    cin>>s;
    read(K);
    p=s+s;
    bool ok=true;
    for(int i=0;i<s.length();i++)
    if(s[i]!=s[0]) ok=false;
    if(ok)
    {
        cout<<(K*s.length())/2;
        return 0;
    }
    ll sum1=q(s);
    ll sum2=q(p);
    ll pos=sum1*2-sum2;
    cout<<sum1*K-pos*(K-1);
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
#define LLINF 9223372036854775807
#define MOD ll(1e9+7)
#define all(x) (x).begin(),(x).end()
#define dbg(x) cerr<<#x<<": "<<x<<endl



int main(){
    ll x, y, z, k;
    cin >> x >> y >> z >> k;
    vector<ll> a(x), b(y), c(z);
    for(int i = 0; i < x; i++){
        cin >> a[i];
    }
    for(int i = 0; i < y; i++){
        cin >> b[i];
    }
    for(int i = 0; i < z; i++){
        cin >> c[i];
    }
    sort(all(a)); sort(all(b)); sort(all(c));
    reverse(all(a)); reverse(all(b)); reverse(all(c));
    vector<ll> ab(x*y);
    for(int i = 0; i < x; i++){
        for(int j = 0; j < y; j++){
            ab[y*i+j] = a[i]+b[j];
        }
    }
    sort(all(ab)); reverse(all(ab));
    vector<ll> ans;
    for(int i = 0; i < min((int)ab.size(),3005); i++){
        for(int j = 0; j < z; j++){
            ans.push_back(ab[i]+c[j]);
        }
    }

    sort(all(ans)); reverse(all(ans));
    for(int i = 0; i < k; i++){
        cout << ans[i] << endl;
    }

    return 0;
}


Measured memory_bytes: 42984
# coding: utf-8
# Your code here!
import sys
read = sys.stdin.read
readline = sys.stdin.readline

#n,k,*a = map(int,read().split())

n, = map(int,readline().split())
vw = [[0,0]]+[list(map(int,readline().split())) for _ in range(n)]

def merge(av,aw,bv,bw):
    la,lb = len(aw),len(bw)
    rv = [0]*(la+lb)
    rw = [0]*(la+lb)
    ia = ib = 0
    for i in range(la+lb):
        if ib==lb or (ia < la and aw[ia] < bw[ib]):
            rv[i] = av[ia]
            rw[i] = aw[ia]
            ia += 1
        else:
            rv[i] = bv[ib]
            rw[i] = bw[ib]
            ib += 1
    return rv,rw

A = 11
N = min(1<<A,n+1)
memov = [[] for _ in range(N)]
memow = [[] for _ in range(N)]

memov[0] = [0]
memow[0] = [0]

#from itertools import acumulate
for i in range(1,N):
    v,w = vw[i]
    m2v = [v+v1 for v1 in memov[i>>1]]
    m2w = [w+w1 for w1 in memow[i>>1]]
    memov[i],memow[i] = merge(memov[i>>1],memow[i>>1],m2v,m2w)

    #memov[i] = list(accumulate(memov[i],max))
    for j in range(1,len(memov[i])):
        memov[i][j] = max(memov[i][j-1],memov[i][j])
    
def solve(lstv,lstw,dv,dw,l):
    ans = 0
    idx = len(lstw)-1
    #print(lstv,lstw,dv,dw,l)
    for v,w in zip(dv,dw):
        while idx >= 0 and lstw[idx] + w > l:
            idx -= 1
        if idx >= 0 and v+lstv[idx] > ans:
            ans = v+lstv[idx]
    print(ans)        
 
 

q, = map(int,readline().split())
for _ in range(q):
    u,l = map(int,readline().split())

    dv = [0]
    dw = [0]
    while u >= N:
        v,w = vw[u]
        m2v = [v+v1 for v1 in dv]
        m2w = [w+w1 for w1 in dw]
        dv,dw = merge(dv,dw,m2v,m2w)
        u >>= 1
    
    #for j in range(1,len(dv)):
    #    dv[j] = max(dv[j-1],dv[j])
    
    solve(memov[u],memow[u],dv,dw,l)

#print(memov)
#print(memow)



Measured memory_bytes: 170780
def edmonds_karp(s, t, C):
    '''
    s, t: start, target (integer)
    C: Array of dict ([from][to] -> length)
    ret: maximum_flow (integer)
    '''
    import copy
    import collections

    r = copy.deepcopy(c)  # Residual network
    maxf = 0

    while True:
        q, found = collections.deque(), False
        q.append(([s], 10 ** 15))
        while len(q) > 0 and not found:
            p, minf = q.popleft()
            for to, flow in r[p[-1]].items():
                if flow == 0:
                    continue
                elif to == t:
                    p, minf = p + [to], min(flow, minf)
                    found = True
                    break
                elif not to in p:
                    q.append((p + [to], min(flow, minf)))

        if not found:
            break

        for i in range(len(p) - 1):
            r[p[i]][p[i + 1]] -= minf
            if p[i] in r[p[i + 1]]:
                r[p[i + 1]][p[i]] += minf
            else:
                r[p[i + 1]][p[i]] = minf
        maxf += minf

    return maxf


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

gain = sum([max(a, 0) for a in A])

# Flow network
S, T = 0, N + 1
c = [{} for i in range(N + 2)]
for i in range(N):
    ix = i + 1
    if A[i] <= 0:
        c[S][ix] = -A[i]
    else:
        c[ix][T] = A[i]

    for j in range(2 * ix, N + 1, ix):
        c[ix][j] = 10 ** 15

print(gain - edmonds_karp(S, T, c))


Measured memory_bytes: 3700
using System;
using System.Linq;

struct Pair {
  public int f, s;
  public Pair(int[] a) { f = a[0]; s = a[1]; }
}

class Program {
  static void Main() {
    var a = Enumerable.Range(1, 6)
      .Select(_ => new Pair(Console.ReadLine().Split().Select(int.Parse).OrderBy(x => x).ToArray()))
      .OrderBy(x => x.f).ThenBy(x => x.s).ToArray();
    bool b = a[0].Equals(a[1]) && a[2].Equals(a[3]) && a[4].Equals(a[5]);
    bool c = a[0].f == a[2].f && a[2].s == a[4].s && a[0].s == a[4].f;
    Console.WriteLine(b && c ? "yes" : "no");
  }
}


Measured memory_bytes: 18640
#include <bits/stdc++.h>
using namespace std;
int main(void){
    int N,max=0,min=10000000000;
    cin >> N;
    vector<int>vec(N);
    for(int i=0;i<N;i++){
        cin >> vec.at(i);
        if(vec.at(i)>max)max=vec.at(i);
        if(vec.at(i)<min)min=vec.at(i);
    }
    cout << max - min;
    
    return 0;
    
}


Measured memory_bytes: 256
"use strict";

const input = require("fs").readFileSync("/dev/stdin", "utf8").trim();

const inputs = input.split("\n").map(i => +i);

const round = (n) => {
  return Math.ceil(n / 10) * 10;
}

const diff = (n) => round(n) - n;

const exec = (inputs) => {
  const sorted = inputs.sort( (a, b) => diff(b) - diff(a) );
  let time = 0;
  let first = false;
  for (let i = 0; i < inputs.length; i++) {
    if (diff(sorted[i]) === 0) {
      time += sorted[i];
      continue;
    }
    if (!first) {
      time += sorted[i];
      first = true;
      continue;
    }
    time += round(sorted[i]);
  }
  return time;
}

console.log(exec(inputs));


Measured memory_bytes: 7372
#include <bits/stdc++.h>
#define REP(i,n,N) for(int i=n;i<N;i++)
#define p(S) cout<<(S)<<endl
#define ck(n,a,b) (a<=(n)&&(n)<b)
#define F first
#define S second
#define inf 300000000
typedef long long ll;
using namespace std;

int main(){
	int N,M;
	cin>>N>>M;
	pair<int,int> A[51],B[51];
	int a,b,c,d;
	REP(i,0,N) {
		cin>>a>>b;
		A[i]={a,b};
	}
	REP(j,0,M) {
		cin>>c>>d;
		B[j]={c,d};
	}
	REP(i,0,N){
		int mn=inf;
		int ans=0;
		REP(j,0,M){
			if(mn>abs(A[i].F-B[j].F)+abs(A[i].S-B[j].S)){
				mn=abs(A[i].F-B[j].F)+abs(A[i].S-B[j].S);
				ans=j+1;
			}
		}
		p(ans);

	}
	return 0;
}


Measured memory_bytes: 256
# import numpy as np

def cal_ans(x):
    ans = (x+1)/2
    return ans
n,k = map(int,input().split())
p = list(map(int,input().split()))
p = list(map(cal_ans,p))

ans_temp = 0
ans_list = []
S = [0]
for i in range(n):
    S.append(S[i]+p[i])
# print(p)
# print(S)
# for i in range(n-k+1):
#     ans_list.append(sum(p[i:i+k]))
t_len = len(S)
ans1 = 0
for i in range(t_len - k):
    if ans1 < S[i+k]-S[i]:
        ans1 = S[i+k]-S[i]
print(ans1)
# ans = 0
# for i in range(k):
#     ans += (ans_list[i]*(ans_list[i]+1)/2)/ans_list[i]
#     # print((ans_list[i]*(ans_list[i]+1)/2))
# print(ans)     

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

int a[200005];
int32_t main() {
 int n;
 cin >> n;
 for (int i = 0; i < n; i++) {
    cin >> a[i];
 }
 sort(a, a + n);
 reverse(a, a + n);
 int curr = a[0], ans = 0, sz = 1, i;
 queue<int> q;
 q.push(a[0]);
 for (i = 1; i < n; i++) {
    if (a[i] == curr) {
        q.push(a[i]);
        sz++;
        ans += a[i];
    }
    else {
        break;
    }
 }

 while(i < n) {
    int x = q.front();
    q.pop();
    ans += x;
    q.push(a[i]);
    q.push(a[i]);
    i++;
 }
 cout << ans;
 return 0;
}


Measured memory_bytes: 6804
#include <iostream>
#include <sstream>
#include <queue>
#include <map>
#include <set>
#include <vector>
#include <numeric>
#include <algorithm>
#include <string>
#include <complex>
 
#include <cassert>
#include <cstdlib>
#include <cmath>
#include <cstdio>
#include <cstring>
 
#define REP(i,e) for(int i=0;i<(int)(e);i++)
#define FOR(i,b,e) for(int i=(int)(b);i<(int)(e);i++)
#define ALL(c) (c).begin(), (c).end()
#define EACH(it,c) for(__typeof((c).begin()) it=(c).begin();it!=(c).end();++it)
#define RALL(c) (c).rbegin(), (c).rend()
#define ALLA(a,n) ((a)+0), ((a)+n)
 
using namespace std;
 
typedef long long ll;
typedef vector<int> vint;
typedef vector<long long> vll;
typedef vector<string> vstring;
typedef vector<double> vdouble;

template<class T>void pp(T v,int n){ REP(i,n)cout<<v[i]<<(i+1==n?'\n':' '); }
template<class T>void pp(T v){ EACH(it,v) cout<<(it==v.begin()?"":" ")<<*it; cout << endl;  }
template<class T>T& ls(T& a,T b){ if(b<a) a=b; return a; }
template<class T>T& gs(T& a,T b){ if(b>a) a=b; return a; }
inline ll to_i(const string& s){ll n;sscanf(s.c_str(),"%lld",&n);return n;}
inline string to_s(ll n){char buf[32];sprintf(buf,"%lld",n);return string(buf);}

inline void write_bool(bool b, const string &tval, const string &fval) {
  cout << (b ? tval : fval) << endl;
} 
inline void YESNO(bool b) { return write_bool(b, "YES", "NO"); }
inline void YesNo(bool b) { return write_bool(b, "Yes", "No"); }
inline void yesno(bool b) { return write_bool(b, "yes", "no"); }

ll gcd(ll a, ll b) { return b?gcd(b,a%b):a; }
ll lcm(ll a, ll b) { return a/gcd(a,b)*b; }

int main() {
  int n; string s;
  while (cin >> n >> s) {
    if (n < 3200) cout << "red" << endl;
    else cout << s << endl;
  }
}


Measured memory_bytes: 888
#include<bits/stdc++.h>
#pragma GCC optimize("O3")
using namespace std;
int n, k;
int v[102];
int dp[100002];
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cin >> n >> k;
    for(int i = 1; i <= n; ++i)
        cin >> v[i];
    // 2 = losing state, 1 = winning state
    for(int i = 0; i < k; ++i)
    {
        if(dp[i] == 0)
            dp[i] = 2;
        for(int j = 1; j <= n; ++j)
        {
            if(i + v[j] > k || dp[i + v[j]] == 1)
                continue;
            dp[i + v[j]] = 3 - dp[i];
        }
    }
    if(dp[k] == 1)
        cout << "First";
    else
        cout << "Second";
    return 0;
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
#define ll long long int
#define ld long double
#define f first
#define s second
#define pb push_back
#define eb emplace_back
#define mk make_pair
#define mt make_tuple
#define MOD 1000000007
#define fo(i,a,b) for(i=a;i<b;i++)
#define foe(i,a,b) for(i=a;i<=b;i++)
#define all(x) x.begin(), x.end()
#define vi vector<int>
#define vl vector <long long int>
#define pii pair <int,int>
#define pll pair <long long int, long long int>
#define vpii vector< pair<int,int> >
#define vpll vector < pair <long long int,long long int> >
#define boost ios::sync_with_stdio(false); cin.tie(0)
using namespace std;
const int inf = 1e9 + 5;
const ll inf64 = 1e18 + 5;

int main()
{
	boost;
	int x;
	cin >> x;
	cout << !x;
}


Measured memory_bytes: 3648
#include<stdio.h>
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<string.h>
#include<math.h>
#include<utility>
#include<map>
using namespace std;
typedef long long int ll;
typedef long double ld;
typedef vector<ll> vi;
typedef vector<string> vs;
typedef pair<ll,ll> P;
typedef vector<P> vp;
#define REP(i,n) for(int i=0;i<n;i++)
#define FOR(i,m,n) for(int i=m;i<n;i++)
#define REPR(i,n) for(int i=n-1;i>=0;i--)
#define FORR(i,n,m) for(int i=n-1;i>=m;i--)
#define all(in) in.begin(),in.end()
#define ALL(in,K) in,in+K
#define INF 1e18
#define MOD 100000007
#define SIZE 100005
#define PI 	3.14159265358979323846

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n;
    cin >> n;
    static ll a[20000] = {0};
    REP(i,n){
        int input;
        cin >> input;
        a[input]++;
    }
    int roop = n;
    REP(i,20000){
        REP(j,a[i]){
            roop--;
            cout << i;
            if(roop)cout << " ";
        }
    }
    cout << endl;
    return 0;
}


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

#define _GLIBCXX_DEBUG

//vector<int> A(M), B(M);
//vector<vector<char>> answer(N, vector<char>(N, '-'));

int main() {
  int a;
  int ans;
  
  cin >> a;
  
  ans = a + a * a + a * a * a;
  
  cout << ans << endl;
  return 0;
}

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

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

  int man = -1, go = -1, sen = -1;
  for(int i = 0;i <= n;i++){
    for(int j = 0;j <= n - i;j++){
      int k = n - i - j;
      if(y == 10000*i + 5000*j + 1000*k){
        man = i;
        go = j;
        sen = k;
      }
    }
  }
  cout << man << " " << go << " " << sen << endl;
}


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

int main(){
  int  N;
  cin >> N;
  vector<long> A(N), B(N);
  for (int i = 0;i < N; i++){
    cin >> A[i];
  }
  for (int i = 0;i < N-1; i++){
    if (A[i] < A[i+1]){
      B[i] = 1;  
    }
    if (A[i] > A[i+1]){
      B[i] = -1;
    }
  }
  B[N-1] = -1;
  long money = 1000, stock = 0;
  for (int i = 0; i < N; i++){
    if (B[i] == -1){
      money += stock*A[i];
      stock = 0;
    }
    else if (B[i] == 1){
      stock += money / A[i];
      money = money % A[i];
    }
  }
  cout << money << endl;
}

Measured memory_bytes: 3608
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cfloat>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <memory>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <sstream>
#include <complex>
#include <stack>
#include <queue>
#include <cstring>
#include <sstream>
#include <cassert>
#include <list>
#include <ctime>
#include <numeric>
#include <fstream>
using namespace std;
static const double EPS = 1e-6;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> PI;
#define rep(i,n) for(int i=0;i<(int)(n);++i)
#define FOR(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)
#define ALL(c) (c).begin(), (c).end()
#define mp(a,b) make_pair(a,b)
#define pb(a) push_back(a)
#define SZ(a) (int(a.size()))
#define F first
#define S second
const long double pi=acos(-1.0);
int dx[]={0,1,0,-1,1,1,-1,-1,0},dy[]={1,0,-1,0,1,-1,1,-1,0};


const int N=110;

void mult(int A[N*N],int B[N*N],int O[N*N]){
  fill(O,O+N*N,0);
  rep(r,N)rep(c,N)rep(k,N)
    O[r*N+c]|=A[r*N+k]*B[k*N+c];
}

void expt(int M[N*N],ll n,int O[N*N]){
  if(n==1){
    copy(M,M+N*N,O);
  }else if(n%2){
    int T[N*N];
    expt(M,n-1,T);
    mult(M,T,O);
  }else{
    int T[N*N];
    expt(M,n/2,T);
    mult(T,T,O);
  }
}

ll n,m,z;

void solve(){
  int mat[N*N];
  memset(mat,0,sizeof(mat));

  vector<PI> ed;
  ed.pb(mp(n,0));
  ed.pb(mp(n-1,n+1));
  rep(i,m){
    int a,b;
    cin>>a>>b;
    --a,--b;
    ed.pb(mp(a,b));
    ed.pb(mp(b,a));
  }

  rep(i,SZ(ed))rep(j,SZ(ed))
    if(ed[i].S==ed[j].F && ed[i].F!=ed[j].S)
      mat[i*N+j]=1;

  int O[N*N];
  expt(mat,z+1,O);

  cout<<(O[1]?"yes":"no")<<endl;
}

main(){
  while(cin>>n>>m>>z,n)
    solve();
}

Measured memory_bytes: 0
#define _USE_MATH_DEFINES
#include<iostream>
#include<string>
#include<vector>
#include <algorithm>
#include<deque>
#include<queue>
#include<set>
#include <functional>
#include <cmath>


//マクロ
/*動かない・・・
#define _overload3(_1,_2,_3,name,...) name
#define _rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(int i=int(a);i<int(b);++i)
#define REP(...) _overload3(__VA_ARGS__,repi,_rep,)(__VA_ARGS__)
#define _roverload3(_1,_2,_3,name,...) name
#define _rrep(i,n) repi(i,0,n)
#define rrepi(i,a,b) for(int i=int(a);i<int(b);++i)
#define RREP(...) _roverload3(__VA_ARGS__,rrepi,_rrep,)(__VA_ARGS__)
//*/
#define REP(i,n) for(int i=0; i<(int)(n); ++i)
#define REPS(i,n) for(int i=1; i<=(int)(n); ++i)
#define RREP(i,n) for(int i=(int)(n)-1; i>=0; --i)
#define RREPS(i,n) for(int i=(int)(n); i>0; --i)
#define FOR(i,s,e) for(int i=(int)(s); i<(int)(e); ++i)
#define RFOR(i,s,e) for(int i=(int)(e)-1; i>=(int)(s); --i)
//*/
#define All(a) (a).begin(),(a).end()
#define dump(x)  cerr << #x << " = " << (x) << endl;

//定数
#define INF 1e9
#define MOD (int)(1e9+7)

typedef long long ll;
typedef unsigned long long ull;
/*
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<string> vs;
typedef pair<int, int> pii;
//*/
using namespace std;

//とりあえず書いておく変数
int dx[4] = { 1,0,-1,0 };
int dy[4] = { 0,1,0,-1 };

//今回の変数

//使用する関数
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()
{
	ios::sync_with_stdio(false);
	cin.tie(0);

	int n;
	string s;
	cin >>n>> s;
	if (n % 2 == 1) {
		cout << "No" << endl;
		return 0;
	}
	REP(i, n/2) {
		if (s[i] != s[i + n / 2]) {
			cout << "No" << endl;
			return 0;
		}
	}
	cout << "Yes" << endl;
}

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

typedef long long ll;
typedef pair<int,int> ii;
#define fore(i,a,b) for(int i=a,ggdem=b;i<ggdem;i++)
#define FIN ios::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#define pb push_back
#define fst first
#define snd second
#define ALL(a) a.begin(),a.end()
#define SZ(a) ((int)(a).size())

int main() {FIN;
    string s;
    cin>>s;
    ll b=0,res=0;
    for(char c:s) {
        if(c=='W')res+=b;
        else if (c=='B')b++;
    }
    cout<<res<<endl;
}

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

using ll = long long;
using ld = long double;
using pii = pair<int, int>;
using pll = pair<ll, ll>;

#define REP(i, n) for (int i = 0, i##_len = (n); i < i##_len; ++i)
#define all(x) (x).begin(), (x).end()
#define m0(x) memset(x, 0, sizeof(x))

int dx4[4] = {1, 0, -1, 0}, dy4[4] = {0, 1, 0, -1};

int conv(string s, int i)
{
    return s[i] - 'A';
}

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

    vector<string> s(n + 1);
    for (int i = 0; i < n; i++)
    {
        cin >> s[i];
    }
    s[n] = s[n - 1];
    vector<int> ans(n);
    bool ok = true;
    for (int i = 0; i < n; i++)
    {
        int now0 = conv(s[i], 0);
        int now1 = conv(s[i], 1);
        int next0 = conv(s[i + 1], 0);
        int next1 = conv(s[i + 1], 1);

        if (a[now0] <= 0 && a[now1] <= 0)
        {
            ok = false;
            break;
        }
        if (a[now0] == 0)
        {
            ans[i] = now0;
            a[now0]++;
            a[now1]--;
        }
        else if (a[now1] == 0)
        {
            ans[i] = now1;
            a[now1]++;
            a[now0]--;
        }
        else //docchi demo ok
        {

            if (now0 == 0 && next0 == 0) // both has A
            {
                ans[i] = now0;
                a[now0]++;
                a[now1]--;
            }
            else if (now1 == 2 && next1 == 2) // both has C
            {
                ans[i] = now1;
                a[now1]++;
                a[now0]--;
            }
            else // both has B
            {
                if (now0 == 1)
                {
                    ans[i] = now0;
                    a[now0]++;
                    a[now1]--;
                }
                else
                {
                    ans[i] = now1;
                    a[now1]++;
                    a[now0]--;
                }
            }
        }
    }

    if (ok)
    {
        cout << "Yes" << endl;
        for (int i = 0; i < n; i++)
        {
            cout << (char)(ans[i] + 'A') << endl;
        }
    }
    else
    {
        cout << "No" << endl;
    }

    return 0;
}

Measured memory_bytes: 6672
#include <iostream>
#include <sstream>
#include <fstream>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <algorithm>
#include <numeric>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <climits>
#include <cmath>
using namespace std;

#define REP(i,n) for(int i=0;i<(int)n;++i)
#define FOR(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)
#define ALL(c) (c).begin(), (c).end()

struct UnionFind {
  vector<int> data;
  UnionFind(int size) : data(size, -1) { }
  bool unionSet(int x, int y) {
    x = root(x); y = root(y);
    if (x != y) {
      if (data[y] < data[x]) swap(x, y);
      data[x] += data[y]; data[y] = x;
    }
    return x != y;
  }
  bool findSet(int x, int y) {
    return root(x) == root(y);
  }
  int root(int x) {
    return data[x] < 0 ? x : data[x] = root(data[x]);
  }
  int size(int x) {
    return -data[root(x)];
  }
};

typedef double Weight;
struct Edge {
  int src, dst;
  Weight weight;
  Edge(int src, int dst, Weight weight) :
    src(src), dst(dst), weight(weight) { }
};
bool operator < (const Edge &e, const Edge &f) {
  return e.weight != f.weight ? e.weight > f.weight : // !!INVERSE!!
    e.src != f.src ? e.src < f.src : e.dst < f.dst;
}
typedef vector<Edge> Edges;
typedef vector<Edges> Graph;

typedef vector<Weight> Array;
typedef vector<Array> Matrix;

pair<Weight, Edges> minimumSpanningForest(const Graph &g) {
  int n = g.size();
  UnionFind uf(n);
  priority_queue<Edge> Q;
  REP(u, n) FOR(e, g[u]) if (u < e->dst) Q.push(*e);

  Weight total = 0;
  Edges F;
  while ((int)F.size() < n-1 && !Q.empty()) {
    Edge e = Q.top(); Q.pop();
    if (uf.unionSet(e.src, e.dst)) {
      F.push_back(e);
      total += e.weight;
    }
  }
  return pair<Weight, Edges>(total, F);
}

const int size = 101;
double X[size];
double Y[size];
double Z[size];
double R[size];

double square( double r ) {
    return r*r;
}

double getDist( int a, int b ) {
    return sqrt( square( X[a]-X[b] ) + square( Y[a]-Y[b] ) + square( Z[a]-Z[b] ) );
}

int main() {
    int n;
    while ( cin >> n && n ) {
        for ( int i = 0; i < n; i++ ) {
            cin >> X[i] >> Y[i] >> Z[i] >> R[i];
        }
        Graph g(n);
        for ( int i = 0; i < n; i++ ) {
            for ( int j = 0; j < n; j++ ) {
                double d = getDist(i,j);
                if ( d <= R[i] + R[j] ) {
                    g[i].push_back( Edge( i, j, 0 ) );
                } else {
                    g[i].push_back( Edge( i, j, d-R[i]-R[j] ) );
                }
            }
        }
        printf( "%.3f\n", minimumSpanningForest(g).first );
    }
    return 0;
}

Measured memory_bytes: 0
import sys
sys.setrecursionlimit(20000000)

def distn(node,distance):
    for next_node,edge_size in G[node]:
        if ans[next_node] == -1:
            ans[next_node] = ((distance+edge_size)%2)
            distn(next_node,distance+edge_size)

n=int(input())
G=[[] for i in range(n)]
for i in range(n-1):
    u,v,w = map(int,input().split())
    G[u-1].append([v-1,w])
    G[v-1].append([u-1,w])

ans=[-1]*n
distn(0,0)
print(*ans,sep="\n")

Measured memory_bytes: 87204
def change_n_shinsu(x, n):
    ans = ''
    while True:
        shou = x // n
        amari = x % n
        if shou == 0 and amari == 0:
            break
        ans = str(amari) + ans
        x = shou
    ans = ans.zfill(60)
    return ans

n = int(input())
a = list(map(int, input().split()))
mod = 10**9+7

zero = [0 for i in range(60)]
one = [0 for i in range(60)]

for i in range(n):
    ai = change_n_shinsu(a[i], 2)
    for j in range(60):
        if ai[j] == '0':
            zero[j] += 1
        else:
            one[j] += 1

zero = zero[::-1]
one = one[::-1]

ans = 0
for i in range(60):
    kumi = (zero[i] * one[i]) % mod
    num = pow(2, i, mod)
    ans += (kumi * num) % mod
    ans %= mod
print(ans)

Measured memory_bytes: 123184
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using ull = unsigned long long;
using V = vector<int>;
using VV = vector<V>;
using VVV = vector<VV>;
using VL = vector<ll>;
using VVL = vector<VL>;
using VVVL = vector<VVL>;
template<class T> using VE = vector<T>;
template<class T> using P = pair<T, T>;
#define rep(i,n) for(int i=0;i<(n);i++)
#define rep1(i,n) for(int i=1;i<=(n);i++)
#define REP(i,k,n) for(int i=(k);i<(n);i++)
#define all(a) (a).begin(),(a).end()
#define output(x,y) cout << fixed << setprecision(y) << x << endl;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }
ll lcm(ll a, ll b) { return a / gcd(a, b) * b; }
const ll MOD = 1e9 + 7;
// const ll MOD = 998244353;
ll upper = MOD + MOD;
ll under = -upper;
ll UPPER = MOD * MOD;
ll UNDER = -UPPER;
const long double pi = 3.141592653589793;
ll ABS(ll x) {
	return x > 0 ? x : -x;
}
int main() {
	ll x, k, d;
	cin >> x >> k >> d;
	x = ABS(x);
	ll rem = x % d;
	ll mo = (x - rem) / d;
	if (mo <= k) {
		k -= mo;
		if (k % 2 == 1) cout << abs(rem - d) << endl;
		else cout << rem << endl;
	}
	else {
		cout << ABS(x) - (k * d) << endl;
	}
	/*
	int n, k;
	cin >> n >> k;
	V a(n), p(n);
	rep(i, n) {
		cin >> a[i];
		a[i]--;
	}
	rep(i, n) {
		cin >> p[i];
	}
	ll ans = UNDER;
	rep(i, n) {
		V cnt(n, 0);
		int pos = i;
		int len = 0;
		int P;
		while (1) {
			cnt[pos]++;
			if (cnt[pos] == 2) {
				P = pos;
				break;
			}
			pos = a[pos];
			len++;
		}
		int Len = 0;
		pos = i;
		rep(i, n) {

		}
	}
	*/
	return 0;
}

Measured memory_bytes: 3608
#include <bits/stdc++.h>
#define all(x) begin(x), end(x)
#define _ << ' ' <<
using namespace std;
using ll = long long;

ll df(ll a, ll b)
{
    if (b < 0) a = -a, b = -b;
    return a / b - (a % b < 0);
}

ll dc(ll a, ll b)
{
    if (b < 0) a = -a, b = -b;
    return a / b + (a % b > 0);
}

int main()
{
    ll w, h;
    cin >> w >> h;
    ll sol = 2e9;
    ll s1 = (w / 3) * h;
    ll s2 = df(w - w / 3, 2) * h;
    ll s3 = dc(w - w / 3, 2) * h;
    ll mx = max(max(s1, s2), s3);
    ll mi = min(min(s1, s2), s3);
    sol = min(sol, mx - mi);
    s1 = (h / 3) * w;
    s2 = df(h - h / 3, 2) * w;
    s3 = dc(h - h / 3, 2) * w;
    mx = max(max(s1, s2), s3);
    mi = min(min(s1, s2), s3);
    sol = min(sol, mx - mi);
    for (ll i = 1; i < h; ++i)
    {
        ll s1 = i * w;
        ll s2 = df(w, 2) * (h - i);
        ll s3 = dc(w, 2) * (h - i);
        ll mx = max(max(s1, s2), s3);
        ll mi = min(min(s1, s2), s3);
        sol = min(sol, mx - mi);
    }
    for (ll i = 1; i < w; ++i)
    {
        ll s1 = i * h;
        ll s2 = df(h, 2) * (w - i);
        ll s3 = dc(h, 2) * (w - i);
        ll mx = max(max(s1, s2), s3);
        ll mi = min(min(s1, s2), s3);
        sol = min(sol, mx - mi);
    }
    cout << sol;
}


Measured memory_bytes: 256
#include <stdio.h>

int main(void)
{
	int a[3],tmp,i;
	char x,y;
	
	a[0] = 1;
	a[1] = 0;
	a[2] = 0;
	
	while(scanf("%c,%c",&x,&y) != EOF){
		tmp = a[x - 'A'];
		a[x - 'A'] = a[y - 'A'];
		a[y - 'A'] = tmp;
	
		getchar();
	}
	for(i = 0;i < 3;i++){
		if(a[i] == 1){
			printf("%c\n",i + 'A');
		}
	}
	return 0;
}

Measured memory_bytes: 548
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cctype>
#include <chrono>
#include <cmath>
#include <complex>
#include <cstring>
#include <deque>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string>
#include <tuple>
#include <utility>
#include <vector>

using namespace std;

using int64 = long long;

#define all(_) begin(_), end(_)
#define rall(_) rbegin(_), rend(_)

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

  string s; cin >> s;
  int sum = 0;
  for (char c : s) sum += c ^ 48;
  cout << (sum % 9 == 0 ? "Yes" : "No") << endl;

  return 0;
}


Measured memory_bytes: 3748
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc=new Scanner(System.in);
		int i=sc.nextInt();
		int x,y,z;
		z=i/3600%60;
		y=(i-3600*z)/60%60;
		x=(i-3600*z)-(60*y);
			System.out.println(z +":"+ y +":"+ x);
	}

}

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

int main(void){
    int n = 0, m = 0;
    char s[101][11];
    char t[101][11]; 
    int x = 0;

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

    //赤と青に書かれている文字列の数を数える
    for(int i = 0; i < n; i++){
        int blue = 0;
        int red = 0;
        for(int j = 0; j < n; j++){
            if(strcmp(s[i], s[j]) == 0){
                blue++;
            }
        }
        for(int k = 0; k < m; k++){
            if(strcmp(s[i], t[k]) == 0){
                red++;
            }            
        }
        if(x < blue - red){
            x = blue - red;
        }
    }
    printf("%d\n", x);

    return 0;

} 


Measured memory_bytes: 256
import itertools
N,K = map(int,input().split())
h =2*K
d = [input().split() for l in range(h)]
z=[]
t=[]
for a in range(h+1):
  if a%2==1:
    z.append(d[a])
s=list(itertools.chain.from_iterable(z))
o=set(s)

print(N-len(o))

Measured memory_bytes: 9512
#include <bits/stdc++.h>
using namespace std;
typedef unsigned long long lli;
 
int main() {
	lli n, t, p, p1, p2, q=0, c;
    cin >> n;
    lli a[100000]={0};
    vector<lli> v;
    for(lli i=0; i<n; i++)
    {
      cin >> p;
      v.push_back(p);
      a[p-1]++;
      q=q+p;
    }
    cin >> t;
    for(lli i=0; i<t; i++)
    {
      cin >> p1 >> p2;
      c=a[p1-1];
      a[p1-1]=a[p1-1]-c;
      a[p2-1]=a[p2-1]+c;
      q=(q-(c*p1))+(c*p2);
      cout << q << endl;
    }
  return 0;
}

Measured memory_bytes: 5064
#include <bits/stdc++.h>
using namespace std;
string s;
int main() {
	while(cin >> s, s != "0000") {
		if(s[0] == s[1] && s[1] == s[2] && s[2] == s[3]) {
			cout << "NA" << endl;
			continue;
		}
		for(int i = 0; ; i++) {
			if(s == "6174") {
				cout << i << endl;
				break;
			}
			sort(s.begin(), s.end());
			string t = s;
			reverse(t.begin(), t.end());
			//cout << s << ' ' << t << endl;
			s = to_string(abs(stoi(s) - stoi(t)));
			while(s.size() < 4) s = "0" + s;
		}
	}
}

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

int main(void){
    int n;
    string str;
    cin >> n >> str;
    int ans = 0;
    for(int i=1; i<n; i++){
        string s = str.substr(0,i);
        string t = str.substr(i,n-i);
        int count = 0;
        for(int j=0; j<26; j++){
            if((int)s.find('a'+j) >= 0 && (int)t.find('a'+j) >= 0){
                count++;
            }
        }
        if(count > ans){
            ans = count;
        }
    }

    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
import java.util.*;
import java.io.*;

class Main {

    static final int ICHIRO = 0;
    static final int JIRO = 1;
    
    public static void main(String[] args) {

	Scanner stdin = new Scanner(System.in);

	while ( true ) {
	    int n = stdin.nextInt();

	    if ( n == 0 ) {
		break;
	    }

	    int[] ar = new int[n];
	    for ( int i = 0; i < n; i++ ) {
		ar[i] = stdin.nextInt();
	    }

	    int turn = 0;
	    int jiro_i = 0;
	    int rest = 32;
	    while ( rest > 0 ) {
		if ( turn == ICHIRO ) {
		    final int get = (rest - 1) % 5;
		    rest = Math.max(0, rest - get);		    
		} else {
		    final int get = ar[jiro_i];
		    rest = Math.max(0, rest - get);
		    jiro_i = (jiro_i + 1) % n;		    
		}
		System.out.println(rest);
		turn = ( turn + 1 ) % 2;
	    }	    
	}
	
    }
    
}

Measured memory_bytes: 20996
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;


namespace ACprac
{
    class Program
    {
        static void Main(string[] args)
        {
            string b = Console.ReadLine();
            switch(b)
            {
                case "A":
                    Console.WriteLine("T");
                    break;
                case "C":
                    Console.WriteLine("G");
                    break;
                case "G":
                    Console.WriteLine("C");
                    break;
                case "T":
                    Console.WriteLine("A");
                    break;
                default:
                    Console.WriteLine("");
                    break;
            }

        }
    }
}


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

/* 大文字を小文字に変換 */
char tolower(char c) {return (c + 0x20);}
/* 小文字を大文字に変換 */
char toupr(char c) {return (c - 0x20);}

// if('A'<=s[i] && s[i]<='Z') s[i] += 'a'-'A';

/*
string s = "abcdefg"
s.substr(4) "efg"
s.substr(0,3) "abc"
s.substr(2,4) "cdef"

// イテレータ要素のインデックス
distance(A.begin(), itr);
*/

int main()
{
    string s, t; cin >> s >> t;
    int ss = s.size();
    int ts = t.size();

    ll ans = 0;
    rep(i,ss-ts+1){
        ll cnt = 0;
        rep(j,ts){
            if(s[i+j] == t[j]) cnt++;
        }
        ans = max(cnt, ans);
    }
    cout << ts-ans << endl;
}

Measured memory_bytes: 3656
#include <cstdio>
#include <cctype>
#include <cstring>
#include <iostream>
#include <algorithm>
using namespace std;

#define ll long long
#define reg register
#define rep(i, a, b) for (reg ll i = (a), i##end = (b); i <= i##end; ++i)
#define dep(i, a, b) for (reg ll i = (a), i##end = (b); i >= i##end; --i)

template <typename _typer>
inline _typer read() {
	_typer init = 0;
	char ch = getchar(), k = 0;
	for ( ; !isdigit(ch); ch = getchar()) k = (ch == '-');
	for ( ; isdigit(ch); ch = getchar()) init = (init << 3) + (init << 1) + (ch ^ 48);
	return k ? -init : init;
}
const ll N = 0, INF = 1e9;

ll a, b, c, d;

ll Work(ll n, ll x, ll y) {
	return n - (n / x + n / y - n / (x * y / __gcd(x, y)));
}

int main() {
	a = read<ll>(), b = read<ll>(), c = read<int>(), d = read<int>();
	cout << Work(b, c, d) - Work(a - 1, c, d) << endl;
	return 0;
}



Measured memory_bytes: 256