akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;
#define ll long long                                    // long long省略
#define pb push_back                                    // push_back省略
#define mp make_pair                                    // make_pair省略
#define fi first                                        // first省略
#define se second                                       // second省略
#define itn int                                         // int誤字保険
#define count cout                                      // cout誤字保険
#define vecotr vector                                   // vector誤字保険
#define ednl endl                                       // endl誤字保険
#define opt() cin.tie(0); ios::sync_with_stdio(false)   // 入出力速度改善

#define rep(i,l,r) for(ll i=(l);i<(r);i++)               // 範囲[l, r)で刻み1のfor文(順方向)
#define repp(i,l,r,k) for(ll i=(l);i<(r);i+=(k))         // 範囲[l, r)で刻みkのfor文(順方向)
#define rrep(i,l,r) for(ll i=(r-1);i>=(l);i--)           // 範囲[l, r)で刻み1のfor文(逆方向)
#define rrepp(i,l,r,k) for(ll i=(r-1);i>=(l);i-=(k))     // 範囲[l, r)で刻みkのfor文(逆方向)
#define all(x) (x).begin(), (x).end()                   // vectorのポインタ位置指定用
#define max(p,q)((p)>(q)?(p):(q))                       // max拡張
#define min(p,q)((p)<(q)?(p):(q))                       // min拡張
#define bit(n,m)(((n)>>(m))&1)                          // 変数nのm番目のbitを取り出す

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 dy[]={0, 1, 0, -1};                                 // 4方向近傍
int dx[]={1, 0, -1, 0};                                 // 4方向近傍

int main(){
  	ll M = 998244353;
    ll n;cin >> n;
    ll d[n];
  	rep(i,0,n)cin >> d[i];
    //最初は0確定
    if(d[0] != 0){
        cout<<0<<endl;
        return 0;
    }
    //他に0を含んでいてもだめ
    rep(i,1,n){
        if(d[i] == 0){
            cout << 0 << endl;
            return 0;
        }
    }
    sort(d,d+n);
    //距離が飛んでいる場合もだめ
    ll aaa = 0;
    rep(i,0,n){
        if(d[i] == aaa)aaa++;
    }
    if(aaa-1!=d[n-1]){
        cout << 0 << endl;
        return 0;
    }
    
    ll res = 1;
    vector<ll> v; ll cnt=1,tmp=1;
  	v.pb(1);
    rep(i,1,n){
        if(d[i] == cnt+1){
            v.pb(i-tmp);
            tmp =i;cnt++;
        }if(i==n-1){
            v.pb(n-tmp);
        }
    }
  	//rep(i,0,v.size())cout<<v[i]<<ednl;
    rep(i,1,v.size()){
      	//cout << v[i] << " " << v[i-1] << endl;
        ll ans = 1;
        rep(j,0,v[i]) ans = (ans * v[i-1]) % M;
        res = (res*ans)%M;
        // ll sum=0;
        // rep(j,0,v[i]+1) sum+=COM(v[i], j);
        // res *= 
    }
    cout << res << endl;
}


Measured memory_bytes: 2168
#include<iostream>
#include<vector>
#include<algorithm>
#include<cctype>
#include<utility>
#include<string>
#include<cmath>
#include<cstring>

#define REP(i, n) for(int i = 0;i < n;i++)
#define REPR(i, n) for(int i = n;i >= 0;i--)
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define FORR(i, m, n) for(int i = m;i >= n;i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define llong long long
#define pb(a) push_back(a)
#define INF 999999999
using namespace std;
typedef pair<int, int> P;
typedef pair<llong, llong> LP;
typedef pair<int, P> PP;
typedef pair<llong, LP> LPP;


int dp[110][10010];
int v[110],w[110];


int main(){

    int N,W;
    cin >> N >> W;
    REP(i,N){
        cin >> v[i] >> w[i];
    }

    memset(dp,0,sizeof(dp));

    //dp[i][j]:= i番目の品物の中から重さがWを超えない品物を選んだ時の価値の最大

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


        for(int j = 0;j <= W;j++){

            if(j < w[i-1]){//使えない
                dp[i][j] = dp[i-1][j];
            }else{
                dp[i][j] = max(dp[i-1][j],dp[i][j-w[i-1]]+v[i-1]);
            }
        }
    }
    cout << dp[N][W] << endl;
   

    return 0;
}


Measured memory_bytes: 7408
#include <bits/stdc++.h>
//#include <ext/pb_ds/assoc_container.hpp> // Common file 
//#include <ext/pb_ds/tree_policy.hpp> 
#define int long long
#define pb push_back
#define ff first
#define ss second
#define ii insert
#define ld long double
#define sz(x) (int)x.size()
#define all(v) v.begin(),v.end()
#define ppb pop_back
#define nuenxfiu ios_base::sync_with_stdio(0);cin.tie(NULL);cout.tie(NULL);
#define input freopen("input.txt", "r", stdin),freopen("output.txt", "w", stdout);
#define TT int testcases;cin>>testcases;while(testcases--)
#define mk make_pair
#define MAX ((int)2e9+17)
#define mod ((int)1e9+7)
#define MOD 1000003
//int fact[1000007]={0};
#define N 1e5+5
int fpow(int n, int k, int p = mod) {int r = 1; while(k > 0) {if (k & 1) r = r * n%p; n = n * n%p; k = k >> 1;} return r;}
int expo(int x,int y){ int res=1; while(y) {if(y%2) res=(res*x%mod)%mod; x=(x*x)%mod; y/=2; } return res;}
int sub(int a, int b) {return (a%mod - b%mod + mod)%mod;}
int mul(int a, int b) {return ((a%mod)*(b%mod) + mod)%mod;}
int inv(int x) {return expo(x, mod-2);}
using namespace std;

int a[100005][4];
int dp[100005][4];
int n;

int func(int day,int flag)
{
	if(day==n)
	return 0;
	
	if(dp[day][flag]!=-1)
	return dp[day][flag];
	
	int maxi=0;
	
	if(flag==0)
	{
		maxi=max(maxi,a[day][1]+func(day+1,1));
		maxi=max(maxi,a[day][2]+func(day+1,2));
		maxi=max(maxi,a[day][3]+func(day+1,3));
	}
	else if(flag==1)
	{
		maxi=max(maxi,a[day][2]+func(day+1,2));
		maxi=max(maxi,a[day][3]+func(day+1,3));
	}
	else if(flag==2)
	{
		maxi=max(maxi,a[day][1]+func(day+1,1));
		maxi=max(maxi,a[day][3]+func(day+1,3));
	}
	else
	{
		maxi=max(maxi,a[day][1]+func(day+1,1));
		maxi=max(maxi,a[day][2]+func(day+1,2));
	}
	
	return dp[day][flag]=maxi;

}

void solve()
{
	cin>>n;
	
	for(int i=0;i<n;i++)
	{
		for(int j=1;j<=3;j++)
		cin>>a[i][j];
	}
	
	memset(dp,-1,sizeof(dp));
	
	cout<<func(0,0)<<endl;;
	
	return ;

}
signed main()
{
    
	nuenxfiu
	//TT
	solve();
     return 0;
}

