akhauriyash/Code-Regression huggingface dataset:
import sys
import numpy as np
import numba
from numba import njit, b1, i4, i8, f8

read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

@njit((i8[:], ), cache=True)
def main(A):
    A = A - 1
    N = len(A) // 3
    A = np.append(A, (N, N))
    INF = 1 << 30
    dp = np.full((N + 1, N + 1), -INF, np.int64)
    a, b = A[:2]
    dp[a, b] = dp[b, a] = 0
    dp_max = np.full(N + 1, -INF, np.int64)
    dp_max[a] = dp_max[b] = 0
    add = 0
    update = np.empty((100 * N, 3), np.int64)
    for n in range(N):
        a, b, c = A[3 * n + 2:3 * n + 5]
        if a == b == c:
            add += 1
            continue
        p = 0
        # 色を持ちかえるだけの遷移
        for _ in range(3):
            a, b, c = b, c, a
            update[p], p = (a, b, dp_max.max()), p + 1
            for k in range(N):
                update[p], p = (k, a, dp_max[k]), p + 1

        for _ in range(3):
            a, b, c = b, c, a
            # 色 a をそろえる遷移
            if a == b:
                for k in range(N):
                    # もともと a, k をもっている
                    update[p], p = (c, k, dp[a, k] + 1), p + 1
            # もともと a, a, をもっている
            update[p], p = (b, c, dp[a, a] + 1), p + 1
        for i in range(p):
            a, b, x = update[i]
            dp[a, b] = dp[b, a] = max(dp[a, b], x)
            dp_max[a] = max(dp_max[a], x)
            dp_max[b] = max(dp_max[b], x)
    return dp_max.max() + add

A = np.array(read().split(), np.int64)[1:]

print(main(A))

Measured memory_bytes: 138876
/**********************************************
*   UPDATE CONDITION & OVERFLOW CONDITION     *
**********************************************/

#include<bits/stdc++.h>
using namespace std;

#define pi 3.1415926535
#define endl "\n"
#define yes cout<<"YES\n"
#define no cout<<"NO\n"
#define ll long long
#define llu unsigned long long
#define pb push_back
#define mp make_pair
#define tc int t; cin>>t; while(t--)
#define f(i,a,n) for(int i=a ; i<n ; i++)
#define rf(i,n,a) for(int i=n-1 ; i>=a ; i--)
#define F first
#define S second
#define all(c) (c).begin(),(c).end()
#define get(a,n) f(i,0,n) cin >> a[i];
#define show(a,n) f(i,0,n) cout << a[i] << " "; cout << endl;
#define fast ios:: sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);

typedef long double ld;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef pair<pii,int> ppi;
typedef vector<pii> vpi;

const int inf = 1e9;
const long long int inf64 = 1e18;
const int mod = inf + 7;
const int N = 2e5 + 10;

int main()
{
    fast;
    int n, m;
    cin >> n >> m;
    vi a(n);
    get(a,n);
    map<int,int> mm;

    while(m--)
    {
        int l, r;
        cin >> l >> r;
        mm[l] = max(mm[l],a[r-1]);
        mm[r] = max(mm[r],a[l-1]);
    }
    int ans = 0;
    f(i,1,n+1)
    {
        if(mm.find(i) == mm.end())
            ans++;
        else if(a[i-1] > mm[i])
            ans++;
    }

    cout  << ans;
}



Measured memory_bytes: 7708
#![allow(unused_imports)]
#![allow(non_snake_case)]
use std::cmp::*;
use std::collections::*;
use std::io::Write;

#[allow(unused_macros)]
macro_rules! debug {
    ($($e:expr),*) => {
        #[cfg(debug_assertions)]
        $({
            let (e, mut err) = (stringify!($e), std::io::stderr());
            writeln!(err, "{} = {:?}", e, $e).unwrap()
        })*
    };
}

fn calc_score(c: &Vec<i64>, t: &Vec<usize>, s: &Vec<Vec<i64>>) -> i64 {
    let d = s.len();
    let mut score = 0;
    let mut last = vec![0; 26];
    for i in 0..d {
        score += s[i][t[i]];
        last[t[i]] = i + 1;
        for qi in 0..26 {
            score -= c[qi] * (i as i64 + 1 - last[qi] as i64);
        }
    }
    score
}

fn main() {
    let d = read::<usize>();
    let c = read_vec::<i64>();
    let mut s = vec![vec![]; d];
    for i in 0..d {
        s[i] = read_vec::<i64>();
    }

    let mut answers = vec![];

    for i in 0..d {
        let mut max_idx = 0;
        for j in 0..26 {
            if s[i][j] > s[i][max_idx] {
                max_idx = j;
            }
        }
        answers.push(max_idx);
    }
    let mut cur_score = calc_score(&c, &answers, &s);

    let mut xor = Xorshift::new();
    let round_num = 250000;
    for ri in 0..round_num {
        let rd = xor.next() as usize % d;
        let rq = xor.next() as usize % 26;

        let prev = answers[rd];
        answers[rd] = rq;
        let score = calc_score(&c, &answers, &s);
        let temp = (round_num as f64 - ri as f64 - 1.0) / (round_num as f64 - 1.0) * 40.0 + 10.0;
        let prob = (score as f64 - cur_score as f64) / temp;
        if score > cur_score || xor.randf() <= prob {
            cur_score = score;
        } else {
            answers[rd] = prev;
        }
    }

    for ans in answers {
        println!("{}", ans + 1);
    }
}

fn read<T: std::str::FromStr>() -> T {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim().parse().ok().unwrap()
}

fn read_vec<T: std::str::FromStr>() -> Vec<T> {
    read::<String>()
        .split_whitespace()
        .map(|e| e.parse().ok().unwrap())
        .collect()
}

#[derive(Debug)]
pub struct Xorshift {
    seed: u64,
}
impl Xorshift {
    pub fn new() -> Xorshift {
        Xorshift {
            seed: 0xf0fb588ca2196dac,
        }
    }
    pub fn with_seed(seed: u64) -> Xorshift {
        Xorshift { seed: seed }
    }
    #[inline]
    pub fn next(&mut self) -> u64 {
        self.seed = self.seed ^ (self.seed << 13);
        self.seed = self.seed ^ (self.seed >> 7);
        self.seed = self.seed ^ (self.seed << 17);
        self.seed
    }
    #[inline]
    pub fn rand(&mut self, m: u64) -> u64 {
        self.next() % m
    }

    pub fn randf(&mut self) -> f64 {
        use std::mem;
        const UPPER_MASK: u64 = 0x3FF0000000000000;
        const LOWER_MASK: u64 = 0xFFFFFFFFFFFFF;
        let tmp = UPPER_MASK | (self.next() & LOWER_MASK);
        let result: f64 = unsafe { mem::transmute(tmp) };
        result - 1.0
    }
}


