akhauriyash/Code-Regression huggingface dataset:
// -*- coding:utf-8-unix -*-
use std::collections::VecDeque;
use std::collections::LinkedList;
use std::collections::HashMap;
use std::collections::HashSet;
use std::collections::BTreeMap;
use std::collections::BTreeSet;
use std::collections::BinaryHeap;
use std::cmp;

const INF: i64 = 1223372036854775807;

macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

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

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

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

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

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

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

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



fn main() {
    input!{
     n: usize,
     v: [i64; n],
    }
    let mut vec = v;
    vec.sort();
    vec.reverse();
    let mut a:i64 = 0;
    let mut b:i64 = 0;
    for i in 0..n {
        if(i%2 == 0)
        {
            a = a + vec[i];
        }
        else {
            b = b + vec[i];
        }
    }
    println!("{}",a - b);
    
    



}


Measured memory_bytes: 2116
#include<bits/stdc++.h>
using namespace std;
#define pb push_back
#define forn(i,n) for(int i=0;i<n;i++)
#define fre(i,a,b) for(int i = a; i < b; i++)
#define sf(n) scanf("%lld", &n)
#define sff(a,b) scanf("%lld %lld", &a, &b)
#define sfff(a,b,c) scanf("%d %d %d", &a, &b, &c)
#define pfn(n) printf("%d\n", n)
#define pfs(n) printf("%d ", n)
#define ff first
#define ss second
#define mem(a,b) memset(a,b,sizeof(a))
#define ll long long int
#define f find
#define ub upper_bound
#define lb lower_bound
#define ld long double
#define in insert
#define bs binary_search  
#define le length()
const ll max_i=1e8;
#define np(s) next_permutation(s.begin(),s.end())
//it gives the lexicographically next string

int main()
{
     int n;
    cin>>n;
    vector<int> arr[n+1];
        for(int i=2;i<=n;i++)
        {
            int x;
            cin>>x;
            arr[x].pb(i);
            arr[i].pb(x);
        }
    for(int i=1;i<=n;i++)
    {
      if(i==1) cout<<arr[i].size()<<endl;
      else cout<<arr[i].size()-1<<endl;
    }
    return 0;
}


Measured memory_bytes: 15196
using System;
using System.Linq;
using System.Collections;
using System.Collections.Generic;
using System.Text;


class Program
{
    static void Main(string[] args)
    {
        // 入力
        //var s = Console.ReadLine();
        var n = long.Parse(Console.ReadLine());
        long[] a = Console.ReadLine().Split().Select(long.Parse).ToArray();

        long[] ans = new long[n];
        long tmp = 0;
        var ok = true;
        for (long i = 0; i < n; i++)
        {
            if (ok)
            {
                tmp = 0 ^ a[i];
                ok = false;
            }
            else
            {
                tmp = tmp ^ a[i];
            }
        }

        for (long i = 0; i < n; i++)
        {
            long tmp2 = tmp;
            ans[i] = tmp2 ^ a[i];
        }

        foreach (var item in ans)
        {
            Console.Write(item + " ");
        }

    }
}

Measured memory_bytes: 65356
package main

import (
	"fmt"
)

func main() {
	var s, t string
	fmt.Scan(&s)
	fmt.Scan(&t)
	ans := 0
	for i := 0; i < 3; i++ {
		if s[i] == t[i] {
			ans++
		}
	}
	fmt.Println(ans)
}


Measured memory_bytes: 512
#include <stdio.h>

int main (int argc,char **argv)
{
	int x,a,b;
	int s,t;

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

	s = x - a;
	t = x - b;

	s = s * s;
	t = t * t;
	
	if  (s < t)
	{
		printf("A\n");
	}

	else 
	{
		printf("B\n");
	}
	return 0;
}

Measured memory_bytes: 128
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
using namespace std;
#define int long long
signed main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	int n, m;
	cin >> n >> m;
	vector<int> in(m);
	for (int i = 0; i < m; i++) {
		cin >> in[i];
	}
	sort(in.begin(), in.end());
	vector<int> dif(m - 1);
	for (int i = 0; i + 1< m; i++) {
		dif[i] = in[i + 1] - in[i];
		cerr << dif[i] << endl;
	}
	sort(dif.begin(), dif.end());
	long long ans = 0;
	for (int i = 0; i  + (n - 1) < m - 1 ; i++) {
		ans += dif[i];
	}
	cout << ans << endl;
	return 0;	
}

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



int main(){
    ll n, left, right, minn, maxx;
    cin >> n >> left >> right >> minn >> maxx;

    ll v = left;
    ll plus = 0;
    ll minus = 0;
    rep(i, n-1){
        if(v < right){
            v += minn;
            plus++;
        }
        else{
            v -= minn;
            minus++;
        }
    }


    ll diff = maxx-minn;

    if(right == v)  cout << "YES" << endl;
    else if(0 < right-v){
        if(right-v <= plus*diff)    cout << "YES" << endl;
        else                        cout << "NO" << endl;
    }
    else{
        if(v-right <= minus*diff)   cout << "YES" << endl;
        else                        cout << "NO" << endl;
    }

 
    return 0;
}

Measured memory_bytes: 256
a,b,k=map(int,input().split())

ans=[]
for i in range(k):
  if a+i<=b and a+i not in ans:
    ans.append(a+i)
for i in range(k):
  if b-i>=a and b-i not in ans:
    ans.append(b-i)
ans.sort()
print(*ans,sep='\n')

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

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

public class Main{

	Scanner sc;

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

	void run(){
		sc=new Scanner(System.in);
		int n=sc.nextInt();
		int ans=100000;
		for(int i=0; i<n; i++){
			if((ans*105/100)%1000!=0)
				ans=(ans*105/100/1000+1)*1000;
			else
				ans=ans*105/100;
		}
		println(""+ans);
		sc.close();
	}

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

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

	public static void main(String[] args){
		new Main().run();
	}
}

Measured memory_bytes: 11000
#include<bits/stdc++.h>
#define ld long double
using namespace std;
const int mod=1e9+7,N=3007;

ld ans[N][N];
int main()
{

    int n;
    cin>>n;
    for(int i=0; i<=n; ++i)
        for(int j=0; j<=n; ++j)
            ans[i][j]=0;
    ld prob[n+1];
    for(int i=1; i<=n; ++i)
        cin>>prob[i];
    ans[1][0]=(1-prob[1]);
    ans[1][1]=prob[1];

    for(int i=2; i<=n; ++i)
    {
        for(int j=0; j<= i; ++j)
        {
            ans[i][j]=ans[i-1][j]*(1-prob[i]);
            if(j)
                ans[i][j]+=ans[i-1][j-1]*prob[i];
        }
    }
    ld sum=0;
    for(int i=((n+1)/2); i<=n; ++i)
        sum+=ans[n][i];
    cout<<fixed<<setprecision(12)<<sum;
    return 0;
}


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

