akhauriyash/Code-Regression huggingface dataset:
/*
  "I knew I shouldn't have
   gotten out of bed today."
   - Squidward Tentacles
*/
#include<iostream>
#include<algorithm>
#include<bitset>
#include<cmath>
#include<cstring>
#include<climits>
#include<numeric>

#include<deque>
#include<queue>
#include<vector>
#include<set>
#include<map>
#include<unordered_map>
// #include<ext/pb_ds/assoc_container.hpp>
// #include<ext/pb_ds/tree_policy.hpp>

#include<fstream>
#include<chrono>
using namespace std;
// using namespace __gnu_pbds;

#define int          long long
#define ld           long double
#define pii          pair<int,int>
#define vi           vector<int>
#define maxheap      priority_queue<int>
#define minheap      priority_queue<int,vi,greater<int>>
#define pb           push_back
#define mp           make_pair
#define ff           first
#define ss           second
#define endl         '\n'
#define rep(i,s,e)   for(int i=s;i<=e;i++)
#define brep(i,s,e)  for(int i=s;i>=e;i--)
#define all(x)       (x).begin(),(x).end()
#define ball(x)      (x).rbegin(),(x).rend()
#define sz(x)        (int)x.size()
#define mem(x,y)     memset(x,y,sizeof(x))
#define pbds         tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update>
#define VR46         ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);

const int MOD = 1e9+7;
ld EPS = 1e-12;

signed main()
{
    VR46 ofstream out("output.txt");
    // auto start = chrono::high_resolution_clock::now();

    // GANDU TEST CASE BNAKE TEST KRLE
    // OUT OF BOUNDS BHI DEKHLIO CHUTIYE
    int t = 1;
    // cin>>t;
    rep(test,1,t)
    {
        bool pr[4];
        mem( pr,false );
        int a, b;
        cin>>a>>b;
        pr[a] = pr[b] = true;
        rep(i,1,3) if( !pr[i] ) cout<<i<<endl;
    }

    // auto stop = chrono::high_resolution_clock::now();
    // auto duration = chrono::duration_cast<chrono::milliseconds>(stop - start); 
    // cout<<"Time taken by function: "<<duration.count()<<" milliseconds"<<endl;

    // *( hsh.find_by_order(k) ) kth smallest, from 0
    // hsh.order_of_key(k) num of ele str less than k
    // change less to less_equal for multiset pbds
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define endl "\n"
#define IOS ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define int long long
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define BS binary_search
#define all(c) (c).begin(),(c).end()
#define sz(x) (int)(x).size()
#define get(a,t) get<a>(t)
#define EPS 0.000000001 //1e-9
using pii=pair<int,int>;
const int INF=1e18;

void dprint(string s) { cout << endl;}
void dprint() { cout << endl;}
template <class T, class... U> void dprint(string s, T t, U... u) 
{int w=s.find(','); cout <<"["<< s.substr(0,w) << ": " << t << "] " ; dprint(s.substr(w+1, sz(s)-w), u...);} 


#define DEBUG 
#ifdef DEBUG
#define dbg(X...) dprint(#X,X)
#else
#define dbg(X...); 
#endif
const int N=100005;

int32_t main()
{
	IOS;
	int s,w; cin>>s>>w;
	if(w>=s)
		cout<<"unsafe";
	else 
		cout<<"safe";
	return 0;
}

Measured memory_bytes: 3640
import java.util.Scanner;


public class Main {
	
	public static class BIT {
		int[] dat;
		
		public BIT(int n){
			dat = new int[n + 1];
		}
		
		public void add(int k, int a){ // k : 0-indexed
			for(int i = k + 1; i < dat.length; i += i & -i){
				dat[i] += a;	
			}
		}
		
		public int sum(int s, int t){ // [s, t)
			if(s > 0) return sum(0, t) - sum(0, s);
			
			int ret = 0;
			for(int i = t; i > 0; i -= i & -i) {
				ret += dat[i];
			}
			return ret;
		}
		
		public int get(int k){ // k : 0-indexed
			int p = Integer.highestOneBit(dat.length - 1);
			for(int q = p; q > 0; q >>= 1, p |= q){
				if( p >= dat.length || k < dat[p]) p ^= q;
				else k -= dat[p];
			}
			return p;
		}
	}
	
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		
		while(true){
			final int n = sc.nextInt();
			final int k = sc.nextInt();
			
			if(n == 0 && k == 0){
				break;
			}
			
			BIT bit = new BIT(n);
			for(int i = 0; i < n; i++){
				bit.add(i, sc.nextInt());
			}
			
			int max = Integer.MIN_VALUE;
			for(int start = 0; start < n - k + 1; start++){
				max = Math.max(max, bit.sum(start, start + k));
				//System.out.println("[" + start + " " + (start + k) + ") = " + bit.sum(start, start + k));
			}
		
		System.out.println(max);
		}
	}
}

Measured memory_bytes: 63896
using System;
using System.Linq;
using System.Collections.Generic;
using static System.Console;
using System.Text;
using System.IO;
using static System.Math;
namespace AtCoder
{
    class Program
    {
        static public long[] Sarray() { return ReadLine().Split().Select(long.Parse).ToArray(); }
        static public List<long> Slist() { return ReadLine().Split().Select(long.Parse).ToList(); }

        static readonly long Mod = 1000000000 + 7;
        static void Main(string[] args)
        {
            var NK = Sarray();
            var N = NK[0];
            var K = NK[1];
            var H = Sarray();

            var ans = H.Where(h => h >= K).Count();
            WriteLine(ans);
        }
    }
}

Measured memory_bytes: 20320
from sys import setrecursionlimit; setrecursionlimit(10**9)
N, A, B, C = map(int, input().split())
L = []
for _ in range(N):
    L.append(int(input()))

# def argmin(array):
#     return min(enumerate(array), key=lambda x:x[1])

# def change_len(L):
#     cons = 0
#     R = list(map(lambda x: abs(x-A), L))
#     cons += min(R)
#     L.pop(argmin(R)[0])
#     S = list(map(lambda x: abs(x-B), L))
#     cons += min(S)
#     L.pop(argmin(S)[0])
#     T = list(map(lambda x: abs(x-C), L))
#     cons += min(T)
#     L.pop(argmin(T)[0])
#     return cons

def change_len(L):
    L.sort()
    return abs(L[0]-C) + abs(L[1]-B) + abs(L[2]-A)

def rec(i, a, b, c, comb, cons):
    if i == N:
        if 0 not in [a, b, c]:
            comb.append([a, b, c, cons])
        return None

    # if n < 3:
    #     return
    v = 0 if a == 0 else 10
    rec(i+1, a+L[i], b, c, comb, cons+v)
    v = 0 if b == 0 else 10
    rec(i+1, a, b+L[i], c, comb, cons+v)
    v = 0 if c == 0 else 10
    rec(i+1, a, b, c+L[i], comb, cons+v)
    rec(i+1, a, b, c, comb, cons)
    return comb

