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

int main(void){
  int P, Q, R, min;
  cin >> P >> Q >> R;
  int ans[3];
  ans[0] = P + Q;
  ans[1] = R + Q;
  ans[2] = P + R;
  min = ans[0];
  for(int i = 0; i < 3; i++){
    if(min > ans[i])
      min = ans[i];
  }
  cout << min << "\n";
  return 0;
}


Measured memory_bytes: 3564
#pragma comment(linker, "/STACK:102400000,102400000")
#include <vector>
#include <list>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <cstring>
#define LL long long
#define len(p) (p.R-p.L+1)
#define keytree ch[ch[root][1]][0]
using namespace std;
const int M = 1e6 + 5, INF = 0x3f3f3f3f;
char s[M],t[M];
int main() {
    int n;
    scanf("%d%s%s",&n,s,t);
    int ans=0;
    for(int j=0;j<n;j++){
        int maxx=-1;
        for(int k=0;j+k<n;k++){
            if(s[j+k]==t[k]){
                maxx=k;
            }
            else break;
        }
//        printf("%d %d\n",j,maxx);
        if(j+maxx==n-1){
//            printf("j = %d\n",j);
            ans=n-j;
            break;
        }
    }
    printf("%d\n",2*n-ans);
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define FASTIO ios::sync_with_stdio(false);cin.tie(0);
#define ADD +
#define SUBTRACT -
#define MULTIPLY *
#define DIVIDE /
#define MOD %
#define INCREMENT(x) ++x
#define DECREMENT(x) --x
#define in(a,b) cin>>a>>b;
#define out(a,b) cout<<a<<endl<<b<<endl;
#define scan(a) scanf("%d",&a);
#define print(a) printf("%d\n",a);
#define scanii(a,b) scanf("%d %d",&a,&b);
#define printii(a,b) printf("%d\n%d\n",a,b);
#define scaniii(a,b,c) scanf("%d %d %d",&a,&b,&c);
#define pub push_back
#define pob pop_back
#define puf push_front
#define pof pop_front
#define ll long long
#define ull unsigned long long
#define sll signed long long
#define pi acos(-1)
#define mod 1000000007
#define TRUE 1
#define FALSE 0
#define ZERO 0
#define MP make_pair
#define F first
#define S second
#define f1(i,a) for(int i=0;i<a;++i)
#define f2(i,a) for(int i=a-1;i>=0;--i)
#define en puts("");
#define elif else if
typedef ll int lli;
typedef sll int slli;
typedef ull int ulli;
const int sz=10000;
using namespace std;

int clue();
int result();
void show();
bool check(int n) {
    for(int i=2;i*i<=n;++i) {
        if(n%i==0)
        return false;
    }
    return true;
}


// bool cmp(pair<int,int>p,pair<int,int>q) {
//     // return p.first>q.first;//descending by first
//     // return p.first<q.first;//ascending by first
//     // return p.second>q.second;//descending by second
//     return p.second<q.second;//ascending by second
// }

bool cmp(int p,int q) {
    return p>q;//descending
    // return p<q;//ascending
}


int main() {

    int t;
    // cin>>t;
    t=1;
    while(t-->0) {
        clue();
    }

    return 0;
}
int clue() {

    int n;
    cin>>n;
    int a[n];
    f1(i,n) {
        cin>>a[i];
    }
    int c=0;

    for(int i=1;i<n-1;INCREMENT(i)) {
        if((a[i]>=a[i-1]&&a[i]<=a[i+1])||(a[i]<=a[i-1]&&a[i]>=a[i+1]))++c;
    }
    cout<<c<<endl;
    
    // ()?cout<<"Yes"<<endl:cout<<"No"<<endl;
    
    return 0;
}

Measured memory_bytes: 3552
#![allow(unused_imports)]
#![allow(dead_code)]
use datastructure::*;
use grapth::*;
use input_scanner::*;
use math::*;
use string_algorithm::*;
use util::*;

use std::cmp;
use std::collections::{BTreeMap, BTreeSet, BinaryHeap, HashMap, HashSet, LinkedList, VecDeque};

fn main() {
    let mut scan = Scanner::new();
    let mut n: u64 = scan.next();
    let mut s: Vec<u32> = vec![];

    
    while n > 0 {
        n -= 1;
        s.push((n % 26u64 + 'a' as u64) as u32);
        n /= 26;
    }
    s.reverse();
    for c in s {
        print!("{}", std::char::from_u32(c).unwrap());
    }
    println!("");
}

mod datastructure {}
mod grapth {}
mod math {}
mod string_algorithm {}
mod util {}
mod input_scanner {
    pub struct Scanner {
        bytes: Vec<u8>,
        begin: usize,
        end: usize,
    }

    impl Scanner {
        pub fn new() -> Self {
            use std::io::Read;
            let mut buffer: Vec<u8> = Vec::new();
            std::io::stdin().read_to_end(&mut buffer).unwrap();
            let end = (0..buffer.len())
                .find(|i| buffer[*i].is_ascii_whitespace())
                .unwrap_or(buffer.len());
            Scanner {
                bytes: buffer,
                begin: 0,
                end: end,
            }
        }
        pub fn next<T: std::str::FromStr>(&mut self) -> T {
            let s: &str =
                unsafe { std::str::from_utf8_unchecked(&self.bytes[self.begin..self.end]) };
            let ret: T = s.parse::<T>().ok().expect("Parse error.");
            self.skip();
            ret
        }
        pub fn next_vec<T: std::str::FromStr>(&mut self, n: usize) -> Vec<T> {
            (0..n).map(|_| self.next()).collect()
        }
        pub fn next_word(&mut self) -> Vec<u8> {
            let r = Vec::from(&self.bytes[self.begin..self.end]);
            self.skip();
            r
        }
        fn skip(&mut self) {
            self.begin = (self.end..self.bytes.len())
                .find(|i| !self.bytes[*i].is_ascii_whitespace())
                .unwrap_or(self.bytes.len());
            self.end = (self.begin..self.bytes.len())
                .find(|i| self.bytes[*i].is_ascii_whitespace())
                .unwrap_or(self.bytes.len());
        }
    }
}


Measured memory_bytes: 2128
N, A, B, C = [int(elem) for elem in input().split()]
inf = 10 ** 9

ls = []
for i in range(0, N):
  l = int(input())
  ls.append(l)

def dfs(cur, a, b, c):
  if cur == N:
    return abs(a - A) + abs(b - B) + abs(c - C) - 30 if min(a, b, c) > 0 else inf
  ret0 = dfs(cur + 1, a, b, c)
  ret1 = dfs(cur + 1, a + ls[cur], b, c) + 10
  ret2 = dfs(cur + 1, a, b + ls[cur], c) + 10
  ret3 = dfs(cur + 1, a, b, c + ls[cur]) + 10
  return min(ret0, ret1, ret2, ret3)

print(dfs(0, 0, 0, 0))

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

edges = [[] for _ in range(N)]
for _ in range(N - 1):
    fr, to, cost = map(int, input().split())
    fr -= 1
    to -= 1
    edges[fr].append((to, cost))
    edges[to].append((fr, cost))

Q, K = map(int, input().split())
K -= 1
ST = [tuple(map(lambda a: int(a) - 1, input().split())) for _ in range(Q)]


minDist = [10**18] * N
st = [(K, 0, -1)]
while st:
    now, d, pr = st.pop()
    minDist[now] = d
    for to, cost in edges[now]:
        if to == pr:
            continue
        st.append((to, d + cost, now))

ans = []
for s, t in ST:
    ans.append(minDist[s] + minDist[t])
print(*ans, sep='\n')

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

using i64 = long long;
using P = pair<i64, i64>;

#define overload3(_1, _2, _3, name, ...) name
#define rep1(i, n) for(i64 i = 0LL; i < (n); ++i)
#define rep2(i, a, b) for(i64 i = (a); i < (b); ++i)
#define rep(...) overload3(__VA_ARGS__, rep2, rep1)(__VA_ARGS__)
#define all(v) v.begin(), v.end()


void solve(string S){
    i64 n = S.size();
    i64 mod = 2019, inv = 202;
    vector<i64> p(n);
    i64 b = 10;
    p[n - 1] = (S[n - 1] - '0');
    for(i64 i = n - 2; i >= 0; --i){
        p[i] = ((S[i] - '0') * b + p[i + 1]) % mod;
        b = b * 10 % mod;
    }
    vector<vector<i64>> q(2, vector<i64>(mod));
    rep(i, n) q[(n - 1) % 2][p[i]]++;
    i64 ans = 0;
    for(i64 i = n - 1; i >= 0; --i){
        ans += q[i % 2][0];
        q[i % 2][S[i] - '0']--;
        rep(j, mod){
            q[(i + 1) % 2][(j - (S[i] - '0') + mod) * inv % mod] += q[i % 2][j];
        }
        rep(j, mod) q[i % 2][j] = 0;
    }
    cout << ans << endl;
}

struct IoSetup {
    IoSetup() {
        // cin.tie(nullptr);
        // ios::sync_with_stdio(false);
        cout << fixed << setprecision(10);
        cerr << fixed << setprecision(10);
    }
} iosetup;

int main(){
    string S;
    cin >> S;
    solve(S);
    return 0;
}


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

using namespace std;

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

	int n;
	cin >> n;

	string ns = to_string(n);

	int s = 0;
	for (int i = 0; i < (int)ns.size(); i++)
		s += ns[i]-'0';

	if (n%s == 0)
		cout << "Yes\n";
	else
		cout << "No\n";
	
	return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
#include<string.h>
struct{
	char c;
	int time[100],max,k;
}temp[30];
int main ()
{
	int i;
	char s[105];
	while(scanf("%s",s)!=EOF){
	for(i=0;i<26;i++){
		temp[i].c='a'+i;
		temp[i].time[0]=0;
		temp[i].max=0;
		temp[i].k=1;
	}
		int len=0,j;
		len=strlen(s);
		for(i=0;i<len;i++)
			for(j=0;j<26;j++){
				if(s[i]==temp[j].c){
				temp[j].time[temp[j].k]=i+1;
				temp[j].k++;
				break;	
				}
			}
		for(i=0;i<26;i++)
			temp[i].time[temp[i].k]=len+1;
		for(i=0;i<26;i++)
			for(j=1;j<=temp[i].k;j++){
				if(temp[i].max<(temp[i].time[j]-temp[i].time[j-1]))
					temp[i].max=temp[i].time[j]-temp[i].time[j-1];
			}
		int answer;
		answer=temp[0].max;
		for(i=0;i<26;i++)
			if(answer>temp[i].max)
			answer=	temp[i].max;
		printf("%d\n",answer-1);
	}
}

Measured memory_bytes: 128
#include <iostream>
#include <cstdio>
#include <vector>
#include <iomanip>
#include <unordered_map>
#include <unordered_set>
#include <algorithm>
#include <map>
#include <set>
#include <cmath>
using namespace std;

int main() {
    int K;

    cin >> K;
    vector <bool> remain(K+10);
    int now = 7;
    int counter = 1;
    bool appear = false;

    while (true) {
        now %= K;

        if (now == 0) {
            appear = true;
            break;
        } else if(remain[now]) { // loop
            break;
        }

        remain[now] = true;
        now *= 10;
        now += 7;
        ++counter;
    }


    if (appear) {
        cout << counter << endl;
    } else {
        cout << -1 << endl;
    }

    return 0;
}

Measured memory_bytes: 3716
#include <bits/stdc++.h>
#define ALL(A) (A).begin(),(A).end()
#define ll long long
#define rep(i,n) for(int i=0;i<(n);i++)

const ll mod = 1e9+7;
const ll INF = -1*((1LL<<63)+1);
const int inf = -1*((1<<31)+1);

using namespace std;

int main(void){
	cin.tie(0);
	ios::sync_with_stdio(false);
	int N;
	cin >> N;
	vector<int> L(N);
	rep(i,N)cin >> L[i];
	sort(ALL(L));
	ll ans = 0;
	rep(i,N)for(int j=i+1;j<N;j++){
		int a = L[i];
		int b = L[j];
		int c;
		int t = a+b;
		int p = lower_bound(ALL(L),t) - L.begin();
		//[p,N-1]はダメ
		//[j,p-1]はok
		if(p-1>=j)ans += p-1-j;
	}
	cout << ans << endl;
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<int> vint;
typedef pair<int,int> pint;
typedef vector<pint> vpint;
#define rep(i,n) for(int i=0;i<(n);i++)
#define REP(i,n) for(int i=n-1;i>=(0);i--)
#define reps(i,f,n) for(int i=(f);i<(n);i++)
#define each(it,v) for(__typeof((v).begin()) it=(v).begin();it!=(v).end();it++)
#define all(v) (v).begin(),(v).end()
#define eall(v) unique(all(v), v.end())
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define chmax(a, b) a = (((a)<(b)) ? (b) : (a))
#define chmin(a, b) a = (((a)>(b)) ? (b) : (a))
const int MOD = 1e9 + 7;
const int INF = 1e9;
const ll INFF = 1e18;

int N, M;
int X[5010], Y[5010];
ll T[5010];
int v0, a, b, c;

typedef tuple<ll, int, int> tup;
const int MAX_N = 510;
vector<pair<int, ll> > G[MAX_N];
vector<vector<ll>> dijkstra(int start, int fv){
	//dist[i][j] := start->i?????§????§??????§, ?????????j????????????????§?????????¢????????????????°????
	vector<vector<ll>> dist(MAX_N, vector<ll>(55, INFF));
	dist[start][fv] = 0;
	priority_queue<tup, vector<tup >, greater<tup > >  que;
	
	que.push(make_tuple(0, fv, start));
	while(!que.empty()){
		ll cost; int v, i;
		tie(cost, v, i) = que.top(); que.pop();
		// printf("%lld %d %d\n", cost, v, i);
		if(dist[i][v] < cost) continue;
		int nv = (a * v + b);
		nv %= c;
		// printf("%lld %d %d nv %d\n", cost, v, i, nv);
		for (auto tmp : G[i]){
			int j = tmp.first; ll time = tmp.second;//??£??\???????????? ?????????????????§????????????
			if(dist[j][nv] > dist[i][v] + time * v){//i->j
				dist[j][nv] = dist[i][v] + time * v;
				que.push(make_tuple(dist[j][nv], nv, j));
			}
		}
	}
	return dist;
}

int main(void){
	scanf("%d %d", &N, &M);
	rep(i, M) scanf("%d %d %lld", &X[i], &Y[i], &T[i]);
	rep(i, M) X[i]--, Y[i]--;
	rep(i, M){
		G[X[i]].pb(mp(Y[i], T[i]));
		G[Y[i]].pb(mp(X[i], T[i]));
	}
	scanf("%d", &v0);
	scanf("%d %d %d", &a, &b, &c);
	auto dis = dijkstra(0,v0);
	ll ans = INFF;
	rep(j, 52){
		if(dis[N - 1][j] == INFF) continue;
		// printf("%lld\n", dis[N - 1][j]);
		auto tm = dijkstra(N - 1, j);
		rep(k, 52) chmin(ans, dis[N - 1][j] + tm[0][k]);
		// printf("ans %lld\n", ans);
	}
	printf("%lld\n", ans);
	return 0;
}

Measured memory_bytes: 7244
#include <bits/stdc++.h>
typedef long long ll;
typedef long double ld;
const int INF=1e9,MOD=1e9+7,ohara=1e6+10;
const ll LINF=1e18;
using namespace std;

#define rep(i,n) for(int (i)=0;(i)<(int)(n);(i)++)
#define rrep(i,a,b) for(int i=(a);i<(b);i++)
#define rrrep(i,a,b) for(int i=(a);i>=(b);i--)
#define all(v) (v).begin(), (v).end()
#define Size(n) (n).size()
#define Cout(x) cout<<(x)<<endl
#define doublecout(a) cout<<fixed<<setprecision(15)<<a<<endl;
#define Cerr(x) cerr<<(x)<<endl
#define fi first
#define se second
#define P pair<ll,ll> 
#define m_p make_pair
#define V vector<ll> 
#define U_MAP unordered_map<ll,ll>

ll n,cnt,ans,a[ohara],b,c,d,tmp,tmpp,m,h,w,x,y,sum,pos,k;
ld doua;
int dy[]={1,0,-1,0};
int dx[]={0,1,0,-1};
//int dy[]={-1,0,1,-1,1,-1,0,1};
//int dx[]={-1,-1,-1,0,0,1,1,1};
string alph("abcdefghijklmnopqrstuvwxyz"),s;
bool fl;
struct edge{int to,cost;};
ll koutiku[ohara];

//-------------------------↓↓↓↓↓↓------------------------

//------ 自分を天才だと信じる ------

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

    cin>>n;
    rep(i,n)cin>>a[i];
    ans=a[n-1];
    rrrep(i,n-2,0){
        cnt++;
        if(cnt%2==1){
            ans+=(a[i])*-1;
        }
        else{
            ans+=(a[i]);
        }
    }
    koutiku[0]=ans;
    rrep(i,1,n){
        koutiku[i]=a[i-1]*2-koutiku[i-1];
    }
    rep(i,n){
        if(i==n-1)Cout(koutiku[i]);
        else cout<<koutiku[i]<<" ";
    }
    return 0;
}


Measured memory_bytes: 6272
#include <bits/stdc++.h>
#define MIN(a,b) (((a)<(b))?(a):(b))
using namespace std;

int main(){
    int n;
    int ab = 0, oa = 0, bo = 0;
    int flg = 1;
    cin >> n;
    for(int i = 0; i < n; i++){
        string t;
        cin >> t;
        for(int j = 0; j + 2 <= t.size(); j++){
            if(t[j] == 'A' && t[j+1] == 'B') ab++;
        }
        if(t[0] == 'B'){
            bo++;
            if(t[t.size()-1] != 'A') flg = 0;
        }
        if(t[t.size()-1] == 'A'){
            oa++;
            if(t[0] != 'B') flg = 0;
        }

    }
    if(oa > 0 && bo > 0 && flg == 1){
        cout << ab + MIN(oa, bo) - 1 << endl;
    }
    else{
        cout << ab + MIN(oa, bo) << endl;
    }
}

Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include <stdio.h>
#include<algorithm>
#include<cstring>
#include<cmath>
#include<cstdlib>
#include<queue>
#include<map>
#include<vector>
#include <set>
#define ll long long
#define IO ios::sync_with_stdio(false);cin.tie();cout.tie(0)
#define inf 0x3f3f3f3f
#define pi 3.1415926535898
using namespace std;
ll f[200010];
const ll mod = 1e9+7;
ll x,y,z;
ll pows(int n,int a)
{
    ll ans=1;
    while(a)
    {
        if(a&1)
        {
            ans=1ll*ans*n%mod;
        }
        n=1ll*n*n%mod;
        a>>=1;
    }
    return ans;
}
int main()
{
    int n,k;
    cin>>n>>k;
    for(int i=k;i>=1;i--)
    {
        f[i]=pows(k/i,n);
        for(int j=2*i;j<=k;j+=i)
        {
            f[i]=(f[i]-f[j]+mod)%mod;
        }
    }
    ll ans=0;
    for(int  i=1;i<=k;i++)
    {
        ans+=1ll*i*f[i]%mod;
        ans%=mod;
    }
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 4412
s = list(input())
t = list(input())
abc = [chr(i) for i in range(97, 97+26)]
def index(list, char):
    return tuple(i for i, c in enumerate(list) if c == char)
s_ = [index(s, _) for _ in abc]
t_ = [index(t, _) for _ in abc]
print('Yes' if set(s_) == set(t_) else 'No')

Measured memory_bytes: 22508
#include <bits/stdc++.h>
template<class T> inline bool chmin(T&a, T b){if(a > b){a = b; return true;}else{return false;}}
template<class T> inline bool chmax(T&a, T b){if(a < b){a = b; return true;}else{return false;}}
#define ll long long
#define double long double
#define rep(i,n) for(int i=0;i<(n);i++)
#define REP(i,n) for(int i=1;i<=(n);i++)
#define mod (ll)(1e9+7)
#define inf (ll)(3e18+7)
#define pi (double) acos(-1.0)
#define P pair<int,int>
#define PiP pair<ll,pair<ll,ll>>
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(),x.rend()
using namespace std;

int main(){
    ll n, d, ans = 0;
    cin >> n >> d;
    d *= d;
    rep(i, n){
        ll x, y;
        cin >> x >> y;
        if(d >= x*x+y*y)ans++;
    }
    cout << ans << endl;
}

Measured memory_bytes: 3632
#include<iostream>
#include<math.h>
using namespace std;
int main(void)
{
	int a[3];
	int b[3];
	int c[4] = { 0,0,0,0 };
	int ans = 0;

	for (int i = 0;i < 3;i++)
	{
		cin >> a[i] >> b[i];
	}

	for (int i = 0;i < 3;i++)
	{
			c[b[i]-1] += 1;
			c[a[i]-1] += 1;
	}

	for (int i = 0;i < 4;i++)
	{
		if (c[i] == 1)
			ans++;
	}

	if (ans == 2)
		cout << "YES" << endl;
	else
		cout << "NO" << endl;

	return 0;
}

Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main(void){
    int N;
    int d[110];
    
    cin >> N;
    for(int i = 0; i < N; ++i) cin >> d[i];
    
    int num[110] = {0};
    for(int i = 0; i < N; ++i){
        num[d[i]]++;
    }
    
    int res = 0;
    for(int i = 1; i <= 100; ++i){
        if(num[i]) ++res;
    }
    
    cout << res << endl;
}


Measured memory_bytes: 256
/* AOJ0033 Ball */

#include <stdio.h>

#define N 10

int main(void)
{
    int n, ans, i;

    scanf("%d", &n);
    while(n--) {
        ans = 1;
        int a, b=-1, c=-1;
        for(i=1; i<=N; i++) {
            scanf("%d", &a);
            if(ans) {
                if(a > b)
                    b = a;
                else if(a > c)
                    c = a;
                else
                    ans = 0;
            }
        }

        printf("%s\n", ans ? "YES" : "NO");
    }

    return 0;
}

Measured memory_bytes: 2572
import java.util.Scanner;

public class Main {

    public static void main(String[] args) throws Exception {
        Scanner input = new Scanner(System.in);
        StringBuilder build = new StringBuilder();
        int n = input.nextInt();
        for(int i = 1; i <= n; i++){
            if(i%3 == 0 || i%10 == 3){
                build.append(" "+i);
                continue;
            }
            int x = i;
            do{
                x /= 10;
                if(x%10 == 3){
                    build.append(" "+i);
                    break;
                }
            }while(x >= 30);
        }
        System.out.println(build);
    }
}

Measured memory_bytes: 28284
import java.util.*;

class Main {
    public static void main(String args[]) {
        Scanner sc = new Scanner(System.in);
        int x = sc.nextInt();
        int a = sc.nextInt();
        int b = sc.nextInt();
        int result = x - a;
        while(result >= b) {
            result -= b;
        }
        System.out.println(result);
    }
}

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

#define select(_1, _2, x, ...) x

#define repn(i, n) for (int i = 0; i < (n); i++)
#define repr(i, a, b) for (int i = (a); i < (b); i++)
#define rep(i, ...) select(__VA_ARGS__, repr, repn)(i, __VA_ARGS__)

#define rrepn(i, n) for (int i = (n - 1); i >= 0; i--)
#define rrepr(i, a, b) for (int i = (b - 1); i >= (a); i--)
#define rrep(i, ...) select(__VA_ARGS__, rrepr, rrepn)(i, __VA_ARGS__)

#define umax(m, x) (m = max(m, x));
#define umin(m, x) (m = min(m, x));

#define rng(v) v.begin(), v.end()
#define rrng(v) v.rbegin(), v.rend()

#define debug(x) cerr << #x << " = " << x << endl

using namespace std;

using ll = long long int;

using vi = vector<int>;
using vl = vector<ll>;
using vb = vector<bool>;
using vc = vector<char>;
using vs = vector<string>;

using vvi = vector<vector<int>>;
using vvl = vector<vector<ll>>;
using vvb = vector<vector<bool>>;
using vvc = vector<vector<char>>;
using vvs = vector<vector<string>>;

const int INF = 1e9;
const ll LINF = 1e18;

inline void yn(bool f) { cout << (f ? "Yes" : "No") << endl; }


int main() {
    int n, k;
    cin >> n >> k;
    vi x(n);
    rep(i, n) cin >> x[i];

    ll sum = 0;
    rep(i, n)
        sum += min(x[i], abs(x[i] - k)) * 2;

    cout << sum << endl;

    return 0;
}


Measured memory_bytes: 256
import java.util.*;

public class Main {
  public static void main(String[] args) {
    Scanner scn = new Scanner(System.in);
    long A = scn.nextLong();
    long B = scn.nextLong();
    long C = scn.nextLong();
    long D = scn.nextLong();

    long multiple_C_num = (A - 1) / C;
    long multiple_D_num = (A - 1) / D;
    long multiple_CD_num = multiple_C_num + multiple_D_num - ((A - 1) / lcm(C, D));
    long notMultiple_num_A = (A - 1) - multiple_CD_num;
    if (notMultiple_num_A < 0) {
      notMultiple_num_A = 0;
    }

    multiple_C_num = B / C;
    multiple_D_num = B / D;
    multiple_CD_num = multiple_C_num + multiple_D_num - (B / lcm(C, D));
    long notMultiple_num_B = B - multiple_CD_num;
    if (notMultiple_num_B < 0) {
      notMultiple_num_B = 0;
    }

    System.out.println(notMultiple_num_B - notMultiple_num_A);

  }

  public static long gcd(long a, long b) {
    if (b == 0) {
      return a;
    }
    return gcd(b, a % b);

  }

  public static long lcm(long a, long b) {
    return (a * b) / gcd(a, b);
  }
}

Measured memory_bytes: 23252
<?php

$n = intval(fgets(STDIN));

$a = [];

array_fill(20002, 20002, 0);
// for($i = 0; $i <= 2000002 ; $i++){
//   $a[] = '';
// }
$head = 10000;
$tail = 10000;
for($i=0; $i<$n; $i++) {
  $g = preg_split("/[\s,]+/", fgets(STDIN));
  $q = intval($g[0]);
  if ($q === 0) {
    if(intval($g[1])===0){
      $head--;
      $a[$head] = $g[2];
      // var_dump($a);
    } else {
      $a[$tail] = $g[2];
      $tail++;
    }
  } else if ($q === 1){
    echo $a[$head+intval($g[1])] . "\n";
  } else {
    if(intval($g[1])===0){
      $head++;
    } else {
      $tail--;
    }
  }
}


Measured memory_bytes: 78892
#include <stdio.h>

int main(void){
    int i;
    
    int n;
    scanf("%d\n",&n);
    int a[n];
    for(i=0;i<n;i++)scanf("%d ",&a[i]);
    
    int m;
    scanf("%d\n",&m);
    if(m>n){
        printf("0\n");
        return 0;
    }
    int b[m];
    for(i=0;i<m;i++)scanf("%d ",&b[i]);
    
    int j;
    for(i=0,j=0;i<m;i++){
        for(;j<n;j++){
            if(a[j]==b[i])break;
            else if(a[j]>b[i]){
                printf("0\n");
                return 0;
            }
        }
        if(m-i>n-j){
            printf("0\n");
            return 0;
        }
    }
    
    printf("1\n");
    
    return 0;
}



Measured memory_bytes: 3236
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <tuple>

using namespace std;

#define all(c) (c).begin(), (c).end()

int main(){
    int N, Q;
    while(cin >> N >> Q, N|Q){
        typedef tuple<int, int, string> Data;
        vector<Data> era;
        while(N--){
            string name;
            int eyear, wyear;
            cin >> name >> eyear >> wyear;
            era.emplace_back(wyear - eyear + 1, wyear, name);
        }
        sort(all(era));
        auto comp = [](Data& d, int x){return get<1>(d) < x;};
        while(Q--){
            int query, one = 0, known = 0;
            string name;
            cin >> query;
            if(query <= get<1>(era.back()))tie(one, known, name) = *lower_bound(all(era), query, comp);
            if(one <= query && query <= known)cout << name << " " << query - one + 1 << '\n';
            else cout << "Unknown\n";
        }
    }
    return 0;
}

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

#define ll long long
#define ld long double
#define db double
#define str string
#define pb push_back
#define nl '\n'
#define X first
#define Y second
#define nimble ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define all(v) (v).begin(),(v).end()
#define rall(v) rbegin(v),rend(v)
#define selp(a) for(auto i:a)cout<<i<<" ";cout<<nl;
#define mod(x,m) ((((x)%(m))+(m))%(m))
#define _sz(x) (int)x.size()
#define rep(i,a,b) for(int i=a;i<b;i++)
#define repv(v) for(int i=0;i<_sz(v);i++)
#define rep1(i,b,a) for(int i=b;i>=a;i--)
#define preci(x) fixed<<setprecision(x)

#define TRACE
#ifdef TRACE
#define see(...) __f(#__VA_ARGS__,__VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
	cerr<<name<<" : "<<arg1<<nl;
}
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...);
}
#else
#endif

