akhauriyash/Code-Regression huggingface dataset:
/**
 * code generated by JHelper
 * More info: https://github.com/AlexeyDmitriev/JHelper
 * @author yosiiii
 */


#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(long long int i=0;i<(n);++i)
typedef long long int ll;

class DLunlunNumber {
public:
	void solve(std::istream& in, std::ostream& out) {
        int k;
        in >> k;
        if(k<10){
            out << k << endl;
            return ;
        }
        deque<ll> q;
        rep(i,9){
            q.push_back(i+1);
        }
        for(int i=1;i<k;i++){
            ll t = q.front();
            q.pop_front();
            if(t%10!=0){
                q.push_back(10*t+t%10-1);
            }
            q.push_back(10*t+t%10);
            if(t%10!=9){
                q.push_back(10*t+t%10+1);
            }
        }

        out << q.front() << endl;
	}
};


int main() {
	DLunlunNumber solver;
	std::istream& in(std::cin);
	std::ostream& out(std::cout);
	solver.solve(in, out);
	return 0;
}


Measured memory_bytes: 1792
//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define INF 0x6fffffff
#define INFL 0x6fffffffffffffffLL

int main() {
	ll		a,b,c,i,j,k,n,h,m,x,y;
	string	s;
	cin >> a >> b >> h >> m;
	double hh,mm,deg,ans;

	hh = double(h*60+m) / 2.0;
	mm = m*6;

	deg = abs(hh-mm);
	if (deg > 180) deg = 360 - deg;
	//printf("%f\n",deg);

	deg = deg * ((double)M_PI/180.0);
	//printf("%f\n",deg);
	ans = sqrt( a*a + b*b - 2.0*a*b*cos(deg));

	//vector<ll>	aa(n);
	//for(i=0;i<n;i++) cin >> aa[i];
	//vector<ll>	dp(n+1,INFL);
	//vector<vector<ll>>	dp2(x , vector<ll>(y,INFL));
	printf("%.10f\n",ans);
	//cout << ans << endl;
	return 0;
}


Measured memory_bytes: 4156
#include<stdio.h>
#include<stdlib.h>
int main()
{
	int a;
	int *b;
	int c=0,d=0,i;
	scanf("%d",&a);
	b=(int *)malloc(a * sizeof(int));
	for(i=0;i<a;i++) scanf("%d",&b[i]);
	for(i=0;i<a-1;i++){
		if(b[i]>=b[i+1]){
			c++;
			//printf("W%dW",i);
		}
		else{
			if(d<c) d=c;
			c=0;
		}
	}
	if(d<c) d=c;
	printf("%d\n",d);
}

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

using namespace std;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n;
  cin >> n;
  vector<int> a(n);
  for (int i = 0; i < n; i++) {
    cin >> a[i];
  }
  int low = 0, high = n;
  while (high - low > 1) {
    int mid = (low + high) / 2;
    bool can = true;
    vector<pair<int, int>> st;
    st.emplace_back(a[0], 0);
    for (int i = 1; i < n; i++) {
      int diff = a[i] - a[i - 1];
      if (diff > 0) {
        st.emplace_back(diff, 0);
        continue;
      }
      while (diff < 0) {
        assert(!st.empty());
        int take = min(-diff, st.back().first);
        diff += take;
        st.back().first -= take;
        if (st.back().first == 0) {
          st.pop_back();
        }
      }
      int del = 0;
      while (!st.empty()) {
        if (st.back().second + 1 < mid) {
          int cc = st.back().second;
          st.back().first -= 1;
          if (st.back().first == 0) {
            st.pop_back();
          }
          st.emplace_back(1, cc + 1);
          break;
        }
        del += st.back().first;
        st.pop_back();
      }
      if (st.empty()) {
        can = false;
        break;
      }
      if (del > 0) {
        st.emplace_back(del, 0);
      }
    }
    (can ? high : low) = mid;
  }
  cout << high << '\n';
  return 0; // :)
}


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

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

using namespace std;

struct UnionFind{
  vector<int> par,num;

  UnionFind(int N) : par(N),num(N){
    for(int i=0;i<N;i++){
      par[i] = i;
      num[i] = 1;
    }
  }

  int root(int x){
    if(par[x] == x) return x;
    return par[x] = root(par[x]);
  }

  void unite(int x, int y){
    int rx = root(x);
    int ry = root(y);
    if(rx == ry) return;
    par[rx] = ry;
    num[ry] = num[ry]+num[rx]; 
  }

  int get_num(int x){
    int rx = root(x);
    return num[rx];
  }

  bool same(int x, int y){
    int rx = root(x);
    int ry = root(y);
    return rx == ry;
  }
};


int main(void){
  int a,b,c,d;
  cin >> a >> b >> c >> d;
  if((a+d-1)/d >= (c+b-1)/b){
    cout << "Yes" << endl;
  }
  else cout << "No" << endl;
  return 0;
}


Measured memory_bytes: 3636
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <string>
#include <sstream>
#include <complex>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
#include <iterator>
#include <numeric>
#include <bitset>
#include <cassert>
#include <functional>

using namespace std;
using Graph = vector<vector<int>>;
typedef long long ll;
typedef pair<ll, ll> P;
inline ll min(ll x, ll y) { return x < y ? x : y; }
inline ll max(ll x, ll y) { return x > y ? x : y; }

#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define rep1(i,n) for(int i=1;i<(int)(n);i++)
#define all(c) c.begin(),c.end()
#define pb push_back
#define fs first
#define sc second
#define show(x) cout << #x << " = " << (x) << endl
#define chmin(x,y) x=min(x,y)
#define chmax(x,y) x=max(x,y)

int main() {
	int N, L;
	cin >> N >> L;
	vector<string> S(N);
	rep(i, N) {
		cin >> S[i];
	}

	sort(all(S));
	string ans;
	rep(i, N) {
		ans += S[i];
	}
	cout << ans;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using Graph = vector<vector<int>>;
const int INF = 1e9 + 1;
const ll LLINF = 1e18;
const int MOD = 1e9 + 7;

int main() {
    int X;
    cin >> X;
    static bool isprime[100010];
    for (int i = 0; i < 100010; ++i)
        isprime[i] = true;
    isprime[0] = isprime[1] = false;
    for (int i = 2; i * i < 100010; ++i) {
        if (isprime[i])
            for (int j = 2; i * j < 100010; ++j)
                isprime[i * j] = false;
    }
    for (int i = X; i < 100010; ++i) {
        if (isprime[i]) {
            cout << i << endl;
            break;
        }
    }
    return 0;
}


Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll INF = 1e18;
const int inf = 1e9;
#define rep(i, a, b) for (int i = a; i < b; i++)
#define per(i, b, a) for (int i = a - 1; i >= b; i--)
using Graph = vector<vector<int>>;
using pint = pair<int, int>;
int dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};
int dxx[8] = {1, 1, 1, 0, 0, -1, -1, -1}, dyy[8] = {-1, 0, 1, -1, 1, -1, 0, 1};

