akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <vector>
#include <string>
#include <math.h>
#include <algorithm>
#include <set>
#include <iomanip>
#include <stdio.h>
#include <sstream>
#include <string>
using namespace std;
int main(void){
  int r,g,b;
  cin>>r>>g>>b;
  if((r*100+g*10+b)%4==0){
    cout<<"YES"<<endl;
  }else{
    cout<<"NO"<<endl;
  }
}

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

#define FOR(i,N) for(int i=0;i<N;i++)
#define ROF(i,N) for(int i=N-1;i>=0;i--)
#define ROF1(i,a,b) for(int i=(b);i>=(a);i--)
#define FOR1(i,a,b) for(int i=(a);i<=(b);i++)
#define FORi(i,a,b,c) for(int i=(a);i<=(b);i+=(c))

#define read freopen("IN.txt","r",stdin)
#define write freopen("OT.txt","w",stdout)
#define fastread {ios_base::sync_with_stdio(false);cin.tie(NULL);}
#define mem(a,b)          memset(a,b,sizeof(a))
#define EPS 1e-9
#define PI              acos(-1.0)
#define INF             2e16

#define ll              long long
#define ull             unsigned long long
#define ft              first
#define sd              second
#define bn              begin
#define en              end
#define pb              push_back
#define mp              make_pair
#define pii             pair<int,int>
#define pll             pair<LL,LL>
#define all(x) x.begin(), x.end()


#define dbg(args...) {cerr<<"-->";debugger::call(#args,args);cerr<<"\n";}
struct debugger {
    static void call(const char* it) {}
    template<typename T, typename ... aT>
    static void call(const char* it, T a, aT... rest) {
        string b;
        for (; *it&&*it != ','; ++it) if (*it != ' ')b += *it;
        cerr << b << "=" << a << " ";
        call(++it, rest...);
    }
};
bool odc(int x)
{
     int c=0;
     while(x)
     {
          x/=10;
          c++;
     }
     if(c&1)return true;
     else false;
}
int main()
{
#ifdef SunWalker
    //read;
   //write;
#endif

int n,cnt=0;
cin>>n;
FOR1(i,1,n)
{
     if(i<=9)cnt++;
     else if(i<=99)continue;
     else if(i<=999)cnt++;
     else if(i<=9999)continue;
     else if(i<=99999)cnt++;
     else if(i<=999999)continue;
}
cout<<cnt<<"\n";
return 0;
}



Measured memory_bytes: 256
program ARC096F
type data
  integer(4)::w,t
  integer(16)::m
end type

integer(4)::N,X,D
integer(4)::V,W,tmp
integer(4)::ans=0
type(data),allocatable::A(:)
integer(16),allocatable::p(:)
integer(16),allocatable::f(:,:)

read*,N,X,D
allocate(A(N),p(N),f(0:N,0:N**3))
read*,A(1)%m
A(1)%w=1;A(1)%t=10**9
do i=2,N
    read*,A(i)%m,p(i)
    a(i)%w=1;a(i)%t=D
end do
do i=n,2,-1 
    A(p(i))%w=A(p(i))%w+A(i)%w
    A(p(i))%m=A(p(i))%m+A(i)%m
end do
call heapsort(N,A)
f=huge(f)/2
f(0,0)=0
do i=1,N
    do k=0,min(n,a(i)%t)
        do j=0,n**3-k*a(i)%w
            f(i,j+k*a(i)%w)= min(f(i,j+k*a(i)%w),f(i-1,j)+k*a(i)%m)
        end do
    end do
end do

do i=0,n**3
    if(f(n,i)>x)cycle
    W=x-f(n,i);V=i
    do j=1,N
      tmp=min(W/a(j)%m,1*max(0,a(j)%t-n))
      W=W-tmp*a(j)%m
      V=V+tmp*a(j)%w
    end do
    ans=max(ans,V)
end do

print"(I0)",ans
contains
logical function datacmp(A,B)
    type(data)::A,B
    datacmp= (A%w*B%m>A%m*B%w)
end function
subroutine heapsort(n,array)
  implicit none
  integer,intent(in)::n
  type(data),intent(inout) :: array(1:n)
  integer(16)::i,k,j,l
  type(data):: t

  l=n/2+1
  k=n
  do while(k /= 1)
     if(l > 1)then
        l=l-1
        t=array(L)
     else
        t=array(k)
        array(k)=array(1)
        k=k-1
        if(k == 1) then
           array(1)=t
           exit
        endif
     endif
     i=l
     j=l+l
     do while(j<=k)
        if(j < k)then
           if(datacmp(array(j),array(j+1)))j=j+1
        endif
        if (datacmp(t,array(j)))then
           array(i)=array(j)
           i=j
           j=j+j
        else
           j=k+1
        endif
     enddo
     array(i)=t
  enddo
  return
end subroutine heapsort
end

Measured memory_bytes: 99840
#include "bits/stdc++.h"
#ifndef err
#define err(...)(void)0
#endif
using namespace std;
using ll = long long;
using ull = decltype(1ull);
template<class T>int size(T&&a) { return a.size(); }
#define REP(t,a)for(typename make_signed<decltype(a.second)>::type t=a.first,_l##t=a.second;t<_l##t;t++)
#define RREP(t,a)for(typename make_signed<decltype(a.second)>::type t=a.second-1,_l##t=a.first;t>=_l##t;t--)
template<class B>pair<int, B>make_pair(B b) { return{ 0,b }; }
#define rep(t,...)REP(t,make_pair(__VA_ARGS__))
#define rrep(t,...)RREP(t,make_pair(__VA_ARGS__))
#define all(a)begin(a),end(a)
#define rall(a)a.rbegin(),a.rend()

void Calc();
int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr); cin.exceptions(istream::failbit | istream::badbit);
  cout << fixed << setprecision(15); Calc(); cout.flush(); return 0;
}
template<class A>void amax(A&a, A b) { a = max(a, b); }
template<class A>void amin(A&a, A b) { a = min(a, b); }
struct Scanner {
  template<class A = string>A Next() { A a; cin >> a; return a; }
  template<class A = int>vector<A>Array(int n) { vector<A>a(n); for (A&i : a) cin >> i; return a; }
  string Line() const { string s; getline(cin, s); return s; }
  template<class A>Scanner&operator,(A&a) { a = Next<A>(); return *this; }
  template<class A>operator A() { return Next<A>(); }
}in;

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

void Calc() {
  int n = in;
  auto a = in.Array(n);
  int cnt = 0;
  for (auto& i : a) {
    if (i % 2 == 0) {
      continue;
    }
    cnt++;
  }
  if (cnt % 2 != 0) {
    cout << ("NO") << endl;
    return;
  }
  cout << ("YES") << endl;
}


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

