akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>

using namespace std;

const int MAXN = 21;
const int MOD = 1e9 + 7;

int dp[(1<<MAXN)];
bool k[MAXN][MAXN];

int main() {
    #ifdef BLAT
        freopen("input", "r", stdin);
    #endif

    int n;
    cin >> n;
    for(int i = 0; i < n; ++i) {
    	for(int j = 0; j < n; ++j) {
    		cin >> k[i][j];
    	}
    } 

    dp[0] = 1;
    for(int mask = 0; mask < (1<<n); ++mask) {
    	int boy = __builtin_popcount(mask);
    	for(int i = 0; i < n; ++i) {
    		if(!(mask&(1<<i)) && k[boy][i]) {
    			dp[mask|(1<<i)] += dp[mask];
    			if(dp[mask|(1<<i)] >= MOD) dp[mask|(1<<i)] -= MOD;
    		}
    	}
    }

    cout << dp[(1<<n) - 1] << '\n';
}   	

Measured memory_bytes: 8448
from collections import deque
import itertools
# K = 3
# a = [1,3,5,4,2]
# N = len(a)

N, K = map(int, input().split())
p = list(map(int, input().split()))

deq = deque()
min_val = [0] * (N - K + 1)
for i in range(N):
  while deq and p[deq[-1]] >= p[i]:
    deq.pop()
  deq.append(i)

  if i - K + 1 >= 0:
    min_val[i - K + 1] = p[deq[0]]
    if deq[0] == i - K + 1:
      deq.popleft()
#print(min_val)

deq = deque()
max_val = [0] * (N - K + 1)
for i in range(N):
  while deq and p[deq[-1]] <= p[i]:
    deq.pop()
  deq.append(i)

  if i - K + 1 >= 0:
    max_val[i - K + 1] = p[deq[0]]
    if deq[0] == i - K + 1:
      deq.popleft()
#print(max_val)

incr = [1 if x<y else 0 for x,y in zip(p, p[1:])]
incr_cum = [0] + list(itertools.accumulate(incr))
is_stable = [y-x==K-1 for x,y in zip(incr_cum,incr_cum[K-1:])]

cnt = 0
preL = -1
prerange_min = -2
sortMatchCnt = 0
for i in range(N - K + 1):
  range_min = min_val[i]
  range_max = max_val[i]
  l = p[i]
  r = p[i + K - 1]

  sortMatchFlg = False
  if is_stable[i]:
    sortMatchCnt += 1
    sortMatchFlg = True

  if (preL == prerange_min and r == range_max) or sortMatchFlg:
    pass
  else:
    cnt += 1
  preL = l
  # preR = r
  prerange_min = range_min
  # prerange_max = range_max
if sortMatchCnt >= 1:
  print(cnt + 1)
else:
  print(cnt)


Measured memory_bytes: 105936
#include<iostream>
#include<cstdio>
#include<cstring>
using namespace std;
int main(){
    char num[1001];
    while(1){
        scanf("%s", num);
        if(num[0] == '0') break;
        int sum = 0;
        for (int i = 0; num[i] != '\0'; i++){
            sum += num[i] - '0';
        }
        printf("%d\n",sum);
    }
    return 0;
}


Measured memory_bytes: 3172
require 'prime'
require 'set'
require 'tsort'
include Math
ALP = ('a'..'z').to_a
INF = 0xffffffffffffffff
def max(a,b);              a > b ? a : b                              end
def min(a,b);              a < b ?  a : b                             end
def swap(a,b);             a, b = b, a                                end
def gif;                   gets.to_i                                  end
def gff;                   gets.to_f                                  end
def gsf;                   gets.chomp                                 end
def gi;                    gets.split.map(&:to_i)                     end
def gf;                    gets.split.map(&:to_f)                     end
def gs;                    gets.chomp.split.map(&:to_s)               end
def gc;                    gets.chomp.split('')                       end
def pr(num);               num.prime_division                         end
def pr?(num);              Prime.prime?(num)                          end
def digit(num);            num.to_s.length                            end
def array(s,ini=nil);      Array.new(s){ini}                          end
def darray(s1,s2,ini=nil); Array.new(s1){Array.new(s2){ini}}          end
def rep(num);              num.times{|i|yield(i)}                     end
def repl(st,en,n=1);       st.step(en,n){|i|yield(i)}                 end

n=gif
a=gi
sum = 0
ts = []
a.each do |aa|
  while aa % 2 == 0
    sum += 1
    aa/=2
  end
end
puts sum


Measured memory_bytes: 2812
// inputに入力データ全体が入る
function Main(input) {
	// 1行目がinput[0], 2行目がinput[1], …に入る
	input = input.split("\n");
  tmp = input[0].split(" ");
  var AB = parseInt(tmp[0], 10)
  var BC = parseInt(tmp[1], 10)
  var CA = parseInt(tmp[2], 10)
	//出力
	console.log('%d',AB*BC/2);
}
//*この行以降は編集しないでください（標準入出力から一度に読み込み、Mainを呼び出します）
Main(require("fs").readFileSync("/dev/stdin", "utf8"));


Measured memory_bytes: 21956
def main():
    N = int(input())
    A = []
    for i in range(5):
        A.append(int(input()))
    A.sort()
    if(N > A[0]):
        if(N % A[0] != 0):
            cnt = N//A[0]+1
        else:
            cnt = N//A[0]
    else:
        cnt = 1    
    print(cnt+4)
main()

Measured memory_bytes: 3060
import java.util.Map.Entry;
import java.io.*;
import java.math.BigInteger;
import java.util.*;

public class Main {
	
	public static void main(String[] args) throws IOException {
		FastScanner sc = new FastScanner(System.in);
		
		int n = sc.nextInt();
		int m = sc.nextInt();
		int[] c = new int[m+1];
		for(int i = 1; i <= m; i++) c[i] = sc.nextInt();
		
		//dp[i][j]:i種類目まででj円払う最小枚数
		int[][] dp = new int[m+1][n+1];
		Arrays.fill(dp[0], Integer.MAX_VALUE);
		
		for(int i = 0; i < m; i++){
			for(int j = 0; j <= n; j++){
				if(j < c[i+1]){
					dp[i+1][j] = dp[i][j];
				}else if(j == c[i+1]){
					dp[i+1][j] = 1;
				}else{
					dp[i+1][j] = Math.min(dp[i][j], dp[i+1][j-c[i+1]] + 1);
				}
			}
		}
		
		System.out.println(dp[m][n]);
	}
}

