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

signed main() {
  ios::sync_with_stdio(false);
  int N;
  cin >> N;
  vector<int> A(N);
  for (int i = 0; i < N; ++i) {
    cin >> A[i];
  }
  int x = *max_element(A.begin(), A.end());
  A.erase(find(A.begin(), A.end(), x));
  int y = A[0];
  for (int i = 0; i < A.size(); ++i) {
    if (abs(x - 2 * A[i]) < abs(x - 2 * y)) {
      y = A[i];
    }
  }
  cout << x << ' ' << y << endl;
  return 0;
}


Measured memory_bytes: 640
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<cmath>
using namespace std;
typedef long long ll;
const int INF=1000000000;
const int MOD=1000000007;

int main()
{
 int n, a, m=INF, c=0;
 cin >> n;
 for(int i=0;i<n;i++){
   cin >> a;
   m=min(m,a);
   if(a<=m) c++;
 }
 cout << c;
 return 0;
}

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

public class Program
{
    static void Main()
    {
        int n = int.Parse(Console.ReadLine());
        int[] d = Array.ConvertAll(Console.ReadLine().Split(' '), int.Parse);
        Array.Sort(d);
        int ans = d[n / 2] - d[n/ 2 - 1];
        Console.WriteLine(ans);
    }
}

Measured memory_bytes: 16864
#include<bits/stdc++.h>
using namespace std;
int main(){
  string s;
  cin>>s;
  string sf=s;
  reverse(sf.begin(), sf.end());
  string t="";
  for(int i=0;i<(s.size()-1)/2;i++)
    t+=s.at(i);
  string tf=t;
  reverse(tf.begin(), tf.end());
  cout<<(s==sf&&t==tf?"Yes":"No")<<endl;
}

Measured memory_bytes: 256
#include<algorithm>
#include<iostream>
#include<cmath>
using namespace std;
int n,m,a,b,v[55],e[55][55],nb;
void dfs(int r,int k1,int k2)
{
	v[r]=1;
	for(int i=1;i<=n;i++)
	{
		if(e[r][i]&&v[i]==0)
		{
			if(!((r==k1&&i==k2)||(r==k2&&i==k1)))dfs(i,k1,k2);
		}
	}
}
int main()
{
	cin>>n>>m;
	pair<int,int>k[55];
	for(int i=1;i<=m;i++)
	{
		cin>>a>>b;
		e[a][b]=1;
		e[b][a]=1;
		k[i]=make_pair(a,b);
	}
	for(int i=1;i<=m;i++)
	{
		for(int j=0;j<55;j++)v[j]=0;
		dfs(1,k[i].first,k[i].second);
		int sv=0;
		for(int j=0;j<55;j++)sv+=v[j];
		if(sv!=n)nb++;
	}
	cout<<nb<<endl;
}

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

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

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

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

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

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

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

    ($iter:expr, $t:ty) => {
        $iter.next().unwrap().parse::<$t>().expect("Parse error")
    };
}
fn main() {
    input!{
        n: usize,
        a: [usize; n],
    };
    let mut tmp: usize = 1;
    for i in 0..100000{
        tmp = a[tmp-1];
        if tmp == 2{
            println!("{}", i +1);
            return;
        }
    }
    println!(
        "{}",
        -1
    );
}


Measured memory_bytes: 6396
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int N;
  cin >> N;
  vector <int> point(N);
  for (int i=0; i<N; i++){
    cin >> point.at(i);
  }
  sort(point.begin(),point.end());
  int Alice=0, Bob=0;
  for(int i=N-1; i>-1; i-=2){
    Alice += point.at(i);
  }
  for(int i=N-2; i>-1; i-=2){
    Bob += point.at(i);
  }
  cout << Alice - Bob << endl;
}

Measured memory_bytes: 256
#!/usr/bin/env python
# -*- coding: utf-8 -*-

from sys import stdin

A = int(stdin.readline().rstrip())
B = int(stdin.readline().rstrip())
C = int(stdin.readline().rstrip())
X = int(stdin.readline().rstrip())

total = 0
cnt = 0

for i in range(A+1):
    for j in range(B+1):
        for k in range(C+1):
            if i*500 + j*100 + k*50 == X:
                cnt += 1


print(cnt)


Measured memory_bytes: 3060
from sys import stdin
readline = stdin.readline
def i_input(): return int(readline().rstrip())
def i_map(): return map(int, readline().rstrip().split())
def i_list(): return list(i_map())

class UnionFind:
    def __init__(self, n):
        self.parents = [-1] * (n + 1)
        self.rank = [0] * (n + 1)

    def root(self, x):
        if(self.parents[x] < 0):
            return x
        else:
            self.parents[x] = self.root(self.parents[x])
            return self.parents[x]

    def unite(self, x, y) -> bool:
        x = self.root(x)
        y = self.root(y)
        if x == y:
            return False
        if self.rank[x] > self.rank[y]:
            self.parents[x] += self.parents[y]
            self.parents[y] = x
        else:
            self.parents[y] += self.parents[x]
            self.parents[x] = y
            if self.rank[x] == self.rank[y]:
                self.rank[y] += 1
        return True

    def members(self, x):
        root = self.root(x)
        return [i for i in range(self.n) if self.root(i) == root]

    def roots(self):
        return [i for i, x in enumerate(self.parents) if x < 0]

    def is_same(self, x, y) -> bool:
        return self.root(x) == self.root(y)

    def size(self, x):
        return -self.parents[self.root(x)]

    def all_group_members(self):
        return {r: self.members(r) for r in self.roots()}

def main():
    N, Q = i_map()
    U = UnionFind(N)
    for _ in range(Q):
        t, u, v = i_map()
        if t == 1:
            print(1 if U.is_same(u, v) else 0)
        else:
            U.unite(u, v)

if __name__ == "__main__":
    main()


Measured memory_bytes: 13624
#![allow(unused_imports, unused_variables, dead_code)]
use std::io::{stdin, Read, StdinLock};
use std::str::FromStr;
use std::fmt::*;
use std::str::*;
use std::cmp::*;
use std::collections::*;

