akhauriyash/Code-Regression huggingface dataset:
#include<stdio.h>



void getData(int *n,int *r){
	fscanf(stdin,"%d%d",n,r);
}

int getDigit(int n, int k){
	int loop = 0;
	int buf = n;
	while(1){
		if(buf < k){
			loop++;
			return loop;
		}
		buf /= k;
		loop++;
	}

}

void solv(){
	int n,k;
	int digit;
	getData(&n,&k);
	digit = getDigit(n,k);
	printf("%d\n",digit);
}	


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


Measured memory_bytes: 128
#include <iostream>
#include <string>
#include <map>

int main () {
    std::string str, alpha = "abcdefghijklmnopqrstuvwxyz", ans = "None";
    std::cin >> str;
    std::map<char, int> m;
    for(int i = 0; i < 26; ++i){
        m.insert(std::make_pair(alpha[i], 0));
    }
    for(int i = 0; i < str.length(); ++i){
        ++m[str[i]];
    }
    for(int i = 0; i < 26; ++i){
        if(m[alpha[i]]==0) {
            ans = alpha[i];
            break;
        }
    }
    std::cout << ans << std::endl;
}


Measured memory_bytes: 3744
#include<iostream>
#include<algorithm>
#include<complex>
#include<vector>
#include<cmath>
#include<set>
#define LL long long
int Q;
int main() {
	std::cin >> Q;
	for (int i = 0; i < Q; i++) {
		LL A, B;
		std::cin >> A >> B;
		if (std::abs( A - B) <= 1) {
			std::cout << std::min(A,B)*2 - 2<<std::endl;
			continue;
		}
		LL AB = A * B;
		LL C = std::sqrt(static_cast<long double>(AB - 1));
		if (C*(C + 1) >= AB) {
			std::cout << 2 * C - 2 << std::endl;
		}
		else {
			std::cout << 2 * C - 1 << std::endl;
		}
	}
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>

using namespace std;

int Tanni(string);
int Keta(string);
int calc(string, int);

main(){
  string num;
  string ht;
  string t;
  int n;
  while(cin >> n){
    for(int count=0;count<n;count++){
      cin >> num;
      cin >> t;
      char c;
      bool fht=false;
      scanf("%c", &c);
      if(c!='\n'){
	ht=t;
	cin >> t;
	fht=true;
      }
      int keta=Keta(num);
      int nht=0;
      if(fht) nht+=Tanni(ht);
      nht+=calc(num, keta);
      string ans="";
      for(int i=0;i<num.size();i++){
	if(num[i]=='.') continue;
	ans+=num[i];
      }
      for(int i=(ans.size()-keta), j=0;i<ans.size();i++, j++){
	if(j==1) cout << '.';
	cout << ans[i];
      }
      printf(" * 10^%d ", nht);
      cout << t << endl;
    }
  }
  return 0;
}

int Tanni(string s){
  if(s=="yotta") return 24;
  if(s=="zetta") return 21;
  if(s=="exa") return 18;
  if(s=="peta") return 15;
  if(s=="tera") return 12;
  if(s=="giga") return 9;
  if(s=="mega") return 6;
  if(s=="kilo") return 3;
  if(s=="hecto") return 2;
  if(s=="deca") return 1;
  if(s=="deci") return -1;
  if(s=="centi") return -2;
  if(s=="milli") return -3;
  if(s=="micro") return -6;
  if(s=="nano") return -9;
  if(s=="pico") return -12;
  if(s=="femto") return -15;
  if(s=="ato") return -18;
  if(s=="zepto") return -21;
  if(s=="yocto") return -24;
}

int Keta(string s){
  int count;
  bool p;
  if(s[0]=='0'){
    p=false;
    for(int i=1;i<s.size();i++){
      if(s[i]=='.'){
	p=true;
	continue;
      }
      if(s[i]!='0' && p){
	return s.size()-i;
      }else if(s[i]!='0' && !p){
	for(int j=i+1;j<s.size();j++){
	  if(s[j]=='.'){
	    return s.size()-i-1;
	  }
	}
	return s.size()-1;
      }
    }
  }else{
    p=false;
    for(int i=0;i<s.size();i++){
      if(s[i]=='.') p=true;
    }
    if(p) return s.size()-1;
    else return s.size();
  }
}

int calc(string s, int keta){
  bool p=false;
  int t=-1;
  for(int i=0;i<s.size();i++){
    if(s[i]=='.'){
      p=true;
      t=i;
      break;
    }
  }
  if(p){
    if((s.size()-keta)>t){
      return 1-s.size()+keta;
    }else if((s.size()-keta)==t){
      return -1; 
    }else {
      return t-1;
    }
  }else{
    return s.size()-1;
  }
}

Measured memory_bytes: 0
#define _CRT_SECURE_NO_WARNINGS
#include<iostream>
#include<sstream>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<climits>
#include<cmath>
#include<string>
#include<vector>
#include<set>
#include<map>
#include<queue>
#include<numeric>
#include<functional>
#include<algorithm>
#include<bitset>
#include<tuple>
#include<unordered_set>
#include<unordered_map>
#include<random>
#include<array>
#include<cassert>
using namespace std;
#define INF (1<<29)
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define all(v) v.begin(),v.end()
#define uniq(v) v.erase(unique(all(v)),v.end())



int n;
int a[100000];

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

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


	multiset<int> s;
	rep(i,n) {
		auto it = s.lower_bound(a[i]);

		if (it != s.begin()) {
			s.erase(--it);
		}
		s.insert(a[i]);
	}
	cout << s.size() << endl;


	return 0;
}

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

#define ll long long
#define fw(p) for(int w=0;w<(p);w++)
#define fx(p) for(int x=0;x<(p);x++)
#define fy(p) for(int y=0;y<(p);y++)
#define fz(p) for(int z=0;z<(p);z++)
#define fyg(p,g) for(int y=(g);y<(p);y++)
#define fzg(p,g) for(int z=(g);z<(p);z++)
#define ce(d) cout<<d<<endl;
#define vecp(p) int aa;cin>>aa;(p).push_back(aa);
#define vecpl(p) long long aa;cin>>aa;(p).push_back(aa);
#define vecps(p) string aa;cin>>aa;(p).push_back(aa);
#define vecp2(p) cin>>aa;(p).push_back(aa);
#define vecpl2(p) long long a	b;cin>>ab;(p).push_back(ab);
#define vecps2(p) string ab;cin>>ab;(p).push_back(ab);
#define set0(k,n) for(int nn=0;nn<(n);nn++){ (k).push_back(0); }
#define sorts(c) sort((c).begin(),(c).end());
#define reverses(c) reverse((c).begin(),(c).end());
#define vec(b) vector<int> (b);
#define vecl(b) vector<long long> (b);
#define vecs(b) vector<string> (b);
#define vecsize(b,size) vector<int> (b)((size));
#define pb(b,a) (b).push_back((a));
#define doublece(a,b) cout<<(a)<<' '<<(b)<<endl;
#define pairs(s) vector<pair<int,int>> (s);
#define pairsl(s) vector<pair<ll,ll>> (s);
#define pairss(s) vector<pair<string,string>> (s);
#define pairsp(s) int aa,bb;cin>>aa>>bb;(s).push_back(make_pair(aa,bb));
#define pairspl(s) int aa,bb;cin>>aa>>bb;(s).push_back(make_pair(aa,bb));
#define pairsps(s) int aa,bb;cin>>aa>>bb;(s).push_back(make_pair(aa,bb));
#define pairsREV(s) (s).push_back(make_pair(bb,aa));
#define pairslREV(s) (s).push_back(make_pair(bb,aa));
#define pairssREV(s) (s).push_back(make_pair(bb,aa));
#define MOD 1000000007