class FastScanner {
    private InputStream in;
    private final byte[] buffer = new byte[1024];
    private int ptr = 0;
    private int buflen = 0;
    public FastScanner(InputStream in) {
		this.in = in;
	}
    private boolean hasNextByte() {
        if (ptr < buflen) {
            return true;
        }else{
            ptr = 0;
            try {
                buflen = in.read(buffer);
            } catch (IOException e) {
                e.printStackTrace();
            }
            if (buflen <= 0) {
                return false;
            }
        }
        return true;
    }
    private int readByte() {
    	if (hasNextByte()) return buffer[ptr++];
    	else return -1;
    }
    private static boolean isPrintableChar(int c){
    	return 33 <= c && c <= 126;
    }
    public boolean hasNext() {
    	while(hasNextByte() && !isPrintableChar(buffer[ptr]))
    		ptr++; return hasNextByte();
    }
    public String next() {
        if (!hasNext()) throw new NoSuchElementException();
        StringBuilder sb = new StringBuilder();
        int b = readByte();
        while(isPrintableChar(b)) {
            sb.appendCodePoint(b);
            b = readByte();
        }
        return sb.toString();
    }
    public long nextLong() {
        if (!hasNext()) throw new NoSuchElementException();
        long n = 0;
        boolean minus = false;
        int b = readByte();
        if (b == '-') {
            minus = true;
            b = readByte();
        }
        if (b < '0' || '9' < b) {
            throw new NumberFormatException();
        }
        while(true){
            if ('0' <= b && b <= '9') {
                n *= 10;
                n += b - '0';
            }else if(b == -1 || !isPrintableChar(b)){
                return minus ? -n : n;
            }else{
                throw new NumberFormatException();
            }
            b = readByte();
        }
    }
    public int nextInt() {
        long nl = nextLong();
        if (nl < Integer.MIN_VALUE || nl > Integer.MAX_VALUE) throw new NumberFormatException();
        return (int) nl;
    }
    public double nextDouble() {
    	return Double.parseDouble(next());
    }
}



Measured memory_bytes: 29260
#include <bits/stdc++.h>
#include <boost/multiprecision/cpp_int.hpp>
using namespace std;
typedef long long ll;
namespace mp = boost::multiprecision;
using Mint = mp::cpp_int;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define repi(i,a,b) for(int i = int(a); i < int(b); i++)
#define all(v) v.begin(), v.end()
#define uni(v) v.erase(unique(all(v)), v.end())
#define sort_g(v) sort(all(v), greater<int>())
#define dump(x) cerr << #x << ' ' << '=' << ' ' << x << endl

int main() {
    vector<int> N(3);
    rep(i, 3) cin >> N.at(i);
    int K;
    cin >> K;

    sort_g(N);
    cout << N.at(0) * pow(2, K) + N.at(1) + N.at(2) << endl;

}

Measured memory_bytes: 384
import java.util.*;

public class Main {
	public static void main (String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int m = sc.nextInt();
		int[] arr = new int[n];
		for (int i = 0; i < n; i++) {
			arr[i] = sc.nextInt();
		}
		Arrays.sort(arr);
		Change[] base = new Change[m];
		for (int i = 0; i < m; i++) {
			base[i] = new Change(sc.nextInt(), sc.nextInt());
		}
		Arrays.sort(base, new Comparator<Change>() {
		public int compare(Change c1, Change c2) {
			return c2.c - c1.c;
		}
		});
		int[] rel = new int[n];
		int idx = 0;
		for (int i = 0; idx < n && i < m; i++) {
			for (int j = 0; idx < n && j < base[i].b; j++) {
				rel[idx] = base[i].c;
				idx++;
			}
		}
		long total = 0;
		for (int i = 0; i < n; i++) {
			total += Math.max(arr[i], rel[i]);
		}
		System.out.print(total);
	}
	
	static class Change {
		int b;
		int c;
		public Change(int b, int c) {
			this.b = b;
			this.c = c;
		}
	}
}


Measured memory_bytes: 92700
import java.io.*;
import java.util.*;
 
public class Main {
    static final long MOD = 1000000007L;
    static final int INF = 50000000;
    static final int NINF = -50000000;
    public static void main(String[] args) {
        FastScanner sc = new FastScanner();
        PrintWriter pw = new PrintWriter(System.out);
        
        int N = sc.ni();
        long[] nums = new long[N];
        long sum = 0;
        for (int i = 0; i < N; i++) {
        	nums[i] = sc.nl();
        	sum += nums[i];
        }
        sum %= MOD;
        long ans = 0;
        for (int i = 0; i < N; i++) {
        	ans += nums[i]*(sum-nums[i]+MOD);
        	ans %= MOD;
        }
        pw.println((ans*500000004L)%MOD);
        pw.close();
    }
 
    static class FastScanner {
        BufferedReader br;
        StringTokenizer st;
 
        public FastScanner() {
            br = new BufferedReader(new InputStreamReader(System.in));
        }
 
        String next() {
            while (st == null || !st.hasMoreElements()) {
                try {
                    st = new StringTokenizer(br.readLine());
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
            return st.nextToken();
        }
 
        int ni() {
            return Integer.parseInt(next());
        }
 
        long nl() {
            return Long.parseLong(next());
        }
 
        double nd() {
            return Double.parseDouble(next());
        }
 
        String nextLine() {
            String str = "";
            try {
                str = br.readLine();
            } catch (IOException e) {
                e.printStackTrace();
            }
            return str;
        }
    }
}

Measured memory_bytes: 56404
#include<iostream>
#include<algorithm>
#include<cstring>

using namespace std;

const int N=2e5+10;

int p[N],se[N],ans;
int n,m;

int find(int x)
{
    if(p[x]!=x) p[x]=find(p[x]);
    return p[x];
}

int main()
{
    cin>>n>>m;
    for(int i=1;i<=n;i++) p[i]=i,se[i]=1;
    for(int i=0;i<m;i++)
    {
        int a,b;
        scanf("%d%d",&a,&b);
        a=find(a),b=find(b);
        if(a!=b) p[b]=a,se[a]+=se[b];
    }
    for(int i=1;i<=n;i++) ans=max(ans,se[i]);
    cout<< ans <<endl;
    return 0;
}

Measured memory_bytes: 5320
def main(data: list):
    [price, numbers] = data
    numbers_set = set(numbers)
    while True:
        unique_price_numbers = set(map(int, list(str(price))))
        common_numbers = numbers_set.intersection(unique_price_numbers)
        if len(common_numbers) == 0:
            print(price)
            break
        price += 1


[N, K] = list(map(int, input().split()))
numbers = [int(v) for v in input().split()]
main([N, numbers])


Measured memory_bytes: 3060
T = [int(input()) for _ in range(5)]

lst1 = []
lst2 = []
for i in range(5):
    if T[i]%10 == 0:
        lst1.append([0,T[i]])
    else:
        lst2.append([T[i]%10,T[i]])

lst2 = sorted(lst2, reverse=True)
lst = lst1 + lst2

ans = 0
for i in range(5):
    ans += lst[i][1]
    if lst[i][0] == 0:
        pass
    else:
        ans += 10 - lst[i][0]

if lst[i][0] == 0:
    pass
else:
    ans -= 10 - lst[i][0]

print(ans)


Measured memory_bytes: 9104
#include<bits/stdc++.h>
using namespace std;
 
int main(){
	int n;cin>>n;
   string s; cin>>s;
   int ans = 1;
   for(int i = 1; i < n; i++){
         if(s[i]!=s[i-1]) ans++;
   }
  cout<<ans;
}

Measured memory_bytes: 512
// https://qiita.com/tanakh/items/0ba42c7ca36cd29d0ac8
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
    ($($r:tt)*) => {
        let s = {
            use std::io::Read;
            let mut s = String::new();
            std::io::stdin().read_to_string(&mut s).unwrap();
            s
        };
        let mut iter = s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
}

macro_rules! input_inner {
    ($iter:expr) => {};
    ($iter:expr, ) => {};

    ($iter:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($iter, $t);
        input_inner!{$iter $($r)*}
    };
}

macro_rules! read_value {
    ($iter:expr, ( $($t:tt),* )) => {
        ( $(read_value!($iter, $t)),* )
    };

    ($iter:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($iter, $t)).collect::<Vec<_>>()
    };

