akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <queue>
#include <algorithm>
#include <string>
#include <vector>
#include <map>
#include <iomanip>
#include <cmath>
#include <cstdlib>
#include <math.h>
#include <stdlib.h>
#include <numeric>


int main(){
	int h, w;
	char input;
	int dark[1000][1000];
	std::queue<std::pair<int,int>> que;
	bool zero = true;
	std::cin >> h >> w;
	for(int i = 0; i < h; i++){
		for(int j = 0; j < w; j++){
			std::cin >> input;
			if(input == '#'){
				dark[i][j] = 0;
				que.push({i,j});
			}else{
				dark[i][j]= 5000;
				zero = false;
			}
		}
	}
	if(zero){
		std::cout << 0 << std::endl;
		return 0;
	}
	int maxx = 0;
	while(!que.empty()){
		int i = que.front().first, j = que.front().second;
		que.pop();
		maxx = std::max(maxx, dark[i][j]);
		if(i != 0 && dark[i-1][j] == 5000){
			dark[i-1][j] = dark[i][j] + 1;
			que.push({i-1,j});
		}
		if(i != h-1 && dark[i+1][j] == 5000){
			dark[i+1][j] = dark[i][j] + 1;
			que.push({i+1,j});
		}
		if(j != 0 && dark[i][j-1] == 5000){
			dark[i][j-1] = dark[i][j] + 1;
			que.push({i,j-1});
		}
		if(j != w-1 && dark[i][j+1] == 5000){
			dark[i][j+1] = dark[i][j] + 1;
			que.push({i,j+1});
		}
	}
	
	std::cout << maxx << std::endl;
	return 0;
}



Measured memory_bytes: 12304
//  SMOKE SHISHA PLAY FIFA  // 
#include<bits/stdc++.h>
using namespace std;

typedef long long int ll;
typedef long double ld;

#define fastio ios_base::sync_with_stdio(false); cin.tie(NULL);
#define pll pair<ll,ll>
#define MP make_pair
#define ff first
#define ss second
#define PB push_back
#define mod 1000000007
#define lp(i,start,end) for(ll i=start;i<=end;i++) 
#define deb1(a) cout<<#a<<" = "<<(a)<<endl;
#define deb2(a,b) cout<<#a<<" = "<<(a)<<", "<<#b<<" = "<<(b)<<endl;
#define deb3(a,b,c) cout<<#a<<" = "<<(a)<<", "<<#b<<" = "<<(b)<<", "<<#c<<" = "<<(c)<<endl;


ll modu(ll a, ll b)
{
	ll ans =1;
	while(b>0)
	{
		if(b&1)
		ans = (ans*a)%mod;
		b/=2;
		a = (a*a)%mod;
	}
	return ans;
}

int main()
{
	fastio
	ll n;
	cin >>n;
	ll po10=1;
	for(ll i=1; i<=n; i++){
		po10=(po10*10)%mod;
	}
	ll po9=1;
	for(ll i=1; i<=n; i++){
		po9=(po9*9)%mod;
	}
	ll po8=1;
	for(ll i=1; i<=n; i++){
		po8=(po8*8)%mod;
	}
	ll ans=((po10-2*po9+po8)%mod+mod)%mod;

	if(n==1)
		cout<<"0"<<endl;
	else
		cout<<ans<<endl;
	
	return 0;	
}


Measured memory_bytes: 3636
#include<stdio.h>
signed main(){
    int k,a,b;
    scanf("%d",&k);
    scanf("%d %d",&a,&b);
    int sum=(b/k)*k;
    if(a<=sum){
        printf("OK\n");
    }else{
        printf("NG\n");
    }
    return(0);
    }

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


void solve(long long N, long long M, long long X, std::vector<long long> A) {
    int cr = 0, cl = 0;
    for (int i = 0; i < M; i++){
        if (A[i] < X)cr++;
        else cl++;
    }
    cout << min(cr, cl) << endl;
}

int main(){
    long long N;
    scanf("%lld",&N);
    long long M;
    scanf("%lld",&M);
    long long X;
    scanf("%lld",&X);
    std::vector<long long> A(M);
    for(int i = 0 ; i < M ; i++){
        scanf("%lld",&A[i]);
    }
    solve(N, M, X, std::move(A));
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<int> vi;
#define endl '\n'
#define fo(i,a,b) for(int i=a;i<=b;i++)
#define rf(i,a,b) for(int i=a;i>=b;i--) 
#define fast_io ios_base::sync_with_stdio(0);
#define show(x) cout<<x<<endl;
#define pret(x) cout<<x<<endl; return 0;
#define disp(x) cout<<x<<" ";
#define let(x,y) cout<<x<<" "<<y<<endl;
ll MOD=1e9+7;
ll MAX=9223372036854775807;

int main(){
    fast_io;
    int x,y;
    cin>>x>>y;
    show(x+y/2);
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <complex>
#include <sstream>
#include <string>
#include <algorithm>
#include <deque>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <vector>
#include <set>
#include <limits>
#include <cstdio>
#include <cctype>
#include <cmath>
#include <cstdlib>
#include <ctime>
using namespace std;
#define REP(i, j) for(int i = 0; i < j; ++i)
#define FOR(i, j, k) for(int i = j; i < k; ++i)
#define P pair<int, int>

int main() {
  int n; cin >>n;
  vector<int> ans(6, 0);
  REP(i, n){
    double h; cin >>h;
    if(h < 165.0) ans[0] += 1;
    else if(h < 170.0) ans[1] += 1;
    else if(h < 175.0) ans[2] += 1;
    else if(h < 180.0) ans[3] += 1;
    else if(h < 185.0) ans[4] += 1;
    else ans[5] += 1;
  }
  REP(i, 6){
    cout <<i + 1 <<":";
    REP(j, ans[i]) cout <<"*";
    cout <<endl;
  }
  return 0;
}

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

public class Main {
  private 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;
    }
  }

  public static void main(String[] args) {
    FastScanner sc = new FastScanner(System.in);
    int d = sc.nextInt();
    int n = sc.nextInt();
    int a = (int) Math.pow(100, d);
    int i = 1;
    int count = 0;
    while (count < n) {
      int val = a * i;
      if (val % a == 0 && val % (a * 100) != 0) {
        count++;
      }
      i++;
    }
    System.out.println(a * (i - 1));
  }
}

Measured memory_bytes: 32868
use std::collections::HashMap;
fn read<T: std::str::FromStr>() -> T {
	let mut s = String::new();
	std::io::stdin().read_line(&mut s).ok();
	s.trim().parse().ok().unwrap()
}

fn read_vec<T: std::str::FromStr>() -> Vec<T> {
	read::<String>().split_whitespace()
		.map(|e| e.parse().ok().unwrap()).collect()
}

fn read_vec2<T: std::str::FromStr>(n: u32) -> Vec<Vec<T>> {
	(0..n).map(|_| read_vec()).collect()
}

