akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <algorithm>
#include <vector>
#include <array>
#include <string>
#include <queue>
#include <cmath>
#include <iterator>
#include <math.h>
#include <cstdio>
#include <map>

using namespace std;
using lli = long long int;
using ulli = unsigned long long int;

int main(void){
    ulli a,b,total = 0;
    cin >> a >> b;
    for(ulli i = a;i<=b;i*=2)total++;
    cout << total;
}


Measured memory_bytes: 256
package main

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

func out(x ...interface{}) {
	fmt.Println(x...)
}

var sc = bufio.NewScanner(os.Stdin)

func getInt() int {
	sc.Scan()
	i, e := strconv.Atoi(sc.Text())
	if e != nil {
		panic(e)
	}
	return i
}

func getString() string {
	sc.Scan()
	return sc.Text()
}

func solve(H, W int) int {
	l0 := W / 2
	l1 := W / 2
	if W%2 == 1 {
		l0++
	}
	h := H / 2
	ans := (l0 + l1) * h
	if H%2 == 1 {
		ans += l0
	}
	return ans
}

func main() {
	sc.Split(bufio.ScanWords)
	sc.Buffer([]byte{}, 1000000)

	H, W := getInt(), getInt()

	n := H * W

	if H == 1 || W == 1 {
		out(1)
		return
	}
	if n%2 == 1 {
		out(n/2 + 1)
	} else {
		out(n / 2)
	}
}


Measured memory_bytes: 640
n,m = map(int,input().split())
ll = 0
rr = 10**5+1
for i in range(m):
    l,r = map(int,input().split())
    if l > ll:
        ll = l
    if r < rr:
        rr = r
else:
    #print(rr-ll+1)
    if rr-ll+1>n:
        print(n)
    elif rr-ll+1<0:
        print(0)
    else:
        print(rr-ll+1)


Measured memory_bytes: 3060
#include <iostream>

using namespace std;

int main()
{
	long long N, M;
	cin >> N >> M;
	if (2 * N > M) {
		cout << M / 2 << endl;
	}
	else {
		long long r = (M - 2 * N);
		cout << N + r / 4 << endl;
	}
}


Measured memory_bytes: 256
package main

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

func main() {
	sc.Split(bufio.ScanWords)
	n := nextInt()
	as := make([]int, n)
	x := 0
	for i := 0; i < n; i++ {
		as[i] = nextInt()
		x ^= as[i]
	}

	for i := 0; i < n; i++ {
		if i < n-1 {
			fmt.Printf("%d ", x^as[i])
		} else {
			fmt.Println(x ^ as[i])
		}
	}
}

var sc = bufio.NewScanner(os.Stdin)

func nextInt() int {
	sc.Scan()
	i, e := strconv.Atoi(sc.Text())
	if e != nil {
		panic(e)
	}
	return i
}


Measured memory_bytes: 7276
# import itertools
# import math
# import sys
# import numpy as np

# N = int(input())
# S = input()
# n, *a = map(int, open(0))
K, N = map(int, input().split())
A = list(map(int, input().split()))
# Q = list(map(int, input().split()))
# S = input()

# d = sorted(d.items(), key=lambda x:x[0]) # keyでsort

interbals = [A[0] + K - A[-1]]
for i in range(N-1):
    interbals.append(A[i + 1] - A[i])

print(K - max(interbals))

Measured memory_bytes: 32252
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		//String s = sc.next();
		//String t = sc.next();
		//long n = sc.nextLong();
		long m = sc.nextLong();
		//long k = sc.nextLong();
		//long l = sc.nextLong();
		long count=0;

		/*for(int i=1;i<10000;i++) {
			if(n<500*(i+1)) {
				count=i;
				break;
			}
		}*/
		/*if(500*count+m>=n) {
			System.out.println("Yes");
		}else{
			System.out.println("No");
		}*/
		//System.out.println((int)Math.ceil((n+m)/2.0));
		System.out.println(m/3);
	}
}




Measured memory_bytes: 21716
#!/usr/bin/env python
from __future__ import division, print_function
from sys import stdin


class Node(object):
    def __init__(self, key=None):
        self.key = key
        self.parent = None
        self.left = None
        self.right = None


def tree_insert(top, z):
    y = None
    x = top
    while isinstance(x, Node):
        y = x
        if z.key < x.key:
            x = x.left
        else:
            x = x.right
    z.parent = y
    if y is None:
        top = z
    elif z.key < y.key:
        y.left = z
    else:
        y.right = z
    return top


def inorder_walk(node):
    if node.left:
        inorder_walk(node.left)
    print('', node.key, end='')
    if node.right:
        inorder_walk(node.right)


def preorder_walk(node):
    print('', node.key, end='')
    if node.left:
        preorder_walk(node.left)
    if node.right:
        preorder_walk(node.right)


n = int(stdin.readline())
#assert n <= 500000

top = None
for _ in range(n):
    cmd = stdin.readline()
    if cmd.startswith('i'):
        key = int(cmd[7:])
        #assert -2000000000 <= key <= 2000000000
        top = tree_insert(top, Node(key))
    else:
        inorder_walk(top)
        print()
        preorder_walk(top)
        print()

Measured memory_bytes: 204816
#include <bits/stdc++.h>
 
#define int long long
#define ll long long
#define ull unsigned long long
#define ld long double
#define rep(i, l, r) for (int i = l; i <= r; i++)
#define repb(i, r, l) for (int i = r; i >= l; i--)
#define sz(a) (int)a.size()
#define fi first
#define se second
#define all(x) x.begin(),x.end()
#define pb push_back
#define mp(a, b) make_pair(a, b)
#define ret(a) {cout << a; exit(0);}
 
using namespace std;                                                                                  
 
mt19937 mrand(random_device{}()); 
const ll mod = 1e9 + 7;
int rnd(int x) { return mrand() % x;}
ll powmod(ll a,ll b,ll mod) {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;}
 
typedef pair < int , int > pii ;                                            
typedef pair < long long  , long long > pll ;
 
const int N = 3e5 + 123;
 
int n, m, k;
vector < pii > gr[N];
int a[N];
int dp1[N] , cnt1[N], dp2[N], cnt2[N] , w[N] , v[N] , u[N];
 
