akhauriyash/Code-Regression huggingface dataset:
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <deque>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>

using namespace std;

typedef long long ll;

#define MOD 1000000007

int main() {
  int v[] = {1, 1, 1, 2, 1, 2, 1, 5,  2, 2, 1, 5, 1, 2, 1, 14,
             1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51};
  int k;
  cin >> k;
  cout << v[k - 1] << endl;
  return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
int main()
{
	int num;
	scanf("%d",&num);
	if(((num / 100) == 7) || (((num % 100) / 10) == 7) || ((num % 10) == 7)){
		printf("Yes\n");
	}
	else{
		printf("No\n");
	}
    return 0;
}


Measured memory_bytes: 1624
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <time.h>
#include <math.h>
#include <vector>
#include <queue>
#include <map>
#include <set>
#include <algorithm>
#include <iterator>
#include <sstream>
#include <string>
#include <bitset>
using namespace std;
#define FOR(I,F,N) for(int I = F; I < (int)(N); I++)
#define rep(i, n) FOR(i, 0, n)
#define FIN(V) cout<<V<<endl
#define pb push_back
#define INF (1 << 30)
typedef pair<int, int> P;
typedef long long ll;
typedef priority_queue<int> pq;
int StrToInt(string);
string IntToStr(int);
int dx[4] = {1, -1, 0, 0};
int dy[4] = {0, 0, 1, -1};

int main(void){
	int n, m;
	cin >> n >> m;
	vector<int> v;
	rep(i,m){
		int a;
		cin >> a;
		v.pb(a);
	}
	int dp[n+1];
	fill_n(dp, n+1, INF);

	dp[0] = 0;
	rep(i, n+1){
		rep(j, v.size()){
			if(i-v[j] >= 0)
				dp[i] = min(dp[i-v[j]]+1, dp[i]);
		}
	}
	FIN(dp[n]);

	return 0;
}

Measured memory_bytes: 1412
#define _USE_MATH_DEFINES

#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <cmath>
#include <cstring>
#include <algorithm>
#include <vector>
#include <queue>
#include <map>
#include <set>
#include <unordered_map> 
#include <unordered_set>
#include <functional>

using namespace std;

typedef pair<long long int, long long int> P;
typedef tuple<int, int, int> T;

long long int INF = 1e18;
long long int MOD = 1e9 + 7;

#define MAX_V 200000

struct edge{
	int to;
	long long int cost;
    edge(int to_, long long int cost_){
        to = to_;
        cost = cost_;
    }
};

vector<edge> G[MAX_V];
long long int d[MAX_V];

// O(ElogV)

void shortest_path(int s, int V){
	
	priority_queue<P, vector<P>, greater<P> > que;
	
	for(int i = 0; i < V; i++){
		d[i] = INF;
	}
	d[s] = 0;
	
	que.push(P(0, s));
	
	while(!que.empty()){
		
		P p = que.top();
		que.pop();
		
		int v = p.second;
		
		if(d[v] < p.first){
			continue;
		}
		
		for(int i = 0; i < G[v].size(); i++){
			edge e = G[v][i];
			if(d[e.to] > e.cost + d[v]){
				d[e.to] = d[v] + e.cost;
				que.push(P(d[e.to], e.to));
			}
		}
	}
}

int main(){
	while(true){
		int w, h;
		cin >> w >> h;
		if(w == 0){
			break;
		}
		int s[32][32];
		for(int i = 0; i < h; i++){
			for(int j = 0; j < w; j++){
				cin >> s[i][j];
			}
		}
		int c_[4];
		cin >> c_[0] >> c_[1] >> c_[2] >> c_[3];
		int CON = (w + 1) * (h + 1);
		for(int i = 0; i < h; i++){
			for(int j = 0; j < w; j++){
				int p00 = i * (w + 1) + j;
				int p01 = i * (w + 1) + j + CON;
				int p10 = i * (w + 1) + j + CON * 2;
				int p11 = i * (w + 1) + j + CON * 3;
				int p20 = (i + 1) * (w + 1) + j;
				int p21 = (i + 1) * (w + 1) + j + CON;
				int p30 = i * (w + 1) + j + 1 + CON * 2;
				int p31 = i * (w + 1) + j + 1 + CON * 3;
				int c[5];
				for(int k = 0; k < 4; k++){
					c[k] = c_[k];
				}
				c[s[i][j]] = 0;
				G[p01].emplace_back(p21, c[0]);
				G[p11].emplace_back(p31, c[0]);
				G[p20].emplace_back(p00, c[0]);
				G[p30].emplace_back(p10, c[0]);
				G[p01].emplace_back(p10, c[1]);
				G[p11].emplace_back(p21, c[1]);
				G[p20].emplace_back(p31, c[1]);
				G[p30].emplace_back(p00, c[1]);
				G[p01].emplace_back(p00, c[2]);
				G[p11].emplace_back(p10, c[2]);
				G[p20].emplace_back(p21, c[2]);
				G[p30].emplace_back(p31, c[2]);
				G[p01].emplace_back(p31, c[3]);
				G[p11].emplace_back(p00, c[3]);
				G[p20].emplace_back(p10, c[3]);
				G[p30].emplace_back(p21, c[3]);
			}
		}
		shortest_path(CON * 3, CON * 4);
		/*
		for(int i = 0; i < 4; i++){
			for(int j = 0; j < h + 1; j++){
				for(int k = 0; k < w + 1; k++){
					cout << d[j * (w + 1) + k + CON * i] << " ";
				}cout << endl;
			}cout << endl;
		}
		*/
		int pos = (h - 1) * (w + 1) + w - 1;
		cout << min(d[pos + CON], d[pos + CON * 3]) << endl;
		for(int i = 0; i < CON * 4; i++){
			G[i].clear();
		}
	}
	return 0;
}


Measured memory_bytes: 8228
a = []
a.append(list(map(int, input().split())))
a.append(list(map(int, input().split())))
a.append(list(map(int, input().split())))
n = int(input())

for _ in range(n):
    b = int(input())
    for i in range(3):
        for j in range(3):
            if b == a[i][j]:
                a[i][j] = 0

# print(a)
if (a[0][0] == 0 and a[0][1] == 0 and a[0][2] == 0) or \
        (a[1][0] == 0 and a[1][1] == 0 and a[1][2] == 0) or \
        (a[2][0] == 0 and a[2][1] == 0 and a[2][2] == 0) or \
        (a[0][0] == 0 and a[1][0] == 0 and a[2][0] == 0) or \
        (a[0][1] == 0 and a[1][1] == 0 and a[2][1] == 0) or \
        (a[0][2] == 0 and a[1][2] == 0 and a[2][2] == 0) or \
        (a[0][0] == 0 and a[1][1] == 0 and a[2][2] == 0) or \
        (a[0][2] == 0 and a[1][1] == 0 and a[2][0] == 0):
    print('Yes')
else:
    print('No')


Measured memory_bytes: 3064
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace AthleteProgramming
{
    class Program
    {
        static void Main()
        {
            string str;
            int n;
            while (true)
            {
                str = Console.ReadLine();
                if (str == null)
                {
                    break;
                }
                n = int.Parse(str);

                if (n >= 37)
                {
                    Console.WriteLine("0");
                    continue;
                }

                Count(n);

            }
        }

        static void Count(int n)
        {
            int count = 0;

            for(int a = 0; a <= 9; a++)
            {
                for(int b = 0; b <= 9; b++)
                {
                    for(int c = 0; c <= 9; c++)
                    {
                        for(int d = 0; d <= 9; d++)
                        {
                            if (n == a + b + c + d)
                            {
                                count++;
                            }
                        }
                    }
                }
            }
            Console.WriteLine(count);
        }

    }
}

Measured memory_bytes: 8996
import std.stdio;
import std.conv;
import std.string;
import std.algorithm;

struct BC { long b, c; }

void main() {
	long n, m;
	scanf("%ld %ld\n", &n, &m);
	auto a = readln.chomp.split.to!(long[]);
	auto bc = new BC[m];
	foreach(i; 0..m) {
		long b, c;
		scanf("%ld %ld\n", &b, &c);
		bc[i] = BC(b,c);
	}
	bc.sort!((x, y) => x.c > y.c);
	a.sort!"a<b";
	size_t bc_i, a_i;
	long cnt;
	while(a_i < a.length) {
		if (bc_i < bc.length) {
			for(size_t j; j < bc[bc_i].b && a_i < a.length; ++j) {
				cnt += max(a[a_i++], bc[bc_i].c);
			}
			++bc_i;
		}
		else {
			cnt += a[a_i++];
		}
	}
	cnt.write;
}


Measured memory_bytes: 7516
#include <iostream>
#include <string>
#include <algorithm>

using namespace std;

#define loop(i,a,b) for(int i=(a); i<(int)(b); i++)
#define rep(i,b) loop(i,0,b)
#define all(c) (c).begin(), (c).end()

int main(){
    string aidu = "AIDUNYAN";
    string aizu = "AIZUNYAN";
    sort(all(aidu));

    string s;
    cin >> s;

    rep(i, s.size()-8+1){
        string t = s.substr(i, 8);
        sort(all(t));
        if (t == aidu){
            rep(j, 8) s[i + j] = aizu[j];
            i += 7;
        }
    }
    cout << s << endl;
}

Measured memory_bytes: 1212
import sys
from io import StringIO
import unittest

def resolve():
    s = list(input())
    t = list(input())

    dp = [[0 for _ in range(len(t) + 1)] for __ in range(len(s) + 1)]

    # 長さを求める
    for i in range(len(s)):
        for j in range(len(t)):
            if s[i] == t[j]:
                dp[i + 1][j + 1] = max(dp[i][j] + 1, dp[i + 1][j], dp[i][j + 1])
            else:
                dp[i + 1][j + 1] = max(dp[i + 1][j], dp[i][j + 1])

    ans = ''
    i += 1
    j += 1

    # 復元する
    while i >= 0 and j >= 0:
        if dp[i][j] == dp[i - 1][j - 1]:
            i -= 1
            j -= 1
        elif dp[i][j] == dp[i - 1][j]:
            i -= 1
        elif dp[i][j] == dp[i][j - 1]:
            j -= 1
        else:
            ans = s[i - 1] + ans
            i -= 1
            j -= 1

    print(ans)

class TestClass(unittest.TestCase):
    def assertIO(self, input, output):
        stdout, stdin = sys.stdout, sys.stdin
        sys.stdout, sys.stdin = StringIO(), StringIO(input)
        resolve()
        sys.stdout.seek(0)
        out = sys.stdout.read()[:-1]
        sys.stdout, sys.stdin = stdout, stdin
        self.assertEqual(out, output)
    def test_入力例_1(self):
        input = """axyb
abyxb"""
        output = """axb"""
        self.assertIO(input, output)
    def test_入力例_2(self):
        input = """aa
xayaz"""
        output = """aa"""
        self.assertIO(input, output)
    def test_入力例_3(self):
        input = """a
z"""
        output = """"""
        self.assertIO(input, output)
    def test_入力例_4(self):
        input = """abracadabra
avadakedavra"""
        output = """aaadara"""
        self.assertIO(input, output)

if __name__ == "__main__":
    # unittest.main()
    resolve()

Measured memory_bytes: 124684
#include <iostream>
#include <string>
#include <algorithm>

int main()
{
	std::string s,t;

	std::cin >> s >>t;

	std::sort(s.begin(), s.end());
	std::sort(t.begin(), t.end(), std::greater<int>());

	if (s < t) {
		std::cout << "Yes" << std::endl;
	}
	else {
		std::cout << "No" << std::endl;
	}
	
	return 0;
}

Measured memory_bytes: 256
// Resistors in Parallel
#include <iostream>
#include <vector>
#include <math.h>
#include <string>
#include <map>
#include <stdio.h>
#include <string.h>
#include <initializer_list>
#include <algorithm>
#include <numeric>
#include <iomanip>

using namespace std;

int gcd(int a, int b)
{
    int temp;
    while (b != 0)
    {
        temp = a % b;

        a = b;
        b = temp;
    }
    return a;
}

int lcm(int a, int b)
{
    return (a * b) / gcd(a, b);
}

int main()
{
    int N;
    vector<int> A;
    cin >> N;
    int sum = 0;
    for (int i = 0; i < N; i++)
    {
        int tmp;
        cin >> tmp;
        A.push_back(tmp);
    }
    int g = 1;
    for (int i = 0; i < N; i++)
    {
        g = gcd(A[i - 1], A[i]);
    }
    int l = 1;
    for (int i = 0; i < N; i++) {
        l = lcm(l, A[i]);
    }
    //cout << "lcm = " << l << endl;
    int sum1 = 0;
    for (int i = 0; i < N; i++) {
        sum1 += l / A[i];
        //cout << l / A[i] << endl;
    }
    cout << std::setprecision(100000) << (double) ((double)l / (double)sum1) << endl;

    return 0;
} // Resistors in Parallel


Measured memory_bytes: 640
#include<bits/stdc++.h>
using namespace std;
    int main(){
        int N, A, B;
            cin >> N;
                if(N == 1){
                    cout << "Hello World" << endl;
                }else if(N == 2){
                    cin >> A >> B;
                        cout << A + B << endl;
                }
    return 0;}

Measured memory_bytes: 256
//{{{
#include <bits/stdc++.h>
using namespace std;
#define repX(a,b,c,x,...) x
#define repN(a) repX a
#define rep(...) repN((__VA_ARGS__,rep3,rep2,loop))(__VA_ARGS__)
#define rrep(...) repN((__VA_ARGS__,rrep3,rrep2))(__VA_ARGS__)
#define loop(n) rep2(i_,n)
#define rep2(i,n) rep3(i,0,n)
#define rep3(i,begin,end) for(int i=(int)(begin),i##_end=(int)(end);i<i##_end;++i)
#define rrep2(i,n) rrep3(i,n,0)
#define rrep3(i,begin,end) for(int i=(int)(begin-1),i##_end=(int)(end);i>=i##_end;--i)
#define foreach(x,a) for(auto&x:a)
using ll=long long;
const ll MOD=(ll)1e9+7;
//}}}

ll f[200001] = {0};
ll comb[200001];

ll mod_pow(ll x, ll n){
  ll res = 1LL;
  while(n > 0){
    if(n & 1) res = res * x % MOD;
    x = x*x % MOD;
    n >>= 1;
  }
  return res;
}

ll mod_inv(ll x){
  return mod_pow(x, MOD-2) % MOD;
}

ll comb_mod(int n, int r){
  return (((f[n] * mod_inv(f[r])) % MOD) * mod_inv(f[n-r])) % MOD;
}

int main(){
  int N, M;
  cin >> N >> M;
  vector<int> v;
  ll ans = 1;
  f[0] = f[1] = 1;
  int nn = 32 + N - 1;
  rep(i, 2, nn + 1) f[i] = (i * f[i-1]) % MOD;
  rep(n, 2, 100000){
    if(M == 1) break;
    int num = 0;
    while(M % n == 0){
      M /= n;
      num++;
    }
    if(num){
      ans *= comb_mod(num + N - 1, N - 1);
      ans %= MOD;
    }
  }
  if(M != 1){
    ans *= comb_mod(N, N - 1);
    ans %= MOD;
  }
  cout << ans << endl;
  return 0;
}


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

int	main()
{
	int	A, B, C, X, Y;
	cin >> A >> B >> C >> X >> Y;
	if (2 * C >= A + B) {
		cout << X * A + Y * B << endl;
		return 0;
	}
	if (X > Y && A <= 2 * C) {
		cout << (X - Y) * A + Y * 2 * C << endl;
		return 0;
	}
	if (X < Y && B <= 2 * C) {
		cout << X * 2 * C + (Y - X) * B << endl;
		return 0;
	}
	cout << max(X, Y) * 2 * C << endl;
	return 0;
}	


Measured memory_bytes: 256
N,M,C = map(int, input().split())
B = list(map(int, input().split()))
A = [ [int(j) for j in input().split()] for _ in range(N)]

ans = 0
for i in range(N):
  tmp = 0
  for k in range(M):
    tmp += A[i][k] * B[k]
  if tmp + C > 0:
    ans += 1
print(ans)

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


#define li          long long int
#define rep(i,to)   for(li i=0;i<((li)(to));i++)
#define repp(i,start,to)    for(li i=(li)(start);i<((li)(to));i++)
#define pb          push_back
#define sz(v)       ((li)(v).size())
#define bgn(v)      ((v).begin())
#define eend(v)     ((v).end())
#define allof(v)    (v).begin(), (v).end()
#define dodp(v,n)       memset(v,(li)n,sizeof(v))
#define bit(n)      (1ll<<(li)(n))
#define mp(a,b)     make_pair(a,b)
#define rin rep(i,n)
#define EPS 1e-12
#define ETOL 1e-8
#define MOD 1000000007
typedef pair<li, li> PI;

#define INF bit(60)

#define DBGP 1


#define idp if(DBGP)
#define F first
#define S second
#define p2(a,b)     idp cout<<a<<"\t"<<b<<endl
#define p3(a,b,c)       idp cout<<a<<"\t"<<b<<"\t"<<c<<endl
#define p4(a,b,c,d)     idp cout<<a<<"\t"<<b<<"\t"<<c<<"\t"<<d<<endl
#define p5(a,b,c,d,e)       idp cout<<a<<"\t"<<b<<"\t"<<c<<"\t"<<d<<"\t"<<e<<endl
#define p6(a,b,c,d,e,f)     idp cout<<a<<"\t"<<b<<"\t"<<c<<"\t"<<d<<"\t"<<e<<"\t"<<f<<endl
#define p7(a,b,c,d,e,f,g)       idp cout<<a<<"\t"<<b<<"\t"<<c<<"\t"<<d<<"\t"<<e<<"\t"<<f<<"\t"<<g<<endl
#define p8(a,b,c,d,e,f,g,h)     idp cout<<a<<"\t"<<b<<"\t"<<c<<"\t"<<d<<"\t"<<e<<"\t"<<f<<"\t"<<g<<"\t"<<h<<endl
#define p9(a,b,c,d,e,f,g,h,i)       idp cout<<a<<"\t"<<b<<"\t"<<c<<"\t"<<d<<"\t"<<e<<"\t"<<f<<"\t"<<g<<"\t"<<h<<"\t"<<i<<endl
#define p10(a,b,c,d,e,f,g,h,i,j)        idp cout<<a<<"\t"<<b<<"\t"<<c<<"\t"<<d<<"\t"<<e<<"\t"<<f<<"\t"<<g<<"\t"<<h<<"\t"<<i<<"\t"<<j<<endl
#define foreach(it,v)   for(__typeof((v).begin()) it=(v).begin(); it!=(v).end(); ++it)
#define p2p(x)      idp p2((x).F, (x).S)
#define dump(x,n)   idp{rep(i,n){cout<<x[i]<<" ";}puts("");}
#define dump2(x,n)  idp{rep(i,n){cout<<"["<<x[i].F<<" , "<<x[i].S<<"] ";}puts("");}
#define dumpi(x)    idp{foreach(it, x){cout<<(*it)<<" ";}puts("");}
#define dumpi2(x)   idp{foreach(it, x){cout<<"["<<(it)->F<<" , "<<(it)->S<<"] ";}puts("");}

#define read2d(a,w,h)   rep(i,h)rep(j,w)cin>>a[i][j]
#define dump2d(a,w,h)   rep(i,h){rep(j,w)cout<<a[i][j]<<" ";puts("");}

typedef pair<li, li> PI;

li n;
li c[200100];
li last_c[200100];
li dp[200100];

int main() {
    cin >> n;
    rin{
        cin >> c[i];
        c[i]--;
    }
    rin{
        last_c[i] = n;
    }

    dp[n] = 1;
    for (li i = n - 1; i >= 0; i--) {
        if (last_c[c[i]] != n && last_c[c[i]] != i + 1) {
            // magic chance!
            dp[i] = (dp[last_c[c[i]]] + dp[i + 1]) % MOD;
        } else {
            dp[i] = dp[i + 1];
        }
        last_c[c[i]] = i;
    }
    cout << dp[0] << endl;


    return 0;
}

Measured memory_bytes: 4992
"use strict";
function I(s,f){this._s=s.split("\n");this._c=0;this._l=0;this._f=f||Number}I.prototype.a=function(){var l=this._s[this._l];if(!l)return;var t=l.trim().split(" ");var a=t[this._c];this._c++;if(t.length===this._c){this._c=0;this._l++}return this._f(a)};I.prototype.l=function(){var l=this._s[this._l];if(!l)return;this._c=0;this._l++;return l.split(" ").map(this._f)};module.exports=I;

function main(input) {
  const o = new I(input);

  const N = o.a();
  const M = o.a();

  const adj = [];
  for (let i = 1; i <= N; i++) {
    adj[i] = [];
  }

  for (let i = 0; i < M; i++) {
    let ai = o.a();
    let bi = o.a();
    adj[ai].push(bi);
    adj[bi].push(ai);
  }

  let six = false;
  let four = 0;
  let fours = [];
  let flag2 = true;
  for (let i = 1; i <= N; i++) {
    if (adj[i].length >= 6) {
      six = true;
    }

    if (adj[i].length >= 4) {
      four += 1;
      fours.push(i);
    }


    if (adj[i].length % 2 !== 0) {
      flag2 = false;
    }
  }

  if (flag2) {
    if (six) {
      console.log("Yes");
    } else if (four >= 3) {
      console.log("Yes");
    } else if (four === 2) {
      // check a b min cut
      var s = fours[0];
      var t = fours[1];
      console.log(dfsStart(s, t, adj, N) ? "Yes":"No");
    } else {
      console.log("No");
    }
  } else {
    console.log("No");
  }
}

function dfsStart(s, t, adj, N) {
  var count = 0;
  var colors = Array(N + 1).fill("white");
  colors[s] = "black";

  var cur = s;
  while (count < 3) {
    cur = s;
    var prev;
    while (cur !== t) {
      prev = cur;
      cur = adj[cur].filter(x => colors[x] === "white")[0];
      if (!cur) {
        if (adj[prev].indexOf(t) === -1) {
          return true;
        } else {
          cur = t;
        }
      } 
      colors[cur] = "black";
    }
    count += 1;
  }

  return false;
}


main(require("fs").readFileSync("/dev/stdin", "utf8"));
// main(require("fs").readFileSync("./c.input", "utf8"));


Measured memory_bytes: 64060
N, X, Y = map(int, input().split())
X -= 1
Y -= 1
out = [0] * N
for i in range(N-1):
  for j in range(i+1, N):
    out[min(j-i, abs(i-X)+1+abs(j-Y))] += 1
for i in range(1, N):
  print(out[i])

Measured memory_bytes: 46556
#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;

int main()
{
    int k, n;
    cin >> k >> n;
    vector<int> distancijos(n), tikrosios_distancijos;

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

    }
    distancijos.push_back(distancijos[0] + k);//
    int tarpas = 0;
    for (int i = 0; i < n; i++)
    {
        tarpas = max(tarpas, distancijos[i+1]-distancijos[i]);

    }
    cout << k - tarpas;
}


