akhauriyash/Code-Regression huggingface dataset:
package main

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

func getScanner(fp *os.File) *bufio.Scanner {
	scanner := bufio.NewScanner(fp)
	scanner.Split(bufio.ScanWords)
	scanner.Buffer(make([]byte, 1000005), 1000005)
	return scanner
}

func getNextString(scanner *bufio.Scanner) string {
	scanner.Scan()
	return scanner.Text()
}

func getNextInt(scanner *bufio.Scanner) int {
	i, _ := strconv.Atoi(getNextString(scanner))
	return i
}

func getNextInt64(scanner *bufio.Scanner) int64 {
	i, _ := strconv.ParseInt(getNextString(scanner), 10, 64)
	return i
}

func getNextUint64(scanner *bufio.Scanner) uint64 {
	i, _ := strconv.ParseUint(getNextString(scanner), 10, 64)
	return i
}

func getNextFloat64(scanner *bufio.Scanner) float64 {
	i, _ := strconv.ParseFloat(getNextString(scanner), 64)
	return i
}

func main() {
	fp := os.Stdin
	wfp := os.Stdout
	cnt := 0

	if os.Getenv("MASPY") == "ますピ" {
		fp, _ = os.Open(os.Getenv("BEET_THE_HARMONY_OF_PERFECT"))
		cnt = 2
	}
	if os.Getenv("MASPYPY") == "ますピッピ" {
		wfp, _ = os.Create(os.Getenv("NGTKANA_IS_GENIUS10"))
	}

	scanner := getScanner(fp)
	writer := bufio.NewWriter(wfp)
	solve(scanner, writer)
	for i := 0; i < cnt; i++ {
		fmt.Fprintln(writer, "-----------------------------------")
		solve(scanner, writer)
	}
	writer.Flush()
}

func solve(scanner *bufio.Scanner, writer *bufio.Writer) {
	n := getNextInt(scanner)
	pp := make([]int, n)
	qq := make([]int, n)
	for i := 0; i < n; i++ {
		pp[i] = getNextInt(scanner)
	}
	for i := 0; i < n; i++ {
		qq[i] = getNextInt(scanner)
	}

	f := factorial{}
	f.init(n)
	ans := f.index(qq) - f.index(pp)
	if ans < 0 {
		ans = -ans
	}
	fmt.Fprintln(writer, ans)
}

type factorial struct {
	n   int
	fac []int
}

func (f *factorial) init(n int) {
	f.n = n
	f.fac = make([]int, n)

	f.fac[0] = 1
	f.fac[1] = 1
	for i := 2; i < n; i++ {
		f.fac[i] = f.fac[i-1] * i
	}
}

func (f *factorial) index(p []int) int {
	n := f.n
	ans := 0
	used := make([]bool, n)
	for i := 0; i < n; i++ {
		sum := 0
		for j := p[i] - 1; j >= 0; j-- {
			if used[j] {
				continue
			}
			sum++
		}
		used[p[i]-1] = true
		ans += sum * f.fac[n-1-i]
	}

	return ans
}

func (f *factorial) get(index int) []int {
	n := f.n
	ans := make([]int, n)
	used := make([]bool, n)
	for i := 0; i < n; i++ {
		ans[i] = index / f.fac[n-1-i]
		index %= f.fac[n-1-i]
	}
	for i := 0; i < n; i++ {
		for j := 0; j < n; j++ {
			if used[j] {
				continue
			}
			if ans[i] == 0 {
				ans[i] = j + 1
				used[j] = true
				break
			}
			ans[i]--
		}
	}

	return ans
}


Measured memory_bytes: 640
# -*- coding: utf-8 -*-
import sys
from bisect import bisect_left,bisect_right
sys.setrecursionlimit(10**9)
INF=10**18
MOD=10**9+7
def input(): return sys.stdin.readline().rstrip()

def main():
    N=int(input())
    A=list(map(int,input().split()))
    B=list(map(int,input().split()))
    C=list(map(int,input().split()))
    A.sort()
    C.sort()
    ans=0
    for x in B:
        ans+=bisect_right(A,x-1)*(N-bisect_left(C,x+1))
    print(ans)    

if __name__ == '__main__':
    main()


Measured memory_bytes: 92968
#include<stdio.h>
int main()
{
	int n,i,j,flg;
	scanf("%d",&n);
	flg=0;
	for(i=0;i<10;i++){
		for(j=0;j<10;j++){
			if(i*j==n){
				flg=1;
			}
		}
	}
	if(flg==1){
		printf("Yes\n");
	}
	else{
		printf("No\n");
	}
	return 0;
}


Measured memory_bytes: 128
import java.util.*
//import kotlin.math.*
 
private fun readString() = readLine()!! // string line
private fun readInt() = readString().toInt() // single int
private fun readLong() = readString().toLong()
private fun readStrings() = readString().split(" ") // list of strings
private fun readInts() = readStrings().map { it.toInt() } // list of ints
private fun readLongs() = readStrings().map { it.toLong() } // list of ints
 
val INF = 1000000000
 
fun main(args: Array<String>)
{
    var (n, k) = readInts()
	var s = readString()
	var ret = 0
	
	for (i in 0..n-1)
	{
		if (i == 0 || s[i] != s[i-1]) ret ++
	}
	
	ret -= 2*k
	if (ret <= 0) ret = 1
	
	print(n-ret)
}


Measured memory_bytes: 37836
#include <bits/stdc++.h>
using namespace std;
typedef unsigned long long ull;

#define REP(i, n) for (int i = 0; i < (n); i++)
#define REP1(i, n) for (int i = 1; i < (n); i++)
#define RREP(i, n) for (int i = (n) - 1; 0 <= i; i--)
#define CIN(A) int A; cin >> A;
#define CIN2(A, B) int A, B; cin >> A >> B;
#define CIN3(A, B, C) int A, B, C; cin >> A >> B >> C;
#define CINVEC(A, N) vector<int> A; REP(i, N) { int a; cin >> a; A.emplace_back(a); }
#define ANS(ans) cout << (ans) << endl
#define SORT(V) sort(V.begin(), V.end())
#define RSORT(V) sort(V.rbegin(), V.rend())

#define DEBUGV(V) REP(i, V.size()) cout << V.at(i) << " "; cout << endl 

int
main()
{
  CIN(N);
  vector<string> V(N);
  REP(i, N) cin >> V[i];

  REP1(i, N) {
    if (V[i - 1].at(V[i - 1].size() - 1) != V[i].at(0)) { ANS("No"); return 0; }
  }

  SORT(V);
  REP1(i, N) {
    if (V[i - 1] == V[i]) { ANS("No"); return 0; }
  }

  ANS("Yes");
  
  return 0;
}


Measured memory_bytes: 256
import Control.Applicative
import Data.ByteString.Char8 (ByteString)
import qualified Data.ByteString.Char8 as B
import Data.List
import Data.Char (isSpace)

main :: IO ()
main = solve <$> f <*> f >>= print
  where
    f = readil B.readInt <$> B.getLine

solve :: [Int] -> [Int] -> Int
solve [n, m, t] as = head as - m
                     + max 0 (t - last as - m)
                     + sum (tail >>= zipWith f $ as)
  where
    f  x y = max 0 (x - y - 2 * m)