// #define multitest 1
#ifdef WIN32
#define db(...) ZZ(#__VA_ARGS__, __VA_ARGS__);
#define pc(...) PC(#__VA_ARGS__, __VA_ARGS__);
template <typename T, typename U>
ostream &operator<<(ostream &out, const pair<T, U> &p)
{
	out << '[' << p.first << ", " << p.second << ']';
	return out;
}
template <typename Arg>
void PC(const char *name, Arg &&arg)
{
	while (*name == ',' || *name == ' ')
		name++;
	std::cerr << name << " { ";
	for (const auto &v : arg)
		cerr << v << ' ';
	cerr << " }\n";
}
template <typename Arg1, typename... Args>
void PC(const char *names, Arg1 &&arg1, Args &&... args)
{
	while (*names == ',' || *names == ' ')
		names++;
	const char *comma = strchr(names, ',');
	std::cerr.write(names, comma - names) << " { ";
	for (const auto &v : arg1)
		cerr << v << ' ';
	cerr << " }\n";
	PC(comma, args...);
}
template <typename Arg1>
void ZZ(const char *name, Arg1 &&arg1)
{
	std::cerr << name << " = " << arg1 << endl;
}
template <typename Arg1, typename... Args>
void ZZ(const char *names, Arg1 &&arg1, Args &&... args)
{
	const char *comma = strchr(names + 1, ',');
	std::cerr.write(names, comma - names) << " = " << arg1;
	ZZ(comma, args...);
}
#else
#define db(...)
#define pc(...)
#endif

using ll = long long;
#define f first
#define s second
#define pb push_back
auto TimeStart = chrono::steady_clock::now();

const int nax = 2e5 + 10, mod = 1000000007;

void solve(int caseNo)
{
	ll a, b, c;
	cin >> a >> b >> c;
	ll ret = LLONG_MAX, cnt = 0;
	if (a & 1)
	{
		cnt++;
		ret = min(ret, b * c);
	}
	if (b & 1)
	{
		cnt++;
		ret = min(ret, a * c);
	}
	if (c & 1)
	{
		cnt++;
		ret = min(ret, b * a);
	}
	if (cnt != 3)
		ret = 0;
	cout << ret << '\n';
}

int main()
{
#ifndef WIN32
	ios_base::sync_with_stdio(0);
	cin.tie(0);
#endif
	int t = 1;
#ifdef multitest
	cin >> t;
#endif
	for (int i = 0; i < t; ++i)
		solve(i);
#ifdef TIME
	cerr << "\n\nTime elapsed: " << chrono::duration<double>(chrono::steady_clock::now() - TimeStart).count() << " seconds.\n";
#endif
	return 0;
}

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

int main() {
  int n;
  cin >> n;
  vector<int> vec(n);
  for(int i=0; i<vec.size(); i++){
    cin >> vec.at(i);
  }
  sort(vec.begin(),vec.end());
  reverse(vec.begin(),vec.end());
  int asum = 0;
  int bsum = 0;
  for(int i=0; i<vec.size(); i+=2){
    asum += vec.at(i);
  }
  for(int i=1; i<vec.size(); i+=2){
    bsum += vec.at(i);
  }
  cout << asum-bsum;
}


Measured memory_bytes: 256
def main():
  N = int(input())
  A_lst = list(map(int, input().split()))
  
  sum = 0
  for i in A_lst:
    sum += i
    sum = sum % (10**9 + 7)
  
  sum2 = 0
  for j in A_lst:
    sum = ((sum-j) % (10**9 + 7))
    sum2 += j * sum
    sum2 = sum2 % (10**9 + 7)

  print(sum2)
  
main()

Measured memory_bytes: 94288
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define repr(i, n) for (int i = (n); i >= 0; --i)
#define FOR(i, m, n) for (int i = (m); i < (n); ++i)
#define FORR(i, m, n) for (int i = (m); i >= (n); --i)
using namespace std;
typedef long long ll;
const ll mod = 1000000007;
const ll mod2 = 998244353;

