akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <algorithm>
#include <functional>
#include <string>
#include <vector>
using namespace std;
#define MAXSIZE 200
#define MAXL 100
typedef long long int lli;

int main(){
    lli n;
    cin >> n;
    
    vector<lli> life_initial_vec;
    lli notZeroLife = 0;
    for(lli i = 0; i < n; i++){
        lli life_initial_vec_input;
        cin >> life_initial_vec_input;
        life_initial_vec.push_back(life_initial_vec_input);
        //notZeroLife += (life_initial_vec[i] != 0);
    }

LOOP:
    sort(life_initial_vec.begin(), life_initial_vec.end());
    /*for(lli i = 0; i != life_initial_vec.size(); i++){
        cout << "life_initial_vec[" << i << "] = " << life_initial_vec[i] << endl;
    }*/
    lli rightZeroIndex = -9, finishFlag = 0;

    if(notZeroLife > 0){
        if(notZeroLife == 1){
            rightZeroIndex = 0;
        }else{
            for(lli i = 0; i < n; i++){
                if(life_initial_vec[i] == 0 && life_initial_vec[i + 1] != 0){
                    rightZeroIndex = i;
                }
            }
        }
    }

    if(rightZeroIndex == 0){
        life_initial_vec.erase(life_initial_vec.begin() + 0);
    }else{
        if(rightZeroIndex > 0)
            life_initial_vec.erase(life_initial_vec.begin(), life_initial_vec.begin() + (rightZeroIndex + 1));
    }

    notZeroLife = 0;

    for(lli i = 0; i != life_initial_vec.size(); i++){
        if(i > 0){
            life_initial_vec[i] %= life_initial_vec[0];
        }
        //cout << "life_initial_vec[" << i << "] = " << life_initial_vec[i] << endl;

        if(life_initial_vec[i] == 1){
            cout << "1" << endl;
            finishFlag = 1;
            break;
        }

        if(life_initial_vec[i] != 0){
            notZeroLife++;
        }
    }

    if(!finishFlag && notZeroLife > 1){
        //cout << notZeroLife << endl;
        goto LOOP;
    }
    
    if(!finishFlag){
        //cout << endl << life_initial_vec[0] << endl;
        cout << life_initial_vec[0] << endl;
    }

    return 0;
}

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

int main(){
  int a,b,c,d,e=-100,f= 100,g;
  cin>>a>>b>>c>>d;
  for(int i=0;i<a;i++){
    cin>>g;
    e=max(e,g);
  }
  for(int i=0;i<b;i++){
    cin>>g;
    f=min(f,g);
  }
  for(int i=c+1;i<=d;i++){
    if(e<i&&i<=f){
      cout<<"No War"<<endl;
      break;
    }
    if(i==d)
      cout<<"War"<<endl;
  }
}

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

using namespace std;

int main(){
	int x,y,a,b,c;
	int i,j,k;
	scanf("%d %d %d %d %d",&x,&y,&a,&b,&c);
	
	long long p[a],q[b],r[c],res[x+y+x+y];
	for(i = 0;i < 2*x + 2*y ;i++)
		res[i] = 0;
	
	i = 0;
	while(i < a)
		scanf("%lld",&p[i++]);
	sort(p,p+a);
	j = a-1;
	for(k = 0;k < x;k++)
		res[k] = p[j--]; 
		
	i = 0;
	while(i < b)
		scanf("%lld",&q[i++]);
	sort(q,q+b);
	j = b-1;
	int e = k + y;
	for(k;k < e;k++)
		res[k] = q[j--]; 
		
	
	i = 0;
	while(i < c)
		scanf("%lld",&r[i++]);
	sort(r,r+c);
	int f = k + x + y;
	j = c - 1;
	for(k;k < f && j >= 0;k++)
		res[k] = r[j--]; 
	
	sort(res,res+2*x+2*y,greater<int>());
/*	
	for(i = 0;i < 2*x + 2*y;i++)
		printf("%d ",res[i]);
*/	
	for(i = 1;i<x+y;i++)
		res[i] += res[i-1];
		
		
	
		
	printf("%lld",res[x+y-1]);
	return 0;
	
	
		
	
} 

Measured memory_bytes: 8984
#include <stdio.h>
int count=0;
void binarySearch(int S[],int T[],int n,int q);
int main(void){
	int i,n,q;
	scanf("%d",&n);
	int j = 0;
	int S[n];
	
	for(i=0;i<n;i++){
		scanf("%d",&S[i]);
	}
	scanf("%d",&q);
	int T[q];
	for(i=0;i<q;i++){
		scanf("%d",&T[i]);
	}
	binarySearch(S,T,n,q);
	printf("%d\n",count);
	return 0;	
}
void binarySearch(int S[],int T[],int n,int q){
	int i,left,right,mid;
	for(i=0;i<q;i++){
	left=0;
	right=n;
		while(left<right){
			mid =(left+right)/2;
			if(S[mid]==T[i]){ 
			count++;
			break;
			}
			else if(T[i]<S[mid]){
				right=mid;
				}
				else {
				left=mid+1;
				}
			}
	}
}


Measured memory_bytes: 2252
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <cstdio>

using namespace std;

int ret;
int n, m, k;

void dfs(int freq, int num)
{
	if (freq == 0){
		ret += ((num - k) <= 0 ? 1 : num - k);
		// printf("%d %d -> %d\n", freq, num, ret);
		return;
	}
	else {
		for (int i = 1; i <= m; i++){
			dfs(freq-1, num + i);
		}
	}
	return;
}

int main(void)
{
	while (cin >> n >> m >> k, n && m){
		ret = 0;
		dfs(n, 0);

		printf("%.08lf\n", ret / pow((double)m, (double)n));
	}
}

Measured memory_bytes: 1248
from collections import deque

N = int(input())
adj = [[] for _ in range(N)]
for _ in range(N-1):
    u,v,w = map(lambda x:int(x)-1, input().split())
    w += 1
    adj[u].append((v,w))
    adj[v].append((u,w))

visited = [False]*N
q = deque([0])
dist = [0]*N
while q:
    cur = q.popleft()
    if visited[cur]:
        continue
    visited[cur] = True
    for nex, w in adj[cur]:
        if (not visited[nex]):
            q.append(nex)
            dist[nex] = dist[cur] + w
# print(dist)
for d in dist:
    print(d%2)


Measured memory_bytes: 43872
A, B = map(int, input().split())

# floor(1009*0.1)=100 かつ floor(1010*0.1)=101 より、1から1009までの数字を調べればよい
ans = '-1'
for i in range(1010)[::-1]:
  if i*8 // 100 == A and i // 10 == B:
    ans = i

print(ans)


