akhauriyash/Code-Regression huggingface dataset:
N = int(input())
A =[int(i) for i in input().split()]
B =[int(i) for i in input().split()]
ans = 0
for i in range(N):
    if B[i]>=A[i]:
        ans += A[i]
        B[i] -= A[i]
        if A[i+1]>=B[i]:
            ans += B[i]
            A[i+1] -= B[i]
        else:
            ans += A[i+1]
            A[i+1] = 0
    else:
        ans += B[i]

print(ans)


Measured memory_bytes: 19648
package main

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

func main() {
	sc := NewScanner()
	_ = sc.NextInt()
	A := sc.NextIntArray()

	mp := map[int]int{}

	for _, v := range A {
		mp[v]++
	}

	ans := 0

	for k, v := range mp {
		if k < v {
			ans += v - k
		} else if k > v {
			ans += v
		}
	}
	fmt.Println(ans)
}

type Scanner struct {
	r   *bufio.Reader
	buf []byte
	p   int
}

func NewScanner() *Scanner {
	rdr := bufio.NewReaderSize(os.Stdin, 1000)
	return &Scanner{r: rdr}
}
func (s *Scanner) Next() string {
	s.pre()
	start := s.p
	for ; s.p < len(s.buf); s.p++ {
		if s.buf[s.p] == ' ' {
			break
		}
	}
	result := string(s.buf[start:s.p])
	s.p++
	return result
}
func (s *Scanner) NextLine() string {
	s.pre()
	start := s.p
	s.p = len(s.buf)
	return string(s.buf[start:])
}
func (s *Scanner) NextInt() int {
	v, _ := strconv.Atoi(s.Next())
	return v
}
func (s *Scanner) NextInt64() int64 {
	v, _ := strconv.ParseInt(s.Next(), 10, 64)
	return v
}

func (s *Scanner) NextIntArray() []int {
	s.pre()
	start := s.p
	result := []int{}
	for ; s.p < len(s.buf)+1; s.p++ {
		if s.p == len(s.buf) || s.buf[s.p] == ' ' {
			v, _ := strconv.ParseInt(string(s.buf[start:s.p]), 10, 0)
			result = append(result, int(v))
			start = s.p + 1
		}
	}

	return result
}
func (s *Scanner) NextInt64Array() []int64 {
	s.pre()
	start := s.p
	result := []int64{}
	for ; s.p < len(s.buf)+1; s.p++ {
		if s.p == len(s.buf) || s.buf[s.p] == ' ' {
			v, _ := strconv.ParseInt(string(s.buf[start:s.p]), 10, 64)
			result = append(result, v)
			start = s.p + 1
		}
	}
	return result
}

func (s *Scanner) NextMap() map[int]bool {
	s.pre()
	start := s.p
	mp := map[int]bool{}
	for ; s.p < len(s.buf); s.p++ {
		if s.buf[s.p] == ' ' {
			v, _ := strconv.Atoi(string(s.buf[start:s.p]))
			mp[v] = true
			start = s.p + 1
		}
	}
	v, _ := strconv.Atoi(string(s.buf[start:s.p]))
	mp[v] = true

	return mp
}

func (s *Scanner) pre() {
	if s.p >= len(s.buf) {
		s.readLine()
		s.p = 0
	}
}
func (s *Scanner) readLine() {
	s.buf = make([]byte, 0)
	for {
		l, p, e := s.r.ReadLine()
		if e != nil {
			panic(e)
		}
		s.buf = append(s.buf, l...)
		if !p {
			break
		}
	}
}


Measured memory_bytes: 8960
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <cstdio>
#include <cstring>
#include <cmath>
using namespace std;
using ll = long long;

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

    cout << (s <= "2019/04/30" ? "Heisei" : "TBD") << endl;

    return 0;
}

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

namespace ContestCs
{
    class Program
    {
        static void Main()
        {
            while (true)
            {
                var sum = int.Parse(Console.ReadLine());
                if (sum == 0) return;
                for (int i = 0; i < 9; i++)
                {
                    sum -= int.Parse(Console.ReadLine());
                }
                Console.WriteLine(sum);
            }
        }
    }
}

Measured memory_bytes: 19940
import sys
readline = sys.stdin.readline
 
N,W = map(int,readline().split())
 
import numpy as np
dp = np.zeros(W + 1, dtype = int)
 
for i in range(N):
  w,v = map(int,readline().split())
  np.maximum(dp[:-w] + v, dp[w:], out = dp[w:])
  
print(dp.max())