pub trait LexicalPermutation {
	/// Return `true` if the slice was permuted, `false` if it is already
	/// at the last ordered permutation.
	fn next_permutation(&mut self) -> bool;
}
impl<T> LexicalPermutation for [T] where T: Ord {
	/// Original author in Rust: Thomas Backman <serenity@exscape.org>
	fn next_permutation(&mut self) -> bool {
		// These cases only have 1 permutation each, so we can't do anything.
		if self.len() < 2 { return false; }

		// Step 1: Identify the longest, rightmost weakly decreasing part of the vector
		let mut i = self.len() - 1;
		while i > 0 && self[i-1] >= self[i] {
			i -= 1;
		}

		// If that is the entire vector, this is the last-ordered permutation.
		if i == 0 {
			return false;
		}

		// Step 2: Find the rightmost element larger than the pivot (i-1)
		let mut j = self.len() - 1;
		while j >= i && self[j] <= self[i-1]  {
			j -= 1;
		}

		// Step 3: Swap that element with the pivot
		self.swap(j, i-1);

		// Step 4: Reverse the (previously) weakly decreasing part
		self[i..].reverse();

		true
	}
}

fn main() {
	let n: usize = read();
	let mut s: Vec<String> = Vec::new();
	for _ in 0..n {
		let tmp: String = read();
		s.push(tmp);
	}

	let mut sorted_s: Vec<String> = Vec::new();
	let mut hash = HashMap::new();

	for si in s {
		let mut tmp: Vec<char> = si.chars().collect();
		tmp.sort_by(|a, b| a.cmp(b));
		let mut chars: String = String::from("");
		for t in tmp {
			chars += &(t.to_string());
		}
		sorted_s.push(chars);
	}

	for si in sorted_s {
		let count = hash.entry(si).or_insert(0);
		*count += 1;
	}

	let mut ans: u64 = 0;
	for (_, v) in hash {
		ans += (v * (v-1))/ 2;
	}

	println!("{}", ans);
}


Measured memory_bytes: 20712
#include<stdio.h>
#define LEN 100005

typedef struct pp{
  char name[100];
  int t;
}P;

P Q[LEN+1];
int head, tail, n;

void enqueue(P x){
  
  Q[tail]=x;
  if(tail==n) tail=0;
  else tail++;
  
}

P dequeue(){
  
  P x;
  x=Q[head];
  if(head==n) head=0;
  else head++;
    
   return x;
}


int main(){
  int elaps = 0, c=0;
  int i, q;
  P u;
  scanf("%d %d", &n, &q);

  for ( i = 1; i <= n; i++){
    scanf("%s", Q[i].name);
    scanf("%d", &Q[i].t);
  }

  head=1;
  tail=0;
  while(c<n){
    u=dequeue();
    
    if(u.t>q){
      u.t-=q;
      elaps+=q;
      enqueue(u);

    }else{
      elaps+=u.t;
      printf("%s %d\n",u.name,elaps);
      c++;
    }
    
  }
  
  return 0;
}



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

using namespace std;

const int M = 1e5;
int n, a[M], b[M], c[M], memo[M][4] = {};

int solve(int i, int last) {
    if (i >= n)
        return 0;

    int r = 0;

    if (memo[i][last])
        r = memo[i][last];
    else {
        if (last != 1)
            r = max(r, a[i] + solve(i + 1, 1));
        if (last != 2)
            r = max(r, b[i] + solve(i + 1, 2));
        if (last != 3)
            r = max(r, c[i] + solve(i + 1, 3));
    }
    memo[i][last] = r;
    return r;
}

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

    cin >> n;
    for (int i = 0; i < n; i++)
        cin >> a[i] >> b[i] >> c[i];
    cout << solve(0, 0) << "\n";
}

Measured memory_bytes: 9216
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define REP(i,m,n) for(int i=(int)(m); i<(int)(n); i++)
#define rep(i,n) REP(i,0,n)
#define RREP(i,m,n) for(int i=(int)(m); i>=(int)(n); i--)
#define rrep(i,n) RREP(i,n-1,0)
#define REPL(i,m,n) for(ll i=(ll)(m); i<(ll)(n); i++)
#define repl(i,n) REPL(i,0,n)
#define all(v) v.begin(), v.end()
const int inf = 1e9+7;
const ll longinf = 1LL<<60;
const ll mod = 1e9+7;

int main() {
  int N;
  cin >> N;
  vector<string> S(N);
  vector<int> T(N);
  map<string, int> mp;
  rep(i, N) {
    cin >> S[i] >> T[i];
    mp[S[i]] = i;
  }
  string X;
  cin >> X;
  vector<ll> sum(N+1);
  rrep(i, N) sum[i] = sum[i+1] + T[i];
  cout << sum[mp[X]+1] << endl;
  return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
long long f(char *s){
  long long n=0,m=0,p=9,i;
  for(i=0;s[i];i++){
    if(s[i]=='.')m=1;
    else{
      n=n*10LL+s[i]-'0';
      p-=m;
    }
  }
  while(p--)n*=10LL;
  return n;
}
int main(){
  int n,i,j,b,c;
  long long l,a[30][30]={};
  double x;
  char s[30];
  scanf("%d",&n);
  for(i=0;i<n;i++){
    //scanf("%lf",&x);
    //l=(x+1e-10)*1e9;
    scanf("%s",s);
    l=f(s);
    for(b=0;l%2==0;b++)l/=2;
    if(b>18)b=18;
    for(c=0;l%5==0;c++)l/=5;
    if(c>18)c=18;
    a[b][c]++;
    //printf("%lf %d %d %lld\n",x,b,c,l);
  }
  /*for(i=0;i<20;i++){
    for(j=0;j<20;j++)printf("%d ",a[i][j]);
    printf("\n");
    }printf("\n");//*/
  for(i=l=0;i<400;i++){
    for(j=i+1;j<400;j++){
      if((i%20+j%20)<18||(i/20+j/20)<18)continue;
      l+=a[i/20][i%20]*a[j/20][j%20];
    }
  }//printf("%lld\n",l);
  for(i=0;i<400;i++){
    if(i%20<9||i/20<9)continue;
    l+=a[i/20][i%20]*(a[i/20][i%20]-1)/2;
  }
  printf("%lld\n",l);
  return 0;
}
  


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

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int A,B,C,D; cin >> A >> B >> C >> D;
    while(A>0&&C>0){
        C-=B;
        if (C<=0){cout << "Yes" << '\n'; return 0;}
        A-=D;
        if (A<=0){cout << "No" << '\n'; return 0;}
    }
}

Measured memory_bytes: 3644
import os
import sys

if os.getenv("LOCAL"):
    sys.stdin = open("_in.txt", "r")

sys.setrecursionlimit(10 ** 9)
INF = float("inf")
IINF = 10 ** 18
MOD = 10 ** 9 + 7
# MOD = 998244353

H, N = list(map(int, sys.stdin.buffer.readline().split()))
AB = [list(map(int, sys.stdin.buffer.readline().split())) for _ in range(N)]

