akhauriyash/Code-Regression huggingface dataset:
//--------------------------------------------------
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,abm,mmx,avx,avx2,popcnt,fma")
//#pragma GCC optimize("fast-math")
//#pragma GCC optimize("unroll-loops")
//#pragma GCC optimize("Ofast")
//--------------------------------------------------
#include <bits/stdc++.h>
//#include <chrono>
//#include <set>
//#include <map>
//#include <deque>
//#include <cmath>
//#include <queue>
//#include <cassert>
//#include <random>
//#include <bitset>
//#include <iomanip>
//#include <numeric>
//#include <time.h>
//#include <ctime>
//#include <string>
//#include <cstdio>
//#include <vector>
//#include <cstdlib>
//#include <iostream>
//#include <algorithm>
//#include <unordered_map>
//#include <unordered_set>
//#include <fstream>
//#include <stack>
//#include <cstring>
//--------------------------------------------------
#define forn(i, n) for(int i = 0; i < n; i++)
#define forw(i, n) for(int i = n-1; i >= 0; --i)
#define forns(i, n, s) for(int i = s; i < n; i++)
#define x first
#define y second
#define pb push_back
#define mp make_pair
#define all(v) v.begin(),v.end()
#define allr(v) v.rbegin(),v.rend()
//----------------------------------------------------
using namespace std;
//----------------------------------------------------
typedef long long ll;
typedef unsigned long long ull;
typedef unsigned int uint;
typedef long double ld;
typedef vector<ll> lnum;
typedef complex<ld> comp;
//----------------------------------------------------
const ll mod = 1e9 + 7, mod2 = 998244353;
const ld eps = 1e-6;
const ll inf = 1e18;
const int base = 1e9;
const ld PI = 3.14159265358979;
//----------------------------------------------------
#define endl '\n';
//----------------------------------------------------
int n, m;
ll fact[5*100*1000+1];
//----------------------------------------------------
unsigned int bitcount(ull val) { return __builtin_popcount(val) + __builtin_popcount(val >> 32); }

void local() {
    freopen("test.in", "r", stdin);
}

void remote() {
}

void read() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);
    cin >> n >> m;
}

ll qpow(ll val, ll n){
    ll res = 1;
    while(n > 0){
        if(n & 1) res = (res * val) % mod;
        val = (val * val) % mod;
        n >>= 1;
    }
    return res;
}

ll binomial(ll n, ll k){
    return (fact[n] * qpow(fact[n-k], mod-2) % mod) * qpow(fact[k], mod-2) % mod;
}

int main() {
#ifdef MY_DEBUG
    local();
#else
    remote();
#endif
    read();

    fact[0] = 1;
    forns(i, m+1, 1) fact[i] = (fact[i-1] * i) % mod;

    ll ans = (fact[m] * qpow(fact[m-n], mod-2)) % mod;
    ll val = ans;
    forn(i, n){
        ll k = i+1;
        ll tmp = binomial(n, k) * (fact[m-k] * qpow(fact[m-k-(n-k)], mod-2) % mod) % mod;
        if(i & 1) val += tmp;
        else val = val + mod - tmp;
        val %= mod;
    }

    cout << (ans * val) % mod << endl;
}


Measured memory_bytes: 7472
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <set>
#include <queue>
#include <stack>
#include <tuple>
#include <cmath>
#include <iomanip>
#include <map>
#include <stdio.h>
#include <cstring> //memset(dp,0,sizeof(dp))
#include <functional> //operator[]
#define ll long long
#define rep(i,n) for(int i=0;i<(n);i++)
#define Rep(i,n) for(int i=1;i<(n);i++)
#define rrep(i,n) for(int i=n-1;i>=0;i--)
#define Rrep(i,n) for(int i=n-1;i>0;i--)
#define fi first
#define se second
#define pb push_back
#define ALL(a) (a).begin(),(a).end()
#define P pair<int,int>
#define Pll pair<ll,ll>
using namespace std;
template<typename T1,typename T2> inline void chmin(T1 &a,T2 b){if(a>b) a=b;}
template<typename T1,typename T2> inline void chmax(T1 &a,T2 b){if(a<b) a=b;}

int main(){
    int n,m; cin >> n >> m;
    if(m==1) cout << 1 << " " << 2 << endl;
    else if(n%2==1){
        for(int i=1;i<=m;i++){
            cout << i << " " << n-i << endl;
        }
    }else{
        bool ok=1;
        for(int i=1;i<=m;i++){
            if((n+1-2*i)<=(n/2)) ok=0;
            if(ok) cout << i << " " << n+1-i << endl;
            else cout << i << " " << n-i << endl;
        }
    }
}



Measured memory_bytes: 3640
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <iomanip>
#include <cmath>
#include <stdio.h>
#include <queue>
#include <deque>
#include <cstdio>
#include <set>
#include <map>
#include <bitset>
#include <stack>
using namespace std;
int main() {
	long double l;
	cin >> l;
	cout << setprecision(10)<<(l / 3) * (l / 3) * (l / 3) << endl;
	return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {

		
		Scanner scanner = new Scanner(System.in);
		int r           = scanner.nextInt();
		int D           = scanner.nextInt();
		int x           = scanner.nextInt();
		int answer      = 0;
		
		for(int i = 0; i <= 9; i++){
			
			answer = r * x - D;
			x = answer;
			System.out.println(answer);
		}
	}

}

Measured memory_bytes: 21844
#include<stdio.h>
int main()
{
    char a,b;
    int t,x;
    while(scanf("%c %c",&a,&b)==2)
    {
        if(a=='H')
            t=1;
        else
            t=2;
        if(t==1)
        {
            if(b=='H')
                x=1;
            else
                x=2;
        }
        else
        {
            if(b=='H')
                x=2;
            else
                x=1;
        }
        if(x==1)
            printf("H\n");
        if(x==2)
            printf("D\n");
            getchar();
    }

    return 0;
}



Measured memory_bytes: 128
#include "bits/stdc++.h"
#define rep(i,n) for(int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
using P = pair<int, int>;
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() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll k;
    cin >> k;
    ll cnt = k/50;
    ll r = k%50;
    vector<ll> a(50, 0);
    rep(i,50) a[i] = i + cnt;
    rep(i,r){
    	a[0] += 50;
    	for(int j = 1; j < 50; j++){
    		a[j]--;
    	}
    	sort(a.begin(), a.end());
    }
    cout << "50" << endl;
    rep(i,50){
    	cout << a[i];
    	if(i == 49) cout << endl;
    	else cout << " ";
    }
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
	priority_queue<string> s;
	stack<string> s2;
	string aa;
	int n,l;
	scanf("%d%d",&n,&l);
	for(int i=1;i<=n;i++){
		cin >> aa;
		s.push(aa);
	}
	while(!s.empty()){
		s2.push(s.top());
		s.pop();
	}
	while(!s2.empty()){
		cout << s2.top();
		s2.pop();
	}
}

