akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#include <atcoder/all>
using namespace std;
using namespace atcoder;
#define REP(i, n) FOR(i, 0, (n))
#define FOR(i, a, b) for(int i=(a); i<(b); i++)
#define LAR(a, b) ((a)=max((a),(b)))
#define SML(a, b) ((a)=min((a),(b)))
using ll = long long;
using ld = long double;
using vi = vector<int>;
using vl = vector<ll>;
using pii = pair<int, int>;
using vpii = vector<pair<int, int>>;
template<typename T>
using pque = priority_queue<T, vector<T>, greater<T>>;
#define PB push_back
#define EB emplace_back
#define MP make_pair
#define ALL(a) (a).begin(), (a).end()
#ifdef LOCAL_DEBUG
#define DEBUG(...) printf(__VA_ARGS__)
#else
#define DEBUG(...)
#endif

#define N 128
mf_graph<int> graph(N*N);
char s[N][N] = {};
int dy[4] = {1, 0, -1, 0};
int dx[4] = {0, 1, 0, -1};
char c[5] = "v>^<";

int main(){
	int n, m; scanf("%d%d", &n, &m);
	REP(i, n) scanf("%s", s[i+1]+1);
	FOR(i, 1, n+1){
		FOR(j, 1, m+1){
			if( (i+j) % 2 ){
				graph.add_edge(0, i*N+j, 1);
				if(s[i][j] != '.') continue;
				REP(h, 4){
					int y = i + dy[h], x = j + dx[h];
					if(s[y][x] != '.') continue;
					graph.add_edge(i*N+j, y*N+x, 1);
				}
			} else {
				graph.add_edge(i*N+j, 1, 1);
			}
		}
	}
	int res = graph.flow(0, 1);
	printf("%d\n", res);
	for(auto e : graph.edges()){
		int i = e.from / N, j = e.from % N;
		int y = e.to / N, x = e.to % N;
		if(!e.flow) continue;
		REP(h, 4){
			if(i + dy[h] != y || j + dx[h] != x) continue;
			s[i][j] = c[h];
			s[y][x] = c[h^2];
		}
	}
	REP(i, n) printf("%s\n", s[i+1]+1);
}



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

using namespace std;

int main() {
    queue<pair<string, int> > que;
    int n, q;
    scanf("%d %d", &n, &q);

    string name;
    int time;
    rep(i, n) {
        cin >> name;
        scanf("%d", &time);
        que.push(make_pair(name, time));
    }

    int totalT = 0;
    while (!que.empty()) {
        pair<string, int> top = que.front();
        if (top.second <= q) {
            totalT += top.second;
            cout << top.first;
            printf(" %d\n", totalT);
        } else {
            totalT += q;
            que.push(make_pair(top.first, top.second - q));
        }
        que.pop();
    }
}


Measured memory_bytes: 6360
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int N, X, D;
  int count = 1;
  cin >> N >> X;
  int L[100];
  for (int i = 0; i < N; i++) {
    cin >> L[i];
  }
   for (int i = 0; i < N; i++) {
    D = D + L[i];
      if ( D > X ) break;
    count++;
  }
  cout << count << endl;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner cin = new Scanner(System.in);
        int A = cin.nextInt();
        int B = cin.nextInt();
        int C = cin.nextInt();
        int X = cin.nextInt();
        int cnt = 0;
        for (int a = 0; a <= A; a++) {
            for (int b = 0; b <= B; b++) {
                for (int c = 0; c <= C; c++) {
                    int x = (a * 500) + (b * 100) + (c * 50);
                    if (x == X) cnt++;
                }
            }
        }
        System.out.println(cnt);
    }
}

Measured memory_bytes: 23764
#include <iostream>
#include <vector>
#include <algorithm>
#include <cstring>
#include <string>
#include <cmath>
#include <map>
#include <limits>
#include <queue>
#include <set>
using namespace std;
typedef long long int lld;
int T;
lld N, A, B;
int main(void){
    cin >> N >> A >> B;
    lld k = N/(A+B) * A;
    N%(A+B) >= A? k += A : k += N%(A+B);
    cout << k;
    return 0;
}

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

const int maxn = 1e5 + 10;

int w[maxn], v[maxn];
long long dp[maxn];

int main() {
    int n, W;
    scanf("%d %d", &n, &W);
    for (int i = 1; i <= n; ++i) {
        scanf("%d %d", &w[i], &v[i]);
    }

    for (int i = 1; i <= n; ++i) {
        for (int j = W; j >= w[i]; --j) {
            dp[j] = max(dp[j], dp[j - w[i]] + v[i]);
        }
    }
    printf("%lld\n", dp[W]);
}

Measured memory_bytes: 1024
import java.util.*;

public class Main {
	static public void main(String args[]){
		Scanner sc=new Scanner(System.in);
		 
		 String str=sc.next();
		 
		 if((str.charAt(0))==(str.charAt(1))&&
		 (str.charAt(2))==(str.charAt(1))&&
		 (str.charAt(0))==(str.charAt(2))){
		 	System.out.print("No");
		 }
		 else{
		 	System.out.print("Yes");
		 }
	}
}

Measured memory_bytes: 35424
n, m = map(int,input().split())
num = [1 for i in range(n+1)]
red = [False for i in range(n+1)]
red[1] = True
for i in range(m):
  x, y = map(int,input().split())
  red[y] |= red[x]
  num[x] -= 1
  num[y] += 1
  if num[x] == 0:
    red[x] = False
print(red.count(True))

Measured memory_bytes: 10600
#include <bits/stdc++.h>
using namespace std;
bool check (char *s1, char *s2)
{
    //cout<<s1 << " " << s2 << endl;
    int len = strlen(s1);
   int cnt = 0;
    for(int i = 0; i < len; i++)
    {
        if(s1[i] == s2[i])
            cnt++;
    }

    if(cnt == len)
        return true;
    else
        return false;
}
int main()
{
    int n;

    while(cin >> n)
    {
        char s1[9], s2[9], temp[9];
        int i;
        for(i = 0; i < n; i++)
        {
            char ch;
            cin >> ch;
            s1[i] = ch;
            temp[i] = ch;
        }
        s1[i] = '\0';
        temp[i] = '\0';
        for(i = 0; i < n; i++)
        {
            char ch;
            cin >> ch;
            s2[i] = ch;
        }
        s2[i] = '\0';

       // cout<< temp << endl;
        int l = strlen(temp), pos1 = 0, pos2 = 0;
        sort(temp, temp + l);
        int cnt = 1;
        do{
              //  cout<< temp << endl;
            if(check(temp, s1) == true)
            {
               // cout<< temp << " " << s1 << endl;
                pos1 = cnt;
            }
            if(check(temp, s2) == true)
            {
                pos2 = cnt;
            }
            cnt++;
        }while(next_permutation(temp, temp + l));//

        cout<< abs(pos1 - pos2) << endl;

    }
}


Measured memory_bytes: 256
#include <stdio.h>
#define STR_MAX 128