main(){
	ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
	int s , t;
	cin >> n >> m >> s >> t;
 
	rep(i , 1 , n)
		dp1[i] = dp2[i] = 1e17;
	dp1[s] = dp2[t] = 0;
	cnt1[s] = cnt2[t] = 1;
	
	for(int i = 1; i <= m; i++){
		cin >> u[i] >> v[i] >> w[i];
		gr[u[i]].pb({v[i],w[i]});
		gr[v[i]].pb({u[i],w[i]});
	}
	set < pii > st;
	st.insert({0 , s});
	
	while(sz(st) != 0){
		int u = (*st.begin()).se;
		st.erase(st.begin());
		for(auto to : gr[u]){
			if(dp1[to.fi] == dp1[u] + to.se)
				cnt1[to.fi] += cnt1[u], cnt1[to.fi] %= mod;
			else if(dp1[to.fi] > dp1[u] + to.se){
				st.erase({dp1[to.fi] , to.fi});
				dp1[to.fi] = dp1[u] + to.se;
				cnt1[to.fi] = cnt1[u];
                st.insert({dp1[to.fi],to.fi});
			}
		}
	}    
 
	st.insert({0 , t});
	while(sz(st) != 0){
		int u = (*st.begin()).se;
		st.erase(st.begin());
		for(auto to : gr[u]){
			if(dp2[to.fi] == dp2[u] + to.se)
				cnt2[to.fi] += cnt2[u] , cnt2[to.fi] %= mod;
			else if(dp2[to.fi] > dp2[u] + to.se){
				st.erase({dp2[to.fi] , to.fi});
				dp2[to.fi] = dp2[u] + to.se;
				cnt2[to.fi] = cnt2[u];
                st.insert({dp2[to.fi],to.fi});
			}
		}
	}	
	int tot = cnt1[t] * cnt1[t]%mod;
	for(int i = 1; i <= m; i++){
		if(dp1[u[i]] + dp2[v[i]] > dp2[u[i]] + dp1[v[i]])
			swap(u[i],v[i]);
		if(dp1[u[i]] + dp2[v[i]] + w[i] == dp1[t]){
			int l = max(dp1[u[i]],dp2[v[i]]) , r = min(dp1[u[i]],dp2[v[i]])+w[i];
			if(l < r)
				tot -= cnt1[u[i]] * cnt2[v[i]] % mod * cnt1[u[i]] % mod * cnt2[v[i]] % mod , tot += mod , tot %= mod;//input//
		}
	}
 
	for(int i = 1; i <= n; i++)
		if(dp1[i] + dp2[i] == dp1[t] and dp1[i] == dp2[i])
			tot -= cnt1[i] * cnt2[i] % mod * cnt1[i] %mod * cnt2[i] % mod , tot += mod , tot %= mod;
 
 
	ret(tot);
        
}

Measured memory_bytes: 39024
#!/mnt/c/Users/moiki/bash/env/bin/python
N = int(input())
sosu = [2]
import math

for i in range(3,101):
    fl = True
    for j in sosu:
        if j > math.sqrt(i):
            break
        if i % j == 0:
            fl = False
            break
    if fl:
        sosu.append(i)
# print(sosu)

def getpow(n, x):
    if n >= x:
        return 1 + getpow(n/x, x) if n % x == 0 else 0
    else:
        return 0

has = {}
powlist = []


for i in range(1,N+1):
    for p in sosu:
        if p > i:
            break
        if i % p == 0:
            has[p] = 2 if not p in has else has[p] + getpow(i,p)
            # print("p: {}".format(p))


# print(has)


def f(primes, num):
    if num == 1:
        # print("\t end: {}".format(primes))
        return 1
    else:
        sum = 0
        for e,p in enumerate(primes.keys()):
            for i in range(3, primes[p]+1):
                if num // i >= 1 and num % i == 0:
                    prime2 = primes.copy()
                    try:
                        # prime2[p] = prime2[p] - i
                        prime2[p] = 0
                    except:
                        print(prime2,e,p)
                        exit(1)
                    # print("num: {}, i: {},  {} => {}".format(num,i,primes,(prime2)))
                    sum += f(prime2, num//i)
        return sum
            

num75 = 0
num25 = 0
num15 = 0
num5  = 0
num3 = 0
# primes = has
primes = []
for p in has:
    primes.append(has[p])
def num(m):
    return len(
        list(
            filter(
                lambda x: 
                    x >=  m, primes
            )
        )
    )
    
# print(num(5), num(3), list(filter(lambda x: x >= 3, primes)))
# sum = f(has, 75)
# print(sum // 6)
sum = num(75) + num(25) * (num(3)-1) + num(15) * (num(5) - 1) + num(5) * (num(5)-1) * (num(3)-2) // 2
print(sum)








Measured memory_bytes: 3316
import java.io.InputStream;
import java.io.PrintStream;
import java.util.Arrays;
import java.util.HashSet;
import java.util.Scanner;
import java.util.Set;

public class Main {

  public static void main(String[] args) {
    resolve(System.in, System.out);
  }

  static void resolve(InputStream is, PrintStream pw) {
    Scanner sc = new Scanner(is);
    Set<Integer> candidate = new HashSet<>(Arrays.asList(1, 2, 3));
    candidate.remove(Integer.valueOf(sc.next()));
    candidate.remove(Integer.valueOf(sc.next()));
    pw.println(candidate.iterator().next());
  }
}


Measured memory_bytes: 21972
#include <bits/stdc++.h>
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 p(s) std::cout << s ;
# define pl(s)  std::cout << s << endl;
# define printIf(j,s1,s2) cout << (j ? s1 : s2) << endl;
# 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;
# define all(v) v.begin(),v.end()
# define showVector(v) REP(i,v.size()){p(v[i]);p(" ")} pl("")
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;}
typedef long long int ll;
typedef pair<ll,ll> P_ii;
typedef pair<double,double> P_dd;

template<class T>
vector<T> make_vec(size_t a){
    return vector<T>(a);
}

template<class T, class... Ts>
auto make_vec(size_t a, Ts... ts){
  return vector<decltype(make_vec<T>(ts...))>(a, make_vec<T>(ts...));
}

template<typename T,typename V>
typename enable_if<is_class<T>::value==0>::type
fill_v(T &t,const V &v){t=v;}

template<typename T,typename V>
typename enable_if<is_class<T>::value!=0>::type
fill_v(T &t,const V &v){
  for(auto &e:t) fill_v(e,v);
}


const int MOD = 1000000007;
const int inf=1e9+7;
const ll longinf=1LL<<60 ;

void addM(long long &a, long long b) {
    a += b;
    if (a >= MOD) a -= MOD;
}

void mulM(long long &a, long long b) {
    a = ((a%MOD)*(b%MOD))%MOD ;
}

// a^b mod M
long myPow(long a,long b,int M) {
    long ret = 1;
    long tmp = a;
    while(b>0) {
        if((b&1)==1) ret = (ret * tmp) % M;
        tmp = (tmp * tmp) % M;
        b = b>>1;
    }
    return ret;
}

 // nCk mod M
int nCk(int n,int k,int M) {
    long ret = 1;
    int mi = min(k, n-k);
    for(int i=1;i<=mi;i++) {
        ret = (ret * myPow(i,M-2,M)) % M;
    }
    for(int i=n-mi+1;i<=n;i++) {
        ret = (ret * i) % M;
    }
    return (int)ret;
};

