akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#include <string>
  
#define repd(i,a,b) for (int i=(a);i<(b);i++)
#define rep(i,n) repd(i,0,n)
#define REP(i, n) for(int i=0; i<(n); ++i)
#define FOR(i, a, b) for(int i=(a); i<(b); ++i)
#define FORR(i, a, b) for(int i=(b)-1; i>=(a); --i)
typedef long long ll;

const ll MOD=1000000007ll;
const int MAX=5100000;

using namespace std;

int inputValue(){
    int a;
    cin >> a;
    return a;
};

void inputArray(int * p, int a){
    rep(i, a){
        cin >> p[i];
    }
};

void inputVector(vector<int> * p, int a){
    rep(i, a){
        int input;
        cin >> input;
        p -> push_back(input);
    }
}

ll fact[MAX], fact_inv[MAX];

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

// nCr
ll comb(ll n, ll r){
	ll t=1000000;
	fact[0]=1;
	REP(i, t) fact[i+1]=fact[i]*(i+1)%MOD;
	fact_inv[t]=power(fact[t], MOD-2);
	FORR(i, 0, t) fact_inv[i]=fact_inv[i+1]*(i+1)%MOD;
	return (fact[n]*fact_inv[r])%MOD*fact_inv[n-r]%MOD;
}
  
int main()
{
  ll N,K; cin >> N >> K;
  if(N % K == 0){cout << 0 << endl; return 0;}
  cout << min(N%K, abs(K-(N%K))) << endl;

  return 0;
}


Measured memory_bytes: 3632
def check(x, a, b, score)
  aa = (1 + x) / 2
  bb = (1 + x + 1) / 2
  return aa * bb <= score if a == b && aa == a && bb == b
  aa * bb < score
end

def solve(a, b)
  score = a * b
  ok, ng = 0, score + 1

  while (ok - ng).abs > 1
    STDERR.puts "#{ok}, #{ng}"
    mid = (ok + ng) / 2
    if check(mid, a, b, score)
      ok = mid
    else
      ng = mid
    end
  end
  ok
end

q = gets.to_i
q.times do
  a, b = gets.split.map(&:to_i)
  puts solve(a, b) - 1
end

Measured memory_bytes: 1788
#include <iostream>
#include <ostream>
#include <string>
#include <vector>
#include <map>
#include <algorithm>
#include <queue>

using namespace std;

int main()
{
    map<string, int> m;

    m["SUN"] = 7;
    m["MON"] = 6;
    m["TUE"] = 5;
    m["WED"] = 4;
    m["THU"] = 3;
    m["FRI"] = 2;
    m["SAT"] = 1;

    string s;

    cin >> s;

    cout << m[s] << endl;
}



Measured memory_bytes: 256
import java.util.LinkedList;
import java.util.List;
import java.util.Scanner;

public class Main {

	static char[] s;
	static int idx;
	static Panel now;
	static List<Panel> list;
	public static void main(String[] args) {
		Scanner cin = new Scanner(System.in);
		for(;;){
			int N=cin.nextInt();
			if(N==0)break;
			idx=0;
			s=(cin.next()+"   ").toCharArray();
			list=new LinkedList<Panel>();
			strc();
			for(Panel p:list){
//				System.out.println(p);
				if(p.children.size()!=0){
					for(Panel c:p.children){
//						System.out.println("children "+c);
					}

				}
				if(p.parent!=null){
//					System.out.println("parent "+p.parent);
				}
			}
			for(int i=0;i<N;i++){
				int[] a=new int[2];
				a[0]=cin.nextInt();
				a[1]=cin.nextInt();
				boolean f=false;
				for(Panel p:list){
					Panel ans=ans(a,p);
					if(ans!=null){
						System.out.println(ans);
						f=true;
						break;
					}
				}
				if(!f){
					System.out.println("OUT OF MAIN PANEL 1");
				}
			}
		}
	}
	static boolean strc(){
		if(s[idx+1]=='/'){
			return false;
		}
		idx++;
		String name=start();
		int[] p=value();
		Panel panel=new Panel(name,p);
		if(now!=null){
			now.children.add(panel);
			panel.parent=now;
		}
		now=panel;
		list.add(panel);

		while(strc());
		end();
		if(now.parent!=null){
			now=panel.parent;
		}
		return true;
	}
	static void end(){
		while(s[idx]!='>'){
			idx++;
		}
		idx++;
	}
	static String start(){
		String re="";
		for(;s[idx]!='>';){
			re=re+s[idx++];
		}
		idx++;
		return re;
	}
	static int[] value(){
		String re="";
		for(;s[idx]!='<';){
			re=re+s[idx++];
		}
		String[] ss=re.split(",");
		int[] p=new int[4];
		for(int i=0;i<4;i++){
			p[i]=Integer.parseInt(ss[i]);
		}
		return p;
	}
	static Panel ans(int[] a,Panel p){
		if(in(a,p.p)){
			for(Panel child:p.children){
				if(in(a,child.p)){
					return ans(a,child);
				}
			}
			return p;
		}
		else{
			return null;
		}
	}
	//点a、面b
	static boolean in(int[] a,int[] b){
		for(int i=0;i<2;i++){
			if(b[i]>a[i]||b[i+2]<a[i])return false;
		}
		return true;
	}
	static class Panel{
		String name;
		Panel parent;
		int[] p;
		List<Panel>children;
		Panel(String s,int[] a){
			name=s;
			p=new int[4];
			children=new LinkedList<Panel>();
			for(int i=0;i<4;i++){
				p[i]=a[i];

			}
		}
		public String toString(){
			return name+" "+children.size();
		}
	}
}

Measured memory_bytes: 20188
#include <bits/stdc++.h>
using namespace std;
int main() {
	string a, b, c;
	cin >> a >> b >> c;
	if((a[a.length() - 1] == b[0]) && (b[b.length() - 1] == c[0])) {
		cout << "YES" << endl;
	} else {
		cout << "NO" << endl;
	}

	return 0;
}

Measured memory_bytes: 256
h,w=map(int,input().split())

grid=[None]*h
for i in range(h):
  grid[i]=input()
  
def isOk(y,x):
  if y-1>=0 and grid[y-1][x]=="#":
    return True
  if y+1<h and grid[y+1][x]=="#":
    return True
  if x-1>=0 and grid[y][x-1]=="#":
    return True
  if x+1<w and grid[y][x+1]=="#":
    return True
  return False
  
for i in range(h):
  for j in range(w):
    if grid[i][j]=="#":
      if not isOk(i,j):
        print("No")
        exit(0)
print("Yes")

Measured memory_bytes: 3064
N=int(input())
S=[""]*N
for i in range(N):
  S[i]=input()
D="MARCH"
cnt=[0]*5
for s in S:
  if s[0] in D:
    cnt[D.index(s[0])]+=1
    