    ($iter:expr, chars) => {
        read_value!($iter, String).chars().collect::<Vec<char>>()
    };

    ($iter:expr, usize1) => {
        read_value!($iter, usize) - 1
    };

    ($iter:expr, $t:ty) => {
        $iter.next().unwrap().parse::<$t>().expect("Parse error")
    };
}

fn main() {
    input! {
        k: usize,
        x: usize,
    }
    println!("{}", if 500 * k >= x { "Yes" } else { "No" });
}


Measured memory_bytes: 4352
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
//template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
//template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
 
/* attention
    long longのシフト演算には気をつけよう
    タイポした時のデバッグが死ぬほどきつくなるので変数名は最低3字くらい使った方がいいかも
    sizeは(int)とキャストしよう
    ごちゃごちゃ場合分けを考える前に全探索は考えましたか？
*/

bool binarySerch(vector<int> s, int key){
    int left = 0, right = s.size()-1;
    int mid;
    while(right-left > 1){
        mid = (left+right)/2;
        if(s[mid] >= key) right = mid;
        else left = mid;
    }

    return s[right] == key;
}

int main(){
    int N; cin >> N;
    vector<int> s(N+2);
    for(int i=1; i<=N; i++) cin >> s[i];
    s[0] = -1; s[N+1] = 1000000005;
    
    int q; cin >> q;
    vector<int> t(q);
    for(int i=0; i<q; i++) cin >> t[i];

    int ans = 0;
    for(int i=0; i<q; i++) if(binarySerch(s, t[i])) ans++;
    cout << ans << endl;
}


Measured memory_bytes: 3868
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
constexpr int Inf = 1000000000;
constexpr ll INF= 1e18;
constexpr ll MOD = 1000000007;
const double PI = 3.1415926535897;
typedef pair<int,int> P;

ll fac[1000010], finv[1000010], inv[1000010];

// テーブルを作る前処理
void COMinit()
{
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < 1000010; i++)
    {
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD % i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}

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

int main() {
    int H,W,A,B;
    cin >> H >> W >> A >> B;
    COMinit();
    ll ret = 0;
    for(int i = 0;i < H - A;i++) {
        ret += COM(B - 1 + i,i) * COM(W - B - 1 + H - 1 - i,H - 1 - i);
        ret %= MOD;
    }
    cout << ret << endl;
}

Measured memory_bytes: 23680
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <cmath>
#include <set>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
const int mod = 1000000007;

int p[100005];

int root(int x) {return p[x] < 0 ? x : p[x] = root(p[x]);}

void mer(int x, int y) {
    if ((x = root(x)) == (y = root(y))) return;
    if (p[x] > p[y]) swap(x, y);
    p[x] += p[y];
    p[y] = x;
}

int main() {
    ios::sync_with_stdio(false);
    int n, x[100005] = {}, y[100005] = {}, c[100005] = {};
    ll z = 0;
    vector<int> g[100005] = {}, h[100005] = {};
    for (int i = 1; i <= 100000; i++) p[i] = -1;
    cin >> n;
    for (int i = 1; i <= n; i++) cin >> x[i] >> y[i], g[x[i]].push_back(y[i]), h[y[i]].push_back(x[i]);
    for (int i = 1; i <= 100000; i++) for (int j = 1; j < g[i].size(); j++) mer(g[i][j - 1], g[i][j]);
    set<int> s[100005] = {};
    for (int i = 1; i <= 100000; i++) {
        int r = root(i);
        c[r]++;
        for (int j : h[i]) s[r].insert(j);
    }
    for (int i = 1; i <= 100000; i++) z += 1ll * c[i] * s[i].size();
    cout << z - n;
}


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

using namespace std;

#define REP(i, n) for(int i = 0; i < (n); i++)
#define SREP(i, s) for(int i = 0; i < (s.length()); i++)
#define SORT(v, n) sort(v, v+n);
#define GSORT(v, n) sort(v, v+n, greater<int>())
#define REV(a) reverse(begin(a),end(a));

int main(){
	ios::sync_with_stdio(false);cin.tie(0);
//////////////////////////////////////////////
	char a,b;
	int c = 0;
	cin >> a >> b;
	if(a=='H') c++;
	if(b=='H') c++;
	cout << (c%2==0 ? 'H' : 'D') << endl;

	
//////////////////////////////////////////////
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int ans,m,a,c,n,sa,sc,scc;

int main(){
    cin >> m;
    for(int i=0;i<m;i++){
        cin >> c >> a >> n;

        for(int i=0;i<=c/3;i++){
            sc=c-3*i;
            for(int j=0;j<=min(sc/2,a);j++){
                scc=sc-j*2;
                sa=a-j;
                for(int k=0;k<=min(scc,min(sa,n));k++){
                    ans=max(ans,i+j+k);
                }
            }
        }



        cout << ans << endl;
        c=0,a=0,n=0,ans=0;
    }

return 0;
}

Measured memory_bytes: 1160
#include <bits/stdc++.h>
using namespace std;
int main(){
  int N;
  cin>>N;
  for(int i=0;i<900;i++){
    if(N%111==0){
      cout<<N<<endl;
      break;
    }
    else{
      N++;
    }
  }
  return 0;
}


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

#include <iostream>
#include <fstream>

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

#define int long long
#define pb push_back
#define mp make_pair

const int MOD = 1000000007;

class DKnapsack1 {
public:
    void solve(std::istream& in, std::ostream& out) {
        int n,c;
        in>>n>>c;
        int wt[n], v[n];
        for(int i=0;i<n;i++)
            in>>wt[i]>>v[i];

        int dp[n+1][c+1];

        for(int i=0;i<=n;i++)
        {
            for(int w=0;w<=c;w++)
            {
                if(i==0||w==0)
                    dp[i][w]=0;
                else if(wt[i-1]<=w)
                    dp[i][w]= max(v[i-1]+dp[i-1][w-wt[i-1]], dp[i-1][w]);
                else
                    dp[i][w]=dp[i-1][w];
            }
        }

        out<<dp[n][c];
    }
};

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

    DKnapsack1 solver;
    std::istream& in(std::cin);
    std::ostream& out(std::cout);
    solver.solve(in, out);
    return 0;
}

Measured memory_bytes: 79104
package main

import (
	"fmt"
)

const MOD = 1000000007

func ModAdd(a, b int64) int64 {
	return (a + b) % MOD
}

func ModMul(a, b int64) int64 {
	return a * b % MOD
}

func ModSub(a, b int64) int64 {
	r := (a%MOD - b%MOD) % MOD
	if r < 0 {
		r += MOD
	}
	return r
}

func ModDiv(a, b int64) int64 {
	return a % MOD * ModInv(b) % MOD
}

func ModPow(a, n int64) int64 {
	var r int64 = 1
	for n > 0 {
		if n&1 == 1 {
			r = r * a % MOD
		}
		a = a * a % MOD
		n >>= 1
	}
	return r
}

func ModInv(a int64) int64 {
	var b, u, v int64 = MOD, 1, 0
	for b > 0 {
		t := a / b
		a -= t * b
		a, b = b, a
		u -= t * v
		u, v = v, u
	}
	u %= MOD
	if u < 0 {
		u += MOD
	}
	return u
}

type Q struct {
	idx, value int
	a, b       int
	index      int
}

type QS []*Q

func (p QS) Len() int           { return len(p) }
func (p QS) Less(i, j int) bool { return p[i].value > p[j].value }
func (pq QS) Swap(i, j int) {
	pq[i], pq[j] = pq[j], pq[i]
	pq[i].index = i
	pq[j].index = j
}

func (pq *QS) Push(x interface{}) {
	n := len(*pq)
	item := x.(*Q)
	item.index = n
	*pq = append(*pq, item)
}

func (pq *QS) Pop() interface{} {
	old := *pq
	n := len(old)
	item := old[n-1]
	old[n-1] = nil  // avoid memory leak
	item.index = -1 // for safety
	*pq = old[0 : n-1]
	return item
}

func main() {
	var N, D int
	fmt.Scanf("%d %d\n", &N, &D)
	r := 2*D + 1
	cnt := 0
	for N > 0 {
		cnt++
		N -= r
	}
	fmt.Println(cnt)
}

func Reverse(runes []rune) []rune {
	for i, j := 0, len(runes)-1; i < j; i, j = i+1, j-1 {
		runes[i], runes[j] = runes[j], runes[i]
	}
	return runes
}


Measured memory_bytes: 512
package main

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

var sc = bufio.NewScanner(os.Stdin)

func nextLine() string {
	sc.Scan()
	return sc.Text()
}

func main() {
	var N int
	var A, B [101]int
	fmt.Scanf("%d", &N)

	line := nextLine()
	cols := strings.Split(line, " ")
	for i := 1; i < N; i++ {
		B[i], _ = strconv.Atoi(cols[i-1])
	}

	for i := 1; i <= N; i++ {
		if i == 1 {
			A[i] = B[i]
		} else if i == N {
			A[i] = B[i-1]
		} else if B[i-1] <= B[i] {
			A[i] = B[i-1]
		} else {
			A[i] = B[i]
		}
	}

	ans := 0
	for i := 1; i <= N; i++ {
		ans += A[i]
	}
	fmt.Printf("%d", ans)
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
#define rep(i, n) for(long long int i = 0; i < n; i++)
#define _rep(i, m, n) for(long long int i = m; i < n; i++)
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
const int N = 1000000;
const ll mod = 1000000007;
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};

ll gcd(ll A, ll B){
    if(B == 0)return A;
    return gcd(B, A % B);
}
ll lcm(ll A, ll B){
    return A * B / gcd(A, B);
}

/*------------------------------------------------------------------*/


int main(){
    string s; cin >> s;
    bool flag = true;
    if(s[0] != 'A') flag = false;
    int count = 0;
    _rep(i, 2, s.size() - 1){
        if(s[i] == 'C') count++;
    }
    if(count != 1) flag = false;
    int cou = 0;
    rep(i, s.size()){
        if(isupper(s[i])) cou++;
    }
    if(cou != 2) flag = false;
    if(flag) cout << "AC" << endl;
    else cout << "WA" << endl;
}

Measured memory_bytes: 256
import Control.Applicative ((<$>), (<*>))
import Control.Monad
import Data.List
import Data.List.Split (splitOn)

main :: IO ()
main = do
  xs <- getc $ map toDbl . splitOn ","
  mapM_ (putStrLn . unwords . map show) $ solve xs

solve :: [[Double]] -> [[Double]]
solve = map sympoint

sympoint :: [Double] -> [Double]
sympoint [x1,y1,x2,y2,xq,yq] = [xop pr, yop pr]
  where
    p1 = Point x1 y1
    p2 = Point x2 y2
    pq = Point xq yq
    pr = toPoint p1 vr
    va = toVect p1 p2
    vb = toVect p1 pq
    vr = addV vb vqr
    vqr = mulV 2 (subV (mulV (dot va vb / norm va) va) vb)
    
toDbl :: String -> Double
toDbl s = read s

getc :: (String -> a) -> IO [a]
getc f = map f . lines <$> getContents

data Point = Point {xop :: Double, yop :: Double} deriving Show
data Vect = Vect {xov :: Double, yov :: Double} deriving Show
 
dot :: Vect -> Vect -> Double
dot v1 v2 = xov v1 * xov v2 + yov v1 * yov v2

norm :: Vect -> Double
norm v = (xov v) ^ 2 + (yov v) ^ 2

addV :: Vect -> Vect -> Vect
addV v1 v2 = Vect (xov v1 + xov v2) (yov v1 + yov v2)

subV :: Vect -> Vect -> Vect
subV v1 v2 = Vect (xov v1 - xov v2) (yov v1 - yov v2)

mulV :: Double -> Vect -> Vect
mulV k v = Vect (k * xov v) (k * yov v)

toVect :: Point -> Point -> Vect
toVect p1 p2 = Vect (xop p2 - xop p1) (yop p2 - yop p1)

toPoint :: Point -> Vect -> Point
toPoint p v = Point (xop p + xov v) (yop p + yov v)

Measured memory_bytes: 4376
#include<iostream>
#include<string>
#include<cmath>
#include<queue>
#include<map>
#include<set>
#include<list>
#include<iomanip>
#include<vector>
#include<random>
#include<functional>
#include<algorithm>
#include<cstdio>
#include<bitset>
#include<unordered_map>
using namespace std;
//---------------------------------------------------
//ライブラリゾーン！！！！
typedef long long ll;
typedef long double ld;
#define str string
#define rep(i,j) for(ll i=0;i<(long long)(j);i++)
#define all(a) (a).begin(),(a).end()
const ll Mod = 1000000007;
const ll gosenchou = 5000000000000000;
short gh[2][4] = { { 0,0,-1,1 },{ -1,1,0,0 } };
struct P {
	ll pos, cost;
};
bool operator<(P a, P b) { return a.cost < b.cost; }
bool operator>(P a, P b) { return a.cost > b.cost; }
struct B {//隣接リスト表現
	ll to, cost;
};
struct E {//辺の情報を入れる変数
	ll from, to, cost;
};
bool operator<(E a, E b) {
	return a.cost < b.cost;
}
struct H {
	ll x, y;
};
bool operator<(H a, H b) {
	if (a.x != b.x) return a.x < b.x;
	return a.y < b.y;
}
bool operator>(H a, H b) {
	if (a.x != b.x) return a.x > b.x;
	return a.y > b.y;
}
bool operator==(H a, H b) {
	return a.x == b.x&&a.y == b.y;
}
bool operator!=(H a, H b) {
	return a.x != b.x || a.y != b.y;
}
ll gcm(ll i, ll j) {//最大公約数
	if (i > j) swap(i, j);
	if (i == 0) return j;
	return gcm(j%i, i);
}
ld rad(H a, H b) {
	return sqrt(pow(a.x - b.x, 2.0) + pow(a.y - b.y, 2.0));
}//rad＝座標上の2点間の距離
ll ari(ll a, ll b, ll c) {
	return (a + b)*c / 2;
}//等差数列の和
ll fact(ll x, ll k, ll p) {//最大値、個数、あまり
	ll sum = 1;
	for (int i = 0; i < k; i++) {
		sum *= (x--);
		sum %= p;
	}
	return sum;
}//階乗(正）
ll mod_pow(ll x, ll n, ll p) {
	ll res = 1;
	while (n > 0) {
		if (n & 1) res = res*x%p;
		x = x*x%p;
		n >>= 1;
	}
	return res;
}//x^n%p
short ctos(char a) {
	return (int)(a - '0');
}
#define int long long
const long long Inf = 4523372036854775807;
const int inf = 15000000000;
//----------------------------------------------------
//++++++++++++++++++++++++++++++++++++++++++++++++++++
signed main() {
	int h, w;
	string a[50];
	cin >> h >> w;
	for (int i = 0; i < h; i++)
		cin >> a[i];
	for (int i = 0; i < h; i++) {
		for (int j = 0; j < w; j++) {
			if (a[i][j] == '.') continue;
			if (i > 0 && a[i - 1][j] == '#') continue;
			if (i < h - 1 && a[i + 1][j] == '#') continue;
			if (j > 0 && a[i][j - 1] == '#') continue;
			if (j < w - 1 && a[i][j + 1] == '#') continue;
			cout << "No\n";
			return 0;
		}
	}
	cout << "Yes\n";
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define inchar			getchar
#define outchar(x)		putchar(x)
#define ll long long 
#define int long long //
#define all(v) v.begin(), v.end()
#define SP outchar(' ')
#define trace(x) cerr<<#x<<": "<<x<<" "<<endl;
#define LN outchar('\n')
#define endl '\n'
using namespace std;

template<typename T> void inpos(T &x){x=0;register T c=inchar();while(((c<48)||(c>57))&&(c!='-'))c=inchar();bool neg=0; if(c=='-')neg=1;for(;c<48||c>57;c=inchar());for(;c>47&&c<58;c=inchar())x=(x<<3)+(x<<1)+(c&15);if(neg)x=-x;}
template<typename T> void outpos(T n){if(n<0){outchar('-');n*=-1;}char snum[65];int i=0;do{snum[i++]=n%10+'0';n/=10;}while(n);i=i-1;while(i>=0)outchar(snum[i--]);}
inline void instr(char *str){register char c=0;register int i=0;while(c<33)c=inchar();while(c!='\n'&&c!=' '&&c!=EOF){str[i]=c;c=inchar();++i;}str[i]='\0';}
typedef vector <int> vi;
typedef vector <vi> Graph;

void dfs(Graph & G, vector <bool> & visited , vi & answer, int src ) {

	int toFill = 0;
	for (auto elem : G[src]) {
		if(!visited[elem]) {
			visited[elem] = true;
			dfs(G, visited, answer,elem );
		}
		toFill = max(toFill, answer[elem]);
	}
	answer[src] = toFill +1;
}


int32_t main () {
	
	int n, m;
	cin >> n >>m;
	Graph G(n);
	int a , b;
	while (m--) {
		cin >> a >> b;
		a--;b--;
		G[a].push_back(b);
		// G[b].push_back(a);

	}
	vi answer (n,0);
	vector <bool> visited(n,false);
	for(int i = 0; i<n;i++){
		if(!visited[i]) {
			visited[i] = true;
			dfs(G,visited, answer, i);
		}
	}	
	cout << *max_element(all(answer))-1 <<endl;


	
}

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

int main(void) {
	int x, y, r, w, h;
	cin >> w >> h >> x >> y >> r;
	if(x >= r && x <= w - r && y >= r && y <= h - r) {
      cout << "Yes" << endl;
    }
    else cout << "No" << endl;
    return 0;
} 


Measured memory_bytes: 3092
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0; i<(int)(n); i++)

using namespace std;
using LL = long long;
using P = pair<int,int>;
const int kind=26;

int main(){
	int D;
	cin >> D;
	vector<int> c(kind);
	rep(i,kind) cin >> c[i];
	int c_sum=0;
	rep(i,kind) c_sum+=c[i];
	vector<vector<int>> s(D,vector<int>(kind));
	rep(i,D){
		rep(j,kind) cin >> s[i][j];
	}
	vector<int> t(D);
	rep(i,D) cin >> t[i];
	rep(i,D) t[i]--;
	int ans=0, day=1, dec=0;
	vector<int> last(kind);
	for(int d=1; d<=D; d++){
		int k=t[d-1];
		ans+=s[d-1][k];
		dec+=c_sum;
		ans-=dec;
		ans+=c[k]*(d-last[k]);
		dec-=c[k]*(d-last[k]);
		last[k]=d;
		cout << ans << endl;
	}

	return 0;
}

Measured memory_bytes: 3676
<?php


fscanf(STDIN, "%d",$N);
$map = fscanf(STDIN, str_repeat("%d", $N));
sort($map);
$list = array_fill(0, 13, 0);
$rand = [];
$const = [];
foreach($map as $value){
    if($value === 0){
        echo 0;
        exit;
    }
    $list[$value]++;
    if($list[$value] === 1 && $value != 12){
        $rand[$value] = $value;
    }elseif($list[$value] === 2){
        $const[] = $value;
        $const[] = 24 - $value;
        unset($rand[$value]);
    }elseif($list[$value] > 2){
        echo 0;
        exit;
    }elseif($value === 12){
        $const[] = $value;
    }
}
sort($rand);
if($list[12] > 1){
    echo 0;
    exit;
}
$ans = 0;
for($i=0;$i<2**11;$i++){
    $tmp = [];
    $tmp[] = 0;
    for($j=0;$j<count($rand);$j++){
        if(($i & $j) > 0){
            $tmp[] = 24 - $rand[$j];
        }else{
            $tmp[] = $rand[$j];
        }
    }
    foreach($const as $value){
        $tmp[] = $value;
    }
    $tmp[]=24;
    sort($tmp);
    $min = PHP_INT_MAX;
    for($j=1;$j<=$N;$j++){
        $min = min($min, ($tmp[$j] - $tmp[$j-1]), $tmp[$j+1] - $tmp[$j]);
    }
    $ans = max($ans, $min);
}
echo $ans;

Measured memory_bytes: 4728
#include <bits/stdc++.h>
//#include <boost/multiprecision/cpp_int.hpp>
//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/tree_policy.hpp>
#pragma GCC optimize("O3")
#define REP(i,n) for(int i=0;i<n;i++)
#define REPP(i,n) for(int i=1;i<=n;i++)
#define ALL(obj) (obj).begin(), (obj).end()
#define EPS (1e-9)
#define INF (1e17)
#define PI (acos(-1))
//const double PI = acos(-1);
//const double EPS = 1e-15;
//long long INF=(long long)1E17;
#define i_7 (long long)(1e9+7)
//#define i_7 998'244'353
long mod(long a){
    long long c=a%i_7;
    if(c>=0)return c;
    return c+i_7;
}
long long po(long a, long b){
    if(b==0){
        return 1;
    }
    
    long long z = po(a,b/2);
    z = mod(z*z);
    if(b%2!=0){
        z = mod(a*z);
    }
    return z;
}

bool prime_(int n){
  if(n==1){
    return false;
  }else if(n==2){
    return true;
  }else{
    for(int i=2;i<=std::sqrt(n);i++){
      if(n%i==0){
        return false;
      }
    }
    return true;
  }
}

long long gcd_(long long a, long long b){
  if(a<b){
    std::swap(a,b);
  }
  if(a%b==0){
    return b;
  }else{
    return gcd_(b,a%b);
  }
}
 
long long lcm_(long long x, long long y){
  return (x/gcd_(x,y))*y;
}

//using namespace std;
//using namespace boost::multiprecision;
//using namespace __gnu_pbds;

int main(){
  using namespace std;
  long long n, k;
  cin>>n>>k;
  vector<long long> h(n);
  REP(i,n){
    cin>>h[i];
  }
  sort(ALL(h), greater<long long>());
  if(n <= k){
    cout<<0<<endl;
    return 0;
  }
  long long ans = 0;
  for(long long i = k; i<n; i++){
    ans += h[i];
  }
  cout<<ans<<endl;
  return 0;
}



Measured memory_bytes: 1792
#include <stdio.h>
int i,n,q,a,v,f[1000000][2],ad[1000000];
void swap(int* x,int* y){int z; z=*x;*x=*y;*y=z;}
int check(int x,int y){
    if(y>=n)return 0;
    else if(f[y][1]>f[x][1] || (f[y][1]==f[x][1] && f[y][0]<f[x][0]))return 1;
    else return 2;
}
void inc(int x){
    int ppp=(x-1)/2;
    if(check(ppp,x)==1){
        swap(&ad[f[x][0]-1],&ad[f[ppp][0]-1]);
        swap(&f[x][0],&f[ppp][0]);
        swap(&f[x][1],&f[ppp][1]);
        if(ppp>0)inc((x-1)/2);
    }
}
void dec(int x){
    int lll=x*2+1,rrr=x*2+2,mmm;
    if(lll>n-1)return;
    else if(lll==n-1)mmm=lll;
    else if(check(lll,rrr)==1)mmm=rrr; else mmm=lll;
    if(check(x,mmm)==1){
        swap(&ad[f[x][0]-1],&ad[f[mmm][0]-1]);
        swap(&f[x][0],&f[mmm][0]);
        swap(&f[x][1],&f[mmm][1]);
        dec(mmm);
    }
}
int main(void){
    scanf("%d %d",&n,&q);
    for(i=n;i>0;i--){f[i-1][0]=i;f[i-1][1]=0;ad[i-1]=i-1;}
    for(;q>0;q--){
        scanf("%d %d",&a,&v);
        f[ad[a-1]][1]+=v;
        if(v>0 && ad[a-1]>0)inc(ad[a-1]);
        if(v<0)dec(ad[a-1]);
        printf("%d %d\n",f[0][0],f[0][1]);
    }
    return 0;
}

Measured memory_bytes: 12312
#include <stdio.h>
#include <math.h>
#include <stdlib.h>

int tetrahedral[200];
int tetrahedralOdd[200];
int map[1000000], oddmap[1000000];

void init()
{
	int i;
	for (i = 0; i < 200; i++)
	{
		tetrahedral[i] = ((i + 1) * (i + 2) * (i)) / 6;
	}
	for (i = 0; i < 1000000; i++)
	{
		map[i] = oddmap[i] = 1000000;
	}
	map[0] = oddmap[0] = 0;
	map[1] = oddmap[1] = 1;
	for (i = 2; i < 1000000; i++)
	{
		for (int j = 1; tetrahedral[j] <= i; j++)
		{
			if (map[i] > map[i - tetrahedral[j]] + 1)
				map[i] = map[i - tetrahedral[j]] + 1;
			if (tetrahedral[j] % 2 && oddmap[i] > oddmap[i - tetrahedral[j]] + 1)
				oddmap[i] = oddmap[i - tetrahedral[j]] + 1;
		}
	}
}

int main()
{
	init();
	for (int input, out1, out2; (scanf("%d", &input)) && input != 0; printf("%d %d\n", out1, out2))
	{
		out1 = map[input];
		out2 = oddmap[input];
	}
	return 0;
}


Measured memory_bytes: 9532
import sys
import os

ii = lambda: int(sys.stdin.buffer.readline().rstrip())
il = lambda: list(map(int, sys.stdin.buffer.readline().split()))
fl = lambda: list(map(float, sys.stdin.buffer.readline().split()))
iln = lambda n: [int(sys.stdin.buffer.readline().rstrip()) for _ in range(n)]

iss = lambda: sys.stdin.buffer.readline().decode().rstrip()
sl = lambda: list(map(str, sys.stdin.buffer.readline().decode().split()))
isn = lambda n: [sys.stdin.buffer.readline().decode().rstrip() for _ in range(n)]

MOD = 10 ** 9 + 7


def main():
    if os.getenv("LOCAL"):
        sys.stdin = open("input.txt", "r")