int main(void) {
	int i, oidx, num, compress;
	char in[STR_MAX], out[STR_MAX];

	while (scanf("%s ", in) != EOF) {
		oidx = compress = 0;
		num = 1;
		for (i = 0; in[i] != '\0'; i++) {
			if (in[i] == '@') {
				compress = 1;
			} else if (compress) {
				compress = 0;
				num = in[i] - '0';
			} else {
				while (num--) {
					out[oidx++] = in[i];
				}
				num = 1;
			}
		}
		out[oidx] = '\0';
		printf("%s\n", out);
	}
	return 0;
}

Measured memory_bytes: 528
#include <bits/stdc++.h>
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
using namespace std;
using ll = long long;
const double PI = 3.14159265358979323846;

int main() {
  int n;
  cin >> n;
  int ans = 0;
  if(1 <= n && n < 10) ans = n;
  else if(10 <= n && n < 100) ans = 9;
  else if(100 <= n && n < 1000) ans = (n - 100) + 1 + 9;
  else if(1000 <= n && n < 10000) ans = 909;
  else if(10000 <= n && n < 100000) ans = (n - 10000) + 1 + 909;
  else if(n == 100000) ans = 90909;
  
  cout << ans << endl;
}

Measured memory_bytes: 3588
import java.util.Arrays;
import java.util.Collections;
import java.util.Scanner;

public class Main {

  public static void main(String[] args) {
    Scanner scanner = new Scanner(System.in);

    int N = scanner.nextInt();
    Integer[] A = new Integer[N];

    for (int i = 0; i < N; i++) {
      A[i] = scanner.nextInt();
    }
    Arrays.sort(A, Collections.reverseOrder());
    int Alice = 0;
    int Bob = 0;
    for (int i = 0; i < N; i+=2) {
      Alice += A[i];
      if (i+1 < N) {
         Bob += A[i+1];
      }
    }

    System.out.println(Alice-Bob);
  }

}


Measured memory_bytes: 23764
#include<bits/stdc++.h>
#define  ll  unsigned long long int
#define  sz  200010

using namespace std;


ll check(string s)
{
    ll l=0;
    ll h=s.length()-1;

    while(h>l)
    {
        if(s[l++]!=s[h--])return 0;
    }
    return 1;

}


int main()
{

    string s,a="",b="";

    ll i,j,c=0,x,y,d;

    cin>>s;

    ll n=s.length();

    d=(n-1)/2;

    for(i=0;i<d;i++)a+=s[i];

    d=(n+3)/2;

    for(i=d-1;i<n;i++)b+=s[i];


    if(check(s))c++;
    if(check(a))c++;
    if(check(b))c++;

  //  cout<<a<<" "<<b<<endl;

    if(c==3)cout<<"Yes"<<endl;
    else
        cout<<"No"<<endl;


    return 0;
}


Measured memory_bytes: 256
#[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, usize1) => {
        read_value!($next, usize) - 1
    };

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

#[allow(unused_macros)]
macro_rules! debug {
    ($($a:expr),*) => {
        #[cfg(debug_assertions)]
        writeln!(&mut std::io::stderr(), concat!("[DEBUG] ", $(stringify!($a), "={:?} "),*), $($a),*);
    }
}

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

#[allow(unused_imports)]
use std::io::Write;

fn main() {
    input!{
      n: i64,
    }
    let mut skip = n;
    if n%2 == 1 {
        skip -= 1;
    }
    let mut e = vec![];
    for i in 1..n+1 {
        for j in i+1..n+1 {
            if !(i == j || j == skip) {
                e.push((i, j));
            }
        }
        skip -= 1;
    }
    println!("{}", e.len());
    for (a, b) in e {
        println!("{} {}", a, b);
    }
}


Measured memory_bytes: 4352
#include <bits/stdc++.h>
#define PB push_back
#define MP make_pair
#define REP(i,n) for (int i=0;i<(n);i++)
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define ALL(a) (a).begin(),(a).end()
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> P;
ll memo[4000][4000];
int dat[4000];
int n;
ll rec(int a,int b,int turn){
	if(memo[a][b]!=-1)return memo[a][b];
	if(a==b){
		if(turn)return memo[a][b]=dat[a];
		return memo[a][b]=0;
	}
	if(turn){
		return memo[a][b]=max(rec(a+1,b,0)+(ll)dat[a],rec(a,b-1,0)+(ll)dat[b]);
	}
	if(dat[a]>dat[b])return memo[a][b]=rec(a+1,b,1);
	return memo[a][b]=rec(a,b-1,1);
}
int main(){
	memset(memo,-1,sizeof(memo));
	cin>>n;
	REP(i,n)cin>>dat[i];
	REP(i,n)dat[i+n]=dat[i];
	ll ans=0;
	REP(i,n){
		ans=max(ans,rec(i+1,i+n-1,0)+(ll)dat[i]);
	}
	cout<<ans<<endl;
}

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

l = []
now = 1 # 今見ている数(1から見る配列を作りたいので1で初期化)
cnt = 0

# lには(1の個数),(0の個数),(1の個数),(0の個数),...(1の個数)という感じのリストを入れたい(両端が0から始まるとしても1が0こあるとしてカウントしたい)
for i in range(N):
    if int(S[i]) == now:
        cnt += 1
    else:
        l.append(cnt)
        cnt = 1
        now = 1 - now # 0と1を切り替える(now ^= 1でも良い)
if cnt != 0:
    l.append(cnt)
if len(l) % 2 == 0: # (1の個数),(0の個数),(1の個数),(0の個数),...(0の個数)となってしまっていたら最後に0を入れておく
    l.append(0)
#print(l)

ans = 0
width = 2 * K + 1

# 累積和
# 元のリストが[0, 1, 2, 3, 4, 5]の時に[0, 1, 2, 3, 4, 5, 6]のように個数は+1になる(つまり最初は0)
lsum = [0 for _ in range(len(l) + 1)] # len(l)+1個の要素
for i in range(len(l)): # 0からlen(l)まで
    lsum[i + 1] = lsum[i] + l[i]
#print(lsum)

for i in range(0, len(l), 2): # ここを2ごとにすることで1の個数を数えられる
    left = i
    right = min(i + width, len(l))
    tmp = lsum[right] - lsum[left] # [left, right)
    ans = max(ans, tmp)

"""
# しゃくとり法

# ①forループの外側にleft,rightを持っておく
left = 0
right = 0
tmp = 0 # [left, right)の総和

for i in range(0, len(l), 2):
    # ②次のleft,rightを計算する
    nextleft = i # 0,2,4,...
    nextright = min(i + width, len(l)) # 0+width,2+width,...

    # ③左端の移動
    while nextleft > left:
        tmp -= l[left]
        left += 1

    # ③右端の移動
    while nextright > right:
        tmp += l[right]
        right += 1

    ans = max(ans, tmp)
"""

"""
# 愚直に足し算を繰り返すとTLE

for i in range(0, len(l), 2): # ここを2ごとにすることで1の個数を数えられる
    tmp = 0
    left = i
    right = min(i + width, len(l))
    for j in range(left, right): # leftからright-1まで
        tmp += l[j]
    ans = max(ans, tmp)
"""

