akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;

// ----------------------------------------Defines and Template-------------------------------------//
#define int long long
#define ll long long
#define double long double
#define f first
#define ss second
#define mp make_pair
#define pb push_back

#define all(v) v.begin(),v.end()
#define pii pair<int,int>
#define pll pair<ll,ll>
#define vi vector<int>
#define vii vector<vi>
#define vl vector<ll>
#define vpii vector<pii>
#define vpll vector<pll>
#define print(arr) for (auto it = arr.begin(); it != arr.end(); ++it) cout << *it << " "; cout << endl;

typedef tree<
int,
null_type,
less<int>,
rb_tree_tag,
tree_order_statistics_node_update>
ordered_set;
//order_of_key (k) : Number of items strictly smaller than k .
//find_by_order(k) : K-th element in a set (counting from zero).

#define setitr set <int, greater <int> > :: iterator
#define RE(i,n) for(int i=1; i<=n; i++)
#define REP(i,j,n) for(int i=j; i<=n; i++)
#define REB(i,j,n) for(int i=j; i>=n; i--)
#define FO(i,n) for(int i=n; i>0; i--)

const int mod = 1e9+7;
const int INF = 1e16;
const int LGN = 30;
const int N = 2e5+5;

//-------------------------------------------------Template Ends------------------------------------------------------/

void solve_case()
{
    int n,i,j;
    cin >> n;
    int a[n+2], dp[n+2];
    RE(i,n) cin >> a[i];
    dp[1] = 0;
    dp[0] = 0;
    dp[2] = abs(a[2]-a[1]);
    REP(i,3,n)
    {
        dp[i] = min(dp[i-1] + abs(a[i]-a[i-1]) , dp[i-2] + abs(a[i]-a[i-2]));
    }
    //RE(i,n) cout << dp[i] << " "; cout << "\n";
    cout << dp[n] << "\n";
}

signed main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);cout.tie(0);
    //freopen("input.txt", "r", stdin);
    int T = 1;
    //cin >> T;
    while(T--)
    {
        solve_case();
    }
    return 0;
}


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

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

int a[maxn];

int main() {
#ifdef suiyuan2009
  freopen("/Users/suiyuan2009/CLionProjects/icpc/input.txt", "r", stdin);
  //freopen("/Users/suiyuan2009/CLionProjects/icpc/output.txt", "w", stdout);
#endif
  int n,m;
  cin>>n>>m;
  int sum = 0;
  for(int i=1;i<=n;i++){
    cin>>a[i];
    sum+=a[i];
  }
  int cnt = 0;
  for(int i=1;i<=n;i++){
    if(a[i]*4*m>=sum)cnt++;
  }
  cout<<(cnt>=m?"Yes":"No")<<endl;
  return 0;
}

Measured memory_bytes: 256
n = int(input())
a = list(map(int,input().split()))

stock = 0
money = 1000

for i in range(n):
    if i == n-1:
        if stock:
            money += stock*a[i]
    elif stock:
        if a[i] > a[i+1]:
            money += stock*a[i]
            stock = 0
        else:
            pass
    else:
        if a[i] < a[i+1]:
            stock += money//a[i]
            money -= stock*a[i]
        else:
            pass

print(money)

Measured memory_bytes: 9132
#include <cstdio>
#include <iostream>
#include <algorithm>
#include <deque>
#include <vector>
#include <set>
#include <string>
#include <queue>
#include <map>
#include <cmath>

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

using namespace std;

int main(){
	int N;
	string S;
	int cnt = 0;
	int max = 0;
	cin >> N;
	cin >> S;

	for(int i = 0; i < N; i++){
		if(S[i] == 'I') cnt++;
		else cnt--;
		if(cnt > max) max = cnt;
	}
	cout << max << endl;
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() );
using namespace std;
using ll = long long;

// 素因数分解(first要素がfactで、second要素がその個数)
vector<pair<ll, ll>> prime_factorize(ll n) {
    vector<pair<ll, ll>> res;
    for (ll p = 2; p * p <= n; ++p) {
        if (n % p != 0) continue;
        int num = 0;
        while (n % p == 0) { ++num; n /= p; }
        res.push_back(make_pair(p, num));
    }
    if (n != 1) res.push_back(make_pair(n, 1));
    return res;
}


int main(){
    ll a, b;
    cin >> a >> b;
    auto af = prime_factorize(a);
    auto bf = prime_factorize(b);

    map<ll, ll> m;
    rep(i, af.size()) m[af[i].first] = af[i].second;
    vector<ll> fact;
    rep(i, bf.size()){
        if(m.find(bf[i].first) != m.end()){
            fact.push_back(min(m[bf[i].first], bf[i].second));
        }
    }

    int ans = fact.size() + 1;
    cout << ans << endl;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {

		Scanner scanner = new Scanner(System.in);
		int H = scanner.nextInt();
		int m[] = new int[H + 1];
		int N = scanner.nextInt();

		int A = scanner.nextInt();
		int B = scanner.nextInt();

		for (int i = 1; i <= H; i++)
			m[i] = ((i - 1) / A + 1) * B;

		for (int i = 2; i <= N; i++) {
			A = scanner.nextInt();
			B = scanner.nextInt();

			for (int j = 1; j <= H; j++)
				if (j <= A) {
					if (m[j] > B)
						m[j] = B;
				} else if (m[j] > m[j - A] + B)
					m[j] = m[j - A] + B;

		}
		scanner.close();

		System.out.println(m[H]);

	}

}


Measured memory_bytes: 25684
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {

		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int[] color = new int[9];
		int ans = 0;

		for(int i = 0; i < n; i++) {
			int a = sc.nextInt();
			color[Math.min(a/400, 8)]++;
		}

		for(int i = 0; i < 8; i++) {
			if(color[i] > 0) ans++;
		}
		int ans2 = ans + color[8];
		if(ans == 0 && color[8] > 0) ans = 1;
		System.out.printf("%d %d", ans, ans2);
		sc.close();
	}
}

Measured memory_bytes: 21460
#include <iostream>
#include <vector>
#include <string>
#include <cmath>
#include <algorithm>
#include <map>
#include <iomanip>
#include <stdlib.h>
#include <queue>

using namespace std;

const int nmax = 1e9 + 7;
typedef long long ll;

int main(){

  double N, M, D; cin >> N >> M >> D;

  double ans;
  if (D != 0){
    ans = 2 * (N - D) / (N * N) * (M - 1);
  }else{
    ans = (M - 1) / N;
  }
  cout << setprecision(32) << ans << endl;

  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define rep(i, n) for (ll i = 0; i < (ll)(n); ++i)
#define repk(i,k,n) for (ll i = k; i < (ll)(n); ++i)
#define INF 5000000000
#define MOD 1000000007
typedef long long  ll;

using namespace std;

int ans;

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

	int N,A,B;
	cin >> N >> A >> B;

	cout << min(N*A,B) << endl;

	return 0;
}


Measured memory_bytes: 256
pub fn read<T: std::str::FromStr>() -> T {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim().parse().ok().unwrap()
}