int inf=0x3f3f3f3f;
ll infl=0x3f3f3f3f3f3f3f3fLL;
ld infd=1.0/0.0;
const ll MOD=1e9+7;// 998244353 // = (119<<23)+1
const db pi=2*acos(0.0);

int main(){
  nimble;
  int tt=1;//cin>>tt;
  while(tt--){
    int h,a;
    cin>>h>>a;
    h=h/a+bool(h%a);
    cout<<h;
  }
  return 0;
}


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

using namespace std;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  int N;
  cin >> N;
  vector<int> A(N), B(N), CA(N, 0), CB(N, 0);
  for (auto&& e : A) {
    cin >> e;
    e--;
    CA[e]++;
  }
  for (auto&& e : B) {
    cin >> e;
    e--;
    CB[e]++;
  }
  // priority_queue<pair<int, int>, vector<pair<int, int>>, greater<pair<int, int>>> que;
  priority_queue<pair<int, int>> que;
  queue<int> only_a, only_b;
  for (int i = 0; i < N; i++) {
    if (CA[i] > 0 && CB[i] > 0) {
      que.push(make_pair(CA[i] + CB[i], i));
    } else if (CA[i] > 0) {
      for (int j = 0; j < CA[i]; j++) {
        only_a.push(i);
      }
    } else if (CB[i] > 0) {
      for (int j = 0; j < CB[i]; j++) {
        only_b.push(i);
      }
    }
  }
  if (!que.empty() && que.top().first > N) {
    cout << "No" << '\n';
    return 0;
  }
  cout << "Yes" << '\n';
  vector<pair<int, int>> res;
  while (!que.empty()) {
    auto [_, x] = que.top();
    que.pop();
    int y;
    bool flag;
    if (!que.empty()) {
      y = que.top().second;
      que.pop();
      flag = true;
    } else {
      y = only_b.front();
      only_b.pop();
      flag = false;
    }
    CA[x]--, CB[y]--;
    res.emplace_back(make_pair(x, y));
    if (CA[x] > 0) {
      que.push(make_pair(CA[x] + CB[x], x));
    } else {
      for (int i = 0; i < CB[x]; i++) {
        only_b.push(x);
      }
    }
    if (flag && CB[y] > 0) que.push(make_pair(CA[y] + CB[y], y));
    if (flag && CB[y] == 0) {
      for (int i = 0; i < CA[y]; i++) {
        only_a.push(y);
      }
    }
  }
  while (!only_a.empty()) {
    int x = only_a.front(), y = only_b.front();
    only_a.pop(), only_b.pop();
    res.emplace_back(make_pair(x, y));
  }
  sort(res.begin(), res.end());
  for (const auto& e : res) {
    cout << e.second + 1 << (&e == &res.back() ? '\n' : ' ');
  }
  return 0;
}


