akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
#define rep(i,n) for(int i = 0;i<n;i++)
using namespace std;
typedef pair<int,int> P;
typedef long long ll;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0;}
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0;}

const int mod = 1000000007;
int main() {
    string s;
    cin >> s;
    int dp[100020][13] = {0};
    dp[0][0] = 1;
    int n = s.size();
    rep(i,n) {
        rep(j,13) {
            if(s[i] == '?') {
                for(int b = 0;b<=9;b++) {
                    int j2 = (j*10 + b)%13;
                    dp[i+1][j2] = (dp[i+1][j2] + dp[i][j])%mod;
                }
            } else {
                int j2 = (j*10 + (s[i] - '0'))%13;
                dp[i+1][j2] = (dp[i+1][j2] + dp[i][j])%mod;
            }
        }
    }
    cout << dp[n][5] << endl;
}

Measured memory_bytes: 8824
kyori = []
for i in range(5):
    kyori += [int(input())]
k = int(input())

for i in range(1, len(kyori)+1):
    left = kyori[:i]
    right = kyori[i:]
    base = left[-1]

    for r in right:
        if abs(base - r) > k:
            print(':(')
            exit()

print('Yay!')

Measured memory_bytes: 3064
n,m = map(int,input().split())
one_li = []
to_n_li = []
for _ in range(m):
    a,b = map(int,input().split())
    if a == 1:
        one_li.append(b)
    if b == n:
        to_n_li.append(a)
ll = len(set(one_li) & set(to_n_li))
if ll == 0:
    print('IMPOSSIBLE')
else:
    print('POSSIBLE')

Measured memory_bytes: 71256
// Created by ...
#include <bits/stdc++.h>

#define db1(x) cout<<#x<<"="<<x<<'\n'
#define db2(x,y) cout<<#x<<"="<<x<<","<<#y<<"="<<y<<'\n'
#define db3(x,y,z) cout<<#x<<"="<<x<<","<<#y<<"="<<y<<","<<#z<<"="<<z<<'\n'
#define rep(i,n) for(int i=0;i<(n);++i)
#define repA(i,a,n) for(int i=a;i<=(n);++i)
#define repD(i,a,n) for(int i=a;i>=(n);--i)

using namespace std;
using ll = long long;

int main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    long long int n;
    vector<long long int>v; 
    cin>>n;
    while(n)
    {
      v.push_back(n%10);
      n=n/10;

    }
    bool found=false;
    for(int i=0;i<v.size();i++)
    {
      if(v[i]==7)
      {
        found=true;
        break;
      }
    }
    if(found)
      cout<<"Yes"<<endl;
    else
      cout<<"No"<<endl;
    return 0;
}

Measured memory_bytes: 3656
fn main() {
    let n: usize = {
        let mut buf = String::new();
        std::io::stdin().read_line(&mut buf).unwrap();
        let mut iter = buf.split_whitespace();
        
        iter.next().unwrap().parse().unwrap()
    };

    let mut a: Vec<u32> = Vec::with_capacity(n);
    let mut b: Vec<u32> = Vec::with_capacity(n);

    for _ in 0..n {
        let mut buf = String::new();
        std::io::stdin().read_line(&mut buf).unwrap();
        let mut iter = buf.split_whitespace();

        a.push(iter.next().unwrap().parse().unwrap());
        b.push(iter.next().unwrap().parse().unwrap());
    }

    a.sort();
    b.sort();

    let ans: u32 = {
        if n % 2 == 1 {
            let left = a[n / 2];
            let right = b[n / 2];
            right - left + 1
        } else {
            let left = a[n / 2 - 1] + a[n / 2];
            let right = b[n / 2 - 1] + b[n / 2];
            right - left + 1
        }
    };

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

Measured memory_bytes: 3944
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n)  for(long long i=0;i<(long long)(n);i++)
#define REP(i,k,n) for(long long i=k;i<(long long)(n);i++)
#define all(a) a.begin(),a.end()
#define pb emplace_back
#define eb emplace_back
#define lb(v,k) (lower_bound(all(v),k)-v.begin())
#define ub(v,k) (upper_bound(all(v),k)-v.begin())
#define fi first
#define se second
#define pi M_PI
#define PQ(T) priority_queue<T>
#define SPQ(T) priority_queue<T,vector<T>,greater<T>>
#define dame(a) {out(a);return 0;}
#define decimal cout<<fixed<<setprecision(15);
#define dupli(a) a.erase(unique(all(a)),a.end())
typedef long long ll;
typedef pair<ll,ll> P;
typedef tuple<ll,ll,ll> PP;
typedef tuple<ll,ll,ll,ll> PPP;
typedef multiset<ll> S;
using vi=vector<ll>;
using vvi=vector<vi>;
using vvvi=vector<vvi>;
using vvvvi=vector<vvvi>;
using vp=vector<P>;
using vvp=vector<vp>;
using vb=vector<bool>;
using vvb=vector<vb>;
const ll inf=1001001001001001001;
const ll INF=1001001001;
const ll mod=1000000007;
const double eps=1e-10;
template<class T> bool chmin(T&a,T b){if(a>b){a=b;return true;}return false;}
template<class T> bool chmax(T&a,T b){if(a<b){a=b;return true;}return false;}
template<class T> void out(T a){cout<<a<<'\n';}
template<class T> void outp(T a){cout<<'('<<a.fi<<','<<a.se<<')'<<'\n';}
template<class T> void outvp(T v){rep(i,v.size())cout<<'('<<v[i].fi<<','<<v[i].se<<')';cout<<'\n';}
template<class T> void outvvp(T v){rep(i,v.size())outvp(v[i]);}
template<class T> void outv(T v){rep(i,v.size()){if(i)cout<<' ';cout<<v[i];}cout<<'\n';}
template<class T> void outvv(T v){rep(i,v.size())outv(v[i]);}
template<class T> bool isin(T x,T l,T r){return (l)<=(x)&&(x)<=(r);}
template<class T> void yesno(T b){if(b)out("yes");else out("no");}
template<class T> void YesNo(T b){if(b)out("Yes");else out("No");}
template<class T> void YESNO(T b){if(b)out("YES");else out("NO");}
template<class T> void noyes(T b){if(b)out("no");else out("yes");}
template<class T> void NoYes(T b){if(b)out("No");else out("Yes");}
template<class T> void NOYES(T b){if(b)out("NO");else out("YES");}
void outs(ll a,ll b){if(a>=inf-100)out(b);else out(a);}
ll gcd(ll a,ll b){if(b==0)return a;return gcd(b,a%b);}
ll modpow(ll a,ll b){ll res=1;a%=mod;while(b){if(b&1)res=res*a%mod;a=a*a%mod;b>>=1;}return res;}

