akhauriyash/Code-Regression huggingface dataset:
str_n = input()
keta = len(str_n)
not_zero = int(input())

dp = [[[0]*(not_zero+2) for _ in range(2)] for _ in range(keta+1)]
first = int(str_n[0])
dp[1][1][0] = 1
for k in range(1,10):
    if first == k:
        dp[1][0][1] += 1
    elif first > k:
        dp[1][1][1] += 1

for i in range(1,keta):
    # smallerからsmallerへの遷移
    for j in range(not_zero+1):
        # i桁目をゼロにする
        dp[i+1][1][j] += dp[i][1][j]
        # i桁目でゼロ以外を使う
        dp[i+1][1][j+1] += (dp[i][1][j])*9

    nex = int(str_n[i])
    # sameからsmallerへの遷移
    if not nex == 0:
        for j in range(not_zero+1):
            # i桁目をぜろにする
            dp[i+1][1][j] += dp[i][0][j]
            # i桁目でゼロ以外
            dp[i+1][1][j+1] += (dp[i][0][j]) * (nex-1)
    
    # sameからsameへの遷移
    if nex == 0:
        for j in range(not_zero+1):
            dp[i+1][0][j] = dp[i][0][j]
    else:
        for j in range(not_zero):
            dp[i+1][0][j+1] = dp[i][0][j]

print(dp[keta][1][not_zero] + dp[keta][0][not_zero])





Measured memory_bytes: 62824
#include <iostream>

using namespace std;

int main()
{
	int N;
	cin >> N;
	int a[N];
	for(int i=0; i<N; ++i) cin >> a[i];
	
	int ans = 0;
	for(int i=0; i<N; ++i) ans+=a[i]-1;
	cout << ans << endl;
	
	return 0;
}


Measured memory_bytes: 256
N = int(input())
C = [int(input()) for _ in range(N)]

l = sorted([(c, i) for i,c in enumerate(C)])

path = [[i+1] for i in range(N)]

for i in range(len(l)-1):
    if l[i][0] == l[i+1][0] and l[i+1][1]-l[i][1] > 1:
        path[l[i][1]].append(l[i+1][1])

dp = [0 for _ in range(N)]
dp[0] = 1
for i in range(N-1):
    for to in path[i]:
        dp[to] = (dp[to]+dp[i])%1000000007

print(dp[N-1])


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

int main()
{
  string s;
  cin >> s;
  if (s[2] == s[3] && s[4] == s[5])
  {
    cout << "Yes" << endl;
  }
  else
  {
    cout << "No" << endl;
  }
}


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

int main(){
  int N;
  cin >> N;
  for (int i = 0; i < N; i++){
    char S;
    cin >> S;
    if (S == 'Y'){
      cout << "Four" << endl;
      break;
    }
    if (i == N-1){
      cout << "Three" << endl;
    }
  }
  return 0 ;
}

Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;

int f(int x) {
    if (x == 1) {
        return 300000;
    }
    else if (x == 2) {
        return 200000;
    }
    else if (x == 3) {
        return 100000;
    }
    else {
        return 0;
    }
}