Measured memory_bytes: 1792
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(10000000)
INF = int(1e9)

#ans:=目標達成するのに必要な最小の金額（求める値）
#最小値を更新しながら求めていくので初期値は十分大きな数とする
ans = INF
def main():
    N, M, X = map(int, readline().split())

    #参考書、アルゴリズムは0-indexed

    #costs[i]:=参考書iの金額
    #score[i][j]:=参考書iを読んで上がるアルゴリズムjの理解度
    costs = []
    score = []
    for _ in range(N):
        c, *d = map(int, readline().split())
        costs.append(c)
        score.append([i for i in d])

    #bit:=どの参考書を買うかの組み合わせを表現するリスト
    #bit[i]が1のときi番目の参考書を買う
    #bit[i]が0のときi番目の参考書を買わない
    bit = []
    #買う参考書の組みを順に全て構成し、構成した組それぞれに対して金額の総和計算をする
    def dfs():
        global ans
        #全てのbitの0,1が決まる=購入する参考書の組みが決定したとき理解度の計算をする
        if len(bit) == N:
            #cost:=買った参考書の値段の合計金額 
            cost = 0
            #sumSocore[i]:=i番目のアルゴリズムの理解度の累計 
            sumScore = [0 for _ in range(M)]
            for i in range(N):
                if bit[i]:
                #bit[i]==1なら参考書iを購入するのでcostを更新する
                    cost += costs[i]
                    for j in range(M):
                        #sumScoreを更新
                        sumScore[j] += score[i][j]

            #全てのアルゴリズムの理解度がx以上であるかの判定
            #flag:=全てのアルゴリズムの理解度がx以上であるか
            flag = True 
            for i in range(M):
                if sumScore[i] < X: 
                    flag = False

            #全てのアルゴリズムの理解度がx以上であるときcostはansの候補である
            if flag:
                #cost < ansのときcostをansに代入
                ans = min(ans, cost)
                return 
            return 

        #bitを決めていく0か1を追加していく
        for i in range(2): 
            bit.append(i)
            dfs()
            #次のループでi=1を同じ位置へappendするためにpopしておく
            bit.pop()

    dfs()
    if ans == INF:
        print(-1)
    else:
        print(ans)
