akhauriyash/Code-Regression huggingface dataset:
let nil = -1

type tree = { mutable parent : int; mutable child : int; mutable bro : int; mutable depth : int }

let make () = { parent = nil; child = nil; bro = nil; depth = nil }

let set_depth t n =
  let rec root i =
    if i = n then nil
    else if t.(i).parent = nil then i
    else root (i + 1) in
  let rec doit i d =
    t.(i).depth <- d;
    if t.(i).bro <> nil then doit t.(i).bro d;
    if t.(i).child <> nil then doit t.(i).child (d + 1) in
  doit (root 0) 0

let print_tree t =
  t |> Array.iteri (fun i _ ->
    print_string "node "; print_int i;
    print_string ": parent = "; print_int t.(i).parent;
    print_string ", depth = "; print_int t.(i).depth;
    print_string (if t.(i).parent = nil then ", root, [" else if t.(i).child = nil then ", leaf, [" else ", internal node, [");
    let c = ref t.(i).child in
    while !c <> nil do
      if !c <> t.(i).child then print_string ", ";
      print_int !c;
      c := t.(!c).bro;
    done;
    print_string "]\n")

let () =
  let n = Scanf.scanf "%d " (fun i -> i) in
  let t = Array.init n (fun _ -> make ()) in
  for _ = 0 to n - 1 do
    let (id, k) = Scanf.scanf "%d %d " (fun id k -> (id, k)) in
    let left_child = ref 0 in
    for i = 0 to k - 1 do
      let c = Scanf.scanf "%d " (fun i -> i) in
      t.(c).parent <- id;
      if i = 0 then t.(id).child <- c else t.(!left_child).bro <- c;
      left_child := c;
    done;
  done;
  set_depth t n;
  print_tree t

