akhauriyash/Code-Regression huggingface dataset:
import java.util.*

fun main(args: Array<String>) {
    val pw = java.io.PrintWriter(System.out)
    Problem.solve(Scanner(System.`in`), pw)
    pw.flush()
}

class Permutations<A : Comparable<A>>(val nums: Array<A>) {
    fun nextPermutation(): Array<A>? {
        var mark = -1
        for (i in nums.size - 1 downTo 1) {
            if (nums[i] > nums[i - 1]) {
                mark = i - 1
                break
            }
        }
        if (mark == -1) {
            reverse(nums, 0, nums.size - 1)
            return null
        }
        var idx = nums.size - 1
        for (i in nums.size - 1 downTo mark + 1) {
            if (nums[i] > nums[mark]) {
                idx = i
                break
            }
        }
        swap(nums, mark, idx)
        reverse(nums, mark + 1, nums.size - 1)
        return nums
    }

    private fun swap(nums: Array<A>, i: Int, j: Int) {
        val t = nums[i]
        nums[i] = nums[j]
        nums[j] = t
    }

    private fun reverse(nums: Array<A>, i: Int, j: Int) {
        var i = i
        var j = j
        while (i < j) {
            swap(nums, i, j)
            i++
            j--
        }
    }
}

object Problem {
    lateinit var dfs: (Int, Int) -> Unit

    fun solve(sc: Scanner, pw: java.io.PrintWriter) {
        val N = sc.next().toInt()
        val XY = Array(N) { Pair(sc.next().toInt(), sc.next().toInt()) }
        val X = XY.map { it.first }.toIntArray()
        val Y = XY.map { it.second }.toIntArray()

        val dist = Array(N) { DoubleArray(N) }
        for (i in 0 until N - 1) {
            for (j in (i + 1) until N) {
                val d = Math.sqrt(
                    ((X[i] - X[j]) * (X[i] - X[j]) + (Y[i] - Y[j]) * (Y[i] - Y[j])).toDouble()
                )
                dist[i][j] = d
                dist[j][i] = d
            }
        }
        var a: Array<Int>? = (0 until N).map { it }.toTypedArray()
        val p = Permutations(a!!)
        var sum = 0.0
        var n = 0
        while (a != null) {
            n += 1
            for (i in 1 until N) {
                sum += dist[a[i - 1]][a[i]]
            }
            a = p.nextPermutation()
        }
        pw.printf("%.10f\n", sum / n)
    }
}

Measured memory_bytes: 36124
#include<iostream>
#include<stdio.h>
#include<vector>
#include<algorithm>
#include<set>
#include<string>
#include<map>
#include<string.h>
#include<complex>
#include<math.h>
#include<queue>
#include <functional>
#include<time.h>
#include <stack>
using namespace std;
#define rep(i,a,n) for(int i=(a);i<(n);i++)
#define ll long long
#define llint long long int
#define sort(s) sort(s.begin(),s.end())
#define reverse(v)  reverse(v.begin(), v.end());
#define Yes(ans) if(ans)cout<<"Yes"<<endl; else cout<<"No"<<endl;
#define YES(ans) if(ans)cout<<"YES"<<endl; else cout<<"NO"<<endl;
#define hei(a) vector<a>
#define whei(a) vector<vector<int>>
constexpr auto mod = 1000000007;


//2のn乗を求めるよ！！！
int ni(int n) {
	if (n == 0)return 1;
	int x = ni(n / 2);
	x *= x;
	if (n % 2 == 1)x *= 2;
	return x;
}

//フィボナッチ数列のx番目を求めるよ！
int f(int x,vector<int> s) {
	if (x == 0)return 0;
	if (x == 1)return 1;
	if (s[x] != 0)return s[x];
	s[x] = f(x - 1,s) + f(x - 2,s);
	return s[x];
}

//aとｂの最大公約数を求めるよ！
llint gcd(llint a, llint b) {
	if (a < b)swap(a, b);
	if (b == 0)return a;
	return gcd(b, a % b);
}



// a^n mod を計算する
long long modpow(long long a, long long n, long long mod) {
	long long res = 1;
	while (n > 0) {
		if (n & 1) res = res * a % mod;
		a = a * a % mod;
		n >>= 1;
	}
	return res;
}

// mod. m での a の逆元 a^{-1} を計算するよ！
long long modinv(long long a, long long m) {
	long long b = m, u = 1, v = 0;
	while (b) {
		long long t = a / b;
		a -= t * b; swap(a, b);
		u -= t * v; swap(u, v);
	}
	u %= m;
	if (u < 0) u += m;
	return u;
}


//aCbをmod.mで割った余りを求める
ll int c(ll int a, ll int b,ll int m) {
	ll int ans = 1;
	for (ll int i = 0; i < b; i++) {
		ans *= a - i;
		ans %= m;
	}
	for (ll int i = 1; i <= b; i++) {
		ans *= modinv(i, m);
		ans %= m;
	}
	return ans;
}

//m進数のn桁を全列挙やで
void dfs(int m, int n) {

	stack<string> st;
	st.push("");
	while (!st.empty()) {
		string now = st.top();
		st.pop();
		if (now.size() == n) {
			cout << now << endl;
		}
		else {
			for (int i = m-1; i >= 0; i--) {
				string next = now + to_string(i);
				st.push(next);
			}
		}
	}
}

int main(){
	int n,m;
	int MAX = 0,MIN=100001;
	cin >> n>>m;
	rep(i, 0, m) {
		int a, b;
		cin >> a >> b;
		MAX=max(a, MAX);
		MIN = min(b, MIN);
	}
	int ans = MIN - MAX+1;
	if (ans < 0)ans = 0;
	cout << ans << endl;
	
	return 0;
}




  


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

using namespace std;

int main()
{
	int n, r;

	while (scanf("%d %d", &n, &r), n){
		vector<int> v;

		for (int i = 0; i < n; i++){
			v.push_back(n - i);
		}

		for (int i = 0; i < r; i++){
			int p, c;

			scanf("%d %d", &p, &c);

			stack<int> s;

			for (int j = p - 1; j < p + c - 1; j++){
				s.push(v[j]);
				v[j] = 0;
			}

			for (int j = n - 1; j >= c; j--){
				if (v[j] == 0){
					v[j] ^= v[j - c];
					v[j - c] ^= v[j];
					v[j] ^= v[j - c];
				}
			}

			for (int j = c - 1; j >= 0; j--){
				v[j] = s.top();
				s.pop();
			}
		}

		printf("%d\n", v[0]);
	}

	return (0);
}

Measured memory_bytes: 1196
import math
n=int(input())
p=list(map(int, input().split()))
q=list(map(int, input().split()))

a=set()
b=set()

ans=0

for i in range(n):
    ans+=(p[i] - len([j for j in a if j < p[i]])) * math.factorial(n-i-1)
    a.add(p[i])
    ans-=(q[i] - len([j for j in b if j < q[i]])) * math.factorial(n-i-1)
    b.add(q[i])