pat=[None]*10
pati=0
for a in range(5):
  for b in range(a+1,5):
    for c in range(b+1,5):
      pat[pati]=[a,b,c]
      pati+=1

ans=0
for p in pat:
  ans+=cnt[p[0]]*cnt[p[1]]*cnt[p[2]]
  
print(ans)

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




int main(void)
{
	int n, m;
	cin >> n >> m;
	int road[n] = {0};
	for (int i = 0; i < m; i++) {
		int a, b;
		cin >> a >> b;

		road[a-1]++;
		road[b-1]++;
	}

	for (int i = 0; i < n; i++)
		cout << road[i] << endl;


	return 0;
}


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

#define rep(i, n) for(int i = 0; i < (n); i++)
#define repp(i, l, r) for(int i = (l); i < (r); i++)
#define per(i, n) for(int i = ((n)-1); i >= 0; i--)
#define perr(i, l, r) for(int i = ((r)-1); i >= (l); i--)
#define all(x) (x).begin(),(x).end()
#define MOD 1000000007
#define IINF 1000000000
#define LINF 1000000000000000000
#define SP <<" "<<
#define CYES cout<<"Yes"<<endl
#define CNO cout<<"No"<<endl
#define CCYES cout<<"Yay!"<<endl
#define CCNO cout<<":("<<endl
#define CFS cin.tie(0);ios::sync_with_stdio(false)

typedef long long LL;
typedef long double LD;

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


Measured memory_bytes: 256
n=int(input())
d=list(map(int,input().split()))
d.sort()
l=n//2-1
half=(d[l]+d[l+1])//2
count=0
sum=0

if d[l]==d[l+1]:
  print(0)
  exit()

if d[l+1]>half:
  sum+=d[l+1]-half

if d[l]!=half:
  sum+=half-d[l]
  
print(sum)

Measured memory_bytes: 14428
#include<iostream>
#include<cstdlib>
#include<cstring>
#include<stack>
#include<queue>
using namespace std;

int max(int x, int y);
int min(int x, int y);
int gcd(int x, int y);	/*最大公約数*/
int lcm(int x, int y);	/*最小公倍数*/
void swap(int* x, int* y);	/*値の交換*/
void downsort(int* a, int n);	/*降順ソート*/
void upsort(int* a, int n);	/*昇順ソート*/

typedef stack<int> IntStack;
typedef queue<int> IntQueue;

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

/*ここからmain関数*/

int main()
{
	char s[100000];
	cin >> s;
	char t[] = "01";

	int bw = 0, wb = 0;
	int lgt = strlen(s);

	for (int i = 0;i < lgt;i++)
	{
		if (s[i]==t[i%2])
		{
			bw++;
		}
		else
		{
			wb++;
		}
	}

	if (bw < wb)
		cout << lgt - wb;
	else
		cout << lgt - bw;

	return 0;
}

/*2数の大きい方を返す*/
int max(int x, int y)
{
	int max;

	if (x < y)
		max = y;
	else
		max = x;

	return max;
}

/*2数の小さい方を返す*/
int min(int x, int y)
{
	int min;

	if (x < y)
		min = x;
	else
		min = y;

	return min;
}

/*2数の最大公約数を返す*/
int gcd(int x, int y)
{
	int m;
	int gcd = 1;

	m = min(x, y);

	for (int i = 1;i <= m; i++)
	{
		if (x%i == 0 && y%i == 0)
			gcd = i;
	}

	return gcd;
}

/*2数の最小公倍数を返す*/
int lcm(int x, int y)
{
	int m;

	for (int i = 1;i <= y;i++)
	{
		if ((x*i) % y == 0) {
			m = x * i;
			break;
		}
	}

	return m;
}

/*2数の値を交換する*/
void swap(int* px, int* py)
{
	int temp;

	temp = *px;
	*px = *py;
	*py = temp;
}

/*クイックソートによる降順並べ替え*/
void downsort(int* a, int n)
{
	//初期設定
	int l = 0, r = n - 1;

	// ピボットの決定
	int piv = *a;

	//ピボットより大を左に、ピボット以下を右に
	while (l < r)
	{
		if (*(a + l) > piv)
			l++;
		else if (*(a + r) <= piv)
			r--;
		else
			swap(a + l, a + r);
	}

	//再帰処理
	if (n == 2)
		return;
	else if (l == 1 || l == 0)
		downsort(a + 1, n - 1);
	else if (r == n - 1)
		downsort(a, n - 1);
	else
	{
		downsort(a, l);
		downsort(a + l, n - l);
	}
}

/*クイックソートによる昇順ソート*/
void upsort(int* a, int n)
{
	downsort(a, n);

	for (int i = 0;i < n / 2;i++)
		swap(a[i], a[n - 1 - i]);
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
#define mod 1000000007

long long modpow(long long n, long long r) {
    n %= mod, r %= (mod-1);
    if (!n) return 0;
    long long ret = 1; long long tmp = n;
    while (r != 0) {
        if (r % 2) ret *= tmp;
        tmp *= tmp; tmp %= mod; ret %= mod;
        r /= 2;
    }
    return ret;
}

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    int n = 3, k; cin >> k;
    vector<long long> v(k+1, 0);
    vector<long long> w(k+1, 0);
    for (int i = 1; i <= k; i++) v[i] = modpow(k / i, n), w[i] = i;
    for (int i = 1; i <= k; i++) {
        for (int j = 2*i; j <= k; j += i) {
            w[j] = (w[j] - w[i] + mod) % mod;
        }
    }
    long long ans = 0;
    for (int i = 1; i <= k; i++) {
        ans += v[i] * w[i] % mod;
        ans %= mod;
    }
    cout << ans << "\n";
    return 0;
}

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

using namespace std;

