akhauriyash/Code-Regression huggingface dataset:
#include <cstdio>
#include <cstring>
#include <cmath>
#include <iostream>
#include <sstream>
#include <algorithm>
#include <numeric>
#include <functional>
#include <vector>
#include <queue>
#include <string>
#include <complex>

#define REP(i,n) for (int i = 0; i < (n); i++)
#define FOR(i,s,n) for (int i = (s); i < (n); i++)
#define ALLOF(c) c.begin(), c.end()
#define RANGEOF(c,i,n) c.begin() + (i), c.begin() + (i) + (n)
#define EPS 1e-9
#define INF 1000000000
using namespace std;

typedef complex<int> POINT;
template <class T>
class vevector : public vector<vector<T>>
{
public:
	using vector<vector<T>>::operator []; 
	T& operator [](const POINT &index) { return (*this)[index.real()][index.imag()]; }
};

template <class T> T read() { T t; cin >> t; return t; }
template <> POINT read<POINT>() { int x, y; cin >> x >> y; return POINT(x, y); }
template <class T> vector<T> read(int n) { vector<T> v; REP(i,n) { v.push_back(read<T>()); } return v; }
template <class T> vevector<T> read(int n, int m) { vevector<T> v; REP(i,n) v.push_back(read<T>(m)); return v; }
template <class T> void write(const T &t) { cout << t << endl; }
template <class T> void write(const T &t, const T &t2) { cout << t << ' ' << t2 << endl; }

template <class T> void write(const vector<T> &v)
{
	ostringstream ss; 
	for (auto x : v) ss << x << ' ';
	auto s = ss.str();
	cout << s.substr(0, s.length() - 1) << endl;
}

struct _Reader { template <class T> _Reader operator ,(T &rhs) { cin >> rhs; return *this; } };
#define READ(t,...) t __VA_ARGS__; _Reader(), __VA_ARGS__

void solve();
int main() { solve(); return 0; }

vector<unsigned char> isPrime;
vector<int> primes;
void initPrimes(int n)
{
	isPrime = vector<unsigned char>(n + 1, true);
	isPrime[0] = isPrime[1] = false;
	FOR(i, 2, n)
	{
		if (!isPrime[i]) continue;
		primes.push_back(i);
		for (int j = i * 2; j <= n; j += i)
			isPrime[j] = false;
	}
}
/// template end ///

void solve()
{
	while (true)
	{
		typedef POINT P;
		auto n = read<int>();
		if (!n) { break; }

		int sx = 0, sy = 0, ex = 0, ey = 0;
		vector<P> v;
		v.push_back(P(0,0));
		REP(i, n-1)
		{
			READ(int, ni, di);
			P tbl[] = { P(-1,0), P(0,1), P(1,0), P(0,-1), };
			P p = v[ni] + tbl[di];
			sx = min(sx, p.real()); sy = min(sy, p.imag());
			ex = max(ex, p.real()); ey = max(ey, p.imag());
			v.push_back(p);
		}
		write(ex - sx + 1, ey - sy + 1);
	}
}

Measured memory_bytes: 1204
import sys
sys.setrecursionlimit(10 ** 6)  # 再帰関数の再帰の深さを設定
to_index = lambda x: int(x) - 1  # 入力した数字に1を引いたものを返す
print_list_in_2D = lambda x: print(*x, sep="\n")  # リストの要素を改行を挟んで表示する関数

# 入力を整数に変換して受け取る
def input_int(): return int(input())

def map_int_input(): return map(int, input())

MII = map_int_input

def MII_split(): return map(int, input().split())

def MII_to_index(): return map(to_index, input())

def MII_split_to_index(): return map(to_index, input().split())

# 入力全てを整数に変換したものの配列を受け取る
def list_int_inputs(): return list(map(int, input()))

LII = list_int_inputs

def LII_split(): return list(map(int, input().split()))

# 2次元リスト化
def LII_2D(rows_number): return [LII() for _ in range(rows_number)]

def LII_split_2D(rows_number): return [LII_split() for _ in range(rows_number)]

N, K = MII_split()

amari = abs(N % K)

print(min(amari, abs(abs(amari) - K)))

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

const int maxn = 55;

int n;
int a[maxn];

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

    int lo = min_element(a, a + n) - a;
    int hi = max_element(a, a + n) - a;
    printf("%d\n", 2 * (n - 1));
    if (abs(a[lo]) < abs(a[hi])) {
        for (int i = 0; i < n; ++i) if (i != hi) {
            printf("%d %d\n", hi + 1, i + 1);
        }
        for (int i = 1; i < n; ++i) printf("%d %d\n", i, i + 1);
    } else {
        for (int i = 0; i < n; ++i) if (i != lo) {
            printf("%d %d\n", lo + 1, i + 1);
        }
        for (int i = n - 1; i > 0; --i) printf("%d %d\n", i + 1, i);
    }

    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <numeric>
#include <cmath>

using namespace std;

int main(){
    int N, M, X, out;
    cin >> N >> M >> X;
    vector<int> C(N), sum(N), sum_store(N);
    vector< vector<int> > A(M, vector<int>(N));
    for(int i=0;i<N;i++){
        cin >> C.at(i);
        for(int j=0;j<M;j++){
            cin >> A.at(j).at(i);
        }
    }

    // 全列挙

    int min = 9999999;

    for(int i=0;i<pow(2,N);i++){
        int n = i;
        int cost = 0;
        vector<int> sum(M);
        for(int j=0;j<M;j++)sum.at(j) = 0;

        for(int j=N-1;j>=0;j--){
            if(n>=pow(2,j)){
                cost += C.at(j);
                for(int k=0;k<M;k++){
                    sum.at(k) += A.at(k).at(j);
                }
                n -= pow(2,j);
            }
        }

        for(int j=0;j<M;j++){
            if(sum.at(j)<X)break;
            if(j==M-1){
                if(min>cost)min = cost;
            }
        }

    }

    if(min==9999999)min = -1;

    cout << min << endl;
}

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

using namespace std;
#define ll long long
#define ld long double
#define f first
#define s second

ll gc[205][205];

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

    ll n , ans=0;
    cin >> n;
    for(int i=1; i<=n; i++)
    {
        for(int j=1; j<=n; j++)
        {
            gc[i][j] = __gcd(i,j);
        }
    }

    for(int i=1; i<=n; i++)
    {
        for(int j=1; j<=n; j++)
        {
            for(int k=1; k<=n; k++)
            {
                ans += __gcd(gc[i][j] , gc[i][k]);
            }
        }
    }

    cout << ans << "\n";

    return 0;
}