int main()
{
		int N;
	cin >> N;
	ce(180*(N-2))
    return 0;
}



Measured memory_bytes: 256
printn = lambda x: print(x,end='')
inn = lambda : int(input())
inl   = lambda: list(map(int, input().split()))
inm   = lambda:      map(int, input().split())
ins = lambda : input().strip()
DBG = True # and False
BIG = 10**18
R = 10**9 + 7

def ddprint(x):
  if DBG:
    print(x)

h,w = inm()
p = h*w
if h==1 or w==1:
    print(1)
else:
    print(p//2 + (1 if p%2==1 else 0))


Measured memory_bytes: 38256
#include<stdio.h>

int main(void){
    int N;
    scanf("%d", &N);
    int A[N];
    int i;
    int min = 1000000001;
    int minIdx = 0;
    for(i = 0; i < N; i++){
        scanf("%d", &A[i]);
        if(min > A[i]){min = A[i]; minIdx = i;}
    }
    //printf("最初のmin:%d\n", min);
    int sum = 0;
    int flag = 0;//少なくとも1があるかどうか/1:yes
    int ans;
    int cnt = 0;
    for(;;){
        for(i = 0; i < N; i++){
            if(i == minIdx)
                continue;
            A[i] %= min;
            sum += A[i];
            if(A[i] == 1){flag = 1;}
            //if(A[i] == 0){cnt++;}
            //ここでminを入れ替えると同じ段階での割る数が異なってしまう
            //→N回のループを終えてからminを求めるべきかなと
            //if((min > A[i])&&(A[i]!=0)){min = A[i];}
        }
        //for(i = 0; i < N; i++){printf("%d ", A[i]);}printf("\n");
        for(i = 0; i < N; i++){if((min > A[i])&&(A[i]!=0)){min = A[i]; minIdx = i;}}
        //printf("次のmin:%d\n", min);
        if(sum == 0){ans = min; break;}
        if(flag == 1){ans = 1; break;}
        sum = 0;
    }
    printf("%d\n", ans);
    return 0;
}

Measured memory_bytes: 512
import math
n = int(input())
x = []
y = []
for i in range(n):
    x1, y1 = (int(j) for j in input().split())
    x.append(x1)
    y.append(y1)
l = 0
ave = 0
for i in range(n):
    for j in range(n):
        if i>j:
            dx = abs(x[i]-x[j])
            dy = abs(y[i]-y[j])
            l += float(math.sqrt(dx**2 + dy**2))
ave = 2*l/(n*(n-1))
ans = ave * (n-1)
print(ans)


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

//#define int long long
#define REP(i,n) for(int i=0;i<n;i++)
#define ALL(vec) (vec).begin(),(vec).end()

signed main(){
    int a,b,c,x,y;
    cin>>a>>b>>c>>x>>y;
    
    int z=min(x,y);
    
    cout<<min({
        a*x+b*y,
        a*(x-z)+b*(y-z)+z*c*2,
        max(x,y)*c*2
    })<<endl;
}


Measured memory_bytes: 256
object Main {
  def main(args: Array[String]): Unit = {
    val s = new Main()
    s.solve()
    s.out.flush()
  }
}

class Main {
  import java.io._
  import java.util.StringTokenizer

  import scala.collection.mutable
  import scala.util.Sorting
  import math.{abs, max, min}
  import mutable.{ArrayBuffer, ListBuffer}
  import scala.reflect.ClassTag

  val MOD = 1000000007
  val out = new PrintWriter(System.out)

  def solve(): Unit = {
    val N = ni()
    val T, A = ni()
    val H = na(N)
    val (_, i) = H.zipWithIndex.minBy { case (h, _) =>
      abs(T * 1000 - h * 6 - A * 1000)
    }

    out.println(i + 1)
  }


  class InputReader(val stream: InputStream) {
    private val reader = new BufferedReader(new InputStreamReader(stream), 32768)
    private var tokenizer: StringTokenizer = _

    def next(): String = {
      while (tokenizer == null || !tokenizer.hasMoreTokens)
        tokenizer = new StringTokenizer(reader.readLine)
      tokenizer.nextToken
    }

    def nextInt(): Int = next().toInt
    def nextLong(): Long = next().toLong
    def nextChar(): Char = next().charAt(0)
  }
  val sc = new InputReader(System.in)
  def ni(): Int = sc.nextInt()
  def nl(): Long = sc.nextLong()
  def nc(): Char = sc.nextChar()
  def ns(): String = sc.next()
  def ns(n: Int): Array[Char] = ns().toCharArray
  def na(n: Int): Array[Int] = map(n)(_ => ni())
  def na2(n: Int, offset: Int = 0): (Array[Int], Array[Int]) = {
    val A1, A2 = Array.ofDim[Int](n)
    rep(n) { i =>
      A1(i) = ni() + offset
      A2(i) = ni() + offset
    }
    (A1, A2)
  }
  def nm(n: Int, m: Int): Array[Array[Int]] = {
    val A = Array.ofDim[Int](n, m)
    rep(n) { i =>
      rep(m) { j =>
        A(i)(j) = ni()
      }
    }
    A
  }
  def nal(n: Int): Array[Long] = map(n)(_ => nl())
  def nm_c(n: Int, m: Int): Array[Array[Char]] = map(n) (_ => ns(m))
  def rep(n: Int, offset: Int = 0)(f: Int => Unit): Unit = {
    var i = offset
    val N = n + offset
    while(i < N) { f(i); i += 1 }
  }
  def rep_r(n: Int, offset: Int = 0)(f: Int => Unit): Unit = {
    var i = n - 1 + offset
    while(i >= offset) { f(i); i -= 1 }
  }

  def map[@specialized A: ClassTag](n: Int)(f: Int => A): Array[A] = {
    val res = Array.ofDim[A](n)
    rep(n)(i => res(i) = f(i))
    res
  }

  def sumL(as: Array[Int]): Long = {
    var s = 0L
    rep(as.length)(i => s += as(i))
    s
  }

  def cumSum(as: Array[Int]) = {
    val cum = Array.ofDim[Int](as.length + 1)
    rep(as.length) { i =>
      cum(i + 1) = cum(i) + as(i)
    }
    cum
  }
}

Measured memory_bytes: 27328
//https://atcoder.jp/contests/abc161/tasks/abc161_a

#include<bits/stdc++.h>

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

  int a, b, c ;
  std::cin >> a >> b >> c ;
  std::cout << c << " " << a << " " << b;

}