# dp[h]: 体力を h にするのに必要な魔力の合計の最小値
dp = [INF] * (H + 1)
dp[H] = 0
for a, b in AB:
    for h in reversed(range(H + 1)):
        dp[max(0, h - a)] = min(dp[h] + b, dp[max(0, h - a)])
print(dp[0])


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

typedef long long ll;
const ll INF = 1e9, MOD = 1e9 + 7;
const double EPS = 1e-9, PI = 3.141592653589793;
#define REP(i,a,b) for(ll i=a;i<b;i++)
#define rep(i,n) REP(i,0,n)
#define REPR(i,a,b) for(ll i=b;i>=a;i--)
#define repr(i,n) REPR(i,0,n)
#define all(v) (v).begin(), (v).end()
#define pb push_back
#define fi first
#define se second
#define m_p make_pair

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

    ll n,ans=0;
    cin >> n;
    vector<ll> d(n);
    map<ll,ll> mp;
    rep(i,n){
        cin >> d[i];
        mp[d[i]]++;
    }
    rep(i,101){
        if(mp[i]>=1) ans++;
    }
    cout << ans << "\n";
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define rep(i, a, b) for(int i=(a); i<(b); i++)
#define per(i, a, b) for(int i=(b)-1; i>=(a); i--)
#define sz(a) (int)a.size()
#define de(a) cout << #a << " = " << a << endl
#define dd(a) cout << #a << " = " << a << " "
#define all(a) a.begin(), a.end()
#define pw(x) (1ll<<(x))
#define endl "\n"
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef double db;

void file_put() {
    freopen("filename.in", "r", stdin);
    freopen("filename.out", "w", stdout);
}

const int N=105; 
int n,a[N],L,R; map<int,int> M;

int main() {
//	file_put();
	
	scanf("%d",&n);
	rep(i,1,n+1) scanf("%d",&a[i]),M[a[i]]++;
	R=M.rbegin()->fi,L=(R+1)/2;
	per(i,L+1,R+1) {
		M[i]-=2;
		if (M[i]<0) return 0*printf("Impossible\n");
	}
	M[L]-=(R&1)+1;
	if (M[L]) return 0*printf("Impossible\n");
	rep(i,1,n+1) if (a[i]<L) return 0*printf("Impossible\n");
	printf("Possible\n"); 
	
	return 0;
}



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

int main() {
  std::string u, d;
  std::cin >> u >> d;

  std::reverse(u.begin(), u.end());

  if (u == d) {
    std::cout << "YES" << std::endl;
  } else {
    std::cout << "NO" << std::endl;
  }
  return 0;
}


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

#define REP(i, x, n) for (int i = x; i < (int)(n); i++)
#define rep(i, n) REP(i, 0, x);
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()

using namespace std;

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

int lcm(int a, int b) { return a * b / gcd(a, b); }

int main(void) {
  int a, b;
  char op;
  cin >> a >> op >> b;
  if (op == '+')
    cout << a + b << endl;
  else
    cout << a - b << endl;
  return 0;
}

Measured memory_bytes: 256
H, W, A, B = map(int,input().split())
MOD = 10**9 + 7

fac = [1 for k in range(200010)]
inv = [1 for k in range(200010)]
finv = [1 for k in range(200010)]

for k in range(2,200010):
    fac[k] = (fac[k-1]*k)%MOD
    inv[k] = (MOD - inv[MOD%k] * (MOD // k))%MOD
    finv[k] = (finv[k - 1] * inv[k]) % MOD;

def nCr(n,r):
    return (fac[n]*finv[r]*finv[n-r])%MOD

k = 1
ans = 0
while B+k <= W and H-A-k+1 > 0:
    ans += nCr(B+k-1+(H-A-k),B+k-1) * nCr(W-(B+k) + H-(H-A-k+1),H-(H-A-k+1))
    ans %= MOD
    k += 1
print(ans)


Measured memory_bytes: 57548
#include<iostream>
#include<string>
#include<queue>
#include<vector>
using namespace std;
const int INF=1000000000;
int main(){
	char A[55][55];
	int H,W;
	cin>>H>>W;
	for(int i=1;i<=H;++i){
		for(int j=1;j<=W;++j){
			cin>>A[i][j];
		}
	}
	int kx[8]={-1,0,1,1,1,0,-1,-1},ky[8]={-1,-1,-1,0,1,1,1,0};
	int c[55][55]={};
	for(int i=1;i<=H;++i){
		for(int j=1;j<=W;++j){
			for(int k=0;k<8;++k){
				if(A[i+ky[k]][j+kx[k]]=='#')++c[i][j];
			}
			if(A[i][j]=='#')c[i][j]=10;
		}
	}
	for(int i=1;i<=H;++i){
		for(int j=1;j<W;++j){
			if(c[i][j]<10)cout<<c[i][j];
			else cout<<"#";
		}
		if(c[i][W]<10) cout<<c[i][W]<<endl;
		else cout<<"#"<<endl;
	}

	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <vector>
#include <algorithm>
#include <numeric>
#include <functional>
#include <cmath>
#include <queue>
#include <stack>
  
#define repd(i,a,b) for (int i=(a);i<(b);i++)
#define rep(i,n) repd(i,0,n)
typedef long long ll;

using namespace std;

int inputValue(){
    int a;
    cin >> a;
    return a;
};

void inputArray(int * p, int a){
    rep(i, a){
        cin >> p[i];
    }
};

void inputVector(vector<int> * p, int a){
    rep(i, a){
        int input;
        cin >> input;
        p -> push_back(input);
    }
}
  
int main()
{
  int m,d,i,j,ans=0;
  int d1,d10;

  cin >> m >> d;
  if(d<22){
      cout << 0 << endl;
      return 0;
  }

  repd(i,1,m+1){
      repd(j,1,d+1){
          d10 = j / 10;
          d1 = j % 10;
          if(d10 > 1 && d1 > 1 && d10 * d1 == i){ans++;}
      }
  }

  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, a, b) for(ll i = ll(a); i < ll(b); i++)
#define rer(i, a, b) for(ll i = ll(a) - 1; i >= ll(b); i--)
#define sz(v) (int)(v).size()
#define pb push_back
#define sc second
#define fr first
#define sor(v) sort(v.begin(),v.end())
#define rev(s) reverse(s.begin(),s.end())
#define lb(vec,a) lower_bound(vec.begin(),vec.end(),a)
#define ub(vec,a) upper_bound(vec.begin(),vec.end(),a)
#define uniq(vec) vec.erase(unique(vec.begin(),vec.end()),vec.end())
using namespace std;
typedef long long int ll;
typedef pair <int, int> P;

const ll MOD=1000000007;
ll n,k;
vector<ll> a;
vector<bitset<5010>> b, c;
int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cin>>n>>k;
    a.resize(n); b.resize(n), c.resize(n);
    rep(i,0,n) cin>>a[i];
    if(n==1){
        cout <<0<<"\n";
        return 0;
    }
    b[0][0]=1;
    if(a[0]<=k) b[0][a[0]]=1;
    rep(i,1,n){
        b[i]=b[i-1]|(b[i-1]<<a[i]);
    }
    c[n-1][0]=1;
    if(a[n-1]<=k) c[n-1][a[n-1]]=1;
    rer(i,n-1,0){
        c[i]=c[i+1]|(c[i+1]<<a[i]);
    }
    int ans=0;
    rep(i,max(0LL,k-a[n-1]),k){
        if(b[n-2][i]==1) break;
        if(i==k-1) ans++;
    }
    rep(i,max(0LL,k-a[0]),k){
        if(c[1][i]==1) break;
        if(i==k-1) ans++;
    }
    rep(i,1,n-1){
        vector<ll> x,y;
        rep(j,0,k+1){
            if(b[i-1][j]) x.pb(j);
            if(c[i+1][j]) y.pb(j);
        }
        rep(j,0,sz(x)){
            if(lb(y,k-a[i]-x[j])!=y.end()&&x[j]+*lb(y,k-a[i]-x[j])<k){
                break;
            }
            if(j==sz(x)-1) ans++;
        }
    }
    cout <<ans<<"\n";
}

Measured memory_bytes: 6712
#include <bits/stdc++.h>
using namespace std;
#define ll long long
int main() {
	ll n, x, ans; cin >> n >> x;
	ll arr[n+1]; arr[0] = x;
	for (ll i = 1; i < n+1; ++i)
		cin >> arr[i];
	sort(arr, arr + n);
	if (n == 1)
		cout << abs(arr[1]-arr[0]) << "\n";
	else {
		ans = arr[1] - arr[0];
		for (ll i = 1, j = 2; j < n+1; ++j, ++i)
			ans = __gcd(abs(arr[j] - arr[i]), ans);
		cout << ans << "\n";
	}	
}

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

void swap(int* x, int* y) {
    int tmp = *x;
    *x = *y;
    *y = tmp;
}

int main()
{
    int a, b, c;
    int tmp;
    cin >> a >> b >> c;
    swap(&a, &b);
    swap(&a, &c);
    printf("%d %d %d\n", a, b, c);
    return 0;
}

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

int main()
{
    int X, Y;
    cin >> X;
    cin >> Y;

    int a = (4 * X - Y) / 2;
    int b = (Y - 2 * X) / 2;

    

    if ( (a < 0) || (b < 0) || (2*a+4*b != Y))
    {
        cout << "No" << endl;
    }
    else 
    {
        cout << "Yes" << endl;
    }

    return 0;
}

Measured memory_bytes: 3620
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)n; ++i)
#define repi(i, a, b) for (int i = int(a); i < int(b); ++i)
#define repr(i, n) for (int i = (int)n - 1; i >= 0; --i)
#define ALL(a) (a).begin(), (a).end()
using ll = long long;
using Graph = vector<vector<int>>;
const ll mod = 1e9 + 7;
const ll INF = 1e9;
const ll LINF = 1LL << 60;