int main(){
    ll a,b,c;cin>>a>>b>>c;
    if(a+b<c)dame("NA");
    out(max(0ll,c-a));
}


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

int main() {
	vector<string> n;
	string s, ans = "zzzzzzzzzzz";
	int k, a = 0;
	cin >> s >> k;
	for(int i = 0; i < s.size(); i++){
		for(int j = 1; j <= k; j++){
			n.resize(a+1);
			n.at(a) = s.substr(i, j);
			//cout << n.at(a) << endl;
			a++;
		}
	}
	sort(n.begin(), n.end());
	int x = 0;
	for(int i = 0; i < k; i++){
		while(ans == n.at(x)){
			x++;
		}
		ans = n.at(x);
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 1660
#include<iostream>
#include<vector>
#include<algorithm>

using namespace std;
typedef long long ll;

const int MAX_N = 10; //チケット
const int MAX_M = 32; //都市
const double INF = 101010.00;

int ti[MAX_N];
int to[MAX_M][MAX_M]; //-1は非接続
double dp[1<<MAX_N][MAX_M];

void chmin(double &a, double b){
  if( a > b){ swap(a,b);} return ;
}

int main(){ 
  int n,m,p,a,b; 
  while(cin >> n >> m >> p >> a >> b){
    if( n == 0 ){ break;}
    
    a--; b--;
    
    for(int i = 0; i < n; i++){ cin >> ti[i];}
    
    for(int i = 0; i < MAX_M; i++){
      fill(to[i],to[i]+MAX_M,-1); //非接続はINF
    }
    
    for(int i = 0; i < 1 << MAX_N; i++){
      fill(dp[i], dp[i]+MAX_M,INF);
    }
    //以上初期化
    
    //出発地点からdp[S][pos]までにかかる距離をおく
    
    dp[(1<<n)-1][a] = 0;
    
    double ans = INF;
    
    for(int i = 0; i < p; i++){ 
      int x,y,z; cin >> x >> y >> z; x--; y--;
      to[x][y] = z; to[y][x] = z;
    }
    
    for(int S = (1<<n)-1; S >= 0; S--){
      
      chmin(ans,dp[S][b]); // dp[][b]の最小値が、求める答え
        
      for(int u = 0; u < m; u++){ //どの頂点から更新するかを全探索
        
        if(dp[S][u] == INF){ continue;} //未更新の組み合わせから更新する必要なし
        
          for(int i = 0; i < n; i++){ //残っているチケットから何を使うか選ぶ
            
            if( (S >> i) & 1){
              //今残っているi枚目を使って、uからvへと移動する
              
              for(int v = 0; v < m; v++){ //どの頂点へ行くかを全探索
          
                if( to[u][v] == -1){ continue;} //接続していない場合も除く
              
             chmin(dp[S & ~(1<<i)][v], dp[S][u]+(double)to[u][v]/ti[i]);
            }
          }
        }
      }
    }
    
    if( ans == INF){ printf("%s\n", "Impossible");}
    else{ printf("%.4f\n", ans);}
    
  }
  
  return 0;
}


Measured memory_bytes: 3308
#include <iostream>
#include <algorithm>
#include <iomanip>
#include <vector>
#include <queue>
#include <set>
#include <map>

using namespace std;
typedef long long ll;

const int INF =  100000;

struct edge {int to, cap, rev;};

class FordFolkerson{
    public:
        FordFolkerson(int n){
            N = n;
            G = vector<vector<edge>>(n, vector<edge>());
            used = vector<bool>(n, false);
        }

        void add_edge(int from, int to, int cap){
            G[from].push_back((edge{to, cap, (int)G[to].size()}));
            G[to].push_back((edge{from, 0, (int)G[from].size()-1}));
        }

        int max_flow(int s, int t){
            int flow = 0;
            while(true){
                clear_used();
                int f = dfs(s, t, INF);
                if(f == 0){
                    break;
                }
                flow += f;
            }
            return flow;
        }

    private:
        vector<vector<edge>> G;
        vector<bool> used;
        int N;
        void clear_used(){
            for(int i = 0; i < N; i++) used[i] = false;
        }

        int dfs(int v, int t, int f){
            if(v == t) return f;
            used[v] = true;
            for(int i = 0; i < G[v].size(); i++){
                edge &e = G[v][i];
                if(!used[e.to] && e.cap > 0){
                    int d = dfs(e.to, t, min(f, e.cap));
                    if(d > 0){
                        e.cap -= d;
                        G[e.to][e.rev].cap += d;
                        return d;
                    }
                }
            }
            return 0;
        }
};

int H, W;
int to_idx(int h, int w){
    return h*W+w;
}

int dh[4] = {0, 0, -1, 1};
int dw[4] = {-1, 1, 0, 0};

bool is_in_field(int i, int j){
    return i >= 0 && i < H && j >= 0 && j < W;
}

int to_in_idx(int h, int w){
    return 1+h*W+w;
}

int to_out_idx(int h, int w){
    return 1+H*W+h*W+w;
}

char c[100][100];

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout << setprecision(10) << fixed;
    cin >> H >> W;
    FordFolkerson ff(3+2*H*W);
    int s = 0, t = 2*H*W+2;
    bool ok = true;
    for(int h = 0; h < H; h++){
        for(int w = 0; w < W; w++){
            cin >> c[h][w];
            int in_idx = 1+h*W+w;
            int out_idx = 1+H*W+h*W+w;
            if(c[h][w] == 'X'){
                ff.add_edge(s, in_idx, INF);
                ff.add_edge(in_idx, out_idx, INF);
            }else{
                ff.add_edge(in_idx, out_idx, 1);
            }
            if(h == 0 || h == H-1 || w == 0 || w == W-1){
                ff.add_edge(out_idx, t, INF);
                if(c[h][w] == 'X') ok = false;
            }
            for(int i = 0; i < 4; i++){
                int h_to = h+dh[i], w_to = w+dw[i];
                if(is_in_field(h_to, w_to)){
                    ff.add_edge(to_out_idx(h_to, w_to), in_idx, 1);
                    ff.add_edge(out_idx, to_in_idx(h_to, w_to), 1);
                }
            }
        }
    }
    if(!ok){
        cout << -1 << endl;
    }else{
        cout << ff.max_flow(s, t) << endl;
    }
}

Measured memory_bytes: 7964
<?php
// From https://qiita.com/yoshikyoto/items/6924478283dbdd549e4b
class Scanner {
    private $arr = [];
    private $count = 0;
    private $pointer = 0;
    public function next() {
        if($this->pointer >= $this->count) {
            $str = trim(fgets(STDIN));
            $this->arr = explode(' ', $str);
            $this->count = count($this->arr);
            $this->pointer = 0;
        }
        $result = $this->arr[$this->pointer];
        $this->pointer++;
        return $result;
    }
    public function hasNext() {
        return $this->pointer < $this->count;
    }
    public function nextInt() {
        return (int)$this->next();
    }
    public function nextDouble() {
        return (double)$this->next();
    }
}
// From https://qiita.com/yoshikyoto/items/6924478283dbdd549e4b
list($N)=sscanf(trim(fgets(STDIN)),"%d");
$bu = array();
$sc = new Scanner();

for ($i=0; $i < $N-1; $i++) { 
    $n = $sc->nextInt();
    if(!isset($bu[$n])){
        $bu[$n] = 1;
    }else{
        $bu[$n] += 1;
    }
}
for ($i=1; $i <= $N; $i++) { 

    if(!isset($bu[$i])){
        print("0"."\n");
    }else{
        print($bu[$i]."\n");
    }
}
//


Measured memory_bytes: 37936
s = [int(x) for x in input()]
s.reverse()
box = []

def f(i, temp, k):
    if i != len(s)-1:
        f(i+1, temp + s[i+1], 1)
        f(i+1, temp + s[i+1]*10*k, 10*k)
    else:
        box.append(temp)

f(0,s[0],1)
print(sum(box))

Measured memory_bytes: 3060
#include <iostream>
#include <iomanip>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <map>
#include<unordered_map>
#include <set>
#include <queue>
#include <stack>
#include <vector>
#include<bitset>
#include<deque>
#include<string>
#include<list>
#include<iterator>
#include<sstream>
#include <algorithm>
#define lli long long int
#define lower(a) transform(a.begin(),a.end(),a.begin(),::tolower);

using namespace std;

const int N = 3e5 + 500;
const long long mod = 1e9 + 7;
const long long cmod = 998244353 ;
const long long inf = 1LL << 57;
const int M = 1e6 + 500;
const lli ths = 1LL << 40;

vector<pair<lli, lli> > v;

void solve()
{
    lli n;
    cin>>n;
    lli a[n];
    for(int i = 0; i < n; i ++)
    {
        cin>>a[i];
        v.push_back({a[i], i + 1});
    }
    sort(v.begin(), v.end());
    for(auto it : v){
        cout<<it.second<<' ';
    }
    cout<<endl;
    return ;
}
/*
7
6 7 4 1 2 11 6
5
1 2 10 4 5
*/

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

    lli t;
    t = 1;
//    cin>>t;
    while(t --)
    {
        solve();
    }
    return 0;
}