print(ans)


Measured memory_bytes: 8004
#include<bits/stdc++.h>
using namespace std;
 
string dp[26][21];
string Z="{";
 
void init(){
  for(int i=0;i<26;i++){
    for(int j=0;j<=20;j++){
      dp[i][j]=Z;
    }
  }
}
 
int N,M;
string from[50],to[50];
 
bool check(int id){
  int sd=from[id][0]-'A';
   
  if( to[id]=="" ){
    bool res=( dp[sd][0] == Z );
    dp[sd][0]="";
    return res;
  }
   
  string t[21];
  for(int i=0;i<=M;i++)t[i]=Z;
  t[0]="";
 
  bool allZero=true;
   
  for(int i=0;i<(int)to[id].size();i++){
    char ch=to[id][i];
    if('A'<=ch&&ch<='Z'){
      int target=ch-'A';
      if( dp[target][0] == Z )allZero=false;
       
      for(int j=M;j>=0;j--){
        if( dp[target][0]==Z )  t[j]=Z;
         
        for(int k=j;k>=0;k--){
          if(t[j-k]!=Z && dp[target][k]!=Z){
            t[j]=min(t[j],t[j-k]+dp[target][k]);
          }
        }
      }
       
    }else{
      allZero=false;
      for(int j=M;j>=1;j--){
        if(t[j-1]!=Z)t[j]=t[j-1]+ch;
        else t[j]=Z;
      }
      t[0]=Z;
    }
  }
   
  bool res=false;
  for(int i=1;i<=M;i++){
    if(dp[sd][i]>t[i]){
      dp[sd][i]=t[i];
      res=true;
    }
  }
     
  if( allZero && dp[sd][0]==Z){
    res=true;
    dp[sd][0]="";
  }
   
  return res;
}
 
int main(){
  while(1){
    cin>>N>>M;
    if(N==0&&M==0)break;
    init();
    for(int i=0;i<N;i++){
      string str;
      cin>>str;
      int index=str.find('=');
      from[i]=str.substr(0,index);
      if(index+1 == (int)str.size()){
        to[i]="";
      }else{
        to[i]=str.substr(index+1);
      }
    }
    bool update=true;
    while(update){
      update=false;
      for(int i=0;i<N;i++){
        update=(update||check(i));
      }
    }
    string ans = dp[ 'S'-'A' ][ M ];
    if(ans==Z)cout<<'-'<<endl;
    else cout<<ans<<endl;
  }
  return 0;
}

Measured memory_bytes: 3180
#include "bits/stdc++.h"
#include <boost/multi_array.hpp>
#include <boost/optional.hpp>
#include <boost/range/irange.hpp>
#include <boost/range/algorithm.hpp>
#include <boost/range/adaptors.hpp>
#include <boost/dynamic_bitset.hpp>
namespace adaptor = boost::adaptors;
using index_t = std::size_t;

namespace lib
{
	using graph_t = std::vector<std::set<index_t>>;
	template<class T>using weighted_graph_t = std::vector<std::map<index_t, T>>;

	struct max_t
	{
		template<class T>constexpr T operator()(T const& lhs, T const& rhs)const
		{
			return std::max(lhs, rhs);
		}
	};
	struct min_t
	{
		template<class T>constexpr T operator()(T const& lhs, T const& rhs)const
		{
			return std::min(lhs, rhs);
		}
	};

	constexpr max_t max;
	constexpr min_t min;

	template<class T>auto order_by(T func)
	{
		return [=](auto&& lhs, auto&& rhs)
		{
			return func(lhs) < func(rhs);
		};
	}

	template<class T>constexpr auto max_v = std::numeric_limits<T>::max();
	template<class T>constexpr auto min_v = std::numeric_limits<T>::min();

	template<class T>using p_queue = std::priority_queue<T, std::vector<T>, std::greater<>>;
}

void Main()
{
	int N;
	std::cin >> N;
	int count = 0;
	for (auto i : boost::irange(N))
	{
		auto idx = i + 1;
		int v;
		std::cin >> v;
		if (idx % 2 == 1 && v % 2 == 1)
		{
			++count;
		}
	}
	std::cout << count << std::endl;
}

int main()
{
	std::cin.tie(nullptr);
	std::ios_base::sync_with_stdio(false);
	std::cout << std::fixed << std::setprecision(15);
	Main();
}

Measured memory_bytes: 3636
// Insertions Sort

#include <stdio.h>

void printer(int n,int data[]){
  for (int i = 0; i < n; i++ ){
    //左端の場合は空白を入力しない
    if (i > 0) printf(" ");
      printf("%d",data[i]);
  }
}
// Sort func


int sort(int n,int data[]){
  
  //未ソートの開始位置でループ
  int v; // 被ソート要素の値
  int j; // 既ソート位置の右端
  for (int i = 0; i < n; i++){
    
    v = data[i];
    j = i-1;
    //既ソート配列を右にずらす
    while((j >= 0) && (data[j] >= v)){
      data[j+1] = data[j];
      j--;
    }
    //値の挿入
    data[j+1] = v;
    
    printer(n,data);
    printf("\n");
  }
  return 0;
}



int main(){
  int n;
  int data[100];
  //入力値処理
  scanf("%d",&n); // nに入力
  //配列に値を入力
  for (int i = 0; i <= n-1; i++ ){
    scanf("%d",&data[i]);
  }
  //初期配列の表示
  //printer(n,data);
  //printf("\n");
  sort(n,data);
  return 0;

}










Measured memory_bytes: 2056
import java.util.*;


public class Main {
    public static void main(String[] args) {
        // 自分の得意な言語で
        // Let's チャレンジ！！

        Scanner sc = new Scanner(System.in);
      int n=sc.nextInt();
      int m=sc.nextInt();
      int []num=new int[n];
      for(int i=0;i<n;i++){
      	num[i]=sc.nextInt();
      }
      Arrays.sort(num);
      int ans=0;
      for(int i=0;i<n;i++){
      	if(num[i]<=m){
        ans++;
          m-=num[i];
        }
      }
      if(ans==n&&m>0)ans--;
        System.out.println(ans);
    }
}

Measured memory_bytes: 22600
#include<bits/stdc++.h>
using namespace std;
int main()
{
 int n,m;
 cin>>n>>m;
 int h[n];
 int i;
 for(i=0;i<n;i++)
 cin>>h[i];
 vector<int> v[n];
 for(i=0;i<m;i++)
 {
 	int x,y;
 	cin>>x>>y;
 	x--;
 	y--;
 	v[x].push_back(y);
 	v[y].push_back(x);
 }
 int ans=0;
 for(i=0;i<n;i++)
 {
 	int j=0,f=0;
 	for(j=0;j<v[i].size();j++)
 	{
 		if(h[i]>h[v[i][j]])
 		continue;
 		else
 		{
 		  f=1;
		   break;	
		}
	}
	if(f==0)
	ans++;
 }
 cout<<ans<<endl;
 return 0;
}


