akhauriyash/Code-Regression huggingface dataset:
import std;

alias sread = () => readln.chomp();
alias lread = () => readln.chomp.to!long();
alias aryread(T = long) = () => readln.split.to!(T[]);

void main()
{
    auto n = sread();
    long sum_n;
    foreach (i; 0 .. n.length)
    {
        // writeln(n[i] - '0');
        sum_n += (n[i] - '0');

    }
    // writeln('s', sum_n);
    // writeln(n.length);
    auto nn = n.to!long();
    // writeln(nn);
    auto tmp = new long[](n.length);
    tmp[0] = nn / (10 ^^ ((n.length) - 1)) - 1;
    foreach (i; 1 .. (n.length))
    {
        tmp[i] = 9;
    }
    // writeln(tmp);
    writeln(max(tmp.sum(), sum_n));

}

auto func(long n)
{
    long sum_x;
    while (n > 0)
    {
        sum_x += n % 10;
        n /= 10;
    }
    return sum_x;
}

void scan(L...)(ref L A)
{
    auto l = readln.split;
    foreach (i, T; L)
    {
        A[i] = l[i].to!T;
    }
}


Measured memory_bytes: 3604
#include <iostream>
#include <string>
#include <algorithm>
#include <cstdio>
#include <vector>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <numeric>
#include <cmath>

using namespace std;

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

#define all(x) x.begin(),x.end()

const ll mod = 1e9+7;
const ll INF = 1e9;
const ll MAXN = 1e9;

int main()
{
	ll w,h,x,y;
	cin>>w>>h>>x>>y;
	double area = (double)w*h/2;
	cout<<area << " "<< ((w%2==0&&h%2==0&&w/2==x&&h/2==y)?1:0)<<endl;
	return 0;
}

Measured memory_bytes: 256
from functools import reduce
import math

def main():
    # 文字列の2進数を数値にする
    # '101' → '5'
    # 文字列の頭に'0b'をつけてint()にわたす
    # binary = int('0b'+'101',0)

    # 2進数で立っているbitを数える
    # 101(0x5) → 2
    # cnt_bit = bin(5).count('1')
    
    # N! を求める
    # f = math.factorial(N)

    # N の逆元
    # N_inv = pow(N,MOD-2,MOD)

    # nCr
    # Nの階乗 * rの階乗の逆元 * n-rの階乗の逆元
    
    # 切り捨て
    # 4 // 3
    # 切り上げ
    #-(-4 // 3)
    
    # 初期値用:十分大きい数(100億)
    INF = float("inf")

    # 大きな素数
    MOD = 10**9+7
    
    # 1文字のみを読み込み
    # 入力:2
    # a = input().rstrip()
    # 変数:a='2'
    
    # スペース区切りで標準入力を配列として読み込み
    # 入力:2 4 5 7
    # a, b, c, d = (int(_) for _ in input().split())  
    # 変数:a=2 b=4 c=5 d =7
    
    # 1文字ずつ標準入力を配列として読み込み
    # 入力:2 4 5 7
    # a = list(int(_) for _ in input().split())
    # 変数:a = [2, 4, 5, 7]    

    # 1文字ずつ標準入力を配列として読み込み
    # 入力:2457
    # a = list(int(_) for _ in input())
    # 変数:a = [2, 4, 5, 7]    
    c = []
    for _ in range(3):
        c.append(list(int(_) for _ in input().split()))
    c_row_sum = []
    c_column_sum = []
    for i in range(3):
        c_row_sum.append(sum(c[i]))
    for i in range(3):
        tmp_sum = 0
        for j in range(3):
            tmp_sum += c[j][i]
        c_column_sum.append(tmp_sum)
    
    for b in range(301):
        a1 = (c_column_sum[0] - b)/3
        a2 = (c_column_sum[1] - b)/3
        a3 = (c_column_sum[2] - b)/3
        if a1.is_integer() and a2.is_integer() and a3.is_integer():
            b1 = (c_row_sum[0]-(a1+a2+a3))/3
            b2 = (c_row_sum[1]-(a1+a2+a3))/3
            b3 = (c_row_sum[2]-(a1+a2+a3))/3
            if b1.is_integer() and b2.is_integer() and b3.is_integer():
                print('Yes')
                return
    print('No')
    
if __name__ == '__main__':
    main()


Measured memory_bytes: 3572
import java.io.IOException;
import java.nio.charset.Charset;

public class Main {

    public static void main(String[] args) {
        try (var input = System.in) {
            var inputText = new String(input.readAllBytes(), Charset.forName("UTF-8"));
            var degree = Integer.parseInt(inputText.trim());
            var roomTemperature = new RoomTemperature(degree);
            if (roomTemperature.isTooHot()) {
                System.out.println("Yes");
            } else {
                System.out.println("No");
            }
        } catch (IOException e) {

        }
    }

    public static class RoomTemperature {
        private final int degree;
        public RoomTemperature(int degree) {
            this.degree = degree;
        }
        public boolean isTooHot() {
            if (degree >= 30) {
                return true;
            } else {
                return false;
            }
        }
    }
}

Measured memory_bytes: 32328
#include <stdio.h>
char a[105],b[105],c[105],turn;
int at,bt,ct;
int main() {
    scanf("%s\n%s\n%s",a,b,c);
    turn=a[at++];
    while(1) {
        if(turn=='a')
            turn=a[at++];
        else if(turn=='b')
            turn=b[bt++];
        else
            turn=c[ct++];
        if(turn=='\0') break;
    }
    if(a[at-1]=='\0') printf("A\n");
    else if(b[bt-1]=='\0') printf("B\n");
    else printf("C\n");
    return 0;
}


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

#define int long long

#define rep(i,n) for(int i=0;i<(n);i++)
#define all(v) (v).begin(),(v).end()
#define pb push_back
#define fi first
#define se second

typedef vector<int>vint;
typedef pair<int,int>pint;
typedef vector<pint>vpint;

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

int N;

int C[1<<22];
int O[1<<22];
bool ex[1<<22];

short cnt[1<<22][22];

signed main(){
    scanf("%lld",&N);
    rep(i,N){
        int x=0;
        int k;scanf("%lld",&k);
        while(k--){
            int a;scanf("%lld",&a);
            a--;
            x^=1<<a;
        }
        cnt[x][0]++;
        O[x]=x;
    }

    for(int i=1<<22;i>=0;i--){
        for(int j=0;j<22;j++){
            if(i>>j&1)O[i^(1<<j)]|=O[i];
        }
    }

    int ans=0;

    for(int i=1<<22;i>=0;i--){
        for(int j=0;j<22;j++){
            if(i>>j&1){
                cnt[i^(1<<j)][j]+=cnt[i][j];
            }
            if(j!=21)cnt[i][j+1]+=cnt[i][j];
        }
        if(cnt[i][21]>=3)chmax(ans,__builtin_popcount(i)*__builtin_popcount(O[i]));
    }
    cout<<ans<<endl;
}

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

using namespace std;

#define sim template <class c
#define ris return *this
#define dor > debug &operator<<
#define eni(x)                                                                        \
	sim > typename enable_if<sizeof dud<c>(0) x 1, debug &>::type operator<<(c i) \
	{
sim > struct rge
{
	c b, e;
};
sim > rge<c> range(c i, c j) { return rge<c>{i, j}; }
sim > auto dud(c *x) -> decltype(cerr << *x, 0);
sim > char dud(...);
struct debug
{
#ifdef LOCAL
	~debug()
	{
		cerr << endl;
	}
	eni(!=) cerr << boolalpha << i;
	ris;
} eni(==) ris << range(begin(i), end(i));
}
sim, class b dor(pair<b, c> d)
{
	ris << "(" << d.first << ", " << d.second << ")";
}
sim dor(rge<c> d)
{
	*this << "[";
	for (auto it = d.b; it != d.e; ++it)
		*this << ", " + 2 * (it == d.b) << *it;
	ris << "]";
}
#else
	sim dor(const c &)
	{
		ris;
	}
