akhauriyash/Code-Regression huggingface dataset:
import numpy as np
from scipy.sparse.csgraph import floyd_warshall

h,w = map(int,input().split())
d = np.zeros((10,10))
for i in range(10):
    a = list(map(int,input().split()))
    d[i] = a
#print(d)
def WF(b):
    for k in range(10):
        for i in range(10):
            for j in range(10):
                d[i][j] = min(d[i][j],d[i][k] + d[k][j])
    return d
WF(d)
#d = floyd_warshall(d)
L = []
for i in range(h):
    b = list(map(int,input().split()))
    L.append(b)
ans = 0
for i in range(h):
    for j in range(w):
        if L[i][j] == 1 or L[i][j] == -1:
            continue
        else:
            ans += d[L[i][j]][1]
print(int(ans))

Measured memory_bytes: 17404
#include<bits/stdc++.h>
#define fo(i,a,b) for(i=a;i<=b;i++)
#define fd(i,a,b) for(i=a;i>=b;i--)
#define min(a,b) (a<b?a:b)
#define max(a,b) (a>b?a:b)
typedef long long ll;
using namespace std;
const int maxn=4e3+5,mo=1e9+7;
int n,m,ji[maxn],ni[maxn];
int a,b,c,d,i,sum,ans,f[maxn];
int qs(int x,int y){
	int s=1;
	for(;y;y>>=1,x=(ll)x*x%mo) if (y&1) s=(ll)s*x%mo;
	return s;
}
int calc(int n,int m){
	return (ll)ji[n]*ni[m]%mo*ni[n-m]%mo;
}
int main(){
	scanf("%d%d",&n,&m);
	ji[0]=1;
	fo(i,1,n+m) ji[i]=(ll)ji[i-1]*i%mo;
	ni[n+m]=qs(ji[n+m],mo-2);
	fd(i,n+m,1) ni[i-1]=(ll)ni[i]*i%mo;
	fo(a,0,n)
	fo(b,0,n-a) f[a+b]++;
	ans=f[n];
	fo(i,1,n) f[i]+=f[i-1];
	fo(b,1,m-1){
		a=m-b;
		int s1=calc(m-1,a);
		fo(d,1,min(a,m-b)){
			c=a-d;
			sum=n-(a+c);
			if (sum>=0){
				int s2=calc(a-1,c);
				(ans+=(ll)f[sum]*s1%mo*s2%mo)%=mo;
			}
		}
	}printf("%d\n",ans);
	
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std; 
typedef long long ll;
typedef long double ld;
#define pb push_back
#define fi first
#define se second
const ll mod = 1e9+7;
const int N = 2e5+5;
ll cnt[N][33];
void solve(){
	int n,m; 
	cin>>n>>m; 
	for(int i=0;i<n;i++){
		int x,y,c; 
		cin>>x>>y>>c;
		cnt[x+x-1][c]++;
		cnt[y+y][c]--;
	}
	ll mx = 0;
	for(int j=1;j<=m;j++){
		for(int i=1;i<N;i++){
			cnt[i][j]+=cnt[i-1][j];
		}
	}
	for(int i=1;i<N;i++){
		ll trt = 0;
		for(int j=1;j<=m;j++){
			if(cnt[i][j])trt++;
		}
		mx=  max(mx,trt);
	}
	cout<<mx<<endl;
}
int main(){
	ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
	int t=1; 
//	cin>>t; 
	while(t--){
		solve();
	}
	return 0;
}


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

int main() {
    string s;
    cin >> s;
    if (s.at(2) == s.at(3) && s.at(4) == s.at(5)) {
        cout << "Yes" << endl;
    } else {
        cout << "No" << endl;
    }
}

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

using namespace std;

const int N = 3e5 + 10;
const int INF = 1e9;

struct Edge {
  int u, v, cap, flow;
};

namespace Max_flow {

vector<Edge> E;
vector<int> G[N];

int S, T, n, d[N];

void init(int _n, int _s, int _t) {
  n = _n, S = _s, T = _t;
  for (int i = 0; i <= n; i++) G[i].clear();
  E.clear();
}

void addedge(int u, int v, int cap) {
  E.push_back((Edge) {u, v, cap, 0});
  E.push_back((Edge) {v, u, 0, 0});
  int m = E.size();
  G[u].push_back(m - 2);
  G[v].push_back(m - 1);
}

bool bfs() {
  for (int i = 0; i <= n; i++) d[i] = 0;
  d[S] = 1;
  queue<int> q;
  q.push(S);
  while (q.size()) {
    int u = q.front(); q.pop();
    for (int i : G[u]) {
      if (E[i].cap > E[i].flow && !d[E[i].v]) {
        d[E[i].v] = d[u] + 1;
        q.push(E[i].v);
      }
    }
  }
  return d[T];
}

int dfs(int u, int a) {
  if (!a || u == T) return a;
  int flow = 0;
  for (int i : G[u]) {
    if (d[E[i].v] != d[u] + 1) continue;
    int f = dfs(E[i].v, min(E[i].cap - E[i].flow, a));
    flow += f;
    a -= f;
    E[i].flow += f;
    E[i ^ 1].flow -= f;
  }
  if (!flow) d[u] = 0;
  return flow;
}

int max_flow() {
  int flow = 0;
  while (bfs()) {
    flow += dfs(S, INF);
  }
  return flow;
}

}

int n, c[N], p[N], q[N], vis[N];
vector<int> g[N], bel[N];

int main() {
  scanf("%d", &n);
  Max_flow::init(2 * n + 1, 0, 2 * n + 1);
  for (int i = 1; i < n; i++) {
    scanf("%d", &c[i]);
    g[i].resize(c[i]);
    Max_flow::addedge(0, i, 1);
    for (int j = 0; j < c[i]; j++) {
      scanf("%d", &g[i][j]);
      bel[g[i][j]].push_back(i);
      Max_flow::addedge(i, g[i][j] + n, 1);
    }
  }
  for (int i = 1; i <= n; i++) {
    Max_flow::addedge(i + n, 2 * n + 1, 1);
  }
  if (Max_flow::max_flow() != n - 1) {
    puts("-1");
    return 0;
  }
  for (Edge e : Max_flow::E) {
    if (e.u <= n && e.v > n && e.cap == e.flow) {
      p[e.u] = e.v - n;
      vis[e.v - n] = 1;
    }
  }
  queue<int> tmp;
  for (int i = 1; i <= n; i++) {
    if (!vis[i]) tmp.push(i);
    vis[i] = 0;
  }
  int cnt = 0;
  while (tmp.size()) {
    cnt++;
    int u = tmp.front(); tmp.pop();
    for (int i : bel[u]) if (!vis[i]) {
      vis[i] = 1;
      q[i] = u;
      tmp.push(p[i]);
    }
  }
  if (cnt != n) {
    puts("-1");
    return 0;
  }
  for (int i = 1; i < n; i++) {
    printf("%d %d\n", p[i], q[i]);
  }
  return 0;
}


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

# define C continue;
# define R return

# define D double
# define I insert
# define ll long long
# define ld long double

# define ull unsigned long long
# define ui unsigned int

# define pb push_back
# define pf push_front

# define vi vector < int >
# define vc vector < char >
# define vs vector < string >
# define vb vector < bool >
# define vd vector < D >
# define vll vector < ll >
# define vull vector < ull >
# define vld vector < ld >
# define PQ priority_queue

# define vvi vector < vector < int > >
# define vvb vector < vector < bool > >
# define vvc vector < vector < char > >
# define vvll vector < vector < ll > >
# define vvd vector < vector < D > >
# define vvld vector < vector < ld > >

# define all(v) (v).begin() , (v).end()
# define allrev(v) (v).rbegin() , (v).rend()
# define allcomp(v) v.begin() , v.end() , comp
# define allrevcomp(v) v.rbegin() , v.rend() , comp

# define pii pair < int , int >
# define pll pair < ll , ll >
# define pld pair < ld , ld >
# define pDD pair < D , D >

# define vpld vector < pld >
# define vpii vector < pii >
# define vpll vector < pll >
# define vpDD vector < pDD >

# define vvpii vector < vector < pii > >
# define F first
# define S second
# define mp make_pair

# define dist(a,b,p,q) sqrt((p-a)*(p-a) + (q-b)*(q-b))

# define pp(n) printf("%.10Lf",n);
# define line cout<<"\n";
# define fast ios_base::sync_with_stdio(false) ; cin.tie(0) ; cout.tie(0);

string vow = "aeiou";
int month[] = {-1, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};

const int dxhorse[] = {-2, -2, -1, -1, 1, 1, 2, 2};
const int dyhorse[] = {1, -1, 2, -2, 2, -2, 1, -1};

const int dx[] = { -1 , 0 , 0 , 1 } ;
const int dy[] = { 0 , -1 , 1 , 0 } ;

const ld pie = 3.14159265358979 ;
const ll mod = 1e9 + 7 ;

// Tip : ceil ( a/b ) = 1 + floor( (a-1)/b ) !

void solve ( int test_case )
{
    int n ;
    cin >> n ;

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

    vi b ( n ) ;
    for ( int i=0 ; i < n ; i ++ ) cin >> b[i] ;

    vi v ( n ) ;
    for ( int i=0 ; i < n ; i ++ )
        v[i] = i + 1 ;

    int aa = -1 ;
    int bb = -1 ;

    int cnt = 0 ;

    do
    {
        if ( v == a )
            aa = cnt ;

        if ( v == b )
            bb = cnt ;

        cnt ++ ;
        if ( aa != -1 && bb != -1 )
            break ;

    }while ( next_permutation ( all ( v ) ) ) ;

    cout << abs ( aa-bb) ;
}

int main()
{
    int t = 1;
    // cin >> t;

    for ( int i=0 ; i < t ; i++ ) solve(i);
    return 0;
}


Measured memory_bytes: 256
import sys
input = sys.stdin.buffer.readline

N = int(input())
T, A = map(int, input().split())
H = list(map(int, input().split()))

answer = -1
dif = 10 ** 15
for i, h in enumerate(H, 1):
    if abs(A - (T - h * 0.006)) < dif:
        answer = i
        dif = abs(A - (T - h * 0.006))

print(answer)

Measured memory_bytes: 3064
import sys
rectangle=0
rhombus=0
for length in sys.stdin:
    e1,e2,diag=map(int,length.split(","))
    if (e1**2+e2**2 == diag**2):
        rectangle+=1
    if (e1==e2 and e1+e2>diag):
        rhombus+=1

print rectangle
print rhombus

Measured memory_bytes: 4196
package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
)