Measured memory_bytes: 9160
N,K = map(int,input().split())
L = input().split()
M = N-1
d = 0
flag = True
while flag:
  d = 0
  M += 1
  for j in range(K):
    if L[j] in str(M):
      break
    else:
      d += 1
  if d == K:
    flag = False    
print(M)

Measured memory_bytes: 2940
N, A ,B = list(map(int,input().split()))
def problem2(N, A, B):
  if A <= N % (A+B):
    answer = (N // (A+B)) * A + A
  else:
    answer = (N // (A+B)) * A + N % (A+B)
  return answer
print(problem2(N, A, B))


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

namespace AOJ {
    public class Probrem {
        public static void Main() {
            var data = Console.ReadLine().Split().Select(int.Parse).ToArray();
            var W = data[0];
            var H = data[1];
            var x = data[2];
            var y = data[3];
            var r = data[4];
            W -= r;
            H -= r;
            Console.WriteLine(r <= x && x <= W && r <= y && y <= H ? "Yes" : "No");
        }
    }
}


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

void solve(long long N, long long Y) {
    rep(i, N + 1) {
        rep(j, N + 1) {
            if ((N - i - j) >= 0) {
                if ((i * 10000 + j * 5000 + (N - i - j) * 1000) == Y) {
                    cout << i << " " << j << " " << N - (i + j) << endl;
                    return;
                }
            }
        }
    }
    cout << "-1 -1 -1" << endl;
}

int main() {
    long long N;
    scanf("%lld", &N);
    long long Y;
    scanf("%lld", &Y);
    solve(N, Y);
    return 0;
}


Measured memory_bytes: 3744
def gcd(m, n):
    x = max(m, n)
    y = min(m, n)
    z = None
    if x % y == 0:
        return y
    else:
        while x % y != 0:
            z = x % y
            x = y
            y = z
        return z


# 引用：https://qiita.com/snow67675476/items/e87ddb9285e27ea555f8
def get_fact(n):
    arr = []
    a_append = arr.append
    temp = n
    for i in range(2, int(-(-n ** 0.5 // 1) + 1)):
        if temp % i == 0:
            cnt = 0
            while temp % i == 0:
                cnt += 1
                temp //= i
            a_append([i, cnt])

    if temp != 1:
        a_append([temp, 1])

    if not arr:
        a_append([n, 1])

    return arr


# input
A, B = map(int, input().split())

# check
# 参考：https://drken1215.hatenablog.com/entry/2019/10/03/175800
# ①最大公約数の素因数分解を求める
g = gcd(A, B)
fact = [f[0] for f in get_fact(g)]

# ②指数を省き、カウントする(1は確実にあるので予めカウントしておく)
elem = [1]
e_append = elem.append
for f in fact:
    if f not in elem:
        e_append(f)

print(len(elem))

Measured memory_bytes: 3188
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		while (true) {
			int a = sc.nextInt();
			String op = sc.next();
			int b = sc.nextInt();

			if (op.equals("+")) {
				System.out.println((a + b));
			}
			if (op.equals("-")) {
				System.out.println((a - b));
			}
			if (op.equals("*")) {
				System.out.println((a * b));
			}
			if (op.equals("/")) {
				System.out.println((a / b));
			}
			if (op.equals("?")) {
				break;
			}

		}

	}
}



Measured memory_bytes: 26228
using System;
using System.IO;
using System.Linq;
using System.Numerics;
using System.Collections.Generic;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading.Tasks;
using System.Diagnostics;
using static System.Math;
using System.Runtime.CompilerServices;
using MethodImplOptions = System.Runtime.CompilerServices.MethodImplOptions;
using MethodImplAttribute = System.Runtime.CompilerServices.MethodImplAttribute;

public static class P
{
    public static void Main()
    {
        int x = 0, y = 0;
        int curDir = 0;
        int curStreak = 0;
        List<int>[] moves = { new List<int>(), new List<int>() };
        bool firstChunk = true;
        foreach (var c in Console.ReadLine() + "T")
        {
            if (c == 'F')
            {
                curStreak++;
            }
            else
            {
                if (firstChunk) x -= curStreak;
                else moves[curDir].Add(curStreak);
                firstChunk = false;
                curDir ^= 1;
                curStreak = 0;
            }
        }

        var xy = Console.ReadLine().Split().Select(int.Parse).ToArray();
        x += xy[0];
        y += xy[1];

        Console.WriteLine(CanAchive(moves[0], x) && CanAchive(moves[1], y) ? "Yes" : "No");
    }

    static bool CanAchive(IEnumerable<int> moves, int cood)
    {
        if (8000 < Abs(cood)) return false;
        HashSet<int> set = new HashSet<int>() { 0 };
        foreach (var move in moves)
        {
            HashSet<int> newSet = new HashSet<int>();
            foreach (var item in set)
            {
                newSet.Add(item + move);
                newSet.Add(item - move);
            }
            set = newSet;
        }
        return set.Contains(cood);
    }
}
 

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

void fnInput(vector<string>& rvsSortBbl, vector<string>& rvsSortSel)
{
  int nMaxSiz;
  cin >> nMaxSiz;
  
  rvsSortBbl.resize(nMaxSiz);
  rvsSortSel.resize(nMaxSiz);
  for (int i = 0; i < nMaxSiz; i++)
  {
    cin >> rvsSortBbl[i];
    rvsSortSel[i] = rvsSortBbl[i];
  }
}

void fnBubbleSort(vector<string>& rvsSortBbl)
{
  int nxMax = rvsSortBbl.size() - 1;
  int nxStop = 0;
  while (nxStop != nxMax)
  {
    int nxMin = nxMax;
    for (int i = nxMax; i > nxStop; i--)
    {
      if (rvsSortBbl[i].at(1) < rvsSortBbl[i - 1].at(1))
      {
        swap(rvsSortBbl[i], rvsSortBbl[i - 1]);
        nxMin = i;
      }
    }
    nxStop = nxMin;
  }
}

void fnOutputBbl(const vector<string>& cnrvsSortBbl)
{
  for (int i = 0; i < cnrvsSortBbl.size(); i++)
  {
    if (i) cout << " ";
    cout << cnrvsSortBbl[i];
  }
  cout << endl;
  cout << "Stable" << endl;
}

void fnSelectionSort(vector<string>& rvsSortSel)
{
  for (int nxed = 0; nxed < rvsSortSel.size() - 1; nxed++)
  {
    int nxMin = nxed;
    bool bSwap = false;
    for (int nxing = nxed + 1; nxing < rvsSortSel.size(); nxing++)
    {
      if (rvsSortSel[nxing].at(1) < rvsSortSel[nxMin].at(1))
      {
        nxMin = nxing;
        bSwap = true;
      }
    }
    if (bSwap)
      swap(rvsSortSel[nxed], rvsSortSel[nxMin]);
  }
}

void fnOutputSel(const vector<string>& cnrvsSortSel, const vector<string>& cnrvsSortBbl)
{
  string sSortEnd = "Stable";

  for (int i = 0; i < cnrvsSortSel.size(); i++)
  {
    if (i) cout << " ";
    cout << cnrvsSortSel[i];
    
    if (cnrvsSortSel[i] != cnrvsSortBbl[i]) sSortEnd = "Not stable";
  }
  cout << endl;
  cout << sSortEnd << endl;
}

int main()
{
  cin.tie(0);
  ios::sync_with_stdio(false);
  
  vector<string> vsSortBbl, vsSortSel;

  fnInput(vsSortBbl, vsSortSel);
  fnBubbleSort(vsSortBbl);
  fnOutputBbl(vsSortBbl); 

  fnSelectionSort(vsSortSel);
  fnOutputSel(vsSortSel, vsSortBbl);

  return 0;
}



Measured memory_bytes: 3232
#include<bits/stdc++.h>
using namespace std;
int main()
{
	int a,b,flag=0;
	char x;
	cin>>a>>b;
	for(int i=1;i<=a+b+1;i++)
	{
		cin>>x;
		if(i!=a+1)
		{
			if(x<48||x>57)
			{
				flag=1;
			}
		}
		else if(i==a+1)
		{
			if(x!=45)
			{
				flag=1;
			}
		}
	}
	if(flag==1)
	{
		cout<<"No"<<endl;
	}
	else
	{
		cout<<"Yes"<<endl;
	}
	return 0;
}

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

#define _CRT_SECURE_NO_WARNINGS

#define REP(i, n) for(decltype(n) i = 0; i < (n); i++)
#define REP2(i, x, n) for(decltype(x) i = (x); i < (n); i++)
#define REP3(i, x, n) for(decltype(x) i = (x); i <= (n); i++)
#define RREP(i, n) for (decltype(n) i = (n) - 1; i >= 0; i--)

#define ALL(a) (a).begin(),(a).end()
#define SORT(c) sort((c).begin(),(c).end())
#define DESCSORT(c) sort(c.begin(), c.end(), greater<int>())

using namespace std;

const int INF = 1000000000;
const double PI = 3.1415926535897932384626433832795;

// N, E, S, W
const int dx[4] = { -1, 0,  1,  0 };
const int dy[4] = { 0, 1,  0, -1 };

using LL = long long int;
using LD = long double;
using pii = pair<int, int>;
using pdd = pair<double, double>;
using pll = pair<LL, LL>;
using vi = vector<int>;
using vd = vector<double>;
using vvi = vector<vi>;
using vll = vector<LL>;

//==============================================

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

	int n;
	cin >> n;

	vvi M(n + 1, vi(n + 1));

	int u, k, v;
	REP3(i, 1, n) {
		cin >> u >> k;
		REP3(j, 1, k) {
			cin >> v;
			M[u][v] = 1;
		}
	}

	REP3(i, 1, n) {
		REP3(j, 1, n) {
			if (j != 1) cout << " ";
			cout << M[i][j];
		}
		cout << "\n";
	}
	return 0;
}

Measured memory_bytes: 3200
#include <stdio.h>

int main (){
	char tanggal [15];
	scanf("%s", &tanggal);
	tanggal [0] = '2';
	tanggal [1] = '0';
	tanggal [2] = '1';
	tanggal [3] = '8';
	printf("%s\n", tanggal);
	
	return 0;
				
			
}

Measured memory_bytes: 1616
#include<iostream>
#include<vector>
#include <algorithm>
#include <functional>
#include <random>

using namespace std;

int main() {
    int N = 0;
    int c = 0;
    vector<int> A, B;

    cin >> N;
    for (int i = 0; i < N; i++) {
        cin >> c;
        A.push_back(c);
    }
    sort(A.begin(), A.end());
    B = A;
    A.erase(unique(A.begin(), A.end()), A.end());
    if (A == B) {
        cout << "YES" << endl;
    }
    else {
        cout << "NO" << endl;
    }
}   


Measured memory_bytes: 1908
#include <stdio.h>
#include <stdlib.h>
 
int main (void) {
  char str1[3];
  char str2[3];
  int resoult = 0;
  
  scanf("%s", str1);
  scanf("%s", str2);
  
  for (int i = 0; i < 3; i++) {
    if( str1[i] == str2[i] ) {
      resoult++;
    }
  }
  
  printf("%d", resoult);
  
  return 0;
}

Measured memory_bytes: 128
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		time();
	}
	
	public static void time() {
		Scanner scan = new Scanner(System.in);
		int S = scan.nextInt();
		int h = S/3600;
		int m = (S%3600)/60;
		int s = (S%3600)%60;
		System.out.println(h+":"+m+":"+s);
	}

}


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

