akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(n);++i)
#define rrep(i,n) for(int i=1;i<(n);++i)
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
#define maxs(a, b) a = max(a, b)
#define mins(a, b) a = min(a, b)
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
const ll linf = (1ll << 61);
const int inf = 1001001001;
const int mod = 1000000007;

int main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	int n;
	cin >> n;
	vector<int> cnt(n + 1, 0);
	for (int x = 1; x <= 100; ++x) {
		for (int y = 1; y <= 100; ++y) {
			for (int z = 1; z <= 100; ++z) {
				int tmp = x * x + y * y + z * z + z * x + y * z + x * y;
				if(tmp <= n) cnt[tmp]++;
			}
		}
	}
	for (int i = 1; i <= n; ++i) {
		cout << cnt[i] << endl;
	}
	return 0;
}

Measured memory_bytes: 3608
#include <bits/stdc++.h>
using ll = long long;
constexpr int MOD = 1000000007;
using namespace std;

int main() {
  int n;
  cin >> n;
  vector<int> x, y;
  for (int i = 0; i < n; i++) {
    int xi, yi;
    cin >> xi >> yi;
    x.push_back(xi);
    y.push_back(yi);
  }
  
  double total = 0;
  for (int i = 0; i < n - 1; i++) {
    for (int j = i + 1; j < n; j++) {
      double dist = sqrt((x[i]-x[j])*(x[i]-x[j]) + (y[i]-y[j])*(y[i]-y[j]));
      dist *= 2.0 / n;
      total += dist;
    }
  }
  cout << setprecision(12) << total << endl;
  return 0;
}

Measured memory_bytes: 256
#![allow(
    non_snake_case,
    unused_variables,
    unused_assignments,
    unused_mut,
    dead_code
)]
use proconio::input;
//use proconio::marker::Usize1;
//use proconio::marker::Chars;
//use std::collections::HashSet;
//use std::cmp::*;
fn main() {
    input! {
        K: i32,A:i32,B:i32
    }
    for i in 1..1001 {
        if A <= K * i && K * i <= B {
            println!("OK");
            return;
        }
    }
    println!("NG");
}


Measured memory_bytes: 2136
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> PLL;
typedef vector<int> VI;
typedef vector<char> VC;
typedef vector<double> VD;
typedef vector<double> VL;
typedef vector<string> VS;
typedef vector<PLL> VP;
typedef vector<ll> VLL;
const static int INF = 1000000000;
const static int MOD = 1000000007;
#define rep(i,n) for (ll i=0; i<(ll)(n); i++)
#define repd(i,n) for (ll i=n-1; i>=0; i--)
#define rept(i,m,n) for(ll i=m; i<n; i++)
#define stl_rep(itr, x) for (auto itr = x.begin(); itr != x.end(); ++itr)
#define all(x) (x).begin(), (x).end()
#define F first
#define S second
#define PF push_front
#define PB push_back
#define SORT(V) sort((V).begin(), (V).end())
#define RVERSE(V) reverse((V).begin(), (V).end())
#define paired make_pair
#define PRINT(V) for(auto v : (V)) cout << v << " "
//charを整数に
int ctoi(char c) { if (c >= '0' && c <= '9') { return c - '0'; } return 0; }
// 累積和 for (int i = 0; i < N; ++i) s[i+1] = s[i] + a[i]; 
void cum_sum(int N,vector<double> a, vector<double> &s){ for(int i=0; i<N; i++){ s[i+1]=s[i]+a[i];}}
//ユークリッドの控除法
ll gcd(ll a,ll b){
    if(b == 0) return a;
    return gcd(b,a%b);
}
//最小公倍数
ll lcm(ll a,ll b){
    ll g = gcd(a,b);
    return a / g * b; // Be careful not to overflow
}
//空白文字も入力 getline(cin, S);
//桁数指定 setprecision

int main()
{
    int N,M,X;
    cin >> N >> M >> X;
    VI C(N);
    vector<vector<int>> A(N, vector<int>(M));
    rep(i,N){
        cin >> C[i];
        rep(j,M){
            cin >> A[i][j];
        }
    }
    bool end=true;
    int money=1000000000;
    VI judge(M);
    for(int i=0; i<(1<<N); i++){
        int max=0;
        rep(j,N){
            if((i>>j)&1){
                rep(k,M){
                    judge[k]+=A[j][k];
                }
                max+=C[j];
            }
        }
        rep(i,M){
            if(judge[i]<X){
                end=false;
            }
        }
        if(end){
            if(money>max){
                money=max;
            }
        }
        end=true;
        rep(i,M){
            judge[i]=0;
        }
    }
    if(money==INF){
        cout << -1 << endl;
    }
    else{
        cout << money << endl;
    }
}




Measured memory_bytes: 3620
#include "bits/stdc++.h"
using namespace std;

#define input_from_file freopen("input.txt","r",stdin)
#define output_to_file freopen("output.txt" , "w",stdout)
#define fastio ios_base::sync_with_stdio(0)
#define endl '\n'

const int N = 1e5 + 1 ; 
int in[N];
int dp[N];

int main()
{
     #ifdef LOCAL
        input_from_file;
        output_to_file;
    #endif
    fastio;cin.tie(0);cout.tie(0);
    int n , k ; cin >> n >> k;
    for(int i = 1 ; i <= n ; ++i)
        cin >> in[i];
    dp[2] = abs(in[1] - in[2]);
    int j , m ;
    for(int i = 3 ; i <= n ; ++i)
    {
        j = i - 1 , m = INT_MAX;
        while(j >= 1 && j >= i - k)
        {
            m = min(dp[j]+ abs(in[i] - in[j]) , m);
            --j;
        }
        dp[i] = m;
    }
    cout << dp[n];

    return 0;
}

Measured memory_bytes: 1024
/*
String[]の初期化、整数の型がlongになっているか
関数（splitとかcontainsとか）内では"+"とかは正規表現となされるので"\\+"とする
配列のコピーはarr1=arr.clone()
HashSet<>[]はおのおの初期化した？？？？？
負の数の割り算は絶対値が小さいほうに切り捨てられるex.-1/2=0ので、ある値>kみたいな式だとバグらせやすいので注意
ある値>=kとして、切り上げた値をとるべき
toLowerCase()はアルファベット以外に対して行ってもエラーにはならない
ArrayDequeではpopとpushはStackと同じ操作になる
*/
//入力終了→Ctrl+D
import java.util.*;
import java.awt.*;
import java.awt.geom.Point2D;
import static java.lang.System.*;
import static java.lang.Math.*;
public class Main {
    public static void main(String[] $) {
        Scanner sc = new Scanner(in);
        int n=sc.nextInt(),m=sc.nextInt();
        Point[] p=new Point[n];
        for (int i = 0; i < n; i++) {
            int a=sc.nextInt(),b=sc.nextInt();
            p[i]=new Point(a,b);
        }
        Arrays.sort(p,(p1,p2)->p1.x-p2.x);
        int t=0;
        long ans=0;
        int i=0;
        while (t<m){
            t+=p[i].y;
            ans+=(long)p[i].x*(long)p[i].y;
            i++;
        }
        i--;
        if(t>m){
            ans-=(long) p[i].x*(long) (t-m);
        }
        out.println(ans);
    }
}