Measured memory_bytes: 3312
/*
     Author:Raghav Bansal
     IIIT Una
                  */
#include <bits/stdc++.h>
#define int long long int
#define pb push_back
#define mp make_pair
#define all(v) v.begin(),v.end()
#define BOLT ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL)
#define X first
#define Y second
#define endl "\n"
using namespace std;
void solve() {
	string s, t;
	cin >> s >> t;
	for (int i = 0; i < s.size(); i++) {
		if (s[i] != t[i]) {
			cout << "No" << endl;
			return;
		}
	}
	cout << "Yes" << endl;
}
int32_t main() {
	BOLT;
	solve();
}

Measured memory_bytes: 3648
#include <iostream>
#include <vector>
#include <string>
#include <cmath>
#include <algorithm>
#include <utility>
#include <queue>
#include <set>
#include <map>
#include <deque>
#include <iomanip>
#include <cstdio>
#include <stack>
#include <numeric>

using namespace std;
typedef  long long ll;
typedef pair<int,int> PII;
typedef vector<int> VI;
typedef vector<VI> VVI;
#define  MP make_pair
#define  PB push_back
#define inf 1000000007
#define mod 1000000007
#define rep(i,n) for(int i=0;i<(int)(n);++i)
#define int long long

int dp[100010][13];

signed main(){
    string s;
    cin >> s;
    int n = s.size();
    reverse(s.begin(),s.end());
    dp[0][0] = 1;
    int m = 1;
    rep(i,n){
        if(s[i]!='?'){
            int c = s[i]-'0';
            rep(j,13){
                dp[i+1][(j+c*m)%13] += dp[i][j];
                dp[i+1][(j+c*m)%13] %= mod;
            }
        }else{
            rep(j,13){
                rep(k,10){
                    dp[i+1][(j+k*m)%13] += dp[i][j];
                    dp[i+1][(j+k*m)%13] %= mod;
                }
            }
        }
        m*=10;
        m%=13;
    }
    cout << dp[n][5] << endl;
    return 0;
}

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

#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define ALL(obj) (obj).begin(), (obj).end()
#define INF 1e9
typedef long long ll;


int main() {
    string S; cin >> S;
    ll K; cin >> K;

    ll count = 0;
    char next;
    REP(i,S.size()){
        if(S[i] == '1'){
            count ++;
        }else{
            next = S[i];
            break;
        }
    }
    if(count >= K){
        cout << 1 << endl;
    }else{
        cout << next << endl;
    }
    
    return 0;
}

Measured memory_bytes: 3652
n = int(input())
a = sorted(list(map(int, input().split())))
b = [0 for _ in range(n)]

if n % 2:
    for i in range(1,n,2):
        b[i] = b[i+1] = n - i
else:
    for i in range(0,n,2):
        b[i] = b[i+1] = n - (i + 1)
b.sort()

for i, j in zip(a, b):
    if i != j:
        print(0)
        exit()

