akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define rep_ll(i,n) for(ll i = 0; i < (ll)(n); i++)

using namespace std;
 
typedef long long ll;
typedef unsigned long long u_ll;
typedef pair<int, int> pair_;

const long double PI = (acos(-1));
 
const int INF = 1001001001;
const int dx[] = {-1, 0, 1, 0};
const int dy[] = {0, -1, 0, 1};
 
int gcd(int a, int b){
    if(b == 0) return a;
    return gcd(b, a%b);
}
ll gcd(ll a, ll b){
    if(b == 0) return a;
    return gcd(b, a%b);
}
vector<pair<ll, int>> factorize(ll n){
    vector<pair<ll, int>> res;
    for(ll i = 2; i*i <=n; i++){//i+=2にしたらもっと速くなる
        if(n%i) continue;//割り切れなかったらcontinue;
        res.emplace_back(i,0);//iで割れて、何回割れるか調べる
        while(n%i==0){//割り切れなくなるまで繰り返す
            n /= i;
            res.back().second++;//iで割れる回数を加算
        }
    }
    if(n != 1) res.emplace_back(n,1);//最後に１も加える
    return res;
}
int main(){
    ll a, b;
    cin >> a >> b;
    ll g = gcd(a,b);
    auto f = factorize(g);
    int ans = f.size()+1;
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
<?php
fscanf(STDIN, "%d", $n);

$format = join(' ', array_map(function ($x) { return '%f'; }, range(1, $n)));
$X = fscanf(STDIN, $format);
$Y = fscanf(STDIN, $format);

$dxy1 = pow(array_sum(array_map(func(1), $X, $Y)), 1);
$dxy2 = pow(array_sum(array_map(func(2), $X, $Y)), 1/2);
$dxy3 = pow(array_sum(array_map(func(3), $X, $Y)), 1/3);
$dxy4 = chebyshev_d($X, $Y);

echo "$dxy1\n";
echo "$dxy2\n";
echo "$dxy3\n";
echo "$dxy4\n";

function func($p)
{
    return function ($x, $y) use ($p) { return pow(abs($x - $y), $p); };
}

function chebyshev_d($X, $Y)
{
    $nums = array_map(function ($x, $y) { return abs($x - $y); }, $X, $Y);

    if (1 === count($nums)) {
        return $nums[0];
    }

    return call_user_func_array('max', $nums);
}

Measured memory_bytes: 6780
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define FOR(I,A,B) for(ll I = (A); I < (B); ++I)
#define POSL(x,v) (lower_bound(x.begin(),x.end(),v)-x.begin()) //ai>=v
#define POSU(x,v) (upper_bound(x.begin(),x.end(),v)-x.begin()) //ai>v
#define NUM(x,v) (POSU(x,v)-POSL(x,v))
const ll INF=1e9+7;
const ll N = 102;
ll a,b,x;

int main(){
	cin>>a>>b>>x;
	if(x<=a+b&&x>=a){
		cout<<"YES"<<endl;
	}else{
		cout<<"NO"<<endl;
	}
	return 0;
}

Measured memory_bytes: 256
n, m = map(int, input().split())
list_student = []
list_ckeckpoint = []
for x in range(n):
    a, b = map(int, input().split())
    list_student.append([a, b])
for y in range(m):
    c, d = map(int, input().split())
    list_ckeckpoint.append([c, d])
    
def distance(lista, listb):
    return abs(lista[0] - listb[0]) + abs(lista[1] - listb[1])

for no in range(n):
    minValue = 2 * 10**8
    minid = 1
    for id in range(m):
        dis = distance(list_student[no], list_ckeckpoint[id])
        if minValue > dis: minid = id + 1
        minValue = min([minValue, dis])
    print(minid)

Measured memory_bytes: 3064
{-# OPTIONS_GHC -O2 #-}
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE ScopedTypeVariables #-}
{-# LANGUAGE LambdaCase #-}
{-# LANGUAGE BangPatterns #-}
{-# LANGUAGE TupleSections #-}
module Main where

import           Data.List
import           Control.Monad
import           Debug.Trace
import qualified Data.ByteString.Char8         as BC
import           Data.Maybe                     ( fromJust, fromMaybe )
import qualified Data.Set                      as S
import qualified Data.IntMap.Strict            as IM
import qualified Data.IntMap.Lazy            as IML
import qualified Data.Map.Strict               as M
import           Data.Char
import qualified Data.Array.IArray as A
import qualified Data.Array.Unboxed as UA
import Data.Bits
import Control.Monad.State.Strict
import qualified Data.Array.ST as STA
import qualified Data.Array.IO as IOA
import qualified Data.Array.MArray as MA
import Control.Monad.ST
import System.IO (stdin)
import Control.Arrow
import qualified Data.Vector as V
import qualified Data.Vector.Unboxed as UV
import qualified Data.Vector.Generic as GV
import qualified Data.Vector.Mutable as MV
import Data.Ix
import Data.Ord (Down(Down))
import qualified Data.Sequence as Seq
-- import Control.Lens

debug = False

ts :: Show a => a -> a
ts a = if debug then traceShowId a else a


readTuple2 :: IO (Int, Int)
readTuple2 = do
    [a, b] <- readInts
    return (a, b)

readTuple3 :: IO (Int, Int, Int)
readTuple3 = do
    [a, b, c] <- readInts
    return (a, b, c)

readTuple4 :: IO (Int, Int, Int, Int)
readTuple4 = do
    [a, b, c, d] <- readInts
    return (a, b, c, d)

readInt :: IO Int
readInt = fst . fromJust . BC.readInt <$> BC.getLine

readInts :: IO [Int]
readInts = map (fst . fromJust . BC.readInt) . BC.words <$> BC.getLine

split :: (a -> Bool) -> [a] -> [[a]]
split f [] = []
split f as =
    let (fo, la) = span f as
        las      = case la of
            [] -> []
            xs -> split f $ tail xs
    in  case fo of
            [] -> las
            xs -> xs : las


main :: IO ()
main = do
  getLine
  as <- readInts
  let total = sum as
  let ss = init $ scanl1 (+) as
  let ssdiff = (\s -> abs $ s - (total - s)) <$> ss
  print $ minimum ssdiff



Measured memory_bytes: 23676
#include <bits/stdc++.h>
 
#define _overload(_1,_2,_3,name,...) name
#define _rep(i,n) _range(i,0,n)
#define _range(i,a,b) for(int i=(int)(a);i<(int)(b);++i)
#define rep(...) _overload(__VA_ARGS__,_range,_rep,)(__VA_ARGS__)
 
#define _rrep(i,n) _rrange(i,n,0)
#define _rrange(i,a,b) for(int i=(int)(a)-1;i>=(int)(b);--i)
#define rrep(...) _overload(__VA_ARGS__,_rrange,_rrep,)(__VA_ARGS__)
 
#define _all(arg) begin(arg),end(arg)
#define uniq(arg) sort(_all(arg)),(arg).erase(unique(_all(arg)),end(arg))
#define getidx(ary,key) lower_bound(_all(ary),key)-begin(ary)
#define clr(a,b) memset((a),(b),sizeof(a))
#define bit(n) (1LL<<(n))
 
// #define DEBUG
 
#ifdef DEBUG
    #define dump(...) fprintf(stderr, __VA_ARGS__)
#else
    #define dump(...)
#endif
 
template<class T>bool chmax(T &a, const T &b) { return (a<b)?(a=b,1):0;}
template<class T>bool chmin(T &a, const T &b) { return (b<a)?(a=b,1):0;}
 
using namespace std;
using ll=long long;
using vi=vector<int>;
using vll=vector<ll>;
 
const double EPS = 1e-10;
const double PI = acos(-1.0);
const ll inf =1LL << 62;
const ll mod=1000000007LL;
const int dx[4]={1,0,-1,0};
const int dy[4]={0,1,0,-1};
 
 
ll extgcd(ll a,ll b,ll& x,ll& y){x=1,y=0;ll g=a;if(b!=0) g=extgcd(b,a%b,y,x),y-=a/b*x;return g;}
ll ADD(const ll &a, const ll &b,const ll &mod) { return (a+b)%mod;}
ll SUB(const ll &a, const ll &b,const ll &mod) { return (a-b+mod)%mod;}
ll MUL(const ll &a, const ll &b,const ll &mod) { return (1LL*a*b)%mod;}
ll DIV(const ll &a, const ll &b,const ll &mod) {ll x,y; extgcd(b,mod,x,y);return MUL(a,(x+mod)%mod,mod);}
 
random_device rd;
mt19937 mt(rd());
uniform_int_distribution<int> dice(1,6);
uniform_real_distribution<double> score(0.0,10.0);

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

    int L; cin >> L;
    string s, t; cin >> s >> t;

    string res = string(1, 'z'+1);
    rep(loop, 2){
        int ns = s.size(), nt = t.size();
        rrep(i, L / ns + 1){
            int sums = ns * i;
            if(L - sums < 0 or (L - sums) % nt != 0) continue;
            string cur = "";
            rep(j, i) cur += s;
            rep(j, (L - sums) / nt) cur += t;
            chmin(res, cur);
            break;
        }
        swap(s, t);
    }
    cout << res << endl;

    return 0;
}


Measured memory_bytes: 1112
#!/usr/bin/env python3
import sys
sys.setrecursionlimit(300000)


def solve(N: int, A: "List[int]"):
    ret = [0] * N
    tmp = A[0]
    i = 1
    while i < N - i:
        tmp = A[i] + A[N - i] - tmp
        i += 1
    ret[N // 2 + 1] = tmp
    for i in range(N // 2, -1, -1):
        ret[i] = A[i] * 2 - ret[i + 1]
    for i in range(N // 2 + 2, N):
        ret[i] = A[i - 1] * 2 - ret[i - 1]
    print(' '.join([str(r) for r in ret]))
    return


def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    A = [ int(next(tokens)) for _ in range(N) ]  # type: "List[int]"
    solve(N, A)

if __name__ == '__main__':
    main()


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

using namespace std;

typedef long long int ll;

const ll MAXN = 1e5 + 5;
const ll mod = 1e9 + 7;

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

  ll n, m;
  cin >> n >> m;
  vector < ll > a(n + 1), b(m + 1);
  for(int i = 1; i <= n; i++) cin >> a[i];
  for(int i = 1; i <= m; i++) cin >> b[i];

  ll dp[n + 1][m + 1], sum[n + 1][m + 1];
  for(int i = 0; i <= n; i++){
    for(int j = 0; j <= m; j++){
      sum[i][j] = 0;
      dp[i][j] = 0;
    }
  }

  for(int i = 1; i <= n; i++){
    for(int j = 1; j <= m; j++){
      if(a[i] == b[j]){
        dp[i][j] = sum[i - 1][j - 1] + 1;
        dp[i][j] %= mod;
      }
      sum[i][j] = sum[i - 1][j] + sum[i][j - 1] - sum[i - 1][j - 1] + dp[i][j];
      sum[i][j] = (sum[i][j] + mod) % mod;
    }
  }

  ll ans = 0;
  for(int i = 1; i <= n; i++){
    for(int j = 1; j <= m; j++){
      ans += dp[i][j];
      ans %= mod;
    }
  }
  ans = (ans + 1) % mod;

  cout << ans << endl;
}


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

int main(){
    int N, M, C;
    cin >> N >> M >> C;
    int A[100][100], B[100];
    REP(i, M) cin >> B[i];

    int ans = 0;
    for(int i = 0; i < N; i++){
        int isSolve = C;
        for(int j = 0; j < M; j++){
            cin >> A[i][j];
            isSolve += A[i][j] * B[j];
        }
        if(isSolve > 0) ans++;
    }
    cout << ans << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll long long
#define ull unsigned long long
#define MP make_pair
#define PII pair<int, int>
#define PLL pair<ll, ll>
#define PLI pair<ll, int>
#define PIL pair<int, ll>
#define STR string
#define Fst first
#define Snd second
#define SHN 1e9
#define LSHN 1e18
using namespace std;
ll n,m,k;
ll md=998244353;
ll tac[200010];
ll dow[200010],upp[200010];
ll res=0;
ll mul[60];
void build()
{
	tac[0]=1;
	for (int i=1;i<=n;i++) tac[i]=(tac[i-1]*(m-1))%md;
	dow[n]=1;
	for (int i=n-1;i>=1;i--) dow[i]=(dow[i+1]*i)%md;
	upp[0]=1;
	for (int i=1;i<=n;i++) upp[i]=(upp[i-1]*i)%md;
}
ll rev(ll x)
{
	memset(mul,0,sizeof(mul));
	mul[0]=x;
	for (int i=1;i<50;i++) mul[i]=(mul[i-1]*mul[i-1])%md;
	ll t=md-2,rt=1;
	for (int i=0;i<50;i++)
	{
		if ((1ll<<i)>t) break;
		if (t & (1ll<<i)) rt=(rt*mul[i])%md;
	}
	return rt;
}
int main()
{
	cin >>n>>m>>k;
	k=n-1-k;
	build();
	for (int i=k;i<n;i++)
	{
		ll r=(tac[i]*m)%md;
		r*=(dow[n-i]*rev(upp[i]))%md,r%=md;
		//cout <<i<<" "<<r<<" ##\n";
		res=(res+r)%md;
	}
	cout <<res;
	return 0;
}

Measured memory_bytes: 8324
import java.util.Scanner;
import java.math.*;
import java.text.*;
public class Main {

	public static void main(String[] args) {
		Scanner in = new Scanner(System.in);
		while(in.hasNextDouble()){
			double x1 = in.nextDouble(), y1 = in.nextDouble(),
				x2 = in.nextDouble(), y2 = in.nextDouble(),
				x3 = in.nextDouble(), y3 = in.nextDouble(),
				xp = in.nextDouble(), yp = in.nextDouble();
			double a1 = x2-x1, a2 = y2-y1,
				b1 = x3-x1, b2 = y3-y1,
				c1 = xp-x1, c2 = yp-y1;
			double det = a1*b2-a2*b1;
			if(det==0){
				System.out.println("NO");
				continue;
			}
			double s = (c1*b2-c2*b1)/det,
					t = (a1*c2-a2*c1)/det;
			if(s>=0 && t>=0 && s+t<=1)
				System.out.println("YES");
			else
				System.out.println("NO");
		}
	}

}

Measured memory_bytes: 12000
def main():
    N = int(input())
    value = list(map(int, input().split()))
    if N == 1:
        print("Yes")
        return
    for i in range(N):
        ans = "Yes"
        if i == 0:
            value[i] -= 1
            continue
        if value[i-1] < value[i]:
            value[i] -= 1
        elif value[i-1] == value[i]:
            continue
        else:
            ans = "No"
            break
    print(ans)

if __name__ == "__main__":
    main()


Measured memory_bytes: 14396
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i=0;i<static_cast<int>(n);++i)
#define per(i, n) for(int i=static_cast<int>(n)-1;i>=0;--i)
#define eee(a) (cerr<<"[@"<<__LINE__<<"] "<<(#a)<<": "<<(a)<<'\n');
#define ppp(a) (cout<<(a)<<'\n'); 
#define cop(a) for(auto x:(a)){cerr<<(x)<<'\n';}
using ll = long long;
constexpr int dx[4]={1,0,-1,0};
constexpr int dy[4]={0,1,0,-1};
constexpr ll MOD = 1e9+7;
constexpr ll Mod = 998244353;
constexpr int INF = 1e9;
constexpr ll LINF = 1e18;
constexpr double phi = (1+sqrt(5))/2;
constexpr double pi = 3.14159265358979323846264338327950288;
inline ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
inline ll lcm(ll a,ll b){return a/gcd(a,b)*b;}
inline ll inverse(ll n,ll m=MOD){ll a=n,b=m,x=1,y=0;while(b){ll t=a/b;a-=t*b;swap(a,b);x-=t*y;swap(x,y);}return (a%m+m)%m;}
inline void Yes(){puts("Yes");}
inline void No(){puts("No");}
inline void Judge(bool b){b?Yes():No();}
inline void YES(){puts("YES");}
inline void NO(){puts("NO");}
inline void JUDGE(bool b){b?YES():NO();}
inline ll powmod(ll b, ll e, ll m=MOD){ll r=1;while(e>0){if(e&1)r=(r%m)*(b%m)%m;b=(b%m)*(b%m)%m;e>>=1;}return r;}
inline double distance(ll x1, ll y1, ll x2, ll y2){return sqrt((x1-x2)*(x1-x2)+(y1-y2)*(y1-y2));}
inline double d2r(double d){return d*pi/180;}
inline double r2d(double r){return r*180/pi;}
template<class T>inline bool chmax(T &a, const T &b){if(a<b){a=b;return 1;}return 0;}
template<class T>inline bool chmin(T &a, const T &b){if(b<a){a=b;return 1;}return 0;}
template<typename T>inline int bs(int g,int k,T c){while(abs(k-g)>1){int m=(g+k)/2;(c(m)?k:g)=m;}return k;}
template<typename T1,typename T2>ostream& operator<<(ostream& s,const pair<T1, T2>& p){return s <<"("<<p.first<<", "<<p.second<<")";}
template<typename T> ostream& operator<<(ostream& s,const vector<T>& v){s<<'[';for(size_t i=0;i<v.size();++i){s<<v[i];if(i<v.size()-1)s<<", ";}s<<']';return s;}
template<typename T> istream& operator>>(istream& s,vector<T>& v){for(T& x:v)s>>x;return s;}

int dp[100010];

int main(){
    cin.tie(0); ios::sync_with_stdio(0); cout<<fixed<<setprecision(15);
    
    
    int n, k;
    cin >> n >> k;
    vector<int> h(n);
    cin >> h;

    fill_n(dp, 100010, INF);

    dp[0] = 0;

    for(int i = 0; i < n; ++i){
        for(int j = 1; j <= k; ++j){
            if(i+j < n)
                dp[i+j] = min(dp[i+j], dp[i]+abs(h[i]-h[i+j]));
        }
    }

    cout << dp[n-1] << '\n';

    return 0;
}


Measured memory_bytes: 1024
#include <stdio.h>
#define BLOCK 4
#define FLOOR 3
#define ROOM 10
int main(void)
{
	int n, b, f, r, v, i, j, k;
	int person[BLOCK][FLOOR][ROOM];
	for(i=0; i<BLOCK; i++){
		for(j=0; j<FLOOR; j++){
			for(k=0; k<ROOM; k++){
				person[i][j][k] = 0;
			}
		}
	}
	scanf("%d", &n);
	for(i=0; i<n; i++){
		scanf("%d %d %d %d", &b, &f, &r, &v);
		person[b-1][f-1][r-1] += v;
	}
	for(i=0; i<BLOCK; i++){
		for(j=0; j<FLOOR; j++){
			for(k=0; k<ROOM; k++){
				printf(" %d", person[i][j][k]);
			}
			puts("");
		}
		if(i != BLOCK-1){
			printf("####################\n");
		}
	}
	return 0;
}

Measured memory_bytes: 608
#include<bits/stdc++.h>
using namespace std;
int main(){
  int A,B,M;
  int a,b,c;
  int aminprice = 10000000;
  int bminprice = 10000000;
  int summinprice = 100000000;
  vector<int> avec,bvec,sumvec;
  int x,y;
  
  cin >> A >> B >> M;
  for(int i = 0;i < A;i++){
  	cin >> a;
    aminprice = min(a,aminprice);
    avec.push_back(a);
  }
  for(int i = 0;i < B;i++){
  	cin >> b;
    bminprice = min(b,aminprice);
    bvec.push_back(b);
  }
  summinprice = aminprice + bminprice;
  sumvec.push_back(aminprice + bminprice);
  for(int i = 0;i < M;i++){
  	cin >> x >> y >> c;
    summinprice = min(summinprice,avec.at(x - 1) + bvec.at(y - 1) - c);
    sumvec.push_back(avec.at(x - 1) + bvec.at( y - 1) - c);
  }
  cout << summinprice << endl;
}

Measured memory_bytes: 1784
import java.util.Scanner;

class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt(), m = sc.nextInt(), max = m, l[] = new int[n];
        for (int i = 0; i < n; i++)
            l[i] = sc.nextInt() - sc.nextInt();
        for (int i = 0; i < n; i++) {
            m +=l[i];
            if (m < 0) {
                max = 0;
                break;
            }
            max = Math.max(max, m);
        }
        System.out.println(max);
    }
}


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

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)   FOR(i,0,n)
#define ALL(a)     (a).begin(),(a).end()
#define VI         vector<int>
#define MOD 1000000007

typedef long long int ll;

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; }

const ll INF=(ll)1e19;
//const int INF=(1<<30);

int main(){
  int k,a,b;
  cin >> k >> a >> b;
  cout << (a<= b/k*k ? "OK" : "NG") << endl;
}



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

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

  if (13 <= A) {
    cout << B << endl;
  } else if (6 <= A && A <= 12) {
    cout << B / 2 << endl;
  } else if (A <= 5) {
    cout << 0 << endl;
  }
}


Measured memory_bytes: 384
package main

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

var (
	reader io.Reader = os.Stdin
	writer io.Writer = os.Stdout
)

func main() {
	reader = os.Stdin
	writer = os.Stdout
	run()
}

func run() {
	var results []string
	nums := readIntsFromStdin()[0]
	n, m := nums[0], nums[1]

	results = append(results, strconv.Itoa(n*m))
	results = append(results, strconv.Itoa(n*2+m*2))

	fmt.Fprintln(writer, strings.Join(results, " "))
}

// ReadInts parses lines of inputs into 2D int array.
func readIntsFromStdin() [][]int {
	out := [][]int{}
	scanner := bufio.NewScanner(reader)

	for scanner.Scan() {
		var ints []int

		for _, s := range strings.Split(scanner.Text(), " ") {
			i, err := strconv.Atoi(s)

			if err != nil {
				fmt.Fprintln(os.Stderr, "Failed to parse string into int.", err)
				os.Exit(1)
			}

			ints = append(ints, i)
		}

		out = append(out, ints)
	}

	return out
}



Measured memory_bytes: 1076
h,w, a, b = map(int, input().split())

current = [i for i in range(a)]
cnt = 0
for i in range(h):
    if i < b:
        s = [str(0) if i < a else str(1) for i in range(w)]
    else:
        s = [str(1) if i < a else str(0) for i in range(w)]
    print(''.join(s))


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

const int mod = 1000000007;

int main() {
    ll n;
    cin >> n;
    
    vector<ll> a(n);
    rep(i,n)  cin >> a[i];
    
    ll ans = 0;
    rep(i,60) {
        ll cnt, sum;
        cnt = sum = 0;
        rep(j,n) {
            if(a[j]>>i & 1)
                cnt++;
        }
        sum += cnt * (n-cnt) % mod;
        rep(j,i) {
            sum = sum * 2 % mod;
        }
        ans = (ans + sum) % mod;
    }
    
    cout << ans << endl;
    
    
    return 0;
}


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

using namespace std;

const int N = 100010;

int n, m;
int root[N];

int getRoot(int u) {
    return root[u] != -1 ? root[u] = getRoot(root[u]) : u;
}

int main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    memset(root, -1, sizeof root);
    cin >> n >> m;
    int res = n;
    for (int i = 1; i <= m; i++) {
        int u, v, w;
        cin >> u >> v >> w;
        u = getRoot(u);
        v = getRoot(v);
        if (u != v) {
            root[u] = v;
            res--;
        }
    }   
    cout << res << endl;
    return 0;
}

