akhauriyash/Code-Regression huggingface dataset:
package main

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

func main() {
	n, m := readInt(), readInt()

	store := make(sortArray, n)
	for i := range store {
		store[i].x = readInt()
		store[i].b = readInt()
	}

	sort.Sort(store)

	ans := 0
	for i := range store {
		k := min(m, store[i].b)
		ans += k * store[i].x
		m -= k
		if m == 0 {
			fmt.Println(ans)
			return
		}
	}
}

// sort ------------------------------------------------------------

type xxx struct {
	x int
	b int
}

type sortArray []xxx

func (s sortArray) Len() int           { return len(s) }
func (s sortArray) Swap(i, j int)      { s[i], s[j] = s[j], s[i] }
func (s sortArray) Less(i, j int) bool { return s[i].x < s[j].x }

// -----------------------------------------------------------------

var (
	readString func() string
	readBytes  func() []byte
)

func init() {
	readString, readBytes = newReadString(os.Stdin)
}

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

	f1 := func() string {
		if !r.Scan() {
			panic("Scan failed")
		}
		return r.Text()
	}
	f2 := func() []byte {
		if !r.Scan() {
			panic("Scan failed")
		}
		return r.Bytes()
	}
	return f1, f2
}

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

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

func readFloat64() float64 {
	f, err := strconv.ParseFloat(readString(), 64)
	if err != nil {
		panic(err.Error())
	}
	return f
}

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

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

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

func sum(a []int) int {
	var ret int
	for i := range a {
		ret += a[i]
	}
	return ret
}

func sumFloat64(a []float64) float64 {
	var ret float64
	for i := range a {
		ret += a[i]
	}
	return ret
}

func gcd(m, n int) int {
	for m%n != 0 {
		m, n = n, m%n
	}
	return n
}

func lcm(m, n int) int {
	return m / gcd(m, n) * n
}


Measured memory_bytes: 3840
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define EPS (1e-7)
#define INF (1e9)
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(x) x.begin(),x.end()
const double PI = acos(-1);
const ll MOD = 1000000007;
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;
}
///////////////////////////////////////////////////////////////

vector<vector<int>> G;

vector<bool> seen;
vector<int> finished;

void dfs(int v) {
    seen[v] = true;
    for (auto nv : G[v]) {
        if (seen[nv]) continue;
        dfs(nv);
    }
    finished.emplace_back(v);
    return;
}

int main() {
    ios::sync_with_stdio(false); cin.tie(nullptr);
    int N,M; cin >> N >> M;
    G.resize(N);
    rep(i,M) {
        int s,t; cin >> s >> t;
        G[s].emplace_back(t);
    }

    seen.assign(N, false);

    rep(i,N) {
        if (seen[i]) continue;
        dfs(i);
    }

    reverse(all(finished));

    rep(i,N) cout << finished[i] << endl;
}


Measured memory_bytes: 3732
object Main extends App {
	val Array(h, w) = scala.io.StdIn.readLine.split(" ").map(_.toInt)
	val a = Array.ofDim[Int](h, w)

	for(i<-0 until h){
		a(i) = scala.io.StdIn.readLine.split(" ").map(_.toInt)
	}

	var ans = List[(Int, Int, Int, Int)]()

	for(i<-0 until h){
		for(j<-0 until w){
			if(a(i)(j)%2!=0){
				if(j!=w-1){
					a(i)(j+1)+=1
					ans=(i, j, i, j+1) :: ans
				}
				else if(i!=h-1){
					a(i+1)(j)+=1
					ans=(i, j, i+1, j) :: ans
				}
			}
		}
	}

	println(ans.size)
	for(x <- ans){
		myP(x._1, x._2, x._3, x._4)
	}

	def myP(x: Int, y: Int, a: Int, b: Int): Unit = {
		println(Array(x+1,y+1,a+1,b+1).mkString(" "))
	}

}


Measured memory_bytes: 84096
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		int N = scan.nextInt();
		int M = scan.nextInt();
		int[] a = new int[M];
		int[] b = new int[M];
		int sum = 0;
		for(int i = 0; i < M; i++) {
			a[i] = scan.nextInt();
			b[i] = scan.nextInt();
		}
		for(int i = 1; i <= N; i++) {
			for(int j = 0; j < M; j++) {
				if(a[j] == i) {
					sum++;
				}
				if(b[j] == i) {
					sum++;
				}
			}
			System.out.println(sum);
			sum = 0;
		}
		scan.close();

	}

}


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

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    
    int n;
    cin >> n;
    
    int sqrt_n = sqrt(n);
    vector<int> ans(n + 1);
    for (int x = 1; x <= sqrt_n; x++){
        for (int y = 1; y <= sqrt_n; y++){
            for (int z = 1; z <= sqrt_n; z++){
                if (x * x + y * y + z * z + x * y + y * z + z * x <= n)
                    ans[x * x + y * y + z * z + x * y + y * z + z * x] += 1;
            }
        }
    }
    
    for (int i = 1; i < (int) ans.size(); i++)
        cout << ans[i] << '\n';

    return 0;
}


Measured memory_bytes: 3652
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ConsoleApplication1
{
    class Program
    {
        static readonly int MAX = 1000000;

        static void Main(string[] args)
        {
            StringBuilder sb = new StringBuilder();

            var memo = Enumerable.Range(0, MAX).ToArray();
            memo[0] = memo[1] = -1;

            int len = (int)Math.Sqrt(MAX);

            for (int i = 2; i < len; i++)
            {
                if (memo[i] == -1) continue;

                for (int j = i + i; j < MAX; j += i)
                {
                    memo[j] = -1;
                }
            }
            var primes = memo.Where(a => a != -1).ToArray();

            while (true)
            {
                int n = int.Parse(Console.ReadLine());

                if (n == 0) break;

                int res = 0;

                for (int i = 0; i < n; i++)
                {
                    string[] input = Console.ReadLine().Split(' ');
                    int p = int.Parse(input[0]);
                    int m = int.Parse(input[1]);
                    int s = p - m;
                    int t = p + m;

                    s = LowerBound(primes, s);
                    t = UpperBound(primes, t);
                    res += (t - s - 1);
                }
                sb.AppendLine(res.ToString());
            }
            Console.Write(sb);
        }

        static int LowerBound(int[] arr, int value)
        {
            int low = 0, high = arr.Length;

            while (low < high)
            {
                int mid = ((high - low) >> 1) + low;

                if (arr[mid] < value) low = mid + 1;
                else high = mid;
            }
            return low;
        }

        static int UpperBound(int[] arr, int value)
        {
            int low = 0, high = arr.Length;

            while (low < high)
            {
                int mid = ((high - low) >> 1) + low;

                if (arr[mid] <= value) low = mid + 1;
                else high = mid;
            }
            return low;
        }
    }
}

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

using namespace std;

