akhauriyash/Code-Regression huggingface dataset:
import sys
input=sys.stdin.readline

n,a,b,c=map(int,input().split())
L=[]
A=[a,b,c]
for i in range(n):
    L.append(int(input()))
L.sort()

ans=10**9
for i in range(4**n):
    F=[[] for i in range(3)] #竹格納:[A,B,C]
    now=i
    for j in range(n):
        r=now%(4**(j+1))
        chk=r//(4**(j))
        if chk!=3:
            F[chk].append(L[j])
        now-=r    
    if F[0] and F[1] and F[2]: #竹が1本以上あるとき
        mp=0
        for k in range(3):
            f=F[k]
            mp+=abs(sum(f)-A[k])+10*(max(0,len(f)-1))
        ans=min(mp,ans)
print(ans)

Measured memory_bytes: 47120
#include<bits/stdc++.h>
using namespace std;
#define FOR(i,n) for(int i=0;i<n;i++)
#define For(i,m,n) for(int i=m;i<n;i++)
#define ll long long
#define l long
#define all(x) x.begin(),x.end()
#define pb push_back
#define len(x) x.len
ll mob=1000000007;
ll dp[1000][100000];
int main()
{
ll n,w;
cin>>n>>w;
ll a[n][2];
FOR(i,n)
{
    cin>>a[i][0]>>a[i][1];
    
}
FOR(i,n-1)
{
    For(j,i,n-i-1)
    {
        if(a[j][0]>a[j+1][0])
        {
            ll temp=a[j+1][0];
            a[j+1][0]=a[j][0];
            a[j][0]=temp;
            
            ll temp1=a[j+1][1];
            a[j+1][1]=a[j][1];
            a[j][1]=temp1;
            
        }
    }
}
For(i,1,n+1)
{
    For(j,0,w+1)
    {
        if(a[i-1][0]<=j)
        {
            dp[i][j]=max(a[i-1][1]+dp[i-1][j-a[i-1][0]],dp[i-1][j]);
        }
        else
        {
            dp[i][j]=dp[i-1][j];
        }
    }
}
cout<<dp[n][w];

return 0;}

Measured memory_bytes: 81684
using namespace std;
#include <bits/stdc++.h>
#define fdto(i, r, l) for(int i = r; i >= l; --i)
#define fto(i, l, r) for(int i = l; i <= r; ++i)
#define forit(it, type, var) for(type::iterator it = var.begin(); it != var.end(); it++)
#define ii pair<int, int>
#define iii pair<int, ii>
#define MEMS(a,b) memset(a,b,sizeof(a))
#define fi first
#define se second
#define m_p make_pair
#define pb push_back
#define ll long long
#define ld long double
#define maxN 10000000000000
ll power(ll a,ll b){ll res=1;while(b>0){res*=a;b--;}return res;}
int main()
{
    
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    ll n,m,k,x,i,st,a1[200005],a2[200005],pref2[200005];
    
    cin>>n>>m>>k;
    for(i=0;i<n;i++)
    {
       cin>>a1[i];
       
    }
    ll sum=0;
    for(i=0;i<m;i++)
    {
       cin>>a2[i];
       sum+=a2[i];
       pref2[i]=sum;
    }
    ll p=k,ansf=0;
    for(i=0;i<=n;i++)
    {
        if(i==0)
        p=p;
        else
        p=p-a1[i-1];
        if(p<0)
        break;

        ll cnt=i,l,h,mi,ans=-1;

        l=0;
        h=m-1;

        while(l<=h)
        {
            mi=(l+h)/2;
            if(pref2[mi]>p)
            {
                h=mi-1;
            }
            else
            {
                ans=mi;
                l=mi+1;
            }
        }
        ansf=max(ans+1+cnt,ansf);

    }
    cout<<ansf<<endl;
    return 0;
}

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

using namespace std;

#define LL long long

LL n,ans,a[80],b[80],f[80][80],g[80][80];

int main(){
	scanf("%lld",&n);
	for (LL i=1;i<=n;++i) scanf("%lld",&a[i]);
	for (LL i=1;i<=n;++i) scanf("%lld",&b[i]);
	for (LL i=1;i<=n;++i)
		g[i][a[i]]=1;
	for (LL i=50;i;--i){
		memcpy(f,g,sizeof f);
		bool fl=1;
		for (LL j=1;j<=n;++j){
			for (LL k=i-1;k;--k)
				for (LL l=0;l<=50;++l)
					f[j][l%k]|=f[j][l];
			fl&=f[j][b[j]];
		}
		if (!fl){
			ans+=1LL<<i;
			for (LL j=1;j<=n;++j)
				for (LL k=0;k<=50;++k)
					g[j][k%i]|=g[j][k];
		}
	}
	for (LL i=1;i<=n;++i) if (!g[i][b[i]]){puts("-1"); return 0;}
	printf("%lld\n",ans);
	
	return 0;
}
			


Measured memory_bytes: 384
from collections import deque

n, m = map(int, input().split())
mark = [-1] * n
mark[0] = 0
graph = [[] for _ in range(n)]

for _ in range(m):
    a, b = map(int, input().split())
    a, b = a - 1, b - 1
    graph[a].append(b)
    graph[b].append(a)

que = deque([0])
while len(que) != 0:
    i = que.popleft()
    for j in graph[i]:
        if mark[j] == -1:
            mark[j] = i + 1
            que.append(j)

if -1 in mark:
    print('No')
else:
    print('Yes')
    for i in mark[1:]:
        print(i)


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

int main() {
  
  long long X,Y;
  
  cin >> X >> Y;
  
  if (Y % 2 == 1) {
    cout << "No" << endl;
    return 0;
  }
  else {
    if (X * 2 > Y || X * 4 < Y) {
      cout << "No" << endl;
      return 0;
    }
  }
  
  cout << "Yes" << endl;
  
}

Measured memory_bytes: 3632
#include <iostream>

using namespace std;

int main() {
  int A, B;
  float T;
  cin >> A >> B >> T;
  int total = 0;
  for(int i = A; i < T + 0.5; i = i + A) {
  	total = total + B;
  }
  cout << total;
  return 0;
}

Measured memory_bytes: 384
package main

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

// I/O
type Scanner struct {
	sc *bufio.Scanner
}

func NewScanner() *Scanner {
	sc := bufio.NewScanner(os.Stdin)
	sc.Split(bufio.ScanWords)
	sc.Buffer(make([]byte, 1024), int(1e+9))
	return &Scanner{sc}
}

func (s *Scanner) nextStr() string {
	s.sc.Scan()
	return s.sc.Text()
}

func (s *Scanner) nextInt() int {
	i, e := strconv.Atoi(s.nextStr())
	if e != nil {
		panic(e)
	}
	return i
}

func (s *Scanner) nextFloat() float64 {
	f, e := strconv.ParseFloat(s.nextStr(), 64)
	if e != nil {
		panic(e)
	}
	return f
}

func (s *Scanner) nextRuneSlice() []rune {
	return []rune(s.nextStr())
}

func (s *Scanner) nextIntSlice(n int) []int {
	res := make([]int, n)
	for i := 0; i < n; i++ {
		res[i] = s.nextInt()
	}
	return res
}

