akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
// #include <iostream>
// #include <vector>
// #include <map>
// #include <algorithm>
using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
#define all(x) (x).begin(),(x).end()
#define sz(x) ((int)(x).size())

template<typename T>
T mod(T a, T b){
    return (a + b) % b;
}

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

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

// n を素因数分解
map<ll, ll> factor(ll n){
    map<ll, ll> mp;
    for (ll i = 2; i*i <= n; i++) {
        while (n % i == 0) {
            mp[i]++;
            n /= i;
        }
    }

    if (n > 1) {
        mp[n]++;
    }

    return mp;
}

// 文字列に "hoge" が含まれているか
// string str = "hogepiyo";
// if (str.find("hoge") != string::npos) {
//     cout << "文字列が含まれています" << endl;
// }

// char to string
// char c = 'a';
// string str = {c};

void solve(){
    int R, G, B, N;
    cin >> R >> G >> B >> N;

    ll ans = 0;
    for (int r = 0; r <= N / R; r++) {
        for (int g = 0; g <= N / G; g++) {
            int b = (N - R*r - G*g) / B;
            if (b >= 0 && R*r + B*b + G*g == N) {
                // cout << r << " " << g << " " << b << endl;
                ans++;
            }
        }
    }

    cout << ans << endl;


    return;
}

int main(int argc, char const* argv[])
{
    solve();
    return 0;
}


Measured memory_bytes: 256
package main

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

// I/O
type Scanner struct {
	sc *bufio.Scanner
}

func NewScanner() *Scanner {
	sc := bufio.NewScanner(os.Stdin)
	sc.Split(bufio.ScanWords)
	sc.Buffer(make([]byte, 1024), int(1e+9))
	return &Scanner{sc}
}

func (s *Scanner) nextStr() string {
	s.sc.Scan()
	return s.sc.Text()
}

func (s *Scanner) nextInt() int {
	i, e := strconv.Atoi(s.nextStr())
	if e != nil {
		panic(e)
	}
	return i
}

func (s *Scanner) nextFloat() float64 {
	f, e := strconv.ParseFloat(s.nextStr(), 64)
	if e != nil {
		panic(e)
	}
	return f
}

func (s *Scanner) nextRuneSlice() []rune {
	return []rune(s.nextStr())
}

func (s *Scanner) nextIntSlice(n int) []int {
	res := make([]int, n)
	for i := 0; i < n; i++ {
		res[i] = s.nextInt()
	}
	return res
}

func (s *Scanner) nextFloatSlice(n int) []float64 {
	res := make([]float64, n)
	for i := 0; i < n; i++ {
		res[i] = s.nextFloat()
	}
	return res
}

// Arithmetic
func max(nums ...int) int {
	m := nums[0]
	for _, i := range nums {
		if m < i {
			m = i
		}
	}
	return m
}

func min(nums ...int) int {
	m := nums[0]
	for _, i := range nums {
		if m > i {
			m = i
		}
	}
	return m
}

func abs(x int) int {
	if x > 0 {
		return x
	}
	return -x
}

func pow(x, y int) int {
	res := 1
	for i := 0; i < y; i++ {
		res *= x
	}
	return res
}

// Sort
type Val struct {
	id, num int
}
type ByNum []Val

func (a ByNum) Len() int           { return len(a) }
func (a ByNum) Less(i, j int) bool { return a[i].num < a[j].num }
func (a ByNum) Swap(i, j int)      { a[i], a[j] = a[j], a[i] }

