akhauriyash/Code-Regression huggingface dataset:
#include <cstdio>
#include <iostream>
using namespace std;

long long read() {
    long long x = 0, f = 1;
    char c = getchar();
    while (c < '0' || c > '9') {
        if (c == '-') f = -1;
        c = getchar();
    }
    while (c >= '0' && c <= '9') {
        x = x * 10 + c - '0';
        c = getchar();
    }
    return x * f;
}

int n;
long long a[2003];
char s[2003];

long long b[2003];

void ins(long long x) {
    for (int i = 60; i >= 0; --i) {
        if (~x >> i & 1) continue;
        if (!b[i]) {
            b[i] = x;
            break;
        }
        x ^= b[i];
    }
}

long long qry(long long x) {
    for (int i = 60; i >= 0; --i) {
        if (~x >> i & 1) continue;
        x ^= b[i];
    }
    return x;
}

int main() {
    for (int T = read(); T; --T) {
        n = read();
        for (int i = 1; i <= n; ++i) a[i] = read();
        for (int i = 1; i <= 70; ++i) b[i] = 0;
        scanf("%s", s + 1);
        int res = 0;
        for (int i = n; i >= 1; --i) {
            if (s[i] == '0')
                ins(a[i]);
            else if (qry(a[i])) {
                res = 1;
                break;
            }
        }

        printf("%d\n", res);
    }
    return 0;
}

Measured memory_bytes: 3204
#pragma warning(disable:4996)
#include <stdio.h>

int main(void) {
	int a[4], b, i;
	scanf("%d", &b);
	for (i = 0; i < 4; i++) {
		a[i] = b % 10;
		if (i > 0) {
			if (a[i] == a[i - 1]) {
				printf("Bad\n");
				return 0;
			}
		}
		b /= 10;

	}
	printf("Good\n");
	return 0;
}

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

int main(){
	int n;
	cin >> n;
	vector<int> b(n);

	for(int i = 0;i < n-1;i++){
	cin >> b[i];
	}
int ans = b[0] + b[n-2];
	for(int i = 1;i < n-1;i++){
	ans += min(b[i],b[i-1]);
	}

	cout << ans <<endl;
	return 0;
}

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

using namespace std;
long long int dizi[100005];
int main(){	
	long long	int a,b;
	cin>>a>>b;
	long long int x=1;
	int cift=0;
	int iki=0;
	for(int i=0;i<a;i++){
		cin>>dizi[i];
		dizi[i]=dizi[i]/2;
		int yed=dizi[i];
		if(cift==0)
		while(yed%2 == 0){
			cift++;
			yed=yed/2;
		}
		
		else{
			iki=0;
			while(yed%2 == 0){
				iki++;
				yed=yed/2;
			}
			if(iki != cift){
				cout<<0;
			
				return 0;
			}
		
		}
		x=(x*dizi[i])/__gcd(x,dizi[i]);
		if(x>b){
			cout<<0<<endl;
			return 0;
			
		}
	}
	
	cout<<(b+x)/(x*2);	

		
}

Measured memory_bytes: 1024
import java.util.Scanner;

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

    int K = scanner.nextInt();
    int T = scanner.nextInt();
    int[] a = new int[T];
    int max = 0;
    for (int i = 0; i < T; i++) {
      a[i] = scanner.nextInt();
      max = Math.max(max, a[i]);
    }
    if (max > (K + 1) / 2) {
      System.out.println(max * 2 - K - 1);
    } else {
      System.out.println(0);
    }
  }
}


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

using namespace std;

#define pb push_back

#define ll long long int
vector<pair<int, int>> graph[100000];
#define max 1000000

int main(){
    
    char ch;
    cin>>ch;
    if(ch>='a' && ch<='z'){
        cout<<"a";
    }
    else if(ch>='A' && ch<='Z'){
        cout<<"A";
    }
    return 0;
}

Measured memory_bytes: 5972
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		long tairyoku = Long.parseLong(sc.next());
		long kobetsuTairyoku = tairyoku;
		long count = 0;
		while(kobetsuTairyoku > 1) {
			kobetsuTairyoku = kobetsuTairyoku/2;
			count++;
		}
		long sumCount = 0;
		for(int i=0; i<=count; i++) {
			sumCount = (long) (sumCount + Math.pow(2, i));
		}
		System.out.println(sumCount);

	}

}

Measured memory_bytes: 24020
N=int(input())
S=[]
for i in range(N):
    x=input()
    S.append(x)

S1=[]
for i in S:
    if i[0] == "M":
        S1.append(i)
    if i[0] == "A":
        S1.append(i)
    if i[0] == "R":
        S1.append(i)
    if i[0] == "C":
        S1.append(i)
    if i[0] == "H":
        S1.append(i)

dict={}
for i in range(len(S1)):
    x=S1[i]
    if x[0] in dict:
        dict[x[0]] += 1
    else:
        dict[x[0]] = 1

if len(dict) < 3:
    print("0")

if len(dict) == 3:
    list3 = list(dict.values())
    print(list3[0]*list3[1]*list3[2])

if len(dict) == 4:
    list4 = list(dict.values())
    print((list4[0]*list4[1]*list4[2])+(list4[0]*list4[2]*list4[3])+(list4[1]*list4[2]*list4[3])+(list4[0]*list4[1]*list4[3]))

if len(dict) == 5:
    a = list(dict.values())
    print((a[0]*a[1]*a[2])+(a[0]*a[2]*a[3])+(a[0]*a[3]*a[4])+(a[0]*a[1]*a[3])+(a[0]*a[1]*a[4])+(a[1]*a[2]*a[3])+(a[1]*a[2]*a[4])+(a[1]*a[3]*a[4])+(a[2]*a[3]*a[4])+(a[0]*a[2]*a[4]))


Measured memory_bytes: 10548
#include <bits/stdc++.h>
using namespace std;
const int maxn = 3e5 + 10;
const int mod = 1e9 + 7;
int n, m;
int a[maxn], b[maxn], num[maxn];
int read() {
	int x; scanf("%d", &x); return x;
}
int main() {
	#ifdef LOCAL
		freopen("1.in", "r", stdin);
	#endif
	n = read();
	for (int i = 1; i <= n; ++i) a[i] = read();
	int cur = 0;
	for (int i = 1; i <= n; ++i) cur = cur ^ (a[i] ^ a[1]);
	for (int i = 1; i <= n; ++i) cout << (a[i] ^ cur) << ' ';
	cout << endl; 
}	

Measured memory_bytes: 4452
n = int(input())
x = input().split()
y = input().split()
import math
for i in range(4):
    D = 0
    for j in range(n):
        if i != 3:
            D = D + math.pow(math.fabs(int(x[j]) - int(y[j])),i+1)
        else:
            compare = math.fabs(int(x[j]) - int(y[j]))
            if D < compare:
                D = compare
    if i != 3:
        print('{0:.6f}'.format(math.pow(D,1/(i+1))))
    else:
        print('{0:.6f}'.format(D))


Measured memory_bytes: 5716
using System;
using System.Text;
using System.Collections.Generic;
using static System.Math;
using System.Linq;
using static System.Array;