Measured memory_bytes: 17760
{-# LANGUAGE ScopedTypeVariables #-}

import qualified Data.Vector.Unboxed as VU
import qualified Data.Vector.Unboxed.Mutable as VUM
import Control.Monad

-- Union-Find
type Parent = VUM.IOVector Int
type Size = VUM.IOVector Int

makeUF :: Int -> IO (Parent, Size)
makeUF n = do
    par <- VU.unsafeThaw $ VU.generate n id
    siz <- VUM.replicate n 1
    return (par, siz)

root :: Int -> Parent -> IO Int
root x par = do
    r <- VUM.read par x
    if x == r
        then return x
        else do
            newr <- root r par
            VUM.write par x newr
            return newr

same :: Int -> Int -> Parent -> IO Bool
same x y par = do
    rx <- root x par
    ry <- root y par
    return $ rx == ry

unite :: Int -> Int -> Parent -> Size -> IO ()
unite x y par siz = do
    x' <- root x par
    y' <- root y par
    sx <- VUM.read siz x'
    sy <- VUM.read siz y'
    unless (x' == y') $ 
        if sx < sy
            then do
                VUM.modify siz (+sx) y'
                VUM.write par x' y'
            else do
                VUM.modify siz (+sy) x'
                VUM.write par y' x'

size :: Int -> Parent -> Size -> IO Int
size x par siz = root x par >>= VUM.read siz
    
main = do
    [n,m,k] <- map read . words <$> getLine :: IO [Int]
    (par, siz) <- makeUF (n+1)
    (fre :: VUM.IOVector Int) <- VUM.replicate (n+1) 0
    (blo :: VUM.IOVector Int) <- VUM.replicate (n+1) 0
    replicateM_ m $ do
        [a,b] <- map read . words <$> getLine :: IO [Int]
        unite a b par siz
        VUM.modify fre (+1) a
        VUM.modify fre (+1) b
    replicateM_ k $ do
        [c,d] <- map read . words <$> getLine :: IO [Int]
        branch <- same c d par
        when branch $ do
            VUM.modify blo (+1) c
            VUM.modify blo (+1) d
        
    forM_ [1..n] $ \i -> do
        s <- size i par siz
        f <- VUM.read fre i
        b <- VUM.read blo i
        putStr $ show (s - f - b - 1)
        putStr " "
    putStrLn ""

Measured memory_bytes: 4988
#include <iostream>
#include <vector>
#include <algorithm>
#include <stack>
#include <queue>
#include <list>
#include <string>
#include <numeric>
#include <math.h>
#include <set>
#include <map>
#include <fstream>
using namespace std;

int main()
{
	int N,H;
	cin>>N>>H;
	vector<int> a(N);
	vector<int> b(N);

	for(int i=0; i<N; i++)
	{
		cin>>a[i]>>b[i];
	}

	int max_a = *max_element(a.begin(),a.end());


	vector<int> e_b;
	for(int i=0; i<N; i++)
	{
		if(b[i]>=max_a)
		{
			e_b.push_back(b[i]);
		}
	}
	sort(e_b.begin(),e_b.end(),greater<int>());

	int count = 0;
	
	for(int i=0; i<e_b.size(); i++)
	{
		if(H>0)
		{
			H-=e_b[i];
			count++;
		}
		else
		{
			break;
		}
	}
	

	if(H > 0)
	{

		count += (H + max_a - 1)/max_a;
	}

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

Measured memory_bytes: 1660
#include <iostream>
#include <vector>
#include <string>
#include <cstring>
#include <math.h>
#include <cmath>
#include <limits.h>
#include <map>
#include <set>
#include <queue>
#include <algorithm>
#include <functional>
#include <stdio.h>
using namespace std;

long long MOD = 1000000007;

int main() {
    int A,B;
    cin >> A >> B;
    A--; B--;

    cout << 100 << " " << 100 << endl;

    int X[100][100] = {0};
    for ( int y = 50; y < 100; y++ ) {
    for ( int x = 0; x < 100; x++ ) {
        X[x][y] = 1;
    }
    }

    for ( int i = 0; i < B; i++ ) {
        int x = (i%50)*2;
        int y = (i/50)*2;
        X[x][y] = 1;
    }
    for ( int i = 0; i < A; i++ ) {
        int x = (i%50)*2;
        int y = 99-(i/50)*2;
        X[x][y] = 0;
    }


    for ( int y = 0; y < 100; y++ ) {
        for ( int x = 0; x < 100; x++ ) {
            cout << ( X[x][y] ? '#' : '.' );
        }
        cout << endl;
    }

}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define inf (int)(1e9)
const int M = 80 * 160;

int main(){
	int H, W, i, j;
	scanf("%d%d", &H, &W);
	vector<vector<int>> A(H, vector<int>(W));
	for(i = 0; i < H; i++){
		for(j = 0; j < W; j++){
			scanf("%d", &A[i][j]);
		}
	}
	for(i = 0; i < H; i++){
		for(j = 0; j < W; j++){
			int B;
			scanf("%d", &B);
			A[i][j] = abs(A[i][j] - B);
		}
	}
	vector<vector<bitset<2 * M>>> dp(H, vector<bitset<2 * M>>(W, bitset<2 * M>(0)));
	dp[0][0][M + A[0][0]] = 1;
	dp[0][0][M - A[0][0]] = 1;
	for(i = 0; i < H; i++){
		for(j = 0; j < W; j++){
			if(i > 0){
				dp[i][j] |= (dp[i - 1][j] << A[i][j]);
				dp[i][j] |= (dp[i - 1][j] >> A[i][j]);
			}
			if(j > 0){
				dp[i][j] |= (dp[i][j - 1] << A[i][j]);
				dp[i][j] |= (dp[i][j - 1] >> A[i][j]);
			}
		}
	}
	int ans = inf;
	for(i = 0; i < 2 * M; i++){
		if(dp[H - 1][W - 1][i] == 1){
			ans = min(ans, abs(i - M));
		}
	}
	printf("%d\n", ans);
	return 0;
}

Measured memory_bytes: 20736
#include <iostream>
#include <vector>
#define eol '\n'
using namespace std;

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

  int N;

  cin >> N;

  cout << N * (N + 1) / 2<< eol;
  
  return 0;
}


Measured memory_bytes: 256
def make_divisors(n):
    divisors = []
    for i in range(1, int(n**0.5)+1):
        if n % i == 0:
            divisors.append(i)
            if i != n // i:
                divisors.append(n//i)

    return divisors

N = int(input())
a = make_divisors(N)
b = []
c = []

for j in range(len(a)):
    for k in range(len(a)):
        if a[j] * a[k] == N:
            b.append([a[j],a[k]])

for l in range(len(b)):
    c.append(b[l][0] + b[l][1])

print(min(c) - 2)

Measured memory_bytes: 41948
#define _USE_MATH_DEFINES

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

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



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




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

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

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

	ll ans = -INF;

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

		int pos = i;
		ll cycle_cnt = 0;
		ll cycle_sum = 0;
		
		do {
			
			cycle_cnt++;
			cycle_sum += c[pos];
			pos = p[pos];
			
		} while (pos != i);

		ll sum = 0;
		ll cnt = 0;

		do{
			
			cnt++;
			sum += c[pos];
			if (cnt > k) {
				break;
			}
			
			ll num = (k - cnt) / cycle_cnt;
			ll score = sum + max(0ll, cycle_sum) * num;
			ans = max(ans, score);
			pos = p[pos];
			
		} while (pos != i);

	}

	std::cout << ans << endl;
}