func main() {
	sc := NewScanner()
	wtr := bufio.NewWriter(os.Stdout)
	A, B := sc.nextInt(), sc.nextInt()

	if A+B < 10 {
		fmt.Fprintln(wtr, A+B)
	} else {
		fmt.Fprintln(wtr, "error")
	}
	wtr.Flush()
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
using ll = int64_t;

void main_()
{
    int N;
    string s, t;
    cin >> N >> s >> t;

    for (int i = 0; i < N; ++i) {
        if (equal(begin(s) + i, end(s), begin(t))) {
            cout << N + i << endl;
            return;
        }
    }
    cout << N * 2 << endl;
}
int main()
{
    cin.tie(nullptr);
    cout.tie(nullptr);
    ios_base::sync_with_stdio(false);
    main_();
    return 0;
}


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

int main(void){
    vector<int> H(10010),W(10010);
    for(int i=0;i<10010;i++){
        cin>>H.at(i)>>W.at(i);
        
        if(H.at(i)==0 && W.at(i)==0)break;
        
        for(int j=0;j<H.at(i);j++){
            
            for(int k=0;k<W.at(i);k++){
                if((j+k)%2==0)cout<<'#';
                else cout<<'.';
            }

            cout<<endl;
        }
        cout<<endl;
    }
}



Measured memory_bytes: 3144
#include <iostream>
#include <cstdio>
#include <string>
#include <vector>
#include <algorithm>
#include <list>
#include <iomanip>
#include <queue>
#include <functional>
#include <cassert>
#include <cmath>


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

using namespace std;
using ll = long long;
using ull = unsigned long long;

int main() {

	int n;

	vector<int> t6, t9;

	cin >> n;

	for (int i = 1; i <= 100000; i *= 6) {
		t6.push_back(i);
	}
	for (int i = 9; i <= 100000; i *= 9) {
		t9.push_back(i);
	}

	vector<int> dp(100010);

	dp[0] = 0;

	int cnt = 0;
	for(int i = 1; i <= 100000; i++) {
		dp[i] = 100000;
		for (auto v: t6) {
			if (i - v >= 0) {
				dp[i] = min(dp[i], dp[i - v] + 1);
			}
		}
		for (auto v: t9) {
			if (i - v >= 0) {
				dp[i] = min(dp[i], dp[i - v] + 1);
			}
		}
	}

	cout << dp[n] NL;

	return 0;
}

Measured memory_bytes: 640
import java.util.Scanner;

public class Main {
  public static void main(String[] args) {
      Scanner input = new Scanner(System.in);
      int second = Integer.valueOf(input.next());
      int minute = secondToMinute(second);
      int hour = secondToHour(second);
      second = second % 60;
      System.out.println(hour + ":" + minute + ":" + second);
  }

  private static int secondToHour(int second) {
    return second / 3600;
  }

  private static int secondToMinute(int second) {
    return (second % 3600) / 60;
  }
}


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

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

int main()
{
	int n;
	cin >> n;
	string s, t;
	cin >> s >> t;

	int max = 0;
	REP(i, n){
		int count = 0;
		for (int j = 0; j + i < n; j++){
			if (s[i + j] != t[j]) break;
			else count++;
		}

		if (max < count) max = count;
	}

	cout << (int)s.size() + (int)s.size() - max << endl;


}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <queue>
#include <tuple>
#include <set>

using namespace std;

typedef tuple<int, int> tu;

struct smaller {
	bool operator()(tu a, tu b) {
		if (get<0>(a) == get<0>(b)) return get<1>(a)>get<1>(b);
		return get<0>(a)>get<0>(b);
	}
};

int V, E, r, s, t, d;

set<int> S; //最短距離が確定した頂点の集合
priority_queue<tu, vector<tu>, smaller> Q;
const int inf = 1000000000;

int main()
{
	ios::sync_with_stdio(false);
	cin >> V >> E >> r;
	vector<int> l(V, inf); //length
	vector<priority_queue<tu, vector<tu>, smaller>> e(V); //edge
	l[r] = 0;
	Q.push(make_tuple(0, r));
	S.insert(r);

	for (int i = 0; i<E; i++)
	{
		cin >> s >> t >> d;
		e[s].push(make_tuple(d, t));
	}

	while (!Q.empty())
	{
		while (!e[r].empty())
		{
			t = get<1>(e[r].top());
			if (S.count(t) == 1)
			{
				e[r].pop();
				continue;
			}
			d = get<0>(e[r].top());
			d += l[r];
			e[r].pop();
			Q.push(make_tuple(d, t));
		}
		while (!Q.empty())
		{
			t = get<1>(Q.top());
			if (S.count(t) == 1)
			{
				Q.pop();
			}
			else
			{
				d = get<0>(Q.top());
				l[t] = d;
				S.insert(t);
				break;
			}
		}
		r = t;
	}

	for (int i = 0; i<V; i++)
	{
		if (l[i] == inf)
		{
			cout << "INF" << endl;
		}
		else
		{
			cout << l[i] << endl;
		}
	}
	return 0;
}



Measured memory_bytes: 18324
#include<bits/stdc++.h>
using namespace std;
const int maxn=20;
int dp[2][20+1][1<<maxn],nx[20+1][1<<maxn][2];
char s[1<<maxn];
int n,m,ans,len;
int main()
{
    scanf("%d%d",&n,&m);
    int now=0;
    for(int i=0;i<=n;++i)
    {
        scanf("%s",s);
        for(int j=0;j<(1<<i);++j)
            if(s[j]=='1') dp[now][i][j]=1;
    }
    for(int i=1;i<=n;++i)
        for(int j=0;j<(1<<i);++j)
        {
            nx[i][j][0]=nx[i][j][1]=-1;
            for(int k=i-1;k>=0;--k)
                if((j>>k)&1)
                {
                    nx[i][j][1]=k;
                    break;
                }
            for(int k=i-1;k>=0;--k)
                if(((j>>k)&1)==0)
                {
                    nx[i][j][0]=k;
                    break;
                }
            //printf("len:%d num:%d 0:%d 1:%d\n",i,j,nx[i][j][0],nx[i][j][1]);
        }
    /*for(int j=1;j<=20;++j)
        for(int s=(1<<n)-1;s>=0;--s)
            if(dp[now][j][s])
        {

            printf("left:%d   totallen:%d      S:%d              dp:%d\n",0,j,s,dp[now][j][s]);
           // if(dp[now][0+1][s]>=m) len=0+1,ans=s;
        }*/
    for(int i=0;i<n;++i)
    {
        /*for(int j=0;j<(1<<i+1);++j)
            if(s[i+1][j]=='1') dp[now^1][i+1][j]=1;*/
        for(int j=n-i;j>=1;--j)
            for(int s=(1<<(i+j))-1;s>=0;--s)
            {
                if(!dp[now][i+j][s]) continue;
                //dp[now^1][i][s>>j]+=dp[now][i+j][s];
                int t=nx[j][s&((1<<j)-1)][0];
                if(t!=-1)
                {

                    //printf("(%d,%d) ,%d -> (%d,%d) ,%d\n",i,j,s,i+1,t,(s>>j<<t+1)|(s&(1<<(t+1))-1));
                    dp[now^1][i+t+1][(s>>j<<t+1)|(s&(1<<(t+1))-1)]+=dp[now][i+j][s];
                }
                t=nx[j][s&((1<<j)-1)][1];
                if(t!=-1)
                    dp[now^1][i+t+1][(s>>j<<t+1)|(s&(1<<(t+1))-1)]+=dp[now][i+j][s];
            }
        memset(dp[now],0,sizeof(dp[now]));
        now^=1;
        for(int j=1;i+1+j<=n;++j)
            for(int s=0;s<1<<(i+1+j);++s)
                dp[now][i+1][s>>j]+=dp[now][i+1+j][s];
        for(int s=(1<<(i+1))-1;s>=0;--s)
        {
           // printf("len : %d     %d              %d\n",i+1,s,dp[now][i+1][s]);
            if(dp[now][i+1][s]>=m) len=i+1,ans=s;
        }
        //for(int j=1;j<=20;++j)
        /*for(int s=(1<<n)-1;s>=0;--s)
            if(dp[now][j][s])
        {

            printf("left:%d   totallen:%d      S:%d              dp:%d\n",i+1,j,s,dp[now][j][s]);
           // if(dp[now][0+1][s]>=m) len=0+1,ans=s;
        }*/
    }
    //printf("%d %d\n",len,ans);
    for(int i=len-1;i>=0;--i)
        if(ans&(1<<i)) printf("1");else printf("0");
    return 0;
}


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

int main(){
    ll k, a, b, cnt;
    ll ans = 0;
    cin >> k >> a >> b;

    cnt = k + 1;
    ll i = 0;
    while(i * 2<= k){
        ll tmp = k - 2 * i;
        if (tmp + 1 >= a){
            cnt = max(cnt, tmp + 1 + i * (b - a));
        }
        i ++;
    }
    cout << cnt << endl;
    
}

Measured memory_bytes: 256
/**
*    created: 21.06.2020 01:01:59
**/
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
#define int long long
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep2(i, s, n) for (int i = (s); i < (int)(n); i++)
#define all(a) (a).begin(),(a).end()
#define mod 1000000007
#define pi acos(-1.0)
using namespace std;

signed main() {

    cin.tie(0);
    ios_base::sync_with_stdio(false);

    int n, h;
    cin >> n >> h;
    vector<int> a(n);
    vector<int> b(n);
    rep(i,n) cin >> a[i] >> b[i];
    sort(all(a));
    sort(all(b));
    int cnt = 0;
    int dam = 0;
    int t = lower_bound(all(b),a[n-1]) - b.begin();
    for (int i = n - 1; i >= t; i--) {
        dam += b[i];
        cnt++;
        if (dam >= h) {
            cout << cnt << endl;
            return 0;
        }
    }

    if ((h - dam) % a[n-1] == 0) cnt += (h - dam) / a[n-1];
    else cnt += (h - dam) / a[n-1] + 1;
    cout << cnt << endl;
    return 0;
}

Measured memory_bytes: 4824
#pragma GCC optimize("O3")  
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define endl "\n"
#define gcd(a,b) __gcd(a,b)
#define lcm(a,b) (a*b)/gcd(a,b)
#define mem(z,i) memset(z,i,sizeof(z))
#define eps 1e-7
#define I (int)
const int mod=(int)1e9+7;
const long long INF = 1000000000000000000LL;
//const int WASTE=∞;
//#define int long long
int power(int a,int b,int m){
	int i=1;
	while(b){
		if(b%2)
			i=(i*a)%mod;
		b/=2;
		a=(a*a)%mod;
	}
	return i;	
}
const int N=1e5+5;
signed main() {
	ios_base::sync_with_stdio(0); cin.tie(NULL); cout.tie(NULL);
    int h,n,s=0;
    cin>>h>>n;
    while(n--){
    	int i;
    	cin>>i;
    	s+=i;
    }
    if(s>=h) cout<<"Yes";
    else cout<<"No";

	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
  int N;
  cin >> N;
  string S;
  cin >> S;
  int x = 0;
  int M = 0;
  for (int i=0;i<N;i++){
    if (S.at(i) == 'I'){
      x += 1;
      if (x > M){
        M = x;
      }
    }
    else if (S.at(i) == 'D'){
      x -= 1;
    }
  }
  cout << M << endl;
  return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		String s = sc.next();
		int n = s.length();
		
		// 条件１
		if (!isKaibun(s)) {
			System.out.println("No");
			sc.close();
			return;
		}
		
		// 条件２
		String sub1 = s.substring(0, (n - 1) / 2);
		if (!isKaibun(sub1)) {
			System.out.println("No");
			sc.close();
			return;
		}
		
		// 条件３
		String sub2 = s.substring((n + 3) / 2 - 1, n);
		if (!isKaibun(sub2)) {
			System.out.println("No");
			sc.close();
			return;
		}
		
		System.out.println("Yes");
		sc.close();
	}
	
	static boolean isKaibun(String s) {
		char[] c = s.toCharArray();
		boolean isKaibun = true;
		int len = c.length;
		for (int i = 0; i < len / 2; i++) {
			if (c[i] != c[len - 1 - i]) {
				isKaibun = false;
				break;
			}
		}
		return isKaibun;
	}
}


