akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <string>
using namespace std;
int main(){
	int i,n;
	string s;
	cin >> n >> s;
	if(n&1){
		cout << "No" << endl;
	}else{
		string t;
		for(i=0;i<n/2;i++){
			t.push_back(s[i]);
		}
		t += t;
		if(s==t){
			cout << "Yes" << endl;
		}else{
			cout <<"No" << endl;
		}
	}
}

Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <vector>
#include <algorithm>
#include <cstring>
#include <map>
#include <queue>
#include <cmath>
#include <complex> // complex<double> a(1.2 , 2.3);// real(): 1.2, imag()2.3
using namespace std;

#define MOD 1000000007
#define ll long long
#define ld long double
#define FOR(i,a,b) for(ll i=(ll)a;i<(ll)b;i++)
#define rep(i,n) FOR(i,0,n)
#define pb push_back
#define mp make_pair
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define rmsame(a) sort(all(a)),a.erase(unique(all(a)), a.end())
#define rmvector(a,b) rep(i,a.size())rep(j,b.size())if(a[i]==b[j]){a.erase(a.begin()+i);i--;break;}
#define pq_pair_tB priority_queue <pair<ll,ll>, vector<pair<ll,ll> > , greater<pair<ll,ll> > > 
#define pq_pair_ts priority_queue <pair<ll,ll> > //第二成分の大きさが関係ない
template<typename X> bool exist(vector<X> vec, X item){return find(all(vec), item)!=vec.end();}
ll gcd(ll a, ll b){if(b==0)return a;return gcd(b,a%b);}
ll lcm(ll a, ll b){return a/gcd(a,b)*b;}

map<ll,vector<ll> > road;
char place[100005];
vector<ll> trace[2];

void cal(ll p){
    ll si = trace[p].size();
    rep(i, si){
        ll aim = trace[p][0];
        rep(j, road[aim].size()){
            ll des = road[aim][j];
            if(place[des] != ' ') continue;
            // else
            if(p == 0) place[des] = 'f';
            else place[des] = 's';
            trace[p].pb(des);
        }
        trace[p].erase(trace[p].begin()+0);
    }
}

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    rep(i,100005) place[i] = ' ';
    ll N ; cin >> N ;
    rep(i,N-1){
        ll a, b;
        cin >> a >> b ;
        a--, b--;
        road[a].pb(b);
        road[b].pb(a);
    }
    
    // 始めに1番のマスは黒く、N番のマスは白く塗られている。
    trace[0].pb(0); place[0] = 'f';
    trace[1].pb(N-1);place[N-1] = 's';
    
    while(trace[0].size() + trace[1].size()){
        cal(0);
        cal(1);
    }
    
    ll ans = 0;
    rep(i,N){
        if(place[i] == 'f') ans++;
        else ans--;
    }
    if(ans > 0) cout << "Fennec" << endl;
    else cout << "Snuke" << endl;
    
    //cout << fixed << setprecision(16) << ans << endl;
    return 0;
}


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

int main()
{
    int w, h;
    while (cin >> h >> w) {
        if (h == 0 && w == 0) break;

        for (int i = 0; i < h; i++) {
            for (int j = 0; j < w; j++) {
                cout << '#';
            }
            cout << endl;
        }
        cout << endl;
    }
}



Measured memory_bytes: 3104
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
const int INF = (1<<30);
const ll INFLL = (1ll<<60);
const ll MOD = (ll)(1e9+7);

#define l_ength size

void mul_mod(ll& a, ll b){
	a *= b;
	a %= MOD;
}

void add_mod(ll& a, ll b){
	a = (a<MOD)?a:(a-MOD);
	b = (b<MOD)?b:(b-MOD);
	a += b;
	a = (a<MOD)?a:(a-MOD);
}



int n,a[5555],b[5555];
ll d[2525],c[5555];
bool visited[2525],cycle[2525];

int main(void){
	int m,i,cnt=0,j;
	bool update;
	ll p;
	fill(d,d+2525,INFLL);
	visited[1] = true; d[1] = 0ll;
	cin >> n >> m >> p;
	for(i=0; i<m; ++i){
		cin >> a[i] >> b[i] >> c[i];
		c[i] = p - c[i];
	}
	while(true){
		update = false;
		for(i=0; i<m; ++i){
			if(d[b[i]]>d[a[i]]+c[i]){
				update = true;
				d[b[i]] = d[a[i]]+c[i];
			}
			if(visited[a[i]]){
				visited[b[i]] = true;
			}
		}
		if(!update){
			break;
		}
		if(cnt > n){
			break;
		}
		++cnt;
	}
	for(j=0; j<n; ++j){
		for(i=0; i<m; ++i){
			if(d[b[i]]>d[a[i]]+c[i]){
				d[b[i]] = d[a[i]]+c[i];
				if(visited[a[i]]){
					cycle[b[i]] = true;
				}
			}
			if(cycle[a[i]] && visited[a[i]]){
				cycle[b[i]] = true;
			}
		}
	}
	if(cycle[n]){
		cout << -1 << endl;
		return 0;
	}
	cout << max(-d[n],0ll) << endl;
	return 0;
}


Measured memory_bytes: 384
/* ＵＴＦ－８ */
#include <iostream>
#include <string>
#include <vector>
#include <deque>
#include <list>
#include <set>
#include <unordered_set>
#include <map>
#include <unordered_map>
#include <array>
#include <queue>
#include <stack>
#include <algorithm>
#include <tuple>
#include <numeric>
#include <type_traits>
#include <limits>

#include <stdio.h>
#include <unistd.h>
#include <fcntl.h>
#include <string.h>

#define USE_COLORED 1

#ifdef USE_COLORED
static const char stdout_pre[]  = "\033[1m"; // bold black
static const char stderr_pre[]  = "\033[31;1m"; // bold red
static const char stdxxx_post[] = "\033[m";

// 当然ながら GCC(g++)/libstdc++ 依存
#include <ext/stdio_filebuf.h>
using stdio_filebuf = __gnu_cxx::stdio_filebuf<char>;
class colored_stdio_filebuf : public stdio_filebuf {
private:
	const char* const pre_;
	const char* const post_;

public:
	colored_stdio_filebuf(FILE* fp, const char* pre, const char* post) : stdio_filebuf(fp, std::ios_base::out), pre_(pre), post_(post)
	{
	}

protected:
	std::streamsize xsputn(const char* s, std::streamsize count) override
	{
		stdio_filebuf::xsputn(pre_, strlen(pre_));
		auto ret = stdio_filebuf::xsputn(s, count);
		stdio_filebuf::xsputn(post_, strlen(post_));
		return ret;
	}
};
#endif

int main()
{
#ifdef USE_COLORED
	if (getenv("DEBUG")) {
		std::cout.rdbuf(new colored_stdio_filebuf(stdout, stdout_pre, stdxxx_post));
		std::cerr.rdbuf(new colored_stdio_filebuf(stderr, stderr_pre, stdxxx_post));
	} else
#endif
	{
		int fd = open("/dev/null", O_WRONLY);
		dup2(fd, 2);
		close(fd);
	}
	
	int N;
	int A = 0;
	std::cin >> N;
	int a;
	for (int i = 0; i < N; ++i) {
		std::cin >> a;
		A |= a;
	}
	int result = 0;
	while (A % 2 == 0) {
		++result;
		A /= 2;
	}
	std::cout << result << "\n";
}