readil :: Integral a =>  (ByteString -> Maybe (a, ByteString)) -> ByteString -> [a]
readil f = unfoldr $ \s -> do
  (n, s') <- f s
  return (n, B.dropWhile isSpace s')



Measured memory_bytes: 3632
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<queue>
#include<deque>
#include<map>
#include<math.h>
#include<iomanip>
#include<set>
#include<numeric>
#include<cstring>
#include<cstdio>
#include<functional>
#include<bitset>
#include<limits.h>
#include<iterator>
#include<complex>
#include<stack>
#include "stdio.h"
using namespace std;

#define REP(i,m,n) for(int i=(int)(m) ; i < (int) (n) ; ++i )
#define rep(i,n) REP(i,0,n)

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

const int inf = 1e9 + 7;
const ll longinf = 1LL << 60;
const long long mod_const = 1e9+7;

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

using MIte = multimap<ll, ll, greater<ll> >::iterator;

ll aaN[300][300];

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

	// long long?
	int N;
	cin >> N;

	ll dist = 0;
	ll rem = 0;
	rep(i, N) {
		rep(j, N) {
			cin >> aaN[i][j];
			
		}
	}

	for (int i = 0; i != N; ++i) {
		for (int j = i; j != N; ++j) {
			if (i == j) continue;
//			dist += aaN[i][j];
			bool add = true;
			for (int k = 0; k != N; ++k) {
				if (k != i && k != j) {
					if (aaN[i][j] == aaN[i][k] + aaN[k][j]) {
						add = false;
						rem += aaN[i][k] + aaN[k][j];
					}
					else if (aaN[i][j] > aaN[i][k] + aaN[k][j]) {
						cout << "-1" << endl;
						return 0;
					}
				}
			}
			if (add) {
				dist += aaN[i][j];
			}
		}
	}

	cout << dist << endl;

	return 0;
}

Measured memory_bytes: 1024
import java.io.IOException;
class Main {
	public static void main(String[] args) throws IOException{
		java.io.BufferedReader in = new java.io.BufferedReader(new java.io.InputStreamReader(System.in));
		
		int top3[] = new int[]{0,0,0,0};
		
		for(int i=0;i<10;i++){
			int height = Integer.parseInt(in.readLine());
			for(int j=2;j>=0;j--){
				if(height > top3[j]){
					top3[j+1] = top3[j];
					top3[j] = height;
				}else{
					break;
				}
			}
		}
		for(int i=0;i<3;i++){
			System.out.println(top3[i]);
		}
	}
}

Measured memory_bytes: 17056
#include<iostream>
#include<algorithm>
#include<map>
#include<vector>
using namespace std;

int main()
{
	long long int n,x,i,j;
	cin>>n;
	map<long long int,long long int>mp;
	vector<bool>b(1000100,0);
	for(i=0;i<n;i++)
	{
		cin>>x;
		mp[x]++;
	}
	long long int cnt=n;
	for(auto it=mp.begin();it!=mp.end();it++)
	{
		int p=it->first;
		if(mp.find(p)!=mp.end()&& mp[p]>1 && b[p]==0)
		{
			cnt=cnt-mp[p];
		}
		for(j=2*p;j<=1000010;j+=p)
		{
			if(mp.find(j)!=mp.end() && mp[j]>0 && b[j]==0)
			{
				cnt=cnt-mp[j];
				b[j]=1;
			}
		}
	}
	cout<<cnt<<"\n";
}

Measured memory_bytes: 16220
def sunuke_sum(arg):
    sum_digit = 0
    for char in arg:
        sum_digit += int(char)
    return sum_digit


input_num = int(input())

sunuke_dict = {}

min_sunuke_div = 10 ** 20
for d in reversed(range(1, 16)):
    for n in reversed(range(10, 1000)):
        i = n * (10 ** d) + (10 ** d - 1)
        sunuke_div = i / sunuke_sum(str(i))
        sunuke_dict[i] = sunuke_div

for i in reversed(range(1, 101)):
    sunuke_div = i / sunuke_sum(str(i))
    sunuke_dict[i] = sunuke_div

sunuke_sorted = sorted(sunuke_dict.items())
sunuke_list = []

for value, div_value in reversed(sunuke_sorted):
    if min_sunuke_div >= div_value:
        sunuke_list.append(value)
        min_sunuke_div = div_value

sunuke_list.reverse()

for i in range(0, input_num):
    print(str(sunuke_list[i]))


Measured memory_bytes: 5700
//A.cpp
#include <iostream>
#include <string>
#include <algorithm>
#include <set>
#include <map>
#include <vector>
#include <queue>
#include <stack>
#include <math.h>
#define rep(i,n) for(int i = 0; i < (n); ++i)
using namespace std;
typedef long long ll;
ll gcd(ll a,ll b){return b!=0?gcd(b,a%b):a;}
ll lcm(ll a,ll b){return a*b/gcd(a,b);}
const ll mod=1e9+7;

int main(){
  int h,n;
  cin >> h >> n;
  int a;
  int sum = 0;
  rep(i,n){
    cin >> a;
    sum += a;
  }
  if(h-sum>0) printf("No\n");
  else printf("Yes\n");
  return 0;
}


Measured memory_bytes: 384
#include<bits/stdc++.h>
using namespace std;
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
//#define int long long 
const int N=1e5+5;
const int INF=1e9+5;
vector<int> dp(N,INF);



int main(){
    int n;
    scanf("%d",&n);
    int a[n];
    for(int i=0;i<n;i++)
      cin>>a[i];
      dp[0]=0;
    for(int i=0;i<n;i++){
        for(int j :{i+1,i+2}){
          if(j<n)
             dp[j]=min(dp[j],dp[i]+abs(a[i]-a[j]));
        }
    }

    printf("%d\n",dp[n-1]);  

return 0;
}

Measured memory_bytes: 1024
N = int(input())

def is_prime(n):
    if n == 2: return True
    if n < 2 or n%2 == 0: return False
    m = 3
    while m*m <= n:
        if n%m == 0: return False
        m += 2
    return True

ans = []
for n in range(11,55556,5):
    if is_prime(n):
        ans.append(n)
        if len(ans) == N:
            break
print(*ans)

Measured memory_bytes: 3060
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<iomanip>
#include<math.h>
#include<complex>
#include<queue>
#include<deque>
#include<stack>
#include<map>
#include<set>
#include<bitset>
#include<functional>
#include<assert.h>
#include<numeric>
using namespace std;
#define REP(i,m,n) for(int i=(int)(m) ; i < (int) (n) ; ++i )
#define rep(i,n) REP(i,0,n)
using ll = long long;
const int inf=1e9+7;
const ll longinf=1LL<<60 ;
const ll mod=1e9+7 ;

int main(){
	int n;
	cin>>n;
	ll ans=0;
	rep(i,n){
		int x;cin>>x;
		ans += x-i-1;
	}
	cout<<ans<<endl;
	return 0;
}


Measured memory_bytes: 3120
#include <bits/stdc++.h>
using namespace std;
 
int main(){
  int n; cin >> n;
  vector<int64_t> h(n);
  
  for (int i=0; i<n; i++){
    cin >> h.at(i);
  }
  
  int64_t ans=0;
  for(int i=0; i<n-1; i++){
    if (h.at(i) > h.at(i+1)){
      int dif = h.at(i)-h.at(i+1);
      h.at(i+1) += dif;
      ans += dif;
    }
  }
  cout << ans << endl;
}

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

public class Main {
	static int[] pow2= new int[16];
	static int calcPow2(int a){
		if(a == 0){
			return 1;
		}else if(pow2[a] == 0){
			int ans = calcPow2(a - 1) * 2;
			pow2[a] = ans;
			return ans;
		}else{
			return pow2[a];
		}
	}
	static int n;
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		n = sc.nextInt();
		int[][][] ary = new int[n][][];
		for(int i = 0; i < n; i++){
			int a = sc.nextInt();
			ary[i] = new int[a][2];
			for(int k = 0; k < a; k++){
				ary[i][k][0] = sc.nextInt() - 1;//人
				ary[i][k][1] = sc.nextInt();//正直or不親切
			}
		}
		int maxNum = 0;
		for(int bi = 0; bi < calcPow2(n); bi++){
			boolean flag = true;
			int[] bynary = new int[n];
			for(int k = 0; k < n; k++){
				bynary[k] = bi / calcPow2(k) % 2;
			}
			for(int i = 0; i < n; i++){
				if(bynary[i] == 1){//正直者が1
					for(int k = 0; k < ary[i].length; k++){
						if(bynary[ary[i][k][0]] != ary[i][k][1]){
							flag = false;
						}
					}
				}
			}
			if(flag){
				int num = 0;
				for(int n : bynary){
					num += n;
				}
				maxNum = Math.max(maxNum, num);
			}
		}
		System.out.println(maxNum);
	}
}



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