vector<pair<long long, long long> > prime_factorize(long long n) {
    vector<pair<long long, long long> > res;
    for (long long p = 2; p * p <= n; ++p) {
        if (n % p != 0) continue;
        int num = 0;
        while (n % p == 0) { ++num; n /= p; }
        res.push_back(make_pair(p, num));
    }
    if (n != 1) res.push_back(make_pair(n, 1));
    return res;
}


int main() {
    string s;
    cin >> s;

    if(s.size()==2) {
        pl(s)
    } else {
        reverse(s.begin(),s.end());
        pl(s)
    }

    return 0;
}

Measured memory_bytes: 256
#include<iostream>

using namespace std;

int main() {
    int a, b;
    string op;
    while (true) {
        cin >> a >> op >> b;
        if (op == "?") {
            break;
        }
        else if (op == "+") {
            cout << a + b << endl;
        }
        else if (op == "-") {
            cout << a - b << endl;
        }
        else if (op == "*") {
            cout << a * b << endl;
        }
        else if (op == "/") {
            cout << a / b << endl;
        }
    }
    return 0;
}

Measured memory_bytes: 3156
using System;
using System.Collections.Generic;
using System.Linq;
using static System.Console;
using static System.Int32;

namespace ConsoleApp1
{
    class Program
    {
        static void Main()
        {
            label:
            int n = Parse(ReadLine());
            int result = 0, a = 0, b = 0, ab = 0;
            for (int i = 0; i < n; ++i)
            {
                var line = ReadLine();
                if (line[line.Length - 1] == 'A')
                {
                    if (line[0] == 'B') ++ab;
                    else ++a;
                }
                else if (line[0] == 'B') ++b;
                for(int j = 0; j < line.Length; ++j)
                {
                    if (line[j] == 'A')
                    {
                        if (j + 1 < line.Length && line[j + 1] == 'B') ++result;
                    }
                }
            }
            if (0 < ab)
            {
                if (0 < a || 0 < b) result += ab;
                else result += ab - 1;
            }
            result += Math.Min(a, b);
            WriteLine(result);
        }
    }
}


Measured memory_bytes: 13140
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

using namespace std;
using namespace __gnu_pbds;

#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define fbo find_by_order
#define ook order_of_key

typedef long long ll;
typedef pair<ll,ll> ii;
typedef vector<int> vi;
typedef long double ld;
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> pbds;

int main(){
    ios_base::sync_with_stdio(0); cin.tie(0);
    vector<ll> arr[51];
    arr[1].pb(1);
    arr[1].pb(1);
    arr[2].pb(1);
    arr[2].pb(2);
    arr[2].pb(1);
    for(int i=3;i<=50;i++){
        arr[i].pb(1);
        for(int j=0;j<=i-2;j++){
            ll k=arr[i-1][j]+arr[i-1][j+1];
            arr[i].pb(k);
        }
        arr[i].pb(1);
    }
    int n,a,b;
    cin>>n>>a>>b;
    vector<ll> v;
    for(int i=0;i<n;i++){
        ll k;
        cin>>k;
        v.pb(k);
    }
    sort(v.begin(),v.end());

    ld count=0;

    int countbig=1;
    for(int i=n-2;i>=0;i--){
        if(v[i]!=v[n-1]){
            break;
        }
        else{
            countbig+=1;
        }
    }
    if(countbig>=a){
            //cout<<"case1"<<endl;
        cout<<v[n-1]<<endl;
        ll ans=0;
        for(int i=a;(i<=b) && (i<=countbig);i++){
            ans+=arr[countbig][i];
        }
        cout<<ans<<endl;
    }
    else{
        //cout<<"case2"<<endl;
        ll countsmall=0,counta=0,countx=0;
        for(int i=n-1;i>n-a-1;i--){
            count+=v[i];
            if(v[i]==v[n-a]){
                counta+=1;          // how many needed
            }
        }
        for(int i=0;i<n;i++){
            if(v[i]==v[n-a]){
                countsmall+=1;      // how many are there
            }
        }
        count/=a;
        cout<<setprecision(9)<<count<<endl;
        for(int i=n-1;i>=0;i--){
            if(v[i]==v[n-a]){
                break;
            }
            else{
                countx+=1;
            }
        }
        a-=countx;
        b-=countx;
        ll ans=0;
        ans+=arr[countsmall][a];
        cout<<ans<<endl;
    }
    return 0;
}


Measured memory_bytes: 256
n = int(input())
list = [int(i) for i in input().split()]

for i in range(n):
    if list[i] %2 == 0:
        if list[i]%3 == 0 or list[i] %5 == 0:
            continue
        else:
            print("DENIED")
            break
else:
    print("APPROVED")


Measured memory_bytes: 3060
function f()
    input = map(x -> parse(Int, x), split(chomp(readline()), " "))
    A = input[1]
    B = input[2]

    r = [A, B]

    tmp = findmax(r)

    ret = tmp[1]


    r[tmp[2]] = r[tmp[2]] - 1


    tmp = findmax(r)

    ret = ret + tmp[1]

    print(ret)
end
f()

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

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

    int counter = 0;
    rep(i, N-2) {
        if (S.substr(i, 3) == "ABC") counter++;
    }
    cout << counter << endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
ll par[100005],sum[100005],bridg[100005][2],ans[100005];
ll find(ll x)
{
    return par[x]==x? x :par[x]=find(par[x]);
}
int main()
{
    ll n,m;
    cin>>n>>m;
    for(int i=0;i<n;i++)
    {
        par[i]=i;
        sum[i]=1;
    }
    for(int i=0;i<m;i++)
    {
        scanf("%lld%lld",&bridg[i][0],&bridg[i][1]);
    }
    ans[m-1]=n*(n-1)/2;
    for(int i=m-1;i>0;i--)
    {
        ll x,y;
        x=find(bridg[i][0]);
        y=find(bridg[i][1]);
        if(x!=y)
        {
            ans[i-1]=ans[i]-sum[x]*sum[y];
            sum[y]+=sum[x];
            par[x]=y;
        }
        else
            ans[i-1]=ans[i];
    }
    for(int i=0;i<m;i++)
        printf("%lld\n",ans[i]);
    return 0;

}