int main() {
    int x, y; cin >> x >> y;
    int ans = 0;
    ans += f(x) + f(y);
    if (x == y && x == 1) {
        ans += 400000;
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<string>
#include<limits.h>
#include<algorithm>
#include<cstring>
#include<math.h>
#include<set>
#include<vector>
#include<queue>
#include<set>
#include<stdlib.h>
#include<time.h>
using namespace std;
typedef long long ll;
#define inf	0x3f3f3f3f
typedef pair<int,int>	P;
int n,m;
P arr[10010];
int parent[10010];
int height[10010];
void init(){
	for(int i=1;i<=n;i++){
		parent[i]=i;
	}
	memset(height,0,sizeof(height));
}
int find(int x){
	if(parent[x]==x){
		return x;
	}else{
		return parent[x]=find(parent[x]);
	}
}
void Unit(int x,int y){
	x=find(x);
	y=find(y);
	if(height[x]<height[y]){
		parent[x]=y;
	} else if(height[y]<height[x]){
		parent[y]=x;
	}else{
		parent[x]=y;
		height[y]++;
	}
}
struct Edge{
	int from;
	int to;
	double cost;
	bool operator<(const Edge &y)const{
		return cost<y.cost;
	}
};
double dis(int x,int y){
	return sqrt(pow(arr[x].first-arr[y].first,2)+
			pow(arr[x].second-arr[y].second,2));
}
int main() {
	while(scanf("%d%d",&n,&m)!=EOF){
		init();
		for(int i=1;i<=n;i++){
			scanf("%d%d",&arr[i].first,&arr[i].second);
		}
		int p1,p2;
		priority_queue<Edge>	myQ;
		Edge e;
		for(int i=0;i<m;i++){
			scanf("%d%d",&p1,&p2); 
			e.from=p1;
			e.to=p2;
			e.cost=dis(p1,p2);
			myQ.push(e);
		}
		double sum=0;
		while(!myQ.empty()){
			e=myQ.top();
			myQ.pop();
			if(find(e.from)==find(e.to)){
				sum+=e.cost;
			}else{
				Unit(e.from,e.to);
			}
		}
		printf("%.3f\n",sum);
	}
	
	return 0;
}


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

// definitions
#define f first
#define s second
#define all(x) x.begin(), x.end()
#define clr(x) memset(x, 0, sizeof(x))
#define rep(i, l, r) for (long long i = (l); i < (long long)(r); i++)
#define repb(i, r, l) for (long long i = (r); i > (long long)(l); i--)
#define high(x) __builtin_popcountll(x)
#define pb push_back
#define pf push_front
#define mod1 998244353
#define mod 1000000007
#define MAX_CHAR 256
#define pi 3.1415926535897932384



using namespace std;
typedef vector<long long> vl;
typedef vector<char> vc;
typedef vector<string> vs;
typedef vector< pair<long long, long long> > vp;
typedef vector<tuple<long long , long long , long long> > vtup;
typedef deque <long long> dql;
typedef deque <char> dqc;
typedef long double ld;
typedef long long ll;
typedef unsigned long long ull;

ll INF=1e18;



// prevent collisions in unordered_map
struct custom_hash {
    static uint64_t splitmix64(uint64_t x) {
        x += 0x9e3779b97f4a7c15;
        x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9;
        x = (x ^ (x >> 27)) * 0x94d049bb133111eb;
        return x ^ (x >> 31);
    }

    size_t operator()(uint64_t x) const {
        static const uint64_t FIXED_RANDOM = chrono::steady_clock::now().time_since_epoch().count();
        return splitmix64(x + FIXED_RANDOM);
    }
};

template <class T>
void read(T arr[],ll n) {rep(i,0,n) cin>> arr[i];}

typedef unordered_map <long long, long long, custom_hash> umap;


// standard functions
ll mystoi(string str)
{
    stringstream ss(str);
    ll ans=0;
    ss >> ans;

    return ans;
}

ll exp(ll x, ll ex, ll p) {
    ll ans = 1ll;
    while (ex > 0) {
        if (ex & 1ll) ans = (ans * x)%p;
        ex >>= 1ll;
        x = (x * x)%p;
    }
    return ans;
}

bool sort_cond(const pair<ll,ll> &a, const pair <ll,ll> &b)
{
    return ((a.f-a.s)>(b.f-b.s));
}

// code beigns in main
int main()
{

    #ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
    #endif
    
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    ll t=1;
    // cin >> t;
    while(t--)
    {
        ll n;
        cin >> n;

        ll arr[n];
        rep(i,0,n) cin >> arr[i];

        sort(arr,arr+n);

        ll ans=1;
        bool ok=1;
        ll inf=1e18;
        rep(i,0,n)
        {
            if(arr[i]!=0 && ans>(inf/arr[i]))
            {
                ok=0;
                cout << -1 << endl;
                break;
            }
            ans*=arr[i];
        }
        if(ok)
            cout << ans << endl;
    }
}

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

int main()
{
#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif

	long long int h, n;
	cin >> h >> n;
	long long int ara[n];
	int sum = 0;
	for (int i = 0; i < n; ++i)
	{
		cin >> ara[i];
		if (h >= 0)
		{
			h -= ara[i];
		}
	}
	if (h <= 0)
	{
		cout << "Yes" << endl;
	}
	else
		cout << "No" << endl;
	return 0;
}

Measured memory_bytes: 4324
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i,a,b) for (ll i = (a); i < (b); i++)
#define REP(i,n) rep(i,0,n)

void solve() 
{
    int n;
    cin>>n;
    n%=10;
    if(n==2||n==4||n==5||n==7||n==9){
        cout<<"hon"<<endl;
    }else if(n==0||n==1||n==6||n==8){
        cout<<"pon"<<endl;
    }else cout<<"bon"<<endl;
}

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

Measured memory_bytes: 3608
using System;
using System.Linq;
using System.Collections;
namespace C
{
    class Program
    {
        static void Main(string[] args)
        {
            var foo = Console.ReadLine().Trim().Split(' ');
            var N = int.Parse(foo[0]);
            var M = int.Parse(foo[1]);

            var bar = Console.ReadLine().Trim().Split(' ');
            var H = bar.Select(x=>int.Parse(x)).ToArray();

            var todai = new bool[H.Length];
            for (int i = 0; i < todai.Length; i++)
            {
                todai[i] = true;
            }
            var sumOfWays = new ArrayList();
            while(M>0){
                var ways = (Console.ReadLine().Trim().Split(' ').Select(x=>int.Parse(x))).ToArray();
                var a = ways[0] - 1;
                var b = ways[1] - 1;
                sumOfWays.Add(a);
                sumOfWays.Add(b);
                todai[a] = todai[a] &&  H[a] > H[b];
                todai[b] = todai[b] &&  H[b] > H[a];
                M--;
            }
            Console.WriteLine(todai.Where(x=>x).Count());
            Console.ReadLine();
        }
    }
}


Measured memory_bytes: 40724
const EPS: f64 = 1e-9;

fn main() {
    let (r, w) = (std::io::stdin(), std::io::stdout());
    let mut sc = IO::new(r.lock(), w.lock());
    let n: usize = sc.read();
    let k: usize = sc.read();
    let a: Vec<f64> = sc.vec(n);

    let mut ng = 0.0;
    let mut ok = 1e10;
    for _ in 0..100 {
        let x = (ng + ok) / 2.0;
        if solve(&a, k, x) {
            if x < 1.0 + EPS {
                println!("1");
                return;
            }
            ok = x;
        } else {
            ng = x;
        }
    }

    println!("{}", (((ng + ok) / 2.0).ceil() + EPS) as usize);
}

fn solve(a: &Vec<f64>, k: usize, x: f64) -> bool {
    let n = a.len();
    let mut cut = 0;
    for i in 0..n {
        let a = a[i];
        cut += ((a / x - 1.0).ceil() + EPS) as usize;
    }
    k >= cut
}

pub struct IO<R, W: std::io::Write>(R, std::io::BufWriter<W>);

impl<R: std::io::Read, W: std::io::Write> IO<R, W> {
    pub fn new(r: R, w: W) -> Self {
        Self(r, std::io::BufWriter::new(w))
    }
    pub fn write<S: ToString>(&mut self, s: S) {
        use std::io::Write;
        self.1.write_all(s.to_string().as_bytes()).unwrap();
    }
    pub fn read<T: std::str::FromStr>(&mut self) -> T {
        use std::io::Read;
        let buf = self
            .0
            .by_ref()
            .bytes()
            .map(|b| b.unwrap())
            .skip_while(|&b| b == b' ' || b == b'\n' || b == b'\r' || b == b'\t')
            .take_while(|&b| b != b' ' && b != b'\n' && b != b'\r' && b != b'\t')
            .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: 3976
#include <bits/stdc++.h>
#include <iostream>
#include <algorithm>
#include <cmath>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <string>
using namespace std;
typedef long long int ll;
#define rep(i, n) for (int(i) = 0; (i) < (n); (i)++)

bool isPrime(int x){
    if(x==1)return 0;
    if(x==2)return 1;
    if(x%2==0)return 0;
    for(int i=3;i*i<=x;i++)if(x%i==0)return 0;
    return 1;
}
int main() {
    int a,b,c,d;
    cin >> a >> b >> c >>d;
    while(a>0 || c>0){
        c-=b;
        if(c<=0){
            break;
        }
        a-=d;
    }
    if(a>0 && c<=0){
        cout << "Yes" << endl;
    }else{
        cout << "No" <<endl;
    }
    return 0;
}


Measured memory_bytes: 3592
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for (ll (i)=(0);(i)<(ll)(n);++(i))
typedef pair<int, int> P;
using ll = long long;
 
map< pair<ll, ll>, ll > memo;
const ll mod = 1000000007LL;
 
ll func(ll S, ll X) {
 
    if (S < 0 or X < 0) return 0;
 
    if (S == 0 and X >= 0) {
        return 1;
    }
    else if (S == 1 and X == 0) {
        return 1;
    }
    else if (S == 1 and X > 0) {
        return 2;
    }
 
    if (memo.count({S, X})) {
        return memo[{S, X}];
    }
 
    return memo[{S, X}] = (func(S/2, X/2) + func((S-1)/2, (X-1)/2) + func((S-2)/2, X/2)) % mod;
}
 
int main() {
    ll N;
    cin >> N;
    cout << func(N, N) << endl;
}

Measured memory_bytes: 256
import itertools
import math
def dis(X,Y):
    return ((X[0]-Y[0])**2+(X[1]-Y[1])**2)**.5
def main():
    n=int(input())
    L=[list(map(int,input().split())) for _ in range(n)]
    S=itertools.permutations([i for i in range(1,n+1)])
    ans=0
    for s in S:
        for i in range(n-1):
            a = s[i] - 1
            b = s[i+1] - 1
            ans += dis(L[a],L[b])
    ans /= math.factorial(n)
    print(ans)
main()

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

int main(){
    int A, B, C, N, L;
    A = 101;
    int sum = 0;
    cin >> N >> L;

    for(int i = 0; i < N; i++){
        sum += L+i;
    }
    for(int i = 0; i < N; i++){
        if(abs(L+i) < A){
            B = L+i;
            A = abs(L+i);
        }
    }

    cout << sum - B << endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<map>
#include<algorithm>
#include<cassert>
using namespace std;
using ll = long long;
using P = pair<int, int>;

const int MX = 1000005;
const int mod = 1e9 + 7;

struct mint {
	ll x;
	mint(ll x = 0) :x((x% mod + mod) % mod) {}
	mint operator-() const { return mint(-x); }
	mint& operator+=(const mint a) {
		if ((x += a.x) >= mod)x -= mod;
		return *this;
	}
	mint& operator-=(const mint a) {
		if ((x += mod - a.x) >= mod)x -= mod;
		return *this;
	}
	mint& operator*=(const mint a) {
		(x *= a.x) %= mod;
		return *this;
	}
	mint operator+(const mint a) const {
		mint res(*this);
		return res += a;
	}
	mint operator-(const mint a)const {
		mint res(*this);
		return res -= a;
	}
	mint operator*(const mint a)const {
		mint res(*this);
		return res *= a;
	}
	mint pow(ll t)const {
		if (!t)return 1;
		mint a = pow(t >> 1);
		a *= a;
		if (t & 1)a *= *this;
		return a;
	}

	mint inv() const {
		return pow(mod - 2);
	}
	mint& operator/=(const mint a) {
		return (*this) *= a.inv();
	}
	mint operator/(const mint a) const {
		mint res(*this);
		return res /= a;
	}
};
struct Sieve {
	int n;
	vector<int>f, primes;
	Sieve(int n = 1) :n(n), f(n) {
		f[0] = f[1] = -1;
		for (ll i = 2; i <= n; i++) {
			if (f[i])continue;
			primes.push_back(i);
			f[i] = i;
			for (ll j = i + i; j <= n; j += i) {
				if (!f[j])f[j] = i;
			}
		}
	}
	bool isPrime(int x) { return f[x] == x; }
	vector<int>factorList(int x) {
		vector<int>res;
		while (x != 1) {
			res.push_back(f[x]);
			x /= f[x];
		}
		return res;
	}
	vector<P>factor(int x) {
		vector<int>fl = factorList(x);
		if (fl.size() == 0)return {};
		vector<P>res(1, P(fl[0], 0));
		for (int p : fl) {
			if (res.back().first == p) {
				res.back().second++;
			}
			else {
				res.emplace_back(p, 1);
			}
		}
		return res;
	}
};

int main() {
	Sieve sieve(1e6);
	int n; cin >> n;
	vector<int>a(n);
	for (auto&& x : a)cin >> x;
	map<int, int>mp;
	for (int i = 0; i < n; i++) {
		auto f = sieve.factor(a[i]);
		for (auto&& p : f) {
			mp[p.first] = max(mp[p.first], p.second);
		}
	}
	mint lcm = 1;
	for (auto&& p : mp) {
		for (int i = 0; i < p.second; i++) {
			lcm *= p.first;
		}
	}
	mint ans;
	for (int i = 0; i < n; i++) {
		mint b = lcm / a[i];
		ans += b;
	}
	cout << ans.x << endl;
	return 0;
}

Measured memory_bytes: 4984
//#pragma GCC optimize("Ofast")
//#pragma GCC optimize("unroll-loops")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using db = double;
using ld = long double;
template<typename T> using V = vector<T>;
template<typename T> using VV = vector<vector<T>>;
#define fs first
#define sc second
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define eb emplace_back
#define lb lower_bound
#define ub upper_bound
#define all(v) (v).begin(),(v).end()
#define siz(v) (ll)(v).size()
#define rep(i,a,n) for(ll i=a;i<(ll)(n);++i)
#define repr(i,a,n) for(ll i=n-1;(ll)a<=i;--i)
#define ENDL '\n'
typedef pair<int,int> Pi;
typedef pair<ll,ll> PL;
constexpr ll mod = 1000000007;
constexpr ll INF = 1000000099;
constexpr ll LINF = (ll)(1e18 +99);
const vector<ll> dx={-1,1,0,0},dy={0,0,-1,1};
template<typename T,typename U> inline bool chmin(T& t, const U& u){if(t>u){t=u;return 1;}return 0;}
template<typename T,typename U> inline bool chmax(T& t, const U& u){if(t<u){t=u;return 1;}return 0;}
template<typename T> inline T gcd(T a,T b){return b?gcd(b,a%b):a;}
template<typename T,typename Y> inline T mpow(T a, Y n) {
  T res = 1;
  for(;n;n>>=1) {
    if (n & 1) res = res * a;
    a = a * a;
  }
  return res;
}


signed main(){
  cin.tie(0);ios::sync_with_stdio(false);
  cout<<fixed<<setprecision(20);
  ll n;cin>>n;
  V<ll> a(n),b(n);
  rep(i,0,n)cin>>a[i];
  rep(i,0,n)cin>>b[i];


  ll ans=0;
  rep(i,0,30){
    V<ll> u(n);
    rep(j,0,n){
      u[j]=b[j]%(1ll<<(i+1));
    }

    sort(all(u));

    ll ocnt=0;
    rep(j,0,n){
      auto l=lb(u.begin(),u.end(),(1ll<<i)-(a[j]%(1ll<<(i+1))));
      auto r=lb(u.begin(),u.end(),(1ll<<(i+1))-(a[j]%(1ll<<(i+1))));
      ocnt+=distance(l,r);

      l=lb(u.begin(),u.end(),(1ll<<i)+(1ll<<(i+1))-(a[j]%(1ll<<(i+1))));
      r=lb(u.begin(),u.end(),(1ll<<(i+2))-1-(a[j]%(1ll<<(i+1))));
      ocnt+=distance(l,r);
    }

    if(ocnt%2)ans+=(1<<i);
    //cerr<<ans<<ENDL;
  }

  cout<<ans<<ENDL;
}
//! ( . _ . ) ! 
//CHECK overflow,vector_size,what to output?

Measured memory_bytes: 4992
import itertools

N = int(input())
P = list(input().split())
Q = list(input().split())
p = itertools.permutations(P)

P = int(''.join(P))
Q = int(''.join(Q))

a = 0
b = 0
for v in p:
    if P >= int(''.join(v)): a += 1
    if Q >= int(''.join(v)): b += 1
print(abs(a - b))

Measured memory_bytes: 3064
#include<stdio.h>
#include<string.h>
using namespace std;
typedef long long int ll;
int main()
{
    ll n,k,a[1000]={0},d[1000],vis[1000]={0},cnt=1,flag=0;
    int p;
    scanf("%lld%lld",&n,&k);
    ll z=n;
    int i,j;
    for(i=1;i<=k;i++)
    {
        scanf("%d",&d[i]);
        vis[d[i]]=1;
    }
    for(i=0;i<=10;i++)
    {
        if(vis[i]==0)
        {
            p=i;
            break;
        }
    }
    while(n)
    {
        a[cnt++]=n%10;
        n=n/10;
    }
    for(i=cnt-1;i>=1;i--)
    {
        // printf("!\n");
        if(vis[a[i]]==1)
        {
            while(vis[a[i]]==1)
            {
         //       printf("!\n");
                a[i]=a[i]+1;
                if(a[i]==10)
                {
                    a[i]=p;
                    i=i+1;
                    a[i]=a[i]+1;
                }
                if(i==cnt)
                {
                    a[i]=1;
                    while(vis[a[i]]==1)
                    {
                        a[i]=a[i]+1;
                    }
                    printf("%lld",a[cnt]);
                    for(j=cnt-1;j>=1;j--)
                        printf("%d",p);
                    printf("\n");
                    return 0;
                }
            }
            k=i;
            for(j=cnt-1;j>=1;j--)
            {
                if(j>=k)
                    printf("%lld",a[i]);
                else
                    printf("%d",p);
                if(j==1)
                    return 0;
 
            }
        }
 
    }
    printf("%lld\n",z);
    return 0;
}


Measured memory_bytes: 128
#include <bits/stdc++.h>
#define rep(i,n) for(int (i)=0;(i)<(n);++(i))
#define all(x) (x).begin(),(x).end()
#define dump(x) cout << #x << " = " << (x) << endl
#define YES(n) cout << ((n) ? "YES" : "NO") << endl
#define Yes(n) cout << ((n) ? "Yes" : "No") << endl
#define yes(n) cout << ((n) ? "yes" : "no") << endl

using namespace std;
using ll = long long;
using P = pair<int, int>;

const int INF = 1001001001;
const vector<int> di = {-1,  0, 1, 0};
const vector<int> dj = { 0, -1, 0, 1};

void chmin(int &a, int b) { if (a > b) a = b; }

ll GCD(ll a, ll b) {
    if (b == 0) return a;
    else return GCD(b, a % b);
}
ll LCM(ll a, ll b) {
    ll g = GCD(a, b);
    return a / g * b;
}


int main(){
    int a, b, c, d, e, f;
    cin >> a >> b >> c >> d >> e >> f;
    a *= 100;
    b *= 100;

    int tot=a;
    int sug=0;
    for(int i1=0;i1<=100;i1++) for(int i2=0;i2<=100;i2++) for(int i3=0;i3<=100;i3++) for(int i4=0;i4<=100;i4++){
        int totwat = i1 * a + i2 * b;
        int totsug = i3 * c + i4 * d;
        if (totwat + totsug <= f) {
            if (totsug * 100 <= totwat * e) {
                if(sug * (totsug + totwat) <= tot * totsug) {
                    sug = totsug;
                    tot = totwat + totsug;
                }
            }
        }
    }
    cout << tot << " " << sug << endl;
}

Measured memory_bytes: 256
#include <vector>
#include <list>
#include <map>
#include <set>
#include "queue"
#include <deque>
#include <stack>
#include <numeric>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <complex>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <cstring>
#include <climits>
#include <cassert>
#include <iostream>
using namespace std;
#define MOD 1000000007
#define MODSET(d) if ((d) >= MOD) d %= MOD;
#define MODNEGATIVESET(d) if ((d) < 0) d = (d % MOD + MOD) % MOD;
#define pii pair<long long ,long long >
#define ll  long long int
#define loop(i,n) for(ll i=0;i<n;i++)
#define loop2(i,n) for(ll i = 1;i<=n;i+=1)
#define pb push_back
#define mp make_pair
#define EPS 1e-7
using namespace std;
// JAI SHREE KRISHNA
//Winning is my right
//I.W.T.D.I.F.M.F
int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    
    ll n,x;
    cin>>n>>x;
    ll arr[n];
    loop(i,n)
    {
        cin>>arr[i];
    }
    ll ans  = 0;
    for(ll  j =1;j<=n-1;j+=1)
    {
    
        if(arr[j-1]+arr[j]>x)
        {
            ll difftobemade = (arr[j]+arr[j-1])-x;
            if(difftobemade>arr[j])
            {
                ans+=arr[j];
                difftobemade-=arr[j];
                arr[j] = 0 ;
                ans+=difftobemade;
                arr[j-1]-=difftobemade;
            }
            else{
                arr[j]-=difftobemade;
                ans+=difftobemade;
            }
        }
        
    }
    cout<<ans;
        return 0;
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define fr(i,s,e) for(int i=s;i<e;i++)

int main(){
    int i,c=0,flag=1;
    string s;
    cin>>s;
    fr(i,0,s.length()){
        if(s[0]!='A'){
            flag=0;
            break;
        }
        if(i>=2&&i<=s.length()-2){
        	
            if(s[i]=='C')
                c++;
                if(c>1){
                flag=0;
                break;}
        }
        else if(i>0&&(s[i]<'a'||s[i]>'z'))
            {flag=0;break;}
    }
if(c==0) flag=0;
if(flag==1)
    cout<<"AC";
else cout<<"WA";
return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define FOR(i, a, b) for(int i=(a);i<(b);++i)
#define rep(i, n) FOR(i, 0, n)
#define rrep(i, n) for (int i = ((int)(n)-1); i >= 0; --i)
#define whole(x) (x).begin(),(x).end()
#define UNIQUE(v) v.erase(unique(v.begin(), v.end()), v.end())
using P = pair<int, int>;
#define debug(var) cerr << "[" << #var << "] " << var << endl
#define chmin(x, y) x = min(x, y)
#define chmax(x, y) x = max(x, y)
const ll mod = 1000000007;
const int dx[] = {-1,0,1,0};
const int dy[] = {0,-1,0,1};


int main(){
    int h, w, k;
    cin >> h >> w >> k;
    vector<string> c(h);
    rep(i, h) cin >> c[i];
    int ans = 0;
    rep(i, 1<<h) rep(j, 1<<w) {
        int nb = 0;
        rep(ii, h) rep(jj, w) {
            if ((i>>ii&1) || (j>>jj&1)) {
                continue;
            }
            if (c[ii][jj]=='#') nb++;
        }
        if (nb==k) ans++;
    }
    
    
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 3624
from collections import Counter

n = int(input())
v = [int(i) for i in input().split()]

ki = v[::2]
gu = v[1::2]

ki = Counter(ki)
gu = Counter(gu)

ki = ki.most_common()
gu = gu.most_common()

ans = 0

if ki[0][0] == gu[0][0]:
    if len(ki) == 1 and len(gu) == 1:
        ans = int(n / 2)
    else:
        if ki[1][1] > gu[1][1]:
            ans = n - ki[1][1] - gu[0][1]
        else:
            ans = n - ki[0][1] - gu[1][1]
else:
    ans = n - ki[0][1] - gu[0][1]

print(ans)



Measured memory_bytes: 18776
////////////////////////////////////////////////////////////////////
// This source code is for Visual Studio
////////////////////////////////////////////////////////////////////
#include <iostream>
#include <string>
#include <vector>
#include <list>
#include <queue>
#include <map>
#include <set>
#include <algorithm>
#include <sstream>
#include <iterator>
#include <stack>
#include <functional>
#include <iomanip>
#include <string>
#include <cstring>
#include <deque>
#include <math.h>

#define	numberof(a)	(sizeof(a) / sizeof(a[0]))
#define	INF		UINT64_MAX
#define Rep(i,n) for(int i = 0; i < (n); ++i )

using namespace std;

typedef vector< vector<int> > MAT;
typedef pair<int, int> PINT;
typedef long long ll;
typedef uint32_t u32;
typedef uint64_t u64;
typedef int32_t s32;
typedef int64_t s64;

int main()
{
	string SS = "";
	string T = "";
	string ret = "";
	bool isChangeable = false;

	cin >> SS;
	cin >> T;
	ll len = SS.length();

	// write here
	for (int i = len - 1; i >= 0; --i )
	{
		{	// 1文字含む
			// check
			ll tmp_len = T.length();
			if (len - i >= tmp_len) {
				string tmp = SS.substr(i, tmp_len);

				// judge
				isChangeable = true;
				for (int j = 0; j < tmp_len; ++j ) {
					if ( !(T[j] == tmp[j] || '?' == tmp[j]) ) {
						isChangeable = false;
						break;
					}
				}

				if (isChangeable) {
					memcpy(((char*)SS.c_str() + i), T.c_str(), tmp_len);
				}
			}
		}

		if (isChangeable) break;
	}
	Rep(i, len) {
		if (SS[i] == '?') {
			SS[i] = 'a';
		}
	}

	if (isChangeable) {
		ret = SS;
	}
	else {
		ret = "UNRESTORABLE";
	}

	cout << ret << endl;

	return 0;
}





Measured memory_bytes: 256
import sys
inputs = sys.stdin.readlines()

n = int(inputs[0])
s = inputs[1].rstrip()
p, c = 0, 0
while True:
    idx = s.find('ABC')
    if idx == -1:
        break
    else:
        s = s[idx+3:]
        c += 1
print(c)

Measured memory_bytes: 3060
import java.util.Scanner;

public class Main {
	private static final int K = 26;
	private static final int COUNT = 1000000;

	public static void main(String[] args) {
		var sc = new Scanner(System.in);
		var d = sc.nextInt();
		var c = new int[K];
		var s = new int[d][K];
		for (var i = 0; i < K; i++) {
			c[i] = sc.nextInt();
		}
		for (var i = 0; i < d; i++) {
			for (var j = 0; j < K; j++) {
				s[i][j] = sc.nextInt();
			}
		}
		sc.close();

		var count = 0;
		var t = create(c, s, d);
		for (var i = 0; count < COUNT; i++) {
			for (var j = 1; j < K; j++) {
				count++;
				var mdi = i % d;
				var mti = (t[mdi] + j - 1) % K;
				var check = check(c, s, t, d, mdi, mti);
				if (check > 0) {
					t[mdi] = mti + 1;
				}
			}
		}

		for (var i = 0; i < d; i++) {
			System.out.println(t[i]);
		}
		//System.out.println(score(c, s, t, d));
	}

	private static int check(int[] c, int[][] s, int[] t, int d, int mdi, int mti) {
		var sum = 0;
		var ti = t[mdi] - 1;
		sum += s[mdi][mti] - s[mdi][ti];

		var last1 = 0;
		var last2 = 0;
		for (var i = mdi - 1; i >= 0; i--) {
			if (t[i] == ti + 1) {
				last1 = i + 1;
				break;
			}
		}
		for (var i = mdi - 1; i >= 0; i--) {
			if (t[i] == mti + 1) {
				last2 = i + 1;
				break;
			}
		}

		var count1 = 1;
		var count2 = 1;
		for (var i = mdi + 1; i < d; i++) {
			if (t[i] == ti + 1) {
				break;
			}
			count1++;
		}
		for (var i = mdi + 1; i < d; i++) {
			if (t[i] == mti + 1) {
				break;
			}
			count2++;
		}
		sum += (mdi - last2 + 1) * c[mti] * count2 - (mdi - last1 + 1) * c[ti] * count1;
		return sum;
	}

	private static int score(int[] c, int[][] s, int[] t, int d) {
		var sum = 0;
		var last = new int[K];
		for (var i = 0; i < d; i++) {
			var ti = t[i] - 1;
			sum += s[i][ti];
			last[ti] = i + 1;
			for (var j = 0; j < K; j++) {
				sum -= ((i + 1) - last[j]) * c[j];
			}
		}

		return sum;
	}

	private static int[] create(int[] c, int[][] s, int d) {
		var t = new int[d];
		for (var i = 0; i < d; i++) {
			t[i] = 1;
		}
		return t;
	}
}


Measured memory_bytes: 46840
#include<iostream>
#include<algorithm>

#define S 100000

long h[S];
long N, A, B;

int input(){
	std::cin >> N >> A >> B;
	for( int i = 0; i < N; i++ ){
		std::cin >> h[i];
	}
	std::sort(&h[0], &h[N], std::greater<long>());
	return 0;
}

int search(long T){
	long sum = 0;
	for( int i = 0; i < N; i++ ){
		long t = (h[i]-B*T);
		if( t < 0 ){ continue; }
		long k = (t%(A-B)==0?t/(A-B):t/(A-B)+1);
		sum += k;
	}
	if( sum <= T ){ return 1; }
	return 0;
}

int run(){
	long s = 0;
	long e = h[0] / B + 10;
	do{
		long T = (s+e) / 2;
		int re = search(T);
		if( re ){
			e = T;
		}else{
			s = T;
		}
	}while( s + 1 < e );
	std::cout << e << std::endl;
	return 0;
}

int main(){
	input();
	run();
	return 0;
}


Measured memory_bytes: 1024
#include <stdio.h>
#include <iostream>
#include <vector>
#include <queue>
#include <stack>
#include <algorithm>

using ll = long long int;
const int INF = (1<<30);
const ll INFLL = (1ll<<60);
const ll MOD = (ll)(1e9+7);

#define l_ength size

void mul_mod(ll& a, ll b){
	a *= b;
	a %= MOD;
}

void add_mod(ll& a, ll b){
	a = (a<MOD)?a:(a-MOD);
	b = (b<MOD)?b:(b-MOD);
	a += b;
	a = (a<MOD)?a:(a-MOD);
}

int main(void){
	int i,n,l,r,ans=0,tmp=INF,x=0,y=0,z=0,w=0;
	std::string s;
	std::cin >> n;
	std::cin >> s;
	l = 0; r = n-1;
	while(l<r){
		if(s[l]=='R'){
			++l;
		}else if(s[r]=='W'){
			--r;
		}else{
			std::swap(s[l],s[r]);
			++l; --r;
			++ans;
		}
	}
	for(i=0; i<n; ++i){
		if(s[i]=='R'){
			++x;
		}else{
			++y;
		}
	}
	if(x==n || y==n){
		std::cout << 0 << std::endl;
		return 0;
	}
	for(i=0; i<n; ++i){
		if(s[i]=='R'){
			++z;
		}else{
			++w;
		}
		tmp = std::min(tmp,w+(x-z));
	}
	std::cout << ans+tmp << std::endl;
	return 0;
}


Measured memory_bytes: 3756
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
int main(){
  int S,W;
  cin>>S>>W;
  if(W>=S){
    cout<<"unsafe"<<endl;
  }
  else{
    cout<<"safe"<<endl;
  }
}

Measured memory_bytes: 3628
#include <iostream>
#include <memory>

#define NIL nullptr

struct Node {
  int key;
  Node *parent, *left, *right;

  Node(int key) : key(key) { parent = left = right = NIL; }
  ~Node() {
    if (right != NIL)
      delete right;
    if (left != NIL)
      delete left;
  }
};

Node *getRoot(Node *t) {
  Node *n = t;
  while (t->parent != NIL) {
    n = n->parent;
  }
  return n;
}

void insert(Node *t, Node *z) {
  Node *root = getRoot(t);
  Node *y = NIL;
  Node *x = root;
  while (x != NIL) {
    y = x;
    if (z->key < x->key)
      x = x->left;
    else
      x = x->right;
  }
  z->parent = y;

  if (y == NIL)
    root = z;
  else if (z->key < y->key)
    y->left = z;
  else
    y->right = z;
}

void printInorder(Node *t) {
  if (t != NIL) {
    printInorder(t->left);
    std::cout << " " << t->key;
    printInorder(t->right);
  }
}

void printPreorder(Node *t) {
  if (t != NIL) {
    std::cout << " " << t->key;
    printPreorder(t->left);
    printPreorder(t->right);
  }
}

Node *find(Node *t, int k) {
  if (t != NIL) {
    if (t->key == k)
      return t;
    if (t->key > k)
      return find(t->left, k);
    else
      return find(t->right, k);
  }
  return NIL;
}

Node *getMinimum(Node *x) {
  while (x->left != NIL) {
    x = x->left;
  }
  return x;
}

Node *getSuccessor(Node *x) {
  if (x->right != NIL)
    return getMinimum(x->right);

  Node *y = x->parent;
  while (y != NIL && x == y->right) {
    x = y;
    y = y->parent;
  }
  return y;
}

void del(Node *t, Node *z) {
  Node *x, *y, *root = getRoot(t);
  // 削除する対象を接点yする
  if (z->left == NIL || z->right == NIL)
    y = z; // zがコを持たないか子を1つしか持たない場合は入力接点のz
  else
    y = getSuccessor(z); // zが子を2つ保つ場合はzの次点

  // yの子xを決める
  if (y->left != NIL)
    x = y->left; // yに左の子がいればxはyの左の子
  else
    x = y->right; // yに左の子がいなければ右の子

  if (x != NIL)
    x->parent = y->parent;

  if (y->parent == NIL)
    root = x;
  else if (y == y->parent->left)
    y->parent->left = x;
  else
    y->parent->right = x;

  if (y != z)
    z->key = y->key;
}

int main() {
  int n, k;
  std::cin >> n;
  std::string cmd;
  Node *t = NIL;

  for (int i = 0; i < n; ++i) {
    std::cin >> cmd;
    switch (cmd.at(0)) {

    case 'i':
      std::cin >> k;
      if (t == NIL)
        t = new Node(k);
      else
        insert(t, new Node(k));
      break;

    case 'f':
      std::cin >> k;
      std::cout << (find(t, k) != NIL ? "yes" : "no") << std::endl;
      break;

    case 'd':
      std::cin >> k;
      del(t, find(t, k));
      break;

    case 'p':
      printInorder(getRoot(t));
      std::cout << std::endl;
      printPreorder(getRoot(t));
      std::cout << std::endl;
      break;
    }
  }
}



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

int main() {
    int N;
    cin >> N;
    vector<int64_t> A(N);

    for (int i = 0; i < N; i++) {
        cin >> A.at(i);
    }

    int zero = 0;

    for (int i = 0; i < N; i++) {
        if (A.at(i) == 0) zero++;

        if (0 < zero) {
            cout << "0" << endl;
            return 0;
        }
    }

    int64_t ans = 1;

    for (int i = 0; i < N; i++) {
        if (A.at(i) <= 1000000000000000000/ans) {
            ans *= A.at(i);
        }
        else {
            cout << "-1" << endl;
            return 0;
        }
    }

    cout << ans << endl;
}

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

int main(){
  int n,i,a,wa=0,nijo=0;
  cin>>n;
  for(i=0;i<n;i++){
    cin>>a;
    wa+=a;
    nijo+=a*a;
  }
  cout<<(wa*wa-nijo)/2;
}


Measured memory_bytes: 256
N,M = [ int(it) for it in input().split() ]
li = [ [ int(it) for it in input().split() ] for i in range(N) ]

#ppp

import itertools as ite
sm = 0
for p,q,r in ite.product( *([[-1,1]]*3) ):
  
  gi = [ p*it[0]+q*it[1]+r*it[2] for it in li ]
  if (True):
    gi.sort()
    gi.reverse()
    sss= sum(gi[:M]) 
    sm = max(sss,sm)
print (sm)

Measured memory_bytes: 40176
#include <iostream>
#include <algorithm>
#include <vector>
#include <unordered_map>
#include <unordered_set>
#include <set>
#include <queue>
#include <cmath>
#include <cstdio>

using namespace std;

int main(){
    int n; cin >> n;
    vector<int> as(n);
    for(int i=0; i<n; ++i){
        cin >> as[i];
    }
    sort(as.begin(), as.end());
    cout << as[n-1]-as[0] << endl;
    return 0;
}


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

// 
int main() {
    long long A, B;
    cin >> A >> B;
    long long minNum = min(A, B);
    long long i = 1;
    while ((minNum * i) % A != 0 || (minNum * i) % B != 0) {
        i++;
    }
    cout << minNum * i;
}


Measured memory_bytes: 3624
import java.util.Scanner;


public class Main{

	public static void main(String args[]){

		Scanner sc = new Scanner(System.in);

		int n =sc.nextInt();
		String s=sc.next();
		int k=sc.nextInt();
		char c[]=new char[n];

		for(int i=0;i<n;++i){
			if(s.charAt(k-1)==s.charAt(i))c[i]=s.charAt(k-1);
			else c[i]='*';
			System.out.print(c[i]);
		}
		System.out.println();


	}
}

Measured memory_bytes: 21844
#include <stdio.h>
 
int main(void) {
 
int m,f,r;

	while(1){
	scanf("%d %d %d",&m,&f,&r);
 
	if(m==-1 && f==-1 && r==-1)
					 break;
		else if(m==-1 || f==-1)
 			printf("F\n");
		else if(m+f >= 80)
 			printf("A\n");
		else if(65 <= m+f && m+f < 80)
			 printf("B\n");
		else if((50 <= m+f && m+f < 65) || r >= 50)
 			printf("C\n");
		else if(30 <= m+f && m+f < 50)
 			printf("D\n");
		else if(m+f < 30)
 			printf("F\n");
		}
 
    return 0;
}

Measured memory_bytes: 584
S = gets.chomp

def month? str
  (1..12).include? str.to_i
end

if month? S[0..1]
  puts (month? S[2..3]) ? 'AMBIGUOUS' : 'MMYY'
else
  puts (month? S[2..3]) ? 'YYMM' : 'NA'
end

Measured memory_bytes: 1788
#include<bits/stdc++.h>
using namespace std;
int main(){
    int n;
    int ans=0;
    for(int i=0;i<3;i++){
        scanf("%d",&n);
        ans*=10;
        ans+=n;
    }
    if(ans%4)
        printf("NO\n");
    else
        printf("YES\n");

}


Measured memory_bytes: 256
#include <bits/stdc++.h>
 
#define loop(n, i) for(int i=0;i<n;i++)
#define all(v) v.begin(),v.end()
#define HERE cout << "HERE: " << __LINE__ << endl;
#define INSP(v) cout << v << " at " << __LINE__ << endl;

using namespace std;
typedef long long ll;

ll dp[101][65536];
int main()
{
    while (1) {
        fill(dp[0], dp[100]+65536, 0);

        int n; cin >> n;
        if (!n) break;
        vector<ll> L(n);
        vector<vector<int>> S, E;
        loop (n, i) {
            int m; cin >> m >> L[i];
            vector<int> s(m), e(m);
            loop (m, j) cin >> s[j] >> e[j];
            S.push_back(s);
            E.push_back(e);
        }

        loop (n, i) {
            int mask = 0;
            loop (S[i].size(), k) {
                for (int l = S[i][k]; l < E[i][k]; l++) {
                    mask ^= (1<<(l-6));
                }
            }
            loop (1<<16, j) {
                dp[i+1][j] = max(dp[i+1][j], dp[i][j]);
                if ((j & mask) == 0) {
                    dp[i+1][j^mask] = max(
                            dp[i+1][j^mask],
                            dp[i][j] + L[i]
                            );
                }
            }
        }

        ll ans = 0;
        loop (1<<16, i) ans = max(ans, dp[n][i]);
        cout << ans << endl;
    }
    return 0;
}

Measured memory_bytes: 54884
def main():
    N = int(input())
    W = list(map(int, input().split(" ")))
    diff = 10000000
    for T in range(1, N):
        a = W[:T]
        b = W[T:]
        diff = min(diff, abs(sum(a) - sum(b)))
    print(diff)


if __name__ == '__main__':
    main()

Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
/*#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
template<typename T> using gpp_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
template<typename T, typename L> using gpp_map = tree<T, L, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
template<typename T> using gpp_multiset = tree<T, null_type, less_equal<T>, rb_tree_tag, tree_order_statistics_node_update>;*/
struct fast_ios { fast_ios(){ cin.tie(0); ios::sync_with_stdio(false); cout << fixed << setprecision(20); }; } fast_ios_;
#define FOR(i, begin, end) for(int i=(begin);i<(end);i++)
#define REP(i, n) FOR(i,0,n)
#define IFOR(i, begin, end) for(int i=(end)-1;i>=(begin);i--)
#define IREP(i, n) IFOR(i,0,n)
#define Sort(v) sort(v.begin(), v.end())
#define Reverse(v) reverse(v.begin(), v.end())
#define all(v) v.begin(),v.end()
#define SZ(v) ((int)v.size())
#define Lower_bound(v, x) distance(v.begin(), lower_bound(v.begin(), v.end(), x))
#define Upper_bound(v, x) distance(v.begin(), upper_bound(v.begin(), v.end(), x))
#define Max(a, b) a = max(a, b)
#define Min(a, b) a = min(a, b)
#define bit(n) (1LL<<(n))
#define bit_exist(x, n) ((x >> n) & 1)
#define debug(x) cout << #x << "=" << x << endl;
#define vdebug(v) { cout << #v << "=" << endl; REP(i_debug, v.size()){ cout << v[i_debug] << ","; } cout << endl; }
#define mdebug(m) { cout << #m << "=" << endl; REP(i_debug, m.size()){ REP(j_debug, m[i_debug].size()){ cout << m[i_debug][j_debug] << ","; } cout << endl;} }
#define Return(ans) { cout << (ans) << endl; return 0; }
#define pb push_back
#define f first
#define s second
#define int long long
#define INF 1000000000000000000
template<typename T> istream &operator>>(istream &is, vector<T> &v){ for (auto &x : v) is >> x; return is; }
template<typename T> ostream &operator<<(ostream &os, vector<T> &v){ for(int i = 0; i < v.size(); i++) { cout << v[i]; if(i != v.size() - 1) cout << endl; }; return os; }
template<typename T1, typename T2> ostream &operator<<(ostream &os, pair<T1, T2> p){ cout << '(' << p.first << ',' << p.second << ')'; return os; }
template<typename T> void Out(T x) { cout << x << endl; }
template<typename T1, typename T2> void Ans(bool f, T1 y, T2 n) { if(f) Out(y); else Out(n); }
 
using vec = vector<int>;
using mat = vector<vec>;
using Pii = pair<int, int>;
using PiP = pair<int, Pii>;
using PPi = pair<Pii, int>;
using bools = vector<bool>;
using pairs = vector<Pii>;
 
//int dx[4] = {1,0,-1,0};
//int dy[4] = {0,1,0,-1};
//char d[4] = {'D','R','U','L'};
 
const int mod = 1000000007;
//const int mod = 998244353;
//#define Add(x, y) x = (x + (y)) % mod
//#define Mult(x, y) x = (x * (y)) % mod


#include <bits/stdc++.h>
using namespace std;
signed main(){
    int N; cin>>N;
    vector<int> A(N-1);
    REP(i,N-1) cin>>A[i];
    vec ans(N,0);
    for(int i=0; i<N-1; i++){
      ans[A[i]-1] ++;
    }
    REP(i,N) cout<<ans[i]<<endl; 
}

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

using namespace std;
int n;
long out = 1;
int main() {
    cin >> n;
    for (int i = 1; i < n + 1;i++) {
        out *= i;
        out = out % ((int) pow(10.0, 9.0) + 7);
    }
    cout << out << endl;
    return 0;
}

Measured memory_bytes: 256
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time, copy

sys.setrecursionlimit(10**7)
inf = 10**20
mod = 10**9 + 7

stdin = sys.stdin

ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
ns = lambda: stdin.readline().rstrip()  # ignore trailing spaces


def cmb(n, r, mod):
    if ( r<0 or r>n ):
        return 0
    r = min(r, n-r)
    return g1[n] * g2[r] * g2[n-r] % mod

mod = 10**9+7 #出力の制限
N = 10**4
g1 = [1, 1] # 元テーブル
g2 = [1, 1] #逆元テーブル
inverse = [0, 1] #逆元テーブル計算用テーブル

for i in range( 2, N + 1 ):
    g1.append( ( g1[-1] * i ) % mod )
    inverse.append( ( -inverse[mod % i] * (mod//i) ) % mod )
    g2.append( (g2[-1] * inverse[-1]) % mod )


s = ni()
m = s // 3
ans = 0
for i in range(1, m+1):
    num = s - i * 3
    ans += cmb(num+i-1, i-1, mod)
    ans %= mod
print(ans)

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

int main() {
	int a,b;cin>>a>>b;
	for(int i=1;i<=10000;i++){
		if(floor(i*0.08)==a){
			if(floor(i*0.1)==b){
				cout<<i<<endl;
				return 0;
			}
		}
	}
	cout<<-1<<endl;
	return 0;
}


Measured memory_bytes: 256
N,X = gets.split.map(&:to_i)
MEMO = []
def content(n)
  return MEMO[n] unless MEMO[n].nil?
  if n == 0
    [1, 0]
  else
    before = content(n-1)
    value = [before[0]*2 + 1, before[1]*2 + 2]
    MEMO[n] = value
    value
  end
end

# P
# B P P P B
# B BPPPB P BPPPB B
# B BBPPPBPBPPPBB P BBPPPBPBPPPBB B
# returns number of P
def burger(n, x)
  burger_content = content(n)
  # puts "burger(#{n}, #{x}), #{burger_content.to_s}"
  burger_size = burger_content.inject(:+)
  half = (burger_size+1) / 2
  if n == 0
    1
  elsif x <= 1
    0
  elsif x < half
    burger(n-1, x-1)
  elsif x == half
    burger(n-1, x-2) + 1
  elsif x < burger_size
    burger(n-1, half-2) + burger(n-1, x-half) + 1
  elsif x == burger_size
    burger_content[0]
  else
    puts "Failed burger(#{n}, #{x})"
  end
end

puts burger(N, X)


Measured memory_bytes: 1916
#include <iostream>
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <queue>
#include <stack>
#include <vector>
#include <algorithm>
#include <map>
#include <set>
#include <deque>

int main()
{

    int n, x, y;

    scanf("%d", &n);
    scanf("%d", &x);
    scanf("%d", &y);

    std::vector<std::vector<int>> graph(n);
    std::vector<int> ans(n - 1, 0);

    for (int i = 0; i < n - 1; i++)
    {
        graph[i].push_back(i + 1);
        graph[i + 1].push_back(i);
    }

    graph[x - 1].push_back(y - 1);
    graph[y - 1].push_back(x - 1);

    for (int i = 0; i < n; i++)
    {
        std::vector<int> seen(n, 0);
        std::deque<std::pair<int, int>> q;

        q.push_back(std::make_pair(i, 0));
        seen[i] = 1;

        while (!q.empty())
        {
            auto cur = q.front();
            q.pop_front();

            int cur_step = cur.second;

            if (cur_step != 0)
            {
                ans[cur_step - 1]++;
            }

            for (auto next = graph[cur.first].begin(); next != graph[cur.first].end(); next++)
            {
                if (!seen[*next])
                {
                    q.push_back(std::make_pair(*next, cur_step + 1));
                    seen[*next] = 1;
                }
            }
        }
    }

    for (int i = 0; i < n - 1; i++)
    {
        printf("%d\n", ans[i] / 2);
    }
}


Measured memory_bytes: 384
#include <iostream>
#include <cstdio>
#include <cmath>
#include <algorithm>
#include<cstring>
#include<string>
#include<cctype>
#include<cstdlib>
#include<map>
#include<ctime>
#define debuglog(x) cerr<<"\tdebug:"<<#x<<endl
#define debug(x) cerr<<"\tdebug:"<<#x<<"="<<(x)<<endl
#define debugg(x,y) cerr<<"\tdebug;"<<(x)<<":"<<#y<<"="<<(y)<<endl
#define debugzu(x,a,b) 	cerr<<"\tdebug:"<<#x<<"=\n\t";for(int i=a;i<b;i++)cerr<<x[i]<<" ";fprintf(stderr,"\n");
#define debugerzu(x,a,b,c,d) 	cerr<<"\tdebug:"<<#x<<"=\n\t";for(int i=a;i<b;i++,fprintf(stderr,"\n\t"))for(int j=c;j<d;j++)cerr<<x[i][j]<<" ";fprintf(stderr,"\n");
#define R register
#define L long
#define LL long long
#define I inline
#define U unsigned
#define START clock_t __start=clock();
#define STOP fprintf(stderr,"\n\nUse Time:%fs\n",((double)(clock()-__start)/CLOCKS_PER_SEC));
using namespace std;
I LL read()
{
	R LL x;R bool f;R char c;
	for (f=0; (c=getchar())<'0'||c>'9'; f=c=='-');
	for (x=c-'0'; (c=getchar())>='0'&&c<='9'; x=(x<<3)+(x<<1)+c-'0');
	return f?-x:x;
}
#define MAXN 200011
int a[MAXN],n;
bool judge(int k)
{
	for(int i=0;i<n-1;i++)
	{
		if((a[n+i]>k&&a[n+i+1]>k)||(a[n-i]>k&&a[n-i-1]>k))
			return false;
		if((a[n+i]<=k&&a[n+i+1]<=k)||(a[n-i]<=k&&a[n-i-1]<=k))
			return true;
	}
	return a[1]<=k&&a[1]<=k;;
}



int main()
{
// 	freopen("agc006_d.in","r",stdin);
// 	freopen("agc006_d.out","w",stdout);
	n=read();
	for(int i=1;i<n<<1;a[i++]=read());
	int l=1,r=(n<<1)-1,mid;
	while(l<r)
	{
		mid=l+r>>1;
		if(judge(mid))
			r=mid;
		else
			l=mid+1;
	}
	printf("%d\n",r);
	fclose(stdin);
	fclose(stdout);
 	return 0;
}

Measured memory_bytes: 1024
import java.util.Scanner;
import java.util.Arrays;
import java.util.ArrayList;
import java.util.List;
import java.util.Collections;

public class Main {
	public static void main(String args[]){
		    Scanner sc = new Scanner(System.in);	
			
			int n = sc.nextInt();
			int[] ar = new int[n];
			int count = 0;
			for (int i = 0; i < n; i++) {
				ar[i] = sc.nextInt();
			}
			for (int i = 0; i < n; i++) {
				if(isOdd(ar[i]) == true){
					count++;
				}
			}

			if (isOdd(count) == true) {
				System.out.println("NO");
			} else {
				System.out.println("YES");
			}

			sc.close();
		}
	private static boolean isOdd(int n) {
		if (n % 2 != 0) {
			return true;
		}else{
			return false;
		}
	}
}

Measured memory_bytes: 50448
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, a, b) for(int i = a; i < b; i++)
#define rrep(i, a, b) for(int i = b-1; i >= a; i--)
typedef pair<int,int> pii;
typedef pair<long long, long long> pll;

signed main(){
    ll N; cin >> N;
    ll cnt = 0;
    if(N%2 == 1){
        cout << 0 << endl;
        return 0;
    }
    N/=2;
    while(N > 0){
        cnt += N/5;
        N /= 5;
    }
    cout << cnt << endl;
}

Measured memory_bytes: 256
#include <cstdio>
#include <cstring>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <algorithm>

using namespace std;

int main()
{
	char s[100000];
	scanf("%s\n", s);
	int g=0, p=0;
	int n=strlen(s);
	for(int i=0; i<n; i++){
		if(s[i]=='g'){
			g++;
		}else{
			p++;
		}
	}
	printf("%d\n", (g-p)/2);
	return 0;
}

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

int main() {
  string s;
  cin >> s;
  bool a = true;
  bool b = true;
  for(int i = 1; i < s.size() + 1; i++){
    if(i % 2 !=0){
      if(s.at(i - 1) == 'L'){
        a = false;
        break;
      }
    }
    else if(i % 2 == 0){
      if(s.at(i - 1) == 'R'){
        b = false;
        break;
      }
    }
  }
  if(a == true && b == true){
    cout << "Yes" << endl;
  }
  else{
    cout << "No" << endl;
  }
}


Measured memory_bytes: 256
total, k = map(int, input().split())

d = list(map(int, input().split()))

def total_to_digits(total):
    return map(int, list(str(total)))

def find_lowest_denomination(total, d):
    res = None
    for i in range(total, 99999):
        digits = list(total_to_digits(i))
        if not (set(digits) & set(d)):
            print(i)
            return


find_lowest_denomination(total, d)


Measured memory_bytes: 9148