Measured memory_bytes: 256
#include<iostream>
#include<map>
#include<set>
#include<string>
#include<algorithm>
#include<cmath>
#include<vector>
#include<queue>
#include<stack>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef int itn;

const int inf = 99999999;
const ll linf = 999999999999999999;
const double pi = acos(-1);
const int dx[4]={1,0,-1,0};
const int dy[4]={0,1,0,-1};

#define p_queue(i) priority_queue<i> 
#define rp_queue(i) priority_queue<i, vector<i>, greater<i>> 
#define P(p) cout<<(p)<<endl
#define rep(i,m,n) for(int i = (m); i < (int)(n); i++)
#define mod(i) ((i)%(ll)(1e9 + 7))
#define divm(a,b) (mod(a * modpow((ll)b,(ll)(1e9+5))))
#define rsort(a,b,c) sort(a, b, greater<c>())
#define vsort(v) sort(v.begin(), v.end());
#define rvsort(v) sort(v.end(), v.begin());
#define ft first
#define sd second
#define pb push_back
#define it insert
#define sz(x) ((int)(x).size())
#define lb(a,n,k) (lower_bound(a,a+n,k) - a) 
#define vlb(a,k)  (lower_bound(a.begin(),a.end(),k) - a.begin())
#define YES cout<<"YES"<< endl
#define NO cout<<"NO"<<endl
#define Yes cout<<"Yes"<<endl
#define No cout<<"No"<<endl  
#define yes cout<<"yes"<<endl
#define no cout<<"no"<<endl
#define ret return

ll modpow(ll i,ll j){ ll tmp=1; while(j){ if(j%2)tmp=mod(tmp*i);i=mod(i*i);j/=2;}return tmp;}
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; }

//ll ncr[100][100];
//ll nCr(int n, int r){if(n==r) ret ncr[n][r] = 1; if(r==0) ret ncr[n][r] = 1; if(r==1) ret ncr[n][r] = n;if(ncr[n][r]) ret ncr[n][r]; ret ncr[n][r] = nCr(n-1,r) + nCr(n-1,r-1);}

//ll npr[100][100]={};
//ll nPr(int n,int r){if(npr[n][r])ret npr[n][r];if(r==0)ret npr[n][r] = 1;if(r==1)ret npr[n][r] = n;ret npr[n][r] = n * nPr(n-1,r-1);}

//ll nHr(int n,int r){ret nCr(n+r-1,r);}

///////////////////////////////////////////////////////////////////////////



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

	ll ans = 1;

	rep(i,0,n){
        ll t;
        cin >> t;
        ans = lcm(ans,t);
	}
	P(ans);

	return  0;
}

Measured memory_bytes: 256
N = int(input())
lisA = list(map(int,input().split()))

dic = {}

for num in lisA:
    if num in dic:
        dic[num] += 1
    else:
        dic[num] = 1

for i in range(N):
    if i+1 in dic:
        print(dic[i+1])
    else:
        print(0)


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

int main() {

  vector<int> x(5); 
  cin >> x.at(0) >> x.at(1) >> x.at(2) >> x.at(3) >> x.at(4);
  rep(i,5)
  {
    if(x.at(i) == 0)
    {
      cout << i+1 << endl;
      break;
    }
  }
}


Measured memory_bytes: 3588
using System;

namespace B
{
    class Program
    {
        static void Main(string[] args)
        {
            string s = Console.ReadLine();
            int min = 1001001001;
            int n = s.Length;
            for(int i = 0; i < n-2; i++)
            {
                int tmp = (s[i] - '0') * 100 + (s[i + 1] - '0') * 10 + (s[i+2]-'0');
                min = (int)Math.Min(min, Math.Abs(tmp-753));
            }
            Console.WriteLine(min);
        }
    }
}


Measured memory_bytes: 25928
H,W,h,w=gets.split.map &:to_i;X=1000
m=H.times.map{[X]*W}
(h-1).step(H-1,h){|i|(w-1).step(W-1,w){|j|m[i][j]=-(h*w-1)*X-1}}
s=0
H.times{|i|W.times{|j|s+=m[i][j]}}
puts *[s>0 ? ['Yes',*m.map{|e|e*' '}] : ['No']]

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

int main() {

	int a,b,c=0;
	int counter=0;

	cin >> a >> b >> c;

	for(int i = a; i<b+1; i++){
		if(c % i == 0){
			counter++;
		}
	}

	cout << counter << endl;
  return 0;
}


Measured memory_bytes: 3100
#include<stdio.h>
int main()
{
  int n, d, x, y, z;
  scanf("%d %d", &n, &d);
  x=2*d+1;
  y=n/x;
  z=n%x;
  if(z==0)
    printf("%d\n", y);
  else
    printf("%d\n", y+1);
  return 0;
}

Measured memory_bytes: 128
import sys

class Card:
	def __init__(self, card):
		self.card = card
		self.mark = card[0]
		self.value = int(card[1])

	def __str__(self):
		return self.card

def print_arr(arr1, arr2):
	n = len(arr1)
	stable = True
	for i in range(n):
		if arr2 != None and arr1[i].card != arr2[i].card: stable = False
		sys.stdout.write(str(arr1[i]))
		if i != n - 1:
			sys.stdout.write(' ')
	print()
	return stable

def swap(arr, i, j):
	temp = arr[i]
	arr[i] = arr[j]
	arr[j] = temp

def bubble_sort(arr):
	n = len(arr)
	for i in range(0, n):
		for j in range(n - 1, i, -1):
			if arr[j].value < arr[j - 1].value:
				swap(arr, j, j - 1)

def selection_sort(arr):
	n = len(arr)
	for i in range(n):
		minj = i
		for j in range(i, n):
			if arr[j].value < arr[minj].value:
				minj = j
		if minj != i:
			swap(arr, i, minj)

n = int(input())
arr = list(map(str, input().split()))
cards1 = [None] * n
cards2 = [None] * n
for i in range(n):
	cards1[i] = Card(arr[i])
	cards2[i] = Card(arr[i])

bubble_sort(cards1)
selection_sort(cards2)

print_arr(cards1, None)
print('Stable')

stable = print_arr(cards2, cards1)
if stable == True:
	print('Stable')
else:
	print('Not stable')



Measured memory_bytes: 5624
N = int(input())
place = [[0,0,0]] + [list(map(int, input().split())) for i in range(N)]

def canMove():
    for i in range(1, N+1):
        t = place[i][0] - place[i-1][0]
        x = place[i][1] - place[i-1][1]
        y = place[i][2] - place[i-1][2]
        if x + y <= t and (t -x-y)%2 == 0:
            continue
        else:
            return "No"
    return "Yes"

print(canMove())

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

int dp[1001][1001];