Measured memory_bytes: 3916
fun main(args: Array<String>) {
    val s = readLine()!!
    val t = readLine()!!
    val sameMapS = mutableMapOf<Char, MutableList<Int>>()
    val sameMapT = mutableMapOf<Char, MutableList<Int>>()
    for (i in 0 until s.length) {
        if (sameMapS[s[i]] == null) sameMapS[s[i]] = mutableListOf(i) else sameMapS[s[i]]!!.add(i)
        if (sameMapT[t[i]] == null) sameMapT[t[i]] = mutableListOf(i) else sameMapT[t[i]]!!.add(i)
    }
    for (key in sameMapT.keys) {
        if (sameMapT[key]!!.size <= 1) continue
        var c = ""
        for (i in sameMapT[key]!!) {
            if (c != "" && s[i].toString() != c) {
                println("No")
                return
            }
            c = s[i].toString()
        }
    }
    for (key in sameMapS.keys) {
        if (sameMapS[key]!!.size <= 1) continue
        var c = ""
        for (i in sameMapS[key]!!) {
            if (c != "" && t[i].toString() != c) {
                println("No")
                return
            }
            c = t[i].toString()
        }
    }
    println("Yes")
}


Measured memory_bytes: 63828
#include<bits/stdc++.h>
#define ll long long
using namespace std;
char a[110];	ll k;	int b[110] = {0};
int main(){
	scanf("%s", a);
	scanf("%lld", &k);
	int n = strlen(a);
	int len = 0;
	int t = 0;
	for (int i = 0; i < n; i++) {
		if (i == 0 || a[i] == a[i-1]) {
			t++;
		}
		else {
			b[len++] = t;
			t = 1;
		}
	}
	b[len++] = t;
	ll ans = 0;
	if(len > 1) {
		for (int i = 1; i < len-1; i++) {
			ans = ans + b[i]/2;
		}
		ans = ans*k;
		if (a[0] == a[n-1]) ans = ans + (k-1)*((b[0]+b[len-1])/2) + b[0]/2+b[len-1]/2;
		else ans = ans + k*(b[0]/2)+k*(b[len-1]/2);
	}
	else ans = (k*b[0])/2;
	printf("%lld\n", ans);
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <array>
#include <queue>
#include <deque>
#include <map>
#include <set>
#include <sstream>
#include <stdio.h>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <list>
#include <numeric>
#include <stack>
#include <iomanip>

using namespace std;

#define Rep(i,a,b) for(int i = a; i < b; i++)
#define rep(i,b) Rep(i,0,b)
#define allof(a) (a).begin(), (a).end()

typedef long long ll;
const int inf = 1e9 + 7;
const ll infll = 1ll << 60ll;
const ll mod = 1e9 + 7;
// 0~3までは右左下上 4~7までは斜め
constexpr int dx[] = { 1, 0, -1, 0, 1, 1, -1, -1 };
constexpr int dy[] = { 0, -1, 0, 1, 1, -1, -1, 1 };

template<typename T> void chmax(T &a, T b) { a = std::max(a, b); }
template<typename T> void chmin(T &a, T b) { a = std::min(a, b); }
template<typename T> void chadd(T &a, T b) { a = a + b; }

namespace {  // 名前なし名前空間
	// gcd, lcm は C++17 でstdに標準入りしたので言語のバージョンに注意
	// 最大公約数
	ll gcd(ll a, ll b) {
		if (b == 0) return a;
		return gcd(b, a % b);
	}

	// 最小公倍数
	ll lcm(ll a, ll b) {
		return a / gcd(a, b) * b;
	}
}

int main() {

	int n, k;
	cin >> n >> k;
	string s;
	cin >> s;
	vector<int> raw(n);
	rep(i, n) {
		if (s[i] == 'L') raw[i] = 0;
		else raw[i] = 1;
	}
	// k回できる
	// 左は0 右は1

	// 変わるのは両端だけ

	int ans = 0;
	//Rep(i, 1, n - 1) {
	//	if (raw[i] == 0) {
	//		if (raw[i - 1] == 0) ans++;
	//	}
	//	else {
	//		if (raw[i + 1] == 1) ans++;
	//	}
	//}
	//if (n != 1) {
	//	if (raw[0] == 1) if (raw[1] == 1) ans++;
	//	if (raw[n - 1] == 0) if (raw[n - 2] == 1) ans++;
	//}
	rep(i, n - 1) {
		if (raw[i] == raw[i + 1]) ans++;
	}
	// 最大で2k増える
	// でもマックスは n - 2

	ans = min(n - 1, ans + 2 * k);

	cout << ans << endl;

	return 0;
}


Measured memory_bytes: 896
#include <stdio.h>
#include <stdlib.h>

//*
//プラキュー（二分ヒープ）（最低限バージョン）
//int PQhikaku(int i,int j);//jの方が優先度が高いならtrueを返す
int PQhikaku(long long*heap,int i,int j){return heap[i]<heap[j];}
void heap_utod(long long*heap,int n){
  if(2*n>heap[0])return;
  int rflag=(2*n+1<=heap[0])&&(PQhikaku(heap,2*n,2*n+1));
  if(PQhikaku(heap,n,2*n+rflag)){
    long long temp=heap[2*n+rflag];
    heap[2*n+rflag]=heap[n];
    heap[n]=temp;
    heap_utod(heap,2*n+rflag);
  }
}
void heap_dtou(long long*heap,int n){
  if(n==1||PQhikaku(heap,n,n/2))return;
  long long temp=heap[n];
  heap[n]=heap[n/2];
  heap[n/2]=temp;
  heap_dtou(heap,n/2);
}
long long PQpop(long long*heap){
  long long rr=heap[1];
  heap[1]=heap[heap[0]--];
  heap_utod(heap,1);
  return rr;
}
void PQpush(long long*heap,long long n){
  heap[++heap[0]]=n;
  heap_dtou(heap,heap[0]);
}
//*/

typedef struct edge{int x,y;}point;

int max(int a,int b){
  if(a > b){
    return a;
  }
  return b;
}

int compare_pair(const void *a,const void *b){
  if((*(point*)a).x > (*(point*)b).x) return 1;
  if((*(point*)a).x < (*(point*)b).x) return -1;
  if((*(point*)a).y > (*(point*)b).y) return 1;
  return -1;
}

int main(void){
  int N, M;
  long long h[100001];
  scanf("%d%d", &N, &M);

  point A[N];
  for (int i = 0; i < N; i++) {
    scanf("%d%d", &A[i].x, &A[i].y);
  }

  qsort(A, N, sizeof(point), compare_pair);

  long long ans = 0;
  int num = 0;

  for (int i = 1; i <= M; i++) {
    while(A[num].x <= i && num < N) PQpush(h, A[num++].y);
    if(h[0]) ans += PQpop(h);
  }

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

  return 0;
}

Measured memory_bytes: 1788
#include <cstdio>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <string>
#include <iostream>
#include <vector>
#include <queue>
#include <unordered_map>
#include <random>
#include <stack>
#include <set>
#include <unordered_set>

#define bug(x) cout<<"zdongdebug1: "<<x<<endl;
#define bug2(x, y) cout<<"zdongdebug2: "<<x<<" "<<y<<endl;
#define bug3(x, y, z) cout<<"zdongdebug3: "<<x<<" "<<y<<" "<<z<<endl;
using namespace std;
typedef long long ll;
const int maxn = 65;
const int mod = 1000000007;

int main() {
#ifdef suiyuan2009
  freopen("/Users/suiyuan2009/CLionProjects/icpc/input.txt", "r", stdin);
  //freopen("/Users/suiyuan2009/CLionProjects/icpc/output.txt", "w", stdout);
#endif
  string s;
  cin>>s;
  int n;
  cin>>n;
  vector<char>st, nd;
  int cc = 0;
  while(n--){
    int tt;
    cin>>tt;
    if(tt==1){
      cc = 1 - cc;
    } else {
      char tmp;
      cin>>tt>>tmp;
      if((tt==1&&!cc)||(tt==2&&cc)){
        st.push_back(tmp);
      } else {
        nd.push_back(tmp);
      }
    }
  }
  if(cc){
    for(int i=nd.size()-1;i>=0;i--)cout<<nd[i];
    for(int i=s.size()-1;i>=0;i--)cout<<s[i];
    for(int i=0;i<st.size();i++)cout<<st[i];
    cout<<endl;
  } else {
    for(int i=st.size()-1;i>=0;i--)cout<<st[i];
    cout<<s;
    for(int i=0;i<nd.size();i++)cout<<nd[i];
    cout<<endl;
  }
  return 0;
}


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

// Template Headers {{{
using pii = pair<int, int>; using vpii = vector<pii>;
using vi = vector<int>; using vvi = vector<vi>;
using ll = long long; using vll = vector<long long>;
template <class T> using min_queue = priority_queue<T, vector<T>, greater<T>>;
template <class T> istream &operator>>(istream &, vector<T> &);
template <class T> ostream &operator<<(ostream &, const vector<T> &);
template <class T, class U> istream &operator>>(istream &, pair<T, U> &);
template <class T, class U> ostream &operator<<(ostream &, const pair<T, U> &);
template <class T> struct Inf { static constexpr T inf() { return std::numeric_limits<T>::has_infinity() ? std::numeric_limits<T>::infinty() : std::numeric_limits<T>::max(); } };
template <> struct Inf<int> { static constexpr int inf() { return 0x3f3f3f3f; } };
template <> struct Inf<long long> { static constexpr long long inf() { return 0x3f3f3f3f3f3f3f3fLL; } };
constexpr int INF = Inf<int>::inf(); constexpr ll BINF = Inf<ll>::inf();
// mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
// }}}

int solve() {
	int n, m; cin >> n >> m;
	vvi g(n);
	vpii e(m); cin >> e;
	for (auto &p : e) p.first--, p.second--;
	vi token(n);
	for (int i=0;i<m;i++) {
		int u, v; tie(u, v) = e[i];
		g[u].push_back(i), g[v].push_back(i);
		token[u] ^= 1;
	}
	vi vis(n);
	function<void(int)> dfs = [&] (int u) {
		// cerr << "dfs " << u << ": " << token;
		for (auto edg : g[u]) {
			int eu, ev; tie(eu, ev) = e[edg];
			if (ev == u) swap(eu, ev);
			if (vis[ev]) continue;
			// cerr << "dfsedge " << u << ' ' << eu << ' ' << ev << endl;
			vis[ev] = 1;
			dfs(ev);
			if (token[ev]) {
				swap(e[edg].first, e[edg].second);
				token[u] ^= 1; token[ev] ^= 1;
			}
		}
		// cerr << "dfsend " << u << ": " << token;
	};
	for (int i=0;i<n;i++) if (!vis[i]) {
		vis[i] = 1;
		dfs(i);
		if (token[i]) return cout << -1 << endl, 0;
	}
	for (auto ed : e) cout << ed.first + 1 << ' ' << ed.second + 1 << endl;
	cerr << token;
	return 0;
}

// Template Main {{{
int main() {
	ios::sync_with_stdio(0);
	// precompute();
	// int t; cin >> t; for (int i=1;i<=t;i++)
	solve();
	// cout << "Case #" << i << ": ", solve();
	return 0;
}

template <class T> istream &operator>>(istream &is, vector<T> &v) {
	for (auto it=v.begin();it!=v.end();++it) is >> *it;
	return is;
}

template <class T> ostream &operator<<(ostream &os, const vector<T> &v) {
	for (auto it=v.begin();it!=v.end();) os << *it, os << " \n"[++it==v.end()];
	return os;
}

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

template <class T, class U> ostream &operator<<(ostream &os, const pair<T, U> &p) {
	return os << p.first << ' ' << p.second;
}
// }}}

// vim: fdm=marker


Measured memory_bytes: 17792
import numpy as np
import sys
input = sys.stdin.readline

N,K=map(int,input().split())
h=np.array(list(map(int,input().split())))

cost=np.array([-1 for _ in range(N)])


for i in range(N):
    if i==0:
        cost[i]=0
    else:
        siten=max(i-K,0)
        min_cost=np.min(cost[siten:i]+abs(h[siten:i]-h[i]))
        cost[i]=min_cost

print(cost[N-1])

Measured memory_bytes: 22956
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.math.BigInteger;
import java.util.ArrayList;
import java.util.Comparator;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;

public class Main {
	static boolean bElapsed = false;
	StringBuilder sb = new StringBuilder();
	List<String> list = new ArrayList<>();
	Set<String> set = new HashSet<>();
	Map<String,String> map = new HashMap<>();

	void solve(BufferedReader br) throws Exception {
		String line = br.readLine();
		int n = Integer.parseInt(line);
		String s = br.readLine();
		String t = br.readLine();
		int i, j;
		boolean bBreak = false;
		for (i=0; i<s.length(); i++) {
			bBreak = false;
			for (j=0; j<t.length()-i; j++) {
				if (s.charAt(i+j) != t.charAt(j)) {
					bBreak = true;
					break;
				}
			}
			if (!bBreak) break;
		}
		if (bBreak) pln(n*2);
		else pln(i+n);
	}

	class Person {
		int no;
		int a;
		public Person(int no, int a) {
			this.no = no;
			this.a = a;
		}
	}
	class PersonComp implements Comparator<Person> {
		public int compare(Person o1, Person o2) {
			return o2.a - o1.a;
		}
	}
	void p(char c) {
		System.out.print(c);
	}
	void pln(char c) {
		System.out.println(c);
	}
	void p(long l) {
		System.out.print(l);
	}
	void pln(long l) {
		System.out.println(l);
	}
	void p(String s) {
		System.out.print(s);
	}
	void pln(String s) {
		System.out.println(s);
	}
	//Integer.MAX_VALUE=2147483647>10^9
	//Long.MAX_VALUE=9223372036854775807L>10^18
	public static void main(String[] args) throws Exception {
		long start = System.currentTimeMillis();
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		new Main().solve(br);
		long end = System.currentTimeMillis();
		if (bElapsed) {
			System.out.println((end-start) + "ms");
		}
	}
}


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

typedef long long int ll;
typedef long double ld;
typedef vector<ll> vi;
typedef vector<string> vs;
typedef pair<ll,ll> P;
typedef vector<P> vp;
#define REP(i,n) for(int i=0;i<n;i++)
#define FOR(i,m,n) for(int i=m;i<n;i++)
#define REPR(i,n) for(int i=n-1;i>=0;i--)
#define FORR(i,n,m) for(int i=n-1;i>=m;i--)
#define ARR(array) for(int i=0;i<array.size();i++)
#define all(in) (in).begin(),(in).end()
#define ALL(in,K) (in),(in)+(K)

#define INF 1e18
#define MOD 1000000007
#define SIZE 10005
#define PI 	3.14159265358979323846

ll gcd(ll a, ll b) { return b ? gcd(b, a%b) : a; } //最大公約数
ll lcm(ll a, ll b) { return a/gcd(a, b)*b; } //最小公倍数

ll input(){
  ll a;
  cin >> a;
  return a;
}

int main(){
  long long s;
  cin >> s;
  long long diff = 999;
  while(s){
    diff = min(diff,abs(s%1000-753));
    s/=10;
  }
  cout << diff << endl;
}

Measured memory_bytes: 256
#[allow(unused_imports)]
use std::cmp::*;
#[allow(unused_imports)]
use std::collections::*;
use std::io::{Write, BufWriter};
// https://qiita.com/tanakh/items/0ba42c7ca36cd29d0ac8
macro_rules! input {
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

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

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

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

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

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

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

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

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

// bias: +1
fn sim(n: usize, s: &[char], mut v: usize, td: &[(char, char)]) -> usize {
    for &(t, d) in td {
        if s[v] == t {
            if d == 'L' {
                if v == 0 {
                    return 0;
                }
                v -= 1;
            } else {
                v += 1;
                if v >= n {
                    return n + 1;
                }
            }
        }
    }
    v + 1
}

fn solve() {
    let out = std::io::stdout();
    let mut out = BufWriter::new(out.lock());
    macro_rules! puts {
        ($($format:tt)*) => (write!(out,$($format)*).unwrap());
    }
    input! {
        n: usize, q: usize,
        s: chars,
        td: [(chars, chars); q],
    }
    let td: Vec<(char, char)> = td.into_iter().map(|(a, b)| (a[0], b[0])).collect();
    let mut pass = n + 1;
    let mut fail = 0;
    while pass - fail > 1 {
        let mid = (pass + fail) / 2;
        if sim(n, &s, mid - 1, &td) > 0 {
            pass = mid;
        } else {
            fail = mid;
        }
    }
    let fst = pass;
    pass = 0;
    fail = n + 1;
    while fail - pass > 1 {
        let mid = (pass + fail) / 2;
        if sim(n, &s, mid - 1, &td) < n + 1 {
            pass = mid;
        } else {
            fail = mid;
        }
    }
    let snd = pass;
    puts!("{}\n", if snd >= fst { snd + 1 - fst } else { 0 });
        
}

fn main() {
    // In order to avoid potential stack overflow, spawn a new thread.
    let stack_size = 104_857_600; // 100 MB
    let thd = std::thread::Builder::new().stack_size(stack_size);
    thd.spawn(|| solve()).unwrap().join().unwrap();
}


Measured memory_bytes: 24828
#include <bits/stdc++.h>
using namespace std;
#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++)
typedef long long ll;

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

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

static constexpr ll d = 1000000007;

ll stairs(int cur, int n, const vector<int>& a, vector<ll>& memo) {
  if (cur == n) return 1;
  if (cur > n  || binary_search(a.begin(), a.end(), cur)) return 0;
  if (memo[cur] != -1) return memo[cur];
  ll ans = 0;
  ans += stairs(cur+1, n, a, memo) % d;
  ans += stairs(cur+2, n, a, memo) % d;
  memo[cur] = ans % d;
  return memo[cur];
}

ll stairs(int cur, int n, const vector<int>& a) {
  vector<ll> memo(n, -1);
  return stairs(cur, n, a, memo);
}

int main() {
  cin.tie(nullptr);
  ios::sync_with_stdio(false);
  cout << setprecision(20);
  int n, m;
  cin >> n >> m;
  vector<int> a(m);
  rep(i, m) {
    cin >> a[i];
  }
  cout << stairs(0, n, a) << endl;
  return 0;
}


Measured memory_bytes: 7296
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll INF= 1LL << 60;
#define REP(i,n) for(ll i=0; i<n; i++)
#define FOR(i,a,n) for(ll i=a; i<n; i++)

struct c{
    int num,sum;
};
int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);    
    int n;
    cin >> n;
    vector<int> A(n);
    vector<int> B(n);
    vector<c> C(n);
    REP(i,n){
        cin >> A[i] >> B[i];
        C[i].num= i;
        C[i].sum= A[i]+B[i];
    }
    sort(C.begin(), C.end(), [](const c &a, const c &b) { return a.sum > b.sum; });

    ll s= 0;
    REP(i,n){
        // cout << C[i].num << " " << C[i].sum << endl;
        s+= (i&1)?-B[C[i].num]:A[C[i].num];
        // cout << s << endl;
    }
    cout << s << endl;
}   