Measured memory_bytes: 3644
#include<iostream>
#include<cstdio>
#include<string>
#include<algorithm>

int *Lv;
int n, k;

bool cmp_Lv(const int i, const int j){ return Lv[i] < Lv[j]; }

bool cmp(const int i, const int j){
    if(Lv[i] != Lv[j]){ return Lv[i] < Lv[j]; }
    int L_i = (i + k >= n ? -1 : Lv[i + k]);
    int L_j = (j + k >= n ? -1 : Lv[j + k]);

    return L_i < L_j;
}

int main()
{
    int *A, *newLv;
    std::string T;
    std::cin >> T;
    n = T.size();

    A = new int [n + 1]; Lv = new int [n + 1]; newLv = new int [n + 1];

    int i;
    for(i = 0; i < n; i++){ A[i] = i; }
    for(i = 0; i < n; i++){ Lv[i] = T[i]; }
    std::sort(A, A + n, cmp_Lv);

    newLv[A[0]] = 0;
    for(i = 1; i < n; i++){
        newLv[A[i]] = newLv[A[i - 1]] + (Lv[A[i]] != Lv[A[i - 1]] ? 1 : 0);
    }
    for(i = 0; i < n; i++){ Lv[i] = newLv[i]; }

    k = 1;
    while(1){
        if(k > n) break;

        std::sort(A, A + n, cmp);
        newLv[A[0]] = 0;
        for(i = 1; i < n; i++){ newLv[A[i]] = newLv[A[i - 1]] + (cmp(A[i - 1], A[i]) ? 1 : 0); }
        for(i = 0; i < n; i++){ Lv[i] = newLv[i]; }

        if(Lv[A[n - 1]] == n - 1) break;
        k <<= 1;
    };

    delete [] Lv; delete [] newLv;

	std::string P;
    int q, left, right, mid, crit;
    bool exist;
    scanf("%d", &q);

    A[n] = n;

    while(q){
		std::cin >> P;
        left = 0, right = n, exist = false;
        while(left < right){

            if(n < P.size()){ exist = false; break; }

            mid = (left + right) / 2;
            crit = T.compare(A[mid], P.size(), P);

            if(crit > 0){ right = mid; }
            else if(crit < 0){ left = mid + 1; }
            else{ exist = true; break; }
        };
        if(T.compare(A[right], P.size(), P) == 0) exist = true;
        if(exist){ printf("1\n"); }else{ printf("0\n"); }
        q--;
    }
	delete [] A;
    return 0;
}

Measured memory_bytes: 13988
#include<cstdio>
#include<cstdlib>
#include<cmath>
#include<cstring>
#include<cctype>
#include<complex>
#include<iostream>
#include<algorithm>
#include<functional>
#include<vector>
#include<string>
#include<stack>
#include<queue>
#include<map>

using namespace std;
const int dx[] = {1,0,-1,0},dy[] = {0,1,0,-1};
#define INF 999999
#define rep(i,j) for(int i=0;i<(j);++i)
#define reps(i,j,k) for(int i=j;i<k;++i)
typedef long long ll;
typedef unsigned long long ull;

int Change(int num){
	 num *= num;
	char mid[10]={0};
	sprintf(mid,"%d",num);
	int len = strlen(mid);
	char str[10]={0};
	int z = 0;
	fill(str,str+8,'0');
	reps(i,8-len,8){
		str[i] = mid[z];
		z++;
	}
	char fin[10]={0};
	rep(i,4){
		fin[i] = str[i+2];
	}
	return atoi(fin);
}
int main(){
	int n;
	scanf("%d",&n);
	rep(i,n){
		int num;
		scanf("%d",&num);
		printf("Case %d:\n",i+1);
		rep(j,10){
			num = Change(num);
			printf("%d\n",num);
		}
	}
	return 0;
}

Measured memory_bytes: 1196
using System;
using System.Linq;
using System.Numerics;

   class Program
    {
        static void Main()
        {
            var INF = (int)1e5;
            var N = int.Parse(Console.ReadLine());
            var steps = Console.ReadLine().Split().Select(int.Parse).ToArray();
            var dp = Enumerable.Repeat((int)INF, N + 1).ToArray();
            dp[0] = 0;
            dp[1] = Math.Abs(steps[0] - steps[1]);
            for (int i = 2; i < N; i++)
            {
                dp[i] = Math.Min(dp[i-1]+Math.Abs(steps[i] - steps[i - 1]),dp[i-2]+ Math.Abs(steps[i] - steps[i - 2]));
            }
            Console.WriteLine(dp[N - 1]);
        }
    }

Measured memory_bytes: 35668
import java.util.Scanner;

public class Main {

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

		int N = sc.nextInt();
		long X = sc.nextLong();

		Burger burger = null;
		for(int i=0;i<=N;i++) {
			burger = new Burger(i,burger);
		}

		System.out.println(search(N,0,X,burger));
	}
	public static long search(int lvl, long ret, long X, Burger bur) {
//		System.out.println("lv "+lvl+" ret "+ret+" x "+X+" byr "+bur);
		if(bur.level==0) {
			return ret+1;
		}
		if(X==1) {
			return ret;
		}
			if(mid(bur.size)==X) {
				ret+=bur.previos.paty+1;

			} else if(bur.size==X){
				ret+=bur.paty;

			} else if(X==0) {

			} else {
				if(bur.size/2 < X) {
					ret+=bur.previos.paty+1;
					ret=search(lvl-1, ret, X-bur.previos.size-2, bur.previos);
				} else {
					ret=search(lvl-1, ret, X-1, bur.previos);
				}

			}

		return ret;
	}
	public static long mid(long size) {
		return size/2+size%2;
	}
	static class Burger{
		int level;
		long pan;
		long paty;
		long size;
		Burger previos;
		Burger(int lvl,Burger bur){
			level=lvl;
			if(lvl==0) {
				previos=null;
				pan=0;
				paty=1;
			}else {
				previos=bur;
				pan=2+bur.pan*2;
				paty=1+bur.paty*2;
			}
			size=pan+paty;
		}
	}
}


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

    if temp!=1:
        arr.append([temp, 1])

    if arr==[]:
        arr.append([n, 1])

    return arr
A,B = map(int,input().split())
Afac = factorization(A)
Bfac = factorization(B)
Ans = {}
for i in range(len(Afac)):
    Af = Afac[i]
    if Af[0] not in Ans:
        Ans[Af[0]] = Af[1]
    else:
        Ans[Af[0]] = Af[1]
for j in range(len(Bfac)):
    Bf = Bfac[j]
    if Bf[0] not in Ans:
        Ans[Bf[0]] = Bf[1]
    else:
        Ans[Bf[0]] = max(Bf[1],Ans[Bf[0]])
Answer = 1
for n, m in Ans.items():
    Answer *= n**m
print(Answer)

Measured memory_bytes: 9368
#include<stdio.h>

#define N 250

int main(){
  int Heap[N];
  int loop,judge;
  int i;

  scanf("%d",&loop);

  judge=loop;
  
  for(i=1;i<loop+1;i++){
    scanf(" %d",&Heap[i]);
  }

  for(i=1;i<loop+1;i++){
    printf("node %d: key = %d, ",i,Heap[i]);

    if((i/2)>=1){
      printf("parent key = %d, ",Heap[(i/2)]);
    }

    if(judge>=(2*i)){
      printf("left key = %d, ",Heap[(2*i)]);
    }

    if(judge>=(2*i)+1){
      printf("right key = %d, ",Heap[(2*i)+1]);
    }

    printf("\n");
    
  }

  return 0;
}