Measured memory_bytes: 640
import java.util.*;
import java.io.*;

public class Main {
	public static void main(String[] args) throws IOException {
		ABC049A p = new ABC049A();
		p.solve();
	}
}

class ABC049A {
	void solve() throws IOException {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		String yes = "vowel";
		String no = "consonant";
		if (br.readLine().matches("a|e|i|o|u")) System.out.println(yes);
		else System.out.println(no);
	}
}


Measured memory_bytes: 8148
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int N, count=0, x=1;
  cin >> N;
  
  vector<int> vec(N);
  for (int i=0;i<N;i++){
    cin >> vec.at(i);
  }
  
  for (int i=0;i<N;i++){
    if (x == 2){
      break;
    }
    else {
      x = vec.at(x-1);
     count++;
    }
    if (i == N-1) {
      count = -1;
    break;
    }
  }
  cout << count << endl;
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
#define ll long long
int main(){
	string n;
	cin >> n;
	if(n[0]=='7'||n[1]=='7'||n[2]=='7')puts("Yes");
	else puts("No");
}


Measured memory_bytes: 3596
n=int(input())
l=[[j for j,k in enumerate(input())if k=="1"]for i in range(n)]
class UnionFind:
    #def   -> foo=UnionFind(n,1)  <- 1-based index, default is 0
    #method -> foo.hoge(huga)
    __slots__ = ["_size", "_first_idx", "_parents"]
    def __init__(self, size: int, first_index: int = 0) -> None:
        self._size = size
        self._first_idx = first_index
        self._parents = [-1] * (size + first_index)
    def find(self, x: int) -> int:
        if self._parents[x] < 0:
            return x
        self._parents[x] = self.find(self._parents[x])
        return self._parents[x]
    def same(self, x: int, y: int) -> bool:
        return self.find(x) == self.find(y)
    def unite(self, x: int, y: int) -> bool:
        x, y = self.find(x), self.find(y)
        if x == y:
            return False
        if self._parents[x] > self._parents[y]:
            x, y = y, x
        self._parents[x] += self._parents[y]
        self._parents[y] = x
        return True
    def size(self, x: int) -> int:
        return -self._parents[self.find(x)]
    def group_count(self) ->int:
        return sum(1 for i in  self._parents if i<0)-self._first_idx
    def connected(self) ->bool:
        return self._parents[self.find(self._first_idx)]==-self._size