Measured memory_bytes: 29080
// 素因数２の個数を積算する.
#include<iostream>
using namespace std;
int main(){
  int n; cin >> n;
  int a[10005];
  int ans=0;
  for(int i=0;i<n;i++){
    int a; cin >> a;
    int b=a;
    int count=0;
    while(b%2==0){
      count++;
      b = b/2;
    }
    ans += count;
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
const int inf=1e9;
int n,S,T,d[200010],ans,a[100010],b[100010];
vector<int> v[100010];
int cnt=1,head[200010],to[800010],nxt[800010],w[800010];
bool used[100010];
void add(int x,int y,int z)
{
	cnt++;
	to[cnt]=y;
	nxt[cnt]=head[x];
	head[x]=cnt;
	w[cnt]=z;
}
void ins(int x,int y,int z)
{
	add(x,y,z);
	add(y,x,0);
}
bool bfs()
{
	for (int i=S;i<=T;i++)
	{
		d[i]=-1;
	}
	queue<int> q;
	d[S]=0;
	q.push(S);
	while (!q.empty())
	{
		int x=q.front();
		q.pop();
		if (x==T)
		{
			return true;
		}
		for (int i=head[x];i;i=nxt[i])
		{
			int y=to[i];
			if (w[i] && d[y]==-1)
			{
				d[y]=d[x]+1;
				q.push(y);
			}
		}
	}
	return false;
}
int dfs(int x,int f)
{
	int res=0;
	if (x==T)
	{
		return f;
	}
	for (int i=head[x];i;i=nxt[i])
	{
		int y=to[i];
		if (w[i] && d[y]==d[x]+1)
		{
			int tmp=dfs(y,min(f-res,w[i]));
			w[i]-=tmp;
			w[i^1]+=tmp;
			res+=tmp;
			if (res==f)
			{
				return res;
			}
		}
	}
	if (!res)
	{
		d[x]=-1;
	}
	return res;
}
void dinic()
{
	while (bfs())
	{
		ans+=dfs(S,inf);
	}
}
int main()
{
	scanf("%d",&n);
	S=1;
	T=2*n;
	for (int i=1;i<n;i++)
	{
		int k;
		scanf("%d",&k);
		for (int j=0;j<k;j++)
		{
			int x;
			scanf("%d",&x);
			v[x].push_back(i);
			if (x!=1)
			{
				ins(x,n+i,1);
			}
		}
	}
	for (int i=2;i<=n;i++)
	{
		ins(S,i,1);
	}
	for (int i=1;i<n;i++)
	{
		ins(n+i,T,1);
	}
	dinic();
	if (ans!=n-1)
	{
		puts("-1");
		return 0;
	}
	for (int i=n+1;i<2*n;i++)
	{
		for (int j=head[i];j;j=nxt[j])
		{
			if (!w[j])
			{
				continue;
			}
			a[i-n]=to[j];
		}
	}
	queue<int> q;
	used[1]=true;
	q.push(1);
	while (!q.empty())
	{
		int x=q.front();
		q.pop();
		for (int i=0;i<v[x].size();i++)
		{
			int y=v[x][i];
			if (!used[a[y]])
			{
				used[a[y]]=true;
				q.push(a[y]);
				b[y]=x;
			}
		}
	}
	bool f=true;
	for (int i=1;i<n;i++)
	{
		f&=used[i];
	}
	if (!f)
	{
		puts("-1");
		return 0;
	}
	for (int i=1;i<n;i++)
	{
		printf("%d %d\n",a[i],b[i]);
	}
	return 0;
}
//霓为衣兮风为马，云之君兮纷纷而来下。
//——李白《梦游天姥吟留别》

Measured memory_bytes: 23156
#include <cstdio>
#include <iostream>
#include <vector>

using namespace std;

int main(void)
{
    int reword[] = {300000, 200000, 100000};
    int x,y;
    cin >>x >>y;

    int sum = 0;
    if(x -1 < 3){
        sum += reword[x-1];
    }
    if(y -1 < 3){
        sum += reword[y-1];
    }
    if(x == 1 && y == 1){
        sum += 400000;
    }

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

    return 0;
}

Measured memory_bytes: 256
use std::io::*;
use std::str::FromStr;

fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let stdin = stdin.lock();
    let token: String = stdin
        .bytes()
        .map(|c| c.expect("failed to read char") as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().expect("failed to parse token")
}

fn main() {
    let age: i32 = read();
    let price: i32 = read();
    let ret = if age <= 5 {
        0
    } else if age <= 12 {
        price / 2
    } else {
        price
    };
    println!("{}", ret);
}


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


int main()
{
	int n;
	cin >> n;
	for (int i = 1; i <= n; i++)
	{
		if (i % 3 == 0) cout << " " << i;
		else if (i % 10 == 3) cout << " " << i;
		else if (i % 10 != 3 && i % 3 != 0)
		{
			int x = i;
			while (x % 10 != 3)
			{
				x /= 10;
				if (x <= 9) break;
			}
			if (x % 10 == 3) cout << " " << i;
		}
		
		if (i == n)cout << endl;
	}
}


Measured memory_bytes: 3116
type ABC(stream:System.IO.TextReader) =
  member this.Scan1 f = stream.ReadLine() |> f
  member this.Scan2 f = stream.ReadLine().Split() |> Array.map f |> (fun a -> (a.[0], a.[1]))
  member this.Scan3 f = stream.ReadLine().Split() |> Array.map f |> (fun a -> (a.[0], a.[1], a.[2]))
  member this.Scan4 f = stream.ReadLine().Split() |> Array.map f |> (fun a -> (a.[0], a.[1], a.[2], a.[3]))
  member this.ScanVecH f = stream.ReadLine().Split() |> Array.map f
  member this.ScanVecV n f = [| for i in 1..n -> stream.ReadLine() |> f |]
  member this.ScanMatrix n f  = [| for i in 1..n -> stream.ReadLine().Split() |> Array.map f |]
  member this.ScanCharMatrix n = [| for i in 1..n -> stream.ReadLine().ToCharArray() |]
  member this.Close () = stream.Close()

let util = ABC(stdin)

let S = util.Scan1 (fun s -> s.ToCharArray())
let T = util.Scan1 (fun s -> s.ToCharArray())
let dicS = Array.init 26 (fun _ -> -1)
let dicT = Array.init 26 (fun _ -> -1)

let rec rfn xs =
  match xs with
  | [] -> true
  | i::xs ->
      let s = (int S.[i]) - (int 'a')
      let t = (int T.[i]) - (int 'a')
      do if dicS.[s] = -1 then Array.set dicS s t
         if dicT.[t] = -1 then Array.set dicT t s
      match t = dicS.[s], s = dicT.[t] with
      | true, true -> rfn xs 
      | _ -> false

if S.Length <> T.Length
then
  printfn "No"
else
  if rfn [0..S.Length-1]
  then printfn "Yes"
  else printfn "No"

util.Close()


Measured memory_bytes: 24152
#include "bits/stdc++.h"
#define _overload3(_1,_2,_3,name,...) name
#define _rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(int i=int(a),i##_len=(b);i<i##_len;++i)
#define MSVC_UNKO(x) x
#define rep(...) MSVC_UNKO(_overload3(__VA_ARGS__,repi,_rep,_rep)(__VA_ARGS__))
#define all(c) c.begin(),c.end()
#define mp make_pair
#define write(x) cout<<(x)<<"\n"
using namespace std; typedef long long ll; typedef vector<int> vi; typedef vector<ll> vll;
template<class T>using vv = vector<vector<T>>; template<class T>auto vvec(int n, int m, T v) { return vv<T>(n, vector<T>(m, v)); }
template<class T>bool chmax(T& a, const T& b) { return a < b ? a = b, 1 : 0; }
template<class T>bool chmin(T& a, const T& b) { return b < a ? a = b, 1 : 0; }
constexpr int INF = 1 << 29, MOD = int(1e9) + 7; constexpr ll LINF = 1LL << 60;
struct aaa { aaa() { cin.tie(0); ios::sync_with_stdio(0); cout << fixed << setprecision(10); }; }aaaa;

int N, K;

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

    if (K > (N - 1) * (N - 2) / 2) {
        write(-1);
        return 0;
    }

    vector<pair<int, int>> edge;
    rep(i, 2, N + 1) {
        edge.emplace_back(1, i);
    }

    int ik = (N - 1) * (N - 2) / 2 - K;
    rep(i, 2, N) rep(j, i + 1, N + 1) {
        if (ik == 0) {
            break;
        }
        
        edge.emplace_back(i, j);
        ik--;
    }

    write(edge.size());
    rep(i, edge.size()) {
        cout << edge[i].first << " " << edge[i].second << endl;
    }
}

Measured memory_bytes: 384
#include <iostream>
#include <string>
#include <vector>
#include <numeric>
#include <queue>
#include <unordered_map>
#include <algorithm>
#include <cmath>
#include <iomanip>
#include <sstream>
#include <stack>
#include <map>
#include <set>
#include <ios>
#include <cctype>
#include <cstdio>
#include <functional>
#include <cassert>
#include <fstream>
#include <ctime>

using namespace std;
using ll = long long;

#define REP(i,a) for(int i = 0;i < (a);++i)
#define FOR(i,a,b) for(int i = (a);i < (b); ++i)
#define FORR(i,a,b) for(int i = (a) - 1;i >=(b);--i)
#define ALL(obj) (obj).begin(),(obj).end()
#define SIZE(obj) (int)(obj).sizeT()
#define YESNO(cond,yes,no){cout <<((cond)?(yes):(no))<<endl; }
#define SORT(list) sort(ALL((list)));
#define RSORT(list) sort((list).rbegin(),(list).rend())
#define ASSERT(cond,mes) assert(cond && mes)

constexpr int MOD = 1'000'000'007;
constexpr int INF = 1'050'000'000;

template<typename T>
T round_up(const T& a, const T& b) {
    return (a + (b - 1)) / b;
}

template <typename T1, typename T2>
istream& operator>>(istream& is, pair<T1, T2>& p) {
    is >> p.first >> p.second;
    return is;
}

template <typename T1, typename T2>
ostream& operator<<(ostream& os, pair<T1, T2>& p) {
    os << p.first << p.second;
    return os;
}

template <typename T>
istream& operator>>(istream& is, vector<T>& v) {
    REP(i, (int)v.size())is >> v[i];
    return is;
}

template <typename T>
T clamp(T& n, T a, T b) {
    if (n < a)n = a;
    if (n > b)n = b;
    return n;
}

template <typename T>
static T GCD(T u, T v) {
    T r;
    while (v != 0) {
        r = u % v;
        u = v;
        v = r;
    }
    return u;
}

template <typename T>
static T LCM(T u, T v) {
    return u / GCD(u, v) * v;
}

std::vector<int> enum_div(int n) {
    std::vector<int> ret;
    for (int i = 1; i*i <= n; ++i) {
        if (n%i == 0) {
            ret.push_back(i);
            if (i != 1 && i*i != n) {
                ret.push_back(n / i);
            }
        }
    }
    return ret;
}

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

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

struct ToUpper {
    char operator()(char c) { return toupper(c); }
};

struct ToLower {
    char operator()(char c) { return tolower(c); }
};

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(20);

    int N, M;
    cin >> N >> M;
    priority_queue<int> A;
    REP(i, N) {
        int a;
        cin >> a;
        A.emplace(a);
    }

    REP(i, M) {
        int n = A.top();
        A.pop();
        A.push(n / 2);
    }

    ll ans = 0;
    REP(i, N) {
        ans += A.top();
        A.pop();
    }

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

Measured memory_bytes: 892
#include <bits/stdc++.h> 
using namespace std;
#define rep(i, N) for(int i=0; i<N; i++)
typedef long long ll;
#define dump(x) cerr<<#x<<"="<<x<<endl
using P = pair<int, int>;

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

    auto digit = [&](int N){
        string cnt = to_string(N);
        int t = cnt.size();

        return t;
    };

    int ans = 100;
    for(int i=1; i<=sqrt(n); i++){
        int res; 
        if(n%i!=0) continue;
        res = n / i;
        int tmp = max(digit(res), digit(i)); 
        ans = min(ans, tmp); 
    }

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


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

long long int mod_pow(long long int n, long long int p, long long int mod)
{
    if (p == 0)
    {
        return 1;
    }
    if (p % 2 == 0)
    {
        long long int t = mod_pow(n, p / 2, mod);
        return t * t % mod;
    }
    return (n * mod_pow(n, p - 1, mod)) % mod;
}

//x*(x-1)*(x-2)*...*(x-k+1)
long long int permutation(long long int x, long long int k, long long int mod)
{
    long long int ans = 1;

    for (long long int i = 0; i < k; i++)
    {
        ans *= x - i;
        ans %= mod;
    }

    return ans;
}

long long int factorial(long long int n, long long int mod)
{
    return permutation(n, n, mod);
}

long long int combination(long long int n, long long int k, long long int mod)
{
    long long int X, Y;

    X = permutation(n, k, mod);
    Y = factorial(k, mod);

    long long int inverse_Y = mod_pow(Y, mod - 2, mod);

    return (X * mod_pow(Y, mod - 2, mod)) % mod;
}

int main()
{
    /* ------- 宣言と入力 ------- */

    long long int n, a, b;

    cin >> n >> a >> b;

    /* ------- 計算 ------- */

    long long int mod = 1000000007;

    long long int ans;

    ans = mod_pow(2, n, mod);

    a = min(a, n - a);
    b = min(b, n - b);

    long long int nCa = combination(n, a, mod);
    long long int nCb = combination(n, b, mod);
    long long int nC0 = combination(n, 0, mod);

    ans -= (nCa + nCb + nC0) % mod;

    if (ans < 0)
    {
        ans += mod;
    }

    cout << ans << endl;

    return 0;
}


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

int main() {
  int n;
  cin >> n;
  vector<int> h(n);
  for(int i = 0; i < n; i++)
    cin >> h.at(i);
  reverse(h.begin(), h.end());
  bool b = 1;
  for(int i = 0; i < n-1; i++){
    if(h.at(i) < h.at(i+1)-1){
      b = 0;
      break;
    }
    else if(h.at(i) == h.at(i+1)-1)
      h.at(i+1)--;
  }
  if(b)
    cout << "Yes" << endl;
  else
    cout << "No" << endl;
}


Measured memory_bytes: 640
#include<bits/stdc++.h>
#include<atcoder/math>

using namespace std;
using ll = long long;
inline int ri() { int n; cin >> n; return n;}


void solve() {
	int n = ri(),  m = ri(), a = ri(), b = ri();
	cout << atcoder::floor_sum(n, m, a, b) << endl;	
}

int main()
{
	int T;
	cin >> T;
	while(T--)solve();
}



Measured memory_bytes: 3588
/*Complete Binary Tree*/
#include <stdio.h>
#include <stdlib.h>

#define N 250

typedef struct node{
  int key;
  struct node *right;
  struct node *left;
  struct node *parent;
} Node;

Node a[N];

void insert(int, int);

int main(){
  int i, n, k;
  
  scanf("%d", &n);
  for (i=1; i<=n; i++){
    a[i].parent = NULL;
    a[i].left = NULL;
    a[i].right = NULL;
    scanf("%d", &k);
    insert(k, i);
  }
  
  for (i=1; i<=n; i++){
    printf("node %d: key = %d, ", i, a[i].key);
    if (a[i].parent != NULL)
      printf("parent key = %d, ", a[i].parent->key);
    if (a[i].left != NULL)
      printf("left key = %d, ", a[i].left->key);
    if (a[i].right != NULL)
      printf("right key = %d, ", a[i].right->key);

    printf("\n");
  }
  
  return 0;
}


void insert(int k, int j){
  
  a[j].key = k;

  if(j!=1){
    if (j%2 == 0){
      a[j/2].left = &a[j];
      a[j].parent = &a[j/2];
    }
    else{
      a[j/2].right = &a[j];
      a[j].parent = &a[j/2];
    }
  }
  
}



Measured memory_bytes: 2044
#include <bits/stdc++.h>
#define rep(i, a) for(int i = 0; i < a; i++)
#define all(v) v.begin(), v.end()
#define dcout cout << fixed << setprecision(15)
#define arep(i, a) for(auto i : a)
#define F first
#define S second
#define VE vector<int>
#define pb(x) push_back(x)
#define MOD 1000000007
#define INF 10000000000
#define int long long
#define KETA(n) floor(log10(n) + 1)
using namespace std;
signed main() {
    string s, t;
    cin >> s >> t;
    int ans = 0;
    rep(i, s.size()) {
        if(s[i] != t[i]) ans++;
    }
    cout << ans << endl;
    return 0;
}

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

const int N=6100010;
int n,m,fa[N],ans[N],fv[N],u[N],v[N],x,y,hd[2010],cnt,Ans,tn[2],t[2][2010];
struct node{int to,next;}e[4010];
vector<int> V[2010];
bool bo[N];

void addedge(int x,int y)
{
	e[++cnt]=(node){y,hd[x]},hd[x]=cnt;
	e[++cnt]=(node){x,hd[y]},hd[y]=cnt;
}

void add(int x)
{
	V[u[x]].push_back(x);
	V[v[x]].push_back(x);
}

bool getpath(int x,int fa,int y,int o)
{
	if (x==y) return t[o][++tn[o]]=x,1;
	for (int i=hd[x]; i; i=e[i].next)
		if (e[i].to!=fa&&getpath(e[i].to,x,y,o)) return t[o][++tn[o]]=x,1;
	return 0;
}

void dfs(int x,int Fa)
{
	for (int i=hd[x]; i; i=e[i].next)
		if (e[i].to!=Fa) dfs(e[i].to,x);
	vector<int> vv; vv.clear();
	for (int i=0,sz=V[x].size(); i<sz; i++) 
		if (!bo[V[x][i]]) vv.push_back(V[x][i]),bo[V[x][i]]=1;
	Ans+=min((int)vv.size(),2);
	if (!vv.size()) return;
	if (vv.size()==1)
	{
		if ((u[vv[0]]^v[vv[0]]^x)==Fa) {ans[vv[0]]=0; return;}
		fa[vv[0]]=(++cnt),fv[vv[0]]=(u[vv[0]]==x);
		u[cnt]=(u[vv[0]]^v[vv[0]]^x),v[cnt]=Fa,add(cnt);
	} else
	{
		for (int j=2,sz=vv.size(); j<sz; j++)
		{
			if ((u[vv[j]]^v[vv[j]]^x)==Fa) {ans[vv[j]]=0; continue;}
			fa[vv[j]]=(++cnt),fv[vv[j]]=(u[vv[j]]==x);
			u[cnt]=(u[vv[j]]^v[vv[j]]^x),v[cnt]=Fa,add(cnt);
		}
		int p,p0=u[vv[0]]^v[vv[0]]^x,p1=u[vv[1]]^v[vv[1]]^x;
		tn[0]=0,getpath(x,0,p0,0),tn[1]=0,getpath(x,0,p1,1);
		while (tn[0]&&tn[1]&&t[0][tn[0]]==t[1][tn[1]]) p=t[0][tn[0]],tn[0]--,tn[1]--;
		if (p!=Fa) 
		{
			u[++cnt]=Fa,v[cnt]=p,add(cnt);
			u[++cnt]=Fa,v[cnt]=p,add(cnt);
		}
		if (p0!=p1)
		{
			fa[vv[0]]=fa[vv[1]]=(++cnt);
			fv[vv[0]]=(u[vv[0]]==x),fv[vv[1]]=(v[vv[1]]==x);
			u[cnt]=p0,v[cnt]=p1,add(cnt);
		} else ans[vv[0]]=0,ans[vv[1]]=(u[vv[0]]==u[vv[1]]);
	}
}

int main()
{
	scanf("%d%d",&n,&m);
	for (int i=1; i<n; i++) scanf("%d%d",&x,&y),addedge(x,y);
	for (int i=1; i<=m; i++) scanf("%d%d",&u[i],&v[i]),add(i);
	Ans=0,cnt=m,dfs(1,0);
	for (int i=cnt; i; i--) if (fa[i]) ans[i]=ans[fa[i]]^fv[i];
	printf("%d\n",Ans);
	for (int i=1; i<=m; i++) if (ans[i]) printf("%d %d\n",v[i],u[i]); else printf("%d %d\n",u[i],v[i]);
	return 0;
}

Measured memory_bytes: 49140
/*
 * written by Yaqi Zhang (zhang623@wisc.edu)
 * University of Wisconsin-Madison
 * 2020
 */
#include <bits/stdc++.h>

#define INF 0x3f3f3f3f

using namespace std;


int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n, k;
    cin >> n >> k;
    string s;
    cin >> s;
    --k;
    s[k] = tolower(s[k]);
    cout << s << endl;
    return 0;
    
}



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