func (s *Scanner) nextFloatSlice(n int) []float64 {
	res := make([]float64, n)
	for i := 0; i < n; i++ {
		res[i] = s.nextFloat()
	}
	return res
}

// Arithmetic
func max(nums ...int) int {
	m := nums[0]
	for _, i := range nums {
		if m < i {
			m = i
		}
	}
	return m
}

func min(nums ...int) int {
	m := nums[0]
	for _, i := range nums {
		if m > i {
			m = i
		}
	}
	return m
}

func abs(x int) int {
	if x > 0 {
		return x
	}
	return -x
}

func pow(x, y int) int {
	res := 1
	for i := 0; i < y; i++ {
		res *= x
	}
	return res
}

func ceil(a, b int) int {
	if a%b == 0 {
		return a / b
	} else {
		return a/b + 1
	}
}

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

func lcm(a, b int) int {
	return a / gcd(a, b) * b
}

// Sort
type RuneSlice []rune

func (a RuneSlice) Len() int           { return len(a) }
func (a RuneSlice) Less(i, j int) bool { return a[i] < a[j] }
func (a RuneSlice) Swap(i, j int)      { a[i], a[j] = a[j], a[i] }

// Main
const MOD = int(1e+9) + 7
const INF = 1 << 60

func main() {
	sc := NewScanner()
	wtr := bufio.NewWriter(os.Stdout)
	defer wtr.Flush()
	N := sc.nextInt()
	A := sc.nextIntSlice(N)
	ans := []int{}
	S := make([]int, N)
	for i := N; i >= 1; i-- {
		sum := 0
		m := 1
		for j := i; j <= N; j = i * m {
			sum += S[j-1]
			m++
		}
		//fmt.Fprintln(wtr, "i: ", i, "sum: ", sum)
		if sum%2 != A[i-1] {
			ans = append(ans, i)
			S[i-1]++
		} else {
			continue
		}
	}

	fmt.Fprintln(wtr, len(ans))
	if len(ans) == 0 {
		return
	}
	first := true
	for _, num := range ans {
		if !first {
			fmt.Fprint(wtr, " ")
		} else {
			first = false
		}
		fmt.Fprint(wtr, num)
	}
	fmt.Fprintln(wtr)
	//fmt.Fprintln(wtr, S)
}


Measured memory_bytes: 10112
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.InputMismatchException;
import java.io.IOException;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 *
 * @author KharYusuf
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        FastReader in = new FastReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        CTypicalStairs solver = new CTypicalStairs();
        solver.solve(1, in, out);
        out.close();
    }

    static class CTypicalStairs {
        public void solve(int testNumber, FastReader s, PrintWriter w) {
            int n = s.nextInt(), m = s.nextInt(), dp[] = new int[n + 1], mod = (int) 1e9 + 7;
            boolean broken[] = new boolean[n + 1];
            dp[0] = 1;
            while (m-- > 0) {
                broken[s.nextInt()] = true;
            }
            for (int i = 1; i <= n; i++) {
                if (i - 1 >= 0 && !broken[i - 1]) {
                    dp[i] = (dp[i] + dp[i - 1]) % mod;
                }
                if (i - 2 >= 0 && !broken[i - 2]) {
                    dp[i] = (dp[i] + dp[i - 2]) % mod;
                }
            }
            w.println(dp[n]);
        }

    }

    static class FastReader {
        private InputStream stream;
        private byte[] buf = new byte[1024];
        private int curChar;
        private int numChars;
        private FastReader.SpaceCharFilter filter;

        public FastReader(InputStream stream) {
            this.stream = stream;
        }

        public int read() {

            if (numChars == -1)
                throw new InputMismatchException();

            if (curChar >= numChars) {

                curChar = 0;

                try {
                    numChars = stream.read(buf);
                } catch (IOException e) {
                    throw new InputMismatchException();
                }

                if (numChars <= 0)
                    return -1;
            }

            return buf[curChar++];
        }

        public int nextInt() {

            int c = read();

            while (isSpaceChar(c))
                c = read();

            int sgn = 1;

            if (c == '-') {
                sgn = -1;
                c = read();
            }

            int res = 0;

            do {
                if (c < '0' || c > '9')
                    throw new InputMismatchException();

                res *= 10;
                res += c - '0';
                c = read();
            }
            while (!isSpaceChar(c));

            return res * sgn;
        }

        public boolean isSpaceChar(int c) {

            if (filter != null)
                return filter.isSpaceChar(c);

            return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
        }

        public interface SpaceCharFilter {
            public boolean isSpaceChar(int ch);

        }

    }
}



Measured memory_bytes: 23252
#include <iostream>

using namespace std;
int main(int argc, char *argv[]) {
	string s;
	string res = "None";
	bool found;
	cin >> s;
	for(char c = 'a'; c <= 'z'; c++){
		found = true;
		for(int i = 0; i < s.length(); i++){
			if(s[i] == c) found = false;
		}
		if(found){
			res = c;
			break;
		}
	}
	cout << res << endl;
	return 0;
}

Measured memory_bytes: 512
/*   _/                _/                 _/_/_/   _/
  _/_/_/_/   _/_/   _/_/_/_/   _/_/    _/       _/_/
   _/     _/    _/   _/     _/    _/  _/_/_/     _/
  _/     _/    _/   _/     _/    _/  _/    _/   _/
   _/_/   _/_/       _/_/   _/_/      _/_/     _/ */
#include<iostream>
#include<algorithm>
#include<cmath>
#include<iomanip>
#include<set>
#include<map>
#include<queue>
#include<vector>
using namespace std;
using ll=long long;
const int MOD=1e9+7;
const double pi=3.14159265358979323846;
const int inf=2e9;
const ll INF=1e18;
using P=pair<int,int>;
int dx[4]={1,0,-1,0},dy[4]={0,1,0,-1};
int main() {
  cin.tie(0),cout.tie(0);
  ios::sync_with_stdio(false);
  int a,b,c;
  cin >> a >> b >> c;
  cout << a+b+c-max({a,b,c}) << endl;
}

Measured memory_bytes: 256
package main

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

var reader = bufio.NewReader(os.Stdin)

func Scan(a ...interface{}) {
	if _, err := fmt.Fscan(reader, a...); err != nil {
		panic(err)
	}
}

func main() {

	var N, D int
	fmt.Scanf("%d %d", &N, &D)

	//var count int = 0
	X := make([]int, N)
	Y := make([]int, N)

	for i := 0; i < N; i++ {
		Scan(&X[i], &Y[i])
	}

	var count int = 0
	for i := 0; i < N; i++ {
		if D*D >= X[i]*X[i]+Y[i]*Y[i] {
			count++
		}
	}

	fmt.Println(count)

}


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

int dp[4000][4000];
int main(){
	int n;scanf("%d",&n);
	string s;cin>>s;
	dp[0][0]=1;
	for(int i=1;i<n;i++){
		if(s[i-1]=='<'){
			int sum=0;
			for(int j=0;j<=i;j++){
				dp[i][j]=sum;
				(sum+=dp[i-1][j])%=MOD;
			}
		}
		else{
			int sum=0;
			for(int j=i;j>=0;j--){
				(sum+=dp[i-1][j])%=MOD;
				dp[i][j]=sum;
			}
		}
	}
	int ans=0;
	rep(i,n)(ans+=dp[n-1][i])%=MOD;
	cout<<ans<<endl;
}