Measured memory_bytes: 256
#include <stdio.h>

int main(void) {
	int W, H, x, y, r;
	scanf("%d %d %d %d %d", &W, &H, &x, &y, &r);
	if((W - (x + r) >= 0) && ( H - (y + r) >= 0)){
		if(x - r < 0 || y - r < 0){
		printf("No");
		}else {
			printf("Yes");
		}
	}else {
		printf("No");
	}
	putchar('\n');
	return 0;
}

Measured memory_bytes: 588
import java.util.Arrays;
import java.util.HashMap;
import java.util.Map;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		Map<String,Integer >cnt = new HashMap<>();
		int a = sc.nextInt();
		long answer = 0;
		
		for(int i=0;i<a;i++) {
			String b = sc.next();
			char[] str = new char[10];
			for(int j=0;j<10;j++) {
				str[j] = b.charAt(j);
			}
			Arrays.sort(str);
			String s = String.valueOf(str);
			Integer n = cnt.get(s);
			if(n == null) {
				cnt.put(s,1);
			}else {
				answer += n;
				cnt.put(s,n+1);
			}
			
			
		}
		
		System.out.println(answer);
		
		
		
		/*int samecnt = 0;
		for(int i=0;i<a;i++) {
			for(int j=i+1;j<a;j++) {
				if(s[i].equals(s[j])) {
					samecnt++;
				}else {
					break;
				}
			}
		}
		
		
		System.out.println(samecnt);*/
		sc.close();

	}

}


Measured memory_bytes: 68664
import heapq