Measured memory_bytes: 91176
#include <bits/stdc++.h>
typedef long long ll;
typedef long double ld;
const int INF=1e9,MOD=1e9+7,ohara=1e6+10;
const ll LINF=1e18;
using namespace std;

#define rep(i,n) for(int (i)=0;(i)<(int)(n);(i)++)
#define rrep(i,a,b) for(int i=(a);i<(b);i++)
#define rrrep(i,a,b) for(int i=(a);i>=(b);i--)
#define all(v) (v).begin(), (v).end()
#define Size(n) (n).size()
#define Cout(x) cout<<(x)<<endl
#define Cerr(x) cerr<<(x)<<endl
#define fi first
#define se second

ll n,cnt,ans,a[ohara],b,c,d,tmp,tmpp,m,h,w,x,y,sum,pos,k,dp[ohara];
ld doua;
int dy[]={1,0,-1,0};
int dx[]={0,1,0,-1};
//int dy[]={-1,0,1,-1,1,-1,0,1};
//int dx[]={-1,-1,-1,0,0,1,1,1};
string alph("abcdefghijklmnopqrstuvwxyz"),s;
bool fl;
struct edge{int to,cost;};
vector<ll> g[ohara];
ll out[ohara];

//-------------------------↓↓↓↓↓↓------------------------

void dfs(ll now){
    rep(i,Size(g[now])){
        dfs(g[now][i]);
    }
    vector<ll> chi;
    rep(i,Size(g[now])){
        chi.push_back(dp[g[now][i]]);
    }
    sort(all(chi));
    reverse(all(chi));
    ll ma=0;
    rep(i,Size(chi)){
        ma=max(ma,chi[i]+i+1);
    }
    dp[now]=ma;
    return;
}

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

    cin>>n;
    rrep(i,2,n+1)cin>>a[i];
    rrep(i,2,n+1){
        g[a[i]].push_back(i);

    }
    dfs(1LL);
    Cout(dp[1]);
    return 0;
}


Measured memory_bytes: 41472
import sys

sysread = sys.stdin.buffer.readline
read = sys.stdin.buffer.read
sys.setrecursionlimit(10 ** 7)

# def main():

    # N = int(input())

    # for i in range(N):
    #     v = int(input())
    #     h.append(v)
def main():
    N, *h = map(int, read().split())
    h.sort()
    hh = h.copy()

    ans = 0
    t = h.pop(-1)
    t1 = t
    pm = 0
    while 1:
        t2 = h.pop(pm)
        ans += abs(t - t2)
        if len(h) == 0:
            break
        t = t2

        t3 = h.pop(pm)
        ans += abs(t1 - t3)
        if len(h) == 0:
            break
        t1 = t3

        if pm==0:
            pm = -1
        else:
            pm = 0

    ans1 = 0
    h = hh
    t = h.pop(0)
    t1 = t
    pm = -1

    while 1:
        t2 = h.pop(pm)
        ans1 += abs(t - t2)
        if len(h) == 0:
            break
        t = t2

        t3 = h.pop(pm)
        ans1 += abs(t1 - t3)
        if len(h) == 0:
            break
        t1 = t3
        if pm == 0:
            pm = -1
        else:
            pm = 0

    print(max(ans, ans1))

if __name__ == "__main__":
    main()

Measured memory_bytes: 18440
#include<cstdio>
#include<iostream>

std::string getS(std::string s,int l,int r){
    std::string res = ""; 
    int n = s.size();
    for(int i = 0; i < n; i++) {
        if(i>=l && i<=r) continue;
        else res.push_back(s[i]);
    }
    return res;
}

int main(){
    std::string s;
    std::cin>>s;
    std::string t = "keyence";
    if(s==t) printf("YES\n");
    else{
        int n = s.size();
        int ok = 0;
        for(int i = 0; i < n; i++){
            for(int j = i; j < n; j++){
                std::string cur = getS(s,i,j);
                if(cur==t) ok = 1;
            }
        } 
        if(ok) printf("YES\n");
        else printf("NO\n");
    }
    
    return 0;
}


Measured memory_bytes: 3612
main = interact $ unlines . map (show . bottommost . map (read . return)) . lines
bottommost ns = head $ iterateUntil ((==1) . length) (compress (\x y -> mod (x+y) 10)) ns
 where
  iterateUntil p f x = if p x == True then x else iterateUntil p f (f x)
  compress _ [x] = []
  compress op (x1:x2:xs) = op x1 x2 : compress op (x2:xs)

Measured memory_bytes: 4080
import sys, math

N, K = map(int, sys.stdin.readline().split())

immediate_win = (N - (K - 1)) / N if K <= N else 0

s = 0
for k in range(1, min(K - 1, N) + 1):
    r = K / k
    c = math.ceil(math.log2(r))
    p = 0.5 ** c
    s += p / N
print(s + immediate_win)

Measured memory_bytes: 3060
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;i++)
#define max3(a,b,c) max(max(a,b),c)
#define min3(a,b,c) min(min(a,b),c)
#define ft first
#define sc second
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define all(v) (v).begin(),(v).end()
#define mod 1000000007
using namespace std;
using Graph = vector<vector<int>>;
typedef long long lint;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ldouble;
typedef vector<int> vec;
typedef vector<ll> lvec;
typedef vector<ull> ulvec;
typedef vector<double> dvec;
typedef vector<pair<int,int>> pvec;
typedef vector<pair<ll,ll>> plvec;
typedef vector<tuple<ll,ll,ll>> tvec;
typedef vector<string> svec;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }

const ll MAX_N=3010,MAX_W=3010;
ll N,T;
ll a[MAX_N],b[MAX_N];
ll dp1[MAX_N+1][MAX_W+1];
ll dp2[MAX_N+1][MAX_N+1];

void solve(){
    for(int i=1;i<=N;i++){
        for(int j=0;j<=T-1;j++){
            dp1[i][j]=dp1[i-1][j];
            if(j-a[i]>=0) dp1[i][j]=max(dp1[i][j],dp1[i-1][j-a[i]]+b[i]);
        }
    }
    for(int i=N;i>0;i--){
        for(int j=0;j<=T-1;j++){
            dp2[i][j]=dp2[i+1][j];
            if(j-a[i]>=0) dp2[i][j]=max(dp2[i][j],dp2[i+1][j-a[i]]+b[i]);
        }
    }
    ll ans=0;
    for(int i=1;i<=N;i++){
        for(int j=0;j<=T-1;j++){
            chmax(ans,dp1[i-1][j]+dp2[i+1][T-1-j]+b[i]);
        }
    }
    cout<<ans<<endl;
}