int main() {
	string S; 
    cin >> S;
	int n = S.size();

	int m = 0;
	for(int i = 0; i < n; i++) {
		int l = 0;
		for(int j = i; j < n; j++) {
			if(S[j] == 'A' || S[j] == 'C' || S[j] == 'G' || S[j] == 'T') {
				l++;
			} else {
				
				break;
			}
			m = max(m, l);
		}
	}
	cout << m << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define repp(i,l,r)for(long long i=(l);i<(r);i++)
#define rep(i,n) for (long long i = 0; i < (n); ++i)
#define per(i,n) for (long long i = (n); i >= 0; --i)
const int INF = 2147483647;//int max
const long long int MOD = 1000000007;
using namespace std;
using ll = long long;
using P = pair<int,int>;
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() {
    int n,k;
    cin >> n >> k;
    vector<int> v(k,0);
    rep(i,k)cin >> v[i];
    sort(v.begin(),v.end());
    ll res = n;
    while(1){
        string s = to_string(res);
        bool b = true;
        rep(i,s.length()){
            rep(j,k)if(s[i]-'0' == v[j]){
                b = false;
                break;
            }
            if(!b)break;
        }
        if(b){
            cout << res << endl;
            break;
        }
        else res++;
    }
    return 0;
}

Measured memory_bytes: 256
N = int(input())
A = list(map(int,input().split()))
B = list(map(int,input().split()))
C = list(map(int,input().split()))
S = sum(B)
for i in range(N-1):
    if A[i+1]==A[i]+1:
        j = A[i]-1
        S +=C[j]
print(S)

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


public class B
{
	public static void Main()
	{
		int n = GetInt();
		var p = new int[n];
		for(int i = 0; i < n; i++)
			p[i] = GetInt();

		int ans = 0;
		for(int i = 0; i < n - 2; i++)
		{
			int min = int.MaxValue;
			int max = int.MinValue;
			for(int j = 0; j < 3; j++)
			{
				min = Math.Min(min, p[i + j]);
				max = Math.Max(max, p[i + j]);
			}

			if(p[i + 1] != min && p[i + 1] != max)
				ans++;
		}

		Console.WriteLine(ans);
	}
}


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

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

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


Measured memory_bytes: 13140
#include<bits/stdc++.h>
#define de(x) cout<<#x<<"="<<x<<endl
#define dd(x) cout<<#x<<"="<<x<<" "
#define rep(i,a,b) for(int i=a;i<(b);++i)
#define repd(i,a,b) for(int i=a;i>=(b);--i)
#define repp(i,a,b,t) for(int i=a;i<(b);i+=t)
#define mt(a,b) memset(a,b,sizeof(a))
#define fi first
#define se second
#define mp(u,v) make_pair(u,v)
#define sz(a) (int)a.size()
#define pb push_back
#define PI acos(-1.0)
#define qc std::ios::sync_with_stdio(false)
#define all(a) a.begin(),a.end()
using namespace std;
typedef vector<int> vi;
typedef long long ll;
typedef double db;
typedef pair<ll,ll> pll;
typedef pair<ll,int> pli;
typedef pair<int,int> pii;
typedef pair<int,pii> piii;

const ll mod = 1000000007;
const int N = 2e5+6;
const int M = 2e6+6;
const double eps = 1e-6;
const int inf = 0x3f3f3f3f;

bool eq(const db &a, const db &b) { return fabs(a - b) < eps; }
bool ls(const db &a, const db &b) { return a + eps < b; }
bool le(const db &a, const db &b) { return eq(a, b) || ls(a, b); }
ll gcd(ll a,ll b) { return a==0?b:gcd(b%a,a); };
ll lcm(ll a,ll b) { return a/gcd(a,b)*b; }
ll kpow(ll a,ll b) {ll res=1;a%=mod; if(b<0) return 1; for(;b;b>>=1){if(b&1)res=res*a%mod;a=a*a%mod;}return res;}
ll read(){
    ll x=0,f=1;char ch=getchar();
    while (ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
    while (ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();}
    return x*f;
}
//inv[1]=1;
//for(int i=2;i<=n;i++) inv[i]=(mod-mod/i)*inv[mod%i]%mod;
int n, m;
int main() {
	while(~scanf("%d%d", &n, &m)) {
		puts(500*n>=m?"Yes":"No");
	}
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
int n,k,ans=0,pushnum=1,ma=0;
string s;
cin>>n>>k>>s;
vector<int> c(n);
vector<int> d={};
for(int i=0;i<n;i++){
    if(s.at(i)=='L'){c[i]=1;}
    else if(s.at(i)=='R'){c[i]=0;}
}
for(int i=0;i<n-1;i++){
    if(c[i]==c[i+1]){pushnum++;}
    else{d.push_back(pushnum);pushnum=1;}
}
d.push_back(pushnum);
if(d.size()<=2*k){cout<<n-1;return 0;}
else{
    for(int i=0;i<d.size();i++){
        ans+=d[i]-1;
    }
}
cout<<ans+2*k;
}


Measured memory_bytes: 1404
#include <iostream>
#include <string>
#include <vector>
#include <map>
#include <cmath>
#include <algorithm>
#include <functional>
#include <stack>
#include <numeric>
typedef long long ll;
using namespace std;
const int MOD = (int)1e9 + 7;
const ll INF = (ll)1e18 + 7;
#define int long long
#define all(vec) vec.begin(), vec.end()
#define dbg(x) cerr << #x << " = " << (x) << endl
#define yn(b) cout << ((b) ? "Yes" : "No") << endl
#define YN(b) cout << ((b) ? "YES" : "NO") << endl
#define isEven(t) t % 2 == 0

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

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

	int ans = 0;
	int N;
	cin >> N;
	for (int i = 0; i < N; i++) {
		int a;
		cin>>a;
		while(a%2==0){
			a /= 2;
			ans++;
		}
	}

	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 256
<?php
fscanf(STDIN, '%d', $N);

$nums = explode(' ', trim(fgets(STDIN)));

$ok = true;
for ($i=0; $i < $N; $i++) {
    if ($nums[$i] % 2 === 0) {
        if ($nums[$i] % 3 !== 0 && $nums[$i] % 5 !== 0) {
            $ok = false;
            break;
        }
    }
}

if ($ok) {
    echo 'APPROVED';
} else {
    echo 'DENIED';
}

echo PHP_EOL;


Measured memory_bytes: 16076
#include <algorithm>
#include <cassert>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <iostream>
#include <map>
#include <memory>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <utility>
#include <vector>
using namespace std;

typedef unsigned long ul;
typedef pair<ul, ul> P;
map<int, int> dp;
#define REP(i, n) for (int i = 0; i < n; i++)
ul H, W;

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  vector<ul> cities(5, 0);
  ul N;
  cin >> N;
  REP(i, 5) { cin >> cities[i]; }
  sort(cities.begin(), cities.end());
  ul ans = 4;
  ans += (cities[0] + (N - 1)) / cities[0];
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
//prepared by dumb
#include<bits/stdc++.h>
using namespace std;
#define   ll long long int
#define   dl double
#define   llu unsigned long long int
#define   scll(x) scanf("%lld",&x)
#define   scdl(x) scanf("%lf",&x)
#define   scull(x) scanf("%llu",&x)
#define   scch(x) scanf(" %c",&x)
#define   pb(x) push_back(x)
#define   pf(x) push_front(x)
#define   ppb() pop_back()
#define   ppf() pop_front()
#define   Pi acos(-1.0)
#define   INF 1000000000000000000
#define   mod 1000000007
#define   ff first
#define   ss second
#define   mpr make_pair
#define   debug(x) cout<<x<<'\n';
//sin((x*pi)/180.0)[x in degree]
//sin(x)[x in radian]
//asin(x)[radian]
//(asin(x)*180)/pi[degree]
//or(|)//and(&)//xor(^)//not(~)
#define fast ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
int main()
{
#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif
	ll a, b, c = 0, d, e, f = 0, g, h, i, j, k, l, m, n, o, p, q, r, s, t, u, v, w, x, y, z;
	ll cnt = 0, ans = 0, l1, l2, l3, c1 = 0, c2 = 0, c3 = 0, mx = 0, mn = 0;
	ll prevsum = 0, ans1 = 0, ans2 = 0, odd = 0, even = 0, hh, mm;
	string str, str1, str2;


	cin >> str1;
	cin >> str2;
	for (i = 0; i < str1.length(); i++)
	{
		if (str1[i]!=str2[i])
			c++;
	}
	cout << c;

	return 0;
}

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

using namespace std;

typedef double D;
typedef long long int LL;

#define st first
#define nd second
#define PLL pair <LL, LL>
#define PII pair <int, int>

const int N = 1e6 + 7;
const int MX = 1e9 + 7;
const LL INF = 1LL * MX * MX;

LL a, b, c, d;
map <LL, LL> M;

LL go(LL n){
	if(n <= 1)
		return n * d;
	
	if(n == 2)
		return min(d * 2, d + a);
	
	if(M.count(n))
		return M[n];
	
	LL ret = INF;
	if(INF / d >= n)
		ret = d * n;
	
	ret = min(ret, (n % 2) * d + a + go(n / 2));
	ret = min(ret, (2 - n % 2) * d + a + go(n / 2 + 1));

	ret = min(ret, (n % 3) * d + b + go(n / 3));
	ret = min(ret, (3 - n % 3) * d + b + go(n / 3 + 1));

	ret = min(ret, (n % 5) * d + c + go(n / 5));
	ret = min(ret, (5 - n % 5) * d + c + go(n / 5 + 1));
//	printf("%lld :: %lld\n", n, ret);
	return M[n] = ret;
}

void solve(){
	M.clear();
	LL n;
	scanf("%lld", &n);
	scanf("%lld %lld %lld %lld", &a, &b, &c, &d);
	printf("%lld\n", go(n));
}

int main(){
	int cases;
	scanf("%d", &cases);
	
	while(cases--)
		solve();
	return 0;
}

Measured memory_bytes: 4948
#include <algorithm>
#include <iostream>
#include <queue>
#include <string>

using namespace std;

void solve(int A, int B);

void solve(int A, int B) {
  int ans = max({2 * A - 1, 2 * B - 1, A + B});
  cout << ans << endl;
}

int main() {
  int A, B;
  cin >> A >> B;
  solve(A, B);
  return 0;
}


Measured memory_bytes: 888
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
ll ans = 0;
bool cmp(const pair<ll,ll> &a, const pair<ll,ll> &b){
  if(a.first==b.first)return a.second > b.second;
  else return a.first < b.first;
}
int main()
{
ll n ;
cin >> n ;
vector<pair<ll,ll>> v(n);
ll rmin=0,lmax=0;
rep(i, n){
  cin >> v[i].first >> v[i].second;
  ans=max(ans,v[i].second-v[i].first+1);
  if(v[rmin].second>v[i].second)rmin=i;
  if(v[lmax].first <v[i].first)lmax=i;
}
ans+=max(0LL,v[rmin].second-v[lmax].first+1);
ll ss=v[rmin].second,t=v[lmax].first;
sort(v.begin(),v.end(),cmp);
multiset<ll> s;
rep(i,n)s.insert(v[i].second);
rep(i,n){
  s.erase(s.find(v[i].second));
  ans=max(ans,max(ss-v[i].first+1,0LL)+max(*s.begin()-t+1,0LL));
}
cout << ans << endl;
return 0;
}

Measured memory_bytes: 6528
package main

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

func main() {
	stdin := bufio.NewScanner(os.Stdin)
	stdin.Scan()
	s := stdin.Text()
	cnt := 0
	l := len(s)
	for i := 0; i < l; i++ {
		if s[i] == '1' {
			cnt++
		}
	}

	fmt.Println(cnt)
}


Measured memory_bytes: 640
#include <cstdio>
#include <string>
#include <iostream>
using namespace std;
int ans;
int main()
{
    int n, a, b;
    string s;
    cin>>n>>a>>b>>s;
    for(int i = 0 ; i < n ; i++ )
    {
        if( s[i] == 'c' ) puts("No");
        else if( s[i] == 'a' )
        {
            if( a > 0 ) a--, puts("Yes");
            else if( b > 0 ) b--, puts("Yes");
            else puts("No");
        }
        else
        {
            if( b > 0 ) b--, puts("Yes");
            else puts("No");
        }
    }
}


Measured memory_bytes: 896
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <cstring>
#include <complex>
#include <stack>
#include <queue>
#include <unordered_map>
#include <map>
#define rep(i, a) for (int i = 0; i < (a); i++)
using namespace std;

int main(){
    string s, t;
    cin >> s;
    
    int i;
    
    for(i = 0; i < s.size(); i++){
        if(s[i] == '0'){
            t += "0";
        }else if(s[i] == '1'){
            t += "1";
        }else{
            if(!t.empty()){
                t.pop_back();
            }
        }
    }
    
    cout << t << endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ALL(x) x.begin(),x.end()
#define rep(i,n) for(int i=0;i<(n);i++)
#define debug(v) cout<<#v<<":";for(auto x:v){cout<<x<<' ';}cout<<endl;
#define mod 1000000007
using ll=long long;
const int INF=1000000000;
const ll LINF=1001002003004005006ll;
int dx[]={1,0,-1,0},dy[]={0,1,0,-1};
// ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
template<class T>bool chmax(T &a,const T &b){if(a<b){a=b;return true;}return false;}
template<class T>bool chmin(T &a,const T &b){if(b<a){a=b;return true;}return false;}
 
struct IOSetup{
    IOSetup(){
        cin.tie(0);
        ios::sync_with_stdio(0);
        cout<<fixed<<setprecision(12);
    }
} iosetup;
 
template<typename T1,typename T2>
ostream &operator<<(ostream &os,const pair<T1,T2>&p){
    os<<p.first<<" "<<p.second;
    return os;
}
 
template<typename T>
ostream &operator<<(ostream &os,const vector<T>&v){
    for(int i=0;i<(int)v.size();i++) os<<v[i]<<(i+1==(int)v.size()?"":" ");
    return os;
}

template<typename T1,typename T2>
istream &operator>>(istream &is,pair<T1,T2>&p){
    is>>p.first>>p.second;
    return is;
}

template<typename T>
istream &operator>>(istream &is,vector<T>&v){
    for(T &x:v)is>>x;
    return is;
}


int dp[310][310][610];
signed main(){
    string s;cin>>s;
    int m;cin>>m;
    int n=(int)s.size();
    if(m>=n){
        cout<<n<<endl;
        return 0;
    }
    string t=s;
    reverse(ALL(t));

    rep(i,n)rep(j,n)rep(k,m+1){
        chmax(dp[i+1][j+1][k],dp[i][j][k]+(s[i]==t[j]));
        chmax(dp[i+1][j+1][k],dp[i][j+1][k]);
        chmax(dp[i+1][j+1][k],dp[i+1][j][k]);
        chmax(dp[i+1][j+1][k+1],dp[i][j][k]+1);
    }
    int res=0;
    // t=rev(s)
    // s = [a   ][b     ]
    // t = [rb    ][ra  ]
    // LCS(a,rb)=LCS(b,ra)
    // 文字同士をマッチングさせることを考えるとそれはそう
    rep(i,n+1)chmax(res,2*dp[i][n-i][m]);
    rep(i,n)  chmax(res,2*dp[i][n-1-i][m]+1);
    cout<<res<<endl;
    return 0;
}


Measured memory_bytes: 218708
#include <iostream>
#include <string>
#include <vector>
#include <utility>
#include <queue>
#include <deque>
#include <stack>
#include <algorithm>
#include <bitset>
#include <cstdio>
#include <cmath>

using namespace std;

int main() {
    string s;
    cin >> s;
    if (s[0] == s[1] && s[1] == s[2]) {
        cout << "No" << endl;
        return 0;
    }
    cout << "Yes" << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define fi first
#define se second
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
#define srep(i,s,t) for (int i = s; i < t; ++i)
#define rng(a) a.begin(),a.end()
#define maxs(x,y) (x = max(x,y))
#define mins(x,y) (x = min(x,y))
#define limit(x,l,r) max(l,min(x,r))
#define lims(x,l,r) (x = max(l,min(x,r)))
#define isin(x,l,r) ((l) <= (x) && (x) < (r))
#define pb push_back
#define sz(x) (int)(x).size()
#define pcnt __builtin_popcountll
#define uni(x) x.erase(unique(rng(x)),x.end())
#define show(x) cout<<#x<<" = "<<x<<endl;
#define PQ(T) priority_queue<T,v(T),greater<T> >
#define bn(x) ((1<<x)-1)
#define dup(x,y) (((x)+(y)-1)/(y))
#define newline puts("")
#define v(T) vector<T>
#define vv(T) v(v(T))
using namespace std;
typedef long long int ll;
typedef unsigned uint;
typedef unsigned long long ull;
typedef pair<int,int> P;
typedef set<int> S;
typedef queue<int> Q;
typedef queue<P> QP;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<P> vp;
inline int in() { int x; scanf("%d",&x); return x;}
const ll LINF = 1001002003004005006ll;
const int INF = 1001001001;
const int MOD = 1000000007;
#define dame { puts("-1"); return 0;}
#define yn {puts("YES");}else{puts("NO");}
  
int main() {
  ll N;
  cin >> N;
  vector<pair<ll,ll>> data(N);
  rep(i,N) {
    ll t,a;
    cin >> t >> a;
    data[i] = P(t,a);
  }
  ll a = data[0].first;
  ll b = data[0].second;
  srep(x,1,N) {
    ll na = data[x].first;
    ll nb = data[x].second;
    ll k = max((ll)((a+na-1)/na), (ll)((b+nb-1)/nb));
    a = na * k;
    b = nb * k;
  }
  cout << a + b << endl;
  return 0;
}

Measured memory_bytes: 764
#include <iostream>

using namespace std;

int main()
{
    int a,b;
    cin >> a >> b;
    if(a%3==0) cout << "Possible";
    else if(b%3==0) cout << "Possible";
    else if((a+b)%3==0) cout << "Possible";
    else cout << "Impossible";
}


Measured memory_bytes: 256
#include <algorithm>
#include <bitset>
#include <cctype>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>
using namespace std;

int main() {
    stack<int> st;
    string in;
    while (cin >> in) {
        if (in.size() == 1 && !isdigit(in[0])) {
            int b = st.top(); st.pop();
            int a = st.top(); st.pop();
            switch (in[0]) {
            case '+':
                st.push(a + b);
                break;
            case '-':
                st.push(a - b);
                break;
            case '*':
                st.push(a * b);
                break;
            }
        } else {
            stringstream ss;
            ss << in;
            int num;
            ss >> num;
            st.push(num);
        }
    }
    cout << st.top() << endl;
}

Measured memory_bytes: 1232
#include <cstdio>
#include <algorithm>
#include <iostream>
using namespace std;
int dp[1000001],Odp[1000001];
int Tn[200],OTn[200]; 

int main(){
    int count = 0;  //pollocks numberの生成
    for(int i = 1;i < 200;i++){
        Tn[i-1] = i * (i + 1) * (i + 2) / 6;
        if(Tn[i-1] % 2 == 1){
            OTn[count] = Tn[i-1];
            count++;
        }
    }
    int n = 1000000;

    //正四面体数の個数の最小値
    for(int j = 0;j <= n;j++)
        dp[j] = j;
    int k;
    for(int i = 0;i < 200;i++)
        for(int j = Tn[i];j <= 1000000;j++){
            if(j >= Tn[i])
                dp[j] = min(dp[j],dp[j-Tn[i]] + 1);
            k = i;
        }

    //奇数正四面体数の個数の最小値
    for(int j = 0;j <= n;j++)
        Odp[j] = j;
    int k1;
    for(int i = 0;i <= 200;i++)
        for(int j = OTn[i];j <= n;j++){
            if(j >= OTn[i])
                Odp[j] = min(Odp[j],Odp[j-OTn[i]] + 1);
            k1 = i;
        }
    while(cin >> n,n)
        cout << dp[n] << ' ' <<  Odp[n] << endl;


    return 0;
}


Measured memory_bytes: 10904
#include <algorithm>
#include <climits>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <limits>
#include <map>
#include <memory>
#include <numeric>
#include <queue>
#include <set>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <vector>

//std::cout << std::fixed << std::setprecision(10)
constexpr long long MOD = 1000000007;

int main()
{
  std::string S;
  std::cin >> S;
  std::reverse(S.begin(), S.end());
  std::vector<std::array<long long, 13>> dp(S.size());
  dp[0].fill(0);
  if (S[0] == '?')
  {
    for (int i = 0; i <= 9; ++i)
      ++dp[0][i];
  }
  else
    ++dp[0][S[0] - '0'];
  long long pow = 1;
  for (int i = 1; i < S.size(); ++i)
  {
    dp[i].fill(0);
    pow *= 10;
    pow %= 13;
    if (S[i] == '?')
    {
      for (int j = 0; j < 10; ++j)
      {
        long long val = (pow * j) % 13LL;
        for (int k = 0; k < 13; ++k)
        {
          dp[i][(k + val) % 13] += dp[i - 1][k];
          dp[i][(k + val) % 13] %= MOD;
        }
      }
    }
    else
    {
      long long val = (pow * (S[i] - '0')) % 13LL;
      for (int j = 0; j < 13; ++j)
      {
        dp[i][(j + val) % 13] = dp[i - 1][j];
      }
    }
  }

  std::cout << dp.back()[5] << std::endl;

  return 0;
}



Measured memory_bytes: 10624
// Problem : B - Mix Juice
// Contest : AtCoder - AtCoder Beginner Contest 171
// URL : https://atcoder.jp/contests/abc171/tasks/abc171_b
// Memory Limit : 1024 MB
// Time Limit : 2000 ms
// Powered by CP Editor (https://github.com/cpeditor/cpeditor)

#include <iostream>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <stack>
#include <queue>
#include <vector>
#include <map>
#include <set>
#include <unordered_set>
#include <unordered_map>
#define ll long long
#define fi first
#define se second
#define pb push_back
#define me memset
const int N = 1e6 + 10;
const int mod = 1e9 + 7;
const int INF = 0x3f3f3f3f;
using namespace std;
typedef pair<int,int> PII;
typedef pair<ll,ll> PLL;

int n,k;
int a[N];

int main() {
    ios::sync_with_stdio(false);cin.tie(0);
	cin>>n>>k;
	 for(int i=1;i<=n;++i){
	 	cin>>a[i];
	 }
	 sort(a+1,a+1+n);
	 int res=0;
	 for(int i=1;i<=k;++i){
	 	res+=a[i];
	 }
	 cout<<res<<endl;


    return 0;
}


Measured memory_bytes: 3660
#include<iostream>
#include<iomanip>
#include<cstdio>
#include<string>
#include<cstring>
#include<climits>
#include<algorithm>
#include<vector>
#include<cmath>
#include<map>
#include<set>
#include<stack>
#include<queue>
#include<tuple>
#include<list>
#include<unordered_map>
#define ll long long
#define pii pair<int,int>
#define pll pair<ll,ll>
#define vii vector<int>
#define vll vector<ll>
#define lb lower_bound
#define pb push_back
#define mp make_pair
#define rep(i,n) for(ll i=0;i<n;i++)
#define rep2(i,a,b) for(ll i=a;i<b;i++)
#define repr(i,n) for(ll i=n-1;i>=0;i--)
#define all(x) x.begin(),x.end()
#define INF (1 << 30) - 1
#define LLINF (1LL << 61) - 1
// #define int ll
using namespace std;
const int MOD = 1000000007;
const int MAX = 510000;

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll n,a[100010],cnt=0;
    map<ll,ll> mp;
    cin>>n;
    rep(i,n){
        cin>>a[i];
        mp[a[i]]=i;
    }
    sort(a,a+n);
    rep(i,n){
        if(mp[a[i]]%2 != i%2) cnt++;
    }
    cout<<cnt/2<<endl;
    return 0;
}

Measured memory_bytes: 7296
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define chmin(x,y) x = min(x,y)
using namespace std;
typedef long long ll;
 
const int INF = 1001001001;
 
int main() {
  int n, m, l;
  cin >> n >> m >> l;
  vector<vector<int>> dist(n, vector<int>(n,INF));
  rep(i,n) dist[i][i] = 0;
  rep(i,m) {
    int a, b, c;
    cin >> a >> b >> c;
    --a; --b;
    dist[a][b] = dist[b][a] = c;
  }
  rep(k,n)rep(i,n)rep(j,n) chmin(dist[i][j], dist[i][k]+dist[k][j]);
  vector<vector<int>> dist2(n, vector<int>(n,INF));
  rep(i,n)rep(j,n) {
    if (dist[i][j] <= l) dist2[i][j] = 1;
  }
  rep(k,n)rep(i,n)rep(j,n) chmin(dist2[i][j], dist2[i][k]+dist2[k][j]);
  int q;
  cin >> q;
  rep(qi,q) {
    int s, t;
    cin >> s >> t;
    --s; --t;
    int ans = dist2[s][t]-1;
    if (dist2[s][t] == INF) ans = -1;
    cout << ans << endl;
  }
  return 0;
}

Measured memory_bytes: 1280
#include <iostream>
#include <cstring>
#include <map>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <set>
#include <vector>
#include <queue>
#include <list>
#include <numeric>
#include <stdio.h>
#include <string>
#include <cstdlib>
#include <math.h>
#include <stack>
#include <climits>
#include <bitset>

using namespace std;
typedef long long ll;

//最小公倍数
ll gcd(ll x, ll y) {
  ll tmp = 0;
  if (x < y){
    tmp=x;
    x=y;
    y=tmp;
  }
  while (y > 0) {
    ll r = x % y;
    x = y;
    y = r;
  }
  return x;
}

//最大公倍数
ll lcm(ll x,ll y){
  return x/gcd(x,y)*y;
}

//階乗
ll kaijo(ll k){
    ll sum = 1;
    for (ll i = 1; i <= k; ++i)
    {
        sum *= i;
        sum%=1000000000+7;
    }
    return sum;
}

//for(int i = ; i < ; i++){}



int main(){
  int a,b,c;
  cin>>a>>b>>c;
  if(b-a==c-b)cout<<"YES"<<endl;
  else cout<<"NO"<<endl;
  return 0;
}

Measured memory_bytes: 256
{-# LANGUAGE BangPatterns #-}
import Control.Monad
import Data.Maybe
import Debug.Trace
import Data.List
import qualified Data.Map.Strict as Map
import qualified Data.IntMap.Strict as IntMap
import qualified Data.Set as Set
import qualified Data.IntSet as IntSet
import Data.Functor
import Data.Array
-- import Data.Array.Unboxed
import Control.Monad.ST
import Data.Array.ST

main :: IO ()
main = getLine >>= print . solve . map read . words
solve :: [Int] -> Int
solve (r:g:b:n:_) = length [ i | i <- [0..(n `div` r)], j <- [0..((n - i * r) `div` b)], (n - i*r - j * b) `mod` g == 0]


Measured memory_bytes: 508
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner scanner = new Scanner(System.in);
		int numClocks = Integer.parseInt(scanner.nextLine());

		long currentLCM = 1;
		for (int clockIndex = 0; clockIndex < numClocks; clockIndex++) {
			long period = Long.parseLong(scanner.nextLine());
			currentLCM = lcm(currentLCM, period);
		}

		System.out.println(currentLCM);
	}

	private static long lcm(long num1, long num2) {
		return num1 * (num2 / gcd(num1, num2));
	}

	private static long gcd(long num1, long num2) {
		return num2 == 0 ? num1 : gcd(num2, num1 % num2);
	}
}


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

typedef unsigned long long ull;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<double, double> pdd;
//const ull mod = 1e9 + 7;
const ll mod = 1e9 + 7;
#define REP(i,n) for(int i=0;i<(int)n;++i)

// debug
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

template<class S, class T> ostream& operator << (ostream& os, const pair<S, T> v){
  os << "(" << v.first << ", " << v.second << ")"; return os;
}
template<class T> ostream& operator << (ostream& os, const vector<T> v){
  for(int i = 0; i < (int)v.size(); i++){if(i > 0){os << " ";} os << v[i];} return os;
}
template<class T> ostream& operator << (ostream& os, const vector<vector<T>> v){
  for(int i = 0; i < (int)v.size(); i++){if(i > 0){os << endl;} os << v[i];} return os;
}
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 (a>b) { a=b; return 1; } return 0; }

// conversion number to bit
string num2bit(ll num, ll len){
  string bit = "";
  REP(i, len){
    bit += char('0'+(num>>i & 1));
  }
  return bit;
}

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

    ll N;
    cin >> N;
    REP(i, N){
    	char t;
    	cin >> t;
    	if(t=='Y'){
    		cout << "Four" << endl;
    		return 0;
    	}
    }
    cout << "Three" << endl;
    return 0;
}

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