Measured memory_bytes: 5248
#include <cmath>
#include <queue>
#include <cstdio>
#include <iomanip>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <algorithm>
#define N 100010
#define ll long long
using namespace std;
inline ll read() 
{ 
    ll x=0,f=1;char ch=getchar(); 
    while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();} 
    while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();} 
    return x*f; 
}
ll Q,H,S,D,n,ans;
ll a[5];//1 2 4 8
ll b[5];
bool ban[5];
int main()
{
	Q=read(),H=read(),S=read(),D=read();
	n=read()*4;
	b[1]=Q,b[2]=H,b[3]=S,b[4]=D;
	a[1]=Q*8,a[2]=H*4,a[3]=S*2,a[4]=D;
	ll mx=100000000000000ll,mxid;
	for(int i=1;i<=4;i++)
	if(a[i]<mx)mx=a[i],mxid=i;
	
	
	while(n)
	{
		mx=1000000000000000ll;
		ll tmp=mxid;
		if(mxid==3)mxid=4;
		else if(mxid==4)mxid=8;
		ans+=n/mxid*b[tmp];
		n%=mxid;
		ban[tmp]=1;
		
		for(int i=1;i<=4;i++)
		if(a[i]<mx&&!ban[i])mx=a[i],mxid=i;
	}
	cout<<ans<<endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define FOR(i, s, e) for (int i = (int)(s); i <= (int)(e); i++)
#define printYesNo(is_ok) puts(is_ok ? "Yes" : "No");
#define SORT(v) sort(v.begin(), v.end());
#define RSORT(v) sort(v.rbegin(), v.rend());
#define REVERSE(v) reverse(v.begin(), v.end());

template <typename T>
void printlnVector(T v)
{
  rep(i, v.size())
  {
    cout << v[i] << endl;
  }
}

template <typename T>
void printVector(T v)
{
  rep(i, v.size())
  {
    cout << v[i] << " ";
  }
  cout << endl;
}

int main()
{
  int A, B, C;
  cin >> A >> B >> C;
  if (A == B && B == C && C == A)
    cout << "Yes" << endl;
  else
    cout << "No" << endl;
  return 0;
}

Measured memory_bytes: 256
#include <algorithm>
#include <cassert>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
using namespace std;
typedef long long ll;

#define rep(i, n) for(ll i = 0; i < n; i++)
#define REP(i, n) for(ll i = 1; i < n + 1; i++)
#define PI 3.14159265359
#define EPS 0.0000000001
#define MOD 1000000007
//cout << std::fixed << std::setprecision(15) << y << endl;



int main(){
    string S;
    cin >> S;

    ll ans = 0;
    if(S == "SUN"){
        ans = 7;
    }else if(S == "MON"){
        ans = 6;
    }else if(S == "TUE"){
        ans = 5;
    }else if(S == "WED"){
        ans = 4;
    }else if(S == "THU"){
        ans = 3;
    }else if(S == "FRI"){
        ans = 2;
    }else{
        ans = 1;
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 3564
#include <iostream>
#include <cstdio>
using namespace std;
int n, m;
int x;
double sum;
int main(){
    int i, j, k;
    cin >> n;
    sum = 0;
    for(i = 1; i <= n; ++i){
        scanf("%d",&x);
        sum += 1./x;
    }
    sum = 1./sum;
    printf("%.6lf\n",sum);
    return 0;
}

Measured memory_bytes: 888
import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int[] origin = new int[n];
        int[] sorted = new int[n];
        for(int i = 0; i < n; i++) {
            int num = sc.nextInt();
            origin[i] = num;
            sorted[i] = num;
        }
        Arrays.sort(sorted);
        int medianIndex1 = sorted.length / 2 - 1;
        int median1 = sorted[medianIndex1];
        int medianIndex2 = sorted.length / 2;
        int median2 = sorted[medianIndex2];
        for(int i = 0; i < n; i++) {
            if(origin[i] <= median1) {
                System.out.println(median2);
            } else {
                System.out.println(median1);
            }
        }
    }
}

Measured memory_bytes: 93496
import java.util.*;
public class Main {
    public static void main(String args[]) {
        Scanner sc=new Scanner(System.in);
        int n=sc.nextInt();
        int h[]=new int[n+1];
        for(int i=1;i<=n;i++)
        h[i]=sc.nextInt();

        int dp[]=new int[n+1];
        dp[1]=0;
        for(int i=2;i<=n;i++)
        {
            int ans1=1000000000,ans2=1000000000;
            ans1=dp[i-1]+Math.abs(h[i]-h[i-1]);
            if(i-2>=1)
            ans2=dp[i-2]+Math.abs(h[i]-h[i-2]);

            dp[i]=Math.min(ans1,ans2);
        }
        System.out.println(dp[n]);

        
    }
}

Measured memory_bytes: 52856
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define rep_1(i,n) for(int (i)=0;(i)<=(n);(i)++)
#define rep_2(i,a,b) for(int (i)=(a);(i)<(b);(i)++)
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
const int INF = 1e9;
const int MOD = 1e9+7;
const ll LINF = 1e18;

int main(){
    int d,g;cin>>d>>g;
    vector<pair<int,int>> p(d);
    rep(i,d) cin>>p[i].first >> p[i].second;

    ll ans = LINF;
    for(int i = 0;i<(1<<d);i++){
        ll tmp = 0;
        ll num = 0;
        for(int j = 0;j<d;j++){
            if(i&(1<<j)){
                tmp += p[j].second + p[j].first*100*(j+1);
                num+=p[j].first;
            }
        }
        if(tmp>=g){
            ans = min(ans,num);
        }else{
            //中途半端に解く奴
            for(int j=d-1;j >= 0;j--){
                if(i &(1<<j)) continue;
                for(int k=0;k<p[j].first;k++){
                    if(tmp>=g) break;
                    tmp+=100*(j+1);
                    num++;
                }
            }
            ans = min(ans,num);
        }
    }
    cout << ans<<endl;

}



Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<cstring>
#include<queue>
#include<algorithm>
#include<string>
#include<cstdio>
#include<cstdlib>
#include <math.h>
#define INF 0x3f3f3f3f
using namespace std;
int a,n,b=0,c=0;
int main() 
{
	scanf("%d",&n);
	for(int i=0;i<n;i++)
	{
		scanf("%d",&a);
		if(a%4==0)
		{
			b++;
		}
		else if(a%2==0)
		{
			c++; 
		} 
	} 
	if(b+c/2>=n/2)
	printf("Yes\n");
	else
	printf("No\n");
}

Measured memory_bytes: 256
def main stdin
  input = stdin.split("\n")[0]
  a,b,c = input.split(' ').map { |s| s.to_i }
  (1..100).each do |i|
    if (a * i) % b == c then
      puts "YES"
      return
    end
  end

  puts "NO"
end

main $stdin.read


Measured memory_bytes: 1788
n = int(input())
a = list(map(int, input().split()))


ruiseki0 = [0] * (n + 10) 
for i in range(n):
    ruiseki0[i + 1] = ruiseki0[i]
    if i % 2 == 0:
        ruiseki0[i + 1] += a[i]
        
l = [0] * (n + 1)
for i in range(n + 1):
    l[i] = ruiseki0[i]
    if i % 2 == 0:
        if i == 0:
            l[i] = 0
        else:
            l[i] = max(l[i - 2] + a[i - 1], l[i])


a = a[::-1]
ruiseki0 = [0] * (n + 10) 
for i in range(n):
    ruiseki0[i + 1] = ruiseki0[i]
    if i % 2 == 0:
        ruiseki0[i + 1] += a[i]

r = [0] * (n + 1)
for i in range(n + 1):
    r[i] = ruiseki0[i]
    if i % 2 == 0:
        if i == 0:
            r[i] = 0
        else:
            r[i] = max(r[i - 2] + a[i - 1], r[i])
   
ans = - 10 ** 20
for i in range(n):
    if n - i - 2 < 0:
        break
    if n % 2 == 0 and i % 2 == 0:
        continue
    ans = max(ans, l[i] + r[n - i - 2])
    
if n % 2 == 0:
    ans1 = 0
    ans2 = 0
    for i in range(n):
        if i % 2 == 0:
            ans1 += a[i]
        else:
            ans2 += a[i]
    ans = max(ans1, ans2, ans)
if n % 2 == 1:
    ans = max(ans, sum(a)- ruiseki0[n])
print(ans)

Measured memory_bytes: 105392
#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 eb emplace_back
#define vi vector<int>
#define vvi vector<vector<int>>
#define vl vector<ll>
#define vs vector<string>
#define vc vector<char>
#define vb vector<bool>
#define vp vector<P>
using namespace std;
using ll = long long;
using P = pair<int,int>;
using LP = pair<ll,ll>;
template<class T> istream& operator>>(istream& is,vector<T>& v) { for(T& t:v){is>>t;} return is; }
template<class T> ostream& operator<<(ostream& os,const vector<T>& v) { for(T t:v){os<<t<<" ";} os<<"\n"; return os; }
void Yes(bool b) { cout << (b ? "Yes" : "No") << endl; }
void YES(bool b) { cout << (b ? "YES" : "NO") << endl; }
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); cout.tie(nullptr);
    int n,m;
    cin >> n >> m;
    vi v(n,0),u(n,0);
    rep(i,m) {
        int a,b;
        cin >> a >> b;
        a--; b--;
        if(a > b) swap(a,b);
        if(a == 0) v[b] = 1;
        if(b == n-1) u[a] = 1;
    }
    rep2(i,1,n-1) {
        if(v[i] && u[i]) {
            cout << "POSSIBLE" << endl;
            return 0;
        }
    }
    cout << "IMPOSSIBLE" << endl;
}

