akhauriyash/Code-Regression huggingface dataset:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

public class ABC
{
    //          long[] sp = Console.ReadLine().Split().Select(long .Parse).ToArray();
    //          int[] sp = Console.ReadLine().Split().Select(int.Parse).ToArray();
    //          int N =  int.Parse(Console.ReadLine());
    public static void Main()
    {
        int[] nk = Console.ReadLine().Split().Select(int.Parse).ToArray();
        int N = nk[0];
        int K = nk[1];
        string S = Console.ReadLine();

        List<int> len = new List<int>();
        char look =  S[0];
        int count = 1;
        for (int i = 1; i < S.Length; i++)
        {
            if (look == S[i])
            {
                count++;
            }
            else
            {
                look = S[i];
                len.Add(count);
                count = 1;
            }
        }
        len.Add(count);
        int saved = 0;
        for (int i = 0; i < len.Count; i++)
        {
            saved += len[i] - 1;
        }

        if (len.Count / 2 > K)
        {
            saved += 2 * K;
        }
        else
        {
            saved = N - 1;

        }
        Console.WriteLine(saved);
    }

}




Measured memory_bytes: 14560
#include<stdio.h>

int main(){
	int N, i, j, k, l, v, A[1000];  
	scanf("%d", &N);
	for (i = 0; i < N; i++) {
		scanf("%d", &A[i]);
	}
	for (i = 1; i < N + 1; i++) {
		for (j = 0; j < i; j++) {
			v = A [j];
			k = j - 1;
			while (k >= 0 && A [k] > v) {
				A [k + 1] = A [k];
				k--;
			}
			A[k + 1] = v;
		}
		for (l = 0; l < N; l++) {
			if (l == 0) {
				printf("%d",A[l]);
			}
			else {
				printf(" %d",A[l]);
			}
		}
		putchar('\n');
	}
}





Measured memory_bytes: 2136
n = int(input())
A = list(map(int, input().split()))
c = []
other = 0
for a in A:
    if a< 400:c.append(1)
    elif a < 800: c.append(2)
    elif a < 1200: c.append(3)
    elif a < 1600: c.append(4)
    elif a < 2000: c.append(5)
    elif a < 2400: c.append(6)
    elif a < 2800: c.append(7)
    elif a < 3200: c.append(8)
    else: other+=1
c = set(c)
if c: print(len(c), len(c)+other)
else: print(1, other)

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

a = list()
b = list()
c = list()

for i in range(N):
    tmp_a, tmp_b, tmp_c = map(int,input().split())
    a.append(tmp_a)
    b.append(tmp_b)
    c.append(tmp_c)

dp = [[0 for i in range(3)] for j in range(N)]
dp[0][0] = a[0]
dp[0][1] = b[0]
dp[0][2] = c[0]

for i in range(1, N):
    dp[i][0] = max(dp[i-1][1]+a[i], dp[i-1][2]+a[i])
    dp[i][1] = max(dp[i-1][0]+b[i], dp[i-1][2]+b[i])
    dp[i][2] = max(dp[i-1][0]+c[i], dp[i-1][1]+c[i])

print( max(dp[N-1]) )



Measured memory_bytes: 36224
import java.util.Arrays;
import java.util.Comparator;
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        char[] input = sc.next().toCharArray();
        for (int i = 0; i < input.length; i++) {
            if (i % 2 == 0) {
                if (input[i] == 'R' || input[i] == 'U' || input[i] == 'D') {

                } else {
                    System.out.println("No");
                    return;
                }
            } else {
                if (input[i] == 'L' || input[i] == 'U' || input[i] == 'D') {

                } else {
                    System.out.println("No");
                    return;
                }
            }
        }
        System.out.println("Yes");
    }
}

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

#define all(v) v.begin(), v.end()
#define rep(i, n) for (int i = 0; i < n; i++)
typedef long long ll;

int main() {
    int H, W; cin >> H >> W;
    vector<string> s(H);
    for(int i = 0; i < H; i++){
        cin >> s[i];
    }
    int dx[] = {1, 0, -1, 0};
    int dy[] = {0, 1, 0, -1};
    int x[] = {-1, 1, -1, 1};
    int y[] = {1, 1, -1, -1};
    for(int h = 0; h < H; h++){
        for(int w = 0; w < W; w++){
            if(s[h][w] != '#'){
                int cnt = 0;
                for(int i = 0; i < 4; i++){
                    int nx = w + dx[i];
                    int ny = h + dy[i];
                    if(nx < 0 || W <= nx || ny < 0 || H <= ny) continue;
                    if(s[ny][nx] == '#') cnt++;
                }
                for(int i = 0; i < 4; i++){
                    int nx = w + x[i];
                    int ny = h + y[i];
                    if(nx < 0 || W <= nx || ny < 0 || H <= ny) continue;
                    if(s[ny][nx] == '#') cnt++;
                }
                char tmp = '0' + cnt;
                if(cnt > 0) s[h][w] = tmp;
                else s[h][w] = '0';
            }
        }
    }
    for(int i = 0; i < H; i++){
        cout << s[i] << endl;
    }
}


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

typedef long long ll;
ll MOD = 1000000007;

struct bit {
	vector<ll> v;
	bit(int n) : v(n + 1) {}
	ll sum(int i) {
		ll res = 0;
		for (; i > 0; i -= i & -i) res += v[i];
		return res;
	}
	void add(int i, ll x) {
		for (i++; i < v.size(); i += i & -i) v[i] += x;
	}
};

int B = 800;

int main() {
	int N; cin >> N;
	vector<int> p(N);
	for (int i = 0; i < N; i++) {
		scanf("%d", &p[i]);
		p[i]--;
	}
	int Q; cin >> Q;
	vector<vector<int> > query(N);
	vector<int> l(Q), r(Q);
	for (int q = 0; q < Q; q++) {
		scanf("%d%d", &l[q], &r[q]);
		l[q]--; r[q]--;
		query[r[q]].push_back(q);
	}
	vector<int> index(N, -1);
	bit bt(N);
	vector<int> A(N / B + 1);
	vector<vector<int> > v(N / B + 1);
	vector<vector<ll> > sum(N / B + 1, vector<ll>(1));
	ll cur = 0;
	vector<ll> ans(Q);
	for (int i = 0; i < N; i++) {
		for (int x = N - 1; x > p[i];) {
			if (x % B == B - 1 && x - B >= p[i]) {
				A[x / B]++;
				cur += v[x / B].size();
				x -= B;
			}
			else {
				if (index[x] != -1) {
					bt.add(index[x], 1);
					cur++;
				}
				x--;
			}
		}
		int x = p[i];
		index[x] = i;
		ll prev = sum[x / B].back();
		v[x / B].push_back(i);
		sum[x / B].push_back(prev + A[x / B]);
		for (int k = 0; k < query[i].size(); k++) {
			int q = query[i][k];
			ans[q] = cur - bt.sum(l[q]);
			for (int i = 0; i <= N / B; i++) {
				int j = lower_bound(v[i].begin(), v[i].end(), l[q]) - v[i].begin();
				ans[q] -= (ll)j * A[i] - sum[i][j];
			}
		}
	}
	for (int q = 0; q < Q; q++)
		printf("%lld\n", ans[q]);
}