struct T {
    int y1, x1, y2, x2;
};

int main() {
    int h, w;
    cin >> h >> w;
    int grid[h][w];
    rep (i, 0, h) rep (j, 0, w) cin >> grid[i][j];
    vector<T> vec;
    rep (i, 0, h) {
        rep (j, 0, w) {
            if (grid[i][j] % 2 == 1) {
                if (j != w - 1) {
                    grid[i][j]--;
                    grid[i][j + 1]++;
                    vec.push_back ({i + 1, j + 1, i + 1, j + 2});
                } else {
                    if (i == h - 1) continue;
                    else {
                        grid[i][j]--;
                        grid[i + 1][j]++;
                        vec.push_back ({i + 1, j + 1, i + 2, j + 1});
                    }
                }
            }
        }
    }
    cout << vec.size() << "\n";
    for (auto p : vec) {
        cout << p.y1 << " " << p.x1 << " " << p.y2 << " " << p.x2 << "\n";
    }
}

Measured memory_bytes: 5104
N = int(input())
As = list(map(int, input().split()))

As.sort(reverse=True)
rlt = As[0]

if N == 2:
  print(rlt)
  exit()

n = N // 2
if N % 2 == 1:
  for i in range(1,n):
    rlt += 2*As[i]
  rlt += As[n]
else:
  for i in range(1,n):
    rlt += 2*As[i]
  
print(rlt)

Measured memory_bytes: 105040
import std.stdio;
import std.string;
import std.conv;

void main(){
    int n;
    while(true){
        int allLunch, allDinner, allMidnight;
        int lunch, dinner, midnight;
        n = readln().chomp().to!int();
        if(n == 0){
            break;
        }
        foreach(i; 0..n){
            auto input = readln().chomp().split(":");
            int h = input[0].to!int();
            if(h < 11){
                h += 24;
            }
            input = input[1].split();
            int m = input[0].to!int();
            int m2 = input[1].to!int();
            int diff = m < m2 ? m2 - m : 60 - m + m2;

            if(11 <= h && h <= 14){
                ++allLunch;
                if(diff <= 8){
                    ++lunch;
                }
            }else if(18 <= h && h <= 20){
                ++allDinner;
                if(diff <= 8){
                    ++dinner;
                }
            }else if(21 <= h && h <= 25){
                ++allMidnight;
                if(diff <= 8){
                    ++midnight;
                }
            }
        }
        if(allLunch){
            writeln("lunch ", 100 * lunch / allLunch);
        }else{
            writeln("lunch no guest");
        }
        if(allDinner){
            writeln("dinner ", 100 * dinner  / allDinner);
        }else{
            writeln("dinner no guest");
        }
        if(allMidnight){
            writeln("midnight ", 100 * midnight / allMidnight);
        }else{
            writeln("midnight no guest");
        }
    }
}

Measured memory_bytes: 1020
# Flog 1

N = int(input())
h_list = list(map(int, input().split()))

cost_list = [0 for i in range(N+1)]

# ステップiへたどり着くためのコスト最小値
for i in range(1,N):
    if i==1:
        cost_list[i+1] = abs(h_list[i] - h_list[i-1])
        continue

    step_1 = cost_list[i] + abs(h_list[i]-h_list[i-1])
    step_2 = cost_list[i-1] + abs(h_list[i]-h_list[i-2])
    min_cost = min(step_1, step_2)
    cost_list[i+1] = min_cost


print(cost_list[N])


Measured memory_bytes: 52728
// This amazing code is by Eric Sunli Chen.
#include <algorithm>
#include <bitset>
#include <cmath>
#include <cstring>
#include <cstdio>
#include <cstdlib>
#include <ctime>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <utility>
#include <vector>
using namespace std;
template<typename T> void get_int(T &x)
{
	char t=getchar();
	bool neg=false;
	x=0;
	for(; (t>'9'||t<'0')&&t!='-'; t=getchar());
	if(t=='-')neg=true,t=getchar();
	for(; t<='9'&&t>='0'; t=getchar())x=x*10+t-'0';
	if(neg)x=-x;
}
template<typename T> void print_int(T x)
{
	if(x<0)putchar('-'),x=-x;
	short a[20]= {},sz=0;
	while(x>0)a[sz++]=x%10,x/=10;
	if(sz==0)putchar('0');
	for(int i=sz-1; i>=0; i--)putchar('0'+a[i]);
}
#define ff first
#define ss second
#define pb push_back
#define mp make_pair
#define get1(a) get_int(a)
#define get2(a,b) get1(a),get1(b)
#define get3(a,b,c) get1(a),get2(b,c)
#define printendl(a) print_int(a),puts("")
typedef long long LL;
typedef unsigned long long uLL;
typedef pair<int,int> pii;
const int inf=0x3f3f3f3f;
const LL Linf=1ll<<61;
const double pi=acos(-1.0);

int n,x[100111],l,q,nxt[20][100111];
int main()
{
	get1(n);
	for(int i=1;i<=n;i++)get1(x[i]);
	get2(l,q);
	for(int i=1;i<=n;i++)nxt[0][i]=upper_bound(x+1,x+n+1,x[i]+l)-x-1;
	nxt[0][n+1]=n+1;
//	for(int i=1;i<=n;i++)printf("i= %d nxt= %d\n",i,nxt[0][i]);
	for(int i=1;i<20;i++)for(int j=1;j<=n+1;j++)nxt[i][j]=nxt[i-1][nxt[i-1][j]];
	for(int i=1,a,b;i<=q;i++)
	{
		get2(a,b);
		if(a>b)swap(a,b);
		int ans=0,cur=a;
		for(int j=19;j>=0;j--)if(nxt[j][cur]<b)
		{
			cur=nxt[j][cur];
			ans+=1<<j;
		}
		printendl(ans+1);
	}
	return 0;
}

Measured memory_bytes: 9088
n,a,b = map(int,input().split())

x = list(map(int,input().split()))

diff_x = []

for i in range(1,n):
    diff_x.append((x[i]-x[i-1])*a)

for i in range(n-1):
    if diff_x[i] > b:
        diff_x[i] = b

print(sum(diff_x))
        

Measured memory_bytes: 63468
n=int(input())
a=list(map(int,input().split()))
j=0
x=0
ans=0
for i in range(n):
  while j<n and x|a[j]==x+a[j]:
    x|=a[j]
    j+=1
  ans+=j-i
  x^=a[i]
print(ans)

