akhauriyash/Code-Regression huggingface dataset:
///Bismillahir Rahmanir Rahim
#include<bits/stdc++.h>

#define                           int                         long long
#define                           fi                          first
#define                           si                          second
#define                           mp                          make_pair
#define                           pb                          push_back
#define                           pi                          pair<int,int>
#define                           f(i,l,r)                    for(int i=l;i<=r;i++)
#define                           rf(i,r,l)                   for(int i=r;i>=l;i--)
#define                           done(i)                     cout<<"done = "<<i<<endl;
#define                           fast                        ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);




using namespace std;

const int inf=1e18;
const int mod=1e9+7;
const int M=100009;
inline int bigmod(int B,int P){int R=1;while(P>0){if(P&1){R=(R*B)%mod;}P>>=1;B=(B*B)%mod;}return R;}

int n;
string s;

bool chk(int x)
{
    map<string,int>fst;
    map<string,int>lst;
    f(i,0,n-1)
    {
        string p=s.substr(i,x);
        if(p.size()<x)break;
        if(fst.count(p)==0)
        {
            fst[p]=i;
        }
    }
     rf(i,n-1,0)
    {
        string p=s.substr(i,x);
        if(p.size()<x)continue;
        if(lst.count(p)==0)
        {
            lst[p]=i;
        }
    }
     for(auto yo:fst)
     {
         int lft=yo.si;
         int rgt=lst[yo.fi];
         if(lft+x<=rgt)
         {
             return true;
         }
     }
     return false;

}
 main()

{
    fast
    cin>>n;
    cin>>s;
    int lo=0,hi=n;
    while(hi-lo>=2)
    {
        int mid=(lo+hi)>>1;
        if(chk(mid))
        {
            lo=mid;
        }
        else hi=mid-1;
    }
    int ses=0;
    f(i,lo,hi)
    {
        if(chk(i))ses=i;
    }
    cout<<ses<<endl;
    return 0;

}













Measured memory_bytes: 13080
import numpy as np,sys
def LI(): return list(map(int,sys.stdin.readline().rstrip().split()))
N,M = LI()
ab = np.array([LI() for _ in range(N)])
cd = np.array([LI() for _ in range(M)])
for x in ab:
    print(abs(cd-x).sum(axis=1).argmin()+1)


Measured memory_bytes: 12432
#include <bits/stdc++.h>
using namespace std;
#define _GLIBCXX_DEBUG
#define rep(i, from, to) for (int i = from; i < (to); ++i)
#define mp(x,y) make_pair(x,y)
#define all(x) (x).begin(),(x).end()
#define sz(x) (int)(x).size()
using ll = long long;
using vin=vector<int>;
using vll=vector<ll>;
using P = pair<int, int>;
const int inf=1e9+7;
const ll INF=1e18;
template <typename T> void chmin(T &a, T b) { a = min(a, b); }
template <typename T> void chmax(T &a, T b) { a = max(a, b); }

int main() {
  string s;
  cin>>s;
  int n=s.size();
  ll ans=0;
  int c=0;
  rep(i,0,n){
    if(s[i]=='W') {
      c++;
      ans+=i-c+1;
    }
  }
  cout<<ans<<endl;
}

Measured memory_bytes: 3700
#!/usr/bin/env python
# -*- coding: utf-8 -*-

while True:
    n,m = map(int,input().split(" "))
    if n == 0 and m == 0:
        break
    prices = list(map(int,input().split(" ")))
    count = 0
    cost = 0
    for p in reversed(sorted(prices)):
        count += 1
        if count >= m:
            count = 0
            continue
        else:
            cost += p
    print(cost)

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

int main()
{
  string b="",m,n;cin>>m>>n;
  int f=n.size()-1;
  for(int i=0;i<f;i++)
  {
    b+=n[i];
  }

  if(b==m)cout<<"Yes";
  else
    cout<<"No";


 return 0;
}


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

typedef unsigned long long ull;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<double, double> pdd;
const ull mod = 1e9 + 7;
#define REP(i,n) for(int i=0;i<(int)n;++i)

//debug
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

template<class S, class T> ostream& operator << (ostream& os, const pair<S, T> v){
  os << "(" << v.first << ", " << v.second << ")"; return os;
}
template<class T> ostream& operator << (ostream& os, const vector<T> v){
  for(int i = 0; i < v.size(); i++){if(i > 0){os << " ";} os << v[i];} return os;
}
template<class T> ostream& operator << (ostream& os, const vector<vector<T>> v){
  for(int i = 0; i < v.size(); i++){if(i > 0){os << endl;} os << v[i];} return os;
}

map<ll, ll> mp;
void prime_factorization(ll x){
    bool flag = true;
    while(flag){
        ll sqx = sqrt(x)+1;
        for(ll j=2;j<sqx+1;j++){
            if(x%j==0){
                mp[j]++;
                x/=j;
                break;
            }
            if(j==sqx) flag = false;
        }
    }
    if(x!=1){
        mp[x]++;
    }
}

bool prime_check(ll x){
	bool flag = true;
	if(x==1) flag = false;
	ll sqx = sqrt(x)+1;
    for(ll j=2;j<sqx+1;j++){
    	if(x==j) continue;
        if(x%j==0){
            flag = false;
            break;
        }
    }
    return flag;
}

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

    ll N;
    cin >> N;
    vector<ll> a(N+1);
    REP(i, N+1) cin >> a[i];

    vector<ll> res;
    reverse(a.begin(), a.end());
    prime_factorization(abs(a[N]));
    for(auto x: mp){
    	ll p = x.first;
    	bool flag = true;
    	REP(i, N+1){
    		if(abs(a[i])%p != 0) flag = false;
    	}
    	if(flag) res.push_back(p);
    }
    for(int p=2;p<N+1;p++){
    	if(prime_check(p)){
    		//dump(p)
    		bool flag = true;
    		vector<ll> sum(p, 0);
    		sum[0] = a[0];
    		for(int i=1;i<N+1;i++){
    			ll ind = i%(p-1);
    			if(ind == 0) ind = p-1;
    			sum[ind] += a[i];
    		}
    		REP(i, p){
    			sum[i] %= p;
    			if(sum[i] < 0) sum[i] += p;
    			if(sum[i]%p != 0) flag = false;
    		}
    		if(flag) res.push_back(p);
    	}
    }
    sort(res.begin(), res.end());
    res.erase(unique(res.begin(), res.end()), res.end());
    REP(i, res.size()){
    	cout << res[i] << endl;
    }
    return 0;
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
const ll INF = 1LL << 60;

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

    for (int tmp = 0; tmp < (1 << 3); tmp++) {
        bitset<3> op(tmp);
        int cal = s[0] - '0';
        string ans = "";
        ans += s[0];

        for (int i = 0; i < 3; i++) {
            if (op.test(i)) { //1なら処理実行
                cal = cal + s[i + 1] - '0';
                ans = ans + "+" + s[i + 1];
            } else {
                cal = cal - (s[i + 1] - '0');
                ans = ans + "-" + s[i + 1];
            }
        }

        if (cal == 7) {
            cout << ans << "=7" << endl;
            return 0;
        }
    }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define forn(i, n) for (int i = 0; i < int(n); i++)
