akhauriyash/Code-Regression huggingface dataset:
//#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>

using namespace std;

//vector string deque break continue
#define forn(i, s, f) for (int i = (int)s; i < (int)f; i++)
#define ll long long
#define ull unsigned long long
#define ld long double
#define pii pair <int, int>
#define fs first
#define sc second
#define pf push_front
#define pb push_back
#define pop_f pop_front
#define pop_b pop_back
#define eb emplace_back
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define sz(x) (int)(x).size()

#ifdef DEBUG
#else
    #define cerr if (false) cerr
#endif

template <typename T> istream& operator>>(istream& in, vector <T>& a) {for (auto& i : a) in >> i; return in;}
template <typename T> ostream& operator<<(ostream& out, vector <T>& a)  {for (auto& i : a) out << i << " "; return out;}
template <typename T, typename U> void chkmin(T& a, U b) {if (a > b) a = b;}
template <typename T, typename U> void chkmax(T& a, U b) {if (a < b) a = b;}

#define int long long

main() {
    ios_base::sync_with_stdio(0), cin.tie(0);
    int n, d;
    cin >> n >> d;
    int ans = 0;
    forn (i, 0, n) {
        int x, y;
        cin >> x >> y;
        if (x * x + y * y <= d * d)
            ans++;
    }
    cout << ans;
    return 0;
}

Measured memory_bytes: 3652
#include<bits/stdc++.h>
using namespace std;
#define ll long long
const int mod=1e9+7;
ll dp[2005][2005];
int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    ll k,n;
    for(int i=0;i<=2004;i++)
    {
        for(int j=i;j<=2004;j++)
        {
            if(i==0)
            {
                dp[i][j]=1;
            }
            else
            {
                dp[i][j]=(dp[i-1][j-1]+dp[i][j-1])%mod;
            }
        }
    }
    cin>>n>>k;
    ll mu=n-k+1;
     ll r=1;
      ll lanban=k-1;
      ll fen=0;
    while(k--)
    {
        ll ans=dp[fen][lanban];





        cout<<(dp[r][mu]*ans)%mod<<'\n';


        r++;
        fen++;


    }







}

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

ll dp[100005][13];
ll mod = pow(10,9)+7;

int main(int argc, char *argv[]) {
  ios::sync_with_stdio(false);
	cin.tie(nullptr);
	cout.tie(nullptr);

  string s;cin>>s;
  int n = s.size();

  dp[0][0]=1;
  for(int i=0;i<n;i++){
    char c;
    if(s[i]=='?')c = -1;
    else c=s[i]-'0';

    for(int j=0;j<10;j++){
      if(c!=-1&&c!=j)continue;
      for(int k=0;k<13;k++){
        int nx = (10*k+j)%13;
        dp[i+1][nx] += dp[i][k];
        dp[i+1][nx] %= mod;
      }
    }
  }

  cout<<dp[n][5]<<endl;

  return 0;
}


Measured memory_bytes: 10704
#include <iostream>
#include <algorithm>
#include <functional>
#include <string>
#include <vector>
using namespace std;
#define MAXSIZE 200
#define MAXL 100
typedef long long int lli;

lli getAbs(lli x);

int main(){
    lli n, sum = 0;
    cin >> n;
    vector<lli> card_vec;
    for(lli i = 0; i < n; i++){
        lli card;
        cin >> card;
        sum += card;
        card_vec.push_back(card);
    }

    lli lSum = 0, ans = __LONG_LONG_MAX__;
    for(lli i = 0; i < n - 1; i++){
        lSum += card_vec[i];
        lli rSum = sum - lSum;
        ans = min(ans, getAbs(lSum - rSum));
    }
    cout << ans << endl;
    return 0;
}

lli getAbs(lli x){
    return (x > 0)? x : -x;
}

Measured memory_bytes: 2420
def resolve():
    X, Y, Z, K = list(map(int, input().split()))
    A = sorted(list(map(int, input().split())), reverse=True)
    B = sorted(list(map(int, input().split())), reverse=True)
    C = sorted(list(map(int, input().split())), reverse=True)
    
    # 「美味しさの和がp以上である組み合わせがK個以上存在する」ならtrue
    def isOk(p):
        cnt = 0
        for i in range(X):
            for j in range(Y):
                for k in range(Z):
                    if A[i]+B[j]+C[k] < p: # sorted
                        break
                    cnt += 1
                    if cnt >= K:
                        return True
        return False
    
    # p以上の美味しさの和をすべて返す
    def values_higher_than(p):
        sums = []
        for i in range(X):
            for j in range(Y):
                for k in range(Z):
                    if A[i]+B[j]+C[k] < p: # sorted
                        break
                    sums.append(A[i]+B[j]+C[k])
        return sums
    
    left = -1
    right = 10**11
    while (right - left) > 1:
        mid = left + (right - left) // 2
        if isOk(mid):
            left = mid
        else:
            right = mid
    
    #print(left)
    ans = sorted(values_higher_than(left), reverse=True)
    for i in range(K):
        if i < len(ans):
            print(ans[i])
        else:
            print(left)


if '__main__' == __name__:
    resolve()

Measured memory_bytes: 197588
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int input = sc.nextInt();
		int nums[] = { 8, 27, 64, 125, 216, 343, 512, 729, 1000, 32, 243, 128, 512 };
		for (int i = 1; i <= 32; i++) {

			if (input == i * i) {
				System.out.println(i * i);
				return;
			}

			if ((input > i * i) && input < (i + 1) * (i + 1)) {
				int binary = i * i;
				for (int s : nums) {
					if (s <= input && s > binary) {
						System.out.println(s);
						return;
					}
				}
				System.out.println(binary);
				return;
			}
		}
	}
}

Measured memory_bytes: 20820
#include<iostream>
#include<cmath>
#include<cstdlib>
#include<string>

using namespace std;

