akhauriyash/Code-Regression huggingface dataset:
use proconio::fastout;
use whiteread::parse_line;

#[fastout]
fn main() {
    let mut a: Vec<usize> = parse_line().unwrap();
    a.sort();

    let mut ret = 0;
    if (a[1] - a[0]) % 2 != 0 {
        ret += 1;
        a[0] += 1;
        a[2] += 1;
    }
    ret += (a[1] - a[0]) / 2;
    ret += a[2] - a[1];

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


Measured memory_bytes: 2140
using System;
using System.Linq;
using System.Collections.Generic;

class Program
{

    static void Main(string[] args)
    {
        var N = long.Parse(Console.ReadLine());
        var A = long.Parse(Console.ReadLine());
        var B = long.Parse(Console.ReadLine());
        var C = long.Parse(Console.ReadLine());
        var D = long.Parse(Console.ReadLine());
        var E = long.Parse(Console.ReadLine());

        var loads = new long[] { A, B, C, D, E };
        long min = long.MaxValue;
        for (int i = 0; i < loads.Length; i++)
        {
            min = Math.Min(loads[i], min);
        }

        var ans = (long)Math.Ceiling((double)N / min) + 4;
        Console.WriteLine(ans);
    }
}



Measured memory_bytes: 13140
#include <bits/stdc++.h>
// #include <ext/pb_ds/assoc_container.hpp>
// #include <ext/pb_ds/tree_policy.hpp>
// #pragma GCC optimize("unroll-loops,no-stack-protector")
// #pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
 
// using namespace __gnu_pbds;
using namespace std;
 
// template <typename T>
// using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
 
typedef long long ll;
typedef long double ld;
typedef pair<long long ,long long> ii; 	
//typedef complex<long double> com;

vector <ll> fact(2e6+2);
ll answer = 0;
const ll mod = 1e9+7;

ll power(ll x,ll y){
	ll ans = 1;
	while (y > 0){
		if (y & 1) ans *= x;
		y /= 2;
		x *= x;
		x %= mod;
		ans %= mod;
	}
	return ans;
}

ll func(ll c,ll r){
	ll ans = 0;
	for (int z=1;z<=r+1;z++){
		ans += ((fact[z+c]*power(fact[z],mod-2))%mod*power(fact[c],mod-2))%mod;
		ans %= mod;
	}
	return ans;
}

int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	ll r1,c1,r2,c2;
	cin >> r1 >> c1 >> r2 >> c2;
	fact[0] = 1;
	fact[1] = 1;
	for (ll z=2;z<=ll(2e6+1);z++){
		fact[z] = fact[z-1] * z;
		fact[z] %= mod;
	}
	answer += func(r2,c2);
	answer %= mod;
	answer -= func(r2,c1-1);
	answer %= mod;
	answer -= func(r1-1,c2);
	answer %= mod;
	answer += func(r1-1,c1-1);
	answer %= mod;
	if (answer < 0) answer += mod;
	cout << answer << endl;
} 
 

Measured memory_bytes: 15872
#include <iostream>
#include <vector>
#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;

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

  vector<int> p(n);

  rep(i,n) cin>>p[i];

  int answer = 0;
  for (int i = 0; i < n-2; i++){
    if(p[i]>p[i+1] && p[i+1] > p[i+2]) answer +=1;
    else if(p[i]<p[i+1] && p[i+1] < p[i+2]) answer +=1;
  }

  cout << answer << endl;

  return 0;
}



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

int main() {
    int n, i=1, x;

    cin >> n;
    do{
        x=i;
        if(x%3==0){
            cout << " " << i;
        }else{
            do{
                if(x%10==3){
                    cout << " " << i;
                    break;
                }
                x= x/10;
            }while(x);
        }
    }while(++i<=n);
    cout << endl;
    return 0;
}


Measured memory_bytes: 3048
#include <stdio.h>

int main(){
    int i, j, k;
    int n, x;
    int count;

    while(1){
        scanf("%d %d ", &n, &x);
        if(n==0&&x==0)break;
        count=0;
        for(i=1;3*i+3<=x;i++){
            for(j=i+1;i+2*j+1<=x;j++){
                for(k=n;k>j;k--){
                    if(x==i+j+k){
                        count++;
                        break;
                    }else if(x>=i+j+k){
                        break;
                    }
                }
            }
        }
        printf("%d\n", count);
    }
    return 0;
}


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

using namespace std;
using ll = long long;
using ull = unsigned long long;

constexpr ll LLINF {1001002003004005006};//ll = 9*LLINF
constexpr int INTINF {1000000000};//int = 2*INTINF

#define  rep(i,n)   for(int i = 0; i < (n); ++i)
#define rrep(i,n)   for(int i = 1; i <= (n); ++i)
#define drep(i,n)   for(int i = (n)-1; i >= 0; --i)
#define srep(i,s,t) for(int i = s; i < t;  ++i)

template<typename T>
void maxs(T& x, T&& y) {
  x=std::max(x,y);
}
template<typename T>
void maxs(T& x, T& y) {
  x=std::max(x,y);
}

template<typename T>
void mins(T& x, T&& y) {
  x=std::min(x,y);
}
template<typename T>
void mins(T& x, T& y) {
  x=std::min(x,y);
}

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

  int N;
  cin >> N;

  ull answer {};
  rep(i, N+1) {
    if (i%3==0) continue;
    else if (i%5==0) continue;
    else answer += i;
  }
  cout << answer << '\n';
}


Measured memory_bytes: 3648
#include <stdio.h>

int main(){
	int n,r,p,c;
	int i,j,k,l;
	int a[55],b[55];

	while (1){
		scanf("%d %d",&n,&r);
		for(i=0; i<n; i++)a[i]=i+1;
		if(n==0&&r==0)break;
		for(i=0; i<r; i++){
			scanf("%d %d",&p,&c);
			for(j=0; j<c; j++){
				b[j]=a[n-p-c+j+1];
			}
			for(j=0; j<p-1; j++){
				a[n-p-c+j+1]=a[n-p+j+1];
			}
			for(j=0; j<c; j++){
				a[n-1-c+j+1]=b[j];
			}
		}
		printf("%d\n",a[n-1]);
	}

	return 0;
}

Measured memory_bytes: 600
import java.io.IOException;
import java.io.InputStream;
import java.util.Arrays;
import java.util.NoSuchElementException;

public class Main {

	public static void main(String[] args) {
		FScanner sc = new FScanner();
		long N = sc.nextLong();
		long[] ary = new long[(int) N];
		for (long i = 0; i < N; i++) {
			ary[(int) i] = sc.nextLong();
		}
		if (N % 2 == 1) {
			System.out.println(0);
			return;
		}
		Arrays.sort(ary);
		long end = ary.length / 2;
		long start = end - 1;
		System.out.println(ary[(int) end] - ary[(int) start]);
	}

}

class FScanner {
	private final InputStream in = System.in;
	private final byte[] buffer = new byte[1024];
	private int ptr = 0;
	private int buflen = 0;

	private boolean hasNextByte() {
		if (ptr < buflen) {
			return true;
		} else {
			ptr = 0;
			try {
				buflen = in.read(buffer);
			} catch (IOException e) {
				e.printStackTrace();
			}
			if (buflen <= 0) {
				return false;
			}
		}
		return true;
	}

