akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;

using ll = long long;
ll modinv(ll a, ll m) {
	assert(m > 0);
	if (m == 1) return 0;
	a %= m;
	if (a < 0) a += m;
	assert(a != 0);
	if (a == 1) return 1;
	return m - modinv(m, a) * m / a;
}

template <int MOD_> struct modnum {
private:
	int v;
public:
	static const int MOD = MOD_;

	modnum() : v(0) {}
	modnum(ll v_) : v(int(v_ % MOD)) { if (v < 0) v += MOD; }
	explicit operator int () const { return v; }
	friend bool operator == (const modnum& a, const modnum& b) { return a.v == b.v; }
	friend bool operator != (const modnum& a, const modnum& b) { return a.v != b.v; }

	modnum operator ~ () const {
		modnum res;
		res.v = modinv(v, MOD);
		return res;
	}

	modnum& operator += (const modnum& o) {
		v += o.v;
		if (v >= MOD) v -= MOD;
		return *this;
	}
	modnum& operator -= (const modnum& o) {
		v -= o.v;
		if (v < 0) v += MOD;
		return *this;
	}
	modnum& operator *= (const modnum& o) {
		v = int(ll(v) * ll(o.v) % MOD);
		return *this;
	}
	modnum& operator /= (const modnum& o) {
		return *this *= (~o);
	}

	friend modnum operator + (const modnum& a, const modnum& b) { return modnum(a) += b; }
	friend modnum operator - (const modnum& a, const modnum& b) { return modnum(a) -= b; }
	friend modnum operator * (const modnum& a, const modnum& b) { return modnum(a) *= b; }
	friend modnum operator / (const modnum& a, const modnum& b) { return modnum(a) /= b; }
};

using num = modnum<int(1e9)+7>;


int main(){
	ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
	int n;
	cin >> n;
	vector<bool> used(2*n, false);
	vector<bool> open(2*n, false);
	int empty = 0;
	for(int i = 0; i < n; i++){
		int r, s;
		cin >> r >> s;
		if(r >= 1) r--;
		if(s >= 1) s--;
		if(r > s) swap(r, s);
		if(r == -1 && s == -1){
			empty += 1;
		} else if(r == -1 && s >= 0){
			open[s] = true;
		} else if(r >= 0 && s >= 0){
			used[r] = used[s] = true;
		}
	}
	vector<vector<num> > dp(n+1, vector<num>(n+1, 0));
	dp[0][0] = 1;

	for(int a = 2*n-1; a >= 0; a--){
		if(used[a]) continue;
		vector<vector<num> > newdp(n+1, vector<num>(n+1, 0));
		if(open[a]){
			for(int h = 0; h <= n; h++){
				for(int p = 0; p <= n; p++){
					if(p < n) newdp[h][p+1] += dp[h][p];
					if(h > 0) newdp[h-1][p] += dp[h][p];
				}
			}
		} else {
			for(int h = 0; h <= n; h++){
				for(int p = 0; p <= n; p++){
					if(h < n) newdp[h+1][p] += dp[h][p];
					if(p > 0) newdp[h][p-1] += p * dp[h][p];
					if(h > 0) newdp[h-1][p] += dp[h][p];
				}
			}
		}
		dp = newdp;
	}
	num res = dp[0][0];

	num mult = 1;
	for(int i = 1; i <= empty; i++) mult *= i;
	res *= mult;

	cout << (int) res << '\n';
}

Measured memory_bytes: 1056
#include<iostream>
#include<cstdio>
#include<cstring>
#include<string>
#include<vector>
#include<cmath>
#include<algorithm>
#include<map>
#include<queue>
#include<deque>
#include<iomanip>
#include<tuple>
#include<cassert>
using namespace std;
typedef long long int LL;
typedef pair<int,int> P;
typedef pair<LL,int> LP;
const int INF=1<<30;
const LL MAX=1e9+7;

void array_show(int *array,int array_n,char middle=' '){
	for(int i=0;i<array_n;i++)printf("%d%c",array[i],(i!=array_n-1?middle:'\n'));
}
void array_show(LL *array,int array_n,char middle=' '){
	for(int i=0;i<array_n;i++)printf("%lld%c",array[i],(i!=array_n-1?middle:'\n'));
}
void array_show(vector<int> &vec_s,int vec_n=-1,char middle=' '){
	if(vec_n==-1)vec_n=vec_s.size();
	for(int i=0;i<vec_n;i++)printf("%d%c",vec_s[i],(i!=vec_n-1?middle:'\n'));
}
void array_show(vector<LL> &vec_s,int vec_n=-1,char middle=' '){
	if(vec_n==-1)vec_n=vec_s.size();
	for(int i=0;i<vec_n;i++)printf("%lld%c",vec_s[i],(i!=vec_n-1?middle:'\n'));
}

LL kai[6600];

long long int pow_mod(long long int p_a,long long int p_n,long long int p_p=1e9+7){
	//p_a^p_n mod p_p
	long long int p_b=1,p_t=1;
	for(;p_b<=p_n;p_b<<=1);
	for(p_b>>=1;p_b>0;p_b>>=1){
		p_t*=p_t;
		if(p_t>=p_p)p_t%=p_p;
		if(p_n&p_b)p_t*=p_a;
		if(p_t>=p_p)p_t%=p_p;
	}
	return p_t;
}

long long int gcd(long long int g_a,long long int g_b){
	if(g_a<g_b)gcd(g_b,g_a);
	if(g_b==0)return g_a;
	return gcd(g_b,g_a%g_b);
}

long long int divide(long long int d_a,long long int d_b,long long int d_p=1e9+7){
	// d_a/d_b mod d_p
	// prime:d_p is prime
	if(d_a>=d_p)d_a%=d_p;
	if(d_a<0)d_a+=d_p;
	if(d_b>=d_p)d_b%=d_p;
	if(d_b<0)d_b+=d_p;
	d_a*=pow_mod(d_b,d_p-2,d_p);
	return d_a%d_p;
}

int main(){
	int n,m;
	int i,j,k;
	LL a,b,c;
	LL p,q,r;
	LL s=0;
	cin>>n>>m;
	kai[0]=1;
	for(i=1;i<=3*n;i++){
		kai[i]=kai[i-1]*i%m;
	}
	for(i=0,p=1;i<=n;i++){
		for(j=0,q=1;i+j<=n;j++){
			b=p*q%m;
			b=b*kai[i]%m;
			b=b*kai[j]%m;
			b=b*kai[3*n-3*i-2*j]%m;
			a=divide(kai[3*n],b,m);
			s+=a;
			if(s>=m)s%=m;

			q*=2;
			if(q>=m)q%=m;
		}
		p*=3;
		if(p>=m)p%=m;
	}
	cout<<s<<endl;
}

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

using namespace std;