comb = rec(0, 0, 0, 0, [], 0)
minval = 10**9
for c in comb:
    minval = min(minval, change_len(c[:3]) + c[3])
print(minval)

Measured memory_bytes: 10100
n, m = gets.chomp.split.map(&:to_i)

x = []
y = []
z = []

n.times do
  a, b, c = gets.chomp.split.map(&:to_i)
  x.push a
  y.push b
  z.push c
end

if m == 0
  puts 0
  exit 0
end

def fun(x,y,z,m)
  ar = []
  x.size.times do |i|
    ar.push x[i]+y[i]+z[i]
  end
  ar.sort.last(m).inject(:+)
end

ans = []

ans.push fun(x,y,z,m)
ans.push fun(x,y,z.map{|e|-e},m)
ans.push fun(x,y.map{|e|-e},z,m)
ans.push fun(x,y.map{|e|-e},z.map{|e|-e},m)

ans.push fun(x.map{|e|-e},y,z,m)
ans.push fun(x.map{|e|-e},y,z.map{|e|-e},m)
ans.push fun(x.map{|e|-e},y.map{|e|-e},z,m)
ans.push fun(x.map{|e|-e},y.map{|e|-e},z.map{|e|-e},m)

puts ans.max


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

struct input_pair {
    int num;
    int val;
};

bool operator<(const input_pair& left, const input_pair& right) {
    return left.val < right.val;
}

bool operator>(const input_pair& left, const input_pair& right) {
    return left.val > right.val;
}

input_pair make_input_pair (int num, int val) {
    input_pair tmp = {num, val};
    return tmp;
}

int main() {
    int n, m;
    cin >> n >> m;
    vector<long> a;
    vector<input_pair> inputs;
    vector<long> d;

    for (int i = 0; i < n; i++) {
        int tmp;
        cin >> tmp;
        a.push_back(tmp);
    }
    sort(a.begin(), a.end());

    for (int i = 0; i < m; i++) {
        int max_index;
        long new_val;
        cin >> max_index >> new_val;
        inputs.push_back(make_input_pair(max_index, new_val));
    }
    sort(inputs.begin(), inputs.end(), greater<input_pair>());

    for (int i = 0; i < inputs.size(); i++) {
        while (inputs[i].num > 0) {
            d.push_back(inputs[i].val);
            if (d.size() >= n) break;
            inputs[i].num--;
        }
    }

    for (int i = 0; i < n; i++) {
        if (a[i] < d[i])
            a[i] = d[i];
        else
            break;
    }

    long sum = 0;
    for (int i = 0; i < a.size(); i++) {
        sum += a[i];
    }
    cout << sum << endl;

    return 0;
}


Measured memory_bytes: 3956
N, M = map(int, input().split())
S = []
for _ in range(M):
    S.append(list(map(int, input().split()))[1:])
P = list(map(int, input().split()))
ans = 0
for bit in range(1 << N):
    for m in range(M):
        if sum([bit & (1 << (s-1)) > 0 for s in S[m]]) % 2 != P[m]:
            break
    else:
        ans += 1
print(ans)