	private int readByte() {
		if (hasNextByte())
			return buffer[ptr++];
		else
			return -1;
	}

	private static boolean isPrintableChar(int c) {
		return 33 <= c && c <= 126;
	}

	public boolean hasNext() {
		while (hasNextByte() && !isPrintableChar(buffer[ptr]))
			ptr++;
		return hasNextByte();
	}

	public String next() {
		if (!hasNext())
			throw new NoSuchElementException();
		StringBuilder sb = new StringBuilder();
		int b = readByte();
		while (isPrintableChar(b)) {
			sb.appendCodePoint(b);
			b = readByte();
		}
		return sb.toString();
	}

	public long nextLong() {
		if (!hasNext())
			throw new NoSuchElementException();
		long n = 0;
		boolean minus = false;
		int b = readByte();
		if (b == '-') {
			minus = true;
			b = readByte();
		}
		if (b < '0' || '9' < b) {
			throw new NumberFormatException();
		}
		while (true) {
			if ('0' <= b && b <= '9') {
				n *= 10;
				n += b - '0';
			} else if (b == -1 || !isPrintableChar(b)) {
				return minus ? -n : n;
			} else {
				throw new NumberFormatException();
			}
			b = readByte();
		}
	}

	public int nextInt() {
		long nl = nextLong();
		if (nl < Integer.MIN_VALUE || nl > Integer.MAX_VALUE)
			throw new NumberFormatException();
		return (int) nl;
	}

	public double nextDouble() {
		return Double.parseDouble(next());
	}
}

Measured memory_bytes: 23608
var
	X,Y,Z,S,K,tmpi:Longint;
	A,B,C,tmps:String;
function rep(s:String;x:Longint):String;
var
	ret:String='';
	i:Longint;
begin
	for i:=1 to x do ret:=ret+s;
	rep:=ret;
end;
procedure two(x,y:Longint;xs,ys:String);
var
	k,i:Longint;
begin
	while(x>0)and(y>0)do begin
		if x<=y then begin
			k:=y div x;
			dec(y,k*x);
			xs:=xs+rep(ys,k);
		end;
		dec(x,y);
		ys:=xs+ys;
	end;
	for i:=1 to x do write(xs);
	for i:=1 to y do write(ys);
	writeln;
end;
begin
	read(X,Y,Z);
	S:=X+Y+Z;
	if S=X then begin
		writeln(rep('a',X));
		exit;
	end else if S=Y then begin
		writeln(rep('b',Y));
		exit;
	end else if S=Z then begin
		writeln(rep('c',Z));
		exit;
	end;
	A:='a';
	B:='b';
	C:='c';
	while True do begin
		if X=0 then begin
			two(Y,Z,B,C);
			exit;
		end else if Y=0 then begin
			two(X,Z,A,C);
			exit;
		end else if Z=0 then begin
			two(X,Y,A,B);
			exit;
		end;
		if X<=Z then begin
			K:=Z div X;
			dec(Z,K*X);
			A:=A+rep(C,K);
		end;
		dec(X,Z);
		C:=A+C;
		tmps:=B;
		B:=C;
		C:=tmps;
		tmpi:=Y;
		Y:=Z;
		Z:=tmpi;
	end;
end.


Measured memory_bytes: 256
N, A, B = int(input()), list(map(int, input().split())), list(map(int, input().split()))
result = 0
for i in range(N):
    a, a_next, b = A[i], A[i+1], B[i]
    if a >= b: result += b
    elif a + a_next < b:
        result += a + a_next
        A[i+1] = 0
    else:
        A[i+1] -= b - a
        result += b
print(result)

Measured memory_bytes: 18476
#include<stdio.h>

int main(){
  int N, flag = 0;
  char s[100];
  
  scanf("%d", &N);
  for (int i = 0; i < N; i++){
    scanf("%c", &s[i]);
    if(s[i] == 'Y'){
      flag = 1;
    }
  }
  if(flag == 0){
    printf("Three\n");
  } else {
    printf("Four\n");
  }
  
  return 0;
}

Measured memory_bytes: 128
import java.util.Scanner;

public class Main {

	public static void main(String[] args) throws Exception {
		Scanner sc = new Scanner(System.in);
		int n = Integer.parseInt(sc.next());
		int sum = 0;
		int max = 0;
		for (int i = 0; i < n; i++) {
			int price = Integer.parseInt(sc.next());
			sum += price;
			if (max < price) {
				max = price;
			}
		}
		int ans = sum - (max / 2);
		System.out.println(ans);
		sc.close();
	}
}

Measured memory_bytes: 21844
#include<stdio.h>
int main()
{
    int a,b,c,count=0;
    scanf("%d %d %d",&a,&b,&c);
    for(int i=a;i<=b;i++)
    {
        if(c%i==0)
        {
            count++;
        }
    }
 printf("%d\n",count);
    
}


Measured memory_bytes: 2096
n=int(input())
a=input()
A=a.split()
b=input()
B=b.split()
c=input()
C=c.split()
ans=0
for i in range(n):
    ans=ans+int(B[int(A[i])-1])
for j in range(n-1):
    if int(A[j+1])==int(A[j])+1:
        ans=ans+int(C[int(A[j])-1])
print(ans)

Measured memory_bytes: 3064
package main

import (
	"bufio"
	"fmt"
	"math/big"
	"os"
	"strconv"
)

type splitter int

const (
	bySpace splitter = iota
	byLine
)

func newScanner(sp splitter) *sc {
	scanner := bufio.NewScanner(os.Stdin)
	if sp == bySpace {
		scanner.Split(bufio.ScanWords)
	}
	return &sc{
		s: scanner,
	}
}

type sc struct {
	s *bufio.Scanner
}

func (s *sc) nextInt() int {
	if s.s.Scan() {
		val := s.s.Text()
		v, err := strconv.Atoi(val)
		if err != nil {
			panic(err)
		}
		return v
	}
	panic("no more stdin")
}

func main() {
	scanner := newScanner(bySpace)
	n := scanner.nextInt()
	arr := make([]int64, n)
	var tot int64 = 0
	for i := 0; i < n; i++ {
		p := scanner.nextInt()
		tot += int64(p)
		arr[i] = int64(p)
	}
	minus := big.NewInt(0)
	ans := big.NewInt(0)
	m := big.NewInt(1000000007)
	bigTot := big.NewInt(tot)
	for _, v := range arr {
		cur := big.NewInt(v)
		minus = big.NewInt(0).Add(minus, cur)
		buf := big.NewInt(0).Mul(cur, big.NewInt(0).Sub(bigTot, minus))
		ans = big.NewInt(0).Mod(big.NewInt(0).Add(ans, buf), m)
	}
	fmt.Println(ans.Int64())
}


