akhauriyash/Code-Regression huggingface dataset:
//的場梨沙★担当
//結城晴★副担当
//日野茜★副担当
#include <vector>
#include <list>
#include <map>
#include <climits>
#include <set>
#include <unordered_set>
#include <unordered_map>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string.h>
#include <string>
#include <cstring>
#include <ctime>
#include <queue>
#include <random>
#include <cctype>
#include <complex>
#include <regex>
#include <unordered_map>
#include <string>
#include <algorithm>
#include <cctype>
#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <iomanip>
#include <iostream>
#include <stdio.h>
#include <string.h>
#include <vector>
#include <stdio.h>


using namespace std;

int main(void) {
    string S;
    cin>>S;
    int A=0;
    for(int i=0;i<4;i++){
        if(S[i]=='+'){
            A++;
        }
        else{
            A--;
        }
    }

    cout<<A<<endl;
}


Measured memory_bytes: 256
#include <string>
#include <queue>
#include <stack>
#include <vector>
#include <sstream>
#include <algorithm>
#include <deque>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <list>
#include <cstdio>
#include <iostream>
#include <cmath>
#include <climits>
#include <bitset>
#include <functional>
#include <numeric>
#include <ctime>
#include <cassert>
#include <cstring>
#include <fstream>

using namespace std;

void saiki(int *kazu, vector<int> op, int pos, int *result) {
    if (result[0] != 0)
        return;
    if (pos == 3) {
        int res = kazu[0] + kazu[1] * op[0] + kazu[2] * op[1] + kazu[3] * op[2];
        if (res == 7) {
            for (int i = 0; i < 3; i++) {
                result[i] = op[i];
            }
        }
        return;
    }
    op[pos] = 1;
    saiki(kazu, op, pos + 1, result);
    op[pos] = -1;
    saiki(kazu, op, pos + 1, result);


}


int main() {
    string s;
    cin >> s;
    int kazu[4], result[4] = {};
    for (int i = 0; i < 4; i++) {
        kazu[i] = s[i] - '0';
    }
    vector<int> op(3, 0);


    saiki(kazu, op, 0, result);

    cout << kazu[0];
    for (int i = 0; i < 3; i++) {
        cout << (result[i] == 1 ? '+' : '-') << kazu[i + 1];
    }
    cout << "=7" << endl;
    return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
int main(){
	long long int n;
	long long int a[10100];
        long long int cnt=0;
	scanf("%lld",&n);
	for(long long int i=0;i<n;i++){
		scanf("%lld",&a[i]);
	    cnt+=a[i];
	}
	printf("%lld",cnt-n);
	return 0;
} 

Measured memory_bytes: 256
import java.io.*;
import java.math.BigInteger;
import java.nio.charset.IllegalCharsetNameException;
import java.util.*;

public class Main {
    public static void main(String[] args) throws IOException {
        OutputStream outputStream = System.out;
        PrintWriter out = new PrintWriter(outputStream);
        FastReader in = new FastReader();
        test a=new test();
        a.solve(in,out);
        out.close();
    }
}

class test {
    public void solve(FastReader in, PrintWriter out) {
       int n=in.nextInt();
       int b=n%10;
       if(b==3){
           out.println("bon");
       }else if(b==0 || b==1 || b==6 || b==8){
           out.println("pon");
       }else{
           out.println("hon");
       }
    }


}


class FastReader{
    BufferedReader br;
    StringTokenizer st;

    public FastReader(){
        br = new BufferedReader(new InputStreamReader(System.in));
    }

    String next(){
        while(st==null || !st.hasMoreElements()){
            try{
                st=new StringTokenizer(br.readLine());
            }
            catch(IOException e){
                e.printStackTrace();
            }
        }
        return st.nextToken();
    }

    int nextInt(){
        return Integer.parseInt(next());
    }

    Long nextLong(){
        return Long.parseLong(next());
    }

    double nextDouble(){
        return Double.parseDouble(next());
    }
    String nextLine(){
        String str="";
        try{
            str=br.readLine();
        }
        catch(IOException e){
            e.printStackTrace();
        }
        return str;
    }
}


Measured memory_bytes: 32684
class Scanner {
    private var stack = [String]()
    private var index = 0
    
    func peek() -> String {
        if stack.count == index {
            stack += readLine()!.split(separator: " ").map{ String($0) }
        }
        return stack[index]
    }
    
    func next() -> String {
        let value = peek()
        index += 1
        return value
    }
    
    func nextInt() -> Int {
        return Int(next())!
    }
    
    func nextDouble() -> Double {
        return Double(next())!
    }
}

var scanner = Scanner()
var A = [Int]()
for _ in 0 ..< 5 {
    A.append(scanner.nextInt())
}
print(A.firstIndex(where: { $0 == 0 })! + 1)


Measured memory_bytes: 7848
#include <bits/stdc++.h>
typedef long long ll;
typedef long double ld;
const int INF=1e9,MOD=1e9+7,ohara=1e6+10;
const ll LINF=1e18;
using namespace std;

#define rep(i,n) for(int (i)=0;(i)<(int)(n);(i)++)
#define rrep(i,a,b) for(int i=(a);i<(b);i++)
#define rrrep(i,a,b) for(int i=(a);i>=(b);i--)
#define all(v) (v).begin(), (v).end()
#define Size(n) (n).size()
#define Cout(x) cout<<(x)<<endl
#define Cerr(x) cerr<<(x)<<endl
#define fi first
#define se second
#define P pair<ll,ll> 
#define m_p make_pair

ll n,cnt,ans,a,b,c,d,tmp,tmpp,m,h,w,x,y,sum,pos,k,x2,y2;
ld doua;
int dy[]={1,0,-1,0};
int dx[]={0,1,0,-1};
//int dy[]={-1,0,1,-1,1,-1,0,1};
//int dx[]={-1,-1,-1,0,0,1,1,1};
string alph("abcdefghijklmnopqrstuvwxyz"),s;
bool fl;
struct edge{int to,cost;};
P p[ohara];
ll p_cou;
bool vi[ohara];

//-------------------------↓↓↓↓↓↓------------------------

bool border(ll nowy, ll nowx){
    if(nowy==h)return true;
    else if(nowy==0)return true;
    else if(nowx==0)return true;
    else if(nowx==w)return true;
    else return false;
}

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

    cin>>h>>w>>n;
    rep(i,n){
        cin>>y>>x>>y2>>x2;
        if(!border(y,x)||!border(y2,x2))continue;
        if(x==0){
            p[p_cou++]=m_p(h-y,i);
        }
        else if(x==w){
            p[p_cou++]=m_p(y+h+w,i);
        }
        else if(y==0){
            p[p_cou++]=m_p(h+x,i);
        }
        else if(y==h){
            p[p_cou++]=m_p(2*h+w+w-x,i);
        }

        if(x2==0){
            p[p_cou++]=m_p(h-y2,i);
        }
        else if(x2==w){
            p[p_cou++]=m_p(y2+h+w,i);
        }
        else if(y2==0){
            p[p_cou++]=m_p(h+x2,i);
        }
        else if(y2==h){
            p[p_cou++]=m_p(2*h+w+w-x2,i);
        }
    }
    sort(p,p+p_cou);
    stack<ll> st;
    int ok=1;
    rep(i,p_cou){
        if(!vi[p[i].se]){
            vi[p[i].se]=true;
            st.push(p[i].se);
        }
        else{
            if(st.top()==p[i].se){
                st.pop();
            }
            else{
                ok=0;
                break;
            }
        }
    }
    if(ok==0)Cout("NO");
    else Cout("YES");
    return 0;
}