    S = list(iss())
    for n in range(ord('a'), ord('z') + 1):
        if chr(n) not in S:
            print(chr(n))
            exit()
    else:
        print('None')


if __name__ == '__main__':
    main()


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

using ll = long long;

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

template<typename T>
T lcm(T a, T b)
{
	return a * b / gcd(a, b);
}

template<typename T>
T ext_gcd(T a, T b, T& x, T& y)
{
	x = 1;
	y = 0;
	T x0 = 0, y0 = 1;
	while (b != 0)
	{
		T q = a / b;
		a -= q * b;
		swap(a, b);
		x -= q * x0;
		swap(x, x0);
		y -= q * y0;
		swap(y, y0);
	}
	return a;
}

template<typename T>
T inv_mod(T a, T mod)
{
	T t1, t2;
	ext_gcd(a, mod, t1, t2);
	t1 %= mod;
	if (t1 < 0)		t1 += mod;
	return t1;
}

template<typename T>
T combination_large(T n, T k, T mod)
{
	if (n < k || n < 0 || k < 0)	return 0;
	vector<T> inv(n + 1, 1), fact(n + 1, 1), fact_inv(n + 1, 1);
	for (T i = 2; i <= n; ++i)
	{
		inv[i] = mod - inv[mod % i] * (mod / i) % mod;
		fact[i] = (fact[i - 1] * i) % mod;
		fact_inv[i] = fact_inv[i - 1] * inv[i] % mod;
	}
	return fact[n] * (fact_inv[k] * fact_inv[n - k] % mod) % mod;
}

template<typename T>
T combination(T n, T k, T mod = 1)
{
	vector<vector<T>> table(n + 1, vector<T>(k + 1, 1));
	for (T i = 1; i <= n; ++i)
	{
		table[i][0] = 1;
		for (T j = 1; j <= n; ++j)
		{
			table[i][j] = (table[i - 1][j - 1] + table[i - 1][j]) % mod;
		}
	}
}


int main(int, char**)
{
	long long N;
	scanf("%lld",&N);
	long long K;
	scanf("%lld",&K);

	if (N >= K)
	{
		N = N % K;
		if (N < 0)	N += K;
	}
	bool changed = true;
	while (changed)
	{
		changed = false;
		ll tmp = abs(N - K);
		if (tmp < N)
		{
			changed = true;
			N = tmp;
		}
	}

	cout << N << endl;

	return 0;
}


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

int main() {
  int n,b,count; vector<int>a(110);
  cin >> n ;
  for (int i=0;i<n;i++){
  cin >> a.at(i);
  }
  for (int i=0;i<n-1;i++){
    for (int j=i+1;j<n;j++){
      b=a.at(i)*a.at(j);
    count+=b;
    }
  
  }
  cout << count << endl;
}

Measured memory_bytes: 256
def ii():return int(input())
def iim():return map(int,input().split())
def iil():return list(map(int,input().split()))
def ism():return map(str,input().split())
def isl():return list(map(str,input().split()))
ans = 0
n,k = iim()
L = sorted(iil(),reverse=True)
for i in range(k):
    ans += L[i]

print(ans)

Measured memory_bytes: 3064
open System


[<EntryPoint>]
let main argv =
    let N =stdin.ReadLine()|>int
    let rec div n i = if i=0 then 0 else ((div n (i-1))+(if (n%i)=0 then 1 else 0))
    [for i in [1..N] do yield (if (div i i = 8)&&((i%2)<>0) then 1 else 0)]
    |>List.sum
    |>stdout.WriteLine
    0

Measured memory_bytes: 11348
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int A,B,C;
  cin>>A>>B>>C;
  