Measured memory_bytes: 13996
use std::collections::HashSet;

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)*}
    };
}

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)*}
    };
}

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, usize1) => {
        read_value!($next, usize) - 1
    };

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

pub trait LexicalPermutation {
    fn next_permutation(&mut self) -> bool;
    fn prev_permutation(&mut self) -> bool;
}

impl<T> LexicalPermutation for [T]
where
    T: Ord,
{
    fn next_permutation(&mut self) -> bool {
        if self.len() < 2 {
            return false;
        }
        let mut i = self.len() - 1;
        while i > 0 && self[i - 1] >= self[i] {
            i -= 1;
        }
        if i == 0 {
            return false;
        }
        let mut j = self.len() - 1;
        while j >= i && self[j] <= self[i - 1] {
            j -= 1;
        }
        self.swap(j, i - 1);
        self[i..].reverse();
        true
    }

    fn prev_permutation(&mut self) -> bool {
        if self.len() < 2 {
            return false;
        }
        let mut i = self.len() - 1;
        while i > 0 && self[i - 1] <= self[i] {
            i -= 1;
        }
        if i == 0 {
            return false;
        }
        self[i..].reverse();
        let mut j = self.len() - 1;
        while j >= i && self[j - 1] < self[i - 1] {
            j -= 1;
        }
        self.swap(i - 1, j);
        true
    }
}

fn main() {
    input! {
        abc: [usize; 3],
    }
    let set = abc.iter().collect::<HashSet<_>>();
    println!("{}", set.len());
}


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

int main(){
    int N; long long K;
    cin >> N >> K;
    vector<pair<long long, long long> > v(N);
    for (int i = 0; i < N; ++i) cin >> v[i].first >> v[i].second;

    // ソート
    sort(v.begin(), v.end());
    
    // a_i が小さい順に b_i を合計して K 以上になる瞬間をとらえる
    long long res = 0;
    long long sum = 0;
    for (int i = 0; i < N; ++i) {
        sum += v[i].second;
        if (sum >= K) {
            res = v[i].first; // sum >= K になった瞬間の a_i
            break;
        }
    }
    cout << res << endl;
}

Measured memory_bytes: 1792
import sys
from collections import  Counter
readline = sys.stdin.buffer.readline
sys.setrecursionlimit(10 ** 8)
INF = float('inf')
MOD = 10 ** 9 + 7



def main():
    S = input()
    count = Counter(S)
    count['a'] += 0
    count['b'] += 0
    count['c'] += 0
    if max(count.values()) - min(count.values()) <= 1:
        print('YES')
    else:
        print('NO')

if __name__ == '__main__':
    main()

Measured memory_bytes: 3444
//Dragon_warrior7(IITK)
#pragma GCC optimize ("Ofast")
#pragma GCC target ("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#pragma GCC optimize ("-ffloat-store")
#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;
#define ll long long
#define pb push_back
#define nl cout << '\n'
#define sor(x) sort(x.begin(), x.end())
#define rev(v) reverse(v.begin(), v.end())
#define lb(v, temp) lower_bound(v.begin(), v.end(), temp)
#define ub(v, temp) upper_bound(v.begin(), v.end(), temp)
#define fi first
#define se second
#define llmax 1000000000000000000
#define pll pair<ll, ll> 
#define ull unsigned ll
#define vll vector<ll> 
#define rub cout << "\n------------------------------------\n"
#define deb(args...) { string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); stringstream _ss(_s); istream_iterator<string> _it(_ss); err(_it, args); }

void err(istream_iterator<string> it) {}
template<typename T, typename... Args>
void err(istream_iterator<string> it, T a, Args... args) 
{
	cout << *it << " = " << a;
	nl;
	err(++it, args...);
}
//typedef  tree < int ,  null_type ,  greater<int> ,  rb_tree_tag ,  tree_order_statistics_node_update > oset;
void read(vector<ll> &v)
{
	for (int i = 0; i < v.size(); i++)
		cin >> v[i];
}
// const int mod=1e9+7;
// ll power(ll a,ll b) {ll res=1;a%=mod; assert(b>=0); for(;b;b>>=1){if(b&1)res=res*a%mod;a=a*a%mod;}return res;}
// ll modInverse(ll a){return power(a,mod-2);}
ll n,m,a,b,c,k,temp,x,y;
void solveforthiscase(const int & test)
{//deb(test);
cin>>n;
vector<pll> vp(n);
for(int i=0;i<n;i++)
cin>>vp[i].se>>vp[i].fi;
sor(vp);
//bool flag=1;
ll sum=0;
for(int i=0;i<n;i++)
{
    if((sum+vp[i].se)>vp[i].fi)
    {cout<<"No";return;}
    sum+=vp[i].se;
}
cout<<"Yes";







return ;
}
int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	int test=1;
// 	cin>>test;
    for(int i=1;i<=test;i++)
    {
        solveforthiscase(i);
    }
}

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

int gcd(int a, int b) {
  if(b == 0) return a;
  return gcd(b, a % b);
}

int main() {
  int a, b;
  while(cin >> a >> b) {
    cout << gcd(a, b)<< endl;
  }
  return 0;
}



Measured memory_bytes: 2988
class UnionFind:
    def __init__(self, n):
        # 負  : 根であることを示す。絶対値はランクを示す
        # 非負: 根でないことを示す。値は親を示す
        self.table = [-1] * n
 
    def _root(self, x):
        if self.table[x] < 0:
            return x
        else:
            # 経路の圧縮
            self.table[x] = self._root(self.table[x])
            return self.table[x]
 
    def find(self, x, y):
        return self._root(x) == self._root(y)
 
    def union(self, x, y):
        r1 = self._root(x)
        r2 = self._root(y)
        if r1 == r2:
            return
        # ランクの取得
        d1 = self.table[r1]
        d2 = self.table[r2]
        if d1 <= d2:
            self.table[r2] = r1
            if d1 == d2:
                self.table[r1] -= 1
        else:
            self.table[r1] = r2

