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

typedef long long   signed int LL;
typedef long long unsigned int LU;

#define incID(i, l, r) for(int i = (l)    ; i <  (r); i++)
#define incII(i, l, r) for(int i = (l)    ; i <= (r); i++)
#define decID(i, l, r) for(int i = (r) - 1; i >= (l); i--)
#define decII(i, l, r) for(int i = (r)    ; i >= (l); i--)
#define  inc(i, n) incID(i, 0, n)
#define inc1(i, n) incII(i, 1, n)
#define  dec(i, n) decID(i, 0, n)
#define dec1(i, n) decII(i, 1, n)

#define inII(v, l, r) ((l) <= (v) && (v) <= (r))
#define inID(v, l, r) ((l) <= (v) && (v) <  (r))

#define PB push_back
#define EB emplace_back
#define MP make_pair
#define FI first
#define SE second
#define PQ priority_queue

#define  ALL(v)  v.begin(),  v.end()
#define RALL(v) v.rbegin(), v.rend()
#define  FOR(it, v) for(auto it =  v.begin(); it !=  v.end(); ++it)
#define RFOR(it, v) for(auto it = v.rbegin(); it != v.rend(); ++it)

template<typename T> bool   setmin(T & a, T b) { if(b <  a) { a = b; return true; } else { return false; } }
template<typename T> bool   setmax(T & a, T b) { if(b >  a) { a = b; return true; } else { return false; } }
template<typename T> bool setmineq(T & a, T b) { if(b <= a) { a = b; return true; } else { return false; } }
template<typename T> bool setmaxeq(T & a, T b) { if(b >= a) { a = b; return true; } else { return false; } }
template<typename T> T gcd(T a, T b) { return (b == 0 ? a : gcd(b, a % b)); }
template<typename T> T lcm(T a, T b) { return a / gcd(a, b) * b; }

// ---- ----

int h, w, a[500][500];
vector<array<int, 4>> v;

int main() {
	cin >> h >> w;
	inc(i, h) {
	inc(j, w) {
		cin >> a[i][j];
	}
	}
	
	inc(i, h) {
	inc(j, w - 1) {
		if(a[i][j] % 2 != 0) {
			v.PB({ i, j, i, j + 1 });
			a[i][j + 1]++;
		}
	}
	}
	
	inc(i, h - 1) {
		int j = w - 1;
		if(a[i][j] % 2 != 0) {
			v.PB({ i, j, i + 1, j });
			a[i + 1][j]++;
		}
	}
	
	cout << v.size() << "\n";
	inc(k, v.size()) {
		inc(l, 4) { cout << v[k][l] + 1 << (l == 3 ? "\n" : " "); }
	}
	
	return 0;
}


Measured memory_bytes: 5104
#include<iostream>
#include<string>
#include<vector>
#include<utility>
#include<queue>
#include<algorithm>
#include<cmath>
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<complex>
#define INF 2147483647
#define llINF 9223372036854775807
#define pb push_back
#define mp make_pair 
#define F first
#define S second
#define ll long long

using namespace std;
int main(){
  int n;cin>>n;
  bool flag=false;
  for(ll i=1;i<=3500;i++){
    for(ll j=1;j<=3500;j++){
      ll aa=(ll)(4*i*j-n*j-n*i);
      ll bb=(ll)(n*i*j);
      if(aa>0&&(bb)%(aa)==0){
	cout<<i<<" "<<j<<" "<<(ll)(bb)/(aa)<<endl;
	flag=true;
	break;
      }
    }
    if(flag)
      break;
  }
  return 0;
}


Measured memory_bytes: 256
import java.util.*;
public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		// 整数の入力
		int a = sc.nextInt();
		// スペース区切りの整数の入力
		String s = sc.next();
      	if(a >= 3200){
          System.out.println(s);
        }
        else
        {
          System.out.println("red");
        }
      
	}
}

Measured memory_bytes: 21716
#include<iostream>
#include<vector>
#include<algorithm>
#include<cstdio>
#include<cstdlib>
#include<string>
#include<sstream>
#include<cmath>
#include<numeric>
#include<map>
#include<stack>
#include<queue>
using namespace std;
int mod = 1e9+7;

long long int func(vector<int> b, int p){
  int n = b.size();
  int tmp = b[p];
  long long int ans = 0;
  for(int i=0; i<n; i++){
    ans += abs(b[i]-tmp);
  }
  return ans;
}

int main() {

  int n; cin >> n;
  vector<int> a(n);
  vector<int> b(n);
  for(int i=0; i<n; i++){
    cin >> a[i];
    b[i] = a[i] - (i-1);
  }

  sort(b.begin(), b.end());
  long long int ans = func(b, n/2);
  ans = min(ans, func(b, n/2+1));

  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 2568
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int,int> P;
typedef pair<ll,ll> l_l;
const int INF=1001001000;
const int mINF=-1001001000;
const ll LINF=1010010010010010000;
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;
}
int main(){
    string s;cin >> s;
    int n=s.size();
    int cnt=0;
    for(int i=0;i<n;i++) if(s[i]=='p') cnt++;
    int num=n/2;
    num-=cnt;
    cout << num << endl;
    return 0;
}

Measured memory_bytes: 512
#include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <utility>

using namespace std;

int bubblesort(vector<int> &a) {
	int n = a.size();
	int changes = 0;

	bool hasNext = true;
	while (hasNext) {
		hasNext = false;
		for (int i = n - 1; i >= 1; i--) {
			if (a[i] < a[i - 1]) {
				swap(a[i], a[i - 1]);
				hasNext = true;
				changes++;
			}
		}
	}
	return changes;
}

int main() {
	int n;

	cin >> n;
	vector<int> a(n, 0);
	for (int i = 0; i < n; i++) {
		cin >> a[i];
	}

	int changes = bubblesort(a);
	for (int i = 0; i < n; i++) {
		printf("%d%c", a[i], i == n - 1 ? '\n' : ' ');
	}
	printf("%d\n", changes);


	return 0;
}

Measured memory_bytes: 1172
#include<cstdio>
#include<cmath>
#include<string>
#include<vector>
#include<algorithm>

using namespace std;

int main()
{
	int n, m;

	scanf("%d %d", &n, &m);

	if (n < m)
	{
		for (int i = 0; i < m; i++)
		{
			printf("%d", n);
		}
	}

	else
	{
		for (int i = 0; i < n; i++)
		{
			printf("%d", m);
		}
	}

	printf("\n");

	return 0;
}

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

struct c
{
	int num;
	int marked;
};

int main(void)
{
	struct c cell[3][3];
	int b[100];
	int n = 0;

	for (int i = 0; i < 3; i++)
		scanf("%d %d %d\n", &cell[i][0].num, &cell[i][1].num, &cell[i][2].num);
	for (int i = 0; i < 3; i++)
		for (int j = 0; j < 3; j++)
			cell[i][j].marked = 0;

	for (int i = 0; i < 100 && scanf("%d\n", &b[i]) == 1; i++)
		n++;

	for (int k = 0; k < n; k++)
	{
		for (int i = 0; i < 3; i++)
		{
			for (int j = 0; j < 3; j++)
			{
				if (cell[i][j].num == b[k])
					cell[i][j].marked = 1;
			}
		}
	}

	for (int i = 0; i < 3; i++)
	{
		if (cell[i][0].marked == 1 && cell[i][1].marked == 1 && cell[i][2].marked == 1)
		{
			printf("Yes");
			return (0);
		}
		if (cell[0][i].marked == 1 && cell[1][i].marked == 1 && cell[2][i].marked == 1)
		{
			printf("Yes");
			return (0);
		}
	}
	if (cell[0][0].marked == 1 && cell[1][1].marked == 1 && cell[2][2].marked == 1)
	{
		printf("Yes");
		return (0);
	}
	if (cell[0][2].marked == 1 && cell[1][1].marked == 1 && cell[2][0].marked == 1)
	{
		printf("Yes");
		return (0);
	}
	printf("No");
	return (0);
}