Measured memory_bytes: 3064
s=input()
n=len(s)
m=s[0:(n-1)//2]
p=s[(n+3)//2-1:]
if s!=s[::-1]:
    print("No")
    quit()
elif m!=m[::-1]:
    print("No")
    quit()
elif p!=p[::-1]:
    print("No")
    quit()
print("Yes")

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
#define PB push_back
#define MP make_pair
#define fora(i,a,b) for(int i = a ; i<b ;i++)
typedef long long ll;
typedef int i;
typedef vector<i>vi;
typedef pair<i,i>pi;

ll v[100010];
ll dp[100010];
ll k;
ll f(int i){
    if(i == 0) return 0;
    if(i < 0) return 1e12;
    ll &r = dp[i];
    if(r!=-1) return r;
    r = 1e12;
    for(int j = 1 ; j <= k ; j++){
        r = min(r,f(i-j)+abs(v[i]-v[i-j]));
    }
    return r;
}
int main(){
    //freopen("in.txt","r",stdin);
    ios::sync_with_stdio(0);
    cin.tie(0);
    int n;
    while(cin>>n>>k){
        fora(i,0,n)cin>>v[i];
        memset(dp,-1 , sizeof dp);
        cout<<f(n-1)<<"\n";
    }

    return 0;
}

Measured memory_bytes: 11428
import java.util.*

fun f(a: Long, x: Long): Long {
    if (a == -1L) {
        return 0
    }
    return a / x + 1
}

fun main(args: Array<String>) {
    val sc = Scanner(System.`in`)
    val a = sc.nextLong()
    val b = sc.nextLong()
    val x = sc.nextLong()
    println(f(b, x) - f(a - 1, x))
}

Measured memory_bytes: 31400
A, B, C, D, E, F = gets.chomp.split(" ").map(&:to_i)

a = Array.new(F/(100*A)+1).map.with_index{|x, i| 100*A*i}
b = Array.new(F/(100*B)+1).map.with_index{|x, i| 100*B*i}
w = a.product(b).map{|x, y| (x + y) / 100}.select{|z| z <= F/100}.uniq.sort
tmp = F/100*E
c = Array.new(tmp/C + 1).map.with_index{|x, i| C*i}
d = Array.new(tmp/D + 1).map.with_index{|x, i| D*i}
s = c.product(d).map{|x, y| x + y}.select{|z| z <= tmp}.uniq.sort
ans = [-1, 0, 0]
w.each{|wa|
  idx = s.bsearch_index{|x| x > [wa * E, F-wa*100].min}
  next if idx == 0
  idx = s.size if idx.nil?
  next if (wa * 100 + s[idx-1]) > F
  wk = s[idx-1].to_f / (wa * 100 + s[idx-1])
  ans = [wk, wa*100 + s[idx-1], s[idx-1]] if ans[0] < wk
}

ans.shift
puts ans.join(" ")


Measured memory_bytes: 34556
#include "bits/stdc++.h"
using namespace std;
int main(){
    int n,i,j,k,l,m;
    cin >> n;
    int A[4][3][10];
    for(i=0;i<4;i++){
        for(j=0;j<3;j++){
            for(k=0;k<10;k++){
                A[i][j][k]=0;
            }
        }
    }
    for(i=0;i<n;i++){
        cin >> j>>k>>l>>m;
        A[j-1][k-1][l-1] += m;
    }
    for(i=0;i<4;i++){
        if(i){
            for(j=0;j<20;j++) cout << "#";
            cout << endl;
        }
        for(j=0;j<3;j++){
            for(k=0;k<10;k++){
                cout << " " << A[i][j][k];
            }
            cout << endl;
        }
    }
    return 0;
}


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

int main()
{
	int n;
	cin >> n;
	vector<int> p( n + 1 );
	for( int i = 1; i < n + 1; i++ ) {
		cin >> p[i - 1] >> p[i];
	}

	vector<vector<int>> m( n + 1, vector<int>( n + 1 ) );
	for( int l = 2; l < n + 1; l++ ) {
		for( int i = 1; i < n - l + 1 + 1; i++ ) {
			int j = i + l - 1;
			m[i][j] = INT32_MAX / 4;
			for( int k = i; k < j; k++ ) {
				m[i][j] = min( m[i][j], m[i][k] + m[k + 1][j] + p[i - 1] * p[k] * p[j] );
			}
		}
	}

	cout << m[1][n] << endl;
}



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

int main() {
    int N,K;
    cin >> N >> K;
    vector<int> p(N);
    rep(i,N){
        cin >> p[i];
    }
    sort(p.begin(), p.end());
    int sum = 0;
    rep(i,K){
        sum += p[i];
    }
    cout << sum << endl;
    return 0;
}

Measured memory_bytes: 3632
#include<stdio.h>

int main(void)
{
  int x, y;
  int TimeSum;
  int Time1, Time2, Time3, Time4;

  scanf("%d %d %d %d", &Time1, &Time2, &Time3, &Time4);

  TimeSum = Time1 + Time2 + Time3 + Time4;

  y = TimeSum % 60;
  x = (TimeSum - y) / 60;

  printf("%d\n%d\n", x, y);

  return 0;
}

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

using namespace std;

int n, m;
vector <int> edge[100005];
long long ways[100005], ans[100005];

void pre(int id, int p) {
	ways[id] = 1LL;
	for (int i = 0; i < edge[id].size(); i++) {
		int to = edge[id][i];
		if (to == p) continue;
		pre(to, id);
		ways[id] = (ways[id] * ways[to]) % m;
	}
	ways[id] = (ways[id] + 1) % m;
}

void solve(int id, int p, int cool) {
	ans[id] = cool;
	vector <long long> l, r;
	
	for (int i = 0; i < edge[id].size(); i++) {
		int to = edge[id][i];
		if (to == p) continue;
		ans[id] = (ans[id] * ways[to]) % m;
		l.push_back(ways[to]);
	}
	r = l;
	
	for (int i = 1; i < l.size(); i++) l[i] = (l[i - 1] * l[i]) % m;
	for (int i = r.size() - 2; i >= 0; i--) r[i] = (r[i + 1] * r[i]) % m;
	
	int child = 0;
	
	for (int i = 0; i < edge[id].size(); i++) {
		int to = edge[id][i];
		if (to == p) continue;
		long long tmp = cool;
		if (child - 1 >= 0) tmp = (tmp * l[child - 1]) % m;
		if (child + 1 < r.size()) tmp = (tmp * r[child + 1]) % m;
		tmp = (tmp + 1) % m;
		solve(to, id, tmp);
		child++;
	}
}

int main() {
	scanf("%d%d", &n, &m);
	
	for (int i = 0; i < n - 1; i++) {
		int x, y;
		scanf("%d%d", &x, &y);
		edge[x].push_back(y);
		edge[y].push_back(x);
	}
	
	pre(1, -1);
	solve(1, -1, 1);
	
	for (int i = 1; i <= n; i++) printf("%lld\n", ans[i]);
}


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

typedef long long ll;
typedef unsigned long long ull;
typedef double dd;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int,int> pii;

const int mx=1e6+11;
const double PI = acos(-1);
#define MOD 1000000007

#define nl '\n'
#define pb push_back
#define F first
#define S second
#define I insert
#define mp make_pair

#define sz(x) x.size()
#define tt int t; cin>>t; while(t--)
#define be(a) (a).begin(),(a).end()
#define rbe(a) (a).rbegin(),(a).rend()
#define mem(a,b) memset(a,b,sizeof(a))
#define yes cout<<"YES"<<nl
#define no cout<<"NO"<<nl

#define su ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define file freopen("input.txt","r",stdin);freopen("output.txt","w",stdout);
#define frac cout.unsetf(ios::floatfield); cout.precision(10); cout.setf(ios::fixed,ios::floatfield);

void f()
{
  int a,b,c;
  cin>>a>>b>>c;
  (b/a>c)?cout<<c<<nl:cout<<b/a<<nl;
}

int main()
{
    su;
    f();
    return 0;
}


Measured memory_bytes: 3620
using System;

class Program
{
    static void Main(string[] args)
    {
        var NK = Console.ReadLine().Trim().Split(' ');
        var K = int.Parse(NK[1]);
        var S = Console.ReadLine().Trim();

        Console.WriteLine(S.Remove(K - 1, 1).Insert(K - 1, S[K - 1].ToString().ToLowerInvariant()));
    }
}

Measured memory_bytes: 13140
#include <iostream>
#include<string>
#include<cmath>
#include<algorithm>
#include<cctype>
#include<queue>
#include<deque>
#include<regex>
#include<stack>
#include<stdio.h>
#include<vector>
#include<set>
#include<map>
#include<iomanip>
#define rep(i,n) for(int i=0;i<n;i++)

typedef int long long ll;
using namespace std;
typedef pair<int,int> P;
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};
const ll MOD=1e9+7;
static const int MAX = 100;
static const int INF = (1<<23);
template<class T> T gcd(T a, T b){return b? gcd(b,a%b) : a;}
template<class T> T lcm(T a,T b){return a / gcd(a,b)*b;}

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

    ll r=1,l=n+1;
    ll ans = a/b-a*(1/b);

    ll j=0;

    while(j!=100000){
        j++;
        ll mid = (r+l)/2;
        ll x = (a*mid)/b-a*(mid/b);
     //   cout<<l<<" "<<r<<" "<<x<<endl;
        if(ans<=x){
            r=mid;
            ans =x;
        }else{
            l=mid;
        }

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


Measured memory_bytes: 3636
#include<iostream>
#include<algorithm>
#include<climits>
#include<cmath>
#include<cstdio>
#include<cstdlib>
#include<ctime>
#include<string>
#include<cstring>
#include<vector>
#include<stack>
#include<queue>
#include<set>
#include<bitset>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;

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

#define mod 1000000007LL
#define eps 0.0001
#define pi acos(-1)
#define INF 10000000000000000

#define rep(i, n) for(int i = 0;i < n;++i)
#define rep1(i, n) for(int i = 1;i < n;++i)
#define pri(x) cout << (x) << "\n"
#define pri2(x, y) cout << (x) << " " << (y) << "\n"
#define pri3(x, y, z) cout << (x) << " " << (y) << " " << (z) << "\n"
#define chmin

    string s;
    ll ans= 0;

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    // ---------------------
    // コーディング開始
    // ---------------------
    cin >> s ;
    ll ssize = s.length();
    for (ll i = 0; i < ssize; i++){
        for (ll j = 0; j < ssize - i; j++){
            //pri(1<<j);
            ans += (s[i]-'0')*pow(10ll,j)*(1 << max(ssize-1-i-j -1,0ll)) * (1 << i);
            //pri(ans);
        }
    }
    pri (ans);

    return 0;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ll int
#define ff first
#define ss second
#define pb push_back
#define vi vector<ll>
#define all(_x) _x.begin(), _x.end()
#define rep(i, s, e) for (ll i = s; i < e; i++)
#define lb(_x, _a) (lower_bound(all(_x), _a) - _x.begin())
#define ub(_x, _a) (upper_bound(all(_x), _a) - _x.begin())

int main()
{
  	// ll is int now
    
    ll n, x, y; cin>>n>>x>>y;
    vector<int> arr(n+10,0);
    for(int i=x+1; i<=n; i++)
    {
        arr[i] = min(i-x, 1 + abs(y - i));
    }
    vi dist(n+1, 0);
    for(ll i=1; i<=n-1; i++)
    {
        for(ll j=i+1; j<=n; j++)
        {
            //i to j dist
            // if(j<=x)
            // {
            //     dist[j-i]++;
            //     continue;
            // }   
            //min j-i or i to x + x to j
            dist[min(j-i, abs(x-i)+ arr[j])]++;
        }
    }
    for(ll i=1; i<=n-1; i++) cout<<dist[i]<<endl;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using G = vector<vector<int>>;
class Pos {
public:
    int node, rank;
    Pos(int node, int rank) : node(node), rank(rank) {};
};

void solve() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);

    int N, X, Y;
    cin >> N >> X >> Y;
    G g(N);
    g[X-1].push_back(Y-1);
    g[Y-1].push_back(X-1);
    for (int i = 0; i < N - 1; ++i) {
        g[i].push_back(i+1);
        g[i+1].push_back(i);
    }
    vector<int> ans(N, 0);
    for (int i = 0; i < N; ++i) {
        queue<int> q;
        q.push(i);
        vector<bool> memo(N, false);
        memo[i] = true;
        vector<int> dis(N);
        dis[i] = 0;
        while (!q.empty()) {
            int node = q.front();
            q.pop();
            for (int e: g[node]) {
                if (memo[e]) continue;
                memo[e] = true;
                dis[e] = dis[node] + 1;
                q.push(e);
            }
        }
        for (int j = 0; j < N; ++j) {
            ans[dis[j]]++;
        }
    }
    for (int i = 1; i < N; ++i) {
        cout << ans[i] / 2 << endl;
    }
    return;
}

int main() {
    solve();
    return 0;
}


Measured memory_bytes: 384
//
//  755.cpp
//  my_programs
//
//  Created by Jiatuo Zou on 9/16/20.
//  Copyright © 2020 Jiatuo Zou. All rights reserved.
//

#include <iostream>

using namespace std;

int Search(int n, int digits, int hasNumber[], int d, int numbers[], int sum, int value){
    if(d == digits){
        for(int i = 0; i < 3; i++){
            if(hasNumber[i] == 0){
                return 0;
            }
        }
        if(value > n){
            return 0;
        }
        return 1;
    }
    for(int i = 0; i < 3; i++){
        hasNumber[i]++;
        int x = numbers[i];
        for(int j = d; j < digits - 1; j++){
            x *= 10;
        }
        value += x;
        sum += Search(n, digits, hasNumber, d + 1, numbers, 0, value);
        value -= x;
        hasNumber[i]--;
    }
    return sum;
}

int main()
{
    int n, numbers[3] = {3, 5, 7}, digits = 0, hasNumber[3] = {0}, ans = 0;
    cin >> n;
    int f = n;
    while(n > 0){
        digits++;
        n /= 10;
    }
    for(int i = 3; i <= digits; i++){
        ans += Search(f, i, hasNumber, 0, numbers, 0, 0);
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 3580
#include <bits/stdc++.h>
#define ll long long
#define pb push_back
#define mp make_pair
#define MOD 1000000007
using namespace std;

// int prime[1000001];
// vector<ll> primes;

// void soe() {
//     int i,j;
//     for(i=2;i<1000001;i++) prime[i] = 1;
//     for(i=2;i<=sqrt(1000001);i++) {
//         if(prime[i] == 1) {
//             for(j=i*i;j<1000001;j+=i) {
//                 prime[j] = 0;
//             }
//         }
//     }
//     for(i=2;i<1000001;i++) {
//         if(prime[i]) primes.pb(i);
//     }
// }

int d[10];

bool valid(int n) {
    while(n) {
        if(d[n%10]) return false;
        n/=10;
    }
    return true;
}

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

    stack<string> st;
    string s, res = "";
    cin >> s;
    int i=0;
    while(s[i]) {
        if(s[i] == '0') st.push("0");
        else if(s[i] == '1') st.push("1");
        else if(s[i] == 'B' && !st.empty()) st.pop();
        i++;
    }
    while(!st.empty()) {
        res+=st.top();
        st.pop();
    }
    reverse(res.begin(), res.end());
    cout << res << "\n";
    return 0;
}




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

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        ArrayList<Integer> x = new ArrayList<>();
        while(true) {
            x.add(sc.nextInt());
            if(x.contains(0)) {
                break;
            }
        }
        sc.close();

        for(int i=0; i<x.size()-1; i++) {
            int c = i+1;
            System.out.println("Case " + c + ": " + x.get(i));
        }
    }
}



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

