akhauriyash/Code-Regression huggingface dataset:
import sys
from collections import deque

sys.setrecursionlimit(10 ** 7)
rl = sys.stdin.readline


def solve():
    N, M = map(int, rl().split())
    graph = [[] for _ in range(N)]
    for _ in range(M):
        a, b = map(lambda x: int(x) - 1, rl().split())
        graph[a].append(b)
        graph[b].append(a)
    
    ans = [0] * N
    que = deque([0])
    while que:
        cur = que.popleft()
        for child in graph[cur]:
            if ans[child] == 0:
                ans[child] = cur + 1
                que.append(child)
    
    if any(ansi == 0 for ansi in ans[1:]):
        print('No')
    else:
        print('Yes')
        print(*ans[1:], sep='\n')


if __name__ == '__main__':
    solve()


Measured memory_bytes: 99796
#include<bits/stdc++.h>
using namespace std;
#define FASTIO ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);
#define ll long long
#define pb push_back
#define F first
#define S second
#define ld long double
#define rep(i,n) for (int i =0;i < (n); ++i)
#define vi vector<ll>
const int inf = 1e9 + 10;
int n;
vector<int> a(200200), G[200200];

vector<int> dp(200200, inf), ans(200200);
vector<bool> seen(200200, false);
int res = 0;
stack<pair<int, int>> s;

void dfs(int v = 0) {
	if (seen[v]) return;
	seen[v] = true;
	//cout << res << " " << v << endl;

	//for (auto c : s) cout << c.F << ',' << c.S << " ";
	//cout << endl;
	if (res == 0) {
		dp[res] = a[v];
		s.push({res, inf});
		res++;
	}
	else {
		if (dp[res - 1] < a[v]) {
			dp[res] = a[v];
			s.push({res, inf});
			res++;
		}
		else {
			int idx = lower_bound(dp.begin(), dp.end(), a[v]) - dp.begin();
			s.push({idx, dp[idx]});
			dp[idx] = a[v];
		}
	}
	//for ( int i = 0; i <= v; i++) cout << dp[i] << " ";
	//cout << endl;
	ans[v] = res;
	//for (int i = 0; i <= v; i++) cout << ans[i] << " ";
	//cout << endl << "#" << endl;

	for (int u : G[v]) {
		dfs(u);
	}

	pair<int, int> p = s.top();
	s.pop();
	dp[p.first] = p.second;
	if (p.second == inf) res--;
	//for ( int i = 0; i <= v; i++) cout << dp[i] << " ";
	//cout << endl << endl;
}