Measured memory_bytes: 5888
N = int(input())
A = sorted(int(a) - i for i, a in enumerate(input().split(), 1))
if N % 2:
    median = A[N // 2]
    print(sum(abs(a - median) for a in A))
else:
    median1 = A[N // 2 - 1]
    median2 = A[N // 2]
    print(min(sum(abs(a - median1) for a in A), sum(abs(a - median2) for a in A)))


Measured memory_bytes: 31180
a = [list(map(int,input().split())) for i in range(3)]
n  = int(input())

#b  = list(map(int,input().split()) for i in range(n))
for i in range(n):
    b = int(input())
    for j in range(3):
        for k in range(3):
            if b == a[j][k]:
                a[j][k] = 0

if a[0][0] == 0 and a[0][1] == 0 and a[0][2] == 0:
    print("Yes")
elif a[1][0] == 0 and a[1][1] == 0 and a[1][2] == 0:
    print("Yes")
elif a[2][0] == 0 and a[2][1] == 0 and a[2][2] == 0:
    print("Yes")
elif a[0][0] == 0 and a[1][0] == 0 and a[2][0] == 0:
    print("Yes")
elif a[0][1] == 0 and a[1][1] == 0 and a[2][1] == 0:
    print("Yes")
elif a[0][2] == 0 and a[1][2] == 0 and a[2][2] == 0:
    print("Yes")
elif a[0][0] == 0 and a[1][1] == 0 and a[2][2] == 0:
    print("Yes")
elif a[0][2] == 0 and a[1][1] == 0 and a[2][0] == 0:
    print("Yes")
else :
    print("No")





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

int main()
{
  cout << fixed << setprecision(12);
  
  int a,b,d,r;
  double f;

  cin >> a >> b;

  d = a / b;
  r = a % b;
  f = (double)a / b;

  cout << d << " " << r << " " << f << endl;
  
}



Measured memory_bytes: 3260
package main

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

func main() {
	H := nextInt()
	W := nextInt()
	s := make([][]byte, H)
	for i := 0; i < H; i++ {
		s[i] = nextBytes()
	}
	for i := 0; i < H; i++ {
		for j := 0; j < W; j++ {
			if s[i][j] == '.' {
				continue
			}
			var find bool
			for d := 0; d < 4; d++ {
				ny := i + dy[d]
				nx := j + dx[d]
				if ny < 0 || ny >= H || nx < 0 || nx >= W {
					continue
				}
				if s[i][j] == s[ny][nx] {
					find = true
				}
			}
			if !find {
				fmt.Println("No")
				return
			}
		}
	}
	fmt.Println("Yes")
}

var dy = []int{1, 0, -1, 0, 0}
var dx = []int{0, 1, 0, -1, 0}
var inf = int(1e9)

func pow(a, b int) int {
	return int(math.Pow(float64(a), float64(b)))
}

func lcm(a, b int) int {
	return a * b / gcd(a, b)
}
func gcd(a, b int) int {
	if a < b {
		a, b = b, a
	}
	for b != 0 {
		a, b = b, a%b
	}
	return a
}
func max(a ...int) int {
	r := a[0]
	for i := 0; i < len(a); i++ {
		if r < a[i] {
			r = a[i]
		}
	}
	return r
}
func min(a ...int) int {
	r := a[0]
	for i := 0; i < len(a); i++ {
		if r > a[i] {
			r = a[i]
		}
	}
	return r
}
func sum(a []int) (r int) {
	for i := range a {
		r += a[i]
	}
	return r
}
func abs(a int) int {
	if a < 0 {
		return -a
	}
	return a
}

type Pair struct {
	a, b int
}

type pairs []Pair

func (p pairs) Len() int {
	return len(p)
}
func (p pairs) Swap(i, j int) {
	p[i], p[j] = p[j], p[i]
}

func (p pairs) Less(i, j int) bool {
	if p[i].a == p[j].a {
		return p[i].b < p[j].b
	}
	return p[i].a < p[j].a
}

var nextReader func() []byte

func init() {
	nextReader = newScanner()
	log.SetFlags(log.Lshortfile)
}

func newScanner() func() []byte {
	r := bufio.NewScanner(os.Stdin)
	r.Split(bufio.ScanWords)
	return func() []byte {
		r.Scan()
		return r.Bytes()
	}
}
func nextBytes() []byte {
	return nextReader()
}

func nextString() string {
	return string(nextReader())
}
func nextInt64() int64 {
	v, _ := strconv.ParseInt(string(nextReader()), 10, 64)
	return v
}
func nextInt() int {
	v, _ := strconv.Atoi(string(nextReader()))
	return v
}
func nextInts(n int) []int {
	r := make([]int, n)
	for i := 0; i < n; i++ {
		r[i] = nextInt()
	}
	return r
}
func nextFloat64() float64 {
	f, _ := strconv.ParseFloat(string(nextReader()), 64)
	return f
}


Measured memory_bytes: 640
#include<iostream>
#include<string>
#include<vector>
using namespace std;
int main() {
	int num, param_num,bias,true_num=0;
	cin >> num >> param_num >> bias;
	vector<int> params(param_num);
	int A[40][40];
	int i,ans=0;
	for (i = 0; i < param_num; ++i) {
		cin >> params[i];
	}
	for (i = 0; i < num; ++i) {
		for (int j = 0; j < param_num; ++j) {
			cin >> A[i][j];
		}
	}
	for (i = 0; i < num; ++i) {
		int cnt=bias;
		for (int j = 0; j < param_num; ++j) {
			cnt += params[j]*A[i][j];
		}
		if (cnt > 0)
			ans++;
	}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 256
n = int(input())
a, b = [int(i) for i in input().split()]
ps = sorted([int(i) for i in input().split()])
p1 = len([True for p in ps if p <= a])
p2 = len([True for p in ps if a < p <= b])
p3 = len([True for p in ps if b < p])
print(min(p1, p2, p3))

Measured memory_bytes: 3064
//abc126_e.cpp
//Mon Sep 23 15:19:30 2019

#include <iostream>
#include <string>
#include <queue>
#include <map>
#include <unordered_map>
#include <vector>
#include <algorithm>
#include <math.h>
#include <set>
#define INTINF 2147483647
#define LLINF 9223372036854775807
using namespace std;
using ll=long long;
typedef pair<int,int> P;

//Union-Find木
int par[100010]; //親
int treerank[100010]; //木の深さ

//n要素で初期化
void init(int n){
	for (int i=0;i<n;i++){
		par[i] = i;
		treerank[i] = 0;
	}
}

//木の根（親）を見つける
int find (int x){
	if (par[x] == x){
		return x;
	} else {
		return par[x] = find(par[x]);
	}
}

//xとyの属する集合の併合
void unite(int x, int y){
	x = find(x);
	y = find(y);
	if (x == y) {
		return;
	} 

	if (treerank[x] < treerank[y]){
		par[x] = y;
	} else {
		par[y] = x;
		if (treerank[x] == treerank[y]){
			treerank[x]++;
		}
	}
}


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

	init(n);

	for (int i=0;i<m;i++){
		int x,y,z;
		cin >> x >> y >> z;
		unite(x,y);
	}

	int ans = 0;
	int used[n];
	fill(used,used+n,0);
	for (int i=0;i<n;i++){
		if (used[find(i)]==0){
			ans++;
			used[find(i)]++;
		}
	}	

	cout << ans << endl;
//	printf("%.4f\n",ans);
}

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

#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)

using ll = long long;
#define INF 1e9


int main(){
  int N;
  string S;
  cin >> N >> S;
  vector<vector<int>> sum(10, vector<int>(N+1, 0));
  REP(i, N){
    REP(j, 10){
      sum[j][i+1] = sum[j][i];
    }
    sum[S[i]-'0'][i+1]++;
  }
  vector<int> exist(1000, 0);
  FOR(i, 1, N-1){
    REP(j, 10){
      REP(k, 10){
        if(sum[j][i] != 0 && sum[k][N]-sum[k][i+1] != 0){
          int x = j*100+(S[i]-'0') * 10 + k;
          exist[x]++;
        }
      }
    }
  }
  int cnt = 0;
  REP(i, 1000){
    if(exist[i]){
      cnt++;
    }
  }
  cout << cnt << endl;
  return 0;
}


Measured memory_bytes: 1536
import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int a = sc.nextInt();
        int b = sc.nextInt();
        if(b<a){
            int temp=b;
            b=a;
            a=temp;
        }
        int c = sc.nextInt();
        if(c<b){
            int temp=c;
            c=b;
            b=temp;
        }
        if(b<a){
            int temp=b;
            b=a;
            a=temp;
        }
        System.out.println(a+" "+b+" "+c);
        sc.close();
    }
}


Measured memory_bytes: 26332
while True:
    H, W = [int(i) for i in input().split()]
    if H == W == 0:
        break

    for h in range(H):
        for w in range(W):
            if h == 0 or h == H - 1 or w == 0 or w == W - 1:
                print('#', end='')
            else:
                print('.', end='')

        print()
    print()

Measured memory_bytes: 8988
//in the name of allah
#include<iostream>
#include<algorithm>
#include<queue>
#include<deque>
#include<set>
#include<map>
#include<bitset>
#include<cstdio>
#include<cstdlib>
#include<cassert>
#include<string>
#include<cstring>
#include<vector>
using namespace std;
typedef pair<int , int> ii;
typedef long long ll;

int main(){
	int a , b , c;
	scanf("%d%d%d" ,&a , &b , &c);
	if(a == b && b == c && (a%2 ==0)){
		puts("-1");
		return 0;
	}
	int ans=0;
	while(a%2 == 0 && b%2 == 0 && c%2 == 0){
		int a1 = (b+c) , b1 = (a+c) , c1 = (a+b);
		a = a1/2;
		b = b1/2;
		c = c1/2;
		ans ++;
	}
	printf("%d\n" , ans);
}


Measured memory_bytes: 256
n = int(input())
count = 0
for i in range(1, n + 1) :
    if i % 2 == 1 :
        divisor = 0
        for j in range(1, i + 1) :
            if i % j == 0 :
                divisor += 1
        if divisor == 8 :
            count += 1
    else :
        continue
print(count)

Measured memory_bytes: 2940
n = int(input())
s = list(input())
ans = "No"
left = ""
right = ""

if n > 1: # 文字数1では成り立たない
    if n % 2 == 0: # 奇数では成り立たない    
        m = int((n/2)); # 中心の数123, 456
        for i in range(m):
            left += s[i]
        for ii in range(m):
            right += s[ii+m]
        if left == right:
            ans = "Yes"
print(ans)

Measured memory_bytes: 3060
import java.util.Scanner;
class Main{
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int n1 = sc.nextInt();
        int n2 = sc.nextInt();
        int[][] A = new int[n1][n2];
        int[] B = new int[n2];
        for(int i=0;i<n1;i++){
            for(int j=0;j<n2;j++){
             A[i][j]= sc.nextInt();
            }
        }
        for(int k=0;k<n2;k++){
            B[k] = sc.nextInt();
        }
        	for(int i=0;i<n1;i++){
                int sum =0;
                for(int j=0;j<n2;j++){
                    sum += A[i][j] * B[j];
                }
                System.out.println(sum);
            }
    }
}