template <class T> inline bool chmin(T &a, const T &b) {
  return (a > b) ? a = b, true : false;
}

int main() {
  int N, W;
  std::cin >> N >> W;
  std::vector<int> w(N);
  std::vector<int> v(N);
  for (int i = 0; i < N; ++i)
    std::cin >> w[i] >> v[i];

  int K = N * 1000;
  long long inf = 1LL << 60;
  std::vector<std::vector<long long>> dp(
      N + 7, std::vector<long long>(2 * K + 7, inf));

  dp[0][0] = 0;
  for (int i = 0; i < N; ++i) {
    for (int k = 0; k <= K; ++k) {
      chmin(dp[i + 1][k], dp[i][k]);
      chmin(dp[i + 1][k + v[i]], dp[i][k] + w[i]);

      // for (int l = 0; l <= v[i]; ++l)
      //   chmin(dp[i + 1][k + l], dp[i][k] + w[i]);
    }
  }

  // for (int i = 0; i < N; ++i) {
  //   for (int k = 0; k < 10; ++k) {
  //     std::cout << " " << dp[i][k];
  //   }
  //   std::cout << std::endl;
  // }

  // for (int k = 0; k < 200; ++k)
  //   std::cout << "k: " << k << ": " << dp[N][k] << std::endl;

  long long res = -1;
  for (int k = 0; k <= K; ++k) {
    if (dp[N][k] <= W)
      res = k;
    // if (W < dp[N][k + 1]) {
    //   res = k;
    //   break;
    // }
  }
  std::cout << res << std::endl;
}


Measured memory_bytes: 169572
n=int(input())
a=list(map(int,input().split()))
j,c=0,0

for i in a:
    if i%2==0:
        j+=1
        if i%3==0:
            c+=1
        elif i%5==0:
            c+=1
    else :
        continue



if c==j:
    print("APPROVED")
else :
    print("DENIED")


Measured memory_bytes: 2940
#include <iostream>
using namespace std;
int i;
char c,v[]="aeiou";
int main()
{
    cin>>c;
    for(i=0;i<5;++i)
        if(v[i]==c)
    {
        cout<<"vowel";
        return 0;
    }
    cout<<"consonant";
    return 0;
}


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

int main() {
	int n,a,b;
	cin >> n;
	a = n / 100;
	b = a * 100 + a * 10 + a;
	if (n <= b)cout << b << endl;
	else cout << (a + 1) * 100 + (a + 1) * 10 + a + 1 << endl;
	return 0;
}

Measured memory_bytes: 256
/*input
6 9
3 4
6 1
2 4
5 3
4 6
1 5
6 2
4 5
5 6
*/
 
#include <iostream>
#include <iomanip>
#include <string>
#include <vector>
#include <algorithm>
#include <sstream>
#include <queue>
#include <deque>
#include <bitset>
#include <iterator>
#include <list>
#include <stack>
#include <map>
#include <set>
#include <functional>
#include <numeric>
#include <utility>
#include <limits>
#include <climits>
#include <time.h>
#include <math.h>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <assert.h>
#include <stdint.h>
#include <tgmath.h>
 
using namespace std;
 
/*******  All Required define Pre-Processors and typedef Constants *******/
#define ar array
#define scd(t) scanf("%d",&t)
#define scld(t) scanf("%ld",&t)
#define sclld(t) scanf("%lld",&t)
#define scc(t) scanf("%c",&t)
#define scs(t) scanf("%s",t)
#define scf(t) scanf("%f",&t)
#define sclf(t) scanf("%lf",&t)
#define rep(i, n) for (int i = 0; i < (n); i++)
#define FOREACH(it, l) for (auto it = l.begin(); it != l.end(); it++)
#define tests int r; cin >> r; while(r--)
#define MP make_pair
#define PI acos(-1)
typedef pair<int, int> PII;
typedef pair<double, double> PDD;
typedef vector<int> VI;
typedef vector<string> VS;
typedef vector<PII> VII;
typedef vector<VI> VVI;
typedef map<int,int> MPII;
typedef set<int> SETI;
typedef multiset<int> MSETI;
typedef long int int32;
typedef unsigned long int uint32;
typedef long long int int64;
typedef unsigned long long int  uint64;
#define godspeed ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(0);
 
#define M(x) ((x)%(1000000007))
#define MAXN   100001  
 

std::vector<int> ans;

void factorize(long long n){
   
   int count = 0;
   while (!(n % 2)) {
      n/= 2;
      count++;
   }
   if (count)
      ans.push_back(count);
   for (long long i = 3; i <= sqrt(n); i += 2) {
      count = 0;
      while (n % i == 0) {
         count++;
         n = n / i;
      }
      if (count)
      	ans.push_back(count);
   }
   if (n > 2)
   	ans.push_back(1);
}






int main() {
 	int64 n;
 	cin>>n;
 	int m;
 	cin>>m;
 	std::vector<int> adj[n+1];
 	int visited[n+1];
 	memset(visited,0,sizeof(visited));
 	rep(i,m){
 		int a;
 		int b;
 		cin>>a>>b;
 		adj[a].push_back(b);
 		adj[b].push_back(a);
 	}
 	queue<int> s;
 	s.push(1);
 	visited[1] = 1;
 	while(!s.empty()){
 		int a = s.front();
 		s.pop();
 		for(int node:adj[a]){
 			if(!visited[node]){
 				visited[node] = a;
 				s.push(node);
 			}
 		}
 	}
 	bool doable = true;
 	for(int i = 2; i<n+1;i++){
 		if(visited[i]==0){
 			doable = false;
 		}
 	}
 	if(!doable){
 		cout<<"No"<<endl;
 	}
 	else{
 		cout<<"Yes"<<endl;
		for(int i = 2; i<n+1;i++){
			cout<<visited[i]<<endl;
		}
 	}
}



 


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