int main() {
  int n;
  cin >> n;
  ll cnt[10][10];  //先頭と末尾が何かで分ける
  rep(i, 10) rep(j, 10) cnt[i][j] = 0;
  for (int i = 1; i <= n; ++i) {
    int ed = i % 10;
    int le = i;
    while (le >= 10) {
      le /= 10;
    }
    ++cnt[le][ed];
  }
  ll ans = 0;
  rep(i, 10) rep(j, 10) { ans += cnt[i][j] * cnt[j][i]; }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define int long long
int n,a[300005],ans;
signed main(){
	scanf("%lld",&n);
	for (int i=1;i<=3*n;i++)scanf("%lld",&a[i]);
	sort(a+1,a+3*n+1);
	for (int i=n+1;i<=3*n;i+=2)ans+=a[i];
	printf("%lld\n",ans);
}

Measured memory_bytes: 2560
N, M = map(int, input().split())
a = list(map(int, input().split()))
a.sort()
ar = [list(map(int, input().split())) for _ in range(M)]
ar.sort(key=lambda x: x[1], reverse=True)
p = 0
for b, c in ar:
    if p >= N or c <= a[p]:
        break
    for i in range(b):
        if p >= N:
            break
        a[p] = max(a[p], c)
        p += 1
print(sum(a))

Measured memory_bytes: 32964
#include <iostream>
#include <vector>
#include <map>
using namespace std;

int main() {
	long long n,i,p,q;
	while(cin>>n,n){
		vector<int> ids;
		map<int,long long> m;
		while(n--){
			cin>>i>>p>>q;
			if(!m.count(i))ids.push_back(i);
			m[i]+=p*q;
		}
		int na=1;
		for (int k=0;k<(int)ids.size();++k) {
			if(1000000<=m[ids[k]]){
				cout<<ids[k]<<endl;
				na=0;
			}
		}
		if(na) cout<<"NA\n";
	}
}

Measured memory_bytes: 1276
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i,n) for(int i=0; i<(n); i++)
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
int main(){
    ll x; cin>>x;
    cout<<(x/500)*1000 + ((x%500)/5)*5<<endl;
    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++)
using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
int main() {
  int n,d;
  cin >> n >> d;
  int range = 2*d+1;
  int i=0;
  while(n>0){
    n -= range;
    i++;
  }
  cout << i << endl;
}

Measured memory_bytes: 256
# -*- coding: utf-8 -*-
N, A, B, C = map(int, input().split(' '))
L = [int(input()) for _ in range(N)]

costs = []
min_cost = float('inf')

def get_candidates(n, buf):
    if n == N:
        cands_A = [l for i, l in zip(buf, L) if i == 0]
        cands_B = [l for i, l in zip(buf, L) if i == 1]
        cands_C = [l for i, l in zip(buf, L) if i == 2]

        if len(cands_A) > 0 and len(cands_B) > 0 and len(cands_C) > 0:
            cost = 0
            cost += (len(cands_A) - 1) * 10
            cost += abs(sum(cands_A) - A)

            cost += (len(cands_B) - 1) * 10
            cost += abs(sum(cands_B) - B)

            cost += (len(cands_C) - 1) * 10
            cost += abs(sum(cands_C) - C)

            costs.append(cost)
            # if cost < 300:
            #     print(cost)


    else:
        for i in range(4):
            buf.append(i)
            get_candidates(n+1, list(buf))
            buf.pop()

get_candidates(0, [])
# cost = min(list())
print(min(costs))




Measured memory_bytes: 110168
n, m = map(int, input().split())
lst = list(map(int, input().split()))
lst = sorted(lst, key = lambda x:-x)
dic = {1:2, 2:5, 3:5, 4:4, 5:5, 6:6, 7:3, 8:7, 9:6}

s = set()
for i in lst:
    s.add(dic[i])
s = list(sorted(s))

dp = [0] * (n+1)
for i in range(0, n+1):
    a = 0
    max_a = 0
    for j in s:
        if i-j < 0:
            pass
        elif i == j:
            a = 1
        elif i - j > 0 and dp[i-j] > 0:
            a = dp[i-j] + 1
        if max_a < a:
            max_a = a
    dp[i] = max_a