// GNU C Compiler
//template<class T> inline string toString(T x) { ostringstream sout; sout << x; return sout.str(); }


/*
--------------------------------------------

	type

--------------------------------------------
*/
using LL = long long;
using ULL = unsigned long long;
using PII = pair<int, int>;
//using pair<T1, T2> = p12;

/*
--------------------------------------------

	container

--------------------------------------------
*/
#define PB emplace_back
#define MP make_pair 
#define SZ(a) int((a).size())

/*
--------------------------------------------

	repetition

--------------------------------------------
*/
#define REP(n) for(int i=0; i<n; i++)
#define REPj(n) for(int j=0; j<n; j++)
#define REPinit(a,n) for(int i=a; i<n; i++)
#define REPinitj(a,n) for(int j=a; j<n; j++)

//algorithm
//#define SORT(c) sort((c).begin(),(c).end())

/*
--------------------------------------------

	constant

--------------------------------------------
*/
//clear memory
#define CLR(a) memset((a), 0 ,sizeof(a))

/*

	Optimizer

*/
//#pragma GCC optimize("Ofast")

int H,W;
vector<string> S;
vector<vector<int>> Smap;

void resolve(int h, int w) {
  REP(3){
    REPj(3){
      if((h-1+i) >= 0 && (h-1+i) < H && (w-1+j) >= 0 && (w-1+j) < W) {
        Smap[h-1+i][w-1+j]++;
      }
    }
  }
}

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

  cin >> H >> W;

  S = vector<string>(H);
  Smap = vector<vector<int>>(H, vector<int>(W));

  REP(H) cin >> S[i];

  REP(H){
    REPj(W){
      if(S[i][j] == '#') {
        resolve(i,j);
      }
    }
  }

  REP(H){
    REPj(W){
      if(S[i][j] == '#') {
        cout << '#';
      }
      else {
        cout << Smap[i][j];
      }
    }
    cout << endl;
  }

  return 0;
}


