akhauriyash/Code-Regression huggingface dataset:
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

int compare(const void*a,const void *b) {
	return *(int*)a - *(int*)b;
}

int main() {
	const int ok = 1000;
	int n, x, y, cnt = 0;
	/*scanf("%d%d", &n, &t);
	for (int i = 0; i < n; i++) {
		int s;
		scanf("%d", &s);
		N[s] = ok;
	}
	for (int i = 0; i < t; i++) {
		int s;
		scanf("%d", &s);
		T[s] = ok;
	}

	for (int i = 0; i < 110; i++) if (N[i] == T[i] && N[i] == ok)printf("%d\n", i);*/
	
	scanf("%d", &n);
	for (int i = 0; i < n; i++) {
		scanf("%d%d", &x, &y);
		if (x == y) {
			cnt++;
			if (cnt == 3) {
				printf("Yes");
				return 0;
			}
		}
		else cnt = 0;
	}
	printf("No");
	return 0;
}

Measured memory_bytes: 1728
#include <stdio.h>
#define true 1
#define false 0
int S[50];
int solve(int,int,int);
int main(){
  int i,n;
int q,m;
scanf("%d",&n);
for(i=0;i<n;i++){
scanf("%d",&S[i]);
}
scanf("%d",&q);
for(i=0;i<q;i++){
scanf("%d",&m);
 if(solve(0,m,n)==true)printf("yes\n");
else printf("no\n");
}
return 0;
}

int solve(int i,int  m,int n){
  int res;
     if( m == 0)
       return true;
     if( i >= n)
       return false;
     res = solve(i + 1, m,n) || solve(i + 1, m - S[i],n);
return res;
}



Measured memory_bytes: 2104
package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
)

func scanInt() int {
	sc.Scan()
	i, _ := strconv.Atoi(sc.Text())
	return i
}

func scanInt64() int64 {
	sc.Scan()
	i, _ := strconv.ParseInt(sc.Text(), 10, 64)
	return i
}

func scanInts(n int) []int {
	res := make([]int, n)
	for i := 0; i < n; i++ {
		res[i] = scanInt()
	}
	return res
}

func scanInts64(n int) []int64 {
	res := make([]int64, n)
	for i := range res {
		res[i] = scanInt64()
	}
	return res
}

var sc = bufio.NewScanner(os.Stdin)

func main() {
	sc.Split(bufio.ScanWords)

	n, m, x := scanInt(), scanInt(), scanInt()

	c := make([]int, n)
	as := make([][]int, n)

	for i := 0; i < n; i++ {
		c[i], as[i] = scanInt(), scanInts(m)
	}

	INF := 100000000000000000
	min := INF
	for s := 0; s < (1 << n); s++ {
		costSum := 0
		smart := make([]int, m)
		for i := 0; i < n; i++ {
			if (s>>i)%2 == 0 {
				continue
			}
			costSum += c[i]
			for j := 0; j < m; j++ {
				smart[j] += as[i][j]

			}
		}
		ok := true
		for _, i := range smart {
			if i < x {
				ok = false
			}
		}
		if ok {
			if min > costSum {
				min = costSum
			}
		}
	}

	if min == INF {
		fmt.Println(-1)
		return
	}
	fmt.Println(min)
}


Measured memory_bytes: 2160
#include <cstdio>
int N, X, m[1001], min=100001, res;
int main(){
  scanf("%d %d", &N, &X);
  for(int i=0;i<N;i++){
    scanf("%d", &m[i]);
    if(min > m[i])min=m[i];
    X -= m[i];
  }
  while((X-min)>=0){
    X -= min;
    ++res;
  }
  printf("%d", res+N);
  return 0;
}

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

#define MAX_N 100
#define MAX_U 10000

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

	vector<int> v(n),w(n);	//??????n???vector?????£?¨?
	for(int i=0;i<n;i++){
		cin>>v[i]>>w[i];
	}
	
	//dp?????£?¨???¨?????????
	int dp[MAX_N+1][MAX_U+1];
	for(int i=0;i<MAX_N+1;i++){
		for(int j=0;j<MAX_U+1;j++){
			dp[i][j] = 0;
		}
	}
	
	//???????????§????????´??°
	for(int i=1;i<=n;i++){
		for(int j=1;j<=u;j++){
			if( j-w[i-1]>=0 ){	//j-w[i-1]???<0??\????????¨??????????????§????????????????????§?????§??????
				dp[i][j] = max( dp[i-1][j-w[i-1]]+v[i-1] , dp[i-1][j] );
			}
			else dp[i][j] = dp[i-1][j];
		}
	}
	
	cout<<dp[n][u]<<endl;
}

Measured memory_bytes: 7052
#include<iostream>
#include<queue>
#include<algorithm>
#include<functional>

using namespace std;

int main(){
  for(int N;cin>>N,N;){
    int ab[2][40000];
    for(int i=0;i<2;i++){
      for(int j=0;j<N;j++){
	cin>>ab[i][j];
      }
      sort(ab[i],ab[i]+N,greater<int>());
    }
    queue<int> que;
    int l=0;
    for(int i=0;i<N-1;i++){
      que.push(ab[1][i]);
      int f=que.front();
      if(ab[0][i]<=f){
	que.pop();
	l++;
      }else{
	l--;
	if(l<0){
	  cout<<i+1<<endl;
	  goto next;
	}
      }
    }
    cout<<"NA"<<endl;
  next:
    ;
  }
}

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

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

    for (int no = 1; no <= k; no++)
    {
        if (no % 2 == 1)
        {
            if (a % 2 == 1)
                a = a - 1;
            b = b + a / 2;
            a = a / 2;
        }
        else
        {
            if (b % 2 == 1)
                b = b - 1;
            a = a + b / 2;
            b = b / 2;
        }
    }

    cout << a << " " << b;

    return 0;
}

Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
#define rep(i,n) for(ll i=0;i<(ll)(n);i++)
#define all(a) (a).begin(),(a).end()
#define pb emplace_back
#define INF (1e9+1)

int main(){
    int n;
    string m;
    cin>>n>>m;
    
    if(m=="100")m = "101";
    cout<<m;
    rep(i,n)cout<<"00";
    cout<<endl;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
typedef vector<int> VI;
 
template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return 1; } return 0; }
#define _overload3(_1,_2,_3,name,...) name
#define _rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(int i=int(a);i<int(b);++i)
#define rep(...) _overload3(__VA_ARGS__,repi,_rep,)(__VA_ARGS__)
#define all(x) (x).begin(),(x).end()

const int mod=1e9+7;
 
int main(){
  int a,b;cin>>a>>b;
  cout<<max({a+b,a-b,a*b})<<endl;
}

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

#define watch(x) cerr << (#x) << ": " << (x) << endl

typedef long long LL;