Measured memory_bytes: 40480
package main

import (
	"fmt"
)

func main() {
	var n, m int
	fmt.Scanf("%d %d", &n, &m)

	ac := map[int]struct{}{}
	wa := map[int]int{}

	for i := 1; i <= m; i++ {
		var p int
		var s string
		fmt.Scanf("%d %s", &p, &s)
		if s == "AC" {
			ac[p] = struct{}{}
		} else if _, ok := ac[p]; !ok {
			wa[p] = wa[p] + 1
		}
	}

	penalty := 0
	for p, c := range wa {
		if _, ok := ac[p]; ok {
			penalty += c
		}
	}

	fmt.Printf("%d %d\n", len(ac), penalty)
}


Measured memory_bytes: 9344
<?php
define("MOD", 10**9+7);
$n = int();
$A = ints();
prepareQuickFactor(1000000);
$lcm = [];
foreach($A as $a){
    $f = quickFactor($a);
    foreach($f as $num => $c){
        if(isset($lcm[$num])){
            chmax($lcm[$num], $c);
        }else{
            $lcm[$num] = $c;
        }
    }
}
$lcmNum = 1;
foreach($lcm as $num => $c){
    for($i = 0; $i < $c; $i++){
        $lcmNum *= $num;
        $lcmNum %= MOD;
    }
}
$sum = 0;
foreach($A as $a){
    $sum += divm($lcmNum, $a);
    $sum %= MOD;
}
echo $sum;

function prepareQuickFactor($M){
    global $era;
    $era = array_fill(0, $M+1, 0);
    $era[0] = -1;
    $era[1] = -1;
    for($i = 2, $I = sqrt($M); $i <= $I; ++$i){
        if($era[$i] == 0){
            for($j = $i*$i; $j <= $M; $j+=$i){
                $era[$j] = $i;
            }
        }
    }
}
function quickFactor($M){
    global $era;
    $map = [];
    while($era[$M]){
        if(!isset($map[$era[$M]]))$map[$era[$M]] = 0;
        $map[$era[$M]]++;
        $M /= $era[$M];
    }
    if(!isset($map[$M]))$map[$M] = 0;
    $map[$M]++;
    return $map;
}
 