if __name__ == '__main__':
    main()


Measured memory_bytes: 70812
import sys
from collections import deque
def input(): return sys.stdin.readline().rstrip()

def per(n, r, mod=10**9+7):  # 順列数
    per = 1
    for i in range(r):
        per = per*(n-i) % mod
    return per
 
n, k = map(int, input().split())
mod=10**9+7
graph = [[] for _ in range(n+1)]

for i in range(n-1):
    a, b = map(int, input().split())
    graph[a].append(b)
    graph[b].append(a)

dist = [-1] * (n+1)
dist[0] = 0
dist[1] = 0

d = deque()
d.append(1)
ans=k
while d:
    v = d.popleft()
    cnt=0
    for i in graph[v]:
        if dist[i] != -1:
            continue
        dist[i] = dist[v] + 1
        d.append(i)
        cnt+=1
    if cnt>0:
        if v==1:
            ans=ans*per(k-1,cnt)%mod
        else:
            ans=ans*per(k-2,cnt)%mod
    


print(ans)

Measured memory_bytes: 29796
from collections import deque

n, m = map(int, input().split())
rooms = [[] for i in range(n + 1)] #直接行ける部屋を記録

for i in range(m):
    a, b = map(int, input().split())
    rooms[a].append(b)
    rooms[b].append(a)