Measured memory_bytes: 1792
import java.util.*;

class Main{
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        String s = sc.next();
        int len = s.length();
        int ans = len;
        for(int i=len-1;i>=2;i--){
            String cur = s.substring(0,i);
            if(helper(cur)){
                ans = i;
                break;
            }
        }
        System.out.println(ans);
    }
    static private boolean helper(String s){
        int len = s.length();
        if(len%2==1) return false;
        String front = s.substring(0,len/2);
        String end = s.substring(len/2,len);
        return front.equals(end);
    }
}


Measured memory_bytes: 21844
//
//  main.cpp
//  minnimum_spanning_tree
//
//  Created by ???????????? on 2017/10/23.
//  Copyright ?? 2017 ????????????. All rights reserved.
//

#include <iostream>
#include <stdio.h>

#define n_max 100
#define WHITE 0
#define GRAY 1
#define BLACK 2
#define INFTY 3000

using namespace std;

int n, M[n_max][n_max], color[n_max], d[n_max], p[n_max];

void init(){
    int i, j;
    scanf("%d", &n);
    for(i = 0; i < n; i++){
        for(j = 0; j < n; j++){
            scanf("%d", &M[i][j]);
        }
        color[i] = WHITE;
        d[i] = INFTY;
    }
}

void prim(){
    //initializing
    d[0] = 0;
    p[0] = -1;
    
    int u;
    while(true){
        int mincost = INFTY;
        for(int i = 0; i < n; i++ ){
            if((color[i] != BLACK) && (d[i] < mincost)){
                mincost = d[i];
                u = i;
            }
        }
        
        if (mincost == INFTY) break;
        
        color[u] = BLACK;
        
        for(int v = 0; v < n; v++){
            if((color[v] != BLACK) && (M[u][v] != -1)){
                if(M[u][v] < d[v]){
                    d[v] = M[u][v];
                    p[v] = u;
                    color[v] = GRAY;
                }
            }
        }
    }
    int sum = 0;
    for(int i = 0; i < n; i++){
        sum += d[i];
    }
    cout<<sum<<endl;
}

int main(int argc, const char * argv[]) {
    init();
    prim();
//    std::cout << "Hello, World!\n";
    return 0;
}

Measured memory_bytes: 3188
import java.util.Scanner;
public class Main{
	public static void main(String[] args) {
    	Scanner sc = new Scanner(System.in);
		long n = Long.parseLong(sc.next());
      	long a = Long.parseLong(sc.next());
      	long b = Long.parseLong(sc.next());
      	if(a==0){
        	System.out.println(0);
          return;
        }
        long c = a+b;
      	long d = n%c;
      	if(d>a) d = a;
        long e = n/c;
        long f = e*a+d;
        System.out.println(f);
    }
 
}

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

const int SIZE=2000*2000+1;
using Bit=bitset<SIZE>;
int main(){
    int n;
    cin>>n;
    vector<int> a(n);
    for(int i=0;i<n;i++) cin>>a[i];
    Bit bit;
    bit[0]=true;
    for(int i=0;i<n;i++){
        bit=bit|(bit<<a[i]);
    }
    int v=accumulate(a.begin(),a.end(),0);
    for(int i=(v+1)/2;i<=v;i++){
        if(bit[i]){
            cout<<i<<endl;
            return 0;
        }
    }
    return 0;
}

Measured memory_bytes: 2176
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<iostream>
#include<cmath>
using namespace std;
int read(){
	int f=1,x=0;char c=getchar();
	while(c<'0'||c>'9'){if(c=='-')f*=-1;c=getchar();}
	while(c>='0'&&c<='9'){x=x*10+c-'0';c=getchar();}
	return f*x;
}
int a1,a2,a3,a,b,c,sum,maxn=-1;
int main(){
	cin>>a1>>a2>>a3;
	a=abs(a1-a2);b=abs(a1-a3);c=abs(a2-a3);
	sum=a+b+c;
	if(a>maxn)maxn=a;
	if(b>maxn)maxn=b;
	if(c>maxn)maxn=c;
	sum-=maxn;
	cout<<sum;
	return 0;
}

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

class Main {

    public static void main(String[] args) throws IOException {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        int n=Integer.parseInt(br.readLine());
        call(n);
    }
    