Measured memory_bytes: 256
#include <iostream>

using namespace std;

string S, T;

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

    string sub_T = T.substr(0, S.size());
    if (sub_T.compare(S) == 0) {
        cout << "Yes\n";
    } else {
        cout << "No\n";
    }

    return 0;
}

Measured memory_bytes: 3600
#include <stdio.h>

int main(void){

	int i,j,h,w;

	while(1){

		scanf("%d %d",&h,&w);
		if(h==0&&w==0)break;

		for(i=0;i<h;i++){
			for(j=0;j<w;j++){
				printf("#");
			}
			printf("\n");
		}
printf("\n");

	}

	return 0;

}

Measured memory_bytes: 572
#pragma GCC optimize("O3") 

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

typedef long long int           ll;
typedef unsigned long long int  ull;
typedef long double             ld;

typedef pair<int, int>          pii;
typedef pair<ll,ll>             pll;
typedef vector<int>             vi;
typedef vector<ll>              vll;
typedef vector<pii>             vpii;
typedef vector<pll>             vpll;

#define test(t)		        int t; cin >> t; while(t--)
#define f(i, a, b)	        for(int (i) = (a); (i) < (b); ++(i))
#define all(a)		        (a).begin(), (a).end()
#define endl 		        "\n"
#define maxvec(vec)             *max_element(all(vec))
#define minvec(vec)             *min_element(all(vec))
#define maxarr(arr)             *max_element(arr, arr + n)
#define minarr(arr)             *min_element(arr, arr + n)
#define deb(x)		        cout << #x << "--" << x << "--" << endl;
#define deb2(x,y)	        cout << #x << "-" << x << "-" << " ~~ " <<  #y << "-" << y << "-" << endl;
#define deba(arr)	        cout << #arr << " ~ [ "; for(auto n: arr) cout << n << " "; cout << "]" << endl;
#define debap(arr)	        cout << #arr << " ~ [ "; for(auto n: arr) cout << n.first << "-" << n.second << " "; cout << "]" << endl;
#define fast 		        ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);

#define mx9		1000000007
#define mx7		10000007
#define mx6		1000006
#define mx5		200005
#define inf		1<<30                                 
#define eps		1e-9
#define mod		1000000007
#define PI		3.141592653589793238462643383279502884L

void solve()
{
  ll a;
  cin >> a;
  cout << a + pow(a, 2) + pow(a, 3) << endl;
}

int main()
{
    fast;
    //test(t)
        solve();
    return 0;
}

Measured memory_bytes: 4300
use std::cmp;
use std::collections::BTreeMap;

fn main() {
    let (r, w) = (std::io::stdin(), std::io::stdout());
    let mut sc = IO::new(r.lock(), w.lock());
    let n: usize = sc.read();

    let mut lr = (0..n)
        .map(|_| (sc.read::<i64>(), sc.read::<i64>()))
        .collect::<Vec<_>>();
    let mut left_set = BTreeMap::new();
    let mut right_set = BTreeMap::new();
    for &(l, r) in lr.iter() {
        push(l, &mut left_set);
        push(r, &mut right_set);
    }

    let mut ans = 0;
    for i in 0..n {
        let (l, r) = lr[i];
        remove(l, &mut left_set);
        remove(r, &mut right_set);

        let first = solver(&left_set, &right_set);
        let second = r - l + 1;
        ans = cmp::max(ans, first + second);

        push(l, &mut left_set);
        push(r, &mut right_set);
    }

    let mut left_set2 = BTreeMap::new();
    let mut right_set2 = BTreeMap::new();

    lr.sort_by_key(|&(l, r)| (l, -r));

    for i in 0..(n - 1) {
        let (l, r) = lr[i];
        remove(l, &mut left_set);
        remove(r, &mut right_set);
        push(l, &mut left_set2);
        push(r, &mut right_set2);

        let ans1 = solver(&left_set, &right_set);
        let ans2 = solver(&left_set2, &right_set2);
        ans = cmp::max(ans, ans1 + ans2);
    }

    println!("{}", ans);
}

fn solver(left_set: &BTreeMap<i64, usize>, right_set: &BTreeMap<i64, usize>) -> i64 {
    let max_l = *left_set.keys().next_back().unwrap();
    let min_r = *right_set.keys().next().unwrap();
    cmp::max(min_r - max_l + 1, 0)
}

fn push(v: i64, map: &mut BTreeMap<i64, usize>) {
    let t = map.entry(v).or_insert(0);
    *t += 1;
}

fn remove(v: i64, map: &mut BTreeMap<i64, usize>) {
    let t = map.get(&v).cloned().unwrap();
    if t == 1 {
        assert_eq!(map.remove(&v), Some(1));
    } else {
        map.insert(v, t - 1);
    }
}

pub struct IO<R, W: std::io::Write>(R, std::io::BufWriter<W>);

impl<R: std::io::Read, W: std::io::Write> IO<R, W> {
    pub fn new(r: R, w: W) -> IO<R, W> {
        IO(r, std::io::BufWriter::new(w))
    }
    pub fn write<S: std::ops::Deref<Target = str>>(&mut self, s: S) {
        use std::io::Write;
        self.1.write(s.as_bytes()).unwrap();
    }
    pub fn read<T: std::str::FromStr>(&mut self) -> T {
        use std::io::Read;
        let buf = self
            .0
            .by_ref()
            .bytes()
            .map(|b| b.unwrap())
            .skip_while(|&b| b == b' ' || b == b'\n' || b == b'\r' || b == b'\t')
            .take_while(|&b| b != b' ' && b != b'\n' && b != b'\r' && b != b'\t')
            .collect::<Vec<_>>();
        unsafe { std::str::from_utf8_unchecked(&buf) }
            .parse()
            .ok()
            .expect("Parse error.")
    }
    pub fn vec<T: std::str::FromStr>(&mut self, n: usize) -> Vec<T> {
        (0..n).map(|_| self.read()).collect()
    }
    pub fn chars(&mut self) -> Vec<char> {
        self.read::<String>().chars().collect()
    }
}


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

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

    for (int i = 1; i <= X; i++) {
        int r = X - 100 * i;
        if (0 <= r && r <= 5 * i) {
            cout << 1 << endl;
            return 0;
        }
    }

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

Measured memory_bytes: 256
def bsolve(a,b,c,d):
	M=len(b)
	for i in range(M):
		for j in range(M):
			if(a[c+i][d+j]!=b[i][j]):
				return 0
	return 1