Measured memory_bytes: 128
#include<cmath>
#include<bits/stdc++.h>
#define MAX(a,b) (a>b? a:b)
#define MIN(a,b) (a>b? b:a)
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define repr(i,n) for(lint i=(lint)(n);i>0;--i)
#define reps(i,a,b) for(lint i=a;i<=(lint)(b);i++)
typedef long long lint;
typedef long double ld;
using namespace std;
const ld PI = acos(-1.0);

int main(){
	int x;
	cin >> x;
	if(x==3||x==5||x==7) cout << "YES" << endl;
	else cout << "NO" << endl;
	return 0;
}

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

const int64_t MOD = 1000000007;
typedef long long ll;
typedef unsigned long long ull;

#define FOR(i, start, end) for(uint64_t i=start; i<end; i++)
#define REP(i, n) FOR(i, 0, n)

// 最大公約数gcd
// 最小公倍数lcm=m*n/gcd
uint64_t gcd(uint64_t m, uint64_t n) {
  uint64_t temp;
  while (m % n != 0){
    temp = n;
    n = m % n;
    m = temp;
  }
  return n;
}

uint64_t lcm(uint64_t m, uint64_t n) {
  return (m*n)/gcd(m,n);
}

// vector<vector<uint64_t> > v(n+1, vector<uint64_t>(n+1, 0))
// v[n][k]に組み合わせ数が入る。
void comb(vector<vector <uint64_t> > &v){
  for(uint64_t i = 0;i <v.size(); i++){
    v[i][0]=1;
    v[i][i]=1;
  }
  for(uint64_t k = 1;k <v.size();k++){
    for(uint64_t j = 1;j<k;j++){
      v[k][j]=(v[k-1][j-1]+v[k-1][j]);
    }
  }
}

// 掛け算オーバーフロー判定
bool is_product_overflow(uint64_t a, uint64_t b) {

	uint64_t prod = a * b;
	
	return (prod / b != a);
}

//素因数分解
void primeFactorization(uint64_t a, list<uint64_t> &factors){ //素因数分解を出力するプログラム
  long i,sq;
  if(a%2==0){ //偶数の場合
    factors.push_back(2);
    primeFactorization(a/2,factors); //2で割った値で再帰
    return;
  }
  sq = sqrt(a);
  for(i=3;i<=sq;i+=2){ //3以上√a以下の奇数の場合
	if(a%i==0){
	  factors.push_back(i);
      primeFactorization(a/i,factors); //割れた値で再帰
      return;
	}
  }
  //偶数でも3以上√a以下の奇数の場合でも割り切れない場合
  if(a!=1){ //aが1でないなら、a自身は素数
    factors.push_back(a);
  }
}

// フェルマーの小定理
// mod. m での a の逆元 a^{-1} を計算する
// (a/b)%m = a*movinv(b,m)%m  
int64_t modinv(int64_t a, int64_t m) {
    int64_t b = m, u = 1, v = 0;
    while (b) {
        int64_t t = a / b;
        a -= t * b; swap(a, b);
        u -= t * v; swap(u, v);
    }
    u %= m;
    if (u < 0) u += m;
    return u;
}

// 円周率
// M_PI

// #include <iomanip> // setprecisionを使用するのに必要
// cout << std::fixed << std::setprecision(15) << y << endl;

// 昇順
// priority_queue<int, vector<int>, greater<int> > queue;

signed main() {
  int n,m;
  cin >> n >> m;

  int l = 0, r = n;
  int li,ri;
  for(int i=0;i<m;i++){
    cin >> li >> ri;
    l = max(l,li);
    r = min(r,ri);
  }
  if(r-l+1>=0){
  	cout << r-l+1 << endl;
  }
  else{
    cout << "0" << endl;
  }
  
  return 0;
}



Measured memory_bytes: 3636
import numpy as np

N = int(input())
A = np.array(list(map(int, input().split())))
ans_list = np.zeros(N).astype(int)
N_2 = N // 2
ans = 0
for i in range(N):
    tmp = N - i - 1
    # print(tmp)
    if i < N_2:
        ans_list[tmp] = A[tmp]
        if A[tmp] == 1:
            ans += 1
    else:
        add = (np.sum(ans_list[tmp::(tmp + 1)]) + A[tmp]) % 2
        ans_list[tmp] = add
        if add == 1:
            ans += 1

print(ans)
for i in range(N):
    if ans_list[i] == 1:
        if i == N - 1:
            print(i + 1, end="")
        else:
            print(i + 1, end=" ")


Measured memory_bytes: 21004
#include<bits/stdc++.h>
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
using namespace std;
using ll = long long;
int main(){
    int a,b,t;
    cin >> a >> b >> t;
    int x = (int)(t+0.5)/a;
    cout << x * b << endl;
    return 0;
}

Measured memory_bytes: 256
def merge(a, left, mid, right):
    L = a[left:mid] + [INF]
    R = a[mid:right] + [INF]
    
    i = 0
    j = 0
    for k in range(left, right):
     
        global idx
        idx += 1
        if( L[i] <= R[j] ):
            a[k] = L[i]
            i += 1
        else:
            a[k] = R[j]
            j += 1

def merge_sort(a, left, right):
    if( left + 1 < right ):
        mid = (left + right) // 2 
        merge_sort(a, left, mid)
        merge_sort(a, mid, right)
        merge(a, left, mid, right)


INF = 1000000000
idx = 0
n = int(input())
a = [int(i) for i in input().split()]
merge_sort(a,0,len(a))
print(*a)
print(idx)


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

using namespace std;

int main() {
  int A, B, H, M;
  cin >> A >> B >> H >> M;
  long double T = H * 60 + M;
  long double r1 = T / 720 * 2 * M_PI;
  long double r2 = T / 60 * 2 * M_PI;
  long double x1 = -sin(r1) * A;
  long double y1 = cos(r1) * A;
  long double x2 = -sin(r2) * B;
  long double y2 = cos(r2) * B;

  printf("%.16LF\n", sqrt(pow(x1 - x2, 2) + pow(y1 - y2, 2)));
  return 0;
}


Measured memory_bytes: 4144
import java.util.Scanner;

public class Main {
  public static void main(String[] args) {
    Scanner scan = new Scanner(System.in);
    final int N = scan.nextInt();
    final int H = scan.nextInt();
    final int W = scan.nextInt();
    System.out.print((N - H + 1) * (N - W + 1));
  }
}


Measured memory_bytes: 22740
<?php
fscanf(STDIN, "%s", $s);
$s_arr = str_split($s);
$a = 'a';
$ret = '';
for($j = 0; $j < 26; $j++) {
//var_dump($a, $ret);
    if(in_array($a, $s_arr)) {
        $a++;
        continue;
    } else {
        $ret = $a;
        break;
    }
}