func main() {
	n := getInt()
	as := getIntSlice(n)

	m := make(map[int]int)
	for _, a := range as {
		m[a]++
	}

	ans := 1
	for k, v := range m {
		if (k == 0 && v != 1) || (k != 0 && v != 2) {
			ans = 0
			break
		}

		ans = (ans * v) % 1000000007
	}

	fmt.Println(ans)
}

// -----------------------------------------

var scanner = wordScanner()

func wordScanner() *bufio.Scanner {
	sc := bufio.NewScanner(os.Stdin)
	sc.Split(bufio.ScanWords)
	return sc
}

func getInt() int {
	scanner.Scan()
	i, err := strconv.Atoi(scanner.Text())
	if err != nil {
		panic(err)
	}
	return i
}

func getIntSlice(n int) []int {
	ans := make([]int, n)
	for i := range ans {
		ans[i] = getInt()
	}
	return ans
}

func getString() string {
	scanner.Scan()
	s := scanner.Text()
	return s
}


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

int main(){
    string s;
    cin >> s;
    int count, n;
    count = 0;
    n = s.size() - 1;
    
    for(int i = 0; i < n; i++){
        if(s.at(i) != s.at(n - i)){
            s.at(n - i) = s.at(i);
            count += 1;
        }
    }
    cout << count << endl;
    return 0;
}

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

int main() {
  string a, b, c;
  cin >> a >> b >> c;
  
  char A = toupper(a[0]);
  char B = toupper(b[0]);
  char C = toupper(c[0]);

  cout << A << B << C << endl;
}


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

int N;
int S[500010] = {0};
int dp[500010][5] = {0};
int ans = 0;

int main()
{
    scanf("%d",&N);
    for(int i = 0; i < N; i++)
    {
        char s;
        scanf(" %c",&s);
        S[i] = s - '0';
    }

    for(int i = 0; i < N; i++)
    {
        if(S[i] == 1)
        {
            vector<int> V;
            int l = i,r = i;
            int mem = 1;
            while(1)
            {
                if(r >= N - 1)
                {
                    if(S[i] == 0)V.push_back(mem - 1);
                    else V.push_back(mem);
                    break;
                }
                if((S[r] == 0 && S[r + 1] == 0))
                {
                    V.push_back(mem - 1);
                    break;
                }
                if(S[r] == 0)
                {
                    V.push_back(mem - 1);
                    mem = 0;
                }
                mem++;
                r++;
                i++;
            }

            if(V.size() != 1)
            {
                dp[l][0] = 0;
                dp[l][1] = V[0];
                dp[l][2] = V[1];
                for(int j = 1; j < V.size() - 1; j++)
                {
                    dp[j + l][0] = max(dp[j + l - 1][0],
                                   max(dp[j + l - 1][1],dp[j + l - 1][2]));
                    dp[j + l][1] = max(dp[j + l - 1][0] + V[j],
                                   max(dp[j + l - 1][1] + V[j] - 1,dp[j + l - 1][2]));
                    dp[j + l][2] = dp[j + l - 1][0] + V[j + 1];
                    if(V[j] != 1)dp[j + l][2] = max(dp[j + l][2],
                                                max(dp[j + l - 1][1] + V[j + 1],dp[j + l - 1][2] + V[j + 1] - 1));
                }
                ans += (dp[V.size() - 2 + l][0],max(dp[V.size() - 2 + l][1],dp[V.size() - 2 + l][2]));
            }
        }
    }
    printf("%d\n",ans);
    return 0;
}


Measured memory_bytes: 12032
n = int(input())
a = list(map(int, input().split()))
num_2 = 0
num_4 = 0
for i in a:
    if i % 4 == 0:
        num_4 += 1
    elif i % 2 == 0:
        num_2 += 1
x = num_4 * 2
if num_4 >= n // 2:
    print("Yes")
elif num_2 >= n - x:
    print("Yes")
else:
    print("No")

Measured memory_bytes: 14252
import sys
sys.setrecursionlimit(5*10**5)
input = sys.stdin.readline

N, Q = map(int, input().split())
ab=[]
for _ in range(N-1):
    ab.append(tuple(map(int, input().split())))