int main(){
    cin>>N>>T;
    for(int i=1;i<=N;i++) cin>>a[i]>>b[i];
    solve();
}

Measured memory_bytes: 141696
import java.util.Scanner;

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

    Scanner stdIn = new Scanner(System.in);
    /*
10^6から時間がかかりすぎる

    int[] a = new int[100000];//javaは0で初期化されてる

    a[0] = 1;
    a[1] = 1;//0と1は素数じゃないです

    //素数表
    for(int i = 2; i < a.length; i++){
      if(a[i] == 0){
        for(int j = i+1; j < a.length; j++){
          if(j % i == 0){
            a[j] = 1;
          }
        }
      }
    }
    System.out.println("素数表完成");
    int n = stdIn.nextInt();
    int cnt = 0;//素数の数
    for(int i = 0; i < n; i++){
      int x = stdIn.nextInt();
      if(a[x] == 0){
        cnt++;
      }
    }
    System.out.println(cnt);
    */

    int n = stdIn.nextInt();
    int cnt = 0;//素数の数
    for(int i = 0; i < n; i++){
      int x = stdIn.nextInt();
      boolean check = true;
      if(x == 2){
        cnt++;
      }
      else{
        for(int j = 2; j < Math.sqrt(x)+1; j++){
          if(x % j == 0){
            check = false;
            break;
          }
        }
        if(check == true){
          cnt++;
        }
      }
    }
    System.out.println(cnt);
    }
  }



Measured memory_bytes: 42948
import Control.Monad
import Data.List
import qualified Data.Vector.Unboxed as V
import qualified Data.Vector.Unboxed.Mutable as MV

root :: MV.IOVector Int -> Int -> IO Int
root par x = do
    p <- MV.unsafeRead par x
    if p == -1 then return x
    else do
        to <- root par p
        MV.unsafeWrite par x to
        return to

unite :: MV.IOVector Int -> MV.IOVector Int -> Int -> Int -> IO ()
unite par siz x y = do 
    rx <- root par x
    ry <- root par y
    when (rx /= ry) $ do
        sx <- MV.unsafeRead siz x
        sy <- MV.unsafeRead siz y
        if (sx < sy) then do
            MV.unsafeWrite par rx ry
            MV.unsafeWrite siz ry (sx + sy)
        else do
            MV.unsafeWrite par ry rx
            MV.unsafeWrite siz rx (sx + sy)


same :: MV.IOVector Int -> Int -> Int -> IO Bool
same par x y = do
    px <- root par x
    py <- root par y
    return (px == py)

main = do
    [n,q] <- fmap(map read . words) getLine
    par <- MV.replicate(n+1)(-1)
    siz <- MV.replicate(n+1)(1)
    replicateM_ q $ do
        [com,x,y] <- fmap(map read . words) getLine
        if com == 0 then
            unite par siz x y
        else do
            f <- same par x y
            if f then print 1
            else 
                print 0


Measured memory_bytes: 4892
# https://atcoder.jp/contests/abc152/submissions/9693323

import sys
read = sys.stdin.read

N, *A = map(int, read().split())
mod = 10 ** 9 + 7


