akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<string>
#include<algorithm>
#include<math.h>
using namespace std;

const int N=2e5+5;
const int M=5e5+5;
const int T=1e6+5;
const int mod=924844033;
const int sqr=5;
const int sqrinv=554906420;

int n,u,v,siz[N],limit,lg;
int E,ot[M],ne[M],g[N];
int fac[N],inv[N],infac[N];
int a[T],b[T],r[T];

int F_p(int x,int y)
{
	int bas=x,ret=1;
	while(y)
	{
		if(y&1) ret=1LL*ret*bas%mod;
		bas=1LL*bas*bas%mod;
		y>>=1;
	}
	return ret;
}

void add(int u,int v)
{
	ot[++E]=v;
	ne[E]=g[u];
	g[u]=E;
}

void init()
{
	int i;
	scanf("%d",&n);
	for(i=1;i<n;++i)
	{
		scanf("%d%d",&u,&v);
		add(u,v),add(v,u);
	}
}

void dfs(int x,int fath)
{
	siz[x]=1;
	int p,to;
	for(p=g[x];p;p=ne[p])
	{
		to=ot[p];
		if(to==fath) continue;
		dfs(to,x);
		siz[x]+=siz[to];
		++a[siz[to]];
	}
	++a[n-siz[x]];
}

int solve_complex(int x,int tp)
{
	if(~tp) return F_p(sqr,x);
	else return F_p(sqrinv,x);
}

void DFT(int *A,int tp)
{
	int i;
	for(i=0;i<limit;++i)
		if(i<r[i])
			swap(A[i],A[r[i]]);
	
	int len,j,k;
	for(len=1;len<limit;len<<=1)
	{
		int wn=solve_complex((mod-1)/(2*len),tp);
		for(j=0;j<limit;j+=len<<1)
		{
			int w=1;
			for(k=0;k<len;++k,w=1LL*w*wn%mod)
			{
				int x=A[j+k];
				int y=1LL*w*A[j+k+len]%mod;
				A[j+k]=x+y,A[j+k+len]=x-y;
				if(A[j+k]>=mod) A[j+k]-=mod;
				if(A[j+k+len]<0) A[j+k+len]+=mod;
			}
		}
	}
}

void prework()
{
	int i;dfs(1,0);
	fac[0]=1;for(i=1;i<=n;++i) fac[i]=1LL*fac[i-1]*i%mod;
	inv[1]=1;for(i=2;i<=n;++i) inv[i]=1LL*inv[mod%i]*(mod-mod/i)%mod;
	infac[0]=1;for(i=1;i<=n;++i) infac[i]=1LL*infac[i-1]*inv[i]%mod;
}

void work()
{
	int i;a[0]=0;
	for(i=0;i<=n;++i) a[i]=1LL*a[i]*fac[i]%mod;
	for(i=0;i<=n;++i) b[i]=infac[n-i];
	
	limit=1;
	while(limit<=2*n) limit<<=1,++lg;
	for(i=1;i<limit;++i) r[i]=(r[i>>1]>>1)|((i&1)<<(lg-1));
	
	DFT(a,1),DFT(b,1);
	for(i=0;i<limit;++i) a[i]=1LL*a[i]*b[i]%mod;
	DFT(a,-1);
	
	int INV=F_p(limit,mod-2);
	for(i=1;i<=n;++i) a[i+n]=1LL*a[i+n]*INV%mod*infac[i]%mod;
	for(i=1;i<=n;++i) a[i]=1LL*fac[n]*infac[i]%mod*infac[n-i]%mod*n%mod;
	for(i=1;i<=n;++i)
	{
		a[i]-=a[i+n];
		if(a[i]<0) a[i]+=mod;
	}
	for(i=1;i<=n;++i) printf("%d\n",a[i]);
}

int main()
{
	init();prework();work();
	return 0;
}

Measured memory_bytes: 30128
#include<bits/stdc++.h>
#define    ll   long long int
#define    sz   200010
#define    md   1000000007
#define    py   printf("YES\n")
#define    pn   printf("NO\n")

using namespace std;


ll vis[sz];


int main()
{


    ll  s,n,i,j,k,p,d,x,y;

    cin>>s;
    vis[s]=1;

    for(i=2; i<=10000; i++)
    {
        if(s%2==0)
        {
            s/=2;

        }
        else
        {
            s=3*s+1;
        }
        if(vis[s]==0)
        {
            vis[s]=1;
        }
        else
        {
            cout<<i<<endl;
            return 0;
        }
    }


    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
	int n;
	cin>>n;
	vector<long> dam;
	for(int i=1;i<=n;i++)
	{
		long x;
		cin>>x;
		dam.push_back(x);
	}
	long sum=0;
	long m[n];
	for(int i=0;i<n;i++)
	{
		if(i%2==0)
			sum+=dam[i];
		else
			sum+=-1*dam[i];
	}
	m[0]=sum;
	for(int i=1;i<n;i++)
	{
		m[i]=2*dam[i-1]-m[i-1];
	}
	for(auto k: m)
		cout<<k<<" ";
	return 0;
}

Measured memory_bytes: 3060
#include<stdio.h>
#include<algorithm>
#include<iostream>
#include<cstring>
#define ll long long
#define MAXN 200005
#define MAXM 400005
using namespace std;
int N,A,B,Ans[MAXN];
bool mark[MAXN];

int tot,en[MAXM],nex[MAXM],las[MAXN];
void ADD(int x,int y)
{
	en[++tot]=y;
	nex[tot]=las[x];
	las[x]=tot;
}

int path[MAXN],Cnt[MAXN];
void DFS(int p,int f)
{
	int i,y;
	if(p==N)return;
	for(i=las[p];i;i=nex[i])
	{
		y=en[i];
		if(y==f)continue;
		path[y]=p;
		DFS(y,p);
	}
}

void DDD(int p,int f)
{
	int i,y;
	Cnt[p]=1;
	for(i=las[p];i;i=nex[i])
	{
		y=en[i];
		if(y==f||mark[y])continue;
		DDD(y,p);
		Cnt[p]+=Cnt[y];
	}
}

void dfs(int p,int f)
{
	int i,y;
	for(i=las[p];i;i=nex[i])
	{
		y=en[i];
		if(y==f||mark[y])continue;
		A++;
		dfs(y,p);
	}
}
int main()
{
	int i,x,y,cnt=0;
	
	scanf("%d",&N);
	for(i=1;i<N;i++)scanf("%d%d",&x,&y),ADD(x,y),ADD(y,x);
	
	DFS(1,-1);
	for(i=N;i!=1;i=path[i])mark[path[i]]=true;
	mark[1]=mark[N]=true;
	for(i=N;path[i]!=1;i=path[i])DDD(path[i],-1);
	for(i=N;path[i]!=1;i=path[i])cnt++,Ans[cnt]=Ans[cnt-1]+Cnt[path[i]];
	dfs(1,-1);
	B=A;A=0;
	dfs(N,-1);
	
	if(B+Ans[cnt]-Ans[cnt/2]>A+Ans[cnt/2])printf("Fennec");
	else printf("Snuke");
}

Measured memory_bytes: 8704
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<math.h>
#include<iostream>
#include<queue>
#include<algorithm>
#define ll long long
#define re register
using namespace std;
inline int gi()
{
	int f=1,sum=0;char ch=getchar();
	while(ch>'9' || ch<'0'){if(ch=='-')f=-1;ch=getchar();}
	while(ch>='0' && ch<='9'){sum=(sum<<3)+(sum<<1)+ch-'0';ch=getchar();}
	return f*sum;
}
int b[35],n,m;
int main()
{
	n=gi();m=gi();
	for(int i=1;i<=n;i++)
	{
		int k=gi();
		for(int j=1;j<=k;j++){
			int q=gi();
			b[q]++;
		}
	}
	int ans=0;
	for(int i=1;i<=m;i++)
		if(b[i]==n)ans++;
	printf("%d\n",ans);
	return 0;
}