int main() {
  int n, m, c;
  cin >> n >> m >> c;
  c *= -1;
  vector<int> b(m);
  rep(i, m) cin >> b[i];
  vector<vector<int>> a(n, vector<int>(m));
  rep(i, n) {
    rep(j, m) {
      cin >> a[i][j];
    }
  }
  int ans = 0;
  rep(i, n) {
    int score = 0;
    rep(j, m) {
      score += a[i][j] * b[j];
    }
    if (score > c) ans++;
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
#include <cstdlib>
#include <cmath>
#include <queue>
#include <vector>

using namespace std;


int main(){
   int a,b;
   cin>>a>>b;
   if(a<=b)cout<<a<<endl;
   else cout<<a-1<<endl;
   
}

Measured memory_bytes: 256
use std::io::Read;

fn main() {
    let mut buf = String::new();
    std::io::stdin().read_to_string(&mut buf).unwrap();

    let answer = solve(&buf);

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

fn solve(input: &str) -> String {
    let mut iterator = input.split_whitespace();

    let n: usize = iterator.next().unwrap().parse().unwrap();
    let k: usize = iterator.next().unwrap().parse().unwrap();
    let a: Vec<usize> = (0..n).map(|_| iterator.next().unwrap().parse().unwrap()).collect();

    if k > *a.iter().max().unwrap() {
        return "IMPOSSIBLE".to_string();
    }

    let mut g = a[0];
    for i in 1..n {
        g = gcd(g, a[i]);
    }

    if k % g == 0 {
        "POSSIBLE".to_string()
    } else {
        "IMPOSSIBLE".to_string()
    }
}

fn gcd(mut x: usize, mut y: usize) -> usize {
    while y > 0 {
        let r = x % y;
        x = y;
        y = r;
    }
    return x;
}


Measured memory_bytes: 3608
#include <bits/stdc++.h>
using namespace std;
#define ss second
#define ff first
#define all(a) a.begin(), a.end()
#define All(a) a.rbegin(), a.rend()
#define ios ios_base::sync_with_stdio(0), cin.tie(0), cout.precision(10), cout << fixed
int main()
{
   ios;
   int a, b;
   cin >> a >> b;
   double x = ((a + b) / 2.0);
   cout << (x - ((a + b) / 2) >= 0.5 ? (int)ceil(x) : (int)x) << '\n';
   return 0;
}

Measured memory_bytes: 3580
#include<cstdio>
#include<cstdlib>
using namespace std;
int n,x,a[10005];
long long pre[100000],tot=0;
bool bo[100005];
int main()
{
//  freopen("1.txt","r",stdin);
    scanf("%d",&n);
    for(int i=n;i>=0;i--)
        scanf("%d",&a[i]);
    //return 0;

    for(int i=2;i<=10000;i++)
    if(!bo[i])
    {
        pre[++tot]=i;
        for(int j=2*i;j<=10000;j+=i)
        {
            bo[j]=true;
        }
    }

    x=abs(a[n]);
    for(int i=2;i<=100000;i++)
    {
        if(x%i==0&&i>10000)
            pre[++tot]=i;
        while(x%i==0&&x!=0)
            x/=i;
    }
    if(x!=1)
        pre[++tot]=x;

//  return 0;

    for(int i=1;i<=tot;i++)
    {
        for(int j=1;j<=20;j++)
        {
            int k=rand()%pre[i];
            long long c=0;
            for(int l=n;l>=0;l--)
            {
                c=(c*k+a[l])%pre[i];
            } 
            if(c!=0)
                break;
            if(j==20)
                printf("%d\n",pre[i]);
        }
    }
}


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

using namespace std;

typedef long long ll;

const ll M = 1e9 + 7;
const int N = 5010;

ll dp[N][N];

int main() {
    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    int k;
    string s;
    cin >> k >> s;
    int n = s.length();
    dp[0][0] = 1;
    for (int i = 0; i < k; ++i) {
        for (int j = 0; j <= k + 1; ++j) {
            if (j) {
                dp[i + 1][j] = (dp[i][j - 1] + 2 * dp[i][j + 1]) % M;
            } else {
                dp[i + 1][j] = (dp[i][j] + 2 * dp[i][j + 1]) % M;
            }
        }
    }
    cout << dp[k][n];
    return 0;
}

Measured memory_bytes: 195968
#include <iostream>
#include <vector>
#include <assert.h>
#include <cmath>
#include <algorithm>

//int32_t gcd(int32_t a, int32_t b){
//    int32_t big = std::max(a,b);
//    int32_t small = std::min(a,b);
//    if(small == 0) return big;
//    int32_t res = small;
//    int32_t mod = big % small;
//    while(mod != 0){
//        big = small;
//        res = mod;
//        mod = small % mod;
//    }
//    return res;
//}

int32_t gcd(int32_t a, int32_t b) { return b ? gcd(b, a%b) : a;}

int main(){
    int32_t N;
    std::cin >> N;
    std::vector<int32_t> A(N);
    for(auto& i : A){
        std::cin >> i;
    }
    
    std::vector<int32_t> left(N+1,0);
    std::vector<int32_t> right(N+1,0);
    for(int32_t i = 0; i < N; i++){
        left[i+1] = gcd(left[i],A[i]);
        right[i+1] = gcd(right[i],A[N - i -1]);
        //std::cout << "i,left,right" << i << "," << left[i+1] << "," << right[i+1] << std::endl;
    }

    int32_t res = 0;
    for(int32_t j = 0; j < N; j++){
        res = std::max(res, gcd(left[j], right[N-j-1]));
    }
    std::cout << res << std::endl;


    return 0;
}


Measured memory_bytes: 1536
program prob5
    implicit none
    integer :: N
    integer(8), allocatable :: x(:), y(:)
    integer(8) :: m1, m2, i

    read(*,*) N
    allocate(x(N))
    
    read(*,*) x
    y = x

    call msort(x)

    m1 = x(N/2)
    m2 = x(N/2 + 1)

    do i = 1, N
        if(y(i) >= m2) then
            write(*,*) m1
        else
            write(*,*) m2
        end if
    end do


    deallocate(x)

    stop
contains


  !
  ! swap two arguments
  !
subroutine swap(a, b)
    implicit none
    integer(8), intent(inout) :: a, b

    integer(8) :: c

    c = a
    a = b
    b = c

  end subroutine swap

  !
  ! merge sort
  !
  recursive subroutine msort(x)
    implicit none
    integer(8), intent(inout) :: x(:)

    integer(8) :: n, mid, i, j, k
    integer(8), allocatable :: tmp(:)
    
    n = size(x)
    
    if(n == 1) then
      return
    end if

    !
    ! 前半と後半に分けてソート
    ! 1~midとmid+1~nをそれぞれソート済みにする
    !
    mid = n / 2
    call msort(x(:mid))
    call msort(x(mid+1:))

    !
    ! tmpという配列にxを一時的に保管
    ! マージソートは外部ソート
    !
    allocate(tmp(n))
    tmp = x

    ! tmpの後半部分を左右反転
    do k = n, mid+1, -1
      tmp(k) = x(mid + n - k + 1)
    end do

    ! iは前半のリストのうちまだ見ていないものの最小値
    ! jは後半のリストのうちまだ見ていないものの最小値
    ! kは見た回数の合計
    i = 1
    j = n

    do k = 1, n
      !
      ! 一番左と一番右のうち小さい方をxに入れていく
      ! ここが等号つき不等号なので、安定ソートとなる
      !
      if(tmp(i) <= tmp(j)) then
        x(k) = tmp(i)
        i = i + 1
      else
        x(k) = tmp(j)
        j = j - 1
      end if
    end do
    
    deallocate(tmp)
    return
  end subroutine msort

end program prob5

Measured memory_bytes: 8968
import std.stdio;
import std.string;
import std.conv;
import std.typecons;
import std.algorithm;
import std.functional;
import std.bigint;
import std.numeric;
import std.array;
import std.math;
import std.range;
import std.container;

void main() {
    int[] ary = [1,5,10,50,100,500];
    writeln(readln.split.to!(int[]).enumerate.map!(a => ary[a.index]*a.value).sum>=1000 ? 1: 0);
}

Measured memory_bytes: 2540
#include <bits/stdc++.h>
using namespace std;
int main() {
    int A,B,C,X;
    cin >> A >> B >> C >> X;
    int count = 0;

    for(int i=0; i <= A ; i++){
        for(int j = 0; j <= B; j++){
            for(int k = 0; k <= C; k++){
                if(500*i+100*j+50*k == X){
                    count++;
                }
            }
        }
    }

    cout << count << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define FOR(i, k, n) for(int i = (k); i < (n); i++)
#define FORe(i, k, n) for(int i = (k); i <= (n); i++)
#define FORr(i, k, n) for(int i = (k)-1; i > (n); i--)
#define FORre(i, k, n) for(int i = (k)-1; i >= (n); i--)
#define REP(i, n) FOR(i, 0, n)
#define REPr(i, n) FORre(i, n, 0)
#define ALL(x) (x).begin(), (x).end()
#define ALLr(x) (x).rbegin(), (x).rend()
#define chmin(x, y) x = min(x, y)
#define chmax(x, y) x = max(x, y)
using namespace std;
using ll = long long;

const int INF = 1001001001;

int main(void){
  int n, m;
  cin >> n >> m;
  vector<ll> x(m);
  REP(i, m) cin >> x[i];
  if(n >= m){
    cout << 0 << endl;
    return 0;
  }
  sort(ALL(x));
  vector<ll> l(m-1);
  REP(i, m-1) l[i] = x[i+1] - x[i];
  sort(ALLr(l));
  ll ans = x[m-1] - x[0];
  REP(i, n-1) ans -= l[i];
  cout << ans << endl;
  return 0;
}

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

using namespace std;

using int64 = long long;

constexpr int DEBUG = 0;

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

  // vector<int> xs({1, 1, 1, 2, 2, 2, 3, 3, 3});
  // cout << lower_bound(xs.begin(), xs.end(), 2) - xs.begin() << endl;
  // cout << upper_bound(xs.begin(), xs.end(), 2) - xs.begin() << endl;

  int n;
  int64 len;
  int64 t;
  cin >> n >> len >> t;
  vector<int64> p_xs;
  vector<int64> n_xs;
  for (int i = 0; i < n; i++) {
    int64 x;
    int w;
    cin >> x >> w;
    if (w == 1) {
      p_xs.push_back(x);
    } else {
      n_xs.push_back(x);
    }
  }

  int64 m = 2 * ((t + len - 1) / len) + 1;

  auto count_leq_pos = [&](int64 k) -> int64 {
    int64 a = k - t;
    if (a < 0) return 0;
    return a / len * p_xs.size()
        + (upper_bound(p_xs.begin(), p_xs.end(), a % len) - p_xs.begin());
  };

  auto count_leq_neg = [&](int64 k) -> int64 {
    int64 a = k + t;
    return a / len * n_xs.size()
        + (upper_bound(n_xs.begin(), n_xs.end(), a % len) - n_xs.begin());
  };

  auto solve = [&](int i) -> int64 {
    int64 l = 0;
    int64 u = (2 * m + 1) * len;
    while (u - l >= 2) {
      int64 middle = (l + u) / 2;
      int64 count = count_leq_pos(middle) + count_leq_neg(middle);
      if (count >= m * n + i + 1) {
        u = middle;
      } else {
        l = middle;
      }
    }
    if (DEBUG) cout << "u: " << u << endl;
    return u % len;
  };
  
  for (int i = 0; i < n; i++) {
    cout << solve(i) << endl;
  }
}

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

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

    const auto base10 = n % 10;
    const char *particles[] = {
        "pon",
        "pon",
        "hon",
        "bon",
        "hon",
        "hon",
        "pon",
        "hon",
        "pon",
        "hon",
    };
    cout << particles[base10] << endl;

    return 0;
}

Measured memory_bytes: 3612
N=int(input())
*V,=map(int,input().split())
import collections

import collections

c1=collections.Counter(V[0::2])
c1=sorted(c1.items(), key=lambda x: x[1], reverse=True)
e=c1[0][0]

c2=collections.Counter(V[1::2])
c2=sorted(c2.items(), key=lambda x: x[1], reverse=True)
o=c2[0][0]

cnt=0
if e!=o:
    cnt=sum(e!=i for i in V[0::2])
    cnt+=sum(o!=i for i in V[1::2])
else:
    if len(c1)==1 and len(c2)==1:
        cnt=N//2
    elif len(c1)==1:
        cnt1=sum(e!=i for i in V[0::2])
        cnt1+=sum(c2[1][0]!=i for i in V[1::2])
        
        cnt2=sum(e!=i for i in V[0::2])
        cnt2+=sum(c2[1][1]!=i for i in V[1::2])
        cnt=min(cnt1,cnt2)
    elif len(c2)==1:
        cnt1=sum(c1[1][0]!=i for i in V[0::2])
        cnt1+=sum(o!=i for i in V[1::2])

        cnt2=sum(c1[1][1]!=i for i in V[0::2])
        cnt2+=sum(o!=i for i in V[1::2])
        cnt=min(cnt1,cnt2)
    else:    
        cnt1=sum(e!=i for i in V[0::2])
        cnt1+=sum(c2[1][0]!=i for i in V[1::2])
        
        cnt2=sum(c1[1][0]!=i for i in V[0::2])
        cnt2+=sum(o!=i for i in V[1::2])
        cnt=min(cnt1,cnt2)
print(cnt)

Measured memory_bytes: 25360
from collections import Counter
from itertools import combinations, product

def gap(s, t):
    d = abs(s-t)
    return min(d, 24 - d)

N = int(input())
*D, = map(int, input().split())
cnt = Counter(D + [0])
time_definite = []
time_indefinite = []
for k, v in cnt.items():
    if (k != 0 and v >= 3) or (k == 0 and v >= 2):
        ans = 0; break
    else:
        if v == 2:
            time_definite.append(k); time_definite.append(-k)
        else:
            if k == 0: time_definite.append(k)
            else: time_indefinite.append(k)
else:
    ans = 0
    def_min = 12
    for t1, t2 in combinations(time_definite, 2):
        def_min = min(def_min, gap(t1, t2))
    cand = len(time_indefinite)
    for bit in range(1 << cand):
        time_temp = [t if (bit & (1 << i)) else -t for i, t in enumerate(time_indefinite)]
        indef_min = 12
        for t1, t2 in combinations(time_temp, 2):
            indef_min = min(indef_min, gap(t1, t2))
        temp = min(def_min, indef_min)
        for t1, t2 in product(time_temp, time_definite):
            temp = min(temp, gap(t1, t2))
        ans = max(ans, temp)
print(ans)

Measured memory_bytes: 3316
package main

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

func main() {
	In := ReadLineInt()
	A, B := In[1], In[2]

	ForeignCount := 0
	GoCount := 0
	PartsInput := ReadLine()
	for _, v := range strings.Split(PartsInput, "") {
		if GoCount >= A+B {
			fmt.Println("No")
			continue
		}

		switch v {
		case "a": //日本人
			fmt.Println("Yes")
			GoCount++

		case "b": //外国人
			if ForeignCount < B {
				fmt.Println("Yes")
				ForeignCount++
				GoCount++
			} else {
				fmt.Println("No")
			}

		case "c":
			fmt.Println("No")
		}
	}
}

/////////////////////////////////////////

func fln(format string, elements ...interface{}) {
	fmt.Printf(format+"\n", elements...)
}

var BufReader = bufio.NewReaderSize(os.Stdin, 1e6)

func ReadLine() string {
	a, _, _ := BufReader.ReadLine()
	return string(a)
}

func ReadLineInt() (result []int) {
	in := strings.Split(ReadLine(), " ")
	result = make([]int, 0, 2)
	for _, v := range in {
		t, _ := strconv.Atoi(v)
		result = append(result, t)
	}
	return
}

Measured memory_bytes: 4480
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define Int int32_t
#define all(c) c.begin(), c.end()
#define FAST ios_base::sync_with_stdio(false) , cin.tie(NULL);
#define pii pair<int,int>
#define pb push_back
#define F first
#define S second
#define endl "\n"
#define bitcnt(n) __builtin_popcountll(n)
#define setpre(n) cout << fixed << setprecision(n)
#define tr(c) for(const auto& x : c )cout << x << " "; cout << "\n";
#define ol(c, s, e) for(int pos=s; pos<e; pos++)cout << c[pos] << " ";cout <<"\n";
#define PI acos(-1LL)

const int M = 1000000007;
const int N = 2e6 + 5;
const long long INF = 1e18 + 37;

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

signed main(){
    FAST
    int tc = 1;
//    TODO: check for tc
//    cin >> tc;
    for (int t = 1; t <= tc; t++) {
        solve();
    }
}


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

/*
  // Overview
  グラフの全点間最短路を求める。
  負辺があっても動作。負閉路検出可能。

  // Time complexity
  O(n ^ 3) (n: 頂点の数)

  // Initialization
  WarshallFloyd wf = WarshallFloyd(n); (n: 頂点の数)
  wf.add_edge(u, v, c); (u: start, v: to, c: コスト) (無向グラフの場合は両辺に張る)
  wf.build();
*/
struct WarshallFloyd {
    typedef vector< vector< long long > > Matrix;
    const long long INF = 1LL<<60;
    int n;
    Matrix g;
    WarshallFloyd(int n) : n(n), g(n, vector< long long >(n, INF)) {
        for (int i = 0; i < n; ++i) g[i][i] = 0;
    }
    void add_edge(int u, int v, long long c) {
        g[u][v] = c;
    }
    void build() {
        for (int k = 0; k < g.size(); ++k) {
            for (int i = 0; i < g.size(); ++i) {
                for (int j = 0; j < g.size(); ++j) {
                    if(g[i][k] == INF || g[k][j] == INF) continue;
                    g[i][j] = min(g[i][j], g[i][k] + g[k][j]);
                }
            }
        }
    }
    // Time complexity
    // O(n) (n: 頂点数)
    bool has_negative_cycle() {
        for (int i = 0; i < n; ++i) if (g[i][i] < 0) return true;
        return false;
    }
    long long shortest_path_value(int s, int t) {
        return g[s][t];
    }
    bool is_unreachable(int s, int t) {
        return g[s][t] == INF;
    }
};

int main() {
    int n, m, r; cin >> n >> m >> r;
    vector<int> rs(r);
    for (int i = 0; i < r; ++i) {
        cin >> rs[i];
        --rs[i];
    }
    WarshallFloyd wf(n);
    for (int i = 0; i < m; ++i) {
        int s, t, d; cin >> s >> t >> d;
        --s, --t;
        wf.add_edge(s, t, d);
        wf.add_edge(t, s, d);
    }
    wf.build();
    sort(rs.begin(), rs.end());
    long long res = 1LL<<60;
    do {
        long long sum = 0;
        for (int i = 1; i < r; ++i) {
            sum += wf.shortest_path_value(rs[i - 1], rs[i]);
        }
        res = min(res, sum);
    } while (next_permutation(rs.begin(), rs.end()));
    cout << res << endl;
}

Measured memory_bytes: 512
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<ll> vec;
typedef vector<vec> mat;
typedef pair<ll,ll> pll;
const ll mod=1e9+7;
//const ll mod=998244353;
const ll inf=1LL<<61;

int main() {
  ll n;
  cin >> n;
  vector<double> p(n);
  for(ll i=0;i<n;i++) cin >> p[i];
  vector<vector<double>> dp(n+1,vector<double>(n+1));
  dp[0][0]=1.0;
  for(ll i=0;i<n;i++) {
    for(ll j=0;j<=n;j++) {
      dp[i+1][j]+=dp[i][j]*(1-p[i]);
      if(j) dp[i+1][j]+=dp[i][j-1]*p[i];
    }
  }
  double ans=0;
  for(ll i=0;i<=n;i++) {
    if(n-i<i) ans+=dp[n][i];
  }
  cout << fixed << setprecision(10) << ans << endl;
}

Measured memory_bytes: 70784
#include<stdio.h>

int N, Q;
char S[100001];

int acCount[100000];
int sum[100001];
int main(){
	scanf("%d%d",&N, &Q);
	scanf("%s",S);

	for(int i = 0; i < N; i++){
		if(S[i] == 'A' and S[i + 1] == 'C'){
			sum[i + 1] += 1 + sum[i];
		}
		else{
			sum[i + 1] = sum[i];
		}
	}
	for(int i = 0; i < Q; i++){
		int l, r;
		scanf("%d%d",&l, &r);
		printf("%d\n", sum[r - 1] - sum[l - 1]);
	}
	return 0;
}


Measured memory_bytes: 1280
#include<iostream>
#include<stdio.h>
#include<stdlib.h>
#include<bits/stdc++.h>
using namespace std;
//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/tree_policy.hpp>
//using namespace __gnu_pbds;
/*---------------------DEBUGGING--------------------------------------------*/
void __print(int x) {cerr << x;}
void __print(long x) {cerr << x;}
void __print(long long x) {cerr << x;}
void __print(unsigned x) {cerr << x;}
void __print(unsigned long x) {cerr << x;}
void __print(unsigned long long x) {cerr << x;}
void __print(float x) {cerr << x;}
void __print(double x) {cerr << x;}
void __print(long double x) {cerr << x;}
void __print(char x) {cerr << '\'' << x << '\'';}
void __print(const char *x) {cerr << '\"' << x << '\"';}
void __print(const string &x) {cerr << '\"' << x << '\"';}
void __print(bool x) {cerr << (x ? "true" : "false");}

template<typename T, typename V>
void __print(const pair<T, V> &x) {cerr << '{'; __print(x.first); cerr << ','; __print(x.second); cerr << '}';}
template<typename T>
void __print(const T &x) {int f = 0; cerr << '{'; for (auto &i: x) cerr << (f++ ? "," : ""), __print(i); cerr << "}";}
void _print() {cerr << "]\n";}
template <typename T, typename... V>
void _print(T t, V... v) {__print(t); if (sizeof...(v)) cerr << ", "; _print(v...);}
#ifndef ONLINE_JUDGE
#define debug(x...) cerr << "[" << #x << "] = ["; _print(x)
#else
#define debug(x...)
#endif
/*-------------------------------------------------------------------------------------*/
//#define mp make_pair
#define pb push_back
#define ll long long
#define pii pair<int,int>
#define pcc pair<char,char>
#define F first
#define S second
#define int long long
#define pi 3.141592653589793238462643383279502
#define M 998244353//1000000007
#define rep(i,a,n) for(int i=a;i<n;i++)
#define INF 10000000000000000
#define N 10000001
#define vi vector<int>
#define all(v) v.begin(),v.end()
//#define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>

signed main()
{
   ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
   int a,v;
   int b,w;
   int t;
   cin>>a>>v;
   cin>>b>>w;
   cin>>t;
   if(a == b)
   {
       cout<<"YES"<<endl;
       return 0;
   }
   a=abs(a-b);
   if(v <= w)
   {
       cout<<"NO"<<endl;
   }
   else
   {
       v-=w;
       if(v*t>=a)
       {
           cout<<"YES"<<endl;
       }
           else
            cout<<"NO"<<endl;
   }
}


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

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

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int a, b;
  cin >> a >> b;
  cout << max({a + b, a - b, a * b}) << endl;
  return 0;
}


Measured memory_bytes: 256
#include <float.h>
#include <inttypes.h>
#include <limits.h>
#include <stdbool.h>
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>
#include <unistd.h>
#include <math.h>
#ifdef __cplusplus
#include <bits/stdc++.h>
#endif

int32_t nextint(void){ char c=getchar_unlocked(); while(c!='-'&&(c<'0'||'9'<c)) c=getchar_unlocked(); bool s=false; if(c=='-'){s=true;c=getchar_unlocked();} uint32_t x=0; while('0'<=c && c<='9'){ x=x*10+c-'0'; c=getchar_unlocked(); } return s?-x:x; }
int64_t nextlong(void){ char c=getchar_unlocked(); while(c!='-'&&(c<'0'||'9'<c)) c=getchar_unlocked(); int s=0; if(c=='-'){s=1;c=getchar_unlocked();} uint64_t x=0; while('0'<=c && c<='9'){ x=x*10+c-'0'; c=getchar_unlocked(); } return s?-x:x; }

int main(void){
	int n=nextint();
	long ans=1;
	bool f=false;
	for(int i=0; i<n; i++){
		long a=nextlong();
		if(a==0){
			f=false;
			ans=0;
			break;
		}
		if(!f){
			if(__builtin_smull_overflow(ans, a, &ans) || ans>1000000000000000000L){
				f=true;
			}
		}
	}
	printf("%ld\n", f?-1:ans);
}


Measured memory_bytes: 1596
package main

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

var rdr = bufio.NewReaderSize(os.Stdin, 1000000)

func main() {
	var n int
	fmt.Scanf("%d", &n)

	freq := make(map[Pair]int)
	for a:=1; a<=n; a++ {
		freq[cPair(a)]++
	}

	ans := 0
	for i:=1; i<=n; i++{
		pair := cPair(i)
		q := Pair{pair.second, pair.first}
		ans += freq[q]
	}

	fmt.Printf("%d", ans)
}

// Pair pair
type Pair struct{
	first int
	second int
}

func cPair(i int) Pair {
	f := first(i)
	l := last(i)

	return Pair{f,l}
}

func first(i int) int {
	digit := 0
	t := i
	for {
		t /= 10
		digit++
		if t == 0 {
			return i / (powInt(10, digit -1))
		} 
	}
}

func last(i int) int {
	return i % 10
}

func powInt(a, b int) int {
	return int(math.Pow(float64(a), float64(b)))
}

func splitAndAtoi(s string) []int {
	ss := strings.Split(s, " ")
	var r []int
	for _, s := range ss {
		i, _ := strconv.Atoi(s)
		r = append(r, i)
	}

	return r
}

func nextNumber(s *bufio.Scanner) int {
	i, _ := strconv.Atoi(nextLine(s))
	return i
}

func nextLine(s *bufio.Scanner) string {
	s.Scan()
	return s.Text()
}

func debug(s string) {
	fmt.Println(s)
}

func readLine() string {
    buf := make([]byte, 0, 1000000)
    for {
        l, p, e := rdr.ReadLine()
        if e != nil {
            panic(e)
        }
        buf = append(buf, l...)
        if !p {
            break
        }
    }
    return string(buf)
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
#define int long long
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()
#define pb push_back
#define F first
#define S second

using namespace std;
using P = pair<int,int>;
using ivec = vector<int>;
using Graph = vector<vector<int>>;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }


const int MOD=1000000007;
int INF=100100100100100;

signed main(){
  string s;cin>>s;
  int n=s.length();
  string t="keyence";
  int ima=0;
  string ans="NO";
  if(n<7){
    cout<<"NO"<<endl;
    return 0;
  }
  for(int i=0;i<=7;i++){
    string s1=s.substr(0,i);
    string s2=s.substr(n-7+i,7-i);
    //cout<<s1+s2<<endl;
    if(t==s1+s2){
      ans="YES";
      break;
    }
  }
  cout<<ans<<endl;
  return 0;
}


Measured memory_bytes: 3640
#include<iostream>
#include<cstdio>
#include<string>
#include<cstring>
#include<algorithm>
using namespace std;
typedef long long ll;
ll n;
ll ans,tmp;
inline void read(ll &x)
{
	ll f;char c;
	for (f=1,c=getchar();c<'0'||c>'9';c=getchar()) if(c=='-') f=-1;
	for (x=0;c<='9'&&c>='0';c=getchar()) x=x*10+(c&15);x*=f;
}
inline int mn(int _x,int _y)
{
	return _x<_y?_x:_y;
}
inline int mx(int _x,int _y)
{
	return _x>_y?_x:_y;
}
inline int ab(int _x)
{
	if(_x<0) return -_x;
	else return _x;
}
int main()
{
	read(n);
	tmp=1;
	while(n)
	{
		ans+=tmp;
		n>>=1;
		tmp<<=1;
	}
	printf("%lld\n",ans);
	return 0;
}



Measured memory_bytes: 256
using System;
using System.Linq;
using System.Collections.Generic;
using static System.Console;
using System.Text;
using System.IO;
using static System.Math;
using System.Numerics;

namespace AtCoder
{
    class Program
    {
        static public long[] Sarray() { return ReadLine().Split().Select(long.Parse).ToArray(); }
        static public List<long> Slist() { return ReadLine().Split().Select(long.Parse).ToList(); }
        static long Mod = (long)1e9 + 7;
        static void Main(string[] args)
        {
            SetOut(new StreamWriter(OpenStandardOutput()) { AutoFlush = false });
            Solve();
            Out.Flush();
            Read();
        }
        static void Solve()
        {
            var NAB = Sarray();
            var N = NAB[0];
            var A = NAB[1];
            var B = NAB[2];
            var Vi = Sarray();
            Array.Sort(Vi); Array.Reverse(Vi);
            var maxMean = Vi.Take((int)A).Sum();
            BigInteger ans = 0;
            //全部同じ場合B個までで使えるだけ使う
            if (Vi[0] == Vi[A - 1])
            {
                var cnt1 = Vi.Count(v => v == Vi[0]);
                var cnt2 = Min(B, Vi.Count(v => v == Vi[0]));
                for (var i = A; i <= cnt2; ++i)
                    ans += nCr((int)cnt1, (int)i);
            }
            else//Vi[A-1]を使う数だけ組み合わせがある
            {
                var cnt1 = Vi.Count(v => v == Vi[A - 1]);
                var cnt2 = 0;
                for (var i = 0; ; ++i)
                    if (Vi[A - 1] != Vi[A - 1 - i])
                    {
                        cnt2 = i;
                        break;
                    }

                ans = nCr(cnt1, cnt2);
            }
            WriteLine((decimal)(maxMean / (double)A));
            WriteLine(ans);
        }
        static BigInteger nCr(int n, int r)
        {
            var t = n - r + 1;
            BigInteger u = 1;
            for (var i = t; i <= n; ++i)
                u *= i;
            for (var i = 1; i <= r; ++i)
                u /= i;
            return u;
        }
    }
}

Measured memory_bytes: 28700
import Data.List (inits, tails, intersect, nub)

cuts :: [a] -> [([a], [a])]
cuts xs = zip (tail $ inits $ init xs) (init $ tails $ tail xs)

solve :: String -> Int
solve = maximum . map (length . nub . uncurry intersect) . cuts

main :: IO ()
main = do
  _n <- read <$> getLine :: IO Int
  s <- getLine
  print $ solve s


Measured memory_bytes: 892
#include <bits/stdc++.h>
#include <vector>
using namespace std;
int main(){
    int n; cin >> n;
    vector<int> a(n);
    for(int i=0; i<n; ++i){cin >> a[i];}
    bool ok = true;
    for(int i=0; i<n; ++i){
        if(a[i]%2==0){
            if(a[i]%5==0 || a[i]%3==0) continue;
            if((a[i]%3)!=0){ok = false;}
            if((a[i]%5)!=0){ok = false;}
        }
    }
    if(ok){cout << "APPROVED" << endl;}
    else{cout << "DENIED" << endl;}
    return 0;
}

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

int main(){
    while(1){
        int a;
        cin >> a;
        if(a == 0) break;
        int sum = 0;
        for(int i=0; i<9; i++){
            int b;
            cin >> b; 
            sum += b;
        }
        cout << a-sum << endl;
    }

    return 0;
}


Measured memory_bytes: 3008
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<ll,ll> P;
typedef pair<int,int> Pi;
#define rep(i, n) for (ll i = 0; i < n; i++)
#define FOR(i, a, b) for (ll i = a; i < b; i++)
#define fi first
#define se second
#define endl "\n"

template<typename T> inline bool chmax(T &a, T b){if(a<b){a=b;return true;}return false;}
template<typename T> inline bool chmin(T &a, T b){if(a>b){a=b;return true;}return false;}
template<typename T> ostream& operator<<(ostream& s,const complex<T>& d) {return s<<"("<<d.real()<<", "<<d.imag()<< ")";}
template<typename T1, typename T2> ostream& operator<<(ostream& s,const pair<T1,T2>& d) {return s<<"("<<d.first<<", "<<d.second<<")";}
template<typename T> ostream& operator<<(ostream& s, const vector<T>& d){
	int len=d.size();
	rep(i,len){
		s<<d[i];if(i<len-1) s<<" ";
	}
	return s;
}
template<typename T> ostream& operator<<(ostream& s,const vector<vector<T>>& d){
	int len=d.size();
	rep(i,len){
		s<<d[i]<<endl;
	}
	return s;
}
template<typename T> ostream& operator<<(ostream& s,const set<T>& v){
	s<<"{ ";
	for(auto itr=v.begin();itr!=v.end();++itr) {
		if (itr!=v.begin()) {s<< ", ";}
		s<<(*itr);
	}
	s<<" }";
	return s;
}
template<typename T1, typename T2> ostream& operator<<(ostream& s,const map<T1,T2>& m){
	s<<"{"<<endl;
	for(auto itr=m.begin();itr!=m.end();++itr){
		s<<" "<<(*itr).first<<" : "<<(*itr).second<<endl;
	}
	s<<"}"<<endl;
	return s;
}

const ll mod=1e9+7;
const ll inf=1e17;
const int INF=1e9;
const double PI=acos(-1);
const double EPS=1e-10;

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	int a,b,q;
	cin>>a>>b>>q;
	vector<ll> s(a+1,-inf),t(b+1,-inf);
	rep(i,a) cin>>s[i+1];
	rep(i,b) cin>>t[i+1];
	while(q--){
		ll x;
		cin>>x;
		auto itr1=lower_bound(begin(s),end(s),x);
		ll A=*itr1;
		itr1--;
		ll B=*itr1;
		auto itr2=lower_bound(begin(t),end(t),x);
		ll C=*itr2;
		itr2--;
		ll D=*itr2;
		ll ans=inf;
		chmin(ans,abs(x-A)+abs(A-C));
		chmin(ans,abs(x-A)+abs(A-D));
		chmin(ans,abs(x-B)+abs(B-C));
		chmin(ans,abs(x-B)+abs(B-D));
		chmin(ans,abs(x-C)+abs(C-A));
		chmin(ans,abs(x-C)+abs(C-B));
		chmin(ans,abs(x-D)+abs(D-A));
		chmin(ans,abs(x-D)+abs(D-B));
		cout<<ans<<endl;
	}
}

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