def min_factor(n):
    sieve = list(range(n + 1))
    sieve[2::2] = [2] * (n // 2)
    for i in range(3, int(n ** 0.5) + 2, 2):
        if sieve[i] == i:
            sieve[i * i::2 * i] = [i] * ((n - i * i) // (2 * i) + 1)
    return sieve


def prime_factorize(n):
    a = {}
    while n != 1:
        b = table[n]
        if b in a:
            a[b] += 1
        else:
            a[b] = 1
        n //= b
    return a


table = min_factor(10**6)

dic = {}
for i in A:
    for key, value in prime_factorize(i).items():
        if key in dic:
            dic[key] = max(dic[key], value)
        else:
            dic[key] = value

lcm = 1
for i, j in dic.items():
    lcm *= pow(i, j, mod)
    lcm %= mod

answer = sum(lcm * pow(i, mod - 2, mod) for i in A) % mod
print(answer)


Measured memory_bytes: 51316
import sys
input = sys.stdin.readline

class RmaxQ:
    def __init__(self, original):
        self.n = len(original)
        self.INF = -(2**31)
        self.N0 = 1 << (self.n-1).bit_length()
        self.seg = [self.INF]*(self.N0 << 1)
        for i, j in enumerate(original, self.N0):
            self.seg[i] = j
        for i in range(self.N0-1, 0, -1):
            self.seg[i] = max(self.seg[2*i], self.seg[2*i+1])

    def get(self, i):
        return self.seg[i+self.N0]
        
    def update(self, i, x):
        i += self.N0
        self.seg[i] = x
        while i > 1:
            y = self.seg[i ^ 1]
            if y >= x:
                break
            i >>= 1
            self.seg[i] = x
                

    def add(self, i, d):
        self.update(i, self.get(i)+d)

    def query(self, l, r):
        res = self.INF
        l += self.N0
        r += self.N0
        while l < r:
            if r & 1:
                res = max(res, self.seg[r-1])
            if l & 1:
                res = max(res, self.seg[l])
                l += 1
            l >>= 1
            r >>= 1
     
        return res
        
n = int(input())
H = list(map(int, input().split()))
A = list(map(int, input().split()))
dp = RmaxQ([0]*(n+1))
for i in range(n):
  h, a = H[i], A[i]
  dp.update(h, max(dp.get(h), dp.query(0, h)+a))
ans = dp.query(0, n+1)
print(ans)

Measured memory_bytes: 111568
#include <bits/stdc++.h>
typedef long long ll;
using namespace std;
ll MOD = 1e9+7;

#define vec vector<int>
#define vecll vector<ll>
#define vpair vector<pair<int, int>>
#define vpairll vector<pair<ll, ll>>

#define rep(i,n)         for(int i=(int)0; i<(int)n; i++)
#define REP(i,m,n)       for(int i=(int)m; i<(int)n; i++)
#define arr(var, n)      vec var(n); rep(i,n){cin >> var[i];}
#define arrll(var, n)    vecll var(n); rep(i,n){cin >> var[i];}
#define all(var)         (var).begin(), (var).end()
#define sortall(var)     sort(all(var))
#define prt(var)         cout << var << endl
#define prtd(n, var)     cout << fixed << setprecision(n) << var << endl
#define prt2(v1, v2)     cout << v1 << " " << v2 << endl
#define prt3(v1, v2, v3) cout << v1 << " " << v2 << " " << v3 << endl
#define prtall(var)      rep(i,var.size()){cout << var[i] << " ";} cout << endl

//----------------------------------------------------------------

int main(void) {
  int n, k;
  cin >> n >> k;
  arrll(h,n);
  sortall(h);

  ll ans=0;
  if(n<=k){
    prt(0); return 0;
  } else {
    rep(i,n-k){
      ans+=h[i];
    }
  }

  prt(ans);
}


Measured memory_bytes: 1792
#include <iostream>
#include <map>

using namespace std;

void solve()
{
	int a[5];
	while(cin >> a[0], a[0])
	{
		for(int i = 1; i < 5; ++i)
		{
			cin >> a[i];
		}
		map<int, int> Map;
		for(int i = 0; i < 5; ++i)
		{
			Map[a[i]]++;
		}
		if(Map.size() == 1 || Map.size() == 3)
		{
			for(int i = 0; i < 5; ++i)
			{
				cout << 3 << endl;
			}
		}
		else
		{
			if(Map.find(1) != Map.end() && Map.find(2) != Map.end())
			{
				for(int i = 0; i < 5; ++i)
				{
					if(a[i] == 1)
					{
						cout << 1 << endl;
					}
					else
					{
						cout << 2 << endl;
					}
				}
			}
			else if(Map.find(1) != Map.end() && Map.find(3)!= Map.end() )
			{
				for(int i = 0; i < 5; ++i)
				{
					if(a[i] == 1)
					{
						cout << 2 << endl;
					}
					else
					{
						cout << 1 << endl;
					}
				}
			}
			else if(Map.find(2) != Map.end() && Map.find(3)!= Map.end() )
			{
				for(int i = 0; i < 5; ++i)
				{
					if(a[i] == 2)
					{
						cout << 1 << endl;
					}
					else
					{
						cout << 2 << endl;
					}
				}
			}
		}
	}
}

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

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

typedef long long ll;

int main() {        
	string s,t;
	cin >> s >> t;
	int n = (int)s.size();
	int m = (int)t.size();
	int index = -1;
	for (int i = 0; i + m - 1< n; ++i) {
		bool d = 1;
		for (int j = i, p = 0; j < i + m; ++j,p++) {
			if (s[j] != '?' && s[j] != t[p]) {
				d = 0;
			}
		}
		if (d) 
			index = i;
	}
	if (index == -1) {
		cout << "UNRESTORABLE";
		return 0;
	}
	for (int i = index, p = 0; i < index + m; ++i,p++) {
		s[i] = t[p];
	}
	for (int i = 0; i < n; ++i) {
		if (s[i] == '?') s[i] = 'a';
	}
	cout << s;
}




Measured memory_bytes: 3628
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using ull = unsigned long long;
using V = vector<int>;
using VV = vector<V>;
using VVV = vector<VV>;
using VL = vector<ll>;
using VVL = vector<VL>;
using VVVL = vector<VVL>;
template<class T> using P = pair<T, T>;
#define rep(i,n) for(int i=0;i<(n);i++)
#define rep1(i,n) for(int i=1;i<=(n);i++)
#define REP(i,k,n) for(int i=(k);i<(n);i++)
#define all(a) (a).begin(),(a).end()
#define output(x,y) cout << fixed << setprecision(y) << x << endl;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }
ll lcm(ll a, ll b) { return a / gcd(a, b) * b; }
const ll MOD = 1e9 + 7;
// const ll MOD = 998244353;
ll upper = MOD + MOD;
ll under = -upper;
ll UPPER = MOD * MOD;
ll UNDER = -UPPER;
const long double pi = 3.141592653589793;
int main() { // こういうの自力で証明したいっすね
	int n;
	cin >> n;
	VL l(n), r(n);
	rep(i, n) {
		cin >> l[i] >> r[i];
	}
	sort(all(l)); sort(all(r));
	if (n % 2 == 1) {
		//　この場合、真ん中の値が動くと中央値も1変化するだけ
		//　真ん中以外の値を適切に動かすとこれが達成できる
		cout << r[n / 2] - l[n / 2] + 1 << endl;
	}
	else {
		// この場合、1/2ずつ変化していく
		// 偶数の中央値は二つの値に影響される
		// Lのとりうる範囲が1-indでn/2とn/2+1番目の間なのでこうなって、Rのとりうる範囲もそうなる
		ll L = l[n / 2 - 1] + l[n / 2];
		ll R = r[n / 2 - 1] + r[n / 2];
		cout << R - L + 1 << endl;
	}
	return 0;
}

Measured memory_bytes: 6432
val = gets.to_i
ans = {
  hour: 0,
  minute: 0,
  second: 0
}

while true do
  if 3599 < val #????????? 60 * 60
    val -= 3600
    ans[:hour] += 1
  elsif 59 < val #??????
    val -= 60
    ans[:minute] += 1
  else
    ans[:second] = val
    break
  end
end

puts "#{ans[:hour]}:#{ans[:minute]}:#{ans[:second]}"

Measured memory_bytes: 8608
N = int(input())

if N <= 111:
    ans = 111
elif 111 < N <= 222:
    ans = 222
elif 222 < N <= 333:
    ans = 333
elif 333 < N <= 444:
    ans = 444
elif 444 < N <= 555:
    ans = 555
elif 555 < N <= 666:
    ans = 666
elif 666 < N <= 777:
    ans = 777
elif 777 < N <= 888:
    ans = 888
elif 888 < N <= 999:
    ans = 999

print(ans)

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

// main.cpp

int main() {
  std::int_fast64_t N, C;;
  std::cin >> N >> C;
  std::vector<std::vector<std::int_fast64_t>> D;
  D.reserve(C);
  for (std::int_fast64_t i = 0; i < C; ++i) {
    D.emplace_back();
    D.back().reserve(C);
    std::copy_n(std::istream_iterator<std::int_fast64_t>(std::cin), C, std::back_inserter(D.back()));
  }
  std::vector<std::vector<std::int_fast64_t>> c;
  c.reserve(N);
  for (std::int_fast64_t i = 0; i < N; ++i) {
    c.emplace_back();
    c.back().reserve(N);
    std::copy_n(std::istream_iterator<std::int_fast64_t>(std::cin), N, std::back_inserter(c.back()));
    std::transform(c.back().begin(), c.back().end(), c.back().begin(), [](const std::int_fast64_t x) { return x - 1; });
  }

  std::array<std::vector<std::int_fast64_t>, 3> phase1 = {
    std::vector<std::int_fast64_t>(C, 0),
    std::vector<std::int_fast64_t>(C, 0),
    std::vector<std::int_fast64_t>(C, 0),
  };
  for (std::int_fast64_t i = 0; i < N; ++i) {
    for (std::int_fast64_t j = 0; j < N; ++j) {
      ++phase1[(i + j + 2) % 3][c[i][j]];
    }
  }

  std::array<std::vector<std::int_fast64_t>, 3> phase2 = {
    std::vector<std::int_fast64_t>(C, 0),
    std::vector<std::int_fast64_t>(C, 0),
    std::vector<std::int_fast64_t>(C, 0),
  };
  for (std::int_fast64_t i = 0; i < 3; ++i) {
    for (std::int_fast64_t j = 0; j < C; ++j) {
      for (std::int_fast64_t k = 0; k < C; ++k) {
        phase2[i][j] += phase1[i][k] * D[k][j];
      }
    }
  }

  std::int_fast64_t answer = std::numeric_limits<std::int_fast64_t>::max();
  for (std::int_fast64_t i = 0; i < C; ++i) {
    for (std::int_fast64_t j = 0; j < C; ++j) {
      if (j == i) continue;
      for (std::int_fast64_t k = 0; k < C; ++k) {
        if (k == i || k == j) continue;
        answer = std::min(answer, phase2[0][i] + phase2[1][j] + phase2[2][k]);
      }
    }
  }

  std::cout << answer << std::endl;
  return 0;
}

Measured memory_bytes: 2176
import java.util.Scanner;
import java.util.Arrays;
import java.util.List;
import java.util.ArrayList;

public class Main{
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int[] array = new int[n];
        List<List<Integer>> result = new ArrayList<>();
        List<Integer> answer = new ArrayList<>();
        for(int i = 0;i < n;i++){
            array[i] = sc.nextInt();
        	result.add(new ArrayList<>());
        }
        for(int i = 0;i < n;i++){
            for(int j = 1;j <= array[i];j++){
                if(array[i] % j == 0){
                    result.get(i).add(j);
                }else{
                    continue;
                }
            }
        }
        for(int j = 0;j < result.get(1).size();j++){
            if(result.get(0).contains(result.get(1).get(j))){
                int tmp = result.get(1).get(j);
                if(n <= 2 || result.get(2).contains(tmp)){
                    answer.add(tmp);
                }
            }
        }
        for(int a : answer){
            System.out.println(a);
        }
    }
}


Measured memory_bytes: 27672
import math
import sys
sys.setrecursionlimit(10**9)

def mi(): return map(int,input().split())
def ii(): return int(input())
def isp(): return input().split()
def deb(text): print("-------\n{}\n-------".format(text))

class Accumulation:
    def __init__(self,X,accumfunc,init_val=0):
        self.X = X
        self.accumfunc = accumfunc

        N = len(X)
        v1 = [0] * (N+1)
        v1[0] = init_val

        for i in range(N):
            v1[i+1] = accumfunc(v1[i],X[i])

        self.v1 = v1
    
    # 0-index
    def query(self,l,r):
        return self.v1[r+1] - self.v1[l]
    
    def get_array(self):
        return self.v1

class Counter:
    def __init__(self):
        self.dict = {}

    def add(self,x):
        if x in self.dict: self.dict[x] += 1
        else: self.dict[x] = 1

    def decrement(self,x):
        self.dict[x] -= 1

    def get_dict(self):
        return self.dict



INF=10**20
def main():
    N,K=mi()
    A=list(mi())

    def madd(x,y): return (x+y) % K
    V = Accumulation(A,madd)

    v = V.get_array()
    u = [-1] * (N+1)

    for i in range(N+1):  
        u[i] = v[i] - i
        u[i] %= K  
    
    # print(u)
    if K <= N:
        s = u[:K]
        counter = Counter()
        for i in range(K):
            _s = s[i]
            counter.add(_s)

        ans = 0
        current_count = counter.get_dict()
        ans += (current_count[u[0]] - 1)
    
        for i in range(1,N+1):
            # print(u[i:i+K])

            old = u[i-1]
            counter.decrement(old)

            if i+K-1 < len(u):
                new = u[i+K-1] 
                counter.add(new)

            current_count = counter.get_dict()
            ans += (current_count[u[i]] - 1)
            # print(i,current_count[u[i]] - 1)
        
        print(ans)


    else:
        counter = Counter()
        for i in range(N+1):
            counter.add(u[i])
        
        u = counter.get_dict()
        ans = 0
        for c in u.values():
            if c <= 0: continue
            ans += c*(c-1)//2
        
        print(ans)
            
    


if __name__ == "__main__":
    main()


Measured memory_bytes: 125456
import java.util.Scanner;
public class Main{
  public static void main(String[] args){
    int ball = 0;
    Scanner sc = new Scanner(System.in);
    int n = sc.nextInt();
    int x = sc.nextInt();
    int howmany = 0;
    for(int i = 0; i < n+1; i++){
      if(ball<=x){
        howmany++;
        if(i==n){
          System.out.println(howmany);
        }else{
          ball = ball + sc.nextInt();
        }
      }else{
        System.out.println(howmany);
        break;
      }
    }
  }
}
      

Measured memory_bytes: 21844
#include <bits/stdc++.h>
#define ll long long int
#define ld long double
#define yorn(f) cout<<((f)?"Yes":"No")<<endl;
#define YORN(f) cout<<((f)?"YES":"NO")<<endl;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define repi(i, n) for (int i = 1; i < (int)(n); i++)
#define all(x) (x).begin(), (x).end()
#define put(x) cout << x << endl;
#define println(x) cout << x << endl;
using namespace std;
int main()
{
    int n;
    cin >> n;
    vector<int> a(n);
    rep(i, n) cin >> a[i];

    int sum = 0;
    rep(i, n) {
        while (a[i] % 2 == 0) {
            sum ++;
            a[i] /= 2;
        }
    }
    put(sum);
    return 0;
}

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

using namespace std;
typedef long long ll;


const int N=1e5+100;

int a[2020];

int main()
{
    a[0]++;
    string s;cin>>s;
    int base=1;
    int kk=0;
    int ans=0;
    for(int i=s.size()-1;i>=0;i--){
        kk+=(s[i]-'0')*base;
        kk%=2019;
        ans+=a[kk]++;
        base=base*10%2019;
    }
    cout<<ans;
    return 0;
}


Measured memory_bytes: 3644
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define srep(i,s,t) for (int i = s; i < t; ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
using namespace std;
typedef long long int ll;
typedef pair<int,int> P;
#define yn {puts("Yes");}else{puts("No");}
#define MAX_N 200005

int main() {
    int n;
    cin >> n;
    int a[n+1];
    a[0] = 1001001001;
    int ans = 0;
    srep(i,1,n+1){
        cin >> a[i];
        if(a[i] > a[i-1])ans++;
    }

    

    cout << ans << endl;
    return 0;
}
 
 



Measured memory_bytes: 3476
#include<bits/stdc++.h>
using namespace std;
 
template <class T1, class T2>
ostream& operator << (ostream& out, const pair <T1, T2> p)
{
        out << '(' << p.first << ',' << p.second << ')';
            return out;
}
 
template <class T1, class T2>
istream& operator >> (istream& in, pair<T1, T2> &p)
{
        in >> p.first >> p.second;
            return in;
}
 
template <class T>
istream& operator >> (istream& in, vector<T> &v)
{
        for (T &x : v)
                    in >> x;
            return in;
}
 
template <class T>
ostream& operator << (ostream& out, const vector<vector<T> > &v)
{
        for (const vector<T> &x : v)
                    out << x << '\n';
            return out;
}
 
template <class T>
ostream& operator << (ostream& out, const vector<T> &v)
{
        for (const T &x : v)
                    out << x << ' ';
            return out;
}

template <class T>
ostream& operator << (ostream& out,const set<T> &s)
{
        for (const T &x : s)
                out << x << ' ';
            return out;
}
 
 
#define ll long long
#define lf long double
#define pb push_back
#define mp make_pair
#define F first
#define S second
typedef pair <ll,ll > ii;
typedef vector <ll> vi;
typedef vector <ii> vii;
typedef vector <bool> vb;
typedef vector <vector <ll> > vv;
typedef vector <vector <vector<ll> > > vvv;
typedef vector <string> vs;
typedef vector <lf> vf;
#define sz(x) (ll)(x).size()
#define tr1(x) cerr << #x << ": " << x << nl
#define tr2(x, y) cerr << #x << ": " << x << " | " << #y << ": " << y << nl
#define tr3(x,y,z) cerr<<#x<<": "<<x<<" | "<<#y<<": "<<y<<" | "<<#z<<": "<<z<<nl
#define tr4(x,y,z,w) cerr<<#x<<": "<<x<<" | "<<#y<<": "<<y<<" | "<<#z<<": "<<z<<" | "<<#w<<": "<<w<<nl
#define trv(a) cerr<<#a<<": ";for(ll zz=0;zz<sz(a);zz++) cerr<<a[zz]<<" ";cerr<<nl
#define trset(s) cerr<<#s<<": ";for(auto &i:s) cerr<<i<<" ";cerr<<nl
#define epsilon 0.00000001L
#define inf 9999999999999999ll// ~ 10^16
#define nl endl
#define all(x) x.begin(), x.end()
#define r_all(x) x.rbegin(), x.rend()
#define fast()  ios_base::sync_with_stdio(false);cin.tie(NULL)
#define mod 1000000007ll
#define modulo 998244353ll
ll power(ll a,ll b){return b?power(a*a%mod,b/2)*(b%2?a:1)%mod:1;}

bool possible(ll num,vi &h,ll a,ll b)
{
    __int128 numa=0;
    for(ll i=0;i<sz(h);i++)
    {
        __int128 health=h[i]-(__int128)num*b;
        if(health>0)
        numa+=(health+a-b-1)/(a-b);
    }
    return numa<=num;
}
int main()
{
    fast();
    ll n,a,b;
    cin>>n>>a>>b;
    vi h(n);
    cin>>h;
    ll low=0;
    ll high=inf;
    while(low<high)
    {
        ll mid=(low+high)/2;
        if(possible(mid,h,a,b))
            high=mid;
        else
            low=mid+1;
    }
    cout<<low<<nl;
    //0 , 1
}


Measured memory_bytes: 3924
#include <stdio.h>
#include <string.h>
#include <math.h>
#include <stdlib.h>
#include <limits.h>
#include <stdbool.h>

#define rep(i, n) for(int i=0; i<(n); ++i)
#define max  200001

//qsort(str, n, sizeof(int), up_comp);
int up_comp(const void *a, const void *b){return *(int*)a - *(int*)b;}
int down_comp(const void *a, const void *b){return *(int*)b - *(int*)a;}
int int_sort( const void * a , const void * b ) {return strcmp(( char * )a , ( char * )b );}
int count_digit(int a){int i=0;while(a!=0){a=a/10;i++;}return i;}
int euclid( int a, int b ){int temp;if(a<b){temp=a;a=b;b=temp;}if(b<1)return -1;if(a%b==0) return b;return euclid(b,a%b);}

int main(void){
 
    char S[11];
    
    scanf("%s",S);
      
    if((S[5]=='0')&&(S[6]<='4')) {
        printf("Heisei\n");
    } else {
        printf("TBD\n");
    }
    
    return 0;
}



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

#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define FOR(i,n,m) for(int i=(int)(n); i<=(int)(m); i++)
#define ITR(x,c) for(__typeof(c.begin()) x=c.begin();x!=c.end();x++)
#define RITR(x,c) for(__typeof(c.rbegin()) x=c.rbegin();x!=c.rend();x++)
#define setp(n) fixed << setprecision(n)

#define ld long double
#define ll long long
#define vll vector<ll>
#define vi vector<int>
#define pll pair<ll,ll>
#define pi pair<int,int>

#define all(a) (a.begin()),(a.end())
#define rall(a) (a.rbegin()),(a.rend())
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define ins insert

using namespace std;

/* Some Libraries */

//-------------------------------------------------

int main(void)
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    string s; cin>>s;
    if (s=="SUN") cout<<"7\n";
    if (s=="MON") cout<<"6\n";
    if (s=="TUE") cout<<"5\n";
    if (s=="WED") cout<<"4\n";
    if (s=="THU") cout<<"3\n";
    if (s=="FRI") cout<<"2\n";
    if (s=="SAT") cout<<"1\n";
    return 0;
}


Measured memory_bytes: 768
from collections import deque
def main():
  s = deque(list(input()))
  q = int(input())
  f = 0
  for _ in range(q):
    l = input()
    if l == "1":
      f ^= 1
    else:
      a, b, c = l.split()
      if f ^ (b=="1"):
        s.appendleft(c)
      else:
        s.append(c)
  if f:
    ans = list(s)[::-1]
  else:
    ans = list(s)
  print(*ans, sep="")
if __name__ == "__main__":
  main()

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

int main() {
    char c; cin >> c;
    if (c == 'A') cout << 'T' << endl;
    else if (c == 'T') cout << 'A' << endl;
    else if (c == 'C') cout << 'G' << endl;
    else cout << 'C' << endl;
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <queue>
#include <cstring>
#include <cstdio>
#include <cmath>
#include <set>
#include <map>
using namespace std;

int main() {

    int n;
    cin >> n;
    
    vector<int> t(100001), x(100001), y(100001);
    t[0] = x[0] = y[0] = 0;

    for (int i = 0; i < n; i++) {
        cin >> t[i+1] >> x[i+1] >> y[i+1];
    }

    bool can = true;
    for (int i = 0; i < n; i++) {
        int dt = t[i+1] - t[i];
        int dist = abs(x[i+1] - x[i]) + abs(y[i+1] - y[i]);
        if (dt < dist) can = false;
        if (dist % 2 != dt % 2) can = false;
    }

    cout << ((can) ? "Yes" : "No" )<< endl;
    
    return 0;
}

Measured memory_bytes: 1408
#include <iostream>
#include <algorithm>
#include <vector>
#include <stack>
#include <queue>
#include <map>
#include <cmath>
#include <string>
#include <sstream>
#include <iomanip>
#include <complex>
using namespace std;

#define ll long long
#define vvi vector< vector<int> >
#define vi vector<int>
#define All(X) X.begin(),X.end()
#define FOR(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define REP(i,n) for(int i=0;i<(int)(n);i++)
#define pb push_back
#define pii pair<int,int>
#define mp make_pair
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
ll lcm(ll a,ll b){return a/gcd(a,b)*b;}

int main(){
	ll int a,b;
	cin >> a >> b;
	cout << gcd(a,b) << endl;
}

Measured memory_bytes: 1156
#include<iostream>
#include<vector>
#include<string>
#include<map>
#include<queue>
#include<functional>
#include<cmath>
#include<algorithm>
typedef  long long ll;

int main() {
	int a = 0, b = 0, c = 0, n = 0,ar[100000] = {};
	std::string str;
	std::cin >> a >> b;
	if (a > 8||b>8) {
		std::cout << ":(" << std::endl;
	}
	else {
		std::cout << "Yay!" << std::endl;
	}
	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <queue>
#include <cstdio>
#include <cstring>
using namespace std;

string ba[2][50];
bool visited[50][50][50][50];
typedef pair<int,int> pii;
typedef pair<pii,pii> P;

int main()  {
    int h,w;
    while(cin>>w>>h,h||w) {
        //cout << h << " " << w << endl;
        pii s[2];
        for (int i=0; i<h; ++i) {
            cin >> ba[0][i] >> ba[1][i];
            for (int j=0; j<2; ++j) {
                for (int k=0; k<w; ++k) {
                    if (ba[j][i][k] == 'L' || ba[j][i][k] == 'R') {
                        s[j] = pii(i,k);
                    }
                }
            }
        }
        queue<P> Q;
        Q.push(P(s[0], s[1]));
        memset(visited,0,sizeof(visited));
        const int dy[2][4] = {
            {-1,0,1,0},
            {-1,0,1,0}
        };
        const int dx[2][4] = {
            {0,1,0,-1},
            {0,-1,0,1}
        };
        bool ans = 0;
        while(!Q.empty()) {
            P p = Q.front(); Q.pop();
            int y[2];
            int x[2];
            y[0] = p.first.first;
            x[0] = p.first.second;
            y[1] = p.second.first;
            x[1] = p.second.second;
           
            if (visited[y[0]][x[0]][y[1]][x[1]]) continue;
            visited[y[0]][x[0]][y[1]][x[1]] = 1;
            //printf("(%d,%d) (%d,%d)\n",x[0],y[0],x[1],y[1]);
            int c = 0;
            for (int i=0; i<2; ++i) {
                if (ba[i][y[i]][x[i]] == '%') c |= 1<<i;
            }
            if (c) {
                if (c == 3) {
                    ans = 1;
                    break;
                } else {
                    continue;
                }
            }
            for (int k=0; k<4; ++k) {
                int yy[2], xx[2];
                for (int i=0; i<2; ++i) {
                    yy[i] = y[i] + dy[i][k];
                    xx[i] = x[i] + dx[i][k];
                    if (yy[i]<0||yy[i]>=h||xx[i]<0||xx[i]>=w || 
                        ba[i][yy[i]][xx[i]] == '#') {
                        yy[i] = y[i];
                        xx[i] = x[i];
                    }
                }
                Q.push(P(pii(yy[0],xx[0]),pii(yy[1],xx[1])));
            }
        } 
        cout <<(ans?"Yes":"No") << endl;
    }
}

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

#define el '\n'

int main(){
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);

  int n;
  cin >> n;
  double dp[n+1]; // dp[i] is prob of having i heads
  memset(dp,0,sizeof(dp));
  dp[0] = 1;
  for(int coin = 0; coin < n; coin++){
    double prob;
    cin >> prob;
    for(int i = coin+1; i >= 0; i--){
      dp[i] = (i!=0 ? dp[i-1]*prob : 0) + dp[i]*(1-prob);
    }
  }

  double ans = 0;
  for(int heads = n/2; heads <= n; heads++){
    int tails = n-heads;
    if(heads > tails) ans += dp[heads];
  }
  
  cout << setprecision(9) << ans << el;
  return 0;
}

Measured memory_bytes: 256
import java.util.*;
public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int num = sc.nextInt();
		long te = 0;
      	for(int i = 0;i<=num;i++){
          if(i%3==0 || i%5==0){
          }else{
            te += i;
          }
        }
      	System.out.println(te);
    }
}

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