pub fn read_vec<T: std::str::FromStr>() -> Vec<T> {
    read::<String>()
        .split_whitespace()
        .map(|e| e.parse().ok().unwrap())
        .collect()
}

pub fn read_vec2<T: std::str::FromStr>(n: usize) -> Vec<Vec<T>> {
    (0..n).map(|_| read_vec()).collect()
}

pub fn read_col<T: std::str::FromStr>(n: usize) -> Vec<T> {
    (0..n).map(|_| read()).collect()
}

use std::collections::BTreeSet;

fn main() {
    let n: usize = read();
    let v: Vec<Vec<u32>> = read_vec2(n * 2);
    let mut pv: Vec<(u32, u32, bool)> = vec![];
    for i in 0..2 * n {
        pv.push((v[i][0], v[i][1], i < n));
    }
    pv.sort_by(|x, y| (x.1).partial_cmp(&y.1).unwrap());

    let mut red = BTreeSet::new();

    let mut ans = 0;

    for j in 0..2 * n {
        let x = pv[j].0;
        if pv[j].2 {
            red.insert(x);
        } else {
            let mut tmp: u32 = 10000;
            let it = red.clone();
            for r in it.iter().rev() {
                if *r < x {
                    tmp = *r;
                    break;
                }
            }
            if red.remove(&tmp) {
                ans += 1;
            }
        }
    }

    println!("{}", ans);
}


Measured memory_bytes: 4352
#include <bits/stdc++.h>
#define arep(a,i,n) for(int i=(a);i<(n);i++)
#define rep(i,n) for(int i=0;i<(n);i++)
#define cinf(x,n) for(int i=0;i<(n);i++)cin>>x[i];
#define coutf(x,n) for(int i=0;i<(n);i++)cout<<x[i]<<endl;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;

using namespace std;

int main(){
	ll  n;
	cin >> n;
	if(n%10==3)
		cout << "bon" << endl;
	else if(n%10==0||n%10==1||n%10==6||n%10==8)
		cout << "pon" << endl;
	else
		cout << "hon" << endl;
}

Measured memory_bytes: 3636
import itertools
D,G=map(int,input().split())
l=sorted([[(i+1)*100]+list(map(int,input().split())) for i in range(D)],key=lambda x:x[0]*x[1]+x[2])[::-1]
comb=[set(x) for i in range(D+1) for x in itertools.combinations(range(D),r=i)]
setD=set(range(D))
ans=1000
for c in comb:
	res=0
	cnt=0
	if len(setD-c)>0:min_rest=min(setD-c)
	else:min_rest=None
	for i in c:
		res+=l[i][0]*l[i][1]+l[i][2]
		cnt+=l[i][1]
	if res>=G:ans=min(ans,cnt)
	elif res<G and min_rest != None and (G-res-1)//l[min_rest][2]<l[min_rest][1]:
		cnt+=(G-res-1)//l[min_rest][0]+1
		ans=min(ans,cnt)
print(ans)




Measured memory_bytes: 3444
#include <bits/stdc++.h>
//#include <ext/pb_ds/assoc_container.hpp>

#define INF 1000000021
#define MOD 1000000007
#define pb push_back
#define sqr(a) (a)*(a)
#define M(a, b) make_pair(a,b)
#define T(a, b, c) make_pair(a, make_pair(b, c))
#define F first
#define S second
#define all(x) (x.begin(), x.end())
#define deb(x) cerr << #x << " = " << x << '\n'
#define N 222222

using namespace std;
//using namespace __gnu_pbds;

typedef long double ld;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
typedef vector<ll> vll;
//typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> indexed_set;

const ld pi = 2 * acos(0.0);
template<class T> bool umin(T& a, T b){if(a>b){a=b;return 1;}return 0;}
template<class T> bool umax(T& a, T b){if(a<b){a=b;return 1;}return 0;}
template<class T, class TT> bool pal(T a, TT n){int k=0;for(int i=0;i<=n/2;i++){if(a[i]!=a[n-i-1]){k=1;break;}}return k?0:1;}

//int month[] = {0,31,28,31,30,31,30,31,31,30,31,30,31};

int main()
{
	ll x;
	cin >> x;
	for(ll i = -1000; i <= 1000; i ++)
	{
		for(ll j = -1000; j <= 1000; j ++)
		{
			ll q = i*i*i*i*i;
			ll p = j*j*j*j*j;
			if(q - p == x)
			return cout << i << ' ' << j << '\n',0;
		}
	}





	





	getchar();
	getchar();
	return 0;
	//ios::sync_with_stdio(false);
	//cin.tie(0);
}

Measured memory_bytes: 3636
import math

N, K = map(int, input().split())

pprob = 0
for n in range(1, N+1):
    if K/n < 1:
        throw = 0
    else:
        throw = math.ceil(math.log2(K/n))
    pprob += ((1 / 2) ** throw) / N

print(pprob)

Measured memory_bytes: 3060
import Foundation

var x = Int(readLine()!) ?? 0
var money = [0,0]
 
money[0] = (x / 500) * 1000
x = x % 500 
money[1] = (x / 5) * 5
x = x % 5
 
let happinessScore =  money.reduce(0) { (num1: Int, num2: Int) -> Int in
  return num1 + num2
}

print(happinessScore)


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

#define int long long
const double PI = 3.14159265358979323846;
typedef vector<int> vint;
typedef pair<int, int> pint;
int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};

int N;
int A[110000], B[110000], C[110000];
vint G[110000];
unordered_map<int, int> cmap[110000];
int mincost = LLONG_MAX;
bool hashigher[110000];

int ans = 0;
int dfs(int from, int to) {
    int cur = 1;
    for (int i = 0; i < G[to].size(); i++) {
        if (G[to][i] == from)continue;
        cur += dfs(to, G[to][i]);
    }
    int deg = min(cur, N - cur);
    int cost = cmap[from][to];
    ans += deg * 2 * cost;
    if (deg * 2 == N)mincost = cost;
    if (cur < N - cur)hashigher[to] = true;
    else if (cur > N - cur) hashigher[from] = true;
    return cur;
}

signed main() {
    cin >> N;
    for (int i = 0; i < N - 1; i++) {
        cin >> A[i] >> B[i] >> C[i];
        cmap[A[i]][B[i]] = C[i];
        cmap[B[i]][A[i]] = C[i];
        G[A[i]].push_back(B[i]);
        G[B[i]].push_back(A[i]);
    }
    for (int i = 0; i < G[1].size(); i++)dfs(1, G[1][i]);
    if (mincost != LLONG_MAX) {
        cout << ans - mincost << endl;
        return 0;
    }
    for (int i = 1; i <= N; i++) {
        if (hashigher[i])continue;
        for (int j = 0; j < G[i].size(); j++) {
            mincost = min(mincost, cmap[i][G[i][j]]);
        }
    }
    cout << ans - mincost << endl;
}