print(abs(ans))

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
int main(){
	long long d;
	while(cin >> d){
		long long ans=0;
		for(int i=0;i<600;i+=d){
			if(i+d<=600){
				ans+=i*i*d;
			}else{
				ans+=i*i*(600-d);
			}
		}
		cout << ans << endl;
	}
	return 0;
}



Measured memory_bytes: 3092
import math
from functools import reduce

def gcd(*numbers):
    return reduce(math.gcd, numbers)

k = int(input())
ans = 0
for a in range(1, k+1):
  for b in range(a, k+1):
    for c in range(b, k+1):
      t = len({a,b,c})
      if t == 3:
        ans += gcd(a,b,c) * 6
      elif t == 2:
        ans += gcd(a,b,c) * 3
      else:
        ans += gcd(a,b,c)
        
print(ans)

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

typedef long long ll;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
typedef pair<ll, ll> P;
#define rep(i, n) for(ll i = 0; i < n; i++)
#define REP(i, a, b) for(ll i = a; i < b; i++)
#define out(x) std::cout << x << '\n'
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define pb push_back
#define sz(x) ((int)(x).size())
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }
ll lcm(ll a, ll b) { ll g = gcd(a, b); return a / g * b; }
const int dx[4] = { 1, 0, -1,  0 };
const int dy[4] = { 0, 1,  0, -1 };
const int INF = INT_MAX / 2;
const ll  inf = LLONG_MAX / 2;
const int mod = 1000000007;
const int MAX_N = 101010;
const long double PI = acos(-1);

std::map<ll, ll> prime_factor(ll n) {
	std::map<ll, ll> res;
	for (ll i = 2; i * i <= n; i++) {
		while (n % i == 0) {
			++res[i];
			n /= i;
		}
	}
	if (n != 1) res[n] = 1;
	return res;
}

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

	ll n;
	cin >> n;

	vector<ll> e(n + 1, 0);
	for (ll i = 2; i <= n; i++) {
		auto primefactor = prime_factor(i);
		for (auto pf : primefactor) {
			e[pf.first] += pf.second;
		}
	}

	ll ans = 1;
	for (ll i = 2; i <= n; i++) {
		ans *= e[i] + 1;
		ans %= mod;
	}

	out(ans);

	return 0;
}

Measured memory_bytes: 256
from sys import stdin
N, W = [int(x) for x in stdin.readline().rstrip().split()]
 
V = 10**3+1
baggage = [0]*N
 
for l in range(N):
    w, v = [int(x) for x in stdin.readline().rstrip().split()]
    baggage[l] = (w, v)
 
dp = [[10**9+1]*(N*V+1) for _ in range(N+1)]
dp[0][0] = 0  # 最初の要素が0でないと更新が開始しない
 
for i in range(N):
    for v in range(N*V+1):
        if v - baggage[i][1] >= 0:
            dp[i+1][v] = min(dp[i+1][v], baggage[i][0]+dp[i][v-baggage[i][1]])
 
        dp[i+1][v] = min(dp[i][v], dp[i+1][v])
ans = 0
for K in range(N*V+1):
    if dp[N][K] <= W:
        ans = max(ans, K)
print(ans)

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

// 写経
long long cnt;
int l;
int A[1000000];
int n;
vector<int > G;

// 感覚gを指定した挿入ソート
void insertionSort(int A[], int n, int g) {
  for ( int i = g; i < n; i++ ) {
    int v = A[i];
    int j = i - g;
    while ( j >= 0 && A[j] > v ) { // 左の方が大きい場合は
      A[j + g] = A[j];
      j = j - g;
      cnt++;
    }
    A[j + g] = v;
  }
}

void shellSort(int A[], int n) {
  // 数列G = ｛1, 4, 13, 40, 121, 364, 1093, ...} を生成
  for ( int h = 1; ; ) {
    if ( h > n ) break;
    G.push_back(h);
    h = 3*h + 1;
  }

  for ( int i = G.size()-1; i >= 0; i-- ) { // 逆順にG[i] = gを指定
    insertionSort(A, n, G[i]);
  }
}


int main() {
  cin >> n;
  // より速い入力scanf関数を使用
  for (int i = 0; i < n; i++) scanf("%d", &A[i]);
  cnt = 0;

  shellSort(A, n);

  cout << G.size() << endl;
  for ( int i = G.size() - 1; i >= 0; i-- ) {
    printf("%d", G[i]);
    if ( i ) printf(" ");
  }
  printf("\n");
  printf("%d\n", cnt);
  for ( int i = 0; i < n; i++ ) printf("%d\n", A[i]);

  return 0;
}



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

using namespace std;

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

typedef int _loop_int;
#define REP(i,n) for(_loop_int i=0;i<(_loop_int)(n);++i)
#define FOR(i,a,b) for(_loop_int i=(_loop_int)(a);i<(_loop_int)(b);++i)
#define FORR(i,a,b) for(_loop_int i=(_loop_int)(b)-1;i>=(_loop_int)(a);--i)

#define DEBUG(x) cout<<#x<<": "<<x<<endl
#define DEBUG_VEC(v) cout<<#v<<":";REP(i,v.size())cout<<" "<<v[i];cout<<endl
#define ALL(a) (a).begin(),(a).end()

#define CHMIN(a,b) a=min((a),(b))
#define CHMAX(a,b) a=max((a),(b))

// mod
const ll MOD = 1000000007ll;
#define FIX(a) ((a)%MOD+MOD)%MOD

// floating
typedef double Real;
const Real EPS = 1e-11;
#define EQ0(x) (abs(x)<EPS)
#define EQ(a,b) (abs(a-b)<EPS)
typedef complex<Real> P;

int main(){
  string s;
  cin>>s;
  while(true){
    s.pop_back(); s.pop_back();
    int n = s.size();
    if(s.substr(0,n/2) == s.substr(n/2)){
      cout<<n<<endl;
      break;
    }
  }
  return 0;
}


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

using namespace std;

int main(void) {
	const long long INF = 100001;
	int N;
	cin >> N;
	vector<long long> B;
	B.push_back(INF);
	for(int i = 0; i < N - 1; ++i) {
		long long t;
		cin >> t;
		B.push_back(t);
	}
	B.push_back(INF);
	long long ans = 0;
	for(int i = 0; i < N; ++i) {
		ans += min(B[i], B[i + 1]);
	}
	cout << ans << '\n';
	return 0;
}



Measured memory_bytes: 256
import java.util.Scanner;

public class Main { 
	public static void main(String[] args){
		String str;
		int i1, i2;;

		Scanner scan = new Scanner(System.in);

		str = scan.next();
		i1 = Integer.parseInt(str);
		
		str = scan.next();
		i2 = Integer.parseInt(str);

		System.out.println(i1*i2 + " " + 2*(i1+i2));
	}
}