  int D =0;
  if (A+B<B+C) {
    D=A+B;
  }
  else {
    D=B+C;
  }
  if (D<A+C) {
    cout<<D<<endl;
  }
  else {
    cout<<A+C<<endl;
  }
  
  
  
}


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

namespace b
{
    class Program
    {
        static void Main(string[] args)
        {
            var _ = Console.ReadLine().Split();
            var k = long.Parse(_[0]);
            var s = long.Parse(_[1]);

            var count = 0;
            for(var i = 0; i <= k; i++){
                for(var j = 0; j <= k; j++){
                    var n = s - i - j;
                    if(n >= 0 && n <= k){
                        count++;
                    }
                }
            }

            Console.WriteLine(count);
        }
    }
}


Measured memory_bytes: 11092
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define tr(container, it) \
	for (auto it = container.begin(); it != container.end(); it++)
#define scontains(c,x) ((c).find(x) != (c).end())   //O(log n) 
#define contains(c,x) (find((c).begin(),(c).end(),x) != (c).end()) //O(n)
#define Ichar(_x) char _x;scanf("%c",&_x);
#define Iint(_x) int _x;scanf("%d",&_x); 
#define Ill(_x)  ll _x;scanf("%lld",&_x);
#define inc(a,b,x)(x)>a && (x)<b	
#define incE(a,b,x)(x)>=a && (x)<=b	
#define fileIO 	freopen("input.txt", "r", stdin);freopen("output.txt", "w", stdout);

