akhauriyash/Code-Regression huggingface dataset:
#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++)

int X[100];
ll DP[100][100][51*51];
int main(){
    int N, A;
    cin >> N >> A;
    REP(i, N){
        int x;
        cin >> x;
        X[i] = x;
    }

    DP[0][0][0] = 1;
    DP[0][1][X[0]] = 1;
    for(int i = 1; i < N; i++){
        int x = X[i];
        DP[i][0][0] = 1;
        for(int j = i+1; j >= 1; j--){
            for(int k = 0; k <= A*N; k++){
                //DP[i][j][k+x] = DP[i-1][j][k+x];
                //DP[i][j][k+x] += DP[i][j-1][k];
                DP[i][j][k] += DP[i-1][j][k];
                if(k - x >= 0) 
                    DP[i][j][k] += DP[i-1][j-1][k-x];
            }
        }
    }

    ll ans = 0;
    for(int j = 1; j <= N; j++){
        ans += DP[N-1][j][j*A];
    }
    //ans += DP[N-1][4][32];

    //for(int j = 0; j <= N; j++){
    //    for(int k = 0; k <= A*N; k++){
    //        printf("%lld ", DP[1][j][k]);
    //    }
    //    printf("\n");
    //}

    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 100608
import sys
n,t=map(int,input().split())
cts=[list(map(int,input().split())) for _ in range(n)]
cts.sort(key=lambda x:(x[0],x[1]))

for ct in cts:
  if ct[-1]<=t:
    print(ct[0])
    sys.exit()

print('TLE')

Measured memory_bytes: 3060
function main(input) {
  const inputs = input.split('\n');
  var n = inputs[0] - 0;

  var a = 0;
  var aLine = 1;
  var people = [];
  for (var i = 0; i < n; i++) {
    var a = inputs[aLine] - 0;
    people.push([]);
    var temp = [];
    for (var j = 1; j <= a; j++) {
      temp.push(inputs[aLine + j].split(' ').map((n) => n - 0));
    }
    people[i] = temp;
    aLine += a + 1;
  }

  var initTemp = [];
  for (var i = 0; i < n; i++) {
    initTemp.push(0);
  }

  var temp = initTemp.concat();
  var max = -1;
  for (var bit = 0; bit < (1 << n); bit++) {
    var counter = 0;
    var isOK = true;
    for (var bi = 0; bi < n; bi++) {
      temp[bi] = bit & (1 << bi) ? 1 : 0;
    }
    for (var bi = 0; bi < n; bi++) {
      if (!(bit & (1 << bi))) {
        if (temp[bi] == 1) isOK = false;
      } else {
        counter += 1;
        if (temp[bi] == 0) {
          isOK = false;
          break;
        }
        for (var pi = 0; pi < people[bi].length; pi++) {
          if (temp[people[bi][pi][0] - 1] != people[bi][pi][1]) {
            isOK = false;
            break;
          }
        }
      }
    }
    if (isOK) max = Math.max(max, counter);
  }
  console.log(max);
}

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


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

int main() {
  string S; cin >> S;
  int cnt1 = 0;
  for (int i = 0; S[i]; ++i) if (S[i] == '1') cnt1++;
  cout << min(cnt1, (int)S.length() - cnt1) * 2 << endl;
  return 0;
}

Measured memory_bytes: 512
package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
	"strings"
)

func main() {
	sc := NewScanner()
	S := sc.Next()
	
	if strings.Contains(S,"7"){
		fmt.Println("Yes")
	}else{
		fmt.Println("No")
	}

}

type Scanner struct {
	r   *bufio.Reader
	buf []byte
	p   int
}

func NewScanner() *Scanner {
	rdr := bufio.NewReaderSize(os.Stdin, 1000)
	return &Scanner{r: rdr}
}
func (s *Scanner) Next() string {
	s.pre()
	start := s.p
	for ; s.p < len(s.buf); s.p++ {
		if s.buf[s.p] == ' ' {
			break
		}
	}
	result := string(s.buf[start:s.p])
	s.p++
	return result
}
func (s *Scanner) NextLine() string {
	s.pre()
	start := s.p
	s.p = len(s.buf)
	return string(s.buf[start:])
}
func (s *Scanner) NextInt() int {
	v, _ := strconv.Atoi(s.Next())
	return v
}
func (s *Scanner) NextInt64() int64 {
	v, _ := strconv.ParseInt(s.Next(), 10, 64)
	return v
}

func (s *Scanner) NextFloat() float64 {
	v, _ := strconv.ParseFloat(s.Next(), 64)
	return v
}

func (s *Scanner) NextIntArray() []int {
	s.pre()
	start := s.p
	result := []int{}
	for ; s.p < len(s.buf)+1; s.p++ {
		if s.p == len(s.buf) || s.buf[s.p] == ' ' {
			v, _ := strconv.ParseInt(string(s.buf[start:s.p]), 10, 0)
			result = append(result, int(v))
			start = s.p + 1
		}
	}

	return result
}
func (s *Scanner) NextInt64Array() []int64 {
	s.pre()
	start := s.p
	result := []int64{}
	for ; s.p < len(s.buf)+1; s.p++ {
		if s.p == len(s.buf) || s.buf[s.p] == ' ' {
			v, _ := strconv.ParseInt(string(s.buf[start:s.p]), 10, 64)
			result = append(result, v)
			start = s.p + 1
		}
	}
	return result
}

func (s *Scanner) NextMap() map[int]bool {
	s.pre()
	start := s.p
	mp := map[int]bool{}
	for ; s.p < len(s.buf); s.p++ {
		if s.buf[s.p] == ' ' {
			v, _ := strconv.Atoi(string(s.buf[start:s.p]))
			mp[v] = true
			start = s.p + 1
		}
	}
	v, _ := strconv.Atoi(string(s.buf[start:s.p]))
	mp[v] = true

	return mp
}

func (s *Scanner) pre() {
	if s.p >= len(s.buf) {
		s.readLine()
		s.p = 0
	}
}
func (s *Scanner) readLine() {
	s.buf = make([]byte, 0)
	for {
		l, p, e := s.r.ReadLine()
		if e != nil {
			panic(e)
		}
		s.buf = append(s.buf, l...)
		if !p {
			break
		}
	}
}


Measured memory_bytes: 1756
a,b,c = map(int,input().split())
d,e,f = map(int,input().split())
if b == e and c == f:
  print(abs(a-d))
  exit()
if a > d:
  num = 100 * b + c
  nu = 100 * e + f
elif a < d:
  num = 100 * e + f
  nu = 100 * b + c
else:
  print(1)
  exit()
if num > nu:
  print(abs(a-d)+1)
else:
  print(abs(a-d))


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

#define int long long
#define ll long long
#define pb push_back
#define mp make_pair
#define f(i,a,n) for(int i=a ; i<n ; i++)
#define rf(i,n,a) for(int i=n ; i>=a ; i--)
#define F first
#define S second
#define all(c) (c).begin(),(c).end()
#define sz(v) (int)(v).size()
#define fast ios::sync_with_stdio(0); cin.tie(0); cout.tie(0)