Measured memory_bytes: 2272
#include <iostream>
#include <vector>
#include <algorithm>
#include <iomanip>
#include <string>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cassert>
#include <cstdint>
#include <numeric>
#include <bitset>
#include <functional>

using namespace std;

using ll =  long long;
using Pll = pair<ll, ll>;
using Pii = pair<int, int>;

constexpr ll MOD = 1000000007;
constexpr long double EPS = 1e-10;
constexpr int dyx[4][2] = {
    { 0, 1}, {-1, 0}, {0,-1}, {1, 0}
};

int main() {
    ll n;
    cin >> n;
    vector<int> v;
    while(n) {
        v.push_back(n&1);
        n -= n&1;
        n /= -2;
    }
    for(int i=v.size()-1;i>=0;--i) {
        cout << v[i];
    }
    if(v.size() == 0) cout << "0";
    cout << endl;
}

Measured memory_bytes: 3632
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0; i<(n); i++)
#define repr(i,x,n) for(int i=x; i<(n); i++)
#define ALL(x) (x).begin(),(x).end()
#define INF 1e9
typedef long long ll;
using VI = vector<int>;
using VB = vector<bool>;
using VS = vector<string>;
using graph = vector<vector<int>>;

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

if (a.size()>b.size())
{
    cout<<"GREATER"<<endl;
}
else if (a.size()<b.size())
{
    cout<<"LESS"<<endl;
}
else {
if (a>b)
{
    cout<<"GREATER"<<endl;
}
else if (a<b)
{
    cout<<"LESS"<<endl;
}

else cout<<"EQUAL"<<endl;
}



    return 0;
}

Measured memory_bytes: 3624
import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt(), m = sc.nextInt();
        ArrayList<HashSet<Integer>> list = new ArrayList<>();
        for (int i = 0; i < n; i++) list.add(i, new HashSet<>());
        while (m-- > 0) {
            int a = sc.nextInt() - 1, b = sc.nextInt() - 1;
            list.get(a).add(b);
            list.get(b).add(a);
        }

        Stack<Data> stack = new Stack<>();
        stack.push(new Data(0, new boolean[n]));
        int ans = 0;

        while (!stack.isEmpty()) {
            Data d = stack.pop();
            int from = d.i;
            boolean[] isVisited = d.b;

            isVisited[from] = true;
            if (allVisited(isVisited)) ans++;
            HashSet<Integer> to = list.get(from);

            for (int go : to) if (!isVisited[go]) stack.push(new Data(go, Arrays.copyOf(isVisited, n)));
        }

        System.out.println(ans);
    }

    private static boolean allVisited(boolean[] isVisited) {
        for (boolean b : isVisited) {
            if (!b) return false;
        }
        return true;
    }
}
class Data {
    int i;
    boolean[] b;

    Data(int i, boolean[] b) {
        this.i = i;
        this.b = b;
    }
}

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

int main() {
  int a,b,c;
  cin >> a >> b >> c;
  bool isPoor = false;
  if (a == b && b != c) isPoor = true; 
  if (b == c && c != a) isPoor = true;
  if (c == a && a != b) isPoor = true;
  
  if (isPoor) cout << "Yes";
  else cout << "No";
}

Measured memory_bytes: 256
#input
n = int(input())
a = list(map(int, input().split()))

ans = 0
#辞書型でデータを管理
dict = {}
for i in range(n):
    if a[i] not in dict:
        dict[a[i]] = 1
    else:
        dict[a[i]] += 1
for i in dict.keys():
    if i < dict[i]:
        #多い場合は減らすのが確定
        ans += dict[i] - i
    elif i > dict[i]:
        ans += dict[i]
print(ans)


Measured memory_bytes: 18168
name_a,name_b=(str(x) for x in input().split())
a_count,b_count=(int(x) for x in input().split())
fetch_color=input()
ans,bns=0,0
if fetch_color==name_a:
  ans = a_count-1
  bns = b_count
elif fetch_color==name_b:
  bns = b_count-1
  ans = a_count
print(ans,bns)

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

#define pb push_back
#define f first 
#define s second
#define ll long long
#define FOR(i, s) for(int i = 0; i<s; i++)
#define sz(s) (int)s.size()
#define vi vector<int>
#define ii pair<int, int>
#define vvi vector<vi>

ll n, m, q;
vector<vector<ii>> tab(20);
int main(){
    ios::sync_with_stdio(0);
    cin.tie(0);
	
	cin >> n;
	FOR(i, n){
		cin >> m;
		FOR(j, m){
			int a, b;
			cin >> a >> b;
			a--;
			tab[i].pb({a, b});
		}
	}	
	int best = 0;
	FOR(i, (1<<n)){
		bool ok = 1;
		FOR(j, n){
			if(i & (1<<j)){
				for(auto&u: tab[j]){
					if(u.s && !(i & (1<<u.f)))
						ok = 0;
					if(!u.s && i & (1<<u.f))
						ok = 0;
				}
			}
		}
		if(ok)
			best = max(best, __builtin_popcount(i));
	}
	cout << best << '\n';
}


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

using namespace std;

int main(){
	int n,tmp,min=INT_MAX,max=INT_MIN;
	scanf("%d",&n);
	for(int i = 0; i < n; i++){
		scanf("%d",&tmp);
		if(max < tmp-min) max = tmp - min;
		if(min > tmp) min = tmp;
	}
	printf("%d\n",max);
	return 0;
}


Measured memory_bytes: 2760
import sys
def t(A,p,r):
 x=A[r][1];i=p-1
 for j in range(p,r):
  if A[j][1]<=x:i+=1;A[i],A[j]=A[j],A[i]
 A[i+1],A[r]=A[r],A[i+1]
 return i+1
def k(A,p,r):
 if p<r:q=t(A,p,r);k(A,p,q-1);k(A,q+1,r)
def s(A):
 for i in range(n-1):
  if A[i][1]==A[i+1][1]:
   if A[i][2]>A[i+1][2]:return'Not s'
 return'S'
n=int(input())
f=lambda x,y:(x,int(y))
A=[(*f(*e.split()),i)for i,e in enumerate(sys.stdin)]
k(A,0,n-1)
for e in[[s(A)+'table']]+A:print(*e[:2])