def b():
	N,M=list(map(int,input().split()))
	A=[input()for _ in range(N)]
	B=[input()for _ in range(M)]
	flag=0
	for i in range(N-M+1):
		for j in range(N-M+1):
			if(A[i][j]==B[0][0]):
				flag=bsolve(A,B,i,j)
				if(flag==1):
					print("Yes")
					return 
	if(flag==1):
		print("Yes")
	else:
		print("No")
b()

Measured memory_bytes: 3064
#include <iostream>
#include <sstream>
#include <cstdio>
#include <cstring>
#include <string>
#include <algorithm>
#include <vector>
#include <queue>
#include <map>
#include <cmath>
using namespace std;
#define ll long long
#define fori(n) for(int i=0;i<n;i++)
#define forr(s,n) for(int i=s;i<n;i++)
#define forj(j,s,n) for(int j=s;j<n;j++)

int main(int argc, char const *argv[])
{
    ll x, y;cin>>x>>y;
    ll ans=0;
    switch (x)
    {
    case 1:
        ans+=300000;
        break;
    case 2:
        ans+=200000;
        break;
    case 3:
        ans+=100000;
        break;
    default:
        break;
    }
    switch (y)
    {
    case 1:
        ans+=300000;
        break;
    case 2:
        ans+=200000;
        break;
    case 3:
        ans+=100000;
        break;
    default:
        break;
    }
    if(x==1&&y==1)ans+=400000;
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 256
n = int(input()) - 1

alphabet = []
for i in range(26):
    alphabet.append(chr(ord('a') + i))

exponent = 1
res = n
lst = [alphabet[res % 26]]
res //= 26
while res != 0:
    res -= 1
    lst.append(alphabet[res % 26])
    res //= 26

lst.reverse()
print("".join(lst))


Measured memory_bytes: 61688
#include <bits/stdc++.h>
#define ll long long
#include <iomanip>

using namespace std;

int main() {
	ios::sync_with_stdio(0);
	cin.tie(0);
    double N;
    cin >> N;
    double n = N/ 3.0;
    std::cout << std::fixed;
    std::cout << std::setprecision(10);
    cout << pow(n,3);

}


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

#define ll long long
#define rep(i,x,y) for(int i=x;i<y;i++)
#define rel(i,x,y) for(int i=x-1;i>=y;i--)
#define all(x) x.begin(),x.end()
const ll INF = (ll)(1e18)+7;
vector<ll> a;

ll smaller_cnt(ll x){
    ll cnt = 0;
    rep(i,0,a.size()){
        ll left = -1,right = a.size();
        if(a[i]>=0){ //plus
            while(left+1<right){
                ll mid = (left+right)/2;
                if(a[mid] * a[i] < x) left = mid;
                else right = mid;
            }
            cnt += right;
        }else{ //minus
            while(left+1<right){
                ll mid = (left+right)/2;
                if(a[mid] * a[i] < x) right = mid;
                else left = mid;
            }
            cnt += a.size()-right;
        }
        if(a[i] * a[i] < x) cnt--; //対角線が範囲に入っていたら消す
    }
    cnt /= 2; // 対照側も消す
    return cnt;
}

int main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    ll n,k;
    cin >> n >> k;
    rep(i,0,n){
        ll tmp;
        cin >> tmp;
        a.push_back(tmp);
    }
    sort(all(a));
    ll left = -INF,right = INF;
    while(left+1<right){
        ll mid = (left+right) / 2;
        if(smaller_cnt(mid)<k) left = mid;
        else right = mid;
    }
    cout << left << endl;
}

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

class Main {

	void solve() {

		int a = inint(), b = inint();
		out.println(b>=a ? a : a-1);

	}

	public static Scanner in = new Scanner(System.in);
	public static PrintWriter out = new PrintWriter(System.out);

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

	public int inint() {
		return in.nextInt();
	}

	public String instr() {
		return in.next();
	}

	public int[] inintar(int num) {
		int[] a = new int[num];
		for (int i=0; i<num; i++) {
			a[i] = in.nextInt();
		}
		return a;
	}

	public char[] incharar() {
		return in.next().toCharArray();
	}

}

Measured memory_bytes: 21716
#include <bits/stdc++.h>
#define rep(i, n) for(int (i)=0; (i)<(n); (i)++)

using namespace std;
typedef long long ll;

template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }

int main()
{
  int r, D, x2000;
  cin >> r >> D >> x2000;

  vector<ll> x(11);
  x[0]=x2000;
  for(int i=0; i<10; i++)
    {
      x[i+1]=r*x[i]-D;
      cout << x[i+1] << endl;
    }
  
  


  return 0;
}