uf=UnionFind(2*n)
for i in range(n):
    for j in l[i]:
        uf.unite(i,j+n)
        uf.unite(i+n,j)
f=0
for i in range(n):
    f|=uf.same(i,i+n)

if f:
    print(-1)

else:
    class WarshallFloyd:
        #O(V^3)で任意２頂点の最短距離
        def __init__(self,n,_first_index=0):
            self.v = n
            self._first_idx=_first_index
            self.d = [[float("INF")]*(n) for _ in range(n)]
            for i in range(n):
                self.d[i][i] = 0
    
        def path(self,x,y,c):
            if x == y:
                return False
            f=self._first_idx
            self.d[x-f][y-f] = c
            self.d[y-f][x-f] = c
            return True
    
        def build(self):
            for k in range(self.v):
                for i in range(self.v):
                    for j in range(self.v):
                        self.d[i][j] = min(self.d[i][j], self.d[i][k] + self.d[k][j])
            return self.d
    w=WarshallFloyd(n)
    for x in range(n):
        for j in l[x]:
            w.path(x,j,1)
    d=w.build()
    ans=0
    for i in range(n):
        ans=max(ans,max(d[i]))
    print(ans+1)

Measured memory_bytes: 57688
#include <cctype>
#include <cerrno>
#include <cfloat>
#include <ciso646>
#include <climits>
#include <clocale>
#include <cmath>
#include <csetjmp>
#include <csignal>
#include <cstdarg>
#include <cstddef>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>