Measured memory_bytes: 1792
import java.util.*;

public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int n = sc.nextInt();
    String s = sc.next();
    int[] b = new int[n + 1];
    int[] w = new int[n + 1];
    int p = 0;
    for(int i = 0; i < n; i++) {
      if(s.charAt(i) == '.') p++;
    }
    w[0] = p;
    for(int i = 0; i < n; i++) {
      if(s.charAt(i) == '.') { 
        w[i + 1] = w[i] - 1;
        b[i + 1] = b[i];
      } else {
        w[i + 1] = w[i];
        b[i + 1] = b[i] + 1;
      }
    }
    int ans = n;
    for(int i = 0; i <= n; i++) {
      ans = Math.min(ans, b[i] + w[i]);
    }
    System.out.println(ans);
  }
}


Measured memory_bytes: 27976
#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 W, H, x, y, r;
    cin >> W >> H >> x >> y >> r;
    if (0 <= x-r && x+r <= W && 0 <= y-r && y+r <= H) cout << "Yes" << endl;
    else cout << "No" << endl;
    return 0;
}


Measured memory_bytes: 3112
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int maxn=1e5+10;
int a[maxn];
int b[maxn];
int main()
{
    int m,n;
    cin>>n;

    int k=0;
    for(int i=1;i<=n;i++)
        cin>>a[i];
    for(int i=1;i<=n;i++)
    {
        if(a[i]!=i)
            k++;
    }
    if(k==2||k==0)
        puts("YES");
    else
        puts("NO");


    return 0;
}