typedef unsigned long long ull;
typedef long long ll;
typedef long double ld;
//#define int ll
//#define int __int128
//#define ll __int128
typedef pair<int, int   > pii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
typedef vector<pii> vpi;
typedef vector< vi > vvi;
typedef vector< vvi > vvvi;
typedef vector<short> vs;
typedef vector<vs> vvs;
typedef vector<vvs> vvvs;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<vvl> vvvl;
typedef vector<ld> vld;
typedef vector<vld> vvld;
typedef vector<vvld> vvvld;
typedef vector<string> vst;
typedef vector<vst> vvst;
typedef pair<ld, ld> pld;
//typedef complex<double> base;

#define inmin(a, b) a = min(a, (b))
#define inmax(a, b) a = max(a, (b))
#define ALL(a) a.begin(),a.end()
#define RALL(a) a.rbegin(),a.rend()
#define sqr(x) ((x) * (x))
#define fori(i, n) for(int i = 0; i < (int)(n); ++i)
#define SZ(a) ((int)((a).size()))
#define triple(T) tuple<T, T, T>
#define quad(T) tuple<T, T, T, T>
#define watch(x) cerr << (#x) << " = " << (x) << endl;
#define mp(a, b) make_pair(a, b)

#ifdef MAX_HOME
#define cerr cout
#else
#define cerr if (false) cerr
#endif

const double PI = 2 * acos(0.0);
#define rand shittttty_shit
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
mt19937_64 rng_64(chrono::steady_clock::now().time_since_epoch().count());

const string DIGITS = "0123456789";
const string ALPH = "abcdefghijklmnopqrstuvwxyz";

template <class T0, class T1>
inline ostream & operator << (ostream &out, pair<T0, T1> &a) {
    return out << "{" << a.first << ", " << a.second << "}";
}

template <class T0, class T1, class T2>
inline ostream & operator << (ostream &out, tuple<T0, T1, T2> &a) {
    return out << "{" << get<0>(a) << ", " << get<1>(a) << ", " << get<2>(a) << "}";
}

template <class T0, class T1, class T2, class T3>
inline ostream & operator << (ostream &out, tuple<T0, T1, T2, T3> &a) {
    return out << "{" << get<0>(a) << ", " << get<1>(a) << ", " << get<2>(a) << ", " <<  get<3>(a) << "}";
}

template<class T>
inline ostream & operator << (ostream &out, vector<T> &a) {
    out << "[";
    fori (i, a.size())
        out << a[i] << vector<string>{", ", "]  "}[i + 1 == a.size()];
    return out;
}



void smain();

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

#ifdef MAX_HOME
    freopen("input.txt", "r", stdin);
    clock_t start = clock();
#endif
    cout << setprecision(12) << fixed;
    smain();
#ifdef MAX_HOME
    cout << "\n\n\n\nTOTAL EXECUTION TIME: " << float( clock () - start ) /  CLOCKS_PER_SEC << endl;
#endif
    return 0;
}