Measured memory_bytes: 17196
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0; i < n; ++i)
#define REPP(i, n) for(int i = 1; i <= n; ++i)
#define REPR(i, n) for(int i = n-1; i >= 0; --i)
#define FOR(i, m, n) for(int i = m; i < n; ++i)
#define ALL(v) v.begin(), v.end()
using namespace std;
typedef long long ll;
const ll MOD = 1000000007;

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

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    string s; cin >> s;
    int n = s.length();
    int ans = 0;
    map<char, int> m;
    REP(i,n) {
        if(s[i]=='g') {
            if(m['g']>m['p']) {
                ++ ans;
                ++ m['p'];
            }
            else ++ m['g'];
        }
        else {
            if(m['g']>m['p']) ++ m['p'];
            else {
                -- ans;
                ++ m['g'];
            }
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 512
#include <iostream>
#include <algorithm>
#include <vector>
#include <iomanip>
#include <map>
#include <queue>

static const int INF = 1000000007;
using ll = long long;
using u32 = unsigned;
using namespace std;

int main() {
    u32 n;
    string s;
    cin >> n >> s;
    vector<int> v(n, 0);
    int p = 1;
    for (int i = 0; i < n; ++i) {
        if(s[i] == '(') for (int j = max(p, i); j < n; ++j) {
            if(s[j] == ')') {
                v[i] = v[j] = 1;
                p = j+1;
                break;
            }
        }
    }
    u32 a = 0, b = 0;
    for (int i = 0; i < n; ++i) {
        if(!v[i]){
            (s[i] == '(' ? a : b)++;
        }
    }
    cout << string(b, '(') << s << string(a, ')') << "\n";
    return 0;
}


Measured memory_bytes: 256
import java.util.Arrays;
import java.util.Scanner;
import java.util.stream.Stream;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int[] line = Stream.of(sc.nextLine().split(" ", 0)).mapToInt(Integer::parseInt).toArray();
		int[] price = Stream.of(sc.nextLine().split(" ", 0)).mapToInt(Integer::parseInt).toArray();
		int sum = 0;
		Arrays.sort(price);

		for (int i = 0; i < line[1]; i++) {
			sum += price[i];
		}

		System.out.println(sum);
	}
}


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

#define ll long long
#define F(i,m,n) for(ll i=m;i<n;i++)
#define Fr(j,n,m) for(ll j=n;j>=m;j--)
#define vll vector<ll>
#define pll pair<ll,ll>
#define ff first
#define ss second
#define vpll vector< pll >
#define tlll tuple < ll ,ll,ll >
/*-------------------------------------*---------------------------------------*/

#define godspeed ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define deb(x) cout << #x << "=" << x << endl
#define cout_array(a) cout<<#a<<"=";for(auto x: a){ cout<<x<<" ";}cout<<endl

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

const ll MAX_PRIME = 1e9+7;
const ll INF = 1e18;


/*I NEED YOU TO WORK FOR TWO HOURS ON THIS NO MATTER WHAT....THE RESULT DOESN'T MATTER.....ITS ALL ABOUT YOUR EFFORTS.
---------------------------------------------------------------------------------------------------------------------*/

ll fast_pow(ll x,ll y,ll z){
    if(y==0)return 1%z;
    else if(y==1)return x%z;
    if(y%2==0){
        ll res = fast_pow(x,y/2,z);
        return (res*res)%z;
    }
    else{
        ll res = fast_pow(x,y/2,z);
        ll temp = (res*res)%z;
        return ((x%z)*temp)%z;
    }
}
ll comb_f(ll n){
    if(n<3)return 0;
    return (n*(n-1)*(n-2))/6;
}
ll simp(ll n){
    if(n<2)return 0;
    return (n*(n-1))/2;
}
int main() {
    godspeed
    ll n;
    cin>>n;
    vll a;
    F(i,0,n){
        ll temp;
        cin>>temp;
        a.push_back(temp);
    }
    sort(a.begin(),a.end());
    ll ans = 0;
    F(i,0,n){
        F(j,i+1,n){
            F(k,j+1,n){
                if(a[i]==a[j] |a[j]==a[k])continue;
                if(a[i] + a[j] > a[k])ans+=1;
            }
        }
    }
    cout<<ans<<endl;

}

Measured memory_bytes: 3540
#include <stdio.h>
#define _USE_MATH_DEFINES
#include<math.h>

double a(double r) {

	double area = r * r* M_PI;
	return area;
}

double c(double r) {

	double circle = 2.0 * r * M_PI;
	return circle;
}

int main(void) {

	double r;

	scanf("%lf", &r);

	//a = r * r * M_PI;
	//b = 2.0 * r * M_PI;

	printf("%f %f\n", a(r), c(r));

	return 0;
}



Measured memory_bytes: 2080
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define INF 2e9
#define ALL(v) v.begin(), v.end()
using namespace std;
typedef long long ll;	

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

	vector<int> a(n);
	REP(i, n) cin >> a[i];
	sort(ALL(a));
	cout << a[n - 1] - a[0] << endl;
	return 0;
}


Measured memory_bytes: 3592
import sys

times=int(input())

num=0

#determine whether same number or not. And if eyes are same, num is +=1, else num is 0 
for i in range(times):
  eyes=input().split()
  if eyes[0]==eyes[1]:
    num+=1
    if num==3:
      print("Yes")
      sys.exit()
  else:
    num=0
    
print("No")
      
    
    

Measured memory_bytes: 9160
#include<cstdio>
#include<algorithm>
#include<cstring>
using namespace std;

char c[100];
int main()
{
    scanf("%s",c);
    int len=strlen(c);
    int flag=0;
    for(int i=0;i<len;i++)
    {
        if(c[i]=='7')
        {
            flag=1;
            break;
        }
    }
    if(flag)
        printf("Yes\n");
    else
        printf("No\n");
    return 0;
}


Measured memory_bytes: 1644
#include <bits/stdc++.h>
using namespace std;
int main(void){
    
    string s;
    int str, end;
    int start = INT_MAX;
    int gool = INT_MIN;
    cin >> s;
    
    for(int i = 0; i < s.size(); i++){
        if(s[i] == 'A')  start = min(start, i);
        if(s[i] == 'Z')  gool = max(gool, i);
    }

    cout << gool - start + 1 << endl;

}


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

typedef unsigned uint;

bool is_exist_bin_search(uint v, std::vector<uint> s){
  uint min = 0, max = s.size();
  while(min < max){
    uint mid = (min + max) / 2;
    uint v_mid = s[mid];
    if(v_mid == v) return true;

    if(v_mid >= v) max = mid;
    else min = mid+1;
  }
  return false;
}