Measured memory_bytes: 24424
#include <bits/stdc++.h>
#define int long long
#define double long double
#define endl "\n"
#define fastio ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define pb push_back
#define mp make_pair
#define ms(v,x) memset(v,x,sizeof(v))
#define pii pair<int,int>
#define ff first
#define ss second
#define frr(i,n) for(int i=0;i<n;i++)
#define rep(i,j,k) for(int i=j;i<k;i++)
#define td(v) v.begin(),v.end()
#define inf 1000000000 // 1e9
#define M   1000000007 // 1e9 + 7
using namespace std;
inline int mod(int n, int m){ int ret = n%m; if(ret < 0) ret += m; return ret; }
int gcd(int a, int b){return (b == 0 ? a : gcd(b, a%b));}
int lcm(int a,int b){return (a*b)/gcd(a,b);}
int exp(int a,int b,int m){
    if(b==0) return 1LL;
    if(b==1) return mod(a,m);
    int k = mod(exp(a,b/2,m),m);
    if(b&1){
        return mod(a*mod(k*k,m),m);
    }
    else return mod(k*k,m);
}
double d(pii a,pii b){
    return sqrt((a.ff - b.ff) * (a.ff - b.ff) + (a.ss - b.ss) * (a.ss - b.ss));
}
main(){
    fastio;
    int n;
    cin >> n;
    vector<int> a(n);
    for(int i=0;i<n;i++) a[i] = i;
    vector<pii> v(n);
    for(pii &x : v) cin >> x.ff >> x.ss;
    double dist = 0;
    double c = 0;
    do{
        for(int i=0;i<n-1;i++)
            dist += d(v[a[i]],v[a[i+1]]);
        c++;
    }   while(next_permutation(td(a)));
    cout << fixed << setprecision(12) << dist / c << endl;
}

Measured memory_bytes: 256
n=gets.to_i
h=Hash.new(0)
n.times do |i|
    s=gets.chomp
    h[:"#{s}"]+=1
end

h=h.sort
max=h.max_by{|x| x[1]}[1]
h.each do |h|
    if h[1]==max
        puts h[0]
    end
end


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

int main() {
    string b;
    cin >> b;
    if(b == "A"){
        cout <<"T";
    }
    if(b == "C"){
        cout <<"G";
    }
    if(b == "T"){
        cout <<"A";
    }
    if(b == "G"){
        cout <<"C";
    }

}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main(){
 char c;
 cin >> c;
 if (c== 'a'){
 cout << "vowel" << endl;
 }
 else if (c== 'i'){
 cout << "vowel" << endl;
 }
 else if (c== 'u'){
 cout << "vowel" << endl;
 }
 else if (c== 'e'){
 cout << "vowel" << endl;
 }
 else if (c=='o'){
 cout << "vowel" << endl;
 }
 else{
 cout << "consonant" << endl;
 }
}

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

int main()
{
    int H, W, N;
    while(cin >> H >> W >> N, H || W || N) {
    int dp[1005][1005] = {};
    int mas[1005][1005];
    dp[0][0] = N - 1;
    for(int i = 0; i < H; i++) {
        for(int j = 0; j < W; j++) {
            cin >> mas[i][j];
            if(dp[i][j] % 2 == 0) {
                dp[i + 1][j] += dp[i][j] / 2;
                dp[i][j + 1] += dp[i][j] / 2;
            } else {
                dp[i + 1][j] += dp[i][j] / 2 + 1 - mas[i][j];
                dp[i][j + 1] += dp[i][j] / 2 + mas[i][j];
            }
            (mas[i][j] += dp[i][j] % 2) %= 2;
        }
    }
    int x = 0, y = 0;
    while(x < W && y < H) {
        if(mas[y][x] == 0) y++;
        else x++;
    }
    cout << y + 1 << " " << x + 1 << endl;
    }
    return (0);
}



Measured memory_bytes: 10956
# 解説AC
# (a,b)をベクトルと考え、内積0→直行するものをとってくる。
# 全ての候補をa>0(or a=0)となるように考えて記録する。
# 第一象限に有るものを候補に考えて、それの対として第四象限にあるものを取ってくる。
# (a,b) s個、(b,-a)t個のとき、少なくとも1つ選ぶもの同士を掛け算して全体から余事象をとる
# 　2^(s+t)-(2^s-1)*(2^t-1)
# 全部選ばないやつは最後に1引いて調整
# zero,zeroのものはそれ自体の集合から1つ選ぶしかないのでzerocnt個足す

from math import gcd
from collections import defaultdict
import sys

input = sys.stdin.buffer.readline

mod = 10 ** 9 + 7
n = int(input())
cnt = 0
cnt += n
cnt10 = 0
cnt01 = 0
zerocnt = 0
kumi = defaultdict(int)
for i in range(n):
    a, b = map(int, input().split())
    if a == 0 and b == 0:
        zerocnt += 1
        continue
    elif b == 0:
        cnt10 += 1
        continue
    elif a == 0:
        cnt01 += 1
        continue
    g = gcd(a, b)
    a //= g
    b //= g
    if a < 0:
        a *= -1
        b *= -1
    kumi[(a, b)] += 1
    kumi[(b, -a)] += 0
ans = 1
cnt -= zerocnt
ans *= pow(2, cnt10 + cnt01, mod) - (pow(2, cnt10, mod) - 1) * (pow(2, cnt01, mod) - 1)
ans %= mod
cnt -= cnt10 + cnt01
for a, b in kumi.keys():
    if b <= 0:
        continue
    s = kumi[(a, b)]
    t = kumi[(b, -a)]
    ans *= pow(2, (s + t), mod) - (pow(2, s, mod) - 1) * (pow(2, t, mod) - 1)
    ans %= mod
    cnt -= s + t
if cnt > 0:
    ans *= pow(2, cnt, mod)
    ans %= mod
print((ans - 1 + zerocnt) % mod)


Measured memory_bytes: 81804
N, Y = map(int, input().split())                      
for i in range(N+1):                                  
    for j in range(N+1-i):                            
        k = N-i-j                                     
        if Y - (i * 10000 + j * 5000 + k * 1000) == 0:
            print(i, j, k)                            
            exit()                                    
print(-1, -1, -1)                                     

Measured memory_bytes: 3060
#include <iostream>
#include <vector>
#include <string>
#include <set>
using namespace std;
int main(){
    int num;
    string b;
    cin>>num;
    set<string>a;
        for (int i=0;i<num;i++){
            cin>>b;
            a.insert(b);
        }
    cout<<a.size();
    return 0;
}


Measured memory_bytes: 19120
n,k=gets.split.map(&:to_i)
a=gets.split.map(&:to_i)
sum=a.inject(0){|s,i| s+=i}
require 'prime'
def divisors(n)
  n.prime_division.inject([1]) do |ary, (p, e)|
    (0..e).map{ |e1| p ** e1 }.product(ary).map{ |a, b| a * b }
  end.sort
end

divs = divisors(sum).reverse