Measured memory_bytes: 256
#define _USE_MATH_DEFINES
#include <iostream>
#include <fstream>
#include <sstream>
#include <string>
#include <cstring>
#include <vector>
#include <set>
#include <map>
#include <unordered_map>
#include <queue>
#include <deque>
#include <stack>
#include <algorithm>
#include <bitset>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <numeric>
#include <functional>
#include <cctype>
#include <list>
#include <limits>
#include <cassert>
#include <random>
#include <time.h>
#include <unordered_set>
//#include <boost/multiprecision/cpp_int.hpp>



using namespace std;
using Int = long long;
//using namespace boost::multiprecision;

const double EPS = 1e-10;
long long const MOD = 998244353;

long long mod_pow(long long x, long long n) {
    long long res = 1;
    for (int i = 0;i < 60; i++) {
        if (n >> i & 1) res = res * x % MOD;
        x = x * x % MOD;
    }
    return res;
}

template<typename T>
T gcd(T a, T b) {
    return b != 0 ? gcd(b, a % b) : a;
}

template<typename T>
T lcm(T a, T b) {
    return a * b / gcd(a, b);
}

void fastInput() {
    cin.tie(0);
    ios::sync_with_stdio(false);
}

string solve(int A, string B) {
    string ret = "error";
    int max_sum = 0;
    for (int i = 0; i < (1 << (B.length() - 1)); i++) {
        int bits = i;
        int sum = 0;
        int num = 0;
        string shredded;
        for (int j = 0; j < B.length(); j++) {
            num += B[j] - '0';
            shredded += B[j];
            if (bits & (1 << j) || j == B.length() - 1) {
                sum += num;
                num = 0;
                if (j != B.length() - 1) shredded += ' ';
            }
            num *= 10;
        }
        if (sum > max_sum && A >= sum) {
            ret = to_string(sum) + ' ' + shredded;
            max_sum = sum;
        } else if (sum == max_sum) {
            ret = "rejected";
        }
    }
    return ret;
}

int main(void) {
    int a;
    string b;
    vector<string> ans;
    while (1) {
        cin >> a >> b;
        if (a == 0) break;
        ans.push_back(solve(a, b));
    }
    for (auto i : ans) {
        cout << i << endl;
    }
}



Measured memory_bytes: 3216
import java.util.Scanner;
public class Main {
	public static void main(String[] args) throws Exception{
		Scanner scan=new Scanner(System.in);
		long A=scan.nextLong();
		long B=scan.nextLong();
		long C=scan.nextLong();
		long ans=B/C-A/C;
		System.out.println(A%C==0?ans+1:ans);
	}
}

Measured memory_bytes: 23124
import java.util.*;
import java.util.function.Consumer;
import java.util.stream.Collectors;

public class Main {
    private static final Scanner scanner = new Scanner(System.in);
    private static final Consumer<List<String>> consumer = solve();

    public static void main(String[] args) {
        consumer.accept(readInput());
    }

    private static List<String> readInput() {
        final List<String> lineList = new ArrayList<>();
        while (scanner.hasNextLine()) {
            lineList.add(scanner.nextLine());
        }
        return lineList;
    }

    static Consumer<List<String>> solve() {
        return args -> {
            int N = Integer.parseInt(args.get(0).split(" ")[0]);
            int M = Integer.parseInt(args.get(0).split(" ")[1]);
            int[][] dist = new int[N][N];
            int[][] fromList = new int[N][N];

            for (int i = 0; i < N; i++) {
                Arrays.fill(dist[i], Integer.MAX_VALUE / 2);
            }
            for (int i = 0; i < N; i++) {
                dist[i][i] = 0;
            }

            for (String l : args.stream().skip(1).collect(Collectors.toList())) {
                int[] edge = Arrays.stream(l.split(" ")).mapToInt(Integer::parseInt).toArray();
                int from = edge[0] - 1, to = edge[1] - 1, cost = edge[2];
                dist[from][to] = cost;
                dist[to][from] = cost;
                fromList[from][to] = from;
                fromList[to][from] = to;
            }

            for (int m = 0; m < N; m++) {
                for (int f = 0; f < N; f++) {
                    for (int t = 0; t < N; t++) {
                        if (dist[f][t] > dist[f][m] + dist[m][t]) {
                            dist[f][t] = dist[f][m] + dist[m][t];
                            fromList[f][t] = m;
                        }
                    }
                }
            }

            int cnt = 0;
            for (String l : args.stream().skip(1).collect(Collectors.toList())) {
                int[] edge = Arrays.stream(l.split(" ")).mapToInt(Integer::parseInt).toArray();
                int from = edge[0] - 1, to = edge[1] - 1, cost = edge[2];
                for (int f = 0; f < N; f++) {
                    if (f == to) {
                        continue;
                    }
                    if (dist[f][from] + cost == dist[f][to]) {
                        cnt++;
                        break;
                    }
                }
            }

            System.out.println(M - cnt);
        };
    }
}

Measured memory_bytes: 31544
#include <bits/stdc++.h>
using namespace std;
#define ll unsigned long long int
#define mod 1000000007
bool isPrime[1000001];
ll power(ll a,ll b)
{
    ll result = 1;
    while(b>0)
    {
        if(b%2)
        {
            result = (a*result)%mod;
        }
        a = (a*a)%mod;
        b = b/2;
    }
    return result;
}
int gcd(int a,int b)
{
    if(b==0)
    {
        return a;
    }
    return gcd(b,a%b);
}
void sieve()
{
    memset(isPrime,1,sizeof(isPrime));
    isPrime[0] = isPrime[1] = 0;
    for(int i=2;i*i<=1000000;i++)
    {
        if(isPrime[i])
        {
            for(int j=i*i;j<=1000000;j+=i)
            {
                isPrime[j] = 0;
            }
        }
    }
}
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL),cout.tie(NULL);
    string s1,s2;
    cin>>s1>>s2;
    int count = 0;
    for(int i=0;i<s1.size();i++)
    {
        if(s1[i]!=s2[i])
        {
            count++;
        }
    }
    cout<<count;
    return 0;
}

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

int main()
{
  int n;
  cin>>n;
  int a[n][3];
  for(int i=0;i<n;i++)
    cin>>a[i][0]>>a[i][1]>>a[i][2];
  
  int dp[n][3];
  dp[0][0]=a[0][0];
  dp[0][1]=a[0][1];
  dp[0][2]=a[0][2];
  
  for(int i=1;i<n;i++)
  {
  	dp[i][0]=max(dp[i-1][1],dp[i-1][2])+a[i][0];
  	dp[i][1]=max(dp[i-1][0],dp[i-1][2])+a[i][1];
  	dp[i][2]=max(dp[i-1][1],dp[i-1][0])+a[i][2];
  }
  
  cout<<max(dp[n-1][0],max(dp[n-1][1],dp[n-1][2]))<<endl;
  
  return 0;
}
  