Measured memory_bytes: 29440
#include<bits/stdc++.h>
using namespace std;
#define int long long int
#define ld long double
#define pb 	push_back
#define endl '\n'
#define all(x) (x).begin(),(x).end()
#define F first
#define S second
#define fuck() cout<<"--------"<<endl
#define see(x) cout<<#x<<" = "<<x<<endl
const int maxn=1e5+5;
int a[maxn];
int32_t main()
{
	ios_base::sync_with_stdio(0); cin.tie(0);cout.tie(0);
	int n,k,q,d=0;
	cin>>n>>k>>q;
	for(int i=1;i<=n;i++)
		a[i]=k;
	while(q--)
	{
		int x;
		cin>>x;
		a[x]++;
		d++;
	}
	for(int i=1;i<=n;i++)
		a[i]-=d;
	for(int i=1;i<=n;i++)
		if(a[i]<=0)cout<<"No\n";
		else cout<<"Yes\n";
}

Measured memory_bytes: 1408
#include<stdio.h>

int main (void)
{
  int N;
  scanf("%d",&N);
  int a[N];
  for(int i=0;i<N;i++)
  {
    scanf("%d",&a[i]);
  }
  int sum=0;
  for(int i=0;i<N;i++)
  {
    if(i%2==0&&a[i]%2==1)
    {
      sum++;
    }
  }
  printf("%d\n",sum);
  return 0;
}

Measured memory_bytes: 1700
#[allow(unused_imports)]
use std::cmp::*;
#[allow(unused_imports)]
use std::collections::*;
#[allow(unused_imports)]
use std::io::*;
#[allow(unused_imports)]
use std::iter;
#[allow(unused_imports)]
use std::mem::*;
#[allow(unused_imports)]
use std::str::*;
#[allow(unused_imports)]
use std::usize;

#[allow(unused_macros)]
macro_rules! read_cols {
    ($($t:ty),+) => {{
        let mut line = String::new();
        stdin().read_line(&mut line).unwrap();

        let mut it = line.trim()
            .split_whitespace();

        ($(
            it.next().unwrap().parse::<$t>().ok().unwrap()
        ),+)
    }}
}

#[allow(dead_code)]
fn read<T: FromStr>() -> T {
    let mut line = String::new();
    stdin().read_line(&mut line).unwrap();
    line.trim().to_string().parse().ok().unwrap()
}

#[allow(dead_code)]
fn read_vec<T: FromStr>() -> Vec<T> {
    let mut line = String::new();
    stdin().read_line(&mut line).unwrap();

    line.trim()
        .split_whitespace()
        .map(|s| s.parse().ok().unwrap())
        .collect()
}

fn main() {
    let n = read::<usize>();
    let a = read_vec::<i64>();

    assert_eq!(n, a.len());

    let es: Vec<_> = a.iter().map(|aa| aa % 2 == 0).collect();

    let num_even = es.iter().filter(|&&e| e).count();
    let num_odd = es.iter().filter(|&&e| !e).count();

    if num_odd % 2 > 0 {
        if num_even == 0 {
            println!("YES");
        } else {
            println!("NO");
        }
    } else {
        println!("YES");
    }
}


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

using namespace std;

#define PREFIX_COUNT 5
const char PREFIXES[PREFIX_COUNT] = { 'M', 'A', 'R', 'C', 'H' };

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

	uint64_t name_count[PREFIX_COUNT] = { 0 };

	for (int i = 0; i < n; i++) {
		string name;
		cin >> name;

		for (int j = 0; j < PREFIX_COUNT; j++) {
			if (name[0] == PREFIXES[j]) {
				name_count[j]++;
				break;
			}
		}
	}


	uint64_t result = 0;

	for (int i = 0; i < PREFIX_COUNT - 2; i++) {
		for (int j = i + 1; j < PREFIX_COUNT - 1; j++) {
			for (int k = j + 1; k < PREFIX_COUNT; k++) {
				result += name_count[i] * name_count[j] * name_count[k];
			}
		}
	}

	cout << result << endl;

    return 0;
}


Measured memory_bytes: 256
W,H,N=map(int,input().split())
A,B,C,D=[0],[W],[0],[H]

for i in range(N):
    x,y,a=map(int,input().split())
    if a==1:
        A.append(x)
    elif a==2:
        B.append(x)
    elif a==3:
        C.append(y)
    elif a==4:
        D.append(y)

W=min(B)-max(A)
H=min(D)-max(C)

if W<0 or H<0:
    ans=0
else:
    ans=H*W
print(ans)

Measured memory_bytes: 9068
import java.util.Scanner;

public class Main{

	static final Scanner	s	=new Scanner(System.in);

	public static void main(String args[]){
		input();
		solve();
	}

	private static void input(){
	}

	private static void solve(){
		long a=s.nextLong(),b=s.nextLong(),m=s.nextLong();
		System.out.println(b/m-a/m+((a%m==0)?1:0));
	}
}