Measured memory_bytes: 21124
#include<bits/stdc++.h>
using namespace std;
#define pb push_back
#define N 200001
#define ll long long
#define pi pair<int , int>
#define pip pair<pi ,int>
#define mp make_pair 
#define f first
#define s second
#define int ll 
#define mod 998244353
ll Mod(ll x, ll y, int p) 
{ll res = 1; x = x % p;
while (y > 0) 
{if(y & 1) res = (res*x) % p; 
y = y>>1;x = (x*x) % p; 
}return res; 
}
// this is triplet class , which will help us .
class Triplet{
 public:
 int x ;
 int y ;
 int gcd;
};
Triplet extendedEuclid(int a , int b){
 if(b == 0){Triplet ans; ans.gcd = a;ans.x = 1;ans.y = 0;return ans;}
 Triplet smallAns = extendedEuclid(b , a%b);
 Triplet ans;
 ans.gcd = smallAns.gcd;
 ans.x = smallAns.y;
 ans.y = smallAns.x - (a/b)*smallAns.y;
 return ans;
}
// this is for finding inversing multiplicative module of a number.
int mmInverse(int a , int m){
 Triplet ans = extendedEuclid(a , m);
 return ans.x;
}
int getlps(string pattern){
 int len = pattern.length();
 int * lps = new int[len];
 lps[0] = 0;
 int i = 1 , j = 0;
 while(i < len){
  if(pattern[i] == pattern[j]){
      lps[i] = j+1;
   i++;
   j++;
  }
  else{
        if(j != 0){
         j = lps[j-1];
        }
        else{
         lps[i] = 0;
         i++;
        }
  }
 }
 return lps[len-1];
}


int32_t main(){
   ios_base::sync_with_stdio(false);
      cin.tie(NULL);
    cout.tie(NULL);
   int k;
   cin>>k;
   int ans = 1;
   int rem = 7%k;
   int  cnt = 1;
   bool ok = false;
   while(cnt <= 2e7){
       if(rem == 0){
        cout<<ans<<endl;
        ok = true;
        break;
       }
        rem= (rem*10 + 7)%k;
        ans++;
        if(rem == 0){
            cout<<ans<<endl;
            ok = true;
            break;
        }
        cnt++;
   }
   if(cnt >= 2e7 && !ok){
cout<<"-1"<<endl;
   }
    
}

Measured memory_bytes: 3616
n,k = map(int,input().split())
r,s,p = map(int,input().split())
t = input()

ans = 0

te = ''

for i in range(n):
    l = t[i]
    if i < k:
        if l == 'r':
            ans += p
            te += 'p'
        elif l == 'p':
            ans += s
            te += 's'
        else:
            ans += r
            te += 'r'
    else:
        if l == 'r':
            if te[i-k] != 'p':
                ans += p
                te += 'p'
            else:
                te += 'a'
        elif l == 'p':
            if te[i-k] != 's':
                ans += s
                te += 's'
            else:
                te += 'a'
        else:
            if te[i-k] != 'r':
                ans += r
                te += 'r'
            else:
                te += 'a'

print(ans)


Measured memory_bytes: 3444
#include <bits/stdc++.h>
#define REP(i,n) for(ll i=0;i<(ll)(n);i++)
#define REPD(i,n) for(ll i=n-1;i>=0;i--)
#define FOR(i,a,b) for(ll i=a;i<=(ll)(b);i++)
#define FORD(i,a,b) for(ll i=a;i>=(ll)(b);i--)
#define ALL(x) (x).begin(),(x).end() 
#define SIZE(x) ((ll)(x).size())
#define MAX(x) *max_element(ALL(x))
#define MIN(x) *min_element(ALL(x))
#define INF 1000000000
using namespace std;
typedef long long ll;
typedef pair<int, int> P;

vector<bool> IsPrime;
void sieve(size_t max){
    if(max+1 > SIZE(IsPrime)){
        IsPrime.resize(max+1, true);
    }
    IsPrime[0] = false;
    IsPrime[1] = false;

    for(size_t i = 2; i <= sqrt(max); i++){
        if(IsPrime[i]){
            for(size_t j = 2; i*j <= max; j++){
                IsPrime[i*j] = false;
            }
        }
    }
}

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

    sieve(1e+5+10);

    int i = X;
    while(1){
        if (IsPrime[i]) break;
        i++;
    }
    cout << i << endl;
}

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

	#include <set>
	#include <iterator>
	using namespace std;
	// using namespace __gnu_pbds;


	#define f first
	#define s second
	#define pb push_back
	#define all(x) x.begin(),x.end()

	#define ll long long int
	#define vi vector<int>
	#define vii vector<pair<int,int> >
	#define pii pair<int,int>
	#define plii pair<pair<ll, int>, int>
	#define piii pair<pii, int>
	#define viii vector<pair<pii, int> >
	#define vl vector<ll>
	#define vll vector<pair<ll,ll> >
	#define pll pair<ll,ll>
	#define pli pair<ll,int>
	#define mp make_pair
	#define ms(x, v) memset(x, v, sizeof x)
	#define pr_vec(v) for(int i=0;i<v.size();i++) cout << v[i] << " " ;

	#define f_in(st) freopen(st,"r",stdin)
	#define f_out(st) freopen(st,"w",stdout)

	#define INF (ll)1e17
	#define matrix vector<vector<ll> >

	#define fr(i, a, b) for(i=a; i<=b; i++)
	#define fb(i, a, b) for(i=a; i>=b; i--)
	#define ASST(x, l, r) assert( x <= r && x >= l )
	#define maxbits 9
	#define maxmask (1ll<<maxbits)
	// typedef tree<pll, null_type, less<pll>, rb_tree_tag,
	//              tree_order_statistics_node_update>
	//     new_data_set;
	const int  N=(ll)2e3 +10, M=(ll)1e9+1 ;
	const int mod =(ll)1e9+7 , MAX=(ll)1e6+10;
	string fir="Monocarp",sec="Bicarp";

	void work(){
		ll n,m,x;
		cin >> n >> m >> x;
		vl cost(n);
		ll a[n][m];

		for(ll i=0;i<n;i++){
			cin >> cost[i];
			for(ll j=0;j<m;j++){
				cin >> a[i][j];
			}
		}

		ll ans=INF;
		for(ll i=0;i<(1ll<<n);i++){
			vl b(m,0);
			ll cur_cost=0;
			for(ll j=0;j<n;j++){
				if(i&(1ll<<j)){
					cur_cost+=cost[j];
					for(ll k=0;k<m;k++){
						b[k]+=a[j][k];
				  }
				}
			}

			bool flag=true;
			for(ll j=0;j<m;j++){
				if(b[j]<x)
					flag=false;
			}

			if(flag){
				// for(ll j=0;j<m;j++){
				// 	cout << b[j] << " ";
				// }
				// cout << "\n";
				ans=min(ans,cur_cost);
			}

		}

		if(ans==INF)
			ans=-1;
		cout << ans << "\n";
		return;

	}

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

		
		// to avoid printing in Scientific Notation like 2.14748e+09 and instead print: 2147483648.000000
		cout << fixed ;
		
		// precomp();
		ll t,z;
		// cin >> t;
		t=1;
		// z=t;
		while(t--){
				// cout << "Case #" << z-t << ": " << "\n";
		        work();
		
		}

		return 0;
	}
		

Measured memory_bytes: 3660
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main {

    public static void main(String[] args) throws IOException {
        InputStreamReader r = new InputStreamReader(System.in);
        BufferedReader br = new BufferedReader(r);
        int x = Integer.parseInt(br.readLine());
        int sum = 0;
        int res = 0;
        while((sum + 500) <= x) {
            res += 1000;
            sum += 500;
        }
        while((sum + 5) <= x) {
            res += 5;
            sum += 5;
        }
        System.out.println(res);

    }
}