Measured memory_bytes: 9116
#include<bits/stdc++.h>
using namespace std;
#define rep(i,a,n) for (int i=a;i<n;i++)
#define per(i,a,n) for (int i=n-1;i>=a;i--)
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(),(x).end()
#define fi first
#define se second
#define SZ(x) ((int)(x).size())
typedef vector<int> VI;
typedef long long ll;
typedef pair<int,int> PII;
const ll mod=1000000007;
ll powmod(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 gcd(ll a,ll b){return b?gcd(b,a%b):a;}

const int N=1e6+10; 
int n,m;
int a[N],sum=0;
int main(){
	scanf("%d%d",&n,&m);
	rep(i,0,m){
		scanf("%d",&a[i]);
		sum+=a[i];
	}
	if(sum>n)puts("-1");
	else printf("%d",n-sum);
    return 0;
}


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

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

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <utility>
#include <stack>
#include <numeric>
#include <algorithm>
#include <stdio.h>
#include <bitset>
#include <complex>
#include <iomanip>
using namespace std;
#define MM 1000000000
#define MOD MM+7
#define pi pair<int32,int32>
#define pl pair<int64,int64>
#define chmax(a,b) (a<b ? a=b:0)
#define chmin(a,b) (a>b ? a=b:0)
const long double PI = acos(-1);
const long long INF = 1e15;
int dx[8] = {-1,0,1,0,-1,-1,1,1};
int dy[8] = {0,-1,0,1,-1,1,1,-1};
template<typename T>
T GCD(T u,T v){
    return v ? GCD(v,u%v) : u;
}
int main(){
    int q; cin >> q;
    vector<int> v(0);
    for(int i = 0; i < q; i++){
        int n; cin >> n;
        if (n == 0){
            int x; cin >> x;
            v.push_back(x);
        } else if (n == 1){
            int x; cin >> x;
            cout << v[x] << endl;
        } else if (n == 2){
            v.pop_back();
        }
    }
}
  




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

int main() {
    int n;
    cin >> n;
    vector<int> d(n);
    for (int i=0; i<n; i++) cin >> d[i];

    vector<int> num(101);
    for (int i=1; i<=100; i++) num[i] = 0;

    for (int i=0; i<n; i++) num[d[i]]++;

    int count = 0;
    for (int i=1; i<=100; i++) {
        if (num[i] > 0) count++;
    }
    cout << count << endl;

    return 0;
}


Measured memory_bytes: 256
# C - Cat Snuke and a Voyage

N, M = map(int, input().split())
destination = [[] for _ in range(N)] # 島iから直接行ける島のリスト

for _ in range(M):
    a, b = map(int, input().split())
    destination[a-1].append(b-1)
    
for mid in destination[0]:
    if N-1 in destination[mid]:
        print("POSSIBLE")
        exit()
            
print("IMPOSSIBLE")

Measured memory_bytes: 29068
using System;
using System.Collections.Generic;
using static System.Console;
using System.Linq;

namespace ConsoleApp2
{
    class Program {
        static void Main(string[] Args) {
            long res = 1;
            int N = int.Parse(ReadLine());
            int mod = 1000000007;
            for (int i = 1; i <= N; i++) {
                res *= i;
                res %= mod;
            }

            WriteLine(res);

            ReadLine();
        }
    }
}


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

using namespace std;
using ll = long long;
typedef pair<int, int> ii;
typedef vector<ii> vii; 
typedef vector<int> vi;

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

	int x, y;
	cin >> x >> y;
	for(int i = 0; i <= x; i++) {
		for(int j = 0; j <= y; j++) {
			if(i + j == x && (2*i + 4*j == y)) {
				cout << "Yes" << endl;
				return 0;
			}
		}
	}
	
	cout << "No" << endl;
	return 0;
}

Measured memory_bytes: 3648
//! ----------------------------------------------
//! Framework <https://github.com/vain0x/procon>
//!
//! See the bottom of file for solution.
//! ----------------------------------------------

#![allow(unused_imports)]
#![allow(non_snake_case)]

use std::cell::RefCell;
use std::cmp::{max, min, Ordering};
use std::collections::*;
use std::fmt::{Debug, Display, Formatter, Write as FmtWrite};
use std::io::{stderr, stdin, BufRead, Write};
use std::mem::{replace, swap};
use std::ops::*;
use std::rc::Rc;

/// Print values to standard error if debug mode.
#[allow(unused_macros)]
macro_rules! debug {
    ($($e:expr),*) => {
        #[cfg(debug_assertions)]
        $({
            let (e, mut err) = (stringify!($e), stderr());
            writeln!(err, "\x1B[33m{}\x1B[0m = {:?}", e, $e).unwrap()
        })*
    };
}

/// Read from standard input and parse each word.
/// - `read!(T, U, ..)` parses a line as a tuple of words.
/// - `read![[T]]` parses a line as an array of words.
/// - `read![..; N]` parses `N` lines, using `read!(..)` repeatedly.
#[allow(unused_macros)]
macro_rules! read {
    ([$t:ty] ; $n:expr) =>
        ((0..$n).map(|_| read!([$t])).collect::<Vec<_>>());
    ($($t:ty),+ ; $n:expr) =>
        ((0..$n).map(|_| read!($($t),+)).collect::<Vec<_>>());
    ([$t:ty]) =>
        (rl().split_whitespace().map(|w| w.parse().unwrap()).collect::<Vec<$t>>());
    ($($t:ty),*) => {{
        let buf = rl();
        let mut w = buf.split_whitespace();
        ($(w.next().unwrap().parse::<$t>().unwrap()),*)
    }};
}

/// Read a line from standard input.
#[allow(dead_code)]
fn rl() -> String {
    let mut buf = String::new();
    stdin().read_line(&mut buf).unwrap();

    #[allow(deprecated)]
    buf.trim_right().to_owned()
}

// -----------------------------------------------
// Solution
// -----------------------------------------------

fn main() {
    let N = read!(usize);
    let V = read![[i64]];
    let C = read![[i64]];

    let mut m = 0;
    for s in 0..(1 << N) {
        let mut X = 0;
        let mut Y = 0;

        for i in 0..N {
            if (s & (1 << i)) != 0 {
                X += V[i];
                Y += C[i];
            }
        }
        m = max(m, X - Y)
    }

    println!("{}", m)
}


Measured memory_bytes: 4352
#include <bits/stdc++.h>
#define ll long long
#define pq priority_queue
using namespace std;
const ll INF=(ll)1e9;
const ll MOD=(ll)1e9+7;
const ll MAX=510000;
vector<int> dx={1,0,-1,0},dy={0,1,0,-1};
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; }