echo ($ret == '') ? "None" : $a;
echo "\n";

Measured memory_bytes: 10744
#include <iostream>
#include <iomanip>
#include <sstream>
#include <stdio.h>
#include <list>
#include <vector>
#include <stack>
#include <queue>
#include <algorithm>
#include <math.h>
#include <utility>
#include <string>
#include <ctype.h>
#include <cstring>
#include <cstdio>
#include <sstream>
#include <functional>

using namespace std;

#define FOR(i,k,n) for(int i = (k); i < (n); i++)
#define REP(i,n) FOR(i,0,n)
#define INF 114514810
#define ll long long
//#define scanf scanf_s

int w, h;
int isl[55][55];

int di[8] = { -1, -1, -1, 0, 0, 1, 1, 1 }; int dj[8] = { -1, 0, 1, -1, 1, -1, 0, 1 };

void dfs(int i, int j)
{
	if (isl[i][j] == 1)
	{
		isl[i][j] = 0;
		REP(k, 8) dfs(i + di[k], j + dj[k]);
	}
}

int main()
{
	while (cin >> w >> h, w)
	{
		REP(i, h)REP(j, w) cin >> isl[i][j];
		int cnt = 0;
		REP(i, h)REP(j, w)
		{
			if (isl[i][j] == 1)
			{
				cnt++;
				dfs(i, j);
			}
		}
		cout << cnt << endl;
	}
	return 0;
}

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

struct Card{
   char a;
   int b;
};

bool compare_as_ints(Card i,Card j){
   return (i.b<j.b);
}

int partition(Card A[],int p,int r){
   Card x=A[r];
   int i=p-1;
   for(int j=p;j<=r-1;j++){
      if(A[j].b<=x.b){
          i++;
          swap(A[i],A[j]);
      }
   }
   swap(A[i+1],A[r]);
   return i+1;
}

void quicksort(Card A[],int p,int r){
   if(p<r){
      int q=partition(A,p,r);
      quicksort(A,p,q-1);
      quicksort(A,q+1,r);
   }
}

int main(){
   int n;
   cin >> n;
   Card A[100000],B[100000];
   for(int i=0;i<n;i++){
      cin >> A[i].a >> A[i].b;
      B[i]=A[i];
   }
   quicksort(A,0,n-1);
   stable_sort(B,B+n,compare_as_ints);
   int count=0;
   for(int i=0;i<n;i++){
      if(A[i].a!=B[i].a||A[i].b!=B[i].b)
         count++; 
   }
   if(count!=0)
      cout << "Not stable" << endl;
   else
      cout << "Stable" << endl;
   for(int i=0;i<n;i++)
      cout << A[i].a << ' ' << A[i].b << endl;
   return 0;
}

Measured memory_bytes: 4640
#include <iostream>
#include <fstream>
#include <sstream>
#include <algorithm>
#include <cstdio>
#include <cassert>
#include <cmath>
#include <cstdlib>
#include <cstring>
#include <string>
#include <deque>
#include <queue>
#include <vector>
#include <list>
#include <map>
#include <set>
#include <bitset>
#include <stack>
#include <iomanip>
#include <utility>
#include <functional>
using namespace std;
#define ll long long
#define ull unsigned ll
/*Fast I/O goes here*/
const double EPS = 1e-8;
const ll PR = 19260817;
const ll inv2 = 500000004;
const ll inv3 = 333333336;
int main() {
	string s;cin>>s;for(int i=0; i<s.length()-1; i++) if(s[i]=='A'&&s[i+1]=='C') {puts("Yes");return 0;} puts("No");
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define REP(i,a,b) for(int i=(a),_end_=(b);i<=_end_;i++)
#define DREP(i,a,b) for(int i=(a),_end_=(b);i>=_end_;i--)
#define EREP(i,u) for(int i=start[u];i;i=e[i].next)
#define fi first
#define se second
#define mkr(a,b) make_pair(a,b)
#define SZ(A) ((int)A.size())
template<class T>inline void chkmin(T &a,T b){ if(a>b)a=b;}
template<class T>inline void chkmax(T &a,T b){ if(a<b)a=b;}
inline int read()
{
	int s=0,f=1;char ch=getchar();
	while(!isdigit(ch) && ch!='-')ch=getchar();
	if(ch=='-')ch=getchar(),f=-1;
	while(isdigit(ch))s=s*10+ch-'0',ch=getchar();
	return ~f?s:-s;
}

const int maxn=20;
const int MAX=1<<16;
const int mod=1e9+7;

inline void pls(int &a,int b){ a+=b; a-=a>=mod?mod:0;}

int jc[MAX+20],jcn[MAX+20],inv[MAX+20];

inline void prepare()
{
	jc[0]=jc[1]=jcn[0]=jcn[1]=inv[1]=1;
	REP(i,2,MAX)jc[i]=(ll)i*jc[i-1]%mod,inv[i]=(ll)(mod-mod/i)*inv[mod%i]%mod,jcn[i]=(ll)jcn[i-1]*inv[i]%mod;
}

int n,m;
int a[maxn];

inline void init()
{
	n=read();m=read();
	REP(i,1,m)a[i]=read();
}

int dp[maxn][1<<16];

inline int Down(int n,int k){ return 1ll*jc[n]*jcn[n-k]%mod;}

inline void doing()
{
	dp[m+1][0]=1;
	DREP(i,m,1)
	{
		REP(j,0,(1<<n)-1)if(dp[i+1][j])
		{
			int t=dp[i+1][j],use=(1<<n)-a[i]+1;
			pls(dp[i][j],t);
			REP(l,0,n-1)if(j>>l&1)use-=1<<l;
			REP(l,0,n-1)if(~j>>l&1)
			{
				if(use>=(1<<l))
				{
					pls(dp[i][j|(1<<l)],(ll)t*(1<<l)%mod*Down(use-1,(1<<l)-1)%mod);
				}
			}
		}
	}
	int ans=0;
	REP(j,0,(1<<n)-1)
	{
		int use=(1<<n)-1;
		REP(l,0,n-1)if(j>>l&1)use-=1<<l;
		ans=(ans+(__builtin_parity(j)?-1:1)*1ll*jc[use]*dp[1][j])%mod;
	}
	ans=(ans+mod)%mod;
	ans=(ll)ans*(1<<n)%mod;
	printf("%d\n",ans);
}

int main()
{
	prepare();
	init();
	doing();
	return 0;
}


Measured memory_bytes: 4864
#include <iostream>
#include <string>
#include <vector>

bool is_even(std::vector<int> &a)
{

    for (int i = 0; i < a.size(); i++)
    {
        if (a[i] % 2 == 1)
        {
            return false;
        }
    }
    return true;
}

int main()
{
    int n;
    std::cin >> n;
    std::vector<int> a(n);
    for (int i = 0; i < n; i++)
    {
        std::cin >> a[i];
    }

    int ans = 0;
    while (is_even(a))
    {
        for (int i = 0; i < n; i++)
        {
            a[i] /= 2;
        }
        ans++;
    }

    std::cout << ans << "\n";
}

Measured memory_bytes: 3572
import sys
import itertools
sys.setrecursionlimit(1000000000)
from heapq import heapify,heappop,heappush,heappushpop
import math
import collections
MOD = 10**9 + 7

r,g,b = map(int,input().split())
d = str(r) + str(g) + str(b)
if int(d)%4 == 0:
    print("YES")
else:
    print("NO")

Measured memory_bytes: 3316
/**
 * code generated by JHelper
 * More info: https://github.com/AlexeyDmitriev/JHelper
 * @author aajisaka
 */

#include<bits/stdc++.h>

using namespace std;

void debug_out() { cerr << endl; }
template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
  cerr << " " << to_string(H);
  debug_out(T...);
}
#ifdef LOCAL
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
#else
#define debug(...) 42
#endif