Measured memory_bytes: 6528
from fractions import gcd
mod=10**9+7
def pow_r(x, n):
    if n == 0:  # exit case
        return 1
    if n % 2 == 0:  # standard case ① n is even
        return pow_r(x ** 2%mod, n // 2)%mod
    else:  # standard case ② n is odd
        return x * pow_r(x ** 2%mod, (n - 1) // 2)%mod
h,w,t=map(int,input().split())
H=gcd(h,t);W=gcd(w,t)
groups=H*W
unit=(h//H,w//W)
cnt=(pow_r(2,unit[0])+pow_r(2,unit[1])-3)%mod
unitd=gcd(unit[0],unit[1])
cnt+=pow_r(2,unitd)%mod
print(pow_r(cnt,groups))


Measured memory_bytes: 64364
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <string>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <iomanip>
#include <utility>
#include <tuple>
#include <functional>
#include <bitset>
#include <cassert>
#include <complex>
#include <stdio.h>
#include <time.h>
#include <numeric>
#include <random>
#include <unordered_map>
#include <unordered_set>
#define all(a) a.begin(),a.end()
#define rep(i, n) for (ll i = 0; i < (n); i++)
#define pb push_back
#define debug(x) cerr << #x << ':' << (x) << '\n'
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair<ll, ll> P;
typedef complex<ld> com;
constexpr int inf = 1000000010;
constexpr ll INF = 1000000000000000010;
constexpr ld eps = 1e-12;
constexpr ld pi = 3.141592653589793238;
template<class T, class U> inline bool chmax(T &a, const U &b) { if (a < b) { a = b; return true; } return false; }
template<class T, class U> inline bool chmin(T &a, const U &b) { if (a > b) { a = b; return true; } return false; }


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

	int n, m;
	cin >> n >> m;
	int q;
	cin >> q;
	vector<int> a(q);
	rep(i, q) {
		cin >> a[i];
		a[i]--;
	}
	reverse(all(a));
	vector<int> pl(m, -1), cnt(m), val(m);
	int idx = 0;
	rep(i, q) {
		if (pl[a[i]] == -1) {
			pl[a[i]] = idx;
			val[pl[a[i]]] = a[i];
			idx++;
			cnt[pl[a[i]]]++;
		}
		else {
			int p = pl[a[i]];
			if (p == 0 || cnt[p - 1] > cnt[p]) {
				if (cnt[p] < n) cnt[p]++;
			}
		}
	}
	vector<int> vec;
	rep(i, m) if (cnt[i] != 0 && cnt[i] != n) vec.pb(val[i]);
	rep(i, m) if (pl[i] == -1) vec.pb(i);
	bool flag = true;
	int sz = vec.size();
	rep(i, sz - 1) if (vec[i] > vec[i + 1]) flag = false;
	cout << (flag ? "Yes" : "No") << '\n';
}

Measured memory_bytes: 5460
#include <bits/stdc++.h>
using namespace std;
void read(int &x){
	char ch=getchar();x=0;
	for (;ch==' '||ch=='\n';ch=getchar());
	for (;ch!=' '&&ch!='\n';x=x*10+ch-'0',ch=getchar()); 
}
void reads(string &s){
	char ch=getchar();s="";
	for (;ch==' '||ch=='\n';ch=getchar());
	for (;ch!=' '&&ch!='\n';s+=ch,ch=getchar()); 
}
void write(int x){
	if (x>9) write(x/10);
	putchar(x%10+'0'); 
}
int n,K,C,n_=1,dp[200005],f[200005],p[200005];
string s;
int main(){
	read(n),read(K),read(C),reads(s),s="$"+s;while (n_<n) n_<<=1; 
	for (int i=n;i;i--){
		dp[i]=dp[i+1];
		if (s[i]=='o' && i+C+1<=n) dp[i]=max(dp[i],dp[i+C+1]+1);
		if (s[i]=='o' && i+C+1>n) dp[i]=1;
		p[i]=n+1;
	}
	for (int i=1;i<=n;i++){
		f[i]=f[i-1];
		if (s[i]=='o' && i-C-1>0) f[i]=max(f[i],f[i-C-1]+1);
		if (s[i]=='o' && i-C-1<1) f[i]=1;
		p[f[i]]=min(i,p[f[i]]);
	}
	int ans=dp[1];
	for (int i=1;i<=n;i++){
		if (s[i]=='x') continue;
		if (f[i-1]==0){
			if (dp[i+1]<K) write(i),putchar('\n');
			continue;
		}
		int D=f[i-1],P=p[D];
		if (P+C+1<=n) D+=dp[max(i+1,P+C+1)];
		if (D<K) write(i),putchar('\n');
	}
}

Measured memory_bytes: 4160
import java.util.*;

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

        for (;;) {
            int h = scanner.nextInt(), w = scanner.nextInt();

            if (h == 0 && w == 0) {
                return;
            }

            for (int j = 0; j < h; ++j) {
                StringBuilder builder = new StringBuilder();
                for (int k = 0; k < w; ++k) {
                    builder.append("#");
                }
                System.out.println(builder.toString());
            }
            System.out.println();

        }
    }
}


Measured memory_bytes: 29212
#include<iostream>

using namespace std;