void insert_sort(int *arr,int n)
{
	for (int i = 1; i < n; ++i)
	{
		int key = arr[i];
		int j = i - 1;
		while (key<arr[j] && j>=0)
		{
			arr[j + 1] = arr[j];
			j--;
		}
		arr[j + 1] = key;
	}
}

void select_sort(int *arr,int n)
{
	
	for (int i = 0; i < n; ++i)
	{
		int min_idx = i;
		for (int j = i+1; j < n; ++j)
		{
			if (arr[j] < arr[min_idx])min_idx = j;
		}
		swap(arr[min_idx], arr[i]);
	}


}

int c[100];
void add_binary(int *a,int *b,int n)
{
	int k = 0;
	for (int i = n-1; i >=0; --i)
	{
		if(a[i]==b[i]==1)
		{
			c[i+1] = k ^ 0;
			k = 1;
		}
		else
		{
			c[i+1] = k ^ (a[i] ^ b[i]);
			k &= a[i] ^ b[i];
		}
	}
	c[0] = k;
	for (int i = 0; i < n+1; ++i)
	{
		std::cout << c[i];
	}
	puts("");
}

void merge_sort(int *a, int l,int r)
{
	if(l==r)return;
	merge_sort(a, l, (l + r) / 2);
	merge_sort(a, (l + r) / 2+1,r );
//	merge();
};



