akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <string>
#include <cmath>
#include<algorithm>
#include<stack>
#include<queue>
#include<map>
#include<set>
#include<iomanip>
#define _USE_MATH_DEFINES
#include <math.h>
#include <functional>
#include<complex>
using namespace std;

#define rep(i,x) for(ll i=0;i<x;i++)
#define repn(i,x) for(ll i=1;i<=x;i++)

typedef long long ll;
const ll INF = 1e17;
const ll MOD = 1000000007;
const ll MAX = 4000001;
const long double eps = 1E-14;

ll max(ll a, ll b) {
	if (a > b) { return a; }
	return b;
}

ll min(ll a, ll b) {
	if (a > b) { return b; }
	return a;
}

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

ll lcm(ll a, ll b) {
	return a / gcd(a, b) * b;
}

struct edge {
	ll ind;
	ll fr;
	ll to;
	ll d;
};

class mint {
	long long x;
public:
	mint(long long x = 0) : x((x% MOD + MOD) % MOD) {}
	mint operator-() const {
		return mint(-x);
	}
	mint& operator+=(const mint& a) {
		if ((x += a.x) >= MOD) x -= MOD;
		return *this;
	}
	mint& operator-=(const mint& a) {
		if ((x += MOD - a.x) >= MOD) x -= MOD;
		return *this;
	}
	mint& operator*=(const  mint& a) {
		(x *= a.x) %= MOD;
		return *this;
	}
	mint operator+(const mint& a) const {
		mint res(*this);
		return res += a;
	}
	mint operator-(const mint& a) const {
		mint res(*this);
		return res -= a;
	}
	mint operator*(const mint& a) const {
		mint res(*this);
		return res *= a;
	}

	mint pow(ll t) const {
		if (!t) return 1;
		mint a = pow(t >> 1);
		a *= a;
		if (t & 1) a *= *this;
		return a;
	}

	// for prime MOD
	mint inv() const {
		return pow(MOD - 2);
	}
	mint& operator/=(const mint& a) {
		return (*this) *= a.inv();
	}
	mint operator/(const mint& a) const {
		mint res(*this);
		return res /= a;
	}

	friend ostream& operator<<(ostream& os, const mint& m) {
		os << m.x;
		return os;
	}
};

mint pw(mint a, ll b) {
	if (b == 0) { return 1; }
	mint ret = pw(a, b >> 1);
	ret *= ret;
	if (b & 1) { ret *= a; }
	return ret;
}

typedef vector<ll> vll;
typedef vector<vector<ll>> vvll;
typedef vector<vector<vector<ll>>> vvvll;

typedef vector<mint> vmint;
typedef vector<vector<mint>> vvmint;
typedef vector<vector<vector<mint>>> vvvmint;

//////////////////////////////////////


int main() {
	ll N, K, M;
	cin >> N >> K >> M;

	vvll pr(N + 1, vll(N + 1, 0));

	rep(i, N + 1)pr[0][i] = 1;

	repn(i, N)rep(j, N+1) {
		rep(k, j + 1) {
			ll now = pr[i - 1][k] * (k + 1) % M;
			pr[i][j] = (pr[i][j] + now) % M;
		}

		//cout << i << " " << j << " " << pr[i][j] << endl;
	}

	

	vvll dp(K + 1, vll(N + 1, 0));

	dp[0][0] = 1;

	repn(i, K)rep(j, N + 1) {
		//cout << i << " " << j << endl;
		rep(k, j + 1) {
			ll now = dp[i - 1][k]  * pr[j-k][k] % M;
			dp[i][j] = (dp[i][j] + now) % M;
			//cout << now << endl;
		}

		//cout << i << " " << j << " " << dp[i][j] << endl;
	}

	cout << dp[K][N] << endl;
}

Measured memory_bytes: 5072
#include<bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
using namespace std;
using namespace __gnu_pbds;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
#define FILL(i,n) memset(i,n,sizeof i)
#define X first
#define Y second
#define ET cout << "\n"
#define SZ(a) ((int)a.size())
#define ALL(v) v.begin(),v.end()
#define pb push_back
#define IOS() ios_base::sync_with_stdio(0);cin.tie(0);
#ifdef bbq
#define debug(...) {\
    fprintf(stderr,"%s - %d (%s) = ",__PRETTY_FUNCTION__,__LINE__,#__VA_ARGS__);\
    _do(__VA_ARGS__);\
}
#define DB(a,s,e) {for(int _i=s;_i<e;++_i) cerr << a[_i] << " ";cerr << "\n";}
template<typename T>void _do(T &&x){cerr<<x<<endl;}
template<typename T,typename ...S> void _do(T &&x,S &&...t){cerr<<x<<", ";_do(t...);}
template<typename a,typename b> ostream& operator << (ostream &s,const pair<a,b> &p){return s<<"("<<p.X<<","<<p.Y<<")";}
#else
#define debug(...)
#define DB(a,s,e)
#endif

vector<int> G[200005],G2[200005];
int dis[200005],in[200005],fa[200005],out[200005],dft,ans,flag;

void dfs2(int u,int d,int f)
{
	fa[u]=f,dis[u]=d,in[u]=++dft;
	for(int i:G2[u])
		if(i!=f)
			dfs2(i,d+1,u);
	out[u]=dft;	
}

bool ancestor(int u,int v)
{
	return in[u]<=in[v]&&out[u]>=out[v];
}

void dfs(int u,int d,int f)
{
	for(int i:G[u])
	{
		if(i!=f&&dis[i]>d+1)
			dfs(i,d+1,u);
		if(!ancestor(fa[u],i)&&i!=fa[fa[u]])
			flag=1;
	}
	ans=max(ans,dis[u]*2);
}

int main()
{
    IOS();
    int n,x,y,a,b;
    cin >> n >> x >> y;
    for(int i=1;i<n;++i)	
    	cin >> a >> b,G[a].pb(b),G[b].pb(a);
    for(int i=1;i<n;++i)
    	cin >> a >> b,G2[a].pb(b),G2[b].pb(a);
    dfs2(y,0,y),dfs(x,0,x);
    if(flag)
    	cout << "-1\n";
    else
    	cout << ans << "\n";
}

Measured memory_bytes: 40320
#!usr/bin/env python3
from collections import defaultdict,deque
from heapq import heappush, heappop
import sys
import math
import bisect
import random
def LI(): return [int(x) for x in sys.stdin.readline().split()]
def I(): return int(sys.stdin.readline())
def LS():return [list(x) for x in sys.stdin.readline().split()]
def S():
    res = list(sys.stdin.readline())
    if res[-1] == "\n":
        return res[:-1]
    return res
def IR(n):
    return [I() for i in range(n)]
def LIR(n):
    return [LI() for i in range(n)]
def SR(n):
    return [S() for i in range(n)]
def LSR(n):
    return [LS() for i in range(n)]

sys.setrecursionlimit(1000000)
mod = 1000000007

#A
def A():
    n,p = LI()
    a = LI()
    o = 0
    for i in a:
        o += i%2
    e = n-o
    ans = (1<<e)*((1<<o)>>((o!=0)|(p!=0)))
    print(ans)
    return
