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

#define fastio 			ios::sync_with_stdio(0);	cin.tie(0); cout.tie(0);  cout<<fixed;  cout<<setprecision(12);	
#define randomINT 		mt19937 rnd(chrono::steady_clock::now().time_since_epoch().count());
#define	newl 			cout<<"\n"
#define DISP(as)		for(auto it : as) cout<<it<<" ";newl;
#define all(x)         	(x).begin(),(x).end()
#define mset(x,val)    	memset(x,val,sizeof(x))
#define newl           	cout<<"\n"
#define pb             	push_back
#define mp             	make_pair
#define f 				first
#define s 				second
#define dline          cerr<<"///REACHED///\n";
#define deb1(x)        cerr<<#x<<" = "<<x<<'\n';
#define deb2(x,y)      cerr<<'['<<#x<<','<<#y<<"] = "<<'['<<x<<','<<y<<']'<<'\n';
#define deb3(x,y,z)    cerr<<'['<<#x<<','<<#y<<','<<#z<<"] = "<<'['<<x<<','<<y<<','<<z<<']'<<'\n';

typedef long long 				ll;
typedef long double 			ld;
typedef vector<ll> 				vll;
typedef pair<ll ,ll> 			pll;
typedef pair<ld,ld> 			pld;
typedef unordered_map<ll,ll> 	um;
typedef vector<pll> 			vpll;

const ll 	MAX5 	= 	1e+5+7;
const ll 	MAX7 	= 	1e+7+7;
const ll 	MAXN 	= 	MAX7;
const ll   	INF   	=  	0x7f7f7f7f7f7f7f7f;
const int  	INFi 	=  	0x7f7f7f7f;
const ll 	MOD		=  	1e+9+7;
const ll 	N 		= 	2*1e6;

// <------------- Declare Variables Here ------------> //

ll T=1;
ll n,x,y,m;
string s,t;
vll a;

// <------------- Implement Functions Here ----------> //

// <------------- Start of main() -------------------> //

void MAIN() {
	cin>>n;
	vll sum;
	vll diff;
	for(ll i=1;i<=n;i++) {
		cin>>x>>y;
		sum.pb(x+y);
		diff.pb(x-y);
	}

	sort(all(sum));
	sort(all(diff));

	cout<<max(sum[n-1] - sum[0], diff[n-1] - diff[0]);
}
int main() {
	fastio;randomINT;
	//cin>>T;
	while(T--) {
		MAIN();
	}
	return 0;
}



Measured memory_bytes: 6732
#include<iostream>

using namespace std;

int main(){

    int n;

    cin >> n;

    if(n == 111){
        cout << 999 << endl;
    }else if(n == 119){
        cout << 991 << endl;
    }else if(n == 191){
        cout << 919 << endl;
    }else if(n == 199){
        cout << 911 << endl;
    }else if(n == 911){
        cout << 199 << endl;
    }else if(n == 919){
        cout << 191 << endl;
    }else if(n == 991){
        cout << 119 << endl;
    }else{
        cout << 111 << endl;
    }

    return 0;
}

Measured memory_bytes: 256
def bubble_sort(A):
    cnt = 0
    for i in range(0, len(A) - 1):
        for j in range(len(A) - 1, i, -1):
            if A[j][1] < A[j - 1][1]:
                A[j - 1], A[j] = A[j], A[j - 1]
                cnt += 1


def selection_sort(A):
    for i in range(0, len(A)):
        min = i
        for j in range(i + 1, len(A)):
            if A[min][1] > A[j][1]:
                min = j
        A[i], A[min] = A[min], A[i]


def isStable(before, after):
    for i in range(0, len((before))):
        for j in range(i + 1, len(before)):
            for a in range(0, len(after)):
                for b in range(a + 1, len(after)):
                    if before[i][1] == before[j][1]:
                        if before[i] == after[b] and before[j] == after[a]:
                            return False
    return True


if __name__ == '__main__':
    n = int(input())
    l = input().split()
    m = l.copy()
    n = l.copy()
    bubble_sort(m)
    selection_sort(n)
    print(' '.join(m))
    print('Stable' if isStable(l, m) else 'Not stable')
    print(' '.join(n))
    print('Stable' if isStable(l, n) else 'Not stable')



Measured memory_bytes: 5608
#include <bits/stdc++.h>
#include <boost/multiprecision/cpp_int.hpp>

// increment
#define rep_n(_1, _2, _3, NAME, ...) NAME
#define rep_2(i, n) for (int(i) = 0; (i) < (int)(n); ++(i))
#define rep_3(i, initial, n) for (int(i) = (int)(initial); (i) < (int)(n); ++(i))
#define rep(...) rep_n(__VA_ARGS__, rep_3, rep_2, rep_1)(__VA_ARGS__)
// decrement
#define rep_r_n(_1, _2, _3, NAME, ...) NAME
#define rep_r_2(i, n) for (int(i) = (int)(n); (i) > 0; (i)--)
#define rep_r_3(i, initial, n) for (int(i) = (int)(initial); (i) > (int)(n); (i)--)
#define rep_r(...) rep_r_n(__VA_ARGS__, rep_r_3, rep_r_2)(__VA_ARGS__)
// define type definition
using namespace std;
typedef long long ll;
using mpint = boost::multiprecision::cpp_int; // 多倍長整数（任意精度）
typedef pair<int, int> P;

// define construct variable
const double EPS = numeric_limits<double>::epsilon();
// 10^9 + 7
const ll MOD = ll(1e9)+7;
const ll INF = ll(1e10);
const string ALPHABET = "abcdefghijklmnopqrstuvwxyz";

// define methods
// 最大公約数
ll gcd(const ll a, const ll b) { return b ? gcd(b, a % b) : a; }
// 最小公倍数
ll lcm(const ll a, const ll b) { return a / gcd(a, b) * b; }
// char -> int
int ctoi(char c) { return (int)(c - '0'); }
// 素因数分解
vector< pair<ll, ll> > prime_factorize(ll n) {
  vector< pair<ll, ll> > p;
  for (ll i = 2; i * i <= n; i++) {
    if ((n % i) != 0) continue;
    p.push_back(make_pair(i, 0));
    while ((n % i) == 0) {
      n /= i;
      p[i].second += 1;
    }
    p.push_back(make_pair(n, 0));
  }

  if (n != 1) p.push_back(make_pair(n, 1));
  return p;
}
// 組み合わせの整合性を保つ（後ほど解析する）
ll modinv(ll a) {
	ll b = MOD, u = 1, v = 0;
	while (b) {
		ll t = a / b;
		a -= t * b;
		swap(a, b);
		u -= t * v;
		swap(u, v);
	}
	u %= MOD;
	if (u < 0) { u += MOD; }
	return u;
}
// 順列
ll permutation(const ll n, const ll m) {
	ll result = 1;
	for (ll i = n; i > n - m; i--) { result = (result * i) % MOD; }
	return result;
}

// 繰り返し n 乗法
ll repeat_square(const ll n, const ll x) {
	if (x == 0) return 1;
	ll res = repeat_square(n, x/2);
	res = res * res % MOD;
	if ((x % 2) == 1) res = res * n % MOD;
  return res;
}
// 組み合わせ
ll combination(const ll n, const ll a) {
	ll x = 1, y = 1;
  for(ll i = 0; i < a; i++){
    x = x * (n-i) % MOD;
    y = y * (i+1) % MOD;
  }
  return x * repeat_square(y, MOD-2) % MOD;
}