function factor($M){
    $rootM = $M**0.5+1;
    for($j = 2; $j <= $rootM; $j++){
        if($M%$j == 0){
            if(!isset($map[$j]))$map[$j] = 0;
            $map[$j]++;
            $M/=$j;
            $rootM = $M**0.5+1;
            $j--;
        }
    }
    if($M>1){
        if(!isset($map[$M]))$map[$M] = 0;
        $map[$M]++;
    }
    return $map;
}
 
function ints(){
  return array_map("intval", explode(" ", trim(fgets(STDIN))));
}
function int(){
  return intval(trim(fgets(STDIN)));
}
function chmax(&$a,$b){if($a<$b){$a=$b;return 1;}return 0;}
 
function o(...$val){
    if(count($val)==1)$val = array_shift($val);
    $trace = debug_backtrace();
    echo $trace[0]['line'].")";
    if(is_array($val)){
        if(count($val) == 0){
            echo "empty array";
        }elseif(!is_array(current($val))){
            echo "array: ";
            echo implode(" ", addIndex($val))."\n";
        }else{
            echo "array:array\n";
            if(isCleanArray($val)){
                foreach($val as $row)echo implode(" ", addIndex($row))."\n";
            }else{
                foreach($val as $i => $row)echo "[".$i."] ".implode(" ", addIndex($row))."\n";
            }
        }
    }else{
        echo $val."\n";
    }
}
function addIndex($val){
    if(!isCleanArray($val)){
        $val = array_map(function($k, $v){return $k.":".$v;}, array_keys($val), $val);
    }
    return $val;
}
function isCleanArray($array){
    $clean = true;
    $i = 0;
    foreach($array as $k => $v){
        if($k != $i++)$clean = false;
    }
    return $clean;
}

//掛け算
function mulm($a, $b){
    return ($a * $b) % MOD;
}
 
//割り算
function divm($a, $b){
    return mulm($a, powerm($b, MOD - 2));
}
 
//累乗
function powerm($a, $b){
    if($b == 0)return 1;
    if($b & 1)return (powerm($a, $b>>1)**2 % MOD) * $a % MOD;
    return powerm($a, $b>>1)**2 % MOD;
}

Measured memory_bytes: 39416
#include<bits/stdc++.h>
using namespace std;
typedef long long int64;
  
int64 N, D;
int64 X[30], Y[30];
  
vector< pair< int64, int64 > > data[2];
priority_queue< pair< int64, int64 > > Que;
  
  
inline void Greedy(int idx, const int end, int64 Value, int64 Precious, const bool in)
{
  if(idx == end) {
    data[in].push_back(make_pair(Value, Precious));
  } else {
    Greedy(idx + 1, end, Value + X[idx], Precious + Y[idx], in);
    Greedy(idx + 1, end, Value         , Precious,          in);
    Greedy(idx + 1, end, Value - X[idx], Precious - Y[idx], in);
  }
}
  
int main()
{
  cin >> N >> D;
  for(int i = 0; i < N; i++) {
    cin >> X[i] >> Y[i];
  }
  Greedy(0, N >> 1, 0, 0, false);
  Greedy(N >> 1, N, 0, 0,  true);
  sort(data[0].begin(), data[0].end());
  sort(data[1].begin(), data[1].end());
  
  int64 ret = 0;
  for(int i = 0, cur = 0; i < data[0].size(); i++) {
    while(cur < data[1].size() && data[1][cur].first <= data[0][i].first + D) {
      Que.push(make_pair(-data[1][cur].second, data[1][cur].first));
      ++cur;
    }
    while(!Que.empty() && Que.top().second < data[0][i].first - D) {
      Que.pop();
    }
    if(!Que.empty()) {
      ret = max(ret, data[0][i].second + Que.top().first);
    }
  }
  cout << ret << endl;
}

Measured memory_bytes: 565964
#include<bits/stdc++.h>
typedef long long ll;
const int INF = 1e9;
const int MOD = 1e9 + 7;
using namespace std;

//ループマクロ
#define FOR(i , a , b)  for(int i = (a) ; i < (b) ; i++)
#define REP(i , n)      for(int i = 0 ; i < n ; i++)
#define REPR(i , n)     for(int i = n ; 0 <= i ; i--)
#define ROP(i, n)       for(int i = 1 ; i <= n ; i++)

//入出力
#define SCOUT(x) cout << (x) << " "
#define VECCIN(x) for(auto& ele : (x) ) cin >> ele
#define VECOUT(x) for(auto& ele : (x) ) cout << ele << " "; cout << endl;

//その他
#define ALL(obj) (obj).begin() , (obj).end() 
#define SORT(obj) sort(ALL(obj))
#define GSORT(obj) sort(ALL(obj) , greater<int>())
#define P pair<int , int>
#define V vector<int>
#define VLL vector<long long>
#define M map<int, int>
#define PQ priority_queue<int>
#define PQG priority_queue<int , V , greater<int>>
int main(void) {

	ios::sync_with_stdio(false);	cin.tie(0);
	
	int N, K;  cin >> N >> K;
	PQ que;
	REP(i, N){  int H;  cin >> H;  que.push(H);  }

  	ll sum = 0;
	while(!que.empty()){
      if(K > 0){  que.pop();  K -= 1;  }
      else{   sum += que.top();  que.pop();  }
    }
	
  	cout << sum << endl;
	return 0;
}


Measured memory_bytes: 1400
import java.io.*;
import java.util.*;
public class Main {
    public static void main(String args[]) throws Exception {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        long[][] intervals = new long[n][2];
        int x = 0, l = 0;
        for(int i = 0; i < n; i++) {
        	x = sc.nextInt();
        	l = sc.nextInt();
        	intervals[i][0] = x - l;
        	intervals[i][1] = x + l;
        }

        Arrays.sort(intervals, (itv1, itv2) -> (int)(itv1[1] - itv2[1]));

        int cnt = 1;
        long start = intervals[0][0];
        long end = intervals[0][1];

        for(int i = 1; i < n; i++) {
        	if(end <= intervals[i][0]) {
    			start = intervals[i][0];
    			end  = intervals[i][1];
    			cnt++;
        	}
        }
        System.out.println(cnt);
    }
}


Measured memory_bytes: 94880
#include<bits/stdc++.h>
using namespace std;
int main()
{
	
  	int A,B;
  	cin>>A>>B;
  	float X=A;
  	float Y=B;
  	float turtle=Y/2-X;
  	float crane=X-turtle;
  	//cout<<crane<<turtle;
  	if((crane==0 && turtle==0) || crane<0 || turtle<0)
  	    cout<<"No";
  	else if((crane==floor(crane)) && (turtle==floor(turtle)))
  	    cout<<"Yes";
  	else
  	    cout<<"No";
}
  	