int main() {
    int n;
    while (cin >> n, n) {
        int five = 0;
        for (int i=1; i<=n; ++i) {
            int t = i;
            while (t % 5 == 0) {
                five ++;
                t /= 5;
            }
        }
        cout << five << endl;
    }
    return 0;
}

Measured memory_bytes: 1160
h, w, m = map(int, input().split())

count_h = [0 for i in range(h)]
count_w = [0 for i in range(w)]
points = set()
for i in range(m):
    y, x = map(int, input().split())
    y -= 1
    x -= 1
    points.add((y, x))
    count_h[y] += 1
    count_w[x] += 1

ch_max, cw_max = max(count_h), max(count_w)
ys = [y for y in range(len(count_h)) if count_h[y] == ch_max]
xs = [x for x in range(len(count_w)) if count_w[x] == cw_max]

    
ans = ch_max + cw_max
if len(ys) * len(xs) <= m:
    def _find():
        for x in xs:
            for y in ys:
                if (y, x) not in points:
                    return True
        return False
    if not _find():
        ans -= 1
print(ans)


Measured memory_bytes: 83640
#include<bits/stdc++.h>
#define ll long long
#define maxn 200010
using namespace std;
struct data{int x, pos;};
int a[maxn], b[maxn], c[maxn], used[maxn];
data A[maxn];
bool cmp(data a, data b) {return a.x < b.x;}
int main()
{
	int n;
	scanf("%d", &n);
	for (int i = 1; i <= n; i++)
	{
		scanf("%d%d", &a[i], &b[i]);
		A[i] = (data){a[i], i};
		A[i + n] = (data){b[i], i};
	}
	ll res = 0, sum = 0;
	for (int i = 1; i <= n; i++)
		sum += a[i];
	res = sum;
	sum = 0;
	for (int i = 1; i <= n; i++)
		sum += b[i];
	res = min(res, sum);
	sort(A + 1, A + 2 * n + 1, cmp);
	sum = 0;
	for (int i = 1; i <= n; i++)
	{
		used[A[i].pos]++;
		sum += A[i].x;
	}
	for (int i = 1; i <= n; i++)
		if (used[i] == 2) res = min(res, sum);
	for (int i = 1; i <= n; i++)
		if (used[i] == 1)
		{
			ll tmp = sum + max(a[i], b[i]);
			if (A[n].pos == i) tmp -= A[n - 1].x;
			else tmp -= A[n].x;
			res = min(res, tmp);
		}
		else if (used[i] == 0)
		{
			ll tmp = sum + a[i] + b[i] - A[n].x - A[n - 1].x;
			res = min(res, tmp);
		}
	printf("%lld\n", res);
	return 0;
}