#define SPEED ios_base::sync_with_stdio(false);cin.tie(nullptr)
#define rep(i,n) for(int i=0; i<(int)(n); i++)
#define all(v) v.begin(), v.end()
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }

using ll = long long;
using ull = unsigned long long;
using P = pair<ll, ll>;

constexpr long double PI = 3.14159265358979323846264338327950288L;
mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());

class EPayment {
public:
    void solve(istream& cin, ostream& cout) {
      SPEED;
      string s; cin >> s;
      reverse(all(s));
      int n = s.size();
      ll ans1 = 0; // non-carry
      ll ans2 = INT_MAX/2; // carry
      for(int i=0; i<n; i++) {
        ll d = s[i] - '0';
        ll now1 = ans1+d;
        if (d<9) chmin(now1, ans2+1+d);
        ll now2 = ans1+10-d;
        chmin(now2, ans2+9-d);
        ans1 = now1;
        ans2 = now2;
        debug(ans1, ans2);
      }
      cout << min(ans1, ans2+1) << endl;

    }
};

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

Measured memory_bytes: 1948
#include <bits/stdc++.h>
typedef long long ll;
using namespace std;
#define pb push_back
ll posR[1000005];
ll posC[1000005];
ll a[1005] , b[1005];
ll n ,m;
class BIT
{
public:
        vector<ll> tree;
        BIT()
        {
                tree.resize(2000005, 0);
        }
        ll qry(ll x)
        {
                ll sum=0;
                for(; x > 0 ; x -= (x&(-x))) sum += tree[x];
                return sum;
        }
        void upd(ll x, ll v)
        {
                for(; x <= n*m; x += (x&(-x))) tree[x] += v;

        }
        ll give(ll l, ll r)
        {
                return qry(r) - qry(l-1);
        }
};
bool done[1005];
const ll mod = 1e9 + 7;
int main()
{
        ios_base::sync_with_stdio(false);
        cin.tie(NULL); cout.tie(NULL);
        cin >> n >> m;
        for(ll i=1;i<=n;i++) {
                cin >> a[i];
                if(posR[a[i]] != 0) {
                        cout << "0\n"; return 0;
                }
                posR[a[i]] = i;
        }
        for(ll i=1;i<=m;i++) {
                cin >> b[i];
                if(posC[b[i]] != 0) {
                        cout << "0\n"; return 0;
                }
                posC[b[i]]=i;
        }
        BIT ftr;
        BIT ftc;
        ll ans = 1LL;
        for(ll i=n*m;i >= 1;i--) {
                if(posR[i] > 0 && posC[i] > 0) {

                        ftr.upd(posR[i], 1);
                        ftc.upd(posC[i], 1);

                }else if(posR[i] > 0 && posC[i]==0) {
                        ftr.upd(posR[i], 1);
                        ans = (ans * ftc.qry(m))%mod;
                }else if(posR[i]==0 && posC[i]==0){
                        ll X = ftc.qry(m) * ftr.qry(n);
                        X %= mod;
                        X = (X - (n*m) + i + mod)%mod;
                        X = (X + mod)%mod;
                        ans = (ans * X)%mod;
                }else {
                        ftc.upd(posC[i] , 1);
                        ans = (ans * ftr.qry(n))%mod;
                }
        }
        cout << ans << endl;
        return 0;
}


Measured memory_bytes: 35584
#include<cstdio>
#include<algorithm>
using namespace std;
int main() {
	long long n, m, res = 0;
	scanf("%lld%lld", &n, &m);
	if (n > m)swap(n, m);
	if (n >= 2 && m >= 2) {
		printf("%lld\n", (n - 2)*(m - 2));
	}
	else if (m >= 2)printf("%lld\n", m - 2);
	else printf("1\n");
}

Measured memory_bytes: 128
/*
 
@author
_      _          _                 _      _
\\    // /\    | | \  |     |    /\ \\    //     
 \\  // /__\   | |_/  |_____|   /__\ \\  //
  \\// /    \  | | \  |     |  /    \ \\//
   \/ /      \ | |_/  |     | /      \ \/
@ Indian Institute of Technology Bhilai
*/
 
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ul;
#define fr(i,start,end, inc) for(ll i=(start); i<(end); i+=inc)
#define rf(i,end,start, inc) for(ll i=(start-1); i>=(end); i-=inc)
#define rep(i,n) for(ll i=0; i<n; i++)
#define rep1(i,n) for(ll i=1; i<n; i++)
#define pb push_back
#define pl pair<ll, ll>
#define fi first
#define se second
#define all(v) v.begin(), v.end()
#define alla(arr,n) arr, arr+n
#define yes cout<<"Yes\n"
#define no cout<<"No\n"
#define fsync ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
const ll maxx =  1e9+7;


bool compare(const pl &a, const pl &b){
    return a.fi<b.fi || (a.fi==b.fi && a.se<b.se);
}
ll inline power(ll a, ll b, ll p){
    a %= p;
    ll ans = 1;
    while(b>0){
        if(b & 1)
            ans = (ans*a)%p;
        a = (a*a)%p;
        b >>= 1;
    }
    return ans;
}

ll inv(ll n, ll p){
    return power(n,p-2, p);
}
inline vector<ll> allinv(ll n, ll p){
    vector<ll> arr(n);
    arr[1]=1;
    fr(i,2,n,1){
        arr[i] = (p - (p/i)*arr[p%i]%p)%p;
    }
    return arr;
}
vector<ll> inline allncr(ll n, ll p){
    vector<ll> nci(n+1);
    nci[0]=1;
    nci[n]=1;
    vector<ll> v = allinv(n,p);
    fr(i,1,n,1){
        nci[i]=(nci[i-1]*(n-i-1))%p;
    }
    return nci;
}

bool inline isPrime(ll n) { 
    if (n <= 1)  return false; 
    if (n <= 3)  return true; 
    if (n%2 == 0 || n%3 == 0) return false; 
    for (ll i=5; i*i<=n; i=i+6) 
        if (n%i == 0 || n%(i+2) == 0) 
           return false; 
    return true; 
}

template<class T>
void printv(T &v, ll n){
    if(n==-1)
        n = v.size();
    rep(i,n)
        cout << v[i] << " ";
    cout << "\n";
}
//------------fenwick--------------
/*vector<ll> f(maxn,0);
void fenwick_update(ll idx, ll val){
    while(idx <= maxn){
        f[idx]+=val;
        idx += (idx & -idx);
    }
}
ll read_fenwick(ll idx){
    ll sum = 0;
    while(idx > 0){
        sum += f[idx];
        idx -= (idx & -idx);
    }
    return sum;
}*/

