akhauriyash/Code-Regression huggingface dataset:
from collections import Counter
import sys
sys.setrecursionlimit(10**7)
n, k = map(int, input().split())
A = list(map(lambda x: int(x)-1, input().split()))

# A[0]から出発して何回でループするか数える

visited = [0]*n


def dfs(v):
    if visited[v]+1 == 3:
        return 0
    visited[v] += 1
    dfs(A[v])


dfs(0)

c = Counter(visited)
loop_cnt = c[2]
init_cnt = c[1]
k_ = k-init_cnt
k_ %= loop_cnt

cnt = 0
visited = [0]*n


ans = 0
loop = k if k < init_cnt else k_+init_cnt
for _ in range(loop):
    ans = A[ans]
print(ans+1)


Measured memory_bytes: 309388
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define PI 3.141592653589793
#define rep(i, n) for (int i = 0; i < (n); i++)
#define REP(i, a, n) for (int i = a; i < (n); i++)
#define rrep(i, n, k) for (int i = (n); i >= (k); i--);
#define all(x) (x).begin(), (x).end()
#define vi vector<int>
template<class T> istream &operator>>(istream&is,vector<T>&v){for(auto &elemnt:v)is>>elemnt;return is;}
template<class T,class U> istream &operator>>(istream&is,pair<T,U>&p){is>>p.first>>p.second;return is;}
template<class T>vector<T> make_vector(size_t a){return vector<T>(a);}
template<class T, class... Ts>auto make_vector(size_t a, Ts... ts){return vector<decltype(make_vector<T>(ts...))>(a, make_vector<T>(ts...));}
const int mod = 1e9 + 7;
const int inf = 2e18;

signed main() {
    int N, K;
    cin >> N >> K;
    vector<int> h(N);
    cin >> h;
    vector<int> dp(N + 1, inf);
    dp[0] = 0;
    for (int i = 0; i < N - 1; i++) {
        for (int j = 1; j <= K; j++) {
            if (i + j < N) dp[i + j] = min(dp[i + j], dp[i] + abs(h[i] - h[i + j]));
        }
    }
    cout << dp[N - 1] << endl;
}



Measured memory_bytes: 1792
#include "bits/stdc++.h"
using namespace std;
#define rep(i,a,b) for(int i=(a);i<(b);i++)
const int INF = 0x3f3f3f3f;

void solve(int N) {
	vector<string>s(N);
	rep(i, 0, N) {
		cin >> s[i];
	}
	auto is_boin = [](char c) {
		return c == 'a' or c == 'i' or c == 'u' or c == 'e' or c == 'o';
	};
	vector<string>t(N);
	rep(i, 0, N) {
		string tmp;
		tmp.push_back(s[i][0]);
		rep(x, 0, s[i].size() - 1) {
			if (is_boin(s[i][x])) {
				tmp.push_back(s[i][x + 1]);
			}
		}
		t[i] = tmp;
		//cout << tmp << endl;
	}

	// check possible
	{
		set<string>st;
		rep(i, 0, N) {
			st.insert(t[i]);
		}
		if (st.size() != N) {
			cout << -1 << endl;
			return;
		}
	}
	int l = 0, r = 100;
	while (r - l > 1) {
		int mid = (l + r) / 2;
		set<string>st;
		rep(i, 0, N) {
			st.insert(t[i].substr(0, min(mid,(int)t[i].size())));
		}
		if (st.size() == N) {
			r = mid;
		}
		else {
			l = mid;
		}
	}
	cout << r << endl;
}

signed main() {
	int N;
	while (cin >> N, N) {
		solve(N);
	}
	return 0;
}


Measured memory_bytes: 3156
N = int(input())
s = [int(input()) for _ in range(N)]

s = list(sorted(s))

ss = sum(s)
idx = 0
while ss % 10 == 0:
    while s[idx] % 10 == 0:
        idx += 1
        if idx == N:
            break
    else:
        ss -= s[idx]
        idx += 1
        continue
    break
print(ss if ss % 10 !=0 else 0)


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

int main(){
	double x1;
	double y1;
	double x2;
	double y2;
	double l;
	double x;
	double y;
	cin >> x1;
	cin >> y1;
	cin >> x2;
	cin >> y2;
	x = x1 - x2;
	y = y1 - y2;
	l = x*x + y*y;
	cout << fixed << sqrt(l) << endl;
	return 0;
}

Measured memory_bytes: 1280
#include <stdio.h>

int main(){
    int x,y,r,tmp;

    scanf("%d%d",&x,&y);

    if (x<y) {
        tmp=x;
        x=y;
        y=tmp;
    }

    while(1){
        r=x%y;
        if (r == 0) break;
        x=y;
        y=r;
    }
    printf("%d\n",y);

    return 0;
}



Measured memory_bytes: 2084
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
using vi=vector<int>;
using P = pair<int,int>;
using Graph = vector<vector<int>>;
template<typename T> void ndarray(vector<T> &vec, int len) { vec.resize(len); }
template<typename T, typename... Args> void ndarray(vector<T> &vec, int len, Args... args) { vec.resize(len); for (auto &v : vec) ndarray(v, args...); }



//mod逆元を使ったnCkの計算(速)
const int64_t MAX = 3000010;
const int64_t MOD = 1000000007;
 
int64_t fac[MAX], finv[MAX], inv[MAX];
 
// テーブルを作る前処理
void COMinit() {
  fac[0] = fac[1] = 1;
  finv[0] = finv[1] = 1;
  inv[1] = 1;
  for (int i = 2; i < MAX; i++){
    fac[i] = fac[i - 1] * i % MOD;
    inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
    finv[i] = finv[i - 1] * inv[i] % MOD;
  }
}
 
// 二項係数計算
int64_t COM(int64_t n, int64_t k){
  if (n < k) return 0;
  if (n < 0 || k < 0) return 0;
  return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}
 
//繰り返し二乗法
int64_t powmod(int64_t x, int64_t n) { 
  int64_t ans = 1;
  while (n > 0) {
    if ((n & 1) == 1) {
      ans = ans * x;
      ans %= MOD;
    }
    x = x * x;//一周する度にx, x^2, x^4, x^8となる
    x %= MOD;
    n >>= 1; //桁をずらす n = n >> 1
  }
  return ans;
}

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int64_t k,n,ans=0;
    string s;
    COMinit();
    cin >> k >> s;
    n=s.size();
    rep(i,k+1){
        int64_t now = powmod(26,k-i);
        now %= MOD;
        now *= powmod(25,i);
        now %= MOD;
        now *= COM(i+n-1,n-1);
        now %= MOD;
        ans += now;
        ans %= MOD;
    }
    cout << ans << "\n";
    return 0;
}