Measured memory_bytes: 22740
#include <iostream>
#include<bits/stdc++.h>
using namespace std;
int main() {
	int h,w;
	cin>>h>>w;
	char cf[h+1][w+1];
	long long int a[h+1][w+1];
	memset(a,0,sizeof(a));
	for(int i=1;i<=h;i++){
		for(int j=1;j<=w;j++){
			cin>>cf[i][j];
		}
	}
	for(int i=1;i<=h;i++){
		for(int j=1;j<=w;j++){
			if(cf[i][j]=='#')a[i][j]=0;
			else if(i==1&&j==1)a[i][j]=1;
			else{
				a[i][j]=a[i][j-1]+a[i-1][j];
				if(a[i][j]>1000000007){
					a[i][j]%=1000000007;
				}
			}
		}
	}
	cout<<(a[h][w])%1000000007;
	return 0;
}

Measured memory_bytes: 9088
#include <iostream>
#include <algorithm>
#include <limits>
#include <vector>
#include <map>
#include <cmath>
#include <limits>
#include <iomanip>
#include <queue>
#define ll long long int
#define ld long double
#define rep(i,n) for(int i = 0;i < n;i++)
#define rep1(i,n) for(int i = 1;i < n;i++)
#define co(x) cout << x << endl
#define cosp(x) cout << x << " "
#define all(x) x.begin(),x.end()
#define p pair<ll,ll>
#define pb push_back
#define mp make_pair
#define PI 3.14159265359

using namespace std;

int main(){
    ll n;
    ll MOD = 1e9+7;
    cin >> n;
    vector<ll> a(n);
    vector<ll> keta(60,0);
    rep(i,n) cin >> a[i];
    rep(i,60){
        rep(j,n){
            if(a[j] & (1ll << i)){
                keta[i]++;
            }
        }
    }
    ll ans = 0;
    ll tmp;
    rep(i,60){
        tmp = pow(2,i);
        tmp %= MOD;
        tmp *= keta[i];
        tmp %= MOD;
        tmp *= (n - keta[i]);
        tmp %= MOD;
        ans += tmp;
        ans %= MOD;
    }

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

Measured memory_bytes: 2560
#include <iostream>
#include <typeinfo>
#include <cstring>
#include <utility>
#include <vector>
#include <cmath>
#include <algorithm>


using namespace std;


vector<vector<bool>> logics;

void dfs(vector<bool> &l1, int N) {
    vector<bool> l2 = l1;
    l1.push_back(true);
    l2.push_back(false);
    if (l1.size() == N - 1) {
        logics.push_back(l1);
        logics.push_back(l2);
    } else {
        dfs(l1, N);
        dfs(l2, N);
    }
}


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

    int N = S.size();
  if(N==1) {
    cout << S << endl;
    return 0;
  }
    
    int A[N];

    for (int i = 0; i < N; i++) {
        A[i] = S[i] - '0';
    }

    vector<bool> l0;
    dfs(l0, N);


    long long ans = 0;
    for (vector<bool> l: logics) {
        long long tmp = 0;
        for (int i = 0; i < N; i++) {
            tmp += A[i];
            if (i == N-1 || l[i]) {
                ans += tmp;
                tmp = 0;
            } else {
                tmp = tmp*10;
            }
        }
    }
    cout << ans << endl;

    return 0;
}



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

#define _GLIBCXX_DEBUG

int main() {
  int n, k, c = 0;
  vector<int> d(100);
  int a[100][100];
  vector<int> count(100);
  cin >> n >> k;
  
  for(int i = 0; i < k; i++) {
    cin >> d[i];
    for(int j = 0; j < d[i]; j++) {
      cin >> a[i][j];
      count[a[i][j] - 1]++;
    }
  }
  
  for(int i = 0; i < n; i++) {
    if(count[i] == 0) c++;
  }
  
  cout << c << endl;  
}

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

using namespace std;
#define all(x) (x).begin(),(x).end()
#define rep(i, n) for (int i = 0; i < (n); i++)
#define chmin(x, y) (x) = min((x), (y))
#define chmax(x, y) (x) = max((x), (y))
#define endl "\n"
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

template <typename T> ostream &operator<<(ostream &os, const vector<T> &vec) {os << "["; for (const auto &v : vec) {os << v << ","; } os << "]"; return os;}
template <typename T, typename U> ostream &operator<<(ostream &os, const pair<T, U> &p) {os << "(" << p.first << ", " << p.second << ")"; return os;}

void solve() {
    int N;
    cin >> N;
    ll A, B;
    cin >> A >> B;
    vector<ll> P(N);
    for (int i = 0; i < N; i++) {
        cin >> P[i];
    }
    int cnt1 = 0, cnt2 = 0, cnt3 = 0;
    for (int i = 0; i < N; i++) {
        if (P[i] <= A) cnt1++;
        else if (P[i] <= B) cnt2++;
        else cnt3++;
    }
    cout << min({cnt1, cnt2, cnt3}) << endl;
}

int main() {
    #ifdef LOCAL_ENV
    cin.exceptions(ios::failbit);
    #endif
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout.setf(ios::fixed);
    cout.precision(16);
    
    solve();

    #ifdef LOCAL_ENV
    assert(cin.rdstate() & ios_base::eofbit);
    #endif
}

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

using namespace std;

using ll = long long;
using pll = pair<ll, ll>;
using vpll = vector<pll>;



int main() {
    int n;
    ll m;
    cin >> n >> m;
    vpll v(n);
    for(int i=0; i<n; i++) cin >> v[i].first >> v[i].second;
    sort(v.begin(), v.end());
    ll res = 0, i = 0;
    while(m>0) {
        res += v[i].first * min(m, v[i].second);
        m -= v[i].second;
        i++;
    }
    cout << res << endl;
    return 0;
}



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


def solve(N: int, a: "List[int]"):
    ans = 0
    for aa in a[::2]:
        if aa % 2 == 1:
            ans += 1
    return ans

# Generated by 1.1.7.1 https://github.com/kyuridenamida/atcoder-tools
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    a = [int(next(tokens)) for _ in range(N)]  # type: "List[int]"
    print(solve(N, a))

def test():
    import doctest
    doctest.testmod()

if __name__ == '__main__':
    #test()
    main()


Measured memory_bytes: 9132
import java.util.Scanner;


class Main{
 public static void main(String args[]){
   Scanner sc = new Scanner(System.in);
   int A = sc.nextInt();
   int B = sc.nextInt();
   int C = sc.nextInt();
   int D = sc.nextInt();
   
    double radian = Math.PI*2*(C/12.0 + (D/60.0)/12.0 - D / 60.0);
   
  
   System.out.println(Math.sqrt((double)((A*A)+(B*B)-(2*A*B*Math.cos(radian)))));
 
 }
}