#B
def B():

    return

#C
def C():

    return

#D
def D():

    return

#E
def E():

    return

#F
def F():

    return

#Solve
if __name__ == "__main__":
    A()


Measured memory_bytes: 40172
#include <stdio.h>
int main(void)
{
  int n, i, x=0, y=0;
  char s[102];
  
  scanf("%d", &n);
  scanf("%s", s);
  for(i = 0; i < n; i++){
    if(s[i] == '(') x++;
    else if(x > 0) x--;
    else y++;
  }

  for(i = 0; i < y; i++)
    printf("(");
  printf("%s", s);

  for(i = 0; i < x; i++)
    printf(")");

  return 0;
}

Measured memory_bytes: 128
if __name__ == "__main__":
    N = int(input())
    num_dict = {'AC': 0, 'WA': 0, 'TLE': 0, 'RE': 0}
    for i in range(N):
        num_dict[input()] += 1
    for k, v in num_dict.items():
        print(f'{k} x {v}')
    



Measured memory_bytes: 8944
n,k = map(int,input().split())

di = 10**9+7
lis = [0 for i in range(n+1)]
lisr = [0 for i in range(n+1)]

lis[0]=1
for i in range(1,n+1):
    lis[i] = (lis[i-1]*i)%di

def pow_k(x, n):
    """
    O(log n)
    """
    if n == 0:
        return 1

    K = 1
    while n > 1:
        if n % 2 != 0:
            K = (K*x)%di
        x = (x*x)%di
        n //= 2

    return (K * x)%di


lisr[0]=1
for i in range(1,n+1):
    lisr[i] = pow_k(i,di-2)


for i in range(1,n+1):
    lisr[i] = (lisr[i-1]*lisr[i])%di

def comb(i,j):
    tmp = (lis[i]*lisr[i-j])%di
    return (tmp*lisr[j])%di


for i in range(k):
    blu = i+1
    red = blu-1
    if (k-blu)<0 or (n-k-red) < 0:
        print(0)
        continue

    cnt = comb((n-k-red)+blu,blu)
    cnt = (cnt*comb((k-blu)+red,red))%di
    print(cnt)


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

namespace Competitive
{
    internal class Solution
    {
        public void Run()
        {
            int N = Input.ReadInt();
            int[] A = Input.ReadIntArray();
            Array.Sort(A);
            Array.Reverse(A);

            int a = 0;
            int b = 0;
            for (int i = 0; i < N; i++)
            {
                if (i % 2 == 0) a += A[i];
                else b += A[i];
            }

            Console.WriteLine(a - b);

        }

    }

    internal static class Input
    {
        public static int ReadInt()
        {
            string line = Console.ReadLine();
            return int.Parse(line);
        }

        public static int[] ReadIntArray()
        {
            string line = Console.ReadLine();
            return line.Split(' ').Select(int.Parse).ToArray();            
        }
    }

    internal class Program
    {
        public static void Main(string[] args)
        {
            var s = new Solution();
            s.Run();
        }
    }
}

Measured memory_bytes: 13396
#define _USE_MATH_DEFINES
#include<iostream>
#include<fstream>
#include<string>
#include<vector>
#include<utility>
#include<algorithm>
#include<climits>
#include<set>
#include<map>
#include<cmath>
#include<iomanip>
#include<iterator>
#include<queue>
#include<stack>
#include<cctype>
#include<deque>
#include<time.h>
#include<bitset>
#include<random>
#include<unordered_set>
#include<unordered_map>
#include<sstream>
#include<random>

//by Skeef79

typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;

#pragma warning(disable : 4996)
#pragma comment(linker, "/STACK:16777216")
#define pb push_back
#define en '\n'
#define for0(i,n) for(int i = 0;i<n;i++)
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
#define vec vector
#define pii pair<int,int>
#define pll pair<ll,ll>

using namespace std;

const int INF = 2000000000;
const ll LINF = 2000000000000000000;

template<typename T> void print(vector<T>& a)
{
	for (int i = 0; i < a.size(); i++)
		cout << a[i] << ' ';
	cout << en;
}

template<typename T> void print(deque<T>& a)
{
	for (int i = 0; i < a.size(); i++)
		cout << a[i] << ' ';
	cout << en;
}

template<typename T> void print(vector<vector<T>>& a)
{
	for (int i = 0; i < a.size(); i++)
	{
		for (int j = 0; j < a[i].size(); j++)
			cout << a[i][j] << ' ';
		cout << en;
	}
}

template <typename T> void input(vector<T>& a)
{
	for (int i = 0; i < a.size(); i++)
		cin >> a[i];
}

template<typename T> void input(deque<T>& a)
{
	for (int i = 0; i < a.size(); i++)
		cin >> a[i];
}

template<typename T> void input(vector<vector<T>>& a)
{
	for (int i = 0; i < a.size(); i++)
		for (int j = 0; j < a[i].size(); j++)
			cin >> a[i][j];
}


void solve()
{
	int n;
	cin >> n;
	vector<string> a(n);
	vector<ll>b(n);
	for (int i = 0; i < n; i++)
		cin >> a[i] >> b[i];

	string t;
	cin >> t;
	int i = 0;
	for (; i < n; i++)
		if (a[i] == t)
			break;
	i++;
	ll sum = 0;
	for (; i < n; i++)
		sum += b[i];
	cout << sum;

}

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

#ifdef _DEBUG
	freopen("input.txt", "r", stdin);
#endif

	int tst = 1;
	//cin >> tst;
	while (tst--)
		solve();
}

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

int main() {
	int H, W;
	while (true) {
		cin >> H >> W;
		if (H == 0 && W == 0) { 
			break; 
		}
		for (int i = 0; i < H; i++) {
			for (int j = 0; j < W; j++) {

				if (i == 0 || i == H-1) {
					cout << "#";
				}
				else if (j == 0 || j == W-1) {
					cout << "#";
				}
				else {
					cout << ".";
				}
			}
			cout << endl;
		}
		cout << endl;
	}
}

Measured memory_bytes: 3000
function myin(){return require("fs").readFileSync("/dev/stdin", "utf8").trim();}
function myout(t){console.log(t);}//standard output
function myerr(t){console.error(t);}//standard error
//[no]param
//0:何もしない  1:数値へ変換  2:半角SPで分割  3:改行で分割  4:半角SPで分割し、数値配列へ
//5:改行で分割し、数値配列へ  6:1文字に分割  7:1文字に分割し、数値配列へ
function myconv(i,no){switch(no){case 0:return i;case 1:return parseInt(i);case 2:return i.split(" ");case 3:return i.split("\n");case 4:return i.split(" ").map((a)=>Number(a));case 5:return i.split("\n").map((a)=>Number(a));case 6:return i.split("");case 7:return i.split("").map((a)=>Number(a));}}
function Main(input) {
  input = myconv(input,4);
  var N = input[0];
  var P = input[1];
  if(isPrime(P)){
     myout(1);
    return;
  }
  var pf = getPrimeFactorization(P);
  var pfKeys = Array.from(Object.keys(pf));
  var output = 1;
  for(var i = 0; i < pfKeys.length; i++){
    if(pf[pfKeys[i]] >= N){
       output *= Math.pow(pfKeys[i],Math.floor(pf[pfKeys[i]] / N));
    }
  }
  myerr(pf);
  myout(output);
}
function getPrimeFactorization(val){
  var primeList = {};
  var div = 2;
  while(val != 1){
    if(val % div == 0){
      (primeList[div] == null)  ? primeList[div] = 1 : primeList[div]++;
      val /= div;
      if(isPrime(val)){
        (primeList[val] == null)  ? primeList[val] = 1 : primeList[val]++;
        break;
      }
    }else{
      div = (div == 2) ? div + 1 : div + 2;
    }
  }
  return primeList;
}
function isPrime(val){
        if(val <= 1 || (val != 2 && val % 2 == 0)){
                return false;
        }else if(val == 2){
                return true;
        }
        var root = Math.floor(Math.sqrt(val));
        for(var i = 3; i <= root; i += 2){
                if(val % i == 0){
                        return false;
                }
        }
        return true;
}
Main(myin());

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