Measured memory_bytes: 11624
import java.util.Arrays;
import java.util.Scanner;

public class Main {
public static void main(String[] args) {
		
		Scanner keyboard = new Scanner(System.in); 
		
		int N  = keyboard.nextInt();
		int[] T = new int[N];
		int sum = 0;
        
        for(int i = 0; i < N; i++){
          T[i]  = keyboard.nextInt();
          sum += T[i];
        }
        
		int M  = keyboard.nextInt();
		
		int[] P = new int[M];
		int[] X = new int[M];
		int[] ans = new int[M];
		
		for(int j = 0; j < M; j++){
          P[j]  = keyboard.nextInt();
          X[j]  = keyboard.nextInt();
          ans[j] = sum - T[P[j]-1] +X[j] ;
        }
        
        for(int k = 0; k < M; k++){
		System.out.println(ans[k]);
		}
		keyboard.close();	
	}
}


Measured memory_bytes: 21844
#include <bits/stdc++.h>
using namespace std;
 
#define rep(i,n) for (int i = 0; i<(n); i++)
#define in(n) cin >> (n)
#define out(ans) cout << (ans) << endl;
using ll = int64_t;
using v = vector<int>;
 
int main() {
  int S, W;
  cin >> S >> W;
  if (S<=W) cout << "unsafe" << endl;
  else cout << "safe" << endl;
}

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