using namespace std;
typedef long long ll;

int main() {
    int n, k;
    cin >> n >> k;
    int ans = 1;
    n -= k;
    ans += ceil(1.0 * n / (k - 1));
    cout << ans << endl;
    return 0;
}

static int speedUp = []() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);
    return 0;
}();

Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
const int MAX = 700000;
const int MOD = 1000000007;

long long fac[MAX], finv[MAX], inv[MAX];

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

// 二項係数計算
long long COM(int n, int k) {
	if (n < k) return 0;
	if (n < 0 || k < 0) return 0;
	return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}
/*第二引数で第一引数を割ったときの切り上げの計算*/
long long int maxtime(long long int x, long long int y) {
	return(x + y - 1) / y;

}
/*最大公約数*/
long long int lcm(long long int number1, long long int number2) {
	long long int m = number1;
	long long int n = number2;

	if (number2 > number1) {
		m = number2;
		n = number1;
	}
	long long int s = -1;
	while (s != 0) {
		s = m % n;
		m = n;
		n = s;
	}
	return m;
}
/*最大公倍数*/
long long int gcd(long long int number1, long long int number2) {
	long long int m = number1;
	long long int n = number2;
	return m / lcm(m, n) * n;
}
long long int dp[12][100000] = {};
int main() {
	long long int n, k;
	cin >> n >> k;
	long long int ans = 0;
	for (int i = k + 1; i <= n; i++) {
		long long int amari = n % i;
		ans = ans + n / i * (i - k);
		amari = amari + 1;
		if (amari - k > 0) {
			ans = ans + amari - k;
		}
	}
	if (k == 0) {
		cout << n * n;
		return 0;
	}
	cout << ans;
}

Measured memory_bytes: 256
def main():
    n,k = map(int,input().split())
    X = list(map(int,input().split()))

    ans = 10**9

    for i in range(n-k+1):
        t1 = abs(X[i]) + abs(X[i] - X[i+k-1])
        t2 = abs(X[i+k-1]) + abs(X[i] - X[i+k-1])
        t = min(t1,t2)

        ans = min(ans,t)

    print(ans)



main()

Measured memory_bytes: 20108
#include <bits/stdc++.h>
#define inf 1000000000 //1E+9
using namespace std;


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

	for(int i=0;i<s.size();i++){
		if(s[i]=='C'){
			for(int j=i+1;j<s.size();j++){
				if(s[j]=='F'){
					cout<<"Yes"<<endl;
					return 0;
				}
			}
		}
	}

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

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

int main() {
  char s[11];
  scanf("%s", s);
  s[0] = '2';
  s[1] = '0';
  s[2] = '1';
  s[3] = '8';
  printf("%s\n", s);
  return 0;
}

Measured memory_bytes: 3744
#include<iostream>
#include<string>
#include<stdio.h>
#include<string.h>
using namespace std;
int main()
{
string s;
cin>>s;
int check1=0;
int check2=0;
int check3=0;
int n=s.length()-1;
int j=n;
for(int i=0;i<n/2;i++)
{
    if(s[i]!=s[j])
    {
    check1=1;
    }
    j--;
}
if(check1==0)
{
    int k=(n-1)/2;
    int l=(n+3)/2;
    for(int i=0;i<(n-1)/2;i++)
    {
        if(s[i]!=s[k])
        {
        check2=1;
        }
        k--;
    }
    for(int i=((n)/2)+1;i<(n+3)/2;i++)
    {
        if(s[i]!=s[l])
        {
            check3=1;
        }
        l--;
    }
    if(check1==0&&check2==0)
    {
    cout<<"Yes";
    }
    else{
    cout<<"No";
    }
}
else
{
    cout<<"No";
}

}


Measured memory_bytes: 256
N = int(input())
A = list(map(int, input().split()))
 
ans = 0
Q = int(1e9 + 7)
 
sumA = sum(A)
 
for i in range(N-1):
    sumA -= A[i]
    ans += sumA * A[i]
    ans %= Q
 
print(ans)

Measured memory_bytes: 31528
#include <algorithm>
#include <iostream>
#include <string>
#include <random>
#include <cassert>
#include <cstring>
#include <chrono>
#include <set>
#include <map>

using namespace std;

typedef long long ll;

int main()
{
  string s;
  cin >> s;
  if (s[2] == s[3] && s[4] == s[5]) {
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }
  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define REP(i,n) for(int i=0;i<(n);i++)
#define REP2(i,a,b) for(int i=(a);i<(b);i++)
#define ALL(v) (v).begin(),(v).end()
#define INF 2e9
typedef long long ll;

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

  int ans;
  if(x==0){
    if(y==0) ans=0;
    else if(y>0) ans=y;
    else ans=-y+1;
  }else if(x>0){
    if(y==0) ans=x+1;
    else if(y>0){
      if(x<=y) ans=y-x;
      else ans=x-y+2;
    }else ans=abs(x+y)+1;
  }else{
    if(y==0) ans=-x;
    else if(y<0){
      if(x<=y) ans=y-x;
      else ans=x-y+2;
    }else ans=abs(x+y)+1;
  }
  cout<<ans<<endl;

  return 0;
}

Measured memory_bytes: 256
from collections import Counter
from itertools import groupby


def bin_search(k, greater_count, smaller_sum):
    l = 0
    r = n + 1
    while l < r - 1:
        m = (l + r) // 2
        gc = greater_count[m]
        ss = smaller_sum[m]
        if gc + ss // m >= k:
            l = m
        else:
            r = m
    return l


n = int(input())
aaa = list(map(int, input().split()))
cnt = sorted(Counter(aaa).values())

# Precompute
greater_count = [0] * (n + 2)  # Number of types of Ai same or greater than i
smaller_sum = [n] * (n + 2)  # Number of Ai smaller than i

remain = greater_count[1] = len(cnt)
total = smaller_sum[1] = 0
pointer = 2

for c, itr in groupby(cnt):
    l = len(list(itr))
    remain -= l
    total += c * l
    for i in range(pointer, c + 2):
        greater_count[i] = remain
        smaller_sum[i] = total
    pointer = c + 2

# print(greater_count)
# print(smaller_sum)

# Query
buf = []
for k in range(1, len(cnt) + 1):
    buf.append(bin_search(k, greater_count, smaller_sum))

buf.extend([0] * (n - len(cnt)))

print(*buf)


Measured memory_bytes: 39256
nm = gets.chomp.split
n = nm[0].to_i
m = nm[1].to_i

ab_a = []
n.times do
  ab = gets.chomp.split
  2.times do |i|
    ab[i] = ab[i].to_i
  end
  ab_a << ab
end

ab_a.sort!