void solve(){
    int n;
    cin>>n;
    vector<int>a(n),flag(n,0);
    for(int i=0;i<n;i++){
        cin>>a[i];
    }
    int ans=0,ctr=0;
    for(int i=n-1;i>0;i--){
        if(a[i]<=a[i-1]){
            ctr++;
        }
        else
        {
            ctr=0;
        }
        flag[i]=ctr;
        ans=max(ctr,ans);
    }
    cout<<ans<<endl;
}

int main(){
    solve();
    return 0;
}

Measured memory_bytes: 1024
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<cmath>
#define mod 1000000007
#define rg register
using namespace std;
int read()
{
    rg int x=0,f=1;
    char ch=getchar();
    while(ch-'0'<0||ch-'0'>9){if(ch=='-') f=-1;ch=getchar();}
    while(ch-'0'>=0&&ch-'0'<=9){x=x*10+ch-'0';ch=getchar();}
    return x*f;
}
int n,m,k;
int f[2][22][(1<<19)+5];
int a[22][22];
int nxt[(1<<19)][22];
int main()
{
    n=read();m=read();k=read();
    n--;
    for(rg int i=1;i<=k;i++)
    {
        rg int q=read(),w=read(),e=read();
        a[q][w]=e+1;
    }
    for(rg int i=0;i<(1<<n);i++)
    {
        rg int tmp=0; 
        for(rg int j=n;j>=1;j--)
        {
            if((i&(1<<(j-1)))!=0)  tmp=j;
            else                   nxt[i][j]=tmp;
        }
    }
    f[0][n][0]=1;
    int now=0;
    for(rg int i=1;i<=m;i++)
    {
        now^=1;
        for(rg int j=0;j<(1<<n);j++)  f[now][0][j]=f[now^1][n][j];
        for(rg int j=0;j<(1<<n);j++)  f[now^1][n][j]=0;
        for(rg int j=0;j<n;j++)
        {
            for(rg int k=0;k<(1<<n);k++)
            {
                if(!f[now][j][k])  continue;
                if(!a[i][j+1]||((k>>j)&1)==a[i][j+1]-1)
                {
                    f[now][j+1][k]=(f[now][j+1][k]+f[now][j][k])%mod; 
                }
                if(((k>>j)&1)==0&&a[i][j+1]!=1)
                {
                    rg int tmp=k+(1<<j);
                    if(nxt[k][j+1])  tmp-=(1<<(nxt[k][j+1]-1));
                    f[now][j+1][tmp]=(f[now][j+1][tmp]+f[now][j][k])%mod;
                }
                f[now][j][k]=0;
            }
        }
    }
    int ans=0;
    for(rg int i=0;i<(1<<n);i++)  ans=(ans+f[now][n][i])%mod;
    printf("%d\n",ans);
    return 0;
}

Measured memory_bytes: 131328
#include <iostream>
#include <stdlib.h>
#include <stdio.h>      /* printf */
#include <math.h>       /* pow */
#include <vector>
#include <algorithm>
#include <string>
#include <list>

void print_array(std::list<int> list)
{
    int j=0;
  for (std::list<int>::iterator i=list.begin(); i!=list.end(); ++i) {
    if(j>0) std::cout << " ";
    std::cout << *i;
    j++;
    }
  
  std::cout << std::endl;
}   

void insert(std::list<int> &list, int a) {
    list.push_front(a);
}

void deleteValue(std::list<int> &list, int a) {
  for (std::list<int>::iterator i=list.begin(); i!=list.end(); ++i) {
        if (*i==a) {
            list.erase(i);
            return;
        }
    }
}

void deleteFirst(std::list<int> &list) {
    list.pop_front();
}

void deleteLast(std::list<int> &list) {
    list.pop_back();
}

int main(void){

    std::cin.tie(0);
    std::ios::sync_with_stdio(false);
    
    int num;
    std::cin >> num;
    
    std::list<int> list;

    for(int i = 0; i < num; i++){
        std::string value;
        std::cin >> value;
 
        if(value=="insert") {
            int a;
            std::cin >> a;
            insert(list,a);
        } else if (value=="delete") {
            int a;
            std::cin >>a;
            deleteValue(list,a);
        } else if (value=="deleteFirst") {
            deleteFirst(list);
        } else if (value=="deleteLast") {
            deleteLast(list);
        }
    }
 
    print_array(list);

    return 0;
}

Measured memory_bytes: 32476
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>
#include <climits>

#define rep(i, m, n) for(int i=int(m);i<int(n);i++)
#define EACH(i, c) for (auto &(i): c)
#define all(c) begin(c),end(c)
#define EXIST(s, e) ((s).find(e)!=(s).end())
#define SORT(c) sort(begin(c),end(c))
#define pb emplace_back
#define MP make_pair
#define SZ(a) int((a).size())

//#define LOCAL 0
//#ifdef LOCAL
//#define DEBUG(s) cout << (s) << endl
//#define dump(x)  cerr << #x << " = " << (x) << endl
//#define BR cout << endl;
//#else
//#define DEBUG(s) do{}while(0)
//#define dump(x) do{}while(0)
//#define BR
//#endif


//改造
typedef long long int ll;
using namespace std;
#define INF (1 << 30)
#define INFl (ll)5e15
#define DEBUG 0 //デバッグする時1にしてね
#define dump(x)  cerr << #x << " = " << (x) << endl
#define MOD 1000000007
//ここから編集する


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

    int N,K;
    cin >> N >> K;
    vector<int> a(200001);
    rep(i,0,N){
        int tmp;
        cin >> tmp;
//        cin >> a[i];
        a[tmp]++;
    }
//    a.erase(a.begin(),unique(all(a)));

    sort(all(a));
    reverse(all(a));
    ll ans = 0;
    rep(i,K,a.size()){
        ans += a[i];
    }
    cout << ans << endl;




    return 0;
}


Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
const int N=3e5+5;
int n,u[N],d[N],ans;
char s[N];
int main(){
	scanf("%d",&n);
	ans=n-1;
	scanf("%s",s+1);
	for (int i=1;i<=n;++i)
		u[i]=u[i-1]+(s[i]=='W');
	for (int i=n;i>=1;--i)
		d[i]=d[i+1]+(s[i]=='E');
	for (int i=1;i<=n;++i)
		ans=min(ans,u[i-1]+d[i+1]);
	printf("%d\n",ans);
}

Measured memory_bytes: 6476
import java.util.*;
class Main{
    public static void main(String[] args){
	Scanner stdIn = new Scanner(System.in);
        int N = stdIn.nextInt();
	int A = stdIn.nextInt();
	int B = stdIn.nextInt();
	int min = A*N;
	if(min>B){
	    min=B;
	}
	System.out.println(min);
    }
}
	


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

int main(){
    int h,w,k,num=0;
    cin >> h >> w >> k;
    vector<int> a(h);
    char s[h][w];
    int ans[350][350]={};
    for(int i=0;i<h;i++){
        bool flag = 0;
        for(int j=0;j<w;j++){
            cin >> s[i][j];
            ans[i][j] = 0;
            if(s[i][j]=='#') flag = 1;
            if(!flag) ans[i][j]++;
        } 
        if(flag) a[i]=1;
    }
    int mina = 350;
    for(int i=0;i<h;i++){
        if(a[i]==1){
            mina = i;
            break;
        } 
    }
    for(int i=0;i<h;i++){
        if(a[i]==1){
            for(int j=0;j<w;j++){
                if(s[i][j]=='#') num++;
                ans[i][j] += num;
            }
        }
    }
    for(int i=mina;i<h-1;i++){
        for(int j=0;j<w;j++){
            if(a[i+1]==0) ans[i+1][j]=ans[i][j];
        }
    }
    for(int i=mina;0<=i;i--){
        for(int j=0;j<w;j++) ans[i][j] = ans[mina][j];
    }
    for(int i=0;i<h;i++){
        for(int j=0;j<w;j++) cout << ans[i][j] << ' ';
        cout << endl;
    }
}

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