Measured memory_bytes: 35884
#include<stdio.h>
#include <sstream>
#include <iostream>
#include <cstdlib>

using namespace std;

#define BUF_SIZE 1024
#define ARRAY_SIZE 100

int main(){

	char buf[BUF_SIZE];
	int n = atoi(fgets(buf,BUF_SIZE,stdin));
	int array[ARRAY_SIZE];
	int change_count = 0;

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

	int tmp = 0;
	for(int i = n-1;i > 0;i--){
		for(int j = 0; j < i;j++){
			if(array[j] > array[j+1]){
				tmp = array[j+1];
				array[j+1] = array[j];
				array[j] = tmp;
				change_count++;
			}
		}
	}

	for(int i = 0; i < n; i++){
		if(i != n-1){
			printf("%d ",array[i]);
		}else{
			printf("%d\n",array[i]);
		}
	}
	printf("%d\n",change_count);
}



Measured memory_bytes: 3224
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <string>
#include <cstdio>
using namespace std;

#define int long long
#define INF 1e18

signed main() {
    int n; cin >> n;
    int sum = 0;
    int mx = 0;

    for(int i = 0; i < n; i++) {
        int l; cin >> l;
        sum += l;
        mx = max(mx, l);
    }

    if(sum - mx > mx) cout << "Yes" << endl;
    else cout << "No" << endl;

}


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

int main() {
  int r, c, k;
  scanf("%d %d %d", &r, &c, &k);
  vector<vector<int>> v(r, vector<int>(c));
  for (int i = 0; i < k; i++) {
    int x, y, z;
    scanf("%d %d %d", &x, &y, &z);
    v[x - 1][y - 1] = z;
  }

  vector<vector<vector<long long>>> f(r, vector<vector<long long>>(c, vector<long long>(4)));
  f[0][0][0] = 0;
  f[0][0][1] = v[0][0];
  for (int i = 0; i < r; i++)
    for (int j = 0; j < c; j++) {
      if (i)
        for (int k = 0; k < 4; k++) {
          f[i][j][0] = max(f[i][j][0], f[i - 1][j][k]);
          f[i][j][1] = max(f[i][j][1], f[i - 1][j][k] + v[i][j]);
        }

      if (j)
        for (int k = 0; k < 4; k++) {
          if (k) f[i][j][k] = max(f[i][j][k], f[i][j - 1][k - 1] + v[i][j]);
          f[i][j][k] = max(f[i][j][k], f[i][j - 1][k]);
        }
    }

  long long ans = 0;
  for (int k = 0; k < 4; k++)
    ans = max(ans, f[r - 1][c - 1][k]);
  printf("%lld\n", ans);

  return 0;
}

Measured memory_bytes: 671448
#include <bits/stdc++.h>
using namespace std;
int main()
{
    int n, l;
    cin >> n >> l;
    int absmin = INT_MAX, ans = 0, min = l;
    for (int i = 0; i < n; i++) {
        ans += l + i;
        if (absmin > abs(l + i)) {
            absmin = abs(l + i);
            min = l + i;
        }
    }
    cout << ans - min << endl;
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int n;
int a[100001];
bool b[100001];

int main(){
	cin>>n;
	for(int i=0;i<n;i++){
		cin>>a[i];
		a[i]--;
		b[i]=0;
	}
	int now=0;
	long long cont=0;
	while(1){
		if(b[now]){
			cout<<-1<<endl;
			return 0;
		}
		if(now==1){
			cout<<cont<<endl;
			return 0;
		}
		cont++;
		b[now]=1;
		now=a[now];
	}
	return 0;
}

Measured memory_bytes: 768
import sys

#入力取得
N, Y = map(int, input().split())

#10000 -> a 5000 -> b 1000 -> c

for a in range(N + 1):
    for b in range(N - a + 1):
        c = N - a - b
        sum = 10000 * a + 5000 * b + 1000 *c
        if sum == Y:
            print(str(a) + ' ' + str(b) + ' ' + str(c) )
            sys.exit()
print(str(-1) + ' ' + str(-1) + ' ' + str(-1))

Measured memory_bytes: 3060
#include<bits/stdc++.h>
using namespace std;
 
typedef long long   ll;
typedef long double ld;
const int N  = 5e5+10;
const ll mod = 1e9+7;
const ll inf = 1e18;
 
#define fast            ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define pb              push_back
#define mp              make_pair
#define ub              upper_bound                 // first element >  val(itr)
#define lb              lower_bound                 // first element >= val(itr) 
#define all(x)          (x).begin(),(x).end()
#define reset(a,x)      memset(a,x,sizeof(a))       // x can be 0 or -1
#define leadzero(a)     __builtin_clz(a)            // count leading zeroes
#define trailzero(a)    __builtin_ctz(a)            // count trailing zeroes
#define bitcount(a)     __builtin_popcount(a)       // count set bits
#define iceil(n,x)      ((n)+(x)-1)/(x)
#define test            int t; cin>>t; while(t--)
#define forn(i,a,e)     for(ll i = a; i < e; i++)
#define pii             pair<int,int>
#define pll             pair<ll,ll>
#define sp              <<" "<<

ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a;    }
ll powm(ll base,ll exp){ll ans=1;while(exp){if(exp&1) ans=(ans*base)%mod;exp>>=1,base=(base*base)%mod;}return ans;}
ll add(ll a,ll b)  { return (a%mod+b%mod)%mod;        }
ll sub(ll a, ll b) { return (a%mod+mod-b%mod)%mod;    }
ll mult(ll a,ll b) { return ((a%mod)*(b%mod))%mod;    }
ll choose2(ll n)   { ll ans=(n*(n-1))/2; return ans;  }
ll dist2(ll x1,ll y1,ll x2,ll y2){ ll ans=(x2-x1)*(x2-x1)+(y2-y1)*(y2-y1); return ans;}

int main()
{
     fast
     string s;
     cin>>s;

     ll n1=0,n2=0;

     n1=(s[2]-48)*10+s[3]-48;
     n2=(s[0]-48)*10+s[1]-48;

     if(n1<=12 && n2<=12 && n1>0 && n2>0)
          cout<<"AMBIGUOUS";
     else if((n1>12 && (n2==0) || (n2>12 && n1==0)) ||(n1>12 && n2>12) ||(n1==0 &&n2==0))
          cout<<"NA";
     else if(n1<=12 && n1>0)
          cout<<"YYMM";
     else
          cout<<"MMYY";

     return 0;
} 

Measured memory_bytes: 256
import core.bitop, std.algorithm, std.ascii, std.bigint, std.conv, std.math,
    std.functional, std.numeric, std.range, std.stdio, std.string, std.random,
    std.typecons, std.container, std.format;