unsigned count(std::vector<uint> s, std::vector<uint> t){
  uint n = 0;
  for(uint i = 0; i < t.size(); i++){
    if(is_exist_bin_search(t[i],s)) n++;
  }
  return n;
}

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

  uint n;
  std::cin >> n;
  std::vector<uint> s(n,0);
  for(uint i = 0; i < n; i++){
    std::cin >> s[i];
  }

  uint q;
  std::cin >> q;
  std::vector<uint> t(q,0);
  for(uint i = 0; i < q; i++){
    std::cin >> t[i];
  }

  std::cout << count(s,t) << '\n';
}

Measured memory_bytes: 2592
#include <algorithm>
#include <iostream>
#include <map>
#include <vector>

using namespace std;

int main() {
  int n, i;
  cin >> n;
  vector<int> odd(n / 2 + 1), even(n / 2 + 1);
  vector<pair<int, int>> o_count(1000001), e_count(1000001);
  for (i = 1; i <= n / 2; i++) {
    cin >> odd[i] >> even[i];
  }
  for (i = 1; i <= n / 2; i++) {
    o_count[odd[i]].second = odd[i];
    e_count[even[i]].second = even[i];
    o_count[odd[i]].first++;
    e_count[even[i]].first++;
  }
  sort(o_count.rbegin(), o_count.rend());
  sort(e_count.rbegin(), e_count.rend());
  if (o_count[0].second != e_count[0].second) {
    cout << n - o_count[0].first - e_count[0].first << "\n";
  } else {
    cout << min(n - o_count[1].first - e_count[0].first,
                n - o_count[0].first - e_count[1].first)
         << "\n";
  }
  return 0;
}

Measured memory_bytes: 16256
N, A, B = map(int, input().split())
S = input()
a = 0
b = 0
ans = "No"
for v, k in enumerate(S, 1):
    if k == "a":
        if a+b < A+B:
            print("Yes")
            a += 1
        else:
            print("No")
    elif k == "b":
        if a+b < A+B and b < B:
            print("Yes")
            b += 1
        else:
            print("No")
    else:
        print("No")

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

using namespace std;

int main(){
	ll a,b,c;
	cin >> a >> b >> c;
	set<ll> st={a,b,c};
	cout << st.size() << endl;
}

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

int main(){
    long double a,b,c;
    cin>>a>>b>>c;
    if(a+b+2.0*sqrt(a*b)<c){
        cout<<"Yes"<<endl;
        return 0;
    }
    else{
        cout<<"No"<<endl;
        return 0;
    }
}

Measured memory_bytes: 256
N, M, K = map(int, input().split())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
cumsum_a = [0] * (N + 1)
cumsum_b = [0] * (M + 1)

for i in range(1, N + 1):
    cumsum_a[i] = cumsum_a[i - 1] + A[i - 1]

for i in range(1, M + 1):
    cumsum_b[i] = cumsum_b[i - 1] + B[i - 1]

ans = 0
bi = M
for i in range(N+1):
    for j in range(bi, -1, -1):
        t = cumsum_a[i] + cumsum_b[j]
        if t <= K:
            ans = max(ans, i + j)
            bi = j
            break

print(ans)


Measured memory_bytes: 117736
n = gets.chomp.to_i

array = []
n.times do
  inner = []
  a = gets.chomp.to_i
  a.times do
    inner.push gets.chomp.split.map(&:to_i)
  end
  array.push inner
end

ans = 0