int main(){
  long long n; cin>>n;
  vector<long long> a(n);
  for(int i = 0; i < n; i++){
    cin >> a.at(i);
  }
  long long un = 0, up = a.at(0);
  long long me = (un + up) / 2;
  long long x = me;
  for(int i = 0; i < n; i++){
    x = a.at(i) - x;
  }
  while(un < up){
    if(x > me){
      un = me;
      me = (un + up) / 2 + 1;
      x -= (me - un);
    }else if(x < me){
      up = me;
      me = (un + up) / 2;
      x += (up - me);
    }else{
      break;
    }
  }
  long long y = me;
  for(int i = 0;i < n; i++){
    cout << 2 * y << " ";
    y = a.at(i) - y;
  }
}


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

int main(){
  
  int array;
  int s1;
  int s2;
  int s3;
  
  cin >> array;

  s1 = array / 100;
  s2 = (array - s1 * 100) / 10;
  s3 = (array - s1 * 100 - s2 * 10);

  cout << s1 + s2 + s3 << endl;
}

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

using namespace std;
using namespace __gnu_pbds;
 
typedef long long ll;
typedef long double ld;
typedef complex<ld> cd;

typedef pair<int, int> pi;
typedef pair<ll,ll> pl;
typedef pair<ld,ld> pd;