if __name__ == "__main__":
    N,K,L = map(int,input().split())
    pq = []
    rs = []
    for i in range(K):
        pq.append(list(map(int,input().split())))
    for i in range(L):
        rs.append(list(map(int,input().split())))
    
    uf_d = UnionFind(N)
    uf_t = UnionFind(N)

    for i in pq:
        uf_d.union(i[0]-1,i[1]-1)

    for i in rs:
        uf_t.union(i[0]-1,i[1]-1)
    
    dic = {}
    
    for i in range(N):
        tmp = (uf_d._root(i),uf_t._root(i))
        #print(tmp)
        if tmp in dic:
            dic[tmp] += 1
        else:
            dic[tmp] = 1
    
    res = []

    for i in range(N):
        tmp = (uf_d._root(i),uf_t._root(i))
        res.append(dic[tmp])
    
    print(*res)


Measured memory_bytes: 86260
#include <bits/stdc++.h>
using namespace std;
int main() {
    // 入力受け取り, 入次数も管理する
int n;
string s;
    cin >> n >> s;
int num=0;
for(int i=0;i<n-2;i++){
if(s[i]=='A' && s[i+1]=='B' && s[i+2]=='C'){
num++;
}
}

cout << num;



   
}


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

typedef long long int ll;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<ll> VL;
typedef vector<VL> VVL;
typedef pair<ll, ll> Pair;
typedef vector<Pair> VP;

#define MOD 1000000007
#define times(n) rep(_idx, n)
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define REP(i, s, n) for(int i = (int)(s); i < (int)(n); i++)
#define all(a) (a).begin(),(a).end()
#define pb push_back
#define mk make_pair
#define out(x) cout << (x) << endl;
#define DU(x) cerr << #x << " = " << (x) << endl;

template<typename _Ty>ostream& operator << (ostream& ostr, const vector<_Ty>& v) {if (v.empty()) {ostr << "[]";return ostr;}ostr << "[" << v.front();for (auto itr = ++v.begin(); itr != v.end(); itr++) {ostr << ", " << *itr;}ostr << "]";return ostr;}

int main() {
    int A, B;
    cin >> A >> B;
    out((int)ceil((B - 1) / (double)(A - 1)));
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll  long long
#define endl '\n'
#define FASTINOUT ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
const ll mod = 1000000007;
const double PI = 3.141592653589793238463;
const int N=2e5+100;
int main()
{
    FASTINOUT;
    int x,k;
    cin>>x>>k;
    ll y[x];
    for (int i=0;i<x;i++)
        cin>>y[i];
    long double ans=0,sum=0;
    int l=0;
    for (int i=0;i<x;i++){
        sum+=(y[i]*(y[i]+1))/2/(long double)y[i];
        if (i>=k-1){
            ans=max(ans,sum);
        sum-=(y[l]*(y[l]+1))/2/(long double)y[l];
        l++;
        }
    }
    cout<<fixed<<setprecision(6)<<ans<<endl;
    return 0;
}


Measured memory_bytes: 1792
#include <stdio.h>
#include <math.h>
#define N 10000
int Prime(int);

int main(){
  int A[N], i, j, n, c=0;

  scanf("%d", &n);

  for (i = 0; i < n; i++){
    scanf("%d", &A[i]);
    c += Prime(A[i]);
  }
  printf("%d\n", c);

  return 0;
}

int Prime(int a)
{
  int i;
  if(a < 2) return 0;
  else if (a == 2) return 1;
  else if (a % 2 == 0) return 0;
  for(i = 3; i <= sqrt(a); i += 2){
    if(a % i == 0) return 0;
  }
  return 1;
}



Measured memory_bytes: 2048
#include<iostream>
#include<iomanip>
#include<math.h>
#include<algorithm>
#include<string>
#include<vector>
#include<queue>
#include<stack>
#include<set>
#include<map>
#define REP(i, N) for(ll i = 0; i < N; ++i)
#define FOR(i, a, b) for(ll i = a; i < b; ++i)
#define ALL(a) (a).begin(),(a).end()
#define pb push_back
#define INF (long long)1000000000
#define MOD 1000000007
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};

int main(void) {
	while(true) {
		ll c, n, m, s, d;
		cin>>c>>n>>m>>s>>d;
		if(c == 0 && n == 0 && m == 0 && s == 0 && d == 0) break;
		--s;
		--d;
		vector<vector<P> > p(n);
		vector<vector<ll> > dir(n, vector<ll>(c + 1, INF * INF));
		REP(i, m) {
			int a, b, f;
			cin>>a>>b>>f;
			--a;
			--b;
			p[a].pb(P(b, f));
			p[b].pb(P(a, f));
		}
		priority_queue<pair<P, ll> > que;
		que.push(pair<P, ll>(P(0, s), c));
		dir[s][c] = 0;
		while(!que.empty()) {
			pair<P, ll> np = que.top();
			que.pop();
			if(dir[np.first.second][np.second] != np.first.first) continue;
			REP(i, p[np.first.second].size()) {
				if(dir[p[np.first.second][i].first][np.second] > dir[np.first.second][np.second] + p[np.first.second][i].second) {
					dir[p[np.first.second][i].first][np.second] = dir[np.first.second][np.second] + p[np.first.second][i].second;
					que.push(pair<P, ll>(P(dir[p[np.first.second][i].first][np.second], p[np.first.second][i].first), np.second));
				}
				if(np.second > 0 && dir[p[np.first.second][i].first][np.second - 1] > dir[np.first.second][np.second] + p[np.first.second][i].second / 2) {
					dir[p[np.first.second][i].first][np.second - 1] = dir[np.first.second][np.second] + p[np.first.second][i].second / 2;
					que.push(pair<P, ll>(P(dir[p[np.first.second][i].first][np.second - 1], p[np.first.second][i].first), np.second - 1));
				}
			}
		}
		ll res = INF * INF;
		REP(i, c + 1) {
			res = min(res, dir[d][i]);
		}
		cout<<res<<endl;
	}
}

Measured memory_bytes: 3188
#include <iostream>
#include <ios>
#include <iomanip>
#include <algorithm>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <utility>
using namespace std;

#define MOD 1000000007
#define INF 1e9+7
#define rep(i, n) for(int i=0; i<n; ++i)
#define rrep(i, m, n) for(int i=m; i<n; ++i)
typedef long long ll;

#define MAX_N 100000
#define MAX_M 100000
#define MAX_V 100
#define MAX_E 100
#define MAX_Q 100000

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

int ddx[] = {-1, 0, 1, 0, -1, 1, -1, 1};
int ddy[] = {0, -1, 0, 1, 1, 1, -1, -1};

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