LL a, v, b, w, t;

int main() {

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

    cin >> a >> v >> b >> w >> t;

    LL d = abs(a-b);
    LL dd = v-w;

    if(dd*t >= d) {
        cout << "YES\n";
    } else {
        cout << "NO\n";
    }
    
    return 0;
}


Measured memory_bytes: 3644
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define per(i, n) for (int i = (int)(n-1); i >= 0; i--)
#define sz(x) int(x.size())
#define all(x) (x).begin(), (x).end()
#define INF 2e9
typedef long long ll;
typedef pair<int, int> P;

int main() {
    int n; cin >> n;
    vector<int> a(n), b(n), c(n);
    rep(i, n) {
        cin >> a[i] >> b[i] >> c[i];
    }
    //dp[i][j] = i日目に活動jを行うときの最大幸福度
    vector<vector<int> > dp(n+1, vector<int>(3));
    dp[1][0] = a[0]; dp[1][1] = b[0]; dp[1][2] = c[0];
    for (int i=1; i<n; i++) {
        dp[i+1][0] = a[i] + max(dp[i][1], dp[i][2]);
        dp[i+1][1] = b[i] + max(dp[i][0], dp[i][2]);
        dp[i+1][2] = c[i] + max(dp[i][0], dp[i][1]);
    }

    int ans = max(dp[n][0], max(dp[n][1], dp[n][2]));
    cout << ans << endl;

}

Measured memory_bytes: 6912
#[allow(unused_macros)]
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

#[allow(unused_macros)]
macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

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

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

#[allow(unused_macros)]
macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

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

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

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

    ($next:expr, bytes) => {
        read_value!($next, String).into_bytes()
    };

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

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

fn main() {
    input! {
        n: usize,
        k: usize,
        h: [usize; n],
    }
    let mut h = h;
    h.sort();
    let mut result = h[n - 1];
    for i in 0..n - k + 1 {
        let d = h[i + k - 1] - h[i];
        if d < result {
            result = d;
        }
    }
    println!("{}", result);
}


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