#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define RFOR(i, a, b) for (int i = (b)-1; i >= (a); i--)
#define rep(i, n) for (int i = 0; i < (n); i++)
#define rep1(i, n) for (int i = 1; i <= (n); i++)
#define rrep(i, n) for (int i = (n)-1; i >= 0; i--)

#define pb push_back
#define mp make_pair
#define fst first
#define snd second
#define show(x) cout << #x << " = " << x << endl
#define chmin(x, y) x = min(x, y)
#define chmax(x, y) x = max(x, y)
#define pii pair<int, int>
#define vi vector<int>

using namespace std;
template <class S, class T>
ostream& operator<<(ostream& o, const pair<S, T>& p)
{
    return o << "(" << p.first << "," << p.second << ")";
}
template <class T>
ostream& operator<<(ostream& o, const vector<T>& vc)
{
    o << "sz = " << vc.size() << endl
      << "[";
    for (const T& v : vc)
        o << v << ",";
    o << "]";
    return o;
}
using ll = long long;
constexpr ll MOD = 1000000007;

constexpr int MAX = 200000;

int node[MAX];
bool check[MAX];
vector<int> edge[MAX];
int tree[MAX];

int dfs(const int s)
{
    check[s] = true;
    int b = 0;
    for (const int to : edge[s]) {
        if (not check[to]) {
            const int col = dfs(to);
            if (col == -1) {
                b++;
            }
            if (col == -100) {
                return -100;
            }
            if (b > 1) {
                return -100;
            }
        }
    }
    if (b == 0) {
        return -1;
    } else if (b == 1) {
        return 1;
    }
}