int main(){
    ll N,K,ans=0;
    cin>>N>>K;
    vector<ll> A(N);
    for(ll i=0;i<N;i++) cin>>A[i];
    for(ll i=0;i<N;i++){
        ll r=0,w=0,sum;
        for(ll j=0;j<N;j++){
            if(i<j&&A[i]<A[j]) r++;
            else if(i<j&&A[i]>A[j]) w++;
        }
        sum=K*(K+1)/2;
        sum%=MOD;
        ans+=w*sum;
        ans%=MOD;
        sum=K*(K-1)/2;
        sum%=MOD;
        ans+=r*sum;
        ans%=MOD;
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cstring>
#include <cmath>
#include <list>
#define pie 3.141592653589793
#define si(a) scanf("%d",&a)
#define ss(a) scanf("%s",a)
#define sl(a) scanf("%lld",&a)
#define pi(a) printf("%d",a)
#define pl(a) printf("%lld",a)
#define ps(a) printf("%s",a)
#define ll long long
using namespace std;
int main()
{
  string s1,s2;
  cin >> s1 >> s2;
  bool ok = 0;
  if((s1[0]==s2[2]) && (s1[1]==s2[1]) && (s1[2]==s2[0]) )
    ok=1;
  if(ok)
    cout << "YES" << endl;
  else
    cout << "NO" << endl;
  return 0;
}


Measured memory_bytes: 256
#include <cstdio>
#include <queue>

using namespace std;

int main(){
  deque<int> que;
  int n;
  while(~scanf("%d",&n)){
    if(n){
      que.push_back(n);
    }else{
      printf("%d\n",que.back());
      que.pop_back();
    }
  }
}

Measured memory_bytes: 1032
#include <bits/stdc++.h>
 
using namespace std;
 
#define INF 1001000100010001000
#define MOD 1000000007
#define EPS 1e-10
#define int long long
#define rep(i, N) for (int i = 0; i < N; i++)
#define Rep(i, N) for (int i = 1; i < N; i++)
#define For(i, a, b) for (int i = (a); i < (b); i++)
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define i_i pair<int, int>
#define vi vector<int>
#define vvi vector<vi >
#define vb vector<bool>
#define vvb vector<vb >
#define vp vector< i_i >
#define all(a) (a).begin(), (a).end()
#define Int(x) int x; scanf("%lld", &x);
#define int2(x, y) int x, y; scanf("%lld %lld", &x, &y);
 
//int dxy[5] = {0, 1, 0, -1, 0};
// assign
 
signed main()
{
    string s;
    cin >> s;

    rep(i, s.size()-1) {
        if (s[i] == s[i+1]) {
            cout << i+1 << " " << i+2 << endl;
            return 0;
        }
    }

    rep(i, s.size()-2) {
        if (s[i] == s[i+2]) {
            cout << i+1 << " " << i+3 << endl;
            return 0;
        }
    }
    cout << -1 << " " << -1 << endl;

    return 0;
}



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

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

  int cnt = 0;
  for (int i = 0; i < 1000; i++) {
    // コンテナに各桁の数字をセットする
    vector<int> v(3);
    v.at(0) = i / 100;
    v.at(1) = (i/10) % 10;
    v.at(2) = i % 10;

    int v_index = 0;
    for (int j = 0; j < n; j++) {
      char c = '0' + v.at(v_index);
      if (s.at(j) == c) {
        v_index++;
        if (v_index == 3) {
          cnt++;
          break;
        }
      }
    }
  }

  cout << cnt << endl;
  return 0;
}


Measured memory_bytes: 3688
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
using namespace std;
typedef long long ll;
typedef unsigned long long int ull;
#define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>
#define ff first
#define ss second
#define pb push_back
#define Inf  1e18
#define inf -1e18
#define mod 1000000007
using vll = vector<ll>;
using vvll = vector<vector<ll>>;
using mll = map<ll,ll>;
using umll = unordered_map<ll,ll>;
using sll = set<ll>;
using msll = multiset<ll>;
using pll = pair<ll,ll>;
 
ll MUL(ll A,ll B){
  return (A%mod*B%mod)%mod;
}
 
ll ADD(ll A,ll B){
  return (A%mod+B%mod)%mod;
}
 
ull power(ll A,ll B) {
    ull RES = 1;
    while (B > 0)
    {
        if (B & 1)
            RES = RES*A;
        B = B>>1;
        A = A*A;
    }
  return RES;
}
 
 const ll MAXN = 1e7+5;
 int spf[MAXN];

 
 
 
 void sieve() 
{ 
    spf[1] = 1; 
    for (int i=2; i<MAXN; i++)  
        spf[i] = i; 
    for (int i=4; i<MAXN; i+=2) 
        spf[i] = 2; 
  
    for (int i=3; i*i<MAXN; i++) 
    {  
        if (spf[i] == i) 
        {  
            for (int j=i*i; j<MAXN; j+=i) 
                if (spf[j]==j) 
                    spf[j] = i; 
        } 
    } 
} 

unordered_map<ll,ll> getFactorization(ll x) 
{ 
    unordered_map<ll,ll> MAP; 
    while (x != 1) 
    { 
        MAP[spf[x]]++;
        x = x / spf[x]; 
    } 
    return MAP; 
} 

void testcases(int cases){
	ll n;
	cin >> n ;
	ll ans = 1;
	ll sum = 0;
	for(int i = 1 ;i <= n ; i ++){
			unordered_map<ll,ll> M = getFactorization(i);
			ans = 1;
			for(auto it :M){
				ans = ans*(it.ss+1);
			}
			sum = sum + ans*i ;
	}
	cout << sum << "\n";
}
int main()
{
	sieve();
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
    ll t;
    t = 1;
    //t = 1;
    ll Case =1 ;
    while(t--)
    {
      testcases(Case++);
    }
}


Measured memory_bytes: 42620
#include <iostream> 
#include<vector>
#include<algorithm>
#include<map>
#include<iomanip>
#include<set>
#include<queue>
#include<deque>
#include<iomanip>
#include<sstream>
#include<cmath>
#include<bitset>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define req(i,n) for(int i = 1;i <=  n; i++)
#define rrep(i,n) for(ll i = n-1;i >= 0;i--)
#define ALL(obj) begin(obj), end(obj)
#define RALL(a) rbegin(a),rend(a)
typedef long long int ll;
typedef long double ld;
const ll INF = 1e18;
template<typename A, size_t N, typename T>
void Fill(A(&array)[N], const T & val) {
    std::fill((T*)array, (T*)(array + N), val);
}
const int MOD = 1e9+7;
int main(void) {
    int n; cin >> n; vector<int> a(n);
    rep(i, n) cin >> a[i];
    sort(ALL(a)); int ans = a[0],sum = a[n-1];
    sum = sum - ans;
    req(i, n - 2)  sum += abs(a[i]);
    cout << sum << endl;
    sum = a[n - 1];
    req(i, n - 2) {
        if (a[i] < 0)cout << sum << " " <<a[i] << endl, sum -= a[i];
        else cout << ans << " " << a[i]<<endl, ans -= a[i];
    }cout << sum << " " << ans << endl;
}

Measured memory_bytes: 3788
def ketatashi(a):
	a = str(a)
	ans = 0
	
	for i in range(len(a)):
		ans = ans + int(a[i])
	
	return ans
	

n = int(input())

min = 100

if n == 2:
	print(2)
	exit()

for i in range(1,n//2):
	if ketatashi(i) + ketatashi(n-i) < min :
		min = ketatashi(i) + ketatashi(n-i)
	

print(min)

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


int main(){
    vector<char> S(3);
    bool A=false;
    bool B=false;
    for(int i=0;i<3;i++){
        cin >> S.at(i);
        if(S.at(i)=='A') A=true;
        if(S.at(i)=='B') B=true;
    }
    if(A && B){
      cout << "Yes";
    }
    else{
      cout << "No";
    }
    


}
    

Measured memory_bytes: 256
import java.util.ArrayList;
import java.util.Scanner;

public class Main {

	static int[] hateNumberArray;
	static int k = 0;

	public static void main(String[] args) {

		int anser = 0;
		int payment = 0;
		int[] splitNumberArray = new int[4];

		Scanner scan = new Scanner(System.in);
		payment = scan.nextInt();
		k = scan.nextInt();

		anser = payment;

		hateNumberArray = new int[k];

		for (int i = 0; i < k; i++) {
			hateNumberArray[i] = scan.nextInt();
		}

		while (anser < 100000) {

			if (isHateNumber(splitNumber(anser))) {
				anser++;
			} else {
				break;
			}
		}

		System.out.println(anser);

	}

	//整数を桁ごとに分解する処理
	private static ArrayList<Integer> splitNumber(int number) {
		ArrayList<Integer> numberArray = new ArrayList<>();
		numberArray.add(number % 10);
		if (number >= 10) {
			numberArray.add((number - numberArray.get(0)) / 10 % 10);
		}
		if (number >= 100) {
			numberArray.add((number - numberArray.get(1) * 10 - numberArray.get(0)) / 100 % 10);
		}
		if (number >= 1000) {
			numberArray.add((number - numberArray.get(2) * 100 - numberArray.get(1) * 10
					- numberArray.get(0)) / 1000 % 10);
		}
		if (number >= 10000) {
			numberArray.add((number - numberArray.get(3) * 1000 - numberArray.get(2) * 100 - numberArray.get(1) * 10
					- numberArray.get(0)) / 10000);
		}
		return numberArray;

	}

	//嫌いな数字が含まれているか
	private static boolean isHateNumber(ArrayList<Integer> numberArray) {
		for (int j = 0; j < numberArray.size(); j++) {
			for (int i = 0; i < k; i++) {
				if (numberArray.get(j) == hateNumberArray[i]) {
					return true;
				}
			}

		}
		return false;
	}

}


Measured memory_bytes: 32476
#include <bits/stdc++.h>
using namespace std;
using lint = long long int;
using pint = pair<int, int>;
using plint = pair<lint, lint>;
struct fast_ios { fast_ios(){ cin.tie(0); ios::sync_with_stdio(false); cout << fixed << setprecision(20); }; } fast_ios_;

#define ALL(x) (x).begin(), (x).end()
#define FOR(i, begin, end) for(int i=(begin),i##_end_=(end);i<i##_end_;i++)
#define IFOR(i, begin, end) for(int i=(end)-1,i##_begin_=(begin);i>=i##_begin_;i--)
#define REP(i, n) FOR(i,0,n)
#define IREP(i, n) IFOR(i,0,n)


void solve(long long X, long long t){
    cout << max(0LL, X-t) << endl;
}

int main(){

    long long X;
    scanf("%lld",&X);
    long long t;
    scanf("%lld",&t);
    solve(X, t);
    return 0;
}



Measured memory_bytes: 256
#include<cstdio>
#include<cstring>
#include<algorithm>
#define lowbit(x) ((x)&(-x))
using namespace std;
typedef long long ll;
const int N=2e5+100,mod=1e9+7;
int a[N],b[N],L[N],R[N],h[N];
bool cmp(int n1,int n2) {return (n1<n2);}
bool cmp1(int n1,int n2) {return (R[n1]<R[n2]);}
bool cmp2(int n1,int n2){
	if(L[n1]==L[n2]) return (R[n1]<R[n2]);
	return (L[n1]>L[n2]);
}
int maxn,tree[N];
void add(int x,int c){
	for(int i=x;i<=maxn;i+=lowbit(i))
		tree[i]=(tree[i]+c)%mod;
}
int find(int x){
	int Sum=0;
	for(int i=x;i;i-=lowbit(i))
		Sum=(Sum+tree[i])%mod;
	return Sum;
}
int main()
{
	int n,m;
	scanf("%d%d",&n,&m);
	for(int i=1;i<=n;i++) scanf("%d",&a[i]);
	for(int i=1;i<=m;i++) scanf("%d",&b[i]);
	sort(a+1,a+n+1,cmp);
	sort(b+1,b+m+1,cmp);
	int id=1;
	while(id<=n&&a[id]<b[1]) id++;
	int sum=0;
	for(int i=1;i<m;i++){
		while(id<=n&&a[id]<b[i+1]){
			L[++sum]=a[id]-b[i];
			R[sum]=b[i+1]-a[id];
			h[sum]=sum;id++;
		}
	}
	sort(h+1,h+sum+1,cmp1);
	int sum2=1;
	for(int i=1;i<=sum;i++){
		int t=sum2;
		if(R[h[i]]!=R[h[i+1]]) sum2++;
		R[h[i]]=t;
	}
	sort(h+1,h+sum+1,cmp2);
	maxn=sum2+1;add(maxn,1);
	for(int i=1;i<=sum;i++){
		if(i==1||L[h[i]]!=L[h[i-1]]||R[h[i]]!=R[h[i-1]]){
			int t=(find(maxn)-find(R[h[i]])+mod)%mod;
			add(R[h[i]],t);
		}
	}
	printf("%d\n",find(maxn));
	return 0;
}

Measured memory_bytes: 3720
a, b, m = list(map(int, input().split()))
A = list(map(int, input().split()))
B = list(map(int, input().split()))
ans = min(A) + min(B)
for i in range(m):
    x, y, c = list(map(int, input().split()))
    ans = min(ans, A[x - 1] + B[y - 1] - c)
print(ans)

Measured memory_bytes: 18736
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> Pl;

int n, a[100001], x, su[100001];
ll ans;
int main(){
    cin >> n >> x;
    for(int i = 0; i < n; i++){
        cin >> a[i];
    }

    for(int i = 1; i < n; i++){
        su[i-1] = a[i] + a[i-1];
    }

    for(int i = 0; i < n-2; i++){
        if(su[i] > x){
            int mem = min(a[i+1], su[i]-x);
            su[i] -= mem;
            su[i+1] -= mem;
            ans += mem;
        }
    }
    if(n == 2){
        if(su[0] > x)   ans += su[0]-x;
    }
    else{
        if(su[0] > x){
            ans += su[0]-x;
        }
        if(su[n-2] > x){
            ans += su[n-2]-x;
        }
    }

    cout << ans << endl;
}

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

struct Card 
{
	char suit;
	int number;
	int order;
};

int partition(vector<Card>& A, int p, int r)
{
	int x = A[r].number;
	int i = p - 1;

	for (int j = p; j < r; ++j)
	{
		if (A[j].number <= x)
			i++, swap(A[i], A[j]);
	}

	swap(A[i + 1], A[r]);

	return i + 1;
}

void quick_sort(vector<Card>& A, int p, int r)
{
	if (p < r)
	{
		int q = partition(A, p, r);
		quick_sort(A, p, q - 1);
		quick_sort(A, q + 1, r);
	}
}

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

	int n;
	cin >> n;

	vector<Card> A(n);
	for (int i = 0; i < n; ++i)
	{
		cin >> A[i].suit >> A[i].number;
		A[i].order = i;
	}

	quick_sort(A, 0, n - 1);

	bool stable = true;
	for (int i = 0; i < n; ++i)
	{
		if (A[i].number == A[i + 1].number && A[i].order > A[i + 1].order)
			stable = false;
	}

	cout << (stable ? "Stable" : "Not stable") << endl;

	for (int i = 0; i < n; ++i)
		cout << A[i].suit << " " << A[i].number << endl;

	return 0;
}

Measured memory_bytes: 3740
import java.util.LinkedList;
import java.util.List;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner in = new Scanner(System.in);
		int INF = 100000000;
		int n = in.nextInt();
		int m = in.nextInt();
		int R = in.nextInt();
		int[] r = new int[R];
		for(int i=0;i<R;i++) {
			r[i] = in.nextInt()-1;
		}
		int[][] c = new int[n][n];
		for(int i=0;i<n;i++) {
			for(int j=0;j<n;j++) {
				if(i!=j) c[i][j] = INF;
			}
		}
		for(int i=0;i<m;i++) {
			int a = in.nextInt();
			int b = in.nextInt();
			int cost = in.nextInt();
			c[a-1][b-1] = c[b-1][a-1] = cost;
		}
		for(int k=0;k<n;k++) {
			for(int i=0;i<n;i++) {
				for(int j=0;j<n;j++) {
					if(c[i][j]>c[i][k]+c[k][j]) c[i][j]=c[i][k]+c[k][j];
				}
			}
		}
		int ans = Integer.MAX_VALUE;
		for(int i=0;i<R;i++) {
			List<Integer> list = new LinkedList<>();
			for(int j=0;j<R;j++) {
				if(i!=j) list.add(r[j]);
			}
			int tmp = search(c,list,r[i],0);
			if(tmp<ans) ans = tmp;
		}
		System.out.println(ans);
		in.close();
	}
	
	public static int search(int[][] c,List<Integer> list,int now,int sum) {
		if(list.size()==1) return sum+c[now][list.get(0)];
		int min = Integer.MAX_VALUE;
		for(int i=0;i<list.size();i++) {
			int next = list.remove(i);
			int tmp = search(c,list,next,sum+c[now][next]);
			list.add(i, next);
			if(tmp<min) min = tmp;
		}
		return min;
	}

}