typedef long double ld;
typedef vector<int> vi;
typedef pair<int,int> pii;
typedef pair<pii,int> ppi;
typedef vector<pii> vpi;

const int inf = 1e9;
const int inf64 = 1e18;
const int MOD = inf + 7;

void solve(){
   int a[] = {400 , 600 , 800 , 1000 , 1200 , 1400 , 1600 , 1800 , 2000};

   int x , ans;
   cin >> x;

   f(i,0,8){
      if(a[i] <= x && a[i+1] > x){
         ans = 8 - i;
         break;
      }
   }

   cout << ans << "\n";
}

int32_t main(){
   fast;
   int t = 1;
   // cin >> t;
   while(t--)  solve();   
}

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

#define REP(i, n) for(int (i)=0; (i)<(n); (i)++)
#define OUT(a) cout << (a) << "\n"
#define ll long long
#define uint unsigned int
#define ushort unsigned short
#define ulong unsigned long

const int MOD = 1e9 + 7;

const int MAX = 2001;

long long fac[MAX], finv[MAX], inv[MAX];

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

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

int main() {
    int n, k;
    COMinit();
    cin >> n >> k;
    for(int i=1; i<=k; i++) {
        ll left = COM(n-k+1, i);
        ll right = COM(k-1, i-1);
        printf("%lld\n", (left*right)%MOD);
    }
    return 0;
}



Measured memory_bytes: 256
#include <cstdio>
#include <cmath>
#include <iostream>
#include <sstream>
#include <string>
#include <vector>
#include <map>
#include <queue>
#include <algorithm>

#ifdef _DEBUG
#define DMP(x) cerr << #x << ": " << x << "\n"
#else
#define DMP(x) ((void)0)
#endif

const int MOD = 1000000007, INF = 1111111111; 
using namespace std;
typedef long long lint;

template <class T = lint>
class CuSum {
private:
	vector<T> cusum;

public:
	CuSum(vector<T> const &vec) : cusum(vec.size() + 1) { for (int i = 0; i < (int)(vec.size()); i++) cusum[i + 1] = cusum[i] + vec[i]; }
	CuSum(int N) : cusum(N + 1) {}

	void add(int i, T x) { cusum[i + 1] += x; }
	void init() { for (int i = 0; i < (int)(cusum.size()) - 1; i++) cusum[i + 1] += cusum[i]; }

	T query(int l, int r) { return cusum[r] - cusum[l]; }  // partial sum of [l, r)
};

int main() {

	cin.tie(nullptr);
	ios::sync_with_stdio(false);

	int N, Q;
	string S;
	cin >> N >> Q >> S;

	vector<pair<int, int>> range(Q);
	for (int i = 0; i < Q; i++) cin >> range[i].first >> range[i].second;

	vector<int> AC(S.length());
	for (int i = 1; i < S.length(); i++) {

		if (S[i - 1] == 'A'&&S[i] == 'C')AC[i] = 1;
	}

	CuSum<int> ACsum(AC);
	for (int i = 0; i < Q; i++) {

		cout << ACsum.query(range[i].first, range[i].second) << "\n";
	}

	return 0;
}

Measured memory_bytes: 2640
def io_tmp():
    global input
    import io, sys
    #f = io.StringIO(open(0).read())
    f = io.BytesIO(sys.stdin.buffer.read())
    input = f.readline

io_tmp()


from scipy.sparse.csgraph import floyd_warshall
import numpy as np

N, M, L = map(int, input().split())
graph = [[0] * N for _ in range(N)]
for _ in range(M):
    s, t, w = map(int, input().split())
    if w <= L:
        graph[s-1][t-1] = graph[t-1][s-1] = w
dist = floyd_warshall(graph, directed=False)
graph = dist <= L
#np.fill_diagonal(graph, 0)
#graph[dist > L] = 0
dist = floyd_warshall(graph, directed=False)
dist[np.isinf(dist)] = 0
dist = dist.astype(int)

Q = int(input())
ans = []
for _ in range(Q):
    s, t = map(int, input().split())
    ans.append(dist[s-1][t-1] - 1)
print(*ans, sep='\n')


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

int main(){
  int a,b,c;
  cin>>a>>b;
  c=a+b;
  if(c%2==0)cout<<c/2<<endl;
  else cout<<"IMPOSSIBLE"<<endl;
  
  return 0;
}

Measured memory_bytes: 3640
#include<bits/stdc++.h>
using namespace std;
 
#define ll long long
#define pb push_back
 
const int maxn = 3e2 + 20;
const int mod = 998244353;

bitset<maxn> a[maxn];

int ind[maxn];

int bpw(int a , int b)
{
	if(!b)
		return 1;
	int x = bpw(a , b / 2);

	x = 1LL * x * x % mod;
	if(b&1)
		x = 1LL * x * a % mod;

	return x;
}

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

	int n , m;
	cin >> n >> m;

	for(int i = 0; i < n; i++)
		for(int j = 0; j < m; j++)
		{
			int x;
			cin >> x;
			a[i][j] = x;
		}

	memset(ind , -1 , sizeof ind);

	int res = 0;
	for(int i = 0; i < n; i++)
	{
		for(int j = m - 1; j >= 0; j--)
			if(a[i][j] && ind[j] != -1)
				a[i] ^= a[ind[j]];

		int last = -1;
		for(int j = 0; j < m; j++)
			if(a[i][j])
				last = j;

		if(last == -1)
			continue;

		for(int j = m - 1; j >= 0; j--)
			if(ind[j] != -1 && a[ind[j]][last])
				a[ind[j]] ^= a[i];

		ind[last] = i;
		res++;
	}

	res = (1LL * bpw(2 , n - res) * (bpw(2 , res) - 1 + mod)) % mod;
	res = 1LL * res * bpw(2 , m - 1) % mod;

	cout << res << endl;
}


















Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
ll arr[200000][3];
ll dp[200000][3];
ll solve(ll n,ll state)
{
    if(n<0)
        return 0;
    if(dp[n][state] != -1)
     return dp[n][state];
    if(state==0)
        dp[n][state]=max(solve(n-1,1)+arr[n][1],solve(n-1,2)+arr[n][2]);
    else if(state==1)
        dp[n][state]=max(solve(n-1,0)+arr[n][0],solve(n-1,2)+arr[n][2]);
    else if(state==2)
        dp[n][state]=max(solve(n-1,1)+arr[n][1],solve(n-1,0)+arr[n][0]);
    return dp[n][state];
}
int main()
{
    int n;
    cin>>n;
    for(int i=0;i<n;i++)
        for(int j=0;j<3;j++){
        cin>>arr[i][j];
        }
     memset(dp, -1, sizeof(dp));
    ll ans;
    ll ans1,ans2,ans3;
    ans1=arr[n-1][0]+solve(n-2,0);
    ans2=arr[n-1][1]+solve(n-2,1);
    ans3=arr[n-1][2]+solve(n-2,2);
    ans=max(ans1,max(ans2,ans3));
    cout<<ans;
}


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