int judge(const std::vector<std::vector<int>> &count, const std::vector<int> & perm,
          const int K, const int W) {
    auto h_div_count = perm.size();
    std::vector<int> v_perm;
    auto prev_idx = 0;
    for (auto idx = 1 ;idx < W + 1;) {
        for (auto h_idx = 1; h_idx < h_div_count; h_idx++) {
            int choco_num = count[perm[h_idx]][idx] - count[perm[h_idx]][prev_idx]
                - count[perm[h_idx - 1]][idx] + count[perm[h_idx - 1]][prev_idx];
            if (choco_num > K) {
                if (idx - prev_idx == 1) {
                    return -1;
                }
                v_perm.push_back(idx - 1);
                prev_idx = idx - 1;
                idx--;
                break;
            }
        }
        idx++;
    }
    return perm.size() + v_perm.size() - 2;
}

int main() {
    int H, W, K;

    std::cin >> H >> W >> K;

    std::vector<std::vector<char>> S(H, std::vector<char>(W));
    for (int h = 0; h < H; h++) {
        for (int w = 0; w < W; w++) {
            std::cin >> S[h][w];
        }
    }

    std::vector<std::vector<int>> count(H + 1, std::vector<int>(W + 1, 0));
    for (int h = 1; h <= H; h++) {
        for (int w = 1; w <= W; w++) {
            int val = S[h - 1][w - 1] == '0' ? 0 : 1;
            count[h][w] += val
                + count[h - 1][w] + count[h][w - 1] - count[h - 1][w - 1];
        }
    }

    int min_div_c = W + H -2;
    for (int bit = 0; bit < (1 << (H - 1)); bit++) {
        std::vector<int> perm;
        perm.push_back(0);
        for (int i = 0; i < H - 1; i++) {
            if (bit & (1 << i)) {
                perm.push_back(i + 1);
            }
        }
        perm.push_back(H);

        int div_c = judge(count, perm, K, W);
        if (div_c != -1 && div_c < min_div_c) {
            min_div_c = div_c;
        }
    }
    std::cout << min_div_c << std::endl;
}


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