Measured memory_bytes: 74564
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef vector<ll> vl;
typedef pair<ll, ll> PP;
#define rep(i, n) for(ll i = 0; i < ll(n); i++)
#define all(v) v.begin(), v.end()
bool chmin(ll & a, ll  b) { if (b < a) { a = b; return 1; } return 0; }
bool chmax(ll & a, ll b) { if (b > a) { a = b; return 1; } return 0; }
const ll INF = 999999999999999;
const ll MOD = 1000000007;
const ll MAX_N=500010;
ll a, b, c, d, e, f, p, t, x, y, z, q, m, n, r, h, k, w, l, ans;
int main() {
    cin>>n;
	string s;
	vl B;
	vector<string> A;
	rep(i,n){
cin>>s>>a;
A.push_back(s);
B.push_back(a);
	}
		cin>>s;
		a=0;
	rep(i,n){
		ans+=a*B[i];
		if(A[i]==s)a++;
	}

	cout<<ans<<endl;
}

Measured memory_bytes: 256
N = gets.to_i

def fetch_prime_list(max)
    table = Array.new(max + 1,true)
    prime_list = []

    (2..max).each do |num|
        if table[num] == true
          prime_list << num if num % 5 == 1
          k = num * num
            while k <= max
                table[k] = false
                k += num
            end
        end
    end

    return prime_list
  end

list = fetch_prime_list(55555)

puts list[0...N].join(" ")


Measured memory_bytes: 2172
import java.util.*;
public class Main {

	private static final int m = 0;
	public static void main(String[] args) {
 Scanner sc=new Scanner(System.in);
long 	n=sc.nextLong();
long m=sc.nextLong();
long ans=0;

ans=Math.min(n,(long)m/2);

m=m-(ans*2);
if(m/4>=1) {
	ans+=m/4;
}
		System.out.println(ans);
	}
}

Measured memory_bytes: 35672
#include<stdio.h>
#include<string.h>
#include<ctype.h>

int main(void)
{
    char W[10], T[1000];
    int i, count = 0;
    
    scanf("%s", &W);
    for(i=0;;i++){
        W[i] = toupper(W[i]);
        if(W[i] == '\0'){
            break;
        }
    }
    
    while(1){
        scanf("%s", &T);
        if(strcmp(T, "END_OF_TEXT") == 0){
            break;
        }
        for(i=0;;i++){
            T[i] = toupper(T[i]);
            if(T[i] == '\0'){
                break;
            }
        }
        if(strcmp(T, W) == 0){
            count++;
        }
    }
    printf("%d\n", count);
    
    return 0;
}

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

int main() {
	int n;
	cin >> n;
	double h[40], count1=0, count2=0, count3=0, count4=0, count5=0, count6=0;
	for(int i=0; i<n; i++){
		cin >> h[i];
		if(h[i]<165.0) count1++;
		if(h[i]>=165.0 && h[i]<170.0) count2++;
		if(h[i]>=170.0 && h[i]<175.0) count3++;
		if(h[i]>=175.0 && h[i]<180.0) count4++;
		if(h[i]>=180.0 && h[i]<185.0) count5++;
		if(h[i]>=185.0) count6++;
	}
	cout << "1:";
	for(int a=0; a<count1; a++){
		cout << "*";
	}
	cout << endl;
	cout << "2:";
	for(int b=0; b<count2; b++){
		cout << "*";
	}
	cout << endl;
	cout << "3:";
	for(int c=0; c<count3; c++){
		cout << "*";
	}
	cout << endl;
	cout << "4:";
	for(int d=0; d<count4; d++){
		cout << "*";
	}
	cout << endl;
	cout << "5:";
	for(int e=0; e<count5; e++){
		cout << "*";
	}
	cout << endl;
	cout << "6:";
	for(int f=0; f<count6; f++){
		cout << "*";
	}
	cout << endl;
	return 0;
}


Measured memory_bytes: 3160
using System;
using System.Collections.Generic;
using System.Linq;
 
public class B {
    public static void Main(){
        int[,] A = new int[3,3];
        bool[,] sheet = new bool[3,3];
        for (int i=0;i<3;i++)
        {
            string[] line = Console.ReadLine().Split(' ');
            for (int j=0;j<3;j++)
            {
                A[i,j] = int.Parse(line[j]);
                sheet[i,j] = false;
            }
        }
        int N = int.Parse(Console.ReadLine());
        for (int i=0;i<N;i++)
        {
            int b = int.Parse(Console.ReadLine());
            for (int j=0;j<3;j++)
            {
                for (int k=0;k<3;k++)
                {
                    if (A[j,k]==b)
                    {
                        sheet[j,k] = true;
                    }
                }
            }
        }
        
        if (isBingo(sheet)) Console.WriteLine("Yes");
        else Console.WriteLine("No");
    }
    
    private static bool isBingo(bool[,] sheet)
    {
        for (int i=0;i<3;i++)
        {
            bool isBingoYoko = true;
            for (int j=0;j<3;j++)
            {
                if (!sheet[i,j])
                {
                    isBingoYoko = false;
                }
            }
            if (isBingoYoko) return isBingoYoko;
        }
        
        for (int i=0;i<3;i++)
        {
            bool isBingoTate = true;
            for (int j=0;j<3;j++)
            {
                if (!sheet[j,i])
                {
                    isBingoTate = false;
                }
            }
            if (isBingoTate) return isBingoTate;
        }
        
        if (sheet[0,0]&&sheet[1,1]&&sheet[2,2]) return true;
        if (sheet[0,2]&&sheet[1,1]&&sheet[2,0]) return true;
        
        return false;
    }
}

Measured memory_bytes: 13140
/**
 * code generated by JHelper
 * More info: https://github.com/AlexeyDmitriev/JHelper
 * @author Yulian
 */

#include <iostream>
#include <iostream>
#include <fstream>
#include <vector>
#include <set>
#include <cmath>
#include <queue>
#include <deque>
#include <string>
#include <algorithm>
#include <map>


#include <iostream>

#include <fstream>
#include <vector>
#include <set>
#include <cmath>
#include <queue>
#include <deque>
#include <string>
#include <algorithm>
#include <map>



int getTheAnswer() {
    return 42;
}

template< class InputIt>
void incAll(const InputIt &first, const InputIt &last){
  for(auto it = first; it != last; ++it){
    ++*it;
  }
}

template <class InputIt>
void printAll(const InputIt &first, const InputIt &last, std::ostream& out){
  for(InputIt it = first; it != last; ++it){
    out << *it << " ";
  }
}

// only for positive integers
int gcd(int a, int b){
  int tmp;
  if(a < b){
    tmp = a;
    a = b;
    b = tmp;
  }
  while(b != 0){
    tmp = a;
    a = b;
    b = tmp % b;
  }
  return a;
}

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


using namespace std;
class TaskB {
public:
	void solve(std::istream& in, std::ostream& out) {
    ios::sync_with_stdio(false);
    string s;
    in >> s;
    out << (s.rfind('Z') - s.find('A') + 1) << endl;
	}
};


int main() {
	TaskB solver;
	std::istream& in(std::cin);
	std::ostream& out(std::cout);
	solver.solve(in, out);
	return 0;
}


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

#define F first 
#define S second
#define PB push_back

using namespace std;

typedef long long LL;
typedef pair<int, int> PII;
typedef priority_queue<int> HEAP;
typedef priority_queue<int, vector<int>, greater<int> > RHEAP;

const int N = 100010, M = 1010;

int n, m;
PII a[N];
HEAP heap;