int main()
{
	int n,c=0;
	cin>>n;
	if (n>=195)
		c++;
	if (n>=189)
		c++;
	if (n>=165)
		c++;
	if (n>=135)
		c++;
	if (n>=105)
		c++;
	cout<<c<<endl;
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
using namespace std;
#include <vector>
#include <algorithm>
int b[10];
int main()
{
	int n;
	int a;
	int cnt = 0,cnt1 = 0;
	cin>>n;
	for(int i = 0;i<n;i++ )
	{
		cin>>a;
		if(a>=1&&a<=399)b[1]++;
		if(a>=400&&a<=799)b[2]++;
		if(a>=800&&a<=1199)b[3]++;
		if(a>=1200&&a<=1599)b[4]++;
		if(a>=1600&&a<=1999)b[5]++;
		if(a>=2000&&a<=2399)b[6]++;
		if(a>=2400&&a<=2799)b[7]++;
		if(a>=2800&&a<=3199)b[8]++;
		if(a>=3200)cnt++;
	}
	for(int i=0;i<10;i++)
	{
		if(b[i])cnt1++;
	}
//	if(cnt1==0)
//	{
//		cout<<1<<" ";
//		if(cnt>=8)cnt = 8;
//		cout<<cnt<<endl;
//	}
//	else
//	{
//		cout<<cnt1<<" ";
//		cnt1+=cnt;
//		if(cnt1>=8)cnt1 = 8;
//		cout<<cnt1<<endl;
//	}
	if(cnt1 == 0)cout<<1<<" "<<cnt<<endl;
	else cout<<cnt1<<" "<<cnt1+cnt<<endl;
	return 0;
}

Measured memory_bytes: 384
import java.io.BufferedReader
import java.io.InputStreamReader
import java.io.PrintWriter
import kotlin.math.abs

val br = BufferedReader(InputStreamReader(System.`in`))
val out = PrintWriter(System.out)

fun main() {
    br.use { out.use {
        solve()
        out.flush()
    } }
}

fun solve() {
    val n = readInteger()
    val aList = listOf(0L) + readLongList() + 0L
    val aSums = LongArray(n + 2)
    for (i in 0 until (n + 1)) {
        aSums[i + 1] = aSums[i] + abs(aList[i + 1] - aList[i])
    }
    for (i in 1..n) {
        val ans = aSums[i - 1] + abs(aList[i - 1] - aList[i + 1]) + (aSums.last() - aSums[i + 1])
        out.println(ans)
    }
}

fun readInteger() = Integer.parseInt(br.readLine())
fun readLong() = java.lang.Long.parseLong(br.readLine())
fun readStringList() = br.readLine()!!.split(' ')
fun readIntegerList() = readStringList().map(Integer::parseInt)
fun readLongList() = readStringList().map(java.lang.Long::parseLong)
fun readDoubleList() = readStringList().map(java.lang.Double::parseDouble)


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

int main() {
	long long n, a, b;
	long long ta[100000];
	long long hirou = 0;
	string str;
	cin >> n >> a >> b;
	for (long long i = 0; i < n; i++) {
		cin >> ta[i];
	}
	for (long long i = 0; i < n - 1; i++) {
		if ((ta[i + 1] - ta[i])*a < b) {
			hirou = hirou + (ta[i + 1] - ta[i])*a;
		}
		else
		{
			hirou = hirou + b;
		}
	}
	cout << hirou << endl;
	return 0;
}

Measured memory_bytes: 1024
#include<cstdio>
#include<algorithm>
using namespace std;
const int MAXN = 50;
int x[MAXN + 5];
long long dp[MAXN + 5][MAXN + 5][MAXN*MAXN + 5];
int main() {
	int N, A;
	scanf("%d%d", &N, &A);
	for(int i=1;i<=N;i++)
		scanf("%d", &x[i]);
	long long ans = 0;
	for(int i=1;i<=N+1;i++)
		dp[i][0][0] = 1;
	for(int i=1;i<=N;i++) {
		for(int j=0;j<=N*A;j++) {
			for(int k=N-i+1;k>=1;k--) {
				dp[k][i][j] = dp[k+1][i][j];
				if( j >= x[k] )
					dp[k][i][j] += dp[k+1][i-1][j-x[k]];
			}
		}
		ans += dp[1][i][i*A];
	}
	printf("%lld\n", ans);
}

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

int main(){
    int N;
    vector<int> A[1000];
    cin >> N;
    for(int i=0; i<N; i++){
        for(int j=0; j<N-1; j++){
            int a;
            cin >> a;
            a--;
            A[i].push_back(a);
        }
        reverse(A[i].begin(), A[i].end());
    }

    vector<int> day(N, 1e9);
    queue<vector<int>> que;
    for(int i=0; i<N; i++){
        int j = A[i].back();
        if(j > i && A[j].back() == i) que.push({i, j, 1});
    }
    while(que.size()){
        auto v = que.front(); que.pop();
        int i = v[0], j = v[1], d = v[2];
        for(int v : {i, j}){
            A[v].pop_back();
            if(A[v].size()){
                int x = A[v].back();
                if(A[x].back() == v){
                    que.push({x, v, d+1});
                }
            }else{
                day[v] = d;
            }
        }
    }
    int ans = *max_element(day.begin(), day.end());
    cout << (ans == 1e9 ? -1 : ans) << endl;
    return 0;
}


Measured memory_bytes: 4352
#include<stdio.h>

int main(void) {
int m,f,r;

while (1) {
scanf("%d %d %d", &m, &f, &r);
if (m == -1 && f == -1 && r == -1) break;
if (m == -1 || f == -1) printf("F\n");
else if (m+f >= 80) printf("A\n");
else if (m+f >= 65) printf("B\n");
else if (m+f >= 50) printf("C\n");
else if (m+f >= 30) {
if (r >= 50) printf("C\n");
else printf("D\n");
}
else printf("F\n");
}

return (0);
}

Measured memory_bytes: 584
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <queue>
#include <math.h>
#include <iomanip>
#include <map>
using namespace std;

int H, W;
int h, w;

int main() {
  cin >> H >> W;
  cin >> h >> w;

  cout << (H-h)*(W-w) << endl;

}


Measured memory_bytes: 256
N, K = map(int, input().split())
vA = list(map(int, input().split()))

# 累積和
vC = [0,]
for a in vA:
    vC.append(a + vC[-1])

# 部分列の和 (美しさ)
vB = []
for i in range(len(vC)):
    vB.extend([vC[i+j+1] - vC[i] for j in range(N-i)])

# 最上位bitが何桁目かを取得
blenB = max(vB).bit_length()

# K個に満たない上位bitは最終的に残らないので除去する
# 上からK個以上あるものを決めていく
x = 0
for i in reversed(range(blenB+1)):
    x_new = x + (1<<i)
    if sum((x_new & b) == x_new for b in vB) >= K:
        x = x_new

print(x)


Measured memory_bytes: 58788
#include<stdio.h>
int main()
{
char S[11],T[12];
scanf("%s",S);
scanf("%s",T);
for(int i=0;S[i]!='\0';i++){
if(S[i]!=T[i]){
printf("No");
return 0;
}
}
printf("Yes");
return 0;
}

Measured memory_bytes: 1712
t=input()
n=t.count("N")
w=t.count("W")
s=t.count("S")
e=t.count("E")
if ((n>=1 and s>=1 and w==0 and e==0) or (w>=1 and e>=1 and n==0 and s==0) or (n>=1 and s>=1 and w>=1 and e>=1)):
    print("Yes")
else:
    print("No")

Measured memory_bytes: 9024
#include <bits/stdc++.h>
using namespace std;
#define sim template < class c
#define ris return * this
#define dor > debug & operator <<
#define eni(x) sim > typename \
  enable_if<sizeof dud<c>(0) x 1, debug&>::type operator<<(c i) {
sim > struct rge { c b, e; };
sim > rge<c> range(c i, c j) { return rge<c>{i, j}; }
sim > auto dud(c* x) -> decltype(cerr << *x, 0);
sim > char dud(...);
struct debug {
#ifdef LOCAL
~debug() { cerr << endl; }
eni(!=) cerr << boolalpha << i; ris; }
eni(==) ris << range(begin(i), end(i)); }
sim, class b dor(pair < b, c > d) {
  ris << "(" << d.first << ", " << d.second << ")";
}
sim dor(rge<c> d) {
  *this << "[";
  for (auto it = d.b; it != d.e; ++it)
	*this << ", " + 2 * (it == d.b) << *it;
  ris << "]";
}
#else
sim dor(const c&) { ris; }
#endif
};
#define imie(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "

int r(int a, int b) {
	return a + rand() % (b - a + 1);
}

int brute(vector<int> a) {
	while((int) a.size() > 1) {
		vector<int> b;
		for(int i = 0; i < (int) a.size() - 1; ++i) {
			b.push_back(abs(a[i] - a[i+1]));
		}
		a = b;
	}
	return a[0];
}

void simulate_once() {
	int n = r(1, 50);
	vector<int> a;
	for(int i = 0; i < n; ++i) {
		a.push_back(r(1, 3));
	}
	debug() << imie(a);
	for(int rep = 0; n > 0; ++rep) {
		vector<int> b;
		for(int i = 0; i < n - 1; ++i) {
			b.push_back(abs(a[i] - a[i+1]));
		}
		a = b;
		n--;
		debug() << imie(b);
	}
	debug();
	for(int i = 1; i <= n - 2; ++i) {
		assert(a[i] == 0 || a[i] == 1);   // 0000000000000000000000000002
	}
	// for(int x : a) {
		// assert(x == 0 || x == 1);
	// }
	debug();
	debug();
}

int parity_binomial_coeff(int a, int b) {
	// a! / (b! (a-b)!)
	for(int bit = 0; bit < 20; ++bit) {
		if(!(a & (1 << bit)) && (b & (1 << bit))) {
			return 0;
		}
	}
	return 1; // Lucas theorem
}