#define rep(i,n) for(int i=0; i<(n); i++)
#define reps(i,x,n) for(int i=x; i<(n); i++)
#define rrep(i,n) for(int i=(n)-1; i>=0; i--)
#define all(X) (X).begin(),(X).end()
#define X first
#define Y second
#define pb push_back
#define eb emplace_back

using namespace std;
typedef long long int ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;

template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return 1; } return 0; }

template<class A, size_t N, class T> void Fill(A (&a)[N], const T &v){ fill( (T*)a, (T*)(a+N), v ); }

template<class T> ostream& operator<<(ostream &os, const vector<T> &t) {os<<"{"; rep(i,t.size()) {os<<t[i]<<",";} os<<"}"; return os;}
template<class T,size_t n> ostream& operator<<(ostream &os, const array<T,n> &t) {os<<"{"; rep(i,n) {os<<t[i]<<",";} os<<"}"; return os;}
template<class S, class T> ostream& operator<<(ostream &os, const pair<S,T> &t) { return os<<"("<<t.first<<","<<t.second<<")";}

const ll INF = 1e15+7;


int main(){
	ios_base::sync_with_stdio(false);
	ll N, ans=0;
	ll A[200005];

	cin >> N;
	rep(i,N) cin >> A[i+1];
	A[0] = INF;
	A[N+1] = INF;
	N += 2;

	vector<pll> v[2];
	rep(k,2) v[k].emplace_back(0, INF);
	ll cost[2][200005] = {};
	rep(k,2){
		rep(i,N-1){
			if( A[i] >= A[i+1] ){
				int cap = -1;
				ll cur = A[i+1];
				while(cur <= A[i]) cur *= 4, cap++;
				if(cap > 0) v[k].emplace_back(i, cap);
			}else{
				int cap = 0;
				ll cur = A[i];
				while(cur < A[i+1]) cur *= 4, cap++;
				ll res = 0;
				rep(j,cap){
					while(v[k].back().Y <= 0) v[k].pop_back();
					res += i - v[k].back().X;
					v[k].back().Y--;
				}
				cost[k][i] += res;
			}
			//cout << k << "," << i << "\t" << cost[k][i] << "\t: " << v[k] << endl;
		}
		reverse(A, A+N);
	}
	//rep(k,2){ rep(i,N) cout << cost[k][i] << ","; cout << endl;}

	ll sum[2][200005] = {};
	rep(k,2) rep(i,N) sum[k][i+1] = sum[k][i] + cost[k][i];
	//rep(k,2){ rep(i,N+1) cout << sum[k][i] << ","; cout << endl;}

	ans = INF;
	rep(i,N-1){
		ll score = sum[0][i]*2ll + sum[1][N-i-2]*2ll + i*1ll;
		chmin(ans, score);
		//cout << i << " " << sum[0][i] << "+" << sum[1][N-i-2] << "\t" << score << endl;
	}
	//ans = sum[1][N-1]*2ll;
	//rep(i,N-1){
	//	ll score = sum[0][i]*2ll + sum[1][N-i-2]*2ll + i+1ll;
	//	chmin(ans, score);
	//	cout << i << " " << sum[0][i] << "+" << sum[1][N-i-2] << "\t" << score << endl;
	//}
	//chmin(ans, sum[0][N-1]*2ll + N);

	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 8064
#define _DEBUG 1
#define _GLIBCXX_DEBUG

#include <bits/stdc++.h>
using namespace std;

using ll = long long;

#ifdef _DEBUG
#define dump(x) cerr << #x << "=" << x << endl
#define dump2(x, y) cerr << #x << "=" << x << "," << #y << "=" << y << endl
#define dump3(x, y, z)                                                     \
  cerr << #x << "=" << x << "," << #y << "=" << y << "," << #z << "=" << z \
       << endl
#define check(s) cerr << s << endl
#else
#define dump(x)
#define dump2(x, y)
#define dump3(x, y, z)
#define check(s)
#endif

#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(x) (x).begin(), (x).end()
#define sz(x) ((int)(x).size())
#define unique(v) v.erase(unique(v.begin(), v.end()), v.end());

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

void solve(ll N, std::vector<ll> X) {
  ll mn = LINF;
  for (int P = 1; P <= 100; P++) {
    ll sum = 0;
    rep(i, N) { sum += pow(X.at(i) - P, 2); }
    mn = min(mn, sum);
  }
  cout << mn << endl;
}

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout << fixed << setprecision(15);
  ll N;
  scanf("%lld", &N);
  std::vector<ll> X(N);
  for (int i = 0; i < N; i++) {
    scanf("%lld", &X[i]);
  }
  solve(N, std::move(X));
  return 0;
}


Measured memory_bytes: 3716
import java.util.*;

public class Main {

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

        int a = scanner.nextInt();
        int b = scanner.nextInt();
        int h = scanner.nextInt();
        int m = scanner.nextInt();

        double hangle = (h * 30) + (m * 0.5);
        double manble = m * 6;
        double angle = Math.abs(hangle - manble);
        if (angle > 180) {
            angle = 360 - angle;
        }

        double length = Math.sqrt(Math.pow(a, 2) + Math.pow(b, 2) - (2 * a * b * Math.cos(Math.toRadians(angle))));
        System.out.println(length);
    }
}

Measured memory_bytes: 35904
#include <stdio.h>
#include <string.h>
typedef long long ll;

int main(void) {
  ll i, cnt[26], n, ans = 1;
  for(i = 0; i < 26; ++i) cnt[i] = 0;
  char s[1000000];
  scanf("%s", s);
  n = strlen(s);
  for(i = 0; i < n; ++i) cnt[s[i] - 'a']++;
  for(i = 0; i < n; ++i) {
    ans += n - cnt[s[i] - 'a'] - i;
    cnt[s[i] - 'a']--;
  }
  printf("%lld", ans);
  return 0;
}

Measured memory_bytes: 384
#include <iostream>
using namespace std;
int main(){
  int n;cin>>n;
  int a[n];
  int b[n];
  int c[n];
  for(int i = 0; n > i; i++)cin>>a[i];
  for(int i = 0; n > i; i++)cin>>b[i];
  for(int i = 0; n-1 > i; i++)cin>>c[i];
  int prev = -1;
  int ans = 0;
  for(int i = 0; n > i; i++){
    ans += b[a[i]-1];
    if(prev+1==a[i]){
      ans += c[prev-1];
    }
    prev = a[i];
  }
  cout << ans << endl;
}


Measured memory_bytes: 256
#pragma warning disable

using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Runtime.Serialization.Formatters.Binary;
using System.Text;
using System.Text.RegularExpressions;
using System.Diagnostics;
using System.Numerics;
using System.Collections;