#define forna(i,a,n) for(int i =a; i < n; i++)
#define fornd(i,a) for (int i = (a)-1; i >= 0; i--)
#define endl '\n'
#define fastIO ios_base::sync_with_stdio(0);cin.tie(0);
#define all(x) x.begin(), x.end()
typedef long long int unsigned lliu;
typedef long long int lli;
typedef long double ld;
typedef pair<int,int> pi;
typedef vector<int> vi;
typedef vector<lli> vlli;
typedef vector<vi> vvi;
typedef vector<pi> vpi;
#define MAXN 200005
int main(){
	fastIO
	int n;
	cin>>n;
	vi costo(n);
	forn(i, n){
		cin>>costo[i];
	}
	vlli mem(n+1);
	mem[n-1]=0;
	mem[n-2]=abs(costo[n-1]-costo[n-2]);
	for(int i=n-3; i>=0; i--){
		mem[i]=min(mem[i+1]+abs(costo[i]-costo[i+1]), mem[i+2] + abs(costo[i]-costo[i+2]));
	}
	cout<<mem[0]<<endl;

	return 0;
}

Measured memory_bytes: 1408
#include <iostream>

void print_array(int a[], int n){
    for(int i=0; i<n; i++){
        std::cout << a[i];
        if(i<n-1){
            std::cout << " ";
        }
    }
    std::cout << '\n';
}

void sort(int a[], int n){
    print_array(a,n);
    for(int i=1; i<n; i++){
        int key = a[i];
        int j = i-1;
        while(j>=0 && a[j]>key){
            a[j+1] = a[j];
            j--;
        }
        a[j+1] = key;
        print_array(a,n);
    }
}

int main(){

    int N;
    std::cin >> N;
    int A[N];
    for(int i=0; i<N; i++){
        std::cin >> A[i];
    }

    sort(A,N);

    return 0;
}


Measured memory_bytes: 3072
n = int(input())
a = list(map(int,input().split()))

d = sum(a)
ans = float('inf')
for i in range(n-1):
    if i == 0:
        x = a[0]
        y = d - x
    else:
        x += a[i]
        y -= a[i]
    ans = min(abs(x-y),ans)
print(ans)

Measured memory_bytes: 76880
import java.util.*;
import java.lang.*;
import java.math.*;
import java.io.*;

import static java.lang.Math.*;
import static java.util.Arrays.*;

public class Main{

	Scanner sc=new Scanner(System.in);

	int INF=1<<28;
	double EPS=1e-9;

	void run(){
		int max=1000001;
		int[] memo=new int[max];// nツ暗按可コ
		boolean[] f=new boolean[max];
		LinkedList<Integer> que=new LinkedList<Integer>();
		que.offer(1);
		f[1]=true;
		int[] ms={2, 3, 5};
		for(; !que.isEmpty();){
			int n=que.poll();
			for(int m : ms){
				if(n*m<max&&!f[m*n]){
					que.offer(n*m);
					f[n*m]=true;
				}
			}
		}
		for(int i=1; i<max; i++){
			memo[i]=memo[i-1]+(f[i]?1:0);
		}

		for(;;){
			int m=sc.nextInt();
			if(m==0){
				break;
			}
			int n=sc.nextInt();
			println(""+(memo[n]-memo[m-1]));
		}
	}

	void debug(Object... os){
		System.err.println(Arrays.deepToString(os));
	}

	void print(String s){
		System.out.print(s);
	}

	void println(String s){
		System.out.println(s);
	}

	public static void main(String[] args){
		// System.setOut(new PrintStream(new BufferedOutputStream(System.out)));
		new Main().run();
	}
}

Measured memory_bytes: 17000
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <stack>
#include <queue>
#include <functional>
#include <math.h>
#include <stdlib.h>
#include <map>
#include <deque>
#include <list>
#include <sys/timeb.h>
#include <fstream>
#include <set>

using namespace std;

#define repr(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define rep(i,n) repr(i,0,n)
#define reprrev(i,a,b) for(int i=(int)(b)-1;i>=(int)(a);i--)
#define reprev(i,n) reprrev(i,0,n)
#define repi(itr,ds) for(auto itr=ds.begin();itr!=ds.end();itr++)
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
#define mp make_pair
#define mt make_tuple
#define INF 1050000000
#define INFL 1100000000000000000LL
#define EPS (1e-10)
#define MOD 1000000007
#define PI 3.1415926536
#define RMAX 4294967295

typedef long long ll;
typedef pair<int, int> Pi;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<bool> vb;
typedef vector<char> vc;
typedef vector<string> vs;
typedef vector<double> vd;
typedef vector<Pi> vPi;
typedef vector<vector<int> > vvi;
typedef vector<vector<bool> > vvb;
typedef vector<vector<ll> > vvll;
typedef vector<vector<char> > vvc;
typedef vector<vector<string> > vvs;
typedef vector<vector<double> > vvd;
typedef vector<vector<Pi> > vvPi;
typedef priority_queue<int, vector<int>, greater<int> > pqli;
typedef priority_queue<ll, vector<ll>, greater<ll> > pqlll;
typedef priority_queue<Pi, vector<Pi>, greater<Pi> > pqlP;
struct Edge {
	int from, to, cost;
	bool operator<(Edge e) {
		return cost < e.cost;
	}
};
typedef vector<Edge> Edges;
typedef vector<Edges> Graph;
template <class T>
using vec = vector<T>;
template<class T>
using pql = priority_queue<T, vector<T>, greater<T>>;
string debug_show(Pi a) {
	return "(" + to_string(a.first) + "," + to_string(a.second) + ")";
}

template<class T>
struct augEdge {
	T from, to;
	int cost;
	bool operator<(augEdge e) { return cost < e.cost; }
	bool operator>(augEdge e) { return cost > e.cost; }
};
template<class T>
using augGraph = vector<augEdge<T>>;


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

	int n, k;
	cin >> n >> k;
	vi a(n);
	
	if (n == k) {
		cout << 1 << endl;
		return 0;
	}

	n--;

	int ans = 0;
	while (n > 0) {
		n -= (k - 1);
		ans++;
	}

	cout << ans << endl;

	return 0;
}



Measured memory_bytes: 640
#include<iostream>
#include<cmath>
using namespace std;
 