int C[200];
void merge(int *A,int *B, int n)
{
	int i = 0, j = 0, k = 0;
	A[n] = INT_MAX;
	B[n] = INT_MAX;
	while (i<=n && j<=n)
	{
		if (A[i] < B[j]) { C[k] = A[i]; i++; k++; }
		else { C[k] = B[j]; j++; k++; }
	}
	
}



int main()
{
	int arr[2][100];
	Iint(n);
	for (int i = 0; i < n; ++i)
	{
		scanf("%d", &arr[0][i]);
	}
	for (int i = 0; i < n; ++i)
	{
		scanf("%d", &arr[1][i]);
	}
	int mx = 0;
	for (int i = 0; i < n; ++i)
	{
		int sum = 0;
		for (int j = 0; j <= i; ++j)
		{
			sum += arr[0][j];
		}
		for (int j = i; j < n; ++j)
		{
			sum += arr[1][j];
		}
		if (sum > mx)mx = sum;
	}
	std::cout << mx;


}





Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep3(i, s, n, a) for (int i = (s); i < (int)(n); i += a)
#define rep2(i, s, n) rep3(i, s, n, 1)
#define rep(i, n) rep2(i, 0, n)

using namespace std;
using ll = long long;
using ull = unsigned long long;
using P = pair<int, int>;