Measured memory_bytes: 256
from collections import Counter
N,M = map(int,input().split())
A = list(map(int,input().split()))
src = [tuple(map(int,input().split())) for i in range(M)]
ctr = Counter(A)
cover = [0] * (2*N+1)
for k,v in ctr.items():
    for i in range(k,k-v,-1):
        cover[i+N] += 1
ans = cover[N+1:].count(0)

for x,y in src:
    ctr[A[x-1]] -= 1
    ai = A[x-1]+N - ctr[A[x-1]]
    cover[ai] -= 1
    if ai > N and cover[ai] == 0: ans += 1
    A[x-1] = y
    bi = y+N - ctr[y]
    if bi > N and cover[bi] == 0: ans -= 1
    cover[bi] += 1
    ctr[y] += 1
    print(ans)

Measured memory_bytes: 62168
{-# LANGUAGE
  ScopedTypeVariables, BangPatterns, TupleSections, ExplicitForAll,
  LambdaCase, MultiWayIf, Unsafe, RecordWildCards, FlexibleContexts, CPP,
  NoMonomorphismRestriction, GADTs,
  RankNTypes, EmptyDataDecls, EmptyCase, ViewPatterns #-}

import Data.Bits
import Data.List
import qualified Data.ByteString.Char8 as BS
import qualified Data.ByteString.Lazy.Char8 as BSL
import Data.IntMap.Strict (IntMap)
import qualified Data.IntMap.Strict as IMS
import qualified Data.IntMap.Lazy as IML
import Data.IntSet (IntSet)
import qualified Data.IntSet as IS
import qualified Data.Sequence as Seq
import Data.Sequence (Seq)
import qualified Data.Array.IArray as A
import qualified Data.Array.MArray.Safe as A
import qualified Data.Array.MArray as A
import Data.Array (Array)
import Data.Array.Unboxed (UArray)
import Data.Array.IArray (IArray)
import Data.Array.MArray.Safe (MArray)
import Data.Array.IO.Safe (IOArray, IOUArray)
import Data.Array.ST.Safe (STArray, STUArray, runSTArray, runSTUArray)
import qualified Data.Vector as V
import qualified Data.Vector.Unboxed as VU
import qualified Data.Vector.Unboxed.Mutable as VUM
import Control.Monad
import Control.Monad.ST
-- import Control.Monad.ST.Safe
import Control.Applicative
import Data.Maybe
import Data.Tuple
import Data.Ord
import Control.Monad.State.Strict
import Data.Int
import Data.Word
import System.IO
import Data.Function
import Control.Monad.Primitive
import qualified Data.Vector.Primitive.Mutable as VPM
import qualified Data.Vector.Generic.Mutable as VGM
import Data.STRef
import Data.IORef

main :: IO ()
main = do
  xs <- take 6 . unfoldr (runStateT rInt) <$> BSL.getContents
  putStrLn $ if (<=2) $ length $ filter odd $ map length $ group $ sort xs
             then "YES"
             else "NO"


rInt :: StateT BSL.ByteString Maybe Int
rInt = StateT $ BSL.readInt . BSL.dropWhile (<'!')

#define D(f,r,d) f::Integral a=>a->d;f=fromIntegral;r::String->d;r=read
#define C(f,r,g,h,d) D(f,r,d);g,h::RealFrac a=>a->d;g=floor;h=ceiling
C(_toInteger_,readInteger,floorInteger,ceilInteger,Integer)
C(toInt,readInt,floorInt,ceilInt,Int)
C(toI8,readI8,floorI8,ceilI8,Int8)
C(toI16,readI16,floorI16,ceilI16,Int16)
C(toI32,readI32,floorI32,ceilI32,Int32)
C(toI64,readI64,floorI64,ceilI64,Int64)
C(toWord,readWord,floorWord,ceilWord,Word)
C(toW8,readW8,floorW8,ceilW8,Word8)
C(toW16,readW16,floorW16,ceilW16,Word16)
C(toW32,readW32,floorW32,ceilW32,Word32)
C(toW64,readW64,floorW64,ceilW64,Word64)
D(toDouble,readDouble,Double)
D(toFloat,readFloat,Float)
#undef D
#undef C


#define N(f,g,a,m)\
  f :: forall e i s. (C(a,m)A.Ix i) => (i,i) -> e -> m (a i e); f=A.newArray;\
  g :: forall e i s. (C(a,m)A.Ix i) => (i,i) -> m (a i e); g=A.newArray_
#define C(a,m)
N(newIOA,newIOA_,IOArray,IO)
N(newSTA,newSTA_,STArray s,ST s)
#undef C
#define C(a,m) MArray (a) e (m), 
N(newIOUA,newIOUA_,IOUArray,IO)
N(newSTUA,newSTUA_,STUArray s,ST s)
#undef C
#undef N



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

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

    int F[N][10];
    for (int i = 0; i < N; i++){
        for (int j = 0; j < 10; j++){
            cin >> F[i][j];
        }
    }
    
    int P[N][11];
    for (int i = 0; i < N; i++){
        for (int j = 0; j < 11; j++){
            cin >> P[i][j];
        }
    }
    
    int Open[1023][10];
    for (int i = 1; i < 1024; i++){
        int num = i;
        for (int j = 0; j < 10; j++){
            Open[i-1][j] = num % 2;
            num = num / 2;
        }
    }
    
    int ans = -1000000000;
    for (int i = 0; i < 1023; i++){
        int sum = 0;

        for (int j = 0; j < N; j++){
            int cnt = 0;
            for (int k = 0; k < 10; k++){
                if (F[j][k] == 1 && Open[i][k] == 1){
                    cnt++;
                }
            }
            sum += P[j][cnt];
        }
        
        if (sum > ans){
            ans = sum;
        }
        
    }
    
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <sstream>
#include <stdio.h>
//#define _USE_MATH_DEFINES
#include <math.h>
#include <set>
#include <string>
#include <vector>
#include <map>
#include <algorithm>
#include <cmath>
#include <limits>
#include <bitset>
#include <stack>
#include <queue>
#include <ctype.h>

typedef long long int lli;
#define rep(i,s,N) for(int i=s;i<N;i++)
#define MOD 1000000007
#define more(a,b) (((a)>(b))?(a):(b))
#define less(a,b) (((a)<(b))?(a):(b))

using namespace std;


int main(void)
{
	lli Q, H, S, D; cin >> Q >> H >> S >> D;
	lli N; cin >> N;
	Q *= 4; H *= 2;
	lli one = min(min(Q, H), S);
	lli ans = 0;
	if (one * 2 >= D) ans = (N / 2) * D + (N % 2) * one;
	else ans = N * one;
	cout << ans << endl;

	return 0;
}


Measured memory_bytes: 256
#include<algorithm>
#include<cstring>
#include<cctype>
#include<cstdio>
#define rep(i,x,y) for(int i=x; i<=y; ++i)
 
using namespace std;
const int N=100005;
bool f[N][3],mp[8][8],vis[N];
int n,m,h[N],cnt,c[8],d[N];
typedef long long LL;
LL ans;
struct edge{int v,w,n;} e[N<<1];
 
int getint()
{
	char ch;
	while(!isdigit(ch=getchar()));
	int x=ch-48;
	while(isdigit(ch=getchar())) x=x*10+ch-48;
	return x;
}
 
void addedge(int u,int v)
{
	e[cnt]=(edge){v,1,h[u]},h[u]=cnt++;
	e[cnt]=(edge){u,-1,h[v]},h[v]=cnt++;
}
 
int get(int x)
{
	return f[x][0]|(f[x][1]<<1)|(f[x][2]<<2);
}
 
void dfs(int x,int tp)
{
	if(!vis[x]) cnt+=d[x],vis[x]=1;
	if(f[x][tp]) return;
	--c[get(x)],f[x][tp]=1,++c[get(x)];
	for(int i=h[x]; i!=-1; i=e[i].n)
		dfs(e[i].v,(tp+e[i].w+3)%3);
}
 
int main()
{
	n=getint(),m=getint();
	memset(h,-1,sizeof(h));
	rep(i,1,m)
	{
		int u=getint(),v=getint();
		addedge(u,v),++d[u],++d[v];
	}
	rep(i,1,7) rep(j,1,7) rep(k,0,2) if(i&(1<<k) && j&(1<<((k+1)%3))) mp[i][j]=1;
	rep(i,1,n) if(!vis[i])
	{
		memset(c,0,sizeof(c));
		cnt=0,dfs(i,0);
		if(!c[7] && (!c[1] || !c[2] || !c[4])) {ans+=cnt/2; continue;}
		rep(j,1,7) if(c[j])
			rep(k,1,7) if(c[k] && mp[j][k])
				ans+=(LL)c[j]*c[k];
	}
	printf("%lld\n",ans);
	return 0;
}

Measured memory_bytes: 13056
<?php

fscanf(STDIN, "%d %d", $n, $m);
$data = [];
for ($i = 0; $i < $m; ++$i) {
    fscanf(STDIN, "%d %d", $a, $b);
    --$a; --$b;
    $data[] = [$a, $b];
}

$bridge_cnt = 0;
// i: 取り除く辺
for ($i = 0; $i < $m; ++$i) {
    $G = array_fill(0, $n, []);
    for ($j = 0; $j < $m; ++$j) {
        if ($i == $j) continue;
        $G[$data[$j][0]][] = $data[$j][1];
        $G[$data[$j][1]][] = $data[$j][0];
    }

    for ($j = 0; $j < $n; ++$j) {
        $G[$j] = array_unique($G[$j]);
    }

    $G2 = array_fill(0, $n, false);
    $cnt = 0;
    for ($j = 0; $j < $n; ++$j) {
        if (!$G2[$j]) {
            dfs($G, $G2, $j);
            ++$cnt;
        }
    }

/* echo "Graph: " . print_r($G), PHP_EOL; */
/* echo "i: $i, cnt: $cnt, bridge_cnt: $bridge_cnt", PHP_EOL; */
    if ($cnt != 1) {
        ++$bridge_cnt;
    }
}

echo $bridge_cnt, PHP_EOL;

function dfs($G, &$G2, $x) {
    $G2[$x] = true;

    foreach ($G[$x] as $nx) {
        if ($G2[$nx]) continue;
        dfs($G, $G2, $nx);
    }
}


Measured memory_bytes: 16268
#include <bits/stdc++.h>
using namespace std;
int main(){
    string S,T;
    cin>>S>>T;
    deque<char>s;
    bool val=true;
    for(int a=0;a<S.length();a++) s.push_back(S[a]);
    for(int a=0;a<S.length();a++){
        val=true;
        for(int b=0;b<s.size();b++){
            if(s[b]!=T[b]) val=false;
            if(!val) break;
        }
        if(val) break;
        char top=s.front();
        s.pop_front();
        s.push_back(top);
    }
    if(val) printf("Yes\n");
    else printf("No\n");
}


Measured memory_bytes: 256
n,k = gets.split.map(&:to_i)
h = gets.split.map(&:to_i)
k = [k,n-1].min
dp = Array.new(n){Float::INFINITY}
dp[0] = 0
(1..k).each do |i|
  dp[i] = (h[i] - h[0]).abs
end
(k+1...n).each do |i|
  (1..k).each {|j| dp[i] = [dp[i-j] + (h[i] - h[i-j]).abs,dp[i]].min}
end
p dp[n-1]


Measured memory_bytes: 22076
#include <bits/stdc++.h>
using namespace std;
using  unll = unsigned long long;

int main() {
  string s;
  cin >> s;
  int ini,en;
  for(int i=0;i<s.size();i++){
    if( s.at(i) == 'A' ){
      ini = i;
      break;
    }
  }
  for(int i=s.size()-1;i>=0;i--){
    if( s.at(i) == 'Z' ){
      en = i;
      break;
    }
  }
  
  cout << en - ini + 1 << endl;
  return 0;
}

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

using ll = long long;
#define ALL(c) (c).begin(), (c).end()
const int MOD = 1000000007;

int main() {
    int n;
    cin >> n;
    vector<ll> a(n);
    for (int i = 0; i < n; i++) {
        cin >> a[i];
    }
    ll b;
    ll m = 0;
    ll x = 0;
    vector<ll> e;
    int d = 0;
    for (int i = 0; i < n; i++) {
        cin >> b;
        x += a[i] - b;
        if (a[i] > b) {
            e.push_back(a[i] - b);
        } else if (a[i] < b) {
            m += b - a[i];
            d++;
        }
    }

    if (x < 0) {
        cout << -1 << endl;
        return 0;
    }

    sort(ALL(e), greater<ll>());

    int c = 0;
    while (m > 0) {
        m -= e[c++];
    }

    cout << d + c << endl;
}


Measured memory_bytes: 1660
#!/usr/bin/env python
import sys
from operator import itemgetter

def _ia(): return [ int(x) for x in sys.stdin.readline().strip().split() ]

n,t = _ia()
ab = []
for i in range(n): ab.append(_ia())
ab.sort(key=itemgetter(0))
#
bmax= ab[0][0]
dp = [ [0]*(t) for _ in range(n) ]
for i in range(n-1):
    a,b = ab[i]
    
    prev = dp[i]
    dnew = dp[i+1]
    for atot in range(t):
        if atot>=a: dnew[atot] = max(prev[atot],prev[atot-a]+b)
        else: dnew[atot] = prev[atot]
    #
    bmax = max(bmax,prev[-1]+b)
#
print(max(bmax,dp[-1][-1]+ab[-1][1]))


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

using namespace std;

typedef long long ll;

const ll MOD = 1000000007;
const ll INF = 1LL<<60;
//int INF = numeric_limits<int>::max();

int main(int, char**) {
	int n, r; cin >> n >> r;
	if (n < 10) r += 100 * (10 - n);
	cout << r << endl;
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main(){
    int a[7],b[7];
    for (int i=1;i<=6;i++){
        cin>>a[i];
    }
    for (int i=1;i<=6;i++){
        cin>>b[i];
    }
    if (a[1]==b[1]&&a[2]==b[2]&&a[3]==b[3]&&a[4]==b[4]&&a[5]==b[5]&&a[6]==b[6]) cout<<"Yes"<<endl;
    else if (a[1]==b[1]&&a[2]==b[3]&&a[3]==b[5]&&a[4]==b[2]&&a[5]==b[4]&&a[6]==b[6]) cout<<"Yes"<<endl;
    else if (a[1]==b[1]&&a[2]==b[5]&&a[3]==b[4]&&a[4]==b[3]&&a[5]==b[2]&&a[6]==b[6]) cout<<"Yes"<<endl;
    else if (a[1]==b[1]&&a[2]==b[4]&&a[3]==b[2]&&a[4]==b[5]&&a[5]==b[3]&&a[6]==b[6]) cout<<"Yes"<<endl;
    
    else if (a[1]==b[2]&&a[2]==b[6]&&a[3]==b[3]&&a[4]==b[4]&&a[5]==b[1]&&a[6]==b[5]) cout<<"Yes"<<endl;
    else if (a[1]==b[2]&&a[2]==b[3]&&a[3]==b[1]&&a[4]==b[6]&&a[5]==b[4]&&a[6]==b[5]) cout<<"Yes"<<endl;
    else if (a[1]==b[2]&&a[2]==b[4]&&a[3]==b[6]&&a[4]==b[1]&&a[5]==b[3]&&a[6]==b[5]) cout<<"Yes"<<endl;
    else if (a[1]==b[2]&&a[2]==b[1]&&a[3]==b[4]&&a[4]==b[3]&&a[5]==b[6]&&a[6]==b[5]) cout<<"Yes"<<endl;
    
    else if (a[1]==b[3]&&a[2]==b[1]&&a[3]==b[2]&&a[4]==b[5]&&a[5]==b[6]&&a[6]==b[4]) cout<<"Yes"<<endl;
    else if (a[1]==b[3]&&a[2]==b[2]&&a[3]==b[6]&&a[4]==b[1]&&a[5]==b[5]&&a[6]==b[4]) cout<<"Yes"<<endl;
    else if (a[1]==b[3]&&a[2]==b[5]&&a[3]==b[1]&&a[4]==b[6]&&a[5]==b[2]&&a[6]==b[4]) cout<<"Yes"<<endl;
    else if (a[1]==b[3]&&a[2]==b[6]&&a[3]==b[5]&&a[4]==b[2]&&a[5]==b[1]&&a[6]==b[4]) cout<<"Yes"<<endl;
    
    else if (a[1]==b[4]&&a[2]==b[1]&&a[3]==b[5]&&a[4]==b[2]&&a[5]==b[6]&&a[6]==b[3]) cout<<"Yes"<<endl;
    else if (a[1]==b[4]&&a[2]==b[2]&&a[3]==b[1]&&a[4]==b[6]&&a[5]==b[5]&&a[6]==b[3]) cout<<"Yes"<<endl;
    else if (a[1]==b[4]&&a[2]==b[5]&&a[3]==b[6]&&a[4]==b[1]&&a[5]==b[2]&&a[6]==b[3]) cout<<"Yes"<<endl;
    else if (a[1]==b[4]&&a[2]==b[6]&&a[3]==b[2]&&a[4]==b[5]&&a[5]==b[1]&&a[6]==b[3]) cout<<"Yes"<<endl;
    
    else if (a[1]==b[5]&&a[2]==b[1]&&a[3]==b[3]&&a[4]==b[4]&&a[5]==b[6]&&a[6]==b[2]) cout<<"Yes"<<endl;
    else if (a[1]==b[5]&&a[2]==b[3]&&a[3]==b[6]&&a[4]==b[1]&&a[5]==b[4]&&a[6]==b[2]) cout<<"Yes"<<endl;
    else if (a[1]==b[5]&&a[2]==b[4]&&a[3]==b[1]&&a[4]==b[6]&&a[5]==b[3]&&a[6]==b[2]) cout<<"Yes"<<endl;
    else if (a[1]==b[5]&&a[2]==b[6]&&a[3]==b[4]&&a[4]==b[3]&&a[5]==b[1]&&a[6]==b[2]) cout<<"Yes"<<endl;
    
    else if (a[1]==b[6]&&a[2]==b[2]&&a[3]==b[4]&&a[4]==b[3]&&a[5]==b[5]&&a[6]==b[1]) cout<<"Yes"<<endl;
    else if (a[1]==b[6]&&a[2]==b[3]&&a[3]==b[2]&&a[4]==b[5]&&a[5]==b[4]&&a[6]==b[1]) cout<<"Yes"<<endl;
    else if (a[1]==b[6]&&a[2]==b[4]&&a[3]==b[5]&&a[4]==b[2]&&a[5]==b[3]&&a[6]==b[1]) cout<<"Yes"<<endl;
    else if (a[1]==b[6]&&a[2]==b[5]&&a[3]==b[3]&&a[4]==b[4]&&a[5]==b[2]&&a[6]==b[1]) cout<<"Yes"<<endl;
    
    else cout<<"No"<<endl;
    return 0;
}


Measured memory_bytes: 3120
N = int(input())
A = input()
B = input()
C = input()

ans = 0
for a,b,c in zip(A,B,C) :
    #print(a,b,c)
    
    if (a == b == c) :
        ans += 0
    elif (a != b) and (b != c) and (c != a) :
        ans += 2
    else :
        ans += 1
print(ans)


Measured memory_bytes: 3060
n, m = map(int, input().split())
x = sorted(list(map(int, input().split())))

if n >= m:
    print(0)
else:
    ans = x[m-1]-x[0]
    x = sorted([x[i] - x[i - 1] for i in range(1, m)])
    print(ans - sum(x[m-n:]))


Measured memory_bytes: 13964
#include <iostream>
#include <string.h>
#include <stdio.h>
#include <math.h>
#include <list>
#include <set>
#include <queue>
#include <iterator>
#include <bitset>
#include <bits/stdc++.h>
#include <vector>
#include <cctype>
#include <algorithm>
#define ll             long long
#define _              ios_base::sync_with_stdio(0);cin.tie(0);
#define loop           for(i=0;i<n;i++)
#define pb             push_back
#define tc()           int t;cin>>t;while(t--) 
#define pi             acos(-1)         
 
using namespace std;
 
ll i,j,temp;

 
int main(){_

	double x;
	cin>>x;
	cout<<2*pi*x<<endl;

	return 0;

}

Measured memory_bytes: 3784
#include <iostream>
#include <math.h>
#include <vector>
#include <stack>
#include <cstdio>
#include <string>
#include <bitset>
#include <list>
#include <set>
#include <algorithm>
#include <numeric>
#include <tuple>
#include <unordered_map>
#include <array>
using namespace std;
//debug
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;
int test(int N, vector<int> a) {
	int sum = 0;
	unordered_map<int, int> count;
	for (int j = 0; j < N; j++) count[a.at(j)] = 0;
	for (int j = 0; j < N; j++) count[a.at(j)]++;
	for (auto it = count.begin(); it != count.end(); it++) sum+= (*it).second >= (*it).first ? (*it).second - (*it).first : (*it).second;
	return sum;
}
int main() {
	int N;
	cin >> N;
	vector<int> a(N);
	for (int i = 0; i < N; cin >> a[i++]);
	cout << test(N, a);
	return 0;

}


Measured memory_bytes: 5028
#include <iostream>
using namespace std;
 
int n, a[10009], sum;
 
int main() {
	cin >> n;
	for (int i = 1; i <= n; i++) {
		cin >> a[i];
		while (a[i] % 2 == 0) { a[i] /= 2; sum++; }
	}
	cout << sum << endl;
	return 0;
}

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

int main() {
long long ans = 0;
long long N,D,A;
cin >> N >> D >> A;
vector<vector<long long>> enemies(N, vector<long long> (2));
for (int i = 0; i < N; i++)
{
    cin >> enemies.at(i).at(0) >> enemies.at(i).at(1);
}
sort(enemies.begin(),enemies.end(),[](const vector<long long> &alpha,const vector<long long> &beta){return alpha[0] < beta[0];});

queue<vector<long long>> damage;
long long dmg = 0;
for (int i = 0; i < N; i++){
    long long x = enemies.at(i).at(0);
    long long h = enemies.at(i).at(1);
    if (damage.empty()){
        long long bomb = (h+A-1)/A;
        ans += bomb;
        dmg += bomb*A;
        damage.push({x+2*D,bomb});
    }
    else{
        while (!damage.empty()){
            vector<long long> vec;
            vec = damage.front();
            long long d = vec.at(0);
            long long bomb = vec.at(1);
            if (d < x){
                dmg -= bomb*A;
                damage.pop();
            }
            else{
                break;
            }
        }
        if (h > dmg){
            long long bomb = (h-dmg+A-1)/A;
            dmg += bomb*A;
            damage.push({x+2*D,bomb});
            ans += bomb;
        }
    }
}

cout << ans << endl;
}

Measured memory_bytes: 16768
// This  Program is made by Jan(Codezebra)
#include<bits/stdc++.h>
#define int long long
#define INF 0x3f3f3f3f
using namespace std;
int sod(int n){
	int ans=0;
	while(n!=0){
		ans+=n%10;
		n/=10;
	}
	return ans;
}
signed main(){
	ios::sync_with_stdio(false);
	cin.tie(0);
	int n;
	cin>>n;
	int m=INF;
	for(int a=1;a<=n/2;a++){
		m=min(m, sod(a)+sod(n-a));
	}
	cout<<m;
	return 0;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <iostream>
#include <string>
#include <cstdlib> 
#include <string.h>
#include <vector>
#include <cstdio>
#include <iomanip>
#include <stack>
#include <set>
#include <map>
#include <list>
#include <ctime>
#include <algorithm>
#include <cmath>
#define PI 3.1415926535897932384626433832795l
#define IOS ios :: sync_with_stdio(false); cin.tie(0); cout.tie(0)
#define deci(n) cout<<fixed<<setprecision(n);
#define F first
#define S second
#define mk make_pair
#define pb push_back
#define ALPHA 27
#define ll long long int
#define ld long double
#define mmset(arr, n) memset(arr, n, sizeof arr)
#define debug(x) cerr << '#' << ' ' << x << '\n'
#define len(s) s.length()
#define ForA(i,a,b) for(int i = a; i < b; i++)
#define ForA1(i,a,b) for(int i = b - 1; i >= a; i--)
#define ForB1(i,a,b) for(int i = b; i > a; i--)
#define ForB(i,a,b) for(int i = a; i <= b; i++)
#define INT_SIZE 18 
#define maxn 410
#define Maxn 100010

using namespace std;

const ll INF = (ll)(8e18);
const ll MOD = 1000000007;

ll a[maxn], dp[maxn][maxn], prefix[maxn];

int main()
{
    IOS;        
    ll n; cin >> n; 
    ForB(i,1,n) cin >> a[i];
    ForB(i,1,n - 1){
        dp[i][i + 1] = a[i] + a[i + 1];
    }
    ForB(i,1,n){
        prefix[i] += prefix[i - 1] + a[i];
    }
    ForB(i,3,n){
        ForB(j,1,n - i + 1){
            int l = i + j - 1;
            dp[j][l] = dp[j][l - 1] + dp[l][l] + prefix[l] - prefix[j - 1];
            ForB(k,j,l - 1){
               dp[j][l] = min(dp[j][l], dp[j][k - 1] + dp[k][l] + 
                              prefix[l] - prefix[j - 1]);
            }
        }
    }
    cout << dp[1][n] << '\n';
    #ifdef LOCAL_DEFINE
    cerr << "Time elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << " s.\n";
    #endif
    return 0 ;
}


Measured memory_bytes: 1536
#include <bits/stdc++.h>
#define rep3(i, s, n, a) for (int i = (s); i < (int)(n); i += a)
#define rep2(i, s, n) rep3(i, s, n, 1)
#define rep(i, n) rep2(i, 0, n)

using namespace std;
using ll = long long;
using ull = unsigned long long;
using P = pair<int, int>;

int main(){
    int n, k;
    cin >> n >> k;
    rep(i, n){
        int x;
        cin >> x;
    }
    cout << (n - 2) / (k - 1) + 1 << endl;
    return 0;
}

Measured memory_bytes: 3580
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		
		int a = 0;
		String operator = "";
		int b = 0;


		// テキスト入力
		Scanner sc = new Scanner(System.in);
		String out = "";

		// 演算子の変数に入っている中身で場合わけ
		while (true) {

			//
			while(sc.hasNext()){
				a = sc.nextInt();
				operator = sc.next();
				b = sc.nextInt();
				break;
			}

			if (operator.equals("?")) {
				break;

			} else if (operator.equals("/")) {
				out = out + a / b + "\n";

			} else if (operator.equals("*")) {
				out = out + a * b + "\n";
				
			}else if (operator.equals("+")) {
				out = out + (a + b) + "\n";

			} else if (operator.equals("-")) {
				out = out + (a - b) + "\n";
			}
		}
		// 出力
		System.out.print(out);
	}
}

Measured memory_bytes: 18212
#include<bits/stdc++.h>
#define rep(i,N) for(int i=0;i<(N);i++)
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
using namespace std;
const long long MOD = 1e9 + 7;
const long long INF = 1e12;
const int inf = 1e9;
typedef long long ll;
typedef pair<ll,int> P;
typedef set<int> S;
ll n;
bool is_prime(ll nn){
    for(ll i=2; i*i <= n ;i++){
        if(nn%i==0) return 0;
    }
    return 1;
}

int main(){
    int n;
    cin>>n;
    int a;
    for(int i=0;i<=n;i++){
        //cout<<(int)(i*1.08)<<endl;
        if(((int)(i*1.08))==n){
            cout<<i<<endl;
            return 0;
        }
    }
    cout<<":("<<endl;

    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cstring>
using namespace std;
int main(void){
    // Your code here!
    char ch;
    int cnt[26]={};
    
    
    while(cin>>ch){
        ch=tolower(ch);
        if(isalpha(ch)){
            cnt[ch-'a']++;
        }
    }
    for(int i=0; i<26; i++){
        printf("%c : %d\n",i+'a',cnt[i]);
    }

    
    return 0;
}



Measured memory_bytes: 3192
# 入力をリスト形式でhaikuに代入する
haiku= input()

# 入力値の中から、5の出現回数と7の出現回数を数える
# 5が2回、7が1回だけであれば、俳句は成立するのでをOK返す
if haiku.count("5")==2 and haiku.count("7")==1:
    print("YES")
else:
    # 条件を満たさなければ、NGを返す
    print("NO")
    
    


Measured memory_bytes: 2940
#include <bits/stdc++.h>
using namespace std;
int main() {
    #ifdef DEBUG
    std::ifstream in("/home/share/inputf.in");
    std::cin.rdbuf(in.rdbuf());
    #endif
    int A, B;
    cin >> A >> B;
    if(A == B) {
        cout << 2 * A << endl;
    } else {
        cout << 2 * max(A, B) - 1 << endl;
    }
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ull = unsigned long long;
#define REP(i,n) for (ll i = 0; i < (n); ++i)
#define RREP(i, n) for (ll i = (n) - 1; i >= 0; --i)
#define ALL(v) (v).begin(), (v).end()


int main(){
    ll n, m, x;
    cin >> n >> m >> x;
    vector<ll> c(n);
    vector<vector<ll>> a(n, vector<ll>(m, 0));
    REP(i, n){
        cin >> c.at(i);
        REP(j, m){
            cin >> a.at(i).at(j);
        }
    }

    ll ans = -1;
    REP(s, 1LL << n){
        ll price = 0;
        vector<ll> total(m, 0);
        REP(i, n){
            if((s >> i) & 1){
                price += c.at(i);

                REP(j, m){
                    total.at(j) += a.at(i).at(j);
                }
            }
        }

        bool is_ok = true;
        REP(i, m){
            if(total.at(i) < x){
                is_ok = false;
                break;
            }
        }
        if(is_ok){
            if(ans == -1 || ans > price){
                ans = price;
            }
        }
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 3636
while True:
    n = int(input())
    if n == 0:break
    plst = list(map(int, input().split()))
    dlst = list(map(int, input().split()))
    edges = [[] for _ in range(n)]
    for i in range(1, n):
        edges[i].append((plst[i - 1] - 1, dlst[i - 1]))
        edges[plst[i - 1] - 1].append((i, dlst[i - 1]))

    is_leaf = [len(edges[i]) == 1 for i in range(n)]
    INF = 10 ** 20


    def dist(x):
        dist_from_x = [-INF] * n
        dist_from_x[x] = 0
        checked = [False] * n
        checked[x] = True

        def search(x):
            for to, d in edges[x]:
                if is_leaf[to] or checked[to]:continue
                checked[to] = True
                dist_from_x[to] = dist_from_x[x] + d
                search(to)
        search(x)
        return dist_from_x

    for i in range(n):
        if not is_leaf[i]:
            dist_from_s = dist(i)
            break
    u = dist_from_s.index(max(dist_from_s))
    dist_from_u = dist(u)
    dia = max(dist_from_u)
    v = dist_from_u.index(dia)
    ans = sum(dlst) * 3
    for i in range(n):
        if len(edges[i]) == 1:
            ans -= edges[i][0][1] * 2
    print(ans - dia)


Measured memory_bytes: 7320
import java.util.Scanner;

public class Main {

  public static void main(String[] args) {
    Scanner scanner = new Scanner(System.in);
    int N = scanner.nextInt();
    int nfound = 0;

    for (int i = 1; i <= N; i += 2) {
      int n = 0;
      for (int j = 1; j <= i; j += 2) {
        if (i % j == 0) {
          n++;
        }
      }
      if (n == 8) {
        nfound++;
      }
    }
    System.out.println(nfound);
  }
}


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

int main() {
 int r;
  cin >> r;
  if(r<1200) cout << "ABC" << endl;
  if(r>=1200 && r<2800) cout << "ARC" << endl;
  if(r>=2800) cout << "AGC" << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll long long
#define fi first
#define se second
#define pll pair<ll, ll>
#define pii pair<ll, pll>
#define pb push_back
#define task "snowboots"
using namespace std;

const ll N = 1e5 + 5;
const ll mod = 1e9 + 7;
const ll base = 311;
ll n, m, t, k, ans, tong, a[N], T, b[N], c[N], lab[N];
vector<ll> kq;
string s;
void nhap(ll u, ll v)
{
    if(lab[u] > lab[v])swap(u, v);
    lab[u] += lab[v];
    lab[v] = u;
}

ll findp(ll u)
{
    return lab[u] < 0 ? u : lab[u] = findp(lab[u]);
}
ll A, B, C, D;
unordered_map<ll, ll> mp;
ll dp(ll n)
{
    if(n == 0)return 0;
    if(n == 1)return D;
    if(mp.count(n))return mp[n];
    ll tong = 1e18;
    if(n < tong / D)tong = D * n;
    ll l2 = (n / 2) * 2, r2 = ((n + 1) / 2) * 2, l3 = (n / 3) * 3, r3 = ((n + 2) / 3) * 3,
    l5 = (n / 5) * 5, r5 = ((n + 4) / 5) * 5;

    tong = min(tong, min((n - l2) * D + A + dp(l2/2), min((r2 - n) * D + A + dp(r2/2), min((n-l3)*D + B + dp(l3/3), (r3-n)*D + B + dp(r3/3)))));
    tong = min(tong, min((n - l5) * D + C + dp(l5/5), (r5 - n) * D + C + dp(r5/5)));
    return mp[n] = tong;
}
void sol()
{
    cin >> T;
    while(T -- > 0)
    {
        mp.clear();
        cin >> n >> A >> B >> C >> D;
        cout << dp(n)<<'\n';
    }
}
int main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    if(fopen(task".INP", "r"))
    {
        freopen(task".INP", "r", stdin);
        freopen(task".OUT", "w", stdout);
    }
    sol();
}


Measured memory_bytes: 4068
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
    ($($r:tt)*) => {
        let s = {
            use std::io::Read;
            let mut s = String::new();
            std::io::stdin().read_to_string(&mut s).unwrap();
            s
        };
        let mut iter = s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
}

macro_rules! input_inner {
    ($iter:expr) => {};
    ($iter:expr, ) => {};

    ($iter:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($iter, $t);
        input_inner!{$iter $($r)*}
    };
}

macro_rules! read_value {
    ($iter:expr, ( $($t:tt),* )) => {
        ( $(read_value!($iter, $t)),* )
    };

    ($iter:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($iter, $t)).collect::<Vec<_>>()
    };

    ($iter:expr, chars) => {
        read_value!($iter, String).chars().collect::<Vec<char>>()
    };

    ($iter:expr, usize1) => {
        read_value!($iter, usize) - 1
    };

    ($iter:expr, $t:ty) => {
        $iter.next().unwrap().parse::<$t>().expect("Parse error")
    };
}

fn solve(s: Vec<char>) -> i32 {
    let mut c = 0;
    for i in s {
        if i == '1' {
            c += 1
        }
    }
    c
}

fn main() {
    input!{
        s: chars,
    }
    println!("{}", solve(s))
}


Measured memory_bytes: 4352
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int n,cnt=0;
    cin>>n;
    for(int i=1;i<=n;i++)
    {
        int val;
        cin>>val;
        if((val%2==1)&&(i%2==1))
            cnt++;
    }
    cout<<cnt<<endl;
    return 0;
}


Measured memory_bytes: 3548
s = list(input())
p = list(input())
for x in range(len(p)) :
    s.append(s[x])

i = 0
j = 0
while True :
    if p[j] == s[i] :
        j += 1
        if j == len(p) :
            print("Yes")
            break
        i += 1
        if i == len(s) :
            print("No")
            break
    else :
        i += (1 - j)
        if i == len(s) :
            print("No")
            break
        j = 0


Measured memory_bytes: 5560
#include <iostream>
#include <string>
using namespace std;
  
int main () {
    int a;
    string p,s;
    cin >> p >> s;
    p += p;
 
    a=p.find(s);
    if(a==-1)cout <<"No"<<endl;
    else cout << "Yes"<<endl;
}

Measured memory_bytes: 3208
using System;
using System.Linq;
using System.Collections.Generic;

public class Test
{
	public static void Main()
	{
        string[] line = Console.ReadLine().Split(' ');
        int H = int.Parse(line[0]);
        int W = int.Parse(line[1]);
    
        string[,] map = new string[H+2,W+2];
        int cnt = 0;

        for(int hi = 0 ; hi < H ; hi++){
            char[] c = Console.ReadLine().ToCharArray();
            for(int wi = 0 ; wi < W ; wi++){
                map[hi+1, wi+1] = c[wi].ToString();
            }
        }

        for(int hi = 1 ; hi < H+1 ; hi++){
            for(int wi = 1 ; wi < W+1 ; wi++){
                cnt = check(map, hi, wi);
                if(map[hi,wi] != "#"){
                    map[hi,wi] = cnt.ToString();
                }
            }
        }

        for(int hi =1 ; hi < H+1 ; hi++){
            for(int wi = 1 ; wi < W+1 ; wi++){
                Console.Write(map[hi,wi]);
            }
            Console.WriteLine("");
        }
	}                   

    public static int check(string[,] map , int cH , int cW){
        int cnt = 0;
        for(int hi = cH-1 ; hi <= cH+1 ; hi++){
            for(int wi = cW -1 ; wi <= cW+1 ; wi++){
                if(map[hi,wi] == "#"){
                     cnt++;
                }
            }
        }
        return cnt;
    }                                                                                                                                                    
}

Measured memory_bytes: 11092
m[22][22],C;
R(x,y){
	if(m[x][y]){
		m[x][y]=0;
		C++;
		R(x-1,y);
		R(x+1,y);
		R(x,y-1);
		R(x,y+1);
	}
}
main(){
	int W,H,x,y,c,px,py;
	for(;scanf("%d%d",&W,&H),W;){
		memset(m,0,sizeof(m));
		for(y=1;y<=H;y++){
			for(x=0;x<=W;x++){
				c=getchar();
				if(c=='@')
					m[x][y]=1,px=x,py=y;
				else if(c=='.')
					m[x][y]=1;
				else if(c=='#')
					m[x][y]=0;
			}
		}
		C=0;
		R(px,py);
		printf("%d\n",C);
	}
	exit(0);
}

Measured memory_bytes: 0
#include <bits/stdc++.h>
#define PI 3.14159265359
#define NIL -1
using namespace std;
const int64_t MOD = 1e9 + 7;

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

	vector<vector<int>> v(N, vector<int>());
	for (int i = 0; i < M; i++) {
		int a, b;
		cin >> a >> b;
		v.at(a - 1).push_back(b - 1);
		v.at(b - 1).push_back(a - 1);
	}

	//for (int i = 0; i < N; i++) {
	//	if (v.at(i).size() == 0) continue;
	//	else {
	//		for (int j = 0; j < v.at(i).size(); j++) {
	//			cout << v.at(i).at(j) << ' ';
	//		}
	//	}
	//	cout << endl;
	//}

	for (int i = 0; i < v.at(0).size(); i++) {
		int n = v.at(0).at(i);
		if (v.at(n).size() == 0) continue;

		for (int j = 0; j < v.at(n).size(); j++) {
			if (v.at(n).at(j) == N - 1) {
				cout << "POSSIBLE" << endl;
				return 0;
			}
		}
	}
	cout << "IMPOSSIBLE" << endl;
}

Measured memory_bytes: 15024
#include<bits/stdc++.h>
using namespace std;
const int N=2e5+5;
struct Edge{int next,to;}edge[N*2];
int fi[N],se,a[N],ans[N],b[N],s;
inline void add_edge(int u,int v){edge[++se]={fi[u],v},fi[u]=se;}
inline void add(int u,int v){add_edge(u,v),add_edge(v,u);}
void dfs(int x,int fa){
	int w=lower_bound(b,b+s,a[x])-b,w1=b[w];
	b[w]=a[x];ans[x]=s=max(s,w+1);
	for(int i=fi[x];i;i=edge[i].next){
		int v=edge[i].to;if(v==fa)continue;
		dfs(v,x);s=ans[x];
	}
	b[w]=w1;
}
int main(){
	int n,u,v;scanf("%d",&n);
	for(int i=1;i<=n;i++)scanf("%d",a+i);
	for(int i=1;i<n;i++)scanf("%d%d",&u,&v),add(u,v);
	dfs(1,0);
	for(int i=1;i<=n;i++)printf("%d\n",ans[i]);
	return 0;
}

Measured memory_bytes: 23420
#include <stdio.h>
#include <stdlib.h>
#include <vector>
#include <map>
#include <string>
#include <iostream>
#include <limits.h>
#include <algorithm>

#define ll long long
#define in(params) cin >> (params);
#define p(params) cout << (params) << endl;
#define mod 1000000007LL

using namespace std;

int main()
{
    int N, M, C;
    cin >> N >> M >> C;

    int B[M];
    int A[M];

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

    int result = 0;

    for (int i = 0; i < N; i++) {
        int count = 0;
        for (int j = 0; j < M; j++)
        {
            cin >> A[j];
            count += A[j] * B[j];
        }
        count += C;

        if (0 < count) {
            result++;
        }
    }

    cout << result << endl;

    return 0;
}

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

const long long MOD=1000000007;

int main(){
  int n; cin >> n;
  int p[20];
  for(int i=0; i<n; i++) cin >> p[i];
  int count =0;
  for(int i=0; i<n-2; i++){
    if((p[i]>p[i+1]&&p[i+1]>p[i+2])||(p[i]<p[i+1]&&p[i+1]<p[i+2])){
      count++;
    }
  }
  cout << count << endl;
}

Measured memory_bytes: 256
H,W = map(int, input().split())
s = []
for i in range(H):
    s.append(list(input()))
can_paint_all = True
for i in range(H):
    for j in range(W):
        if s[i][j] == '.':
            continue
        if 0 <= i - 1 and s[i-1][j] == '#':
            continue
        if i + 1 < H and s[i+1][j] == '#':
            continue
        if 0 <= j - 1 and s[i][j-1] == '#':
            continue
        if j + 1 < W and s[i][j+1] == '#':
            continue
        can_paint_all = False
        break
    if not can_paint_all:
        break

if can_paint_all:
    print("Yes")
else:
    print("No")

Measured memory_bytes: 9220
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;

int main(){
    int n;
    cin >> n;
    vector<ll> a(n+2,0);
    for(int i = 1; i < n+1; i++){
        cin >> a[i];
    }
    vector<ll> diff(n+1);
    vector<ll> jump(n);
    ll sum = 0;
    for(int i = 0; i < n; i++){
        diff[i] = abs(a[i+1] - a[i]);
        jump[i] = abs(a[i+2]-a[i]);
    }
    diff[n] = abs(a[n+1]-a[n]);
    for(int i = 0; i < n+1; i++){
        sum += diff[i];
    }
    for(int i = 0; i < n; i++){
        cout << sum - (diff[i] + diff[i+1]) + jump[i] << endl;
    }

    return 0;

}


Measured memory_bytes: 3584
#!/usr/bin/env python3
import math

def main():
    N = int(input())
    A = list(map(int, input().split()))
    A = [A[i] - i - 1 for i in range(N)]
    A.sort()
    diff = A[(N-1)//2]
    print(sum([abs(a-diff) for a in A]))


if __name__ == "__main__":
    main()


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

int main() {
  int n, m;
  cin >> n >> m;
  vector<vector<int>> s(m);
  for (int i = 0; i < m; i++) {
    int k;
    cin >> k;
    vector<int> t(k);
    for (int j = 0; j < k; j++) {
      cin >> t.at(j);
      t.at(j)--;
    }
    s.at(i) = t;
  }
  vector<int> p(m);
  for (int i = 0; i < m; i++) {
    cin >> p.at(i);
  }
  int ans = 0;
  for (int bit = 0; bit < (1 << n); bit++) {
    bool on = true;
    for (int i = 0; i < m; i++) {
      int cnt = 0;
      for (int j = 0; j < s.at(i).size(); j++) {
        if (bit & (1 << s.at(i).at(j))) {
          cnt++;
        }
      }
      if (cnt % 2 != p.at(i)) {
        on = false;
      }
    }
    if (on) {
      ans++;
    }
  }
  cout << ans << endl;
  return 0;
}

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

using p_int = pair<int, int>;

const int MAX_N = (int) 1e5;

vector<p_int> edges[MAX_N];

int ans[MAX_N];

void dfs(int idx, int par) {
    for (auto e: edges[idx]) {
        if (e.first != par) {
            ans[e.first] = (ans[idx] + e.second) % 2;
            dfs(e.first, idx);
        }
    }
}


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

    int N;
    cin >> N;

    for (int i = 0; i < N - 1; ++i) {
        int u, v, w;
        cin >> u >> v >> w;
        edges[u - 1].emplace_back(v - 1, w % 2);
        edges[v - 1].emplace_back(u - 1, w % 2);
    }
    dfs(0, -1);

    for (int i = 0; i < N; ++i) {
        cout << ans[i] << '\n';
    }
    return 0;
}


Measured memory_bytes: 8448
#include <iostream>
#include <string>
#include <algorithm>
#include <queue>
#include <map>
#include <set>
#include <vector>
#include <cmath>
#include <cctype>
#define rep(i,a,b) for(int i=(a);i<b;i++)
#define INF 1000000000
using namespace std;
bool debug=false;

int main(){
  int n,r;
  while(1){
    cin>>n>>r;
    if(n==0&&r==0)break;
    int d[51];
    //?????????
    for(int i=0;i<n;i++){
      d[i]=n-i;
    }

    if(debug)for(int i=0;i<n;i++)cout<<d[i]<<" ";
    if(debug)cout<<endl;
      
    for(int i=0;i<r;i++){
      int p,c,tmp[51];
      cin>>p>>c;
      
      for(int j=0;j<c;j++)tmp[j]=d[j+p-1];

      for(int j=p-2;j>=0;j--)d[j+c]=d[j];

      for(int j=0;j<c;j++)d[j]=tmp[j];

      
      if(debug)for(int i=0;i<n;i++)cout<<d[i]<<" ";
      if(debug)cout<<endl;
    }
    cout<<d[0]<<endl;
  }
  return 0;
}

Measured memory_bytes: 3084
fn main() {
    let n = read::<usize>();
    let mut a = read_vec::<u64>();
    let mut b = read_vec::<u64>();
    let mut c = read_vec::<u64>();
    a.sort();
    b.sort();
    c.sort();

    let mut ret = 0;
    for j in 0..n {
        let mut i = upper_bound(&a, b[j]-1);
        let mut k = lower_bound(&c, b[j]+1);
        ret += i * (n - k);
    }

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

fn lower_bound(v: &Vec<u64>, k: u64) -> usize {
    let mut low = 0;
    let mut high = v.len();

    while low < high {
        let mid = (low + high) / 2;
        if v[mid] < k {
            low = mid + 1;
        } else {
            high = mid;
        }
    }

    low
}

fn upper_bound(v: &Vec<u64>, k: u64) -> usize {
    let mut low = 0;
    let mut high = v.len();

    while low < high {
        let mid = (low + high) / 2;
        if v[mid] <= k {
            low = mid + 1;
        } else {
            high = mid;
        }
    }

    low
}

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

fn read_vec<T: std::str::FromStr>() -> Vec<T> {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim().split_whitespace().map(|e| e.parse().ok().unwrap()).collect()
}


Measured memory_bytes: 13560
#include "bits/stdc++.h"
#define rep(i,n) for(int i = 0; i < (n); ++i)
using namespace std;
typedef long long int ll;
typedef pair<ll, ll> P;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	int n;
	cin >> n;
	vector<ll> rui(n+1, 0);
	ll sum = 0;
	rep(i,n){
		ll a;
		cin >> a;
		sum += a;
		rui[i+1] = rui[i] + a;
	}
	ll ans = 2e9;
	for(int i = 1; i < n; ++i){
		//cout << i << " " << sum << " " << rui[i] << endl;
		chmin(ans, abs(sum - 2*rui[i]));
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 4776
from collections import Counter
from math import factorial
#from scipy.special import comb
def com(n , r):
    if n == 1:
        return 0
    else:
        return factorial(n) // (factorial(n - r) * factorial(r))
N = int(input())
S = []
for _ in range(N):
    s = input()
    S.append("".join(sorted(s)))
CS = Counter(S)
ans = 0
for val in CS.values():
    ans += com(val , 2 )
print(ans)

Measured memory_bytes: 19820
#include <bits/stdc++.h>
#define FOR(i, a, n) for(ll i = (ll)a; i < (ll)n; i++)
#define FORR(i, n) for(ll i = (ll)n - 1LL; i >= 0LL; i--)
#define rep(i, n) FOR(i, 0, n)
#define ALL(x) (x).begin(), (x).end()
using namespace std;
using ll = long long;
template <typename T> using V = vector<T>;

constexpr int Mod = 998244353;
constexpr int mod = 1e9 + 7;
constexpr ll inf = 1LL << 60;

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

/*-------------------------------------------*/

ll dp[6009][12009];

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

    ll n, m;
    cin >> n >> m;
    dp[0][n * 3] = 1;
    rep(i, 3 * n + 1) rep(j, 6 * n + 1) if(dp[i][j]) {
        (dp[i + 1][j - 1] += dp[i][j]) %= m;
        (dp[i + 2][j + 1] += dp[i][j] * (i + 1)) %= m;
        (dp[i + 3][j] += dp[i][j] * (i + 1) % m * (i + 2)) %= m;
    }
    ll ans = 0;
    rep(j, n * 3 + 1) ans += dp[3 * n][j];
    cout << ans % m << endl;

    return 0;
}

Measured memory_bytes: 561536
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner scanner = new Scanner(System.in);
		long n = scanner.nextLong();
		long a = scanner.nextLong();
		long b = scanner.nextLong();
		System.out.println(n / (a + b) * a + Math.min(n % (a + b), a));
	}

}


Measured memory_bytes: 24020
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner in = new Scanner(System.in);
		int n = in.nextInt();
		long x = in.nextLong();
		long[] num_layer = new long[n+1];
		long[] num_paty = new long[n+1];
		num_layer[0] = 1;
		num_paty[0] = 1;
		for(int i=1;i<=n;i++) {
			num_layer[i] = num_layer[i-1]*2 + 3;
			num_paty[i] = num_paty[i-1]*2 + 1;
		}
		long ans = 0;
		int i = n;
		while(i>=1) {
			if(x==num_layer[i-1]*2+3) {
				ans += num_paty[i-1]*2+1;
				break;
			}else if(x>num_layer[i-1]+2) {
				ans += num_paty[i-1]+1;
				x -= num_layer[i-1]+2;
				i--;
			}else if(x==num_layer[i-1]+2) {
				ans += num_paty[i-1]+1;
				break;
			}else if(x==num_layer[i-1]+1) {
				ans += num_paty[i-1];
				break;
			}else {
				x--;
				i--;
			}
		}
		if(i==0 && x==1) ans++; 
		System.out.println(ans);
		in.close();
	}

}


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