int main(int argc,char* argv[]){
  int N,count=1;
  string S;
  cin >> N;
  cin >> S;
  for(int i=1;i<N;i++){
    if(S[i-1]!=S[i]) count++; 
  }
  cout << count << endl;
  return 0;
}


Measured memory_bytes: 512
using System;
using System.Linq;

namespace ALDS1_9_B_MaximumHeap
{
	class Program
	{
		static void Main ( string[] args )
		{
			int dataCount = int.Parse (Console.ReadLine ());
			int[] inputNum = new int[dataCount];
			inputNum = Console.ReadLine ().Split (' ').Select (int.Parse).ToArray ();

			int[] result = Heap.BuildMaxHeap (inputNum);

			string output = string.Join (" ", Array.ConvertAll (result, (num => num.ToString ())));

			Console.WriteLine (" " + output);
		}
	}

	class Heap
	{
		public static int[] BuildMaxHeap ( int[] numArray )
		{
			int[] heapArray = new int[numArray.Length + 1];
			numArray.CopyTo (heapArray, 1);

			for (int lp = heapArray.Length / 2; lp >= 1; lp--)
			{
				MaxHeapify (heapArray, lp);
			}

			return heapArray.Skip (1).ToArray ();
		}

		private static void MaxHeapify ( int[] numArray, int index )
		{
			int myselfIndex = index;
			int leftIndex = LeftKey (index);
			int rightIndex = RightKey (index);

			//??¨?????¨????????§?????§?????????????????¶
			bool isRangeLeft = 1 <= leftIndex && leftIndex < numArray.Length;
			bool isRangeRight = 1 <= rightIndex && rightIndex < numArray.Length;

			int maxIndex = 0;

			if (isRangeLeft && numArray[myselfIndex] < numArray[leftIndex])
			{
				maxIndex = leftIndex;
			}
			else
			{
				maxIndex = myselfIndex;
			}
			if (isRangeRight && numArray[maxIndex] < numArray[rightIndex])
			{
				maxIndex = rightIndex;
			}

			//??????????????§????????´???
			if (maxIndex != index)
			{
				var tmp = numArray[maxIndex];
				numArray[maxIndex] = numArray[index];
				numArray[index] = tmp;

				MaxHeapify (numArray, maxIndex);
			}
		}

		private static int LeftKey ( int index )
		{
			return index * 2;
		}
		private static int RightKey ( int index )
		{
			return index * 2 + 1;
		}
	}
}

Measured memory_bytes: 80524
#include <iostream>
#include <vector>

int main(void) {
  const int N = 100000;
  int n;
  int a = 0;
  std::cin >> n;
  for (int i = 0; i < n; i++) {
    int x;
    std::cin >> x;
    a += x - 1;
  }
  std::cout << a << std::endl;
  return 0;
}


Measured memory_bytes: 256
#include <iostream>

using namespace std;

int main() {
    int N, L;
    cin >> N >> L;
    int a[N];
    for (int i = 0; i < N; ++i) {
        cin >> a[i];
    }
    bool can = false;
    int t = 0;
    for (int j = 0; j < N - 1; ++j) {
        if (a[j] + a[j + 1] >= L) {
            can = true;
            t = j + 1;
            break;
        }
    }
    if (can) {
        cout << "Possible" << endl;
        for (int i = 1; i < t; ++i) {
            cout << i << endl;
        }
        for (int j = N - 1; j > t; --j) {
            cout << j << endl;
        }
        cout << t << endl;
    } else {
        cout << "Impossible" << endl;
    }
    return 0;
}


Measured memory_bytes: 1152
#include <vector>
#include <list>
#include <map>
#include <set>
#include <stack>
#include <queue>
#include <deque>
#include <algorithm>
#include <utility>
#include <functional>
#include <sstream>
#include <iostream>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>
#include <climits>
#include <cassert>
using namespace std;
inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<string> vs;
typedef pair<int, int> pii;
typedef long long ll;
#define ALL(a) (a).begin(),(a).end()
#define RALL(a) (a).rbegin(),(a).rend()
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) FOR(i,0,n)
const double EPS = 1e-9;
const double PI  = acos(-1.0);


typedef vector<vvi> vvvi;

void print(vvvi &f){
		REP(i,5){
			REP(j,5){
				REP(k,5){
					cout<<f[i][j][k];
				}
				cout<<endl;
			}
			if(i<4)
			cout<<endl;
		}
}

int main(){
	int n;
	int caseCnt=0;
	while(cin>>n,n){
		caseCnt++;
		vvvi f(5,vvi(5,vi(5)));
		REP(i,5){
			REP(j,5){
				string s;
				cin>>s;
				REP(k,5){
					f[i][j][k]=s[k]-'0';
				}
			}
		}
		int m1,m2;
		cin>>m1;
		vi a(m1);
		REP(i,m1){
			cin>>a[i];
		}
		cin>>m2;
		vi b(m2);
		REP(i,m2){
			cin>>b[i];
		}

		REP(day,n){
			vvvi newF(f);

			REP(i,5){
				REP(j,5){
					REP(k,5){
						int aliveCount=0;
						FOR(dy,-1,1+1){
							FOR(dx,-1,1+1){
								FOR(dz,-1,1+1){
									if(dy==0&&dx==0&&dz==0)continue;
									int z=i+dz,y=j+dy,x=k+dx;
									if(y>=0&&x>=0&&z>=0&&y<5&&x<5&&z<5){
										aliveCount+=f[z][y][x];
									}
								}
							}
						}

						int deadOrAlive;
						if(f[i][j][k]==0){
							deadOrAlive=0;
							REP(l1,m1){
								if(aliveCount==a[l1]){
									deadOrAlive=1;
								}
							}
						}else{
							deadOrAlive=0;
							if(deadOrAlive!=1){
								REP(l2,m2){
									if(aliveCount==b[l2]){
										deadOrAlive=1;
									}
								}
							}
						}
						switch(deadOrAlive){
						case 1:
							newF[i][j][k]=1;
							break;
						case 0:
							newF[i][j][k]=0;
							break;
						default:
							assert(0);
							break;
						}
					}
				}
			}

			f=newF;
			//cout<<"day "<<day<<endl;
			//print(f);
		}

		if(caseCnt>1)cout<<endl;
		cout<<"Case "<<caseCnt<<":"<<endl;
		print(f);
	}
}

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