int main()
{
	scanf("%d%d", &n, &m);
	for (int i = 0; i < n; i ++ ) scanf("%d%d", &a[i].F, &a[i].S);
	sort(a, a + n);
	
	int res = 0;
	for (int i = 1, j = 0; i <= m; i ++ )
	{
		while (j < n && a[j].F == i)
		{
			heap.push(a[j].S);
			j ++ ;
		}
		
		if (heap.size())
		{
			res += heap.top();
			heap.pop();
		}
	}
	printf("%d\n", res);
    return 0;
}

Measured memory_bytes: 4668
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
#define endl "\n";
#define FAST ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
ll dp[1001][1001];
int MOD = 1e9+7;

int main(){

    FAST;
    ll h,w;
    cin>>h>>w;
    char a[h][w];
    for(ll i=0;i<h;i++)
    for(ll j=0;j<w;j++)
    cin>>a[i][j];

    memset(dp,-1,sizeof(dp));
    
    for(ll i=0;i<h;i++)
    {
        if(a[i][0]=='#'){
        for(ll j=i;j<h;j++)
        {
            dp[j][0]=0;
        }
        break;
        }
        else
        {
            dp[i][0]=1;
        }
        
    }
    for(ll i=0;i<w;i++)
    {
        if(a[0][i]=='#'){
        for(ll j=i;j<w;j++)
        dp[0][j]=0;
        break;
        }
        else
        {
            dp[0][i]=1;
        }
        
    }

    for(ll i=1;i<h;i++){
        for(ll j=1;j<w;j++){
            dp[i][j]= (a[i][j]=='#')?0:(dp[i-1][j]+dp[i][j-1])%MOD;
        }
    }
    cout<<dp[h-1][w-1]<<'\n';

    return 0;
}

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

#define fir first
#define sec second
using namespace std;
typedef long long LL;

template <typename T> inline bool cmin(T & a, const T & b) { return a > b ? a = b, 1 : 0;}
template <typename T> inline bool cmax(T & a, const T & b) { return a < b ? a = b, 1 : 0;}
int inp() {
	int x = 0, f = 1;char ch;
	for(ch = getchar(); !isdigit(ch); ch = getchar())
		if(ch == '-') f = -1;
	for(; isdigit(ch); x = x * 10 + ch - '0', ch = getchar());
	return x * f;
}
const int MaxN = 101234;
int n, K, a[MaxN];

int main() {
	int i, g;
	n = inp(); K = inp();
	for(i = 1; i <= n; i++) a[i] = inp();
	for(g = a[i = 1]; i <= n; i++) g = __gcd(g, a[i]);
	if(K % g == 0 && *max_element(a + 1, a + n + 1) >= K)
		puts("POSSIBLE");
	else 
		puts("IMPOSSIBLE");
	return 0;
}




Measured memory_bytes: 640
// https://atcoder.jp/contests/abc147/submissions/8853537
// https://outline.hatenadiary.jp/entry/2019/12/17/021530
#include <iostream>
#include <string>
#include <vector>
#include <utility>
#include <queue>
#include <deque>
#include <stack>
#include <algorithm>
#include <bitset>
#include <cstdio>
#include <cmath>

using namespace std;

int main() {
    int n, r;
    cin >> n >> r;

    int ans;
    if (n >= 10) ans = r;
    else ans = r+100*(10-n);

    cout << ans << endl;
}


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

typedef complex<double> Point, Vector;
typedef pair<Point, Point> Segment, Line;
typedef vector<Point> Polygon;

#define X real()
#define Y imag()
#define EPS (1e-10)
#define equals(a, b) (fabs((a) - (b)) < EPS)

double dot(Vector a, Vector b){
    return a.X * b.X + a.Y * b.Y;
}

double cross(Vector a, Vector b){
    return a.X * b.Y - a.Y * b.X;
}

static const int COUNTER_CLOCKWISE = 1;
static const int CLOCKWISE = -1;
static const int ONLINE_BACK = 2;
static const int ONLINE_FRONT = -2;
static const int ON_SEGMENT = 0;

// ベクトルと点の位置関係
int ccw(Point p0, Point p1, Point p2){
    Vector a = p1 - p0;
    Vector b = p2 - p0;
    if(cross(a, b) > EPS) return COUNTER_CLOCKWISE;
    if(cross(a, b) < -EPS) return CLOCKWISE;
    if(dot(a, b) < -EPS) return ONLINE_BACK;
    if(norm(a) < norm(b)) return ONLINE_FRONT;

    return ON_SEGMENT;
}

Point getCrossPointLL(Line l1, Line l2){
    double a = cross(l1.second - l1.first, l2.second - l2.first);
    double b = cross(l1.second - l1.first, l1.second - l2.first);
    if(abs(a) < EPS && abs(b) < EPS) return l2.first;
    return l2.first + (l2.second - l2.first) * (b / a);
}

Polygon convexCut(Polygon pol, Line l){
    Polygon q;
    int n = pol.size();
    for(int i=0; i<n; i++){
        Point a = pol[i];
        Point b = pol[(i+1)%n];
        if(ccw(l.first, l.second, a) != CLOCKWISE) q.emplace_back(a);
        if(ccw(l.first, l.second, a) * ccw(l.first, l.second, b) < 0){
            q.emplace_back(getCrossPointLL(Line(a, b), l));
        }
    }

    return q;
}

double convexArea(Polygon pol){
    int n = pol.size();
    if(n == 0) return 0.0;
    Point basep = pol[0];

    double S = 0.0;
    for(int i=1; i<n-1; i++){
        Vector a = pol[i] - basep;
        Vector b = pol[i+1] - basep;
        S += cross(a, b) / 2;
    }

    return S;
}

int main(){
    int n; cin>>n;
    Polygon pol;
    for(int i=0; i<n; i++){
        double x, y; cin>>x>>y;
        pol.emplace_back(x, y);
    }

    int q; cin>>q;
    while(q--){
        double x1, y1, x2, y2; cin>>x1>>y1>>x2>>y2;
        Line l1 = {Point(x1, y1), Point(x2, y2)};
        Polygon fipol = convexCut(pol, l1);
        printf("%.10f\n", convexArea(fipol));
    }
}


Measured memory_bytes: 3264
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cstring>
#include <vector>
#include <list>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <bitset>
#include <algorithm>
#include <functional>
#include <assert.h>
#include <iomanip>
using namespace std;
const int N = 1e5 + 5;
// const int M = 1005;
const int INF = 0x3f3f3f3f;
const int MOD = 1000000007;
typedef long long ll;

int Y[N], P[N];
vector<int> year[N];
int main() {
    int n, m;
    while(~scanf("%d %d", &n, &m)) {
        for(int i = 1; i <= n; ++i) year[i].clear();
        for(int i = 0; i < m; ++i) {
            scanf("%d %d", &P[i], &Y[i]);
            year[P[i]].push_back(Y[i]);
        }

        for(int i = 1; i <= n; ++i) {
            sort(year[i].begin(), year[i].end());
        }

        for(int i = 0; i < m; ++i) {
            int id = lower_bound(year[P[i]].begin(), year[P[i]].end(), Y[i]) - year[P[i]].begin();
            printf("%06d%06d\n", P[i], id + 1);
        }
        
        
    }
    return 0;
}