Measured memory_bytes: 4480
#include <cstdio>
#include <algorithm>
#define NIL -1
#define rep(i,n) for(int i=0; i<(n); ++i)
struct Node{
  int p,l,r;
  Node(): p(NIL), l(NIL), r(NIL){};
};

int N;
Node T[30];
int D[30];
int H[30];

void setDepth(int u, int p){
  if(u == NIL)return;
  D[u] = p;
  setDepth(T[u].l, p+1);
  setDepth(T[u].r, p+1);
}

int setHight(int u){
  int hl = 0, hr = 0;
  if(~T[u].l)hl = setHight(T[u].l)+1;
  if(~T[u].r)hr = setHight(T[u].r)+1;
  return H[u] = std::max(hl, hr);
}

int getSibling(int u){
  if(T[u].p == NIL)return NIL;
  const int p = T[u].p;
  if(T[p].l != u && T[p].l != NIL)return(T[p].l);
  if(T[p].r != u && T[p].r != NIL)return(T[p].r);
  return(NIL);
}

inline int getDeg(int u){return( 0 + (T[u].l != NIL) + (T[u].r != NIL) );}

void print(int u){
  printf("node %d: parent = %d, sibling = %d, degree = %d, depth = %d, height = %d, %s\n",
    u, T[u].p, getSibling(u), getDeg(u), D[u], H[u],
    T[u].p == NIL ? "root"
      : (T[u].l == NIL && T[u].r == NIL)? "leaf"
      : "internal node"
  );
}

main()
{
  int id, lf, ri;
  int root;
  scanf("%d", &N);

  rep(i,N){
    scanf("%d %d %d", &id, &lf, &ri);
    T[id].l = lf, T[id].r = ri;
    if(~lf)T[lf].p = id;
    if(~ri)T[ri].p = id;
  }

  rep(i,N)
    if(T[i].p == NIL){root = i; break;}
  setDepth(root, 0);
  setHight(root);

  rep(i,N)print(i);
}

Measured memory_bytes: 2688
use std::io;
use std::io::Read;
use std::process;

fn main() {
    let mut buf = String::new();

    io::stdin().read_to_string(&mut buf).expect("sho");
    let mut iter = buf.split_whitespace();

    let N: usize = iter.next().unwrap().parse().unwrap();
    if N < 2 {
        println!("Hello World");
        process::exit(0);
    }
    let A: usize = iter.next().unwrap().parse().unwrap();
    let B: usize = iter.next().unwrap().parse().unwrap();

    println!("{}", A+B);
}

Measured memory_bytes: 4352
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const ll INF = 1e18;
const ll mod = 1000000007;

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
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;
}
int ctoi(char c) {
  if (c >= '0' && c <= '9') {
    return c - '0';
  }
  return 0;
}
ll factorial(ll n) {
  if (n == 1) {
    return 1;
  }
  ll ans = factorial(n-1);
  return ans*n;
}
ll gcd(ll a, ll b) {
  if (a < b) {
    ll tmp = a;
    a = b;
    b = tmp;
  }
  ll r = a%b;
  while(r != 0) {
    a = b;
    b = r;
    r = a%b;
  }
  return b;
}
ll lcm(ll a, ll b) {
  return (a/gcd(a, b))*b;
}
bool prime(ll n) {
  if (n == 1) {
    return false;
  } else {
    for (ll i = 2; i <= (ll)pow(n, 0.5); i++) {
      if (n%i == 0) return false;
    }
  }
  return true;
}
ll RepeatSquaring(ll n, ll p, ll m) {
  if (p == 0) return 1;
  if (p%2 == 0) {
    ll t = RepeatSquaring(n, p/2, m);
    return (t*t)%m;
  }
  return (n*RepeatSquaring(n, p-1, m))%m;
}

int main() {
  ll n, m;
  cin >> n;
  set <ll> s;
  ll a;
  rep(i, n) {
    cin >> a;
    s.insert(a);
  }
  cin >> m;
  rep(i, m) {
    cin >> a;
    if (s.count(a)) {
      cout << a << endl;
    }
  }
}


Measured memory_bytes: 12432
X,Y = list(map(int, input().split()))

class Combination:
    """
    O(n)の前計算を1回行うことで，O(1)でnCr mod mを求められる
    n_max = 10**6のとき前処理は約950ms (PyPyなら約340ms, 10**7で約1800ms)
    使用例：
    comb = Combination(1000000)
    print(comb(5, 3))  # 10
    """
    def __init__(self, n_max, mod=10**9+7):
        self.mod = mod
        self.modinv = self.make_modinv_list(n_max)
        self.fac, self.facinv = self.make_factorial_list(n_max)

    def __call__(self, n, r):
        return self.fac[n] * self.facinv[r] % self.mod * self.facinv[n-r] % self.mod

    def make_factorial_list(self, n):
        # 階乗のリストと階乗のmod逆元のリストを返す O(n)
        # self.make_modinv_list()が先に実行されている必要がある
        fac = [1]
        facinv = [1]
        for i in range(1, n+1):
            fac.append(fac[i-1] * i % self.mod)
            facinv.append(facinv[i-1] * self.modinv[i] % self.mod)
        return fac, facinv

    def make_modinv_list(self, n):
        # 0からnまでのmod逆元のリストを返す O(n)
        modinv = [0] * (n+1)
        modinv[1] = 1
        for i in range(2, n+1):
            modinv[i] = self.mod - self.mod//i * modinv[self.mod%i] % self.mod
        return modinv
      
if (X+Y) % 3 > 0:
  print(0)
  exit(0)
  
K = (X+Y)//3

if X < K or Y < K:
  print(0)
  exit(0)

comb = Combination(K+10)
print(comb(K, X-K))

Measured memory_bytes: 82280
#include <iostream>
#include <string>
#include <algorithm>
#include <utility>
#include <set>
#include <vector>
#include <map>

using namespace std;

using ll = long long;

int main() {
    ll n; cin >> n;
    map<string, ll> m;
    while (n--) {
	string s; cin >> s;
	sort(begin(s), end(s));
	++m[s];
    }
    ll c = 0;
    for (auto x : m) {
	ll n = x.second - 1;
	c += n * (n+1) / 2;
    }
    cout << c << "\n";
    return 0;
}