#define REP(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define all(x) (x).begin(),(x).end()
using ll = long long;
string char_to_string(char val) {
  return string(1, val);
}
int char_to_int(char val) {
  return val - '0';
}
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 vector_finder(std::vector<ll> vec, int number) {
  auto itr = std::find(vec.begin(), vec.end(), number);
  size_t index = std::distance( vec.begin(), itr );
  if (index != vec.size()) { // 発見できたとき
    return 1;
  }
  else { // 発見できなかったとき
    return 0;
  }
}

int main() {
  string S; cin >> S;
  int ans = 100000000;
  for(int i = 0; i < S.size() - 2; ++i) {
    string tmp = S.substr(i, 3);
    int a = stoi(tmp);
    if(ans > abs(a - 753)) ans = abs(a - 753);
  }
  cout << ans << endl;
}


Measured memory_bytes: 3624
A = zip(range(60, 180, 20), [2] + range(5, 30, 5))
C = range(600, 1800, 200)

while 1:
  n = int(raw_input())
  if n==0: break
  s = 0
  for _ in [0]*n:
    x, y, h, w = map(int, raw_input().split())
    r = 0
    size = x + y + h
    for a, b in A:
      if size > a or w > b: r+=1
      else: break
    if r<6: s += C[r]
  print s

Measured memory_bytes: 4304
#include<algorithm>
#include<iostream>
#include<cstring>
#include<cstdio>
#include<cmath>
#define LL long long
#define M 200020
#define INF 10000000000000ll
using namespace std;
namespace IO{
	const int BS=(1<<20); char Buffer[BS],*HD,*TL;
	char Getchar(){if(HD==TL){TL=(HD=Buffer)+fread(Buffer,1,BS,stdin);} return (HD==TL)?EOF:*HD++;}
	int read(){
		int nm=0,fh=1; char cw=Getchar();
		for(;!isdigit(cw);cw=Getchar()) if(cw=='-') fh=-fh;
		for(;isdigit(cw);cw=Getchar()) nm=nm*10+(cw-'0');
		return nm*fh;
	}
}
using namespace IO;
int n,m,A,B,G[M]; LL maxn,p[M<<2][2],ans=INF;
void pushup(int x){
	p[x][0]=min(p[x<<1][0],p[x<<1|1][0]);
	p[x][1]=min(p[x<<1][1],p[x<<1|1][1]);
}
void build(int x,int l,int r){
	if(l==r){
		if(l==A) p[x][0]=-l,p[x][1]=l;
		else p[x][0]=p[x][1]=INF; return;
	}
	int mid=((l+r)>>1); build(x<<1,l,mid);
	build(x<<1|1,mid+1,r),pushup(x);
}
LL qry(int x,int l,int r,int L,int R,int kd){
	if(r<L||R<l) return INF; if(L<=l&&r<=R) return p[x][kd];
	int mid=((l+r)>>1); return min(qry(x<<1,l,mid,L,R,kd),qry(x<<1|1,mid+1,r,L,R,kd));
}
void mdf(int x,int l,int r,int pos,LL dt){
	if(l==r){p[x][0]=min(p[x][0],dt-l),p[x][1]=min(p[x][1],dt+l);return;}
	int mid=((l+r)>>1);if(pos<=mid) mdf(x<<1,l,mid,pos,dt);else mdf(x<<1|1,mid+1,r,pos,dt); pushup(x);
}
void dfs(int x,int l,int r){
	if(l==r){ans=min(ans,p[x][0]+(LL)l);return;}
	int mid=((l+r)>>1);dfs(x<<1,l,mid),dfs(x<<1|1,mid+1,r);
}
int main(){
	n=read(),m=read(),A=read(),B=read(),G[0]=B,build(1,1,n);
	for(int i=1;i<=m;i++){
		G[i]=read(); LL t1=G[i]+qry(1,1,n,1,G[i],0)+maxn;
		LL t2=qry(1,1,n,G[i],n,1)-G[i]+maxn,dt=abs(G[i]-G[i-1]);
		maxn+=dt,mdf(1,1,n,G[i-1],min(t1,t2)-maxn);
	} dfs(1,1,n),printf("%lld\n",maxn+ans); return 0;
}

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