void smain() {

    int n;
    cin >> n;
    n <<= 1;
    vi a(n);
    fori (i, n) {
        cin >> a[i];
    }
    sort(ALL(a));
    int ans = 0;
    for (int i = 0; i < n; i += 2) {
        ans += a[i];
    }
    cout << ans;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <math.h>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
using namespace std;

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

int main(){
    ll N, P;
    cin >> N >> P;
    if(N == 1){
        cout << P << endl;
        return 0;
    }
    if(P == 1){
        cout << 1 << endl;
        return 0;
    }
    ll ans;
    for(int gcd = 1; gcd <= sqrt(P); gcd++){
        ll g_n = pow(gcd, N);
        if(P % g_n == 0) ans = gcd;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 4260
#include <cstdio>
#include <iostream>
#include <vector>
using namespace std;

const int MaxN = 505;
int a[MaxN*MaxN], x[MaxN*MaxN];

int main(){
	int n; scanf("%d",&n);
	for(int i=1; i<=n; ++i){
		int r; scanf("%d",&r);
		x[r] = i; // 直接存
	}
	bool ok = true;
	for(int i=1; i<=n*n; ++i){
		if(x[i] == 0) continue;
		int cnt = a[i] = x[i];
		for(int j=1; j<i&&cnt>1; ++j)
			if(a[j] == 0)
				a[j] = x[i], -- cnt;
		if(cnt > 1) ok = false;
	}
	for(int i=n*n; i>=1; --i){
		if(x[i] == 0) continue;
		int cnt = n-x[i];
		for(int j=n*n; j>i&&cnt>0; --j)
			if(a[j] == 0)
				a[j] = x[i], -- cnt;
		if(cnt > 0) ok = false;
	}
	if(ok){
		printf("Yes\n");
		for(int i=1; i<=n*n; ++i)
			printf("%d ",a[i]);
	}
	else printf("No\n");
	return 0;
}

Measured memory_bytes: 2816
n, m = gets.split(" ").map(&:to_i)
@s = {}
err = false

case n
when 3
  s = {
    0 => (1..9).to_a,
    1 => (0..9).to_a,
    2 => (0..9).to_a,
  }
when 2
  s = {
    0 => [0],
    1 => (1..9).to_a,
    2 => (0..9).to_a,
  }
when 1
  s = {
    0 => [0],
    1 => [0],
    2 => (0..9).to_a,
  }
end

m.times do |i|
  x, y = gets.split(" ").map(&:to_i)
  s[x+2-n] = s[x+2-n] & [y]
end

x, y, z = s[0].first, s[1].first, s[2].first
if x.nil? then
  puts -1
elsif y.nil? then
  puts -1
elsif z.nil? then
  puts -1
else
  puts x*100 + y*10 + z
end


Measured memory_bytes: 1788
#include <iostream>
#include <vector>
#include <algorithm>
#include <list>
#include <iomanip>
#include <string>
#include <cctype>
#include <cstdio>
#include <cmath>

using namespace std;

int main() {
  int A;
  for(int i=0;i<5;i++){
    cin>>A;
    if(A==0){
      cout<<i+1<<endl;
      break;
    }
  }
}

Measured memory_bytes: 3620
import numpy as np
import sys
read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines

def main():
    N = int(readline())
    A = [int(i) for i in readline().split()]
    B = [int(i) for i in readline().split()]
    C = [int(i) for i in readline().split()]

    A = np.array(sorted(A), dtype=np.int64)
    B = np.array(sorted(B), dtype=np.int64)
    C = np.array(sorted(C), dtype=np.int64)

    A_bisect = np.searchsorted(A, B, side="left")
    C_bisect = np.searchsorted(C, B, side="right")

    ans = A_bisect * (N - C_bisect)
    print(ans.sum())


if __name__ == "__main__":
    main()


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

#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n - 1; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i <= n; i++)
#define FORR(i, m, n) for(int i = m; i >= n; i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define VSORTR(v) sort(v.rbegin(), v.rend());
#define ALL(v) (v).begin(),(v).end()
using namespace std;
using ll = long long;
using vll = vector<ll>;
using vvll = vector<vector<ll>>;
using P = pair<ll, ll>;
const ll mod = 1e9+7;

ll power(ll a,ll b){return b?power(a*a%mod,b/2)*(b%2?a:1)%mod:1;}

ll C(ll n,ll k)
{
  ll x=1,y=1;
  for(int i=1;i<=k;i++)
  {
    x=x*(n-i+1)%mod;
    y=y*i%mod;
  }
  return x * power(y,mod-2) % mod;
}

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

    ll n,l;cin>>n>>l;
    ll sum = l * n + n*(n-1)/2;
    if (l>=0)cout<< sum-l<<endl;
    else if(l>=1-n) cout<<sum<<endl;
    else cout<<sum-l-n+1<<endl;
    return 0;
}

Measured memory_bytes: 256
#include <algorithm>
#include <iostream>
#include <math.h>
#include <stdio.h>
#include <string>
#include <sstream>
#include <vector>
#include <set>
#include <stack>
#include <map>
#include <cmath>
#include <queue>
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
using namespace std;
typedef unsigned long long ll;

int main()
{
	const ll upperLimit = 1000000000000000000;
	int n;
	cin>>n;
	ll ans;
	ll *A = new ll[n];
	rep(i,n) cin>>A[i];
	double dAns = A[0];
	ans = A[0];
	bool consistZero = false;
	rep(i,n){
		if(A[i] == 0){
			consistZero = true;
			break;
		}
	}
	if(consistZero == true){
		cout<<0<<endl;
	}else{
		bool over = false;
		for(int i = 1; i <n; i++){
			dAns = dAns * A[i];
			if(dAns > upperLimit){
				over = true;
				break;
			}
			ans = ans* A[i];
			if(ans > upperLimit){
				over = true;
				break;
			}
		}
		if( over == true){
			cout<<-1<<endl;
		}else{
			cout<<ans<<endl;
		}
	}
	
	return 0;
}



Measured memory_bytes: 3888
#include <iostream>
#include <queue>
using namespace std;
static const int N = 100;
static const int INFTY = (1<<21);
int n, M[N][N], d[N];

void bfs(int s) {
    queue<int> q;
    q.push(s);
    for(int i = 0; i < n; i++) d[i] = INFTY;
    d[s] = 0;
    int u;
    while(!q.empty()) {
        u = q.front(); q.pop();
        for(int v = 0; v < n; v++) {
            if(M[u][v] == 0) continue;
            if(d[v] != INFTY) continue;
            d[v] = d[u] + 1;
            q.push(v);
        }
    }
    for(int i = 0; i < n; i++) {
        cout << i+1 << " " << ((d[i] == INFTY) ? (-1):d[i]) << endl;
    }
}

int main() {
    int u, k, v;
    cin >> n;
    for(int i = 0; i < n; i++) {
        for(int j = 0; j < n; j++) M[i][j] = 0;
    }
    for(int i = 0; i < n; i++) {
        cin >> u >> k;
        u--;
        for(int j = 0; j < k; j++) {
            cin >> v;
            v--;
            M[u][v] = 1;
        }
    }
    bfs(0);
    return 0;
}


Measured memory_bytes: 3144
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cctype>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstring>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string>
#include <tuple>
#include <vector>
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
//#define cerr if(false) cerr
#ifdef DEBUG
#define show(...) cerr << #__VA_ARGS__ << " = ", debug(__VA_ARGS__);
#else
#define show(...) 42
#endif
using namespace std;
using ll = long long;
using pii = pair<int, int>;
template <typename T, typename S>
ostream& operator<<(ostream& os, pair<T, S> a) {
    os << '(' << a.first << ',' << a.second << ')';
    return os;
}
template <typename T>
ostream& operator<<(ostream& os, vector<T> v) {
    for (auto x : v) os << x << ' ';
    return os;
}
void debug() {
    cerr << '\n';
}
template <typename H, typename... T>
void debug(H a, T... b) {
    cerr << a;
    if (sizeof...(b)) cerr << ", ";
    debug(b...);
}
int a[2000005];
int aru[1000005];
bool b[1000005];
int main(){
    int n;
    cin >> n;
    rep(i,n)cin >> a[i];
    rep(i,n)aru[a[i]]++;
    for(int i = 1; i <= 1000000; i++){
        if(aru[i])for(int j = 2 * i; j <= 1000000; j += i){
            b[j] = true;
        }
    }
    int ans = 0;
    rep(i,n){
        if(aru[a[i]]==1 and !b[a[i]])ans++;
    }
    cout << ans << endl;
}


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

#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 FORR(i, m, n) for(int i = m;i >= n;i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define llong long long
#define pb(a) push_back(a)
#define INF 999999999
using namespace std;
typedef pair<int, int> P;
typedef pair<llong, llong> LP;
typedef pair<int, P> PP;
typedef pair<llong, LP> LPP;

int dy[]={0, 0, 1, -1, 0};
int dx[]={1, -1, 0, 0, 0};

llong gcd( llong m, llong n )
{
	// 引数に０がある場合は０を返す
	if ( ( 0 == m ) || ( 0 == n ) )
		return 0;
	
	// ユークリッドの方法
	while( m != n )
	{
		if ( m > n ) m = m - n;
		else         n = n - m;
	}
	return m;
}//gcd

//*********************************************************
// 最小公倍数（Least Common Multiple）を返す。
// 引数に０がある場合は０を返す。
//*********************************************************
llong lcm( llong m, llong n )
{
	// 引数に０がある場合は０を返す
	if ( ( 0 == m ) || ( 0 == n ) )
		return 0;
	
	return ((m / gcd(m, n)) * n); // lcm = m * n / gcd(m,n)
}//lcm



int main(){
    llong N;
    cin >> N;
    llong A[N],T[N];
    llong nowt,nowa;
    llong bait=1,baia=1;
    for(int i=0;i<N;i++){
        scanf("%lld %lld",&T[i],&A[i]);
    }
    nowt=T[0];
    nowa=A[0];
    llong net,nea;

    for(int i=1;i<N;i++){
        net=(nowt%T[i]==0?nowt/T[i]:nowt/T[i]+1);
        nea=(nowa%A[i]==0?nowa/A[i]:nowa/A[i]+1);

        llong kitei=max(net,nea);
        nowt=kitei*T[i];
        nowa=kitei*A[i];
        //cout <<nowt<<" "<<nowa<<endl;
    }

    
    cout <<nowt+nowa<<endl;

    
    
    return 0;
}

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

void solve() {
	int n;
	cin >> n;
	vector<int> a(n);
	// i - j == a[i] + a[j]
	// i - a[i] = j + a[j]
	map<int, int> cnt;
	long long ways = 0;
	for (int i = 0; i < n; i++) {
		cin >> a[i];
		if (cnt.count(i - a[i])) ways += cnt[i - a[i]];
		cnt[i + a[i]]++;
	}
	cout << ways << "\n";
}

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

Measured memory_bytes: 13416
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
const double PI = acos(-1);
const ll MOD = 1000000007;
using Graph = vector<vector<int>>;

int main() {
  int N,M; cin >> N >> M;
  Graph G(N, vector<int>(N,0));
  rep(i,M) {
    int a,b; cin >> a >> b;
    a--; b--;
    G[a][b] = 1;
    G[b][a] = 1;
  }

  vector<int> num(N);
  rep(i,N) num[i] = i;
  int count = 0;
  do {
    bool can = true;
    if (num[0] != 0) can = false;
    for (int i = 1; i < N; i++) {
      if (G[num[i]][num[i-1]] == 0) can = false;
    }
    if (can) count++;
  } while (next_permutation(num.begin(),num.end()));

  cout << count << endl;
}

Measured memory_bytes: 256
N, T = map(int, input().split())
CT = [list(map(int, input().split())) for i in range(N)]

min = 9999
for i in range(N):
  if CT[i][1] <= T and CT[i][0] < min:
    min = CT[i][0]

if min == 9999:
  print('TLE')
else:
  print(min)

Measured memory_bytes: 3064
class Group:
    
    def __init__(self, a, b):
        self.member = {a, b}
        self.n = 2
        
        
N, M = list(map(int, input().split()))
AB = [list(map(int, input().split())) for _ in range(M)]

d = {}
ans = [None] * M
ans[-1] = (N - 1) * N // 2
pre = ans[-1]
count = -2
for a, b in AB[:0:-1]:
    now = pre
    if a in d:
        if b in d:
            group1, group2 = d[a], d[b]
            if group1 is group2:
                pass
            else:
                if group1.n < group2.n:
                    group1, group2 = group2, group1
                now -= group1.n * group2.n
                group1.member |= group2.member
                group1.n += group2.n
                for x in group2.member:
                    d[x] = group1
        else:
            group = d[a]
            now -= group.n
            group.member.add(b)
            group.n += 1
            d[b] = group
    elif b in d:
        group = d[b]
        now -= group.n
        group.member.add(a)
        group.n += 1
        d[a] = group
    else:
        group = Group(a, b)
        d[a] = group
        d[b] = group
        now -= 1
    ans[count] = now
    pre = now
    count -= 1
print("\n".join(map(str, ans)))

Measured memory_bytes: 61356
#include <stdbool.h>
#include <stdbool.h>
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

typedef struct counting_sort_t *counting_sort_t;

struct counting_sort_t {
  uint32_t *counting_arr;
  size_t counting_arr_len;
};

static void free_counting_sort_object(counting_sort_t c)
{
  if (c != NULL) {
    free(c->counting_arr);
  }
  free(c);
}

counting_sort_t counting_sort_create(size_t n)
{
  counting_sort_t c = (counting_sort_t)malloc(sizeof(counting_sort_t));
  if (c == NULL) goto err;

  c->counting_arr_len = n;
  c->counting_arr = (uint32_t *)calloc(sizeof(uint32_t), n);
  if (c->counting_arr == NULL) goto err;

  return c;

err:
  free_counting_sort_object(c);
  perror("malloc error");
  exit(1);
}

void counting_sort_destroy(counting_sort_t c)
{
  free_counting_sort_object(c);
}

static void count_incidence(counting_sort_t c, uint64_t data[], size_t len)
{
  uint32_t i;
  for (i = 0; i < len; i++) {
    c->counting_arr[data[i]]++;
  }
}

static void calc_cumulative_sum(counting_sort_t c)
{
  uint32_t i;
  for (i = 1; i < c->counting_arr_len; i++) {
    c->counting_arr[i] += c->counting_arr[i - 1];
  }
}

static bool copy_array(uint64_t data[], size_t len, uint64_t **p)
{
  *p = (uint64_t *)malloc(sizeof(data[0]) * len);
  if (*p == NULL) return false;

  memcpy(*p, data, sizeof(data[0]) * len);

  return true;
}

void counting_sort(counting_sort_t c, uint64_t data[], size_t len)
{
  count_incidence(c, data, len);

  calc_cumulative_sum(c);

  uint64_t *aux;
  if (!copy_array(data, len, &aux)) goto err;

  int32_t i;
  for (i = len - 1; 0 <= i; i--) {
    uint32_t index = c->counting_arr[aux[i]];
    data[index - 1] = aux[i];
    c->counting_arr[aux[i]]--;
  }

  return;
err:
  counting_sort_destroy(c);
  perror("malloc error");
  exit(1);
}

#if !defined(TEST)
uint64_t data[2000000];
int32_t main(void)
{
  int32_t num;
  scanf("%d", &num);

  counting_sort_t c = counting_sort_create(10001);

  int32_t i;
  for (i = 0; i < num; i++) {
    uint64_t val;
    scanf("%ld", &val);
    data[i] = val;
  }

  counting_sort(c, data, num);

  for (i = 0; i < num; i++) {
    if (i != 0) printf(" ");
    printf("%lu", data[i]);
  }
  printf("\n");

  counting_sort_destroy(c);

  return 0;
}
#endif

Measured memory_bytes: 31924
#include <algorithm>
#include <iostream>
#include <limits>
#include <numeric>
#include <string>
#include <vector>
#include <set>

#define rep(i, x, n) for (int i = x; i < n; i++)
using namespace std;
const long long INF = 1LL << 60;

bool cont(vector<int> v, int k, int size)
{
    for (int i = 0; i < size; i++)
    {
        if (v[i] == k)
        {
            return true;
        }
    }
    return false;
}
int main()
{
    int X, N;
    cin >> X >> N;
    vector<int> p(N);
    rep(i, 0, N)
    {
        cin >> p[i];
    }
    rep(i, 0, 100)
    {
        int syo = X - i;
        int dai = X + i;
        if (!cont(p, syo, N))
        {
            cout << syo << endl;
            return 0;
        }
        else if (!cont(p, dai, N))
        {
            cout << dai << endl;
            return 0;
        }
    }
}

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

using namespace std;
using ll = long long;

int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n;
    string s;
    cin >> n >> s;
    vector<int> R(n+1), W(n+1);
    for (int i = 0; i < n; ++i) {
        R[i+1] = R[i] + int(s[i] == 'R');
        W[i+1] = W[i] + int(s[i] == 'W');
    }
    int an = n+11;
    for (int i = 0; i <= n; ++i) {
        // first i is 'R', n-i is 'W'
        int a = W[i];
        int b = R[n] - R[i];
        an = min(an, min(a, b) + abs(a-b));
    }
    cout << an << '\n';
    return 0;
}


Measured memory_bytes: 5188
#include "bits/stdc++.h"
using namespace std;
using ll = long long;
using P = pair<int, int>;
ll MOD = 1e9 + 7;

int main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	string S;
	cin >> S;
	sort(begin(S), end(S));
	S.erase(unique(begin(S), end(S)), end(S));
	if (S.size() == 1) cout << "No" << endl;
	else cout << "Yes" << endl;
}