int main()
{
  // 入力回収
  unsigned long long int input[6];
  int bottleneck = 1;
  for (int ii = 0 ; ii < 6 ; ii++ ) {
    cin >> input[ii];
    if (ii == 0) continue;
    bottleneck = input[bottleneck] < input[ii] ? bottleneck : ii;
  }
  
  // 処理はすべてボトルネック依存
  // 人数 / ボトルネックの処理効率 + 5
  unsigned long long int total_time = 0;
  if (input[0] <= input[bottleneck]) {
    total_time = 5;
  }
  else {
    if (input[0] % input[bottleneck] == 0) {
      total_time = input[0] / input[bottleneck] + 5 - 1;
    }
    else {
      total_time = input[0] / input[bottleneck] + 5;
    }
  }

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

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long 
#define INF 999999999
#define rep(i,n) for(int i=0;i<n;i++)
const int MOD = 1000000007;
ll cnt =0;

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

  int a = 2*d +1;
  if(n%a == 0) cout << n/a << endl;
  else cout << n/a + 1 << endl;
  
}

Measured memory_bytes: 256
//baka wrong answer
#include <stdio.h>
#include <string.h>
#include <ctype.h>
#include <algorithm>
#define LL long long
#define min(a,b) (((a)<(b))?(a):(b))
#define max(a,b) (((a)>(b))?(a):(b))
#define abs(a) (((a)<0)?(-(a)):(a))
LL num1[1000000],num2[1000000],ans1[1000000],ans2[1000000];
LL p1[1000000],p2[1000000],far[1000000],del[1000000];

bool cmp1(const LL &a,const LL &b)
{
	return a>b;
}
bool cmp2(const LL &a,const LL &b)
{
	if (num2[a]==num2[b])
	{
		return num1[a]<num1[b];
	}
	return num2[a]<num2[b];
}

int main()
{
	//freopen("in.in","r",stdin);
	LL i,j,k,a,b,c,ans,n,pp1,pp2,rem,ans1,ans2;
	scanf("%lld",&n);
	for (i=1;i<=n;i++)
	{
		scanf("%lld%lld",&num1[i],&num2[i]);
	}
	std::sort(num1+1,num1+n+1,cmp1);
	std::sort(num2+1,num2+n+1);

	if (num1[1]<=0) if (num2[1]>=0) {printf("0\n");return 0;}
	ans=0;i=1;j=1;a=0;ans1=0;ans2=0;
	if (num1[1]>0)
	{
		while (1)
		{
			if (i>n) {break;}
			if (num1[i]<=a) {break;}
			ans+=abs(num1[i]-a);a=num1[i];
			i+=1;
			if (j>n) {break;}
			if (num2[j]>=a) {break;}
			ans+=abs(num2[j]-a);a=num2[j];
			j+=1;
		}
		ans+=abs(a);
		ans1=ans;
	}
	ans=0;i=1;j=1;a=0;
	if (num2[1]<0)
	{
		while (1)
		{
			if (j>n) {break;}
			if (num2[j]>=a) {break;}
			ans+=abs(num2[j]-a);a=num2[j];
			j+=1;
			if (i>n) {break;}
			if (num1[i]<=a) {break;}
			ans+=abs(num1[i]-a);a=num1[i];
			i+=1;
		}
		ans+=abs(a);
		ans2=ans;
	}
	ans=max(ans1,ans2);
	//printf("%llu %llu %llu\n",a,b,i);
	printf("%llu\n",ans);
	return 0;
}

Measured memory_bytes: 8320
#include<iostream>
#include<cstdio>

using namespace std;



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

Node T[1000000];
int D[1000000];


void dep(int u) {
	int d = 0;
	while (T[u].parent != -1) {
		u = T[u].parent;
		d++;
	}
	D[u] = d;
	cout << D[u] <<",";
}

int main() {
	int n; //節点の数
	int id; //節点の番号
	int k; //次数
	int child; //子
	int l, r;

	cin >> n;

	for (int i = 0; i < n; i++) {
		T[i].parent = -1;
		T[i].left = -1;
		T[i].right = -1;
	}

	for (int i = 0; i < n; i++) {
		cin >> id >> k;
		for (int j = 0; j < k; j++) {
			cin >> child;
			if (j == 0) {
				T[id].left = child;
			}
			else {
				T[l].right = child;
			}
			l = child;
			T[child].parent = id;
		}
		for (int i = 0; i < n; i++) {
			if (T[i].parent == -1) {
				r = i;
			}
		}
	}


	for (int i = 0; i < n; i++) {
		cout << "node " << i << ": " << "parent = " << T[i].parent << ", " << "depth = ";
		dep(i);
		if (T[i].parent == -1) {
			cout << " root, ";
		}
		else if (T[i].left == -1) {
			cout << " leaf, ";
		}
		else {
			cout << " internal node, ";
		}

		cout << "[";

		int child = T[i].left;
		int count = 0;
		while (child != -1) {
			if (count == 0) {
				cout << child;
			}
			else if (count != 0) {
				cout << ", " << child;
			}
			count++;
			child = T[child].right;
		}
		cout << "]" << endl;

	}

	//cout << T[1].left << endl;
	//cout << T[2].parent << endl;

	return 0;
}


Measured memory_bytes: 4260
n = gets.to_i
h = gets.split().map(&:to_i)
i = 0
n.times do
  if h[i] > h[i-1]
    h[i] -= 1
  end
  i += 1
end
r = h.sort
if h == r
  puts "Yes"
else
  puts "No"
end

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

using namespace std;

typedef long long ll;

// Defines and one-liners
#define INF 0x3f3f3f3f
#define LLINF 0x3f3f3f3f3f3f3f3f
template <typename T> inline T& back(vector<T> &vec) { return *(vec.end() - 1); }
template <typename T> inline void pop(vector<T> &vec) { return vec.erase(vec.end() - 1); }

// Scan, Debug, and other nonsense
template <typename T> ostream& operator<<(ostream& out,vector<T> iter){out<<"[";for(auto t:iter){out<<t<<", ";}out<<"]";return out;}
template <typename T> void printArray(ostream& out,T* arr,int sz){out<<"[";for(int i=0;i<sz;i++){out<<arr[i]<<", "; } out<<"]";}
#define OUT_OPERATOR(type, propa, propb) ostream& operator<<(ostream& out,type obj){out<<"("<<#propa<<"="<<obj. propa<<", "<<#propb<<"="<<obj. propb<<")";return out;}

void scan(){}
template<typename F, typename... R> void scan(F &f,R&... r){cin>>f;scan(r...);}
int di_; string dnms_, co_ = ",";
void debug_(){cout<<endl;}
template<typename F, typename... R> void debug_(F f,R... r){while(dnms_[di_] != ',')cout<<dnms_[di_++];di_++;cout<<": "<<f<<",";debug_(r...);}
#define debug(...) dnms_=#__VA_ARGS__+co_,di_=0,debug_(__VA_ARGS__)