def main():

    n, m = map(int, input().split())
    a = list(map(lambda x: int(x) * (-1), input().split()))
    heapq.heapify(a)
    sum = 0

    for _ in range(m):
        mn = heapq.heappop(a)
        heapq.heappush(a, (-1) * (-mn // 2))

    for i in range(n):
        sum += a[i]

    print(-sum)

if __name__ == "__main__":
    main()

Measured memory_bytes: 14180
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>

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

using namespace std;

int main(){
    int N, M;
    cin >> N >> M;
    vector<int> H(N+1);
    vector<int> ma(N+1);

    REP(i, N) {
        cin >> H[i];
        ma[i] = 0;
    }

    rep(i, M) {
        int A, B;
        cin >> A >> B;
        ma[A] = max(ma[A], H[B]);
        ma[B] = max(ma[B], H[A]);
    }

    int ans = 0;
    REP(i, N) {
        ans += H[i] > ma[i];
    }
    cout << ans << endl;
    return 0;
}



Measured memory_bytes: 3672
#include <bits/stdc++.h>
using namespace std;
#define ull unsigned long long
#define ul unsigned long
#define ll long long

int main(){
  int N;
  cin>>N;
  char arfa;
  ull ans=0;
  ull syou=1000000007;
  vector<ull> an(26,0);//アルファベットの文字の出現数
  for(int i=0;i<N;i++){
    cin>>arfa;
    an[int(arfa-97)]++;
  }
  
  ans=an[25];
  for(int i=24;i>=0;i--){
    ans=ans*(1+an[i])+an[i];
    ans=ans%syou;
  }
  cout<<ans<<endl;
  
  
  return 0;
}

Measured memory_bytes: 256
#include"bits/stdc++.h"
using namespace std;
#define LL long long
#define PB push_back
#define MP make_pair

int N;
string S[10000];
int ans = 0;
int tmp[3] ={};
int main(){
	cin >> N;
	for(int i=0; i<N; i++){
		cin >> S[i];
		for(int j=0; j<S[i].size()-1; j++){
			if(S[i][j] == 'A' && S[i][j+1] == 'B') ans++;
		}
		if(S[i][0] == 'B' && S[i][S[i].size()-1] == 'A') tmp[0]++;
		else if(S[i][0] == 'B') tmp[1]++;
		else if(S[i][S[i].size()-1] == 'A') tmp[2]++;
	}

	ans += max(1,tmp[0])-1;
	tmp[0] = min(tmp[0], 1);

	if(tmp[0] == 1){
		if(tmp[1] > 0){
			ans++;
			tmp[0]--;
		}
	}

	if(tmp[0] == 1){
		if(tmp[2] > 0){
			ans++;
			tmp[0]--;
		}
	}

	ans += min(tmp[1], tmp[2]);
	
	cout << ans << endl;
}

Measured memory_bytes: 768
#include <iostream>
#include <algorithm>
#include <vector>

uint64_t get_GCD(uint64_t lhs, uint64_t rhs)
{
  uint64_t a = std::max(lhs, rhs);
  uint64_t b = std::min(lhs, rhs);

  if(b == 0) return 1;

  uint64_t res = a % b;

  while(res != 0) {
    a = b;
    b = res;
    res = a % b;
  }
  return b;
}

uint64_t get_LCM(uint64_t lhs, uint64_t rhs) {
  uint64_t gcd = get_GCD(lhs, rhs);
  return (lhs * rhs) / gcd;
}

// check lhs, rhs have semi common multiple
// \param lhs, rhs even number
bool has_scm(uint64_t lhs, uint64_t rhs) {
  // a * m - b * n = (b-a)/2
  // so (b-a)/2 must be multiple of gcd(a,b)

  uint64_t a = std::max(lhs, rhs);
  uint64_t b = std::min(lhs, rhs);

  uint64_t gcd_ab = get_GCD(a, b);

  return ((a-b)/2) % gcd_ab == 0;
}

int main()
{
  uint64_t N, M;
  std::cin >> N >> M;

  std::vector<uint64_t> a(N);
  for(uint64_t i=0; i<N; i++) {
    std::cin >> a[i];
  }

  // if two numbers a, b has scm, then
  // they are integrated with semi multiples of lcm(a, b)
  uint64_t x = a[0];
  for(uint64_t i=1; i<N; i++) {
    if(has_scm(x, a[i])) {
      uint64_t xx = get_LCM(x, a[i]);
      // avoid overflow
      if(xx < x || xx/2 > M) {
        x = 0;
        break;
      }
      x = xx;
      // std::cout << "i: " << i << " x: " << x << std::endl;
    } else {
      x = 0;
      break;
    }
  }
  // std::cout << "x: " << x << std::endl;

  uint64_t ret = 0;
  if(x !=0) {
    while(x/2 + x * ret <= M) {
      ret++;
    }
  }

  std::cout << std::fixed << ret << std::endl;
  // std::cout << ret << std::endl;
  return 0;
}


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

int main(){
  int n, t; cin >> n >> t;
  int ans = 1e9;
  for (int i = 0; i < n; i++) {
    int a, b; cin >> a >> b;
    if (t >= b) ans = min(ans, a);
  }
  if (ans == 1e9) cout << "TLE" << endl;
  else cout << ans << endl;
  return 0;
}


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

int main() {
	int n; cin >> n;
	vector<int>h(n); for (auto&& x : h)cin >> x;
	int ans = 0;
	int maxNum = h[0];
	for (auto&& x : h) {
		if (maxNum <= x) {
			maxNum = x;
			ans++;
		}
	}
	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 256
N = int(input())
TXY = [list(map(int, input().split())) for _ in range(N)]
 
pre_t, pre_x, pre_y = 0, 0, 0
for t, x, y in TXY:
  diff_t = t - pre_t
  diff_pos = abs(x-pre_x) + abs(y-pre_y)
  if diff_t < diff_pos or (diff_t-diff_pos) % 2 == 1:
    print('No')
    exit()
  else:
    pre_t, pre_x, pre_y = t, x, y
print('Yes')

Measured memory_bytes: 26864
import java.math.BigDecimal;
import java.util.Scanner;

public class Main {

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

    private Scanner scan = new Scanner(System.in);
    private final int N;
    private final long[] T;

    public Main() {
	N = Integer.parseInt(scan.next());
	T = new long[N];
	for (int i = 0; i < N; i++) {
	    T[i] = Long.parseLong(scan.next());
	}
	scan.close();
    }

    public final void answer() {

	long ans = 1;
	for (int i = 0; i < N; i++) {
	    ans = lcm(ans, T[i]);
	}

	System.out.println(ans);
    }

    private long gcd(long m, long n) {

	while(m % n != 0) {
	    long tmp = n;
	    n = m % n;
	    m = tmp;
	}

	return n;
    }

    private long lcm(long m, long n) {
	BigDecimal mb = new BigDecimal(m);
	BigDecimal nb = new BigDecimal(n);
	BigDecimal tmp = new BigDecimal(gcd(m, n));
	return mb.multiply(nb).divide(tmp).longValue();
    }
}


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

typedef long long ll;

template<typename T>
void out(T x) { cout << x << endl; exit(0); }
#define watch(x) cout << (#x) << " is " << (x) << endl

const int maxn = 55;

ll k;
ll a[maxn];

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

  cin>>k;
  ll cnt = k/50;
  
  for (int i=0; i<50; i++) {
    a[i] = 49;
    a[i] += cnt;
  }

  k %= 50;

  for (int i=0; i<k; i++) {
    for (int j=0; j<50; j++) {
      if (j == i) {
	a[j] += 50;
      } else {
	a[j]--;
      }
    }
  }

  cout<<50<<endl;
  for (int i=0; i<50; i++) {
    cout<<a[i]<<" ";
  }
  cout<<endl;  

  return 0;
}


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

#ifdef DEBUG
#include <Mylib/Debug/debug.cpp>
#else
#define dump(...)
#endif

/**
 * @title Convert base
 * @docs convert_base.md
 */
std::vector<int64_t> convert_base_to(int64_t val, int64_t base){
  if(val == 0) return {0};

  std::vector<int64_t> ret;

  while(1){
    if(val < base){
      ret.push_back(val);
      break;
    }
    ret.push_back(val % base);
    val /= base;
  }
  

  std::reverse(ret.begin(), ret.end());
  
  return ret;
}



int main(){
  int64_t N;

  while(std::cin >> N){
    int64_t t = 1;
    int l = 1;

    while(1){
      t *= 26;

      if(N <= t){
        dump(N);
        auto res = convert_base_to(N-1, 26);

        std::string ans;

        for(auto x : res) ans += (char)('a' + x);
        while((int)ans.size() < l) ans = 'a' + ans;
        
        std::cout << ans << "\n";
        break;
      }

      ++l;
      N -= t;
    }
  }

  return 0;
}


Measured memory_bytes: 3620
#include "iostream"
#include "climits"
#include "list"
#include "queue"
#include "stack"
#include "set"
#include "functional"
#include "algorithm"
#include "string"
#include "map"
#include "unordered_map"
#include "unordered_set"
#include "iomanip"
#include "cmath"
#include "random"
#include "bitset"
#include "cstdio"
#include "numeric"
#include "cassert"
#include "ctime"

using namespace std;

constexpr long long int MOD = 1000000007;
//constexpr int MOD = 1000000007;
//constexpr int MOD = 998244353;
//constexpr long long int MOD = 998244353;
constexpr double EPS = 1e-9;

//int N, M, K, H, W, L, R;
long long int N, M, K, H, W, L, R;

class Add_Segment_Tree {
	vector<long long int>v;
	long long int ret;
	int num;
	long long int Update(int place) {
		if (place >= v.size() / 2) {
			return v[place];
		}
		v[place] = Update(place * 2) + Update(place * 2 + 1);
		return v[place];
	}
public:
	Add_Segment_Tree(int n) {
		n++;
		num = 1;
		while (num < n * 2)num *= 2;
		v.resize(num, 0);
	}
	void Add(int place, long long int num, bool update) {
		place += v.size() / 2;
		v[place] += num;
		if (!update)return;
		place /= 2;
		while (place) {
			v[place] = v[place * 2] + v[place * 2 + 1];
			place /= 2;
		}
	}
	void TopDown() {
		Update(1);
	}
	long long int Sum(int a, int b) {
		ret = 0;
		b++;
		for (a += num / 2, b += num / 2; a < b; a >>= 1, b >>= 1) {
			if (a & 1)ret += v[a++];
			if (b & 1)ret += v[--b];
		}
		return ret;
	}
};

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

	cin >> N;
	vector<long long int>v(N);
	for (auto &i : v)cin >> i;
	for (int i = 1; i < N; i++) {
		v[i] += v[i - 1];
	}
	vector<long long int>w(N);
	for (auto &i : w)cin >> i;
	for (int i = 1; i < N; i++) {
		w[i] += w[i - 1];
	}
	auto u = v;
	sort(u.begin(), u.end());
	if (w[0] > u[0]) {
		cout << -1 << endl;
		return 0;
	}
	for (int i = 1; i < N; i++) {
		if (w[i] - w[i - 1] > u[i] - u[i - 1]) {
			cout << -1 << endl;
			return 0;
		}
	}
	long long int ans = 0;
	Add_Segment_Tree asg(N);
	for (int i = 0; i < N; i++) {
		int idx = lower_bound(u.begin(), u.end(), v[i]) - u.begin();
		ans += asg.Sum(idx, N - 1);
		asg.Add(idx, 1, true);
	}
	cout << ans  << endl;
}


Measured memory_bytes: 7324
#include <bits/stdc++.h>
 
#define endl '\n'
#define fi first
#define se second
#define MOD(n,k) ( ( ((n) % (k)) + (k) ) % (k))
#define forn(i,n) for (int i = 0; i < n; i++)
#define forr(i,a,b) for (int i = a; i <= b; i++)
#define all(v) v.begin(), v.end()
#define pb emplace_back

using namespace std;
 
typedef long long ll;
typedef long double ld;
typedef pair<int, int> ii;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<ii> vii;

ll s;

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

	cin >> s;
	ll x1 = 1e9;
	ll y2 = (s + x1 - 1) / x1;
	ll y1 = x1 * y2 - s;
	ll x2 = 1;

	cout << 0 << " " << 0 << " " << x1 << " " << y1 << " " << x2 << " " << y2 << endl;

	return 0;
}

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