Measured memory_bytes: 11136
fn main(){
 let input = {
     let mut input = String::new();
        std::io::stdin().read_line(&mut input).unwrap();
        input.trim_right().to_owned()
    };
    let (h, a) = {
     let mut ws = input.split_whitespace();
        let h: i32 = ws.next().unwrap().parse().unwrap();
        let a: i32 = ws.next().unwrap().parse().unwrap();
        (h, a)
    };
    
    let mut answer: i32 = h / a;
    if ( answer * a < h ){
    	answer = answer + 1;
    }
    print!("{}", answer);
}

Measured memory_bytes: 4352
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.UncheckedIOException;
import java.util.StringTokenizer;

class Main{
	public static void main(String[] args) {
		SC sc=new SC(System.in);
		int N=sc.nextInt();
		int K=sc.nextInt();
		int INF=1000000007;
		int[] dp=new int[N];
		int[] cost=new int[N];
		for(int i=0; i<N; i++) {
			cost[i]=sc.nextInt();
			dp[i]=INF;
		}
		dp[0]=0;
		if(N>=K) {
			for(int i=1; i<K; i++) {
				for(int j=0; j<i; j++) {
					dp[i]=Math.min(dp[i], dp[j]+Math.abs(cost[i]-cost[j]));
				}
			}
			for(int i=K; i<N; i++) {
				for(int j=i-K; j<i; j++) {
					dp[i]=Math.min(dp[i], dp[j]+Math.abs(cost[i]-cost[j]));
				}
			}
		}
		else {
			for(int i=1; i<N; i++) {
				for(int j=0; j<i; j++) {
					dp[i]=Math.min(dp[i], dp[j]+Math.abs(cost[i]-cost[j]));
				}
			}
		}
		pl(dp[N-1]);
	}
	public static void pl(Object o) {
		System.out.println(o);
	}
	public static void pl() {
		System.out.println();
	}
	public static void p(Object o) {
		System.out.print(o);
	}
	static class SC {
		private BufferedReader reader = null;
		private StringTokenizer tokenizer = null;
		public SC(InputStream in) {
			reader = new BufferedReader(new InputStreamReader(in));
		}
		public String next() {
			if (tokenizer == null || !tokenizer.hasMoreTokens()) {
				try {
					tokenizer = new StringTokenizer(reader.readLine());
				} catch (IOException e) {
					throw new UncheckedIOException(e);
				}
			}
			return tokenizer.nextToken();
		}
		public int nextInt() {
			return Integer.parseInt(next());
		}
		public long nextLong() {
			return Long.parseLong(next());
		}
		public double nextDouble() {
			return Double.parseDouble(next());
		}
		public String nextLine() {
			try {
				return reader.readLine();
			} catch (IOException e) {
				throw new UncheckedIOException(e);
			}
		}
	}
}

