akhauriyash/Code-Regression huggingface dataset:
import java.util.*;
 
public class Main {
    public static void main(String[] args) {

        Scanner scan = new Scanner(System.in);
        
        int n = scan.nextInt();

        List<Long> list = new ArrayList<Long>();
        for (int i = 0; i < n; i++) {
            long a = scan.nextLong();
            list.add(a);
        }

        Collections.sort(list);//System.out.println(list);
        // listの先頭が0だったら、0を出力して即終了
        if (list.get(0) == 0) {
            System.out.println(0);
            return;
        }

        long ans = 1l;
        for (int i = 0; i < n; i++) {
            long a = list.get(i);
            ans *= a;
            if (ans > 1000000000000000000l || ans <= 0) {
                break;
            }
        }
        if (ans > 1000000000000000000l || ans <= 0) {
            //System.out.println(ans);
            System.out.println(-1);
        } else {
            System.out.println(ans);
        }
        
    }
}

Measured memory_bytes: 61568
/**
*    author:  souzai32
*    created: 01.08.2020 17:22:10
**/

#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using namespace std;

int main() {

    int n;
    cin >> n;
    vector<string> s(n);
    rep(i,n){
        cin >> s.at(i);
        sort(s.at(i).begin(),s.at(i).end());
    }

    vector<int> alp(26);
    vector<int> ans(26,100);
    int count=0;

    rep(i,n){
        int k=0;
        rep(j,s.at(i).size()){
            alp.at(s.at(i).at(j)-'a')++;
        }
        rep(j,26){
            ans.at(j)=min(ans.at(j),alp.at(j));
            alp.at(j)=0;
        }
    }

    char a='a';
    rep(i,26){
        //cout << ans.at(i) << endl;
        rep(j,ans.at(i)) cout << a;
        a++;
    }
    cout << endl;

    return 0;
}

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

int main()
{
   ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
   int t;t=1;while(t--)
   {
       string s;cin>>s;
       if(s.length()==6)
       {
           if(s[2]==s[3]&&s[4]==s[5]) cout<<"Yes\n";
           else cout<<"No\n";
       }
       else cout<<"No\n";
   }
}


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

int main() {
    uint32_t n; cin >> n;
    uint32_t ret = 0;
    for (uint32_t cn = 1, i = n; i; --i) {
        uint32_t a; cin >> a;
        if (cn == a)++cn;
        else ++ret;
    }
    if (ret == n)cout << -1 << endl;
    else cout << ret << endl;
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
int n,t,tt[200005];
int main(){
	scanf("%d%d",&n,&t);
	for(int i=1;i<=n;i++) scanf("%d",&tt[i]);
	int ans=t;
	for(int i=2;i<=n;i++){
		ans+=min(t,tt[i]-tt[i-1]);
	}
	printf("%d\n",ans);
	return 0;
}
//QAZWSXEDCRFVTGBYHNUJMIKOLP


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

int main(){
    int h, n; cin >> h >> n;
    vector<pair<int, int>> ab;
    for(int i = 0; i < n; i++){
        int a, b; cin >> a >> b;
        ab.push_back(make_pair(a, b));
    }
    ll dp[10001] = {0};
    for(int i = 1; i <= 10000; i++) dp[i] = 1e8;
    for(int hp = 0; hp <= h; hp++){
        if(dp[hp] == 1e8) continue;
        for(int i = 0; i < n; i++){
            dp[min(hp+ab[i].first, h)] = min(dp[min(hp+ab[i].first, h)], dp[hp] + ab[i].second);
        }
    }
    cout << dp[h] << endl;
}

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

const int MAXN = 10001;

int main()
{
  bool prime[MAXN];

  memset(prime, true, sizeof(prime));
  prime[0] = prime[1] = false;

  for (int i = 2; i * i < MAXN; i++){
    for (int j = i * i; j < MAXN; j += i){
      prime[j] = false;
    }
  }

  int n;
  while (scanf("%d", &n), n){
    for (int i = n;; i--){
      if (prime[i] && prime[i - 2]){
        printf("%d %d\n", i - 2, i);
        break;
      }
    }
  }

  return (0);
}

Measured memory_bytes: 1204
#!/usr/bin/env python3
import sys


def solve(N: int):
    count = 0
    for i in range(1, N+1):
        if i  % 2 != 0:
            count += 1
    print(count / N)
    return


# Generated by 1.1.5 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
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
    solve(N)

if __name__ == '__main__':
    main()


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

adj=[[] for i in range(N+1)]
for i in range(N-1):
	a,b,c=[int(x) for x in input().split()]
	adj[a].append([b,c])
	adj[b].append([a,c])
	


Q,K=[int(x) for x in input().split()]
dist=[0 for i in range(N+1)]

import heapq
queue=[[K,0]]
heapq.heapify(queue)
while queue:
	#print(queue)
	a=heapq.heappop(queue)
	node=a[0]
	cost=a[1]
	for temp in adj[node]:
		if dist[temp[0]]==0:
			heapq.heappush(queue,[temp[0],temp[1]+cost])
			dist[temp[0]]=cost+temp[1]

B=[]
for i in range(Q):
	x,y=[int(x) for x in input().split()]
	print(dist[x]+dist[y])


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

#define mp make_pair
#define pb push_back

#define int int64_t
#define ld long double

const int MOD = 1e9+7;
const int N = 1e6+5;

int32_t main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);

    int n,m;
    cin>>n>>m;
    int x;
    int s=0;
    for(int i=0;i<m;i++) {
        cin>>x;
        s+=x;
    }   
    n-=s;
    int lmao = -1;
    cout<<max(n, lmao);

    return 0;
}

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

#define chmin(a, b) (a = min(a, b))

int n, m;
int a[100];
vector<pair<int, int>> v[2];
long long dp[2][100010];

int main()
{
	while (cin >> n, n){
		v[0].clear(), v[1].clear();
		for (int i = 0; i < n; i++){
			cin >> a[i];
		}
		cin >> m;
		for (int i = 0; i < m; i++){
			string s, t;
			int p, d;
			cin >> s >> p >> t >> d;
			v[t == "Single"].emplace_back(p, d);
		}
		fill_n(*dp, 2 * 100010, 1ll << 52);
		dp[0][0] = dp[1][0] = 0;
		for (int i = 0; i < 2; i++){
			for (int j = 0; j < v[i].size(); j++){
				for (int k = 1; k <= 100000; k++){
					chmin(dp[i][k], dp[i][max(0, k - v[i][j].second)] + v[i][j].first);
				}
			}
		}
		long long res = 1ll << 52;
		for (int i = 0; i <= 100000; i++){
			long long sum = dp[0][i];
			for (int j = 0; j < n; j++){
				sum += dp[1][max(0, a[j] - i)];
			}
			chmin(res, sum);
		}
		cout << res << endl;
	}
}

Measured memory_bytes: 4692
#include <iostream>

using namespace std;
#define MAX 1000

class queue{
    int num;
    queue* head = NULL;
    queue* tail = NULL;
public:
    void enque(int x){
        if(head == NULL){
            head = new queue(x);
            tail = head;
        }
        else{
            tail->head = new queue(x);
            tail = tail->head;
        }
    }
    