Measured memory_bytes: 23764
from fractions import gcd
A,B,C,D = map(int, input().split())
X = B//C - (A-1)//C
Y = B//D - (A-1)//D
lcm = round(C*D//gcd(C,D))
Z = B//lcm - (A-1)//lcm
print(B-A+1-X-Y+Z)

Measured memory_bytes: 5048
N = gets.chomp.to_i
H = gets.chomp.split(" ").map(&:to_i)

max = 0
count = 0

for i in 0...(N - 1) do
  if H[i] >= H[i+1] then
    count += 1
  else
    max = [max, count].max
    count = 0
  end
end

max = [max, count].max

p max


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

using namespace std;

int main()
{
	int x1, y1, x2, y2;
	cin >> x1 >> y1 >> x2 >> y2;
	cout << x2 + y1 - y2 << " " << y2 + x2 - x1 << " " << x1 + y1 - y2 << " " << y1 + x2 - x1 << endl;

	return 0;
}


Measured memory_bytes: 256
// B

#include <bits/stdc++.h>
using ll = long long;
using namespace std;
ll mod=1e9+7;
#define pa(x,n) for(ll i=0;i<n;i++){cout<<(x[i])<<" \n"[i==n-1];};

int main(){
  ll A,B,K;
  cin>>A>>B>>K;
  if (A < K){
    cout << 0 <<" " <<  max(B - (K - A),0ll) << endl;
  }else{
    cout << A - K << " "<< B << endl;
  }
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
const int Maxn = 305;
int n, m, s, t, cnt, cur[Maxn], col[Maxn * Maxn], dis[Maxn], tmp[Maxn], head[Maxn], a[Maxn][Maxn], ans1[Maxn][Maxn], ans2[Maxn][Maxn];
vector <int> Ve[Maxn][Maxn];
struct edg
{
	int nxt, to, w;
	bool del;
}edge[2 * Maxn * Maxn];
void add(int x, int y, int w)
{
	edge[++cnt] = (edg){head[x], y, w};
	head[x] = cnt;
	edge[++cnt] = (edg){head[y], x, 0, true};
	head[y] = cnt;
}
queue <int> Qu;
bool bfs(void)
{
	memset(dis, 0, sizeof(dis));
	Qu.push(s);
	while (!Qu.empty())
	{
		int u = Qu.front();
		Qu.pop();
		for (int i = head[u]; i; i = edge[i].nxt)
		{
			int to = edge[i].to;
			if (edge[i].w && to != s && !dis[to])
				dis[to] = dis[u] + 1, Qu.push(to);
		}
	}
	return (bool)dis[t];
}
int dfs(int u, int mini)
{
	if (u == t || !mini) return mini;
	int w, used = 0;
	for (int &i = cur[u]; i; i = edge[i].nxt)
	{
		int to = edge[i].to;
		if (dis[to] == dis[u] + 1 && edge[i].w)
		{
			w = dfs(to, min(edge[i].w, mini - used));
			edge[i].w -= w, edge[((i - 1) ^ 1) + 1].w += w, used += w;
		}
	}
	return used;
}
void dinic(void)
{
	while (bfs())
	{
		memcpy(cur, head, sizeof(cur));
		dfs(s, 0x3f3f3f3f);
	}
}
int main()
{
	scanf("%d%d", &n, &m);
	for (int i = 1; i <= n * m; i++)
		col[i] = (i - 1) / m + 1;
	for (int i = 1; i <= n; i++)
		for (int j = 1; j <= m; j++)
		{
			scanf("%d", &a[i][j]);
			add(i, n + col[a[i][j]], 1);
			Ve[i][col[a[i][j]]].push_back(a[i][j]);
		}
	s = 2 * n + 1, t = 2 * n + 2;
	for (int i = 1; i <= m; i++)
	{
		for (int j = 1; j <= n; j++)
			add(s, j, 1), add(n + j, t, 1);
		dinic();
		for (int u = 1; u <= n; u++)
			for (int j = head[u]; j; j = edge[j].nxt)
			{
				int to = edge[j].to;
				if (!edge[j].w && !edge[j].del)
				{
					edge[j].del = true;
					edge[((j - 1) ^ 1) + 1].w = 0;
					ans1[u][i] = *Ve[u][to - n].rbegin();
					Ve[u][to - n].pop_back();
					break;
				}
			}
	}
	for (int i = 1; i <= m; i++)
	{
		for (int j = 1; j <= n; j++)
			tmp[j] = ans1[j][i];
		sort(tmp + 1, tmp + 1 + n);
		for (int j = 1; j <= n; j++)
			ans2[j][i] = tmp[j];
	}
	for (int i = 1; i <= n; i++)
	{
		for (int j = 1; j <= m; j++)
			printf("%d ", ans1[i][j]);
		puts("");
	}
	for (int i = 1; i <= n; i++)
	{
		for (int j = 1; j <= m; j++)
			printf("%d ", ans2[i][j]);
		puts("");
	}
	return 0;
}

Measured memory_bytes: 5760
#include <stdio.h>
#include <math.h>

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

	scanf("%d %d %d %d", &a, &b, &c, &d);

	
	if ((abs(a - b) <= d && abs(b - c) <= d) || abs(a-c)<=d ) {
		printf("Yes");
	}
	else {
		printf("No");
	}
	return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
template <class T, class U>
ostream &operator<<(ostream &os, const pair<T, U> &p) {
  os << "(" << p.first << "," << p.second << ")";
  return os;
}
#ifdef __LOCAL
#define debug(x) cerr << __LINE__ << ": " << #x << " = " << x << endl
#define debugArray(x, n)                           \
  cerr << __LINE__ << ": " << #x << " = {";        \
  for (long long hoge = 0; (hoge) < (n); ++(hoge)) \
    cerr << ((hoge) ? "," : "") << x[hoge];        \
  cerr << "}" << endl
#else
#define debug(x) (void(0))
#define debugArray(x, n) (void(0))
#endif

signed main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  long long N, K;
  cin >> N >> K;
  N -= N / K * K;
  cout << min(N, K - N) << endl;
  return 0;
}


Measured memory_bytes: 3572
#include <iostream>
#include <fstream>
#include <string>
#include <cmath>
#include <cstdio>
#include <algorithm>
#include <iomanip>
#include <vector>
#include <utility>
#include <numeric>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <unordered_map>
#include <limits.h>
#include <bitset>
#include <math.h>
#define int long long
using namespace std;
using P = pair<int, int>;
using ll = long long;
using prique = priority_queue<int>;
const int MOD = 998244353;
const int INF = LLONG_MAX/3;
const int MAX = 510000;

/*-----Library-----*/

struct UnionFind {
    vector<int> par; // 親ノード
    vector<int> rank; // ランク
    vector<int> sizeuf; //要素数
    UnionFind(int n = 1) {
        init(n);
    }

    void init(int n = 1) {
        par.resize(n); rank.resize(n); sizeuf.resize(n);
        for (int i = 0; i < n; ++i) {
            par[i] = i;
            rank[i] = 0;
            sizeuf[i]=1;
        }
    }

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

    bool issame(int x, int y) {
        return root(x) == root(y);
    }

    bool merge(int x, int y) {
        x = root(x); y = root(y);
        if (x == y) return false;
        if (rank[x] < rank[y]) swap(x, y);
        if (rank[x] == rank[y]) ++rank[x];
        par[y] = x;
        sizeuf[x]+=sizeuf[y];
        return true;
    }

    int size(int x){
        return sizeuf[root(x)];
    }
};

long long gcd(long long a,long long b){
    if(b==0)return a;
    return gcd(b,a%b);
}

long long lcm(long long i,long long j){
    return i*(j/gcd(i,j));
}

long long fac[MAX], finv[MAX], inv[MAX];
// テーブルを作る前処理
void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}