int main(){
  int a,b,c;
  cin >> a >> b >> c;
  int sum1,sum2,sum3;
  sum1 = a+b;
  sum2 = b+c;
  sum3 = c+a;
  
  cout << min(sum1,min(sum2,sum3)) << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
typedef long long int ll;
typedef unsigned long long ull;
typedef long double ld;
#define mp make_pair
#define F first
#define S second
#define pb push_back
#define pll pair<ll,ll>
#define pii pair<int,int>
#define all(v) v.begin(),v.end()
const ll INF = ll(1e9);
const int N = 2e5 + 5;
const ll mod = 1000000007 ;
using namespace std;

ll binpow(ll x, ll y) {
	ll z = 1;
	while (y) {
		if (y % 2) z = (z * x) % mod;

		y = y / 2;
		x = (x * x) % mod;
	}
	return z % mod;
}

int main() {
#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif

	ios_base::sync_with_stdio(false);
	cin.tie(NULL), cout.tie(NULL);


	ll tc = 1;

//	cin >> tc;

	while (tc--) {

		ll n, k;
		cin >> n >> k;

		vector<ll> a(n + 1);
		ll mp[n + 1] = {0}, mapp[n + 1] = {0};

		for (int i = 1; i <= n; i++) {
			cin >> a[i];
		}


		if (k <= n) {
			ll tar = 1;

			for (int i = 1; i <= k; i++) {
				tar = a[tar];
			}
			cout << tar << endl;
			return 0;
		}

		ll tar;
		ll x = 1;
		vector<ll> seq;
		while (1) {
			if (mapp[x] == 1) {
				tar = x;
				break;
			}
			else {
				mapp[x]++;
				seq.pb(x);
				x = a[x];
			}
		}

		ll sub = 0;
		ll f = 1;
		std::vector<ll> ans;
		for (int i = 0; i < seq.size(); i++) {
			if (tar != seq[i] and f) {
				sub++;
			}
			else {
				f = 0;
				ans.push_back(seq[i]);
			}
		}

		ll p = k - sub;
		ll ind = p % ans.size();
		cout << ans[ind] << endl;
		return 0;


	}

}

Measured memory_bytes: 10880
<?php
 fscanf(STDIN,"%d",$n);
 $a_li = explode(" ",trim(fgets(STDIN)));
 $count_hen = array();
 foreach($a_li as $a){
   $count_hen[$a]++;
 }

krsort($count_hen);
$x = '';
$y = '';

//print_r($count_hen);
  foreach($count_hen as $k=>$c){
  if($c>=4 && $x==''){
    echo $k*$k;
    exit;
  }elseif($c>=2){
    if($x!='' && $y!=''){
      	break;
    }elseif($x==''){
      //echo "{$k}";
	    $x = $k;
    }else{
           // echo "{$k}\n";
      $y = $k;
      break;
    }
  }
}

if($y==''){
  echo "0";
}else{
	echo $x*$y;
}

Measured memory_bytes: 19444
import sys
input = sys.stdin.readline
sys.setrecursionlimit(pow(10, 6))


edges = []

def dfs(i):
    ret = 0
    tmp = []
    for j in edges[i]:
        tmp.append(dfs(j))
    for d, k in enumerate(reversed(sorted(tmp))):
        if ret < k+d+1:
            ret = k+d+1
    return ret


def main():
    global edges
    n = int(input())
    edges = [[] for _ in range(n+1)]
    for i in range(n-1):
        a = int(input())
        edges[a].append(i+2)
    print(dfs(1))


if __name__ == '__main__':
    main()


Measured memory_bytes: 118960
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
#define REP(i, a, b) for(int i = (a); i < (b); ++i) 

int main()
{
    int A, B;
    cin >> A >> B;
    A -= 1; if(A == 0) A += 13;
    B -= 1; if(B == 0) B += 13;
    if(A < B) cout << "Bob" << endl;
    else if(A > B) cout << "Alice" << endl;
    else cout << "Draw" << endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <cstdio>
#include <string>

#define rep(x,to) for(int x=0;x<to;x++)
#define rep2(x,from,to) for(int x=from;x<to;x++)

using namespace std;

//三角形面積（三点から）
double smen(double x1, double y1, double x2, double y2, double x3, double y3){
double wkk;
	
	wkk =((x3-x2) * (y1-y2) - (x1-x2) * (y3-y2) )* 0.5;
	if(wkk < 0) wkk *= -1;
	return wkk;
}


int main(void){

double xa,xb,xc,xd,ya,yb,yc,yd;
int cnt=0;
char k;
	while(!cin.eof() && cnt < 50){
		cin >> xa >> k >> ya >> k >> xb >> k >> yb >> k
		    >> xc >> k >> yc >> k >> xd >> k >> yd ;
		if(cin.eof()) break;
		 
		double s1 = smen(xa,ya,xb,yb,xc,yc);
		double s1b= smen(xa,ya,xc,yc,xd,yd);
		double s2 = smen(xa,ya,xb,yb,xd,yd);
		double s2b= smen(xb,yb,xc,yc,xd,yd);
		if(s1+s1b==s2+s2b) cout << "YES" << endl;
		else  cout <<  "NO" << endl;
//		cin.clear();
		cnt++;
	}
	return 0;
	
	
}

Measured memory_bytes: 1216
import java.util.*;

public class Main {

    static Scanner sc = new Scanner(System.in);

    public static void main(String[] args) {
        int N = sc.nextInt();
        int M = sc.nextInt();

        int[] cost = new int[] {0, 2 , 5 , 5 , 4 , 5 , 6 , 3 , 7 , 6};
        int[] nums = new int[M];
        for (int i = 0; i < M; i++) {
            nums[i] = sc.nextInt();
        }

        String[] dp = new String[N+100];
        dp[0] = "";
        for (int i = 0; i <= N; i++) {
            for (int j = 0; j < M; j++) {
                if (dp[i] == null) continue;
                dp[i + cost[nums[j]]] = max(dp[i + cost[nums[j]]], dp[i] + nums[j]);
            }
        }

        System.out.println(dp[N]);
    }

    private static String max(String a, String b) {
        if (a == null) {
            return b;
        } else if (a.length() < b.length()) {
            return b;
        } else if (a.length() == b.length()) {
            if (a.compareTo(b) < 0) {
                return b;
            }
        }
        return a;
    }
}

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

#define fastio ios_base::sync_with_stdio(false); cin.tie(NULL);
#define SUBL freopen("/home/ajinkya/Desktop/input.txt","r",stdin); freopen("/home/ajinkya/Desktop/output.txt","w",stdout); 
#define ll long long
#define ull unsigned long long
#define FI(i,a,n) for(int i=a; i<=n; i++)
#define RFI(i,n,a) for(int i=n; i>=a; i--)
#define FLL(i,a,n) for(ll i=a; i<=n; i++)
#define RFLL(i,n,a) for(ll i=n; i>=a; i--)
#define vi vector<int>
#define vll vector<ll>
#define all(v) v.begin(),v.end()
#define pll pair<ll,ll>
#define pi pair<int, int>
#define GCD(a,b) __gcd(a,b)
#define MP make_pair
#define PB push_back
#define PF push_front
#define LB lower_bound
#define UB upper_bound
#define debug(x) cout << x << endl
#define MOD 1000000007
#define INF LLONG_MAX
#define PI 3.14159265359
using namespace std;




int main()
{
    fastio 
    // SUBL
    int a, b;
  	cin >> a >> b;
  	cout << max(a+b,max(a-b,a*b));
    return 0;
}         	

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

using namespace std;

int main(){
    long long n;
    cin >> n;
    for(int s = (int)sqrt(n);s>0;--s){
        if(n%s==0){
            cout << (int)log10(n/s)+1;
            break;
        }
    }
    return 0;
}

Measured memory_bytes: 512
#include<bits/stdc++.h>
#define ll long long
#define inf 1000000000
#define infll 1000000000000000000ll
#define vi vector<int>
#define vll vector<ll>
#define pb push_back
#define pii pair<int,int>
#define pll pair<ll,ll>
#define pdd pair<double,double>
#define mpr make_pair
#define fi first
#define se second
#define pq priority_queue<int>
#define pqll priority_queue<ll>
#define up(x,y) (x<(y)?x=(y):0)
#define dn(x,y) (x>(y)?x=(y):0)
#define ad(x,y) (x=(x+(y))%mod)
#define N 2000009
using namespace std;

int n; char ch[N];
int main(){
	scanf("%s",ch+1); n=strlen(ch+1);
	int i,x=0,y=0; ll ans=0;
	for (i=1; i<=n; i++){
		if (ch[i]=='A'){
			ans+=(ll)x*y; y=0; x++;
		} else if (ch[i]=='C'){
			ans+=(ll)x*y; x=y=0;
		} else{
			if (ch[i+1]=='C'){ i++; y++; continue; }
			else{
				ans+=(ll)x*y; x=y=0;	
			}
		}
	}
	ans+=(ll)x*y;
	printf("%lld\n",ans);
	return 0;
}


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

namespace ALDS1_3D{
    public class Program{
        public struct Pool{
            public int Place;
            public int Area;
        }

        public static void Main(string[] args){
            var S = Console.ReadLine();

            var stkLeft = new Stack<int>();
            var stkPool = new Stack<Pool>();

            for(var i = 0; i < S.Length; i++){
                if(S[i] == '\\'){
                    stkLeft.Push(i);
                }
                else if(S[i] == '/' && stkLeft.Count > 0){
                    var left = stkLeft.Pop();
                    var right = i;

                    var place = left;
                    var area = right - left;

                    while(stkPool.Count > 0 && stkPool.Peek().Place > place){
                        area += stkPool.Pop().Area;
                    }

                    stkPool.Push(new Pool {Place = place, Area = area});
                }
            }

            Console.WriteLine(stkPool.Sum(p => p.Area));

            var res = stkPool.Count + " ";
            res += string.Join(" ", stkPool.Select(p => p.Area.ToString()).Reverse().ToArray());
            Console.WriteLine(res.Trim());
        }
    }
}

Measured memory_bytes: 10796
#include<iostream>
#include<vector>
using namespace std;
const int INF=1e9+7;

int D,G;
int p[100],c[100];
vector<bool> used(10,false);

int dfs(int cur,int score,int s){
    if(cur==D){
        int res=0;
        if(s!=-1){
            while(score<G&&res<p[s]){
            score+=(s+1)*100;
            res++;
          }
        }
        if(score<G) return INF;
        return res;
    }
    int res1,res2;
    res1=dfs(cur+1,score+(cur+1)*100*p[cur]+c[cur],s)+p[cur];
    res2=dfs(cur+1,score,cur);
    return min(res1,res2);
}

int main(){
    cin>>D>>G;
    for(int i=0;i<D;i++){
        cin>>p[i]>>c[i];
    }
    cout<<dfs(0,0,-1)<<endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<sstream>
#include<vector>
#include<iterator>
#include<utility>
#include<climits>
using namespace std;

const int inf = INT_MAX;
vector<int> pos;
vector<vector<pair<int, int>>> edge;

bool check(int src)
{
	for(int i=0; i<edge[src].size(); i++){
		int dst =edge[src][i].first;
		int d = edge[src][i].second;

		if(pos[dst] == inf){
			pos[dst] = pos[src] + d;

			if(check(dst) == false)
				return false;
		}
		else if(pos[dst] != pos[src]+d)
				return false;
	}

	return true;
}

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

	edge = vector<vector<pair<int, int>>>(N, vector<pair<int, int>>());
	for(int i=0; i<M; i++){
		int L, R, D;
		cin >> L >> R >> D;

		L--;
		R--;

		edge[L].push_back(make_pair(R, D));
		edge[R].push_back(make_pair(L, -D));
	}

	pos = vector<int>(N, inf);
	for(int i=0; i<N; i++){
		if(pos[i] != inf)
			continue;

		pos[i] = 0;
		if(check(i) == false){
			cout << "No" << endl;
			return 0;
		}
	}

	cout << "Yes" << endl;

	return 0;
}


Measured memory_bytes: 11008
# Your code here!
# 課題41 コッホ曲線
import math
def plot(x,y):
    print(f"{x:.8f} {y:.8f}")
    
def koch(n, x1,y1,x2,y2):
    if n==0:
        plot(x1,y1)
        return
    sx=(2*x1+x2)/3
    sy=(2*y1+y2)/3
    tx=(x1+2*x2)/3
    ty=(y1+2*y2)/3
    ux=(tx-sx)*(1/2)-(ty-sy)*(math.sqrt(3)/2)+sx
    uy=(tx-sx)*(math.sqrt(3)/2)+(ty-sy)*(1/2)+sy
    
    koch(n-1, x1,y1, sx,sy)
    koch(n-1, sx,sy, ux,uy)
    koch(n-1, ux,uy, tx,ty)
    koch(n-1, tx,ty, x2,y2)
    
n=int(input())
koch(n, 0,0, 100,0)
plot(100,0)
    
    


Measured memory_bytes: 5752
import java.util.*;

public class Main {

    public static void main(String[] args) {
        // write your code here
        Scanner sc = new Scanner(System.in);

        int n = sc.nextInt();
        String s = sc.next();

        String ans = "No";

        if (n % 2 == 0) {
            if (s.substring(0, n / 2).equals(s.substring(n / 2 ))) {
                ans = "Yes";
            }
        }

        System.out.println(ans);
    }
}

Measured memory_bytes: 21716
#include <iostream>
#include <fstream>

using namespace std;

int main()
{
    int a[2][100], n;
    cin >> n;
    for (int i = 0; i < 2; ++i)
        for (int j = 0; j < n; ++j)
            cin >> a[i][j];

    for (int i = 0; i < 2; ++i)
        for (int j = 0; j < n; ++j)
            a[i][j] += max((i - 1 >= 0 ? a[i - 1][j] : 0), (j - 1 >= 0 ? a[i][j - 1] : 0));

    cout << a[1][n - 1];
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define PI 3.14159265359
#define NIL (-1)
#define LL long long
using namespace std;
const int64_t MOD = 1e9 + 7;
const int INF = INT_MAX;

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

	string a, b;
	int m = S.size() / 2;

	if (S.size() & 1) {
		a = S.substr(0, m);
		b = S.substr(m + 1, m);
	}
	else {
		a = S.substr(0, m);
		b = S.substr(m, m);
	}
	reverse(b.begin(), b.end());

	int ans = 0;
	for (int i = 0; i < a.size(); i++) {
		if (a[i] != b[i]) ans++;
	}

	cout << ans << endl;
}

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

using namespace std;
using ll = long long;

int main() {
  ll N;
  cin >> N;
  vector<ll> d(N);
  for (int i = 0; i < N; ++i) {
    cin >> d[i];
  }
  sort(d.begin(),d.end());
  ll a= d[N/2-1], b=d[N/2];
  cout << b-a << endl;
}


Measured memory_bytes: 1024
import java.util.Scanner;

public class Main {
	public static void main(String args[]) {
		Scanner scan = new Scanner(System.in);
		String a = "ABC";
		if(scan.next().equals("ABC")) {
			a = "ARC";
			
		}
		
		
		
		System.out.println(a);
		
		
	}
		
		
		
}

Measured memory_bytes: 35648
#include <bits/stdc++.h>
#ifdef _DEBUG
#include "../../../debug_print.hpp"
#else
#define debug(...)
#endif
#define sort_(a) sort(a.begin(), a.end())
#define rsort(a) sort(a.rbegin(), a.rend())
#define rep(i, n) for (int i = 0; i < n; i++)
#define rrep(i, n) for (int i = n - 1; 0 <= i; i--)
#define for_(i, start, end) for (int i = start; i < end; i++)
#define rfor(i, start, end) for (int i = start - 1; 0 <= i; i--)
#define all(a) a.begin(), a.end()
using ll = long long;
using ld = long double;
using namespace std;
constexpr int INF32       = 1'050'000'000;
constexpr long long INF64 = 4'000'000'000'000'000'000;
constexpr int MOD7        = 1'000'000'007;
constexpr int MOD53       = 998'244'353;
constexpr double PI       = 3.14159265358979323846;
template <class T> inline bool chmin(T &a, T b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
}
template <class T> inline bool chmax(T &a, T b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}
void print() { std::cout << '\n'; }
template <class H, class... T> void print(H &&head, T &&... args) {
    std::cout << head;
    sizeof...(args) == 0 ? std::cout << "" : std::cout << ' ';
    print(std::forward<T>(args)...);
}
template <class T> void print(std::vector<T> &v) {
    for (int i = 0; i < v.size(); i++) {
        std::cout << v[i];
        i == v.size() - 1 ? std::cout << '\n' : std::cout << ' ';
    }
}
template <class T> void print(std::vector<std::vector<T>> &v) {
    for (int i = 0; i < v.size(); i++) {
        for (int j = 0; j < v[i].size(); j++) {
            std::cout << v[i][j];
            j == v[i].size() - 1 ? std::cout << '\n' : std::cout << ' ';
        }
    }
}
void scan() {}
template <class H, class... T> void scan(H &&head, T &&... args) {
    std::cin >> head;
    scan(std::forward<T>(args)...);
}
template <class T> void scan(std::vector<T> &v) {
    for (auto &&i : v) {
        scan(i);
    }
}

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

    int N, M;
    scan(N, M);
    if (N == M) {
        print("Yes");
    } else {
        print("No");
    }

    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <vector>
#include <cstring>
#include <map>
#include <set>
#include <queue>
#include <cstdio>
#include <cmath>
using namespace std;
typedef long long LL;

int n,k;

int main() {
	scanf("%d %d",&n,&k);
	LL ans=0;
	for(int b=k+1;b<=n;b++) {
		for(int i=0;i*b<=n;i++) {
			int x_low=max(k,-i*b+1);
			int x_up=min(b-1,n-i*b);
			ans+=max(0,x_up-x_low+1);
		}
	}
	printf("%lld\n",ans);
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0; i<(n); i++)
#define FOR(i,x,n) for(int i=x; i<(n); i++)
#define ALL(n) begin(n),end(n)
#define MOD 1000000007
 
typedef long long ll;
typedef unsigned int ui;
typedef unsigned long long ull;
template<class T>void print(T x){cout << x << endl;}
template<class T>void printvec(vector<T>& a){rep(i, a.size()-1){cout << a[i] << " ";} cout << a[a.size()-1] << endl;}
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
 
int main()
{
    int n; cin>>n;
    vector<vector<int>> a(3, vector<int>(n));
    rep(i, n) cin >> a[0][i] >> a[1][i] >> a[2][i];

    vector<vector<int>> dp(n+1, vector<int>(3, 0));
    rep(i, 3) dp[0][i]=0;

    FOR(i, 1, n+1){
        rep(j, 3){
            rep(k, 3){
                if(j==k) continue;
                chmax(dp[i][j], dp[i-1][k]+a[j][i-1]);
            }
        }
    }

    print(max(dp[n][0], max(dp[n][1], dp[n][2])));
    return 0;
}

Measured memory_bytes: 6904
package main

import (
	"bufio"
	"fmt"
	"io"
	"os"
	"strconv"
)

var sc *bufio.Scanner

func nextInt() int {
	sc.Scan()
	i, e := strconv.Atoi(sc.Text())
	if e != nil {
		panic(e)
	}
	return i
}

func ufRoot(e []int, x int) int {
	if e[x] == x {
		return x
	}
	return ufRoot(e, e[x])
}

func ufUnite(e []int, x int, y int) {
	rx := ufRoot(e, x)
	ry := ufRoot(e, y)
	if rx != ry {
		e[rx] = ry
		e[x] = ry
	}
}

func answer(reader io.Reader, writer io.Writer) {
	sc = bufio.NewScanner(reader)
	sc.Split(bufio.ScanWords)

	n := nextInt()
	m := nextInt()
	t := make([]int, n)
	for i := 0; i < n; i++ {
		t[i] = i
	}

	for i := 0; i < m; i++ {
		x := nextInt()
		y := nextInt()
		_ = nextInt()
		x--
		y--
		ufUnite(t, x, y)
	}
	//fmt.Printf("%v\n", t)
	count := 0
	for i := 0; i < n; i++ {
		if t[i] == i {
			count++
		}
	}
	_, _ = fmt.Fprintf(writer, "%d", count)
}

func main() {
	answer(os.Stdin, os.Stdout)
}


Measured memory_bytes: 2944
#include<bits/stdc++.h>
using namespace std;
using ll=long long;
int main(){
  ll n,m=10000000000,ans=0;
  cin>>n;
  vector<ll> a(n);
  for(ll i=0;i<n;i++){
    cin>>a[i];
  }
  sort(a.begin(),a.end());
  reverse(a.begin(),a.end());
  ans+=a[0];
  for(ll i=1;i<(n/2);i++){
    ans+=2*a[i];
  }if(n%2==1){
    ans+=a[n/2];
  }
  cout<<ans<<endl;
}

Measured memory_bytes: 4832
#include<iostream>
#include<cstdio>
#include<string>
#include<cmath>
#define loop(i,a,b) for(int i=a;i<b;i++)
#define rep(i,a) loop(i,0,a)
using namespace std;

int main(){
	int m,n;
	int max=0;
	int data;
	int ans[20][20];
	cin>>m>>n;
	rep(i,m){
		data=0;
		rep(j,n){
			cin>>ans[i][j];
			data+=ans[i][j];
			
		}	
//		cout<<data<<endl;
			if(max<data)max=data;
	}
	
	cout<<max<<endl;
}

Measured memory_bytes: 1164
#include<bits/stdc++.h>
using namespace std;
#define inf 1e9
#define ll long long
#define ull unsigned long long
#define M 1000000007
#define P pair<int,int>
#define FOR(i,m,n) for(int i=m;i<n;i++)
#define rep(i,n) FOR(i,0,n)
const int vx[4] = {0,1,0,-1};
const int vy[4] = {1,0,-1,0};
#define PI 3.14159265

string s;
string t="AKIHABARA";
map<string,bool> mp;

void search(string u,int m){
  if(u.size()>=9){
    mp[u]=true;
    return;
  }
  search(u+'A',m);
  search(u+s[m],m+1);
}


int main(){
  cin>>s;

  if(s.size()<10)
    search("",0);

  if(mp[t]){
    cout<<"YES"<<endl;
  }
  else{
    cout<<"NO"<<endl;
  }
  

  return 0;
}


Measured memory_bytes: 256
// include headers{{{
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>
/*}}}*/
# define rep(i, n) for (int i = 0; i < (int)(n); i++)
using namespace std;


int max(vector<int> & l) {
    int max = -1;
    rep (i, l.size()) {
        if (max < l[i]) max = l[i];
    }
    return max;
}


int sum(vector<int> & l) {
    int ans = 0;
    rep (i, l.size()) ans += l[i];
    return ans;
}


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

    vector<int> l(n);
    rep (i, n) cin >> l[i];

    int lmax = max(l);
    int lsum = sum(l) - lmax;

    if (lmax >= lsum) {
        cout << "No" << endl;
    }
    else {
        cout << "Yes" << endl;
    }

    return 0;
}



Measured memory_bytes: 888
#include <iostream>
#include <cstdio>
#include <string>
#include <algorithm>
#include <utility>
#include <cmath>
#include <vector>
#include <queue>
#include <set>
#include <map>
using namespace std;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
typedef vector<vector<pair<ll, ll>>> vvpll;
#define rep(i, n) for(ll i = 0; i < n; i++)
#define exrep(i, a, b) for(ll i = a; i <= b; i++)
#define out(x) cout << x << endl
#define exout(x) printf("%.10f\n", x)
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define pb push_back
#define re0 return 0
const ll mod = 1000000007;
const ll INF = 1e16;
const ll MAX_N = 100010;
 
int main() {
    ll n, U, V;
    cin >> n >> U >> V;
    U--;  V--;
 
    vvpll G(n);
    rep(i, n-1) {
        ll a, b;
        cin >> a >> b;
        a--;  b--;
        G[a].pb(make_pair(b, 1));
        G[b].pb(make_pair(a, 1));
    }
    
    vl distTaka(n, -1);  // distTaka[i] : 頂点iの頂点Uからの距離
    queue<ll> Qtaka;
    distTaka[U] = 0;
    Qtaka.push(U);
    while(!Qtaka.empty()) {
        ll v = Qtaka.front();
        Qtaka.pop();
        for(auto p : G[v]) {
            ll u = p.first;
            ll cost = p.second;
            if(distTaka[u] != -1) {
                continue;
            }
            distTaka[u] = distTaka[v] + cost;
            Qtaka.push(u);
        }
    }
    
    vl distAoki(n, -1);  // distAoki[i] : 頂点iの頂点Vからの距離
    queue<ll> Qaoki;
    distAoki[V] = 0;
    Qaoki.push(V);
    while(!Qaoki.empty()) {
        ll v = Qaoki.front();
        Qaoki.pop();
        for(auto p : G[v]) {
            ll u = p.first;
            ll cost = p.second;
            if(distAoki[u] != -1) {
                continue;
            }
            distAoki[u] = distAoki[v] + cost;
            Qaoki.push(u);
        }
    }
    
    ll ans = 0;
    rep(v, n) { 
        if(distTaka[v] < distAoki[v]) {
            chmax(ans, distAoki[v]);
        }
    }
    ans--;
    
    out(ans);
    re0;
}

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



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

string s; 
int n;
vector<int> ans;

int solve(int i) {
	if (ans[i] != -1) return ans[i];
	if (i == 0 && s[0] == '<') {
		ans[i] = 0; return 0;
	}
	if (i == n && s[n-1] == '>') {
		ans[i] = 0; return 0;
	}
	if (s[i-1] == '>' && s[i] == '<') {
		ans[i] = 0; return 0;
	}

	int rs = 0;
	if (i < n && s[i] == '>') {
		rs = max(rs, solve(i+1) + 1);
	}
	if (i > 0 && s[i-1] == '<') {
		rs = max(rs, solve(i-1) + 1);
	}
	return ans[i] = rs;
}

signed main() {
	ios::sync_with_stdio(0); cin.tie(0);
	
	cin >> s;
	n = s.size();
	ans.resize(n+1, -1);
	for (int i = 0; i <= n; i++) {
		solve(i);
	}

	long long rs = 0;
	for (int i: ans) rs += i;
	cout << rs;
	
	return 0;
}


Measured memory_bytes: 26268
#include <iostream>
#include <cmath>
#include <iomanip>
#include <limits>
#include <string>
#include <vector>
#include <algorithm>
#include <stack>
#include <queue>
#include <map>
using namespace std;

int main(){
    int n,a,b;
    string s;
    cin >> n >> a >> b >> s;
    int winner=0,foreign=0;
    for(int i=0;i<s.size();i++){
        if(s[i] == 'a'){
            if(winner < a+b){
                cout << "Yes" << endl;
                winner++;
            }
            else cout << "No" << endl;
        }
        else if(s[i] == 'b'){
            if(winner < a+b && foreign < b){
                cout << "Yes" << endl;
                winner++;
                foreign++;
            }
            else{
                cout << "No" << endl;
                foreign++;
            }
        }
        else cout << "No" << endl;
    }
}

Measured memory_bytes: 896
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#include <set>
#include <cmath>
#include <cstring>
#include <iomanip>
#include <random>
#include <chrono>
#include <queue>
#include <ctime>
using namespace std;
typedef long long ll;
typedef pair<int, int> PII;
typedef pair<ll, ll> PLL;
#define fs first
#define sc second
#define INF 1000000000
#define MOD 1000000007
#define EPS 0.00000001


vector<int> dy = {-1, 0, 1, 0};
vector<int> dx = {0, 1, 0, -1};

int main() {
    int H, W; cin >> H >> W;
    vector<string> V(H);
    for(string &s:V){
        cin >> s;
    }
    
    priority_queue<pair<int, PII>, vector<pair<int, PII>> ,greater<>> Q;
    for(int i=0; i<H; i++){
        for(int j=0; j<W; j++){
            if(V[i][j]=='#') Q.push(pair<int, PII>(0, {i, j}));
        }
    }
    
    int ans = 0;
    while(!Q.empty()){
        pair<int, PII> p = Q.top();
        Q.pop();
        int y = p.sc.fs;
        int x = p.sc.sc;
        int c = p.fs;
        ans = c;
        for(int i=0; i<4; i++){
            int ny = y + dy[i];
            int nx = x + dx[i];
            if(ny>=0 && ny<H && nx >=0 && nx<W && V[ny][nx]=='.'){
                V[ny][nx] = '#';
                Q.push(pair<int, PII>(c+1, {ny, nx}));
            }
        }
        
    }
    
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 15596
#include <iostream>
#include <stdio.h>
using namespace std;



int main(){
	int c[4][13]={0};
	string mark;
	int i,j;
	int n,a,m;	
	
	cin >> n; //総数

	for(i=0;i<n;i++){	
		cin >> mark; //任意
		cin >> a; //任意
	
		if(mark=="S"){
			m=0;
		}
		else if(mark=="H"){
			m=1;
		}
		else if(mark=="C"){
			m=2;
		}
		else if(mark=="D"){
			m=3;
		}
	
		c[m][a-1]=1;
	}
	
	for(i=0;i<=3;i++){
		for(j=0;j<=12;j++){
			if(c[i][j]==1){}
			else{
				
				if(i==0){
				cout << "S" << " " << j+1 << endl;
				}
				else if(i==1){
				cout << "H" << " " << j+1 << endl;
				}
				else if(i==2){
				cout << "C" << " " << j+1 << endl;
				}
				else if(i==3){
				cout << "D" << " " << j+1 << endl;
				}
			}
		}
	}
	
	return 0;
}

Measured memory_bytes: 1208
N = int(input())
a = list(map(int, input().split()))

Alice = 0
Bob = 0
cou = 1

for i in range(N):
    if cou % 2 != 0:
        Alice += max(a)
        a.remove(max(a))
    else:
        Bob += max(a)
        a.remove(max(a))
    cou += 1

print(Alice - Bob)

Measured memory_bytes: 3064
process.stdin.resume();
process.stdin.setEncoding('utf8');
process.stdin.on('data', function (inputString)
{
  const stringArray = inputString.split(' ');
  const W = Number(stringArray[0]);
  const H = Number(stringArray[1]);
  const x = Number(stringArray[2]);
  const y = Number(stringArray[3]);
  const r = Number(stringArray[4]);
  let result = 'No';
  
  if (x >= 0 && y >= 0) {
    if (x + r <= W && y + r <= H) {
      result = 'Yes';
    }
  }

  console.log(result);
});


Measured memory_bytes: 19332
#include<cstdio>
#include<algorithm>
#include<iostream>
using namespace std;
int n, m; int c[21]; int dp[50001];
void solve()
{
  for(int j=1; j<=n; j++)
  {
    for(int i=1; i<=m; i++)
    {
      if(j - c[i] >= 0)
      {
        dp[j] = min(dp[j], dp[j - c[i]] + 1);
      }
      else break;
    }
  }
  printf("%d\n", dp[n]);
}
int main()
{
  scanf("%d%d", &n, &m);
  for(int i=1; i<=m; i++)
  {
    scanf("%d", &c[i]);
  }
  c[0] = 0;
  sort(c, c+m+1);
  fill(dp, dp+n+1, (1<<30));
  dp[0] = 0;
  solve();

  return 0;
}



Measured memory_bytes: 3456
//============================================================================
// Name        : JOI.cpp
// Author      :
// Version     :
// Copyright   : Your copyright notice
// Description : Hello World in C++, Ansi-style
//============================================================================

#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <math.h>
#include <stdio.h>
#include <vector>
using namespace std;
typedef long long ll;
int N,M;
ll A[51],B[51],C[51],D[51];
int main(){
	cin>>N>>M;

	for(int i=1;i<N+1;i++){
		cin>>A[i]>>B[i];
	}
	for(int i=1;i<M+1;i++){
		cin>>C[i]>>D[i];
	}

	for(int i=1;i<N+1;i++){
		ll T=10000000000;
		int k=0;
		for(int j=1;j<M+1;j++){
			if(T>(abs(A[i]-C[j])+abs(B[i]-D[j]))){
				T=abs(A[i]-C[j])+abs(B[i]-D[j]);
				k=j;
			}
		}
		cout<<k<<endl;
	}

    return 0;
}


Measured memory_bytes: 256
A,B,C = map(int,input().split(" "))

cnt = 0
while True:
    if A % 2 == 1 or B % 2 == 1 or C % 2 == 1:
        print(cnt)
        exit(0)
    elif A == B == C:
        print("-1")
        exit(0)
    
    A , B, C = (B+C)//2,(A+C)//2,(A+B)//2
    cnt += 1



Measured memory_bytes: 38256
//	Totally unrelated and not AT ALL stolen from hohohaha's, generic_placeholder_name's or katoriyuu's template
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/trie_policy.hpp>
#include <ext/rope>

using namespace std;

#pragma GCC optimize("Ofast")
//#pragma GCC optimize("unroll-loops")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")

#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define eb emplace_back
#define gcd __gcd
#define rep(i,s,end) for(int i = (s); i <  (end); ++i)
#define rep0(i, end) for(int i =   0; i <= (end); ++i)
#define rep1(i, end) for(int i =   1; i <= (end); ++i)
#define lb lower_bound
#define ub upper_bound

#define vt vector
#define endl "\n"

#define fileopen(filename, in_type, out_type) if (fopen(filename in_type, "r")) {freopen(filename in_type, "r", stdin);freopen(filename out_type, "w", stdout);}
#define local_input(x) if (x && fopen("input.txt","r")) freopen("input.txt","r",stdin);
#define fastio ios_base::sync_with_stdio(false), cin.tie(NULL), cout.tie(NULL)

#define fscan(x)   scanf("%d",  &x)
#define fscandb(x) scanf("%lf", &x)
#define fscanll(x) scanf("%lld",&x)
//	Until next time, remember:
//			You are closer than you think.
//						_Dan Lok_

#define int ll
typedef double db;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<bool> vb;
typedef vector<pii> vpii;
typedef vector<pll> vpll;
#define pi 3.1415926535897932	
//	srand(chrono::steady_clock::now().time_since_epoch().count());
//	freopen("input.txt","r",stdin);

#define mn 100002
int n,m, root = 1;
int a[mn];
vi adjlist[mn];
void fuck_no(){cout << "NO"; exit(0);}

void dfs(const int& u, const int& p)
{
	if(adjlist[u].size() > 1){
		int sum = 0;
		for(int& i : adjlist[u]) if(i != p){
			dfs(i,u); sum += a[i];
			if(a[i] > a[u]) fuck_no();
		}
		int x = sum-a[u], y = a[u]-x;
		if(x < 0 || y < 0) fuck_no();
		a[u] = y;
	}
}

signed main()
{
	fastio;
	cin >> n; rep1(i,n){
		cin >> a[i];
	}
	if(n == 2){
		cout << (a[1] == a[2] ? "YES\n" : "NO\n");
		return 0;
	}
	rep(i,1,n){
		int x,y; cin >> x >> y;
		adjlist[x].pb(y), adjlist[y].pb(x);
		if(root == 1){
			if(adjlist[x].size() > 1) root = x;
			if(adjlist[y].size() > 1) root = y;
		}
	}
	dfs(root, 0);
	cout << (a[root] ? "NO\n" : "YES\n");
	return 0;
}
// with the aura of Dora, AC!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!1!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
// Why is there a one in my row of exclamation marks?


Measured memory_bytes: 16024
#include <iostream>

using namespace std;

int main(int argc, char **argv)
{
    int N;
    cin >> N;
    int A[N];
    for (int i = 0; i < N; ++i) cin >> A[i];

    int tlen = N * 2;
    int table[tlen];
    for (int i = 0; i < tlen; ++i) table[i] = 0;
    bool flag = true;
    for (int i = 0; i < N; ++i) {
        int h = A[i] % tlen;
        while(true) {
            if (table[h] == A[i]) {
                flag = false;
                break;
            }
            else if (table[h] == 0){
                table[h] = A[i];
                break;
            }
            else {
                h = (h + 1) % tlen;
            }
        }
        if (flag == false) break;
    }
    if (flag) cout << "YES";
    else cout << "NO";
    return 0;
}


Measured memory_bytes: 2560
#define _USE_MATH_DEFINES
#include  <iostream>
#include  <algorithm>
#include  <climits>
#include  <vector>
#include  <string>
#include  <cstring>
#include  <stack>
#include  <queue>
#include  <cmath>
#include  <iomanip>
#include  <set>
#include  <map>
#include  <new>
#include <cstdint>
#include <cctype>
using namespace std;
#define rep(i,n)  for(int i = 0; i < n; i++)
#define lrep(i,n,m)  for(int i = n; i < m; i++)

using ll = long long;
using Vii = vector<vector<int> >;
using Gjudge = vector<vector<bool>>;
using Vi = vector<int>;
using Vl = vector<ll>;
using Vll = vector<vector<ll> >;
using Vs = vector<string>;
using Vb = vector<bool>;
using the = pair<int, int>;
using lthe = pair<ll, ll>;

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

const int Mod = static_cast<int>(1e9 + 7);
const int INF = INT_MAX;
const int dx[4] = { -1,0,1,0 };
const int dy[4] = { 0,1,0,-1 };

int main() {
    int n, w;
    cin >> n >> w;
    Vl W(n), V(n);
    rep(i, n)  cin >> W[i] >> V[i];

    ll MAXV = (1e3 + 1) * n;
    Vll dp(n + 1, Vl(MAXV, 1LL << 60));
    //初期条件
    dp[0][0] = 0;

    for (int i = 0; i < n; i++) {
        for (int j = 0; j < MAXV; j++) {
            if (j - V[i] >= 0)  dp[i + 1][j] = min(dp[i][j], dp[i][j - V[i]] + W[i]);
            else dp[i + 1][j] = dp[i][j];
        }
    }

    ll ans = 0;
    for (ll j = 0; j < MAXV; j++) {
        if (dp[n][j] <= w)  ans = j;
        //cout << dp[n][j] << endl;
    }
    cout << ans << endl;
}


Measured memory_bytes: 80256
#include <bits/stdc++.h>
using namespace std;
int main(){
  string S,T;
  cin >> S >> T;
  bool answer= true;
  for(int i=0;i<S.size();i++){
    if(S.at(i)!=T.at(i)){
      answer=false;
    }
  }
  if(answer==true){
    cout << "Yes" << endl;
  }
  else{
    cout << "No" << endl;
  }
}

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

int H, W;
vector<vector<char>> s;
vector<vector<int>> d;

void Bfs() {
  d.resize(H, vector<int>(W, 1000000000));
  queue<pair<int, int>> q;

  q.push(pair<int, int>(0, 0));
  d[0][0] = 1;

  while (!q.empty()) {
    int i = q.front().first, j = q.front().second;
    q.pop();

    int di[4] = {1, 0, -1, 0}, dj[4] = {0, 1, 0, -1};
    for (int k = 0; k < 4; ++k) {
      int ni = i + di[k], nj = j + dj[k];
      if (ni >= 0 && ni < H && nj >= 0 && nj < W) {
        if (s[ni][nj] == '.' && d[i][j] + 1 < d[ni][nj]) {
          q.push(pair<int, int>(ni, nj));
          d[ni][nj] = d[i][j] + 1;
        }
      }
    }
  }
}

int main() {
  cin >> H >> W;
  s.resize(H, vector<char>(W));
  for (int i = 0; i < H; ++i)
    for (int j = 0; j < W; ++j)
      cin >> s[i][j];

  Bfs();

  int white = 0;
  for (int i = 0; i < H; ++i)
    for (int j = 0; j < W; ++j)
      if (s[i][j] == '.')
        ++white;

  if (d[H - 1][W - 1] != 1000000000)
    cout << white - d[H - 1][W - 1] << endl;
  else
    cout << -1 << endl;
}


Measured memory_bytes: 256
INF = 1001001001

def resolve():
  n, l = map(int, input().split())
  base = 0
  for i in range(1, n+1):
    base += l + i - 1

  ans = 0
  sa = INF

  for i in range(1, n+1):
    tmp = base - (l + i - 1)
    if abs(base - tmp) <= sa:
      ans = tmp
      sa = abs(base - tmp)
  print(ans)
  return

if __name__ == "__main__":
  resolve()


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

typedef long long ll;

deque<int> d;

int main(){
int n; cin >> n;
  for(int i=0;i<n;i++){
    int a; cin >> a;
    if( i&1 ) d.push_back( a );
    else d.push_front( a );
  }
  if( n &1 )
    for(int i=0;i<n;i++){
      if( i ) cout << " ";
      cout << d[i];
    }
  else
    for(int i=n-1;i>-1;i--){
      if( i < n-1 ) cout << " ";
      cout << d[i];
    }
 cout << endl;
}

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

int main() {
  int n,k;
  cin >> n >> k;
  vector<int> a(n);
  rep(i,n){
    cin >> a[i];
  }
  int ans = (n-1+k-2)/(k-1);
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); i++)
using namespace std;
using ll = long long;
using ld = long double;
const int INF = (1<<30)-1;
const long long LINF = (1LL<<62)-1;
const long double PI = acos(-1.0L);
const int dx[] = {-1, 0, 1, 0};
const int dy[] = {0, 1, 0, -1};
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }

signed main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int x, a, b;
  cin >> x >> a >> b;
  cout << (x-a)%b << endl;
  return 0;
}

Measured memory_bytes: 256
#include <iostream>
    #include <cstdlib>
    #include <string>
    #include <vector>
    #include <algorithm>
    #include <math.h>
    #include <list>
     
    using namespace std;
     
    int gcd(int a, int b) {
        int r;
        while (b != 0) {
            r = a % b;
            a = b; 
            b = r;
        }
        return a;
    }
    
    list<int> divisor(int m){
        list<int> l;
        int m_div = (int)(sqrt(m) + 2);
        for(int i=1; i<=m_div; ++i){
            if(m % i == 0){
                l.push_back(i);
                l.push_back(m / i);
            }
        }
        return l;
    }
     
     
    int main()
    {
        int n, m, ans, ans_tmp;
        list<int> l;
        cin >> n >> m;
        ans = 1;
        if(m % n == 0){
            ans = m / n;
        }
        else {
            l = divisor(m);
            for(auto itr=l.begin(); itr != l.end(); ++itr){
                if(*itr >= 1 && m - ((n - 1) * (*itr)) >= 1){
                    ans_tmp = gcd((*itr), m - ((n - 1) * (*itr)));
                    ans = (ans_tmp <= m / n) ? max(ans, ans_tmp) : ans;
                }
            }
        }
        cout << ans << endl;
    }

