akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
#include<cmath>
#include<cstring>
using namespace std;

int main(){
	char ta[1000];
	int a,b;

	while(true){
	for(int i=0;i<3;i++){
	cin>>ta;
	if(strcmp(ta,"0")==0)return 0;
	a=b=0;
		for(int j=1;ta[j]!='\0';j++){
		(ta[j]=='A')?a++:b++;
		}
		(a>b)?a++:b++;
		cout<<a<<" "<<b<<endl;
	}
	}


	return 0;
}

Measured memory_bytes: 1140
n, m = gets.split.map(&:to_i)
ab = []
cd = []

n.times { ab << gets.split.map(&:to_i) }
m.times { cd << gets.split.map(&:to_i) }

ab.each do |ab_|
  tmp = 1 << 31
  ans = 0
  cd.each_with_index do |cd_, i|
    now = (ab_[0] - cd_[0]).abs + (ab_[1] - cd_[1]).abs
    if now < tmp
      ans = i + 1
      tmp = now
    end
  end
  p ans
end

Measured memory_bytes: 1788
using System;
using System.Collections.Generic;
using static AtCoderer.Exter;
using static System.Console;
using static System.Math;
using System.Linq;

namespace AtCoderer
{

    public class App
    {
        public static void Main(string[] args)
        {
            var n = readarr;
            cout = (n[0] * 3 + n[1])/2;
        }
    }
    public static class Exter
    {
        public static void rep(int loop, Action<int> act)
        {
            for (int i = 0; i < loop; i++)
                act(i);
        }
        public static int ToInt(this string v) => int.Parse(v);
        public static int Max(params int[] p) => p.Max();
        public static long Max(params long[] p) => p.Max();
        public static int Min(params int[] p) => p.Min();
        public static long Min(params long[] p) => p.Min();
        public static int Gcd(int a, int b) => a > b ? GcdRecursive(a, b) : GcdRecursive(b, a);
        private static int GcdRecursive(int a, int b) => b == 0 ? a : GcdRecursive(b, a % b);
        public static object cout
        {
            set
            {
                Console.Write(value.ToString());
                Console.WriteLine();

            }
        }
        public static void ToCout<t>(this IEnumerable<t> v)
        {
            cout = string.Join(",", v);
        }
        public static int[] readarr
        {
            get
            {
                return Console.ReadLine().Split().Select(s => int.Parse(s)).ToArray();
            }
        }
        public class UnionFind
        {
            public int[] Parent;
            private int GetRoot(int v)
            {
                if (Parent[v] == v)
                    return v;
                else
                    return Parent[v] = GetRoot(Parent[v]);
            }
            public UnionFind(int size)
            {
                Parent = Enumerable.Range(0, size).ToArray();
            }
            public bool AreGrouped(int a, int b)
            {
                return GetRoot(a) == GetRoot(b);
            }
            public void Connect(int a, int b)
            {
                a = GetRoot(a);
                b = GetRoot(b);
                if (a == b) return;
                else Parent[a] = b;
            }
            public int GetGroupSize(int a)
            {
                return 0;
            }
        }
    }
}


Measured memory_bytes: 11348
#define ENABLE_DEBUG 1
// Kana's kitchen {{{
#include<bits/stdc++.h>
#define ALL(v) std::begin(v),std::end(v)
#define LOOP(k) for(i64 ngtkana_is_a_genius=0; ngtkana_is_a_genius<(i64)k; ngtkana_is_a_genius++)

using i32 = std::int_least32_t;
using i64 = std::int_least64_t;
using u32 = std::uint_least32_t;
using u64 = std::uint_least64_t;
using usize = std::size_t;

template <class T> using vec = std::vector<T>;
template <class T> using numr = std::numeric_limits<T>;

#ifdef NGTKANA
#include<debug.hpp>
#else
#define DEBUG(...)(void)0
#endif
/*}}}*/
auto cmn=[](auto&x,auto y){if(x>y){x=y;return true;}return false;};
int main(){
    std::cin.tie(nullptr);
    std::ios::sync_with_stdio(false);
    std::cout << std::setprecision(15) << std::fixed;

    i32 x, y;
    std::cin >> x >> y;

    if (x <= 0 && 0 <= y) {
        std::cout << "Zero" << '\n';
        return 0;
    }

    y++;

    cmn(x, 0);
    cmn(y, 0);
    std::cout << ((y-x)%2 ? "Negative" : "Positive") << '\n';
}


Measured memory_bytes: 256
#include<cstdio>
using namespace std;
int main()
{
	int i,j;
	int n;
	while(scanf("%d",&n)!=EOF)
	{
		int ans;
		if(n%2==0)
		{
			ans=n/2-1;
		}
		else
		{
			ans=n/2;
		}
		printf("%d\n",ans);
	}
	return 0;
 } 

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

int main(){
  int n,sum=0;
  cin>>n;
  vector<int>a(n);
  for(int i=0;i<n;i++){
    cin>>a.at(i);
    sum=sum+a.at(i);
  }
  sort(a.begin(),a.end());
  sum=sum-a.at(n-1);
  if(a.at(n-1)<sum)cout <<"Yes";
  else cout <<"No";

}

Measured memory_bytes: 3608
#include "iostream"
#include "algorithm"
#include "string"
#include "vector"
#include "cmath"
#include "bitset"
#define lp(n) for (int i = 0; i < n; i++)
#define lop(n,i) for (int i = 0; i < n; i++)
#define mod 1000000007
#define ll long long int
#define sp ' '
#define intmax 2147483647
#define intmin –2147483648
#define llmax 9223372036854775807
#define llmin -9223372036854775808
using namespace std;

int n;
ll a[200000], mn;

ll gcd(ll x, ll y) {
	if (y == 0) return x;
	return gcd(y, x%y);
}
ll lcm(ll x, ll y) {
	ll g = gcd(x, y);
	return x / g * y;
}

int main(){
	cin >> n;
	lp(n) {
		cin >> a[i];
		if (i >= 1)
			a[i] += a[i - 1];
	}
	mn = llmax;

	lp(n-1) {
		mn = min(mn, abs(a[n - 1] - a[i] - a[i]));
	}
	cout << mn << endl;
	return 0;
}

Measured memory_bytes: 1792
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {

        Scanner sc = new Scanner(System.in);

        int A = sc.nextInt();
        int P = sc.nextInt();
        sc.close();

        int tmp=0;

        tmp = A * 3 + P;

        System .out.println(tmp / 2);

    }
}

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

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

	int ans, ans1 = 0, ans2 = 0;

	if (n != 1) {
		for (int i = 1; i < n; i++) {
			ans1 += i;
		}
	}
	else {
		ans1 = 0;
	}

	if (m != 1) {
		for (int i = 1; i < m; i++) {
			ans2 += i;
		}
	}
	else {
		ans2 = 0;
	}

	cout << ans1+ans2 << endl;

	return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;