Measured memory_bytes: 34204
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<queue>
#include<map>
#include<math.h>
#include<iomanip>
#include<set>
#define REP(i, n) for(int i = 0;i < n;i++)
#define REPR(i, n) for(int i = n;i >= 0;i--)
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define FORR(i, m, n) for(int i = m;i >= n;i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define REVERSE(v,n) reverse(v,v+n);
#define VREVERSE(v) reverse(v.begin(), v.end());
#define llong long long
#define pb(a) push_back(a)
#define INF 9999999

using namespace std;

typedef pair<int, int> P;

int dy[4] = { 0,0,1,-1 };
int dx[4] = { 1,-1,0,0 };

int H, W;
//迷路を表す配列
char meiro[501][501];

//位置(x,y)からゴールまでたどり着けるか判定する
bool dfs(int x, int y) {
	//現在位置がゴールならOK
	if (meiro[x][y] == 'g') {
		return true;
	}

	//4方向について探索
	REP(i, 4) {
		//隣のマスの座標を(nx,ny)とする
		int nx = x + dx[i];
		int ny = y + dy[i];

		//移動後のマスが迷路に収まっているか、あるいは通れないマスでないか判定
		if (nx < 0 || nx >= H || ny < 0 || ny >= W || meiro[nx][ny] == '#')continue;
		//さっきまでいたマスを'#'で塗りつぶす
		meiro[x][y] = '#';
		if (dfs(nx, ny))return true;
	}
	return false;
}

int main() {
	int r, g, b;
	cin >> r >> g >> b;
	int c = 100 * r + 10 * g + b;
	if (c % 4 == 0)cout << "YES" << endl;
	else cout << "NO" << endl;
	return 0;
}


Measured memory_bytes: 256
import itertools
N,M,Q=map(int,input().split())
v=[[] for _ in range(Q)]
o=0
for i in range(Q):
    v[i]=list(map(int,input().split()))
l=list(itertools.combinations(range(M-1+N), N))
for x in l:
    s=0
    a=[]
    for i in range(N):
        a.append(x[i]-i+1)
    for i in range(Q):
        if a[v[i][1]-1]-a[v[i][0]-1]-v[i][2]==0:
            s+=v[i][3]
    if s>o:
        o=s
print(o)

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

int choose(vector <vector <int>> stores, int i, int n, int m, vector <int> books,
           int cost, vector <int> dp) {
	if (i == n) {
		for (int j = 1; j < m + 1; j++) {
			if (books[j] > 0) {
				return INT_MAX;
			}
		}
		return cost;
	}
	if (dp[i] > -1) {
		return dp[i];
	}
	int ans1 = choose(stores, i + 1, n, m, books, cost, dp);
	for (int j = 0; j < m + 1; j++) {
		books[j] -= stores[i][j];
	}
	int ans2 = choose(stores, i + 1, n, m, books, cost + stores[i][0], dp);
	int ans = min(ans1, ans2);
	dp[i] = ans;
	return ans;
}

void solve() {
	int n, m, x;
	cin >> n >> m >> x;

	vector <vector <int>> stores(n);
	for (int i = 0; i < n; i++) {
		for (int j = 0, ele; j < m + 1; j++) {
			cin >> ele;
			stores[i].push_back(ele);
		}
	}
	vector <int> books(m + 1, x);
	vector <int> dp(n + 1, -1);
	int ans = choose(stores, 0, n, m, books, 0, dp);
	if (ans == INT_MAX) {
		cout << -1;
	}
	else {
		cout << ans;
	}
}

int main() {
	ios_base::sync_with_stdio(0);
	cin.tie(0); cout.tie(0);
# ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
# endif
	solve();
	return 0;
}

Measured memory_bytes: 3676
from collections import Counter
N = int(input())
A = list(map(int, input().split()))

allCount = 0
c = Counter(A)

for i, v in c.items():
    if (v == 1):
        continue
    else:
        allCount += v * (v - 1) // 2


if (allCount == 0):
    for i in range(N):
        print(0)
    exit()

for i in range(N):
    a = allCount
    num = c[A[i]] - 1
    if (num == 1 or num == 0):
        print(allCount - num)
        continue
    old = c[A[i]] * (c[A[i]] - 1) // 2
    count = num * (num - 1) // 2
    print(a - old + count)


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

#define rep(i,n) for(i = 0;i < n;++i)
#define all(v) v.begin(), v.end()
using ll = long long;

int main()
{
    ll i,j;
    ll n;
    cin >> n;
    vector<pair<ll,ll>> a(n);
    for(i = 0;i < n;++i){
        cin >> a.at(i).first;
        a.at(i).second = i;
    }
    sort(all(a));
    ll ans = 0;
    for(i = 0;i < n;++i){
        ll ind = a.at(i).second;
        if((ind-i)%2) ++ans;
    }
    cout << ans/2 << endl;

    return 0;
}


Measured memory_bytes: 1792
#include <iostream>
#include <stdio.h>
#include <cstring>
#include <algorithm>
#define ll long long
using namespace std;
const int NUM=210;
ll travel[10000];
int n,m,num;
ll land[NUM][NUM],water[NUM][NUM],dp[10000][NUM];
ll solve();
int main()
{
    int u,v,c;
    char ch;
    while(~scanf("%d%d",&n,&m)&&n+m)
    {
        memset(land,0xf,sizeof land);
        memset(water,0xf,sizeof water);
        memset(dp,0xf,sizeof dp);
        for (int i=0; i<m; i++)
        {
            scanf("%d%d%d %c",&u,&v,&c,&ch);
            if (ch=='L')
                land[u][v]=land[v][u]=c;
            else
                water[u][v]=water[v][u]=c;
        }
        for (int i=1; i<=n; i++)
            land[i][i]=water[i][i]=0;
        scanf("%d",&num);
        for (int i=1; i<=num; i++)
            scanf("%d",&travel[i]);
        ll ans=solve();
        printf("%lld\n",ans);
    }
    return 0;
}
ll solve()
{
    for (int k=1; k<=n; k++)
        for (int i=1; i<=n; i++)
            for (int j=1; j<=n; j++)
            {
                water[i][j]=min(water[i][j],water[i][k]+water[k][j]);
                land[i][j]=min(land[i][j],land[i][k]+land[k][j]);
            }
    dp[1][travel[1]]=0;
    for (int i=1; i<=num; i++)
    {
        for (int j=1; j<=n; j++)
        {
            dp[i][j]=min(dp[i][j],dp[i-1][j]+land[travel[i-1]][travel[i]]);
            for (int k=1; k<=n; k++)
            {
                dp[i][k]=min(dp[i][k],dp[i-1][j]+land[travel[i-1]][j]+water[j][k]+land[k][travel[i]]);
            }
        }
    }
    ll ans=0x5fffffff;
    for (int i=1; i<=n; i++)
        ans=min(ans,dp[num][i]);
    return ans;
}



Measured memory_bytes: 20324
local str = io.read("*l")

local len = string.len(str)

local snum = 0
local tnum = 0
for i = 1,len do
	local j = string.sub(str,i,i)
	if j == "S" then
		snum = snum + 1
	elseif j == "T" then
		if snum > 0 then
			snum = snum - 1
		else
			tnum = tnum + 1
		end
	end
end
local ret = snum + tnum
print(ret)

Measured memory_bytes: 760
#include <bits/stdc++.h>
#define INF 100000000000
#define MOD 1000000007
#define ll long long int
#define REP(i, n) for (int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()



using namespace std;

int main(){
  int N; cin>>N;
  ll ans = 0;
  for(ll i = 1; i<=N;i++){
    if(i % 3 == 0 or i % 5 == 0) continue;
    else ans += i;
  }
  cout<<ans<<endl;

  
  return 0;
}

Measured memory_bytes: 3636
import java.util.*;
// warm-up
public class Main {

	static void solve() {
		Scanner sc = new Scanner(System.in);
		int n=sc.nextInt(), x=sc.nextInt(), t=sc.nextInt();
		int s = ((n/x)*t) + ((n%x>0) ? t : 0);
		System.out.println(s);
		sc.close();		
	}

	public static void main(String args[]) {
		solve();
	}

}


Measured memory_bytes: 35656
#include <cstdio>
#include <cstring>

int main()
{
	char sl[1001];
	int sum = 0;

	while (true) {
		scanf("%s", sl);

		if (sl[0] == '0')
			break;
		int len = strlen(sl);
		for (int i = 0; i < len; i++) {
			sum += sl[i] - '0';
		}
		printf("%d\n", sum);
		sum = 0;
	}
	return 0;
}


Measured memory_bytes: 2668
#include <stdio.h>
#include <stdlib.h>
int main(){
       int n;
       unsigned long long  a,b;
       scanf("%d%llu",&n,&a);
       for(int i=0;i<n-1;i++){
              scanf("%llu",&b);
              if(a%b==0) a=a;
              else if(b%a==0)a=b;
              else{
                     if(a<b){
                            a=a^b;
                            b=a^b;
                            a=a^b;
                     }
                     for(int  i=2;8;i++) if((a*i)%b==0){
                                   a=a*i;
                                   break;
                     }
              }
       }
       printf("%llu",a);
       return 0;
}


Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
#define ll long long
const int Mod=1e9+7;
map <ll ,int > f;
int solve(ll x){
	if (f[x]) return f[x];
	return f[x]=(((solve(x/2)+solve((x-1)/2))%Mod+solve((x-2)/2))%Mod);
}
int main (){
	f[0]=1,f[1]=2;
	ll n;scanf ("%lld",&n);
	printf ("%d",solve(n));
	return 0;
}

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

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

	int a, minv = (1<<21);
	for (int i = 0; i < s.size() - 2; i++) {
		a = (s[i] - '0') * 100 + (s[i + 1] - '0') * 10 + (s[i + 2] - '0');
		minv = min(minv, abs(753 - a));
	}

	cout << minv << endl;

	return 0;
}

Measured memory_bytes: 256
n, m = map(int, input().split())
a = list(map(int , input().split()))
t = [2,5,5,4,5,6,3,7,6]
cost = {ai: t[ai-1] for ai in a}

dp = [0] + [-1] * n

for i in range(n+1):
    tmp = []
    for ai, ci in cost.items():
        if i - ci >= 0 and dp[i-ci] >= 0:
            tmp.append(dp[i-ci] * 10 + ai)
    if len(tmp) > 0:
        dp[i] = max(tmp)
print(dp[n])

Measured memory_bytes: 51804
#include <iostream>
#include <string>
#include <algorithm>

using namespace std;