namespace ConsoleApplication6
{

    class Program
    {
        static int H = 0;
        static int W = 0;
        static int K = 0;
        static int hmax = 0;
        static int wmax = 0;
        static void Main(string[] args)
        {
            var D = RL2IE().ToList();
            H=D[0];
            W=D[1];
            K = D[2];
            hmax = (int)Math.Pow(2, H)-1;
            wmax = (int)Math.Pow(2, W)-1;

            //var whitestr = ".";
            var blackstr = '#';

            var bitlst = new List<int>();
            for (var i = 0; i < H; i++)
            {
                var line = 0;
                var str = RL();
                for (int seek = 0; seek < W; seek++)
                {
                    var bit = str[seek] == blackstr ? 1 : 0;
                    line |= (bit << seek);
                }
                bitlst.Add(line);
            }

            var ret=dfs(hmax, wmax, bitlst, 0);



            Console.WriteLine(ret);
            Console.ReadLine();

        }
        static int dfs(int hlst, int wlst,List<int> bitlst,int count)
        {
            var num = checkcount(hlst, wlst, bitlst);
            if (num == K) count++;
            if (hlst <= 0 && wlst <= 0) return count;
            else if (hlst<=0) {
                wlst--; 
                hlst = hmax;

                /*while (checkcount(hlst, wlst, bitlst) < K)
                {
                    wlst--;
                    if (wlst <= 0) break;
                }*/
            }
            else hlst--;
            return dfs(hlst, wlst, bitlst,count);
           
        }
        static int checkcount(int hlst, int wlst,List<int> bitlst)
        {
            var count = 0;
            var masked = bitlst.Select(x => x & wlst).ToList();

            for (int i = 0; i < masked.Count(); i++)
            {
                if ((hlst & (1 <<i))==0) masked[i]=0;
            }
            foreach (var mask in masked)
            {
                count += numofbit(mask);
            }
            //Console.WriteLine(count);
            return count;
        }
        static int numofbit(long bits)
        {
            bits = ((bits & 0xAAAAAAAA) >> 1) + (bits & 0x55555555);
            bits = ((bits & 0xCCCCCCCC) >> 2) + (bits & 0x33333333);
            bits = ((bits & 0xF0F0F0F0) >> 4) + (bits & 0x0F0F0F0F);
            bits = ((bits & 0xFF00FF00) >> 8) + (bits & 0x00FF00FF);
            bits = ((bits & 0xFFFF0000) >> 16) + (bits & 0x0000FFFF);
            return (int)bits;

        }
        static IEnumerable<int> RL2IE() { return spr(RL()).Select(x => (int)c2i(x)); }
        static string RL() { return Console.ReadLine().Trim(); }
        static IEnumerable<string> spr(string s) { return s.Split(' '); }
        static Int64 c2i(string c) { return Int64.Parse(c); }
        //static double c2d(string c) { return double.Parse(c); }
        static string bool2ret(bool b) { return b ? "Yes" : "No"; }
    }
}