// 二項係数計算
long long COM(int n, int k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

/*-----Library-----*/
signed main(){
    int n;
    cin>>n;
    int p[114514];
    for(int i=0;i<n;i++)cin>>p[i];
    bool k[114514];
    for(int i=0;i<n;i++){
        if(p[i]==i+1)k[i]=true;
        else k[i]=false;
    }
    int cnt=0;
    int ans=0;
    for(int i=0;i<n;i++){
        if(k[i]==true){
            cnt++;
        }else{
            ans+=(cnt+1)/2;
            cnt=0;
        }
    }
    ans+=(cnt+1)/2;
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 1152
#include <iostream>
#include <stdio.h>
#include <vector>
#include <queue>
#include <stack>
#include <algorithm>
#include <set>
#include <map>
#include <deque>
#include <math.h>
#include <string.h>
#include <iomanip>
#include <locale>
using namespace std;
#define FORN(i,m,n) for(int i=m; i<(n); i++)
#define PRINTVEC(v) FORN(i,0,v.size()) cout<<v[i]<<" "; cout<<endl
#define PRINTMAT(m) FORN(j,0,m.size()) {PRINTVEC(m[j]);}
#define p_b(x) push_back(x)
#define m_p(a,b) make_pair(a,b)
typedef long long ll;

int n,q;
vector<vector<int> > edges;
vector<int> value, sum;

void DFS(int u, int ac){
  ac += sum[u];
  value[u] += ac;
  FORN(i,0,edges[u].size()) DFS(edges[u][i], ac);
}

int main(){
  ios_base::sync_with_stdio(false); cin.tie(NULL);
  cin>>n>>q;
  edges = vector<vector<int> > (n);
  value = sum = vector<int> (n);
  FORN(i,1,n){
    int a,b;
    cin>>a>>b;
    a--, b--;
    edges[min(a,b)].p_b(max(a,b));
  }
  FORN(i,0,q){
    int p,x;
    cin>>p>>x;
    p--;
    sum[p] += x;
  }
  DFS(0,0);
  PRINTVEC(value);
}

Measured memory_bytes: 21120
#include <iostream>
#include <vector>
#include <string>
#include <stack>
#include <queue>
#include <climits>
#include <algorithm>
#include <cmath>
using namespace std;

typedef long long LL;
typedef vector<int> VI;
typedef vector<LL> VLL;
typedef vector<string> VS;
typedef vector<bool> VB;
typedef vector<vector<int>> VVI;
typedef vector<vector<bool>> VVB;

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

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(a>b){
		a=b;
		return true;
	}
	return false;
}


int main(){
	int n,a,b;cin>>n>>a>>b;
	int c=n*a;
	cout<<min(c,b)<<endl;
	return 0;
}


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

int main() {
    string S;
    cin >> S;
    string ans = "Yes";
    if (S[2] != S[3]) ans = "No";
    if (S[4] != S[5]) ans = "No";

    cout << ans << endl;

    return 0;
}



Measured memory_bytes: 256
import java.util.*;
import java.io.*;
import java.math.*;
 
 
import static java.lang.Math.*;
import static java.util.Arrays.*;
import static java.util.Collections.*;
 
public class Main{
    static final long mod=1000000007;
    
    public  static void main(String[] args)   throws Exception, IOException{
        Reader sc = new Reader(System.in);
        PrintWriter out=new PrintWriter(System.out);
        // int n=sc.nextInt();
        // char c[][] = new char[h][w];
        // char c[]=sc.nextString().toCharArray();
        // for(int i=0; i<n; i++) {d[i]=sc.nextInt();}
        int n=sc.nextInt();
        int d[] = new int[n];
        int e[] = new int[n];
        for(int i=0; i<n; i++) {
            e[i] = d[i] = sc.nextInt();
        }

        sort(d);
        for(int i=0; i<n; i++) {
            if(e[i]<=d[n/2-1])out.println(d[n/2]);
            else out.println(d[n/2-1]);
        }

        // out.println();
        out.flush();
    }
    
    static void db(Object... os){
        System.err.println(Arrays.deepToString(os));
    }
     
    static boolean validpos(int x,int y,int r, int c){
        return x<r && 0<=x && y<c && 0<=y;
    }
    
    static boolean bit(long x,int k){
        // weather k-th bit (from right) be one or zero
        return  ( 0 < ( (x>>k) & 1 )  )  ? true:false;
    }    
}

class P implements Comparable<P>{
        int id, d;
        P(int  id, int d) {
            this.id=id;
            this.d=d;
        } 
          
        public int compareTo(P p){
            return d-p.d; //descend
        }
    }

class Reader
{ 
    private BufferedReader x;
    private StringTokenizer st;
    
    public Reader(InputStream in)
    {
        x = new BufferedReader(new InputStreamReader(in));
        st = null;
    }
    public String nextString() throws IOException
    {
        while( st==null || !st.hasMoreTokens() )
            st = new StringTokenizer(x.readLine());
        return st.nextToken();
    }
    public int nextInt() throws IOException
    {
        return Integer.parseInt(nextString());
    }
    public long nextLong() throws IOException
    {
        return Long.parseLong(nextString());
    }
    public double nextDouble() throws IOException
    {
        return Double.parseDouble(nextString());
    }
}

Measured memory_bytes: 55132
#include<iostream>
#include<string>
using namespace std;
int main() {
	string s;
	cin >> s;
	if ((s[0]==s[1] && s[2]==s[3] && s[0]!=s[2]) ||
		(s[0]==s[2] && s[1]==s[3] && s[0]!=s[1]) || (s[0]==s[3] && s[1]==s[2] && s[0]!=s[1]))  {
		cout << "Yes" << endl;
	}
	else {
		cout << "No" << endl;
	}
	return 0;
}


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

using namespace std;

#define SZ(x) (int)(x.size())

using ll = long long;
using ld = long double;
const ld eps = 1e-9;
const ll MOD = 1000000007;
const int INF = 1000000000;
const ll LINF = 1ll<<50;

template <typename T1, typename T2>
void chmax(T1 &a, const T2 &b) {
  if(a < b) a = b;
}

template <typename T1, typename T2>
void chmin(T1 &a, const T2 &b) {
  if(a > b) a = b;
}

template<typename T>
void printv(const vector<T>& s) {
  for(int i=0;i<(int)(s.size());++i) {
    cout << s[i];
    if(i == (int)(s.size())-1) cout << endl;
    else cout << " ";
  }
}

template<typename T1, typename T2>
ostream& operator<<(ostream &os, const pair<T1, T2> p) {
  os << p.first << ":" << p.second;
  return os;
}

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout << fixed << setprecision(10);

  int n, m, q; cin >> n >> m >> q;
  vector<string> s(n);
  for(int i=0;i<n;++i) {
    string tmp; cin >> tmp;
    s[i] = tmp;
  }

  vector<vector<int>> ver(n+1, vector<int>(m+1, 0));
  vector<vector<int>> tate(n+1, vector<int>(m+1, 0)), yoko(n+1, vector<int>(m+1, 0));
  for(int i=0;i<n;++i) {
    for(int j=0;j<m;++j) {
      ver[i+1][j+1] = s[i][j] == '1';
    }
  }
  for(int i=0;i<n;++i) {
    for(int j=0;j<m;++j) {
      ver[i+1][j+1] += ver[i+1][j] + ver[i][j+1] - ver[i][j];
    }
  }

  for(int i=0;i<n-1;++i) {
    for(int j=0;j<m;++j) {
      tate[i+1][j+1] = s[i][j] == '1' && s[i+1][j] == '1';
    }
  }
  for(int i=0;i<n-1;++i) {
    for(int j=0;j<m;++j) {
      tate[i+1][j+1] += tate[i+1][j] + tate[i][j+1] - tate[i][j];
    }
  }

  for(int i=0;i<n;++i) {
    for(int j=0;j<m-1;++j) {
      yoko[i+1][j+1] = s[i][j] == '1' && s[i][j+1] == '1';
    }
  }
  for(int i=0;i<n;++i) {
    for (int j = 0; j < m - 1; ++j) {
      yoko[i + 1][j + 1] += yoko[i + 1][j] + yoko[i][j + 1] - yoko[i][j];
    }
  }

  while(q--) {
    int x1, y1, x2, y2; cin >> x1 >> y1 >> x2 >> y2;

    int tmpv = ver[x2][y2] - ver[x2][y1-1] - ver[x1-1][y2] + ver[x1-1][y1-1];
    int tmptate = tate[x2-1][y2] - tate[x2-1][y1-1] - tate[x1-1][y2] + tate[x1-1][y1-1];
    int tmpyoko = yoko[x2][y2-1] - yoko[x2][y1-1] - yoko[x1-1][y2-1] + yoko[x1-1][y1-1];

    cout << tmpv - tmptate - tmpyoko << endl;
  }
}