using namespace std;

#define PB push_back
#define f first
#define s second

typedef long long ll;
typedef pair<ll, ll> pll;
typedef pair<int, int> pii;

const int MOD = 1000000007;
const int INF = 1000000007;
const int MAXN = (int)3e5+1;

void setIO(string name)
{
	freopen((name+".in").c_str(),"r",stdin);
	freopen((name+".out").c_str(),"w",stdout);
}

bool ok(int a, int b)
{
    if(a<1)
    {
        return false;
    }
    if(a == 1)
    {
        return true;
    }
    if(a%b == 0)
    {
        return ok(a/b, b);
    }
    else
    {
        return ok(a-b, b);
    }
}

bool seen[1000001];

bool res(ll a, ll b)
{
    while(a%b == 0)
    {
        a/=b;
    }
    return a%b == 1;

}

int main()
{
    ios_base::sync_with_stdio(0); cin.tie(0);
    //setIO("");
    ll n;
    cin >> n;
    if(n==2)
    {
        cout << 1;
        return 0;
    }
    ll ct = 2;
    for(ll i = 2; i*i <= n; i++)
    {
        if(n%i == 0 && res(n, i))
        {
            ct++;
            seen[i] = true;
            //cout << i << " ";
        }
    }

    for(ll i = 2; i*i <= (n-1); i++)
    {
        if(seen[i])
            continue;
        if((n-1)%i == 0)
        {
            //cout << i << " " << (n-1)/i << " ";
            ct += 2;
            if(i*i == n-1)
                ct--;
        }
    }
    //cout << "\n";

//    for(int j=2; j<=3141; j++)
//    {
//        if(ok(3141, j))
//        {
//            cout << j << " ";
//        }
//    }
    cout << ct;

    return 0;
}