divs.each do |i|
  b=a.map{|j| j%i}.sort
  mae=b.shift
  ushiro=i-b.pop
  until(b.empty?)
    if mae >= ushiro
      ushiro+=i-b.pop
    else
      mae+=b.shift
    end
  end
  if mae <= k
    puts i
    exit
  end
end
puts 1


Measured memory_bytes: 11256
module Vector =
  struct
    type t = { x: float; y:float }
    let eps = 1e-10
    let set x y = {x = x; y = y}
    let add v1 v2 = {x = v1.x +. v2.x; y = v1.y +. v2.y}
    let sub v1 v2 = {x = v1.x -. v2.x; y = v1.y -. v2.y}
    let mul v a = {x = v.x *. a; y = v.y *. a}
    let div v a = {x = v.x /. a; y = v.y /. a}
    let norm v = v.x *. v.x +. v.y *. v.y
    let abs v = sqrt (norm v)
    let dot v1 v2 = v1.x *. v2.x +. v1.y *. v2.y
    let cross v1 v2 = v1.x *. v2.y -. v1.y *. v2.x
  end

let fabs a = if a > 0.0 then a else a *. (-1.0)

let _ =
  let is_parallel v1 v2 = fabs (Vector.cross v1 v2) < Vector.eps in
  let n = Scanf.scanf "%d\n" (fun x -> x) in
  for i = 1 to n do
    let v1, v2 = Scanf.scanf "%f %f %f %f %f %f %f %f\n" (fun x1 y1 x2 y2 x3 y3 x4 y4 -> (Vector.sub (Vector.set x2 y2) (Vector.set x1 y1), Vector.sub (Vector.set x4 y4) (Vector.set x3 y3))) in
    print_endline @@ if is_parallel v1 v2 then "YES" else "NO"
  done

Measured memory_bytes: 2372
#include <iostream>
#include <cstdio>
#include <cstring>
#include <vector>
#include <queue>
#include <array>
#include <set>
#include <unordered_set>
#include <unordered_map>
#include <cmath>
#include <algorithm>
#include <numeric>
#include <cassert>
#include <utility>
#include <functional>

using namespace std;
using lli = long long int;

int main() {

    int r, D, x2000;
    cin >> r >> D >> x2000;

    int x = x2000;
    for (int i = 0; i < 10; ++i) {
        int xi = r * x - D;
        cout << xi << endl;
        x = xi;
    }
}

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

using Int = long long;
using ll = long long;

template<typename T1,typename T2> inline void chmin(T1 &a,T2 b){if(a>b) a=b;};
template<typename T1,typename T2> inline void chmax(T1 &a,T2 b){if(a<b) a=b;};

template<typename T> void drop(T x){cout<<x<<endl;exit(0);}


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

  Int n,q,l,r;
  cin>>n>>q>>l>>r;
  vector<Int> as(n);
  for(Int i=0;i<n;i++) cin>>as[i];

  vector<Int> qs(q),xs(q),ss(q),ts(q);
  for(Int i=0;i<q;i++) cin>>qs[i]>>xs[i]>>ss[i]>>ts[i];

  sort(as.begin(),as.end());

  // number of elements whose value is no more than d
  auto calc=
    [&](Int d)->Int{
      auto check=
        [&](Int a)->Int{
          for(Int i=0;i<q;i++){
            if(qs[i]==1){
              if(a>=xs[i]) a=ts[i]*(a+ss[i]);
            }else{
              if(a<=xs[i]) a=(a-ss[i])/ts[i];
            }
          }
          return a<=d;
        };
      Int L=-1,R=n;
      while(L+1<R){
        Int M=(L+R)>>1;
        if(check(as[M])) L=M;
        else R=M;
      }
      return R;
    };
  Int ans=calc(r)-(l==LLONG_MIN?0:calc(l-1));
  cout<<ans<<endl;
  return 0;
}



Measured memory_bytes: 10496
#include<stdio.h>
int main(){
  int n=0,r[3]={};
  char s[3][100010];
  scanf("%s %s %s",s[0],s[1],s[2]);
  while(s[n][r[n]])n=s[n][r[n]++]-'a';
  printf("%c\n",n+'A');
  return 0;
}

Measured memory_bytes: 128
#include <atcoder/convolution>
#include <iostream>
#include <vector>
using namespace std;
using namespace atcoder;

int main() {
	int n, m;
	cin >> n >> m;
	
	vector<long long> a(n);
	vector<long long> b(m);
	for (int i = 0; i < n; i++) {
		cin >> a[i];
	}
	for (int i = 0; i < m; i++) {
		cin >> b[i];
	}
	
	vector<long long> c = convolution(a, b);
	
	for (int i = 0; i < n + m - 1; i++) {
		cout << c[i] << " ";
	}
	return 0;
}

Measured memory_bytes: 27196
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int a,b,k;
    cin>>a>>b>>k;
    int d=min(a,b);
    for(int i=d;i>=1;i--)
    {
        if(a%i==0&&b%i==0)
        {
            k--;
        }

        if(k==0)
        {
            printf("%d\n",i);
            break;
        }
    }
}

Measured memory_bytes: 256
fn main() {
    use std::io::Read;
    let mut buf = String::new();
    std::io::stdin().read_to_string(&mut buf).unwrap();
    let mut iter = buf.split_whitespace();
    
    let n: usize = iter.next().unwrap().parse::<usize>().unwrap();
    let m: usize = iter.next().unwrap().parse::<usize>().unwrap();
    let c: i64 = iter.next().unwrap().parse::<i64>().unwrap();
    let b: Vec<i64> = (&mut iter).take(m).map(|x| x.parse().unwrap()).collect();
    
    let mut ret = 0;
    for _ in 0..n {
        let a: Vec<i64> = (&mut iter).take(m).map(|x| x.parse().unwrap()).collect();
        if a.iter().zip(&b).fold(c, |acc, (p, q)| acc + p * q) > 0 {
            ret += 1;
        }
    }
    println!("{}", ret);
}