#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>
#include <regex>
#define rep(i,n) for(int i = 0; i < n; i++)
#define reps(i,j,n) for(int i = j; i < n; i++)
#define rrep(i,j,n) for(int i = j-1; i >= n; i--)
#define prec(n) fixed << setprecision(n)
#define print_array(v) rep(__k, v.size()) { cout << v[__k]; if(__k != v.size()-1) cout << " "; else cout << endl; }
#define YesorNo(a) printf(a?"Yes\n":"No\n")
#define fi first
#define se second
using namespace std;

int inf = 2147483647;
int64_t inf64 = 9223372036854775807;
int mod = 1e+7;

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

  int x;
  cin >> x;
  bool res = false;

  if(x >= 2000) res = true;
  rep(i,20) {
    rep(j,20) {
      rep(k,20) {
        rep(l,20) {
          rep(m,20) {
            rep(n,20) {
              if(i*105+j*104+k*103+l*102+m*101+n*100 == x) res = true;
            }
          }
        }
      }
    }
  }
  cout << (int)res << endl;
  return 0;
}

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

int main() {
  int N, C, K;
  cin >> N >> C >> K;
  vector<int> t = vector<int>(N);
  for (int i = 0; i < N; i++) cin >> t.at(i);
  sort(t.begin(), t.end());

  int busCount = 0;
  for (int i = 0; i < N;) {
    int start = i;
    while (i < N && i - start < C && t.at(i) <= t.at(start) + K) i++;
    busCount++;
  }
  cout << busCount << endl;
  return 0;
}