Measured memory_bytes: 45824
#include <cstdio>
#include <cstring>
#include <map>
#include <vector>
#include <iostream>
#include <iomanip>
#include <algorithm>
using namespace std;
typedef long long ll;
int n;
ll W;
vector<ll> v[4];
ll w0;

ll input(){
  ll x;cin>>x;return x;
}

ll s[4][10001];

int main(){
  cin >> n >> W;
  cin >> w0;
  int v0; cin>>v0;
  v[0].push_back(v0);
  for(int i=0;i<n-1;++i){
    int a,b;cin>>a>>b;
    v[a-w0].push_back(b);
  }
  int m[4]={};
  for(int i=0;i<4;++i){
    m[i]=v[i].size();
    sort(v[i].begin(), v[i].end());
    reverse(v[i].begin(), v[i].end());
    s[i][0]=0;
    for(int j=1;j<=m[i];++j)
      s[i][j]=s[i][j-1]+v[i][j-1];
  }

  ll ans = 0;

  for(ll a=0;a<=m[0];++a){
    for(ll b=0;b<=m[1];++b){
      for(ll c=0;c<=m[2];++c){
	if(w0*(a+b+c)+b+2*c>W)
	  continue;
	ll d=m[3];
	d = min(d, (W-(w0*(a+b+c)+b+2*c))/(w0+3));
	ans = max(ans, s[0][a]+s[1][b]+s[2][c]+s[3][d]);
      }
    }
  }
  
  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 256
function puzzle(){
   var obj={};
   obj["01234567"]=0;
   var dy=[-1,0,0,1];
   var dx=[0,-1,1,0];
   var V=[0,1,2,3,4,5,6,7];
   var P=[[V,0]];
   while(P.length>0){
      var A=P.shift();
      var arr=A[0];
      var cnt=A[1];
      var index=arr.indexOf(0);
      var y=Math.floor(index/4);
      var x=index%4;
      var yx=[arr.slice(0,4),arr.slice(4,8)];
      for(var i=0;i<4;i++){
         var yy=y+dy[i];
         var xx=x+dx[i];
         if(yy<0 || xx<0 || yy>=2 || xx>=4)continue;
         yx[y][x]=yx[yy][xx];
         var card=yx[yy][xx];
         yx[yy][xx]=0;
         var YX=yx[0].concat(yx[1]);
         var str=YX.join("");
         if(obj.hasOwnProperty(str)==false){
               obj[str]=cnt+1;
               P.push([YX,cnt+1]);
         }
         yx[yy][xx]=card;
         yx[y][x]=0;
      }
   }
   return obj;
}
var input = require('fs').readFileSync('/dev/stdin', 'utf8');
var Arr=(input.trim()).split("\n");
var PUZZLE=puzzle();
Arr.forEach(function(v){
   console.log(PUZZLE[v.split(" ").join("")]);
});

Measured memory_bytes: 19228
Imports System
Imports System.Collections.Generic

Module ABC107B

	Dim Hmax,Wmax As Integer
	Dim data() As String
	
	Function IsHorAllWhite(ByVal idx As Integer)
		For w As integer = 0 To Wmax-1
			If data(idx)(w) = "#" Then Return False
		Next
		Return True	
	End Function

	Function IsVerAllWhite(ByVal idx As Integer)
		For h As integer = 0 To HMax-1
			If data(h)(idx) = "#" Then Return False
		Next
		Return True	
	End Function


	Sub Main()
		Dim inputs() As String = Console.ReadLine().Split()
		Hmax = Integer.Parse(inputs(0))
		Wmax = Integer.Parse(inputs(1))
		
		ReDim data(Hmax)
		For i As Integer = 0 To Hmax-1
			data(i) = Console.ReadLine()
		Next

		Dim LiveH As New List(Of Integer)
		Dim LiveW As New List(Of Integer)

		For h As Integer = 0 To Hmax-1
			If Not IsHorAllWhite(h)
				LiveH.Add(h)
			End If
		Next
		For w As Integer = 0 To Wmax-1
			If Not IsVerAllWhite(w)
				LiveW.Add(w)
			End If
		Next

		Dim ansH As Integer = LiveH.Count
		Dim ansW As Integer = LiveW.Count
		
		rem Console.WriteLine(ansH.ToString() & " " & ansW.ToString())
		For h As Integer = 0 To Hmax-1
			If Not LiveH.Contains(h) Then Continue For
			For w As Integer = 0 To Wmax-1
				If Not LiveW.Contains(w) Then Continue For
				Console.Write(data(h)(w))
			Next
			Console.WriteLine()
		Next
	End Sub
End Module



Measured memory_bytes: 20312
#include<bits/stdc++.h>
#define x first
#define y second
#define pb push_back
#define eb emplace_back
#define all(a) (a).begin(),(a).end()
#define SZ(a) (int)(a).size()
#define FOR(i, a, b) for(int i=(a); i<=(b); ++i)
#define iFOR(i, a, b) for(int i=(a); i>=(b); --i)
#define make_unique(a) sort(all((a))), (a).resize(unique(all((a)))-(a).begin())
const double PI = 3.141592;
using namespace std;

typedef pair<int,int> PII;
typedef long long LL;
typedef double DD;
typedef long double LD;
typedef pair<LL,LL> PLL;
typedef pair<DD,DD> PDD;
typedef vector<int> VI;
typedef vector<LL> VL;

int main(){
	int i,j,k,l,a,b,c,d;
	scanf("%d",&i);
    printf("%lf",2*PI*i);
	return 0;
}
/*
 *
 *
 *
 *
 *
 *
 *
 *
 *
 *
 */


Measured memory_bytes: 3824
#include <bits/stdc++.h>
#define REP(i, m, n) for(int (i) = (m); (i) < (n); ++i)
#define rep(i, n) REP(i, 0, n)
#define all(x) (x).begin(), (x).end()
using namespace std;
using Graph = vector<vector<int>>;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
typedef long long ll;
typedef pair<int, int> P;
typedef pair<ll, ll> PL;
const int MOD = 1e9+7;
const int INF = 1<<30;
const ll LINF = 1LL<<60;


int main()
{
    cin.tie(0);
    ios_base::sync_with_stdio(0);
    int n;
    cin >> n;
    vector<ll> a(n);
    rep(i, n) {
        cin >> a[i];
        if (a[i] == 0) {
            cout << 0 << endl;
            return 0;
        }
    }

    ll res = 1;
    rep(i, n) {
        if (a[i] <= 1000000000000000000 / res) {
            res *= a[i];
        }
        else {
            cout << -1 << endl;
            return 0;
        }
    }

    cout << res << endl;

    return 0;
}

Measured memory_bytes: 3992
#include<iostream>
#include<algorithm>
#include<stdio.h>
#include<cstdio>

#include<set>
using namespace std;
set <int>st;
int main(){
	int a,b,c;
	cin>>a>>b>>c;
	st.insert(a);
	st.insert(b);
	st.insert(c);
	if(st.size()==2){
		puts("Yes");
	}
	else{
		puts("No");
	}
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <cmath>
#include <map>
#include <functional>
#include <array>

using namespace std;

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

    int ans = 1000000;
    for(int i = 1; i < N; ++i){
        int A = i;
        int B = N - A;
        int cnt = 0;
        while(A > 0){
            cnt += A % 10;
            A /= 10;
        }
        while(B > 0){
            cnt += B % 10;
            B /= 10;
        }
        ans = min(ans, cnt);
    }
    cout << ans << endl;
}

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

int main(void) {
    int n, m;
    int *a, *b;
    int i;
    int flag = 0;
    unsigned long int *dp;

    scanf("%d%d", &n, &m);

    a = calloc(m, sizeof(int));
    b = calloc(n, sizeof(int));
    dp = calloc(n + 1, sizeof(unsigned long int));

    for (i = 0; i < m; i++) {
        scanf("%d", &a[i]);
        b[a[i]] = 1;
    }

    if (b[1] == 0)
        dp[1] = 1;
    if (b[2] == 1)
        dp[2] = 0;
    else if (b[1] == 1)
        dp[2] = 1;
    else 
        dp[2] = 2;

    for (i = 3; i <= n; i++) {
        dp[i] = (dp[i-1] + dp[i-2]) % 1000000007;
        if (b[i] == 1)
            dp[i] = 0;
    }

    printf("%ld\n", dp[n]);

    return 0;
}

Measured memory_bytes: 1792
#include <algorithm>
#include <array>
#include <cmath>
#include <iostream>
#include <queue>
#include <vector>

const std::array<int32_t, 4> dx = {1, 0, -1, 0};
const std::array<int32_t, 4> dy = {0, 1, 0, -1};

int main() {
  uint32_t H = 0, W = 0, K = 0;
  std::cin >> H >> W >> K;
  std::pair<uint32_t, uint32_t> start, goal;
  std::cin >> start.first >> start.second >> goal.first >> goal.second;
  std::vector<std::vector<int32_t>> G(H + 2, std::vector<int32_t>(W + 2, -1));
  for (size_t i = 0; i < H; i++) {
    std::string str;
    std::cin >> str;
    for (size_t j = 0; j < W; j++) {
      if (str[j] == '.') G[i + 1][j + 1] = 0;
    }
  }

  std::queue<std::pair<uint32_t, uint32_t>> Q;
  Q.push(start);
  while (!Q.empty()) {
    uint32_t x = Q.front().first, y = Q.front().second;
    Q.pop();
    for (size_t i = 0; i < dx.size(); i++) {
      for (size_t k = 1; k <= K; k++) {
        uint32_t to_x = x + dx[i] * k, to_y = y + dy[i] * k;
        if ((to_x == start.first && to_y == start.second) ||
            G[to_x][to_y] == -1)
          break;
        if (G[to_x][to_y] != 0) {
          if (G[to_x][to_y] <= G[x][y]) break;
          continue;
        }
        G[to_x][to_y] = G[x][y] + 1;
        Q.push({to_x, to_y});
      }
    }
  }

  std::cout << (G[goal.first][goal.second] == 0 ? -1
                                                : G[goal.first][goal.second])
            << std::endl;

  return 0;
}

Measured memory_bytes: 18836
#include <iostream>
#define R(i,n) for(i=0;i<n;i++)
using namespace std;
int main()
{
long a[100][100],b[100][100],c[100][100]={0};
int n,m,l,i,j,k;
cin>>n>>m>>l;
R(i,n)R(j,m)cin>>a[i][j];
R(i,m)R(j,l)cin>>b[i][j];
R(i,n)R(j,l)R(k,m)c[i][j]+=a[i][k]*b[k][j];
R(i,n){R(j,l){
if (j)cout<<' ';
cout<<c[i][j]; 
}
cout<<endl;
}
}

Measured memory_bytes: 3316
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for(ll i = 0; i < n; i++)
#define Rep(i, m, n) for(ll i = m; i < n; i++)
#define all(vec) vec.begin(), vec.end()
#define tmax(x, y, z) max((x), max((y), (z)))
#define tmin(x, y, z) min((x), min((y), (z)))
#define MINUS(a) memset(a, 0xff, sizeof(a))
#define ZERO(a) memset(a, 0, sizeof(a))
const ll INF = 1LL << 60;
const ll MM = 1000000000; const ll MOD = MM + 7; const ll MMM=9223372036854775807;//2^63 -1
#define ADD(a,b) a = (a + ll(b)) % MOD
#define MUL(a,b) a = (a * ll(b)) % MOD
ll GCD(ll x, ll y){ if(y == 0) return x; else return GCD(y, x % y);}
ll LCM(ll x, ll y){ return x / GCD(x, y) * y;}
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;}
template<typename A, size_t N, typename T> void FILL(A (&array)[N], const T &val){ fill( (T*)array, (T*)(array+N), val );}
using Graph = vector<vector<ll>>;
ll dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};
ll ddx[8] = {1, 1, 0, -1, -1, -1, 0, 1}, ddy[8] = {0, 1, 1, 1, 0, -1, -1, -1};
//cout << fixed << setprecision(10);