Measured memory_bytes: 2560
from sys import stdin

def main():
    n = int(input())
    a = [int(x) for x in stdin.readline().rstrip().split()]
    cnt = 0
    for i, aaa in enumerate(a):
        if (i + 1) % 2 and aaa % 2:
            cnt += 1
    print(cnt)
    

if __name__ == "__main__":
    main()

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

vector<int> v;

int main(){
  ll n;
  v.push_back(2);
  for(ll i=3; i<1000000; i+=2){
    bool flag=true;
    for(vector<int>::iterator it=v.begin(); it!=v.end() && (*it)*(*it)<=i; it++){
      if(i%(*it)==0){
        flag=false;
        break;
      }
    }
    if(flag)v.push_back(i);
  }
  while(scanf("%lld", &n)!=EOF){
    ll ans=0;
    for(vector<int>::iterator it=v.begin(); it!=v.end(); it++){
      if(*it>n)break;
      ans++;
    }
    printf("%lld\n", ans);
  }
  return 0;
}

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

using namespace std;
typedef long long ll;
typedef pair<int,int> P;

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

    map<string, ll> mp;
    ll N; cin >> N;
    ll sum = 0;
    for (int i = 0;i < N;i++){
        string s; ll t;
        cin >> s >> t;
        sum += t;
        mp[s] = sum;
    }

    string s; cin >> s;

    cout << sum-mp[s] << endl;

    return 0;

}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int a[10], b[10];
int main(){
	for(int i = 0; i < 6; i+=2){
		cin >> a[i] >> b[i];
		b[i + 1] = a[i], a[i + 1] = b[i];
	}
	for(int i = 0; i < 6; i++){
		for(int j = 0; j < 6; j++){
			for(int k = 0; k < 3; k++){
				if(i != j && i != k && j != k){
					set<int> st;
					st.insert(a[i]);
					st.insert(a[j]);
					st.insert(a[k]);
					st.insert(b[k]);
					/*
					cout << a[i] << " -> " << b[i] << " - ";
					cout << a[j] << " -> " << b[j] << " - ";
					cout << a[k] << " -> " << b[k] << endl;
					cout << st.size() << endl;
					*/
					if(st.size() == 4 && b[i] == a[j] && b[j] == a[k])return cout << "YES" << endl, 0;
				}
			}
		}
	}
	cout << "NO" << endl;
}

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

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

typedef pair<int,int> pii;
const int INF=1e6, MAXM=128;
int C[2][MAXM][MAXM], dist[MAXM], visited[MAXM], N, M;

int main()
{
        int a,b,c,d;
        while(cin>>N>>M&&(N|M))
        {
                rep(i,M) rep(j,N) C[0][i][j]=C[1][i][j]=INF;
                rep(i,N){ cin>>a>>b>>c>>d; --a; --b; C[0][a][b]=C[0][b][a]=c; C[1][a][b]=C[1][b][a]=d; }

                cin>>d;
                rep(i,d)
                {
                        fill(dist,dist+MAXM,INF);
                        fill(visited,visited+MAXM,false);

                        cin>>a>>b>>c; --a; --b;
                        dist[a]=0;

                        while(true)
                        {
                                int from=-1;
                                rep(i,M) if(!visited[i]&&(from==-1||dist[i]<dist[from])){ from=i; }
                                if(from==b){ cout<<dist[from]<<endl; break; } else { visited[from]=true; }

                                rep(to,M) dist[to]=min(dist[to],dist[from]+C[c][from][to]);
                        }
                }
        }

        return 0;
}

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

using namespace std;
#define rep(i, n) for (ll i = 0; i < (n); ++i)
//#define rep(i, n) for (int i = 0; i < (n); ++i)
#define sz(x) ll(x.size())
//typedef long long ll;
typedef long long ll;
//typedef pair<int, int> P;
typedef pair<ll, ll> P;
//const double INF = 1e10;
//const ll INF = 10e15;
const ll MINF = -10e10;
const int INF = INT_MAX / 100;
#define cmin(x, y) x = min(x, y)
#define cmax(x, y) x = max(x, y)


//ifstream myfile("~/Downloads/02.txt");
//ofstream outfile("log.txt");
//outfile << setw(6) << setfill('0') << prefecture << setw(6) << setfill('0') << rank << endl;
// std::cout << std::bitset<8>(9);

typedef priority_queue<P, vector<P>, greater<P> > PQ_ASK;
const int mod = 1000000007;

string to_upper(string str) {
    int diff = 'a' - 'A';
    for (int i = 0; i < str.size(); i++) {
        char c = str[i];
        if ('A' <= c && c <= 'Z') {
            c += diff;
            str[i] = c;
        }
    }
    return str;
}

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

    rep(i, n) {
        string command;
        int start, end;
        cin >> command >> start >> end;
        if (command == "replace") {
            string p;
            cin >> p;
            string front = start == 0 ? "" : s.substr(0, start);
            string back = s.substr(end + 1);
            s = front + p + back;
        } else if (command == "reverse") {
            reverse(s.begin() + start, s.begin() + end + 1);
        } else if (command == "print") {
            string ans = s.substr(start, end - start+1);
            cout << ans << endl;
        }
    }

}



Measured memory_bytes: 3204
#include <bits/stdc++.h>
using namespace std;
 
#define int long long
 
signed main() {
    string s;
    cin >> s;
    for(int i=0; i<2; ++i) {
        if(s[i]==s[i+1]&& s[i]==s[i+2]) {
            cout << "Yes" << endl;
            return 0;
        }
    }
    cout << "No" << endl;
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
const int N=5005,mo=1e9+7;
int n,m,i,j,f[N],a,b,mi[N],ans;
int main(){
	scanf("%d%d",&n,&m);
	for(i=*mi=1;i<N;++i)mi[i]=2*mi[i-1]%mo;
	f[m]=1;
	for(i=n;i;--i){
		a=b=0;
		for(j=m;j;--j){
			int of=f[j];
			f[j]=(1ll*(j+1)*f[j]+a)%mo;
			a=2ll*(a+mo-b)%mo;b=2*b%mo;
			a=(a+1ll*(j-1)*of)%mo;b=(b+of)%mo;
		}
	}
//	for(i=1;i<=m;++i)ans=(ans+1ll*mi[i]*f[i])%mo;
	for(i=1;i<=m;++i)ans=(ans+f[i])%mo;
	printf("%d\n",ans);
}

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

static const int N = 100;

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

	for (int l = 2; l <= n; ++l) {

		for (int i = 1; i <= n-l+1; ++i) {
			int j=i+l-1;
			m[i][j]=(1<<21);
			for (int k = i; k <= j-1; ++k) {
				m[i][j]=min(m[i][j],m[i][k]+m[k+1][j]+p[i-1]*p[k]*p[j]);
			}
		}
	}
	cout<<m[1][n]<<endl;
	return 0;
}