using namespace std;

int main()
{
  int H,W;
  string s[50];
  cin>> H>> W;
  for(int i=0;i<H;i++)cin>> s[i];
  
  int ret=H*W;
  int far[50][50];
  for(int i=0;i<H;i++)for(int j=0;j<W;j++)far[i][j]=-1;
  int mx[4]={0,0,-1,+1};
  int my[4]={-1,1,0,0};
  queue<pair<int,int>> que;
  que.push(pair<int,int>(0,0));
  far[0][0]=0;
  while(que.size())
  {
    pair<int,int> p=que.front();que.pop();
    for(int i=0;i<4;i++)
    {
      int x=p.first+mx[i];
      int y=p.second+my[i];
      if(x>=0&&x<H&&y>=0&&y<W&&s[x][y]!='#'&&far[x][y]==-1)
      {
        far[x][y]=far[p.first][p.second]+1;
        que.push(pair<int,int>(x,y));
      }
    }
  }
  int black=0;
  for(int i=0;i<H;i++)for(int j=0;j<W;j++)if(s[i][j]=='#')black++;
  ret-=black+far[H-1][W-1]+1;
  if(far[H-1][W-1]==-1)ret=-1;
  cout<< ret<< endl;
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <numeric>
#include <cmath>
#include <algorithm>
#include <vector>
#include <map>
#include <cstring>
#include <iomanip>

using namespace std;

#define sp ' '
#define st first
#define nd second
#define pb push_back
#define mp make_pair
#define forn(YY, yy) for(long long int yy = 0; yy < YY; ++yy)
#define prn(XX) cout << XX << endl
#define prs(XX) cout << XX << " "

typedef long long int ll;
typedef unsigned long long int ull;
typedef vector<ll> vll;
typedef vector<vector<ll>> vvll;
typedef pair<ll, ll> pll;
typedef vector<pll> vpll;

const int MOD = 1e9 + 7;
const int INF = 2e9 + 13;
const int mINF = -2e9 - 13;
const double PI = 3.14159265358979;
const double EPS = 1e-9;

double dp[301][301][301];
bool done[301][301][301];
int a[300], one = 0, two = 0, three = 0, N;

int t = 1;

double dn(int bir, int iki, int uc){
    //cout << bir << sp << iki << sp << uc << endl;

    if(done[bir][iki][uc]){ return dp[bir][iki][uc];}
    if(bir + iki + uc == 0) return 0.0;

    double total = 0;
    double poss = (((double)N)/(double)(bir+iki+uc));

    total += (bir ? ((double)bir*dn(bir-1, iki, uc)) : 0.0);
    total += (iki ? ((double)iki*dn(bir+1, iki-1, uc)) : 0.0);
    total += (uc ? ((double)uc*dn(bir, iki+1, uc-1)) : 0.0);
    total /= (double)(bir+iki+uc);
    total += poss;

    done[bir][iki][uc] = true;
    return dp[bir][iki][uc] = total;
}

int main(int argc, char **argv){
    //ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
    
    cin >> N;
    for(int i = 0; i < N; ++i){
        cin >> a[i];
        if(a[i] == 1) one++;
        else if(a[i] == 2) two++;
        else three++;
    }
    //cout << one << sp << two << sp << three << endl;
    cout << setprecision(14) << dn(one, two, three) << endl;

    return 0;
}

//cikisir



Measured memory_bytes: 239872
H,N = map(int,input().split())
magic = []
for i in range(N):
    a,b = map(int,input().split())
    magic.append([a,b])

INF = 10**9
DP = [INF]*(20005); DP[0] = 0

for i in range(1,20005):
    h = INF
    for j in range(N):
        if i - magic[j][0] >= 0:
            k = magic[j][1] + DP[i - magic[j][0]]
        else:
            k = magic[j][1]
        h = min(h,k)
    DP[i] = h

ans = DP[H]
for i in DP[H+1:]:
    ans = min(ans,i)
print(ans)

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

int compare_ints(const void* a, const void* b)
{
    int arg1 = *(const int*)a;
    int arg2 = *(const int*)b;
 
    if (arg1 < arg2) return -1;
    if (arg1 > arg2) return 1;
    return 0;
}

double	ave(double a, double b)
{
  	return (a + b) / 2.0;
}

int	main(void)
{
  	int	N;
  	int	*v;
  	int	i;
  	double av;
  
  	scanf("%d\n", &N);
  
  	v = (int *)malloc(sizeof(int) * N);
  	for(i=0; i<N; i++)
    {
      	scanf("%d", &v[i]);
    }
  
  	qsort(v, N, sizeof(int), compare_ints);
  
  	av = v[0];
  	for(i=1; i<N; i++)
    {
      	av = ave(av, v[i]);
    }
  
  	printf("%f", av);
  	return (0);
}

Measured memory_bytes: 128
#include <iostream>
using namespace std;
int main(void){
  int N,K;
  cin >> N >> K;
  int nw = 1;
  for(int i = 0; N > i; i++){
    if(nw + K > nw * 2){
      nw *= 2;
    } else {
      nw += K;
    }
  }
  cout << nw << endl;
}

Measured memory_bytes: 256
#include <cmath>
#include <string>
#include <vector>
#include <iomanip>
#include <iostream>
#include <algorithm>
#include <functional>
using namespace std;
int N, d, c[15], bit; bool f[29], ff[29];
int main() {
	cin >> N;
	for (int i = 0; i < N; i++) cin >> d, c[d]++;
	f[0] = true;
	bool flag = false;
	for (int i = 0; i <= 12; i++) {
		if (i == 0 && c[i] >= 1) flag = true;
		else if (i == 12 && c[i] >= 2) flag = true;
		else if (c[i] >= 3) flag = true;
		if (i == 12 && c[i] == 1) f[12] = true;
		if (1 <= i && i <= 11 && c[i] == 2) f[i] = f[24 - i] = true;
	}
	for (int i = 1; i < 12; i++) {
		if (c[i] == 1) bit |= 1 << i;
	}
	if (flag) cout << 0 << endl;
	else {
		int ret = 0;
		for (int i = 0; i < 1 << 12; i++) {
			if ((i | bit) != bit) continue;
			for (int j = 0; j < 24; j++) ff[j] = f[j];
			for (int j = 1; j < 12; j++) {
				if (c[j] != 1) continue;
				if (i & (1 << j)) ff[j] = true;
				else ff[24 - j] = true;
			}
			int res = 1 << 30;
			for (int j = 0; j < 24; j++) {
				for (int k = j + 1; k < 24; k++) {
					if (ff[j] && ff[k]) res = min(res, min(k - j, 24 - k + j));
				}
			}
			ret = max(ret, res);
		}
		cout << ret << endl;
	}
	return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
int main()
{
    int S,h,m,s;
    
    scanf("%d",&S);
    
    h = S / 3600;
    m = (S % 3600) / 60;
    s = (S % 3600) % 60;
    
    printf("%d:%d:%d\n",h,m,s);
    
    return 0;
    
}


Measured memory_bytes: 2104
import java.util.Arrays;
import java.util.Scanner;
import java.util.TreeSet;

public class Main {
	Scanner sc = new Scanner(System.in);

	void solve2() {
		int n = sc.nextInt();
		int[] p = new int[n];
		for (int i = 0; i < n; i++) p[sc.nextInt() - 1] = i;
		TreeSet<Integer> set = new TreeSet<>();
		set.add(-1);
		set.add(n);
		long cnt = 0;
		for (int i = 0; i < n; i++) {
			set.add(p[i]);
			int next = set.higher(p[i]);
			int prev = set.lower(p[i]);
			cnt += (p[i] - prev) * (long) (next - p[i]) * (i + 1);
		}
		System.out.println(cnt);
	}

	void solve1() {
		int N = sc.nextInt();
		int[] a = new int[N];
		int[] b = new int[N];
		for (int i = 0; i < N; i++) {
			a[i] = sc.nextInt();
			b[a[i] - 1] = i;
		}
		long cnt = 0;

		UnionFind uf = new UnionFind();
		uf.init(N);

		for (int i = N - 1; i >= 0; i--) {
			int pos = b[i];
			long g1 = 1;
			long g2 = 1;
			if (pos + 1 < N && a[pos] < a[pos + 1]) {
				g1 += uf.getGroupSize(pos + 1);
				uf.union(pos, pos + 1);
			}
			if (pos - 1 >= 0 && a[pos] < a[pos - 1]) {
				g2 += uf.getGroupSize(pos - 1);
				uf.union(pos, pos - 1);
			}
			cnt += a[pos] * (g1 * g2);
		}

		System.out.println(cnt);
	}

	public class UnionFind {

		int[] par;
		int[] rank;
		int groupCnt;

		void init(int n) {
			groupCnt = n;
			par = new int[n];
			rank = new int[n];
			Arrays.fill(par, -1);
		}

		void union(int x, int y) {
			x = find(x);
			y = find(y);
			if (x == y) {
				return;
			}
			groupCnt--;
			if (rank[x] < rank[y]) {
				par[y] += par[x];
				par[x] = y;
			} else {
				par[x] += par[y];
				par[y] = x;
				if (rank[x] == rank[y]) {
					rank[x]++;
				}
			}
		}

		int find(int x) {
			if (par[x] < 0) {
				return x;
			} else {
				return par[x] = find(par[x]);
			}
		}

		int getGroupSize(int x) {
			return -par[find(x)];
		}
	}

	public static void main(String[] args) {
		new Main().solve2();
	}
}

Measured memory_bytes: 85312
def judge(N,Y):
    sum = 0
    for i in range(N+1):
        for j in range(N-i+1):
            sum = i*10000+ j*5000 + (N-i-j)*1000
            if sum == Y:
                return i, j, N-i-j
        if i == N:
            return -1, -1, -1

N, Y = map(int, input().split())
x, y, z = judge(N,Y)
print("{} {} {}".format(x,y,z))

Measured memory_bytes: 3064
#include <stdio.h>

int main(int argc, const char * argv[]) {
    int a, b, c;
    
    scanf("%d %d %d", &a, &b, &c);
    
    if (a < b && b < c) {
        printf("Yes\n");
    }else {
        printf("No\n");
    }
    
    return 0;
}



Measured memory_bytes: 2100
N = int(input())
W = list(map(int,input().split()))

S = [1000000000] * (N+1)

for i in range(1,N) :
    S1 = W[:i]
    S2 = W[i:]

    S[i] = abs(sum(S1) - sum(S2))

S.sort()

print(S[0])

Measured memory_bytes: 3060
#include<bits/stdc++.h> 
#include <iostream>
#include <algorithm>
#include <cstring>
#include <cstdio>
#include <vector>
#include <cmath>
#include <set>
#include <map>
#include <queue>
#include <iomanip>
#include <assert.h>
using namespace std;
typedef long long ll;
int main()
{
	ll n,m;
	cin>>n>>m;
	vector<ll> v;
	for(ll i=1;i*i<=m;i++) if(m%i==0) v.push_back(m/i),v.push_back(i);
	sort(v.begin(),v.end());
	ll ans=m;
	for(ll i=0;i<v.size();i++)
	{
//		printf("%lld ",v[i]);
		if(v[i]>=n)
		{
			ans=v[i];break;
		}
	}
	cout<<m/ans;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define rep1(i,n) for(int i=1;i<=(int)(n);i++)
#define all(c) c.begin(),c.end()
#define pb push_back
#define fs first
#define sc second
#define chmin(x,y) x=min(x,y)
#define chmax(x,y) x=max(x,y)
using namespace std;
template<class S,class T> ostream& operator<<(ostream& o,const pair<S,T> &p){
	return o<<"("<<p.fs<<","<<p.sc<<")";
}
template<class T> ostream& operator<<(ostream& o,const vector<T> &vc){
	o<<"{";
	for(const T& v:vc) o<<v<<",";
	o<<"}";
	return o;
}
using ll = long long;
template<class T> using V = vector<T>;
template<class T> using VV = vector<vector<T>>;
constexpr ll TEN(int n) { return (n == 0) ? 1 : 10 * TEN(n-1); }

#ifdef LOCAL
#define show(x) cerr << "LINE" << __LINE__ << " : " << #x << " = " << (x) << endl
#else
#define show(x) true
#endif

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);		//DON'T USE scanf/printf/puts !!
	cout << fixed << setprecision(20);
	
	int N;
	string s;
	cin >> N >> s;
	int W = 0;
	rep(i,N) if(s[i]=='.') W++;
	int ans = N;
	int w = 0;
	rep(i,N+1){
		int b = N-i - (W-w);
		chmin(ans,N-w-b);
		if(i<N && s[i]=='.') w++;
	}
	cout << ans << endl;
}


Measured memory_bytes: 720
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<string>
#include<algorithm>
#include<iostream>
#include<queue>
#include<map>
#include<cmath>
#include<set>
#include<stack>
#define ll long long
#define max(x,y) ((x)>(y)?(x):(y))
#define min(x,y) ((x)>(y)?(y):(x))
#define cls(name,x) memset(name,x,sizeof(name))
using namespace std;
const int inf=1<<28;
const int maxn=110;
const int maxm=110;
const int mod=1e9+7;
const double pi=acos(-1.0);
int n,a,b;
int main()
{
    //freopen("in.txt","r",stdin);
    while(~scanf("%d %d %d",&n,&a,&b))
    {
        if(a>b) {printf("0\n");continue;}
        if(a!=b&&n==1) {printf("0\n");continue;}
        printf("%lld\n",(ll)(n-2)*b-(ll)(n-2)*a+1);
    }
    return 0;
}


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

#define min(a,b) (a<b)?a:b

int main(void) {
    int i, j, K, N, h[100010], dp[100010];
    scanf("%d%d", &N, &K);
    for(i=1;i<=N;i++) {
        scanf("%d",&h[i]);
    }

    dp[1] = 0;
    dp[2] = abs(h[1]-h[2]);
    for(j=3;j<=K;j++) {
        dp[j] = dp[j-1] + abs(h[j-1] - h[j]);
        for (i=j-2;i>0;i--) {
            dp[j] = min( dp[i] + abs(h[i]-h[j]) , dp[j] );
        }
    }
    for(j=K+1;j<=N;j++) {
        dp[j] = dp[j-1] + abs(h[j-1] - h[j]);
        for (i=2;i<=K;i++) {
            dp[j] = min( dp[j-i] + abs(h[j-i]-h[j]) , dp[j] );
        }
    }
    printf("%d\n", dp[N]);
    return 0;
}

Measured memory_bytes: 896
#include<iostream>
#include<string>
#include<cstdio>
#include<cstring>
#include<vector>
#include<cmath>
#include<algorithm>
#include<functional>
#include<iomanip>
#include<queue>
#include<ciso646>
#include<random>
#include<map>
#include<set>
#include<complex>
#include<bitset>
#include<stack>
#include<unordered_map>
#include<utility>
#include<cassert>
using namespace std;

typedef long long ll;
typedef unsigned long long ul;
typedef unsigned int ui;
typedef long double ld;
const ll mod = 1000000007;
const ll INF = mod * mod;
#define rep(i,n) for(int i=0;i<n;i++)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define per1(i,n) for(int i=n;i>=1;i--)
#define Rep1(i,sta,n) for(int i=sta;i<=n;i++)
typedef complex<ld> Point;
const ld eps = 1e-8;
const ld pi = acos(-1.0);
typedef pair<int, int> P;
typedef pair<ld, ld> LDP;
typedef pair<ll, ll> LP;
typedef vector<int> vec;
typedef vector<string> svec;
#define fr first
#define sc second
#define all(c) c.begin(),c.end()
#define pb push_back
//#define int long long

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

void solve() {
    int N; cin >> N;
    ll ans = 1LL;
    rep(i, N) {
        ll T; cin >> T;
        ll g = gcd(ans, T);
        ans = ans / g * T;
    }
    cout << ans << endl;

}

signed main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	//cout << fixed << setprecision(10);
	//init();
	solve();
	//cout << "finish" << endl;
    return 0;
}