string s;
int a[100009];
int main()
{
	cin>>s;
	int len=s.length();
	int sum=0;
	for(int i=0;i<len;i++)
	{
		if(s[i]=='L')
		{
			a[i-1]+=(sum+1)/2;
			a[i]+=sum/2;
			sum=0;
		}
		else sum++;
	}	
	sum=0;
	for(int i=len-1;i>=0;i--)
	{
		if(s[i]=='R')
		{
			a[i+1]+=(sum+1)/2;
			a[i]+=sum/2;
			sum=0;
		}
		else sum++;
	}
	for(int i=0;i<len;i++)
	{
		cout<<a[i]<<" "; 
	}
	return 0;
} 

Measured memory_bytes: 1088
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int main(){
  int N;
  string S;
  cin >> N >> S;
  
  ll cnt=0;
  ll r=0,g=0,b=0;
  
  for(int i=0;i<N;i++){
    if(S.at(i) == 'R'){
      r++;
    }else if(S.at(i) == 'G'){
      g++;
    }else{
      b++;
    }
  }
  
  for(int i=0;i<N;i++){
    for(int j=i+1;j<N;j++){
      if(2*j-i < N && S.at(i) != S.at(j) && S.at(i) != S.at(2*j-i) && S.at(j) != S.at(2*j-i)){
        cnt++;
      }
    }
  }
  
  cout << r*g*b - cnt << endl;
  
  return(0);
}

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

int main(){
  //nは木の本数、kは電飾を施す木の本数
  int n,k;
  cin >> n >> k;
  
  vector<int> vec(n);
  for(int i = 0;i < n;i ++){
    cin >> vec.at(i);
  }
  
  sort(vec.begin(),vec.end());
  
  vector<int> sa(n - 1);
  for(int i = 0;i < n - 1;i ++){
    sa.at(i) = vec.at(i + 1) - vec.at(i);
  }
  
  int ans = 0;
  
  for(int i = 0;i < n - k + 1;i ++){
    int kazu = 0;
    for(int j = 0;j < k - 1;j ++){
      kazu += sa.at(j + i);
    }
    if(i == 0)ans = kazu;
    else {
      if(ans > kazu)ans = kazu;
    }
  }
  
  cout << ans << endl;
}

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

public class Main {

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

			for (int i = 0; i < 3; i++) {
				a[i] = sc.nextInt();
			}

			Arrays.sort(a);

			System.out.println(a[0] + a[1] + a[2] * 10);

		}
	}
}


Measured memory_bytes: 23124
#include<iostream>
#include<stack>

using namespace std;

bool solve(stack<int> st1, stack<int> st2, int ball[10],int index){
	if(index == 10){
		return true;
	}
	if(st1.top() < ball[index]){
		st1.push(ball[index]);
		if(solve(st1,st2,ball,index+1)){
			return true;
		}else{
			st1.pop();
		}
	}
	if(st2.top() < ball[index]){
		st2.push(ball[index]);
		if(solve(st1,st2,ball,index+1)){
			return true;
		}else{
			st2.pop();
		}
	}
	return false;
}

int main(){
	stack<int> st1,st2;
	int ball[10];
	int n;
	cin >> n;
	for(int loop=0;loop<n;loop++){
		for(int i=0;i<10;i++){
			cin >> ball[i];
		}
		st1.push(0);
		st2.push(0);
		
		if(solve(st1,st2,ball,0)){
			cout << "YES" << endl;
		}else{
			cout << "NO" << endl;
		}
	}
}

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

int main(){
  int n;
  cin >> n;
  string s;
  cin >> s;
  char c = s[0];
  int res = 1;
  rep(i,n) {
    if (s[i] != c) res++,c = s[i]; 
  }
  cout << res << endl;
  return 0;
}

Measured memory_bytes: 512
import java.util.*;
public class Main {
	public static void main(String[] args){
      Scanner sc = new Scanner(System.in);
      int N = sc.nextInt();
      int A = sc.nextInt();
      int B = sc.nextInt();
      int C = sc.nextInt();
      int D = sc.nextInt();
      String s = sc.next();
      String ans = "Yes";
      if(s.charAt(C-1)=='#' || s.charAt(D-1)=='#'){
          ans = "No";
      }
      if(D<C){
        String str = s.substring(A-1,C);
        if(str.contains("##")){
           ans = "No";
        }
        str = s.substring(B-2,D+1);
        if(!(str.contains("..."))){
          ans = "No";
        }
      }else{
        String str = s.substring(A-1,D);
        if(str.contains("##")){
           ans = "No";
        }
      }
      System.out.println(ans);
    }
}

Measured memory_bytes: 40864
import java.util.Scanner;

//Roll-A-Big-Ball
public class Main{

final double EPS = 1e-8;
	
	double dot(double[] a, double[] b){
		return a[0]*b[0]+a[1]*b[1];
	}
	double cross(double[] a, double[] b){
		return a[0]*b[1]-a[1]*b[0];
	}
	double norm(double[] a){
		return Math.hypot(a[0], a[1]);
	}
	double norm(double[] a, double[] b){
		return Math.hypot(a[0]-b[0], a[1]-b[1]);
	}
	double[] sub(double[] a, double[] b){
		return new double[]{a[0]-b[0], a[1]-b[1]};
	}
	double ex(double[] a, double[] b, double[] c){
		double[] s1 = sub(b, a), s2 = sub(c, a);
		return cross(s1, s2);
	}
	double area(double[] a, double[] b, double[] c){
		double res = cross(a, b)+cross(b, c)+cross(c, a);
		return Math.abs(res)/2;
	}
	boolean crossing(double[] a, double[] b, double[] s, double[] t){
		if(ex(a, b, s)*ex(a, b, t)>0)return false;
		if(ex(b, a, s)*ex(b, a, t)>0)return false;
		if(ex(s, t, a)*ex(s, t, b)>0)return false;
		return ex(t, s, a)*ex(t, s, b)<0;
	}
	//Segment a-b Point p
	double dist(double[] a, double[] b, double[] p){
		if(dot(sub(b, a), sub(p, a))<EPS)return norm(a, p);
		if(dot(sub(a, b), sub(p, b))<EPS)return norm(b, p);
		return Math.abs(cross(sub(b, a), sub(p, a)))/norm(a, b);
	}
	//Segment a-b Segment s-t
	double dist(double[] a, double[] b, double[] s, double[] t){
		if(crossing(a, b, s, t))return 0;
		return Math.min(dist(a, b, s), Math.min(dist(a, b, t), Math.min(dist(s, t, a), dist(s, t, b))));
	}
	
	double[] S, T;
	double[][][] p;
	