public class Main { 
    public static void main(String[] args){
        Scanner scan = new java.util.Scanner(System.in);
        int a = scan.nextInt();
        int b = scan.nextInt();
        int c = scan.nextInt();
        int temp1, temp2, temp3;
        if(a > c){
            temp1 = a;
            a = c;
            c = temp1;
        }
        if(b > c){
            temp2 = b;
            b = c;
            c = temp2;
        }
        if(a > b){
            temp3 = a;
            a = b;
            b = temp3;
        }
        System.out.println(a + " " + b + " " + c);
    }
}

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

using namespace std;

const int INF = 1e9;
const int N = 1e5;
const int MOD = 1e9 + 7;

const double PI = acos(-1);

long long fact_pow (long long n, int k) {
    long long res = 0;
    while (n) {
        n /= k;
        res += n;
    }
    return res;
}

int main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0), cout.tie(0);
    long long n;
    cin >> n;
    if (n & 1) {
        cout << 0;
        return 0;
    }
    n /= 2;
    long long ans = fact_pow(n, 5);
    cout << ans;
}

Measured memory_bytes: 256
import java.util.*;

public class Main {

    static final int MOD = 1000000007;

    public static void main(String[] args) {

        Scanner sc = new Scanner(System.in);
        long n = sc.nextLong();
        long min = Long.MAX_VALUE;
        for(int i=0;i<5;i++)min = Math.min(min,sc.nextLong());
        System.out.println((n%min==0?n/min:n/min+1)+4);




    }
}


Measured memory_bytes: 23764
#include <cstdio>

using namespace std;

int dp[103];

void init()
{
    int t = 2;
    for(int i = 0; i <= 100; i++)
    {
        if(i == t * 2)
        {
            t *= 2;
        }
        dp[i] = t;
    }
}

int main()
{
    int n;
    scanf("%d",&n);
    init();
    dp[1] = 1;
    printf("%d\n",dp[n]);
//    for(int i = 1 ; i <= 100 ; i ++)
//    printf("%d = %d\n",i,dp[i]);
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int a, b, c, d, e, k=0;
  cin >> a >> b >> c >> d >> e;
  
  if(a%10!=0)k=a%10;
  if(b%10!=0 && b%10<k)k=b%10;
  if(c%10!=0 && c%10<k)k=c%10;  
  if(d%10!=0 && d%10<k)k=d%10;
  if(e%10!=0 && e%10<k)k=e%10;
  if(k==0)k=10;
  
  while(a%10!=0)a++;
  while(b%10!=0)b++;
  while(c%10!=0)c++;
  while(d%10!=0)d++;
  while(e%10!=0)e++;
  
  cout << a+b+c+d+e-10+k;
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rrep(i, n) for (int i = (int)(n - 1); i >= 0; i--)
#define all(x) (x).begin(), (x).end()
#define sz(x) int(x.size())
#define get_unique(x) x.erase(unique(all(x)), x.end());
typedef long long ll;
typedef complex<double> Complex;
const int INF = 1e9;
const ll MOD = 1e9 + 7;
const ll LINF = 1e18;
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;
}
template <class T>
vector<T> make_vec(size_t a) {
    return vector<T>(a);
}
template <class T, class... Ts>
auto make_vec(size_t a, Ts... ts) {
    return vector<decltype(make_vec<T>(ts...))>(a, make_vec<T>(ts...));
}
struct UnionFind {
    vector<int> data;
    UnionFind(int size) : data(size, -1) {
    }
    int root(int x) {
        return (data[x] < 0) ? x : data[x] = root(data[x]);
    }
    bool unite(int x, int y) {
        x = root(x);
        y = root(y);
        if (x != y) {
            if (data[y] < data[x]) swap(x, y);
            data[x] += data[y];
            data[y] = x;
        }
        return x != y;
    }
    bool find(int x, int y) {
        return root(x) == root(y);
    }
    int size(int x) {
        return -data[root(x)];
    }
};
int main() {
    int n, k, l;
    cin >> n >> k >> l;
    UnionFind douro(n);
    while (k--) {
        int p, q;
        cin >> p >> q;
        p--;
        q--;
        douro.unite(p, q);
    }
    UnionFind train(n);
    while (l--) {
        int r, s;
        cin >> r >> s;
        r--;
        s--;
        train.unite(r, s);
    }
    map<pair<int, int>, int> mp;
    rep(i, n) {
        mp[{douro.root(i), train.root(i)}]++;
    }
    rep(i, n) {
        cout << mp[{douro.root(i), train.root(i)}] << " \n"[i == n - 1];
    }
}


Measured memory_bytes: 13568
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define all(x) (x).begin(),(x).end()
using namespace std;
using ll = long long;
using P = pair<int,int>;
template <class T> void chmin(T &a, const T &b) noexcept { if (b < a) a = b; }
template <class T> void chmax(T &a, const T &b) noexcept { if (a < b) a = b; }
void debug_out() { cout << "\n"; }
template <class T, class... Args>
void debug_out(const T &x, const Args &... args) { cout << x << " "; debug_out(args...);}
#ifdef _DEBUG
  #define debug(...) debug_out(__VA_ARGS__)
#else
  #define debug(...) 
#endif

const int mod = 1000000007;
// const int mod = 998244353;
struct mint {
  ll x;
  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;}
  bool operator==(const mint rhs) const { return x == rhs.x; }
  bool operator!=(const mint rhs) const { return x != rhs.x; }
  bool operator<(const mint &a) const{ return x<a.x;};
};
istream& operator>>(istream& is, mint& a) { return is >> a.x;}
ostream& operator<<(ostream& os, const mint& a) { return os << a.x;}


int main() {
  std::cin.tie(nullptr);
  std::ios_base::sync_with_stdio(false);
  std::cout << std::fixed << std::setprecision(15);
  int n,k;
  cin >> n >> k;
  vector<int> a(n);
  rep(i,n) cin >> a[i];
  vector<mint> dp(k+5,0);
  for (int i = 0; i <= a[0]; ++i) dp[i] = 1; //初期化
  for (int i = 1; i < n; ++i) {
    for (int j = 1; j <= k; ++j) { //累積和
      dp[j] += dp[j-1];
    }
    for (int j = k; j-(a[i]+1) >= 0; --j) {
      dp[j] -= dp[j-(a[i]+1)];
    }
  }
  cout << dp[k] << endl;
  return 0;
}

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