Measured memory_bytes: 4352
#include <iostream>
#include <queue>
using namespace std;
typedef pair<int, int> P;
const int dx[] = { -1, 0, 1, 0 };
const int dy[] = { 0, -1, 0, 1 };
int main(){
	int w, h;
	while( cin >> w >> h && w && h ){
		int maze[65][65];
		// 周りと壁の交点を１にする
		for( int i = 0; i < h * 2 + 1; i++ ){
			for( int j = 0; j < w * 2 + 1; j++ ){
				if( i == 0 || j == 0 ){
					maze[i][j] = 1;
				}else if( i % 2 == 0 && j % 2 == 0 ){
					maze[i][j] = 1;
				}else if( i == h * 2 || j == w * 2 ){
					maze[i][j] = 1;
				}else if( i % 2 == 1 && j % 2 == 1 ){
					maze[i][j] = 0;
				}else{
					int wall;
					cin >> wall;
					maze[i][j] = wall;
				}
			}
		}
		// 壁の入力
		/*for( int i = 0; i < h * 2 - 1; i++ ){
			if( i % 2 == 0 ){
				for( int j = 0; j < (w + 1) / 2; j++ ){
					int wall;
					cin >> wall;
					maze[i + 1][(j + 1) * 2] = wall;
				}
			}else{
				for( int j = 0; j < w; j++ ){
					int wall;
					cin >> wall;
				}
			}
		}*/
		// 探索
		queue< P > que;
		que.push( P(1, 1) );
		maze[1][1] = 1;
		while( !que.empty() ){
			for( int i = 0; i < 4; i++ ){
				int x = que.front().first + dx[i];
				int y = que.front().second + dy[i];
				if( maze[x][y] == 0 ){
					que.push( P( x, y ) );
					maze[x][y] = maze[que.front().first][que.front().second] + 1;
				}
			}
			if( que.front().first == h * 2 - 1 && que.front().second == w * 2 - 1 ){
				break;
			}
			que.pop();
		}
		/*
		for( int i = 0; i < h * 2 + 1; i++ ){
			for( int j = 0; j < w * 2 + 1; j++ ){
				cout << maze[i][j] << ' ';
			}
			cout << endl;
		}*/
		cout << (maze[h * 2 - 1][w * 2 -1] + 1) / 2 << endl;
	}
}

Measured memory_bytes: 1232
X, N = gets.split(" ").map(&:to_i)
p = gets.split(" ").map(&:to_i) if N > 0
p = [] if N == 0
i = 0; j = 0
while true 
  unless p.include?(X+j)
    puts X+j
    exit
  end
  unless p.include?(X+i)
    puts X+i
    exit
  end
  i += 1
  j -= 1
end

Measured memory_bytes: 14328
/****************************
/////  Shubham Singhal
/////  LNMIIT
*****************************/
#include <bits/stdc++.h>
// #include <ext/pb_ds/assoc_container.hpp> 
// #include <ext/pb_ds/tree_policy.hpp> 
// #include <functional> 
// using namespace __gnu_pbds;
#define ff first
#define ss second
#define mp make_pair
#define pb push_back
#define ppb pop_back
#define pf push_front
#define ppf pop_front
#define eb emplace_back
#define lwr lower_bound
#define upr upper_bound
#define pq priority_queue
#define umap unordered_map
#define rep(i,n) for(i=0; i<n;i++)
#define repp(i,a,n) for(i=a; i<n;i++)
#define precise(x) cout<<fixed<<setprecision(x)
#define all(x) x.begin(),x.end()
#define lcm(a,b) (a*b)/__gcd(a,b)
#define prn(x) cout<<x<<"\n"
#define prn2(x, y) cout<<x<<" "<<y<<"\n"
#define prn3(x, y, z) cout<<x<<" "<<y<<" "<<z<<"\n"
#define prn4(x, y, z, a) cout<<x<<" "<<y<<" "<<z<<" "<<a<<"\n"
#define prnv(x) for(auto i:x) cout<<i<<" "; cout<<"\n"
#define MOD 1000000007
#define MaX 300005
using namespace std;

 
typedef unsigned long long ull;
typedef long long ll;
typedef double ld;
typedef pair<int, int> pii;
typedef pair<ll, int> pli;
typedef pair<int, ll> pil;
typedef pair<ll, ll> pll;
typedef pair<double, double> pdd; 
typedef vector<int> vi;
typedef vector<long> vl;
typedef vector<char> vc;
typedef vector<ll> vll;
typedef vector<bool> vb;
typedef vector<double> vd;
typedef vector<string> vs;
typedef vector<pii> vpii;
typedef vector<pil> vpil;
typedef vector<pli> vpli;
typedef vector<pll> vpll;
const long long INF64 = 1e18;
clock_t time_p=clock();
void time()
{
    time_p=clock()-time_p;
    cerr<<"Time Taken : "<<(float)(time_p)/CLOCKS_PER_SEC<<"\n";
}
void doc()
{
    freopen("input.txt","r",stdin);
    freopen("output.txt","w",stdout);
}
void fast()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);cout.tie(NULL);
}
// typedef tree<int, null_type, less<int>, rb_tree_tag, 
//              tree_order_statistics_node_update> 
//     new_data_set; 
bool isprime(ll n) 
{ 
    if (n <= 1) 
        return false; 
    if (n <= 3) 
        return true; 
    if (n % 2 == 0 || n % 3 == 0) 
        return false; 
  
    for (ll i = 5; i * i <= n; i = i + 6) 
        if (n % i == 0 || n % (i + 2) == 0) 
            return false; 
    return true; 
}



int main() 
{
	fast();
	int x,a;
	cin>>x;
	if(x<=599)
		a=8;
	else if(x<=799)
	{
		a=7;
	}
	else if(x<=999)
		a=6;
	else if(x<=1199)
		a=5;
	else if(x<=1399)
		a=4;
	else if(x<=1599)
		a=3;
	else if(x<=1799)
		a=2;
	else
		a=1;
	cout<<a;

	return 0;
}

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

public class Main {
    
    public static void main(String[] args) {
        FastScanner sc = new FastScanner();
        String s = sc.next();
        String t = sc.next();
        int ans = 0;
        for(int i=0; i<s.length(); i++){
            if(s.charAt(i) == t.charAt(i)) ans++;
        }
        System.out.println(ans);
    }


    private static class FastScanner {
        private final InputStream in = System.in;
        private final byte[] buffer = new byte[1024];
        private int ptr = 0;
        private int buflen = 0;

        private boolean hasNextByte() {
            if (ptr < buflen) {
                return true;
            } else {
                ptr = 0;
                try {
                    buflen = in.read(buffer);
                } catch (IOException e) {
                    e.printStackTrace();
                }
                if (buflen <= 0) {
                    return false;
                }
            }
            return true;
        }

        private int readByte() {
            if (hasNextByte())
                return buffer[ptr++];
            else
                return -1;
        }

        private static boolean isPrintableChar(int c) {
            return 33 <= c && c <= 126;
        }

        public boolean hasNext() {
            while (hasNextByte() && !isPrintableChar(buffer[ptr]))
                ptr++;
            return hasNextByte();
        }

        public String next() {
            if (!hasNext())
                throw new NoSuchElementException();
            StringBuilder sb = new StringBuilder();
            int b = readByte();
            while (isPrintableChar(b)) {
                sb.appendCodePoint(b);
                b = readByte();
            }
            return sb.toString();
        }