// dfmt off
T lread(T = long)(){return readln.chomp.to!T();}
T[] aryread(T = long)(){return readln.split.to!(T[])();}
void scan(TList...)(ref TList Args){auto line = readln.split();
foreach (i, T; TList){T val = line[i].to!(T);Args[i] = val;}}
alias sread = () => readln.chomp();enum MOD = 10 ^^ 9 + 7;
// dfmt on

void main()
{
    long N = lread();
    auto A = new long[](N);
    auto B = new long[](N);
    foreach (i; 0 .. N)
        scan(A[i], B[i]);

    long ans;
    foreach_reverse (i; 0 .. N)
    {
        long m = (A[i] + ans) % B[i];
        if (m == 0)
            continue;
        long d = B[i] - m;
        ans += d;
    }
    writeln(ans);
}


Measured memory_bytes: 4604
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using Edge = pair<int, int>;
using Graph = vector<vector<Edge>>;
#define REP(i, n) for (int i = 0; i < (n); ++i)
#define SORT(v) sort((v).begin(), (v).end())
#define RSORT(v) sort((v).rbegin(), (v).rend())
const ll MOD = 1000000007;
const ll nmax = 8;
const ll INF = 1e9;
bool graph[nmax][nmax];
vector<vector<ll>> dist = vector<vector<ll>>(nmax, vector<ll>(nmax, INF));
void warshall_floyd(ll n)
{
    for (size_t i = 0; i < n; i++)
    {
        for (size_t j = 0; j < n; j++)
        {
            for (size_t k = 0; k < n; k++)
            {
                dist[j][k] = min(dist[j][k], dist[j][i] + dist[i][k]);
            }
        }
    }
}

class UnionFind
{
public:
    vector<ll> Parent;

    UnionFind(ll N)
    {
        Parent = vector<ll>(N, -1);
    }
    ll find(ll A)
    {
        if (Parent[A] < 0)
            return A;
        return Parent[A] = find(Parent[A]);
    }

    ll size(ll A)
    {
        return -Parent[find(A)];
    }

    bool Union(ll A, ll B)
    {
        A = find(A);
        B = find(B);
        if (A == B)
        {
            return false;
        }
        if (size(A) < size(B))
            swap(A, B);

        Parent[A] += Parent[B];
        Parent[B] = A;

        return true;
    }
};

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

ll lcm(ll a, ll b)
{
    ll g = gcd(a, b);
    return a / g * b;
}

ll mulMod(ll a, ll b)
{
    return (((a % MOD) * (b % MOD)) % MOD);
}

ll powMod(ll a, ll p)
{
    if (p == 0)
    {
        return 1;
    }
    else if (p % 2 == 0)
    {
        ll half = powMod(a, p / 2);
        return mulMod(half, half);
    }
    else
    {
        return mulMod(powMod(a, p - 1), a);
    }
}

ll ceil(ll a, ll b)
{
    return (a + b - 1) / b;
}

ll combination(ll a, ll b)
{
    ll ret = 1;

    for (int i = a; i > a - b; i--)
    {
        ret *= i;
    }

    for (int i = 1; i <= b; i++)
    {
        ret /= i;
    }

    return ret;
}

void solve(long long N, string str)
{
    ll ans = 0;
    for (int a = 0; a < 10; a++)
    {
        for (int b = 0; b < 10; b++)
        {
            for (int c = 0; c < 10; c++)
            {
                int tmp = 0;
                for (int i = 0; i < str.size(); i++)
                {
                    int index = (int)(str[i] - '0');
                    if (index == a && tmp == 0)
                    {
                        tmp++;
                        continue;
                    }

                    if (index == b && tmp == 1)
                    {
                        tmp++;
                        continue;
                    }

                    if (index == c && tmp == 2)
                    {
                        ans++;
                        break;
                    }
                }
            }
        }
    }

    cout << ans << endl;
}

int main()
{
    long long N;
    scanf("%lld", &N);
    string str;
    cin >> str;
    solve(N, str);
    return 0;
}


Measured memory_bytes: 384
import java.util.Scanner;


public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		
		String s = sc.next();
		int min = 999999999;
		
		for(int i = 0; i < s.length()-2; i++) {
			int n = Integer.parseInt(s.substring(i, i+3));
			
			int m = Math.abs(n - 753);
			
			if(min > m )	min = m;			
		}
		System.out.println(min);
		sc.close();

	}

}


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

#define rep(i,n) for (int i = 0; i < (n); ++i)
#define F first
#define S second

using ll = long long;
using P = pair<int,int>;

int main() {
  int n;
  cin >> n;
  vector<int> v(n);
  rep(i, n) {
    cin >> v[i];
  }

  vector<int> res(n, 0);
  rep(i, 32) {
    int cnt = 0;
    rep(j, n) {
      int t = (v[j] >> i) & 1;
      cnt += t;
    }
    if (cnt % 2 == 0) {
      rep(j, n) {
        int t = (v[j] >> i) & 1;
        res[j] |= (t << i);
      }
    } else {
      rep(j, n) {
        int t = (v[j] >> i) & 1;
        t = (t == 0) ? 1 : 0;
        res[j] |= (t << i);
      }
    }
  }

  rep(i, n) {
    if (i) cout << ' ';
    cout << res[i];
  }
  cout << endl;

  return 0;
}


Measured memory_bytes: 4844
#include <iostream>
#include <algorithm>
#include <string>
#include <fstream>
#include <cmath>

using namespace std;



int main(int argc, const char * argv[]) {

    double n=0.0;
    cin >> n;
    while(n!=0){
        int num;
        num = n;
        double a[num];
        double total=0;
        
        for(int i=0; i<num; i++){
            cin >> a[i];
            total += a[i];
        }
        
        double avg;
         avg = total/n;
 
        double tmp_sum =0;
        for(int i=0 ; i<n; i++){
            tmp_sum += (a[i] - avg)*(a[i] - avg);

        }
            
        printf("%5f\n", sqrt(tmp_sum/n));
        cin >> n;
    
    }
    return 0;
}



Measured memory_bytes: 3284
/* long long or int */
/* xx 396*/

#include<bits/stdc++.h>
using namespace std;

vector <int> v;
int n;

bool check(vector <int> v){
	for(int i=1;i<v.size();i++) if(v[i]<v[i-1]) return false;
	return true;
}

int main(){
	ios::sync_with_stdio(false); 
	cin.tie(0); cout.tie(0);
	cin>>n;
	for(int i=0;i<n;i++){
		int x; cin>>x;
		v.push_back(x);
	}
	if(check(v)){
		cout<<"YES"<<endl;
		return 0;
	}
	for(int i=0;i<n;i++){
		for(int j=i+1;j<n;j++){
			vector <int> now=v;
			swap(now[i],now[j]);
			if(check(now)){
				cout<<"YES";
				return 0;
			}
		}
	}
	cout<<"NO";
	return 0;
}

Measured memory_bytes: 256
import java.io.*;
import java.math.BigInteger;
import java.util.*;
import java.util.Stack;

