akhauriyash/Code-Regression huggingface dataset:
;; -*- coding:utf-8 -*-

;; Header
(defparameter *file-path* *load-pathname*)
(defun clip-to-string ()
  (with-output-to-string (out)
    (sb-ext:run-program "C:/msys64/usr/bin/cat.exe" '("/dev/clipboard") :output out)))
(defun test ()
  (with-input-from-string (*standard-input* (delete #\return (clip-to-string)))
    (main)))
(defmacro print-line (obj &optional (stream '*standard-output*))
  `(prog1 (princ ,obj ,stream) (terpri ,stream)))
(eval-when (:compile-toplevel :execute)
  (defparameter *optimize* '(optimize (speed 3) (safety 0))))


;; Hauptteil

(defstruct stop
  (duration 0 :type fixnum)
  (offset 0 :type fixnum)
  (interval 0 :type (integer 0 100)))

(deftype unum () '(integer 0 100000000))
(defun get-time (lst &optional (elapsed 0))
  (declare #.*optimize*
	   (unum elapsed))
  (if (null lst)
      elapsed
      (get-time (cdr lst)
		(let ((stop (car lst)))
		  (+ (stop-duration stop)
		     (if (<= elapsed (stop-offset stop))
			 (stop-offset stop)
			 (* (stop-interval stop)
			    (ceiling elapsed (stop-interval stop)))))))))
		
(defun main ()
  (let* ((num (- (read) 1))
	 (stops (loop for idx from 0 below num
		      collect (make-stop :duration (read)
					 :offset (read)
					 :interval (read)))))
    (loop for lst on stops do
	 (print-line (get-time lst))
       finally (print-line (get-time nil)))))

#-swank(main)


;; Für Benchmark
(defparameter *dat-path* (merge-pathnames "test.dat" *file-path*))

#+swank
(with-open-file (out *dat-path*
		     :direction :output :if-exists :supersede)
  )

(defun bench ()
  (let ((*standard-output* (make-broadcast-stream)))
    (with-open-file (*standard-input* *dat-path*)
      (time (main)))))


Measured memory_bytes: 10856
N = int(input())
c = [1]
temp = 6
while(temp <= N):
    c.append(temp)
    temp *= 6
temp = 9
while(temp <= N):
    c.append(temp)
    temp *= 9
m = len(c)

dp = [10 ** 9 + 7 for _ in range(N + 1)]
dp[0] = 0
for i in range(m):
    for j in range(1, N + 1):
        if j - c[i] >= 0:
            dp[j] = min(dp[j], dp[j - c[i]] + 1)
print(dp[N])

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

#define all(a) (a).begin(), (a).end()
#define rall(a) (a).rbegin(), (a).rend()
#define MIN(a) *min_element(all(a))
#define MAX(a) *max_element(all(a))
#define SUM(a) accumulate(all(a), 0LL)
#define REP(i, n) for(int (i)=0; (i)<(n); (i)++)
#define RREP(i, n) for(int (i)=(n)-1; (i)>=0; (i)--)
#define FOR(i, m, n) for(int (i)=(m); (i)<(n); i++)
#define FORR(i, m, n) for(int (i)=(n)-1; (i)>=(m); i--)
#define debug(x) cerr << #x << " = " << x << endl
//#define int long long

typedef long long ll;
//ll const MOD = 998244353;
ll const MOD = 1e9+7;
int const inf = 1e9;
ll const INF = 1e18;

inline void ios_(){cin.tie(0); ios::sync_with_stdio(false);}
template<typename T> int size(const T& a){return (int)a.size();}
template<typename T> T Div(T a, T b){return (a + b - 1) / b;}
template<typename T> bool chmin(T& a, const T& b){if(a > b){a = b; return true;} return false;}
template<typename T> bool chmax(T& a, const T& b){if(a < b){a = b; return true;} return false;}



signed main(){
    int n;
    cin >> n;
    vector<vector<pair<int,int>>> v(n);
    REP(i, n){
        int a;
        cin >> a;
        REP(j, a){
            int x, y;
            cin >> x >> y;
            v[i].push_back(make_pair(x-1, y));
        }
    }

    int ans = 0;

    REP(bit, (1 << n)){
        vector<int> u(n, -1);
        REP(i, n) u[i] = (bit >> i) & 1;

        bool ok = true;
        REP(i, n){
            if(!ok) break;
            if(!((bit >> i) & 1)) continue;

            for(auto p : v[i]){
                if(u[p.first] != p.second){
                    ok = false;
                    break;
                }
            }
        }
        if(ok){
            chmax(ans, __builtin_popcount(bit));
        }
    }
    cout << ans << endl;
    return 0;
}


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

int main(){
    int n;
    cin >> n;
    vector<int> dp(n + 1);
    dp[1] = 1;
    dp[0] = 1;
    for (int i = 2; i <= n; i++)
        dp[i] = dp[i - 1] + dp[i - 2];
    cout << dp[n] << endl;
}


Measured memory_bytes: 3088
W, H, N = map(int, input().split())
XYA = [tuple(map(int, input().split())) for _ in range(N)]

def isBlack(h, w):
    for x, y, a in XYA:
        if a == 1 and w < x:
            return True
        if a == 2 and w >= x:
            return True
        if a == 3 and h < y:
            return True
        if a == 4 and h >= y:
            return True
    return False

ans = H * W
for w in range(W):
    for h in range(H):
        ans -= 1 if isBlack(h, w) else 0
print(ans)


Measured memory_bytes: 9144
#include <bits/stdc++.h>
#define F(i, l, r) for(int i = (l), _end_ = (int)(r); i <= _end_; ++i)
#define f(i, r, l) for(int i = (r), _end_ = (int)(l); i >= _end_; --i)
#define Set(a, v) memset(a, v, sizeof(a))
#define file(a) freopen(a".in","r",stdin),freopen(a".out","w",stdout)
using namespace std;

bool chkmin(int &a, int b) {return b < a ? a = b, 1 : 0;}
bool chkmax(int &a, int b) {return b > a ? a = b, 1 : 0;}

inline int read() {
 int x = 0, fh = 1; char ch = getchar();
    for (; !isdigit(ch); ch = getchar() ) if (ch == '-') fh = -1;
    for (; isdigit(ch); ch = getchar() ) x = (x<<1) + (x<<3) + (ch ^ '0');
    return x * fh;
}
int n;
int a[100005];
bool cmp(int x,int y){
   return x>y;
}
int main () {
     n=read();
	 F(i,1,n)a[i]=read();
	 sort(a+1,a+n+1,cmp);
     bool ans=0;
	 F(i,1,n){
	   if(i+1>a[i+1]){
	      int j=i+1;
		  while(j<=n&&a[j]==i){
		        ans^=1;
				++j;
		  }
		  ans|=(a[i]-i)&1;
		  break;
	   }
	 }
	 if(ans)puts("First");
	 else puts("Second");
    return 0;
}

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

using namespace std;
using ll = long long;

int main()
{
    ll n;
    cin >> n;
    vector<ll> arr(n, 0);
    ll ans = 0;
    for (ll i = 1; i <= n; i++)
    {
        ll j = 1;
        ll a = i * j;
        while (a <= n)
        {
            arr[a - 1]++;
            j++;
            a = i * j;
        }
    }
    for (ll i = 0; i < n; i++)
    {
        ans += (arr[i] * (i + 1));
    }
    cout << ans << endl;
}

Measured memory_bytes: 81400
import * as fs from "fs";

const input = (fs.readFileSync("/dev/stdin", "utf8") as string).split("\n");
const n = +input[0];
const a = input[1].split(" ").map((x: string): number => +x);

let result = -Infinity;
const rsw_r = new Array<number>(n + 1);
rsw_r[n] = 0;
rsw_r[n - 1] = a[n - 1];
for (let i = n - 2; i >= 0; i--) {
	rsw_r[i] = rsw_r[i + 2] + a[i];
}

const diff_r = new Array<number>(n + 1);
diff_r[n] = 0;
for (let i = n - 1; i >= 0; i--) {
	diff_r[i] = rsw_r[i + 1] - rsw_r[i];
}

const diff_max_r = new Array<number>(n + 1);
diff_max_r[n] = 0;
diff_max_r[n - 1] = diff_r[n - 1];
for (let i = n - 2; i >= 0; i--) {
	diff_max_r[i] = Math.max(diff_max_r[i + 2], diff_r[i]);
}

/*
console.error(a);
console.error(rsw_r);
console.error(diff_r);
console.error(diff_max_r);
*/
if (n % 2 === 0) {
	// skip first
	let sum = 0;
	for (let i = 1; i < n; i += 2) {
		sum += a[i];
	}
	if (sum > result) result = sum;
	const tmp = rsw_r[0] + diff_max_r[2];
	if (tmp > result) result = tmp;

}
else {
	for (let i = 0; i < n; i += 2) {
		const tmp = rsw_r[0] + diff_r[i] + diff_max_r[i + 1];
		if (tmp > result) result = tmp;
	}
}

console.log(result);


Measured memory_bytes: 58320
#include <iostream>
#include <string>
#include <stack>
#include <queue>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <algorithm>

using namespace std;
#define rep(i, n) for (int i = 0; i < (n); i++)
#define rep1(i, s, n) for (int i = (s); i <= (n); i++)
#define rrep(i, n) for (int i = (n) - 1; i >= 0; i--)
typedef long long ll;

int main()
{
	int A, B;
	cin >> A >> B;
	if (A + B >= 10) cout << "error" << endl;
	else cout << A + B << endl;

	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <algorithm>
#include <iomanip>
#include <cassert>
using namespace std;

#define GET_ARG(a,b,c,F,...) F
#define REP3(i,s,e) for (i = s; i <= e; i++)
#define REP2(i,n) REP3 (i,0,(int)(n)-1)
#define REP(...) GET_ARG (__VA_ARGS__,REP3,REP2) (__VA_ARGS__)
#define RREP3(i,s,e) for (i = s; i >= e; i--)
#define RREP2(i,n) RREP3 (i,(int)(n)-1,0)
#define RREP(...) GET_ARG (__VA_ARGS__,RREP3,RREP2) (__VA_ARGS__)
#define DEBUG(x) cerr << #x ": " << x << endl

pair<int,int> p[500];
int a[250000];

int main(void) {
    int i, n;
    scanf("%d",&n);
    REP (i,n) {
        int x;
        scanf("%d",&x);
        x--;
        p[i].first = x;
        p[i].second = i;
    }
    sort(p,p+n);
    int l = 0;
    REP (i,n) {
        int pos = p[i].first;
        int rest = p[i].second;
        a[pos] = p[i].second+1;
        for (; rest && l < pos; l++) {
            if (a[l] == 0) {
                a[l] = p[i].second+1;
                rest--;
            }
        }
        if (rest) {
            puts("No");
            return 0;
        }
    }
    REP (i,n) {
        int pos = p[i].first;
        int rest = n - p[i].second - 1;
        for (; rest; l++) {
            if (a[l] == 0) {
                if (l < pos) {
                    puts("No");
                    return 0;
                }
                a[l] = p[i].second+1;
                rest--;
            }
        }
    }
    puts("Yes");
    REP (i,n*n) printf("%d%c",a[i]," \n"[i==n*n-1]);
    return 0;
}


Measured memory_bytes: 2176
#include <iostream>
#include <cmath>
#include <vector>
#include <map>
#include <set>
using namespace std;


struct T{
	T *l,*r;
	T(){
		l = 0;
		r = 0;
	}
};


string str;
int p;
T* dfs(T *x){
	if( str[p] == 'x'){
		p++;
		return x;
	}else{
		p++;
		x->l = new T();
		x->r = new T();
		dfs(x->l);
		p++;
		dfs(x->r);
		p++;
		return x;
	}
}

map< pair<T*,T*>, bool> chk;
bool issame(T *x,T *y){
	if( x == 0 || y == 0) return x == y;
	if( chk.count(pair<T*,T*>{x,y}) ) return chk[pair<T*,T*>{x,y}];

	return chk[pair<T*,T*>{x,y}] = 
		(issame(x->l,y->l) && issame(x->r,y->r)) ||
		(issame(x->l,y->r) && issame(x->r,y->l));
	;
}


vector<T*> getAll(T *x){
	if(x){
		vector<T*> v = getAll(x->l);
		vector<T*> w = getAll(x->r);
		v.insert(v.end(),w.begin(),w.end());
		v.push_back(x);
		return v;
	}
	return vector<T*>();
}
vector<T*> uniq(vector<T*> v){
	vector<bool> used(v.size(),false);
	vector<T*> res;
	for(int i = 0 ; i < v.size() ; i++){
		if( used[i] == false) used[i] = true;
		else continue;
		res.push_back(v[i]);
		for(int j = 0 ; j < v.size() ; j++){
			if( !used[j] ){
				if( issame(v[i],v[j]) ){
					used[j] = true;
				}
			}
		}
	}
	return res;
}
vector<T*> ando(vector<T*> a,vector<T*> b){
	vector<T*> res;
	for(int i = 0 ; i < a.size() ; i++){
		bool ok = false;
		for(int j = 0 ; j < b.size() ; j++){
			if( issame(a[i],b[j]) ) ok = true;	
		}
		if(ok)res.push_back(a[i]);
		
	}
	return res;
}
double calc(T *x){
	if( x->l == 0 ) return 0.0;
	vector<T*> a = uniq(getAll(x->l));
	vector<T*> b = uniq(getAll(x->r));
	vector<T*> c = a;
	c.insert(c.end(),b.begin(),b.end());
	c = uniq(c);
	auto d = ando(a,b);
	//cout << a.size() << " " << b.size() << endl;
	return 1. * d.size() / c.size();
}

// -1 : xのほうが強い
int comp(T *x,T *y){
	double a = calc(x);
	double b = calc(y);
	if( fabs(a-b) > 1e-8 ){
		return a < b ? -1 : 1;
	}else if( x->l == 0 && y->l == 0 ){
		return 0;
	}else{
		T *x2 = x;
		T *y2 = y;
		if( comp(x2->l,x2->r) > 0 ) swap(x2->l,x2->r);
		if( comp(y2->l,y2->r) > 0 ) swap(y2->l,y2->r);

		int a2 = comp(x2->l,y2->l);
		if( a2 != 0 ) return a2; 
		int b2 = comp(x2->r,y2->r);
		return b2;
	}
}

T* fix(T *x,int flip){
	if(x->l==0){
		return x;
	}else{
		if( comp(x->l,x->r) != 0 && (flip^(comp(x->l,x->r) > 0)) ){
			swap(x->l,x->r);
		}
		fix(x->l,0);
		fix(x->r,1);
		return x;
	}
}
string view(T *x){
	if( x->l == 0 ) return "x";
	else return "(" + view(x->l) + " " + view(x->r) + ")";
}

int main(){
	while(getline(cin,str), str != "0" ){
		chk.clear();
		p = 0;
		T *root = new T();
		dfs(root);
		//cout << calc(root) << endl;
		root = fix(root,0);
		cout << view(root) << endl;

	}

}

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

int main(){
    int n, k;
    cin >> n >> k;

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

    sort(p, p + n);
    int ans = 0;
    for(int i = 0; i < k; i++){
        ans += p[i];
    }

    cout << ans << endl;
}

Measured memory_bytes: 3636
#include <cassert>
#include <algorithm>
#include <bitset>
#include <cctype>
#include <cmath>
#include <complex>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <vector>
#include <random>
#include <memory>
#include <utility>
#include <limits>
#include "limits.h"
 
#define rep(i, a, b) for (long long (i) = (a); i < (b); i++)
#define all(i) i.begin(), i.end()
#define debug(...) std::cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)

void debug_out(){std::cerr<<std::endl;}

template<typename Head,typename... Tail>
void debug_out(Head h,Tail... t){
  std::cerr<<" "<<h;
  debug_out(t...);
}

 
template <typename T1, typename T2>
std::ostream& operator<<(std::ostream& os, std::pair<T1, T2> pa) {
  return os << pa.first << " " << pa.second;
}
 
template <typename T>
std::ostream& operator<<(std::ostream& os, std::vector<T> vec) {
  for (int i = 0; i < vec.size(); i++)os << vec[i] << (i + 1 == vec.size() ? "" : " ");
  return os;
}
 
template<typename T1,typename T2>
inline bool chmax(T1& a,T2 b){return a<b && (a=b,true);}
 
template<typename T1,typename T2>
inline bool chmin(T1& a,T2 b){return a>b && (a=b,true);}
 
long long pow_mod(long long a, long long b, long long mod=-1) {
  if(b==0)return 1;

  if ((a == 0)||(mod!=-1&&(a+mod)%mod==0)) {
    return 0;
  }
 
  long long x = 1;
 
  while (b > 0) {
    if (b & 1) {
      x = (mod!=-1)?(x * a) % mod:x*a;
    }
    a = (mod!=-1)?(a * a) % mod:a*a;
    b >>= 1;
  }
  return x;
}
 
// const long long MOD = 998244353;
const long long MOD = 1e9 + 7;

using ll = long long;
using P = std::pair<long long, long long>;

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

  ll k,n;
  std::cin>>k>>n;

  if(k%2==0){
    std::cout<<k/2;
    rep(i,0,n-1)std::cout<<" "<<k;
    std::cout<<"\n";
    return 0;
  }else{
    std::vector<ll> ans(n,(k+1)/2);
    rep(i,0,n/2){
      if(ans.back()==1){
        ans.pop_back();
      }else{
        ll num=ans.size();
        ans[num-1]--;
        rep(i,0,n-num)ans.push_back(k);
      }
    }

    for(ll e:ans)std::cout<<e<<" ";
    std::cout<<"\n";
  }

  return 0;
}

Measured memory_bytes: 4608
i,I;float h,w,B;main(n){for(;~scanf("%d",&n);I=I&&!printf("%d\n",I))for(B=1e9;n--;w<B|w==B&i<I&&(B=w,I=i))scanf("%d%f%f",&i,&h,&w),w=fabs(w/h/h*1e4-22);}

Measured memory_bytes: 0
#include<stdio.h>

#define MAX_N 100

int stack[MAX_N];
int top;

void push( int n )
{
	stack[top++] = n;
}

int pop(void)
{
	return stack[--top];
}

int main(void)
{
	int n;
	
	while( scanf( "%d", &n ) != EOF ) {
		if ( n == 0 ) {
			printf( "%d\n", pop() );
		}
		else {
			push( n );
		}
	}
	
	return 0;
}

Measured memory_bytes: 600
#include <bits/stdc++.h>
typedef long long ll;
using namespace std;
#define repr(i,a,b) for(int i=a;i<b;i++)
#define rep(i,n) for(int i=0;i<n;i++)
#define invrepr(i,a,b) for(int i=b-1;i>=a;i--)
#define invrep(i,n) invrepr(i,0,n)
#define repitr(itr,a) for(auto itr=a.begin();itr!=a.end();++itr)
#define P pair<int,int>
const ll MOD=1e9+7;
const int INF=2e9;
const double PI=acos(-1);


int main() {
    ios_base::sync_with_stdio(false);

    ll n,m;
    cin >> n >> m;
    ll ans=(n<m/2)?n:m/2;
    if (2*n<m) ans=(2*n+m)/4;
    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 3540
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#define print(n) std::cout << n << std::endl
#define FOR(i,n) for(int i = 0; i < n; i++)
using namespace std;

int main(){
    int m,n;
    cin >> m >> n;
    print((m-1)*(n-1));
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
struct Matrix
{
    ll m[3][3];
};

Matrix Mul(Matrix a,Matrix b)
{
    Matrix c;
    memset(c.m,0,sizeof(c.m));
    for(int i=0;i<3;i++)
        for(int j=0;j<3;j++)
            for(int k=0;k<3;k++)
                c.m[i][j] += a.m[i][k]*b.m[k][j];
    return c;
}

Matrix fastm(Matrix a,ll n)
{
    Matrix res;
    memset(res.m,0,sizeof(res.m));
    res.m[0][0] = res.m[1][1] = res.m[2][2] = 1;
    while(n)
    {
        if(n&1)
            res = Mul(res,a);
        n>>=1;
        a = Mul(a,a);
    }
    return res;
}

int main() {
    ll k;
    vector<ll> nums(3);
    cin >> nums[0] >> nums[1] >> nums[2] >> k;
    Matrix coef;
    ll num[3][3] = {{0,1,1},{1,0,1},{1,1,0}};
    for (int i = 0; i < 3; i++) {
        for (int j = 0; j < 3; j++) {
            coef.m[i][j] = num[i][j];
        }
    }
    Matrix res = fastm(coef, k);
    vector<ll> ans(3, 0);
    for (int i = 0; i < 3; i++) {
        for (int j = 0; j < 3; j++) {
            ans[i] += res.m[i][j] * nums[j];
        }
    }
    if (abs(ans[0] - ans[1]) > 1e18) {
        cout << "Unfair\n";
    } else {
        cout << ans[0] - ans[1] << "\n";
    }
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define _GLIBCXX_DEBUG
using namespace std;
using ll = long long;
using vec = vector<ll>;
using vect = vector<double>;
using Graph = vector<vector<ll>>;
#define loop(i, n) for (ll i = 0; i < n; i++)
#define Loop(i, m, n) for (ll i = m; i < n; i++)
#define pool(i, n) for (ll i = n; i >= 0; i--)
#define Pool(i, m, n) for (ll i = n; i >= m; i--)
#define mod 1000000007ll
#define flagcount __builtin_popcount
#define flag(x) (1 << x)
#define flagadd(bit, x) bit |= flag(x)
#define flagpop(bit, x) bit &= ~flag(x)
#define flagon(bit, i) bit &flag(i)
#define flagoff(bit, i) !(bit & (1 << i))
#define all(v) v.begin(), v.end()
#define low2way(v, x) lower_bound(all(v), x)
#define high2way(v, x) upper_bound(all(v), x)
#define idx_lower(v, x) (distance(v.begin(), low2way(v, x)))  //配列vでx未満の要素数を返す
#define idx_upper(v, x) (distance(v.begin(), high2way(v, x))) //配列vでx以下の要素数を返す
#define idx_lower2(v, x) (v.size() - idx_lower(v, x))         //配列vでx以上の要素数を返す
#define idx_upper2(v, x) (v.size() - idx_upper(v, x))         //配列vでxより大きい要素の数を返す
#define putout(a) cout << a << endl
#define Gput(a, b) G[a].push_back(b)
#define Sum(v) accumulate(all(v), 0ll)
#define gcd(x, y) __gcd(x, y)
ll ctoi(char c)
{
    if (c >= '0' && c <= '9')
    {
        return c - '0';
    }
    return 0;
}
template <typename T>
T lcm(T x, T y)
{
    T z = gcd(x, y);
    return x * y / z;
}
template <typename T>
bool primejudge(T n)
{
    if (n < 2)
        return false;
    else if (n == 2)
        return true;
    else if (n % 2 == 0)
        return false;
    double sqrtn = sqrt(n);
    for (T i = 3; i < sqrtn + 1; i++)
    {
        if (n % i == 0)
        {
            return false;
        }
        i++;
    }
    return true;
}
//場合によって使い分ける
//const ll dx[4]={1,0,-1,0};
//const ll dy[4]={0,1,0,-1};
const ll dx[8] = {1, 1, 0, -1, -1, -1, 0, 1};
const ll dy[8] = {0, 1, 1, 1, 0, -1, -1, -1};
//2次元配列の宣言
//vector<vector<ll>> field(h, vector<ll>(w));

int main()
{
    cout << fixed << setprecision(30);
    static const long double pi = 3.141592653589793;
    long double A, B, H, M;
    cin >> A >> B >> H >> M;
    long double x = (pi / 6.0) * (H + (M / 60.0));
    long double y = M * pi / 30.0;
    long double z = max(x, y) - min(x, y);
    long double ans = sqrt(A * A + B * B - 2.0 * A * B * cos(z));
    putout(ans);
    return 0;
}


Measured memory_bytes: 4136
#include <bits/stdc++.h>
    // #include <iostream>
    #include <string>
    #include <queue>
    #include <set>
    #include <list>
    #include <chrono>
    #include <random>
    #include <iostream>
    #include <algorithm>
    #include <cmath>
    #include <string>
    #include <vector>
    #include <map>
    #include <unordered_map>
    #include <stack>
    using namespace std;
    #define frn(i,a,b) for(ll i=a;i<b;i++)
    #define forn(i,a,b) for(ll i=a;i<=b;i++)
    #define frt(i,a,b) for(auto it=a;it!=b;it++)
    #define MP make_pair
    #define F first
    #define S second
    #define PB push_back
    #define SQ(a) (a)*(a)
    #define SUM(n) ((n)*(n+1))/2
    #define SqSUM(n) ((n)*(n+1)*(2*n+1))/2
    #define GMSUM(a,r,n) (a*pow(r,n)-a)/(r-1)
    // to sort vector of any kind string or any sorting form sort(v.begin(),v.end()); and for reverse use rbegin and rend
    const long long int md = 998244353;
    typedef long long ll;
    typedef long double ld;
    typedef pair<ll, ll> pi;
    typedef vector<ll> vi;
    typedef vector<vector<ll, ll> > vvi;
    // typedef bitset<5> bst;
    const ll MAX = LONG_MAX;
    int main()
    {
        ios_base::sync_with_stdio(false);
        cin.tie(NULL);
        cout.tie(NULL);
        ll n;
        cin>>n;
        string ar[n];
        map<map<char ,ll > ,ll > mp1; 
        frn(i,0,n)
        {
            cin>>ar[i];
            map<char, ll> mp2;
            frn(j,0,ar[i].length())
            {
                mp2[ar[i][j]]++;
            }
            mp1[mp2]++;
        }
        ll sm=0;
        for(auto it:mp1)
        {
            sm+=(it.second*(it.second-1))/2;
        }
        cout<<sm;
        return 0;
    } 

Measured memory_bytes: 67840
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
int gcd(int a,int b)
{
	if(b==0)
	return a;
	
	return gcd(b,a%b);
}
int power(int x,int y,int p)
{
	int res=1;
	x=x%p;
	while(y>0)
	{
		if(y&1)
		res=(res*x)%p;
		
		y=y>>1;
		x=(x*x)%p;
	}
	return res;
}
int modInverse(int n,int p)
{
	return power(n,p-2,p);
}

int main() {
	// your code goes here
	 ios_base::sync_with_stdio(0);
	 cin.tie(0);
	 ll n,k;
	 cin>>n>>k;
	 vector<ll> v(n+1);
	 for(ll i=1;i<=n;i++)
	 {
	 	cin>>v[i];
	 }
	 set<ll> st;
	 vector<ll> already;
	 ll pos=1;
	 k++;
	 while(k>0)
	 {
	 	if(st.count(pos)==0)
	 	{
	 		st.insert(pos);
	 		already.push_back(pos);
	 	}
	 	else
	 	{
	 		
	 		break;
	 	}
	 	pos=v[pos];
	 	k--;
	 }
	 for(ll i=0;i<(ll)already.size();i++)
	 {
	 	if(already[i]==pos)
	 	{
	 		pos=i;
	 		break;
	 	}
	 }
	 if(k>0)
	 {
	 	k--;
	 	ll val=(ll)already.size()-pos;
		ll ans=already[pos+k%val];
		cout<<ans;
	 }
	 else
	 {
	 	cout<<already[(ll)already.size()-1];
	 }
	 //for(ll x:already)
	 //cout<<x<<" ";
	 
	 return 0;
}

Measured memory_bytes: 13688
#include <stdio.h>

int main() {
  int n;
  scanf("%d", &n);

  char str[n + 1];
  scanf("%s", str);

  if(n % 2 == 1) {
      puts("No");
  }
  else {
    int flag = 1;
    for(int i = 0; i < n / 2; i++) {
      if(str[i] != str[i + n / 2]) {
        flag = 0;
      }
    }
    if(flag == 1) {
      puts("Yes");
    }
    else {
      puts("No");
    }
  }
  return 0;
}

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

#define mp make_pair
#define eb emplace_back
#define ff first
#define ss second

using namespace std;

typedef long long ll;
typedef unsigned long long ull;

#ifdef ONPC
mt19937 rnd(228);
#else
mt19937 rnd(chrono::steady_clock::now().time_since_epoch().count());
#endif


const int MAXN = 454;
//#define int long long
const int INF = 1e9;

const ll MOD = (ll)1e9 + 7LL;

ll mult(ll a, ll b){
  return (a * b) % MOD;
}

ll add(ll a, ll b){
  return (a + b) % MOD;
}

ll a[MAXN], b[MAXN];

ll dp[MAXN][MAXN];

void solve(){
  int n, c;
  cin >> n >> c;
  for (int i = 0; i < n; i++) cin >> a[i];
  for (int i = 0; i < n; i++) cin >> b[i];
  
  for (ll x = a[0]; x <= b[0]; x++){
    ll curx = 1LL;
    dp[0][0] = add(dp[0][0], curx);
    for (int j = 1; j <= c; j++){
      curx = mult(curx, x);
      dp[0][j] = add(dp[0][j], curx);
    }
  }

  for (int i = 1; i < n; i++){
    vector<ll> sx(c + 1, 0);
    for (int x = a[i]; x <= b[i]; x++){
      ll curx = 1LL;
      sx[0] = add(sx[0], curx);
      for (int j = 1; j <= c; j++){
        curx = mult(curx, x);
        sx[j] = add(curx, sx[j]);
      }
    }
    for (int k = 0; k <= c; k++){
      for (int j = 0; j <= k; j++){
        dp[i][k] = add(dp[i][k], mult(dp[i-1][j], sx[k - j]));
      }
    }
  }

  cout << dp[n-1][c] << '\n';
}

signed main()
{
    #ifdef FILEIO
      freopen("input.txt", "r", stdin);
      freopen("output.txt", "w", stdout);
    #endif

    ios_base::sync_with_stdio(0);
    cin.tie(0);

    solve();

    return 0;
}


Measured memory_bytes: 5092
N = int(input())
X = [list(map(int, input().split())) for _ in range(N)]

res = 0

for i in range(N):
    for j in range(i+1):
        res += ((X[i][0]-X[j][0])**2+(X[i][1]-X[j][1])**2)**0.5


print(res*2/N)

Measured memory_bytes: 3188
import java.util.*;

public class Main {

    public static void main(String[] args) {

        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();

        int ans =0;
        Map<String, List<Integer>> m = new HashMap<>();

        for (int i = 1; i <= N; i++) {
            String iStr = i+"";
            String a = iStr.substring(0,1);
            String b = iStr.substring(iStr.length()-1);
            String ab = a+b ;
            String ba = b+a ;
            if(!m.containsKey(ab)){
                m.put(ab,new ArrayList<>());
            }
            m.get(ab).add(i);
            if(m.containsKey(ba)){
                if(a.equals(b)){
                    ans+=m.get(ba).size() * 2 -1;
                }else{
                    ans+=m.get(ba).size() * 2;
                }

            }
        }
        System.out.println(ans);
    }
}

Measured memory_bytes: 64416
#include <bits/stdc++.h>
#define rep(i, n) for (int i=0; i<(int)(n); i++)
#define all(v) v.begin(), v.end()
#define PRINT(v) for (auto x : (V)) cout <<x <<" " <<endl;
using namespace std;
using ll = long long;
using Graph = vector<vector<int>>;
const ll MOD = 1000000007;
const ll INF = 10000000000000000;
vector<int> x4 = {0, 1, 0, -1}, x8 = {0, 1, 1, 1, 0, -1, -1, -1};
vector<int> y4 = {1, 0, -1, 0}, y8 = {1, 1, 0, -1, -1, -1, 0, 1};
template<class T> struct edge { int from, to; T cost;};
template<class T> inline bool chmin(T& a, T b){if (a>b){a = b; return true;}return false;}
template<class T> inline bool chmax(T& a, T b){if (a<b){a = b; return true;}return false;}
template<class T> inline T powerM(T a,T b){if (b==0) return 1;
T tmp = powerM(a,b/2); if (b%2==0) return tmp*tmp%MOD; else return tmp*tmp%MOD*a%MOD; }
template<class T> inline T power(T a,T b,T m){ if (b==0) return 1;
  T tmp = power(a,b/2,m); if (b%2==0) return tmp*tmp%m; else return tmp*tmp%m*a%m; }
template<class T> inline T gcd(T a, T b){if (b==0) return a; return gcd(b, a%b);}
template<class T> inline T lcm(T a, T b){return a / gcd(a,b) * b;}
// ax+by=gcd(a,b)を解く
template<class T> inline T extgcd(T a,T b,T &x,T &y){if (b==0){x=1; y=0; return a;} T d=extgcd(b,a%b,y,x); y -= a/b*x; return d;}
void hey(){ cout <<"hey" <<endl; }


// Union-Find木-----------------------------------------------
/* ここらへんと蟻本を参考に
<https://qiita.com/drken/items/cce6fc5c579051e64fab>
<http://baitop.hatenadiary.jp/entry/2018/06/26/224712>
sizeが必要なら2個目のリンクからいい感じに
*/
// UnionFind uf(N); // N:要素数

struct UnionFind{
  vector<int> par;  // 親ノードを格納
  vector<int> rank; // 木の深さを格納
  vector<int> sizes; // 木の大きさを格納

  UnionFind(int N = 1) : par(N), rank(N, 0), sizes(N) { // N要素で初期化する
    for (int i=0; i<N; i++) par[i] = i;
    for (int i=0; i<N; i++) sizes[i] = 1;
  }

  int root(int x){ // 木の根を求める。自分じゃなかったら親の根を調べていき調べたノードの親はすべて根に
    return par[x] == x ? x : par[x] = root(par[x]); // 経路圧縮も行う
  }

  bool same(int x, int y){ // x,yの木が同じかどうか
    return root(x) == root(y);
  }

  bool unite(int x, int y){ // xとyの木を併合
    x = root(x); y = root(y); // ここでx,yのroot同士の扱いにする
    if (x == y) return false; // 元々同じならそのまま
    if (rank[x] < rank[y]) swap(x, y); // rank[x] >= rank[y]になるようにswap
    if (rank[x] == rank[y]) rank[x]++; // 元のrankが同じなら親になる方のrankは1増える
    par[y] = x;
    sizes[x] += sizes[y];
    return true;
  }

  int size(int x){
    return sizes[par[x]];
  }
};


int main() {
  int N,M; cin >>N >>M;
  UnionFind uf(N);
  vector<int> A(M),B(M);
  rep(i, M){
    cin >>A[i] >>B[i]; A[i]--; B[i]--;
  }
  /*橋が崩落したとして、崩落した後もaとbが連結ならばまあいいでしょう
  AとBが連結でなくなれば、崩落した後のsize(A) * size(B) の分だけ不便さが増える
  UnionFindでやりたいので、逆から見ていってAとBが繋がると考える
  この時減少する不便さはAとBが元々連結なら0、そうでなければsize(A) * size(B)の分だけ減少する
  答えるときはこれらを逆に見ていって足していけばよい
  */
  vector<ll> inc(M);
  for (int i=M-1; i>=0; i--){
    int a = A[i], b = B[i];
    if (uf.same(a, b)) continue; // 元々連結なら繋がってもうれしくない
    inc[i] = (ll)uf.size(a) * (ll)uf.size(b);
    uf.unite(a, b);
  }
  ll res = 0;
  rep(i, M){
    res += inc[i];
    cout <<res <<endl;
  }

}


Measured memory_bytes: 4096
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for(ll i = 0, i##_len = (n); i < i##_len; i++)
#define reps(i, s, n) for(ll i = (s), i##_len = (n); i < i##_len; i++)
#define rrep(i, n) for(ll i = (n) - 1; i >= 0; i--)
#define rreps(i, e, n) for(ll i = (n) - 1; i >= (e); i--)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define sz(x) ((ll)(x).size())
#define len(x) ((ll)(x).length())
#define endl "\n"

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    // ifstream in("input.txt");
    // cin.rdbuf(in.rdbuf());
    ll n, k;
    cin >> n >> k;
    vector<ll> a(n);
    rep(i, n) cin >> a[i];
    reps(i, k, n) {
        cout << ((a[i - k] < a[i]) ? "Yes" : "No") << endl;
    }
    return 0;
}


Measured memory_bytes: 4800
fn main() {
    let s = std::io::stdin();
    let mut sc = Scanner { stdin: s.lock() };
    let l: usize = sc.read();

    let mut r = 0;
    while (1 << (r + 1)) <= l {
        r += 1;
    }

    let sum = (1 << r) - 1;
    let n = r + 1;
    let mut graph = vec![vec![]; n];
    for i in 0..r {
        graph[i].push((i + 1, 1 << i));
        graph[i].push((i + 1, 0));
    }

    let mut l = l;
    for i in (0..(n - 1)).rev() {
        let to_i = (1 << i) - 1;

        if l >= sum + 1 + (to_i + 1) {
            let t = l - (to_i + 1);
            graph[i].push((n - 1, t));
            l = t;
        }
    }

    let mut ans = vec![];
    for i in 0..n {
        for &(next, w) in graph[i].iter() {
            ans.push((i, next, w));
        }
    }

    println!("{} {}", n, ans.len());
    for &(i, next, w) in ans.iter() {
        println!("{} {} {}", i + 1, next + 1, w);
    }
}

pub struct Scanner<R> {
    stdin: R,
}

impl<R: std::io::Read> Scanner<R> {
    pub fn read<T: std::str::FromStr>(&mut self) -> T {
        use std::io::Read;
        let buf = self
            .stdin
            .by_ref()
            .bytes()
            .map(|b| b.unwrap())
            .skip_while(|&b| b == b' ' || b == b'\n')
            .take_while(|&b| b != b' ' && b != b'\n')
            .collect::<Vec<_>>();
        unsafe { std::str::from_utf8_unchecked(&buf) }
            .parse()
            .ok()
            .expect("Parse error.")
    }
    pub fn vec<T: std::str::FromStr>(&mut self, n: usize) -> Vec<T> {
        (0..n).map(|_| self.read()).collect()
    }
    pub fn chars(&mut self) -> Vec<char> {
        self.read::<String>().chars().collect()
    }
}


Measured memory_bytes: 4352
#include <iostream>
#include<cstdlib>
#include<queue>
#include<set>
#include<vector>
#include<string>
#include<algorithm>
#include<stack>
#include<map>
#include<deque>
#include<cstdio>
using namespace std;
#define rep(i,a) for(int i=0;i<a;i++)
#define mp make_pair
#define pb push_back
#define ll __int64
//#define __int64 long long
#define P pair<int,int>
int g[111][111];
int is[111][111];
bool ok[111][111];
int n,m;
int a,b,c;
vector<P>edge;
const int INF=1000000000;
int main(){
	cin>>n>>m;
	rep(i,n)rep(j,n)g[i][j]=(i==j)?0:INF;

	rep(i,m){
		cin>>a>>b>>c;
		a--;b--;
		g[a][b]=c;
		g[b][a]=c;
		is[a][b]=is[b][a]=c;
		edge.push_back(mp(a,b));
	}
	
	rep(k,n){
		rep(i,n){
			rep(j,n)g[i][j]=min(g[i][j],g[i][k]+g[k][j]);
		}
	}


	rep(k,n){
		rep(i,n){
			rep(j,n)if(g[i][k]+is[k][j]==g[i][j])ok[k][j]=ok[j][k]=1;
		}
	}
	int ans=0;
	rep(i,n){
		for(int j=i+1;j<n;j++)if(is[i][j]&&!ok[i][j])ans++;
	}		
	cout<<ans<<endl;
	
	return 0;
}



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

ll n, k, a[200001];

bool check(ll len){
    ll kk = k;
    for(int i = 0; i < n; i++){
        kk -= ((a[i] + len - 1) / len - 1);
    }
    return kk >= 0;
}

int main(){
    cin >> n >> k;
    ll sum = 0;
    for(int i = 0; i < n; i++){
        cin >> a[i];
        sum += a[i];
    }
    sort(a, a + n);
    ll beg = 1, en = 1e9;
    ll ans = a[n - 1];
    while(beg <= en){
        ll mid = (beg + en) / 2;
        if(check(mid)){
            en = mid - 1;
            ans = mid;
        }else{
            beg = mid + 1;
        }
    }
    cout << ans;
}


Measured memory_bytes: 5108
#include <cstring>
#include <map>
#include <unordered_map>
#include <string>
#include <list>
#include <vector>
#include <algorithm>
#include <queue>
#include <stack>
#include <cstdio>
#include <iostream>
#include <set>
#include <unordered_set>
using namespace std;

#define MAX(a,b) (a>b?a:b)
#define MIN(a,b) (a<b?a:b)
#define ABS(a) ((a)>0?(a):(-(a)))
typedef long long ll;
typedef unsigned long long ull;
typedef unsigned int ui;
typedef pair<int, int> pii;

int gi() {
    int a;
    scanf("%d", &a);
    return a;
}

ll gli() {
    ll a;
    scanf("%lld", &a);
    return a;
}

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

    ll t1 = gi();
    ll t2 = gi();

    ll a1 = gli();
    ll a2 = gli();
    ll b1 = gli();
    ll b2 = gli();

    ll at = a1*t1+a2*t2;
    ll bt = b1*t1+b2*t2;
    if (at == bt) {
        printf("infinity\n");
        return 0;
    }

    ll at1 = a1*t1;
    ll bt1 = b1*t1;
    if ((at1 > bt1 && at > bt) || (at1 < bt1 && at < bt)) {
        printf("0\n");
        return 0;
    }

    ll fd = ABS(at - bt);
    ll fd1 = ABS(at1 - bt1);
    if (fd1%fd == 0) {
        cout << 2*fd1/fd << endl;
    } else {
        cout << 1+2*(fd1/fd) << endl;
    }

    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ALL(a) (a).begin(), (a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define pb push_back
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define rep(i, n) FOR(i, 0, n)
#define ll long long
using namespace std;

const ll P = 1000000007;
const long long INF = 1LL << 60;
int gcd(int a, int b) { return b != 0 ? gcd(b, a % b) : a; }
int lcm(int a, int b) { return a / gcd(a, b) * b; }

int main()
{
  cout << fixed << setprecision(10);
  int N;
  cin >> N;
  int sum = 0;
  rep(i,1000)
  {
    sum += N;
    if(sum%360==0)
    {
      cout << i + 1 << endl;
      return 0;
    }
  }
  return 0;
}


Measured memory_bytes: 3632
import java.io.IOException;
import java.util.ArrayList;
import java.util.Comparator;
import java.util.List;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) throws IOException {

		Scanner scan = new Scanner(System.in);

		int A = scan.nextInt();
		int B = scan.nextInt();
		int C = scan.nextInt();

		List<Integer> list = new ArrayList<>();
		list.add(A);
		list.add(B);
		list.add(C);

		list.sort(Comparator.reverseOrder());

		String large = String.valueOf(list.get(0)) + String.valueOf(list.get(1));
		int sum = Integer.parseInt(large) + list.get(2);

		System.out.println(sum);

	}

	//***********************以下共通関数************************************************
	/**
	 * 文字列を反転して返す
	 * @param pStr 文字列
	 * @return 反転した文字列
	 */
	public static String myReverse(String pStr) {
		if (pStr.length() < 1) {
			return "";
		}

		StringBuffer sb = new StringBuffer(pStr);
		return sb.reverse().toString();
	}

	/**
	 * 余りを求める。
	 * @param a
	 * @param b
	 * @return 余り。余りがマイナスの時はプラスで返す。
	 */
	public static long myMod(long a, long b) {
		long ret = 0;

		ret = a % b;

		if (ret < 0) {
			ret += b;
		}

		return ret;
	}

	/**
	 * 乗数を求める ※mod対応
	 * @param kisu 基数
	 * @param josu 乗数
	 * @param primeNumMod_0 法 mod値 使わない場合は「0」
	 * @return
	 */
	public static long myPowWithMod(long kisu, long josu, long primeNumMod_0) {

		long ans = 1;

		//乗数が0の場合→1
		if (josu == 0)
			return 1;

		if (primeNumMod_0 == 0) {
			//modを使わないとき

			while (josu > 0) {

				if (josu % 2 == 0) {
					//累乗が偶数の時

					kisu *= kisu;
					josu = josu / 2;
				} else {
					//累乗が奇数の時
					ans *= kisu;
					josu--;
				}
			}

			return ans;

		} else {
			//modを使うとき

			//初めに桁を落とす
			kisu = myMod(kisu, primeNumMod_0);

			while (josu > 0) {

				if (josu % 2 == 0) {
					//累乗が偶数の時

					kisu *= myMod(kisu, primeNumMod_0);
					josu = josu / 2;

				} else {
					//累乗が奇数の時
					ans *= myMod(kisu, primeNumMod_0);
					josu--;

				}
			}

			return myMod(ans, primeNumMod_0);

		}

	}

}


Measured memory_bytes: 21844
#include <bits/stdc++.h>
using namespace std;
//using namespace __gnu_pbds; 
#define ull          unsigned long long int
#define ll          long long int
#define pb          push_back
#define pii         pair<int,int>
#define F           first
#define S           second
#define vi          vector<int>
#define vli          vector<ll>
#define vii         vector<pii>
#define mi          map<int,int>
#define mii         map<pii,int>
#define M_PI        3.14159265358979323846
#define mp          make_pair
#define sz(x)       (int)x.size()
#define matrix      vector<vector<ll>>
#define forn(i,a,b)  for(int i=a;i<b;i++)
#define eps 0.0000000001
#define all(a)      (a).begin(),(a).end()
#define ordered_set     tree<ll,null_type,less<ll>,rb_tree_tag,tree_order_statistics_node_update> 
 
const long long INF = (long long) 1e11+1;
const long long mod = (long long) 998244353;
const long long hell = (long long) 1000000007;

ll power(ll x,ll y){
  ll res=1;
  while(y>0){
    if(y%2) res=(x%hell*res%hell)%hell;
    x=(x%hell*x%hell)%hell;    
    y=y/2;
  }
  
  return res%hell;
}
 
ll modinv(ll x){
  return power(x,hell-2);
}

ll gcd(ll a,ll b){
    while( b != 0)
	{
		ll  t = b;
		b= a %t;
		a = t;
	}
	return a;
}    
    
void fastIO(){
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
} 
    
void solve(){  
    int h1,h2,m1,m2,k;
    cin>>h1>>m1>>h2>>m2>>k;
    
    int tot=(h2-h1)*60;
    tot+=m2;
    tot-=m1;
    
    int ans=max(0,tot-k);
    
    cout<<ans;
}    

int main(){
   fastIO();
   int test;
   //cin>>test;
   test=1;    
      
   while(test--)
   solve();
}

Measured memory_bytes: 3604
let n = Scanf.scanf " %d" (+) 0
let vs = Array.init n @@ fun _ -> Scanf.scanf " %d" (+) 0
let css = Array.make_matrix 2 100001 0
let ms = ref [|0, 0; 0, 0|]
let e0, e1, o0, o1 = Array.iteri (fun i v -> let c = css.(i mod 2).(v) + 1 in css.(i mod 2).(v) <- c; !ms.(i mod 2) <- max !ms.(i mod 2) (c, v)) vs;
  List.iter (fun i -> Array.sort (fun x y -> compare y x) css.(i)) [0; 1];
  css.(0).(0), css.(0).(1), css.(1).(0), css.(1).(1)
let _ = Printf.printf "%d\n" @@ if snd !ms.(0) = snd !ms.(1) then n - max (e0 + o1) (e1 + o0) else n - e0 - o0

Measured memory_bytes: 6400
#include<bits/stdc++.h>
#define int long long
#define pb push_back
using namespace std;
int dp[200][200][2];
vector <int> num;
int k;
string s;
int solve(int pos, int cnt, int flag)
{
	if(cnt > k) return 0;
	if(pos == s.size())
	{
		if(cnt == k) return 1;
		else return 0;
	}
	if(dp[pos][cnt][flag] != -1) return dp[pos][cnt][flag];
	int res = 0;
	int limit;
	if(flag == 0) limit = s[pos]-'0';
	else limit = 9;
	for(int digit = 0; digit <= limit; digit++)
	{
		int nf = flag;
		int ncnt = cnt;
		if(digit != 0) ncnt++;
		if(flag == 0 && digit < limit) nf = 1;
		if(ncnt <= k) res += solve(pos+1,ncnt,nf);
	}
	return dp[pos][cnt][flag] = res;
}
int solve1(string s)
{
	memset(dp,-1,sizeof(dp));
	int result = solve(0,0,0);
	return result;
}
int32_t main()
{
	cin >> s >> k;
	cout << solve1(s) << "\n";
	return 0;
}

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

int main(){
    int N;
    string ans = "No";
    vector<vector<int>> A(3, vector<int>(3));
    vector<vector<bool>> C(3, vector<bool>(3, false));
    for(int i = 0; i < 3; ++i){
        for(int j = 0; j < 3; ++j) cin >> A[i][j];
    }
    cin >> N;
    vector<int> B(N);
    for(auto& b : B) cin >> b;
    if(N < 3) ans = "No";
    else{
        for(auto b : B){
            for(int i = 0; i < 3; ++i){
                for(int j = 0; j < 3; ++j){
                    if(A[i][j] == b) C[i][j] = true;
                }
            }
        }
        for(int i = 0; i < 3; ++i){
            if(C[i][0] && C[i][1] && C[i][2]) ans = "Yes";
            else if(C[0][i] && C[1][i] && C[2][i]) ans = "Yes";
        }
        if((C[0][0] && C[1][1] && C[2][2]) || (C[0][2] && C[1][1] && C[2][0])) ans = "Yes";
    }
    /*
    for(int i = 0; i < 3; ++i){
        for(int j = 0; j < 3; ++j){
            cout << C[i][j] << ",";
        }
        cout << endl;
    }
    */
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3632
n,q = gets.chomp.split.map(&:to_i)
ts = (n-1).times.map{gets.chomp.split.map(&:to_i)}
cs = q.times.map{gets.chomp.split.map(&:to_i)}
tree = Array.new(n){Array.new}
count = Array.new(n,0)

ts.each do |a,b|
  tree[a-1].push(b-1)
end
cs.each do|c,add|
  count[c-1] += add
end
count.each_with_index do|c,i|
  if !tree[i].empty?
    tree[i].each do |t|
      count[t] += count[i]
    end
  end
end
puts count.join(" ")




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

#define int long long
#define fi first
#define se second
#define rep(i,n) for(int i=0;i<(int)(n);++i)
#define rep1(i,n) for(int i=1;i<=(int)(n);++i)
#define rep11(i,n) for(int i=1;i<(int)(n);++i)
#define repo(i,o,n) for(int i=o;i<(int)(n);++i)
#define repm(i,n) for(int i=(int)(n)-1;i>=0;--i)
#define all(v) (v).begin(),(v).end()
#define rall(v) (v).rbegin(),(v).rend()
#define sperase(v,n) (v).erase(remove(all(v), n), (v).end())
#define vdelete(v) (v).erase(unique(all(v)), (v).end())
#define pb(n) push_back(n)
#define mp make_pair
#define MOD 1000000007
#define INF LONG_LONG_MAX

bool ans=true;
string s,s1="RUD",s2="LUD";

signed main() {
    cin >> s;
    rep(i,s.size()) {
        bool f=false;
        if (i%2) {
            for(auto j : s2) if (s[i] == j) f=true;
        }
        else {
            for(auto j : s1) if (s[i] == j) f=true;
        }
        ans &= f;
    }
    if (ans) cout << "Yes" << endl;
    else cout << "No" << endl;
}

Measured memory_bytes: 256
N=int(input())
A=list(map(int,input().split()))

y=abs(A[0])
for i in range(1,N):
  y+=abs(A[i]-A[i-1])
y+=abs(A[N-1])

print(y-abs(A[0]-A[1])-abs(A[0])+abs(A[1]))
for i in range(1,N-1):
  print(y-abs(A[i]-A[i+1])-abs(A[i]-A[i-1])+abs(A[i+1]-A[i-1]))
print(y-abs(A[N-1])-abs(A[N-1]-A[N-2])+abs(A[N-2]))

Measured memory_bytes: 14172
<?php
//fscanf(STDIN, "%d", $number); // STDIN から数値を読み込む
//fscanf(STDIN, "%d %d", $number2,$number3); // STDIN から数値を読み込む

$arr = explode(' ', trim(fgets(STDIN)));
$A = $arr[0];
$B = $arr[1];
$N = $arr[2];

//echo "A:$A B:$B N:$N \n";

//$A = 11;
//$B = 6;
//$N = 9;
$old_data = 0;
$x = $B - 1;
if($N < $x) $x = $N;


//for($x=1;$x<$N + 1;$x++){

$data = floor($A*$x/$B) -$A*floor($x/$B);
if($data > $old_data){
$old_data = $data;
}
//echo "x = {$x}のとき {$data} old_data:{$old_data}\n";

//}


echo $old_data;



?>

Measured memory_bytes: 16096
#include<bits/stdc++.h>
using namespace std;
#define MAX (int)1e+5+1

int N, K;
string S;
vector <int> A;

int main() {
    cin >> N;
    cin >> K;
    cin >> S;

    char s;
    int n;
    for (int i=0; i<N; i++) {
        if (i==0) {
            s = S[i];
            n = 1;
        } else {
            if (s==S[i]) {
                n++;
            } else {
                A.push_back(n);
                s = S[i];
                n = 1;
            }
        }
    }
    A.push_back(n);

    for (int i=0; i<K; i++) {
        if (A.size()==1) break;
        if (A.size() >= 3) {
            A[1] += A[2] + A[0];
            A.erase(A.begin() + 2);
            A.erase(A.begin());
        } else {
            A[0] += A[1];
            A.erase(A.begin() + 1);
        }
    }

    int ans = 0;
    for (int i=0; i<A.size(); i++) {
        ans += A[i] - 1;
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 1020
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int MAXN = 2010;
int N, M, Q;
vector<string> S;
int v[MAXN][MAXN], ns[MAXN][MAXN], ew[MAXN][MAXN];
int a[MAXN][MAXN];

void precompute() {
    for(int i=0;i<N;i++) {
        for(int j=0;j<M;j++) {
            a[i+1][j+1] = S[i][j]=='1';
        }
    }
    for(int i=1;i<=N;i++) {
        for(int j=1;j<=M;j++) {
            v[i][j] = a[i][j] + v[i-1][j] + v[i][j-1] - v[i-1][j-1];
            ns[i][j] = ns[i-1][j] + ns[i][j-1] - ns[i-1][j-1];
            ew[i][j] = ew[i-1][j] + ew[i][j-1] - ew[i-1][j-1];
            if(a[i][j] && a[i-1][j]) ns[i][j] += 1; // valid south
            if(a[i][j] && a[i][j-1]) ew[i][j] += 1; // valid east
        } 
    }
}

int query(int x1, int y1, int x2, int y2) {
    int vertices = v[x2][y2] - v[x1-1][y2] - v[x2][y1-1] + v[x1-1][y1-1];
    int east_west = ew[x2][y2] - ew[x1-1][y2] - ew[x2][y1] + ew[x1-1][y1];
    int north_south = ns[x2][y2] - ns[x1][y2] - ns[x2][y1-1] + ns[x1][y1-1];
    //cout << "Vertices: " << vertices << " East cells: " << east_west << " South Cells: " << north_south << endl;

    return vertices - (east_west + north_south);
}

void print() {
    for(int i=1;i<=N;i++) {
        for(int j=1;j<=M;j++) {
            printf("%d ", a[i][j]);
        } printf("\n");
    }
    printf("----\n");
    for(int i=1;i<=N;i++) {
        for(int j=1;j<=M;j++) {
            printf("%d ", v[i][j]);
        } printf("\n");
    }
    printf("----\n");
    for(int i=1;i<=N;i++) {
        for(int j=1;j<=M;j++) {
            printf("%d ", ew[i][j]);
        } printf("\n");
    }
    printf("----\n");
    for(int i=1;i<=N;i++) {
        for(int j=1;j<=M;j++) {
            printf("%d ", ns[i][j]);
        } printf("\n");
    }
}

int main() {    
    ios::sync_with_stdio(false);
    cin >> N >> M >> Q;
    S.assign(N, "");
    for(int i=0;i<N;i++) {
        cin >> S[i];
    }
    precompute();
    //print();
    
    int x1, x2, y1, y2;
    while(Q--) {
       cin >> x1 >> y1 >> x2 >> y2;
       cout << query(x1, y1, x2, y2) << endl;
    }
}


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

int main(void){
    ll a, b, c, d;
    cin >> a >> b >> c >> d;
    cout << min(a, b) + min(c, d) << endl;
    return 0;
}


Measured memory_bytes: 256
#include <iostream>

using namespace std;

int main()
{
  int n, *w, *sum1, *sum2, min;
  cin >> n;
  w = new int[n];
  sum1 = new int[n-1];
  sum2 = new int[n-1];

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

  sum1[0] = w[0];
  for (int i = 1; i < n-1; i++) {
    sum1[i] = sum1[i-1] + w[i];
  }
  sum2[n-2] = w[n-1];
  for (int i = n-3; 0 <= i; i--) {
    sum2[i] = sum2[i+1] + w[i+1];
  }

  //for (int i = 0; i < n-1; i++) {
  //  cout << ' ' << sum1[i];
  //}
  //cout << endl;
  //for (int i = 0; i < n-1; i++) {
  //  cout << ' ' << sum2[i];
  //}
  //cout << endl;

  min = 9999999;
  for (int i = 0; i < n-1; i++) {
    int diff;
    diff = sum1[i] - sum2[i];
    if (diff < 0) {
      diff = -diff;
    }
    if (diff < min) {
      min = diff;
    }
  }

  cout << min << endl;

  delete [] w;
  delete [] sum1;
  delete [] sum2;
}


Measured memory_bytes: 256
import sys
input = sys.stdin.readline
def main():
    R, C,K = map(int, input().split())
    dp = [[[0]*(C+1) for k in range(R+1)] for _ in range(4)]
    # dp[r][c][j] :=r index c columns already j cnt
    dp[0][0][0] = 0
    D = [[0 for i in range(C+1)] for j in range(R+1)]
    import random
    for i in range(K):
        r, c, v = map(int,input().split())
        D[r][c] = v
    
    for i in range(R+1):
        for j in range(C+1):
            if D[i][j] > 0:
                v = D[i][j]
                M = max(dp[k][i-1][j] for k in range(4))
                dp[0][i][j] = max(dp[0][i][j-1], M)
                dp[1][i][j] = max(dp[0][i][j-1]+v, dp[1][i][j-1], M+v)
                dp[2][i][j] = max(dp[1][i][j-1]+v, dp[2][i][j-1])
                dp[3][i][j] = max(dp[2][i][j-1]+v, dp[3][i][j-1])
    
            else:
                M = max(dp[k][i-1][j] for k in range(4))
                dp[0][i][j] = max(dp[0][i][j-1], M)
                dp[1][i][j] = dp[1][i][j-1]
                dp[2][i][j] = dp[2][i][j-1]
                dp[3][i][j] = dp[3][i][j-1]
    
    
    ans = max(dp[i][-1][-1] for i in range(4))
    print(ans)
main()

Measured memory_bytes: 446216