Measured memory_bytes: 3096
import sys
import os

ii = lambda: int(sys.stdin.buffer.readline().rstrip())
il = lambda: list(map(int, sys.stdin.buffer.readline().split()))
fl = lambda: list(map(float, sys.stdin.buffer.readline().split()))
iln = lambda n: [int(sys.stdin.buffer.readline().rstrip()) for _ in range(n)]

iss = lambda: sys.stdin.buffer.readline().decode().rstrip()
sl = lambda: list(map(str, sys.stdin.buffer.readline().decode().split()))
isn = lambda n: [sys.stdin.buffer.readline().decode().rstrip() for _ in range(n)]

MOD = 10 ** 9 + 7


def main():
    if os.getenv("LOCAL"):
        sys.stdin = open("input.txt", "r")

    N = iss()
    N = N.replace('1', 'b')
    N = N.replace('9', '1')
    N = N.replace('b', '9')
    print(N)


if __name__ == '__main__':
    main()


Measured memory_bytes: 3064
import java.io.*;
import java.math.BigInteger;
import java.util.*;

public class Main {

    private static PrintWriter out;

    private static <T> void mprintln(T ... ar){
        for(T i: ar) out.print(i + " ");
        out.println();
    }

    public static void main(String[] args) throws FileNotFoundException{

        // Input from file
        // File inputFile = new File("JavaFile.txt");
        // File outputFile = new File("JavaOutputFile.txt");
        // FileReader fileReader = new FileReader(inputFile);
        // Here it ends

        MyScanner sc = new MyScanner();
        // MyScanner sc = new MyScanner(fileReader);

        out = new PrintWriter(new BufferedOutputStream(System.out)); // Output to console
        // out = new PrintWriter(new PrintStream(outputFile)); // Output to file

        getAns(sc);

        out.close();
    }

    /*
     *Don't use builtin function (Math.ceil)
     */

    static final long MOD = (long) (1e9 + 7);

    private static void getAns(MyScanner sc){
        char[] ar = sc.nn().toCharArray();
        int[] count = new int[26];
        for(char ch: ar) count[ch - 'a']++;

        out.println(Arrays.stream(count).map(in -> in % 2).sum() == 0? "Yes": "No");
    }

    static class MyScanner{
        BufferedReader br;
        StringTokenizer st;

        MyScanner(FileReader fileReader){
            br = new BufferedReader(fileReader);
        }

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

        String nn(){
            while(st == null || !st.hasMoreElements()){
                try{
                    st = new StringTokenizer(br.readLine());
                }catch(IOException e){
                    e.printStackTrace();
                }
            }
            return st.nextToken();
        }

        String nextLine(){
            String ans = "";
            try {
                ans = br.readLine();
            } catch (IOException ex) {
                ex.printStackTrace();
            }
            return ans;
        }

        char nc(){
            return nn().charAt(0);
        }

        int ni(){
            return Integer.parseInt(nn());
        }

        long nl(){
            return Long.parseLong(nn());
        }

        double nd(){
            return Double.parseDouble(nn());
        }

        int[] niArr0(int n){
            int[] ar = new int[n];
            for(int i = 0; i < n; i++) ar[i] = ni();
            return ar;
        }

        int[] niArr1(int n){
            int[] ar = new int[n + 1];
            for(int i = 1; i <= n; i++) ar[i] = ni();
            return ar;
        }

        long[] nlArr0(int n){
            long[] ar = new long[n];
            for(int i = 0; i < n; i++) ar[i] = nl();
            return ar;
        }

        long[] nlArr1(int n){
            long[] ar = new long[n + 1];
            for(int i = 1; i <= n; i++) ar[i] = nl();
            return ar;
        }
    }
}

Measured memory_bytes: 26964
#include <bits/stdc++.h>
#define REP(i, s, n) for (int i = s; i < (int)(n); i++)
#define ALL(a) a.begin(), a.end()
#define MOD 1000000007
using namespace std;
using ll = long long;

int main() {
    int N; ll C; cin >> N >> C;
    vector<ll> X(N), V(N);
    REP(i, 0, N) cin >> X[i] >> V[i];


    vector<ll> R(N + 1, 0), Rmax(N + 1, 0); ll prev = 0;
    REP(i, 0, N) {
        R[i + 1] = R[i] + V[i] - (X[i] - prev);
        Rmax[i + 1] = max(R[i + 1], Rmax[i]);
        prev = X[i];
    }

    vector<ll> L(N + 1, 0), Lmax(N + 1, 0); prev = C;
    REP(i, 0, N) {
        L[i + 1] = L[i] + V[N - i - 1] - (prev - X[N - i - 1]);
        Lmax[i + 1] = max(L[i + 1], Lmax[i]);
        prev = X[N - i - 1];
    }

    ll ans = max(Rmax.back(), Lmax.back());
    REP(i, 0, N) {
        ans = max({
            ans,
            R[i + 1] - X[i] + Lmax[N - i - 1],
            L[i + 1] - (C - X[N - i - 1]) + Rmax[N - i - 1],
        });
    }
    cout << ans << endl;

    return 0;
}


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

int main()
{
  int n;
  cin>>n;
  int arr[n];
  float mean;
  int sum=0;
  for(int i=0;i<n;i++)
  {
    cin>>arr[i];
    sum+=arr[i];
  }
  
  mean=(float)sum/n;
  int p=round(mean);
  int ans=0;
  for(int i=0;i<n;i++)
  {
    ans+=(arr[i]-p)*(arr[i]-p);
  }
  cout<<ans<<"\n";
  return 0;
}

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

namespace Algorithm
{
    class Program
    {
        static void Main(string[] args)
        {
            var line = Console.ReadLine().Split().Select(z => int.Parse(z)).ToArray();
            int n = line[0], m = line[1];

            var k = Console.ReadLine().Split().Select(z => long.Parse(z)).ToArray();
            Array.Sort(k);

            var array = new int[m][];
            for (var i = 0; i < m; i++)
            {
                array[i] = Console.ReadLine().Split().Select(z => int.Parse(z)).ToArray();
            }
            array = array.OrderByDescending(o => o[1]).ToArray();

            var count = 0;
            var isLoop = true;
            for (var i = 0; i < m; i++)
            {
                for (var j = count; j < count + array[i][0]; j++)
                {
                    if (j >= k.Length || k[j] > array[i][1])
                    {
                        isLoop = false;
                        break;
                    }

                    k[j] = array[i][1];
                }

                if (!isLoop) break;
                count += array[i][0];
            }

            Console.WriteLine(k.Sum());
        }
    }
}