Measured memory_bytes: 2044
#include <bits/stdc++.h>
#define ll long long
#define pb push_back

using namespace std;

const int  mod = 1e9 + 7;
const int e = 2e5 + 69;
const int base = 311;

ll child[e];

int main()
{
    ll n;
    cin >> n;
    for(int i=2; i<=n; i++)
    {
        ll par;
        cin >> par;
        child[par] ++;
    }
    for(int i=1; i<=n; i++) cout << child[i] <<"\n";
}


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

int main(){
    int n,a,b,c,d;
    string s;
    cin>>n>>a>>b>>c>>d>>s;
    for(int i=a-1;i<c;i++){
        if(s[i]==s[i+1]&&s[i]=='#'){
            cout<<"No"<<endl;
            return 0;
        }
    }
    for(int i=b-1;i<d;i++){
        if(s[i]==s[i+1]&&s[i]=='#'){
            cout<<"No"<<endl;
            return 0;
        }
    }
    if(c>d){
        for(int i=b-1;i<d;i++){
            if(s[i-1]==s[i]&&s[i+1]==s[i]&&s[i]=='.'){
                cout<<"Yes"<<endl;
                return 0;
            }
        }
        cout<<"No"<<endl;
    }else cout<<"Yes"<<endl;
}

Measured memory_bytes: 3728
import java.io.BufferedReader
import java.io.InputStreamReader
import java.io.PrintWriter

val br =  BufferedReader(InputStreamReader(System.`in`))
val out = PrintWriter(System.out)

fun main() {
    br.use { out.use {
        solve()
        out.flush()
    } }
}

fun solve() {
    val n = readInteger()
    var AC = 0
    var WA = 0
    var TLE = 0
    var RE = 0
    repeat(n) {
        when (br.readLine()) {
            "AC" -> AC++
            "WA" -> WA++
            "TLE" -> TLE++
            else -> RE++
        }
    }
    out.println("AC x $AC")
    out.println("WA x $WA")
    out.println("TLE x $TLE")
    out.println("RE x $RE")
}

fun readInteger() = Integer.parseInt(br.readLine())
fun readLong() = java.lang.Long.parseLong(br.readLine())
fun readStringList() = br.readLine()!!.split(' ')
fun readIntegerList() = readStringList().map(Integer::parseInt)
fun readLongList() = readStringList().map(java.lang.Long::parseLong)
fun readDoubleList() = readStringList().map(java.lang.Double::parseDouble)


Measured memory_bytes: 42392
import sys, math
input = sys.stdin.readline
rs = lambda: input().strip()
ri = lambda: int(input())
rl = lambda: list(map(int, input().split()))
mod = 10**9 + 7

N = ri()
D = rl()

ans = 0
for i in range(N):
	for j in range(i+1, N):
		ans += D[i]*D[j]
print(ans)

Measured memory_bytes: 39760
#include<cstdio>
#include<queue>
#include<algorithm>
#include<vector>
using namespace std;

const int MAXN=2005;

int n,in[MAXN];
int a[MAXN],g[MAXN][MAXN];
bool vis[MAXN];
vector<int> E[MAXN];
priority_queue<int> q;

int gcd(int x,int y){return !y?x:gcd(y,x%y);}

void dfs(int u,int fa=0){
    vis[u]=1;
    for(int i=1;i<=n;i++)
        if(g[u][i]&&!vis[i]){
            in[i]++;
            E[u].push_back(i);
            dfs(i);
        }
}

int main(){
    scanf("%d",&n);
    for(int i=1;i<=n;i++) scanf("%d",&a[i]);
    sort(a+1,a+n+1);
    for(int i=1;i<=n;i++)
        for(int j=1;j<=n;j++)
            if(gcd(a[i],a[j])!=1)
                g[i][j]=g[j][i]=1;
    for(int i=1;i<=n;i++)
        if(!vis[i]) dfs(i);
    for(int i=1;i<=n;i++)
        if(!in[i]) q.push(i);
    while(!q.empty()){
        int u=q.top(); q.pop();
        printf("%d ",a[u]);
        for(int i=0;i<(int)E[u].size();i++){
            int v=E[u][i];
            if((--in[v])==0)
                q.push(v);
        }
    }
}


Measured memory_bytes: 16128
#include<stdio.h>
#include<math.h>
int main(){
    int x,a,b;
    scanf("%d %d %d",&x,&a,&b);
    if(abs(x-a)<abs(x-b)){
        printf("A\n");
    }
    else{
        printf("B\n");
    }
    return 0;
}

Measured memory_bytes: 128
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, tan, asin, acos, atan, radians, degrees, log2, log
from itertools import accumulate, permutations, combinations, combinations_with_replacement, product, groupby
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left, insort, insort_left
from fractions import gcd
from heapq import heappush, heappop
from functools import reduce
from decimal import Decimal
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def ZIP(n): return zip(*(MAP() for _ in range(n)))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10**9 + 7
from decimal import *

H, W, A, B = MAP()

for _ in range(B):
	print("0"*A + "1"*(W-A))
for _ in range(B, H):
	print("1"*A + "0"*(W-A))

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

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

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

  int ans = 0;
  if (S.find("RRR") < string::npos) {
    ans = 3;
  } else if (S.find("RR") < string::npos) {
    ans = 2;
  } else if (S.find("R") < string::npos) {
    ans = 1;
  } else {
    ans = 0;
  }

  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 3620
#include <bits/stdc++.h>
using namespace std;
#define mem(a,b) memset(a,b,sizeof(a))
#define pii pair<int,int>
#define int long long
const int inf = 0x3f3f3f3f;
const int maxn = 201110;
const int M = 1e9+7;
int n,m,k,ok;

signed main()
{
    cin>>n>>m;
    cout<<((n)*(n-1)/2+m*(m-1)/2)<<endl;
    return 0;
}

Measured memory_bytes: 256
#include <algorithm>
#include<iostream>
#include<cstring>
#include<cstdio>
using namespace std;
 
int h,w,a,b;
void f1(){
	for(int i=1;i<=a;i++){
		cout<<"1";
	}
	for(int i=a+1;i<=w;i++){
		cout<<"0";
	}
	cout<<endl;	
}
void f2(){
	for(int i=1;i<=a;i++){
		cout<<"0";
	}
	for(int i=a+1;i<=w;i++){
		cout<<"1";
	}
	cout<<endl;	
}
int main(){
	cin>>h>>w>>a>>b;
	for(int i=1;i<=b;i++){
		f1();
	}
	for(int i=b+1;i<=h;i++){
		f2();
	}
	return 0;
}


