akhauriyash/Code-Regression huggingface dataset:
import java.util.*;

public class Main {

    public static void main(String args[]) {

        // 入力
        Scanner sc = new Scanner(System.in);
        int n = Integer.parseInt(sc.next());
        Long[] a = new Long[n];
        Long[] b = new Long[n];
        for (int i = 0; i < n; i++) {
            a[i] = Long.parseLong(sc.next());
        }
        for (int i = 0; i < n; i++) {
            b[i] = Long.parseLong(sc.next());
        }
        sc.close();

        // 主処理
        long sumA = Arrays.stream(a).mapToLong(i -> i).sum();
        long sumB = Arrays.stream(b).mapToLong(i -> i).sum();

        int result = 0;
        if (sumA < sumB) {
            result = -1;
        } else {
            PriorityQueue<Long> overNumberQueue = new PriorityQueue<>(Collections.reverseOrder());
            PriorityQueue<Long> lackNumberQueue = new PriorityQueue<>(Collections.reverseOrder());
            for (int i = 0; i < n; i++) {
                long diff = a[i] - b[i];
                if (0 < diff) {
                    overNumberQueue.add(diff);
                } else if (diff < 0) {
                    lackNumberQueue.add(diff * -1);
                }
            }
            long over = 0;
            while (!lackNumberQueue.isEmpty()) {
                long lack = lackNumberQueue.poll();
                over -= lack;
                result++;
                while (over < 0) {
                    over += overNumberQueue.poll();
                    result++;
                }
            }
        }

        // 出力
        System.out.println(result);
    }
}


Measured memory_bytes: 67880
def pow_mod(a, b, p):
    res = 1
    mul = a
    for i in range(len(bin(b)) - 2):
        if (1 << i) & b:
            res = (res * mul) % p
        mul = (mul ** 2) % p
    return res


def comb_mod(n, r, p, factorial, invert_factorial):
    return (factorial[n] * invert_factorial[r] * invert_factorial[n - r]) % p


def main():
    p = 10 ** 9 + 7
    n, k = map(int, input().split())

    factorial = [1] * (n + 1)
    for i in range(1, n + 1):
        factorial[i] = (factorial[i - 1] * i) % p

    invert_factorial = [0] * (n + 1)
    invert_factorial[n] = pow_mod(factorial[n], p - 2, p)
    for i in range(n - 1, -1, -1):
        invert_factorial[i] = (invert_factorial[i + 1] * (i + 1)) % p

    res = 0
    for i in range(min(k + 1, n)):
        res = (res + comb_mod(n, i, p, factorial, invert_factorial)
               * comb_mod(n - 1, i, p, factorial, invert_factorial)) % p
    print(res)


main()


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

int main() {
  int N, N1, N2, N3, N4;
  cin >> N;
  N1 = N/1000;
  N2 = N/100%10;
  N3 = N/10%10;
  N4 = N%10;
  if ((N1 == N2 && N2 == N3) || (N2 == N3 && N3 == N4)){
    cout << "Yes" << endl;
  }
  else{
    cout << "No" << endl;
  }
}

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

using namespace std;

int main() {
    ios::sync_with_stdio(false); cin.tie(nullptr);
    string s, t;
    cin >> s >> t;
    int ans = 0;
    for (int i = 0; i < (int)s.length(); ++i)
        ans += (s[i] != t[i]);
    cout << ans << '\n';
    return 0;
}

Measured memory_bytes: 3744
#include <iostream>
#include <vector>
#include <algorithm>
#include <functional>
#include <map>
#include <string>
#include <queue>
#include <stack>
#include <math.h>
#include <cmath>
#include <numeric>
#include <iomanip>


#define log(x) cout<<x<<endl
#define pb push_back
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()
typedef long long lint;
using namespace std;


// <<fixed<<setprecision(6)<<


int gcd(lint x, lint y){
  return y==0 ? x:gcd(y,x % y);
}


int combi(int n, int r){
  int num = 1;
  for(int i = 1; i <= r; i++){
    num = num * (n - i + 1) / i;
  }
  return num;
}


int main(){
  int x,y,z;
  cin>>x>>y>>z;
  swap(x,y);
  swap(x,z);
  cout<<x<<" "<<y<<" "<<z;
}

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

int main(){
	 ios::sync_with_stdio(false);
	string a, b;
	int x, i = 0;
	cin >> a >> b;
	for(int i = 0;a[i];i++){
		i = a.find(b, i);
		if(i == -1)break;
		cout << i << endl;
	}
	while((x = a.find(b, i)) != -1){
		cout << x << endl;
		i = x + 1;
	}
	return 0;
}*/

#include <iostream>
#include <string>
using namespace std;
string t,p;
int main(){
	//ios::sync_with_stdio(false);
	cin>>t>>p;
	for(int i=0;t[i];i++){
		i=t.find(p, i);
		if(i==string::npos)break;
		cout<<i<<'\n';
	}
	return 0;
}

Measured memory_bytes: 4000
/*
AizuOnline A0539
Title Pizza
@kankichi573
*/
#include <stdio.h>
#define min(x,y) (((x)<(y))?(x):(y))

int l,n,m;
int d[100002];
int k[10001];

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


int calc()
{
        int dp,kp,sum,r;

        qsort(d+1,n,sizeof(int),compare_int);
        d[n+1]=d[0]+l;
        qsort(k+1,m,sizeof(int),compare_int);

        for(sum=0,dp=1,kp=1;kp<=m;kp++)
        {
#ifdef DEBUG
                printf("k[%d]=%d",kp,k[kp]);
#endif
                while(d[dp]<k[kp])
                        dp++;
                r = min((k[kp]-d[dp-1]),(d[dp]-k[kp]));
#ifdef DEBUG
                printf("%d~%d~%d %d\n",d[dp-1],k[kp],d[dp],r);
#endif
                sum += r;
        }
        return(sum);
}
main()
{
        int i,sum;

        while(scanf("%d",&l) && l)
        {
                scanf("%d",&n);
                scanf("%d",&m);

                //printf("LNM=%d %d %d\n",l,n,m);
                d[0]=0;
                for(i=2;i<=n;i++)
                        scanf("%d",&d[i]);
                for(i=1;i<=m;i++)
                        scanf("%d",&k[i]);
                sum=calc(n);
                printf("%d\n",sum);
        }
        return(0);
}

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

using namespace std;

string put_nchar(int n, char c)
{
	string S = "";

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

	return S;
}

int main()
{
	string S;

	while (cin >> S)
	{
		for (string::size_type i = 0; i < S.size(); i++)
		{
			if (S[i] == '@')
			{
				cout << put_nchar(static_cast<int>(S[i + 1]) - 48, S[i + 2]);

				i += 2;
			}
			else
			{
				cout << S[i];
			}
		}

		cout << endl;
	}

	return 0;
}