namespace ConsoleApp2
{
    class Program
    {
        static long[,] A;
        static bool[,] map;
        static long count = 0;
        static long N;
        static long[] used;
        static long ans = 0;
        static void Main(string[] args)
        {
            N = long.Parse(Console.ReadLine());

            if (Solve(N) && N <= 81)
            {
                Console.WriteLine("Yes");
            }
            else
            {
                Console.WriteLine("No");
            }

        }

        static bool Solve(long N)
        {


            for (int i = 1; i <= 9; i++)
            {
                if (N % i == 0 && N / i <= 9)
                {
                    return true;
                }
            }
            return false;
        }

    }
}


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

int main(void)
{
	long long int N;
	long long int arr[200001] = {};
	scanf("%lld",&N);
	char str[200001][11];
	long long int index = 0;
	while (index < N)
	{
		scanf("%s",str[index]);
		index++;
	}
	index = 0;
	qsort(str,N,11,strcmp);
	while (index <N-1)
	{
		if(!strcmp(str[index],str[index+1]))
		{
			arr[index]++;
			arr[index+1] =  arr[index] +1;
		}
		index++;
	}
	index =0;
	long long int max_count = 0;
	while (index <N)
	{
		if(max_count < arr[index])
			max_count = arr[index];
		index++;
	}
	index =0;
	while (index <N)
	{
		if(arr[index] == max_count)
			printf("%s\n",str[index]);
		index++;
	}


	return(0);
}


Measured memory_bytes: 6012
#include <stdio.h> 

int main(void){
    int n,m,l,i,j,k;
    scanf("%d %d %d",&n,&m,&l);
    int matA[n][m];
    int matB[m][l];
    long long matC[n][l];
    for(i=0;i<n;i++){
        for(j=0;j<l;j++){
            matC[i][j] = 0;
        }
    }
    for(i=0;i<n;i++){
        for(j=0;j<m;j++){
            scanf("%d",&matA[i][j]);
        }
    }
    
    for(i=0;i<m;i++){
        for(j=0;j<l;j++){
            scanf("%d",&matB[i][j]);
        }
    }
    for(i=0;i<n;i++){
        for(j=0;j<l;j++){
            for(k=0;k<m;k++){
                matC[i][j] += matA[i][k] * matB[k][j];
            }
        }
    }
    for(i=0;i<n;i++){
        for(j=0;j<l;j++){
            if(j != 0) printf(" ");
            printf("%lld",matC[i][j]);
        }
        printf("\n");
    }
    return 0;
}

Measured memory_bytes: 760
fun main(args: Array<String>) {
    // Your code here!
    var (n,m) = readLine()!!.split(" ").map{it.toInt()}
    
    println(fact(n) + fact(m))
    
}

fun fact(num:Int):Int{
    var ans = 1
    var iNum = num
    var iPi = 2
    
    while(iPi >= 1){
        ans *= iNum
        
        iNum -= 1
        iPi -=1
    }
    
    return ans / 2
}


Measured memory_bytes: 37796
#include <bits/stdc++.h>
#define f first
#define s second
#define pb push_back
#define mp make_pair
using namespace std;
typedef long long ll;
typedef long double ld;


const int N = 200006;

ll n, k;

ll ans = 0;

vector<ll> a(N);

int main() {

    ios_base::sync_with_stdio(false);
    cin.tie(0);
    
    cin >> n >> k;
    for(int i = 1; i <= n; i++) cin >> a[i];

    sort(a.begin() + 1, a.begin() + 1 + n);

    ll low = -2e18 + 5, high = 2e18 + 5;

    while(low <= high) {

        ll mid = (low + high) / 2;


        ll coun = 0;

        for(int i = 1; i <= n; i++) {

            // fix x as a[i]

            if(a[i] >= 0) {

                int l = 1, r = n, pos = 0;

                while(l <= r) {

                    int x = (l + r) / 2;
                    if (a[i] * a[x] <= mid) {
                        pos = x;
                        l = x + 1;
                    } else r = x - 1;
                }

                coun += pos;

            } 

            if (a[i] < 0) {

                int l = 1, r = n, pos = n + 1;

                while(l <= r) {

                    int x = (l + r) / 2;
                    if (a[i] * a[x] <= mid) {
                        pos = x;
                        r = x - 1;
                    } else l = x + 1;
                }

                coun += n - pos + 1;
            }

            if (a[i] * a[i] <= mid) coun--;
        }

        coun /= 2;

        if (coun < k) {
            low = mid + 1;
        } else {
            ans = mid;
            high = mid - 1;
        }
    }

    cout << ans << '\n';

    return 0; 
}

Measured memory_bytes: 4692
#include <bits/stdc++.h>
using namespace std;
#define int long long
typedef pair<int,int> P;
int INF = 1e18;
int mod = 1e9+7;
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};
signed main() {
    int N,M;
    cin >> N >> M;
    vector<int>A(N+1);
    for(int i = 1; i <= N; i++) {
        cin >> A[i];
        A[i] += A[i-1];
        A[i]%=M;
    }
    sort(A.begin(),A.end());
    int ans = 0;
    int cnt = 1;
    for(int i = 1; i <= N; i++) {
        if(A[i] == A[i-1]) {
            cnt++;
        }
        else {
            ans += cnt*(cnt-1)/2;
            cnt = 1;
        }
    }
    ans += cnt*(cnt-1)/2;
    cout << ans << endl;
}

Measured memory_bytes: 4048
//Keep working hard :)
#include <bits/stdc++.h>
using namespace std;

#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);

const int N = 1e5+5;
int a[N];

void fileIO()
{
        #ifndef ONLINE_JUDGE
        freopen("int.txt","r",stdin);
        freopen("out.txt","w",stdout);
        #endif
}
int main()
{
	IOS;
       // fileIO();
	string s;
	cin >> s;
	s[5] = ' ';s[13] = ' ';
	for(int i = 0;  i < 19; i++)cout << s[i];
	return 0;
}


Measured memory_bytes: 256
<?php

class Operator
{
    public $operations;
    public $n_operations;
    public $keys_operated = array();

    public function __construct()
    {
        fscanf(STDIN, '%d', $this->n_operations);
        $this->operations = new \SplDoublyLinkedList();
        while ($this->n_operations > 0) {
            $word = trim(fgets(STDIN));
            if ($word[0] === 'i') {
                $this->operations->unshift(substr($word, 7));
            } elseif ($word[6] === 'F') {
                $this->operations->shift();
            } elseif ($word[6] === 'L') {
                $this->operations->pop();
            } else {
                foreach ($this->operations as $key => $element) {
                    if ($element === substr($word, 7)) {
                        $this->operations->offsetUnset($key);
                        break;
                    }
                }
            }
            $this->n_operations -= 1;
        }
    }

    public function getAnswer()
    {
        while (1) {
            if (count($this->operations) > 0) {
                $keys_operated[] = $this->operations->shift();
            } else {
                break;
            }
        }
        echo implode(' ', $keys_operated), PHP_EOL;
    }
}

$operator = new Operator();
$operator->getAnswer();



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

long long N;
bool check753(long long S) {
    int A = 0, B = 0, C = 0;
    long long check = S;
    while (check != 0) {
        if (check % 10 == 3) A++;
        else if (check % 10 == 5) B++;
        else if (check % 10 == 7) C++;
        check /= 10;
    }
    if (A > 0 && B > 0 && C > 0) return true;
    else return false;
}
long long dfs(long long S) {
    if (S > N) return 0;
    int cnt;
    if (check753(S)) cnt = 1;
    else cnt = 0;
    cnt += dfs(10 * S + 3) + dfs(10 * S + 5) + dfs(10 * S + 7);
    return cnt;
}