const int MAX = 510000;
const int mod = 1000000007;

long long fac[MAX]; //i!%mod=fac[i]
long long finv[MAX]; //pow(i!,-1)%mod=finv[i]
long long inv[MAX]; //pow(i,-1)%mod=inv[i]

// テーブルを作る前処理
void perinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % mod;
        inv[i] = mod - inv[mod%i] * (mod / i) % mod;
        finv[i] = finv[i - 1] * inv[i] % mod;
    }
}

// 二項係数計算
long long per(int n, int k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * finv[n-k] % mod;
}

int n;
long long k,ans;
set<int> edge[100005];

void dfs(int now)
{
	if (now==0)
	{
		ans*=per(k-1,edge[now].size());
	}
	else
	{
		ans*=per(k-2,edge[now].size());
	}
	ans%=mod;
	for (auto i = edge[now].begin(); i != edge[now].end(); ++i)
	{
		edge[*i].erase(now);
		dfs(*i);
	}
}

int main(int argc, char const *argv[])
{
	perinit();
	cin>>n>>k;
	int a,b;
	for (int i = 0; i < n-1; ++i)
	{
		cin>>a>>b;
		--a,--b;
		edge[a].insert(b);
		edge[b].insert(a);
	}
	ans=k;
	dfs(0);
	cout<<ans<<endl;
	return 0;
}


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