route = [-1]*(n + 1)
route[1] = 0
q = deque()
q.append(1)

while q:
    v = q.popleft()
    for i in rooms[v]:
        if route[i] == -1:
            route[i] = v
            q.append(i)

print("Yes")

for i in route[2:]:
    print(i)

Measured memory_bytes: 35044
import java.io.*;
import java.math.BigInteger;
import java.util.*;
import java.util.Stack;

public class Main{
	public static class FastReader {
		BufferedReader br;
		StringTokenizer root;
		
 
		public FastReader() {
			br = new BufferedReader(new InputStreamReader(System.in));
		}
 
		String next() {
			while (root == null || !root.hasMoreTokens()) {
				try {
					root = new StringTokenizer(br.readLine());
				} catch (Exception r) {
					r.printStackTrace();
				}
			}
			return root.nextToken();
		}
 
		int nextInt() {
			return Integer.parseInt(next());
		}
 
		double nextDouble() {
			return Double.parseDouble(next());
		}
 
		long nextLong() {
			return Long.parseLong(next());
		}
 
		String nextLine() {
			String str = "";
			try {
				str = br.readLine();
			} catch (Exception r) {
				r.printStackTrace();
			}
			return str;
		}
	}
	
	public static PrintWriter out = new PrintWriter (new BufferedOutputStream(System.out));
	static int mod = (int) (1e9+7),n;
	static long cf = 998244353;
    static final int MAX = (int) 1e6;
    public static List<Integer>[] edges;
    public static int[][] parent;
    public static int col = 20;
    public static long[] Bit;
    public static long[] fac,inv;
    public  static int[] prime; 
    public static long[] dp;
	public static FastReader sc = new FastReader();
	public static void main(String[] args) {
	//	Scanner sc = new Scanner(System.in);
 
		int n = sc.nextInt();
		int k = sc.nextInt()-1;
		char[] s = sc.next().toCharArray();
		s[k] = Character.toLowerCase(s[k]);
		out.print(new String(s));
		out.close();
	}
	
	
}