	boolean in(int k){
		double area = norm(p[k][0], p[k][1])*norm(p[k][1], p[k][2]);
		double s = 0;
		for(int i=0;i<4;i++)s+=area(p[k][i], p[k][(i+1)%4], S);
		return Math.abs(area-s)<EPS;
	}
	
	void run(){
		Scanner sc = new Scanner(System.in);
		for(;;){
			int n = sc.nextInt();
			if(n==0)break;
			S = new double[]{sc.nextDouble(), sc.nextDouble()}; T = new double[]{sc.nextDouble(), sc.nextDouble()};
			p = new double[n][4][2];
			double[] h = new double[n];
			for(int i=0;i<n;i++){
				double x1 = sc.nextDouble(), y1 = sc.nextDouble(), x2 = sc.nextDouble(), y2 = sc.nextDouble();
				h[i] = sc.nextDouble();
				p[i][0] = new double[]{x1, y1};
				p[i][1] = new double[]{x2, y1};
				p[i][2] = new double[]{x2, y2};
				p[i][3] = new double[]{x1, y2};
			}
			double R = 1000;
			for(int i=0;i<n;i++){
				if(in(i)){
					R = 0; break;
				}
				double d = 1<<29;
				for(int j=0;j<4;j++)d = Math.min(d, dist(S, T, p[i][j], p[i][(j+1)%4]));
				if(h[i]<d)R = Math.min(R, (h[i]*h[i]+d*d)/2/h[i]);
				else R = Math.min(R, d);
			}
			System.out.printf("%.6f\n", R);
		}
	}
	
	public static void main(String[] args) {
		new Main().run();
	}
}

Measured memory_bytes: 13000
import collections
from operator import mul
from functools import reduce

def C(n, r):
    r = min(r, n - r)
    numer = reduce(mul, range(n, n - r, -1), 1)
    denom = reduce(mul, range(1, r + 1), 1)
    return numer // denom

def main():
  n = input()
  n = int(n)
  x = []
  for i in range(n):
    l = input()
    x.append(''.join(sorted(l)))

  c = collections.Counter(x)
  values, counts = zip(*c.most_common())
  sum = 0
  for i in range(len(counts)):
    if counts[i] > 1:
      sum += C(counts[i], 2)
  print(sum)


if __name__ == '__main__':
    main()

Measured memory_bytes: 89304
extern crate core;

use std::io::{self, Read};

fn main() {
    let mut input = String::new();
    io::stdin().read_to_string(&mut input).unwrap();
    let output = run(input.trim().to_string());
    println!("{}", output);
}

fn run(input: String) -> String {
    let mut iter = input.split_whitespace().map(|x| x.parse::<i64>().unwrap());
    let n = iter.next().unwrap();
    let d = iter.next().unwrap();
    let x = iter.next().unwrap();
    let list = iter.collect::<Vec<_>>();
    let mut sum = 0;
    for a in list {
        for n in 0.. {
            if n * a + 1 > d {
                break;
            } else {
                sum += 1;
            }
        }
    }
    (x + sum).to_string()
}

macro_rules! tests {
    ($($name:ident: $input:expr=>$output:expr,)*) => {
        mod tests {
            $(
                #[test]
                fn $name() {
                    assert_eq!(super::run($input.to_string()), $output.to_string());
                }
            )*
        }
    }
}

tests! {
    test1: "3\n7 1\n2\n5\n10" => "8",
    test2: "2\n8 20\n1\n10" => "29",
    test3: "5\n30 44\n26\n18\n81\n18\n6" => "56",
}


Measured memory_bytes: 4352
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int sz = 3e5+5;

int a[sz];

int main()
{
    int k, a, b;
    cin >> k >> a >> b;
    for(int i=a; i<=b; i++) {
        if(i%k==0) {
            puts("OK");
            exit(0);
        }
    }
    puts("NG");
}


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

using namespace std;

int main()
{
    string s;
    while (getline(cin, s)) {
        for (int o = 0; ; o++) {
            string p = s;
            for (int i = 0; i < p.size(); i++) {
                if (isalpha(p[i])) {
                    p[i] = ((p[i] - 'a' + o) % 26) + 'a';
                }
            }
            if (p.find("that") != -1 || p.find("this") != -1 || p.find("the") != -1) {
                cout << p << endl;
                break;
            }
        }
    }
}

Measured memory_bytes: 0
ni = lambda: int(input())
nm = lambda: map(int, input().split())
nl = lambda: list(map(int, input().split()))

s = [_ for _ in input()]
t = [_ for _ in input()]

for i in range(len(s)):
  s = [s[-1]] + s[:-1]
  if s==t:
    print('Yes')
    exit()
print('No')

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

int main(int argc, char const *argv[])
{
  long long S, c;
  cin >> S >> c;
  if(2 * S >= c)
    cout << c / 2 << flush;
  else
    cout << S + (c - 2 * S) / 4 << flush;
  return 0;
}


Measured memory_bytes: 256
import java.util.*;
public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
	    int cnt = sc.nextInt();
        int a[]= new int[cnt];
        int sigcnt =0;
      String answer = "YES";
        for(int i=0 ; i<cnt ; i++){
         a[i]=sc.nextInt(); 
        }
        for(int i=0 ; i<cnt ; i++){
         if(a[i]!=i+1){
           sigcnt++;
         }
         if(sigcnt>2){
           answer="NO";
           break;
         }
        }

		System.out.println(answer);

	}
}


Measured memory_bytes: 23252
#include<stdio.h>
#include<string.h>
int main()
{
    int x,n,i;
    char s[10000];
    scanf("%d",&n);
    scanf("%s",s);
    x=strlen(s);
    for(i=0;i<x;i++)
    {
        s[i]=(s[i]+n);
        if(s[i]>90)
        {
            s[i]=(s[i]-26);
        }
    }
    printf("%s\n",s);
}


Measured memory_bytes: 1672
#pragma GCC optimize("O3")
#pragma GCC target("sse4")
#define _CRT_SECURE_NO_WARNINGS
#include <vector>
#include <iostream>
#include <iomanip>
#include <string.h>
#include <algorithm>
#include <cmath>
#include <math.h>
#include <set>
#include <unordered_set>
#include <map>
#include <unordered_map>
#include <string>
#include <stack>
#include <queue>
#include <deque>
#include <time.h>
#include <bitset>
using namespace std;

typedef double LD;
typedef long long LL;
typedef pair<int, int> PII;
#define MP make_pair
#define PB push_back
//#define X first
//#define Y second

#define FOR(i, a, b) for(int i = (a); i < (b); ++i)
#define RFOR(i, b, a) for(int i = (b) - 1; i >= (a); --i)
#define REP(i, t) FOR(i, 0, t)
#define ALL(a) a.begin(), a.end()
#define SZ(a) (int)((a).size())
#define FILL(a, value) memset(a, value, sizeof(a))

const LD PI = acos(-1.0);
const LD EPS = 1e-6;
const int INF = 1000000007;
const LL LINF = 1e18;
const int mod = 1000000007;
const LL MAX = 607;

string S[MAX];
bool DP[MAX >> 1][MAX][MAX];