Measured memory_bytes: 7808
n = int(input())
h = [int(x) for x in input().split()]
l = len(h)
h.append(10 ** 9 + 1)
flag = 0
for i in range(l):
    if h[i] - h[i+1] > 1:
        print("No")
        exit()
    elif h[i] - h[i+1] == 1:
        if flag == 1:
            print("No")
            exit()
        else:
            flag = 1
    elif h[i] - h[i+1] < 0:
        flag = 0
print("Yes")

Measured memory_bytes: 14224
import sys
read = sys.stdin.buffer.read
from fractions import gcd
from functools import reduce

n,m,*alst = list(map(int,read().split()))
mm=2*m
def lcm(x,y):
  g=gcd(x,y)
  if x//g %2==0 or y//g%2==0:
    return 0
  g=x*y//g
  if g>mm:
    return 0
  return g
g=reduce(lcm,alst)
if g==0:
  print(0)
  quit()
else:
  res=(mm//g)
  print(res//2+res%2)


Measured memory_bytes: 14508
use List::Util qw(min);

my $n = glob<>;
push(@h, glob<>);

for (my $i = 0; $i < $n; $i++) {
    if ($i == 0) {
        push(@m1, 0);
        push(@m2, 0);
        next;
    }

    if ($i == 1) {
        push(@m1, abs($h[$i-1] - $h[$i]));
        push(@m2, ~0);
        next;
    }

    push(@m1, min($m1[$i-1] + abs($h[$i-1] - $h[$i]),
                  $m1[$i-2] + abs($h[$i-2] - $h[$i])));
    push(@m2, min($m2[$i-1] + abs($h[$i-1] - $h[$i]),
                  $m2[$i-2] + abs($h[$i-2] - $h[$i])));
}

print (min($m1[$n-1], $m2[$n-1]));

Measured memory_bytes: 29960
#include<bits/stdc++.h>
    using namespace std;
    int main(){
      int n;
      cin >> n;
      vector<int> cnt(n + 1, 0);
      for(int i = 1; i < n; i++){
        int a;
        cin >> a;
        cnt[a]++;
      }
      for(int i = 1; i <= n; i++)
        cout << cnt[i] << endl;
      return 0;
    }

Measured memory_bytes: 4048
#include<stdio.h>
int main(){
  int n,m,i,j,l,mi,mj,min,a,b,e;
  int c[2][110]={0};
  while(scanf("%d %d",&n,&m),n||m){
    int d[110][110]={0};
    while(m--){
      scanf("%d %d %d",&a,&b,&e);
      d[a][b]=d[b][a]=e;
    }
    for(i=2;i<=n;i++)c[0][i]=c[1][i]=100000000;
    c[0][1]=c[1][1]=0;
    //for(k=0;k<2;k++){
    mi=1;
    mj=0;
    int f[2][110]={0};
    for(i=0;i<n*2;i++){
      f[mj][mi]=1;
      for(j=1;j<=n;j++){
	if(d[mi][j]==0)continue;
	if(c[mj][j]>c[mj][mi]+d[mi][j])c[mj][j]=c[mj][mi]+d[mi][j];
	if(mj)continue;
	for(l=1;l<=n;l++){
	  if(d[j][l]==0)continue;
	  if(c[1][l]>c[0][mi])c[1][l]=c[0][mi]; 
	}
      }
      min=2100000000;
      for(l=0;l<2;l++){
	for(j=1;j<=n;j++){
	  if(f[l][j])continue;
	  if(min>c[l][j])min=c[mj=l][mi=j];
	}
      }
      //for(j=1;j<=n;j++)printf("%d ",c[k][j]);printf("\n");
    }
    printf("%d\n",c[1][n]);
  }
  return 0;
}

Measured memory_bytes: 656
#include <bits/stdc++.h>
using namespace std;
int main(){
	string input;
	while(1){
		getline(cin,input);
		if(input.length()==1&&input[0]=='.')break;
		stack<bool> data;
		bool f=true;
		for(int i=0;i<input.length();i++){
			if(input[i]=='[')data.push(true);
			if(input[i]==']'){
				if(data.empty()||!data.top()){
					f=false;
					break;
				}else data.pop();
			}
			if(input[i]=='(')data.push(false);
			if(input[i]==')'){
				if(data.empty()||data.top()){
					f=false;
					break;
				}else data.pop();
			}
		}
		if(f&&data.empty()){
			cout<<"yes"<<endl;
		}else{
			cout<<"no"<<endl;
		}
	}
}

Measured memory_bytes: 1176
import java.util.Scanner;

public class Main {

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

		int count = 0;
		String S = scan.next();
		char str [] = new char [S.length()] ;

		for (int i = 0;i < S.length();i++) {
			str[i] = S.charAt(i) ;
		}

		for (int i = 0; i < S.length() ;i++) {
			for (int j =i+1; j < S.length(); j++) {
				if (str[i] == str[j]) {
				count++;
				}
			}
		}
		if (count == 2) {
			System.out.println("Yes");
		} else {
			System.out.println("No");
		}

	}
}

Measured memory_bytes: 21844
a,b,c,x,y=map(int,input().split())
ans=a*x+b*y
if x>y:
    p=2*y*c+(x-y)*min(a,2*c)
    ans=min(ans,p)
if x<=y:
    p=2*x*c+(y-x)*min(b,2*c)
    ans=min(ans,p)
print(ans)


Measured memory_bytes: 61900
#include<bits/stdc++.h>
using namespace std;
#define int long long
const int mod=1e9+7;
string s;
int k;
void add(int &a, int b)
{
	a+=b;
	if(a>=mod)
		a-=mod;
}
signed main()
{
	ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
	cin>>s>>k;
	int n=s.length();
	vector<vector<int>> dp(k, vector<int>(2));
	/* dp[i][j], where i = number of digits processed so far, j = bound or not(0-> bound, 1->not bound);*/

	dp[0][1]=1;
	for(int idx=0; idx<n; ++idx)
	{
		vector<vector<int>> new_dp(k, vector<int>(2));
		for(int sum=0; sum<k; ++sum)
		{
			for(bool bound : {true, false}){
				for(int newdig=0; newdig<=9; ++newdig)
				{
					if(newdig>(s[idx]-'0') and bound)
						break;
					add(new_dp[(sum+newdig)%k][bound and (newdig==(s[idx]-'0'))], dp[sum][bound]);
				}
			}
		}
		dp=new_dp;
	}
	int ans = (dp[0][0]+dp[0][1])%mod-1;
	if(ans==-1)
		ans=mod-1;
	cout<<ans;


	return 0;	
}

Measured memory_bytes: 3636
#include<iostream>
#include<vector>
#include<string>
#include <queue>
#include<map>
#include <cstring>
using namespace std;
#define ll long long int
#define pi pair<int , pair<int , int> >
ll n , m ;
bool check(int i , int j , vector<vector<char> >&v , vector<vector<bool> > &vis)
{
      return (i >= 0 && i < n && j >= 0 && j < m && !vis[i][j] && v[i][j] == '.' ) ;
}
int main()
{
    ll  x1 , x2 , y1 , y2;
    cin>>n>>m ;
    cin>>x1>>y1 ;
    cin>>x2>>y2 ;
    x1-- ;
    x2--;
    y1--;
    y2-- ;
    vector<vector<char> > v1(n , vector<char>(m)) ;
    vector<vector<bool> > vis(n , vector<bool>(m , false)) ;
    for(int i = 0 ; i < n ; i++)
    {
       for(ll j = 0 ; j < m ; j++)
        {
            cin>>v1[i][j] ;
        }
    }

    priority_queue<pi , vector<pi> , greater<pi> > q ;

    q.push({0 , {x1 , y1}}) ;
    int ans = -1 ;
    while(!q.empty())
    {
        pi p = q.top() ;
        q.pop() ;
        int u = p.second.first ;
        int v = p.second.second ;
        int d = p.first ;

        if(u == x2 && v == y2)
        {
            ans = d ;
            break ;
        }

        if(!vis[u][v])
        {
            vis[u][v] = true ;

            if(check(u + 1 , v , v1 , vis))
            q.push({d , {u + 1 , v}}) ;
            if(check(u - 1 , v , v1 , vis))
            q.push({d , {u - 1 , v}}) ;
            if(check(u , v + 1, v1 , vis))
            q.push({d , {u  , v + 1}}) ;
            if(check(u  , v - 1 , v1 , vis))
            q.push({d , {u  , v - 1}}) ;

             for(int k = u - 2 ; k <= u + 2 ; k++)
                {
                    for(int t = v - 2 ;  t <= v + 2 ; t++)
                    {
                        if(check(k , t , v1 , vis ))
                        q.push({d + 1 , {k , t}}) ;
                    }
                }
        }
    }

    cout<<ans ;
}




Measured memory_bytes: 6092
#include<iostream>
#include<string>
#include<algorithm>
#include<cmath>
using namespace std;
int main() {
	int a, b, c = 1001, d = 0, e;
	cin >> a;
	for (int h = 1; h <= a; h++) {
		cin >> b;
		c = min(b, c);
		d = max(b, d);
	}
	cout << d - c << "\n";
	cin >> e;
}

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

const int di[4] = {1,0,-1,0};
const int dj[4] = {0,1,0,-1};

int main(){
    int h, w;
    cin >> h >> w;
    
    vector<string> field(h);
    rep(i,h) cin >> field[i];

    int ans = 0;
    rep(si,h) rep(sj,w){
        if(field[si][sj] == '#') continue;

        vector<vector<int>> dist(h, vector<int>(w, -1));
        dist[si][sj] = 0;

        queue<pair<int,int>> que;
        que.push(make_pair(si, sj));

        while(!que.empty()){
            P now = que.front();
            int i = now.first;
            int j = now.second;
            que.pop();

            rep(d, 4){
                int ni = i + di[d];
                int nj = j + dj[d];

                if(ni < 0 || ni >= h || nj < 0 || nj >= w) continue;
                if(field[ni][nj] == '#') continue;

                if(dist[ni][nj] == -1){
                    que.push(make_pair(ni, nj));
                    dist[ni][nj] = dist[i][j] + 1;
                }
            }
        }
        rep(i,h) rep(j,w) ans = max(ans, dist[i][j]);
    }
    cout << ans << endl;
}

Measured memory_bytes: 3608
#include<iostream>
#include<algorithm>
#include<vector>
#include<functional>
#include<string>
#include<cmath>
#include<map>
#include<set>
#include<queue>
#include<stack>
#include<cstdio>
#include<numeric>
using namespace std;
using ll = long long;
int main(){
  int n;
  cin >> n;
  map<ll, ll> m;
  for(int i = 0; i < n; i++){
    ll tmp;
    cin >> tmp;
    m[tmp]++;
  }
  ll ans = 0;
  for(auto a : m) {
    if(a.second % 2 != 0){
      ans++;
    }
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 6528
# ANSHUL GAUTAM
# IIIT-D

from math import *
from copy import *
from string import *				# alpha = ascii_lowercase
from random import *				# l.sort(key=lambda l1:l1[0]-l1[1]) => ex: sort on the basis difference
from bisect import *				# bisect_left(arr,x,start,end)  => start and end parameters are temporary
from sys import stdin				# bisect_left return leftmost position where x should be inserted to keep sorted
from sys import maxsize
from operator import *				# d = sorted(d.items(), key=itemgetter(1))
from itertools import *
from collections import Counter		# d = dict(Counter(l))
from collections import defaultdict # d = defaultdict(list)

'''
2 1
'''

def solve(l):
	n = len(l)
	

N,M = list(map(int, stdin.readline().rstrip().split()))
ans = 0
if(N >= 2):
	ans += N*(N-1)//2
if(M >= 2):
	ans += M*(M-1)//2
print(ans)


Measured memory_bytes: 5232
#include <iostream>
#include <vector>
#include<list>
#include <algorithm>
#include <string>
#include <math.h>
#include<map>
#include <utility>
#include <iomanip>
#include<queue>
using namespace std;
#define REP(i,k,n) for(int i=k;i<n;i++)
 
#define INF 1844674407370955161
typedef long long int ll;
#define SIZE_OF_ARRAY(array) (sizeof(array)/sizeof(array[0]))
#define MOD 1000000007




int main()
{
    string S;
    cin >> S;
    int N = S.size();
    int ans[N];
    REP(i,0,N){
        ans[i] = 0;
    }
    int rcount = 0;
    int lcount = 0;
    int flag = false;
    int idx = 0;
    REP(i, 0, N)
    {
        if(S[i]=='R'){           
            if(flag==true){
                rcount = 1;
                ans[idx - 1] += lcount / 2;
                ans[idx] += lcount - lcount / 2;
            }
            else
            {
                rcount++;
            }
            flag = false;
        }
        if(S[i]=='L'){
            if(!flag){
                flag = true;
                lcount = 1;
                ans[i - 1] = rcount - rcount / 2;
                ans[i] = rcount / 2;
                idx = i;
                if(i==N-1){
                    ans[idx - 1] += lcount / 2;
                    ans[idx] += lcount - lcount / 2;
                }
            }
            else
            {
                lcount++;
                if(i==N-1){
                    ans[idx - 1] += lcount / 2;
                    ans[idx] += lcount - lcount / 2;
                }
            }
        }
    }

    REP(i,0,N){
        cout << ans[i] <<" ";
    }

    return 0;
}

Measured memory_bytes: 1024
import java.util.*;
import java.lang.*;
public class Main{
  public static void main(String[]args){
    Scanner sn=new Scanner(System.in);
     int n=sn.nextInt();
    int[] arr=new int[n];
    int[] place=new int[n];            
    for(int i=0;i<n;i++)
            {
              arr[i]=sn.nextInt();}
    int ans=0;
    for(int i=0;i<arr.length-1;i++)
    {
     if((i+1)==arr[i])
     {
       ans++;
       int x=arr[i];
       int y=arr[i+1];
       arr[i]=y;
       arr[i+1]=x;
    }}
    if(arr[n-1]==n)
      ans++;
    
    System.out.println(ans);
   }}

Measured memory_bytes: 57880
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int N,X;
    int List[N+1];
    List[0]=0;
    int s;
    int count=0;
    cin>>N>>X;
    
    for(int i=0;i<N;i++)
    {
    cin>>s;
    List[i+1]=List[i]+s;
    }
    for(int i=0;i<=N;i++)
    {
        if(List[i]<=X){
        count++;
        }
        else{
        break;
        }
    }
    cout<<count;
 return 0;
}

Measured memory_bytes: 3636
N = int(input())

c = list(map(str, input()))

r = c.count("R")
w = 0

res = max(r, w)

for i in range(N):
    if c[i] == "R":
        r -= 1
    else:
        w += 1

    now = max(r, w)
    res = min(res, now)

print(res)

Measured memory_bytes: 10792
#include<stdio.h>
#define N 100000
#define M -1


struct Node{
  int parent;
  int left;
  int right;
};
struct Node T[N];
int count=0;
 
int depth(int nodeid) {
  if(T[nodeid].parent == M) {
    return count;
  }
  else {
 count++;
 return depth(T[nodeid].parent);
  }
}
 
void degree(int nodeid) {
  if(nodeid != M) {
    if(count != 0){
      printf(", ");
    }
    printf("%d",nodeid);
    count++;
    degree(T[nodeid].right);
  }
}  

main(){

  int i,j,n,m,newnode,child,left,right;

  scanf("%d",&n);

  for(i=0;i<n;i++)
    T[i].parent = T[i].left = T[i].right = M;
 
  for(i=0;i<n;i++) {
    scanf("%d%d",&newnode,&m);
    for(j=0;j<m;j++) {
      scanf("%d",&child);
      T[child].parent = newnode;
      if(j != 0) {
	T[left].right = child;
      }
      else {
	T[newnode].left = child;
      }
      left = child;
    }
  }
  for(i=0;i<n;i++) {
    count = 0;
    printf("node %d: parent = %d, depth = %d, ",i,T[i].parent,depth(i));
    if(T[i].parent == M) {
      printf("root, [");
    }
    else if (T[i].left == M) {
      printf("leaf, [");
    } 
    else  {
      printf("internal node, [");
    }   
    count=0;
    degree(T[i].left);
    printf("]\n");
  }
  return 0;

}

Measured memory_bytes: 1784
#define KAKUSUKO
#include <iostream>
#include <algorithm>
#include <bitset>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <cstring>
#include <utility>
#include <vector>
#include <complex>
#include <valarray>
#include <fstream>
#include <cassert>
#include <cmath>
#include <functional>
#include <iomanip>
#include <numeric>
#include <climits>
#include <random>

#define _overload(a, b, c, d, ...) d
#define _rep1(X, A, Y) for (int (X) = (A);(X) <= (Y);++(X))
#define _rep2(X, Y) for (int (X) = 0;(X) < (Y);++(X))
#define rep(...) _overload(__VA_ARGS__, _rep1, _rep2)(__VA_ARGS__)
#define rrep(X,Y) for (int (X) = Y-1;(X) >= 0;--(X))
#define all(X) (X).begin(),(X).end()
#define len(X) ((int)(X).size())
#define mod(n, m) (((n)%(m)+(m))%m)
#define fi first
#define sc second
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> Pii;
typedef pair<ll,ll> Pll;
const int INFINT = 1 << 30;                          // 1.07x10^ 9
const ll INFLL = 1LL << 60;                          // 1.15x10^18
const double EPS = 1e-10;
const int MOD = 1000000007;
const int dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};

const int MAX_N = 100000;
int N;
Pii A[MAX_N];

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

  cin >> N;
  rep(i, N) {
    cin >> A[i].fi;
    A[i].sc = i + 1;
  }

  sort(A, A+N);
  rep(i, N) {
    cout << A[i].sc << (i+1 == N ? '\n' : ' ');
  }

  return 0;
}


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