    int front(){
        return head->num;
    }
    
    void deque(){
        // 繋ぎかえる
        if(this->head->head != NULL){
            queue* tmp = head;
            this->head = this->head->head;
            delete tmp;
            tmp = NULL;
        }
        else if(head != NULL){
            delete head;
            head = NULL;
        }
    }
    
    bool empty(){
        return head == NULL;
    }
    
    queue(){
        
    }
    
    queue(int num){
        this->num = num;
    }
};

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    int n,q,command,t,x;
    queue myQueue[MAX];
    cin >> n >> q;
    
    for (int i = 0;i < q;++i) {
        cin >> command >> t;
        switch(command){
                // enque
            case 0:
                cin >> x;
                myQueue[t].enque(x);
                break;
                // front
            case 1:
                if(!myQueue[t].empty()){
                    cout << myQueue[t].front() << endl;
                }
                break;
                // deque
            case 2:
                if(!myQueue[t].empty()){
                    myQueue[t].deque();
                }
                break;
        }
    }
}



Measured memory_bytes: 9356
#include<iostream>
#include<vector>
#include<string>
#include<cmath>
#include<algorithm>
#include<functional>
#include<numeric>
#include<queue>
#include<stack>
#include<map>
#include<unordered_map>
#include<set>
#include<bitset>
#include<random>

#pragma region
using namespace std;
#define FOR(i,r,n) for(ll i = (ll)(r); i < (ll)(n); i++)
#define rep(i,n) FOR(i,0LL,n)
#define RFOR(i,r,n) for(ll i=(ll)(n-1);i>=r;i--)
#define rrep(i,n) RFOR(i,0LL,n)
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(),x.rend()
#define COUNT(a,y,x) upper_bound(all(a), y) - lower_bound(all(a), x)
#define UNIQUE(a) sort(all(a)); a.erase(unique(all(a)), a.end())
#define pb push_back
typedef long long int ll;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef pair<ll, ll> pll;
typedef vector<pll> vpll;
typedef vector<string> vs;
typedef map<ll, ll> MAP;
const ll inf = 1LL << 61;
const ll mod = 1000000007LL;
//const ll mod = 998244353LL;

ll n = 0, m = 0, ans = 0, tmp = 0, ma = -inf, mi = inf;
string s;
bool ok;
ll dx[9] = { 0,1,0,-1,0,1,1,-1,-1 }, dy[9] = { 0,0,1,0,-1,1,-1,1,-1 };
#define endl '\n'
#pragma endregion
#define MAX 222222






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


  cin >> n >> m;
  if (n < m) cout << "0" << endl;
  else cout << "10" << endl;



  

  return 0;
}

Measured memory_bytes: 256
#include <stdio.h>

int main(void)
{
    char s[4];

    for (int i = 0; i < 4; i++)
    {
        scanf("%s", &s[i]);
    }

    int a = 0;
    for (int i = 0; i < 4; i++)
    {
        if (s[i] == '+')
        {
            a++;
        }
        else if (s[i] == '-')
        {
            a--;
        }
    }
    printf("%d\n", a);
    return 0;
}


Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
int main(void){
    long long int n,m,x;
    cin>>n>>m;
    if (n<m) {
        std::deque<long long int> deq;
        for (int i=0;i<m;i++) {
            cin>>x;
            deq.emplace_back(x);
        }
        sort(deq.begin(),deq.end());
        std::deque<long long int> diff;
        for (int j=0;j+1<m;j++) {
            diff.emplace_back(deq[j+1]-deq[j]);
        }
        sort(diff.begin(),diff.end());
        for (int k=0;k<n-1;k++) {
            diff.pop_back();
        }
        long long int sum=0;
        for (int l=0;l<diff.size();l++) {
            sum+=diff[l];
        }
        cout<<sum<<endl;
    } else {
        cout<<0<<endl;
    }
}

Measured memory_bytes: 1920
#include<stdio.h>

int main(){
	long long n,a,b,c,d,e;
	scanf("%lld%lld%lld%lld%lld%lld",&n,&a,&b,&c,&d,&e);
	int f=0;
	if(a<=b&&a<=c&&a<=d&&a<=e)f=1;
	if(b<=a&&b<=c&&b<=d&&b<=e)f=2;
	if(c<=b&&c<=a&&c<=d&&c<=e)f=3;
	if(d<=b&&d<=c&&d<=a&&d<=e)f=4;
	if(e<=b&&e<=c&&e<=d&&e<=a)f=5;
	long long ans=0;
	if(f==1){
		ans=(n-1+a)/a;
		ans+=4;
	}if(f==2){
		ans=(n-1+b)/b;
		ans+=4;
	}if(f==3){
		ans=(n-1+c)/c;
		ans+=4;
	}if(f==4){
		ans=(n-1+d)/d;
		ans+=4;
	}if(f==5){
		ans=(n-1+e)/e;
		ans+=4;
	}
	printf("%lld\n",ans);
	return 0;
}

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

min_sum = 100000

for A in range(1, N):
    Sum = 0
    sum_A = 0
    sum_B = 0
    B = N - A
    str_A = str(A)
    str_B = str(B)
    for i in str_A:
        sum_A += int(i)
    for j in str_B:
        sum_B += int(j)
    Sum = sum_A + sum_B
    if Sum < min_sum:
        min_sum = Sum
    
print("{}".format(min_sum))

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


int main() {

    string a, b;
    cin >> a >> b;
    string n = a + b;
    int num = atoi(n.c_str());
    for (ll i = 1; i < 1000000; ++i) {
        if (i * i == num) {
            cout << "Yes" << endl;
            return 0;
        }
    }
    cout << "No" << endl;
    return 0;
}

Measured memory_bytes: 256
#include<stdio.h>

int selectionSort(int A[], int N) {
int i, j, t, sw=0, minj;
for ( i = 0; i < N - 1; i++ ) {
minj = i;
for ( j = i; j < N; j++ ) {
if ( A[j] < A[minj] ) minj = j;
}
t = A[i]; A[i] = A[minj]; A[minj] = t;
if ( i != minj ) sw++;
}
return sw;
}

int main() {
int A[100], N, i, sw;

scanf("%d", &N);
for ( i = 0; i < N; i++ )
scanf ("%d", &A[i]);
sw = selectionSort(A, N);
 for ( i = 0; i < N; i++ ) {
if ( i > 0 )  printf(" ");
printf("%d", A[i]);

}
printf("\n");
printf("%d\n", sw);

return 0;
}


Measured memory_bytes: 2140
n,m = gets.chomp.split(" ").map(&:to_i);
a = gets.chomp.split(" ").map(&:to_i);

hw_ttl = 0
for i in 0..a.length-1 do
	hw_ttl += a[i]
end

if n-hw_ttl<0 then
	puts "-1"
	exit
else
	puts n-hw_ttl
end



Measured memory_bytes: 14656
Q = int(input())