int main()
{
	ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
	//freopen("In.txt", "r", stdin);
	int n;
	cin >> n;
	REP(i, n)
	{
		cin >> S[i];
		S[i] += S[i];
		S[n + i] = S[i];
	}
	REP(i, n << 1)
		REP(j, n << 1)
		DP[0][i][j] = true;
	FOR(k, 1, n + 1)
		FOR(i, k - 1, n << 1)
		REP(j, (n << 1) - k + 1)
	{
		if (k <= 1)
			DP[k][i][j] = true;
		else
			DP[k][i][j] = DP[k - 2][i - 1][j + 1] && S[i][j] == S[i - k + 1][j + k - 1];
	}
	int ans = 0;
	REP(i, n)
		REP(j, n)
	{
		bool ok = true;
		REP(k, n)
			if (!DP[k + 1][i + k][j] || !DP[k + 1][i + n - 1][j + n - 1 - k])
				ok = false;
		ans += ok;
	}
	cout << ans;
	//system("pause");
	return 0;
}

Measured memory_bytes: 109184
LI = lambda: list(map(int, input().split()))

N, D = LI()
XY = [LI() for _ in range(N)]


def main():
    ans = 0
    d2 = D ** 2
    for x, y in XY:
        if x ** 2 + y ** 2 <= d2:
            ans += 1
    print(ans)


if __name__ == "__main__":
    main()


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

int n, mn = 1e9;

int f(int p, int q) {
	if (p == 0) return 0;
	return f(p / q, q) + p % q;
}

int main()
{
	int i;
	cin >> n;
	for (i = 0; i <= n; i++) mn = min(mn, f(i, 6) + f(n - i, 9));
    cout << mn << endl;
    return 0;
}

Measured memory_bytes: 256
/* Bismillahir Rahmanir Rahim */

#include <bits/stdc++.h>

#define rep(i, n)	for(int i=0;i<n;i++)
#define repn(i, n)	for(int i=1;i<=n;i++)
#define set(i, n)	memset(i, n, sizeof(i))

#define mx		1000007
#define pb		push_back
#define inf 	(1 << 30)

#define f	first
#define s 	second

using namespace std;

typedef long long ll;
typedef pair<int, int> pii;

int main(){
	int a, b, c;
	cin >> a >> b >> c;
	if(a == b + c) cout << "Yes\n";
	else if(b == a + c) cout << "Yes\n";
	else if(c == a + b) cout << "Yes\n";
	else cout << "No\n";
	return 0;
}


Measured memory_bytes: 256
#include<vector>
#include<cmath>
#include<complex>
#include<iostream>
#include<stdio.h>
#include<string>
#include<stdlib.h>
#include<float.h>
#include<set>
#include<map>
#include<queue>
#include<math.h>
#include<algorithm>
using namespace std;


typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef vector<vvd> vvvd;
typedef pair<int, int> pii;
typedef vector<pii> vpii;

#define pb push_back
#define mp make_pair
#define snd second
#define fst first
#define debug printf("--%d--\n",__LINE__)
#define ll long long int

int N, K;
int a[2000], b[2000];
int main(void){
	cin >> N >> K;
	vector<vector<int> > nbh(N);
	for(int i=0;i<N-1;i++){
		cin >> a[i] >> b[i];
		nbh[a[i]-1].pb(b[i]-1);
		nbh[b[i]-1].pb(a[i]-1);
	}
	
	int maxi = 0;
	if (K%2){
		for(int i=0;i<N;i++){
			for(int k=0;k<nbh[i].size();k++){
				int d = nbh[i][k];
				queue<int> q;
				vector<int> dep(N);
				q.push(d);
				q.push(i);
				dep[i] = 1;
				dep[d] = 1;
				int cnt = 2;
				while(!q.empty()){
					int now = q.front();q.pop();
					if (dep[now]>=(K+1)/2) continue;
					for(int j=0;j<nbh[now].size();j++){
						if (dep[nbh[now][j]]==0){
							dep[nbh[now][j]] = dep[now] + 1;
							q.push(nbh[now][j]);
							cnt++;
						}
					}
				}
				//cout << i << " " << cnt << endl;
				maxi = max(maxi, cnt);
			}
		}
	}else{
		for(int i=0;i<N;i++){
			queue<int> q;
			vector<int> dep(N);
			q.push(i);
			dep[i] = 1;
			int cnt = 1;
			while(!q.empty()){
				int now = q.front();q.pop();
				if (dep[now]>=K/2+1) continue;
				for(int j=0;j<nbh[now].size();j++){
					if (dep[nbh[now][j]]==0){
						dep[nbh[now][j]] = dep[now] + 1;
						q.push(nbh[now][j]);
						cnt++;
					}
				}
			}
			//cout << i << " " << cnt << endl;
			maxi = max(maxi, cnt);
		}
	}
	cout << N - maxi << endl;
	
	return 0;
}


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

 int main() {
   int n;
   cin >> n;
   vector<int> p(n);
   int min = 1000000000;
   int count = 0;
   for (int i = 0; i < n; i++) {
     cin >> p[i];
     if (min > p[i] ) {
       count++;
       min = p[i];
     }
   }

   cout << count << '\n';
 }


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

// long long power(long long a, long long b) {
//     long long ans = 1;
//     while (b) {
//         ans = ans * a;
//         b--;
//     }

//     return ans;
// }

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

//     string res = "";

//     long long temp = 1, count = 0;
//     while (temp <= n) {
//         temp += temp * 26;
//         count++;
//     }

//     cout << count << endl;
//     while (n) {
//         temp = 0;
//         long long curr = power(26, count-1), prev = 1;
//         char ch = 'a' - 1;

//         cout << "currently dealing with " << curr << endl;
//         while (temp <= n) {
//             prev = temp;
//             temp += curr;
//             ch++;
//         }
//         count--;
//         ch--;
//         n = n - prev;
//         cout << "update " << count << " " << n << " tep " << temp << " prev " << prev << endl;
//         cout << ch << endl;
//     }
//     while (count--) cout << "a";
//     cout << endl;
// }

#include <bits/stdc++.h>
using namespace std;

int main() {
    int n;
    cin >> n;
    
    vector<int> countbits(31, 0), arr(n, 0);
    for (int i = 0; i < n; i++) {
        int x;
        cin >> x;
        arr[i] = x;
        for (int j = 0; j < 31; j++)
            countbits[j] += (((x >> j) & 1) > 0);
    }

    vector<int> sol(n, 0);
    for (int i = 0; i < n; i++) {
        int x = arr[i];
        for (int j = 0; j < 31; j++) {
            if ((countbits[j] - (((x >> j) & 1) > 0)) & 1)
                sol[i] |= (1 << j);
        }
    }

    for (int i = 0; i < n; i++) {
        cout << sol[i] << " ";
    }
    cout << endl;
}

Measured memory_bytes: 4768
N=int(input())
ans=''
t=1
while(N>0):
    s=N%26
    if s==0:
        s+=26
    ans+=chr(s+96)
    if s!=26:
        N//=26
    else:
        N-=1
        N//=26
    t+=1
print(ans[::-1])

Measured memory_bytes: 61672
import java.util.Scanner;

public class Main {
  public static void main(String[] args) {
    Scanner scan = new Scanner(System.in);
    String str_scan = scan.nextLine();
    // int型へ変換
    var N = Integer.parseInt(str_scan);
    int AxB = 0;
    int max = N / 2;
    int ans = 0;
    int kasan = N - max;

    for (var i = 1;i <= max;i++){
      for (var j = 1; j <= max;j++){

        AxB=i*j;

        if (AxB < N){
          ans++;
        }else{
          break;
        }
      }
    }

    ans = ans + kasan + kasan - 2;

    System.out.println(ans);
    scan.close();
  }
}

