akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <cmath>
#include <iomanip>
typedef long long ll;
typedef long double ld;
#define rep(i, n) for (ll i = 0; i < (n); i++)
using namespace std;

int main(){
  int a, b, h, m;
  cin >> a >> b >> h >> m;
  
  ld a_rad = (ld)h * 30 + m * 0.5;
  ld b_rad = (ld)m * 6;
  ld rad = abs(a_rad - b_rad);
  ld ans = sqrt(a*a + b*b - 2*a*b*cos(M_PI*rad/180.0));
  
  cout << std::fixed << std::setprecision(20) << ans << endl;
  
  return 0;
}

Measured memory_bytes: 4156
package main

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

func abs(a int) int {
	if a >= 0 {
		return a
	}
	return -a
}

func min(a, b int) int {
	if a > b {
		return b
	}
	return a
}

func main() {
	var N int
	fmt.Scan(&N)
	h := make([]int, N)
	sc := bufio.NewScanner(os.Stdin)
	sc.Split(bufio.ScanWords)
	for i := range h {
		sc.Scan()
		h[i], _ = strconv.Atoi(sc.Text())
	}
	const inf = int(1e10)
	dp := make([]int, N+10)
	for i := 0; i < len(dp); i++ {
		dp[i] = inf
	}
	dp[0] = 0 // 初期値
	for i := 1; i < N; i++ {
		dp[i] = dp[i-1] + abs(h[i]-h[i-1]) // 1つ前から来た場合のコスト
		if i > 1 {
			dp[i] = min(dp[i], dp[i-2]+abs(h[i]-h[i-2])) // 2つ前から来た場合のコストと比較して小さい方を採用
		}
	}
	fmt.Println(dp[N-1])
}


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

//type
#define ll long long
typedef pair<int, int> P;
//定数
#define INF 1000000000000 //10^12:∞
#define MOD 1000000007    //10^9+7:合同式の法
#define MAXR 100000       //10^5:配列の最大のrange
//略記
#define PB push_back //挿入
#define MP make_pair //pairのコンストラクタ
#define F first      //pairの一つ目の要素
#define S second     //pairの二つ目の要素
#define Z class
// OTHER
// xの二乗を返す (関数テンプレート版)
template <typename T>
T square(T x) { return x * x; }
#define chmax(x, y) (x = max(x, y))
#define chmin(x, y) (x = min(x, y))
// loop
#define rep(i, n) for (int i = 0; i < (n); i++)
#define REPD(i, n) for (ll i = n - 1; i >= 0; i--)
#define FOR(i, a, b) for (ll i = a; i <= ll(b); i++)
#define FORD(i, a, b) for (ll i = a; i >= ll(b); i--)
#define FORA(i, I) for (const auto &i : I)

// vector
#define ALL(x) x.begin(), x.end()

// output
#define YES() printf("YES\n")
#define NO() printf("NO\n")
#define isYES(x) printf("%s\n", (x) ? "YES" : "NO")
#define Yes() printf("Yes\n")
#define No() printf("No\n")
#define ln cout << '\n'
template <Z A>
void pr(A a)
{
  cout << a;
  ln;
}
template <Z A, Z B>
void pr(A a, B b)
{
  cout << a << ' ';
  pr(b);
}

int ans = 0;
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *

int main()
{
  int a, b, c;
  cin >> a >> b >> c;
  pr((a + b + c) - max(a, max(b, c)));

  return 0;
}


Measured memory_bytes: 3592
#include<iostream>

int main()
{
	int a;
	int b;

	std::cin >> a >> b;

	if (a > b){
		std::cout << "a > b\n";
	}
	else if(a<b){
		std::cout << "a < b\n";

	}
	else{
		std::cout << "a == b\n";
	}
	return 0;
}


Measured memory_bytes: 3084
# LRRRRRRL, LRL は同じ(不幸な人は3人)
# L, R で分割してやると一回の操作でLRL -> LLL -> で不幸な人が2人へる LR の時は LLで1人減る
n, k = list(map(int, input().split(' ')))
s = input()

# LLRRRLL -> 1,1,1に変換して合体させていく
old = ''
converted = []
for c in s:
    if old != c:
        converted.append(1)
        old = c
temp = max(len(converted) - 2*k, 1)  # 必ず一人は犠牲になる
print(n - temp)

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

typedef long long ll;

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

  char last = S[0];
  std::string ans = "Good";
  for(int i = 1; i < 4; ++i) {
    if(last == S[i]) {
      ans = "Bad";
      break;
    }
    last = S[i];
  }

  std::cout << ans << std::endl;
}


Measured memory_bytes: 256
import sys

read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines
sys.setrecursionlimit(10 ** 9)
INF = 1 << 60