signed main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout << fixed << setprecision(20);

    ll n;
    string s;
    cin>>n>>s;
    map<pair<string,string>,ll> mp1,mp2;
    for(int bit=0;bit<(1<<n);bit++){
        string r1,r2,b1,b2;
        for(int i=0;i<n;i++){
            if(bit&(1<<i)){
                r1 += s[i];
                r2 += s[n+i];
            }
            else{
                b1 += s[i];
                b2 += s[n+i];
            }
        }
        reverse(b1.begin(),b1.end());
        reverse(b2.begin(),b2.end());
        mp1[make_pair(r1,b1)]++;
        mp2[make_pair(b2,r2)]++;
    }
    ll ans = 0;
    for(auto i:mp1){
        ans += i.second * mp2[make_pair(i.first.first,i.first.second)];
    }
    cout << ans << endl;
}

Measured memory_bytes: 103424
#pragma GCC optimize("O3")
#pragma GCC optimize ("unroll-loops")
#pragma GCC target ("avx2")
#define io_init cin.tie(0);ios::sync_with_stdio(0);cout<<setprecision(20)
#include <bits/stdc++.h>
constexpr int INF = 2147483647;
constexpr long long int INF_LL = 9223372036854775807;
constexpr int MOD = 1000000007;
constexpr double PI = 3.14159265358979323846;
using namespace std;
typedef long long int ll;
typedef unsigned long long int ull;

