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

def judge_cardgame_winner(a_player_cards_str, b_player_cards_str, c_player_cards_str):

    a_players_hand_queue = deque([ s for s in a_player_cards_str ])
    b_players_hand_queue = deque([ s for s in b_player_cards_str ])
    c_players_hand_queue = deque([ s for s in c_player_cards_str ])

    discard = a_players_hand_queue.popleft()

    while a_players_hand_queue!=[] and b_players_hand_queue!=[] and c_players_hand_queue!=[]:
        if discard=='a':
            try:
                discard = a_players_hand_queue.popleft()
            except:
                return 'A'
        if discard=='b':
            try:
                discard = b_players_hand_queue.popleft()
            except:
                return 'B'
        if discard=='c':
            try:
                discard = c_players_hand_queue.popleft()
            except:
                return 'C'


if __name__=='__main__':
    input_list = [input() for i in range(3)]
    sa, sb, sc = input_list[0], input_list[1], input_list[2]
    print(judge_cardgame_winner(sa, sb, sc))


Measured memory_bytes: 3316
#include <bits/stdc++.h>
#define IO ios::sync_with_stdio(0), cin.tie(0) 
using namespace std;
typedef long long ll;
const int maxn = 1e5 + 5;
const int inf = ~0u >> 1;
int main() {
    IO;
    ll a, b, n;
    cin >> a >> b >> n;
    ll x = min(b - 1, n);
    cout << a * x / b - a * (x / b) << endl;
    return 0;
}

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

#define vi vector<int>
#define pb push_back
#define ii pair<int, int>
#define x first
#define y second

double x[10], y[10];
vector<double> v;

double distance(int a, int b) {
	return sqrt((x[a] - x[b]) * (x[a] - x[b]) + (y[a] - y[b]) * (y[a] - y[b]));
}

int main() {
	ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
	int n;
	cin >> n;
	double mau = 1;
	for (int i = 1; i <= n; i++) {
		cin >> x[i] >> y[i];
		v.pb(i);
		mau *= i;
	}
	double sum = 0;
	do {
		for (int i = 1; i < n; i++) {
			sum += distance(v[i], v[i - 1]);
		}
	} while (next_permutation(v.begin(), v.end()));
	cout << setprecision(10) << fixed << sum / mau;
	return 0;
}