print((2**(n//2))%(10**9+7))


Measured memory_bytes: 14008
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

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

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

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

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

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

    ($next:expr, i321) => {
        read_value!($next, i32) - 1
    };

    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}

//
// # Examples
//
// # integers
// input! { n: i32, m: i32, ... }
//
// # array
// input! { n: i32, v: [i32; n], }
//
// # matrix
// input! { n: i32, m: i32, mat: [[]] }
//
// # string
// input! { s: chars }
//
// 3 4
// ####
// #..#
// .#.#
//
// input!{
//     h: i32,
//     w: i32,
//     board: [chars; h],
// }

// https://practice.contest.atcoder.jp/tasks/practice_1
//fn main() {
//    input!{
//        a: i32, b: i32, c: i32,
//        foo: chars,
//    }
//    let s: String = foo.into_iter().collect();
//    println!("{} {}", a+b+c, s);
//}
fn main() {
    input! { s: chars }
    let mut ans = 0;
    for c in s {
        if c == '1' { ans += 1; }
    }
    println!("{}", ans); 
}

Measured memory_bytes: 4352
#include<iostream>
#include<string>
#include<cmath>
#include<queue>
#include<map>
#include<set>
#include<list>
#include<iomanip>
#include<vector>
#include<functional>
#include<algorithm>
#include<cstdio>
#include<unordered_map>
using namespace std;
//---------------------------------------------------
//ライブラリゾーン！！！！
#define int long long
#define str string
#define rep(i,j) for(int i=0;i<(int)(j);i++)
typedef long long ll;
typedef long double ld;
const ll inf = 4523372036854775807;
const ld pi = 3.1415926535897932384626433832795028841971693993751058209749445923078164062862089986280348253421170679821480865132823066470938446095505822317253594081284811174502841027019385211055596446229489549303819644288109756659334461284756482337867831652712019091456485669234603486104543266482133936072602491412737245870066063155881748815209209628292540917153643678925903600113305305488204665213841469519415116094330572703657595919530921861173819326117931051185480744623799627495673518857527248912279381830119491298336733624406566430860213949463952247371907021798609437027705392171762931767523846748184676694051320005681271452635608277857713427577896091736371787214684409012249534301465495853710507922796892589235420199561121290219608640344181598136297747713099605187072113499999983729780499510597317328160963185950244594553469083026425223082533446850352619311881710100031378387528865875332083814206171776691473035982534904287554687311595628638823537875937519577818577805321712268066130019278766111959092164201989;
struct P {
	ll pos, cost;
};
bool operator<(P a, P b) { return a.cost < b.cost; }
bool operator>(P a, P b) { return a.cost > b.cost; }
struct B {//隣接リスト表現
	ll to, cost;
};
struct S {//辺の情報を入れる変数
	int from, to, cost;
};
struct H {
	int x, y;
};
ll gcm(ll i, ll j) {//最大公約数
	if (i > j) swap(i, j);
	if (i == 0) return j;
	return gcm(j%i, i);
}
ld rad(ld a, ld b, ld c, ld d) {
	return sqrt(pow(a - c, 2) + pow(b - d, 2));
}//rad＝座標上の2点間の距離
//---------------------------------------------------
//+++++++++++++++++++++++++++++++++++++++++++++++++++
signed main() {
	string s;
	cin >> s;
	if (s[0] == '9' || s[1] == '9')
		cout << "Yes\n";
	else
		cout << "No\n";
	getchar(); getchar();
}

Measured memory_bytes: 768
#include<iostream>

using namespace std;

int check(int *d, int n, int k) {
	while (n > 0) {
		for (int i = 0; i < k; i++)
			if ((n % 10) == d[i])
				return -1;
		n /= 10;
	}
	return 0;
}

int main() {

	int n, k;

	cin >> n >> k;

	int *d = new int[k];
	for (int i = 0; i < k; i++)
		cin >> d[i];

	int ans = n;
	while (check(d, ans, k) == -1)
		ans++;

	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
int main(void){
  int kind,choice,count=0;
  int i;
  double sum=0;
  double judge;
    
  scanf("%d %d\n", &kind,&choice);
  int num[kind];
  for(i=0;i<kind;i++){
    scanf("%d ", &num[i]);
    sum+=num[i];
  }
  judge=sum*1/(4*choice);
  for(i=0;i<kind;i++){
    if(num[i]>=judge)
      count++;
  }
  if(count>=choice)
    printf("Yes");
  else
    printf("No");
  
  return 0;
}

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

#define rep(i,n) for(int i = 0; i<n; ++i)
#define REP(i,n) for(int i = 1; i<n; ++i)
const int INF = 100100100;
const int MOD = (int)1e9 + 7;
typedef long long ll;

int main(){
    int n;cin>>n;
    vector <int> p(n); rep(i,n)cin>>p[i];
    int changed = 0;
    rep(i,n){
        if(p[i] != i+1)changed++;
    }
    cout<<((changed <= 2)?"YES":"NO")<<endl;return 0;
}


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

int main (void)
{
    
    long long s[120000] = {0},t[120000] = {0},p[120000] ={0};
    long long n,m;
    long long i,j=0,an = 0;
    int a=0;
    int b=0;
    char c[120]={0},d[120] = {0};
    scanf("%lld",&n);
    for(i=0;i<n;i++){
        scanf("%lld",&s[i]);
    }
    sort(s,s+n);
    for(i=0;i<n;i++){
        if(i==0){
            j++;
            t[j] = s[i];
            p[j]++;
            //printf("%lld %lld\n",t[j], j);
        }else if(t[j] != s[i]){
            j++;
            t[j] = s[i];
            p[j]++;
        }else{
            p[j]++;
        }
    }
    for(i=0;i<j;i++){
        //printf("%lld %lld\n",p[i+1],t[i+1]);
    }
    for(i=0;i<j;i++){
        if(p[i+1] > t[i+1]){
            an += p[i+1] -t[i+1];
        }else if(p[i+1] < t[i+1]){
            an += p[i+1];
        }
    }
    printf("%lld\n",an);

    return 0;
    
}

Measured memory_bytes: 3200
#include<iostream>
#include<stdio.h>
#include<string>
#include<vector>
#include<algorithm>
#include<cmath>
#include <queue>
#include <utility>
#include <map>
#include <set>
using namespace std;

int main() {
    string S;
    long long K;
    cin >> S >> K;

    while (1) {
        int n = S[0] - '0';
        if (pow(n, 5000'0000'0000'0000) >= K) {
            cout << n;
            return 0;
        }
        else {
            K -= pow(n, 5000'0000'0000'0000);
            S.erase(S.begin());
        }
    }

    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <string>
#include <stdio.h>
#include <stdlib.h>
#include <iomanip>
#include <math.h>
#include <sstream>

using namespace std;


int main()
{
	long long a, b, c;
	cin >> a >> b >> c;
	if (c - a - b  < 0)
	{
		puts("No");
	}
	else
	{
		if(4*a*b < (c - a -b)*(c - a - b))
		{
			puts("Yes");
		}
		else
		{
			puts("No");
		}
	}
	
	return 0;
	

	 
	//uint64_t w = 1, h = 1;
	//cin >> w >> h;
	//uint64_t w_max = w / 2 + (w % 2);
	//uint64_t h_max = h / 2 + (h % 2);
	//uint64_t w_min = w / 2;
	//uint64_t h_min = h / 2;
	//uint64_t counter = 0;

	//counter += w_max * h_max;
	//counter += w_min * h_min;

	//if (w == 1 || h == 1)
	//{
	//	counter = 1;
	//}
	//
	//cout << counter << endl;
	//return 0;

}

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

using namespace std;

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

#define REP(i, n) for (int (i) = 0 ; (i) < (int)(n) ; ++(i))
#define REPN(i, m, n) for (int (i) = m ; (i) < (int)(n) ; ++(i))
#define REP_REV(i, n) for (int (i) = (int)(n) - 1 ; (i) >= 0 ; --(i))
#define REPN_REV(i, m, n) for (int (i) = (int)(n) - 1 ; (i) >= m ; --(i))
#define ALL(x) x.begin(), x.end()

#define INF (1e10)
#define MOD (1000000007)

#define print2D(h, w, arr) REP(i, h) { REP(j, w) cout << arr[i][j] << " "; cout << endl; }
template<class T> void print(const T& x) { cout << setprecision(16) << x << endl; }
template<class T, class... A> void print(const T& first, const A& ... rest) { cout << first << " "; print(rest...); }
struct PreMain { PreMain() { cin.tie(0); ios::sync_with_stdio(false); } } premain;



int main() {
	int N;
	cin >> N;
	
	double ans = 0;

	REP(i, N) {
		int a;
		cin >> a;
		ans += (1.0 / (double)a);
	}

	print(1 / ans);
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <unordered_map>
#include <map>
#include <algorithm>
#include <set>
#include <unordered_set>
#include <deque>
#include <cmath>
#include <stack>
#include <queue>

using namespace std;

int n, h[100005], x, o;

int main(){

    cin >> n;
    for(int i = 0; i < n; i++){
        cin >> h[i];
    }

    for(int i = 0; i < n; i++){
        x = 0;
        if((i + 1) != n && (n - (i+1) > o)){
            for(int j = i+1; j < n; j++){
                int b = j -1;
                if(h[b] >= h[j]){
                    x++;
                } else{
                    break;
                }
                
            }
        }
        if(x > o){
            o = x;
        }
    }

    cout << o;



}

Measured memory_bytes: 640
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0; i<(n); i++)
typedef long long ll;
#define mod 1000000007
#define F first
#define S second
#define P pair<long long,long long>
#define all(a) a.begin(),a.end()
#define INF 1000000000000000000
using namespace std;
int main(void){
    ll n,W;cin>>n>>W;
    vector<vector<ll>>v(4);
    ll w,y,z;cin>>w>>y;v[0].push_back(y);
    rep(i,n-1){cin>>y>>z;v[y-w].push_back(z);}
    rep(i,4)sort(all(v[i]),greater<ll>());
    vector<vector<ll>>V(4);rep(i,4)V[i].push_back(0);
    rep(i,4){
        rep(j,v[i].size()){ll p=V[i][V[i].size()-1]+v[i][j];V[i].push_back(p);}
    }
    ll ans=0;
    for(int i=0;i*w<=W&&i<V[0].size();i++){
        for(int j=0;i*w+j*(w+1)<=W&&j<V[1].size();j++){
            for(int k=0;i*w+j*(w+1)+k*(w+2)<=W&&k<V[2].size();k++){//wをi個、w+1をj個、w+2をk個使う時の最大値
            ll m=V[3].size()-1,n=(W-i*w-j*(w+1)-k*(w+2))/(w+3);
            ll s=min(m,n);
                ans=max(ans,V[0][i]+V[1][j]+V[2][k]+V[3][s]);
            }
        }
    }
    cout<<ans;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <bitset>
#include <map>
#include <tuple>
#include <unordered_set>
#include <unordered_map>
#include <list>
#include <numeric>
#include <utility>
#include <iterator>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cstring>
#include <climits>
#include <ctime>
#include <cassert>
#include <random>
#include <cstring>

#define rep(i,n) for(int i=0;i<int(n);i++)
#define all(x) (x).begin(),x.end()
#define pb push_back

using namespace std;
using ll = long long;

const ll mod = 1000000007;

// int dx[4]={1,0,-1,0};
// int dy[4]={0,1,0,-1};
int ddx[8]={-1,-1,0,1,1,1,0,-1};
int ddy[8]={0,1,1,1,0,-1,-1,-1};
// bool debug=false;

/*---------------------------------------------------*/

const int INF = 100000000;

struct Edge {
    int to;
    int dist;
    int enemy;
};

typedef tuple<int, int, int> TP;

void solve(int N, int M, int L) {
    int A, B, D, E;
    vector<Edge> G[N + 1];
    for(int i = 0; i < M; i++) {
        cin >> A >> B >> D >> E;
        G[A].push_back({B, D, E});
        G[B].push_back({A, D, E});
    }
    vector<vector<int>> dp = vector<vector<int>>(N + 1, vector<int>(L + 1, INF));
    
    // cost, money, curr
    priority_queue<TP, vector<TP>, greater<TP>> que;
    que.push(make_tuple(0, L, 1));
    dp[1][L] = 0;
    while(que.size()) {
        // assert(que.size() <= 10000);
        TP tp = que.top(); que.pop();
        int cost, money, curr;
        tie(cost, money, curr) = tp;
        //cerr << cost << endl;
        if(dp[curr][money] < cost) continue;
        for(Edge e : G[curr]) {
            if(dp[curr][money] + e.enemy < dp[e.to][money]) { 
                assert(0 <= dp[curr][money]);
                dp[e.to][money] = dp[curr][money] + e.enemy;
                que.push(make_tuple(dp[e.to][money], money, e.to));
            }
            if(e.dist <= money && dp[curr][money] < dp[e.to][money - e.dist]) {
                // //cerr << "debug: " << e.dist << " " << money << " " << cost << endl;
                // assert(0 <= dp[curr][money]);
                dp[e.to][money - e.dist] = dp[curr][money];
                que.push(make_tuple(dp[e.to][money - e.dist], money - e.dist, e.to));
            }
        }
    }

    int ans = INF;
    for(int i = 0; i <= L; i++) {
        ans = min(ans, dp[N][i]);
    }
    cout << ans << endl;
}

int main() {
    int N, M, L;
    while(cin >> N >> M >> L) {
        if(N == 0 && M == 0 && L == 0) break;
        solve(N, M, L);
    }
}



Measured memory_bytes: 3456
/**
 * C - Remainder Minimization 2019
 * https://atcoder.jp/contests/abc133/tasks/abc133_c
 * 
 * 2019で割ったあまりが等しい a, b は 任意の整数 c 
 * との積 を 2019 で割った結果は等しい
 **/
#include<iostream>

using namespace std;

long l, r;

void solve() {
    long res = 2020;

    if (r - l >= 2019) {
        res = 0;
    } else {
        for (long i = l; i < r; i++) {
            for (long j = i+1; j < r+1;j++) {
                res = min(res, (i * j) % 2019);
            }
        }
    }
    cout << res << endl;
}

int main() {
    cin >> l >> r;
    solve();
}


Measured memory_bytes: 256
def check(w,k,mid):
  weight=mid
  remains=k
  flag=True
  for i in range(len(w)):
    if weight>=w[i]:
      weight-=w[i]
    else:
      remains-=1
      if remains==0:
        flag=False
        break
      weight=mid
      weight-=w[i]

  return flag



n,k=map(int,input().split())
w=[]

for i in range(n):
  a=int(input())
  w.append(a)

left=max(w)
right=sum(w)
mid=0

while(1):
  mid=int((left+right)/2)
  #print(left,mid,right)
  if check(w,k,mid):
    right=mid
  else:
    left=mid+1

  if left>=right:
    print(left)
    break


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

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

    void solve(Scanner sc) {
        int n = sc.nextInt();
        int[] dp = new int[n + 1];
        dp[0] = 0;
        for (int i = 1; i <= n; i++) {
            dp[i] = Integer.MAX_VALUE;
            int pow = 1;
            while (pow <= i) {
                dp[i] = Math.min(dp[i], dp[i - pow] +1);
                pow *= 6;
            }
            pow = 1;
            while (pow <= i) {
                dp[i] = Math.min(dp[i], dp[i - pow] +1);
                pow *= 9;
            }
        }
        System.out.println(dp[n]);
    }
}

Measured memory_bytes: 21844
#include <iostream>
#include <cmath>
#include <string>
#include <vector>
#include <algorithm>
#include <queue>
#include <map>
#include <set>
using namespace std;
#define MOD 1000000007
#define INF 1<<30
#define LINF (ll)1<<62
#define rep(i,n) for(ll i=0; i<(n); i++)
#define REP(i,a,b) for(ll i=(a); i<(b); i++)
#define all(x) (x).begin(),(x).end()
using namespace std;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef pair<ll, ll> P;
typedef vector<pair<ll, ll>> vpl;



int main(){
    ll a,b,c; cin >> a >> b >> c;
    if(a%2==1 && b%2==1 && c%2==1) cout << min(a*b,min(b*c,a*c)) << endl;
    else cout << 0 << endl;
}


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

#define inf 0x3f3f3f3f
#define pb push_back
#define fi first
#define se second

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef vector <int> vi;
typedef vector <ll> vl;
typedef vector <ull> vu;
typedef vector <vector <int>> vvi;
typedef pair <int, int> pi;
typedef vector <pair <int, int>> vpi;

int n, k;

vi v;

void read() {
  cin >> n >> k;
  for(int i = 0; i < n; ++i) {
    int x;
    cin >> x;
    v.pb(x);
  }
}

void solve() {
  sort(v.begin(), v.end());

  int start = 0, stop = k - 1;
  int sol = 1e9;
  while (stop < n) {
    sol = min(v[stop] - v[start], sol);
    ++start, ++stop;
  }
  cout << sol << endl;
}

int main() {
  ios :: sync_with_stdio(false);
  cin.tie(nullptr);
  int t = 1;
//  cin >> t; //please do not forget to comment this if there are no queries
  while(t) {
    --t;
    read();
    solve();
  }
  return 0;
}


Measured memory_bytes: 892
S = input()

L = int(S[:2])
R = int(S[2:])

if 0 < L <= 12:
    if 0 < R <= 12:
        print('AMBIGUOUS')
    else:
        print('MMYY')
elif 0 < R <= 12:
    print('YYMM')
else:
    print('NA')

Measured memory_bytes: 3060
// (c) 2020, redotter

// Roses are red
// The Tardis is blue
// The Doctor once said
// Rose Tyler...

#pragma GCC optimize("O3", "unroll-loops")
#pragma GCC target("avx2")
#include <bits/stdc++.h>
using namespace std;
#ifndef ONLINE_JUDGE
#pragma comment(linker, "/stack:500000000")
#endif

#define pb push_back
#define the(a) (a).begin(), (a).end()
#define ft first
#define sd second
#define endl "\n"
#define forn(i, n) for (int i = 0; i < (n); i++)
#define forr(i, s, n) for (int i = (s); i < (n); i++)

using i64 = long long;
using i32 = int;
using f64 = long double;

template <class T> using vec = vector<T>;
using str = string; using p64 = pair<i64, i64>;
using v64 = vec<i64>; using vv64 = vec<v64>;
using s64 = set<i64>; using m64 = map<i64, i64>;
template <size_t Size1> using a64 = array<i64, Size1>;
template <size_t Size1, size_t Size2> using aa64 = array<a64<Size2>, Size1>;
template <class T> using hash_set = unordered_set<T>;
template <class T, class U> using hash_map = unordered_map<T, U>;

mt19937 gen(998244353);
const i64 inf = numeric_limits<i64>::max() / 2;

template <class T> inline i64 len(const T& a) { return (i64)(a.size()); }
inline void fast() { ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0); }
template <class T, class S>
inline bool check_min(T& a, S b) { if (a > b) return a = b, 1; return 0; }
template <class T, class S>
inline bool check_max(T& a, S b) { if (a < b) return a = b, 1; return 0; }

void read() {}
template<class T, class ...U>
void read(T& a, U& ...b) { cin >> a; read(b...); }
void print() {}
template<class T, class ...U>
void print(const T& a, const U& ...b) { cout << a << " "; print(b...); }
void println() { cout << "\n"; }
template<class T, class ...U>
void println(const T& a, const U& ...b) { cout << a << " "; println(b...); }

struct Problem {
	void files(str in, str out) {
#ifdef ONLINE_JUDGE
		freopen(in.c_str(), "r", stdin), freopen(out.c_str(), "w", stdout);
#endif
	}
	void solve(), input();
	void many() { i32 t; cin >> t; while (t--) input(), solve(); }
	void make(bool mt = 0) { if (mt) many(); else input(), solve(); }
} problem;

signed main() {
	fast();
	problem.make();
#ifdef _DEBUG
	println(); println("[finished]"); system("pause > nul");
#endif
	return 0;
}

i64 n;
vec<f64> a;

void Problem::solve() {
	vec<vec<f64>> dp(n + 1, vec<f64>(n + 1));
	dp[0][0] = 1;
	forr(i, 1, n + 1) {
		forn(j, i + 1) {
			dp[i][j] = dp[i - 1][j] * (1 - a[i]);
			if (j) dp[i][j] += dp[i - 1][j - 1] * a[i];
		}
	}
	f64 ans = 0;
	forr(j, n / 2 + 1, n + 1) {
		ans += dp[n][j];
	}
	println(ans);
}

void Problem::input() {
	read(n);
	a.resize(n + 1);
	forn(i, n) read(a[i + 1]);
	cout << fixed << setprecision(20);
}


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

using namespace std;
typedef long long ll;
typedef unsigned long long ull;
#define rep(i, n) for (int i = 0; i < (n); i++)
#define MAX 9223372036854775807
ll score(int x, int p)
{
    return pow(x - p, 2);
}

int main(void)
{
    int n;
    cin >> n;
    vector<int> x(n);
    rep(i, n) cin >> x.at(i);

    sort(x.begin(), x.end());
    int mn = x.at(0);
    int mx = x.at(n - 1);
    ll sum = MAX;
    ll t_sum = 0;
    for (int i = mn; i <= mx; i++)
    {
        t_sum = 0;
        rep(j, n)
            t_sum += score(x.at(j), i);
        sum = min(sum, t_sum);
    }
    cout << sum << endl;

    return 0;
}


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;
}
#ifdef DEBUG
#define debug(...) pr(any{__VA_ARGS__})
#define debugv(x) pr((x))
#else
#define debug(...)
#define debugv(x)
#endif

using lli = pair<pair<ll, ll>, int>;

int main(){
	int N, M;
	ll L;
	cin >> N >> M >> L;
	vector<vector<ll>> A(N, vector<ll>(N, 1e18));
	for(int i=0; i<M; i++){
		int a, b;
		ll c;
		cin >> a >> b >> c;
		a--; b--;
		A[a][b] = c;
		A[b][a] = c;
	}

	vector<vector<pair<ll, ll>>> dist(N, vector<pair<ll, ll>>(N, {1e18, -1e18}));

	for(int s=0; s<N; s++){
		priority_queue<lli, vector<lli>, greater<lli>> que;
		que.push({{0, -L}, s});
		dist[s][s] = {0, -L};
		while(!que.empty()){
			auto d = que.top().first;
			int v = que.top().second;
			que.pop();
			if(dist[s][v] < d) continue;
			for(int u=0; u<N; u++) if(u!=v&&A[u][v]<=L){
				auto dd = d;
				dd.second += A[u][v];
				if(dd.second>0){
					dd.first++;
					dd.second = -L+A[u][v];
				}
				debug(s, v, u, dd.first, dd.second);
				if(dd < dist[s][u]){
					dist[s][u] = dd;
					que.push({dd, u});
				}
			}
		}
	}

	int Q;
	cin >> Q;
	for(int i=0; i<Q; i++){
		int s, t;
		cin >> s >> t;
		s--; t--;
		if(dist[s][t] < pair<ll, ll>(1e18, -1e18)){
			cout << dist[s][t].first << endl;
		} else {
			cout << -1 << endl;
		}
	}

	return 0;
}


Measured memory_bytes: 3900
import java.util.*;


class Main{
    static long mod = 1000000007;
    public static void main(String argv[]) {
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        int L = sc.nextInt();
        int[] ringo = new int[N];
        int result = 10000000;
        int sum = 0;
        for(int i=0;i<N;i++){
            ringo[i] = L+i;
            sum += ringo[i];
            if(Math.abs(ringo[i])<Math.abs(result))result=ringo[i];
        }
        System.out.println(sum-result);
    }
}

Measured memory_bytes: 22356
#include <stdio.h>
#define M 1002

void printline(int n,int a[]){
	int i;
	printf("%d",a[0]);
	for(i=1;i<n;i++){
		printf(" %d",a[i]);
	}
	printf("\n");
	return;
}

void insertsort(int p, int a[]){

	int pp=p,dum_a,dum_b,i;

	for(i=0;i<p;i++){
		if(a[p]<a[i]){
		 pp=i;
		 dum_a=a[p];
		 break;
		}
	}

	if(i==p) return;

	for(i=pp;i<p+1;i++){
		dum_b=a[i];
		a[i]=dum_a;
		dum_a=dum_b;
	}

	return;

}

int main(void){
	int i,n,a[M];
	scanf("%d",&n);

	for(i=0;i<n;i++){
		scanf("%d",&a[i]);
	}

	for(i=0;i<n;i++){
		insertsort(i,a);
		printline(n,a);
	}

	return 0;

}

Measured memory_bytes: 1820
#include <iostream>
#include <vector>
#include <algorithm>
#include <set>
using namespace std;

vector<pair<int,int>> types[100010];
pair<int,int> sushi[100010];
int main(){
    int N,K;cin>>N>>K;
    for(int i=0;i<N;i++){
        int t,d;cin>>t>>d;
        sushi[i] = make_pair(d,t);
    }
    sort(sushi, sushi + N);
    reverse(sushi, sushi + N);
    for(int i=0;i<N;i++) types[sushi[i].second].push_back(make_pair(sushi[i].first,i));
    vector<pair<int,int>> possib;
    for(int i=1;i<=N;i++) if(types[i].size() > 0) possib.push_back(types[i][0]);
    sort(possib.rbegin(),possib.rend());

    set<pair<int,int>> curr;
    long long total = 0,ans = 0;
    long long k = min((int)possib.size(),K);
    for(int i=0;i<k;i++){
        total += possib[i].first;
        curr.insert(possib[i]);
    }
    for(int i=0;i<N && curr.size() < K;i++) if(curr.count(make_pair(sushi[i].first,i)) == 0){
        curr.insert(make_pair(sushi[i].first,i));
        total += sushi[i].first;
    }
    ans = total + k*k;
    for(int i=0;i<N && k > 0;i++) if(curr.count(make_pair(sushi[i].first,i)) == 0){
        auto x = *curr.begin();
        total -= x.first;
        k -= 1;
        curr.erase(curr.begin());
        total += sushi[i].first;
        curr.insert(make_pair(sushi[i].first,i));
        ans = max(ans, total + k*k);
    }

    cout<<ans<<endl;
}

Measured memory_bytes: 10364
import sys
sys.setrecursionlimit(10**7) #再帰関数の上限,10**5以上の場合python
import math
from copy import copy, deepcopy
from copy import deepcopy as dcp
from operator import itemgetter
from bisect import bisect_left, bisect, bisect_right#2分探索
#bisect_left(l,x), bisect(l,x)#aはソート済みである必要あり。aの中からx未満の要素数を返す。rightだと以下
from collections import deque
#deque(l), pop(), append(x), popleft(), appendleft(x)
##listでqueの代用をするとO(N)の計算量がかかってしまうので注意
from collections import Counter#文字列を個数カウント辞書に、
#S=Counter(l),S.most_common(x),S.keys(),S.values(),S.items()
from itertools import accumulate,combinations,permutations#累積和
#list(accumulate(l))
from heapq import heapify,heappop,heappush
#heapify(q),heappush(q,a),heappop(q) #q=heapify(q)としないこと、返り値はNone
#import fractions#古いatcoderコンテストの場合GCDなどはここからimportする
from functools import lru_cache#pypyでもうごく
#@lru_cache(maxsize = None)#maxsizeは保存するデータ数の最大値、2**nが最も高効率
from decimal import Decimal

def input(): 
    x=sys.stdin.readline()
    return x[:-1] if x[-1]=="\n" else x
def printl(li): _=print(*li, sep="\n") if li else None
def argsort(s, return_sorted=False): 
    inds=sorted(range(len(s)), key=lambda k: s[k])
    if return_sorted: return inds, [s[i] for i in inds]
    return inds
def alp2num(c,cap=False): return ord(c)-97 if not cap else ord(c)-65
def num2alp(i,cap=False): return chr(i+97) if not cap else chr(i+65)
def matmat(A,B):
    K,N,M=len(B),len(A),len(B[0])
    return [[sum([(A[i][k]*B[k][j]) for k in range(K)]) for j in range(M)] for i in range(N)]
def matvec(M,v):
    N,size=len(v),len(M)
    return [sum([M[i][j]*v[j] for j in range(N)]) for i in range(size)]
def T(M):
    n,m=len(M),len(M[0])
    return [[M[j][i] for j in range(n)] for i in range(m)]
def main():
    mod = 1000000007
    #w.sort(key=itemgetter(1),reversed=True)  #二個目の要素で降順並び替え

    s = input()
    K= int(input())
    #N, K = map(int, input().split())
    #A = tuple(map(int, input().split())) #1行ベクトル
    #L = tuple(int(input()) for i in range(N)) #改行ベクトル
    #S = tuple(tuple(map(int, input().split())) for i in range(N)) #改行行列
    keta=len(s)
    dp=[[[0,0] for _ in range(K+1)] for _ in range(keta+1)]
    #dp[i][j][k]前からi桁目まで決め、j個の条件を満たす桁を含み、k=1:i文字目まで一致 k=0:対象の数以下

    dp[0][0][0]=1
    for i in range(0,keta):
        ni=i+1
        nd=int(s[i])
        for j in range(0,K+1):
            for k in range(0,2):  
                for d in range(10): 
                    nj=j
                    nk=k
                    if d!=0:nj+=1
                    if nj>K:continue
                    if k==0:
                        if d>nd:break
                        elif d<nd:nk=1
                    dp[ni][nj][nk]+=dp[i][j][k]
    if K<=keta:
        ans=dp[keta][K][1]+dp[keta][K][0]
    else:
        ans=0
        #与えられた数未満で条件を満たすもの+与えられた数が条件を満たす場合1
    print(ans)
    #print(dp)


    
    

        
    



if __name__ == "__main__":
    main()

Measured memory_bytes: 60908
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <map>
#include <unordered_map>
#include <set>
#include <climits>
using namespace std;

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int H, W, N;
    cin >> H >> W >> N;
    vector<int> a(N);
    for(int i=0; i<N; i++) cin >> a[i];

    vector<int> c(H*W);
    int k = 0;
    for(int i=0; i<N; i++){
        for(int j=0; j<a[i]; j++){
            c[k] = i + 1;
            k++;
        }
    }

    vector<vector<int>> ans(H, vector<int>(W, 0));
    for(int i=0; i<H; i++){
        for(int j=0; j<W; j++){
            int k;
            if(i % 2 == 0) k = j;
            else k = W - 1 - j;
            ans[i][k] = c[i*W+j];
        }
    }

    for(int i=0; i<H; i++){
        for(int j=0; j<W; j++){
            cout << ans[i][j] << " ";
        }
        cout << endl;
    }

    return 0;
}

Measured memory_bytes: 384
Option Infer On
Imports System.Collections.Generic
Imports System.Console

Module Program
    Sub Main()
        Dim O = NextString()
        Dim E = NextString()

        For i As Integer = 0 To Math.Max(O.Length, E.Length) - 1
            If i < O.Length Then Write(O(i))
            If i < E.Length Then Write(E(i))
        Next
        WriteLine()
    End Sub

    Function NextString() As String
        Dim result As New List(Of Char)
        Do
            Dim tmp = Read()
            If tmp < 0 Then Exit Do
            Dim nextChar = Chr(tmp)

            If Not Char.IsWhiteSpace(nextChar) Then
                result.Add(nextChar)
            ElseIf nextChar <> vbCr Then
                Exit Do
            End If
        Loop
        Return New String(result.ToArray())
    End Function

End Module


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

int main() {
	string s,t;
  	cin >> s >> t;
  	int count=0;
  	for(int i=0;i<3;i++){
      if(s.at(i) == t.at(i))count++;
    }
  cout << count << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
// type alias
typedef long long LL;
typedef pair<int,int> II;
typedef tuple<int,int,int> III;
typedef vector<int> VI;
typedef vector<string> VS;
typedef unordered_map<int,int> MAPII;
typedef unordered_set<int> SETI;
template<class T> using VV=vector<vector<T>>;
// minmax
template<class T> inline T SMIN(T& a, const T b) { return a=(a>b)?b:a; }
template<class T> inline T SMAX(T& a, const T b) { return a=(a<b)?b:a; }
// repetition
#define FORE(i,a,b) for(int i=(a);i<=(b);++i)
#define REPE(i,n)  for(int i=0;i<=(n);++i)
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  for(int i=0;i<(n);++i)
#define FORR(x,arr) for(auto& x:arr)
#define SZ(a) int((a).size())
// collection
#define ALL(c) (c).begin(),(c).end()
// DP
#define MINUS(dp) memset(dp, -1, sizeof(dp))
#define ZERO(dp) memset(dp, 0, sizeof(dp))
// stdout
#define println(args...) fprintf(stdout, ##args),putchar('\n');
// debug cerr
template<class Iter> void __kumaerrc(Iter begin, Iter end) { for(; begin!=end; ++begin) { cerr<<*begin<<','; } cerr<<endl; }
void __kumaerr(istream_iterator<string> it) { (void)it; cerr<<endl; }
template<typename T, typename... Args> void __kumaerr(istream_iterator<string> it, T a, Args... args) { cerr<<*it<<"="<<a<<", ",__kumaerr(++it, args...); }
template<typename S, typename T> std::ostream& operator<<(std::ostream& _os, const std::pair<S,T>& _p) { return _os<<"{"<<_p.first<<','<<_p.second<<"}"; }
#define __KUMATRACE__ true
#ifdef __KUMATRACE__
#define dump(args...) { string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); stringstream _ss(_s); istream_iterator<string> _it(_ss); __kumaerr(_it, args); }
#define dumpc(ar) { cerr<<#ar<<": "; FORR(x,(ar)) { cerr << x << ','; } cerr << endl; }
#define dumpC(beg,end) { cerr<<"~"<<#end<<": "; __kumaerrc(beg,end); }
#else
#define dump(args...)
#define dumpc(ar)
#define dumpC(beg,end)
#endif

// $ cp-batch GoodDistance | diff GoodDistance.out -
// $ g++ -std=c++14 -Wall -O2 -D_GLIBCXX_DEBUG -fsanitize=address GoodDistance.cpp && ./a.out

/*
 
 7/7/2019
 
 5:02-
 
 */

const int MAX_N=15+1;
LL A[MAX_N][MAX_N];
int N,D;

void solve() {
  int res=0;
  REP(j,N)REP(i,j) {
    int x=0;
    REP(k,D) x+=(A[i][k]-A[j][k])*(A[i][k]-A[j][k]);
    int y=(int)sqrt(x+0.5);
    res+=(y*y==x);
  }
  cout<<res<<endl;
}

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout<<setprecision(12)<<fixed;
  
  cin>>N>>D;
  REP(i,N)REP(j,D) {
    cin>>A[i][j];
  }
  solve();
  
  return 0;
}


Measured memory_bytes: 256