Measured memory_bytes: 1280
#include <bits/stdc++.h>
#define N 1000500
using namespace std;
int a[N],b[N],c[N],d[N],fa[N],n,ans,tot;
map<int,int> mp;
int gf(int x) {return fa[x]==x ? x : fa[x] = gf(fa[x]);}
inline int rd() {int r;scanf("%d",&r);return r;}
int main() {
	n = rd();
	for (int _=1;_<=n;_++) a[_] = rd();
	for (int _=1;_<=n;_++) b[_] = rd();

	for (int _=1;_<=n;_++) a[n+1] ^= a[_], b[n+1] ^= b[_];
	++n;
	for (int _=1;_<=n;_++) c[_] = a[_], d[_] = b[_];

	sort(c+1,c+n+1); sort(d+1,d+n+1);
	for (int _=1;_<=n;_++) if (d[_]!=c[_]) return puts("-1"), 0;
	
	for (int _=1;_<=n;_++) if (a[_] != b[_] || _ == n) {
		_<n ? ++ans :0;
		!mp[ a[_] ] ? mp[ a[_] ] = ++tot :0;
		!mp[ b[_] ] ? mp[ b[_] ] = ++tot :0;
	}
	
	if (!ans) return puts("0"), 0;

	for (int _=1;_<=tot;_++) fa[_] = _;
	for (int _=1;_<n;_++) if (a[_] != b[_])
		fa[ gf( mp[a[_]] ) ] = gf( mp[b[_]] );
	for (int _=1;_<=tot;_++) ans += fa[_] == _;
	cout << ans-1 << endl;

	return 0;
}

Measured memory_bytes: 19200
#include <stdio.h>
#include <stdlib.h>
#define NIL NULL

typedef struct node{
	int key;
	int priority;
	struct node *right , *left;
}Node;

Node * Delete(Node **,int);
Node * delete(Node **,int);

int find(Node *p,int x)
{
	while(p!=NIL)
	{
		if(p->key==x)return 1;
		else if(p->key > x)p = p->left;
		else p = p->right;
	}
	return 0;
}

void inorder(Node *a)
{
	if(a->left!=NIL) inorder(a->left);
	printf(" %d",a->key);
	if(a->right!=NIL) inorder(a->right);
	return;
}

void preorder(Node *p)
{
	printf(" %d",p->key);
	if(p->left!=NIL) preorder(p->left);
	if(p->right!=NIL) preorder(p->right);
	return;
}

void print(Node *p)
{
	inorder(p);
	printf("\n");
	preorder(p);
	printf("\n");
	return;
}

Node * makenode(int x , int y)
{
	Node *new = malloc(sizeof(Node));
	new->key = x;
	new->priority = y;
	new->left = NIL;
	new->right = NIL;
	return new;
}

Node *rightRotate(Node *p)
{
	Node *q = p->left;
	p->left = q->right;
	q->right = p;
	return q;
}

Node *leftRotate(Node *p)
{
	Node *q = p->right;
	p->right = q->left;
	q->left = p;
	return q;
}

Node* insert(Node **t , int key, int priority)  // 再帰的に探索
{
	Node *new;
	if((*t)==NIL)
	return new = makenode(key,priority); // 葉に到達したら新しい節点を生成して返す
	if((*t)->key == key)
	return *t;  // 重複したkeyは無視
	
	if(key < (*t)->key) // 左の子へ移動
	{
		(*t)->left = insert(&(*t)->left,key,priority); // 左の子へのポインタを更新
		if((*t)->priority < (*t)->left->priority) // 左の子の方が優先度が高い場合右回転
		(*t) = rightRotate(*t);
	}
	else{ // 右の子へ移動
		(*t)->right = insert(&(*t)->right,key,priority); // 右の子へのポインタを更新
		if((*t)->priority < (*t)->right->priority) // 右の子の方が優先度が高い場合左回転
		(*t) = leftRotate((*t));
	}
	return *t;
}

Node * Delete(Node **t , int key)
{
	if((*t)==NIL)
	return NIL;
	
	if(key < (*t)->key) // 削除対象を検索
	(*t)->left = Delete(&((*t)->left),key);
	
	else if(key > (*t)->key)
	(*t)->right = Delete(&((*t)->right),key);
	
	else return delete(t,key);
	return *t;
}

Node * delete(Node **t , int key)
{
	if((*t)->left == NIL && (*t)->right == NIL)  // 葉の場合
	{
		return NIL;
	}
	else if((*t)->left == NIL) // 右の子のみを持つ場合左回転
	{
		(*t) = leftRotate(*t);
	}
	else if((*t)->right ==NIL) // 左の子のみを持つ場合右回転
	{
		(*t) = rightRotate(*t);
	}
	else{ // 左の子と右の子を両方持つ場合
		if((*t)->left->priority > (*t)->right->priority) // 優先度が高い方を持ち上げる
		(*t) = rightRotate(*t);
		else
		(*t) = leftRotate(*t);
	}
	return Delete(t,key);
}

int main(void)
{
	int num ,  x, y;
	char com[8];
	Node *root = NIL;
	scanf("%d",&num);
	
	for(int i = 0; i < num; i++)
	{
		scanf("%s",com);
		switch(com[0])
		{
		  case 'i':scanf("%d %d",&x,&y);
			root = insert(&root,x,y);
			break;
		  case 'd':scanf("%d",&x);
			root = Delete(&root,x);
			break;
		  case 'f':scanf("%d",&x);
			if(find(root,x))printf("yes\n");
			else printf("no\n");
			break;
		  case 'p':print(root);
			break;
		}
	}
	return 0;
}


Measured memory_bytes: 8036
// https://atcoder.jp/contests/abc133/tasks/abc133_d
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cstdlib>
#include <vector>
#include <string>
#include <algorithm>
#include <numeric>
#include <map>
#include <unordered_map>
#include <stack>
#include <queue>
#include <set>
#include <unordered_set>
#include <bitset>
using namespace std;
using ll = long long;
using P = pair<ll, ll>;
#define REP(i, n) for(size_t i = 0; i < (n); ++i)
#define READD(n) scanf("%d", &n)
int main()
{
    int N;
    READD(N);
    vector<ll> A(N);
    REP(i, N) cin >> A[i];
    vector<ll> B(N, 0);
    int sig = 1;
    REP(i, N)
    {
        B[0] += sig * A[i];
        sig *= -1;
    }
    for (int i = 1; i < N; ++i)
    {
        B[i] = 2 * A[i - 1] - B[i - 1];
    }
    REP(i, N)
    {
        printf("%lld", B[i]);
        if (i == N - 1) printf("\n");
        else printf(" ");
    }
    return 0;
}


Measured memory_bytes: 4900
#include <iostream>
#include <vector>
#include <queue>

int main() {
  int N, M;
  std::cin >> N >> M;
  
  std::priority_queue<unsigned int, std::vector<unsigned int>> heap;
  for (int i=0, temp; i<N; ++i) {
    std::cin >> temp;
    heap.push(temp);
  }
  
  for (int i=0; i<M; ++i) {
    auto top = heap.top();
    heap.pop();
    heap.emplace(top / 2);
  }
  
  unsigned long long ans = 0;
  while (!heap.empty()) {
    ans += heap.top();
    heap.pop();
  }
  
  std::cout << ans << std::endl;
}