//cout << setprecision(13);
//next_permutation();
//__gcd();
//reverse();
//set ,tuple ,pair;
//bitset
//vector.find
//vector.count



Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cmath>
using namespace std;
double a,b,x,s;
int main(){
	cin>>a>>b>>x;
	s=x/a;
	double pi=acos(-1.0);
	if(2.0*s<a*b){
        double opt=a*b*b/(2.0*x);
		double now=atan(opt);
		double ans=now/pi*180;
		printf("%.10lf",ans);
	}
	else { 
		double opt=(double)2.0*b/a-2.0*x/a/a/a;
		double now=atan(opt);
		double ans=now/pi*180;
		printf("%.10lf",ans);
	}
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
//datatypes
	#define int long long
	#define vi vector<int>
	#define si set<int>
	#define vii vector<ii>
	#define ii pair<int,int>
	#define mii map<int,int>
	#define M 1000000007
	#define pi 3.141592653589793
	#define in(x) int x; cin>>x;
	#define sz(x) (int)x.size()
	#define fr first
	#define sc second
	#define pb push_back
	#define mkp make_pair
	#define inputFile \
	    freopen("input.txt", "r", stdin); 
	#define outputFile \
	    freopen("output.txt", "w", stdout)
	#define rep(i,a,b) for(int i=a; i<b; i++)
	#define trav(a) for(auto &x:a)
	#define test cout<<"hello\n";
	#define all(x) (x).begin(),(x).end()
	#define mem0(x) memset(x, 0, sizeof(x))
	#define mem1(x) memset(x, -1, sizeof(x))
	#define sa(x) std::sort(all(x))
	#define sd(x) std::sort(all(x),greater<int>())

signed solve()
{
	int n;
	cin>>n;
	double p[n+1];
	rep(i,1,n+1)cin>>p[i];
	double dp[n+1][n+1];
	mem0(dp);
	dp[1][0]=1-p[1];
	dp[1][1]=p[1];
	rep(i,2,n+1)
	{
		rep(j,0,n+1)
		{
			dp[i][j] = p[i]*dp[i-1][j-1] + (1-p[i])*dp[i-1][j];
		}
	}
	/*rep(i,0,n+1)
	{
		rep(j,0,n+1)
		cout<<fixed<<setprecision(9)<<dp[i][j]<<" ";
		cout<<endl;
	}
*/
	double ans=0;
	//cout<<n/2+(n)%2<<endl;
	/*int k;
	if(n&1)
		k=n/2+1;
	else k=n/*/
	rep(i, n/2+1, n+1)
	ans+=dp[n][i];

	cout<<fixed<<setprecision(9)<<ans;

	return 0;
}

signed main()
{
	ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
	int t=1;
	//cin>>t;
	while(t--) solve();
	//cout << "\nTime elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << " s.\n";
	return 0;
}

Measured memory_bytes: 70656
N = int(input())
A = list(map(int, input().split()))
total = sum(A)
mid = total // 2
sum_left, sum_left2 = 0, 0
seperation_i = 0
# for i, l in enumerate(A[:-1]):
for i, l in enumerate(A):
  sum_left += l
  if sum_left >= mid:
    seperation_i = i
    sum_left2 = sum_left - l
    break
sum_right, sum_right2 = sum(A[seperation_i + 1:]), sum(A[seperation_i:])
ans = min(abs(sum_left - sum_right), abs(sum_left2 - sum_right2))
print(ans)

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

int main(){
    int n,d;
    cin>>n>>d;
    vector<vector<int>> x(n);
    rep(i,n){
        x[i]=vector<int>(d);
        rep(j,d){
            cin>>x[i][j];
        }
    }
    int ans=0;
    for(int i=0; i<n-1; i++){
        for(int j=i+1; j<n; j++){
            int d2=0;
            for(int k=0; k<d; k++){
                d2+=(x[i][k]-x[j][k])*(x[i][k]-x[j][k]);
            }
            int sq=int(pow(d2,0.5));
            if(sq*sq==d2)ans++;
        }
    }
    cout<<ans;
    
    return 0;
}

Measured memory_bytes: 512
#if __cplusplus >= 201103L
#include <bits/stdc++.h>
#endif
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cctype>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
using namespace std;

typedef long long ll;
const int N = 105;
const int M = 1000000007;

int h, w;
char mp[N][N];
int mov[4][2] = { -1, 0, 0, -1, 1, 0, 0, 1};

inline bool judge(int x, int y) {
  return x >= 0 && x < h && y >= 0 && y < w;
}

void dfs(int x, int y, char c) {
  mp[x][y] = '.';
  for (int i = 0; i < 4; i++) {
    int xx = x + mov[i][0], yy = y + mov[i][1];
    if (judge(xx, yy) && mp[xx][yy] == c) { dfs(xx, yy, c); }
  }
}

int main() {
  while (scanf("%d%d", &h, &w), h) {
    for (int i = 0; i < h; i++) {
      scanf("%s", mp[i]);
    }
    int ans = 0;
    for (int i = 0; i < h; i++) {
      for (int j = 0; j < w; j++) {
        if (mp[i][j] != '.') { dfs(i, j, mp[i][j]); ans++; }
      }
    }
    printf("%d\n", ans);
  }
}

Measured memory_bytes: 3776
#pragma GCC optimize("O3")

#include <bits/stdc++.h>

typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
#define F first
#define S second
#define pii pair<int,int>
#define pll pair<ll, ll>
#define vi vector<int>
#define vll vector<ll>
#define vii vector<pii>
#define read(FILE)  freopen(FILE, "r", stdin);
#define out(FILE) freopen(FILE, "w", stdout);
#define clr(x, y) memset(x,y,sizeof(x));
#define IO ios_base::sync_with_stdio(0);cin.tie(0); cout.tie(0);
#define all(x) x.begin(),x.end()
#define rep(i, m, n) for(int i=m ; i<n ; i++)
#define forr(i, m, n) for(ll i=m ; i<=n ; i++)
#define endl '\n'
#define pb push_back
#define re return
#define point complex<double>
const int N = 3e5 + 5;
const int OO = 1e9 + 7;
using namespace std;

ll solve(ll n) {
    re n * n * n * n * n;
}

int main() {
    IO;
    ll x;
    cin >> x;
    forr(a, -200, 200) {
        forr(b, -200, 200) {
            if ((solve(a) - solve(b)) == x)
                re cout << a << " " << b, 0;
        }
    }


}

Measured memory_bytes: 3656
// warm heart, wagging tail,and a smile just for you!
//
//                            ▒█████▒▒
//                             ██████████▒
//                             ▒████████████▒
//                            ██████████████████
//                           ████████████████████▒
//                          ▒██████████████████████▒
//                          ▒███████████████████████
//                      ▒████▒▒▒▒▒▒█████████████████▒
//                    ███▒▒▒▒▒▒██████████████████████▒▒▒
//                  ▒██▒▒███████████████████████▒▒▒▒▒██████
//                 ▒█████████████████████████▒▒▒▒▒▒█████████▒
//                 ▒█████████████████████▒▒▒▒▒▒██████████████
//                  ▒████         ████▒▒▒▒▒████         ████▒
//              ▒█████▒    ████    ▒▒▒▒███████    ████    ██████▒
//            ▒██▒▒▒▒▒    ██████    █████████    ██████    ██▒▒▒██▒
//           █████████   ████████   █████████   ████████   ▒▒▒▒█████
//          ▒█████████    ██████    ████████▒    ██████    █████████
//          ▒██████████    ████    █████▒▒▒▒▒▒    ████    ██████████
//           ████████████        ▒▒▒▒▒▒▒████████        ███████████▒
//       ▒██████████▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒███████████████████████████████████▒
//     ███▒▒▒▒▒▒▒▒▒▒▒▒█████████████████████████████████████████▒▒████████▒
//   ▒▒▒▒▒▒▒▒▒██████████████                         ███████▒▒▒▒███████████
//   █████████████████████████                     ███████▒▒▒██████████████▒
//   █████████████████████████████             ███████▒▒▒██████████████████▒
//   ██████████████████████████████████████████████████████████████████████
//    ██████████████████████████████████████████████████████████████████▒
//      ▒█████████████████▒▒▒▒▒▒▒██████████████████████████████████▒▒▒
//
#include "bits/stdc++.h"
using namespace std;
#define MOD 1000000007
//#define MOD 998244353
const double EPS = 1e-9;
#define INF (1LL<<60)
#define D double
#define fs first
#define sc second
#define int long long
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define RFOR(i,a,b) for(int i = (b-1);i>=(a);--i)
#define REP(i,n)  FOR(i,0,(n))
#define RREP(i,n) RFOR(i,0,(n))
#define ITR(itr,mp) for(auto itr = (mp).begin(); itr != (mp).end(); ++itr)
#define RITR(itr,mp) for(auto itr = (mp).rbegin(); itr != (mp).rend(); ++itr)
#define range(i,a,b) ((a)<=(i) && (i)<(b))
#define debug(x)  cout << #x << " = " << (x) << endl;
#define SP << " " << 
typedef pair<int,int> P;
typedef vector<int> vec;
typedef vector<vector<int>> mat;

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

  int x,a,b,n;
  cin >> x >> a >> b >> n;

  vector<string> s(n);
  REP(i,n) cin >> s[i];
  
  REP(i,n){
    if(s[i] == "nobiro") x = max(0LL,x+a);
    if(s[i] == "tidime") x = max(0LL,x+b);
    if(s[i] == "karero") x = 0;
  }

  cout << x << endl;

  return 0;
}


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