typedef vector<int> vi;
typedef vector<ld> vd;
typedef vector<ll> vl;
typedef vector<pi> vpi;
typedef vector<pl> vpl;
typedef vector<cd> vcd;

template <class T> using Tree = tree<T, null_type, less<T>, rb_tree_tag,tree_order_statistics_node_update>;

#define FOR(i, a, b) for (int i=a; i<(b); i++)
#define F0R(i, a) for (int i=0; i<(a); i++)
#define FORd(i,a,b) for (int i = (b)-1; i >= a; i--)
#define F0Rd(i,a) for (int i = (a)-1; i >= 0; i--)

#define sz(x) (int)(x).size()
#define mp make_pair
#define pb push_back
#define f first
#define s second
#define lb lower_bound
#define ub upper_bound
#define all(x) x.begin(), x.end()

const int MOD = 1000000007;
const ll INF = 1e18;
const int MX = 100001;

int N;
pi pos[1002];
ld dist[1002];
int rad[1002];

ld dis(pi a, pi b) {
    return sqrt(pow(a.f-b.f,2)+pow(a.s-b.s,2));
}

ld getDist(int x, int y) {
    return max(dis(pos[x],pos[y])-rad[x]-rad[y],(ld)0);
}

int main() {
    ios_base::sync_with_stdio(0); cin.tie(0);
    cin >> pos[0].f >> pos[0].s >> pos[1].f >> pos[1].s;
    cin >> N;
    FOR(i,2,2+N) cin >> pos[i].f >> pos[i].s >> rad[i];
    FOR(i,1,N+2) dist[i] = INF;
    priority_queue<pair<ld,int>,vector<pair<ld,int>>,greater<pair<ld,int>>> pq; pq.push({0,0});
    // cout << getDist(0,2) << "\n";
    while (sz(pq)) {
        auto a = pq.top(); pq.pop();
        if (a.f != dist[a.s]) continue;
        F0R(i,N+2) if (a.f+getDist(a.s,i) < dist[i]) {
            dist[i] = a.f+getDist(a.s,i);
            pq.push({dist[i],i});
        }
    }
    cout << fixed << setprecision(12) << dist[1];
}

