akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
using ll = long long;

signed
main(){
		int H;
		while(cin >> H && H!=0)
		{
				vector<vector<int> > d(H, vector<int>(5, -1));
				for(int i=0;i<H;i++)
				{
						for(int j=0;j<5;j++)
						{
								cin >> d[i][j];
						}
				}
				
				bool flag = true;
				int ans = 0;
				vector<int> minus_num(5,0);

				while(1)
				{
						flag = true;
						vector<vector<bool> > exist(H, vector<bool>(5, true));
						for(int y=0;y<H;y++)
						{
								int fi = -1, la = -1;
								bool seq = false;
								for(int x=2;x<5;x++)
								{
										if(d[y][x-2] == -1) continue;
										if(!seq && d[y][x-2] == d[y][x-1] && d[y][x-1] == d[y][x])
										{
												fi = x-2;
												la = x;
												seq = true;
										}
										else if(seq && d[y][x-1] == d[y][x])
										{
												la++;
										}else{
												seq = false;
										}
								}
								if(fi==-1 && la==-1) continue;
								
								//cout << fi << " " << la << endl;
								for(int x=fi;x<=la;x++)
								{
										exist[y][x] = false;
										ans += d[y][x];
								}

						}

						for(int x=0;x<5;x++)
						{								
								for(int y=0;y<H;y++)
								{
										if(exist[y][x]==false){
												flag = false;
													
												for(int sy=y;sy>minus_num[x];sy--)
												{
														d[sy][x] = d[sy-1][x];
												}
												d[minus_num[x]++][x] = -1;
										}
								}
						}
						if(flag) {
								cout << ans << endl;
								break;
						}

						for(int y=0;y<H;y++)
						{
								for(int x=0;x<5;x++)
								{
										//cout << d[y][x] << " ";
								}
								//cout << endl;
						}
				}
		}
}


Measured memory_bytes: 3136
#include <cstdio>
#include <stdlib.h>
#include <cstring>
#include <algorithm>
#include <iostream>
#include <queue>
#define min(a,b)    (((a) < (b)) ? (a) : (b))
#define max(a,b)    (((a) > (b)) ? (a) : (b))
#define abs(x)    ((x) < 0 ? -(x) : (x))
#define INF 0x3f3f3f3f
#define delta 0.85
#define eps 1e-3
#define PI 3.14159265358979323846
#define MAX_N 1005
using namespace std;
typedef pair<int, int> P;
const int dx[4] = {0, 0, 1, -1};
const int dy[4] = {1, -1, 0, 0};
int H, W, N;
char mp[MAX_N][MAX_N];
int d[MAX_N][MAX_N];

bool judge(int x, int y){
	return x >= 0 && x < H && y >= 0 && y < W && d[x][y] == 0 && mp[x][y] != 'X';
}

int bfs(int &sx, int &sy, char c){
	int fx, fy;
	queue<P> que;
	memset(d, 0, sizeof(d));
	que.push(P(sx, sy));
	while(!que.empty()){
		P p = que.front(); que.pop();
		int x = p.first, y = p.second;
		if(mp[x][y] == c){
			fx = x, fy = y;
			break;
		}
		for(int i = 0; i < 4; i++){
			int nx = x + dx[i], ny = y + dy[i];
			if(judge(nx, ny)){
				d[nx][ny] = d[x][y] + 1;
				que.push(P(nx, ny));
			}
		}
	}
	sx = fx, sy = fy;
	return d[fx][fy];
}

int main(){
	while(~scanf("%d%d%d", &H, &W, &N)){
		int sx, sy;
		for(int i = 0; i < H; i++){
			scanf("%s", mp + i);
			for(int j = 0; j < W; j++){
				if(mp[i][j] == 'S'){
					sx = i, sy = j;
				}
			}
		}
		int res = 0;
		for(int i = 1; i <= N; i++){
			res += bfs(sx, sy, i + '0');
		}
		printf("%d\n", res);
	}
	return 0;
}


Measured memory_bytes: 8044
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		
		int n, count[][];
		String s[];
		StringBuilder ans = new StringBuilder();
		
		n = sc.nextInt();
		
		s = new String[n];
		count = new int[n][26];
		
		for(int i = 0; i < n; ++i)s[i] = sc.next();
		sc.close();
		
		for(int i = 0; i < n; ++i) {
			for(int j = 0; j < s[i].length(); ++j) {
				char tmp = s[i].charAt(j);
				int tmp2 = tmp - 'a';
				++count[i][tmp2];
			}
		}
		
		for(int i = 0; i < 26; ++i) {
			int min = 51;
			char tmp = '\0';
			for(int j = 0; j < n; ++j)
				min = Math.min(min,  count[j][i]);
			tmp = (char)(i + 'a');
			for(int j = 0; j < min; ++j)
			ans.append(tmp);
		}
		
		System.out.println(ans);
	}

}


Measured memory_bytes: 22996
#include <bits/stdc++.h>
#define be(v) (v).begin(),(v).end()
#define pb(q) push_back(q)
typedef long long ll;
using namespace std;
const ll mod=1000000007;
#define doublecout(a) cout<<fixed<<setprecision(10)<<a<<endl;

int main() {
    cin.tie(0);
    cout.tie(0);
    ios::sync_with_stdio(false);
    int n,a;
    cin>>n;
    int b[n+1];
    memset(b,0,sizeof(b));
    vector<int> v1,v2;
    v1.pb(0);
    for(int i=0;i<n;i++){
    	cin>>a;
    	b[a]++;
    }
    for(int i=0;i<=n;i++){
    	if(b[i])v1.pb(b[i]);
    }
    sort(be(v1));
    v2=v1;
    int niko=v1.size();
    for(int i=1;i<niko;i++){
    	v2[i]+=v2[i-1];
    }
    for(int k=1;k<=n;k++){
    	int le=0,ri=n/k+1,ans;
    	while(ri-le>1){
    		ans=(le+ri)/2;
    		int idx=(lower_bound(be(v1),ans)-v1.begin());
    		if((v2[idx-1]+(niko-idx)*ans)>=ans*k)le=ans;
    		else ri=ans;
    	}
    	cout << le <<endl;
    }

    return 0;
}


Measured memory_bytes: 4336
#include<bits/stdc++.h>
using namespace std;
const int M=1e9+7;
#define lli long long int
vector<lli>T;
lli gcd(lli a, lli b) {
    if(b == 0) 
        return a;
    return gcd(b, a%b);
}

lli gcd_vector(vector<lli>& a, lli b) {
    lli ma = 1;
    for(int i=0; i<T.size(); i++)
        ma = ma*T[i]%b;
    return gcd(b, ma);
}

int mul(int a,int b){
    return (long long)a*b%M;
}

int mypow(int a,int b){
    int r=1;
    while(b){
        if(b%2){
            r=mul(a,r);
        }
        a=mul(a,a);
        b/=2;
    }
    return r;
}