Measured memory_bytes: 23252
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(n);++i)
#define ALL(A) A.begin(), A.end()

using namespace std;

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

bool isALLoneChar(string s){
	int n = (int)s.length();
	set<char> same; same.clear();
	rep (i, n){
		same.insert(s[i]);
	} // end rep

	return ((int)same.size() == 1);
}

int main()
{
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	
	string s; cin >> s;
	set<char> cand; cand.clear();

	int n = (int)s.length();
	rep (i, n){
		cand.insert(s[i]);
	} // end rep

	if (isALLoneChar(s)){
		cout << 0 << endl;
		return 0;
	} // end if

	int ans = 0;
	set<char>::iterator it = cand.begin();
	for (; it != cand.end(); ++it){
		char c = (*it);
//		cerr << "cand: " << c << endl;
		string u = s;
		for (int k = 0; k < n; ++k){
			string t = "";
			for (int i = 0; i < n - k; ++i){	
				if (u[i] != c){
					t += u[i];
				}else{
					if ((int)t.length() - 1 >= 0){
						t[(int)t.length() - 1] = c;
					} // end if
					t += c;
				} // end if
			} // end for
			t = t.substr(0,(int)t.length() - 1);
//			cerr << "t: " << t << endl;
			if (isALLoneChar(t)){
				int curr = (int)t.length();
				ans = max(ans, curr);
				break;
			} // end if
			u = t;
		} // end for
	} // end for

	cout << n - ans << endl;

	return 0;
}

Measured memory_bytes: 256
n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
mon_sum = 0
for i in range(n):
    m1 = min(a[i],b[i])
    m2 = min(a[i + 1],max(b[i] - a[i],0))
    mon_sum += m1 + m2
    a[i+1] = a[i + 1] -m2
print(mon_sum)

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

namespace ProgramingStudying2
{
    class Program
    {

        static void Main(string[] args)
        {
            var input = Console.ReadLine().Split();
            var a = int.Parse(input[0]);
            var b = int.Parse(input[2]);
            var op = input[1];

            if(op == "+")
            {
                Console.WriteLine(a + b);
            }
            else
            {
                Console.WriteLine(a - b);
            }
        }
    }
}