int main() {
   string S;
   cin >> S;

   int ans = 0;
   for (int i = 0; i < S.size(); i++) {
      if (S[i] == '+') ans++;
      else ans--;
   }
  
   cout << ans << endl;

   return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <boost/range/algorithm.hpp>
#include <boost/range/numeric.hpp>
#include <boost/integer/common_factor.hpp>
#include <boost/integer/common_factor_rt.hpp>
#include <boost/multiprecision/cpp_dec_float.hpp>

using std::string;
using std::vector;
using std::set;
using std::multiset;
using std::unordered_set;
using std::map;
using std::multimap;
using std::unordered_map;
using std::pair;
using std::cin;
using std::cout;

typedef uintmax_t    ull;
typedef intmax_t     ll;
typedef uint64_t     ul;
typedef uint32_t     ui;
typedef uint8_t      uc;

typedef boost::multiprecision::number<boost::multiprecision::cpp_dec_float<1000>> cpp_dec_float_1000;

constexpr char CRLF  = '\n';
constexpr char SPACE = ' ';
constexpr char VECTOR_COUT_SEPARATOR = SPACE;
constexpr ll INF = 1000'000'007;

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; }
template<class T> std::ostream& operator<< (std::ostream& os, const std::vector<T>& vc) { for(auto it = vc.begin(); it != vc.end(); ++it) { if (std::next(it) == vc.end()) os << *it; else os << *it << VECTOR_COUT_SEPARATOR; } return os; }
template<class T1, class T2> inline std::ostream & operator<< (std::ostream & os, const std::pair<T1, T2> & p) { return os << p.first << ' ' << p.second; }

void solve(void)
{
  int N; cin >> N;
  vector<ll> H(N);
  ll A, B; cin >> A >> B;
  for (auto& h : H) {
    cin >> h;
  }
  boost::sort(H, std::greater<ll>());

  ll C = A - B;
  ll inf = (H[0] + B - 1) / B;

  auto judge = [&H, &B, &C](const auto current){
    ll r{};
    for (auto h : H) {
      h -= B * current;
      if (h <= 0) {
        continue;
      }
      ll num = (h + C - 1) / C;
      r += num;
    }
    return r <= current;
  };

  ll min = 0;
  ll itr = inf / 2;
  ll max = inf;
  while (max - min != 1) {
    if (judge(itr)) {
      max = itr;
      itr = min + (itr - min) / 2;
    } else {
      min = itr;
      itr = max - (max - itr) / 2;
    }
  }

  auto ans = max;
  cout << ans << CRLF;
  return;
}

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

  solve();

  return 0;
}


Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
#define ll long long
const int mod=1e9+7;
const int maxn=2e5+5;
ll a[maxn];
int main()
{
	ios::sync_with_stdio(false);
	cin.tie(0);
	ll k,n;
	cin>>k>>n;
	ll max1=-1;
	ll sum=0;
	for(int i=1;i<=n;i++)
    {
        cin>>a[i];
    }
    for(int i=1;i<n;i++)
    {
        sum+=abs(a[i+1]-a[i]);
        max1=max(max1,abs(a[i+1]-a[i]));
    }
    max1=max(abs(a[n]-k-a[1]),max1);
    sum+=abs(a[n]-k-a[1]);

    cout<<sum-max1<<'\n';





}


Measured memory_bytes: 1792
#include <iostream>
#include <string>
#include <algorithm>
#include <cassert>
#include <set>
#include <vector>
#include <cmath>
#include <bitset>
#include <functional>
#include <limits>
#include <map>
using namespace std;

typedef long long ll;
#define rep1(i, n) for(ll i = 1; i <=(ll)(n); i++)
#define rep0(i, n) for(ll i = 0; i <=(ll)(n); i++)

ll pow(ll a, ll n) { //compute a^n with o(logn)
    ll res = 1;
    while (n > 0) {
        if (n & 1) res = res * a;
        a = a * a;
        n >>= 1;
    }
    return res;
}

ll pow(ll a, ll n, ll mod) { //compute a^n (mod mod) with o(logn)
    ll res = 1;
    while (n > 0) {
        if (n & 1) res = res * a % mod;
        a = a * a % mod;
        n >>= 1;
    }
    return res;
}

const int MAX = 199;
const int MOD = 1000000007;
ll fac[MAX], finv[MAX], inv[MAX];

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

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

//順列計算
ll PER(int n, int k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[n - k] % MOD) % MOD;
}

int main(){
    ll x;
    cin >> x;
    if(400 <= x && x < 600){
        cout << "8" << endl;
    }else if(600 <= x && x < 800){
        cout << "7" << endl;
    }else if(800 <= x && x < 1000){
        cout << "6" << endl;
    }else if(1000 <= x && x < 1200){
        cout << "5" << endl;
    }else if(1200 <= x && x < 1400){
        cout << "4" << endl;
    }else if(1400 <= x && x < 1600){
        cout << "3" << endl;
    }else if(1600 <= x && x < 1800){
        cout << "2" << endl;
    }else if(1800 <= x && x < 2000){
        cout << "1" << endl;
    }
    return 0;
}

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

#include <algorithm>
#include <cassert>
#include <cfloat>
#include <complex>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <regex>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <vector>

using namespace std;

#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
#define rep(i, n) for (ll i = 0; i < (n); ++i)
#define repLRE(i, l, r) for (ll i = (l); i <= (r); ++i)
#define rrepLRE(i, l, r) for (ll i = (l); i >= (r); --i)
#define Sort(v) sort(v.begin(), v.end())
#define rSort(v) sort(v.rbegin(), v.rend())
#define Reverse(v) reverse(v.begin(), v.end())
#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))

using ll = long long;
using ull = unsigned long long;
using P = pair<ll, ll>;
using T = tuple<ll, ll, ll>;
using vll = vector<ll>;
using vP = vector<P>;
using vT = vector<T>;
using vvll = vector<vector<ll>>;
using vvP = vector<vector<P>>;
using dqll = deque<ll>;

ll dx[9] = {-1, 1, 0, 0, -1, -1, 1, 1, 0};
ll dy[9] = {0, 0, -1, 1, -1, 1, -1, 1, 0};

/* Macros reg. ends here */

const ll INF = 1LL << 50;

int main() {
  // ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
  cout << fixed << setprecision(15);

  ll n;
  cin >> n;

  vll dts(n), dxs(n), dys(n);
  ll pt = 0, px = 0, py = 0;
  rep(i, n) {
    ll t, x, y;
    cin >> t >> x >> y;
    dts[i] = t - pt, dxs[i] = abs(x - px), dys[i] = abs(y - py);
    pt = t, px = x, py = y;
  }

  bool ok = true;
  rep(i, n) {
    ok = dxs[i] + dys[i] <= dts[i] && ((dxs[i] ^ dys[i] ^ dts[i]) & 1) == 0;
    if (!ok) break;
  }

  string ans = ok ? "Yes" : "No";

  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 5552
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner std = new Scanner(System.in);
        long w = std.nextLong();
        long h = std.nextLong();
        long x = std.nextLong();
        long y = std.nextLong();
        
        int same = (w / 2.0 == x && h / 2.0 == y) ? 1 : 0;
        double square = w * h / 2.0;
        System.out.println(String.format("%s %d", square, same));
    }
}