const int MN = 1e5 + 1, MMO = 13 + 1;
const ll MOD = 1e9 + 7;
int n;
ll dp[MN][MMO];
string s;

inline int sub(int i, int j) {
    return (i - j + 13) % 13;
}

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

    scan(s);
    n = s.length();
    // s = " " + s;

    dp[0][0] = 1;
    for (int i = 0; i < n; i++) {
        for (int j = 0; j < MMO; j++) {
            if (!dp[i][j])
                continue;
            
            if (s[i] == '?') {
                for (int k = 0; k <= 9; k++) {
                    ll &val = dp[i + 1][(j * 10 + k) % 13];
                    val = (val + dp[i][j]) % MOD;
                }
            }
            else {
                ll &val = dp[i + 1][(j * 10 + (int)(s[i] - '0')) % 13];
                val = (val + dp[i][j]) % MOD;
            }
                // dp[i][j] = dp[i - 1][sub(j, (int)(s[i] - '0'))];
        }
    }

    cout << dp[n][5] << "\n";

    return 0;
}

Measured memory_bytes: 11472
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ConsoleApp2
{
    class Program
    {
        static void Main(string[] args)
        {
            var a = new List<int> { 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 };

            var input = int.Parse(Console.ReadLine());

            var output = a[input-1];

            Console.WriteLine(output);
        }
    }
}


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


void solve(long long N, long long K, std::vector<long long> p){
  sort(p.begin(), p.end());
  long long sum = 0;
  for (long long i=0; i<K; i++) sum += p[i];
  cout << sum << endl;
}

int main(){
    long long N;
    scanf("%lld",&N);
    long long K;
    scanf("%lld",&K);
    std::vector<long long> p(N);
    for(int i = 0 ; i < N ; i++){
        scanf("%lld",&p[i]);
    }
    solve(N, K, std::move(p));
    return 0;
}


Measured memory_bytes: 3676
#include<stdio.h>
int main()
{
    int N, temp, sum=0;
    scanf("%d", &N);
    temp=N;

    while(temp!=0)
    {
        sum=sum+temp%10;
        temp=temp/10;
    }
    if(N%sum!=0)
    {
        printf("No\n");
    }
    else
    {
        printf("Yes\n");
    }
    return 0;
}


Measured memory_bytes: 128
#include <iostream>
#include<bits/stdc++.h>
#define ll long long int
#define MAX 1000000000000000000
using namespace std;
 
int main() {
	// your code goes here
	int n;
	cin>>n;
	vector<ll>arr(n);
	ll prod = 1;
	bool zeropresent = false;
	for(int i = 0 ; i<n;i++)
	{
	    cin>>arr[i];
	    if(arr[i] == 0)
	    zeropresent = true;
	        
	}
	if(zeropresent)
	{
	    cout<<0<<endl;
	    return 0;
	}
	ll prev = 1;
	ll next = 1;
		for(int i = 0 ; i<n;i++)
	{
	    prod *= arr[i];
	    next = prod;
	    if(next < prev || prod < 0 || prod > MAX)
	    {
	       // cout<<next<<" "<<prev<<" "<<prod<<endl;
	        cout<<-1<<endl;
	        return 0;
	    }
	    prev = prod;
	}
	
// 	cout<<prod<<endl;
	if(prod > MAX || prod < 0)
	    cout<<-1<<endl;
	 else
	    cout<<prod<<endl;
	return 0;
}


Measured memory_bytes: 4052
#include <stdlib.h>
#include <stdio.h>

int main(int argc, char* argv[]){
  long a, b, c;
  int err = scanf("%ld %ld %ld", &a, &b, &c);
  if(a%2==0 || b%2==0 || c%2==0){
    printf("0\n");
  }else{
    if(a>=b && a>=c){
      printf("%ld\n",b*c);
    }else if(b>=a && b>=c){
      printf("%ld\n",a*c);
    }else{
      printf("%ld\n",a*b);
    }
  }
  return 0;
}

Measured memory_bytes: 128
#include <cstdio>
#include <algorithm>
#include <cstring>
#include <cctype>
using namespace std;

namespace zyt
{
	const int N = 3e5 + 10, P = 1e9 + 7;
	int n, f[N][3][3];
	char str[N];
	void add(int &a, const int b)
	{
		a = (a + b) % P;
	}
	int work()
	{
		scanf("%s", str);
		n = strlen(str);
		f[0][0][0] = 1;
		for (int i = 0; i < n; i++)
			for (int j = 0; j < 3; j++)
				for (int k = 0; k < 3; k++)
					if (f[i][j][k])
					{
						if (str[i] != '0')
						{
							if (j)
								add(f[i + 1][j - 1][k], f[i][j][k]);
							else
								add(f[i + 1][j][min(k + 1, 2)], f[i][j][k]);
						}
						if (str[i] != '1')
						{
							if (j == 2)
								add(f[i + 1][1][k], f[i][j][k]);
							else
								add(f[i + 1][j + 1][k], f[i][j][k]);
						}
					}
		int ans = 0;
		for (int i = 0; i < 3; i++)
			for (int j = i; j < 3; j++)
				add(ans, f[n][i][j]);
		printf("%d", ans);
		return 0;
	}
}
int main()
{
	return zyt::work();
}

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