int main(){
    int n;
    cin >> n;
    vector<int> a;
    rep(i, n){
        int x;
        cin >> x;
        a.push_back(x);
    }
    sort(a.begin(), a.end());
    string ans = "YES";
    rep(i, n-1){
        if(a[i]==a[i+1]){
            ans = "NO";
            break;
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 4204
import java.util.*;
public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        String S = sc.next();
        int cnt=0;
        for(int a=0; a<=9; a++) {
            for(int b=0; b<=9; b++) {
                for(int c=0; c<=9; c++) {
                    boolean ax=false, bx=false, cx=false;
                    for(int i=0; i<N; i++) {
                        char tmp = S.charAt(i);
                        if(!ax) {
                            if(tmp=='0'+a) {
                                ax=true;
                            }
                            continue;
                        }
                        if(!bx) {
                            if(tmp=='0'+b) {
                                bx=true;
                            }
                            continue;
                        }
                        if(!cx) {
                            if(tmp=='0'+c) {
                                cx=true;
//                                System.out.println(String.format("%d is valid.", 100*a+10*b+1*c));
                                cnt++;
                                break;
                            }
                            continue;
                        }
                    }
                }
            }
        }
        System.out.println(String.format("%d", cnt));
    }
}


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

#define LL long long

#define FOR(INDEX, START, END) for (LL INDEX = (START); INDEX < (END); ++INDEX)
#define REP(INDEX, COUNT) for (LL INDEX = 0; INDEX < (COUNT); ++INDEX)

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

	vector<LL> cnt(S.size());

	LL g = 0;
	LL k = 0;
	for (int i = 0; i < S.size(); ++i) {
		if (S[i] == 'R') {
			if (i % 2) {
				k++;
			}
			else {
				g++;
			}
		}
		else {
			if (i % 2) {
				cnt[i] += k;
				cnt[i - 1] += g;
			}
			else {
				cnt[i] += g;
				cnt[i - 1] += k;
			}

			g = 0;
			k = 0;
		}
	}

	g = 0;
	k = 0;
	for (int i = S.size() - 1; i >= 0; --i) {
		if (S[i] == 'L') {
			if (i % 2) {
				k++;
			}
			else {
				g++;
			}
		}
		else {
			if (i % 2) {
				cnt[i] += k;
				cnt[i + 1] += g;
			}
			else {
				cnt[i] += g;
				cnt[i + 1] += k;
			}

			g = 0;
			k = 0;
		}
	}

	for (LL c : cnt) {
		cout << c << " ";
	}
	cout << endl;


	return 0;
}


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

using namespace std;

int main(int argc, char **argv)
{
    int a, b;

    cin >> a >> b;

    if(a < b){
        cout << "a < b" << endl;
    }else if(a > b){
        cout << "a > b" << endl;
    }else{
        cout << "a == b" << endl;
    }


}


Measured memory_bytes: 3084
#encoding:utf-8 No.0510 2014.11.10
score_A = 0
score_B = 0

gets.chomp.split.map{|n| score_A += n.to_i}
gets.chomp.split.map{|n| score_B += n.to_i}

if score_A >= score_B
  puts score_A
else
  puts score_B
end

Measured memory_bytes: 6096
#include <cstdio>
#include <algorithm>
#include <iostream>
#include <cstring>
using namespace std;
int a[100001];
int n;


int main(){
    
    scanf("%d",&n);
    
    for(int i=0;i<n;i++) scanf("%d",&a[i]);
    
    
    int now = 0;
    
    //1 오름차순 // 0 내림차순
    int ans = 0;
    
    
    int state = 0 ;
    
    if(a[0] == a[1]) state = 0;
    else if(a[0] < a[1]) state = 1;
    else if(a[0] > a[1]) state = 2;
    
    //0 아직 모른다
    //1 오름차순
    //2 내림차순
    
    while(true){
        
        
        
        for(int i=now+1;i<n;i++){
            if(state==0){
                
                if(a[now] == a[i]){
                    state = 0;
                    now = i;
                }else if(a[now]<a[i]){
                    state = 1;
                    now = i;
                }else if(a[now]>a[i]){
                    state = 2;
                    now = i;
                }
                
            }else if(state==1){ //오름차순
                
                if(a[now] <= a[i]){
                    now = i;
                }else{
                    ans++;
                    state = 0;
                    now = i;
                    break;
                }
                
                
            }else if(state==2){
                if(a[now] >= a[i]){
                    now = i;
                }else{
                    ans++;
                    state = 0;
                    now= i;
                    break;
                }
            }
        }
        if(now==n-1){
            ans++;break;
        }
        
        
    }
    
    
    printf("%d\n",ans);
    
    
    return 0;
}

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

int main() {
    int N;
  	string S;
    int count = 0;
    cin >> N;
    for(int i = 0; i < N; i++){
      cin >> S;
      if(S == "Y"){
        count++;        
      } else {
        continue;
      }
    }
  
    if(count >= 1){
      cout << "Four" << endl;
    } else {
      cout << "Three" << endl;
    }
 
}

Measured memory_bytes: 3612
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <map>
#include <unordered_map>
#include <stack>
#include <queue>
#include <utility>

#include <cassert>
#include <cmath>
#include <cstdio>

using namespace std;

#define fi first
#define se second
#define mkp make_pair
#define pb push_back
#define all(v) (v).begin(), (v).end()
#define rall(v) (v).rbegin(), (v).rend()
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;

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

int main() {
	int N, K;
	cin >> N >> K;
	rep(i,N) {
		int a;
		cin >> a;
	}

	cout << (N-1)/(K-1) + !!((N-1)%(K-1)) << endl;

	return 0;
}


Measured memory_bytes: 384
import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner kbd = new Scanner(System.in);
        int s = kbd.nextInt();
        int a = s / 100;
        int b = s % 100;
        if ((0 < a && a < 13) && (0 < b && b < 13)) {
            System.out.println("AMBIGUOUS");
        } else if (0 < a && a < 13) {
            System.out.println("MMYY");
        } else if (0 < b && b < 13) {
            System.out.println("YYMM");
        } else {
            System.out.println("NA");
        }
    }
}

Measured memory_bytes: 21844
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
const ll MOD = 1000000007;

int main(){
    ll N;
    cin >> N;
    ll H[N];
    for(ll i = 0; i < N; i++) cin >> H[i];
    
    ll ans = 1;
    ll max = H[0];
    
    for(ll i = 1; i < N; i++){
        if(max <= H[i]){
            ans++;
            max = H[i];
        }
    }
    cout << ans << "\n";
    return 0;
} 


Measured memory_bytes: 256