px=[]
for _ in range(Q):
    px.append(tuple(map(int, input().split())))

cnt=[0]*(N+1)
for el in px:
    cnt[el[0]] += el[1]
#print(cnt)


lst=[[] for _ in range(N+1)]
for el in ab:
    lst[el[0]].append(el[1])
    lst[el[1]].append(el[0])
#print(lst)

seen = [False] * (N + 1)
def dfs(n):
    seen[n] = True
    for child in lst[n]:
        if seen[child] == False:
            cnt[child]+=cnt[n]
            dfs(child)

dfs(1)
#print(cnt)
print(' '.join(list(map(str, cnt[1:]))))

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

int main(){
    int n;
    cin>>n;
    int a[200000][3];
    for(int i=0;i<n;i++){
        for(int j=0;j<3;j++){
            cin>>a[i][j];
        }
    }
    int dp[200000][3];
    dp[0][0]=a[0][0];
    dp[0][1]=a[0][1];
    dp[0][2]=a[0][2];

    for(int i=1;i<n;i++){
        for(int j=0;j<3;j++){
            dp[i][j]=max(dp[i-1][(j+1)%3],dp[i-1][(j+2)%3])+a[i][j];
        }
    }
   // cout<<dp[n-1][2]<<endl;
    cout<<max(dp[n-1][0],max(dp[n-1][1],dp[n-1][2]));
}

Measured memory_bytes: 4480
#include <bits/stdc++.h>
typedef long long int lint;

#define PI acos(-1)
#define INF64 1LL << 60
#define INF32 1 << 29
#define all(a) (a).begin(), (a).end()
#define INV ((long long int)1000000007)

using namespace std;

struct SegmentTree
{
	vector<int> data;
	vector<int> size;

	SegmentTree(int n)
	{
		size = vector<int>(n, 1);
		for (int i = 0; i < n; i++)
		{
			data.push_back(i);
		}
	}

	int Root(int n)
	{
		if (data[n] == n)
			return n;

		return Root(data[n]);
	}

	void Union(int n, int m)
	{
		n = Root(n);
		m = Root(m);

		if (Check(n, m))
			return;

		if (size[n] < size[m])
			swap(n, m);

		size[n] += size[m];
		data[m] = n;
	}

	bool Check(int n, int m)
	{
		return Root(n) == Root(m);
	}

	int Size(int n)
	{
		return size[Root(n)];
	}
};

void execute()
{
	int N, M;
	cin >> N >> M;
	vector<int> data(N, 0);
	int ans = 0;
	for (int i = 0; i < N; i++)
	{
		int a;
		cin >> a;
		data[a - 1] = i;
	}

	SegmentTree tree(N);
	for (int i = 0; i < M; i++)
	{
		int a, b;
		cin >> a >> b;
		tree.Union(a - 1, b - 1);
	}

	for (int i = 0; i < N; i++)
	{
		if (tree.Check(i, data[i]))
			ans++;
	}

	cout << ans << endl;
	return;
}

int main()
{
	cin.tie(0);
	ios_base::sync_with_stdio(false);
	std::cout << std::fixed << std::setprecision(15);
	execute();

	int stop;
	cin >> stop;

	return 0;
}

Measured memory_bytes: 1660
N = int(input())
X = [[int(x), i] for i,x in enumerate(input().split())]
M = sorted(X)
median = N // 2
for i in range(N):
    X[M[i][1]][1] = i
for i in range(N):
    print(M[median][0] if X[i][1] < median else M[median-1][0])

Measured memory_bytes: 51392
#include <iostream>

int main() {
  int n, a, b, c, d;

  std::cin >> n;
  std::cin >> a;
  std::cin >> b;
  std::cin >> c;
  std::cin >> d;

  int qty_x = n % a == 0 ? n / a : (n / a) + 1;
  int qty_y = n % c == 0 ? n / c : (n / c) + 1;

  int cost_x = qty_x * b;
  int cost_y = qty_y * d;

  if (cost_x <= cost_y) {
    std::cout << cost_x << std::endl;
  } else {
    std::cout << cost_y << std::endl;
  }

  return 0;
}



Measured memory_bytes: 3116
n = int(input())
h = list(map(int, input().split()))

ans = -float('inf')
k = 0
for i in range(n-1):
  if int(h[i]) >= int(h[i+1]):
    k = k + 1
    if ans < k:
      ans = k
  else:
    k = 0
if ans == -float('inf'):
  ans = 0
print(ans)

Measured memory_bytes: 14224
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int main() {
    int N;
    cin >> N;
    map<int, ll> mp;
    ll S = 0;
    for (int i = 0; i < N; i++) {
        int A;
        cin >> A;
        mp[A]++;
        S += A;
    }
    int Q;
    cin >> Q;
    for (int i = 0; i < Q; i++) {
        int B, C;
        cin >> B >> C;
        S += (C-B)*mp[B];
        mp[C] += mp[B];
        mp[B] = 0;
        cout << S << endl;
    }
}

Measured memory_bytes: 9440
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0;i < n;i++)
#define REPR(i, n) for(int i = n;i >= 0;i--)
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define FORR(i, m, n) for(int i = m;i >= n;i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define ll long long
#define pb(a) push_back(a)
#define INF 1000000000
using namespace std;
typedef pair<int, int> P;
typedef pair<ll, ll> LP;
typedef pair<int, P> PP;
typedef pair<ll, LP> LPP;

int dy[]={0, 0, 1, -1, 0};
int dx[]={1, -1, 0, 0, 0};

int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  int n;
  cin >> n;
  vector<int> odd(n/2);
  vector<int> even(n/2);
  
  REP(i,n/2){
      cin >> odd[i];
      cin >> even[i];
  }
  
  auto f = [](vector<int>a, int rej=-1){
    int N = (int)a.size();
    vector<int> Map(1e5 +10, 0);
    REP(i,N){
      if(a[i]==rej) continue;
      Map[a[i]]++;
    }
    int Max=0;
    int id=0;
    REP(i,1e5+10){
      if(Max<Map[i]){
        Max = Map[i];
        id = i;
      }
    }
    return P(N-Max,id);
  };

  int ans=0;
  P odd1=f(odd);//奇数の1位
  P odd2=f(odd,odd1.second);
  P even1=f(even);//偶数の1位
  P even2=f(even,even1.second);
  
  if(odd1.second==even1.second){
    ans = min(odd1.first+even2.first,odd2.first+even1.first);
  }
  else{
    ans = odd1.first + even1.first;
  }
  
  cout << ans << endl;
  
}


Measured memory_bytes: 1280
use std::io::stdin;
use std::str::FromStr;
#[allow(dead_code, unused_mut)]
fn read<T: FromStr>() -> T {
    let mut s = String::new();
    stdin().read_line(&mut s).ok();
    s.trim().parse().ok().expect("1")
}
#[allow(dead_code, unused_mut)]
fn read_vec<T: FromStr>() -> Vec<T> {
    read::<String>().split_whitespace()
        .map(|e| e.parse().ok().expect("2"))
        .collect()
}
#[allow(dead_code, unused_mut)]
fn read_two<T: FromStr>() -> (T, T) {
    let mut s = String::new();
    stdin().read_line(&mut s).unwrap();
    let mut x = s.split_whitespace().map(|x| x.parse().ok().unwrap());
    (x.next().unwrap(), x.next().unwrap())
}
#[allow(dead_code, unused_mut)]
fn read_three<T: FromStr>() -> (T, T, T) {
    let mut s = String::new();
    stdin().read_line(&mut s).unwrap();
    let mut x = s.split_whitespace().map(|x| x.parse().ok().unwrap());
    (x.next().unwrap(), x.next().unwrap(), x.next().unwrap())
}
fn main() {
    let n: i32 = read();
    let x = (n as f64 / 1.08) as i32;
    let a = (x as f64 * 1.08) as i32;
    let b = ((x + 1) as f64 * 1.08) as i32;
    let c = ((x - 1) as f64 * 1.08) as i32;
    if n == a {
        println!("{}", x);
    } else if n == b {
        println!("{}", x + 1);
    } else if n == c {
        println!("{}", x - 1);
    } else {
        println!(":(");
    }
}