Measured memory_bytes: 1188
N = int(input())
X = list(map(int, input().split()))

x_min = min(X)
x_max = max(X)

Min_power = 0

for i in X:

    Min_power += (i-x_min)**2


for p in range(x_min, x_max+1):
    power = 0
    for i in X:
        power += (i-p)**2
    if Min_power > power:
        Min_power = power

print(Min_power)


Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define rep(i,n) for(long long (i)=0;(i)<(n);++(i))
#define ref(i,a,b) for (long long (i)=(a); (i)<=(b); ++(i))
#define endl '\n'
#define pb push_back
#define mp make_pair
const int mx=1e5+5;
int main(){
	/*freopen(".gir", "r", stdin);
	freopen(".cik", "w", stdout); 
    */ios_base::sync_with_stdio(false);cin.tie(NULL);
	int m,d;cin >> m >> d;
	int ans=0;
	for(int i=1;i<=m;++i){
		for(int j=22;j<=d;++j){
			if(j%10>=2){
				if((j%10)*(j/10)==i)++ans;
			}	
		}
	
	}
	cout << ans << endl;
}
	

Measured memory_bytes: 256
import java.util.Scanner;

/**
 * Main
 */
public class Main {

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

        long X = sc.nextLong();
        sc.close();
        int min = (int)(-1*Math.pow(10, 3));
        int max = (int)(Math.pow(10, 3));
    
        for(int i= min; i < max; i++) {
            for(int j=i-1; j>=min; j--){
                long A = (long)(Math.pow(i, 5));
                long B = (long)(Math.pow(j, 5));
                if(A - B == X){
                    System.out.println(i + " " + j);
                    return;
                }
                if(i-j > X){
                    break;
                }
            }
        }
    }
}


Measured memory_bytes: 27244
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define mp make_pair
#define pb push_back
#define F first
#define S second
#define mod 1000000007
#define PI 3.141592653589793238
#define all(a) a.begin(),a.end()
#define dbg(n) cout<<#n<<' '<<n<<endl;
#define dbg_v(v) cout<<#v<<":";for(auto x:v) cout<<" "<<x; cout<<endl;
int power(ll x,ll y){ll res = 1;while(y>0){if(y&1)res = (res*x)%mod;y=y>>1;x=(x*x)%mod;}return res;}
int gcd(int a,int b){
	if(!a)
		return b;
	return gcd(b%a,a);
}
int main(){ 
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);	
	ll n;
	cin>>n;
	string s="";
	while(n>0){
		char c='a'+((n%26)+25)%26;
		s=c+s;
		if(n%26==0)
			n--;
		n/=26;
	}
	cout<<s<<endl;
}


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

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int x = sc.nextInt();
        int y = sc.nextInt();

        int total = x + (y / 2);

        System.out.println(total);

        }
    }









Measured memory_bytes: 21844
#include<stdio.h>
#include<string.h>
#include<math.h>
int main(){
  int data[100],top=0;
  char s[101];
  while(scanf("%s", s) != EOF){
    if ( s[0] == '+' ){
        top--;
        data[top-1]=data[top-1]+data[top];
    }
    else if ( s[0] == '-' ){
        top--;
        data[top-1]=data[top-1]-data[top];
    }
    else if ( s[0] == '*' ){
        top--;
        data[top-1]=data[top-1]*data[top];
    }else if ( s[0] == '/' ){
        top--;
        data[top-1]=data[top-1]/data[top];
    }
    else {
      data[top] = atoi(s);
      top++;
    } 
  }
  printf("%d\n",data[0]);
  
  return 0;
}


Measured memory_bytes: 2104
#include <cstdio>
#include <iostream>
#include <algorithm>
#include <cmath>
#include <map>

int main(){
  bool num[100];
  int input,count=0;
  for(int i=0; i<100;i++){
    num[i]=false;
  }
  while(scanf("%d",&input)!=EOF){
    if(!num[input-1]){
      num[input-1]=true;
      count++;
    }
  }
  printf("%d\n",count );
}


