akhauriyash/Code-Regression huggingface dataset:
#include <algorithm>
#include <iomanip>
#include <iostream>
#include <vector>
using namespace std;
template <class T>
inline bool chmax(T &a, T b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}

typedef long long ll;
ll MOD = 1000000007;

// a^p
// 2^3 = 2 * 2^2
// 2^2 = 2 * (2^1)
// 2^1 = 2
ll modpow(ll a, ll p, ll mod) {
  if (p == 0) return 1;

  if (p % 2 == 0) {
    ll half = modpow(a, p / 2, mod) % mod;
    return half * half % mod;
  } else {
    return a * modpow(a, p - 1, mod) % mod;
  }
}

// nCa を求める
ll modCombination(ll n, ll a, ll mod) {
  if (n - a < a) {
    return modCombination(n, n - a, mod);
  }

  ll denominator = 1;  // 分母
  ll numerator = 1;    // 分子

  for (ll i = 0; i < a; i++) {
    denominator *= a - i;
    numerator *= n - i;
    denominator %= mod;
    numerator %= mod;
  }

  return numerator * modpow(denominator, mod - 2, mod) % mod;
}

class UnionFind {
 private:
  vector<ll> parents;

 public:
  UnionFind(ll n) : parents(n, -1) {}

  bool issame(ll x, ll y) { return root(x) == root(y); }

  bool merge(ll x, ll y) {
    if (issame(x, y)) return false;

    ll rx = root(x);
    ll ry = root(y);
    if (parents[rx] > parents[ry]) swap(rx, ry);
    // サイズ情報を更新
    parents[rx] += parents[ry];
    // yの親を更新
    parents[ry] = rx;

    return true;
  }

  ll size(ll x) { return -parents[root(x)]; }

 private:
  ll root(ll x) {
    if (parents[x] < 0) return x;
    // 根の親の値に木の(-)サイズの情報を入れる
    return parents[x] = root(parents[x]);
  }
};

void dfs(string s, ll n, char mx) {
  if ((ll)s.size() == n) {
    cout << s << endl;
    return;
  }

  for (char c = 'a'; c <= mx + 1; c++) {
    string t = s;
    t += c;
    dfs(t, n, max(mx, c));
  }
}

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

  ll N;
  cin >> N;

  dfs("", N, 'a' - 1);

  return 0;
}


Measured memory_bytes: 1536
#![allow(unused_imports)]
use std::collections::HashMap;
use std::collections::HashSet;
use std::collections::VecDeque;
use std::collections::BinaryHeap;

#[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) =>
        (rl().parse::<$t>().unwrap());
    ($($t:ty),*) => {{
        let buf = rl();
        let mut w = buf.split_whitespace();
        ($(w.next().unwrap().parse::<$t>().unwrap()),*)
    }};
}

#[allow(dead_code)]
fn rl() -> String {
    let mut buf = String::new();
    std::io::stdin().read_line(&mut buf).unwrap();
    buf.trim_end().to_owned()
}

trait IteratorExt: Iterator + Sized {
    fn vec(self) -> Vec<Self::Item> {
        self.collect()
    }
}
impl<T: Iterator> IteratorExt for T {}

fn main() {
    let (n, m, mut k) = read!(usize, usize, usize);
    let k_cpy = k;
    let a = read!([usize]);
    let b = read!([usize]);

    let mut sum_a = vec![0; n+1];
    let mut sum_b = vec![0; m+1];

    for i in 1..n+1 {
        sum_a[i] = sum_a[i-1] + a[i-1];
    }
    for i in 1..m+1 {
        sum_b[i] = sum_b[i-1] + b[i-1];
    }
    
    // aをできるだけ読んでからbをできるだけ読む
    let mut idx_a = 0; //現在idx_a冊読んでいる
    let mut idx_b = 0;
    while idx_a <= n && sum_a[idx_a] <= k {
        idx_a += 1;
    }
    idx_a -= 1;
    k -= sum_a[idx_a];
    while idx_b <= m && sum_b[idx_b] <= k {
        idx_b += 1;
    }
    idx_b -= 1;

    // 全部読めてた
    if idx_a == n && idx_b == m {
        println!("{}", n+m);
        return;
    }

    let max_a = idx_a;
    let mut max_count = idx_a + idx_b;
    for i in 1..=max_a {
        // aをi冊読むのやめる
        k = k_cpy - sum_a[max_a - i];
        // その時bは？
        while idx_b <= m && sum_b[idx_b] <= k {
            idx_b += 1;
        }
        idx_b -= 1;
        if max_count < idx_b + max_a - i {
            max_count = idx_b + max_a - i;
        }
    }
    println!("{}", max_count);
}


Measured memory_bytes: 8772
#include <bits/stdc++.h>
#define mp make_pair
#define pb push_back
#define sz(x) (int)x.size()
#define all(x) begin(x), end(x)
#define fi first
#define se second
#define debug(x) cerr << #x << " " << x << '\n'
using namespace std;
using ll = long long;
using pii = pair<int,int>;
using pli = pair<ll,int>;
const int INF = 0x3f3f3f3f, N = 2e3 + 5;
const ll LINF = 1e18 + 5;
constexpr int mod = 1e9 + 7;
int n, x, y, dis[N], cnt[N];
vector <int> G[N];
void bfs(int u)
{
	for(int i=1; i<=n; i++) dis[i] = -1;
	dis[u] = 0;
	queue <int> q;
	q.push(u);
	while(sz(q))
	{
		int v = q.front(); q.pop();
		cnt[dis[v]]++;
		for(int to : G[v])
		{
			if(dis[to]==-1)
			{
				dis[to] = dis[v] + 1;
				q.push(to);
			}
		}
	}
}
int main()
{
	ios::sync_with_stdio(false);
	cin.tie(0);
	cin >> n >> x >> y;
	for(int i=1; i<n; i++) G[i].pb(i+1), G[i+1].pb(i);
	G[x].pb(y); G[y].pb(x);
	for(int i=1; i<=n; i++) bfs(i); 
	for(int i=1; i<n; i++) cout << cnt[i]/2 << '\n';
	return 0;
}

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

template <class T1, class T2>
ostream& operator << (ostream& out, const pair <T1, T2> p)
{
	out << '(' << p.first << ',' << p.second << ')';
	return out;
}
 
template <class T1, class T2>
istream& operator >> (istream& in, pair<T1, T2> &p)
{
	in >> p.first >> p.second;
	return in;
}
 
template <class T>
istream& operator >> (istream& in, vector<T> &v)
{
	for (T &x : v)
		in >> x;
	return in;
}
 
template <class T>
ostream& operator << (ostream& out, const vector<vector<T>> &v)
{
	for (const vector<T> &x : v)
		out << x << '\n';
	return out;
}
 
template <class T>
ostream& operator << (ostream& out, const vector<T> &v)
{
	for (const T &x : v)
		out << x << ' ';
	return out;
}