using namespace std;

typedef long long ll;
typedef unsigned long long ull;

#define _abs(x)((x) < 0 ? (x) * -1 : (x))
#define _max(x, y)(max(0, max((x), (y))))
#define _min(x, y)(max(0, min((x), (y))))

#define pb push_back
#define mp make_pair

static const ll MOD = 1e9 + 7;

int main()
{
    //freopen("in.txt", "r", stdin);
    //freopen("out.txt", "w", stdout);
    //freopen("debug.txt", "w", stderr);

    cin.tie(0);
    ios::sync_with_stdio(false);

    string s;

    cin >> s;

    int i, len = s.size() - 1;

    for (i = 0; i < len; i++) {
        if (s[i] == 'A' && s[i + 1] == 'C') {
            cout << "Yes" << '\n';

            return 0;
        }
    }

    cout << "No" << '\n';

    return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
#include <assert.h>
#include <fstream>
#include <iostream>
#include <algorithm>
#include <array>
#include <vector>
#include <queue>
#include <set>
#include <map>
//#include <unordered_map>
//#include <unordered_set>
//#include <boost/container/static_vector.hpp>
//#include <boost/unordered_set.hpp>
//#include <boost/unordered_map.hpp>
//#include <unistd.h>

//#include <cv.h>
//#include <highgui.h>
#include <stdlib.h>
#include <string>

const int MAX_N = 200050;
std::string A;
int memo[MAX_N];

int cal_length_from(const int begin) {
    if (memo[begin] != -1) {
        return memo[begin];
    }

    std::set<char> st;
    int ret = 1;
    int num = 0;
    for (int i = begin; i < A.size(); i++) {
        if (st.find(A[i]) == st.end()) {
            st.insert(A[i]);
            num++;
            if (num == 26) {
                ret += cal_length_from(i + 1);
                break;
            }
        }
    }
    memo[begin] = ret;
    return ret;
}

int main(int argc, char **argv) {
    std::cin >> A;

    for (int i = 0; i < MAX_N; i++) {
        memo[i] = -1;
    }

    int length = cal_length_from(0);

    //std::cout << "length:" << length << std::endl;

    std::string ret;
    int begin = 0;
    for (int i = 0; i < length; i++) {
        bool pushed = false;
        for (char tmp = 'a'; tmp <= 'z'; tmp++) {
            bool found = false;
            for (int j = begin; j < A.size(); j++) {
                if (A[j] == tmp) {
                    found = true;
                    if (cal_length_from(j+1) == length - i - 1) {
                        //std::cout << i << " " << begin << " " << tmp << " " << j + 1 << " " << length - i - 1 << std::endl;
                        ret.push_back(tmp);
                        begin = j + 1;
                        pushed = true;
                    }
                    break;
                }
            }
            if (i == length - 1 && !found) {
                ret.push_back(tmp);
                break;
            }
            if (pushed) {
                break;
            }
        }
    }
    std::cout << ret << std::endl;

    return 0;
}

Measured memory_bytes: 11524
s = input()

if s=="SUN":
  print(7)
elif s=="MON":
  print(6)
elif s=="TUE":
  print(5)
elif s=="WED":
  print(4)
elif s=="THU":
  print(3)
elif s=="FRI":
  print(2)
else:
  print(1)

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

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

  int digit = 1;
  while (N >= pow(10, digit)) {
    digit++;
  }

  switch (digit) {
    case 1:
      cout << N << endl;
      break;
    case 2:
      cout << 9 << endl;
      break;
    case 3:
      cout << (N - 100 + 1) + 9 << endl;
      break;
    case 4:
      cout << 900 + 9 << endl;
      break;
    case 5:
      cout << (N - 10000 + 1) + 900 + 9 << endl;
      break;
    case 6:
      cout << 90000 + 900 + 9 << endl;
      break;
  }
}


Measured memory_bytes: 256
import sys

read=sys.stdin.read

n,m=map(int,input().split())
edge=[tuple(map(int,lst.split())) for lst in read().splitlines()]


def isconn(v,e0):
  clst=[1]*(n+1)
  clst[v]=0
  for _ in range(n):
    for e in edge:
      if e!=e0:
        tmp=clst[e[1]]&clst[e[0]]
        clst[e[1]]=tmp
        clst[e[0]]=tmp
  if sum(clst)>1:
    return False
  else:
    return True
ans=0
for e in edge:
  if not isconn(1,e):
    ans+=1
print(ans)

Measured memory_bytes: 9216
#include <iostream>
#include <vector>
#include <cstdlib>
using namespace std;


void A()
{
    int N;
    cin >> N;
    cout << (N+1) / 2;
}


void B()
{
    int A[3][3];
    int N;
    int b[100];
    
    for( int i = 0; i < 3; ++i )
        for( int j = 0; j < 3; ++j )
            cin >> A[i][j];
    
    cin >> N;
    
    for( int i = 0; i < N; ++i )
        cin >> b[i];
    
    
    for( int i = 0; i < N; ++i )
        for( int j = 0; j < 3; ++j )
            for( int k = 0; k < 3; ++k )
                if( A[j][k] == b[i] )
                    A[j][k] = -1;
    
    
    if( A[0][0]+A[1][1]+A[2][2] == -3 ||
        A[0][2]+A[1][1]+A[2][0] == -3 ){
        cout << "Yes" << endl;
        return;
    }
    
    for( int i = 0; i < 3; ++i )
        if( A[i][0]+A[i][1]+A[i][2] == -3 ||
            A[0][i]+A[1][i]+A[2][i] == -3 ){
            cout << "Yes" << endl;
            return;
        }
    
    cout << "No" << endl;
}

int main()
{
    //A();
    B();
    
    return 0;
}


Measured memory_bytes: 256
n,m = map(int, input().split())
cnts = [0]*(n+1)
for _ in range(m):
    a,b = map(int, input().split())
    cnts[a] += 1
    cnts[b] += 1

for c in cnts:
    if c%2 == 1:
        print('NO')
        exit()
else:
    print('YES')

Measured memory_bytes: 75460
#include <iostream>
#include <algorithm>
#include <iomanip>
#include <vector>
#include <set>
#include <map>

using namespace std;

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout << setprecision(10) << fixed;
    int N;
    string S;
    cin >> N >> S;
    int ans = 1;
    for(int i = 1; i < N; i++){
        if(S[i] != S[i-1]) ans++;
    }
    cout << ans << endl;
}