int main(){
  int q,xl,yl;
  char X[1001],Y[1001];

  cin >> q;

  for (int i=0;i<q;i++){
    cin >> X >> Y;

    xl=strlen(X);
    yl=strlen(Y);
  
    for (int i=1;i<=xl;i++)dp[0][i]=0;
    for (int i=1;i<=yl;i++)dp[i][0]=0;
    for (int i=0;i<yl;i++)
      for (int j=0;j<xl;j++){
	if (X[j]==Y[i]){
	  dp[i+1][j+1]=dp[i][j]+1;
	}else{
	  if (dp[i+1][j]>dp[i][j+1])
	    dp[i+1][j+1]=dp[i+1][j];
	  else
	    dp[i+1][j+1]=dp[i][j+1];	    
	}
      }
    cout << dp[yl][xl]<<endl;
    
  }
  
  return 0;
}

Measured memory_bytes: 6892
from collections import defaultdict
n = int(input())
s = tuple(input() for _ in range(n))

cnt_dict = defaultdict(int)
cnt_max = 0
for si in s:
    cnt_dict[si] += 1
    cnt_max = max(cnt_max, cnt_dict[si])

ans = [key for key in cnt_dict if cnt_dict[key] == cnt_max]
ans.sort()
print(*ans, sep='\n')


Measured memory_bytes: 35936
//wxlcoder
#include <iostream>
#include <algorithm>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <cctype>
#include <string>
#include <numeric>
#include <utility>
#include <queue>
#include <memory>
#include <vector>
#include <stack>
#include <set>
#include <map>
#include <bitset>
#include <cstdlib>
#include <list>
#include <limits.h>
#include <utility>
#include <functional>
#include <iterator>
#include <deque>
#define MOD9 1000000009ll
#define MOD7 1000000007ll
#define MOD
#define INF  1023456789ll
#define INF16 10000000000000000ll
#define EPS 1e-9
#define PI 3.1415926535897932384626433832795
#define MAXN 10010
#define MAXM
using namespace std;
/*********default*********/
char a[110][110];
int main()
{
	int n, m;
	
	scanf("%d%d", &n, &m);
	for (int i = 0; i < n; i++) {
		scanf("%s", a[i]);
	}
	for (int i = 0; i < m + 2; i++) {
		putchar('#'); 
	}
	puts(""); 
	for (int i = 0; i < n; i++) {
		putchar('#');
		printf("%s", a[i]);
		putchar('#');
		puts(""); 
	}
	for (int i = 0; i < m + 2; i++) {
		putchar('#'); 
	}
	puts(""); 
 } 

Measured memory_bytes: 256
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.HashSet;
import java.util.Scanner;
import java.util.Set;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        Scanner in = new Scanner(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        TaskC solver = new TaskC();
        solver.solve(1, in, out);
        out.close();
    }

    static class TaskC {
        public void solve(int testNumber, Scanner in, PrintWriter out) {
            int n = in.nextInt();
            Set<Integer> s = new HashSet<>();
            for (int i = 0; i < n; i++) {
                int a = in.nextInt();
                if (s.contains(a)) {
                    s.remove(a);
                } else {
                    s.add(a);
                }
            }
            out.println(s.size());
        }

    }
}



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

using namespace std;
int n,m;
vector <int> a[100001];
int d[100001];
int kq;
int d__p(int u)
{
    if(d[u]!=-1)
        return d[u];
    int res=1;
    for(auto v:a[u])
    {
        res=max(res,d__p(v)+1);
    }
    kq=max(kq,res);
    return d[u]=res;
}
int main()
{
    cin>>n>>m;
    for(int i=1;i<=m;i++)
    {
        int u,v;
        cin>>u>>v;
        a[u].push_back(v);
    }
    for(int i=1;i<=n;i++)
        d[i]=-1;
    for(int i=1;i<=n;i++)
    {
        if(d[i]==-1)
            d__p(i);
    }
    cout<<kq-1;
    return 0;
}


Measured memory_bytes: 8192
#include <iostream>
#include <cstdio>
#include <string>
#include <cstring>
#include <algorithm>
#include <cmath>
#include <vector>
#include <queue>
#define pb push_back
using namespace std;
typedef pair<int,int> pii;

int main(){
  int d;
  cin>>d;
  if(d==25) cout<<"Christmas";
  if(d==24) cout<<"Christmas Eve";
  if(d==23) cout<<"Christmas Eve Eve";
  if(d==22) cout<<"Christmas Eve Eve Eve";
  cout<<endl;
  return 0;
}


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

int main() {
    int64_t n;
    cin >> n;
    vector<int64_t> h(n);
    for (auto& e : h) cin >> e;
    string ans = "Yes";
    for (int i = n - 1; i - 1 >= 0; i--) {
        if (h[i-1] - h[i] == 1) h[i-1]--;
        if (h[i-1] - h[i] > 1) ans = "No";
    }
    cout << ans << endl;
}


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

const int INF = 1e9;
const int N = 110;
const int dx[2] = {1,0};
const int dy[2] = {0,1};

char board[N][N];
int dp[N][N];

signed main() {
    int h,w;
    cin >> h >> w;
    rep(i,h) rep(j,w) cin >> board[i][j];
    rep(i,N) rep(j,N) dp[i][j] = INF;

    if(board[0][0] == '#') dp[0][0] = 1;
    else dp[0][0] = 0;

    queue<P> que;
    que.push({0,0});
    while(!que.empty()){
        int x = que.front().first;
        int y = que.front().second;
        que.pop();
        if(x == h - 1 && y == w - 1) break;

        int add = 0;
        rep(i,2){
            int nx = x + dx[i];
            int ny = y + dy[i];
            if(nx >= h || ny >= w) continue;

            if(board[x][y] == '.' && board[nx][ny] == '#') add = 1;
            else add = 0;

            if(dp[x][y] + add < dp[nx][ny]){
                dp[nx][ny] = dp[x][y] + add;
                que.push({nx,ny});
            }
        }

    }

    cout << dp[h - 1][w - 1] << endl;
}

Measured memory_bytes: 256
#include <stdio.h>
long long a [100010];
int main (){
int n;
scanf("%d",&n);
for(int i=0;i<n;i++) scanf("%lld",&a[i]);
int zero =0;

for(int i=0;i<n;i++)if(a[i]==0) zero ++;
if(zero >0){
// a[i] contains 0
printf("0\n");
return 0;
}
long long prod =1;
for(int i=0;i<n;i++){
if(a[i ] <=1000000000000000000/ prod ){
// This condition is equivalent to prod*a[i] <=10ˆ18
prod *=a[i];
}else{
printf("-1\n");
return 0;
}
}
printf("%lld\n",prod );
}


Measured memory_bytes: 2464
#from statistics import median
#import collections
#aa = collections.Counter(a) # list to list || .most_common(2)で最大の2個とりだせるお a[0][0]
from fractions import gcd
from itertools import combinations,permutations,accumulate, product # (string,3) 3回
#from collections import deque
from collections import deque,defaultdict,Counter
import decimal
import re
import math
#import bisect
#
#    d = m - k[i] - k[j]
#    if kk[bisect.bisect_right(kk,d) - 1] == d:
#
#
#
# pythonで無理なときは、pypyでやると正解するかも！！
#
#
# my_round_int = lambda x:np.round((x*2 + 1)//2)
# 四捨五入g
import sys
sys.setrecursionlimit(10000000)
#mod = 10**9 + 7
#mod = 9982443453
mod = 998244353
def readInts():
  return list(map(int,input().split()))