int odd_answer(vector<int> a) {
	int n = a.size();
	int answer = 0;
	for(int i = 0; i < n; ++i) {
		if(a[i] % 2 == 1 && parity_binomial_coeff(n - 1, i)) {
			answer ^= 1;
		}
	}
	return answer;
}

int main() {
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	
	int n;
	cin >> n;
	string s;
	cin >> s;
	vector<int> a(n);
	for(int i = 0; i < n; ++i) {
		a[i] = s[i] - '0';
	}
	
	// one iteration
	for(int i = 0; i < n - 1; ++i) {
		a[i] = abs(a[i] - a[i+1]);
	}
	a.pop_back();
	n--;
	
	if(odd_answer(a)) {
		cout << 1 << endl;
		return 0;
	}
	for(int elem : a) {
		if(elem == 1) {
			cout << 0 << endl;
			return 0;
		}
	}
	for(int& elem : a) {
		assert(elem == 0 || elem == 2);
		elem /= 2;
	}
	if(odd_answer(a)) {
		cout << 2 << endl;
	}
	else {
		cout << 0 << endl;
	}
}

// 1231  N <= 200'000   O(N^2) too slow
// 112
// 01
// 1 <- print this final number


Measured memory_bytes: 9116
#include <iostream>
#include <algorithm>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <string>
#include <sstream>
#include <map>
#include <set>
#include <vector>
#include <cmath>
#include <queue>
#include <random>

using namespace std;

#define min(a,b) ((a)<(b) ? (a):(b))
#define max(a,b) ((a)>(b) ? (a):(b))

int gcd(int a, int b){
    while( b ){
        int m = a % b;
        a = b;
        b = m;
    }
    return a;
}

int lcm(int a, int  b){
    return (a*b)/gcd(a,b);
}

int isPrim(int a){
    if(a==1){
        return 0;
    }
    for(int i=2;i<=(a+1)/2;i++){
        if(a%i==0){
            return 0;
        }
    }
    return 1;
}

long long mod_pow(long long x, long long n, long long mod){
    //xのn乗を計算するのにn乗を2進表記にして計算
    //x^22 = x^16 + x^4 + x^2
    long long ret=1;
    while(n>0){
        if(n%2==1){
            ret=(ret*x)%mod;//答えに付加
        }
        x=(x*x)%mod;//2乗
        n=n/2;
    }
    return ret;
}

struct VV{
    int x;
    int y;
    int z;
};

class LessInt {
public:
    bool operator()(const VV& riLeft, const VV& riRight) const {
        if(riLeft.x == riRight.x){
            return riLeft.y > riRight.y;
        }
        return riLeft.x > riRight.x;
        
    }
};

class indInt {
public:
    bool operator()(const VV& riLeft, const VV& riRight) const {
        return riLeft.x < riRight.x;
        
    }
};

struct XX{
    string a;
    int b;
    string c;
};

class xxIntu {
public:
    bool operator()(const XX& riLeft, const XX& riRight) const {
        //第1条件
        if(riLeft.a != riRight.a){
            return riLeft.a > riRight.a;//<:昇順(小さい順)、>:降順(大きい順)
        }
        //第2条件
        return riLeft.b > riRight.b;
    }
};
bool operator< (const XX &riLeft, const XX &riRight){
    return riLeft.a < riRight.a;
};
bool operator> (const XX &riLeft, const XX &riRight){
    return riLeft.a > riRight.a;
};


int main(int argc, const char * argv[])
{
    //std::ios::sync_with_stdio(false);
    //scanf("%s",S);
    //scanf("%d",&N);
    //getline(cin, target);
    //cin >> x >> y;
    //ここから
    
    int a,b;
    cin >> a >> b;
    string ans;
    int tmp=1;
    
    if(a<0){
        if(abs(a)%2==0){
            tmp=1;
        }else{
            tmp=-1;
        }
    }
    if(b<0){
        if(abs(b-a)%2==0){
            tmp=-1;
        }else{
            tmp=1;
        }
    }
    if(a==0 || b==0){
        tmp=0;
    }else if(a<0 && b>0){
        tmp=0;
    }
    
    if(tmp==0){
        ans="Zero";
    }else if(tmp>0){
        ans="Positive";
    }else{
        ans="Negative";
    }
    
    
    cout << ans << endl;
    
    
    
    //ここまで
    //cout << "ans" << endl;改行含む
    //printf("%.0f\n",ans);//小数点以下表示なし
    //printf("%.7f\n",p);
    //printf("%f\n",pow(2,ans.size()));
    
    return 0;
}

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

int cmp(const void *a, const void *b)
{ return *(int *)b - *(int *)a ;}

int if_tri(int a,int b, int c)
{
  if(a+b>c && b+c>a && c+a>b)
    return 1;
  else
    return 0;
}

int main()
{
  int n,i,j,k,count=0;
  int *l;

  scanf("%d", &n);
  l = calloc(n,sizeof(int));

  for(i=0; i<n; i++)
    scanf("%d",&l[i]);

  qsort(l,n,sizeof(int),cmp);

  for(i=0; i<n-2; i++){
    for(k=i+1; k<n-1; k++){
      for(j=k+1; j<n; j++){
        if(if_tri(l[i],l[k],l[j]))
        count++;
      }
    }
  }

  printf("%d", count);
  free(l);
  return 0;
}


Measured memory_bytes: 1708
#include <bits/stdc++.h>
#define fi first
#define se second
#define mp make_pair
using namespace std;

typedef pair <int, int> pii;

int p, r, t;
int l[310], nl[310];
int n[310][310], nn[310][310];
pii a[200010];
int cnt[310];

bool check(int mid){
	for (int i = 1; i <= r; i++){
		nl[i] = l[i];
	}
	for (int i = 1; i <= p; i++){
		cnt[i] = 0;
		for (int j = 1; j <= r; j++){
			nn[i][j] = n[i][j], cnt[i] += n[i][j];
		}
	}
	for (int i = 0; i <= mid; i++){
		int P = a[i].fi, R = a[i].se;
		nl[R]--, nn[P][R]--, cnt[P]--;
		if (cnt[P] == 0){
			for (int j = 1; j <= r; j++){
				nl[j] += n[P][j];
			}
		}
	}
	int pd = 1;
	while (pd){
		pd = 0;
		for (int i = 1; i <= p; i++){
			int flag = 1, ppp = 1;
			for (int j = 1; j <= r; j++){
				if (nl[j] < nn[i][j]){
					flag = 0;
					break;
				}
				if (nn[i][j]) ppp = 0;
			}
			if (!flag || ppp) continue;
			for (int j = 1; j <= r; j++){
				nl[j] += n[i][j] - nn[i][j];
				nn[i][j] = 0;
			}
			pd = 1;
		}
	}
	for (int i = 1; i <= p; i++){
		for (int j = 1; j <= r; j++){
			if (nn[i][j]) return 1;
		}
	}
	return 0;
}