int my_inv(int a){
    return mypow(a,M-2);
}

int main(){
  int n;
  cin>>n;
  vector<int>a(n);
  for(int &i:a) cin>>i;
  lli ans=0;
  lli answer = 1;
  for(int i:a) {
      lli factor = i/gcd_vector(T, i); 
      T.push_back(factor);
      answer = (answer*factor)%1000000007;
  }
  for(int num:a){
      ans=(ans+mul(answer,my_inv(num)))%M;
  }
  cout<<ans;
  return 0;
}

Measured memory_bytes: 512
#include<bits/stdc++.h>
#define ll long long
#define ld long double
#define pi acos(-1)
#define mod 1000000007
#define show(x, y); cout << x << " " << y << endl;
using namespace std;

ld p[3001], dp[3001][3001];

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

    int n;
    cin >> n;
    for(int i = 0; i < n; i++){
        cin >> p[i];
        for(int j = 0; j <= i+1; j++){
            if(i == 0){
                if(j == 0){
                    dp[i][j] = 1 - p[i];
                }else{
                    dp[i][j] = p[i];
                }
            }else{
                dp[i][j] = dp[i-1][j] * (1 - p[i]);
                if(j > 0){
                    dp[i][j] += (dp[i-1][j-1] * p[i]);
                }
            }
        }
    }
    ld ans = 0;
    for(int i = (n+1)/2; i <= n; i++){
        ans += dp[n-1][i];
    }
    cout << setprecision(10) << fixed << ans;
    return 0;
}


Measured memory_bytes: 139136
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
#define mp make_pair
#define pb push_back
#define ip pair<ll,ll>
#define ff first
#define ss second
#define MAX 100005
const ll MOD = 1000000007;

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

	int h,w;
	cin>>h>>w;
	string s[h];
	for(int i=0;i<h;i++)
		cin>>s[i];
	
	int dp[h][w];
	if(s[0][0] == '#')
		dp[0][0] = 1;
	else
		dp[0][0] = 0;
	for(int j=1;j<w;j++){
		dp[0][j] = dp[0][j-1];
		if(s[0][j] != s[0][j-1] && s[0][j] == '#')
			++dp[0][j];
	}

	for(int i=1;i<h;i++){
		dp[i][0] = dp[i-1][0];
		if(s[i][0] != s[i-1][0] && s[i][0] == '#')
			++dp[i][0];
		for(int j=1;j<w;j++){
			int v1 = dp[i-1][j], v2 = dp[i][j-1];
			if(s[i-1][j] != s[i][j] && s[i][j] == '#')
				++v1;
			if(s[i][j-1] != s[i][j] && s[i][j] == '#')
				++v2;
			dp[i][j] = min(v1,v2);
		}
	}

	cout<<dp[h-1][w-1]<<endl;
}

Measured memory_bytes: 384
#include<iostream>
#include<vector>
#include<queue>
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;

int main(){
    int h, w;
    cin >> h >> w;
    priority_queue<pii> pq;
    for(int i = 0; i < h; i++){
        int x;  cin >> x;
        pq.push({-x, 0});
    }
    for(int i = 0; i < w; i++){
        int x;  cin >> x;
        pq.push({-x, 1});
    }
    ll ans = 0;
    while(!pq.empty()){
        pii p = pq.top();   pq.pop();
        ll v = -p.first;
        int stat = p.second;
        if(stat == 0){
            ans += v*w;
            h--;
        }else if(stat == 1){
            ans += v*h;
            w--;
        }
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 4940
//#include <bits/stdc++.h>
#include <string>
#include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <map>
#include <set>
#include <stack>
#include <queue>
#include <deque>
#include <utility>

using namespace std;
using ll=long long;

void solve(){
  int num,m;
  cin >> num >> m;
  vector<string> s1(num);
  vector<string> s2(num);
  for(int i=0;i<num;i++)
    cin >> s1[i];
  for(int i=0;i<m;i++)
    cin >> s2[i];
  for(int i=0;i<=num-m;i++)
    for(int j=0;j<=num-m;j++){
      bool b=true;
      for(int k=i;k<i+m;k++)
        for(int l=j;l<j+m;l++)
          b&=s1[k][l]==s2[k-i][l-j];
      if(b){cout << "Yes" << endl;return;}
    }
  cout << "No" << endl;
}

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


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

public class Main {
    public static void main(final String[] args) {
        final Scanner scanner = new Scanner(System.in);
        final int n = scanner.nextInt();
        final int m = scanner.nextInt();

        final int[] bitConverter = new int[n + 1];
        int pow = 1;
        for (int i = 1; i < n + 1; i++) {
            bitConverter[i] = pow;
            pow *= 2;
        }

        final Key[] keys = new Key[m];
        for (int i = 0; i < m; i++) {
            final int a = scanner.nextInt();
            final int b = scanner.nextInt();
            int sum = 0;

            for (int j = 0; j < b; j++) {
                final int c = scanner.nextInt();
                sum += bitConverter[c];
            }
            keys[i] = new Key(a, sum);
        }

        final int[][] dpTable = new int[m][pow];
        for (final int[] array : dpTable) {
            Arrays.fill(array, Integer.MAX_VALUE);
        }

        dpTable[0][keys[0].boxes] = keys[0].price;
        dpTable[0][0] = 0;
        for (int i = 1; i < m; i++) {
            System.arraycopy(dpTable[i - 1], 0, dpTable[i], 0, dpTable[i].length);
            for (int j = 0; j < dpTable[i].length; j++) {
                if (dpTable[i - 1][j] != Integer.MAX_VALUE) {
                    final int idx = j | keys[i].boxes;
                    dpTable[i][idx] = Math.min(dpTable[i][idx], dpTable[i - 1][j] + keys[i].price);
                }
            }
        }

        if (dpTable[m - 1][pow - 1] == Integer.MAX_VALUE) {
            System.out.println(-1);
        } else {
            System.out.println(dpTable[m - 1][pow - 1]);
        }
    }

    static class Key {
        int price;
        int boxes;

        Key(final int price, final int boxes) {
            this.price = price;
            this.boxes = boxes;
        }
    }
}


Measured memory_bytes: 50624
#include "bits/stdc++.h"
using namespace std;

#define int long long
#define MAX_N (300005)
#define INF (1LL<<60)
#define EPS (1e-7)
#define DEBUG(x) cerr << #x <<":"<< x << endl;
#define DEBUGVC(x) cerr << #x <<": "; for(auto p:(x)) cerr << p <<" "; cerr << endl;
#define DEBUGVCP(x) for(auto p:(x)) cerr << #x <<": "<< p.first <<", "<< p.second << endl;
#define DEBUG2(x, y) cerr << #x <<" : "<< x <<", "<< #y <<" : "<< y << endl;
#define DEBUG3(x, y, z) cerr << #x <<" : "<< x <<", "<< #y <<" : "<< y <<", "<< #z <<" : "<< z << endl;
const int MOD = (int)1e9+7;

int gcd(int a, int b){
    if(b==0) return a;
    return gcd(b, a%b);
}

signed main() {
    int N;
    cin >> N;
    vector<int> A(N);
    for(int i=0; i<N; i++) cin >> A[i];

    vector<int> L(N+1), R(N+1);
    L[0] = R[N] = 0;

    for(int i=0; i<N; i++){
        L[i+1] = gcd(L[i], A[i]);
        //DEBUG2(i, L[i+1]);
    }
    for(int i=N-1; i>=0; i--){
        R[i] = gcd(R[i+1], A[i]);
        //DEBUG2(i, R[i]);
    }

    int ans=0;
    for(int i=0; i<N; i++){
        //DEBUG3(i, L[i], R[i]);
        ans = max(ans, gcd(L[i], R[i+1]));
        //DEBUG(ans);
    }

    cout << ans << endl;

}

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

bool has3(int x){
    while(x){
        if(x%10==3) return true;
        x /= 10;
    }
    return false;
}

void call(int n){
    for(int x = 1; x <= n; x++){
        if(x%3 == 0 || has3(x)){
            cout << " " << x;
        }
    }
    cout << endl;
}

int main(){
    int n; cin >> n;
    call(n);
    return 0;
}


Measured memory_bytes: 3080
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayDeque;
import java.util.Deque;

public class Main {

	public static void main(String[] args) throws NumberFormatException,
			IOException {
		BufferedReader reader = new BufferedReader(new InputStreamReader(
				System.in));
		StringBuilder builder = new StringBuilder();
		int n = Integer.parseInt(reader.readLine());
		Deque<Integer> deque = new ArrayDeque<Integer>();
		for (int i = 0; i < n; i++) {
			String[] line = reader.readLine().split(" ");
			String name = line[0];

			if (name.equals("deleteFirst"))
				deque.pollFirst();
			else if (name.equals("deleteLast"))
				deque.pollLast();
			else {
				int num = Integer.parseInt(line[1]);
				if (name.equals("insert"))
					deque.push(num);
				else
					deque.remove(num);
			/*System.out.println(deque.stream().map(String::valueOf)
					.collect(Collectors.joining(", ", "[", "]")));*/
			}
		}
		builder.append(deque.poll());
		for(int num2 : deque)
			builder.append(" ").append(num2);
		System.out.println(builder);
	}
}

Measured memory_bytes: 561088
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n)  FOR(i,0,n)
#define req(i,n) for(int i = 1;i <=n;i++)
#define pai 3.14159265358979323846
const int INF = 1001001001;
typedef long long ll;
int A[3][3], N;
bool punched[3][3];
bool ok[3][3];
using Graph = vector<vector<int>>;
vector<vector<int>> field;
vector<bool> seen;

const int MOD = 1000000007;
typedef pair<int,int> P;

//最大公約数
ll gcd(ll a,ll b){
	if (a%b == 0){
		return b;
	}
	else{
		return gcd(b,a%b);
	}

}

//最小公倍数
ll lcm(ll a,ll b){
	return a /gcd(a,b) * b;
}

//素数判定
bool is_prime(long long N) {
    if (N == 1) return false;
    for (long long i = 2; i * i <= N; ++i) {
        if (N % i == 0) return false;
    }
    return true;
}

// 素因数分解
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;
}