struct UnionFind{
    vector<ll> par;

    UnionFind(ll n) : par(n, -1){ }
    void init(ll n){ par.assign(n, -1); }

    ll root(ll x){
        if(par[x] < 0) return x;
        else return par[x] = root(par[x]);
    }

    bool issame(ll x, ll y){
        return root(x) == root(y);
    }

    bool unite(ll x, ll y){
        x = root(x); y = root(y);
        if(x == y) return false;
        if(par[x] > par[y]) swap(x, y);
        par[x] += par[y];
        par[y] = x;
        return true;
    }

    ll size(ll x){
        return -par[root(x)];
    }
};


int main() {
    ll n, k, l;
    cin >> n >> k >> l;
    UnionFind road(n), train(n);
    rep(i, k){
        ll p, q;
        cin >> p >> q;
        p--, q--;
        road.unite(p, q);
    }
    rep(i, l){
        ll r, s;
        cin >> r >> s;
        r--, s--;
        train.unite(r, s);
    }

    vector<pair<ll, ll>> v(n);
    map<pair<ll, ll>, ll> mp;
    rep(i, n){
        v[i] = make_pair(road.root(i), train.root(i));
        mp[v[i]]++;
    }
    rep(i, n){
        cout << mp[v[i]] << ' ';
    }
    cout << endl;
}


Measured memory_bytes: 20524
#include <bits/stdc++.h>
#define  ren(i,j,n) for(li i=(j);i<(n);i++)
#define  rep(i,n) ren(i,0,(n))
#define  all(a) begin(a),end(a)
using namespace std;
typedef long int li;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<string> vs;
 