Measured memory_bytes: 256
import bisect,collections,copy,heapq,itertools,math,numpy,string
#from operator import itemgetter
import sys
def I(): return int(sys.stdin.readline().rstrip())
def LI(): return list(map(int,sys.stdin.readline().rstrip().split()))
def S(): return sys.stdin.readline().rstrip()
def LS(): return list(sys.stdin.readline().rstrip().split())
X = I()
x = 100
i = 0
while x < X:
  x = math.floor(x*1.01)
  i+=1
print(i)

Measured memory_bytes: 27200
//#include"cpp_kyopro.h"
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>
#include <stdlib.h>
#include <math.h>
#include <string.h>
#include<stdio.h>

using namespace std;
int main() {
	int h, w; cin >> h >> w;
	vector<string> v(h );
	for (int i = 0; i < h; i++) {
		cin >> v[i];
	}
	for (int i = 0; i < w+2; i++) cout << "#";
	printf("\n");
	for (int i = 0; i < h; i++)cout << "#" << v[i] << "#" << endl;
	for (int i = 0; i < w+2; i++) cout << "#";


	return 0;
}




Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<cmath>
#include<cstring>
#include<string>
#include<stack>
#include<queue>
#include<vector>
#include<algorithm>
#include<iomanip>
#include<set>
typedef long long int ll;
using namespace std;
#define FOR(i,a,b) for (int i=(a);i<(b);i++)
#define REP(i,n) for (int i=0;i<(n);i++)
#define EREP(i,n) for (int i=1;i<=(n);i++)
#define ALL(a) (a).begin(),(a).end()
//#define EVEL 1