Measured memory_bytes: 54400
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		long a[] = new long[n];

		long sum = 0;
		for (int i = 0; i < n; i++) {
			a[i] = sc.nextInt();
			sum += a[i];
		}

		long result = 0;
		for (int i = 0; i < n; i++) {
			sum -= a[i];
			result = (result + a[i] * (sum % 1000000007)) % 1000000007;
//			sum = sum % 1000000007;
		}

		System.out.println(result);

		sc.close();

	}

}

Measured memory_bytes: 61560
def main():
    n = int(input())
    p = [int(x) for x in input().split()]

    count = 0
    for i in range(1, n-1):
        if p[i-1] < p[i] < p[i+1] or p[i+1] < p[i] < p[i-1]:
            count += 1

    print(count)                


main()


Measured memory_bytes: 2940
#include <bits/stdc++.h>
#define SORT(x) sort((x).begin(),(x).end())
#define ALL(x) (x).begin(),(x).end()
#define rep(i, n) for(int i = 0; i < n; i++)
#define reps(i, m, n) for(int i = m; i < n; i++)
#define repr(i, m, n) for(int i = m; i >= n; i--)
#define db(x) cout<<#x<<"="<<x<<endl
template<class T>bool maxi(T &a,const T &b){if(a<b){ a=b; return 1;} return 0;}
template<class T>bool mini(T &a,const T &b){if(b<a){ a=b; return 1;} return 0;}
#define y0 y3487465 //y1 j0 j1
#define INF2 4000000000000000037
#define INF 1000000007
#define PI (acos(-1))
#define MOD 1000000007
#define EPS 1e(-9);
using namespace std;
typedef long long ll;

void Main(){

  // 最も近い寺社に行き、そこから行ってない近い方に行く 最も近い相方

  int A,B,Q; cin>>A>>B>>Q;

  vector<ll> s(A),t(B),x(Q);

  rep(i,A){
      cin>>s[i];
  }
  rep(i,B){
      cin>>t[i];
  }
  rep(i,Q){
      cin>>x[i];
  }

  s.emplace_back(-INF2);
  s.emplace_back(INF2);

  t.emplace_back(-INF2);
  t.emplace_back(INF2);


  SORT(s); SORT(t);


/*
  reps(i,1,A+1){
      ll sa=lower_bound(ALL(t),s[i])-t.begin();
  }
  reps(i,1,B+1){
      ll ta=lower_bound(ALL(s),t[i])-s.begin());
  }
*/

  rep(i,Q){
      ll ans=INF2; ll ta,sa;
      ta=lower_bound(ALL(t),x[i])-t.begin();
      sa=lower_bound(ALL(s),t[ta])-s.begin();

      mini(ans,abs(x[i]-t[ta])+abs(t[ta]-s[sa]));
      --sa;
      mini(ans,abs(x[i]-t[ta])+abs(t[ta]-s[sa]));

      --ta;

      sa=lower_bound(ALL(s),t[ta])-s.begin();
      mini(ans,abs(x[i]-t[ta])+abs(t[ta]-s[sa]));
      --sa;
      mini(ans,abs(x[i]-t[ta])+abs(t[ta]-s[sa]));

      sa=lower_bound(ALL(s),x[i])-s.begin();
      ta=lower_bound(ALL(t),s[sa])-t.begin();

      mini(ans,abs(x[i]-s[sa])+abs(t[ta]-s[sa]));
      --ta;
      mini(ans,abs(x[i]-s[sa])+abs(t[ta]-s[sa]));

      --sa;
      ta=lower_bound(ALL(t),s[sa])-t.begin();
      mini(ans,abs(x[i]-s[sa])+abs(t[ta]-s[sa]));
      --ta;
      mini(ans,abs(x[i]-s[sa])+abs(t[ta]-s[sa]));

      cout<< ans<<"\n";

  }

}

//-----------------------------------
int main(){
  cin.tie(nullptr);
  ios_base::sync_with_stdio(false);
  cout << fixed << setprecision(15);
  Main();
}
//-----------------------------------


Measured memory_bytes: 3680
using System;
 
namespace Sample
{
  class Sample
  {
    static void Main(string[] args)
    {
    string[] str=Console.ReadLine().Split(' ');
     int x=int.Parse(str[0]);
     int y=int.Parse(str[1]);
      int flg=0;
	int a=0;
      int b;
    while(a<x+1){
    b=x-a;
      if((2*a+4*b)==y)
      {flg=1;
       break;
      }
      a++;
    }
      if(flg==1){
        Console.WriteLine("Yes");
      }else{
        Console.WriteLine("No");
      }
     
    }
    
  }

}


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

int main(){
  int n,i=0,cus=0;
  cin>>n;
  while(i<n){
    int l,r;
    cin>>l>>r;
    cus+=r-l+1;
    i++;
  }
  cout<<cus<<endl;
}

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

double avg(int a[], int N) {
  double sum = 0;
  double avg;
  for (int i = 0; i < N; ++i) {
    sum += a[i];
  }
  avg = std::round(sum / N);
  return avg;
}

int main() {
  
  int N = 0;
  std::cin >> N;

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

  double target = avg(a, N);

  int calculation = 0;
  for (int j = 0; j < N; ++j) {
    calculation += std::pow(a[j] - target, 2); 
  }
  
  std::cout << calculation << std::endl;

}

Measured memory_bytes: 512
#include<stdio.h>
#include<algorithm>
#include<vector>
using namespace std;
int dp[110][310];
vector<int>w[110];
vector<int>p[110];
int main(){
	int a,b,c;
	while(~scanf("%d%d%d",&a,&b,&c)){
		for(int i=0;i<a;i++){
			w[i].clear();p[i].clear();
		}
		for(int i=0;i<a;i++){
			int d;scanf("%d",&d);
			for(int j=0;j<d;j++){
				int x,y;scanf("%d%d",&x,&y);
				w[i].push_back(x);
				p[i].push_back(y);
			}
		}
		for(int i=0;i<=b;i++){
			for(int j=0;j<=c;j++){
				dp[i][j]=-999999999;
			}
		}
		dp[0][0]=0;
		for(int i=0;i<b;i++){
			int t;scanf("%d",&t);
			for(int k=0;k<w[t].size();k++){
				for(int j=c;j>=0;j--){
					
					if(j+p[t][k]<=c){
						dp[i][j+p[t][k]]=max(dp[i][j+p[t][k]],dp[i][j]+w[t][k]);
					}
				}
			}
			for(int j=0;j<=c;j++)dp[i+1][j]=max(dp[i+1][j],dp[i][j]);
		}
		int ret=0;
		int val=0;
		for(int i=0;i<=c;i++){
			if(ret<dp[b][i]){
				val=i;ret=dp[b][i];
			}
		}
		printf("%d %d\n",ret,val);
	}
}

Measured memory_bytes: 1236
N = int(input())
h = list(map(int, input().split()))

DP = [0, abs(h[0]-h[1])]

for i in range(N-2):
  DP += [min((DP[-2] + abs(h[i]-h[i+2])),(DP[-1] + abs(h[i+2]-h[i+1])))]
  
print(DP[-1])

Measured memory_bytes: 13928
max = 10000
j = 3
l = [1] * (max + 1)
l[1] = 0
for i in range(4,max + 1, 2):
    l[i] = 0