int main()
{
    string s;
    cin>>s;
    for(char c:s) cout << (char)((c==',')? ' ':c);
    cout<<endl;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main() {
    long long n; cin >> n;
    map<long long,int> m;
    for(long long i=2;i*i <= n;++i){
      if(n%i==0){
        m[i] = 0;
        while(n%i==0){
          ++m[i];
          n /= i;
        }
      }
    }
    if(n > 1) m[n] = 1;
    int ans = 0, i = 0, tmp;
    for(auto it : m){
      i = 1;
      tmp = it.second;
      while(tmp >= i){
        tmp -= i;
        ++i;
        ++ans;
      }
    }
    cout << ans;
}

Measured memory_bytes: 3632
import java.util.Scanner;

/**
 * Created by LCW on 2016-9-19.
 */

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

		char[] cs = s.toCharArray();
		int[] moved = new int[cs.length];

		for (int i = 0; i < cs.length; i++) {
			int cp = Character.codePointAt(cs, i);
			if (cs[i] != 'a' && cp + n > 122) {// codePointAt 'z'
				int used = 123 - cp;
				n = n - used;
				cs[i] = 'a';
				moved[i] = 1;
			}
		}

		if (n > 0) {
			for (int i = cs.length - 1; i >= 0 && n > 0; i--) {
				int cp = Character.codePointAt(cs, i);
				char newChar = Character.toChars(97 + (cp + n - 97) % 26)[0];
				cs[i] = newChar;
				n = 0;
			}
		}

		System.out.println(String.valueOf(cs));
	}

	/*public static void main(String[] args) {
		String s = "z";
		char[] cs = s.toCharArray();
		System.out.println(Character.toChars(97 + (123 - 97) % 26)[0]);
	}*/
}


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

#define ll long long
#define vi vector<int>
#define vl vector<ll>
#define pii pair<int,int>
#define pll pair<ll,ll>
// pll pp; -> (pp.first,pp.second)
// vector<vl> pp(n,vl(2)); sort(pp.begin(),pp.end(),[](vl a,vl b){return a[0]<b[0];});

#define REP(i,n) for(ll (i)=0;(i)<(n);(i)++)
#define RREP(i,n) for(ll (i)=(n)-1;(i)>=0;(i)--)
#define FOR(i,a,b) for(ll (i)=(a);(i)<(b);(i)++)
#define FORR(i,a,b) for(ll (i)=(b)-1;(i)>=(a);(i)--)
#define DEBUG(x) cout << #x << ": " << x << endl
#define CHMAX(a,b) a=max((a),(b))
#define CHMIN(a,b) a=min((a),(b))
/*}}}*/
int main() {
  ll A,B,C,D,E,a,b,c,d,e,pmax,ans;
  cin >> A>>B>>C>>D>>E;
  a = A%10;
  b = B%10;
  c = C%10;
  d = D%10;
  e = E%10;
  pmax = 10;
  if(a !=0){
    A = A+10-a;
    pmax = min(pmax,a);
  }
  if(b !=0){
    B = B+10-b;
    pmax = min(pmax,b);
  }
  if(c !=0){
    C = C+10-c;
    pmax = min(pmax,c);
  }
  if(d !=0){
    D = D+10-d;
    pmax = min(pmax,d);
  }
  if(e !=0){
    E = E+10-e;
    pmax = min(pmax,e);
  }
  ans = A+B+C+D+E+pmax-10;
  cout << ans<< endl;
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
//#include <boost/multiprecision/cpp_int.hpp>
//namespace mp = boost::multiprecision;

using namespace std;

const double PI = 3.14159265358979323846;
typedef long long ll;
const double EPS = 1e-9;
#define rep(i, n) for (int i = 0; i < (n); ++i)
//#define rep(i, n) for (ll i = 0; i < (n); ++i)
typedef pair<ll, ll> P;
const ll INF = 10e17;
#define cmin(x, y) x = min(x, y)
#define cmax(x, y) x = max(x, y)
#define ret() return 0;

double equal(double a, double b) {
    return fabs(a - b) < DBL_EPSILON;
}

std::istream &operator>>(std::istream &in, set<int> &o) {
    int a;
    in >> a;
    o.insert(a);
    return in;
}

std::istream &operator>>(std::istream &in, queue<int> &o) {
    ll a;
    in >> a;
    o.push(a);
    return in;
}

bool contain(set<int> &s, int a) { return s.find(a) != s.end(); }

//ofstream outfile("log.txt");
//outfile << setw(6) << setfill('0') << prefecture << setw(6) << setfill('0') << rank << endl;
// std::cout << std::bitset<8>(9);
//const ll mod = 1e10;

typedef priority_queue<ll, vector<ll>, greater<ll> > PQ_ASK;


void normalize(vector<P> &nums) {
    if (nums.size() > 1) {
        if (nums[nums.size() - 1].first == nums[nums.size() - 2].first) {
            nums[nums.size() - 2].second += nums[nums.size() - 1].second;
            nums.pop_back();
        }
    }
}

void zouka(vector<P> &nums) {
    if (nums.back().second == 1) {
        nums.back().first += 1;
    } else {
        nums.back().second--;
        nums.push_back(P(nums.back().first + 1, 1));
    }
    normalize(nums);
}

bool check(vector<int> &a, int mid) {
    int n = a.size();
    vector<P> nums;
    nums.emplace_back(0, a[0]);
    for (int i = 1; i < n; i++) {
        if (a[i - 1] < a[i]) nums.push_back(P(0, a[i] - a[i - 1]));
        else {
            long long sum = 0;
            while (nums.size() > 0 && sum + nums.back().second <= a[i - 1] - a[i]) {
                sum += nums.back().second;
                nums.pop_back();
            }
            nums.back().second -= a[i - 1] - a[i] - sum;

            if (nums.back().first == mid - 1) {
                if (nums.size() == 1) {
                    return false;
                }
                long long num = nums.back().second;
                nums.pop_back();
                zouka(nums);
                nums.push_back(P(0, num));
            } else zouka(nums);
        }
        normalize(nums);
    }
    return true;
}

int main() {
    int n;
    cin >> n;
    vector<int> a(n);
    rep(i, n) cin >> a[i];

    int floor = 0, ceil = n + 1;
    while (floor + 1 < ceil) {
        int mid = (floor + ceil) / 2;
        bool ok = check(a, mid);
        if (ok) ceil = mid;
        else floor = mid;
    }
    cout << ceil << endl;
}


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

long long n, res = 0;

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

    cin >> n;
    long long res = n * (n + 1) / 2;
    res -= n / 3 * (n / 3 + 1) / 2 * 3;
    res -= n / 5 * (n / 5 + 1) / 2 * 5;
    res += n / 15 * (n / 15 + 1) / 2 * 15;

    cout << res << "\n";
    return 0;
}


Measured memory_bytes: 3576
/* The journey is what brings us pleasure, not the destination <3 */

#include<bits/stdc++.h>

#define PI acos(-1)
#define _fastIO ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define MOD 1000000007
#define mxx 1000000
#define all(v) v.begin(),v.end()

using namespace std;
typedef long long ll;

int tc;


void solve()
{
    string s;
    map<string,int>mp;
    ll n;
    cin>>n;
    for(int i=0; i<n; i++){
        cin>>s;
        mp[s]++;
    }
    cout<<"AC x "<<mp["AC"]<<endl;
    cout<<"WA x "<<mp["WA"]<<endl;
    cout<<"TLE x "<<mp["TLE"]<<endl;
    cout<<"RE x "<<mp["RE"]<<endl;
}

int main()
{

    _fastIO;

    //cin>>tc;while(tc--)
    solve();

    return 0;
}


Measured memory_bytes: 3648
#include <bits/stdc++.h>
typedef long long ll; 
const ll mod = 1e9+7;
#define fo(i, n) for (int i = 0; i < n; i++)
#define sc(n) scanf("%d", &n) 
using namespace std;