int main(){
  int N;
  cin >> N;
  int D_1,D_2,count=0;
  for(int i=0;i<N;i++){
    cin >> D_1 >> D_2;
    if(D_1==D_2){
      count++;
      if(count>2){
        break;
      }
    }else{
      count=0;
    }
  }
  if(count>2){
    cout << "Yes" << endl;
  }else{
    cout << "No" << endl;
  }
}

Measured memory_bytes: 3624
#define _CRT_SECURE_NO_WARNINGS

#include <stdio.h>
#include <string.h>
#include <algorithm>
#include <set>
#include <map>
#include <vector>
#include <math.h>
#include <cmath>
#include <queue>
#include <stack>
#include <list>
#include <functional>
#include <numeric>
#include <iostream>
#include <string>
#include <time.h>
#include <bitset>

using namespace std;
typedef long long ll;
#define rep(i, n) for (ll i = 0; i < (n); ++i)
#define all(x) (x).begin(),(x).end()
ll GCD(ll a, ll b) { return b ? GCD(b, a % b) : a; }

double L;

int main() {

	cin >> L;

	printf("%.20lf\n", (L / 3.0) * (L / 3.0) * (L / 3.0));

	return 0;
}


Measured memory_bytes: 256
program probC
  implicit none
  integer :: c(3,3),a(3),b(3)
  integer i,j,k,ans

  do i=1,3
     read(*,*) c(i,1:3)
  end do

  do i=0,100
     ans=0
     a(1)=i

     b(1)=c(1,1)-a(1)
     b(2)=c(1,2)-a(1)
     b(3)=c(1,3)-a(1)
     
     a(2)=c(2,1)-b(1)
     a(3)=c(3,1)-b(1)

     do j=1,3
        do k=1,3
           if(c(j,k).ne.a(j)+b(k)) ans=1
        end do
     end do

     if(ans==0) then
        write(*,*) 'Yes'
        stop
     end if
  end do

  write(*,*) 'No'
  