Measured memory_bytes: 892
#include<iostream>
#include<algorithm>
using namespace std;
long long int aI,aO,aT,aJ,aL,aS,aZ;
int a[3][3][3];
int main()
{
	cin>>aI>>aO>>aT>>aJ>>aL>>aS>>aZ;
	int tempI=0,tempL=0,tempJ=0;
	long long int ans=0;
	a[0][0][0]=0;
	a[0][0][1]=0;
	a[0][0][2]=2;
	a[0][1][0]=0;
	a[0][1][1]=0;
	a[0][1][2]=2;
	a[0][2][0]=2;
	a[0][2][1]=2;
	a[0][2][2]=4;
	a[1][0][0]=0;
	a[1][0][1]=0;
	a[1][0][2]=2;
	a[1][1][0]=0;
	a[1][1][2]=3;//I,J,L;
	a[1][1][1]=3;
	a[1][2][1]=3;
	a[1][2][2]=4;
	a[1][2][0]=2;
	a[2][0][0]=2;
	a[2][0][1]=2;
	a[2][0][2]=4;
	a[2][1][0]=2;
	a[2][1][1]=3;
	a[2][1][2]=4;
	a[2][2][0]=4;
	a[2][2][1]=4;
	a[2][2][2]=6;
	ans+=aO;
	if(aI>=2){
		if(aI%2==0){
			ans+=(aI-2);
			tempI=2;
		}
		else{
			ans+=(aI-1);
			tempI=1;
		}
	}
	else{
		tempI=aI;
	}
	if(aL>=2){
		if(aL%2==0){
			ans+=(aL-2);
			tempL=2;
		}
		else{
			ans+=(aL-1);
			tempL=1;
		}
	}
	else{
		tempL=aL;
	}
	if(aJ>=2){
		if(aJ%2==0){
			ans+=(aJ-2);
			tempJ=2;
		}
		else{
			ans+=(aJ-1);
			tempJ=1;
		}
	}
	else{
		tempJ=aJ;
	}
	ans+=a[tempI][tempJ][tempL];
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 256
n = int(input())
a = [int(i) for i in input().split()]
b = [int(i) for i in input().split()]

ans = 0

for i in range(n):
  if b[i] > a[i]:
    ans += a[i]
    if (b[i] - a[i]) > a[i+1]:      
      ans += a[i+1]
      a[i+1] = 0
    else:
      ans += b[i] - a[i]
      a[i+1] -= (b[i] - a[i])
  else:
    ans += b[i]
print(ans)

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

using static Input;
using static Util;
class Program
{
    static int N;
    static void INPUT()
    {
        N = NextInt();
    }
    static void OUTPUT()
    {
        Console.WriteLine(N*N*N);
    }

    static void Main(string[] args)
    {
#if DEBUG  
        TESTINPUT();
        INPUT();
#else
        INPUT();
#endif
        OUTPUT();
    }

    static void TESTINPUT()
    {
        N = 3;
    }
}

public class Input
{
    public const long MOD = 1000000007;
    public const int INF = 1000000007;
    private static Queue<string> q = new Queue<string>();
    private static void Confirm() { if (q.Count == 0) foreach (var s in Console.ReadLine().Split(' ')) q.Enqueue(s); }
    public static int NextInt() { Confirm(); return int.Parse(q.Dequeue()); }
    public static long NextLong() { Confirm(); return long.Parse(q.Dequeue()); }
    public static string NextString() { Confirm(); return q.Dequeue(); }
    public static double NextDouble() { Confirm(); return double.Parse(q.Dequeue()); }
    public static int[] LineInt() { return Console.ReadLine().Split(' ').Select(int.Parse).ToArray(); }
    public static long[] LineLong() { return Console.ReadLine().Split(' ').Select(long.Parse).ToArray(); }
    public static string[] LineString() { return Console.ReadLine().Split(' ').ToArray(); }
    public static double[] LineDouble() { return Console.ReadLine().Split(' ').Select(double.Parse).ToArray(); }
}

class Util
{

}




Measured memory_bytes: 11220
# -*- coding:utf-8 -*-
N = int(input())
a = list(map(int, input().split()))
rate = [ 0 for tmp in range(9) ]
factor = 0
empty = 0
for tmp in range(N):
    if 1 <= a[tmp] and  a[tmp] <= 399:
        rate[0] += 1
    elif 400 <= a[tmp] and a[tmp] <= 799:
        rate[1] += 1
    elif 800 <= a[tmp] and a[tmp] <= 1199:
        rate[2] += 1
    elif 1200 <= a[tmp] and a[tmp] <= 1599:
        rate[3] += 1
    elif 1600 <= a[tmp] and a[tmp] <= 1999:
        rate[4] += 1
    elif 2000 <= a[tmp] and a[tmp]<= 2399:
        rate[5] += 1
    elif 2400 <= a[tmp] and a[tmp] <= 2799:
        rate[6] += 1
    elif 2800 <= a[tmp] and a[tmp] <= 3199:
        rate[7] += 1
    else:
        rate[8] += 1
for tmp in range(len(rate)-1):
    if rate[tmp] > 0:
        factor += 1
    else:
        empty += 1
if rate[8] > 0:
    if factor == 0:
        print("1 "+str(rate[8]))
    else:
        print(str(factor)+' '+str(factor+rate[8]))
else:
    print(str(factor)+' '+str(factor)) 

Measured memory_bytes: 3064
#include <stdio.h>
 
int main(){
     
char num[1001];
 
    while(1){
        int i=0,sum=0;
 
        scanf("%s", num);
        if(num[0]-'0'==0) break;
         
        while(num[i]){
        sum+=num[i]-'0';
        i++;
        }
    printf("%d\n",sum);
    }
     
    return(0);
}


Measured memory_bytes: 1804
#include <stdio.h>  
#include <algorithm>  
#include <assert.h>
#include <bitset>
#include <cmath>  
#include <complex>  
#include <deque>  
#include <functional>  
#include <iostream>  
#include <limits.h>  
#include <map>  
#include <math.h>  
#include <queue>  
#include <deque>
#include <set>  
#include <stdlib.h>  
#include <string.h>  
#include <string>  
#include <time.h>  
#include <unordered_map>  
#include <unordered_set>  
#include <vector>  
#include <chrono>
#include <random>
#include <time.h>
#include <fstream>
#define ll long long
#define rep2(i,a,b) for(ll i=a;i<=b;++i)
#define rep(i,n) for(ll i=0;i<n;i++)
#define rep3(i,a,b) for(ll i=a;i>=b;i--)
#define pii pair<int,int>
#define pll pair<ll,ll>
#define pq priority_queue<int>
#define pqg priority_queue<int,vector<int>,greater<int>>
#define pb push_back
#define vec vector<int>
#define vecll vector<ll>
#define vecpii vector<pii>
#define endl "\n"
#define all(c) begin(c),end(c)
using namespace std;
int in() {int x;scanf("%d",&x);return x;}
ll lin() {ll x;scanf("%lld",&x);return x;}
void print(vec v){for(auto e:v)cout<<e<<" ";cout<<endl;}
void print(vecll v){for(auto e:v)cout<<e<<" ";cout<<endl;}
void print(map<int,int> mp){for(auto e:mp)cout<<e.first<<" "<<e.second<<endl;cout<<endl;}


#define INF 1e9+7
#define LLINF 1e18+7
const ll MOD=1e9+7;
const int N=500000;


main(){
    int n=in();ll k=in();
    vector<ll> a;
    a.pb(0);
    rep(i,n){
        a.pb(a.back()+in()-1);
    }
    rep(i,n+1)a[i]=(a[i]%k+k)%k;
    map<ll,ll> mp;
    ll ans=0;
    mp[0]++;
    rep2(i,1,n){
        if(i-k>=0){
            mp[a[i-k]]--;
        }
        ans+=mp[a[i]];
        mp[a[i]]++;
    }
    cout<<ans;
}

Measured memory_bytes: 14320
#include<iostream>
#include<cstring>
#include<string>
using namespace std;
int main()
{
	char str[20];
	cin>>str+1;
	int flag=1;
	int len=strlen(str+1);
	if(len%2==1)
	flag=0;
	for(int i=1;i<=strlen(str)-1;i=i+2)
	{
		if(str[i]=='h'&&str[i+1]=='i')
		;
		else
		{
			flag=0;
			break;
		}
	}
	if(flag) cout<<"Yes"<<endl;
	else
	cout<<"No"<<endl;
 } 

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

ac = [False]*N
wa = [0]*N

for i in range(M):
    p,res=input().split()
    p = int(p)-1
    if res=="AC":
        ac[p]=True
    else:
        if not ac[p]:
            wa[p]+=1
account = 0
wacount = 0
for i in range(N):
    if ac[i]:
        account+=1
        wacount+=wa[i]

print(account,wacount)

Measured memory_bytes: 45400
#include <bits/stdc++.h>
using namespace std;
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;
}
typedef long long int ll;