Measured memory_bytes: 256
#include<stdio.h>
#include<vector>
#include<algorithm>
#include<math.h>
#include<stdlib.h>
using namespace std;
typedef long long ll;
vector<int>pat[100000];
bool flag[100000];
bool iscirc[100000];
vector<int>nowp;
vector<int>circ;
bool found;
void dfs(int node, int par)
{
	if (found)return;
	if (flag[node])
	{
		for (int i = nowp.size() - 1; i >= 0; i--)
		{
			circ.push_back(nowp[i]);
			iscirc[nowp[i]] = true;
			if (nowp[i] == node)break;
		}
		found = true;
		return;
	}
	flag[node] = true;
	nowp.push_back(node);
	for (int i = 0; i < pat[node].size(); i++)
	{
		if (pat[node][i] != par)dfs(pat[node][i], node);
	}
	nowp.pop_back();
}
ll ans = 0;
int get(int node)
{
	flag[node] = true;
	int s = 1;
	for (int i = 0; i < pat[node].size(); i++)
	{
		if (!iscirc[pat[node][i]] && !flag[pat[node][i]])s -= get(pat[node][i]);
	}
	if (!iscirc[node])ans += abs(s);
	return s;
}
void no()
{
	printf("-1\n");
	exit(0);
}
int main()
{
	int num, way;
	scanf("%d%d", &num, &way);
	for (int i = 0; i < way; i++)
	{
		int za, zb;
		scanf("%d%d", &za, &zb);
		za--, zb--;
		pat[za].push_back(zb);
		pat[zb].push_back(za);
	}
	if (way == num - 1)
	{
		int t = pat[0][0];
		iscirc[0] = iscirc[t] = true;
		circ.push_back(0);
		circ.push_back(t);
	}
	else dfs(0, -1);
	vector<int>r;
	fill(flag, flag + num, false);
	for (int i = 0; i < circ.size(); i++)r.push_back(get(circ[i]));
	if (r.size() % 2 == 0)
	{
		ll s1 = 0, s2 = 0;
		for (int i = 0; i < r.size(); i += 2)s1 += r[i], s2 += r[i + 1];
		if (s1 != s2)no();
		vector<int>z;
		int now = 0;
		for (int i = 0; i < r.size(); i++)
		{
			z.push_back((i & 1) ? now : -now);
			now = r[i] - now;
		}
		sort(z.begin(), z.end());
		int m = z[z.size() / 2];
		for (int i = 0; i < z.size(); i++)ans += abs(m - z[i]);
	}
	else
	{
		ll s = 0;
		for (int i = 0; i < r.size(); i++)s += r[i];
		if (s % 2 != 0)no();
		ll z = 0;
		for (int i = 0; i < r.size() - 2; i += 2)z += r[i];
		for (int i = 0; i < r.size(); i++)
		{
			ans += abs(s / 2 - z);
			z -= r[i * 2 % r.size()];
			z += r[(i * 2 + r.size() - 1) % r.size()];
		}
	}
	printf("%lld\n", ans);
}

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

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