void solve() {
	cin >> n;
	rep(i, n) cin >> a[i];
	rep(i, n - 1) {
		int u, v;
		cin >> u >> v;
		u--, v--;
		G[u].push_back(v);
		G[v].push_back(u);
	}

	dfs();
	rep(i, n) cout << ans[i] << '\n';

}
int main() {

	FASTIO;


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

Measured memory_bytes: 26584
#![allow(unused_imports)]
use std::cmp::*;
use std::collections::*;
use itertools::Itertools;
use num_traits::clamp;
use ordered_float::OrderedFloat;
use proconio::{input, marker::*, fastout};
use superslice::*;

const M: usize = 998244353;

#[fastout()]
fn main() {
    input! {
        a: usize, b: usize, c: usize, d: usize,
    }

    let mut dp = vec![vec![vec![0usize; 2]; d+1]; c+1];
    dp[a][b][1] = 1;
    for y in a..=c {
        for x in b..=d {
            if y != a {
                dp[y][x][0] = (dp[y-1][x][0] + dp[y-1][x][1]) * x;
                dp[y][x][0] %= M;
            }
            if x != b {
                dp[y][x][1] = dp[y][x-1][0] + dp[y][x-1][1] * y;
                dp[y][x][1] %= M;
            }
        }
    }
    let ans = (dp[c][d][0] + dp[c][d][1]) % M;
    println!("{}", ans);
}


Measured memory_bytes: 494544
#include <iostream>
#include <string>
using namespace std;
int main(){
  int ans;
  string s;
  cin >> s;
  if (s == "SUN")
    ans = 7;
  else if (s == "MON")
    ans = 6;
  else if (s == "TUE")
    ans = 5;
  else if (s == "WED")
    ans = 4;
  else if (s == "THU")
    ans = 3;
  else if (s == "FRI")
    ans = 2;
  else
    ans = 1;
  cout << ans << endl;
}


Measured memory_bytes: 256
#include<iostream>
#include<stack>
#include<vector>
#define ll int
#define rep(i,a,b) for(int i = a;i < b;i++)
#define N 200004

using namespace std;

string s;
ll minlength[N];
ll n;
ll seg[4*N][26];
string ans;
ll epomeno[N][26];

ll first_occurence(ll cur,ll id)
{
    return epomeno[cur][id];
}

ll calc(ll cur)
{
    if(cur > n)
        return 0;
    if(cur == n)
        return 1;

    if(minlength[cur])
        return minlength[cur];

    minlength[cur] = n-cur+1;

    rep(i,0,26)
    {
        ll goes = first_occurence(cur,i);

        minlength[cur] = min(minlength[cur],calc(goes+1)+1);
    }

    return minlength[cur];
}

void solve(ll cur,ll pos)
{
    if(cur >= n)
        return;

    rep(i,0,26)
    {
        ll goes = first_occurence(cur,i);

        if(minlength[goes+1]+1==minlength[cur])
        {
            ans[pos]=i+'a';
            solve(goes+1,pos+1);
            break;
        }
    }

    return;
}

int main()
{
    ios_base::sync_with_stdio(false);
    cin >> s;
    n = s.size();

    rep(i,0,26)
    {
        epomeno[n][i]=n;
        for(int j = n-1;j>=0;j--)
        {
            if(s[j]-'a'==i)
                epomeno[j][i]=j;
            else
                epomeno[j][i]=epomeno[j+1][i];
        }
    }

    calc(0);

    rep(i,0,minlength[0])
        ans += "a";

    solve(0,0);

    cout << ans;

    return 0;
}


Measured memory_bytes: 22036
from collections import defaultdict
from itertools import combinations

d = defaultdict(int)

n = int(input())

for _ in range(n):
    initial = input()[0]
    if initial in 'MARCH':
        d[initial] += 1

a = list(d.values())

ans = 0

for x in combinations(range(min(len(a),5)),3):
    ans += a[x[0]] * a[x[1]] * a[x[2]]

print(ans)

Measured memory_bytes: 3316
/*
AizuOnline A2399
Title Save Your Privacy! 
*/
#include <stdio.h>
#include <string.h>
//Global data section
int N;
int M[100];
char p[100][100];
int K;
int l[100];

//
main()
{
        int i,j,k,lk,findcnt,find,cnt;

        while(EOF!=scanf("%d",&N) && N)
        {
                memset(p,'\0',100*100);
                for(i=0;i<N;i++)
                {
                        scanf("%d ",&M[i]);
                        for(j=0;j<M[i];j++)
                        {
                                scanf("%d ",&lk);
                                p[i][lk]=-1;
                        }
                }
                scanf("%d",&K);
                for(i=0;i<K;i++)
                             scanf("%d ",&l[i]);

                
                findcnt=0;find=-1;
                for(i=0;i<N;i++)
                {
                        if(M[i] < K)
                                continue;
                        
                        cnt=0;
                        for(j=0;j<K;j++)
                        {
                                //printf("Lpik=%d %d %d\n",l[j],p[i][l[j]],i);
                                if(p[i][l[j]])
                                        cnt++;
                                if(cnt == K)
                                        goto NEXT;
                        }
                        continue;
                NEXT:
                        //printf("find=%d\n",i+1);
                        find=i+1;
                        findcnt++;
                        if(findcnt>1)
                                break;
                }
                if(findcnt==1)
                        printf("%d\n",find);
                else
                        printf("-1\n");
        }
return(0);
}

Measured memory_bytes: 632
#include <iostream>
#include <vector>
#include <algorithm>
#include <set>
#include <math.h>
#include <string>
#include <set>

#ifdef _MSC_VER
#pragma warning(disable:4996)
#endif

using namespace std;


int main() {

	int n;
	cin >> n;
	set<string> s;
	string tmp;
	
	for (int i = 0; i < n; i++) {
		cin >> tmp;
		s.insert(tmp);
	}
	cout << s.size();
	return 0;
}



Measured memory_bytes: 19228
#include <iostream>
#include <vector>
#include <string>
#include <array>
#include <map>
#include <cmath>
#include <cstdlib>

//using ll = long long;
using namespace std;

int main(){
  int n,m;
  cin>>n>>m;
  int a[1001];
  int cnt=0;
  for(int i=0;i<m;++i){
    cin>>a[i];
    if(a[i]<=m)cnt++;
  }
  cout<<m-cnt<<endl;
  return 0;
}



Measured memory_bytes: 3100
N = int(input())
A = [int(a) for a in input().split()]

mod = 10**9+7
r = 0
g = 0
b = 0

cnt = 1

for i in range(N):
    if A[i] == r:
        if r == g and r == b:
            cnt *= 3
        elif r == g or r == b:
            cnt *= 2
        r += 1
    elif A[i] == g:
        if g == b:
            cnt *= 2
        g += 1
    elif A[i] == b:
        b += 1
    else:
        cnt = 0
        break
        
    cnt %= mod
    
print(cnt)

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

typedef long long ll;
using namespace std;

int main(){
    ll n, m;
    cin >> n >> m;
    vector<ll> a;
    vector<pair<ll, ll>> bc;
    ll tmp;
    for (int i = 0; i < n; ++i) {
        cin >> tmp;
        a.push_back(tmp);
    }
    sort(a.begin(), a.end());
    ll tmpb;
    ll tmpc;
    for (int j = 0; j < m; ++j) {
        cin >> tmpb >> tmpc;
        bc.push_back(make_pair(tmpc, tmpb));
    }
    sort(bc.begin(), bc.end(), greater<>());
    ll ans = 0;
    int idx = 0;
    for (int k = 0; k < n; ++k) {
        if(idx < m && bc[idx].first > a[k]){
            ans += bc[idx].first;
            bc[idx].second--;
        }else{
            ans += a[k];
        }
        if(idx < m && bc[idx].second == 0)idx++;
    }
    cout << ans << endl;
}

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

int main() {
    int R, G, B, N;
    cin >> R >> G >> B >> N;

    long long res = 0;
    for(int r=0; r<=N; ++r) {
        for(int g=0; g<=N; ++g) {
            int tmp = N - r * R - g * G;
            if(tmp >= 0 && (tmp % B == 0)) ++res;
        }
    }
    cout << res << endl;
}

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

using namespace std;
#define ll long long
#define pb push_back
#define mp make_pair

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 << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
#else
#define debug(...) 42
#endif

int main()
{
	int n;
	cin >> n;
	int a[n];
	for(int i=0;i<n;i++)
		cin >> a[i];
	sort(a, a+n);
	int sum = 0;
	for(int i =0;i<n;i++)
		sum += a[i];
	sum -= a[n-1]/2;
	cout << sum << "\n";
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

#define COUT(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << endl
template<class T1, class T2> ostream& operator << (ostream &s, pair<T1,T2> P)
{ return s << '<' << P.first << ", " << P.second << '>'; }
template<class T> ostream& operator << (ostream &s, vector<T> P)
{ for (int i = 0; i < P.size(); ++i) { if (i > 0) { s << " "; } s << P[i]; } return s; }
template<class T> ostream& operator << (ostream &s, vector<vector<T> > P)
{ for (int i = 0; i < P.size(); ++i) { s << endl << P[i]; } return s << endl; }
template<class T> ostream& operator << (ostream &s, set<T> P)
{ for(auto it : P) { s << "<" << it << "> "; } return s << endl; }
template<class T1, class T2> ostream& operator << (ostream &s, map<T1,T2> P)
{ for(auto it : P) { s << "<" << it.first << "->" << it.second << "> "; } return s << endl; }


// r -> P, s -> R, p -> S
int main() {
    int N, K, R, S, P;
    string T;
    cin >> N >> K >> R >> S >> P >> T;
    auto score = [&](int i) {
        if (T[i] == 'r') return P;
        else if (T[i] == 's') return R;
        else return S;
    };
    long long res = 0;
    for (int k = 0; k < K; ++k) {
        bool last = false;
        for (int i = k; i < N; i += K) {
            if (i >= K && T[i-K] == T[i] && last) last = false;
            else res += score(i), last = true;
        }
    }
    cout << res << endl;
}


Measured memory_bytes: 512
# -*- coding: utf-8 -*-
import numpy as np

# input
l = list(map(int, input().split()))

A = l[0] # Aの値が出力される
B = l[1] # Bの値が出力される
T = l[2] # Cの値が出力される

t = 0
created = 0

while 1:
    t += 1

    if t%A == 0:
        #print("create t:", t)
        created += B

    if t >= T:
        break

print(created)


Measured memory_bytes: 12500
#include <bits/stdc++.h>
#define FOR(v, a, b) for(int v = (a); v < (b); ++v)
#define FORE(v, a, b) for(int v = (a); v <= (b); ++v)
#define REP(v, n) FOR(v, 0, n)
#define REPE(v, n) FORE(v, 0, n)
#define REV(v, a, b) for(int v = (a); v >= (b); --v)
#define ALL(x) (x).begin(), (x).end()
#define ITR(it, c) for(auto it = (c).begin(); it != (c).end(); ++it)
#define RITR(it, c) for(auto it = (c).rbegin(); it != (c).rend(); ++it)
#define EXIST(c,x) ((c).find(x) != (c).end())
#define LLI long long int
#define fst first
#define snd second
#ifdef DEBUG
#include <boost/core/demangle.hpp>
#define dump(x) cerr << "L" << __LINE__ << ": in " << __PRETTY_FUNCTION__ << " \e[32;1m" << boost::core::demangle(typeid(x).name()) << "\e[37m" << " " << (#x) << " = " << (x) << "\e[m" << endl;
#else
#define dump(x)
#endif
using namespace std;
template <typename T> using V = vector<T>;
template <typename T, typename U> using P = pair<T,U>;
template <typename I> void join(ostream &ost, I s, I t, string d=" "){for(auto i=s; i!=t; ++i){if(i!=s)ost<<d; ost<<*i;}ost<<endl;}
template <typename T> istream& operator>>(istream &is, vector<T> &v){for(auto &a : v) is >> a; return is;}
template <typename T, typename U> istream& operator>>(istream &is, pair<T,U> &p){is >> p.first >> p.second; return is;}

template <typename T> ostream& operator<<(ostream &os, vector<T> &v){os << "{";ITR(i,v){if(i!=v.begin())os << ","; os << *i;}os << "}"; return os;}
template <typename T, typename U> ostream& operator<<(ostream& os, pair<T,U> &p){os << "(" << p.first << "," << p.second << ")"; return os;}

template <typename T> T& chmin(T &a, const T &b){return a = min(a,b);}
template <typename T> T& chmax(T &a, const T &b){return a = max(a,b);}

LLI dp[1<<16];
bool visit[1<<16];

LLI score[1<<16];

LLI rec(vector<vector<int>> &a, int p){
  if(visit[p]) return dp[p];
  visit[p] = true;

  for(int t=p; ; t=(t-1)&p){
    chmax(dp[p], rec(a,t)+score[p^t]);
    if(t==0) break;
  }
  
  return dp[p];
}


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

  int N; cin >> N;
  vector<vector<int>> a(N, vector<int>(N)); cin >> a;

  REP(i,1<<N){
    if(__builtin_popcount(i) == 0) continue;
    
    REP(j,N){
      if((i>>j) & 1) continue;
      LLI t = score[i];
      REP(k,N) if(((i>>k) & 1) && j!=k) t += a[j][k];
      score[i | (1<<j)] = t;
    }
  }

  int p = 0;
  REP(i,N) p |= (1<<i);

  cout << rec(a, p) << endl;
  
  return 0;
}


Measured memory_bytes: 1408
import java.util.*;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        double sum = 0;
        for (int i= 1;i<=n;i++) {
            double u = sc.nextDouble();
            String x = sc.next();
            if (x.equals("JPY")) {
                sum += u;
            } else {
                sum += u * (double )380000;
            }
        }
        System.out.println(sum);
    }
}