def I():
  return int(input())
#from statistics import median
#import collections
#aa = collections.Counter(a) # list to list || .most_common(2)で最大の2個とりだせるお a[0][0]
from fractions import gcd
from itertools import combinations,permutations,accumulate, product # (string,3) 3回
#from collections import deque
from collections import deque,defaultdict,Counter
import decimal
import re
import math
#import bisect
#
#    d = m - k[i] - k[j]
#    if kk[bisect.bisect_right(kk,d) - 1] == d:
#
#
#
# pythonで無理なときは、pypyでやると正解するかも！！
#
#
# my_round_int = lambda x:np.round((x*2 + 1)//2)
# 四捨五入g
import sys
sys.setrecursionlimit(10000000)
mod = 10**9 + 7
#mod = 9982443453
#mod = 998244353
def readInts():
  return list(map(int,input().split()))
def I():
  return int(input())
n = I()
import math
root = int(math.sqrt(n))+1
ans = float('inf')
for i in range(1,root+1):
    if n%i == 0:
        left = i
        right = n//i
        ll = len(str(left))
        lr = len(str(right))
        lm = max(ll,lr)
        ans = min(ans,lm)
print(ans)


Measured memory_bytes: 10432
/*input
2 2 2 8
4 6
1 5
3 8
*/

#include <algorithm>
#include <iostream>
#include <string.h>
#include <stdlib.h>
#include <iomanip>
#include <utility>
#include <vector>
#include <math.h>
#include <queue>
#include <stack>
#include <map>
#include <set>

using namespace std;

#define pb          push_back
#define pp          pop_back
#define nl          cout << "\n"
#define MIN(con)    (*min_element(ALL(con)))
#define MAX(con)    (*max_element(ALL(con)))
#define NX(cont)    next_permutation(ALL(cont))
#define PX(cont)    prev_permutation(ALL(cont))
#define prec(n)     cout << fixed << setprecision(n)
#define PI          3.14159265358979323846264338327951
#define all(c)      c.begin(),c.end()
#define rep(i,a,b)  for(ll i=a;i<b;i++)
#define sp          cout << " "
#define ifalse      ios_base::sync_with_stdio(false),cin.tie(NULL)
#define debug(x)    cout << #x << " = " << x << "\n";

using ll = long long;
using ld = long double;
 
template <typename T> T GCD(T a, T b) { ll t; while(a){ t=a; a=b%a; b=t; } return b; }
template <typename T> T LCM(T a, T b) { return (a*b) / GCD(a, b); }
template <typename T> string toString(T a) { return to_string(a); }
template <typename T> void toInt(string s, T &x) { stringstream str(s); str >> x; }

ll add(ll x, ll y, ll MOD) { x += y; if(x >= MOD) x -= MOD; return x; }
ll sub(ll x, ll y, ll MOD) { x -= y; if(x < 0) x += MOD; return x; }
ll mul(ll x, ll y, ll MOD) { return ((x % MOD) * (y % MOD)) % MOD; }

ll powr(ll a, ll b, ll MOD) {
  ll x = 1LL;
  while(b) {
    if(b & 1) x = mul(x, a, MOD);
    a = mul(a, a, MOD);
    b >>= 1;
  }
  return x;
}

ll inv(ll a, ll MOD) { return powr(a, MOD-2, MOD); }
const ll INF =  1e18;
const int SINF = 1e9;
const ll MOD = 1e9 + 7;

bool check(ll n)
{
  if(n == 1) return 0;
  if(n == 2 or n == 3) return 1;
  if(n%2 == 0 or n%3 == 0) return 0;
  for(ll i = 5; i*i <= n; i += 6) if(n%i == 0 or n % (i+2) == 0) return 0;
  return 1;
}

/************************************START***************************************/
const int N = 100005;

int main()
{
  ifalse;
  int x, y, z, k;
  cin >> x >> y >> z >> k;
  vector < ll > v1(x), v2(y), v3(z);
  for(auto &x: v1) {
    cin >> x;
  } 

  for(auto &x: v2) {
    cin >> x;
  } 

  for(auto &x: v3) {
    cin >> x;
  } 


  vector < ll > v;
  for(int i = 0; i < x; i ++) {
    for(int j = 0; j < y; j ++) {
      v.pb(v1[i] + v2[j]);
    }
  }
  sort(all(v));
  reverse(all(v));

  vector < ll > v4;
  for(int i = 0; i < min(k, int(v.size())); i ++) {
    for(int j = 0; j < z; j ++) {
      v4.pb(v[i] + v3[j]);
    }
  }
  sort(all(v4));
  reverse(all(v4));
  for(int i = 0; i < k; i ++) {
    cout << v4[i], nl;
  }
  return 0;
}

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

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using Graph = vector<vector<int>>;

const ll LINF = 1e18;
const int INF = 1e9;
const ll MOD = 1000000007;


int main(){

    string n;
    cin >> n;
    if((n[0] == '9') || (n[1] == '9')) cout << "Yes" << endl;
    else cout << "No" << endl;

    return 0;
}

Measured memory_bytes: 3564
//For higher stack size use g++ -O2 -std=c++11 -Wall -Wl,--stack=268435456 a.cpp -o a.exe in cmd
    #include <bits/stdc++.h>
    #include <cstdio>
    #include <cstring>
    #include <cmath>
    #include <cstring>
    #include <chrono>
    #include <complex>
    #define ll long long
    #define ld long double
    #define vi vector<int>
    #define vll vector<ll>
    #define vvi vector < vi >
    #define pii pair<int,int>
    #define pll pair<long long, long long>
    #define mod 1000000007
    #define inf 1000000000000000001;
    #define all(c) c.begin(),c.end()
    #define mp(x,y) make_pair(x,y)
    #define mem(a,val) memset(a,val,sizeof(a))
    #define eb emplace_back
    #define pb push_back
    #define f first
    #define s second
    
    using namespace std;

    ll power(ll a, ll b)    //a is base, b is exponent
    {
        if(b==0)
            return 1;
        if(b==1)
            return a;
        if(b%2 == 1)
            return (power(a,b-1)*a)%mod;
        ll q = power(a,b/2);
        return (q*q)%mod;
    }

    int main()
    {
        std::ios::sync_with_stdio(false);
        int T;
        T=1;
        // cin.ignore(); must be there when using getline(cin, s)
        while(T--)
        {
            ll n,k,i,j;
            cin>>n>>k;
            ll ar[n+1],pre[n+1];
            ld ar2[n+1];
            ar2[0]=0;
            for(i=1;i<=n;++i)
            {
                cin>>ar[i];
                ar2[i]=(ld)1.0*(ar[i]+1)/2.0;
                ar2[i]=ar2[i]+ar2[i-1];
            }
            ld ans=0.0;
            for(i=k;i<=n;++i)
            {
                ans=max(ans,ar2[i]-ar2[i-k]);
            }
            printf("%.9Lf\n",ans);

        }
        return 0;
    }


Measured memory_bytes: 4992
#include<bits/stdc++.h>
#define fi first
#define se second
#define show(x) cerr<<#x<<"="<<x<<"\n"
typedef long long ll;
using namespace std;
//const ll MOD=(ll)1e9+7;
//const ll inf=(ll)1e14;
const int dy[]={1,0,-1};
const int dx[]={1,0,-1};
vector<pair<int,int> > v[10001];
int vv[10001][1000];