static class MainClass
{
    public static void Main(string[] args)
    {
        var na = Console.ReadLine().SplittedStringToInt32List();
        var n = na[0];
        var a = na[1];

        var xn = Console.ReadLine().SplittedStringToInt32List();
        
        var dp = new long[n + 1,n + 1,2520];
        dp[0, 0, 0] = 1;
        for (int i = 0; i < n; i++)
        {
            for (int j = 0; j <= n; j++)
            {
                for (int k = 0; k <= 2510; k++)
                {
                    if (j - 1 >= 0 && k - xn[i] >= 0)
                        dp[i + 1, j, k] = dp[i, j, k] + dp[i, j - 1, k - xn[i]];
                    else
                        dp[i + 1, j, k] = dp[i, j, k];
                }
            }
        }
        var count = 0l;
        for (int i = 1; i <= n; i++)
        {
            count += dp[n, i, a * i];
        }
        Console.WriteLine(count);

        Console.ReadLine();
    }

    #region ライブラリ
    public static long ToInt64(this string str) => long.Parse(str);
    public static int ToInt32(this string str) => int.Parse(str);
    public static BigInteger ToBigInteger(this string str) => BigInteger.Parse(str);
    public static List<string> SplittedStringToList(this string str) => str.Split(new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries).ToList();
    public static List<int> SplittedStringToInt32List(this string str) => str.Split(new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries).Select(x => int.Parse(x)).ToList();
    public static List<long> SplittedStringToInt64List(this string str) => str.Split(new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries).Select(x => long.Parse(x)).ToList();
    public static List<BigInteger> SplittedStringToBigInteger(this string str) => str.Split(new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries).Select(x => BigInteger.Parse(x)).ToList();
    public const int INF = int.MaxValue / 2;
    public const long LONGINF = long.MaxValue / 2;
    public const int Mod1e9 = 1000000007;
    

    public static void PrintArray(int[,] array)
    {
        for (int i = 0; i < array.GetLength(0); i++)
        {
            var sb = new StringBuilder();
            for (int j = 0; j < array.GetLength(1); j++)
            {
                sb.Append(array[i, j]).Append(" ");
            }
            Console.WriteLine(sb.ToString());
        }
    }

    #endregion
}



Measured memory_bytes: 64224
#include <cstdio>
#include <algorithm>
#include <utility>
#include <cassert>

#define FOR(i, n) for(int i = 0; i < n; i++) 

#define pow CHANGETHENAMESTUPID

using namespace std;

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

using ll = long long;
ll modinv(ll a, ll m) {
	assert(m > 0);
	if (m == 1) return 0;
	a %= m;
	if (a < 0) a += m;
	assert(a != 0);
	if (a == 1) return 1;
	return m - modinv(m, a) * m / a;
}
 
template <int MOD_> struct modnum {
private:
	int v;
public:
	static const int MOD = MOD_;
 
	modnum() : v(0) {}
	modnum(ll v_) : v(int(v_ % MOD)) { if (v < 0) v += MOD; }
	explicit operator int () const { return v; }
	friend bool operator == (const modnum& a, const modnum& b) { return a.v == b.v; }
	friend bool operator != (const modnum& a, const modnum& b) { return a.v != b.v; }
 
	modnum operator ~ () const {
		modnum res;
		res.v = modinv(v, MOD);
		return res;
	}
 
	modnum& operator += (const modnum& o) {
		v += o.v;
		if (v >= MOD) v -= MOD;
		return *this;
	}
	modnum& operator -= (const modnum& o) {
		v -= o.v;
		if (v < 0) v += MOD;
		return *this;
	}
	modnum& operator *= (const modnum& o) {
		v = int(ll(v) * ll(o.v) % MOD);
		return *this;
	}
	modnum& operator /= (const modnum& o) {
		return *this *= (~o);
	}
 
	friend modnum operator + (const modnum& a, const modnum& b) { return modnum(a) += b; }
	friend modnum operator - (const modnum& a, const modnum& b) { return modnum(a) -= b; }
	friend modnum operator * (const modnum& a, const modnum& b) { return modnum(a) *= b; }
	friend modnum operator / (const modnum& a, const modnum& b) { return modnum(a) /= b; }
};
 
using num = modnum<998244353>;

const int N = 1e5 + 100;

int n; int d[N];

void load() {
	scanf("%d", &n);
	FOR(i, n) scanf("%d", d + i);
}

num solve() {
	if (d[0]) return 0;
	sort(d, d + n);
	for (int i = 1; i < n; i++) if (d[i] > d[i-1] + 1) return 0;
	if (n > 1 && !d[1]) return 0;
	int ind = 1;
	int pre = 1;
	num res = 1;
	while (ind < n) {
		int ind_ = ind;
		while (ind_ < n && d[ind_] == d[ind]) ind_++;
		int cur = ind_ - ind;
		FOR(i, cur) res *= pre;
		ind = ind_;
		pre = cur;
	}
	return res;
}

int main() {
	load();
	printf("%d\n", (int)solve());
	return 0;
}


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

using namespace std;

#define mp make_pair
#define pb push_back
#define f first
#define s second
#define ll long long

#define for(i,a,b) for (i=a; i<b; i++)
#define forb(i,a,b) for (i=a; i>b; i--)
#define all(S) S.begin(),S.end()
#define sort(S) sort(all(S))

const int inf = 1e9+7;
const ll INF = 1e18;
const int sq = 320;

ll m[200000],r;
vector <pair <ll,ll> > V;

ll st(ll a, ll b)
{
    ll ans = 1;
    ll a1 = a;
    int i;
    for (i,0,17)
    {
        if (b&(1<<i))
            ans=(ans*a1)%inf;
        a1=(a1*a1)%inf;
    }
    return ans;
}

void go(ll k, ll ans)
{
    if (k==V.size())
    {
        r-=m[ans];
        return;
    }
    ll bns = ans;
    ll i;
    go(k+1,ans);
    for (i,0,V[k].s)
    {
        bns*=V[k].f;
        go(k+1,bns);
    }
    return;
}

int main()
{
    cin.tie(0);
    cout.tie(0);
    ios_base::sync_with_stdio(false);
    ll n,k,ans=0,i,j;
    cin >> n >> k;
    for (i,1,k+1)
    {
        ll kol = k/i;
        r = i;
        V.clear();
        ll u = i;
        for (j,2,sq)
            if (i%j==0)
        {
            V.pb(mp(j,0));
            while (u%j==0)
            {
                V.back().s++;
                u/=j;
            }
        }
        if (u>1)
            V.pb(mp(u,1));
        go(0,1);
        m[i]=r;
        ans=(ans+st(kol,n)*r)%inf;
    }
    cout << (ans+inf)%inf << endl;
}


Measured memory_bytes: 4408
#include <bits/stdc++.h>
using namespace std;
 
int n, m, x;
int c[12];
int a[12][12];
int u[12];
int dp[4096];
 
constexpr int MAX = 1e9;
 
bool ok() {
	for (int i = 0; i < m; ++i) {
		if (u[i] < x) {
			return false;
		}
	}
 
	return true;
}
 
void add(int b) {
	for (int i = 0; i < m; ++i) {
		u[i] += a[b][i];
	}
}
 