int main() {
    ll x;
    cin >> x;
    ll ans = 0;
    ans += x / 11;
    ans *= 2;
    x = x % 11;
    if(x > 6){
        ans += 2;
    }else if(x == 0){
    }else{
        ans += 1;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ff first
#define ss second
#define pb push_back
#define mp make_pair
typedef long long LL;
typedef unsigned long long uLL;
typedef pair<int,int> pii;

const int maxn=10;
#define getcode(i,j) (((i)>>(j))&1)
int n,c,l[maxn],ord[maxn];

int f[311][311][1<<5];
double calc()
{
	memset(f,0,sizeof(f));f[0][l[n]*n][0]=1;
	for(int i=0;i<c*n;i++)for(int j=0;j<=c*n;j++)for(int k=0;k<(1<<n-1);k++)if(f[i][j][k])
	{
//		printf("i= %d j= %d k= %d dp= %d\n",i,j,k,f[i][j][k]);
		if(i<j)f[i+1][j][k]+=f[i][j][k];
		int val=i%n;
		if(val==0||getcode(k,val-1))continue;
		f[i+1][min(c*n,max(j,i+l[ord[val]]*n))][k|(1<<val-1)]+=f[i][j][k];
	}
	
	double ret=f[c*n][c*n][(1<<n-1)-1];
	for(int i=1;i<n;i++)ret/=c;
	return ret;
}

int main()
{
	scanf("%d%d",&n,&c);
	for(int i=1;i<=n;i++)scanf("%d",l+i);
	sort(l+1,l+n+1);
	for(int i=1;i<n;i++)ord[i]=i;
	
	int tot=0;double ans=0.0;
	do{
		ans+=calc();
		tot++;
	}while(next_permutation(ord+1,ord+n));
	printf("%.12lf\n",ans/tot);
	return 0;
}

Measured memory_bytes: 12288
#define _USE_MATH_DEFINES
#include <cassert>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <string>
#include <sstream>
#include <vector>
#include <queue>
#include <stack>
#include <list>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <algorithm>
#include <complex>
#include <cmath>
#include <numeric>
#include <bitset>
#include <functional>
#include <random>
#include <ctime>

using namespace std;

#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
  cerr << name << ": " << arg1 << endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
  const char* comma = strchr(names + 1, ',');
  cerr.write(names, comma - names) << ": " << arg1 << " |";
  __f(comma + 1, args...);
}

typedef long long int64;
typedef pair<int, int> ii;
const int INF = 1 << 29;
const int MOD = 1e9 + 7;

int main() {
  string s, t;
  cin >> s >> t;
  if (s.size() < t.size()) {
    cout << "LESS" << endl;
  } else if (s.size() > t.size()) {
    cout << "GREATER" << endl;
  } else {
    int i;
    for (i = 0; i < s.size() && s[i] == t[i]; ++i);
    if (i == s.size()) {
      cout << "EQUAL" << endl;
    } else if (s[i] < t[i]) {
      cout << "LESS" << endl;
    } else {
      cout << "GREATER" << endl;
    }
  }
  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define LLI long long int
#define pii pair<int,int>
#define fst first
#define sec second
#define ULTRA 2134567890
#define MOD 1000000007LL
#define de(x) if(x!=0 && MODE==x)
#define MODE 1
using namespace std;

LLI fac[200007];

void prepare()
{
    fac[0] = 1;
    for( LLI i=1; i<=200000; i++)
    {
        fac[i] = fac[i-1] * i % MOD;
    }
}

LLI pwr( LLI a, LLI b)
{
    LLI ans = 1;
    while(b)
    {
        if(b&1)
            ans = ans * a % MOD;
        a = a * a % MOD;
        b >>= 1;
    }
    return ans;
}

LLI C( LLI a, LLI b)
{
    // LLI ans = 1;
    // for( LLI i=0; i<b; i++)
    // {
    //     ans = ans * ( a - i ) % MOD;
    //     ans = ans * pwr( i+1, MOD-2) % MOD;
    // }
    // return ans;
    return fac[a] * pwr( fac[b], MOD-2) % MOD * pwr( fac[a-b], MOD-2) % MOD;
}

LLI H( LLI a, LLI b)
{
    return C( a+b-1, b);
}

int main()
{
    LLI i,j;
    LLI n,k;

    scanf("%lld %lld", &n, &k);
    prepare();
    LLI ans = 0;

    for( i=0; i<=min( n-1, k); i++)
    {
        // printf(" i = %lld\n", i);
        LLI add = C( n, i) * H( n-i, i)  % MOD;
        de(0)
        {

            printf("%lld >>> %lld\n", i, add);
            printf("C >>> %lld\n", C( n, i));
            printf("H( %lld, %lld) >>> %lld\n", n-i, i, H( n-i, i));
        }
        ans = ( ans + add ) % MOD;
    }
    printf("%lld\n", ans);

    return 0;
}

//
//          ___ ___  __________  __________
//         /////\  \/\   ______\/\\\\\\\\\\\  Code by ~Ice Tea~ of
//        //// \ \  \ \  \_____/\ \\\\_____/      New Empire of CHSH ...
//       ////   \ \  \ \  \      \ \\\\\\\\\\\
//      ////__   \ \  \ \  \      \ \\\\_____/
//     ///////\   \ \  \ \  \______\ \\\\_______   ________
//    ////____/    \ \__\ \___   ___\ \\\\\\\\\\\ _\  ___  \_
//   /__/           \/__/\/__/\  \__/\ \\\\_____//\  .\_/\_  \
//                           \ \  \   \ \\\\\\\\\\\\  \_\/_\  \
// ... with the AC Power of   \ \  \   \ \\\\_____/ \   _____  \
//   The Great Tsundere Doggy. \ \  \   \ \\\\     \ \  \  \ \  \
//                              \ \__\   \ \\\\\\\\\\ \__\  \ \__\
//                               \/__/    \/________/\/__/   \/__/
//


Measured memory_bytes: 1920
#include <iostream>
using namespace std;
int x[7];
bool y[7];
int main() {
	
	int n = 5;
	int sum = 0;
	for(int i = 0; i < n ; i++)
	{
		cin>>x[i];
		if(x[i] % 10 == 0)
		{
			sum+=x[i];
			y[i] = 1;
		}
	}
	int j = 0;
	bool check = false;
	int MIN = 100000000;
	for(int i = 0; i < n; i++)
	{
		if(!y[i])
		{
			if(x[i] % 10 < MIN)
			{
				MIN = x[i]%10;
				j = i;
				check = 1;
			}
		}
	}
	for(int i = 0; i < n; i++)
	{
		if(i != j and !y[i])
		{
			sum+=x[i];
			sum+=10-x[i]%10;
		}
	}
	if(check)
	{
		sum+=x[j];
	}
	
	cout<<sum;
	
	return 0;
}

Measured memory_bytes: 3608
#include <iostream>
#include <cstdio>
#include <vector>
#include <string>
#include <queue>

using namespace std;

int n;
vector<string> a(10);
vector<string> b(10);
string g, d;

queue<string> que;

string repl(string s, int i) {
    string s2 = s.substr(a[i].size());
    int x = s2.find(a[i]);
    if (x != string::npos) {
        string s3 = s2.substr(0,x) + repl(s2.substr(x), i);
        return b[i] + s3;
    }
    else return b[i] + s2;
}

int bfs(int c) {
    if (c > 9) return -1;
    queue<string> que2;
    while (!que.empty()) {
        string s = que.front();
        que.pop();
        for (int i = 0; i < n; i++) {
            int x = s.find(a[i]);
            if (x == string::npos) continue;
            string s2 = s.substr(x);
            string s3 = s.substr(0, x) + repl(s2,i);
            if (s3 == d) return c+1;
            que2.push(s3);
        }
    }
    que = que2;
    return bfs(c+1);
}

int main(void){
    while (cin>>n && n) {
        for (int i = 0; i < n; i++) cin >> a[i] >> b[i];
        cin >> g >> d;
        queue<string> a;
        que = a;
        que.push(g);
        cout << bfs(0) << endl;
    }
}

Measured memory_bytes: 4932
#include <stdio.h>
#include <stdlib.h>

#define PRIME_TABLE_SIZE 1000000
#define P_MAX 100
#define UNKNOWN -1

char is_prime[PRIME_TABLE_SIZE];
int next_prime[PRIME_TABLE_SIZE];

int comp_ints(const void* a, const void*b) { return *(int*)a - *(int*)b; }

void prime_table_init()
{
    int i, j;

    /* sieve */

    is_prime[0] = is_prime[1] = 0;
    for(i = 2; i < PRIME_TABLE_SIZE; i++)
        is_prime[i] = 1;

    i = 2;
    while(i < PRIME_TABLE_SIZE)
    {
        for(j = i * 2; j < PRIME_TABLE_SIZE; j += i)
            is_prime[j] = 0;

        /* search for the next prime */
        for(i++; !is_prime[i] && PRIME_TABLE_SIZE < i; i++);
    }

    for(i = UNKNOWN, j = PRIME_TABLE_SIZE - 1; j >= 0; j--)
    {
        next_prime[j] = i;
        if(is_prime[j]) i = j;
    }
}

int main(void)
{
    int n, p, i, j, k, primes[P_MAX], sums[P_MAX * P_MAX];

    prime_table_init();

    while(scanf("%d %d", &n, &p), n != -1)
    {
        for(i = 0, j = next_prime[n]; i < p; i++, j = next_prime[j])
            primes[i] = j;
        for(i = k = 0; i < p; i++)
            for(j = 0; j <= i; j++, k++)
                sums[k] = primes[i] + primes[j];
        qsort(sums, k, sizeof(int), comp_ints);
        printf("%d\n", sums[p - 1]);
    }

    return 0;
}

Measured memory_bytes: 5560
#include <stdio.h>

/** Application main entry point. */
int
main (
  int     argc,
  char  * argv[ ]
  )
{
  char pv = ' ';
  char rs = ' ';
  int cur = 0;
  int res = 0;

  for ( ; ; )
  {
    const int ch = getchar ( );

    if ( ch == pv
      || ch == '\n' )
    {
      if ( cur > res )
      {
        rs  = pv;
        res = cur;
      }
      cur = 0;
    }
    if ( ch == '\n' ) break ;

    if ( ch == 'e' )
    {
      getchar ( );
      getchar ( );
    }
    if ( ch == 'c' )
    {
      getchar ( );
      getchar ( );
      getchar ( );
      getchar ( );
      getchar ( );
      getchar ( );
    }

    pv = ch;
    ++cur;
  }

  puts ( rs == 'e'
       ? "egg"
       : "chicken" );

  return ( 0 );
}

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

int main(){
  int n,m;
  cin >> n >> m;
  int food[m] = {};
  
  int ki,aij;
  
  rep(i,n){
    cin >> ki;
    rep(j,ki){
      cin >> aij;
      food[aij-1]++;
    }
  }
  
  int count = 0;
  rep(i,m){
    if(food[i]==n) count++;
  }
  
  cout << count << endl;
  
  return 0;
}


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

using namespace std;

typedef long long ll;
const ll mod = 1e9 + 7;

struct Combination {
  vector<ll> factorial, inv;
  Combination(int n) {
    factorial = vector<ll>(n, 1);
    inv = vector<ll>(n);
    for (int i = 1; i < n; ++i) {
      factorial[i] = factorial[i - 1] * i % mod;
    }
    for (int i = 0; i < n; ++i) {
      inv[i] = powMod(factorial[i], mod - 2);
    }
  }

  ll powMod(ll n, ll m) {
    ll ans = 1;
    while (m) {
      if (m & 1) {
        ans = ans * n % mod;
      }
      n = n * n % mod;
      m >>= 1;
    }
    return ans;
  }

  ll C(int n, int k) {
    if (n < k) return 0;
    return factorial[n] * inv[k] % mod * inv[n - k] % mod;
  }
}cb(100001);

int main(int argc, char *argv[]) {
  int n, L, R;
  cin >> n;
  vector<int> a(n + 1);
  map<int, int> mp;
  for (int i = 0; i < n + 1; i++) {
    int t;
    cin >> t;
    if (mp.count(t)) {
      L = mp[t];
      R = i;
      break;
    }
    mp[t] = i;
  }
  n++;
  int len = n - (R - L + 1);
  for (int i = 1; i <= n; i++) {
    if (i == 1) {
      cout << n - 1 << endl;
    } else {
      ll sum = cb.C(n - 2, i - 2) + cb.C(n - 2, i - 1) * 2 - cb.C(len, i - 1) + cb.C(n - 2, i);
      sum = (sum % mod + mod) % mod;
      cout << sum << endl;
    }
  }
  return 0;
}


Measured memory_bytes: 7808
#include<iostream>
#include<cstdio>
#include<string>
#include<algorithm>
#include<utility>
#include<numeric>
#include<vector>
#include<map>
#include<unordered_map>
#include<set>
#include<tuple>
#include<stack>
#include<queue>
#include<functional>
#include<iterator>
#include<cmath>
#include<cctype>
#include<cassert>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> P;

const int INF = 1e9;
const ll LINF = 1e18;
const int MOD = INF+7;

#define FOR(i, a, n) for (ll i = (ll)a; i < (ll)n; ++i)
#define rep(i,n) FOR(i,0,n)

struct edge{int to,cost;};

void dump(ll *b,int n){
	for(int i=0;i<n;i++){
		cout << b[i] << " ";
	}
	cout << "\n";
}

ll mypow(ll x,ll n){
	if(n==0) return 1;
	ll res=mypow(x*x,n/2);
	if(n&1) res=res*x;
	return res;
}

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	
	int n;
	cin >> n;
	pair<ll,ll> v_i[n];
	rep(i,n){
		cin >> v_i[i].first;
		v_i[i].second=i;
	}
	sort(v_i,v_i+n);

	set<int> s;
	ll v,ind;
	ll l,r;
	ll ans=0;
	rep(j,n){
		v = v_i[j].first, ind=v_i[j].second;
		s.insert(ind);
		auto itr=s.find(ind);
		if(itr!=s.begin()){
			auto li = (--itr);
			itr++;
			l=(*itr)-*(li)-1;
		}else{
			l=*itr;
//			cout << "先頭\n";
		}

		if(itr!=(--(s.end()))){
			auto ri = (++itr);
			itr--;
			r=(*ri)-(*itr)-1;
		}else{
			r=n-1-(*itr);
//			cout << "最後\n";
		}

//		cout << j << "番目に小さい" << v << "(位置:" << ind << ")　左に" <<l << "個，右に" << r << "個\n";

		ans+=v*(l+1)*(r+1);
//		cout << ans << "\n";
	}
	cout << ans << "\n";
	
	return 0;
}

Measured memory_bytes: 12800
a, b, c = map(int, input().split())
def cal(n, i):
    if n-i>=0:
        return n-i
    else:
        if (i-n)%2 == 1:
            return (i-n)//2+2
        else:
            return (i-n)//2
cnt = float('inf')
for i in range(51):
    cnt = min(cnt, cal(a,i)+cal(b,i)+cal(c,i))
print(cnt)


Measured memory_bytes: 3060
#include <iostream>
#include <string>
#include <cmath>
#include <algorithm>
#include <cassert>
#include <vector>
//#include <array>
//#include <set>
//#include <map>
//#include <unordered_set>
//#include <unordered_map>
//#include <stack>
//#include <queue>
using ll = long long;
using namespace std;

int main() {
	int N;
	cin >> N;
	vector<int> x;
	vector<int> y;
	vector<int> h;
	for (int i = 0; i < N; i++)
	{
		int tmpx, tmpy, tmph;
		cin >> tmpx >> tmpy >> tmph;
		x.push_back(tmpx);
		y.push_back(tmpy);
		h.push_back(tmph);
	}
	for (int X = 0; X <= 100; X++)
	{
		for (int Y = 0; Y <= 100; Y++)
		{
			int H;
			for (int i = 0; i < N; i++)
			{
				if (h[i] != 0) {
					H = abs(x[i] - X) + abs(y[i] - Y) + h[i];
					break;
				}
			}
			bool is_ok = true;
			for (int i = 0; i < N; i++)
			{
				if (h[i] != max(H - abs(x[i] - X) - abs(y[i] - Y), 0)) {
					is_ok = false;
					break;
				}
			}
			if (is_ok) {
				cout << X << " " << Y << " " << H << endl;
				return 0;
			}
		}
	}
	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cstring>
#include <vector>
#include <deque>
#include <queue>
#include <array>
#include <set>
#include <map>
#include <cmath>
#include <algorithm>
#include <numeric>
#include <cassert>
#include <utility>
#include <functional>
#include <bitset>
#include <cstdint>

using namespace std;
using i64 = int64_t;
using i32 = int32_t;
template<class T, class U> void init_n(vector<T>& v, size_t n, U x) 
{ v = vector<T>(n, x); }
template<class T> void init_n(vector<T>& v, size_t n) { init_n(v, n, T()); }
template<class T> void read_n(vector<T>& v, size_t n, size_t o = 0) 
{ v = vector<T>(n+o); for (size_t i=o; i<n+o; ++i) cin >> v[i]; }
template<class T> void read_n(T a[], size_t n, size_t o = 0)
{ for (size_t i=o; i<n+o; ++i) cin >> a[i]; }
template<class T> T gabs(const T& x) { return max(x, -x); }
#define abs gabs

const i64 mod = 1000003;
i64 q;
i64 ipow(i64 a, i64 b) {
  return (b & 1 ? a : 1) * (b > 1 ? ipow(a * a % mod, b >> 1) : 1) % mod;
}

i64 inv(i64 x) {
  return ipow(x, mod - 2);
}

i64 fact_memo[1000007];
i64 fact(i64 x) {
  if (x > mod) return 0;
  if (fact_memo[x] > 0) return fact_memo[x];
  return fact_memo[x] = x > 0 ? x * fact(x - 1) % mod : 1;
}

int main() {
  cin >> q;
  
  while (q--) {
    i64 x, d, n;
    cin >> x >> d >> n;
    if (x == 0) { cout << 0 << '\n'; continue; }
    if (d == 0) { cout << ipow(x, n) << '\n'; continue; }
    i64 a = x * inv(d) % mod;
    i64 y = ipow(d, n) 
      * fact(n + a - 1) % mod
      * inv(fact(a - 1)) % mod;
    cout << y << '\n';
  }
  return 0;
}


Measured memory_bytes: 23936
n=int(input())
l1=list(map(int,input().split()))
dp=[0]*n
for i in range(1,n):
    if i==1:
        dp[i]=abs(l1[i]-l1[i-1])
    else :
        dp[i]=min(dp[i-1]+abs(l1[i]-l1[i-1]),dp[i-2]+abs(l1[i]-l1[i-2]))
print(dp[n-1])
    

Measured memory_bytes: 13980
using System;
using System.Linq;//リストの使用
using System.Collections.Generic;
using System.Text;//テキストの高速出力に必要
class Program
{
	static void Main()
	{
		string[] input = Console.ReadLine().Split(' ');
		int k = int.Parse(input[0]);
		int n = int.Parse(input[1]);
		int[] nums = Array.ConvertAll(Console.ReadLine().Split(' '),int.Parse);

    int[] dp = new int[n+1];//1で勝てる

    for(int i = 1; i <= n; i++)
    {
      for(int j = 0; j < k; j++)
      {
        if(i-nums[j] >= 0)
        {
          if(dp[i-nums[j]] == 0)
          {
            dp[i] = 1;
            break;
          }
        }
      }
    }
    
		Console.WriteLine(dp[n] == 1?"First":"Second");
	}
}

Measured memory_bytes: 13280
import { readFileSync } from 'fs'

const solve = (k: number) => {
  const memo = new Set()
  let s = 7

  for (let i = 1; true; i++) {
    if (s % k === 0) {
      return i
    }

    if (memo.has(s)) {
      return -1
    }

    memo.add(s)
    s = (s * 10 + 7) % k
  }
}

function main(input: string) {
  const k = Number(input)

  const result = solve(k)

  console.log(result)
}

main(readFileSync('/dev/stdin', 'utf8').trim())


Measured memory_bytes: 74392
#include "bits/stdc++.h"
using namespace std;
#define Would
#define you
#define all(n)  n.begin(),n.end()
#define rall(n) n.rbegin(),n.rend()
typedef long long ll;
const ll INF = 1e18;
const ll MOD = 1e9 + 7;
const double EPS = 1e-10;
const double pi = acos(-1);//3.1415926535897932384626433832795028...
const ll SIZE = 1 << 17;
int dx[] = { 1,0,-1,0 }, dy[] = { 0,1,0,-1 }, alp[30];
ll fac[200005], finv[200005], inv[200005];
vector<ll>dij;
struct edge { ll to, cost; };
vector<vector<edge> >G;

ll mod_pow(ll a, ll b) {
	ll res = 1, mul = a;
	for (int i = 0; i < 31; ++i) {
		if (b >> i & 1) {
			res *= mul;
			res %= MOD;
		}
		mul = (mul * mul) % MOD;
	}
	return res;
}

void addedge(int from, int to, int cost) {
	G[from].push_back({ to,cost });
	G[to].push_back({ from,cost });
}

template<typename T>
vector<T> make_v(size_t a) { return vector<T>(a); }

template<typename T, typename... Ts>
auto make_v(size_t a, Ts... ts) {
	return vector<decltype(make_v<T>(ts...))>(a, make_v<T>(ts...));
}

template<typename T, typename V>
typename enable_if<is_class<T>::value == 0>::type
fill_v(T & t, const V & v) { t = v; }

template<typename T, typename V>
typename enable_if<is_class<T>::value != 0>::type
fill_v(T & t, const V & v) {
	for (auto& e : t) fill_v(e, v);
}

template<typename T>
void outp(vector<T>v) {
	for (int i = 0; i < v.size(); ++i) {
		cout << v[i];
		if (i != v.size() - 1) { cout << " "; }
	}
}

double add(double a, double b) {
	if (abs(a + b) < EPS * (abs(a) + abs(b))) { return 0; }
	return a + b;
}

int n, k[1005];
bool isIn[1005];
int main() {
	cin >> n;
	stack<int>s;
	for (int i = 0; i < n; ++i) {
		cin >> k[i];
		if (k[i] > 0) {
			if (isIn[k[i]]) {
				cout << i + 1 << endl;
				return 0;
			}
			s.push(k[i]);
			isIn[k[i]] = 1;
		}
		else {
			k[i] *= -1;
			if ((!s.empty() && s.top() != k[i]) || s.empty()) {
				cout << i + 1 << endl;
				return 0;
			}
			s.pop();
			isIn[k[i]] = 0;
		}
	}

	cout << "OK" << endl;
}


Measured memory_bytes: 3120
#include <bits/stdc++.h>
#include <algorithm>
#include <cmath>
#include <set>
#include <cstdio>
#include <vector>
#include <iostream>
#include <utility>
#include <queue>
#include <map>

#define fir first
#define sec second
#define sz(s) (s).size()
#define pb push_back
#define get(n) scanf("%d",&n);
#define gets(s) string s;cin >> (s);
#define prfi(n) printf("%d", &n);
#define prfd(n) printf("%lf", &n);
#define All(s) (s).begin(), (s).end()
#define rep(i,j) for(int (i)=0;(i)<(j);(i)++)
#define For(i,j,k) for(int (i)=(j);(i)<(k);(i)++)
#define repd(i,j) for(int (i)=(j);(i)>=0;(i)--)
#define Ford(i,j,k) for(int (i)=(j);i>=(k);i--)
#define vfor(c,v) for(auto (c): v)
#define dump(x)  std::cout << #x << " = " << (x) << std::endl;
#define debug(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

using ll = long long;
using pii = std::pair<int,int>;
using vi = std::vector<int> ;
using vvi = std::vector<vi> ;
using vll = std::vector<ll>;
using vvll = std::vector<vll>;
using vd = std::vector<double> ;
using vvd = std::vector<vd> ;
using qi = std::queue<int> ;
using vpii = std::vector<std::pair<int, int> >;
using namespace std;

const int Mod = (1e9) + 7;
const int max_n = 3 * (1e5) + 1;
const int max_m = 83 * (1e5) + 1;
const int INF = 1e9 + 19;
const ll INFL = 1e18 + 19;
const int dx[] = {-1, 0, 0, 1};
const int dy[] = {0, -1, 1, 0};
//_____________________________________Templates_________________________________________//

template<class T1, class T2> inline void chmin(T1 &a, T2 b){if(a > b) a = b;}
template<class T1, class T2> inline void chmax(T1 &a, T2 b){if(a < b) a = b;}

//mainly use for dynamic prog
template<class T1, class T2>
void update(T1 &a, T2 b){
  a += b;
  if(a > Mod) a %= Mod;
}

inline void IN(void){
  return;
}

template <typename First, typename... Rest>
void IN(First& first, Rest&... rest){
  cin >> first;
  IN(rest...);
  return;
}

inline void OUT(void){
  cout << "\n";
  return;
}

template <typename First, typename... Rest>
void OUT(First first, Rest... rest){
  cout << first << " ";
  OUT(rest...);
  return;
}
//_____________________　following sorce code_________________________//
int n,m,k;
//vvll dp(400, vll(400));
string S;
vll cost(1 << 16);
int a,b,c;
int h,w;
vi v;
vll u;

bool check(){
}

int main () {
  cin.tie(0);
  ios::sync_with_stdio(false);
  IN(S);
  n = sz(S);
  int ans = n;
  rep(i,n-1){
    if(S[i] != S[i+1]){
      int res = max(i+1, n -(i+1));
      chmin(ans, res);
    }
  }
  cout << ans << endl;
  //cout << fixed << setprecision(15) << ans << endl;
  return 0;
}

Measured memory_bytes: 1024
#include <iostream>

// using
using namespace std;

// define
#define FOR(i, a, b, c) for (int i = (int)(a); i < (int)(b); i += (int)(c))
#define REP(i, n) FOR(i, 0, n, 1)

// functions
int ceil(int a, int b) {
    return (a + b - 1) / b;
}

// main
int main() {
    const int MAX_N = 100000;
    int N, K, A[MAX_N];
    cin >> N >> K;
    for(int i = 0;i < N; ++i) {
        cin >> A[i];
    }
    cout << 1 + ceil(N - K, K - 1) << endl;
    return 0;
}


Measured memory_bytes: 640
ans = 0
A = [int(i) for i in input().split()]
A.sort()
A = [A[0]-A[2],A[1]-A[2]]
ans += abs(A[1])
a = abs(A[0] - A[1])

ans += a // 2

if a % 2 == 1:
    ans += 2
    
print(ans)

Measured memory_bytes: 3064
#include <iostream>

using namespace std;

int main() {
    string s;
    cin >> s;
    string t;
    cin >> t;
    int counter = 0;
    for(int i = 0; i < 3; i++) {
        if(s[i] == t[i]) {
            counter++;
        } 
    }
    cout << counter << endl;
 
    return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
static inline int IN(void)
{
  int x=0,f=0,c=getchar();while(c<48||c>57){f^=c==45,c=getchar();}
  while(c>47&&c<58){x=x*10+c-48,c=getchar();}return f?-x:x;
}
int main()
{
  int c[26],D=IN(),i=0,j=0,s[365][26]={{0}},t,update[26]={0},sum=0;
  while(i<26){c[i++]=IN();}i=0;
  while(i<D){while(j<26){s[i][j++]=IN();}i++,j=0;}i=0;
  while(i<D)
  {
    j=0;t=IN()-1;sum+=s[i][t];update[t]=++i;
    while(j<26){sum-=c[j]*(i-update[j]);j++;}
    printf("%d\n",sum);
  }
}

Measured memory_bytes: 1620
import java.util.Scanner;

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

        int N = sc.nextInt();
        int A[] = new int[N], rev[] = new int[N];
        long left[] = new long[N], right[] = new long[N];
        for (int i = 0; i < N; i++) {
            A[i] = sc.nextInt();
            rev[A[i]-1] = i;
        }
        left[0] = -1;
        right[N-1] = N;
        for (int i = 1; i < N; i++) {
            long now = i-1;
            while (now != -1 && A[(int)now] > A[i]) now = left[(int)now];
            left[i] = now;
        }
        for (int i = N-2; i >= 0; i--) {
            long now = i+1;
            while (now != N && A[(int)now] > A[i]) now = right[(int)now];
            right[i] = now;
        }

        long ans = 0;
        for (int i = 0; i < N; i++) {
            long M = right[rev[i]] - left[rev[i]] - 1, R = right[rev[i]] - rev[i] - 1, L = rev[i] - left[rev[i]] - 1;
            ans += (long)(i + 1) * (M * (M + 1) / 2 - L * (L + 1) / 2 - R * (R + 1) / 2);
        }

        System.out.println(ans);
    }
}


Measured memory_bytes: 72732
#include <iostream>
#include <cstdio>

using namespace std;

long long n, a, b, x[100005], s;
int main()
{
    int i;

    cin >> n >> a >> b;
    for(i=0; i<n; i++) {
        cin >> x[i];
    }
    for(i=0; i<n-1; i++) {
        if((x[i+1]-x[i])*a<b) {
            s = s + (x[i+1]-x[i])*a;
        }
        else {
            s = s + b;
        }
    }
    cout << s << endl;
    return 0;
}


Measured memory_bytes: 1152
#include<stdio.h>
#define MAX 10000
#define NIL -1

struct Node {int parent, left, right;};

struct Node T[MAX];
int n,D[MAX],H[MAX];

void setDepth(int u,int d){
    if(u == NIL) return;
    D[u] = d;
    setDepth(T[u].left, d + 1);
    setDepth(T[u].right, d + 1);
}
int setHeight(int u){
    int h1 = 0, h2 = 0;
    if(T[u].left != NIL) h1 = setHeight(T[u].left) + 1;
    if(T[u].right != NIL) h2 = setHeight(T[u].right) + 1;
    return H[u] = (h1 > h2 ? h1 : h2);
}

int getSibling(int u){
    if(T[u].parent == NIL) return NIL;
    if(T[T[u].parent].left != u && T[T[u].parent].left != NIL) return T[T[u].parent].left;
    if(T[T[u].parent].right != u && T[T[u].parent].right != NIL) return T[T[u].parent].right;
    return NIL;
}

void print(int u){
    printf("node %d: ",u);
    printf("parent = %d, ",T[u].parent);
    printf("sibling = %d, ", getSibling(u));
    int deg = 0;
    if(T[u].left != NIL) deg++;
    if(T[u].right != NIL) deg++;
    printf("degree = %d, ",deg);
    printf("depth = %d, ",D[u]);
    printf("height = %d, ",H[u]);
    
    if(T[u].parent == NIL){
        printf("root\n");
    }else if(T[u].left == NIL && T[u].right == NIL){
        printf("leaf\n");
    }else{
        printf("internal node\n");
    }
}

int main(){
    int i,v,l,r,root = 0;
    scanf("%d",&n);
    for(i=0;i<n;i++) T[i].parent = NIL;
    for(i=0;i<n;i++){
        scanf("%d %d %d",&v,&l,&r);
        T[v].left = l;
        T[v].right = r;
        if(l != NIL) T[l].parent = v;
        if(r != NIL) T[r].parent = v;
    }
    
    for(i=0;i<n;i++)if(T[i].parent == NIL) root = i;
    
    setDepth(root,0);
    setHeight(root);
    
    for(i=0;i<n;i++) print(i);
    
    return 0;
}


Measured memory_bytes: 2104
n = int(input())
playlist = []
seccond = []

i = 0
while i < n:
    name, sec = input().split()
    playlist.append(name)
    seccond.append(int(sec))

    i += 1

x = input()
si = playlist.index(x)+1
cnt = 0

while si < n:
    cnt += seccond[si]

    si += 1


print(cnt)


Measured memory_bytes: 3060
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.Arrays;
import java.util.StringTokenizer;

import static java.lang.Integer.parseInt;

public class Main {
    public static void main(String[] args) throws Exception {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        String[] padding = new String[]{"", "0", "00", "000", "0000", "00000"};
        StringTokenizer st = new StringTokenizer(br.readLine());
        int N = parseInt(st.nextToken());
        int M = parseInt(st.nextToken());
        int[][] cities = new int[M][4];//[p,y,index,sort]

        for (int i = 0; i < M; i++) {
            st = new StringTokenizer(br.readLine());
            cities[i][0] = parseInt(st.nextToken());
            cities[i][1] = parseInt(st.nextToken());
            cities[i][2] = i;
        }
        br.close();

        Arrays.sort(cities, (e1, e2) -> (e1[0] == e2[0]) ? (e1[1] - e2[1]) : (e1[0] - e2[0]));
        cities[0][3] = 1;
        for (int i = 1; i < M; i++) {
            cities[i][3] = (cities[i][0] == cities[i - 1][0]) ? cities[i - 1][3] + 1 : 1;
        }

        Arrays.sort(cities, (e1, e2) -> e1[2] - e2[2]);
        StringBuilder sb = new StringBuilder(100000 * 13);

        for (int[] city : cities) {
            sb.append(padding[getZeroCnt(city[0])]).append(city[0]);
            sb.append(padding[getZeroCnt(city[3])]).append(city[3]).append('\n');
        }
        System.out.println(sb.toString());
    }

    private static int getZeroCnt(int n) {
        if (n < 10) return 5;
        else if (n < 100) return 4;
        else if (n < 1000) return 3;
        else if (n < 10000) return 2;
        else if (n < 100000) return 1;
        else return 0;
    }
}

Measured memory_bytes: 49656
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Arrays;
import java.util.SortedMap;
import java.util.StringTokenizer;
import java.util.TreeMap;

public final class Main {

    public static void main(String[] args) {
        final FastScanner fs = new FastScanner();
        final int h = fs.nextInt();
        final int w = fs.nextInt();
        final int[] a = new int[h];
        final int[] b = new int[h];
        for (int i = 0; i < h; i++) {
            a[i] = fs.nextInt() - 1;
            b[i] = fs.nextInt();
        }
        final SortedMap<Integer, Integer> currToOrigin = new TreeMap<>();
        for (int i = 0; i < w; i++) {
            currToOrigin.put(i, i);
        }
        final int[] gaps = new int[w];
        final int[] results = new int[h];
        gaps[0] = w;
        Arrays.fill(results, -1);
        int minGapIndex = 0, maxGapIndex = 0;
        for (int i = 0; (i < h) && !currToOrigin.isEmpty(); i++) {
            final SortedMap<Integer, Integer> subMap = currToOrigin.subMap(a[i], b[i]);
            if (!subMap.isEmpty()) {
                final int maxOrigin = subMap.get(subMap.lastKey());
                subMap.forEach((key, value) -> gaps[key - value]--);
                subMap.clear();
                if ((b[i] < w) && !currToOrigin.containsKey(b[i])) {
                    currToOrigin.put(b[i], maxOrigin);
                    gaps[b[i] - maxOrigin]++;
                    maxGapIndex = Math.max(maxGapIndex, b[i] - maxOrigin);
                }
                while ((minGapIndex <= maxGapIndex) && (0 == gaps[minGapIndex])) {
                    minGapIndex++;
                }
            }
            results[i] = (minGapIndex <= maxGapIndex) ? minGapIndex + i + 1 : -1;
        }
        Arrays.stream(results).forEach(System.out::println);
    }

    static class FastScanner {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        StringTokenizer st = new StringTokenizer("");

        String next() {
            while (!st.hasMoreTokens()) {
                try {
                    st = new StringTokenizer(br.readLine());
                } catch (IOException e) {
                    //noinspection CallToPrintStackTrace
                    e.printStackTrace();
                }
            }
            return st.nextToken();
        }

        int nextInt() {
            return Integer.parseInt(next());
        }

        int[] readArray(int n) {
            final int[] a = new int[n];
            for (int i = 0; i < n; i++) { a[i] = nextInt(); }
            return a;
        }

        long nextLong() {
            return Long.parseLong(next());
        }
    }
}


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

struct ArrayOfInt {
	int *value;
	int max;
	int count;
	ArrayOfInt() {
		clear();
	}
	void push_back(int x) {
		if (count > 0.99 * max) {
			int *temp = value;
			value = new int[max * 2];
			for (int i = 0; i < count; i++)
				value[i] = temp[i];
			max = max * 2;
			delete[] temp;
		}
		value[count] = x;
		count++;
	}
	void show() {
		for (int i = 0; i < count; i++)
		{
			if (i) cout << " ";
			cout << value[i];
		}
		cout << endl;
	}
	void clear() {
		delete[] value;
		max = 100;
		count = 0;
		value = new int[max];
	}
};

struct ArrayOfArray {
	int max;
	ArrayOfInt *value;
	ArrayOfArray(int x)
	{
		max = x;
		value = new ArrayOfInt[max];
	}
	void pushBack(int t, int x) 
	{
		value[t].push_back(x);
	}
	void dump(int t) 
	{
		value[t].show();
	}
	void clear(int t)
	{
		value[t].clear();
	}
};

int main(void)
{
	int n, q, com, t, x;
	cin >> n >> q;
	ArrayOfArray ar(n);
	while (q--)
	{
		cin >> com >> t;
		if (com == 0)
		{
			cin >> x;
			ar.pushBack(t, x);
		}
		else if (com == 1)
		{
			ar.dump(t);
		}
		else
		{
			ar.clear(t);
		}
	}
}


Measured memory_bytes: 6620
stdin.ReadLine() |> ignore

let ary =
    stdin.ReadLine().Split() |> Array.map int

let q = stdin.ReadLine() |> int

let initSum = Array.sumBy int64 ary

let counts =
    let cnt = Array.zeroCreate 100001

    for a in ary do
        cnt.[a] <- cnt.[a] + 1

    cnt

let rec replace i sum =
    if i <= 0 then
        ()
    else
        let b, c =
            stdin.ReadLine().Split()
            |> Array.map int
            |> fun ary -> ary.[0], ary.[1]

        let sum =
            sum + (int64 c - int64 b) * int64 counts.[b]

        counts.[c] <- counts.[b] + counts.[c]
        counts.[b] <- 0

        printfn "%d" sum

        replace (i - 1) sum

replace q initSum


Measured memory_bytes: 56804
#include<bits/stdc++.h>
#define int long long int
#define pb push_back
#define pp pop_back
#define pii pair<int,int>
#define vec vector<int>
#define mp make_pair
using namespace std;
int32_t main()
{
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  int t=1;
  //cin>>t;
  while(t--)
  {
    int n;
    cin>>n;
    int h[n+1],i;
    for(i=1;i<=n;i++)
        cin>>h[i];
    int dp[n+1]={0};
    for(i=2;i<=n;i++)
    {
      if(i==2)
            dp[i]=abs(h[i]-h[i-1])+dp[i-1];
      else
            dp[i]=min(abs(h[i]-h[i-1])+dp[i-1],abs(h[i]-h[i-2])+dp[i-2]);
    }
    cout<<dp[n];
  }
}

Measured memory_bytes: 5204
#include<stdio.h>

int main() {
  int A[100];
  int n, i, j, temp, flag=1, cout=0;

  scanf("%d\n",&n);
  
  for(i=0; i<n; i++)
    scanf("%d",&A[i]);

  while (flag) {
    flag=0;
    for (j=n-1; j>0; j--) {
      if (A[j]<A[j-1]) {
        temp=A[j];
        A[j]=A[j-1];
        A[j-1]=temp;
        flag=1;
        cout++;
      }
    }
  }
  for (i=0; i<n-1; i++)
    printf("%d ",A[i]);
  printf("%d",A[n-1]);
 
  printf("\n");
  printf("%d\n",cout);
  return 0;

}

Measured memory_bytes: 604
#include <iostream>
#include <algorithm>

using namespace std;

int main(){
	int H, W;//ブロック数縦、横
	int CicadaNum[50][50] = {};//[行][列]
	int CicadaGraph[50][50] = {};
	cin >> H; cin >> W;

	char load[51];//ローダー
	for (int i = 0; i < H; ++i){
		cin >> load;
		for (int j = 0; j < W; ++j){
			CicadaNum[i][j] = load[j] - '0';
		}
	}
	for (int i = 1; i < H; ++i){//0列目
		CicadaGraph[i][0] = CicadaGraph[i - 1][0] + CicadaNum[i][0];
	}
	for (int j = 1; j < W; ++j){//0行目
		CicadaGraph[0][j] = CicadaGraph[0][j - 1] + CicadaNum[0][j];
	}

	for (int i = 1; i < H; ++i){
		for (int j = 1; j < W; ++j){
			CicadaGraph[i][j] = min(CicadaGraph[i - 1][j] + CicadaNum[i][j], CicadaGraph[i][j - 1] + CicadaNum[i][j]);
		}
	}

	cout << CicadaGraph[H - 1][W - 1] << endl;

	return 0;
}

Measured memory_bytes: 1192
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (long long i = 0; i < (long long)(n); i++)
#define lb(v,i) lower_bound(v.begin(),v.end(),i)-v.begin()
#define ub(v,i) upper_bound(v.begin(),v.end(),i)-v.begin()
typedef long long ll;
typedef pair<int,int> P;
using vi=vector<long long>;
using vvi=vector<vector<long long>>;
using vc=vector<char>;
using vvc=vector<vector<char>>;
const ll inf=1000000000009;
void chmin(auto &a,auto b){if(b<a)a=b;}
void chmax(auto &a,auto b){if(a<b)a=b;}

int main(){
  ll a,b,c;cin>>a>>b>>c;
  vi s(a),t(b);
  rep(i,a)cin>>s[i];
  rep(i,b)cin>>t[i];
  rep(i,c){
    ll k;cin>>k;
    ll ans=inf;
    ll sf=lb(s,k),se=ub(s,k)-1,tf=lb(t,k),te=ub(t,k)-1;
    if(sf<a){
      if(tf<b)chmin(ans,max(s[sf],t[tf])-k);
      if(te>=0)chmin(ans,min(s[sf]-k,k-t[te])+s[sf]-t[te]);
    }
    if(se>=0){
      if(te>=0)chmin(ans,k-min(s[se],t[te]));
      if(tf<b)chmin(ans,min(t[tf]-k,k-s[se])+t[tf]-s[se]);
    }
    cout<<ans<<endl;
  }
}


Measured memory_bytes: 2944