#endif
}
;
#define imie(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "

#define forn(i, n) for (ll i = 0; i < int(n); i++)
#define rfor(n, i) for (ll i = (n - 1); i >= 0; --i)
#define all(V) V.begin(), V.end()
#define rall(V) V.rbegin(), V.rend()
#define len(V) (int)V.size()
#define ll long long
#define ld long double
#define ff first
#define ss second
#define pb push_back
#define mp make_pair
#define endl '\n'
#define M_PI 3.14159265358979323846
#define EPS 1e-7

int cnt = 0;

void solve()
{
	int n, k; cin >> n >> k;
	ll p = 1;
	for (int i = 0; i < n - 1; ++i)
	{
		p *= (k - 1);
	}
	cout << p * k << endl;
}

int main()
{
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	solve();
}


Measured memory_bytes: 3632
x, n = map(int, input().split())
p = list(map(int, input().split()))
i = 0
ans = x

while True:
    if (x - i) not in p:
        ans = x - i
        break
    elif (x + i) not in p:
        ans = x + i
        break
    i += 1

print(ans)

Measured memory_bytes: 9188
#include<bits/stdc++.h>
using namespace std;
struct stu{
	int t;
	int h;
} s[100010];
int cmp(stu a,stu b){
	return a.t<b.t; 
}
int main(){
	int n;
	cin>>n;
	for(int i=0;i<n;i++){
		cin>>s[i].t;
		s[i].h=i;
	}
	sort(s,s+n,cmp);
	for(int i=0;i<n;i++){
		cout<<s[i].h+1<<' '; 
	}
	return 0;
}

Measured memory_bytes: 1536
#include <bits/stdc++.h>
#define endl "\n"
using namespace std;
typedef long long ll;
typedef pair<ll, ll> l_l;
typedef pair<int, int> i_i;
template<class T>
inline bool chmax(T &a, T b) {
    if(a < b) {
        a = b;
        return true;
    }
    return false;
}

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

const long long INF = 1e18;
//const ll mod = 1000000007;
ll dp[61][200000];

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll N, K;
    cin >> N >> K;
    for(int i = 0; i < N; i++) {
        cin >> dp[0][i];
        dp[0][i]--;
    }
    for(int k = 1; k <= 60; k++) {
        for(int i = 0; i < N; i++) {
            dp[k][i] = dp[k-1][dp[k-1][i]];
        }
    }
    ll ans = 0;
    for(int i = 0; i <= 60; i++) {
        if(K & (1LL << i)) {
            ans = dp[i][ans];
        }
    }
    cout << ans + 1 << endl;
    return 0;
}

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

namespace bit {
using u32 = uint_fast32_t;
using u64 = unsigned long long;
template<class T>
constexpr T set(T bin, u32 pos) {
	return bin | (1LL << pos);
}
template<class T>
constexpr T get(T bin, u32 pos) {
	return bin & (1LL << pos);
}
template<class T>
constexpr bool check(T bin, u32 pos) {
	return get(bin, pos);
}
constexpr u32 popcount(u64 bin) {
	return __builtin_popcountll(bin);
}
} // namespace bit

int main() {
	int N; cin >> N;
	vector<vector<pair<int, int>>> A(N);
	for (int i = 0; i < N; i++) {
		int a; cin >> a;
		for (int j = 0; j < a; j++) {
			int x, y; cin >> x >> y;
			x--;
			A[i].emplace_back(x, y);
		}
	}
	int res = 0;
	for (int i = 1; i < 1 << N; i++) {
		bool ok = true;
		for (int j = 0; j < N; j++) {
			if (!bit::check(i, j)) continue;
			for (auto p : A[j]) {
				ok = ok && (bit::check(i, p.first) == p.second);
			}
		}
		if (ok) {
			res = max(res, int(bit::popcount(i)));
		}
	}
	cout << res << endl;
}

Measured memory_bytes: 256
#define ENABLE_DEBUG 1
// Kana's kitchen {{{
#include<bits/stdc++.h>
#define ALL(v) std::begin(v),std::end(v)
#define LOOP(k) for(i64 ngtkana_is_a_genius=0; ngtkana_is_a_genius<(i64)k; ngtkana_is_a_genius++)

using i32 = std::int_least32_t;
using i64 = std::int_least64_t;
using u32 = std::uint_least32_t;
using u64 = std::uint_least64_t;
using usize = std::size_t;

template <class T, class U> using pair = std::pair<U, T>;
template <class T> using diag_pair = std::pair<T, T>;
template <class... Args> using tuple = std::tuple<Args...>;
template <class T> using vec = std::vector<T>;
template <class T> using numr = std::numeric_limits<T>;

#ifdef NGTKANA
#include<debug.hpp>
#else
#define DEBUG(...)(void)0
#endif
/*}}}*/

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

    i64 n;
    std::cin >> n;
    n++;
    vec<i64> ans, r;
    i64 now = 0;
    for (; n!=1; n/=2) {
        if (n%2==1)  r.push_back(now++);
        ans.push_back(now++);
    }
    ans.insert(ans.end(), r.rbegin(), r.rend());
    DEBUG(ans);

    std::cout << ans.size() * 2 << '\n';
    for (usize i=0; i<ans.size()*2; i++) {
        std::cout << (i ? " " : "") << (i<ans.size() ? ans.at(i) : i - ans.size()) + 1;
    }
    std::cout << '\n';
}


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


def pro(m):
	x=0
	for j in range(3,m+1):
		x+= (3**j) - 3*(2**j) + 3
	return(x)

def plus(s,n):
	s=list(str(s))
	if s[-n]=="3":
		s[-n]="5"
		return(int(''.join(s)))
	elif s[-n]=="5":
		s[-n]="7"
		return(int(''.join(s)))
	else:
		s[-n]="3"
		s=int(''.join(s))
		return(plus(s,n+1))

c=0

if N<=356: c=0
elif N<=999:
	x=357
	while x<=N:
		s=str(x)
		if "3" in s and "5" in s and "7" in s: c+=1
		if x==777: break
		x=plus(x,1)
else:
	m=len(str(N))-1
	c=pro(m)
	x=int("3"*(m+1))
	while x<=N:
		s=str(x)
		if "3" in s and "5" in s and "7" in s: c+=1
		if x==int("7"*(m+1)): break
		x=plus(x,1)

print(c)



Measured memory_bytes: 3064
#include <bits/stdc++.h>
#define rep(i,s,n) for(int i=s;i<n;i++)
#define pb push_back
#define all(x) (x).begin(),(x).end()
#define int long long
using namespace std;
using P=pair<int,int>;
using Graph=vector<vector<int>>;
using ll=long long;


ll gcd(ll A, ll B){
    if(B == 0)return A;
    return gcd(B, A % B);
}
ll lcm(ll A, ll B){
    return A * B / gcd(A, B);
}
bool root(string s){
    int n=s.length();
    if(n==2){
        if(s[0]==s[1]){
            return true;
        }
        else return false;
    }
    if(n==3){
        if(s[0]==s[2]){
            return true;
        }
        else return false;
    }
 
    return false;
}
 
 
//深さ優先
vector<int> seen;
vector<ll> h;
 