// -10 -10
// 10 10
// -9 9
// 9 -9
// -9 -9 10 10
int main() {
	int N, K;
	cin >> N >> K;
	vector<ll> x(N), y(N);
	for (int i = 0; i < N; i++)cin >> x[i] >> y[i];
	ll ans = INF_LL;
	for (int i = 0; i < N; i++)for (int j = 0; j < N; j++) {
		for (int k = 0; k < N; k++)for (int s = 0; s < N; s++) {
			ll xmax = max(x[i], x[j]), xmin = min(x[i], x[j]), ymax = max(y[k], y[s]), ymin = min(y[k], y[s]);
			int cnt = 0;
			for (int t = 0; t < N; t++) {
				if (xmin <= x[t] && x[t] <= xmax && ymin <= y[t] && y[t] <= ymax)cnt++;
			}
			if (cnt >= K)ans = min(ans, abs(xmax - xmin) * abs(ymax - ymin));
		}
	}
	cout << ans << endl;
}

Measured memory_bytes: 3628
#include <bits/stdc++.h>
#define f(i,j,k) for(int i=j;i<k;i++)
using namespace std;
int main(){
    long long n,m,a,b;
    cin>>n>>m;
    vector<long long> ans(n,0);
    f(i,0,m){
        cin>>a>>b;
        ans[a-1]++;
        ans[b-1]++;
    }
    f(i,0,n){
        cout<<ans[i]<<endl;
    }
    return 0;
}


Measured memory_bytes: 3636
#include<bits/stdc++.h>
#define watch(x) cout << (#x) << " is " << (x) << endl
typedef long long ll;
using namespace std;
int static fast = [](){
  ios::sync_with_stdio(false);
  cin.tie(0); cout.tie(0); return 0;
}();

int main() {
    int n, C, s, t, c;
    cin >> n >> C;
    int ans = 0;
    unordered_map<int, vector<int>> rec;
    for(int i = 0; i < n; i++) {
        cin >> s >> t >> c;
        rec[c].push_back(s);
        rec[c].push_back(t);
    }
    map<int, int> rec2;
    for(auto p: rec) {
        auto& vec = p.second;
        sort(vec.begin(), vec.end());
        vector<int> st;
        for(int i = 0; i < vec.size(); i++) {
            if (!st.empty() && vec[i] == st.back()) {
                st.pop_back();
            } else {
                st.push_back(vec[i]);
            }
        }
        for(int i = 0; i < st.size(); i+= 2) {
            rec2[st[i]-1] += 1;
            rec2[st[i+1]] -= 1;
        }
    }
    int cur = 0;
    for(auto p: rec2) {
        cur += p.second;
        ans = max(ans, cur);
    }
    cout << ans << endl;
    return 0;
}




Measured memory_bytes: 5504
#include <stdio.h>
#include <stdlib.h>
#include <iostream>
#include <iomanip>
#include <vector>
#include <string.h>
#include <string>
#include <map>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <math.h>
#include <algorithm>
#include <numeric>

using namespace std;

// マクロ&定数 ============================================================
typedef unsigned int uint;
typedef long long ll;
//typedef pair<int, int> P;

typedef vector<int> vint;
typedef vector<ll> vll;
typedef vector<double> vdouble;
typedef vector<bool> vbool;
typedef vector<string> vstring;

typedef vector<pair<int, int>> vpint;
typedef vector<pair<ll, ll>> vpll;
typedef vector<pair<double, double>> vpdouble;

typedef vector<vector<int>> vvint;
typedef vector<vector<ll>> vvll;
typedef vector<vpint> vvpint;
typedef vector<vpll> vvpll;
typedef vector<vector<double>> vvdouble;
typedef vector<vector<string>> vvstring;
typedef vector<vector<bool>> vvbool;

typedef vector<vector<vector<ll>>> vvvll;

const int c_YET = -1;
const int INF = 1e9 + 1;
const ll LLINF = 1e17 + 1;
const int DX[9] = { 0,0,1,-1, 1, 1, -1, -1, 0 }; // 4;４近傍
const int DY[9] = { 1,-1,0,0, 1, -1, 1, -1, 0 }; // 8:８近傍 9:(0,0)を含む
const ll MOD = 1e9 + 7; //10^9 + 7
const ll MAX = 1e9;
const double PI = 3.14159265358979323846264338327950288;
//========================================================================





int main() {

	////==================================
	cin.tie(nullptr);
	ios_base::sync_with_stdio(false);
	cout << fixed << setprecision(30);
	////==================================
	

	int N;
	cin >> N;
	vdouble A(N);
	for (int i = 0; i < N; i++)
	{
		cin >> A[i];
	}

	double avr = 0;
	for (int i = 0; i < N; i++)
	{
		avr += A[i];
	}

	avr /= N;

	vector<pair<double, int>> dis(N);
	for (int i = 0; i < N; i++)
	{
		double d = avr - A[i];
		if (d < 0)
		{
			d = -d;
		}


		dis[i] = { d, i };
	}
	
	sort(dis.begin(), dis.end());

	cout << dis[0].second << endl;


}





Measured memory_bytes: 256
#include<bits/stdc++.h>
#include<boost/variant.hpp>
using namespace std;
typedef long long ll;
typedef vector<boost::variant<bool, ll, int, string, double, char*, const char*>> any;
template<typename T> inline void pr(const vector<T> &xs){
	for(int i=0; i<xs.size()-1; i++) cout<<xs[i]<<" ";
	(xs.empty()?cout:(cout<<xs[xs.size()-1]))<<endl;
}
template<typename T> inline void debug(const vector<T> &xs){
#ifdef DEBUG
	pr(xs);
#endif
}