Measured memory_bytes: 4352
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define Yes                \
    cout << "Yes" << endl; \
    return 0;
#define No                \
    cout << "No" << endl; \
    return 0;
using namespace std;
using ll = long long;
const int INF = 1001001001;
const int MOD = 1000000007;
typedef long long ll;
 
template <typename T>
void print(const T &v);
 
int main()
{
    int n;
    ll k;
    cin >> n >> k;
    vector<int> a(n);
    rep(i, n) cin >> a[i];
 
    vector<int> s;
    vector<int> ord(n + 1, -1);
    int c = 1, l = 0;
    {
        int v = 1;
        while (ord[v] == -1)
        {
            ord[v] = s.size();
            s.push_back(v);
            v = a[v - 1];
        }
        c = s.size() - ord[v];
        l = ord[v];
    }
    if (k < l)
        cout << s[k] << endl;
    else
    {
        k -= l;
        k %= c;
        cout << s[l + k] << endl;
    }
    return 0;
}
 
// Use For Debug
template <typename T>
void print(T const &v)
{
    for (int i = 0; i < v.size(); i++)
    {
        if (i)
            cout << " ";
        cout << v[i];
    }
    cout << endl;
}

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

using namespace std;

const int N = 100005;

int n, par[N];
int col[N];
int vis[N];
vector <int> g[N];

void dfs(int at, int pa){
	par[at] = pa;
	for(auto u : g[at]){
		if(u == pa) continue;
		dfs(u, at);
	}
}

int ffs(int at){
	vis[at] = 1;
	int ret = 1;
	for(auto u : g[at]){
		if(vis[u]) continue;
		if(col[u] == 0){
			col[u] = col[at];
			ret += ffs(u);
		}
		else if(col[u] == col[at]){
			ret += ffs(u);
		}
	}
	return ret;
}

int main(){
	int x, y;
	scanf("%d", &n);
	for(int i = 2; i <= n; ++i){
		scanf("%d %d", &x, &y);
		g[x].push_back(y);
		g[y].push_back(x);
	}
	dfs(1, 0);
	int cur = n;
	vector <int> path;
	while(cur){
		path.push_back(cur);
		cur = par[cur];
	}
	reverse(path.begin(), path.end());
	int m = path.size();
	for(int i = 0; i < (m + 1) / 2; ++i){
		col[path[i]] = 1;
	}
	for(int i = (m + 1) / 2; i < m; ++i){
		col[path[i]] = 2;
	}
	int aa = ffs(1);
	int bb = ffs(n);
	if(aa > bb) printf("Fennec\n");
	else printf("Snuke\n");
	return 0;
}

Measured memory_bytes: 12152
#include <bits/stdc++.h>
 
using namespace std;
 
#define MAX 1000
#define INF 1e9
typedef pair<int,int> pii;
 
int H,W[MAX];
string s[MAX];
bool visited[MAX][80];
vector<pii> vec[10000];
const int dx[8] = {-1,0,0,1,-1,-1,1,1};
const int dy[8] = {0,-1,1,0,-1,1,-1,1};
 
bool inField(int x,int y){
    if(0 > y || y >= H){
	return false;
    }
    if(0 > W[y] || W[y] <= x){
	return false;
    }
    return true;
}
 
void dfs(int x,int y,int idx){
    if(s[y][x] != '*') return;
    s[y][x] = ' ';
    vec[idx].push_back(pii(x,y));
 
    for(int i = 0 ; i < 8 ; i++){
	int nx = x + dx[i];
	int ny = y + dy[i];
	if(!inField(nx,ny)) continue;
	dfs(nx,ny,idx);
    }
}
 
int getArea(vector<pii> &v){
    int px[4] = {INF,0,INF,0};
    int py[4] = {INF,INF,0,0};
    for(int i = 0 ; i < (int)v.size() ; i++){
	int x = v[i].first,y = v[i].second;
	if(y < py[0]){
	    px[0] = px[1] = x;
	    py[0] = py[1] = y;
	}else if(y == py[0]){
	    if(x < px[0]){
		px[0] = x;
	    }else if(px[1] < x){
		px[1] = x;
	    }
	}
	if(py[2] < y){
	    px[2] = px[3] = x;
	    py[2] = py[3] = y;
	}else if(py[2] == y){
	    if(x < px[2]){
		px[2] = x;
	    }else if(px[3] < x){
		px[3] = x;
	    }
	} 
    }
    return ((px[1]-px[0]+1)+(px[3]-px[2]+1))*(py[2]-py[0]+1)/2;
}
 
int main(){
    bool flg = false;
    while(cin >> H,H){
	if(flg){
	    cout << "----------" << endl;
	}
	flg = true;
	cin.ignore();
	for(int i = 0 ; i < 10000 ; i++){
	    vec[i].clear();
	}
	for(int i = 0 ; i < H ; i++){
	    getline(cin,s[i]);
	    W[i] = s[i].size();
	}
	int idx = 0;
	for(int i = 0 ; i < H ; i++){
	    for(int j = 0 ; j < W[i] ; j++){
		if(s[i][j] == '*'){
		    dfs(j,i,idx); idx++;
		}
	    }
	}
	map<int,int> cnt;
	for(int i = 0 ; i < idx ; i++){
	    int area = getArea(vec[i]);
	    cnt[area]++;
	}
	map<int,int>::iterator it;
	for(it = cnt.begin() ; it != cnt.end() ; ++it){
	    cout << it->first << " " << it->second << endl;
	}
    }
    return 0;
}

Measured memory_bytes: 1540
// A. 

#include <iostream>
#include <algorithm>
#include <sstream>
#include <cstdio>
#include <cstring>

using namespace std;
typedef long long LL;

