akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <map>
#include <vector>
#include <cmath>
#include <string>
#include <cstring>
#include <algorithm>
#include <climits>
#include <stack>
#include <queue>
#include <set>
#include <cctype>
#include <bitset>
#include <type_traits>

#include <list>
using namespace std;

#define REP(i, n) for (int i = 0; i < (n); ++i)
#define rep(i, a, b) for (int i = a; i < (b); ++i)
#define YES(j) cout << (j ? "YES" : "NO") << endl;
#define Yes(j) std::cout << (j ? "Yes" : "No") << endl;
#define yes(j) std::cout << (j ? "yes" : "no") << endl;
int main(void)
{
    int n;
    cin >> n;
    int a[n];
    map<int, int> mp;
    REP(i, n)
    {
        cin >> a[i];
        if (a[i] % 4 == 0)
        {
            mp[4]++;
        }
        else if (a[i] % 2 == 0)
        {
            mp[2]++;
        }
    }
    n -= mp[4] * 2;
    if (n < 1)
    {
        Yes(1);
    }
    else if (n == 1)
    {
        Yes(1);
    }
    else
    {
        n -= mp[2];
        if (n <= 0)
        {
            Yes(1);
        }
        else
        {
            Yes(0);
        }
    }
}

Measured memory_bytes: 640
let rec iter a b f = if a > b then [] else let v = f a in v :: iter (a+1) b f
let () =
  Scanf.scanf "%s %d" @@ fun s k ->
  let n = String.length s in
  iter 1 5 (fun l -> iter 0 (n-l) (fun i -> String.sub s i l))
  |> List.concat |> List.sort_uniq compare
  |> fun xs -> print_endline (List.nth xs (k-1))

Measured memory_bytes: 6144
#include <bits/stdc++.h>
using namespace std;
const int MAXN=60;
int n,p[MAXN],dif;
int main () {
	scanf("%d",&n);
	for (int i=1;i<=n;i++) {
		scanf("%d",&p[i]);
		if (p[i]!=i) {++dif;}
	}
	if (dif==0||dif==2) {printf("YES\n");}
	else {printf("NO\n");}
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
typedef long long int ll;
using namespace std;
int main()
{
 ll a,b,c,d,e,f;
 scanf("%lld %lld %lld",&a,&b,&c);
 d=c-(a+b);
 if(d<=0)
 {
     printf("No\n");
     return 0;
 }
 d*=d;
 e=2*a*b;
 f=d/2;
 if(d%2==1)
    f++;
 if(f>e)
    printf("Yes\n");
 else
    printf("No\n");
}


Measured memory_bytes: 256
def two_int():
    N, K = map(int, input().split())
    return N,K

def one_int():
    return int(input())

def one_str():
    return input()

def many_int():
    return list(map(int, input().split()))

N, P = two_int()
A=many_int()

even = 0
odd = 0
for a in A:
    if a%2==0:
        even+=1
    else:
        odd+=1

import math
def comb(n,r):
    return math.factorial(n) // (math.factorial(n-r) * math.factorial(r))

even_count=0
for i in range(even+1):
    even_count += comb(even, i)

odd_count=0
if P==1:
    for i in range(1, odd+1, 2):
        odd_count += comb(odd, i)
elif P==0:
    for i in range(2, odd+1, 2):
        odd_count += comb(odd, i)
    odd_count+=1

if odd_count != 0 and even_count != 0:
    print(odd_count * even_count)
else:
    print(odd_count)

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

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

using ll = long long;
using P = pair<int,int>;
using mp =  map<string,int>;

const int MOD = 1e9 + 7;

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

    int k, n;
    cin >> k >> n;
    vector<int> a(n);

    rep(i, n){
        cin >> a[i];
    }

    int m = k - a[n - 1] + a[0];
    ll sum = k - a[n-1] + a[0];
    rep(i, n-1){
        sum += a[i+1] - a[i];
        m = max(m, a[i+1] - a[i]);
    }

    cout << sum - m<< endl;

    return 0;
}

Measured memory_bytes: 1024
import java.io.IOException;
import java.io.BufferedReader;
import java.io.InputStreamReader;

class Main {
    static int answer = 0;

    static void initialize() {
        answer = 0;
    }

    static void dfs(int restn, int restSum, int now) {
        if (restSum == 0 && restn == 0) {
            answer++;
            return;
        }

        if (now == 10 || restn == 0) {
            return;
        }

        dfs(restn - 1, restSum - now, now + 1); // nowを採用
        dfs(restn, restSum, now + 1); // nowを不採用
    }