#ifdef EVEL
#define DEB(X) cout << #X << ":" <<X<<" " ;
#define TF(f) f ? cout<<"true  " : cout<<"false ";
#define END cout<<"\n";
#else
#define DEB(X) {}
#define TF(f) {}
#define END {}
#endif
const int MOD = 1000000007;
const int INF = 2000000000;

    ll N,K;
    ll A[3];
    ll ans=1;
int main(){
    ios_base::sync_with_stdio(false);
    cin>>N;
    EREP(i,N){
        if(i==1)continue;
        for(int k=2;;k++){
            ll temp=pow(i,k);
            if(temp>N)break;
            ans=max(ans,temp);
        }
    }
    cout<<ans;
    return 0;
}


Measured memory_bytes: 256
INF = 1001001001
H, N = map(int, input().split())
ab = [list(map(int, input().split())) for _ in range(N)]
dp = [INF] * (20000)
dp[0] = 0
for a,b in ab:
    for j in range(H):
        if dp[j+a] > dp[j] + b:
            dp[j+a] = dp[j] + b
print(min(dp[H:]))

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

struct node {
    int start = 0;
    int end = 0;
};

void depth_search(map<int, vector<int> > &a, map<int, node> &nodes, int &time, int current) {
    time++;
    nodes[current].start = time;
    for (int i=0; i<a[current].size(); i++) {
        if ( nodes[a[current][i]].start == 0 ) {
            depth_search(a, nodes, time, a[current][i]);
        }
    }
    time++;
    nodes[current].end = time;
}

int main() {
    int n;
    cin >> n;
    map<int, vector<int> > a;
    for (int i=0; i<n; i++) {
        int u, k, v;
        cin >> u >> k;
        for (int j=0; j<k; j++) {
            cin >> v;
            a[u].push_back(v);
        }
    }
    
    int time = 0;
    map<int, node> nodes;
    for (int i=0; i<n; i++) {
        node nd; 
        nodes[i] = nd;
    }
    for (int i=1; i<=n; i++) {
        if ( nodes[i].start == 0 ) {
            depth_search(a, nodes, time, i);
        }
    }
    
    for (int i=1; i<=n; i++) {
        cout << i << " " << nodes[i].start << " " << nodes[i].end << endl;
    }
}

Measured memory_bytes: 3156
import java.util.Scanner;

public class Main { 

	public static void main(String[] args) {
    	Scanner sc = new Scanner(System.in);
    	String[] numberAandB = sc.nextLine().split(" ");
    	int numberA = Integer.parseInt(numberAandB[0]);
    	int numberB = Integer.parseInt(numberAandB[1]);
    	int result = -100000;
    	
    	int plusAB = numberA + numberB;
    	int minusAB = numberA - numberB;
    	int multiAB = numberA*numberB;
    	if(result <= plusAB) {
    		result = plusAB;
    	}
    	if(result <= minusAB) {
    		result = minusAB;
    	}
    	if(result <= multiAB) {
    		result = multiAB;
    	}
    	System.out.println(result);
    	
    	
	}
}