Measured memory_bytes: 27088
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <iomanip>
#include <cmath>
#include <stdio.h>
#include <queue>
#include <deque>
#include <cstdio>
#include <set>
#include <map>
#include <bitset>
#include <stack>
#include <cctype>
using namespace std;
long long dp[3030][3030][4] = { 0 };
long long a[3030][3030] = { 0 };
int main() {
	int r, c, K;
	cin >> r >> c >> K;
	for (int i = 0; i < K; i++) {
		int R, C;
		long long v;
		cin >> R >> C >> v;
		a[R][C] = v;
	}
	for (int i = 0; i <= r; i++) {
		for (int j = 0; j <= c; j++) {
			for (int k = 1; k < 4; k++) {
				dp[i][j][k] = -100000000000007;
			}
		}
	}
	for (int i = 1; i <= r; i++) {
		for (int j = 1; j <= c; j++) {
			for (int k = 3; k > 0; k--) {
				dp[i][j][k] = max(dp[i][j][k], dp[i][j][k - 1] + a[i][j]);
			}
			for (int k = 0; k < 4; k++) {
				if (i + 1 <= r) {
					dp[i + 1][j][0] = max(dp[i + 1][j][0], dp[i][j][k]);
				}
				if (j + 1 <= c) {
					dp[i][j + 1][k] = max(dp[i][j + 1][k], dp[i][j][k]);
				}
			}
		}
	}
	long long ans = 0;
	for (int i = 0; i < 4; i++) {
		if (ans < dp[r][c][i]) {
			ans = dp[r][c][i];
		}
	}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 358552
#include <stdio.h>
#include <string>
#include <iostream>
#include <iomanip>
#include <map>
#include <algorithm>
#include <vector>
#include <math.h>
#define INF 1000000007
using namespace std;

int main(void) {
	int n,k;cin >> n >> k;
	long long sum=0,index;
	for(int i=1; i<=33; i++){
		for(int j=1; j<=5; j++){
			index=(7*i+j-7)*9+6;
			if(index%11==k)sum++;
		}
	}
	sum*=n/33;
	n%=33;
	long long ans=0;
	for(int i=1; i<=n-2; i++){
		for(int j=1; j<=5; j++){
			index=(7*i+j-7)*9+6;
			if(index%11==k)ans++;
		}
	}
	cout << ans+sum << endl;
	return 0;
}


Measured memory_bytes: 256
n = int(input())
xy = [tuple(map(int, input().split())) for _ in range(n)]
p = [x + y for x, y in xy]
a1 = max(p) - min(p)
q = [x - y for x, y in xy]
a2 = max(q) - min(q)
print(max(a1, a2))

Measured memory_bytes: 130416
#include<bits/stdc++.h>
#include<atcoder/math>
using namespace std;
using namespace atcoder;
typedef long long ll;
#define rep(i,n) for(int i=0;i<n;i++)
#define repl(i,a,b) for(int i=a;i<b;i++)
typedef vector<int > vi;
typedef vector<pair<int, int > > vp;
int main(){
	//m containers ai matchboxes bi matches
	//burglar bag n matchboes
	int t;
	cin>>t;
	while(t--){
		ll n,m,a,b;
		cin>>n>>m>>a>>b;
		cout<<floor_sum(n,m,a,b)<<'\n';
	}

}

Measured memory_bytes: 3628
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import accumulate, permutations, combinations, product, groupby
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left
from fractions import gcd
from heapq import heappush, heappop
from functools import reduce
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def ZIP(n): return zip(*(MAP() for _ in range(n)))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7
 
L = INT()
print((L/3)**3)

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

#define LL long long
typedef pair<int, int> pii;

template< typename T > inline void read(T &x)
{
    static char _c;
    static bool _f;

    x = 0;
    _f = 0;
    _c = getchar();

    while(_c < '0' || '9' < _c) {if(_c == '-') _f = true; _c = getchar();}
    while('0' <= _c && _c <= '9') {x = (x << 1) + (x << 3) + (_c & 15); _c = getchar();}
    if(_f) x = -x;
}

template < typename T > inline void Min(T &x, T y) {if(y < x) x = y;}
template < typename T > inline void Max(T &x, T y) {if(x < y) x = y;}


#define lowbit(x) ((x) & -(x))
#define lson l,mid,id<<1
#define rson mid+1,r,id<<1|1
#define ls id<<1
#define rs id<<1|1
#define MID(l,r) ((l)+(((r)-(l))>>1))
#define fi first
#define se second
#define mk make_pair
#define pb push_back

const int INF = 0x3f3f3f3f;
const int MOD = (int) 1e9 + 7;
//const int MOD = (int) 998244353;
const int maxn = (int) 1e4 + 20;
const int maxm = (int) 1e6 + 20;
const double pi = (double) acos(-1.0);
const double eps = (double) 1e-8;

inline int sig(double x) {return x < -eps ? -1 : eps < x;}
LL fp(LL a, LL n, LL m = MOD) {LL res = 1; for(; n; n >>= 1, a = a * a % m) if(n & 1) res = res * a % m; return res;}

void work()
{
    int n, k;
    cin >>n >>k;
    cout <<(n + k - 1) / k <<endl;
}


int main()
{
#ifdef yukihana0416
freopen("in.txt", "r", stdin);
//freopen("out.txt", "w", stdout);
#endif // yukihana0416
//    get_prime();
    int tc = 1;
//    read(tc);
    for(int ca = 1; ca <= tc; ca++)
    {
//        printf("Case #%d: ", ca);
        work();
    }
    return 0;
}


Measured memory_bytes: 256
import qualified Data.ByteString.Char8 as BS
import Data.Maybe

getInts :: IO [Int]
getInts = map (fst . fromJust . BS.readInt) . BS.words <$> BS.getLine

main :: IO ()
main = do
  _ <- readLn :: IO Int
  p <- getInts
  
  print $ length $ filter id $ zipWith (<=) p (tail $ scanl min maxBound p)

Measured memory_bytes: 4348
N = int(input())
A = list(map(int, input().split()))
B = list(map(int, input().split()))

count = 0
i = N
j = N - 1
tmpA = A[i]
tmpB = B[j]
while (i >= 0 and j >= 0):
    if tmpA - tmpB > 0:
        tmpA -= tmpB
        count += tmpB
        j -= 1
        if j >= 0:
            tmpB = B[j]
        if i - j > 1:
            i -= 1
            if i >= 0:
                tmpA = A[i]
    elif tmpB - tmpA > 0:
        tmpB -= tmpA
        count += tmpA
        i -= 1
        if i >= 0:
            tmpA = A[i]
        if i - j < 0:
            j -= 1
            if j >= 0:
                tmpB = B[j]
    else:
        count += tmpA
        i -= 1
        j -= 1
        if i >= 0 and j >= 0:
            tmpA = A[i]
            tmpB = B[j]

print(count)


Measured memory_bytes: 19284
#include <bits/stdc++.h>
#define ll long long int
using namespace std;
ll cnt[100003]={0};
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
  ll n;
  cin>>n;
  ll a[n],i,j,k;
  for(i=0;i<n;i++)
  cin>>a[i];
  ll ans=0;
  for(i=0;i<n;i++)
  {
      ans=(ans^a[i]);
  }
  for(i=0;i<n;i++)
  {
      cout<<(ans^a[i])<<" ";
  }
}

Measured memory_bytes: 5136
def maxChain(n,p):
    m = [[0 for i in range(n+1)] for i in range(n+1)]
    for l in range(2, n+1):
        for i in range(1, n - l + 2):
            j = i + l - 1
            m[i][j] = float("inf")
            for k in range(i, j):
                m[i][j] = min(m[i][j], m[i][k] + m[k+1][j] + p[i - 1] * p[k] * p[j])
    return str(m[1][n])
n = int(input())
p = []
for i in range(n):
    L = list(map(int, input().split()))
    if i == 0:
        p.append(L[0])
        p.append(L[1])
    else:
        p.append(L[1])
print(maxChain(n,p))

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

int main() {
  int n,m;
  cin>>n>>m;
  bool l=true;
  if(n==1&&m==0){
    cout<<0<<endl;
    return 0;
  }
  map<int,int> mp;
  for(int i=1; i<=n; i++){
    mp[i]=10;
  }
  for(int i=1; i<=m; i++){
    int s,c;
    cin>>s>>c;
    if(mp[s]!=10 && mp[s]!=c){
      l=false;
    }else{
      mp[s]=c;
    }
  }
  if(mp[1]==10){
    mp[1]=1;
  }else if(mp[1]==0 && n!=1){
    l=false;
  }
  for(int i=1; i<=n; i++){
    if(i==1){
      continue;
    }else{
      if(mp[i]==10){
        mp[i]=0;
      }
    }
  }
  if(!l){
    cout<<-1<<endl;
  }else{
    for(int i=1; i<=n; i++){
      cout<<mp[i];
    }
  }
}

Measured memory_bytes: 256
#include <algorithm>
#include <iostream>
#include <cstring>
#include <cstdio>
#define MX 500005
#define oo 1000000001

using namespace std;

template <typename T> void read(T& x)
{
	bool f = 0; x = 0; char c = getchar();
	while(!isdigit(c) && c!='-') c = getchar();
	if(c == '-') f = 1, c = getchar();
	while(isdigit(c)) x = x*10+c-'0', c = getchar();
	if(f) x = -x;
}

template <typename T> T abs(const T& x) {return (x>0) ? (x) : (-x);}

int n, q, d;
int seq[MX], pos[MX], low[MX];

int main()
{
	read(n); read(d);
	for(int i=1; i<=n; i++) read(seq[i]);
	read(q);
	pos[0] = d;
	for(int i=1; i<=n; i++) pos[i] = min(pos[i-1], abs(pos[i-1]-seq[i]));
	low[n+1] = 1;
	for(int i=n; i>=1; i--)
		if(low[i+1]*2 <= seq[i]) low[i] = low[i+1];
		else low[i] = min(+oo, low[i+1]+seq[i]);
	for(int i=1; i<=q; i++)
	{
		int p; read(p);
		if(pos[p-1] >= low[p+1]) puts("YES");
		else puts("NO");
	}
	return 0;
}