// 10進数から2進数
int binary(int bina){
    int ans = 0;
    for (int i = 0; bina>0 ; i++)
    {
        ans = ans+(bina%2)*pow(10,i);
        bina = bina/2;
    }
    return ans;
}









int main() {
  string s;
  cin >> s;
  ll cnt = 0;
  rep (i,s.size()){
    if (s[i] == 'W' && s[i+1] == 'B') {
      cnt++;
    }
    if (s[i] == 'B' && s[i+1] == 'W') {
      cnt++;
    }
  }
  cout << cnt << endl;
  
}


Measured memory_bytes: 3664
import java.util.Scanner;

public class Main {
  public static void main(String[] args) {
    Scanner scanner = new Scanner(System.in);

    long A = scanner.nextLong();
    long B = scanner.nextLong();
    System.out.println(g(A - 1) ^ g(B));
  }

  private static long g(long a) {
    a++;
    long res = a / 2 % 2;
    for (int i = 1; i < 40; i++) {
      long j = 1L << i;
      long k = a / j;
      long l = a % j;
      if (k % 2 == 1 && l % 2 == 1) {
        res |= j;
      }
    }
    return res;
  }
}


Measured memory_bytes: 23764
H,W,K = map(int,input().split())
c = [input() for _ in range(H)]

def f(x):
    x = bin(x)
    ans = []
    l = len(x)
    for i in range(l):
        if x[l-1-i]=='1':
            ans.append(i)
    return ans

ans = 0
for i in range(2**H):
    for j in range(2**W):
        tmp = 0
        I = f(i)
        J = f(j)
        for x in range(H):
            for y in range(W):
                if (x not in I) and (y not in J) and c[x][y]=='#':
                    tmp += 1
        if tmp==K:
            ans += 1
print(ans)

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

class Program
{
    static void Main(string[] args)
    {
        var LR = ReadLine().Split(' ').Select(s => long.Parse(s)).ToArray();
        var (L, R) = (LR[0], LR[1]);

        var pigeonhole = new bool[2019];
        var ans = long.MaxValue;

        for (long i = L; i < R && i < L + 5000; i++)
        {
            for (long j = i + 1; j <= R; j++)
            {
                var value = (i * j) % 2019;

                if (pigeonhole[value])
                    break;

                pigeonhole[value] = true;
                ans = Math.Min(ans, value);
            }

            pigeonhole = new bool[2019];
        }

        WriteLine(ans);
    }
}


Measured memory_bytes: 38052
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rrep(i, n) for (int i = (int)(n - 1); i >= 0; i--)
#define all(x) (x).begin(), (x).end()
#define sz(x) int(x.size())
#define get_unique(x) x.erase(std::unique(all(x)), x.end());
typedef long long ll;
const int INF = 1e9;
const ll MOD = 1e9 + 7;
const ll LINF = 1e18;
const double PI = acos(-1);
using namespace std;
template <class T>
bool chmax(T &a, const T &b) {
    if (a < b) {
        a = b;
        return 1;
    }
    return 0;
}
template <class T>
bool chmin(T &a, const T &b) {
    if (b < a) {
        a = b;
        return 1;
    }
    return 0;
}
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...));
}