int main(){
   
  int n, m, st[110], sh[110], sumt, sumh;
 
  while(cin>>n>>m, n){
    sumt=0;
    for(int i=0;i<n;i++){
      cin>>st[i];
      sumt+=st[i];
    }
    sumh=0;
    for(int i=0;i<m;i++){
      cin>>sh[i];
      sumh+=sh[i];
    }
    bool f=true;
    for(int i=0;i<n;i++){
      for(int j=0;j<m;j++){
	if(sumt-st[i]+sh[j]==sumh-sh[j]+st[i]){
	  cout<<st[i]<<" "<<sh[j]<<endl;
	  f=false;
	  break;
	}
      }
      if(!f) break;
    }
    if(f) cout<<-1<<endl; 
  }
   
  return 0;
}

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

#define fi first
#define se second
#define mp make_pair
#define sz(v) (int) v.size()
#define all(v) v.begin(), v.end()

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair<int, int> pii;

mt19937 rnd(chrono::steady_clock::now().time_since_epoch().count());

signed main() {
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	int n;
	cin >> n;
	while (n) {
		if (n % 10 == 7) return cout << "Yes\n", 0;
		n /= 10;
	}
	cout << "No\n";
	return 0;
}

Measured memory_bytes: 3652
N, P = map(int, input().split())
n = P
fs = []
f = 2
while n > 1:
  if f*f > n:
    fs.append(n)
    n = 1
  elif n%f == 0:
    fs.append(f)
    n = n//f
  else:
    f += 1
#print(fs)
nfs = {}
for f in fs:
  if f not in nfs: nfs[f] = 0
  nfs[f] += 1
r = 1
for f in nfs:
  n = nfs[f]
  r *= f**(n//N)
print(r)


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

const int INF = 1e9;

vector<int> graph[100005];

vector<int> bfs(int n, int s){
    vector<int> mini(n + 1, INF);
    mini[s] = 0;
    queue<pair<int,int>> que;
    que.push(make_pair(s, 0));

    while(!que.empty()){
        pair<int, int> curr = que.front(); que.pop();
        for(auto to : graph[curr.first]){
            if(mini[to] < curr.second + 1)continue;
            mini[to] = curr.second + 1;
            que.push(make_pair(to, curr.second + 1));
        }
    }

    return mini;
}

int main(){
    int n;
    cin >> n;
    for(int i=0;i<n-1;++i){
        int a, b;
        cin >> a >> b;
        graph[a].push_back(b);
        graph[b].push_back(a);
    }

    vector<int> fennec = bfs(n, 1), snuke = bfs(n, n);

    int fs = 0, ss = 0;
    for(int i=1;i<=n;++i){
        if(fennec[i] <= snuke[i])fs++;
        else ss++;
    }

    if(fs > ss)cout << "Fennec" << endl;
    else cout << "Snuke" << endl;

    return 0;
}


Measured memory_bytes: 6724
import java.io.IOException;
import java.util.Arrays;
import java.util.Collections;
import java.util.LinkedList;
import java.util.List;
import java.util.PriorityQueue;
import java.util.Scanner;

public class Main {

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

		final int n = sc.nextInt();
		
		PriorityQueue<Long> queue = new PriorityQueue<Long>(n, Collections.reverseOrder());
		
		for(int i = 0; i < n; i++){
			queue.add(sc.nextLong());
		}
		
		int loss = 0;
		int count = 0;
		long sum = 1;
		while(!queue.isEmpty()){
			final long hp = queue.poll();
			sum += Math.max(0, hp - loss);
			count++;
			
			if(count >= 4){
				loss++;
				count = 0;
			}
		}
		
		System.out.println(sum);
		
	}

}

Measured memory_bytes: 20896
package main

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

var sc = bufio.NewScanner(os.Stdin)

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

func nextFloat64() float64 {
	sc.Scan()
	i, e := strconv.ParseFloat(sc.Text(), 64)
	if e != nil {
		panic(e)
	}
	return i
}

func nextString() string {
	sc.Scan()
	return sc.Text()
}

func max(x, y int) int {
	if x > y {
		return x
	}
	return y
}

func main() {
	sc.Split(bufio.ScanWords)
	sc.Buffer(nil, 10000000000)

	a, b, c, d := nextInt(), nextInt(), nextInt(), nextInt()

	ac := a * c
	ad := a * d
	bc := b * c
	bd := b * d

	fmt.Println(max(max(max(ac, ad), bc), bd))
}


Measured memory_bytes: 1772
// AOJ Volume 0 Problem 0075

#include <stdio.h>

int main(void)
{
    int student;
	float weight;
	float height;
	float bmi;
	
    while (scanf("%d,%f,%f", &student, &weight, &height) != EOF){
		bmi = weight / (height * height);
		if (bmi >= 25.0){
			printf("%d\n", student);
		}
    }
	
	return (0);
}

Measured memory_bytes: 0
def get_i() #空白区切の入力を数値(整数)の配列で返す
  return gets.chomp.split(" ").map(&:to_i)
end
def get_f() #空白区切の入力を数値(実数)の配列で返す
  return gets.chomp.split(" ").map(&:to_f)
end
def get() #空白区切の入力を文字列の配列で返す
  return gets.chomp.split(" ")
end
def get_nsp() #入力されたものを一文字ずつに区切った文字列の配列で返す
  return gets.chomp.split("")
end
def yn_judge(bool,y="Yes",n="No") #boolに真偽を投げることで、trueならy、falseならnの値を出力する
  return bool ? y : n 
end
def array(size1,init=nil,size2=-1) #size2に二次元配列時の最初の要素数、size1に次の配列の大きさ、initに初期値を投げることでその配列を返す
  if size2==-1
    return Array.new(size1){init}
  else
    return Array.new(size2){Array.new(size1){init}}
  end
end
class Pos
    attr_accessor:x,:y
end

Direct=[[1,0],[1,1],[0,1],[-1,1],[-1,0],[-1,-1],[0,-1],[1,-1]]
loop do
w,h=get_i
break if w.zero? and h.zero?
c=array(h)
h.times do|i|
    c[i]=get_i
end
$seen=array(w,false,h)
def bfs(map,pos,w,h)
  queue=[]
  queue.push(pos)
  $seen[pos.y][pos.x]=true
  until queue==[]
    curr_p=queue.shift
    Direct.each do|x,y|
        next_p=Pos.new
        next_p.x,next_p.y=curr_p.x+x,curr_p.y+y
        next unless next_p.x.between?(0,w-1) and next_p.y.between?(0,h-1) and map[next_p.y][next_p.x]==1 and not $seen[next_p.y][next_p.x]
        $seen[next_p.y][next_p.x]=true
        queue.push(next_p)
    end
  end
end
pos=Pos.new
ans=0
h.times do|i|
    w.times do|j|
      pos.x,pos.y=j,i
      if c[i][j]==1 and not $seen[i][j]
        ans+=1
        bfs(c,pos,w,h)    
      end
    end
end
puts ans
end