(2**n).times do |i|
  bits = i.to_s(2).split(//)
  (n - bits.length).times{bits.unshift('0')}

  flg = true
  array.zip(bits).each do |inner, bit|
    next if bit == '0' # 嘘言う人はするー
    if inner.any?{|e| (e.last == 1 && bits[e.first-1] == '0') ||
                      (e.last == 0 && bits[e.first-1] == '1')} # 矛盾
      flg = false
      break
    end
  end

  # p [bits, flg]
  if flg
    ans = [ans, bits.count{|bit| bit=='1'}].max
  end
end

puts ans

Measured memory_bytes: 1788
#include<iostream>
#include<algorithm>
#include<vector>
#include<string>
#include<math.h>
#include<stdlib.h>
using namespace std;
#define MAX 114514
int main(){
    string s;
    cin>>s;
    int ans=MAX;
    for(int i=0;i<s.length()-2;i++){
        int x=stoi(s.substr(i,3));
        ans=min(ans,abs(x-753));
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main{
    public static void main(String[] args){
        Scanner scan = new Scanner(System.in);
        int S = scan.nextInt();
        int h = S / 3600;
        int hi = S % 3600;
        int m = hi / 60;
        int s = S % 60;
        System.out.println(h + ":" + m + ":" + s);
    }
}


Measured memory_bytes: 26220
#include<bits/stdc++.h>
using namespace std;
int main(){
  int n,temp,samec=0, same[200000],dumped=0;
  cin>>n;
  cin>>same[0];
  samec++;
  for(int i=1; i<n; i++){
    cin>>temp;
    if(dumped==0){
      if(same[0] == temp){
	dumped=1;
	int ji = 1;
	i++;
	if(n%samec != 0){
	    cout<<1<<endl;
	    return 0;
	}
        while(i<n){
	  if(ji >= samec) ji =0;
	  cin>>temp;
	  //cout<<"compare "<<ji<<" and "<<i<<endl;
	  if(same[ji] != temp){
	    cout<<1<<endl;
	    return 0;
	  }
	  ji++;
	  i++;
	}
	break;
      }else{
	same[samec] = temp;
	samec++;
      }
    }
  }
  cout<<n/samec<<endl;
  return 0;
}
      



Measured memory_bytes: 3848
#include<iostream>
#include<cstdio>
#include<cstring>
#include <cstdlib>  
#include <math.h>
#include <cmath>
#include<cctype>
#include<string>
#include<set>
#include<iomanip>
#include <map>
#include<algorithm>
#include <functional>
#include<vector>
#include<climits>
#include<stack>
#include<queue>
#include<bitset>
#include <deque>
#include <climits>
#include <typeinfo>
#include <utility> 
using namespace std;
using ll = long long;
template<typename T>using min_priority_queue = priority_queue<T, vector<T>, greater<T>>;
const ll inf = 1LL << 60;
#define all(x) (x).begin(),(x).end()
#define puts(x) cout << x << endl
#define rep(i,m,n) for(ll i = m;i < n;++i)
#define pb push_back
#define fore(i,a) for(auto &i:a)
#define rrep(i,m,n) for(ll i = m;i >= n;--i)

ll MOD = 1e9 + 7;
ll modpow(ll a, ll n) {
	ll res = 1;
	while (n > 0) {
		if (n & 1) res = res * a % MOD;
		a = a * a % MOD;
		n >>= 1;
	}
	return res;
}

ll dp[404][404];
vector<ll>A(404),B(404);
ll sum[404][404];

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

	int N, C;
	cin >> N >> C;
	for (int i = 0; i < N; i++)cin >> A[i];
	for (int i = 0; i < N; i++)cin >> B[i];


	for (int i = 0; i < 402; i++) {
		for (int j = 0; j < 402; j++) {
			sum[i][j+1] += sum[i][j] + modpow(j,i);
			sum[i][j+1] %= MOD;
		}
	}

	dp[0][0] = 1;
	for (int i = 0; i < N; i++) {
		for (int j = 0; j <= C;j++){
			for (int k = 0; k <= j; k++){
				dp[i + 1][j] += (sum[k][B[i]+1]-sum[k][A[i]] + 8LL*MOD)*dp[i][j-k];
				dp[i + 1][j] %= MOD;
			}
		}
	}
	puts(dp[N][C]);
	return 0;
}


Measured memory_bytes: 2816
#include <bits/stdc++.h>
using namespace std;
struct fast_ios { fast_ios(){ cin.tie(0); ios::sync_with_stdio(false); cout << fixed << setprecision(20); }; } fast_ios_;
#define FOR(i, begin, end) for(int i=(begin);i<(end);i++)
#define REP(i, n) FOR(i,0,n)
#define IFOR(i, begin, end) for(int i=(end)-1;i>=(begin);i--)
#define IREP(i, n) IFOR(i,0,n)
#define Sort(v) sort(v.begin(), v.end())
#define Reverse(v) reverse(v.begin(), v.end())
#define all(v) v.begin(),v.end()
#define SZ(v) ((int)v.size())
#define Lower_bound(v, x) distance(v.begin(), lower_bound(v.begin(), v.end(), x))
#define Upper_bound(v, x) distance(v.begin(), upper_bound(v.begin(), v.end(), x))
#define Max(a, b) a = max(a, b)
#define Min(a, b) a = min(a, b)
#define bit(n) (1LL<<(n))
#define bit_exist(x, n) ((x >> n) & 1)
#define debug(x) cout << #x << "=" << x << endl;
#define vdebug(v) cout << #v << "=" << endl; REP(i_debug, v.size()){ cout << v[i_debug] << ","; } cout << endl;
#define mdebug(m) cout << #m << "=" << endl; REP(i_debug, m.size()){ REP(j_debug, m[i_debug].size()){ cout << m[i_debug][j_debug] << ","; } cout << endl;}
#define pb push_back
#define f first
#define s second
#define int long long
#define INF 1000000000000000000
template<typename T> istream &operator>>(istream &is, vector<T> &v){ for (auto &x : v) is >> x; return is; }
template<typename T> ostream &operator<<(ostream &os, vector<T> &v){ for(int i = 0; i < v.size(); i++) { cout << v[i]; if(i != v.size() - 1) cout << endl; }; return os; }
template<typename T> void Out(T x) { cout << x << endl; }
template<typename T1, typename T2> void Ans(bool f, T1 y, T2 n) { if(f) Out(y); else Out(n); }

using vec = vector<int>;
using mat = vector<vec>;
using Pii = pair<int, int>;
using PiP = pair<int, Pii>;
using PPi = pair<Pii, int>;
using bools = vector<bool>;
using pairs = vector<Pii>;

//int dx[4] = {1,0,-1,0};
//int dy[4] = {0,1,0,-1};
//char d[4] = {'D','R','U','L'};

const int mod = 1000000007;
//const int mod = 998244353;
#define Add(x, y) x = (x + (y)) % mod
#define Mult(x, y) x = (x * (y)) % mod

signed main(){
    int N; cin>>N;
    string S; cin>>S;
    int R = 0, B=0;
    REP(i,N){
        if(S[i]=='R') R++;
        if(S[i]=='B') B++;
    } 
    if(R>B) Out("Yes"); 
    else Out("No");
}

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>
#include <iomanip>

#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 ll INF = INT_MAX;
const ll MOD = 1e9+7;

bool isPalindrome(int x){
  string s = to_string(x);
  int n=s.length();
  bool ret=true;
  repeat(i,(n+1)/2){
    ret &= s[i]==s[n-1-i];
  }
  return ret;
}

int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  int N,X;cin>>N>>X;
  int mx=INF;
  repeat(i,N){
    int m;cin>>m;
    X -= m;
    mx = min(mx,m);
  }
  cout << X/mx+N<<endl;
  return 0;
}


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

int main() {

  int N, K;
  cin >> N >> K;

  long long answer = 0;

  if (K % 2 == 0) {
    long long c1 = N / K;
    long long c2 = N / (K / 2) - c1;
    answer = c1 * c1 * c1 + c2 * c2 * c2;
  } else {
    long long c = N / K;
    answer =(long long) c * c * c;
  }

  cout << answer << endl;

  return 0;

}

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

int main() {
  ios::sync_with_stdio(0); cin.tie(0);
  int n;
  cin >> n;
  vector<int> a(n), b(n);
  for(int i = 0; i < n; ++i) {
    cin >> a[i] >> b[i];
  }
  sort(a.begin(), a.end());
  sort(b.begin(), b.end());
  int l = a[n/2] + (n % 2 ? 0 : a[n/2 - 1]);
  int r = b[n/2] + (n % 2 ? 0 : b[n/2 - 1]);
  cout << r - l + 1 << '\n';
}

Measured memory_bytes: 4736
S = input()

N = len(S)

ACGT = {"A", "C", "G", "T"}

ans = 0
for i in range(N):
    if S[i] in ACGT:
        cnt = 0
        for j in range(i, N):
            if S[j] in ACGT:
                cnt += 1
            else:
                break
        ans = max(ans, cnt)

print(ans)

Measured memory_bytes: 8928
int main(){
   int a, b, c;

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

  if((a == b || a == c ) && b != c){
    printf(" Yes");
  } else if((b == a || b == c ) && a != c){
    printf(" Yes");    
  }else if((c == a || c == b ) && a != b){
    printf(" Yes");
  }else {
   printf("No");
  }
  
  return 0;
}



Measured memory_bytes: 128
#include "bits/stdc++.h"
#define YES "YES"
#define NO "NO"
#define Yes "Yes"
#define No "No"
#define DEFAULT LL ans=solve();\
 	if(ans==NONE){\
 	}else{\
 		cout << ans << endl;\
 	}
#define YESNO three(solve(),(OUT(YES),1),(OUT(NO),0))
#define YesNo three(solve(),OUT(Yes),OUT(No))
#define ECHO OUT(solve())
#define three(A,B,C) ((A)?(B):(C))
#define FOR(i,a,b)  for(LL i=(a);i< (LL)(b);i++)
#define EFOR(i,a,b) for(LL i=(a);i<=(LL)(b);i++)
#define RFOR(i,a,b) for(LL i=(b-1);i>=(LL)(a);i--)
#define REP(i,b) FOR(i,zero,b)
#define rep REP
#define EREP(i,b) EFOR(i,zero,b)
#define RREP(i,b) RFOR(i,zero,b)
#define ALL(c) c.begin(),c.end()
#define UNIQUE(c) sort(ALL(c));c.erase(unique(ALL(c)),c.end())
#define MAX(c) (*max_element(ALL(c)))
#define MIN(c) (*min_element(ALL(c)))
#define MP make_pair
#define FI first
#define SE second
#define SI(x) (LL(x.size()))
#define PB push_back
#define DEBUG(a) OUT(a)
#define DEBUG2(a,b) OUT2(a,b)
#define cat cout << __LINE__ << endl
#define OUT(a) cout << (a) << endl
#define OUT2(a,b) cout << (a) <<" "<<(b) << endl
#define zero 0LL
#define all ALL
#define pb emplace_back
#define eb pb
#define int long long
using namespace std;
template<typename T> inline void maximize(T &a, T b) { a = max(a, b); }
template<typename T> inline void minimize(T &a, T b) { a = min(a, b); }
template<typename T> inline bool middle(T a, T b, T c) { return b <= a && a <= c; }
template<class T> inline bool MX(T &l, const T &r) { return l < r ? l = r, 1 : 0; }
template<class T> inline bool MN(T &l, const T &r) { return l > r ? l = r, 1 : 0; }
typedef int LL;
typedef double ld;
typedef int ut;
typedef vector<ut> VI;
typedef vector<VI> VII;
typedef pair<ut, ut> pr;
typedef pair<ut, pr> ppr;
typedef vector<pr> Vpr;
typedef vector<ppr> Vppr;
typedef tuple<int, int, int, int> tapu;
typedef vector<tapu> Vtapu;
typedef priority_queue<pr, Vpr > PQ;
inline void outputVI(VI x) { REP(i, SI(x)) { cout << three(i, " ", "") << x[i]; }OUT(""); }
const int SIZE1 = 5e5 + 1000;
const int SIZE2 = 5010;
const int SIZE3 = 430;
const int SIZE = SIZE1;
const int MAPSIZE = 40;
const LL p998 = 998244353;
const LL p107 = 1000000007;
const LL p = p107;
const LL INF = 1LL << 60;
const long double EPS = 1e-7;
const LL NONE=-2;
#define endl "\n"
ut N, M,K,  Q, D, H, W;
VI edges[SIZE];
LL vals[SIZE], answer = zero;
//LL A[SIZE],B[SIZE],C[SIZE];
LL solve(){
	cin >> H >> W >> N;
	LL ma=max(H,W);
	return (N+ma-1)/ma;

	return NONE;
}
 signed main() {
 
	ios_base::sync_with_stdio(false);
	cout << fixed << setprecision(10);
	LL T=1;

	REP(i,T){
		DEFAULT;

	}
	
//	YesNo;
//	YESNO;
//	three(solve(),OUT("First"),OUT("Second"));
	//cin >> N;
	return 0;
 
}


Measured memory_bytes: 13824
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll inf = 1LL<<60;

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

  vector<vector<ll>> dp(N+1, vector<ll>(N+1, 0));
  for (int len=2; len<=N; len++) {
    for (int l=0; l+len<=N; l++) {
      int r = l+len;
      ll sum = 0;
      for (int i=l; i<r; i++) {
        sum += a[i];
      }
      ll tmp = inf;
      for (int i=l; i<r-1; i++) {
        tmp = min(tmp, dp[l][i+1]+dp[i+1][r]);
      }
      dp[l][r] = sum+tmp;
    }
  }
  cout << dp[0][N] << endl;

  return 0;
}