void rm(int b) {
	for (int i = 0; i < m; ++i) {
		u[i] -= a[b][i];
	}
}
 
int f(int mask, int s = 0) {
	if (ok()) {
		return s;
	}
 
	if (dp[mask] != MAX) {
		return dp[mask];
	}
 
	int mn = 1e9;
	for (int i = 0; i < n; ++i) {
		if ((mask >> i) & 1) {
			continue;
		}
 
		mask += (1 << i);
		add(i);
		mn = min(mn, f(mask, s + c[i]));
		dp[mask] = min(dp[mask], mn);
		rm(i);
		mask -= (1 << i);
	}
 
	return mn;
}
 
int main() {
	cin >> n >> m >> x;
	
	for (int i = 0; i < m; ++i) {
		u[i] = 0;
	}

	for (int i = 0; i < n; ++i) {
		cin >> c[i];
		for (int j = 0; j < m; ++j) {
			cin >> a[i][j];
			u[j] += a[i][j];
		}
	}

	if (!ok()) {
		cout << -1;
		return 0;
	}
 
	for (int i = 0; i < 4096; ++i) {
		dp[i] = MAX;
	}
 
	for (int i = 0; i < m; ++i) {
		u[i] = 0;
	}
 
	int ans = f(0);
	if (ans == MAX) {
		cout << -1;
	} else {
		cout << ans;
	}
	
	return 0;
}

Measured memory_bytes: 3668
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const static ll INF = LLONG_MAX;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
// __uint128_t
const ll MOD = 1e9+7;



int main(){
    ll N, K; cin >> N >> K;
    vector<ll> A(N+1);
    for(int i = 0; i < N; i++) cin >> A[i];
    while(K--){
        vector<ll> A_(N+1);
        for(int i = 0; i < N; i++){
            ll l = i-A[i], r = i + A[i];
            l = max(l, 0LL), r = min(r, N-1);
            A_[l]++;
            A_[r+1]--;
        }
        ll t = 0;
        bool flag = true;
        for(int i = 0; i < N; i++) {
            t += A_[i];
            A[i] = t;
            if(flag && A[i] != N) flag = false;
        }
        if(flag) break;
    }
    for(int i = 0; i < N; i++) cout << A[i] << " "; cout << endl;
}


Measured memory_bytes: 6320
/**
 * code generated by JHelper
 * More info: https://github.com/AlexeyDmitriev/JHelper
 * @author
 */

#include <iostream>
#include <fstream>

#include <iostream>
#include "bits/stdc++.h"

using namespace std;

typedef unsigned long long ll;
typedef int                     integer;
#define int                     long long
#define ii                      pair<int,int>
#define vii                     vector<pair<int,int>>
#define vi                      vector<int>
#define vvi                     vector<vector<int>>
#define f(a,b,c)                for(int a=b;a<c;a++)
#define s(x)                    in>>x
#define s2(x,y)                 in>>x>>y
#define s3(x,y,z)               in>>x>>y>>z
#define s4(x,y,z,w)             in>>x>>y>>z>>w
#define p(x)                    out<<x<<endl
#define p2(x,y)                 out<<x<<" "<<y<<endl
#define pl(x)                   out<<x
#define p2l(x,y)                out<<x<<" "<<y
#define p1d(a,n)                for(int ix=0;ix<n;ix++) out<<a[ix]<<" "; out<<endl
#define p2d(a,n,m)              for(int ix=0;ix<n;ix++){ for(int jx=0;jx<m;jx++) out<<a[ix][jx]<<" "; out<<endl;}
#define range(v)                v.begin(),v.end()
#define w(x)                    while(x--)
#define rst(x)                  memset(x, -1, sizeof(x))
#define UNVISITED               -1
#define VISITED                 0
#define EXPLORED                2

class AACOrWA {
public:
	void solve(std::istream& in, std::ostream& out) {
        int n,m;
        s2(n,m);
        out<<(m==n?"Yes":"No")<<endl;
	}
};


integer main() {
	AACOrWA solver;
	std::istream& in(std::cin);
	std::ostream& out(std::cout);
	solver.solve(in, out);
}


Measured memory_bytes: 256
#include<iostream>

int main (){
    std::cin.tie(0); 
	std::ios::sync_with_stdio(false);
    int L,R,d;std::cin >> L >> R >> d;

    int ans=0;

    for (int i=L;i<=R;++i) {
        if (i % d == 0) {
            ++ans;
        }
    }
    std::cout << ans;

    return 0;
}

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

using namespace std;

typedef long long ll;
typedef long double ld;

#define mp make_pair
#define ff first
#define ss second
#define pb push_back
#define pf push_front
#define popb pop_back
#define popf pop_front
#define all(v) v.begin(),v.end()

const int maxn = 1e5 + 100;
const ll inf = 2e18, mod = 1e9 + 7;

int n, l[maxn];

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

	cin >> n;
	for (int i = 0; i < 2 * n; i++)
		cin >> l[i];
	sort(l, l + 2 * n);
	ll ans = 0;
	for (int i = 2 * n - 1; i >= 0; i -= 2)
		ans += l[i - 1];
	cout << ans << endl;
}



Measured memory_bytes: 256
//
//  code.cpp
//  Cpp
//
//  Created by Yash Jain on 25/02/20.
//  Copyright © 2020 Yash Jain. All rights reserved.
//

#include<bits/stdc++.h>
#define mod 1000000007
using namespace std;
int degree[200001];
long long fact[200001];

long long powermod(long long a,long long b){
    if(b == 0)
        return 1;
    if(b%2 == 1)
        return (a*(powermod((a*a)%mod,b/2)))%mod;
    return powermod((a*a)%mod, b/2);
}

long long ncr(long long a,long long b){
    long long temp = (fact[a]*powermod(fact[b],mod-2))%mod;
    temp = (temp*powermod(fact[a-b],mod-2))%mod;
    return temp;
}

int main(){
    
    int n,x,y;
    cin>>n>>x>>y;
    
    int dist[n];
    memset(dist,0,sizeof(dist));
    
    for(int i=1;i<=n;i++){
        for(int j=i+1;j<=n;j++){
            int now = j-i;
            now = min(now,abs(x-i)+1+abs(j-y));
            now = min(now,abs(y-i)+1+abs(j-x));
            dist[now]++;
        }
    }
    
    for(int i=1;i<=n-1;i++){
        cout<<dist[i]<<"\n";
    }
    
}


Measured memory_bytes: 764
from itertools import product
n = int(input())
tells = [[] for _ in range(n)]
for i in range(n):
    for j in range(int(input())):
        tells[i].append(list(map(int, input().split())))
for i in product(['1', '0'], repeat=n):
    a = list(map(int, i))
    flag = True
    for j in range(n):
        for k in tells[j]:
            if a[j] and a[k[0]-1] != k[1]:
                flag = False
                break
    if flag:
        print(sum(a))
        break