Measured memory_bytes: 6920
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstring>
#include<map>
using namespace std;
int n,m,j,k,maxx;
map<string,int> s,t,p;
string a,x[101],y[101];
int main()
{
	cin>>n;
	for(int i=1;i<=n;i++)
	{
		cin>>a;
		if(s[a]==0)x[++j]=a;s[a]+=1;
	}
	cin>>m;
	for(int i=1;i<=m;i++)
	{
		cin>>a;
		if(t[a]==0)y[++k]=a;t[a]++;
	}
	
	for(int i=1;i<=j;i++)
	{
		int f=0;
		//cout<<s[x[i]]<<endl;
	   for(int c=1;c<=k;c++)
	   
	   if(x[i]==y[c]){f=1;
	   break;
	   }
	   if(f==1)maxx=max(maxx,s[x[i]]-t[x[i]]);
	   else maxx=max(maxx,s[x[i]]);
	   //cout<<maxx<<endl;
	}
	cout<<maxx;	
	return 0;
}

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

using namespace std;

typedef long long ll;
typedef pair<ll, ll> P;

#define each(i,a) for (auto&& i : a)
#define FOR(i,a,b) for (ll i=(a),__last_##i=(b);i<__last_##i;i++)
#define RFOR(i,a,b) for (ll i=(b)-1,__last_##i=(a);i>=__last_##i;i--)
#define REP(i,n) FOR(i,0,n)
#define RREP(i,n) RFOR(i,0,n)
#define __GET_MACRO3(_1, _2, _3, NAME, ...) NAME
#define rep(...) __GET_MACRO3(__VA_ARGS__, FOR, REP)(__VA_ARGS__)
#define rrep(...) __GET_MACRO3(__VA_ARGS__, RFOR, RREP)(__VA_ARGS__)
#define pb push_back
#define all(a) (a).begin(),(a).end()
#define chmin(x,v) x = min(x, v)
#define chmax(x,v) x = max(x, v)

const ll linf = 1e18;
const int inf = 1e9;
const double eps = 1e-12;
const double pi = acos(-1);

template<typename T>
istream& operator>>(istream& is, vector<T>& vec) {
    each(x,vec) is >> x;
    return is;
}
template<typename T>
ostream& operator<<(ostream& os, const vector<T>& vec) {
    rep(i,vec.size()) {
        if (i) os << " ";
        os << vec[i];
    }
    return os;
}
template<typename T>
ostream& operator<<(ostream& os, const vector< vector<T> >& vec) {
    rep(i,vec.size()) {
        if (i) os << endl;
        os << vec[i];
    }
    return os;
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    ll n; cin >> n;
    vector<bool> need(n);
    vector<ll> h(n);
    rep(i, n) {
        string s; cin >> s >> h[i];
        need[i] = s == "y";
    }
    priority_queue<P, vector<P>, greater<P>> Q;
    rep(i, n) {
        if (need[i]) {
            Q.push({h[i], i});
        }
    }
    ll ans = 0;
    vector<bool> used(n, false);
    while ( !Q.empty() ) {
        P p = Q.top(); Q.pop();
        ll h0, id; tie(h0, id) = p;
        if (used[id]) continue;
        // cout << id << " :" << endl;
        rep(i, id, n) {
            if (need[i]) {
                used[i] = true;
            }
            else if (h[i] >= h[id]) {
                // cout << i << " " << id << " " << h[i] << " " << h[id] << endl;
                break;
            }
        }
        rrep(i, 0, id) {
            if (need[i]) {
                used[i] = true;
            }
            else if (h[i] >= h[id]) {
                break;
            }
        }
        ++ans;
    }
    cout << ans << endl;
}

Measured memory_bytes: 3256
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        long N = sc.nextLong();
        long K = sc.nextLong();

        long ans1 = N % K;
        long ans2 = K - ans1;

        System.out.println(Math.min(ans1, ans2));
    }
}


Measured memory_bytes: 35708
#include<bits/stdc++.h>
#define llt long long int
#define pb push_back
#define mp make_pair
#define speed ios::sync_with_stdio(false); cin.tie(0); cout.tie(0)
using namespace std;
double fun(double s) 
{ 
    double length = s / 3.0; 
    s -= length; 
    double breadth = s / 2.0; 
    double height = s - breadth; 
    return length * breadth * height; 
} 
  
int main()
{
	speed;
	int l;
	cin >> l;
	printf("%0.6lf",fun(l));
	return 0;
}


Measured memory_bytes: 256
const int isDebugMode = 1;
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<long long, long long> P;
struct edge{long long to,cost;};
const int inf = 1 << 27;
const long long INF = 1LL << 60;
const int COMBMAX = 1001001;
const long long MOD = 1000000007;
const long long dy[] = {-1, 0, 0, 1};
const long long dx[] = {0, -1, 1, 0};
string abc = "abcdefghijklmnopqrstuvwxyz";
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define eachdo(v, e) for (const auto &e : (v))
#define all(v) (v).begin(), (v).end()
#define lower_index(v, e) (long long)distance((v).begin(), lower_bound((v).begin(), (v).end(), e))
#define upper_index(v, e) (long long)distance((v).begin(), upper_bound((v).begin(), (v).end(), e))
long long mpow(long long a, long long n, long long mod = MOD){long long res = 1; while(n > 0){if(n & 1)res = res * a % mod; a = a * a % mod; n >>= 1;} return res;}
void pt(){cout << endl; return;}
template<class Head> void pt(Head&& head){cout << head; pt(); return;}
template<class Head, class... Tail> void pt(Head&& head, Tail&&... tail){cout << head << " "; pt(forward<Tail>(tail)...);}
void dpt(){if(!isDebugMode) return; cout << endl; return;}
template<class Head> void dpt(Head&& head){if(!isDebugMode) return; cout << head; pt(); return;}
template<class Head, class... Tail> void dpt(Head&& head, Tail&&... tail){if(!isDebugMode) return; cout << head << " "; pt(forward<Tail>(tail)...);}
template<class T> void debug(T v){if(!isDebugMode) return; rep(i, v.size()) cout << v[i] << " " ; cout << endl;}
template<class T> void debug2(T v){if(!isDebugMode) return; rep(i, v.size()){rep(j, v[i].size()) cout << v[i][j] << " " ; cout << endl;}}
template<class T1, class T2> inline bool chmin(T1 &a, T2 b){if(a > b){a = b; return true;} return false;}
template<class T1, class T2> inline bool chmax(T1 &a, T2 b){if(a < b){a = b; return true;} return false;}
template<class T1, class T2> long long gcd(T1 a, T2 b){return a % b ? gcd(b , a % b) : b;}
template<class T1, class T2> void reduce(T1 &a, T2 &b){ll g = gcd(a, b); a /= g; b /= g; return;}
bool valid(long long H, long long W, long long h, long long w) { return 0 <= h && h < H && 0 <= w && w < W; }