int main()
{
    int N, M;
    cin >> N;
    M = N - 1;

    rep(i, M)
    {
        int a, b;
        cin >> a >> b;
        a--;
        b--;
        node[a]++;
        node[b]++;
        edge[a].pb(b);
        edge[b].pb(a);
    }

    if (N % 2 == 1) {
        cout << "First" << endl;
        return 0;
    }

    if (dfs(0) != -100) {
        cout << "Second" << endl;
    } else {
        cout << "First" << endl;
    }

    return 0;
}


Measured memory_bytes: 8832
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
#define X first
#define Y second
#define pb push_back

void solve();

int main() {
    // freopen("schools.in", "r", stdin);
    // freopen("schools.out", "w", stdout);
	ios_base::sync_with_stdio(0), cin.tie(0);
	int t;
	// cin >> t;
	t = 1;	
	while(t--) solve();
	return 0;
}

ll n, k;

void solve() {
	cin >> n >> k;
	ll can = (n + 1) / 2;
	cout << (can >= k ? "YES\n" : "NO\n");
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <map>
#include <set>
#include <vector>
#include <cmath>
#include <algorithm>

using namespace std;
typedef long long ll;
ll dp[402][402];
ll cost[402][402];

int main() {
	int n; cin >> n;
	vector<int> nums(n);
	for (auto &x : nums) { cin >> x; }
	for (int i = 0; i < n; i++) {
		for (int j = 0; j < n; j++) {
			dp[i][j] = 1e15;
			cost[i][j] = 1e15;
		}
		dp[i][i] = nums[i];
		cost[i][i] = 0;
	}

	for (int i = n-1; i >= 0; i--)
		for (int j = i + 1; j < n; j++)
			for (int k = i; k < j; k++) {
				ll newCost = cost[i][k] + cost[k + 1][j] + dp[i][k] + dp[k + 1][j];
				if (newCost < cost[i][j]) {
					dp[i][j] = dp[i][k] + dp[k + 1][j];
					cost[i][j] = newCost;
				}
			}

	cout << cost[0][n - 1] << endl;
}

Measured memory_bytes: 2816
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <string>
#include <vector>
#include <queue>
#include <map>
#include <set>
#include <functional>
#include <cmath>
#include <complex>
#include <cctype>
#include <cassert>

using namespace std;

#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REP(i,n) FOR(i,0,n)
#define ALL(v) (v).begin(),(v).end()

#define INF (1<<29)
#define INFL (1ll<<60)
#define EPS (1e-8)
#define PI (acos(-1))
#define MOD 1000000007ll

template<class A, class B> inline bool chmax(A &a, B b) { if (a<b) { a=b; return 1; } return 0; }
template<class A, class B> inline bool chmin(A &a, B b) { if (a>b) { a=b; return 1; } return 0; }

typedef long long ll;
typedef complex<double> P;
typedef complex<double> Vec;
typedef pair<int, int> pii;
typedef pair<int, pii> p;

int n;
vector<int> g[100000];

int dfs(int pos) {
	if (g[pos].size() == 0) return 0;
	
	vector<int> v;
	REP(i, g[pos].size()) v.push_back(dfs(g[pos][i]));
	sort(ALL(v), greater<int>());
	
	int res = 0;
	REP(i, v.size()) chmax(res, v[i] + i + 1);
	return res;
}

int main() {
	cin >> n;
	FOR(i, 1, n) {
		int a;
		scanf("%d", &a);
		a--;
		g[a].push_back(i);
	}
	
	cout << dfs(0) << endl;
	
	return 0;
}

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

const int sqrtN = 512;

struct SqrtDecomposition {
    int N, K;
    vector<int> data;
    vector<bool> lazyFlag;
    vector<int> lazyUpdate;

    explicit SqrtDecomposition(const vector<int> &v) : N(v.size()) {
        K = (N + sqrtN - 1) / sqrtN;
        data.assign(K * sqrtN, 0);
        for (int i = 0; i < v.size(); ++i) {
            data[i] = v[i];
        }
        lazyFlag.assign(K, false);
        lazyUpdate.assign(K, 0);
    }

    // [s, t) = x
    void update(int s, int t, int x) {
        for (int k = 0; k < K; ++k) {
            int l = k * sqrtN, r = (k + 1) * sqrtN;
            if (r <= s || t <= l) {
                continue;
            }
            if (s <= l && r <= t) {
                lazyFlag[k] = true;
                lazyUpdate[k] = x;
            } else {
                eval(k);
                for (int i = max(s, l); i < min(t, r); ++i) {
                    data[i] = x;
                }
            }
        }
    }

    int find(int i) {
        int k = i / sqrtN;
        eval(k);
        return data[i];
    }

private:
    void eval(int k) {
        if (lazyFlag[k]) {
            lazyFlag[k] = false;
            for (int i = k * sqrtN; i < (k + 1) * sqrtN; ++i) {
                data[i] = lazyUpdate[k];
            }
        }
    }

};

int main() {
    ios::sync_with_stdio(false);
    int N, Q;
    cin >> N >> Q;
    vector<int> v(N, (1LL << 31) - 1);
    SqrtDecomposition sd(v);
    while (Q--) {
        int c;
        cin >> c;
        if (c == 0) {
            int s, t, x;
            cin >> s >> t >> x;
            sd.update(s, t + 1, x);
        } else {
            int i;
            cin >> i;
            cout << sd.find(i) << endl;
        }
    }

    return 0;
}


Measured memory_bytes: 3616
#include <iostream>
#include <string>
#define MAX_H 400
#define MAX_W 400
using namespace std;

int parent[MAX_H * MAX_W];
int depth[MAX_H * MAX_W];
long black[MAX_H * MAX_W];
long white[MAX_H * MAX_W];

void init(int h, int w) {
    for (int i = 0; i < h; i++) {
        for (int j = 0; j < w; j++) {
            parent[w * i + j] = w * i + j;
            depth[w * i + j] = 1;
            black[w * i + j] = white[w * i + j] = 0;
        }
    }
}

int find(int p0) {
    if (parent[p0] == p0) {
        return p0;
    }
    return parent[p0] = find(parent[p0]);
}

void unite(int p0, int p1) {
    int parent0 = find(p0);
    int parent1 = find(p1);
    if (parent0 == parent1)
        return;

    if (depth[parent0] < depth[parent1]) {
        parent[parent1] = parent0;
    } else {
        parent[parent0] = parent1;
        if (depth[parent0] == depth[parent1])
            depth[parent1]++;
    }
}

int main() {
    int h, w;
    cin >> h >> w;
    string s[h];
    for (int i = 0; i < h; i++) {
        cin >> s[i];
    }

    init(h, w);

    for (int j = 1; j < w; j++) {
        if (s[0][j - 1] != s[0][j])
            unite(j, j - 1);
    }
    for (int i = 1; i < h; i++) {
        if (s[i - 1][0] != s[i][0])
            unite(w * i, w * i - w);
        for (int j = 1; j < w; j++) {
            if (s[i][j - 1] != s[i][j]) {
                unite(w * i + j, w * i + j - 1);
            }
            if (s[i - 1][j] != s[i][j]) {
                unite(w * i + j, w * i + j - w);
            }
        }
    }

    for (int i = 0; i < h; i++) {
        for (int j = 0; j < w; j++) {
            int pa = find(w * i + j);
            if (s[i][j] == '#')
                black[pa]++;
            else
                white[pa]++;
        }
    }

    long ans = 0;
    for (int i = 0; i < h; i++) {
        for (int j = 0; j < w; j++) {
            ans += black[w * i + j] * white[w * i + j];
        }
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 4224
h, w = list(map(int, input().split()))  
power = [list(map(int, input().split())) for i in range(10)]  

for i in range(10):
    for j in range(10):
        for k in range(10):
            power[j][k] = min(power[j][i] + power[i][k], power[j][k])  

ans = 0
for i in range(h):
    wall = list(map(int, input().split()))  
    for item in wall:
        if item < 0:
            continue
        ans += power[item][1]  
print(ans)

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

const string st = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ";

int main() {
  for (int n; cin >> n, n;) {
    vector<int> k(n);
    REP(i, n) cin >> k[i];
    string s;
    cin >> s;
    string ans;
    REP(i, s.length()) {
      int p;
      REP(j, 52) {
        if (st[j] == s[i]) p = j;
      }
      ans += st[(p - k[i % n] + 52) % 52];
    }
    cout << ans << endl;
  }
}



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

int main(){
    string s;
    cin>>s;
    ll cnt=0;
    int sz=s.size();
    int numa1=0;//iまでに連なるaの数
    int numa2=0;//iがbのとき前に連なるaの数
    for(int i=0; i<sz; i++){
        //最後がbのときcがきたらnuma2を足す
        if(s[i]=='A'){
            numa1++;
            numa2=0;
        }
        else if(s[i]=='B'){
            numa2=numa1;
            numa1=0;
        }
        else{
            numa1=numa2;
            cnt+=numa2;
            numa2=0;
            if(i>0&&s[i-1]!='B')numa1=0;
        }
    }
    cout<<cnt;
    return 0;
}

Measured memory_bytes: 640
n = list(input())
l = len(n)

for i in range(l):
    n[i] = int(n[i])

score = 0

if l == 1:
    print(n[0])
else:
    if n.count(9) == l:
        score = sum(n)
    elif n.count(9) == l-1:
        if n[0] != 9:
            score += sum(n)
        else:
            score += 8 + 9*(l-1)
    else:
        if n[0] != 9:
            score += n[0]-1 + 9*(l-1)
        else:
            for j in range(l):
                if n[j] != 9:
                    n[j-1] = 8
                    score += 8 + 9*(l-1)
                    break
    print(score)

Measured memory_bytes: 9092
#include <iostream>
#include <string>
#include <vector>
#include <deque>
#include <queue>
#include <algorithm>
#include <set>
#include <map>
#include <bitset>
#include <cmath>
#include <functional>

using namespace std;

#define REP(i,n) for(ll (i) = (0);(i) < (n);++i)
#define REV(i,n) for(ll (i) = (n) - 1;(i) >= 0;--i)
#define PB push_back
#define EB emplace_back
#define MP make_pair
#define FI first
#define SE second
#define SHOW1d(v,n) {REP(WW,n)cerr << v[WW] << ' ';cerr << endl << endl;}
#define SHOW2d(v,WW,HH) {REP(W_,WW){REP(H_,HH)cerr << v[W_][H_] << ' ';cerr << endl;}cerr << endl;}
#define ALL(v) v.begin(),v.end()
#define Decimal fixed<<setprecision(20)
#define INF 1000000000
#define LLINF 1000000000000000000LL
#define MOD 998244353

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

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

  ll a, b;cin >> a >> b;
  for(int num = 0;num < 1000000;num++){
    if(a != (int)(num * 0.08))continue;
    if(b != (int)(num * 0.10))continue;
    cout << num << endl;
    return 0;
  }

  cout << -1 << endl;

	return 0;
}


Measured memory_bytes: 256
"use strict";
const fs = require("fs");

const X = parseInt(fs.readFileSync("/dev/stdin", { encoding: "utf8" }));

function isPrime(n) {
  const m = Math.ceil(Math.sqrt(n));
  for (let i = 2; i < m; ++i) {
    if (n % i === 0) {
      return false;
    }
  }
  return true;
}

function main() {
  let i = X;
  while (true) {
    if (isPrime(i)) {
      return i;
    }
    i++;
  }
}

console.log(main());


Measured memory_bytes: 9548
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
typedef long long ll;
typedef pair<ll,ll> P;
typedef vector<ll> vec;
typedef vector<vec> mat;
int main(){
    deque<char> A;
    string s;
    cin>>s;
    rep(i,s.size()) A.push_back(s[i]);
    int q,a=0;
    cin>>q;
    rep(i,q){
        int t,f;
        char c;
        cin>>t;
        if(t==1) a=(a+1)%2;
        else{
            cin>>f>>c;
            if(a==0){
                if(f==1) A.push_front(c);
                else A.push_back(c);
            }
            else{
                if(f==2) A.push_front(c);
                else A.push_back(c);
            }
        }
    }
    if(a==1){
        reverse(A.begin(),A.end());
    }
    for(auto i:A) cout<<i;
}

Measured memory_bytes: 896
/**
*    created: 23.05.2020 00:35:58
**/
#include <bits/stdc++.h>
#define int long long
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep2(i, s, n) for (int i = (s); i < (int)(n); i++)
using namespace std;

signed main() {

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

    int n, m, c;
    cin >> n >> m >> c;
    vector<int> b(m);
    rep(i,m) cin >> b[i];
    vector<vector<int>> a(n,vector<int>(m));
    rep(i,n) rep(j,m) {
        cin >> a[i][j];
    }
    int cnt = 0;
    rep(i,n) {
        int sum = 0;
        rep(j,m) {
            sum += a[i][j] * b[j];
        }
        sum += c;
        if (sum > 0) cnt++;
    }
    cout << cnt << endl;
    return 0;
}

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

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

  int sheet[r+1][c+1] = {{0}};

  for (int i = 0; i < r; i++) {
    int rowTotal = 0;

    for (int j = 0; j < c; j++) {
      int v;
      cin >> v;
      sheet[i][j] = v;
      rowTotal += v;
    }

    sheet[i][c] = rowTotal;
  }

  for (int i = 0; i <= c; i++) {
    int columnTotal = 0;

    for (int j = 0; j < r; j++) {
      int v = sheet[j][i];
      columnTotal += v;
    }

    sheet[r][i] = columnTotal;
  }

  for (int i = 0; i <= r; i++) {
    for (int j = 0; j <= c; j++) {
      if (j != 0) cout << ' ';
      cout << sheet[i][j];
    }
    cout << endl;
  }

  return 0;
}



Measured memory_bytes: 3144
use proconio::input;

fn main() {
    input! {
        s: String,
    }

    solve(&s);
}

fn solve(s: &String) {
    let mut max_cnt = 0;
    let mut loc_cnt = 0;
    for c in s.chars() {
        if c == 'R' {
            loc_cnt += 1;
        } else {
            if loc_cnt > max_cnt {
                max_cnt = loc_cnt;
            }
            loc_cnt = 0;
        }
    }
    if loc_cnt > max_cnt {
        max_cnt = loc_cnt;
    }

    println!("{}", max_cnt);
}


Measured memory_bytes: 2132
#include<iostream>
#include<cmath>
#include<algorithm>
#include<string>
#include<vector>
#include<stack>
#include<queue>
#include<set>
#include<map>
#include<iomanip>
#include<bitset>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
typedef pair<ll,P> P1;
typedef pair<P,P> P2;
#define pu push
#define pb push_back
#define mp make_pair
#define eps 1e-7
#define INF 1000000000
#define fi first
#define sc second
#define rep(i,x) for(ll i=0;i<x;i++)
#define repn(i,x) for(ll i=1;i<=x;i++)
#define SORT(x) sort(x.begin(),x.end())
#define ERASE(x) x.erase(unique(x.begin(),x.end()),x.end())
#define POSL(x,v) (lower_bound(x.begin(),x.end(),v)-x.begin())
#define POSU(x,v) (upper_bound(x.begin(),x.end(),v)-x.begin())

const int MAX = 510000;
const int MOD = 1000000007;

int main(){
  ll N , K; cin >> N >> K;
  vector<ll> p(N); rep(i,N) cin >> p[i];

  SORT(p);
  ll ans = 0;
  rep(i,K){
    ans += p[i];
  }
  cout << ans << endl;
}


Measured memory_bytes: 3636
#include<bits/stdc++.h>
using namespace std;
using Int = long long;
template<typename T1,typename T2> inline void chmin(T1 &a,T2 b){if(a>b) a=b;}
template<typename T1,typename T2> inline void chmax(T1 &a,T2 b){if(a<b) a=b;}

//INSERT ABOVE HERE
signed main(){
  Int x;
  cin>>x;
  cout<<(4LL<<x)-2<<endl;
  return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<string>
using namespace std;
int main() {
	string  s;
	getline(cin, s);
	for (int i = 0; i < s.size(); i++) {
		if ('a' <= s[i] && s[i] <= 'z') s[i] += 'A' - 'a';
		else if ('A' <= s[i] && s[i] <= 'Z') s[i] += 'a' - 'A';
	}
	cout << s << endl;

}


Measured memory_bytes: 3168
import sys

N = int(input())
s = [int(input()) for _ in range(N)]
ss = sum(s)
s.sort()

if ss % 10 != 0:
    print(ss)
    sys.exit()

for p in s:
    if p % 10 != 0:
        print(ss - p)
        break
else:
    print(0)


Measured memory_bytes: 3060
h,w,a,b = map(int,input().split())
ans = [[0 for j in range(w)] for i in range(h)]
for i in range(h):
    for j in range(w):
        if i<b:
            if j>=a:
                ans[i][j] = 1
        else:
            if j<a:
                ans[i][j] = 1

for i in ans:
    print(''.join(map(str,i)))


Measured memory_bytes: 17612
PROGRAM-ID.                      ABC_104_D.
ENVIRONMENT                      DIVISION.
INPUT-OUTPUT                     SECTION.
FILE-CONTROL.
    SELECT SYSIN ASSIGN TO KEYBOARD ORGANIZATION LINE SEQUENTIAL.

DATA                             DIVISION.
FILE                             SECTION.
    FD  SYSIN.
        01 INDATA PIC X(100000).

WORKING-STORAGE                  SECTION.

    01 ABC     PIC X(3) VALUE "ABC".
    01 INF     PIC 9(10) VALUE 1000000007.
    01 S       PIC X(100000).
    01 dp1.
        03 dp11 OCCURS 100001.
            05 dp PIC 9(20) OCCURS 4.
    01 len     PIC 9(6).
    01 i       PIC 9(6) BINARY.
    01 j       PIC 9(1) BINARY.
    01 m1      PIC 9(1).
    01 m2      PIC 9(1).
    01 ans     PIC X(10).
    01 ZS      PIC Z(10)9.
    01 DUMMY   PIC X(1).

PROCEDURE                        DIVISION.

    OPEN INPUT SYSIN.

    READ SYSIN INTO S.

    CLOSE SYSIN.

    COMPUTE len = FUNCTION STORED-CHAR-LENGTH(S).

*> ○ 0
    MOVE ZERO TO dp(len + 1 1).
*> ○ 1
    MOVE ZERO TO dp(len + 1 2).
*> ○ 2
    MOVE ZERO TO dp(len + 1 3).
*> ○ 3
    MOVE 1 TO dp(len + 1 4).

    PERFORM VARYING i FROM len BY -1 UNTIL i <= ZERO
        PERFORM VARYING j FROM 4 BY -1 UNTIL j <= ZERO
*> ○ 3
            IF j = 4
                MOVE 1 TO m1
                IF '?' = S(i:1)
                    MOVE 3 TO m1
                END-IF
                COMPUTE dp(i j) = m1 * dp(i + 1 j)
*> ○ 3 以外
            ELSE
                MOVE 1 TO m2
*> ?
                IF S(i:1) = '?'
                    MOVE 3 TO m1
*> ? 以外
                ELSE
                    MOVE 1 TO m1
                    IF ABC(j:1) NOT = S(i:1)
                        MOVE ZERO TO m2
                    END-IF
                END-IF
                COMPUTE dp(i j) = m1 * dp(i + 1 j) + m2 * dp(i + 1 j + 1)
            END-IF
            COMPUTE dp(i j) = FUNCTION MOD(dp(i j), INF)
        END-PERFORM
    END-PERFORM.

    MOVE dp(1 1) TO ZS.

    PERFORM UNANS.

    DISPLAY ans(1:FUNCTION STORED-CHAR-LENGTH(ans)).
    STOP RUN.

UNANS                            SECTION.
    UNSTRING
        ZS DELIMITED BY ALL SPACE
        INTO DUMMY ans
    END-UNSTRING.


Measured memory_bytes: 8320
#include <cmath>
#include <cstdio>
#include <vector>
#include <iostream>
#include <algorithm>
#include <queue>
#include <string>
#include <set>
#include <map>
#define REP(i,n) for(ll i = 0; i < (ll)n; i++)
#define INF 1000000000000000
using namespace std;
typedef long long ll;
typedef double db;
typedef string str;

int main(){
  ll n;
  cin >> n;
  bool exist[n][100];
  fill(exist[0],exist[n],false);
  REP(i,n){
    ll h; cin >> h;
    REP(j,h) exist[i][j] = true;
  }
  ll ans = 0;
  REP(j,100){
    REP(i,n){
      if(exist[i][j]){
        if(i==0) ans++;
        else if(!exist[i-1][j]) ans++;
      }
    }
  }
  cout << ans << endl;
  return 0;
}


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

using namespace std;

struct St
{
  int b;
  int c;
};

bool cmp(const St &x, const St &y){
  return x.c > y.c;
}

int main()
{
  int n,m;
  map<int, int> mp;
  long long int a[100001];
  cin >> n >> m;
  vector<St> stvec(m);
  long long int sum = 0;
  for(int i = 0;i < n;i++){
    cin >> a[i];
  }
  sort(a,a+n);
  for(int i = 0;i < m;i++){
    cin >> stvec.at(i).b >> stvec.at(i).c;
  }
  std::sort(stvec.begin(), stvec.end(), cmp);

  int k = 0;
  int fl = 0;
  for(int i = 0;i < m;i++){
    if(fl == -1)break;
    int b = stvec.at(i).b;
    int c = stvec.at(i).c;
    for(int j = 0;j < b; j++){
      if(k == n){fl = -1; break;}
      else if(a[k] < c) {a[k] = c;k++;}
      else {fl = -1;break;}
    }

  }
  for(int i = 0;i < n;i++){
    sum = sum + a[i];
  }
  cout << sum << endl;
  return 0;
}

Measured memory_bytes: 1792
#include <bits/stdc++.h>
using namespace std;
#define boost ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0)
#define rando mt19937 rng(chrono::steady_clock::now().time_since_epoch().count())
#define fi first
#define se second
#define debug(x) cerr << " - " << #x << ": " << x << endl;
#define debugs(x, y) cerr << " - " << #x << ": " << x << " " << #y << ": " << y << endl;
#define debugii(x) cerr << " - " << #x << ": " << x.fi<<","<<x.se << endl;
#define sep() cerr << "--------------------" << endl;
#define all(x) (x).begin(),(x).end()
#define sz(x) (ll)x.size()
#define ll long long
#define ii pair<int,int>
#define v vector<int>
#define vii vector<ii>
#define vv vector<vector<int> >
#define mp make_pair
#define INF 1000000000
#define pb push_back
#define EPS 1e-9
const int MOD = 1000000007; // 998244353
int main(){
	boost;
	double n;
	cin>>n;
	int ans=0;
	for (double i = 1.0; i <= n; ++i)
		ans+=(((int)floor(log10(i))+1)&1);
	cout<<ans;
	return 0;
}
//long long
//array bounds
//special cases
//binary search

Measured memory_bytes: 384
def minesweep(s,h,w):
    
    List = [s[h-1][w-1]
            ,s[h-1][w]
            ,s[h-1][w+1]
            ,s[h][w-1]
            ,s[h][w+1]
            ,s[h+1][w-1]
            ,s[h+1][w]
            ,s[h+1][w+1]]
    
    count = 0
    
    for i in range(8):
        if List[i]=="#":
            count+=1
            
    print(count,end="")
    
H,W = map(int,input().split(" "))

s  = [""]*(H+2)
s[0] = "0"*(W+2)
for i in range(1,H+1):
    s[i]="0"+input()+"0"
s[-1]="0"*(W+2)

for i in range(1,H+1):
    for j in range(1,W+1):
        if s[i][j]=="#":
            print("#",end="")
        else:
            minesweep(s,i,j)
    print("\n",end="")

Measured memory_bytes: 3444
N, M, R = map(int, input().split())
r = list(map(int, input().split()))
d = [[float('inf')]*N for _ in range(N)]
for i in range(M): #ひとまず枝があるペアは枝の長さをセット
  a,b,t = map(int, input().split())
  d[a-1][b-1] = t
  d[b-1][a-1] = t

for i in range(N):
  d[i][i] = 0 #自身への最短経路は0
#三重ループ
for k in range(N):
  for i in range(N):
    for j in range(N):
      d[i][j] = min(d[i][j], d[i][k]+d[k][j])

from itertools import groupby, accumulate, product, permutations, combinations

ans = float('inf')
for p in permutations(r,R):
  cnt = 0
  for i in range(1,R):
    cnt += d[p[i-1]-1][p[i]-1]
  ans = min(ans,cnt)
print(ans)

Measured memory_bytes: 70760
use proconio::{input, fastout};
use proconio::marker::{Chars};
use proconio::marker::Usize1;
use std::cmp::*;

macro_rules! debug {
      ($($a:expr),*) => {
          eprintln!(concat!($(stringify!($a), " = {:?}, "),*), $($a),*);
    }
}

#[fastout]
fn main() {
    input!{
        n: usize,
        mut a: [usize;n],
    }

    let inf = 10_0000+5;
    let mut cnt: Vec<usize> = vec![0;inf];
    for i in 0..n {
        cnt[a[i]] += 1;
    }
    a.sort();
    debug!(cnt[99999]);
    debug!(a[a.len()-1]);
    let mut ans = 0;
    for i in a[0]+1..a[a.len()-1]+2 {
        let sum = cnt[i-1]+cnt[i]+cnt[i+1];
        debug!(sum);
        ans = max(ans,sum);
    }
    println!("{}", ans);
}


Measured memory_bytes: 4512
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/detail/standard_policies.hpp>
 
using namespace std;
using namespace __gnu_pbds;

typedef long long ll;
typedef long double ld;
#define int ll
#define pb push_back
#define pii pair<int,int>
#define ff first
#define ss second
const int MAX = 2005;
const int INF = 1e18;
typedef tree< int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;

int n, dp[MAX][MAX];
pii a[MAX];


int solve(int left, int right){
	if (left == right){
		return dp[left][right] = a[n].ff*abs(a[n].ss-left);
	}
	if (dp[left][right] != -1) return dp[left][right];

	int cur = left + n - right ;
	dp[left][right] = solve(left+1,right) + a[cur].ff*abs(a[cur].ss-left);
	dp[left][right] = max(dp[left][right], solve(left,right-1) + a[cur].ff*abs(a[cur].ss - right));
	return dp[left][right];
}

signed main(){

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



	cin>>n;
	for(int i=1;i<=n;i++){
		cin>>a[i].ff;
		a[i].ss = i;
	}
	memset(dp,-1,sizeof(dp));
	sort(a+1,a+n+1);
	reverse(a+1,a+n+1);


	cout<<solve(1,n);
	return 0;
}

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

int main(){
  int n, t;
  cin >> n >> t;
  vector<int>cost(n);
  vector<int>time(n);
  for (int i = 0; i < n; i++){
    cin >> cost.at(i) >> time.at(i);
  }
 
  int cc =cost.at(0);
  
  for (int i = 1; i < n ; i++){
    if (cost.at(i) < cc && time.at(i) <= t){
      cc = cost.at(i);
    }
  }
  sort(time.begin(), time.end());
  if (time.at(0) > t)
    cout << "TLE" << endl;

  else
  cout << cc << endl;
}


Measured memory_bytes: 256
def bubblesort(a, n):
	flag = 1
	count = 0
	while flag:
		flag = 0
		for j in range(n-1, 0, -1):
			if a[j] < a[j-1]:
				count += 1
				a[j], a[j-1] = a[j-1], a[j]
				flag = 1
	return count

def main():
	n = int(input())
	data = list(map(int, input().split()))

	c = bubblesort(data, n)
	print(*data)
	print(c)

if __name__ == "__main__":
	main()

Measured memory_bytes: 7796
#include <bits/stdc++.h>
#define for0(i, n) for(int i = 0; i < n; i++)
#define for1(i, n) for(int i = 1; i <= n; i++)
#define pb push_back
#define mp make_pair
#define all(v) v.begin(), v.end()
#define V vector<int>
#define VP vector<pair<int, int> >
#define FASTIO ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
using namespace std;
#ifdef _WIN32
#include <windows.h>
#define print(x) PRINT(x, #x)
template<typename T> inline const void PRINT(T VARIABLE, string NAME)
{
#ifndef ONLINE_JUDGE /// ONLINE_JUDGE IS DEFINED ON CODEFORCES
    HANDLE hConsole = GetStdHandle(STD_OUTPUT_HANDLE);
    SetConsoleTextAttribute(hConsole, 10);
    cerr << NAME << " = " << VARIABLE << '\n';
    SetConsoleTextAttribute(hConsole, 7);
#endif
}
#else
#define print(x) 0
#endif
struct pair_hash
{
    template<typename T1, typename T2>
    size_t operator () (const pair<T1, T2> &p) const
    {
        auto h1 = hash<T1> {}(p.first);
        auto h2 = hash<T2> {}(p.second);
        return h1 ^ h2;
    }
};
typedef long long ll;
typedef unsigned long long ull;
const ll INFLL = 2 * (ll)1e18 + 100;
const int INFINT = 2 * (int)1e9 + 100;
//ifstream fin(".in");
//ofstream fout(".out");
void die()
{
    cout << "NO";
    exit(0);
}
const int NMAX = 2 * 1e5 + 5;
const int MOD = 1e9 + 7; /// careful here (7 or 9, 66.. etc)
const double PI = atan(1) * 4;
const double EPS = 1e-12;

int n;
map<int, int> cnt;
int sol;

int main()
{
    FASTIO;
    cin >> n;
    for1(i, n)
    {
        int a;
        cin >> a;
        cnt[a]++; cnt[a + 1]++;
        cnt[a - 1]++;
    }
    for(int i = -1; i <= (int)1e5 + 1; i++)
        sol = max(sol, cnt[i]);
    cout << sol;

    return 0;
}


Measured memory_bytes: 4992