Measured memory_bytes: 23252
def factorization(n):
    arr = []
    temp = n
    for i in range(2, int(-(-n**0.5//1))+1):
        if temp%i==0:
            cnt=0
            while temp%i==0:
                cnt+=1
                temp //= i
            arr.append([i, cnt])

    if temp!=1:
        arr.append([temp, 1])

    if arr==[]:
        arr.append([n, 1])

    return arr

n = int(input())
if(n == 1):
  print(0)
  exit()
a = factorization(n) 
sum = 0
for i in a:
  m = i[1]
  s = 1
  while(m >= s):
    sum += 1
    m -= s
    s += 1
    
print(sum)

Measured memory_bytes: 9488
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <bitset>    // bitset
#include <cctype>    // isupper, islower, isdigit, toupper, tolower
#include <cmath>     // pow
#include <cstdint>   // int64_t, int*_t
#include <cstdio>    // printf
#include <deque>     // deque
#include <iomanip>   // setprecision
#include <iostream>  // cout, endl, cin
#include <map>       // map
#include <queue>     // queue, priority_queue
#include <set>       // set
#include <stack>     // stack
#include <string>    // string, to_string, stoi
#include <tuple>     // tuple, make_tuple
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <utility>       // pair, make_pair
#include <vector>        // vector
using namespace std;

int gcd(long long a, long long b) { return b != 0 ? gcd(b, a % b) : a; }
// cout << fixed << setprecision(10);
// vector<vector<int>> vec(H, vector<int>(W))    // int H*W
// int binary_search(int key) {
//     int ng = -1;
//     int ok = (int)a.size();
//     while(abs(ok - ng) > 1) {
//         int mid = (ok + ng) / 2;
//         if(isOK(mid, key))
//             ok = mid;
//         else
//             ng = mid;
//     }
//     return ok;
// }
int main() {
    int N, a, b, c;
    cin >> N;
    vector<int> L(N);
    for(size_t i = 0; i < N; i++) {
        cin >> L[i];
    }
    sort(L.begin(), L.end());
    int ans = 0;
    for(int i = 0; i < N - 2; i++) {
        int I = L[i];
        for(int j = i + 1; j < N - 1; j++) {
            int J = L[j];
            for(int k = j + 1; k < N; k++) {
                int K = L[k];
                if(K >= I + J) {
                    continue;
                }
                if(I < J + K && J < I + K) {
                    ans++;
                }
            }
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 888
//#include <fsociety>
#include <cmath>
#include <deque>
#include <algorithm>
#include <iterator>
#include <list>
#include <map>
#include <unordered_map>
#include <queue>
#include <set>
#include <unordered_set>
#include <stack>
#include <string>
#include <vector>
#include <fstream>
#include <iostream>
#include <iomanip> 
#include <stdio.h>
//end of libraries ;
// freopen("input.txt","r",stdin);
// freopen("output.txt","w",stdout);
// ll lmax(ll o , ll w) {if(o>w)return o; return w;}
// ll lmin(ll o , ll w) {if(o<w)return o; return w;}
#define LNF 3999999999999999999
#define INF 999999999
#define N 9000003
#define PI 3.14159265359
#define F first
#define S second
#define pb push_back
#define ll long long
#define fcin ios_base::sync_with_stdio(false),cin.tie(0),cout.tie(0);
using namespace std;
ll n , x , sum = 0 , d[N];
int main(){
fcin;
	cin >> n;
	for(ll i = 1 ; i <= n ; i++){
		cin >> x;
		d[x]++;
		sum += x;
	}
	ll q;
	cin >> q;
	while(q--){
		ll x , y;
		cin >> x >> y;
		sum += (d[x]*(y-x));
		d[y] += d[x];
		d[x] = 0;
		cout << sum << '\n';
		}


}

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

int main() {
  int N, l, r;
  cin >> N;
  
  int sum = 0;
  for (int i = 0; i < N; i++) {
    cin >> l >> r;
    sum += r - l + 1;
  }
  
  cout << sum << endl;
}

Measured memory_bytes: 256
#include<stdio.h>

int main()

{

    char S[101]={'\0'};

    int n=0,i=0,m=0;

    scanf("%s",S);

    while(S[i]!='\0')

    {

        n++;

        i++;

    }

    for(i=0;i<n/2;i++)

    if(S[i]!=S[n-i-1])

    m++;

    printf("%d",m);

    return 0;

}

Measured memory_bytes: 128
import java.util.*;
public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		// 整数の入力
		String m = sc.nextLine();
		String n = sc.nextLine();
		boolean equalFlag = true;
		if(m.length()>n.length()){
			System.out.println("GREATER");
			equalFlag = false;
		}else if(m.length()<n.length()){
			System.out.println("LESS");
			equalFlag = false;
		}

		if(m.length()==n.length()){
			for(int i=0;i<m.length();i++){
				int a = Character.getNumericValue(m.charAt(i));
				int b = Character.getNumericValue(n.charAt(i));
				if(a>b){
					System.out.println("GREATER");
					equalFlag = false;
					break;
				}else if(a<b){
					System.out.println("LESS");
					equalFlag = false;
					break;
				}
			}



		}


		if(equalFlag){
			System.out.println("EQUAL");
		}


		sc.close();
	}


}

Measured memory_bytes: 23764
#include <bits/stdc++.h>
using namespace std;
 
int main() {
    int A,B;
    cin >> A >> B;
    if ( (A - B*2) > 0){
        cout <<A - B*2<< endl;
    }else{
        cout << 0 << endl;
    }

    return 0;
}

Measured memory_bytes: 256
from collections import deque

while(True):
    W, H = map(int, input().split())
    if not W: break
    tx,ty = map(int, input().split())
    kx,ky = map(int, input().split())
    ma = [[False]*(W+2) for _ in range(H+2)]
    for i in range(1,H+1):
        for j,a in enumerate(input().split()):
            ma[i][j+1] = bool(1-int(a))
    from pprint import pprint
    que = deque([[tx,ty,kx,ky,0]])
    pas = set()
    ans = "NA"
    while(que):
        tx,ty,kx,ky,c = que.popleft()
        if c > 100: break
        if tx == kx and ty == ky:
            ans = c
            break
        for dx,dy in [[-1,0],[0,-1],[1,0],[0,1]]:
            tdx, tdy = [ dx, dy] if ma[ty+dy][tx+dx] else [0,0]
            kdx, kdy = [-dx,-dy] if ma[ky-dy][kx-dx] else [0,0]
            if (tx+tdx,ty+tdy,kx+kdx,ky+kdy) in pas: continue
            que.append([tx+tdx,ty+tdy,kx+kdx,ky+kdy,c+1])
            pas.add((tx+tdx,ty+tdy,kx+kdx,ky+kdy))
    print(ans)



Measured memory_bytes: 35868
#include<cstring>
#include<cstdio>
int main(){
	char s[111];
	scanf("%s",&s);
	int a=0,b=0;
	for(int i=0;s[i];i++){
		if(s[i]=='C')a++;
		if(s[i]=='F'&&a)b++;
	}
	if(b)printf("Yes\n");
	else printf("No\n"); 
} 

Measured memory_bytes: 128
#include <cstdio>
#include <cmath>
#include <cstring>
#include <numeric>
#include <algorithm>
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <map>
#include <utility>
#include <string>

using namespace std;

typedef long long ll;
typedef unsigned int uint;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef pair<ll, int> pli;

const int iinf = 1 << 29;
const long long linf = 1ll << 61;

#define modp(x, y) (((y) + (x) % (y)) % (y))

ll gcd(ll x, ll y)
{
	if(x < y) swap(x, y);
	ll mod = x % y;
	if(mod == 0) return y;
	return gcd(y, mod);
}

ll lcm(ll x, ll y)
{
	return x / gcd(x, y) * y;
}

int N;
ll T[100];

int main(int argc, char* argv[])
{
	scanf("%d", &N);
	for(int i = 0; i < N; i++) scanf("%lld", &T[i]);

	ll l = T[0];
	for(int i = 0; i < N; i++)
	{
		l = lcm(l, T[i]);
	}

	printf("%lld", l);

	return 0;
}


Measured memory_bytes: 128
#include<iostream>
#include <algorithm>
#include <functional>
#include<vector>
#include<math.h>
#include <assert.h>
#include<bitset>
#include<string>
#include <deque>
#include<queue>
#include <iomanip>
#include<map>
#include <random>
#include<type_traits>
#include<stack>
#include <sstream> 
#include <limits>
#include <numeric>
#include<string.h>
#include<set>
#include <climits>
using namespace std;
typedef unsigned long long ull;
#define ll long long int
ll mod = 1000000007;
//typedef vector<int> V;
//typedef vector<V> VV;
//typedef vector<VV> VVV;

int main() {

	ll a, b, c;
	cin >> a >> b >> c;
	a = min(c - 1, a);
	c -= a;
	if (b >= c - 1) {
		cout << b + c+a << endl;
	}
	else {
		cout << 2 * b + 1+a << endl;
	}
}




Measured memory_bytes: 256
loop do
    n, w = gets.split.map &:to_i    
    break if n == 0
    count = Hash.new(0)
    n.times do
        count[gets.to_i / w] += 1    
    end 
    m = count.values.max.to_f
    l = count.keys.max.to_f
    p (0..count.keys.max).map{|i| (l - i) / l * count[i] / m}.inject(:+) + 0.01
end

Measured memory_bytes: 8784
n=int(input())
a_list=[int(i)-1 for i in input().split()]
b_list=[int(i) for i in input().split()]
c_list=[int(i) for i in input().split()]

bef=-1
ans=0
for a in a_list:
    ans+=b_list[a]
    if bef>=0 and a<n and bef==a-1:
        ans+=c_list[bef]
    bef=a
print(ans)

Measured memory_bytes: 3064
#include <algorithm>
#include <iostream>
#include <vector>
#include <cmath>
#include <set>
#include <unordered_map>
#include <queue>

using namespace std;

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

    int n;
    cin >> n;
    string s;
    int arr[4] = {0};
    for (int i = 0; i < n; i++) {
        cin >> s;
        if (s == "AC") {
            arr[0]++;
        } else if (s == "WA") {
            arr[1]++;
        } else if (s == "TLE") {
            arr[2]++;
        } else {
            arr[3]++;
        }
    }
    cout << "AC x " << arr[0] << "\nWA x " << arr[1] << "\nTLE x " << arr[2] << "\nRE x " << arr[3] << endl;
}

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

typedef long long ll;
const int MOD = 1e9 + 7;
typedef vector<ll> vll;
typedef vector<int> vi;
const int maxn = 100 + 10;

int main() {
    int n;
    cin >> n;
    int sum = 0;
    int x;
    int maxNum = INT_MIN;
    for (int i = 0; i < n; ++i) {
        cin >> x;
        sum += x;
        maxNum = max(maxNum, x);
    }
    cout << sum - maxNum / 2 << endl;
    return 0;
}


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

using namespace std;

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

int const MAX_N = 200000;

int par[MAX_N];
int rnk[MAX_N];

void init(int n) {
  for(int i=0; i<n; i++) {
    par[i] = i;
    rnk[i] = 0;
  }
}

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

void unite(int x, int y) {
  x = find(x);
  y = find(y);
  if(x == y) return;
  
  if(rnk[x] < rnk[y]) {
    par[x] = y;
  }
  else {
    par[y] = x;
    if(rnk[x] == rnk[y]) rnk[x] ++;
  }
}

bool same(int x, int y) {
  return find(x) == find(y);
}








#define INF (1LL<<58)
typedef long long ll;

int N, M, K, S;
int P, Q;

vector<int> G[100010];
vector<int> zombies;
ll F[100100];
queue<int> q;

int main() {
  
  cin >> N >> M >> K >> S;
  cin >> P >> Q;
  
  rep(i, K) {
    int x; cin >> x; x--;
    zombies.push_back(x);
  }
  
  rep(i, M) {
    int A, B; cin >> A >> B; A--, B--;
    G[A].push_back(B);
    G[B].push_back(A);
  }

  rep(i, N + 10) F[i] = INF;
  
  rep(i, zombies.size()) {
    F[zombies[i]] = 0;
    q.push(zombies[i]);
  }
  
  while(!q.empty()) {
    int p = q.front();
    q.pop();
    if(F[p] == S) continue;
    rep(i, G[p].size()) {
      int to = G[p][i];
      if(F[to] <= F[p] + 1) continue;
      F[to] = F[p] + 1;
      q.push(to);
    }
  }
  
  typedef pair<ll, int> pli; // cost, pos;
  priority_queue<pli, vector<pli>, greater<pli>> pq;
  vector<ll> dist(N + 10, INF);
  dist[0] = 0;
  
  pq.push({0, 0});

  while(!pq.empty()) {
    pli p = pq.top(); pq.pop();
    ll co = p.first, pos = p.second;
    if(pos == N-1) {
      cout << co << endl;
      break;
    }
    
    rep(i, G[pos].size()) {
      int to = G[pos][i];
      if(F[to] == 0) continue;
      ll pco = F[to] == INF ? P : Q;
      if(to == N - 1) pco = 0;
      if(dist[to] <= co + pco) continue;
      dist[to] = co + pco;
      pq.push({dist[to], to});
    }
  }
  
  return 0;
}

Measured memory_bytes: 10988
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using vl = vector<ll>;
using vvl = vector<vl>;
using pll = pair<ll, ll>;
using vpll = vector<pll>;
using vb = vector<bool>;
using vs = vector<string>;
const ll oo = 0x3f3f3f3f3f3f3f3fLL;
const ld eps = 1e-9;
#define sz(c) ll((c).size())
#define all(c) begin(c), end(c)
#define mp make_pair
#define pb push_back
#define eb emplace_back
#define xx first
#define yy second
#define FOR(i,a,b) for (ll i=(a); i<(b); i++)
#define FORD(i,a,b) for(ll i=ll(b)-1; i>=(a); i--)
#define TR(X) ({if(1) cerr << "TR: " << (#X) << " = " << (X) << endl;})

int main(){
	cin.sync_with_stdio(0);

	ll n;
	cin >> n;
	vl h(n);
	vl stein(n);

	FOR(i,0,n){
		cin >> h[i]; 
	}

	stein[0] = 0;

	FOR(i,1,n){
		if(i > 2){
			stein[i] = min((stein[i - 2] + abs(h[i - 2] - h[i])), (stein[i - 1] + abs(h[i - 1]  - h[i])));
		}else{
			stein[i] = stein[0] + abs(h[0] - h[i]);
		}
	}

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


Measured memory_bytes: 1792
#include <stdio.h>

int main(){

	int N, v, i, j;
	int A[1000];

	scanf("%d", &N);
	for(i=0; i<N; i++){
		scanf("%d", &A[i]);
	}

	for(i=0; i<N; i++){
		v = A[i];
		j = i-1;
		while(j>=0 && A[j]>v){
			A[j+1] = A[j];
			j--;
			A[j+1] = v;
		}
		for(j=0; j<N; j++){
			if(j!=0){
				printf(" ");
			}
			printf("%d", A[j]);
		}
		printf("\n");
	}

	return 0;
}

Measured memory_bytes: 604
# ABC138D - Ki (main, dfs)
import sys

input = sys.stdin.readline
sys.setrecursionlimit(10 ** 7)


def dfs(v: int, p: int, T: list, cnt: list) -> None:
    for u in T[v]:
        if u != p:  # p: parent -> skip
            cnt[u] += cnt[v]  # cumulative sum
            dfs(u, v, T, cnt)


def main():
    # Ai (A[i][0]) may be not a parent of Bi (A[i][1])
    global T, cnt
    N, Q = tuple(map(int, input().split()))  # vertices and queues
    E = tuple(tuple(map(int, input().split())) for _ in range(N - 1))
    P = tuple(tuple(map(int, input().split())) for _ in range(Q))
    T = [[] for _ in range(N + 1)]  # tree, (N+1: 1-idx -> 0-idx)
    for a, b in E:
        T[a] += [b]
        T[b] += [a]
    cnt = [0] * (N + 1)
    for p, x in P:
        cnt[p] += x  # increase vertex p by x
    dfs(1, -1, T, cnt)
    print(*cnt[1:])


if __name__ == "__main__":
    main()

Measured memory_bytes: 265844
import java.util.Scanner;
public class Main {

    public static void main(String[] args){
    	Scanner sc = new Scanner(System.in);
    	// 入力
    	String s = sc.next();

    	String alp = "abcdefghijklmnopqrstuvwxyz";
    	String ans = "";



    	for(int i = 0; i < alp.length(); i++){
			String tmp = "";

    		for(int j = 0; j < s.length(); j++){
        		if (alp.charAt(i) == s.charAt(j)){
        			tmp = "ng";
        			//System.out.println(alp.charAt(i));
        			//System.out.println(s.charAt(j));

        		}
    		}
    		if (!(tmp.equals("ng"))){
        		ans = String.valueOf(alp.charAt(i));
        		break;
    		}

    	}

		if (ans.equals("")){
			ans = "None";
		}

    	// 出力
    	System.out.println(ans);
    }
}

Measured memory_bytes: 23312
#include <bits/stdc++.h>
#define ll long long
#define MODV 1000000007
#define INFLL LLONG_MAX // 9223372036854775807
#define EPS 1e-9
#define rep(i, n) for(ll i=0, i##_len=(ll)(n); i<i##_len; i++)
#define repf(i, n) for(ll i=1, i##_len=(ll)(n+1); i<i##_len; i++)
#define all(v) v.begin(), v.end()
#define endl "\n"
#define vi vector<ll>
#define vvi vector<vector<ll>>
#define Yes() cout << "Yes" << endl
#define YES() cout << "YES" << endl
#define No() cout << "No" << endl
#define NO() cout << "NO" << endl
#define Init() std::ios::sync_with_stdio(false); std::cin.tie(0); std::cout<<fixed<<setprecision(15);
template<class T>bool chmax(T &a, const T &b){ if(a<b){ a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b){ if(b<a){ a=b; return 1; } return 0; }
using namespace std;

int main(){
    Init();
    ll n, ans = 1; cin >> n;
    vi a(n), assign(3, 0);
    rep(i, n) cin >> a[i];

    rep(i, n){
        ll cnt = 0; bool chg = false;
        rep(j, 3){
            if(assign[j] == a[i]){
                cnt++;
                if(!chg){
                    chg = true;
                    assign[j]++;
                }
            }
        }
        ans = (ans*cnt)%MODV;
    }
    cout << ans << endl;
}

Measured memory_bytes: 3988
#include<iostream>
#include<iomanip>
#include<algorithm>
#include<array>
#include<bitset>
#include<cassert>
#include<cctype>
#include<cmath>
#include<cstdio>
#include<cstring>
#include<functional>
#include<limits>
#include<list>
#include<map>
#include<numeric>
#include<set>
#include<stack>
#include<string>
#include<sstream>
#include<unordered_map>
#include<queue>
#include<vector>
using namespace std;

//#define int long long
using ll = long long;
using ull = unsigned long long;
using pii = pair<int, int>;

#define rep(i,a,b) for(int i=(a);i<(b);i++)
#define rrep(i,a,b) for(int i=(b)-1;i>=(a);i--)
#define all(a) (a).begin(),(a).end()
#define dump(o) {cerr<<#o<<" "<<o<<endl;}
#define dumpc(o) {cerr<<#o; for(auto &e:(o))cerr<<" "<<e;cerr<<endl;}
#define INF 0x3f3f3f3f
#define INFL 0x3f3f3f3f3f3f3f3fLL
const int MOD = 1e9 + 7;

//n??????
//Radix r;
//cout << r.to(n, 4) << endl;
class Radix {
private:
	const char* s;
	int a[128];
public:
	Radix(const char* s = "0123456789ABCDEF") : s(s) {
		for (int i = 0; s[i]; i++) a[(int)s[i]] = i;
	}
	string to(long long p, int q) {
		if (!p) return "0";
		char t[64] = {};
		int i;
		for (i = 62; p; i--) {
			t[i] = s[p % q];
			p /= q;
		}
		return string(t + i + 1);
	}
	string to(const string &t, int p, int q) {
		return to(to(t, p), q);
	}
	long long to(const string &t, int p) {
		long long sm = a[(int)t[0]];
		for (int i = 1; i < (int)t.length(); i++)
			sm = sm * p + a[(int)t[i]];
		return sm;
	}
};

signed main() {
	for (int n; cin >> n&&n != -1;) {
		Radix r;
		cout << r.to(n, 4) << endl;
	}
	return 0;
}

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

int main(){

    int k,n;
    int diffmax=0;
    cin>>k>>n;
    vector<int> a(n);
    for(int i=0;i<n;i++){
        cin>>a[i];
    }
    for(int i=0;i<n;i++){
        if(i!=n-1) diffmax=max(diffmax,a[i+1]-a[i]);
        else diffmax=max(diffmax,k+a[0]-a[i]);
    }
    cout<<k-diffmax<<endl;


    return 0;
}

Measured memory_bytes: 1024
#include <iostream>
#include <vector>
#include <string>
#include <map>
#include <algorithm>

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

const long long INF = 1LL << 60;

int main()
{
	long long H, W;
	std::cin >> H >> W;
	if((H==1) || (W==1))
	{
		std::cout << 1 << std::endl;
		return 0;
	}
	long long ans = (H * W) / 2;
	if((ans * 2) != (H * W))
	{
		ans++;
	}
	std::cout << ans << std::endl;
	return 0;
}


Measured memory_bytes: 3640
import java.math.BigInteger

fun main(args: Array<String>){
  var input = readLine()!!.split(" ")
  val N = input[0].toInt()
  val M = input[1].toInt()
  input = readLine()!!.split(" ")
  val A = Array(N){ input[it].toInt() }
  A.sortBy{ -it }

  var i = 0
  for( m in 1..M ){
    A[i] /= 2
    if( i == N-1 )
      i = 0
    else if( A[i] < A[i+1] )
      i++
    if( A[i] <= A[0] ){
      A.sortBy{ -it }
      i = 0
    }
  }

  var all = BigInteger.ZERO
  for( a in A )
    all = all.plus(BigInteger(a.toString()))
  println(all)
}


Measured memory_bytes: 81724
#include<stdio.h>
int main(){
  int n,b[300]={};
  char s[100010];
  scanf("%d",&n);
  while(n--){
    scanf("%s",s);
    b[s[0]]++;
  }
  printf("AC x %d\nWA x %d\nTLE x %d\nRE x %d\n",b['A'],b['W'],b['T'],b['R']);
  return 0;
}


Measured memory_bytes: 1740