void solve(){
    ll k,n,f=0;
    cin >> k >> n;
    vector<ll> v(n);
    rep(i,n)
        cin >> v[i];
    sort(all(v));
    vector<ll> ans;
    rep1(i,n){
        ans.pb(v[i]-v[i-1]);
    }
    ans.pb(k-v[n-1]+v[0]); 
    cout << k - *max_element(all(ans))<<"\n";

}

int main(){
    fsync
    ll test=1;
    // cin >> test;
    while(test--){
        solve();

    }
}

Measured memory_bytes: 3956
import java.util.Scanner;

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

		Scanner sc = new Scanner(System.in);
//		String s = sc.next();
		int n = sc.nextInt();

		if(n%2==1) {
			System.out.println(n/2 + 1);
		}else {
			System.out.println(n/2);
		}

	}
}


Measured memory_bytes: 21716
#include<bits/stdc++.h>
using namespace std;
 
void __print(int x) {cerr << x;}
void __print(long x) {cerr << x;}
void __print(long long x) {cerr << x;}
void __print(unsigned x) {cerr << x;}
void __print(unsigned long x) {cerr << x;}
void __print(unsigned long long x) {cerr << x;}
void __print(float x) {cerr << x;}
void __print(double x) {cerr << x;}
void __print(long double x) {cerr << x;}
void __print(char x) {cerr << '\'' << x << '\'';}
void __print(const char *x) {cerr << '\"' << x << '\"';}
void __print(const string &x) {cerr << '\"' << x << '\"';}
void __print(bool x) {cerr << (x ? "true" : "false");}

template<typename T, typename V>
void __print(const pair<T, V> &x) {cerr << '{'; __print(x.first); cerr << ','; __print(x.second); cerr << '}';}
template<typename T>
void __print(const T &x) {int f = 0; cerr << '{'; for (auto &i: x) cerr << (f++ ? "," : ""), __print(i); cerr << "}";}
void _print() {cerr << "]\n";}
template <typename T, typename... V>
void _print(T t, V... v) {__print(t); if (sizeof...(v)) cerr << ", "; _print(v...);}
#ifndef ONLINE_JUDGE
#define debug(x...) cerr << "[" << #x << "] = ["; _print(x)
#else
#define debug(x...)
#endif
 
#define fi first
#define se second
#define FIO {ios::sync_with_stdio(0);cin.tie(nullptr);cout.tie(nullptr);}
#define pb push_back
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define forn(i, n) for (int i = 0; i < (int)(n); ++i)
#define for1(i, n) for (int i = 1; i <= (int)(n); ++i)
#define ford(i, n) for (int i = (int)(n) - 1; i >= 0; --i)
 
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<pii> vpi;
typedef vector<vi> vvi;
typedef long long ll;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef long double ld;

int main(){
	FIO
	
	int a,b,m;
	cin>>a>>b>>m;
		int q[a],w[b];
	forn(i,a)
	{
		cin>>q[i];
	}
	forn(i,b)
	{
		cin>>w[i];
	}
	if(m!=1){
		int x[m],y[m],c[m];
		int mini1=INT_MAX,mini2=INT_MAX,mini3=INT_MAX;
		forn(i,m)
		{
			cin>>x[i]>>y[i]>>c[i];
		}
		forn(i,m)
		{
			mini3=min(mini3,(q[x[i]-1]+w[y[i]-1]-c[i]));
		}
		forn(i,a)
		{
			mini1=min(mini1,q[i]);
		}
		forn(i,b)
		{
			mini2=min(mini2,w[i]);
		}
		//cout<<mini3;
		cout<<min(mini1+mini2,mini3);return 0;
	}
	else
	{
		int x,y,c;
		cin>>x>>y>>c;
		int mini1=INT_MAX,mini2=INT_MAX;
		forn(i,a)
		{
			mini1=min(mini1,q[i]);
		}
		forn(i,b)
		{
			mini2=min(mini2,w[i]);
		}
		cout<<min((mini1+mini2),(q[x-1]+w[y-1]-c));

	}
}

Measured memory_bytes: 2176
//https://atcoder.jp/contests/dp/tasks/dp_s
#include<bits/stdc++.h>
using namespace std;
typedef long long LL;
#ifdef BTK
#define DEBUG if(1)
#else
#define CIN_ONLY if(1)
struct cww {cww() {CIN_ONLY{ios::sync_with_stdio(false); cin.tie(0);}}}star;
#define DEBUG if(0)
#endif
#define ALL(v) (v).begin(),(v).end()
#define REC(ret, ...) std::function<ret (__VA_ARGS__)>
template <typename T>inline bool chmin(T &l, T r){bool a = l>r; if (a)l = r; return a;}
template <typename T>inline bool chmax(T &l, T r){bool a = l<r; if (a)l = r; return a;}
template <typename T>istream& operator>>(istream &is, vector<T> &v){for (auto &it : v)is >> it;return is;}
class range {private: struct I { int x; int operator*() { return x; }bool operator!=(I& lhs) { return x<lhs.x; }void operator++() { ++x; } }; I i, n;public:range(int n) :i({ 0 }), n({ n }) {}range(int i, int n) :i({ i }), n({ n }) {}I& begin() { return i; }I& end() { return n; }};

string s;
vector<int> S;
int D;
constexpr int mod=1e9+7;
bool vis[11234][2];
LL dp[11234][2][112];
void calc(int i,int ver){
    if(vis[i][ver])return;
    vis[i][ver]=true;
    if(i==S.size()){
        dp[i][ver][0]=1;
        return;
    }

    int p = ver?9:S[i];
    calc(i+1,0);
    calc(i+1,1);
    for(int x:range(D)){
        for(int y:range(p)){
            dp[i][ver][(x+y)%D]+=dp[i+1][1][x];
        }
    }
    for(int x:range(D)){
        for(int y:range(p,p+1)){
            dp[i][ver][(x+y)%D]+=dp[i+1][ver][x];
        }
    }
    for(int x:range(D)){
        dp[i][ver][x]%=mod;
        //cout<<i<<" "<<ver<<" "<<x<<" "<<dp[i][ver][x]<<endl;
    }

}
void latte(){
    for(int i:range(11234)){
        vis[i][0]=vis[i][1]=false;
        for(int j:range(112))dp[i][0][j]=dp[i][1][j]=0;
    }
}
int main(){
    cin>>s>>D;
    S.resize(s.size());
    for(int i:range(s.size()))S[i]=s[i]-'0';
    LL ret=0;
    latte();
    calc(0,0);
    ret+=dp[0][0][0];
    int p=s.size()-1;
    /*
    while(S[p]==0){
        S[p]=9;
        p--;
    }
    S[p]--;
    latte();
    calc(0,0);
    ret+=mod-dp[0][0][0];
    */
    cout<<(ret+mod-1)%mod<<endl;
    return 0;
}

Measured memory_bytes: 20480
N=int(input())
N=str(N)
N = int(N[-1])
if (N==2 or N==4 or N==5 or N==7 or N==9):
  print("hon")
elif (N==0 or N==1 or N==6 or N==8):
  print("pon") 
else:
  print("bon")

Measured memory_bytes: 9056
package main

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

func main() {
	sc := NewScanner()

	n := sc.ReadInt()
	aItemCount := make(map[int]int)
	aTotal := 0
	for i := 0; i < n; i++ {
		ai := sc.ReadInt()
		aItemCount[ai]++
		aTotal += ai
	}

	q := sc.ReadInt()
	for i := 0; i < q; i++ {
		bi := sc.ReadInt()
		ci := sc.ReadInt()

		replaceItemCount := aItemCount[bi]
		aTotal += (ci - bi) * replaceItemCount
		fmt.Println(aTotal)

		aItemCount[bi] = 0
		aItemCount[ci] += replaceItemCount
	}
}