void solve() {
    int r; cin >> r;
    cout << 3*r*r;

}

int main() {
    int t = 1;
    //scanf("%d", &t);
    while (t--) {
        solve();
    }
    return 0;
}

Measured memory_bytes: 256
X, Y, A, B, C = map(int, input().split())
P = sorted(list(map(int, input().split())), reverse=True)
Q = sorted(list(map(int, input().split())), reverse=True)
R = sorted(list(map(int, input().split())), reverse=True)

red = sorted(P[:X])
gre = sorted(Q[:Y])
m = min((X+Y),C)
n = R[:m]
red.extend(gre)
red.extend(n)
red = sorted(red, reverse=True)

print(sum(red[:X+Y]))

Measured memory_bytes: 23604
def gcd(a, b):
    if(a < b):
        a, b = b, a
    if(b == 0):
        return a
    return gcd(b, a % b)

def lcm(a, b):
    return a // gcd(a, b) * b

N = int(input())
A = list(map(int, input().split()))
l = A[0]
for a in A:
    l = lcm(l, a)
ans = 0
mod = int(1e9+7)
for a in A:
    ans += (l * pow(a, mod-2, mod))%mod
    ans %= mod
print(ans)


Measured memory_bytes: 4084
#include<cstdio>
#include<iostream>
#include<algorithm>
#include<string>
using namespace std;
int main(void)
{
  int n;
  cin >> n;
  getchar();
  for(int i=0;i<n;i++){
    string s;
    getline(cin,s);
    for(int j=0;j<(int)s.size()-6;j++){
      string hos = s.substr(j,7);
      if(hos == "Hoshino"){
	s[j+6] = 'a';
      }
    }
    cout << s << endl;
  }
}

Measured memory_bytes: 1220
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace C
{
    class Program
    {
        static void Main(string[] args)
        {
            string line = Console.ReadLine();
            string[] strs = line.Split(' ');
            long A = long.Parse(strs[0]);
            long B = long.Parse(strs[1].Replace(".", ""));

            Console.WriteLine((A * B) / 100);
        }
    }
}


Measured memory_bytes: 27532
#

#

import itertools
from collections import Counter
from collections import defaultdict
from collections import deque
import bisect
from heapq import heappush, heappop

def main():
    n = int(input())
    a = [int(input()) for _ in range(n)]
    sort_a = sorted(a)

    for v in a:
        if v == sort_a[-1]:
            print(sort_a[-2])
        else:
            print(sort_a[-1])


if __name__ == '__main__':
    main()


Measured memory_bytes: 70688
#include<bits/stdc++.h> 
//#define <- プログラムの文字列を置換する
//typedef <- 新しい型に名前を付けるためのキーワード

using namespace std;

#define MAX_N 100000

typedef long long ll;
typedef pair<int,int> P;

const long long MOD = 1e9 + 7;
const long long INF = 1e15;
const int INF_INT = 1e9;

template<class TYPE>
struct edge{
    TYPE to,cost; 
    edge(TYPE t,TYPE c){
        to = t;
        cost = c;
    }
};