end program probC


Measured memory_bytes: 768
#define _USE_MATH_DEFINES
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cctype>
#include <clocale>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <ctime>
#include <deque>
#include <fstream>
#include <functional>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <regex>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <tuple>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>

using namespace std;

#define IOS ios::sync_with_stdio(false); cin.tie(0);
#define FOR(i, s, n) for(int i = (s), i##_len=(n); i < i##_len; ++i)
#define FORS(i, s, n) for(int i = (s), i##_len=(n); i <= i##_len; ++i)
#define VFOR(i, s, n) for(int i = (s); i < (n); ++i)
#define VFORS(i, s, n) for(int i = (s); i <= (n); ++i)
#define REP(i, n) FOR(i, 0, n)
#define REPS(i, n) FORS(i, 0, n)
#define VREP(i, n) VFOR(i, 0, n)
#define VREPS(i, n) VFORS(i, 0, n)
#define RFOR(i, s, n) for(int i = (s), i##_len=(n); i >= i##_len; --i)
#define RFORS(i, s, n) for(int i = (s), i##_len=(n); i > i##_len; --i)
#define RREP(i, n) RFOR(i, n, 0)
#define RREPS(i, n) RFORS(i, n, 0)
#define IREP(i, v) for(auto i = (v).begin(); i != (v).end(); ++i)
#define IRREP(i, v) for(auto i = (v).rbegin(); i != (v).rend(); ++i)
#define ALL(v) (v).begin(), (v).end()
#define SORT(v) sort(ALL(v))
#define RSORT(v) sort(ALL(v), greater<decltype(v[0])>())
#define SZ(x) ((int)(x).size())
#define REV(x) reverse(ALL(x))
#define PB push_back
#define EB emplace_back
#define MP make_pair
#define MT make_tuple
#define BIT(n) (1LL<<(n))
#define UNIQUE(v) v.erase(unique(ALL(v)), v.end())