Measured memory_bytes: 256
n = int(input())
a = list(map(int,input().split()))
dp = [0] * n
dp[0] = 1000
for i in range(1, n):
  dp[i] = max(dp[i-1], dp[i-1] // a[i-1] * a[i] + dp[i-1] % a[i-1])
print(dp[-1])

Measured memory_bytes: 9128
#include<bits/stdc++.h>
	   using namespace std;
	   int main()
	   {
	   	double r,p;
	   	double const pi=acos(-1);
	   	scanf("%lf",&r);
	   	p=(2*pi*r);
	   	printf("%0.15lf\n",p);
	   	return 0;
	   	
	   }
	   


Measured memory_bytes: 3760
#include <iostream>
#include <string>
#include <vector>
#include <list>
#include <set>
#include <algorithm>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> pll;

// input
void input() {}
template <class Head, class... Tail>
void input(Head &&a, Tail &&... b)
{
    cin >> a;
    input(forward<Tail>(b)...);
}

template <class V>
void input(vector<V> &v)
{
    for_each(v.begin(), v.end(), [](auto &i) { input(i); });
}

// output
template <class V>
void output(vector<V> &v)
{
    for_each(v.begin(), v.end(), [](auto &x) { cout << x << " "; });
    cout << endl;
}

// math functions
ll mpow(ll a, ll n, ll p)
{
    ll x = 1;
    while (n > 0)
    {
        if (n & 1)
        {
            x = a * x % p;
        }
        a = a * a % p;
        n >>= 1;
    }

    return x;
}

ll mfact(ll n, ll p)
{
    ll res = 1;
    for (ll i = 2; i <= n; i++)
    {
        res = res * i % p;
    }
    return res;
}

ll mcomb(ll n, ll r, ll p)
{
    if (n == 0 && r == 0)
    {
        return 1;
    }
    if (n < r || n < 0 || r < 0)
    {
        return 0;
    }

    ll a = mfact(n, p);
    ll b = mfact(n - r, p);
    ll c = mfact(r, p);
    return (((a * mpow(b, p - 2, p)) % p) * mpow(c, p - 2, p)) % p;
}

ll gcd(ll a, ll b)
{
    if (a < b)
    {
        a ^= b;
        b ^= a;
        a ^= b;
    }
    return b ? gcd(b, a % b) : a;
}

ll lcm(ll a, ll b)
{
    return a * b / gcd(a, b);
}

int main()
{
    string S;
    input(S);

    bool res = false;
    for (int i = 0; i < S.size() - 1; i++)
    {
        if (S[i] == S[i + 1])
        {
            res = true;
            break;
        }
    }

    cout << (res ? "Bad" : "Good") << endl;
    return 0;
}

Measured memory_bytes: 256
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import permutations, combinations, product
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits

def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
MOD = 10 ** 9 + 7

N = INT()
V = LIST()
C = LIST()

V_C = []
for i in range(N):
	V_C.append(V[i]-C[i])

# print(V_C)

count= 0
for x in V_C:
	if x > 0:
		count += x

print(count)

Measured memory_bytes: 3884
N=int(input())
A = [list(map(int, input().split())) for _ in range(N)]
A.sort(key = lambda A:A[1])
star_time = 0
ans = 'Yes'
for i in range(N):
    star_time += A[i][0]
    deadline = A[i][1]
    if deadline < star_time:
        ans = 'No'
print(ans)

Measured memory_bytes: 53720
def ascan; gets.split.map(&:to_i); end

a,b = ascan

# 0..x の排他的論理和
def solve(x)
    return 0 if x <= 0
    ans = ((x+1)/2)&1
    1.upto(55) do |i|
        l = 1 << i
        l2 = 1 << (i+1)
        # p [l2, x%l2, x%l2-l+1]
        ans += ([x%l2-l+1, 0].max&1) << i
    end
    ans
end

p solve(b) ^ solve(a-1)

Measured memory_bytes: 1788
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
int main(){
    int n,x=1;
    int m=-1;
    cin >> n;
    vector<int> a(n+1);
    for(int i=1;i<=n;i++){
        cin >> a[i];
    }
    for(int i=0;i<n;i++){
        x=a[x];
        if(x==2){
            m=i+1;
            break;
        }
    }
    cout << m << endl;
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
#define INF (1<<30)
#define MOD 1000000007
#define l_ength size
using ll = long long;
using namespace std;

int main(){
	int a, b, c;
	cin >> a >> b >> c;
	if( (a*100 + b*10 + c) % 4 == 0 ){
		cout << "YES" << endl;
	} else {
		cout << "NO" << endl;
	}
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
using P = pair<ll,ll>;
constexpr ll mod = 1e9+7;
#define ALL(x) (x).begin(),(x).end()
#define REP(i,n) for(ll (i)=0;(i)<(n);(i)++)
#define REPS(i,n) for(ll (i)=1;(i)<=(n);(i)++)
#define RREP(i,n) for(ll (i)=(n-1);(i)>=0;(i)--)
#define RREPS(i,n) for(ll (i)=(n);(i)>0;(i)--)
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define F first
#define S second
#define UNIQUE(v) v.erase(unique(ALL(v)),v.end());

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

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

signed main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout<<fixed<<setprecision(12);
    string S,T;
    cin >> S >> T;
    sort(ALL(T),greater<>());
    sort(ALL(S));
    cout << (S < T ? "Yes" : "No") << "\n";
}

Measured memory_bytes: 3640
//http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=2399

#include<iostream>
#include<map>
#include<vector>
#include<algorithm>
#include<cmath>
#include<climits>
#include<ctime>
#include<cstring>
#include<numeric>

#define ALL(v) (v).begin(),(v).end()
#define REP(i,p,n) for(int i=p;i<(int)(n);++i)
#define rep(i,n) REP(i,0,n)
#define dump(a) (cerr << #a << "=" << (a) << endl)
#define DUMP(list) cout << "{ "; for(auto nth : list){ cout << nth << " "; } cout << "}" << endl;

using namespace std;

class member
{
	private:
		int id;
		bool flag;
		vector<int> privacy_list;
	public:
		member(int ID):id(ID), flag(false){}

		void set_flag(bool FLAG){
			flag = FLAG;
		}

		bool get_flag(){
			return flag;
		}

		int get_id(){
			return id;
		}

		void add(int ID){
			privacy_list.push_back(ID);
		}

		bool check_list(int ID)
		{
			bool check=false;
			rep(i,privacy_list.size()){
				if(ID == privacy_list[i]){ check=true; }
			}
			return check;
		}

		void show()
		{
			dump(id);
			dump(flag);
			DUMP(privacy_list);
		}
};

int main()
{
	int N,M;
	while(cin >> N && N)
	{
		vector<member> members;

		rep(i,N)
		{
			members.push_back(member(i+1));
			cin >> M;

			int tmp;
			rep(j,M)
			{
				cin >> tmp;
				members[i].add(tmp);
			}
		}

		

		int K;
		cin >> K;
		vector<int> leak(K);
		rep(i,K){
			cin >> leak[i];
		}	

		rep(j,N)
		{
			bool flag=true;
			rep(i,leak.size())
			{
				if(!members[j].check_list(leak[i])){
					flag = false;
				}		
			}
			members[j].set_flag(flag);
		}
	
		vector<int> ans;
		rep(i,members.size()){
			if(members[i].get_flag()){ans.push_back(members[i].get_id());}
		}

		cout << (ans.size() == 1 ? ans[0] : -1) << endl;
		
	}
	return 0;
}

Measured memory_bytes: 1272
"""
AtCoder :: Beginner Contest 173 :: Chat in a Circle
https://atcoder.jp/contests/abc173/tasks/abc173_d
"""
import sys
import heapq

def solve(players):
    """Solve puzzle."""
    players.sort(reverse=True)
    circle = []
    heapq.heappush(circle, -players[1])
    heapq.heappush(circle, -players[1])

    comfort = players[0]
    for player in players[2:]:
        spot = -heapq.heappop(circle)
        comfort += spot
        heapq.heappush(circle, -player)
        heapq.heappush(circle, -player)
    return comfort


def main():
    """Main program."""
    player_count = int(sys.stdin.readline())
    players = [int(i) for i in sys.stdin.readline().split()]
    print(solve(players))


if __name__ == '__main__':
    main()


Measured memory_bytes: 31568
#include<iostream>
int c[(int)2e5],a[(int)2e5],n,d,r,x,i;main(){std::cin>>n;for(;n--;){std::cin>>x;if(x!=d)a[r++]=x;d=x;}d=1;for(i=0;i<r;++i){x=a[i];c[x]+=d;if(c[x]>=1e9+7)c[x]-=1e9+7;d=c[x];}std::cout<<d;}

Measured memory_bytes: 1792
#include <iostream>
#include <cstdio>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <iomanip>
#include <stdlib.h>
#include <string.h>
#include <cstring>
#include <cmath>
#include <map>
#include <queue>
#include <deque>
#include <stack>
#include <set>
#include <stdio.h>
#include <tuple>
#include <bitset>
#include <cfloat>
#include <fstream>
#include <limits.h>
#include <list>
#include <math.h>
#include <random>
#include <unordered_map>
#include <unordered_set>
#include <bitset>
#include <numeric>
#include <utility>
#include <sstream>

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

using namespace std;
#define int long long
#define ll long long
#define rep(i, n) for (ll i = 0; i < (n); i++)
#define FOR(i,a,b) for(ll i=(a);i<(b);i++)
#define FORR(i,a,b)for(ll i=(a);i<=(b);i++)
#define repr(i,n) for(ll i=n;i>=0;i--)
#define P pair<ll, ll>
#define sz(x) (ll)x.size()
#define ALL(x) (x).begin(),(x).end()
#define ALLR(x) (x).rbegin(),(x).rend()
#define VE vector<ll>
#define COUT(x) cout<<(x)<<endl
#define MA map<ll,ll>
#define SE set<ll>
#define PQ priority_queue<ll>
#define PQR priority_queue<ll,VE,greater<ll>>
#define COUT(x) cout<<(x)<<endl
#define YES(n) cout << ((n) ? "YES" : "NO"  ) << endl
#define Yes(n) cout << ((n) ? "Yes" : "No"  ) << endl
#define EPS (1e-10)
ll gcd(ll a, ll b) {
	if (a < b)swap(a, b);
	if (b == 0) return a;
	unsigned r;
	while ((r = a % b)) {
		a = b;
		b = r;
	}
	return b;
}
ll lcm(ll a, ll b) {
	ll g = gcd(a, b);
	return a / g * b;
}
bool prime(ll n) {
	for (ll i = 2; i <= sqrt(n); i++) {
		if (n%i == 0)return false;
	}
	return n != 1;
}
map<ll, ll> prime_factor(ll n) {
	map<ll, ll> ret;
	for (ll i = 2; i * i <= n; i++) {
		while (n % i == 0) {
			ret[i]++;
			n /= i;
		}
	}
	if (n != 1) ret[n] = 1;
	return ret;
}

const long long MOD = 1000000007;
//const long long MOD = 998244353;
const long long INF = 1LL << 60;



const long double PI = 3.14159265359;
const int MAX_N = 100010;


signed main() {
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	int sx, sy, tx, ty;
	cin >> sx >> sy >> tx >> ty;
	int dx = tx - sx, dy = ty - sy;
	rep(i, dy) {
		cout << "U";
	}
	rep(i, dx) {
		cout << "R";
	}
	rep(i, dy) {
		cout << "D";
	}
	rep(i, dx) {
		cout << "L";
	}
	cout << "L";
	dx++; dy++;
	rep(i, dy) {
		cout << "U";
	}
	rep(i, dx) {
		cout << "R";
	}
	cout << "D";
	cout << "R";
	rep(i, dy) {
		cout << "D";
	}
	rep(i, dx) {
		cout << "L";
	}
	cout << "U";
	return 0;
}

Measured memory_bytes: 384
#include<stdio.h>
int main() {
	int A, B, C;
	int i=0;//回数計測用
	int Max,Mix, Min;//大きさ比べるよう

	scanf("%d %d %d", &A, &B, &C);

	Max = (A > B) ? ((A > C) ? A : C) : ((B > C) ? B : C);//最大値代入
	Mix = (A > B) ? ((C > A) ? A : (B > C) ? B : C) : ((C > B) ? B : (A > C) ? A : C);//中間値
	Min = (A < B) ? ((A < C) ? A : C) : ((B < C) ? B : C);//最小値

	i += Max - Mix;
	i += (Mix - Min) / 2;
	if( (Mix - Min) % 2){
		i += 2;
	}

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

	return 0;
}

Measured memory_bytes: 128
N, K = map(int, input().split())

okashi_total = [0 for x in range(N)]

for k in range(K):
    d = int(input())
    okashi_d = list(map(int, input().split()))
    
    for i in okashi_d:
        okashi_total[i-1] += 1
        
print(okashi_total.count(0))

Measured memory_bytes: 9192
def listseki(A,start,end):
    ans=A[end]/A[start-1]
    return ans
N,K=map(int,input().split())
A=list(map(int,input().split()))
for i in range(1,N-K+1):
    nowseki=listseki(A,i,i+K-1)
    if nowseki>1:
        print("Yes")
    else:
        print("No")

Measured memory_bytes: 31620
import java.util.*;
import java.math.RoundingMode;
import java.math.BigDecimal;
 
 
 
public class Main{
	 public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int m = sc.nextInt();
		int a[] = new int[n];
		for(int i = 0; i < n; i++) {
			a[i] = sc.nextInt();
		}
		int bc[][] = new int[m][2];
		for(int i = 0; i < m; i++) {
			bc[i][0] = sc.nextInt();
			bc[i][1] = sc.nextInt();
		}
		Arrays.sort(a);
		Arrays.sort(bc, (ab, b)->Integer.compare(ab[1], b[1]));
		int now = 0;
		for(int i = m-1; i >= 0; i--) {
			for(int j = now; j < n; j++) {
				if(a[j]<bc[i][1]){
					a[j] = bc[i][1];
					bc[i][0]--;
					now++;
				}
				if(bc[i][0]<1) {
					break;
				}
			}
			if(bc[i][0]>0) {
				break;
			}
		}
		long ans = 0;
		for(int i = 0; i < n; i++) {
			ans+=a[i];
		}
		System.out.println(ans);
	 }
}

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

int main(){
    int n,x_id,y_id;
    double min;
    vector<double> v;
    cin>>n;
    v.resize(n);
    for(int i=0; i<n; i++){
        cin>>v[i];
    }

    while(v.size()>1){
        min=2000;
        for(int i=0; i<v.size()-1; i++){
            for(int j =i+1; j<v.size(); j++){
                if(min>v[i]+v[j]){
                    x_id=i;
                    y_id=j;
                    min=v[i]+v[j];
                }
            }
        }
        /*
        for(auto a: v){
            cout<<a<<" ";
        }cout<<endl;
       
        cout<<min/2.0<<endl;
        */
        v.push_back(min/2.0);

        swap(v[y_id],v[v.size()-2]);
        swap(v[x_id],v[v.size()-1]);

        v.pop_back();
        v.pop_back();

    }
    cout<<v[0]<<endl;
    return 0;
}

Measured memory_bytes: 256
# N, K = map(int, input().split())
S = input()
K = int(input())

if len(S) == 1:
    print(K // 2)
    exit(0)

# first one
pp = '#'
res1 = 0
for s in S:
    if pp == s:
        res1 += 1
        pp = '#'
    else:
        pp = s

if K >= 2:
    S = S + S
else:
    print(res1)
    exit(0)

# pp = S[-1] or '#'
res2 = 0
for s in S:
    if pp == s:
        res2 += 1
        pp = '#'
    else:
        pp = s

print(res2*(K-1)//2 + res1)


Measured memory_bytes: 3064
// Original: https://github.com/tanakh/competitive-rs
#[allow(unused_macros)]
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

#[allow(unused_macros)]
macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

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

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

#[allow(unused_macros)]
macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

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

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

    ($next:expr, bytes) => {
        read_value!($next, String).into_bytes()
    };

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

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

#[allow(unused_imports)]
use std::cmp::{max, min};
#[allow(unused_imports)]
use std::collections::HashMap;

fn main() {
    input!(r: usize, d: usize, x: usize);

    let mut ans = x;
    for _ in 0..10 {
        ans = ans * r - d;
        println!("{}", ans);
    }
}


Measured memory_bytes: 4352
#include <iostream>
#include <math.h>

using namespace std;

int main(){
  int N,L;
  int azi_yotei = 0;
  int azi[201];            //iのリンゴを抜いたパイの味を格納
  int sa[201];             //aziともともとのパイの味の差の絶対値を格納
  int min = 100000;        //sa配列の要素で最小のもの
  int num;                 //minになるようなi

  cin >> N >> L;
  
//作る予定のパイの味を求める
  for(int i = 1;i <= N;i++){
    azi_yotei += L + i - 1;
  }

  //iのリンゴを抜いたパイの味をそれぞれ求めて、配列に格納
  for(int i = 1;i <= N;i++){
    azi[i] = azi_yotei - (L + i-1);
  }

  for(int i = 1;i <= N;i++){
    sa[i] = abs(azi_yotei - azi[i]);
    if(sa[i] < min){
      min = sa[i];
      num = i;
    }
  }
  //でばっく
  //cout << azi_yotei << " " << min << " " << num << "\n";
  //for(int i = 1;i <= N;i++){
    //cout << i << " " << sa[i] << "\n";
    //cout << i << " " << azi[i] << "\n";
  //}
  cout << azi[num];
}

Measured memory_bytes: 256
#include <iostream>
#include <stdio.h>
#include <algorithm>
#include <vector>
#include <queue>
#include <numeric>
#include <string>
#include <string.h>
#include <map>
#include <set>
#include <functional>
#include <complex>
#include <stack>
#include <tuple>
#include <array>
#include <ctype.h> // isdigit
#include <cassert>
using namespace std;

int main(){
    
  int n, m, a;
  while(cin >> n >> m >> a, n|m|a){
    vector<pair<int, pair<int, int>>> input;
    for(int i=0; i<m; i++){
      int h, p, q; cin >> h >> p >> q;
      input.push_back({h,{p, q}});
    }
    sort(input.rbegin(), input.rend());
    for(int i=0; i<m; i++){
      if(input[i].second.first == a)
        a = input[i].second.second;
      else if(input[i].second.second == a)
        a = input[i].second.first;
    }
    cout << a << endl;
  }
  return 0;
}

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

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

    unsigned long long d[5] = {0};

    for (int i=0;i<N;i++) {
        string s;
        cin >> s;
        if (s[0]=='M') d[0]++;
        if (s[0]=='A') d[1]++;
        if (s[0]=='R') d[2]++;
        if (s[0]=='C') d[3]++;
        if (s[0]=='H') d[4]++;
    }

    unsigned long long sum = 0;
    for (int i=0;i<3;i++) {
        for (int j=i+1;j<4;j++) {
            for (int k=j+1;k<5;k++) {
                sum += d[i] * d[j] * d[k];
            }
        }
    }

    cout << sum << endl;

    return 0;
}


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

int main() {
    int n; cin >> n;
    while (n != 0) {
        int a[n] = {}; for (int i = 0; i < n; ++i) cin >> a[i];
        
        int min_diff = 1000000;
        for (int first = 0; first < n; ++first) {
            for (int second = first + 1; second < n; ++second) {
                int diff = abs(a[first] - a[second]);
                min_diff = min(min_diff, diff);
            }
        }
        cout << min_diff << endl;
        
        cin >> n;
    }
    return 0;
}


Measured memory_bytes: 3088
///cREATED bY BERNARB.01
#include<bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
typedef tree<int,null_type,less<int>,rb_tree_tag, tree_order_statistics_node_update> indexed_set;
typedef priority_queue<int,vector<int>,greater<int>> pqil;
typedef priority_queue<int> pqig;
typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef pair<int, int> pii;
typedef pair<int, pii> piii;
typedef priority_queue<pii> pqiig;
typedef vector<pii> vii;
typedef vector<piii> viii;
typedef vector<vi> vvi;
typedef vector<vii> vvii;
typedef map<int, int> mii;
#define mid ((l+r)/2)
#define PB push_back
#define PP pop_back
#define PF push_front
#define DF pop_front
#define F first
#define S second
#define MP make_pair
#define C continue
#define B break
#define R return
#define sz(v) (int)(v).size()
#define len(s) (int)(s).length()
#define all(a) (a).begin(), (a).end()
#define rall(a) (a).rbegin(), (a).rend()
#define clr(arr, x) memset((arr), (x), sizeof (arr))
#define loop(n) for(int i=0; i<(n); i++)
#define lop(a, n) for(int i=(a); i<(n); i++)
#define jloop(n) for(ll j=0; j<(n); j++)
#define kloop(n) for(ll k=0; k<(n); k++)
#define gloop(n) for(ll g=0; g<(n); g++)
#define rloop(n) for(ll i=(n)-1; i>=0; i--)
#define sgm(y) (((y)*((y)+1))/2)
const ll INF = 2e17+423;
const ll mod = 1e9+7; //998244353;
const ld pi = acos(-1.0);
const ld cmpf = 1e-9;
//__int128_t
//      -ASCII-
//a -> z | A -> Z | 0 -> 9
//97 122 | 65  90 | 48  57
#define endl '\n'
ll po(ll,ll);

























int main() {
    ios::sync_with_stdio(0);
    cin.tie(0);
    int n ;
    cin >> n;
    string s, t;
    cin >>t >> s;
    loop(n) cout << t[i] << s[i];
    R 0;
}
/*

*/




























































ll po(ll x, ll n){
  if(n==0) R 1;
  ll y = po(x, n/2);
  y = ((y)*(y));
  if(n%2) y = (y*(x));
  R y;
}


Measured memory_bytes: 256
#include <iostream>

using namespace std;

int main() {
  int r, c;
  cin >> r >> c;
  int as[r + 1][c + 1];
  for (int i = 0; i <= r; i++) {
    for (int j = 0; j <= c; j++) {
      as[i][j] = 0;
    }
  }

  for (int i = 0; i < r; i++) {
    int sum = 0;
    for (int j = 0; j < c; j++) {
      int val;
      cin >> val;
      as[i][j] = val;
      as[i][c] += val;
      as[r][j] += val;
      as[r][c] += val;
    }
  }

  for (int i = 0; i < r + 1; i++) {
    cout << as[i][0];
    for (int j = 1; j < c + 1; j++) {
      cout << " " << as[i][j];
    }
    cout << endl;
  }
}


Measured memory_bytes: 3108
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define l long
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define fi first
#define se second
#define M1 1000000007
#define M2 998244353

#define fl(i,a,b)  for(ll i=a;i<b;i++)
#define ifl(i,a,b) for(ll i=b-1;i>=a;i--)
#define f(i,n)     for(ll i=0;i<n;i++)
#define bf(i,n)    for(ll i=n-1;i>=0;i++)


#define p0(a) cout << a << " "
#define p1(a) cout << a << endl
#define p2(a, b) cout << a << " " << b << endl
#define p3(a, b, c) cout << a << " " << b << " " << c << endl
#define p4(a, b, c, d) cout << a << " " << b << " " << c << " " << d << endl

#define bn "\n"

//------------------------------------------------------------------------ 
// #define V(a) vector<a>
// #define vt() vector< tuple < ll ,ll ,ll > > ;
// #define vector< ll ,ll > pv;
// vector< pair <ll,ll> > vect;


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

ll modI(ll a,ll m);
ll gcd(ll a,ll b);
ll powM(ll x,ll y,ll m);
ll swap(ll a,ll b);


ll gcd(ll x,ll y)
{
    if(x==0) return y;
    return gcd(y%x,x);
}

ll powM(ll x,ll y,ll m)
{
    ll ans=1,r=1;
    x%=m;
    while(r>0&&r<=y)
    {
        if(r&y)
        {
            ans*=x;
            ans%=m;
        }
        r<<=1;
        x*=x;
        x%=m;
    }
    return ans;
}
 
ll modI(ll a, ll m)
{
    ll m0=m,y=0,x=1;
    if(m==1) return 0;
    while(a>1)
    {
        ll q=a/m;
        ll t=m;
        m=a%m;
        a=t;
        t=y;
        y=x-q*y;
        x=t;
    }
    if(x<0) x+=m0;
    return x;
}

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

// variable = Expression1 ? Expression2 : Expression3
// max = (n1 > n2) ? n1 : n2; 
// (n>m) ? cout<<"True"<<endl:cout<<"false"<<endl ;

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

// ll n;cin>>n;ll a[n];for(ll i=0;i<n;i++)cin>>a[i];    
// for(ll i=0;i<n;i++)cout<<a[i];
// ll a,b;cin>>a>>b;   


int main() {
	
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(0);
	ll tt=1;
   // cin>>tt;
	while(tt--)
	{
	  ll num,k; cin>>num>>k;
	ll a[num+1];
	fl(i,1,num+1) cin>>a[i];
	
	bool vissited[num+1] = {0};
	vector <ll> vec;
	ll index = a[1];
	while(!vissited[index])
	{
	    vissited[index] = 1;
	    vec.pb(index);
	    index = a[index];
	}

	ll len = vec.size();
	ll key = 0;
	while(vec[key]!=index) key++;

	k--;
	bool okn=0;
	if(k<key)
	okn=1;
	
	if(okn)
	{ 
	   
	   p1(vec[k]);
	    return 0; 
	    
	}
	bool okt=0;
	if(key==0)
	okt=1;
	if(okt)
	{ 
	  
	    p1(vec[k%len]);
	return 0; 
	    
	}
	
	k -= key;
	k %= (len-key);
	p1(vec[k+key]);

	
	
	   
	    
	}
	
	return 0;
}


Measured memory_bytes: 7084
#include<bits/stdc++.h>
#define ll long long
using namespace std;
ll ans,x;
int n,num[15];
void dfs(int pos,ll sum)
{
	if(pos==n+1) {ans+=sum;return;}
	ll tmp=0;
	for(int i=pos;i<=n;i++)
	    tmp=tmp*10+num[i],dfs(i+1,sum+tmp);
}
int main(){
	cin>>x;
	while(x) num[++n]=x%10,x/=10;
	reverse(num+1,num+n+1);
	dfs(1,0);
	cout<<ans;
	return 0;         
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
//char all[15][15];
//int vis[15][15];
int n,wanted,mini;
int a[15][105];
int sum[15];
int used[15];
void dfs(int num,int tot,int flag,int SUM,int i)
{
    if(SUM>=wanted)
    {
        if(tot<mini)
            mini=tot;
        return;
    }

    if(i>=a[num][0]) return;
    if(num<1) return;
    if(tot>=mini) return;
    if(i==0)
    {dfs(num-1,tot+a[num][0],flag,SUM+sum[num],0);
    dfs(num-1,tot,flag,SUM,0);
    }
    if(flag==0)
    dfs(num,tot+1,1,SUM+num*100,1);
    if(i>0)
    {
    dfs(num,tot+1,1,SUM+num*100,i+1);
    dfs(num-1,tot,1,SUM,0);
    }
}
int main()
{
    int i;
    scanf("%d%d",&n,&wanted);
    for(i=1;i<=n;i++)
    {
        scanf("%d%d",&a[i][0],&a[i][1]);
    }
    mini=INT_MAX;
    for(i=1;i<=n;i++)
    {
        sum[i]=a[i][0]*i*100+a[i][1];
    }

    dfs(n,0,0,0,0);
    printf("%d\n",mini);
    return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
#include<string.h>
int main(void)
{
	int i,x;
	char str[21];
	scanf("%s",str);
		x=strlen(str);
		for(i=x-1;i>=0;i--){
			printf("%c",str[i]);
		}
		printf("\n");
	return 0;
}	

Measured memory_bytes: 928
#include<iostream>
#include<vector>
#include<map>
#include<algorithm>
#include<math.h>
#include<string>
#include <iomanip>
#include<deque>

typedef long long ll;
typedef unsigned long long ull;
typedef int itn;
const ll LINF = 1e18;
const int INF = 1e8;

using namespace std;


//マクロ定義
#define vvint(vec,n,m,l) vector<vector<int>> vec(n, vector<int>(m,l));	// lで初期化
#define vvll(vec,n,m,l) vector<vector<ll>> vec(n,vector<ll>(m,l));
#define vint vector<int>
#define pint pair<int,int>
#define rep(i,a) for(int i=0;i<(a);i++)
#define all(x) (x).begin(),(x).end()
#define debug system("pause")				//デバッグ用


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

	int a, b;
	cin >> a >> b;
	int ans = 0;

	if (a > b)
	{
		ans += a + a - 1;
	}
	else if (b > a)
	{
		ans += b + b - 1;
	}
	else
	{
		ans += 2 * a;
	}

	cout << ans << endl;

}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define int long long
using namespace std;
const int INF = 1e9 + 7, MOD = 1e9 + 7;
const long long LINF = 1e18;
const int dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};
signed main() {
	int n;
	cin >> n;
	int a[n];
	int MCnt = 0, MVal = INF;
	long sum = 0;
	for (int i = 0; i < n; i++) {
		cin >> a[i];
		MCnt += (a[i] < 0);
		MVal = min(MVal, abs(a[i]));
		sum += abs(a[i]);
	}
	long ans;
	if (MCnt & 1) ans = sum - 2 * MVal;
	else ans = sum;
	cout << ans << endl;
	return 0;
}

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

#define ll long long int
#define inv(name,Type,size) vector<Type> name(size);for(int index=0;index<size;index++) cin>>name[index];
#define F(a,n,i) for(int i=a;i<n;i++)
#define pb push_back
#define endl "\n"
#define mod 1000000007
#define modpro 99824435

const int d8i[8]={-1,0,1,0,-1,1,1,-1},d8j[8]={0,1,0,-1,1,1,-1,-1};


void solve(){
	int n;
	cin>>n;
	inv(a,ll,n);
	ll wall=1000;
	ll start = a[0];
	F(0,n-1,i){
		if(a[i]>a[i+1]){
			ll twall = wall - ((wall/start) * start);
			wall = twall + (wall/start)*a[i];
			start = a[i+1];
		}
		//cout<<start<<endl;
	}
	if(start < a[n-1]){
		ll twall = wall - ((wall/start) * start);
		wall = twall + (wall/start)*a[n-1];
	}
	cout<<wall;
}

int main()
{
  ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
  
  //int t;cin>>t;while(t--) solve(),cout<<endl;
  solve();
}



Measured memory_bytes: 3652
//g++ -std=gnu++14 a.cpp
//#include <bits/stdc++.h>

#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <iostream>
#include <istream>
#include <iterator>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
#include <tuple>
#include <iomanip>
#include <random>
#include <math.h>

using namespace std;

#define ll long long
#define rep(i, n) for(ll i = 0; i < (n); i++)
ll MOD = 1e9 + 7;
int INF = 1 << 30;
ll INFL = 1LL << 60;

int main(){
  string s,t;
  cin >> s >> t;
  int a,b;
  cin >> a >> b;
  string u;
  cin >> u;
  if(u == s) cout << a-1 << " " << b << endl;
  else cout << a << " " << b-1 << endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
const int N = 100010;
int n, x = -1, y = -1, z = -1, p, q, r;
int main(){
	scanf("%d", &n);
	if(n < 3){puts("Yes");return 0;}
	for(int i = 1; i <= n; ++ i){
		int a; scanf("%d", &a);
		if(a == x)p ++;
		else if(a == y)q ++;
		else if(a == z)r ++;
		else if(x == -1)x = a, p = 1;
		else if(y == -1)y = a, q = 1;
		else if(z == -1)z = a, r = 1;
		else{puts("No"); return 0;}
	}
	if(z == -1){
		if(y == -1){
			if(x)puts("No");
			else puts("Yes");
			return 0;
		}
		if(q == p / 2 && p % 2 == 0 && y == 0){
			puts("Yes");
			return 0;
		}
		if(p == q / 2 && q % 2 == 0 && x == 0){
			puts("Yes");
			return 0;
		}
		puts("No");
		return 0;
	}
	if(p != q || q != r){puts("No"); return 0;}
	if(x^y^z){puts("No"); return 0;}
	puts("Yes");
	return 0;
}

Measured memory_bytes: 256
S = input()

S_c, T_c = 0, 0

# TSTTSS -> 4
ans = 0
for ch in S:
  if ch == "T" and S_c > 0:
    S_c -= 1
  elif ch == "T" and S_c == 0:
    ans += 2
  else:
    S_c += 1
    
print(ans)

Measured memory_bytes: 3500
#include <bits/stdc++.h>
using namespace std;
 
#define mp make_pair
#define pb push_back
#define F first
#define S second
#define boost ios::sync_with_stdio(false);cin.tie(NULL)
 
typedef long long ll;
typedef pair<int, int> ii;
typedef pair<ll,ll> pll;
 
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<bool> vb;
typedef vector<ii> vii;
typedef vector<vi> vvi;
 
inline ll max_(ll a, ll b) { return (a>b)?a:b; }
inline ll min_(ll a, ll b) { return (a<b)?a:b; }

bool cmpfunc(pair<double,ll> &a, pair<double,ll> &b)
{
	return (1.0*a.S/a.F)<(1.0*b.S/b.F);
}
 
int main() {
	boost;
	if(fopen("inp.txt", "r")){
	  freopen("inp.txt", "r", stdin);
	  freopen("outp.txt", "w", stdout);
    }
 
    pair<double,ll> p[4];
    ll i;

    cin>>p[0].S>>p[1].S>>p[2].S>>p[3].S;
    p[0].F=0.25,p[1].F=0.5,p[2].F=1.0,p[3].F=2.0;

    sort(p,p+4,cmpfunc);

    double n;
    cin>>n;

    ll cost=0;
    for (i=0;i<4 && n>0;i++) {
		ll q=n/p[i].F;
		n-=q*p[i].F;
		cost+=(q*p[i].S);
    }

    cout<<cost<<endl;

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
//#include <boost/multiprecision/cpp_int.hpp>
//namespace mp = boost::multiprecision;

using namespace std;

const double PI = 3.14159265358979323846;
typedef long long ll;
const double EPS = 1e-9;
#define rep(i, n) for (int i = 0; i < (n); ++i)
//#define rep(i, n) for (ll i = 0; i < (n); ++i)
typedef pair<ll, ll> P;
const ll INF = 10e17;
#define cmin(x, y) x = min(x, y)
#define cmax(x, y) x = max(x, y)
#define ret() return 0;

double equal(double a, double b) {
    return fabs(a - b) < DBL_EPSILON;
}

std::istream &operator>>(std::istream &in, set<int> &o) {
    int a;
    in >> a;
    o.insert(a);
    return in;
}

std::istream &operator>>(std::istream &in, queue<int> &o) {
    ll a;
    in >> a;
    o.push(a);
    return in;
}

bool contain(set<int> &s, int a) { return s.find(a) != s.end(); }

//ofstream outfile("log.txt");
//outfile << setw(6) << setfill('0') << prefecture << setw(6) << setfill('0') << rank << endl;
// std::cout << std::bitset<8>(9);
//const ll mod = 1e10;

typedef priority_queue<ll, vector<ll>, greater<ll> > PQ_ASK;

int main() {
    ll a, b, c, d;
    cin >> a >> b >> c >> d;
    int ans = max(a * b, c * d);
    cout << ans << endl;
}


Measured memory_bytes: 3604
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Comparator;
import java.util.PriorityQueue;


public class Main {

	/**
	 * @param args
	 * @throws IOException 
	 */
	public static void main(String[] args) throws IOException {
		// TODO Auto-generated method stub
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		
		int q = Integer.parseInt(br.readLine());
		
		for(int i = 0; i < q; i++){
			String[] tmpArray = br.readLine().split(" ");
			int a = Integer.parseInt(tmpArray[0]);
			int b = Integer.parseInt(tmpArray[1]);
			
			if(a > b){
				int tmp = a;
				a = b;
				b = tmp;
			}
			
			long result = 0;
			if(a == b){
				result = 2*a - 2;
			}
			else if(a + 1 == b){
				result = 2*a - 2;
			}
			else {
				long c = (long)Math.sqrt((long)a*b);
//				System.out.println("c = "+c);
				if(c*c == (long)a*b){
					c--;
				}
				
				if(c*(c+1) >= (long)a*b){
					result = 2*c - 2;
				}
				else {
					result = 2*c - 1;
				}
			}
			System.out.println(result);
		}
		
	}

}

Measured memory_bytes: 21460
use whiteread::parse_line;

fn main() {
    let n: usize = parse_line().unwrap();
    let b: Vec<u32> = parse_line().unwrap();
    let mut a: Vec<u32> = vec![0; n];
    a[0] = b[0];
    a[n - 1] = b[n - 2];

    if n > 2 {
        for i in 1..n - 1 {
            a[i] = b[i - 1].min(b[i]);
        }
    }
    println!("{}", a.iter().sum::<u32>());
}


Measured memory_bytes: 2112
#include <iostream>
#include <string>
using namespace std;
int main(){
	int max = -1,j;
	string str,search;
	cin >> str >> search;
	for(int i=0,n=str.length() - search.length();i <= n;i++){
		for(j=0;j<search.length();j++){
			if(str[i+j] != '?' && str[i+j] != search[j]){
				break;
			}
		}
		if(j >= search.length()){
			if(max < i)
				max = i;
		}
	}
	if(max != -1){
		for(int i=0;i<str.length();i++){
			if(i == max){
				for(int j=0;j<search.length();j++,i++){
					cout << search[j];
				}
				--i;
			}else if(str[i] == '?'){
				cout << "a";
			}
			else{
				cout << str[i];
			}
		}
		cout << endl;
	}else{
		cout << "UNRESTORABLE" << endl;
	}
}

Measured memory_bytes: 256
//I am so vegetable
#include <bits/stdc++.h>
#define _for(i,a,b) for(int i = (a);i<(b);++i)
#define _defor(i,a,b) for((i) = (a);(i)<(b);++i)
#define _rfor(i,a,b) for(int i = (a);i>(b);--i)
#define _sfor(p,st) for(auto p:st)
//#define _LOCAL_
using namespace std;
typedef long long ll;
const int INF = 0x3f3f3f3f;
const ll maxn = 2e5 + 5;
const int MOD = 1e9 + 7;
const double exps = 1e-6;
#ifdef _LOCAL_
void deprint() {
	ofstream cout("E:\\acm dream\\debug.txt");
	return;
}
#endif
struct xy {
	int x, y;
	bool operator < (const xy& p) { return y < p.y; }
}a[maxn];
int main() {
#ifdef _LOCAL_
	ifstream cin("E:\\acm dream\\in.txt");
	ofstream cout("E:\\acm dream\\out.txt");
#endif
	//srand((unsigned)time(nullptr));
	ios::sync_with_stdio(false), cin.tie(0), cout.tie(0);
	string s;
	int n, t, q, pos, l, r;
	while (cin >> n >> s) {
		char ch;
		cin >> t;
		set<int>p[26];
		_for(i, 0, n)p[s[i] - 'a'].insert(i);
		while (t--) {
			cin >> q;
			if (q == 1) {
				cin >> pos >> ch;
				--pos;
				p[s[pos] - 'a'].erase(pos);
				p[ch - 'a'].insert(pos);
				s[pos] = ch;
			}
			else {
				int ans = 0;
				cin >> l >> r; --l, --r;
				_for(i, 0, 26) {
					auto it = p[i].lower_bound(l);
					if (it != p[i].end()&&*it <= r)ans++;
				}
				cout << ans << endl;
			}
		}
	}
	return 0;
}

Measured memory_bytes: 24220
#include<stdio.h>
#include<string.h>

int main(void){

    char S[101];
    int i,ans=0;

    scanf("%s",S);

    for(i = 0;i < strlen(S);i++){
        if(i % 2 != 0){
            if(S[i] == 'R'){
                printf("No\n");
                return 0;
            }
        }else{
            if(S[i] == 'L'){
                printf("No\n");
                return 0;
            }
        }
    }

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

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

using namespace std;

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

int N;
int a[200010];

int main() {
  cin >> N;
  REP(i,N) scanf("%d", &a[i]);

  int x = 0, y = 0, cnt = 0;
  REP(i,N) if (x <= a[i]) x = a[i];
  REP(i,N) if (x == a[i]) cnt++;
  if (1 < cnt) {
    y = x;
  } else {
    REP(i,N) if (y <= a[i] && x != a[i]) y = a[i];
  }
  REP(i,N) {
    if (a[i] == x) {
      cout << y << endl;
    } else {
      cout << x << endl;
    }
  }

  return 0;
}


Measured memory_bytes: 2432
#include <iostream>
#include <string>

using namespace std;
int main()
{
    int a,b,c,k;
    cin>>a>>b>>c>>k;
    if (k-a>0)
    {


        if (k-a<=b)
        {
            cout<<a<<endl;
        }
        else
            cout<<a-(k-a-b)<<endl;
    }
    else
        cout<<k<<endl;



    return 0;
}


Measured memory_bytes: 3580
#include <bits/stdc++.h>
using namespace std;
int main(void){
int K;
  
int vec1[] = { 1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51};
cin >> K ;
  cout << vec1[K-1] << endl;
 
 return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ALL(x) x.begin(),x.end()
#define rep(i,n) for(int i=0;i<n;i++)
#define debug(v) cout<<#v<<":";for(auto x:v){cout<<x<<' ';}cout<<endl; 
#define INF 1000000000
#define mod 1000000007
using ll=long long;
const ll LINF = 1001002003004005006ll;
int dx[]={1,0,-1,0};
int dy[]={0,1,0,-1};
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }

int n,k;
vector<ll> h;

inline ll cost(int a,int b){
    return (max(0ll,h[b]-h[a]));
}

signed main(){
    cin.tie(0);
    ios::sync_with_stdio(0);
    
    cin>>n>>k;
    h.resize(n+1);
    rep(i,n) cin>>h[i+1];
    h[0]=0;

    if(k>=n){
        cout<<0<<endl;
        return 0;
    }

    ll dp[n+1][k+1];
    rep(i,n+1){
        rep(j,k+1){
            dp[i][j]=INF*100ll;
        }
    }
    dp[0][0]=0;

    rep(j,k+1){
        rep(i,n){
            for(int l=0;l<=k and j-l>=0 and i-l>=0;l++){
                chmin(dp[i+1][j],dp[i-l][j-l]+cost(i-l,i+1));
            }
        }
    }
    // rep(j,k+1){
    //     rep(i,n+1){
    //         cout<<dp[i][j]<<"  ";
    //     }cout<<endl;
    // }
    ll ans=LINF;
    rep(i,k+1){
        chmin(ans,dp[n-i][k-i]);
    }
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 896
use std::io::stdin;
use std::vec::Vec;

mod utils {
    use std::io::BufRead;
    use std::str::{self, FromStr};

    pub struct StdinReader<R: BufRead> {
        reader: R,
        buf: Vec<u8>,
    }

    impl<R: BufRead> StdinReader<R> {
        pub fn new(reader: R) -> StdinReader<R> {
            StdinReader {
                reader: reader,
                buf: Vec::new(),
            }
        }

        #[allow(unused)]
        #[inline]
        pub fn reads<T: FromStr>(&mut self) -> T {
            self.read_until(b' ')
        }

        #[allow(unused)]
        #[inline]
        pub fn readl<T: FromStr>(&mut self) -> T {
            self.read_until(b'\n')
        }

        #[allow(unused)]
        #[inline]
        pub fn read_vec<T: FromStr>(&mut self) -> Vec<T> {
            return self.read_until::<String>(b'\n').trim().split_whitespace().map(|c| c.parse().ok().unwrap()).collect();
        }

        #[inline]
        pub fn read_until<T: FromStr>(&mut self, delim: u8) -> T {
            loop {
                self.buf.clear();
                let len = self.reader
                    .read_until(delim, &mut self.buf)
                    .expect("failed reading bytes");
                match len {
                    0 => panic!("early eof"),
                    1 if self.buf[0] == delim => (),
                    _ => {
                        if self.buf[len - 1] == delim {
                            self.buf.truncate(len - 1);
                        }
                        break;
                    }
                }
            }

            let elem = unsafe { str::from_utf8_unchecked(&self.buf) };
            elem.parse().unwrap_or_else(|_| panic!(format!("failed parsing: {}", elem)))
         }
    }
}


fn main(){
    let stdin = stdin();
    let mut r = utils::StdinReader::new(stdin.lock());
    let n:usize = r.readl();
    let h_s:Vec<i64> = r.read_vec();

    let mut dp = vec![std::u64::MAX;n];
    dp[0] = 0;
    dp[1] = (h_s[1] - h_s[0]).abs() as u64;

    for i in 2..n {
        if( (dp[i - 2]) + ((h_s[i] - h_s[i - 2]).abs() as u64)  ) < ( (dp[i - 1]) + ((h_s[i] - h_s[i - 1]).abs() as u64)  ) {
            dp[i] = (dp[i - 2]) + ((h_s[i] - h_s[i - 2]).abs() as u64);
        }else{
            dp[i] = ( (dp[i - 1]) + ((h_s[i] - h_s[i - 1]).abs() as u64)  );
        }
    }


    println!("{}", dp[n - 1]);

}


Measured memory_bytes: 8444
#pragma region include
#include <iostream>
#include <iomanip>
#include <stdio.h>

#include <sstream>
#include <algorithm>
#include <cmath>
#include <complex>

#include <string>
#include <cstring>
#include <vector>
#include <tuple>
#include <bitset>

#include <queue>
#include <complex>
#include <set>
#include <map>
#include <stack>
#include <list>

#include <fstream>
#include <random>
//#include <time.h>
#include <ctime>
#pragma endregion //#include
/////////
#define REP(i, x, n) for(int i = x; i < n; ++i)
#define rep(i,n) REP(i,0,n)
/////////
#pragma region typedef
typedef long long LL;
typedef long double LD;
typedef unsigned long long ULL;
#pragma endregion //typedef
////定数
const int INF = (int)1e9;
const LL MOD = (LL)1e9+7;
const LL LINF = (LL)1e18;
const double PI = acos(-1.0);
const double EPS = 1e-9;
/////////
using namespace::std;

void solve(){
	int N;
	cin >> N;
	vector< vector<int> > num( N, vector<int>(26,0) );
	for(int i=0;i<N;++i){
		string str;
		cin >> str;
		int size = str.size();
		for(int j=0;j<size;++j){
			int res = str[j]-'a';
			num[i][res]++;
		}
	}
	vector<int> ans(26,INF);
	for(int a=0;a<26;++a){
		for(int i=0;i<N;++i){
			ans[a] = min( ans[a], num[i][a] );
		}
	}
	for(int a=0;a<26;++a){
		int res = ans[a];
		for(int i=0;i<res;++i){
			char temp = 'a'+a;
			cout << temp;
		}
	}
	cout << endl;
}

#pragma region main
signed main(void){
	std::cin.tie(0);
	std::ios::sync_with_stdio(false);
	std::cout << std::fixed;//小数を10進数表示
	cout << setprecision(16);//小数点以下の桁数を指定//coutとcerrで別	

	solve();
}
#pragma endregion //main()


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

typedef long long ll;
const int maxn=2e3+10;
int n,k,q,x[maxn],ans=2e9;
bool vis[maxn];
pair<int,int> a[maxn];

inline int chk(){
	vector<int> vec;
	for(int i=1;i<=n;){
		while(i<=n&&vis[i])
			++i;
		vector<int> tmp;
		while(i<=n&&!vis[i]){
			tmp.push_back(x[i]);
			++i;
		}
		sort(tmp.begin(),tmp.end());
		for(int j=0;j+k-1<tmp.size();++j)
			vec.push_back(tmp[j]);
	}
	sort(vec.begin(),vec.end());
	return vec.size()>=q?vec[q-1]:2e9;
}

int main(){
	cin>>n>>k>>q;
	for(int i=1;i<=n;++i){
		cin>>x[i];
		a[i]=make_pair(x[i],i);
	}
	sort(a+1,a+n+1);
	ans=min(ans,chk()-a[1].first);
	for(int i=1;i<n;++i){
		vis[a[i].second]=true;
		ans=min(ans,chk()-a[i+1].first);
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 384
#include <iostream>
#include<bits/stdc++.h>
#define ll long long
#define   ull unsigned long long 
const int MAX=2e5+9;
const long long mod=1e9+7;
using namespace std;
vector<int>adj[MAX];
int dp[MAX][4];
ll pre[MAX][101];
int main(){
	int a, b, n;
	cin>>n>>a>>b;
	cout<<min(n*a, b);

}

Measured memory_bytes: 6144
#include <iostream>
#include <vector>
#include <algorithm>
#include <random>
#include <string>
#include <cmath>
#include <sstream>
#include <istream>
#include <iomanip>
#include <typeinfo>
#include <stack>

using namespace std;
typedef long long ll;

int main(){

    double N;

    cin >> N;

    vector<double > a(N,0);
    double ans = 0;
    for(ll i = 0; i < N; i++){
        cin >> a[i];
    }

    sort(a.begin(), a.end());
    ans = a[0];
    for(ll i = 0; i < N - 1; i++){
        ans = (ans + a[i+1]) / 2;
    }
    
    cout << ans << endl;

}

Measured memory_bytes: 256
import java.io.*;
import java.util.*;


public class Main {

	private static Scanner sc;
	private static Printer pr;

	private static void solve() {
		int r = sc.nextInt();
		int g = sc.nextInt();

		pr.println(2 * g - r);
	}

	// ---------------------------------------------------
	public static void main(String[] args) {
		sc = new Scanner(System.in);
		pr = new Printer(System.out);

		solve();

		pr.close();
		sc.close();
	}

	private static class Printer extends PrintWriter {
		Printer(PrintStream out) {
			super(out);
		}
	}
}


Measured memory_bytes: 21840
#include<bits/stdc++.h>
#define ll long long
#define fast ios::sync_with_stdio(false); cin.tie(0);
#define f(i,s,e) for(int i=s;i<e;i++)
#define pb(x) push_back(x)
#define mp make_pair
#define mod 1000000007
#define all(x) x.begin(),x.end()
using namespace std;
int n,dp[100005],arr[100005];

int func(int ind){
    if(ind==n-1)return 0;

    if(dp[ind]!=-1)return dp[ind];

    int ans=INT_MAX;

    if(ind+1<n)        ans=min(ans,func(ind+1)+abs(arr[ind]-arr[ind+1]));
    if(ind+2<n)        ans=min(ans,func(ind+2)+abs(arr[ind]-arr[ind+2]));

    return dp[ind]=ans;
}
int main(){
    fast;

    cin>>n;

    f(i,0,n)cin>>arr[i];

    memset(dp,-1,sizeof(dp));
    cout<<func(0);
}


Measured memory_bytes: 5760
#include<bits/stdc++.h>
using namespace std;
const int N=1e3+15;
typedef long long ll;
int main()
{
    ll n,a,b;
    cin>>n>>a>>b;
    if(a<b)
        swap(a,b);
    if((a-b)%2==0)
    {
        cout<<((a-b)/2)<<endl;
    }
    else
    {
        ll d=(a-b)/2;
        ll op1=b;
        ll op2=n-a+1;
        cout<<min(op1,op2)+d<<endl;
    }
    return 0;
}


Measured memory_bytes: 3636