typedef long long ll;

const int INF = 1 << 30;
const ll LLINF = 1LL << 60;

int mod = 1000000007;

int main(void){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int N; cin >> N;
    int cnt[N] = {};
    ll pow2[N] = {};
    pow2[0] = 1;
    rep(i, N) pow2[i+1] = (pow2[i]*2) % mod;
    //N-1, N-3, ... 1or0が2つずつあるはず(それぞれNが偶数,奇数の時)
    rep(i, N){
        int a; cin >> a;
        cnt[a]++;
    }

    if(N % 2){
        //0,2,...,N-1
        if(cnt[0] == 1){
            bool ok = true;
            for(int i = 2; i <= N-1; i+=2) if(cnt[i] != 2) ok = false;
            if(ok) cout << pow2[(N-1)/2] << endl;
            else cout << 0 << endl;
        }
        else cout << 0 << endl;
    }
    else{
        bool ok = true;
        for(int i = 1; i <= N-1; i+=2) if(cnt[i] != 2) ok = false;
        if(ok) cout << pow2[N/2] << endl;
        else cout << 0 << endl;
    }
    return 0;
}

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

#define FOR(i,a,b) for (int i=(a);i<(b);i++)
#define RFOR(i,a,b) for (int i=(b)-1;i>=(a);i--)
#define REP(i,n) for (int i=0;i<(n);i++)
#define RREP(i,n) for (int i=(n)-1;i>=0;i--)
#define ALL(a) (a).begin(),(a).end()
const int INF = INT_MAX/3;
const double EPS = 1e-14;

template<typename U, typename T>
void chmin(U &x, T y) { x = min(x, y); }

template<typename U, typename T>
void chmax(U &x, T y) { x = max(x, y); }

typedef long long int lli;
typedef long double ld;

typedef tuple<int, int, int> Dat;
typedef int hand; // Mamoru, Tameru, Kougekida

int charge(int a, int hand) {
  if (a < 5 && hand == 1) {
    return a + 1 ;
  } else if (hand == 2) {
    return 0;
  } else {
    return a;
  }
}

Dat move(Dat d, hand ha, hand hb) {
  if (get<0>(d) != 0) return d;
  int a = get<1>(d), b = get<2>(d);
  if (ha == 2 and a == 0 and !(hb == 2 and b == 0)) return Dat(-1, 0, 0);
  if (hb == 2 and b == 0 and !(ha == 2 and a == 0)) return Dat(1, 0, 0);
  if (ha == 2 and hb == 2 and a > b) return Dat(1, 0, 0);
  if (ha == 2 and hb == 2 and a < b) return Dat(-1, 0, 0);
  if (ha == 1 and hb == 2) return Dat(-1, 0, 0);
  if (ha == 2 and hb == 1) return Dat(1, 0, 0);
  if (ha == 0 and hb == 2 and b == 5) return Dat(-1, 0, 0);
  if (ha == 2 and hb == 0 and a == 5) return Dat(1, 0, 0);
  a = charge(a, ha), b = charge(b, hb);
  return Dat(0, a, b);
}

int to_i(string s) {
  if (s == "mamoru") return 0;
  if (s == "tameru") return 1;
  else return 2;
}