int main() {
	int N;
	cin >> N;
	vector<ll> A(N);
	rep(i, N) {
		cin >> A[i];
	}

	int judge = 0;
	int result = 1;
	rep(i, 1, N) {
		if(judge==0){
			if(A[i-1]<A[i]) judge=1;
			if(A[i-1]>A[i]) judge=-1;
		}
		if(judge==1&&A[i-1]>A[i]){
			judge=0;
			result++;
		}
		if(judge==-1&&A[i-1]<A[i]){
			judge=0;
			result++;
		}
	}

	cout << result << endl;
  return 0;
}


Measured memory_bytes: 1024
#define _CRT_SECURE_NO_WARNINGS
#include<bits/stdc++.h>
#define fi first
#define se second

using namespace std;

const long long MOD = (long long)1e9 + 7;
int cnt[10], tmp;
vector<int> vec;
int main()
{
	ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
	for (int i = 0; i < 6; i++) {
		cin >> tmp;
		cnt[tmp]++;
	}
	sort(cnt + 1, cnt + 5);
	if (cnt[1] == 1 && cnt[2] == 1 && cnt[3] == 2 && cnt[4] == 2)
		cout << "YES\n";
	else
		cout << "NO\n";
	//system("pause");
	return 0;
}

Measured memory_bytes: 256
def factor(n):
  l=[]
  while n%2==0:
    n=n//2
    l.append(2)
  for i in range(3,int(n**0.5)+1,2):
    while n%i==0:
      n=n//i
      l.append(i)
  if n>2:
    l.append(n)
  return l