Measured memory_bytes: 256
#![allow(unused_imports)]
#![allow(non_snake_case)]
use std::cmp::*;
use std::collections::*;
use std::ops::Bound::*;
use itertools::Itertools;
use num_traits::clamp;
use ordered_float::OrderedFloat;
use proconio::{input, marker::*, fastout};
use superslice::*;

#[fastout]
fn main() {
    input! {
        n: usize, q: usize,
        tuv: [(usize, usize, usize); q]
    }

    let mut dsu = DSU::new(n);
    
    for (t, u, v) in tuv {
        match t {
            0 => {
                dsu.merge(u, v);
            }
            1 => {
                let res = (dsu.leader(u) == dsu.leader(v)) as u32;
                println!("{}", res);
            }
            _ => unreachable!()
        }
    }
}
#[allow(dead_code)]
pub struct DSU {
    parent_or_size: Vec<isize>,
}

#[allow(dead_code)]
impl DSU {
    pub fn new(n: usize) -> Self {
        assert!(n <= std::isize::MAX as usize);
        Self {
            parent_or_size: vec![-1; n],
        }
    }

    pub fn merge(&mut self, a: usize, b: usize) -> usize {
        let mut x = self.leader(a);
        let mut y = self.leader(b);
        if x == y {
            return x;
        }
        if -self.parent_or_size[x] < -self.parent_or_size[y] {
            std::mem::swap(&mut x, &mut y);
        }
        self.parent_or_size[x] += self.parent_or_size[y];
        self.parent_or_size[y] = x as isize;
        x
    }