Measured memory_bytes: 21844
#include <iostream>
#include <sstream>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <string>
#include <vector>
#include <list>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <bitset>
#include <numeric>
#include <climits>
#include <cfloat>
using namespace std;

int main()
{
    for(;;){
        int ret;
        cin >> ret;
        if(ret == 0)
            return 0;

        for(int i=0; i<9; ++i){
            int a;
            cin >> a;
            ret -= a;
        }
        cout << ret << endl;
    }
}

Measured memory_bytes: 0
import sys
# import math
# import bisect
# import numpy as np
# from decimal import Decimal
# from numba import njit, i8, u1, b1 #JIT compiler
# from itertools import combinations, product
# from collections import Counter, deque, defaultdict

# sys.setrecursionlimit(10 ** 6)
MOD = 10 ** 9 + 7
INF = 10 ** 9
PI = 3.14159265358979323846

def read_str():      return sys.stdin.readline().strip()
def read_int():      return int(sys.stdin.readline().strip())
def read_ints():     return map(int, sys.stdin.readline().strip().split())
def read_ints2(x):   return map(lambda num: int(num) - x, sys.stdin.readline().strip().split())
def read_str_list(): return list(sys.stdin.readline().strip().split())
def read_int_list(): return list(map(int, sys.stdin.readline().strip().split()))
def GCD(a: int, b: int) -> int: return b if a%b==0 else GCD(b, a%b)
def LCM(a: int, b: int) -> int: return (a * b) // GCD(a, b)