int main(){
	scanf("%d%d%d", &p, &r, &t);
	for (int i = 1; i <= r; i++){
		scanf("%d", &l[i]);
	}
	for (int i = 1; i <= p; i++){
		for (int j = 1; j <= r; j++){
			scanf("%d", &n[i][j]);
		}
	}
	for (int i = 0; i < t; i++){
		scanf("%d%d", &a[i].fi, &a[i].se);
	}
	if (!check(t - 1)){
		printf("-1\n");
		return 0;
	}
	int l = 0, r = t - 1;
	while (l < r){
		int mid = l + r >> 1;
		if (!check(mid)) l = mid + 1;
		else r = mid;
	}
	printf("%d\n", l + 1);
	return 0;
}



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

typedef long long ll;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef pair<ll,ll> pll;
typedef vector<bool> vb;
const ll oo = 0x3f3f3f3f3f3f3f3f;
const double eps = 1e-9;
#define sz(c) ll((c).size())
#define all(c) begin(c), end(c)
#define FOR(i,a,b) for (ll i = (a); i < (b); i++)
#define FORD(i,a,b) for (ll i = (b)-1; i >= (a); i--)
#define mp make_pair
#define pb push_back
#define eb emplace_back
#define xx first
#define yy second
#define TR(X) ({ if(1) cerr << "TR: " << (#X) << " = " << (X) << endl; })

const ll MOD = 998244353;

int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	
	ll n, k;
	cin >> n >> k;
	vl a(k), b(k);
	FOR(i,0,k) cin >> a[i] >> b[i];


	vl dp(n), dpsum(n);
	dp[0] = 1;
	FOR(i,1,n) {
		dpsum[i] = (dpsum[i-1] + dp[i-1]) % MOD;

		FOR(j,0,k) {
			// i == 10, a[j] == 3, b[j] == 5
			// dp[5] + dp[6] + dp[7] == dpsum[8]-dpsum[5]
			//  == dpsum[i-a[j]+1] - dpsum[i-b[j]]
			ll hi = max(0LL, i-a[j]+1), lo = max(0LL, i-b[j]);
			dp[i] += dpsum[hi] - dpsum[lo];
		}
		dp[i] %= MOD;
	}
	
	ll res = dp[n-1];
	if (res < 0) res += MOD;
	cout << res << endl;

}



Measured memory_bytes: 6360
#include <iostream>
#include <climits>
#include <bitset>
#include <stack>
#include <queue>
#include <iomanip>
#include <limits>
#include <string>
#include <cmath>
#include <set>
#include <map>
#include <math.h>
#include <algorithm>
#include <vector>
#include <string.h>
 
using namespace std;
typedef long long ll;
 
 
typedef pair<ll,ll> P;
long long int INF = 1e18;
double Pi = 3.141592653589;
const int mod = 1000000007;
// memset(a,0,sizeof(a)); →全部０にする
 
vector<ll> G[100005];
std::vector<P> tree[100010];
 
int dx[8]={1,0,-1,0,1,1,-1,-1};
int dy[8]={0,1,0,-1,1,-1,-1,1};
 
#define p(x) cout<<x<<endl;
#define el cout<<endl;
#define pe(x) cout<<x<<" ";
#define re(i,a,b) for(i=a;i<=b;i++);
#define pb push_back
#define lb lower_bound
#define ub upper_bound
 
ll i,j,k,ii,jj;
ll n,m,sum,num;
ll a,b,c,d,e,ans[500005];
ll x[500005],y[500005],z[100005];
ll dp[100],ma,mi;
char s[100005];

int main(){
	cin>>n;
	for(i=0;i<n;i++){
		cin>>x[i];
	}
	sort(x,x+n);
	p(x[n-1]-x[0]);
	return 0;

}

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

int main()
{
	int n,k;
    cin >> n>> k;
    
    bool is[n];
    memset(is,false,sizeof(is));
    
    while(k--)
    {
        int d;
        cin >> d;
        
        int arr[d];
        for(int i=0;i<d;i++)
        {
            cin >> arr[i];
            
            is[arr[i]-1]=true;
        }
    }
    
    int f=0;
    for(int i=0;i<n;i++)
    {
        if(is[i]==false)
        {
            f++;
        }
    }
    
    cout << f << endl;
	return 0;
}

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

using namespace std;

int main() {
  int n;
  cin >> n;
  int cnt = 0;
  for (int i = 1; i < n; ++i) {
    int b = n / i;
    int c = n - i * b;
    if (n % i == 0) cnt += b - 1;
    else cnt += b;
  }
  cout << cnt << '\n';
  return 0;
}



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

int h, w, k;

int solve(int x, int y, vector<vector<char>> field) {
  if (y == h) {
    int count = 0;
    rep(i, w) rep(j, h) {
      if (field[i][j] == '#') count++;
    }
    return count == k ? 1 : 0;
  }
  if (x == w) {
    int tmp = solve(x, y + 1, field);
    rep(i, w) field[i][y] = 'r';
    return tmp + solve(x, y + 1, field);
  }
  int tmp = solve(x + 1, y, field);
  rep(i, h) field[x][i] = 'r';
  return tmp + solve(x + 1, y, field);
}

int main() {
  cin >> h >> w >> k;
  vector<vector<char>> field(w, vector<char>(h));
  rep(y, h) rep(x, w) cin >> field[x][y];
  cout << solve(0, 0, field) << endl;
  return 0;
}

Measured memory_bytes: 3608
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Scanner;

public class Main {

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

	void run() {
		Scanner sc = new Scanner(System.in);

		int N = sc.nextInt();

		Map<Integer,Integer> map=new HashMap<Integer,Integer>();

		for (int i = 0; i < N; i++) {

			int buf = sc.nextInt();

			if(map.containsKey(buf)) {
				map.put(buf,map.get(buf)+1);
			}else {
				map.put(buf,1);
			}

		}

		int ans = 0;


		for(Entry<Integer,Integer> E:map.entrySet()) {

			int num=E.getKey();
			int x=E.getValue();

			if(num<=x) {
				ans+=x-num;
			}else {
				ans+=x;
			}

		}

		System.out.println(ans);

	}

	//以下テンプレート

	public static String numtoalpha(int i) {

		String alpha = "abcdefghijklmnopqrstuvwxyz";

		return alpha.substring(i, i + 1);

	}

	public static int[] extgcd(int a, int b) {

		int x0 = 1;
		int x1 = 0;

		int y0 = 0;
		int y1 = 1;

		while (b != 0) {
			int q = a / b;
			int r = a % b;

			int x2 = x0 - q * x1;
			int y2 = y0 - q * y1;

			a = b;
			b = r;

			x0 = x1;
			x1 = x2;

			y0 = y1;
			y1 = y2;
		}

		return new int[] { a, x0, y0 };

	}

	static int gcd(int a, int b) {

		if (b == 0)
			return a;

		if (a < b) {
			int t = a;
			a = b;
			b = t;
		}

		return gcd(b, a % b);

	}

	static int lcm(int a, int b) {
		return a * b / gcd(a, b);
	}

	static void swap(int[] a) {
		int t;

		t = a[0];
		a[0] = a[1];
		a[1] = t;

		return;
	}

	static <T> void output(List<T> list) {

		for (int i = 0; i < list.size(); i++) {
			System.out.print(list.get(i));

			if (i != list.size() - 1) {
				System.out.print(" ");
			} else {
				nl();
			}
		}

	}