#define EPS (1e-7)
#define INF (1 << 30)
#define LLINF (1LL << 60)
#define PI (acos(-1))
#define MOD (1000000007)
#define ALL(v) (v).begin(), (v).end()
#define RALL(v) (v).rbegin(), (v).rend()
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};

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

ll dp[101][10];

int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int h, w, k;
    cin >> h >> w >> k;
    dp[0][0] = 1;
    for (int i = 0; i < h; i++)
    {
        for (int j = 0; j < w; j++)
        {
            // bitで何処を使ったか状態管理
            for (int bit = 0; bit < (1 << (w - 1)); bit++)
            {
                bool flg = true;
                // 横線を使えるかどうかを調べる
                for (int k = 0; k < w - 2; k++)
                {
                    // その位置から前か後ろを使っていたらfalse
                    if ((bit & (1 << k)) && (bit & (1 << (k + 1))))
                    {
                        flg = false;
                    }
                }
                if (flg)
                {
                    if (bit & (1 << j))
                    {
                        // 左
                        (dp[i + 1][j + 1] += dp[i][j]) %= MOD;
                    }
                    else if (j >= 1 && (bit & (1 << (j - 1))))
                    {
                        // 右
                        (dp[i + 1][j - 1] += dp[i][j]) %= MOD;
                    }
                    else
                    {
                        // 上
                        (dp[i + 1][j] += dp[i][j]) %= MOD;
                    }
                }
            }
        }
    }
    cout << dp[h][k - 1] << endl;
}

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

const int N = 200005;

int n, k, a[N], b[N];

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    cin >> n >> k;
    int q = min(k, 40);
    for (int i = 1; i <= n; i++) {
        cin >> a[i];
    }
    while (q--) {
        for (int i = 1; i <= n; i++) {
            b[max(1, i - a[i])]++;
            b[min(n + 1, i + a[i] + 1)]--;
        }
        for (int i = 1; i <= n; i++) {
            a[i] = b[i] + a[i - 1];
            b[i] = 0;
        }
    }
    for (int i = 1; i <= n; i++) {
        cout << min(n, a[i] + k - min(k, 40)) << " ";
    }
}


Measured memory_bytes: 5208
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10**9)

n,m = map(int, input().split())
G = [[] for i in range(n)]
for i in range(m):
    a,b = map(int, input().split())
    a,b = a-1,b-1
    G[a].append(b)

from collections import deque

inf = float("inf")
ans = inf
ss = []
def bfs(i):
    global ans, ss
    dist = [inf]*n
    prev = [None]*n
    que = deque()
    # 一個先から始める
    for to in G[i]:
        que.append(to)
        dist[to] = 1
        prev[to] = i
    while que:
        cur = que.popleft()
        if cur == i:
            break
        for to in G[cur]:
            if dist[to] != inf:
                continue
            dist[to] = dist[cur]+1
            prev[to] = cur
            que.append(to)

    if dist[i] < ans:
        ans = dist[i]
        ss = [i]
        for _ in range(ans-1):
            ss.append(prev[ss[-1]])
        #print(ss)

for i in range(n):
    bfs(i)

if ans == inf:
    print(-1)
else:
    print(ans)
    #print(ss)
    for i in reversed(ss):
        print(i+1)

Measured memory_bytes: 44508
#include <bits/stdc++.h>
#define Int int64_t

using namespace std;

int main() {
	int H, W, A, B;
	cin >> H >> W >> A >> B;

	vector<vector<int>> s(H, vector<int>(W, 0));
	for (int i = 0; i < H; ++i) {
		for (int j = 0; j < W; ++j) {
			if (i < B) {
				if (j < A) { s[i][j] = 0; }
				else { s[i][j] = 1; }
			} else {
				if (j < A) { s[i][j] = 1; }
				else { s[i][j] = 0; }
			}
		}
	}

	for (int i = 0; i < H; ++i) {
		for (int j = 0; j < W; ++j) {
			cout << s[i][j];
		}
		cout << endl;
	}

	return 0;
}


Measured memory_bytes: 5120
#include <cstdio>
#include <algorithm>
#define LL long long
#define N 100005
using namespace std;

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

int n,q,a,b,c,k,cnt;
LL fa[N][18][2],ans;
int head[N],dep[N];
bool f;
struct edge
{
	int to,next; LL w;
}e[N<<1];

void addedge(int u,int v,LL w)
{
	e[++cnt].to=v; e[cnt].next=head[u]; head[u]=cnt; e[cnt].w=w;
}

void dfs(int u,int fas)
{
	dep[u]=dep[fas]+1;
	for(int i=head[u];i;i=e[i].next)
	{
		int v=e[i].to; 
		if(v==fas) continue;
		fa[v][0][0]=u; fa[v][0][1]=e[i].w;
		dfs(v,u);
	}
}

int lca(int x,int y)
{
	if(dep[x]<dep[y]) swap(x,y);
	for(int i=17;i>=0;i--)
		if(dep[y]<=dep[fa[x][i][0]]) x=fa[x][i][0];
	if(x==y) return x;
	for(int i=17;i>=0;i--)
		if(fa[x][i][0]!=fa[y][i][0]) 
		{
			x=fa[x][i][0]; 
			y=fa[y][i][0];
		}
	return fa[x][0][0];
}