using ld = long double;
using ll = long long;
using ui = unsigned int;
using ull = unsigned long long;
using Pi_i = pair<int, int>;
using Pll_ll = pair<ll, ll>;
using VB = vector<bool>;
using VC = vector<char>;
using VD = vector<double>;
using VI = vector<int>;
using VLL = vector<ll>;
using VS = vector<string>;
using VSH = vector<short>;
using VULL = vector<ull>;

const int MOD = 1000000007;
const int INF = 1000000000;
const int NIL = -1;
const double EPS = 1E-10;

template<class T, class S>
bool chmax(T &a, const S &b){
    if(a < b){
        a = b; return true;
    }
    return false;
}
template<class T, class S>
bool chmin(T &a, const S &b){
    if(b < a){
        a = b; return true;
    }
    return false;
}


int main(){
    string S; cin >> S;
    ll K; cin >> K;
    int n(S.length());
    ll ans(0);
    int cnt(0);
    char prv(0);
    REP(i, n){
        if(prv == S[i]) ++cnt;
        else{
            ans += cnt/2;
            prv = S[i];
            cnt = 1;
        }
    }
    if(cnt == n){
        cout << n * K / 2 << endl;
        return 0;
    }
    ans += cnt/2;
    ans *= K;
    if(S[0] == S[n-1]){
        int a(0), b(0); char c(S[0]);
        for(int i = 0; i < n && S[i] == c; ++i)
            ++a;
        for(int i = n-1; i >= 0 && S[i] == c; --i)
            ++b;
        ans -= (K-1) * (a/2 + b/2 - (a+b)/2);
    }
    cout << ans << endl;
    return 0;
}


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

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

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

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

const int MAX = 200005;
const int INF = 1001001001;
const int MOD = 1000000007;

int N, M, Q, A[10], a[50], b[50], c[50], d[50];

int dfs(int n) {
    if (n == N) {
        int res = 0;
        rep(i, Q) {
            if (A[b[i]] - A[a[i]] == c[i]) res += d[i];
        }
        return res;
    }

    int res = 0;

    int s = n == 0? 0 : A[n-1];
    for (int i = s; i < M; ++i) {
        A[n] = i;
        chmax(res, dfs(n+1));
    }

    return res;
}

int main(){
    cin >> N >> M >> Q;
    rep(i, Q) {
        cin >> a[i] >> b[i] >> c[i] >> d[i];
        a[i]--, b[i]--;
    }

    cout << dfs(0) << endl;
}

Measured memory_bytes: 3620
#include<bits/stdc++.h>
using namespace std;
int main(){
  int n,a=0;string s;cin>>n>>s;
  for(int i=1;i<n;i++){
    int c=0;
    for(int j=0;j<26;j++){
      int p=0;
      for(int k=0;k<i;k++){
        if(s.at(k)=='a'+j){
          p=1;
          break;
        }
      }
      for(int k=i;k<n;k++){
        if(s.at(k)=='a'+j){
          p++;
          break;
        }
      }
      if(p==2)c++;
    }
    a=max(a,c);
  }
  cout<<a<<endl;
}
    
      
    
    


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

int main(){
  int N;
  cin >> N;
  vector <int> a(N);
  int sumA=0;
  int sumB=0;
  for(int i=0;i<N;i++){
    cin >> a.at(i);
  }
  sort(a.begin(),a.end());
  reverse(a.begin(),a.end());
  for(int i=0;i<N;i++){
    if(i%2==0){
      sumA+=a.at(i);
    }else{
      sumB+=a.at(i);
    }
  }
  cout << sumA-sumB << endl;
  return 0;
}


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

for i in range(1000):
    n = str(i)
    if len(n) != N:
        continue
    for j in range(M):
        if len(n)<S[j][0]:
            break
        if int(n[S[j][0]-1]) != S[j][1]:
            break
    else:
        print(i)
        break

else:
    print(-1)

Measured memory_bytes: 38256
N = int(input())
s =[input() for i in range(N)]
M = int(input())
t =[input() for i in range(M)]
ansmx= -100
ans=0

strset =set(s)
strlist = list(strset)

for i in range(len(strlist)):
    str1=strlist[i]
    ans = s.count(str1)-t.count(str1)
    if ans>ansmx:
        ansmx = ans
if ansmx <0:
    print(0)
else:
    print(ansmx)

Measured memory_bytes: 3064
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.Arrays;

public class Main {

	public static void main(String[] args) throws Exception {
		// TODO ?????????????????????????????????????????????
		BufferedReader br =
				new BufferedReader( new InputStreamReader(System.in) );

		int n = Integer.parseInt(br.readLine());
		String[] prestr = br.readLine().split(" ");
		String[] instr = br.readLine().split(" ");

		int[] preorderTreeWalk = new int[n];
		int[] inorderTreeWalk = new int[n];
		for (int i=0; i < n; i++) {
			preorderTreeWalk[i] = Integer.parseInt(prestr[i]);
			inorderTreeWalk[i] = Integer.parseInt(instr[i]);
		}
//		prestr = instr = null;
		Tree t = new Tree(preorderTreeWalk, inorderTreeWalk);

		String ans = postorder(t).trim();
		System.out.println(ans);
	}

	public static class Tree {
		int root;

		Tree leftSubTree;

		Tree rightSubTree;

		public Tree(int[] pre, int[] in) {
			root = pre[0];

			int index = 0; // InorderTreeWalk ?????¨?????????in??§????????? root ??§??????????´??????????????????????
			for (int i=0; i < in.length; i++) {
				if (in[i] == root) {
					index = i;
					break;
				}
			}

			if (index != 0) {
				int[] leftSubTreeOfIn = Arrays.copyOfRange(in, 0, index);
				int[] leftSubTreeOfPre = Arrays.copyOfRange(pre, 1, index+1);
				leftSubTree = new Tree(leftSubTreeOfPre, leftSubTreeOfIn);
			}

			if (index != in.length-1) {
				int[] rightSubTreeOfPre = Arrays.copyOfRange(pre, index+1, pre.length);
				int[] rightSubTreeOfIn = Arrays.copyOfRange(in, index+1, in.length);
				rightSubTree = new Tree(rightSubTreeOfPre, rightSubTreeOfIn);
			}
//			for (int i=0; i < index; i++) {
//				leftsubTreeOfin[i] = in[i];
//			}
//			for (int i=0; i < in.length-1-index; i++) {
//				rightsubTreeOfin[i] = in[index+1+i];
//			}
		}
	}