using namespace std;


int main() {
  int N;
  cin >> N;
  vector<int> H(N);
  for (int i = 0; i < N; i++) cin >> H[i];

  int ans = 1;
  for (int i = 1; i < N; i++) {
    bool flag = true;
    for (int j = 0; j < i; j++) {
      if (H[i] < H[j]) {
        flag = false;
        break;
      }
    }
    if(flag) ans++;
  }

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

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <bits/extc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (n); i++)
#define all(x) (x).begin(), (x).end()
typedef long long int ll;
typedef pair<int, int> pr;
typedef priority_queue<int> p_int_max;
typedef priority_queue<int, vector<int>, greater<int>> p_int_min;

int a, b;
bool f = false;
int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);

    cin >> a >> b;
    rep(i, 2000)
    {
        if (i * 8 / 100 == a && i / 10 == b)
        {
            cout << i << "\n";
            f = true;
            break;
        }
    }
    if (!f)
        cout << "-1\n";
}

Measured memory_bytes: 256
import java.util.*;
public class Main{
        public static void main(String[] args){
                Scanner sc = new Scanner(System.in);
                int[] az = new int[26];
                String s = sc.next();
                Arrays.fill(az , 0);
                for(int i = 0 ; i < s.length() ; i++){
                        az[(int)(s.charAt(i) - 97)]++;
                }
                sc.close();
                boolean ebishu = true;
                for(int i = 0 ; i < 26 ; i++){
                        if(az[i] % 2 != 0) ebishu = false;
                }
                if(ebishu){
                        System.out.println("Yes");
                }else{
                        System.out.println("No");
                }
        }
}//a_97
//鶏になれ

Measured memory_bytes: 35484
INTEGER N,B,ANSWER
INTEGER,ALLOCATABLE,DIMENSION(:)::X,Y
READ*,N
ALLOCATE(X(N))
ALLOCATE(Y(N))
READ*,X
Y=0
B=1
ANSWER=0
DO
  ANSWER = ANSWER+1
  Y(X(B))=Y(X(B))+1
  IF (Y(X(B))==2) THEN
   PRINT"(I0)",-1
   STOP
  ENDIF
  IF(X(B)==2) THEN
   PRINT"(I0)",ANSWER
   STOP
  ENDIF
  B=X(B)
END DO
END

Measured memory_bytes: 2048
import java.util.Arrays;
import java.util.Scanner;

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

	int[][] memo;
	int[] ans;
	int n, m;

	int rep(int masked, int answer) {
		if (memo[masked][answer] != -1) {
			return memo[masked][answer];
		}
		int count = 0;
		for (int i = 0; i < n; i++) {
			if ((ans[i] & masked) == answer) {
				count++;
			}
		}
		if (count <= 1) {
			memo[masked][answer] = 0;
			return 0;
		}
		int min = 1000;
		for (int i = 0; i < m; i++) {
			int shi = 1 << i;
			if ((masked & shi) != 0) {
				continue;
			}
			int z = shi;
			min = Math.min(min, Math.max(rep(masked | z, answer), rep(masked | z, answer | z)));
		}
		memo[masked][answer] = min + 1;
		return min + 1;
	}

	void solver() {
		Scanner sc = new Scanner(System.in);
		while (true) {
			m = sc.nextInt();// the number of features 0<m<=11
			n = sc.nextInt();// the number of objects 0<n<=128
			memo = new int[1 << 11][1 << 11];
			for (int i = 0; i < (1 << 11); i++) {
				Arrays.fill(memo[i], -1);
			}
			if (m == 0 && n == 0)
				break;
			ans = new int[n];
			for (int i = 0; i < n; i++) {
				ans[i] = sc.nextInt(2);
			}
			int m = rep(0, 0);
			System.out.println(m);
		}
	}
}

Measured memory_bytes: 225528
#include <bits/stdc++.h>
 
#define fi first
#define se second
#define mp make_pair
#define mt make_tuple
#define pb push_back
#define INF  (1<<30)
#define INFL (1LL<<60)
#define MOD 998244353LL
#define EPS ((ld)(1e-9))
 
#define sz(x) ((int)(x).size())
#define setz(x) memset(x, 0, sizeof(x))
#define all(x) (x).begin(), (x).end()
#define rep(i, e) for (int i = 0, _##i = (e); i < _##i; i++)
#define repp(i, s, e) for (int i = (s), _##i = (e); i < _##i; i++)
#define repr(i, s, e) for (int i = (s)-1, _##i = (e); i >= _##i; i--)
#define repi(i, x) for (auto &i : (x))
 
 
using namespace std;
 
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<double, double> pdd;
typedef pair<ll, ll> pll;
 
template<typename T, typename V>
ostream &operator<<(ostream &os, const pair<T, V> pai) { 
    return os << '(' << pai.first << ' ' << pai.second << ')';
}
 
template<typename T>
ostream &operator<<(ostream &os, const vector<T> v) {
    cout << '[';
    for (auto p : v) cout << p << ",";
    cout << "]";
    return os;
}
 
template<typename T>
ostream &operator<<(ostream &os, const set<T> v) {
    cout << "{";
    for (auto p : v) cout << p << ",";
    cout << "}";
    return os;
}
 
template<typename T, typename V>
ostream &operator<<(ostream &os, const map<T, V> v) {
    cout << "{";
    for (auto p : v) cout << p << ",";
    cout << "}";
    return os;
}
 
#ifndef __SOULTCH
#define debug(...) 0
#define endl '\n'
#else
#define debug(...) cout << " [-] ", _dbg(#__VA_ARGS__, __VA_ARGS__)
template<class TH> void _dbg(const char *sdbg, TH h){ cout << sdbg << '=' << h << endl; }
template<class TH, class... TA> void _dbg(const char *sdbg, TH h, TA... a) {
    while(*sdbg != ',') cout << *sdbg++;
    cout << '=' << (h) << ','; 
    _dbg(sdbg+1, a...);
}
#endif
 