public class Main{
	public static class FastReader {
		BufferedReader br;
		StringTokenizer root;
		
 
		public FastReader() {
			br = new BufferedReader(new InputStreamReader(System.in));
		}
 
		String next() {
			while (root == null || !root.hasMoreTokens()) {
				try {
					root = new StringTokenizer(br.readLine());
				} catch (Exception r) {
					r.printStackTrace();
				}
			}
			return root.nextToken();
		}
 
		int nextInt() {
			return Integer.parseInt(next());
		}
 
		double nextDouble() {
			return Double.parseDouble(next());
		}
 
		long nextLong() {
			return Long.parseLong(next());
		}
 
		String nextLine() {
			String str = "";
			try {
				str = br.readLine();
			} catch (Exception r) {
				r.printStackTrace();
			}
			return str;
		}
	}
	
	public static PrintWriter out = new PrintWriter (new BufferedOutputStream(System.out));
	static int mod = (int) (1e9+7),n;
	static long cf = 998244353;
    static final int MAX = (int) 1e6;
    public static List<Integer>[] edges;
    public static int[][] parent;
    public static int col = 20;
    public static long[] Bit;
    public static long[] fact,inv;
    public  static int[] prime; 
    public static long[] dp;
	public static FastReader sc = new FastReader();
	public static void main(String[] args) {
	//	Scanner sc = new Scanner(System.in);
 
		int n = sc.nextInt();
		int k = sc.nextInt();
		int r = sc.nextInt();
		int s = sc.nextInt();
		int p = sc.nextInt();
		char[] str = sc.next().toCharArray();
		long sum = 0;
		dp = new long[n];
		for(int i=0;i<k;++i) {
			sum+=get(str[i],r,p,s);
			dp[i] = sum;
		}
		
		for(int i=k;i<n;++i) {
			if(str[i] == str[i-k]) {
				dp[i] = Math.max(dp[i-k], dp[i-1]);
				str[i] = '$';
			}else dp[i] = dp[i-1] + get(str[i],r,p,s);
		}
		out.print(dp[n-1]);
		
		
		out.close();
	}
	private static long get(char c, int r, int p, int s) {
		if(c=='r')return p;
		else if(c=='p') return s;
		else return r;
		
	}
	 
	
}

Measured memory_bytes: 27220
#include <iostream>
#include <string>

using namespace std;

string chars[] = {
  "",
  ".,!? ",
  "abc",
  "def",
  "ghi",
  "jkl",
  "mno",
  "pqrs",
  "tuv",
  "wxyz",
};

int main() {
  int nnn;
  cin >> nnn;
  for (int iii = 0; iii < nnn; ++iii) {
    string input;
    cin >> input;
    int prev = 0, cnt = 0;
    for (char c : input) {
      int i = c-'0';
      if (i == 0) {
	if (prev != 0) {
	  cout << chars[prev][(cnt-1) % chars[prev].size()];
	}
	prev = i;
	cnt = 0;
      } else {
	prev = i;
	++cnt;
      }
    }
    cout << endl;
  }
}

Measured memory_bytes: 3144
#include <cstdio>
#include <set>
#include <algorithm>
#include <cmath>

int cnt[500005];
int a[500005];
int block;

struct A{
    int l, r;
    int idx;
    int ans;
}q[500005];

bool cmp(A a, A b){
    if(a.l / block != b.l / block)
        return a.l / block < b.l / block;
    return a.r < b.r;
}

bool cmp2(A a, A b){return a.idx < b.idx;}

int main(){
    int N, Q;
    int i;
    scanf("%d%d", &N, &Q);
    for(i = 1; i <= N; ++i)
        scanf("%d", &a[i]);
    for(i = 0; i < Q; ++i){
        scanf("%d%d", &q[i].l, &q[i].r);
        q[i].idx = i;
    }
    block = sqrt(N);
    std::sort(q, q + Q, cmp);
    //std::set<int> s;
    int curL = q[0].l;
    int curR = q[0].l;
    //s.insert(a[curL]);
    int num = 1;
    //s.insert(a[curL]);
    cnt[a[curL]] = 1;
    for(i = 0; i < Q; ++i){
        while(curR < q[i].r){
            ++curR;
            if(cnt[a[curR]] == 0){
                ++num;
                cnt[a[curR]] = 1;
            }else{
                ++cnt[a[curR]];
            }
        }
        while(curR > q[i].r){
            if(cnt[a[curR]] == 1){
                cnt[a[curR]] = 0;
                --num;
            }else{
                --cnt[a[curR]];
            }
            --curR;
        }
        while(curL < q[i].l){
            if(cnt[a[curL]] == 1){
                cnt[a[curL]] = 0;
                --num;
            }else{
                --cnt[a[curL]];
            }
            ++curL;
        }
        while(curL > q[i].l){
            --curL;
            if(cnt[a[curL]] == 0){
                ++num;
            }
            ++cnt[a[curL]];
        }
        q[i].ans = num;
    }
    std::sort(q, q + Q, cmp2);
    for(i = 0; i < Q; ++i)
        printf("%d\n", q[i].ans);
    return 0;
}

Measured memory_bytes: 15316
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
#define rep2(i, s, n) for (int i = (s); i < (int)(n); ++i)
#define chmax(a, b) a = max(a, b)
#define chmin(a, b) a = min(a, b)
#define fi first
#define se second
#define INF 1000000009
#define LLINF 1000000000000000009LL
using ll = long long;

int main(){
  string s;
  cin>>s;
  int k=s.size()-1;
  if(s[k]=='3'){
    cout<<"bon"<<endl;
  }
  else if(s[k]=='0'||s[k]=='1'||s[k]=='6'||s[k]=='8'){
    cout<<"pon"<<endl;
  }
  else{
    cout<<"hon"<<endl;
  }
  return(0);
}


Measured memory_bytes: 3628
class UnionFind():
    def __init__(self, n):
        self.n = n
        self.parents = [i for i in range(n)]
        self.size = [1 for _ in range(n)]

    def find(self, x):
        root = x
        while self.parents[root] != root:
            root = self.parents[root]
        return root

    def unite(self, x, y):
        xroot = self.find(x)
        yroot = self.find(y)
        if xroot == yroot: return
        if self.size[xroot] <= self.size[yroot]:
            self.parents[xroot] = yroot
            self.size[yroot] += self.size[xroot]
        else:
            self.parents[yroot] = xroot
            self.size[xroot] += self.size[yroot]

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

uf = UnionFind(M)
L = []

for _ in range(N):
    k, *l = map(int, input().split())
    for i in range(1, k):
        uf.unite(l[0] - 1, l[i] - 1)
    L.append(l[0] - 1)

if len(set([uf.find(L[i]) for i in range(N)])) == 1:
    print('YES')
else:
    print('NO')