int main(){
	int N;
	cin >> N;
	vector<int> L(N), R(N);
	for(int i=0; i<N; i++) cin >> L[i] >> R[i];

	vector<pair<int, int>> ls(N), rs(N);
	for(int i=0; i<N; i++){
		ls[i] = {L[i], i};
		rs[i] = {R[i], i};
	}
	sort(ls.begin(), ls.end());
	reverse(ls.begin(), ls.end());
	sort(rs.begin(), rs.end());

	ll ans1 = 0;
	vector<bool> used(N);
	ll cur = 0;
	int li = 0, ri = 0;
	for(int i=0; i<N; i++){
		if(i%2){
			while(ri<N&&used[rs[ri].second]) ri++;
			if(ri==N || cur<rs[ri].first) break;
			ans1 += cur-rs[ri].first;
			used[rs[ri].second] = true;
			cur = rs[ri].first;
		} else {
			while(li<N&&used[ls[li].second]) li++;
			if(li==N||ls[li].first<cur) break;
			ans1 += ls[li].first-cur;
			used[ls[li].second] = true;
			cur = ls[li].first;
		}
	}
	ans1 += abs(cur);
	ll ans2 = 0;
	used.assign(N, false);
	cur = 0;
	li = 0;
	ri = 0;
	for(int i=0; i<N; i++){
		if(i%2==0){
			while(ri<N&&used[rs[ri].second]) ri++;
			if(ri==N || cur<rs[ri].first) break;
			ans2 += cur-rs[ri].first;
			used[rs[ri].second] = true;
			cur = rs[ri].first;
		} else {
			while(li<N&&used[ls[li].second]) li++;
			if(li==N||ls[li].first<cur) break;
			ans2 += ls[li].first-cur;
			used[ls[li].second] = true;
			cur = ls[li].first;
		}
	}

	ans2 += abs(cur);

	cout << max(ans1, ans2) << endl;

	return 0;
}


Measured memory_bytes: 2560
use std::io;
fn main(){
    let mut s=String::new();
    let mut t=String::new();
    io::stdin().read_line(&mut s).unwrap();
    io::stdin().read_line(&mut t).unwrap();
    let mut ans=0;
    for i in 0..s.len(){
        if s.as_bytes()[i]!=t.as_bytes()[i]{
            ans+=1;
        }
    }
    println!("{}",ans);
    }


Measured memory_bytes: 2456
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
using P = pair<ll, ll>;
#define rep(i, n)  for (int i = 0; i <  (int)(n); i++)
#define rep1(i, n) for (int i = 1; i <= (int)(n); i++)
#define all(x) (x).begin(), (x).end()
const ll INF = ll(1e18)+1;

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

    ll X;
    cin >> X;

    ll limit = 200;
    vector<ll> test_vec(limit*2+1);

    rep(i,test_vec.size()){
        test_vec[i] = i-200;
    }

    bool flag = false;
    for(ll i : test_vec){
        for(ll j : test_vec){
            if(pow(i,5) - pow(j,5) == X){
                cout << i << " " << j;
                flag = true;
                break;
            }
        }
        if(flag) break;
    }
}

Measured memory_bytes: 4072
#include<stdio.h>
int n,i,flg[100000000],flg1[100000000],j,cnt=0;
int main(void){
	for(i=2;i<=10000000;i++){
		flg[i]=1;
	}
	for(i=2;i*i<=10000000;i++){
		if(flg[i]==1){
			for(j=2;j*i<=10000000;j++){
				flg[j*i]=0;
			}
		}
	}
	scanf("%d",&n);
	while(n!=0){
		for(i=n;i>=0;i--){
			if(flg[i]==1){
				if(flg[i-2]==1){
					if(flg[i-6]==1){
						if(flg[i-8]==1){
							printf("%d\n",i);
							break;
						}
					}
				}
			}
		}
		scanf("%d",&n);
	}
	return 0;
}

Measured memory_bytes: 41564
#include<bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>

#define mod 1000000007 
#define check exit(0)
#define ordered_set tree<int,null_type,less_equal<int>,rb_tree_tag,tree_order_statistics_node_update>
#define ll long long int
#define trace(x) cerr<<#x<<" : "<<x<<endl;
#define jaldi ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);

using namespace __gnu_pbds;
using namespace std;

int main()
{
    jaldi
    int n;
    cin>>n;
    vector<vector<int>> v(n,vector<int>(3));
    vector<vector<int>> dp(n,vector<int>(3,-1));
    for(int i=0;i<n;i++)
    {
        for(int j=0;j<3;j++) cin>>v[i][j];
    }
    for(int i=0;i<3;i++) dp[0][i]=v[0][i];
    for(int i=1;i<n;i++)
    {
        for(int j=0;j<3;j++)
        {
            for(int k=0;k<3;k++)
            {
                if(j==k) continue;
                dp[i][j]=max(dp[i][j],dp[i-1][k]+v[i][j]);
            }
        }
    }
    cout<<max({dp[n-1][0],dp[n-1][1],dp[n-1][2]});
    return 0;
}


Measured memory_bytes: 11264
;; E - Almost Everywhere Zero

(defun choose (n k)
  (labels ((choose-r (n k acc)
             (if (zerop k) acc
                 (choose-r (1- n) (1- k) (* acc (/ n k))))))
    (if (or (< n k) (minusp k)) 0
        (choose-r n k 1))))

(defun solve (n l k)
  "nは10進数字列. 0でない数字がちょうどk個ある1以上n以下の整数の個数"
  (cond
    ((zerop k) 1)
    ((zerop l) 0)
    ((zerop (car n)) (solve (cdr n) (1- l) k))
    (t (+
          ; 先頭桁が0の数の個数
          (* (choose (1- l) k) (expt 9 k))
          ; 先頭が1以上n[0]未満の数の個数
          (* (1- (car n)) (choose (1- l) (1- k)) (expt 9 (1- k)))
          ; 先頭がn[0]の数の個数
          (solve (cdr n) (1- l) (1- k))))))

(let* ((n (map 'list #'digit-char-p (read-line)))
       (k (read))
       (l (length n)))
  (princ (solve n l k)))


Measured memory_bytes: 13032
#include <cstdio>

int ans[5];

int N,M;
int request[10][2];

int main(){
    scanf("%d%d",&N,&M);
    if (N>1)
        ans[N]=1;

    for(int i=1;i<=M;i++){
        int s,c;
        scanf("%d%d",&s,&c);
        request[i][0]=s;
        request[i][1]=c;
        ans[N+1-s]=c;
    }

    bool ok=(ans[N]!=0)||N==1;
    for(int i=1;i<=M;i++)
        ok=ok&&(ans[N+1-request[i][0]]==request[i][1]);

    if (ok){
        for(int i=N;i>=1;i--) printf("%d",ans[i]);
        putchar('\n');
    }else puts("-1");


    return 0;
}

Measured memory_bytes: 128
import java.util.*;