int main(){
    int a, b, c;
    cin >> a >> b;
    c = a + b;
    if(c % 2 == 0){
        cout << c / 2 << endl;
    }else{
        cout << c / 2 + 1 << endl;
    }
    
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for(int64_t i=0;i < (int64_t)(n);i++)
#define invrep(i,n) for(int64_t i=n-1;i >= 0;i--)
#define _GLIBCXX_DEBUG
using namespace std;

int main(){
  double l;
  cin >> l;
  printf("%.12lf\n",(l/3.0)*(l/3.0)*(l/3.0));
    
}


Measured memory_bytes: 256
use proconio::{fastout, input};

#[fastout]
fn main() {
    input! {
        r: u128,
        d: u128,
        x: u128
    };

    let mut x = r * x - d;
    for _ in 0..10 {
        println!("{}", x);
        x = r * x - d;
    }
}


Measured memory_bytes: 2168
//run: g++ -std=c++14 -o run_sol.exe solution.cpp -DLOCAL_JUDGE
#include<bits/stdc++.h>
#define INF 0x7fffffff
#define INFLL 1e17
#define PI 2*acos(0.0)
#define show(x) cout<< #x <<" is "<< x <<"\n"
using namespace std;

#define FS first
#define SC second
#define PB(t) push_back(t)
#define LEN(t) ((int)t.size())
#define ALL(t) t.begin(),t.end()
#define MP(x, y) make_pair((x), (y))
#define Fill(a,c) memset(&a, c, sizeof(a))
#define POPCOUNT __builtin_popcount

typedef long long LL;
typedef pair<int, int> PII;
typedef vector<int> VI;
typedef vector<LL> VLL;
typedef vector<PII> VPII;

int main() {
    #ifdef LOCAL_JUDGE
        freopen("../input.txt", "rt", stdin);
        freopen("../output.txt", "wt", stdout);
    #endif

    ios::sync_with_stdio(false);
    cin.tie(NULL);

    for (string s, t; cin >> s >> t;) {
        vector<VI> dp(s.size() + 1, VI(t.size() + 1, 0));
        
        for (int i = 1; i <= s.size(); i++) {
            for (int j = 1; j <= t.size(); j++) {
                dp[i][j] = max(max(dp[i - 1][j], dp[i][j - 1]), dp[i - 1][j - 1] + (s[i - 1] == t[j - 1]));
            }
        }

        vector<char> res;
        int tpos, spos;
        tpos = t.size();
        spos = s.size();

        while (tpos > 0 and spos > 0) {
            if (dp[spos][tpos] > max(dp[spos - 1][tpos], dp[spos][tpos - 1])) {
                res.push_back(s[spos - 1]);
                spos--;
                tpos--;
            } else if (dp[spos][tpos] == dp[spos - 1][tpos]) {
                spos --;
            } else {
                tpos --;
            }
        }

        for (int i = res.size() -1; i >= 0; i--) {
            cout << res[i];
        }
        cout << "\n";
    }

return 0;
}

Measured memory_bytes: 35584
#!/usr/bin/env python3
# from typing import *

YES = 'Yes'
NO = 'No'

# def solve(D: int, T: int, S: int) -> str:
def solve(D, T, S):
    return S * T >= D

# generated by online-judge-template-generator v4.4.0 (https://github.com/kmyk/online-judge-template-generator)
def main():
    D, T, S = map(int, input().split())
    a = solve(D, T, S)
    print(YES if a else NO)

if __name__ == '__main__':
    main()


Measured memory_bytes: 9116
/*==============================================*\
Codeforces ID:    mdshihab
                                                  |
Name:     Md. Shihabul Minhaz                     |
Study:      CSE, JKKNIU                           |
Address:  Trishal, Mymensingh, Bangladesh         |
                                                  |
 mail:   mdshihabul20171@gmail.com                |
 FB  :   fb.com/mdshihabul.minhaz.7               |
 github: Shihabulminhaz                           |
stopstalk :  mdshihab                             |
                                                  |
@uthor   Md. Shihabul Minhaz (shihab)             |
\*===============================================*/


#include<bits/stdc++.h>
using namespace std;
#define fi(a) scanf("%d",&a);
#define fli(a) scanf("%ld",&a);
#define fll(a) scanf("%lld",&a);
#define pi(a) printf("%d\n",a);
#define ppi(i,a) printf("Case %d: %d\n",i,a);
#define ll long long
#define fast ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
void FI()
{
#ifndef ONLINE_JUDGE
    freopen("C:\\Users\\SHIHAB\\Desktop\\input.in","r",stdin);
#endif // ONLINE_JUDGE
}

int main()
{
    fast
    FI(); /// skip this line for compile
    int n;
    cin >> n;
    if(n>29) cout << "Yes\n";
    else cout << "No\n";
    return 0;
}



Measured memory_bytes: 3624
# in[]:
class UnionFind():
    def __init__(self, n):
        self.n = n
        self.parents = [-1] * n

    def find(self, x):
        if self.parents[x] < 0:
            return x
        else:
            self.parents[x] = self.find(self.parents[x])
            return self.parents[x]

    def union(self, x, y):
        x = self.find(x)
        y = self.find(y)

        if x == y:
            return

        if self.parents[x] > self.parents[y]:
            x, y = y, x

        self.parents[x] += self.parents[y]
        self.parents[y] = x

    def size(self, x):
        return -self.parents[self.find(x)]

    def same(self, x, y):
        return self.find(x) == self.find(y)

    def members(self, x):
        root = self.find(x)
        return [i for i in range(self.n) if self.find(i) == root]

    def roots(self):
        return [i for i, x in enumerate(self.parents) if x < 0]

    def group_count(self):
        return len(self.roots())

    def all_group_members(self):
        return {r: self.members(r) for r in self.roots()}

    def __str__(self):
        return '\n'.join('{}: {}'.format(r, self.members(r))
            for r in self.roots())


# in[]:
NM = input()
N = int(NM.split()[0])
M = int(NM.split()[1])

info = [input() for i in range(M)]
uf = UnionFind(N)

for i in range(M):
    AB = info[i].split()
    A = int(AB[0]) - 1
    B = int(AB[1]) - 1
    uf.union(A, B)

roots = uf.roots()
rootsize = [uf.size(rt) for rt in roots]
print(max(rootsize))

Measured memory_bytes: 28700
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cstring>
#include <climits>
#include <vector>
#include <map>
#include <set>
#include <list>
#include <stack>
#include <queue>
#include <algorithm>
#include <iostream>
#include <string>

#define REP(i,n) for(auto i=0;i<n;++i)
#define REPR(i,n) for(auto i=n;i>=0;--i)
#define REPI(itr,v) for(auto itr=v.begin();itr!=v.end();++itr)
#define REPIR(itr,v) for(auto itr=v.rbegin();itr!=v.rend();++itr)
#define FOR(i,a,b) for(auto i=a;i<b;++i)
#define SORT(v,n) sort(v, v+n)
#define SORTV(v) sort(v.begin(), v.end())
#define ALL(v) v.begin(),v.end()
#define llong long long
#define ll long long
#define INF 999999999
#define MOD 1000000007
#define pb push_back
#define pf push_front
#define MP make_pair
#define SV(n,v) {int tmp;for(int i=0;i<n;++i){scanf("%d",&tmp);v.push_back(tmp);}}

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

using namespace std;

typedef pair<int,int> pii;

int main(){

  llong n, k;
  cin >> k >> n;

  vector<llong> a(n);
  REP(i,n){
    cin >> a[i];
  }

  llong ans = 0;
  vector<llong> v;
  REP(i,n){
    v.pb(min(llabs(a[i] - a[(i+1)%n]), a[(i+1)%n] + (k - a[i])));
    ans += v[i];
  }

  SORTV(v);

  cout << ans - v[n-1] << endl;


  return 0;

}





Measured memory_bytes: 6500
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		String n = sc.next();
		String ans = "";
		if (n.equals("Sunny")) {
			ans = "Cloudy";
		} else if (n.equals("Cloudy")) {
			ans = "Rainy";
		} else {
			ans = "Sunny";
		}
		System.out.println(ans);
	}
}

Measured memory_bytes: 24020
#include <stdio.h>

int main(){
    
    int number,ctr;
    scanf("%d", &number);
    if(number <100 || number >999){
        return 1;
    }
    ctr = number;
    for(int i = number; i != 0; i / 10){
        if(ctr % 10 == 7){
            printf("Yes\n");
            break;
        } else {
            ctr /= 10;
            if ( ctr == 0){
             printf("No\n");
             break;
        }
        }
    }
    return 0;
}