int main(int argc, char *argv[])
{
	LL a[3];
	cin >> a[0] >> a[1] >> a[2];
	sort(a, a + 3);
	LL ans = (a[2] % 2) * a[0] * a[1];
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<bitset>
using namespace std;
int n,a[2010];
bitset<4000000> bs;
int main()
{
	int n;scanf("%d",&n);int sum=0;
	for(int i=1;i<=n;i++)scanf("%d",&a[i]),sum+=a[i];
	sum=(sum+1)/2;
	sort(a+1,a+n+1);bs[0]=1;
	for(int i=1;i<=n;i++)bs|=(bs<<a[i]);
	for(int i=sum;i<=4000000;i++)
		if(bs[i])return 0*printf("%d",i);
	return 0;
 } 

Measured memory_bytes: 1664
#define LOCAL

#undef _GLIBCXX_DEBUG

#include <bits/stdc++.h>
using namespace std;

#define IOS ios::sync_with_stdio(false);cin.tie(0)
#define all(x) x.begin(), x.end()
#define ff first
#define ss second
#define LLINF 1e18
#define INF (int)1e9+1

// Copied from Gennady-Korotkevich's template

template <typename A, typename B>
string to_string(pair<A, B> p);

template <typename A, typename B, typename C>
string to_string(tuple<A, B, C> p);

template <typename A, typename B, typename C, typename D>
string to_string(tuple<A, B, C, D> p);

string to_string(const string& s) {
	return '"' + s + '"';
}

string to_string(const char* s) {
	return to_string((string)s);
}

string to_string(bool b) {
	return (b ? "true" : "false");
}

string to_string(vector<bool> v) {
	bool first = true;
	string res = "{";
	for (int i = 0; i < static_cast<int>(v.size()); i++) {
		if (!first) {
			res += ", ";
		}
		first = false;
		res += to_string(v[i]);
	}
	res += "}\n";
	return res;
}

template <size_t N>
string to_string(bitset<N> v) {
	string res = "";
	for (size_t i = 0; i < N; i++) {
		res += static_cast<char>('0' + v[i]);
	}
	return res;
}

template <typename A>
string to_string(A v) {
	bool first = true;
	string res = "{";
	for (const auto& x : v) {
		if (!first) {
			res += ", ";
		}
		first = false;
		res += to_string(x);
	}
	res += "}\n";
	return res;
}

template <typename A, typename B>
string to_string(pair<A, B> p) {
	return "(" + to_string(p.first) + ", " + to_string(p.second) + ")";
}

template <typename A, typename B, typename C>
string to_string(tuple<A, B, C> p) {
	return "(" + to_string(get<0>(p)) + ", " + to_string(get<1>(p)) + ", " + to_string(get<2>(p)) + ")";
}

template <typename A, typename B, typename C, typename D>
string to_string(tuple<A, B, C, D> p) {
	return "(" + to_string(get<0>(p)) + ", " + to_string(get<1>(p)) + ", " + to_string(get<2>(p)) + ", " + to_string(get<3>(p)) + ")";
}

template <typename A, typename B, typename C, typename D, typename E>
string to_string(tuple<A, B, C, D, E> p) {
	return "(" + to_string(get<0>(p)) + ", " + to_string(get<1>(p)) + ", " + to_string(get<2>(p)) + ", " + to_string(get<3>(p)) + "," + to_string(get<4>(p)) + ")";
}

void debug_out() {
	cerr << endl;
}

template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
	cerr << " " << to_string(H);
	debug_out(T...);
}

#ifdef LOCAL
#define debug(...) cerr << "\n[" << #__VA_ARGS__ << "]:\n", debug_out(__VA_ARGS__)
#else
#define debug(...) 42
#endif

// End of Gennady-Korotkevich's template 

using llong = long long;
using PII = pair<int, int>;

const llong MOD = 1e9 + 7;
const double PI = acos(-1);

int main() {
	IOS;
	string s; cin >> s;
	for (int i = 0; i < 3; i++) cout << s[i];
}

Measured memory_bytes: 3648
#include <iostream>
#include <string>
#include <vector>
#include <set>
#include <stack>
#include <queue>
#include <map>
#include <algorithm>
#include <iomanip>
#include <math.h>
#include <string.h>
using namespace std; using ll = long long; using pll = pair<ll, ll>;
using vl = vector<ll>; using vll = vector<vl>; using vpll = vector<pll>;
int ctoi(char c) {
	switch (c) {
	case '0': return 0; case '1': return 1; case '2': return 2;
	case '3': return 3; case '4': return 4; case '5': return 5;
	case '6': return 6; case '7': return 7; case '8': return 8;
	case '9': return 9;  default: return 0;
	}
}
bool pairCompare(const pll firstElof, pll secondElof)
{ return firstElof.second < secondElof.second; }
//**Snippetリスト**//
//rep, vin, all//
//gcdlcm, isPrime, eratos, modinv, bitSearch, dfs, bfs, dijkstra, UnionFind, COM, digitDP//
ll i, j, k, l, m, n; ll N, M, K, H, W, L; 
ll MOD = 1000000007; ll INF = 9999999999999; ll ans = -1;
vl flag, color; vll path; vl D; ll S, T;
//***********//
void bfs(ll now) {
	queue<ll> Q;
	Q.push(now);
	D[now] = 0;
	flag[now]++;
	ll u;
	while (!Q.empty()) {
		u = Q.front();
		if ((u-T)%N==0 && D[u]%3==0) {
			if (ans == -1) ans = D[u] / 3;
			else ans = min(ans, D[u] / 3);
		}
		//cout << u;
		Q.pop();
		for (ll v = 0; v < path[u].size(); v++) {
			ll next = path[u][v];
			if (flag[next]==0) {
				D[next] = D[u] + 1;
				flag[next] = 1;
				Q.push(next);
			}
		}
	}
}
int main() {
	cin >> N >> M;
	path.resize(N*3);
	flag.resize(N*3);
	D.resize(N*3);
	for (i = 0; i < M; i++) {
		ll u, v;
		cin >> u >> v;
		path[u - 1].push_back(v + N - 1);
		path[u + N - 1].push_back(v + N*2 - 1);
		path[u + N*2 - 1].push_back(v - 1);
	}
	for (i = 0; i < N*3; i++) {
		flag[i] = 0;
	}
	cin >> S >> T;
	S--, T--;
	bfs(S);
	cout << ans;
}


Measured memory_bytes: 21376
s = input()
K = int(input())
n = len(s)

dp = [[[0]*5 for _ in range(2)] for _ in range(10001)]
dp[0][0][0] = 1

for i in range(n):
  for k in range(K+1):
    x = int(s[i])
    
    dp[i+1][1][k+1] += dp[i][1][k] * 9
    dp[i+1][1][k]   += dp[i][1][k]        
    
    if x > 0:
      dp[i+1][1][k+1] += dp[i][0][k] * (x-1)
      dp[i+1][1][k]   += dp[i][0][k]
      dp[i+1][0][k+1] = dp[i][0][k]
    else:
      dp[i+1][0][k] = dp[i][0][k]
      
print( dp[n][0][k]+ dp[n][1][k])      


Measured memory_bytes: 6388
#include<bits/stdc++.h>
using namespace std;
char b[8][20]={"dreameraser","dreamerase","dream","dreamer","erase","eraser"};
string c;
int pan(int i,int j,int f)
{
    for(int k=i,cnt=0;k<j;k++)
    {
        if(c[k]!=b[f][cnt++])
            return false;
    }
    return true;
}
bool judge()
{
    int len=c.size();
    for(int i=0;i<2*len;i++)
    {
        if(pan(i,i+11,0))
            i+=10;
        else if(pan(i,i+10,1))
            i+=9;
        else if(pan(i,i+7,3))
            i+=6;
        else if(pan(i,i+5,2))
            i+=4;
        else if(pan(i,i+6,5))
            i+=5;
        else if(pan(i,i+5,4))
            i+=4;
        else return false;
        if(i==len-1) return true;
    }
}
int main()
{
    while(cin>>c)
    {
        if(judge())
            printf("YES\n");
        else printf("NO\n");
    }
}