    public static void main(String[] args) throws IOException {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        String line;

        while (!(line = br.readLine()).equals("0 0")) {
            String[] input = line.split(" ");
            int n = Integer.parseInt(input[0]);
            int s = Integer.parseInt(input[1]);

            initialize();
            dfs(n, s, 0);

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


Measured memory_bytes: 24556
#include <bits/stdc++.h>
using namespace std;
int main(){
  int n;
  long long h;
  cin >> n >> h;

  vector<long long> b(n);
  long long maxa = 0;
  for(int i=0;i<n;i++){
    long long ai,bi;
    cin >> ai >> bi;
    maxa = max(maxa,ai);
    b[i] = bi;
  }
  sort(b.begin(),b.end());
  reverse(b.begin(),b.end());

  long long ans=0;
  for(int i=0;i<n;i++){
    if(b[i]>maxa && h>0){
      h-=b[i];
      ans++;
    }
    else break;
  }

  if(h>0) ans+=(h+maxa-1) / maxa;

  cout << ans << endl;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define repr(i,n) for(int i = (int)(n); i >= 0; i--)
#define all(v) v.begin(),v.end()
typedef long long ll;

int main(){
    ll H,W;
    cin >> H >> W;
    if (H == 1 || W == 1) cout << 1 << endl;
    else{
        if ((H * W) % 2 == 0) cout << (H * W) / 2 << endl;
        else cout << (H * W + 1) / 2 << endl;
    }
}

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


void solve(long long N, long long K){
    int ans = 1;
    while(N >= K){
        N = N / K;
        ans++;
    }
    //`if(N != 0) ans++;
    cout << ans << endl;
    return;
}

int main(){
    long long N;
    scanf("%lld",&N);
    long long K;
    scanf("%lld",&K);
    solve(N, K);
    return 0;
}


Measured memory_bytes: 3644
import qualified Data.Map as M
import Control.Monad
import Data.List

main :: IO ()
main = do
  n <- readLn
  ss <- replicateM n getLine
  putStrLn $ unlines $ solve ss

solve :: [String] -> [String]
solve = sort . freq . count
  where
    count = foldr (\s mp -> M.insertWith (+) s 1 mp) M.empty
    freq mp = let cm = M.foldr max 0 mp in M.keys (M.filter (== cm) mp)
    
    


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

using namespace std;

int main() {
  int a, b;
  cin >> a >> b;

  if (a + b == 15)
    cout << "+" << endl;
  else if (a * b == 15)
    cout << "*" << endl;
  else
    cout << "x" << endl;

  return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#define y0 yy
#define y1 Yy
#define yn YY
#include <assert.h>
#include <algorithm>
#include <vector>
using namespace std;

int n,cnt[100005],res;

int main(){
    scanf("%d",&n);
    for(int i=0;i<n;i++){
        int ai;
        scanf("%d",&ai);
        cnt[ai-1]++;
        cnt[ai]++;
        cnt[ai+1]++;
    }
    for(int i=0;i<100000;i++)if(res<cnt[i])res=cnt[i];
    printf("%d\n",res);
    return 0;
}


Measured memory_bytes: 640
"use strict";
    
const main = arg => {
    arg = arg.trim().split("\n");
    const N = parseInt(arg[0].split(" ")[0]);
    const D = parseInt(arg[0].split(" ")[1]);
    
    const points = arg.slice(1, N + 1);
    let answer = 0;
    
    for(let i in points) {
        let temp = points[i].split(" ").map(n=>parseInt(n));
        let nows = [];
        
        for(let j in temp) {
            nows.push(temp[j]);           
        }
        
        for(let j=parseInt(i)+1; j<N; j++) {
            let temp = points[j].split(" ").map(n=>parseInt(n));
            let targets = [];
            
            for(let k in temp) {
                targets.push(temp[k]);           
            }
            
            let distance = 0;
            
            for(let k in targets) {
                distance += Math.abs(Math.pow(nows[k] - targets[k], 2));
            }
            
            distance = Math.sqrt(distance);
            
            if(distance % 1 === 0) {
                answer++
            }
        }
    }
    
    console.log(answer);
}
main(require('fs').readFileSync('/dev/stdin', 'utf8'));

Measured memory_bytes: 21192
function main()
  N,K=map(x->parse(Int,x),split(readline()))
  memo=zeros(Int,K)
  ans=0
  M=10^9+7
  for k=K:-1:1
    t=div(K,k)
    now=powermod(t,N,M)
    for j=2*k:k:K
      now-=memo[j]
    end
    memo[k]=now
    ans+=now*k
  end
  println(ans%M)
end
main()

Measured memory_bytes: 173964
import java.util.*;
class Main {
    public static void main(String[] args) {
	Scanner sc = new Scanner(System.in);
	int N = sc.nextInt();
	long[] a = new long[N+1];
	for(int i = 2; i<=N; i++) {
	    int k = i;
	    for(int j = 2; j<=i && k>1; j++) {
		while(k % j == 0) {
		    a[j] = a[j] + 1;
		    k=k/j;
		}
	    }
	}
	long ans = 1;
	for(long e: a) {
	    ans *= (e+1);
	    ans %= 1000000007;
	}
	System.out.println(ans);
    }
}

Measured memory_bytes: 21460
#include<bits/stdc++.h>
using namespace std;
#define ll long long
const int N = 110;
const int M = 100010;
int n, W, w[N], v[N];
ll memo[N][M];
ll dp(int i, int wight){
    if(i == n){
        return 0;
    }
    ll &ret = memo[i][wight];
    if(ret != -1)
        return ret;
    ll path1 = 0, path2;
    if(wight + w[i] <= W)
        path1 = dp(i+1, wight + w[i]) + v[i];
    path2 = dp(i+1, wight);

    return ret =  max(path1, path2);
}
int main(){
    memset(memo, -1, sizeof memo);
    cin>>n>>W;
    for(int i = 0; i < n; ++i)
        cin>>w[i]>>v[i];

    cout<<dp(0, 0);
    return 0;
}


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

int gcd(int i, int j, int k);

int main(void)
{
    int num,i,j,k;
    cin>>num;
    long long sum = 0;
    for(i = 1; i <= num; ++i)
    {
        j = 1;
        k = 1;

        for(j = 1; j <= num; ++j)
        {
            for(k = 1; k <= num; ++k)
            {
                sum = sum + gcd(i,j,k);
            }
        }
    }
    cout<<sum<<endl;

    return 0;
}

int gcd(int i, int j, int k)
{
    int x;
    long long G = 0;

    for(x = 1; ((x <= i) && (x <= j) && (x <= k)); ++x)
    {
        if(i % x == 0 && j % x == 0 && k % x == 0)
        {
                    G = x;
        }
    }

    return G;
}


Measured memory_bytes: 3596
//#include <bits/stdc++.h>
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <cstring>
#include <deque>
#include <queue>
#include <map>
using namespace std;

#define ii pair <int, int>
#define lli long long
#define pb push_back
#define X first
#define Y second

const int Mod = 1E9 + 7;
const int Inf = 1E9 + 7;
const int N = 2E6 + 10;

lli n, F[N][4];;
lli POW(lli n, lli k)
{
    if (k == 0) return 1;
    if (k == 1) return n % Mod;
    lli tmp = POW(n, k / 2);
    tmp = tmp * tmp % Mod;
    if (k % 2 == 0) return tmp;
    return tmp * n % Mod;
}

void Input()
{

}

void Solve()
{
    cin >> n;
    F[1][0] = 8;
    F[1][1] = F[1][2] = 1;
    F[1][3] = 0;

    for (int i = 2; i <= n; i++) {
        F[i][0] = F[i - 1][0] * 8 % Mod;
        F[i][1] = (F[i - 1][0] + F[i - 1][1] * 9 % Mod) % Mod;
        F[i][2] = (F[i - 1][0] + F[i - 1][2] * 9 % Mod) % Mod;
        F[i][3] = (F[i - 1][3] * 10 % Mod + F[i - 1][1] + F[i - 1][2]) % Mod;
    }

    cout << F[n][3];
}

#define task "test"
int main()
{
    if (fopen(task ".inp", "r")) {
        freopen(task ".inp", "r", stdin);
        freopen(task ".out", "w", stdout);
    }
    int testcase = 1;
    /// cin >> testcase;
    while (testcase--) {
        Input();
        Solve();
    }
}




Measured memory_bytes: 34800
#include <stdio.h>
int main(){
  int a,b,c,l,i;
  scanf("%d%d%d",&a,&b,&c);
  l=0;
  for(i=a;i<=b;i++){
    if(c%i==0){
      l=l+1;
    }
  }
    printf("%d\n",l);
    return 0;
}

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

template<typename T>
istream& operator >> (istream& istr, vector<T>& v){
    for(T& x: v) istr >> x;
    return istr;
}

template<typename T, typename U>
istream& operator >> (istream& istr, pair<T,U>& p){
    istr >> p.first >> p.second;
    return istr;
}

template<typename T>
ostream& operator << (ostream& ostr, vector<T>& v){
    if(!v.empty()){
        ostr << v.front();
        for(auto itr = ++v.begin(); itr != v.end(); itr++)
            // ostr << *itr;
            ostr << " " << *itr;
    }
    return ostr;
}

template<typename T, typename U>
ostream& operator << (ostream& ostr, pair<T,U>& p){
    // ostr << p.first << p.second;
    ostr << p.first << ", " << p.second;
    return ostr;
}

template<typename T>
ostream& operator << (ostream& ostr, vector<vector<T>>& vv){
    if(!vv.empty()){
        ostr << vv.front();
        for(auto itr = ++vv.begin(); itr != vv.end(); itr++)
            ostr << endl << *itr;
    }
    return ostr;
}

template<typename T, typename U>
ostream& operator << (ostream& ostr, vector<pair<T,U>>& vp){
    if(!vp.empty()){
        ostr << vp.front();
        for(auto itr = ++vp.begin(); itr != vp.end(); itr++)
            ostr << endl << *itr;
    }
    return ostr;
}

typedef long long ll;
typedef vector<ll> vll;
typedef vector<char> vc;
typedef vector<double> vd;
// vll x(n); x[i]=a;
typedef vector<vll> vvll;
typedef vector<vc> vvc;
typedef vector<vd> vvd;
// vvll x(m,vi(n)); x[i][j]=a;
typedef pair<ll,ll> pll;
typedef pair<double,double> pd;
typedef vector<pll> vpll;
typedef vector<pd> vpd;
// vpll x(n); x[i]={a,b}; x[i].first/second;

#define PI 3.1415926535897932
#define EPS 1e-12
#define INF (ll)1e+12
#define REP(i,n) for(ll i=0; i<(n); i++)
#define RREP(i,n) for(ll i=(n)-1; i>=0; i--)
#define FOR(i,a,b) for(ll i=(a); i<(b); i++)
#define FORR(i,a,b) for(ll i=(b)-1; i>=(a); i--)
#define fix(x) cout << fixed << setprecision(x)
#define dump(x) cout << #x << " = " << (x) << endl
#define all(x) (x).begin(),(x).end()

template<typename T> T sum(vector<T> &v) {return accumulate(all(v), (T)0LL);}
template<typename T> void sort(vector<T> &v){sort(all(v));}
template<typename T> void rsort(vector<T> &v){sort(all(v),greater<T>());}

int main(){
    ll n, ans = INF;
    cin >> n;
    vll a(n);
    cin >> a;
    REP(i,100+1){
        ll tmp = 0;
        REP(j,n) tmp += (a[j]-i)*(a[j]-i);
        if(tmp < ans) ans = tmp;
    }
    cout << ans << endl;
    return 0;
}


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

typedef long long   ll;
typedef long double ld;
using namespace std;

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    ll n,m;
    cin >> n >> m;
    if(2*n>m) cout << m/2 << "\n";
    else{
        ll tmp=m-2*n;
        cout << n+tmp/4 << "\n";
    }
    return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
int index[1000000];
int head,tail;
int sum;

typedef struct{
	char name[10];
	int t;
}data;

data d[100000];

void put(int n){
	index[tail++]=n;
}

int get(){
	return index[head++];
}

void process(int q){
	int x;
	while(tail!=head){
		x=get();
		if(d[x].t > q){
			d[x].t=d[x].t-q;
			sum+=q;
			put(x);
		}else{
			sum+=d[x].t;
			printf("%s %d\n",d[x].name,sum);
		}

	}
}

int main(){
	int i,n,q;

	scanf("%d %d",&n,&q);
	head=0,tail=n,sum=0;

	for(i=0;i<n;i++){
		scanf("%s %d",d[i].name,&d[i].t);
		index[i]=i;
	}
	process(q);

	return 0;
}

Measured memory_bytes: 3988
#include "stdio.h"

int cnt;
int b,f,r,v;
int i,j,k;
int num[4][3][10]={};//こんなので全部0に初期化できたのか！
int main(void){
	scanf(" %d",&cnt);
	for(i=0;i<cnt;i++){
		scanf("%d %d %d %d",&b,&f,&r,&v);
		num[b-1][f-1][r-1]+=v;
	}
	for(i=0;i<4;i++){
		for(j=0;j<3;j++){
			for(k=0;k<10;k++){
				printf(" %d",num[i][j][k]);
			}
			printf("\n");
		}
		if(i!=3) printf("####################\n");
	}
	
	
	return 0;
	
}

Measured memory_bytes: 612
#include<stdio.h>
#include<stdlib.h>

int main(){
 int N,K,S,i;
  scanf("%d %d %d",&N,&K,&S);
  int *A=(int*)malloc(sizeof(int)*N);
  for(i=0;i<K;i++)A[i]=S;
  if(S==1000000000)S=0;
  for(i=K;i<N;i++)A[i]=S+1;
  for(i=0;i<N;i++)printf("%d ",A[i]);
  free(A);
  return 0;
}


Measured memory_bytes: 1664
s = []
while True:
    n, x = map(int, input().strip().split())
    if n == x == 0:
        break
    c = 0
    for i in range(1,x//3):
        c += max(0, max(0,(x -3*i -1)//2) - max(0,(x -2*i -1 -n)))
    s.append(str(c))
print('\n'.join(s))

Measured memory_bytes: 7604
#include <bits/stdc++.h>
using namespace std;
using i64 = long long;

int main(){
    i64 n;
    cin>>n;
    i64 tei=n/1.08;
    i64 komi=tei*1.08,komi2=(tei+1)*1.08;
    if(komi==n) cout<<tei<<endl;
    else if(komi2==n)cout<<tei+1<<endl;
    else cout<<":("<<endl;
    return 0;
}

Measured memory_bytes: 256
from collections import defaultdict
N = int(input())
d = defaultdict(int)
for i in range(N):
    S = input()
    d[S] += 1
print("AC x "+str(d["AC"]))
print("WA x "+str(d["WA"]))
print("TLE x "+str(d["TLE"]))
print("RE x "+str(d["RE"]))

Measured memory_bytes: 74580
#include <iostream>

using namespace std;

int main()
{
	long long n, a, b;
	cin >> n >> a >> b;
	if (a == b) {
		cout << 1 << endl;
	}else if (a > b || n == 1) {
		cout << 0 << endl;
	}
	else {
		cout << b * (n - 1) + a - a * (n - 1) - b + 1 << endl;
	}

	return 0;
}

Measured memory_bytes: 256
import math

K = int(input())
# for K in range(201):
#     ans = 0
#     for i in range(1, K + 1):
#         for j in range(1, K + 1):
#             for k in range(1, K + 1):
#                 ans += math.gcd(math.gcd(i, j),k)
#     print(ans,end=',')

print([0,1,9,30,76,141,267,400,624,885,1249,1590,2208,2689,3411,4248,5248,6081,7485,8530,10248,11889,13687,15228,17988,20053,22569,25242,28588,31053,35463,38284,42540,46581,50893,55362,61824,65857,71247,76884,84388,89349,97881,103342,111528,120141,128047,134580,146316,154177,164817,174438,185836,194157,207927,218812,233268,245277,257857,268182,288216,299257,313635,330204,347836,362973,383709,397042,416448,434025,456967,471948,499740,515581,536073,559758,583960,604833,633651,652216,683712,709065,734233,754734,793188,818917,846603,874512,909496,933081,977145,1006126,1041504,1073385,1106467,1138536,1187112,1215145,1255101,1295142,1342852,1373253,1422195,1453816,1502376,1553361,1595437,1629570,1691292,1726717,1782111,1827492,1887772,1925853,1986837,2033674,2089776,2145333,2197483,2246640,2332104,2379085,2434833,2490534,2554600,2609625,2693919,2742052,2813988,2875245,2952085,3003306,3096024,3157249,3224511,3306240,3388576,3444609,3533637,3591322,3693924,3767085,3842623,3912324,4027884,4102093,4181949,4270422,4361548,4427853,4548003,4616104,4718640,4812789,4918561,5003286,5131848,5205481,5299011,5392008,5521384,5610705,5739009,5818390,5930196,6052893,6156139,6239472,6402720,6493681,6623853,6741078,6864016,6953457,7094451,7215016,7359936,7475145,7593865,7689630,7886244,7984165,8130747,8253888,8403448,8523897,8684853,8802826,8949612,9105537,9267595,9376656,9574704,9686065,9827097,9997134,10174780,10290813,10493367,10611772,10813692]
      [K])




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

#define taskname ""
#define pb push_back
#define eb emplace_back
#define fi first
#define se second
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define for0(i, n) for (int i = 0; i < (int)(n); ++i)
#define for1(i, n) for (int i = 1; i <= (int)(n); ++i)
#define ford(i, n) for (int i = (int)(n) - 1; i >= 0; --i)
#define fore(i, a, b) for (int i = (int)(a); i <= (int)(b); ++i)

using namespace std;

typedef long long ll;
typedef long double ld;
typedef complex <ld> cd;
typedef vector <cd> vcd;
typedef vector <int> vi;

mt19937 rng(chrono::system_clock::now().time_since_epoch().count());

const int maxH = 1e3 + 1;
const int maxW = 1e3 + 1;
const ll mod = 1e9 + 7;

int h, w;
char a[maxH][maxW];

ll dp[maxH][maxW];

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    cin >> h >> w;
    for1(i, h)
    {
        cin >> (a[i] + 1);
    }
    dp[0][1] = 1;
    for1(i, h)
    {
        for1(j, w)
        {
            if (a[i][j] == '.')
            {
                dp[i][j] = dp[i - 1][j] + dp[i][j - 1];
                dp[i][j] %= mod;
            }
        }
    }
    cout << dp[h][w];
    return 0;
}


Measured memory_bytes: 9088
package main

import (
	"fmt"
	"sort"
)

func main() {

	var N int
	fmt.Scan(&N)

	ds := make([]int, N)
	for i := range ds {
		fmt.Scan(&ds[i])
	}
	sort.Sort(sort.IntSlice(ds))

	fmt.Println(ds[N/2] - ds[N/2-1])
}


Measured memory_bytes: 5504
import java.util.Scanner;
import java.util.stream.LongStream;

public class Main {
    
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        
        final int N = sc.nextInt();
        final int M = sc.nextInt();
        final int K = sc.nextInt();
        
        final long[] A = new long[N];
        final long[] B = new long[M];
        
        for (int i = 0; i < N; i++) {
            A[i] = sc.nextLong();
        }
        for (int j = 0; j < M; j++) {
            B[j] = sc.nextLong();
        }
        
        int maxNum = 0;
        int numA = 0;
        int numB = M;
        long totalA = 0;
        long totalB = LongStream.of(B).sum();
        
        while (numA <= N) {
            while (K < totalA + totalB && 0 < numB) {
                numB--;
                totalB -= B[numB];
            }
            if (K < totalA + totalB) {
                break;
            }
            if (maxNum < numA + numB) {
                maxNum = numA + numB;
            }
            
            if (numA < N) {
                totalA += A[numA];
            }
            numA++;
        }
        
        System.out.println(maxNum);
    }
}


Measured memory_bytes: 65212
# B - Card Game for Two
#25min
N = int(input())
a_input = map(int, input().split())
a = list(a_input)
alice = 0
bob = 0
a.sort(reverse=True)
for i in range(N):
    if i%2 == 0:
        alice = alice + a[i]
    else:
        bob = bob + a[i]
print(alice-bob)

Measured memory_bytes: 3060
#include <iostream>
#include <vector>
#include <bitset>
#include <utility>
#include <string>
#include <queue>
#include <stack>
#include <algorithm>
#include <cmath>
#include <map>
#include <set>
 
using namespace std;
typedef long long ll;

const ll MOD=1000000007;

int main(){
  ll N,K;
  cin >> N >> K;
  vector<vector<ll>> a(N,vector<ll>(N));
  vector<vector<ll>> a1(N,vector<ll>(N));

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

  vector<vector<ll>> r(N,vector<ll>(N));
  vector<vector<ll>> r1(N,vector<ll>(N));
  for (int i = 0; i < N; i++){
    r[i][i]=1;
  }

  for (int i = 0; i < 60; i++){
    if(K&1){
      for (int n = 0; n < N; n++){
        for (int m = 0; m < N; m++){
          r1[n][m]=0;
          for (int l = 0; l < N; l++){
            r1[n][m]+=r[n][l]*a[l][m];
            r1[n][m]%=MOD;
          }
        }       
      }
      swap(r1,r);
    }
//    cout << i << endl;
    for (int n = 0; n < N; n++){
      for (int m = 0; m < N; m++){
        a1[n][m]=0;
        for (int l = 0; l < N; l++){
          a1[n][m]+=a[n][l]*a[l][m];
          a1[n][m]%=MOD;
        }
//        cout << a1[n][m] << " ";
      }       
//      cout << endl;
    }
    swap(a1,a);
    K>>=1;
  }

  ll res=0;
  for (int n = 0; n < N; n++){
    for (int m = 0; m < N; m++){
      res+=r[n][m];
      res%=MOD;
    }       
  }

  cout << res << endl;

  return 0;
}


Measured memory_bytes: 384
N = gets.to_i
A = gets.split.map(&:to_i)
B = gets.split.map(&:to_i)

count = 0

N.times do |i|
  if A[i] < B[i]
    count += A[i]
    B[i] -= A[i]
    if A[i+1] < B[i]
      count += A[i+1]
      A[i+1] = 0
    else
      count += B[i]
      A[i+1] -= B[i]
    end
  else
    count += B[i]
  end
end

puts count

Measured memory_bytes: 15500
#include <iostream>
#include <assert.h>
#include <vector>

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

  int32_t N;
  std::cin >> N;
  int32_t idx = 1;
  int32_t rm_cnt = 0;
  for (int i = 0; i < N; i++) {
    int32_t cur;
    std::cin >> cur;
    if (cur == idx) {
      idx++;
    } else {
      rm_cnt++;
    }
  }
  if (rm_cnt == N) {
    std::cout << -1 << std::endl;
  } else {
    std::cout << rm_cnt << std::endl;
  }
  return 0;
}


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

class Main {
	public static void main(String[] args) throws Exception {
		new Main().run();
	}
	
	void run() {
		Scanner sc=new Scanner(System.in);
		int a=sc.nextInt();
		int b=sc.nextInt();
		System.out.println(a*b%2==0?"Even":"Odd");
	}
	
	static void tr(Object... objects) {
		System.out.println(Arrays.deepToString(objects));
	}
	
}


Measured memory_bytes: 21204
use std::io;
use std::cmp;
use std::collections::BinaryHeap;
use std::collections::HashMap;
use std::collections::HashSet;
use std::f64::consts::PI;

fn read_line() -> String {
    let mut buf = String::new();
    io::stdin().read_line(&mut buf).ok();
    buf
}

fn func1(n: u64) -> u64 {
    if n == 2 {
        return 0;
    }
    let mut res = 1;
    for k in 2..cmp::min(n-1, 2_000_010) {
        if k * k > n-1 {
            break;
        }
        if (n-1) % k == 0 {
            if (n-1) / k == k {
                res += 1;
            } else {
                res += 2;
            }
        }
    }
    res
}

fn func2(n: u64) -> u64 {
    let mut res = 1;
    for k in 2..cmp::min(n, 2_000_010) {
        if n % k == 0 {
            let mut tmp = k;
            while n % tmp == 0 {
                if (n / tmp) % k == 1 {
                    res += 1;
                    break;
                }
                tmp *= k;
            }
        }
    }
    res
}


fn main() {
    let line: Vec<u64> = read_line().split_whitespace().map(|s| s.parse().unwrap()).collect();
    let n = line[0];
    println!("{}", func1(n) + func2(n));
}

#[cfg(test)]
mod test {
    fn greedy(n: u64) -> u64 {
        let mut res = 0;
        for i in 2..n+1 {
            let mut tmp = n;
            while tmp >= i {
                if tmp % i == 0 {
                    tmp /= i;
                } else {
                    tmp -= i;
                }
            }
            if tmp == 1 {
                res += 1;
            }
            
        }
        res
    }
    use func1;
    use func2;

    #[test]
    fn test() {
        for i in 10000..50000 {
            let ans = greedy(i);
            println!("testing :{}, ans: {}", i, ans);
            assert_eq!(ans, func1(i) + func2(i));
        }
    }
}

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

using namespace std;
#define PI 3.1415926535897932384626433832795
#define MOD (1000000007)
#define EPS (1e-15)
#define rep(i, n) for (int i = 0; i < (n); i++)
#define repc(i, s, n) for (int i = (s); i <= (n); i++)
#define rrep(i, n) for (int i = (n) - 1; i >= 0; i--)
#define rrepc(i, s, n) for (int i = (s); i >= (n); i--)
#define bet(x, a, b) (a) <= (x) && (x) < (b)
typedef long long ll;
typedef unsigned long long ull;

int main()
{
	string S;
	bool ans = false;

	cin >> S;
	
	if (S.length() >= 4 && S.substr(0, 4) == "YAKI") ans = true;

	cout << (ans ? "Yes" : "No") << endl;

	return 0;
}


Measured memory_bytes: 256
import java.io.*;
import java.util.*;
import java.math.*;

public class Main {
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int[] a = new int[n];
        int[] b = new int[n];
        int[] c = new int[n];
        int[] dp1 = new int[n];
        int[] dp2 = new int[n];
        int[] dp3 = new int[n];
        for(int i=0;i<n;i++){
            a[i] = sc.nextInt();
            b[i] = sc.nextInt();
            c[i] = sc.nextInt();
        }
        dp1[0] = a[0];
        dp2[0] = b[0];
        dp3[0] = c[0];
        for(int i=1;i<n;i++){
            dp1[i] = Math.max(dp1[i], Math.max(dp2[i-1]+a[i], dp3[i-1]+a[i]));
            dp2[i] = Math.max(dp2[i], Math.max(dp1[i-1]+b[i], dp3[i-1]+b[i]));
            dp3[i] = Math.max(dp3[i], Math.max(dp2[i-1]+c[i], dp1[i-1]+c[i]));
        }
        System.out.println(Math.max(dp1[n-1], Math.max(dp2[n-1], dp3[n-1])));
    }
}

Measured memory_bytes: 95392
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
    ($($r:tt)*) => {
        let s = {
            use std::io::Read;
            let mut s = String::new();
            std::io::stdin().read_to_string(&mut s).unwrap();
            s
        };
        let mut iter = s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
}

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

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

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

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

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

    ($iter:expr, usize1) => {
        read_value!($iter, usize) - 1
    };

    // Rust version 1.15.1, which is used by AtCoder,
    // does not support std::str::FromStr for char
    ($iter:expr, char) => {
        $iter.next().unwrap().chars().next().expect("Parse error")
    };

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

#[allow(unused_imports)]
fn main() {
    use std::cmp::max;
    use std::cmp::min;
    use std::collections::HashMap;

    input!{
        x1: i32,
        y1: i32,
        x2: i32,
        y2: i32,
    }
    let x3 = x2 - (y2-y1);
    let y3 = y2 + x2-x1;
    let x4 = x3 - (y3-y2);
    let y4 = y3 + x3-x2;
    println!("{} {} {} {}", x3, y3, x4, y4);
}


Measured memory_bytes: 4352
#include<iostream>
#include<vector>
#include<queue>
#include<stack>
#include<string>
#include<cmath>
#include<algorithm>
#include<bitset>
#include<map>
#include<functional>
#include<set>

#pragma region
using namespace std;
#define FOR(i,r,n) for(ll i = (ll)(r); i < (ll)(n); i++)
#define RFOR(i,r,n) for(ll i=(ll)(n-1);i>=r;i--)
#define ALL(x) x.begin(),x.end()
#define RALL(x) x.rbegin(),x.rend()
#define LOWER(a,x) lower_bound(ALL(a), x) - a.begin() - 1;
#define COUNT(a,x)  upper_bound(ALL(a), x) - lower_bound(ALL(a), x);
#define MCOUNT(a,x,y) upper_bound(ALL(a), y) - lower_bound(ALL(a), x);
#define INF 111111111111111111
#define MOD 1000000007
#define pb push_back
#define F first
#define S second
typedef long long int ll;
typedef long double ld;
typedef vector<ll> vll;
typedef pair<ll, ll> pll;
ll n = 0, m = 0, ans = 0, sum = 0, cnt = 0, tmp = 0, ma = 0, mi = 0;
string s;
bool flag, ok;
ll dx[4] = { 1,-1,0,0 }, dy[4] = { 0,0,1,-1 };
ll ddx[8] = { 1,-1,0,0,1,1,-1,-1 }, ddy[8] = { 0,0,1,-1,1,-1,1,-1 };
#pragma endregion
#define MAX 111111



int main(void) {
  vll a, b;
  cin >> n;
  a.pb(0);
  FOR(i, 0, n) {
	cin >> tmp;
	a.pb(tmp);
  }
  a.pb(0);
  b.pb(0);
  FOR(i, 0, n) {
	cin >> tmp;
	b.pb(tmp);
  }
  b.pb(0);

  ans = 1;
  RFOR(i, 1, n + 1) {
	if (b[i] != b[i + 1]) {
	  if (b[i] > a[i]) {
		cout << "0" << endl;
		return 0;
	  }
	}
	else {
	  if (a[i] != a[i - 1]) {
		if (b[i] < a[i]) {
		  cout << "0" << endl;
		  return 0;
		}
	  }
	  else {
		(ans *= min(a[i], b[i])) %= MOD;
	  }
	}
  }

  if (n == 1) {
	if (a[1] != b[1]) ans = 0;
  }
  cout << ans << endl;

  return 0;
}

Measured memory_bytes: 2548
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		long n = sc.nextLong();
		long k = sc.nextLong();
		n = Math.min(n % k, Math.abs(n % k - k));
		System.out.println(n);

	}

}


Measured memory_bytes: 21844
from numba import*
@njit(cache=1)
def main(N,Q,C,LR,A):
    data=[0]*(N+1)
    def add(i,x):
        i+=1
        while i<=N:
            data[i]+=x
            i+=i&-i
    def sum(a,b):
        r=0
        i=b
        while i>0:
            r+=data[i]
            i-=i&-i
        i=a
        while i>0:
            r-=data[i]
            i-=i&-i
        return r
    p=[-1]*N
    q=0
    a=[0]*Q
    for i in range(N):
        if p[C[i]-1]>=0:
            add(p[C[i]-1],-1)
        p[C[i]-1]=i
        add(i,1)
        while q<Q and LR[A[q]][1]==i+1:
            a[A[q]]=sum(LR[A[q]][0]-1,LR[A[q]][1])
            q+=1
    return a

import sys
def input(): return sys.stdin.buffer.readline()
N,Q=map(int,input().split())
import numpy as np
C=np.array(input().split(),dtype=np.int64)
LR=np.array(sys.stdin.buffer.read().split(),dtype=np.int64).reshape(Q,2)
A=np.argsort(LR[:,1])
print(*main(N,Q,C,LR,A),sep='\n')


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

class Main {
	static Scanner sc = new Scanner(System.in);
	public static void main(String[] args) {
		int n=sc.nextInt();
		int m=sc.nextInt();
		int a[]=new int[m];
		int yen=0;
		int check=0;
		for(int i=0;i<m;i++) {
			a[i]=sc.nextInt();
			int useless=sc.nextInt();
		}
		Arrays.sort(a);
		for(int i=m-1;i>=0;i--) {
			if(check>=m-1) break;
			if(a[i]>=n) {
				check++;
			}else {
			yen+=n-a[i];
			check++;
			}
		}
		System.out.println(yen);
		}
	}


Measured memory_bytes: 31800
#include <iostream>
#include <cstring>
#include <vector>
#include <algorithm>
#include <fstream>
#include <sstream>
#include <string>
#include <iomanip>
#include <math.h>
#include <limits>
#include <chrono>

using namespace std;

class circleOfATriangle
{
public:
	void calc(double,double,double,double,double,double);
};

void circleOfATriangle::calc(double x1, double y1, double x2, double y2, double x3, double y3)
{
	double a2 = (x2 - x3) * (x2 - x3) + (y2 - y3) * (y2 - y3);
	double b2 = (x1 - x3) * (x1 - x3) + (y1 - y3) * (y1 - y3);
	double c2 = (x2 - x1) * (x2 - x1) + (y2 - y1) * (y2 - y1);
	double area = ((x2 - x1) * (y3 - y1) - (x3 - x1) * (y2 - y1)) / 2.0;

	double px = (a2*(b2 + c2 - a2)*x1 + b2*(c2 + a2 - b2)*x2 + c2*(a2 + b2 - c2)*x3) / (16 * area*area);
	double py = (a2*(b2 + c2 - a2)*y1 + b2*(c2 + a2 - b2)*y2 + c2*(a2 + b2 - c2)*y3) / (16 * area*area);
	double r = sqrt((x1 - px)*(x1 - px) + (y1 - py)*(y1 - py));
	
	cout << fixed << setprecision(3) << px << " " << py << " " << r << "\n";
}

int main()
{
	circleOfATriangle ct;
	int n;
	double x1, y1, x2, y2, x3, y3;
	cin >> n;
	for (int i = 0; i < n; i++) {
		cin >> x1 >> y1 >> x2 >> y2 >> x3 >> y3;
		ct.calc(x1,y1,x2,y2,x3,y3);
	}

	return 0;
}

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

int main()
{
	string a,b;
	int x;
	int zh(string s);
	
	cin>>a>>b;
	
	x=zh(a+b);
	
	if(int(sqrt(x))==sqrt(x))
		cout<<"Yes"<<endl;
	else
		cout<<"No"<<endl;
	
	return 0;
}

int zh(string s)
{
	int tmp=0;
	
	for(int i=0;i<s.size();i++)
		tmp=tmp*10+(s[i]-'0');
	
	return tmp;
}

Measured memory_bytes: 256
package main

import "fmt"

func main() {
  S := []string{"SUN", "MON", "TUE", "WED", "THU", "FRI", "SAT"}
  var s string
  fmt.Scan(&s)
  for i := range S {
    if S[i] == s {
      fmt.Println(7-i)
    }
  }
}

Measured memory_bytes: 512
#include <bits/stdc++.h>
#define ft first
#define sc second
#define pt(sth) cout << sth << "\n"
using namespace std;
typedef long long ll;
typedef pair<ll, ll> pll;
template<class T>bool chmax(T &a, const T &b) {if(a<b) {a=b; return 1;} return 0;}
template<class T>bool chmin(T &a, const T &b) {if(b<a) {a=b; return 1;} return 0;}
static const ll INF=1e18;
static const ll MAX=101010;
static const ll MOD=1e9+7;

//for(i=0; i<N; i++) cin >> a[i];


int main(void) {
  ll i, j, k;
  
  ll N;
  ll a[MAX*2], b[MAX*2];
  
  cin >> N;
  for(i=0; i<N; i++) {
    cin >> a[i] >> b[i];
  }
  sort(a, a+N);
  sort(b, b+N);
  
  
  if(N&1) {
    pt(b[N/2]-a[N/2]+1);
  }else {
    double A=(a[N/2-1]+a[N/2])/2.0;
    double B=(b[N/2-1]+b[N/2])/2.0;
    ll ans=(B-A)*2+1;
    pt(ans);
  }
  
  
  
  
  
  
}
 
 




Measured memory_bytes: 6776
#include<iostream>
#include<cmath>
#include<algorithm>
#include<vector>
#include<functional>
#include<string>
#include<iomanip>
#include<map>
#include<utility>
#include<string>
#include<unordered_map>
#include <queue>

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; }

using namespace std;

#define min_3(a, b, c) min(a, min(b, c))
#define max_3(a, b, c) max(a, max(b, c))
typedef long long ll;

vector<int> to[200005];//辺のつながりをもつ
vector<int> ans;

void dfs(int u, int p=-1){ //dfs(部分木の根，根の親)
    for(int v : to[u]){
        if(v == p) continue; //vとつながってる頂点が親のときは見ないので
        ans[v] += ans[u];
        dfs(v,u);
    }
}

int main()
{
    int n, q;
    cin >> n >> q;
    for(int i = 0; i < n-1; i++){
        int a, b;
        cin >> a >> b;
        a--; b--;
        to[a].push_back(b);
        to[b].push_back(a);
    }
    ans.resize(n);
    for(int i = 0; i < q; i++){
        int p, x;
        cin >> p >> x;
        p--;
        ans[p] += x; //頂点pに前もって足しておく
    }
    dfs(0);
    for(int i = 0; i < n; i++){
        cout << ans[i] << " ";
    }
    cout << endl;
    return 0;
}


Measured memory_bytes: 23552
#include<bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < n; ++i)
#define rrep(i,n) for (int i = n-1; i >= 0; i--)
#define rep2(i,s,n) for (int i = s; i < n; ++i)
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define tmax(a,b,c) max(a,max(b,c))
#define tmin(a,b,c) min(a,min(b,c))
#define pb push_back
#define vi vector<int>
#define vl vector<ll>
#define vs vector<string>
#define vc vector<char>
using namespace std;
using ll = long long;
using P = pair<int,int>;
using LP = pair<ll,ll>;
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;}
const int inf = 1001001001;
const ll linf = 1001001001001001001;

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int n,k;
    cin >> n >> k;
    vector<P> neta(n);
    rep(i,n) cin >> neta[i].second >> neta[i].first;
    sort(rall(neta));
    ll sum = 0;
    ll kind = 0;
    set<int> se;
    priority_queue<int,vi,greater<int>> pq;
    rep(i,k) {
        sum += neta[i].first;
        if(se.count(neta[i].second)) {
            pq.push(neta[i].first);
        } else {
            se.insert(neta[i].second);
            kind++;
        }
    }
    ll ans = sum+kind*kind;
    int now = k;
    while(true) {
        if(kind == k) break;
        while(now < n) {
            if(!se.count(neta[now].second)) {
                se.insert(neta[now].second);
                sum += neta[now].first;
                sum -= pq.top();
                pq.pop();
                break;
            }
            now++;
        }
        if(now == n) break;
        kind++;
        now++;
        chmax(ans,sum+kind*kind);
    }
    cout << ans << endl;
}