Measured memory_bytes: 32712
n = int(input())
if n < 10:
    print(n)
elif n < 100:
    print(9)
elif n < 1000:
    print(n - 90)
elif n < 10000:
    print(909)
elif n < 100000:
    print(n - 9090)
else:
    print(90909)


Measured memory_bytes: 2940
#include <bits/stdc++.h>
#define PI 3.1415926535897
using namespace std;
typedef long long ll;
const int INF = 1000000000;
const ll LINF = 1000000000000000000; //1e18
const double EPS = 1e-10;            //

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

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

    vector<bool> checker(N, true);
    checker[0] = false;
    int now = a[0] - 1;
    int cnt = 1;
    int ans = -1;
    while (cnt < N)
    {
        if (now == 1)
        {
            ans = cnt;
            break;
        }
        else if (checker[now] == true)
        {
            checker[now] = false;
            now = a[now] - 1;
            cnt++;
        }
        else
        {
            break;
        }
    }
    cout << ans << endl;
    return (0);
}

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

int main()
{
    string s;

    while(cin>>s)
    {
        int sz=s.size();

        for(int i=0;i<s.size()-1;i++)
        {
            if((s[i]=='0' && s[i+1]=='1') || (s[i]=='1' && s[i+1]=='0'))
            {
                s.erase(i,2);
                i-=2;

                if(i==-2)
                    i=-1;
            }
            if(s.size()<2)
                break;
        }

        cout<<sz-s.size()<<endl;
    }

    return 0;
}


Measured memory_bytes: 512
#include "bits/stdc++.h"
using namespace std;
using ll = long long; using ull = unsigned long long;
//#define int ll
using vb = vector<bool>; using vvb = vector<vb>;
using vi = vector<int>; using vvi = vector<vi>;
using vl = vector<ll>; using vvl = vector<vl>;
using pii = pair<int,int>; using pll = pair<ll,ll>;
#define FOR(i,a,b) for(ll i = (a); i < (ll)(b); ++i)
#define REP(i,n) FOR(i,0,n)
#define RFOR(i,a,b) for(ll i = (ll)(b)-1;i >= a;--i)
#define RREP(i,n) RFOR(i,0,n)
#define ALL(obj) (obj).begin(), (obj).end()
#define rALL(obj) (obj).rbegin(), (obj).rend()
#define eb(val) emplace_back(val)
const double PI = acos(-1);
const double EPS = 1e-10;
const ll MOD = 1e9+7;
void cioacc(){//accelerate cin/cout
  cin.tie(0);
  ios::sync_with_stdio(false);
}
int main(){
  int n;
  cin >> n;
  FOR(i,1,n+1){
    if(i%3==0){
      cout << " " << i;
      continue;
    }
    int x = i;
    while(x){
      if(x%10==3){
       cout << " " << i;
       break;
      }
      x /= 10;
    }
  }
  cout << endl;
}


Measured memory_bytes: 3108
#include <iostream>
#include <iomanip>

using namespace std;

int main(){
	int a, b;
	int d, r;
	double f;

	cin >> a >> b;

	d = a/b;
	r = a%b;
	f = (double)a/b;
 
	cout << d << " " << r << " " << fixed << setprecision(5) << f << endl; 

	return 0;
}

Measured memory_bytes: 3248
import math
import sys
from itertools import permutations
input = sys.stdin.readline

n,k=map(int,input().split())
arr=list(map(int,input().split()))

fin = 1000000000000
def check(x):
	global arr, n, k, fin
	# print("x",x)
	cur=0
	for i in range(n):
		cur+=(math.ceil(arr[i]/x)-1)
		# print(cur)
		if cur>k:
			return False
	
	return True

def bs(l, r):
	global arr, n, k, fin
	if r>=l:
		mid = l+(r-l)//2
		if check(mid):
			fin = min(fin, mid)
			bs(l, mid-1)
		else:
			bs(mid+1, r)

if k==0:
	print(max(arr))
else:
	bs(1, max(arr))
	print(fin)

Measured memory_bytes: 92316
#include<bits/stdc++.h>
using namespace std;
#define lowbit(x) ((x)&(-x))
typedef long long LL;

void run_case() {
    double H, A;
    cin >> H >> A;
    cout << (int)ceil(H/A);
}

int main() {
    ios::sync_with_stdio(false), cin.tie(0);
    run_case();
    //cout.flush();
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <math.h>
#include <algorithm>
#include <stdint.h>
#include <queue>
#include <bitset>
#include <iomanip>
#define PI (3.14159265358979323846)
#define INF (1e+9)
#define DIV_NUM (1000000007)

using namespace std;

int main()
{

	/*--------------------------------*/
		/* 数字宣言と入力*/
	int N,a,i;
	cin >> N;
	vector<int> vecX(N);
	
  	a=1;
	for (i=0;i<N;i++){
      cin >> vecX[i];
      if(vecX[i]%2==0){
        if(vecX[i]%3==0 ||vecX[i]%5==0){
        }
        else{
          	a=0;
          	cout <<"DENIED"  << endl;
          	break;
        }
      }
      
    }	

  	if(a==1){
      		cout <<"APPROVED"  << endl; 
    }

 
		
	//cout << vecX[0] << " " << vecX[1] << " " << vecX[2] << endl;


	/*----------------------------------*/
	return 0;
}

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

signed main() {
  int n, k;
  cin >> n >> k;
  bool sunuke[100] = {0};
  int count = n;
  for(int i = 0; i < k; i++){
    int d;
    cin >> d;
    for(int j = 0; j < d; j++){
      int a;
      cin >> a;
      if(!sunuke[a]){
        count--;
        sunuke[a] = true;
      }
    }
  }

  cout << count << endl;

}

Measured memory_bytes: 3672
#include <iostream>
#include <iomanip>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <complex>
#include <map>
#include<unordered_map>
#include <set>
#include <queue>
#include <stack>
#include <vector>
#include<bitset>
#include<deque>
#include<string>
#include<list>
#include<iterator>
#include<sstream>
#include <algorithm>
#include <numeric>
#include <math.h>

#define lli long long int
#define ld long double
#define lower(a) transform(a.begin(),a.end(),a.begin(),::tolower);

using namespace std;

const int N = 3e5 + 500;
const long long mod = 1e9 + 7;
const long long cmod = 998244353 ;
const long long inf = 1LL << 61;
const int M = 1e6 + 500;
const lli ths = 1LL << 40;
const int NN = 5e3 + 6;

void solve()
{
    lli n, r;
    cin>>n>>r;
    lli ans;
    if(n >= 10)
        ans = r;
    else {
        ans = r + 100 * (10 - n);
    }
    cout<<ans;
    cout<<'\n';
    return ;
}



/*
*/

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

    int t = 1;
//    cin>>t;
    while(t --)
    {
        solve();
    }
    return 0;
}


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

