akhauriyash/Code-Regression huggingface dataset:
#include <cstdio>
#include <utility>
#include <climits>
#include <algorithm>
using namespace std;

#define gcu getchar_unlocked
int in(int c){int n=0;bool m=false;if(c=='-')m=true,c=gcu();
	do{n=10*n+(c-'0'),c=gcu();}while(c>='0');return m?-n:n;} //&&c<='9'
int in() {return in(gcu());}
bool scan(int &n){int c=gcu();return c==EOF?false:(n=in(c),true);}
bool scan(char &c){c=gcu();gcu();return c!=EOF;}
//bool scan(string &s){int c;s="";
//	for(;;){c=gcu();if(c=='\n'||c==' ')return true;else if(c==EOF)return false;s+=c;}}
template <typename head, typename... tail>
bool scan(head &h, tail&&... t){return scan(h) && scan(t...);}
#define pcu putchar_unlocked
#define vo inline void out
template <typename T>
vo(T n){static char buf[20];char *p=buf;
	if(n<0)pcu('-'),n*=-1;if(!n)*p++='0';else while(n)*p++=n%10+'0',n/=10;
	while (p!=buf)pcu(*--p);}
vo(const char *s){while(*s)pcu(*s++);}
vo(char c){pcu(c);}
//vo(string &s){for (char c: s) pcu(c);}
template <typename head, typename... tail> vo(head&& h, tail&&... t){out(h);out(move(t)...);}
//template <typename T> vo(vector<T> &v){for(T &x:v)out(&x == &v[0]?"":" "),out(x);out('\n');}
template <typename... tail> void outl(tail&&... t) {out(move(t)...); out('\n');}
#undef vo

int main() {
	for (int a, b; scan(a, b);)
		outl(a - b);
}


Measured memory_bytes: 2488
n,t=map(int,input().split())
a=[]
b=[]
for i in range(n):
  s,u=map(int,input().split())
  a.append(s)
  b.append(u)
c=[]
for j in range(n):
  if b[j]>t:
    c.append(1001)
  else:
    c.append(a[j])
if c==[1001]*n:
  print('TLE')
else:
  print(min(c))

    


Measured memory_bytes: 3064
#include <bits/stdc++.h>
#define int long long
using namespace std;

typedef tuple<string,int,int> P;

signed main(){
  
  int n;
  cin>>n;
  
  vector<P> S;
    
  for(int i=0;i<n;i++){
    
    string s;
    int p;
    
    cin>>s>>p;
    
    S.push_back( P( s, -p, i + 1 ) );
    
  }
  
  sort( S.begin(), S.end() );
  
  for(P t : S){
    
    string s;
    int p;
    int ans;
    
    tie( s, p, ans ) = t;
    
    cout<<ans<<endl;
    
  }
  
  return 0;
}