int main() {
    ll n, m, v, p;
    cin >> n >> m >> v >> p;
    vector<ll> a(n);
    rep(i, n) cin >> a[i];
    sort(all(a), greater<ll>());

    ll ok = 0, ng = n;
    while (ng - ok > 1) {
        ll mid = (ok + ng) / 2;

        if (a[mid] + m < a[p-1]) {
            ng = mid;
            continue;
        }

        ll sum = 0;
        rep(i, n) {
            if (i == mid)
                sum += m;
            else if (i < p - 1)
                sum += m;
            else if (i > mid)
                sum += m;
            else
                sum += a[mid] + m - a[i];
        }

        (sum >= m * v ? ok : ng) = mid;
    }
    cout << ok + 1 << endl;
}

Measured memory_bytes: 1024
#![allow(unused_imports)]
#![allow(unused_macros)]
use std::cmp::{ min, max };

macro_rules! ewriteln {
    ($($args:expr),*) => { let _ = writeln!(&mut std::io::stderr(), $($args),*); };
}
macro_rules! trace {
    ($x:expr) => { ewriteln!(">>> {} = {:?}", stringify!($x), $x) };
    ($($xs:expr),*) => { trace!(($($xs),*)) }
}
macro_rules! put {
    ($x:expr) => { println!("{}", $x) };
    ($x:expr, $($xs:expr),*) => { print!("{} ", $x); put!($($xs),*) }
}

const M: u64 = 1_000_000_007;

fn main() {
    let mut sc = Scanner::new();
    let n: usize = sc.cin();
    let a: Vec<Vec<bool>> = (0..n).map(|_|
                                       (0..n).map(|_|
                                                  sc.cin::<usize>() == 1).collect()).collect();

    let mut bits = vec![vec![]; n+1];
    for bp in 0..(1<<n)+1 {
        let k = (bp as u32).count_ones();
        bits[k as usize].push(bp);
    }
    let mut memo = [0; 1<<21];
    memo[0] = 1;
    for i in 1..n+1 {
        for &bp in bits[i].iter() {
            for j in 0..n {
                if a[i-1][j] && (bp & (1<<j)) != 0 {
                    let bq = bp ^ (1<<j);
                    memo[bp] += memo[bq];
                    memo[bp] %= M;
                }
            }
        }
        // trace!(&memo[i]);
    }
    put!(memo[(1<<n)-1]);

    // let mut memo = vec![vec![None; 1<<n]; n+1];
    // let mut stack = vec![(n, (1<<n)-1)];
    //
    // for bp in 0..1<<n {
    //     memo[0][bp] = Some(0);
    // }
    // memo[0][0] = Some(1);
    //
    // while let Some((i, bp)) = stack.pop() {
    //     if memo[i][bp].is_some() { continue }
    //     let mut sum = 0;
    //     let mut ok = true;
    //     stack.push((i, bp));
    //     for j in 0..n {
    //         if a[i-1][j] && (bp & (1 << j)) != 0 {
    //             let bq = bp ^ (1 << j);
    //             match memo[i-1][bq] {
    //                 None => {
    //                     ok = false;
    //                     stack.push((i-1, bq));
    //                 },
    //                 Some(x) => {
    //                     sum = (sum + x) % M;
    //                 }
    //             }
    //         }
    //     }
    //     if ok { memo[i][bp] = Some(sum); }
    // }
    // put!(memo[n][(1<<n)-1].unwrap());
}

use std::io::{self, Write};
use std::str::FromStr;
use std::collections::VecDeque;

struct Scanner { stdin: io::Stdin, buffer: VecDeque<String>, }
impl Scanner {
    fn new() -> Scanner { Scanner { stdin: io::stdin(), buffer: VecDeque::new() } }
    fn cin<T: FromStr>(&mut self) -> T {
        while self.buffer.len() == 0 {
            let mut line = String::new();
            let _ = self.stdin.read_line(&mut line);
            for w in line.split_whitespace() {
                self.buffer.push_back(String::from(w));
            }
        }
        self.buffer.pop_front().unwrap().parse::<T>().ok().unwrap()
    }
}


Measured memory_bytes: 47500
#include<iostream>
#include<iomanip>
#include<vector>
#include<algorithm>
using namespace std;
typedef long long ll;
 
int p[100000],y[100000];
vector<int> t[1000001];
 
int main(){
	int n,m;
	cin >> n >> m;
	for(int i=0;i<m;i++){
		cin >> p[i] >> y[i];
		t[p[i]].push_back(y[i]);
	}
	for(int i=1;i<=n;i++) sort(t[i].begin(),t[i].end());
	for(int i=0;i<m;i++){
			cout << setw(12) << setfill('0') << 
			ll(p[i])*1000000+int(lower_bound(t[p[i]].begin(),t[p[i]].end(),y[i])-t[p[i]].begin())+1
			<< endl;
	}
	return 0;
}


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

int main() {
  int N;
  cin >> N;
  
  if(N <= 10){
    cout << "Yes";
	return 0;
  }
  if(81 < N){
    cout << "No";
	return 0;
  }
  
  for(int i = 2; i <= 9; i++){
    if(N % i == 0 && N <= (i * 9) ){
      	cout << "Yes";
    	return 0;
    }
  }
  
	cout << "No";
  	return 0;
}

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

int main() {
    cin.tie(0)->sync_with_stdio(false);

    int t;
    cin >> t;

    while (t--) {
        int n;
        cin >> n;

        vector<ll> a(n);
        REP(i, n) cin >> a[i];

        string s;
        cin >> s;

        int ans = 0;
        vector<ll> dp;
        for (int i = n - 1; i >= 0; i--) {
            for (auto j : dp) a[i] = min(a[i], a[i]^j);
            if (s[i] == '0') {
                if (a[i]) dp.push_back(a[i]);
            } else if (a[i]) {
                ans = 1;
                break ;
            }
        }
        cout << ans << '\n';
    }
    return 0;
}

Measured memory_bytes: 3600
#include<iostream>
#include<set>
#include<string>

using namespace std;

int main(){
	set<string> S;
	string command,key;
	int n;
	cin>>n;
	for(int i=0;i<n;++i){
		cin>>command;
		if(command=="insert"){
			cin >> key;
			S.insert(key);
		}
		else if(command == "find"){
			cin >> key;
			if(S.count(key) == 1){
			    cout << "yes" << endl;
			}
			else{
			    cout << "no" << endl;
			}
		}
	}
}



Measured memory_bytes: 32528
#include<cstdio>
#include<iostream>
#include<map>
#include<cmath>
#include<cstring>

using namespace std;

typedef long long ll;