Measured memory_bytes: 21076
/// Template by Zayed ///

///#include <bits/stdc++.h>
#include <iostream>
#include <cstdio>
#include <iomanip>

#include <string>
#include <cstring>
#include <sstream>

//#include <tuple>
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <list>
#include <map>
//#include<unordered_map>
#include <set>
//#include<unordered_set>

#include <algorithm>
#include <bitset>
#include <cmath>
#include <cstdlib>

typedef long long LL;//NOTES:"%lld"
typedef unsigned long long ULL;//NOTES:"%llu"

using namespace std;
int caseno = 1;

#define NL '\n'
#define SF scanf
#define PF printf
#define PC() printf("Case %d: ", caseno++)//NOTES:printf
//#define BUG() printf("\n!!!!!!WHERE IS YOUR FOCUS!!!!!!\n") //NOTES:printf

#define BUG cout << "\n!!!!!!WHERE IS YOUR FOCUS!!!!!!\n" //NOTES:cout
//#define PC cout << "Case "//NOTES:cout
//#define CN cout << caseno++ << ": "//NOTES:cout

#define CLR(ar) memset(ar, 0, sizeof(ar))
#define SET(ar) memset(ar, -1, sizeof(ar))
#define READ() freopen("input.txt", "r", stdin)
#define WRITE() freopen("output.txt", "w", stdout)
#define BOOST std::ios_base::sync_with_stdio(0);
#define FOR(I,J,K) for(I = J; I < K; I++)
#define REV(I,J,K) for(I = J; I > K; I--)

#define INTMAX (1LL << 31) - 1
#define LLMAX (1LL << 63) - 1
#define MOD 1000000007		    // (10^9 + 7)
#define PRIME 999998727899999   // (largest prime below 10^16)
#define PB push_back
#define pii pair<int, int>
#define pdd pair<double, double>
#define pic pair<int, char>
#define pci pair<char, int>
#define pLL pair<LL, LL>
#define pis pair<int, string>
#define psi pair<string, int>
#define pss pair<string, string>
//#define tiii tuple<int, int, int>
#define PI 2 * acos(0.0)
#define EPS 1e-11


template< class T > bool Inside(T a, T b, T c) { return a <= b && b <= c; }
template < class T > inline void SWAP(T &a, T &b) { T t = a; a = b; b = t; }
inline LL POW(LL base, LL power){
	LL res = base; if (power == 0) return 1;
	for (int I = 0; I < power - 1; I++) res *= base; return res;
}

//Translator Functions
int ToInt(string s) { int r = 0; istringstream sin(s); sin >> r; return r; }//NOTES:ToInt(
double ToDouble(string s) { double r = 0; istringstream sin(s); sin >> r; return r; }//NOTES:ToDouble(
string ToString(int n) { string s; stringstream convert; convert << n; s = convert.str(); return s; }//NOTES:ToString(

//int dx[] = {0, 0, -1, +1}, dy[] = {-1, +1, 0, 0}; //4 Direction Array
//int dx[] = {0, 0, -1, +1, -1, -1, +1, +1}, dy[] = {-1, +1, 0, 0, -1, +1, -1, +1}; //8 Direction Array
//int dx[] = {-2, -2, -1, -1, +1, +1, +2, +2}, dy[] = {-1, +1, -2, +2, -2, +2, -1, +1}; //Knight Moves


const int SIZE = 1000 + 5;




int main()
{
	BOOST
	///READ();
	///WRITE();
	int T, I, J, K, N, n, m, k, cnt = 0, len, A, B;

    cin >> A >> B;

    if(A == 1 && A != B)
        cout << "Alice\n";
    else if(B == 1 && A != B)
        cout << "Bob\n";
    else if(A == B)
        cout << "Draw\n";
    else if(A > B)
        cout << "Alice\n";
    else if(A < B)
        cout << "Bob\n";


	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <string>
#include <sstream>
#include <stdio.h>
#include <string.h>
#include <vector>
#include <algorithm>
#include <utility>
#include <tuple>
#include <cstdint>
#include <cstdio>
#include <cmath>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <deque>
#include <unordered_map>
#include <unordered_set>
#include <bitset>
#include <cctype>
using namespace std;

int main(){
  string S,T;
  cin >> S >> T;

  int answer = T.size();

  for(int i = 0;i <= S.size() - T.size();i++){
    int now = 0;
    for(int j = 0;j < T.size();j++){
      if(T.at(j) != S.at(i + j)){
        now++;
      }
    }
    answer = min(answer,now);
  }
  cout << answer << endl;
}
/*
int main(){
  string S,T;
  cin >> S >> T;

  //int answer = T.size();
  string SS = S;
  int x,count = 1000;
  for(int i = 0;i < T.size();i++){
    string now;
    for(int j = i;j < T.size();j++){
      now = now + T.at(j);
      if(0 <= SS.find(now) && SS.find(now) <= S.size()){
      //  cout << now << endl;
        x = T.size() - now.size();
        count = min(count,x);
      }
    }
    SS.erase(0,1);
  }



  cout << count << endl;
}
*/


Measured memory_bytes: 3576
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
    ($($r:tt)*) => {
        let mut s = {
            use std::io::Read;
            let mut s = String::new();
            std::io::stdin().read_to_string(&mut s).unwrap();
            s
        };
        let mut iter = s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
}

macro_rules! input_inner {
    ($iter:expr) => {};
    ($iter:expr, ) => {};

    ($iter:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($iter, $t);
        input_inner!{$iter $($r)*}
    };
}

macro_rules! read_value {
    ($iter:expr, ( $($t:tt),* )) => {
        ( $(read_value!($iter, $t)),* )
    };

    ($iter:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($iter, $t)).collect::<Vec<_>>()
    };

    ($iter:expr, chars) => {
        read_value!($iter, String).chars().collect::<Vec<char>>()
    };

    ($iter:expr, usize1) => {
        read_value!($iter, usize) - 1
    };

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

fn result<'a>(x: u64, y: u64) -> u64{
    if y > 1 { x + result(x, y-1)*10 } else {x}
}