Measured memory_bytes: 888
#include <bits/stdc++.h>
using namespace std;
main(){
    int h, w, d, q, a, l, r;
    map<int, pair<int, int>> v;
    int sum[90001] = {};
    cin >> h >> w >> d;
    for(int i = 0; i < h; i++) for(int j = 0; j < w; j++) cin >> a, v[a] = make_pair(i, j);
    for(int i = d + 1; i <= h*w; i++) sum[i] = sum[i - d] + abs(v[i].first - v[i - d].first) + abs(v[i].second - v[i - d].second);
    cin >> q; while(q--) cin >> l >> r, cout << sum[r] - sum[l] << '\n';
}

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

using namespace std;
using ll = long long;

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

int gcd(int a, int b) {
  if (b == 0) return a;
  return gcd(b, a % b);
}

struct SegmentTree {
  int n;
  vector<int> v;
  SegmentTree(int size, int *a) {
    n = 1;
    while (n < size) n *= 2;
    v = vector<int>(2 * n - 1);
    rep(i, size) v[i + n - 1] = a[i];
    rep(i, size) {
      int j = i + n - 1;
      while (j > 0) {
        j = (j - 1) / 2;
        v[j] = gcd(v[2 * j + 1], v[2 * j + 2]);
      }
    }
  }

  SegmentTree(int size) {
    n = 1;
    while (n < size) n *= 2;
    v = vector<int>(2 * n - 1, 0);
  }

  void update(int i, int x) {
    i += n - 1;
    v[i] = x;
    while (i > 0) {
      i = (i - 1) / 2;
      v[i] = gcd(v[2 * i + 1], v[2 * i + 2]);
    }
  }

  int solve(int a, int b, int k, int l, int r) {
    if (r <= a || b <= l) return 0;
    if (a <= l && r <= b) return v[k];
    int c1 = solve(a, b, 2 * k + 1, l, (l + r) / 2);
    int c2 = solve(a, b, 2 * k + 2, (l + r) / 2, r);
    return gcd(c1, c2);
  }

  int solve(int a, int b) { return solve(a, b, 0, 0, n); }
};

int main() {
  int n;
  cin >> n;
  int a[n];
  rep(i, n) cin >> a[i];

  SegmentTree st(n, a);
  int ans = -1;
  rep(i, n) { ans = max(ans, gcd(st.solve(0, i), st.solve(i + 1, n))); }
  cout << ans << endl;
  return 0;
}


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

int main()
{
  int n;
  cin>>n;
  
  if(n==1)
    cout << fixed << setprecision(15) <<1<<endl;
  else if(n%2==0)
    cout << fixed << setprecision(15) <<0.5<<endl;
  else
    cout << fixed << setprecision(15) <<(((double)n-1.0)/2.0+1.0)/((double)n)<<endl;
 
  return 0;
}

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

int main(){
	unsigned N;
	unsigned *a;
	unsigned i;
	int updown = 0;
	unsigned count = 0;
	scanf("%u", &N);
	a = (unsigned *)malloc(sizeof(unsigned) * N);
	for(i = 0; i < N; i++) scanf("%u", a + i);
	for(i = 1; i < N; i++){
		if(a[i - 1] < a[i]){
			if(!updown){
				updown = 1;
			}else if(updown == -1){
				count++;
				updown = 0;
			}
		}else if(a[i - 1] > a[i]){
			if(!updown){
				updown = -1;
			}else if(updown == 1){
				count++;
				updown = 0;
			}
		}
	}
	printf("%d", count + 1);
	return 0;
}

Measured memory_bytes: 512
#include <iostream>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <algorithm>
#include <string>
#include <cmath>
#include <cstdio>
#include <iomanip>
#include <fstream>
#include <cassert>
#include <cstring>
#include <unordered_set>
#include <unordered_map>
#include <numeric>
#include <ctime>
#include <bitset>
#include <complex>
#include <chrono>
#include <random>
#include <functional>