template<typename T> void get_max(T &a, T b) {a = max(a, b);}
template<typename T> void get_min(T &a, T b) {a = min(a, b);}

int main(void) {
    iostream::sync_with_stdio(false);
    cin.tie(nullptr), cout.tie(nullptr);  

    int D, N; cin >> N >> D;
    cout << (N-1)/(2*D+1)+1 << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <iomanip> //! for setprecision(10)
#include <math.h>
#include <algorithm>
#include <functional> 
#include <string>
#include <vector>

#include <cstring>
#include <set>
#include <map>
#include <queue>
#include <utility>
#include <limits.h>

using namespace std;

typedef long long LL;

#define rep(i,n) for (int i = 0; i < (n); ++i)
#define dump(c) { for (auto it = c.begin(); it != c.end(); ++it) if (it == c.begin()) cout << *it; else cout << ' ' << *it; cout << endl; } 
#define dumpMap(m) { for (auto it: m) cout << it.first << "=>" << it.second << ' '; }

const int MOD = 1000000007;

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

    vector<int> data = { 1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51 };
 
    int N;
    cin >> N;
    
    cout << data[N-1] << endl;

    return 0;
}


Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
using ll = long long;

int main() {
    int n;
    cin >> n;
    vector<int> p(n);
    for(int i = 0; i < n; i++){
        cin >> p[i];
        p[i]--;
    }
    vector<int> index(n);
    for(int i = 0; i < n; i++){
        index[p[i]] = i;
    }
    set<int> s;
    ll ans = 0;
    for(int j = n-1; j >= 0; j--){
        int i = index[j];
        ll c = 0;
        s.insert(i);
        vector<int> l(2, -1);
        vector<int> r(2, n);
        {
        auto itr = s.find(i);
        for(int k = 0; k < 2; k++){
            if(itr == s.begin()) break;
            itr--;
            l[k] = *itr;
        }
        }
        {
        auto itr = s.find(i);
        for(int k = 0; k < 2; k++){
            itr++;
            if(itr == s.end()) break;
            r[k] = *itr;
        }
        }
        vector<int> ls(2);
        ls[0] = i-l[0]; ls[1] = l[0]-l[1];
        vector<int> rs(2);
        rs[0] = r[0]-i; rs[1] = r[1]-r[0];
        c = (ll)ls[0] * rs[1] + (ll)ls[1] * rs[0];
        ans += c * (j+1);
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 5760
n = int(input())
results = 0
number = 0
for i in range(n + 1):
    if i == 0:
        continue
    if i == 1:
        number = 1
        continue
    count = 0
    v = i

    while v % 2 == 0:
        count += 1
        v = v / 2
    if results < count:
        results = count
        number = i
    continue
print(number)

Measured memory_bytes: 3060
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int a,b,c=0;
    cin>>a>>b;
    int temp=a,t,k=a,rev=0,rem;
    t=abs(a-b)+1;
    while(t--)
    {
        while( temp != 0)
        {
            rem = temp % 10;
            rev = rev * 10 + rem;
            temp = temp / 10;
        }
        if(rev==k)
            c++;
        k=k+1;
        temp=k;
        rev=0;
    }
    cout<<c<<endl;
}


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

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

  vector<int>a(N);
  int next, now=1, count=0;

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

  while(1){
    next = a.at(now-1);
    a.at(now-1) = 0;
    count++;
    if(next == 2){
      cout << count << endl;
      return 0;
    }

    if(next == 0){
      cout << -1 << endl;
      return 0;
    }
    now = next;
  }
  cout << count << endl;
}


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

int main(){
  string s,tmps;
  int q,tmpin,tmpq,frflag=0;
  cin>>s>>q;
  
  rep(i,0,q){
    cin>>tmpin;
    if(tmpin==1){frflag++;}
    else{
      cin>>tmpq>>tmps;
      if(frflag%2==0){
        if(tmpq==1){s.insert(0,tmps);}
        else{s+=tmps;}
      }
      else{
        if(tmpq==1){s+=tmps;}
        else{s.insert(0,tmps);}
      }
    }
  }
  
  if(frflag%2!=0){reverse(s.begin(),s.end());}
  
  cout<<s<<endl;
  
  return 0;
}


Measured memory_bytes: 900
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define _GLIBCXX_DEBUG
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(){
  string n;
  cin >> n;
  if(stoi(n)>=100)
   n = n[2];
  else if(stoi(n)>=10)
   n = n[1];

  int k;
  k = stoi(n);
  if(k == 2 || k ==4 || k == 5 || k == 7 || k == 9)
    cout << "hon" << endl;
  else if (k == 0 || k == 1 || k== 6 || k == 8)
    cout << "pon" << endl;
  else
    cout << "bon" << endl;
}


Measured memory_bytes: 3616
from itertools import groupby

S = input()
K = int(input())