fn main(){
    input!{
        a: u64,
        b: u64,
    }
    println!("{}", if a == b {"Yes".to_string()} else {"No".to_string()})
}


Measured memory_bytes: 4352
#include<bits/stdc++.h>
using namespace std;
typedef signed long long ll;
 
#define REP(i,a,b) for(i=a;i<b;i++)
#define rep(i,n) REP(i,0,n)

int main(){
	int i,j,k,n,m,l,f,x,y,z; string s;
	cin >> n >> m >> l >> f;
	cout << max(0, min(m, f) - max(n,l)) << endl;

}

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

int n, k, q;


int a[2010];
int no[2010];

int solve(){

    priority_queue<int, vector<int>, greater<int>> que;
    vector<int> ans;

    for(int i = 0;i < n;i++){
        if(no[i] == 1){
            while(!que.empty()) que.pop();
        }else{
            que.push(a[i]);
            if(que.size() == k){
                ans.push_back(que.top());
                que.pop();
            }
        }
    }

    if(ans.size() >= q){
        sort(ans.begin(), ans.end());
        return ans[q-1] - ans[0];
    }else{
        return INT_MAX;
    }
}

int main(){
    cin >> n >> k >> q;

    set<int> st;
    for(int i = 0;i < n;i++){
        cin >> a[i];
        st.insert(a[i]);
    }

    int ans = INT_MAX;
    for(auto num : st){
        ans = min(ans, solve());

        for(int i = 0;i < n;i++){
            if(a[i] == num){
                no[i] = 1;
            }
        }
    }

    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 384
using System;
using System.Collections;
using System.Collections.Generic;
using System.Text;
using System.Linq;
using static MyIO;


public class A
{
    public static void Main()
    {
        var s = Console.ReadLine().Split(',');
        Console.WriteLine($"{s[0]} {s[1]} {s[2]}");
        
    }
}

public static class MyIO
{
    private static string[] args = null;
    private static int num = -1;
    private static int used = -1;

    private static string getArg()
    {
        if (used == num)
        {
            args = Console.ReadLine().Split(' ');
            num = args.Length;
            used = 0;
        }
        return args[used++];
    }

    public static int GetInt() { return int.Parse(getArg()); }
    public static long GetLong() { return long.Parse(getArg()); }
    public static double GetDouble() { return double.Parse(getArg()); }
    public static string GetString() { return getArg(); }
}

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

#define rep(i, n) for (ll i = 0; i < (n); i++)
#define rep2(i, a, b) for (ll i = (a); i < (b); i++)
#define chmax(x, v) do { x = max(x, v); } while (0)
#define chmin(x, v) do { x = min(x, v); } while (0)
typedef uint64_t ull;
typedef int64_t ll;
typedef std::pair<ll, ll> PLL;

using namespace std;

ll INF = 1e10;
ll N, W;
ll w[100];
ll v[100];
ll dp[100][200000]; // dp[n][v]

signed main() {
  rep(i,100) rep(j, 200000) dp[i][j] = INF;
  cin >> N >> W;
  rep(i,N)
    cin >> w[i] >> v[i];
  dp[0][0] = 0;
  dp[0][v[0]] = w[0];
  rep(i, N) rep(j, 200000) {
    if (dp[i][j] == INF) continue;
    ll ni = i+1;
    if (ni >= N) continue;
    ll nv = j;
    if (nv < 200000) chmin(dp[ni][nv], dp[i][j]);
    nv = j + v[ni];
    if (nv < 200000) chmin(dp[ni][nv], dp[i][j] + w[ni]);
  }
  ll ans = -1;
  rep(j, 200000)
    if (dp[N-1][j] <= W)
      chmax(ans, j);
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 156544
#include <string>
#include <iostream>
#include <stack>
#include <queue> // priority_queue も入ってる
#include <set>   // 要素数は size() で取得 multisetもある
#include <map>
#include <array> // sizeはコンパイル時定数で固定
#include <vector>
#include <numeric>   // accumulate, gcd
#include <algorithm> // count_ifに必要
#include <iomanip>   // cout << setprecision(15) << x で小数の出力精度を指定
#include <tuple>
#include <utility> //pair
#include <cmath>

using namespace std;
// 問題が起こるまでintは使用禁止2020-04-13
using ll = long long;

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

template <class InputIterator, class T>
bool contains_itr(InputIterator iterator, const T &value)
{
    if (find(iterator.begin(), iterator.end(), value) == iterator.end())
        return false;
    else
        return true;
}

template <class T>
bool contains_set(set<T> st, const T &value)
{
    if (st.find(value) == st.end())
    {
        return false;
    }
    else
    {
        return true;
    }
}

template <class InputIterator>
auto sum(InputIterator iterator)
{
    return accumulate(iterator.begin(), iterator.end(), 0);
}

// endは排他的(exclusive)なので注意
vector<ll> range(ll begin, ll end)
{
    vector<ll> result;
    for (ll i = begin; i < end; ++i)
    {
        result.push_back(i);
    }
    return result;
}

// =========ここまでテンプレ============

int main()
{
    ll x, y;
    cin >> x >> y;
    if (y % 2 == 0 && y - 2 * x >= 0 && 4 * x - y >= 0)
    {
        cout << "Yes" << endl;
    }
    else
    {
        cout << "No" << endl;
    }
}

Measured memory_bytes: 3132
public class Main{
  public void run(java.io.InputStream in, java.io.PrintStream out){
    java.util.Scanner sc = new java.util.Scanner(in);
/*answer*/
    int n;
    int[] a;
    int i, j, k, max, sum;

    for(;;){
      n = sc.nextInt();
      if(n == 0)break;
      a = new int[n];
      for(i = 0;i < n;i++)a[i] = sc.nextInt();

      max = a[0];
      for(i = 0;i < n;i++){
        for(j = i + 1;j < n + 1;j++){
          sum = 0;
          for(k = i;k < j;k++)sum += a[k];
          if(max < sum)max = sum;
        }
      }
      System.out.println(max);
    }

    sc.close();
  }
  public static void main(String[] args){
    (new Main()).run(System.in, System.out);
  }
}

Measured memory_bytes: 26480
#include <iostream>
#include <map>

using namespace std;

int main()
{
    int N,num,count=0;
	map<int,int> dmap;
	cin>>N;
	for(int i=0;i<N;i++){
		cin>>num;
		map<int,int>::iterator it = dmap.find(num);
		if(it==dmap.end()){
			dmap.insert(map<int, int>::value_type(num,1));
		}
	}
	cin>>N;
	for(int i=0;i<N;i++){
		cin>>num;
		map<int,int>::iterator it = dmap.find(num);
		if(it!=dmap.end()){
			count++;
		}
	}
	cout<<count<<endl;
}

Measured memory_bytes: 1236
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int MOD = 1e9 + 7;
const int N = 1e6 + 5;
ll fact[2 * N];

ll binpow(ll a, ll b, ll m) {
    a %= m;
    ll res = 1;
    while (b > 0) {
        if (b & 1)
            res = res * a % m;
        a = a * a % m;
        b >>= 1;
    }
    return res % m;
}

ll inverse(ll x) {
	return binpow(x, MOD - 2, MOD);
}

ll cc(ll n, ll k) {
	return fact[n] * inverse(fact[k]) % MOD * inverse(fact[n - k]) % MOD;
}

int main()
{
	ll r1, c1, r2, c2;
	scanf("%lld%lld%lld%lld", &r1, &c1, &r2, &c2);
	fact[0] = 1;
	for (int i = 1; i <= r2 + c2 + 2; i++) {
		fact[i] = fact[i - 1] * i % MOD;
	}
	ll ans = (cc(r1+c1, c1) + cc(r2+c2+2, c2+1) - cc(r1+c2+1, c2+1) - cc(r2+c1+1, c1)) % MOD;
	printf("%lld\n", (ans + MOD) % MOD);
	return 0;
}

Measured memory_bytes: 15872
#include<iostream>
#include<string>
#include<complex>
#include<vector>
#include<algorithm>
#include<functional>
#include<array>
using namespace std;
typedef unsigned long long ull;
typedef long long ll;
#define INF 1e+9


int main() {
	ull a, b,c;
	cin >> a >> b;
	if (b != 100) {
		if (a == 0) c = b;
		if (a == 1) c = 100 * b;
		if (a == 2) c = 10000 * b;
		cout << c << endl;
	}
	else {
		b++;
		if (a == 0) c = b;
		if (a == 1) c = 100 * b;
		if (a == 2) c = 10000 * b;
		cout << c << endl;
	
	}

	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int N,M;
int MAP[9][9];
int cnt=0;

void dfs(int i,set<int> s)
{
    s.insert(i);
    if(s.size()==N)
    {
        cnt++;
        return ;
    }
    for(int j=1;j<=N;j++)
    {
        if(s.count(j)==0&&MAP[i][j]!=0)
        {
            dfs(j,s);
            s.erase(j);
        }
    }
    s.erase(i);
}
int main(void)
{
    memset(MAP,0,sizeof(MAP));
    set<int>s;
    s.clear();
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    cin>>N>>M;
    int a,b;
    for(int i=0;i<M;i++)
    {
        cin>>a>>b;
        MAP[a][b]=1;
        MAP[b][a]=1;
    }
    dfs(1,s);
    cout << cnt <<endl;
    return 0;
}


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

int main()
{
  int n;
  cin >> n;
  int ans = 0;
  for (int i = 105; i <= n; i += 2)
  {
    int cnt = 0;
    for (int j = 1; j <= i; j++)
    {
      if (i % j == 0)
        cnt++;
    }
    if (cnt == 8)
      ans++;
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 3564
#include <bits/stdc++.h>
#include <math.h>
using namespace std;
typedef long long ll;
typedef long double ld;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
const ll mod = 1000000007;
const int INF = 1001001001;
const ll LINF = 1001001001001001001;

int main(){
    ll n ; cin >> n;
    string s;  cin >> s;
    vector<ll> a(26,0);
    rep(i,n) a.at((int)(s.at(i)-'a'))++;
    ll ans = 1;
    rep(i,26) ans = ans * (a.at(i) + 1) % mod;
    cout << ans - 1 << endl;
    return 0;
}

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

using namespace std;

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


int main() {

	int n;
	int s[101];

	cin>>n;

	int d=0;
	int total=0;
	rep(i,n){
		cin>>s[i];
		total+=s[i];
	}
	if(total%10>0){
		cout<<total<<endl;
	}else{
		sort(s,s+n);
		rep(i,n){
			if(s[i]%10>0){
				cout<<total-s[i]<<endl;
				break;
			}else{
				d++;
			}
		}
	}
	if(d==n){
		cout<<"0"<<endl;
	}
	return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

int main(){
    int n,k;
    scanf("%d%d",&n,&k);
    int x=1;
    for(int i=0;i<n;i++){
        if(x*2<x+k)
            x = x*2;
        else
            x = x+k;
    }
    printf("%d\n",x);
    return 0;
}


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

// types
typedef long long ll;
typedef long double ld;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef pair<ld,ld> pdd;
typedef vector<ll> vll;
typedef vector<ld> vld;
typedef vector<pll> vpll;

// macros
#define ALL(a) a.begin(),a.end()
#define SZ(a) ((int)a.size())
#define FI first
#define SE second
#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 FOR(i,a,b) for(int i=(a);i<(b);i++)
#define PB push_back
#define EB emplace_back
#define MP(a,b) make_pair(a,b)
#define SORT_UNIQUE(c) (sort(c.begin(),c.end()), c.resize(distance(c.begin(),unique(c.begin(),c.end()))))
#define GET_POS(c,x) (lower_bound(c.begin(),c.end(),x)-c.begin())
#define Decimal fixed<<setprecision(20)
#define INF 1000000000
#define LLINF 1000000000000000000LL

// constants
const int inf = 1e9;
const ll linf = 1LL << 50;
const double eps = 1e-10;
const int MOD = 1e9 + 7;
const int dx[4] = {-1, 0, 1, 0};
const int dy[4] = {0, -1, 0, 1};

int main(){
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);

  ll n;
  cin>>n;

  vll h(n);
  REP(i,n)
    cin>>h[i];

  vll dp(n+1,LLINF);
  dp[0]=0;
  REP(i,n){
    if(i+1<n)
      dp[i+1] = min(dp[i+1],dp[i]+abs(h[i]-h[i+1]));
    if(i+2<n)
      dp[i+2] = min(dp[i+2],dp[i]+abs(h[i]-h[i+2]));
  }

  cout<<dp[n-1]<<endl;
}


Measured memory_bytes: 1792
#include <iostream>
#include<string>
#include<cmath>
#include<algorithm>
#include<cctype>
#include<queue>
#include<stack>
#include<stdio.h>
#include<vector>
#include<set>
#include<map>
#include<iomanip>
#define rep(i,n) for(double i=0;i<n;i++)
typedef int long long ll;
using namespace std;
int const INF = 1000000;
int main(){
    ll k,a,b;
    cin>>k>>a>>b;
    
    if(a+2>=b){cout<<k+1<<endl;return 0;}
    if(k<a+1){cout<<k+1<<endl;return 0;}
    k++;
    k=k-(a+2);
    ll ans=b;
    ll add = b-a;
    ans+=(k/2)*add;
    if(k%2==1){ans++;}
    cout<<ans<<endl;
 
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <boost/range/algorithm.hpp>
#include <boost/range/numeric.hpp>
#include <boost/integer/common_factor.hpp>
#include <boost/integer/common_factor_rt.hpp>
#include <boost/multiprecision/cpp_dec_float.hpp>
#include <boost/multiprecision/cpp_int.hpp>

using std::string;
using std::vector;
using std::set;
using std::multiset;
using std::unordered_set;
using std::map;
using std::multimap;
using std::unordered_map;
using std::pair;
using std::cin;
using std::cout;

using boost::multiprecision::cpp_int;
using cpp_dec_float_1000 = boost::multiprecision::number<boost::multiprecision::cpp_dec_float<1000>>;

typedef uintmax_t    ull;
typedef intmax_t     ll;
typedef uint64_t     ul;
typedef uint32_t     ui;
typedef uint8_t      uc;

constexpr char CRLF  = '\n';
constexpr char SPACE = ' ';
constexpr char VECTOR_COUT_SEPARATOR = SPACE;
constexpr ll INF = 1000'000'007;
constexpr int MOD = 1000'000'007;

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; }
template<class T> std::ostream& operator<< (std::ostream& os, const std::vector<T>& vc) { for(auto it = vc.begin(); it != vc.end(); ++it) { if (std::next(it) == vc.end()) os << *it; else os << *it << VECTOR_COUT_SEPARATOR; } return os; }
template<class T1, class T2> inline std::ostream & operator<< (std::ostream & os, const std::pair<T1, T2> & p) { return os << p.first << ' ' << p.second; }
template<class T> T modinv(T a, T m) { T b = m, u = 1, v = 0; while (b) { T t = a / b; a -= t * b; boost::swap(a, b); u -= t * v; boost::swap(u, v); } u %= m; if (u < 0) u += m; return u; }

struct Tmp
{
public:
  Tmp(int N);
  int mSize;
  vector<vector<int>> mGraph;
  vector<int> mF;

  void rec(int back, int index);
};

Tmp::Tmp(int N)
  : mSize(N), mGraph(N), mF(N, -1)
{ /* do nothing */ }

void Tmp::rec(int back, int index)
{
  if (mF[index] != -1) {
    return;
  }

  int res{};
  for (const auto next : mGraph[index]) {
    // assert(back != next);
    if (mF[next] == -1) {
      rec(index, next);
    }
    // assert(mF[next] != -1);
    chmax(res, mF[next] + 1);
  }
  mF[index] = res;
  // assert(mF[index] != -1);
  return;
}

void solve(void)
{
  int N, M; cin >> N >> M;
  Tmp t(N);

  for (int i = 0; i < M; ++i) {
    int x, y; cin >> x >> y;
    --x; --y;
    t.mGraph[x].push_back(y);
  }

  for (int i = 0; i < (int)t.mGraph.size(); ++i) {
    if (t.mF[i] == -1) {
      t.rec(-1, i);
    }
  }
  auto ans = boost::max_element(t.mF);
  cout << *ans << CRLF;
  return;
}

int main(void)
{
  std::ios_base::sync_with_stdio(false);
  std::cin.tie(0);

  solve();

  return 0;
}


Measured memory_bytes: 9600
#include <iostream>
//#include <iomanip>
#include <algorithm>
//#include <numeric>
//#include <queue>
//#include <stack>
#include <math.h>
#include <vector>
//#include <string>
typedef long long LL;
using namespace std;
 
static LL MOD = 998244353;
 
int main(){
    int n;
    vector<int> d;
    int d_tmp;
    int max;
    LL ans = 1;
    int pre;
    int now;
    cin >> n;
    for(int i=0; i<n; i++){
        cin >> d_tmp;
        d.push_back(d_tmp);
    }
    sort(d.begin()+1, d.end());
    max = d[n-1];
    vector<int> n_cb(max+1);
    for(int i=0; i<=max; i++){
        n_cb[i]=0;
    }
    for(int i=0; i<n; i++){
        n_cb[d[i]]++;
    }
    if(n_cb[0]==1 && d[0]==0){
        for(int i=1; i<=max; i++){
            pre = n_cb[i-1];
            now = n_cb[i];
            if(now==0){
                ans *= 0;
            }else{
                for(int i=0; i<now; i++){
                    ans *= (LL)pre;
                    ans %= MOD;
                }
            }
            //cout << pre << " " << now << " " << ans << endl;
        }
    }else{
        ans = 0;
    }
    cout << ans << endl;
}

Measured memory_bytes: 1144
class Dice():
    def __init__(self,ary):
        self.top = ary[0]
        self.south = ary[1]
        self.east = ary[2]
        self.west = ary[3]
        self.north = ary[4]
        self.bottom = ary[5]

    def get_top(self):
        return self.top

    def rotate_north(self):
        self.top,self.south,self.north,self.bottom = self.south,self.bottom,self.top,self.north
    
    def rotate_south(self):
        self.top,self.south,self.north,self.bottom = self.north,self.top,self.bottom,self.south

    def rotate_west(self):
        self.top,self.west,self.bottom,self.east = self.east,self.top,self.west,self.bottom

    def rotate_east(self):
        self.top,self.west,self.bottom,self.east = self.west,self.bottom,self.east,self.top

    def rotate_horizon(self):
        self.south,self.east,self.north,self.west = self.west,self.south,self.east,self.north

    def get_east(self):
        return self.east
        
dice1 = Dice(list(map(int,input().split())))
dice2 = Dice(list(map(int,input().split())))

h=""

for i in range(4):
    dice2.rotate_west()
    if dice1.top == dice2.top:
        for _ in range(4):
            dice2.rotate_horizon()
            if dice1.south == dice2.south:
                if dice1.east == dice2.east and dice1.west == dice2.west:
                    h = "Yes"
for _ in range(4):
    dice2.rotate_north()
    if dice1.top == dice2.top:
        for m in range(4):
            dice2.rotate_horizon()
            if dice1.south == dice2.south:
                if dice1.east == dice2.east and dice1.west == dice2.west:
                    h = "Yes"
if h:
    print(h)
else:
    print("No")

Measured memory_bytes: 7832
import math

n,a,b = map(int, input().split())
h = [int(input()) for i in range(n)]

l = 0
r = 10**14

while True:
    e = (l+r)//2
    f = e
    for i in range(n):
        f -= math.ceil(max((h[i]-b*e),0)/(a-b))
        if f<0:
            break
    if f < 0:
        if l==e:
            print(e+1)
            exit()
        else:
            l = e
    else:
        r = e



Measured memory_bytes: 51160
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {

		Scanner sc = new Scanner(System.in);

		int a = sc.nextInt();
		int b = sc.nextInt();

		if (a * b % 2 == 0) {
			System.out.print("Even");
		} else {
			System.out.print("Odd");
		}
	}
}

Measured memory_bytes: 23252