def f(L):
    A, B = L
    N = 2 * (A * B) ** 0.5
    K = int(N)
    #print(K, N)
    K -= 1 if K == N else 0
    #print(K)
    res = K - 1
    if A + B == K:
        res -= 1
    else:
        #print(res)
        if (K - 1 >= A or K - 1 >= B) and A != B:
            res -= 1
    return res
    
for _ in range(Q):
    q = list(map(int, input().split()))
    print(f(q))


Measured memory_bytes: 3064
#include <iostream>
#include <string>
#include <vector>

using namespace std;

int main()
{
    string instr1,instr2;
    cin >> instr1 >> instr2;

    while(!cin.eof()) {
        vector<vector<int> > dp;

        dp.resize(instr1.size());

        int ans=0;

        for(int i=0; i<(int)instr1.size(); ++i) {
            dp[i].resize(instr2.size());

            if(instr1[i]==instr2[0]) {
                dp[i][0]=1;
                ans=1;
            } else {
                dp[i][0]=0;
            }
        }

        for(int i=0; i<(int)instr2.size(); ++i) {
            if(instr1[0]==instr2[i]) {
                dp[0][i]=1;
                ans=1;
            } else {
                dp[0][i]=0;
            }
        }


        for(int i=1; i<(int)instr1.size(); ++i) {
            for(int j=1; j<(int)instr2.size(); ++j) {
                if(instr1[i]==instr2[j]) {
                    dp[i][j]=dp[i-1][j-1]+1;
                    ans=max(dp[i][j],ans);
                }
            }
        }

        cout << ans << endl;

        cin >> instr1 >> instr2;
    }
    return 0;
}

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

typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef stack<int> SI;
typedef queue<int> QI;
typedef pair<int,int> PII;
typedef long long LL;

#define d(x)  cout<<#x<<" = "<<(x)<<endl;
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define EMP empty()
#define SZ(a) int((a).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define REACH(i,c) for(typeof((c).rbegin()) i=(c).rbegin(); i!=(c).rend(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c,n) sort(c,c+n)
#define VSORT(c) sort((c).begin(),(c).end())
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define DFOR(i,b,a) for(int i=(b)-1;i>=(a);--i)
#define DREP(i,n) DFOR(i,n,0)
#define INF 1000000000

const double EPS = 1e-10;
const double PI  = acos(-1.0);
////////////////////////////////////////////////
class DisjointSet
{
	public:
		vector<int> rank,p;
		DisjointSet(){}
		DisjointSet(int size)
		{
			rank.resize(size,0);
			p.resize(size,0);
			for(int i=0;i<size;i++)makeSet(i);
		}
		
		void makeSet(int x)
		{
			p[x]=x;
			rank[x]=0;
		}
		
		bool same(int x,int y)
		{
			return findSet(x)==findSet(y);
		}
		
		void unite(int x,int y)
		{
			link(findSet(x),findSet(y));
		}
		
		void link(int x,int y)
		{
			if(rank[x]>rank[y])
			{
				p[y]=x;
			}
			else
			{
				p[x]=y;
				if(rank[x]==rank[y])
				{
					rank[y]++;
				}
			}
		}
		
		int findSet(int x)
		{
			if(x!=p[x])
			{
				p[x]=findSet(p[x]);
			}
			return p[x];
		}
};

int main()
{
	int n,a,b,q;
	int t;
	cin>>n>>q;
	DisjointSet ds=DisjointSet(n);
	
	for(int i=0;i<q;i++)
	{
		cin>>t>>a>>b;
		if(t==0)ds.unite(a,b);
		else if(t==1)
		{
			if(ds.same(a,b))cout<<1<<endl;
			else cout<<0<<endl;
		}
	}
	return 0;
}

Measured memory_bytes: 3192
package main

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

func sliceAtoi(sa []string) ([]int, error) {
	si := make([]int, 0, len(sa))
	for _, a := range sa {
		i, err := strconv.Atoi(a)
		if err != nil {
			return si, err
		}
		si = append(si, i)
	}
	return si, nil
}

func getDigits(ary []int) (digits int) {
	sum := 0
	for _, v := range ary {
		sum += v
	}

	for sum != 0 {
		sum /= 10
		digits++
	}
	return
}

func getsTwoNumAsArray() (nums [][]int) {
	scanner := bufio.NewScanner(os.Stdin)

	for scanner.Scan() {
		str := scanner.Text()
		if str == "" {
			break
		}

		ary, _ := sliceAtoi(strings.Split(str, " "))
		nums = append(nums, ary)
	}

	return
}

func main() {
	ary := getsTwoNumAsArray()

	for _, v := range ary {
		fmt.Println(getDigits(v))
	}
}



Measured memory_bytes: 1084
#include <vector>
#include <iostream>
#include <algorithm>
using namespace std;
int main() {
	cin.tie(0);
	ios_base::sync_with_stdio(false);
	int N, T;
	cin >> N >> T;
	int mx = (1 << 30), diff = 0, cnt = 0;
	for (int i = 0; i < N; ++i) {
		int a;
		cin >> a;
		mx = min(mx, a);
		if (a - mx > diff) {
			diff = a - mx;
			cnt = 0;
		}
		if (a - mx == diff) {
			++cnt;
		}
	}
	cout << cnt << endl;
	return 0;
}

Measured memory_bytes: 256
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
    ($($r:tt)*) => {
        let mut s = {
            use std::io::Read;
            let mut s = String::new();
            std::io::stdin().read_to_string(&mut s).unwrap();
            s
        };
        let mut iter = s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
}

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

macro_rules! read_value {
    ($iter:expr, ( $($t:tt),* )) => {
        ( $(read_value!($iter, $t)),* )
    };
    ($iter:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($iter, $t)).collect::<Vec<_>>()
    };
    ($iter:expr, chars) => {
        read_value!($iter, String).chars().collect::<Vec<char>>()
    };
    ($iter:expr, usize1) => {
        read_value!($iter, usize) - 1
    };
    ($iter:expr, $t:ty) => {
        $iter.next().unwrap().parse::<$t>().expect("Parse error")
    };
}

fn main() {
    input! {
        s: chars
    }
    let mut ok: bool = true;

    for i in 0..s.len() {
        let t: char = s[i];
        if i % 2 == 0 {
            //　奇数
            if t == 'L' {
                ok = false;
            }
        } else {
            // 偶数
            if t == 'R' {
                ok = false;
            }
        }
    }

    if ok {
        println!("Yes");
    }else {
        println!("No");
    }
}

Measured memory_bytes: 4352
coin_500 = int(input())
coin_100 = int(input())
coin_50 = int(input())
target = int(input())
count = 0

for i in range(coin_500 + 1):
    for j in range(coin_100 + 1):
        for k in range(coin_50 + 1):
            if i * 500 + j * 100 + k * 50 ==  target:
                count += 1
                # print(str(i) + str(j) + str(k))

print(count)

Measured memory_bytes: 3060
#include<iostream>
#include<stdio.h>
#include<algorithm>
using namespace std;