int main() {

  int n;
  cin >> n;
  cout << n/2+n%2-1 << endl;

  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define m 1000000007
using namespace std;
typedef long long ll;
vector<int> adj[1001];
int visited[1001]={0};

int main()
{
    ll a;
    string s;
    cin>>a>>s;
    if(a>=3200)
        cout<<s;
    else
        cout<<"red";
    return 0;
}


Measured memory_bytes: 256
N, A, B, C = map(int,input().split())
INF = float('inf')
L = []
for _ in range(N):
    L.append(int(input()))

def dfs(i, cnt, a, b, c):
    if i == N:
        if a == 0 or b == 0 or c == 0:
            return INF
        return abs(a - A) + abs(b - B) + abs(c - C) + 10 * cnt
    MP = INF
    if a == 0:
        MP = min(MP, dfs(i+1, cnt, a+L[i], b, c))
    else:
        MP = min(MP, dfs(i+1, cnt+1, a+L[i], b, c))
    if b == 0:
        MP = min(MP, dfs(i+1, cnt, a, b+L[i], c))
    else:
        MP = min(MP, dfs(i+1, cnt+1, a, b+L[i], c))
    if c == 0:
        MP = min(MP, dfs(i+1, cnt, a, b, c+L[i]))
    else:
        MP = min(MP, dfs(i+1, cnt+1, a, b, c+L[i]))
    MP = min(MP, dfs(i+1, cnt, a, b, c))
    
    return MP

print(dfs(0, 0, 0, 0, 0))

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

using namespace std;
using ll = long long;
using ld = long double;
using P = pair<int, int>;
using LP = pair<ll, ll>;

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

#define INF 1001001

double dpRec(int l, int r, vector<vector<double>>& dp, vector<vector<int>>& key, vector<double> sump, vector<double> sumq) {
    if (dp[l][r] != INF) return dp[l][r];
    if (l > r) {
        dp[l][r] = sumq[r + 1] - sumq[l - 1];
        return dp[l][r];
    }

    double s = sump[r] - sump[l - 1] + sumq[r + 1] - sumq[l - 1];

    if (chmin(dp[l][r], dpRec(l, l - 1, dp, key, sump, sumq) + dpRec(l + 1, r, dp, key, sump, sumq) + s)) {
        key[l][r] = l;
    }
    if (l == r) return dp[l][r];
    
    if (chmin(dp[l][r], dpRec(l, r - 1, dp, key, sump, sumq) + dpRec(r + 1, r, dp, key, sump, sumq) + s)) {
        key[l][r] = r;
    }

    for (int i = key[l][r - 1]; i <= key[l + 1][r]; ++i) {
        if (chmin(dp[l][r], dpRec(l, i - 1, dp, key, sump, sumq) + dpRec(i + 1, r, dp, key, sump, sumq) + s)) {
            key[l][r] = i;
        }
    }
    return dp[l][r];
}

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

    int n;
    cin>>n;
    vector<double> ps(n), sump(n + 1), qs(n + 1), sumq(n + 2);
    rep(i, n) {
        cin>>ps[i];
        sump[i + 1] = sump[i] + ps[i];
    }
    rep(i, n + 1) {
        cin>>qs[i];
        sumq[i + 1] = sumq[i] + qs[i];
    }

    vector<vector<double>> dp(n + 2, vector<double>(n + 2, INF));
    vector<vector<int>> key(n + 2, vector<int>(n + 2, INF));
    double ans = dpRec(1, n, dp, key, sump, sumq);
    printf("%.10f\n", ans);
}


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

int main() 
{
	int n; cin>>n;
	set<int>ez;
	int p[n];
	for(int i=0;i<n;i++)
	{
		cin>>p[i];
	//	ez.insert(p[i]);
	}
	int pre=n-ez.size();
	//cout<<pre;
	int r=1;
	for(int i=0;i<n;i++)
	{
		if(!ez.count(p[i]))
		{
		if(p[i]==r)
		{
			ez.insert(p[i]);
			r++;
		}
	//	r++;
		}
		
	}
	//cout<<r;
	if(r==1){cout<<-1; return 0;}
	cout<<n-r+1;
}

Measured memory_bytes: 10368
#include <cstdio>
#include <iostream>
#include <iomanip>
#include <functional>
#include <algorithm>
#include <string>
#include <vector>
#include <limits>
#include <numeric>
#include <queue>
#include <cmath>
#include <set>
#include <map>
#include <stack>

using namespace std;

#define INFint (1<<30)
#define BOUND 27182818284
#define MAT 2

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

ll MOD = 1000000007;
const ll INF = (1ll<<60);
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define repi(i, a, b) for(int i=int(a);i<int(b);++i)

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

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

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

int findGCD(vector<int> arr) {
    int result = arr[0];
    for (auto a: arr) {
        result = gcd(a, result);
    }
    return result;
}

template<typename T>
T lcm(T m, T n) {
    // 引数に0がある場合は0を返す
    if ((0 == m) || (0 == n))
        return 0;
    return ((m / gcd(m, n)) * n); // lcm = m * n / gcd(m,n)
}

template<typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val) {
    fill((T *) array, (T *) (array + N), val);
}


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

// v.front() = -BOUND;
// v.back() = BOUND;

//struct edge{
//    int cost, to;
//
//    edge(int in_cost, int in_to){
//        cost=in_cost;
//        to=in_to;
//    }
//    bool operator<(const edge &a) const
//    {
//        return cost > a.cost;
//    }
//};
ll euler_phi(ll n) {
    ll ret = n;
    for(ll i = 2; i * i <= n; i++) {
        if(n % i == 0) {
            ret -= ret / i;
            while(n % i == 0) n /= i;
        }
    }
    if(n > 1) ret -= ret / n;
    return ret;
}
int main() {
    string S , T; cin >> S >> T;

    cout << T << S << endl;
    return 0;
}

Measured memory_bytes: 256
n=int(input())
s=input()
ans=10**9
w=[0]*n
b=[0]*n
cw,cb=0,0
for i in range(n):
  if s[i]==".":
    cw+=1
  else:
    cb+=1
  w[i]=cw
  b[i]=cb

for i in range(n):
  ans=min(ans,b[i]+w[-1]-w[i])
ans=min(ans,b[-1],w[-1])
print(ans)


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

int main(){
  int n;
  string cube[30][6];
  bool use[30];

  for(;;){
    cin >> n;
    if(!n)break;
    for(int i=0;i<n;i++){
      use[i] = false;
      for(int j=0;j<6;j++)cin >> cube[i][j];
    }

    for(int i=0;i<n;i++){
      if(!use[i]){
	for(int j=i+1;j<n;j++){
	  string tmp[6] = cube[j];
	  bool f;
	  for(int k=0;k<6;k++){
	    swap(tmp[0],tmp[1]);
	    swap(tmp[1],tmp[5]);
	    swap(tmp[5],tmp[4]);
	    for(int l=0;l<4;l++){
	      if(l){
		if(k&1){
		  swap(tmp[3],tmp[4]);
		  swap(tmp[4],tmp[2]);
		  swap(tmp[2],tmp[1]);
		}else{
		  swap(tmp[1],tmp[2]);
		  swap(tmp[2],tmp[4]);
		  swap(tmp[4],tmp[3]);
		}
	      }
	      f = true;
	      for(int z=0;z<6;z++)
		if(cube[i][z] != tmp[z])f = false;
	      if(f)break;
	    }
	    if(f)break;
	  }
	  if(f)use[j] = true;
	}
      }
    }
    int ans = 0;
    for(int i=0;i<n;i++)if(use[i])ans++;
    cout << ans << endl;
  }
}