Measured memory_bytes: 4224
import sys
input = sys.stdin.readline
N = int(input())
x = sorted(list(map(int, input().split())))
t = 1
for num in x:
    t = t * num
    if t > 10 ** 18:
        print(-1)
        sys.exit()

if (t > 10 ** 18): 
    print(-1)
else:
    print(t)


Measured memory_bytes: 21564
/*
Author : Xinyuan
*/
#include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for (int i = 0; i < n; i++)
#define all(x) (x).begin(), (x).end()
#define INF 1000000007
#define mod 1005
typedef pair<int, int> PII;
typedef vector<int> VI;
typedef vector<string> VS;
typedef vector<PII> VII;
typedef vector<VI> VVI;
typedef long long int ll;
ll powmod(ll a, ll b) {
    ll res = 1;
    a %= mod;
    assert(b >= 0);
    for (; b; b >>= 1) {
        if (b & 1) res = res * a % mod;
        a = a * a % mod;
    }
    return res;
}
int nxt() {
    int x;
    scanf("%d", &x);
    return x;
}

const int nax = 305;
double dp[nax][nax][nax], ev[nax][nax][nax];
// dp[i][j][k] is the expected number of operations so far to get to state (a, b, c)

int main() {
    int n = nxt();
    VI cnt(4);
    REP(i, n) {
        int x = nxt();
        cnt[x]++;
    }
    dp[cnt[1]][cnt[2]][cnt[3]] = 1;
    for (int c = n; c >= 0; c--) {
        for (int b = n; b >= 0; b--) {
            for (int a = n; a >= 0; a--) {
                if (a + b + c > n) continue;
                if (a + b + c == 0) continue;
                double p_waste = (double)(n - a - b - c) / n;
                double ev_waste = p_waste / (1 - p_waste) + 1;
                ev[a][b][c] += ev_waste * dp[a][b][c];
                if (a) {
                    double p_go = (double)a / (a + b + c);
                    dp[a - 1][b][c] += dp[a][b][c] * p_go;
                    ev[a - 1][b][c] += ev[a][b][c] * p_go;
                }
                if (b) {
                    double p_go = (double)b / (a + b + c);
                    dp[a + 1][b - 1][c] += dp[a][b][c] * p_go;
                    ev[a + 1][b - 1][c] += ev[a][b][c] * p_go;
                }
                if (c) {
                    double p_go = (double)c / (a + b + c);
                    dp[a][b + 1][c - 1] += dp[a][b][c] * p_go;
                    ev[a][b + 1][c - 1] += ev[a][b][c] * p_go;
                }
            }
        }
    }
    printf("%.10lf\n", ev[0][0][0]);
    return 0;
}


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