Measured memory_bytes: 1600
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <set>
#include <queue>
#include <stack>
#include <tuple>
#include <cmath>
#include <iomanip>
#include <map>
#include <cstring> //memset(dp,0,sizeof(dp))
#include <functional>
#include <cctype>
#include <locale>
#define ll long long
#define rep(i,n) for(int i=0;i<(n);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()
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;}
typedef pair<int,int> P;
typedef pair<long long,long long> Pll;
#define fout(num) cout << fixed << setprecision(20) << (num) << endl
//s[i]=tolower(s[i]); islower(s[i]); cout << tolower(s[i])はバグ
//vector<vector<ll>> dp(n,vector<ll>(n))
//exist x map o set
const ll  MOD=1e9+7;
signed main(){
    ios::sync_with_stdio(false);
    std::cin.tie(nullptr);
    int n; cin >> n;
    vector<int> a(n),b(n);
    priority_queue<P> pq;
    rep(i,n) cin >> a[i];
    rep(i,n){
        cin >> b[i];
        if(a[i]!=b[i]) pq.push({b[i],i});
    }
    ll ans=0;
    while(!pq.empty()){
        P d=pq.top(); pq.pop();
        int del=b[d.se]-a[d.se];
        if(del%(b[(d.se+1)%n]+b[(d.se-1+n)%n])==0){
            ans+=del/(b[(d.se+1)%n]+b[(d.se-1+n)%n]);
            b[d.se]=a[d.se];
            continue;
        }
        if(b[d.se]<(b[(d.se+1)%n]+b[(d.se-1+n)%n])){
            cout << -1 << endl;
            return 0;
        }
        int cnt=b[d.se]/(b[(d.se+1)%n]+b[(d.se-1+n)%n]);
        b[d.se]-=cnt*(b[(d.se+1)%n]+b[(d.se-1+n)%n]);
        if(a[d.se]<b[d.se]) pq.push({b[d.se],d.se});
        if(a[d.se]>b[d.se]){
            cout << -1 << endl;
            return 0;
        }
        ans+=cnt;
    }
    cout << ans << endl;
}