int main() {
  int k;
  cin >> k;
  vector<int> I_(k), N_(k);
  REP(i, k) {
    string is; cin >> is;
    I_[i] = to_i(is);
  }
  REP(i, k) {
    string na; cin >> na;
    N_[i] = to_i(na);
  }

  Dat d(0, 0, 0);
  REP(i, k) {
    d = move(d, I_[i], N_[i]);
  }
  int sh = get<0>(d);
  if (sh == 0) cout << "Hikiwake-kun" << endl;
  if (sh == 1) cout << "Isono-kun" << endl;
  if (sh == -1) cout << "Nakajima-kun" << endl;
  return 0;
}

Measured memory_bytes: 1216
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        String today = sc.next();
        List<String> week = new ArrayList<>(Arrays.asList("SAT", "FRI", "THU", "WED", "TUE", "MON", "SUN"));

        System.out.println(week.indexOf(today) + 1);

    }
}


Measured memory_bytes: 21844
#include<iostream>

using namespace std;

int main() {
	
	string s, t;

	cin >> s;
	cin >> t;

	int sl = s.size();
	int tl = t.size();

	int i;

	bool res = true;

	if ((sl + 1) != tl) res = false;

	for (i = 0; i < sl; i++) {
		if (s[i] != t[i]) res = false;
}

	if (res)cout << "Yes";
	else cout << "No";

	return 0;

}

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

#define trace(...) __f( #__VA_ARGS__ , __VA_ARGS__ )
template <typename Arg1>
void __f( const char* name , Arg1&& arg1 ) {
        cerr << name << " : " << arg1 << "\n";
}
template <typename Arg1, typename... Args>
void __f( const char* na , Arg1&& arg1 , Args&&... args ) {
        const char* c = strchr( na + 1 , ',' );
        cerr.write( na , c - na ) << " : " << arg1 << " , ";
        __f( c + 1 , args... );
}
#define endl "\n"
#define all(V) V.begin(),V.end()
#define Unique(V) sort(all(V)),V.erase(unique(all(V)),V.end())
#define IO ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
typedef long long int LL;
typedef pair <int,int> pii;
const int MOD = 1e9 + 7;
const int inf = 1e9;
const double EPS = 1e-9;
const double PI = acos(-1.0);
const long long INF = 1e18;
const int N = 1e5 + 5;

int main( ) {
        IO;
        #ifdef LOCAL
            //freopen( "input.txt" , "r" , stdin );
        #endif // LOCAL
        string s;
        cin >> s;
        map <char,int> cnt;
        for( int i = 0; i < s.size(); i++ ) cnt[ s[i] ]++;
        if( cnt.size() != 2 ) return cout << "No" << endl,0;
        for( auto x : cnt ) {
                if( x.second != 2 ) return cout << "No" << endl,0;
        }
        cout << "Yes" << endl;
        return 0;
}










Measured memory_bytes: 256
import math

if __name__ == '__main__':
    N = int(input())
    A = list(map(int, input().split(' ')))

    count = 0
    currentHeight = A[0]

    for i in range(1, len(A)):
        if A[i] < A[i-1]:
            dai = A[i-1] - A[i]
            A[i] += dai
            count += dai

    print(count)


Measured memory_bytes: 33020
function main(input) {
  const lines = input.split('\n');
  lines.pop();
  lines.forEach(line => {
    const splited = line.split(' ');
    console.log(fn(
      parseInt(splited[0], 10),
      parseInt(splited[1], 10)
    ));
  });
}

function fn(a, b) {
  const amount = a + b;
  if (amount % 2 === 0 ) {
    return (amount) / 2;
  }
  return 'IMPOSSIBLE'
}

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


Measured memory_bytes: 11468
#include<stdio.h>


int main(void)
{
  while(1){
    int matrix[11][11]={0};
    int i,j;
    int number;
  
  scanf("%d",&number);
  if( number==0 )break;
  if( number>10 )break;
  if( number<0 )break;
 
  for( i=0; i<number; i++ ){
    for( j=0; j<number; j++ ){
      scanf("%d",&matrix[i][j]);
    }
  }
  for( i=0; i<number; i++ ){
    for( j=0; j<number; j++ ){
      matrix[i][number]+=matrix[i][j];
      matrix[number][j]+=matrix[i][j];
    }
  }
 
  for( i=0; i<number; i++ ){
   matrix[number][number]+=matrix[i][number];
  }
 
  for( i=0; i<number+1; i++ ){
    for( j=0; j<number+1; j++ ){
      printf("%5d",matrix[i][j]);
    }
    puts("");
  }
}
  return 0;
}

Measured memory_bytes: 620
INT = lambda: int(input())
INTM = lambda: map(int,input().split())
STRM = lambda: map(str,input().split())
STR = lambda: str(input())
LIST = lambda: list(map(int,input().split()))
LISTS = lambda: list(map(str,input().split()))
def do():
    a,b,c=INTM()
    if a+b>=c:
        print('Yes')
    else:
        print('No')
if __name__ == '__main__':
    do()

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

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

long long MOD = 1000000000 + 7;

int main(){
  cout << setprecision(10);

  string S;
  cin >> S;
  int ans = 0;
  for(char c: S){
    if(c == '1'){
      ans++;
    }
  }
  cout << ans << endl;
}


Measured memory_bytes: 256
#include<stdio.h>
#include<stdlib.h>
#include<iostream>
#include<string>
#include<algorithm>
#include<vector> 
#include<limits>
#include<numeric>
#include<type_traits>
#include<math.h>
#include<fstream>
#include<set>
#include<queue>
using namespace std;
typedef long long ll;

const ll MOD = 1e9 + 7; 

#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define repi(i,a,b) for(int i = (int)(a); i < (int)(b); i++)
#define out(str) cout << str << endl
#define ALL(a) (a).begin(),(a).end()
#define INF_INT (1<<30)
#define INF_LL (1ll<<62)

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; }

int num[3][3],N,b;
bool hit[3][3];


int main(){
    rep(i,3){
        rep(j,3){
            cin>>num[i][j];
            hit[i][j]=false;
        }
    }
    cin>>N;
    rep(i,N){
        cin>>b;
        rep(j,3){
            rep(k,3){
                if(num[j][k]==b)hit[j][k]=true;
            }
        }
    }
    bool ans = false;
    rep(i,3){
        if(hit[i][0]&&hit[i][1]&&hit[i][2])ans=true;
        if(hit[0][i]&&hit[1][i]&&hit[2][i])ans=true;
        if(hit[0][0]&&hit[1][1]&&hit[2][2])ans=true;
        if(hit[2][0]&&hit[1][1]&&hit[0][2])ans=true;
    }
    if(ans)out("Yes");
    else out("No");
}

Measured memory_bytes: 256
process.stdin.resume();
process.stdin.setEncoding('utf8');

var g_input = '';
process.stdin.on('data', function(chunk) {
    g_input += chunk;
});

process.stdin.on('end', function() {
    Main(g_input.split(/\r?\n/));
});