#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORTASC(c) sort((c).begin(),(c).end())
#define SORTDESC(c,t) sort((c).begin(),(c).end(), std::greater<t>());
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define VMAX(a) *max_element(ALL(a))
#define VMIN(a) *min_element(ALL(a))
#define OUT(a) cout << (a) << endl;
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

const double PI  = acos(-1.0);

template <class T, class S>
using umap = std::unordered_map<T, S>;
using ll = long long;
using namespace std;

int main() {
    ll a, b, c;

    cin >> a >> b >> c;

    if (b >= a*c){
        cout << c << endl;
    } else {
        cout << b/a << endl;
    }
    
    return 0;
}

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

int next(const vector<long long> v, const int i,int n){
  int r=i;
  while(v[r] == v[r+1] && r != n-1) r++;
  return r+1;
}

int main(){
  int n;
  cin >> n;
  
  map<long long, int> a;
  
  for(int i=0; i<n; i++){int p; cin >> p; a[p]++;}
  
  long long ans = 0;
  for(auto itr = a.begin(); itr != a.end(); itr++){
    if (itr -> first < itr -> second)
      ans += (itr -> second) - (itr -> first);
    else if (itr -> first > itr -> second)
      ans += itr -> second;
  }
  
  cout << ans << endl;
  
}