Measured memory_bytes: 0
n, m = gets.chomp.split.map(&:to_i)
pref = Array.new(n) { Array.new }
city = Array.new(m)
m.times do |i|
  p, y = gets.chomp.split.map(&:to_i)
  pref[p - 1] << [i, y]
end

n.times do |i|
  cities = pref[i]  
  cities.sort_by! {|_, y| y }
  (cities.size).times do |j|
    c, y = cities[j]
    city[c] = [i + 1, j + 1]
  end
end

city.each do |i, j|
  puts "%06d%06d" % [i, j]
end

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

int main(void)
{
	char s[100];
	scanf("%s",s);
	int k=strlen(s);
	
	int i=0,j=0,count=0;
	for(i;i <= k-1;i++)
		{
		count=0,j=0;
		for(j;j<=k-1;j++)
			{
			if(s[i] == s[j])
				{count++;}
			}
		if(count%2 != 0)
			{
			printf("No\n");
			break;
			}
		}
	if(count%2 == 0)
		{printf("Yes\n");}
	return 0;
}


Measured memory_bytes: 128
#include <bits/stdc++.h>
#define REP(i,n) for (int i=0;i<(n);i++)
#define ALL(a) (a).begin(),(a).end()
#define RFOR(i,a,b) for (int i=(b)-1;i>=(a);i--)
#define REP(i,n) for (int i=0;i<(n);i++)
#define RREP(i,n) for (int i=(n)-1;i>=0;i--)
#define ll long long
#define ull unsigned long long
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};

using namespace std;

int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
	string s;
	cin >> s;
	bool canmatch = true;
	while(s.size()){
		if(s.substr(0,6) == "eraser")
			s.erase(s.begin(),s.begin() + 6);		
		else if(s.substr(0,5) == "erase")
			s.erase(s.begin(),s.begin() + 5);
		else if(s.substr(0,5) == "dream"){
			if(s.substr(5,6) == "eraser")
				s.erase(s.begin(),s.begin() + 11);
			else if(s.substr(5,5) == "erase")
				s.erase(s.begin(),s.begin() + 10);
			else if(s.substr(5,2) == "er")
				s.erase(s.begin(),s.begin() + 7);
			else s.erase(s.begin(),s.begin() + 5);
		}	else {
			canmatch = false;
			break;
		}
	}
	if(canmatch)cout << "YES" << endl;
	else cout << "NO" << endl;
  return 0;
}


Measured memory_bytes: 512
N = input()
def rec(list1,list2,initial,time):
    for e in list1:
        for b in [0,1,2,3]:
            if b == 0:
                e_copy = e
                list2.append(e_copy)
            elif b == 1:
                e_copy = e + "3"
                list2.append(e_copy)
            elif b == 2:
                e_copy = e + "5"
                list2.append(e_copy)
            elif b == 3:
                e_copy = e + "7"
                list2.append(e_copy)
    list1.clear()
    # initial + 1 がn回目のループ
    if initial + 1 >= time :
        return list2
    else:
        return rec(list2,list1,initial + 1, time)
l1 = [""]
l2 = []
result = rec(l1,l2,0,len(N))
result = [int(e) for e in result if e.count("3")*e.count("5")*e.count("7") >= 1]
result = list(set(result))
result.sort()
count = 0
for e in result:
    if int(N) < e:
        break
    count += 1
print(count)

Measured memory_bytes: 31148
#include<iostream>
using namespace std;
int main(){
	int N,K,P;
	cin >> N;
	for(int i=0; i<N; i++){
		cin >> K >> P;
		if(K%P==0){
			cout<<P<<endl;
		}
		else if(K%P!=0){
			cout<<K%P<<endl;
		}
	}

return 0;
}

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

int main() {
    int N, M, p;
    cin >> N >> M >> p;
    vector<int> d(M);
    for(int i=0; i<M; ++i) {
        cin >> d[i];
        d[i] -= p;
        d[i] = (d[i] + N) % N;
    }
    sort(d.begin(), d.end());
    int res = min(d.back(), N - d[0]);
    for(int i=0; i<M-1; ++i) {
        res = min(res, min(2*d[i] + (N - d[i+1]), 2*(N - d[i+1]) + d[i]));
    }
    cout << res * 100 << endl;
}

Measured memory_bytes: 3156
#include <bits/stdc++.h>
using namespace std;
#define int         long long
#define mp          make_pair
#define pb          push_back
#define pii         pair<int,int>
#define vi          vector<int>
// #define vb          vector<bool>
// #define vc          vector<char>
#define vii         vector<pii>
//#define mi          map<int,int>
//#define mii         map<pii,int>
#define all(a)      (a).begin(),(a).end()
#define F           first
#define S           second
#define sz(x)       (int)x.size()
// #define ub(x)       upper_bound(x)
// #define lb(x)       lower_bound(x)
#define endl        '\n'
#define file        freopen("b1.in","r",stdin);freopen("output.txt","w",stdout)
#define fastio      ios::sync_with_stdio(false),cin.tie(0),cout.tie(0);
// #define N            1e5+5
#define PRIME           1000000007
#define MAX         50000
#define mem0(a)     memset(a,0,sizeof(a))
#define prec        cout<<std::setprecision(9)<<std::fixed
#define forn(i,a,b)  for(int i=a;i<b;i++)
#define pi          3.14159265358979323
int i,j,k;
// int n;
// const int N=1e6+5;
// vector<bool> prime(N);
// void sieve(){
//     for(int i=0;i<=N;i++)prime[i]=true;
//     prime[0]=prime[1]=false;
//     for(int i=2;i*i<=N;i++){
//         if(prime[i] and i*i<=N){
//             for(int j=i*i;j<=N;j+=i){
//                 prime[j]=false;
//             }
//         }
//     }
// }
const bool cmp(pii a,pii b){
    return a.F-a.S>b.F-b.S;
}

void Anon_mouS(){
    int l,r,d;
    cin>>l>>r>>d;
    bool ok=false;
    int ans=0;
    for(i=l;i<=r;){
        if(i%d==0){
            ans++;
            ok=true;
        }
        if(ok)i+=d;
        else i++;
    }
    cout<<ans<<endl;
}
int32_t main(){
    fastio;
    int q=1;
    // sieve();
    // cin>>q;
    for(int it=1;it<=q;it++){
        // cout<<"Case #"<<it<<": ";
        Anon_mouS();
    }
    return 0;   
}