money = 0
drinks = 0
m.times do |i|
  price = ab_a[i][0]
  drink = ab_a[i][1]

  if drinks + drink < m
    drinks += drink
    money += (drink * price)
  else
    money += ((m - drinks) * price)
    break
  end
end

puts money

Measured memory_bytes: 10488
N = int(input())
problems = list(map(int,input().split()))
times = sum(problems)

M = int(input())
drink = [list(map(int,input().split())) for _ in range(M)]

for i in range(M):
    ans = times
    x = drink[i][0] - 1
    y = drink[i][1]
    ans += (y - problems[x])
    print(ans)

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

int main() {
  int a, b, c, d;
  cin >> a >> b >> c >> d;
  
  if(a+b > c+d)
    cout << "Left" << endl;
  else if(a+b < c+d)
    cout << "Right" << endl;
  else
    cout << "Balanced" << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#include <iostream>
#include <cstdlib>
#include <cmath>
#include <vector>
#include <algorithm>
int main() {
  int S,a,b,c,d;
  cin>>S;
  a=S/1000;
  b=(S-a*1000)/100;
  c=(S-a*1000-b*100)/10;
  d=S%10;
  if(a!=b&&b!=c&&c!=d){
  cout<<"Good"<<endl;
  }else{
  cout<<"Bad"<<endl;
  }
}

Measured memory_bytes: 256
use std::cmp::min;
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")
    };
}

fn main() {
    input! {
    n: usize,
    h: [i64; n]
    }
    let mut dp = vec![0; n];
    dp[1] = (h[1] - h[0]).abs();
    for i in 2..n {
        dp[i] = min(dp[i - 2] + (h[i] - h[i - 2]).abs(), dp[i - 1] + (h[i] - h[i - 1]).abs());
    }
    let ans = dp[n - 1];
    println!("{}", ans);
}



Measured memory_bytes: 6396
#include<bits/stdc++.h>
#define rep(i,n) for(ll i=0;i<n;++i)
#define rrep(i,n) for(int i=n-1;i>=0;--i)
#define yesno(flg) if(flg){cout<<"YES"<<endl;}else{cout<<"NO"<<endl;}
#define MAX_N 1002
#define i197 1000000007

using namespace std;

typedef long long ll;
typedef pair<ll,ll> P1;
typedef pair<int,int> Pi;
typedef pair<double,Pi> Pdi;
typedef pair<ll,int>Pli;
typedef pair<P1,ll> P2;
const ll INF=100000000000000001;
struct edge{int to,cost;};
int dy[]={0, 0, 1, -1};
int dx[]={1, -1, 0, 0};
struct Road{double cost;int a,b;};