int main(){
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.precision(10);
  cout<<fixed;
#ifdef LOCAL_DEFINE
  FILE *stream1;
  //FILE *stream2;
  stream1=freopen("in","r",stdin);
  //stream2=freopen("out","w",stdout);
  if(stream1==NULL)return 0;
  //if(stream2==NULL)return 0;
#endif
  int n,m;
  while(cin>>n>>m,n){
    int r,q;cin>>r;
    vector<pair<int,int> > v[10001];
    for(int i=0;i<r;i++){
      int a,b,c,d;cin>>a>>b>>c>>d;
      c--;
      a-=540;
      if(d==0){
        v[c].push_back({b,a});
      }else{
        v[c].push_back({b,a});
      }
    }
    for(int i=0;i<m;i++){
      for(int j=0;j<800;j++){
        vv[i][j]=0;
      }
    }
    for(int i=0;i<m;i++){
      sort(v[i].begin(),v[i].end());
      for(int j=0;j<(int)v[i].size();j+=2){
        vv[i][v[i][j].se]++;
        vv[i][v[i][j+1].se]--;
      }
    }
    for(int i=0;i<m;i++){
      for(int j=0;j<800;j++){
        if(j==0)continue;
        vv[i][j]=vv[i][j-1]+vv[i][j];
      }
    }
    cin>>q;
    for(int i=0;i<q;i++){
      int ts,te,tm;cin>>ts>>te>>tm;
      tm--;
      ts-=540;
      te-=540;
      int res=0;
      for(int j=ts;j<te;j++){
        if(vv[tm][j]>0)res++;
      }
      cout<<res<<endl;
    }
  }
#ifdef LOCAL_DEFINE
  cerr<<"Time elapsed: "<<1.0*clock()/CLOCKS_PER_SEC<<"s.\n";
  fclose(stream1);
  //fclose(stream2);
#endif
  return 0;
}







Measured memory_bytes: 41456
#include <bits/stdc++.h>
#define all(x) begin(x), end(x)
#define dbg(x) cerr << #x << " = " << x << endl
#define _ << ' ' <<
using namespace std;
using ll = long long;
using vi = vector<int>;

ll n, a[100001], b[100000];

int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    cin >> n;
    for (int i = 0; i <= n; ++i)
        cin >> a[i];
    for (int i = 0; i < n; ++i)
        cin >> b[i];

    ll sol = 0;
    for (int i = 0; i < n; ++i)
    {
        if (i != 0)
        {
            ll k = min(a[i], b[i - 1]);
            sol += k;
            a[i] -= k;
            b[i - 1] -= k;
        }
        ll k = min(a[i], b[i]);
        sol += k;
        b[i] -= k;
        a[i] -= k;
    }
    cout << sol + min(a[n], b[n - 1]);
}


Measured memory_bytes: 1792
import sys
import math

input_methods=['clipboard','file','key']
using_method=0
input_method=input_methods[using_method]

tin=lambda : map(int, input().split())
lin=lambda : list(tin())
mod=1000000007

#+++++