	static void output(String[][] str) {

		for (int i = 0; i < str.length; i++) {
			for (int j = 0; j < str[i].length; j++) {
				print(str[i][j]);
			}

			nl();
		}

	}

	static void output(boolean flg, String Yes, String No) {

		if (flg) {
			pln(Yes);
		} else {
			pln(No);
		}

	}

	static void output(String[][] str, int digit) {

		String dig = "%" + String.valueOf(digit) + "s";

		for (int i = 0; i < str.length; i++) {
			for (int j = 0; j < str[i].length; j++) {
				System.out.printf(dig, str[i][j]);
			}
			nl();
		}

	}

	static void pln(String str) {
		System.out.println(str);
	}

	static void pln(int x) {
		System.out.println(x);
	}

	static void print(String str) {
		System.out.print(str);
	}

	static void print(int x) {
		System.out.print(x);
	}

	static void print(String str, int times) {
		for (int i = 0; i < times; i++) {
			print(str);
		}
	}

	static void print(int x, int times) {
		for (int i = 0; i < times; i++) {
			print(x);
		}
	}

	static void nl() {
		System.out.println();
	}

}


Measured memory_bytes: 62012
import java.util.Scanner;


class Main {

	public static void main(String[] args) {
	
		Scanner sc = new Scanner(System.in);
		
		int a = sc.nextInt();
		int b = sc.nextInt();
		
		if(1 <= a && b <= 10 * 10 * 10 * 10 * 10 * 10 * 10 * 10 * 10){
			int d = a / b;
			int r = a % b;
			
			double A = (int)a;
			double B = (int)b;

			double f = A / B;
			
			String F = String.format("%.5f", f);
			
			System.out.println(d + " " + r + " " + F );
		}
	}

}

Measured memory_bytes: 26524
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
const ll MOD = 1e9 + 7;
const ll INF = LLONG_MAX;

ull f(ull a)
{
    ull ans[] = {a, 1, a + 1, 0};
    return ans[a % 4];
}