public class Main {
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int numbers[] = new int[3];
        int countNormal = 0;
        int countRight = 0;
        int countAcute = 0;
        int countObtuse = 0;
        while(true){
            for(int i = 0; i < 3; i++){
                numbers[i] = sc.nextInt();
            }
            Arrays.sort(numbers);
            if(numbers[0] + numbers[1] <= numbers[2]){
                break;
            }else{
                countNormal++;
                if(numbers[0] * numbers[0] + numbers[1] * numbers[1] == numbers[2] * numbers[2]){
                    countRight++;
                }else if(numbers[0] * numbers[0] + numbers[1] * numbers[1] < numbers[2] * numbers[2]){
                    countObtuse++;
                }else{
                    countAcute++;
                }
            }
         }
        System.out.println(countNormal + " " + countRight + " " +countAcute + " " + countObtuse);
    }
}


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

int main() {
    int H, W, N; cin >> H >> W >> N;
    if (N % max(H, W) == 0) {
        cout << N / max(H, W) << endl;
    } else {
        cout << N / max(H, W) + 1 << endl;
    }
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
#include <math.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep2(i, n) for (int i = n; i > 0; i--)
#define rep3(i, s, e) for (int i = (s); i < (int)(e); i++)
#define rep4(i, s, e) for (int i = (e); i < (int)(s); i--)

int main() {
    int h, w;
    cin >> h >> w;
    vector<string > str(h);

    rep(i, h) {
        cin >> str.at(i);
    }
    rep(i, w+2){
        cout << "#";
    }
    cout << endl;

    rep(i, h){
        cout << "#" << str.at(i) << "#" << endl;
    }
    rep(i, w+2){
        cout << "#";
    }
    cout << endl;
}


Measured memory_bytes: 256
h, w = map(int, input().split())
cc = [[int(x) for x in input().split()] for i in range(10)]

for k in range(10):
    for i in range(10):
        for j in range(10):
            cc[i][j] = min(cc[i][j], cc[i][k] + cc[k][j])

ans = 0
for i in range(h):
    aa = map(int, input().split())
    for a in aa:
        if a >= 0:
            ans += cc[a][1]

print(ans)

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

int A, B, C, D;

int main(){
    ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
    cin >> A >> B >> C >> D;
    int n = (C + B - 1) / B;
    int m = (A + D - 1) / D;
    if(n <= m){
        cout << "Yes" << endl;
    }else{
        cout << "No" << endl;
    }
    return 0;
}


Measured memory_bytes: 3648
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.StringTokenizer;

public class Main {

	public static void main(String[] args) {
		FastScanner fc = new FastScanner(System.in);

		int K = fc.nextInt();
		int S = fc.nextInt();

		int count = 0;

		for (int i = 0; i <= K; i++) {
			for (int j = 0; j <= K; j++) {
				int temp = S - i - j;
				if (temp >=0 && temp <=K) count++;
			}
		}

		System.out.println(count);

	}

	static class FastScanner {

		private BufferedReader reader = null;
	    private StringTokenizer tokenizer = null;

	    public FastScanner(InputStream in) {
	        reader = new BufferedReader(new InputStreamReader(in));
	        tokenizer = null;
	    }

	    public String next() {
	        if (tokenizer == null || !tokenizer.hasMoreTokens()) {
	            try {
	                tokenizer = new StringTokenizer(reader.readLine());
	            } catch (IOException e) {
	                throw new RuntimeException(e);
	            }
	        }
	        return tokenizer.nextToken();
	    }

	    public String nextLine() {
	        if (tokenizer == null || !tokenizer.hasMoreTokens()) {
	            try {
	                return reader.readLine();
	            } catch (IOException e) {
	                throw new RuntimeException(e);
	            }
	        }

	        return tokenizer.nextToken("\n");
	    }

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

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

	    public double nextDouble() {
	         return Double.parseDouble(next());
	     }

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

	    public long[] nextLongArray(int n) {
	        long[] a = new long[n];
	        for (int i = 0; i < n; i++)
	            a[i] = nextLong();
	        return a;
	    }

	}


}


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

int main(){
    int n;
    int m;
    int x;
    int y;
    int ar_x[100];
    int ar_y[100];
    int maxx=-101;
    int maxy=101;
    cin>>n>>m>>x>>y;
    for(int i=0;i<n;i++){
        cin>>ar_x[i];
        if (ar_x[i]>maxx){maxx=ar_x[i];}
    }
    if (x>maxx){maxx=x;}
    for(int i=0;i<m;i++){
        cin>>ar_y[i];
        if (ar_y[i]<maxy){maxy=ar_y[i];}
    }
    if (y<maxy){maxy=y;}
    if (maxy-maxx>=1){cout<<"No War";}
    else{cout<<"War";}
}


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


int main(){

	//num2???????????????1???6???????????????case??????????????????????????????
	int num, num1, num2,num2_dice,count;
	int Dice[6] = {};//{0,1,2,3,4,5}={???,S,E,W,N,???}
	for (int i = 0; i < 6; i++){//???????????????????????°????????£??\
		cin >> num;
		Dice[i] = num;
	}

	cin >> count;//??????????????°

	for (int j = 0; j < count; j++){
		cin >> num1 >> num2;

		//num2???1???6??¨????????????????????????num2_dice?????£??\
		for (int i = 0; i < 6; i++){
			if (num2 == Dice[i]){
				num2_dice = i + 1;
			}
		}


		
		if (num1 == Dice[0]){


		switch (num2_dice) {

		case 2:
		cout << Dice[2];
		break;

		case 3:
		cout << Dice[4];
		break;

		case 5:
		cout << Dice[3];
		break;

		case 4:
		cout << Dice[1];
		break;
		}
		}
		else if (num1 == Dice[1]){

		switch (num2_dice) {

		case 1:
		cout << Dice[3];
		break;

		case 3:
		cout << Dice[0];
		break;

		case 4:
		cout << Dice[5];
		break;

		case 6:
		cout << Dice[2];
		break;
		}
		}
		else if (num1 == Dice[2]){

		switch (num2_dice) {

		case 1:
		cout << Dice[1];
		break;

		case 2:
		cout << Dice[5];
		break;

		case 6:
		cout << Dice[4];
		break;

		case 5:
		cout << Dice[0];
		break;
		}
		}
		else if (num1 == Dice[3]){

		switch (num2_dice) {

		case 2:
		cout << Dice[0];
		break;

		case 1:
		cout << Dice[4];
		break;

		case 5:
		cout << Dice[5];
		break;

		case 6:
		cout << Dice[1];
		break;
		}
		}
		else if (num1 == Dice[4]){

		switch (num2_dice) {

		case 1:
		cout << Dice[2];
		break;

		case 3:
		cout << Dice[5];
		break;

		case 6:
		cout << Dice[3];
		break;

		case 4:
		cout << Dice[0];
		break;
		}
		}
		else if (num1 == Dice[5]){

		switch (num2_dice) {

		case 2:
		cout << Dice[3];
		break;

		case 4:
		cout << Dice[4];
		break;

		case 5:
		cout << Dice[2];
		break;

		case 3:
		cout << Dice[1];
		break;
		}
		}
		cout << endl;

	}//?????????????????????

	return 0;
}

Measured memory_bytes: 1160