A = [len(tuple(v)) for _, v in groupby(S)]
if len(A) == 1:
    print((len(S) * K) // 2)
    quit()

t = sum(a // 2 for a in A)
if S[0] == S[-1]:
    l, r = A[0], A[-1]
    m = l // 2 + r // 2 - (l + r) // 2
    print(t * K - m * (K - 1))
else:
    print(t * K)


Measured memory_bytes: 3064
A = list(map(int, input().split()))
C = [0] * 3
N = [0,1,2,0,1]
for i in range(3):
  a = N[i]
  b = N[i+1]
  c = N[i+2]
  C[i] += ( abs(A[b]-A[a]) + abs(A[c]-A[b]) )
print(min(C))

Measured memory_bytes: 3064
#include <stdio.h>
#define MAX 100005
#define NIL -1

typedef struct{
  int p,l,r;
} Node;

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

void print(int u){
  int i,c;
  printf("node %d: ",u);
  printf("parent = %d, ",T[u].p);
  printf("depth = %d, ",D[u]);
  if(T[u].p == NIL) printf("root, ");
  else if(T[u].l == NIL) printf("leaf, ");
  else printf("internal node, ");
  printf("[");
  for(i = 0,c = T[u].l;c != NIL;i++,c = T[c].r){
    if(i) printf(", ");
    printf("%d",c);
  }
  printf("]\n");
}

int rec(int u,int p){
  D[u] = p;
  if(T[u].r != NIL) rec(T[u].r,p);
  if(T[u].l != NIL) rec(T[u].l,p + 1);
}

int main(){
  int i,j,d,v,c,l,r;
  scanf("%d",&n);
  for(i = 0;i < n;i++) T[i].p = T[i].l = T[i].r = NIL;
  for(i = 0;i < n;i++){
    scanf("%d %d",&v,&d);
    for(j = 0;j < d;j++){
      scanf("%d",&c);
      if(j == 0) T[v].l = c;
      else T[l].r = c;
      l = c;
      T[c].p = v;
    }
  }
  for(i = 0;i < n;i++){
    if(T[i].p == NIL) r = i;
  }
  rec(r,0);
  for(i = 0;i < n;i++) print(i);
  return 0;
}

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

// @@ !! LIM()
// --> 
// @@ !! LIM  -- end mark --

int main(/* int argc, char *argv[] */) {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
  cout << setprecision(20);

  ll N; cin >> N;
  vector<ll> A(N + 1), pos(N + 1);
  for (ll i = 1; i <= N; i++) {
    ll a; cin >> a;
    A[i] = a;
    pos[a] = i;
  }
  set<ll> app;

  ll ans = 0;
  for (ll i = 1; i <= N; i++) {
    ll t = pos[i];
    auto itq = app.lower_bound(t);
    ll q = itq == app.end() ? N + 1 : *itq;
    ll p = itq == app.begin() ? 0 : *(--itq);
    ans += i * (t - p) * (q - t);
    app.insert(t);
  }
  cout << ans << endl;

  return 0;
}



Measured memory_bytes: 15804
<?php
// $n = (int)trim(fgets(STDIN));
$input = explode(' ', trim(fgets(STDIN)));

$a = (int)$input[0];
$b = (int)$input[1];
$x = (int)$input[2];

$height = $x / ($a*$a);
$area = $a * $height;

$half_height = $b / 2;

if ($height <= $half_height) {
	$h = $b;
	$e = $area * 2 / $b;
	// $result = rad2deg(atan($h/$e));
} else {
	$h = ($b - $height) * 2;
	$e = $a;
}
$result = rad2deg(atan($h/$e));
echo $result;

Measured memory_bytes: 4856
#include<bits/stdc++.h>
using namespace std;
inline int read(){
	char c=getchar();int x=0,f=1;
	while(c<'0'||c>'9'){ if(c=='-')f=-1;c=getchar();}
	while(c>='0'&&c<='9') x=(x<<3)+(x<<1)+c-'0',c=getchar();
	return x*f;
}
char s[1005];
int dong,xi,na,bei;
int main(){
	scanf("%s",s+1);int len=strlen(s+1);
	for(int i=1;i<=len;++i){
		if(s[i]=='N') bei=1;
		if(s[i]=='W') xi=1;
		if(s[i]=='S') na=1;
		if(s[i]=='E') dong=1;
	}
	if(bei^na){
		printf("No\n");
		return 0;
	}
	if(xi^dong){
		printf("No\n");
		return 0;
	}
	printf("Yes\n");
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#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 ALL(obj) (obj).begin(), (obj).end()
const int INF = 100100100;
const int MOD = (int)1e9 + 7;
typedef long long ll;

using namespace std;

int main() {
   ll n, ans = 1;
	cin >> n;
	for (int i = 1; i <= n; ++i) {
		ans *= i;
		ans %= MOD;
	}
 
	cout << ans << endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<cmath>
#include<cstdlib>
#include<cstdio>
#include<cstring>
#include<iomanip>
#include<string>
#include<set>
#include<map>
#include<vector>
#include<queue>
#include<stack>
#include<utility>
#define PI acos(-1.0)
using namespace std;
const int N = 2e5+5;
vector<int> road[N];
int ans[N];
int n,m,u,v;
void bfs(){
	queue<int> q;
	q.push(1);
	while(!q.empty()){
		int t = q.front();
		q.pop();
		for(int i = 0;i < road[t].size();i++){
			if(!ans[road[t][i]]){
				q.push(road[t][i]);
				ans[road[t][i]] = t;
			}	
		}	
			
	}
}
int main(){
	
	cin >> n >> m;
	for(int i = 1;i <= m;i++){
		scanf("%d %d",&u,&v);
		road[u].push_back(v);
		road[v].push_back(u);
	}
	bfs();
	int flag = 1;
	for(int i = 2;i <= n;i++){
		if(!ans[i]){
			flag = 0;
			break;
		}
	}
	if(flag){
		printf("Yes\n");
		for(int i = 2;i <= n;i++){
			printf("%d\n",ans[i]);
		}
	}
	else cout << "No" << endl;
	return 0;
}

Measured memory_bytes: 12876
import numpy as np
S = input()
T = input()
B = np.zeros(len(S) - len(T) + 1)
for i in range(len(S) - len(T) + 1):
  a = 0
  for j in range(len(T)):
    if S[i + j] != T[j]:
      a +=1
  B[i] = a
print(int(min(B)))

Measured memory_bytes: 27164
"""
高橋君はとりあえず、青木君から最も遠い木の端を目指すのがベスト。
また、目指すべき木の端までの距離に関しては、高橋くんよりも自分の方が近くなくてはならない。
また、高橋君が捕まるときは、必ず木の端の一歩手前のノードになる。
つまり、青木君が移動しなくてはいけない最大距離は、高橋君が目指す木の端までの距離-1、ということになる。
とりま、高橋くん、青木君の初期位置から各ノードまでの距離を調べて、上記の条件にマッチする端を見つける。
"""
from collections import deque
N,u,v = map(int,input().split())
edges = [[] for _ in range(N+1)]
for _ in range(N-1):
    a,b = map(int,input().split())
    edges[a].append(b)
    edges[b].append(a)

takahashi = [None]*(N+1)
que = deque([(0,u,0)])
while que:
    step,cur,par = que.popleft()
    takahashi[cur] = step
    for nx in edges[cur]:
        if nx == par:
            continue
        que.append((step+1,nx,cur))

aoki = [None]*(N+1)
que = deque([(0,v,0)])
while que:
    step,cur,par = que.popleft()
    aoki[cur] = step
    for nx in edges[cur]:
        if nx == par:
            continue
        que.append((step+1,nx,cur))
ans = 0
for i in range(1,N+1):
    if takahashi[i] < aoki[i]:
        ans = max(ans,aoki[i]-1)
print(ans)

Measured memory_bytes: 98748
n, m = map(int, input().split())
a = list(map(int, input().split()))
a.sort(reverse=True)
x = []
for _ in range(m):
    b, c = map(int, input().split())
    x.append([b, c])

x.sort(key=lambda p: p[1], reverse=True)

ret = 0
for b, c in x:
    if not a:
        break
    if c > a[-1]:
        while c > a[-1]:
            ret += c
            a.pop()
            b -= 1
            if b == 0:
                break
            if not a:
                break
    else:
        break

print(ret + sum(a))



Measured memory_bytes: 99156
#include<bits/stdc++.h>
using namespace std;
#define ll long long
int main()
{
    ll n,m,k,l,o,p;
    cin>>n>>m>>k;
    ll a[n+1],b[m+1];
    a[0]=0;
    b[0]=0;
    for(ll i=1;i<=n;i++)
    {
        ll x,y;
        cin>>x;
        a[i]=x+a[i-1];
        
    }
    for(ll i=1;i<=m;i++)
    {
        ll x,y;
        cin>>x;
        b[i]=x+b[i-1];
    }
    ll ans=0;
    o=m;
    for(ll i=0;i<=n;i++)
    {
        for(ll j=o;j>=0;j--){
            if(a[i]+b[j]<=k){
                o=j;
                if(i+j>ans){
                    ans=i+j;
                }
                break;
            }
        }
    }

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


Measured memory_bytes: 6752
#include <bits/stdc++.h>
#define fastIO (cin.tie(0), cout.tie(0), ios::sync_with_stdio(false))
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define precise(i) fixed << setprecision(i)
using lint = long;
using llint = long long;
using namespace std;

int sum_digit(int n) {
    int sum = 0;
    while (n > 0) {
        sum += n % 10;
        n /= 10;
    }
    return sum;
}

int main() {
    fastIO;
    int n;
    cin >> n;
    if (n % sum_digit(n) == 0) {
        cout << "Yes";
    } else {
        cout << "No";
    }
}

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

char s[1000000];
ll t[3][1000001];

int main() {
  int n, q;
  scanf("%d%s%d", &n, s, &q);

  V D, C;
  rep(i, n) {
    rep(j, 3) t[j][i+1] = t[j][i];
    switch(s[i]){
      case 'D':
        ++t[0][i+1];
        D.push_back(i+1);
        break;
      case 'M':
        ++t[1][i+1];
        break;
      case 'C':
        ++t[2][i+1];
        C.push_back(i);
        break;
    }
  }

  ll suma = 0, sumc = 0;
  for (auto &a : D) suma += t[1][a] * t[2][a];
  for (auto &c : C) sumc += t[1][c] * t[0][c];

  rep(_, q) {
    int k; 
    scanf("%d", &k);
    ll ans = suma + sumc;
    for (auto &a : D) {
      if (a+k-1 < n) ans -= t[1][a] * t[2][a+k-1];
      else ans -= t[1][a] * t[2][n];
    }
    for (auto &c : C) {
      if (c-k+1 > 0) ans -= t[1][c] * t[0][c-k+1];
      else ans -= t[1][c] * t[0][0];
    }
    printf("%lld\n", ans);
  }
  return 0;
}


Measured memory_bytes: 28652
# include <iostream>
# include <cstdio>
# include <cstdlib>

using namespace std ;

const long long INF = 1e18 ;

long long a[100005] ;
int n ;
long long ans = 1 ;

long long qmul( long long a , long long b )
{
	long long res = 0 ;
	while ( b )
	{
		if ( b & 1 )
		{
			res = res + a ;
			if ( res > INF ) 
			{
				puts("-1") ;
				exit( 0 ) ;
			}
		}
		a = a + a ;
		b >>= 1 ;
		// printf("a:%lld b:%lld\n" , a , b) ;
		if ( b && a > INF ) 
		{
			// printf("a:%lld\n" , a) ;
			puts("-1") ;
			exit( 0 ) ;
		}
	}
	// puts("") ;
	return res ;
}

int main()
{
	scanf("%d" , &n) ;
	for ( int i = 1 ; i <= n ; i++ )
	{
		scanf("%lld" , &a[i]) ;
		// ans = qmul( ans , a[i] ) ;
		// printf("%lld\n" , ans) ;
	}
	for ( int i = 1 ; i <= n ; i++ )
	{
		if ( a[i] == 0 )
		{
			puts("0") ;
			return 0 ;
		}
	}
	for ( int i = 1 ; i <= n ; i++ )
	{
		// printf("%lld\n" , ans) ;
		ans = qmul( ans , a[i] ) ;
	}
	printf("%lld\n" , ans) ;
	return 0 ;
}

Measured memory_bytes: 4608
#include<bits/stdc++.h>
#define INF 1e9
#define llINF 1e18
#define MOD 1000000007
#define pb push_back
#define mp make_pair 
#define F first
#define S second
#define ll long long
#define vi vector<ll>
#define vvi vector<vi>
#define BITLE(n) (1LL<<((ll)n))
#define SHIFT_LEFT(n) (1LL<<((ll)n))
#define SUBS(s,f,t) ((s).substr((f),(t)-(f)))
#define ALL(a) (a).begin(),(a).end()
using namespace std;

int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  ll n;cin>>n;
  ll sum = 0;
  for(ll i=1;i<=n;i++){
    if(i % 3 != 0 && i%5 !=0)sum += i;
  }
  cout<<sum<<endl;
  return 0;
}


Measured memory_bytes: 3612
#include <bits/stdc++.h>
#define ll long long
#define dbg(x) cout<<#x<<"="<<x
#define nl cout<<"\n"
#define frn(i,n) for(int i = 0;i < n;i++)
#define fr(i,a,b) for(int i = a;i < b;i++)
#define pb push_back
using namespace std;



int main() {
  int n;
  cin>>n;
  bool y = false;
  frn(i,n) {
    char x;
    cin>>x;
    if(x == 'Y') y = true;
  }
  if(y) cout<<"Four";
  else cout<<"Three";
}

Measured memory_bytes: 256
import scala.collection.mutable._
import io.StdIn.readInt
import io.StdIn.readLine

object Main extends App {
  val out = new java.io.PrintWriter(System.out)

  def calculate(q:Array[Int],d:Array[Array[Int]]):Int = {
    val ts = q(0)
    val te = q(1)
    val st = q(2)

    val a = d.filter(_(2) == st)
    val map = HashMap.empty[Int,Array[Int]]
    val log = ListBuffer.empty[Tuple2[Int,Int]]
    a.foreach(l => {
      if(l(3) == 1) map.put(l(1),l)
      else {
        val e = map(l(1))
        log += {( e(0), l(0) )}
        }
    })
    // println(log.mkString)

    val time = Array.ofDim[Boolean](721)
    log.foreach(t => {
      val s = math.max(ts, t._1) -540
      val e = math.min(te, t._2) -540
      (s until e).foreach(time(_) = true)
    })
    time.count(_ == true)
  }

  def solve(s:String):Unit = {
    val Array(n, m) = s.split(" ").map(_.toInt)
    val r = readInt
    val d = Iterator.continually(readLine)
      .take(r)
      .map(_.split(" ").map(_.toInt))
      .toArray
    val q = readInt
    Iterator.continually(readLine)
      .take(q)
      .map(_.split(" ").map(_.toInt))
      .foreach(qd => out.println(calculate(qd,d)))
  }

  Iterator.continually(readLine)
    .takeWhile(_ != "0 0")
    .foreach(solve(_))
  
  out.flush
}


Measured memory_bytes: 59308