Measured memory_bytes: 13156
#include <iostream>
#include <vector>
#include <string>
#include <cmath>
#include <algorithm>
#include <queue>
#include <functional>
#include <utility>
#include <unordered_map>
#define INF 2147483647
using namespace std;
typedef long long int ll;
typedef unsigned long long int ull;
int main() {
	int N, M;
	cin >> N >> M;
	vector <ll> A(N, 0), An(N + 1, 0);
	for (int i = 0; i < N; i++)cin >> A[i];
	for (int i = 1; i < N + 1; i++)An[i] = An[i - 1] + A[i - 1];
	ll ans = 0;
	unordered_map<int, int> mp;
	for (int i = 0; i < N + 1; i++){
		ans += mp[An[i] % M];
		mp[An[i] % M]++;
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 5260
#include <bits/stdc++.h>
#define FOR(i,a,b) for (int i = (a); i < (b); ++i)
#define rep(i,n) for (int i = (0); i < (n); ++i)
#define rng(x) (x).begin(),(x).end()
#define rrng(x) (x).rbegin(),(x).rend()
#define show(x) cout << #x << " = " << (x) << endl
#define show2(x,y) cout << #x << " = " << (x) << ", " << #y << " = " << (y) << endl
#define show3(x,y,z) cout << #x << " = " << (x) << ", " << #y << " = " << (y) <<  ", " << #z << " = " << (z) << endl
#define showv(v) rep(i,v.size()) printf("%d%c", v[i], i==v.size()-1?'\n':' ')
#define showv2(v) rep(j,v.size()) showv(v[j])
#define showt(t,n) rep(i,n) printf("%d%c", t[i], i==n-1?'\n':' ')
#define showt2(t,r,c) rep(j,r) showt(t[j],c)
#define printv(v) rep(i,v.size()) printf("%d\n", v[i])
#define printt(t,n) rep(i,n) printf("%d\n", t[i])
#define fi first
#define se second
#define pb push_back
#define eb emplace_back
#define sz(x) (int)(x).size()
#define bn(x) ((1<<x)-1)
#define dup(x,y) (((x)+(y)-1)/(y))
#define uni(x) x.erase(unique(rng(x)),x.end())
#define SP << " " <<
using namespace std;
using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vll = vector<ll>;
using pii = pair<int, int>;
using tiii = tuple<int, int, int>;
const int mod = 1000000007;
const double EPS = 1e-9;
const int INF = (1<<30)-1;
const ll INFLL = (1LL<<62)-1;
//cout << fixed << setprecision(10);

int main () {
  int a, b;
  cin >> a >> b;
  string s(b, '0'+a);
  string t(a, '0'+b);
  cout << min(s,t) << endl;
  return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
  int N;cin>>N;int Sn=0;
  for(int i=N;i>0;){
    Sn+=i%10;
    i=(i-i%10)/10;
  }
  if(N%Sn==0)cout<<"Yes"<<endl;
  else cout<<"No"<<endl;
}

Measured memory_bytes: 256
n = int(input())
h = list(map(int, input().split()))
ans = 0
flag = 0
for i in range(102):
    flag = 0
    for j in range(n):
        if flag == 0 and h[j] != 0:
            ans += 1
            flag = 1
            h[j] -= 1
        elif flag == 1 and h[j] != 0:
            h[j] -= 1
        elif flag == 1 and h[j] == 0:
            flag = 0
    if sum(h) <= 0:
        print(ans)
        break

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

int main() {
  int n, r;
  cin >> n >> r;
  int ans = 0;
  if(n >= 10) ans = r;
  else ans = r + 100*(10-n);
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 3636
#include<bits/stdc++.h>
using namespace std;
long long n,m,w[1000],v[1000],sum=0;
long long f[200][200000]={0};
int main(){
	cin>>n>>m;
	for(int i=1;i<=n;i++){
	    cin>>w[i]>>v[i];
	    sum=sum+v[i];
	}
	for(int i=0;i<=n;i++){
		for(int j=1;j<=sum;j++){
			f[i][j]=1e18+5;
		}
	}
	for(int i=1;i<=n;i++){
		for(int j=1;j<=sum;j++){
			if(j>=v[i]){
				f[i][j]=min(f[i-1][j],f[i-1][j-v[i]]+w[i]);
			}else{
				f[i][j]=f[i-1][j];
			}
		}
	}
	while(f[n][sum]>m){
		sum--;
	}
	cout<<sum;
}

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

int main()
{
    int n, d;

    while( cin >> n, n )
    {
        bool* taro = new bool[2*n+1];
        bool* hanako = new bool[2*n+1];

        for( int i = 0; i <= 2 * n; i++ )
        {
            taro[i] = 0;
            hanako[i] = 0;
        }

        for( int i = 0; i < n; i++ )
        {
            cin >> d;
            taro[d] = 1;
        }

        for( int i = 1; i <= 2 * n; i++ )
            if( !taro[i] )
                hanako[i] = 1;

        int cnt1 = n, cnt2 = n, field = 0;
        bool sw = 1;
        while( cnt1 && cnt2 )
        {
            if( sw == 1 )
            {
                for( int i = 1; i <= 2 * n; i++ )
                    if( i > field && taro[i] )
                    {
                        taro[i] = 0;
                        field = i;
                        cnt1--;
                        sw = 0;
                        break;
                    }
                if( sw )
                {
                    sw = 0;
                    field = 0;
                }
            }
            else
            {
                for( int i = 1; i <= 2 * n; i++ )
                    if( i > field && hanako[i] )
                    {
                        hanako[i] = 0;
                        field = i;
                        cnt2--;
                        sw = 1;
                        break;
                    }
                if( !sw )
                {
                    sw = 1;
                    field = 0;
                }
            }
        }
        if( cnt1 == 0 )
            cout << cnt2 << endl << 0 << endl;
        else
            cout << 0 << endl << cnt1 << endl;

        delete taro, hanako;
    }
    return 0;
}


Measured memory_bytes: 3100
#include<bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
#define repk(i,k, n) for (ll i = k; i < (ll)(n); ++i)
#define MAX 500001
#define MOD 1000000007
typedef long long  ll;

using namespace std;


int max;
int cnt[MAX];

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

	string s,t;
	cin >> s >> t;

	rep(i, N) {
		cout << s[i] << t[i];
	}
	
	cout << endl;

	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define FOR(i, a, b) for(int i=(a);i<(b);++i)
#define rep(i, n) FOR(i, 0, n)
#define whole(x) (x).begin(),(x).end()
#define UNIQUE(v) v.erase(unique(v.begin(), v.end()), v.end())
using ll = long long;
using P = pair<int, int>;
const int mod = 1000000007;


int main(){
    double l;
    cin >> l;
    double ans = (l/3.0)*(l/3.0)*(l/3.0);
    
    
    
    printf("%.10f", ans);
    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<cmath>
#include<climits>
#include<map>
#include<set>
#include<queue>
#include<stack>
#include<bitset>
#include<iomanip>
#include<deque>
using namespace std;

#define rep(i,j,n) for(int i=(j);i<(n);i++)
#define rep2(i,j,n) for(int i=(j);i<=(n);i++)
#define all(i) i.begin(),i.end()

typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef vector<string> vs;
typedef vector<vector<string>> vvs;
typedef pair<int, int> pi;
typedef long long i64;

int main() {
	i64 n, a, b;
	cin >> n >> a >> b;
	vector<i64> x(n);
	rep(i, 0, n) {
		cin >> x[i];
	}
	i64 ans = 0;
	rep(i, 1, n) {
		ans += min(a*(x[i] - x[i - 1]), b);
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 1024
import math
from math import gcd
INF = float("inf")

import sys
input=sys.stdin.readline
import itertools
from collections import Counter

def main():
    n = int(input())
    a = list(map(int, input().split()))
    c = Counter(a)
    p = [True] * (10**6 + 1)
    s = list(set(a))
    for x in s:
        t = x * 2
        while t <= 10**6:
            p[t] = False
            t += x
    ans = 0
    for x in a:
        if c[x] == 1 and p[x] == True:
            ans += 1
    print(ans)


if __name__=="__main__":
    main()


Measured memory_bytes: 165160
#include <vector>
#include <iostream>
#include <cmath>
#include <map>
#include <algorithm>
#include <fstream>
#include <unistd.h>
#include <string>
#include <numeric>
#include <queue>
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vector<int>> vvi;
typedef vector<bool> vb;
typedef vector<vector<bool>> vvb;
typedef vector<string> vs;
typedef vector<vector<string>> vvs;
typedef vector<char> vc;
typedef vector<vector<char>> vvc;
typedef pair<int, int> pii;
const int INF = 1001001001;
const ll LINF = 1e18;

template <typename T>
T gcd(T a, T b) {
    if(a < b) gcd(b, a);
    T r;
    while((r=a%b)) {
        a = b; b = r;
    }
    return b;
}


int main(){
    ll N; cin >> N;
    vl xs(N, 0), t_xs(N, 0);
    for(ll i = 0; i < N; i++){
        cin >> xs[i];
        t_xs[i] = xs[i];
    }
    
    sort(xs.begin(), xs.end(), less<ll>());
    ll l_max = xs[N / 2 - 1];
    ll r_min = xs[N / 2];
    
    for (ll i = 0; i < N; i++) {
        ll res = 0;
        if(t_xs[i] <= l_max) res = r_min;
        else res = l_max;
        cout << res << endl;
    }
    
    return 0;
}


Measured memory_bytes: 5376
#include <iostream>
#include <sstream>
#include <algorithm>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <stack>
#include <memory>
#include <complex>
#include <numeric>
#include <cstdio>
#include <iomanip>
#include <random>

#define REP(i,m,n) for(int i=int(m);i<int(n);i++)
#define RREP(i,m,n) for(int i=int(n)-1;i>=int(m);--i)
#define EACH(i,c) for (auto &(i): c)
#define all(c) begin(c),end(c)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort(begin(c),end(c))
#define pb emplace_back
#define MP make_pair
#define SZ(a) int((a).size())
//#define int long long

#ifdef LOCAL
#define DEBUG(s) cout << (s) << endl
#define dump(x)  cerr << #x << " = " << (x) << endl
#define BR cout << endl;
#else
#define DEBUG(s) do{}while(0)
#define dump(x) do{}while(0)
#define BR 
#endif
using namespace std;

using UI = unsigned int;
using UL = unsigned long;
using LL = long long;
using ULL = unsigned long long;
using VI = vector<int>;
using VVI = vector<VI>;
using VLL = vector<LL>;
using VVLL = vector<VLL>;
using VS = vector<string>;
using PII = pair<int,int>;
using VP = vector<PII>;
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; }

constexpr double EPS = 1e-10;
//constexpr double PI  = acos(-1.0);
//constexpr int INF = INT_MAX;
constexpr int MOD = 1'000'000'007;
//inline void modAdd(LL &l, LL &r) {l = (l + r) % MOD;}

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

void solve() {
    LL a,b,c,k;
    cin >> a >>b >> c >> k;
    cout << min(a,k) - max(0LL, k - a - b) << endl;
}

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

Measured memory_bytes: 3636
import java.util.Scanner;
import java.util.TreeSet;

public class Main {

    public static void main(String[] args) {
        
        Scanner sc = new Scanner(System.in);
        
        String s = sc.next();
        int k = Integer.parseInt(sc.next());
        
        TreeSet<String> set = new TreeSet<>();
        for(int i = 1; i <= 5; i++){
            for(int j = 0; j <= s.length()-i; j++){
                set.add(s.substring(j, j+i));
            }
        }
        
        String ans = "";
        for(int i = 0; i < k; i++){
            ans = set.pollFirst();
        }
        System.out.println(ans);
    }
}

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

using namespace std;

typedef long long LL;
const LL MO=1e9+7;

LL qmi(LL a,LL b) {
    LL res=1;
    while(b) {
        if (b&1) {
            res=res*a%MO;
        }
        a=a*a%MO;
        b>>=1;
    }
    return res;
}

int main() {
    LL n;
    cin>>n;

    cout<<((qmi(10,n)-2*qmi(9,n)+qmi(8,n))%MO+MO)%MO<<"\n";

    return 0;
}


Measured memory_bytes: 3620
#include<bits/stdc++.h>
#define mod 1000000007
#define max 5005
//#define max1 60000000
#define inf INT_MAX
using namespace std;
typedef  long long int ll;
template<typename T> inline T maxi(T a,T b){return a>b?a:b;}
template<typename T> inline T mini(T a,T b){return a<b?a:b;}
template<typename T> inline T absl(T a){return a>0?a:-a;}
template<typename T> inline T gcd(T a,T b){T t;if(a<b){while(a){t=a;a=b%a;b=t;}return b;}else{while(b){t=b;b=a%b;a=t;}return a;}}
#define mp(a,b) make_pair(a,b)
//###################################################------------------------------------------------------#######################################

void input(){
    int n,m,c;
    cin>>n>>m>>c;
    int b[m];
    for(int i =0;i<m;++i)cin>>b[i];
    int ans =0;
    for(int i =0;i<n;++i){
        int a[m];
        for(int i =0;i<m;++i)cin>>a[i];
        int temp =0;
        for(int i =0;i<m;++i)temp+=(a[i]*b[i]);
        if(temp+c>0)++ans;
    }
    cout<<ans<<endl;
}
int main(){
    input();
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
#define pi 3.141592653589793238
#define int long long
using namespace __gnu_pbds;
using namespace std;
template <typename T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

int ans[1000000];
int cnt[505];
int mm[1000005];

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

#ifndef ONLINE_JUDGE
	if(fopen("INPUT.txt","r"))
	{
	freopen ("INPUT.txt" , "r" , stdin);
	freopen ("OUTPUT.txt" , "w" , stdout);
	}
#endif  

	int a[7];
	for(int i=0;i<7;i++)
		cin>>a[i];
	int ans=0;
	ans+=a[1];
	if(a[0]==0||a[3]==0||a[4]==0)
	{
		int z=(a[0]/2+a[3]/2+a[4]/2)*2;
		ans+=z;
	}
	else
	{
		int x=a[0]%2;
		int y=a[3]%2;
		int z=a[4]%2;
		if(x==y&&x==z)
		{
			ans+=(a[0]+a[3]+a[4]);
		}
		else 
		{
			ans+=(a[0]+a[3]+a[4])-1;
		}
	}
	cout<<ans;
}


Measured memory_bytes: 3620
import java.util.*;
class Main {
    public static void main(String[] args) {
        Scanner sc= new Scanner(System.in);
        int N=sc.nextInt();
        int bit=0;
        for(int i=0;i<N;i++){
            bit|=sc.nextInt();
        }
        System.out.println(Integer.numberOfTrailingZeros(bit));
        
        
        System.out.println();
    }
}

Measured memory_bytes: 21844
#include <bits/stdc++.h>
#define rep(i,n) for (int (i) = 0; (i) < (n); i++)
#define ll long long
using namespace std;
int main() {
  ll A = 0,B = 0,C = 0,a = 0,b = 0,c = 0;
  cin >> A >> B >> C;
  rep(i,1000){
    if(A % 2 != 0 || B % 2 != 0 || C % 2 != 0){
      cout << i;
      return 0;
    }
    a = (B + C)/2;
    b = (A + C)/2;
    c = (A + B)/2;
    A = a; B = b; C = c;
  }
  cout << "-1";
}

Measured memory_bytes: 256
#include <stdio.h>

int main(void)
{
	int a,b,c,d,e,k;
	scanf("%d %d %d %d %d %d",&a,&b,&c,&d,&e,&k);

	if(b-a<=k && c-a<=k && d-a<=k && e-a<=k && c-b<=k && d-b<=k && e-d<=k && d-c<=k && e-c<=k && e-d<=k){
		printf("Yay!\n");
	}else{
		printf(":(\n");
	}
	
	
	return 0;
}


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

int main(){
  int a, b;
  cin >> a >> b;
  
  int y = a + b;
  if(y % 2 == 0){
    cout << y / 2 << endl;
  }
  
  else{
    cout << y / 2 + 1 << endl;
  }
}


Measured memory_bytes: 3584
import java.util.*;
class Main {
	public static void main(String[] args) {
		Scanner stdIn = new Scanner(System.in);
		int n = stdIn.nextInt();
		boolean[][] cards = new boolean[4][13];
		for (int i=0; i<n; i++) {
			String s = stdIn.next();
			switch (s.charAt(0)) {
				case 'S':cards[0][stdIn.nextInt()-1] = true; break;
				case 'H':cards[1][stdIn.nextInt()-1] = true; break;
				case 'C':cards[2][stdIn.nextInt()-1] = true; break;
				case 'D':cards[3][stdIn.nextInt()-1] = true; break;
			}
		}
		char[] c = {'S','H','C','D'};
		for (int i=0; i<4; i++) {
			for (int j=0; j<13; j++) {
				if (!cards[i][j]) {
					System.out.println(c[i]+" "+(j+1));
				}
			}
		}
	}
}

Measured memory_bytes: 18072
package main

import (
	"fmt"
	"math"
)

func abs(a int) int {
	if a < 0 {
		return -a
	} else {
		return a
	}
}

func min(nums ...int) int {
	if len(nums) == 0 {
		panic("funciton min() requires at least one argument.")
	}
	res := nums[0]
	for i := 0; i < len(nums); i++ {
		res = int(math.Min(float64(res), float64(nums[i])))
	}
	return res
}

func max(nums ...int) int {
	if len(nums) == 0 {
		panic("funciton max() requires at least one argument.")
	}
	res := nums[0]
	for i := 0; i < len(nums); i++ {
		res = int(math.Max(float64(res), float64(nums[i])))
	}
	return res
}

func main() {
	var a int
	var b int
	fmt.Scan(&a,&b)
	fmt.Println(a*b)

}


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

int main(void){
    int N;
    cin >> N;
    long long A,B;
    cin >> A >> B;
    for(int i=0; i<(N-1); i++){
        long long x,y;
        cin >> x >> y;
        long long k=max(A/x, B/y);
        while(k*x<A or k*y<B){
            k++;
        }
        A=k*x; B=k*y;
    }
    cout << A+B << endl;
    return 0;
} 

Measured memory_bytes: 256
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

from heapq import heappop, heappush

N = int(readline())
m = map(int,read().split())
data = list(zip(m,m,m))
R = data[:N]
B = data[N:]

class MinCostFlow:
    """
    最小費用流。負辺がないと仮定して、BellmanFordを省略している。
    """
    def __init__(self, N, source, sink):
        self.N = N
        self.G = [[] for _ in range(N)]
        self.source = source
        self.sink = sink
        
    def add_edge(self, fr, to, cap, cost):
        n1 = len(self.G[fr])
        n2 = len(self.G[to])
        self.G[fr].append([to, cap, cost, n2])
        self.G[to].append([fr, 0, -cost, n1])

    def MinCost(self, flow, negative_edge = False):
        if negative_edge:
            raise ValueError
        N = self.N; G = self.G; source = self.source; sink = self.sink
        INF = 10 ** 18
        prev_v = [0] * N; prev_e = [0] * N # 経路復元用
        H = [0] * N # potential
        mincost=0
        while flow:
            dist=[INF] * N
            dist[source]=0
            q = [source]
            mask = (1 << 20) - 1
            while q:
                x = heappop(q)
                dv = (x >> 20); v = x & mask
                if dist[v] < dv:
                    continue
                if v == sink:
                    break
                for i,(w,cap,cost,rev) in enumerate(G[v]):
                    dw = dist[v] + cost + H[v] - H[w]
                    if (not cap) or (dist[w] <= dw):
                        continue
                    dist[w] = dw
                    prev_v[w] = v; prev_e[w] = i
                    heappush(q, (dw << 20) + w)
            #if dist[sink] == INF:
            #    raise Exception('No Flow Exists')
            # ポテンシャルの更新
            for v,d in enumerate(dist):
                H[v] += d
            # 流せる量を取得する
            d = flow; v = sink
            while v != source:
                pv = prev_v[v]; pe = prev_e[v]
                cap = G[pv][pe][1]
                if d > cap:
                    d = cap
                v = pv
            # 流す
            mincost += d * H[sink]
            flow -= d
            v = sink
            while v != source:
                pv = prev_v[v]; pe = prev_e[v]
                G[pv][pe][1] -= d
                rev = G[pv][pe][3]
                G[v][rev][1] += d
                v = pv
        return mincost

source = N+N; sink = N+N+1
V1 = N+N+2; V2 = N+N+3; V3 = N+N+4; V4 = N+N+5

G = MinCostFlow(N+N+6, source = source, sink = sink)
base = 10 ** 9 * 2 # 各辺に上乗せしておく -> 最後に引く
INF = 10 ** 18

flow = 0

for i,(x,y,c) in enumerate(R):
    flow += c
    G.add_edge(fr=source, to=i, cap=c, cost=0)
    G.add_edge(i,V1,INF,base-x-y)
    G.add_edge(i,V2,INF,base-x+y)
    G.add_edge(i,V3,INF,base+x-y)
    G.add_edge(i,V4,INF,base+x+y)

for i,(x,y,c) in enumerate(B,N):
    G.add_edge(fr=i, to=sink, cap=c, cost=0)
    G.add_edge(V1,i,INF,base+x+y)
    G.add_edge(V2,i,INF,base+x-y)
    G.add_edge(V3,i,INF,base-x+y)
    G.add_edge(V4,i,INF,base-x-y)

cost = G.MinCost(flow)

answer = base * (2 * flow) - cost
print(answer)

Measured memory_bytes: 121264
#include<iostream>
using namespace std;
int main(){
  string x;
  cin >> x;
  if(x.at(x.size()-1) == '3')
    cout << "bon";
  else if(x.at(x.size()-1) == '0' || x.at(x.size()-1) == '1' || x.at(x.size()-1) == '6' || x.at(x.size()-1) == '8')
    cout << "pon";
  else
    cout << "hon";
}

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

using namespace std;

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

typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<ll> vl;

ll N;
string s;

void solve() {
    cin >> N >> s;
    rep(mask,4) {
        int ani[N];
        ani[0] = mask & 1;
        ani[1] = (mask >> 1) & 1;
        REP(i,2,N) {
            ani[i] = (ani[i-1]) ? ((s[i-1] == 'o')^ani[i-2]) : ((s[i-1] != 'o')^ani[i-2]);
        }
        bool flag1 = ani[0] == (ani[N-1]) ? ((s[N-1] == 'o')^ani[N-2]) : ((s[N-1] != 'o')^ani[N-2]);
        bool flag2 = ani[1] == (ani[0]) ? ((s[0] == 'o')^ani[N-1]) : (s[0] != 'o')^(ani[N-1]);
        if (flag1 && flag2) {
            rep(i,N) cout << (ani[i] ? "W" : "S");
            cout << endl;
            return;
        }
    }
    cout << -1 << endl;
}

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


Measured memory_bytes: 976
// class point	の練習（クラスの高度な実装）
#include <iostream>
#include <iomanip>
using namespace std;



int main() {
	double r;
	double pi = 3.14159265358979323846;

	double men, syu;
	cin >> r;

	men = r * r*pi;
	syu = r * 2 * pi;
	cout <<fixed<< setprecision(6) << men << " " << syu << endl;
	return 0;
}




Measured memory_bytes: 3300
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<iomanip>
#include<math.h>
#include<complex>
#include<queue>
#include<deque>
#include<stack>
#include<map>
#include<set>
#include<bitset>
#include<functional>
#include<assert.h>
#define int long
#define ll long long
#define rep(i, n) for(int i = 0; i < n; i++)
#define IOS cin.tie(0); ios::sync_with_stdio(false)
const int INF = 1e9;
using namespace std;

signed main(){
    int n; cin >> n;
    vector<ll> a(n); rep(i,n) cin >> a[i];
    sort(a.begin(),a.end());
    ll pat1 = 0, pat2 = 0;
    if(n%2){
        rep(i,n/2) pat1 += 2*a[n-i-1];
        rep(i,n/2-1) pat1 -= 2*a[i];
        pat1 -= (a[n/2-1]+a[n/2]);

        rep(i,n/2-1) pat2 += 2*a[n-i-1];
        rep(i,n/2) pat2 -= 2*a[i];
        pat2 += (a[n/2] + a[n/2+1]);
    }else{
        rep(i,n/2-1) pat1 += 2*a[n-i-1];
        pat1 += a[n/2];
        rep(i,n/2-1) pat1 -= 2*a[i];
        pat1 -= a[n/2-1];
        pat2 = pat1;
    }
    cout << max(pat1, pat2) << endl;
}


Measured memory_bytes: 1024
import math
a, b, x = map(int, input().split())
if x >= a*a*b/2:
    l = 2*b - 2*x/(a**2)
    print(math.degrees(math.atan(l/a)))
else:
    l = 2*x/(a*b)
    print(math.degrees(math.atan(b/l)))

Measured memory_bytes: 3060
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<ll,ll>pl;
const ll asize=1e5+5,inf=1e18;

int main(){
	ios_base::sync_with_stdio(0),cin.tie(NULL);
	ld a,b;
	ll c;
	cin>>a>>b;
	a*=b;
	c=a;
	cout<<c;
	return 0;
}

Measured memory_bytes: 3748
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<iomanip>
#include<math.h>
#include<complex>
#include<queue>
#include<deque>
#include<stack>
#include<map>
#include<set>
#include<bitset>
#include<functional>
#include<assert.h>
#include<numeric>
using namespace std;
#define REP(i,m,n) for(int i=(int)(m) ; i < (int) (n) ; ++i )
#define rep(i,n) REP(i,0,n)
using ll = long long;
const int inf=1e9+7;
const ll longinf=1LL<<60 ;
const ll mod=998244353 ;

const int MAX = 3000000;
const int MOD = 998244353;

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

// 二項係数計算
long long COM(int n, int k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}


int main(){
  int N, M; cin >> N >> M; COMinit();
  ll ans = COM(3*M+N-1, N-1); ll igai = 0;
  rep(i, M){
    igai+=(COM(i+N-2, i)*N%mod); igai%=mod;
  }
  for(int i=M+1; i<=min(3*M, N); i++){
    if((3*M-i)%2) continue;
    ll tmp = (3*M-i)/2;
    igai+=(COM(tmp+N-1, tmp)*COM(N, i)%mod);
    igai%=mod;
  }
  ans-=igai; if(ans<0) ans+=mod;
  cout << ans << endl;
}

Measured memory_bytes: 70528
#include<iostream>
#include<stdio.h>
#include<cstring>
using namespace std;
int num[100010];
int father[100010];	
int n,m;
int a,b;
int findfa(int a){
	if(father[a]==a)
		return father[a];
	else{
		father[a] = findfa(father[a]);
		return father[a];
	}
}
void doit(int a,int b){
	if(father[a]==-1&&father[b]==-1){
		father[b] = b;
		father[a] = b;
	}
	else if(father[a]==-1&&father[b]!=-1){
		father[a] = findfa(b);
	}
	else if(father[a]!=-1&&father[b]==-1){
		father[b] = findfa(a);
	}
	else if(father[a]!=-1&&father[b]!=-1){
		father[findfa(a)] = findfa(b);
		father[a] = findfa(b);
	}
}

int main(){
	memset(num,0,sizeof(num));
	memset(father,-1,sizeof(father));
	cin>>n>>m;
	for(int i=1;i<=n;i++)
		cin>>num[i];
	for(int j=0;j<m;j++){
		cin>>a>>b;
		doit(a,b);
	}
	int res = 0;
	for(int i=1;i<=n;i++){
		if(father[i]==-1)
			father[i] = i;
	}
	for(int i=1;i<=n;i++){
		if(findfa(i)- findfa(num[i])==0)
			res++;
	}
	cout<<res<<endl;
}

Measured memory_bytes: 1024
require 'pp'
paths = [[], [], [], []]
3.times do |i|
  a,b = readline.chomp.split.map(&:to_i).map {|x| x-1}
  paths[a].push(b)
  paths[b].push(a)
end

ks = paths.map {|a| a.size }.sort

if ks == [1,1,2,2]
  puts 'YES'
else
  puts 'NO'
end



Measured memory_bytes: 2172
#include<bits/stdc++.h>
#include<cmath>
#define pb push_back
#define ld long double
#define mp make_pair
#define vl vector<ll> 
#define vd vector<double>
#define vld vector<long double>
#define ll long long int
#define pl pair<ll, ll>
#define all(a) a.begin(), a.end()
#define forr(i, n) for(ll i=0; i<n; i++) 
#define forr1(i, n) for(ll i=1; i<=n; i++)
using namespace std;
const ld PI =3.1415926535897923846;
const ll MOD = 1e9+7;
const ll N=998244353;
void solve()
{
    ll n;
    cin>>n;
    string str="";
    while(n)
    {
        ll k=n%26;
        if(k==0)
        k+=26;
        n-=k;
        n/=26;
        str=str+(char)(k-1+'a');
    }
    reverse(all(str));
    cout<<str;
}
int main()
{
    ll test=1;
    //cin>>test;
    while(test--)
        solve();
}

Measured memory_bytes: 3632
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int N,M;
  cin >> N >> M;
  vector<int> toshi(N);
  int left,right;
  
  
  for(int i = 0; i < M; i++){
    cin >> left >> right;
    toshi.at(left - 1)++;
    toshi.at(right - 1)++;
  }
  
  for(int i = 0; i < N; i++){
    cout << toshi.at(i) << endl;
  }
  
  
}

Measured memory_bytes: 3632
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define ld double
#define ll long long
#define all(x) x.begin(),x.end()
const int mod=1e9+7;
#define fi first
#define se second
#define Dracarys  ios_base::sync_with_stdio(false);cin.tie(NULL);
#define inf (ll)1e16

#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")

inline int parity(int x,int y){
    bitset<64> b1(x-y),b2(y);
    ll count=0;
    for (int i=0;i<64;i++){
        if (b1[i] and b2[i])
        count++;
    }
    if (count)
    return 0;
    else
    return 1;
}

int xoor(vector<ll> &rr){
    ll n=rr.size();
    
    ll xo=0;
    for (ll i=0;i<n;i++){
        // (n-1)Ci
        if (rr[i] and (parity(n-1,i)))
        xo^=(rr[i]);
    }
    return xo;
}

void solve(){
    ll n;
    cin>>n;
    vector<ll> v(n),rep(n-1);
    string s;
    cin>>s;
    for (ll i=0;i<n;i++){
        v[i]=(s[i]-'0');
    }
    ll one=0;
    for (ll i=0;i<n-1;i++){
        rep[i]=(abs(v[i]-v[i+1]))%2;
        if (rep[i]){
            one++;
        }
    }
    n--;
    
    if (n==0){
        cout<<abs(v[0]-v[1])<<endl;
        return;
    }
    
    ll xo=0;
    xo=xoor(rep);
    
    if (xo){
        cout<<"1\n";
    }
    else{
        
        for (ll i=0;i<n;i++){
            rep[i]=(abs(v[i]-v[i+1]))/2;
        }
        
        xo=xoor(rep);
        
        if (one){
            cout<<"0\n";
        }
        else{
            if (xo){
                cout<<"2\n";
            }
            else
            cout<<"0\n";
        }
    }
}

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

Measured memory_bytes: 17564
<?php
 
$abc = explode(' ', trim(fgets(STDIN)));
$a = $abc[0];
$b = $abc[1];
$c = $abc[2];

$ans = 'NO';
for($i=1; $i<=$b; $i++){
  if($a*$i%$b == $c) $ans = 'YES';
}

echo $ans;
 
?>

Measured memory_bytes: 4604
#include <iostream>
#include <vector>
#include <algorithm>
#include <iterator>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <string>
#include <cmath>
using namespace std;
#define MOD 1000000007
#define INF 1<<30
#define LINF (ll)1<<62
#define rep(i,n) for(ll i=0; i<(n); i++)
#define REP(i,a,b) for(ll i=(a); i<(b); i++)
#define all(x) (x).begin(),(x).end()
using namespace std;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef pair<ll, ll> P;
typedef vector<pair<ll, ll>> vpl;

int main(){
    ll n; cin >> n;
    vl a(n),b(n),c(n);
    rep(i,n) cin >> a[i];
    rep(i,n) cin >> b[i];
    rep(i,n) cin >> c[i];
    sort(all(a));
    sort(all(b));
    sort(all(c));
    vl s(n,0);
    for(ll i=n-1; i>=0; i--){
        auto itr = upper_bound(all(c), b[i]);
        if(itr == c.end()) continue;
        if(i==n-1) s[i] = distance(itr, c.end());
        else s[i] = s[i+1] + distance(itr, c.end());
    }
    ll ans = 0;
    rep(i,n){
        auto itr = upper_bound(all(b),a[i]);
        ll dist = distance(b.begin(), itr);
        ans += s[dist];
        //cout << s[dist] << " ";
    }
    cout << ans << endl;
}

Measured memory_bytes: 3456
#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>;

int main() {
  ll a, b, c, k;
  cin >> a >> b >> c >> k;
  ll ans = 0;
  
  if(a >= k) {
    ans += k;
    k = 0;
  } else {
    ans += a;
    k -= a; 
  }
  if(b >= k) {
    ans += 0;
    k = 0;
  } else {
    ans += 0;
    k -= b; 
  }
  if(c >= k) {
    ans -= k;
    k = 0;
  } else {
    ans -= c;
    k -= c; 
  }
  cout << ans << endl;
  return 0;
}

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

int main(){
  int h,w,k;
  cin>>h>>w>>k;
  vector<vector<int>> vv(h,vector<int>(w));
  for(int i=0;i<h;i++){
    for(int j=0;j<w;j++){
      char a;
      cin>>a;
      if(a=='#') vv[i][j]++;
    }
  }
  
  int l=pow(2,h+w);
  
  int ans=0;
  for(int i=0;i<l;i++){
    int s=0;
    for(int a=0;a<h;a++){
      for(int b=0;b<w;b++){
        int x=pow(2,a);
        int y=pow(2,h+b);
        if(i/x%2&&i/y%2) s+=vv[a][b];
      }
    }
    if(s==k) ans++;
  }
  
  cout<<ans<<endl;
}


Measured memory_bytes: 4092
#include<cstdio>
#define MAX 10000
#define NIL -1

struct Node {int parent, left, right;};

Node T[MAX];
int n, D[MAX], H[MAX];

void setDepth(int u, int d){ // ??±???d?????????u??????????§????????????????????????¨????????±???????¨????????????¢?????´?????????
	if(u==NIL) return;
	D[u] = d;
	setDepth(T[u].left,d+1);
	setDepth(T[u].right,d+1);
}

int setHeight(int u){ // ??????????????????????????????+1??¨?????????????????????+1??????????????§????????????????????\??????????????¨????????????????????°??????????????¢?????´?????????
	int h1=0,h2=0;
	if(T[u].left != NIL) // ?????????????????¨?????????????????????????????????+1???u???????????¨??????
		h1 = setHeight(T[u].left)+1;
	if(T[u].right != NIL) // ?????¨????§?
		h2 = setHeight(T[u].right)+1;
	return H[u] = (h1 > h2 ? h1 : h2);
}

// ??????u??????????????????
int getSibling(int u){
	if(T[u].parent == NIL) return NIL; // ?????????????????´???
	if(T[T[u].parent].left != u && T[T[u].parent].left != NIL) // ??????????????????????????§????????????????????????????????????????????¨????????´???
	       return T[T[u].parent].left;
	if(T[T[u].parent].right != u && T[T[u].parent].right != NIL) // ?????¨????§?
		return T[T[u].parent].right;
	return NIL;
}

void print(int u){
	printf("node %d: ",u);
	printf("parent = %d, ", T[u].parent);
	printf("sibling = %d, ",getSibling(u));
	int deg = 0; // ????????°
	if(T[u].left != NIL) deg++; // ?????????????????¨????????´???
	if(T[u].right != NIL) deg++;
	printf("degree = %d, ", deg);
	printf("depth = %d, ",D[u]);
	printf("height = %d, ",H[u]);

	if(T[u].parent == NIL){
		printf("root\n");
	}else if(T[u].left == NIL && T[u].right == NIL){
		printf("leaf\n");
	}else{
		printf("internal node\n");
	}
}

int main(){
	int v, l, r, root = 0;
	scanf("%d",&n);

	for(int i=0;i<n;i++) T[i].parent = NIL;

	for(int i=0;i<n;i++){
		scanf("%d %d %d",&v,&l,&r);
		T[v].left = l;
		T[v].right = r;
		if(l != NIL) T[l].parent = v;
		if(r != NIL) T[r].parent = v;
	}

	for(int i=0;i<n;i++) if(T[i].parent == NIL) root = i;

	setDepth(root,0);
	setHeight(root);

	for(int i=0;i<n;i++) print(i);

	return 0;
}

Measured memory_bytes: 2740
//#include<bits/stdc++.h>
#include <iostream>
#include <cstdio>
#include <string>
#include <vector>
#include <queue>
#include <map>
#include <algorithm>
#include <utility>
#include <climits>
#define REP(i, n) for(int i = 0; i < n; ++i)
#define FOR(i, a, b) for(int i = a; i < b; ++i)
#define F first
#define S second
#define OUT(x) cout << (x) << "\n"
using namespace std;
using point = pair< int,int >;
using ll = long long;

int main() {
    int a, b;
    cin >> a >> b;

    if (a + b >= 10) OUT("error");
    else OUT(a + b);
    return 0;
}



Measured memory_bytes: 256
import sys
import math
from collections import Counter
import heapq
try:
    for _ in range(1):
        n,d=map(int,input().split())
        ans=0
        coord=[]
        for i in range(n):
            x,y=map(int,input().split())
            coord.append((x,y))
        for x,y in coord:
            if math.sqrt((x**2+y**2))<=d:
                ans+=1
        print(ans)
        
except:
    pass


Measured memory_bytes: 88408
n, k = list(map(int, input().split()))
p = list(map(int, input().split()))
q = [(1 + p[0]) / 2]
for i in range(1, n):
    q.append(q[i - 1] + ((1 + p[i]) / 2))
s = [q[k - 1]]
for i in range(k, n):
    s.append(q[i] - q[i - k])
print(max(s))


Measured memory_bytes: 24804
#include <bits/stdc++.h>
using namespace std;
const long double PI = acos(-1);
typedef long long ll;
typedef pair<ll,ll> pll;
int dx[]={1,-1,0,0,1,-1,1,-1};
int dy[]={0,0,1,-1,1,-1,-1,1};
#define rep(i,a,b) for (int64_t i = (a); i < (b); i++)
#define REP(i,n) rep(i,0,n)
#define ALL(a) begin(a),end(a)
#define sz(s) (s).size()
#define pb push_back
#define mp make_pair
#define fi first
#define se second

int main()
{   
    string s;
    while(getline(cin,s),s!=".")
    {
        stack<bool>a;
        bool flag=0;
        REP(i,s.size())
        {
            if(s[i]=='(')a.push(0);
            if(s[i]=='[')a.push(1);
            if(s[i]==')')
            {
                if(a.empty())flag=1;
                else if(a.top()==0)a.pop();
                else flag=1;
            }
            if(s[i]==']')
            {
                if(a.empty())flag=1;
                else if(a.top()==1)a.pop();
                else flag=1;
            }
            if(flag){cout<<"no"<<endl;break;}
        }
        if(flag)continue;
        else if(a.empty())cout<<"yes"<<endl;
        else cout<<"no"<<endl;
    }
}


Measured memory_bytes: 3160
W, H, N = map(int, input().split())
xya = [list(map(int, input().split())) for i in range(N)]

x_axis = [0, W]
y_axis = [0, H]

for x, y, a in xya:
    if a == 1 and x_axis[0] <= x:
        x_axis[0] = x

    elif a == 2 and x <= x_axis[1]:
        x_axis[1] = x

    elif a == 3 and y_axis[0] <= y:
        y_axis[0] = y

    elif a == 4 and y <= y_axis[1]:
        y_axis[1] = y

if x_axis[1] - x_axis[0] <=0 or y_axis[1] - y_axis[0] <=0:
    print(int(0))

else:
    print((x_axis[1] - x_axis[0]) * (y_axis[1] - y_axis[0]))

Measured memory_bytes: 3064
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <climits>
#include <cfloat>
#include <ctime>
#include <cassert>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <memory>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <sstream>
#include <complex>
#include <stack>
#include <queue>
#include <numeric>
#include <list>


using namespace std;

#ifdef _MSC_VER
#define __typeof__ decltype
template <class T> int __builtin_popcount(T n) { return n ? 1 + __builtin_popcount(n & (n - 1)) : 0; }
#endif

#define foreach(it, c) for (__typeof__((c).begin()) it=(c).begin(); it != (c).end(); ++it)
#define all(c) (c).begin(), (c).end()
#define rall(c) (c).rbegin(), (c).rend()
#define clear(arr, val) memset(arr, val, sizeof(arr))

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

template <class T> void max_swap(T& a, const T& b) { a = max(a, b); }
template <class T> void min_swap(T& a, const T& b) { a = min(a, b); }

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

const double EPS = 1e-8;
const double PI = acos(-1.0);
const int dx[] = { 0, 1, 0, -1 };
const int dy[] = { 1, 0, -1, 0 };


int main()
{
	int n, m, a[5144], b[5144];
	scanf("%d%d", &n, &m);
	for (int i = 0; i < n; ++i)
		scanf("%d", a + i);
	for (int i = 0; i < m; ++i)
		scanf("%d", b + i);

	int res = 0;
	for (int p = 0; p < m; ++p)
	{
		int i = p, j = 0;
		for (; i < m && j < n; ++j)
			if (b[i] == a[j])
				++i;
		max_swap(res, i - p);
	}
	printf("%d\n", res);
}

Measured memory_bytes: 0
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		String s1 = sc.next();
		String s2 = sc.next();
		String s3 = sc.next();
		
		String a = s1.substring(0,1) + s2.substring(0,1) + s3.substring(0,1);
			System.out.println(a.toUpperCase());
		}
	}

Measured memory_bytes: 23892
N = int(input())
S = (input())

a = []
pc = "."
pi = 0
for i,c in enumerate(S):
    if pc!=c:
        a.append(i-pi)
        pi = i
        pc = c
else:
    a.append(i+1-pi)

l = len(a)
w = 0
b = sum(a[2::2])
ans = w+b
for i in range(1,(l+1)//2):
    #ans = min(ans,sum(a[1:1+i*2:2])+sum(a[2+i*2::2]))
    if -1+i*2 < l:
        w += a[-1+i*2]
    if i*2 < l:
        b -= a[i*2]
    ans = min(ans,w+b)
print(ans)

Measured memory_bytes: 5864
#include<stdio.h>
#include<stdlib.h>
#include<string.h>

typedef struct{
	char marknumber[10];
	int value;
}trump;

void BubbleSort(trump *C,int n);
void SelectionSort(trump *C2,int n);
int isStable(trump *in,trump *out,int n);

int main(void){
	
	int n,i,check;
	trump C[36],C1[36],C2[36];
	
	scanf("%d",&n);
	
	for(i=0;i<n;i++){						//マークと数字を読み込み
		scanf("%s",C[i].marknumber);
		C[i].value=(int)(C[i].marknumber[1])-48;
		strcpy(C1[i].marknumber,C[i].marknumber);
		C1[i].value=C[i].value;
		strcpy(C2[i].marknumber,C[i].marknumber);
		C2[i].value=C[i].value;
	}
	
	BubbleSort(C1,n);////////////////
	
	for(i=0;i<n;i++){
		printf("%s",C1[i].marknumber);
		if(i!=n-1){
			printf(" ");
		}
	}
	printf("\n");
	
	check=isStable(C,C1,n);
	
	if(check==2){
		printf("Not stable\n");
	}
	else if(check==1){
		printf("Stable\n");
	}
	
	SelectionSort(C2,n);/////////
	
	for(i=0;i<n;i++){
		printf("%s",C2[i].marknumber);
		if(i!=n-1){
			printf(" ");
		}
	}
	printf("\n");
	
	check=isStable(C,C2,n);
	
	if(check==2){
		printf("Not stable\n");
	}
	else if(check==1){
		printf("Stable\n");
	}
	
	return 0;
}  

void BubbleSort(trump *C1,int n){
	
	int i,j,tmp1;
	char tmp2[10];
	
	for(i=0;i<n;i++){
		for(j=n-1;j>=i+1;j--){
			if(C1[j].value<C1[j-1].value){
				tmp1=C1[j].value;
				C1[j].value=C1[j-1].value;
				C1[j-1].value=tmp1;
				strcpy(tmp2,C1[j].marknumber);
				strcpy(C1[j].marknumber,C1[j-1].marknumber);
				strcpy(C1[j-1].marknumber,tmp2);
			}
		}
	}
}

void SelectionSort(trump *C2,int n){
	
	int i,j,minj,tmp1;
	char tmp2[10];
	
	for(i=0;i<n;i++){
		minj=i;
		for(j=i;j<n;j++){
			if(C2[j].value<C2[minj].value){
				minj=j;
			}
		}
		tmp1=C2[i].value;
		C2[i].value=C2[minj].value;
		C2[minj].value=tmp1;
		strcpy(tmp2,C2[i].marknumber);
		strcpy(C2[i].marknumber,C2[minj].marknumber);
		strcpy(C2[minj].marknumber,tmp2);
	}
}

int isStable(trump *in,trump *out,int n){
	
	int i,j,a,b;
	
	for(i=0;i<n;i++){
		for(j=i+1;j<n;j++){
			for(a=0;a<n;a++){
				for(b=a+1;b<n;b++){
					if(in[i].value==in[j].value && strcmp(in[i].marknumber,out[b].marknumber)==0 && strcmp(in[j].marknumber,out[a].marknumber)==0){
						return 2;
					}
				}
			}
		}
	}
	
	return 1;
}


Measured memory_bytes: 2092
#include<bits/stdc++.h>
using namespace std;
int main(){
  int n,w;
  cin>>n>>w;
  long long int wt[n+1];
  int val[n+1],sum=0;
  for(int i=1;i<=n;i++)
  {cin>>wt[i]>>val[i];
   sum+=val[i];
  }
 long long  int dp[n+1][sum+1];
  
  for(int x=0;x<=sum;x++)
    dp[1][x]=1e9+7;
    dp[1][0]=0;
  dp[1][val[1]]=wt[1];
  for(int i=2;i<=n;i++){
    for(int v=0;v<=sum;v++){
       dp[i][v]=dp[i-1][v];
      if(val[i]> v) continue;
      dp[i][v]=min(dp[i][v],wt[i]+dp[i-1][v-val[i]]);
      
    }
  }
    
    int ans=0;
    for(int x=0;x<=sum;x++)
      if(dp[n][x]<=w)
        ans=x;  
   
   cout<<ans<<endl;
}
      


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

int main(){
  int h, w;
  while(true){
    cin >> h >> w;
    if(h==0 && w==0){
      break;
    }
    for(int i=0;i<h;i++){
      for(int j=0;j<w;j++){
        cout << "#";
      }
      cout << endl;
    }
    cout << endl;
  }
}



Measured memory_bytes: 3112
#include<iostream>
#include<math.h>
#include<vector>
#include<algorithm>
#include<string.h>
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
long long int mod=1e9+7;
typedef long long ll;
bool debug = false;
class Pair{
	public:
		int a,b;
	Pair(){a=0;b=0;}
	Pair(int _a,int _b){a=_a;b=_b;}
	bool operator <(const Pair&r)const{
		return b<r.b;
	}
	
};
int main(){
	int n;
	cin>>n;
	vector<Pair>wl;
	int a,b;
	rep(i,n){
		cin>>a>>b;
		Pair tmp(a,b);
		wl.push_back(tmp);
	}
	sort(wl.begin(),wl.end());
	if(debug){
		rep(i,wl.size()) cout<<"a="<<wl[i].a<<"b="<<wl[i].b<<endl;
	}
	long long int time=0;
	rep(i,n){
		time+=wl[i].a;
		if(time>wl[i].b){
			if(debug) cout<<"i="<<i;
			cout<<"No"<<endl;
			return 0;
		}
	}
	cout<<"Yes"<<endl;


	
	return 0;
}

Measured memory_bytes: 2420
import java.util.Collections;
import java.util.HashMap;
import java.util.Map;
import java.util.Scanner;
import java.util.TreeMap;
 
public class Main {
 
	public Main() {
		// TODO 自動生成されたコンストラクター・スタブ
	}
 
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		long answer,l,index,index2;
		long a,b,n;
		long h,h2;
		Map <Long,Long> mapH = new HashMap<Long,Long>();
		Map <Long,Long> mapA = new TreeMap<Long,Long>(Collections.reverseOrder());

		String s,t;
		
			// 整数の入力
		
		n = sc.nextInt();
		for(index=0;index<n;index++) {
			h=sc.nextLong();
			mapH.put(index, h);
		}
		sc.close();
		
		answer=0;
		Loop1: for(index=0;index<n;index++) {
			//System.out.println("*:"+index);
			l=0;
			if(index>=n) {
				break Loop1;
			}
			Loop2: for(index2=index+1;index2<n;index2++) {
				h=mapH.get(index2-1);
				h2=mapH.get(index2);
				if(h>=h2) {
				}
				else {
					l=index2-index-1;
					//System.out.println("Loop2:"+index+":"+index2);
					if(l>0) {
						mapA.put(l, index);
					}
					break Loop2;
				}
			}
			if(index2==n) {
				l=n-index-1;
				//System.out.println("Loop2E:"+index+":"+index2);
				if(l>0) {
					mapA.put(l, index);
					//System.out.println("mapA:"+l);
				}
				break Loop1;
			}
			index=index2-1;
		}
		if(mapA.size()==0) {
			System.out.println("0");
		}
		else {
			for (Long lindex : mapA.keySet()) {
			System.out.println(lindex);
			break;
			}
			
		}
			// 出力
 
	}
}	


Measured memory_bytes: 72628
import Control.Monad
main = do
  [h,w]<- fmap (map read . words) getLine
  _ <-  getLine
  a's <- fmap (map read . words) getLine
  let dat = analyze h w a's
  prettyprint dat

analyze :: Int -> Int -> [Int] -> [[Int]]
analyze h w a's = neaten w $ concat [ replicate v u | (u,v) <- zip [1..] a's]

neaten :: Int -> [a] -> [[a]]
neaten w [] = []
neaten w arr = take w arr : map reverse (neaten w (drop w arr))

prettyprint :: [[Int]] -> IO ()
prettyprint ks = forM_ ks $ \k -> do
  putStrLn (unwords . map show $ k)


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

#define ll long long
#define pb push_back
#define mp make_pair
#define boost ios_base::sync_with_stdio(0); cin.tie(0);cout.tie(0)
#define f first
#define se second
#define lb lower_bound
#define ub upper_bound
#define pii pair<double, double>
#define all(x) x.begin(), x.end()

const int N = 3000 + 144, mod = 1e9 + 7, inf = 1e9 + 7;
int n;
double dp[N][N];
double a[N];

ll bp(ll x, ll y){
    if(y == 0)
        return 1;
    if(y & 1)
        return (x * bp(x, y - 1)) % mod;
    ll z = bp(x, y / 2);
    return (z * z) % mod;
}

int main(){
    boost;
    cin >> n;
    for(int i = 1; i <= n; i++){
        cin >> a[i];
    }
    dp[0][0] = 1;
    for(int i = 1; i <= n; i++)
        dp[i][0] = (1 - a[i]) * dp[i - 1][0];
    for(int i = 1; i <= n; i++){
        for(int j = 1; j <= i; j++){
            dp[i][j] = dp[i - 1][j - 1] * a[i] + dp[i - 1][j] * (1 - a[i]);
        }
    }
    double ans = 0;
    for(int i = n / 2 + 1; i <= n; i++){
        ans += dp[n][i];
    }
    cout << fixed << setprecision(9) << ans;
    return 0;
}


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

#define dump(x)  cout << #x << " = " << (x) << endl;

typedef long long ll;
typedef pair<int, int> ii;
const int mod = 1e9+7;
const ll INF = 1e18;
const int inf = 1e9;

void solve()
{
  int n; cin>>n;
  vector<vector<int>> g(n);
  for (int i=0; i<n-1; i++) {
    int u,v; cin>>u>>v;
    g[u-1].push_back(v-1);
    g[v-1].push_back(u-1);
  }
  vector<int> c(n, 0);
  for (int i=0; i<n; i++) {
    cin>>c[i];
  }
  sort(c.rbegin(),c.rend());
  ll ans=0;
  vector<int> v(n);
  queue<int> q;
  q.push(0);
  v[0]=c[0];
  int p=1;
  while(!q.empty()) {
    int r=q.front();
    q.pop();
    for (auto& t: g[r]) {
      if (v[t]!=0) continue;
      q.push(t);
      v[t] = c[p];
      p++;
      ans += min(v[r], v[t]);
    }
  }
  cout << ans << endl;
  for (int i=0; i<n; i++) {
    if (i==0) cout<<v[i];
    else cout<<" "<<v[i];
  }
  cout<<endl;
}

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


Measured memory_bytes: 1024
import math
N = int(input())
f = 0
for a in range(1, N+1):
    for b in range(1, N+1):
        for c in range(1, N+1):
            if b<a or c<a or b>c:
                continue
            elif a==b and b==c:
                d=math.gcd(a, b)
                e=math.gcd(d, c)
                f+=e
                continue
            elif a==b and b!=c:
                d=math.gcd(a, b)
                e=math.gcd(d, c)
                f+=e*3
                continue
            elif b==c and b!=a:
                d=math.gcd(a, b)
                e=math.gcd(d, c)
                f+=e*3
                continue   
            elif a==c and b!=c:
                d=math.gcd(a, b)
                e=math.gcd(d, c)
                f+=e*3
                continue
            else:
                d=math.gcd(a, b)
                e=math.gcd(d, c)
                f+=e*6
                continue
print(f)

Measured memory_bytes: 9260