Measured memory_bytes: 46320
object Main {
  def main(args: Array[String]): Unit = {
    val s = new Main()
    s.solve()
    s.out.flush()
  }
}

class Main {
  import java.io._
  import java.util.StringTokenizer

  import scala.collection.mutable
  import scala.util.Sorting
  import math.{abs, max, min}
  import mutable.{ArrayBuffer, ListBuffer}
  import scala.reflect.ClassTag

  val MOD = 1000000007
  val out = new PrintWriter(System.out)

  def solve(): Unit = {
    val N = ni()
    val H = na(N)
    val cost = Array.fill[Int](N)(1e9.toInt + 10)
    cost(0) = 0
    REP(N) { i =>
      if (i + 1 < N) cost(i + 1) = min(cost(i + 1),  cost(i) + abs(H(i) - H(i + 1)))
      if (i + 2 < N) cost(i + 2) = min(cost(i + 2),  cost(i) + abs(H(i) - H(i + 2)))
    }
    out.println(cost(N - 1))
  }

  class InputReader(val stream: InputStream) {
    private val reader = new BufferedReader(new InputStreamReader(stream), 32768)
    private var tokenizer: StringTokenizer = _

    def next(): String = {
      while (tokenizer == null || !tokenizer.hasMoreTokens)
        tokenizer = new StringTokenizer(reader.readLine)
      tokenizer.nextToken
    }