for i in range(3,max + 1, 2):
    if ( l[i] == 0 ):
        continue
    j = i + i 
    while ( j <= max ):
        l[j] = 0
        j = j + i 

while True:
    try:
        n  = int(input())
    except EOFError:
        break
    cnt = 0
    for i in range(1,n+1):
        if (l[i] + l[n+1-i] == 2 ):
            cnt += 1
    print(cnt)


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

int main(){
  int N;
  cin>>N;
  int count=0;
  int ans=0;
  vector<int> hight(N);
  for(int i=0;i<N;i++){
  	cin>>hight.at(i);
    if(i!=0){
      if(hight.at(i)<=hight.at(i-1))
        count++;
      else{
      	ans=max(count,ans);
        count=0;
      }
    }
  }
  ans=max(ans,count);
  cout<<ans<<endl;
}

Measured memory_bytes: 640
s = input()
n = len(s)
red = [0]
blue = [0]
mod = 998244353
red = [-1]*(2*n)
blue = [-1]*(2*n)
cntr = 0
cntb = 0
for i in range(n):
  cntr = max(cntr,i)
  cntb = max(cntb,i)
  if s[i] == "0":
    red[cntr] = 1
    red[cntr+1] = 1
    cntr += 2
  if s[i] == "1":
    red[cntr] = 1
    cntr += 1
    blue[cntb] = 1
    cntb += 1
  if s[i] == "2":
    blue[cntb] = 1
    blue[cntb+1] = 1
    cntb += 2
for i in range(1,2*n):
  red[i] += red[i-1]
  blue[i] += blue[i-1]
dp = [[0]*(4*n+5) for i in range(2*n+1)]
dp[0][0] = 1
for i in range(1,2*n+1):
  for j in range(-blue[i-1],red[i-1]+1,1):
    dp[i][j] = (dp[i-1][j+1]+dp[i-1][j-1])%mod

print(dp[-1][red[-1]])

Measured memory_bytes: 285576
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define INF 1LL<<62
#define inf 1000000007

set<ll>a;
int main() {
	ll n;
	cin>>n;
	if(n==1){
		cout << 0;
		return 0;
	}
	ll m=sqrt(n);
	for(ll i=1;i<=m;i++){
		if(n%i!=0){
			continue;
		}
		ll now=n/i;
		ll ma=max(now,i);
		ma--;
		ll mi=min(now,i);
		if(n/ma==mi){
			a.insert(ma);
		}
	}
	ll ans=0;
	for(auto itr=a.begin();itr!=a.end();itr++){
		ans+=*itr;
	}
	cout <<ans;
	// your code goes here
	return 0;
}

Measured memory_bytes: 384
#include <queue>
#include <map>
#include <cstdio>
using namespace std;
int main(){
	int n,m;
	scanf("%d%d",&n,&m);
	vector<int>start(n),end1(n),end2(n);
	for(int i=0;i<n;i++)scanf("%d",&start[i]);
	{
		vector<int>p(m);
		for(int i=0;i<m;i++)scanf("%d",&p[i]);
		for(int i=0,c=0,x=0;i<m;i++,x^=1)for(int j=0;j<p[i];j++,c++)end1[c]=x;
		for(int i=0,c=0,x=1;i<m;i++,x^=1)for(int j=0;j<p[i];j++,c++)end2[c]=x;
	}
	map<vector<int>,int>depth;
	queue<vector<int> >q;
	depth[start]=1,depth[end1]=depth[end2]=-1;
	q.push(start),q.push(end1),q.push(end2);
	for(;!q.empty();){
		vector<int>cur=q.front();q.pop();
		int d=depth[cur];
		for(int i=0;i<n-1;i++)if(cur[i]!=cur[i+1]){
			swap(cur[i],cur[i+1]);
			map<vector<int>,int>::iterator it=depth.find(cur);
			if(it==depth.end()){
				depth[cur]=d+(d>0?1:-1);
				q.push(cur);
			}else if(it->second*d<0){
				d-=it->second;
				if(d<0)d=-d;
				printf("%d\n",d-1);
				return 0;
			}
			swap(cur[i],cur[i+1]);
		}
	}
	puts("0");
}

Measured memory_bytes: 2652
#include <bits/stdc++.h>
using namespace std;
typedef pair<int,int> P;
typedef long long ll;
typedef long double ld;
const int inf=1e9+7;
const ll longinf=1LL<<60;
#define REP(i,m,n) for(int i=(int)(m) ; i < (int) (n) ; ++i )
#define rep(i,n) REP(i,0,n)
#define F first
#define S second

const int mx=101010;
const ll mod=1e9+7;

vector<vector<ll>> dp(mx, vector<ll>(3,-longinf));
vector<vector<ll>> act(mx, vector<ll>(3,0));
int n;

ll rec(int d,int a){
  if(dp[d][a]!=-longinf){ return dp[d][a];}
  if(d==1){return dp[d][a]=act[d-1][a];}
  int b,c; if(a==0){b=1,c=2;} if(a==1){b=0,c=2;} if(a==2){b=0,c=1;}
  dp[d][a] = act[d-1][a]+max(rec(d-1,b),rec(d-1,c));
  return dp[d][a];
}


int main(){
  cin >> n;
  rep(i,n){ cin>>act[i][0]>>act[i][1]>>act[i][2]; }
  ll ans=max(max(rec(n,0),rec(n,1)), rec(n,2));
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 19072
import java.util.Scanner;
class Main {
  public static void main(String[] args){
    Scanner scanner = new Scanner(System.in);
   int n;
    n = scanner.nextInt();
    if (n%10 == 3)
      System.out.println("bon");
    else if ((n%10==0)||(n%10==1)||(n%10==6)||(n%10==8))
      System.out.println("pon");
    else 
      System.out.println("hon");
    
  }         
}


Measured memory_bytes: 35708
loop {
    n, m, p = gets.split.map &:to_i
    break if n == 0
    a = (1..n).map {|i| gets.to_i}
    p a[m-1] == 0 ? 0 : (a.inject(:+) * (100.0 - p) / a[m-1]).to_i
}

Measured memory_bytes: 6116
using System;
using System.IO;

class Program
{
    static void Main(string[] args) {
        var writer = new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false };
        Console.SetOut(writer);
        Console.WriteLine(Solve());
        Console.Out.Flush();
    }

    static object Solve() {
        Console.ReadLine();
        var A = Array.ConvertAll(Console.ReadLine().Split(), int.Parse);
        var logicalSum = 0;
        foreach (var ai in A) {
            if ((ai & 1) == 1) {
                logicalSum = 0;
                break;
            }
            logicalSum |= ai;
        }
        var result = 0;
        if (logicalSum == 0) return result;
        while ((logicalSum & 1) == 0) {
            logicalSum >>= 1;
            result++;
        }
        return result;
    }
}