Measured memory_bytes: 7808
#include <bit>
#include <bitset>
#include <assert.h>
#include <stdio.h>
#include <string.h>
#include <algorithm>
#include <sstream>
#include <iostream>
#include <set>
#include <map>
#include <vector>
#include <math.h>
#include <stdlib.h>
#include <queue>
#include <stack>
using namespace std;
int main()
{
    int K;
    int N = 7;
    int count = 0;
    cin >> K;
    while (true) {
        N = N % K;
        count++;
        if (N == 0) {
            break;
        }
        N = N * 10 + 7;
        if (count > K) {
            break;
        }
    }
    if (count > K) {
        cout << -1;
    }
    else {
        cout << count;
    }
}

Measured memory_bytes: 3572
#include<bits/stdc++.h>
using namespace std;
#define int long long 
#define FIO ios_base::sync_with_stdio(0); cin.tie(0);
#define MOD (1000000007LL)
vector <int> g[200003];
const int N = 200005;
int dp[N], sz[N], fac[N], inv[N], ways[N], res[N];
int add(int a, int b, int m){
  if(b < 0) b += m;
  int res = ((a % m) + (b % m)) % m;
  res %= m;
  return res;
}
 
int mul(int a, int b, int m){
  if(b < 0) b += m;
  int res = ((a % m) * (b % m)) % m;
  res %= m;
  return res;
}
 
int sub(int a, int b, int m){
  int res = (a - b + m) % m;
  res %= m;
  return res;
}

int modexp(int x, unsigned int y){
  int res = 1;
  x %= MOD;
  if(!y) return 0;
  while(y > 0){
    if(y & 1) res = mul(res, x, MOD);
    y >>= 1;
    x = mul(x, x, MOD);
  }
  return res;
}

int modularInverse(int a){
  return modexp(a, MOD - 2) % MOD;
}

void dfs(int x,int p){
    sz[x] = 1;
    for (auto u: g[x]){
        if (u == p) continue;
        dfs(u,x);
        sz[x] += sz[u];
    }
}

void dfs2(int x,int p,int n){
    dp[x] = 1;
    int temp = n - 1;
    for (auto u: g[x]){
        if (u == p) continue;
        dfs2(u,x,sz[u]);
        dp[x] = mul(dp[x],dp[u],MOD);
        // cout << x << " " << temp << " " << temp - sz[u] << " " << sz[u] << "\n";
        int temp2 = mul(fac[temp],mul(inv[temp - sz[u]],inv[sz[u]],MOD),MOD);
        dp[x] = mul(dp[x],temp2,MOD);
        temp -= sz[u];
    }
} 
void reroot(int x, int p,int n){
    res[x] = dp[x];
    for (auto u: g[x]){
        if(u == p) continue;
        sz[x] -= sz[u];
        dp[x] = mul(dp[x],modularInverse(dp[u]),MOD);
        int temp1 = mul(fac[n-1],mul(inv[n-1-sz[u]],inv[sz[u]],MOD),MOD);
        dp[x] = mul(dp[x],modularInverse(temp1),MOD);
        dp[u] = mul(dp[u],dp[x],MOD);
        int temp2 = mul(fac[n-1],mul(inv[n-1-sz[x]],inv[sz[x]],MOD),MOD);
        dp[u] = mul(dp[u],temp2,MOD);
        sz[u] += sz[x];
        reroot(u,x,n);
        sz[u] -= sz[x];
        dp[u] = mul(dp[u],modularInverse(temp2),MOD);
        dp[u] = mul(dp[u],modularInverse(dp[x]),MOD);
        dp[x] = mul(dp[x],temp1,MOD);
        dp[x] = mul(dp[x],dp[u],MOD);
        sz[x] += sz[u];
    }
}
int32_t main(){
    FIO
    fac[0] = 1;
    for(int i = 1; i < N - 1; ++i){
        fac[i] = mul(i, fac[i - 1], MOD);
    }
    inv[0] = 1;
      for(int i = 1; i < N - 1; ++i){
        inv[i] = modularInverse(fac[i]);
    }
    int n;
    cin >> n;

    for (int i = 1; i < n; i++){
        int x,y;
        cin >> x >> y;
        g[x].push_back(y);
        g[y].push_back(x);
    }
    dfs(1,-1);
    // for (int i = 1; i <= n; i++) cout << sz[i] << '\n';
    dfs2(1,-1,n);
    reroot(1,-1,n);
    for (int i = 1; i <= n; i++) cout << res[i] << '\n';
    }

Measured memory_bytes: 23664
# include <iostream>
# include <vector>
# include <map>


using namespace std;


typedef std::vector<std::pair<long long, long long>> factor_result;
factor_result factor(long long base) {
    vector<pair<long long, long long>> fs;

    for (long long i=2; i*i <= base; i++) {
        if (base % i == 0) {
            long long cnt = 0;

            while (base % i == 0) {
                base /= i;
                cnt++;
            }

            fs.emplace_back(i, cnt);
        }
    }
    if (base > 1) {
        fs.emplace_back(base, 1);
    }

    return fs;
}


int main() {
    long long a, b; cin >> a >> b;
    auto ra = factor(a);
    auto rb = factor(b);

    map<int, int> cm;

    for (auto ra_: ra) {
        int e = ra_.first;
        if (cm.find(e) == cm.end()) cm[e] = 1;
        else cm[e]++;
    }

    for (auto rb_: rb) {
        int e = rb_.first;
        if (cm.find(e) == cm.end()) cm[e] = 1;
        else cm[e]++;
    }

    int ans = 1;
    for (auto ce: cm) {
        if (ce.second == 2) ans++;
    }

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



Measured memory_bytes: 256
#include<bits/stdc++.h>
#define REP(i,n) for(int i=0;i<n;i++)
#define RREP(i,n) for(int i=n;i>=0;i--)
#define FOR(i,m,n) for(int i=m;i<n;i++)
#define ALL(v) v.begin(), v.end()
#define RALL(v) v.rbegin(), v.rend()
using namespace std;
typedef long long ll;
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
//const ll INF = 1LL << 60;
//const int INF = 1001001001;

int main(void){
    int n;
    string s;
    cin >> n >> s;
    int ans=1;
    FOR(i,1,n){
        if(s[i-1]!=s[i]) ans++;
    }
    cout << ans;
    return 0;
}

Measured memory_bytes: 3760
process.stdin.resume();
process.stdin.setEncoding('utf8');

var lines = [];
var reader = require('readline').createInterface({
  input: process.stdin,
  output: process.stdout
});
reader.on('line', (line) => {
  lines.push(line);
});
reader.on('close', () => {
  console.log(lines[0].split(" ")[0] - lines[0].split(" ")[1] + 1);
});

Measured memory_bytes: 21320
#include<bits/stdc++.h>
#define N 200050
#define ll long long
#define pb push_back
#define x first
#define y second
using namespace std;
double pi = acos(-1);
int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    double r; cin>>r;
    cout<<fixed<<setprecision(20)<<2.0*pi*r;
    return 0;
}