Measured memory_bytes: 512
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace AtCoder
{
	class Program
	{
		static void Main(string[] args)
		{
			var n = int.Parse(Console.ReadLine());
			var sList = new List<List<char>>();


			for(var i = 0; i < n; i++)
			{
				sList.Add(Console.ReadLine().ToList());
				sList[i].Sort();
			}

			for (var i = 1; i < n; i++)
			{
				var index1 = 0;
				var index2 = 0;

				while(index1 < sList[0].Count && index2 < sList[i].Count)
				{
					if(sList[0][index1] == sList[i][index2])
					{
						index1++;
						index2++;
					}
					else if(sList[0][index1] < sList[i][index2])
					{
						sList[0].RemoveAt(index1);
					}
					else
					{
						index2++;
					}
				}

				if(index1 < sList[0].Count)
				{
					sList[0].RemoveRange(index1, sList[0].Count - index1);
				}
			}
			
			foreach(var c in sList[0])
			{
				Console.Write(c);
			}
			Console.WriteLine();
		}
	}
}


Measured memory_bytes: 13396
#include <iostream>
#include <bitset>
#include <vector>
#include <string>
#include <algorithm>
#include <set>
#include <map>
#include <cmath>
#include <regex>
#include <iomanip>
#include <climits>
#include <utility>
#include <queue>
using namespace std;
using ll = long long int;
using dd = long double;
const ll MOD = 1e9 + 7;

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

struct Fish
{
    ll beauty;
    ll taste;
};

ll fact(ll n)
{
    if (n == 0)
    {
        return 1;
    }
    if (n == 1)
    {
        return 1;
    }
    return n * fact(n - 1) % MOD;
}