Measured memory_bytes: 3608
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
#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 fore(i,a) for(auto &i:a)
#define all(x) (x).begin(),(x).end()

int main(void){
    ll x, y;
    cin >> x >> y;

    if(signbit(x) != signbit(y)){
        if(y > x){
            cout << min(abs(abs(x) - abs(y)) + 1, y - x) << endl;
        }else{
            cout << abs(abs(x) - abs(y)) + 1 << endl;
        }
    }else{
        if(x > y){
            cout << min(x - y + 2, abs(x + y) + 1) << endl;
        }else{
            cout << y - x << endl;
        }
    }
    return 0;
}


Measured memory_bytes: 256
<?php
// 標準入力を一行ずつ配列に代入する
$stdins = array();
while(true) {
    $stdin = trim(fgets(STDIN));
    if ($stdin === '') {
        break;
    }
    $stdins[] = $stdin;
}

$ans = array_fill(0, 4, 0);
for ($i = 1; $i <= $stdins[0]; $i++) {
    switch ($stdins[$i]) {
        case 'AC':
            $ans['AC'] += 1;
            break;
        case 'WA':
            $ans['WA'] += 1;
            break;
        case 'TLE':
            $ans['TLE'] += 1;
            break;
        case 'RE':
            $ans['RE'] += 1;
            break;
    }
}

echo 'AC x '.(int)$ans['AC'].PHP_EOL;
echo 'WA x '.(int)$ans['WA'].PHP_EOL;
echo 'TLE x '.(int)$ans['TLE'].PHP_EOL;
echo 'RE x '.(int)$ans['RE'];
?>

Measured memory_bytes: 22624
#!/usr/bin/env python3
# Christmas Eve

N = list(map(int, (input().strip().split(' '))))
K = N[1]
N = N[0]
i = 0
h = []
while i < N:
  hi = int(input().strip())
  h.append(hi)
  i += 1
h = sorted(h)

i = 0
min_diff = 10000000000
while i < N - K + 1:
  diff = h[i+K-1] - h[i]
  if min_diff > diff:
    min_diff = diff
  i += 1
print(min_diff)

Measured memory_bytes: 8280
def check(a, b):
    if 1<= a <= 12 and 1 <= b <= 12:
        return "AMBIGUOUS"
    elif 1 <= a <= 12 and (b <= 0 or 13 <= b):
        return "MMYY"
    elif (a <= 0 or 13 <= a) and 1 <= b <= 12:
        return "YYMM"
    else:
        return "NA"

s = input()
a = int(s[:2])
b = int(s[2:])
print(check(a, b))

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

long long myPow(long long x, long long n){
  if(n == 0)
    return 1;
  if(n % 2 == 0)
    return myPow(x * x , n / 2);
  else
    return x * myPow(x, n - 1);
}

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

    long long buf = 0, digit = 0;

    while (__LONG_LONG_MAX__ / 26 > buf)
    {
        if(buf <= n && n < myPow(26, digit) + buf)break;
        buf += myPow(26, digit);
        digit++;
    }
    string ans;
    for (int i = 0; i < digit; i++)
    {
        ans += 'a';
    }
    
    long long num = n - buf;
    digit--;
    while (num != 0)
    {
        ans[digit] = 'a' + num % 26;
        num /= 26;
        digit--;
    }
    cout << ans << endl;
}

Measured memory_bytes: 3620
#include<bits/stdc++.h>
#define N 105
using namespace std;
int n,u,k,v,e[N][N],cnt;
int ans1[N],ans2[N];
bool used[N];
 
void dfs(int x){
  if(used[x])return;
  used[x]=true;
  ans1[x]=cnt++;
  for(int i=0;i<n;i++)
    if(e[x][i])dfs(i);
  ans2[x]=cnt++;
}
 
int main(){
  cin>>n;
  for(int i=0;i<n;i++){
    cin>>u>>k;
    for(int j=0;j<k;j++){
      cin>>v;
      e[u-1][v-1]=1;
    }
  }
  cnt=1;
  for(int i=0;i<n;i++)
    if(!used[i])dfs(i);
  
  for(int i=0;i<n;i++)
    cout<<i+1<<' '<<ans1[i]<<' '<<ans2[i]<<endl;

  return 0;
}



Measured memory_bytes: 3120
import std.stdio, std.algorithm, std.conv, std.array, std.string, std.math, std.typecons, std.numeric, std.container, std.range;

void main()
{
    auto dts = readln.split.to!(int[]);
    auto D = dts[0];
    auto T = dts[1];
    auto S = dts[2];
    writeln(D <= T * S ? "Yes" : "No");
}

Measured memory_bytes: 2728
#include <iostream>
#include <array>
#include <algorithm>
#include <vector>
#include <set>
#include <cmath>
#include <complex>
#include <deque>
#include <iterator>
#include <numeric>
#include <map>
#include <queue>
#include <stack>
#include <string>
#include <tuple>
#include <utility>
#include <limits>
#include <iomanip>
using namespace std;

using ll=long long;
template<class T> using V = vector<T>;
template<class T, class U> using P = pair<T, U>;
using vll = V<ll>;
using vvll = V<vll>;
#define rep(i, k, n) for (ll i=k; i<(ll)n; ++i)
#define REP(i, n) rep(i, 0, n)
template<class T> inline bool chmax(T& a, T b) {if (a<b) {a=b; return true;} return false;}
template<class T> inline bool chmin(T& a, T b) {if (a>b) {a=b; return true;} return false;}

const ll MOD = 1000000007;
const ll HIGHINF = (ll)1e18;

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll n, k; cin >> n >> k;
    vll a(n), b(n);
    REP(i, n) cin >> a[i] >> b[i];
    ll ans = 0;
    REP(i, n) if ((a[i]&k) == a[i]) ans += b[i];

    for (ll i=1; i<=k; i<<=1) {
        if (k&i) {
            k ^= i;
            ll tmp=0;
            REP(j, n) if ((a[j]&k) == a[j]) tmp += b[j];
            chmax(ans, tmp);
        }
        k^=i;
    }
    cout << ans << '\n';
    return 0;
}


Measured memory_bytes: 1792
#include<bits/stdc++.h>
using namespace std;
long long n, k, a[100005], s, ans=1e9;
int main(){
	cin>>n>>k;
	for(int i=1;i<=n;i++) {
		scanf("%lld", &a[i]);
	}
	long long now;
	for(int i=1;i+k-1<=n;i++){
		now=a[i+k-1]-a[i];
		now+=min(abs(a[i]), abs(a[i+k-1]));
		ans=min(ans, now);
	}
	cout<<ans;
}