Measured memory_bytes: 43884
#define _USE_MATH_DEFINES
#include<iostream>
#include<string>
#include<queue>
#include<cmath>
#include<map>
#include<set>
#include<list>
#include<iomanip>
#include<vector>
#include<random>
#include<functional>
#include<algorithm>
#include<stack>
#include<cstdio>
#include<bitset>
#include<unordered_map>
#include<climits>
#include<fstream>
using namespace std;
///////////////////library zone!!!!!!!!!!!!!!!!!!!!!!!!!!!!
typedef long long ll;
typedef long double ld;
#define all(a) (a).begin(),(a).end()
#define EPS (1e-5)
#define bit(n,k) ((n>>k)&1)
const ll Mod = 1000000007;
const ll mod = 998244353;
struct H {
	ll x, y;
	bool operator<(const H& b) const {
		if (x != b.x) return x < b.x;
		return y < b.y;
	}
	bool operator>(const H & b) const {
		if (x != b.x) return x > b.x;
		return y > b.y;
	}
	bool operator==(const H & b) const { return x == b.x && y == b.y; }
	bool operator!=(const H & b) const { return (*this) != b; }
};
struct P {
	ll pos, cost;
	bool operator<(const P& b) const { return cost < b.cost; }
	bool operator>(const P& b) const { return cost > b.cost; }
};
struct B {
	ll to, cost;
};
struct E {
	ll from, to, cost;
	bool operator<(const E& b) const { return cost < b.cost; }
	bool operator>(const E& b) const { return cost > b.cost; }
};
template<typename T, typename U>
void chmin(T & a, U b) {
	if (a > b) a = b;
}
template<typename T, typename U>
void chmax(T & a, U b) {
	if (a < b) a = b;
}
template<typename T>
T max_0(T a) {
	if (a < 0) return 0;
	return a;
}
template<typename T>
T min_0(T a) {
	if (a > 0) return 0;
	return a;
}
ll read() {
	ll u;
	ll k = scanf("%lld", &u);
	return u;
}
ll gcd(ll i, ll j) {
	if (i > j) swap(i, j);
	if (i == 0) return j;
	return gcd(j % i, i);
}
ll mod_pow(ll x, ll n, ll p) {
	ll res = 1;
	while (n > 0) {
		if (n & 1) res = res * x % p;
		x = x * x % p;
		n >>= 1;
	}
	return res;
}//x^n%p
const ll Inf = 3023372036854775807;
const int inf = 1500000000;
#define int long long
//----------------------------------------------------
int n, a, b;
signed main() {
	cin >> n >> a >> b;
	cout << min(a * n, b) << endl;
}

Measured memory_bytes: 256
package main

import (
	"bufio"
	"fmt"
	"io"
	"math"
	"os"
	"strconv"
	"strings"

)


func main() {
	solve(os.Stdin, os.Stdout)
}

type ReaderEx struct {
	baseScanner *bufio.Scanner
	words       []string
	nextWordIdx func() int
	initWordIdx func(int)
}

func NewScannerEx(stdin io.Reader) *ReaderEx {
	var this ReaderEx
	var idx int
	var wordsCnt int
	this.baseScanner = bufio.NewScanner(stdin)
	this.baseScanner.Buffer(make([]byte, 0), 1E+11)
	this.nextWordIdx = func() int {
		cur := idx
		idx = (idx + 1) % wordsCnt
		return cur
	}
	this.initWordIdx = func(wc int) {
		idx = 0
		wordsCnt = wc
	}
	return &this
}

func (me *ReaderEx) Scan(doSplit bool) (isScanned bool) {
	isScanned = me.baseScanner.Scan()
	if doSplit {
		me.words = strings.Fields(me.baseScanner.Text())
	} else {
		me.words = []string{me.baseScanner.Text()}
	}
	me.initWordIdx(len(me.words))
	return
}

func (me *ReaderEx) nextBytes() []byte {
	return []byte(me.words[me.nextWordIdx()])
}
func (me *ReaderEx) nextString() string {
	return me.words[me.nextWordIdx()]
}

type StringArray []string

func (me *ReaderEx) nextStringArray() StringArray {
	return me.words[me.nextWordIdx():]
}

func (me StringArray) toStrings() []string {
	return me
}

func (me StringArray) toInts() []int {
	strValues := me.toStrings()
	values := make([]int, len(strValues))
	for i, v := range strValues {
		n, err := strconv.Atoi(v)
		if err != nil {
			panic(err)
		}
		values[i] = n
	}
	return values
}
func (me *ReaderEx) nextInt() int {
	n, err := strconv.Atoi(me.words[me.nextWordIdx()])

	defer func() {
		if err != nil {
			panic(fmt.Sprintf("getInt(%d)", n))
		}
	}()
	return n
}

func pow(x, y, mod int) (ans int) {

	ans = 1
	for bit := 1 << uint(math.Floor(math.Log2(float64(y)))); ; bit >>= 1 {
		if y&bit != 0 {
			ans *= x
			if mod > 0 {
				ans %= mod
			}
		}
		if bit <= 1 {
			return
		}
		ans *= ans
		if mod > 0 {
			ans %= mod
		}
	}
}

type factType struct {
	prime int
	count int
}

func fact(n int) (facts []*factType) {

	for i := 2; i*i <= n; i++ {
		if n%i == 0 {
			fa := factType{prime: i}
			for n%fa.prime == 0 {
				n /= fa.prime
				fa.count++
			}
			facts = append(facts, &fa)
		}
	}
	if n > 1 {
		facts = append(facts, &factType{prime: n, count: 1})
	}
	return facts
}
func dec2bin(n int) (ret []bool) {
	for bit := 1 << uint(math.Floor(math.Log2(float64(n)))); ; bit >>= 1 {
		ret = append(ret, n&bit != 0)

		if bit <= 1 {
			return
		}
	}

}

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

func b2i(b bool) (i int) {
	if b {
		i = 1
	} else {
		i = 0
	}
	return
}

func solve(stdin io.Reader, stdout io.Writer) {

	r := NewScannerEx(stdin)
	r.Scan(true)
	n := r.nextInt()
	r.Scan(true)
	a := r.nextStringArray().toInts()

	cnt := map[int]int{}
	for _, c := range a {
		cnt[c] = 1
	}

	fmt.Fprintln(stdout, []string{"NO", "YES"}[b2i(len(cnt) == n)])
}


Measured memory_bytes: 15360
#include <iostream>
#include <stdio.h>
#include <algorithm>
#include <math.h>
#include <list>
#include <string>
#include <map>
#include <vector>
#include <stack>
#include <queue>
#include <iomanip> // setprecisionを使用するのに必要 cout << fixed << setprecision(15) << p でpを小数点以下15桁表示
using namespace std;
#define REPD(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i, n) REPD(i, 0, n)
#define DIV0 1000000007
typedef long long ll;
#define fin(ans) cout << (ans) << '\n'
/*

*/
int main()
{
    int N;
    cin >> N;
    int A[N];
    REP(i,N) cin >> A[i];
    ll money = 1000;
    REP(i,N){
        if(i == 0)continue;
        if(A[i-1] < A[i]){
            money = money/A[i-1]*A[i] + (money%A[i-1]);
        }
    }
    fin(money);
    return 0;
}