//普通の深さ優先探索seenを返す感じ
void dfs(const Graph &G,int v){
    seen[v] = 0; //v探索済み
 
    P good=make_pair(v,h[v]);
    for(auto next_v :G[v]){
        if(seen[next_v]!=-1) continue;//もう探索していた
        if(h[next_v]>good.second){
            good=make_pair(next_v,h[next_v]);
        }
        dfs(G,next_v);
    }
 
    if(!(h[v]==good.second && v==good.first)){
        seen[good.first]=1;
    }
}
 
signed main(){
    /*
    int n,m;
    cin>>n>>m;
 
    h.assign(n,0);
    rep(i,0,n) cin>>h[i];
 
    Graph G(n);
    rep(i,0,m){
        int a,b; cin>>a>>b;
        G[a-1].push_back(b-1);
        G[b-1].push_back(a-1);
    }
 
    seen.assign(n,-1);
 
    rep(i,0,n){
        if(seen[i]==-1){
            dfs(G,i);
        }
    }
 
    int sum=accumulate(all(seen),0);
 
    cout<<sum<<endl;*/
 
    int a,b; cin>>a>>b;
    if((a*b)%2){
        cout<<"Odd"<<endl;
    }else{
        cout<<"Even"<<endl;
    }
}   

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

constexpr int64_t mod = 1'000'000'007; //'
int64_t fact[1000000], finv[1000000];

int64_t comb(int n, int r){
    return fact[n]*finv[r] % mod * finv[n-r] % mod;
}
int64_t mpow(int64_t x, int64_t y){
    if(y==0) return 1;
    if(y==1) return x%mod;
    if(y%2 == 0) return mpow(x*x%mod, y/2) % mod;
    return mpow(x*x%mod, y/2)*x % mod;
}

int main(){
    fact[0] = 1;
    for(int i=1;i<1000000;++i) fact[i] = i * fact[i-1] % mod;
    finv[999999] = mpow(fact[999999], mod-2);
    for(int i=999999;i>0;--i) finv[i-1] = i * finv[i] % mod;
    int x, y;
    cin >> x >> y;
    if((x+y)%3 != 0 || y > x*2 || x > y*2){
        cout << 0 << endl;
        return 0;
    }
    int cnt = (x+y) / 3;
    cout << comb(cnt, x-cnt) << endl;
    return 0;
}

Measured memory_bytes: 16000
#include <iostream>
#include <vector>
using namespace std;
int n;
vector<int> a, ans;
int main(void){
    cin >> n;
    a.assign(n+1, 0);
    ans.assign(n+1, 0);
    for(int i=2;i<=n;i++){
        cin >> a[i];
        ans[a[i]]++;
    }
    
    for(int i=1;i<=n;i++){
        cout << ans[i] << endl;
    }
}


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

typedef long long ll;

int main() {
    ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
    ll r, d, x;
    cin >> r >> d >> x;
    for(int i = 0; i < 10; i++) {
        x = r * x - d;
        cout << x << endl;
    }
}

/**
*/


Measured memory_bytes: 256
(eval-when (:compile-toplevel :load-toplevel :execute)
  (defparameter OPT
    #+swank '(optimize (speed 3) (safety 2))
    #-swank '(optimize (speed 3) (safety 0) (debug 0)))
  #+swank (progn (ql:quickload '(:cl-debug-print :fiveam))
                 (shadow :run)
                 (use-package :fiveam)))
#+swank (cl-syntax:use-syntax cl-debug-print:debug-print-syntax)