Measured memory_bytes: 256
#include<iostream>
#include<iomanip>
#include<limits>
#include<string>
#include<vector>
#include<algorithm>
#include<stdio.h>
#include<cmath>


using namespace std;

typedef unsigned long long ull;
typedef long long ll;

#define big ((ll)(1e9)+7)

int main()
{
   ll k,n;
   cin >> k >> n;
   vector<ll> a(n);
   for(ll i = 0;i < n;i++)
   {
     cin >> a[i];
   }
   vector<ll> b;
   for(ll i = 1;i < n;i++)
   {
     b.push_back(a[i]-a[i-1]);
   }
   ll num_f = k-a[n-1];
   ll num_l = a[0]-0;
   b.push_back(num_f+num_l);
  //  cout << num_f+num_l << endl;
  //  for(ll i = 0;i < n;i++)
  //  {
  //    cout << b[i] << " ";
  //  }
  //  cout << endl;
   sort(b.rbegin(),b.rend());
   ll ans = 0;
   for(ll i = 1;i < b.size();i++)
   {
     ans += b[i];
   }
   cout << ans << endl;
}


Measured memory_bytes: 3956
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <bitset>
#include <string>
#include <cmath>
#include <complex>
#include <numeric>
#include <cassert>

#include <vector>
#include <array>
#include <map>
#include <set>
#include <stack>
#include <queue>
#include <deque>
#include <utility>

#define int64 long long
#define uint64 unsigned long long
using namespace std;

int main()
{
	int64 aa, bb, cc, dd;
	cin >> aa >> bb >> cc >> dd;
	cout << max(aa * bb, cc * dd) << endl;
	return 0;
}


Measured memory_bytes: 3520