        public long nextLong() {
            if (!hasNext())
                throw new NoSuchElementException();
            long n = 0;
            boolean minus = false;
            int b = readByte();
            if (b == '-') {
                minus = true;
                b = readByte();
            }
            if (b < '0' || '9' < b) {
                throw new NumberFormatException();
            }
            while (true) {
                if ('0' <= b && b <= '9') {
                    n *= 10;
                    n += b - '0';
                } else if (b == -1 || !isPrintableChar(b)) {
                    return minus ? -n : n;
                } else {
                    throw new NumberFormatException();
                }
                b = readByte();
            }
        }

        public int nextInt() {
            long nl = nextLong();
            if (nl < Integer.MIN_VALUE || nl > Integer.MAX_VALUE)
                throw new NumberFormatException();
            return (int) nl;
        }

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


Measured memory_bytes: 21332
N, L = input().split()
N = int(N)
L = int(L)

apples = list(range(N)) 
apples = [x + L for x in apples]
abs_apples = [abs(x) for x in apples]
abs_min_index = abs_apples.index(min(abs_apples))

print(sum(apples) - apples[abs_min_index])

Measured memory_bytes: 3060
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ConsoleApp1
{
    static class CDistinctOrNot
    {
        static void Main(string[] args)
        {
            var n = int.Parse(Console.ReadLine());
            var aList = Console.ReadLine().Split(' ').Select(x => int.Parse(x));

            Console.WriteLine(aList.GroupBy(x => x).Any(x => x.Count() > 1) ? "NO" : "YES");
            Console.ReadLine();
        }
    }
}

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

#define rep(i,s,n) for (int i = (int)s; i < (int)n; i++)
#define ll long long
#define ld long double
#define pb push_back
#define eb emplace_back
#define All(x) x.begin(), x.end()
#define Range(x, i, j) x.begin() + i, x.begin() + j
#define lbidx(x, y) lower_bound(x.begin(), x.end(), y) - x.begin()
#define ubidx(x, y) upper_bound(x.begin(), x.end(), y) - x.begin()
#define llbidx(x, y, z) lower_bound(x.begin(), x.end(), z) - lower_bound(x.begin(), x.end(), y) // 二要素間の距離
#define deg2rad(deg) ((((double)deg)/((double)360)*2*M_PI))
#define rad2deg(rad) ((((double)rad)/(double)2/M_PI)*(double)360)
#define Find(set, element) set.find(element) != set.end()
#define Decimal(x) printf("%.10f\n", x) // 小数点を10桁まで表示
// debug用
#define PrintVec(x) for (auto elementPrintVec: x) { cout << elementPrintVec << " "; } cout << "\n";
#define debug(x) cerr << #x << ": " << (x) << "\n";
#define endl "\n"
// gcj print用
#define Case(x) printf("Case #%d: ", x);

typedef pair<int, int> PI;
typedef pair<ll, ll> PLL;
typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef vector<vector<vector<int>>> vvvi;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
typedef vector<vector<vector<int>>> vvvl;
typedef vector<PI> vpi;
typedef vector<vector<PI>> vvpi;
typedef vector<vector<vector<PI>>> vvvpi;
typedef vector<PLL> vpl;
typedef vector<vector<PLL>> vvpl;
typedef vector<vector<vector<PLL>>> vvvpl;

int POWINT(int x, int n) {
  int ret = 1;
  while (n > 0) {
    if (n & 1) ret *= x;
    x *= x;
    n >>= 1;
  }
  return ret;
};

ll POWLL(ll x, int n) {
  ll ret = 1;
  while (n > 0) {
    if (n & 1) ret *= x;
    x *= x;
    n >>= 1;
  }
  return ret;
};

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

void print() {
  cout << endl;
}

template <class T>
void print(vector<T> &vec) {
  for (auto& a : vec) {
    cout << a;
    if (&a != &vec.back()) cout << " ";
  }
  cout << endl;
}

template <class T>
void print(vector<T> &vec, ll k){
   ll n = vec.size();
   k = min(k, n);
   rep(i, 0, k-1) cout << vec[i] << " ";
   cout << vec[k-1] << endl;
}

template <class T>
void print(vector<vector<T>> &df) {
  for (auto& vec : df) {
    print(vec);
  }
}

template<class T, class U>
void print(pair<T,U> &p){
  cout << p.first << " " << p.second << "\n";
}

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

  int n; cin >> n;
  int z, w; cin >> z >> w;

  vi a(n+1);
  rep(i, 1, n+1) cin >> a[i];
  vi dpx(n+1), dpy(n+1);

  dpx[n] = abs(w-a[n]);

  dpx[n-1] = abs(a[n-1]-a[n]);
  dpy[n-1] = abs(a[n-1]-a[n]);

  for (int i = n-2; i >= 1; i--) {
    for (int j = i+1; j <= n; j++) {
      chmin(dpx[i], dpy[j]);
      chmax(dpy[i], dpx[j]);
    }
  }

  int ans = -1;

  for (int i = 1; i <= n; i++) {
    chmax(ans, dpx[i]);
  }

  cout << ans << endl;

  return 0;
};


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

using namespace std;

int main() {
    int n;
    cin >> n;
    vector<int> a(n),b(n),c(n);
    for (int i = 0; i < n; i++) {
        cin >> a.at(i);
        a.at(i)--;
    }

    for (int i = 0; i < n; i++) {
        cin >> b.at(i);
    }

    for (int i = 0; i < n-1; i++) {
        cin >> c.at(i);
    }

    int count = 0;
    for (int i = 0; i < n; i++) {
        count += b.at(a.at(i));
        if (i != 0 && a.at(i) == a.at(i-1)+1) {
            count += c.at(a.at(i-1));
        }
    }

    cout << count << endl;

    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
// debug
#define d(x) cerr << #x ":" << x << endl;
#define dd(x, y) cerr << "(" #x "," #y "):(" << x << "," << y << ")" << endl;
#define ddd(x, y, z) cerr << "(" #x "," #y "," #z "):(" << x << "," << y << "," << z << ")" << endl;
#define dump(v) cerr<<#v":[ ";for (auto macro_vi:v){cerr<<macro_vi<< " ";}cerr<<"]"<<endl;
#define ddump(v) cerr<<#v":"<<endl;for(auto macro_row:v) {cerr<<"["; for (auto macro__vi:macro_row){cerr<<macro__vi<< " ";}cerr<<"]"<<endl;}
#define damp(m) for(auto macro_pair:m){cerr<< macro_pair.first<<":"<<macro_pair.second<<endl;}
#define dpair(p) cerr << #p":"<<"(" << p.first << "," << p.second << ")" << endl;
// iterate
#define repr(i, a, b) for (int i = (int)(a); i < (int)(b); i++)
#define rep(i, n) repr(i, 0, n)
#define reprrev(i, a, b) for (int i = (int)(b)-1; i >= (int)(a); i--)
#define reprev(i, n) reprrev(i, 0, n)
#define repi(itr, ds) for (auto itr = ds.begin(); itr != ds.end(); itr++)
#define all(v) v.begin(), v.end()
// etc
#define chmin(mi, val) mi = min(mi, val);
#define chmax(ma, val) ma = max(ma, val);
using ll = long long;

using namespace std;

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);\
    string s;
    cin >> s;
    if(s=="Sunny")
        cout << "Cloudy"<< endl;
    else if(s=="Cloudy")
        cout << "Rainy" << endl;
    else if(s == "Rainy")
        cout << "Sunny" <<  endl;
    return 0;
}

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