Measured memory_bytes: 1024
import std.algorithm;
import std.array;
import std.ascii;
import std.container;
import std.conv;
import std.math;
import std.numeric;
import std.range;
import std.stdio;
import std.string;
import std.typecons;

void log(A...)(A arg) {
    stderr.writeln(arg);
}
int size(T)(in T s) {
    return cast(int)s.length;
}

void main() {
    int N; scanf("%d\n", &N);
    auto T = readln.chomp.split(" ").map!(to!int).array;
    auto A = readln.chomp.split(" ").map!(to!int).array;

    auto fixed = new bool[N];
    auto limit = new long[N];

    int t = 0;
    foreach (i; 0 .. N) {
        int prev = t;
        t = max(t, T[i]);
        if (prev == t) {
            limit[i] = t;
        } else {
            fixed[i] = true;
            limit[i] = t;
        }
    }
    int a = 0;
    foreach_reverse(i; 0 .. N) {
        int prev = a;
        a = max(a, A[i]);
        if (fixed[i]) {
            if (limit[i] > a) {
                writeln(0);
                return;
            }
        }
        if (prev == a) {
            limit[i] = min(limit[i], a);
        } else {
            if (limit[i] < a) {
                writeln(0);
                return;
            }
            fixed[i] = true;
        }
    }

    const long mod = cast(long)(1e9 + 7);
    long ans = 1;
    foreach (i; 0 .. N) {
        if (fixed[i]) continue;
        ans = (ans * limit[i]) % mod;
    }
    writeln(ans);

}


Measured memory_bytes: 8264
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using vi = vector<int>;
using vvi = vector<vector<int>>;
using vl = vector<ll>;
using vvl = vector<vector<ll>>;
#define all(x) x.begin(),x.end()
#define rep(i,j,n) for (int i = j; i < (int)(n); i++)
#define _GLIBCXX_DEBUG
#define MOD 1000000007
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
//name[i][j]-> vvl name(i,vl(j))
//map<int,int>mp
//�]���؂�グ�� =>  (a + b - 1) / b 