Measured memory_bytes: 6884
#include<iostream>
#include<string>
#include <numeric>
using namespace std;
int H, W;
string s[26] = {"A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "K", "L", "M", "N", "O", "P", "Q", "R", "S", "T", "U", "V", "W", "X", "Y", "Z"};
string str;
int main() {
    cin >> H >> W;
    bool flag=true;
    for(int i=0; i<H; ++i){
        for(int j=0; j<W; ++j){
            cin >> str;
            if(str == "snuke"){
                cout << s[j] << i+1 << endl;
                flag = false;
                break;
            }
        }
        if(!flag) break;
    } 
    return 0;
}

Measured memory_bytes: 256
INF = 10 ** 8
def main():
    s = input()
    word = list(set(s))
    output = INF
    for c in word:
        t = s
        cnt = 0
        while len(set(t)) > 1:
            l = []
            for i in range(len(t)-1):
                if t[i] == c or t[i+1] == c: l.append(c)
                else: l.append(t[i])
            t = ''.join(l)
            cnt += 1
        output = min(output, cnt)
    print(output)
    return

if __name__ == '__main__':
    main()


Measured memory_bytes: 3064
N, M = map(int, input().split())

# 各行のスイッチ
switches_list = []
for i in range(M):
    line = input().split()
    switch_count = int(line[0])
    switches = [0] * N
    for j in range(switch_count):
        switches[int(line[j + 1]) - 1] = 1
    switches_list.append(switches)
# print(switches_list)

# 余り
surpluses = input().split()

count = 0
# bit全検索
# on/offのような二択なら、自分で組み合わせを作らなくても
# 2のN乗の数値のビット演算で表現ができる
for k in range(2 ** N):
    for i in range(len(switches_list)):
        switches = switches_list[i]
        surplus = int(surpluses[i])
        on_count = 0
        for j in range(len(switches)):
            if switches[j] == 1 and ((k >> j) & 1):
                on_count += 1
        if on_count % 2 != surplus:
            break
        # 全電球分のチェックを通ったらOKとする
        if i == len(switches_list) - 1:
            count += 1
print(count)


Measured memory_bytes: 3188
import java.util.*;

public class Main {
  public static void main(String[] args) {
    Scanner s = new Scanner(System.in);
    int n = s.nextInt();
    long[] a = new long[n];
    
    for (int i = 0; i < n; i++) {
      a[i] = s.nextLong();
    }
    
    long dpMaxCurrentPositive = 0;
    long dpMaxCurrentNegative = -(1L << 40);
    
    for (int i = 1; i < n; i++) {
      long nextDpMaxCurrentPositive = Math.max(dpMaxCurrentPositive + a[i-1], dpMaxCurrentNegative - a[i-1]);
      long nextDpMaxCurrentNegative = Math.max(dpMaxCurrentPositive - a[i-1], dpMaxCurrentNegative + a[i-1]);
      dpMaxCurrentPositive = nextDpMaxCurrentPositive;
      dpMaxCurrentNegative = nextDpMaxCurrentNegative;
    }
    long maxValue = Math.max(dpMaxCurrentPositive + a[n-1], dpMaxCurrentNegative - a[n-1]);
    System.out.println(maxValue);
  }
}


Measured memory_bytes: 57444
#include <iostream>
#include <limits>
#include <vector>
#include <algorithm>

int rec(int index, int k, const std::vector<int>& h, std::vector<int>& result) {
    if (result[index] == std::numeric_limits<int>::max()) {
        for (int j = 1; j <= k; j++) {
            if (index - j < 0) break;
            result[index] = std::min(
                    result[index],
                    std::abs(h[index] - h[index - j]) + rec(index - j, k, h, result));
        }
    }
    return result[index];
}

int main() {
    int n;
    int k;
    std::cin >> n;
    std::cin >> k;
    std::vector<int> h(n);
    for (int i = 0; i < n; ++i) {
        std::cin >> h[i];
    }
    std::vector<int> result(n, std::numeric_limits<int>::max());
    result[0] = 0;
    std::cout << rec(n - 1, k, h, result);
    return 0;
}


Measured memory_bytes: 10368
#pragma GCC optimize("O3")
#include<bits/stdc++.h> 
using namespace std;
using ll=long long;
typedef  unsigned long long int ull;
typedef pair<ll,ll> P;
template<class T> using V=vector<T>; 
#define fi first
#define se second
#define all(v) (v).begin(),(v).end()
const ll inf=(1e18);
//const ll mod=998244353;
const ll mod=1000000007;
//ios_base::sync_with_stdio(false);
//cin.tie(NULL);
ll gcd(ll a,ll b) {return b ? gcd(b,a%b):a;}
struct __INIT{__INIT(){cin.tie(0);ios::sync_with_stdio(false);cout<<fixed<<setprecision(15);}} __init;
template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return 1; } return 0; }
ll dp[200005];
int main(){
    for(int i=0;i<200005;i++)dp[i]=inf;
    dp[0]=0;
    int n;
    cin>>n;
    string s,cp={};
    cin>>s;
    reverse(all(s));
   for(int i=0;i<n;i++){
       if(cp.size()==0&&s[i]=='#')continue;
        cp.push_back(s[i]);
   }
   reverse(all(cp));
   s={};
   for(int i=0;i<cp.size();i++){
       if(s.size()==0&&cp[i]=='.')continue;
        s.push_back(cp[i]);
   }
    n=s.size();
     V<int> cnt(2,0);
    for(int i=0;i<n;i++){
        cnt[(s[i]=='.')]++;
    }
    int ans=min(cnt[0],cnt[1]);
    int b=cnt[0],w=cnt[1];
    int cnb=0,tmp=0;
    for(int i=0;i<n;i++){
        if(s[i]=='#')cnb++;
        else{
            w--;
            chmin(ans,cnb+w);
        }
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 2452
#include <bits/stdc++.h>
#define nl ios::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define ll long long
#define all(v) (v).begin(), (v).end()
#define allr(v) (v).rbegin(), (v).rend()

using namespace std;

int main() {
    nl // lofi  
    int x[5];
    for(int i=1; i<=5; ++i){
        cin >> x[i];
        if(x[i] == 0) {
            cout << i; return 0;
        }
    }
} 

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

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

	if(S.size() <= K)
		cout << S;
	else
		cout << S.substr(0,K) << "...";
	cout << endl;
}

Measured memory_bytes: 3636
#include<bits/stdc++.h>
using namespace std;
int gcd(int a,int b){
	if(a%b!=0){
		return gcd(b,a%b);
	}
	return b;
}
int main(){
	long long a,b;
	cin>>a>>b;
	cout<<a*b/gcd(a,b)<<endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using Graph = vector<vector<int>>;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
const long long MOD=1000000007;
#define chmax(x,y) x=max(x,y)
#define chmin(x,y) x=min(x,y)
const int mmax=1000009;

int main(void){
    int a,b,c;
    cin>>a>>b>>c;
    if(a==b && b==c && c==a) puts("1");
    if(a==b && b!=c && c!=a) puts("2");
    if(a!=b && b==c && c!=a) puts("2");
    if(a!=b && b!=c && c==a) puts("2");
    if(a!=b && b!=c && c!=a) puts("3");
    return 0;
}


Measured memory_bytes: 3528
N,M=map(int, input().split())
P=list(map(int, input().split()))
XY=[list(map(int,input().split())) for i in range(M)]
class UnionFind:
    def __init__(self,N,P):
        self.Parent=[-1]*N
        self.num=[{p-1:1} for p in P]
    def unite(self,m,n):
        rm=self.root(m)
        rn=self.root(n)
        if rm==rn:
            return False
        else:
            if self.size(rm)<self.size(rn):
                rm,rn=rn,rm
            self.Parent[rm]+=self.Parent[rn]
            self.Parent[rn]=rm
            self.num[rm].update(self.num[rn])
            return True
    def root(self,n):
        if self.Parent[n]<0:
            return n
        else:
            self.Parent[n]=self.root(self.Parent[n])
            return self.Parent[n]
    def size(self,n):
        return -self.Parent[self.root(n)]
u=UnionFind(N,P)
for xy in XY:
    u.unite(xy[0]-1,xy[1]-1)
ans=0
for n in range(N):
    if n in u.num[u.root(n)]:
        ans+=1
print(ans)

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

typedef long long ll;

const int MAX_N = 100010;
int par[MAX_N];
int rnk[MAX_N];
int siz[MAX_N];

void init(int n) {
    rep(i,n) {
        par[i] = i;
        rnk[i] = 0;
        siz[i] = 1;
    }
}

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

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

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

int size(int x) {
    return siz[find(x)];
}

int main() {
    int N, M;
    cin >> N >> M;
    init(N);
    vector<int> X(M), Y(M), Z(M);
    rep(i, M) {
        cin >> X[i] >> Y[i] >> Z[i];
        unite(X[i] - 1, Y[i] - 1);
    }
    int ans = 0;
    rep(i, N) {
        if (find(i) == i) ans++;
    }
    cout << ans << "\n";
}

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

#define rep(i, n) REP(i, 0, n)
#define ALL(v) v.begin(), v.end()
#define MSG(a) cout << #a << " " << a << endl;
#define REP(i, x, n) for (int i = x; i < n; i++)
#define OP(m) cout << m << endl
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pii;

int main()
{
    int d, g;
    cin >> d >> g;
    int p[d], c[d];
    rep(i, d) cin >> p[i] >> c[i];
    int ans = 1001;

    for (int bit = 0; bit < (1 << d); bit++)
    {
        int cnt = 0;
        int sum = 0;
        rep(i, d)
        {
            if (bit & (1 << i))
            {
                cnt += p[i];
                sum += (i + 1) * 100 * p[i] + c[i];
            }
        }
        if (sum < g)
        {
            for (int i = d - 1; i >= 0; i--)
            {
                if (bit & (1 << i))
                    continue;
                rep(j, p[i] - 1)
                {
                    if (sum >= g)
                        break;
                    cnt += 1;
                    sum += (i + 1) * 100;
                }
            }
        }
        if (sum >= g)
            ans = min(ans, cnt);
    }

    OP(ans);
    return 0;
}

Measured memory_bytes: 256
#include <iostream>

using namespace std;

bool DP[200001];
int A[200001];

int main(int argc, char* argv[]) {
  int N;
  cin >> N;
  for(int i = 0; i < N; ++i){
    cin >> A[i];
  }
  int K = 1;
  for(int i=0; i<N; ++i) {
    if(K==A[i]) {
      DP[i] = true;
      ++K;
    }
  }
  int cnt=0;
  int ans=-1;
  for(int i=0; i<N; ++i){
    if(DP[i]) {
      cnt++;
      ans = cnt;
    }
  }
  if(ans < 0) cout << -1 << endl;
  else cout << N-ans << endl;
  return 0;
}

Measured memory_bytes: 1280
#include <iostream>
#include <algorithm>
#include <cstdio>
#include <vector>
#include <cmath>
#include <iomanip>
#include <bitset>
#include <string>
#include <cstring>
#include <stdlib.h>
using namespace std;
//cout <<  << endl;
typedef long long int ll;
typedef long double ld;

using Graph = vector<vector<ll>>;

template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }

#define MAX_N 2010

const long long INF = 1LL << 60;

ll x[90];
//境界値に注意！！！
ll lucas(ll n){
    if (n==0)return 2;
    if (n==1)return 1;
    if (x[n-1])return x[n-1];
    
    return x[n-1]=lucas(n-1)+lucas(n-2);
}
int main() {
    ll n;
    cin >> n;
    cout << lucas(n) << endl;
}


Measured memory_bytes: 256
def solve():
    a,b,c=input().split()
    k=int(input())
    a=int(a)
    b=int(b)
    c=int(c)
    t=0
    # print(a,b,c)
    while(b<=a):
        t=t+1
        b=b*2
    # print(t,b)
    while(c<=b):
        t=t+1
        c=c*2
    # print(t,c)
    if t<=k:
        print("Yes")
    else:
        print("No")
solve()

Measured memory_bytes: 9176
#include <bits/stdc++.h>
 
using namespace std;
 
typedef long long LL;
const LL MO=1e9+7;
 
LL qmi(LL a,LL b) {
    LL res=1;
    while(b) {
        if (b&1) {
            res=res*a%MO;
        }
        a=a*a%MO;
        b>>=1;
    }
    return res;
}
 
int main() {
    LL n;
    cin>>n;
 
    cout<<((qmi(10ll,n)-2*qmi(9ll,n)+qmi(8ll,n))%MO+MO)%MO<<"\n";
 
    return 0;
}


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

int ans = -1;



void minmin(vector<int> S, vector<int> C, vector<vector<int> > A, int N, int M, int X, int i){
    if (i == N){
        vector<int> test(M);
        rep(j, N){
            if(S[j] == 1){
                rep(k, M){
                    test[k] += A[j][k];
                }
            }
        }
        bool check = true;
        rep(j, M){
            if (test[j] < X){
                check = false;
                break;
            }
        }

        if (check){
            int total = 0;
            rep(j, N){
                if(S[j] == 1){
                    total += C[j];
                }
            }

            if (ans == -1){
                ans = total;
            } else {
                ans = min(ans, total);
            }
        }
        return;
    }

    minmin(S,C,A,N,M,X,i+1);
    S[i] = 1;
    minmin(S,C,A,N,M,X,i+1);
    S[i] = 0;
}

int main() {
    int N, M, X; cin >> N >> M >> X;
    vector<int> C(N);
    vector<vector<int> > A(N);
    rep(i, N){
        int c; cin >> c;
        C[i] = c;
        rep(j, M){
            int a; cin >> a;
            A[i].push_back(a);
        }
    }

    vector<int> S(N);
    rep(i, N){
        S[i] = 0;
    }

    minmin(S,C,A,N,M,X,0);

    cout << ans << endl;



}

Measured memory_bytes: 3648
#include <bits/stdc++.h>
    #include <cstdio>
    #include <cstring>
    #include <cmath>
    #include <cstring>
    #include <chrono>
    #include <complex>
    #define endl "\n"
    #define int long long int
    #define vi vector<int>
    #define vll vector<ll>
    #define vvi vector < vi >
    #define pii pair<int,int>
    #define pll pair<long long, long long>
    #define mod 1000000007
    #define inf 1000000000000000001;
    #define all(c) c.begin(),c.end()
    #define mp(x,y) make_pair(x,y)
    #define mem(a,val) memset(a,val,sizeof(a))
    #define eb emplace_back
    #define f first
    #define s second

    using namespace std;
int power(int base, int exp)
{
    if (exp == 0)
       return 1;
    else if (exp == 1)
       return base;
    else
    {
       int calc;
       if (exp % 2 == 0)
       {
         calc = power(base, exp/2);
         calc =(calc* calc)%mod;
       }
       else
       {
         calc = (base*power(base, exp-1))%mod;
       }
       return calc%mod;
    }
}
    int32_t main()
    {
        std::ios::sync_with_stdio(false);
       int s,w;
       cin>>s>>w;
       if(s<=w)
        cout<<"unsafe"<<endl;
       else
        cout<<"safe"<<endl;
        return 0;
    }


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

int main(){
  int n, m, x, y;
  cin >> n >> m >> x >> y;
  //int sum;
  vector<int> vecx(n+1);
  for(int i=0;i<n;i++){
    cin >> vecx.at(i);
  }
  
  vector<int> vecy(m+1);
  for(int i=0;i<m;i++){
    cin >> vecy.at(i);
  }
  
  vecx.at(n) = x;
  vecy.at(m) = y;
  
  sort(vecx.begin(), vecx.end());
  sort(vecy.begin(), vecy.end());
  int xmax =vecx.at(n);
  int ymin = vecy.at(0);
  if(x <y)
  if(xmax < ymin){
  cout << "No War" << endl;
  }
  else {
    cout << "War" << endl;
  }
}
    

Measured memory_bytes: 256
S = input()

def f(S):
    if S[0] is not "A":
        return(False)
    if not "C" in S[2:-1]:
        return(False)
    if [str.isupper(c) for c in S].count(True) != 2:
        return(False)
    return(True)

if f(S):
    print("AC")
else:
    print("WA")


Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
typedef long long ll;
 
int main(){
  int a;
  cin >> a;
  if(a<1200){
    cout << "ABC" << endl;
  }
  else if(a<2800){
    cout << "ARC" << endl;
  }
  else{
    cout << "AGC" << endl;
  }
}

Measured memory_bytes: 256
//http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=0520
#include <iostream>
#include <vector>
using namespace std;
#define ll long long
inline ll gcd(ll a, ll b) { if (b > a)swap(a, b); return b ? gcd(b, a%b) : a; }
inline ll lcm(ll a, ll b) { return a / gcd(a, b)*b; }

struct mobile {
	ll lb, rb, ln, rn;
	mobile() {}
	mobile(ll lb, ll rb, ll ln, ll rn) :lb(lb), rb(rb), ln(ln), rn(rn) {}
	mobile& operator=(const mobile& o) {
		this->lb = o.lb;
		this->rb = o.rb;
		this->ln = o.ln;
		this->rn = o.rn;
		return *this;
	}
};

ll dfs_mobile(int n,vector<mobile>& Mobile) {
	ll lM = Mobile[n].ln == 0 ? 1 : dfs_mobile(Mobile[n].ln, Mobile);
	ll rM = Mobile[n].rn == 0 ? 1 : dfs_mobile(Mobile[n].rn, Mobile);
	ll LCM = lcm(lM*Mobile[n].lb, rM*Mobile[n].rb);

	return LCM / Mobile[n].lb + LCM / Mobile[n].rb;
}

int main() {
	cin.tie(0); ios::sync_with_stdio(false);
	while (true) {
		int n; cin >> n;
		if (n == 0) break;
		vector<ll> rev(n + 1, -1);
		vector<mobile> Mobile(n + 1);

		/* initialize */
		for (int i = 1; i <= n;i++) {
			ll lb, rb, ln, rn; cin >> lb >> rb >> ln >> rn;
			ll GCD = gcd(lb, rb);
			lb /= GCD; rb /= GCD;
			Mobile[i] = mobile(lb, rb, ln, rn);
			if (ln != 0) rev[ln] = i;
			if (rn != 0) rev[rn] = i;
		}

		/*????????¢?´¢*/
		ll root = 1;
		while (rev[root] != -1) root = rev[root];

		cout << dfs_mobile(root,Mobile) << endl;

	}
}

Measured memory_bytes: 3136
#include <iostream>

using namespace std;
int main(){
    int i,x,y;
    cin >> x >> y;
    for(i=0;i<=x;i++){
        if(2*i + 4*(x - i)==y){
            cout << "Yes" << endl;
            return 0;
        }
    }
    cout << "No" << endl;
}

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


int main()
{
  int x;
  cin >> x;
  int a,b,c,d;
  a = x / 1000 % 10;
  b = x / 100 % 10;
  c = x / 10 % 10;
  d = x % 10;
  if(a == b && a == c){
    cout << "Yes" << endl;
  }else if(b == c && b == d){
    cout << "Yes" << endl;
  } else{
    cout << "No" << endl;
  }
  return 0;
}


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

/*--- Macro ---*/
#define rep(i, n) for(int i=0; i<(int)n; i++)
#define rep1(i, n) for(int i=1; i<(int)n; i++)
#define mp make_pair
#define pb push_back

/*---  Type ---*/
typedef long long ll;

/*--- Constants ---*/
template <typename T> const T INF = numeric_limits<T>::max() / 10;
const int MOD = (int)1e9 + 7;

// Floating
const double EPS = 1e-11;
#define EQ0(x) (abs(x) < EPS)
#define EQ(x, y) (abs(a-b) < EPS)

// Util
int max(int a, int b, int c) {return max(a, max(b, c));}
int min(int a, int b, int c) {return min(a, min(b, c));}
ll max(ll x, ll y) {return x > y ? x : y;}
ll min(ll x, ll y) {return x < y ? x : y;}
ll max(ll a, ll b, ll c) {return max(a, max(b, c));}
ll min(ll a, ll b, ll c) {return min(a, min(b, c));}

// -------------------------------------------------------------------------------------



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

  if(abs(x-a) < abs(x-b)) cout << "A" << endl;
  else cout << "B" << endl;

  return 0;
}