// util
// *   math/simple

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

func Min(values ...int) int {
	if len(values) == 0 {
		panic("no values")
	}
	min := values[0]
	for _, v := range values {
		if v < min {
			min = v
		}
	}
	return min
}

func Max(values ...int) int {
	if len(values) == 0 {
		panic("no values")
	}
	max := values[0]
	for _, v := range values {
		if v > max {
			max = v
		}
	}
	return max
}

func Pow(base int, exponent uint) int {
	answer := 1
	for i := uint(0); i < exponent; i++ {
		answer *= base
	}
	return answer
}

func Ceil(divident, dividor int) int {
	quo := divident / dividor
	rem := divident % dividor

	if rem != 0 {
		if (divident > 0 && dividor > 0) ||
			(divident < 0 && dividor < 0) {
			return quo + 1
		}
	}
	return quo
}

// *   sortutil

func ReverseInts(a []int) {
	sort.Sort(sort.Reverse(sort.IntSlice(a)))
}

func ReverseStrings(a []string) {
	sort.Sort(sort.Reverse(sort.StringSlice(a)))
}

// *   io

type Scanner struct {
	bufScanner *bufio.Scanner
}

func NewScanner() *Scanner {
	bufSc := bufio.NewScanner(os.Stdin)
	bufSc.Split(bufio.ScanWords)
	bufSc.Buffer(nil, 100000000)
	return &Scanner{bufSc}
}

func (sc *Scanner) ReadString() string {
	bufSc := sc.bufScanner
	bufSc.Scan()
	return bufSc.Text()
}

func (sc *Scanner) ReadInt() int {
	bufSc := sc.bufScanner
	bufSc.Scan()
	text := bufSc.Text()

	num, err := strconv.Atoi(text)
	if err != nil {
		panic(err)
	}
	return num
}


Measured memory_bytes: 8716
import sys

n, *xl = map(int, sys.stdin.read().split())
xl = sorted(zip(*[iter(xl)] * 2))

def main():
    cnt = 0
    cur = -float('inf')
    for x, l in xl:
        left = x - l
        right = x + l
        if left >= cur:
            cur = right
            cnt += 1
            continue
        else:
            if right > cur:
                pass
            else:
                cur = right
                continue

    return cnt

if __name__ == '__main__':
    ans = main()
    print(ans)

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

int main() {
  int N;
  cin >> N;
  
  if (N % 1110 < 10){
    cout << "Yes" << endl;
  }
  else if (N % 1000 == 0){
    cout << "Yes" << endl;
  }
  else{
    cout << "No" << endl;
  }
}

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

using namespace std;

#define ll long long

int main() {
    string s;
    cin>>s;
    int n=s.size();
    int i=0,j=n-1;
    int ans=0;
    while(i<j) {
        if(s[i]==s[j]) i++,j--;
        else if(s[i]=='x') i++,ans++;
        else if(s[j]=='x') j--,ans++;
        else {
            ans=-1; break;
        }
    }
    cout<<ans<<endl;
    
    return 0;
}


Measured memory_bytes: 512
#include <iostream>
#include <fstream>
#include <sstream>
#include <string>
#include <cstring>
#include <vector>
#include <set>
#include <map>
#include <unordered_map>
#include <queue>
#include <deque>
#include <stack>
#include <algorithm>
#include <bitset>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <numeric>
#include <functional>
#include <cctype>
#include <list>
#include <limits>
#include <cassert>
//#include <boost/multiprecision/cpp_int.hpp>

const double EPS = (1e-10);


using namespace std;
using Int = long long;
//using namespace boost::multiprecision;

const Int MOD = 1000000007;

void fast_input() {
    cin.tie(0);
    ios::sync_with_stdio(false);
}

int main(void) {
    long long N; cin >> N;
    int ans = 0;
    for (long long i = 1; i < N; ans++) {
        i *= 3LL;
    }
    cout << ans << endl;
}   


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

using namespace std;

int l[110];

int main(){

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

    int n, x;
    cin >> n >> x;

    bool ok = true;
    int sum = 0;
    int counter = 1;
    for(int i=0;i<n;++i){
        cin >> l[i];
        if(sum + l[i] <= x and ok){
            sum += l[i];
            counter++;
        }else ok = false;
    }

    cout << counter << '\n';

    return 0;
}


Measured memory_bytes: 256
r,c = [eval(x) for x in input().split()]
table = [[eval(x) for x in input().split()] for _ in range(r)]
[table[i].append(sum(table[i])) for i in range(r)]
table.append([sum([table[i][j] for i in range(r)]) for j in range(c+1)])
[print(''.join([str(table[i][j]) + (' ' if j != c else '') for j in range(c+1)])) for i in range(r+1)]

Measured memory_bytes: 7500
num=[]
num=input().split(" ")
atama=int(num[0])
ashi=int(num[1])

count=0
for i in range(atama+1):
    if 2*(atama-i)+4*i == ashi:
        print("Yes")
        break
    else:
        count=count+1
    
    if count == atama+1:
        print("No")

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