    pub fn same(&mut self, a: usize, b: usize) -> bool {
        self.leader(a) == self.leader(b)
    }

    pub fn leader(&mut self, a: usize) -> usize {
        if self.parent_or_size[a] < 0 {
            a
        } else {
            self.parent_or_size[a] = self.leader(self.parent_or_size[a] as usize) as isize;
            self.parent_or_size[a] as usize
        }
    }

    pub fn size(&mut self, a: usize) -> usize {
        let leader = self.leader(a);
        -self.parent_or_size[leader] as usize
    }

    pub fn groups(&mut self) -> Vec<Vec<usize>> {
        let mut leader_buf = vec![0usize; self.parent_or_size.len()];
        let mut group_size = vec![0usize; self.parent_or_size.len()];
        for i in 0..self.parent_or_size.len() {
            leader_buf[i] = self.leader(i);
            group_size[leader_buf[i]] += 1;
        }
        let mut result = vec![Vec::new(); self.parent_or_size.len()];
        for i in 0..self.parent_or_size.len() {
            result[i].reserve(group_size[i]);
        }
        for i in 0..self.parent_or_size.len() {
            result[leader_buf[i]].push(i);
        }
        result.retain(|v| !v.is_empty());
        result
    }
}

Measured memory_bytes: 10088
<?php
define('MOD', pow(10, 9) + 7);

fscanf(STDIN, "%d %d", $N, $K);

$ans = 0;
for ($i = $K; $i <= $N + 1; $i++) {
    $ret = calc($N, $i);
    $ans += $ret;
    $ans %= MOD;
}
printf("%d", $ans);

function calc($N, $K) {
    // echo "{$N} {$K} ";
    $mmin = (0 + $K - 1) * $K / 2;
    $mmax = (($N) + ($N - $K + 1)) * $K / 2;
    $ret = $mmax - $mmin + 1;
    // echo $mmin . " " . $mmax . " " . $ret . PHP_EOL;
    return $ret;
}


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

public class Main {

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

	    int n=gi();
        int a=gi();

        //System.out.println(c);
        if ((n%500) <= a) {
        	System.out.print("Yes");
        }else {
        	System.out.print("No");
        }


	}

	// 文字列として入力を取得
	public static String gs() {
		return scanner.next();
	}

	// intとして入力を取得
	public static int gi() {
		return Integer.parseInt(scanner.next());
	}

	// longとして入力を取得
	public static long gl() {
		return Long.parseLong(scanner.next());
	}
	
	// doubleとして入力を取得
	public static double gd() {
		return Double.parseDouble(scanner.next());
	}
}

Measured memory_bytes: 35664
#include<stdio.h>
#include<math.h>

int main()
{
    int n,i;
    int arr1[60];
    int arr2[60];
    scanf("%d",&n);

    for(i=0;i<n;i++)
        scanf("%d",&arr1[i]);
     for(i=0;i<n;i++)
        scanf("%d",&arr2[i]);

    int output=0;

    for(i=0;i<n;i++)
    {
        if(arr1[i]>arr2[i])
            output=output+(arr1[i]-arr2[i]);

    }
    printf("%d",output);
}


Measured memory_bytes: 1736
#include <cstdio>
#include <cstdint>
#include <vector>
#include <algorithm>
#include <string>
#include <numeric>
#include <set>
#include <map>
#include <utility>