Measured memory_bytes: 256
from sys import stdout
import itertools
printn = lambda x: stdout.write(str(x))
inn = lambda : int(input())
inl   = lambda: list(map(int, input().split()))
inm   = lambda:      map(int, input().split())
ins = lambda : input().strip()
DBG = True  and False
BIG = 999999999
R = 10**9 + 7

def ddprint(x):
  if DBG:
    print(x)

n,m,rr = inm()
r = inl()
r = [x-1 for x in r]
dst = [ [] for i in range(n) ]
for i in range(m):
    a,b,c = inm()
    dst[a-1].append((b-1,c))
    dst[b-1].append((a-1,c))

ddprint("n {} m {} r {}".format(n,m,rr))
ddprint(dst)

# warshal floyd
dist = [ [BIG]*n for i in range(n) ]
for i in range(n):
    dist[i][i] = 0
    for j,c in dst[i]:
        dist[i][j] = c
for k in range(n):
    for i in range(n):
        for j in range(n):
            dist[i][j] = min(dist[i][j], dist[i][k]+dist[k][j])

ddprint("dist")
ddprint(dist)

pm = itertools.permutations(r,rr)
mn = BIG
for p in pm:
    sm = 0
    #ddprint(p)
    for i in range(rr-1):
        sm += dist[p[i]][p[i+1]]
    mn = min(mn,sm)