int main()
{
    int n;
    cin >> n;
    if(n%2==0)
        printf("%d\n",n/2-1);
    else
        printf("%d\n",(n+1)/2-1);
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <string>
#include <sstream>
#include <complex>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
#include <iomanip>
using namespace std;
typedef long long ll;
template<typename T> using min_priority_queue = priority_queue<T, vector<T>, greater<T>>;

#define EPS (1e-7)
#define INF (1e15)
#define PI (acos(-1))
#define MOD 1000000007

#define REP(i,n) for(int i=0;i<n;i++)
#define REPS(i,f,n) for(int i=(f);i<(n);i++)
#define EACH(it,v) for(__typeof((v).begin()) it=(v).begin();it!=(v).end();it++)

#define dump(x)  cout << #x << " = " << (x) << endl;
#define debug(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;
#define arrdump(n,a) for(int i=0;i<n;i++) {cout<<((i>0)? " ":"")<<a[i];}cout<<"\n";


typedef pair<int, int> P;
typedef pair<ll, ll> LP;
typedef pair<int, P> PP;
typedef pair<ll, LP> LPP;

int dy4[]={0, 0, 1, -1};
int dx4[]={1, -1, 0, 0};
int dx8[]={0, 0, 1, -1, 1, 1, -1, -1};
int dy8[]={1, -1, 0, 0, 1, -1, -1, 1};

// https://atcoder.jp/contests/abc103/tasks/abc103_d

int main() {
    int N, M; cin >> N >> M;
    P ab[M];
    REP(i, M) {
        int a, b; cin >> a >> b;
        ab[i] = {b, a};
    }
    sort(ab, ab+M);

    int now = 0;
    int cnt = 0;
    REP(i, M) {
        int l = ab[i].second;
        int r = ab[i].first;
        if (l >= now) {
            cnt++;
            now = r;
        }
    }

    cout << cnt << "\n";

    return 0;
}


Measured memory_bytes: 1024
import sys

input = sys.stdin.readline


def main():
    S = input().rstrip()

    N = len(S)
    if N % 2 == 0:
        is_h = all(s == "h" for s in S[0::2])
        is_i = all(s == "i" for s in S[1::2])
        ans = "Yes" if is_h and is_i else "No"
    else:
        ans = "No"

    print(ans)


if __name__ == "__main__":
    main()


Measured memory_bytes: 3060
#include <iostream>
#include <vector>
#include <string>
#include <queue>

using namespace std;

int main(){
    int H, W;
    while(cin >> H >> W){
        vector<string> vs(H);
        for(auto& s : vs) cin >> s;
        vector<vector<int>> visit(H, vector<int>(W, 0));
        long long res = 0;
        for(int i=0;i<H;i++){
            for(int j=0;j<W;j++){
                if(visit[i][j]) continue;
                queue<pair<int,int>> qu; qu.emplace(i, j);
                visit[i][j] = 1;
                int cnt[2] = {0, 0};
                while(!qu.empty()){
                    auto p = qu.front(); qu.pop();
                    int dx[] = {0, -1, 0, 1};
                    int dy[] = {1, 0, -1, 0};
                    if(vs[p.first][p.second] == '#') cnt[0]++;
                    else cnt[1]++;
                    for(int k=0;k<4;k++){
                        int nx = p.first + dx[k];
                        int ny = p.second + dy[k];
                        if(nx < 0 || H <= nx || ny < 0 || W <= ny) continue;
                        if(vs[p.first][p.second] == vs[nx][ny]) continue;
                        if(visit[nx][ny]) continue;
                        visit[nx][ny] = 1;
                        qu.emplace(nx, ny);
                    }
                }
                res += (long long)cnt[0] * cnt[1];
            }
        }
        cout << res << endl;
    }
}

Measured memory_bytes: 1152
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <queue>
#include <cstring>
#include <vector>
#include <map>
#include <algorithm>
#include <cctype>
#include <cmath>
#include <bitset>
#include <set>
#include <stack>
using namespace std;

#define REP(i,n) for(int i=0;i<(int)(n);i++)
#define RREP(i,n) for(int i=n-1;i>=0;i--)
#define FOR(i,k,n) for(int i=(k);i<(int)(n);i++)
#define all(i,n) (i),(i+n)

int dx4[4]={1,0,-1,0};
int dy4[4]={0,-1,0,1};
int dx8[8]={1,0,-1,1,-1,1,0,-1};
int dy8[8]={1,1,1,0,0,-1,-1,-1};
int dx9[9]={0,1,0,-1,1,-1,1,0,-1};
int dy9[9]={0,1,1,1,0,0,-1,-1,-1};

typedef pair<int, int> P;
typedef pair<string, int> SP;
typedef long long ll;
typedef pair<ll, ll> PLL;

const int INF = 1e9;
const ll LLINF = 1e18;
const int MAX_V = 1e6+1;
const ll mod = 1000000007;
// << fixed << setprecision
// --------------------------------------
int n, k;
int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);

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

  REP(i, n) cin >> a[i];

  ll ans = 0;

  REP(i, min(n + 1, k + 1)) {
    priority_queue<int, vector<int>, greater<int>> que;
    ll sum = 0;

    REP(ii, i) {
      sum += a[ii];
      if(a[ii] < 0)  que.push(a[ii]);
    }

    for(int j = n; j >= i && (n - j) <= (k - i); j--) {
      ll t_sum = sum;
      priority_queue<int, vector<int>, greater<int>> t_que = que;

      for(int jj = n - 1; jj >= j; jj--) {
        t_sum += a[jj];
        if(a[jj] < 0) t_que.push(a[jj]);
      }

      REP(l, k - (n - j + i)) {
        if(!t_que.empty()) {
          int t = t_que.top(); t_que.pop();
          t_sum -= t;
        } else {
          break;
        }
      }

      ans = max(ans, t_sum);
    }
  }
  cout << ans << endl;
}


Measured memory_bytes: 3148
#include<bits/stdc++.h>
#define ll long long int
#define M 1000000007
using namespace std;
ll n,t;
int main(){
      ios_base::sync_with_stdio(false); cin.tie(NULL);
      cin>>n>>t;
      ll cnt=0,x;
      for(int i=0;i<n;i++){
        cin>>x;
        if(x>=t)cnt++;
      }
      cout<<cnt;
}

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

typedef long long ll;
static const int MOD = 1e9+7;
static const ll MAX = 1ll<<60;

int main(){
    int x;
    cin>>x;

    if(x){
        cout<<"0"<<endl;
    }else cout<<"1"<<endl;
}