Measured memory_bytes: 3800
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using static System.Console;
namespace AtCoder.AGC019
{
    class ReverseAndCompare
    {
        public static void Main()
        {
            var chars = "abcdefghijklmnopqrstuvwxyz";
            var str = ReadLine().Trim();
            WriteLine((long)str.Length * (str.Length + 1) / 2 - chars.Select(_ => str.Where(c => c == _).Count()).Select(_ => (long)_ * (_ + 1) / 2).Sum() + 1);
        }
    }
}

Measured memory_bytes: 13368
#include <bits/stdc++.h>
using namespace std;
#define null NULL
#define mp make_pair
#define pb(a) push_back(a)
#define sz(a) ((int)(a).size())
#define all(a) a.begin() , a.end()
#define fi first
#define se second
#define relaxMin(a , b) (a) = min((a),(b))
#define relaxMax(a , b) (a) = max((a),(b))
#define SQR(a) ((a)*(a))
#define PI 3.14159265358979323846
typedef vector<int> vi;
typedef pair<int,int> pii;
typedef long long ll;

const int MAX = 15;

int h, w;
char in[MAX][MAX];

deque<char> Apply(int row, const vector<pii>& prs){
  deque<char> res;
  for(int i = sz(prs) - 1;i >= 0;--i){
    int a = prs[i].fi, b = prs[i].se;
    res.push_front(in[row][a]);
    res.pb(in[row][b]);
  }
  return res;
}

bool fine = false;

bool Validate(const vector<pii>& _prs){
  vector<pii> prs;
  for(const auto& e : _prs)
    if(e.fi != e.se) prs.pb(e);
  for(const auto& e : _prs)
    if(e.fi == e.se) prs.pb(e);

  vector<deque<char>> wrds;
  for(int i = 0;i < h;++i)
    wrds.pb(Apply(i, prs));

  while(!wrds.empty()){
    int ss = sz(wrds);
    for(int i = 0;i < min(2, sz(wrds));++i){
      auto a = wrds[i];
      auto b = a;
      reverse(all(b));

      if(sz(wrds) == 1){
        return a == b;
      }

      int j;
      for(j = 0;j < sz(wrds);++j)
        if(i != j && wrds[j] == b)
          break;

      if(j == sz(wrds)) continue;
      wrds.erase(wrds.begin() + max(i, j));
      wrds.erase(wrds.begin() + min(i, j));
      break;
    }
    if(sz(wrds) == ss) return false;
  }

  return true;
}

void Iterate(vector<pii>& prs, bool has_same){
  if(fine) return;

  vector<char> free(w, true);
  for(const auto& e : prs)
    free[e.fi] = free[e.se] = false;

  if(count(all(free), true) == 0){
    fine = (fine || Validate(prs));
  } else {
    for(int a = 0;a < w;++a)
      if(free[a]){
        if(!has_same) prs.pb(mp(a, a)),
                      Iterate(prs, true),
                      prs.pop_back();
        for(int b = a + 1;b < w;++b)
          if(free[b]) prs.pb(mp(a, b)),
                      Iterate(prs, has_same),
                      prs.pop_back();
        break;
      }
  }
}

int main(){
  scanf("%d%d", &h, &w);
  for(int i = 0;i < h;++i)
    scanf("%s", in[i]);

  vector<pii> prs;
  Iterate(prs, false);

  printf(fine ? "YES\n" : "NO\n");

  return 0;
}


Measured memory_bytes: 384
#include <algorithm>
#include <cassert>
#include <cstring>
#include <iostream>

using namespace std;

#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i, n) FOR(i, 0, n)
#define TRACE(x) cout << #x << " = " << x << endl
#define _ << " _ " <<

typedef long long llint;