ull Xor(ull a, ull b)
{
    return f(b) ^ f(a - 1);
}
int main()
{
    ull a, b;
    cin >> a >> b;
    ull ans = Xor(a, b);
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <set>
#include <map>
#include <queue>
#include <assert.h>
#include <numeric>
#include <math.h>
#include <climits>
#include <stack>
#include <iomanip>
#include <sstream>

using namespace std;

template <typename T>
inline bool sign(T A) {
    return (A>0)-(A<0);
}
#define REP(i, n) for (int i = 0; i < (n); ++i)
#define SREP(i,s,n) for(int i=s; (n-i)*sign(n-s)>0; i+=sign(n-s))
#define all(x) (x).begin(),(x).end()
typedef long long ll;
typedef unsigned long long ull;

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

bool _less(pair<int, int> a, pair<int, int> b) {
    return a.second < b.second;
}

template <template<class,class,class...> class C, typename K, typename V, typename... Args>
V map_get(const C<K,V,Args...>& m, K const& key, const V & defval)
{
    typename C<K,V,Args...>::const_iterator it = m.find( key );
    if (it == m.end())
        return defval;
    return it->second;
}

#define MOD (1'000'000'000 + 7)



int main(void)
{
    ll N;
    cin >> N;
    vector<ll> D(N);
    REP(i, N) {
        cin >> D[i];
    }
    sort(D.begin(), D.end());
    vector<ll> cl;
    cl.push_back(0);
    REP(i, N){
        if (i%2) {
            cl.push_back(24 - D[i]);
        } else {
            cl.push_back(D[i]);
        }
    }

    ll m = 24;
    REP(i, cl.size()) {
        REP(j, cl.size())
        {
            if (i!=j) {
                ll a = max(cl[i], cl[j]) - min(cl[i], cl[j]);
                m = min(m, min(a, 24-a));
            }
        }
    }
    cout << m << endl;
}


Measured memory_bytes: 256
#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;

#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define fbo find_by_order
#define ook order_of_key

typedef long long ll;
typedef pair<int,int> ii;
typedef vector<int> vi;
typedef long double ld; 
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> pbds;
typedef set<int>::iterator sit;
typedef map<int,int>::iterator mit;
typedef vector<int>::iterator vit;

ll a[300001];

ll dpmax[300001];
ll dpmin[300001];

int main()
{
	ios_base::sync_with_stdio(0); cin.tie(0);
	int n; cin>>n;
	for(int i=0;i<n*3;i++)
	{
		cin>>a[i];
	}
	priority_queue<ll,vector<ll>,greater<ll> > pq;
	ll sum = 0;
	for(int i = 0; i < n; i++)
	{
		pq.push(a[i]);
		sum+=a[i];
	}
	dpmax[n-1] = sum;
	for(int i = n; i < 2*n; i++)
	{
		ll tmp = pq.top();
		if(a[i]>tmp)
		{
			pq.pop();
			sum-=tmp;
			sum+=a[i];
			pq.push(a[i]);
		}
		dpmax[i] = max(dpmax[i-1],sum);
	}
	sum = 0;
	priority_queue<ll,vector<ll>,less<ll> > pq2;
	for(int i=3*n-1;i>=2*n;i--)
	{
		pq2.push(a[i]);
		sum+=a[i];
	}
	dpmin[2*n] = sum;
	for(int i = 2*n-1;i>=n;i--)
	{
		ll tmp = pq2.top();
		if(a[i]<tmp)
		{
			pq2.pop();
			sum-=tmp;
			sum+=a[i];
			pq2.push(a[i]);
		}
		dpmin[i] = min(dpmin[i+1],sum);
	}
	ll ans = -ll(1e18);
	for(int i = n - 1; i < 2*n; i++)
	{
		//cerr<<i<<' '<<dpmax[i]<<' '<<dpmin[i+1]<<'\n';
		ans=max(ans,dpmax[i]-dpmin[i+1]);
	}
	cout<<ans<<'\n';
}


Measured memory_bytes: 7796
N, K = list(map(int, input().split()))
hList = list(map(int, input().split()))

dp = [float("inf")] * N
dp[0] = 0
for i in range(N):
    for j in range(1, K + 1):
        if j > i:
            break
        dp[i] = min(dp[i - j] + abs(hList[i] - hList[i - j]), dp[i])

print(dp[N - 1])


Measured memory_bytes: 55136
#include <iostream>
#include <algorithm>
#include <vector>
using namespace std;
int temp[101];
int main() {
	int n; cin >> n;
	string s; cin >> s;
	if ((n & 1)){
		cout << "No";
	return 0;
}
	int div = n / 2;
	string l, r;
	for (int i = 0; i < div; i++) {
		l += s[i];
	}
	for (int i = div; i < n; i++) {
		r += s[i];
	}
	if (r == l)
		cout << "Yes" << endl;
	else
		cout << "No" << endl;

	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
  using namespace std;
  #define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
  #define endl "\n"
  #define ll long long
  #define int long long
  #define double long double
  #define max(a,b) (a>b?a:b)
  #define min(a,b) (a<b?a:b)
  #define mp make_pair
  #define pb push_back
  #define inf INT_MAX
  #define f first
  #define s second
  #define trace1(x)                cerr<<#x<<": "<<x<<endl
  #define trace2(x, y)             cerr<<#x<<": "<<x<<" | "<<#y<<": "<<y<<endl
  #define trace3(x, y, z)          cerr<<#x<<":" <<x<<" | "<<#y<<": "<<y<<" | "<<#z<<": "<<z<<endl
  #define trace4(a, b, c, d)       cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<endl
  #define trace5(a, b, c, d, e)    cerr<<#a<<": "<<a<<" | "<<#b<< ": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<" | "<<#e<< ": "<<e<<endl
  #define trace6(a, b, c, d, e, f) cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<" | "<<#e<< ": "<<e<<" | "<<#f<<": "<<f<<endl
  #define cases int testcases;cin>>testcases; while(testcases--)
  #define all(v) v.begin(), v.end()
  #define mod INT_MAX 
  const int MOD=1e9+7;
  const int N=2e5+2;

  int32_t main()
  {
    /*#ifndef ONLINE_JUDGE
       freopen("in.txt","r",stdin);
       freopen("out.txt","w",stdout);
    #endif*/
       IOS
       int n,x=0;
       cin>>n;
       vector<int> v(n);
       
       for(int i=0;i<n;i++)
       {
         cin>>v[i];
         x=x^v[i];
       }
       for(int i=0;i<n;i++)
       {
        int y=x^v[i];
        cout<<y<<" ";
       }
       
       return 0;
      }

Measured memory_bytes: 4768
#include <bits/stdc++.h>
#define int long long
#define ll long long
#define vec vector
#define vi vec<int>
#define vvi vec<vec<int>>
#define ALL(a) begin(a), end(a)
#define RALL(a) rbegin(a), rend(a)
#define SORT(a) stable_sort(ALL(a))
#define RSORT(a) stable_sort(RALL(a))
#define REV(a) reverse(ALL(a))
#define UNIQUE(a) a.erase(unique(ALL(a)), end(a))
#define lambda(i) [=](auto i)
#define compare(i, j) [=](auto i, auto j)
#define min_of(a) *min_element(ALL(a))
#define max_of(a) *max_element(ALL(a))
#define sum(a) accumulate(ALL(a), 0)
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define SZ(a) (int)(a).size()
#define REP(i, n) for (decltype(+n) i = 0; i < (n); i++)
#define RREP(i, n) for (auto i = n - 1; i != static_cast<decltype(i)>(-1); i--)
#define FOR(i, a, b) for (auto i = (a); i < (b); i++)
#define RFOR(i, a, b) for (auto i = b - 1; i != a; i--)
#define EACH(i, a) for (auto&& i: (a))
using namespace std;

const int INF = 1e18;
const int MOD = 1e9 + 7;

int ceil_div(int X, int Y) {
  return (X - 1) / Y + 1;
}

struct union_find {
  vi data;
  union_find(int size) : data(size, -1) { }
  bool union_set(int x, int y) {
    x = root(x); y = root(y);
    if (x != y) {
      if (data[y] < data[x]) swap(x, y);
      data[x] += data[y]; data[y] = x;
    }
    return x != y;
  }
  bool find_set(int x, int y) {
    return root(x) == root(y);
  }
  int root(int x) {
    return data[x] < 0 ? x : data[x] = root(data[x]);
  }
  int size(int x) {
    return -data[root(x)];
  }
};

vi cum(vi V) {
  vi U(SZ(V));
  partial_sum(ALL(V), begin(U));
  return U;
}

void solve() {
  int n;
  int ans = 0;

  cin >> n;
  string s = to_string(n);

  cout << (s[0] == '7' || s[1] == '7' || s[2] == '7' ? "Yes" : "No") << endl;
  // REP(i, n) {
  //   cout << v[i];
  // }
}

signed main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout << fixed << setprecision(15);
  solve();
}


Measured memory_bytes: 3680
#include <iostream>
#include <cmath>
using namespace std;
int main()
{
    int a,b,c;
    cin>>a>>b;
    c=a+b;
    if(a%3==0||b%3==0||c%3==0)
        cout<<"Possible";
    else
        cout<<"Impossible";




    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define pb push_back
#define rint register int
#define endl '\n'
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;

const int maxn=1e5+10;
const int inf=0x3f3f3f3f;

int n,m;
double ans;

int main(){
	scanf("%d%d",&n,&m);
	for(rint i=1;i<=n;++i){
		double tmp=1.0/n;
		int cnt=i;
		while(cnt<m) cnt*=2,tmp/=2.0;
		ans+=tmp;
	}
	printf("%.12lf",ans);
}

Measured memory_bytes: 256
#include <iostream>
#include <stdio.h>
#include <fstream>
#include <algorithm>
#include <string>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <vector>
#include <limits.h>
#include <math.h>
#include <functional>
#include <bitset>

#define repeat(i,n) for (long long i = 0; (i) < (n); ++ (i))
#define debug(x) cerr << #x << ": " << x << '\n'
#define debugArray(x,n) for(long long i = 0; (i) < (n); ++ (i)) cerr << #x << "[" << i << "]: " << x[i] << '\n'
#define debugArrayP(x,n) for(long long i = 0; (i) < (n); ++ (i)) cerr << #x << "[" << i << "]: " << x[i].first<< " " << x[i].second << '\n'

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> Pii;
typedef vector<int> vint;
typedef vector<ll> vll;
const ull INF = ULLONG_MAX;
const ll MOD = 998244353;


int main(){
  int N;ull X;cin>>N>>X;
  vector<ull> sumx(N+1,0);
  repeat(i,N){
    ll x;cin>>x;
    sumx[i+1]=sumx[i]+x;
  }
  //debugArray(sumx,N+1);
  ull ans = INF;
  for(int k=1;k<=N;k++){
    ull a=0;
    for(int j=1;(j-1)*k<N;j++){
      a += (sumx[N-(j-1)*k]-sumx[max(0,N-j*k)])*(j==1? 5:(2*j+1));
    }
    a += X*(N+k);
    ans = min(ans,a);
    //debug(ans);
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 1792
import bisect,collections,copy,heapq,itertools,math,string
import sys
def S(): return sys.stdin.readline().rstrip()
def M(): return map(int,sys.stdin.readline().rstrip().split())
def I(): return int(sys.stdin.readline().rstrip())
def LI(): return list(map(int,sys.stdin.readline().rstrip().split()))
def LS(): return list(sys.stdin.readline().rstrip().split())
n, x, t = M()
print(math.ceil(n/x)*t)

Measured memory_bytes: 74580
import sys

read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline

in_n = lambda: int(readline())
in_nn = lambda: map(int, readline().split())
in_nl = lambda: list(map(int, readline().split()))
in_na = lambda: map(int, read().split())
in_s = lambda: readline().rstrip().decode('utf-8')


def main():

    N = in_n()
    t = in_na()
    xyh = list(zip(t, t, t))

    for cx in range(101):
        for cy in range(101):
            hmax = 10**9 + 7
            pred_h = -1
            for i in range(N):
                x, y, h = xyh[i]
                xy = abs(x - cx) + abs(y - cy)
                if h == 0:
                    hmax = min(hmax, xy)
                    if pred_h > hmax:
                        break
                else:
                    if pred_h == -1:
                        pred_h = h + xy
                    elif pred_h != h + xy:
                        break
            else:
                print(cx, cy, pred_h)
                exit()


if __name__ == '__main__':
    main()


Measured memory_bytes: 9200