Measured memory_bytes: 6272
#include <bits/stdc++.h>
const int INF = 1e9;
const int MOD = 1e9+7;
const long long LINF = 1e18;
#define dump(x)  cout << 'x' << ' = ' << (x) << ` `;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n) for(int i=0;i<(n);++i)
#define REPR(i,n) for(int i=n;i>=0;i--)
#define FOREACH(x,a) for(auto& (x) : (a) )
typedef long long ll;
using namespace std;
typedef pair<ll, ll> P;

template<typename T>
void print(const vector<T> &x) {
    int n = x.size();
    rep(i,n) {
        cout << x[i];
        if (i!=n-1) cout<<" ";
        else cout << endl;
    }
}

template<typename T>
void print(const vector<vector<T>> &x) {
    int n = x.size();
    rep(i,n) {
        rep(j,x[i].size()) {
            cout << x[i][j] << " ";
        }
        cout << endl;
    }
}

template<typename T>
void print(const vector<T> &x, int n) {
    rep(i,n) {
        cout << x[i];
        if (i!=n-1) cout<<" ";
        else cout << endl;
    }
}

template<typename T>
void print(const vector<vector<T>> &x, int n, int m) {
    rep(i,n) {
        rep(j,m) {
            cout << x[i][j] << " ";
        }
        cout << endl;
    }
}

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