Measured memory_bytes: 256
N,x=map(int, input().split(' '))
a = list(map(int, input().split(' ')))
wa = [a[0]]+[a[i]+a[i+1] for i in range(N-1)]+[a[-1]]
ans = 0

for i in range(N):
    if wa[i] <= x:
        continue
    if wa[i] > x:
        dif = wa[i]-x
        ans += dif
        a[i] -= dif
        wa[i] -= dif
        wa[i+1] -= dif
        continue

if wa[-1] > x:
    ans += wa[-1]-x
    a[-1] = wa[-1]-x
    wa[-1] -= wa[-1]-x

print(ans)

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

int main() {
  int a, b, c, d;
  cin >> a >> b >> c >> d;
  int ans = 0;
  ans = min(b, d) - max(a, c);
  if (ans < 0)
    ans = 0;
  cout << ans;
  return 0;
}

Measured memory_bytes: 256
// clang-format off
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define loop(i, a, n) for (int i = (a); i < (n); i++)
#define rep(i, n) loop(i, 0, n)
#define all(v) (v).begin(), (v).end()
#define rall(v) (v).rbegin(), (v).rend()
#define prec(n) fixed << setprecision(n)
constexpr int INF = sizeof(int) == sizeof(long long) ? 1000000000000000000LL : 1000000000;
constexpr int MOD = 1000000007;
constexpr double PI = 3.14159265358979;
template<typename A, typename B> bool cmin(A &a, const B &b) { return a > b ? (a = b, true) : false; }
template<typename A, typename B> bool cmax(A &a, const B &b) { return a < b ? (a = b, true) : false; }
bool odd(const int &n) { return n & 1; }
bool even(const int &n) { return ~n & 1; }
template<typename T> int len(const T &v) { return v.size(); }
template<typename T = int> T in() { T x; cin >> x; return x; }
template<typename T = int> T in(T &&x) { T z(forward<T>(x)); cin >> z; return z; }
template<typename T> istream &operator>>(istream &is, vector<T> &v) { for (T &x : v) is >> x; return is; }
template<typename A, typename B> istream &operator>>(istream &is, pair<A, B> &p) { return is >> p.first >> p.second; }
template<typename T> ostream &operator<<(ostream &os, const vector<vector<T>> &v) { int n = v.size(); rep(i, n) os << v[i] << (i == n - 1 ? "" : "\n"); return os; }
template<typename T> ostream &operator<<(ostream &os, const vector<T> &v) { int n = v.size(); rep(i, n) os << v[i] << (i == n - 1 ? "" : " "); return os; }
template<typename A, typename B> ostream &operator<<(ostream &os, const pair<A, B> &p) { return os << p.first << ' ' << p.second; }
template<typename Head, typename Value> auto vectors(const Head &head, const Value &v) { return vector<Value>(head, v); }
template<typename Head, typename... Tail> auto vectors(Head x, Tail... tail) { auto inner = vectors(tail...); return vector<decltype(inner)>(x, inner); }
// clang-format on