int main(){
unsigned  l,p,*s,*g,t[2],i[3]={0,0,0};
bool f = false;

scanf("%d%d",&l,&p);
s = new unsigned[l];
g = new unsigned[p];

for(int j=0;j<p;j++){
 scanf("%d%d",t,t+1);
 if(t[0]==1){s[t[1]]++;
 if(s[t[1]]==2){cout << "POSSIBLE";return 0;}}
 else if(t[1]==l){ s[t[0]]++;
 if(s[t[0]]==2){cout << "POSSIBLE";return 0;}}
}
cout << "IM";
cout << "POSSIBLE";
return 0;
}

Measured memory_bytes: 1024
#include<iostream>
#include<algorithm>
#include<vector>
#include<queue>
#include<string>
using namespace std;
typedef long long Int;
int main(){
  int d;
  cin>>d;
  if(d==25) cout<<"Christmas"<<endl;
  if(d==24) cout<<"Christmas Eve"<<endl;
  if(d==23) cout<<"Christmas Eve Eve"<<endl;
  if(d==22) cout<<"Christmas Eve Eve Eve"<<endl;
}


Measured memory_bytes: 256
n,m=map(int,input().split())
x=list(map(int,input().split()))
if n>=m:
    print(0)
    exit()

x=sorted(x)
l=[0]*(m-1)
for i in range(m-1):
    l[i]=x[i+1]-x[i]
    
l=sorted(l)[::-1]
dist=x[m-1]-x[0]-sum(l[:n-1])
print(dist)

Measured memory_bytes: 20628
#include<iostream>
#include<iomanip>
#include<algorithm>
#include<bitset>
#include<cstdio>
#include<cmath>
#include<deque>
#include<map>
#include<numeric>
#include<queue>
#include<set>
#include<sstream>
#include<stack>
#include<string>
#include<tuple>
#include<utility>
#include<vector>
using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<long long> vll;
typedef vector<vector<long long>> vvll;
typedef vector<vector<int>> vvi;

#define rep(i, a, n)  for(int i=a; i<n; i++)
#define REP(i, n)  for(int i=0; i<(int)(n); i++)
#define REPS(i, n)  for(int i=1; i<=(int)(n); i++)
#define PER(i, n) for(int i=(int)(n)-1; i>= 0; i--)
#define PERS(i, n)  for(int i=(int)(n); i>0; i--)
#define FOR(i, c) for(__typeof((c).begin()) i = (c).begin(); i!=(c).end(); i++)
#define RFOR(i, c)  for(__typeof((c).rbegin()) i=(c).rbegin(); i!=(c).end(); i++)
#define ALL(container)  (container).begin(), (container).end()
#define RALL(container) (container).rbegin(), (container).rend()
#define SZ(container) (container).size()
#define FILL0(n)  setfill('0') << right << setw(n)
#define mp(a, b)  make_pair(a, b)
#define toLower(c)  c+0x20
#define toUpper(c)  c-0x20
#define pb  push_back
#define eb  emplace_back

const int INF = 1e9;
const long long LLINF = 1e18;
const int MOD = 1000000007;
const double Pi = 3.14159265358979323146;

int main(){
  int h, w, n;  cin >> h >> w >> n;
  vector<vector<int>> mas(h, vector<int>(w, 0));
  int my=0, mx=0;
  REP(i, n){
    int a;  cin >> a;
    while(a>0){
      mas[my][mx]=i+1;
      mx++;
      if(mx==w){
        mx=0;
        my++;
      }
      a--;
    }
  }
  for(int i=1; i<h; i+=2){
    reverse(ALL(mas[i]));
  }

  REP(y, h) {
    REP(x, w){
      cout << mas[y][x] << " ";
    }
    cout << endl;
  }
  return 0;
}


Measured memory_bytes: 384
#include<iostream>
using namespace std;
int main(){
  long long n,d,x,y;
  int count=0;
  cin >> n >> d;
  for(int i=0; i<n; i++){
    cin >> x >> y;
    if(x*x+y*y<=d*d)count++;
  }
  cout << count << endl;
}

Measured memory_bytes: 3504
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0, i##_len = (n); i < i##_len; ++i)
#define rep2(i, x, n) for(int i = x, i##_len = (n); i < i##_len; ++i)
#define all(n) begin(n), end(n)
using ll = long long;
using P = pair<int, int>;
using vi = vector<int>;
using vl = vector<ll>;
using vs = vector<string>;
using vc = vector<char>;
using vb = vector<bool>;
using vd = vector<double>;
vi dir = {-1, 0, 1, 0, -1, -1, 1, 1, -1};

vector<vi> g;
vi a, ans, lis;
vb seen;

void dfs(int v) {
  seen[v] = true;
  auto it = lower_bound(all(lis), a[v]);
  int tmp = *it;
  *it = a[v];
  ans[v] = lower_bound(all(lis), 1e9 + 1) - lis.begin();
  for(auto nv : g[v]) {
    if(seen[nv]) continue;
    dfs(nv);
  }
  *it = tmp;
}

int main() {
  int n;
  cin >> n;
  a = vi(n);
  rep(i, n) cin >> a[i];
  g = vector<vi>(n);
  seen = vb(n, false);
  ans = vi(n);
  rep(i, n - 1) {
    int u, v;
    cin >> u >> v;
    u--;
    v--;
    g[u].push_back(v);
    g[v].push_back(u);
  }
  lis = vi(n, 1e9 + 1);
  dfs(0);
  rep(i, n) cout << ans[i] << ' ';
  cout << endl;
}

Measured memory_bytes: 25096
#include <string>
#include <iostream>
#include <vector>
#include <algorithm>
#include <unordered_set>
#include <utility>
#include <cmath>
#include <stdlib.h> 
#include <stdio.h>
#include <iterator>
#include <chrono>
#include <iomanip>
#include <set>
#include <map>
#include <list>
#include <iterator>
#include <deque>
#include <stack>
#include <queue>
#include <fstream>
#include <limits>
#include <unordered_map>
#include <bitset>
#include <numeric>
#include <sstream>
#include <random>
#include <cassert>

using namespace std;
#define ffor(n) for(int i = 0; i < n; i++)
#define fffor(n) for(int j = 0; j < n; j++)
int INF = 1e9 + 7;
bool pairwise_coprime = true;

void verify_factors(int n, vector <int>& is_factor) {
	if (pairwise_coprime == false) return;
	vector <int> factors;
	for (int i = 1; i * i <= n; i++) {
		if (n % i != 0) continue;
		if (i * i == n) {
			factors.push_back(i);
		}
		else {
			if (i == n) {
				factors.push_back(i);
			}
			else {
				factors.push_back(i);
				factors.push_back(n / i);
			}
		}
	}

	for (auto e : factors) {
		if (e == 1) continue;
		if (is_factor[e]) {
			pairwise_coprime = false;
			break;
		}
		is_factor[e] = true;
	}
}

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

	int n;
	cin >> n;
	vector <int> v(n), is_factor(1e6 + 5, false);
	ffor(n) cin >> v[i];
	
	for (auto e : v) verify_factors(e, is_factor);

	if (pairwise_coprime) {
		cout << "pairwise coprime";
	}
	else {
		int current = v[0];
		for (int i = 1; i < v.size(); i++) {
			current = gcd(current, v[i]);
		}
		if (current == 1) {
			cout << "setwise coprime";
		}
		else {
			cout << "not coprime";
		}
	}
}
	