    static void call(int n){
        for(int i=1;i<=n;i++){
            if(check(i)) System.out.print(" "+i);
        }System.out.println();
    }
    
    static boolean check(int n){
        if(n>=10){
            char[] c=String.valueOf(n).toCharArray();
            for(char checker:c){
                if(checker=='3'){
                    return true;
                }
            }
        }if(n%3==0) return true;
        return false;
    }
}

Measured memory_bytes: 28732
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define fast_cin() ios_base::sync_with_stdio(false); cin.tie(NULL)
#define ll long long
#define ld long double
#define mp make_pair
#define pb push_back
#define fi first
#define se second
#define gcd __gcd
#define pcount __builtin_popcount
#define pcountll __builtin_popcountll
#define nxtperm next_permutation
#define int ll
//primitive roots: 998244353 - 3; 7340033 - 5
//#pragma 03
//#pragma GCC target ("sse4.2")

const ll mod = 1000000007;		const double PI = acos(-1.);
using namespace std;
using namespace __gnu_pbds;
typedef tree<int, null_type, less<int>,rb_tree_tag, tree_order_statistics_node_update> ordered_set;
typedef pair<int, int> ii;
typedef vector<int> vi;
typedef vector<ii> vii;
typedef complex<double> cd;

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 kawaii = chrono::steady_clock::now().time_since_epoch().count();
        return splitmix64(x + kawaii);
    }
};

int n, W; 
const int maxn = 200; 
int w[maxn], v[maxn], dp[maxn][100005]; 
signed main()
{
//	freopen("in.txt", "r", stdin); freopen("out.txt", "w", stdout);
// 	fast_cin();
	cin >> n >> W; 
	for(int i=1;i<=n;i++) cin >> w[i] >> v[i]; 
	for(int i=1;i<=W;i++) dp[0][i] = -1e18; 
	for(int i=1;i<=n;i++)
	{
		for(int j=1;j<=W;j++) 
		{ 
			dp[i][j] = max(dp[i-1][j], (j < w[i] ? 0 : dp[i-1][j - w[i]] + v[i])); 
		}
	}
	int ans = 0; 
	for(int i=0;i<=W;i++) ans = max(ans, dp[n][i]); 
	cout << ans; 
}

/*
	Test input:
*/


Measured memory_bytes: 80128
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
#define PI 3.1415926535

double add(double a, double b){
    double EPS = 1e-10;
    if(abs(a + b) < EPS * (abs(a) + abs(b))){
        return 0;
    }
    return a + b;
}

struct Point{
    double x, y;

    Point() {}

    Point(double x, double y) : x(x), y(y) {}

    Point operator + (Point p){
        return Point(add(x, p.x), add(y, p.y));
    }
    Point operator - (Point p){
        return Point(add(x, -p.x), add(y, -p.y));
    }
    Point operator * (double d){
        return Point(x * d, y * d);
    }

    double dot(Point p){
        return add(x * p.x, y * p.y);
    }

    double cross(Point p){
        return add(x * p.y, -y * p.x);
    }
};

bool cmp_x(const Point &p, const Point &q){
    if(p.x != q.x){
        return p.x < q.x;
    }
    return p.y < q.y;
}

vector<Point> convex_hull(vector<Point> &ps, int n){
    sort(ps.begin(), ps.end(), cmp_x);

    int k = 0;

    vector<Point> qs(n * 2);

    for (int i = 0; i < n; i++){
        while (k > 1 && (qs[k - 1] - qs[k - 2]).cross(ps[i] - qs[k - 1]) <= 0){ 
            k--;
        }
        qs[k++] = ps[i];
    }

    for (int i = n - 2, t = k; i >= 0; i--){
        while (k > t && (qs[k - 1] - qs[k - 2]).cross(ps[i] - qs[k - 1]) <= 0){ 
            k--;
        }
        qs[k++] = ps[i];
    }
    qs.resize(k - 1);
    return qs;
}

int main() {
    int n;
    cin >> n;
    vector<Point> p(n);
    vector<Point> X(n);
    for(int i = 0; i < n; i++){
        double tx, ty;
        cin >> tx >> ty;
        p[i] = Point(tx,ty);
        X[i] = Point(tx,ty);
    }
    if(n==2){
        cout << "0.5" << endl << "0.5" << endl;
        return 0;
    }
    vector<Point> conv = convex_hull(X, n);

    int num = conv.size();
    for(int i = 0; i < n; i++){
        double vec1x = -99999999.0;
        double vec1y = -99999999.0;
        double vec2x = -99999999.0;
        double vec2y = -99999999.0;
        for(int j = 0; j < num; j++){
            if(p[i].x == conv[j].x && p[i].y == conv[j].y){
                vec1x = conv[(j+num-1)%num].x - conv[j].x;
                vec1y = conv[(j+num-1)%num].y - conv[j].y;
                vec2x = conv[(j+num+1)%num].x - conv[j].x;
                vec2y = conv[(j+num+1)%num].y - conv[j].y;
                }
        }
        if(vec1x == -99999999.0){
            cout << "0.0000000"<<endl;
        }else if(num == 2){
            cout << "0.5" << endl;
        }else{
            double angle = (vec1x*vec2x+vec1y*vec2y)/(sqrt(vec1x*vec1x+vec1y*vec1y)*sqrt(vec2x*vec2x+vec2y*vec2y));
            printf("%.8f\n",(PI-acos(angle))/(2*PI));
        }
    }
    return 0;
}


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

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

    vector<int> l(m),r(m);
    for(int i=0; i<m; i++){
        cin>>l[i]>>r[i];
    }

    bool exist=true;
    int tent_l=0,tent_r=0;

    tent_l=l[0];
    tent_r=r[0];

    for(int i=0; i<m-1; i++){
        tent_l=max(tent_l,l[i+1]);
        tent_r=min(tent_r,r[i+1]);
        if(tent_l>tent_r){
            exist=false;
            break;
        }
    }

    cout<<(exist==true ? tent_r-tent_l+1 : 0)<<endl;
}

Measured memory_bytes: 1024
#include<stdio.h>
#define N 100000

typedef struct{
int parent;
int left;
int right;
}Node;

int depth(int);
int height(int);

Node node[N];