Measured memory_bytes: 3648
N,Y = map(int,input().split())
X = Y // 1000
check = 0
for a in range(X // 10 + 1):
    for b in range(X // 5 + 1):
        c = N - a - b
        Z = 10 * a + 5 * b + c
        if c >= 0 and X == Z:
            check = 1
            break
    if check == 1:
        break
if check == 0:
    print(-1,-1,-1)
else:
    print(a,b,c)

Measured memory_bytes: 40684
#include<stdlib.h>

struct node{
  struct node *right;
  struct node *left;
  struct node *parent;
  int key;
};
typedef struct node * Node;
#define NIL NULL

Node root;

Node treeMinimum(Node x){

  while(x->right!=NIL){
    x=x->right;
  }
  return x;
}

Node treeMaximum(Node x){
  while(x->right!=NIL){
    x=x->right;
  }
  return x;

}

Node treeSearch(Node u, int k){
  if(u==NIL || k==u->key){
    return u;
  }
  if(k<u->key){
    return treeSearch(u->left,k);
  }
  else{
    return treeSearch(u->right,k);
  }
}

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

void treeDelete(Node z){
  Node y; // node to be deleted
  Node x; // child of y



}

void insert(int k){
  Node y = NIL;
  Node x = root;
  Node z;

  z = malloc(sizeof(struct node));
  z->key = k;
  z->left = NIL;
  z->right = NIL;

  //code
  while(x!=NIL){
    y=x;
    if(z->key < x->key){
      x=x->left;
    }
    else{
      x=x->right;
    }
  }
  z->parent=y;

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

void inorder(Node u){

  if(u!=NIL){
    inorder(u->left);
    printf(" %d",u->key);
    inorder(u->right);
  }
}
void preorder(Node u){
  
  if(u==NIL) return;  
  printf(" %d",u->key);
  preorder(u->left);
  preorder(u->right);
}


int main(){
  int n, i, x;
  char com[20];
  scanf("%d", &n);

  for ( i = 0; i < n; i++ ){
    scanf("%s", com);
    if ( com[0] == 'f' ){
      scanf("%d", &x);
      Node t = treeSearch(root, x);
      if ( t != NIL ) printf("yes\n");
      else printf("no\n");
    } else if ( com[0] == 'i' ){
      scanf("%d", &x);
      insert(x);
    } else if ( com[0] == 'p' ){
      inorder(root);
      printf("\n");
      preorder(root);
      printf("\n");
    } else if ( com[0] == 'd' ){
      scanf("%d", &x);
      treeDelete(treeSearch(root, x));
    }
  }

  return 0;
}



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

using namespace std;

int64_t calc(const std::vector<int>& as, const std::vector<int>& bs,
             const std::vector<int>& cs) {
  int const n = as.size();
  std::vector<int64_t> bCounts(n, 0);
  auto prevItrC = cs.begin();
  for (int i = 0; i < n; i++) {
    auto itrC = std::upper_bound(prevItrC, cs.end(), bs[i]);
    if (itrC == cs.end()) {
      break;
    }
    bCounts[i] = cs.end() - itrC;
    prevItrC = itrC;
  }
  int64_t sum = bCounts[n - 1];
  for (int i = n - 2; i >= 0; i--) {
    sum += bCounts[i];
    bCounts[i] = sum;
  }

  int64_t ret = 0;
  auto prevItrB = bs.begin();
  for (int i = 0; i < n; i++) {
    auto itrB = std::upper_bound(prevItrB, bs.end(), as[i]);
    if (itrB == bs.end()) {
      break;
    }
    ret += bCounts[itrB - bs.begin()];
    prevItrB = itrB;
  }
  return ret;
}

int main() {
  int n;
  std::cin >> n;
  std::vector<int> as(n);
  std::vector<int> bs(n);
  std::vector<int> cs(n);
  for (auto& a : as) {
    std::cin >> a;
  }
  for (auto& b : bs) {
    std::cin >> b;
  }
  for (auto& c : cs) {
    std::cin >> c;
  }
  std::sort(as.begin(), as.end());
  std::sort(bs.begin(), bs.end());
  std::sort(cs.begin(), cs.end());
  std::cout << calc(as, bs, cs) << std::endl;
  return 0;
}


Measured memory_bytes: 2176
import std.algorithm;
import std.array;
import std.ascii;
import std.bigint;
import std.complex;
import std.container;
import std.conv;
import std.functional;
import std.math;
import std.range;
import std.stdio;
import std.string;
import std.typecons;

auto readInts() {
	return array(map!(to!int)(readln().strip().split()));
}
auto readInt() {
	return readInts()[0];
}
auto readLongs() {
	return array(map!(to!long)(readln().strip().split()));
}
auto readLong() {
	return readLongs()[0];
}

void readlnTo(T...)(ref T t) {
    auto s = readln().split();
    assert(s.length == t.length);
    foreach(ref ti; t) {
        ti = s[0].to!(typeof(ti));
        s = s[1..$];
    }
}

class UnionFindTree {
public:
    this(size_t n) {
        parent = iota(n).array();
        rank = new size_t[](n);
    }
    size_t find(size_t n) {
        if(n == parent[n]) {
            return n;
        } else {
            parent[n] = find(parent[n]);
            return parent[n];
        }
    }
    void unite(size_t n, size_t m) {
        auto p1 = find(n);
        auto p2 = find(m);
        if(n == m) {
            return;
        }
        if(rank[p1] < rank[p2]) {
            swap(p1, p2);
        }
        if(rank[p1] == rank[p2]) {
            ++rank[p1];
        }
        parent[p2] = p1;
    }
private:
    size_t[] parent;
    size_t[] rank;
}
unittest {
    auto uft = new UnionFindTree(10);
    foreach(i; iota(10)) {
        assert(uft.find(i) == i);
    }
    foreach(i; iota(10).filter!(a => a%3 == 0).drop(1)) {
        uft.unite(i, i-3);
    }
    foreach(i; iota(10).filter!(a => a%3 == 0)) {
        assert(uft.find(0) == uft.find(i));
    }
    foreach(i; iota(10).filter!(a => a%3 != 0)) {
        assert(uft.find(0) != uft.find(i));
    }
}

const real eps = 1e-10;

const long p = 1_000_000_000 + 7;


bool next(in string s, long i, bool ai, bool aii) {
    if(aii) {
        if(s[(i+1)%s.length] == 'o') {
            return ai;
        } else {
            return !ai;
        }
    } else {
        if(s[(i+1)%s.length] == 'o') {
            return !ai;
        } else {
            return ai;
        }
    }
}

bool test(in string s, bool a0, bool a1) {
    bool ai = a0;
    bool aii = a1;
    foreach(i; iota(s.length)) {
        bool tmp = next(s, i, ai, aii);
        ai = aii;
        aii = tmp;
    }
    return ai == a0 && aii == a1;
}

string solve(in string s, bool a0, bool a1) {
    bool ai = a0;
    bool aii = a1;

    char toStr(bool b) {
        return b ? 'S': 'W';
    }

    string ret = [toStr(a0), toStr(a1)];
    foreach(i; iota(s.length)) {
        bool tmp = next(s, i, ai, aii);
        ai = aii;
        aii = tmp;
        ret ~= toStr(aii);
    }
    return ret[0..s.length];
}

void main(){
    auto n = readLong();
    auto s = readln().chomp();

    foreach(b; [[true, true], [true, false], [false, true], [false, false]]) {
        if(test(s, b[0], b[1])) {
            writeln(solve(s, b[0], b[1]));
            return;
        }
    }
    writeln(-1);
    return;
}



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

#define for_(i,a,b) for(int i=(a);i<(b);++i)

int bit[11][7] = {
	{1,1,1,1,1,1,0},
	{0,1,1,0,0,0,0},
	{1,1,0,1,1,0,1},
	{1,1,1,1,0,0,1},
	{0,1,1,0,0,1,1},
	{1,0,1,1,0,1,1},
	{1,0,1,1,1,1,1},
	{1,1,1,0,0,1,0},
	{1,1,1,1,1,1,1},
	{1,1,1,1,0,1,1},
	{0,0,0,0,0,0,0},
};

int main() {
	int n;
	
	while (cin >> n) {
		if (n == -1) break;
		
		int p = 10;
		
		for_(i,0,n) {
			int c;
			cin >> c;
			
			for_(i,0,7) cout << (bit[c][7 - i - 1] == bit[p][7 - i - 1] ? 0 : 1);
			cout << endl;
			
			p = c;
		}
	}
}

Measured memory_bytes: 1160
#include<bits/stdc++.h>
#include<cctype>
using namespace std;
#define rep(i,n) for (int i=0;i<(n);i++)
#define reps(i,n) for (int i=1;i<=(n);i++)
#define rrep(i,n) for (int i=(n)-1;i>=0;i--)
#define rreps(i,n) for (int i=(n);i>0;i--)
#define all(v) (v).begin(),(v).end()
#define pi 3.1415926535897932384
#define E9 1000000000
#define eps 1e-4
#define pii pair<int,int>
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;};
typedef long long int ll;
const long long INF = 1LL << 60;


int main(){
  int N; cin >> N;
  int parity = -1;

  stack<int> ans;
  if (N==0) ans.push(N);

  while (N!=0){
    int m = N&1;
    ans.push(m);
    (N += m*parity) /= 2;
    parity *= -1;
    // cout << N << endl;
  }
  while (!ans.empty()) {
    cout << ans.top();
    ans.pop();
  }

  // cout << fixed << setprecision(10);
  
  return 0;
}

Measured memory_bytes: 3604
using System;
using System.Collections.Generic;
using System.Linq;

namespace AizuOnlineJudge
{
    class Program
    {
        static void Main(string[] args)
        {
            var stack = new Stack<int>();
            var ops = Console.ReadLine().Split(' ');
            foreach(var op in ops)
            {
                int a, b;
                switch(op)
                {
                    case "+":
                        a = stack.Pop(); b = stack.Pop();
                        stack.Push(b + a); break;
                    case "-":
                        a = stack.Pop(); b = stack.Pop();
                        stack.Push(b - a); break;
                    case "*":
                        a = stack.Pop(); b = stack.Pop();
                        stack.Push(b * a); break;
                    case "/":
                        a = stack.Pop(); b = stack.Pop();
                        stack.Push(b / a); break;
                    default:
                        stack.Push(int.Parse(op)); break;
                }
            }
            Console.WriteLine(stack.Pop());
        }
    }
}


Measured memory_bytes: 18420
#include <iostream>
#include <numeric>
#include <math.h>
#include <algorithm>
#include <float.h>
#include <limits>
#include <vector> 
#include <string.h>
#include <iomanip>

#define rep(i,a,n) for(ll int (i) = (a);(i) < (n);(i)++)
#define urep(i,a,n) for(ll int (i) = (a);(i) > (n);(i)--)
#define MOD 1000000007
#define ll long long
#define asort(a) sort(a.begin(),a.end());

using namespace::std;

int jo(ll int jxo, ll int jyo){//累乗
	ll int jhogeo = 1;
	rep(jinto,0,jyo) jhogeo=jhogeo*jxo;
	return jhogeo;
}
char tobig(char toxbig){//char大文字化
  return (toxbig-0x20);
}
char tolow(char toxlow){//char小文字化
  return (toxlow+0x20);
}
int ctoi(char cctoi){//char->int
  if('0' <= cctoi && cctoi <= '9') return (cctoi-'0');
  return -1;
}
/*
int stoi(string sstoi){//string->int
  ll int stois=0;
  rep(stoii,0,sstoi.length()){
    stois+=ctoi(sstoi[stoii])*jo(10,sstoi.length()-stoii-1);
  }
  return stois;
}*/
  
int gcd(int gcad, int gcbd) {//最大公約数
  if(gcad < gcbd) return gcd(gcbd, gcad);
  int gcrd;
  while ((gcrd=gcad%gcbd)) {
    gcad = gcbd;
    gcbd = gcrd;
  }
  return gcbd;
}
int lcm(int lcam, int lcbm){//最小公倍数
 return (lcam*lcbm)/gcd(lcam,lcbm);
}


int main(){
  string s;
  int n;
  cin>>n>>s;
  rep(i,0,s.length()){
    if(((s[i]-'A')+n)<26){
        
      s[i]=s[i]+n;
    }else{
      s[i]=s[i]-(26-n);
    }
  }
  cout<<s;

  
  
}
// int *p = new int[N];

//  vector<int> 変数名(要素数);
//  sort(変数名.begin(),変数名.end());//昇順ソート

// vector<vector<int>> 変数名(左の個数, vector<int>(右の個数));

//cout<<fixed<<setprecision(n);  //小数点n桁まで表示


Measured memory_bytes: 256
/*------------------------------------
........Bismillahir Rahmanir Rahim....
..........created by Abdul Aziz.......
------------------------------------*/
#include <iostream>
#include <algorithm>
#include <stdio.h>
#include <cmath>
#include <vector>
#include <set>
#include <map>
#include <cstring>
#include <unordered_map>
#include <queue>
#define   mod  998244353
#define   int  long long 
#define   ld   long double
#define   pb   push_back
#define   dbg(x)  cerr << #x << " = " << x << '\n'
#define   sz(x)  (int)x.size()
#define   ff   first
#define   ss   second
#define   pii  pair<int,int>
using namespace std;

inline void solve(){ 
    int n;
    cin>>n;
    cout << ((n*800)-((n/15)*200)) ;
}
signed main()
{
    int n=1; // cin>>n;
    while (n--) solve();
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define FOR(i,l,r) for(long long i=(l);i<(r);++i)
#define REP(i,n) FOR(i,0,n)
#define REPS(i,n) FOR(i,1,n+1)
#define int long long
const int MOD=1e9+7;
const int INF=1e15;

signed main(){
    vector<int>A;
    vector<int>B;
    REP(i,7){
        A.push_back(pow(6,i));
    }
    REP(i,6){
        B.push_back(pow(9,i));
    }
    sort(A.rbegin(),A.rend());
  	sort(B.rbegin(),B.rend());
    int N;cin>>N;
    int ans=INF;
    REP(i,N+1){
      	int D=i;
      	int pre=0;
        int K=N-D;
        for(int j=0;D>0;j++){
            pre+=D/A[j];
            D%=A[j];
        }
        for(int j=0;K>0;j++){
            pre+=K/B[j];
            K%=B[j];
        }
        ans=min(pre,ans);
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 256
import math
import functools as f

def gcd(*numbers):
	return f.reduce(math.gcd, numbers)

	

k = int(input())

s = 0

for i in range(1,k+1):
	for j in range(1,k+1):
		t = math.gcd(i,j)
		for l in range(1,k+1):
				s += math.gcd(t,l)

print(s)


Measured memory_bytes: 9576
#include"bits/stdc++.h"
#include<cassert>
using namespace std;
#define int long long
#define rep(i,n) for(int i=0;i<n;i++)
const long long mod = 998244353;
const long long inf = 1ll << 61;
typedef pair<int, int> P;
int a[100006], b[100006];
signed main() {
	int n; cin >> n;
	rep(i, 1 + n)cin >> a[i];
	rep(i, n)cin >> b[i];
	int cnt = 0;
	for (int i = n + 1; i > 0; i--) {
		if (a[i] >= b[i - 1]) {
			cnt += b[i - 1];
			a[i] -= b[i - 1];
		}
		else {
			cnt += a[i];
			cnt += min(a[i - 1], b[i - 1] - a[i]);
			a[i - 1] -= min(a[i - 1], b[i - 1] - a[i]);
		}
	}
	cout << cnt << endl;
}

Measured memory_bytes: 1792
#include <iostream>
#include <iomanip> //! for setprecision(10)
#include <math.h>
#include <algorithm>
#include <functional> 
#include <string>
#include <vector>

#include <cstring>
#include <set>
#include <map>
#include <queue>
#include <utility>
#include <limits.h>

using namespace std;

typedef long long LL;

#define rep(i,n) for (int i = 0; i < (n); ++i)
#define dump(c) { for (auto it = c.begin(); it != c.end(); ++it) if (it == c.begin()) cout << *it; else cout << ' ' << *it; cout << endl; } 
#define dumpMap(m) { for (auto it: m) cout << it.first << "=>" << it.second << ' '; }

const int MOD = 1000000007;

const int MAXN = 100;
const int MAXW = 100000;
LL dp[MAXN+1][MAXW+1];
int w[MAXN+1];
int v[MAXN+1];

int main()
{
	cin.tie(0);
	ios::sync_with_stdio(0);
    
    int N, W;
    cin >> N >> W;
    for (int i = 1; i <= N; ++i) {
        cin >> w[i] >> v[i];
    }

    for (int i = 1; i <= N; ++i) {
        for (int j = 1; j <= W; ++j) {
            if (j < w[i]) {
                dp[i][j] = dp[i-1][j];
            } else {
                dp[i][j] = max(dp[i-1][j-w[i]] + v[i], dp[i-1][j]);        
            }
        }
    }

    cout << dp[N][W] << endl;

    return 0;
}


Measured memory_bytes: 78336
#include<stdio.h>
int main(void)
{
    long long int x,k,d,s,x_1,x_2;
    scanf("%lld%lld%lld",&x,&k,&d);
    if(x<0) x *= -1;
    s = x/d;
    if(s > 0){
        if(s < k){
            x_1 = x-d*s;
            x_2 = (x-d*(s+1))*-1;
            if((k-s)%2==0) x = x_1;
            else x = x_2;
        }
        else{
            x = x-k*d;
        }
    }
    else if(k%2!=0) x=(x-d)*-1;
    printf("%lld\n",x);
    return 0;
}

Measured memory_bytes: 1736
import java.util.Scanner;

public class Main{
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        while (true) {
            int n = sc.nextInt();
            if (n == 0) {
                break;
            }
            double sum = 0;
            int[] s = new int[n];
            for (int i=0; i<n; ++i) {
                s[i] = sc.nextInt();
                sum += s[i];
            }
            double ave = sum / n;
            sum = 0;
            for (int i=0; i<n; ++i) {
                sum += (s[i] - ave) * (s[i] - ave);
            }
            System.out.println(Math.sqrt(sum / n));
        }
        sc.close();
    }
}



Measured memory_bytes: 31260
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <climits>
#include <cfloat>
#include <ctime>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <memory>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <sstream>
#include <complex>
#include <stack>
#include <queue>
#include <numeric>
#include <list>

using namespace std;

#ifdef _MSC_VER
#define __typeof__ decltype
template <class T> int __builtin_popcount(T n) { return n ? 1 + __builtin_popcount(n & (n - 1)) : 0; }
#endif

#define foreach(it, c) for (__typeof__((c).begin()) it=(c).begin(); it != (c).end(); ++it)
#define all(c) (c).begin(), (c).end()
#define rall(c) (c).rbegin(), (c).rend()
#define popcount __builtin_popcount

#define rep(i, n) for (int i = 0; i < n; ++i)

template <class T> void max_swap(T& a, const T& b) { a = max(a, b); }
template <class T> void min_swap(T& a, const T& b) { a = min(a, b); }

const double EPS = 1e-10;
typedef long long ll;
typedef pair<int, int> pint;


int main()
{
	int e;
	while (scanf("%d", &e), e)
	{
		int res = e;

		int z_max = pow(e, 1.0 / 3) + 1;
		int y_max = (int)sqrt(e + 0.0) + 1;
		for (int z = z_max; z >= 0; --z)
		{
			for (int y = y_max; y >= 0; --y)
			{
				int x = e - (z*z*z + y*y);
				if (x >= 0)
					min_swap(res, x + y + z);
			}
		}
		printf("%d\n", res);
	}
}

Measured memory_bytes: 896
using System;

namespace kyopro
{
    class Program
    {
        static void Main(string[] args)
        {
            string str = Console.ReadLine();
            int han1 = 0;
            int han2 = 0;
            for(int i = 1;i <= 3; i++)
            {
                if(str[0] == str[i])
                {
                    han1 = han1 + 1;
                    han2 = i;
                }
            }
            if(han1 == 1)
            {
                if(han2 == 1)
                {
                    if(str[2] == str[3])
                    {
                        Console.WriteLine("Yes");
                    }
                    else
                    {
                        Console.WriteLine("No");
                    }
                }else if(han2 == 2)
                {
                    if (str[1] == str[3])
                    {
                        Console.WriteLine("Yes");
                    }
                    else
                    {
                        Console.WriteLine("No");
                    }
                }else if(han2 == 3)
                {
                    if (str[1] == str[2])
                    {
                        Console.WriteLine("Yes");
                    }
                    else
                    {
                        Console.WriteLine("No");
                    }
                }
            }
            else
            {
                Console.WriteLine("No");
            }
        }
    }
}


Measured memory_bytes: 11092