int main() {
	long a,b;
	cin>>a>>b;
	long i=1,c,d,s1,s2,c1=0;
  long h=a>b?a:b;
	for(i=0;i<=h;i++)
	{
	    c=a-i;
	    d=b-i;
	    s1=abs(c);
	    s2=abs(d);
	    if(s1==s2){
          c1=1;
	        cout<<i;
	        break;
	    }
	}if(c1==0)
      cout<<"IMPOSSIBLE";
	return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define Mod(n) n % 1000000007
const int dx[8] = {1, 0, -1, 0, -1, 1, -1, 1};
const int dy[8] = {0, 1, 0, -1, 1, -1, -1, 1};

bool IsPrime(int num)
{
    if (num < 2) return false;
    else if (num == 2) return true;
    else if (num % 2 == 0) return false; // 偶数はあらかじめ除く

    double sqrtNum = sqrt(num);
    for (int i = 3; i <= sqrtNum; i += 2)
    {
        if (num % i == 0)
        {
            // 素数ではない
            return false;
        }
    }

    // 素数である
    return true;
}

void solve()
{
    int X;
    cin >> X;
    for(int i = X;;i++)
    {
        if(IsPrime(i))
        {
            cout << i << endl;
            break;
        }
    }
}

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


Measured memory_bytes: 256
import random
from collections import defaultdict


def solve(n, s, xs, m):
    ans = [10 ** 9] * (n + 1)
    for x in xs:
        p = 0
        h = 0
        y = 1
        r = pow(x, m - 2, m)
        pos = [0] * (n + 1)
        hashes = [0] * (n + 1)
        for i, c in enumerate(s, start=1):
            if c == '>':
                p += 1
                y = y * x % m
            elif c == '<':
                p -= 1
                y = y * r % m
            elif c == '+':
                h = (h + y) % m
            else:
                h = (h - y) % m
            pos[i] = p
            hashes[i] = h

        pow_x = [1]
        for _ in range(max(pos)):
            pow_x.append(pow_x[-1] * x % m)
        mp = min(pos)
        if mp < 0:
            pow_x.append(pow(r, -mp, m))
            for _ in range(-mp - 1):
                pow_x.append(pow_x[-1] * x % m)

        ideal = hashes[-1]
        required = defaultdict(lambda: 0)
        for i, (p, h) in enumerate(zip(pos, hashes)):
            ans[i] = min(ans[i], required[h])
            req = (ideal * pow_x[p] + h) % m
            required[req] += 1

    return sum(ans)


n = int(input())
s = input()

xs = random.sample(range(10 ** 9, 10 ** 10), 3)
m = 2305843009213693951
print(solve(n, s, xs, m))


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

using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;

typedef int _loop_int;
#define REP(i,n) for(_loop_int i=0;i<(_loop_int)(n);++i)
#define FOR(i,a,b) for(_loop_int i=(_loop_int)(a);i<(_loop_int)(b);++i)
#define FORR(i,a,b) for(_loop_int i=(_loop_int)(b)-1;i>=(_loop_int)(a);--i)

#define DEBUG(x) cout<<#x<<": "<<x<<endl
#define DEBUG_VEC(v) cout<<#v<<":";REP(i,v.size())cout<<" "<<v[i];cout<<endl
#define ALL(a) (a).begin(),(a).end()

#define CHMIN(a,b) a=min((a),(b))
#define CHMAX(a,b) a=max((a),(b))

// mod
const ll MOD = 1000000007ll;
#define FIX(a) ((a)%MOD+MOD)%MOD

// floating
typedef double Real;
const Real EPS = 1e-11;
#define EQ0(x) (abs(x)<EPS)
#define EQ(a,b) (abs(a-b)<EPS)
typedef complex<Real> P;

int main(){
  int n;
  cin>>n;
  vi a(n);
  REP(i,n)cin>>a[i];
  int x = *max_element(ALL(a)) - *min_element(ALL(a));
  cout<<x<<endl;
  return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
#include<stdlib.h>
int asc(const void *a, const void *b)
{
    return *(int *)a - *(int *)b;
}
int main()
{
    int n;
    scanf("%d", &n);
    int i;
    int x[200005];
    for (i = 0; i < n; i++)
        scanf("%d", &x[i]);
    int y[200005];
    for (i = 0; i < n; i++)
        y[i] = x[i];
    qsort(y, n, sizeof(int), asc);
    int a, b;
    a = y[(n / 2) - 1];
    b = y[n / 2];
    for (i = 0; i < n; i++)
    {
        if (2 * x[i] < a + b)
            printf("%d\n", b);
        else
            printf("%d\n", a);
    }
    return 0;
}

Measured memory_bytes: 3704
import java.io.File;
import java.io.IOException;
import java.util.ArrayDeque;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;
import java.util.Comparator;
import java.util.Deque;
import java.util.HashMap;
import java.util.List;
import java.util.Scanner;

public class Main {
 
	public static void main(String[] args) throws IOException {
		//File file = new File("input.txt");
		//Scanner sc = new Scanner(file);
		
		Scanner sc = new Scanner(System.in);
		
		int N = sc.nextInt();
		boolean ans = true;
		for(int i = 0; i < N; i++){
			String S = sc.next();
			if(S.equals("Y")){
				ans = false;
				break;
			}
		}
		System.out.println(ans?"Three":"Four");
	}
}

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

using namespace std;

int main()
{
  int n;
  cin>>n;
  vector<int> A(n, 0);
  for(int i = 0;i<n;i++)
  {
    cin>>A[i];
  }
  
  vector<int> dp(n, 0);
  dp[0] = 0, dp[1] = abs(A[1] - A[0]);
  for(int i = 2;i<n;i++)
  {
    dp[i] = min(dp[i-2]+abs(A[i] - A[i-2]), dp[i-1]+abs(A[i]-A[i-1]));
  }
  
  cout<<dp[n-1]<<endl;
}

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

using ll = long long;

ll f(int N, ll X) {
    ll levelNlen = 1;
    for (int t = 0; t < N; t++) {
        levelNlen = levelNlen *2 + 3;
    }
    ll _levelNlen = (levelNlen - 3) / 2;
    if(N==0) return 1;
    if (X <= 1) return 0;
    ll res = 0;
    if (X <= 1 + _levelNlen) return f(N - 1, X - 1);
    return (1LL<<N)-1 + 1 + (X == 1+_levelNlen+1 ? 0 : f(N-1,X-(1+_levelNlen+1)));
}

int main() {
    int N;
    ll X;
    cin>>N>>X;
    cout << f(N, X) << endl;
}


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

struct UnionFind {
  vector<int> d;  //リンクの情報。同時にサイズも持つ。
  UnionFind(int n = 0) : d(n, -1) {}  //最初はサイズは-1に設定
  int find(int x) {                   // findの実装
    if (d[x] < 0) return x;  //サイズが負なら親なのでその親のIDを返す
    return d[x] = find(d[x]);  //子なら根に向かって探索をする。
                               // d[x]=とすることで経路縮約を実現。
  }
  bool unite(int x, int y) {
    x = find(x);
    y = find(y);  // 2つの頂点を持ってくる
    if (x == y)
      return false;  //連結成分が一致するとやることがない。falseにするとくっつけられるかどうか確認できて楽。
    if (d[x] > d[y])
      swap(x, y);  // xの方を大きいとするが、サイズは負なので不等号に注意。
    d[x] += d[y];  //くっつけたのでサイズを合算する
    d[y] = x;      //大きい方に根を張り替える
    return true;
  }
  bool same(int x, int y) { return find(x) == find(y); }
  int size(int x) { return -d[find(x)]; }
};

int main() {
  int n, m;
  cin >> n >> m;
  UnionFind uf(n);
  rep(i, m) {
    int a, b;
    cin >> a >> b;
    --a, --b;
    uf.unite(a, b);
  }

  int ans = 0;
  rep(i, n) ans = max(ans, uf.size(i));
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 4060
#include <bits/stdc++.h>
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n) FOR(i,0,n)
#define repr(i,n) for(int i=(n)-1;0<=i;--i)
#define each(e,v) for(auto&& e:(v))
#define all(v) begin(v),end(v)
#define dump(x) cerr<<#x<<": "<<(x)<<endl
using namespace std;
using vint = vector<int>;
using ll = long long;
using vll = vector<ll>;
template <class T> void chmin(T& a, const T& b) { a = min(a, b); }
template <class T> void chmax(T& a, const T& b) { a = max(a, b); }
void yes() { cout << "Yes" << endl; exit(0); }
void no() { cout << "No" << endl; exit(0); }

int main() {
    int n, k; cin >> n >> k;
    if(k == 1) cout << 0 << endl;
    else cout << n - k << endl;
    return 0;
}


Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner scan = new Scanner(new BufferedReader(new InputStreamReader(System.in)));
        int A = scan.nextInt();
        int B = scan.nextInt();
        int C = scan.nextInt();
        boolean answer = false;
        if (A < C && C < B) {
            answer = true;
        }
        if (B < C && C < A) {
            answer = true;
        }
        System.out.println(answer ? "Yes" : "No");
    }
}


Measured memory_bytes: 21972
import sys
sys.setrecursionlimit(4100000)

import math

import logging

logging.basicConfig(level=logging.DEBUG)

logger = logging.getLogger(__name__)

# from collections import defaultdict
# d = defaultdict(list)

# from itertools import combinations
# comb = combinations(range(N), 2)

