akhauriyash/Code-Regression huggingface dataset:
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
#define int long long
#define rep(i,n) for(int i=0;i<n;i++)
#define Rep(i,a,b) for(int i=a;i<b;i++)
#define REP(i,a,b) for(int i=a;i<=b;i++)
#define rev(i,n) for(int i=n-1;i>=0;i--)
#define vi vector<int>
#define pb push_back
#define pi pair<int,int>
#define vp vector<pair<int,int> >
#define mp make_pair
#define all(v) (v).begin(),(v).end()
#define fi first
#define se second
#define MEMSET(a) memset(a,0,sizeof(a))
#define inf 1000000000000000000

using namespace std;

const int mod=1e9+7;

void run();

void init() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout<<fixed<<setprecision(12);
}

signed main(){
    init();
    run();
    return 0;
}

void run(){
    int n,x;
    cin>>n>>x;
    vi a(n);
    rep(i,n)cin>>a[i];
    sort(all(a));
    int ans=0;
    int s=0;
    rep(i,n){
        if(i==n-1&&x-s==a[i])ans++;
        else if(i<n-1&&s+a[i]<=x){
            ans++;
            s+=a[i];
        }
        else break;
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<set>
#include<vector>
#include<algorithm>
#include<string>
#include<map>
#include<queue>
#include<stdio.h>
#include<math.h>
using namespace std;

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

typedef long long ll;
typedef unsigned long long int ulli;
typedef vector<int> vi;
typedef vector<long long> vll;
typedef pair<int, int> pii;

const ll INF = ll(1e18) + 1;
const int intINF = 1e9 * 2 + 3;
//--------------------------------------------------

ulli gcd(ulli a, ulli b) {return (b <= 0) ? a : gcd(b, a % b);}
ulli lcm(ulli a, ulli b) {return a * b / gcd(a, b);}

bool isPrime(int n)
{
	if (n <= 3)return n > 1;
	if (n % 2 == 0)return false;
	if (n % 3 == 0)return false;
	for (int i = 5; i * i < n; i += 6) {
		if (n % i == 0 || n % (i + 2) == 0) { return false; }
	}
	return true;
}
//---------------------------------------------------



void Main()
{
	ulli width, height , ans = 0;
	cin >> width >> height;
	if (width == 1 || height == 1) {
		ans = 1;
	}
	else {
		ans = (height * width + 1) / 2;
	}
	cout << ans << endl;
}


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

Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;

namespace Abc088
{
    class Program
    {
        static void Main(string[] args)
        {
            int N = int.Parse(Console.ReadLine());

            var rStr = Console.ReadLine().Split(' ');

            List<int> nums = new List<int>();

            for (int i = 0; i < rStr.Length; i++)
            {
                nums.Add(int.Parse(rStr[i]));
            }

            nums.Sort((a, b) => b - a);

            int Ap = 0;
            int Bp = 0;
            for (int i = 0; i < nums.Count(); i++)
            {
                if (i % 2 == 0)
                {
                    Ap += nums[i];
                }
                else
                {
                    Bp += nums[i];
                }
            }

            int result = Ap - Bp;

            Console.WriteLine(result);
        }
    }
}


Measured memory_bytes: 28204
#include<cstdio>
#define MAX 10000
#define NIL -1

struct Node{ int parent, left, right; };

Node T[MAX];
int n, D[MAX], H[MAX];

void setDepth(int u, int d){
	if(u == NIL) return;
	D[u] = d;
	setDepth(T[u].left, d+1);
	setDepth(T[u].right, d+1);
}

int setHeight(int u){
	int h1 = 0,h2 = 0;
	if(T[u].left != NIL) 
		h1 = setHeight(T[u].left) + 1;
	if(T[u].right != NIL) 
		h2 = setHeight(T[u].right) + 1;
	return H[u] = (h1 > h2 ? h1 : h2);
}


int getSibling(int u){
	if(T[u].parent == NIL) return NIL;
	if(T[T[u].parent].left != u && T[T[u].parent].left != NIL) 
		return T[T[u].parent].left;
	if(T[T[u].parent].right != u && T[T[u].parent].right != NIL) 
		return T[T[u].parent].right;
	return NIL;
}

void print(int u){
	printf("node %d: ", u);
	printf("parent = %d, ", T[u].parent);
	printf("sibling = %d, ", getSibling(u));
	int deg = 0;
	if(T[u].left != NIL) deg++;
	if(T[u].right != NIL) deg++;
	printf("degree = %d, ", deg);
	printf("depth = %d, ", D[u]);
	printf("height = %d, ", H[u]);

	if(T[u].parent == NIL){
		printf("root\n");
	} else if (T[u].left == NIL && T[u].right == NIL){ 
		printf("leaf\n");
	}else {
		printf("internal node\n");
	}
}

int main(){
	int v,l,r,root=0;
	scanf("%d",&n);

	for(int i=0;i<n;i++) T[i].parent = NIL;

	for(int i=0;i<n;i++){
		scanf("%d %d %d",&v,&l,&r);
		T[v].left=l;
		T[v].right=r;
		if(l!=NIL) T[l].parent=v;
		if(r != NIL) T[r].parent = v;
	}

	for(int i=0;i<n;i++) if(T[i].parent == NIL) root = i;

	setDepth(root, 0);
	setHeight(root);

	for(int i=0;i<n;i++) print(i);

	return 0;
}


Measured memory_bytes: 2760
#include <stdio.h>
int main(void)
{
  int n, i, x=0, j;
  scanf("%d", &n);
  int a[n], b[n], ans[n];
  for(i=0;i<n;i++){
    scanf("%d %d", &a[i], &b[i]);
    ans[i]=b[i]-a[i]+1;
  }
  for(j=0;j<n;j++){
    x+=ans[j];
  }
  printf("%d", x);
  return 0;
}


Measured memory_bytes: 128
fun readString() = readLine()!!
fun readInt() = readLine()!!.toInt()
fun readLong() = readLine()!!.toLong()
fun readIntList() = readLine()!!.split(" ").map(String::toInt)
fun readLongList() = readLine()!!.split(" ").map(String::toLong)
fun <T> Array<Array<T>>.print() {
    this.forEach {
        println(it.joinToString(" "))
    }
}

fun main(){
    val res = when(readString()) {
        "AAA" -> "No"
        "BBB" -> "No"
        else -> "Yes"
    }
    println(res)
}

Measured memory_bytes: 34372
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
ll m,n,c,b[25],a[25];
int main()
{
    while(cin>>n>>m>>c)
    {
        for(int i=0;i<m;i++) cin>>b[i];
        ll ans=0;
        for(int i=0;i<n;i++)
        {
            ll sum=0;
            for(int j=0;j<m;j++)
            {
                cin>>a[j];
                sum+=b[j]*a[j];
                //cout<<j<<" "<<sum<<"\n";
            }
            if(sum>-c) ans++;
        }
        cout<<ans<<"\n";
    }
}


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

char s[100][11];
int p[100];

int compare(const void *a, const void *b)
{
  int res;
  res = strcmp(s[*((int*)a)], s[*((int*)b)]);
  if (res == 0) {
    res = p[*((int*)b)] - p[*((int*)a)];
  }
  return res;
}


int main()
{
  int N, idx[100];
  scanf("%d", &N);
  for (int i=0; i<N; ++i) {
    idx[i] = i;
    scanf("%s %d", s[i], &p[i]);
  }
  qsort(idx, N, sizeof(int), compare);
  for (int i=0; i<N; ++i) {
    printf("%d\n", idx[i]+1);
  }
  return 0;
}

Measured memory_bytes: 128
from scipy.sparse.csgraph import shortest_path, floyd_warshall, dijkstra, bellman_ford, johnson, minimum_spanning_tree
from scipy.sparse import csr_matrix, coo_matrix, lil_matrix
import numpy as np
from collections import deque, Counter, defaultdict
from itertools import product, permutations,combinations
from operator import itemgetter
from heapq import heappop, heappush
from bisect import bisect_left, bisect_right, bisect
from fractions import gcd
from math import ceil,floor, sqrt, cos, sin, pi, factorial
import math
from functools import reduce
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(10**8)
INF = float('inf')
MOD = 10**9+7
def lcm_base(a, b):
    return (a * b) // gcd(a, b)

def lcm_list(numbers):
    return reduce(lcm_base, numbers, 1)

def factorization(n):
  arr = []
  temp = n
  for i in range(2, int(-(-n**0.5//1))+1):
    if temp%i==0:
      cnt=0
      while temp%i==0:
        cnt+=1
        temp //= i
      arr.append([i, cnt])
  if temp!=1:
    arr.append([temp, 1])
  if arr==[]:
    arr.append([n, 1])
  return arr

def main():
  A, B = map(int, readline().split())
  g = gcd(A, B)
  L = factorization(g)
  if L[0][0] == 1:
    ans = 1
  else:  
    ans = len(L) +1
  
  print(ans)
  
if __name__ == '__main__':
  main()

Measured memory_bytes: 14656
typedef long long ll;
#include <bits/stdc++.h>
using namespace std;
template<typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val){
    std::fill( (T*)array, (T*)(array+N), val );
}

string max_string(string s1,string s2){
    if(s1.length() > s2.length()){
        return s1;
    }else if(s1.length() < s2.length()){
        return s2;
    }
    for (int i = 0; i < s1.length(); i++) {
        if(s1[i] > s2[i]){
            return s1;
        }else if(s1[i] < s2[i]){
            return s2;
        }else{
            continue;
        }
    }
    return s1;
}

int main() {
    ll n,m,a[10];
    std::cin >> n>>m;
    ll v_c[10] = {0,2 , 5 , 5 , 4 , 5 , 6 , 3 , 7 , 6};
    ll cost_value[10];
    Fill(cost_value,0);
    for (int i = 0; i < m; i++) {
        std::cin >> a[i];
        if(cost_value[v_c[a[i]]]==0){
            cost_value[ v_c[a[i]] ] = a[i];
        }else if( cost_value[ v_c[a[i]] ] < a[i] ){
            cost_value[ v_c[a[i]] ] = a[i];
        }
    }
    struct cosv{
        ll cost;
        ll value;
    };
    vector<cosv> coscos;
    for (int i = 2; i < 10; i++) {
        if(cost_value[i] !=0){
            coscos.push_back({i,cost_value[i]});
            // std::cout << i<<" "<< cost_value[i] << std::endl;
        }
    }
    
    string dp[10001];
    
    for (int i = 0; i <= n; i++) {
        for (auto e : coscos) {
            if(e.cost <= i){
                if(dp[i-e.cost] == "" && i-e.cost != 0){
                    continue;
                }
                dp[i] = max_string(dp[i], max_string(to_string(e.value) + dp[i - e.cost],dp[i - e.cost] + to_string(e.value)) );
            }
        }
        // std::cout << i<<" dp: "<<dp[i] << std::endl;
    }
    std::cout << dp[n] << std::endl;
}

Measured memory_bytes: 30080
package main

import (
	"fmt"
)

func cal(n int) int {
	return n
}

func main() {
	var num int

	fmt.Scan(&num)
	exsits := make(map[int]bool, 1000000)

	exsits[num] = true

	for i := 1; i <= 1000000; i++ {
		if num%2 == 0 {
			num /= 2
		} else {
			num = num*3 + 1
		}

		if exsits[num] {
			fmt.Println(i + 1)
			break
		}

		exsits[num] = true
	}

}


Measured memory_bytes: 21760
#include <stdio.h>

int main(int argc, char **argv)
{
    char s[100001];
    scanf("%s", s);

    int alpha[26] = {};
    for (int i = 0; s[i] != '\0'; ++i) {
        alpha[s[i] - 'a']++;
    }
    for (int i = 0; i < 26; ++i) {
        if (alpha[i] == 0) {
            printf("%c\n", 'a' + i);
            goto end;
        }
    }
    puts("None");
end:
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <deque>
#include <climits>
#include <functional>
#define endl '\n'
#define ll long long

using namespace std;

int main(void)
{
    cin.tie(NULL); ios_base::sync_with_stdio(false);
    ll N;
    ll cur = 1;
    ll ret = 1;
    cin >> N;
    for(;cur * cur <= N; cur++) ret = cur;
    cout << ret * ret << endl;

    
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include<vector>
#define inf 1e9
using namespace std;

int solve(vector<int> h, int n){
    vector<int> dp(n+1);
    dp[1] = 0; // 0 cose is incurred from reaching s1 to s1
    for(int i=2;i<=n;i++){
        int op1,op2;
        op1 = abs(h[i] - h[i-1]) + dp[i-1];
        op2 = (i==2) ? inf : abs(h[i] - h[i-2]) + dp[i-2];
        dp[i] = min(op1,op2);
    }
return dp[n];
}
int main() {
    int n;
    cin>>n;
    vector<int> h(n+1); //h(n+1) denotes that vector is havinf 1 based indexing.
    for(int i=1;i<=n;i++){
        cin>>h[i];
    }
    cout<<solve(h,n);
}


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

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

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

int sum(ll n){
    int ret = 0;
    int digit = 0, num = 0;
    while(n > 0){
        num++;
        digit = n % 10;
        ret += digit;
        n /= 10;
    }
    return max(digit - 1 + (num - 1) * 9, ret);
}

int main(){
    ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
    ll n;
    cin >> n;
    cout << sum(n) << endl; 
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#include<tr1/unordered_map>
#define pb push_back
#define pii pair<int,int>
#define SZ(x) (int)x.size()
#ifdef __linux__
#define getchar getchar_unlocked
#endif
#define mem(a,b) memset(a,b,sizeof(a))
#define  For(i,a,b) for(int i=a,i##E=b;i<=i##E;++i)
#define rFor(i,a,b) for(int i=a,i##E=b;i>=i##E;--i)
typedef long long LL;
using namespace std;
const int N=110;
const int inf=0x3f3f3f3f;
const LL mod=998244353;
template<typename T>inline bool chkmin(T &a,const T &b){return a>b?a=b,1:0;}
template<typename T>inline bool chkmax(T &a,const T &b){return a<b?a=b,1:0;}
template<typename T>inline void read(T &x)
{
	x=0;int _f(0);char ch=getchar();
	while(!isdigit(ch))_f|=(ch=='-'),ch=getchar();
	while( isdigit(ch))x=x*10+ch-'0',ch=getchar();
	x=_f?-x:x;
}
inline void file()
{
#ifdef ztzshiwo
	freopen("in.txt","r",stdin);
	freopen("out.txt","w",stdout);
#endif
}
__int128 S;
int n;
char str[N];
#define pli pair<__int128,int>
map<pli,LL>mp;
inline void Add(LL&x,LL y){x=x+y<mod?x+y:x+y-mod;}
inline LL dfs(__int128 S,int n)
{
	if(!n)return 1;
	if(mp.count(pli(S,n)))return mp[pli(S,n)];
	LL &ans=mp[pli(S,n)];
	Add(ans,dfs(S>>1,n-1)*(1+(S&1))%mod);
	__int128 ret=0,now=0;
	For(i,1,n)
	{
		ret=ret<<1|1;now=ret&S;
		for(int j=i<<1;j<=n;j+=i)
			Add(ans,dfs(now&=(S>>(j-i)),i)*dfs(S>>j,n-j)%mod);
	}
	return ans;
}
int main()
{
	file();
	scanf("%s",str+1);
	n=strlen(str+1);
	For(i,1,n)S=S<<1|(str[i]-'0');
	printf("%lld\n",dfs(S,n));
	return 0;
}


Measured memory_bytes: 4480
import java.util.*;
import static java.lang.Math.*;
import static java.util.Arrays.*;

public class Main {

	int INF = 1 << 28;
	int[] s;
	int n, m, d;
	
	void run() {
		Scanner sc = new Scanner(System.in);
		for(;;) {
			d = sc.nextInt();
			if(d == 0) break;
			n = sc.nextInt();
			m = sc.nextInt();
			s = new int[n];
			s[0] = 0;
			for(int i=1;i<n;i++) 
				s[i] = Integer.parseInt(sc.next());
			
			sort(s);
//			debug(s);
			int sum = 0;
			for(int i=0;i<m;i++) {
				int to = Integer.parseInt(sc.next());
				int l = 0;
				int r = n-1;
				for(;l<=r;) {
					int c = (l+r) / 2;
					if( to < s[c] ) r=c-1;
					else if( to > s[c] ) l = c+1;
					else {
						l = r = c;
						break;
					}
				}
//				debug(l, r);
//				debug(to, l>=n? d: s[l], l>=n? abs(d-to): abs(to-s[l]), r<0? to:s[r], r<0? to:abs(to-s[r]));
				sum += min(l>=n? abs(d-to): abs(to-s[l]), r<0? to:abs(to-s[r]));
			}
			System.out.println(sum);
		}
	}

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

	void debug(Object... os) {
		System.err.println(Arrays.deepToString(os));
	}
}

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

int main(void){
  double t500,t1000;
  int r500,r1000,rank;
  while(cin>>t500>>t1000){
    if(t500<35.5)r500=0;
    else if(t500<37.5)r500=1;
    else if(t500<40)r500=2;
    else if(t500<43)r500=3;
    else if(t500<50)r500=4;
    else if(t500<55)r500=5;
    else if(t500<70)r500=6;
    else r500=7;
    if(t1000<71)r1000=0;
    else if(t1000<77)r1000=1;
    else if(t1000<83)r1000=2;
    else if(t1000<89)r1000=3;
    else if(t1000<105)r1000=4;
    else if(t1000<116)r1000=5;
    else if(t1000<148)r1000=6;
    else r1000=7;
    rank=max(r500,r1000);
    switch (rank) {
      case 0:
        cout<<"AAA"<<endl;
        break;
      case 1:
        cout<<"AA"<<endl;
        break;
      case 2:
        cout<<"A"<<endl;
        break;
      case 3:
        cout<<"B"<<endl;
        break;
      case 4:
        cout<<"C"<<endl;
        break;
      case 5:
        cout<<"D"<<endl;
        break;
      case 6:
        cout<<"E"<<endl;
        break;
      case 7:
        cout<<"NA"<<endl;
        break;
    }
  }
  return 0;
}



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

const int MOD = 1000000007;

int64_t pow_mod(int64_t x, int64_t n)
{
    int64_t res = 1;
    while (n > 0)
    {
        if (n & 1)
        {
            res = res * x % MOD;
        }
        x = x * x % MOD;
        n >>= 1;
    }
    return res;
}

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

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

    vector<bool> is_prime(1000001, true);
    vector<int> min_factor(1000001, 0);
    for (int64_t p = 2; p < 1000001; p++)
    {
        if (is_prime.at(p))
        {
            min_factor.at(p) = p;
            for (int64_t j = p * p; j < 1000001; j += p)
            {
                if (is_prime.at(j))
                {
                    is_prime.at(j) = false;
                    min_factor.at(j) = p;
                }
            }
        }
    }

    map<int, int> lcmp;
    for (int i = 0; i < n; i++)
    {
        int ai = a.at(i);
        vector<pair<int, int>> aip;
        while (ai > 1)
        {
            int p = min_factor.at(ai);
            if (!aip.empty() && aip.back().first == p)
            {
                aip.back().second += 1;
            }
            else
            {
                aip.push_back(pair<int, int>(p, 1));
            }
            ai /= p;
        }

        for (auto &&f : aip)
        {
            lcmp[f.first] = max(lcmp[f.first], f.second);
        }
    }

    int64_t lcm = 1;
    for (auto &&f : lcmp)
    {
        lcm = lcm * pow_mod(f.first, f.second) % MOD;
    }

    int64_t res = 0;
    for (int i = 0; i < n; i++)
    {
        int64_t bi = lcm * pow_mod(a.at(i), MOD - 2) % MOD;
        res = (res + bi) % MOD;
    }
    cout << res << endl;
}

Measured memory_bytes: 4736
import java.util.*;
import java.util.stream.*;
import java.io.*;
class Main {
  public static void main(String[] args) {
    BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
    br.lines()
      .skip(1)
      .parallel()
      .map(line -> Stream.of(line.split(" "))
                    .parallel()
                    .mapToInt(Integer::parseInt)
                    .map(n -> n * n)
                    .sorted()
                    .toArray())
      .map(ar -> (ar[0] + ar[1] == ar[2]) ? "YES" : "NO")
      .sequential()
      .forEach(System.out::println);
  }
}

Measured memory_bytes: 34156
#include <stdio.h>
#include <string.h>

int main(int argc, const char * argv[]) {
    
    char s[1000] = {};
    int w = 0;
    int len = 0;
    
    scanf("%s %d",s,&w);
    
    len = strlen(s);
    
    int count = len / w;
    int countA = len % w;
    if (countA != 0) {
        count++;
    }
    
    char result[1000] = {};
    int resultCount = 0;
    int plusW = 0;
    for (int i = 0; i < count; i++) {
        if (i != 0) {
            plusW = w * i;
        }else{
            plusW = i;
        }
        result[resultCount] = s[plusW];
        resultCount++;
    }
    
    printf("%s",result);
    
    
    return 0;
}

Measured memory_bytes: 128
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstring>
#include<cmath>
using namespace std;
inline int read(){
	int x = 0; char ch = getchar(); bool positive = 1;
	for (; !isdigit(ch); ch = getchar())	if (ch == '-')	positive = 0;
	for (; isdigit(ch); ch = getchar())	x = x * 10 + ch - '0';
	return positive ? x : -x;
}
inline void write(int a){
    if(a>=10)write(a/10);
    putchar('0'+a%10);
}
inline void writeln(int a){
    write(a); puts("");
}
int n,a[100005],ans;
int main(){
    n=read();
    for(int i=1;i<=n;i++){a[i]=read(); }
    if(a[1]==1){
    	ans=1; swap(a[1],a[2]);
	}
    for(int i=2;i<=n;i++){
    	if(a[i]==i){
    		if(a[i+1]==i+1){
    			swap(a[i],a[i+1]); ans++;
			}else{
				swap(a[i],a[i-1]); ans++;
			}
		}
	}
	writeln(ans);
}

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

int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);	cout.tie(NULL);
	int n;	cin >> n;
	vector<int> d1(n), d2(n);
	for (int i = 0; i < n; i += 1) {
		cin >> d1[i] >> d2[i];
	}
	bool ans = false;
	for (int i = 1; i < n-1; i += 1) {
		if (d1[i-1] == d2[i-1] and d1[i] == d2[i] and d1[i+1] == d2[i+1]) {
			ans = true;
			//cout << i << '\n';
			break;
		}
	}
	if (ans == true)
		cout << "Yes" << '\n';
	else
		cout << "No" << '\n';
	return 0;
}

Measured memory_bytes: 3656
#include <iostream>
#include <cmath>
#include <map>
#include <utility>
#include <list>
#include <string>
#include <vector>
#include <algorithm>
#include <set>

using namespace std;

#define LL long long

int n;
int a[3];
int l[8];
int ans = 10000;

void calc(vector<int> v) {
    int mp = 0;
    for (int i=0; i < 3; i++) {
        int len = 0;
        int num = 0;
        for (int j=0; j < v.size(); j++) {
            if (v[j] == i) {
                len += l[j];
                num++;
            }
        }
        if (num == 0) return;
        mp += abs(len - a[i]) + (num - 1) * 10;
    }
    if (mp < ans) {
        ans = mp;
    }
}

void dsf(int depth, vector<int> v) {
    if (depth == n) {
        calc(v);
        return;
    }

    for (int i=0; i < 4; i++) {
        vector<int> u = v;
        u.push_back(i);
        dsf(depth + 1, u);
    }
}

int main() {
    cin >> n >> a[0] >> a[1] >> a[2];

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

    dsf(0, vector<int>());

    cout << ans << endl;

    return 0;
}


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

 
int main(void){
	int i,n;
	double x1,x2,x3,y1,y2,y3,xp,yp,r;
	char str[100];

	fgets(str,sizeof(str),stdin);
	sscanf(str,"%d",&n);
	for(i=0;i<n;i++){
		fgets(str,sizeof(str),stdin);
		sscanf(str,"%lf %lf %lf %lf %lf %lf",&x1,&y1,&x2,&y2,&x3,&y3);
		r = 2 * (x1 * (y2 - y3) + x2 * (y3 - y1) + x3 * (y1 - y2));
		xp = ((x1 * x1 + y1 * y1) * (y2 - y3) + (x2 * x2 + y2 * y2) * (y3 - y1) + (x3 * x3 + y3 * y3) * (y1 - y2)) / r;
		yp = ((x1 * x1 + y1 * y1) * (x3 - x2) + (x2 * x2 + y2 * y2) * (x1 - x3) + (x3 * x3 + y3 * y3) * (x2 - x1)) / r;
		r = hypot(xp - x1, yp - y1);
		printf("%.03lf %.03lf %.03lf\n",xp,yp,r); 
	}
	return 0;
}

Measured memory_bytes: 684
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <deque>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <cstring>
#include <iomanip>
#include <utility>
  
#define rep(i,n) for(int i=0;i<(n);i++)
#define reps(i,n) for(int i=1;i<=(n);i++)
const int INF = 0x3f3f3f3f;
const long long LINF = 0x3f3f3f3f3f3f3f3fLL;
using namespace std;

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

  int a,b;
  cin>>a>>b;
  if(a==b){
    cout<<"Yes"<<'\n';
  }
  else{
    cout<<"No"<<'\n';
  }
  return 0;
}


Measured memory_bytes: 256
n = int(input())
x = input()
pcnt = x.count("1")
pp = pcnt+1
pn = pcnt-1
ansb = [0,0,0]
def modpcnt(x):
  if x == 0:
    return 0
  b = x.bit_length()
  mod = 0
  for i in range(b):
    if x&1<<i:
      mod += 1
  return 1+modpcnt(x%mod)
for i in range(n):
  if x[i] == "1":
    ansb[1] += pow(2,n-i-1,pcnt)
    ansb[1] %= pcnt
    ansb[0] += pow(2,n-i-1,pp)
    ansb[0] %= pp
    if pn == 0:
      ansb[2] = 0
    else:
      ansb[2] += pow(2,n-i-1,pn)
      ansb[2] %= pn
for i in range(n):
  if x[i] == "0":
    tmp = (ansb[0]+pow(2,n-i-1,pp))%pp
    print(modpcnt(tmp)+1)
  else:
    if pn == 0:
      print(0)
    else:
      tmp = (ansb[2]-pow(2,n-i-1,pn))%pn
      print(modpcnt(tmp)+1)

Measured memory_bytes: 81572
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <cmath>
#include <deque>

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

using namespace std;

int main()
{
	int ans = 0;
	string s;
	cin >> s;

	rep(i, s.size())
		if (s[i] == '2')
			ans++;
	cout << ans << endl;

	return 0;
}

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

int main() {
    long long n; cin >> n;
    int c = sqrt(n);
    long long a = 0;
    for(int i=c; i>0; i--){
        if(n%i==0){
            a = i;
            break;
        }
    }
    long long b = n/a;
    cout << a + b -2 << endl;
}

Measured memory_bytes: 3668
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.StringTokenizer;

public class Main {
	public static void main(String[] args) {
		FastScanner sc = new FastScanner(System.in);
		String s = sc.next();
		ArrayList<String> l = new ArrayList<>();
		while(s.length() > 9) {
			String x = s.substring(0,9);
			l.add(x);
			s = s.substring(9);
		}
		l.add(s);
		long ans = 0;
		for(String st : l) {
			int p = Integer.valueOf(st);
			while(p >= 10) {
				ans += p%10;
				p /= 10;
			}
			ans += p;
		}
		if(ans%9 == 0) {
			System.out.println("Yes");
		}else {
			System.out.println("No");
		}

	}

	static class FastScanner {
		private BufferedReader reader = null;
	    private StringTokenizer tokenizer = null;
	    public FastScanner(InputStream in) {
	        reader = new BufferedReader(new InputStreamReader(in));
	        tokenizer = null;
	    }

	    public String next() {
	        if (tokenizer == null || !tokenizer.hasMoreTokens()) {
	            try {
	                tokenizer = new StringTokenizer(reader.readLine());
	            } catch (IOException e) {
	                throw new RuntimeException(e);
	            }
	        }
	        return tokenizer.nextToken();
	    }

	    public String nextLine() {
	        if (tokenizer == null || !tokenizer.hasMoreTokens()) {
	            try {
	                return reader.readLine();
	            } catch (IOException e) {
	                throw new RuntimeException(e);
	            }
	        }

	        return tokenizer.nextToken("\n");
	    }

	    public long nextLong() {
	        return Long.parseLong(next());
	    }

	    public int nextInt() {
	        return Integer.parseInt(next());
	    }

	    public double nextDouble() {
	         return Double.parseDouble(next());
	     }

	    public int[] nextIntArray(int n) {
	        int[] a = new int[n];
	        for (int i = 0; i < n; i++)
	            a[i] = nextInt();
	        return a;
	    }

	    public long[] nextLongArray(int n) {
	        long[] a = new long[n];
	        for (int i = 0; i < n; i++)
	            a[i] = nextLong();
	        return a;
	    }
	}
}


Measured memory_bytes: 55040
#include <iostream>


using namespace std;


int main()
{
  int n, minv=101, sumv=0;
  cin >> n;
  int *s = new int[n];

  for (int i=0; i<n; i++){
    cin >> s[i];
    sumv += s[i];
    if (s[i]%10 != 0 && s[i] < minv) minv = s[i];
  }

  if (sumv%10 != 0) cout << sumv << endl;
  else{
    if (minv == 101) cout << 0 << endl;
    else cout << sumv - minv << endl;
  }

  delete s;

  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define MOD 1000000007
#define INF 1000000000
#define LINF 1000000000000000000
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define bit(n) (1LL<<(n))
using namespace std;

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

int main() {
    
    long long L, R;
    cin >> L >> R;

    long long ans = 2019;

    for (long long i = L; i < R && i < L + 2019; i++) {
        for (long long j = i + 1; j <= R && j < i + 1 + 2019; j++) {
            ans = min(ans, (i * j) % 2019);
        }
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256
import collections
import sys
def main():

    sys.setrecursionlimit(10 ** 6)

    N, M = map(int, input().split())
    graph = collections.defaultdict(list)
    for _ in range(M):
        x, y = map(int, input().split())
        graph[x].append(y)

    memo = dict()
    def helper(node):
        if node in memo:
            return memo[node]

        max_l = 0
        for nxt in graph[node]:
            max_l = max(max_l, helper(nxt) + 1)
        memo[node] = max_l
        return max_l

    max_l = 0
    for i in range(1, N+1):
        l = helper(i)
        max_l = max(max_l, l)
    return max_l

if __name__ == '__main__':
    print(main())

Measured memory_bytes: 158720
#include <stdio.h>

#define LENGTH 10
#define HIGH 10
#define LOW 1


int calc(int num) {
  int result;
  result = num + num * num + num * num * num;
  return result;
}

int main() {
  char input[LENGTH];
  int a, b;
  fgets(input, LENGTH, stdin);
  sscanf(input, "%d", &a);
  b = calc(a);
  printf("%d \n", b);
}


Measured memory_bytes: 1724
using System;

namespace AtCoderProject
{
    class Program
    {
        static void Main(string[] args)
        {
            var s = Console.ReadLine().ToCharArray();
            var t = Console.ReadLine().ToCharArray();
            int cnt = 0;
            for (int i = 0; i < s.Length; i++)
            {
                if (s[i].CompareTo(t[i]) != 0)
                {
                    s[i] = t[i];
                    cnt++;
                }
            }
            Console.WriteLine(cnt);
        }
    }
}


Measured memory_bytes: 28312
#include <iostream>
#include <algorithm>
#include <cstdio>
#include <vector>
#include <math.h>
#include <iomanip>
#include <bitset>
#include <string>
#include <cstring>
#include <stdlib.h>
#include <utility>
#include <set>
using namespace std;
typedef long long int ll;
typedef long double ld;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
const long long INF = 1LL << 60;
 
typedef pair<ll,ll> pairs;
vector<pairs> p;
bool pairCompare(const pair<double,ll>& firstElof, const pair<double,ll>& secondElof){
    return firstElof.first < secondElof.first;
}
#define MAX_N 1000100
bool x[MAX_N];
ll num[MAX_N];
ll fibl[MAX_N]={0};
 
ll fib(ll a){
    if (fibl[a]!=0)return fibl[a];
    if (a==0){
        return 0;
    }else if (a==1){
        return 1;
    }
    return fibl[a]=fib(a-1)+fib(a-2);
}
 
ll eratosthenes(ll n) {
    int p = 0;
    for (ll i=0; i<=n; ++i) x[i] = true;
    x[0] = x[1] = false;
    for(int i=2; i<=n; ++i) {
        if(x[i]) {
            p++;
            for(int j=2*i; j<=n; j+=i) x[j] = false;
        }
        
        num[i] = p;
    }
    return p;
}
 
ll gcd(ll a,ll b){
    if (a%b==0)return(b);
    else return(gcd(b,a%b));
}
 
ll keta(ll N){
    int tmp{};
    while( N > 0 ){
        tmp += ( N % 10 );
        N /= 10;
    }
    N = tmp;
    return N;
}

int main(){
    string s;
    cin >> s;
    ll count=0,ans;
    for (ll i=0;i<s.size();i++){
        if (i%2==0){
            if(s[i]=='1')count++;
        }else{
            if(s[i]=='0')count++;
        }
    }
    ans=count;
    count=0;
    for (ll i=0;i<s.size();i++){
        if (i%2==1){
            if(s[i]=='1')count++;
        }else{
            if(s[i]=='0')count++;
        }
    }
    ans=min(ans,count);
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 512
package main

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

func configure(scanner *bufio.Scanner) {
	scanner.Split(bufio.ScanWords)
	scanner.Buffer(make([]byte, 1000005), 1000005)
}
func getNextString(scanner *bufio.Scanner) string {
	scanned := scanner.Scan()
	if !scanned {
		panic("scan failed")
	}
	return scanner.Text()
}
func getNextInt(scanner *bufio.Scanner) int {
	i, _ := strconv.Atoi(getNextString(scanner))
	return i
}
func getNextInt64(scanner *bufio.Scanner) int64 {
	i, _ := strconv.ParseInt(getNextString(scanner), 10, 64)
	return i
}
func getNextFloat64(scanner *bufio.Scanner) float64 {
	i, _ := strconv.ParseFloat(getNextString(scanner), 64)
	return i
}
func main() {
	fp := os.Stdin
	wfp := os.Stdout
	extra := 0
	if os.Getenv("I") == "IronMan" {
		fp, _ = os.Open(os.Getenv("END_GAME"))
		extra = 100
	}
	scanner := bufio.NewScanner(fp)
	configure(scanner)
	writer := bufio.NewWriter(wfp)
	defer func() {
		r := recover()
		if r != nil {
			fmt.Fprintln(writer, r)
		}
		writer.Flush()
	}()
	solve(scanner, writer)
	for i := 0; i < extra; i++ {
		fmt.Fprintln(writer, "-----------------------------------")
		solve(scanner, writer)
	}
}
func solve(scanner *bufio.Scanner, writer *bufio.Writer) {
	n := getNextInt64(scanner)
	stack := make([]int64, 0)
	for n > 0 {
		n--
		stack = append(stack, n%26)
		n /= 26
	}
	for i := len(stack) - 1; i >= 0; i-- {
		fmt.Fprintf(writer, "%c", 'a'+stack[i])
	}
	fmt.Fprintln(writer, "")
}


Measured memory_bytes: 1792
#include<iostream>
#include<math.h>
#include<algorithm>
#include<stdint.h>
#include<vector>
#include<deque>
#include<stack>
#include<string>
#include<cstring>
#include<time.h>
#include<iomanip>
#include<list>
#include<set>
#include<unordered_map>
#include<unordered_set>
#include<random>
#include<bitset>
#include <queue>
#include <map>


using namespace std;
using ll = long long;
using ull = unsigned long long;
using uint = unsigned int;
using ldouble = long double;


#define repi(i,a,b) for(ll i = (a); i < (b); i++)
#define rep(i, n) for(ll i = 0; i < (n); ++i)


ll MOD = 1000000007;


ull n(const vector<ll> & v, ll k) {
	if (v[0] >= k) return 0;
	int st = 0;
	int en = v.size();
	while (st + 1 != en) {
		int bo = (en + st) / 2;
		if (v[bo] < k) st = bo;
		else en = bo;
	}
	return st + 1;
}
//kより大きい要素数-> ｋ以下の最大のインデックスを求める
ull n2(const vector<ll>& v, ll k) {
	if (k < v[0]) return v.size();
	int st = 0;
	int en = v.size();
	while (st + 1 != en) {
		int bo = (en + st) / 2;
		if (v[bo] <= k) st = bo;
		else en = bo;
	}
	return v.size() -1- st;
}

int main() {
	int N; 
	cin >> N;
	vector<ll> A(N);
	vector<ll> B(N);
	vector<ll> C(N);
	rep(i, N) cin >> A[i];
	rep(i, N) cin >> B[i];
	rep(i, N) cin >> C[i];
	sort(A.begin(), A.end());
	sort(B.begin(), B.end());
	sort(C.begin(), C.end());
	ull res = 0;
	rep(j, N) {
		res += n(A, B[j]) * n2(C, B[j]);
	}
	cout << res << endl;
	return 0;
}


Measured memory_bytes: 2560
#include <iostream>
#include <iomanip>
#include <algorithm>
typedef long long ll;
using namespace std;
const ll INF = 1e9;
const ll MOD = 1e9 + 7;
#define repi(i, n, init) for (ll i = init; i < (n); i++)

int main()
{
    int n;
    cin >> n;
    int w[n];
    int s1 = 0, s2 = 0;
    repi(i, n, 0)
    {
        cin >> w[i];
        s2 += w[i];
    }
    s1 = w[0];
    s2 -= s1;
    int ans = abs(s1 - s2);
    repi(i, n - 1, 1)
    {
        s1 += w[i];
        s2 -= w[i];
        ans = min(ans,abs(s1-s2));
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
using namespace std;
int main(){
  string s;
  cin >> s;
  int n = s.length();
  int counter = 0;
  for(int i = 0; i < n/2; i++){
    if(s[i] != s[n-i-1]){
      counter++;
    }
  }
  cout << counter << endl;
}

Measured memory_bytes: 256
#include <iostream>
using namespace std;
//A - On the Way
int main(void){
    int a,b,c;
    std::cin >> a >> b >> c;
    
    if(a>b)swap(a,b);
    
    if(a<c && c<b){
        std::cout << "Yes" << std::endl;
    }else{
        std::cout << "No" << std::endl;
    }
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;i++)
using namespace std;
using ll=long long;
using ld=long double;
using Graph=vector<vector<int>>;
const int mod=1e9+7;
const int mxN=2e6+3;
vector<int> x_vec={-1,1,0,0};
vector<int> y_vec={0,0,-1,1};

int main(void){
    string s;
    cin>>s;
    if(s.at(s.size()-1)=='s')cout<<s<<"es"<<endl;
    else cout<<s<<'s'<<endl;
    return 0;
}

Measured memory_bytes: 3628
#include<iostream>
using namespace std;
#define SHEETS 17
#define GROUPS 130

int main()
{
	int ans[GROUPS] = {0,};
	int now;
	int sheets[SHEETS];
	int peoples[GROUPS] = {0,};
	int arrive[GROUPS] = {0,};
	int eating[GROUPS] = {0,};

	for(int i = 0; i < SHEETS; ++i){
		sheets[i] = -1;
	}
	for(int i = 0; i < GROUPS; ++i)
	{
		arrive[i] = i*5;
		peoples[i] = i%5==1?5:2;
		eating[i] = 17*(i%2)+3*(i%3)+19;
	}
	
	now = 0;
	for(int t = 0; t < 800; ++t){

		for(int i = 0; i < SHEETS; ++i){
			if( sheets[i] >= 0 ){
				--eating[sheets[i]];
				if( eating[sheets[i]] == 0 ){
					for(;sheets[i]==sheets[i+1]&&i<SHEETS-1;++i)
						sheets[i] = -1;
					sheets[i]=-1;
					/*
					cout << "t=" << t <<":\t";
					for(int i = 0; i < SHEETS; ++i){
						cout << sheets[i] << ' ';
					}
					cout << endl;
					*/
					
				}else{
					for(;sheets[i]==sheets[i+1]&&i<SHEETS-1;++i)
						0;
				}
			}
		}

		while( true ){
			bool bCont = false;
			for(int i = 0; i < SHEETS; ++i){
				if( sheets[i] == -1 ){
					int cont = 0;
					for(int j = i; j < SHEETS; ++j){
						if( sheets[j] == -1 ) cont++;
						else break;
					}
					if( now < GROUPS && cont >= peoples[ now ] && t >= arrive[ now ] ){
						for(int j = i; j < i+peoples[now]; ++j)
							sheets[j] = now;
						
						/*
						cout << "t=" << t <<":\t";
						for(int k = 0; k < SHEETS; ++k){
							cout << sheets[k] << ' ';
						}
						cout << endl;
						*/
						
						ans[now] = t - arrive[now];//<0?0:waiting[now];
						++now;
						bCont = true;
						break;
					}
				}
			}
			if( !bCont ) break;
		}
	}

	/*
	for(int i = 0; i < GROUPS;++i){
		cout << ans[i] << ' ';
	}
	*/

	while(true){
		int n;
		cin >> n;
		if(cin.eof())
			break;
		cout << ans[n] << endl;
	}

	return 0;
}

Measured memory_bytes: 0
l = list(map(int,input().split()))
k=0
if l[0]== l[1]==l[2]:
    k+=1
if l[0]!=l[1]:
    k+=1
if l[1]!=l[2]:
    k+=1
if l[2]!=l[0]:
    k+=1
if k>3:
    k=3
print('{}'.format(k))


Measured memory_bytes: 3060
#include <iostream>
#include <iomanip>
#include <vector>
#include <string>
#include <algorithm>
#include <cmath>
#include <stack>
#include <queue>
#include <functional>
#include <limits.h>
#include <set>
#include <map>
#include <tuple>
using namespace std;



#define ll long long
#define ull unsigned long long
#define rep(i,N) for (ll i=0;i<N;i++)
#define loop(i,N,M) for(ll i=N;i<M;i++)
#define MAX(v) *max_element(v.begin(),v.end())
#define MIN(v) *min_element(v.begin(),v.end())
#define SORTL2S(type,v) sort(v.begin(),v.end(),greater<type>())
#define SORTS2L(type,v) sort(v.begin(),v.end())
#define SORTMF(v,func) sort(v.begin(),v.end(),func)

ll debugFlag = false;
template<typename T> void debug(T&);
template<typename T> void debug(T&, bool);
template<typename T> void debug(vector<T>&);
template<typename T> void debug(vector<T>&, bool);
template<typename T, typename U> void debug(pair<T, U>&);
template<typename T, typename U> void debug(pair<T, U>&, bool);

template<typename T>
void debug(T& obj) {
	debug(obj, true);
}

template<typename T>
void debug(T& obj, bool lnFlag) {
	if (!debugFlag) return;
	cout << obj;
	if (lnFlag) cout << endl;
}

template<typename T>
void debug(vector<T>& obj) {
	debug(obj, true);
}

template<typename T>
void debug(vector<T>& obj, bool lnFlag) {
	if (!debugFlag) return;
	cout << "[";
	rep(i, obj.size()) {
		if (i != 0) cout << ",";
		debug(obj[i], false);
	}
	cout << "]";
	if (lnFlag) cout << endl;
}

template<typename T, typename U>
void debug(pair<T, U>& obj) {
	debug(obj, true);
}

template<typename T, typename U>
void debug(pair<T, U>& obj, bool lnFlag) {
	if (!debugFlag) return;
	cout << "(";
	debug(obj.first, false);
	cout << ",";
	debug(obj.second, false);
	cout << ")";
	if (lnFlag) cout << endl;
}

void solve() {

	int X, Y;
	cin >> X >> Y;

	ll ans = 0;
	if (X < 4) ans += (4 - X) * 100000;
	if (Y < 4) ans += (4 - Y) * 100000;
	if (X == 1 && Y == 1) ans += 400000;

	cout << ans;


}


int main(int argc, char* argv[]) {
	if (argc == 2 && string(argv[1]) == "debug") debugFlag = true;
	solve();
	return 0;
}


Measured memory_bytes: 256
n=input()
op_cnt=len(n)-1
for i in range(2**op_cnt):
    op=["-"]*op_cnt
    for j in range(op_cnt):
        if ((i >> j)&1):
            op[j]="+"

    formula=""
    for p_n, p_o in zip(n, op + [""]):
        formula += (p_n + p_o)
    if eval(formula) == 7:
        print(formula + "=7")
        break

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

#define ll long long
#define pb push_back
#define F first
#define S second

using namespace std;

const int N = 300005;

int main() {
    ios_base :: sync_with_stdio(0);
    cin.tie(0), cout.tie(0);
    int n, k; string s;
    cin >> n >> k >> s;
    s[k - 1] = tolower(s[k - 1]);
    cout << s << endl;
    return 0;
}


Measured memory_bytes: 256
import java.util.*;
public class Main{
	public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        String s = sc.next();
        int k = sc.nextInt();
        HashSet<String> set = new HashSet<>();
        for(int i=0; i<k; i++){
            for(int j=0; j<s.length()-i; j++){
                set.add(s.substring(j, j+i+1));
            }
        }
        List<String> list = new ArrayList<>(set);
        Collections.sort(list);
        System.out.println(list.get(k-1));
    }
}


Measured memory_bytes: 27216
#define _USE_MATH_DEFINES

#include <iostream>
#include <iomanip>
#include <string>
#include <vector>
#include <algorithm>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <cmath>
#include <atcoder/all>
using namespace std;
using namespace atcoder;

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef tuple<ll, ll, ll> tl3;

//typedef modint998244353 mint;

const int BIG_NUM = 1e9;
const ll INF = 1000000000000000000;
const ll MOD = 1e9 + 7;
//const ll MOD = 998244353;

const ll MAX = 1e9 + 5;


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

	dsu d(n);
	for (int i = 0; i < m; i++) {
		int a, b;
		cin >> a >> b;
		a--;
		b--;
		d.merge(a, b);
	}

	int cnt = 0;
	for (int i = 0; i < n; i++) {
		//cout << i << " " << d.same(0,i) << endl;
		if (!d.same(0, i)) {
			//cout << i << endl;
			cnt++;
			d.merge(0, i);
		}
	}
	cout << cnt << endl;

}

Measured memory_bytes: 3824
private fun readLn() = readLine()!! // string line
private fun readInt() = readLn().toInt() // single int
private fun readStrings() = readLn().split(" ") // list of strings
private fun readInts() = readStrings().map { it.toInt() } // list of ints

fun main(){
    val (a, b) = readInts()
    println(a*b)
}

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

int main()
{
    int x,y;
    int temp;

    while(1){
        cin >> x >> y;

        if(x==0 && y==0){
            break;
        }

        if(x>y){
            temp=x;
            x=y;
            y=temp;
        }
        cout << x << " " << y << endl;
    }

    return 0;
}


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

using namespace std;

int main()
{
    int a, b, c;
    cin >> a >> b >> c;
    cout << min(min(a, b), c)*(sqrt(max(max(a, b), c)*max(max(a, b), c) - min(min(a, b), c)*min(min(a, b), c)))/2;
}


Measured memory_bytes: 256
#include <iostream>
#include <sstream>
#include <cstdio>
#include <cmath>
#include <cstring>
#include <cctype>
#include <string>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <algorithm>
#include <functional>
#include <iomanip>
#include <limits>

using namespace std;
typedef long long int ll;
void sayYes() { cout << "Yes" << endl; };
void sayNo() { cout << "No" << endl; };
ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }                   // 最大公約数
ll lcm(ll a, ll b) { return a * b / gcd(a, b); };                      // 最小公倍数
ll getDigit(ll num) { return log10(num) + 1; }                         // 桁数
ll digitSum(ll n) { return (n < 10) ? n : digitSum(n / 10) + n % 10; } // 各桁の和
#define rep(i, n) for (ll i = 0; i < n; i++)
#define repn(i, n) for (ll i = 1; i <= n; i++)

void Main()
{
    vector<int> a(3);
    cin >> a[0] >> a[1] >> a[2];
    set<int> s(a.begin(), a.end());
    cout << s.size() << endl;

    return;
}

signed main(void)
{
    std::cin.tie(nullptr);
    std::ios_base::sync_with_stdio(false);
    std::cout << std::fixed << std::setprecision(15);
    Main();
    return 0;
}


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

#define rep(i,n) for(ll i=0;i<(n);++i)
using ll = int_fast64_t;
using pll = pair<ll,ll>;
constexpr ll INF = 1LL<<60;
constexpr ll MOD = 1e9+7;
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(a>b){a=b;return 1;}return 0;}
#if loc||local
void dump(){cerr<<endl;}
template<class T,class... Ts> void dump(T&& h, Ts&&... t){cerr<<h<<", ";dump(forward<Ts>(t)...);}
#else
void dump(){}
template<class T,class... Ts> void dump(T&& h, Ts&&... t){}
#endif
template<class T> istream &operator>>(istream&is,vector<T>&v){for(auto &elemnt:v)is>>elemnt;return is;}
template<class T,class U> istream &operator>>(istream&is,pair<T,U>&p){is>>p.first>>p.second;return is;}
template<class T> ostream &operator<<(ostream& os,vector<T>const& v){for(auto const& vi:v)os<<vi<<" ";return os;}
template<class T,class U> ostream &operator<<(ostream& os,pair<T,U>const& p){os<<p.first<<","<<p.second;return os;}
template<class T>vector<T> vec(size_t a){return vector<T>(a);}
template<class T, class... Ts>auto vec(size_t a, Ts... ts){return vector<decltype(vec<T>(ts...))>(a, vec<T>(ts...));}

signed main(){

  ll a,v,b,w,t;
  cin>>a>>v>>b>>w>>t;

  if(v==w){
    puts("NO");
    return 0;
  }

  ll dx = abs(a-b);
  ll dv = v-w;

  if(dv<=0){
    puts("NO");
    return 0;
  }
  constexpr auto ceil = [](auto a,auto b){return (a-1)/b+1;};
  if(ceil(dx,dv)<=t)puts("YES");
  else puts("NO");

}

Measured memory_bytes: 3672
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
using namespace std;
#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);

typedef tree<int,null_type,less<int>,rb_tree_tag, tree_order_statistics_node_update> indexed_set;
typedef long long int lli;
typedef long double ld;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<long long, long long> pll;
typedef vector<int> vi;
typedef vector<long long> vll;
typedef vector<pair<int,int>> vp;
typedef pair<int,pair<int,int>> ddp;
typedef pair<long long,pll> ldp;

#define mp make_pair
#define eb emplace_back
#define pb push_back
#define all(v) v.begin(), v.end()
#define fi(n) for(int i=0;i<(n);i++)
#define fj(n) for(int j=0;j<(n);j++)
#define fk(n) for(int k=0;k<(n);k++)
#define mod 1000000007
#define MAX 100000+5;

int main()
    {
        fastio
        lli n,x,y;
        cin >> n;
        vector<pair<lli,lli>> vec;
        fi(n)
        {
            cin >> x >> y;
            vec.pb(mp(y,x));
        }
       sort(all(vec));
       lli sum=0,c=1;
       fi(n)
       {
           sum+=(vec[i].second);
           if(sum>vec[i].first)
           {
               c=0;
               break;
           }
       }
       if(c)
       cout << "Yes" << endl;
       else
       cout << "No" << endl;
        return 0;
    }

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

ll mod = 1000000007;
ll modpow(ll a, ll n){
    ll res = 1;
    while(n > 0){
        if(n & 1) res = res * a % mod;
        a = a * a % mod;
        n >>= 1;
    }
    return res;
}
ll com(ll a, ll b){
	ll res = 1;
	b = min(b, a-b);
	ll n = b;
	for(int i=0; i<n; i++){
    	res *= a;
    	if(res >= mod) res %= mod;
    	res *= modpow(b, mod-2);
    	if(res >= mod) res %= mod;
    	a--;
    	b--;
    }
	return res;
}

int main(){
	int a, b, c;
	cin >> a >> b >> c;
	int aa = a;
	ll ans = 1;
	ll n = 2;
    while(aa > 0){
        if(aa & 1) ans = ans * n % mod;
        n = n * n % mod;
        aa >>= 1;
    }
	ans--;
	if(ans < 0) ans += mod;
	ans -= com(a, b);
	if(ans < 0) ans += mod;
	ans -= com(a, c);
	if(ans < 0) ans += mod;
	cout << ans << endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<algorithm>

using namespace std;

int main(void){

  int d,n,t,a,b,c,dp[202][202];
  vector<int>T,A,B,C;

  cin >> d >> n;
  
  for(int i=0;i<d;i++){
    cin >> t;
    T.push_back(t);
  }
  
  for(int i=0;i<n;i++){
    cin >> a >> b >> c;
    A.push_back(a);
    B.push_back(b);
    C.push_back(c);
  }
  
  for(int i=0;i<202;i++)
    for(int j=0;j<202;j++)
      dp[i][j]=-1;
  
  for(int i=0;i<n;i++)
    for(int j=0;j<n;j++)
      if(A[i]<=T[0] && T[0]<=B[i] && A[j]<=T[1] && T[1]<=B[j])
	dp[0][j]=max(dp[0][j],abs(C[i]-C[j]));
  
  for(int i=1;i<=d;i++)
    for(int j=0;j<n;j++)
      for(int k=0;k<n;k++)
	if(A[k]<=T[i+1] && T[i+1]<=B[k] && dp[i-1][j]>=0)
	  dp[i][k]=max(dp[i][k],dp[i-1][j]+abs(C[j]-C[k]));
  
  int ans=0;
  for(int i=0;i<n;i++)
    ans=max(ans,dp[d-2][i]);
  
  cout << ans << endl;
  
  return 0;
}

Measured memory_bytes: 1384