int main()
{
    map<string, ll> BLUE;
    map<string, ll> RED;

    ll N;
    cin >> N;
    for (ll i = 0; i < N; i++)
    {
        string s;
        cin >> s;
        BLUE[s] += 1;
    }
    
    ll M;
    cin >> M;
    for (ll i = 0; i < M; i++)
    {
        string s;
        cin >> s;
        RED[s] += 1;
    }
    
    ll ans = 0;
    for (auto &&e : BLUE)
    {
        ans = max(ans, e.second - RED[e.first]);
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
#include <algorithm>
#include <bitset>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <ctime>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <utility>
#include <vector>


using namespace std;

int main(){

	long long mm = 0, mn = 1000000002, N;

	cin >> N;

	for(int i = 0; i<N ; i++){
		long long x;
		cin >> x;
		mn = min(mn, x);
		mm = max(mm, x);
	}

	cout << mm - mn << endl;

	return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<map>
#include<math.h>
#include<queue>
#include<deque>
#include<stack>
#include<cstdio>
#include<utility>
#include<set>
#include<list>
#include<cmath>
#include<stdio.h>
#include<string.h>
#include<iomanip>
#include<cstdio>
#include<cstdlib>
#include<cstring>
using namespace std;
#define FOR(i, a, b) for (ll i = (a); i <= (b); i++)
#define REP(i, n) FOR(i, 0, n - 1)
#define NREP(i, n) FOR(i, 1, n)
using ll = long long;
using pii = pair<int, int>;
using piii = pair<pii, pii>;
const ll dx[4] = { 0, -1, 1, 0 };
const ll dy[4] = { -1, 0, 0, 1 };
const int INF = 1e9 + 7;
const ll inf = 1LL << 50;
int gcd(int x, int y) {
	if (x < y)swap(x, y);
	if (y == 0)return x;
	return gcd(y, x%y);
}
void mul(ll a, ll b) {
	a = a * b % INF;
}
///////////////////////////////////////


int main() {
	string a; cin >> a;
	ll N = a.size();
	ll ans = N * (N - 1) / 2+1;
	ll cnt[26];
	REP(i, 26)cnt[i] = 0;
	for (int i = 0; i < N; ++i) {
		cnt[a[i] - 'a']++;
	}
	for (int i = 0; i < 26; ++i) {
		ans -= cnt[i] * (cnt[i] - 1) / 2;
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 640
#include <stdio.h>
  
void print_array(int *array,int n){
  int i;
  
  for(i=0;i<n-1;i++)  printf("%d ",array[i]);
  printf("%d\n",array[n-1]);
}
  
int main(void){
  int i,j,v,n,array[100];
  
  scanf("%d",&n);
  for(i=0;i<n;i++)  scanf("%d",&array[i]);  
  for(i=0;i<n;i++){
    v=array[i];
    j=i-1;
    while(j>=0 && array[j]>v){
      array[j+1]=array[j];
      j--;
    }
    array[j+1]=v;
    print_array(array,n);
  }
  
  return 0;
}

Measured memory_bytes: 600
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <algorithm>
#include <numeric>
#include <functional>
#include <sstream>
#include <iostream>
#include <iomanip>
#define _USE_MATH_DEFINES
#include <cmath>
#include <climits>
#include <cstdlib>
#include <cstring>
#include <cfloat>
#include <cmath>
#include <ctime>
#include <cassert>
#include <cctype>
#include <cstdio>
#include <cassert>
using namespace std;

#define EPS 1e-12
#define ull unsigned long long
#define ll long long
#define VI vector<ll>
#define PII pair<ll, ll> 
#define VVI vector<vector<ll> >
#define VVVI vector<vector<vector<ll>>>
#define VVVVI vector<vector<vector<vector<ll>>>>
#define REP(i,n) for(ll i=0,_n=(n);(i)<(ll)_n;++i)
#define REPR(i,n) for(ll i=(ll)(n)-1;0<=(i);--i)
#define RANGE(i,a,b) for(ll i=(ll)a,_b=(ll)(b);(i)<_b;++i)
#define RANGER(i,a,b) for(ll i=(ll)(b)-1,_a=(ll)(a);(_a)<=i;--i)
#define FOR(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)
#define ALL(c) (c).begin(), (c).end()
#define ALLR(c) (c).rbegin(), (c).rend()
#define PB push_back
#define MP(a, b) make_pair(a, b)
#define POPCOUNT __builtin_popcount
#define POPCOUNTLL __builtin_popcountll
#define CLEAR(table, v) memset(table, v, sizeof(table));
#define UNIFORM_DOUBLE(a, b) (((b-a)*(double)rand()/RAND_MAX)+a) // [a, b) 
#define UNIFORM_LL(a, b) (ll)UNIFORM_DOUBLE(a, b) // [a, b) 
#define IN(v, lo, hi) ((lo)<=(v) && (v)<(hi))
#define DD(v) cout<<#v<<": "<<v<<endl
#define FI first
#define SE second
template <typename T0, typename T1> std::ostream& operator<<(std::ostream& os, const map<T0, T1>& v) { for( typename map<T0, T1>::const_iterator p = v.begin(); p!=v.end(); p++ ){os << p->first << ": " << p->second << " ";} return os; }
template <typename T0, typename T1> std::ostream& operator<<(std::ostream& os, const pair<T0, T1>& v) { os << v.first << ": " << v.second << " "; return os; }
template <typename T> std::ostream& operator<<(std::ostream& os, const vector<T>& v) { for( int i = 0; i < (int)v.size(); i++ ) { os << v[i] << " "; } return os; }
template <typename T> std::ostream& operator<<(std::ostream& os, const set<T>& v) { vector<T> tmp(v.begin(), v.end()); os << tmp; return os; }
template <typename T> std::ostream& operator<<(std::ostream& os, const deque<T>& v) { vector<T> tmp(v.begin(), v.end()); os << tmp; return os; }
template <typename T> std::ostream& operator<<(std::ostream& os, const vector<vector<T> >& v) { for( int i = 0; i < (int)v.size(); i++ ) { os << v[i] << endl; } return os; }
template<typename T>void maxUpdate(T& a, T b) {a = max(a, b);}
template<typename T>void minUpdate(T& a, T b) {a = min(a, b);}
string YN(bool v) { return v ? "Yes":"No"; }
void uniq(VI& es) { sort(ALL(es)); es.erase(unique(ALL(es)), es.end()); }

#define INF (1LL<<60)

int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	ll mx = 10001;
	VI ans(mx);
	RANGE(x, 1, 101) RANGE(y, 1, 101) RANGE(z, 1, 101) {
		ll n = x*x+y*y+z*z+x*y+y*z+z*x;
		if(n<mx) ans[n]++;
	}
	ll N;
	while(cin>>N) {
		RANGE(i, 1, N+1) {
			cout<<ans[i]<<endl;
		}
	}
	
	return 0;
}


Measured memory_bytes: 3180
n = int(input())
arr = []
[arr.append(input().split(' ')) for _ in range(n)]

search = input()
ans = 0
flag = False
for i in range(n):
  if flag:
    ans += int(arr[i][1])
  if search == arr[i][0]:
    flag = True

    
print(ans)

Measured memory_bytes: 3064
#include <bits/stdc++.h>
#define ll long long
#define INF 1000000005
#define MOD 1000000007
#define EPS 1e-10
#define rep(i,n) for(int i=0;i<(int)(n);++i)
#define rrep(i,n) for(int i=(int)(n)-1;i>=0;--i)
#define srep(i,s,t) for(int i=(int)(s);i<(int)(t);++i)
#define each(a,b) for(auto& (a): (b))
#define all(v) (v).begin(),(v).end()
#define len(v) (int)(v).size()
#define zip(v) sort(all(v)),v.erase(unique(all(v)),v.end())
#define cmx(x,y) x=max(x,y)
#define cmn(x,y) x=min(x,y)
#define fi first
#define se second
#define pb push_back
#define show(x) cout<<#x<<" = "<<(x)<<endl
#define spair(p) cout<<#p<<": "<<p.fi<<" "<<p.se<<endl
#define sar(a,n) cout<<#a<<":";rep(kbrni,n)cout<<" "<<a[kbrni];cout<<endl
#define svec(v) cout<<#v<<":";rep(kbrni,v.size())cout<<" "<<v[kbrni];cout<<endl
#define svecp(v) cout<<#v<<":";each(kbrni,v)cout<<" {"<<kbrni.first<<":"<<kbrni.second<<"}";cout<<endl
#define sset(s) cout<<#s<<":";each(kbrni,s)cout<<" "<<kbrni;cout<<endl
#define smap(m) cout<<#m<<":";each(kbrni,m)cout<<" {"<<kbrni.first<<":"<<kbrni.second<<"}";cout<<endl

using namespace std;

typedef pair<int,int> P;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<double> vd;
typedef vector<P> vp;
typedef vector<string> vs;

const int MAX_N = 100005;

vector<int> G[MAX_N];
int ans;

bool dfs(int u,int p)
{
    int ch = 0;
    int res = 0;
    each(v,G[u]){
        if(v != p){
            ch++;
            if(dfs(v,u)){
                res++;
            }
        }
    }
    if(ch <= 1){
        if(res){
            return true;
        }else{
            return false;
        }
    }else{
        if(ch > res+1){
            ans += ch - res - 1;
        }
        return true;
    }
}

int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n;
    cin >> n;
    rep(i,n-1){
        int a,b;
        cin >> a >> b;
        G[a].pb(b),G[b].pb(a);
    }
    int r = -1;
    rep(i,n){
        if(len(G[i]) >= 3){
            r = i;
            break;
        }
    }
    if(r < 0){
        cout << "1\n";
        return 0;
    }
    ans = 0;
    dfs(r,-1);
    cout << ans << "\n";
    return 0;
}


Measured memory_bytes: 9088
#include<cstdio>
#include<iostream>
using namespace std;
struct card{
char c;
int a;
}card1[100010],card2[100010],temp;
int  partition(int p,int r)
{
    int x = card1[r].a;
    int i = p - 1,j;
    for(j = p;j < r;j++)
        if(card1[j].a <= x)
    {
        i++;
        temp = card1[j];
        card1[j] = card1[i];
        card1[i] = temp;
    }
    temp = card1[i+1];
    card1[i+1] = card1[r];
    card1[r] = temp;
    return i+1;
}
void quicksort(int p,int r)
{
    if (p < r)
    {
        int q = partition (p,r);
        quicksort (p,q - 1);
        quicksort (q + 1,r);
    }
}
void merge(int left,int mid,int right)
{
    int n1 = mid - left,n2 = right - mid;
    struct card l[n1 + 10],r[n2 + 10];
    int i,j,k;
    for(i = 0;i < n1;i++)
        l[i] = card2[left + i];
    for(i = 0;i < n2;i++)
        r[i] = card2[mid + i];
        i = j = 0;
        l[n1].a = r[n2].a = 1000000000;
    for(k = left;k < right;k++)
    {
        if(l[i].a <= r[j].a)
            card2[k] = l[i++];
        else
            card2[k] = r[j++];
    }
}
void mergesort(int left,int right)
{
    if(left + 1 < right)
    {
        int mid = (left + right) / 2;
        mergesort(left,mid);
        mergesort(mid,right);
        merge(left,mid,right);
    }
}
int main()
{
    int n,i,flag = 0;
    cin >> n;
    for (i=0;i < n;i++)
    {
             cin >> card1[i].c >> card1[i].a;
             card2[i] = card1[i];
    }
    quicksort(0,n - 1);
    mergesort(0,n);
    for (i=0;i < n;i++)
        if(card1[i].c != card2[i].c)
        {
               flag = 1;
               break;
        }
      if(flag == 0)
        printf("Stable\n");
      else
        printf("Not stable\n");
          for (i=0;i < n;i++)
            printf("%c %d\n",card1[i].c,card1[i].a);
            return 0;
}

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

int main() {
	int x, y, z;
	cin >> x >> y >> z;
	int ans = 1;
	x -= y + 2 * z;
	ans += x / (y + z);
	cout << ans << endl;
}

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

using namespace std;
typedef long long ll;
typedef long double ld;
//#define rep(i, a, b) for(ll i = ll(a); i <= ll(b); i++)
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep1(i, n) for (int i = 1; i <= (int)(n); i++)


int main(){

 long long n,a,b;
 cin>>n>>a>>b;

  long long full = (n/(a+b))*a;

  long long rem = n%(a+b);

  full += min(rem,a);

  cout<<full<<endl;

return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(void){
  vector<int> a(3); cin>>a[0]>>a[1]>>a[2];
  sort(a.begin(),a.end());
  int res=a[2]-a[1],cnt=0;
  if((a[2]^(a[0]+res))&1) cnt+=2;
  res+=(a[2]-a[0]-res)/2;
  cout<<res+cnt;
  return 0;
}

Measured memory_bytes: 3524
#include<stdio.h>
#define  N  100
int main(){
  int M[N][N];
  int n,u,k,v;
  scanf("%d",&n);
  for(int i = 0;i<n;i++){
    for(int j = 0; j<n;j++)M[i][j]=0;
  }
  for(int i=0;i<n;i++){
    scanf("%d %d",&u ,&k);
    u--;
    for(int j=0;j<k;j++)
      {
        scanf("%d",&v);
        v--;
        M[u][v]=1;
      }
}
  for(int i=0;i<n;i++){
    for(int j=0;j<n;j++){
      if(j)
        printf(" ");
      printf("%d",M[i][j]);
    }
    printf("\n");
  }
  return 0;
}



Measured memory_bytes: 2052
#include <list>
#include <vector>
#include <cstdio>
using namespace std;
int main(){
int n,q,a,b,c;
scanf("%d%d",&n,&q);
vector<list<int>>v(n);
for(;q--;){
scanf("%d",&a);
if(a==0)scanf("%d%d",&b,&c),v[b].push_back(c);
if(a==1){scanf("%d",&b);int f=0;for(auto &e:v[b]){if(f)putchar(' ');f=1;printf("%d",e);}putchar('\n');}
if(a==2)scanf("%d%d",&b,&c),v[c].splice(v[c].end(),v[b]);
}
}


Measured memory_bytes: 18280
#include <bits/stdc++.h> 
using namespace std;
#define int long long
#define ld long double
#define fi first
#define se second
#define pb push_back
#define pii pair<int,int>
#define all(x) (x).begin(), (x).end()
const int MOD = 1e9+7;
int mpow(int a,int b,int p=MOD){a=a%p;int res=1;while(b>0){if(b&1)res=(res*a)%p;a=(a*a)%p;b=b>>1;}return res%p;}
const int N=1e3+2;

int32_t main(){
      ios_base::sync_with_stdio(false);
      cin.tie(NULL);

      int k;
      cin>>k;
      string s;
      cin>>s;
      int n=s.length();
      for(int i=0;i<n;i++)
      {
        int o=s[i]-'A'+k;
        o%=26;
        cout<<(char)('A'+o);
      }
}
// I never lose. I either win or I learn

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

int main(void){
  int n;
  cin >> n;
  int h[n];
  for(int i = 0; i < n; i++) cin >> h[i];
  int ans = 0;
  int maxh = h[0];
  for(int i = 0; i < n; i++){
    if(h[i] >= maxh){
      ans++;
      maxh = h[i];
    }
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
use std::io::Read;

fn main() {
    let mut buf = String::new();

    std::io::stdin().read_to_string(&mut buf).unwrap();

    let mut iter = buf.split_whitespace();
    let r: usize = iter.next().unwrap().parse().unwrap();

    println!("{}", 2.0 * std::f32::consts::PI * (r as f32));
}


Measured memory_bytes: 2116
let () = Scanf.scanf "%d" @@ fun n ->
  let xus = Array.init n @@ fun _ -> Scanf.scanf " %f %s" @@ fun x u -> (x, u) in
  let ans = Array.fold_left (fun acm (x, u) -> acm +. if u = "JPY" then x else x *. 380000.0) 0.0 xus in
  Printf.printf "%f\n" @@ ans

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



namespace CSharpSample01
{

    
    
    class Program
    {

        //約数を昇順リストで返す
        //O(√N)
        static List<int> Divisor(int M)
        {
            List<int> divlist = new List<int>();

            for(int i = 1; i * i <= M; i++)
            {
                if(M % i == 0)
                {
                    divlist.Add(i);
                    if (i * i != M) divlist.Add(M / i);
                }
            }

            divlist.Sort();

            return divlist;
        }

        static int Solve(int N, int M, List<int> divisor)
        {

            for(int i = divisor.Count - 1; i >= 0; i--)
            {
                if(N <= (M / divisor[i]))
                {
                    return divisor[i];
                }
            }

            return 1;
        }

        
        static void Main(string[] args)
        {
            string[] input = Console.ReadLine().Split(' ');
            int N = int.Parse(input[0]);
            int M = int.Parse(input[1]);

            List<int> divisor = Divisor(M);

            Console.WriteLine(Solve(N, M, divisor));
            
        }
    }
}

Measured memory_bytes: 13268
#include <iostream>

using namespace std;

#define MAX 500000
#define SENTINEL 2e9

int L[MAX / 2 + 2], R[MAX / 2 + 2];
int cnt;

void merge(int A[], int left, int mid, int right) {
	int n1 = mid - left;
	int n2 = right - mid;
	for (int i = 0; i < n1; ++i) L[i] = A[left + i];
	for (int i = 0; i < n2; ++i) R[i] = A[mid + i];
	L[n1] = R[n2] = SENTINEL;
	int i = 0, j = 0;
	for (int k = left; k < right; ++k) {
		cnt++;
		if (L[i] <= R[j]) A[k] = L[i++];
		else A[k] = R[j++];
	}
}

void mergeSort(int A[], int left, int right) {
	if (left < right - 1) {
		int mid = (left + right) / 2;
		mergeSort(A, left, mid);
		mergeSort(A, mid, right);
		merge(A, left, mid, right);
	}
}

int main() {
	int n; cin >> n;
	int A[MAX];
	for (int i = 0; i < n; ++i) cin >> A[i];
	mergeSort(A, 0, n);
	for (int i = 0; i < n; ++i) {
		if (i) cout << " ";
		cout << A[i];
	}
	cout << endl << cnt << endl;

	return 0;
}


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

#define INF (1000000000+1)

vector<int> L;
vector<int> R;
int cnt;

void merge( vector<int> &S, int left, int mid, int right )
{
	int n1 = mid - left;
	int n2 = right - mid;
	for( int i = 0; i < n1; i++ ) {
		L[i] = S[left + i];
	}
	for( int i = 0; i < n2; i++ ) {
		R[i] = S[mid + i];
	}
	int i = 0;
	int j = 0;
	L[n1] = INF;
	R[n2] = INF;
	for( int k = left; k < right; k++ ) {
		cnt++;
		if( L[i] <= R[j] ) {
			S[k] = L[i];
			i++;
		}
		else {
			S[k] = R[j];
			j++;
		}
	}
}

void sort( vector<int> &S, int left, int right )
{
	if( right - left <= 1 ) return;
	int mid = ( left + right ) / 2;
	sort( S, left, mid );
	sort( S, mid, right );
	merge( S, left, mid, right );
}

int main()
{
	int n;
	cin >> n;
	vector<int> S( n );
	L = vector<int>( n / 2 + 2 );
	R = vector<int>( n / 2 + 2 );
	for( int i = 0; i < n; i++ ) {
		cin >> S[i];
	}

	sort( S, 0, n );
	for( int i = 0; i < n; i++ ) {
		if( i ) cout << " ";
		cout << S[i];
	}
	cout << endl;
	cout << cnt << endl;
}



Measured memory_bytes: 7648
using System;
using System.Collections.Generic;

namespace Aizu
{
    class OnlineJudge
    {
        public static void Main()
        {
            var cards = new Dictionary<string, bool[]> {
                { "S", new bool[13] }, { "H", new bool[13] },
                { "C", new bool[13] }, { "D", new bool[13] }
            };
            for(int i = int.Parse(Console.ReadLine()); i > 0; --i){
                var input = Console.ReadLine().Split();
                cards[input[0]][int.Parse(input[1]) - 1] = true;
            }
            foreach(var item in cards){
                for(int i = 0; i < item.Value.Length; ++i){
                    if(!item.Value[i]) {
                        Console.WriteLine("{0} {1}", item.Key, i + 1);
                    }
                }
            }
        }
    }
}

Measured memory_bytes: 5796