    def nextInt(): Int = next().toInt
    def nextLong(): Long = next().toLong
    def nextChar(): Char = next().charAt(0)
  }
  val sc = new InputReader(System.in)
  def ni(): Int = sc.nextInt()
  def nl(): Long = sc.nextLong()
  def nc(): Char = sc.nextChar()
  def ns(): String = sc.next()
  def ns(n: Int): Array[Char] = ns().toCharArray
  def na(n: Int, offset: Int = 0): Array[Int] = map(n)(_ => ni() + offset)
  def na2(n: Int, offset: Int = 0): (Array[Int], Array[Int]) = {
    val A1, A2 = Array.ofDim[Int](n)
    REP(n) { i =>
      A1(i) = ni() + offset
      A2(i) = ni() + offset
    }
    (A1, A2)
  }
  def nm(n: Int, m: Int): Array[Array[Int]] = {
    val A = Array.ofDim[Int](n, m)
    REP(n) { i =>
      REP(m) { j =>
        A(i)(j) = ni()
      }
    }
    A
  }
  def nal(n: Int): Array[Long] = map(n)(_ => nl())
  def nm_c(n: Int, m: Int): Array[Array[Char]] = map(n) (_ => ns(m))
  def REP(n: Int, offset: Int = 0)(f: Int => Unit): Unit = {
    var i = offset
    val N = n + offset
    while(i < N) { f(i); i += 1 }
  }
  def REP_r(n: Int, offset: Int = 0)(f: Int => Unit): Unit = {
    var i = n - 1 + offset
    while(i >= offset) { f(i); i -= 1 }
  }

  def map[@specialized A: ClassTag](n: Int, offset: Int = 0)(f: Int => A): Array[A] = {
    val res = Array.ofDim[A](n)
    REP(n)(i => res(i) = f(i + offset))
    res
  }


  def sumL(as: Array[Int]): Long = {
    var s = 0L
    REP(as.length)(i => s += as(i))
    s
  }

  def cumSum(as: Array[Int]) = {
    val cum = Array.ofDim[Long](as.length + 1)
    REP(as.length) { i =>
      cum(i + 1) = cum(i) + as(i)
    }
    cum
  }
}

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

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

    int t, d, l;
    while (cin >> t >> d >> l) {
        if (t == 0) break;
        int last = -1e9;
        int cnt = 0;
        for (int i = 0; i < t; i++) {
            int a;
            cin >> a;
            if (i == t - 1) continue;
            if (a >= l) {
                last = i;
                cnt++;
            } else if (i - last < d) cnt++;
        }
        cout << cnt << '\n';
    }
}


Measured memory_bytes: 3148
#include<stdio.h>

long long param[1000][3];

long long val(int id, int a, int b, int c) {
	return param[id][0] * a + param[id][1] * b + param[id][2] * c;
}