;; BEGIN_INSERTED_CONTENTS
(defmacro buffered-read-line (&optional (buffer-size 30) (in '*standard-input*) (terminate-char #\Space))
  "Note that the returned string will be reused."
  (let ((buffer (gensym))
        (character (gensym))
        (idx (gensym)))
    `(let ((,buffer (load-time-value (make-string ,buffer-size
                                                  :element-type 'base-char))))
       (declare (simple-base-string ,buffer))
       (loop for ,character of-type base-char =
                #-swank (code-char (read-byte ,in nil #.(char-code #\Newline)))
                #+swank (read-char ,in nil #\Newline)
             for ,idx from 0
             until (char= ,character #\Newline)
             do (setf (schar ,buffer ,idx) ,character)
             finally (setf (schar ,buffer ,idx) ,terminate-char)
                     (return (values ,buffer ,idx))))))

(defmacro split-ints-bind (vars string &body body)
  (let ((position (gensym))
        (s (gensym)))
    (labels ((expand (vars &optional init-pos)
               (if (null vars)
                   body
                   `((multiple-value-bind (,(car vars) ,position)
                         (parse-integer ,s :start ,(or init-pos position)
                                           :junk-allowed t)
                       ,@(when (null (cdr vars)) `((declare (ignore ,position))))
                       ,@(expand (cdr vars)))))))
      `(let ((,s ,string))
         (declare (string ,s))
         ,@(expand vars 0)))))

(defmacro define-int-types (&rest bits)
  `(progn
     ,@(mapcar (lambda (b) `(deftype ,(intern (format nil "UINT~A" b)) () '(unsigned-byte ,b))) bits)
     ,@(mapcar (lambda (b) `(deftype ,(intern (format nil "INT~A" b)) () '(signed-byte ,b))) bits)))
(define-int-types 2 4 7 8 15 16 31 32 62 63 64)

(defmacro println (obj &optional (stream '*standard-output*))
  `(let ((*read-default-float-format* 'double-float))
     (prog1 (princ ,obj ,stream) (terpri ,stream))))

(defconstant +mod+ 1000000007)

;; Hauptteil

(defun main ()
  (declare #.OPT)
  (let* ((n (read))
         (k (read))
         (seq (make-array n :element-type 'list)))
    (declare (uint32 n k))
    (dotimes (i n)
      (split-ints-bind (a b) (buffered-read-line 15)
        (setf (aref seq i) (cons a b))))
    (setf seq (stable-sort seq #'< :key #'car))
    (loop for (a . b) of-type (uint32 . uint32) across seq
          sum b into cumul of-type fixnum
          while (< cumul k)
          finally (println a))))

#-swank(main)


Measured memory_bytes: 34148
#include<iostream>
#include<string>
#include<cstdio>
#include<algorithm>
#include<vector>
using namespace std;

vector<int>V[1000];
string S[1000];
void DFS(int a, int b) {//??±?????????????????????
	for (int c = 0; c < a; c++)printf(".");
	cout << S[b] << endl;
	for (int c : V[b]) {
		DFS(a + 1, c);
	}
}
signed main() {
	int a; scanf("%d", &a);
	int b; scanf("%d", &b); 
	cin >> S[0];
	for (int d = 1; d < a; d++) {
		scanf("%d", &b); cin >> S[d];
		V[b - 1].push_back(d);
	}
	DFS(0, 0);
}

Measured memory_bytes: 3452
#include<cstdio>
#include<vector>
#include<algorithm>


using namespace std;
using vi=vector<int>;
using pii=pair<int,int>;
using vpii=vector<pii>;


int main(void)
{
	int n, h;

	while(scanf("%d%d", &n, &h)==2)
	{
		vi a(n), b(n);

		for(int i=0;i<n;i++)
		{
			scanf("%d%d", &a[i], &b[i]);
		}
		sort(a.rbegin(), a.rend());
		sort(b.rbegin(), b.rend());

		int ans=0;
		for(int i=0;i<n;i++)
		{
			if(b[i]<a[0]) break;
			ans++;
			h-=b[i];
			if(h<=0) break;
		}
		if(h>0) ans+=(h+a[0]-1)/a[0];

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

	return 0;
}


Measured memory_bytes: 1024
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        String s = sc.next();
        System.out.println(s.charAt(0) == s.charAt(1) && s.charAt(0) == s.charAt(2) ? "No" : "Yes");
    }
}

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

using namespace std;
#define int long long

const int N = 55;
int n, a[N], b[N], c[N];

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

	cin >> n;
	bool found = false;
	int bound = (int)1e3 + 1;
	for (int i = 1; i <= n; ++i) {
		cin >> a[i];
		if (a[i] > bound) found = true;
	}
	
	int res = 0, turn = 0;
	while (found) {
		// for (int i = 1; i <= n; ++i) {
		// 	cerr << a[i] << ' ';
		// }
		turn++;
		// cerr << endl;
		int s = 0;
		for (int i = 1; i <= n; ++i) {
			int ru = (int)ceil(1.0 * (a[i] - bound) / n);
			if (a[i] > bound) b[i] = ru, a[i] = a[i] - n * ru;
			else b[i] = 0;
			s += b[i];
		}
		res += s;
		found = false;
		for (int i = 1; i <= n; ++i) {
			a[i] = a[i] + s - b[i];
			if (a[i] > bound) found = true;
		}
	}
	// for (int i = 1; i <= n; ++i) {
	// 	cerr << a[i] << ' ';
	// }
	// cerr << turn << endl;
	int tmp = (int)1e9;
	for (int t = 0; t <= 1e5; ++t) {
		int new_bound = n - 1 - t;
		int need = 0;
		for (int i = 1; i <= n; ++i) {
			int ru = (int)ceil(1.0 * (a[i] - new_bound) / (n + 1));
			if (a[i] > new_bound) need += ru;
		}
		if (need <= t) tmp = min(tmp, t);
	}
	cout << res + tmp << endl;

	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <math.h>
using namespace std;
int main(void){
    int n;
    cin>>n;
    int h[n];
    for(int i=0;i<n;i++) cin>>h[i];
    int a=0;
    int b=0;
    for(int i=0;i<n-1;i++){
        if(h[i]>=h[i+1]) a++;
        else {
            b=max(a,b);
            a=0;
        }
        if(i==n-2) b=max(a,b);
    }
    cout<<b;
}


Measured memory_bytes: 640
#include<cstdio>
#include<vector>
#include<algorithm>
#include<map>

using namespace std;

using ll=long long;
using vi=vector<int>;
using vvi=vector<vi>;
using pii=pair<int,int>;
using vll=vector<ll>;
using vvll=vector<vll>;
using vpii=vector<pii>;
using vvpii=vector<vpii>;


int main(void)
{
	int n;
	while(scanf("%d", &n)==1)
	{
		vi a(n+1);
		vvpii xy(n+1);
		for(int i=1;i<=n;i++)
		{
			scanf("%d", &a[i]);
			xy[i].resize(a[i]);
			for(int j=0;j<a[i];j++)
			{
				scanf("%d%d", &xy[i][j].first, &xy[i][j].second);
			}
		}

		int ans=0;
		for(int i=(1<<n)-1;i>=0;i--)
		{
			vi is_honest(n+1);
			int hn=0;
			for(int j=1;j<=n;j++)
			{
				if((i>>(j-1))&1)
				{
					is_honest[j]=1;
					hn++;
				}
			}
			if(hn<=ans) continue;

			bool is_good=true;
			for(int j=1;j<=n;j++)
			{
				if(!is_honest[j]) continue;

				for(auto&mxy:xy[j])
				{
					if(is_honest[mxy.first]!=mxy.second)
					{
						is_good=false;
						break;
					}
				}
			}
			if(is_good)
			{
				ans=hn;
			}
		}
		printf("%d\n", ans);
	}
	return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<stdlib.h>
#include<string>
#include<vector>
#include<algorithm>
#include<cmath>
using namespace std;

int main()
{
  int d,t,s;
  
  cin>>d>>t>>s;
  
  if(t*s>=d)
  {
    cout<<"Yes"<<endl;
  }
  else
  {
    cout<<"No"<<endl;
  }
  
  return 0;
}

Measured memory_bytes: 3672
#include<bits/stdc++.h>
using namespace std;
string b;
int q;
int main()
{
    cin>>b;
    for(int i=0;i<b.size();i++)
	{
        if(b[i]=='C')q++;
    	if(q!=0&&b[i]=='F')q-=10000000000;
    }
    if(q<0)cout<<"Yes";
    else cout<<"No";
    return 0;
}

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

int main()
{
	int a, b;
	cin >> a >> b;
	int cnt = a;
	int ans = 1;
	if (b == 1) {
		cout << 0 << endl;
		return 0;
	}
	if (cnt >= b) {
		cout << 1 << endl;
		return 0;
	}
	
	while (cnt < b) {
		cnt = cnt + a - 1;
		ans++;
	}
	cout << ans << endl;
}

Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;

class Program
{
    //static int[] dp;
    //static decimal[,,] dp;
    //static decimal N;
    static void Main(string[] args)
    {
        // 入力
        int[] input = Console.ReadLine().Split().Select(p => int.Parse(p)).ToArray();
        int N = input[0];
        int K = input[1];
        input = Console.ReadLine().Split().Select(p => int.Parse(p)).ToArray();
        int ret = 0;
        
        for(int i=0; i<N; i++)
        {
            if(input[i] >= K)
            {
                ret++;
            }
        }

        Console.WriteLine(ret + "");
    }
}


Measured memory_bytes: 19296
a,b,c=map(int,input().split())
x=0
while a!=b or b!=c or c!=a:
  if a%2==b%2==c%2:
    if min(a,b,c)==a:a+=2
    elif min(a,b,c)==b:b+=2
    else:c+=2
  else:
    if a%2==b%2:
      a+=1
      b+=1
    elif b%2==c%2:
      b+=1
      c+=1
    else:
      c+=1
      a+=1
  x+=1
print(x)

Measured memory_bytes: 3064
unittest
{
	assert( [ "3 4", "2 2 4" ].parse.expand.solve == 6 );
	assert( [ "5 8", "9 9 9 9 9" ].parse.expand.solve == 0 );
	assert( [ "10 10", "3 1 4 1 5 9 2 6 5 3" ].parse.expand.solve == 3296 );
}



import std.conv;
import std.range;
import std.stdio;
import std.typecons;

void main()
{
	stdin.byLineCopy.parse.expand.solve.writeln;
}

auto parse( Range )( Range input )
if( isInputRange!Range && is( ElementType!Range == string ) )
{
	auto ns = input.front.split.to!( long[] );
	input.popFront;
	auto as = input.front.split.to!( long[] );
	return tuple( ns[ 1 ], as );
}

auto solve( long s, long[] as )
{
	const M = 998244353;
	
	// dp[ i番目 ][ 入れたaの合計 ] = パターン数
	auto dp = new ModWorld!M[][]( 1 + as.length, 1 + s );
	dp[ 0 ][ 0 ] = ModWorld!M( 1 );
	foreach( i, a; as )
	{
		foreach( j; 0L .. dp[ i ].length.signed )
		{
			// 入れない
			dp[ i + 1 ][ j ] += dp[ i ][ j ] * 2;		// サブセットのパターンを考慮して2倍にする
			
			// 入れる
			if( j + a < dp[ i ].length )
			{
				dp[ i + 1 ][ j + a ] += dp[ i ][ j ];		// サブセットに含まれていないとこのパターンが成立しないので2倍にしない
			}
		}
	}
	return dp[ $ - 1 ][ $ - 1 ];
}

// モジュラ整数型（n mod M）
struct ModWorld( long M )
{
	long n;
	
	void opUnary( string OP )() if( OP == "++" ){ this.n = ( this.n + 1 ) % M; }
	void opUnary( string OP )() if( OP == "--" ){ this.n = ( this.n + M - 1 ) % M; }
	void opOpAssign( string OP )( ModWorld r ) if( OP == "+"  ){ this.n = ( this.n + r.n ) % M; }
	void opOpAssign( string OP )( ModWorld r ) if( OP == "-"  ){ this.n = ( this.n + M - r.n ) % M; }
	void opOpAssign( string OP )( ModWorld r ) if( OP == "*"  ){ this.n = ( this.n * r.n ) % M; }
	void opOpAssign( string OP )( ModWorld r ) if( OP == "/"  ){ this *= r ^^ ModWorld( M - 2 ); }
	void opOpAssign( string OP )( ModWorld r ) if( OP == "^^" )
	{
		auto a = this.n;
		this.n = 1L;
		for( auto i = r.n; 0 < i; i >>= 1 )
		{
			if( i & 1 ) this.n = ( this.n * a ) % M;
			a = ( a * a ) % M;
		}
	}
	auto opBinary( string OP )( ModWorld r ){ auto l = this; l.opOpAssign!OP( r ); return l; }
	
	void opAssign( long r ){ this.n = r; }
	void opOpAssign( string OP )( long r ){ this.opOpAssign!OP( ModWorld( r ) ); }
	auto opBinary( string OP )( long r ){ return this.opBinary!OP( ModWorld( r ) ); }
	auto opBinaryRight( string OP )( long l ){ return ModWorld( l ).opBinary!OP( this ); }
	auto opEquals( long r ){ return this.n == r; }
	
	auto toString(){ return this.n.to!string; }
}


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

#if __has_include("print.hpp")
  #include "print.hpp"
#endif

#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define ALL(x) (x).begin(), (x).end()
#define RALL(x) (x).rbegin(), (x).rend()
#define MOD 1000000007

typedef long long ll;

struct mint {
  ll x;
  mint(ll x=0):x(x%MOD){}
  mint& operator+=(const mint a) {
    if ((x += a.x) >= MOD) x -= MOD;
    return *this;
  }
  mint& operator-=(const mint a) {
    if ((x += MOD-a.x) >= MOD) x -= MOD;
    return *this;
  }
  mint& operator*=(const mint a) {
    (x *= a.x) %= MOD;
    return *this;
  }
  mint operator+(const mint a) const {
    mint res(*this);
    return res+=a;
  }
  mint operator-(const mint a) const {
    mint res(*this);
    return res-=a;
  }
  mint operator*(const mint a) const {
    mint res(*this);
    return res*=a;
  }
};


typedef pair<mint, mint> p;

int main(){
  ios::sync_with_stdio(false);
  cin.tie(0);
  ll n, k;
  cin >> n >> k;
  vector<ll> v(n);
  mint res = 0;
  for (int i = 0; i < n; i++) {
    cin >> v[i];
  }

  map<ll, p> mp;
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < i; j++) {
      if(v[i] > v[j]) mp[i].first.x++;
    }
    for (int j = i + 1; j < n; j++) {
      if(v[i] > v[j]) mp[i].second.x++;
    }
  }
  // ll a = 1000000001ll * 1000000000ll;
  // cout << a << endl;

  for(auto a : mp){
    mint tmp = (a.second.second) * (((1ll + k) * k) / 2ll);
    res += tmp;
    tmp = (a.second.first) * (((-1ll + k) * k) / 2ll);
    res += tmp;
  }


  cout << res.x << endl;
}


Measured memory_bytes: 384
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define ll long long
int n;
int a[400010],b[400010],c[400010],tot=1;
int cnt[400010],num[400010];
map<int,int> m;
signed main(){
    cin>>n;
    for(int i=1;i<=n;i++)scanf("%d",a+i),b[i]=i-a[i],c[i]=i+a[i];
    for(int i=n;i>=1;i--){
        if(m.count(b[i])==1)cnt[m[b[i]]]+=num[m[b[i]]];
        if(m.count(c[i])==0)m[c[i]]=tot++;
        num[m[c[i]]]++;
    }
    ll ans=0;
    for(int i=0;i<tot;i++){
        ans+=cnt[i];
    }
    m.clear();
    tot=1;
    memset(cnt,0,sizeof(cnt));
    memset(num,0,sizeof(num));
    for(int i=1;i<=n;i++){
        if(m.count(b[i])==1)cnt[m[b[i]]]+=num[m[b[i]]];
        if(m.count(c[i])==0)m[c[i]]=tot++;
        num[m[c[i]]]++;
    }
    for(int i=0;i<tot;i++){
        ans+=cnt[i];
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 27048
#pragma GCC optimize ("-O3")
#ifdef LOCAL
  #include "helper_funcs.hpp"
#else
  #include <bits/stdc++.h>
#endif
// #include <ext/pb_ds/assoc_container.hpp>
using namespace std;
// using namespace __gnu_pbds;
#define frn(i,a,b) for(ll i=a;i<b;i++)
#define rfrn(i,a,b) for(ll i=a;i>b;--i)
#define forn(i,a,b) for(ll i=a;i<=b;i++)
#define rforn(i,a,b) for(ll i=a;i>=b;--i)
#define sqfrn(i,a,b) for(ll i=a;i*i<b;i++)
#define sqforn(i,a,b) for(ll i=a;i*i<=b;i++)
#define frt(it,v) for(auto &it:v)
#define MP make_pair
#define F first
#define S second
#define PB push_back
#define SQR(a) (a)*(a)
#define SUM(n) ((n)*(n+1))/2
// #define SqSUM(n) ((n)*(n+1)*(2*n+1))/2
// #define GMSUM(a,r,n) (a*pow(r,n)-a)/(r-1)
#define ciel(x, y) (((x) / (y)) + ((x) % (y) != 0))
#define input(v,a,b) for(ll i = a ; i<b ; i++) cin>>v[i]
#define output(v,a,b) cout<<"["<<#v<<"]: "; for(ll i = a ; i<b ; i++) cout<<v[i]<<" "; cout<<ln
#define cout_p(x, p) cout << fixed << setprecision((p)) << x
#define dbg(x) cerr << #x << "is" << (x) << endl
#define leadzero(a) __builtin_clz(a)      // count leading zeroes
#define trailzero(a) __builtin_ctz(a)     // count trailing zeroes
#define bitcount(a) __builtin_popcount(a) // count set bits (add ll)
#define ln "\n"
const long long int md = 998244353;
typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> pi;
typedef vector<ll> v1;
typedef vector<vector<ll > > vv2;
#define M 32
#ifndef M_PI
  #define M_PI 3.14159265358979323846
#endif
typedef bitset<M> btst;
typedef priority_queue<int, vector<int>, greater<int>> min_heap;
typedef priority_queue<int, vector<int>> max_heap;
// typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update>
//     indexed_set;
const ll MAX = LONG_MAX;
const ll lrg = 1000000007;

void solve()
{
	ll n;
	cin>>n;
	ll x[n], y[n];
	for(int i=0;i<n;i++)
	{
		cin>>x[i]>>y[i];
	}
	ll mx1=-LONG_MAX, mx2=-LONG_MAX, mn1=LONG_MAX, mn2=LONG_MAX;
	for(int i=0;i<n;i++)
	{
		mx1=max(mx1, x[i]+y[i]);
		mx2=max(mx2, x[i]-y[i]);
		mn1=min(mn1, x[i]+y[i]);
		mn2=min(mn2, x[i]-y[i]);
	}
	cout<<max(mx1-mn1, mx2-mn2);
}

int main()
{
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  int t=1,cp;
  // cin>>t;
  cp=t;
  while(t--){
   // cout<<"Case #"<<cp-t<<": ";
   solve();
   cout<<"\n";
  }
  return 0;
}

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

typedef long long ll;
typedef long double ld;
typedef pair<int, int> ii;
typedef pair<int, ii> iii;
typedef pair<ii, int> ri3;
#define mp make_pair
#define pb push_back
#define fi first
#define sc second
#define SZ(x) (int)(x).size()
#define ALL(x) begin(x), end(x) 
#define REP(i, n) for (int i = 0; i < n; ++i) 
#define FOR(i, a, b) for (int i = a; i <= b; ++i)
#define RFOR(i, a, b) for (int i = a; i >= b; --i)

const int MX_N = 1e5+5;

int N, M;
int A[MX_N], o[MX_N], vis[MX_N], used[MX_N];
vector<int> al[MX_N];
ll ans = 0;

int dfs(int u) {
    vis[u] = 1;
    int x = u;
    for (int v : al[u]) if (!vis[v]) {
        int y = dfs(v);
        if (A[y] < A[x]) x = y;
    }
    return x;
}

int main() {
    //freopen("in.txt", "r", stdin);
    ios::sync_with_stdio(false);
    cin.tie(0);

    cin >> N >> M;
    FOR(i,0,N-1){
        cin >> A[i];
        o[i] = i;
    }

    if (M+1 < (N+1)/2) { cout << "Impossible"; return 0; }
    if (M == N-1) { cout << 0; return 0; }

    FOR(i,0,M-1){
        int x, y; cin >> x >> y;
        al[x].push_back(y);
        al[y].push_back(x);
    }

    int cnt = 2*M;
    FOR(i,0,N-1) if (!vis[i]) {
        int x = dfs(i);
        used[x] = 1;
        ans += A[x];
        ++cnt;
    }

    sort(o,o+N,[](int a, int b) { return A[a] < A[b]; });

    FOR(i,0,N-1) if (!used[o[i]]) {
        if (cnt == 2*(N-1)) break;
        ans += A[o[i]];
        ++cnt;
    }
    cout << ans;
}



Measured memory_bytes: 7168
#include<iostream>
using namespace std;
int main() {
	char b, c[128];
	c['A'] = 'T';
	c['G'] = 'C';
	c['C'] = 'G';
	c['T'] = 'A';
	cin >> b;
	cout << c[(int)b] << endl;
	return 0;
}

Measured memory_bytes: 256
#define _CRT_SECURE_NO_WARNINGS
#include<iostream>
#include<sstream>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<climits>
#include<cmath>
#include<string>
#include<vector>
#include<set>
#include<map>
#include<queue>
#include<numeric>
#include<functional>
#include<algorithm>
#include<bitset>
#include<tuple>
#include<unordered_set>
#include<unordered_map>
#include<random>
#include<array>
#include<cassert>
using namespace std;
#define INF (1<<29)
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define all(v) v.begin(),v.end()
#define uniq(v) v.erase(unique(all(v)),v.end())





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

	int n;
	int a[110], b[110];
	cin >> n;
	rep(i, n - 1)cin >> b[i];

	rep(i, n)a[i] = INF;

	rep(i, n-1) {
		a[i] = min(a[i], b[i]);
		a[i + 1] = min(a[i + 1], b[i]);
	}

	int ans = 0;
	rep(i, n)ans += a[i];

	cout << ans << endl;


	return 0;
}

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

namespace AtCoders {
	class Program {
		static void Main(string[] args) {
			
  			var inputArray = retreiveLongArray();
			var inputCount = 1;

			// 不正な入力は処理しない
			if (inputArray.Length != inputCount) {
				Console.WriteLine("invalid input");
				return;
			}

			var N = inputArray[0];

			var numArray = retreiveLongArray();
			
			//Keyと、登場回数
			var dictionary = new Dictionary<long, int>();

			foreach (var n in numArray) {
				if (dictionary.ContainsKey(n)) {
					dictionary[n] += 1;
				}
				else {
					dictionary.Add(n, 1);
				}
			}

			//答えの出力
			if (dictionary.All(x => x.Value == 1)) {
				Console.WriteLine("YES");
			}
			else {

			
				Console.WriteLine("NO");
			}




		}

		/// <summary>
		/// スペースで区切られた文字列配列の入力を受け取る
		/// </summary>
		/// <returns></returns>
		private static string[] retreiveStringArray() {
			var inputArray =  Console.ReadLine().Split(' ');
			return inputArray;
		}

		/// <summary>
		/// スペースで区切られた整数配列の入力を受け取る
		/// </summary>
		/// <returns></returns>
		private static long[] retreiveLongArray() {
			var inputArray = Console.ReadLine().Split(' ');
			var longArray = inputArray.Select(s => long.Parse(s));
			return longArray.ToArray();
		}
	}
}


Measured memory_bytes: 52788
#include<stdio.h>
#include<iostream>

using namespace std;

int main()
{
	int N,M[9999],big,ans=1;
	cin >> N;
	for (int i = 0; i < N; i++) cin >> M[i];
	big = M[0];
	//カウント
	for (int i = 1; i < N; i++)
	{
		if (M[i] >= big){
			ans++;
			big = M[i];
		}
	}
	cout << ans << endl;
}

Measured memory_bytes: 256
import sys
def input(): return sys.stdin.readline().strip()
def mapint(): return map(int, input().split())
sys.setrecursionlimit(10**9)

N = int(input())
Xs = [int(input()) for _ in range(N)]

last = 0
ans = 0
for i in range(1, N+1):
    cnt = Xs[i-1]
    if cnt<=last:
        ans += cnt
        last = 0
    else:
        ans += last
        cnt -= last
        ans += cnt//2
        last = cnt%2
print(ans)

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

using namespace std;
typedef vector<int> VI;
typedef long long LL;
typedef pair<int,int> PI; 
typedef pair<LL,LL> PLL;
typedef unsigned long long ULL;

#define IOSWORK ios::sync_with_stdio(0); cin.tie(0)
#define FOR(x, b, e) for(int x = b; x<= (e); x++)
#define FORD(x, b, e) for(int x = b; x>= (e); x--)
#define REP(x, n) for(int x = 0; x<(n); ++x)
#define ALL(c) (c).begin(), (c).end()
#define SIZE(x) ((int)(x).size())
#define VAR(v, n) typeof(n) v = (n)
#define FOREACH(i, c) for(VAR(i, (c).begin()); i != (c).end(); ++i)

#define SCAN_INT(n) scanf("%i",&n)
#define SCAN_P_INT(n,m) scanf("%i %i",&n,&m)
#define PRINT_P_INT(n,m) printf("%i %i\n",n,m);
#define PRINT_INT(n) printf("%i\n",n)


#define PB push_back
#define IN insert
#define ST first
#define ND second
#define INF 2000000007


#define MAXSIZE 100100

int liczby[MAXSIZE];
int n;
int wynik=0;
int main(){
	
	SCAN_INT(n);
	REP(i,n)
		SCAN_INT(liczby[i]);
	sort(liczby,liczby+n);
	
	int ostatni=0;
	int wystapienia=0;
	
	REP(i,n){
		if(liczby[i]!=ostatni){
			if(wystapienia<ostatni)
				wynik+=wystapienia;
			else
				wynik+=wystapienia-ostatni;
			
			ostatni=liczby[i];
			wystapienia=1;
		}
		else
			wystapienia++;
	}
	
	if(wystapienia<ostatni)
		wynik+=wystapienia;
	else
		wynik+=wystapienia-ostatni;
		
	PRINT_INT(wynik);
	
	return 0;
}


Measured memory_bytes: 640
h, w = map(int, input().split())
grid = []
for _ in range(h):
    grid.append(input())

grid = [i for i in grid if i.count('#')>0]
c = []
for j in range(w):
    for i in range(len(grid)):
        if grid[i][j]=='#':
            break
    else:
        c.append(j)
for row in grid:
    tmp = ''
    s = 0
    for i in c:
        tmp += row[s:i]
        s = i+1
    tmp += row[s:]
    print(tmp)



Measured memory_bytes: 3064
#include <stdio.h>

int main(void)
{
    int n;
    scanf("%d", &n);
    int v[n];
    for (int i = 0; i < n; i++)
    {
        scanf("%d", &v[i]);
    }
    for (int i = 0; i < n; i++)
    {
        for (int j = 0; j < n - 1; j++)
        {
            if (v[j] > v[j + 1])
            {
                int tmp = v[j + 1];
                v[j + 1] = v[j];
                v[j] = tmp;
            }
        }
    }
    float set = 0;
    set = (v[0] + v[1]);
    set = set / 2;
    for (int i = 2; i < n; i++)
    {
        set = (set + v[i]) / 2;
    }
    printf("%f\n", set);
    return 0;
}


Measured memory_bytes: 128
#include<bits/stdc++.h>
#include<cmath>
#define SZ(x) ((int)x.size())
#include<vector>
#include<set>
#include<map>
#define ll long long
#define lli long long int
#define REP(i,a,b) for(ll i=a;i<b;i++)
#define pb push_back
#include<string>
#include<cctype>
#include<queue>
#define ii pair<int,int>
#include <sstream>
#define lli long long int
#define pairs pair<int,int>
#define mod 1000000007
const double PI = 3.141592653589793238460;
typedef std::complex<double> Complex;
typedef std::valarray<Complex> CArray;
using namespace std;
ll pows(ll a,ll n,ll m)
{
	ll res=1;
	while(n)
	{
	if(n%2!=0)
	{
		res=(res*a)%m;
		n--;
		}
		else
		{
			a=(a*a)%m;
			n=n/2;
			}	
	}
	return res%m;
}
ll  gcd(ll a,ll b)
{
	if(b==0)
	return a;
	else 
	return gcd(b,a%b);
}
bool isprime(ll n)
{
	if(n==1)
	{
		return false;
	}
	for(ll i=2;i*i<=n;i++)
	{
		if(n%i==0)
		{
			return false;
		}
	}
	return true;
}
bool istrue(string s)
{
	int i=0;
	int j=s.size()-1;
	while(i<j)
	{
	if(s[i]==s[j])
	{
		i++;
		j--;
		}
		else
		{
			return false;
			}	
	}
	return true;
}
int n;
int a[100001];
int dp[100001];
int getans(int i)
{
if(i>=n-1)
{
	return 0;
	}
	if(dp[i]!=-1)
	{
		return dp[i];
	}
	int ans=mod;
	if(i+1<=n-1)
	{
		ans=min(ans,getans(i+1)+abs(a[i]-a[i+1]));
	}
	if(i+2<=n-1)
	{
		ans=min(ans,getans(i+2)+abs(a[i]-a[i+2]));
	}
return dp[i]=ans;
}
int main()
{
ios::sync_with_stdio(false);
	 cin.tie(0);
    cout.tie(0);
cin>>n;
for(int i=0;i<n;i++)
{
	cin>>a[i];
}
for(int i=0;i<=n;i++)
{
	dp[i]=-1;
}
cout<<getans(0)<<endl;
}




Measured memory_bytes: 9068
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
ll MOD = 1000000007;
ll INFL = 1ll << 60;
ll INF = 1 << 30;
int dx[8] = {0, 1, 1, 1, 0, -1, -1, -1};
int dy[8] = {1, 1, 0, -1, -1, -1, 0, 1};

struct edge {
  ll from, to, cost;
};
edge es[2020];
ll n, m;
ll d[1020];
ll issyu;

void longest_path(int s) {
  for (int i = 0; i <= n; i++)
    d[i] = -1 * INFL;
  d[1] = 0;

  for (int k = 0; k <= 2 * n; k++) {  // N回以上→閉路があるのでは？
    for (int i = 0; i < m; i++) {
      edge e = es[i];
      // cout << d[e.from] << " " << d[e.to] << " " << e.cost << endl;
      if (d[e.from] != -1 * INFL) {
        // cout << "kousin" << endl;
        d[e.to] = max(d[e.to], d[e.from] + e.cost);
      }
    }

    // cout << d[n] << endl;
    if (k == n)
      issyu = d[n];
  }
}

int main() {
  cin >> n >> m;
  ll a, b, c;
  for (int i = 0; i < m; i++) {
    cin >> es[i].from >> es[i].to >> es[i].cost;
  }

  longest_path(0);

  if (issyu < d[n]) {  //更新されていた（閉路があった）
    cout << "inf" << endl;
    // cout << issyu << " " << d[n] << endl;
    return 0;
  }
  cout << issyu << endl;
}


Measured memory_bytes: 256
K,A,B = map(int, open(0).read().split())
if B - A <= 1:
    print(K+1)
else:
    if K < A + 1:
        print(K+1)
    else:
        dm = divmod(K-A-1,2)
        print((dm[0]*(B-A)+B+dm[1]))

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

using namespace std;
#define all(a)a.begin(),a.end()
using ll=long long;
const int INF = 1<<30;
const ll INFll =1LL<<62;
const int mod =(1e9)+7;
using P = pair<ll,ll>;

int main(){
    ll n;cin >>n;
    vector<P>p;
    for (int i = 1; i < n+1; ++i) {
        for (int j = i+1; j < n + 1; ++j) {
            if(i+j==n/2*2+1)continue;
            p.push_back(P(i,j));
        }
    }
    cout <<p.size()<<endl;
    for(auto u:p){
        cout <<u.first<< " "<<u.second<<endl;
    }
    return 0;
}

Measured memory_bytes: 512
#include<bits/stdc++.h>
using namespace std;
const int N=3005;
int n,now,a[N],v[N],nex[N],head[N];
void addedges(int x,int y){
	nex[++now]=head[x];
	head[x]=now,v[now]=y;
}
bool dfs(int x){
	int f=0;
	for(int i=head[x];i;i=nex[i])
		if(!dfs(v[i]))	f=1;
	return f;
}
int main(){
	scanf("%d",&n);
	for(int i=1;i<=n;i++)	scanf("%d",&a[i]);
	for(int i=1;i<n;i++){
		int x,y;
		scanf("%d%d",&x,&y);
		if(a[x]<a[y])	swap(x,y);
		if(a[x]==a[y])	continue;
		addedges(x,y);
	}
	for(int i=1;i<=n;i++)
		if(dfs(i))	printf("%d ",i);
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
 
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

using namespace std;
using namespace __gnu_pbds;

template<class T> using ordered_set = tree<T,null_type,less<T>,rb_tree_tag,tree_order_statistics_node_update>;
template<class T> using ordered_multiset = tree<T,null_type,less_equal<T>,rb_tree_tag,tree_order_statistics_node_update>;

typedef long long  ll;
typedef unsigned long long  ull;
typedef long double ld;
#define lp(i,n)      for(int i=0;i<n;i++)
#define lpi(i,j,n)   for(int i=j;i<n;i++)
#define lpd(i,j,n)   for(int i=j;i>=n;i--)
#define MP           make_pair
#define clr(v, d)    (memset(v, d, sizeof(v)))
#define all(v)     (v.begin()),(v.end())
#define N 100006
const double pi = acos(-1);

ll n,t,m,k;

ll ans;
ll mod = 1e9 +7;
bool marked[305][305][305];
ld dp[305][305][305];
ld solve(int ones ,int twos, int threes){
  if(marked[ones][twos][threes])return dp[ones][twos][threes];
  int tot =(ones+twos+threes);
  if(tot == 0)return 0;
  marked[ones][twos][threes]=1;
  ld& ret =dp[ones][twos][threes];
  ret =0;
  
  ret = (ld)n/tot;
  if(ones)ret  += (ld)ones/tot*solve(ones-1,twos,threes);
  if(twos)ret  += (ld)twos/tot*solve(ones+1,twos-1,threes);
  if(threes)ret += (ld)threes/tot*solve(ones,twos+1,threes-1);
  return ret;

}

int main() {
 
ios_base::sync_with_stdio(0);
cin.tie(0);cout.tie(0);
// freopen("e.txt","r",stdin); 
// freopen("e_out.txt","w",stdout); 
cout.precision(10);
cin>>n;
int cnt[3]={0,0,0};
lp(i,n){
  int x;
  cin>>x;
  cnt[x-1]++;
}
cout<<fixed<<solve(cnt[0],cnt[1],cnt[2]);








  
}
  
 



// bool isPrime(ll h){
//      for(ll i=0;primes[i]*primes[i]<= h;i++)
//      if (h%primes[i]==0)
//      	return 0;
//      return h!=1;
//  }
 bool isPrime(ll g){
   if((g%2==0 && g>2) || g==1)return 0;
   for(ll i=3;i*i<=g;i+=2)if(g%i==0)return 0;
   return 1;   
 
 }

Measured memory_bytes: 230816
import java.io.*;
import java.util.*;
import java.util.function.*;

class Cost<T> {
	int cost;
	T thing;

	Cost(int cost, T thing) {
		this.cost = cost;
		this.thing = thing;
	}
}

class Pair {
	int x, y;

	Pair(int x, int y) {
		this.x = x;
		this.y = y;
	}
}

final class Solver {
	static final Solver INSTANCE = new Solver();

	void solve(Supplier<String> sc) {
		int H = Integer.parseInt(sc.get());
		int W = Integer.parseInt(sc.get());
		
		Queue<Cost<Pair>> queue = new ArrayDeque<>();

		BitSet[] black = new BitSet[H];
		Arrays.setAll(black, $ -> new BitSet(W));
		for (int i = 0; i < H; i++) {
			char[] data = sc.get().toCharArray();
			for (int j = 0; j < W; j++) {
				if (data[j] == '#') {
					black[i].set(j);
					queue.add(new Cost<>(0, new Pair(j, i)));
				}
			}
		}

		int[] vx = {1, 0, -1, 0};
		int[] vy = {0, 1, 0, -1};

		int max = 0;

		while (!queue.isEmpty()) {
			Cost<Pair> next = queue.remove();
			max = Math.max(max, next.cost);
			for (int i = 0; i < 4; i++) {
				int x = next.thing.x + vx[i];
				int y = next.thing.y + vy[i];
				if (x < 0 || x >= W || y < 0 || y >= H) continue;
				Pair pair = new Pair(x, y);
				if (black[y].get(x)) continue;
				queue.add(new Cost<>(next.cost + 1, pair));
				black[y].set(x);
			}
		}

		System.out.println(max);
	}
}

class Main {
	public static void main(String... args) {
		BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
		Solver.INSTANCE.solve(new Supplier<String>() {
			StringTokenizer line;

			public String get() {
				try {
					return (line = line != null && line.hasMoreTokens() ? line : new StringTokenizer(reader.readLine())).nextToken();
				} catch (IOException e) {
					throw new UncheckedIOException(e);
				}
			}
		});
	}
}


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

#define REP(i, x, n) for (int i = x; i < (int)(n); i++)
#define rep(i, n) REP(i, 0, n)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define sz(x) (int)(x.size())
#define popcount(x) __builtin_popcount(x)
#define popcountll(x) __builtin_popcountll(x)
#define uniq(x) x.erase(unique(x.begin(), x.end()), x.end())
#define F first
#define S second
#define mp make_pair
#define eb emplace_back
#define pii pair<int, int>
#define pll pair<ll, ll>

using namespace std;

typedef long long ll;

/* --- INFやMODの値が適切か確認する --- */
// const int INF = 1 << 30;
// const ll INF = 1LL << 60;
// const ll MOD = 1000000007;

class MaximumFlow {
 private:
  static const int INF = 1 << 29;

  class Edge {
   public:
    int to, cap, rev;
    Edge() {}
    Edge(int t, int c, int r) { to = t, cap = c, rev = r; }
  };

  int vertexSize;
  vector<int> level;  // sからの距離
  vector<int> iter;   // どこまで調べ終わったか
  vector<vector<Edge>> edge;

  void bfs(int s) {
    level = vector<int>(vertexSize, -1);
    queue<int> Q;
    level[s] = 0;
    // Q.emplace(s);
    Q.push(s);
    while (!Q.empty()) {
      int v = Q.front();
      Q.pop();
      for (int i = 0; i < (int)(edge[v].size()); i++) {
        Edge &e = edge[v][i];
        if (e.cap > 0 && level[e.to] < 0) {
          level[e.to] = level[v] + 1;
          // Q.emplace(e.to);
          Q.push(e.to);
        }
      }
    }
  }

  int dfs(int v, int t, int f) {
    if (v == t) return f;
    for (int &i = iter[v]; i < (int)(edge[v].size()); i++) {
      Edge &e = edge[v][i];
      if (e.cap > 0 && level[v] < level[e.to]) {
        int d = dfs(e.to, t, min(f, e.cap));
        if (d > 0) {
          e.cap -= d;
          edge[e.to][e.rev].cap += d;
          return d;
        }
      }
    }
    return 0;
  }

 public:
  MaximumFlow(int vs) {
    vertexSize = vs;
    level = vector<int>(vs);
    iter = vector<int>(vs);
    edge = vector<vector<Edge>>(vs);
  }

  void addEdge(int from, int to, int cap) {
    edge[from].emplace_back(Edge(to, cap, edge[to].size()));
    edge[to].emplace_back(Edge(from, 0, edge[from].size() - 1));
  }

  int getMaximumFlow(int s, int t) {
    int flow = 0;
    while (1) {
      bfs(s);
      if (level[t] < 0) break;
      iter = vector<int>(vertexSize, 0);
      int f;
      while ((f = dfs(s, t, INF)) > 0) {
        flow += f;
      }
    }
    return flow;
  }
};

int main() {
  int n;
  cin >> n;
  vector<int> x(2 * n), y(2 * n);
  rep(i, 2 * n) cin >> x[i] >> y[i];

  MaximumFlow mf(2 * n + 2);
  rep(i, n) mf.addEdge(0, i + 1, 1);
  rep(i, n) mf.addEdge(n + i + 1, 2 * n + 1, 1);

  rep(i, n) rep(j, n) {
    if (x[i] < x[n + j] && y[i] < y[n + j]) {
      mf.addEdge(i + 1, n + j + 1, 1);
    }
  }

  cout << mf.getMaximumFlow(0, 2 * n + 1) << endl;
}


Measured memory_bytes: 384