# 累積和
# from itertools import accumulate
# _list = list(accumulate(a_list)

# from functools import lru_cache
# @lru_cache(maxsize=None)
# def setUp(self):
#     dp.cache_clear()


def resolve():
    # S = [x for x in sys.stdin.readline().split()][0]  # 文字列 一つ
    N = [int(x) for x in sys.stdin.readline().split()][0]  # int 一つ
    # N, D = [int(x) for x in sys.stdin.readline().split()]  # 複数int
    x_list = [int(x) for x in sys.stdin.readline().split()]  # 複数int

    # grid = [list(sys.stdin.readline().split()[0]) for _ in range(N)]  # 文字列grid
    # v_list = [int(sys.stdin.readline().split()[0]) for _ in range(N)]
    # grid = [[int(x) for x in sys.stdin.readline().split()]
    #         for _ in range(N)]  # int grid

    logger.debug('{}'.format([]))

    _min = 10**10
    for p in range(min(x_list), max(x_list) + 1):
        _min = min(_min, sum([(x - p)**2 for x in x_list]))

    print(_min)


if __name__ == "__main__":
    resolve()

# AtCoder Unit Test で自動生成できる, 最後のunittest.main は消す
# python -m unittest template/template.py で実行できる
# pypy3 -m unittest template/template.py で実行できる

import sys
from io import StringIO
import unittest


class TestClass(unittest.TestCase):
    def assertIO(self, input, output):
        stdout, stdin = sys.stdout, sys.stdin
        sys.stdout, sys.stdin = StringIO(), StringIO(input)
        resolve()
        sys.stdout.seek(0)
        out = sys.stdout.read()[:-1]
        sys.stdout, sys.stdin = stdout, stdin
        self.assertEqual(out, output)

    def test_入力例_1(self):
        input = """2
1 4"""
        output = """5"""
        self.assertIO(input, output)

    def test_入力例_2(self):
        input = """7
14 14 2 13 56 2 37"""
        output = """2354"""
        self.assertIO(input, output)


Measured memory_bytes: 6316
#include<iostream>
using namespace std;
const int MAXN=10000+8;
int par[MAXN];
int rank[MAXN];
void init(int n){
	for(int i=0;i<n;i++){
		par[i]=i;
		rank[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(rank[x]<rank[y]){
		par[x]=y;
	}
	else par[y]=x;
	if(rank[x]==rank[y]) rank[x]++;
}
bool same(int x,int y){
	return find(x)==find(y);
}

int main(){
	int n,q;
	int a,s,j;
	cin>>n>>q;
	init(n);
	for(int i=0;i<q;i++){
		cin>>a>>s>>j;
		if(a==0) unite(s,j);
		if(a==1) cout<<same(s,j)<<endl;
	}
	return 0;
}

Measured memory_bytes: 3152
import java.util.*;
import java.lang.*;
import java.math.*;
import java.io.*;

import static java.lang.Math.*;
import static java.util.Arrays.*;

public class Main{

	Scanner sc=new Scanner(System.in);

	int INF=1<<28;
	double EPS=1e-9;

	int n, max;
	boolean[] b;

	void run(){
		max=300001;
		b=new boolean[max];
		for(int i=2; i<max; i++){
			if(i%7!=1&&i%7!=6){
				continue;
			}
			LinkedList<Integer> list=divisor(i);
			b[i]=true;
			for(int d : list){
				b[i]&=(d%7!=1&&d%7!=6)||d==1||d==i;
			}
		}
		for(;;){
			n=sc.nextInt();
			if(n==1){
				break;
			}
			solve();
		}
	}

	void solve(){
		Integer[] is=divisor(n).toArray(new Integer[0]);
		sort(is);
		String ans=n+":";
		for(int d : is){
			if(b[d]){
				ans+=" "+d;
			}
		}
		println(ans);
	}

	LinkedList<Integer> divisor(int n){
		LinkedList<Integer> list=new LinkedList<Integer>();
		for(int i=1; i*i<=n; i++){
			if(n%i==0){
				list.add(i);
				if(i!=n/i){
					list.add(n/i);
				}
			}
		}
		return list;
	}

	void debug(Object... os){
		System.err.println(Arrays.deepToString(os));
	}

	void print(String s){
		System.out.print(s);
	}

	void println(String s){
		System.out.println(s);
	}

	public static void main(String[] args){
		// System.setOut(new PrintStream(new BufferedOutputStream(System.out)));
		new Main().run();
	}
}

Measured memory_bytes: 13000
#include<bits/stdc++.h>
#define rep(i,a,b) for(int i=(a);i<=(b);++i)
using namespace std;
int n;
int main(){
	scanf("%d",&n);
	if(__builtin_popcount(n)==1){
		puts("No");
		return 0;
	}
	puts("Yes");
	if(n&1){
		for(int i=2;i<=n;i+=2){
			printf("%d %d\n",1,i);
			printf("%d %d\n",1,i+n+1);
			printf("%d %d\n",i,i+1);
			printf("%d %d\n",i+n,i+n+1);
		}
		printf("%d %d\n",n+1,3);
	}else{
		for(int i=2;i<=n-1;i+=2){
			printf("%d %d\n",1,i);
			printf("%d %d\n",1,i+n+1);
			printf("%d %d\n",i,i+1);
			printf("%d %d\n",i+n,i+n+1);
		}
		printf("%d %d\n",n+1,3);
		int pos=-1;
		for(int i=0;i<30;++i)if(n>>i&1){
			pos=1<<i;
			break;
		}
		printf("%d %d\n",n,pos);
		printf("%d %d\n",n+n,n-pos+n+1);
	}
	return 0;
}

Measured memory_bytes: 3756
import sys
N,X = map(int,input().split())
x = list(map(int,input().split()))

def gcd(a, b):
    if b == 0:
        return a
    else:
        return gcd(b, a % b) 

for i in range (0,N):
  x[i] = abs(x[i] - X)
x.sort()
ans = max(x)
for i in range (0,N-1):
  g = gcd(x[i],x[i+1])
  ans = min(g,ans)
print(ans)

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

int mass[20][20];
int num;

bool hasBlank(int n){
	for (int i = 0; i < n; i++) {
		for (int j = 0; j < n; j++) {
			if (mass[i][j] == -1) {
				return true;
			}
		}
	}
	return false;
}

void fill(int n, int x, int y){
	if (mass[y][x] != -1) {
			x--;
			if (x < 0) {
				x = n-1;
			}
			y = (y+1) % n;
			fill(n, x ,y);
	}else {
		mass[y][x] = num++;
	}
}

void printAnswer(int n){
		for (int i = 0; i < n; i++) {
			for (int j = 0; j < n; j++) {
				printf("%4d", mass[i][j]);
			}
			cout << endl;
		}
}

int main(){
	int n, x, y;
	while (cin >> n) {
		if (n == 0) {
			break;
		}
		for (int i = 0; i < n; i++) {
			for (int j = 0; j < n; j++) {
				mass[i][j] = -1;
			}
		}
		num = 1;
		// 1st step
		x = n/2;
		y = n/2+1;
		mass[y][x] = num++;
		// 2nd step
		while (hasBlank(n)) {
			x = (x+1) % n;
			y = (y+1) % n;
			fill(n, x ,y);
		}
		printAnswer(n);
	}
	return 0;
}

Measured memory_bytes: 0