class Combination:
    def __init__(self, n, p):
        self.n = n
        self.p = p
        self.note = [1, 1]
        self.noteinv = [1, 1]
        self.inv = [0, 1]
        self.calc()

    def calc(self):
        for i in range(2, self.n + 1):
            self.note.append((self.note[-1] * i) % self.p)
            self.inv.append((-self.inv[self.p % i] * (self.p // i)) % self.p)
            self.noteinv.append((self.noteinv[-1] * self.inv[-1]) % self.p)
    
    def nCr(self, n, r):
        n = self.n
        if r < 0 or n < r:
            return 0
        r = min(r, n - r)
        return (self.note[n] * self.noteinv[r] * self.noteinv[n - r]) % self.p

def Main():
    n, m, k = read_ints()
    # m * _{n-1}C_k * 1^k * (m-1)^{n-1-k}

    p = 998244353
    modm = [1]
    for _ in range(1, n):
        modm.append((modm[-1] * (m - 1)) % p)
    
    cmb = Combination(n - 1, p)
    ans = 0
    for i in range(k + 1):
        ans += (cmb.nCr(n - 1, i) * m * modm[n - 1 - i]) % p
        ans %= p
    print(ans)

if __name__ == '__main__':
    Main()

Measured memory_bytes: 40720
def input_n
  gets.to_i               # 単一整数
end

def input_s
  gets.chomp              # 文字列。chompを付けないと改行文字がついてくる
end

def input_a
  gets.split.map(&:to_i)  # スペースで区切られた複数の整数
end

def input_o(num)
  num.times.map { gets.to_i }  # 縦に並んだ複数の整数。たまにある
end

def output_f(num)
  puts sprintf("%.12f", num)
end

x = input_n
n = 512
pre = Array.new(n)
nums = Array.new(n)
(n / 2).times do |i|
  pre[i + (n / 2)] = -(i ** 5)
  nums[i + (n / 2)] = -i
  pre[i] = (i ** 5)
  nums[i] = i
end

pre.each_with_index do |p, i|
  pre.each_with_index do |r, j|
    if p - r == x
      puts "#{nums[i]} #{nums[j]}"
      exit
    end
  end
end


Measured memory_bytes: 14388
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define fo(i, n) for(int i=0; i<n; i++)
#define Fo(i, k, n) for(int i=k; i<n; i++)
#define MOD 1000000007
#define deb(n) cout<<"[ "#n<<" = "<<n<<" ]"<<endl;
#define FIO ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
const long long  MAX = 1 << 18;
int case_no = 1;
#define w(x) int x; cin>>x; while(x--)

int main() {
	FIO
	/*
	#ifndef ONLINE_JUDGE 
   	freopen("input.txt", "r", stdin); 
   	freopen("error.txt", "w", stderr); 
   	freopen("answer.txt", "w", stdout); 
   	#endif 
   	*/
	int n;
	cin >> n;
	if(n >= 30) cout << "Yes" << endl;
	else cout << "No" << endl;

	return 0;
}

Measured memory_bytes: 3684
#!/usr/bin/env python
from __future__ import division, print_function
from sys import stdin, exit


def make_number_of_combination():
    pre = [[0] * 10 for _ in xrange(1001)]
    now = [[0] * 10 for _ in xrange(1001)]

    for a in xrange(101):
        now[a][0] = 1
        for i in xrange(1001):
            if i+a > 1000:
                break
            for j in xrange(9):
                now[i+a][j+1] += pre[i][j]

        for i in xrange(1001):
            for j in xrange(10):
                pre[i][j] = now[i][j]

    return pre


def main():
    ans = make_number_of_combination()
    for line in stdin:
        n, s = (int(s) for s in line.split())
        if not n and not s:
            exit()
        print(ans[s][n-1])


if __name__ == '__main__':
    main()

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

#define ll long long
#define fornum(A,B,C) for(A=B;A<C;A++)
#define mp make_pair
#define pii pair<int,int>
#define pll pair<ll,ll>

using namespace std;

/////////////////////////////////////////////////////
#define MOD 998244353
ll moddiv(ll a,ll b){
    for(ll m=MOD-2;m>0;m/=2){
        if(m&1){
            a=a*b%MOD;
        }
        b=b*b%MOD;
    }
    return a;
}
ll N, A[333],Asum;
ll Al[333][99999],Bl[333][99999];
ll Fa[333],C[333][333];
ll i, j,k, l,ans;
int main(){
    scanf("%lld", &N);
    Fa[0] = 1;
    fornum(i,0,N+1){
        C[i][0] = 1;
        fornum(j,0,i){
            C[i][j + 1] = (C[i][j + 1] + C[i - 1][j] + C[i - 1][j + 1]) % MOD;
        }
    }
    fornum(i,0,N){
        scanf("%lld", &A[i]);
        Asum += A[i];
        Fa[i + 1] = Fa[i] * (i + 1) % MOD;
    }
    ans = 1;
    fornum(i,0,N){
        ans = ans * 3 % MOD;
    }
    Al[0][0] = 1;
    fornum(i,0,N){
        fornum(j,0,Asum+1){
            Al[i+1][j] = (Al[i+1][j]+Al[i][j]*2) % MOD;
            Al[i+1][j+A[i]] = (Al[i+1][j+A[i]]+Al[i][j]) % MOD;
        }
    }
    fornum(i,(Asum+1)/2,Asum+1){
        ans = (ans + MOD - Al[N][i]*3%MOD) % MOD;
    }
    if(Asum%2==0){
        Bl[0][0] = 1;
        fornum(i,0,N){
            fornum(j,0,Asum+1){
                Bl[i + 1][j] = (Bl[i + 1][j] + Bl[i][j]) % MOD;
                Bl[i + 1][j+A[i]] = (Bl[i + 1][j+A[i]] + Bl[i][j]) % MOD;
            }
        }
        ans = (ans + Bl[N][Asum/2]*3) % MOD;
    }
    printf("%lld", ans);

    return 0;
}

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

namespace CP
{
    class Atria
    {
        readonly static long mod = 1000000000 + 7;
        static void Main(string[] args)
        {
            long n = long.Parse(ReadLine());
            var ans = Digits(n);
            for (int i = 1; i <= (int)Sqrt(n); i++)
            {
                if (n % i == 0)
                {
                    ans = Min(ans, Digits(n / i));
                }
            }
            WriteLine(ans);
        }

        static int Digits(long a)
        {
            return(a == 0) ? 1: ((int)Log10(a) + 1);
        }

    }
}


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

typedef pair<int,int> P;
typedef vector<int> vec;
typedef vector<vec> mat;

const int INF = 1 << 28;
int N, M;

bool check(vec& v, vec& t) {
    for (int i = 0; i < N; i++) {
        if (v[i] >= t[i]) return false;
    }

    return true;
}

void solve() {
    vector<vector<P> > v(N);
    for (int i = 0; i < M; i++) {
        int x, y, z;
        cin >> x >> y >> z;
        x--;
        y--;
        v[x].push_back(P(z, y));
        v[y].push_back(P(z, x));
    }

    for (auto& i : v) {
        sort(i.begin(), i.end());
    }

    int res = INF;
    for (int i = 0; i < N; i++) {
        for (int j = 0; j < v[i].size(); j++) {
            priority_queue<P, vector<P>, greater<P> > que;
            vec used(N, false);
            used[i] = used[v[i][j].second] = true;
            for (auto k : v[i]) {
                if (k.first >= v[i][j].first) que.push(k);
            }

            for (auto k : v[v[i][j].second]) {
                if (k.first >= v[i][j].first) que.push(k);
            }

            int Max = v[i][j].first;

            while (que.size()) {
                P p = que.top(); que.pop();
                int w = p.first;
                int now = p.second;
                if (used[now]) continue;
                used[now] = true;
                Max = max(Max, w);
                if (Max - v[i][j].first > res) break;
                for (auto e : v[now]) {
                    int tmp = e.first - v[i][j].first;
                    if (tmp >= 0 && tmp < res && !used[e.second]) {
                        que.push(e);
                    }
                }
            }

            bool flag = true;
            for (int i = 0; i < N; i++) {
                if (!used[i]) {
                    flag = false;
                    break;
                }
            }

            if (flag) {
                res = min(res, Max - v[i][j].first);
            }
        }
    }

    cout << (res > 10000 ? -1 : res) << endl;
}

int main() {
    while (cin >> N >> M, N || M) solve();

    return 0;
}

Measured memory_bytes: 3216
#include <bits/stdc++.h>
using namespace std;
#define lowbit(x) (x&(-x))
#define N 100015
#define LL long long
const int mo = 1e9 + 7;
struct xx {
	int L,R;
} num[N<<2];
int dp[105][N<<2]; // 第i位用了 第j段的数字.
int main() {
	int n,k;
	cin >> n >> k;
	int x = 1,cot = 0;
	while(x <= n) {
		int t = n/x,R = n/t;
		num[++cot] = (xx) <% x,R %>;
		x = R+1;
	}
	for(int i=1; i<=cot; i++) dp[1][i] = num[i].R - num[i].L + 1,(dp[1][i] += dp[1][i-1]) %= mo;
	for(int T=2; T<=k; T++) {
		for(int i=1; i<=cot; i++) {
			dp[T][i] = 1LL*dp[T-1][cot-i+1]*(num[i].R-num[i].L+1)%mo;
			(dp[T][i] += dp[T][i-1]) %= mo;
		}
	}
	printf("%d",dp[k][cot]);
	return 0;
}

Measured memory_bytes: 158208
n = gets.chomp.to_i
max_profit = (10 ** 9) * -1
min_val = gets.chomp.to_i

(n-1).times do
  r = gets.chomp.to_i
  max_profit = max_profit > (r - min_val) ? max_profit : (r - min_val)
  min_val = min_val < r ? min_val : r
end

puts max_profit

Measured memory_bytes: 8720
from sys import stdin

x = []
x.append(int(stdin.readline().rstrip()))
x.append(int(stdin.readline().rstrip()))
x.append(int(stdin.readline().rstrip()))
x.append(int(stdin.readline().rstrip()))
x.append(int(stdin.readline().rstrip()))

time = []
min = 0
for i in range(0,5):
    if x[i] %10 == 0:
        time.append(x[i])
    else:
        time.append(x[i] - (x[i]%10) + 10)
    if ((x[min]-1) % 10) > ((x[i]-1) % 10):
        min = i

time[min] = x[min]

sum_time = 0
for i in range(0,5):
    sum_time += time[i]

print(sum_time)

Measured memory_bytes: 3064
#include <bits/stdc++.h>
#include<string.h>
using namespace std;
#define FAST ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define endl "\n"
#define Max(x,y,z) max(x,max(y,z))
#define Min(x,y,z) min(x,min(y,z))
#define fr(i,s,e) for(i=s;i<e;i++)
#define rf(i,s,e) for(i=s-1;i>=e;i--)
#define pb push_back
#define eb emblace_back
#define mp make_pair
#define ff first
#define ss second
//#define int   long long
#define ll   long long
#define trace1(x)                cerr<<#x<<": "<<x<<endl
#define trace2(x, y)             cerr<<#x<<": "<<x<<" | "<<#y<<": "<<y<<endl
#define trace3(x, y, z)          cerr<<#x<<":" <<x<<" | "<<#y<<": "<<y<<" | "<<#z<<": "<<z<<endl
#define trace4(a, b, c, d)       cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<endl
#define trace5(a, b, c, d, e)    cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<" | "<<#e<< ": "<<e<<endl
#define trace6(a, b, c, d, e, f) cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<" | "<<#e<< ": "<<e<<" | "<<#f<<": "<<f<<endl
#define vl vector<long long>
#define inf (1LL<<61)
#define vi vector<int>
#define vii vector< vector<int> >
#define vll vector< vector<long long> >
#define vpi vector< pair<int,int> >
#define vpl vector< pair<ll,ll> >
#define viii vector< vector<vector<int> > >
typedef pair<pair<int, int>,int> P;
#define cd complex<double>
#define PI 4*atan(1)
#define mod %1000000007
#define pi 3.14159265358979323846//20 decimals
#define ld long double

int main()
{
	FAST;
	ll n, k, i, j;
	cin >> n >> k;
	ll mn = n - 2;
	ll mx = (n-1)*(n-2)/2;
	if((k > mx))
	{
		cout << "-1";
		return 0;
	}
	vector <pair <ll, ll> > e;
	fr(i,2,n+1)
		e.pb(mp(1,i));
	ll curr = mx, ci = 2, br = 0;
	while(1)
	{
		if(curr == k)
			break;
		fr(i, ci+1, n+1)
		{
			e.pb(mp(ci, i));
			curr--;
			if(curr == k)
				break;
		}
		ci++;
	}
	cout << e.size() << endl;
	fr(i,0,e.size())
		cout << e[i].ff << " " << e[i].ss << endl;
}


Measured memory_bytes: 512
# -*- coding: utf-8 -*-
def check(a, time):
  ret, mod = divmod(time, a)
  value = True if mod == 0 else check(a, ret) if ret > a else False
  return value


a, b, t, biscuit = map(int, input().split() + ["0"])
for i in range(1, t + 1):
  if check(a, i):
    biscuit = biscuit + b

print(biscuit)


Measured memory_bytes: 3060
#include <bits/stdc++.h>
#define int long long
#define mod (int)(1e9+7)
#define inf (int)(3e18)
#define rep(i,n) for(int i=0;i<n;i++)
#define REP(i,n) for(int i=1;i<n;i++)
#define P std::pair<int,int>
#define PiP std::pair<int,std::pair<int,int>>
#define all(v) v.begin(),v.end()
#define mkp std::make_pair
#define prique(T) std::priority_queue<T,vector<T>,greater<T>>
using namespace std;
template<class T> inline void chmax(T& a, T b) { a = std::max(a, b); }
template<class T> inline void chmin(T& a, T b) { a = std::min(a, b); }

bool prime(int x) {
	for (int i = 2; i * i <= x; i++) {
		if (x % i == 0)return false;
	}
	return x != 1;
}
int gcd(int x, int y) {
	if (y == 0)return x;
	return gcd(y, x % y);
}
int lcm(int x, int y) {
	return x / gcd(x, y) * y;
}
int kai(int x, int y) {
	int res = 1;
	for (int i = x - y + 1; i <= x; i++) {
		res *= i; res %= mod;
	}
	return res;
}
int mod_pow(int x, int y, int m) {
	int res = 1;
	while (y > 0) {
		if (y & 1) {
			res = res * x % m;
		}
		x = x * x % m;
		y >>= 1;
	}
	return res;
}
int comb(int x, int y) {
	if (y > x)return 0;
	return kai(x, y) * mod_pow(kai(y, y), mod - 2, mod) % mod;
}
int get_rand(int MIN, int MAX) {
	std::random_device rnd;
	std::mt19937_64 mt64(rnd());
	std::uniform_int_distribution<int>engine(MIN, MAX);
	return engine(mt64);
}
/*--------Library Zone!--------*/

int n;
string s;
stack<char>st;
signed main() {
	cin >> n >> s;
	rep(i, n) {
		if (st.empty() || st.top() != s[i])st.push(s[i]);
	}
	cout << st.size() << endl;
}


Measured memory_bytes: 512
#include <iostream>
#include <bitset>

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

using namespace std;
using ll = long long;

int a[4];

int to_int(char);

int main()
{
    string s;
    cin>>s;
    int n = s.size();
    rep(i,n){
        a[i]=to_int(s[i]);
    }

    rep(bit,(1<<(n-1))){
        int sum=a[0];

        rep(i,3){
            if(bit&(1<<i)){
                sum+=a[i+1];
            }else{
                sum-=a[i+1];
            }
        }

        if(sum==7){
            cout<<a[0];
            rep(i,3){
                if(bit&(1<<i)){
                    cout<<"+";
                }else{
                    cout<<"-";
                }
                cout<<a[i+1];
            }
            cout<<"=7"<<endl;
            return 0;
        }
    }



    return 0;
}

int to_int(char c){
    if(c=='0'){
        return 0;
    }else if(c=='1'){
        return 1;
    }else if(c=='2'){
        return 2;
    }else if(c=='3'){
        return 3;
    }else if(c=='4'){
        return 4;
    }else if(c=='5'){
        return 5;
    }else if(c=='6'){
        return 6;
    }else if(c=='7'){
        return 7;
    }else if(c=='8'){
        return 8;
    }else{
        return 9;
    }
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <cmath>
#include <vector>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <queue>
#include <ctime>
#include <cassert>
#include <complex>
#include <string>
#include <cstring>
#include <chrono>
#include <random>
#include <queue>
#include <bitset>
#include <stack>
#include <functional>

#ifdef LOCAL
    #define eprintf(...) fprintf(stderr, __VA_ARGS__)
#else
    #define eprintf(...) 42
#endif

#define rep(i, n) for(int i = 0, i##_len = (n); i < i##_len; ++i)
#define repp(i, m, n) for(int i = m, i##_len = (n); i < i##_len; ++i)
#define reprev(i, n) for(int i = (n-1LL); i >= 0; --i)
#define all(x) (x).begin(), (x).end()
template <class T> bool chmax(T &a, const T &b) { if (a < b) { a = b; return 1; } return 0; }
template <class T> bool chmin(T &a, const T &b) { if (b < a) { a = b; return 1; } return 0; }
template <class T> T gcd(T a, T b) { return b ? gcd(b, a % b) : a; }
using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair <int,int> P;
typedef long double ld;

int main(void)
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n; cin >> n;
    vector<int> a(n); rep (i, n) cin >> a[i];
    int m = 1, M = -1, mid = -1, Mid = -1;
    rep (i, n) {
        if (chmin(m, a[i])) mid = i;
        if (chmax(M, a[i])) Mid = i;
    }
    if (-m <= M) {
        if (m >= 0) {
            cout << n - 1 << "\n";
            rep (i, n - 1) cout << i + 1 << " " << i + 2 << "\n";
        } else {
            cout << 2 * n - 1 << "\n";
            rep (i, n) if (i != Mid) cout << Mid + 1 << " " << i + 1 << "\n";
            cout << Mid + 1 << " " << Mid + 1 << "\n";
            rep (i, n - 1) cout << i + 1 << " " << i + 2 << "\n";
        }
    } else { 
        if (M <= 0) {
            cout << n - 1 << "\n";
            reprev (i, n - 1) cout << i + 2 << " " << i + 1 << "\n";
        } else {
            cout << 2 * n - 1 << "\n";
            rep (i, n) if (i != mid) cout << mid + 1 << " " << i + 1 << "\n";
            cout << mid + 1 << " " << mid + 1 << "\n";
            reprev (i, n - 1) cout << i + 2 << " " << i + 1 << "\n";
        }
    }
    return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <string>
#include <iostream>
#include <iomanip>
#include <map>
#include <algorithm>
#include <vector>
#include <math.h>
#include <queue>
#define MOD (long long)1000000007
#define INF (long long)998244353
using namespace std;

int main(void){
    int h,w,n;
    cin >> h >> w >> n;
    int ans=0;
    while(ans*max(h,w)<n)ans+=1;
    cout << ans << endl;
    return 0;
}

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

using namespace std;

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

    int N; cin>>N;
    map<std::string, vector<pair<int, int>>> sp;
    for (int i = 0; i < N; i++) {
        string s;int p; cin>>s>>p;
        sp[s].push_back({i+1, p});
    }
    for (auto& v : sp) {
        sort(v.second.begin(), v.second.end(), [](auto l, auto r) {return l.second > r.second;});
    }
    for (auto& v : sp) {
        for (auto p : v.second)
            cout << p.first << endl;
    }


    return 0;
}



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

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

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

int main(){
	cin.tie(0);ios::sync_with_stdio(false);
	string s;
	cin>>s;
	vector<int> a(4);
	rep(i,4) a[i]=s[i]-'0';
	rep(i,1<<3){
		int now=a[0];
		string t;
		rep(j,3){
			if(i & 1<<j){
				now+=a[j+1];
				t+='+';
			}else{
				now-=a[j+1];
				t+='-';
			}
		}
		if(now==7){
			rep(j,3){
				cout<<s[j]<<t[j];
			}
			cout<<s[3]<<"=7"<<endl;
			return 0;
		}
	}
}

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

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

    while (1) {
        int N;
        cin >> N;
        if (!N) break;
        map<char, int> vote;
        for (char i = 'A'; i <= 'Z'; i++) {
            vote.insert(make_pair(i, 0));
        }
        vector<char> touhyo(N);
        for (int i = 0; i < N; i++) {
            cin >> touhyo[i];
        }

        for (int i = 0; i < touhyo.size(); i++) {
            vote[touhyo[i]] += 1;
            int firstInt = 0, secondInt = 0;
            char firstChar, secondChar;
            for (char c = 'A'; c <= 'Z'; c++) {
                if (firstInt < vote[c]) {
                    firstChar = c;
                    firstInt = vote[c];
                }
            }
            for (char c = 'A'; c <= 'Z'; c++) {
                if (c == firstChar) continue;
                if (secondInt < vote[c]) {
                    secondChar = c;
                    secondInt = vote[c];
                }
            }
            if (firstInt - secondInt > N - (i + 1)) {
                cout << firstChar << " " << i + 1 << endl;
                break;
            }
            if (i + 1 == N && firstInt == secondInt) {
                cout << "TIE" << endl;
            }
        }
    }
}


Measured memory_bytes: 3148
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {

		Scanner s = new Scanner(System.in);
		int a = Integer.parseInt(s.next());
		int b = Integer.parseInt(s.next());
		int c = Integer.parseInt(s.next());
		s.close();

		int min = Math.min(Math.min(a+b, b+c), a+c);

		System.out.println(min);
	}

}


Measured memory_bytes: 23124
N=int(input())
if N/1<=9 and N%1==0:
    print('Yes')
else:
    if N/2<=9 and N%2==0:
        print('Yes')
    else:
        if N/3<=9 and N%3==0:
            print('Yes')
        else:
            if N/4<=9 and N%4==0:
                print('Yes')
            else:
                if N/5<=9 and N%5==0:
                    print('Yes')
                else:
                    if N/6<=9 and N%6==0:
                        print('Yes')
                    else:
                        if N/7<=9 and N%7==0:
                            print('Yes')
                        else:
                            if N/8<=9and N%8==0:
                                print('Yes')
                            else:
                                if N/9<=9 and N%9==0:
                                    print('Yes')
                                else:
                                    print('No')

Measured memory_bytes: 3064
// g++ -std=gnu++1y -O2 main.cpp

#include <cstdio>
#include <vector>
#include <set>

#include <map>
#include <unordered_map>
#include <string>
#include <utility>
#include <algorithm>
#include <iostream>
#include <iostream>
#include <climits>

using namespace std;

template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }

int main() {
	int N, M;
	cin >> N >> M;

	int sum = 0;
	vector<int> A(N);
	for (int i = 0; i < N; i++)
	{
		int Ai;
		cin >> Ai;
		A[i] = Ai;
		sum += Ai;
	}

	double ber = sum / (4.0 * M);

	int cnt = 0;
	for (int i = 0; i < N; i++)
	{
		if (A[i] >= ber) {
			cnt++;
		}
	}

	if (cnt >= M) {
		cout << "Yes" << endl;
	}
	else {
		cout << "No" << endl;
	}
	return 0;
}

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

using namespace std;

#define fi first
#define se second
#define pb push_back
#define mp make_pair

#define int long long
typedef pair<int, int> ii;

const int mod = 1e9 + 7;

const int N = 2e6 + 5;

long long n;

long long p, sum = 1;

vector<long long> vec;

signed main() {
    cin.tie(0), ios::sync_with_stdio(0);
    cin >> n >> p;
    for(int i = 2; i <= sqrt(p); i++) {
        if(p % i == 0) {
            long long x = p, cnt = 0;
            while(p % i == 0) {
                cnt++;
                p /= i;
            }
            if(cnt >= n) {
                int times = cnt / n;
                int lmao = 1;
                for(int j = 1; j <= times; j++)
                    lmao *= i;
                vec.pb(lmao);
            }
        }
    }
    if(p > 1) {
        if(n == 1)
            vec.pb(p);
    }
    for(int i= 0; i < vec.size(); i++)
        sum *= vec[i];
    cout << sum;
}