signed main(){
  cout << fixed << setprecision(10);
	long double l; cin>>l;
  long double k=l/3;
  cout<<k*k*k;
	
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define boost_io ios::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define int long long
#define num(a) a-'0'
#define charr(a) (a - 'A' + 1)
#define rep(i,a,b) for(int i=a;i<b;i++)
#define maxs(a,b) if(b>a)a=b
#define mins(a,b) if(b<a)a=b
#define debug(x) cerr<<"["<<#x<<":"<<x<<"] "
#define debug2(a,b) debug(a);debug(b)
#define debug3(a,b,c) debug2(a,b);debug(c)
#define gcd(a,b) __gcd(a,b)
#define lcm(a,b) (a*b)/(__gcd(a,b))
#define print(arr) for(auto it = arr.begin();it < arr.end();it ++){cout << *it << " ";}cout << ln;
#define all(a) (a).begin(), (a).end()
#define vi vector<long long>
#define v vector
#define p pair
#define pb push_back
#define mk make_pair
#define f first
#define s second
#define ln "\n"
typedef long double ld;
typedef double d;
using namespace std;
int modF=1e9+7;
int INF=1e11;

void solve(){
	int n,m;
	cin>>n>>m;
	int ans=(n*(n-1))/2+(m*(m-1))/2;
	cout<<ans<<ln;
}

signed main(){
	boost_io;
	solve();
	return 0;
}

Measured memory_bytes: 3652
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<string>
#include<iostream>
#include<algorithm>
using namespace std;
long long a, b, c;

int main()
{
	scanf("%lld %lld %lld", &a, &b, &c);
	if(a%2 == 0 || b%2 == 0 || c%2 == 0) printf("0\n");
	else
	{
		long long minnum = min(a*b, min(b*c, c*a));
		printf("%lld\n", minnum);
	}
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
	long long a,b;
	cin>>a>>b;
	int mn = 2019;
	if(b-a+1>=2019) cout<<0;
	else{
		for(int i=a; i<=b; i++){
			for(int j=i+1; j<=b; j++){
				mn = min(mn,( (i%2019)*(j%2019) )%2019);
			}
		}
		cout<<mn;
	}
}

Measured memory_bytes: 3544
#include <stdio.h>

int ads(int a){
	if(a>=0) return a;
	else return -1*a;
}

int min(int a,int b){
	if(a>=b) return b;
	else return a;
}

int main(void) {
	
	int N;
	scanf("%d",&N);
	int h[N];
	for(int i=0;i<N;i++) scanf("%d",&h[i]);
	int dp[N];
	dp[0] = 0;
	dp[1] = ads(h[1]-h[0]);
	
	for(int i=2;i<N;i++){
		dp[i] = min(dp[i-1]+ads(h[i]-h[i-1]),dp[i-2]+ads(h[i]-h[i-2]));
	}
	printf("%d",dp[N-1]);
	
	
	return 0;
}

Measured memory_bytes: 896
#include <iostream>

using namespace std;

int main()
{
    int a, b;
    cin >> a >> b;

    if (a == b)
    {
        cout << "Draw" << endl;
    }
    else if(a == 1)
    {
        cout << "Alice" << endl;
    }
    else if(b == 1)
    {
        cout << "Bob" << endl;
    }
    else if(a > b)
    {
        cout << "Alice" << endl;
    }
    else
    {
        cout << "Bob" << endl;
    }

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<string> vs;
ll llmax = LLONG_MAX;
string ALP = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
string alp = "abcdefghijklmnopqrstuvwxyz";
vi d1 = {1, 0, -1, 0}, d2 = {0, 1, 0, -1};
void Yes() {cout << "Yes" << endl;}
void No() {cout << "No" << endl;}
void YES() {cout << "YES" << endl;}
void NO() {cout << "NO" << endl;}
void neg() {cout << -1 << endl;}
void mysort(vll &a) {sort(a.begin(), a.end());}

int main() {
  string s;
  cin >> s;
  int cnt = 0;
  for (int i = 0; i < 3; i++)
    if (s[i] == '1') cnt++;
  cout << cnt << endl;
}

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



int main(){
    int A,B,C;
    vector<int> retu(3);
    cin >> retu.at(0) >> retu.at(1) >> retu.at(2);
    int K;
    cin >> K;

    sort(retu.begin(),retu.end());
    reverse(retu.begin(),retu.end());

    for(int i=0;i<K;i++){
        retu.at(0) = retu.at(0)*2;
    }

    cout << retu.at(0) + retu.at(1) + retu.at(2) << endl;

}

Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<algorithm>

using namespace std;

int main(){
	int n, a, b;
	cin >> n >> a >> b;
	if (n*a > b){
		cout << b << endl;
	}
	else if (n*a < b){
		cout << n*a << endl;
	}
	else{
		cout << b << endl;
	}
}

Measured memory_bytes: 256
#include <iostream>
#include <cstring>
#include <algorithm>
#include <cmath>
using namespace std;
typedef long long ll;
ll n, a[100008], dp[100008][2];

int main(){
	cin >> n;
	for(ll i = 1; i <= n; i++){
		cin >> a[i];
	}
	
	dp[1][0] = a[1];
	dp[1][1] = -a[1];
	for(ll i = 2; i <= n; i++){
		dp[i][0] = max(dp[i-1][0]+a[i], dp[i-1][1]-a[i]);
		dp[i][1] = max(dp[i-1][0]-a[i], dp[i-1][1]+a[i]);
	}
	
	cout << dp[n][0] << endl;
	return 0;
}

Measured memory_bytes: 2560
#include <iostream>
#include <iomanip>
#include <cassert>

#include <cstring>
#include <vector>
#include <algorithm>
#include <string>
#include <cmath>
#include <limits>
#include <queue>
#include <unordered_map>
#include <list>
#include <set>
#include <numeric>
using namespace std;

using ll = long long;

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

template<typename T>
constexpr T gcd(T a, T b)
{
	if (a < b) swap(a, b);

	if (a % b == 0) return b;
	else return gcd(b, a % b);
}

struct Rational
{
public:
	int64_t numerator;
	int64_t denominator;

public:
	Rational(int64_t numerator, int64_t denominator)
		: numerator(numerator), denominator(denominator)
	{
		assert(denominator != 0);
	}

	Rational& operator+=(const Rational& rhs)
	{
		auto newNumerator = numerator * rhs.denominator + rhs.numerator * denominator;
		auto newDenominator = denominator * rhs.denominator;
		if (newNumerator != 0)
		{
			auto g = gcd(abs(newNumerator), abs(newDenominator));
			numerator = newNumerator / g;
			denominator = newDenominator / g;
		}
		else
		{
			numerator = 0;
			denominator = 1;
		}
		return *this;
	}

	Rational& operator*=(const Rational& rhs)
	{
		auto newNumerator = numerator * rhs.numerator;
		auto newDenominator = denominator * rhs.denominator;
		if (newNumerator != 0)
		{
			auto g = gcd(abs(newNumerator), abs(newDenominator));
			numerator = newNumerator / g;
			denominator = newDenominator / g;

		}
		else
		{
			numerator = 0;
			denominator = 1;
		}
		return *this;
	}

	Rational& operator/=(const Rational& rhs)
	{
		return this->operator*=(Rational(rhs.denominator, rhs.numerator));
	}

	Rational& operator-=(const Rational& rhs)
	{
		return this->operator+=(Rational(-rhs.numerator, rhs.denominator));
	}

	Rational operator+(const Rational& rhs)
	{
		return *this += rhs;
	}

	Rational operator*(const Rational& rhs)
	{
		return *this += rhs;
	}

	Rational operator/(const Rational& rhs)
	{
		return *this /= rhs;
	}

	Rational operator-(const Rational& rhs)
	{
		return *this -= rhs;
	}

	explicit operator double()
	{
		return static_cast<double>(this->numerator) / static_cast<double>(this->denominator);
	}
};

int main()
{
	int N, K;

	cin >> N >> K;

	Rational ans(0, 1);
	rep(i, N)
	{
		Rational ans_partial(1, N);
		int point = i + 1;
		while (point < K)
		{
			point *= 2;
			ans_partial *= Rational(1, 2);
		}
		ans += ans_partial;
	}

	cout << std::fixed << std::setprecision(15) << static_cast<double>(ans) << endl;
}

Measured memory_bytes: 3792
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0, i##_len = (n); i < i##_len; ++i)
#define rep2(i, x, n) for(int i = x, i##_len = (n); i < i##_len; ++i)
#define all(n) begin(n), end(n)
using ll = long long;
using P = pair<int, int>;
using vi = vector<int>;
using vl = vector<ll>;
using vs = vector<string>;
using vc = vector<char>;
using vb = vector<bool>;
vi dir = {-1, 0, 1, 0, -1, -1, 1, 1, -1};

int main() {
  int n;
  string s;
  cin >> n >> s;
  int ans = 0;
  rep(i, 10) rep(j, 10) rep(k, 10) {
    int a = 0;
    vi nums = {i, j, k, 10};
    rep(m, s.size()) if(s[m] - '0' == nums[a]) a++;
    if(a == 3) ans++;
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
l,r=map(int,input().split())
import sys
mod=2019
ans=float('inf')

for i in range(l,r+1):
  for j in range(i+1,r+1):
    ans=min((i*j)%mod,ans)
    if ans==0:
      print(0)
      sys.exit()
print(ans)

Measured memory_bytes: 9176
#include<bits/stdc++.h>
using namespace std;
#define REP(i, n) for (int i = 0; i < (int)(n); i++)
#define FOR(i, a, b) for (int i= (a); i < (b); ++i)
typedef long long ll;
typedef pair<int,int> P;
const int INF = 100100100;
const int MOD = (int)1e9 + 7;
const double EPS = 1e-9;
int main() { ll N, K;
  cin >> N >> K;
  vector<ll> A(N);
  REP(i, N) cin >> A[i],A[i]--;
  ll now = 0,remainK=K;
  vector<int> rireki(0);
  bool t = true;//falseならループ済
  map<int,int> back{};
  while (0 < remainK) {
    remainK--;
    now = A[now];/*
    auto result = std::find(rireki.begin(), rireki.end(), now);
    if(result!=rireki.end()&&t){
      t = false;
      remainK %= (rireki.size() - distance(rireki.begin(), result));
    }else{
      rireki.push_back(now);
    }*/
    
    if (back[now]==1 && t) {
      auto result = std::find(rireki.begin(), rireki.end(), now);
      t = false;
      remainK %= (rireki.size() - distance(rireki.begin(), result));
    } else {
      back[now]=1;
      rireki.push_back(now);
    }
  }
  cout << now+1 << endl;
}

Measured memory_bytes: 12908
import java.util.*;
public class Main {
    static int ans = 0;
    static int n;
    public static void main(String[] args) {
        n = new Scanner(System.in).nextInt();
        dfs(0, 0);
        System.out.println(ans);
    }
    public static void dfs(long m, int check) {
        if (m > n) return;
        if (check == 0b111) ans++;
        dfs(10 * m + 3, check | 0b100);
        dfs(10 * m + 5, check | 0b010);
        dfs(10 * m + 7, check | 0b001);
    }
}

Measured memory_bytes: 21972