Measured memory_bytes: 1144
#include <bits/stdc++.h>
#define For(i, a, b) for(int (i)=(a); (i)<(b); ++(i))
#define rFor(i, a, b) for(int (i)=(a)-1; (i)>=(b); --(i))
#define rep(i, n) For((i), 0, (n))
#define rrep(i, n) rFor((i), (n), 0)
#define fi first
#define se second
using namespace std;
typedef long long lint;
typedef unsigned long long ulint;
typedef pair<int, int> pii;
typedef pair<int, lint> pil;
typedef pair<lint, int> pli;
template<class T>bool chmax(T &a, const T &b){if(a<b){a=b; return true;} return false;}
template<class T>bool chmin(T &a, const T &b){if(a>b){a=b; return true;} return false;}

constexpr lint mod = 1e9+7;
constexpr lint INF = mod*mod;
constexpr int MAX = 100010;

int main(){
        int n;
        scanf("%d", &n);
        int p[n];
        rep(i, n) scanf("%d", &p[i]);
        int M=mod;
        int ans=0;
        rep(i, n)if(chmin(M, p[i])) ++ans;
        printf("%d\n", ans);
}

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

#define REP(i, n) for (int i = 0; i < (n); ++i)
#define SIZE(a) ((int)(a).size())
#define ALL(a) (a).begin(), (a).end()

using ll = long long;
using K = long double;

const ll B = 1e18;

int main() {
  ll a, b, c, k;
  cin >> a >> b >> c >> k;
  cout << (a-b)*(k % 2 ? -1 : 1) << '\n';
}


Measured memory_bytes: 256
D = int(input())
C = list(map(int, input().split()))
S = [list(map(int, input().split())) for _ in range(D)]

L = [0]*26

v = 0
for i in range(1, D+1):
    t = int(input())
    t -= 1
    v += S[i-1][t]
    L[t] = i
    for j in range(26):
        v -= C[j]*(i-L[j])
    print(v)


Measured memory_bytes: 75012
#include<bits/stdc++.h>
using namespace std;
 
template <class T1, class T2>
ostream& operator << (ostream& out, const pair <T1, T2> p)
{
    out << '(' << p.first << ',' << p.second << ')';
        return out;
}
 
template <class T1, class T2>
istream& operator >> (istream& in, pair<T1, T2> &p)
{
    in >> p.first >> p.second;
        return in;
}
 
template <class T>
istream& operator >> (istream& in, vector<T> &v)
{
    for (T &x : v)
                in >> x;
        return in;
}
 
template <class T>
ostream& operator << (ostream& out, const vector<vector<T> > &v)
{
    for (const vector<T> &x : v)
                out << x << '\n';
        return out;
}
 
template <class T>
ostream& operator << (ostream& out, const vector<T> &v)
{
    for (const T &x : v)
                out << x << ' ';
        return out;
}
 
template <class T>
ostream& operator << (ostream& out,const set<T> &s)
{
    for (const T &x : s)
            out << x << ' ';
        return out;
}
 
 
#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 << nl
#define tr2(x, y) cerr << #x << ": " << x << " | " << #y << ": " << y << nl
#define tr3(x,y,z) cerr<<#x<<": "<<x<<" | "<<#y<<": "<<y<<" | "<<#z<<": "<<z<<nl
#define tr4(x,y,z,w) cerr<<#x<<": "<<x<<" | "<<#y<<": "<<y<<" | "<<#z<<": "<<z<<" | "<<#w<<": "<<w<<nl
#define epsilon 0.00000001L
#define inf 9999999999999999ll// ~ 10^16
#define nl "\n"
#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 mod 1000000007ll
#define modulo 998244353ll
ll power(ll a,ll b){return b?power(a*a%mod,b/2)*(b%2?a:1)%mod:1;}

int main()
{
    fast();
    ll n;
    cin>>n;
    vi x(n),y(n);
    for(ll i=0;i<n;i++)
        cin>>x[i]>>y[i];
    ll ans=0;
    for(ll p:{-1,1})
    {
        for(ll q:{-1,1})
        {
            ll smallest=p*x[0]+q*y[0];
            for(ll i=1;i<n;i++)
            {
                ll curr=p*x[i]+q*y[i];
                ans=max(ans,curr-smallest);
                smallest=min(smallest,curr);
            }
        }
    }
    cout<<ans<<nl;
}


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

public class Main {

	static int []powMod,memo[];
	static int getMod(int mod,int add,int pow) {
		long x=add*1L*powMod[pow]%13;
		return (int) ((x+mod)%13);
	}
	static int MOD=(int)1e9+7;
	static char[]s;
	static int dp(int idx,int mod,int pow) {
		if(idx==s.length)
			return mod==5?1:0;
		if(memo[mod][idx]!=-1)
			return memo[mod][idx];
		long ans=0;
		if(s[idx]!='?')
			ans=dp(idx+1,getMod(mod, s[idx]-'0',pow),pow-1);
		else
			for(int add=0;add<10;add++) {
				ans+=dp(idx+1,getMod(mod, add,pow),pow-1);
				ans%=MOD;
			}
		return memo[mod][idx]=(int)ans;
	}
	public static void main(String[] args) throws IOException {
		Scanner sc = new Scanner();
		PrintWriter out = new PrintWriter(System.out);
		s=sc.next().toCharArray();
		long x=1;
		powMod=new int [s.length+5];
		powMod[0]=1;
		for(int i=1;i<powMod.length;i++) {
			x=x*10L%13;
			powMod[i]=(int)x;
		}
		memo=new int [13][s.length];
		for(int []a:memo)
			Arrays.fill(a, -1);
		out.println(dp(0, 0,s.length-1));
		out.close();

	}

	static class Scanner {
		BufferedReader br;
		StringTokenizer st;

		Scanner() {
			br = new BufferedReader(new InputStreamReader(System.in));
		}

		Scanner(String fileName) throws FileNotFoundException {
			br = new BufferedReader(new FileReader(fileName));
		}

		String next() throws IOException {
			while (st == null || !st.hasMoreTokens())
				st = new StringTokenizer(br.readLine());
			return st.nextToken();
		}

		String nextLine() throws IOException {
			return br.readLine();
		}

		int nextInt() throws IOException {
			return Integer.parseInt(next());
		}

		long nextLong() throws NumberFormatException, IOException {
			return Long.parseLong(next());
		}

		double nextDouble() throws NumberFormatException, IOException {
			return Double.parseDouble(next());
		}

		boolean ready() throws IOException {
			return br.ready();
		}

	}

}

Measured memory_bytes: 48368
#include<bits/stdc++.h>
using namespace std;
#define int long long

#ifdef LOCAL_DEBUG
  #include "LOCAL_DEBUG.hpp"
#endif