int main(){
int i,j,n,id,child;

scanf("%d",&n);
for(i=0;i<n;i++){
node[i].parent=node[i].left=node[i].right=-1;
}
for(i = 0;i < n;i++){
scanf("%d", &id);
for(j = 0;j < 2;j++){
scanf("%d", &child);
if(child != -1){
node[child].parent = id;
if(j == 0){
node[id].left = child;
}
else{
node[id].right = child;
}
}
}
}

for(i = 0;i < n;i++){
printf("node %d: parent = %d, sibling = ", i, node[i].parent);
if(node[i].parent == -1){
printf("-1, ");
}
else{
if(node[node[i].parent].right == -1){
if(node[node[i].parent].left != -1 && node[node[i].parent].left != i){
printf("%d, ", node[node[i].parent].left);
}
else{
printf("-1, ");
}
}
else{
if(node[node[i].parent].right != i){
printf("%d, ", node[node[i].parent].right);
}
else{
printf("%d, ", node[node[i].parent].left);
}
}
}

printf("degree = ");
if(node[i].left == -1){
if(node[i].right == -1){
printf("0, ");
}
else{
printf("1, ");
}
}
else{
if(node[i].right == -1){
printf("1, ");
}
else{
printf("2, ");
}
}

printf("depth = %d, height = %d, ", depth(i), height(i));

if(node[i].parent == -1){
printf("root\n");
}
else{
if(node[i].left == -1){
if(node[i].right != -1){
printf("internal node\n");
}
else{
printf("leaf\n");
}
}
else{
printf("internal node\n");
}
}
}
return 0;
}

int depth(int id){
int dep = 0;
while(1){
if(node[id].parent == -1){
return dep;
}
else{
dep++;
id = node[id].parent;
}
}
}

int height(int id){
int hei, l = 0, r = 0;
if(node[id].left == -1){
if(node[id].right == -1){
return 0;
}
else{
r += height(node[id].right) + 1;
}
}
else{
l += height(node[id].left) + 1;
if(node[id].right != -1){
r += height(node[id].right) + 1;
}
}
if(l < r){
return r;
}
else{
return l;
}
}



Measured memory_bytes: 1848
#include<iostream>
#include<map>
#include<vector>
#include<sstream>
#include<cstdio>
#include<string>
using namespace std;
#define DIR 1
#define FILE 2
#define ARB 3
#define IDX "index.html"
#define REP(i,b,e) for(int i=b;i<e;i++)
#define rep(i,n) REP(i,0,n)
class Tree{
public:
  int type;
  string myname;
  map<string,Tree* > M;
  Tree(){type=DIR;M.clear();myname="";}
};

void get_path(string a,vector<string>&b){
  rep(i,a.size())if (a[i]=='/')a[i]=' ';
  stringstream sin(a);
  while(sin>>a)b.push_back(a);
}

void get_query(string a,vector<pair<string,int> > & b){
  REP(i,1,a.size()){
    string t;
    while(i<a.size() && a[i] != '/')t+=a[i++];
    b.push_back(make_pair(t,DIR) );
  }
  if ( b.size() == 0)return;
  if ( a[a.size()-1]=='/')b.push_back(make_pair(IDX,FILE) );
  else b[b.size()-1].second =ARB;
}

void make_tree(Tree *a,vector<string>&b,int &p){
  if (b.size()==p){return;}
  Tree *next=a->M[b[p]];
  if ( next == 0){
    next = new Tree;
    next->myname=b[p];
    a->M[b[p]]=next;
    next->type = p+1==b.size()?FILE:DIR;
    make_tree(next,b,++p);
  }else make_tree(next,b,++p);  
}

Tree* Find_Page(Tree *a,vector<pair<string,int> >&b,int &p,Tree *prev){
  Tree *ret=a;
  while(p < b.size()){
    if (b[p].first == "."){p++;continue;}
    else if ( b[p].first ==".."){p++;return prev;}
    Tree *next = a->M[b[p].first];
    if ( next == 0 || (next->type&b[p].second )==0  )return NULL;
    ret = Find_Page(next,b,++p,a);
    if ( ret == NULL)return NULL;
  }

  if (ret->type == FILE)return ret;
  ret = ret->M[IDX];
  if ( ret == 0 || ret->type !=FILE)return NULL;
  return ret;
}

void solve(string *q,Tree *root){
  Tree *data[2];
  rep(i,2){
    vector<pair<string,int> > a;
    int p=0;
    data[i]=NULL;
    get_query(q[i],a);
    data[i]=Find_Page(root,a,p,NULL);
    if (  data[i] == NULL){puts("not found");return;}
  }
  if (data[0] == data[1] )puts("yes");
  else puts("no");
}

main(){
  int n,q;
  while(cin>>n>>q &&n){
    Tree root;
    string t;
    vector<string> a;
    int p=0;
    rep(i,n)cin>>t,get_path(t,a),make_tree(&root,a,p=0),a.clear();
    rep(i,q){
      string in[2];
      cin>>in[0]>>in[1];
      solve(in,&root);
    }
  }
  return false;
}

Measured memory_bytes: 0
def solve(string):
    h, w, *a = string.split()
    h = int(h)
    w = int(w)
    rows = [sum([_c == "#" for _c in _a]) for _a in a]
    cols = [sum([_a[i] == "#" for _a in a]) for i in range(w)]
    ans = "\n".join(
        "".join([_c for __f, _c in zip(cols, _a) if __f]) for _f, _a in zip(rows, a) if _f)
    return ans


if __name__ == '__main__':
    n, w = map(int, input().split())
    print(solve('{} {}\n'.format(n, w) + '\n'.join([input() for _ in range(n)])))


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

int main(){
    using namespace std;
    unsigned long N;
    cin >> N;
    vector<unsigned long> d(N);
    {
        vector<unsigned long> x(N);
        for(auto& i : x)cin >> i;
        adjacent_difference(x.begin(), x.end(), d.begin());
    }
    constexpr unsigned long MOD = 1000000007;
    vector<unsigned long> coef(N);
    coef[1] = 1;
    for(unsigned long i{2}; i < N; ++i)(coef[1] *= i) %= MOD;
    for(unsigned long i{2}; i < N; ++i)coef[i] = coef[MOD % i] * (MOD - MOD / i) % MOD;
    partial_sum(coef.begin(), coef.end(), coef.begin(), [](auto i, auto j){return (i + j) % MOD;});
    cout << inner_product(d.begin(), d.end(), coef.begin(), 0UL, [](auto i, auto j){return (i + j) % MOD;}, [](auto i, auto j){return i * j % MOD;}) << endl;
    return 0;
}

Measured memory_bytes: 1792
#include <stdio.h>
#include <string.h>
#include <algorithm>
#include <iostream>
#include <math.h>
#include <assert.h>
#include <vector>
#include <deque>

using namespace std;
typedef long long ll;
typedef unsigned int uint;
typedef unsigned long long ull;
static const double EPS = 1e-9;
static const double PI = acos(-1.0);

#define REP(i, n) for (int i = 0; i < (int)(n); i++)
#define FOR(i, s, n) for (int i = (s); i < (int)(n); i++)
#define FOREQ(i, s, n) for (int i = (s); i <= (int)(n); i++)
#define FORIT(it, c) for (__typeof((c).begin())it = (c).begin(); it != (c).end(); it++)
#define MEMSET(v, h) memset((v), h, sizeof(v))