print(mn)


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

int main() {
    long long int num, blue, red;

    cin >> num >> blue >> red;

    long long int counter;
    long long int ans = 0;

    counter = num / (blue + red);
    ans += counter * blue;

    counter = num % (blue + red);
    ans += min(counter, blue);

    cout << ans << endl;
}

Measured memory_bytes: 256
/*

  "With age, comes wisdom. With travel, comes understanding.
   Remember that happiness is a way of travel – not a destination"

*/

#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

using namespace std;
using namespace __gnu_pbds;

#define int            long long int
#define F              first
#define S              second
#define pb             push_back
#define si             set <int>
#define vi             vector <int>
#define pii            pair <int, int>
#define vpi            vector <pii>
#define vpp            vector <pair<int, pii>>
#define mii            map <int, int>
#define mpi            map <pii, int>
#define spi            set <pii>
#define endl           "\n"
#define sz(x)          ((int) x.size())
#define all(p)         p.begin(), p.end()
#define double         long double
#define que_max        priority_queue <int>
#define que_min        priority_queue <int, vi, greater<int>>
#define bug(...)       __f (#__VA_ARGS__, __VA_ARGS__)
#define print(a)       for(auto x : a) cout << x << " "; cout << endl
#define print1(a)      for(auto x : a) cout << x.F << " " << x.S << endl
#define print2(a,x,y)  for(int i = x; i < y; i++) cout<< a[i]<< " "; cout << endl

inline int power(int a, int b)
{
     int x = 1;
     while (b)
     {
          if (b & 1) x *= a;
          a *= a;
          b >>= 1;
     }
     return x;
}

typedef tree<pii, null_type, less<pii>, rb_tree_tag, tree_order_statistics_node_update> Set;

template <typename Arg1>
void __f (const char* name, Arg1&& arg1) { cout << name << " : " << arg1 << endl; }
template <typename Arg1, typename... Args>
void __f (const char* names, Arg1&& arg1, Args&&... args)
{
     const char* comma = strchr (names + 1, ',');
     cout.write (names, comma - names) << " : " << arg1 << " | "; __f (comma + 1, args...);
}

const int N = 405;
int a[N], n, m, k;
int cache[N][N];

int dp(int st, int en)
{
     if (st == en)
          return 0;

     int &ans = cache[st][en];
     if (ans != -1)
          return ans;

     ans = 1e18;
     for (int i = st; i < en; i++)
          ans = min(ans, a[en] - a[st - 1] + dp(st, i) + dp(i + 1, en));

     return ans;

}

void solve()
{
     cin >> n;
     for (int i = 1; i <= n; i++)
     {
          cin >> a[i];
          a[i] += a[i - 1];
     }
     memset(cache, -1, sizeof cache);
     cout << dp(1, n);

}

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

     cout << setprecision(9) << fixed;
     clock_t z = clock();
     solve();
     cerr << "Run Time : " << ((double)(clock() - z) / CLOCKS_PER_SEC);

     return 0;
}

Measured memory_bytes: 1536
local w, h = io.read("*n", "*n")
local x, y = io.read("*n", "*n")
local menseki = w * h / 2
local flag = 0
if x * 2 == w and y * 2 == h then
  flag = 1
end
io.write(string.format("%.10f", menseki))
io.write(" " .. flag .. "\n")


Measured memory_bytes: 888