Measured memory_bytes: 1536
#include<bits/stdc++.h>
using namespace std;
#define ll long long
int main()
{
	int n,i,j;
	cin>>n;
	int a[n];
	for (i=0;i<n;i++)
	cin>>a[i];
	sort(a,a+n);
	cout<<a[n-1]-a[0];
}


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

int main() {
  ll n=3;
  mat c(n,vec(n));
  for(ll i=0;i<n;i++) for(ll j=0;j<n;j++) cin >> c[i][j];
  ll f=1;
  for(ll i=0;i<n-1;i++) {
    vec a(n);
    for(ll j=0;j<n;j++) {
      a[j]=c[i+1][j]-c[i][j];
    }
    if(a[0]!=a[1]||a[1]!=a[2]) {
      f=0;
    }
  }
  for(ll i=0;i<n-1;i++) {
    vec a(n);
    for(ll j=0;j<n;j++) {
      a[j]=c[j][i+1]-c[j][i];
    }
    if(a[0]!=a[1]||a[1]!=a[2]) {
      f=0;
    }
  }
  if(f) cout << "Yes" << endl;
  else cout << "No" << endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<climits>
#include<vector>
#include<utility>
#include<cmath>
#include<string>
#include<cstring>
#include<map>
#define rep(i,n) for(int i=0;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define prin(arg) std::cout<<arg<<"\n"
#define prin2(arg1,arg2) std::cout<<arg1<<" "<<arg2<<"\n"
#define fill(arg,n) std::memset(arg,n,sizeof(arg))
using std::cin;
typedef long long ll;
typedef std::pair<int,int> pi;
typedef std::vector<int> vi;
const int INF=1e+9;
const ll INFLL=1e+17;
const ll MOD=1e+9+7;
ll N;
ll perm(ll x){
  if(x==0) return 1;
  return x*perm(x-1)%MOD;
}
int main(){
  cin>>N;
  prin(perm(N));
  return 0;
}


Measured memory_bytes: 1792
#include <cmath>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <iostream>
#include <algorithm>
#include <bits/stdc++.h>
#define ll long long
using namespace std;
void put(int x){
	if(x<0) {
		putchar('-');
		x*=-1;
	}
	if(x==0) {
		putchar('0');
	}
	int num=0;
	char c[15];
	while(x) {
		c[++num]=(x%10)+48;
		x/=10;
	}
	while(num) {
		putchar(c[num--]);
	}
	putchar('\n');
}
inline void in(int &x){
	char ch=getchar();
	int flag=1;
	while(!(ch>='0'&&ch<='9')) {
		if(ch=='-')
			flag*=-1;
		ch=getchar();
	}
	x=ch-'0';
	ch=getchar();
	while(ch>='0'&&ch<='9') {
		x=((x<<3)+(x<<1))+ch-'0';
		ch=getchar();
	}
	x*=flag;
}
int a,f[105];
int main(){
	//freopen(".in","r",stdin);
	//freopen(".out","w",stdout);
	in(a);memset(f,0,sizeof f);
	for(int i=1;i<=9;i++)
	for(int j=1;j<=9;j++)
	f[i*j]=1;
	if(f[a])printf("Yes\n");
	else printf("No\n");
	return 0;
}


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

public class Main {
	public static void main(String args[]){//double 处理果盘
		Scanner in = new Scanner(System.in);
		String str = in.nextLine();
		String[] s = str.split(" ");
		String[] s_re = new String[s.length];
		for (int i=0;i<s.length;i++){
			switch(s[i]){
			case "Sunny":
				s_re[i] = "Cloudy";
				break;
			case "Cloudy":
				s_re[i] = "Rainy";
				break;
			case "Rainy":
				s_re[i] = "Sunny";
				break;
				default:
			}
		}
		for (int i=0;i<s.length;i++){
			System.out.print(s_re[i]+" ");
		}
	}
}	

Measured memory_bytes: 21844
get_number(Number) :-
    get_string(String),
    number_string(Number, String).

get_number(A, B) :-
    get_number(A),
    get_number(B).

get_number(A, B, C) :-
    get_number(A, B),
    get_number(C).

get_string(String) :-
    current_input(Input),
    read_string(Input, ' \n', '', _, String).

/* memo
    code(int)
    string_code(1, S, C), (C: code)
    char_code(X, Y) (X: char, Y: code)
    string_chars(S, S2) (S: string, S2: [char])
    to_lower(C, C2) (C: char? C2: code?)
    sub_string

    f(0, [], []).
    f(Z, [X|Xs], [Y|Ys]) :- X = Y, f(Z1, Xs, Ys), Z is Z1 + 1.
    f(Z, [_|Xs], [_|Ys]) :- f(Z, Xs, Ys).

    match: =, \=

    numeric: <,=<, >, >= (eval)
    lexicographically: @<. @=<, @>, @>=
    value?: =:=, =\= (eval)
    identical: ==, \==
*/

main :-
    get_number(X),
    X div 100 =:= X mod 10 -> writeln("Yes") ; writeln("No").


Measured memory_bytes: 7980
# coding: utf-8
import time
import re
import math

def main():
    global N,A,memo
    N=int(input())
    A=[int(input()) for  a in range(N)] 
    if sum(A)%10==0:
        nm0=[]
        for a in A:
            if not a%10==0:
                nm0.append(a)
        if len(nm0)==0:
            print(0)
        else:
            print(sum(A)-min(nm0))

    else:
        print(sum(A))

main()

Measured memory_bytes: 3184
# colorful slimes
class SegTree():
    # 1-indexed
    def __init__(self, lists, function, basement):
        self.n = len(lists)
        self.K = (self.n-1).bit_length()
        self.f = function
        self.b = basement
        self.seg = [basement]*(2**(self.K+1)+1)
        X = 2**self.K
        for i, v in enumerate(lists):
            self.seg[i+X] = v
        for i in range(X-1, 0, -1):
            self.seg[i] = self.f(self.seg[i << 1], self.seg[i << 1 | 1])

    def update(self, k, value):
        X = 2**self.K
        k += X
        self.seg[k] = value
        while k:
            k = k >> 1
            self.seg[k] = self.f(self.seg[k << 1], self.seg[(k << 1) | 1])

    def query(self, L, R):
        num = 2**self.K
        L += num
        R += num
        vL = self.b
        vR = self.b
        while L < R:
            if L & 1:
                vL = self.f(vL, self.seg[L])
                L += 1
            if R & 1:
                R -= 1
                vR = self.f(self.seg[R], vR)
            L >>= 1
            R >>= 1
        return self.f(vL, vR)


N, X = map(int, input().split())
A = list(map(int, input().split()))
B = [0 for i in range(3*N)]
for i in range(N):
    B[i] = B[i+N] = B[i+2*N] = A[i]

T = SegTree(B, min, 10**10)
ans = 10**30
# ちょうどN回の要素増加が必要。
# セグメント木を利用した解答
for cnt in range(N+1):
    # cnt回数だけループ操作を行うとする。
    # N回以上のループを伴う解答は自明回より不最適なのでのぞいて良い。
    sub = X*cnt
    for i in range(1+N, 2*N+1):
        sub += T.query(i-cnt, i+1)
    ans = min(sub, ans)
print(ans)

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

int main(){
  string s1, s2, s3;
  cin >> s1 >> s2 >> s3;
  
  char S1, S2, S3;
  S1 = toupper(s1.at(0));
  S2 = toupper(s2.at(0));
  S3 = toupper(s3.at(0));
  
  cout << S1 << S2 << S3 << endl;
  
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, a, n) for(int i = a; i < n; i++)
#define REP(i, n) rep(i, 0, n)
#define repb(i, a, b) for(int i = a; i >= b; i--)
#define all(a) a.begin(), a.end()
#define int long long
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
using namespace std;
typedef pair<int, int> P;
const int mod = 1000000007;
const int INF = 1e12;


signed main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n;
    cin >> n;
    n++;
    vector<int> d(n);
    d[0] = 0;
    rep(i, 1, n) cin >> d[i];
    sort(all(d));
    vector<vector<int> > e(2, vector<int> (n));
    rep(i, 1, n){
        e[0][i] = d[i];
        e[1][i] = 24 - d[i];
        if(e[1][i] == 24) e[1][i] = 0;
    }
    e[0][0] = 0; e[1][0] = 0;
    int ans = 0;
    rep(i, 1, 25){
        int id = 0, now = 0;
        bool f[55] = {}, g = true;
        f[0] = true;
        rep(j, 1, n){
            if(e[0][j] >= now + i){
                now = e[0][j];
                f[j] = true;
            }
        }
        repb(j, n - 1, 1){
            if(f[j]) continue;
            else{
                if(e[1][j] >= now + i){
                    now = e[1][j];
                    f[j] = true;
                }else{
                    g = false;
                }
            }
        }
        int tmp = min(now, 24 - now);
        if(tmp < i) g = false;
        int cnt = 0;
        rep(j, 0, n) if(f[j]) cnt++;
        if(cnt != n) g = false;
        if(g) ans = i;
    }
    ans = min(ans, 24 - ans);
    // if(ans == 24) ans = 0;
    // if(n == 2) ans = d[1];
    cout << ans << endl;
}