/*
C:\Users\User\Desktop\comp_programming\final_straw_after_this_im_switching_to_vs_code\final_straw_after_this_im_switching_to_vs_code.cpp
*/

Measured memory_bytes: 11092
<?php
while($input = fgets(STDIN)){
    if(trim($input)){
        $tmp_array = explode(' ', trim($input));
        $words[] = $tmp_array[0];
        $words[] = $tmp_array[1];
      	$words[] = $tmp_array[2];
    }
}

for ($i = 0; $i < count($words) - 1; $i++) {
    $firstString = $words[$i];
    $secondString = $words[$i + 1];
    if (substr($firstString, strlen($firstString) - 1, 1) !== substr($secondString, 0, 1)) {
        echo 'NO';
        return;
    }
}
echo 'YES';

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

const int M=100010;
bool stu[410][410];
int n,m,a[M],b[M];
bool cant[410];

int main() {
	scanf("%d%d",&n,&m);
	for(int i=1; i<=m; i++)
		scanf("%d%d",a+i,b+i);
	for(int i=1; i<=n; i++) {
		stu[i][i]=1;
		for(int j=m; j>=1; j--) {
			bool x=stu[i][a[j]],y=stu[i][b[j]];
			if(x&&y) {
				cant[i]=1;
				break;
			} else if(x) stu[i][b[j]]=1;
			else if(y) stu[i][a[j]]=1;
		}
	}
	int ans=0;
	for(int i=1; i<n; i++) {
		if(cant[i]) continue;
		for(int j=i+1; j<=n; j++) {
			if(cant[j]) continue;
			bool flag=1;
			for(int k=1; k<=n; k++)
				if(stu[i][k]&&stu[j][k]) flag=0;
			ans+=flag;
		}
	}
	printf("%d\n",ans);
	return 0;
}

Measured memory_bytes: 1152
#include <map>
#include <set>
#include <list>
#include <cmath>
#include <deque>
#include <stack>
#include <queue>
#include <list>
#include <array>
#include <bitset>
#include <cstdio>
#include <string>
#include <vector>
#include <random>
#include <chrono>
#include <utility>
#include <numeric>
#include <cstdlib>
#include <cstring>
#include <climits>
#include <sstream>
#include <assert.h>
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <functional>
#include <unordered_map>

using namespace std;
struct _ { ios_base::Init i; _() { ios_base::sync_with_stdio(false), cin.tie(NULL), cout.tie(NULL); } } _;

const long long maxa = 1e6 + 1;
vector<long long> spf(maxa + 1, 0);
vector<bool> can(maxa + 1, true);

int main() {

	iota(spf.begin(), spf.end(), 0);

	for (long long i = 2; i * i <= maxa; i++) {
		if (spf[i] == i) {
			for (long long j = i * i; j <= maxa; j += i) if (spf[j] == j) spf[j] = i;
		}
	}

	long long n; cin >> n;
	long long gd = 0;
	vector<long long> a(n); for (long long i = 0; i <= n - 1; i++) cin >> a[i], gd = gcd(gd, a[i]);

	bool is_setwise = (gd == 1);
	bool is_pairwise = true;


	for (long long i = 0; i <= n - 1; i++) {
		long long x = a[i];
		set<int> s;

		while (x != 1) {
			s.insert(spf[x]);
			x /= spf[x];
		}

		for (auto pfac : s) {
			if (can[pfac] == false) {
				is_pairwise = false;
				break;
			}
			can[pfac] = false;
		}


		if (!is_pairwise) break;
	}

	if (is_pairwise) cout << "pairwise coprime";
	else if (is_setwise) cout << "setwise coprime";
	else cout << "not coprime";


	return 0;
}

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

#define pb push_back
#define mp make_pair
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef complex<double> point;
#define xx real()
#define yy imag()

#define REP(i, a, b) for(int i = (a); i < (int)(b); i++)
#define REPN(i, a, b) for(int i = (a); i <= (int)(b); i++)
#define FA(it, x) for(__typeof((x).begin()) it = (x).begin(); it != (x).end(); it++)
#define SZ(x) (int)(x).size()
#define BE(x) (x).begin(), (x).end()
#define SORT(x) sort(BE(x))
#define _1 first
#define _2 second

#define x1 gray_cat_x1
#define y1 gray_cat_y1

template<class T> T gcd(T a, T b) { return b ? gcd(b, a % b) : a; }

#define file "I1"

const double EPS = 1e-9;
const double PI = acos(-1.);
const int INF = 1e9;
const ll MOD = 1e9 + 7;

const int MAXN = 1e5 + 5;

vi g[MAXN];

int dp_min[MAXN][2], dp_max[MAXN][2];

int v[MAXN];

int ans[MAXN];

void unset_dp(int s, int ind){
	dp_min[s][ind] = INF;
	dp_max[s][ind] = 0;
}

bool dfs1(int s, int par){
	if (v[s] != -1){
		dp_min[s][v[s] & 1] = dp_max[s][v[s] & 1] = v[s];
		unset_dp(s, (v[s] & 1) ^ 1);
	}
	REP(i, 0, SZ(g[s])){
		int to = g[s][i];
		if (to != par){
			if (!dfs1(to, s)){
				return false;
			}
			REP(j, 0, 2){
				if (dp_min[to][j] > dp_max[to][j]){
					unset_dp(s, j ^ 1);
				}
				dp_min[s][j ^ 1] = max(dp_min[s][j ^ 1], dp_min[to][j] - 1);
				dp_max[s][j ^ 1] = min(dp_max[s][j ^ 1], dp_max[to][j] + 1);
			}
		}
	}
	//printf("%d %d %d %d %d\n", s, dp_min[s][0], dp_min[s][1], dp_max[s][0], dp_max[s][1]);
	return dp_min[s][0] <= dp_max[s][0] || dp_min[s][1] <= dp_max[s][1];
	
}

void dfs2(int s, int par){
	int ind, val;
	if (dp_min[s][0] <= dp_max[s][0]){
		ind = 0;
	} else {
		ind = 1;
	}
	ans[s] = dp_min[s][ind];
	REP(i, 0, SZ(g[s])){
		int to = g[s][i];
		if (to != par){
			unset_dp(to, ind);
			dp_min[to][ind ^ 1] = max(dp_min[to][ind ^ 1], ans[s] - 1);
			dp_max[to][ind ^ 1] = min(dp_max[to][ind ^ 1], ans[s] + 1);
			dfs2(to, s);
		}
	}
}

void solve(){
	int n;
	scanf("%d", &n);
	REPN(i, 1, n){
		v[i] = -1;
		dp_min[i][0] = 0;
		dp_min[i][1] = 1;
		dp_max[i][0] = 1e6;
		dp_max[i][1] = 1e6 - 1;
	}
	REP(i, 1, n){
		int a, b;
		scanf("%d%d", &a, &b);
		g[a].pb(b);
		g[b].pb(a);
	}
	int k;
	scanf("%d", &k);
	REP(i, 0, k){
		int a, b;
		scanf("%d%d", &a, &b);
		v[a] = b;
	}
	if (!dfs1(1, 0)){
		printf("No\n");
		return;
	}
	printf("Yes\n");
	dfs2(1, 0);
	REPN(i, 1, n){
		printf("%d\n", ans[i]);
	}
}   