def main():
    N, X, M = map(int, readline().split())

    a = X
    ans = 0

    A = []
    index = [-1] * M
    n = 0

    while index[a] == -1 and n < N:
        index[a] = n
        A.append(a)
        n += 1
        a = (a * a) % M

    if n == N - 1:
        print(sum(A))
        return

    ans = sum(A[: index[a]])
    rest = N - index[a]
    cycle = sum(A[index[a] : n])
    remainder = sum(A[index[a] : index[a] + rest % (n - index[a])])

    ans += cycle * (rest // (n - index[a])) + remainder
    print(ans)

    return


if __name__ == '__main__':
    main()


Measured memory_bytes: 68884
n = int(input())
a=[int(input()) for i in range(n)]

if n == 1:
    print(a[0]//2)
else:
    ass = 0
    for i in range(n-1):
        k = a[i]//2
        if a[i]%2 == 1 and a[i]+1>0:
            k += 1
            a[i+1] = a[i+1]-1
        ass += k
    k = a[n-1]//2
    ass += k
    print(ass)

Measured memory_bytes: 7072
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;

class D {
    static StreamWriter Out = new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false };
    static void Main(string[] args) {
        int N;
        Input(out N);
        int[] A;
        Inputs(out A);
        int[] x = new int[N];
        for(int i = 0; i < N; i++) {
            if(i % 2 == 0) {
                x[0] += A[i];
            } else {
                x[0] -= A[i];
            }
        }
        for(int i = 1; i < N; i++) {
            x[i] = 2 * A[i - 1] - x[i - 1];
        }
        Print(x);
        Out.Flush();
    }
    static T ChangeT<T>(string s) => (T)Convert.ChangeType(s, typeof(T));
    static void Input<A>(out A a) {
        var words = Console.ReadLine().Split(new[] { ' ' }, options: StringSplitOptions.RemoveEmptyEntries);
        a = ChangeT<A>(words[0]);
    }
    static void Input<A, B>(out A a, out B b) {
        var words = Console.ReadLine().Split(new[] { ' ' }, options: StringSplitOptions.RemoveEmptyEntries);
        a = ChangeT<A>(words[0]);
        b = ChangeT<B>(words[1]);
    }
    static void Input<A, B, C>(out A a, out B b, out C c) {
        var words = Console.ReadLine().Split(new[] { ' ' }, options: StringSplitOptions.RemoveEmptyEntries);
        a = ChangeT<A>(words[0]);
        b = ChangeT<B>(words[1]);
        c = ChangeT<C>(words[2]);
    }
    static void Input<A, B, C, D>(out A a, out B b, out C c, out D d) {
        var words = Console.ReadLine().Split(new[] { ' ' }, options: StringSplitOptions.RemoveEmptyEntries);
        a = ChangeT<A>(words[0]);
        b = ChangeT<B>(words[1]);
        c = ChangeT<C>(words[2]);
        d = ChangeT<D>(words[3]);
    }
    static void Input<A, B, C, D, E>(out A a, out B b, out C c, out D d, out E e) {
        var words = Console.ReadLine().Split(new[] { ' ' }, options: StringSplitOptions.RemoveEmptyEntries);
        a = ChangeT<A>(words[0]);
        b = ChangeT<B>(words[1]);
        c = ChangeT<C>(words[2]);
        d = ChangeT<D>(words[3]);
        e = ChangeT<E>(words[4]);
    }
    static void Input<A, B, C, D, E, F>(out A a, out B b, out C c, out D d, out E e, out F f) {
        var words = Console.ReadLine().Split(new[] { ' ' }, options: StringSplitOptions.RemoveEmptyEntries);
        a = ChangeT<A>(words[0]);
        b = ChangeT<B>(words[1]);
        c = ChangeT<C>(words[2]);
        d = ChangeT<D>(words[3]);
        e = ChangeT<E>(words[4]);
        f = ChangeT<F>(words[5]);
    }
    static void Inputs<T>(out T[] array) {
        array = Console.ReadLine().Split(new[] { ' ' }, options: StringSplitOptions.RemoveEmptyEntries).Select(s => ChangeT<T>(s)).ToArray();
    }
    static void Print<T>(T s) => Out.WriteLine(s);
    static void Print<T>(params T[] s) => Out.WriteLine(string.Join(" ", s));
    static void Print<T>(IEnumerable<T> e) => Out.WriteLine(string.Join(" ", e));
}

Measured memory_bytes: 31320
fn main() {
    proconio::input! {
        _n: usize,
        a: usize,
        b: usize,
        c: usize,
        d: usize,
        s: proconio::marker::Chars,
    }
    let (a, b, c, d) = (a - 1, b - 1, c - 1, d - 1);
    for w in s[b + 1..=d].windows(2) {
        if w[0] == '#' && w[1] == '#' {
            println!("No");
            return;
        }
    }
    for w in s[a + 1..=c].windows(2) {
        if w[0] == '#' && w[1] == '#' {
            println!("No");
            return;
        }
    }
    if c > d {
        for w in s[b - 1..=d + 1].windows(3) {
            if w[0] == '.' && w[1] == '.' && w[2] == '.' {
                println!("Yes");
                return;
            }
        }
        println!("No");
    } else {
        println!("Yes");
    }
}


Measured memory_bytes: 3020
#include <iostream>
#include <fstream>
#include <cstdio>
#include <cmath>
#include <vector>
#include <string>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <deque>
#include <bitset>
#include <algorithm>
#include <complex>
#include <array>
#include <functional>
using namespace std;
 
#define REP(i,n) for(int i=0; i<n; ++i)
#define FOR(i,a,b) for(int i=a; i<=b; ++i)
#define FORR(i,a,b) for (int i=a; i>=b; --i)
#define ALL(c) (c).begin(), (c).end()
 
typedef long long ll;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef vector<double> VD;
typedef vector<VI> VVI;
typedef vector<VL> VVL;
typedef vector<VD> VVD;
typedef pair<int,int> P;
typedef pair<ll,ll> PL;

template<typename T> void chmin(T &a, T b) { if (a > b) a = b; }
template<typename T> void chmax(T &a, T b) { if (a < b) a = b; }

int in() { int x; scanf("%d", &x); return x; }
ll lin() { ll x; scanf("%lld", &x); return x; }

int main() {
    int n;
    cin >> n;
    VD x(n), y(n);
    REP(i,n){
        cin >> x[i] >> y[i];
    }
    VI p(n);
    REP(i,n) p[i] = i;
    double ans = 0.0;
    do {
        double d = 0.0;
        REP(i,n-1){
            int a = p[i], b = p[i + 1];
            d += sqrt((x[a] - x[b]) * (x[a] - x[b]) + (y[a] - y[b]) * (y[a] - y[b]));
        }
        ans += d;
    }while (next_permutation(ALL(p)));
    FOR(x,1,n) ans /= x;
    printf("%.15f\n", ans);
    return 0;
}


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


def solve():
    N = int(input())
    d = {i:-1 for i in range(1, N+1)}
    *l, = map(int, input().split())

    MOD = 10**9+7
    n = N+1
    fac = [1]*(n+1)
    rev = [1]*(n+1)
    
    for i in range(1,n+1):
        fac[i] = i*fac[i-1]%MOD
        rev[i] = pow(fac[i], MOD-2, MOD)
    
    comb = lambda a,b:(fac[a]*rev[a-b]*rev[b])%MOD if a>=b else 0

    for i, j in enumerate(l):
        if d[j] != -1:
            break
        d[j] = i

    v = d[j]+N-i
    for i in range(1, N+2):
        print((comb(N+1, i)-comb(v, i-1))%MOD)


if __name__ == "__main__":
    solve()


Measured memory_bytes: 67756
{-# LANGUAGE BangPatterns #-}
{-# LANGUAGE BinaryLiterals #-}
{-# LANGUAGE MultiWayIf #-}
{-# LANGUAGE NumDecimals #-}
{-# LANGUAGE ScopedTypeVariables #-}
{-# LANGUAGE TupleSections #-}

import Control.Applicative
import Control.Arrow
import Control.Monad
import Control.Monad.ST

import Data.Char
import Data.List
import Data.Maybe

import qualified Data.ByteString.Char8 as B

import Data.Array.ST.Safe
import Data.STRef

import Debug.Trace
import Text.Printf

readInt = readLn :: IO Int
readInteger = readLn :: IO Integer
readInts = map ( fst . fromJust . B.readInt ) . B.words <$> B.getLine
readIntegers = map ( fst . fromJust . B.readInteger ) . B.words <$> B.getLine

which a b f = if f then a else b
mp [ a, b ] = ( a, b )

modifyArray a i f = writeArray a i =<< f <$> readArray a i

main = do
	[ a, b, h, m ] :: [Double] <- map fromIntegral <$> readInts
	let
		theta = abs ( ( h / 12 + m / 60 / 12 ) - ( m / 60 ) ) * 2 * pi
	printf "%.12f\n" $ sqrt ( a ^ 2 + b ^ 2 - 2 * a * b * cos theta )

Measured memory_bytes: 4420
use std::cmp;

fn main() {
    let s = std::io::stdin();
    let mut sc = Scanner { stdin: s.lock() };

    let n: usize = sc.read();
    let mut tree = vec![vec![]; n];
    for _ in 1..n {
        let a = sc.read::<usize>();
        let b = sc.read::<usize>();
        tree[a].push(b);
        tree[b].push(a);
    }

    match (0..n).find(|&i| tree[i].len() > 2) {
        None => println!("1"),
        Some(root) => {
            let mut max = 0;
            let mut sum = 0;
            for &next in tree[root].iter() {
                let (only_line, count) = dfs(next, root, &tree);
                sum += count;
                if only_line {
                    assert_eq!(count, 1);
                    max = cmp::max(max, count);
                }
            }
            println!("{}", sum - max);
        }
    }
}

fn dfs(v: usize, p: usize, graph: &Vec<Vec<usize>>) -> (bool, usize) {
    let mut result = vec![];
    for &next in graph[v].iter().filter(|&&next| next != p) {
        result.push(dfs(next, v, graph));
    }

    if result.is_empty() {
        (true, 1)
    } else if result.len() == 1 {
        let (only_line, count) = result[0];
        assert!(!only_line || count == 1);
        (only_line, count)
    } else {
        let sum = result.iter().map(|&(_, count)| count).sum::<usize>();
        let mut ans = sum;
        for (only_line, count) in result.into_iter() {
            if only_line {
                assert_eq!(count, 1);
                ans = cmp::min(ans, sum - 1);
            }
        }
        (false, ans)
    }
}

pub struct Scanner<R> {
    stdin: R,
}

impl<R: std::io::Read> Scanner<R> {
    pub fn read<T: std::str::FromStr>(&mut self) -> T {
        use std::io::Read;
        let buf = self
            .stdin
            .by_ref()
            .bytes()
            .map(|b| b.unwrap())
            .skip_while(|&b| b == b' ' || b == b'\n')
            .take_while(|&b| b != b' ' && b != b'\n')
            .collect::<Vec<_>>();
        unsafe { std::str::from_utf8_unchecked(&buf) }
            .parse()
            .ok()
            .expect("Parse error.")
    }
    pub fn vec<T: std::str::FromStr>(&mut self, n: usize) -> Vec<T> {
        (0..n).map(|_| self.read()).collect()
    }
    pub fn chars(&mut self) -> Vec<char> {
        self.read::<String>().chars().collect()
    }
}


Measured memory_bytes: 22524
#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 (ll i = (ll)(a); i < (ll)(b); ++i)
#define rep(...) _overload3(__VA_ARGS__, repi, _rep, )(__VA_ARGS__)
#define ll long long
#define lld long double
#define ALL(x) x.begin(), x.end()
#define MOD (ll)(1e9 + 7)
using namespace std;
int main()
{
    int n;
    cin >> n;
    priority_queue<ll> l, r;
    ll lsum = 0, rsum = 0;
    vector<ll> a(3 * n, 0);
    vector<ll> maxl(3 * n, -1);
    vector<ll> minr(3 * n, -1);

    rep(i, 3 * n) cin >> a[i];
    rep(i, n)
    {
        l.push(-a[i]);

        lsum += a[i];
    }
    maxl[n - 1] = lsum;

    rep(i, n, 2 * n + 1)
    {
        //cerr << lsum << "," << rsum << "," << a[i] << endl;
        if (a[i] > -l.top())
        {
            lsum -= -l.top();
            lsum += a[i];

            l.pop();
            l.push(-a[i]);
        }
        maxl[i] = lsum;
        cerr << "max " << i << " : " << maxl[i] << endl;
    }

    for (int i = 3 * n - 1; i >= 2 * n; i--)
    {
        r.push(a[i]);
        rsum += a[i];
    }
    minr[2 * n] = rsum;
    for (int i = 2 * n - 1; i >= n - 1; i--)
    {
        if (a[i] < r.top())
        {
            rsum -= r.top();
            rsum += a[i];
            r.pop();
            r.push(a[i]);
        }
        minr[i] = rsum;
        cerr << "min " << i << " : " << minr[i] << endl;
    }
    ll ans = -(1ll << 60);
    rep(i, 3 * n - 1)
    {
        if (maxl[i] == -1 || minr[i + 1] == -1)
            continue;
        ans = max(ans, maxl[i] - minr[i + 1]);
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 9588
import sys
sys.setrecursionlimit(200000)

def dfs(v):
    global node_chk
    global B
    global connect
    global value

    node_chk[v] = 1
    connect[v] = value
    for x in B[v]:
        if(node_chk[x] == 0):
                dfs(x)



n,m = map(int,input().split())
B = [[]for i in range(n)] # 隣接リスト
node_chk = [0 for i in range(n)]
connect = [0 for i in range(n)]
value = 0

for i in range(m):
    A = list(map(int,input().split()))
    B[A[0]].append(A[1])
    B[A[1]].append(A[0])

for i in range(n):
    if(node_chk[i] == 1):
        continue
    dfs(i)
    value += 1


q = int(input())
for i in range(q):
    start,target = map(int,input().split())
    if(connect[start] == connect[target]):
        print("yes")
    else:
        print("no")


Measured memory_bytes: 122208
#include <bits/stdc++.h>
#define ll long long
#define pb push_back
using namespace std;

const int mnx = 1e6 + 9;
const int mod = 1e9 + 7;

string s, t;
ll dp[3005][3005];

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

    ll n = s.size();
    ll m = t.size();

    for(int i = 1; i <= n; i++){
        for(int j = 1; j <= m; j++){
            if(s[i - 1] == t[j - 1]){
                dp[i][j] = dp[i - 1][j - 1] + 1;
            } else {
                dp[i][j] = max(dp[i - 1][j], dp[i][j - 1]);
            }
        }
    }

//    cout << "  ";
//
//    for(int i = 1; i <= m; i++){
//        cout << t[i - 1] << ' ';
//    } cout << '\n';
//
//    for(int i = 1; i <= n; i++){
//        cout << s[i - 1] << ' ';
//        for(int j = 1; j <= m; j++){
//            cout << dp[i][j] << ' ';
//        } cout << '\n';
//    }

    string f;
    ll qw = dp[n][m];

    while(qw){
        if(dp[n][m - 1] == qw){
            m--;
        } else if(dp[n - 1][m] == qw){
            n--;
        } else if(dp[n - 1][m - 1] + 1 == qw){
            qw--; f += s[n - 1];
            n--; m--;
        }
    }

    reverse(f.begin(), f.end());

    cout << f << '\n';

    return 0;
}

/*
3
10 40 70
20 50 80
30 60 90

10  40  70
90  120 120
150 180 210
*/


















Measured memory_bytes: 70656
#include <algorithm>
#include <cassert>
#include <iostream>
#include <vector>
#include <unordered_map>

class Sushi {
  public:
    long long type;
    long long value;
    Sushi() { type = 0; value = 0; }
    Sushi(long long _t, long long _v) { type = _t, value = _v; }
};

bool has_larger_value(const Sushi& a, const Sushi& b)
{
  return a.value > b.value;
}

long long calc_score(long long total_value, std::unordered_map<long long, long long>& type_inuse)
{
  return total_value + type_inuse.size() * type_inuse.size();
}

int main()
{
  int n, k;
  std::cin >> n >> k;
  std::vector<Sushi> master_sushi;
  for (int i = 0; i < n; i++) {
    int t, v;
    std::cin >> t >> v;
    master_sushi.emplace_back(t, v);
  }
  //master_sushi.sort(has_larger_value);
  std::sort(master_sushi.begin(), master_sushi.end(), has_larger_value);
  std::vector<Sushi> eaten_sushi;
  long long total_value = 0;
  std::unordered_map<long long, long long> type_inuse;
  for (int i = 0; i < k; i++) {
    Sushi* p = &master_sushi.at(i);
    type_inuse[p->type]++;
    total_value += p->value;
    eaten_sushi.emplace_back(p->type, p->value);
  }
  long long score = calc_score(total_value, type_inuse);
  int master_index = k;
  int eaten_index = k-1;
  while (0 < eaten_index && master_index < n) {
    Sushi* old_sushi = &eaten_sushi.at(eaten_index);
    auto old_it = type_inuse.find(old_sushi->type);
    assert(old_it != type_inuse.end());
    assert(1 <= old_it->second);
    if (old_it->second == 1) {
      eaten_index--;
      continue;
    }
    Sushi* new_sushi = &master_sushi.at(master_index);
    if (type_inuse.find(new_sushi->type) != type_inuse.end()) {
      master_index++;
      continue;
    }
    total_value += new_sushi->value - old_sushi->value;
    type_inuse[old_sushi->type]--;
    type_inuse[new_sushi->type]++;
    eaten_sushi.at(eaten_index) = master_sushi.at(master_index);
    score = std::max(score, calc_score(total_value, type_inuse));
    eaten_index--;
    master_index++;
  }
  std::cout << score << '\n';
  return 0;
}


Measured memory_bytes: 7408
def main():
  n=int(input())
  anums=list(map(int,input().split()))
  mx_nonleaves=[0 for _ in range(n+1)]
  if n==0:
    if anums[0]==1:
      return 1
    return -1
  for i,anum in enumerate(anums):
    if i==0:
      if anum>0:
        return -1
      mx_nonleaves[i]=1
      continue
    mx_nonleaves[i]=mx_nonleaves[i-1]*2-anums[i]
    if mx_nonleaves[i]<0:
      return -1
  mx_nonleaves[-1]=0
  #print(mx_nonleaves)
  for idx in range(n,1,-1):
    mx_nonleaves[idx-1]=min(mx_nonleaves[idx-1],mx_nonleaves[idx]+anums[idx])
  #print(anums)
  #print(mx_nonleaves)
  return sum(anums)+sum(mx_nonleaves)

print(main())

Measured memory_bytes: 699592
#include <bits/stdc++.h>
#define fast ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
using namespace std;

int main() {
	fast;
	int n;
	cin>>n;
	int dp[n][3],energy[n][3];
	for(int i=0;i<n;i++) cin>>energy[i][0]>>energy[i][1]>>energy[i][2];
	dp[n-1][0]=energy[n-1][0],dp[n-1][1]=energy[n-1][1],dp[n-1][2]=energy[n-1][2];
	for(int i=n-2;i>=0;i--){
		dp[i][0]=energy[i][0]+max(dp[i+1][1],dp[i+1][2]);
		dp[i][1]=energy[i][1]+max(dp[i+1][0],dp[i+1][2]);
		dp[i][2]=energy[i][2]+max(dp[i+1][0],dp[i+1][1]);
	}
	cout<<max(dp[0][0],max(dp[0][1],dp[0][2]))<<"\n";
	return 0;
}

Measured memory_bytes: 2560
#include <iostream>
#include <cmath>
#include <complex>

using namespace std;

const double pi = acos(-1.0);
using comd = complex<double>; 

int main()
{
    int A, B, H, M;
    cin >> A >> B >> H >> M;

    double ath = (H + M / 60.0) * pi / 6.0;
    double bth = M * pi / 30.0;

    comd a = polar<double>(A, ath);
    comd b = polar<double>(B, bth);
    
    double ans = abs(a-b);
    printf("%.20f\n", ans);
}

Measured memory_bytes: 4032
// I'm a f*cking looser
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define fasino ios_base::sync_with_stdio(false); cin.tie(0);
#define asc(A) sort(A.begin(),A.end())
#define dsc(A) sort(A.begin(),A.end(),greater<ll>())
#define input(A,N) for(ll i=0;i<N;i++) cin>>A[i];
int main()
{
    fasino
    #ifndef ONLINE_JUDGE
   // freopen("input.txt", "r", stdin); 
    #endif
    string s;
    cin>>s;
    if(s=="ABC")
        cout<<"ARC";
    else
        cout<<"ABC";   
    return 0;
}

Measured memory_bytes: 3636
def main():
    n = int(input())
    a = [None]*n
    b = [None]*n
    for i in range(n):
        a[i], b[i] = map(int, input().split())
    ans = 0
    buf = 0
    for i in reversed(range(n)):
        x = (a[i]+buf+b[i]-1) // b[i]
        ans += x*b[i] - (a[i]+buf)
        buf += x*b[i] - (a[i]+buf)
    print(ans)

if __name__ == "__main__":
    main()

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

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

int main()
{
	ios::sync_with_stdio(false);
  	cin.tie(0);
  	int a,b,c,d;
	cin >> a >> b >> c >> d;
	if(a+b > c+d)
		cout << "Left\n";
	else if(a+b == c+d)
		cout<< "Balanced\n";
	else cout << "Right\n";	
	return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<map>
#include<string>
#include<vector>
#include<algorithm>
#define p pair<int,int>
#define P pair<int,p>
using namespace std;

int Par[100], Rank[100];
int Find(int a) {
	if (Par[a] == a)return a;
	return Par[a]=Find(Par[a]);
}
void unite(int a, int b) {
	a = Find(a);
	b = Find(b);
	if (Rank[a] > Rank[b]) {
		Par[b] = a;
	}
	else if (Rank[a] < Rank[b]) {
		Par[a] = b;
	}
	else {
		Par[b] = a;
		Rank[a]++;
	}
}
int main() {
	int a, b;
	P s[500];
	while (cin >> a >> b, a | b) {
		for (int i = 0; i < a; i++) {
			Par[i] = i; Rank[i] = 0;
		}
		for (int c = 0; c < b; c++) {
			int d, e, f; scanf("%d%d%d", &d, &e, &f);
			s[c] = P(f, p(d, e));
		}
		sort(s, s + b);
		bool k[100]{};
		int sum = 0;
		for (int i = 0; i < b; i++) {
			if (Find(s[i].second.first)!=Find(s[i].second.second)) {
				unite(s[i].second.first, s[i].second.second);
				sum += s[i].first;
			}
		}
		cout << sum << endl;
	}
}

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

using namespace std;

int main(){
int N; cin >> N;
  int cnt = 0; long long sum_minus = 0;  long long  flag = 0;
  vector<long long >X(N); for(int i = 0; i < N; i++){ cin >> X[i];}
  for(int i = 0; i < N; i++){ long long b; cin >> b; X[i] -= b;
         // X[i] = A[i] - B[i]
    if( X[i] < 0){ cnt++; sum_minus += X[i]; } 
                         flag += X[i];}
  
  if( flag < 0){ // Aの総和がBの総和より小さいことを意味
    cout << -1 << endl; return 0;}
  
  sort(X.begin(),X.end()); reverse( X.begin(), X.end());
  //Xを大きい順に並べる

    
  for(int i = 0; i < N; i++){
    if( X[i] <= 0){ break;}
    if( sum_minus >= 0){ break;}
    
    sum_minus += X[i]; cnt++;
  }
  
  cout << cnt << endl; return 0;}
  


Measured memory_bytes: 1024
import sys
input = sys.stdin.readline
from itertools import product
n, m = map(int, input().split())
xyz = [list(map(int, input().split())) for _ in range(n)]

ans = 0
for p in product([1, -1], repeat=3):
    temp = []
    for x, y, z in xyz:
        x*=p[0];y*=p[1];z*=p[2]
        temp.append(x+y+z)
    temp.sort(reverse=True)
    ans = max(ans, sum(temp[:m]))
print(ans)

Measured memory_bytes: 40176
parseInt(x) = parse(Int, x)
parseMap(x::Array{SubString{String},1}) = map(parseInt, x)

function main()
	n = readline() |> parseInt
	a = readline() |> split |> parseMap
	b = zeros(Int,n)
	for i in 1:n
		b[a[i]] = i
	end
	for i in 1:n-1
		print(b[i], " ")
	end
	println(b[n])
end

main()

Measured memory_bytes: 130012
#include<stdio.h>
#include<iostream>
#include<vector>
#include<math.h>
#include<queue>
#include<map>
#include<algorithm>
#include<string.h>
#include<functional>
#include<limits.h>
#include<stdlib.h>
#include<cmath>
#include<cstring>
#include<set>
#include<climits>
using namespace std;

#define intmax INT_MAX
#define lmax LONG_MAX
#define uintmax UINT_MAX
#define ulmax ULONG_MAX
#define llmax LLONG_MAX
#define ll long long
#define rep(i,a,N) for((i)=(a);(i)<(N);(i)++)
#define rrp(i,N,a) for((i)=(N)-1;(i)>=(a);(i)--)
#define llfor ll i,j
#define sc(a) cin>>a
#define pr(a) cout<<a<<endl
#define pY puts("YES")
#define pN puts("NO")
#define py puts("Yes")
#define pn puts("No")
#define pnn printf("\n")
#define pb(b) push_back(b) 
#define all(a) a.begin(),a.end()
#define llvec vector<vector<ll>>
#define charvec vector<vector<char>>
#define size(a,b) (a,vector<ll>(b))
const int mod=1e9+7;
/* 
UnionFind：素集合系管理の構造体(union by size)
isSame(x, y): x と y が同じ集合にいるか。 計算量はならし O(α(n))
unite(x, y): x と y を同じ集合にする。計算量はならし O(α(n))
treeSize(x): x を含む集合の要素数。
*/
struct UnionFind{
 vector<int>size,parents;
 UnionFind(){}
 UnionFind(int n){//make n trees.
  size.resize(n,0);
  parents.resize(n,0);
  for(int i=0;i<n;i++)makeTree(i);
 }
 void makeTree(int x){
   parents[x]=x;//the parent of x is x
   size[x]=1;
  }
 bool isSame(int x,int y){return findRoot(x)==findRoot(y);}
 bool unite(int x,int y){
  x = findRoot(x);
  y = findRoot(y);
  if(x==y)return false;
  if(size[x]>size[y]){
   parents[y]=x;
   size[x]+=size[y];
  } 
  else{
   parents[x]=y;
   size[y]+=size[x];
  }
  return true;
 }
 int findRoot(int x){//木の根を探す,計算量削減のため低く
  if(x!=parents[x])parents[x]=findRoot(parents[x]);
  return parents[x];
 }
 int treeSize(int x){return size[findRoot(x)];}
};
/*pi*/const double pi=acos(-1);
/*繰り上げ除算*/ll cei(ll x,ll y){ll ans=x/y;if(x%y!=0)ans++;return ans;}
/*最大公約数*/ll gcd(ll x,ll y){return y?gcd(y,x%y):x;}
/*最小公倍数*/ll lcm(ll x,ll y){return x/gcd(x,y)*y;}
/*n乗*/ll llpow(ll x,ll n){ll i,ans=1;rep(i,0,n)ans*=x;return ans;}
/*階乗*/ll fact(ll x){ll i,ans=1;rep(i,0,x)ans*=(x-i);return ans;}
/*nCr*/ll ncr(ll n,ll r){return fact(n)/fact(r)/fact(n-r);}
/*nPr*/ll npr(ll n,ll r){return fact(n)/fact(n-r);}
/*primejudge*/bool prime(ll a){if(a<=1)return false;ll i;for(i=2;i*i<=a;i++){if(a%i==0)return false;}return true;}
/*Fibonacci数列*/ll fib(ll x){ll i,fibo[x+10];fibo[0]=1;fibo[1]=1;fibo[2]=1;rep(i,3,x+1)fibo[i]=fibo[i-1]+fibo[i-2];return fibo[x];}
/*桁数*/ll dig(ll n){ll d=0,tmp=n;while(tmp/10>0){tmp/=10;d++;}return d;}
/*迷路移動*/const int dx[4]={1,0,-1,0};const int dy[4]={0,1,0,-1};
llfor;////////////////////////////////////////////////////////////
int main(){
 string s;cin>>s;
 ll n=s.length();
 ll cnt=0,tmp;
 rep(i,0,n){
  tmp=s[i]-'0';
  cnt+=tmp;
 }
 if(cnt%9==0)py;
 else pn;
 return 0;
return 0;}

Measured memory_bytes: 3764
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
 
namespace ABC109A
{
    class Program
    {
        static void Main(string[] args)
        {
 
 
            var word = Console.ReadLine().Split();
            int a = int.Parse(word[0]);
            int b = int.Parse(word[1]);
            var max = new int[3] { 1, 2, 3 };
            int c,d,e;
 
            c = a * b * max[0];
            d = a * b * max[1];
            e = a * b * max[2];
            if (c % 2 == 0 && d % 2 == 0 && e %2 == 0)
            {
 
 
                Console.WriteLine("No");
            }
            else
                Console.WriteLine("Yes");
 
 
 
 
                Console.ReadKey();
 
 
 
            }
        }
    }
 

Measured memory_bytes: 11092
parseInt(x::String) = parse(Int, x)
parseInt(x::SubString{String}) = parse(Int, x)
parseInt(x::Char) = parse(Int, x)
parseInt(x::Float64) = trunc(Int, x)
parseFloat(x::String) = parse(Float64, x)
parseFloat(x::Int) = trunc(Float64, x)
parseMap(x::Array{SubString{String},1}) = map(parseInt, x)

function main()
    println(div(parseInt(readline()),3))
end
main()

Measured memory_bytes: 163396
#include<bits/stdc++.h>
#include<cmath>
#include<string>
using namespace std;
int main(){
int N;
  int cnt=0;
  
  cin>>N;
  vector<int> W(N);
  for(int i=0;i<N;i++){
    cin>>W.at(i);
    cnt+=W.at(i);
  }
  int A=0;
  int M=100000000;
  for(int i=0;i<N;i++){
    A+=W.at(i);
    M=min(M,abs(2*A-cnt));
  }
  cout <<M<< endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define fol(i,n) for(int i=0;i<n;i++)
#define pb push_back
typedef long long ll;
typedef pair<int,int> P;
typedef vector<P> vip;

bool reg(string s,string t){ //|s|=|t|
    int n = s.size();
    bool flag = true;
    fol(i,n){
        if (s[i]!=t[i]&&s[i]!='?') flag=false;
    }
    return flag;
}

void solve(){
    string s,t;cin>>s>>t;
    string buf,str1,ans;
    int a = s.size();
    int b = t.size();
    bool flag=false;
    for(int i=a-b;i>=0;i--){
        buf = s.substr(i,b);
        if (!flag&&reg(buf,t)){
            s.replace(i,b,t);
            flag = true;
        }
    }
    fol(i,a){
        if (s[i]=='?') s[i]='a';
    }
    if (flag){
        cout << s <<endl;
    }else{
        cout << "UNRESTORABLE"<<endl;
    }
}

int main(){
//option:-std=c++0x
    solve();
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main(){
    long long n, a, b; cin >> n >> a >> b;
    if(a>b){
        cout << 0 << endl;
        return 0;
    }
    if(n==1){
        if(a!=b) cout << 0 << endl;
        else cout << 1 << endl;
    }else{
        cout << (n-2) * (b-a) + 1 << endl;
    }
    return 0;
}

Measured memory_bytes: 3636
# -*- coding: utf-8 -*-
x, y, z, k = map(int, input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
c = list(map(int, input().split()))

a.sort(reverse=True)
b.sort(reverse=True)
c.sort(reverse=True)

abc = []

for i, _a in enumerate(a):
    for j, _b in enumerate(b):
        if (i+1) * (j+1) > k:
            break
        for l, _c in enumerate(c):
            if (i+1) * (j+1) * (l+1) > k:
                break
            abc.append(_a + _b + _c)

abc.sort(reverse=True)
for x in abc[:k]:
    print(x)


Measured memory_bytes: 8708
W, H, x, y, r = (int(i) for i in input().split())
 
if x - r < 0 :
    print("No")
elif x + r > W:
    print("No")
elif  y - r < 0:
    print("No")
elif y + r > H:
  print ("No")
else:
  print ("Yes")

Measured memory_bytes: 7724
package main

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

var sc = bufio.NewScanner(os.Stdin)

func main() {
	var inputs [4]float64
	if sc.Scan() {
		for i, v := range strings.Split(sc.Text(), " ") {
			inputs[i], _ = strconv.ParseFloat(v, 64)
		}
	}

	x := inputs[2] - inputs[0]
	y := inputs[3] - inputs[1]
	fmt.Println(math.Sqrt(x*x + y*y))
}



Measured memory_bytes: 1152
#include <iostream>
#include <cmath>
#include <algorithm>
#include <vector>
#include <set>
#include <unordered_set>
#include <queue>
#include <deque>
#include <string>
#include <sstream>
#include <iomanip>
#include <map>
#include <unordered_map>
#include <stack>
#include <cstdio>
#include <climits>
#include <tuple>
#include <ctime>
#include <cstring>
#include <numeric>
#include <functional>
#define FOR(i,a,n) for (int i = a; i < n; i++)
#define IFOR(i,n,a) for (int i = n; i >= a; i--)
#define mp make_pair
#define full(a) a.begin(), a.end()
#define sz(x) ((int)(x).size())
#define pii pair<int, int>
#define trav(a,x) for (auto& a : x)
using ull = unsigned long long;
using ll = long long;
using ld = long double;
using namespace std;
const ll mod = 998244353;
const int N = 2e5 + 5;



void solve()
{
    ll a, b, c, d; cin >> a >> b >> c >> d;
    cout << max({ a * c, a * d, b * c, b * d });
}


int main()
{
    ios::sync_with_stdio(false); cin.tie(NULL); //cout.tie(NULL);
    /*int tc; cin >> tc;
    while (tc--)*/
        solve();

    return 0;
}


Measured memory_bytes: 3160
#include <iostream>
#include <vector>
#include <string>
#include <unordered_map>
#include <utility>

using namespace std;

vector<int> dx = {0, 1, 0, -1};
vector<int> dy = {1, 0, -1, 0};

template<typename T> 
void show(T a){
  for(auto i : a){ cout << i << " "; }
  cout << endl;
}
template<typename T> 
void showmatrix(T a){
  for(auto j: a){for(auto i : j){ cout << i; }cout << endl;}
  cout << endl;
}
//debug
void check(int i = 0){
  cout << "checkpoint:[" << i << "]" << endl;
}

int euclidean(int a, int b){
  if(a < b) swap(a, b);
  if(a == 0) return b;
  if(a == b || b == 0) return a;
  return euclidean(b, a%b);
}

int main(int argc, char *argv[]){
  ios::sync_with_stdio(false);
  cin.tie(NULL);

  int n; cin >> n;
  vector<int> v(n);
  for(auto& i : v){
    cin >> i;
  }

  for(int i = 1; i < n; i++){
    v[i] = euclidean(v[i-1], v[i]);
  }

  cout << v[v.size()-1] << endl;
}


Measured memory_bytes: 640
#include <iostream>
using namespace std;
int main(void){
    int h1,h2,k1,k2,a,b,c,d;
    cin >> h1 >> h2;
    cin >> k1 >> k2; 
    cin >> a >> b >> c >> d;
    int x=h1*a+h2*b+h1/10*c+h2/20*d;
    int y=k1*a+k2*b+k1/10*c+k2/20*d;
    if(x > y){
        cout << "hiroshi" << endl;
    }
    else if(x < y){
        cout << "kenjiro" << endl;
    }
    else if(x == y){
        cout << "even" << endl;
    }
} 


Measured memory_bytes: 3104
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;

// definition {{{ 1

// scaning {{{ 2
#define Scd(x) scanf("%d", &x)
#define Scd2(x,y) scanf("%d%d", &x, &y)
#define Scd3(x,y,z) scanf("%d%d%d", &x, &y, &z)

#define Scll(x) scanf("%llu", &x)
#define Scll2(x,y) scanf("%llu%llu", &x, &y)
#define Scll3(x,y,z) scanf("%llu%llu%llu", &x, &y, &z)

#define Scc(c) scanf("%c", &c);
#define Scs(s) scanf("%s", s);
#define Scstr(s) scanf("%s", &s);
// }}} 2

// constants {{{ 2
#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
// }}} 2

// systems {{{ 2
#define Rep(x,y) for(int x = 0; x < y; x++)
#define Repe(x,y,z) for(int x = z; x < y; x++)
// }}} 2

// output {{{ 2
#define YesNo(a) (a)?printf("Yes\n"):printf("No\n");
// }}} 2

// }}} 1

int main() {

    int A,B,Q;
    Scd3(A,B,Q);
    set<ll> s;
    set<ll> t;

    ll a = 0;
    Rep(i,A){
        Scll(a);
        s.insert(a);
    }
    Rep(i,B){
        Scll(a);
        t.insert(a);
    }

    ll q;
    ll a1;
    ll a2;
    ll b1;
    ll b2;
    ll ans = 0;
    ll dp[222];
    Rep(i,Q){
        Scll(q);
        auto ta = s.upper_bound(q);
        auto tb = t.upper_bound(q);
        a2 = ta!=s.end() ? *ta : INF*INF;
        a1 = ta!=s.begin() ? *--ta : -INF*1333;
        b2 = tb!=t.end() ? *tb : INF*INF;
        b1 = tb!=t.begin() ? *--tb : -INF*1333;
        dp[0] = abs(q-a1) + abs( a1 - b1 );
        dp[1] = abs(q-a1) + abs( a1 - b2 );
        dp[2] = abs(q-a2) + abs( a2 - b1 );
        dp[3] = abs(q-a2) + abs( a2 - b2 );
        dp[4] = abs(q-b1) + abs( a1 - b1 );
        dp[5] = abs(q-b1) + abs( a2 - b1 );
        dp[6] = abs(q-b2) + abs( a1 - b2 );
        dp[7] = abs(q-b2) + abs( a2 - b2 );
        ans = INF*33333;
        Rep(i,8) ans = min( ans, dp[i] );
        printf ("%lld\n", ans);

    }



    return 0;
}



Measured memory_bytes: 10752
// haaaaaaaaaaaaard

#include<cmath>
#include<cstdio>

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

using namespace std;

int main(){
	int n,m;
	double p; scanf("%d%d%lf",&n,&m,&p);
	p/=100;

	int e[1<<14]={}; // e[S] := ( S から V\S へ出ている辺の本数 )
	rep(i,m){
		int u,v; scanf("%d%d",&u,&v); u--; v--;
		rep(S,1<<n){
			if(S&1<<u && (S&1<<v)==0) e[S]++;
			if(S&1<<v && (S&1<<u)==0) e[S]++;
		}
	}

	// dp[S] := ( V の部分集合 S が連結になる確率 )
	// ここで、S と V-S のつながり方については気にしていない
	double dp[1<<14];
	dp[0]=1;
	rep(S,1<<n) if(S!=0) {
		// S に含まれる頂点(どれでもいい)を一つ固定する
		int u0;
		rep(u,n) if(S&1<<u) u0=u;

		// S を頂点集合とみた部分グラフに制限して考える。
		//   dp[S] = ( u0 を含む連結成分が S である確率 )
		// と
		//   Σ_{T \subset S, u0 \in T} ( u0 を含む連結成分が T である確率 ) = 1
		// より、移項して dp[S] についての漸化式
		//   dp[S] = 1 - Σ_{T \subset S, u0 \in T, T!=S} ( u0 を含む連結成分が T である確率 )
		// を得る。
		// さらに
		//   ( u0 を含む連結成分が T である確率 )
		// = ( T が連結になる確率 ) * p^k
		// = dp[T] * p^k, ( k は T と S\T の間にある辺の本数 )
		// なので
		//   dp[S] = 1 - Σ_{T \subset S, u0 \in T, T!=S} dp[T] * p^k
		// となる。
		dp[S]=1;
		for(int T=(S-1)&S;T>0;T=(T-1)&S) if(T&1<<u0) {
			dp[S]-=dp[T]*pow(p,(e[T]+e[S-T]-e[S])/2);
		}
	}

	printf("%.15f\n",dp[(1<<n)-1]);

	return 0;
}

Measured memory_bytes: 952
#define _GLIBCXX_DEBUG
#include<bits/stdc++.h>
using namespace std;
typedef long long int lli;
typedef unsigned long long int ulli;
#define vec(s) vector

#define vvec(s) vector<vector
>
typedef vector<lli> vi;
typedef vector<vi> vvi;
typedef pair<lli,lli> pii;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define YN(x) cout<<(bool x?"Yes":"No")<<endl;
#define out(s) cout<<s<<endl;
#define pb(s) push_back(s);
#define sp " ";
#define INF 10000000000
#define all(s) s.begin(),s.end()
void vout(vi v){
    for(int i=0;i<v.size();i++)
    cout<<v.at(i)<<endl;
}
int main(){
    lli l,r,d,ans=0;
    cin >> l >> r>>d;
    for (int i = l; i <= r;i++){
        if(i%d==0){
            ans++;
        }
    }
    out(ans);
}

Measured memory_bytes: 3632
#include "bits/stdc++.h"


#define REP(i,n) for(int i=0;i< (n);i++)
#define REPR(i, n) for(int i = (n);i >= 0;i--)
#define FOR(i, m, n) for(int i = (m);i < (n);i++)
#define FORR(i, m, n) for(int i = (m);i >= (n);i--)
#define SORT(v, n) std::sort(v, v+n);
#define VSORT(v) std::sort(v.begin(), v.end());
#define VRSORT(v) std::sort(v.rbegin(), v.rend());
#define ll long long
#define pb(a) push_back(a)
#define ALL(obj) (obj).begin(),(obj).end()

using namespace std;

const int INF = 99999999;
const ll LINF = 9999999999999;

typedef pair<int, int> P;
typedef pair<ll, ll> LP;
int dx[4] = { 1,0,-1,0 };
int dy[4] = { 0,1,0,-1 };

int n, m, ans, a, b;
int h[100001], out[100001];

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

    for (int i = 1; i <= n; i++)
        cin >> h[i];

    for (int i = 1; i <= m; i++) {
        cin >> a >> b;

        if (h[a] >= h[b])
            out[b] = 1;

        if (h[b] >= h[a])
            out[a] = 1;
    }

    for (int i = 1; i <= n; i++)
        if (!out[i])
            ans++;

    cout << ans << endl;
}

Measured memory_bytes: 4400
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
const int mod = 1e9+7;

int main(){
    int x;
    cin >> x;
    if(x == 7 || x == 3 || x == 5) cout << "YES" << endl;
    else cout << "NO" << endl;    
}

Measured memory_bytes: 256
# -*- coding: utf-8 -*-
import sys
from sys import stdin
import math

n, k = map(int, stdin.readline().split())
w = list([int(stdin.readline().rstrip()) for i in range(n)])

def main2():
  def is_ok():
    cnt_track = w_tmp = 0
    for w_i in w:
      w_tmp += w_i
      if w_tmp > m:
        w_tmp = w_i
        cnt_track += 1
        if cnt_track >= k:
          return 0
    return 1

  r = sum(w)
  l = max(math.ceil(r/k),max(w))
  while l < r:
    m = (l + r) // 2
    # print("%d %d %d " % (l, r, m))
    if is_ok():
      r = m
    else:
      l = m + 1
  print(r)

if __name__ == '__main__':
  main2()



Measured memory_bytes: 10372
from collections import Counter

def main():
    N = int(input())
    A = list(map(int, input().split()))

    c = Counter(A)
    vals = c.keys()
    cnts = c.values()

    subs = {}
    a_sum = 0
    for v, c in zip(vals, cnts):
        subs[v] = c - 1
        a_sum += (c * (c-1)) // 2
    
    for a in A:
        print(a_sum - subs[a])


if __name__ == '__main__':
    main()

Measured memory_bytes: 32024
#include<cstdio>
#include<cstring>
#include<algorithm>
#define N 100010
#define ll long long
using namespace std;

int n, map[N][4], b[4], w1[N], w2[N], flag1[N], flag2[N], x, pos[N], s[N];
ll sum1, sum2;

inline char gc(){
	return getchar();
	static char now[1<<16], *S, *T;
	if(S==T){T=(S=now)+fread(now, 1, 1<<16, stdin); if(S==T)return EOF;}
	return *S++;
}
inline int read(){
	int x=0, f=1; char ch=gc();
	while(ch<'0'||ch>'9'){if(ch=='-')f=-1; ch=gc();}
	while(ch>='0'&&ch<='9'){x=x*10+ch-'0'; ch=gc();}
	return x*f;
}

inline void ins(int x){for(int i=x; i<=n; i+=i&(-i))s[i]++;}
inline int cs(int x){int s1=0; for(int i=x; i; i-=i&(-i))s1+=s[i]; return s1;}

int main(){
	n=read();
	for(int i=1; i<=3; i++)
		for(int j=1; j<=n; j++)map[j][i]=read();
	for(int i=1; i<=n; i++){
		for(int j=1; j<=3; j++)b[j]=map[i][j];
		if(b[1]>b[3])swap(b[1], b[3]);
		if(b[1]+1!=b[2]||b[2]+1!=b[3]){printf("No"); return 0;}
		if(b[3]%3){printf("No"); return 0;}
		x=b[3]/3; if((x^i)&1){printf("No"); return 0;}
		if(i&1){w1[(i+1)>>1]=(x+1)>>1; flag1[(i+1)>>1]=map[i][3]==b[3]?0:1;}
		else{w2[i>>1]=x>>1; flag2[i>>1]=map[i][3]==b[3]?0:1;}
	}
	sum1=0; for(int i=1; i<=(n+1)/2; i++)sum1+=flag1[i];
	sum2=0; for(int i=1; i<=n/2; i++)sum2+=flag2[i];
	for(int i=1; i<=(n+1)/2; i++)pos[w1[i]]=i; for(int i=1; i<=(n+1)/2; i++)w1[i]=pos[i];
	for(int i=1; i<=n/2; i++)pos[w2[i]]=i; for(int i=1; i<=n/2; i++)w2[i]=pos[i];
	
	memset(s, 0, sizeof(s));
	for(int i=(n+1)/2; i; i--){sum2+=cs(w1[i]-1); ins(w1[i]);}
	memset(s, 0, sizeof(s));
	for(int i=n/2; i; i--){sum1+=cs(w2[i]-1); ins(w2[i]);}
	
	if((!(sum1&1))&&(!(sum2&1)))printf("Yes"); else printf("No");
	
	return 0;
}

Measured memory_bytes: 3072
#include <iostream>
#include <cmath>
#include <vector>
#include <algorithm>
using namespace std;
#define MOD 1000000007
#define rep(i,n) for(ll i=0; i<(n); i++)
#define REP(i,a,b) for(ll i=(a); i<(b); i++)
#define RREP(i,a,b) for(ll i=(a); i>=(b); i--)
#define all(x) (x).begin(),(x).end()
using namespace std;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef pair<ll, ll> p;
typedef vector<pair<ll, ll>> vpl;

int main(){
    ll a,b; cin >> a >> b;
    ll x=0;
    x = max(a,b);
    if(x == a){
        x += max(a-1,b);
    }else{
        x += max(a,b-1);
    }
    cout << x << "\n";
}

Measured memory_bytes: 256
#include<iostream>
#include<queue>
#include<vector>
#include<algorithm>
#include<cassert>
#include<set>
#include<cassert>
using namespace std;
#define REP(i,b,n) for(int i=b;i<n;i++)
#define rep(i,n)   REP(i,0,n)
#define ALL(c)   (c).begin(),(c).end()
#define pb push_back

typedef long long ll;

bool vis[10][10];
char m[10][10];
int check[10][10];

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

bool isout(int ney,int nex,int r,int c){
  return nex==-1||ney==-1||nex==c||ney==r;
}

bool isok(int y,int x,int r,int c){
  int all=0,cnt=0;
  rep(i,4){
    int nex=x+dx[i],ney=y+dy[i];
    if (isout(ney,nex,r,c))continue;
    all++;
    if (m[ney][nex] == '0')cnt++;
  }
  if (cnt <= 1)return false;
  return true;
}

bool vis2[10][10];
void canvisitall(int r,int c,int y,int x,
		 int &tmp){
  if (vis2[y][x])return;
  vis2[y][x]=true;
  tmp--;
  rep(i,4){
    int nex=x+dx[i],ney=y+dy[i];
    if (isout(ney,nex,r,c)||
	m[ney][nex] == '1')continue;
    canvisitall(r,c,ney,nex,tmp);
  }
}

ll geta(int r,int c){
  ll ret=0;
  rep(i,r){
    rep(j,c)ret=ret*2+vis[i][j];
  }
  return ret;
}

set<ll> S;
int ini;
bool search(int r,int c,int y,int x,int cnt,
	    int sy,int sx,int py,int px){
  if (cnt==0){
    return x==sx && y == sy;
  }
  if (vis[y][x])return false;
  check[y][x]=cnt;

  int tmp=cnt+1;
  rep(i,r)rep(j,c)vis2[i][j]=vis[i][j];
  vis2[sy][sx]=false;

  canvisitall(r,c,y,x,tmp);
  if ((x!=sx||y!=sy) && tmp != 0){
    return false;
  }

  vis[y][x]=true;

  ll tmp2=geta(r,c);
  if (S.find(tmp2) != S.end()){
    vis[y][x]=false;
    return false;
  }
  S.insert(tmp2);



  rep(i,4){
    int nex=x+dx[i],ney=y+dy[i];
    if (isout(ney,nex,r,c)||
	m[ney][nex] == '1')continue;
    if (nex == px && ney == py)continue;
    if (search(r,c,ney,nex,cnt-1,sy,sx,y,x))return true;
  }
  vis[y][x]=false;
  return false;
}

main(){
  int r,c;
  while(cin>>c>>r && r){
    S.clear();
    int sx=0,sy=0;
    int cnt=0;
    bool haveans=true;
    rep(i,r){
      rep(j,c){
	cin>>m[i][j];
	if (m[i][j] == '0')sx=j,sy=i,cnt++;
	vis[i][j]=false;
      }
    }

    rep(i,r){
      rep(j,c){
	if (m[i][j]=='0'&&!isok(i,j,r,c))haveans=false;
      }
    }

    ini=cnt;
    if (ini == 1||ini == 0){
      //cout <<"Yes" << endl;
      cout <<"No" << endl;
      continue;
    }
    if (ini > 1 && haveans && search(r,c,sy,sx,cnt,sy,sx,-1,-1))
      cout << "Yes" << endl;
    else cout <<"No" << endl;
  }
  return false;
}

Measured memory_bytes: 16000
#include <bits/stdc++.h>
#define ll long long int
#define v vector<ll>
#define vv vector<v>
using namespace std;
ll MOD=1e9+7;
int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int n;
    cin>>n;
    vector<v> dp(n+1,v(n+1,1e17));
    v a(n+1,-1),prefix(n+1,0);
    for (int i=1; i<=n; i++) 
    {
        cin>>a[i];
        prefix[i]=a[i]+prefix[i-1];
        dp[i][i]=0;
    }
    for (int j=2; j<=n; j++)
    {
        for (int i=j-1; i>=1; i--)
        {
            for (int k=i; k<j; k++)
            {
                dp[i][j]=min(dp[i][j],dp[i][k]+dp[k+1][j]+prefix[j]-prefix[i-1]);
            }
        }
    }   
    cout<<dp[1][n];
	return 0;
}

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

struct edge {
    int to, cost;
};

vector<edge> G[100000];
int d[100000];
bool visited[100000];

bool dfs(int v, int c) {
    if (visited[v] && d[v] != c) return false;
    if (visited[v] && d[v] == c) return true;

    d[v] = c;
    visited[v] = true;

    for (int i = 0; i < G[v].size(); i++) {
        edge e = G[v][i];
        if (!dfs(e.to, d[v] + e.cost)) {
            return false;
        }
    }

    return true;
}

int main() {
    int N, M;
    cin >> N >> M;
    for (int i = 0; i < M; i++) {
        int L, R, D;
        cin >> L >> R >> D;
        L--;
        R--;
        G[L].push_back({R, D});
        G[R].push_back({L, -D});
    }

    for (int i = 0; i < N; i++) {
        if (!visited[i] && !dfs(i, 0)) {
            cout << "No" << endl;
            return 0;
        }
    }

    cout << "Yes" << endl;
    return 0;
}

Measured memory_bytes: 12032
#include <iostream>
#include <string>
#include <vector>
#include <deque>
#include <queue>
#include <algorithm>
#include <set>
#include <map>
#include <bitset>
#include <cmath>
#include <functional>
#define vv(a, b, c, d) vector<vector<d> >(a, vector<d>(b, c))
#define vvi vector<vector<int> >
#define vvl vector<vector<ll> >
#define vll vector<ll>
#define rep(c, a, b) for(ll c=a;c<b;c++)
#define re(c, b) for(ll c=0;c<b;c++)
#define all(obj) (obj).begin(), (obj).end()
typedef long long int ll;
typedef long double ld;
using namespace std;
int main(int argc, char const *argv[]) {
  string s;std::cin >> s;
  ll n;std::cin >> n;
  for(int i=0;i<s.size();i+=n) std::cout << s[i];
  std::cout << '\n';
}


Measured memory_bytes: 256
def div(p,q):
	deci,rest = "",[p]
	while True:
		p *= 10
		deci += str(p//q)
		p -= q*(p//q)
		rest.append(p)
		if rest[-1] == 0: return deci,rest
		if rest[-1] in rest[:-1]: return deci,rest
		
while True:
	try:
		p,q = map(int, raw_input().split())
		deci,rest = div(p,q)
		if rest[-1] == 0:
			print deci
		else:
			print deci
			print " "*rest.index(rest[-1])+"^"*(len(rest)-rest.index(rest[-1])-1)
	except:
		break

Measured memory_bytes: 4232
#include <iostream>
#include<string>
#include<algorithm>
#include<stdio.h>

using namespace std;

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

    for(int i=0; i<n; i++){
        cin>>color;

        if(color == "Y") {
            cout << "Four" << endl;
            break;
        }

        if(i == n-1){
            cout<<"Three"<<endl;
        }
    };
    return 0;
}


Measured memory_bytes: 256