Measured memory_bytes: 3192
import java.util.Scanner;

public class Main{
  public static void main(String[] args){

    Scanner sc = new Scanner(System.in);
    int A = sc.nextInt();
    int B = sc.nextInt();
    int addition = A+B;

    if(addition<10){
      System.out.println(addition);
    }else{
      System.out.println("error");
    }

  }
}


Measured memory_bytes: 21844
def main():
    N, W = map(int, input().split())
    # (v, w)
    items = [tuple(map(int, input().split())) for _ in range(N)]
    """
    使い回さない
    dp = [[0]*(W+1) for _ in range(N+1)]
    for i in range(N):
        for w in range(W+1):
            if items[i][1] > w:
                dp[i+1][w] = dp[i][w]
            else:
                dp[i+1][w] = max(dp[i][w], dp[i+1][w-items[i][1]]+items[i][0])
    print(max(dp[N]))
    """
    """ 使い回す方 """
    dp = [0]*(W+1)
    for i in range(N):
        for w in range(W+1):
            if items[i][1] <= w:
                dp[w] = max(dp[w], dp[w-items[i][1]]+items[i][0])
    print(max(dp))


if __name__ == "__main__":
    main()


Measured memory_bytes: 5920
s = input();
char_list = list(str(s))
N = 753
mini = 100000

for i in range(len(char_list)-2):
    temp = int(char_list[i]+char_list[i+1]+char_list[i+2])

    if mini > abs(N - temp) :
        mini = abs(N - temp)


print(mini)


Measured memory_bytes: 3064
import java.util.Scanner;

public class Main {
	public static void main(String[] args)  {
		Scanner sc = new Scanner((System.in));
		int w = sc.nextInt();
		int a = sc.nextInt();
		int b = sc.nextInt();
		if( a <=b ) {
			if(w + a < b) {
				System.out.println(Math.abs(w + a -b));
			}else {
				System.out.println(0);
			}
		}else {
			if(w + b < a) {
				System.out.println(Math.abs(w + b -a));
			}else {
				System.out.println(0);
			}
		}
		}
}

Measured memory_bytes: 23764
#include <algorithm>
#include <bitset>
#include <cassert>
#include <chrono>
#include <climits>
#include <cmath>
#include <complex>
#include <cstring>
#include <deque>
#include <functional>
#include <iostream>
#include <iomanip>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <unordered_map>
#include <unordered_set>
#include <vector>
#include <cstdint>
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef pair<int,int> pii;
#define MP make_pair
#define PB push_back
#define inf 1000000007
#define rep(i,n) for(int i = 0; i < (int)(n); ++i)
#define all(x) (x).begin(),(x).end()

template<typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val){
    std::fill( (T*)array, (T*)(array+N), val );
}
 
template<class T> inline bool chmax(T &a, T b){
    if(a<b){
        a = b;
        return true;
    }
    return false;
}

template<class T> inline bool chmin(T &a, T b){
    if(a>b){
        a = b;
        return true;
    }
    return false;
}

class Trie {
public:
	struct Node {
		Node *next[26];
        ll res[26];
        ll sm[26];
		int sub;
		Node() : sub(0){
			for(int i = 0; i < 26; i++){
				next[i] = nullptr;
                res[i] = 0;
                sm[i] = 0;
            }
		}
	};
	Node* root;
    ll ans;
	Trie(){
		root = new Node();
	}
	//Trie木にxを加える
	void add(string& s) {
        Node *curr = root;
		for(int i = 0; i < (int)s.size(); i++){
			if(i==(int)s.size()-1){
                curr->res[s[i]-'a']++;
            }
            int y = s[i] - 'a';
			if (!curr->next[y]) {
				curr->next[y] = new Node();
			}
			curr->sub++;
			curr = curr->next[y];
		}
		curr->sub++;
	}
    //何らかのクエリ
	int query(Node *curr,int d) {
		int res = 0;
		for(int i = 0; i < 26; i++){
			if(curr->next[i]){
				res += query(curr->next[i],d+1);
			}
		}
		return res;
	}
	int query() {
		return query(root, 0);
	}
    void dfs(Node *curr,int c){
        for(int i = 0; i < 26; i++){
			if(curr->next[i]){
                dfs(curr->next[i],i);    
                for(int j=0;j<26;j++){
                    curr->sm[j] += curr->next[i]->sm[j];
                }
            }
		}
        for(int i=0;i<26;i++){
            // cerr << c << " "<< curr->sm[i] << " " << curr->res[i] << endl;
            if(curr->res[i]){
                ans += curr->sm[i]-1;
            }
        }
        if(c!=-1){
            curr->sm[c] = curr->sub;
        }
    }
    ll init(){
        ans = 0;
        dfs(root,-1);
        return ans;
    }
};

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    Trie tr;
    int n;
    cin >> n;
    rep(i,n){
        string s;
        cin >> s;
        reverse(s.begin(),s.end());
        tr.add(s);
    }
    cout << tr.init() << endl;
    return 0;
}

Measured memory_bytes: 681116
import sys

sr = lambda: sys.stdin.readline().rstrip()
ir = lambda: int(sr())
lr = lambda: list(map(int, sr().split()))

N = sr()
K = ir()
length = len(N)
top = int(N[0])
dp_de = [[0] * 4 for _ in range(length)] #decided
dp_pend = [[0] * 4 for _ in range(length)] #pending
dp_de[0][1] = (top-1)
dp_de[0][0] = 1
dp_pend[0][1] = 1
for i in range(1, length):
    cur = int(N[i])
    # pend → pend
    if cur == 0:
        dp_pend[i] = dp_pend[i-1][:] #右端に0
    else:
        for k in range(1, 4):
            dp_pend[i][k] = dp_pend[i-1][k-1] #右端にcur

    dp_de[i] = dp_de[i-1][:] #0が右端に加わった場合
    for j in range(1, 4):
        dp_de[i][j] += dp_de[i-1][j-1] * 9 #1~9が右端に加わった場合
        if cur > 0:
            # pendから流れる、右端にcur以下の数が加わった場合と0が加わった場合
            dp_de[i][j] += dp_pend[i-1][j-1] * (cur-1) + dp_pend[i-1][j] * 1 

answer = dp_de[length-1][K] + dp_pend[length-1][K]
print(answer)


Measured memory_bytes: 3064
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.HashMap;
import java.util.StringTokenizer;

class Main{

	public static void main(String[] args) throws IOException{
		BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
		int N=Integer.parseInt(br.readLine());
		StringTokenizer st=new StringTokenizer(br.readLine());
		HashMap<Integer, Integer> hm=new HashMap<>();
		for(int i=0;i<N;i++)
		{
			int key=Integer.parseInt(st.nextToken());
			hm.put(key, hm.getOrDefault(key, 0)+1);
		}
		
		int ans=0;
		for (Integer key: hm.keySet()) {
			if(hm.get(key)<key)
				ans+=hm.get(key);
			else
			ans+=Math.abs(hm.get(key)-key);
		}
		
		System.out.println(ans);
	}

}