function Main(input) {

    var ab = input[0].split(' ');
    var a = parseInt(ab[0], 10);
    var b = parseInt(ab[1], 10);

    var ans = 0;
    if (a <= b) {
        ans = a;
    }
    else {
        ans = a - 1;
    }

    console.log(ans);

    return 0;
}


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

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    
    int n, k;
    cin >> n >> k;

    vector<int> h(n), dp(n, 0x3f3f3f3f);
    for (int i = 0; i < n; i++)
        cin >> h[i];

    dp[0] = 0;
    for (int i = 1; i < n; i++){
        for (int j = 1; j <= k && i - j >= 0; j++)
            dp[i] = min(dp[i], dp[i - j] + abs(h[i] - h[i - j]));
    }

    cout << dp[n - 1] << '\n';

    return 0;
}


Measured memory_bytes: 3996
n = int(input())
ga, sa, ba = map(int, input().split())
gb, sb, bb = map(int, input().split())

dp1 = [0] * (n + 1)
if n > 5001:
    for i in range(1, 5001):
        feat = [i]
        if i - ga >= 0:
            feat.append(dp1[i-ga]+gb)
        if i - sa >= 0:
            feat.append(dp1[i-sa]+sb)
        if i - ba >= 0:
            feat.append(dp1[i-ba]+bb)
        dp[i] = max(feat)
    for i in range(5001, n+1):
        dp1[i] = max(i, dp1[i-ga]+gb, dp1[i-sa]+sb, dp1[i-ba]+bb)
else:
    for i in range(1, n+1):
        feat = [i]
        if i - ga >= 0:
            feat.append(dp1[i-ga]+gb)
        if i - sa >= 0:
            feat.append(dp1[i-sa]+sb)
        if i - ba >= 0:
            feat.append(dp1[i-ba]+bb)
        dp1[i] = max(feat)

B = dp1[-1]
dp2 = [0] * (B + 1)
if B > 5001:
    for i in range(1, 5001):
        feat = [i]
        if i - gb >= 0:
            feat.append(dp2[i-gb]+ga)
        if i - sb >= 0:
            feat.append(dp2[i-sb]+sa)
        if i - bb >= 0:
            feat.append(dp2[i-bb]+ba)
        dp2[i] = max(feat)

    for i in range(5001, B+1):
        dp2[i] = max(i, dp2[i-gb]+ga, dp2[i-sb]+sa, dp2[i-bb]+ba)
else:
    for i in range(1, B+1):
        feat = [i]
        if i - gb >= 0:
            feat.append(dp2[i-gb]+ga)
        if i - sb >= 0:
            feat.append(dp2[i-sb]+sa)
        if i - bb >= 0:
            feat.append(dp2[i-bb]+ba)
        dp2[i] = max(feat)

print(dp2[-1])


Measured memory_bytes: 230024
#include<iostream>

int main()
{
	int sum = 0;

	for( int i = 0; i != 4; ++i )
	{
		int a;
		std::cin >> a;
		sum += a;
	}

	std::cout << sum / 60 << std::endl;
	std::cout << sum % 60 << std::endl;

	return 0;
}

Measured memory_bytes: 1160
#include <bits/stdc++.h>
using namespace std;
#define REP(i,a) for(int i = 0; i < (a); i++)
typedef long long ll;
typedef pair<int, int> P;
const int INF = 1e9;
const int MOD = 1e9 + 7;
#define MAX 100000

bool isprime[MAX + 1];

int eratos(int n){
	for(int i = 0; i <= n; i++)isprime[i] = true;
	isprime[0] = isprime[1] = false;
	for(int i = 2; i * i <= n; i++){
		if(isprime[i]){
			int j = i + i;
			while(j <= n){
				isprime[j] = false;
				j = j + i;
			}
		}
	}
}

int main(){
	int q;
	cin >> q;
	int l[q],r[q];
	REP(i,q){
		cin >> l[i] >> r[i];
		r[i]++;
	}
	int sum = 0,s[MAX + 1];
	eratos(MAX);
	for(int n = 1; n <= MAX; n++){
		s[n] = sum;
		if(n % 2 == 1 && isprime[n] && isprime[(n + 1) / 2]) sum++;
	}
	REP(i,q) cout << s[r[i]] - s[l[i]] << endl;
}

Measured memory_bytes: 1920
#include <iostream>
#include <string>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <functional>
#include <map>
#include <set>

using namespace std;

typedef long long i64;
typedef i64 int_t;
typedef vector<int_t> vi;
typedef vector<vi> vvi;

typedef pair<int_t, int_t> pi;

#define tr(c, i) for(auto i = (c).begin(); i != (c).end(); i++)
#define pb push_back
#define sz(a) i64((a).size())
#define all(c) (c).begin(), (c).end()
#define REP(s, e, i) for(i=(s); i < (e); ++i)

int main(int argc, char *argv[]) {
  string S;
  getline(cin, S);

  reverse(all(S));
  i64 i;
  i64 ans1 = 0, ans2 = -1;
  REP(0, sz(S), i) {
    i64 d = S[i] - '0';

    i64 ans1_new = -1, ans2_new = -1;
    // no co
    if(ans1 != -1)
      ans1_new = ans1 + d;
    ans2_new = ans1 + 10 - d;

    // co
    if(ans2 != -1) {
      if(d != 9) {
	ans1_new = min(ans1_new, ans2 + d + 1);
      }
      ans2_new = min(ans2_new, ans2 + 9 - d);
    }

    ans1 = ans1_new;
    ans2 = ans2_new;
  }
  
  ans2 += 1;
  
  cout << min(ans1, ans2) << endl;

  return 0;
}


Measured memory_bytes: 1412
#include <bits/stdc++.h>
#define all(vec) vec.begin(),vec.end()
#define mp make_pair
using namespace std;
using ll=long long;
using P=pair<int,int>;
const ll INF=1LL<<30;
const ll LINF=1LL<<61;
const double eps=1e-9;
const ll MOD=1e9+7;
int main(){
    ll a,b,c,k;cin>>a>>b>>c>>k;
    if(k%2){
        cout<<b-a<<endl;
    }else{
        cout<<a-b<<endl;
    }
}


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

#define rep(i,p) for(int i=1;i<=p;i++)
#define ll long long

using namespace std;

int main(){

	string A;
	ll int N;
	cin >> N >> A;
 	ll int counter;
	counter =0;

	for (int i=0;i<N-2;i++){
		if(A[i] == 'A' && A[i+1] == 'B' && A[i+2] == 'C'){
			counter += 1;
		}
	}
	cout << counter;










	return 0;

}



Measured memory_bytes: 256
#include <stdio.h>
int main (void) {
	char s[10];
	int r = 0;
	gets(s);
	for (int i = 0; i < 4; i++) {
		if (s[i] == '2') {
			r++;
		}
	}
	printf("%d\n", r);
	return 0;
}