Measured memory_bytes: 23252
import qualified Data.Text.Lazy as T
import qualified Data.Text.Lazy.IO as T
import qualified Data.Text.Lazy.Read as T

main :: IO ()
main = do
  let
    modulus = 1000000007 :: Int
    modAdd :: Int -> Int -> Int
    modAdd x y = (x + y) `mod` modulus
    modMul :: Int -> Int -> Int
    modMul x y = (x * y) `mod` modulus
    step :: (Int, Int) -> Int -> (Int, Int)
    step (s, c) x = (s `modAdd` (c `modMul` x), c `modAdd` x)
  n <- unsafeTextToInt <$> T.getLine :: IO Int
  as <- map unsafeTextToInt . T.words <$> T.getContents :: IO [Int]
  print . fst . foldl step (0, 0) $ as

unsafeTextToInt :: T.Text -> Int
unsafeTextToInt s = case T.signed T.decimal s of
  Right (n, _) -> n
{-# INLINE unsafeTextToInt #-}


Measured memory_bytes: 4892
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <stack>
#include <queue>
#include <cmath>

using namespace std;

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define SZ(x) ((int)(x).size()) //unsignedのサイズをint型に変換
#define dump(x)  cerr << #x << " = " << (x) << endl;

typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef long long LL; 

 

//ここから書き始める
int main(int argc, char const *argv[])
{
	int N,i;
	cin >> N >> i;

	cout << (N + 1) - i << endl;


}

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

using namespace std;

#define FOR(i,s,e) for((i)=(s);(i)<(int)(e);(i)++)
#define REP(i,e) FOR(i,0,e)

#define all(o) (o).begin(), (o).end()
#define psb(x) push_back(x)
#define mp(x,y) make_pair((x),(y))

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

const double EPS = 1e-10;

int n;

int main() {
  map<string, bool> d;
  string q, s;
  scanf("%d ", &n);
  for (int i=0; i<n; i++) {
    char qq[7], ss[13];
    scanf("%s%s ", qq, ss);
    q = qq; s = ss; 
//    cin >> q >> s;
//    if (q == "insert" && !d.count(s)) 
    if (q == "insert")
      d[s] = true;
    else if (q == "find") {
//      cout << (d.count(s) ? "yes" : "no") << endl; 
      if (d.count(s))
        printf("yes\n");
      else
        printf("no\n");
    }
  }

  return 0;
}

Measured memory_bytes: 32328
INF = 10 ** 15

N = int(input())
As = list(map(int, input().split()))
As.append(-INF)

INF = 10 ** 15
dp = [[-INF] * (N//2) for _ in range(3)]
dp[0][0] = As[0]
dp[1][0] = As[1]
dp[2][0] = As[2]

for i in range(1, N//2):
    dp[0][i] = dp[0][i-1] + As[2*i]
    dp[1][i] = max(dp[0][i-1], dp[1][i-1]) + As[2*i+1]
    dp[2][i] = max(dp[0][i-1], dp[1][i-1], dp[2][i-1]) + As[2*i+2]

if N % 2 == 0:
    print(max(dp[0][-1], dp[1][-1]))
else:
    print(max(dp[0][-1], dp[1][-1], dp[2][-1]))



Measured memory_bytes: 33744
#include <bits/stdc++.h>
using namespace std; 
char str[102400]; 
int arr[102400]; 
int main()
{cin>>str;
	int n=strlen(str); 
	for (int i = 0; i < n; i++)str[i]-='0'; 
	for (int i = 0; i <= n; i++)arr[i]=(i?str[i-1]:0)^str[i]; 
	int l=1,r=n,ans; 
	while (l <= r){
		int m=(l+r)/2,x=0,y=0,z=0;
		for (int i=m; i<=n; i++)x ^= arr[i]; 
		for (int i=0; i<=min(m-1,n-m); i++)y ^= arr[i]; 
		for (int i=n-m+1; i<m; i++)z += arr[i]; 
		if (x==y&&!z){
			ans=m; 
			l=m+1;
		}
		else
			r=m-1; 
	}cout<<ans<<endl;
	return 0; 
}


Measured memory_bytes: 768
import Control.Applicative ((<$>))
import Control.Monad (unless)
import Data.List (foldl')

main :: IO ()
main = do
  cs <- map read <$> words <$> getLine
  unless (cs == [0]) $ do
    solve cs >>= print
    main

solve :: [Int] -> IO Int
solve cs = return . maximum . (0:) . foldl' f [0] $ cs
  where f xs y = [w | u <- xs, v <- g y, let w = u + v, w <= 21]
        g x | x == 1 = [1, 11]
            | x >= 10 = [10]
            | otherwise = [x]



Measured memory_bytes: 4040
#include <bits/stdc++.h>
#define fi first
#define se second
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
#define srep(i,s,t) for (int i = s; i < t; ++i)
#define rng(a) a.begin(),a.end()
#define rrng(a) a.rbegin(),a.rend()
#define maxs(x,y) (x = max(x,y))
#define mins(x,y) (x = min(x,y))
#define limit(x,l,r) max(l,min(x,r))
#define lims(x,l,r) (x = max(l,min(x,r)))
#define isin(x,l,r) ((l) <= (x) && (x) < (r))
#define pb push_back
#define eb emplace_back
#define sz(x) (int)(x).size()
#define pcnt __builtin_popcountll
#define uni(x) x.erase(unique(rng(x)),x.end())
#define show(x) cout<<#x<<" = "<<x<<endl;
#define PQ(T) priority_queue<T,v(T),greater<T> >
#define bn(x) ((1<<x)-1)
#define dup(x,y) (((x)+(y)-1)/(y))
#define newline puts("")
#define v(T) vector<T>
#define vv(T) v(v(T))
using namespace std;
typedef long long int ll;
typedef unsigned uint;
typedef unsigned long long ull;
typedef pair<int,int> P;
typedef tuple<int,int,int> T;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<P> vp;
typedef vector<T> vt;

int main() {
  vector<string>s(3);
  rep(i,3)cin >> s[i];
  string ans = "";
  rep(i,3) ans+= 'A'+(s[i][0]-'a');
  cout<<ans<<endl;
  return 0;
}

Measured memory_bytes: 256
{-# LANGUAGE OverloadedStrings #-}

import Data.Monoid
import Control.Applicative
import Data.Maybe

main :: IO ()
main = do
    s <- getLine
    t <- getLine
    putStrLn . rep . fromMaybe "UNRESTORABLE" $ restore s t

restore :: String -> String -> Maybe String
restore "" t = Nothing
restore s t = let
    in if take (length t) s `eq` t 
           then ((head s :) <$> restore (drop 1 s) t) <|> Just (t <> rep (drop (length t) s))
           else ((head s :) <$> restore (drop 1 s) t)

rep :: String -> String
rep = map (\c -> if c=='?' then 'a' else c) 

eq :: String -> String -> Bool
eq "" "" = True
eq "" _  = False
eq _ ""  = False
eq ss ts = (head ss == head ts || head ss == '?') && eq (tail ss) (tail ts)


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

#define N 200

int isEmpty(int);
void push(int* ,int);
int pop(int*);

int top=0;

int main(){
  char s[N],c;
  int buf[N],x,y,i=0,j;
  
  
  
  while(scanf("%s",s)!=EOF){
    if(s[0]=='+'){
      x=pop(buf);
      y=pop(buf);
      push(buf,x+y);
    }
    else if(s[0]=='-'){
      x=pop(buf);
      y=pop(buf);
      push(buf,y-x);
    }
    else if(s[0]=='*'){
      x=pop(buf);
      y=pop(buf);
      push(buf,x*y);
    }
    else{
      x=atoi(s);
      push(buf,x);
    }
  }

  j=pop(buf);
  printf("%d\n",j);
  
  return 0;
}
      


void push(int *s ,int x){
  if(top>=N-1) exit(1);
  
  top++;
  s[top]=x;
}

int pop(int *s){
  if(top==0) exit(2);

  else{
    top--;
    return s[top+1];
  }
}



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

int main() {
	int k;
	cin >> k;
	if (k % 2 == 0) {
		cout << k * k / 4 << endl;
	}
	else {
		int a = (k - 1) / 2;
		cout << (k - a)*a << endl;
	}
}

Measured memory_bytes: 256
from __future__ import print_function

import sys

import re
import array
import copy
import functools
import operator

import math
import string
import fractions
from fractions import Fraction
from fractions import gcd
# fractions.gcd() を用いること
# math.log2()はatcoderでは対応していない．留意せよ．

import collections
import itertools
import bisect

import random
import time

import heapq
from heapq import heappush
from heapq import heappop
from heapq import heappushpop
from heapq import heapify
from heapq import heapreplace
from queue import PriorityQueue as pq
from queue import Queue

from itertools import accumulate

from collections import deque
from collections import Counter

from operator import mul
from functools import reduce

input = sys.stdin.readline


def eprint(*args, **kwargs):
    print(*args, file=sys.stderr, **kwargs)
    return


def lcm(n, m):
    return int(n * m / gcd(n, m))


def coprimize(p, q):
    common = fractions.gcd(p, q)
    return (p // common, q // common)


def combinations_count(n, r):
    r = min(r, n - r)
    numer = reduce(mul, range(n, n - r, -1), 1)
    denom = reduce(mul, range(1, r + 1), 1)
    return numer // denom


def main():
    # input
    n = int(input().strip())
    l = list(range(2, 10**5+4))

    # main process
    for i in range(len(l)):
        l2 = []
        for j in range(len(l)):
            if l[j] % l[i] == 0 and l[j] != l[i]:
                pass
            else:
                l2.append(l[j])
        if len(l) == len(l2):
            break
        l = l2
        # eprint('l2 ', end=':\n')
        # eprint(l2)
    
    for i in range(len(l)):
        if l[i]>=n:
            print(l[i])
            return

if __name__ == '__main__':
    main()


Measured memory_bytes: 68968
#include<stdio.h>

int main()
{
	int a[5] = {}, M = 0, S = 0, k, ans;
	for (int i = 0; i < 5; i++)
	{
		scanf("%d", &a[i]);
		
		
	}
	scanf("%d", &k);
	ans = a[4] - a[0];
	
	
	if (ans<= k)printf("Yay!\n");
	else printf(":(\n");
}

Measured memory_bytes: 128
#include <stdio.h>
#include<math.h> 
int main(void)
{
	double x1,x2,x3,y1,y2,y3;
	double r,px,py;
	double A1,A2,B1,B2,C1,C2;
	int n;
	int i;
	scanf("%d",&n);
	for(i=0;i<n;i++){
		scanf("%lf%lf%lf%lf%lf%lf",&x1,&y1,&x2,&y2,&x3,&y3);
		A1=2*(x2-x1); A2=2*(x3-x1);
		B1=2*(y2-y1); B2=2*(y3-y1);
		C1=pow(x1,2)-pow(x2,2)+pow(y1,2)-pow(y2,2);
		C2=pow(x1,2)-pow(x3,2)+pow(y1,2)-pow(y3,2);
		px=(B1*C2-B2*C1)/(A1*B2-A2*B1);
		py=(C1*A2-C2*A1)/(A1*B2-A2*B1);
		r=sqrt(pow(x1-px,2)+pow(y1-py,2));
		printf("%.3lf %.3lf %.3lf\n",px,py,r);
	}
return 0;
}

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

	typedef long long ll;
	using namespace std;

	int main(){
		ll n;
		cin >> n;
		long double  s=0;
		for(ll i =0; i < n; i++){
			long double a;
			string b;
			cin >> a >> b;
			if(b == "JPY"){
				s += a;
			}else{
				s += a*380000.0;
			}
		}
		cout << s;
		
		return 0;
	}

Measured memory_bytes: 256
#include <iostream>
#include <fstream>
#include <stdio.h>
#include <algorithm>
#include <string>
#include <cmath>
#include <functional>
#include <cstdint>
#define REP(i, n) for(int i = 0; i < n; i++)
using ll = long long;
using namespace std;



int main() {

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

  ll a,b,c;
  ll k, ans;
  cin >> a >> b >> c >> k;
  
  if (a >= k) {
    ans = k;
  } else if (a+b >= k){
    ans = a;
  } else {
    ans = 2*a  + b - k;
  }
 
  cout << ans << endl;
}
  

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


n = int(input())

tank = []
dg = 10**10
mi = []
ma = []

for _ in range(n):
    a,b = map(int,input().split())
    tank.append(a*dg + b)
    mi.append(a)
    ma.append(b)

mi.sort()
ma.sort(reverse = True)

if n % 2 == 1:
    c = mi[n//2]
    d = ma[n//2]
    print(d-c+1)
else:

    c = (mi[(n//2) - 1] + mi[n//2])
    d = (ma[(n//2) - 1] + ma[n//2])

    print(d-c+1)


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

h = []

for i in range(N):
  m = int(input())
  g = []
  for j in range(m):
    a, b = map(int, input().split())
    g.append((a-1, b))
  h.append(g)
  
def judge(a, b):
  for i in range(N):
    if (b >> i) & 1:
      for j in a[i]:
        if ((b >> j[0]) & 1) != j[1]:
          return False
  return True
  
x = 0b0
ans = -1
for i in range(2**N):
  if judge(h, x):
    tmp = 0
    for i in range(N):
      if (x >> i) & 1:
        tmp += 1
    if tmp > ans:
      ans = tmp
  x += 1

print(ans)

Measured memory_bytes: 3064
#include<stdio.h>
main(){
  int n, q, S[10000], T[500], i, j, key, c=0;
  scanf("%d", &n);
  for(i = 0; i < n; i++){
    scanf("%d", &S[i]);
  }
  scanf("%d", &q);
  for(i = 0; i < q; i++){
    scanf("%d", &T[i]);
  }
  for(i = 0; i < q; i++){
    key = T[i];
   S[n] = key;
   j = 0;
    while(S[j] != key){
      j++;
    }
    if(j != n){
      c++;
    }
  }
  printf("%d\n", c);
  return 0;
}

Measured memory_bytes: 640
#include<bits/stdc++.h>
using vvi = std::vector<std::vector<int>>;


int main()
{
    int h,w;
    std::cin >> h >> w;
    vvi dist(10,std::vector<int>(10));
    vvi map(h,std::vector<int>(w));


    for(int i = 0; i < 10; i++){
        for(int j = 0; j < 10; j++){
            std::cin >> dist[i][j];
        }
    }
    for(int i = 0; i < h; i++){
        for(int j = 0; j < w; j++){
            std::cin >> map[i][j];
        }
    
    }
    //Warshall-Floyd
    for(int k = 0; k < 10; k++){            //経由
        for(int i = 0; i < 10; i++){        //始点
            for(int j = 0; j < 10; j++){    //終点
                dist[i][j] = std::min(dist[i][j] , dist[i][k] + dist[k][j]);
            }
        }
    }

    int res = 0;
    for(int i = 0; i < h; i++){
        for(int j = 0; j < w; j++){
            if(map[i][j] == -1)continue;
            res += dist[map[i][j]][1];
        }
    }
    std::cout << res << std::endl;
}

Measured memory_bytes: 384
#include<bits/stdc++.h>
#define rep(i,N) for(int i=0;i<(N);i++)
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
using namespace std;
const long long MOD = 1e9 + 7;
const long long INF = 1e12;
const int inf = 1e9;
typedef long long ll;
typedef pair<ll,int> P;
typedef set<int> S;
ll n,m;
int main(){
    cin >> n >> m;
    vector<pair<ll,ll>> v;
    rep(i,n){
        ll a,b;
        cin>>a>>b;
        v.push_back(make_pair(a,b));
    }
    sort(v.begin(),v.end());
   //rep(i,n) cout<<v[i].first<<" "<<v[i].second<<endl;
    ll now =0;
    ll ans = 0;
    ll i = 0;
    while(1){
        if(now+v[i].second>=m){
            ans += v[i].first*(m-now);
            cout<<ans<<endl;
            return 0;
        }
        ans += v[i].first*v[i].second;
        now += v[i].second;
        //cout<<ans<<endl;
        i++;
    }
    
    return 0;
}

Measured memory_bytes: 2420
A,B,M=map(int,input().split())
a=list(map(int,input().split()))
b=list(map(int,input().split()))

price=[0]*(M+1)
price[0]=min(a)+min(b)

for i in range(M):
    x,y,c=map(int,input().split())
    price[i+1]=a[x-1]+b[y-1]-c

print(min(price))


Measured memory_bytes: 18736
#include <bits/stdc++.h>
using namespace std;
#define F(i,a,b) for(long long int i=a;i<b;i++)
#define f(i,n) for(long long int i=0;i<n;i++)
typedef unsigned long long ull;
typedef long long ll;
#define vint vector<int>
#define vll vector<long long int>
#define vull vector<unsigned long long int>
#define pb(a) push_back(a);
#define bug(x) cout<<#x<<" = "<<x<<"\n";
#define fastio ios_base::sync_with_stdio(false); cin.tie(0)

int main(){
	fastio;
	int n; cin>>n;
	vull a(n);
	f(i,n){
		cin>>a[i];
	}
	sort(a.begin(),a.end(),greater<ull>());
	
	ull ans=a[0];
	int j=1,count=0;
	// cout<<a[0]<<"\n";
	F(i,2,n){
		// cout<<a[j]<<"\n";
		ans += a[j]; count+=1;
		if(count==2){j++; count=0;} 
		// cout<<a[i]<<" ";
	}
	cout<<ans<<"\n";
	return 0;
}

Measured memory_bytes: 4776
#include<bits/stdc++.h>
using namespace std;
int main(){
  	long long a,b,c;
	cin >> a >> b >> c;
	if(c>a){
		c=c-a;
		a=0;
		if(c>b){
			b=0;
		}
		else{
			b=b-c;
		}
	}
	else{
		a=a-c;
	}
	cout << a << " " << b << endl;
	return 0;
}

Measured memory_bytes: 256
N, M = map(int, input().split())
H = list(map(int, input().split()))
l = [0 for i in range(len(H))]
A = []
B = []
for _ in range(M):
    temp = list(map(int, input().split()))
    A.append(temp[0])
    B.append(temp[1])

for i in range(M):
    if H[A[i]-1] > H[B[i]-1]:
        l[B[i]-1] = 1
    elif H[A[i]-1] < H[B[i]-1]:
        l[A[i]-1] = 1
    else:
        l[A[i]-1] = 1
        l[B[i]-1] = 1
print(len(H)-sum(l))

Measured memory_bytes: 23180
#include<bits/stdc++.h>
using namespace std;
int main(){
  int n, m, l;
  cin >> n >> m >> l;
  int A[100][100] = {0};
  int B[100][100] = {0};
  for(int i = 0; i< n;i++){
      for(int j=0;j<m;j++){
          cin >>A[i][j];
      }
  }
    for(int i = 0; i< m;i++){
      for(int j=0;j<l;j++){
          cin >>B[i][j];
      }
  }
  
    for(int i = 0; i< n;i++){
      for(int j=0;j<l;j++){
          long X=0;
          for(int k = 0; k<m;k++){
              X += A[i][k] *B[k][j];
          }
          cout << X;
          if(j!= l-1)cout << ' ';
      }
      cout << endl;
  }
}


Measured memory_bytes: 3172
#include <iostream>
#include <cmath>
#include <vector>
#include <map>
#include <iomanip>
#include <algorithm>
#include <sstream>
#include <string>
#include <math.h>
#include <set>
using namespace std;
typedef long long ll;
const int mod = 1000000007;
 
int main() {
    ios::sync_with_stdio(false);
	int n;
	cin >> n;
	int a, b;
	int x = 0;
	for (int i = 0 ; i < n ; i++) {
		cin >> a >> b;
		x += b - a + 1;
	} 
	cout << x;
}

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

void solve(std::string S, long long K){
    ll N = S.size();
    vector<ll> vec;
    for(int i=0;i<N;i++){
        ll num =1;
        while(i+1<N && S[i] == S[i+1]){
            num++;
            i++;
        }
        vec.push_back(num);
    }
    if(vec.size()==1){
        cout << (K*N)/2 << endl;
        return;
    }

    ll midsize =0;
    for(int i=1;i<vec.size()-1;i++){
        midsize += vec[i]/2;
    }

    if(S[0] == S[N-1]){
         cout << (vec.front()/2) + midsize*K + (vec.back()/2) +((vec.front() + vec.back())/2)*(K-1) << endl;
    }else{
        cout << (vec.front()/2 + midsize + vec.back()/2)*K << endl;
    }


}

// Generated by 1.1.7.1 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
int main(){
    std::string S;
    std::cin >> S;
    long long K;
    scanf("%lld",&K);
    solve(S, K);
    return 0;
}


Measured memory_bytes: 3672
#include<bits/stdc++.h>
#include<iostream>
#include<vector>
#include<algorithm>
#include<numeric>
using namespace std;
int main(){
   int n;
   int max_L=0;
   int total=0;
   cin>>n;
   for(int i=0;i<n;i++){
       int L;
       cin>>L;
       max_L=max(L,max_L);
       total+=L;
   }
   if(max_L<total-max_L){
       cout<<"Yes"<<endl;
   }else{
       cout<<"No"<<endl;
   }
}

Measured memory_bytes: 256
N = int(input())
a = [0] + list(map(int, input().split()))
b = set([i for i in range(N//2 + 1, N + 1) if a[i] == 1])

for i in range(N//2, 0, -1):
    if sum([1 for k in range(2, N//i + 1) if k*i in b]) % 2 != a[i]:
        b.add(i)

if len(b) > 0:
    print(len(b))
    print(' '.join(list(map(str, sorted(list(b))))))
else:
    print(0)

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

int main(void){
  int A,B,C,d;
  
  d=scanf("%d %d %d",&A,&B,&C);
  
  if(d!=3){
    printf("正常に作動しません\n");
    exit(1);
  }
   if((A==B&&B!=C)||(B==C&&C!=A)||(C==A&&A!=B)){
     printf("Yes\n");
   }
    else{
      printf("No\n");
    }
    return 0;
  }

Measured memory_bytes: 128
#include <iostream>
#include <vector>
#include <set>
#include <numeric>
#include <algorithm>
#include <cmath>
#include <limits.h>
 
#define YesNo(b) ((b) ? "Yes" : "No")
#define YESNO(b) ((b) ? "YES" : "NO")

using namespace std;
using vi = vector<int>;
using vvi = vector<vi>;
using ll = long long;
using vll = vector<ll>;
using vvll = vector<vll>;



int main()
{
    string S, T;
    cin >> S >> T;

    set<int> bucS[26], bucT[26];
    for (size_t i = 0; i < S.size(); i++)
    {
        bucS[S[i]-'a'].insert(i);
        bucT[T[i]-'a'].insert(i);
    }
    
    bool ans = true;
    for (size_t i = 0; i < 26; i++)
    {
        if (bucT[i].size() == 0) continue;
        
        int is = S[*(bucT[i].begin())] - 'a';
        
        ans = ans && (bucS[is] == bucT[i]);
    }

    cout << YesNo(ans) << endl;
}


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

typedef long long ll;
typedef pair<int, int> P;
#define MOD 1000000007
#define INF (1 << 30)
#define REP(i, m, n) for(int i = (int)m; i < (int)n; ++i)
#define rep(i, n) REP(i, 0, n)


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

    int sumA = 0, sumB = 0;
    rep(i, 4) {
        int a; cin >> a;
        sumA += a;
    }
    rep(i, 4) {
        int b; cin >> b;
        sumB += b;
    }
    cout << max(sumA, sumB) << '\n';
    return 0;
}


Measured memory_bytes: 3136
#include<stdio.h>
#define WHITE 0
#define GRAY 1
#define BLACK 2
#define INF -1;
int color[101];
int A[101][101];
int n,dis,head,tail;
int q[101];
int d[101];
void bfs(int);
void enqueue(int);
int dequeue(void);
void print(void);
int main(){
  int i,j,k,id,kn;
  scanf("%d",&n);
  for(i=0;i<n;i++){
    scanf("%d%d",&id,&kn);
    for(j=0;j<kn;j++){
      scanf("%d",&k);
      A[id][k]=1;
    }
  }
  bfs(1);
  for(i=1;i<=n;i++){
    printf("%d %d\n",i,d[i]);
  }
  return 0;
}
void bfs (int root){
  int i,j,u;
  for(i=1;i<=n;i++){
      d[i]=INF;
  }
      d[root]=0;
      color[root]=GRAY;
      head=1;
      tail=2;
      enqueue(root);
      /* print();*/
      while(head!=tail){
	u=dequeue();
	/*print();*/
	for(i=1;i<=n;i++){
	  if(A[u][i]==1){
	    if(color[i]==WHITE){
	      color[i]=GRAY;
	      d[i]=d[u]+1;
	      enqueue(i);
	      /* print();*/
	    }
	  }
	}
	color[u]=BLACK;
      }
}
void enqueue(int k){
  q[tail]=k;
  tail++;
}
int dequeue(void){
  int k;
  k=q[head];
  head++;
  return k;
}
void print(void){
  int i;
  printf("Q----\n");
  for(i=head;i<tail;i++){
    printf("%d ",q[i]);
  }
  printf("%d\n-----Q\n",q[i]);
}
	    
    

    
  
  
 



Measured memory_bytes: 2060
#include <algorithm>
#include <iostream>
#include <numeric>
#include <string>
#include <utility>
#include <vector>

int main() {
  int n, k;
  std::cin >> n >> k;
  int a = 1;
  for (int ki = 1; ki < k; ++ki) a += 2;
  std::cout << (a <= n ? "YES" : "NO") << std::endl;
  return 0;
}


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

#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define ALL(obj) (obj).begin(), (obj).end()
#define INF 1e9
typedef long long ll;


int main() {
    int N,M;
    cin >> N >> M;
    vector<int> H(N);
    REP(i,N){
        cin >> H[i];
    }

    vector<vector<int>> G(N);

    vector<bool> seen(N,false);

    REP(i,M){
        int a,b;
        cin >> a >> b;
        a--;
        b--;
        G[a].push_back(b);
        G[b].push_back(a);
    }

    int ans = 0;
    REP(i,N){
        bool ok = true;
        seen[i] = true;
        for(auto next: G[i]){
            if(H[i] <= H[next]){
                ok = false;
            }
        }
        if(ok){
            ans++;
        }
    }

    REP(i,N){
        if(!seen[i]){
            ans++;
        }
    }

    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 8800
#include <cstdio>
const int MAXN = 100;

using namespace std;

int main()
{
	int nums[MAXN];
	int key;

	int n;
	scanf("%d", &n);

	for (int i = 0; i < n; i++)
	{
		scanf("%d", &nums[i]);
	}

	for (int i = 0; i < n; i++)
	{
		key = nums[i];
		int j;
		for (j = i - 1; j >= 0 && nums[j] > key; j--)
		{
			nums[j + 1] = nums[j];
		}
		nums[j + 1] = key;
		for (int k = 0; k < n; k++)
		{
			if (k != n - 1)
			{
				printf("%d ", nums[k]);
			}
			else
			{
				printf("%d", nums[k]);
			}
		}
		putchar('\n');
	}

	return 0;
}


Measured memory_bytes: 2756
#include<bits/stdc++.h>
#define fi first
#define se second
#define rep(i, n) for(int (i) = 0; (i) < (n); (i)++)
#define rrep(i, n) for (int (i) = 1; (i) <= (n); (i++))
#define rng(a) a.begin(),a.end()
#define rrng(a) a.rbegin(),a.rend()
#define pb push_back
#define eb emplace_back
#define yn {puts("Yes");}else {puts("No");}
#define printd(x) printf("%.12f\n", x);
template<class T> bool chmin(T& a, const T& b) {if (a > b) {a = b; return 1;} return 0;}
template<class T> bool chmax(T& a, const T& b) {if (a < b) {a = b; return 1;} return 0;}
using namespace std;
using ll = long long;

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

	vector<pair<int, int>> ans;
	for (int i = n; i >= 2; i--) {
		for (int j = i - 1; j >= 1; j--) {
			if (n % 2 == 1) {
				if (j == n - i) continue;
				ans.eb(i, j);
			}
			else {
				if (j == n + 1 - i) continue;
				ans.eb(i, j);
			}
		}
	}

	cout << ans.size() << endl;
	rep (i, ans.size()) cout << ans[i].fi << " " << ans[i].se << endl;
	return 0;
}

Measured memory_bytes: 384
import itertools
n = int(input())
xyh = [list(map(int, input().split())) for i in range(n)]
for cx, cy in itertools.product(range(0,101), repeat=2):
  flag = False
  hhh = []
  for i in range(n):
    if xyh[i][2] != 0:
      h = xyh[i][2] + abs(xyh[i][0]-cx) + abs(xyh[i][1]-cy)
      hhh.append(h)
  if len(set(hhh)) == 1:
    flag = True
    for i in range(n):
      if xyh[i][2] == 0:
         if hhh[0] - abs(xyh[i][0]-cx) - abs(xyh[i][1]-cy) > 0:
            flag = False
  if flag:
    print(cx, cy, hhh[0])

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

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

using namespace std;
using lint=long long;

int main(){
	int n; scanf("%d",&n);
	vector<pair<int,int>> a(n);
	rep(i,n){
		int l,r; scanf("%d%d",&l,&r);
		a[i]=minmax(l,r);
	}

	int mx=0,mn=1e9;
	rep(i,n){
		mx=max(mx,a[i].second);
		mn=min(mn,a[i].first);
	}

	lint ans=1LL<<61;
	{
		int rmx=mn,bmn=mx;
		rep(i,n){
			rmx=max(rmx,a[i].first);
			bmn=min(bmn,a[i].second);
		}
		ans=min(ans,1LL*(rmx-mn)*(mx-bmn));
	}
	{
		sort(a.begin(),a.end());
		multiset<int> S;
		rep(i,n) S.emplace(a[i].first);
		rep(i,n+1){
			int bmn=*S.begin(),bmx=*S.rbegin();
			ans=min(ans,1LL*(mx-mn)*(bmx-bmn));
			if(i<n){
				S.erase(S.find(a[i].first));
				S.emplace(a[i].second);
			}
		}
	}
	printf("%lld\n",ans);

	return 0;
}


Measured memory_bytes: 11136
#include<stdio.h>

int main()
{
    int n,m;
    while(~scanf("%d %d",&n,&m))
    {
        n=n*(n-1);
        n=n/2;
        m=m*(m-1);
        m=m/2;
        printf("%d\n",n+m);
    }
    return 0;
}


Measured memory_bytes: 128
from collections import deque

n = int(input())
C = [[] for i in range(n)]
Cnum = [0 for i in range(n)]
P = [-1 for i in range(n+1)]
S = [-1 for i in range(n+1)]
Dep = [0 for i in range(n)]
Deg = [0 for i in range(n)]
H = [0 for i in range(n)]
Typ = ["leaf" for i in range(n)]
for i in range(n):
    id,left,right=map(int,input().split( ))
    C[id] = [left,right]
    P[left] = id
    P[right] = id
    S[left] = right
    S[right] = left
    if left != -1:#完全二分木でなかった
            Deg[id] += 1
            Typ[id] = "internal node"
    if right != -1:
            Deg[id] += 1
            Typ[id] = "internal node"
for i in range(n):
    if P[i] == -1:
        root = i

Typ[root] = "root"

D = deque()
D.append(root)

while len(D)>0:#また-1の扱いがおかしかった
    t = D.popleft()#()忘れてた
    d = Dep[t]
    left = C[t][0]
    right = C[t][1]
    if left != -1:
        D.append(left)
        Dep[left] = d+1
    if right != -1:
        D.append(right)
        Dep[right] = d+1

def height_child(i):
    global C,Cnum,H

    if C[i] == [-1,-1]:
        return [0,0]

    h = max(height_child(C[i][0])[0], height_child(C[i][1])[0])+1
    c = height_child(C[i][0])[1] + height_child(C[i][1])[1] + 2
    H[i] = h
    Cnum[i] = c

    return [h,c]

height_child(root)

#for i in range(n):
#    print(f"node :{i} parent = {P[i]}, sibling = {S[i]}, degree = {Deg[i]}, depth = {Dep[i]}, height = {H[i]}, {Typ[i]}")
for i in range(n):
 print('node {}: parent = {}, sibling = {}, degree = {}, depth = {}, height = {}, {}'.format(i,P[i],S[i],Deg[i],Dep[i],H[i],Typ[i]))



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

int main(){
    string s;
    cin>>s;
    int n=0,w=0,so=0,e=0;

    int k=s.size();

    for(int i=0;i<k;i++){
        if(s[i]=='N') n++;
        else if(s[i]=='W') w++;
        else if(s[i]=='S') so++;
        else e++;
    }

    bool ok=true;

    if(n==0 && so!=0) ok=false;
    if(n!=0 && so==0) ok=false;
    if(w!=0 && e==0) ok=false;
    if(w==0 && e!=0) ok=false;

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

}



Measured memory_bytes: 256
#include<iostream>
using namespace std;
typedef int アハ;
#define アッハッハ main
#define ブワハハ cin
#define ゲラゲラ cout
typedef void 笑;


アハ アッハッハ(笑){
    アハ オホホ,イヒヒ;
    ブワハハ>>オホホ>>イヒヒ;
    ゲラゲラ<<(オホホ-1)*(イヒヒ-1);
}


Measured memory_bytes: 504
use std::io;

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

    io::stdin().read_line(&mut input).expect("failed read line");
    
    let mut count: u32 = 0;
    for s in input.trim().chars() {
        if s == '1' {
            count += 1;
        }
    }

    println!("{}", count)
}

Measured memory_bytes: 2104
#include<stdio.h>

int main(){
  int a,b,c,k,sum;
  int max=0;
  int num[3];

  scanf("%d %d %d",&a,&b,&c);
  scanf("%d",&k);

  num[0]=a;
  num[1]=b;
  num[2]=c;

  for(int i=0;i<3;i++){
    for(int n=0;n<k;n++){
      num[i]=num[i]*2;
    }
    sum=num[0]+num[1]+num[2];
    if(sum>max) max=sum;
    num[0]=a;
    num[1]=b;
    num[2]=c;
  }

  printf("%d\n",max);

  return 0;
}


Measured memory_bytes: 128
h = -1
w = -1

while True:
  input = map(int, raw_input().split(" "))
  h = input[0]
  w = input[1]
  if (h == 0 and w == 0):
    break

  i = 1
  j = 0
  inner_line = "#"
  outer_line = ""

  while j < w:
    outer_line += "#"
    if (j != 0 and j != w - 1):
      inner_line += "."
    j += 1
  inner_line += "#"

  print outer_line  
  while i < h - 1:
    print inner_line
    i += 1
  print outer_line

  print ""

Measured memory_bytes: 4232
#include<stdio.h>
#include<string.h>
int main()
{
    int i,j,k,n,p=0,l=0;
    char x[1000];
    char y[1000];
    scanf("%d",&n);
    getchar();
    while(n--)
    {
        scanf("%s",x);

        scanf("%s",y);

        if(strcmp(x,y)==0){p=p+1,l=l+1;};
        if(strcmp(x,y)<0){l=l+3;};
        if(strcmp(x,y)>0){p=p+3;};

    }
    printf("%d %d\n",p,l);
    return 0;
}



Measured memory_bytes: 2104
#include <iostream>
#include <string>
#include <algorithm>
#include <functional>
#include <vector>
#include <utility>
#include <cstring>
#include <iomanip>
#include <numeric>
#include <cmath>
#include <cassert>
using namespace std;
using ll = long long;
const int INF = 1<<30;
const int MOD = 1e9 + 7;
signed main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n; cin >> n;
    string s; cin >> s;
    int k; cin >> k;
    k--;
    char ch = s[k];
    for(int i = 0; i < n; i++)
    {
        if(ch != s[i]) s[i] = '*';
    }
    cout << s << endl;
    return 0;
}



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


int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    long long n;
    vector<long long> v;
    cin >> n;
    for (long long i = 0; i < n; i++) {
      long long t;
      cin >> t;
      v.push_back((t));
    }
    long long res=0;
    for (long long i = 0; i < n - 1; i++) {
      if (v[i] > v[i + 1]) {
        res += (v[i] - v[i+1]);
        v[i + 1] = v[i];
        
      }
    }

    cout <<res;
    

}


Measured memory_bytes: 5236
import std.stdio;
import std.string;
import std.conv;
import std.array;
import std.algorithm;

static bool greater(string a, string b){
    return a > b;
}
void main(){
    int N,L;
    int i;
    string[] str;
    auto temp = readln();
   // writeln(temp);
    N = temp.split[0].to!int;
    L = temp.split[1].to!int;
    
    for(i=0;i<N;i++){
        temp = readln().dup;
        str = str ~ removechars(temp,"\n");
    }
    sort(str);
    for(i=0;i<N;i++){
        write(str[i]);
    }
    writeln("");
}


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

int main(void){
    int H, M;
    double A, B;
    cin >> A >> B >> H >> M;
    double d = abs((H % 12) * 30 - M * 5.5);
    d = min(d, 360 - d);

    double L = 0.0;
    if (d == 90){
        L = sqrt(A*A + B*B);
    }
    else if (d < 90){
        L = sqrt(A*A + B*B - 2*A*B*cos(acos(-1) * d / 180));
    }
    else if (d > 90){
        L = sqrt(A*A + B*B + abs(2*A*B*cos(acos(-1) * d / 180)));
    }
    
    cout << fixed << setprecision(15) << L << endl;
}


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

typedef unsigned long long ull;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<double, double> pdd;
const ull mod = 1e9 + 7;
#define REP(i,n) for(int i=0;i<(int)n;++i)

int main(){
	int N, A, B;
	cin >> N;
	if (N==1){
		cout << "Hello World" << endl;
	}else{
		cin >> A >> B;
		cout << A+B << endl;
	}
    return 0;
}

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

int main(){
    string str;
    cin >> str;
    int start = 0,goal = 0,k = 0,offset = 0;

    

    for(int i = 0; i < str.length(); i++){
        if(i+1 < str.length()){
            if(str[i] == str[i+1]){
                cout << i+1 << " " << i+2 << endl;
                return 0;
            }
        }
        if(i+2 < str.length()){
            if(str[i] == str[i+2]){
                cout << i+1 << " " << i+3 << endl;
                return 0;
            }
        }
    }


    cout << -1 << " " << -1 << endl;
    return 0;
}


Measured memory_bytes: 512
import java.util.*;

public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int x = sc.nextInt();
    int a = sc.nextInt();
    int b = sc.nextInt();
    
    System.out.println(Math.abs(x-a) > Math.abs(x-b) ? "B" : "A");
  }
}

Measured memory_bytes: 23764