signed main(){

  int n; cin >> n;
  vector<int> a(n);
  for(int i = 0; i < n; i++){
    cin >> a[i];
  }

  sort(a.begin(),a.end());
  vector<pair<int,int>> ans;
  int cur = a[0];
  for(int i = 1; i < n-1; i++){
    if(a[i] >= 0){
      ans.push_back({cur,a[i]});
      cur -= a[i];
    }
  }
  ans.push_back({a[n-1],cur});
  cur = a[n-1] - cur;
  for(int i = 1; i < n-1; i++){
    if(a[i] < 0){
      ans.push_back({cur,a[i]});
      cur -= a[i];
    }
  }

  cout << cur << endl;
  for(auto p : ans){
    cout << p.first << " " << p.second << endl;
  }

  return 0;
}


Measured memory_bytes: 4848
import java.util.*;
import java.io.PrintWriter;
public class Main{
	public static void main(String[] args){
		Scanner sc=new Scanner(System.in);
		int k=sc.nextInt();
		int n=sc.nextInt();
		int max=0;
		int a=sc.nextInt();
		int last=0;
		int sum=a;
		for(int i=1; i<n; i++){
			int aa=sc.nextInt();
			if(i==n-1){
				last=aa;
			}
			max=Math.max(max,aa-sum);
			sum=aa;
		}
		System.out.println(k-Math.max(max,a+k-last));
	}
}


Measured memory_bytes: 62952
//Tuvshee
  
#include<iomanip>
#include<iostream>
#define _USE_MATH_DEFINES
#include<math.h>
#include<cmath>
#include<algorithm>
#include<string>
#include<cctype>
#include<vector>
#include<queue>
using namespace std;
#define I int
#define D double
#define F float
#define C char
#define S string
#define B bool
#define L long long
#define rep(n) for(int i=0;i<n;i++)
#define reps(m,n,c) for(int c=m;c<n;c++)
#define repd(m,n,j) for(int j=n;j>m;j--)
#define whL while
#define eL endl
#define oR ||
#define anD &&
#define rtn return
#define pause system("PAUSE")
#define Max 300
#define max(m,n) ((n<m)?m:n)
#define min(m,n) ((n>m)?m:n)
  
int main()
{
	deque<int>b;
	int c;
	reps(0,3,i){
		cin>>c;
		b.push_back(c);
	}
	sort(b.begin(),b.end());
	reps(0,3,i){
		if(i)cout<<' ';
		cout<<b[i];
	}
	cout<<eL;
    rtn 0;
}

Measured memory_bytes: 1204
#include<iostream>
#include<string>
#include<algorithm>
#include<math.h>
#include<queue>
#include<set>
#include<map>
#include<random>
#include<functional>
#include<utility>

typedef long long ll;

#define rep(i,n) for(int i=0; i<n; i++)
#define pb push_back
#define P pair<int, int>
#define PLI pair<ll, int>
#define PLL pair<ll, ll>
#define VI vector<int>
#define VII vector<VI>

using namespace std;


int main() {
	int N;
	cin >> N;
	int ans = N / 2;
	if (N % 2 == 0) ans--;

	cout << ans << endl;

	return 0;
}


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

#define reps(i,s,n) for(int (i) = (s); (i) < (n); (i)++)
#define rep(i,n) reps(i,0,n)
using namespace std;
using ll = long long;

int main(){
    int n,m,x;
    cin >> n >> m >> x;
    vector<int> a(m);
    int tmp;
    vector<bool> flag(200,false);
    x--;
    rep(i,m){
        cin >> tmp;
        tmp--;
        flag[tmp] = true;
    }
    int cost0=0,costm=0;
    reps(i,x,n){
        if(flag[i] == true){
            costm++;
        }
    }
    for(int i = x; i >= 0 ;i --){
        if(flag[i] == true){
            cost0++;
        }
    }

    cout << min(cost0,costm) << endl;
    return 0;
}

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

#define DEBUG 1
#define NINF -1
#define PINF 1E9+1

typedef struct {
	int a;
	int b;
} Money;

int n,m;
Money *money;

int compareMoney(const void *sub1,const void *sub2)
{
	return ((Money *)sub1)->a - ((Money *)sub2)->a;
}

int main()
{
	long ret;
	int i,j;

	ret = 0;

	scanf("%d %d",&n,&m);
	money = (Money *)malloc(sizeof(Money) * n);
	for (i=0;i<n;i++) {
		scanf("%d %d",&money[i].a,&money[i].b);
	}
	
	qsort(money,n,sizeof(Money),compareMoney);

	for (i=0;i<n;i++) {
		if (m <= money[i].b) {
			ret += (long)money[i].a * m;
			break;
		}

		ret += (long)money[i].a * money[i].b;
		m -= money[i].b;
	}

	printf("%ld\n",ret);
	free(money);
	return 0;
}


Measured memory_bytes: 1788
#include <bits/stdc++.h>
using namespace std;
using P = pair<int, int>;
using LP = pair<int, int>;
using ll = long long;

#define rep(i, n) for (int i = 0; i < (n); ++i)
#define sz(x) int(x.size())

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

const double PI=3.14159265358979323846;

int mod = 1e9+7;
const long long INF = 1LL<<60;


int main(){
  ll X;
  cin >> X;
  vector<ll> nums;
  vector<ll> original;
  for(ll i=-200; i<200; i++){
    nums.push_back(i*i*i*i*i);
    original.push_back(i);
  }

  rep(a_idx, sz(nums)){
    rep(b_idx, sz(nums)){
      if(nums[a_idx] - nums[b_idx] == X){
        cout << original[a_idx] << " " << original[b_idx] << endl;
        return 0;
      }
    }    
  }
  return 0;
}


Measured memory_bytes: 3644
#include <bits/stdc++.h>
using namespace std;
const int INF = 1000000000;
#define REP(i,s,n) for(int i=(int)(s);i<(int)(n);++i)
#define rep(i,n) REP(i, 0, n)
typedef long long int i64;
typedef pair<int, int> pint;

struct Edge {
    int to, cost;
    Edge(int t, int c)
         : to(t), cost(c){}
};
vector<vector<Edge>> edges;
int memo[800][801][2];
int dfs(int cur, int before, int need_to_back) {
    int& res = memo[cur][before][need_to_back];
    if(res != -1) return res;
    res = 0;
    if(need_to_back) {
        for(const Edge& e : edges[cur]) {
            if(e.to == before) continue;
            int cos = dfs(e.to, cur, 1);
            res += cos;
            if(cos == 0) res += e.cost;
            else res += e.cost * 3;
        }
    }else {
        int ma = 0;
        for(const Edge& e : edges[cur]) {
            if(e.to == before) continue;
            int cos[2];
            rep(i, 2) {
                cos[i] = dfs(e.to, cur, i);
                if(cos[i] == 0) cos[i] += e.cost;
                else cos[i] +=  e.cost * (i + 2);
            }
            ma = max(ma, cos[1] - cos[0]);
            res += cos[1];
        }
        res -= ma;
    }
    return res;
}
int main() {
    cin.tie(0); ios::sync_with_stdio(false);
    int N;
    while(cin >> N && N) {
        edges.assign(N, vector<Edge>());
        vector<int> num(N);
        REP(i, 1, N) cin >> num[i];
        REP(i, 1, N) {
            int c; cin >> c;
            --num[i];
            edges[num[i]].push_back(Edge(i, c));
            edges[i].push_back(Edge(num[i], c));
        }
        
        int ans = INF;
        memset(memo, -1, sizeof(memo));
        rep(i, N) ans = min(ans, dfs(i, N, 0));
        cout << ans << endl;
    }
    return 0;
}