Measured memory_bytes: 3724
#include <iostream>
#include <string>
#include <cstring>
#include <fstream>
#include <random>
#include <cmath>
#include <iomanip>
#include <climits>
#include <cstdlib>
#include <algorithm>
#include <vector>
#include <map>
#include <deque>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <list>
#include <unordered_map>
#include <bitset>
#include <sstream>
#include <new>
#include <typeinfo>
#include <iterator>

typedef long long ll;
typedef unsigned long long ull;
constexpr ll mop = 1000000007;
constexpr ll mop2 = 998244353;

using namespace std;

int main() {
	vector <ll> x;
	x.resize(6);
	for (ll i = 1; i <= 5; i++) {
		cin >> x[i];
		if (x[i] == 0) {
			cout << i << endl;
			return 0;
		}
	}

}

Measured memory_bytes: 3628
def check(s,i):
   global count
   count+=1
   if i+1 < len(s):
       if s[i+1] == 'A' or s[i+1] == 'C' or s[i+1] =='G' or s[i+1] =='T':
           check(s,i+1) 

s=input()
count=0
list=[]
for i in range(len(s)):
    count=0
    if s[i] == 'A' or s[i] == 'C' or s[i] =='G' or s[i] =='T':
        check(s,i)
    list.append(count)

print(max(list))

Measured memory_bytes: 38256
import sys
def input():
    return sys.stdin.readline()[:-1]

H = int(input())
k = 0

for i in range(40+1):
    a = 2**i
    if H<a:
        k = i - 1
        break
cnt = 0
for i in range(k+1):
    cnt += 2**i
print(cnt)

Measured memory_bytes: 3060
#pragma GCC optimize("O3", "unroll-loops")

#include <bits/stdc++.h>

using namespace std;

#define ll long long
#define ld long double

/* kの約数を求める. 時間計算量O(√k) */
vector<ll> divisor(ll k) {
	vector<ll> d;
	for (ll i = 1; i * i <= k; ++i) {
		if (k % i == 0) {
			d.push_back(i);
			if (i * i != k)
				d.push_back(k / i);
		}
	}
	sort(d.begin(), d.end());
	return d;
}