#define ll long long
#define lf long double
#define pb push_back
#define mp make_pair
#define F first
#define S second
typedef pair <ll,ll > ii;
typedef vector <ll> vi;
typedef vector <ii> vii;
typedef vector <bool> vb;
typedef vector <vector <ll> > vv;
typedef vector <vector <vector<ll> > > vvv;
typedef vector <string> vs;
typedef vector <lf> vf;
#define sz(x) (ll)(x).size()
#define tr1(x) cerr << #x << ": " << x << nl
#define tr2(x, y) cerr << #x << ": " << x << " | " << #y << ": " << y << nl
#define tr3(x,y,z) cerr<<#x<<": "<<x<<" | "<<#y<<": "<<y<<" | "<<#z<<": "<<z<<nl
#define tr4(x,y,z,w) cerr<<#x<<": "<<x<<" | "<<#y<<": "<<y<<" | "<<#z<<": "<<z<<" | "<<#w<<": "<<w<<nl
#define trv(a) cerr<<#a<<": ";for(ll zz=0;zz<sz(a);zz++) cerr<<a[zz]<<" ";cerr<<nl
#define trset(s) cerr<<#s<<": ";for(auto &i:s) cerr<<i<<" ";cerr<<nl
#define epsilon 0.000000001L
#define inf 9999999999999999ll// ~ 10^16
#define nl endl
#define all(x) x.begin(), x.end()
#define r_all(x) x.rbegin(), x.rend()
#define fast()  ios_base::sync_with_stdio(false);cin.tie(NULL)
#define mod 1000000007ll
#define modulo 998244353ll
ll power(ll a,ll b){return b?power(a*a%mod,b/2)*(b%2?a:1)%mod:1;}



int main() 
{
    fast();
    ll a,b,c,k;
    cin>>a>>b>>c>>k;
    ll ans=min(a,k);
    k-=ans;

    k-=min(b,k);

    ans-=min(c,k);
    cout<<ans<<nl;

}


Measured memory_bytes: 3592
// </> : towhid1zaman

#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef pair< int, int > pii;
typedef pair< pii, int > ppi;
#define fill(a,b) memset(a,b,sizeof(a))
#define all(v) (v).begin(),(v).end()
#define sp(k) cout<<setprecision(k)<<fixed;
#define rep(i,a) for(int i=0;i<a;i++)
#define rep1(i,a,b) for(int i=(a);i<=(b);++i)
#define irep(i,b,a) for(int i=(b);i>=(a);--i)
#define minv(v) *min_element(all(v))
#define maxv(v) *max_element(all(v))
#define unq(v) sort(all(v)),(v).erase(unique(all(v)),(v).end())
#define _ ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define endl "\n"
#define sqr(a) ((a)*(a))
#define sz(a) int(a.size())
#define ff first
#define ss second
#define pb push_back

const double pi = acos(-1.0);
const int mod = 1000000007; // (int)1e9+7
const int inf = 0x3f3f3f3f;// (int)3e18;
const int maxn = 2000100;



int main(){
        _
        string s; cin >> s;
        int ans = 1;
        bool f = 0;
        int n = s.length();
        rep1(i,1,sz(s)-1){
            if(f==0){
            if(s[i]==s[i-1]){
                f = 1;
                i++;
                if(i<n)ans++;
            }
            else{
                ans++;
            }
        }
        else{
            f = 0;
            ans++;
        }
    }

    cout<<ans<<endl;

return 0;
}




Measured memory_bytes: 720
def solve(string):
    is_a = string[0] == "A"
    index_c = string.find("C")
    rest = string[1:index_c] + string[index_c + 1:]
    return "AC" if is_a and 1 < index_c < len(string) -1 and rest == rest.lower() else "WA"


if __name__ == '__main__':
    print(solve(input()))


Measured memory_bytes: 38512
k, a, b = map(int, input().split())
kk = k
ans = 0
if a >= b:
    ans += k+1