Measured memory_bytes: 128
#include<iostream>
#include<string>
using namespace std;
int main(){
  string str;
  while(getline(cin,str)){
    for(int i=0; i<str.size(); i++){
      if(str[i] >= 'a' && str[i] <= 'z')
	str[i] += ('A' - 'a');
    }
    cout << str << endl;
  }
}

Measured memory_bytes: 0
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<bitset>
#include<set>
#include<map>
#include<stack>
#include<queue>
#include<deque>
#include<iomanip>
#include<math.h>
using namespace std;

#define repr(i, a, b) for (int i = (int)(a); i < (int)(b); i++)
#define rep(i, n) repr(i, 0, n)
#define INF 2e9
#define MOD 1000000007
#define LINF (long long)4e18

using ll = long long;
using Pi = pair<int,int>;
using Pl = pair<ll,ll>;


int main(){
    string S; cin >> S;
    reverse(S.begin(),S.end());
    int N = S.size();
    ll dp[100010][13];
    rep(i,N)rep(j,13){
        dp[i][j] = 0;
    }
    if(S[0] != '?'){
        dp[0][S[0]-'0'] = 1;
    }
    else{
        rep(i,10){
            dp[0][i] = 1;
        }
    }
    int now = 10;
    rep(i,N-1){
        if(S[i+1] != '?'){
            rep(j,13){
                dp[i+1][(j+(S[i+1]-'0')*now)%13] += dp[i][j];
                dp[i+1][(j+(S[i+1]-'0')*now)%13] %= MOD;
            }
        }
        else{
            rep(j,13){
                rep(k,10){
                    dp[i+1][(j+k*now)%13] += dp[i][j];
                    dp[i+1][(j+k*now)%13] %= MOD;
                }
            }
        }
        now *= 10;
        now %= 13;
    }
    cout << dp[N-1][5] << endl;
}


Measured memory_bytes: 10624
#if !defined(__clang__) && defined(__GNUC__)
#include <bits/stdc++.h>
#else
#include <cstdlib>
#include <climits>
#include <iostream>
#include <cstdint>
#include <vector>
#include <string>
#include <complex>
#include <bitset>
#include <queue>
#include <deque>
#include <stack>
#include <utility>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <regex>
#endif //  !defined(__clang__) && defined(__GNUG__)
#include <boost/lexical_cast.hpp>
#include <boost/algorithm/string.hpp>
#include <boost/multi_array.hpp>
#include <boost/optional.hpp>
#include <boost/math/common_factor_rt.hpp>

using namespace std;



int main()
{
    size_t N;
    std::cin >> N;

    std::vector<int64_t> P(5);

    for (size_t i = 0; i < N; ++i) {
        std::string s;
        std::cin >> s;

        switch (s[0]) {
        case 'M':
            P[0]++;
            break;
        case 'A':
            P[1]++;
            break;
        case 'R':
            P[2]++;
            break;
        case 'C':
            P[3]++;
            break;
        case 'H':
            P[4]++;
            break;
        default:
            break;
        }
    }

    int64_t count = 0;
    // MAR--
    count += P[0]*P[1]*P[2];
    // MA-C-
    count += P[0]*P[1]*P[3];
    // MA--H
    count += P[0]*P[1]*P[4];
    // M-RC-
    count += P[0]*P[2]*P[3];
    // M-R-H
    count += P[0]*P[2]*P[4];
    // M--CH
    count += P[0]*P[3]*P[4];
    // -ARC-
    count += P[1]*P[2]*P[3];
    // -AR-H
    count += P[1]*P[2]*P[4];
    // -A-CH
    count += P[1]*P[3]*P[4];
    // --RCH
    count += P[2]*P[3]*P[4];

    std::cout << count << std::endl;

    return 0;
}


Measured memory_bytes: 256
/*
	Bakul Gaur (caesar1551)
*/
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define PrePro ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define fr(i,n) for(ll i = 0; i < n; i++)
#define fre(i,a,b) for(ll i = a; i <= b; i++)
#define fb(i,n) for(ll i = n; i >= 0; i--)
#define fbe(i,a,b) for(ll i = a; i >= b; i--)
#define umap(x,y) unordered_map<x,y>
#define uset(x) unordered_set<x>
#define vv(x) vector<x>
#define pp(x,y) pair<x,y>
#define prar(a,n) fr(i,n){cout << a[i] << " ";}
#define inar(a,n) fr(i,n){cin >> a[i];}
#define mk make_pair
#define pb push_back
#define ff first
#define ss second
#define endl "\n"
#define mod 1000000007
#define MAX 1000001
inline ll gcd(ll a, ll b){
	if(b == 0){
		return a;
	}
	return gcd(b,a%b);
}
inline ll pwr(ll a, ll b, ll modulo = mod){
	if(a == 0 && b == 0){
		return 0;
	}
	ll ans = 1;
	while(b > 0){
		if(b&1){
			ans = ((ans%modulo) * (a%modulo))%modulo;
		}
		b >>= 1;
		a = ((a%modulo) * (a%modulo))%modulo;
	}
	return (ans+modulo)%modulo;
}
inline ll modInverse(ll a, ll p){
	// Only if p is prime.
	return pwr(a,p-2,p);
}



/* #############
   START SOLVING 
   ############# */

ll dfs(vv(vv(char)) &arr, vv(vv(ll)) &dp, ll &n, ll &m, ll i, ll j){
	if(i == n-1 && j == m-1){
		return dp[i][j] = 1%mod;
	}
	if(dp[i][j] != -1){
		return dp[i][j]%mod;
	}
	ll op1 = 0, op2 = 0;
	if(i+1 < n && arr[i+1][j] == '.'){
		op1 = dfs(arr,dp,n,m,i+1,j);
	}
	if(j+1 < m && arr[i][j+1] == '.'){
		op2 = dfs(arr,dp,n,m,i,j+1);
	}
	return dp[i][j] = ((op1%mod)+(op2%mod))%mod;
}

void solve(){
	ll n, m;
	cin >> n >> m;
	vv(vv(char)) arr(n,vv(char)(m));
	fr(j,n){
		inar(arr[j],m);
	}
	vv(vv(ll)) dp(n,vv(ll)(m,-1));
	cout << dfs(arr,dp,n,m,0,0)%mod << endl;
}
int main(){
	PrePro
	/* #ifndef ONLINE_JUDGE
		freopen("input.txt","r",stdin);
		freopen("output.txt","w",stdout);
	#endif */
    ll t = 1;
    // cin >> t;
    fr(i,t){
    	// cout << "Case #" << i+1 << ": ";
    	solve();
    	// cout << endl;
    }
	return 0;
}

Measured memory_bytes: 12156
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int MOD = 1000000007;
//cout << setprecision(20) << 

int main() {
    ll x; cin >> x;
    if (x == 7 || x == 5 || x == 3) {
        cout << "YES" << endl;
    }
    else {
        cout << "NO" << endl;
    }
}

Measured memory_bytes: 3628