signed main() {
	ll n; cin >> n;
	ll ans = 10000000000000LL;
	auto d = divisor(n);
	for (auto di : d) {
		ans = min(ans, (di - 1) + (n / di - 1));
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 384
import java.util.*

val sc = Scanner(System.`in`)
val N = sc.nextInt()

fun main(args: Array<String>) {
    val a = Array(N) { sc.nextInt() }
    println(calc(a))
}

fun calc(a: Array<Int>): Int {
    var j = 1
    for (i in 1..a.size) {
        j = a[j - 1]
        if (j == 2) {
            return i
        }
    }
    return -1
}


Measured memory_bytes: 55060
import sys
n = int(input())
src = [int(input()) for _ in range(n)]
if n == 1:
    print(src[0])
    sys.exit()

def check(a, b):
    if a < b:
        a, b = b, a
    while a % b != 0:
        a, b = b, a % b
    return b
tmp = src[0]
for i in range(n-1):
    tmp = tmp//check(tmp, src[i+1])*src[i+1]
print(tmp)

Measured memory_bytes: 3064
#include<bits/stdc++.h>
using namespace std;
int main(){
  int n;
  cin>>n;
  vector<int>a(n),ans(n);
  for(int i=0;i<n;i++)cin>>a[i],ans[a[i]-1]=i+1;
  for(int i=0;i<n;i++)cout<<ans[i],i<n-1?cout<<' ':cout<<endl;
  return 0;
}

Measured memory_bytes: 4032
/// Containers Start
#include <algorithm>
#include <bitset>
#include <cstdlib>
#include <functional>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <list>
#include <map>
#include <queue>
#include <random>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <tuple>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>
/// C Header Files
#include <cassert>
#include <cctype>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <ctime>
#include <math.h>
#include <stdio.h>
/// Containers End

using namespace std;

/// Math Start
#define PI acos(-1.0)
#define Pi 3.141592653589793
#define EPS (1e-7)
#define INF (0x3f3f3f3f)
/// Math End

/// Extra Start
#define nn '\n'
#define pb push_back
#define ull unsigned long long
#define ll long long
#define MOD 1000000007
#define sz(a) int((a).size())
#define space " "
#define All(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
/// Extra End

#define rep(i, n) for (int i = 0; i < n; i++)
#define Cini(a)                                                                \
    int a;                                                                     \
    cin >> a;
#define Cinii(a, b)                                                            \
    int a, b;                                                                  \
    cin >> a >> b;
#define Ciniii(a, b, c)                                                        \
    int a, b, c;                                                               \
    cin >> a >> b >> c;
#define Cins(s)                                                                \
    string s;                                                                  \
    cin >> s;
#define Cinss(s1, s2)                                                          \
    string s1, s2;                                                             \
    cin >> s1 >> s2;
#define Cinc(c)                                                                \
    char c;                                                                    \
    cin >> c;
/// Functions End

/// Graph Start
struct edge {
    int from, to;
    long long cost;
};
/// Graph End

/// Debug Start
#define deb(x) cout << #x << ": " << x << endl
#define deb2(x, y) cout << #x << ": " << x << '\t' << #y << ": " << y << endl;
#define deb3(x, y, z)                                                          \
    cout << #x << ": " << x << '\t' << #y << ": " << y << '\t' << #z << ": "   \
         << z << endl;
/// Debug End

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

/**>>>>>>>>>>>>>>>>>>> END <<<<<<<<<<<<<<<<<<**/

/// template


signed main(void) {
    cin.sync_with_stdio(false);
    cin.tie(0);
    string t = "yahoo";
    Cinii(n,k);
    if (k<=(n+1)/2) cout << "YES" << nn;
    else cout << "NO" << nn;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
using namespace std;
int N, A, B, C, D;
string S;

bool ok(int s, int e) {
    for (int i = s; i <= e - 1; i++) {
        if (S[i] == '#' && S[i+1] == '#') return false; 
    }
    return true;
}

int main() {
    cin >> N >> A >> B >> C >> D >> S;
    S = '#' + S + '#';

    if (!ok(A, C) || !ok(B, D)) {
        cout << "No" << endl;
        return 0;
    }

    if (C > D) {
        bool flag = false;
        for (int i = B; i <= D; i++) {
            if (S[i-1] == '.' && S[i] == '.' && S[i+1] == '.') flag = true;
        }
        if (!flag) {
            cout << "No" << endl;
            return 0;
        }
    }
    cout << "Yes" << endl;
}

Measured memory_bytes: 772
h, w, k = map(int, input().split())
dp = [0] * w
mod = 10 ** 9 + 7

comb = []
for bit in range(1 << w - 1):
    ok = True
    for j in range(w - 2):
        if bit >> j & 1 and bit >> j + 1 & 1:
            ok = False
    if ok:
        comb.append(bit)

dp[0] = 1
for i in range(h):
    next = [0] * w
    for bit in comb:
        moved = [False] * w
        for j in range(w):
            if bit >> j & 1:
                next[j + 1] += dp[j]
                next[j] += dp[j + 1]
                moved[j] = moved[j + 1] = True
            elif not moved[j]:
                next[j] += dp[j]
    dp = next
print(dp[k - 1] % mod)


Measured memory_bytes: 9136
#include <vector>
#include <algorithm>
#include <string>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <cstdio>
#include <memory.h>
#include <cmath>
#include <array>

using namespace std;

void re(int& x);

template<class T, class... Ts> void re(T& t, Ts&... ts);

void pr(int x);

void pr(char x);
void pr(const char *x);

template<class T> void pr(const std::vector<T> x);

void ps();
template<class T, class... Ts> void ps(const T& t, const Ts&... ts);

#ifdef FFDBG

#else
#define dbg(x...) dsfdsfsdfasd
#endif

typedef vector<int> vi;

#define sz(x) (int)(x).size()

#define rep(i, a, b) for(int i = a; i < (b); ++i)

int n;
vi ans, cur;
vector< vi > adj;

int bd, bi;

void dfs(int v, int p, int d) {
    if (d > bd) {
        bd = d; bi = v;
    }

    for (int x : adj[v]) if (x != p) dfs(x,v,d+1);
}

bool check(int v, int p, int num) {
    // dbg(v,p,num);

    int b = -1;
    for (int x : adj[v]) if (x != p) {
        if (b == -1 || sz(adj[x]) > sz(adj[b])) b = x;
    }

    int nxt = num + 1;

    for (int x : adj[v]) if (x != p && x != b) {
        if (sz(adj[x]) > 1) return false;
        cur.push_back(nxt++);
    }

    cur.push_back(num);

    if (b != -1) return check(b,v,nxt);

    return true;
}

void solve()
{
    re(n);
    adj = vector< vi >(n);

    rep(i,0,n-1) {
        int u,v; re(u,v); u--; v--;
        adj[u].push_back(v);
        adj[v].push_back(u);
    }

    bd = -1;
    dfs(0,-1,0);
    int l = bi;

    bd = -1;
    dfs(bi,-1,0);
    int r = bi;

    cur = {};
    if (check(l,-1,1)) ans = cur;
    cur = {};
    if (check(r,-1,1)) ans = min(ans,cur);

    if (!ans.empty()) ps(ans);
    else ps(-1);
}

int main() {

    solve();
}

void re(int& x) { scanf("%d", &x); }

template<class T, class... Ts> void re(T& t, Ts&... ts) { 
    re(t); re(ts...); 
}

void pr(int x) { printf("%d", x); }

void pr(char x) { printf("%c", x); }
void pr(const char *x) { printf("%s", x); }

template<class T> void pr(std::vector<T> v) {
    int f=0;
    for (int x : v) {
        if (f++) pr(' ');
        pr(x);
    }
}

void ps() { pr("\n"); }
template<class T, class... Ts> void ps(const T& t, const Ts&... ts) { 
    pr(t); if (sizeof...(ts)) pr(" "); ps(ts...); 
}



Measured memory_bytes: 16888
//                   ********** YATIN KWATRA **********

// AC BAKSHI RABBA

#include <bits/stdc++.h>
#define ll                      long long 
#define ld                      long double
#define ull                     unsigned long long 
#define FIO                     ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define endl                    "\n"
#define fo(i,a,b)               for(int i = a; i<=b ; i++)
#define rfo(i,a,b)              for(int i = a; i>=b ; i--)
#define vii                     vector<int>
#define vll                     vector<ll>
#define pq                      priority_queue
#define uom                     unordered_map                
#define all(v)                  v.begin(),v.end()
#define mp                      make_pair
#define pb                      push_back
#define pob                     pop_back
#define ff                      first
#define ss                      second
#define pii                     pair<int,int> 
#define pll                     pair<long,long>
#define mll                     map<ll,ll>
#define mii                     map<int,int>
#define vvii                    vector<vii>
#define vvll                    vector<vll>
#define mod                     1000000007
#define pi                      3.1415926535897932384626433832795

using namespace std;

void INPUT() 
{  
    #ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
    #endif
}

/*
    
   -> Check For Overflows
   -> Out of Bounds
   -> Initialisations of global arrays and variables
   -> Its not Always Complex, Try to simplify
   -> write it down and try to solve
   -> Have Faith in urself and in ur approach
   -> If it seems totally out of reach, switch to next :)
   -> And Come Back later, if possible 
*/





void solve()
{ 
      ll n;
      cin >> n;

      n %= 1000;

      if(n == 0) cout << n << endl;
      else cout << (1000-n) << endl;

       
}
int main() {
    
    FIO
    INPUT();
    
    int t;
    t = 1;
    //cin >> t;
    
    while(t--)
    {
       solve();
    }
    return 0;
}


Measured memory_bytes: 3608
import java.util.*;

public class Main{

	static int[][] multi;
	static int[] matR;
	static int[] matC;

	public static void main(String[] args){

		Scanner scan = new Scanner(System.in);

		int n = scan.nextInt();
		multi = new int[n][n];
		matR = new int[n];
		matC = new int[n];

		for(int i = 0; i < n; i++){
			matR[i] = scan.nextInt();
			matC[i] = scan.nextInt();
		}

		System.out.println(Mat(0, n-1));

		scan.close();
		System.exit(0);
	}

	private static int Mat(int fr, int to){
		if(fr == to)
			return 0;
		if(multi[fr][to] == 0){
			int min = Integer.MAX_VALUE;
			for(int i = fr; i < to; i++){
				int r = Mat(fr, i) + Mat(i+1, to) + (matR[fr] * matC[i] * matC[to]);
				if(r < min)
					min = r;
			}
			multi[fr][to] = min;
		}
		return multi[fr][to];
	}
}



Measured memory_bytes: 27124
package main

import (
	"fmt"
	"sort"
)

func main() {
	var (
		n   int
		sum float64
	)
	fmt.Scan(&n)
	v := make([]int, n)
	for i := 0; i < n; i++ {
		fmt.Scan(&v[i])
	}
	sort.Ints(v)

	sum = float64(v[0])
	for i := 1; i < n; i++ {
		sum = (sum + float64(v[i])) / 2.0
	}
	fmt.Println(sum)
}


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

int main() {
  int n,y;
  cin >> n >> y;
  
  int res10000 = -1;
  int res5000 = -1;
  int res1000 = -1;
  
  for (int i=0;i<=n;i++){
    for (int j=0;j<=n-i;j++){
      int k = n-i-j;
      
      int sum = 10000*i+5000*j+1000*k;
      
      if (sum == y){
        res10000 = i;
        res5000 = j;
        res1000 = k;
        break;
      }
      
    }
  }
  
  cout << res10000 << ' ' << res5000 << ' ' << res1000 << endl;
  
}


Measured memory_bytes: 256
import java.util.HashMap;
import java.util.Scanner;

class Main {
	int n;
	HashMap<Integer,Integer> map;

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		Main m = new Main(sc);
		m.solve();
		sc.close();
	}

	Main(Scanner sc) {
		n = sc.nextInt();
		map = new HashMap<Integer,Integer>(){
			{
				for(int i=-1;i<=1.0e+5+2;i++) put(i, 0);
			}
		};
		for(int i=0;i<n;i++){
			int a = sc.nextInt();
			map.replace(a, map.get(a)+1);
		}
	}

	void solve() {
		int max = Integer.MIN_VALUE;
		for(int x=0;x<=1.0e+5+1;x++){
			max = Math.max(max, map.get(x-1) + map.get(x) + map.get(x+1));
		}
		System.out.println(max);
	}
}


Measured memory_bytes: 65696
#include <stdio.h>
#include <cctype>
#include <limits.h>
#include <math.h>
#include <complex>
#include <bitset>
#include <vector>
#include <map>
#include <set>
#include <stack>
#include <queue>
#include <cstring>
#include <string>
#include <sstream>
#include <algorithm>
#include <iomanip>
#include <iostream>

#define VARIABLE(x) cerr << #x << "=" << x << endl
#define BINARY(x) static_cast<bitset<16> >(x)
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define REP(i,m,n) for (int i=m;i<(int)(n);i++)
#define if_range(x, y, w, h) if (0<=(int)(x) && (int)(x)<(int)(w) && 0<=(int)(y) && (int)(y)<(int)(h))
#define ALL(a) (a).begin(),(a).end()
const int INF = 1e9;
int dx[4]={0, 1, 0, -1}, dy[4]={-1, 0, 1, 0};
using namespace std;
typedef long long ll;
typedef pair<int, int> PII;

/* struct P {
	int x, y, n;
	P(int n, int x, int y):n(n), x(x), y(y){}
	P(){}
}; */


/** Problem2529 : Brainf*ck **/
void printMulti(int n, int m, bool plus)
{
	char sig = (plus?'+':'-');
	cout << ">";
	rep(i, n) cout << "+";
	cout << "[<";
	rep(i, m) cout << sig;
	cout << ">-]<";
}

int main()
{
	string S;
	cin>>S;
	
	map<int, PII> list;
	for (int i=1; i<=126; i++) {
		int tmp=1;
		for (int j=1; j*j<=i; j++) {
			if (i%j==0)
				tmp = max(tmp, j);
		}
		list[i] = PII(tmp, i/tmp);
	}
	
	int mem[8] = {};
	int np = 0;
	
	for (int i=0; i<S.size(); i++) {
		int diff = INF;
		int newp = np;
		
		for (int j=0; j<8; j+=2) {
			int tmp = S[i] - mem[j];
			if (abs(tmp) < abs(diff)) {
				diff = tmp;
				newp = j;
			}
		}
		
		for (int j=0; j<abs(newp - np); j++) {
			cout << (np<newp ? '>' : '<');
		}
		
		int tmp=abs(diff);
		while (tmp!=0 && diff!=0) {
			if (list[tmp].first + list[tmp].second + 6 <= abs(tmp)) {
				printMulti(list[tmp].first, list[tmp].second, diff>0);
				diff -= (diff>0?1:-1) * tmp;
				tmp = abs(diff);
			} else {
				tmp--;
			}
		}
		
		if (diff > 0) {
			for (int j=0; j<diff; j++) {
				cout << "+";
			}
		} else if (diff < 0) {
			for (int j=0; j<-diff; j++) {
				cout << "-";
			}
		}
		
		cout << "." << flush;
		np = newp;
		mem[np] = S[i];
	}
	
	cout << endl;
}

Measured memory_bytes: 1188
#include<stdio.h>

int main(){
  int n,x,i;
  int c=0;
  scanf("%d", &n);
  for ( i = 0; i<n; i++ ){
    scanf("%d", &x);
    if ( primecheck(x)==1 ) 
        c++;
  }
  printf("%d\n", c);

  return 0;
}

int primecheck(int x){
  int i;
  if ( x < 2 ) 
    return 0;
  if ( x == 2 ) 
    return 1;
  if ( x%2 == 0 ) 
    return 0;
  for (i=3; i*i<=x; i+=2 ){
    if ( x%i == 0 )
     return 0;
  }
  return 1;
}


Measured memory_bytes: 2048
# 早い話出てきた回数を数えればいい
n, m = gets.split.map(&:to_i)
ary = Array.new()
m.times do |_|
    ary.push(gets.split.map(&:to_i))
end
ary.flatten!
n.times do |i|
    puts ary.count(i+1)
end

Measured memory_bytes: 1788
#include <iostream>
#include <vector>

#define 中心() main()
#define 返 return
#define 入力(a) cin >> a
#define 出力(a) cout << a << endl
#define 再帰(s,t) for(整数 s = 0; s < 整数(t); s += 1)
#define 逆再(s,t) for(整数 s = 整数(t) - 1; s >= 0; s -= 1)
#define 脱出 break
#define もし(a) if(a)
#define 他 else
#define 全部(h) (h).begin(), (h).end()
#define 整理(h) sort(全部(h))

using namespace std;

typedef int 整;
typedef void 無;
typedef long long 整数;
typedef vector<整数> 整数配列;

整数 s, t, v;
整数 和=0;

無 分布(整数配列 &u){
    逆再(a,s){
        和 -= u[a];
        v -= 1;
        もし(和<=t){
            出力(v);
            脱出;
        }
    }
}

整 中心(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    入力(s);
    入力(t);
    v = s;
    整数配列 u(s);
    再帰(a,s){
        入力(u[a]);
    }

    整理(u);
    再帰(a,s){
        和 += u[a];
    }
    
    もし(和 == t) 出力(s);
    他 分布(u);
    返 0;
}


Measured memory_bytes: 384
import sys

# 許容する再帰処理の回数を変更
sys.setrecursionlimit(10**5+10)
# input処理を高速化する
input = sys.stdin.readline

def chmax(a, b):
    """ 最大値を返す関数 """
    if a >= b:
        return a
    else:
        return b

def main():  
    # 入力
    N, M = map(int, input().split())
    # 隣接関係は隣接リストで管理する
    lst_edge = [[] for _ in range(N)]
    for _ in range(M):
        x, y = map(int, input().split())
        # 最初のindexをゼロにする
        lst_edge[x-1].append(y-1)

    # dp[v] := ノードvを始点とした時の有向パスの長さの最大値
    # -1 未訪問で初期化。
    dp = [-1] * N

    # メモ化再帰
    def rec(v):
        # 既に更新済み
        if dp[v] != -1:
            return dp[v]
        ans = 0
        lst_nv = lst_edge[v]
        for nv in lst_nv:
            ans = chmax(ans, rec(nv) + 1)
        dp[v] = ans
        return dp[v]
    
    # 全ての点に対して更新する
    ans = 0
    for v in range(N):
        ans = chmax(ans, rec(v))
    
    print(ans)



main()

Measured memory_bytes: 67248
from collections import defaultdict, deque, Counter
from heapq import heappush, heappop, heapify
import math
import bisect
import random
from itertools import permutations, accumulate, combinations, product
import sys
import string
from bisect import bisect_left, bisect_right
from math import factorial, ceil, floor
from operator import mul
from functools import reduce


sys.setrecursionlimit(2147483647)
INF = 10 ** 13
def LI(): return list(map(int, sys.stdin.readline().split()))
def I(): return int(sys.stdin.readline())
def LS(): return sys.stdin.readline().rstrip().split()
def S(): return sys.stdin.readline().rstrip()
def IR(n): return [I() for i in range(n)]
def LIR(n): return [LI() for i in range(n)]
def SR(n): return [S() for i in range(n)]
def LSR(n): return [LS() for i in range(n)]
def SRL(n): return [list(S()) for i in range(n)]
def MSRL(n): return [[int(j) for j in list(S())] for i in range(n)]

mod=10**9+7

n=I()

fac = [1] * (n + 1)
inv = [1] * (n + 1)
for j in range(1, n + 1):
    fac[j] = fac[j-1] * j % mod

inv[n] = pow(fac[n], mod-2, mod)
for j in range(n-1, -1, -1):
    inv[j] = inv[j+1] * (j+1) % mod


def comb(n, r):
    if r > n or n < 0 or r < 0:
        return 0
    return fac[n] * inv[n - r] * inv[r] % mod



G=[[]for _ in range(n)]
for _ in range(n-1):
    a,b=LI()
    G[a-1]+=[b-1]
    G[b-1] += [a-1]

cnt=[-1]*n
par=[-1]*n
def f(x):
    ret=1
    for y in G[x]:
        if par[x]==y:
            continue
        par[y]=x
        ret+=f(y)
    cnt[x]=ret
    return ret

f(0)
D=[0]*n
def tree_dp(x):
    c = 1
    remain_v = cnt[x] - 1
    for y in G[x]:
        if y == par[x]:
            continue
        c = c * tree_dp(y) * comb(remain_v, cnt[y]) % mod
        remain_v -= cnt[y]
    D[x] = c
    if x: return c

tree_dp(0)
ans=[0]*n
ans[0]=D[0]



q=deque([0])
while q:
    e=q.pop()
    for d in G[e]:
        if d==par[e]:
            continue
        ans[d]=pow(comb(n-1,cnt[d])*D[d],mod-2,mod)*ans[e]*comb(n-1,cnt[d]-1)*D[d]%mod
        q+=[d]

print(*ans,sep="\n")

Measured memory_bytes: 186456
#include <bits/stdc++.h>
typedef long long ll;
const int INF = 1e9;
const int MOD = 1e9+7;
const ll LINF = 1e18;

using namespace std;

#define rep(i, a, b) for (int i = a; i < b; i++)
#define rrep(i, a, b) for (int i = a; i <= b; i++)
#define revrep(i, s) for (int i = s-1; i > 0; i--)
#define revrrep(i, s) for (int i = s-1; i >= 0; i--)
#define all(a)  begin((a)),end((a))
#define uniq(c) (c).erase(unique(all((c))), end((c)))

int main()
{
    char b; cin >> b;
    if ('A' == b) cout << 'T';
    else if ('C' == b) cout << 'G';
    else if ('G' == b) cout << 'C';
    else if ('T' == b) cout << 'A';
    cout << endl;
}

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

int main(){
    int a, b, k;
    cin >> a >> b >> k;
    if(a+k-1 >= b-k+1){ // kasanatteru
        for(int i = a; i <= b; i++){
            cout << i << endl;
        }
    }else{
        for(int i = 0; i < k; i++){
            cout << a+i << endl;
        }
        for(int i = 0; i < k; i++){
            cout << b-k+1+i << endl;;
        }
    }
    return 0;
}

Measured memory_bytes: 256
#include<math.h>
#include <bits/stdc++.h>
#include <algorithm>
#define rep(i, n) for (int i = 0; i < (int)n; i++)
#define ll long long int
#define py printf("Yes\n")
#define pn printf("No\n")
#define in cin>>
using namespace std;
int main()
{
    int n;
    string s;
    in n>>s;
    int ans=0;
    for(int i=1;i<n;i++)
    {
        int check=0;
        for (char c = 'a'; c <= 'z'; c++)
        {
            bool left=false,right=false;
            for (int j = 0; j < i; j++)
            {
                if(s[j]==c)left=true;
            }

            for(int j=i;j<n;j++)
            {
                if(s[j]==c)right=true;
            }
            if(left&&right)check++;
        }
        if(ans<check)ans=check;
    }
    cout<<ans<<endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define chmin(a, b) ((a)=min((a), (b)))
#define chmax(a, b) ((a)=max((a), (b)))
#define fs first
#define sc second
#define eb emplace_back
using namespace std;
 
typedef long long ll;
typedef pair<int, int> P;
typedef tuple<int, int, int> T;
 
const ll MOD=1e9+7;
const ll INF=1e18;
 
int dx[]={1, -1, 0, 0};
int dy[]={0, 0, 1, -1};

int check[25][25];

int main(){
    while(1){
        int w,h;
        cin >> w >> h;
        if(w == 0 && h == 0) break;
        char tile[23][23];
        queue<P> black;
        int ans = 0;
        for(int i = 0;i < h;i++){
            cin >> tile[i];
            for(int j = 0;j < w;j++){
                check[i][j] = 0;
                if(tile[i][j] == '@'){
                    black.push(P(i,j));
                }
            }
        }
        while(!black.empty()){
            P q = black.front(); black.pop();
            if(check[q.fs][q.sc] != 0) continue;
            ans++;
            check[q.fs][q.sc] = 1;
            for(int i = 0;i < 4;i++){
                int ni = q.fs+dx[i];
                int nj = q.sc+dy[i];
                if( min(ni,nj) >= 0 && ni < h && nj < w && check[ni][nj] == 0 && tile[ni][nj] == '.'){
                    black.push(P(ni,nj));
                }
            }
        }
        cout << ans << endl;
    }
}


Measured memory_bytes: 3048
N, M = map(int, input().split())

mod = (10**9 + 7)

def factorial(n):
    for i in range(1, n):
        n *= i
        if n > mod:
            n %= mod
    return n

if N == M:
    a = factorial(M)
    print(a ** 2 * 2 % mod)
elif abs(N-M) == 1:
    print(factorial(N) * factorial(M) % mod)
else:
    print(0)


Measured memory_bytes: 3060
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner s1 = new Scanner(System.in);
        int N = s1.nextInt();
        long result = 0;
        for(int i = 1; i <= N; i++) {
            if(i % 3 != 0 && i % 5 != 0)  result += i;
        }
        System.out.println(result);
    }
}


Measured memory_bytes: 35788