n=int(input())
if 360%n==0:
  print(360//n)
else:
  ll=factor(n)
  mul=1
  #print(ll)
  use=360
  for i in range(len(ll)):
    if use%ll[i]==0:
      use=use//ll[i]
    else:
      mul*=ll[i]
  print((360*mul)//n)
  
  

Measured memory_bytes: 9356
#include <bits/stdc++.h>
using namespace std;
 
int main() {
	long long A,Amin,Amax,B,Bmin,Bmax,ans;
	cin >> A;	
	cin >> B;
  
  	if(A%2==0){
    	Amin=A/0.08;
    	Amax=Amin+12;
  	}else{
     	Amin=A/0.08+1;
      	Amax=Amin+11;
    }
  	Bmin=B/0.1;
  	Bmax=Bmin+9;
  
  
  	if(Amin <= Bmin && Bmin <= Amax){
     	ans=Bmin; 
    }else if(Bmin <= Amin && Amin <= Bmax){
     	ans=Amin; 
    }else{
    	ans=-1;
    }

   cout << ans << endl; 

}

Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <utility>
#include <cmath>
#include <random>
#include <vector>
#include <map>
#include <set>
#include <deque>
#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)
#define all(x) begin(x),end(x)
#define show(obj) {for(auto x:obj)cout<<x<<' ';cout<<endl;}
#define line "----------"
typedef long long ll;
typedef pair<int,int> P;
typedef pair<ll,ll> LP;
const int inf = 1001001000;
const ll INF = 1LL<<60;
const int MOD = (int)1e9 + 7;

int main(){
	string s;cin >> s;
	int cnt = 0;
	if(s == "RRR")cout << 3<< endl;
	else if(s.substr(0,2) == "RR" || s.substr(1,2) == "RR")cout << 2 << endl;
	else if(s != "SSS")cout << 1 << endl;
	else cout << 0 << endl;
	return 0;
}


Measured memory_bytes: 3596
#include <stdio.h>

int main(void)
{
	char c;
	scanf("%c", &c);
	
	if (c == 'a' || c == 'i' || c == 'u' || c == 'e' || c == 'o')
		printf("vowel\n");
	else
		printf("consonant\n");
	
	return 0;
}

Measured memory_bytes: 128
#include<stdio.h>
int main()
{
    int i=0,j,flag=1,count=0;
    char s[15];
    scanf("%s",s);
    while(s[i]!='\0')i++;
    //printf("%d",i);
    if(s[0]!='A')flag=0;
    for(j=1;j<i;j++)
    {
        if(j>=2&&j<(i-1))
        {
            if(s[j]=='C')count++;
            else if(s[j]<96)flag=0;
        }
        else if(s[j]<96)flag=0;
    }
    if(count!=1)flag=0;
    if(flag)printf("AC");
    else printf("WA");
    
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
int main()
{
	ios_base::sync_with_stdio(false); cin.tie(0);
	char s[105];
	int l,j,x=0,t;
	cin>>t;
	cin>>s;
	j=t/2;
	if(t%2!=0)
		cout<<"No"<<endl;
	else
	{
		for(int i=0;i<t/2;i++,j++)
		{
			if(s[i]!=s[j])
			{
				x=1;
				break;
			}		
		}
		if(x)
			cout<<"No"<<endl;
		else
			cout<<"Yes"<<endl;
	}
	return 0;
}

Measured memory_bytes: 3592
#include <iostream>
#include <cstdio>
#include <vector>
#include <queue>
#include <string>
#include <cmath>
#include <algorithm>

using namespace std;

#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define BIT(X, i) ((X>>i)&1)
#define REP(i, a, b) for(int i = (a); i < (b); ++i)
#define rep(i, n) for(int i = 0; i < (n); ++i)
#define all(a) (a).begin(), (a).end()
#define r_all(a) (a).rbegin(), (a).rend()
#define in(x) cin>>x
#define ina(x, n) rep(x_i,n) cin>>x[x_i]
#define outa(x, n) rep(x_i,n) cout<<x[x_i]<<" \n"[x_i==n-1]

typedef long long ll;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef pair<ll, ll> pll;
typedef vector<pll> vll;
typedef priority_queue<ll> pq;

const int MOD = 1e9+7;
const int INF = (1<<30);
const ll INFL = (1L<<62);

int n, q;
vl vals, ans;
vvl edges;

void calc(int node, int par, int val) {
  val += vals[node];
  ans[node] += val;
  if (edges[node].empty()) return;
  rep(i,edges[node].size()) {
    int next_node = edges[node][i];
    if (next_node == par) continue;
    calc(next_node, node, val);
  }
}

int main() {
  in(n); in(q);
  vals.assign(n,0);
  ans.assign(n,0);
  edges.resize(n);
  rep(i,n-1) {
    int a, b; cin >> a >> b; a--; b--;
    edges[a].pb(b);
    edges[b].pb(a);
  }
  rep(i,q) {
    int p, x; cin >> p >> x; p--;
    vals[p] += x;
  }
  calc(0, -1, 0);
  // rep(i,n) {
  //   cout << vals[i] << " \n"[i==n-1];
  // }
  rep(i,n) {
    cout << ans[i] << " \n"[i==n-1];
  }
  return 0;
}


Measured memory_bytes: 25856
from itertools import combinations
def main():
    h, w, k = list(map(int, input().split()))
    C = [list(input()) for _ in range(h)]
    Ch = []
    Cw = []
    for c in C:
        Ch.append(sum(i == '#' for i in c))
    C = [list(x) for x in zip(*C)]
    for c in C:
        Cw.append(sum(i == '#' for i in c))
    C = [list(x) for x in zip(*C)]
    tot = sum(Ch)
    ans = 0
    for i in range(h + 1):
        for j in range(w + 1):
            for ch in combinations(range(h), i):
                for cw in combinations(range(w), j):
                    ci = sum(Ch[ii] for ii in ch)
                    cj = sum(Cw[jj] for jj in cw)
                    dup = sum(C[ii][jj] == '#' for ii in ch for jj in cw)
                    if tot - (ci + cj - dup) == k:
                        ans += 1
    print(ans)



if __name__ == '__main__':
    main()


Measured memory_bytes: 9256
#include<iostream>
#include<algorithm>
#include<string>
#include<vector>
#include<cmath>
#include<stack>
#include<queue>
#include<cstdlib>
#include<cstdio>
#include<utility>
#include<list>
using namespace std;
int solve(int x, int y, int z){
	int i=0,res=0;
	while(res <= x){
		i++;
		res = y*i + z*(i+1);
	}

	return i-1;
}

int main(){
	int x,y,z; cin>>x>>y>>z;

	cout<< solve(x, y, z) <<endl;

	return 0;
}


Measured memory_bytes: 256
package main

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

const (
	initialBufSize = 1024
	maxBufSize     = 1e6
)

var (
	scanner = bufio.NewScanner(os.Stdin)
	writer  = bufio.NewWriterSize(os.Stdout, 1000000)
)

func main() {
	scanner.Split(bufio.ScanWords)
	// scanner.Buffer(make([]byte, initialBufSize), maxBufSize)
	defer writer.Flush()
	n := scanInt()
	m := make([]int, n)
	for i := 0; i < (n - 1); i++ {
		m[scanInt()-1]++
	}

	for i := 0; i < n; i++ {
		fmt.Fprintf(writer, "%v\n", m[i])
	}
}

func scanInt() int {
	i, _ := strconv.Atoi(scanString())
	return i
}

func scanInts(size int) []int {
	ints := make([]int, size)
	for i := 0; i < size; i++ {
		ints[i] = scanInt()
	}
	return ints
}

func scanFloat64() float64 {
	f, _ := strconv.ParseFloat(scanString(), 64)
	return f
}

func scanFloat64s(size int) []float64 {
	f := make([]float64, size)
	for i := 0; i < size; i++ {
		f[i] = scanFloat64()
	}
	return f
}

func scanString() string {
	scanner.Scan()
	return scanner.Text()
}

func scanStrings(size int) []string {
	s := make([]string, size)
	for i := 0; i < size; i++ {
		s[i] = scanString()
	}
	return s
}


Measured memory_bytes: 5588
#include <iostream>
#include <vector>
#include <algorithm>
#include <random>
#include <string>
#include <cmath>
#include <sstream>
#include <istream>
#include <iomanip>
#include <typeinfo>
#include <stack>

using namespace std;
typedef long long ll;
ll N;

int main(){
    //ll P , Q , R;
    //cin >> P >> Q  >> R;

    ll N , A , B;
    cin >> N >> A >> B;

    ll ans = min(N *A, B);
    cout << ans << endl;


    /*
    string v;
    cin >> v;
    sort(v.begin(), v.end());
    v.erase(unique(v.begin(), v.end()), v.end());
    if(v.length() == 2){
        cout << "Yes" << endl;
    }else{
        cout << "No" << endl;
    }
    */
}

Measured memory_bytes: 256
import sys
from collections import deque
import copy
import math
def get_read_func(fileobject):
    if fileobject == None :
        return raw_input
    else:
        return fileobject.readline



def main():
    if len(sys.argv) > 1:
        f = open(sys.argv[1])
    else:
        f = None
    read_func = get_read_func(f);
    A = []
    input_raw = read_func().strip().split()
    N = long(input_raw[0])
    input_raw = read_func().strip().split()
    A.append(long(input_raw[0]))
    input_raw = read_func().strip().split()
    A.append(long(input_raw[0]))
    input_raw = read_func().strip().split()
    A.append(long(input_raw[0]))
    input_raw = read_func().strip().split()
    A.append(long(input_raw[0]))
    input_raw = read_func().strip().split()
    A.append(long(input_raw[0]))

    min_A = min(A)
    if min_A > N :
        print 5
        return
    x = (N / min_A) + (1 if N % min_A != 0 and N > min_A else 0)
##    for i in range(5):
##        x = (min_A / N) + (1 if min_A % N != 0 else 0)
##        min_A = min(min_A, x)
    print x + 4




if __name__ == '__main__':
    main()


Measured memory_bytes: 28908
def gcd(a,b):
    while b:
        a,b=b,a%b
    return a


def gcd_list(A):
    num=A[0]
    for i in A:
        num=gcd(num,i)
    return num


n,k=map(int,input().split())
A=list(map(int,input().split()))
print("POSSIBLE" if k%gcd_list(A)==0 and k<=max(A) else "IMPOSSIBLE")

Measured memory_bytes: 14480
import random

D = int(input())
C = list(map(int, input().split()))
S = list(list(map(int, input().split())) for i in range(D))

manzoku = 0
yasumi= [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]
besttbl = []
for day in range(D):
  yasumi = list(map(lambda x: x + 1, yasumi))
  zouka = 0
  for t in range(26):
    if zouka < S[day][t] + C[t] * yasumi[t]:
      zouka = S[day][t] + C[t] * yasumi[t]
      best = t
  manzoku += zouka
  yasumi[best] = 0
  besttbl.append(best + 1)
manman = manzoku
T = besttbl
for roop in range(20):
  T[random.choice(range(D))] = random.choice(range(26)) + 1
  manzoku = 0
  yasumi= [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]
  for day in range(D):
    yasumi = list(map(lambda x: x + 1, yasumi))
    yasumi[T[day] - 1] = 0
    manzoku += S[day][T[day] - 1]
    for i in range(26):
      manzoku -= C[i] * yasumi[i]
  if manman < manzoku:
    print(a)
    manman = manzoku
    besttbl = T
for best in besttbl:
  print(best)

Measured memory_bytes: 9884
#include<stdio.h>
#include<iostream>
#include<vector>
#include<math.h>
#include<queue>
#include<map>
#include<algorithm>
#include<string.h>
#include<functional>
#include<limits.h>
#include<stdlib.h>
#include<string>
#include<unordered_map>
#include<set>
using namespace std;

#define intmax INT_MAX
#define lmax LONG_MAX
#define uintmax UINT_MAX
#define ulmax ULONG_MAX
#define llmax LLONG_MAX
#define ll long long
#define rep(i,a,N) for((i)=(a);(i)<(N);(i)++)
#define rrp(i,N,a) for((i)=(N)-1;(i)>=(a);(i)--)
#define llfor ll i,j,k
#define sc(a) cin>>a
#define pr(a) cout<<a<<endl
#define pY puts("YES")
#define pN puts("NO")
#define py puts("Yes")
#define pn puts("No")
#define pnn printf("\n")
#define sort(a) sort(a.begin(),a.end())
#define push(a,b) (a).push_back(b)
#define llvec vector<vector<ll>>
#define charvec vector<vector<char>>
#define sizeoof(a,b) (a,vector<ll>(b))
#define llpvec vector<pair<ll,ll>>
/*繰り上げ除算*/ll cei(ll x,ll y){ll ans=x/y;if(x%y!=0)ans++;return ans;}
/*最大公約数*/ll gcd(ll x,ll y){return y?gcd(y,x%y):x;}
/*最小公倍数*/ll lcm(ll x,ll y){return x/gcd(x,y)*y;}
/*n乗*/ll llpow(ll x,ll n){ll i,ans=1;rep(i,0,n)ans*=x;return ans;}
/*階乗*/ll fact(ll x){ll i,ans=1;rep(i,0,x)ans*=(x-i);return ans;}
/*nCr*/ll ncr(ll n,ll r){return fact(n)/fact(r)/fact(n-r);}
/*nPr*/ll npr(ll n,ll r){return fact(n)/fact(n-r);}
/*primejudge*/bool prime(ll a){if(a<=1)return false;ll i;for(i=2;i*i<=a;i++){if(a%i==0)return false;}return true;}
llfor;///////////////////////////////////////////////////////////
int main(){
 ll h,w,k;
 sc(h);sc(w);sc(k);
 char c[h+10][w+10];
 rep(i,0,h)sc(c[i]);
 ll bita=0,bitb=0;
 ll ans=0;ll cnt;
 for(bita=0;bita<(1<<h);bita++){
  for(bitb=0;bitb<(1<<w);bitb++){//塗りつぶす行と列を選ぶ
   cnt=0;
   for(i=0;i<h;i++){
    for(j=0;j<w;j++){
     if(bita&(1<<i)||bitb&(1<<j))continue;
     if(c[i][j]=='#')cnt++;
    }
   }
   //cout<<bita<<" "<<bitb<<" "<<cnt<<endl;
   if(cnt==k)ans++;
  }
 }
 pr(ans);
return 0;}

Measured memory_bytes: 3628
#include <stdio.h>

int main()
{
	int r, g, b;
	scanf("%d", &r);
	scanf("%d", &g);
	scanf("%d", &b);

	if ((100 * r + 10 * g + b) % 4 == 0) printf("YES\n");

	else printf("NO\n");
    return 0;
}

Measured memory_bytes: 128
#include <iostream>
using namespace std;
int main() {
    int a, b, x = 1;
    cin>>a>>b;
    if(a==b){
        cout<<"Draw";
    }
    if((a>b || a==x) && (b!=x)  )
        cout<<"Alice";
    if((b>a || b==x) && (a!=x))
        cout<<"Bob";
}



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

const int nax =305;
double dp[nax][nax][nax],ex[nax][nax][nax];

int main(){
	int n;
	cin>>n;
	int cnt[4]={0};
	for(int i=0;i<n;i++){
		int temp;
		cin>>temp;
		cnt[temp]++;
	}
	dp[cnt[1]][cnt[2]][cnt[3]]=1;
	for(int c=n;c>=0;c--){
		for(int b=n;b>=0;b--){
			for(int a=n;a>=0;a--){
				if(a==0 && b==0 && c==0)continue;
				if((a+b+c)>n)continue;
				double waste=(double)(n-(a+b+c))/n;
				double ev=waste/(1-waste) + 1;
				ex[a][b][c]+=ev*dp[a][b][c];
				if(a!=0){
					double p=(double)a/(double)(a+b+c);
					dp[a-1][b][c]+=dp[a][b][c]*p;
					ex[a-1][b][c]+=ex[a][b][c]*p;
				}
				if(b!=0){
					double p=(double)b/(double)(a+b+c);
					dp[a+1][b-1][c]+=dp[a][b][c]*p;
					ex[a+1][b-1][c]+=ex[a][b][c]*p;
				}
				if(c!=0){
					double p=(double)c/(double)(a+b+c);
					dp[a][b+1][c-1]+=dp[a][b][c]*p;
					ex[a][b+1][c-1]+=ex[a][b][c]*p;
				}
			}
		}
	}
	cout<<fixed<<setprecision(15)<<ex[0][0][0]<<endl;
	return 0;
}

Measured memory_bytes: 438528
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <queue>
#include <set>
#include <map>
#include <cmath>
using namespace std;
typedef long long i64;
typedef long double ld;
typedef pair<i64,i64> P;
#define rep(i,s,e) for(int i = (s);i <= (e);i++)

int x;
int y;

#include <vector>
using namespace std;


struct UnionFind
{
	vector<int> par_;
	vector<int> rank_;

	void init(int size)
	{
		par_.resize(size, 0);
		rank_.resize(size, 0);
		for (int i = 0; i < size; i++)
		{
			par_[i] = i;
			rank_[i] = 0;
		}
	}
	int root(int x)
	{
		return par_[x] == x ? x : par_[x] = root(par_[x]);
	}

	bool unite(int x, int y)
	{
		x = root(x);
		y = root(y);
		if (x == y)
			return true;

		if (rank_[x] < rank_[y])
		{
			par_[x] = y;
		}
		else
		{
			par_[y] = x;
			if (rank_[x] == rank_[y])
				rank_[x]++;
		}
		return false;
	}
	bool same(int x, int y)
	{
		return root(x) == root(y);
	}
};



int main()
{
    UnionFind uf;
    uf.init(13);
    uf.unite(1,3);
    uf.unite(1,5);
    uf.unite(1,7);
    uf.unite(1,8);
    uf.unite(1,10);
    uf.unite(1,12);
    uf.unite(4,6);
    uf.unite(4,9);
    uf.unite(4,11);
    cin >> x >> y;
    if(uf.same(x,y))
    {
        cout << "Yes" << endl;
    }
    else
    {
        cout << "No" << endl;
    }
}

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

long long int memo[111][11][1111];

long long int solve(int p, int n, int s){
  
  if(n == 1 && s >= p && s < 101) return memo[p][n][s] = 1;
  if(n == 1 || n*100 < s) memo[p][n][s] = 0;
  if(~memo[p][n][s]) return memo[p][n][s];
  
  long long int ans = 0;
  for(int i=p;i<101;i++) if(s-i >= 0) ans += solve(i+1, n-1, s-i);
  
  return memo[p][n][s] = ans;
}

int main(){

  memset(memo, -1, sizeof(memo));

  int n, s;
  while(cin >> n >> s, n+s) cout << solve(0, n, s) << endl;
  
}

Measured memory_bytes: 11764
a, b = map(int, input().split())
w = 100
grid = []
grid.append('.'*w)
a -= 1
while b > 1:
    x = min(w//2, b-1)
    b -= x
    grid.append('#.'*x + '.'*(w-x*2))
    grid.append('.'*w)
grid.append('#'*w)
b -= 1
while a > 0:
    x = min(w//2, a)
    a -= x
    grid.append('#.'*x + '#'*(w-x*2))
    grid.append('#'*w)
print(len(grid), w)
for row in grid:
    print(row)

Measured memory_bytes: 3064
import sys
from collections import *
import heapq
import math
from math import gcd
import bisect
import copy
from itertools import permutations,accumulate,combinations,product
def input():
    return sys.stdin.readline()[:-1]
def ruiseki(lst):
    return [0]+list(accumulate(lst))
mod=pow(10,9)+7
al=[chr(ord('a') + i) for i in range(26)]
direction=[[1,0],[0,1],[-1,0],[0,-1]]

n=input()
for i in range(len(n)):
    if n[i]=="7":
        print("Yes")
        break
else:
    print("No")

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

#define FOR(i, l, r) for(size_t i = (l); i < (r); i = i + 1)
#define REP(i, n) FOR(i, 0, n)
using ll = long long;

int main() {
    int N;
    cin >> N;
    int one = N % 10;
    if(one == 2 || one == 4 || one == 5 || one == 7 || one == 9) {
        cout << "hon" << endl;
    }
    else if(one == 3) {
        cout << "bon" << endl;
    }
    else {
        cout << "pon" << endl;
    }
    return 0;
}


Measured memory_bytes: 3636
#include<bits/stdc++.h>
using namespace std;
#define fi first
#define se second
#define pb push_back
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
#define srep(i,s,t) for (int i = s; i < t; ++i)
#define rng(a) a.begin(),a.end()
#define rrng(a) a.rbegin(),a.rend()
#define uni(x) x.erase(unique(rng(x)),x.end())
#define PQ(T) priority_queue<T,v(T),greater<T> >
#define dup(x,y) (((x)+(y)-1)/(y))
#define v(T) vector<T>
#define vv(T) v(v(T))
using ll = int64_t;
using ull = uint64_t;
using uint = uint32_t;
using pii = pair<int,int>;
using pll = pair<ll,ll>;
using pil = pair<int,ll>;
using vi = vector<int>;
using vvi = vector<vi>;
using vl = vector<ll>;
template<typename T>inline istream& operator>>(istream&i,v(T)&v)
{rep(j,v.size())i>>v[j];return i;}
template<typename T>string join(const v(T)&v)
{stringstream s;rep(i,v.size())s<<' '<<v[i];return s.str().substr(1);}
template<typename T>inline ostream& operator<<(ostream&o,const v(T)&v)
{if(v.size())o<<join(v);return o;}
template<typename T1,typename T2>inline istream& operator>>(istream&i,pair<T1,T2>&v)
{return i>>v.fi>>v.se;}
template<typename T1,typename T2>inline ostream& operator<<(ostream&o,const pair<T1,T2>&v)
{return o<<v.fi<<","<<v.se;}
const double eps = 1e-6;
const ll LINF = 100200300400500600ll;
const int INF = 1001001001;
//--------------------------------------------------------
#define fastio cin.tie(nullptr); std::ios::sync_with_stdio(false);
#define myio ifstream iofi; if(argc>1){iofi.open(argv[1]); std::cin.rdbuf(iofi.rdbuf());}
#define myloopset int loop = 1; if(argc>2) loop =stoi(argv[2]); rep(i,loop)
//--------------------------------------------------------------
template <class T> T chmin(T &a,T b){if(a>b){a=b; return 1;}else return 0;}
template <class T> T chmax(T &a,T b){if(a<b){a=b; return 1;}else return 0;}
const int dx[4] = {0,1,0,-1};
const int dy[4] = {-1,0,1,0};
const int mod = 1000000007;

void Main(){
  ll n;
  ll a,b;
  cin>>n>>a>>b;
  ll ans = (n/(a+b))*a + min(n-(a+b)*(n/(a+b)),a);
  cout<<ans<<endl;
} signed main(int argc,char** argv)
{fastio; myio; myloopset Main();}


Measured memory_bytes: 256
import java.util.*;
public class Main{
	public static void main(String[] args){
		Scanner scan = new Scanner(System.in);
		String a = scan.next();
		String b = scan.next();
		String[] x = a.split("",0);
		String[] y = b.split("",0);
		if(x.length>y.length){System.out.println("GREATER");}
		else if(y.length>x.length){System.out.println("LESS");}
		else if(x.length==y.length){
			for(int i=0;i<x.length; i++){
				int n = Integer.parseInt(x[i]);
				int m = Integer.parseInt(y[i]);
				if(n>m){System.out.println("GREATER"); break;}
				else if(m>n){System.out.println("LESS"); break;}
				else if(m==n){
					if(i==x.length-1){System.out.println("EQUAL");}
					continue;}

			}
		}
 	}
}

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

int gcd(int x,int y,int& step){
	int n = 0;
	if( x < y ) swap( x , y );

	do{
		x = x % y;
		swap( x , y );
		n++;
	}while( y != 0 );
	step = n;
	return x;
}

int main(){
	int a,b,n;

	while( cin >> a >> b , a && b ){
		int ans = gcd(a,b,n);
		cout << ans << " " << n << endl;
	}
}

Measured memory_bytes: 0
import java.util.*;
import java.io.*;
public class Main {
	public static void main(String[] args){
	  Scanner sc = new Scanner(System.in);
      String str = sc.nextLine();
      str = str.replaceAll("eraser", " ");
      str = str.replaceAll("erase", " ");
      str = str.replaceAll("dreamer", " ");
      str = str.replaceAll("dream", " ");
      int strNum = str.split(" ").length;
      if(strNum>0){
        System.out.println("NO");
      } else {
        System.out.println("YES");
      } 
	}
}

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

#define int long long
#define rep(i, l, r) for (int i = (int)(l); i < (int)(r); i++)
#define all(x) (x).begin(), (x).end()
#define sz(x) ((int)x.size())
template <class T> bool chmax(T &a, T b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T> bool chmin(T &a, T b) {
  if (a > b) {
    a = b;
    return 1;
  }
  return 0;
}

template <class T> using V = vector<T>;
using P = pair<int, int>;

/*
 *  *  */

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

  V<int> a(n);
  int sum = 0;
  rep(i, 0, n){
    cin >> a[i];
    sum += a[i];
  }

  int cnt = 0;
  rep(i, 0, n){
    if(a[i] * 4 * m < sum) continue;
    cnt++;
  }

  if(cnt >= m) cout << "Yes" << endl;
  else cout << "No" << endl;

  return 0;
}





Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <string>
#include <cstring>
#include <deque>
#include <list>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <complex>
#include <cmath>
#include <limits>
#include <climits>
#include <ctime>
#include <cassert>
using namespace std;

#define rep(i,a,n) for(int (i)=(a); (i)<(n); (i)++)
#define repq(i,a,n) for(int (i)=(a); (i)<=(n); (i)++)
#define repr(i,a,n) for(int (i)=(a); (i)>=(n); (i)--)
#define all(v) begin(v), end(v)
#define pb(a) push_back(a)
#define fr first
#define sc second
#define INF 2000000000
#define int long long int

#define X real()
#define Y imag()
#define EPS (1e-10)
#define EQ(a,b) (abs((a) - (b)) < EPS)
#define EQV(a,b) ( EQ((a).X, (b).X) && EQ((a).Y, (b).Y) )
#define LE(n, m) ((n) < (m) + EPS)
#define LEQ(n, m) ((n) <= (m) + EPS)
#define GE(n, m) ((n) + EPS > (m))
#define GEQ(n, m) ((n) + EPS >= (m))

typedef vector<int> VI;
typedef vector<VI> MAT;
typedef pair<int, int> pii;
typedef long long ll;

typedef complex<double> P;
typedef pair<P, P> L;
typedef pair<P, double> C;

int dy[]={0, 0, 1, -1};
int dx[]={1, -1, 0, 0};
int const MOD = 1000000007;

namespace std {
    bool operator<(const P& a, const P& b) {
        return a.X != b.X ? a.X < b.X : a.Y < b.Y;
    }
}

// ?§?????????¨????????¨???????????????????¨???????????§???????
template <typename T>
struct Edge {
    int from, to;
    T cost;
    Edge(int s, T d) : to(s), cost(d) {}
    Edge(int f, int s, T d) : from(f), to(s), cost(d) {}

    bool operator<(const Edge &e) const {
        return cost < e.cost;
    }
    bool operator>(const Edge &e) const {
        return cost > e.cost;
    }
};
#define Graph(type) vector< vector< Edge<type> > >

template <typename T>
vector< vector<T> > warshall(vector< vector< Edge<T> > > &G) {
    int V = G.size();
    vector< vector<T> > d(V);
    rep(i,0,V) rep(j,0,V) {
        if(i == j) d[i].push_back(0);
        else d[i].push_back(numeric_limits<T>::max());
    }

    rep(i,0,V) rep(j,0,G[i].size()) {
        Edge<T> e = G[i][j];
        d[i][e.to] = e.cost;
    }

    rep(k,0,V) rep(i,0,V) rep(j,0,V)
        if(d[i][k] != numeric_limits<T>::max() && d[k][j] != numeric_limits<T>::max())
            d[i][j] = min(d[i][j], d[i][k] + d[k][j]);
    return d;
}

signed main() {
    int v, e; cin >> v >> e;
    Graph(int) G(v);

    int s, t;
    rep(i,0,e) {
        cin >> s >> t;
        G[s].pb(Edge<int>(t, 1));
    }

    vector< vector<int> > w = warshall(G);
    int ma = numeric_limits<int>::max();
    bool ans = false;
    rep(i,0,v) rep(j,0,v) {
        if(i == j) continue;
        if(w[i][j] != ma && w[j][i] != ma) ans = true;
    }
    cout << (ans ? 1 : 0) << endl;
    return 0;
}

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

typedef long long ll;

const int pMax = 10000;
ll prime[pMax];
bool is_prime[200010];

void sieve(ll n) {
	int p = 0;
	for (ll i = 0; i <= n; i++) is_prime[i] = true;
	is_prime[0] = is_prime[1] = false;
	for (ll i = 2; i <= n; i++) {
		if (is_prime[i]) {
			prime[p++] = i;
			if (p == pMax) return;
			for (ll j = 2 * i; j <= n; j += i) is_prime[j] = false;
		}
	}
}
int main() {
	sieve(200000);
	int n;
	while (cin >> n && n) {
		ll s = 0;
		for (int i = 0; i < n; i++) {
			s += prime[i];
		}
		cout << s << endl;
	}
}


Measured memory_bytes: 3340
#include <iostream>
#include <string>
#include <sstream>
#include <vector>
#include <tuple>
#include <algorithm>
using namespace std;
#define REP(n) for(int i=0;i<n;i++)

int flowers[101] = { 0 };

int type_cnt[100001] = { 0 };
int main() {
	long long N;
	cin >> N;
	vector<int> p(N);
	int max = 0;
	int ans = 0;
	REP(N) {
		cin >> p[i];
		if (p[i] > max) {
			max = p[i];
		}
		ans += p[i];
	}
	ans -= max / 2;


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

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

using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;

typedef int _loop_int;
#define REP(i,n) for(_loop_int i=0;i<(_loop_int)(n);++i)
#define FOR(i,a,b) for(_loop_int i=(_loop_int)(a);i<(_loop_int)(b);++i)
#define FORR(i,a,b) for(_loop_int i=(_loop_int)(b)-1;i>=(_loop_int)(a);--i)

#define DEBUG(x) cout<<#x<<": "<<x<<endl
#define DEBUG_VEC(v) cout<<#v<<":";REP(i,v.size())cout<<" "<<v[i];cout<<endl
#define ALL(a) (a).begin(),(a).end()

#define CHMIN(a,b) a=min((a),(b))
#define CHMAX(a,b) a=max((a),(b))

// mod
const ll MOD = 1000000007ll;
#define FIX(a) ((a)%MOD+MOD)%MOD

// floating
typedef double Real;
const Real EPS = 1e-11;
#define EQ0(x) (abs(x)<EPS)
#define EQ(a,b) (abs(a-b)<EPS)
typedef complex<Real> P;

int n,m,s,t;
vector<pii> ga[125252], gb[125252];
ll dista[125252], distb[125252];

int main(){
  scanf("%d%d%d%d",&n,&m,&s,&t);
  --s;--t;
  REP(i,m){
    int u,v,a,b;
    scanf("%d%d%d%d",&u,&v,&a,&b);
    --u;--v;
    ga[u].push_back(pii(v,a));
    ga[v].push_back(pii(u,a));
    gb[u].push_back(pii(v,b));
    gb[v].push_back(pii(u,b));
  }
  REP(i,n)dista[i] = distb[i] = 1ll<<60;
  priority_queue<pll> Q;
  dista[s] = 0ll;
  Q.push(pll(-0ll, s));
  while(!Q.empty()){
    pll P = Q.top(); Q.pop();
    int p = P.second;
    if(dista[p] != -P.first)continue;
    for(pii PP : ga[p]){
      int to = PP.first;
      int cost = PP.second;
      if(dista[to] > dista[p] + cost){
        dista[to] = dista[p] + cost;
        Q.push(pll(-dista[to],to));
      }
    }
  }
  distb[t] = 0ll;
  Q.push(pll(-0ll, t));
  while(!Q.empty()){
    pll P = Q.top(); Q.pop();
    int p = P.second;
    if(distb[p] != -P.first)continue;
    for(pii PP : gb[p]){
      int to = PP.first;
      int cost = PP.second;
      if(distb[to] > distb[p] + cost){
        distb[to] = distb[p] + cost;
        Q.push(pll(-distb[to],to));
      }
    }
  }
  const ll MAX = 1000000000000000ll;
  vector<ll> answers;
  ll cur = 1ll<<60;
  FORR(i,0,n){
    CHMIN(cur, dista[i] + distb[i]);
    answers.push_back(MAX-cur);
  }
  reverse(ALL(answers));
  for(ll ans : answers){
    printf("%lld\n",ans);
  }
  return 0;
}


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

int main () {
    int N;
    cin >> N;
    vector<float> A(N);
    for (int i = 0 ; i < N ; i++) {
        cin >> A.at(i);
    }
     float sum;
    for (int i = 0 ; i < N ; i++) {
        A.at(i) = 1 / A.at(i);
        sum += A.at(i);
    }
    cout << 1.0 / sum << endl;

}

Measured memory_bytes: 256
typedef int ll;

#include <bits/stdc++.h>
using namespace std;
// 感謝
// http://www.iot-kyoto.com/satoh/2016/01/29/tangent-003/
int calcCircleOf2Point(int x1, int y1, int x2, int y2, int x3, int y3, long double *cx, long double *cy, long double *r)
{
	long double 	ox, oy, a, b, c, d ;
	long double 	r1, r2, r3 ;
	int		stat ;

	a = x2 - x1 ;
	b = y2 - y1 ;
	c = x3 - x1 ;
	d = y3 - y1 ;

	stat = -1 ;

	if  ((a && d) || (b && c)) {
		ox = x1 + (d * (a * a + b * b) - b * (c * c + d * d)) / (a * d - b * c) / 2 ;
		if  (b) {
			oy = (a * (x1 + x2 - ox - ox) + b * (y1 + y2)) / b / 2 ;
		} else {
			oy = (c * (x1 + x3 - ox - ox) + d * (y1 + y3)) / d / 2 ;
		}
		r1   = sqrt((ox - x1) * (ox - x1) + (oy - y1) * (oy - y1)) ;
		r2   = sqrt((ox - x2) * (ox - x2) + (oy - y2) * (oy - y2)) ;
		r3   = sqrt((ox - x3) * (ox - x3) + (oy - y3) * (oy - y3)) ;
		*cx = ox ;
		*cy = oy ;
		*r  = (r1 + r2 + r3) / 3 ;
		stat = 0 ;
	}

	return stat ;
}
int main() {
    ll n;
    std::cin >> n;
    
    vector<pair<long double,long double>> xy(n);
    
    for (int i = 0; i < n; i++) {
        std::cin >> xy[i].first>>xy[i].second;
    }
    
    long double ans = 1e15;
    
    for (int i = 0; i < n; i++) {
        for (int j = i+1; j < n; j++) {
            bool ok = true;
        
            long double cx = (xy[i].first+xy[j].first)/2.0;
            long double cy = (xy[i].second+xy[j].second)/2.0;
            long double cr = sqrt((xy[i].first-xy[j].first)*(xy[i].first-xy[j].first)+(xy[i].second-xy[j].second)*(xy[i].second-xy[j].second))/2.0;
            for (int t = 0; t < n; t++) {
                if( (xy[t].first-cx)*(xy[t].first-cx)+(xy[t].second-cy)*(xy[t].second-cy) > cr*cr +0.00000001){
                    ok=false;
                    break;
                }
            }
            if(ok){
                ans = min(ans,cr);
            }
        }
    }
    
    for (int i = 0; i < n; i++) {
        for (int j = i+1; j < n; j++) {
            for (int k = j+1; k < n; k++) {
                long double cx,cy,cr;
                if(calcCircleOf2Point(xy[i].first,xy[i].second,xy[j].first,xy[j].second,xy[k].first,xy[k].second,&cx,&cy,&cr)!=-1){
                    bool ok = true;
                    // std::cout << 1 << std::endl;
                    for (int t = 0; t < n; t++) {
                        
                        // std::cout <<setprecision(20) << (xy[t].first-cx)*(xy[t].first-cx)+(xy[t].second-cy)*(xy[t].second-cy) <<" "<<cr*cr<< std::endl;
                        if( (xy[t].first-cx)*(xy[t].first-cx)+(xy[t].second-cy)*(xy[t].second-cy) > cr*cr+0.00000001 ){
                            ok=false;
                            break;
                        }
                    }
                    if(ok){
                        ans = min(ans,cr);
                    }
                }
            }
        }
    }
    std::cout <<setprecision(20)<< ans << std::endl;
}


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

using namespace std;

inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}
template<class T> inline T sqr(T x) {return x*x;}

typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<string> vs;
typedef pair<int, int> pii;
typedef long long ll;

#define all(a)  (a).begin(),(a).end()
#define rall(a) (a).rbegin(), (a).rend()
#define pb push_back
#define mp make_pair
#define each(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define exist(s,e) ((s).find(e)!=(s).end())
#define range(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n)  range(i,0,n)
#define clr(a,b) memset((a), (b) ,sizeof(a))
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

const double eps = 1e-10;
const double pi  = acos(-1.0);
const ll INF =1LL << 62;
const int inf =1 << 29;

const ll mod=1000000007;
ll dp[51][2];

int main(void){
	string a,b,c;
	while(cin >> a){
		if(a=="0")
			break;
		cin >> b  >> c;
		rep(i,50)rep(j,2) dp[i][j]=0;
		int n=a.size();
		dp[n][0]=1LL;
		for(int i=n-1;i>=0;--i)rep(j,2){
			ll cur[2]={0,0};
			int start=(i==0);
			if(a[i]=='?'&&b[i]=='?'){
				range(aa,start,10)range(bb,start,10){
					int sum=j+aa+bb;
					if(c[i]=='?'||(sum%10==(c[i]-'0')))
						cur[sum>=10]++;
				}
			}else if(a[i]=='?'){
				range(aa,start,10){
					int bb=b[i]-'0';
					int sum=j+aa+bb;
					if(c[i]=='?'||(sum%10==(c[i]-'0')))
						cur[sum>=10]++;
				}
			}else if(b[i]=='?'){
				range(bb,start,10){
					int aa=a[i]-'0';
					int sum=j+aa+bb;
					if(c[i]=='?'||(sum%10==(c[i]-'0')))
						cur[sum>=10]++;
				}
			}else{
				int aa=a[i]-'0';
				int bb=b[i]-'0';
				int sum=j+aa+bb;
				if(c[i]=='?'||(sum%10==(c[i]-'0')))
					cur[sum>=10]++;
			}

			rep(k,2) dp[i][k]=(dp[i][k]+dp[i+1][j]*cur[k])%mod;
		}
		cout << dp[0][0] << endl;
	}
	return 0;
}

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

const int mod = 1e9;
int main()
{
	int N;
	scanf("%d",&N);
	
	int Max1 = mod*-1,Min1 = mod;
	int Max0 = mod*-1,Min0 = mod;
	for(int i = 1;i <= N;++i)
	{
		int x,y;
		scanf("%d%d",&x,&y);
		
		Max1 = max(Max1,x+y);
		Min1 = min(Min1,x+y);
		Max0 = max(Max0,x-y);
		Min0 = min(Min0,x-y); 
	}
	int ans = max((Max1 - Min1) , (Max0 - Min0));
	return printf("%d",ans),0;
} 

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


def main():
    h, w = map(int, input().split())
    grids = [list(input()) for _ in range(h)]
    up = [[1 for __ in range(w)] for _ in range(h)]
    down = [[1 for __ in range(w)] for _ in range(h)]
    left = [[1 for __ in range(w)] for _ in range(h)]
    right = [[1 for __ in range(w)] for _ in range(h)]
    ans = 0

    for i in range(h - 1, -1, -1):
        for j in range(w):
            if (grids[i][j] == '.') and (i < h - 1):
                up[i][j] = up[i + 1][j] + 1
            elif grids[i][j] == '#':
                up[i][j] = 0

    for i in range(h):
        for j in range(w):
            if (grids[i][j] == '.') and (i > 0):
                down[i][j] = down[i - 1][j] + 1
            elif grids[i][j] == '#':
                down[i][j] = 0

    for i in range(h):
        for j in range(w - 1, -1, -1):
            if (grids[i][j] == '.') and (j < w - 1):
                left[i][j] = left[i][j + 1] + 1
            elif grids[i][j] == '#':
                left[i][j] = 0

    for i in range(h):
        for j in range(w):
            if (grids[i][j] == '.') and (j > 0):
                right[i][j] = right[i][j - 1] + 1
            elif grids[i][j] == '#':
                right[i][j] = 0

    for i in range(h):
        for j in range(w):
            ans = max(ans, (up[i][j] + down[i][j] - 1) + (left[i][j] + right[i][j] - 1) - 1)

    print(ans)


if __name__ == '__main__':
    main()


Measured memory_bytes: 312712
number = input().split(" ")
N = int(number[0])
K = int(number[1])
 
list = []
numbers = input().split(" ")
for i in numbers:
    list.append(int(i))
list.sort()
 
a = 0
 
for i in range(K):
	a += int(list[i])
print(a)

Measured memory_bytes: 9140
//#pragma GCC optimize("Ofast")
#include <set>
#include <map>
#include <cmath>
#include <stack>
#include <queue>
#include <vector>
#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <algorithm>
#define endl '\n'
#define fast ios::sync_with_stdio(0),cin.tie(0),cout.tie(0)
#define zy 2333333
#define bql 2147483647
using namespace std;
int n,d;
int main()
{
	fast;
	cin>>n>>d;
	if (n%(d+d+1)==0)
	   cout<<n/(d+d+1)<<endl;
  else
	   cout<<n/(d+d+1)+1<<endl;
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()
#define rep(i,n) for (int i=0;i<(int)(n);i++)
#define codefor int test;scanf("%d",&test);while(test--)
#define yn(ans) cout<<(ans?"Yes":"No")<<endl
#define YN(ans) cout<<(ans?"YES":"NO")<<endl
#define umap unordered_map
#define uset unordered_set
using namespace std;
using ll = long long;
//入力系
void scan(int& a){scanf("%d",&a);}
void scan(long long& a){scanf("%lld",&a);}
template<class T> void scan(T& a){cin>>a;}
template<class T> void scan(vector<T>& vec){for(auto&& it:vec)scan(it);}
void in(){}
template <class Head, class... Tail> void in(Head& head, Tail&... tail){scan(head);in(tail...);}
//出力系
void print(const int& a){printf("%d",a);}
void print(const long long& a){printf("%lld",a);}
void print(const double& a){printf("%.15lf",a);}
template<class T> void print(const T& a){cout<<a;}
template<class T> void print(const vector<T>& vec){if(vec.empty())return;print(vec[0]);for(auto it=vec.begin();++it!= vec.end();){putchar(' ');print(*it);}}
void out(){putchar('\n');}
template<class T> void out(const T& t){print(t);putchar('\n');}
template <class Head, class... Tail> void out(const Head& head,const Tail&... tail){print(head);putchar(' ');out(tail...);}
//デバッグ系
template<class T> void dprint(const T& a){cerr<<a;}
template<class T> void dprint(const vector<T>& vec){if(vec.empty())return;cerr<<vec[0];for(auto it=vec.begin();++it!= vec.end();){cerr<<" "<<*it;}}
void debug(){cerr<<endl;}
template<class T> void debug(const T& t){dprint(t);cerr<<endl;}
template <class Head, class... Tail> void debug(const Head& head, const Tail&... tail){dprint(head);cerr<<" ";debug(tail...);}

int main(){
    int n;
    in(n);
    int x,ans=0;
    rep(i,n){
        in(x);
        if(i%2==0&&x%2==1)ans++;
    }
    out(ans);
}


Measured memory_bytes: 3760
#include <bits/stdc++.h>
#define pb push_back
#define pll pair <ll, ll>
#define mp make_pair
#define pyshnapyshnakaa ios_base :: sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define x first
#define y second
#pragma GCC optimize("O3")
#pragma GCC optimize("Ofast")
// #pragma GCC optimize("avx2")
// #pragma GCC optimize("unroll-loops")
#pragma GCC target ("sse4.2")
#define plll pair <pair <ll, ll>, ll>
#define pllll pair <pair <ll, ll>, pair <ll, ll> >
#define psl pair <string, ll>
#define all(a) a.begin(), a.end()

typedef long long ll;

typedef long double ld;

using namespace std;

const ll maxn = 1e6 + 100;

ll n, m, k, t;

int main() {
    pyshnapyshnakaa;
    ll q, w, e, a, b, c;
    cin >> n >> a >> b;
    if ((b - a) % 2 == 0) {
        cout << (b - a) / 2;
    }
    else {
        if (b < a) {
            swap(a, b);
        }
        ll ans1 = (a) + (b - a - 1) / 2;
        ll ans2 = (n - b + 1) + (b - a - 1) / 2; 
        cout << min(ans1, ans2);
    }
    return 0;
}


Measured memory_bytes: 256
n,m=map(int,input().split())
x=[]
y=[]
for i in range(m):
    a,b=map(int,input().split())
    x.append([a,b,i])
x.sort()
s=1
for i in range(m):
    c=x[i][0]
    a=6-len(str(x[i][0]))
    b=["0"]*a
    for j in range(len(str(x[i][0]))):
        b.append(str(x[i][0])[j])
    x[i][0]="".join(b)
    a=6-len(str(s))
    b=["0"]*a
    for j in range(len(str(s))):
        b.append(str(s)[j])
    x[i].append("".join(b))
    if i<m-1:
        if c==x[i+1][0]:
            s+=1
        else:
            s=1
for i in range(m):
    y.append([x[i][2],x[i][0],x[i][3]])
y.sort()
for i in range(m):
    print(y[i][1]+y[i][2])

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

using namespace std;

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

    vector<int> v(3);
    for (int i = 0; i < 3; i++) {
        cin >> v[i];
    }
    sort(v.begin(), v.end());

    cout << v[2] - v[0] << endl;

    return 0;
}


Measured memory_bytes: 256
import java.util.*;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		Stack<Integer> st = new Stack<Integer>();
		
		while(sc.hasNext()){
			int in = sc.nextInt();
			if (in == 0){
				int out = st.pop();
				System.out.println(out);
			}else{
				st.push(in);
			}
		}
		sc.close();
	}
}

Measured memory_bytes: 17200
#include<bits/stdc++.h>
#define rep(i, n) for(int (i)=0 ;i <(n); ++(i))
#define REP(i,m,n) for(int (i) = (m); (i) <= (n); ++(i))
#define yorn(f) puts((f)?"Yes":"No")
#define YORN(f) puts((f)? "YES":"NO")
typedef long long ll;
using namespace std;

int main() {
  int n, m;
  cin >> n >> m;
  vector<int> b;
  rep(i, n) {
    int k;
    cin >> k;
    vector<int> a(k);
    rep(j, k) {
      cin >> a[j];
      b.push_back(a[j]);
    }
  }

  int x = b.size();
  unordered_map<int, int> mp; 
  rep(i, x) {
    mp[b[i]]++;
  }

  int cnt = 0;
  for(auto p : mp) {
    int tmp = p.second;
    //cout << tmp << endl;
    if(tmp == n) cnt++;
  }   
  cout << cnt << endl;
  return 0;
}

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


#define rep(p,q) for(int i = p;i < q;i++)
#define ll long long

using namespace std;

const int CONS = 1e9 + 7;
const ll INF = 1e16 + 7;

//62C
int main(void) {
	ll h, w;
	cin >> h >> w;
	ll ans;
	if (h % 3 == 0) ans = 0;
	else ans = w;
	if (w % 3 == 0) ans = 0;
	else ans = min(ans, h);
	if (ans == 0) {
		cout << 0 << endl;
	}
	else {
		rep(1, h) {
			ll coOrd = INF;

			ll sMax = i * w, sMin = i * w;

			if (w % 2 == 0) {
				sMax = max(sMax, (h - i) * (w / 2));
				sMin = min(sMin, (h - i) * (w / 2));

			}
			else {
				sMax = max(sMax, (h - i) * ((w + 1) / 2));
				sMin = min(sMin, (h - i) * ((w - 1) / 2));

			}
			coOrd = sMax - sMin;
			ans = min(ans, coOrd);
		}
		rep(1, w) {
			ll coOrd = INF;

			ll sMax = i*h, sMin = i*h;

			if (h % 2 == 0) {
				sMax = max(sMax,(w - i) * (h / 2));
				sMin = min(sMin, (w - i) * (h / 2));
				
			}
			else {
				sMax = max(sMax,(w - i) * ((h + 1) / 2));
				sMin = min(sMin, (w - i) * ((h - 1) / 2));
				
			}
			coOrd = sMax - sMin;
			ans = min(ans, coOrd);
		}
		cout << ans << endl;
	}
}


Measured memory_bytes: 256