int main() {
  int n;
  cin >> n;
  string s;
  cin >> s;
  int E[n] = {};
  int W[n] = {};
  int E_cnt = 0;
  for (int i = n - 1; i >= 0; i--) {
    E[i] = E_cnt;
    if (s[i] == 'E') {
      E_cnt++;
    }
  }
  int W_cnt = 0;
  for (int i = 0; i < n; i++) {
    W[i] = W_cnt;
    if (s[i] == 'W') {
      W_cnt++;
    }
  }
  int min = n;
  for (int i = 0; i < n; i++) {
    if (min > (E[i] + W[i])) {
      min = E[i] + W[i];
    }
  }

  cout << min << endl;

  return 0;
}

Measured memory_bytes: 3076
import math
N, K = map(int, input().split())
if K == 0:
    ans = N*N
else:
    ans = 0
    j = 1
    for i in range(K+1, N+1):
        mod = N % i
        x = N//i
        ans += x*j
        if mod>=K:
            ans+=mod-K+1
        j += 1
print(ans)


Measured memory_bytes: 9180
#include<bits/stdc++.h>
using namespace std;
#define int long long int
#define ps push_back
#define mod 1000000007
#define fi first
#define so second
#define pii pair<int,int>
#define TT int tt;cin>>tt;while(tt--)

int res(int n)
{
    int a=n;
    int b=(n*(n-1));
    int c=(b*(n-2))/6;
    return a+b+c;
}

signed main()
{
    int k,ans=0;
    cin>>k;
    for(int i=1;i<=k;i++) for(int j=1;j<=k;j++) for(int g=1;g<=k;g++) ans+=__gcd(__gcd(i,j),g);
    cout<<ans;
}


Measured memory_bytes: 3636
#include<bits/stdc++.h>
using namespace std;
#define fast ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
typedef long long ll;
typedef double dd;
#define pb push_back
#define mp make_pair
#define endl "\n"
ll const M = 1000000007;
dd const pi = acos(-1);
ll const inf = 2e18;
ll const N = 200001;
int main()
{
    fast;
    ll i,j,t,n,cnt = 0,ans = 0;
    cin >> n;
    bool flag = false;
    for(i = 2; i*i <= n; i++)
    {
    	while(n % i == 0)
    	{
    		n /= i;
    		flag = true;
    		cnt++;
    	}
    	if(flag)
    	{
    		ans = ans + (-1 + sqrt(1 + 8*cnt))/2;
    		flag = false;
    		cnt = 0;
    	}
    }
    if(n > 1)
    	ans++;
    cout<<ans<<endl;
    return 0;
}    

Measured memory_bytes: 3696
# verify-helper: PROBLEM https://judge.yosupo.jp/problem/unionfind
import sys

input = sys.stdin.buffer.readline


class UnionFindTree:
    """Disjoint-Set Data Structure

    Union-Find Tree

    complexity:
        - init: O(n)
        - find, unite, same: O(alpha(n))
    """

    def __init__(self, n: int) -> None:
        self.par = list(range(n))  # parent
        self.rank = [0] * n  # depth of tree

    def find(self, x: int) -> int:
        if self.par[x] == x:
            return x
        else:
            self.par[x] = self.find(self.par[x])
            return self.par[x]

    def unite(self, x: int, y: int) -> None:
        x, y = self.find(x), self.find(y)
        if x == y:
            return
        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 is_same(self, x: int, y: int) -> bool:
        return self.find(x) == self.find(y)


def main() -> None:
    N, Q = map(int, input().split())
    uft = UnionFindTree(N)
    ans = []
    for _ in range(Q):
        t, u, v = map(int, input().split())
        if t == 0:
            uft.unite(u, v)
        else:
            ans.append(int(uft.is_same(u, v)))
    print(*ans, sep="\n")


if __name__ == "__main__":
    main()


Measured memory_bytes: 19552
#include<iostream>
using namespace std;
int main(void){
    int n,min;
    int count = 1;
    cin >> n;
    int x[n];
    for(int t=0;t<n;t++){
        cin >> x[t];
    }

    min = x[0];
    for(int i=0;i<n;i++){
        if(min > x[i]){
            min = x[i];
            count++;
            if(min == 1)break;
        }
        
    }
    
    cout << count << endl;

    return 0;
}

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

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

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


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


const int MAX_N = 100010;
int dp[MAX_N];
int h[MAX_N];
signed main() {
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	int n; cin >> n;
	rep(i, n)cin >> h[i];
	rep(i, 100010)dp[i] = INF;
	dp[0] = 0;
	rep(i, n) {
		chmin(dp[i + 1], dp[i] + abs(h[i] - h[i + 1]));
		chmin(dp[i + 2], dp[i] + abs(h[i] - h[i + 2]));
	}
	cout << dp[n-1] << endl;
	return 0;
}


Measured memory_bytes: 1792
#include<iostream>
#include<sstream>
#include<cstdio>
#include<cstdlib>
#include<vector>
#include<string>
#include<stack>
#include<queue>
#include<deque>
#include<set>
#include<map>
#include<algorithm>
#include<functional>
#include<utility>
#include<cmath>
#include<ctime>
#include<complex>

using namespace std;

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


int main(){

	int h,m,s,h1,m1,s1;

	rep(i,3){

		cin >> h >> m >> s >> h1 >> m1 >> s1;

		int a=(3600*h1+60*m1+s1)-(3600*h+60*m+s);

		cout << a/3600 << " " << (a%3600)/60 << " " << (a%3600)%60 << endl;

	}

	return 0;
}

Measured memory_bytes: 1160
#define _CRT_SECURE_NO_WARNINGS

#include<iostream>
#include<string>
#include<vector>
#include<list>
#include<stack>
#include<queue>
#include<map>
#include<tuple>
#include<algorithm>
#include<numeric>
#include<math.h>
#include<functional> // greater<Type>()

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

using namespace std;

using ll = long long;
using pii = pair<int, int>;
using vi = vector<int>;

const int mod = 1e9 + 7;
const long double pi = 3.141592653589793238462643383279502884197;
const long double eps = 1e-7;