using namespace std;

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

	int n, m;
	cin >> n >> m;
	m += (n - 1);
	vector<int> in(n);
	vector<vector<int>> g(n);
	for (int i = 0; i < m; i++) {
		int u, v;
		cin >> u >> v;
		u--;
		v--;
		g[u].push_back(v);
		in[v]++;
	}
	vector<int> p(n, -1);
	queue<int> q;
	for (int i = 0; i < n; i++) {
		if (in[i] == 0) {
			q.push(i);
		}
	}
	while (!q.empty()) {
		int v = q.front();
		q.pop();
		for (auto u : g[v]) {
			in[u]--;
			if (!in[u]) {
				p[u] = v;
				q.push(u);
			}
		}
	}
	for (auto t : p) {
		cout << t + 1 << '\n';
	}
}


Measured memory_bytes: 9104
from fractions import gcd
a, b, c, d = map(int, input().split())
l = c*d // gcd(c, d)
x = (a-1) - (a-1)//c - (a-1)//d + (a-1)//l
y = b - b//c - b//d + b//l
print(y-x)

Measured memory_bytes: 5048
A,B,C = input().split()
A = int(A)
B = int(B)
C = int(C)

if A == B == C :
    print('No')
elif A == B :
    print('Yes')
elif B == C :
    print('Yes')
elif C == A :
    print('Yes')
elif A == B == C :
    print('No')
else :
    print('No')

Measured memory_bytes: 9172
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep2(i, s, n) for (int i = (s); i < (int)(n); i++)
typedef long long ll;
#define ALL(v) v.begin(), v.end()
#define vmax(v) *max_element(ALL(v))
#define vmin(v) *min_element(ALL(v))
#define chmax(x, a) x = max(x, a)
#define chmin(x, a) x = min(x, a)

int main() {
    int N;
    ll D; cin >> N >> D;
    ll X, Y;
    int cnt = 0;
    rep(i, N) {
        cin >> X >> Y;
        if (X*X + Y*Y <= D*D) cnt++;
    }
    cout << cnt << endl;
}


Measured memory_bytes: 3620
#include<stdio.h>
int main(void)
{
    int d1,d2,m1,m2;
    scanf("%d%d",&m1,&d1);
    scanf("%d%d",&m2,&d2);

    if(m1 == 1 || m1 == 3 || m1 == 5 || m1 == 7 || m1 == 8 || m1 == 10 || m1 == 12)
    {
        if(d1 == 31)
        printf("1");
        else 
        printf("0");
    }
    else if(m1 == 2)
    {
        if(d1 == 28)
        printf("1");
        else 
        printf("0");
    }
    else
    {
        if(d1 == 30)
        printf("1");
        else
        printf("0");
    }
return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
#include <vector>
#include <iostream>
#include<algorithm>
#include<string>
#include <map>
#include <queue>
#include <stack>
#include<set>

#define DIV 998244353
using namespace std;
using ll = long long;
using ldb = long double;

int main() {
	ll N; cin >> N;
	map<ll, ll> cnt;
	for (int i = 0; i < N; i++) {
		ll a; cin >> a;
		cnt[a]++;
	}
	ll tot = 0;
	for (auto x : cnt) {
		tot += x.first * x.second;
	}

	ll Q; cin >> Q;
	for (int i = 0; i < Q; i++) {
		ll B, C; cin >> B >> C;
		tot += cnt[B] * (C - B);
		cnt[C] += cnt[B];
		cnt[B] = 0;
		cout << tot << endl;
	}

}

Measured memory_bytes: 9392
#include <iostream> // cout, endl, cin
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower

using namespace std;
 
int main(){
    int A,B;
    cin >> A >> B;
    if(A <= B){
        cout << A << endl;
    }
    else cout << A-1 << endl;
}

Measured memory_bytes: 3572
#include <bits/stdc++.h>
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
typedef long long ll;
typedef std::vector<long long> vll;
typedef std::vector<std::vector<long long>> vvll;
typedef long double ld;
typedef std::vector<long double> vld;
typedef std::vector<std::vector<long double>> vvld;
using namespace std;
void yesno(bool state);

void Main(){
    ll N;
    cin >> N;
    vector<bool> isR(N);
    rep(i,N){
        char c;
        cin >> c;
        if(c == 'R')
            isR[i] = true;
        else
            isR[i] = false;
    }
    ll r = 0;
    rep(i,N)
        if(isR[i] == true)
            r++;
    ll ans = 0;
    rep(i,r)
        if(!isR[i])
            ans++;
    cout << ans << endl;
        
}

int main(int argc, char const *argv[])
{
    Main();
    return 0;
}

void yesno(bool state){
    if(state)
        cout << "Yes" << endl;
    else
        cout << "No" << endl;
}

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

int main(void)
{
  float a,b,c,d;
  cin>>a>>b>>c>>d;

  if(abs(c-a)<=d)
    cout<<"Yes"<<endl;
  else if(abs(b-a)<=d&&abs(c-b)<=d)
    cout<<"Yes"<<endl;
  else
    cout<<"No"<<endl;
}

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

int main() {
    int N, M;
    cin >> N >> M;
    int L = 1, R = N;
    rep(i, M) {
        int l, r;
        cin >> l >> r;
        L = max(L, l);
        R = min(R, r);
    }
    int ans = max(R - L + 1, 0);
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
//型に気を付けよう

#define rep(i,n) for(int i=0;i<n;i++)
typedef long long  ll;
const double pi=3.1415926535;
const ll  mod=1000000007;
//桁数指定　cout << fixed << setprecision(2)
int main() {
  int h1,a1,h2,a2;
  string ans="Yes";
  cin>>h1>>a1>>h2>>a2;
  while(1){
    h2-=a1;
    if(h2<=0)break;
    h1-=a2;
    if(h1<=0){ans="No";break;}
  }
  cout<<ans;
}

Measured memory_bytes: 3628
import java.util.*;

public class Main {

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

        int a = sc.nextInt();
        int b = sc.nextInt();
        int c = sc.nextInt();

        if ((a <= c && c <= b) || (b <= c && c <= a)) {
            System.out.println("Yes");
        } else {
            System.out.println("No");
        }

    }
}

Measured memory_bytes: 22356
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (int)(n); i ++)
#define irep(i,n) for (int i = (int)(n) - 1;i >= 0;--i)
using namespace std;
using ll = long long;
using PL = pair<ll,ll>;
using P = pair<int,int>;
constexpr int INF = 1000000000;
constexpr long long HINF = 1000000000000000;
constexpr long long MOD = 1000000007;// = 998244353;
constexpr double EPS = 1e-4;
constexpr double PI = 3.14159265358979;

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

    int N; cin >> N;
    vector<int> A(N),B(N);
    rep(i,N) cin >> A[i];
    rep(i,N) cin >> B[i];
    vector<int> ca(N + 1,0),cb(N + 1,0);
    rep(i,N) {
        ca[A[i]]++;
        cb[B[i]]++;
    }
    rep(i,N) {
        if (ca[i + 1] + cb[i + 1] > N) {
            cout << "No" << '\n';
            return 0;
        }
    }

    rep(i,N) {
        ca[i + 1] += ca[i];
        cb[i + 1] += cb[i];
    }
    int ma = -1;
    rep(i,N) ma = max(ma,ca[i + 1] - cb[i]);

    cout << "Yes" << '\n';
    rep(i,N) cout << B[(i - ma + N)%N] << ' ';
    cout << '\n';
    return 0;
}

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