Measured memory_bytes: 29864
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner((System.in));
		String x = sc.next();
		String y = sc.next();

		if (x.matches("(1|3|5|7|8|10|12)") && y.matches("(1|3|5|7|8|10|12)")) {
			System.out.println("Yes");
		} else if (x.matches("(4|6|9|11)") && y.matches("(4|6|9|11)")) {
			System.out.println("Yes");
		} else if (x.equals("2") && y.equals("2")) {
			System.out.println("Yes");
		} else {
			System.out.println("No");
		}
		sc.close();
	}
}


Measured memory_bytes: 23764
#include <stdio.h>
#include <stdlib.h>
#include <iostream>

using namespace std;

struct Node{
    int key;
    Node *parent,*left,*right;
};

Node *root,*NIL;

void insert(int key){
    Node* y = NIL;
    Node* x = root;
    Node* z = (Node*)malloc(sizeof(Node));
    z->key = key;
    z->left = NIL;
    z->right = NIL;
    
    // 挿入するノードの探索
    while(x != NIL){
        // 親の設定
        y = x;
        // 挿入する位置を決定する
        if(key < x->key){
            x = x->left;
        }else{
            x = x->right;
        }
    }
    
    // 親の設定
    z->parent = y;
    
    // 親が空の場合(2分木が空の場合)
    if(y == NIL){
        root = z;
    }
    else if(key < y->key){
        y->left = z;
    }
    else{
        y->right = z;
    }
}