typedef long long ll;
const int N = 2000006;
const ll MOD = 1000000007;

ll fact[N];
ll infact[N];

ll powermod(ll a,ll b){
	ll ret = 1;
	while(b){
		if(b&1){
			ret *= a;
			ret %= MOD;
		}
		b >>= 1;
		a *= a;
		a %= MOD;
	}
	return ret;
}

ll calc(ll n, ll m){
	ll ret = 0;
	for(int i=2;i<=n;i++){
		ll hano = m*fact[m+i-1] - fact[m] * fact[i];
		hano %= MOD;
		hano += MOD;
		hano %= MOD;
		hano *= infact[m];
		hano %= MOD;
		hano *= infact[i];
		hano %= MOD;
		ret += hano;
		ret %= MOD;
	}
	return ret;
}

int main(){
	ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
	
	fact[0] = 1;
	infact[0] = powermod(1,MOD-2);
	
	for(int i=1;i<N;i++){
		fact[i] = fact[i-1] * i;
		fact[i] %= MOD;
		infact[i] = powermod(fact[i],MOD-2);
	}
	
	int r,c,rr,cc;
	cin>>r>>c>>rr>>cc;
	r++;c++;
	rr++;cc++;
	ll ans = calc(rr,cc);
	ans -= calc(rr,c-1);
	ans -= calc(r-1,cc);
	ans += calc(r-1,c-1);
	ans %= MOD;
	ans += MOD;
	ans %= MOD;
	cout<<ans;
	
	return 0;
}


Measured memory_bytes: 34864
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> P;

int main(){
  string N;
  cin >> N;
  for (int i = 0; i < N.length(); i++) {
      if (N.at(i)=='7') {
          cout << "Yes" << endl;
          return 0;
      }
  }
  cout << "No" << endl;
  return 0;
}


Measured memory_bytes: 3628