int main() {
	vector<ll> cost[8];
	int N, M;
	cin >> N >> M;

	REP(i, N) {
		ll x, y, z;
		cin >> x >> y >> z;
		cost[0].push_back(x + y + z);
		cost[1].push_back(x + y - z);
		cost[2].push_back(x - y + z);
		cost[3].push_back(x - y - z);
		cost[4].push_back(-x + y + z);
		cost[5].push_back(-x + y - z);
		cost[6].push_back(-x - y + z);
		cost[7].push_back(-x - y - z);
	}

	ll maxCost = 0;
	REP(i, 8){
		sort(cost[i].begin(), cost[i].end());

		ll totalCost = 0;
		for (int j = N - 1; j > N - M -1; j--) {
			totalCost += cost[i][j];
		}
		if (maxCost < totalCost) maxCost = totalCost;
	}
	std::cout << maxCost;
	
	std::system("pause");
	return 0;
}

Measured memory_bytes: 512
#include<bits/stdc++.h>
using namespace std;
const int N = 100005;
int n, k;
int ar[N];
long long dp[N];

long long f(int pos){
	if (pos == 1)
		return 0;
	if (pos < 1)
		return INT_MAX;
	if (dp[pos] != -1)
		return dp[pos];
	long long mn = 10000000000000000;
	for (int i = 1; i <= k; i++){
		mn = min(mn, f(pos - i) + abs(ar[pos] - ar[pos - i]));
	}
	return dp[pos] = mn;
}

int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	cin >> n >> k;
	for (int i = 1; i <= n; i++){
		cin >> ar[i];
	}
	memset(dp, -1, sizeof(dp));
	cout << f(n) << '\n';
	return 0;
}



Measured memory_bytes: 6144
#include <bits/stdc++.h>
#define int long long
#define double long double

using namespace std;

typedef pair<int, double> pi;
vector<pi> adjlist[1005];
double dist[1005];
int x[1005], y[1005], r[1005], sx, sy, tx, ty;
int n;
double calc(int x1, int y1, int x2, int y2){
	return (double) sqrt( (double) ((x2-x1)*(x2-x1)+(y2-y1)*(y2-y1)));
}
double mmax(double a, double b){ return a>b?a:b; }
int32_t main(){
	cin >> sx >> sy >> tx >> ty;
	cin >> n;
	for(int i=1; i<=n; ++i) cin >> x[i] >> y[i] >> r[i];
	adjlist[0].push_back(pi(n+1,calc(sx,sy,tx,ty)));
	for(int i=1; i<=n; ++i){
		adjlist[0].push_back(pi(i,mmax(0.0,calc(sx,sy,x[i],y[i])-r[i])));
		adjlist[i].push_back(pi(n+1,mmax(0.0,calc(tx,ty,x[i],y[i])-r[i])));
		for(int j=i+1; j<=n; ++j){
			adjlist[i].push_back(pi(j,mmax(0.0,calc(x[i],y[i],x[j],y[j])-(double) r[i]-(double) r[j])));
			adjlist[j].push_back(pi(i,mmax(0.0,calc(x[i],y[i],x[j],y[j])-(double) r[i]-(double) r[j])));
		}
	}
	typedef pair<double, int> di;
	priority_queue<di, vector<di>, greater<di>> pq;
	for(int i=0; i<=n+1; ++i) dist[i] = -1.0;
//	for(int i=0; i<=n+1; ++i) cout << dist[i] << " "; cout << endl;
	dist[0] = 0.0;
	pq.push(di(dist[0], 0));
	while(!pq.empty()){
		int node = pq.top().second; double d = pq.top().first; pq.pop();
		if(dist[node] != d) continue;
		for(auto i : adjlist[node]){
			int childnode = i.first;
			double childdist = i.second;
			if(dist[childnode] == -1 or dist[childnode] > dist[node] + childdist){
				dist[childnode] = dist[node] + childdist;
				pq.push(di(dist[childnode], childnode));
			}
		}
	}
	cout << setprecision(20) << dist[n+1];
}


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

#define ff              first
#define ss              second
#define int             long long
#define pb              push_back
#define mp              make_pair
#define pii             pair<int,int>
#define vi              vector<int>
#define mii             map<int,int>
#define pqb             priority_queue<int>
#define pqs             priority_queue<int,vi,greater<int> >
#define MX              200005
#define mod             1000000007
#define inf             1e18
#define ps(x,y)         fixed<<setprecision(y)<<x
#define mk(arr,n,type)  type *arr=new type[n];
#define w(x)            int x; cin>>x; while(x--)
#define pw(b,p)         pow(b,p) + 0.1
#define ull unsigned long long
#define ll long long

void sbs()
{
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    #ifndef ONLINE_JUDGE
    freopen("input.in", "r", stdin);
    freopen("output.in", "w", stdout);
    #endif
}
void add(int &a,int b){
    a+=b;
    if(a>=mod)
        a-=mod;
}
int32_t main()
{
    //sbs();
    // int t;cin>>t;
    // while(t--) {
        
    //     cout<<'\n';
    // }

    int n,w;cin>>n>>w;
    vi v,wt;
    vector<vi> dp(n+1,vi(w+1,0));
    for (int i = 0; i < n; ++i){
        int t;cin>>t;
        wt.pb(t);
        cin>>t;
        v.pb(t);
    }
    for (int i = 1; i < n+1; ++i){
        for (int j = 1; j < w+1; ++j){
            if(wt[i-1]<=j){
                dp[i][j]=max(dp[i-1][j],v[i-1]+dp[i-1][j-wt[i-1]]);
            }else dp[i][j]=dp[i-1][j];
        }
    }
    // for (int i = 0; i < n+1; ++i){
    //     for (int j = 0; j < w+1; ++j){
    //         cout<<dp[i][j]<<" ";
    //     }cout<<'\n';
    // }
    cout<<dp[n][w]<<endl;
    return 0;
}

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

typedef long long ll;
int n,h;
vector<int> th;
int maxa,maxai;
int a[100005];
int b[100005];
int ans;
int main() {

  cin >> n >> h;
  for(int i = 0; i < n; i++) {
    cin >> a[i] >> b[i];
    if(maxa < a[i]) {
      maxa = a[i];
      maxai = i;
    }
  }

  for(int i = 0; i < n; i++) {
    if(maxa < b[i]) th.push_back(b[i]);
  }

  sort(th.begin(),th.end(),greater<int> ());

  for(int i = 0; i < th.size(); i++) {
    h -= th[i];
    ans++;
    if(h <= 0) {
      cout << ans << endl;
      return 0;
    }
  }
  
  int tmp = (h % maxa == 0) ? (h / maxa) : (h / maxa + 1);

  cout << ans + tmp << endl;
  
  
}


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

int main(){
  string s;
  cin >> s;
  int curr = 0, ans = 0;
  for(int i = 0; i < s.size(); i++){
  	if(s[i]=='R'){
    	curr++;
    }
    ans = max(curr, ans);
    if(s[i]!='R'){
      curr = 0;
    }
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 3604