Measured memory_bytes: 256
#![allow(non_snake_case, unused)]
use std::cmp::*;
use std::collections::*;
use std::f64::consts::*;

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

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

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

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

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

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

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

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

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

fn dfs(m: u64, n: u64) -> u64 {
    if m > n {
        0
    } else {
        let mut ret = if is_753(m) { 1 } else { 0 };
        for x in [7, 5, 3].iter() {
            ret += dfs(m * 10 + x, n);
        }
        ret
    }
}

fn is_753(n: u64) -> bool {
    let mut n = n;
    let mut is_7 = 0;
    let mut is_5 = 0;
    let mut is_3 = 0;

    while n != 0 {
        match n % 10 {
            7 => is_7 += 1,
            5 => is_5 += 1,
            3 => is_3 += 1,
            _ => return false,
        }
        n /= 10;
    }
    is_7 > 0 && is_5 > 0 && is_3 > 0
}

fn main() {
    input!{
        n: u64,
    }
    println!("{}", dfs(0, n));
}


Measured memory_bytes: 4352
#include <iostream>
#include<cmath>
using namespace std;
int fib[1010];
int d,V;
int parent[1010];
void makefib(){
  fib[0]=2;fib[1]=3;
  for(int i=2;i<1010;i++)fib[i]=(fib[i-1]+fib[i-2])%1001;
}
int root(int x){
  return (parent[x]==x)?x:root(parent[x]);
}
bool sameset(int x,int y){
  return root(x)==root(y);
}
void union_set(int x,int y){
  parent[root(y)]=root(x);
}
int main(){
  makefib();
  while(cin>>V>>d){
    for(int i=0;i<V;i++)parent[i]=i;
    for(int i=0;i<V;i++){
      for(int j=0;j<V;j++){
        if(abs(fib[i]-fib[j])<d&&!sameset(i,j))union_set(i,j);
      }
    }
    int cnt=0;
    for(int i=0;i<V;i++)if(root(i)==i)cnt++;
    cout<<cnt<<endl;
  }
}