	public static String postorder(Tree t) {
		StringBuilder sb = new StringBuilder();

		if (t.leftSubTree != null) {
			String s = postorder(t.leftSubTree);
			sb.append(s);
		}

		if (t.rightSubTree != null) {
			String s = postorder(t.rightSubTree);
			sb.append(s);
		}

		return sb.append(t.root + " ").toString();
	}
}

Measured memory_bytes: 24508
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <vector>
#include <queue>
#include <cmath>

using namespace std;

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

template<typename T> inline T sqr(T x) { return x * x; }

struct Sphere { double x, y, z, r; };

istream& operator>>(istream& is, Sphere& s) { 
    return is >> s.x >> s.y >> s.z >> s.r;
}

double dist(const Sphere& a, const Sphere& b) {
    double retval = sqrt(sqr(a.x - b.x) + sqr(a.y - b.y) + sqr(a.z - b.z)) - a.r - b.r;
    return max(0.0, retval);
}

struct Edge {
    int src, dst;
    double wt;
    Edge(int src_, int dst_, double wt_) : src(src_), dst(dst_), wt(wt_) {}
    bool operator>(const Edge& rhs) const { return wt > rhs.wt; }
};

typedef vector<Edge> Edges;

struct UnionFind {
    UnionFind(size_t n) : data(n, -1) {}
    int root(size_t x) { return data[x] < 0? x: data[x] = root(data[x]); }
    bool unite(size_t x, size_t y) {
        x = root(x); y = root(y);
        if (x == y) return false;
        if (data[y] < data[x]) swap(x, y);
        data[x] += data[y];
        data[y] = x;
        return true;
    }
private:
    vector<int> data;
};

double solve(const vector<Sphere>& cell) { // kruskal
    double retval = 0.0;
    Edges stree;
    UnionFind uf(cell.size());
    priority_queue<Edge, vector<Edge>, greater<Edge>> Q;
    rep(i, cell.size()) rep(j, i) Q.emplace(i, j, dist(cell[i], cell[j]));
    for (; stree.size() < cell.size() - 1 && !Q.empty();) {
        Edge e = Q.top(); Q.pop();
        if (!uf.unite(e.src, e.dst)) continue;
        stree.push_back(e);
        retval += e.wt;
    }
    return retval;
}

int main() {
    for (int n; cin >> n, n;) {
        vector<Sphere> cell(n);
        for (auto& e: cell) cin >> e;
        cout << fixed << setprecision(3) << solve(cell) << endl;
    }
    return 0;
}

Measured memory_bytes: 1428
#include <stdio.h>
int main(void){
    int a,b,d,n,m;
    while(~scanf("%d%d",&a,&b)){
        n=a,m=b;
        while(b>0)d=a%b,a=b,b=d;
        printf("%d %d\n",a,n/a*m);
    }
    return 0;
}

Measured memory_bytes: 1024
#include<bits/stdc++.h>
#define ALL(c) (c).begin(),(c).end()
#define EACH(i,c) for(auto i=(c).begin();i!=(c).end();++i)
using namespace std;
#define int long long


void solve(long long X, long long Y){
    int res = 0;

    if (X == 1) {
        res += 3;
    } else if (X == 2) {
        res += 2;
    } else if (X == 3) {
        res += 1;
    }

    if (Y == 1) {
        res += 3;
    } else if (Y == 2) {
        res += 2;
    } else if (Y == 3) {
        res += 1;
    }

    if (X == 1 && Y == 1) {
        res += 4;
    }

    cout << res * 100000 << endl;
}

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


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

int main()
{
  int n;
  int a, b, ab, o;
  char t;
  string c;

  a = b = ab = o = 0;
  while (cin >> n >> t >> c){
    if (c == "A") a++;
    else if (c == "B")  b++;
    else if (c == "AB") ab++;
    else if (c == "O")  o++;
  }
  cout << a << endl << b << endl << ab << endl << o << endl;
  return (0);
}

Measured memory_bytes: 1204
#include <iostream>
#include <vector>
#include <string>

using namespace std;

int vector_finder(std::vector<char> vec, char ch) {
	for (int i = 0; i < vec.size(); i++) {
		if (vec[i] == ch) return 1;
	}

	return 0;
}

int main() {
	bool ans = true;
	vector<char> fixed;
	string S, T;
	char c1, c2;
	cin >> S >> T;

	for (int i = 0; i < S.size(); i++) {
		if (S[i] != T[i]) {
			if (vector_finder(fixed, S[i]) == 1 || vector_finder(fixed, T[i]) == 1) {
				ans = false;
				break;
			}
			fixed.push_back(T[i]);
			//Sのc1をc2に,c2をc1に
			c1 = S[i]; c2 = T[i];
			for (int j = i; j < S.size(); j++) {
				if (S[j] == c1) S[j] = c2;
				else if (S[j] == c2) S[j] = c1;
			}
		}
		else {
			fixed.push_back(S[i]);
		}
	}

	if (ans) cout << "Yes" << endl;
	else cout << "No" << endl;

	return 0;
}

Measured memory_bytes: 1156
#include <cstdio>
#include <queue>
#include <vector>
using namespace std;

#define MAXN 100002

char vis[MAXN] = {0};
int n, q, k;
long long int D[MAXN];
vector<pair<int, long long int> > a[MAXN];
queue<int> Q;

void bfs(int st) {
	D[st] = 0;
	vis[st] = 1;
	Q.push(st);
	
	while(Q.size()) {
		int u = Q.front(); Q.pop();
		for(auto p : a[u]) {
			if(!vis[p.first]) {
				vis[p.first] = 1;
				D[p.first] = D[u] + p.second;
				Q.push(p.first);
			}
		}
	}
}

int main() {
	scanf("%d", &n);
	for(int i = 2, u, v, c; i <= n; ++i) {
		scanf("%d%d%d", &u, &v, &c);
		a[u].push_back({ v, c });
		a[v].push_back({ u, c });
	}
	
	scanf("%d%d", &q, &k);
	bfs(k);
	
	while(q--) {
		int u, v;
		scanf("%d%d", &u, &v);
		printf("%lld\n", D[u] + D[v]);
	}
	
	return 0;
}

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

using namespace std;

static const int INF = 1e9 + 7;

template<typename T>
using Vec = vector<T>;

template<typename T, typename T2>
using P = pair<T, T2>;

template<typename... Args>
using Tup = tuple<Args...>;

template<typename T>
using qp = priority_queue<T, Vec<T>, greater<T> >;

template<typename T>
using pq = priority_queue<T>;

using llong = long long;
using ullong = unsigned long long;
using uint = unsigned int;

int gcd(int x, int y)
{
	return y ? gcd(y, x % y) : x;
}

void hawawa()
{
	char x, y;
	cin >> x >> y;
	if (x < y) {
		cout << "<";
	}
	else if (x == y) {
		cout << "=";
	}
	else {
		cout << ">";
	}
	cout << "\n";
}

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


Measured memory_bytes: 256