void input_init() {
    cin.tie(0); ios::sync_with_stdio(false);
}



int main(int argc, char const *argv[]) {
    int n; cin>>n;
    vector<vector<P>> g(n);
    rep(i,n-1) {
        int a,b; cin>>a>>b;
        --a,--b;
        g[a].emplace_back(b,i);
        g[b].emplace_back(a,i);
    }

    vector<int> ans(n-1);
    auto dfs = [&](auto &&f, int x, int par, int pc) -> void {
        int col = 0;
        for (auto &&e: g[x]) {
            if (e.first==par) continue;
            col += (pc==col);
            ans[e.second] = col+1;
            f(f,e.first,x,col++);
        }
    };

    dfs(dfs,0,-1,-1);
    cout << *max_element(ans.begin(), ans.end()) << endl;
    rep(i,n-1) cout << ans[i] << endl;
    return 0;
}

Measured memory_bytes: 8320
n = int(input())
s = input()

c = 0
for i in range(1000):
  a = str(i).zfill(3)  
  n0 = s.find(a[0])
  if n0==-1:
    continue
  n1 = s.find(a[1], n0+1)
  if n1==-1:
    continue
  n2 = s.find(a[2], n1+1)
  if n2!=-1:
    c += 1
print(c)

Measured memory_bytes: 3060
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10**6)