def cc(al, v_max, k):
	for vl in al:
		if vl <= v_max:
			return True
		k -= ((vl + v_max- 1) // v_max) - 1
		#pa((k, -(-v // v_max)))
		if k < 0:
			return False
	return True
		

def main():
	#a = int(input())
	n, k = tin()
	#s = input()
	al = lin()
	al.sort(reverse = True)
	#print(al)
	ok = al[0]
	ng = 0
	while ok - ng > 1:
		mid = (ok + ng)//2
		ii=cc(al, mid, k)
		#pa((mid,ii))
		if ii:
			ok = mid
		else:
			ng = mid
	#pa(ok)
	print(ok)
	
	
#+++++
isTest=False

def pa(v):
	if isTest:
		print(v)
		
def input_clipboard():
	import clipboard
	input_text=clipboard.get()
	input_l=input_text.splitlines()
	for l in input_l:
		yield l

if __name__ == "__main__":
	if sys.platform =='ios':
		if input_method==input_methods[0]:
			ic=input_clipboard()
			input = lambda : ic.__next__()
		elif input_method==input_methods[1]:
			sys.stdin=open('inputFile.txt')
		else:
			pass
		isTest=True
	else:
		pass
		#input = sys.stdin.readline
			
	ret = main()
	if ret is not None:
		print(ret)

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

int main() {
    long long h; scanf("%lld", &h);

    long long res = 0;
    for (long long two=(long long)1; h; two *= (long long)2) {
        res += two;
        h /= (long long)2;
    }

    printf("%lld\n", res);
    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<string>
#include<algorithm>
using namespace std;

int main(){
	int n[10000];
	int input;
	while(cin >> input, input != 0){
		long long int ans = 0;
		for(int i=0; i < input; i++) cin >> n[i];

		sort(n, n+input);

		for(int i=0; i < input-1; i++){
			ans += n[i];
			n[i+1] += n[i];
		}
		cout << ans << endl;
	}
}

Measured memory_bytes: 1208
import java.util.*;
import java.io.*;
import java.math.*;
public class Main
{
    static class Reader 
    { 
        private InputStream mIs;private byte[] buf = new byte[1024];private int curChar,numChars;public Reader() { this(System.in); }public Reader(InputStream is) { mIs = is;} 
        public int read() {if (numChars == -1) throw new InputMismatchException();if (curChar >= numChars) {curChar = 0;try { numChars = mIs.read(buf);} catch (IOException e) { throw new InputMismatchException();}if (numChars <= 0) return -1; }return buf[curChar++];} 
        public String nextLine(){int c = read();while (isSpaceChar(c)) c = read();StringBuilder res = new StringBuilder();do {res.appendCodePoint(c);c = read();}while (!isEndOfLine(c));return res.toString() ;} 
        public String s(){int c = read();while (isSpaceChar(c)) c = read();StringBuilder res = new StringBuilder();do {res.appendCodePoint(c);c = read();}while (!isSpaceChar(c));return res.toString();} 
        public long l(){int c = read();while (isSpaceChar(c)) c = read();int sgn = 1;if (c == '-') { sgn = -1 ; c = read() ; }long res = 0; do{ if (c < '0' || c > '9') throw new InputMismatchException();res *= 10 ; res += c - '0' ; c = read();}while(!isSpaceChar(c));return res * sgn;} 
        public int i(){int c = read() ;while (isSpaceChar(c)) c = read();int sgn = 1;if (c == '-') { sgn = -1 ; c = read() ; }int res = 0;do{if (c < '0' || c > '9') throw new InputMismatchException();res *= 10 ; res += c - '0' ; c = read() ;}while(!isSpaceChar(c));return res * sgn;} 
        public double d() throws IOException {return Double.parseDouble(s()) ;}
        public boolean isSpaceChar(int c) { return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1; } 
        public boolean isEndOfLine(int c) { return c == '\n' || c == '\r' || c == -1; } 
        public int[] arr(int n){int[] ret = new int[n];for (int i = 0; i < n; i++) {ret[i] = i();}return ret;}
    }
    
    

    //       |----|       /\      |    |   -----   |
    //       |   /       /  \     |    |     |     |
    //       |--/       /----\    |----|     |     |
    //       |   \     /      \   |    |     |     |
    //       |    \   /        \  |    |   -----   -------
    
    
    public static void main(String[] args)throws IOException
    {
        PrintWriter out= new PrintWriter(System.out);
        Reader sc=new Reader();
        String s=sc.s();
        String find="keyence";
        int f=0;
        for(int i=0;i<s.length();i++)
        {
            for(int j=i;j<s.length();j++)
            if((s.substring(0,i)+s.substring(j)).equals(find))
            f=1;
        }
        if(f==1)
        out.println("YES");
        else
        out.println("NO");
        out.flush();
    }
}

Measured memory_bytes: 23380
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i,n) for(int i = 0; i < (n); i++)
#define all(v) v.begin(), v.end()
#define MOD 1000000007
const int INF = 1LL<<30;

int main(){
    int n,m;
    cin>>n>>m;
    vector<int> k(m);
    vector<int> s[15];
    rep(i,m){
        cin>>k[i];
        rep(j,k[i]){
            int ss;
            cin>>ss;
            ss--;
            s[i].push_back(ss);
        }
    }
    vector<int> p(m);
    rep(i,m) cin>>p[i];

    int ans=0;
    rep(bit,1<<n){
        bool ok=true;
        rep(j,m){
            int cnt=0;
            rep(i,k[j]){
                if(bit & 1<<s[j][i]) cnt++;
            }
            if(cnt%2!=p[j]){
                ok=false;
            }
        }
        if(ok) ans++;
    }

    cout<<ans<<endl;
}

Measured memory_bytes: 3644
import java.util.Arrays;
import java.util.Scanner;

class Main{

	public static void main(String[] args) {




		Scanner scan = new Scanner(System.in);
		int N = scan.nextInt();
		//		int K = scan.nextInt();

		int data[] = new int[N];
		for(int i = 0;i < N;i++){
			data[i] = scan.nextInt();
		}
		Arrays.sort(data);		
		int ans = 0;

		for(int i = N-1;i >= 0;i = i - 2){
			ans += data[i];
		}
		for(int i = N-2;i >= 0;i = i - 2){

			ans -= data[i];
		}
		
		System.out.println(ans);
	}




}


Measured memory_bytes: 23764
#include<stdio.h>

int main(){
	int cnt;
	int i;
	int x[10000],y[10000];
	while(1){
		scanf("%d %d",&x[cnt],&y[cnt]);
		if(x[cnt]==0&&y[cnt]==0)break;
		cnt++;
	}
	
	int tmp;
	for(i=0;i<cnt;i++){
		if(x[i]>y[i]){
		tmp=x[i];
		x[i]=y[i];
		y[i]=tmp;
		}
		printf("%d %d\n",x[i],y[i]);
	}
	return 0;
}

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

int main() {

  long W, H;
  long x, y;
  cin >> W >> H;
  cin >> x >> y;

  int f = 0;

  if (double(x) == (double(W) / 2) && double(y) == (double(H) / 2)) {
    f = 1;
  }

  cout << fixed << setprecision(15);
  cout << double(W) * double(H) / 2.0 << " " << f << endl;

}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define ll long long
#define ii pair<int, int>
#define iii tuple<int, int, int>
#define iiii tuple<int, int, int, int>
#define vi vector<int>
#define vvi vector<vector<int>>
#define fi first
#define se second
#define eb emplace_back
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()
#define uni(v) v.erase(unique(v.begin(), v.end()), v.end())
#define gcd(a, b) __gcd(a, b)
#define lcm(a, b) (ll) a / __gcd(a, b) * b

using namespace std;

void solve() {
    const ll M = 1e9;
    int n, d, x;
    cin >> n >> d >> x;
    vector<pair<ll, ll>> a(n);
    vector<ll> c(n);
    for (auto& i : a) cin >> i.fi >> i.se;
    sort(all(a));
    int i = 0, j = 0;
    ll res = 0;
    while (i < n) {
        if (i) c[i] += c[i - 1];

        int y = a[i].fi + d + d;
        while (j < n && a[j].fi <= y) j++;

        if (a[i].se - c[i] > 0) {
            int z = (a[i].se - c[i] - 1) / x + 1;
            res += z;
            c[i] += z * x;
            if (j < n) c[j] -= z * x;
        }

        i++;
    }
    cout << res << '\n';
}

int main() {
    ios::sync_with_stdio(false), cin.tie(nullptr), cout.tie(nullptr);
    // freopen("in", "r", stdin);

    int t = 1;
    // cin >> t;

    while (t--) solve();
    return 0;
}

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

using namespace std;
int main(){
  int n, m;
  cin >> n >> m;
  while(m--){
  	int temp;
    cin >> temp;
    n -= temp;
  }

  if(n < 0) cout << -1;
  else cout << n;
 return 0; 
}

Measured memory_bytes: 3592
#include <iostream>
#include <iostream>
using namespace std;
int n,k,s,flg,cnt;

void saiki(int kai,int sum,int p) {
  if(kai == k && sum == s) cnt++;
    if(kai < k && sum < s) {
      for(int i=p+1;i<=n;i++) saiki(kai+1,sum+i,i);	
    }
}

int main() {

  while(1) {
  cin >> n >> k >> s;
  if(n==0 && k==0 && s==0) break;
  cnt = 0;
  saiki(0,0,0);
  cout << cnt <<endl;
  }
  return 0;
}
    

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

int A,B,C,N;
int minMP=9999;
vector<int>l(8);

void calc(vector<int>v){
  int a=0,b=0,c=0;
  int synthesize= -3;
  int MP=0;
  
  //竹準備
  for(int i=0;i<N;i++){
    if(v.at(i)==1){
      a+=l.at(i);
      synthesize++;
    }
    
    if(v.at(i)==2){
      b+=l.at(i);
      synthesize++;
    }
    
    if(v.at(i)==3){
      c+=l.at(i);
      synthesize++;
    }
    
  }
  //竹準備完了
  //竹あるかチェック
  if(a==0||b==0||c==0)
    return;
  
  //MP計算
  MP+=abs(A-a)+abs(B-b)+abs(C-c);
  
  if(synthesize>0)
    MP+=10*synthesize;
  
  minMP=min(minMP,MP);
}
  
  
  
  
    
    

void dfs(int depth,vector<int>v){
  if(depth==N){
    calc(v);
    return;
  }
  
  for(int i=0;i<4;i++){
    v.at(depth)=i;
    dfs(depth+1,v);
  }
  
}


int main(){
  cin>>N>>A>>B>>C;
  for (int i=0;i<N;i++)
    cin>>l.at(i);
  vector<int>v(N);
  
  dfs(0,v);
  
  cout<<minMP;
}





Measured memory_bytes: 256
#include <string>
#include <vector>
#include <algorithm>
#include <numeric>
#include <set>
#include <map>
#include <queue>
#include <iostream>
#include <sstream>
#include <cstdio>
#include <cmath>
#include <ctime>
#include <cstring>
#include <cctype>
#include <cassert>
#include <limits>
#include <functional>
#include <iomanip>
#include <complex>
#include <bitset>
#include <stack>
using namespace std;
 
#define rep(i,n) for(int (i)=0;(i)<(int)(n);++(i))
#define repl(i,s,n) for(int i=s; i<=n; ++i)
#define rer(i,l,u) for(int (i)=(int)(l);(i)<=(int)(u);++(i))
#define reu(i,l,u) for(int (i)=(int)(l);(i)<(int)(u);++(i))
#if defined(_MSC_VER) || __cplusplus > 199711L
#define aut(r,v) auto r = (v)
#else
#define aut(r,v) __typeof(v) r = (v)
#endif
#define each(it,o) for(aut(it, (o).begin()); it != (o).end(); ++ it)
#define ktya(x) sort(all(x))
#define maxs(x,y) (x = max(x,y))
#define mins(x,y) (x = min(x,y))
#define all(o) (o).begin(), (o).end()
#define pb(x) push_back(x)
#define mp(x,y) make_pair((x),(y))
#define mset(m,v) memset(m,v,sizeof(m))
#define INF 1e18
#define INFLL 1000000000000000007LL
#define SIZE 200105
#define REP(i,n) for(int i=0;i<(int)n;++i)
#define FOR(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)
#define ALL(c) (c).begin(), (c).end()
#define mind(a,b) (a>b?b:a)
#define maxd(a,b) (a>b?a:b)
#define PI (acos(-1))
typedef vector<int> vi; typedef pair<int, int> pii; typedef vector<pair<int, int> > vpii; typedef long long ll;
typedef pair<int,ll> pill; typedef pair<ll,int> plli; 
typedef pair<double, int> pdi;
template<typename T, typename U> inline void amin(T &x, U y) { if(y < x) x = y; }
template<typename T, typename U> inline void amax(T &x, U y) { if(x < y) x = y; }
typedef complex<double> P;
//ll MOD = 1000000007;
ll MOD=1e9+7;
typedef ll Weight;
struct Edge {
	int src, dst;
	Weight weight;
};
bool operator < (const Edge &e, const Edge &f) {
	return e.weight != f.weight ? e.weight > f.weight : // !!INVERSE!!
	e.src != f.src ? e.src < f.src : e.dst < f.dst;
}
typedef vector<Edge> Edges;
int N;
ll K;
vi A;
int main(){
	cin>>N>>K;
	rep(i,N){
		int x;
		cin>>x;
		A.pb(x);
	}
	ll ans=0;
	rep(i,N){
		ll cnt1=0;
		ll cnt2=0;
		rep(j,N){
			if(A[j]>A[i]){
				if(j<i)cnt1++;
				cnt2++;
			}
		}
		cnt1*=K;
		cnt1%=MOD;
		ll hoge=(K*(K-1))/2;
		hoge%=MOD;
		cnt2*=hoge;
		cnt2%=MOD;
		ans+=cnt1;
		ans%=MOD;
		ans+=cnt2;
		ans%=MOD;
	}
	cout<<ans<<endl;
}

Measured memory_bytes: 256
//#include <bits/stdc++.h>
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <cstring>
#include <deque>
#include <map>
using namespace std;

#define ii pair <int, int>
#define lli long long
#define pb push_back
#define X first
#define Y second

const int Mod = 1E9 + 7;
const int Inf = 1E9 + 7;
const int N = 2E5 + 10;

void Input()
{

}

void Solve()
{
    string N;
    cin >> N;
    int x = 0;
    for (int i = 0; i < N.size(); i++)
        x = (x + N[i] - '0') % 9;
    if (x == 0) cout << "Yes";
    else cout << "No";
}

#define task "test"
int main()
{
    if (fopen(task ".inp", "r")) {
        freopen(task ".inp", "r", stdin);
        freopen(task ".out", "w", stdout);
    }
    int testcase = 1;
    /// cin >> testcase;
    while (testcase--) {
        Input();
        Solve();
    }
}




Measured memory_bytes: 3312
#include <queue>
#include <vector>
#include <iostream>
#include <algorithm>
using namespace std;
struct edge { int to, cost; };
int n, u, v, w; vector<bool> vis; vector<int> c; vector<vector<edge> > G;
int solve(int pos, edge *e_) {
	vis[pos] = true;
	if (c[pos] > 0) return (*e_).cost;
	int res = 0;
	for (edge e : G[pos]) {
		if(!vis[e.to]) res += solve(e.to, &e);
	}
	if (pos == 0) return res;
	return min(res, (*e_).cost);
}
int main() {
	cin >> n; c.resize(n);
	for (int i = 1; i < n; i++) cin >> c[i];
	G.resize(n);
	for (int i = 0; i < n - 1; i++) {
		cin >> u >> v >> w;
		G[u].push_back(edge{ v, w });
		G[v].push_back(edge{ u, w });
	}
	vis.resize(n, false);
	cout << solve(0, nullptr) << endl;
	return 0;
}

Measured memory_bytes: 3192
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
int main()
{
    // #ifndef ONLINE_JUDGE
    // freopen("F:/cpp/input.txt", "r", stdin);
    // freopen("F:/cpp/output.txt", "w", stdout);
    // #endif
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    ll n, k;
    cin >> n >> k;
    ll a[n], i, j;
    vector <ll> dp(n, INT_MAX);
    for (i=0;i<n;i++)
    {
        cin >> a[i];
    }
    dp[n-1] = 0;
    dp[n-2] = abs(a[n-2] - a[n-1]);
    for (i=n-3;i>=0;i--)
    {
        for (j=i+1;j<n&&j-i<=k;j++)
        {
            dp[i] = min(dp[i], abs(a[i] - a[j]) + dp[j]);
        }
    }
    cout << dp[0];
    return 0;
}

Measured memory_bytes: 1792
#include <iostream>
#include <cstdio>
#include <queue>
#include <stack>
#include <vector>
#include <algorithm>
#include <string>
#include <cstring>
#include <cmath>
#include <complex>
#include <map>
#include <climits>
#include <sstream>
using namespace std;

#define reep(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n) reep((i),0,(n))
#define ALL(v) (v).begin(),(v).end()
#define PB push_back
#define EPS 1e-8
#define F first
#define S second
#define mkp make_pair

static const double PI=6*asin(0.5);
typedef long long ll;
typedef complex<double> CP;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef vector<ll> vint;
static const int INF=1<<24;

template <class T>
void initvv(vector<vector<T> > &v,int a,int b, const T  &t = T()){
	v.assign(a,vector<T>(b,t));
}

//v.erase(unique(v.begin(),v.end()),v.end());

vint v;
ll ans;
ll a,b;
void foo(ll c){
	if(c==v.size()){
		ans=min(ans,abs(a-b));
		return;
	}
	a+=v[c];
	foo(c+1);
	a-=v[c];
	b+=v[c];
	foo(c+1);
	b-=v[c];
}

int main(){
	int n;
	while(cin>>n,n){
		v.clear();
		ans=INF;
		a=0;
		b=0;
		rep(i,n){
			ll t;
			cin>>t;
			v.PB(t);
		}
		foo(0);
		cout<<ans<<endl;
	}
}

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

int main(){
  int N,K;
  cin >> N >> K;
  vector<int> d(K);
  int x;
  set<int> S;
  int ans=0;
  
  for(int i=0;i<K;i++){
    cin >> d.at(i);
   for(int j=0;j<d.at(i);j++){
     cin >> x;
     S.insert(x);
   }
  }
  for(int i=0;i<N;i++){
    if(!S.count(i+1)) ans++;
  }
  cout << ans << endl;
}

Measured memory_bytes: 3636
#include <cstdio>

int main()
{
  int m, d;
  scanf("%d%d", &m, &d);
  int ans = 0;
  for (int i = 1; i <= m; ++i)
  {
    for (int j = 22; j <= d; ++j)
    {
      if (j % 10 < 2) continue;
      if (i == (j / 10) * (j % 10)) ++ans;
    }
  }
  printf("%d\n", ans);
  return 0;
}

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

int main() {
  int q;
  cin >> q;
  string k;
  map<string, int> M;
  while (cin >> q >> k) {
    if (q == 0) {
      int x;
      cin >> x;
      M[k] = x;
    }
    if (q == 1)
      cout << M[k] << endl;
    if (q == 2)
      M.erase(k);
  }
}


Measured memory_bytes: 27808
import sys

#sys.setrecursionlimit(500000)

K = int(input())

ans = []

def make(prev,scale,now):
    if scale == 0:
        ans.append("".join(now))
        return
    if prev > 0:
        n = list(now)
        n.append(str(prev-1))
        make(prev-1,scale-1,n)
    n = list(now)
    n.append(str(prev))
    make(prev,scale-1,n)
    if prev < 9:
        n = list(now)
        n.append(str(prev+1))
        make(prev+1,scale-1,n)
    
for i in range(10):
    for j in range(1,10):
        make(j,i,[str(j)])

print(ans[K-1])

Measured memory_bytes: 67164
#include<bits/stdc++.h>
#include<unordered_set>
#include<unordered_map>
#include <iostream>
#include <string>
#include <cmath>
using namespace std;
#define ll long long
#define rep(i, n) for (ll i = 0; i < (n); i++)
#define FOR(i,a,b) for(ll i=(a);i<(b);i++)
#define FORR(i,a,b)for(ll i=(a);i<=(b);i++)
#define repR(i,n) for(ll i=n;i>=0;i--)
#define all(v)(v).begin(),(v).end()
#define rall(v)(v).rbegin(),(v).rend()
#define F first
#define S second
#define pb push_back
#define pu push
#define COUT(x) cout<<(x)<<endl
#define PQ priority_queue<ll>
#define PQR priority_queue<ll,vector<ll>,greater<ll>>
#define YES(n) cout << ((n) ? "YES" : "NO"  ) << endl
#define Yes(n) cout << ((n) ? "Yes" : "No"  ) << endl
#define mp make_pair
#define maxs(x,y) (x = max(x,y))
#define mins(x,y) (x = min(x,y))
#define sz(x) (int)(x).size()
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
const ll MOD = 1000000007LL;
const ll INF = 1LL << 60;
using vll = vector<ll>;
using vb = vector<bool>;
using vvb = vector<vb>;
using vvll = vector<vll>;
using vstr = vector<string>;
using pll = pair<ll, ll>;
using vc = vector<char>;
using vvc = vector<vc>;
ll dx[4]={0,1,0,-1};
ll dy[4]={1,0,-1,0};
int main(){
  ll n;
  string s;
  cin>>n>>s;
  ll q;
  cin>>q;
  vector<set<ll>> p(26);
  rep(i,n){
    p[s[i]-'a'].insert(i);
  }
  rep(i,q){
    ll k;
    cin>>k;
    if(k==1){
      ll d;
      char r;
      cin>>d>>r;
      d--;
      p[s[d]-'a'].erase(d);
      s[d]=r;
      p[s[d]-'a'].insert(d);
    }
    else{
      ll l,r;
      cin>>l>>r;
      l--;
      ll ans=0;
      rep(j,26){
        auto it=p[j].lower_bound(l);
        if(it!=p[j].end()&&*it<r){
          ans++;
        }
      }
      COUT(ans);
    }
  }
}


Measured memory_bytes: 24196
import sys

n=int(input())
if n==1:
  print(1)
  sys.exit()
result = 0
for i in range(n):
  a = n-i
  while True:
    if a % 2 == 1:
      break
    else:
      if a == 2:
        print(n-i)
        sys.exit()
      else:
        a /= 2


Measured memory_bytes: 2940
#include <stdio.h>
#include <string>
#include <iostream>
#include <iomanip>
#include <map>
#include <algorithm>
#include <vector>
using namespace std;

int sum(long long n){
	int ans=n%10;
	while(n/10){
		n/=10;
		ans+=n%10;
	}
	return ans;
}

int main(void) {
	long long n;
	cin >> n;
	string ans=(n%sum(n)==0?"Yes":"No");
	cout << ans << endl;
	return 0;
}


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

int main() {
	int mth[13]={0,31,29,31,30,31,30,31,31,30,31,30,31};
	char wks[][16]={"Wednesday","Thursday","Friday","Saturday","Sunday",
				"Monday","Tuesday"};
	int m,d;
	while(cin>>m>>d,m){
		int days=0;
		for(int i=1;i<m;i++) days+=mth[i];
		days+=d; cout<<wks[days%7]<<endl;
	}
}

Measured memory_bytes: 1160
#include"bits/stdc++.h"
using namespace std;
#define REP(k,m,n) for(int (k)=(m);(k)<(n);(k)++)
#define rep(i,n) REP((i),0,(n))
using ll = long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using tp3 = tuple<int, int, int>;
using Mat = vector<vector<ll>>;
constexpr int INF = 1 << 28;
constexpr ll INFL = 1ll << 60;
constexpr int dh[4] = { 0,1,0,-1 };
constexpr int dw[4] = { -1,0,1,0 };
bool isin(const int H, const int W, const int h, const int w) {
    return 0 <= h && h < H && 0 <= w && w < W;
}
// ============ template finished ============

int main()
{
    int X;
    cin >> X;
    cout << (X >= 30 ? "Yes" : "No") << endl;
    return 0;
}


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

int main() {
  char c;
  cin >> c;
  cout << (char)(c + 1) << endl;
  return 0;
}


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

int groupting( int a )
{
    if ( a < 8 && a % 2 == 1 || a > 7 && a % 2 == 0 )
        return 1;
    else if ( a == 2 )
        return 3;
    else
        return 2;
}

int main( void )
{
    int x,y;
    cin >> x >> y;
    
    int groupx = groupting(x),groupy = groupting(y);
    if ( groupx == groupy )
        cout << "Yes" << endl;
    else
        cout << "No" << endl;
}


Measured memory_bytes: 256
#include <stdio.h>
#include <string.h>
#define lop(i, n) for(i=1; i<=n; i++)

int main()
{
	char s[4];
	
	scanf("%s", s);
	
	if(s[0] == s[1] && s[1] != s[2] && s[2] == s[3])printf("Yes\n");
	else if(s[0] == s[2] && s[2] != s[1] && s[1] == s[3])printf("Yes\n");
	else if(s[0] == s[3] && s[3] != s[1] && s[1] == s[2])printf("Yes\n");
	else printf("No\n");
	
return 0;
}

Measured memory_bytes: 128