int main() {

	ll n;
	double t,a;
	double h[1001];
	double c=0;
	double min=1000000;
	ll o=0;
	double f=0.006;

	cin>>n;
	cin>>t>>a;

	for(ll i=1; i<n+1; ++i){
		cin>>h[i];
		c=t-h[i]*f;
		if(fabs(c-a)<min){
			min=fabs(c-a);
			o=i;
		}
	}

	cout<<o<<endl;


	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
//----***やべーやつら***----
using namespace std;
#define int long long

//----***型定義***----
using ll = long long;
using P = pair<int,int>;

//----***Like a Pythonista***----
#define REP(ii,jj,nn) for (ll ii=jj;ii<(nn);ii++)
#define RREP(ii,nn,jj) for (ll ii = nn; jj<ii;ii--)
#define each(i,...) for (auto&& i:__VA_ARGS__)
#define ALL(vec) (vec).begin(),(vec).end()
#define sum(...) accumulate(ALL(__VA_ARGS__),0LL)
#define dsum(...) accumulate(ALL(__VA_ARGS__),0.0)
#define vec(type,name,...) vector<type> name(__VA_ARGS__)
template<class T> inline auto max(const T& a){ return *max_element(ALL(a)); }
template<class T> inline auto min(const T& a){ return *min_element(ALL(a)); }
inline ll gcd(ll a,ll b){if(b == 0) return a;return  gcd(b,a%b);}
inline ll lcm(ll a,ll b){ll g = gcd(a,b);return a / g * b;}

//----***定数***----
#define MOD 1000000007
#define INF 100000000000000000
#define EPS 1e-9
#define PI  acos(-1)
const vector<vector<int>> DXY={{-1,0},{1,0},{0,-1},{0,1}};

//----***パーツ***----
#define fi first
#define se second
#define pb push_back
#define re return
#define br break

//----***入出力***---
void print() { std::cout << "\n"; }
template <class T>void print(const T &x) {std::cout << x<<"\n";}
template <class T, class... Args>void print(const T &x, const Args &... args) {std::cout << x << " ";print(args...);}
#define debug(var)  do{std::cerr << #var << " ↓ "<<"\n";view(var);}while(0);
#define dbg cerr<<"🥺🥺🥺🥺🥺🥺"<<endl;
template<typename T> void view(T e){std::cout << e << std::endl;}
template<typename T> void view(const std::vector<T>& v){for(const auto& e : v){ std::cout << e << " "; } std::cout << std::endl;}
template<typename T> void view(const std::vector<std::vector<T> >& vv){ for(const auto& v : vv){ view(v); } }

//----***初期時読み込み***----
struct initial{initial(){cin.tie(0); ios::sync_with_stdio(0); cout<<fixed<<setprecision(15);};}initial_;

// 素因数分解
vector< ll > divisor(int64_t n) {
  vector< ll > ret;
  for(ll i = 1; i * i <= n; i++) {
    if(n % i == 0) {
      ret.push_back(i);
      if(i * i != n) ret.push_back(n / i);
    }
  }
  sort(begin(ret), end(ret));
  return (ret);
}

signed main(){
  int N,M;cin>>N>>M;
  vector<ll> ve=divisor(M);
  int res=1;
  each(v,ve){
    if(M/N<v)br;
    res=v;

  }
  print(res);

}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
using P = pair<int,string>;
const ll M = 1000000007;

int main() {
    ll n,k; cin >> n >> k;
    ll ans = 0;
    for (int i = k; i < n + 1; i++) {
        ans += (i * (n - i + 1) + 1) % M;
        ans %= M;
    }
    ans = (ans + 1) % M;
    cout << ans << "\n";
}

Measured memory_bytes: 3636
#!/usr/bin/env python
# -*- coding: utf-8 -*-

while True:
    try:
        s = input('')
    except:
        break

    cut_s_list = [s[i:i+3] for i in range(len(s[:-2]))]

    n_joi = 0
    n_ioi = 0
    for cut_s in cut_s_list:
        if cut_s == 'JOI':
            n_joi += 1
        if cut_s == 'IOI':
            n_ioi += 1

    print(n_joi)
    print(n_ioi)

Measured memory_bytes: 7352
import java.util.Scanner;

public class Main{
	
	public static void main(String args[]) {
		
		Scanner input = new Scanner(System.in);
		
		int x = input.nextInt();
		int y = input.nextInt();
		
		System.out.println(gcd(x, y));
		
	}
	
	public static int gcd(int x, int y) {
		
		while(x!=0 && y!=0) {
			
			int z = y;
			y = x%y;
			x = z;
			
		}
		
		return x+y;
		
	}

}



Measured memory_bytes: 26120
#include <iostream>
#include <iomanip>
#include <string>
#include <unordered_map>

#define PI 3.141592653589793238462643383L

using namespace std;
int main()
{
  int r;
  cin >> r;
  cout << fixed << setprecision(15) << r * 2 * PI << endl;
  return 0;
}


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

int main(){
    int a[5];

    while(cin >>a[1]>>a[2]>>a[3]>>a[4]){
        int b[5], hit=0, blow=0;
        cin >>b[1]>>b[2]>>b[3]>>b[4];
        for(int i=1; i<6; i++){
            for(int j=1; j<6; j++){
                if(a[i] == b[j]){
                    blow++;
                    if(i == j){
                        blow--;
                        hit++;
                    }
                }
            }
        }
        cout << hit << ' ' << blow << endl;
    }

    return 0;
}

Measured memory_bytes: 1160
N,M = map(int,input().split())
target = [[num-1 for num in list(map(int,input().split()))[1:]] for _ in range(M)]
#各sについてのリストを元にした配列を、それぞれの値から1を引いて作成
judge = list(map(int,input().split()))
#2で割った余り=最終判定のリスト
cnt = 0

for i in range(2 ** N):
#スイッチの状態について全探索
#N = 2の時、スイッチは[00,01,10,11]の4 = 2^N通り
	switches = [0] * M
	for k in range(M):
	#各電球についてfor文を回す
		for j in range(N):
		#各スイッチについてfor文を回す
			if ((i >> j) & 1) and j in target[k]:
			#jビット右シフト(ex:6 = 0b110 >> 1 → 0b11 = 3)かつ、1と論理積をとる
			#⇨下位1ケタのビットが立っているか = j番目スイッチが押されているかどうかに対応を判定
			#j番目のスイッチが押されており、かつj番目のスイッチが電球Kの点灯条件であれば
			#+1カウント
				switches[k] += 1

	switches =	[switch % 2 for switch in switches]
	#2で割ったあまりを算出し、点灯するかどうかのリストに
	if switches == judge:
		cnt += 1
		
print(cnt)

Measured memory_bytes: 3064
package main

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

var sc = bufio.NewScanner(os.Stdin)

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

func nextInt() int {
	sc.Scan()
	i, e := strconv.Atoi(sc.Text())
	if e != nil {
		panic(e)
	}
	return i
}

func main() {
	sc.Split(bufio.ScanWords)

	x, y, z := nextInt(), nextInt(), nextInt()

	fmt.Println((x-z)/(y+z))
}


Measured memory_bytes: 640
import java.awt.*;
import java.util.*;
import java.io.*;

public class Main {
    public static void main(String[] args) throws Exception {
        FastReader sc = new FastReader();
        int n=sc.nextInt();
        ArrayList<Integer> adj[]=new ArrayList[n+1];
        for (int i=0;i<=n;i++)adj[i]=new ArrayList<>();
        for (int i=2;i<=n;i++){
            adj[sc.nextInt()].add(i);
        }
        StringBuilder sb=new StringBuilder();
        for (int i=1;i<=n;i++){
            sb.append(adj[i].size()+"\n");
        }
        System.out.print(sb);
    }
    static class FastReader {
        BufferedReader br;
        StringTokenizer st;

        public FastReader() {
            br = new BufferedReader(new InputStreamReader(System.in));
        }

        String next() {
            while (st == null || !st.hasMoreElements()) {
                try {
                    st = new StringTokenizer(br.readLine());
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
            return st.nextToken();
        }

        int nextInt() {
            return Integer.parseInt(next());
        }

        long nextLong() {
            return Long.parseLong(next());
        }

        double nextDouble() {
            return Double.parseDouble(next());
        }

        String nextLine() {
            String str = "";
            try {
                str = br.readLine();
            } catch (IOException e) {
                e.printStackTrace();
            }
            return str;
        }
    }
}


Measured memory_bytes: 75612
#include <bits/stdc++.h>
#define Rint register int
#define C(n,m) (n<m?0:1ll*fac[n]*invfac[n-m]%mod*invfac[m]%mod)
using namespace std;
int T,n,m,p,k;
int fa[100010],sz[100010],a[100010],b[100010],c[100010],deg[100010];
bool nocy[100010];
int Y[100010],Z[100010];
int X=0;
int find(int a){
	return fa[a]==a?a:fa[a]=find(fa[a]);
}
void merge(int a,int b){
	a=find(a),b=find(b);
	if(a==b) return;
	fa[a]=b;
	sz[b]+=sz[a];
}
int main(){
	scanf("%d%d",&n,&m);
	for(int i=1;i<=n;i++) fa[i]=i,sz[i]=1;
	for(int i=1;i<=m;i++){
		scanf("%d%d%d",&a[i],&b[i],&c[i]);c[i]--;
		merge(a[i],b[i]);deg[a[i]]++,deg[b[i]]++;
	}
	for(int i=1;i<=n;i++) if(deg[i]>2) nocy[find(i)]=true;
	for(int i=1;i<=n;i++) if(find(i)==i&&!nocy[i]&&sz[i]>=2) X++;
	int now=0;
	bool flag=0;
	for(int i=1;i<=m;++i) if(c[i]){
		if(nocy[find(a[i])]){
			if(a[i]==b[i]) Z[++Z[0]]=c[i];
			else flag=true,now+=c[i];
		}
		else{
			if(a[i]==b[i]) Y[++Y[0]]=c[i]-1;
			else now+=c[i];
		}
	}
	sort(Y+1,Y+Y[0]+1),reverse(Y+1,Y+Y[0]+1);
	sort(Z+1,Z+Z[0]+1),reverse(Z+1,Z+Z[0]+1);
	for(int i=1;i<=Y[0];++i) now+=Y[i];
	int ans=INT_MAX;
	for(int i=1,j=Y[0];i<=Z[0]+1;i++){
		while(j>=1&&now-Y[j]>=X) now-=Y[j--];
		if((flag||i>1||X==0)&&now>=X) ans=min(ans,i+2*j-1);
		if(i<=Z[0]) now+=Z[i];
	}
	if(ans>2e9) puts("-1");
	else{
		ans+=X;
		for(int i=1;i<=m;i++) if(a[i]!=b[i]) ans++;
		printf("%d\n",ans);
	}
}


Measured memory_bytes: 6640
#include <iostream>
#include <vector>
#include <stdlib.h>

struct Card
{
	std::string name;
	int value;
};

std::string Print(int size, std::vector<Card> ls) {
	std::string sort = "";
	for (int i = 0; i < size; i++)
		i != size - 1 ? sort += ls[i].name + " " :
		sort +=  ls[i].name + "\n";
	return sort;
}

std::string BubbleSort(int size, std::vector<Card> ls) {
	int swap = 0;
	for (int i = 0; i < size; i++)
		for (int j = size - 1; j > 0; j--)
			if (ls[j].value < ls[j - 1].value) {
				Card _ = ls[j];
				ls[j] = ls[j - 1];
				ls[j - 1] = _;
				swap++;
			}
	return Print(size, ls);
}

std::string SelectionSort(int size, std::vector<Card> ls) {
	int swap = 0, mini;
	for (int i = 0; i < size; i++) {
		mini = i;
		for (int j = i; j < size; j++)
			if (ls[j].value < ls[mini].value) {
				mini = j;
			}
		if (i != mini) {
			Card _ = ls[i];
			ls[i] = ls[mini];
			ls[mini] = _;
			swap++;
		}
	}
	return Print(size, ls);
}

std::vector<Card> scan(int size) {
	std::vector<Card> ls(size);
	for (int i = 0; i < size; i++) {
		std::cin >> ls[i].name;
		ls[i].value = atoi(ls[i].name.substr(1, 1).c_str());
	}
	return ls;
}

int main() {
	int size;
	std::string s1, s2;
	std::cin >> size;
	std::vector<Card>  c = scan(size);
	s1 = BubbleSort(size, c);
	s2 = SelectionSort(size, c);
	std::cout << s1;
	std::cout << "Stable\n";
	if (s1 == s2) {
		std::cout << s2;
		std::cout << "Stable\n";
	}
	else {
		std::cout << s2;
		std::cout << "Not stable\n";
	}
	return 0;
}



Measured memory_bytes: 3240
N, Q = map(int, input().split())
G = [[] for _ in range(N)]
ans = [0]*N

for _ in range(N-1):
    a, b = map(int, input().split())
    G[a-1].append(b-1)
    G[b-1].append(a-1)

for _ in range(Q):
    p, x = map(int, input().split())
    ans[p-1] += x

judge = [False]*N
judge[0] = True
queue = [0]
while queue:
    a = queue.pop()
    for i in G[a]:
        if not judge[i]:
            judge[i] = True
            ans[i] += ans[a]
            if G[i]:
                queue.append(i)

print(*ans)


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

namespace AtCoder
{
    class Program
    {
        static long patties;
   
        static void Main(string[] args)
        {
            //[summary]D - Christmas
            var line = ReadLine();
            int n = (int)line[0];
            long x = line[1];

            var burgers = CreateBurgers(n);

            CountPatties(burgers, n, x);
            Console.WriteLine(patties);            
        }

        static void CountPatties(List<Burger> burgers, int n, long x)
        {
            long a = burgers[n].Size;
            long b = burgers[n - 1].Size + 2;

            if (x == a | x == a - 1)
            {
                patties += burgers[n].Patties;
            }
            else if (x > b)
            {
                patties += burgers[n - 1].Patties + 1;
                CountPatties(burgers, n - 1, x - b);
            }
            else if (x == b)
            {
                patties += burgers[n - 1].Patties + 1;
            }
            else if (x == b - 1)
            {
                patties += burgers[n - 1].Patties;
            }
            else if (x > 1)
            {
                CountPatties(burgers, n - 1, x - 1);
            }
        }
        
        static List<Burger> CreateBurgers(int n)
        {
            var burgers = new List<Burger>();

            //レベル0バーガーを追加
            burgers.Add(new Burger(1, 1));
            
            for(int i = 0; i < n; i++)
            {
                long size = burgers[i].Size * 2 + 3;
                long patties = burgers[i].Patties * 2 + 1;

                var burger = new Burger(size, patties);
                burgers.Add(burger);
            }

            return burgers;
        }

        //static string CreateBurger(int n)
        //{
        //    string burger = "P";

        //    for(int i = 0; i < n; i++)
        //    {
        //        burger = "B" + burger + "P" + burger + "B";
        //    }

        //    return burger;
        //}

        static List<long> ReadLine()
        {
            var line = Console.ReadLine().TrimEnd();
            var array = line.Split(' ');
            var numbers = new List<long>();

            foreach (var s in array)
            {
                long num = long.Parse(s);
                numbers.Add(num);
            }

            return numbers;
        }
    }

    struct Burger
    {
        public long Size { set; get; }
        public long Patties { set; get; }

        public Burger(long size, long patties)
        {
            Size = size;
            Patties = patties;
        }
    }
}

Measured memory_bytes: 11220
import java.util.*
import kotlin.math.acos
import kotlin.math.cos
import kotlin.math.round
import kotlin.math.sin

fun main(args: Array<String>) {
    val x = readInt()
    
    if (x == 0) println(1)
    else println(0)
}

// read
fun readString() = readLine()!!
fun readInt() = readLine()!!.toInt()

Measured memory_bytes: 34396
// AC版.
#include <bits/stdc++.h>
using namespace std;
int v[100001];

int main(){
    
    // 1. 入力情報取得.
    int N;
    scanf("%d", &N);
    map<int, int> me, mo;
    me[100001] = 0, mo[100001] = 0; // dummyデータとして保存.
    for(int i = 0; i < N; i++){
        scanf("%d", &v[i]);
        // 偶数番目, 奇数番目 ごとに, 各整数の出現回数を保存.
        if(i % 2 == 0) me[v[i]]++;
        else           mo[v[i]]++;
    }
    
    // 2. 出現回数の調査.
    // map -> vector に 情報 を 移し替える.
    vector<pair<int, int>> ve, vo;
    for(auto &p : me){
        int f = p.first, s = p.second;
        ve.push_back({-s, f});
    }
    for(auto &p : mo){
        int f = p.first, s = p.second;
        vo.push_back({-s, f});
    }
    
    // 昇順sort.
    sort(ve.begin(), ve.end());
    sort(vo.begin(), vo.end());
    
    // 2-1. 偶数番目, 奇数番目 で, 最大出現数 を 持つ整数が異なる場合.
    if(ve[0].second != vo[0].second){
        printf("%d\n", N + ve[0].first + vo[0].first);
        return 0;
    }
    
    // 2-2. 偶数番目, 奇数番目 で, 最大出現数 を 持つ整数が同じ場合.
    if(ve[0].second == vo[0].second){
        // 偶数番目で, 2番目に大きい整数を選択した場合.
        int v1 = N + ve[1].first + vo[0].first;
        // 奇数番目で, 2番目に大きい整数を選択した場合.
        int v2 = N + ve[0].first + vo[1].first;
        // 大小比較して, 小さい方を出力.
        printf("%d\n", min(v1, v2));
    }
    
    return 0;
    
}

Measured memory_bytes: 6520
def make_tree(n):
    i = 2
    while True:
        if i >= n * 2:
            tree = [[inf] * i for _ in range(26)]
            break
        else:
            i *= 2
    return tree

def update(i, x, tree):
    i += len(tree) // 2
    tree[i] = x
    i //= 2
    while True:
        if i == 0:
            break
        tree[i] = min(tree[2 * i], tree[2 * i + 1])
        i //= 2
    return

def find(s, t, tree):
    s += len(tree) // 2
    t += len(tree) // 2
    ans = inf
    while True:
        if s > t:
            break
        if s % 2 == 0:
            s //= 2
        else:
            ans = min(ans, tree[s])
            s = (s + 1) // 2
        if t % 2 == 1:
            t //= 2
        else:
            ans = min(ans, tree[t])
            t = (t - 1) // 2
    return ans

s = list(input())
t = list(input())
inf = 10 ** 6
n = len(s)
first = [-2] * 26
tree = make_tree(n)
for i in range(n):
    m = ord(s[i]) - 97
    update(i, i, tree[m])
    if first[m] == -2:
        first[m] = i
ans = 1
c = -1
for i in t:
    m = ord(i) - 97
    if not c == -1:
        u = -1
        u = find(c + 1, n - 1, tree[m])
        if u == -1 or u == inf:
            ans += n
            c = -1
        else:
            c = u
    if c == -1:
        c = first[m]
        if c == -2:
            print(-1)
            exit()
ans += c
print(ans)

Measured memory_bytes: 63232
class UnionFind:
    def __init__(self, n=1):
        self.par = [i for i in range(n)]
        self.rank = [0] * (n+1)
        self.cnt = 0

    
    def find(self, x):
        if self.par[x] == x:
            return x
        else:
            self.par[x] = self.find(self.par[x])
            return self.par[x]
    
    def groupsize(self):
        self.cnt = 0
        for i, x in enumerate(self.par):
            if x == i:
                self.cnt += 1
        return self.cnt
    
    def union(self, x, y):
        x = self.find(x)
        y = self.find(y)
        if self.rank[x] < self.rank[y]:
            self.par[x] = y
        else:
            self.par[y] = x
            if self.rank[x] == self.rank[y]:
                self.rank[x] += 1
    
    def same_check(self, x, y):
        return self.find(x) == self.find(y)

N, M = map(int,input().split())
A = [list(map(int,input().split())) for i in range(M)]
uf = UnionFind(N)

for i in range(M):
    uf.union(A[i][0]-1, A[i][1]-1)

print(uf.groupsize())

Measured memory_bytes: 32284
n=int(input())
s=[*input()]
q=int(input())
# BIT
B={chr(97+i):[0]*(n+1) for i in range(26)}
def bsum(c,i):
  s=0
  while i:
    s+=B[c][i]
    i-=i&-i
  return s
def badd(c,i,x):
  while i<=n:
    B[c][i]+=x
    i+=i&-i
for i,c in enumerate(s):
  badd(c,i+1,1)
for _ in range(q):
  x,y,z=input().split()
  y=int(y)-1
  if x=='1':
    badd(s[y],y+1,-1)
    s[y]=z
    badd(z,y+1,1)
  else:
    a=0
    for c in B:
      if bsum(c,int(z))-bsum(c,y): a+=1
    print(a)

Measured memory_bytes: 203856
# -*- coding: utf-8 -*-
"""
Created on Sun Dec  2 21:05:33 2018

@author: owner
"""

from math import log10

def cal(num,tup,k,max_,arr):
    r=0
    if k<0:
        if num <= max_ and arr[0]*arr[1]*arr[2]>0:
            return 1
        else:
            return 0
    for i,x in enumerate(tup):
        arr[i]+=1
        r+=cal(num+x*10**k,tup,k-1,max_,arr)
        arr[i]-=1
    return r

def fac(n):
    t=1
    for i in range(2,n+1):
        t*=i
    return t

N=int(input())
k=int(log10(N))

tup=(3,5,7)

ans=0
for i in range(2,k+1):
    ans+=cal(0,tup,i,N,[0,0,0])
print(ans)

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define ll long long
#define FOR(i,a,b) for(int i=(a); i<=(b); i++)
#define rep(i,n) for(int i = 0; i < (n); i++)
#define loop(k) rep(author_is_masa,k)
#define chmin(a,b) if((a)>(b)) (a)=(b);
#define chmax(a,b) if((a)<(b)) (a)=(b);
#define vi vector<int>
#define pii pair<int,int>
#define all(v) (v).begin(),(v).end()
#define allr(v) (v).rbegin(),(v).rend()
#define pb push_back
#define pf push_front
int gcd(int a,int b){/*a>=0,b>=0,￢(a=b=0)*/
  while(min(a,b)>0){if(a<b)swap(a,b);a%=b;}return max(a,b);
}
int dx[]={1,0,-1,0,1,-1,-1,1};
int dy[]={0,1,0,-1,1,1,-1,-1};
const int MOD = 1e9+7;
const long long INF = 1e18+10;

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

signed main(){
	int a,b,k;
	cin>>a>>b>>k;
	int g=gcd(a,b);
	vi yaku;
	for(int i=1;i<=g;i++){
		if(g%i==0) yaku.pb(i);
	}
	reverse(all(yaku));
	cout<<yaku[k-1]<<endl;
	return 0;
}

Measured memory_bytes: 3616
#include <iostream>
#include <vector>
#include <map>
#include <cstdio>

using namespace std;
 
#define rep(i, n) for (int i = 0; i < (int) n; i ++)
 
const long long MOD = 1e9 + 7;
const long long MOD2 = 1e9 + 9;
const long long B = 23456789;

long long Pow(long long a, long long x, long long m) {
        long long res = 1;
        while (x > 0) {
                if (x & 1) res = res * a % m;
                a = a * a % m;
                x >>= 1;
        }
        return res;
}

long long Inv(long long a, long long m) { return Pow(a, m - 2, m); }
 
int main() {
	int n;
        scanf("%d", &n);
	string s;
        cin >> s;
	int x = 250000;
        int x2 = 250000;
        long long h = 0;
        long long h2 = 0;
	vector<int> xs(n + 1);
	vector<int> xs2(n + 1);
        xs[0] = x;
        xs2[0] = x2;
	vector<long long> hs(n + 1);
	vector<long long> hs2(n + 1);
        hs[0] = h;
        hs2[0] = h2;
	rep(i, n) {
		char c = s[i];
		if (c == '+') h = (h + Pow(B, x, MOD)) % MOD;
		if (c == '-') h = (h - Pow(B, x, MOD) + MOD) % MOD;
		if (c == '>') x ++;
		if (c == '<') x --;
		xs[i + 1] = x;
                hs[i + 1] = h;
		if (c == '+') h2 = (h2 + Pow(B, x2, MOD2)) % MOD2;
		if (c == '-') h2 = (h2 - Pow(B, x2, MOD2) + MOD2) % MOD2;
		if (c == '>') x2 ++;
		if (c == '<') x2 --;
		xs2[i + 1] = x2;
                hs2[i + 1] = h2;
	}
	map<pair<long long, long long>, int> cnt;
	long long ans = 0;
	for (int i = n; i >= 0; i --) {
		int dx = xs[i] - xs[0];
		long long coef = (dx >= 0 ? Pow(B, dx, MOD) : Inv(Pow(B, -dx, MOD), MOD));
		long long hoge = (hs[i] + hs[n] * coef) % MOD;
		int dx2 = xs2[i] - xs2[0];
		long long coef2 = (dx2 >= 0 ? Pow(B, dx2, MOD2) : Inv(Pow(B, -dx2, MOD2), MOD2));
		long long hoge2 = (hs2[i] + hs2[n] * coef2) % MOD2;
		ans += cnt[make_pair(hoge, hoge2)];
		cnt[make_pair(hs[i], hs2[i])] ++;
	}
        printf("%lld\n", ans);
}


Measured memory_bytes: 37636
#include <iostream>
#include <vector>
#include <array>
#include <set>
#include <cmath>
#include <string>
#include <queue>
#include <list>
#include <unordered_map>
#include <algorithm>
#include <functional>
#include <iomanip> // std::std::setprecision(X)
#include <limits>  //std::numeric_limits<int>::max(), min()

int main (void) {

  std::string S; std::cin >> S;
  char b = S[0];
  for(int i=1; i<S.size(); i++) {
    if ( S[i] == b ) {
      std::cout << "Bad" << std::endl;
      return 0;
    }
    else b = S[i];
  }

  std::cout << "Good" << std::endl;

  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for (int (i) = 1; (i) < (n); i++)
#define ll long long
using namespace std;

int main(){
  int n ;
  cin>>n;
  int a[10000];
   rep(i,n+1){
    cin>>a[i];
    }
   int ans=0;
   rep(i,n+1){
    if(a[i] != i ){
        ans++;
    }
}
if(ans == 0 || ans == 2){
    cout<<"YES"<<endl;
}
else {
    cout<<"NO"<<endl;
}
}


Measured memory_bytes: 256
#include<cstdio>
#include<functional>
#include<algorithm>
#define MM 2100000000
using namespace std;
int a[100000][3],dp[100000][3];
int main(void)
{
	int n,i,j,k,mx;
	scanf("%d",&n);
	for(i=0;i<n;i++)	{
		for(j=0;j<3;j++)	scanf("%d",&a[i][j]);
	}
	for(i=0;i<n;i++)	{
		for(j=0;j<3;j++)	dp[i][j]=0;
	}
	for(j=0;j<3;j++)	dp[0][j]=a[0][j];
	for(i=1;i<n;i++)	{
		for(j=0;j<3;j++)	{
			for(k=0;k<3;k++)	{
				if(j!=k)	{
					dp[i][k]=max(dp[i][k],dp[i-1][j]+a[i][k]);
				}
			}
		}
	}
	mx=-1;
	for(j=0;j<3;j++)	mx=max(mx,dp[n-1][j]);
	printf("%d\n",mx);
	return 0;
}

Measured memory_bytes: 2560
#include <bits/stdc++.h>
#define repl(i, l, r) for (ll i = l; i < r; i++)
#define rep(i, n) repl(i, 0, n)
using namespace std;
using ll = long long;
using ld = long double;
using P = pair<int, int>;

int main()
{
    int w, h, x, y;
    cin >> w >> h >> x >> y;
    double ans1 = (double) w * h / 2;
    int ans2 = 0;
    if(2 * x == w && 2 * y == h) ans2 = 1;
    cout << setprecision(15) << ans1 << " " << ans2 << endl;
    return 0;
}


Measured memory_bytes: 3756
import sys
import  math
from statistics import *
from collections import *
from operator import itemgetter
"""
from fractions import gcd
def lcm(x, y):
    return (x * y) // gcd(x, y)
"""
stdin = sys.stdin
ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
ns = lambda: stdin.readline()

n = ni()
li = [2, 1]
for i in range(90):
    li.append(li[-1] + li[-2])
print(li[n])

Measured memory_bytes: 5084
#include <bits/stdc++.h>
#define ll long long int
#define ld long double
#define f first
#define s second
#define pb push_back
#define eb emplace_back
#define mk make_pair
#define MOD 1000000007
#define fo(i,a,b) for(i=a;i<b;i++)
#define foe(i,a,b) for(i=a;i<=b;i++)
#define all(x) x.begin(), x.end()
#define vi vector<int>
#define pii pair <int,int>
#define vpii vector< pair<int,int> >
#define boost ios::sync_with_stdio(false); cin.tie(0)
using namespace std;
int main()
{
	boost;
	int k, x;
	cin >> k >> x;
	k *= 500;
	cout << (k >= x ? "Yes" : "No");
}

Measured memory_bytes: 892
#include <bits/stdc++.h>
using namespace std;
int main()
{
  int n;
  cin >> n;
  vector<int> v(n);
  
  for(int i=0;i<n;i++){
    cin >> v[i];
  }
  sort(v.begin(),v.end());
  int P=v[0],Q=v[1];
       if(P<Q) swap(P,Q);
       while(P%Q!=0){
       P=P%Q;
       swap(P,Q);
       }
  for(int i=2;i<n-1;i++){
       int P=v[i];
       if(P<Q) swap(P,Q);
       while(P%Q!=0){
       P=P%Q;
       swap(P,Q);
  		}
    }
  cout << Q << endl;
}


Measured memory_bytes: 640
// https://atcoder.jp/contests/dp/tasks/dp_a

#include <algorithm>
#include <array>
#include <cmath>
#include <deque>
#include <iostream>
#include <limits>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <unordered_map>
#include <unordered_set>
#include <vector>
using namespace std;


/* range: ± 3.27 * 10^4 */
using i16 = short int;
/* range: 0 to 65535 */
using u16 = short unsigned int;
/* range: ± 2.14 * 10^9 */
using i32 = int;
/* range: 0 to 4.29 * 10^9 */
using u32 = unsigned int;
/* range: ± 9.22 * 10^18 */
using i64 = long long int;
/* range: 0 to 1.84 * 10^19 */
using u64 = long long unsigned int;


int main() {
    i32 n = 0;
    cin >> n;

    vector<i64> heights(n);
    for (auto& ht : heights) {
        cin >> ht;
    }

    vector<i64> dp(n, numeric_limits<i64>::max());
    dp[n - 1] = 0;
    for (auto i = n - 1; i > 0; i--) {
        dp[i - 1] = min(dp[i - 1], dp[i] + abs(heights[i] - heights[i - 1]));

        if (i - 2 >= 0) {
            dp[i - 2] =
                min(dp[i - 2], dp[i] + abs(heights[i] - heights[i - 2]));
        }
    }

    cout << dp[0] << '\n';
}

Measured memory_bytes: 4392
package main

import "fmt"

func bubbleSort(c []Card) {
	for i := 0; i < len(c); i++ {
		for j := len(c) - 1; j > i; j-- {
			if c[j].num < c[j-1].num {
				c[j], c[j-1] = c[j-1], c[j]
			}
		}
	}
}

func selectionSort(c []Card) {
	for i := 0; i < len(c); i++ {
		minj := i
		for j := i; j < len(c); j++ {
			if c[j].num < c[minj].num {
				minj = j
			}
		}
		c[i], c[minj] = c[minj], c[i]
	}
}

type Card struct {
	suit byte
	num  int
}

func (c Card) String() string {
	return fmt.Sprintf("%c%d", c.suit, c.num)
}

func main() {
	var n int
	fmt.Scan(&n)
	c := make([]Card, n)
	for i := range c {
		fmt.Scanf("%c%d", &c[i].suit, &c[i].num)
	}

	c1 := make([]Card, n)
	copy(c1, c)
	bubbleSort(c1)
	printCards(c1)
	if isSortedStably(c, c1) {
		fmt.Println("Stable")
	} else {
		fmt.Println("Not stable")
	}

	c2 := make([]Card, n)
	copy(c2, c)
	selectionSort(c2)
	printCards(c2)
	if isSortedStably(c, c2) {
		fmt.Println("Stable")
	} else {
		fmt.Println("Not stable")
	}
}

func printCards(c []Card) {
	for i, e := range c {
		if i > 0 {
			fmt.Print(" ")
		}
		fmt.Print(e)
	}
	fmt.Println()
}

func isSortedStably(orig, res []Card) bool {
	if len(res) < 2 {
		return true
	}

	if res[0].num == res[1].num {
		if indexOf(orig, res[0]) > indexOf(orig, res[1]) {
			return false
		}
	}

	return isSortedStably(orig, res[1:])
}

func indexOf(c []Card, card Card) int {
	for i, e := range c {
		if e.suit == card.suit && e.num == card.num {
			return i
		}
	}
	return -1
}



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

int main(){
  int N,answer;
  cin >> N;
  vector<int> V(N);
  vector<int> C(N); 
  for(int i=0;i<N;i++){
    cin>>V.at(i);  
  }
  for(int i=0;i<N;i++){
    cin>>C.at(i);  
  }
  
  for(int i=0;i<N;i++){
    if((V.at(i)-C.at(i))>0){
      answer+=V.at(i)-C.at(i);
    }
  }
  
  cout<<answer<<endl;
}


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

int main() {
    int  num_of_tuple = 0;
    cin >> num_of_tuple;
   
    string a;
    int b = 0;
    
    vector<tuple<string, int, int>> v(num_of_tuple);

    for (int i = 0; i < num_of_tuple; ++i) {
        cin >> a >> b;
        v.at(i) = make_tuple(a, b, 1+i); //3番目の要素にインデックスの代わりを入れる
    }
    
    //市名順にソート
    sort(v.begin(), v.end(), [](const tuple<string, int, int>& t1, const tuple<string, int, int>& t2){
        if(get<0>(t1) != get<0>(t2)){
            return get<0>(t1) < get<0>(t2);
        } else {
            return get<1>(t1) > get<1>(t2);
        }
    });
    
    
    
    //ソートしたものを出力
    for (tuple<string, int, int> i : v) {
        string s;
        int x=0,y=0;
        tie(s,x,y) = i;
        //cout << s << " " << x << " " << y << endl; //入っている要素を確かめるためのcout
        cout << y << endl;
    }
}



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

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

#pragma GCC optimize("Ofast")



using namespace std;

bool is_integer( float x ){
    return floor(x) == x;
}
bool is_integer(double x){
    return floor(x) == x;
}


int main() {

    int n,m; cin >> n >> m;
    vector<pair<int,bool>> v(3);
    bool ans = true;
    int sum = 0;
    int a = 1;
    int ml = 1;
    for(int i = 1; i < n; i ++){
        ml *= 10;
    }
    if(m == 0){
        if(n == 1) cout << 0;
        else if(n == 2) cout << 10;
        else if(n == 3) cout << 100;
    }
    else {
        rep(i, m) {
            a = 1;
            int s, c;
            cin >> s >> c;
            if (n != 1 && (n + 1) - s >= n && c == 0) {
                ans = false;
                break;
            }
            for (int j = 1; j < n + 1 - s; j++) {
                a *= 10;
            }

            if ((sum / a) % 10 == 0) sum += a * c;
            else {
                if ((sum / a) % 10 != c) {
                    ans = false;
                    break;
                }
            }

        }

        if (ans){
            if(sum < ml){
                if(n == 1) cout << 0;
                else if(n == 2) cout << sum + 10;
                else if(n == 3) cout << sum + 100;
            }else {
                cout << sum;
            }
        }
        else cout << -1;
    }
    return 0;
}











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

int main(){
	int N;
	cin >> N;
	vector<int> A(N);
	rep(i,N){
      int a;
      cin >> a;
      a--;
      A[i] = a;
    }
	vector<int> RA(N);
	rep(i,N) RA[A[i]] = i+1;
    rep(i,N) cout << RA[i] << " ";
	return 0;
}

Measured memory_bytes: 1536
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        while (true) {
            int n = scanner.nextInt();
            if (n == 0) break;
            int sum = 0;
            int min = 100000000;
            int max = 0;
            for (int i = 0; i < n; i++) {
                int p = scanner.nextInt();
                sum += p;
                if (p > max) max = p;
                if (p < min) min = p;
            }
            System.out.println((sum - min - max) / (n -2));
        }
        scanner.close();
    }
}



Measured memory_bytes: 29020