int main() {
    cin >> N;
    cout << dfs(0) << endl;
}

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

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

  int tmp;
  if (a > b) {
    tmp = b;
    b = a;
    a = tmp;
  }

  if (b > c) {
    tmp = c;
    c = b;
    b = tmp;
  }

  if (a > b) {
    tmp = b;
    b = a;
    a = tmp;
  }

  cout << a << " " << b << " " << c << endl;

  return 0;

}



Measured memory_bytes: 3084
#include <bits/stdc++.h>
#define FAST ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define MAXX 100005
#define PI 3.14159265358979323846264338327950
#define ll signed long long int
using namespace std;
ll t , n, k,   y = 2, m,h,s , ans =0;
ll a[MAXX] = {0}, b, c[MAXX];
vector<ll> adj[MAXX];
bool used[MAXX];


signed main()
{
	FAST;
	cin >> t >> n;
	if((t+n )% 2 == 0){
		cout << (t+n )  /2;
	}
	else{
		cout << "IMPOSSIBLE";
	}
}

Measured memory_bytes: 2560
use proconio::{input, marker::Chars};
const MOD: u32 = 1_000_000_007;
fn main() {
	input!(h: usize, w: usize, grid: [Chars; h]);
	let mut dp = vec![vec![0; w]; h];
	dp[0][0] = 1;
	for i in 1..h { dp[i][0] = if grid[i][0] == '.' { dp[i-1][0] } else { 0 } };
	for j in 1..w { dp[0][j] = if grid[0][j] == '.' { dp[0][j-1] } else { 0 } };
	for i in 1..h {
		for j in 1..w {
			dp[i][j] = if grid[i][j] == '.' { (dp[i-1][j] + dp[i][j-1]) % MOD } else { 0 };
		}
	}

	println!("{}", dp[h-1][w-1]);
}

Measured memory_bytes: 10812
n, m = map(int, input().split())
index=0
listL=[]
while index < n:
    listA=list(map(int, input().split()))
    del listA[0]
    if index==0:
        listL=listA
    else:
        index2=0
        while index2 < len(listL):
            if listL[index2] in listA:
                pass
            else:
                del listL[index2]
                index2-=1
            index2+=1
        if len(listL)==0:
            print(0)
            break
    index+=1
if index==n:
    print(len(listL))

Measured memory_bytes: 3064
#include <cmath>
#include <cstdio>
#include <vector>
#include <iostream>
#include <algorithm>
#include <unordered_map>
#include <cstring>
using namespace std;
typedef long long ll;
const int maxn = 100;
const int mod = 1000000007;
const int maxm = 4;

int f[maxn][maxm][2];
bool vis[maxn][maxm][2];
int bit[maxn],cbit;
int dfs(int x,int y,int z) {
    if(x==-1)return y==0;
    if(vis[x][y][z])return f[x][y][z];
    int lim=1;
    if(z&&!bit[x])lim=0;
    for(int j=0; j<=lim; j++)
        for(int i=0; i<=2&&i<=y+j; i++) {
            int ny = (y+j-i)*2;
            if(ny>=maxm)continue;
            f[x][y][z]+=dfs(x-1,ny,z&&j==lim);
            if(f[x][y][z]>=mod)f[x][y][z]-=mod;
        }
    vis[x][y][z]=1;
    return f[x][y][z];
}