else:
    if k <= a:
        ans += k+1
    else:
        ans += a
        k -= a - 1
        if k % 2 == 1:
            ans += 1
            k -= 1
        ans += (k // 2)*(b - a)


        ans = max(ans, kk+1)

print(int(ans))


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

const int HW = 100;

int main() {
    int A, B;
    cin >> A >> B;
    char a = '.', b = '#';

    if (A > B) {
        swap(A, B);
        swap(a, b);
    }

    int both = A - 1;
    int single = B - (A - 1);
    vector<string> grid(HW, string(HW, a));

    for (int row = 0; row < HW; row += 4)
        for (int col = 0; col < HW; col += 4)
            if (both-- > 0) {
                for (int r = row; r <= row + 2; r++)
                    for (int c = col; c <= col + 2; c++)
                        grid[r][c] = b;

                grid[row + 1][col + 1] = a;
            } else if (single-- > 0) {
                grid[row][col] = b;
            }

    cout << HW << ' ' << HW << '\n';

    for (int row = 0; row < HW; row++)
        cout << grid[row] << '\n';
}


Measured memory_bytes: 256
#!usr/bin/env python3
from collections import defaultdict,deque
from heapq import heappush, heappop
import sys
import math
import bisect
import random
def LI(): return [int(x) for x in sys.stdin.readline().split()]
def I(): return int(sys.stdin.readline())
def LS():return [list(x) for x in sys.stdin.readline().split()]
def S():
    res = list(sys.stdin.readline())
    if res[-1] == "\n":
        return res[:-1]
    return res
def IR(n):
    return [I() for i in range(n)]
def LIR(n):
    return [LI() for i in range(n)]
def SR(n):
    return [S() for i in range(n)]
def LSR(n):
    return [LS() for i in range(n)]

sys.setrecursionlimit(1000000)
mod = 1000000007

def solve():
    pi = 3.141592653589793238
    a,b,x = LI()
    h = x/a**2
    s = x/a
    theta = 180*math.atan(2*(b-h)/a)/pi
    theta2 = 180*math.atan(2*h/a)/pi
    if theta < theta2:
        print(theta)
    else:
        print(180*math.atan((b**2)/2/s)/pi)
    return

#Solve
if __name__ == "__main__":
    solve()


Measured memory_bytes: 39280
#include <cstdio>
#include <algorithm>
#include <cstring>
#include <cmath>
#include <queue>
#include <vector>
#include <map>
#include <set>
#define MAXN 205
#define P 1000000007
#define G 3
#define INF 0x3f3f3f3f
#define rint register int
#define LL long long
#define LD long double
#define fuck printf("FUCK!!\n");
using namespace std;

int n, x, s[MAXN], f[MAXN][100005];

inline int add(int x, int y) {return x+y>=P?x+y-P:x+y;}
inline int sub(int x, int y) {return x>=y?x-y:x-y+P;}

int main()
{
    scanf("%d%d",  &n, &x);
    for(rint i=1; i<=n; ++i) scanf("%d", &s[i]);
    sort(s+1, s+n+1);
    for(rint i=1; i<=x; ++i) f[0][i]=i;
    for(rint i=1; i<=n; ++i)
        for(rint j=1; j<=x; ++j)
            f[i][j]=add(f[i-1][j%s[i]], 1LL*(i-1)*f[i-1][j]%P);
    printf("%d\n", f[n][x]);
    return 0;
}

Measured memory_bytes: 80000
li_a = list(input())
li_b = list(input())
li_c = list(input())


def play(name):
    if name == 'A':
        current = li_a
    elif name =='B':
        current = li_b
    else:
        current = li_c

    if len(current) > 0:
        drop = current.pop(0)
        play(str(drop).upper())

    else:
        print(name)
        exit(0)

play("A")



Measured memory_bytes: 3188
#include<iostream>
#include<algorithm>
using namespace std;
static const int MAX = 200000;

int main(){
	int R[MAX], n;

	cin >> n;
	for(int i=0; i<n ; i++){
		cin >> R[i];
	}
	int maxv = -2000000000;
	int minv = R[0];

	for(int i=1; i<n; i++){
		maxv = max(R[i]-minv, maxv);
		minv = min(R[i], minv);
	}
	cout << maxv << endl;
	return 0;
}


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

// 縦height(px),横width(px)の画像を受け取って、周りを"#"で囲んだ物を返すプログラム
// >> 2 3
// >> abc
// >> arc
// #####
// #abc#
// #arc#
// #####
int main() {
    int height,width;
    cin >> height >> width;

    // 画像の上のフレームを表示する
    for (int i = 0; i < width + 2; i++)
    {
        cout << "#";
    }
    cout << endl;
    
    // 画像の横のフレームを表示する
    for (int i = 0; i < height; i++)
    {
        string s;
        cin >> s;
        cout << "#" << s << "#" << endl;
    }

    // 画像の下のフレームを表示する
    for (int i = 0; i < width + 2; i++)
    {
        cout << "#";
    }
    cout << endl;
    
}

Measured memory_bytes: 256
using System;

class Program
{
	static void Main()
	{
		Console.ReadLine();
		long a = 0;
		string[] sD = Console.ReadLine().Split(' ');
		int[] D = new int[sD.Length];
		for (int i = 0; i < sD.Length; i++)
		{
			D[i] = int.Parse(sD[i]);
		}
		Array.Sort(D);
		for (int i = 0; i < D.Length; i++)
		{
			a += D[i];
		}
		Console.WriteLine("{0} {1} {2}", D[0], D[D.Length - 1], a);
	}
}

Measured memory_bytes: 13880
//#pragma GCC optimize("Ofast,unroll-loops,no-stack-protector")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")

#include <bits/stdc++.h>
// #include <bits/extc++.h>
using namespace std;

#define debug(s) cout << #s << " = " << s << endl
#define all(v) (v).begin(), (v).end()
#define KeepUnique(v) (v).erase( unique(all(v)), v.end() )
#define MEMSET(a, val) memset(a, val, sizeof (a))
#define PB push_back
#define endl '\n'
typedef long long ll;

inline int myrand(int l, int r) {
	int ret = rand(); ret <<= 15; ret ^= rand();
	if(ret < 0) ret = -ret; ret %= (r-l+1); ret += l;
	return ret;
}

template <typename F, typename S>
ostream& operator << (ostream &os, const pair<F, S> &p) {
	return os << "(" << p.first << ", " << p.second << ")"; }

typedef pair<int, int> ii;

template<typename T> using min_pq =
	std::priority_queue<T, vector<T>, greater<T> >;

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

const int mod = 1e9 + 7;
const int maxn = 2e5 + 5;

int n, a[maxn], cnt[maxn], k = 0;

int32_t main () {
	// freopen("in", "r", stdin);
	cin >> n;
	for(int i = 1; i <= n; i++) {
		int x; cin >> x;
		if(x != a[k]) {
			a[++k] = x;
		}
	}
	n = k;
	cnt[a[1]] = 1;
	for(int i = 1; i <= n; i++) {
		cnt[a[i + 1]] += cnt[a[i]];
		if(cnt[a[i + 1]] >= mod) cnt[a[i + 1]] -= mod;
	}
	cout << cnt[a[n]] << endl;
}

Measured memory_bytes: 1792
#pragma GCC optimize(2)
#include<bits/stdc++.h>
using namespace std;
#define endl '\n'
typedef long long LL;
const int MAXN = 2e5+10;
const int MOD = 998244353;
const int INF = 0x3f3f3f3f;
signed main(){
    string ss; cin>>ss;
    int l=0,r=ss.length()-1,res=0;
    while(l<=r){
        if(ss[l]!=ss[r]) res++;
        l++,r--;
    }
    cout<<res<<endl;
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
using namespace std;
 
    
    
int main(){
  string s;
  cin>>s;
  for (int i = 0; i < (s.size()-1)/2; i++)
  {
    if (s[i]!=s[s.size()-1-i])
    {
      cout<<"No"<<endl;
      return 0;
    }
    
  }
  
  for (int i = 0; i < (s.size()-1)/4; i++)
  {
    //cout<<s[i]<<endl;
    if (s[i]!=s[(s.size()-1)/2-i-1])
    {
      cout<<"No"<<endl;
      return 0;
    }
    
  }
  cout<<"Yes"<<endl;
    return 0;
}

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

#define ALL(a)  (a).begin(),(a).end()
#define ALLR(a)  (a).rbegin(),(a).rend()
#define spa << " " <<
#define test cout<<"test"<<endl;
#define fi first
#define se second
#define MP make_pair
#define rep(i,n,m) for(ll i = n; i < (ll)(m); i++)
#define rrep(i,n,m) for(ll i = n - 1; i >= (ll)(m); i--)
typedef long long ll;
typedef long double ld;
const ll MOD = 1e9+7;
//const ll MOD = 998244353;
const ll INF = 1e18;
using P = pair<ll, ll>;
template<typename T>
void chmin(T &a,T b){if(a>b)a=b;}
template<typename T>
void chmax(T &a,T b){if(a<b)a=b;}
void pmod(ll &a,ll b){a=(a+b)%MOD;}
void pmod(ll &a,ll b,ll c){a=(b+c)%MOD;}
void qmod(ll &a,ll b){a=(a*b)%MOD;}
void qmod(ll &a,ll b,ll c){a=(b*c)%MOD;}
ll median(ll a,ll b, ll c){return a+b+c-max({a,b,c})-min({a,b,c});}
void ans1(bool x){if(x) cout<<"Yes"<<endl;else cout<<"No"<<endl;}
void ans2(bool x){if(x) cout<<"YES"<<endl;else cout<<"NO"<<endl;}
void ans3(bool x){if(x) cout<<"Yay!"<<endl;else cout<<":("<<endl;}
template<typename T1,typename T2>
void ans(bool x,T1 y,T2 z){if(x)cout<<y<<endl;else cout<<z<<endl;}  
template<typename T>
void debug(vector<vector<T>>v,ll h,ll w){for(ll i=0;i<h;i++)
{cout<<v[i][0];for(ll j=1;j<w;j++)cout spa v[i][j];cout<<endl;}};
void debug(vector<string>v,ll h,ll w){for(ll i=0;i<h;i++)
{for(ll j=0;j<w;j++)cout<<v[i][j];cout<<endl;}};
template<typename T>
void debug(vector<T>v,ll n){cout<<v[0];
for(ll i=1;i<n;i++)cout spa v[i];cout<<endl;};
template<typename T>
vector<vector<T>>vec(ll x, ll y, T w){
  vector<vector<T>>v(x,vector<T>(y,w));return v;}
ll gcd(ll x,ll y){ll r;while(y!=0&&(r=x%y)!=0){x=y;y=r;}return y==0?x:y;}
//m.emplace(x,0).fi->se++;

int main(){
  cin.tie(NULL);
  ios_base::sync_with_stdio(false);
  ll res=0,res1=INF,res2=-INF,buf=0;
  bool judge = true;
  string s;cin>>s;
  ll n=s.size();
  char c='A';
  ll countbuf=0;
  rep(i,0,n){
    if(c!=s[i]){
      c=s[i];
      if(countbuf!=0){
        if(countbuf%3==0)res+=countbuf/3*2;
        if(countbuf%3==1)res+=countbuf/3*2+1;
        if(countbuf%3==2){
          res+=countbuf/3*2+2;
          countbuf=-1;
        }
      }
      if(countbuf!=-1)countbuf=1;
      else countbuf=0;
    }
    else countbuf++;
    //cout<<countbuf spa res spa c<<endl;
  }

  if(countbuf!=0){
        if(countbuf%3==0)res+=countbuf/3*2;
        if(countbuf%3==1)res+=countbuf/3*2+1;
        if(countbuf%3==2){
          res+=countbuf/3*2+1;
        }
  }
  cout<<res<<endl;
  
  return 0;
}

Measured memory_bytes: 720
N = int(input())
A = []

maxN = 0 
secmax = 0

for i in range(N):
  x = int(input())
  A.append(x)
  if maxN <= x:
    secmax = maxN
    maxN = x
  elif secmax <= x:
    secmax = x
  
for a in A:
  print(secmax if maxN == a else maxN)

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

// template {{{  0 
// using {{{ 1
using ll = long long int;
using pii = pair<int,int>;
using pll = pair<ll,ll>;
using vi = vector<int>;
using vl = vector<ll>;
using vii = vector<pii>;
using vll = vector<pll>;
// }}} 1
// definition {{{ 1
// scaning {{{ 2
#define Scd(x) scanf("%d", &x)
#define Scd2(x,y) scanf("%d%d", &x, &y)
#define Scd3(x,y,z) scanf("%d%d%d", &x, &y, &z)
#define Scll(x) scanf("%lld", &x)
#define Scll2(x,y) scanf("%lld%lld", &x, &y)
#define Scll3(x,y,z) scanf("%lld%lld%lld", &x, &y, &z)
#define Scc(c) scanf("%c", &c);
#define Scs(s) scanf("%s", s);
#define Scstr(s) scanf("%s", &s);
// }}} 2
// constants {{{ 2
#define EPS (1e-7)
#define INF (2e9)
#define PI (acos(-1))
// }}} 2
// systems {{{ 2
#define Repe(x,y,z) for(ll x = z; x < y; x++)
#define Rep(x,y) Repe(x,y,0)
#define RRepe(x,y,z) for(ll x = y-z-1; x >= 0; x--)
#define RRep(x,y) RRepe(x,y,0)
// }}} 2
// output {{{ 2
#define YesNo(a) (a)?printf("Yes\n"):printf("No\n")
#define YESNO(a) (a)?printf("YES\n"):printf("NO\n")
// }}} 2
// }}} 1
// input {{{ 1
// }}} 1
// }}} 0

int main() {

    int N;
    Scd(N);

    char s[102022];
    Scs(s);

    char pre = 0;
    int ans = 0;
    Rep(i,N){
        if( pre != s[i] ) ans++;
        pre = s[i];
    }

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

    return 0;
}




Measured memory_bytes: 384
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define deb(x) cout << #x << " = "<< x << "\n";

signed main() {
	//freopen("in.txt", "r",stdin);
	ios::sync_with_stdio(false);
	cin.tie(0); cout.tie(0);
	
	int k; cin >> k;
	set<int> s;
	
	int num = 0;
	
	for(int i = 1;; i++) {
	    num = (num *10 +  7) % k;
	    if(num == 0) {
	        cout << i << "\n";
	        break;
	    }
	    if(s.count(num)) {
	        cout << "-1\n";
	        break;
	    } else s.insert(num);
	}
}


Measured memory_bytes: 50484
#include <iostream>
#include <vector>
#include <map>
#include <algorithm>
#include <string>
#include <numeric>
#include <math.h>

using namespace std;


void func()
{
	int64_t N, ai = 0;;
	cin >> N;
	for (int64_t i = 1; i <= N; ++i)
	{
		if (i % 3 == 0 || i % 5 == 0)
			continue;
		ai += i;
	}
	cout << ai << endl;
}

int main() {

//	while (1)
		func();
	return 0;
}


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

int gcd(int a, int b)
{
  if(a < b) swap(a, b);
  int r = a%b;
  while(r != 0)
  {
    a = b;
    b = r;
    r = a%b;
  }
  return b;
}

int main()
{
  int n;
  cin >> n;
  vector<int> a(n);
  int i;
  for(i = 0; i < n; i++)
  {
    cin >> a.at(i);
  }
  vector<int> gcdfroml(n-1);
  vector<int> gcdfromr(n-1);
  gcdfroml.at(0) = a.at(0);
  gcdfromr.at(0) = a.at(n-1);
  for(i = 1; i < n-1; i++)
  {
    gcdfroml.at(i) = gcd(gcdfroml.at(i-1), a.at(i));
    gcdfromr.at(i) = gcd(gcdfromr.at(i-1), a.at(n-1-i));
  }
  int ans = 0;
  int gcdmax;
  for(i = 0; i < n; i++)
  {
    if(i == 0)
    {
      gcdmax = gcdfromr.at(n-2);
    }
    else if(i == n-1)
    {
      gcdmax = gcdfroml.at(n-2);
    }
    else
    {
      gcdmax = gcd(gcdfroml.at(i-1), gcdfromr.at(n-2-i));
    }
    if(gcdmax > ans) ans = gcdmax;
    gcdmax = 0;
  }
  cout << ans << endl;
}

Measured memory_bytes: 1408
#include <iostream>

using namespace std;

int main(){
	int w,h,x,y,r;
	cin>>w>>h>>x>>y>>r;

	if(x+r<=w&&y+r<=h&&x-r>=0&&y-r>=0){
		cout<<"Yes"<<endl;
	}else{
		cout<<"No"<<endl;
	}

	return 0;

}

Measured memory_bytes: 3088
#include<stdio.h>

#define N 100
#define INF 2001
#define BLACK 1
#define WHITE 2

int prim();

int n,a[N][N];

int main(){

  int i,j;

  scanf("%d",&n);
  for(i=0;i<n;i++){
    for(j=0;j<n;j++){
      scanf("%d",&a[i][j]);
    }
  }

  printf("%d\n",prim());
  return 0;
}
int prim(){
  int i,u,v,color[100],d[N],pi[N],mincost,ans=0;

  for(i=0;i<n;i++){
    d[i]=INF;
    pi[i]=-1;
    color[i]=WHITE;
  }
  d[0]=0;

  while(1){
    mincost=INF;
    for(i=0;i<n;i++){
      if(color[i] != BLACK && d[i] < mincost){
	mincost=d[i];
	u=i;
      }
    }

    if(mincost==INF)break;

    color[u]=BLACK;
    for(v=0;v<n;v++){
      if(a[u][v]!=-1){
	if(color[v] != BLACK && a[u][v] < d[v]){
	  pi[v]=u;
	  d[v]=a[u][v];
	}
      }
    }
  }

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

  return ans;

}

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

#define OnlineJudge1

#define loop(x,a,n) for(int x = a;x < n;x++)
#define NumofDigits(n) ((int)log10(n)+1)
#define CountofNumber(array,n,x)  (upper_bound(array, array+n, x)-lower_bound(array, array+n, x))
#define readline(s) getline(cin,s)
#define PB push_back
#define MP make_pair
#define F first
#define S second
#define EPS 1e-7
#define modulo ll (1e9 + 7)
const long double PI = 3.141592653589793238L;

typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef pair<int,int> pii;
typedef pair<int,ll> pill;
typedef pair<ll,ll> pll;

#define debug(...) fprintf(stderr, __VA_ARGS__), fflush(stderr)

#define time__(d) \
    for ( \
        auto blockTime = make_pair(chrono::high_resolution_clock::now(), true); \
        blockTime.second; \
        debug("%s: %lld ms\n", d, chrono::duration_cast<chrono::milliseconds>(chrono::high_resolution_clock::now() - blockTime.first).count()), blockTime.second = false \
    )

void init(){
    cin.tie(0);
    ios::sync_with_stdio(0);
#ifdef OnlineJudge
    freopen("in.txt","r",stdin);
    freopen("out.txt","w",stdout);
#endif
}

int main(){
    init();

    int a,b,c;   cin >> a >> b >> c;

    int arr[10] = {0};
    arr[a]++;
    arr[b]++;
    arr[c]++;

    if(arr[5] == 2 && arr[7] == 1)
        cout << "YES";
    else
        cout << "NO";
}


Measured memory_bytes: 256
#include <iostream>
#include<string>
#include<cmath>
#include<algorithm>
#include<cctype>
#include<queue>
#include<deque>
#include<regex>
#include<stack>
#include<stdio.h>
#include<vector>
#include<set>
#include<map>
#include<iomanip>

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

typedef int long long ll;
using namespace std;
typedef pair<int, int> P;
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};
const ll MOD = 1e9 + 7;
static const int MAX = 100;
static const int INF = (1 << 23);

int main() {
    ll n;
    cin>>n;
    vector<ll> l(n);
    rep(i,n){
        cin>>l[i];
    }

    ll ans=0;

    sort(l.begin(),l.end());
  //  map<pair<ll,ll> ll> m;
    for(int i=0;i<n-2;i++){
        for(int j=i+1;j<n-1;j++){
            ll a = l[i];
            ll b = l[j];
            ll lef = abs(a-b);
            ll ri = a+b;

            auto p1 = upper_bound(l.begin(),l.end(),lef) - l.begin();
            auto p2 = lower_bound(l.begin(),l.end(),ri) - l.begin();


//           if(p1>=j)p1++;
//           if(p2<j)p2--;
          // cout<<i<<" "<<j<<endl;
           if(p1<=i)p1=i;
           if(p2<=i)p2=i;
           if(p1<=j)p1=j;
           if(p2<=j)p2=j;


           // cout<<p1<<" "<<p2<<endl;

            ll aa =p2-p1-1;

            if(p1<i&&i<p2)aa--;
            if(p1<j&&j<p2)aa--;

            if(aa>=0)ans+=aa;
            //cout<<aa<<endl;

        }
    }

    cout<<ans<<endl;



    return 0;
}


Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
const int MAXN=100010;
inline int read(){
    int f=1,x=0;
    char ch=getchar();
    while(ch<'0'||ch>'9') {if(ch=='-') f=-1;ch=getchar();}
    while(ch>='0'&&ch<='9') {x=x*10+ch-'0';ch=getchar();}
    return f*x;
}
int main(){
    int a,b,t;
    cin>>a>>b>>t;
    cout<<t/a*b;
    return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<math.h>
#define true 1
#define false 0
typedef long long ll;
typedef unsigned char Uchar; 

int main(void){
  
  int i,j;
  ll x,k,d;
  scanf("%lld %lld %lld",&x,&k,&d);
  x = fabsl(x);
  ll ans = 0;
  if(x/d >= k){
   ans = x - d*k; 
  }else{
    ll e = x/d;
    k -= e;
    x -= e * d;
    if(k%2) x = fabsl(x-d);
    ans = x;
  }
  
  printf("%lld",ans);
  return 0;
}

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

int main() {
	int n,k;
	cin>>n>>k;
	int a[n];
	for(int i=0;i<n;i++)
	cin>>a[i];
	vector<int> v(n,INT_MAX);
//	b[n]={INT_MAX};
	v[0]=0;
	for(int i=0;i<n;i++){
	for(int j=1;j<=k;j++){
		if(i+j>=n)
		break;
		v[i+j]=min(v[i+j],v[i]+abs(a[i]-a[i+j]));
	}
	}
	cout<<v[n-1];
	return 0;
}

Measured memory_bytes: 1024
#!usr/bin/env python3
from collections import defaultdict, deque
from heapq import heappush, heappop
from itertools import permutations, accumulate
import sys
import math
import bisect
def LI(): return [int(x) for x in sys.stdin.readline().split()]
def I(): return int(sys.stdin.readline())
def LS():return [list(x) for x in sys.stdin.readline().split()]
def S():
    res = list(sys.stdin.readline())
    if res[-1] == "\n":
        return res[:-1]
    return res
def IR(n):
    return [I() for i in range(n)]
def LIR(n):
    return [LI() for i in range(n)]
def SR(n):
    return [S() for i in range(n)]
def LSR(n):
    return [LS() for i in range(n)]

sys.setrecursionlimit(1000000)
mod = 1000000007

def solve():
    n,m,v,p = LI()
    a = LI()
    a.sort()
    l = -1
    r = n-1
    while l+1 < r:
        i = (l+r) >> 1
        A = a[i]+m
        ri = bisect.bisect_right(a,A)
        j = n-ri
        if j >= p:
            l = i
            continue
        s = m
        for j in range(n-p+1):
            if i == j:
                continue
            s += min(m,A-a[j])
        s += m*(p-1)
        if s >= m*v:
            r = i
        else:
            l = i
    print(n-r)
    return

#Solve
if __name__ == "__main__":
    solve()


Measured memory_bytes: 58736
n=int(input())
def dfs(s):
    if int(s)>n:
        return 0
    a=s.count("7")
    b = s.count("5")
    c = s.count("3")
    if min(a,b,c)>0:
        ans=1
    else:
        ans=0
    for c in "753":
        ans+= dfs(s+c)
    return ans

print(dfs("0"))

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

int main(){
  string s1, s2;
  cin >> s1 >> s2;
  
  int j=0;
  
  for(int i=0; i<s1.size(); i++){
    cout << s1.at(i);
    if(i+1 <= s2.size()){
     while(j<i+1){
      cout << s2.at(j);
      j++;
     }
    }
  }
}

Measured memory_bytes: 256
import java.util.Scanner;
 
public class Main{
    public  static void main(String[] args){
        Scanner scan = new Scanner(System.in);

        int[][][] official_house =  new int[4][3][10];

        int n = scan.nextInt();
        for(int i = 0; i < n; i++) {
            int b = scan.nextInt() - 1;
            int f = scan.nextInt() - 1;
            int r = scan.nextInt() - 1;
            int v = scan.nextInt();
 
            official_house[b][f][r] += v;
        }

        for(int i = 0; i < 4; i++) {
            for(int j = 0; j < 3; j++) {
                for(int k = 0; k < 10; k++) {
                    System.out.print(" " + official_house[i][j][k]);
                }
                System.out.println("");
            }

            if(i != 3) {
                System.out.println("####################");
            }
        }
    }
}



Measured memory_bytes: 30092
// D - Cake 123
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rp(i,n) for(int i=0;i<(n);++i)

int main(){
	int X,Y,Z,K; cin>>X>>Y>>Z>>K;

	vector<ll> A(X), B(Y), C(Z);
	rp(i,X) cin>>A[i];
	rp(i,Y) cin>>B[i];
	rp(i,Z) cin>>C[i];

	vector<ll> AB;
	for(ll a:A) for(ll b:B) AB.push_back(a + b);
	sort(AB.rbegin(), AB.rend());

	vector<ll> ABC;
	int e = min(K, (int)AB.size());
	for(ll c:C) rp(d,e) ABC.push_back(c + AB[d]);

	sort(ABC.rbegin(), ABC.rend());
	rp(i,K) cout<<ABC[i]<<"\n";
}

Measured memory_bytes: 43112
#include <bits/stdc++.h>
#define REP(i,n) for(ll i = 0; i < (ll)n; i++)
#define FOR(i,a,b) for (ll i=(a);i<(ll)b; i++)
#define ALL(obj) (obj).begin(),(obj).end()
#define INF 1LL << 60
using namespace std;
typedef long long ll;
typedef double db;
typedef string str;
typedef pair<ll,ll> p;
const int MOD = 1000000007;

// vector<p> cut(M);
// cut[i].second
// cut[i].first;
// REP(i,M){
//     int a,b;cin>>a>>b;
//     cut[i] = make_pair(b,a);//last first の順番
// }
// for(int i=0; i<N;i++){
// }
// sort(cut.begin(),cut.end()); //sort
// char '' str ""
int main(void)
{
    int N;cin>>N;
    int ans=0;
    for(int i=0; i<N;i++){
      int r, l; cin>>l>>r;
      ans = ans + r - l +1;
    }
    
    cout<<ans<<endl;

    return 0;
}


Measured memory_bytes: 256
from collections import deque
N = int(input())
A = list(map(int,input().split()))
r = -1
a = 0
b = 0
n = 0
for l in range(N):
    for i in range(r+1,N):
        bb = bin(A[i]).count("1")
        if bin(a+A[i]).count("1")==b+bb:
            a += A[i]
            b += bb
            r = i
            n += r - l + 1
        else:
            break
    a -= A[l]
    b -= bin(A[l]).count("1")
    if r == N-1:
        break
print(n)


Measured memory_bytes: 25096
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ull = unsigned long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using pull = pair<ull, ll>;
#define INF 1000000000
#define LLINF 10000000000000000ll
#define MOD 998244353LL

bool dbgflag = false;


int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  //cout << fixed << setprecision(15);
  
   ll n;
   cin >> n;
   ll all = 0;
   vector<ll> snuke(n);
   for (int i = 0; i < n; i++) {
     cin >> snuke[i];
     all = all ^ snuke[i];
   }

   for (int i = 0; i < n; i++) {
     ll a = snuke[i];
     cout << (all ^ a) << " ";
   }
   cout << endl;
}

Measured memory_bytes: 4748
#include <algorithm>
#include <cassert>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <vector>
#include <cmath>

#include <limits.h>

using namespace std;

typedef long long ll;

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

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

int main(void) {
    double R;
    cin >> R;

    double ans = 2 * R * M_PI;
    printf("%.3f\n", ans);
    return 0;
}


Measured memory_bytes: 3784
#include <vector>
#include <iostream>
#include <utility>
#include <algorithm>
#include <string>
#include <deque>
#include <tuple>
#include <queue>
#include <functional>
#include <cmath>
#include <iomanip>
#include <map>
//cin.sync_with_stdio(false);
//streambuf
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
vector<bool> pf(1000000, true);
vector<int> p;
int main() {
	pf[0] = pf[1] = 0;
	for (int i = 2; i < 1000; i++) {
		if (!pf[i])continue;
		for (int j = i * 2; j < 1000000; j += i) {
			pf[j] = 0;
		}
	}
	//for (int i = 0; i < 1000000; i++) {
	//	if (pf[i])p.push_back(i);
	//}
	int a, b, n;
	while (cin >> a >> b >> n, a) {
		int cnt = 0;
		int i = a;
		for (;; i += b) {
			if (pf[i])cnt++;
			if (cnt == n)break;
		}
		cout << i << endl;
	}
	return 0;
}

Measured memory_bytes: 3184
#include <iostream>
#include <fstream>
#include <sstream>
#include <string>
#include <cstring>
#include <vector>
#include <set>
#include <map>
#include <unordered_map>
#include <queue>
#include <deque>
#include <stack>
#include <algorithm>
#include <bitset>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <numeric>
#include <functional>
#include <cctype>
#include <list>
#include <limits>
#include <cassert>
//#include <boost/multiprecision/cpp_int.hpp>

const double EPS = (1e-10);


using namespace std;
using Int = long long;
//using namespace boost::multiprecision;

const Int MOD = 1000000007;

long long mod_pow(long long x, long long n) {
    long long res = 1;
    for(int i = 0;i < 60; i++){
        if(n >> i & 1) res = res * x % MOD;
        x = x * x % MOD;
    }
    return res;
}

template<typename T>
T gcd(T a, T b) {
    return b != 0 ? gcd(b, a % b) : a;
}

template<typename T>
T lcm(T a, T b) {
    return a * b / gcd(a, b);
}

void fast_input() {
    cin.tie(0);
    ios::sync_with_stdio(false);
}


double solve(int D, int E) {
    double ans = 1000000000;
    for (int x = 0; x <= D; x++) {
        int y = D-x;
        ans = min(ans, abs(sqrt(x*x+y*y) - E));
    }
    return ans;
}

int main(void) {
    int D, E;
    while (1) {
        cin >> D >> E;
        if (!D && !E) break;
        cout << solve(D, E) << endl;
    }
}   



Measured memory_bytes: 3208
n=int(input())
h=[int(i) for i in input().split()]

dp=[0 for i in range(n)]
dp[0]=0
dp[1]=abs(h[1]-h[0])
for i in range(2,n):
    dp[i]=min(dp[i-1]+abs(h[i]-h[i-1]),dp[i-2]+abs(h[i]-h[i-2]))
print(dp[n-1])

Measured memory_bytes: 13928
#include<iostream>
#include<string>
#include<vector>
#include<map>
using namespace std;

int main(){
    int N, M;
    cin >> N;

    map<string, int> blue;
    vector<string> blue_str;
    for(int i=0;i<N;i++){
        string s;
        cin >> s;
        if(blue.count(s) == 0){
            blue.insert(make_pair(s,1));
            blue_str.push_back(s);
        }
        else{
            blue[s]++;
        }
    }

    cin >> M;
    map<string, int> red;
    for(int i=0;i<M;i++){
        string s;
        cin >> s;
        if(red.count(s) == 0){
            red.insert(make_pair(s,1));
        }
        else{
            red[s]++;
        }
    }

    int max_num = -100000;

    for(int i=0;i<blue_str.size();i++){
        int n = blue[blue_str[i]]-red[blue_str[i]];
        if(n>max_num){
            max_num = n;
        }
    }

    cout << max(max_num, 0) << endl;
    return 0;
}


Measured memory_bytes: 256
/* BISMILLAHIR RAHMANIR RAHIM */
#include<bits/stdc++.h>
using namespace std;
#define ll       long long
#define ull       unsigned long long
#define  sci(x)   scanf("%d", &x)
#define  scl(x)   scanf("%lld", &x)
#define  scd(x)   scanf("%lf", &x)
#define l0(i,n)   for(ll i=0; i<n; i++)
#define MAX                 100000
#define maxn 200002
#define pb push_back
#define mk make_pair


int main ()
{
		ios::sync_with_stdio(0);
		cin.tie(0);
		//CODE TONOY
		char a;
		cin >> a;
		if (isupper(a)) cout << 'A' << endl;
		else cout << 'a' << endl;
		return 0;
}


Measured memory_bytes: 3644
#include <bits/stdc++.h>
#define int long long
#define uint unsigned int
#define REP(i, n) for (int i = 0; i < (n); ++i)
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define FORR(i, a, b) for (int i = (a); i >= (b); --i)
#define ALL(a) (a).begin(), (a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define SZ(a) ((int)(a).size())
#define PB(a) push_back(a)
#define EB(...) emplace_back(__VA_ARGS__)
#define MP(a, b) make_pair(a, b)
#define MT(...) make_tuple(__VA_ARGS__)
#define BIT(n) (1LL << (n))
using namespace std;
using pii = pair<int, int>;
template <class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
template <class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
const int MOD = 1000000007;
const int INF = 1LL << 30;
const double EPS = 1e-10;

int N;
int a[16][16];
int dp[BIT(16)];
int S[BIT(16)];

signed main() {
  cin.tie(0);
  ios_base::sync_with_stdio(false);
  cout << fixed << setprecision(10);
  
  cin >> N;
  REP(i, N) REP(j, N) cin >> a[i][j];
  REP(ms, BIT(N)) {
    int sum = 0;
    REP(i, N) if (ms & BIT(i)) {
      FOR(j, i+1, N) if (ms & BIT(j)) {
        sum += a[i][j];
      }
    }
    S[ms] = sum;
  }
  REP(ms, BIT(N)) {
    dp[ms] = S[ms];
    int sub = ms;
    do {
      chmax(dp[ms], dp[sub]+dp[ms-sub]);
      sub = (sub-1)&ms;
    } while (sub != ms);
  }
  cout << dp[BIT(N)-1] << endl;

  return 0;
}

Measured memory_bytes: 1408
import math

n = int(input())
numbers = [int(input()) for i in range(n)]

def isPrime(x):
    if x == 2:
        return True
    if x < 2 or x % 2 == 0:
        return False
    i = 3
    while i <= math.sqrt(x):
        if x % i == 0:
            return False
        i += 2
    
    return True

c =  0
for i in range(n):
    if isPrime(numbers[i]):
        c += 1

print(c)



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

int main(void){
  int n;
  cin >> n;
  if(n >= 64) cout << 64 << endl;
  else if(n >= 32) cout << 32 << endl;
  else if(n >= 16) cout << 16 << endl;
  else if(n >= 8) cout << 8 << endl;
  else if(n >= 4) cout << 4 << endl;
  else if(n >= 2) cout << 2 << endl;
  else cout << 1 << endl;
  return 0;
}


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

#define ALL(a) (a).begin(), (a).end()
#define llong long long

using namespace std;

signed main(){
	const llong INF = 100000000;
	llong n; cin >> n;
	vector<llong> h(n+1);
	for(int i = 1; i <= n; i++)cin >> h[i];
	h[0] = INF;
	vector<llong> dp(n+1,INF);
	dp[1] = 0;
	for(int i = 2; i <= n; i++){
		dp[i] = min(dp[i-2]+abs(h[i]-h[i-2]),dp[i-1]+abs(h[i]-h[i-1]));
	}
	cout << dp[n] << endl;

	return 0;
}



Measured memory_bytes: 1792
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <string>
#include <map>
#include <set>
#include <algorithm>
using namespace std;
typedef long long LL;

const int MaxN = 100000;
int n;
int a[MaxN + 5];

int main()
{
	while (~scanf("%d", &n)) {
		int odd = 0, even = 0, Reven = 0;
		for (int i = 1; i <= n; i++) {
			scanf("%d", &a[i]);	
			if (a[i] & 1) odd++;
			int x = a[i], d2 = 0;
			while (x % 2 == 0) d2++, x /= 2;
			if (d2 == 1) even++;
			else if (d2 > 1) Reven++;
		}
		if (even == 0) {
			if (Reven >= odd - 1) printf("Yes\n");
			else printf("No\n");
		}
		else {
			if (Reven >= odd) printf("Yes\n");
			else printf("No\n");
		}
	}
	return 0;
}

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

fn read1<T: std::str::FromStr>() -> T {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim().parse().ok().unwrap()
}

pub fn readn<T: std::str::FromStr>(delimiter: &str) -> Vec<T> {
    let s = read1::<String>();
    s.split(delimiter).map(|e| e.parse().ok().unwrap()).collect::<Vec<T>>()
}

fn main() {
    let n = read1::<usize>();
    let mut dict = HashSet::new();
    let mut flg = true;
    let mut back = '*';

    for _ in 0..n {
        let w = read1::<String>();
        let ws = (&w).to_string();

        if dict.contains(&w) {
            flg = false;
            break;
        } else {
            dict.insert(ws);
            let c = w.chars().collect::<Vec<char>>();
            if back != '*' && c[0] != back {
                flg = false;
                break;
            } else {
                back = c[c.len()-1];
            }
        }
    }

    if flg {
        println!("Yes");
    } else {
        println!("No");
    }
}

Measured memory_bytes: 4352
object Main {

  class UnionFind(val n: Int) {
    private[this] val par = Array.range(0, n)

    def root(x: Int): Int = if(par(x) == x) x else root(par(x))

    def same(x: Int, y: Int): Boolean = root(x) == root(y)

    def unite(x: Int, y: Int): Unit = par(root(x)) = root(y)
  }

  def main(args: Array[String]): Unit = {
    val Array(n,q,_*) = scala.io.StdIn.readLine.split(" ").map(_.toInt)
    val uf = new UnionFind(n)

    for(i <- 1 to q){
      val Array(com,x,y,_*) = scala.io.StdIn.readLine.split(" ").map(_.toInt)
      if(com==0)uf.unite(x,y)
      else println(if(uf.same(x,y)) 1 else 0)
    }
  }
}

Measured memory_bytes: 149176
z[9999],a,b,c;f(x,y){fflush(!printf("? %d %d\n",x,y));scanf("%s",&b);b=b>78;}main(i){if(scanf("%d%d",&a,&b),a<=b){puts("Impossible");return;}for(i=a+=b;~--i;)!c||f(i,z[c-1])?z[c++]=i:c--;for(c=*z,i=a;~--i;)z[i]=f(c,i);for(printf("! "),i=0;i<a;)printf("%d",z[i++]);}

Measured memory_bytes: 720
#include<bits/stdc++.h>
#include <math.h>
#include<iostream>
#include <string>
using namespace std;
typedef long long ll;
#define pb pushback
#define fr(i,n) for(int i=0;i<n;i++)
#define ifr(i,n) for(int i=n-1;i>=0;i--)


int main() {
    int a[3];
	cin >> a[0]>> a[1]>> a[2];
    sort(a,a+3);
      cout << a[0]+a[1] << endl;
}

Measured memory_bytes: 256
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cstring>

#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <unordered_map>
#include <unordered_set>

#include <complex>

#include <functional>
#include <cassert>

typedef long long ll;
using namespace std;

#define debug(x) cerr << #x << " = " << (x) << endl;


#define mod 1000000007 //1e9+7(prime number)
#define INF 1000000000 //1e9
#define LLINF 2000000000000000000LL //2e18
#define SIZE 200010

int n, m, S, T, U, V;
int a[SIZE], b[SIZE], c[SIZE];

vector<pair<int, int> > G[SIZE];
vector<pair<int, int> > G2[SIZE];
vector<pair<int, int> > G2r[SIZE];

void dijkstra(vector<pair<int,int> > *G, int q, int *start, ll *res){
  priority_queue<pair<pair<ll,int>,int> > pq;
  bool visited[3][SIZE] = {};
  
  for(int i=0;i<q;i++){
    pq.push({{0, start[i]},0});
  }

  while(pq.size()){
    auto p = pq.top();
    pq.pop();

    int now = p.first.second;
    ll cost = p.first.first;
    int f = p.second;
    
    if(visited[f][now]) continue;
    if(!visited[0][now] && !visited[1][now] && !visited[2][now])
      res[now] = -cost;

    visited[f][now] = true;

    for(int i=0;i<G[now].size();i++){
      if(G[now][i].first == -1){
        if(f == 0 || f == 1)
          pq.push({{cost, G[now][i].second},1});
      }else{
        if(f == 0)
          pq.push({{cost - c[G[now][i].first], G[now][i].second},0});
        else
          pq.push({{cost - c[G[now][i].first], G[now][i].second},2});
      }
    }
  }
  
}

int main(){
  ll res1[SIZE], res2[SIZE];
  int start[SIZE];
  scanf("%d%d%d%d%d%d",&n,&m,&S,&T,&U,&V);
  S--; T--; U--; V--;

  for(int i=0;i<m;i++){
    scanf("%d%d%d",a+i, b+i, c+i);
    a[i]--; b[i]--;

    G[a[i]].push_back({i, b[i]});
    G[b[i]].push_back({i, a[i]});
  }

  start[0] = S;
  for(int i=0;i<n;i++) res1[i] = -1;
  dijkstra(G, 1, start, res1);
  
  queue<int> que;
  bool visited[SIZE] = {};
  que.push(T);

  for(int i=0;i<n;i++) G2r[i] = G[i];
  for(int i=0;i<n;i++) G2[i] = G[i];
  
  while(que.size()){
    int p = que.front();
    que.pop();

    if(visited[p]) continue;
    visited[p] = true;
    
    for(int i=0;i<G[p].size();i++){
      if(res1[p] - c[G[p][i].first] == res1[G[p][i].second]){
        que.push(G[p][i].second);
        G2r[p].push_back({-1, G[p][i].second});
        G2[G[p][i].second].push_back({-1, p});
      }
    }
  }

  start[0] = V;
  for(int i=0;i<n;i++) res1[i] = -1;
  for(int i=0;i<n;i++) res2[i] = -1;
  dijkstra(G2, 1, start, res1);
  dijkstra(G2r, 1, start, res2);

  cout << min(res1[U], res2[U]) << endl;
  
  return 0;
}



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

using namespace std;

typedef long long LL;
typedef pair<int , int> P2;
typedef pair<pair<int , int> , int> P3;
typedef pair<pair<int , int> , pair<int , int> > P4;
#define PB(a) push_back(a)
#define MP(a , b) make_pair((a) , (b))
#define M3P(a , b , c) make_pair(make_pair((a) , (b)) , (c))
#define M4P(a , b , c , d) make_pair(make_pair((a) , (b)) , make_pair((c) , (d)))
#define repp(i,a,b) for(int i = (int)(a) ; i < (int)(b) ; ++i)
#define repm(i,a,b) for(int i = (int)(a) ; i > (int)(b) ; --i)

int main(){
	int N; cin >> N;
	vector<double> dp(N+1,0.0);
	dp[0] = 1.0;
	repp(i,0,N){
		double p; cin >> p;
		vector<double> nx(N+1,0.0);
		repp(j,0,i+1){
			nx[j] += dp[j]*(1-p);
			nx[j+1] += dp[j]*p;
		}
		swap(dp,nx);
	}
	double ans = 0.0;
	repp(i,(N+1)/2,N+1) ans += dp[i];
	printf("%.12f\n",ans);
	return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;
 
public class Main {
 
 
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int a = Integer.parseInt(sc.next()) -1;
		int b = Integer.parseInt(sc.next());
		int total = 1;
		int cnt = 0;
 
		while (total < b) {
			total += a;
			cnt++;
		}
 
		System.out.println(cnt);
	}
}

Measured memory_bytes: 23764
#include<iostream>
#include<algorithm>
#include<vector>
#include<iomanip>
#include<cmath>
#include<map>

using namespace std;

#define rep(i,N) for(int i=0;i<N;i++) //0から


typedef long long ll;




ll binary_search(vector<ll> a, ll n, ll key){
    ll right = n, left = -1;
    ll md = (right + left) / 2;

    while(right - left > 1){
        if(a[md] <= key){
            right = md;
        }else{
            left = md;
        }
        md = (right + left) / 2;
    }
    if(left == -1) return -1; //無い場合
    return right;
}

vector<ll> prime;
void Prime(ll n){ //線形篩,素数列挙
    vector<ll> p(n,0);
    p[0]=1;
    p[1]=1;
    for(ll i=2;i<n;i++){
        if(p[i]==0){
            prime.push_back(i);
            p[i]=i;
        }
        ll k=prime.size();
        for(ll j=0;j<k && i*prime[j]<n && prime[j]<=p[i];j++){
            p[i*prime[j]]=prime[j];
        }
    }
}

ll gcd(ll a,ll b){
    if(a<b){
        swap(a,b);
    }
    //a>=b
    ll r=a%b;
    while(r!=0){
        a=b;
        b=r;
        r=a%b;
    }
    return b;
}

#define MOD ((ll)1e+9 + 7)




//cout<<fixed<<setprecision(10);
int main(){
    ll a,b,c,d;
    cin>>a>>b>>c>>d;
    a--;
    ll g=(c*d)/gcd(c,d); //c,dの最小公倍数
    ll ans=b -(b/c +b/d -b/g) -a +(a/c +a/d -a/g);
    cout<<ans<<endl;


    return 0;
}



Measured memory_bytes: 3600
#include <bits/stdc++.h>
#define int long long
using namespace std;

struct edge{ int to,num; };

int n,vs[100010],ans[100010],s[100010];
vector<edge> G[100010];

void dfs(int v,int par){
	int sum = 1;
	for(edge e : G[v]){
		if(e.to != par){
			dfs(e.to,v);
			sum += vs[e.to];
			if(n - vs[e.to] * 2 == 0) ans[e.num] = 0;
			else ans[e.num] = abs((s[v] - s[e.to]) / (n - vs[e.to] * 2));
		}
	}
	vs[v] = sum;
}

int dfs2(int v,int par){
	int sum = 0;
	vs[v] = 1;
	for(edge e : G[v]){
		if(e.to != par){
			sum += dfs2(e.to,v) + ans[e.num] * vs[e.to];
			vs[v] += vs[e.to];
		}
	}
	return sum;
}

signed main(){
	int a[100010],b[100010];
	cin >> n;
	for(int i = 0;i < n - 1;i++){
		cin >> a[i] >> b[i]; a[i]--;b[i]--;
		G[a[i]].push_back({b[i],i});
		G[b[i]].push_back({a[i],i});
	}
	for(int i = 0;i < n;i++) cin >> s[i];
	dfs(0,-1);
	for(int i = 0;i < n - 1;i++){
		if(ans[i]) cout << ans[i] << endl;
		else cout << (s[a[i]] - dfs2(a[i],-1)) / vs[b[i]] << endl;
	}
	return 0;
}

Measured memory_bytes: 19584