Measured memory_bytes: 1172
#include <iostream>
#include <array>
#include <algorithm>
#include <vector>
#include <bitset>
#include <set>
#include <unordered_set>
#include <cmath>
#include <complex>
#include <deque>
#include <iterator>
#include <numeric>
#include <map>
#include <unordered_map>
#include <queue>
#include <stack>
#include <string>
#include <tuple>
#include <utility>
#include <limits>
#include <iomanip>
#include <functional>
#include <cassert>
using namespace std;

using ll=long long;
template<class T> using V = vector<T>;
template<class T, class U> using P = pair<T, U>;
using vll = V<ll>;
using vvll = V<vll>;
#define ALL(v) v.begin(),v.end()
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; }
#define DEBUG_VLL(vec) for(int sz=0;sz<int(vec.size());sz++) std::cerr<<vec[sz]<<(sz==vec.size()-1?'\n':' ');

const long long MOD = 1000000007;
const long long HIGHINF = (long long)1e18;
const int INF = (int)1e9;

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    string s; cin >> s;
    int n = s.size();
    V< V<int> > dp(n + 1, V<int>(3, 0));
    dp[1][1] = dp[2][2] = 1;
    for (int i = 1; i < n; i++) {
        for (int pre = 1; pre <= 2; pre++) {
            if (i - pre < 0) continue;
            string pres = s.substr(i - pre, pre);
            for (int nxt = 1; nxt <= 2; nxt++) {
                if (i + nxt > n) continue;
                string nxts = s.substr(i, nxt);
                if (pres == nxts) continue;
                chmax(dp[i + nxt][nxt], dp[i][pre] + 1);
            }
        }
    }
    cout << max(dp[n][1], dp[n][2]) << '\n';
    return 0;
}


Measured memory_bytes: 14448
sx, sy, tx, ty = map(int, input().split())
s = ""
dx, dy = abs(tx - sx), abs(ty - sy)
dxy = dx + dy
for a in range(dx):
  s += "R"
for b in range(dy):
  s += "U"
for c in range(dx):
  s += "L"
for d in range(dy):
  s += "D"
s += "D"
for e in range(dx + 1):
  s += "R"
for f in range(dy + 1):
  s += "U"
s += "L"
s += "U"
for g in range(dx + 1):
  s += "L"
for h in range(dy + 1):
  s += "D"
s += "R"
print(s)

Measured memory_bytes: 3064
#include <stdio.h>

#define INF 10000000

int main()
{
    int n, p[101], m[101][101];
    int i, j, k, l, q;

    scanf("%d", &n);
    for (i = 1; i <= n; i++)
        scanf("%d%d", &p[i - 1], &p[i]);

    for (i = 1; i <= n; i++)
        m[i][i] = 0;
        
    for (l = 2; l <= n; l++)
    {
        for (i = 1; i <= n - l + 1; i++)
        {
            j = i + l - 1;
            m[i][j] = INF;
            for (k = i; k < j; k++)
            {
                q = m[i][k] + m[k + 1][j] + p[i - 1] * p[k] * p[j];
                m[i][j] = (m[i][j] > q) ? q : m[i][j];
            }
        }
    }

    printf("%d\n", m[1][n]);

    return 0;
}


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

int main(){
	int N,K;
	cin >> N >> K;
	int R,S,P,loop;
	map<char,int> RSP;
	cin >> R >> S >> P;
	RSP['r']=R;
	RSP['s']=S;
	RSP['p']=P;
	vector<char> T(N);
	char Tm;
	for(loop=0;loop<N;loop++){
		cin >> Tm;
		if(Tm=='r'){
			T[loop]='p';
		}else if(Tm=='s'){
			T[loop]='r';
		}else{
			T[loop]='s';
		}
	}
	int ans=0;
	for(loop=0;loop<N;loop++){
		if(loop<K||T[loop]!=T[loop-K]){
			ans+=RSP[T[loop]];
		}else{
			T[loop]='L';
		}
	}
	cout << ans << endl;
	return 0;
}

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

int main() {
    int N ;
    cin >> N ;
    
    vector<string> S(N) ;
    
    for( int i=0 ;i<N ; i++){
        cin >> S.at(i) ;
    }
    int AC = 0 ;
    int WA = 0 ;
    int TLE = 0 ;
    int RE = 0 ;
    
    for( int i=0 ; i<N ; i++){
        if( S.at(i) == "AC" ){
            AC++ ;
        }
        else if ( S.at(i) == "WA" ){
            WA++ ;
        }
        else if( S.at(i) == "TLE" ){
            TLE++ ;
        }
        else{
            RE++ ;
        }
    }
    
    cout << "AC " << "x " << AC << endl;
    cout << "WA " << "x " << WA << endl;
    cout << "TLE " << "x " << TLE << endl;
    cout << "RE " << "x " << RE << endl;
}


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

int main()
{
  int n, m;
  long k;
  cin >> n >> m >> k;
  long t;
  long a[n+1], b[m+1];
  a[0] = 0;
  b[0] = 0;
  for(int i = 1; i<= n;++i){
    cin >> t;
    a[i] = a[i-1]+t;
  }
  for(int i = 1; i<= m;++i){
    cin >> t;
    b[i] = b[i-1]+t;
  }
  int count = 0;
  int sj, ej;
  ej = m+1;
  for(int i = 0; i<= n;++i){
    sj = (count - i > 0) ? count - i : 0;
    for(int j = sj; j < ej;++j){
      if(a[i] + b[j] <= k){
        count = i + j;
      }else{
        ej = j;
        break;
      }
    }
    //cout << count << endl;
  }
  cout << count << endl;
}


Measured memory_bytes: 6744
main :: IO ()
main = do
    (a, b) <- getPair
    print $ solve a b

type Pair a = (a, a)
getPair = (\(x:y:_) -> (x, y)) . map read . words <$> getLine :: Read a => IO (Pair a)

data Sign = Negative | Zero | Positive deriving Show

solve :: Int -> Int -> Sign
solve a b
  | 0 < a = Positive
  | a <= 0 && 0 <= b = Zero
  | b < 0 = if abs (b - a) `mod` 2 == 0
    then Negative
    else Positive


Measured memory_bytes: 508