int main(){

    //freopen(file".in", "r", stdin); freopen(file".out", "w", stdout);
    int t = 1;
    //cin >> t;
    while(t--){
        solve();    
    }
}


Measured memory_bytes: 16512
#include<cstdio>
#include<queue>
#include<utility>
#include<cstring>
#include<stack>
#include<algorithm>
#include<cmath>
#include<iostream>
#include<map>
#define MAX_N 100001
#define INF_INT 2147483647
#define INF_LL 9223372036854775807
#define REP(i,n) for(int i=0;i<(int)(n);i++)
using namespace std;
typedef long long int ll;
typedef pair<ll,ll> P;
void init(int n);
int find(int n);
void unite(int x,int y);
bool same(int x, int y);
ll bpow(ll,ll,ll);
typedef vector<int> vec;
typedef vector<vec> mat;
mat mul(mat &A,mat &B);
mat pow(mat A,ll n);
int dx[4] = {1,0,0,-1};
int dy[4] = {0,1,-1,0};


bool cmp_P(const P &a,const P &b){
  return a.second < b.second;
}
int main()
{
  int N,H,W,cnt=0;
  bool gyo[101],retu[101];
  REP(i,101){
    gyo[i] = true;
    retu[i] = true;
  }
  char masu[101][101];
  cin >> H >> W;
  REP(i,H)cin >> masu[i];
  REP(i,H){
    cnt = 0;
    REP(j,W){
      if(masu[i][j] == '.')
        cnt++;
    }
    if(cnt == W){
      gyo[i] = false;
    }
  }
  REP(i,W){
    cnt = 0;
    REP(j,H){
      if(masu[j][i] == '.')
        cnt++;
    }
    if(cnt == H){
      retu[i] = false;
    }
  }
  REP(i,H){REP(j,W){
    if(gyo[i] && retu[j]){
      cout << masu[i][j];
    }else
      continue;
    }
    if(gyo[i])
      cout << endl;
  }
  
  return 0;
}

int par[MAX_N];
int ranks[MAX_N];

//n要素で初期化
void init(int n){
  REP(i,n){
    par[i] = i;
    ranks[i] = 0;
  }

}

//木の根を求める
int find(int x){
  if(par[x] == x){
    return x;
  }else{
    return par[x] = find(par[x]);
  }
}

void unite(int x,int y){
  x = find(x);
  y = find(y);
  if(x == y) return ;
  if(ranks[x] < ranks[y]){
    par[x] = y;
  }else{
    par[y] = x;
    if(ranks[x] == ranks[y]) ranks[x]++;
  }
}

bool same(int x, int y){
  return find(x) == find(y);
}

ll bpow(ll a, ll n,ll mod){
  int i = 0;
  ll res=1;
  while(n){
    if(n & 1)
      res = (res*a) % mod;
    a = (a*a) % mod;
    n >>= 1;
  }
  return res;
}
const int MOD = 1000000007;
mat mul(mat &A, mat &B){
  mat C(A.size(),vec(B[0].size()));
    REP(i,A.size())REP(k,B.size())REP(j,B[0].size()){
    C[i][j] = (C[i][j] + A[i][k] * B[k][j]) % MOD;
  }
  return C;
}

mat pow(mat A,ll n)
{
  mat B(A.size(),vec(A.size()));
  REP(i,A.size()){
    B[i][i] = 1;
  }
  while(n > 0){
    if ( n & 1) B = mul(B,A);
    A = mul(A,A);
    n >>= 1;
  }
  return B;
}


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

int main(void){
  int N, i;
  cin>>N;

  int A[N];
  for (i=0; i<N; i++) cin>>A[i];
  int maxA=A[0], minA=A[0];
  for (i=1; i<N; i++){
    if (maxA<A[i])  maxA=A[i];
    if (minA>A[i])  minA=A[i];
  }


  cout<<maxA-minA<<endl;
}


Measured memory_bytes: 256
#include<iostream>

using namespace std;

int order(int n)
{
  int i = 0;
  while(n != 0)
  {
    n /= 10;
    i++;
  }
  return i;
}

int main()
{
  int n;
  int j=0;
  cin >> n;

  for(int i=1;i<=n;i++)
  {
    if(order(i) % 2 == 1)
    {
      j++;
    }
  }
  cout << j << endl;

  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cmath>
#include <algorithm>
#include <string>
#include <vector>
#include <list>
#include <map>

using namespace std;

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)



bool isPrime(int a){	//must be a>1
	int maxI = floor(sqrt(a));
	FOR(i,2,maxI+1){
		if(a%i==0)return false;
	}
	return true;
}

int main(){
	while(true){
		MUNENIKAKETE:
		int dishL,maxYosan;
		cin >> dishL >> maxYosan;			if(!dishL&&!maxYosan) return 0;

		vector<int> dishS(dishL);
		REP(dishI,dishL){
			int dish;
			cin >> dish;
			dishS[dishI] = dish;
		}

		vector<bool> dekiru(maxYosan+1,false);
		dekiru[0] = true;
		REP(yosan,maxYosan+1){
			REP(dishI,dishL){
				int dish = dishS[dishI];
				if(yosan<dish) continue;
				dekiru[yosan] = dekiru[yosan] || dekiru[yosan - dish];
			}
		}

		for(int yosan = maxYosan; yosan>1 ; --yosan){
			if(dekiru[yosan]&&isPrime(yosan)){
				cout << yosan << endl;
				goto MUNENIKAKETE;
			}
		}
		cout << "NA" << endl;

	}
}

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

using namespace std;

#define int 		long long
#define endl		"\n"
#define mod			1000000007
#define inf			1e12
#define IOS			ios::sync_with_stdio(0), cin.tie(0), cout.tie(0)

int32_t main() {

	IOS;

	int x;
	cin >> x;

	if (x < 600)
		cout << "8\n";
	else if (x < 800)
		cout << "7\n";
	else if (x < 1000)
		cout << "6\n";
	else if (x < 1200)
		cout << "5\n";
	else if (x < 1400)
		cout << "4\n";
	else if (x < 1600)
		cout << "3\n";
	else if (x < 1800)
		cout << "2\n";
	else
		cout << "1\n";

	return 0;
}

Measured memory_bytes: 3664
#include <iostream>
#include <fstream>
#include <cstdio>
#include <cmath>
#include <vector>
#include <string>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <deque>
#include <bitset>
#include <algorithm>
#include <complex>
#include <array>
#include <functional>
using namespace std;
 
#define REP(i,n) for(int i=0; i<n; ++i)
#define FOR(i,a,b) for(int i=a; i<=b; ++i)
#define FORR(i,a,b) for (int i=a; i>=b; --i)
#define ALL(c) (c).begin(), (c).end()
 
typedef long long ll;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef vector<double> VD;
typedef vector<VI> VVI;
typedef vector<VL> VVL;
typedef vector<VD> VVD;
typedef pair<int,int> P;
typedef pair<ll,ll> PL;

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