int main(){
    int R,G;
    cin >> R >> G;
    cout << R + 2 * (G - R) << endl;
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main(void){
    int a,b;
    cin >> a >> b;
    if(a < b)
        cout << "a < b" << endl;
    else if(a > b)
        cout << "a > b" << endl;
    else
        cout << "a == b" << endl;

    return 0;
}



Measured memory_bytes: 3112
N = int(input())
AB = [tuple([int(_) for _ in input().split()]) for i in range(N)]

AB.sort(key=lambda x:x[1])

result = True

t = 0
for a, b in AB:
    if t + a > b:
        result = False
        break
    else:
        t += a

if result:
    print("Yes")
else:
    print("No")


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

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

int main() {
  int N;
  cin >> N;
  vector<int> vec(N);
  rep(i, N) cin >> vec[i];
  sort(vec.begin(), vec.end());

  int ans = 0;

  for (int i = 0; i < N; i++) {
    for (int j = 0; j < i; j++) {
      for (int k = 0; k < j; k++) {
        if (vec[k] != vec[j] && vec[i] != vec[j] && vec[k] + vec[j] > vec[i]) {
          ans++;
        }
      }
    }
  }

  cout << ans << endl;

  return 0;
}


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

using namespace std;
using ll = long long;
#define int ll
using VI = vector<int>;
using VVI = vector<VI>;
using PII = pair<int, int>;

#define FOR(i, a, n) for (ll i = (ll)a; i < (ll)n; ++i)
#define REP(i, n) FOR(i, 0, n)
#define ALL(x) x.begin(), x.end()
#define PB push_back

const ll LLINF = (1LL<<60);
const int INF = (1LL<<30);
const int MOD = 1000000007;

template <typename T> T &chmin(T &a, const T &b) { return a = min(a, b); }
template <typename T> T &chmax(T &a, const T &b) { return a = max(a, b); }
template <typename T> bool IN(T a, T b, T x) { return a<=x&&x<b; }
template<typename T> T ceil(T a, T b) { return a/b + !!(a%b); }
template<class S,class T>
ostream &operator <<(ostream& out,const pair<S,T>& a){
  out<<'('<<a.first<<','<<a.second<<')';
  return out;
}
template<class T>
ostream &operator <<(ostream& out,const vector<T>& a){
  out<<'[';
  REP(i, a.size()) {out<<a[i];if(i!=a.size()-1)out<<',';}
  out<<']';
  return out;
}

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

signed main(void)
{
  cin.tie(0);
  ios::sync_with_stdio(false);

  int n;
  cin >> n;

  string s = to_string(n);
  int sum = 0;
  REP(i, s.size()) sum += s[i] - '0';

  if(n%sum == 0) cout << "Yes" << endl;
  else cout << "No" << endl; 

  return 0;
}


Measured memory_bytes: 256
use proconio::{fastout, input};

#[fastout]
fn main() {
    input! {
        n: usize,
        mut a: [u64; n],
    }

    let mut ans = 0;

    for &ai in a.iter() {
        let mut _t = ai;
        while _t & 1 == 0 {
            _t = _t >> 1;
            ans += 1;
        }
    }

    println!("{}", ans);
}


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

#define int long long
#define vvi vector<vector<int>>
#define vec vector
#define pq priority_queue
#define all(v) (v).begin(), (v).end()
#define uniqueV(x) sort(x.begin(), x.end()); x.erase(unique(x.begin(), x.end()), x.end());
#define rep(i, n) for (int (i) = (0); (i) < (n); ++(i))
#define repp(i, m, n) for (int (i) = (m); (i) < (n); ++(i))
#define dbg(x) cerr << #x << ": " << x << endl;
#define dbg2(x, y) cerr<<"("<<#x<<", "<<#y<<") = "<<"("<<x<<", "<<y<<")"<<endl;
#define dbg3(x, y, z) cerr<<"("<<#x<<", "<<#y<<", "<<#z<<") = "<<"("<<x<<", "<<y<<", "<<z<<")"<<endl;
#define dbgB(value, size) cerr<<#value<<": "<<bitset<size>(value) << endl;
#define line() cerr << "---------------" << endl;

const int dx[] = {1, -1, 0, 0};
const int dy[] = {0, 0, -1, 1};
const double PI = 3.14159265358979323846;

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<typename T>
void print1(T begin, T end) {
  while (begin != end) {
    cout << (*begin) << " ";
    *begin++;
  }
  cout << endl;
}

template<typename T>
void print2(T Array, int height, int width) {
  for (int i = 0; i < height; i++) {
    for (int j = 0; j < width; j++) {
      cout << " " << Array[i][j];
    }
    cout << endl;
  }
}

void print() { std::cerr << endl; }
template <class Head, class... Tail>
void print(Head&& head, Tail&&... tail) {
  std::cerr << head << " ";
  print(std::forward<Tail>(tail)...);
}

template<class T>
void Add(T &a, const T &b, const T &mod=1000000007) {
  int val = ((a % mod) + (b % mod)) % mod;
  if (val < 0) { val += mod; }
  a = val;
}

template <typename X, typename T> auto vectors(X x, T a) { return vector<T>(x, a); }
template <typename X, typename Y, typename Z, typename... Zs> auto vectors(X x, Y y, Z z, Zs... zs) { auto cont = vectors(y, z, zs...); return vector<decltype(cont)>(x, cont); }

// ------------------------------------------------------------------------------------------

const int mod = 1e9 + 7;

int a, b, x;

signed main() {
  cin >> a >> b >> x;

  if (x < a) {
    cout << x % mod << endl;
    return 0;
  }

  int cnt = (x - a) / (a - b);
  int ans = ((cnt%mod) * (a%mod))%mod;
  x -= cnt * (a - b);

  while (x >= a) {
    x -= a;
    x += b;
    ans += a;
    ans %= mod;
  }

  ans += x;
  ans %= mod;

  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 3076
#include<bits/stdc++.h>
using namespace std;
#define F(i,L,R) for(int i=L;i<R;i++)
#define FE(i,L,R) for(int i=L;i<=R;i++)
#define RF(i,l,r) for(int i=r;i>l;i--)
#define RFE(i,l,r) for(int i=r;i>=l;i--)
#define getI(i) scanf("%d",&i)
#define getII(i,j) scanf("%d%d",&i,&j)
#define getIII(i,j,k) scanf("%d%d%d",&i,&j,&k)
#define VgetI(i) int (i);scanf("%d",&(i));
#define VgetII(i,j) int (i),(j);scanf("%d%d",&(i),&(j));
#define VgetIII(i,j,k) int (i),(j),(k);scanf("%d",&(i),&(j),&(k));
#define EoF(n) int(n);while(~getI(n))
#define max(a,b) (a>b?a:b)
#define min(a,b) (a<b?a:b)
#define abs(n) (n>0?n:(-n))
#define INF 2147483647
#define nINF -2147483648
int main(){
	int n;
	while(~getI(n)){
		int sum=0,rn=n;
		while(n){
			sum+=n%10;
			n/=10;
		}
		printf("%s\n",rn%sum==0?"Yes":"No");
	}
}


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


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

int ans=0;
for(char i='0';i<='9';i++){
  for(char j='0';j<='9';j++){
    for(char k='0';k<='9';k++){
      int x=0;
      vector<char> t(3);
      t[0]=i,t[1]=j,t[2]=k;
      int y=0;
      while(x<N){
        if(S[x]==t[y]){
          y++;
          x++;
          if(y==3){
            ans++;
            break;
          }
        }
        else x++;
      }
    }
  }
}
cout<<ans<<endl;
}


Measured memory_bytes: 384
#pypyは内包表記使わない, rstrip注意
#提出前に見返すこと！
def main():
    import sys
    input = sys.stdin.readline
    sys.setrecursionlimit(10000000)
    from collections import Counter, deque
    #from collections import defaultdict
    from itertools import combinations, permutations, accumulate
    #from itertools import product
    from bisect import bisect_left,bisect_right
    import heapq
    from math import floor, ceil
    #from operator import itemgetter

    inf = 10**17
    #mod = 1000000007

    N = int(input())
    dp = [inf]*(N+1)
    dp[0] = 0
    money = [1, 6, 9, 36, 81, 216, 729, 6**4, 6561, 6**5, 6**6, 59049]
    while dp[N]==inf:
        for i in range(N, 0, -1):
            for j in money:
                if i<j:
                    continue
                dp[i] = min(dp[i-j]+1, dp[i])
    print(dp[N])

if __name__ == '__main__':
    main()

Measured memory_bytes: 42092
#[allow(unused_imports)]
use proconio::input;

fn main() {
    input! {
        s: String,
    }
    let mut yes = false;
    for c in s.chars() {
        if c == '7' {
            yes = true;
        }
    }
    println!("{}", if yes {"Yes"} else {"No"});
}

Measured memory_bytes: 2096
#include<bits/stdc++.h>
using namespace std;
 
#define ll long long
#define lf long double
#define pb push_back
#define mp make_pair
#define F first
#define S second
typedef pair <ll,ll> ii;
typedef vector <ll> vi;
typedef vector <ii> vii;
typedef vector <bool> vb;
typedef vector <vector <ll> > vv;
typedef vector <vector <vector<ll> > > vvv;
typedef vector <string> vs;
typedef vector <lf> vf;
#define sz(x) (ll)(x).size()
#define tr1(x) cerr << #x << ": " << x << endl
#define tr2(x, y) cerr << #x << ": " << x << " | " << #y << ": " << y << endl
#define tr3(x,y,z) cerr<<#x<<": "<<x<<" | "<<#y<<": "<<y<<" | "<<#z<<": "<<z<<endl
#define tr4(x,y,z,w) cerr<<#x<<": "<<x<<" | "<<#y<<": "<<y<<" | "<<#z<<": "<<z<<" | "<<#w<<": "<<w<<endl
#define trv(a) cerr<<#a<<": ";for(ll zz=0;zz<sz(a);zz++) cerr<<a[zz]<<" ";cerr<<endl
#define trii(x) cerr<<#x<<": ("<<x.F<<","<<x.S<<")\n";
#define trset(s) cerr<<#s<<": ";for(auto &i:s) cerr<<i<<" ";cerr<<"\n"
#define triiset(s) cerr<<#s<<": ";for(auto &i:s) trii(i);
#define epsilon 0.000000001L
#define mod 1000000007ll
#define inf 9999999999999999ll
#define nl endl
#define all(x) x.begin(), x.end()
#define r_all(x) x.rbegin(), x.rend()
#define fast()  ios_base::sync_with_stdio(false);cin.tie(NULL)
#define modulo 998244353ll

int main()
{
    fast();
    ll a,b;
    cin>>a>>b;
    ll ans=a*b;
    ans/=__gcd(a,b);
    cout<<ans<<nl;
}


Measured memory_bytes: 256
#include <stdio.h>
#include <string.h>
#define lop(i, n) for(i=0; i<n; i++)

int main()
{
	int i, x, y;
	int a, b; /* a：８％ ｂ：１０％ */ 
	scanf("%d %d", &a, &b);
	
	for(i=1; i<1011; i++){
		x=i*0.08, y=i*0.1;
		if(x==a && y==b){
		printf("%d", i); return 0;
		}
	}
	
	printf("-1");
	
return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
using ll = long long;
using namespace std;
int main() {
  int a1, a2, a3;
  cin >> a1 >> a2 >> a3;
  
  if (a1 + a2 + a3 >= 22)
    cout << "bust" << endl;
  else
    cout << "win" << endl;
  
  return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <iostream>
#include <algorithm>
using namespace std;

void check_data(int *data, int n, char c){
  for(int i=0; i<13; i++){
    bool hit = false;
    for(int j=0; j<n; j++){
      if(data[j]==i+1){
        hit = true;
        break;
      }
    }
    if(!hit){
      printf("%c %d\n", c, i+1);
    }
  }
}

int main(void){
  int n, s[13], h[13], c[13], d[13];
  int s_idx=0, h_idx=0, c_idx=0, d_idx=0;
  cin >> n;
  for(int i=0; i<n; i++){
    char kind;
    int num;
    cin >> kind >> num;
    if(kind=='S'){
      s[s_idx] = num;
      s_idx++;
    }else if(kind=='H'){
      h[h_idx] = num;
      h_idx++;
    }else if(kind=='C'){
      c[c_idx] = num;
      c_idx++;
    }else{
      d[d_idx] = num;
      d_idx++;
    }
  }

  sort(s,s+s_idx);
  sort(h,h+h_idx);
  sort(c,c+c_idx);
  sort(d,d+d_idx);

  check_data(s, s_idx, 'S');
  check_data(h, h_idx, 'H');
  check_data(c, c_idx, 'C');
  check_data(d, d_idx, 'D');

  return 0;
}



Measured memory_bytes: 3256
N = int(input())
h = list(map(int, input().split()))

dp = [0]

for i in range(1, N):
    m = dp[i - 1] + abs(h[i] - h[i - 1])
    if i > 1:
        m = min(m, dp[i - 2] + abs(h[i] - h[i - 2]))
    dp.append(m)

print(dp[-1])

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

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

#define FOR(i,a,b) for(ll i=(a);i<(b);++i)
#define ALL(v) (v).begin(), (v).end()
#define p(s) cout<<(s)<<endl
#define p2(s, t) cout << (s) << " " << (t) << endl
#define br() p("")
#define pn(s) cout << (#s) << " " << (s) << endl
#define p_yes() p("YES")
#define p_no() p("NO")

const ll mod = 1e9 + 7;
const ll inf = 1e18;

void vprint(vector<ll> A){
    ll L = A.size();
    FOR(i, 0, L){
        if(i) cout << ' ';
        cout << A[i];
    }
    cout << endl;
}

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

    // input
    ll r; cin >> r;
    ll ans = 3 * r * r;
    p(ans);
    
    return 0;
}

Measured memory_bytes: 256
#include <stdio.h>

int A[1000000], n;

//二分探索
int binarySearch(int key){
  int left = 0;
  int right = n;//要素の数（A[n]には値は入っておらず番兵の役割がある）
  int mid;

  while(left < right){
    mid = (left + right)/2; //midはint型であるから少数部分は切り捨て
    if(key == A[mid]) return 1; //keyを発見
    if(key > A[mid]) left = mid + 1; //もし検索したい値が中央値より大きいならば後半を探索
    else if (key < A[mid])right = mid; //前半を探索
  }
  return 0;//見つからなかった場合
}

int main(){
  int i, q, k, sum = 0;

  scanf("%d", &n);//要素の数
  for(i = 0; i < n; i++){
    scanf("%d", &A[i]);//配列Aに値をセット
  }

  scanf("%d", &q);//二つ目の配列の要素数
  for(i = 0; i < q; i++){//二つ目の配列の要素数の分だけループする
    scanf("%d", &k);//値を保存して
    if(binarySearch(k)) sum++;//binarySearchで値が見つかればsumがインクリメントされる
    }
    printf("%d\n", sum);

    return 0;

}


Measured memory_bytes: 2120
#include <iostream>
#include <algorithm>
#include <cmath>
#include <cstdlib>
#include <cstdio>
#include <cstring>
#include <iomanip>
#include <string>
#include <set>
#include <vector>
#include <queue>
#include <stack>
using namespace std;
#define ms(a, x) memset(a, x, sizeof(a))
#define fore(i, a, n) for (long long i = a; i < n; i++)
#define ford(i, a, n) for (long long i = n - 1; i >= a; i--)
#define si(a) scanf("%d", &a)
#define sii(a, b) scanf("%d%d", &a, &b)
#define debug(a) cout << a << endl
#define endl '\n'
#define pi acos(-1.0)
#define tr t[root]
#define lson t[root << 1]
#define rson t[root << 1 | 1]
#define IO ios::sync_with_stdio(false), cin.tie(0)
const double eps = 1e-8;
inline int sgn(const double &x) { return x < -eps ? -1 : x > eps; }
typedef long long ll;
const int inf = 0x3f3f3f3f;
const int maxn=1000100;
#define maxn0 1e9+7;
//=================================================

ll sum;
ll w[maxn];
ll dp[maxn];
ll v[maxn];

// void init() {
//     for(ll i=0;i<=n;i++){
//         w[i]=0;
//         v[i]=0;
//     }
// }
int main() {
    IO;
    ll n,W;
    cin>>n>>W;
    // sum=0;
    // init();
    memset(dp,inf,sizeof(dp));
    dp[0]=0;
    for(int i=1;i<=n;i++){
        cin>>w[i]>>v[i];
        // sum+=v[i];
    }
    for(int i=1;i<=n;i++) {
        for(int j=100000;j>=v[i];j--) {
            dp[j]=min(dp[j],dp[j-v[i]]+w[i]);
        }
    }
    ll ans=-1;
    for(int i=1;i<=100000;++i) {
        if(dp[i]<=W)
            ans=max(ans,1LL*i);
    }
    cout<<ans<<endl;

    return 0;
}

Measured memory_bytes: 10624
#pragma GCC optimize("O2,unroll-loops")
#pragma GCC target("avx,avx2,sse,sse2,ssse3")
#include<bits/stdc++.h>
#define all(x) x.begin(), x.end()
#define pb push_back
using namespace std;
using ll = long long;
using vi = vector<ll>;
using pi = pair<ll, ll>;
const int maxn = 5050, mod = 1e9 + 7;
vi pref(string s) {
	vi b(s.size()+1);
	int i, j;
	i = 0, b[0] = j = -1;
	while(i < s.size()) {
		while(j != -1 && s[i] != s[j]) j = b[j];
		i++, j++;
		b[i] = j;
	}
	return b;
}
int main() {
	cin.tie(0)->sync_with_stdio(0);
	string s;
	cin >> s;
	int n = s.size();
	set<int> _t(all(s));
	if(_t.size() == 1) {
		cout << n << "\n1\n";
		return 0;
	}
	vi p = pref(s);
	reverse(all(s));
	vi f = pref(s);
	for(int i = 1; i <= n; i++) {
		p[i] = !p[i] || i%(i - p[i]) != 0;
		f[i] = !f[i] || i%(i - f[i]) != 0;
	}
	reverse(all(f));
	if(p.back()) {
		cout << "1\n1\n";
		return 0;
	}
	int cnt = 0;
	for(int i = 1; i < n; i++) {
		cnt += p[i] && f[i];
	}
	cout << "2\n" << cnt << '\n';
}


Measured memory_bytes: 9012