int main() {
  size_t N;
  scanf("%zu", &N);

  std::vector<int> B(N-1);
  for (auto& bi: B) scanf("%d", &bi);

  int inf = 1e9;
  B.push_back(inf);
  B.insert(B.begin(), inf);

  std::vector<int> A(N);
  for (size_t i = 0; i < N; ++i)
    A[i] = std::min(B[i], B[i+1]);

  printf("%d\n", std::accumulate(A.begin(), A.end(), 0));
}


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

using namespace std;

typedef long long ll;
 

int main()
{
	std::ios::sync_with_stdio(false);
	cin.tie(0);
	
	int T;
	cin >> T;
	int rest = T%1000;
	cout << (1000-rest)%1000 << "\n";


	return 0;
}



Measured memory_bytes: 3652
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
#define all(c) begin(c), end(c)
#define dump(x) cerr << __LINE__ << ":\t" #x " = " << (x) << endl

template <typename T>
bool chmax(T &x, T y) {
    if (x < y) {
        x = y;
        return true;
    } else {
        return false;
    }
}

template <typename T>
bool chmin(T &x, T y) {
    if (x > y) {
        x = y;
        return true;
    } else {
        return false;
    }
}

int dp[100010][3];

int n;
int a[100010][3];

int main() {
    int n;
    while (cin >> n) {
        rep(i, n) rep(j, 3) cin >> a[i][j];
        memset(dp, 0, sizeof dp);
        rep(i, n) {
            rep(j, 3) {
                rep(k, 3) {
                    if (j != k) {
                        chmax(dp[i+1][j], dp[i][k] + a[i][j]);
                    }
                }
            }
        }
        // rep(i, n) {
        //     rep(j, 3) {
        //         cout << dp[i][j] << ' ';
        //     }
        //     cout << endl;
        // }
        cout << max({dp[n][0], dp[n][1], dp[n][2]}) << endl;
    }
}


Measured memory_bytes: 2560
using System;
using System.Collections.Generic;
//using atcorder.DataStructure;
namespace atcorder
{
    class MainClass
    {
        public static void Main(string[] args)
        {
            atcorder.Test.Run();
        }
    }


    public class Test
    {
        public static void Run()
        {
            Input input=new Input(' ');
            input.ReadLine();
            int N = input.Next<int>();
            int M = input.Next<int>();
            List<Pair<long, long>> pairs = new List<Pair<long, long>>();
            for (int i = 0; i < N;i++){
                Pair<long, long> pair = new Pair<long, long>();
                input.ReadLine();
                pair.first = input.Next<long>();
                pair.second = input.Next<long>();
                pairs.Add(new Pair<long, long>(pair));
            }
            pairs.Sort((a, b) => (int)(a.first - b.first));
            long num = 0;
            long cash = 0;
            for (int i = 0; i < N;i++){
                if(num+pairs[i].second>=M){
                    cash += (M - num) * pairs[i].first;
                    num = M;
                    break;
                }else{
                    num += pairs[i].second;
                    cash += pairs[i].second * pairs[i].first;
                }
            }
            Console.WriteLine(cash);
        }
    }


    public class Pair<S, T>
    {
        public Pair() { }
        public Pair(S f, T s)
        {
            first = f;
            second = s;
        }
        public Pair(Pair<S, T> p)
        {
            first = p.first;
            second = p.second;
        }
        public S first;
        public T second;
    }




    public class Input
    {
        int arg;
        int length;
        string s;
        string[] ss;
        char sep;
        public Input(char _sep = '\0')
        {
            sep = _sep;
        }
        public void ReadLine()
        {
            s = Console.ReadLine();
            if (sep != '\0') ss = s.Split(sep);
            else
            {
                ss = new string[1];
                ss[0] = s;
            }
            arg = 0;
            length = ss.Length;
        }
        public T Next<T>()
        {
            if (arg == length) throw new IndexOutOfRangeException();
            return (T)Convert.ChangeType(ss[arg++], typeof(T));
        }
        public void SetSeparater(char _sep)
        {
            sep = _sep;
        }
    }
}


Measured memory_bytes: 23996
#include <bits/stdc++.h>
#include <cassert>
typedef long long int ll;
using namespace std;

// @@ !! LIM()

int main(int argc, char *argv[]) {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
  cout << setprecision(20);

  ll N; cin >> N;
  vector<vector<ll>> vec(2, vector<ll>(N));
  for (ll i = 0; i < N; i++) cin >> vec.at(0).at(i);
  for (ll i = 0; i < N; i++) cin >> vec.at(1).at(i);
  ll ans = 0;
  for (ll i = 0; i < N; i++) {
    ll s = 0;
    ll r = 0;
    for (ll j = 0; j < N; j++) {
      s += vec.at(r).at(j);
      if (j == i) {
	r = 1;
	s += vec.at(r).at(j);
      }
      ans = max(ans, s);
    }
  }
  cout << ans << endl;

  return 0;
}



Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <queue>
#include <cstring>
#include <vector>
#include <map>
#include <algorithm>
#include <cctype>
#include <cmath>
using namespace std;

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

const int INF = 1e9;
const int MAX_V = 1e6+1;

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

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

int N;

int main() {
  cin >> N;
  int res = N;
  for(int i=0; i<=N; i++) {
    int cc = 0;
    int t = i;
    while(t > 0) cc += t % 6, t /= 6;
    t = N - i;
    while(t > 0) cc += t % 9, t /= 9;
    if(res > cc) res = cc;
  }

  cout << res << endl;
}


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

int main(void)
{
    long long int X;
    cin >> X;
    long long int money = 100;
    int count = 0;

    while(money < X){
        money = money*1.01;
        count++;
    }

    cout << count << endl;  

    return 0;

}

Measured memory_bytes: 3648
#include <stdio.h>

int main(void)
{
    int i,j;
    int hit,blow;
    char enter;
    int a[4],b[4];

    while (scanf("%d", &a[0]) != EOF){
    for (i = 1; i < 4; i++){
        scanf("%d", &a[i]);
    }
    for (j = 0; j < 4; j++){
        scanf("%d", &b[j]);
    }

    /*ヒット判定*/
    hit = 0;
    for (i = 0; i < 4; i++){
        if (a[i] == b[i]){
            hit++;
        }
    }
    /*ブロー判定*/
    blow = 0;
    for (i = 0; i < 4; i++){
        for (j = 0; j < 4; j++){
           if(a[i] == b[j] && i != j){
               blow++;
           }
        }
    }
    printf("%d %d\n", hit, blow);
    }
    return (0);
}


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

int N,M;
int WA[105000];
bool AC[105000];

void solve()
{
    cin >> N >> M;
    int WAnum = 0,ACnum = 0;
    for(int i= 1;i <= N; i++)
    {
        WA[i] = 0;
        AC[i] = false;
    }

    while(M--)
    {
        int p;
        string S;
        cin >> p >> S;
        if(AC[p]) continue;
        if(S == "AC") {
            AC[p] = true;
            ACnum++;
            WAnum += WA[p];
        } else if(S == "WA") {
            WA[p]++;
        }
    }
    cout << ACnum << " " << WAnum << endl;
}

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