Measured memory_bytes: 256
S = input()
N = int(len(S))
Sf = S[:(N-1)//2]
Sb = S[(N+3)//2-1:]
# print(Sf)
# print(Sb)
def rotate(ST) :
    SR = ST[::-1]
    #print(SR)
    if ST == SR :
        return 1
    else:
        return 0


if rotate(S) == 1 and rotate(Sf) == 1 and rotate(Sb) == 1 :
    ans = 'Yes'
else :
    ans = 'No'

print(ans)

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

int n;
int h[100001];
bool visited[100001];
int DP[100001];

int solve(int i)
{
	if(i==n-2)
		return abs(h[i]-h[i+1]);
	else if(i>n-2) return 0;

	int v1,v2;
	if(visited[i+1]) v1 = DP[i+1];
	else{
		v1 = solve(i+1);
		visited[i+1] = true;
		DP[i+1] = v1;
	}

	if(visited[i+2]) v2 = DP[i+2];
	else{
		v2 = solve(i+2);
		visited[i+2] = true;
		DP[i+2] = v2;
	}

	int s1 = abs(h[i]-h[i+1]) + v1;
	int s2 = abs(h[i]-h[i+2]) + v2;
	return min(s1,s2);
}


int main()
{
	cin >> n;
	for (int i = 0; i < n; ++i)
	{
		cin >> h[i];
	}
	cout << solve(0) << endl;

	return 0;
}

Measured memory_bytes: 5760
#include <stdio.h>

const int MAXN = 55;
const int MOD = (int)1e9 + 7;

long long a[MAXN][MAXN];
long long ans[MAXN][MAXN];
long long aux[MAXN][MAXN];

void mul(long long a[MAXN][MAXN], long long b[MAXN][MAXN], long long c[MAXN][MAXN], int n) {
    for (int i = 0; i < n; i++) {
        for (int j = 0; j < n; j++) {
            aux[i][j] = 0;
        }
    }

    for (int i = 0; i < n; i++) {
        for (int j = 0; j < n; j++) {
            for (int k = 0; k < n; k++) {
                aux[i][j] += b[i][k] * c[k][j];
                aux[i][j] %= MOD;
            }
        }
    }

    for (int i = 0; i < n; i++) {
        for (int j = 0; j < n; j++) {
            a[i][j] = aux[i][j];
        }
    }
    return;
}

void fast_exp(int n, long long p) {
    for (int i = 0; i < n; i++) {
        ans[i][i] = 1;
    }
    while(p > 0) {
        if (p & 1) mul(ans, ans, a, n);

        mul(a, a, a, n);
        p /= 2;
    }
    return;
}

int main(void) {
    int n;
    long long k;

    scanf(" %d %lld", &n, &k);
    for (int i = 0; i < n; i++) {
        for (int j = 0; j < n; j++) {
            scanf(" %lld", &a[i][j]);
        }
    }
    fast_exp(n, k);
    long long qt = 0;
    for (int i = 0; i < n; i++) {
        for (int j = 0; j < n; j++) {
            qt += ans[i][j];
            qt %= MOD;
        }
    }
    printf("%lld\n", qt);
    return 0;
}


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

#define FOR(i, j, k) for (int i = j; i < k; i++)
#define REP(i, j) FOR(i, 0, j)
#define fst first
#define snd second
#define pb push_back
#define eb emplace_back
#define all(obj) (obj).begin(), (obj).end()
typedef long long int ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<vi> vvi;

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;
}

template <typename T> istream &operator>>(istream &is, vector<T> &vec) {
  for (T &x : vec)
    is >> x;
  return is;
}

int main() {

  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.precision(10);
  cout << fixed;

  int N, M;
  cin >> M >> N;
  vi x(N);
  cin >> x;

  if (M > N - 1) {
    cout << 0 << endl;
    return 0;
  }

  sort(all(x));

  ll sum = 0;
  vi d(N - 1);
  REP(i, N - 1) {
    d[i] = x[i + 1] - x[i];
    sum += d[i];
  }
  sort(all(d));
  // REP(i, N - 1) cout << d[i] << " ";
  // cout << endl;

  REP(i, M - 1) sum -= d[N - 2 - i];
  cout << sum << endl;

  return 0;
}


Measured memory_bytes: 1024
import copy
import itertools

import numpy as np

H, W, K = map(int, input().split())
C = np.array([list(input()) for _ in range(H)])
F = np.zeros([H, W], dtype=np.int64)

for i in range(H):
    for j in range(W):
        if C[i][j] == "#":
            F[i][j] = 1


cnt = 0
for i in itertools.product(range(2), repeat=H):
    f = copy.deepcopy(F)

    ii = np.arange(H)[np.array(i) == 1]

    f[ii] = 0

    for j in itertools.product(range(2), repeat=W):
        jj = np.arange(W)[np.array(j) == 1]
        ff = copy.deepcopy(f)
        ff[:, jj] = 0
        if np.sum(ff) == K:
            cnt += 1

print(cnt)


Measured memory_bytes: 27264
#include<iostream>
using namespace std;
int i,ans;
int main()
{
	int a[3];
	for(i=0;i<3;i++)
	cin>>a[i];
	ans+=a[0]*100+a[1]*10+a[2];
	if(ans%4==0)
	cout<<"YES"<<endl;
	else
	cout<<"NO"<<endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long int lli;
int main() {
	// your code goes here
	lli n,i,j,k,ans=0;
	cin>>n;
	for(i=1;i<=n;i++){
	    for(j=1;j<=n;j++){
	        for(k=1;k<=n;k++){
	            ans+=__gcd(i,__gcd(j,k));
	        }
	    }
	}
	cout<<ans;
	
	return 0;
}


Measured memory_bytes: 3632
def main():
    H, N = map(int, input().split())
    A = [0] * N
    B = [0] * N
    for i in range(N):
        A[i], B[i] = map(int, input().split())

    dp = [0] * (H+1)
    for x in range(1, H+1):
        dp[x] = min(dp[max(x-a, 0)] + b for a, b in zip(A, B))

    print(dp[H])
if __name__ == "__main__":
    main()

Measured memory_bytes: 42844
#include <stdio.h>
int main()
{
	int a[10];
	int i,j,k;
	while(scanf("%d",&a[0])!=EOF)
	{
		for (i=1;i<10;i++)
			scanf("%d",&a[i]);
		for (i=0;i<9;i++)
		{
			for(j=i+1;j<10;j++)
			{
				if(a[j]>a[i])
				{
					k=a[i];
					a[i]=a[j];
					a[j]=k;
				}
			}
			if(i==2)
				printf("%d\n%d\n%d\n",a[0],a[1],a[2]);
		}
	}
	return 0;
}

Measured memory_bytes: 600
// inputに入力データ全体が入る
function Main(input) {
    // 1行目がinput[0], 2行目がinput[1], …に入る
    
    var answer = Math.floor((Number(input) / 2));
    var answer2 = (Number(input) % 2);
    if (answer2 !== 0) {
        answer++
    }

    console.log(answer);
}
//*この行以降は編集しないでください（標準入出力から一度に読み込み、Mainを呼び出します）
Main(require("fs").readFileSync("/dev/stdin", "utf8"));

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

using namespace std;

int main(){
    vector<int> a(5);
    for(int i=0;i<5;i++){
        cin >> a[i];
    }

    int k;
    cin >> k;
    for(int i=0;i<5;i++){
        for(int j=i+1;j<5;j++){
            if(k<abs(a[i]-a[j])){
                cout << ":(" << endl;
                return 0;
            }
        }
    }

    cout << "Yay!" << endl;
}

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

using namespace std;

int main(){
    int n;
    cin>>n;
    double ans=0;
    
    for(int i=0;i<n;i++){
        double x;
        string s;
        cin>>x>>s;
        
        if(s=="JPY") ans+=x;
        else ans+=x*380000;
    }
    
    cout<<ans<<endl;
    
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main(void){
    int a,b,c,d,e,p;
    cin>>a>>b>>c>>d>>p;
    e=a*p;
    if(p<=c){
        if(b<e){
         e=b;   
        }
    }
    else{
        if(b+d*(p-c)<e){
            e=b+d*(p-c);
        }
    }
    cout<<e<<endl;
    return 0;
}

Measured memory_bytes: 3048
import java.util.Scanner;

public class Main{

	public static void main(String[] args) {

		Scanner scanner = new Scanner(System.in);
		int n = scanner.nextLine().length();
		StringBuilder sb = new StringBuilder();

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

			sb.append("x");

		}

		System.out.println(sb.toString());

	}
}

Measured memory_bytes: 35644
#include <bits/stdc++.h>
using namespace std;
#define ll long long int
#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp> 
using namespace __gnu_pbds;   
#define ordered_set tree<ll, null_type,less<ll>, rb_tree_tag,tree_order_statistics_node_update> 
#define ld long double
#define ff first
#define ss second
#define pb push_back
#define mp make_pair
#define all(a) a.begin(),a.end()
#define sz(a) (ll)(a.size())
const int M = 1e6+6;
ll seg[4*M],lazy[4*M],ct[4*M];
ll ans[100];
int main()
{
	ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
	int n;
	cin>>n;
	string s;
	cin>>s;
	s = "$"+s;
	int q;
	cin>>q;
	while(q--)
	{
		int k;
		cin>>k;
		ll ans = 0;
		ll m = 0;
		ll d = 0;
		ll cur = 0;
		for(int i=1;i<=n;i++)
		{
			if(i>k)
			{
				// delete i-k
				if(s[i-k] == 'D')
				{
					cur -= m;
					d--;
				}
				if(s[i-k] == 'M')
				{
					m--;
				}
			}
			if(s[i] == 'D')
				d++;
			if(s[i] == 'M')
			{
				m++;
				cur += d;
			}
			if(s[i] == 'C')
				ans += cur;
		}
		cout<<ans<<"\n";
	}
	return 0;
}

Measured memory_bytes: 5320
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for (int i=(a);i<(b);++i)
#define REP(i,n) for (int i=0;i<(n);++i)
#define all(a) (a).begin(),(a).end()
#define MOD 1000000007
int main(){
    int a,b,t;
    cin>>a>>b>>t;
    cout<<(t/a)*b<<endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <cstdlib>
#include <cstdio>
#include <queue>
#include <stack>
#include <list>
#include <utility>
#include <vector>
#include <set>
#include <algorithm>
#include <cmath>
#include <climits>
#include <map>
#include <unordered_map>
#include <string.h>
#include<iomanip>
#include <iterator>
#include <locale>

#define all(a) a.begin(),a.end()
#define VV(T) vector<vector< T > >
#define rep(i,N) for(int i = 0; i <N; i++)
#define repsg(i,s,g) for(int i = s; i <g; i++)
#define name(x) #x
using namespace std;


const int INF = 10000000;
const long long INFL = (1LL<<40);
const int MOD = pow(10,9)+7;
int dy[]={0, 0, 1, -1, 0};
int dx[]={1, -1, 0, 0, 0};

typedef long long ll,LL;
typedef vector<int> vint;
typedef vector<vector<int> > vvint;
typedef vector<long long> vll, vLL;
typedef vector<vector<long long> > vvll, vvLL;
typedef pair<int,int> pii;
typedef pair<LL, LL> pLL;


// vector入力
template<typename T>
istream& operator >> (istream& is, vector<T>& vec){
    for(T& x: vec) is >> x;
    return is;
}
// vector出力
template<typename T>
ostream& operator << (ostream& os, vector<T>& vec){
    for(int i=0; i<vec.size(); i++){
        os << vec[i] << ( i+1 == vec.size() ? "" : " " );
    }
    return os;
}

template< typename T >
struct edge{
    int src, to;T cost;
    edge(int to,T cost) :src(-1),to(to),cost(cost){}
    edge(int src, int to, T cost) :src(src),to(to),cost(cost){}edge
    &operator=(const int &x){
        to =x;
        return *this;
    }
    operator int() const{ return to;}
};



int main() {
    int n;cin>>n;
    string s;cin>>s;
    int maxim=-1;
    repsg(i,1,n){
        string p = s.substr(0,i);
        string q = s.substr(i);
        int c[127]={0};
        int d[127]={0};
        for(auto x:p) c[x]=1;
        for(auto y:q) d[y]=1;
        int temp = 0;
        rep(z,127) temp += (c[z]*d[z]);
        
        maxim = max(maxim,temp);
    }
    cout<<maxim<<endl;
    return 0;
}







Measured memory_bytes: 256
#include<stdio.h>
int main (void)
{
    int n;
    int ans = 0;
    scanf("%d",&n);
    int c[n],v[n];
    for(int i = 0; i < n; i ++) {
        scanf("%d",&v[i]);
    }
    for(int i = 0; i < n; i ++) {
        scanf("%d",&c[i]);
    }
    for(int i = 0; i < n; i ++) {
        if(v[i] > c[i])
            ans += v[i] - c[i];
    }
    printf("%d",ans);
    return 0;
}

Measured memory_bytes: 128
#include <stdio.h>

int minn(int x, int y, int z)
{
    if (x >= y)
    {
        if (y >= z)
        {
            return z;
        }

        if (y <= z)
        {
            return y;
        }
    }

    if (x <= y)
    {
        if (x <= z)
        {
            return x;
        }

        if (x >= z)
        {
            return z;
        }
        
        
    }
    
    
}

int main(void)
{
    unsigned long int answer = 0;
    int K;
    scanf("%d", &K);

    for (int i = 1; i <= K; i++)
    {
        for (int k = 1; k <= K; k++)
        {
            for (int j = 1; j <= K; j++)
            {
                for (int n = minn(i, k, j); n >= 1; n--)
                {
                    if (i%n == 0 && k%n == 0 && j%n == 0)
                    {
                        answer += n;
                        break;
                    }
                    
                }
                
            }
            
        }
        
    }

    printf("%lu", answer);
    
    return 0;
}

Measured memory_bytes: 1724
fun main(args: Array<String>) {
    abc086b()
}

fun abc086b() {
    val ab = readLine()!!.replace(Regex(" "), "")

    val sqrt = Math.sqrt(ab.toDouble()).toInt()

    val answer = if (sqrt * sqrt == ab.toInt()) "Yes" else "No"

    println(answer)
}


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

#define ll long long
#define fw(p) for(int w=0;w<(p);w++)
#define fx(p) for(int x=0;x<(p);x++)
#define fy(p) for(int y=0;y<(p);y++)
#define fz(p) for(int z=0;z<(p);z++)
#define fyg(p,g) for(int y=(g);y<(p);y++)
#define fzg(p,g) for(int z=(g);z<(p);z++)
#define ce(d) cout<<d<<endl;
#define vecp(p) int aa;cin>>aa;(p).push_back(aa);
#define vecpl(p) long long aa;cin>>aa;(p).push_back(aa);
#define vecps(p) string aa;cin>>aa;(p).push_back(aa);
#define vecp2(p) cin>>aa;(p).push_back(aa);
#define vecpl2(p) long long a	b;cin>>ab;(p).push_back(ab);
#define vecps2(p) string ab;cin>>ab;(p).push_back(ab);
#define set0(k,n) for(int nn=0;nn<(n);nn++){ (k).push_back(0); }
#define sorts(c) sort((c).begin(),(c).end());
#define reverses(c) reverse((c).begin(),(c).end());
#define vec(b) vector<int> (b);
#define vecl(b) vector<long long> (b);
#define vecs(b) vector<string> (b);
#define vecsize(b,size) vector<int> (b)((size));
#define pb(b,a) (b).push_back((a));
#define doublece(a,b) cout<<(a)<<' '<<(b)<<endl;
#define pairs(s) vector<pair<int,int>> (s);
#define pairsl(s) vector<pair<ll,ll>> (s);
#define pairss(s) vector<pair<string,string>> (s);
#define pairsp(s) int aa,bb;cin>>aa>>bb;(s).push_back(make_pair(aa,bb));
#define pairspl(s) int aa,bb;cin>>aa>>bb;(s).push_back(make_pair(aa,bb));
#define pairsps(s) int aa,bb;cin>>aa>>bb;(s).push_back(make_pair(aa,bb));
#define pairsREV(s) (s).push_back(make_pair(bb,aa));
#define pairslREV(s) (s).push_back(make_pair(bb,aa));
#define pairssREV(s) (s).push_back(make_pair(bb,aa));
#define MOD 1000000007

int main()
{
	int N, A, B;
	cin >> N >> A >> B;
	ce(min(N*A,B))

    return 0;
}



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

int main() {
	int n;
	cin >> n;
	double probabilities[n];
	double solve[n+1][n+1]={{0.0d}};
	for(int i=0;i<n;i++)
		cin >> probabilities[i];
	solve[0][0]=1;
	for(int i=0;i<=n;i++)
        for(int j=i;j<=n;j++)
            {
                solve[i][j+1]+=solve[i][j]*(1-probabilities[j]);
                solve[i+1][j+1]=solve[i][j]*(probabilities[j]);
            }
    double totalProbability=0.0d;
    for(int i=0;i<(n+1)/2;i++)
        totalProbability+=solve[i][n];
    cout << setprecision(10) << (1-totalProbability) << "\n";
    return 0;
}

Measured memory_bytes: 70528
#include<stdio.h>
#include<string.h>

char a[51][51];
char b[51][51];

int main(void) {

	int i, j, k, l;
	int n, m;
	int flag = 0;
	char c;

	scanf("%d%d%c", &n, &m, &c);

	//行列のnまたはm成分には改行文字が含まれていることに注意//
	for (i = 0; i < n; i++) {
		scanf("%s", a[i], 51);
	}

	for (i = 0; i < m; i++) {
		scanf("%s", b[i], 51);
	}


	//同じ行列が含まれるか判定//
	//まず大きいほうの各行列成分について//
	for (i = 0; i <= n - m; i++) {
		for (j = 0; j <= n - m; j++) {
			//小さいほうの各行列成分が等しいか確認//
			for (k = 0; k < m; k++) {
				for (l = 0; l < m; l++) {
					if (a[i + k][j + l] != b[k][l]) {
						flag = 1;
						break;
					}
				}
				if (flag == 1) {
					break;
				}
			}
			if (flag == 0) {
				printf("Yes\n");
				return 0;
			}
			flag = 0;
		}
	}

	printf("No\n");
	   
	return 0;
}

Measured memory_bytes: 128
open Batteries
module EnumL = Enum.Labels
module ListL = List.Labels
module ArrayL = Array.Labels

let dbg0 x = Printf.eprintf "[debug]%s\n" @@ dump x
let dbg1 x = dbg0 x; x

let id = identity

let (++) n m = List.range n `To m
let (++^) n m = if n < m then List.range n `To (pred m) else []

let scan fmt = Scanf.sscanf (read_line ()) fmt

let scan_lines n fmt f =
  if n = 0 then []
  else List.map (fun _ -> scan fmt f) (1 ++ n)

let scan_list sep cnv =
  let line = read_line () in
  (match sep with
   | None -> List.map String.of_char @@ String.to_list line
   | Some sep -> String.split_on_char sep line)
  |> List.map cnv

let scan_array ?sep cnv = Array.of_list @@ scan_list sep cnv

let scan_matrix n m e ?sep conv =
  let arr = Array.make_matrix n m e in
  ListL.iter (0 ++^ n)
    ~f:(fun i -> arr.(i) <- Array.of_list @@ scan_list sep conv);
  arr

let rec powerset e =
  match Enum.get e with
  | None -> Enum.singleton @@ Enum.empty ()
  | Some v ->
    let f = powerset e in
    let g = Enum.clone f in
    EnumL.map f ~f:(fun x -> let y = Enum.clone x in push y v; y)
    |>  Enum.append g

let permutations l =
  let rec aux l =
    let rec interleave x = function
      | [] -> [[x]]
      | (hd::tl) as lst ->
        (x::lst) ::
        (ListL.map ~f:(List.cons hd)  @@ interleave x tl)
    in
    match l with
    | [] -> [[]]
    | hd::tl -> List.concat @@ List.map (interleave hd) @@ aux tl in
  let l = List.sort (List.compare Int.compare) @@ aux @@ List.of_enum l in
  List.enum % ListL.map ~f:List.enum @@ l

let intersection l =
  EnumL.filter ~f:(fun x -> EnumL.exists ~f:((=) x) @@ Enum.clone l)

let lower_bound n f =
  let rec aux l u =
    if u - l > 1 then
      let m = (l + u) / 2 in
      if f m then aux l m
      else aux m u
    else u in aux (-1) n

let between n x m = n <= x && x < m

let k = scan "%d" id
let (a,b) = scan "%d %d" Tuple2.make

let () =
  ListL.exists ~f:(fun i -> i mod k = 0) (a++b)
  |> (fun b -> Printf.printf "%s\n" (if b then "OK" else "NG"))


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

const int N = 100005;

int n;
int a[N];
int rem[N];
vector<int> G[N];

void dfs(int u, int p) {
	int mx = 0;
	rem[u] = (G[u].size() == 1 ? a[u] : 0);
	for (int v : G[u]) if (v != p) {
		dfs(v, u);
		rem[u] += rem[v];
		mx = max(mx, rem[v]);
	}
	if (a[u] > rem[u]) { printf("NO\n"); exit(0); }
	int need = rem[u] - a[u]; // number of needed pairs

	if (mx > rem[u] / 2) mx = rem[u] - mx;
	else mx = rem[u] / 2;

	if (mx < need) { printf("NO\n"); exit(0); }

	rem[u] -= 2 * need;
	a[u] = 0;
	//cerr << u << ' ' << rem[u] << endl;
}

int main() {
	ios_base::sync_with_stdio(false); cin.tie(0);
	cin >> n;
	for (int i = 1; i <= n; ++i) cin >> a[i];
	if (n == 2) {
		if (a[1] == a[2]) return printf("YES\n"), 0;
		else return printf("NO\n"), 0;
	}
	for (int i = 1; i < n; ++i) {
		int u, v; cin >> u >> v;
		G[u].push_back(v); G[v].push_back(u);
	}
	int rt;
	for (int i = 1; i <= n; ++i) if (G[i].size() > 1) rt = i;
	dfs(rt, 0);

	if (!rem[rt]) printf("YES\n"); else printf("NO\n");
}

Measured memory_bytes: 13696
#define _USE_MATH_DEFINES
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <climits>
#include <cfloat>
#include <ctime>
#include <cassert>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <memory>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <sstream>
#include <complex>
#include <stack>
#include <queue>
#include <numeric>
#include <list>
#include <iomanip>


using namespace std;
typedef long long ll;
const int MODULO = 1000000007;
const int INF = 100000000; //1e8

typedef long long ll;
typedef pair<int,int> Pii;
typedef pair<ll,ll> Pll;
typedef complex<double> Cd;

int expr(char *& s);

int val(char *& s){
	if(*s == '('){
		s++;
		int ret = expr(s);
		s++;
		return ret;
	}

	int v = 0;
	while(*s >= '0' && *s <= '9'){
		v *= 10;
		v += *s - '0';
		s++;
	}
	return v;
}

int pri(char *& s){
	int l = val(s);
	while(true){
		char ope = *s;
		if(ope != '*' && ope != '/')
			return l;
		s++;
		int r = val(s);
		if(ope == '*')
			l *= r;
		else
			l /= r;
	}
}

int expr(char *& s){
	int l = pri(s);
	while(true){
		char ope = *s;
		if(ope != '+' && ope != '-')
			return l;
		s++;
		int r = pri(s);
		if(ope == '+')
			l+=r;
		else
			l-=r;
	}
}

void solve()
{
	char s[256];
	cin>>s;
	char *p = s;
	cout << expr(p) << endl;
}

int main(){
	int t; cin>>t;
	while(t--){
		solve();
	}

	return 0;
}

Measured memory_bytes: 0
n = int(input())
a = [int(i) for i in input().split()]
b = []
c = {}
for i in a:
    b.append(i-1)
    b.append(i)
    b.append(i+1)

for i in b:
    if i in c.keys():
        c[i] = c[i]+1
    else:
        c[i] = 1

print(sorted(c.items(),key = lambda x: x[1],reverse = True)[0][1])

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

#define rep(X,Y) for (int (X) = 0;(X) < (Y);++(X))
#define all(X) (X).begin(),(X).end()
#define fi first
#define sc second
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;

int a, b;

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

  cout << (b-a)*(b-a-1)/2 - a << endl;

}


Measured memory_bytes: 256
#pow(a,b,mod)
#np.gcd.outer
#s.count, s.replace, s.index
from math import gcd
from functools import reduce
from itertools import product ##for i in z for j in z -> for i,j in product(z,z)   ||  for i,j in product(z,repeat=2)


n,k=map(int,input().split(' '))
 
mod=10**9+7
 
ar=list(range(1,k+1))
ar.reverse()
 
ans=[0]*(k+1)
for i in ar:
	ava=(k-i)//i+1
	ans[i]=pow(ava,n,mod)
	for j in range(i*2,k+1,i):
		ans[i]-=ans[j]
print(sum(i*x for i,x in enumerate(ans))%mod)
	


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

int main(){
  vector<int> A(3);
  rep(i,3) cin >> A[i];
  sort(A.begin(),A.end());
  if(A[0] + A[1] == A[2]){
    puts("Yes");
    return 0;
  }
  puts("No");
  return 0;
}


Measured memory_bytes: 256
// AtCoder-Template.cpp : このファイルには 'main' 関数が含まれています。プログラム実行の開始と終了がそこで行われます。
//

#include <iostream>
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cctype>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <deque>
#include <fstream>
#include <functional>
#include <iostream>
#include <limits>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <vector>
using namespace std;
using ll = long long;
#define fst first
#define snd second
#define FOR(i,N) for(auto i=0; i<N; ++i)
#define FORREV(i,N,_cnt) for(auto i=N-1,cnt=_cnt; cnt > 0; --i, --cnt)
#define ALL(x) x.begin(), x.end()

/* clang-format off */
template <class T, size_t D> struct _vec { using type = vector<typename _vec<T, D - 1>::type>; };
template <class T> struct _vec<T, 0> { using type = T; };
template <class T, size_t D> using vec = typename _vec<T, D>::type;
template <class T> vector<T> make_v(size_t size, const T& init) { return vector<T>(size, init); }
template <class... Ts> auto make_v(size_t size, Ts... rest) { return vector<decltype(make_v(rest...))>(size, make_v(rest...)); }
template <class T> inline void chmin(T& a, const T& b) { if (b < a) a = b; }
template <class T> inline void chmax(T& a, const T& b) { if (b > a) a = b; }
/* clang-format on */

int main() {
#ifdef DEBUG
	ifstream ifs("in.txt");
	cin.rdbuf(ifs.rdbuf());
#endif
	ll N;
	cin >> N;
	ll ans = 0;
	if (N == 3) {
		ans = 180;
	}
	else {
		ans = 180 * N - 360;
	}
	cout << ans << endl;

	return 0;
}


Measured memory_bytes: 256
#include <stdio.h>

int main(int argc, const char * argv[]) {
    int n, a;
    int min, max;
    long long sum;
    
    scanf("%d", &n);
    
    for (int i=0; i<n; i++) {
        //scanfでn回整数を読み取る
        scanf("%d", &a);
        if (i == 0) {
            min = a;
            max = a;
            sum = a;
        }else{
            if (max < a) {
                max = a;
            }
            if (min > a) {
                min = a;
            }
            sum += a;
        }
    }
    
    printf("%d %d %lld\n", min, max, sum);

    return 0;
}


Measured memory_bytes: 2104
#include <bits/stdc++.h>
#pragma warning (disable:4996)
using namespace std;
#define ll long long 
#define ull unsigned long long



int main()
{
	int a, b;
	cin >> a >> b;
	int sum = a;
	if (b == 1)
	{
		cout << 0;
		return 0;
	}
	if (a >= b)
	{
		cout << 1;
		return 0;
	}
	for (int cnt = 2; ; cnt++)
	{
		sum += a - 1;
		if (sum >= b)
		{
			cout << cnt;
			break;
		}
	}

	return 0;
}

Measured memory_bytes: 256
#include <algorithm>
#include <array>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <map>
#include <memory>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <sstream>
#include <unordered_map>
#include <vector>


#define INF 4000000000000000000LL
#define MOD 1000000007
#define ALL(x) std::begin(x), std::end(x)


int main(int argc, char** argv)
{
  std::cin.tie(0);
  std::ios_base::sync_with_stdio(0);

  std::cout << std::fixed << std::setprecision(6);

  int N, A, B, total = 0;
  
  std::cin >> N >> A >> B;

  for (int i = 0; i <= N; i ++) {
    std::string s(std::to_string(i));

    int S = 0;

    for (const auto& c : s)
      S += c - '0';

    if (A <= S && S <= B)
      total += i;
  }

  std::cout << total << std::endl;

  return 0;
}


Measured memory_bytes: 888
N,A,B = list(map(int,input().split()))
X = list(map(int,input().split()))
Y = [0]*(N-1)
for i in range(N-1):
    Y[i] = X[i+1]-X[i]
out = 0
for i in range(N-1):
    out += min(B,Y[i]*A)
print(out)


Measured memory_bytes: 85532
#include<stdio.h>
#include<ctype.h>
int main(){
  int a,b;
  int x=0;
  int z=0;
  char A;
  while(scanf("%c",&A)!=EOF){
    if(islower(A)){
      A=toupper(A);
    }
    printf("%c",A);
  }
  return 0;
}

Measured memory_bytes: 524
import sys

sr = lambda: sys.stdin.readline().rstrip()
ir = lambda: int(sr())
lr = lambda: list(map(int, sr().split()))

S = sr()
bl = False
for x, y in zip(S, S[1:]):
    if x+y == 'AC':
        bl = True

print('Yes' if bl else 'No')
# 45

Measured memory_bytes: 3060
#include<iostream>

using namespace std;

int main(void){
    int i, j, k, n, b, f, r, v, people[4][3][10]={};
    cin >> n;
    for(i=0; i<n; i++){
        cin >> b >> f >> r >> v;
        people[b-1][f-1][r-1] += v;
    }
    for(k=0; k<4; k++){
        for(j=0; j<3; j++){
            for(i=0; i<10 ;i++) cout << " " << people[k][j][i];
            cout << endl;
        }
        if(k<3){
            for(i=0; i<20; i++) cout << "#";
            cout << endl;
        }
    }
    return 0;
}

Measured memory_bytes: 3100
A = [list(map(int, input().split())) for _ in range(3)]
n = int(input())
B = [int(input()) for _ in range(n)]

li = []
for i in A:
  li.append(i)
for i in range(3):
  li.append([A[0][i], A[1][i], A[2][i]])
li.append([A[0][0], A[1][1], A[2][2]])
li.append([A[0][2], A[1][1], A[2][0]])

for i, j, k in li:
  if i in B and j in B and k in B:
    print("Yes")
    exit()
print("No")

Measured memory_bytes: 3064
#include <iostream>
#include <sstream>
#include <algorithm>
#include <functional>
#include <iterator>
#include <numeric>
#include <cstdint>
#include <cmath>
#include <bitset>
#include <string>
#include <list>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>

#define N_TIMES(i, n)     for ( uint64_t i = 0;     i <  n; ++i )
#define N_TIMES_REV(i, n) for (  int64_t i = n - 1; i >= 0; --i )
#define SQRTI(n) static_cast<uint64_t>(::floor(::sqrt(static_cast<double>(n))))

#ifdef __DEBUG__
template<typename T, typename U>
std::ostream& operator<<(std::ostream &os, const std::pair<T, U> &pair)
{
  os << pair.first << ": " << pair.second;
  return os;
}

template<class ForwardIterator>
std::ostream& _iterator_to_display(
  std::ostream &os, 
  ForwardIterator begin, ForwardIterator end, 
  const std::string &delim = ", "
)
{
  auto itr = begin;
  while (itr != end) {
    os << *itr;
    ++itr;
    if (itr != end) os << delim;
  }
  return os;
}

template<typename T>
std::ostream& operator<<(std::ostream &os, const std::list<T> &list)
{
  _iterator_to_display(os, list.begin(), list.end());
  return os;
}

template<typename T>
std::ostream& operator<<(std::ostream &os, const std::vector<T> &vector)
{
  _iterator_to_display(os, vector.begin(), vector.end());
  return os;
}

template<typename T, class C=std::less<T>>
std::ostream& operator<<(std::ostream &os, const std::set<T> &set)
{
  _iterator_to_display(os, set.begin(), set.end());
  return os;
}

template<typename T, typename U, class C=std::less<T>>
std::ostream& operator<<(std::ostream &os, const std::map<T, U> &map)
{
  _iterator_to_display(os, map.begin(), map.end());
  return os;
}
#endif /* __DEBUG__ */

int main(int argc, char **argv)
{
  uint32_t D, G;
  std::cin >> D >> G;
  
  std::vector<uint32_t> p(D), c(D), s(D);
  N_TIMES(d, D) {
    std::cin >> p[d] >> c[d];
    s[d] = (d + 1) * 100 * p[d] + c[d];
  }
  
  uint32_t min = INT32_MAX;
  
  for (uint32_t i = 0; i < (1 << D); ++i) {
    std::bitset<10> bs(i);
    uint32_t x = 0, y = 0;
    
    N_TIMES(d, D) {
      if (bs[d]) {
        x += s[d];
        y += p[d];
      }
    }
    
    if (x < G) {
      N_TIMES_REV(d, D) {
        if (!bs[d]) {
          uint32_t remain = G - x;
          uint32_t unit_price = (d + 1) * 100;
          
          uint32_t m = (remain / unit_price) + ((remain % unit_price > 0) ? 1 : 0);
          uint32_t n = std::min(m, p[d] - 1);
          
          x += n * unit_price;
          y += n;
          
          break;
        }
      }
    }
    
    if (x >= G) {
      min = std::min(y, min);
    }
  }
  
  std::cout << min << std::endl;
  
  return 0;
}

Measured memory_bytes: 256
//#include <bits/stdc++.h>
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <stack>
using namespace std;

#define FOR(i,f,t) for(int i=(int)f; i<(int)t; i++)
#define FORR(i,f,t) for(int i=(int)f; i>(int)t; i--)
#define ms(obj, val) memset(obj, val, sizeof(obj))
#define pb push_back
#define SYNC ios_base::sync_with_stdio(false)
#define st(v) sort(v.begin(),v.end());
#define F first
#define S second
#define ri(x) scanf("%d",&x)
#define rii(x,y) scanf("%d %d",&x,&y)
#define riii(x,y,z) scanf("%d %d %d",&x,&y,&z)
#define lri(x) scanf("%lld",&x)
#define lrii(x,y) scanf("%lld %lld",&x,&y)
#define lriii(x,y,z) scanf("%lld %lld %lld",&x,&y,&z)

typedef vector<int> vi;
typedef long long ll;
typedef pair<int, int> ii;

const int MAXN = 2e5+3; //AREGLAAAAAAAAR!!!!
const int MAXLOG = 20;


int main(){
	int n;
	ri(n);
	int cnt=0;
	FOR(i,1,n+1){
		int num = sqrt(i);
		int ans=0;
		if(i%2==0) continue;
		FOR(j,1,num+1){
			if(i%j==0){
				ans++;
				if(j/i!=i) ans++;
			}
		}
		if(ans==8) cnt++;
	}
	printf("%d\n",cnt);
}


Measured memory_bytes: 256
def main():
    n, d = map(int, input().split())
    x = [list(map(int, input().split())) for i in range(n)]

    ans = 0
    for i in range(n-1):
        for j in range(i+1,n):
            res = 0
            for k in range(d):
                res += (x[j][k]-x[i][k])**2
            if (res**0.5).is_integer():
                ans += 1
    print(ans)

if __name__ == '__main__':
    main()



Measured memory_bytes: 38384
import sys
from collections import deque
import copy
import math
def get_read_func(fileobject):
    if fileobject == None :
        return raw_input
    else:
        return fileobject.readline

global score

def dfs(graph, nd, d):
    global score
    max_depth = 0
    if score[nd] != -1:
        return score[nd] + 1
    if len(graph[nd]) == 0:
        score[nd] = 0
        return 1
    for adj in graph[nd]:
        max_depth = max(max_depth, dfs(graph, adj, d + 1))

    #if max_depth > score[nd]:
    score[nd] = max_depth
    return score[nd] + 1


def main():
    if len(sys.argv) > 1:
        f = open(sys.argv[1])
    else:
        f = None
    sys.setrecursionlimit(100000)
    read_func = get_read_func(f);
    input_raw = read_func().strip().split()
    [N, M] = [int(input_raw[0]), int(input_raw[1])]
    graph = {}
    global score
    score = {}
    for i in range(1, N+1):
        graph[i] = []
        score[i] = -1
    for i in range(M):
        input_raw = read_func().strip().split()
        [a, b] = [int(input_raw[0]), int(input_raw[1])]
        graph[a].append(b)

    for i in range(1, N + 1):
        dfs(graph, i, 0)
    max_score = 0
    for i in range(1, N + 1):
        max_score = max(max_score, score[i])
    print max_score
##        q = [i]
##        d = 0
##        while 1:
##            if len(q) <= 0:
##                score[i] = d
##                break
##            nd = q.pop()
##            if score[nd] != -1:
##                score[i] = d + score[nd]
##                break
##            for adj in graph[nd]:
##                if score[nd] + 1 > score[adj]:
##                    q.append(adj)
##                    score[adj] = score[nd] + 1
##                else:







if __name__ == '__main__':
    main()


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


int main(){
  vector<int> edge(3);
  cin >> edge.at(0) >> edge.at(1) >> edge.at(2);
  sort(edge.begin(), edge.end());
  int s = (edge.at(0) * edge.at(1)) / 2;
  cout << s << endl;
}


Measured memory_bytes: 256
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep2(i, s, n) for (int i = (s); i < (int)(n); i++)
#define ALL(v) v.begin(),v.end()
using ll = long long;
using pii = pair<int,int>;
using vi = vector<int>;
using vs = vector<string>;
using vb = vector<bool>;
using vll = vector<long long>;
using vpii = vector<pair<int,int>>;
using vivi = vector<vector<int>>;
using vbvb = vector<vector<bool>>;
const int dx[4] = {1,0,-1,0};
const int dy[4] = {0,1,0,-1};
const int mod = 1000000007;
const int inf = 1001001001;



int main(void) {
  int n;
  cin >> n;
  vi a(n);
  rep(i,n) cin >> a[i];
  deque<int> b;
  rep(i,n){
    if(i%2)b.push_back(a[i]);
    else b.push_front(a[i]);
  }
  while(!b.empty()){
    if(n%2){
      cout << b.front() << endl;
      b.pop_front();
    }
    else{
      cout << b.back() << endl;
      b.pop_back();
    }
  }
  
      
}




Measured memory_bytes: 3840
package main

import (
	"fmt"
	"strings"
)

func main() {
	var S string
	fmt.Scan(&S)
	sList := strings.Split(S, "")
	red := 0
	blue := 0
	for _, v := range sList {
		if v == "0" {
			red++
		} else {
			blue++
		}
	}

	if red < blue {
		fmt.Println(2 * red)
	} else {
		fmt.Println(2 * blue)
	}
}


Measured memory_bytes: 2944
#include<bits/stdc++.h>
typedef long long ll;
typedef long double ld;
using namespace std;

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

#define REP(i, l, n) for(int i=(l), i##_len=(n); i<i##_len; ++i)
#define ALL(x) (x).begin(),(x).end()
#define pb push_back

ll gcd(ll a,ll b){return b ? gcd(b,a%b) : a;}
ll lcm(ll a,ll b){return a/gcd(a,b)*b;}

char alpha[26] = {'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z'};

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

int check(vector<ll> ch){
    REP(i, 0, 20){
        if(ch[i] > 1){
            return 0;
        }
    }
    return 1;
}

int main(){
    int n; cin >> n;
    vector<ll> lis(n);
    REP(i, 0, n){
        cin >> lis[i];
    }
    lis.pb(0); lis.pb(0);
    int r = 0;
    ll ans = 0;
    vector<ll> bit(20, 0);
    REP(l, 0, n){
        while(check(bit) == 1){
            if(r == n+1){
                break;
            }else{
                ll c = lis[r], c1 = lis[r];
                REP(k, 0, 20){
                    bit[k] += c % 2;
                    c /= 2;
                }
                r++;
            }
        }
        ans += (r-l-1);
        ll c = lis[l];
        REP(k, 0, 20){
            bit[k] -= c % 2;
            c /= 2;
        }
    }
    cout << ans << endl;
}

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

typedef unsigned long long ull;

int main(){
	ull x;
	cin >> x;
	ull d = 100ULL;
	int ans = 0;
	while((ull)d < x){
		double m = floor(d * .01);
		d += (ull) m;
		ans ++;
	}
	cout << ans;
}

Measured memory_bytes: 3636
import sys

a,v =map(int,input().split())
b,w =map(int,input().split())
t =int(input())
 
if a==b:
    print('YES')
    sys.exit()
if a<b:
    w=abs(w)
    v=abs(v)
    if (a+v*t)>=(b+w*t):
        print('YES')
        sys.exit()
    else:
        print('NO')
else:
    w=(abs(w)*(-1))
    v=(abs(v)*(-1))
    if (a+v*t)<=(b+w*t):
        print('YES')
        sys.exit()
    else:
        print('NO')

Measured memory_bytes: 9220
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define MOD 1000000007
#define INF 1e9
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 a[26];
int main(void){
    string S;
    cin>>S;
    
    int a[26];
    for(int i=0;i<26;i++) a[i]=0;
    for(int i=0;i<4;i++){
        a[S[i]-'A']++;
        //cout<<S[i]-'A'<<endl;
    }
    
    for(int i=0;i<26;i++){
        if(a[i]==0 || a[i]==2) continue;
        cout<<"No"<<endl;
        return 0;
    }
    cout<<"Yes"<<endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define REP(i,n,N) for(int i=(n);i<(int) N;i++)
#define RREP(i,n,N) for(int i=N-1;i>=(int) n;i--)
#define p(s) cout<<(s)<<endl
#define DEBUG(x,y) cout<<#x<<": "<<x<<" , "<<#y<<": "<<y<<endl;
#define CK(n,a,b) ((a)<=(n)&&(n)<(b))
#define F first
#define S second
typedef long long ll;
using namespace std;
const int inf=1e9;


bool visited[100010];
int dp[100010];
int dp2[100010];
vector<int> edge[100010];
int main(){
	int N;
	cin>>N;
	REP(i,0,N){
		int a,b;
		cin>>a>>b;
		edge[a].push_back(b);
		edge[b].push_back(a);
	}

	queue<int> q,q1,q2;
	q.push(1);
	REP(i,1,N+1) {
		dp[i]=inf;
		dp2[i]=inf;
	}
	dp[1]=0;
	int cnt=0;
	bool flag=false;
	visited[1]=true;
	while(!q.empty()){
		int node=q.front();q.pop();
		for(auto next:edge[node]){
			if(dp[next]<inf) continue;
			if(next==N) {
				cnt=(dp[node]+1)/2;
				flag=true;
				break;
			}
			dp[next]=dp[node]+1;
			q.push(next);
		}
		if(flag) break;
	}
	//REP(i,0,N+1) p(dp[i]);
//	p(cnt);
	q1.push(N);
	flag=false;
	dp2[N]=0;
	int ans2=0;
	while(!q1.empty()){
		int node=q1.front();q1.pop();
		for(auto next:edge[node]){
			if(dp2[next]<inf) continue;
			if(dp[next]<=cnt) continue;
			ans2++;
			dp2[next]=dp2[node]+1;
			q1.push(next);
		}
		if(flag) break;
	}

//	REP(i,0,N+1) p(dp2[i]);
	q2.push(1);
	int ans=0;
	visited[0]=true;
	while(!q2.empty()){
		int node=q2.front();q2.pop();
		for(auto next:edge[node]){
			if(visited[next]) continue;
			if(dp2[next]<inf) continue;
			visited[next]=true;
			ans++;
			q2.push(next);
		}
	}
//	p("ok");

	if(ans>ans2) p("Fennec");
	else p("Snuke");
	return 0;
}


Measured memory_bytes: 6784
#include <iostream>
#include <string>
using namespace std;
 
int main(void){
  int n;
  cin >> n;
  
  string word;
  cin >> word;
  
  int k;
  cin >> k;
  
  char p = word[k-1];
  for(int i=0;i<n;i++){
    if(word[i] != p){
      word[i] = '*';
    }
  }
    cout << word << endl;
    
    return 0;
}

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

#include <math.h>
#include <stdio.h>
using namespace std;

int main(void) {
	double x1, y1, x2, y2;
	cin >> x1 >> y1 >> x2 >> y2;
	double distance = sqrt((x2 - x1) * (x2 - x1) + (y2 - y1) * (y2 - y1));
	printf("%.7f", distance);
	return 0;
}



Measured memory_bytes: 3220
'use strict';

var _slicedToArray = function () { function sliceIterator(arr, i) { var _arr = []; var _n = true; var _d = false; var _e = undefined; try { for (var _i = arr[Symbol.iterator](), _s; !(_n = (_s = _i.next()).done); _n = true) { _arr.push(_s.value); if (i && _arr.length === i) break; } } catch (err) { _d = true; _e = err; } finally { try { if (!_n && _i["return"]) _i["return"](); } finally { if (_d) throw _e; } } return _arr; } return function (arr, i) { if (Array.isArray(arr)) { return arr; } else if (Symbol.iterator in Object(arr)) { return sliceIterator(arr, i); } else { throw new TypeError("Invalid attempt to destructure non-iterable instance"); } }; }();

var fs = require('fs');

var input = Buffer.alloc(0x10000);
fs.readSync(0, input, 0, 0x10000);

var _input$toString$split = input.toString().split('\n').map(function (n) {
    return parseInt(n);
}),
    _input$toString$split2 = _slicedToArray(_input$toString$split, 4),
    A = _input$toString$split2[0],
    B = _input$toString$split2[1],
    C = _input$toString$split2[2],
    X = _input$toString$split2[3];

var answer = 0;

for (var a = 0; a <= Math.min(Math.floor(X / 500), A); a++) {
    var remnantA = X - 500 * a;
    for (var b = 0; b <= Math.min(Math.floor(remnantA / 100), B); b++) {
        var remnantB = remnantA - 100 * b;
        if (remnantB >= 0 && remnantB <= C * 50) {
            answer++;
        }
    }
}

console.log(answer);

Measured memory_bytes: 21192
#include <iostream>
#include <utility>
#include <map>
#include <vector>
#include <algorithm>
#include <queue>
#include <math.h>
#include <stack>
#include <set>
#include <deque>

using namespace std;
typedef long long ll;
ll mod = 1e9+7;
#define rep(i,n) for(int i = 0; i < (n); ++i)

int main(){
    int h, w, d;
    cin >> h >> w >> d;
//    vector<vector<int>> a(h, vector<int>(h));
    vector<pair<int, int>> place(h*w+1);
    rep(i, h) rep(j, w) {
        int a;
        cin >> a;
        place[a] = {i+1, j+1};  
    }

//    for ( auto place_num : place ) {
//        cout << place_num.first << ":" << place_num.second << ", ";
//    }
//    cout << endl;

    vector<ll> magic(h*w+1, -1);
    for ( int i = 1; i <= d; ++i ) {
        if ( magic[i] != -1 ) continue;
        magic[i] = 0;
        int idx = i+d;
        while(1) {
            if ( idx >= h*w+1 ) break;
            magic[idx] = magic[idx-d] + ( abs(place[idx].first - place[idx-d].first) + abs(place[idx].second - place[idx-d].second) );
            idx += d;
        }
    }

//    for ( auto magic_num : magic) {
//        cout << magic_num << " ";
//    }

    int q;
    cin >> q;
    vector<ll> ans(q);
    rep(i, q) {
        int l, r;
        cin >> l >> r;
        ans[i] = magic[r] - magic[l];
    }
    for ( auto tmp_ans : ans ) {
        cout << tmp_ans << endl;
    }
    return 0;
}


Measured memory_bytes: 3328
N, Y = map(int, input().split())
for x in range(N+1):
	for y in range(N+1):
		if (N-x-y) < 0:
			continue
		total = 10000*x + 5000*y + 1000*(N-x-y)
		if total > Y:
			continue
		if total == Y:
			print(str(x)+" "+str(y)+" "+str(N-x-y))
			exit()
print(-1,-1,-1)

Measured memory_bytes: 3064
import math
a = int(input())
if ((a > 0) & (a < 100001)):
    data_size = int (math.log10(a) + 1)
    if a == 100000:
        print(90909)
    elif data_size == 5:
        print(a - 10000 + 1 + 909)
    elif data_size == 4:
        print(909)
    elif data_size == 3:
        print(a - 100 + 1 + 9)
    elif data_size == 2:   
        print(9)
    elif data_size == 1:   
        print(a - 1 + 1)

Measured memory_bytes: 3064
import java.util.*;
import static java.lang.Math.*;
import java.math.BigInteger;

public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		
		// 入力
		int n = sc.nextInt();
		int h = sc.nextInt();
		Integer[] a = new Integer[n];
		Integer[] b = new Integer[n];
		for(int i = 0; i < n; i++){
		    a[i] = sc.nextInt();
		    b[i] = sc.nextInt();
		}
		Arrays.sort(a);
		Arrays.sort(b);
		
		// 計算
		int result = 0;
		int maxA = a[n-1];
		Integer[] sumB = new Integer[n+1];
		sumB[0] = 0;
		for(int i = 0; i < n; i++){
		    sumB[i+1] = sumB[i] + b[i]; 
		}
		int index = upperBound(b, maxA);
		int x = sumB[n] - sumB[index];
		if(x < h){
		    result = n - index + (h-x+maxA-1)/maxA;
		}else{
		    int index2 = upperBound(sumB, sumB[n] - h);
		    result = n - index2 + 1;
		}
		
		// 出力
		System.out.println(result);
	}
	
	static int upperBound(Integer[] array, int n){
		int index = ~Arrays.binarySearch(array, n, (x,y) -> x.compareTo(y) > 0 ? 1 : -1);
		return index;
	}
}




Measured memory_bytes: 93764
import scala.io.StdIn

object Main extends App {
  
  val n = StdIn.readLine().toInt
  val a = StdIn.readLine().split(' ').map(_.toLong)
  
  def loop(ai: Array[Long], cnt: Long): Long = {
    //println(ai.toList)
    if(ai.forall(p => p % 2 == 0)){
      loop(ai.map(p => p / 2), cnt + 1)
    } else {
      cnt
    }
  }
  println(loop(a, 0))
}

Measured memory_bytes: 27592
A1 = list(map(int, input().split()))
A2 = list(map(int, input().split()))
A3 = list(map(int, input().split()))
Am = [A1[0], A2[1], A3[2]]
Al = [A1[2], A2[1], A3[0]]
n = int(input())
B = []
for k in range(n):
    b = int(input())
    B.append(b)
#タテ
for i in range(3):
    chk1 = A1[i]
    chk2 = A2[i]
    chk3 = A3[i]
    if chk1 in B:
        if chk2 in B:
            if chk3 in B:
                print('Yes')
                exit()

cnt = 0
for j in A1:
    if j in B:
        cnt += 1
if cnt == 3:
    print('Yes')
    exit()

cnt = 0
for j in A2:
    if j in B:
        cnt += 1
if cnt == 3:
    print('Yes')
    exit()

cnt = 0
for j in A3:
    if j in B:
        cnt += 1
if cnt == 3:
    print('Yes')
    exit()

cnt = 0
for j in Am:
    if j in B:
        cnt += 1
if cnt == 3:
    print('Yes')
    exit()

cnt = 0
for j in Al:
    if j in B:
        cnt += 1
if cnt == 3:
    print('Yes')
    exit()

print('No')

Measured memory_bytes: 3064
#include <iostream>
#include <set>
#include <algorithm>
using namespace std;
int main() {
  set<string> st;
  int n;
  string op, str;
  
  cin >> n;
  for(int i = 0; i < n; ++i) {
	cin >> op >> str;
	if(op == "insert") {
	  //	  v.push_back(str);
	  st.insert(str);
	}
	else { // find
	  if(st.find(str) != st.end()) {
		cout << "yes" << endl;
	  }
	  else {
		cout << "no" << endl;
	  }
	}
  }
  return 0;
}

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

using namespace std;

#define all(c)	(c).begin(),(c).end()
#define rall(c)	(c).rbegin(),(c).rend()
#define rep(i,N)	for(int i=0;i<N;++i)
#define pb	push_back
#define eb	emplace_back

using ll = long long;

constexpr ll INF = 0x1fffffffffffffff;
constexpr int inf = 0x1fffffff;
constexpr double inf_l = 1e18;
constexpr ll MOD = 1000000007LL;
constexpr int mod = 1000000007;

int main()
{
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
	set<char> dirs;
	string s;
	cin >> s;
	for (auto& c : s) {
		dirs.emplace(c);
	}
	map<char, char> rev;
	rev['N'] = 'S';
	rev['S'] = 'N';
	rev['W'] = 'E';
	rev['E'] = 'W';

	string d = "NSWE";
	for (int i = 0; i < 4; ++i) {
		if (dirs.find(d[i]) != dirs.end() && dirs.find(rev[d[i]]) == dirs.end()) {
			cout << "No" << endl;
			return 0;
		}
	}
	cout << "Yes" << endl;
	return 0;
}

Measured memory_bytes: 256