Measured memory_bytes: 8312
#include<stdio.h>
int main()
{
	long long int n,t,o;
	long long int a[200009],b[200009],c[200000];
	while(~scanf("%lld%lld",&n,&t))
	{
		o=0;
		for(int i=0;i<t;i++)
		{
			scanf("%lld %lld",&a[i],&b[i]);
			if(a[i]==1&&b[i]!=n) 
			c[b[i]]=1;
		}
		for(int i=0;i<t;i++)
		{
			if(b[i]==n&&c[a[i]]==1) 
			{
						o=1;
			} 
		}
		if(o!=1) printf("IMPOSSIBLE\n");
		else printf("POSSIBLE\n");
	}
	return 0;
 } 

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

public class Main {

	static Scanner sc = new Scanner(System.in);
	static int N, W, H;
	static int[] X, Y;
	static int minY, maxY;

	public static void main(String[] args) {
		W = sc.nextInt();
		H = sc.nextInt();
		N = sc.nextInt();
		X = new int[N];
		Y = new int[N];
		for (int i = 0; i < N; ++i) {
			X[i] = Integer.parseInt(sc.next());
			Y[i] = Integer.parseInt(sc.next());
		}
		int[] ax = X.clone();
		int[] ay = Y.clone();
		Arrays.sort(ax);
		Arrays.sort(ay);
		int[] x = new int[] { ax[(N - 1) / 2], ax[N / 2] };
		int[] y = new int[] { ay[(N - 1) / 2], ay[N / 2] };
		long ans = Long.MAX_VALUE;
		int ansX = 0;
		int ansY = 0;
		for (int i = 0; i < 2; ++i) {
			for (int j = 0; j < 2; ++j) {
				long v = calc(x[i], y[j]);
				if (v < ans) {
					ans = v;
					ansX = x[i];
					ansY = y[j];
				}
			}
		}
		System.out.println(ans);
		System.out.println(ansX + " " + ansY);
	}

	static long calc(long x, long y) {
		long max = 0;
		long sum = 0;
		for (int i = 0; i < N; ++i) {
			long d = Math.abs(X[i] - x) + Math.abs(Y[i] - y);
			max = Math.max(max, d);
			sum += d;
		}
		return sum * 2 - max;
	}

}

Measured memory_bytes: 14000
N = int(input())
T,A = map(int,input().split())
H = list(map(int,input().split()))
tmp = 1000
ans = 0
for i in range(N):
    if abs(A-T+H[i]*0.006)<tmp:
        tmp=abs(A-T+H[i]*0.006)
        ans=i+1
print(ans)

Measured memory_bytes: 3060
a = int(input())
b = [1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51]
print(b[a-1])

Measured memory_bytes: 3060
#include <algorithm>
#include <functional>
#include <iostream>
#include <string>
int main(int argc, char *argv[]) {
  std::string s, t;
  std::cin >> s >> t;
  std::sort(s.begin(), s.end());
  std::sort(t.begin(), t.end(), std::greater<char>());
  std::cout << (s < t ? "Yes" : "No") << std::endl;
}


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

int main()
{
int n,cnt=0;
cin >> n;
int a[n];
for(int i=0;i<n;i++)
{
cin >> a[i]; 
}

for(int i=0;i<n;i++)
    for(int j=1;j<n;j++)
    {
        if(a[j-1]>a[j])
        {
        swap(a[j-1],a[j]);
        cnt++;
        }
    }
for(int i=0;i<n-1;i++)
{
cout << a[i] << " ";
}
cout << a[n-1];
cout << endl;
cout << cnt << endl;




return 0;
}


Measured memory_bytes: 3064
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
int main(){
  ll k,x,y;
  cin>>k>>x>>y;
  vector<P> ans;
  ll kx=1,ky=1;
  if(x<0){
    x*=-1;
    kx=-1;
  }
  if(y<0){
    y*=-1;
    ky=-1;
  }
  if(k%2==0){
    if((x+y)%k!=0){
      ll dis=(x+y)%k;
      if(x+y<k) dis=k-dis;
      ll dx=(k+dis)/2,dy=(k-dis)/2;
      ans.push_back(P(x,y));
      if(x+y<k){
        if(x-dy>=0){
          x-=dy;
          y+=dx;
        }
        else{
          y-=dy;
          x+=dx;
        }
      }
      else{
        if(x-dx>=0){
          x-=dx;
          y+=dy;
        }
        else{
          y-=dx;
          x+=dy;
        }
      }
    }
    ll cnt=(x+y)/k;
    for(int i=cnt;i>0;i--){
      ans.push_back(P(x,y));
      ll dx=min(x,k);
      x-=dx;
      y-=k-dx;
    }
  }
  else{
    if(x+y<k){
      ll dis=k-(x+y);
      ans.push_back(P(x,y));
      if((x+y)%2==0){
        ll dx=(k+dis)/2,dy=(k-dis)/2;
        if(y-dy>=0){
          x+=dx;
          y-=dy;
        }
        else{
          x-=dy;
          y+=dx;
        }
      }
      else{
        x++;
        y+=k-1;
      }
    }
    if((x+y)%k!=0){
      ans.push_back(P(x,y));
      ll dis=(x+y)%k;
      if(dis%2==1){
        ll dx=(k+dis)/2,dy=(k-dis)/2;
        if(x-dx>=0){
          x-=dx;
          y+=dy;
        }
        else{
          x+=dy;
          y-=dx;
        }
      }
      else{
        dis=k-dis;
        ll dx=(k+dis)/2,dy=(k-dis)/2;
        if(x-dy>=0){
          x-=dy;
          y+=dx;
        }
        else{
          x+=dx;
          y-=dy;
        }
      }
    }
    ll cnt=(x+y)/k;
    for(int i=cnt;i>0;i--){
      ans.push_back(P(x,y));
      ll dx=min(x,k);
      x-=dx;
      y-=k-dx;
    }
  }
  for(int i=ans.size()-1;i>0;i--){
    if(abs(ans[i].first-ans[i-1].first)+abs(ans[i].second-ans[i-1].second)!=k){
      cout<<-1<<endl;
      return 0;
    }
  }
  if(abs(ans[ans.size()-1].first)+abs(ans[ans.size()-1].second)!=k){
    cout<<-1<<endl;
    return 0;
  }
  cout<<ans.size()<<endl;
  for(int i=ans.size()-1;i>=0;i--) cout<<kx*ans[i].first<<" "<<ky*ans[i].second<<endl;
}


Measured memory_bytes: 5744