Measured memory_bytes: 768
using System;
using System.Collections.Generic;
using System.Linq;
using System.IO;
using System.Text;
//var input = Console.ReadLine().Split().Select(int.Parse).ToArray();
namespace AtCoderSolve
{
    class Solve
    {
        const int mod = 1000000007;
        static void Main(string[] args)
        {
            var sw = new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false };
            Console.SetOut(sw);

            var p = Console.ReadLine().Split().Select(int.Parse).ToArray();
            Console.WriteLine(p[0] - p[1] + 1);

            Console.Out.Flush();
        }
    }



    public class Calculation
    {

    }

    public class Graph
    {

    }
}

Measured memory_bytes: 13396
// -*- coding:utf-8-unix -*-

use proconio::input;

fn gcd(a: u64, b: u64) -> u64 {
    if b == 0 {
        a
    } else {
        gcd(b, a % b)
    }
}

fn lcm(a: u64, b: u64) -> u64 {
    // a * b / gcd(a, b)
    let d = gcd(a, b);
    a / d * b
}

fn main() {
    input! {
        n: u8,
        t: [u64; n],
    }

    let mut ans = t[0];
    for i in 1..n {
        ans = lcm(ans, t[i as usize]);
    }
    println!("{}", ans);
}


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

typedef uint64_t u64;
typedef int64_t i64;
typedef uint32_t u32;
typedef int32_t i32;

using namespace std;

template <typename T>
static inline void ArrayInput(vector<T>& A) {
  for (auto itr = A.begin(); itr < A.end(); ++itr) cin >> *itr;
}

template <typename T>
static inline void ArrayPut(const vector<T>& A) {
  for (auto itr = A.begin(); itr < A.end(); ++itr) cout << *itr << " ";
  cout << endl;
}

bool Sec_compare(pair<uint64_t, uint64_t> a, pair<uint64_t, uint64_t> b) {
  if (a.second != b.second) {
    return a.second < b.second;
  } else {
    return a.first < b.first;
  }
}

u64 dec_dig(u64 num) {
  u64 res = 0;
  while (num > 0) {
    num /= 10;
    ++res;
  }
  return res;
}

u64 gcd(u64 a, u64 b) {
  if (a < b) {
    a ^= b;
    b ^= a;
    a ^= b;
  }

  return b ? gcd(b, a % b) : a;
}

u64 lcm(u64 a, u64 b) { return (a / gcd(a, b)) * b; }

int main() {
  cout << setprecision(15);
  u64 N, R;
  cin >> N >> R;
  if (N >= 10) {
    cout << R << endl;
  } else {
    cout << R + (100 * (10 - N)) << endl;
  }

  return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cmath>
#include<cctype>
#include<math.h>
#include<string>
#include<string.h>
#include<stack>
#include<queue>
#include<vector>
#include<utility>
#include<set>
#include<map>
#include<stdlib.h>
#include<iomanip>

using namespace std;

#define ll long long
#define ld long double
#define EPS 0.0000000001
#define INF 1e9
#define LINF (ll)INF*INF
#define MOD 1000000007
#define rep(i,n) for(int i=0;i<(n);i++)
#define loop(i,a,n) for(int i=a;i<(n);i++)
#define all(in) in.begin(),in.end()
#define shosu(x) fixed<<setprecision(x)

#define int ll //!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

typedef vector<int> vi;
typedef vector<string> vs;
typedef pair<int,int> pii;
typedef vector<pii> vp;

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


signed main(void) {
    int n,m;
    cin >> n >> m;
    vi a(n),b(m);
    rep(i,n) cin >> a[i];
    rep(i,m) cin >> b[i];
    sort(all(a));
    sort(all(b));
    map<int,int> ma;
    ma[a[0]]++;
    ma[b[0]]++;
    rep(i,n-1)if(a[i+1] != a[i])ma[a[i+1]]++;
    rep(i,m-1)if(b[i+1] != b[i])ma[b[i+1]]++;
    vi v1,v2;
    for(auto itr = ma.begin(); itr != ma.end(); itr++){
        int cnt = itr->second;
        //cout << (itr->first) << " " << cnt << endl;
        if(cnt > 1)v1.push_back(itr->first);
        v2.push_back(itr->first);
    }
    cout << v1.size() << " " << v2.size() << endl;
    sort(all(v1));
    sort(all(v2));
    rep(i,v1.size())cout << v1[i] << endl;
    rep(i,v2.size())cout << v2[i] << endl;
}



Measured memory_bytes: 20584
N, K = map(int, input().split())
P = int(1e9+7)

A = [i + 1 for i in range(N+1)]
sumA=[i + 1 for i in range(N+1)]
for i in range(1, N+1):
    sumA[i] += sumA[i-1]
ans = 0
for i in range(K, N+1):
    ans = (ans + (sumA[-1] - sumA[-(i + 1)]) - sumA[i - 1] + 1) % P
ans = (ans + 1) % P
print(ans)


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

int main(){
  int ball[3]={1,0,0},b;
  string cup;
  while(cin>>cup){
    b = ball[(cup[0]-'A')];
    ball[cup[0]-'A'] = ball[(cup[2]-'A')];
    ball[(cup[2]-'A')] = b;
  }
  for(int i=0;i<3;i++)if(ball[i])cout<<(char)('A'+i)<<endl;
  return 0;
}

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

int main() {
    int n;cin>>n;
    int a;
    int any=0;
    set<int> st;
    for (int i=0;i<n;i++) {
        cin>>a;
        if (a>=3200)
            any++;
        else
            st.insert(a/400);
    }
    cout<<(st.size()?st.size():1)<<' '<<st.size()+any<<endl;
    return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
#include<string.h>
#include<iostream>
#include<algorithm>
using namespace std;
typedef long long ll;
ll dp[55][2];
int main()
{
	int n,p;
	dp[0][0]=1;
	cin>>n>>p;
	for(int i=1;i<=n;i++){
		int x;
		cin>>x;
		x=x%2;
		dp[i][x]=dp[i-1][x];
		dp[i][x^1]=dp[i-1][x^1];
		dp[i][1]+=dp[i-1][x^1];
		dp[i][0]+=dp[i-1][x];
	//	printf("%lld %lld\n",dp[i][0],dp[i][1]);
	}
	printf("%lld\n",dp[n][p]);
	return 0;
}

Measured memory_bytes: 256
N = int(input())
A = list(map(int, input().split()))
A.sort()
ans = 0
hoge = 10000000000000000000
# マイナスの個数が偶数かつ、Nが偶数なら全部の絶対値で良い気がする
# マイナスの個数が偶数なら全部の和でいい
n = sum(x < 0 for x in A)
if n % 2 == 0:
    for i in range(N):
        ans += abs(A[i])
    print(ans)
    exit()
else:
    for i in range(N):
        ans += abs(A[i])
        if hoge > abs(A[i]):
            hoge = abs(A[i])
    print(ans - hoge*2)
    exit()
# マイナスの個数が奇数なら被害を抑えるために、絶対値の一番小さいやつを-にする


Measured memory_bytes: 14332