main() {
  int a, b, c;
  cin >> a >> b >> c;
  cout << min({a, b, c}) << " " << max({a, b, c}) << endl;
}



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

const int MAXN = 100100;

int n;
int a[MAXN], p[MAXN], csum[2*MAXN];

bool good(int c){
  for(int i=0;i<n;i++){
    if (a[i] >= c) p[i] = 1;
    else p[i] = -1;
  }
  for(int i=0;i<2*MAXN;i++) csum[i] = 0;

  int cs = MAXN;
  csum[cs] = 1;
  int ctot = 1;
  long long res = 0;
  for(int i=0;i<n;i++){
    if(p[i] == -1){
      ctot -= csum[cs];
      cs--;
    }else{
      ctot += csum[cs+1];
      cs++;
    }
    res += ctot;
    csum[cs]++;
    ctot++;
  }
  return res * 2 >= (n*((long long)n+1))/2;
}

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

  int l=0, r=1e9;
  while(l<r){
    int mid = (l+r+1)/2;
    if(good(mid)) l = mid;
    else r = mid - 1;
  }
  cout << l << endl;
}


Measured memory_bytes: 1920
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;

#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
//const ll mod = 1000000007;

int main() {
    //cout.precision(10);
    int a, b, c;
  cin>>a>>b>>c;
  int sum = a+b+c;
  if(max(a, max(b, c))*2==sum) cout << "Yes"<<endl;
  else cout << "No"<<endl;
    return 0;
}