Measured memory_bytes: 35852
/* This code is written by Nemlit */
#include<bits/stdc++.h>
using namespace std;
#define il inline
#define re register
#define debug printf("Now is Line : %d\n",__LINE__)
#define file(a) freopen(#a".in","r",stdin);freopen(#a".out","w",stdout)
#define rep(i, a, b) for(re int i = (a); i <= (b); ++ i)
#define drep(i, a, b) for(re int i = (b); i >= (a); -- i)
#define Next(i, u) for(re int i = head[u]; i; i = e[i].next)
#define mem(k, p) memset(k, p, sizeof(k))
#define int long long
#define D double
#define inf 1023456789
#define mod 1000000007
#define lb(x) (x)&(-(x))
il int read() {
    re int x = 0, f = 1; re char c = getchar();
    while(c < '0' || c > '9') { if(c == '-') f = -1; c = getchar();}
    while(c >= '0' && c <= '9') x = x * 10 + c - 48, c = getchar();
    return x * f;
}
il int Mul(int a, int b) { return 1ll * a * b % mod; }
il int Inc(int a, int b) { return (a += b) >= mod ? a - mod : a; }
il int Dec(int a, int b) { return (a -= b) < 0 ? a + mod : a; }
il int qpow(int a, int b) { int r = 1; while(b) { if(b & 1) r = Mul(r, a); a = Mul(a, a), b >>= 1; } return r; }
#define maxn 200005
namespace Graph {
	int head[maxn], cnt;
	struct edge { int v, next; }e[maxn << 1];
	il void add(int u, int v) { e[++ cnt] = (edge){v, head[u]}, head[u] = cnt; }
}
//using namespace Graph;
int n, m, sum[maxn * 44], rt, a[maxn], cnt, L = -200000, R = (1e9) + 200000, ls[maxn * 44], rs[maxn * 44];
il void insert(int &k, int l, int r, int ll) {
	if(!k) k = ++ cnt; ++ sum[k];
	if(l == r) return;
	int mid = (l + r) >> 1;
	if(ll <= mid) insert(ls[k], l, mid, ll);
	else insert(rs[k], mid + 1, r, ll);
}
il int query(int k, int l, int r, int ll) {
	if(l == r) return sum[k];
	int mid = (l + r) >> 1;
	if(ll <= mid) return query(ls[k], l, mid, ll);
	else return query(rs[k], mid + 1, r, ll);
}
signed main() {
	n = read();
	rep(i, 1, n) a[i] = read();
	rep(i, 1, n) {
		m += query(1, L, R, i - a[i]);
		insert(rt, L, R, i + a[i]);
	}
	cout << m;
	return 0;
}

Measured memory_bytes: 45996
#include<cstdio>
#include<iostream>
#include<cstring>
#include<algorithm>
#include<cmath>
#include<queue>
#include<set>
using namespace std;
typedef long long ll;
const int inf=1<<29;
const ll Maxn=1e6;
const double pi=3.1415926536;



int main(){
	ll n,t,x,s,mid;
	ll sum=0;
	cin>>n>>t;
	cin>>s;
	mid=s;
	for(int i=1;i<n;i++){
		cin>>x;
				if(x-mid>=t){
					sum+=t; 
					mid=x;
				}
				if(x-mid<t){
					sum+=x-mid;
					mid=x;
				}
	}
		printf("%lld\n",sum+t);
	}


Measured memory_bytes: 384
#include<iostream>
#include<algorithm>
using namespace std;
#define int long long
int n, p[101][20];
bool a[20], f[101][20];
int f1(int k) {
	if (k == 10) {
		if (!a[0] && !a[1] && !a[2] && !a[3] && !a[4] && !a[5] && !a[6] && !a[7] && !a[8] && !a[9])return -1145141919810;
		int r = 0;
		for (int i = 0; i < n; i++) {
			int cnt = 0;
			for (int j = 0; j < 10; j++) 
				if (a[j] && f[i][j])cnt++;
			r += p[i][cnt];
		}
		return r;
	}
	int p1, p2;
	a[k] = 0;
	p1 = f1(k + 1);
	a[k] = 1;
	p2 = f1(k + 1);
	return max(p1, p2);
}
signed main() {
	cin >> n;
	for (int i = 0; i < n; i++)for (int j = 0; j < 10; j++)cin >> f[i][j];
	for (int i = 0; i < n; i++)for (int j = 0; j <= 10; j++)cin >> p[i][j];
	cout << f1(0) << "\n";
}

Measured memory_bytes: 256
#include <iostream>
#include <sstream>
#include <string>
#include <cassert>
#include <cmath>
#include <climits>
#include <cstdio>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <stack>
#include <algorithm>
#include <functional>
#include <numeric>
#include <iomanip>

using namespace std;
typedef unsigned int uint;
typedef long long ll;
typedef unsigned long long ull;

#define REP(i,n) for(int i = 0; i < (int)(n); ++i)
#define FOR(i,a,b) for(int i = (a); i < (int)(b); ++i)
#define ALL(c) (c).begin(), (c).end()
#define SIZE(v) ((int)v.size())

#define pb push_back
#define mp make_pair
#define mt make_tuple

vector<int> Ps;
vector<set<int>> Cs;
vector<int> Xs;

tuple<bool, int, int> dfs(int v) {
    // leaf
    if (Cs[v].empty()) {
        // cout << "v " << v << ": possible(leaf)" << endl;
        return mt(true, Xs[v], 0);
    }

    int sum_of_subtree = 0;
    set<int> possible{0};

    for(auto c: Cs[v]) {
        auto ret = dfs(c);
        auto ok_flag = get<0>(ret);
        auto col1 = get<1>(ret);
        auto col2 = get<2>(ret);
        sum_of_subtree += (col1 + col2);
        if (!ok_flag) return mt(false, 0, 0);

        set<int> possible2;
        for(auto p: possible) {
            if (p + col1 <= Xs[v]) possible2.insert(p + col1);
            if (p + col2 <= Xs[v]) possible2.insert(p + col2);
        }
        possible = possible2;
    }

    if (possible.empty()) return mt(false, 0, 0);

    // cout << "possible: ";
    // for(auto p: possible) cout << p << " ";
    // cout << endl;

    auto max_possible = *possible.rbegin();
    int add = Xs[v] - max_possible;

    // cout << "v " << v << ": possible:" << endl;
    // cout << "   " << Xs[v] << ", " << sum_of_subtree + add - Xs[v] << endl;

    return mt(true, Xs[v], sum_of_subtree + add - Xs[v]);
}

int main(void)
{
    cin.sync_with_stdio(false);
    int N;
    cin >> N;

    Ps.resize(N);
    Cs.resize(N);
    Xs.resize(N);

    REP(n, N-1) {
        int c = n+1;
        int p;
        cin >> p; --p;

        Ps[c] = p;
        Cs[p].insert(c);
    }
    Ps[0] = -1;

    REP(n,N) cin >> Xs[n];

    auto ret = dfs(0);
    if (get<0>(ret)) {
        cout << "POSSIBLE" << endl;
    }
    else {
        cout << "IMPOSSIBLE" << endl;
    }
    
    return 0;
}


Measured memory_bytes: 640