H, W = map(int, input().split())
S = [list(map(lambda x: 1 if x == '#' else 0, input()[:-1])) for _ in [0]*H]
for i, ss in enumerate(S):
    for j, s in enumerate(ss):
        if (i ^ j) & 1:
            ss[j] ^= 1

visited = [0]*(H*W)

dirs = [(-1, 0), (0, -1), (0, 1), (1, 0)]


def dfs(i, j, cnt):
    c = S[i][j]
    for di, dj in dirs:
        ni, nj = i+di, j+dj
        if not 0 <= ni < H or not 0 <= nj < W:
            continue
        if visited[ni*W+nj]:
            continue
        if c == S[ni][nj]:
            visited[ni*W+nj] = 1
            cnt[(ni ^ nj) & 1] += 1
            dfs(ni, nj, cnt)


ans = 0
for i in range(H):
    for j in range(W):
        if visited[i*W+j]:
            continue
        visited[i*W+j] = 1
        cnt = [0, 0]
        cnt[(i ^ j) & 1] += 1
        dfs(i, j, cnt)
        ans += cnt[0] * cnt[1]
print(ans)


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

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

Measured memory_bytes: 640
from itertools import permutations

def main():
    n, a, b, c = map(int, input().split())
    l = [int(input()) for _ in range(n)]

    # full search
    ans = 10**9
    for perm in permutations(l):
        cost = -30
        for i in range(1, n-1):
            cost1 = cost + 10 * len(perm[:i]) + abs(a - sum(perm[:i]))
            for j in range(i+1, n):
                cost2 = cost1 + 10 * len(perm[i:j]) + abs(b - sum(perm[i:j]))
                for k in range(j+1, n+1):
                    cost3 = cost2 + 10 * len(perm[j:k]) + abs(c - sum(perm[j:k]))
                    if cost3 < ans:
                        ans = cost3

    print(ans)

main()

Measured memory_bytes: 70048
#include <iostream>
#include <string>
#include <algorithm>
#include <cmath>
#include <vector>
#include <ctype.h>
#include <stdlib.h>
using namespace std;


int main(){
    int K,X;
    cin >> K >> X;

    if(K * 500 >=  X){
        cout << "Yes" << endl;
    }else{
        cout << "No" << endl;
    }
}


Measured memory_bytes: 256
N = int(input())
A = [int(_) for _ in input().split()]

from heapq import *

L = [0] * (N + 1)

t = 0
h = []
for a in A[:N]:
    heappush(h, a)
    t += a

L[0] = t
for i in range(N):
    x = A[N + i]
    heappush(h, x)
    y = heappop(h)
    t += x - y
    L[i + 1] = t

R = [0] * (N + 1)

t = 0
h = []
for a in A[N * 2:]:
    heappush(h, -a)
    t -= a

R[N] = t
for i in range(N - 1, -1, -1):
    x = A[N + i]
    heappush(h, -x)
    y = heappop(h)
    t += -x - y
    R[i] = t

result = max(l + r for l, r in zip(L, R))

print(result)

Measured memory_bytes: 38676