Measured memory_bytes: 256
package main

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

var sc = bufio.NewScanner(os.Stdin)

func main() {
	scanInit()

	a := nextInt() // 500
	b := nextInt() // 100
	c := nextInt() // 50
	x := nextInt()

	cnt := 0

	for ai := 0; ai <= a; ai++ {
		for bi := 0; bi <= b; bi++ {
			for ci := 0; ci <= c; ci++ {
				if ai*500+bi*100+ci*50 == x {
					cnt++
				}
			}
		}
	}

	fmt.Println(cnt)

}

// ---- readfunc
func scanInit() {
	const cap = 64 * 1024
	var buf = make([]byte, cap)
	sc.Buffer(buf, cap)
	sc.Split(bufio.ScanWords)
	return
}
func nextInt() int {
	sc.Scan()
	i, e := strconv.Atoi(sc.Text())
	if e != nil {
		panic(e)
	}
	return i
}
func nextStr() string {
	sc.Scan()
	return sc.Text()
}


Measured memory_bytes: 1776
d=input().split()
for _ in range(int(input())):
 t,f=[d.index(s)for s in input().split()]
 n=[(1,2,4,3,1),(0,3,5,2,0),(0,1,5,4,0),(1,0,4,5,1),(0,2,5,3,0),(1,3,4,2,1)][t]
 print(d[n[n.index(f)+1]])



Measured memory_bytes: 5604