// read the question correctly (is y a vowel? what are the exact constraints?)
// look out for SPECIAL CASES (n=1?) and overflow (ll vs int?) ARRAY OUT OF BOUNDSS

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

using namespace std;

int main(){
   string s;
   cin >> s;
   int n = s.length();
   int len = n;
   for(int i=0;i<len/2;i++){
     if(s[i]!=s[n-1-i]){
       cout << "No" << endl;
       return 0;
     }
   }
   for(int i=0;i<n/4;i++){
     if(s[i]!=s[n/2-1-i] || s[i]!=s[(n+1)/2+i] || s[i]!=s[n-1-i]){
       cout << "No" << endl;
       return 0;
     }
   }
   cout << "Yes" << endl;
}


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

int main(){
  int x,a,b;
  cin >> x >> a >> b;
  if(b<=a){
    cout << "delicious" << endl;
  }else if(b-a<=x){
    cout << "safe" << endl;
  }else if(b-a>x){
    cout <<  "dangerous" << endl;
  }
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long 
// memo  fixed  setprecision(20);
using vvll = vector<vector<ll>>;
ll mod =1e9+7;
/*"itob" int to "N"base */           template<typename TypeInt> string itob(const TypeInt v, int base){static const char table[] = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ";string ret;static numeric_limits<TypeInt> t;TypeInt n = v;if (t.is_signed) {if (v < 0) n *= -1;}while (n >= base) {ret += table[n%base];n /= base;}ret += table[n];if (t.is_signed) {if (v < 0 && base == 10) ret += '-';}reverse(ret.begin(), ret.end());return ret;}
/*"chmin" a = MAX*/                  template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
/*"chmax" a = MIN*/                  template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
/*"ctoi"  char to int*/              int ctoi(char c) {return c-'0';}
/*"gcd"   MAX Euclidean */           ll gcd(ll a,ll b){if(b==0)return a; return gcd(b,a%b);}
    /*"lcm"   MIN*/                      ll lcm(ll a,ll b){ll g = gcd(a,b);return a/g*b;}
/*"primecheck"If prime,return true.*/bool primecheck(ll n){if(n < 2) return false;else{for(int i = 2; i * i <= n; i++){if(n % i == 0) return false;}return true;}}
string  reverserange(string s,ll a,ll b){reverse(s.begin()+a-1,s.begin()+b); return s;}
ll modpow(ll a,ll n, ll mod){ll res = 1;while(n>0){if (n%2==1){res = res * a % mod;}a = a * a % mod;n/=2;}return res;}
int main() {
    ll x,k,d;
    cin >> x >>k >> d;
    x = abs(x);
    ll ans;ll check = k;
    if(x/d>=k){
        ans = abs(x-k*d);
        cout<<ans<<endl;
    }// oke 
    else{
        check-=x/d;
        //cout<<check<<endl;
        if(check%2==0){
            ans =abs(x%d);
            cout<<ans<<endl; 
        }
        else{
            ll z = x%d;
            //cout<<z<<endl;
            ans =z+d;
            //cout<<ans<<endl;
            ans = min(ans,abs(z-d));
            cout<<ans<<endl;
        }
    }
}
    



Measured memory_bytes: 3576
import java.util.Scanner;

public class Main {

	private static Node[] nodes;
	private static int[] D;

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

		nodes = new Node[n];
		StringBuilder[] children = new StringBuilder[n];

		for (int i = 0; i < n; i++) {
			nodes[i] = new Node(-1, -1, -1);
		}

		for (int i = 0; i < n; i++) {
			int node = sc.nextInt();
			int Cnum = sc.nextInt();

			int[] Ckari = new int[Cnum];

			children[node] = new StringBuilder("[");

			for (int j = 0; j < Cnum; j++) {
				Ckari[j] = sc.nextInt();

				if (j == 0) {
					nodes[node].left = Ckari[j];
				} else {
					nodes[Ckari[j - 1]].right = Ckari[j];
				}

				nodes[Ckari[j]].parent = node;

				children[node].append(Ckari[j]);
				if (j != Cnum - 1) {
					children[node].append(", ");
				}
			}

			children[node].append("]");
		}

		// int rootJudge = -1;
		for (int i = 0; i < n; i++) {
			if (nodes[i].parent == -1) {
				// rootJudge = i;
				break;
			}
		}

		D = new int[n];

		for (int i = 0; i < n; i++) {
			D[i] = setDepth(i);
		}

		for (int i1 = 0; i1 < n; i1++) {
			StringBuilder kari = new StringBuilder();
			kari.append("node ");
			kari.append(i1);
			kari.append(": parent = ");
			kari.append(nodes[i1].parent);
			kari.append(", depth = ");
			kari.append(D[i1]);
			kari.append(", ");
			if (nodes[i1].parent == -1) {
				kari.append("root, ");
			} else if (nodes[i1].left == -1) {
				kari.append("leaf, ");
			} else {
				kari.append("internal node, ");
			}
			kari.append(children[i1]);
			System.out.println(kari);

		}

	}

	// public static void setDepth(int u, int p) {
	// D[u] = p;
	//
	// if (nodes[u].right != -1) {
	// setDepth(nodes[u].right, p);
	// }
	// if (nodes[u].left != -1) {
	// setDepth(nodes[u].left, p + 1);
	// }
	//
	// return;
	// }

	public static int setDepth(int u) {
		if (nodes[u].parent == -1) {
			return 0;
		} else {
			return setDepth(nodes[u].parent) + 1;
		}
	}

}

class Node {
	int parent;
	int left;
	int right;

	public Node(int parent, int left, int right) {
		super();
		this.parent = parent;
		this.left = left;
		this.right = right;
	}

}

Measured memory_bytes: 135704