int main(){
    int N, K; cin >> N >> K;
    vector<int> a(N + 1), cum(N + 1, 0);
    rep(i, N) cin >> a[i];
    rep(_, min(K, 100)){
        cum.assign(N + 1, 0);
        rep(i, N){
            cum[max(0, i - a[i])] += 1;
            cum[min(N, i + a[i] + 1)] -= 1;
        }
        rep(i, N) cum[i + 1] += cum[i];
        a = cum;
    }
    rep(i, N) pt(a[i]);

    return 0;
}

Measured memory_bytes: 4832
#define DEBUG 1
#include <bits/stdc++.h>
using namespace std;
typedef          char      s8;
typedef unsigned char      u8;
typedef          short    s16;
typedef unsigned short    u16;
typedef          int      s32;
typedef unsigned int      u32;
typedef          long int s64;
typedef unsigned long int u64;
typedef float             f32;
typedef double            f64;
#define rep(_i, _n) for (int _i = 0; _i < (int)(_n); _i++)
#if DEBUG
#define PHERE()			{ cerr << "L" << setw(3) << __LINE__ << ": PHERE" << clock() << endl; }
#define PVAL( _var )	{ cerr << "L" << setw(3) << __LINE__ << ":" << #_var "=" << (_var) << endl; }
#else
#define PHERE()
#define PVAL( _var )
#endif


int H,W,K;

bool isMatch( int table[6][6] )
{
	int sum = 0;
	rep( i, H ) {
		rep( j, W ) {
			if( table[i][j] ) {
				++sum;
			}
		}
	}
	return sum == K;
}

int calcSum( int table[6][6], int cur )
{
	if( cur >= H+W ) {
		return 0;
	}
	if( cur < 0 ) {
		int sum0 = 0;
		if( isMatch( table ) ) {
			++sum0;
		}
		return sum0+calcSum( table, 0 );
	}
	int sum1 = calcSum( table, cur+1 );
	
	int table2[6][6];
	memcpy( table2, table, sizeof(table2) );
	if( cur < H ) {
		rep( j, W ) {
			table2[cur][j] = 0;
		}
	}
	else {
		rep( i, H ) {
			table2[i][cur-H] = 0;
		}
	}
	int sum3 = 0;
	if( isMatch( table2 ) ) {
		++sum3;
	}
	int sum2 = calcSum( table2, cur+1 );
	
	return sum1+sum2+sum3;
}

int main()
{
	//////// 入力 ////////
	cin >> H>>W>>K;
	
	int table[6][6] = {0};
	rep( i, H ) {
		rep( j, W ) {
			char ch;
			cin >> ch;
			if( ch == '#' ) {
				table[i][j] = 1;
			}
		}
	}
	/////////////////////
	
#if 0
	int Hsum[H] = {0};
	int Wsum[W] = {0};
	rep( i, H ) {
		int sum = 0;
		rep( j, W ) {
			if( table[i][j] == 1 ) {
				++sum;
			}
		}
		Hsum[i] = sum;
	}
#endif
	
	int out = calcSum( table, -1 );
	
	//////// 出力 ///////
	cout << out;
	
	/////////////////////
	
	return 0;
}
#if 0
#endif


Measured memory_bytes: 3628
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<ll,ll> P;
typedef pair<int,int> Pi;
#define rep(i,n) for(ll i=0;i<n;i++)
#define FOR(i,a,b) for(ll i=a;i<b;i++)
#define fi first
#define se second
#define endl "\n"

template<typename T> inline bool chmax(T &a, T b){if(a<b){a=b;return true;}return false;}
template<typename T> inline bool chmin(T &a, T b){if(a>b){a=b;return true;}return false;}
template<typename T> ostream& operator<<(ostream& s,const complex<T>& d) {return s<<"("<<d.real()<<", "<<d.imag()<< ")";}
template<typename T1, typename T2> ostream& operator<<(ostream& s,const pair<T1,T2>& d) {return s<<"("<<d.first<<", "<<d.second<<")";}
template<typename T> ostream& operator<<(ostream& s, const vector<T>& d){int len=d.size();rep(i,len){s<<d[i];if(i<len-1) s<<" ";}return s;}
template<typename T> ostream& operator<<(ostream& s,const vector<vector<T>>& d){int len=d.size();rep(i,len){s<<d[i]<<endl;}return s;}
template<typename T> ostream& operator<<(ostream& s,const set<T>& v){s<<"{ ";for(auto itr=v.begin();itr!=v.end();++itr) {if (itr!=v.begin()) {s<< ", ";}s<<(*itr);}s<<" }";return s;}
template<typename T> ostream& operator<<(ostream& s,const multiset<T>& v){s<<"{ ";for(auto itr=v.begin();itr!=v.end();++itr) {if (itr!=v.begin()) {s<< ", ";}s<<(*itr);}s<<" }";return s;}
template<typename T1, typename T2> ostream& operator<<(ostream& s,const map<T1,T2>& m){s<<"{"<<endl;for(auto itr=m.begin();itr!=m.end();++itr){s<<" "<<(*itr).first<<" : "<<(*itr).second<<endl;}s<<"}"<<endl;return s;}

const ll mod=1'000'000'007;
const ll inf=1'000'000'000'000'000'00;
const int INF=1'000'000'000;
const double EPS=1e-10;
const double PI=acos(-1);

int main(){
    cin.tie(0);ios::sync_with_stdio(false);
    int k;
    cin>>k;
    vector<vector<Pi>> g(k);
    rep(i,k){
        g[i].push_back({(i+1)%k,1});
        g[i].push_back({(10*i)%k,0});
    }
    deque<int> que;
    vector<int> dist(k,INF);
    dist[1]=0;
    que.push_back(1);
    while(!que.empty()){
        auto v=que.front();
        que.pop_front();
        for(auto [to,cost]:g[v]){
            if(cost){
                if(chmin(dist[to],dist[v]+1)){
                    que.push_back(to);
                }
            }else{
                if(chmin(dist[to],dist[v])){
                    que.push_front(to);
                }
            }
        }
    }
    cout<<dist[0]+1<<endl;
}

Measured memory_bytes: 9312
N,A,B=map(int,input().split())

X=int(N/(A+B))
ans1=int(A*X)

Y=int(N%(A+B))
ans2=0
if Y>A:
  ans2=A
elif Y==A:
  ans2=A
elif Y<A:
  ans2=Y

print(int(ans1+ans2))