Measured memory_bytes: 87780
#include <stdio.h>
int main(void){
  long H,W;
  scanf("%ld %ld",&H,&W);
  
if(H == 1 || W == 1)
{
printf("1");
  return 0;
}
if (H * W %2 == 0)
{
printf("%ld",H * W / 2);
  return 0;
}
 else
{
printf("%ld",H * W / 2 + 1);
  return 0;
}
 
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
int PREP = (cin.tie(nullptr), ios::sync_with_stdio(false), cout << fixed << setprecision(12), 0);
//int SEGV = getenv("D") || (exit(system("D= SEGFAULT_SIGNALS=all catchsegv ./prog.exe") >> 8), 0);
using Int = long long;
vector<int> scc(const vector<vector<int>> &G) {
    int N = G.size();
    vector<int> low(N), dfsnum(N, -1), comp(N, -1);
    stack<int> L;
    int num = 0, conum = 0;
    auto visit = [&](auto&& visit, int p) -> void {
        L.push(p);
        low[p] = dfsnum[p] = num++;
        for (int q : G[p]) {
            if (comp[q] >= 0) continue;
            if (dfsnum[q] < 0) visit(visit, q);
            low[p] = min(low[p], low[q]);
        }
        if (low[p] == dfsnum[p]) {
            for (;;) {
                int v = L.top(); L.pop();
                comp[v] = conum;
                if (v == p) break;
            }
            conum++;
        }
    };
    for (int i = 0; i < N; i++) {
        if (comp[i] < 0) visit(visit, i);
    }
    return comp;
}
int main() {
    int N, M; cin >> N >> M;
    vector<vector<int>> G(N);
    for (int i = 0; i < M; i++) {
        int u, v; cin >> u >> v;
        G[u].push_back(v);
    }
    auto comp = scc(G);
    map<int, vector<int>> components;
    for (int i = 0; i < N; i++) {
        components[-comp[i]].push_back(i);
    }
    cout << components.size() << '\n';
    for (auto& [idx, vec] : components) {
        cout << vec.size();
        for (auto elem : vec) cout << ' ' << elem;
        cout << '\n';
    }
    return 0;
}


Measured memory_bytes: 83280
#include<bits/stdc++.h>
using namespace std;
#define ll  long long
#define ld  long double
#define endl '\n'
#define FAST ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
const ll MOD = 1e9 + 7;
const double PI = 3.141592653589793238463;
const int MAXN = 200005;
bool isPrime[MAXN];
vector<int> pr;
vector<int> ans;
void sieve()
{
    memset(isPrime, 1, sizeof isPrime);
    isPrime[0] = isPrime[1] = 0;

    for (int i = 2; i * i <= MAXN; i += 1 + (i & 1))
    {
        if (isPrime[i])
        {

            for (int j = i * i; j < MAXN; j += i)
                isPrime[j] = 0;
        }
    }
    for(int i=0; i<MAXN; i++)
    {
        if(isPrime[i])
        {

            ans.push_back(i);
        }
    }
}

ld power(ld x, ll y)
{
    ll temp;
    if (y == 0)
        return 1;
    temp = power(x, y / 2);
    if (y % 2 == 0)
        return temp * temp;
    else
        return x * temp * temp;
}

void debug_out()
{
    cerr << endl;
}

template<typename Head, typename... Tail>
void debug_out(Head H, Tail... T)
{
    cerr << " " << H;
    debug_out(T...);
}

#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)


int main()
{
    FAST
    int n,x;
    cin>>x>>n;
    int arr[n];
    for(int i=0;i<n;i++)
        cin>>arr[i];
        sort(arr,arr+n);
        int f=0,s=0;
    for(int i=x;;i++){
        if(!binary_search(arr,arr+n,i)){
            f=i;
            break;
        }
    }
    for(int i=x;;i--){
        if(!binary_search(arr,arr+n,i)){
            s=i;
            break;
        }
    }
    if(abs(f-x)<abs(s-x))
        cout<<f<<endl;
    else if(abs(f-x)>abs(s-x)){
        cout<<s<<endl;
    }
    else{
        cout<<min(f,s)<<endl;
    }
    return 0;
}


Measured memory_bytes: 3664
#include <stdio.h>

int binary(int *,int,int);

int main(){
  int len1,len2,A[100000],elem,sum=0;
  int i;

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

  scanf("%d",&len2);
  for(i=0;i<len2;i++){
    scanf("%d",&elem);
    sum+=binary(A,elem,len1);
  }

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

int binary(int *A,int elem,int len){
  int left=0,right=len,mid;
  
  while(left<right){
    mid=(left+right)/2;
    if(A[mid]==elem) return 1;
    if(A[mid]<elem) left=mid+1;
    else right=mid;
  }

  return 0;
}



Measured memory_bytes: 2248
/*
Author:Jenil Mehta
Not yet serious but trying to be serious :)
Coding is lub
*/
 
#include <iostream>
#include <sstream>
#include <cstdio>
#include <climits>
#include <cmath>
#include <cstring>
#include <cctype>
#include <string>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <algorithm>
#include <functional>
typedef long long int ll;
ll power(ll a, ll n) {ll p = 1;while (n > 0) {if(n%2) {p = p * a;} n >>= 1; a *= a;} return p;}
ll power(ll a, ll n, ll mod) {ll p = 1;while (n > 0) {if(n%2) {p = p * a; p %= mod;} n >>= 1; a *= a; a %= mod;} return p % mod;}
using namespace std;
ll a[1002];
ll b[1002];
int main()
{
    ll n;
    cin>>n;
    ll w;
    cin>>w;
    
    ll i,j;
    ll ans=0;
    ll index=0;
    ll dp[n+1][w+1]={0};
    for(i=0;i<n;i++)
    {
        cin>>a[i]>>b[i];
    }
    if (n == 0 || w == 0) 
    {
        cout<<0<<endl;
        return 0;
    }
    //cout<<"hello1"<<endl;
    for(i=0;i<=n;i++)
    {
        //cout<<"hello2"<<endl;
        for(j=0;j<=w;j++)
        {
           if(i==0||j==0)
           dp[i][j]=0;
            else if(a[i-1]>j)
            {
                dp[i][j]=dp[i-1][j];
            }
            else
            {
                dp[i][j]=max(dp[i-1][j],b[i-1]+dp[i-1][j-a[i-1]]);
            }
        }
    }
    
    cout<<dp[n][w]<<endl;
}

Measured memory_bytes: 79104
import sys
sys.setrecursionlimit(10**9)
from functools import lru_cache

t = int(input())
  
for _ in range(t):
    n,a,b,c,d = map(int,input().split())
    @lru_cache(None)
    def f(k):
      if k == 1:return d
      if k == 0:return 0
      return min(k*d,f(k//5)+c+k%5*d,f(k//3)+b+k%3*d,f(k//2)+a+k%2*d,f((k+4)//5)+c+-k%5*d,f((k+2)//3)+b+-k%3*d,f((k+1)//2)+a+-k%2*d)
    print(f(n))

Measured memory_bytes: 11324