int main(void) {
  int n;
  scanf("%d", &n);
  vector<int> a(2*n);
  REP(i, 2*n) scanf("%d", &a[i]);
  sort(a.begin(), a.end());
  int ans = 0;
  for (int i = 0; i < 2*n; i += 2)
    ans += a[i];
  printf("%d\n", ans);
  return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<complex>
using namespace std;
 
#define rep(i, n) for(int i = 0; i < (int)n; i++)
 
int main(){
	int k, s;
	cin >> k >> s;
	int count = 0;
	rep(i, k + 1) {
        rep(j, k + 1){
            int z = s - i - j;
            if (0<= z && z <= k) {
                count++;
            }
        }
    }
    cout << count << endl;
	return 0;
}


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

using namespace std;

#define debug(n) cerr << #n << ':' << n << endl;
#define dline    cerr << __LINE__ << endl;

using ll = long long;
using ull = unsigned long long;
template<class T, class U> using P = pair<T,U>;
template<class T> using Heap = priority_queue<T>;
template<class T> using heaP = priority_queue<T,vector<T>,greater<T>>;
template<class T,class U> using umap = unordered_map<T,U>;
template<class T> using uset = unordered_set<T>;

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

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

template<class T, size_t N, class U>
void Fill(T (&a)[N], const U&v){
    fill((U*)a,(U*)(a+N),v);
}

template<class T,class U>
istream& operator >> (istream&is, P<T,U>&p){
  is >> p.first >> p.second;
  return is;
}

template<class T>
istream& operator >> (istream&is, vector<T>&v){
  for(auto&e:v){
    is >> e;
  }
  return is;
}

int main(){
  int n,q; cin >> n >> q;
  vector<int> line(n); cin >> line;
  vector<int> from_list(n);
  {
    map<int,int> mp;
    for(int i = 0; i < n; ++i){
      if(mp.count(line[i]) == 0){
	from_list[i] = -1;
      } else {
	from_list[i] = mp[line[i]];
      }
      mp[line[i]] = i;
    }
  }
  vector<P<int,int>> queries(q); cin >> queries;
  for(auto&e:queries){e.first--;e.second--;}
  static vector<P<int,int>> r_base[500000];
  for(int i = 0; i < q; ++i)
    r_base[queries[i].second].emplace_back(queries[i].first,i);
  vector<int> vec;
  vector<int> ans(q);
  for(int i = 0; i < n; ++i){
    // debug(i);
    auto it = lower_bound(vec.begin(),vec.end(),from_list[i]);
    if(it == vec.end() || *it != from_list[i])vec.insert(it,from_list[i]);
    for(auto e:r_base[i]){
      ans[e.second] = i-e.first+1-(vec.end()-lower_bound(vec.begin(),vec.end(),e.first));
      // debug(e.first);
      // debug(e.second);
      // debug(distance(st.lower_bound(e.first),st.end()));
    }
  }
  for(auto e:ans)cout << e << endl;
}


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

typedef vector<int> vi;
typedef pair<int, int> pii;
#define endl "\n"
#define sd(val) scanf("%d", &val)
#define ss(val) scanf("%s", &val)
#define sl(val) scanf("%lld", &val)
#define debug(val) printf("check%d\n", val)
#define all(v) v.begin(), v.end()
#define PB push_back
#define MP make_pair
#define FF first
#define SS second
#define ll long long
#define ull unsigned long long
#define MOD 1000000007
#define clr(val) memset(val, 0, sizeof(val))
#define what_is(x) cerr << #x << " is " << x << endl;
#define OJ                            \
    freopen("input.txt", "r", stdin); \
    freopen("output.txt", "w", stdout);
#define FIO                           \
    ios_base::sync_with_stdio(false); \
    cin.tie(NULL);                    \
    cout.tie(NULL);

ll n, w;
ll we[105];
ll va[105];
ull mem[105][100005];

ll dp(ll n, ll v)
{
    if (n == 0)
    {
        if (v == 0)
        {
            return 0;
        }
        else
        {
            return INT_MAX;
        }
    }

    if (mem[n][v] != -1)
    {
        return mem[n][v];
    }

    return mem[n][v] = min(we[n] + dp(n - 1, v - va[n]), dp(n - 1, v));
}

int main()
{
    cin >> n >> w;

    for (ll i = 1; i <= n; i++)
    {
        cin >> we[i] >> va[i];
    }

    memset(mem, -1, sizeof(mem));

    for (ll i = 100000; i > 0; i--)
    {
        if (dp(n, i) <= w)
        {
            cout << i << endl;
            break;
        }
    }

    return 0;
}

Measured memory_bytes: 85672
#include<iostream>
#include<sstream>
#include<vector>
#include<iterator>
using namespace std;

int main(void)
{
	long long A, B, C;
	cin >> A >> B >> C;

	long long sum;
	if(C <= B)
		sum = B + C;
	else if(C <= A+B)
		sum = B + C;
	else
		sum = A + 2*B + 1;

	cout << sum << endl;

	return 0;
}


Measured memory_bytes: 256
S = int(input())
m = (10**9)+7
l = [1,1]
for i in range(2,S+1) :
    l.append(l[-1]*i)

ans = 0
for i in range(S//3) :
    kou = i+1
    maru = S - 3*kou
    shikiri = i
    ans += l[maru+shikiri] // (l[maru]*l[shikiri])

print(int((ans%m)))


Measured memory_bytes: 11144
program Project1;

{$APPTYPE CONSOLE}

uses
  SysUtils;
var
  a:string;
begin
  try
    { TODO -oUser -cConsole メイン : ここにコードを記述してください }
    Readln(a);

    a[4]:='8';
    Writeln(a);
    Readln;
  except
    on E: Exception do
      Writeln(E.ClassName, ': ', E.Message);
  end;
end.


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

using ll = long long;

//constant
const ll MOD = 1e+9 + 7;
const double EPS = 1e-10;

#define REP(i, n) for (ll i = 0; i < n; i++)
#define ALL(x) (x).begin(),(x).end()
#define RALL(x) (x).rbegin(), (x).rend()

//debug
#define DUMP(x)  cerr << #x << " = " << (x) << endl;
#define DEBUG(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << endl;

// view vector
template<typename T> void view(T e) { std::cout << e << std::endl; }
template<typename T> void view(const std::vector<T>& v) { for (const auto& e : v) { std::cout << e << " "; } std::cout << std::endl; }
template<typename T> void view(const std::vector<std::vector<T> >& vv) { for (const auto& v : vv) { view(v); } }


// ***************************************


int main(void){

    ll N;
    cin >> N;

    int x;
    cin >> x;
    vector<ll> L{x};
    
    REP(i, N - 1) {
        cin >> x;
        if (x > L.back()) {
            L.push_back(x);
        }
        else {
            auto idx = lower_bound(ALL(L), x) - L.begin();
            L[idx] = x;
        }
    }


    cout << L.size() << endl;

    return 0;
}


Measured memory_bytes: 3740
// Package main provides
//
// File:  b.go
// Author: ymiyamoto
//
// Created on Thu Jan 17 11:41:22 2019
//
package main

import "fmt"

func main() {
	var S string
	fmt.Scan(&S)

	for i := range S {
		for j := i + 1; j < len(S); j++ {
			if S[i] == S[j] {
				fmt.Println("no")
				return
			}
		}
	}
	fmt.Println("yes")
}


Measured memory_bytes: 512
// Danielxlr
// https://atcoder.jp/contests/dp/tasks/dp_a
// dynamic programming

#include <bits/stdc++.h>
using namespace std;
#define optimizar_io ios_base::sync_with_stdio(false);cin.tie(0);

typedef long long int ll;
int N;
ll h[100010];

int main() {
	optimizar_io
	ll dp[100010];

	cin >> N;
	for (int i = 0; i < N; i++) cin >> h[i];
	dp[0] = 0;
	for (int i = 1; i < N; i++) {
		if (i - 2 >= 0)
			dp[i] = min(dp[i - 1] + abs(h[i] - h[i - 1]), dp[i - 2] + abs(h[i] - h[i - 2]));
		else
			dp[i] = dp[i - 1] + abs(h[i] - h[i - 1]);
	}
	cout << dp[N - 1] << "\n";
	return 0;
}

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

using namespace std;

#define FOR(i, a, b) for(int i = (a); i < (b); ++i)
#define FORR(i, a, b) for(int i = (a); i > (b); --i)
#define REP(i, n) for(int i = 0; i < (n); ++i)
#define REPR(i, n) for(int i = n; i >= 0; i--)
#define FOREACH(x, a) for(auto &(x) : (a))
#define VECCIN(x)                                                              \
    for(auto &youso_ : (x)) cin >> youso_
#define mp make_pair
#define bitcnt __builtin_popcount
#define All(a) (a).begin(), (a).end()
template <typename T = long long> inline T IN() {
    T x;
    cin >> x;
    return (x);
}
inline void CIN() {}
template <class Head, class... Tail>
inline void CIN(Head &&head, Tail &&... tail) {
    cin >> head;
    CIN(move(tail)...);
}
#define CINT(...)                                                              \
    int __VA_ARGS__;                                                           \
    CIN(__VA_ARGS__)
#define LCIN(...)                                                              \
    ll __VA_ARGS__;                                                            \
    CIN(__VA_ARGS__)
#define SCIN(...)                                                              \
    string __VA_ARGS__;                                                        \
    CIN(__VA_ARGS__)
#define Yes(a) cout << (a ? "Yes" : "No") << "\n"
#define YES(a) cout << (a ? "YES" : "NO") << "\n"

typedef long long ll;
typedef vector<int> V;
typedef vector<ll> VL;
typedef pair<int, int> P;
typedef pair<ll, ll> PL;
typedef priority_queue<int> PQ;
typedef priority_queue<int, V, greater<int>> PQG;

const int INF = 1e9;
const int MOD = 1e9 + 7;
const ll LINF = 1e18;

int s;
V a;
map<int, int> an;

int main() {
    cin >> s;
    a.push_back(s);
    REP(i, INF) {
        an[a[i]]++;
        if(a[i] % 2) {
            a.push_back(3 * a[i] + 1);
        } else {
            a.push_back(a[i] / 2);
        }
        if(an[a[i + 1]]) {
            cout << i + 2 << "\n";
            break;
        }
    }
    return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
int main(){
  int a, i, j, n, min, mini, sum=0;
  int A[100][100], flag[100], t[100];

  scanf("%d", &n);

  for(i = 0; i < n ; i++){
    flag[i] = 0;
    t[i] = 2001;
  }
  t[0] = 0;

  for(i = 0; i < n; i++){
    for(j = 0; j < n; j++){
      scanf("%d", &A[i][j]);
    }
  }
  for(a = 0; a < n - 1; a++){
    min = 2001;
    for(i = 0; i < n; i++){
      if(t[i] < min && flag[i] == 0){
    min = t[i];
    mini = i;
      }
    }
    flag[mini] = 1;

    for(i = 0; i < n; i++){
      if(A[mini][i] != -1 && A[mini][i] < t[i] && flag[i]==0){
    t[i] = A[mini][i];
      }
    }

  }

  for(i = 0; i < n; i++){
    sum += t[i];
  }
  printf("%d\n", sum);



  return 0;
}

Measured memory_bytes: 640
<?php
list($H1, $M1, $H2, $M2, $K) = explode(' ', trim(fgets(STDIN)));

$wu = 0;

if($H1 === $H2){
	$wu = $M2 - $M1;
}else{
	$wu = ($H2 - $H1 -1) * 60;
	$wu += 60 - $M1;
	$wu += $M2;
}

echo $wu - $K;
?>

Measured memory_bytes: 16208
#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 n, m, q;
vector<int> a, b, c, d;
int ans;

void dfs(vector<int> A){
  if(A.size() == n + 1){
    int count = 0;
    rep(i,q){
      if(A[b[i]] - A[a[i]] == c[i]){
        count += d[i];
      }
    }
    ans = max(ans,count);
    return;
  }
  
  A.push_back(A.back());
  while(A.back() <= m){
    dfs(A);
    A.back()++;
  }
}
  
int main() {
  cin >> n >> m >> q;
  a = b = c = d = vector<int>(q);
  rep(i,q){
    cin >> a[i] >> b[i] >> c[i] >> d[i];
  }
  dfs(vector<int>(1,1));
  cout << ans;
  return 0;
}

Measured memory_bytes: 3612
// AOJ 2524: Mysterious Operator
// 2017.10.5 bal4u@uu

#include <stdio.h>

int main()
{
	int n, a, b, nn, m, m1, m2, m3, ans;

	scanf("%d", &n);
	for (ans = 0, m3 = 1, m = 10; ; m3 = m, m *= 10) {
		nn = n;
		m1 = nn / m, m2 = nn % m;
		a = m2 + m1, b = m2 - m1;
		if (m2 / m3 > 0 && !(a & 1) && b >= 0 && !(b & 1)) ans++;
		if (m1 == 0) break;
	}
	printf("%d\n", ans);
	return 0;
}

Measured memory_bytes: 1848
#include <bits/stdc++.h>
#define bug(x) cout << #x << " = " << x << endl
#define fr(x) freopen(x,"r",stdin)
#define fw(x) freopen(x,"w",stdout)
#define all(x) x.begin(),x.end()
#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define reset(x) memset(x,0,sizeof(x))
#define up(i,l,r) for(int i=l;i<=r;i++)
#define down(i,r,l) for(int i=r;i>=l;i--)
using namespace std;
typedef long long int ll;
typedef vector<int> vi;
typedef pair<int,int> pii;
int n,m,k,xa,ya,xb,yb,Ti;

int main(){
    ios_base::sync_with_stdio(0);
    cin>>n>>m>>k;
    cin>>xa>>ya>>xb>>yb;
    xa--, ya--, xb--, yb--;
    
  	vector<vector<char>> table(n,vector<char>(m));
  	up(i,0,n-1) up(j,0,m-1) cin>>table[i][j];
    
  	vector<vector<int>> dis(n,vector<int>(m,2e9));
  	// bfs()
    dis[xa][ya]=0;
    queue<pii> q;
    q.push({xa,ya});
    while(!q.empty()){
        int xx=q.front().fi,yy=q.front().se;
        q.pop();
        if(xx==xb&&yy==yb)
            break;
        up(i,1,k){
            if(xx+i==n||table[xx+i][yy]!='.'||dis[xx+i][yy]<=dis[xx][yy]) break;
            else if(dis[xx+i][yy]>dis[xx][yy]+1){
                dis[xx+i][yy]=dis[xx][yy]+1;
                q.push({xx+i,yy});
            }
        }
        up(i,1,k){
            if(xx-i==-1||table[xx-i][yy]!='.'||dis[xx-i][yy]<=dis[xx][yy]) break;
            else if(dis[xx-i][yy]>dis[xx][yy]+1){
                dis[xx-i][yy]=dis[xx][yy]+1;
                q.push({xx-i,yy});
            }
        }
        up(i,1,k){
            if(yy+i==m||table[xx][yy+i]!='.'||dis[xx][yy+i]<=dis[xx][yy]) break;
            else if(dis[xx][yy+i]>dis[xx][yy]+1){
                dis[xx][yy+i]=dis[xx][yy]+1;
                q.push({xx,yy+i});
            }
        }
        up(i,1,k){
            if(yy-i==-1||table[xx][yy-i]!='.'||dis[xx][yy-i]<=dis[xx][yy]) break;
            else if(dis[xx][yy-i]>dis[xx][yy]+1){
                dis[xx][yy-i]=dis[xx][yy]+1;
                q.push({xx,yy-i});
            }
        }
    }
  
    Ti=dis[xb][yb];
    if(Ti==2e9) Ti=-1;
    cout<<Ti<<endl;
    return 0;
}

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

int main() {
	int n; cin >> n;
	vector<int> a(n + 1), f(n + 1);
	for (int i = 1; i <= n; i++) cin >> a[i];
	for (int i = 2; i <= n; i++) {
		f[i] = f[i - 1] + abs(a[i] - a[i - 1]);
		if (i > 2) f[i] = min(f[i], f[i - 2] + abs(a[i] - a[i - 2]));
	}
	cout << f[n] << '\n';
}

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

int main() {
  int a,b,c,d;
  cin >> a >> b >> c >> d;

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


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

int main(){
   int A, B, H, M;
   cin >> A >> B >> H >> M;
   double hs, ms;
   hs = 0.5 * (H*60+M);
   ms = 6 * M;
   double sita = abs(hs - ms);
   if (sita > 180){
      sita = 360 - sita;
   }
   cerr << "hs; " << hs << " " << "ms: " << ms << " " << "sita: " << sita << endl;
   double rsita;
   rsita = M_PI * sita / 180;
   double c2;
   c2 = pow(A, 2) + pow(B, 2) - 2 * A * B * cos(rsita);
   double c;
   c = sqrt(c2);
   cout << setprecision(20) << c << endl;
}



Measured memory_bytes: 4160
r,g,b,n = $stdin.read.split(" ").map(&:to_i)

count = 0
(0..3000).each do |ri|
  if ri*r>n
    break
  end
  (0..3000).each do |gi|
    if ri*r + gi*g > n
      next
    end

    bi = (n - ri * r - gi * g)/b

    if ri*r + gi*g + bi*b == n
      count += 1
    end
  end
end

puts count

Measured memory_bytes: 1788
#include <iostream>

int main(int argc, char const* argv[])
{
    int N, K;
    std::cin >> N >> K;
    if (K == 1) {
        std::cout << 0 << std::endl;
        return 0;
    }
    std::cout << N-K << std::endl;
    return 0;
}


Measured memory_bytes: 256