Measured memory_bytes: 256
n, k =  [ int(v) for v in input().split() ]
num_list = sorted([ tuple(map(int, input().split())) for i in range(n) ])
order_list, value_list = [ 0 for i in range(n) ], [ 0 for i in range(n) ]
for i in range(n):
	order_list[i] = num_list[i][1] + order_list[i-1]
	value_list[i] = num_list[i][0]


for i in range(n):
	if order_list[i] - k >= 0:
		print(value_list[i])
		break

Measured memory_bytes: 21952
(defmacro defsolver (name vars &body body)
  `(defun ,name ()
     (let (,@(mapcar #'list
            vars
            (mapcar (constantly '(read))
                vars)))
       ,@body)))

(defsolver sol-c (n m)
  (defun check (pattern parity switches)
    (let ((l (mapcar (lambda (x)
		       (mod (ash pattern (- 1 x)) 2))
		     switches)))
      (= parity (mod (loop for x in l sum x) 2))))
  (let ((l
	 (loop repeat m collect
	      (let ((k (read)))
		(loop repeat k collect (read)))))
	(p (loop repeat m collect (read)))
	(ans (loop for x below (expt 2 n) collect x)))
    (dotimes (i m)
      (setf ans
	    (remove-if-not
	     #'(lambda (x)
		 (check x (nth i p) (nth i l)))
	     ans)))
    (princ (length ans))))


(sol-c)

Measured memory_bytes: 21604
// atcoder/abc150/A/main.cpp
// author: @___Johniel
// github: https://github.com/johniel/

#include <bits/stdc++.h>

#define each(i, c) for (auto& i : c)
#define unless(cond) if (!(cond))

using namespace std;

typedef long long int lli;
typedef unsigned long long ull;
typedef complex<double> point;

template<typename P, typename Q> ostream& operator << (ostream& os, pair<P, Q> p) { os << "(" << p.first << "," << p.second << ")"; return os; }
template<typename P, typename Q> istream& operator >> (istream& is, pair<P, Q>& p) { is >> p.first >> p.second; return is; }
template<typename T> ostream& operator << (ostream& os, vector<T> v) { os << "("; each (i, v) os << i << ","; os << ")"; return os; }
template<typename T> istream& operator >> (istream& is, vector<T>& v) { each (i, v) is >> i; return is; }

template<typename T> inline T setmax(T& a, T b) { return a = std::max(a, b); }
template<typename T> inline T setmin(T& a, T b) { return a = std::min(a, b); }

int main(int argc, char *argv[])
{
  ios_base::sync_with_stdio(0);
  cin.tie(0);

  int k, x;
  while (cin >> k >> x) {
    cout << (x <= 500 * k ? "Yes" : "No") << endl;
  }

  return 0;
}


Measured memory_bytes: 256
// Created by martinezdiego on 23/4/19

#include <bits/stdc++.h>

using namespace std;

int main() {
  ios_base::sync_with_stdio(false);
  int n, k;
  string s;
  cin >> n >> s >> k;
  for (auto i : s) {
    if (i == s[k-1])
      cout << i;
    else
      cout << '*';
  }
  cout << '\n';
  return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <string>
#include <numeric>
#include <unordered_map>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <memory>
#include <iomanip>
#include <type_traits>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
constexpr long long MOD = 1e9 + 7;
constexpr long long MAX = 1000000;

//long long MOD = 998244353;
constexpr ll INF = 1e17;
constexpr double PI = 3.141592653589793;
template<class T>bool chmax(T& a, const T& b) { if (a < b) { a = b; return 1; } return 0; }
template<class T>bool chmin(T& a, const T& b) { if (b < a) { a = b; return 1; } return 0; }

ll h, w;
vector<ll> dx = { -1, 0, 1, 0 };
vector<ll> dy = { 0, -1, 0, 1 };


bool isInField(ll x, ll y) {
    bool f = x >= 0 && x < w && y >= 0 && y < h;
    return f;
}

bool compare_first(pair<ll, ll> x, pair<ll, ll> y)
{
    if (x.first != y.first) {
        return x.first < y.first;
    }
    else {
        return x.second < y.second;
    }
}

bool compare_second(pair<ll, ll> x, pair<ll, ll> y)
{
    if (x.second != y.second) {
        return x.second < y.second;
    }
    else {
        return x.first < y.first;
    }
}

struct {
    bool operator()(pair<string, int> x, pair<string, int> y) const
    {
        return x.second <= y.second && x.first < y.first;
    }
} compare_map;

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

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

    ll min = 1e+10;
    int candidate = 0;
    for (int p = 0; p < 100; p++)
    {
        ll sum = 0;
        for (int i = 0; i < n; i++)
        {
            sum += (a[i] - p) * (a[i] - p);
        }
        if (min > sum) {
            candidate = p;
            min = sum;
        }
    }

    cout << min << "\n";

    return 0;
}



Measured memory_bytes: 256
#include <vector>
#include <stack>
#include <queue>
#include <list>
#include <bitset>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <algorithm>
#include <numeric>
#include <iostream>
#include <iomanip>
#include <string>
#include <chrono>
#include <random>
#include <cmath>
#include <cassert>
#include <climits>
#include <cstring>
#include <cstdlib>
#include <functional>
#include <sstream>

using namespace std;


int main(int argc, char** argv) {
    ios::sync_with_stdio(false);
    cin.tie(0);

    long long n;
    cin >> n;

    int b = -2;
    int ab = abs(b);

    string res;
    if (n == 0) {
        res = "0";
    }
    while (n != 0) {
        int d = (n % b + ab) % ab;
        res += (char)('0' + d);
        n -= d;
        n /= b;

    }

    reverse(res.begin(), res.end());

    cout << res << '\n';
    return 0;
}

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

int  main(){
  int n;cin>>n;
  int odd=0,even=0,four=0;
  vector<ll> v(n);
  rep(i,n){
    cin>>v[i];
    if(v[i]%2==1)odd++;
    else if(v[i]%4==0)four++;
    else{even++;}
  }
  if(odd<=four){cout<<"Yes";}
  else if(even==0&&odd<=four+1){cout<<"Yes";}
  else{cout<<"No";}
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define loop(__x, __start, __end) for(int __x = __start; __x < __end; __x++)

int h,w,k;
const int m = 3;
ll G[3000][3000];
ll dp[3000][3000][4];

void print(int num, ...) {
  va_list valist;
  va_start(valist, num);
  for (int i = 0; i < num; i++) {
    if (i!=0) cout << ' ';
    cout << va_arg(valist, ll);
  }
  cout << endl;
  va_end(valist);
}

template <class T> bool chmax(T &a, T b) { if (a < b) {a = b; return true; } return false; }

ll dfs(int y = 0, int x = 0, int a = 0) {
  if (y == h-1 and x == w-1) {
    if (a >= m) return 0;
    else return G[y][x];
  }
  if (y >= h or x >= w) return 0;

  ll &cc = dp[y][x][a];
  if (~cc) return cc;

  ll ans = 0;
  // とらない
  chmax(ans, dfs(y + 1, x, 0));
  chmax(ans, dfs(y, x + 1, a));

  // とる
  if (a < m and G[y][x] > 0) {
    chmax(ans, G[y][x] + dfs(y + 1, x, 0));
    chmax(ans, G[y][x] + dfs(y, x + 1, a + 1));
  }

  return cc = ans;
}

int main() {
  cin >> h >> w >> k;
  loop(i,0,k) {
    int r, c; ll v;
    cin >> r >> c >> v;
    r--;c--;
    G[r][c] = v;
  }

  memset(dp, -1, sizeof(dp));

  cout << dfs() << endl;
  return 0;
}


Measured memory_bytes: 355552
#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 MOD 1000000007
#define ALL(v) v.begin(), v.end()
using namespace std;
typedef long long ll;
using P = pair<int,int>;
  
int main()
{
  ll N;
  cin >> N;

  ll sum = 0;
  ll B[100010]={0};
  vector<ll> A(N);
  REP(i, N){
    cin >> A[i];
    if(A[i]>N){
      sum++;
      continue;
    }else{
      B[A.at(i)-1]++;
    }
  }
  REP(i,N){
    if(B[i]<i+1){
      sum+=B[i];
    }else{
      sum+=B[i]-i-1;
    }
  }
  cout << sum << endl;
}

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

int main() {
    int A, B;
    cin >> A >> B;

    int x = A + B;
    int y = A - B;
    int z = A * B;

    int max = x;
    if (max < y) max = y;
    if (max < z) max = z;

    cout << max << endl;
}


Measured memory_bytes: 256
#include<stdio.h>
#include<string.h>
#include<algorithm>
#include<math.h>
using namespace std;
#define N 100010
int a[N],dp[N];
int main()
{
    int i,j,k,n;
    scanf("%d",&n);
    for(i=1;i<=n;i++)
        scanf("%d",&a[i]);
    dp[2]=abs(a[2]-a[1]);
    for(i=3;i<=n;i++)
        dp[i]=min(dp[i-1]+abs(a[i]-a[i-1]),dp[i-2]+abs(a[i]-a[i-2]));
    printf("%d\n",dp[n]);
    return 0;
}


Measured memory_bytes: 896
import Control.Monad
import Text.Printf

comb 0 xs = [[]] 
comb _ [] = []
comb n (x:xs) = [x:y | y <- comb (n-1) xs] ++ comb n xs


calc ::  [[(Double, Double)]] -> Double -> Double 
calc [] sumv = sumv 
calc ((z1:z2:zs):xy) sumv = calc xy (sumv+len) 
  where
    v = sqrt $ ((fst z1) - (fst z2))^2 + ((snd z1) - (snd z2))^2
    len = v*2 


main = do
  n <- readLn 
  xy <- replicateM n $ do
    [a,b] <- map read . words <$> getLine :: IO [Double] 
    return (a,b)
 
  let xy_list = comb 2 xy
  let s = calc xy_list 0 
  let ans = s / (fromIntegral (n :: Int)) 
  printf "%.9f\n" ans


Measured memory_bytes: 636
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <set>
#include <cmath>
#include <queue>
#include <map>
#include <stack>
#include <bitset>
#include <numeric> //lcm
#include <iomanip> //double精度 setprecision

using namespace std;

#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = n-1; i >= 0; --i)
#define rep1(i,n) for(int i = 1; i <= (n); ++i)
#define rrep1(i,n) for(int i = (n); i >= 1; --i)
#define all(vec) (vec).begin(),(vec).end()

#define debug(vec) for(auto v : vec) cerr << v << " "; cerr << endl;
#define debug2D(vec2D) for(auto vec : vec2D) { for (auto v : vec) cerr << v << " "; cerr << endl; } 
#define debugP(vec) for(auto v : vec) cerr << "(" << v.first << "," << v.second << ") "; cerr << endl;
#define debug2DP(vec2D) for(auto vec : vec2D) { for (auto v : vec) cerr << "(" << v.first << "," << v.second << ") "; cerr << endl; } 

typedef long long ll;

constexpr ll INF = 1000000000; //10^10
//const ll MOD = 998244353;
constexpr ll MOD = 1000000007;

template<class T>inline bool chmax(T& a, T b) { if (a <= b) { a = b; return true; } else return false; }
template<class T>inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } else return false; }

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

	long double a,b,h,m ; cin >> a >> b >> h >> m;

	long double ang = abs(h/12 + m/(60*12) - m/60)*2*3.14159265358979;

	cout << setprecision(15) << sqrt(a*a + b*b - 2*a*b*cos(ang)) << endl;
}

Measured memory_bytes: 4184