long long mtop(int n, int m, int a, int b, int c) {
	int sort_idx[1000], i, swapped, t;
	long long ret;
	for (i = 0; i < n; i ++) {
		sort_idx[i] = i;
	}

	swapped = 1;
	while (swapped == 1) {
		swapped = 0;
		for (i = 0 ; i < n - 1; i ++) {
			if (val(sort_idx[i], a, b, c) < val(sort_idx[i+1], a, b, c)) {
				t = sort_idx[i];
				sort_idx[i] = sort_idx[i+1];
				sort_idx[i+1] = t;
				swapped = 1;
			}
		}
	}

	ret = 0;
	for (i = 0; i < m; i ++) {
		ret += val(sort_idx[i], a, b, c);
	}
	return ret;
}

int main()
{
	int n, m, i;
	long long t, max;
	scanf("%d %d", &n, &m);
	for (i = 0; i < n; i ++) {
		scanf("%lld %lld %lld", &param[i][0], &param[i][1], &param[i][2]);
	}

	max = 0;
	t = mtop(n, m,  1,  1,  1); if (max < t) { max = t; }
	t = mtop(n, m,  1,  1, -1); if (max < t) { max = t; }
	t = mtop(n, m,  1, -1,  1); if (max < t) { max = t; }
	t = mtop(n, m,  1, -1, -1); if (max < t) { max = t; }
	t = mtop(n, m, -1,  1,  1); if (max < t) { max = t; }
	t = mtop(n, m, -1,  1, -1); if (max < t) { max = t; }
	t = mtop(n, m, -1, -1,  1); if (max < t) { max = t; }
	t = mtop(n, m, -1, -1, -1); if (max < t) { max = t; }

	printf("%lld", max);
	return 0;
}


Measured memory_bytes: 128
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using Graph = vector<vector<int>>;
#define ALL(x) (x).begin(), (x).end()
#define REP(i ,n) for(int i = 0; i < (int)(n); i++)
#define pb push_back
typedef vector<int>vint;
typedef vector<ll>vll;
template<typename T> istream &operator>>(istream &is, vector<T> &vec){ for (auto &v : vec) is >> v; return is; }
template<typename A,typename B>inline void chmin(A &a,B b){if(a>b)a=b;}
template<typename A,typename B>inline void chmax(A &a,B b){if(a<b)a=b;}

int main()
{
  int N;
  cin >> N;
  vint d(N);
  cin >> d;
  
  sort(d.begin(), d.end());
  
  if(d[d.size()/2-1] == d[d.size()/2]){
    cout << 0 << endl;
  }else{
    cout << d[d.size()/2] - d[d.size()/2-1]<< endl;
  }
  
}

Measured memory_bytes: 640
# D

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

cnt = 0
temp = []

d = [0]*(2*(10**5) + 1)

now = 1
while True:
  d[now] += 1
  if d[now] > 1:
    break

  temp.append(now)
  now = A[now-1]


for t in temp[::-1]:
  cnt += 1
  if t == now:
    break

temp2 = temp[-cnt::]

if len(temp) <= K:
  kk = (K-(len(temp)-cnt))%cnt
  print(temp2[kk])
else:
  print(temp[K])






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

#define fi first
#define se second
#define be begin
#define en end
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define ALL(a) (a).be() , (a).en()
#define REP(i,n) for(int (i)=0;(i)<(n);(i)++)        //repeat n times
#define REP2(i,s,n) for(int (i)=(s);(i)<(n);(i)++)   //repeat from s to n 
#define REPD(i,n) for(int (i)=(n);(i)>=0;(i)--)      //repeat from n to 0
#define REPD2(i,s,e) for(int (i)=(s);(i)>=(e);(i)--) //repeat from s to e
#define RANGE(i,v) for(auto &(i):v)                  //repeat range
#define ASIZE(a) (sizeof(a) / sizeof(a[0]))          //array size

using LL = long long;

template<typename T> using V = vector< T >;
using Vi = V<int>;
using Vll = V<LL>;
using Vs = V<string>;

double distance_nD(Vi a, Vi b){
    if(a.size() != b.size()) return -1;
    double dist = 0.0;
    REP(i,a.size()){
        dist += (a[i]-b[i])*(a[i]-b[i]);
    }
    return sqrt(dist);
}

bool is_int32( double x ){
    return static_cast<int32_t>(x)==x;
}

int main(){
    int n,d;
    cin>>n>>d;
    V<Vi> x(n,Vi(d,0));
    REP(i,n){
        REP(j,d) cin>>x[i][j];
    }
    
    int cnt = 0;
    REP(i,n){
        REP2(j,i+1,n){
            if(is_int32(distance_nD(x[i],x[j]))) cnt++;
        }
    }

    cout<<cnt<<endl;

    return 0;
}

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

int main(void) {
	int a, b; cin >> a >> b;
	if (a <= 0 && 0 <= b) {
		cout << "Zero" << endl;
		return 0;
	}
	else if (a < 0 && b < 0) {
		if ((b - a) % 2 == 0) {
			cout << "Negative" << endl;
			return 0;
		}
		else { cout << "Positive" << endl; return 0; }
	}
	else { cout << "Positive" << endl; return 0; }

	return 0;
}

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

using namespace std;

typedef long long ll;
typedef pair<ll, ll> pii;
typedef vector<ll> vi;
typedef vector<vi> vvi;
typedef vector<pii> vpii;
const ll INF = (1ll << 60);

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

  vi v(N);
  for (ll i = 0; i < N; i++) {
    cin >> v[i];
  }

  sort(v.begin(), v.end());
  double ans = 0;
  cout << fixed << setprecision(10);
  for (ll i = 0; i < N; i++) {
    if (i == 0) {
      ans = v[i];
    } else {
      ans = (ans + v[i]) / 2;
    }
  }

  cout << ans << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cstring>
#include <vector>
#include <algorithm>
#include <cmath>

using namespace std;

#define mp make_pair
#define pb push_back
#define ll long long

ll n, k, a, b, c, r;
ll ans;

int main()
{
 //   freopen("test.in","r",stdin);

    cin >> n >> k;
    for (b = k + 1; b <= n; b++) {
        c = n / b;

        ans += c * (b - k);
        ans += max(0LL, (n % b) - k + 1);
    }

    if (k == 0) ans -= n;

    cout << ans;


    return 0;
}


Measured memory_bytes: 256
#!/usr/bin/env python3
import sys
sys.setrecursionlimit(10000000)
INF = 1<<32

MOD = 2  # type: int

def solve(N: int, a: "List[int]"):
    a = [0] + a
    b = [0] * (N+1)
    for i in range(N,0,-1):
        j = i*2
        n = 0
        while j <= N:
            n += b[j]
            j += i
        # print("a[i],n :", i, a[i], n)
        if a[i] == n%MOD:
            b[i] = 0
        else:
            b[i] = 1

    x = [i for i in range(1, N+1) if b[i] == 1]
    print(len(x))
    for i in x:
        print(i)

    return



def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    a = [int(next(tokens)) for _ in range(N)]  # type: "List[int]"
    solve(N, a)

if __name__ == '__main__':
    main()


Measured memory_bytes: 15224