Measured memory_bytes: 3064
import heapq
n,m=map(int,input().split())
a=list(map(lambda x:int(x)*(-1),input().split()))
heapq.heapify(a)
for _ in range(m):
  now=heapq.heappop(a)
  heapq.heappush(a,(-now//2)*(-1))
print(-sum(a))  


Measured memory_bytes: 20376
#include<stdio.h>
#include<string.h>
char a[101];
int b;

int main(void)
{
  int i,len;
  scanf("%s",a);
  scanf("%d",&b);
  len=strlen(a);
  for(i=0;i<len;i++)
  {
    if(i+1==b)
    {
      printf("%c\n",a[i]);
      break;
    }
    else if('1'!=a[i])
    {
      printf("%c\n",a[i]);
      break;
    }
  }
  return 0;
}

Measured memory_bytes: 128
k = int(input())
a = [1, 9, 30, 76, 141, 267, 400, 624, 885, 1249, 1590, 2208, 2689, 3411, 4248, 5248, 6081, 7485, 8530, 10248, 11889, 13687, 15228, 17988, 20053, 22569, 25242, 28588, 31053, 35463, 38284, 42540, 46581, 50893, 55362, 61824, 65857, 71247, 76884, 84388, 89349, 97881, 103342, 111528, 120141, 128047, 134580, 146316, 154177, 164817, 174438, 185836, 194157, 207927, 218812, 233268, 245277, 257857, 268182, 288216, 299257, 313635, 330204, 347836, 362973, 383709, 397042, 416448, 434025, 456967, 471948, 499740, 515581, 536073, 559758, 583960, 604833, 633651, 652216, 683712, 709065, 734233, 754734, 793188, 818917, 846603, 874512, 909496, 933081, 977145, 1006126, 1041504, 1073385, 1106467, 1138536, 1187112, 1215145, 1255101, 1295142, 1342852, 1373253, 1422195, 1453816, 1502376, 1553361, 1595437, 1629570, 1691292, 1726717, 1782111, 1827492, 1887772, 1925853, 1986837, 2033674, 2089776, 2145333, 2197483, 2246640, 2332104, 2379085, 2434833, 2490534, 2554600, 2609625, 2693919, 2742052, 2813988, 2875245, 2952085, 3003306, 3096024, 3157249, 3224511, 3306240, 3388576, 3444609, 3533637, 3591322, 3693924, 3767085, 3842623, 3912324, 4027884, 4102093, 4181949, 4270422, 4361548, 4427853, 4548003, 4616104, 4718640, 4812789, 4918561, 5003286, 5131848, 5205481, 5299011, 5392008, 5521384, 5610705, 5739009, 5818390, 5930196, 6052893, 6156139, 6239472, 6402720, 6493681, 6623853, 6741078, 6864016, 6953457, 7094451, 7215016, 7359936, 7475145, 7593865, 7689630, 7886244, 7984165, 8130747, 8253888, 8403448, 8523897, 8684853, 8802826, 8949612, 9105537, 9267595, 9376656, 9574704, 9686065, 9827097, 9997134, 10174780, 10290813, 10493367, 10611772, 10813692]

s = a[k-1]

print(s)


Measured memory_bytes: 9368
#include<queue>
#include<stack>
#include<math.h>
#include<cmath>
#include<bitset>
#include<stdio.h>
#include<string>
#include<map>
#include<algorithm>
#include<vector>
#include<iostream>
#include<utility>
#include<functional>
#include<deque>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
const int MAX = 100010;
const int MOD = 1000000007;
long long fac[MAX], finv[MAX], inv[MAX];
// テーブルを作る前処理
void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}
// 二項係数計算
long long COM(int n, int k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}
int main(){
  int i,n,k,a,b;
  cin >> n >> k;
  n=n-k;
  COMinit();
  for(i=0;i<k;i++){
    a=n-i;
    b=2+i;
    cout << COM(k-1,i)*COM(n+1,n-i)%MOD << endl;
  }
  return 0;
}

Measured memory_bytes: 2560
#include <cstdio>

const int mod = 1e9 + 7;
const int MAXN = 2005, MAXS = MAXN * MAXN;

template<typename _T>
void read( _T &x )
{
	x = 0;char s = getchar();int f = 1;
	while( s > '9' || s < '0' ){if( s == '-' ) f = -1; s = getchar();}
	while( s >= '0' && s <= '9' ){x = ( x << 3 ) + ( x << 1 ) + ( s - '0' ), s = getchar();}
	x *= f;
}

template<typename _T>
void write( _T x )
{
	if( x < 0 ){ putchar( '-' ); x = ( ~ x ) + 1; }
	if( 9 < x ){ write( x / 10 ); }
	putchar( x % 10 + '0' );
}

int f[MAXN][MAXN];
int fac[MAXS], ifac[MAXS];
int N, K;

int qkpow( int, int );
int inv( const int a ) { return qkpow( a, mod - 2 ); }
void sub( int &x, const int v ) { x = ( x < v ? x - v + mod : x - v ); }
void add( int &x, const int v ) { x = ( x + v >= mod ? x + v - mod : x + v ); }

int qkpow( int base, int indx )
{
	int ret = 1;
	while( indx )
	{
		if( indx & 1 ) ret = 1ll * ret * base % mod;
		base = 1ll * base * base % mod, indx >>= 1;
	}
	return ret;
}

void init( const int siz )
{
	fac[0] = ifac[0] = 1;
	for( int i = 1 ; i <= siz ; i ++ ) fac[i] = 1ll * fac[i - 1] * i % mod;
	ifac[siz] = inv( fac[siz] );
	for( int i = siz - 1 ; ~ i ; i -- ) ifac[i] = 1ll * ifac[i + 1] * ( i + 1 ) % mod;
}

int C( const int n, const int m ) { return 1ll * fac[n] * ifac[m] % mod * ifac[n - m] % mod; }

int main()
{
	read( N ), read( K );
	if( K == 1 ) { puts( "1" ); return 0; }
	init( N * K );
	for( int i = 0 ; i <= N ; i ++ ) f[i][0] = 1;
	for( int i = 1 ; i <= N ; i ++ )
		for( int j = 1 ; j <= i ; j ++ )
		{
			f[i][j] = f[i - 1][j];
			int t = N * K - i - ( K - 1 ) * ( j - 1 ) - 1;
			add( f[i][j], 1ll * f[i][j - 1] * ( N - j + 1 ) % mod * C( t, K - 2 ) % mod );
		}
	write( f[N][N] ), putchar( '\n' );
	return 0;
}

Measured memory_bytes: 46532
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main {
    public static void main (String[] args ) throws IOException {
        BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
        StringBuilder builder = new StringBuilder();
        
        while(true) {
            String line = reader.readLine();
            String[] column = line.split(" ");
            int y = Integer.parseInt(column[0]);
            int x = Integer.parseInt(column[1]);
            
            if ( y == 0 && x == 0 ) {
                break;
            }
            builder.append(StringUtilsRepeat(x,y));
        }
        System.out.print(builder);
    }
    public static StringBuilder StringUtilsRepeat(int x,int y) {
        StringBuilder line = new StringBuilder();
        String str = "#";
        String strin = ".";
        for ( int j = 1; j <= y; j++ ){
             for ( int i = 1; i <= x ; i++ ) {
                 if (j == 1 || j == y)
                     line.append(str);
                 else if (i == 1 || i == x)
                     line.append(str);
                 else
                     line.append(strin);
             }
             line.append("\n");
        }
        line.append("\n");
        return line;
    }
}

Measured memory_bytes: 25384
#include <bits/stdc++.h>
using namespace std;
 
int gcd(long int a,long int b)
{
	if (a%b==0)
	{
		return(b);
    }
	else
	{
		return(gcd(b,a%b));
    }
}

int main(){
  long int a,b,c,d,e;
  cin>>a>>b>>c>>d;
  a--;
  e=(c*d)/gcd(c,d);
  cout<<b-a+(a/c+a/d-a/e-b/c-b/d+b/e);
}
  

Measured memory_bytes: 256
//34
#include<iostream>
#include<vector>

using namespace std;

int main(){
  for(int n;cin>>n,n;){
    vector<int> vo(n+1);
    for(int i=0;i<n;i++){
      cin>>vo[i];
    }
    vo[n]=-1;
    int ans=1<<30;
    for(int i=0;i<n;i++){
      for(int j=0;j<3;j++){
	vector<int> v=vo;
	v[i]=j;
	for(;;){
	  bool va=false;
	  int c=0;
	  int p=-1;
	  for(int i=0;i<v.size();i++){
	    if(v[i]!=p){
	      if(c>=4){
		v.erase(v.begin()+i-c,v.begin()+i);
		va=true;
		break;
	      }else{
		p=v[i];
		c=1;
	      }
	    }else{
	      c++;
	    }
	  }
	  if(!va)break;
	}
	if(ans>v.size()){
	  ans=v.size();
	}
      }
    }
    cout<<ans-1<<endl;
  }
  return 0;
}

Measured memory_bytes: 1296
//abc151_d.cpp
//Sun Jan 12 20:59:40 2020

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

string s[20];
int dx[4] = {-1,0,1,0}; 
int dy[4] = {0,1,0,-1};
int visited[20][20];
int h,w;

int solve(int a, int b, int c, int d){
	queue<P> q;
	queue<int> qscore;
	q.push(P(a,b));
	visited[a][b]++;
	qscore.push(0);
	int ans = 0;
	while (q.size()){
		P temp = q.front();q.pop();
		int score = qscore.front();qscore.pop();
		for (int i=0;i<4;i++){
			if (temp.first+dy[i]>=0 &&
				temp.first+dy[i]<=h-1 &&
				temp.second+dx[i]>=0 &&
				temp.second+dx[i]<=w-1 &&
				s[temp.first+dy[i]][temp.second+dx[i]]=='.' &&
				visited[temp.first+dy[i]][temp.second+dx[i]]==0){
				q.push(P(temp.first+dy[i],temp.second+dx[i]));
				qscore.push(score+1);
				visited[temp.first+dy[i]][temp.second+dx[i]]++;
				if (temp.first+dy[i]==c &&
					temp.second+dx[i]==d){
					ans = score+1;
					break;
				}
			}
		}
		if (ans > 0){
			break;
		}
	}
	return ans;
}

int main(){
	cin >> h >> w;

	for (int i=0;i<h;i++){
		cin >> s[i];
	}

	vector<P> positions;
	for (int i=0;i<h;i++){
		for (int j=0;j<w;j++){
			if (s[i][j]=='.'){
				positions.push_back(P(i,j));
			}
		}
	}

	int ans = 0;
	for (int i=0;i<positions.size()-1;i++){
		for (int j=0;j<positions.size();j++){
			P start = positions[i];
			P goal = positions[j];
			for (int k=0;k<20;k++){
				for (int l=0;l<20;l++){
					visited[k][l] = 0;
				}
			}
			int temp = solve(start.first,start.second,goal.first,goal.second);
			ans = max(ans,temp);
		}
	}

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

Measured memory_bytes: 256
using System;
using System.IO;
using System.Linq;
using System.Text;
using System.Collections.Generic;
using System.Diagnostics;
using Enu = System.Linq.Enumerable;

public class Program
{
    public void Solve()
    {
        int D = Reader.Int();
        int Dlen = (D + "").Length;
        long ans = 0;

        for (int len = Dlen; len <= Dlen * 2; len++)
            for (int mask = 0; mask < (1 << len / 2); mask++)
            {
                long count = 1;
                long rem = D;
                long p10 = (long)Math.Pow(10, len - 1);
                for (int i = 0; i < len / 2; i++, rem /= 10, p10 /= 100)
                {
                    long d = (rem % 10 + 10) % 10 - (mask >> i & 1) * 10;
                    if (d == -10) { rem = -1; break; }
                    count *= (10 - Math.Abs(d)) - (i == 0 ? 1 : 0);
                    rem -= p10 * -d + d;
                }
                if (len % 2 == 1) count *= (len == 1) ? 9 : 10;
                if (rem == 0) ans += count;
            }

        Console.WriteLine(ans);
    }
}


class Entry { static void Main() { new Program().Solve(); } }
class Reader
{
    static TextReader reader = Console.In;
    static readonly char[] separator = { ' ' };
    static readonly StringSplitOptions op = StringSplitOptions.RemoveEmptyEntries;
    static string[] A = new string[0];
    static int i;
    static void Init() { A = new string[0]; }
    public static void Set(TextReader r) { reader = r; Init(); }
    public static void Set(string file) { reader = new StreamReader(file); Init(); }
    public static bool HasNext() { return CheckNext(); }
    public static string String() { return Next(); }
    public static int Int() { return int.Parse(Next()); }
    public static long Long() { return long.Parse(Next()); }
    public static double Double() { return double.Parse(Next()); }
    public static int[] IntLine() { return Array.ConvertAll(Split(Line()), int.Parse); }
    public static int[] IntArray(int N) { return Range(N, Int); }
    public static int[][] IntTable(int H) { return Range(H, IntLine); }
    public static string[] StringArray(int N) { return Range(N, Next); }
    public static string[][] StringTable(int N) { return Range(N, () => Split(Line())); }
    public static string Line() { return reader.ReadLine().Trim(); }
    public static T[] Range<T>(int N, Func<T> f) { var r = new T[N]; for (int i = 0; i < N; r[i++] = f()) ; return r; }
    static string[] Split(string s) { return s.Split(separator, op); }
    static string Next() { CheckNext(); return A[i++]; }
    static bool CheckNext()
    {
        if (i < A.Length) return true;
        string line = reader.ReadLine();
        if (line == null) return false;
        if (line == "") return CheckNext();
        A = Split(line);
        i = 0;
        return true;
    }
}

Measured memory_bytes: 13268
#include <iostream>
#include <bitset>
#include <map>
#include <vector>
#include <string>
#include <climits>
#include <algorithm>
using namespace std;

int main() {

    int N;
    cin >> N;
    map<string, int> m;
    
    for(int i = 0; i < N; i++){
        string S;
        cin >> S;
        m[S]++;
    }
    
    int ans = 0;
    for(auto A : m){
        ans++;
    }
    
    cout << ans << endl;
    
    
}



Measured memory_bytes: 18876
use std::cmp::*;
use std::io::*;

fn main() {
    let mut s: String = String::new();
    std::io::stdin().read_to_string(&mut s).ok();
    let mut itr = s.trim().split_whitespace();
    let n: usize = itr.next().unwrap().parse().unwrap();
    let k: i64 = itr.next().unwrap().parse().unwrap();
    let mut a: Vec<i64> = (0..n)
        .map(|_| itr.next().unwrap().parse().unwrap())
        .collect();
    let mut f: Vec<i64> = (0..n)
        .map(|_| itr.next().unwrap().parse().unwrap())
        .collect();
    a.sort();
    f.sort();
    f.reverse();
    let mut b = vec![0; n];
    for i in 0..n {
        b[i] = a[i] * f[i];
    }

    let c = |x: i64| {
        let mut diff = 0;
        for i in 0..n {
            let t = max(0, b[i] - x);
            diff += (t + f[i] - 1) / f[i];
        }
        diff <= k
    };
    let mut ng = -1;
    let mut ok = 1i64 << 60;
    while ok - ng > 1 {
        let mid = (ng + ok) / 2;
        if c(mid) {
            ok = mid;
        } else {
            ng = mid;
        }
    }
    println!("{}", ok);
}


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

template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }

using ll = long long;

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

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

int main() {
  ll N,A,B;
  cin>>N>>A>>B;
  vector<ll> X(N);
  for(ll i = 0LL; i < N; i++) cin>>X[i];
  vector<ll> d(N-1);
  for(ll i = 0LL; i < N-1LL; i++) d[i]=X[i+1]-X[i];
  ll ans = 0LL;
  for(ll i = 0LL; i < N-1LL; i++) {
    if(d[i]*A<=B) ans+=d[i]*A;
    else ans+=B;
  }
  cout<<ans<<endl;
}

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

int main(){
  int k,x,a,b;
  cin >> k >> x;
  if(x-k<-10000){
    a=-10000;
  }else{
    a=x-k+1;
  }
  if(x+k>10000){
    b=10000;
  }else{
    b=x+k-1;
  }
  for(int i=a;i<=b;i++){
    cout << i;
    cout << " ";
  }
  cout << endl;
}

Measured memory_bytes: 256
n,m=input().split()
n=int(n)
m=int(m)
sum,c=0,0
lt = list(map(int, input().split()))
for i in range(0,n):
    sum=sum+lt[i]
for i in range(0,n):
    if (sum/(4*m))<=lt[i]:
        c=c+1
if c>=m:
    print('Yes')
else:
    print('No')

Measured memory_bytes: 3064
#include <iostream>
#include <algorithm>
#include <vector>
#include <cstring>
using namespace std;

class dp{
public:
  int n;
  static const int limit=393;
  int s[limit+1], l[limit+1], p[limit+1];
  int d[limit+1][limit+1];
  bool can[limit+1][limit+1];

  dp(int n):n(n){}

  void init(){
    for(int i=0; i<=n; i++){
      for(int j=0; j<=limit; j++) {
        d[i][j] = 0;
        if(j==0) can[i][j] = true;
        else can[i][j] = false;
      }
    }
    for(int i=1; i<=n; i++){
      for(int j=0; j<=limit; j++){
        int temp=0;
        for(int k=s[i]; k<=l[i]; k++){
          if(can[i-1][j]){
            temp = max(temp, d[i-1][j]);
            can[i][j] = true;
          }
          if(j>=k) {
            if(can[i][j-k]){
              temp = max(temp, d[i][j-k]+p[i]);
              can[i][j] = true;
            }
          }
        }
        d[i][j] = temp;
      }
    }
  }

  vector<int> ans(vector<int> w){
    vector<int> ans;
    for(int i=0; i<w.size(); i++){
      if(!can[n][w[i]]){
        ans = vector<int>(1, -1);
        return ans;
      }
      ans.push_back(d[n][w[i]]);
    }
    return ans;
  }
};

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

  int s, l, p;
  for(int i=1; i<=n; i++){
    cin >> s >> l >> p;
    d.s[i] = s;
    d.l[i] = l;
    d.p[i] = p;
  }

  d.init();

  int m; cin >> m;
  vector<int> melodies;
  for(int i=0; i<m; i++){
    int w; cin >> w;
    melodies.push_back(w);
  }

  vector<int> ans = d.ans(melodies);
  for(int i=0; i<ans.size(); i++){
    cout << ans[i] << endl;
  }

  return 0;
}



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