using ll = long long;
using pii = pair<int,int>;

#define REP(i,n) for(int i=0; i<n; i++)
#define FOR(i,a,b) for(int i=a; i<b; i++)
#define FORR(i,a,b) for(int i=b-1;i>=a;i--)

#define DEBUG(x) cerr<<#x<<": "<<(x)<<endl

#define ALL(v) (v).begin(),(v).end()

int n;
vector<pii> g[830];

int memo[830];
int dfs0(int p, int bef){
    memo[p] = 0;
    for(pii P : g[p]){
        int to = P.first; int d = P.second;
        if(to==bef)continue;
        memo[to] = 0;
        if(g[to].size()==1){
            memo[p] += d;
        }else{
            memo[p] += d+dfs0(to,p)+d+d;
        }
    }
    return memo[p];
}

int dfs(int p, int bef){
    // DEBUG(p);DEBUG(bef);
    int sum = memo[p];
    int ans = sum;
    // DEBUG(sum);
    for(pii P : g[p]){
        int to = P.first; int d = P.second;
        if(to==bef)continue;
        if(g[to].size()==1)continue;
        ans = min(ans, (sum-memo[to]-d-d-d)+d+d+dfs(to,p));
    }
    return ans;
}

int pp[830], dd[830];

int main(){
    while(true){
        cin>>n;
        if(n==0)break;
        REP(i,n)g[i].clear();
        FOR(i,1,n)cin>>pp[i];
        FOR(i,1,n)cin>>dd[i];
        FOR(i,1,n){
            int p=pp[i],d=dd[i];
            --p;
            g[i].push_back(pii(p,d));
            g[p].push_back(pii(i,d));
        }
        int ans = 1<<30;
        REP(i,n){
            dfs0(i,-1);
            ans = min(ans, dfs(i,-1));
        }
        cout<<ans<<endl;
        // break;
    }
    return 0;
}



Measured memory_bytes: 3192
#include <iostream>

using namespace std;

int main() {
    int a, b;
    cin >> a >> b;
    if (a < b) {
        for (int i = 0; i < b; i++) {
            cout << a;
        }
    }
    else {
        for (int i = 0; i < a; i++) {
            cout << b;
        }
    }
}

Measured memory_bytes: 256
#include <iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<map>
#include<set>
#include<stack>
#include<queue>
#include<math.h>
using namespace std;
typedef long long ll;
#define int long long
#define double long double
typedef vector<int> VI;
typedef pair<int, int> pii;
typedef vector<pii> VP;
typedef vector<string> VS;
typedef priority_queue<int> PQ;
template<class T>bool chmax(T &a, const T &b) { if (a < b) { a = b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b < a) { a = b; return 1; } return 0; }
#define fore(i,a) for(auto &i:a)
#define REP(i,n) for(int i=0;i<n;i++)
#define eREP(i,n) for(int i=0;i<=n;i++)
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define eFOR(i,a,b) for(int i=(a);i<=(b);++i)
#define SORT(c) sort((c).begin(),(c).end())
#define rSORT(c) sort((c).rbegin(),(c).rend())
#define LB(x,a) lower_bound((x).begin(),(x).end(),(a))
#define UB(x,a) upper_bound((x).begin(),(x).end(),(a))
#define INF 1000000000
#define LLINF 9223372036854775807
#define mod 1000000007
#define eps 1e-12 
//priority_queue<int,vector<int>, greater<int> > q2;
int N;
int G[300][300];

void warshall() {
	REP(i, N + 2) {
		REP(j, N + 2) {
			REP(k, N + 2) {
				G[j][k] = min(G[j][k], G[j][i] + G[i][k]);
			}
		}
	}
}


string solve(int M) {
	cin >> N;

	VI D(N);
	REP(i, N)cin >> D[i];
	queue<int>Q;
	vector<bool>F(N + 1, false);
	F[0] = 1;
	Q.push(0);
	while (!Q.empty()) {
		int from = Q.front(); Q.pop();
		eFOR(i, 1, M) {
			int to = from + i;
			if (to > N + 1)break;
			if (to == N + 1) {
				//G[from].push_back(to);
				G[from][to] = 1;
			}
			else {
				to += D[to - 1];
				if (to < 0)to = 0;
				if (to > N + 1)to = N + 1;
				//if (from != to) {
					//G[from].push_back(to);
					//cout << from << " " << to << endl;
					G[from][to] = 1;
					if (!F[to]) {
						F[to] = 1;
						Q.push(to);
					}
				//}
			}
		}
	}
	warshall();
	eREP(i, N) {
		//cout << i + 1 << " " << G[0][i + 1] << " " << G[i + 1][N + 1] << endl;
		if (G[0][i] != INF && G[i][N + 1] == INF) {
			//cout << i + 1 << endl;
			return "NG";
		}
	}
	return "OK";
}

signed main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	
	int M = 1;
	while (M) {
		REP(i, 300)REP(j, 300)G[i][j] = INF;
		cin >> M;
		if (!M)return 0;
		cout << solve(M) << '\n';
	}

	return 0;
}




Measured memory_bytes: 3896
import java.util.Scanner;

public class Main {	
	public static void main(String[] args) {
		try(Scanner sc = new Scanner(System.in)) {
			while(true) {
				int e = sc.nextInt();
				if(e == 0)	break;

				int ee= 1 << 30;
				for(int z=0;;z++) {
					int yx = e - z*z*z;
					if(yx < 0) break;
					for(int y=0; y*y <= yx; y++) {
						int x = yx -y*y;
						ee = Math.min(ee, x+y+z);
					}
				}
				
				
				System.out.println(ee);
			}
				
		}
	}
}


Measured memory_bytes: 34348
// D - Walk and Teleport
#include <bits/stdc++.h>
using namespace std;
using ll = long long;

int main(){
	int n,a,b; cin>>n>>a>>b;
	ll cur = 0, nxt = 0;
	int xi,xj; cin>>xj;
	for(int i=0; i<n-1; i++){
		xi = xj; cin>>xj;
		nxt = cur + min((ll)b, (ll)(xj-xi)*a);
		cur = nxt;
	}
	cout<< cur <<endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(void){
  int a,b,c;
  string k;
  cin >> a >> b >> c >> k;
  if ((int)k.at(k.size()-1)%2) cout << b-a << endl;
  else cout << a-b << endl;
  return 0;
}

Measured memory_bytes: 256