int main()
{
	const int MAX_N = 50;
	int n;
	cin >> n;
	
	int d[MAX_N];
	for (int i = 0; i < n; i++)
	{
		cin >> d[i];
	}
	
	int ans = 0;
	for (int i = 0; i < n; i++)
	{
		for (int j = i+1; j < n; j++)
		{
			ans += d[i] * d[j];
		}
	}
	
	cout << ans;
	
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define int long long
#define uint unsigned int
#define pii pair<int, int>
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define FORR(i,a,b) for(int i=(a);i>=(b);--i)
#define REP(i,n) FOR(i,0,n)
#define REPR(i,n) FORR(i,n,0)
#define ALL(c) ((c).begin(),(c).end())
#define PB(a) push_back(a)
#define EMPB(...) emplace_back(__VA_ARGS__)
#define EMP(...) emplace(__VA_ARGS__)
#define MP(a,b) make_pair(a,b)
#define MT(...) make_tuple(__VA_ARGS__)
#define ZERO(a) memset(a,0,sizeof(a))
#define MINUS(a) memset(a,0xff,sizeof(a))
#define MINF(a) memset(a,0x3f,sizeof(a))
#define PW(n) (1LL<<(n))
using namespace std;
template <class T> inline bool CHMIN(T& a, T b) { if(a>b) { a=b; return 1; } return 0; }
template <class T> inline bool CHMAX(T& a, T b) { if(a<b) { a=b; return 1; } return 0; }
template <class T> inline void SORT(T& a) { sort(ALL(a)); }
template <class T> inline void REV(T& a) { reverse(ALL(a)); }
template <class T> inline void UNI(T& a) { SORT(a); a.erase(unique(ALL(a)),a.end()); }
template <class S, class T> ostream& operator<<(ostream& os, const pair<S,T> a) {
  return os << a.first << ' ' << a.second;
}
const int MOD = 1000000007;
// const int INF = 0x3f3f3f3f3f3f3f3f;
// const double EPS = 1e-10;
/* ---------------------------------------------------------------------------------------------------- */

/* 基本要素 */
using D = double; // 座標値の型 doubleかlong double
using P = complex<D>; // Point
using L = pair<P,P>;  // Line
using VP = vector<P>;
const double EPS = 1e-8;  // 許容誤差
const double INF = 1e12;
#define X real()
#define Y imag()
#define LE(n,m) ((n)<(m)+EPS) // n <= m ?
#define GE(n,m) ((n)+EPS>(m)) // n >= m ?
#define EQ(n,m) (abs((n)-(m))<EPS)

namespace std {
  istream& operator >> (istream& is, P& p) {
    int F, S;
    is >> F >> S;
    p = P(F,S);
    return is;
  }
}

// 内積
D dot(P a, P b) {
  return (conj(a)*b).X;
}
// 外積
D cross(P a, P b) {
  return (conj(a)*b).Y;
}
// 点aから見た、点bから点cへの方向
int ccw(P a, P b, P c) {
  b -= a; c -= a;
  if (cross(b,c) > 0) return +1;  // counter clockwise
  if (cross(b,c) < 0) return -1;  // clockwise
  if (dot(b,c) < 0) return +2;  // c--a--b on line
  if (norm(b) < norm(c)) return -2; // a--b--c on line or a==b
  return 0;                     // a--c--b on line or a==c or b==c
}

/* 交差判定 直線・線分は縮退してはならない．接する場合は交差するとみなす */
// 直線と点
bool isecLP(P a1, P a2, P b) {
  return abs(ccw(a1,a2,b)) != 1;
}
// 直線と直線
bool isecLL(P a1, P a2, P b1, P b2) {
  return !isecLP(a2-a1,b2-b1,0) || isecLP(a1,b1,b2);
}
// 直線と線分
bool isecLS(P a1, P a2, P b1, P b2) {
  return cross(a2-a1,b1-a1) * cross(a2-a1,b2-a1) < EPS;
}
// 線分と線分
bool isecSS(P a1, P a2, P b1, P b2) {
  return ccw(a1,a2,b1) * ccw(a1,a2,b2) <= 0 && ccw(b1,b2,a1)*ccw(b1,b2,a2) <= 0;
}
// 線分と点
bool isecSP(P a1, P a2, P b) {
  return !ccw(a1, a2, b);
}

signed main() {
  cin.tie(0);
  ios_base::sync_with_stdio(false);
  cout << fixed << setprecision(10);

  int q;
  cin >> q;
  REP(i,q) {
    P p0, p1, p2, p3;
    cin >> p0 >> p1 >> p2 >> p3;
    cout << isecSS(p0,p1,p2,p3) << endl;
  }

  return 0;
}


Measured memory_bytes: 3204
#[allow(unused_macros)]
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

#[allow(unused_macros)]
macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

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

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

#[allow(unused_macros)]
macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

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

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

    ($next:expr, bytes) => {
        read_value!($next, String).into_bytes()
    };

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

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

use std::collections::BTreeSet;

fn main() {
    input! {
        x: usize,
        y: usize,
        z: usize,
        k: usize,
        mut a: [i64; x],
        mut b: [i64; y],
        mut c: [i64; z],
    }

    a.sort();
    a.reverse();
    b.sort();
    b.reverse();
    c.sort();
    c.reverse();

    let mut v = BTreeSet::new();
    v.insert((0, 0, 0));

    for _ in 0..k {
        let f = |(i, j, k)| -> i64 { a[i] + b[j] + c[k] };
        let mut maxk = *v.iter().nth(0).unwrap();
        for &key in v.iter() {
            if f(maxk) < f(key) {
                maxk = key;
            }
        }

        println!("{}", f(maxk));

        v.remove(&maxk);
        let (i, j, k) = maxk;

        if i + 1 < x {
            v.insert((i + 1, j, k));
        }
        if j + 1 < y {
            v.insert((i, j + 1, k));
        }
        if k + 1 < z {
            v.insert((i, j, k + 1));
        }
    }
}


Measured memory_bytes: 4352
def g;gets.split.map &:to_i;end
r=1..n=g[0]
w=[0]+r.map{[0]+[1e9]*n}
r.map{f,_,*t=g;t.map{|i|w[f][i]=1}}
r.map{|k|r.map{|i|r.map{|j|(a=(b=w[i])[k]+w[k][j])<b[j]&&b[j]=a}}}
g[0].times{s,d,v=g;puts v<(c=w[s][d]+1)?:NA:c}

Measured memory_bytes: 16764
package main

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

func main() {
	sc := bufio.NewScanner(os.Stdin)
	sc.Split(bufio.ScanWords)

	sc.Scan()
	num, _ := strconv.Atoi(sc.Text())

	A := make([]int, num)
	i := 0
	for sc.Scan() {
		A[i], _ = strconv.Atoi(sc.Text())
		i++
	}

	criterion := A[len(A)-1]
	i = 0
	for j := 0; j < len(A)-1; j++ {
		if A[j] <= criterion {
			if j != 0 {
				tmp := A[i]
				A[i] = A[j]
				A[j] = tmp
			}
			i++
		}
	}
	A[len(A)-1] = A[i]

	fmt.Print(strings.Trim(strings.Join(strings.Fields(fmt.Sprint(A[:i])), " "), "[]"))
	fmt.Printf(" [%d] ", criterion)
	fmt.Println(strings.Trim(strings.Join(strings.Fields(fmt.Sprint(A[i+1:])), " "), "[]"))
}



Measured memory_bytes: 5940
// 1_6_A
#include<stdio.h>

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

	int numbers[n];

	for(i = 0; i < n; i++){
		scanf("%d", &numbers[i]);
	}

	for(i = n-1; i > 0; i--){
		printf("%d ", numbers[i]);
	}
	printf("%d\n", numbers[0]);
	return 0;
}

Measured memory_bytes: 596