Measured memory_bytes: 43092
#include <stdio.h>
int main(void){
    // Your code here!
    int N;
    int dam[100001];
    int ans[100001];
    
    int i;
    int sum = 0;
    int sum_even=0;
    scanf("%d\n",&N);
    for(i=1;N>=i;i++){
        scanf("%d",&dam[i]);
        sum += dam[i];
        if(i%2==1 && i!=N) sum_even += dam[i];
    }
    sum = sum/2; //偶数であることが保証されている．
    ans[N] = sum - sum_even;
    ans[1] = dam[N]-ans[N];
    
    for(i=2;N>i;i++){
        ans[i] = dam[i-1] - ans[i-1];
    }
    
    for(i=1;N>=i;i++){
        printf("%d",ans[i]*2);
        if(i<N) printf(" ");
        else    printf("\n");
    }
    
    return 0;    
}


Measured memory_bytes: 2048
#include<cstdio>
#include<algorithm>
using namespace std;
int D[5010][5010], n, Mod, C[5010];
void Make(int t) {
	int i, j;
	for (i = 0; i <= n / (t+1); i++) {
		for (j = t * i; j <= n-t; j++) {
			D[i + 1][j + t] = (D[i + 1][j + t] + D[i][j]) % Mod;
		}
	}
}
int main() {
	int i, j;
	scanf("%d%d", &n, &Mod);
	D[0][0] = 1;
	for (i = 2; i <= n; i++) {
		C[min(i - 2, n + 1 - i)]++;
	}
	for (i = n / 2; i >= 0; i--) {
		for (j = 0; j < C[i]; j++) {
			Make(i);
		}
	}
	int res = 0;
	for (i = 0; i < n; i++) {
		for (j = 0; j <= n; j++) {
			res = (res + (long long)max(n - i - j, 0) * D[i][j]) % Mod;
		}
	}
	printf("%d\n", res);
}

Measured memory_bytes: 98048
#include <bits/stdc++.h>
#include <cmath>
#include <numeric>
using namespace std;
using ll=long long;
#define rep(i,a,b) for(int i=(a); i<(b); ++i) // a ≦ i < b 
#define Rrep(i,a,b) for(int i=(a);i>=(b);--i) // reverse repeat. a から b まで減少．
#define ALL(a) (a).begin(),(a).end()


int main() {
	int K, S;
	cin >> K >> S;
	int counter = 0;

	rep(x, 0, K+1){
		rep(y, 0, K+1){
			int z = S - x - y;
			if (0 <= z && z <= K) ++counter;
		}
	}
	cout << counter << endl;

}


Measured memory_bytes: 256
#include "bits/stdc++.h"
#define rep(i,n) for(int i = 0; i < (n); ++i)
using namespace std;
typedef long long int ll;
typedef pair<int, int> P;
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; }

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int x, a, b;
    cin >> x >> a >> b;
    if(b <= a) cout << "delicious" << endl;
    else if(b <= a+x) cout << "safe" << endl;
    else cout << "dangerous" << endl;
    return 0;
}

Measured memory_bytes: 256
using System;
using System.Linq;
using System.Collections.Generic;

using E = System.Linq.Enumerable;

public class Program
{
    public static void Main()
    {
        var nk = Console.ReadLine().Split().Select(x => int.Parse(x)).ToArray();
        var n = nk[0];
        var k = nk[1];
        var s = Console.ReadLine().Trim();

        var happyness = 0;
        var m = 1;
        var l = 0;
        for (int i = 0; i < s.Length; ++i)
        {
            if (s[i] == s[l])
            {
                continue;
            }

            happyness += i - l - 1;
            l = i;
            ++m;
        }
        happyness += s.Length - l - 1;

        k = Math.Min(k, m / 2);
        happyness += k * 2 - (k * 2 == m ? 1 : 0);

        Console.WriteLine(happyness);
    }
}


Measured memory_bytes: 13536
#include<stdio.h>

int main(void)
{
    int n, b, f, r, v;
    int i, j, k;
    int count[4][3][10];
    for ( i=0; i<4; ++i)
        for ( j=0; j<3; ++j)
            for ( k=0; k<10; ++k)
                count[i][j][k] = 0;

    scanf("%d", &n);
    for ( ; n>0; --n) {
        scanf("%d %d %d %d", &b, &f, &r, &v);
        count[b-1][f-1][r-1] += v;
    }
    
    /* 書き出し */
    for ( i=0; i<4; ++i) {
        for ( j=0; j<3; ++j) {
            for ( k=0; k<10; ++k) {
                printf(" %d", count[i][j][k]);
            }
            putchar('\n');
        }
        if (i!=3) printf("####################\n");
    }
    
    return 0;
}


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

struct dice{
	int top;
	int front;
	int left;
	int right;
	int back;
	int bottom;
};

struct dice ClockwiseTop(struct dice X){
	struct dice Y;
	Y.top    = X.top;
	Y.front  = X.right;
	Y.left   = X.front;
	Y.right  = X.back;
	Y.back   = X.left;
	Y.bottom = X.bottom;
	return Y;
}

struct dice ClockwiseFront(struct dice X){
	struct dice Y;
	Y.top    = X.left;
	Y.front  = X.front;
	Y.left   = X.bottom;
	Y.right  = X.top;
	Y.back   = X.back;
	Y.bottom = X.right;
	return Y;
}

struct dice ClockwiseRight(struct dice X){
	struct dice Y;
	Y.top    = X.front;
	Y.front  = X.bottom;
	Y.left   = X.left;
	Y.right  = X.right;
	Y.back   = X.top;
	Y.bottom = X.back;
	return Y;
}

struct dice ClockwiseLeft(struct dice X){
	X = ClockwiseRight(X);
	X = ClockwiseRight(X);
	X = ClockwiseRight(X);
	return X;
}

struct dice ClockwiseBack(struct dice X){
	X = ClockwiseFront(X);
	X = ClockwiseFront(X);
	X = ClockwiseFront(X);
	return X;
}

int main(){
	//????????????????????¢?????°????????\?????????
	struct dice X;
	cin >> X.top;
	cin >> X.front;
	cin >> X.right;
	cin >> X.left;
	cin >> X.back;
	cin >> X.bottom;
	//?????¢??????????????\?????????
	string Rotation;
	cin >> Rotation;
	//????????????????????¢?????????
	for(int i = 0; i < Rotation.size(); i++){
		if(Rotation[i] == 'N') X = ClockwiseRight(X);
		if(Rotation[i] == 'E') X = ClockwiseFront(X);
		if(Rotation[i] == 'S') X = ClockwiseLeft(X);
		if(Rotation[i] == 'W') X = ClockwiseBack(X);
	}
	//?????¢??????????????¨?????????
	cout << X.top << endl;
	return 0;
}

Measured memory_bytes: 1208