using namespace std;

long long h[200005];

int main()
{
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	
	long long n, k, z = 0;
	cin >> n >> k;
	for(long long i = 0; i < n; ++i){
		cin >> h[i];
	}
	sort(h, h + n);
	reverse(h, h + n);
	for(long long i = k; i < n; ++i){
		z += h[i];
	}
	cout << z;

	return 0;
}



Measured memory_bytes: 1792
import numpy


K = int(input())

cnt = 0
for i in range(1, K):
    for j in range(i+1, K+1):
        if (i % 2 == 0 and j % 2 != 0) or (i % 2 != 0 and j % 2 == 0):
            cnt += 1
print(cnt)


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

using namespace std;

using ll = long long;

int main(void) {
    string n;
    cin >> n;
    ll s = n.size();
    
    vector<vector<ll>> dp(s+1, vector<ll>(11));

    dp[s][1] = 1;
    for(ll i=s-1; i>=0; i--) {
        ll nn = n[i] - '0';

        dp[i][0] = dp[i+1][0] + nn;
        if(nn < 9)
            dp[i][0] = min(dp[i][0], dp[i+1][1] + nn + 1);

        dp[i][1] = dp[i+1][0] + (10 - nn);
        if(nn < 9)
            dp[i][1] = min(dp[i][1], dp[i+1][1] + (9 - nn));
        else
            dp[i][1] = min(dp[i][1], dp[i+1][1]);
    }

    cout << min(dp[0][0], dp[0][1]+1) << endl;
}

Measured memory_bytes: 118404
N, X, Y = map(int, input().split())
ans = [0] * N

for i in range(1, N + 1):
    for j in range(i + 1, N + 1):
        d = min(
            j - i,
            abs(i - X) + 1 + abs(j - Y),
            abs(j - X) + 1 + abs(i - Y)
        )
        ans[d] += 1

print(*ans[1:], sep='\n')


Measured memory_bytes: 46812
#include <bits/stdc++.h>
#define int long long
#define pii pair<int,int>
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) FOR(i,0,n)
#define ALL(c) (c).begin(),(c).end()
#define ZERO(a) memset(a,0,sizeof(a))
#define MINUS(a) memset(a,0xff,sizeof(a))
#define MINF(a) memset(a,0x3f,sizeof(a))
#define POW(n) (1LL<<(n))
#define IN(i,a,b) (a <= i && i <= b)
using namespace std;
template <typename T> inline bool CHMIN(T& a,T b) { if(a>b) { a=b; return 1; } return 0; }
template <typename T> inline bool CHMAX(T& a,T b) { if(a<b) { a=b; return 1; } return 0; }
template <typename T> inline void SORT(T& a) { sort(ALL(a)); }
template <typename T> inline void REV(T& a) { reverse(ALL(a)); }
template <typename T> inline void UNI(T& a) { sort(ALL(a)); a.erase(unique(ALL(a)),a.end()); }
const int MOD = 1000000007;
const int INF = 0x3f3f3f3f3f3f3f3f;
const double EPS = 1e-10;
/* ---------------------------------------------------------------------------------------------------- */

int N,Z,W;
int a[2010];
bool used[2][2010];
int memo[2][2010];

int dfs(int t, int i) {
  if (used[t][i]) return memo[t][i];
  int res;
  if (t == 0) {
    res = abs(a[N-1] - (i == 0 ? W : a[i-1]));
    for (int k = i+1; k < N; k++) {
      CHMAX(res,dfs(t^1,k));
    }
  } else {
    res = abs(a[N-1] - (i == 0 ? Z : a[i-1]));
    for (int k = i+1; k < N; k++) {
      CHMIN(res,dfs(t^1,k));
    }
  }
  used[t][i] = true;
  return memo[t][i] = res;
}

signed main() {
  cin.tie(0);
  ios_base::sync_with_stdio(false);
  cout << fixed << setprecision(10);

  cin >> N >> Z >> W;
  REP(i,N) cin >> a[i];
  cout << dfs(0,0) << endl;

  return 0;
}

Measured memory_bytes: 384
#include <stdio.h>
#include <limits.h>
int main(){
  int n;
  int i;
  long max =LONG_MIN;
  long min =LONG_MAX;
  long sum =0;
  int num;

  scanf("%d",&n);

  for(i=0;i<n;i++){
    scanf("%d",&num);

    if(num<min){
      min=num;
    }
    if(num>max){
      max=num;
    }
    sum+=num;
  }
  printf("%ld %ld %ld\n",min,max,sum);

    return 0;
  }
  



Measured memory_bytes: 2104
#include<iostream>
#include<string>
#include<cstring>
#include<algorithm>
#include<vector>
#include<iomanip>
#include<math.h>
#include<complex>
#include<queue>
#include<deque>
#include<stack>
#include<map>
#include<set>
#include<bitset>
#include<functional>
#include<assert.h>
#include<numeric>
using namespace std;
#define REP(i,m,n) for(int i=(int)(m) ; i < (int) (n) ; ++i )
#define rep(i,n) REP(i,0,n)
using ll = long long;
const int inf=1e9+7;
const ll longinf=1LL<<60 ;
const ll mod=1e9+7 ;
#define PI 3.141592653589793

int main(){
   int N, M, X; cin >> N >> M >> X; int c[15], a[15][15];
   rep(i, N){
       cin >> c[i];
       rep(j, M){
           cin >> a[i][j];
       }
   }
   int an=inf;
   for(int bits=0; bits<(1<<N); bits++){
       int ans[15] = {}; int cost = 0;
       rep(i, N){
           if(bits&(1<<i)){
             cost+=c[i];
             rep(j, M){
                 ans[j]+=a[i][j];
             }
           }
       }
       bool can=true;
       rep(j, M){
             if(ans[j]<X) can=false;
         }
         if(can){
             //if(cost<an) cout << bits << " " << cost << endl;
             an = min(an, cost);
             
         }
   }
   if(an==inf) cout << -1 << endl;
   else cout << an << endl;
}

Measured memory_bytes: 3636
#include<bits/stdc++.h>
#define rep(i, n) for(int i=0; i<n; i++)
#define repo(i, n) for(int i=1; i<=n; i++)
#define INF 1001001001
#define INFll 100100100100100
// debug用
#define PrintVec(x) for (auto elementPrintVec: x) { cout << elementPrintVec << " "; } cout << endl;