int main() {
 //   freopen("in.cpp","r",stdin);
    ll n;
    while(cin>>n) {
        cbit=0;
        while(n) {
            bit[cbit++]=n&1;
            n>>=1;
        }
        memset(vis,0,sizeof(vis));
        memset(f,0,sizeof(f));
        cout<<dfs(cbit-1,0,1)<<endl;
    }
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <math.h>

struct City{
  long num;
  long pref;
  long year;
  long id;
  
  City(long nin, long pin, long yin){
    num = nin;
    pref = pin;
    year = yin;
  }
};

bool cmpyear(const City &a, const City &b){
  return a.year < b.year;
}

bool cmpnum(const City &a, const City &b){
  return a.num < b.num;
}

using namespace std;
int main() {
	int n, m;
	cin >> n >> m;
	
	vector<City> city;
	
	long p,y; 
	for(int i = 0; i < m; i++){
	  cin >>p >>y;
	  city.push_back(City(i,p,y));
	}
	
	sort(city.begin(), city.end(), cmpyear);
	
	int prefcity[n+1];
	for(int i = 0; i <= n; i++) prefcity[i] = 0;
	
	for(int i = 0; i < m; i++){
	  prefcity[city[i].pref]++;
	  city[i].id = city[i].pref*1000000 + prefcity[city[i].pref];
	}
	
	sort(city.begin(), city.end(), cmpnum);
	
	for(int i = 0; i < m; i++){
		printf("%012ld\n", city[i].id);
	}
}

Measured memory_bytes: 6512
Q, H, S, D = [int(_) for _ in input().split()]
N = int(input())

p1 = min(4 * Q, 2 * H, S)
p2 = min(2 * S, D)
print(min([p2 * (N // 2) + p1 * (N % 2), p1 * N]))


Measured memory_bytes: 3060
#include<iostream>
#include<vector>
#include<queue>
#include<stack>
#include<string>
#include<cmath>
#include<algorithm>
#include<bitset>
#include<map>
#include<functional>
#include<set>

#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,0,n)
#define RFOR(i,r,n) for(ll i=(ll)(n-1);i>=r;i--)
#define ALL(x) x.begin(),x.end()
#define RALL(x) x.rbegin(),x.rend()
#define LOWER(a,x) lower_bound(ALL(a), x) - a.begin() - 1;
#define COUNT(a,x)  upper_bound(ALL(a), x) - lower_bound(ALL(a), x);
#define MCOUNT(a,x,y) upper_bound(ALL(a), y) - lower_bound(ALL(a), x);
#define scan(x) scanf("%lld",&x);
#define inf 5555555555555555555
#define mod 1000000007
#define pi 3.14159265358979323846
#define pb push_back
#define F first
#define S second
typedef long long int ll;
typedef long double ld;
typedef vector<ll> vll;
typedef pair<ll, ll> pll;
typedef vector<pll> vpll;
typedef map<ll, ll> MAP;
typedef set<ll> SET;
ll n = 0, m = 0, ans = 0, sum = 0, cnt = 0, tmp = 0, ma = 0, mi = 0;
string s;
bool ok, flag;
ll dx[4] = { 1,-1,0,0 }, dy[4] = { 0,0,1,-1 };
ll ddx[9] = { 1,-1,0,0,1,1,-1,-1,0 }, ddy[9] = { 0,0,1,-1,1,-1,1,-1,0 };
#pragma endregion
#define MAX 111111

ll cou(string ss) {
  ll x = ss.length();
  ll ret = 0;
  rep(i, x) {
	tmp = ss[i] - '0';
	ret += tmp;
  }
  return ret;
}

int main(void) {
  ll a, b, c;
  ans = inf;
  cin >> n;
  FOR(i, 1, n) {
	a = i; b = n - i; c = 0;
	s = to_string(a);
	c += cou(s);
	s = to_string(b);
	c += cou(s);
	ans = min(ans, c);
  }
  cout << ans << endl;

  return 0;
}

Measured memory_bytes: 256
//Problem B
#include<bits/stdc++.h>
using namespace std;
#define ll long long
const int N=100005;
int n,a[N],b[N],c[N],t[N],m;
ll nd;
void add(int v){/*printf("add %d\n",v);*/for(;v<=m;v+=v&-v)++t[v];}
int query(int v){/*printf("query %d=",v);*/int a=0;for(;v;v-=v&-v)a+=t[v];/*printf("%d\n",a);*/return a;}
int chk(int v){b[0]=0;
    for(int i=1;i<=n;i++){
        b[i]=b[i-1];
        if(v<=a[i])++b[i];else --b[i];
    }
    //if(v<11){for(int i=0;i<=n;i++)printf("%d ",b[i]);printf("\n");}
    for(int i=0;i<=n;i++)c[i]=b[i];
    sort(c,c+n+1);
    m=unique(c,c+n+1)-c;
    for(int i=0;i<=n;i++)b[i]=lower_bound(c,c+m+1,b[i])-c+1;
    //if(v<11)
    //{for(int i=0;i<=n;i++)printf("%d ",b[i]);printf(" %d %d\n",m,v);}
    memset(t,0,sizeof(t));
    ll gt=0;
    for(int i=0;i<=n;i++)gt+=query(b[i]),add(b[i]);//if(v<11){printf("%lld %lld\n",gt,nd);printf("\n");}
    return nd<=gt;
}
int main(){
    scanf("%d",&n);
    nd=((long long)n*(n+1))>>1;
    nd=(nd+1)>>1;
    for(int i=1;i<=n;i++)scanf("%d",&a[i]);
    int l=1,r=1000000007,ans=0;
    //for(int i=10;i<41;i+=10)chk(i);
    while(l<=r){
        int mid=(l+r)>>1;
        if(chk(mid))ans=mid,l=mid+1;
        else r=mid-1;
    }
    printf("%d",ans);
    return 0;
}

Measured memory_bytes: 1792
import heapq

n,m = map(int, input().split())
h_list = list(map(int, input().split()))

ten = [[] for _ in range(n+1)]
for i in range(m):
    a1,a2 = map(int,input().split())
    ten[a1].append(a2)
    ten[a2].append(a1)

cnt = 0
for i in range(1,n+1):

    rel = ten[i]
    if len(rel) == 0:
        cnt += 1
        continue

    rel = list(map(lambda x: (-h_list[x-1], x), set(rel)))
    heapq.heapify(rel)
    max_ten = heapq.heappop(rel)
    max_height = -max_ten[0]

    if max_height < h_list[i-1]:
        cnt += 1

print(cnt)

Measured memory_bytes: 37256
#include<stdio.h>
void trance(int A[], int N)
{
	int i;
	for(i=0;i<N;i++)
		{
			if(i>0)printf(" ");
			printf("%d", A[i]);
		}
	printf("\n");
}

void insertionSort(int A[], int N)
{
	int j,i,v;
	for (i = 1; i < N;i++)
	{
		v=A[i];
		j=i-1;
		while(j>=0 && A[j]>v)
		{
			A[j+1] = A[j];
			j--;
		}
		A[j+1]= v;
		trance(A,N);
	}
}

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

	scanf("%d",&N);
	for(i=0;i<N;i++)
	{
		scanf("%d",&A[i]);
	}

	trance(A,N);
	insertionSort(A,N);

	return 0;
}

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

using namespace std;

int main(){

	int n, m, a, b;
	int A[100005];
	int color[100005];

	for(int i=0; i<100005; i++){
		A[i] = 1;
		color[i] = 0;
	}
	
	scanf("%d %d", &n, &m);

	color[1] = 1;

	for(int i=0; i<m; i++){
		scanf("%d %d", &a, &b);
		if(A[a]>0){
			A[a]--;
			A[b]++;
			color[b] = color[a] ? 1:color[b];
			if(!A[a]){
				color[a] = 0;
			}
		}
	}

	int cont=0;
	for(int i=1; i<=n; i++){
		if(color[i] && A[i]>0){
			cont++;
		}
	}

	printf("%d\n", cont);

	return 0;
}

Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0; i<(n) ;i++)
#define pb push_back
#define all(v) (v).begin(),(v).end()
#define fi first
#define se second
#define sz(x) ((int)(x).size())
using ll=long long;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
#define MOD  1000000007
const ll INF=1e18;
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; }



int main(int argc, char const *argv[]) {
  int n;
  cin >> n;
  rep(i,50000){
    if((int)(i*1.08)==n){
      cout << i << endl;
      return 0;
    }
  }
  cout << ":(" << endl;
  return 0;
}


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

namespace AtCoder.B
{
    public class Program
    {
        public static void Main() { var r = GetResult(); Debug.WriteLine(r); Console.Write(r); }

        private static object GetResult()
        {
            var (H, W) = Read2Longs();
            var s = new long[H + 2, W + 2];
            for (var i = 0; i < H; i++)
            {
                var text = ReadText();
                for (var j = 0; j < W; j++)
                {
                    if (text[j] == '#')
                    {
                        s[i + 1, j + 1] = -100;
                        s[i, j] += 1;
                        s[i, j + 1] += 1;
                        s[i, j + 2] += 1;
                        s[i + 1, j] += 1;
                        s[i + 1, j + 2] += 1;
                        s[i + 2, j] += 1;
                        s[i + 2, j + 1] += 1;
                        s[i + 2, j + 2] += 1;
                    }
                }
            }
            var output = new StringBuilder();
            for (var i = 0; i < H; i++)
            {
                var r = new char[W];
                for (var j = 0; j < W; j++)
                {
                    if (s[i + 1, j + 1] < 0)
                    {
                        r[j] = '#';
                    }
                    else
                    {
                        r[j] = char.Parse(s[i + 1, j + 1].ToString());
                    }
                }
                output.AppendLine(new string(r));
            }
            return output.ToString().TrimEnd();
        }

        #region Console.Read

        public static string ReadText() { return Console.ReadLine(); }
        public static List<string> ReadTexts() { return Console.ReadLine().Split(' ').ToList(); }
        public static long ReadLong() { return long.Parse(Console.ReadLine()); }
        public static (long, long) Read2Longs() { var ls = ReadLongs(); return (ls[0], ls[1]); }
        public static (long, long, long) Read3Longs() { var ls = ReadLongs(); return (ls[0], ls[1], ls[2]); }
        public static (long, long, long, long) Read4Longs() { var ls = ReadLongs(); return (ls[0], ls[1], ls[2], ls[3]); }
        public static (long, long, long, long, long) Read5Longs() { var ls = ReadLongs(); return (ls[0], ls[1], ls[2], ls[3], ls[4]); }
        public static List<long> ReadLongs() { return Console.ReadLine().Split(' ').Select(x => long.Parse(x)).ToList(); }

        #endregion
    }
}


Measured memory_bytes: 27840
from math import ceil
from heapq import heapify, heappop, heappush
N,M = map(int, input().split())
A = list(map(lambda x: int(x)*(-1), input().split()))
heapify(A)
while M>0:
    temp = heappop(A)
    heappush(A, temp/2)
    M-=1
print(-sum(map(ceil, A)))

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

using namespace std;

vector<bool> isPrime(10001, true);
vector<int> primeNumbers;

int main(){
    isPrime[0] = isPrime[1] = false;
    for(int i = 2; i * i <= 10000; i += 2){
        if(!isPrime[i]) continue;
        for(int j = i * i; j <= 10000; j += i){
            isPrime[j] = false;
        }
        i -= i == 2;
    }
    int n, ans = 0;
    for(int i = 0; i <= 10000; i++){
        if(isPrime[i]){
            primeNumbers.push_back(i);
        }
    }
    cin >> n;
    while(n--){
        int a;
        cin >> a;
        if(a <= 1e4){
            ans += isPrime[a];
            continue;
        }
        ans++;
        for(int i = 0; i < primeNumbers.size() && primeNumbers[i] * primeNumbers[i] <= a; i++){
            if(a % primeNumbers[i] == 0){
                ans--;
                break;
            }
        }
    }
    cout << ans << "\n";
}


Measured memory_bytes: 3128
#pragma target("avx")
#pragma optimize("O3")
#include<bits/stdc++.h>
using ll = int_fast64_t;
using P = std::pair<ll,ll>;
using PP = std::pair<ll,P>;
using V = std::vector<ll>;
template<typename T> using pq = std::priority_queue<T>;
template<typename T> using rpq = std::priority_queue<T, std::vector<T>, std::greater<T>>;

#define REP(i,b,e) for(ll i=b; i<e; i++)
#define ALL(vec) vec.begin(),vec.end()
#define PRINT(vec) printf("[ ");for(auto &i:vec)printf("%ld ",i);puts("]");
#define SCAN(vec) for(auto &i:vec)scanf("%ld",&i)
#define fi first
#define se second

const int MOD = 1e9+7;
const ll INF = 1e18;
int dx[] = {0, 1, 0, -1, 1, 1, -1, -1}, dy[] = {1, 0, -1, 0, 1, -1, -1, 1};

int main(){
	ll a;
	char b[5];
	scanf("%ld %s", &a, b);
	printf("%ld\n", a * (b[0] - '0') + a * (10*(b[2] - '0') + b[3] - '0') / 100);
	return 0;
}



Measured memory_bytes: 3832
#include <bits/stdc++.h>
#define rep(i, n) for (ll(i) = 0; (i) < (n); (i)++)
#define all(x) (x).begin(), (x).end()
#define print(x) cout << (x) << endl;

typedef long long ll;
const ll INF = 99999999999999;
const ll MOD = 1000000007;

ll gcd(ll a, ll b)
{
    if (b == 0)
        return a;
    return gcd(b, a % b);
}
ll lcm(ll number1, ll number2)
{
    return number1 * number2 / gcd(number1, number2);
}
template <class T>
bool contain(const std::string &s, const T &v)
{
    // contain(to_string(N), '3')
    return s.find(v) != std::string::npos;
}

int ctoi(char c)
{
    if (c >= '0' && c <= '9')
        return c - '0';
    return 0;
}
using namespace std;

void transpose(vector<vector<char>> &b)
{
    if (b.size() == 0)
        return;

    vector<vector<char>> trans_vec(b[0].size(), vector<char>());

    for (int i = 0; i < b.size(); i++)
    {
        for (int j = 0; j < b[i].size(); j++)
        {
            trans_vec[j].push_back(b[i][j]);
        }
    }

    b = trans_vec; // <--- reassign here
}
int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    string s, ans = "Yes";
    cin >> s;
    ll n = s.size();
    rep(i, n)
    {
        if ((i + 1) % 2 == 1 && s[i] == 'L')
        {
            ans = "No";
        }
        if ((i + 1) % 2 == 0 && s[i] == 'R')
        {
            ans = "No";
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
gets
T, A = gets.split.map(&:to_i)
H = gets.split.map(&:to_i)
X = (T - A) * 1000
puts H.map{|v|v*6}.map{|v|v-X}.map(&:abs).map.with_index{|v,i|[v,i+1]}.sort_by{|v|v[0]}.first[1]


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

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

using Graph = vector<vector<int>>;

ll calc(ll a, ll b, ll p){//aのb乗をpで割った余り
  if(b == 0) return 1;

  else if(b%2 == 0){
    ll d = calc(a,b/2,p);
    return (d*d)%p;
  }
  else if(b%2 == 1){
    return (a * calc(a,b-1,p))%p;
  }
}

typedef pair<int,int> P;

bool is_prime(int n){//nが素数であるかどうか判定 iで割り切れると素数でない
    if(n == 1) return false;//1は例外
    for(int i = 2;i*i <= n;i++){
        if(n%i == 0) return false;
    }
    
    return true;
}
int factorial(int a){
  int res = 1;
  while(a){
    res *= a;
    a--;
  }
  return res;
}

int main(){
  vector<int> v(3);
  rep(i,3){
    cin >> v[i];
  }
  int ans = 1000000;
  for(int i = 0;i<3;i++){
    for(int j = i+1;j<3;j++){
      ans = min(ans,v[i] + v[j]);
    }
  }
  cout << ans << endl;
 }

Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main(){
  int n;
  while(cin >> n, n){
    int dp[(1<<(17))] = {}, M, L, ans = 0;
    for(int i = 0; i < n; ++i){
      cin >> M >> L;
      int s, e, t = 0;
      for(int j = 0; j < M; ++j){
        cin >> s >> e;
        s -= 6;
        e -= 6;
        t |= (((1<<(e-s))-1)<<s);
      }
      for(int j = 0; j < (1<<17); ++j){
        if(!(j&t)){
          dp[j|t] = max(dp[j|t],dp[j]+L);
        }
        ans = max(ans,dp[j]);
      }
    }
    cout << ans << endl;
  }
  return 0;
}



Measured memory_bytes: 3500
#include<iostream>
#include<algorithm>
#include<vector>
#include<string>
#include<set>
#include<queue>
#include<stack>
#include<bitset>
#include<functional>
#include<map>
#include <iomanip>
#include <limits>
#include<unordered_set> 
#include<cmath>
using namespace std;
//long long p = 998244353;
long long p = 1000000007;
#define int long long
#define vel vector<long long>
#define vvel vector<vel>
#define rep(i,n) for(int i=0;i<n;i++)
#define sor(v) sort(v.begin(),v.end())
#define mmax(a,b) a=max(a,b)
#define mmin(a,b) a=min(a,b)
#define mkp make_pair
#define pin pair<int,int>
#define qin pair<int,pin>
#define V vector
#define Endl endl
#define veb vector<bool>
#define fcout cout << fixed << setprecision(15)
#define rev(s) reverse(s.begin(),s.end())
#define lower(h,val) lower_bound(h.begin(),h.end(),val)-h.begin()
#define upper(h,val) upper_bound(h.begin(),h.end(),val)-h.begin()
int max_kai = 150000;
vel kai(max_kai, 1);
vel inv_kai;
int rui(int a, int n) {
    if (n == 0) { return 1; }
    int x = rui(a, n / 2);
    x *= x; x %= p;
    if (n % 2 == 1) { x *= a; x %= p; }
    return x;
}
int inv(int a) { return rui(a, p - 2); }
void make_kai() {
    for (int i = 1; i < max_kai; i++) { kai[i] = kai[i - 1] * i; kai[i] %= p; }
    inv_kai = kai;
    rep(i, max_kai) { inv_kai[i] = inv(kai[i]); }
}
int nCr(int n, int r) {
    if (n < 0 || r<0 || r>n) { return 0; }
    int a = kai[n] * inv_kai[r]; a %= p;
    a *= inv_kai[n - r]; a %= p;
    return a;
}
vel pa;
int root(int x) {
    if (pa[x] == -1) { return x; }
    int ans = root(pa[x]); pa[x] = ans;
    return ans;
}
void marge(int x, int y) {
    x = root(x);
    y = root(y);
    if (x != y) { pa[x] = y; }
}
int gcd(int x, int y) {
    if (x < y) { return gcd(y, x); }
    if (y == 0) { return x; }
    return gcd(y, x % y);
}
#define pd pair<int,double>
#define ved vector<double>
bool is_in(pin lr, int x) {
    return (lr.first <= x) && (x < lr.second);
}
signed main() {
    int n, m; cin >> n>> m; n+=2;
    V<V<pin>> lr(n, V<pin>(4,mkp(0,n)));//x番目に現れるものの範囲
    rep(i, m) {
        int l, r; cin >> l >> r;
        int x; cin >> x;
        if (r == 1 && x != 1) { cout << 0 << endl; return 0; }
        mmax(lr[r][x-1].first, l);
        mmin(lr[r][x].second, l);
    }
    V<vvel> dp(n, vvel(n, vel(n, 0)));//最初、2番目、3番目
    dp[1][0][0] = 3;
    for (int i = 1; i < n-1; i++) {
        rep(j, i) {
            rep(k, j + 1) {
                if (is_in(lr[i][1], j) && is_in(lr[i][2], k)) {
                    dp[i + 1][j][k] += dp[i][j][k];
                    dp[i + 1][j][k] %= p;
                    dp[i + 1][i][k] += dp[i][j][k];
                    dp[i + 1][i][k] %= p;
                    dp[i + 1][i][j] += dp[i][j][k];
                    dp[i + 1][i][j] %= p;
                }
            }
        }
    }
    int ans = 0;
    rep(j, n) {
        rep(k, n) {
            ans += dp[n - 1][j][k]; ans %= p;
        }
    }
    ans *= inv(3);
    ans %= p;
    cout << ans << endl;
}


Measured memory_bytes: 220928
#include <iostream>
#include <cstdio>
using namespace std;
int n; 
int a[1000];
int b[1000];
int main() {
    int ant, flag = 0;
    scanf("%d", &n);
    for(int i = 1; i <= n; i++)  {
        scanf("%d", &a[i]);
        if(a[i] > i)
            flag = 1;
    }
    if(flag) {
        printf("-1\n");
        return 0;
    }
    int len = n;
    for(int i = 1; i <= n; i++) {
        flag = 0;
        for(int j = n; j >= 1; j--) {
            if(a[j] == 0) continue;
            ant = 0;
            for(int k = 1; k <=j; k++)
                if(a[k]) ant++;
            if(ant == a[j]) {
                b[len] = a[j];
                a[j] = 0;
                break;
            }
        }
        len--;
    }
    for(int i = 1; i <= n; i++)
        printf("%d\n", b[i]);
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main() {
  long int n;
  cin>>n;
  vector<long int> a(n);
  for(long int i;i<n;i++){
    cin>>a.at(i);
  }
  long int x=a.at(0);
  for(long int i=0;i<n;i++){
    x=__gcd(a.at(i),x);
  }
  cout<<x<<endl;
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
#define endl '\n';

typedef long long ll;

using namespace std;

const string YES = "";
const string NO  = "";

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

    int x, y;

    cin >> x >> y;

    cout << x + y / 2 << endl;

    return 0;
}



Measured memory_bytes: 256
case class store(val a: Long, val b: Int)

object Main extends App {
	var Array(n,m) = scala.io.StdIn.readLine.split(" ").map(_.toInt)

	var List = new Array[store](n)

	for(i<-0 until n){
		val Array(tp1, tp2) = scala.io.StdIn.readLine.split(" ")
		List(i) = store(tp1.toLong, tp2.toInt)
	}

	List = List.sortBy(_.a)

	var ans = 0L
	var tq = 0
	while(m > 0){
		val L1 = List(tq).a
		val L2 = List(tq).b

		if( m - L2 > 0){
			m = m - L2
			tq = tq + 1
			ans = ans + L1*L2
		}else{
			ans = ans + L1*m
			m = -1
		}
	}

	println(ans)


}

Measured memory_bytes: 55960
#include<iostream>
#include<algorithm>
#include<math.h>
#include<vector>
#include<map>
#include<set>

using namespace std;
using ll = long long;

const int INF = 1e9;
const int MOD = 1e9+7;
const ll LINF = 1e18;
const double PI = acos(-1.0);

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

int main() {
    int x; cin >> x;
    int a; cin >> a;

    if (x < a) cout << 0 << endl;
    else cout << 10 << endl;
    return 0;
}


Measured memory_bytes: 256
// abc050_b
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<map>
#include<set>
#include<unordered_map>
#include<utility>
#include<cmath>
#include<random>
#include<cstring>
#include<queue>
#include<stack>
#include<bitset>
#include<cstdio>
#include<sstream>
#include<iomanip>
#include<assert.h>
#include<typeinfo>
#define loop(i,a,b) for(int i=a;i<b;i++)
#define rep(i,a) loop(i,0,a)
#define FOR(i,a) for(auto i:a)
#define pb push_back
#define all(in) in.begin(),in.end()
#define shosu(x) fixed<<setprecision(x)
#define show1d(v) rep(i,v.size())cout<<" "<<v[i];cout<<endl<<endl;
#define show2d(v) rep(i,v.size()){rep(j,v[i].size())cout<<" "<<v[i][j];cout<<endl;}cout<<endl;
using namespace std;
typedef long long ll;
typedef int Def;
typedef pair<Def,Def> pii;
typedef vector<Def> vi;
typedef vector<vi> vvi;
typedef vector<pii> vp;
typedef vector<vp> vvp;
typedef vector<string> vs;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef pair<Def,pii> pip;
typedef vector<pip>vip;
template<typename A,typename B>bool cmin(A &a,const B &b){return a>b?(a=b,true):false;}
template<typename A,typename B>bool cmax(A &a,const B &b){return a<b?(a=b,true):false;}
const double PI=acos(-1);
const double EPS=1e-9;
Def inf = sizeof(Def) == sizeof(long long) ? 2e18 : 1e9+10;
int dx[]={0,1,0,-1};
int dy[]={1,0,-1,0};
int main(int argc, char *argv[])
{
  int n,m,p,x,ans=0;
  cin>>n;
  vi t(n);
  rep(i, n) {
    cin>>t.at(i);
  }
  cin>>m;
  rep(i, m) {
    cin>>p>>x;
    ans=0;
    rep(j, n) {
      if (j == p-1) {
        ans+=x;
      } else {
        ans+=t.at(j);
      }
    }
    cout<<ans<<endl;
  }

  return 0;
}


Measured memory_bytes: 256
//Serene
#include<algorithm>
#include<iostream>
#include<cstring>
#include<cstdlib>
#include<cstdio>
#include<cmath>
using namespace std;
#define ll long long
#define db double
#define For(i,a,b) for(int i=(a);i<=(b);++i)
#define Rep(i,a,b) for(int i=(a);i>=(b);--i)
const int maxn=2e5+7,maxt=23;
const ll mod=1e9+7;
int n,W,p[maxn],st[2][maxn][maxt],TOT;

char cc;ll ff;
template<typename T>void read(T& aa) {
	aa=0;ff=1; cc=getchar();
	while(cc!='-'&&(cc<'0'||cc>'9')) cc=getchar();
	if(cc=='-') ff=-1,cc=getchar();
	while(cc>='0'&&cc<='9') aa=aa*10+cc-'0',cc=getchar();
	aa*=ff;
}

struct Node{
	int x,v;
	bool operator < (const Node& b) const{return x<b.x;}
}node[maxn];

struct Li{
	int l,r;
	Li(){}
	Li(int l,int r):l(l),r(r){}
	bool operator < (const Li& b) const{return r==b.r? l>b.l:r<b.r;}
}li[maxn];

int getl(int x) {
	int pos=1;
	Rep(i,W,0) if(st[0][pos][i]<x) pos+=(1<<i);
	return pos;
}

int getr(int x) {
	int pos=n;
	Rep(i,W,0) if(st[1][pos][i]>x) pos-=(1<<i);
	return pos;
}

ll sum[4*maxn],ql,qr,qx;
void ud(int pos) {sum[pos]=(sum[pos<<1]+sum[pos<<1|1])%mod;}
void pd(int pos) {
	if(sum[pos]!=0) return;
	sum[pos<<1]=0; sum[pos<<1|1]=0;
}
 
void chge(int pos,int l,int r) {
	if(l>=ql&&r<=qr) {
		sum[pos]=qx;
		return;
	}
	int mid=(l+r)>>1; pd(pos);
	if(ql<=mid) chge(pos<<1,l,mid);
	if(qr>mid) chge(pos<<1|1,mid+1,r);
	ud(pos);
}

int main() {
	read(n); int x,y;
	For(i,1,n) {
		read(node[i].x);
		read(node[i].v);
		p[i]=node[i].v;
	}
	sort(p+1,p+n+1);
	sort(node+1,node+n+1);
	For(i,1,n) {
		node[i].x=i;
		node[i].v=lower_bound(p+1,p+n+1,node[i].v)-p;
	}
	For(i,1,n) st[0][i][0]=st[1][i][0]=node[i].v;
	for(W=1;(1<<W)<=n;++W) {
		x=(1<<W-1);
		For(i,1,n-x) st[0][i][W]=max(st[0][i][W-1],st[0][i+x][W-1]);
		For(i,n-x+1,n) st[0][i][W]=st[0][i][W-1];
		Rep(i,n,x+1) st[1][i][W]=min(st[1][i][W-1],st[1][i-x][W-1]);
		Rep(i,x,1) st[1][i][W]=st[1][i][W-1];
	} --W;
	For(i,1,n) {
		x=getl(node[i].v);
		y=getr(node[i].v);
		li[i]=Li(x,y);
	}
	sort(li+1,li+n+1);
	For(i,1,n) p[i]=0;
	For(i,1,n) p[li[i].r]=max(p[li[i].r],li[i].l);
	For(i,2,n) p[i]=max(p[i],p[i-1]);
	TOT=n+1; ql=qr=1; qx=1; chge(1,1,TOT);
	For(i,1,n) {
		ql=qr=i+1; qx=sum[1];
		chge(1,1,TOT);
		ql=1; qr=p[i]; qx=0;
		if(ql<=qr) chge(1,1,TOT);
	}
	printf("%lld\n",sum[1]%mod);
	return 0;
}


Measured memory_bytes: 46336
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
#define rep(i,n) for(ll i=0;i<(ll)(n);i++)
#define all(a)  (a).begin(),(a).end()
#define pb emplace_back
#define INF (1e9+1)

struct edge{int from,to,cost;};

class UF{
private:
	vector<int> par;
public:
	UF(int __size):par(__size){ rep(i,__size)par[i]=i; }
	
	int find(int x){
		if(par[x]==x) return x;
		else return par[x]=find(par[x]);
	}
	
	void unite(int x,int y){ par[find(y)]=find(x); }
};

int MSA(int r, int v, vector<edge> edges){
	int ret = 0;
	UF uf(v);
	vector<priority_queue<pii,vector<pii>,greater<pii>>> vpq(v);
	vector<int> lazy(v,0), state(v,0);
	
	for(auto e:edges){
		vpq[e.to].push(pii(e.cost,e.from));
	}
	state[r] = 2;
	
	rep(start,v){
		int cur = uf.find(start);
		if(state[cur]!=0)continue;
		
		vector<int> processing, from(v,-1), from_cost(v,0);
		
		while(state[cur]!=2){
			processing.pb(cur);
			state[cur]=1;
			if( vpq[cur].empty() )return INF;
			
			pii e = vpq[cur].top(); vpq[cur].pop();
			from[cur] = e.second;
			from_cost[cur] = e.first+lazy[cur];
			if(cur==from[cur])continue;
			
			ret+=from_cost[cur];
			
			if(state[ from[cur] ]==1){
				int p=cur;
				do{
					lazy[p] -= from_cost[p];
					
					if(p!=cur){
						uf.unite(cur,p);
						while(vpq[p].size()){
							pii t = vpq[p].top();vpq[p].pop();
							t.first+=lazy[p]-lazy[cur];
							t.second = uf.find(t.second);
							vpq[cur].push(t);
						}
					}
					p = uf.find(from[p]);
				}while(p!=cur);
			}else{
				cur = from[cur];
			}
		}
		for(auto elm:processing)state[elm]=2;
	}
	return ret;
}

int main(){
	int e,v;
	int r;
	cin>>v>>e>>r;

	vector<edge> edges;
	rep(i,e){
		int s,t,w;
		cin>>s>>t>>w;
		edges.pb(edge{s,t,w});
	}
	cout<<MSA(r,v,edges)<<endl;
}

Measured memory_bytes: 3244
#include<stdio.h>
int main()
{
    int n,d,count=0;
    long double x,y;
    double r;
    scanf("%d %d",&n,&d);
    for(int i=0;i<n;i++)
    {
        scanf("%Lf %Lf",&x,&y);
        r=(double)sqrt((x*x)+(y*y));
        if(r<=d)
        {
            count++;
        }
        else { continue;}
    }
    printf("%d\n",count);
    return 0;

}


Measured memory_bytes: 2208
#include<iostream>
#include<cstdio>
#include<vector>
#include<algorithm>
#include<cstring>
#include<stdio.h>
#include<fstream>
#include<stdlib.h>
#include<math.h> 
#include<queue>
#include<string.h>
#include<stack>


using namespace std;

int par[100001];
int r[100001];

void init(int n){
	for(int i=0;i<n;i++){
		par[i]=i;
		r[i]=0;
	}
}


int root(int x){
	if(par[x]==x){
		return x;
	}
	else {
		return par[x]=root(par[x]);
	}
}

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


void unite(int x,int y){
	x=root(x);
	y=root(y);
	if(x==y)return;

	if(r[x]<r[y]){
		par[x]=y;
	}
	else{
		par[y]=x;
		if(r[x]==r[y])r[x]++;
	}
}

int main(){
	int n,q;
	cin>>n>>q;
	init(n);
	int com;
	int x,y;
	for(int i=0;i<q;i++){
		cin>>com>>x>>y;
		if(com==0){
			if(same(x,y))continue;
			unite(x,y);
		}
		else if(com==1){
			if(same(x,y))cout<<"1"<<endl;
			else cout<<"0"<<endl;
		}
	}
}






Measured memory_bytes: 3200
# include <bits/stdc++.h>
# define INF 1e9
using namespace std;

int main(){

  int N;
  cin >> N;
  string S;
  cin >> S;

  map<char, int> d, d1;
  for(int i=0; i < S.size();++i){
    if(d.find(S[i]) == d.end()) d[S[i]] = 1;
    else d[S[i]]++;
  }

  int ans = 0;
  for(int i=0; i<S.size()-1;++i){
    if(d1.find(S[i]) == d1.end()) d1[S[i]] = 1;
    else d1[S[i]]++;

    int count = 0;
    for(auto c: d1){
      if(d[c.first] > d1[c.first]) count++;
    }
    ans = max(ans, count);
  }

  cout << ans << endl;
}

Measured memory_bytes: 256
import math
N=int(input())
A=[0]*N
B=[0]*N
for i in range(N):
	A[i],B[i]=map(int,input().split())
total=0
for i in range(N):
  for j in range(i+1,N):
    total+=((A[i]-A[j])**2+(B[i]-B[j])**2)**0.5
    
    

print(total/N*2)

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

typedef long long ll;
#if 0
蜷郁ｨ・
0,0 L
蜷郁ｨ・
1,0 L
蜷郁ｨ・
2,0 W
1,1 L
蜷郁ｨ・
3,0 W
2,1 L
蜷郁ｨ・
4,0 W
3,1 W
2,2 L
蜷郁ｨ・
5,0 W
4,1 W
3,2 L
蜷郁ｨ・
6,0 W
5,1 W
4,2 W
3,3 L
#endif

int main(void)
{
	ll X, Y;
	cin >> X >> Y;
	if(X - Y == 0 || X - Y == -1 || X - Y == 1){
		cout << "Brown" << endl;
	}else{
		cout << "Alice" << endl;
	}
	return 0;
}


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

using namespace std;

int main()
{
	string s;
	cin >> s;
	vector<int> flood;
	int count = 0;
	int depth;
	double area;
	double totalarea = 0;
	for (int i = 0; i < s.size(); i++)
	{
		area = 0;
		depth = 0;
		// '_', '/'はfloodの始点とはならない
		if (s[i] != '\\') continue;
		// iを始点としてareaを計算、同じ高さに戻ってきたらループ終了
		for (int j = i; j < s.size(); j++)
		{
			switch (s[j])
			{
			case '\\':
				area += 0.5 + depth;
				depth++;
				break;
			case '_':
				area += depth;
				break;
			case '/':
				depth--;
				area += 0.5 + depth;
				break;
			default:
				break;
			}
			if (depth == 0)
			{
				i = j;
				break;
			}
		}
		if (depth == 0)
		{
			flood.push_back(area);
			totalarea += area;
			count++;
		}
		else
		{
			continue;
		}
	}
	cout << setprecision(10) << totalarea << endl;
	cout << count;
	for (int i = 0; i < flood.size(); i++)
	{
		cout << ' ' << flood[i];
	}
	cout << endl;
	return 0;
}


Measured memory_bytes: 3340
n, x = map(int, input().split())

a, p = [1], [1]
for i in range(n):
    a.append(a[i]*2+3)
    p.append(p[i]*2+1)

def f(n, x):
    if n == 0:
        return 0 if x <= 0 else 1
    elif x <= 1 + a[n-1]:
        return f(n-1, x-1)
    else:
        return p[n-1] + 1 + f(n-1, x-2-a[n-1])

print(f(n, x))


Measured memory_bytes: 3064
# -*- coding: utf-8 -*-
import sys
sys.setrecursionlimit(200000)
input = sys.stdin.readline
def ii(): return int(input())
def mi(): return map(int, input().rstrip().split())
def lmi(): return list(map(int, input().rstrip().split()))
def fi(): return float(input())
def mfi(): return map(float, input().rstrip().split())
def lmfi(): return list(map(float, input().rstrip().split()))
def li(): return list(input().rstrip())
def debug(*args, sep=" ", end="\n"): print("debug:", *args, file=sys.stderr, sep=sep, end=end) if not __debug__ else None
def exit(*arg): print(*arg); sys.exit()
# template


def main():
    N = ii()
    a = lmi()
    if a[0] != 0:
        exit(0)

    a.sort()
    ma = max(a)
    if a[1] == 0:
        exit(0)
    ans = 1
    dp = [0] * N
    for x in a:
        dp[x] += 1
    for i in range(1, ma + 1):
        ans = ans * pow(dp[i - 1], dp[i], 998244353) % 998244353
    print(ans)
    return


if __name__ == '__main__':
    main()


Measured memory_bytes: 54188
from collections import deque
import sys

n=int(sys.stdin.readline().rstrip())
q=deque()
for _ in range(n):
    c,*x=sys.stdin.readline().split()
    if c=="deleteLast":
        q.pop()
    elif c=="deleteFirst":
        q.popleft()
    else:
        x=int(*x)
        if c=="insert":
            q.appendleft(x)
        else:
            try:
                q.remove(x)
            except:
                continue

print(*q)


Measured memory_bytes: 45948
//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
//#include <cstdio>
//#include <iomanip>//"cout<<fixed<<setprecision(n)<<sth<<endl;"
//#include <string>//"reverse(s's it,s's it)"
//#include <functional>//"greater<T>" "sort(a,a+n,greater<int>());""
//#include <cmath>//"abs" "sqrt"
//#include <numeric>//"accumulate(inputit,inputit,init,(optional) object)"
//#include <algorithm>//"lower_bound(it,it,v)" "next_permutation(a,a+n)"
//"reverse(v's it,v's it)"(v: vector)
using namespace std;
#define pb push_back//also for STRING
#define fi first
#define sc second
#define mp make_pair
#define is insert
#define ps push//TMP//stack,(priority) queue,
#define fr front//TMP//queue//for priority, use top().
typedef long long ll;//not necessarily
typedef pair<int,int> pii;
//Add other types in the same way.
const ll M=1000000007;//can be changed
int mod(int a){	return (a+M)%M;	}//M can be a variable
void plmod(ll &a,ll b){	a=(a+b+M)%M;	return;	}
void mnmod(ll &a,ll b){	a=(a-b+M)%M;	return;	}
void mlmod(ll &a,ll b){	a=(a*b)%M;  	return;	}
//Caution! you may need sth larger than "+M"!
void chmax(int &a,int b){	a=max(a,b);	return;	}
void chmin(int &a,int b){	a=min(a,b);	return;	}
//These 2 could be better in long long

#define MAX_N 200000
#define MAX_M 200000

int main(){
	int n,m,d[MAX_N],t[MAX_M];
	cin>>n;
	for(int i=0;i<n;++i) cin>>d[i];
	sort(d,d+n);
	cin>>m;
	for(int i=0;i<m;++i) cin>>t[i];
	sort(t,t+m);
	int j=0;
	for(int i=0;i<m;++i){
		while(t[i]!=d[j]){
			++j;
			if(j==n) goto error;
		}
		++j;
	}
	cout<<"YES"<<endl;
	return 0;
error:
	cout<<"NO"<<endl;
	return 0;
}

Measured memory_bytes: 1792