ans = ''
ans_digit = dp[n]
while len(ans) < ans_digit:
    if len(ans) == ans_digit-1:
        for i in lst:
            if n == dic[i]:
                ans += str(i)
                break
    else:
        for i in lst:
            if n - dic[i] >= 0:
                if dp[n] -1 == dp[n-dic[i]]:
                    ans += str(i)
                    n -= dic[i]
                    break
    
print(ans)

Measured memory_bytes: 3408
#include <iostream>
using namespace std;
int main(){
    string s = "keyence";
    string t;
    cin >> t;
    if(s==t){
        puts("YES");
        return 0;
    }
    int n = t.size();
    for(int i=0; i<n; i++){
        for(int j=i; j<n; j++){
            string tmp = "";
            for(int k=0; k<n; k++){
                if(i<=k && k<=j) continue;
                else tmp.push_back(t[k]);
            }
            if(tmp==s){
                puts("YES");
                return 0;
            }
        }
    }
    puts("NO");
    return 0;
}

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

struct StNode
{
  StNode* m_poParnt;
  StNode* m_poLeft;
  StNode* m_poRigt;
  int m_nKey;

  StNode(int nNo) :
    m_poParnt(nullptr), m_poLeft(nullptr), m_poRigt(nullptr), m_nKey(nNo)
  { }
};

void fnPreOrder(StNode* poNode)
{
  if (poNode == nullptr)  return;

  cout << " " << poNode->m_nKey;
  fnPreOrder(poNode->m_poLeft);
  fnPreOrder(poNode->m_poRigt);
}

void fnInOrder(StNode* poNode)
{
  if (poNode == nullptr)  return;

  fnInOrder(poNode->m_poLeft);
  cout << " " << poNode->m_nKey;
  fnInOrder(poNode->m_poRigt);
}

void fnInsert(StNode*& rpoRoot, StNode* poNewNod)
{
  StNode* poParnt = nullptr;
  StNode* poNode = rpoRoot;

  while (poNode != nullptr)
  {
    poParnt = poNode;
    if (poNewNod->m_nKey < poNode->m_nKey)
      poNode = poNode->m_poLeft;
    else
      poNode = poNode->m_poRigt;
  }

  poNewNod->m_poParnt = poParnt;
  if (poParnt == nullptr)
    rpoRoot = poNewNod;
  else if (poNewNod->m_nKey < poParnt->m_nKey)
    poParnt->m_poLeft = poNewNod;
  else
    poParnt->m_poRigt = poNewNod;
}

void fnBinSchTree(StNode*& rpoRoot)
{
  int nMaxSiz;
  cin >> nMaxSiz;

  for (int i = 0; i < nMaxSiz; ++i)
  {
    string sCmd;
    cin >> sCmd;
    if (sCmd[0] == 'i')
    {
      int nNo;
      cin >> nNo;
      StNode* poNewNod = new StNode(nNo);
      fnInsert(rpoRoot, poNewNod);
    }
    if (sCmd[0] == 'p')
    {
      fnInOrder(rpoRoot);
      cout << endl;
      fnPreOrder(rpoRoot);
      cout << endl;
    }
  }
}

void fnPstOrder(StNode* poNode)
{
  if (poNode == nullptr)  return;

  fnPstOrder(poNode->m_poLeft);
  fnPstOrder(poNode->m_poRigt);
  delete poNode;
}

int main()
{
  cin.tie(0);
  ios::sync_with_stdio(false);
  StNode* poRoot = nullptr;

  fnBinSchTree(poRoot);
//fnPstOrder(poRoot);
}

Measured memory_bytes: 26636
# -*- coding: utf-8 -*-

import sys