/**
 根→左→右の順番で出力する
 */
void preOrder(Node* node){
    if(node == NIL){
        return;
    }
    // 根である自身を出力する
    cout << " " << node->key;
    // 左
    if(node->left != NIL){
        preOrder(node->left);
    }
    // 右
    if(node->right != NIL){
        preOrder(node->right);
    }
}

/**
    対象のキーを散策する
*/
bool find(int key){
    bool find = false;
    Node* x = root;
    while(x != NIL){
        if(x->key == key){
            find = true;
            break;
        }
        else if(key < x->key){
            x = x->left;
        }
        else{
            x = x->right;
        }
    }
    return find;
}

/**
 左部分木 → 根節点 → 右部分木の順番で節点をまわること
 */
void inOrder(Node* node){
    if(node == NIL){
        return;
    }
    // 左を探す
    if(node->left != NIL){
        inOrder(node->left);
    }
    // 左がなくなったら左を出力する
    cout << " " << node->key;
    // 右
    if(node->right != NIL){
        inOrder(node->right);
    }
}

int main(void){
    int n,key;
    
    cin >> n;
    
    for(int i = 0;i < n;++i){
        string input;
        cin >> input;
        // insert
        if(input[0] == 'i'){
            cin >> key;
            insert(key);
        }
        else if(input[0] == 'f'){
            cin >> key;
            string s = find(key) ? "yes" : "no";
            cout << s << endl;
        }
        else{
            inOrder(root);
            cout << endl;
            preOrder(root);
            cout << endl;
        }
    }
    return 0;
}



Measured memory_bytes: 21928