using namespace std;
using ull = unsigned long long;
using ll = long long;
using P = pair<int, int>;
const int mod = 1000000007;

struct mint {
  ll x; // typedef long long ll;
  mint(ll x=0):x((x%mod+mod)%mod){}
  mint operator-() const { return mint(-x);}
  mint& operator+=(const mint a) {
    if ((x += a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator-=(const mint a) {
    if ((x += mod-a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator*=(const mint a) {
    (x *= a.x) %= mod;
    return *this;
  }
  mint operator+(const mint a) const {
    mint res(*this);
    return res+=a;
  }
  mint operator-(const mint a) const {
    mint res(*this);
    return res-=a;
  }
  mint operator*(const mint a) const {
    mint res(*this);
    return res*=a;
  }
  mint pow(ll t) const {
    if (!t) return 1;
    mint a = pow(t>>1);
    a *= a;
    if (t&1) a *= *this;
    return a;
  }

  // for prime mod
  mint inv() const {
    return pow(mod-2);
  }
  mint& operator/=(const mint a) {
    return (*this) *= a.inv();
  }
  mint operator/(const mint a) const {
    mint res(*this);
    return res/=a;
  }
};

const int MAX = 510000;//階乗の配列数
const int MOD = 1000000007;

long long 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;
    }
}

// 二項係数計算
long long 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;
}

// 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;
}

// 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;
}

int main(){
  int n , k;
  cin >> n >> k;
  vector<ll> a(n);
  rep(i, n){
    cin >> a[i];
  }
  sort(a.begin(), a.end());
  mint ans=0;
  COMinit();
  rep(i, n-k+1){
    ans-=a[i]*COM(n-i-1, k-1);
  }
  for(int i=k-1; i<n; i++){
    ans+=a[i]*COM(i, k-1);
  }
  cout << ans.x << endl;
  return 0;
}


Measured memory_bytes: 15772
#include <cstdio>
#include <cstdlib>
#include <vector>
#define repeat(i, n) for (int i = 0; (i) < int(n); ++(i))
#define repeat_reverse(i, n) for (int i = (n)-1; (i) >= 0; --(i))
using namespace std;

int main() {
    // input
    int n, dd; scanf("%d%d", &n, &dd);
    vector<int> d(n); repeat (i, n) scanf("%d", &d[i]);

    // solve
    vector<int> a(n + 1);
    a[0] = dd;
    repeat (i, n) {
        a[i + 1] = min(a[i], abs(a[i] - d[i]));
    }
    vector<int> b(n + 1);
    b[n] = 1;
    repeat_reverse (i, n) {
        b[i] = b[i + 1] + (b[i + 1] <= d[i] / 2 ? 0 : d[i]);
    }

    // output
    int queries; scanf("%d", &queries);
    while (queries --) {
        int q_i; scanf("%d", &q_i); -- q_i;
        bool result = b[q_i + 1] <= a[q_i];
        printf("%s\n", result ? "YES" : "NO");
    }
    return 0;
}


Measured memory_bytes: 7808
//If you can think it, you should implement it
#include<bits/stdc++.h>
using namespace std;
 
#define xlr8 ios::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define int long long int
#define ld long double
#define mod 1000000007
#define eb emplace_back
#define mp make_pair
#define nl "\n"
#define ignore cin.ignore(numeric_limits<streamsize>::max(),'\n')

#define error(args...) { string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); stringstream _ss(_s); istream_iterator<string> _it(_ss); err(_it, args); }

void err(istream_iterator<string> it) {}
template<typename T, typename... Args>
void err(istream_iterator<string> it, T a, Args... args) {
    cerr << *it << " = " << a << endl;
    err(++it, args...);
}

int power(int a,int b,int m=mod){ int ans=1; a=a%m;  while(b>0) {  if(b&1)  ans=(1LL*a*ans)%m; b>>=1;a=(1LL*a*a)%m;}return ans;}
int ncr(int n,int r){ int res=1; if(r>n-r)r=n-r; for(int i=0;i<r;i++) {  res*=n-i;  res/=i+1; } return res; }
int gcd(int a,int b){  if(b==0) return a;  return gcd(b,a%b);}
int lcm(int a,int b){return (a* b)/gcd(a,b);}

//__builtin_popcount()
//memset(a,0,sizeof(a))
//bool next_permutation(a.begin(),a.end())

int sum(int a)
{
    int cnt=0;
    while(a!=0)
    {
        cnt+=a%10;
        a/=10;
    }
    return cnt;
}

signed main(){
    xlr8;
    int tt=1;
    //cin>>tt;
    while(tt--)
    {
        int a,b,c,k;
        cin>>a>>b>>c>>k;
        int ans=0;
       if(k>a)
       {
         if(k>a+b)
         {
            ans=a-(k-a-b);
         }
         else
            ans=a;
       }
       else
        ans+=k;
        cout<<ans<<nl;



    }

 return 0;
}

Measured memory_bytes: 3652
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define mod 1000000007
ll a[100001]={0};
int main()
{//ios_base::sync_with_stdio(false);
    ll s,w;
    cin>>s>>w;
    if(w>=s)
        cout<<"unsafe";
    else
        cout<<"safe";
}


Measured memory_bytes: 3628
import java.util.Scanner;

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

    private void run() {
        Scanner scanner = new Scanner(System.in);
        String N = scanner.next();
        int sum = 0;
        for(char num : N.toCharArray()) {
            int n = num - '0';
            sum += n;
        }
        if(sum % 9 == 0) {
            System.out.println("Yes");
        }else{
            System.out.println("No");
        }
    }
}

Measured memory_bytes: 40436
using System;

public class Problem_B
{
  public static void Main()
  {
    var N = int.Parse(Console.ReadLine());
    var a = new int[N];
    for (var i = 0; i < N; i++) a[i] = int.Parse(Console.ReadLine());

    var pressed = new bool[N];
    Console.WriteLine($"{FindAns(0, a, pressed, 0)}");
  }

  private static int FindAns(int next, int[] paths, bool[] visited, int count)
  {
    if (visited[next]) return -1;
    visited[next] = true;
    if (paths[next] == 2) return count + 1;
    else return FindAns(paths[next] - 1, paths, visited, ++count);
  }
}


Measured memory_bytes: 18144
import java.util.*;
public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		
		int n = sc.nextInt();
		int[] dep = new int[n];
		long sum=0;
		
		for (int i=0;i<n;i++){
			dep[i]=sc.nextInt();
		}
		
		for(int s=0;s<n;s++){
			for(int t=s+1;t<n;t++){
				sum += dep[s] * dep[t];
			}
		}
		
		System.out.print(sum);
	}
}

Measured memory_bytes: 21844