Measured memory_bytes: 256
{-# LANGUAGE BangPatterns #-}
{-# LANGUAGE BinaryLiterals #-}
{-# LANGUAGE MultiWayIf #-}
{-# LANGUAGE NumDecimals #-}
{-# LANGUAGE ScopedTypeVariables #-}
{-# LANGUAGE TupleSections #-}

import Control.Applicative
import Control.Arrow
import Control.Monad
import Control.Monad.ST

import Data.Char
import Data.List
import Data.Maybe

import qualified Data.ByteString.Char8 as B

import Data.Array.ST.Safe
import Data.STRef

import Debug.Trace
import Text.Printf

readInt = readLn :: IO Int
readInts = map ( fst . fromJust . B.readInt ) . B.words <$> B.getLine
readNInts = readInt >>= flip replicateM readInt

which a b f = if f then a else b
mp [ a, b ] = ( a, b )

main = readInts >>= print . sum . tail . reverse . sort

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

int main() {
    int r, g, b;
    cin >> r >> g >> b;
    int a = r*100+g*10+b;
    if(a%4 == 0)
      cout << "YES" << endl;
    else
      cout << "NO" << endl;
}


Measured memory_bytes: 256
import qualified Data.Vector.Unboxed as VU
import qualified Data.ByteString.Char8 as B
import Data.Char

solve :: Int -> VU.Vector Int -> Int
solve n xs = VU.maximum $ VU.map comp (VU.fromList [0..n-1])
    where
        left = VU.scanl gcd 0 xs
        right = VU.scanr gcd 0 xs
        comp x = gcd (left VU.! x) (right VU.! (x+1))

main = do
    n <- readLn :: IO Int
    xs <- VU.unfoldrN n (B.readInt . B.dropWhile isSpace) <$> B.getLine 
    print $ solve n xs

Measured memory_bytes: 6524
//#include <bits/stdc++.h>
#include <iostream>
#include <complex>
#include <sstream>
#include <string>
#include <algorithm>
#include <deque>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <vector>
#include <set>
#include <limits>
#include <cstdio>
#include <cctype>
#include <cmath>
#include <cstring>
#include <cstdlib>
#include <ctime>
#include <climits>
#define REP(i, n) for(int i = 0; i < (int)(n); i++)
#define FOR(i, j, k) for(int i = (int)(j); i < (int)(k); ++i)
#define ROF(i, j, k) for(int i = (int)(j); i >= (int)(k); --i)
#define FORLL(i, n, m) for(long long i = n; i < (long long)(m); i++)
#define SORT(v, n) sort(v, v+n)
#define REVERSE(v) reverse((v).begin(), (v).end())

using namespace std;
using ll = long long;
const ll MOD=1000000007LL;
typedef pair<int, int> P;

ll ADD(ll x, ll y) { return (x+y) % MOD; }
ll SUB(ll x, ll y) { return (x-y+MOD) % MOD; }
ll MUL(ll x, ll y) { return x*y % MOD; }
ll POW(ll x, ll e) { ll v=1; for(; e; x=MUL(x,x), e>>=1) if (e&1) v = MUL(v,x); return v; }
ll DIV(ll x, ll y) { /*assert(y%MOD!=0);*/ return MUL(x, POW(y, MOD-2)); }


int
main(void){  
  ll k;
  string s;
  cin >> s >> k;
  
  if(s.size() == 1){
    cout << s[0] << endl;
  }
  else{
      ll j = 0;
      ll count = 0;      
      for(;j<k;j++){
	if(s.size() == j) break;
	if(s[j] == '1') count++;
	else break;	  
      }      
      if(count >= k) cout << "1" << endl;
      else cout << s[count] << endl;
  }

  return 0;
}


Measured memory_bytes: 256
# coding:utf-8

K = int(input())
if K < 10:
    print(K)
    exit(0)

runrun_list = [n for n in range(10)]
idx = 1
cnt = 9

while True:
    prefix_str = str(runrun_list[idx])
    prefix = int(prefix_str) * 10
    add_idx = int(prefix_str[-1])

    if add_idx == 0:
        start = 0
        stop = 2
    elif add_idx == 9:
        start = 8
        stop = 10
    else:
        start = add_idx - 1
        stop = (add_idx - 1) + 3

    for n in range(start, stop):
        runrun_list.append(prefix + n)
        cnt += 1
        if cnt == K:
            print(runrun_list[-1])
            exit(0)
    idx += 1


Measured memory_bytes: 7320
#coding: utf-8
import math
import heapq
import bisect
import numpy as np
#from scipy.misc import comb

N = int(input())

prime = [2,3,5,7,11,13,17,19,23,29,31,37,41,43,47,53,59,61,67,71,73,79,83,89,97]
p_cnt = [0]*25

for i in range(2,N+1):
    p_index = 0
    while i > 1:
        if i%prime[p_index] == 0:
            p_cnt[p_index] += 1
            i /= prime[p_index]
        else:
            p_index += 1

ans = 0

for i in range(25):
    if p_cnt[i] >= 74:
        ans += 1

for i in range(25):
    for j in range(i+1,25):
        if p_cnt[i] >= 2 and p_cnt[j] >= 24:
            ans += 1
        if p_cnt[i] >= 24 and p_cnt[j] >= 2:
            ans += 1
        if p_cnt[i] >= 4 and p_cnt[j] >= 14:
            ans += 1
        if p_cnt[i] >= 14 and p_cnt[j] >= 4:
            ans += 1

for i in range(25):
    for j in range(i+1,25):
        for k in range(j+1,25):
            if p_cnt[i] >= 2 and p_cnt[j] >= 4 and p_cnt[k] >= 4:
                ans += 1
            if p_cnt[i] >= 4 and p_cnt[j] >= 2 and p_cnt[k] >= 4:
                ans += 1
            if p_cnt[i] >= 4 and p_cnt[j] >= 4 and p_cnt[k] >= 2:
                ans += 1

print(ans)
# 74, 2*24, 4*14, 2*4*4

Measured memory_bytes: 12220
#include<cstdio>
#include<algorithm>
#include<vector>
#include<queue>
#include<cstring>
#include<map>
#define NO {puts("No");continue;}
#define YES {puts("Yes");continue;}
using namespace std;
const int MAXN=int(1e5+5);
#define INF int(1e9+5)
typedef long long LL;
int T,n;
LL A;
map<LL,int>cnt;
vector<LL>G;
int main()
{
    //scanf("%d",&T);
    T=1;
    while(T--) {
        G.clear();
        cnt.clear();
        scanf("%d",&n);
        int t=0;
        for(int i=1;i<=n;i++) {
            scanf("%lld",&A);
            if(cnt[A]==0) {
                t++;
                G.push_back(A);
            }
            cnt[A]++;
        }
        if(cnt[0]==n)
            YES;
        if(t>3||n%3!=0)
            NO;
        if(t==1)
            NO;
        if(t==2) {
            if(cnt[0]==n/3)
                YES;
            NO;
        }
        LL d=G[0]^G[1]^G[2];
        if(d==0LL&&cnt[G[0]]==n/3&&cnt[G[1]]==n/3&&cnt[G[2]]==n/3)
            YES;
        NO;
    }
}
/*
4 5 6
0 3
0 1 5
1 2 5
2 3 5
0 3 5
1 3 5
*/


Measured memory_bytes: 5620
from heapq import heappop, heappush
class MedianContainer:
    def __init__(self):
        self._left_q = []
        self._right_q = []
        self._left_sum = 0
        self._right_sum = 0
        self._med1, self._med2 = None, None
        self._med = None

    def insert(self, x):
        if not any([self._med, self._med1, self._med2]): # First insert
            self._med = x
        elif self._med is None and self._med1 is not None and self._med2 is not None:
            if x <= self._med1:
                heappush(self._left_q, x*(-1))
                heappush(self._right_q, self._med2)
                self._left_sum += x
                self._right_sum += self._med2
                self._med = self._med1
            elif x >= self._med2:
                heappush(self._left_q, self._med1*(-1))
                heappush(self._right_q, x)
                self._left_sum += self._med1
                self._right_sum += x
                self._med = self._med2
            else:
                heappush(self._left_q, self._med1*(-1))
                heappush(self._right_q, self._med2)
                self._left_sum += self._med1
                self._right_sum += self._med2
                self._med = x
            self._med1, self._med2 = None, None
        else:
            if x <= self._med:
                heappush(self._left_q, x*(-1))
                self._med1 = heappop(self._left_q)*(-1)
                self._left_sum += x
                self._left_sum -= self._med1
                self._med2 = self._med
            else:
                heappush(self._right_q, x)
                self._right_sum += x
                self._med1 = self._med
                self._med2 = heappop(self._right_q)
                self._right_sum -= self._med2
            self._med = None

        
    def get_med(self):
        if self._med is not None:
            return [self._med]
        else:
            return [self._med1, self._med2]


    def get_left_sum(self):
        return self._left_sum


    def get_right_sum(self):
        return self._right_sum


    def get_half_len(self):
        return len(self._left_q)

q = int(input())
const_b = 0
ansl = []

mc = MedianContainer()
for _ in range(q):
    row = list(input().split())
    if row[0] == '2':
        half_len = mc.get_half_len()
        meds = mc.get_med()
        if len(meds) == 1:
            left_sum = meds[0]*half_len - mc.get_left_sum()
            right_sum = mc.get_right_sum() - meds[0]*half_len
            ans = left_sum + right_sum + const_b
            ansl.append((meds[0],ans))
        else:
            left_sum = meds[0]*half_len - mc.get_left_sum()
            right_sum = mc.get_right_sum() - meds[0]*half_len
            ans = left_sum + right_sum + (meds[1]-meds[0]) + const_b
            ansl.append((meds[0],ans))
    
    else:
        a,b = int(row[1]), int(row[2])
        const_b += b
        mc.insert(a)


for ax,av in ansl:
    print(ax,av)

Measured memory_bytes: 93276
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (int)(n); i++)
#define REP(i,n) for (int i = 1; i < (int)(n); i++)
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(),x.rend()
#define vout(x) rep(i,x.size()) cout << x[i] << " "
template<class T> bool chmin(T &a, T b) {if(a>b) {a=b;return 1;}return 0;}
template<class T> bool chmax(T &a, T b) {if(a<b) {a=b;return 1;}return 0;}
using namespace std;
using vint = vector<int>;
using vvint = vector<vector<int>>;
using ll = long long;
using vll = vector<ll>;
using vvll = vector<vector<ll>>;
using P = pair<int,int>;
const int inf = 1e9+7;
const ll inf_l = 1e18;
const int MAX = 1e6;

int main() {
    int n; cin >> n;
    vint a(n), b(n);
    rep(i,n) cin >> a[i];
    rep(i,n) cin >> b[i];
    ll ct_a = 0, ct_b = 0;
    rep(i,n) {
        if (a[i] > b[i]) ct_b += a[i] - b[i];
        if (a[i] < b[i]) ct_a += (b[i]-a[i])/2;
    }
    if (ct_b <= ct_a) cout << "Yes" << endl;
    else cout << "No" << endl;
}

Measured memory_bytes: 384
a,v=map(int,input().split())
b,w=map(int,input().split())
t=int(input())
if a<b and v<=w:
    print("NO")
elif w>v:
    print("NO")
else:
    if abs(b-a)<=t*abs(v-w):
        print("YES")
    else:
        print("NO")


Measured memory_bytes: 61788
using System;
using System.Linq;
namespace ConsoleApp11
{
    class MainClass
    {
        public static void Main()
        {
            string[] str = Console.ReadLine().Split();
            int N = int.Parse(str[0]);
            int K = int.Parse(str[1]);

            str = Console.ReadLine().Split();
            var h = str.Where(x=>int.Parse(x)>=K).Select(x => int.Parse(x));

            Console.WriteLine(h.Count());
        }
    }
}

Measured memory_bytes: 17760
#include<bits/stdc++.h>
#define int long long
using namespace std;
const int N=59,M=109;
struct edge{int to,nxt,a,w;}e[M*2]; int hd[N],tot;
void add(int u,int v,int a,int w){e[++tot]=(edge){v,hd[u],a,w};hd[u]=tot;}
int n,m,s; int maxs; int c[N],d[N]; int dis[N][N*N],ans[N];
struct node{
	int u,sil,f;
	bool operator < (const node b)const{return f>b.f;}
	bool operator > (const node b)const{return f<b.f;}
};
void dijkstra(){
	memset(dis,0x3f,sizeof(dis)); memset(ans,0x3f,sizeof(ans));
	priority_queue<node>q; q.push((node){1,s}); dis[1][s]=0;
	while(!q.empty()){
		int u=q.top().u,sil=q.top().sil; q.pop();
		ans[u]=min(ans[u],dis[u][sil]);
		for(int i=hd[u],v;i;i=e[i].nxt){
			if(e[i].a<=sil&&dis[v=e[i].to][sil-e[i].a]>dis[u][sil]+e[i].w)
				q.push((node){v,sil-e[i].a,dis[v][sil-e[i].a]=dis[u][sil]+e[i].w});
		}
		if(sil<maxs&&dis[u][min(sil+c[u],maxs)]>dis[u][sil]+d[u])
			q.push((node){u,min(maxs,sil+c[u]),dis[u][min(sil+c[u],maxs)]=dis[u][sil]+d[u]});
	}
}
signed main(){
	scanf("%lld%lld%lld",&n,&m,&s);
	for(int i=1,u,v,a,w;i<=m;i++)
		scanf("%lld%lld%lld%lld",&u,&v,&a,&w),add(u,v,a,w),add(v,u,a,w),maxs+=a;
	s=min(s,maxs);
	for(int i=1;i<=n;i++) 
		scanf("%lld%lld",&c[i],&d[i]);
	dijkstra();
	for(int i=2;i<=n;i++) printf("%lld\n",ans[i]);
	return 0;
}

Measured memory_bytes: 7900
#include <iostream>
#include <vector>
#include <algorithm>
#include <queue>
#include <string>
#include <set>
#include <math.h>
#include <map>
#include <stack>
using namespace std;
static const int INF = 1e9+7;
// 型定義
typedef long long ll;
typedef pair<ll, ll> P;

#define rep(i, n) for (int i = 0; i < n; i++)
#define repr(i, a, b) for (int i =a; i < b; i++)
#define all(a) a.begin(), a.end()
#define PI 3.14159265359

int main(){
    string s; cin >> s;
    stack<char> result;
    rep(i,s.size()){
        if(s[i] == '0' || s[i] =='1'){
            result.push(s[i]);
        }else if(!result.empty()){
            result.pop();
        }
    }
    string ans = "";
    int len = result.size();
    rep(i,len){
        ans += result.top();
        result.pop();
    }
    reverse(all(ans));
    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 3572
#include <bits/stdc++.h>
#define rep(i, n) REP(i, 0, n)
#define REP(i, l, r) for (int i = l; i < r; ++i)
#define int long long
#ifdef DEBUG
#define dout cout
#else
std::stringstream dout;
#endif
using namespace std;
typedef pair<int, int> P;
// other libs

signed main(int argc, char* argv[]) {
	const int mod = 1e9 + 7;
	int n, k, a[2000];
	int cnt1 = 0, cnt2 = 0;
	cin >> n >> k;
	rep(i, n) cin >> a[i];
	rep(i, n) {
		rep(j, n) {
			if (a[i] > a[j]) {
				if (j > i)
					cnt1++;
				else
					cnt2++;
			}
		}
	}
	dout << cnt1 << " " << cnt2 << endl;
	int ans = 0;
	if (cnt1)
		ans += cnt1 * (k * (k + 1) / 2 % mod) % mod;
	ans %= mod;
	if (cnt2)
		ans += cnt2 * (k * (k - 1) / 2 % mod) % mod;
	cout << ans % mod << endl;
}

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

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

typedef pair<int, int> P;
typedef pair<llong, llong> LP;
typedef pair<int, P> PP;
typedef pair<llong, LP> LPP;

int iy[]={0, 0, 1, -1};
int ix[]={1, -1, 0, 0};

int n, m;
vector<int> c(21);
vector<int> T(500002, INF);

int main(){
	
	cin >> n >> m;
	T[0] = 0;
	FOR(i, 0, m)
		cin >> c[i];
	FOR(i, 0, m)
		FOR(j, c[i],n + 1)
			T[j] = min(T[j], T[j - c[i]] + 1);
	cout << T[n] << endl;
	return 0;
}
//??????????????????...


Measured memory_bytes: 4496
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define zero_pad(num) setfill('0') << std::right << setw(num)
using namespace std;
using ll = long long;
using ld = long double;
using P = pair<int, int>;

int main() {
    int k, s;
    cin >> k >> s;
    int ans = 0;
    rep(x, k + 1)rep(y, k + 1){
        int z = s - x - y;
        if(z >= 0 && z <= k)ans++;
    }
    cout << ans << endl;
}

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

int main() {
  	string A, B;
    cin >> A >> B;
    int a=A.size(), b=B.size();
    vector<char> X(a);
    for (int i=0; i<a; i++){
    	X[i]=A[i];
    }
    vector<char> Y(b);
    for (int i=0; i<b; i++){
    	Y[i]=B[i];
    }
    sort (X.begin(),X.end());
    sort (Y.begin(),Y.end());
    reverse (Y.begin(),Y.end());
    for (int i=0; i<a; i++){
    	A[i]=X[i];
    }
    for (int i=0; i<b; i++){
    	B[i]=Y[i];
    }
    if (A<B) cout << "Yes" << endl;
    else cout << "No" << endl;
}


Measured memory_bytes: 3664
def dfs(i,sum1,sum2):
    global ans
    #print(sum1,sum2)
    if i == 4 and sum1 != 7:
        return 0
    elif i == 4 and sum1 == 7:
        ans = sum2 + "=7"
    else:
        dfs(i + 1,sum1 - int(s[i]),sum2 + "-" +s[i])
        dfs(i + 1,sum1 + int(s[i]),sum2 + "+" +s[i])

ans = ""
s = input()
dfs(1,int(s[0]),s[0])
print(ans)

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

int main() {
  long long A, B, K;
  cin >> A >> B >> K;
  if (A >= K) {
    cout << A - K << " " << B;
  } else {
    if (B >= K - A) {
      cout << 0 << " " << B - (K - A);
    } else {
      cout << 0 << " " << 0;
    }
  }
  return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
int increment(int array[],int n)
{
  if(array[n] ==0){
    array[n]++;
    return n;
  }
  else if(array[n] == 1)
    {
      array[n] = 0;
      return increment(array,n+1);
    }
}

int main()
{
  int point=0,i,s[100],N,max=0,bool[100]={0};
  scanf("%d",&N);
  for(i=0;i<N;i++)
    scanf("%d",&s[i]);
    point = 0;
    for(i=0;i<N;i++)
      point += s[i];
    if(!(point % 10)){
      for(i=0;i<N;i++)
        if((point - s[i]) % 10)
          if(max < point - s[i])
            max = point - s[i];
    }else
      max = point;
  printf("%d\n",max);
  return 0;
  
}


Measured memory_bytes: 128
#include <iostream>
#include <vector>
#include <string>
#include <numeric>
#include <tuple>
#include <algorithm>
using namespace std;
#define rep(i,n) for(int i=0; i<n; ++i)

int main() {
    int n;
    cin >> n;
    vector<int> h(n);
    rep(i,n) cin >> h[i];

    vector<int> dp(n);
    for (int i=1; i<n; ++i) {
        int c1 = dp[i-1]+abs(h[i-1]-h[i]);
        if (i == 1) {
            dp[i] = c1;
            continue;
        }
        int c2 = dp[i-2]+abs(h[i-2]-h[i]);
        dp[i] = min(c1,c2);
    }

    cout << dp[n-1] << endl;
    return 0;
}


Measured memory_bytes: 3592
import math
a, b, n = map(int, input().split())

if (b != 1):
  if (n >=b):
    x=math.floor(n/b)*b-1
    print (math.floor(a*x/b)-a*math.floor(x/b))
  else:
    print (math.floor(a*n/b)-a*math.floor(n/b))
else:
  print (0)


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

#define rep(i,n) for(int i=0;i<n;i++)
#define REP(i,s,n) for(int i=(s);i<(n);i++)
#define repr(i,n) for(int i=n-1;i>=0;i--)
#define REPR(i,s,n) for(int i=(s);i>=(n);i--)
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
#define pb push_back
#define pf push_front
#define mod 1e9 +7;

typedef long long ll;
typedef vector<ll> vll;

ll gcd(ll x,ll y)
{
    ll r;
    while((r = x % y) != 0)
    {
        x = y;
        y = r;
    }
    return y;
}

ll lcm(ll x,ll y)
{
    x /= gcd(x,y);
    y /= gcd(x,y);
    return (x*y);
}

string to_bin_string(ll n){
    stringstream ss;
    ss << bitset<8>(n); //任意の桁数<m>
    string s = ss.str();
    return s;
}
int main()
{
    ll k, n;
    cin >> k >> n;
    vll a(n);
    ll md = -1;
    rep(i,n)cin >> a[i];
    REP(i,1,n)md = max(abs(a[i] - a[i-1]), md);
    md = max(md, k - a[n-1] + a[0]);
    cout << k - md << endl;
    return 0;
} 

Measured memory_bytes: 1792
#include<cstdio>
#include<bits/stdc++.h>
typedef long long int ll;
#define REP(i, n) for(int i = 0; i < (n); i++)
#define FOR_IN(i, a, b) for(int i = (a); i < (b); i++)
#define BETWEEN(x, a, b) ((x) >= (a) && (x) <= (b))
#define BIT(b, i) (((b) >> (i)) & 1)
#define LOG_F 1
#define LOG(...) if(LOG_F) fprintf(stderr, __VA_ARGS__)

using namespace std;

ll pow(int x, int n){
  return n == 0 ? 1 : x * pow(x, n - 1);
}


/*

 */
char a,b;
char hd[] = {'H','D'};

int main(){
  cin >> a >> b;
  int b1;
  if(b=='H')
    b1 = 0;
  else
    b1 = 1;

  
  if(a=='H')
    cout << hd[b1] << endl;
  else
    cout << hd[1-b1] << endl;

  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = int64_t;
using P = pair<ll, ll>;
using mat = vector<vector<ll>>;

inline void IOS() { ios::sync_with_stdio(false), cin.tie(0); }

template <typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val){
	fill((T *)array, (T *)(array + N), val);
}

const ll INF = 1e16;
const ll MOD = 1e9 + 7;
//int dx[4] = {1,0,-1,0};
//int dy[4] = {0,1,0,-1};
//ll pas[5001][5002];

vector<ll> g[114514];
bool used[114514] = {};
ll dp[114514] = {};
ll n;

P rec(int i){
	used[i] = true;
	bool unko = true;
	ll w = 1, b = 1;
	for (int j = 0;j < g[i].size();++j) {
		int to = g[i][j];
		if(used[to])continue;
		P nw = rec(to);
		w *= nw.first + nw.second;
		b *= nw.first;
		w %= MOD;
		b %= MOD;
	}
	return make_pair(w, b);
}

signed main(){
	IOS();
	cin >> n;
	for (int i = 0;i < n - 1;++i) {
		int x, y;
		cin >> x >> y;
		g[x].push_back(y);
		g[y].push_back(x);
	}
	P ans = rec(1);
	cout << (ans.first + ans.second) % MOD << endl;
	
}

Measured memory_bytes: 11776
#include<bits/stdc++.h>
#define INF 9223372036854775807LL
#define inf 1000000007
#define SYOU(x) setprecision(x+1)
#define lol long long
#define mp make_pair
#define fi first
#define se second
using namespace std;
lol abs(lol x,lol y){return(x>y?x-y:y-x);}
lol max(lol x,lol y){if(x>y)return x;return y;}
lol min(lol x,lol y){if(x<y)return x;return y;}

string s;
int n;
lol mem[1000010][5];
lol dp(lol jun,bool oo){
  if(jun==n) return 0;
  if(mem[jun][oo]!=-1) return mem[jun][oo];
  lol u;
  if(oo){
    u = min(dp(jun+1,false),dp(jun+1,true)-(jun+1==n?0:1));
    u += '9'-s[jun]+1;
  }else{
    u = min(dp(jun+1,false),dp(jun+1,true)+1);
    u += s[jun]-'0';
  }
  //cout <<jun<<' '<<oo<<' '<<u<<'\n';
  return mem[jun][oo]=u;
}
signed main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    cin >>s;
    n=s.size();
    memset(mem,-1,sizeof(mem));
    cout <<min(dp(0,false),dp(0,true)+1)<<'\n';
    return (0);
}


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

// iterator
#define REP(i,from, to) for(lli i=from;i<to;i++)
#define REPE(i,from, to) for(lli i=from;i<=to;i++)
#define REP_R(i,from, to) for(lli i=from;i>to;i--)
#define REPE_R(i,from, to) for(lli i=from;i>=to;i--)
#define REPIT(it,container) for(auto it = container.begin(); it != container.end(); it++)
#define REPIT_R(it,container) for(auto it = container.rbegin(); it != container.rend(); it++)

// input
#define cin1(x)             cin >> x
#define cin2(x, y)          cin >> x >> y
#define cin3(x, y, z)       cin >> x >> y >> z
#define ncin1(n, x)         REP(i, 0, n) {cin1(x[i]);}
#define ncin2(n, x, y)      REP(i, 0, n) {cin2(x[i], y[i]);}
#define ncin3(n, x, y, z)   REP(i, 0, n) {cin3(x[i], y[i], z[i]);}

// output
#define cout1(x)         cout << #x << ": " << x << endl;
#define cout2(x, y)      cout << #x << ": " << x << ", " << #y << ": " << y << endl;
#define cout3(x, y, z)   cout << #x << ": " << x << ", " << #y << ": " << y << ", " << #z << ": " << z << endl;;
#define ncout1(n, x)     REP(i, 0, n) {cout << #x << "[" << i << "]: "<< x[i] << endl;}

#define coutp(p)         cout << #p << ":" <<  " (" << p.first << ", " << p.second << ")" << endl;

// sort
#define sort_r(x, y)        sort(x, y, greater<lli>()); // 降順(5,4,3,,,)

#define ARRAY_LENGTH(array) (sizeof(array) / sizeof(array[0]))

typedef long long int lli;
typedef pair<lli, lli> P;
typedef tuple<lli, lli, lli> tup;
typedef vector<lli> vlli;

P table[90001];
lli costs[90001];
int main() {
    lli h,w,d;
    cin3(h,w,d);
    //cout3(h,w,d);
    lli a[h+1][w+1];
    REPE(i,1,h) {
        REPE(j,1,w) {
            cin >> a[i][j];
            table[a[i][j]] = P(i,j);
        }
    }
    lli q;
    cin1(q);
    lli l[q];
    lli r[q];
    ncin2(q, l, r);


    //REPE(i,1,d) {
    //    lli total = 0;
    //    for(lli j = i; j <= h*w; j += d) {
    //        lli cur = 
    //        // i => j のコストを保存する
    //        cost[j] = 100;
    //    }
    //}
    REPE(from,1,h*w) {
        lli to = from + d;
        if (to > h*w)
            break;
        // from => to を計算
        P f = table[from];
        P t = table[to];
        lli cur_cost = abs(f.first - t.first) + abs(f.second - t.second);
        costs[to] = costs[from] + cur_cost;
    }
    //REP(i,1,h*w) {
    //    cout2(i,costs[i]);
    //}

    REP(i,0,q) {
        cout << costs[r[i]] - costs[l[i]] << endl;
    }
}


// 1 => 4 => 7 => 10
// 1 => 4: 8
// 1 => 7: 15
// 1 => 10: 30
//
//
//
//13  25  7 15 17
//16  22 20  2  9
//14  11 12  1 19
//10   6 23  8 18
// 3  21  5 24  4


Measured memory_bytes: 5504
#include<stdio.h>
int p[200005];
int root(int n)
{
	if (p[n] == n)
		return n;
	p[n] = root(p[n]);
	return p[n];
}
void f(int x, int y)
{
	if (root(x) == root(y))
		return;
	p[root(x)] = root(y);
	return;
}
int main()
{
	int n, m;
	scanf("%d %d", &n, &m);
	int i, j;
	int k, l[200005], r;
	for (i = 0; i <= m + n; i++)
		p[i] = i;
	for (i = 0; i < n; i++)
	{
		scanf("%d", &k);
		for (j = 0; j < k; j++)
		{
			scanf("%d", &r);
			f(i + 1, n + r);
		}
	}
	f(0, 1);
	for (i = 1; i <= n; i++)
	{
		if (root(0) != root(i))
		{
			printf("NO\n");
			return 0;
		}
	}
	printf("YES\n");
	return 0;
}

Measured memory_bytes: 1280
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
#define DUMP(x) cout << #x << " = " << (x) << endl;
#define FOR(i, m, n) for (ll i = m; i < n; i++)
#define IFOR(i, m, n) for (ll i = n - 1; i >= m; i--)
#define REP(i, n) FOR(i, 0, n)
#define IREP(i, n) IFOR(i, 0, n)
#define FOREACH(x, a) for (auto&(x) : (a))
#define ALL(v) (v).begin(), (v).end()
#define SZ(x) ll(x.size())

template <class T>
inline bool chmax(T& a, T b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}

int main() {
  ll n;
  cin >> n;
  vector<ll> a(n);
  REP(i, n) { cin >> a[i]; }
  const ll INF = 1e18;
  vector<vector<vector<ll>>> dp(n + 1,
                                vector<vector<ll>>(2, vector<ll>(2, -INF)));
  dp[0][1][0] = 0;
  REP(i, n) {
    REP(j, 2) {
      REP(k, 2) if (dp[i][j][k] != -INF) {
        if (i % 2 == 1) {
          chmax(dp[i + 1][j][0], dp[i][j][k]);
        } else {
          chmax(dp[i + 1][0][0], dp[i][1][k]);
        }
        if (i % 2 == 1) {
          chmax(dp[i + 1][1][1], dp[i][0][0] + a[i]);
        } else {
          chmax(dp[i + 1][j][1], dp[i][j][0] + a[i]);
        }
      }
    }
  }
  int b = !(n % 2 == 1);
  cout << max(dp[n][b][0], dp[n][b][1]) << endl;
}


Measured memory_bytes: 34420
// 以下のソースを勉強する.
// zscoder氏.
// https://atcoder.jp/contests/dp/submissions/3939142
#include <bits/stdc++.h>
using namespace std;
 
const int MOD = (1e9 + 7);
int add(int a, int b){
    a += b;
    while(a >= MOD) a -= MOD;
    return a;
}

int a[111];
int dp[111][111111];
int S[111][111111];

int sum(int i, int l, int r){
    l = max(l, 0);
    if(l > r)  return 0;
    if(l == 0) return S[i][r];
    else       return add(S[i][r], MOD - S[i][l - 1]);
}

int main(){
    
    // 1. 入力情報取得.
    int N, K;
    scanf("%d %d", &N, &K);
    for(int i = 1; i <= N; i++) scanf("%d", &a[i]);
    
    // 2. dp更新.
    dp[0][0] = 1;
    for(int i = 0; i <= K; i++) S[0][i] = 1;
    for(int i = 1; i <= N; i++){
        for(int j = 0; j <= K; j++) dp[i][j] = sum(i - 1, j - a[i], j);
        for(int j = 0; j <= K; j++){
            S[i][j] = dp[i][j];
            if(j > 0) S[i][j] = add(S[i][j], S[i][j - 1]);
        }
    }
    // for(int i = 0; i <= N; i++){
    //     for(int j = 0; j <= K; j++) printf("%d ", dp[i][j]);
    //     printf("\n");
    // }
    
    // 3. 出力.
    printf("%d\n", dp[N][K]);
    return 0;
}

Measured memory_bytes: 90240
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(ll i=0;i<n;i++)
using ll=long long;
using vl=vector<ll>;
using vvl=vector<vector<ll>>;
void dfs(ll v,ll par,set<ll> &st,vl &ans, vvl &g){
    for(auto nv:g[v]){
        if(ans[nv]==-1){
            ans[nv]=v;
            st.insert(v);dfs(nv,v,st,ans,g);st.erase(v);
        }
        else{
            if(st.count(ans[nv]))ans[nv]=v;
        }
    }
}
int main(){
    ll n,m;cin >>n >>m;
    vvl g(n);
    vl ans(n,-1);
    set<ll> st;rep(i,n)st.insert(i);
    rep(i,n-1+m){
        ll a,b;cin >> a >> b;a--;b--;
        g[a].push_back(b);
        st.erase(b);
    }
    ll s=*st.begin();st.clear();
    dfs(s,-1,st,ans,g);
    for(auto p:ans)cout << p+1 <<endl;
} 

Measured memory_bytes: 24816
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cmath>
#include<vector>
#include<map>
#include<set>
#include<string>
#include<queue>
#include<stack>
using namespace std;
#define MOD 1000000007
#define INF (1<<29)
#define LINF (1LL<<60)
#define EPS (1e-10)
typedef long long Int;
typedef pair<Int, Int> P;


Int last[216000];
Int bef[216000];
Int nxt[216000];
Int n, k, a[216000];
Int come[216000];
bool exist[216000];
int main(){
    cin >> n >> k;
    fill(last, last+216000, -1);
    for(Int i = 0;i < n;i++){
        cin >> a[i];
        bef[i] = last[a[i]];
        last[a[i]] = i;
    }
    for(Int i = 0;i < n;i++){
        if(bef[i] == -1){
            bef[i] = last[a[i]];
        }
        nxt[bef[i]] = i;
    }
    Int now = 0;
    Int tm = 0;
    do{
        Int nxtt = nxt[now];
        tm += nxtt - now;
        if(nxtt <= now)tm += n;
        tm++;
        now = nxtt+1;
        now %= n;
        come[now] = tm;
    }while(now != 0);
    Int rem = n * k % come[0];
    while(true){
        Int nxtt = nxt[now];
        tm = nxtt - now;
        if(nxtt <= now)tm += n;
        if(rem - tm > 0)rem -= tm;
        else break;
        rem--;
        now = nxtt + 1;
        now %= n;
    }
    vector<Int> vec;
    for(Int i = 0;i < rem;i++){
        if(exist[a[now]]){
            while(exist[a[now]]){
                exist[vec.back()] = false;
                vec.pop_back();
            }
        }
        else{
            exist[a[now]] = true;
            vec.push_back(a[now]);
        }
        now++;now %= n;
    }
    if(now != 0)return 1;
    for(Int v:vec)cout << v << " ";
    cout << endl;
    return 0;
}

Measured memory_bytes: 11760
#include <bits/stdc++.h>
#define int long long

using namespace std;

int n, a[100005], mx = -9999999999;
map<int, int> mp;

main()
{
    cin >> n;
    for (int i = 1; i <= n; ++i)
    {
        cin >> a[i];
        mp[a[i]]++;
    }
    for (int i = 1; i <= 100005; ++i)
    {
        if (mp[i - 1] + mp[i] + mp[i + 1] > mx)
            mx = mp[i - 1] + mp[i] + mp[i + 1];
    }
    cout << mx;
}


Measured memory_bytes: 7296
#include <iostream>
#include <cstdio>
#include <stack>
using namespace std;
int main(void)
{
	int n,i,j;
	stack<int>s1,s2;
	int table[10];
	cin >> n;
	for(i=0;i<n;i++)
	{
		for(j=0;j<10;j++)
		{
			cin >> table[j];
		}
		s1.push(0);
		s2.push(0);
		for(j=0;j<10;j++)
		{
			if(s1.top()<table[j])
			{
				if(s2.top()<table[j])
				{
					if(s1.top()>s2.top())
					{
						s1.push(table[j]);
					}
					else
					{
						s2.push(table[j]);
					}
				}
				else
				{
					s1.push(table[j]);
				}
			}
			else
			{
				break;
			}
		}
		if(j==10)cout <<"YES"<< endl;
		else cout << "NO" << endl;
	}
	return 0;
}

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

const int MAXN = 100005;

struct node {
	int to, next;
} edge[MAXN*2];
int head[MAXN], top = 0;
inline void push(int i, int j)
{ edge[++top] = (node) {j, head[i]}, head[i] = top; }

int n, x, y;

int dp[MAXN];

void dfs(int nd, int f)
{
	for (int i = head[nd]; i; i = edge[i].next) {
		int to = edge[i].to;
		if (to == f) continue;
		dfs(to, nd), dp[nd] ^= dp[to]+1;
	}
}

int main()
{
	ios::sync_with_stdio(false);
	cin >> n;
	for (int i = 2; i <= n; i++) {
		cin >> x >> y;
		push(x, y), push(y, x);
	}
	dfs(1, 0);
	if (dp[1] != 0) cout << "Alice" << endl;
	else cout << "Bob" << endl;
	return 0;
}


Measured memory_bytes: 7296
H, W = map(int, input().split())
S = []
rng = [-1 , 0, 1]
for _ in range(H):
    S.append([0 if val == '.' else val for val in input()])

for i in range(H):
    for j in range(W):
        if S[i][j] == '#':
            for m in rng:
                tmp_i = i + m
                if tmp_i < 0:
                    continue
                for n in rng:
                    tmp_j = j + n
                    if tmp_j < 0:
                        continue
                    try:
                        S[tmp_i][tmp_j] += 1
                    except:
                        pass

for k in range(H):
    print(''.join(map(str, S[k])))

Measured memory_bytes: 3064
n = int(input())
a = [int(input()) for _ in range(n)]
a.sort()
b = []
for I in range(n-1):
 b.append(a[I+1]-a[I])
s = 0
if n%2 == 0:
 for j in range(int(n/2)-1):
  s += 2*(j+1)*(b[j] + b[n-j-2])
 s += b[int(n/2) - 1]*(2*int(n/2)-1)
if n%2 == 1:
 for j in range(int((n-1)/2)):
  s += 2*(j+1)*(b[j] + b[n-j-2])
 s -= min(b[int((n-1)/2)-1],b[int((n-1)/2)])

print(s) 

Measured memory_bytes: 11220
package main

import (
	"fmt"
)

func main() {

	// 読み込み数取得
	var input string
	fmt.Scan(&input)

	max := len(input)
	count := max / 2

	result := 0

	for i := 0; i < count; i++ {
		if input[i:i+1] != input[max-i-1:max-i] {
			result++
		}
	}

	fmt.Printf("%d", result)

}

Measured memory_bytes: 512
// " every champion was once a contender who refused to give up " //
    // eat sleep code repeat :)
    // vectorTango
    // reapedJuggler
                            
    #include "bits/stdc++.h"
                                 
    #define FAST_IO ios::sync_with_stdio(0); cin.tie(0); cout.tie(0)
    #define ld long int
    #define all(A) begin(A) , end(A)
    #define rep(i , a , b)  for(lld i = a; i < b ; i++)
    #define rep1(i , a , b) for(lld i = a ; i >= b ; i--)
    #define lld long long int 
    #define ulld unsigned long long int
    #define input lld* a = new lld [n] 
    #define input1 lld* b = new lld [n] 
    #define vec vector < lld >
    #define pb push_back          
    #define ss second
    #define ff first
    #define inf 999999999999999999
    #define fin -999999999999999999
    #define mod 1000000007
    #define umap unordered_map
    #define mpp make_pair
    #define finish(x) cout << v << " ";
    #define tolower(s)   std::transform(s.begin(), s.end(), s.begin(),[](unsigned char c){ return std::tolower(c); });
                                                      
    using namespace std;
                             
    void start()
    {
      #ifndef ONLINE_JUDGE 
      freopen("input.txt" , "r" , stdin) ;
      freopen("output.txt" , "w" , stdout) ;
      #endif
    } 

  //   vec g[200007];
  //   vec v;
  //   map<lld , bool> vis ; lld siz = 0 , ans = 1 ;

  //    void dfs(lld x , lld dest){
  
  //    vis[x] = 1;

  //    for(auto i : g[x]){
  //     if(!vis[i]){
  //       dfs(i);
  //     }
  //    }

  //    return;
  //   }

  // lld pow1(ulld  a , ulld y){
  //   // a %= mod;
  //   ulld  res = 1;

  //   while(y > 0){

  //     if(y & 1)
  //       res = (res*a)%mod;

  //     y = y >> 1;
  //     a = (a*a)%mod;
  //   }
  //   return res;
  // }

// bool sortbysec(const pair<lld ,lld > &a, const pair<lld ,lld > &b) { 
//   return (a.ss < b.ss); 
// } 
    
void sober(){
lld n , x = 0 , a = 0 , b = 0 , y = 0 , sum = 0 , k = 0 , m = 0;
cin >> n >> k;
bool vis[200055] = {0};
rep(i , 0 , k){
  cin >> x ;
  rep(j  , 0 , x){
    cin >> a;
    vis[a] = 1;
  }
}

rep(i , 1 , n + 1){
  if(!vis[i]){
    sum++;
  }
}
cout << sum << "\n";
return;
}

signed main(){  
  start();  
  FAST_IO;
  lld t = 1; 
  // cin >> t;
  while(t--){
     sober();
  }
}      

//  c0ded by :
// - - - - - - - - - - - - - - - - - - - - - - s 0 b e r and s i m r a n


Measured memory_bytes: 3856
#include <iostream> // cout, endl, cin
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower
#include <math.h>
#include <iomanip>
using namespace std;
#define int long long

int gcd(int c,int d){
    return d ? gcd(d, c % d) : c;
}



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

    int n,m; cin >> n >> m;
    vector<int> h(n),a(m),b(m);
    for(int i = 0;i < n;i ++) cin >> h.at(i);
    for(int i = 0;i < m;i ++) cin >> a.at(i) >> b.at(i);
    for(int i = 0;i < m;i ++){
        a.at(i) --;
        b.at(i) --;
    }

    vector<int> hantei(n,1);
    int ans = 0;

    for(int i = 0;i < m;i ++){
        if(h.at(a.at(i)) <= h.at(b.at(i))) hantei.at(a.at(i)) = 0;
        if(h.at(b.at(i)) <= h.at(a.at(i))) hantei.at(b.at(i)) = 0;
    }

    for(int i = 0;i < n;i ++) ans += hantei.at(i);

    cout << ans << endl;
}



Measured memory_bytes: 6364
#include<stdio.h>
#include<string.h>
#include<math.h>
int main()
{
    int n;
    scanf("%d",&n);
    while(1)
    {
        int i;
        if(n%2==0&&n!=2)
            n=n+1;
        else if(n!=1&&n%2==1&&n!=2)
        {
               for(i=2;i<=sqrt(n);i++)
                    if(n%i==0)
                    break;
               if(i>sqrt(n))
                {
                    printf("%d",n);
                    break;
                }
               else{
                n++;
               }
        }
        else if(n==2||n==1)
        {
            printf("2");
            break;
        }
    }
}


Measured memory_bytes: 888