struct Scanner<'a> {
    cin: StdinLock<'a>,
}
impl<'a> Scanner<'a> {
    fn new(cin: StdinLock<'a>) -> Scanner<'a> {
        Scanner { cin: cin }
    }
 
    fn read1<T: FromStr>(&mut self) -> Option<T> {
        let token = self.cin.by_ref().bytes().map(|c| c.unwrap() as char)
            .skip_while(|c| c.is_whitespace())
            .take_while(|c| !c.is_whitespace())
            .collect::<String>();
        token.parse::<T>().ok()
    }
 
    fn read<T: FromStr>(&mut self) -> T {
        self.read1().unwrap()
    }
}

// https://beta.atcoder.jp/contests/joi2008ho/tasks/joi2008ho_b

fn dfs(
    paths: &Vec<Vec<usize>>,
    cnct: &mut Vec<i32>,
    p: usize,
    num: i32
) {
    cnct[p] = num;
    for next in paths[p].iter() {
        if cnct[*next] == -1 {
            dfs(paths, cnct, *next, num);
        }
    }
}

fn main() {
    let cin = stdin(); let cin = cin.lock(); let mut sc = Scanner::new(cin);

    let (n, k, l): (usize, usize, usize) = (sc.read(), sc.read(), sc.read());
    let mut pqs: Vec<Vec<usize>> = vec![Vec::new(); n];
    for i in 0..k {
        let (p, q): (usize, usize) = (sc.read(), sc.read());
        pqs[p-1].push(q-1); pqs[q-1].push(p-1);
    }
    let mut rss: Vec<Vec<usize>> = vec![Vec::new(); n];
    for i in 0..l {
        let (r, s): (usize, usize) = (sc.read(), sc.read());
        rss[r-1].push(s-1); rss[s-1].push(r-1);
    }
    
    let mut c1: Vec<i32> = vec![-1; n];
    let mut cnt = 0;
    for i in 0..n {
        if c1[i] == -1 {
            cnt += 1;
            dfs(&pqs, &mut c1, i, cnt);
        }
    }
    cnt = 0;
    let mut c2: Vec<i32> = vec![-1; n];
    for i in 0..n {
        if c2[i] == -1 {
            cnt += 1;
            dfs(&rss, &mut c2, i, cnt);
        }
    }

    let mut cncts = HashMap::new();
    for i in 0..n {
        let num = cncts.entry((c1[i], c2[i])).or_insert(0);
        *num += 1;
    }
    for i in 0..n {
        if i < n-1 { print!("{} ", cncts.get(&(c1[i], c2[i])).unwrap()); }
        else { println!("{}", cncts.get(&(c1[i], c2[i])).unwrap()); }
    }
}



Measured memory_bytes: 39164
package main

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

var N, K int

func main() {
	fsc := NewFastScanner()
	N := fsc.NextInt()
	K := fsc.NextInt()
	result := (1 << 25)
	for bit := 0; bit < (1 << uint(N)); bit++ {
		tmp := bit
		res := 1
		cnt := N
		for cnt > 0 {
			if tmp%2 == 0 {
				res += K
			} else {
				res *= 2
			}
			tmp >>= 1
			cnt -= 1
		}
		result = IntMin(result, res)
	}
	fmt.Println(result)
}

//template
type FastScanner struct {
	r   *bufio.Reader
	buf []byte
	p   int
}

func NewFastScanner() *FastScanner {
	rdr := bufio.NewReaderSize(os.Stdin, 1024)
	return &FastScanner{r: rdr}
}
func (s *FastScanner) Next() string {
	s.pre()
	start := s.p
	for ; s.p < len(s.buf); s.p++ {
		if s.buf[s.p] == ' ' {
			break
		}
	}
	result := string(s.buf[start:s.p])
	s.p++
	return result
}
func (s *FastScanner) NextLine() string {
	s.pre()
	start := s.p
	s.p = len(s.buf)
	return string(s.buf[start:])
}
func (s *FastScanner) NextInt() int {
	v, _ := strconv.Atoi(s.Next())
	return v
}
func (s *FastScanner) NextInt64() int64 {
	v, _ := strconv.ParseInt(s.Next(), 10, 64)
	return v
}

func (s *FastScanner) pre() {
	if s.p >= len(s.buf) {
		s.readLine()
		s.p = 0
	}
}
func (s *FastScanner) readLine() {
	s.buf = make([]byte, 0)
	for {
		l, p, e := s.r.ReadLine()
		if e != nil {
			panic(e)
		}
		s.buf = append(s.buf, l...)
		if !p {
			break
		}
	}
}

//Max,Min
func IntMax(a, b int) int {
	if a < b {
		return b
	}
	return a
}

func Int64Max(a, b int64) int64 {
	if a < b {
		return b
	}
	return a
}
func Float64Max(a, b float64) float64 {
	if a < b {
		return b
	}
	return a
}

func IntMin(a, b int) int {
	if a > b {
		return b
	}
	return a
}

func Int64Min(a, b int64) int64 {
	if a > b {
		return b
	}
	return a
}
func Float64Min(a, b float64) float64 {
	if a > b {
		return b
	}
	return a
}

//Gcd
func IntGcd(a, b int) int {
	if a < b {
		b, a = a, b
	}
	if b == 0 {
		return a
	}
	return IntGcd(b, a%b)
}
func Int64Gcd(a, b int64) int64 {
	if a < b {
		b, a = a, b
	}
	if b == 0 {
		return a
	}
	return Int64Gcd(b, a%b)
}

func IntAbs(a int) int {
	if a < 0 {
		a *= -1
	}
	return a
}

func Int64Abs(a int64) int64 {
	if a < 0 {
		a *= -1
	}
	return a
}


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

long long ans(int L, long long X){
	long long size = 1LL << (L+2);
	size -= 3;
	if (X == 0) return 0;
	if (L == 0) return 1;
	if (X <= (1LL << (L+1)) - 3 + 1) return ans(L-1, X-1);
	return (1LL << L) + ans(L-1, X-((1LL << (L+1)) - 3 + 2));
}
 
int main() {
	int N;
	long long X;
    cin >> N >> X;
    cout << ans(N, X) << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const ll mod = 1e9 + 7;
const ll inf = (1 << 30) - 1;
const ll infll = (1LL << 61) - 1;

int main()
{
    ll N, L, sum = 0, m = infll, mi;
    cin >> N >> L;
    for (int i = 0; i < N; i++)
    {
        ll a = L + i;
        sum += a;
        if (abs(a) < m)
        {
            m = abs(a);
            mi = a;
        }
    }
    cout << sum - mi << endl;
}

Measured memory_bytes: 256
#include <algorithm>
#include <iostream>
#include <vector>
#include <string>
#include <map>
#include <cmath>

using namespace std;
using ll = long long;
using ull = unsigned long long;

constexpr ll LLINF {1001002003004005006};//ll = 9*LLINF
constexpr int INTINF {1000000000};//int = 2*INTINF

#define  rep(i,n)   for(int i = 0; i < (n); ++i)
#define rrep(i,n)   for(int i = 1; i <= (n); ++i)
#define drep(i,n)   for(int i = (n)-1; i >= 0; --i)
#define srep(i,s,t) for(int i = s; i < t;  ++i)

template<typename T>
void maxs(T& x, T&& y) {
  x=std::max(x,y);
}
template<typename T>
void maxs(T& x, T& y) {
  x=std::max(x,y);
}

template<typename T>
void mins(T& x, T&& y) {
  x=std::min(x,y);
}
template<typename T>
void mins(T& x, T& y) {
  x=std::min(x,y);
}

const int mod = 1000000007;
struct mint {
  ll x; // typedef long long ll;
  mint(ll x=0):x((x%mod+mod)%mod){}
  mint operator-() const { return mint(-x);}
  mint& operator+=(const mint a) {
    if ((x += a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator-=(const mint a) {
    if ((x += mod-a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator*=(const mint a) {
    (x *= a.x) %= mod;
    return *this;
  }
  mint operator+(const mint a) const {
    mint res(*this);
    return res+=a;
  }
  mint operator-(const mint a) const {
    mint res(*this);
    return res-=a;
  }
  mint operator*(const mint a) const {
    mint res(*this);
    return res*=a;
  }
  mint pow(ll t) const {
    if (!t) return 1;
    mint a = pow(t>>1);
    a *= a;
    if (t&1) a *= *this;
    return a;
  }

  // for prime mod
  mint inv() const {
    return pow(mod-2);
  }
  mint& operator/=(const mint a) {
    return (*this) *= a.inv();
  }
  mint operator/(const mint a) const {
    mint res(*this);
    return res/=a;
  }
};

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

  int N;
  cin >> N;

  mint a(10);
  a = a.pow(N);
  mint b(9);
  b = b.pow(N);
  b *= 2;
  mint c(8);
  c = c.pow(N);

  mint ans = a + c - b;
  //cout << "a:" << a.x << '\n';
  //cout << "b:" << b.x << '\n';
  //cout << "c:" << c.x << '\n';
  cout << ans.x << '\n';
}


Measured memory_bytes: 3648
"use strict";

function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _nonIterableRest(); }

function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance"); }

function _iterableToArrayLimit(arr, i) { var _arr = []; var _n = true; var _d = false; var _e = undefined; try { for (var _i = arr[Symbol.iterator](), _s; !(_n = (_s = _i.next()).done); _n = true) { _arr.push(_s.value); if (i && _arr.length === i) break; } } catch (err) { _d = true; _e = err; } finally { try { if (!_n && _i["return"] != null) _i["return"](); } finally { if (_d) throw _e; } } return _arr; }

function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }

function main(input) {
  var lines = input.split('\n');

  var _splitNum = splitNum(lines[0]),
      _splitNum2 = _slicedToArray(_splitNum, 2),
      N = _splitNum2[0],
      K = _splitNum2[1];

  var xs = splitNum(lines[1]).slice(0, N);
  var min = Infinity;

  for (var start = 0; start <= N - K + 1; start++) {
    // (start)th to (start + K - 1)th
    var left = xs[start];
    var right = xs[start + K - 1];
    var walk = left >= 0 ? right : right <= 0 ? -left : -left >= right ? right + right - left : -left - left + right;

    if (min > walk) {
      min = walk;
    }
  }

  console.log(min);
}

main(require('fs').readFileSync('/dev/stdin', 'utf8'));

function splitNum(line) {
  return line.split(/\s+/).map(function (n) {
    return parseInt(n);
  });
}


Measured memory_bytes: 26688
#include<iostream>
#include<cstring>
using namespace std;
string s;int n;
int main(){
	cin>>n;
	cin>>s;
	for(int i=0;i<s.length();i++){
		char c=s[i];c-='A';c+=n;c%=26;c+='A';cout<<c;
	}
	return 0;
}

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


int main() {
	
	string s;
	cin >> s;
	int cnt =0;
	for (int i=0; i<3; i++){
		if( s.at(i) == '1' )
			cnt++;
	}
	cout << cnt;
	
	
	return 0;
}

Measured memory_bytes: 256
cnt = 0
*ant_locs, k = [int(input()) for _ in range(6)]
for idx_i, loc_i in enumerate(ant_locs):
    for idx_j, loc_j in enumerate(ant_locs):
        if idx_j >= idx_i:
            break
        if abs(loc_i - loc_j) > k:
            cnt += 1
            
print("Yay!" if cnt == 0 else ":(")

Measured memory_bytes: 3060
A,B,C,D,E,F = map(int,input().split())
W = []
S = []

# 100A,100B の水
for a in range(1 + F // 100):
    for b in range(1 + F // 100):
        water = 100 * (a * A + b * B)
        if 0 < water <= F:
            W.append(water)

# c,d の砂糖
for c in range(1 + F // C):
    for d in range(1 + F // D):
        sugar = c * C + d * D
        if sugar <= F:
            S.append(sugar)

W = list(set(W))
S = list(set(S))

x = -1
for w in W:
    for s in S:
        if w + s <= F:
            sol = 100 * s / w
            if x < sol <= E:
                x = sol
                X, Y = w + s, s

print(X,Y)


Measured memory_bytes: 51416
N = int(input())

A = list(map(int, input().split()))
B = list(map(int, input().split()))
B.append(0)
C = [0] * (N + 2)

cnt = 0

for i in range(N + 1):
    if A[i] <= B[i] + C[i]:
        cnt += A[i]
        C[i + 1] = B[i] - max(0, A[i] - C[i])
    else:
        cnt += B[i] + C[i]

print(cnt)


Measured memory_bytes: 18468
# -*- coding: utf-8 -*-
import sys
N=int(sys.stdin.readline().strip())
V=[]    #頂点の集合 (x座標、y座標、頂点番号)
for v in range(N):   #v:頂点番号
    x,y=tuple(map(int, sys.stdin.readline().split()))
    V.append((x,y,v+1))

#頂点をy軸でソート
V.sort(key=lambda x:(x[0]) )
E=[]    #辺の集合 (辺の長さ、頂点番号、頂点番号)
for i in range(N-1):
    fro_x,fro=V[i][0],V[i][2]
    to_x,to=V[i+1][0],V[i+1][2]
    E.append( (abs(fro_x-to_x),fro,to))

#頂点をx軸でソート
V.sort(key=lambda x:(x[1]) )
for i in range(N-1):
    fro_y,fro=V[i][1],V[i][2]
    to_y,to=V[i+1][1],V[i+1][2]
    E.append( (abs(fro_y-to_y),fro,to))

#辺の集合を辺の長さで昇順ソート
E.sort(key=lambda x:(x[0]) )


par=[ i for i in range(N+1) ]
size=[ 1 for i in range(N+1) ]

#Union Find
def root(x):
    while par[x]!=x:
        x=par[x]
    return x

def same(x,y):
	return root(x)==root(y)

def unite(x,y):
    x=root(x)
    y=root(y)
    if x==y: return
    if size[y]<size[x]: x,y=y,x  #yの要素数を大きくする
    size[y]+=size[x]
    par[x]=y #yが親ノード

def getsize(x):
	return size[root(x)]

ans=0
for cost,v1,v2 in E:
    if same(v1,v2) is False:
        ans+=cost
        unite(v1,v2)

print ans

Measured memory_bytes: 150440
#include <stdio.h>
int main(void){
    int a, b, c, i, divisor = 0;
    
    scanf("%d %d %d", &a, &b, &c);
    
    for(i = a; i <= b; i++){
        if (c % i == 0) divisor++;
    }
    
    printf("%d\n", divisor);

    return 0;
}

Measured memory_bytes: 596
#define _USE_MATH_DEFINES

#include <iostream>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <algorithm>
#include <functional>
#include <climits>
#include <cmath>
#include <utility>
#include <iomanip>

using namespace std;


int main(int argc, char *argv[])
{
	int n;
	string s;

	//input
	cin >> n;
	cin >> s;


	//calc
	string ans;

	string t1 = s.substr(0, n / 2);
	string t2 = s.substr(n / 2);
	if (t1.compare(t2) == 0){
		ans = "Yes";
	}
	else{
		ans = "No";
	}


	//ans
	cout << ans << endl;



	return 0;
}


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

using namespace std;

typedef long long ll;

int main() {
    ll L, R;

    cin >> L >> R;
    ll mod = 2019;

    ll res = 2131243;
    for (ll i = L; i < min(R, L+mod); i++) {
        ll first;
        for (ll j = i+1; j <= min(R, i+1 + mod); j++) {
            if (j == i+1) first = i*j % mod;

            res = min(res, i*j % mod);
        }
    }

    cout << res << endl;


}



Measured memory_bytes: 256
A, B, M = [int(i) for i in input().split()]
al = [int(i) for i in input().split()]
bl = [int(i) for i in input().split()]
xyc = [[int(i) for i in input().split()] for _ in range(M)]

print(min(min(al)+min(bl), min([al[m[0]-1] + bl[m[1]-1] - m[2] for m in xyc])))

Measured memory_bytes: 87660
#include <iostream>
#include <string>
#include <cmath>
#include <iomanip>
#include <vector>
#include <algorithm>

using namespace std;

int main(){

	int n;
	cin >> n;
	vector<double> v;
	double t,ans=0;
	for(int i=0;i<n;i++){
		cin >> t;
		v.push_back(t);
	}
	sort(v.begin(),v.end());

	for(int i=0;i<n;i++){
		if(i==0){
			ans += v[i]/(pow(2,n-i-1));
		}else{
			ans += v[i]/(pow(2,n-i));
		}
	}

	printf("%.5f\n",ans);

	return 0;
}

Measured memory_bytes: 256
a = list(map(int,input().split()))
a = sorted(a)
a,b,c = a[0],a[1],a[2]
ca = c-a
cb = c-b
if ca % 2 == 0 and cb % 2 == 0:
    print(ca //2 + cb //2)
elif ca % 2 == 1 and cb % 2 == 1:
    print(((ca-1) // 2) + ((cb-1) // 2) + 1)
elif ca % 2 == 1 and cb % 2 == 0:
    print((cb // 2) + 1 + ((ca+1) // 2))
elif cb % 2 == 1 and ca % 2 == 0:
    print((ca // 2) + 1 + ((cb+1) // 2))

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

#define all(x) begin(x), end(x)

using i64 = int_fast64_t;
using f64 = double;

constexpr i64 INF = INT_FAST64_MAX / 2;
constexpr f64 EPS = DBL_EPSILON;

void solve() {
    i64 n;
    cin >> n;

    i64 ans = 0;
    i64 cnt = 0, pre = 0;
    for (i64 i = 0; i < n; i++) {
        i64 a;
        cin >> a;
        if (pre == a) {
            cnt++;
            if (i != n - 1) continue;
        }
        pre = a;
        ans += cnt / 2;
        cnt = 1;
    }

    cout << ans << endl;
}

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


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define REP(i,n) for(int i=0;i<n;i++)
#define REPR(i,n) for(int i=n;i>=0;i--)
#define FOR(i,m,n) for(int i=m;i<n;i++)
#define ALL(a) a.begin(),a.end()
int main()
{
    string S,T;
    cin >> S >> T;
    T += S;
    cout << T << endl;
    return 0;
}

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

using namespace std;

int main(void)
{
    int N, i;
    string S, T;

    cin >> N;
    cin >> S >> T;

    for(i=0; i<N; i++){
        cout << S[i] << T[i];
    }
    cout << endl;

    return 0;
}

Measured memory_bytes: 256
import java.util.*;
import java.lang.String;
class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner (System.in);
    int n = sc.nextInt(); 
    sc.nextLine();
    String str = sc.nextLine(); // 6 7 9 10 31
    
    String[] arr = str.split(" ");
    for (String a : arr) {
      int i = Integer.parseInt(a);
      if (i % 2 == 0 && (i % 3 != 0 && i%5 != 0)) {
          System.out.println("DENIED");
          return;
      }
    }
    System.out.println("APPROVED");
  }
}

Measured memory_bytes: 22100
(defun prime-factorization (n)
  (let ((ans '()))
    (labels ((divide (m i c)
		     (unless (zerop (rem m i))
		       (return-from divide (values m (cons i c))))
		     (divide (/ m i) i (1+ c)))
	     (take-apart (m i)
			 (when (= m 1)
			   (return-from take-apart ans))

			 (when (< (sqrt m) i)
			   (return-from take-apart
			     (setf ans (append ans (list (cons m 1))))))

			 (if (zerop (rem m i))
			    (multiple-value-bind (m2 part) (divide m i 0)
			      (setf ans (append ans (list part)))
			      (take-apart m2 (1+ i)))
			    (take-apart m (1+ i)))))
      (take-apart n 2)
      ans)))

(defun abc052c (n)
  (let ((ex (make-array (1+ n) :initial-element 0)))
    (loop for i from 1 to n do
	  (loop for (p . e) in (prime-factorization i) do
		(setf (aref ex p)
		      (+ (aref ex p) e))))
    (rem (reduce #'*
	    (map 'list #'1+ ex))
	 (+ (expt 10 9) 7))))

(let ((n (read)))
   (princ (abc052c n))(terpri))


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

int32_t main()
{
    string s;
    cin>>s;
    if(s[0]=='A')
    {
        if(s[1]=='R')
        {
            if(s[2]=='C')
            cout<<"ABC";
        }
        else
        cout<<"ARC";
    }


    

}


Measured memory_bytes: 3572
#define _USE_MATH_DEFINES
#include <cstdio>
#include <iostream>
#include <sstream>
#include <fstream>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <complex>
#include <string>
#include <vector>
#include <list>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <bitset>
#include <numeric>
#include <limits>
#include <climits>
#include <cfloat>
#include <functional>
#include <iterator>
using namespace std;

class Point
{
public:
    double y, x;
    Point(){
        y = x = 0.0;
    }
    Point(double y0, double x0){
        y = y0;
        x = x0;
    }
    Point(double theta){
        y = sin(theta);
        x = cos(theta);
    }
    Point operator+(const Point& p) const{
        return Point(y + p.y, x + p.x);
    }
    Point operator-(const Point& p) const{
        return Point(y - p.y, x - p.x);
    }
    Point operator*(double a) const{
        return Point(y * a, x * a);
    }
    Point operator/(double a) const{
        return Point(y / a, x / a);
    }
    double length() const{
        return sqrt(y * y + x * x);
    }
    double dist(const Point& p) const{
        return sqrt(pow(y - p.y, 2) + pow(x - p.x, 2));
    }
    double dot(const Point& p) const{
        return y * p.y + x * p.x; // |a|*|b|*cosθ
    }
    double cross(const Point& p) const{
        return x * p.y - y * p.x; // |a|*|b|*sinθ
    }
    double angle() const{
        return atan2(y, x);
    }
};

template <class T>
class EdgeBase
{
public:
    int to;
    T cost;
    EdgeBase(){};
    EdgeBase(int to0, T cost0){to = to0; cost = cost0;}
};
typedef EdgeBase<double> Edge;

template<class T>
void shortestPath(const vector<vector<EdgeBase<T> > >& edges, int start, vector<T>& dist)
{
    const T INF = numeric_limits<T>::max();
    const T EPS = static_cast<T>(1.0e-10);

    dist.assign(edges.size(), INF);
    dist[start] = 0;
    priority_queue<pair<T,int>, vector<pair<T,int> >, greater<pair<T,int> > > q;
    q.push(make_pair(0, start));

    while(!q.empty()){
        pair<T, int> p = q.top();
        q.pop();
        int v = p.second;
        if(dist[v] < p.first - EPS)
            continue;
        for(unsigned i=0; i<edges[v].size(); ++i){
            EdgeBase<T> e = edges[v][i];
            if(dist[v] + e.cost < dist[e.to] - EPS){
                dist[e.to] = dist[v] + e.cost;
                q.push(make_pair(dist[e.to], e.to));
            }
        }
    }
}

int main()
{
    vector<Point> v(2);
    for(int i=0; i<2; ++i)
        cin >> v[i].x >> v[i].y;

    int n;
    cin >> n;
    n += 2;
    v.resize(n);
    vector<int> r(n, 0);
    for(int i=2; i<n; ++i)
        cin >> v[i].x >> v[i].y >> r[i];

    vector<vector<Edge> > edges(n);
    for(int i=0; i<n; ++i){
        for(int j=0; j<i; ++j){
            double dist = v[i].dist(v[j]);
            dist = max(0.0, dist - r[i] - r[j]);
            edges[i].push_back(Edge(j, dist));
            edges[j].push_back(Edge(i, dist));
        }
    }

    vector<double> dist;
    shortestPath(edges, 0, dist);
    printf("%.10f\n", dist[1]);

    return 0;
}


Measured memory_bytes: 22384
//Copyright(c)2017 Mstdream
#include<bits/stdc++.h>
using namespace std;
#define LL long long
inline void splay(LL &v){
	v=0;char c=0;LL p=1;
	while(c<'0' || c>'9'){if(c=='-')p=-1;c=getchar();}
	while(c>='0' && c<='9'){v=(v<<3)+(v<<1)+c-'0';c=getchar();}
	v*=p;
}

const int N=200010;
LL ans=1LL<<60,a[N],sum[N],n;
int main(){
	splay(n);
	for(int i=1;i<=n;i++){
		splay(a[i]);
		sum[i]=sum[i-1]+a[i];
	}
	for(int i=1;i<n;i++){
		LL x=sum[i];
		LL y=sum[n]-sum[i];
		ans=min(ans,abs(x-y));
	}
	cout<<ans<<endl;
}

Measured memory_bytes: 3328
/*---> 03 December 2019 <--- > 01:28:16 <---*/
// #pragma GCC optimize("Ofast")
// #pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
// #pragma GCC optimize("unroll-loops")
// #pragma comment(linker, "/stack:200000000")
#pragma GCC optimize("O3")
//#pragma GCC target ("sse4")
#include <bits/stdc++.h>
//#include <ext/pb_ds/tree_policy.hpp>
//#include <ext/pb_ds/assoc_container.hpp>
//using namespace __gnu_pbds;
using namespace std;
//template <class T> using Tree = tree<T, null_type, less<T>, rb_tree_tag,tree_order_statistics_node_update>;
#define int long long
#define F first
#define S second
#define mod 1000000007
#define inf (int)1e18+5
#define sz(x) (int)x.size()
#define PI 3.141592653589793238510
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
#define __ ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define vi vector<int>
#define vpii vector<pair<int,int> > 
#define vvi vector<vector<int> >
#define PRINT_TIME cerr << "Time elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << " s." <<endl;
#define sim template < class c
#define ris return * this
#define dor > debug & operator <<
#define eni(x) sim > typename   enable_if<sizeof dud<c>(0) x 1, debug&>::type operator<<(c i) {
sim > struct rge { c b, e; };
sim > rge<c> range(c i, c j) { return rge<c>{i, j}; }
sim > auto dud(c* x) -> decltype(cerr << *x, 0);
sim > char dud(...);
struct debug {
#ifdef LOCAL
~debug() { cerr << endl; }
eni(!=) cerr << boolalpha << i; ris; }
eni(==) ris << range(begin(i), end(i)); }
sim, class b dor(pair < b, c > d) {
  ris << "(" << d.first << ", " << d.second << ")";
}
sim dor(rge<c> d) {
  *this << "[";
  for (auto it = d.b; it != d.e; ++it)
    *this << ", " + 2 * (it == d.b) << *it;
  ris << "]";
}
#else
sim dor(const c&) { ris; }
#endif
};
#define imie(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "
typedef long double ld;
typedef pair<int,int> pii;
///////////////////////////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////////////////////////
const int N=1e5+5;
int n;
string s;
void add(int &a,int b){
	a+=b;
	if(a>=mod)
		a-=mod;
}
int32_t main(){__
	cin>>s;
	n=s.length();
	vi dp(n+1,1);
	for(int i=n-1;i>=0;i--){
		vi tdp(2);
		int cur=s[i]-'0';
		if(!cur){
			add(tdp[1],dp[1]);
		}
		else{
			add(tdp[1],dp[0]);
			add(tdp[1],(2*dp[1])%mod);
		}
		add(tdp[0],(3*dp[0])%mod);
		dp=tdp;
	}
	cout<<dp[1]<<"\n";
return 0;
}

Measured memory_bytes: 1232
#include <bits/stdc++.h>
#define REP(i, a, b) for (int i = (a); i < (b); ++i)

using namespace std;
using ll = long long;

/**
 * main
 */
int main () {
  int N; cin >> N;
  vector<ll> a(N);

  REP(i, 0, N) cin >> a[i];

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

  ll prev = 0;
  REP(i, 0, N) {
    if (prev == a[i]) {
      cout << "NO" << endl;
      return 0;
    }
    prev = a[i];
  }

  cout << "YES" << endl;
  return 0;
}


Measured memory_bytes: 1792
Public Class Program
  Shared Sub Main()
    Dim abc As Integer() = Cin.IntArr()
    Dim a As Integer = abc(0)
    Dim b As Integer = abc(1)
    Dim c As Integer = abc(2)
    Dim ans As String = "No"
    If a = b Then
      If b <> c Then
        ans = "Yes"
      End If
    ElseIf b = c Then
      If c <> a Then
        ans = "Yes"
      End If
    ElseIf c = a Then
      If a <> b Then
        ans = "Yes"
      End If
    End If
    Console.WriteLine(ans)
  End Sub
End Class

Public Class Cin
  Public Shared Function Str() As String
    Return Console.ReadLine().Trim()
  End Function
  Public Shared Function Int() As Integer
    Return Integer.Parse(Str())
  End Function
  Public Shared Function Lng() As Long
    Return Long.Parse(Str())
  End Function
  Public Shared Function Dbl() As Double
    Return Double.Parse(Str())
  End Function
  Public Shared Function StrArr(Optional separator As String = " ") As String()
    Return Str().Split(separator)
  End Function
  Public Shared Function IntArr(Optional separator As String = " ") As Integer()
    Return Array.ConvertAll(Of String, Integer)(StrArr(separator), AddressOf Integer.Parse)
  End Function
  Public Shared Function LngArr(Optional separator As String = " ") As Long()
    Return Array.ConvertAll(Of String, Long)(StrArr(separator), AddressOf Long.Parse)
  End Function
  Public Shared Function DblArr(Optional separator As String = " ") As Double()
    Return Array.ConvertAll(Of String, Double)(StrArr(separator), AddressOf Double.Parse)
  End Function
End Class

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

int main() {
  long long x, k, d;
  cin >> x >> k >> d;
  if (x < 0) x *= -1;
  if (x/d >= k) {
      cout << (x - k * d) << endl;
  } else {
      cout << abs((x % d) - d*((k - (x / d)) % 2)) << endl;
  }
}

Measured memory_bytes: 3632
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i,n) for(ll i = 0; i < (ll)(n); i++)
#define repi(i,a,b) for(ll i = (ll)(a); i < (ll)(b); i++)
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
const ll INF = 1LL << 60;
int main(){
    int n,r; cin >> n >> r;
    int ans;
    if(n>=10) ans = r;
    else ans = r + 100*(10-n);
    cout << ans << endl;
    return 0;
}

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

using namespace atcoder;
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<int, ll> pil;
typedef pair<ll, int> pli;
typedef pair<double,double> pdd;
#define SQ(i) ((i)*(i))
#define MEM(a, b) memset(a, (b), sizeof(a))
#define SZ(i) int(i.size())
#define FOR(i, j, k, in) for (int i=j ; i<(k) ; i+=in)
#define RFOR(i, j, k, in) for (int i=j ; i>=(k) ; i-=in)
#define REP(i, j) FOR(i, 0, j, 1)
#define REP1(i,j) FOR(i, 1, j+1, 1)
#define RREP(i, j) RFOR(i, j, 0, 1)
#define ALL(_a) _a.begin(),_a.end()
#define mp make_pair
#define pb push_back
#define eb emplace_back
#define X first
#define Y second
#ifdef jayinnn
#define TIME(i) Timer i(#i)
#define debug(...) do{\
    fprintf(stderr,"%s - %d (%s) = ",__PRETTY_FUNCTION__,__LINE__,#__VA_ARGS__);\
    _do(__VA_ARGS__);\
}while(0)
template<typename T>void _do(T &&_x){cerr<<_x<<endl;}
template<typename T,typename ...S> void _do(T &&_x,S &&..._t){cerr<<_x<<", ";_do(_t...);}
template<typename _a,typename _b> ostream& operator << (ostream &_s,const pair<_a,_b> &_p){return _s<<"("<<_p.X<<","<<_p.Y<<")";}
template<typename It> ostream& _OUTC(ostream &_s,It _ita,It _itb)
{
    _s<<"{";
    for(It _it=_ita;_it!=_itb;_it++)
    {
        _s<<(_it==_ita?"":",")<<*_it;
    }
    _s<<"}";
    return _s;
}
template<typename _a> ostream &operator << (ostream &_s,vector<_a> &_c){return _OUTC(_s,ALL(_c));}
template<typename _a> ostream &operator << (ostream &_s,set<_a> &_c){return _OUTC(_s,ALL(_c));}
template<typename _a> ostream &operator << (ostream &_s,deque<_a> &_c){return _OUTC(_s,ALL(_c));}
template<typename _a,typename _b> ostream &operator << (ostream &_s,map<_a,_b> &_c){return _OUTC(_s,ALL(_c));}
template<typename _t> void pary(_t _a,_t _b){_OUTC(cerr,_a,_b);cerr<<endl;}
#define IOS()
class Timer {
private:
    string scope_name;
    chrono::high_resolution_clock::time_point start_time;
public:
    Timer (string name) : scope_name(name) {
        start_time = chrono::high_resolution_clock::now();
    }
    ~Timer () {
        auto stop_time = chrono::high_resolution_clock::now();
        auto length = chrono::duration_cast<chrono::microseconds>(stop_time - start_time).count();
        double mlength = double(length) * 0.001;
        debug(scope_name, mlength);
    }
};
#else
#define TIME(i)
#define debug(...)
#define pary(...)
#define endl '\n'
#define IOS() ios_base::sync_with_stdio(0);cin.tie(0)
#endif

const ll MOD = 1000000007;
const ll INF = 0x3f3f3f3f3f3f3f3f;
const int iNF = 0x3f3f3f3f;
const ll MAXN = 100005;

mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

/********** Good Luck :) **********/
int main () {
    TIME(main);
    IOS();
    int n, q;
    cin >> n >> q;
    dsu d(n);
    while(q--){
        int t, u, v;
        cin >> t >> u >> v;
        if(t == 0){
            d.merge(u, v);
        } else {
            cout << d.same(u, v) << endl;
        }
    }

    return 0;
}

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

int main() {
  int N, sum = 0, team, l, r;
  cin >> N;

  for (int i = 0; i < N; i++){
    cin >> l >> r;
    team = r - l + 1;
    sum += team;
  }
  cout << sum;
}


Measured memory_bytes: 256
#include <algorithm>
#include <cassert>
#include <cfloat>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <deque>
#include <iostream>
#include <limits>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <tuple>
#include <unordered_map>
#include <unordered_set>
#include <vector>
 
#define FOR(i,k,n) for (int (i)=(k); (i)<(n); ++(i))
#define rep(i,n) FOR(i,0,n)
#define all(v) begin(v), end(v)
#define debug(x) std::cerr<< #x <<": "<<x<<"\n"
#define debug2(x,y) std::cerr<< #x <<": "<< x <<", "<< #y <<": "<< y <<"\n"
 
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<vector<int> > vvi;
typedef vector<ll> vll;
typedef vector<vector<ll> > vvll;
typedef deque<bool> db;
template<class T> using vv=vector<vector< T > >;

// cout vector
template<typename T> ostream& operator<<(ostream& s, const vector<T>& v) {
  int len = v.size(); s << "\n";
  for (int i = 0; i < len; ++i) {
    s << v[i]; if (i < len - 1) s << "\t";
  }
  s << "\n"; return s;
}

// cout 2-dimentional vector
template<typename T> ostream& operator<<(ostream& s, const vector< vector<T> >& vv) {
  int len = vv.size();
  for (int i = 0; i < len; ++i) { s << vv[i]; }
  return s;
}

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

int abs(int x) {
  if (x >= 0) {
    return x;
  } else {
    return -x;
  }
}

int main() {
  int n, X;
  scanf("%d %d", &n, &X);
  vi x(n);
  rep (i, n) {
    scanf("%d", &x[i]);
  }
  int ans = abs(x[0] - X);

  rep (i, n) {
    int d = abs(x[i] - X);
    ans = gcd(ans, d);
  }
  printf("%d\n", ans);

  return 0;
}


Measured memory_bytes: 888
def main():
    n = int(input())

    sum_count = 0

    for i in range(1,n+1):
        if i % 3 == 0:
            continue
        if i % 5 == 0:
            continue
        sum_count += i

    print(sum_count)

if __name__ == '__main__':
    main()

Measured memory_bytes: 67248
#include <bits/stdc++.h>
using namespace std;
#ifdef ENABLE_DEBUG_OUTPUT
#define DEBUG_LOG(s) cout << s << endl;
#else
#define DEBUG_LOG(s) void();
#endif

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

    vector<vector<pair<int, bool>>> s(n);
    for (auto i = 0; i < n; i++) {
        int a; cin >> a;
        for (auto j = 0; j < a; j++) {
            int x; bool y; cin >> x >> y;
            s[i].emplace_back(x - 1, y);
        }
    }

    int ans = 0;
    for (auto i = 0; i < (1 << n); i++) {
        int cnt = 0, all_cnt = 0;
        for (auto j = 0; j < n; j++) {
            if(i & (1 << j)) {
                int ok_cnt = 0;
                for (auto k = 0; k < (int)s[j].size(); k++) {
                    if (bitset<16>(i)[s[j][k].first] == s[j][k].second) ok_cnt++;
                }
                if(ok_cnt == (int)s[j].size()) cnt++;
                all_cnt++;
            }
        }
        if(cnt == all_cnt) ans = max(ans, all_cnt);
    }

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

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
using i64 = int_fast64_t;
#define rep(i, N) for(int (i) = 0; (i) < (N); (i)++)
#define all(v) (v).begin(), (v).end()
#define eb emplace_back
#define Cout(s) cout << s << endl
string Yes(bool b) {if(b){return "Yes";} else {return "No";}}
string YES(bool b) {if(b){return "YES";} else {return "NO";}}


int main(){
	string S;
	cin >> S;
	S.insert(4, " ");
	Cout(S);
}


Measured memory_bytes: 256
from sys import stdin
from itertools import groupby

li = [list(map(int,stdin.readline().rstrip().split())) for _ in range(3)]
lis = []
for i in range(3):
    for j in range(2):
        lis.append(li[i][j])
lis.sort()
lin = []
for key, value in groupby(lis):
    lin.append(len(list(value)))
lin.sort()
if lin == [1,1,2,2]:
    print("YES")
else:
    print("NO")

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

int main() {
  int W, H, x, y;
  cin >> W >> H >> x >> y;
  
  cout << double(W) * double(H) / 2;
  cout << ' ';
  
 // if ((W%2==0 && x==W/2) && (H%2==0 && y==H/2)) {
  if (x+x==W && y+y==H) {
    cout << 1;
  } else {
    cout << 0;
  }
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
    std::ios_base::sync_with_stdio(false);
    cin.tie(0);
    int n,m;
    cin>>n>>m;
    long long sum=0;
    int a[m]={0};
    for(int i =0;i<m;i++)
    {
        cin>>a[i];
        sum+=a[i];
    }
    if(n-sum<0)
        cout<<-1;
    else
        cout<<n-sum;


}


Measured memory_bytes: 3692
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
using ll = long long;
using u64 = uint_fast64_t;
using pii = pair<int, int>;
using pll = pair<long long, long long>;
#define rep(i, n) for(int i = 0; i < (n); ++i)
#define all(x) (x).begin(),(x).end()
constexpr char ln =  '\n';
constexpr long long MOD = 1000000007;
//constexpr long long MOD = 998244353;
template<class T1, class T2> inline bool chmax(T1 &a, T2 b) { if (a < b) { a = b; return true;} return false; }
template<class T1, class T2> inline bool chmin(T1 &a, T2 b) { if (a > b) { a = b; return true;} return false; }
inline int popcount(int x) {return __builtin_popcount(x);}
inline int popcount(long long x) {return __builtin_popcountll(x);}
void print() { cout << "\n"; }
template<class T, class... Args>
void print(const T &x, const Args &... args) {
    cout << x << " ";
    print(args...);
}
///////////////////////////////////////////////////////////////////////////////////////////////////////////////

int main() {
    ios::sync_with_stdio(false); cin.tie(nullptr);
    string S; cin >> S;
    int N = S.size();

    //後ろからdp
    reverse(all(S));
    //次にjが出てくるid(0-indexed)
    vector<vector<int>> nex(N+1, vector<int>(26,N));
    for (int i = N-1; i >= 0; i--) {
        rep(j,26) nex[i][j] = nex[i+1][j];
        nex[i][S[i]-'a'] = i;
    }
    //(1-indexed) i文字目の前まで見て最後にj使ったときの求めたい文字列の長さの最小値
    vector<vector<int>> dp(N+2, vector<int>(26,1e9));
    rep(j,26) dp[0][j] = 0;
    rep(i,N+1) {
        int m = 1e9;
        rep(j,26) chmin(m,dp[i][j]);
        rep(j,26) chmin(dp[nex[i][j]+1][j],m+1);
    }
    for (int i = N+1; i > 0; i--) {
        rep(j,26) chmin(dp[i-1][j],dp[i][j]);
    }
    int cur = N+1;
    int val = 1e9;
    int num = 26;
    int pos = N+1;
    rep(i,26) if (chmin(val,dp[N+1][i])) num = i;
    string ans = "";
    ans += char(num+'a');
    // cur = nex[i][j]+1のi
    while (cur) {
        while (cur and nex[cur-1][num]+1>=pos) cur--;
        if (!cur) break;
        rep(j,26) {
            if (dp[cur][j]==val-1) {
                num = j;
                break;
            }
        } 
        ans += char(num+'a');
        val--;
        pos = cur;
    }

    cout << ans << ln;
}



Measured memory_bytes: 56648
#include <stdio.h>


int main(void){
	int sum, p;


	while (true){
		scanf("%d", &sum);
		if (sum == 0){ break; }
		for (int i = 0; i < 9; i++){
			scanf("%d", &p);
			sum -= p;
		}
		printf("%d\n", sum);
	}


	return 0;
}

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

typedef unsigned long long  ULL;
typedef long long LL;

#define PB push_back
#define MP make_pair
#define RESET(a, b) memset(a, b, sizeof(a))
#define FOR(i,a,b) for(int i=a; i<=b; i++)
#define F first 
#define S second

 
int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    int n,m;
    cin>>n>>m;
    
    int sum1=n*(n-1)/2;
    int sum2=m*(m-1)/2;
    
    cout<<sum1+sum2;

    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <cstdlib>
#include <math.h>

using namespace std;
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; }

const long long INF = 1LL << 60;

#define MOD 1000000007

int w[110];
int v[110];
// initialize all to 0
long long dp[110][100010] = {0};

int main(){

    int N, W; cin >> N >> W;

    for(int i = 0; i < N; ++i) cin >> w[i] >> v[i];


    for(int i = 0; i < N; ++i){
        for(int sum_w = 0; sum_w <= W; ++sum_w){
            
            // case choose i+1 th item
            if(sum_w >= w[i]){
                chmax(dp[i+1][sum_w], dp[i][sum_w-w[i]]+v[i]);
            }

            // case not choose i+1 th item
            // not use else because there is a case where the prev ith item is larger than current
            chmax(dp[i+1][sum_w], dp[i][sum_w]);
            
        }
    }

    cout << dp[N][W] << endl;
}

Measured memory_bytes: 79488
#include <bits/stdc++.h>
    using namespace std;
     
    int main () 
    {
        int N;
        std::cin >> N;
        
        int A[N];
        for (int i = 0; i < N; i++) 
        {
            std::cin >> A[i]; 
        }
        for (int k = 0; k < N; k++) 
        {
            if (k != N-1) std::cout << A[k] << " ";
            else          std::cout << A[k] << std::endl;
        }
        
        for (int i = 1; i < N; i++) 
        {
            int point = A[i];
            
            int j = i-1;
            for(; j >= 0 and A[j] > point; )
            {
                A[j+1] = A[j];
                j--;
            }
            A[j+1] = point;
            
            for (int k = 0; k < N; k++) 
            {
                if (k != N-1) std::cout << A[k] << " ";
                else          std::cout << A[k] << std::endl;
            }
        }
        
        return 0;
    }


Measured memory_bytes: 3068
#include <iostream>
#include <string>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <vector>
#include <cmath>
#include <cstdlib>
#include <queue>
#include <stack>
#include <iomanip>


using namespace std;

#define REP(i, n) for(ll i = 0;i < n;i++)
#define REPR(i, n) for(ll i = n;i >= 0;i--)
#define FOR(i, m, n) for(ll i = m;i < n;i++)
#define FORR(i, m, n) for(int i = m;i >= n;i--)
#define REPO(i, n) for(ll i = 1;i <= n;i++)
#define ll long long
#define INF (ll)1 << 60
#define MINF (-1 * INF)
#define ALL(n) n.begin(),n.end()
#define MOD (ll)1000000007
#define P pair<ll, ll>
	
ll n, m, now;
vector<P> s;
priority_queue<ll> q;
int main() {
	cin >> n >> m;
	s.resize(n);
	REP(i, n) {
		ll a, b;
		cin >> a >> b;
		s[i] = P(a, b);
	}
	s.push_back(P(INF, INF));
	sort(ALL(s));
	ll ans = 0;
	REPO(i, m) {
		while (s[now].first == i) {
			q.push(s[now].second);
			now++;
		}
		if (!q.empty()) {
			ans += q.top();
			q.pop();
		}
	}
	cout << ans << endl;
}
	

Measured memory_bytes: 4864
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <string>
#include <vector>


using LL = long long;
const int kN = 100000 + 5;
int n, a[kN], b[kN];

int main() {
  scanf("%d", &n);
  for (int i = 0; i < n; ++ i) {
    scanf("%d", a + i);
  }
  int result = 0;
  LL left = 0;
  std::vector<int> surplus;
  for (int i = 0; i < n; ++ i) {
    scanf("%d", b + i);
    if (a[i] < b[i])
      left += b[i] - a[i], ++ result;
    else if (a[i] > b[i])
      surplus.emplace_back(a[i] - b[i]);
  }
  std::sort(surplus.begin(), surplus.end());
  while (left > 0 && !surplus.empty()) {
    int w = surplus.back();
    surplus.pop_back();
    left -= w;
    ++ result;
  }
  if (left > 0) {
    puts("-1");
  } else {
    printf("%d\n", result);
  }
}

Measured memory_bytes: 1404
#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>;
const int mod = 1000000007;
struct mint {
  ll x; // typedef long long ll;
  mint(ll x=0):x((x%mod+mod)%mod){}
  mint operator-() const { return mint(-x);}
  mint& operator+=(const mint a) {
    if ((x += a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator-=(const mint a) {
    if ((x += mod-a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator*=(const mint a) { (x *= a.x) %= mod; return *this;}
  mint operator+(const mint a) const { return mint(*this) += a;}
  mint operator-(const mint a) const { return mint(*this) -= a;}
  mint operator*(const mint a) const { return mint(*this) *= a;}
  mint pow(ll t) const {
    if (!t) return 1;
    mint a = pow(t>>1);
    a *= a;
    if (t&1) a *= *this;
    return a;
  }

  // for prime mod
  mint inv() const { return pow(mod-2);}
  mint& operator/=(const mint a) { return *this *= a.inv();}
  mint operator/(const mint a) const { return mint(*this) /= a;}
};


mint choose(ll a, ll b){
  mint ans = 1;
  for(ll i = 1; i < b + 1; i++){
      ans *=(a + 1 - i);
      ans /= i;
  }
  return ans;
}
int main(){
    ll x, y;
    cin >> x >> y;
    if((x + y) % 3 != 0){
        cout << 0 << endl;
        return 0;
    }
    ll kaisu, sa;
    kaisu = (x + y) / 3;
    if(x - kaisu < 0|| y - kaisu < 0){
        cout << 0 << endl;
        return 0;
    }
    sa = abs(x - y);
    ll a = (kaisu - sa) / 2;
    mint ans;
    ans = choose(kaisu, a);
    cout << ans.x << endl;
}

Measured memory_bytes: 256