int in() { int x; scanf("%d", &x); return x; }
ll lin() { ll x; scanf("%lld", &x); return x; }

int main(void){
    string s;
    cin >> s;
    cout << string(s.length(), 'x') << endl;

    return 0;
}


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

int main()
{
	int h1, m1, h2, m2, k;
	cin >> h1 >> m1 >> h2 >> m2 >> k;
	
	int diff_h = h2 - h1;
	int diff_m = m2 - m1;;
	
	if (diff_m < 0)
	{
		diff_h -= 1;
		diff_m += 60;
	}
	
	int n = diff_h * 60 + diff_m;
	
	int ans = n;
	int cnt = 0;
	while(1)
	{
		ans -= k;
		cnt++;
		
		if (ans < n)
		{
			break;
		}
	}
	
	cout << (n - k) * cnt << endl;
	
	return 0;
}


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

int main() {
  int n;
  vector<int> p;

  cin >> n;
  for (int i = 0; i < n; ++i) {
    int a;
    cin >> a;
    p.push_back(a);
  }

  for (int i = n; i >= 0; --i) {
    int cnt = 0;
    for (int j = 0; j < n; ++j) {
      if (p[j] >= i) cnt++;
    }

    if (cnt >= i) {
      cout << i << endl;
      break;
    }
  }
}

Measured memory_bytes: 3160
N=int(input())
xy=list(list(map(int,input().split())) for _ in range(N))
L=[]
c=1
for i in range(N):
    for j in range(N):
        if i!=j:
            L.append(([xy[j][0]-xy[i][0],xy[j][1]-xy[i][1]]))
for l in L:
    c=max(c,L.count(l))
print(N-c if N!=1 else 1)

Measured memory_bytes: 41452
n=int(input())
a=list(map(int,input().split()))
cnt=0
error=0
while(1):
    for i in range(len(a)):
        if a[i]%2:
            error=1
            break
        else:
           a[i]/=2
    if error==1:
        break
        
    cnt+=1

print(cnt)


Measured memory_bytes: 3060
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define sz(x) int(x.size())
#define show(x) {for(auto i: x){cout << i << " ";} cout << endl;}
using namespace std;
using ll = long long;
using P = pair<int, int>;

int dp[3003];

int main() {
  // greedy、逆順、O(NT)は通る
  int N, T;
  cin >> N >> T;
  vector<P> AB(N);
  rep(i, N) {
    cin >> AB[i].first >> AB[i].second;
  }
  sort(AB.begin(), AB.end(), [](P x, P y) {
    return x.first < y.first;
  });
  rep(i, N) {
    int A, B;
    A = AB[i].first;
    B = AB[i].second;    
    for (int j = T-1; j >= 0; j--) {
      int nj = j + A;
      if (nj > T) nj = T;
      dp[nj] = max(dp[nj], dp[j] + B);
    }
  }
  int ans = 0;
  rep(i, T+1) {
    ans = max(ans, dp[i]);
  }
  cout << ans << '\n';
  return 0;
}

Measured memory_bytes: 3616
#include"bits/stdc++.h"
using namespace std;
#define REP(k,m,n) for(int (k)=(m);(k)<(n);(k)++)
#define rep(i,n) REP((i),0,(n))
using ll = long long;

int main()
{
    ll N, res = 1ll << 60;
    cin >> N;

    REP(i, 1, sqrt(N) + 1) {
        if (N%i == 0) {
            ll a = N / i;
            ll b = N / a;
            assert(a*b == N);
            res = min(res, a + b - 2);
        }
    }cout << res << endl;
    return 0;
}


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

typedef long long ll;
typedef pair<int, int> P;

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

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

int main(){
    int n, t; cin>>n>>t;
    int ans=MOD;
    for(int i=0; i<n; i++){
        int a, b; cin>>a>>b;
        if(b <= t) ans=min(ans, a);
    }
    if(ans == MOD) cout << "TLE" << endl;
    else cout << ans << endl;
}

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

using namespace std;

typedef long long ll;

ll n, k, d = 0, a, p[105], di;

int main()
{
  	ios_base::sync_with_stdio(false);
  	cin.tie(NULL); cout.tie(NULL);
  	memset(p, 0, sizeof(p));
	cin >> n >> k;
  	for (ll i = 1; i <= k; i++)
    {
    	cin >> di;
      	for (ll j = 1; j <= di; j++)
        {
        	cin >> a;
          	p[a] ++;
        }
    }
  	for (ll i = 1; i <= n; i++)
      	if (p[i] == 0) d++;
  	cout << d;
}

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

vector<int> pos[30];

int main() {
    string s, t;
    cin >> s >> t;
    map<char, int> sn, tn;
    for (char c : s) sn[c]++;
    bool ok = true;
    for (char c : t) {
        if (sn[c] == 0) ok = false;
    }
    if (!ok) {
        cout << -1 << endl;
        return 0;
    }

    rep(i, s.size()) {
        int x = s[i] - 'a';
        pos[x].push_back(i);
    }

    ll ans = pos[t[0]-'a'][0];
    int cur = pos[t[0]-'a'][0];
    for (int i=1; i<t.size(); ++i) {
        int x = t[i] - 'a';
        auto itr = upper_bound(pos[x].begin(), pos[x].end(), cur);
        if (itr != pos[x].end()) {
            ans += (*itr - cur);
            cur = *itr;
        }
        else {
            ans += (s.size() - cur);
            ans += pos[x][0];
            cur = pos[x][0];
        }
    }

    cout << ans+1 << endl;

}


Measured memory_bytes: 1216
#include <bits/stdc++.h>
#define rep(i , n) for(int i = 0; i < (int)(n); i++)
using namespace std;
using ll = long long;
int main() {
    ll A , B , C , D;
    cin >> A >> B >> C >> D;
    ll X = B - (B / C + B / D - B / lcm(C , D));
    ll Y = A - 1 - ((A - 1) / C + (A - 1) / D - (A - 1) / lcm(C , D));
    cout << X - Y << endl;
}

Measured memory_bytes: 3608
import math

a, b, h, m=map(int, input().split())

a_rad=30*h+m/2
b_rad=6*m

if a_rad==b_rad:
    print(abs(a-b))
elif abs(a_rad-b_rad)==180:
    print(a+b)
else:
    if abs(a_rad-b_rad)<180:
        rad=abs(a_rad-b_rad)
    else:
        rad=360-(abs(a_rad-b_rad))
    c=a**2+b**2-2*a*b*math.cos(math.radians(rad))
    print(math.sqrt(c))



Measured memory_bytes: 9416
#include <iostream>
#include <cmath>
#include <vector>
#include <set>
#include <map>
#include <algorithm>
#include <climits>

#define el '\n'
typedef long long ll;
using namespace std;

void sol(){
	int n;
	cin >>n;
	vector<int> h(n);
	for (int &i: h) cin >>i;
	vector<int> dp(n, INT_MAX);
	dp[0] = 0;
	for (int i = 1; i < n; i++){
		dp[i] = min(dp[i - 1] + abs(h[i] - h[i - 1]), dp[i]);
		if (i > 1)
		dp[i] = min(dp[i - 2] + abs(h[i] - h[i - 2]), dp[i]);
	}
	cout << dp[n - 1]<<el;
}