LL lca1(int x,int y)
{
	LL res=0;
	if(dep[x]<dep[y]) swap(x,y);
	for(int i=17;i>=0;i--)
		if(dep[y]<=dep[fa[x][i][0]]) res+=fa[x][i][1],x=fa[x][i][0];
	if(x==y) return res;
	//printf("hhh %d %d\n",x,y);
	for(int i=17;i>=0;i--)
		if(fa[x][i][0]!=fa[y][i][0]) 
		{
			res+=fa[x][i][1]; res+=fa[y][i][1];
			x=fa[x][i][0]; 
			y=fa[y][i][0];
		}
	res+=fa[x][0][1]+fa[y][0][1];
	return res;
}
int main()
{
	n=read();
	for(int i=1;i<n;i++)
	{
		a=read(); b=read(); c=read();
		addedge(a,b,c); addedge(b,a,c);
	}
	dfs(1,0);
	for(int j=1;j<=17;j++)
	for(int i=1;i<=n;i++)
	{
		fa[i][j][0]=fa[fa[i][j-1][0]][j-1][0];
		fa[i][j][1]=fa[fa[i][j-1][0]][j-1][1]+fa[i][j-1][1];
		//printf("%d %d %lld\n",i,j,fa[i][j][1]);
	}
	q=read(); k=read();
	while(q--)
	{
		a=read(); b=read();
		if(dep[a]<dep[b]) swap(a,b);
		f=false; int fas=lca(a,b); 
		//printf("lca=%d\n",fas);
		if(k==a || k==b) f=true;
		if((dep[k]<dep[a] && lca(a,k)==k && lca(k,fas)==fas) ||(dep[k]<dep[b] && lca(b,k)==k && lca(k,fas)==fas)) f=true;
		//printf("%lld %lld\n",lca1(a,k),lca1(k,b));
	//	printf("%d %d %d\n",a,b,k);
		//printf("hhh %lld %lld\n",lca1(a,k),lca1(k,b));
		if(f) printf("%lld\n",lca1(a,b)); else printf("%lld\n",lca1(a,k)+lca1(k,b));
	}
	return 0;
}


Measured memory_bytes: 38400
import sys


lines = 4
inp = list()

for _ in range(lines):
    inp.append(sys.stdin.readline().strip())

n500 = int(inp[0])
n100 = int(inp[1])
n50 = int(inp[2])
total = int(inp[3])

pattern = 0

i = 0
while i * 500 <= total and i <= n500:
    j = 0
    while j * 100 <= total and j <= n100:
        k = 0
        while k * 50 <= total and k <= n50:
            if i * 500 + j * 100 + k * 50 == total:
                pattern += 1
            k += 1
        j += 1
    i += 1

print(pattern)


Measured memory_bytes: 3064
#include <algorithm>
#include <cmath>
#include <complex>
#include <cstdio>
#include <deque>
#include <iomanip>
#include <ios>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <tuple>
#include <unordered_map>
#include <utility>
#include <vector>
#define itn int
#define retrun return
#define rep(i, n) for (int i = 0, i##_len = (n); i < i##_len; ++i)
using namespace std;
typedef long long llong;
typedef pair<int, int> pii;
llong gcd(llong a, llong b) {
	if (a < b) std::swap(a, b);
	if (a % b == 0)
		return b;
	else
		return gcd(b, a % b);
}
llong lcm(llong a, llong b) {
	llong g = gcd(a, b);
	return a * b / g;
}
//ここまで共通
int X, Y, A, B, C;
vector<int> P, Q, R;
priority_queue<int, vector<int>, greater<int>> S;
llong ANS = 0;
int main() {
	cin >> X >> Y >> A >> B >> C;
	for (int i = 0; i < A; i++) {
		int p;
		cin >> p;
		P.push_back(p);
	}
	for (int i = 0; i < B; i++) {
		int q; cin >> q;
		Q.push_back(q);
	}
	for (int i = 0; i < C; i++) {
		int r;
		cin >> r;
		R.push_back(r);
	}
	R.push_back(0);

	sort(P.begin(), P.end(), greater<int>());
	sort(Q.begin(), Q.end(), greater<int>());
	sort(R.begin(), R.end(), greater<int>());
	for (int i = 0; i < X; i++) {
		S.push(P[i]);
	}
	for (int i = 0; i < Y; i++) {
		S.push(Q[i]);
	}
	for (int i = 0; i < R.size(); i++) {
		if (R[i] <= S.top()) break;

		S.pop();
		S.push(R[i]);
	}
	while (!S.empty()) {
		ANS += S.top();
		S.pop();
	}
	cout << ANS << endl;
	return 0;
}

Measured memory_bytes: 2552
#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>;
 
 
int main() {
    int m,d,mm,dd;
    cin >> m >> d >> mm >> dd;
    if(m!=mm) cout << "1" << endl;
    else cout << "0" << endl;
}


Measured memory_bytes: 3584
using System;
using System.Collections.Generic;
using static Exter;
using System.Linq;
#if DEBUG
#else
using console = System.Console;
#endif

public class App
{
    public static void Main(string[] args)
    {
        long n = readarr[0];
        cout = readarr.Sum(v=>Math.Abs(v))-(preadarr.Count(v=>v<0)%2==0?0:preadarr.Min(v=>Math.Abs(v))*2);
        
    }
}
public static class Exter
{
    public static void rep(int loop,Action<int> act)
    {
        for(int i=0;i<loop;i++)
            act(i);
    }
    public static int ToInt(this string v)=>int.Parse(v);
    public static int Max(params int[] p)=>p.Max();
    public static long Max(params long[] p)=>p.Max();
    public static int Min(params int[] p)=>p.Min();
    public static long Min(params long[] p)=>p.Min();
    public static int Gcd(int a, int b)=>a > b ? GcdRecursive(a, b) : GcdRecursive(b, a);
    private static int GcdRecursive(int a, int b)=>b == 0 ? a : GcdRecursive(b, a % b);
    public static object cout
    {
        set
        {
            console.Write(value.ToString());
            console.WriteLine();
            
        }
    }
    public static void ToCout<t>(this IEnumerable<t> v)
    {
        cout = string.Join(",",v);
    }
    public static long[] readarr
    {
        get 
        {
            preadarr = console.ReadLine().Split().Select(s=>long.Parse(s)).ToArray();
            return preadarr;
        }
    }
    public static long[] preadarr;
}


#if DEBUG
public static class console
{
    static int cursorLine = 0;
    static readonly string[] cin = new string[]
    {
                "3",
"-10 5 -4"
    };
    static public string ReadLine()
    { 
        return cin[cursorLine++];
    }
    static public void WriteLine()
    {
        Console.WriteLine();
    }
    static public void WriteLine<T>(T input)
    {
        Console.WriteLine(input);
    }
    static public void Write<T>(T input)
    {
        Console.Write(input);
    }
    static public void WriteLine(string s,params object[] arr)
    {
        Console.WriteLine(s,arr);
    }
}
#endif

Measured memory_bytes: 29532
type t = { mutable parent : int; mutable rank : int }

let split_on_char sep s =
  let open String in
  let r = ref [] in
  let j = ref (length s) in
  for i = length s - 1 downto 0 do
    if get s i = sep then begin
      r := sub s (i + 1) (!j - i - 1) :: !r;
      j := i
    end
  done;
  sub s 0 !j :: !r

let readln () = read_line () |> split_on_char ' ' |> List.map int_of_string

let find s x =
  let rec doit x =
    let p = s.(x).parent in
    if x = p then x
    else begin
      s.(x).parent <- doit p;
      s.(x).parent
    end in
  doit x

let unite s x y =
  let px = find s x in
  let py = find s y in
  if s.(px).rank > s.(py).rank then s.(py).parent <- px
  else begin
    s.(px).parent <- py;
    if s.(px).rank = s.(py).rank then s.(py).rank <- s.(py).rank + 1
  end

let same_p s x y = find s x = find s y

let solve n q =
  let s = Array.init n (fun i -> { parent = i; rank = 0 }) in
  for i = 0 to q - 1 do
    match readln () with
    | n :: x :: y :: _ ->
      if n = 0 then unite s x y
      else print_endline (if same_p s x y then "1" else "0")
    | _ -> assert false
  done

let () =
  match readln () with
  | [n; q] -> solve n q
  | _ -> assert false

Measured memory_bytes: 4652