def input(): return sys.stdin.readline().strip()
def list2d(a, b, c): return [[c] * b for i in range(a)]
def list3d(a, b, c, d): return [[[d] * c for j in range(b)] for i in range(a)]
def list4d(a, b, c, d, e): return [[[[e] * d for j in range(c)] for j in range(b)] for i in range(a)]
def ceil(x, y=1): return int(-(-x // y))
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def Yes(): print('Yes')
def No(): print('No')
def YES(): print('YES')
def NO(): print('NO')
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
MOD = 10 ** 9 + 7

class BIT:

    def __init__(self, n):
        # 0-indexed
        nv = 1
        while nv < n:
            nv *= 2
        self.size = nv
        self.tree = [0] * nv

    def sum(self, i):
        """ [0, i]を合計する """
        s = 0
        i += 1
        while i > 0:
            s += self.tree[i-1]
            i -= i & -i
        return s

    def add(self, i, x):
        """ 値の追加：添字i, 値x """
        i += 1
        while i <= self.size:
            self.tree[i-1] += x
            i += i & -i

    def get(self, l, r=None):
        """ 区間和の取得 [l, r) """
        # 引数が1つなら一点の値を取得
        if r is None: r = l + 1
        res = 0
        if r: res += self.sum(r-1)
        if l: res -= self.sum(l-1)
        return res

def bisearch_min(mn, mx, func):
    """ 条件を満たす最小値を見つける二分探索 """
    ok = mx
    ng = mn
    while ng+1 < ok:
        mid = (ok+ng) // 2
        if func(mid):
            # 下を探しに行く
            ok = mid
        else:
            # 上を探しに行く
            ng = mid
    return ok

# 右から1番目の値の位置
def calc1(m):
    cnt = lend - bit.sum(m)
    return cnt < 1

# 左から1番目の値の位置
def calc2(m):
    cnt = bit.sum(m) - rstart
    return cnt >= 1

N = INT()
A = LIST()
# aの昇順に処理できるようにindexで並べておく
idxs = [0] * (N+1)
for i, a in enumerate(A):
    idxs[a] = i + 1

bit = BIT(N+2)
# 先頭と末尾に番兵を仕込む
bit.add(0, 1)
bit.add(N+1, 1)
ans = [0] * (N+1)
for a in range(1, N+1):
    # a(1~N)が格納されているindex
    idx = idxs[a]
    # 左の終点と右の始点は各回固定なので先に取っておく
    lend = bit.sum(idx)
    rstart = bit.sum(idx)
    # 自分より小さいindexで最初に自分より小さい値がある直前の場所
    l = bisearch_min(-1, idx, calc1) + 1
    # 自分より大きいindexで最初に自分より小さい値がある直前の場所
    r = bisearch_min(idx, N+1, calc2) - 1
    # aを使う回数 * a = 左端として使える範囲 * 右端として使える範囲 * a
    ans[a] = (idx-l+1) * (r-idx+1) * a
    # aを出現済とする
    bit.add(idx, 1)
# 全てのaについての合計
print(sum(ans))


Measured memory_bytes: 80080
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for (int i = 0; i < (n); i++)
#define repd(i,a,b) for (int i = (a); i < (b); i++)
typedef long long ll;
int main(void)
{
	int n, a, q, b, e;
	vector<int> A;
	cin >> n;
	rep(i, n)
	{
		cin >> a;
		A.push_back(a);
	}
	
	cin >> q;
	rep(i, q)
	{
	    cin >> b >> e;
	    reverse(A.begin() + b, A.begin() + e);
	}
	
	rep(i, n)
	{
	    if (i)
	    {
	        cout << " ";
	    }
	    cout << A[i];
	}
	cout << endl;
}



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

int main(){
    std::string S, T;
    std::cin >> S >> T;
    
    int i;
    for(i=S.size() - T.size(); i>=0; i--){
        bool find = 1;
        for(int j=0; j<T.size(); j++){
            int S_index = i + j;
            if(S[S_index] != '?' && S[S_index] != T[j]){
                find = 0;
            }
        }
        if(find){
            for(int j=0; j<T.size(); j++){
                int S_index = i + j;
                S[S_index] = T[j];
            }
            for(int j=0; j<S.size(); j++){
                if(S[j] == '?'){
                    S[j] = 'a';
                }
            }
            break;
        }
    }
    if(i < 0){
        std::cout << "UNRESTORABLE" << std::endl;
    }else{
        std::cout << S << std::endl;
    }
    
    return 0;
}



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

int main() {
  int N;
  cin >> N;
  N %= 10;
  if (N == 3)
    cout << "bon";
  else if (N == 0 || N == 1 || N == 6 || N == 8)
    cout << "pon";
  else
    cout << "hon";
  cout << endl;
  return 0;
}

Measured memory_bytes: 3648
#include <iostream>
#include <fstream>
using namespace std;
const int nmax=100005;
int aib[2*nmax];
int a[nmax];
int n,i,j,zr;
inline int lbit(int x)
{
    return (((x^(x-1))&x));
}
void update(int poz,int val)
{
    for(int idx=poz;idx<=2*n+1;idx+=lbit(idx))
        aib[idx]+=val;
}
int compute(int poz)
{
    int ret=0;
    for(int idx=poz;idx>0;idx-=lbit(idx))
        ret+=aib[idx];
    return ret;
}
long long check(int val)
{
    long long ret=0,sum=0;
    update(zr,1);
    for(int i=1;i<=n;i++)
    {
        if(a[i]<=val) sum++;
        if(a[i]>val) sum--;
        ret+=1LL*compute(sum+zr-1);
        update(sum+zr,1);
    }
    for(i=1;i<=2*n;i++)
        aib[i]=0;
    return ret;
}
int main()
{
    //freopen("data.in","r",stdin);
    ios_base::sync_with_stdio(false);
    cin>>n;
    for(i=1;i<=n;i++)
        cin>>a[i];
    int ans=0;zr=n+1;
    long long c=(1LL*n*(n+1)/2)/2+1;
    for(int p=30;p>=0;p--)
        if(check(ans+(1<<p))<c)
              ans+=(1<<p);
    ans++;
    cout<<ans;
    return 0;
}

Measured memory_bytes: 1408
#include<bits/stdc++.h> 
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using namespace std;
using ll = long long;
using ull = unsigned long long;
using vv = vector<vector<int>>;
using P = pair<int,int>;

int func( string l,string r ){
  int cnt=0;
  for(char c='a';c<='z';c++){
    bool left=false,right=false;
    rep(j,l.size()){
      if( l.at(j) == c ) left = true;
    }
    rep(j,r.size()){
      if(r.at(j) == c ) right = true;
    }
    if( left && right ) cnt++;
  }
  return cnt;
}
int main(){
  int n;  string s;
  cin >> n >> s;
  int ans=0;
  rep(i,n){
    int num;
    string l,r;
    l = s.substr(0,i);
    r = s.substr(i);
    num = func( l,r );
    ans = max(ans,num);
  }
  
  cout << ans << endl;
  
  return 0;
}


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

using namespace std;



int main() {

	int64_t H, N;
	cin >> H >> N;
	int64_t total=0;
	for (int64_t i = 0; i < N; i++) {
		int64_t a;
		cin >> a;
		total += a;
		if (total >= H) {
			cout << "Yes";
			return 0;
		}

	}
	cout << "No";
	return 0;

}

Measured memory_bytes: 256
import * as fs from 'fs';

namespace AtCoder.abc160 {

    export class ProgramC {
        args: string[];

        constructor(args: string[]) {
            this.args = args;
        }

        /**
         * in
         *  20 3
         *  5 10 15
         * out
         *  10
         *
         *
         *  20 3
         *  0 5 15
         *
         *  10
         */
        main(): void {
            const [k, n]: number[] = this.args[0].split(' ').map(Number);
            let a: number[] = this.args[1].split(' ').map(Number);

            for (let i = 0; i < n; i++) {
                a.push(k + a[i]);
            }
            let ans: number = Infinity;
            for (let i = 0; i < n; i++) {
                let wk: number = 0;
                wk = a[i+n-1]-a[i];
                // for (let j = 0; j < n - 1; j++) {
                //     wk += a[j + i + 1] - a[j + i];
                //     if (ans < wk) break;
                // }
                if (ans > wk) ans = wk;
            }
            console.log(ans);
        }
    }

}

const args = fs.readFileSync('/dev/stdin', 'utf8').trim().split('\n');
const prg = new AtCoder.abc160.ProgramC(args);
prg.main();




Measured memory_bytes: 29204
#include <iostream>
#include <string>
#include <vector>
#include <map>
#include <queue>
#include <stack>
#include <cmath>
#include <iomanip>
#include <algorithm>
using namespace std;

int main(){
    string str;
    cin >> str;
    for(int i = 0; i < str.size(); i++){
        if(str[i] == '1'){
            cout << "9";
        } else if(str[i] == '9'){
            cout << "1";
        } else {
            cout << str[i];
        }
    }
    cout << endl;
    return 0;
}

Measured memory_bytes: 256
#include<cstdio>
#include<algorithm>
using namespace std;
int D[310][310][310], n, K;
char p[310];
int main() {
	int i, L, j, k;
	scanf("%s", p + 1);
	scanf("%d", &K);
	for (i = 1; p[i]; i++);
	n = i - 1;
	for (L = 1; L <= n; L++) {
		for (i = 1; i <= n - L + 1; i++) {
			j = i + L - 1;
			for (k = 0; k <= n; k++) {
				D[i][j][k] = max(D[i][j][k],1);
				D[i][j][k] = max(D[i][j][k], D[i][j - 1][k]);
				D[i][j][k] = max(D[i][j][k], D[i + 1][j][k]);
				if (L != 1) {
					if (p[i] == p[j]) D[i][j][k] = max(D[i][j][k], D[i + 1][j - 1][k] + 2);
					if (k)D[i][j][k] = max(D[i][j][k], D[i + 1][j - 1][k - 1] + 2);
				}
			}
		}
	}
	printf("%d\n", D[1][n][K]);
}

Measured memory_bytes: 114432
H, W = map(int, input().split())
C = [''.join(['.' for j in range(W + 2)]) for i in range(H + 2)]
for i in range(1, H + 1):
  C[i] = '.' + input() + '.'
drawable = True
for i in range(1, H + 1):
  for j in range(1, W + 1):
    if C[i][j] == '#' and C[i - 1][j] == '.' and C[i + 1][j] == '.' and C[i][j - 1] == '.' and C[i][j + 1] == '.':
      drawable = False
print('Yes' if drawable else 'No')

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

int main() {
  int N, M;
  cin >> N >> M;
  vector<ll> a(N), b(N), c(M), d(M);

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

  for(int i = 0; i < M; i++) {
    cin >> c[i] >> d[i];
  }

  for(int i = 0; i < N; i++) {
    ll min_d = 1000000000000;
    int index = 0;
    ll s = 0;
    for(int j = 0; j < M; j++) {
      s = abs(a[i] - c[j]) + abs(b[i] - d[j]);
      if(min_d > s) { min_d = s; index = j; }
    }
    cout << index + 1 << endl;
  }
  return 0;
}

Measured memory_bytes: 256
n,x,y = map(int,input().split())
r = y-x+1
for k in range(1,n):
  ans = 0
  left=right=circle = 0
  for i in range(1,n+1):
    #left
    if i < x:
      if i + k <= x:#円に届かない
        left += 1
        continue
      elif r/2 == k- (x-i):
        left += 1
      elif r/2 > k - (x-i):
        left += 2
      if (x-i)+1 < k and k - (x-i)-1 - (n-y) <= 0:
        left += 1
  #right
    elif i >= y:
      if i + k <= n:
        right += 1
      if i == y:
        continue
      if r / 2 == k-(i-y):
        right += 1
      elif r / 2 > k-(i-y)>0:
      #if  k - (i- y)> 0 and (k-(i-y))< r//2:
        right += 2
  #circle
  if r /2 == k:
    circle = r//2
  elif r/2 > k:
    circle = r
  print(left+right+circle)
        

Measured memory_bytes: 47068
use std::io;

fn main() {
    let mut buf = String::new();
    io::stdin().read_line(&mut buf).unwrap();
    let n = buf.trim().parse::<usize>().unwrap();
    buf.clear();
    io::stdin().read_line(&mut buf).unwrap();
    let mut xs: Vec<_> = buf
        .split_ascii_whitespace()
        .map(|x| x.parse::<usize>().unwrap())
        .collect();
    assert!(xs.len() == n);
    xs.sort_by(|a, b| a.partial_cmp(b).unwrap());

    let mut dp = vec![true; *xs.last().unwrap() + 1];

    let mut i = 0;
    while i < xs.len() {
        if dp[xs[i]] {
            let x = xs[i];
            if i < xs.len() - 1 && x == xs[i + 1] {
                dp[x] = false;
            }
            let mut xx = x + x;
            while xx < dp.len() {
                dp[xx] = false;
                xx += x;
            }
        }
        i += 1;
    }

    println!(
        "{}",
        xs.iter().filter(|x| dp[**x]).collect::<Vec<_>>().len()
    );
}


Measured memory_bytes: 8036
#include <bits/stdc++.h>
#define REP(i,n) for (int i=0; i<(n); ++i)
#define REPR(i,n,m) for (int i=(n); i>=(m); --i)
using namespace std;
using LL = long long;
using LD = long double;
using PLL = pair<long long, long long>;
using PLD = pair<long double, long double>;
using VLL = vector<long long>;
using VLD = vector<long double>;
using VPLL = vector<PLL>;
using VPLD = vector<PLD>;

const int INF = numeric_limits<int>::max();

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

    signed int x; cin >> x;

    if (x>=30) cout << "Yes" << endl;
    else cout << "No" << endl;

    return 0;
}


Measured memory_bytes: 3644
n = input()
k = len(n) - int(input())
if k < 0:
    print(0)
    exit()

dp = [[[0] * 2 for _ in range(k + 1)] for _ in range(len(n)+1)]

dp[0][0][1] = 1

for i in range(len(n)):
    if n[i] == "0":
        for j in range(k):
            dp[i + 1][j + 1][0] = dp[i][j][0]
            dp[i + 1][j + 1][1] = dp[i][j][1]
        for j in range(k+1):
            dp[i + 1][j][0] += dp[i][j][0] * 9
    else:
        for j in range(k):
            dp[i + 1][j + 1][0] = dp[i][j][0] + dp[i][j][1]
        for j in range(k+1):
            dp[i + 1][j][0] += dp[i][j][0] * 9+dp[i][j][1] * (int(n[i])-1)
            dp[i + 1][j][1] += dp[i][j][1]
print(sum(dp[-1][-1]))


Measured memory_bytes: 42480
#include<iostream>
#include<iomanip>
#include<string>
#include<algorithm>
#include<cmath>
using namespace std;
int main(){
    double x,h;
    while(cin>>x>>h){
        if(x==0&&h==0) {
            break;
        }
        cout<<setprecision(10)<<x*x+2*x*sqrt(h*h+x*x/4)<<endl;
    }
    return 0;
}

Measured memory_bytes: 3264
#include<iostream>
#include<vector>
#include<algorithm>
#include<cstring>
#define PI 3.14159
using namespace std;
int R;
double L;
void solve()
{
    
    L = 2.0 * (double)R * PI;
    cout << L;
}

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



Measured memory_bytes: 3788
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <queue>
#include <cmath>
#include <climits>
#include <iomanip>
using namespace std;
typedef long long ll;
int main(){
  int a = 0;
  cin >> a;
  ll res = 0;
  res += a / 500 * 1000;
  a -= res / 2;
  res += a / 5 * 5;
  cout << res << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define P pair<int,int>
using ll=int64_t;
using namespace std;
#define ketasuu(n) fixed<<setprecision(n)
#define btoe(p) p.begin(),p.end()
#define etob(p) p.rbegin(),p.rend()


//library mod int
template <int mod>
struct modint{
    ll x;

    //constructor
    modint(ll x=0): x((x%mod+mod)%mod){}

    //unary operator
    modint operator-() const { return modint(mod-x);}
    modint inv() const { return this->pow(mod-2);}
    
    //compound assignment
    modint& operator+=(const modint& a){
        if((x+=a.x)>=mod) x-=mod;
        return *this;
    }
    modint& operator-=(const modint& a){
        if((x-=a.x)<0) x+=mod;
        return *this;
    }
    modint& operator*=(const modint& a){
        (x*=a.x)%=mod;
        return *this;
    }
    modint& operator/=(const modint& a){
        return *this *= a.inv();
    }

    //arithmetic
    // なぜmodintの後ろに＆を書いたり書かなかったりしてるかの理解ができいないです
    // 四則演算の記号をそなままmodintの世界でも使えるようにしたいです
    // この部分はネットに落ちていたものを写経しています
    modint operator-(const modint& a) const {return modint (*this) -= a ; }
    modint operator+(const modint& a) const {return modint (*this) += a ; }
    modint operator*(const modint& a) const {return modint (*this) *= a ; }
    modint operator/(const modint& a) const {return modint (*this) /= a ; }
    //n should not be smaller than 0.
    modint pow(ll n) const{
        auto x=modint(1);
        auto m=*this;
        while(n>0){
            if(n&1) x*=m;
            n>>=1;
            m*=m;
        }
        return x;
    }

    //compare
    bool operator==(const modint& a) const {return x==a.x ; }
    bool operator!=(const modint& a) const {return x!=a.x ; }

    //I/O
    friend istream& operator>>(istream& is, modint& a ) noexcept {return is >> a.x ; }
    friend ostream& operator<<(ostream& os, const modint& a ) noexcept {return os << a.x ; }
};

//modの調整
constexpr int mod = 1e9 + 7;
using mint = modint<mod>;

//////////////////////////////////////////////////////////////////////
//combination
//コンビネーション計算で代入できる値は3e6で設定している
vector<mint> mintcombvector;
int startmintcomb(int n){
    mintcombvector.push_back(0);
    mintcombvector.push_back(1);
    rep(i,n-5) mintcombvector.push_back(mintcombvector[i+1]*(i+2));
    return 0;
}
mint comb(mint a, mint b){
    if(a.x<b.x || a.x<=0 || b.x<0) return mint(0);
    if(b.x==0) return mint(1);
    if(a==b) return mint(1);
    return mintcombvector[a.x]*(mintcombvector[b.x].inv())*(mintcombvector[a.x-b.x].inv());
}
//combinationを使いたいときは　startmintcomb(n=代入したい数の最大値); を始めに打つこと


int main(){
    startmintcomb(3e6);
    int x,y;
    cin>>x>>y;
    if((x+y)%3!=0){
        cout<<0<<endl;
        return 0;
    }
    int z=(x+y)/3;
    mint a=x-z, b=y-z;
    cout<<comb((a+b),b)<<endl;
    return 0;
}


Measured memory_bytes: 35172
#define _USE_MATH_DEFINES
#include <iostream>
#include <algorithm>
#include <string>
#include <cmath>
#include <map>
#include <vector>

#define REP(i,n) for(int i=0;i<(int)n;i++)
#define REP1(j,n) for(int j=0;j<(int)n;j++)
#define REPD(i,n) for(int i=n;i>=0;i--)
#define REPD1(j,n) for(int j=n;j=>0;j--)
#define REPS(i,n) for(int i=1;i<=(int)n;i++)
#define REPS1(j,n) for(int j=1;j<=(int)n;j++)
#define rep(i,a,n) for(int i=a;i<=(int)n;i++)
#define SZ(x) ((int)(x).size())	//size() unsigned -> int
#define DescSort(a) sort(a.begin(),a.end(),std::greater<int>())

using namespace std;
typedef long long ll;

int main(void) {
	int n,ans = 0;
	cin >> n;
	for (int i = n; i > 0; i--) {
		for (int j = 0; j < n; j++) {
			if (i == pow(2, j)) {
				cout << i << endl;
				return 0;
			}
		}
	}
	return 0;
}



Measured memory_bytes: 512
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef long double lld;
ll MOD = (1e9)+7;
const int dr[] = {+1, -1, +0, +0, +1, -1, +1, -1};
const int dc[] = {+0, +0, +1, -1, +1, -1, -1, +1};
const int kx[] = {+1, +2, -1, -2, +1, +2, -1, -2};
const int ky[] = {+2, +1, +2, +1, -2, -1, -2, -1};
//#pragma GCC target ("avx2")
//#pragma GCC optimization ("O3")
//#pragma GCC optimization ("unroll-loops")
inline void fastIO(){
  ios_base::sync_with_stdio(0);cin.tie(0);
}
template<typename T> ostream& operator<<(ostream &os, const vector<T> &v) { os << '{'; string sep; for (const auto &x : v) os << sep << x, sep = ", "; return os << '}'; }
template<typename T, size_t size> ostream& operator<<(ostream &os, const array<T, size> &arr) { os << '{'; string sep; for (const auto &x : arr) os << sep << x, sep = ", "; return os << '}'; }
template<typename A, typename B> ostream& operator<<(ostream &os, const pair<A, B> &p) { return os << '(' << p.first << ", " << p.second << ')'; }

void debug_out() { cerr << endl; }
template<typename Head, typename... Tail> void debug_out(Head H, Tail... T) { cerr << ' ' << H; debug_out(T...); }

#ifdef LOCAL
#define debug(...) cerr << "(" << #__VA_ARGS__ << "):", debug_out(__VA_ARGS__)
#else
#define debug(...) 47
#endif
int main(){
  fastIO();
  int n;
  cin>>n;
  vector<ll>a(n);
  ll tot=0,ans=0;
  ll DP[n];
  memset(DP,0,sizeof(DP));
  for(int i=0;i<n;i++){
    cin>>a[i];
    tot+=a[i];
    DP[i]=tot;
  }
  for(int i=0;i<n;i++){
    ll ope=DP[n-1]-DP[i];
    ans+=((a[i]%MOD)*(ope%MOD))%MOD;
    ans%=MOD;
  }
  cout<<ans%MOD<<endl;
  return 0;
}


Measured memory_bytes: 6328
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
#include <math.h>


int ASC(const void *a, const void *b) {
	return *(int *)b - *(int *)a;//降順
}
	
int main(void)
{
	long long n, k, before;
	scanf("%lld%lld",&n,&k);
	before = n;
	long long ans = n%k;
	if (ans > k - ans)
		ans = k - ans;
	printf("%lld",ans);
	return 0;
} 

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

int main(){
  string s;
  cin >> s;
  if(s.substr(0,4) == "YAKI"){
    puts("Yes");
    return 0;
  }
  puts("No");
  return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<bits/stdc++.h>
using namespace std;
int main()
{
	int N,M,s[4],c[10];
	cin>>N>>M;
	if(N==1&&M==0)
	{
		cout<<0;
		return 0;
	}
	int fla=1;
	memset(s,-1,sizeof(s));
	for(int i=1;i<=M;i++)
	{
		int ss,cc;
		cin>>ss>>cc;
		if(N>1&&ss==1&&cc==0)fla=0;
		else if(s[ss]==-1)s[ss]=cc;
		else  
		{
			if(s[ss]!=-1&&s[ss]!=cc)fla=0;
		}
	}
	if(fla==0)
	{
		cout<<"-1";
		return 0;
	}
	for(int i=1;i<=N;i++)
	{
		if(s[i]==-1&&i==1)s[i]=1;
		else if(s[i]==-1)s[i]=0;
		printf("%d",s[i]);
	}
	return 0;
	
} 

Measured memory_bytes: 256
#include<stdio.h>
#include<string.h>

int main(void) {
   int N, out = 0;
   scanf("%d", &N);

   char s[N+1][101];
   for(int i = 0; i < N; i++) {
      scanf("%s", s[i]);
   }

   for(int i = 0; i < N-1; i++) {
      for(int j = i+1; j < N; j++) {
         if(s[i][strlen(s[i])-1] != s[i+1][0]) {
            out++;
         }
         if(strcmp(s[i],s[j])==0) {
            out++;
         }
      }
   }

   if(out >= 1) {
      printf("No\n");
   } else {
      printf("Yes\n");
   }
      
   return 0;
}


Measured memory_bytes: 1648