int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	int t;
	t= 1;
	while(t--){
	//	cout << t<<el;
		sol();
	}
}

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

using namespace std;

#define pb push_back
#define mp make_pair
#define fst first
#define snd second
#define sz(X) (int)(X).size()
#define forn(i, n) for (int i = 0; i < int(n); i++)
#define fornr(i, n) for (int i = int(n) - 1; i >= 0; i--)
#define forab(i, a, b) for(int i = int(a); i < int(b); i++)
#define all(X) X.begin(), X.end()

typedef long long ll;
typedef pair<int, int> pii;
typedef double dbl;
typedef long double ld;
typedef vector<int> vi;
typedef vector<pair<ll, ll>> vpll;

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    int x;
    cin >> x;
    bool f = false;
    int t = 7;
    forn(i, 1e7+1) {
        if (t % x == 0) {
            cout << i + 1 << "\n";
            f = true;
            break;
        }
        t = (t * 10 + 7) % x;
    }
    if (!f) cout << "-1\n";
    return 0;
}

Measured memory_bytes: 3644
import sys
input = lambda: sys.stdin.readline().rstrip()

N, M = map(int, input().split())

switch_list = []
for i in range(M):
    k = list(map(int, input().split()))
    k = k[1:]
    switch_list.append(k)

p = list(map(int, input().split()))

ans = 0
for i in range(2 ** N):
    all_flg = 1
    on_list = []
    for j in range(M):
        flg = False
        for s in switch_list[j]:
            if (i >> (s-1)&1):
                flg = not flg
        if p[j] != flg:
            all_flg = 0
            break
    if all_flg:
        ans += 1    
print(ans)

Measured memory_bytes: 40944
open Batteries
let n, m = Scanf.sscanf (read_line()) "%d %d" (fun n m -> n,m)
let h = read_line () |> String.split_on_char ' ' |> List.map int_of_string |> Array.of_list
let dp = Array.init n @@ fun a -> 0
let rec loop i =
  if i >= m then () else (
    Scanf.sscanf (read_line()) "%d %d" (fun a b -> 
    if h.(a-1) > h.(b-1) then dp.(b-1) <- 1 else 
    if h.(a-1) < h.(b-1) then dp.(a-1) <- 1 else
    (dp.(a-1) <- 1; dp.(b-1) <- 1) 
    );
    loop (i+1)
  )
let _ = loop 0
let _ = Printf.printf "%d\n" @@ List.fold_left (fun a b -> if b != 0 then a else 1 + a) 0 (Array.to_list dp)


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

// 定義
typedef long long         ll;
typedef pair<ll, ll>      P;
#define ALL(x)            (x).begin(),(x).end()
#define REP(i, n)         for(ll i = 0 ; i < (ll)n ; ++i)
#define REPN(i, m, n)     for(ll i = m ; i < (ll)n ; ++i)
#define REVREP(i, n)      for(ll i = n - 1; i >= 0 ; i--)
#define VL                vector<ll>
#define VVL               vector<vector<ll>>
#define VVVL              vector<vector<vector<ll>>>
#define VC                vector<char>
#define VVC               vector<vector<char>>
#define INF               2e9
#define INF_LL            1LL<<60
#define MOD               1000000007

ll Ceil(ll val, ll div)   { return (val + div - 1) / div; }
ll CeilN(ll val, ll div)  { return Ceil(val, div) * div; }
ll FloorN(ll x, ll n)     { return (x - x % n); }
bool IsOdd(ll x)          { return ((x & 1) == 1); }
bool IsEven(ll x)         { return ((x & 1) == 0); }
ll _accumulate(const VL &v) { return accumulate(ALL(v), (ll)0); }
template<class T> bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

// 処理
void Solve()
{
	ll A, B;
	cin >> A >> B;
	
	ll ans = A * B;
	cout << ans << endl;
}

// メイン
int main()
{
	cin.tie(nullptr);
	ios_base::sync_with_stdio(false);
	cout << fixed << setprecision(15);
	Solve();
	return 0;
}


Measured memory_bytes: 3652
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <cassert>
#include <map>
using namespace std;

class state{
public:
  int x,y,l;
  state(int y=0, int x=0, int l=0):y(y),x(x),l(l){}
  bool operator < (const state &s) const {return l > s.l;}
};

const int INF = (1<<29);
typedef pair<int,int> P;
int r,h,w,rx,ry,a[500][500];
int dy[] = {0,1,0,-1};
int dx[] = {1,0,-1,0};
bool f[500][500];
vector<int> numr[2],numl[2];
map<int,int> m[2];

bool check(int y, int x){
  if(y < 0 || y >= h) return false;
  if(x < 0 || x >= w) return false;
  return true;
}

void bfs(int k){
  int maxl = 0;
  priority_queue<state> Q;
  state u,v;

  m[k].clear();
  fill(f[0],f[500],false);
  f[ry][rx] = true;
  Q.push(state(ry,rx,1));
  while(!Q.empty()){
    u = Q.top();
    Q.pop();

    if(u.l > maxl){
      m[k][u.l] = m[k][maxl] + 1;
      maxl = u.l;
    } else m[k][maxl]++;

    for(int i=0;i<4;i++){
      v.x = u.x + dx[i];
      v.y = u.y + dy[i];
      if(check(v.y,v.x) && !f[v.y][v.x]){
	f[v.y][v.x] = true;
	v.l = a[v.y][v.x];
	Q.push(v);
      }
    }
  }

  numr[k].clear();
  numl[k].clear();
  for(map<int,int>::iterator it=m[k].begin(); it!=m[k].end(); it++){
    numl[k].push_back(it->first);
    numr[k].push_back(it->second);
  }

}

int main(){
  while(cin >> r && r){
    int ans = INF;
    for(int k=0;k<2;k++){
      cin >> w >> h >> rx >> ry;
      rx--;
      ry--;
      for(int i=0;i<h;i++)
	for(int j=0;j<w;j++)
	  cin >> a[i][j];
      bfs(k);      
    }

    for(int i=0;i<numr[0].size();i++){
      if(numr[0][i] >= r){
	ans = min(numl[0][i],ans);
	break;
      }
      int cnt = r - numr[0][i];
      int pos = upper_bound(numr[1].begin(), numr[1].end(), cnt) - numr[1].begin();
      if(pos < numr[1].size()) ans = min(ans,numl[0][i] + numl[1][pos]);
      pos = max(0,pos-1);
      if(numr[0][i] + numr[1][pos] >= r) ans = min(ans,numl[0][i] + numl[1][pos]);
    }
    int pos = upper_bound(numr[1].begin(), numr[1].end(), r) - numr[1].begin();
    if(pos < numr[1].size()) ans = min(ans,numl[1][pos]);
    pos = max(0,pos-1);
    if(numr[1][pos] >= r) ans = min(ans,numl[1][pos]);

    cout << ans << endl;
  }
}

Measured memory_bytes: 15040