Measured memory_bytes: 27700
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)n;i++)
#define rep1(i,n) for(int i=1;i<=(int)n;i++)
#define rep2(i,j,n) for(int j=i;j<n;j++)
#define rep3(i,j,n) for(int j=i;j<=n;j++)
#define rrep(i,n) for(int i=n-1;i>=0;i--)
#define sp(n) cout << fixed << setprecision(n)
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
typedef long long ll;
using namespace std;
int main(void){
    ll n,k;cin>>n>>k;
    ll res=k;
    rep(i,n){
        if(i==0)continue;
        res*=(k-1);
    }
    cout<<res<<endl;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		double x1 = sc.nextDouble();
		double y1 = sc.nextDouble();
		double x2 = sc.nextDouble();
		double y2 = sc.nextDouble();
		double P = 0;
		
		P = (x2-x1)*(x2-x1)+(y2-y1)*(y2-y1);
		Math.sqrt(P);
		
		System.out.printf("%.8f\n",Math.sqrt(P));

	}
}


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

#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define endl "\n"
#define PI 3.14159265358979
#define MOD 1000000007 // = 10^9 + 7

using namespace std;
using ll = long long;

void solve()
{
	int n;
	cin >> n;

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

	ll ans = 0;
	for(int i = 0; i < 60; ++i)
	{
		ll d0 = 0, d1 = 0;
		for(int j = 0; j < n; ++j)
		{
			// i 桁目が 1 か 0 か
			if((a[j] >> i) & 1) ++d1;
			else ++d0;
		}

		// i 桁目が 1 の個数
		ll n = d0 * d1 % MOD;

		// 2^i * d0 * d1
		ll tmp = ((1LL << i) % MOD) * n % MOD;

		ans = (ans + tmp) % MOD;
	}
	cout << ans << endl;	
}

int main()
{
	fastio;
	solve();

	return 0;
}

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

const int MAX = 1000001; 
struct Query 
{ 
	int l, r, idx; 
}; 

bool cmp(Query x, Query y) 
{ 
	return x.r < y.r; 
} 

// updating the bit array 
void update(int idx, int val, int bit[], int n) 
{ 
	for (; idx <= n; idx += idx&-idx) 
		bit[idx] += val; 
} 

// querying the bit array 
int query(int idx, int bit[], int n) 
{ 
	int sum = 0; 
	for (; idx>0; idx-=idx&-idx) 
		sum += bit[idx]; 
	return sum; 
} 

void answeringQueries(int arr[], int n, Query queries[], int q) 
{ 
	// initialising bit array 
	int bit[n+1]; 
	memset(bit, 0, sizeof(bit)); 

	// holds the rightmost index of any number 
	// as numbers of a[i] are less than or equal to 10^6 
	int last_visit[MAX]; 
	memset(last_visit, -1, sizeof(last_visit)); 

	// answer for each query 
	int ans[q]; 
	int query_counter = 0; 
	for (int i=0; i<n; i++) 
	{ 
		// If last visit is not -1 update -1 at the 
		// idx equal to last_visit[arr[i]] 
		if (last_visit[arr[i]] !=-1) 
			update (last_visit[arr[i]] + 1, -1, bit, n); 

		// Setting last_visit[arr[i]] as i and updating 
		// the bit array accordingly 
		last_visit[arr[i]] = i; 
		update(i + 1, 1, bit, n); 

		// If i is equal to r of any query store answer 
		// for that query in ans[] 
		while (query_counter < q && queries[query_counter].r == i) 
		{ 
			ans[queries[query_counter].idx] = 
					query(queries[query_counter].r + 1, bit, n)- 
					query(queries[query_counter].l, bit, n); 
			query_counter++; 
		} 
	} 

	// print answer for each query 
	for (int i=0; i<q; i++) 
		cout << ans[i] << endl; 
} 

// driver code 
int main()
{ 
	int n,q; cin>>n>>q;
	int a[n]; for(auto &x:a)cin>>x;
	Query queries[q]; 
	for(int i=0;i<q;i++){
		cin>>queries[i].l>>queries[i].r;
		--queries[i].l; --queries[i].r;
		queries[i].idx = i;
	}
	sort(queries, queries+q, cmp); 
	answeringQueries(a, n, queries, q); 
	return 0; 
} 


Measured memory_bytes: 19304
using System;
using System.Collections.Generic;
using System.Linq;
class Scanner
{
    string[] s;
    int i;

    char[] cs = new char[] { ' ' };

    public Scanner() {
        s = new string[0];
        i = 0;
    }

    public string next() {
        if (i < s.Length) return s[i++];
        string st = Console.ReadLine();
        while (st == "") st = Console.ReadLine();
        s = st.Split(cs, StringSplitOptions.RemoveEmptyEntries);
        if (s.Length == 0) return next();
        i = 0;
        return s[i++];
    }

    public int Int() {
        return int.Parse(next());
    }
    public int[] ArrayInt(int N, int add = 0) {
        int[] Array = new int[N];
        for (int i = 0; i < N; i++) {
            Array[i] = Int() + add;
        }
        return Array;
    }

    public long Long() {
        return long.Parse(next());
    }

    public long[] ArrayLong(int N, long add = 0) {
        long[] Array = new long[N];
        for (int i = 0; i < N; i++) {
            Array[i] = Long() + add;
        }
        return Array;
    }
}
class Program {
    static Scanner cin = new Scanner();
    static void Main() {
        long N = cin.Long();
        if (N == 0) Console.WriteLine(0);
        else {
            string ans = "";
            while (N != 0) {
                if (N % 2 == 0) {
                    ans = "0" + ans;
                    N /= -2;
                }
                else {
                    ans = "1" + ans;
                    N = (N - 1) / (-2);
                }
            }
            Console.WriteLine(ans);
        }
        Console.ReadLine();
    }
}

Measured memory_bytes: 11092
import Control.Monad.Trans.State.Lazy( StateT, get, modify, evalStateT)
main = do
    x <- getLine
    let process [] = return []
	process [c] = return [c]
	process (c1:rem@(c2:cs)) = do
	    n <- get
	    if n==0 then return $ c1:rem
	    else if [c1,c2] == "ST"
		    then modify pred >> process cs
		    else do
			next <- process rem
			case next of
			    []	    -> return [c1]
			    (cc:ccs) -> if [c1,cc] == "ST"
				then modify pred >> return ccs
				else return $ c1:next
    print . length =<< evalStateT (process x) 100000

Measured memory_bytes: 14588
#include <cstdio>
#include <iostream>
#include <cstdlib>
#include <algorithm>
using namespace std;

int a, b, c;

void init() {
	scanf("%d%d%d", &a, &b, &c);
}

void solve() {
	printf("%d", max(0, c-(a-b)));
}

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


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

#define LL long long

bool chk(int x){
	if(x>0 && x<=12){
		return true;
	}
	return false;
}

int main(){
	

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

	string s;cin>>s;

	int x = (s[0]-'0')*10 + (s[1]-'0');
	int y = (s[2]-'0')*10 + (s[3]-'0');
	

	if(chk(x) && chk(y)){
		cout<<"AMBIGUOUS"<<endl;
	}else if(chk(x) && y>=0){
		cout<<"MMYY"<<endl;
	}else if(x>=0 && chk(y)){
		cout<<"YYMM"<<endl;
	}else{
		cout<<"NA"<<endl;
	}
}

Measured memory_bytes: 256