int main() {
  int n;
  while (scanf("%d", &n) > 0) {
    deque<int> other;
    deque<int> one;
    deque<int> zero;
    REP(i, n) {
      int v;
      scanf("%d", &v);
      if (v == 0) { zero.push_back(v); }
      else if (v == 1) { one.push_back(v); }
      else { other.push_back(v); }
    }
    sort(other.begin(), other.end());
    deque<int> ans;
    if (zero.size() % 2 == 0) {
      if (other.size() >= 2 && other.back() == 3 && other[other.size() - 2] == 2) {
        swap(other.back(), other[other.size() - 2]);
      }
      FORIT(it, other) { ans.push_back(*it); }
      FORIT(it, zero) { ans.push_back(*it); }
      FORIT(it, one) { ans.push_back(*it); }
    } else {
      int v = -1;
      if (!one.empty()) { v = 1; one.pop_back(); }
      else if (!other.empty()) { v = other.front(); other.pop_front(); }

      if (other.size() >= 2 && other.back() == 3 && other[other.size() - 2] == 2) {
        swap(other.back(), other[other.size() - 2]);
      }
      FORIT(it, other) { ans.push_back(*it); }
      REP(i, zero.size() - 1) { ans.push_back(0); }
      if (v != -1) {
        ans.push_back(v);
      }
      ans.push_back(0);
      FORIT(it, one) { ans.push_back(*it); }
    }
    FORIT(it, ans) {
      printf("%d\n", *it);
    }
  }
}

Measured memory_bytes: 0
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using intpair=pair<int,int>;
using llpair=pair<ll,ll>;
using llvec=vector<ll>;
using llmat=vector<vector<ll>>;
#define llmattp(name,a,b,num) name(a,vector<ll>(b,num))
#define INTINF 1<<30
#define LLINF 1LL<<60
#define ABS(x) ( (x)>0 ? (x) : -(x) )

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

ll gcd(ll a, ll b) {
	if(a==0||b==0) return 0;
	if(a<b) swap(a,b);
	ll tmp = a%b;
	while(tmp!=0) {
		a = b;
		b = tmp;
		tmp = a%b;
	}
	return b;
}

ll factorial(ll x) {
	ll f=1;
	for(ll i=2; i<x; i++) {
		f*=i;
	}
	return f;
}

ll nPr(ll n, ll r) {
	ll result=1;
	for(ll i=r+1; i<=n; i++) result*=i;
	return result;
}

ll nCr(ll n, ll r) {
	if (n == r) { return 1; }
	if (r > n) { return 0; }

	if (r > n / 2) { r = n - r; }

	if (n == 0) { return 0; }
	if (r == 0) { return 1; }
	if (r == 1) { return n; }

	double result = 1;
	for (double i = 1; i <= r; i++) {
		result *= (n - i + 1) / i;
	}

	return (ll)result;
}

bool IsPrime(ll num) {
	if (num < 2) return false;
	else if (num == 2) return true;
	else if (num % 2 == 0) return false; // 偶数はあらかじめ除く

	double sqrtNum = sqrt(num);
	for (ll i = 3; i <= sqrtNum; i += 2)
	{
		if (num % i == 0)
		{
			// 素数ではない
			return false;
		}
	}

	// 素数である
	return true;
}

ll GreaterBinarySearch(ll *array, ll key, ll max, ll min) {
	if(array[max]<array[min]) {
		return NULL;
	} else {
		ll mid = max + (min-max)/2;
		if(array[mid]<key) {
			return GreaterBinarySearch(array,key,max,mid-1);
		} if(array[mid]>key) {
			return GreaterBinarySearch(array,key,mid+1,min);
		} else {
			return mid;
		}
	}
}

bool Palind(string s) {
	return s == string(s.rbegin(), s.rend());
}

int main() {
	int N; cin>>N;
	string S; cin>>S;
	int result=0;

	for(int i=0; i<1000; i++) {
		int j;
		for(j=0; j<N-2; j++)
			if(S.at(j)-'0'==i/100)
				break;
		if(j==N-2) continue;

		for(j++; j<N-1; j++)
			if(S.at(j)-'0'==i/10%10)
				break;
		if(j==N-1) continue;

		for(j++; j<N; j++)
			if(S.at(j)-'0'==i%10)
				break;
		if(j==N) continue;

		result++;
	}

	cout<<result<<endl;
}


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

int main() {

	int codes[20][20];
	int B[20];
	int source, tokutyou, hasuu;
	int sum = 0;
	int counter = 0;

	cin >> source >> tokutyou >> hasuu;

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

	for (int i = 0; i < source; i++) {
		for (int k = 0; k < tokutyou; k++) {
			cin >> codes[i][k];
			sum += codes[i][k] * B[k];
		}
		if (sum + hasuu > 0) {
			counter++;
		}
		sum = 0;
	}

	cout << counter << endl;

	return 0;
}
//*/

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

public class Main {
	static long max = 1000000000000000000L;

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		String eatEmpty = sc.nextLine();
		String input = sc.nextLine();
		String tempInput = " " + input + " ";
		if (tempInput.contains(" 0 "))
			System.out.println(0);
		else {
			String nums[] = input.split(" ");
			double logAns = 0;
			long ans = 1;
			while (--N >= 0) {
				long temp = Long.parseLong(nums[N]);
				logAns += Math.log10(temp);
				ans *= temp;
			}
//			System.out.println(logAns + " " + ans + " " + max);
			if (logAns > 18.1 || ans > max || ans <= 0)
				System.out.println(-1);
			else
				System.out.println(ans);
		}
		sc.close();

	}
}


Measured memory_bytes: 62208
/**
*    author:  souzai32
*    created: 22.08.2020 21:03:51
**/

#include <bits/stdc++.h>
#define all(x) (x).begin(),(x).end()
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using ll = long long;
typedef long long ll;
using namespace std;

int main() {

    string n;
    cin >> n;
    int sum=0;
    rep(i,n.size()){
        sum+=n[i]-'0';
        sum%=9;
    }
    if(sum) cout << "No" << endl;
    else cout << "Yes" << endl;

    return 0;
}

Measured memory_bytes: 3744
use proconio::input;

fn diff(a: &[u8]) -> i32 {
    let n: i32 = (a[0] - b'0') as i32 * 100
        + (a[1] - b'0') as i32 * 10
        + (a[2] - b'0') as i32;
    if n >= 753 {
        n - 753
    } else {
        753 - n
    }
}

fn main() {
    input!{
        s: String,
    }
    let sv = s.as_bytes().to_vec();
    let mut mind = std::i32::MAX;
    for i in 0..sv.len()-2 {
        let d = diff(&sv[i..i+3]);
        if mind > d {
            mind = d;
        }
    }
    println!("{}", mind);
}


Measured memory_bytes: 2140