#define rep(i, n) for (int i = 0; i < (n); i++)
using namespace std;
typedef long long ll;
const int mod = 1e9 + 7;

int main() {
  ll n, a, ans = 1;
  cin >> n;
  vector<ll> cnt(n + 1, 0);
  rep(i, n) {
    cin >> a;
    if (a == 0)
      ans *= 3 - cnt[a];
    else
      ans *= cnt[a - 1] - cnt[a];
    ans %= mod;
    cnt[a]++;
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 3976
#include<iostream>
#include<cstdio>
#include<cstring>
#include<string>
#include<vector>
#include<algorithm>
using namespace std;

int main(){
   int n,k;
   int i,l;
   int sum;
   int flag;
   int s[100];
   int b[100][100];
   
   for(;;){
      cin>>n>>k;
      if(n==0&&k==0) break;
      
      memset(s,0,sizeof(s));
      memset(b,0,sizeof(b));
      flag=0;
      
      for(i=0;i<k;i++) cin>>s[i];
      
      for(i=0;i<n;i++){
         for(l=0;l<k;l++){
            cin>>b[i][l];
         }
      }
      for(i=0;i<k;i++){
         sum=0;
         for(l=0;l<n;l++){
            sum+=b[l][i];
         }
         if(sum>s[i]){
            puts("No");
            flag++;
            break;
         }
      }
      if(flag==0) puts("Yes");
   }
   return 0;
}

Measured memory_bytes: 880
#include <stdio.h>
#include <stdlib.h>

struct node{
    int value;
    struct node *left,*right;
};

typedef struct node node;

node *build(){
    if(getchar()==')')return NULL; //skip (
    node *res = (node *)malloc(sizeof(node));
    if(res->left = build())getchar(); //skip )
    scanf("[%d](",&res->value);
    if(res->right = build())getchar(); //skip )
    return res;
}

node *unite(node *a, node *b){
    if(a==NULL || b==NULL)return NULL;
    node *res = (node *)malloc(sizeof(node));
    res->value = a->value+b->value;
    res->left = unite(a->left, b->left);
    res->right = unite(a->right, b->right);
    return res;
}

void output(node *n){
    if(n==NULL)return;
    printf("(");
    output(n->left);
    printf(")[%d](", n->value);
    output(n->right);
    printf(")");
}

int main(){
    node *a = build();
    getchar(); //skip \n
    node *b = build();
    getchar(); //skip \n
    output(unite(a,b));
    printf("\n");
    return 0;
}

Measured memory_bytes: 620