akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
using namespace std;

#define max(a,b) ((a) > (b) ? (a) : (b))

int N, W, v[101], w[101];
int dp[101][10001] = { 0 };

int main() {
	cin >> N >> W;
	for (int i = 1; i <= N; i++) {
		cin >> v[i] >> w[i];
	}
	for (int i = 1; i <= N; i++) {
		for (int j = 0; j <= W; j++) {
			if (j >= w[i]) {
				dp[i][j] = max(dp[i - 1][j], dp[i - 1][j - w[i]] + v[i]);
			}
			else {
				dp[i][j] = dp[i - 1][j];
			}
		}
	}
	cout << dp[N][W] << endl;

	return 0;
}

Measured memory_bytes: 7032
#include <iostream>
#include <vector>
#include <algorithm>
#include <queue>
using namespace std;
int dx[4] = {1, 0,-1, 0};
int dy[4] = {0, 1, 0,-1};
struct info{
	int lx, ly, rx, ry;
	info(int lx, int ly, int rx, int ry):
		lx(lx), ly(ly), rx(rx), ry(ry){}
};

int main(){
	while(1){
		int w,h;
		cin >> w >> h;
		if(w==0) break;
		
		vector<vector<char> > l(h+2, vector<char>(w+2, '#'));
		vector<vector<char> > r(h+2, vector<char>(w+2, '#'));
		vector<vector<bool> > used(h*w, vector<bool>(h*w, false));
		int lx,ly, rx,ry;
		for(int i=1; i<=h; i++){
			for(int j=1; j<=w; j++){
				cin >> l[i][j];
				if(l[i][j]=='L'){
					lx = j;
					ly = i;
				}
			}
			for(int j=1; j<=w; j++){
				cin >> r[i][j];
				if(r[i][j]=='R'){
					rx = j;
					ry = i;
				}
			}
		}
		
		queue<info> search;
		search.push(info(lx, ly, rx, ry));
		bool success = false;
		while(!search.empty()){
			int lx = search.front().lx;
			int ly = search.front().ly;
			int rx = search.front().rx;
			int ry = search.front().ry;
			search.pop();
			if(used[(ly-1)*w+(lx-1)][(ry-1)*w+(rx-1)]) continue;
			used[(ly-1)*w+(lx-1)][(ry-1)*w+(rx-1)] = true;
			if(l[ly][lx]=='%'){
				if(r[ry][rx]=='%'){
					success = true;
					break;
				}else{
					continue;
				}
			}else if(r[ry][rx]=='%'){
				continue;
			}
			
			for(int i=0; i<4; i++){
				int nlx = lx+dx[i], nly = ly+dy[i];
				int nrx, nry;
				if(i%2==0){
					nrx = rx+dx[(i+2)%4];
					nry = ry+dy[(i+2)%4];
				}else{
					nrx = rx+dx[i];
					nry = ry+dy[i];
				}
				int uc=0;
				if(l[nly][nlx]=='#'){
					nlx = lx;
					nly = ly;
					uc++;
				}
				if(r[nry][nrx]=='#'){
					nrx = rx;
					nry = ry;
					uc++;
				}
				if(uc==2) continue;
				search.push(info(nlx, nly, nrx, nry));
			}
		}
		
		if(success){
			cout << "Yes" << endl;
		}else{
			cout << "No" << endl;
		}
	}
	return 0;
}

Measured memory_bytes: 7180
#include<bits/stdc++.h>
#include<unordered_map>
using namespace std;
#define ll long long
#define all(x) (x).begin(),(x).end()
#define rep(i, n) for(ll i = 0; i < n; i++)
const ll INF = 100100100100;
const ll MOD = 1000000007;


ll combination(ll n, ll r){
    if(n < r) return 0;
    if(r == 0||r == n) return 1;
    else if(r == 1) return n;
    return (combination(n - 1, r - 1) + combination(n - 1, r));
}

bool checkKaibun(string str){
    string checkStr = str;
    reverse(checkStr.begin(), checkStr.end());
    if(str == checkStr) return true;
    else return false;
}

int keta(ll num){
    int digits = 0;
    while(num > 0){
        num /= 10;
        digits++;
    }
    return digits;
}


ll mpow(ll x, ll n){//繰り返し二乗法 計算量O(logN)
    ll ans = 1;
    while(n != 0){
        if(n&1) ans = ans * x % MOD;
        x = x * x % MOD;
        n  = n >> 1;
    }
    return ans;
}

int gcd(int a, int b){
    if(a % b == 0) return b;
    else return (gcd(b, a%b));
}



int main(){
    int A, B, C;
    cin >> A >> B >> C;
    if(B + C - A < 0)cout << 0 << endl;
    else cout << B + C - A << endl;
}

Measured memory_bytes: 256
package main

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

var sc = bufio.NewScanner(os.Stdin)

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

func main() {
	mn := 1000
	ans := 0
	N, _ := strconv.Atoi(nextLine())
	for i := 1; i <= 9; i++ {
		d := i * 111 - N
		if d >= 0 {
			if d <= mn {
				mn = d
				ans = i * 111
			}
		}
	}
	fmt.Println(ans)
}

Measured memory_bytes: 640
#include<stdio.h>
#define MAX 50
int f(int);
int F[MAX],n;
int main(){
  int i;
  scanf("%d",&n);
  for(i=0; i<MAX; i++) F[i] = -1;
  printf("%d\n",f(n));
  return 0;
}
int f(int n){
  if(n == 1 || n == 0) return F[n] = 1;
  if(F[n] != -1) return F[n];
  return F[n] = f(n - 2) + f(n - 1);
}

Measured memory_bytes: 596
#!/bin/ruby
until (n=gets.to_i)==0
  c=0
  b=gets.split.map(&:to_i)
  while c<=10000
    f=false
    b.each_with_index do |e,x|
      f|=e!=x+1
    end
    break if !f
    c+=1
    b=b.map{|e|e-=1}
    b<< b.size
    b=b.select{|e|e!=0}
  end
  puts (c<=10000)?c: -1
end

Measured memory_bytes: 11764
#include <bits/stdc++.h>
#define meow(args...) fprintf(stderr, args)
int main() {
	int k;
	assert(scanf("%d", &k)==1);
	if(k==1) {
		puts("1\n1");
		return 0;
	}
	int n=(k+3)/4*2;
	printf("%d\n", n);
	for(int i=0; i<n; ++i) {
		for(int j=0; j<n; ++j) {
			int t=(i+j)%n+1;
			printf("%d ", (i%2==1&&t+n<=k)?t+n:t);
		}
		puts("");
	}
	return 0;
}


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

ll n; int m,cnt,a[4][7],b[35],fa[35]; bool bo[100005];
struct node{ int p[2][7]; ll sz; };
int getfa(int x){ return (x==fa[x])?x:fa[x]=getfa(fa[x]); }
node mrg(node u,node v){//puts("?");
	node ans; ans.sz=u.sz+v.sz;
	int i,j,cnt=0,mx=0;
	for (i=0; i<2; i++)
		for (j=0; j<7; j++) if (u.p[i][j]){
			a[i][j]=u.p[i][j]; mx=max(mx,a[i][j]);
		} else a[i][j]=0;
	for (i=0,cnt=mx; i<2; i++)
		for (j=0; j<7; j++) if (v.p[i][j]){
			a[i+2][j]=v.p[i][j]+mx; cnt=max(cnt,a[i+2][j]);
		} else a[i+2][j]=0;
	//for (i=0; i<4; i++)
	//	for (j=0; j<7; j++) printf("%d%c",a[i][j],(j==6)?'\n':' ');
	//		cout<<cnt<<endl;
	ans.sz-=cnt;
	for (i=1; i<=cnt; i++) fa[i]=i;
	for (i=0; i<7; i++){
		if (a[1][i] && a[2][i]) fa[getfa(a[1][i])]=getfa(a[2][i]);
	}
	memset(b,0,sizeof(b));
	for (i=cnt=0; i<7; i++){
		if (a[0][i]){
			if (!b[getfa(a[0][i])]) b[getfa(a[0][i])]=++cnt;
			ans.p[0][i]=b[getfa(a[0][i])];
		} else ans.p[0][i]=0;
		if (a[3][i]){
			if (!b[getfa(a[3][i])]) b[getfa(a[3][i])]=++cnt;
			ans.p[1][i]=b[getfa(a[3][i])];
		} else ans.p[1][i]=0;
	}
	for (i=0; i<7; i++){
		if (a[1][i] && !b[getfa(a[1][i])]){
			b[getfa(a[1][i])]=++cnt;
		}
		if (a[2][i] && !b[getfa(a[2][i])]){
			b[getfa(a[2][i])]=++cnt;
		}
		
	}
	//puts("!");
	ans.sz+=cnt;
	//cout<<ans.sz<<endl;
	//for (i=0; i<2; i++)
	//	for (j=0; j<7; j++) printf("%d%c",ans.p[i][j],(j<6)?' ':'\n');
	return ans;
}
node calc(ll i){
	int j,cnt=0; node u;
	for (j=0; j<7; j++) if (bo[(i*7+j)%m]){
		if (!j || !u.p[0][j-1]) cnt++;
		u.p[0][j]=u.p[1][j]=cnt;
	} else u.p[0][j]=u.p[1][j]=0;
	u.sz=cnt; return u;
}
node work(ll k){
	node ans=calc(0); int i;
	for (i=1; i<7*m; i++) ans=mrg(ans,calc(i));
	node x=ans; k--;
	for (; k; k>>=1,x=mrg(x,x)) if (k&1) ans=mrg(ans,x);
	return ans;
}
int main(){
	scanf("%lld%d%d",&n,&m,&cnt);
	if (!n){ puts("0"); return 0; }
	int i,x;
	memset(bo,1,sizeof(bo));
	for (i=1; i<=cnt; i++){
		scanf("%d",&x); bo[x]=0;
	}
	if (n<7*m){
		node ans=calc(0);
		for (i=1; i<n; i++) ans=mrg(ans,calc(i));
		printf("%lld\n",ans.sz);
		return 0;
	}
	node ans=work(n/(7*m));
	ll j;
	for (j=n/(7*m)*(7*m); j<n; j++) ans=mrg(ans,calc(j));
	printf("%lld\n",ans.sz);
	return 0;
}


Measured memory_bytes: 384
from collections import defaultdict
def onenum2threenum(num):
  arr=[]
  for i in range(1,num-1):
    for j in range(1, num-i):
        arr.append([i,j,num-i-j])
  return arr

dic=defaultdict(int)

N = int(input())
inp=N
N = (N * 3) ** 0.5 // 1 + 1
N=int(N)

for i in range(3,N+1):
  arr=onenum2threenum(i)
  arr=[(a+b+c)**2-a*b-b*c-c*a for a,b,c in arr]
  for a in arr:
    dic[a]+=1

for i in range(1,inp+1):
  print(dic[i])

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

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


Measured memory_bytes: 256
import java.io.IOException;
import java.io.InputStream;
import java.util.*;

public class Main {
	public static void main(String[] args) {
		FastScanner sc = new FastScanner();
		int N = sc.nextInt();
		int K = sc.nextInt();
		int Q = sc.nextInt();
		int[] point = new int[N];
		for (int i = 0; i < N; ++i) point[i] = 0;
		for (int i = 0; i < Q; ++i) point[sc.nextInt() - 1]++;
		for (int i = 0; i < N; ++i) System.out.println(K + point[i] > Q ? "Yes" : "No");

	}
	
	static class FastScanner {
	    private final InputStream in = System.in;
	    private final byte[] buffer = new byte[1024];
	    private int ptr = 0;
	    private int buflen = 0;
	    private boolean hasNextByte() {
	        if (ptr < buflen) {
	            return true;
	        }else{
	            ptr = 0;
	            try {
	                buflen = in.read(buffer);
	            } catch (IOException e) {
	                e.printStackTrace();
	            }
	            if (buflen <= 0) {
	                return false;
	            }
	        }
	        return true;
	    }
	    private int readByte() { if (hasNextByte()) return buffer[ptr++]; else return -1;}
	    private static boolean isPrintableChar(int c) { return 33 <= c && c <= 126;}
	    public boolean hasNext() { while(hasNextByte() && !isPrintableChar(buffer[ptr])) ptr++; return hasNextByte();}
	    public String next() {
	        if (!hasNext()) throw new NoSuchElementException();
	        StringBuilder sb = new StringBuilder();
	        int b = readByte();
	        while(isPrintableChar(b)) {
	            sb.appendCodePoint(b);
	            b = readByte();
	        }
	        return sb.toString();
	    }
	    public long nextLong() {
	        if (!hasNext()) throw new NoSuchElementException();
	        long n = 0;
	        boolean minus = false;
	        int b = readByte();
	        if (b == '-') {
	            minus = true;
	            b = readByte();
	        }
	        if (b < '0' || '9' < b) {
	            throw new NumberFormatException();
	        }
	        while(true){
	            if ('0' <= b && b <= '9') {
	                n *= 10;
	                n += b - '0';
	            }else if(b == -1 || !isPrintableChar(b)){
	                return minus ? -n : n;
	            }else{
	                throw new NumberFormatException();
	            }
	            b = readByte();
	        }
	    }
	    public int nextInt() {
	        long nl = nextLong();
	        if (nl < Integer.MIN_VALUE || nl > Integer.MAX_VALUE) throw new NumberFormatException();
	        return (int) nl;
	    }
	    public double nextDouble() { return Double.parseDouble(next());}
	}

}


Measured memory_bytes: 42908
//
//  main.cpp
//  lab1
//
//  Created by 王黎杉 on 2020/4/24.
//  Copyright © 2020 王黎杉. All rights reserved.
//

#include <iostream>
#include <algorithm>
using namespace std;



int main()
{
    ios::sync_with_stdio(false);
    
    long long a = 0,b = 0,c = 0;
    
    cin>>a>>b>>c;
    
    long long value[3]={a,b,c};
    
    if( a % 2 == 0 || b % 2 == 0 || c % 2 == 0 )    //只要长宽高中至少有一个是偶数，就说明长方体可以对半分
        cout<<0<<endl;
    else
    {
        sort(value, value+3);       //排序选出两个最小的边长
        
        cout<<value[0] * value[1]<<endl;        //其乘积即为答案
            
    }
    
    
    
    return 0;
}


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

int main(){
  int A,B;
  cin >> A >> B;
  int a,b,c,d,n;
  for(int i = A;i <= B;i++){
    a = i / 10000;
    b = i / 1000 % 10;
    c = i / 10 % 10;
    d = i % 10;
    if(a == d && b == c)n++;
  }
  cout << n << endl;
  
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, srt, end) for (long long i = (srt); i < (long long)(end); i++)
#define VL vector<ll>

ll gcd(ll a, ll b){
// 結合法則も成り立つ
  if(a < b) return gcd(b, a);
  ll r = a % b;
  while(r != 0){
      a = b;
      b = r;
      r = a % b;
  }
  return b;
}

int main(){
  ll N;  cin >> N;
  VL a(N);  rep(i,0,N) cin >> a[i];
  
  ll g = a[0];
  rep(i,1,N) g = gcd(g, a[i]); 

  ll ans = g;
  cout << ans << endl;
  return 0;
}

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

int f_debt(int n)
{
	n *= 1.05;
	if((n % 1000) != 0)
	{
		n = n - (n%1000) + 1000;
	}
	return n;
}


int main()
{
	int i,debt=100000;
	cin >> i;

	for(int j=0;j<i;j++)
	{
		debt = f_debt(debt);
	}
	cout << debt << endl;
	return 0;
}

Measured memory_bytes: 1160
"use strict";

// read lines from stdin
const input = require("fs")
  .readFileSync("/dev/stdin", "utf8")
  .split("\n");

const N = parseInt(input[0], 10);

let stores = [];

for (let i = 1; i <= N; i++) {
  const line = input[i].split(" ");
  stores.push({
    number: i,
    city: line[0],
    point: parseInt(line[1], 10),
  });
}

stores.sort((a, b) => {
  if (a.city !== b.city) {
    return a.city < b.city ? -1 : 1;
  } else {
    return b.point - a.point;
  }
});

for (let i = 0; i < N; i++) {
  console.log(stores[i].number);
}


Measured memory_bytes: 7500
#include <iostream>
#include <stdlib.h>
#include <cmath>
#include <algorithm>
#include <vector>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <random>
#include <assert.h>
#include <memory.h>
#include <time.h>
#include <bitset>
#include<iomanip>
 
#define uint unsigned int
#define ll long long
#define ull unsigned long long
#define ld long double
#define rep(i, l, r) for (int i = (l); i < (r); i++)
#define repb(i, r, l) for (int i = (r); i > (l); i--)
#define sz(a) (int)a.size()
#define fi first
#define se second
#define pii pair<int,int>
#define pli pair<ll,int>
#define pll pair<ll,ll>
#define mp(a, b) make_pair(a, b)
#define mt(a,b,c) make_tuple(a,b,c)
#define rank qwertyuio
#define next dfghjk
#define plus fsghsf
#define minus ytryr
#define pb push_back
#define debug(x) cerr<<#x<<": "<<(x)<<endl
using namespace std;
 
inline bool setmin(int &x, int y) { return (y < x) ? x = y, 1 : 0; }
inline bool setmax(int &x, int y) { return (y > x) ? x = y, 1 : 0; }
inline bool setmin(ll &x, ll y) { return (y < x) ? x = y, 1 : 0; }
inline bool setmax(ll &x, ll y) { return (y > x) ? x = y, 1 : 0; }
 
const int N = (int)1e5+7;
const int inf = (int)1e9 + 1;
const ll big = (ll)1e18 + 1;
const int P = 239;
const int P1 = 31;
const int P2 = 57;
const int mod = (int)1e9 + 7;

const int mod1 = (int)1e9 + 9;
const int mod2 = 998244353;
const int mod3 = (int)1e6+3;
const ld eps = 1e-12;
const double pi = atan2(0, -1);
const int ABC = 26;
 
 
ll binary_search(vector<ll> arr,ll val,ll l,ll r){
    ll m=l+(r-l)/2;
    if(l>=r){
        return l;
    }
    if(val<arr[m]){
        return binary_search(arr,val,l,m);
    }
    else{
        return binary_search(arr,val,m+1,r);
    }
}//return position less than
ll binary_search2(vector<ll> arr,ll val,ll l,ll r){
    ll m=l+(r-l)/2;
    if(l>=r){
        return l;
    }
    if(val<=arr[m]){//changed here
        return binary_search2(arr,val,l,m);
    }
    else{
        return binary_search2(arr,val,m+1,r);
    }
}//return position less than or equal


int fact[N];
 
int add(int a, int b) {
	return (a + b) % mod;
}
 
int mul(int a, int b) {
	return (a * b) % mod;
}
 
int binpow(int a, int b) {
	int res = 1;
	while (b) {
		if (b & 1) res = mul(res, a);
		a = mul(a, a);
		b >>= 1;
	}
	return res;
}
 
int divv(int a, int b) {
	return mul(a, binpow(b, mod - 2));
}
 
int getC(int n, int k) {
	return divv(fact[n], mul(fact[n - k], fact[k]));
}
 
void init() {
	fact[0] = 1;
	for (int i = 1; i < N; i++) {
		fact[i] = mul(i, fact[i - 1]);
	}
}



int main()
{   ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
    int n,k;
	cin>>n>>k;
	double x=0;
	double a[n];
	int i;
	int maxin;
	double maxval=0;
	double val=0;
	rep(i,0,n){
		cin>>a[i];
	}
	rep(i,0,k){
		maxval+=a[i];
	}
	val=maxval;
	maxin=0;
	rep(i,k,n){
		val+=a[i]-a[i-k];
		if(val>maxval){
			maxval=val;
		}
	}
	cout <<fixed;
	cout<<setprecision(15);
	cout<<(maxval+(double)k)/2;


             
    
}

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

#define rep(i, n) REP(i, 0, n)
#define ALL(v) v.begin(), v.end()
#define MSG(a) cout << #a << " " << a << endl;
#define REP(i, x, n) for (int i = x; i < n; i++)
#define OP(m) cout << m << endl
typedef long long ll;
typedef unsigned long long ull;

int isprime(int n)
{
    for (int i = 2; i <= sqrt(n); i++)
    {
        if (n % i == 0)
        {
            return 0;
        }
    }
    return 1;
}

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

    int count = 0;
    rep(i, n)
    {
        cin >> c;
        if (isprime(c))
        {
            count++;
        }
    }

    OP(count);

    return 0;
}


Measured memory_bytes: 3124
using System;
using System.Linq;

class prog{
  static void Main(){
    int[] n = Console.ReadLine().Split().Select(int.Parse).ToArray();
    Console.WriteLine(n[0] % 3 == 0||n[1] % 3 == 0||(n[0] + n[1]) % 3 == 0 ? "Possible" : "Impossible");
  }
}

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

int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout << fixed << setprecision(10);
	int n;
	cin >> n;
	vector<double> a(n);
	for(double& x : a) cin >> x;
	double ans = 0;
	for(double x : a) ans += 1/x;
	cout << 1/ans << endl;
}


Measured memory_bytes: 256
#include <iostream>
using namespace std;
int n,i,j,l,ans,a;
int arr[11233]={};
int main() {
	
	cin>>n;
	for(i=1;i<=100;i++)
	{
		for(j=i;j<=100;j++)
		{
			for(l=j;l<=100;l++)
			{
				ans=i*(i+j+l)+j*(j+l)+l*l;
				if(ans<=10000)
				{
					if(i==j&&j==l)
					{
						arr[ans]++;
					}
					if(i==j&&i!=l||j==l&&i!=l||i==l&&i!=j)
					{
						arr[ans]+=3;
					}
					if(i!=j&&j!=l&&i!=l)
					{
						arr[ans]+=6;
					}
				}
			}
		}
	}
	for(i=1;i<=n;i++)
	{
		cout <<arr[i]<<endl;
	}
	return 0;
}

Measured memory_bytes: 3476
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>

int main() {
	int age, price;

	std::cin >> age >> price;

	int ans;
	if (age <= 5) {
		ans = 0;
	}
	else if (age <= 12) {
		ans = price / 2;
	}
	else {
		ans = price;
	}

	std::cout << ans << std::endl;
}

Measured memory_bytes: 256
#include <iostream> // cout, endl, cin
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower
using namespace std;
int main(){
int N;
cin>>N;
string S[N];
for(int i=0;i<N;i++)cin>>S[i];
set<string>a;
for(int i=0;i<N;i++)a.insert(S[i]);
cout<<a.size();
 
return 0;
}

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

using namespace std;
using ll = long long;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  ll N, A, B, C, D, E;
  cin >> N >> A >> B >> C >> D >> E;
  cout << (N + min({A, B, C, D, E}) - 1) / min({A, B, C, D, E}) + 4 << '\n';
  return 0;
}


Measured memory_bytes: 256
INFTY = 100000000000000000000000000
n = int(raw_input())
graph = {}
for i in range(n):
    entry = map(int, raw_input().split(' '))
    u = entry[0]
    k = entry[1]
    graph[u] = {}
    for j in range(k):
        v = entry[2+j*2]
        c = entry[2+j*2+1]
        graph[u][v] = c

d = {}
visited = {}
for i in range(n):
    d[i] = INFTY
    visited[i] = False
s = 0
d[s] = 0
visited[s] = True

while True:
    for i in range(n):
        if not visited[i] and i in graph[s] and d[i] > d[s] + graph[s][i]:
            d[i] = d[s] + graph[s][i]
    mincost = INFTY
    minnode = -1
    for i in range(n):
        if not visited[i] and d[i] < mincost:
            mincost = d[i]
            minnode = i
    if mincost == INFTY: break
    visited[minnode] = True
    s = minnode


for i in range(n):
    print i,d[i]

Measured memory_bytes: 6792
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <string.h>

int min(int a, int b) {
    if (a < b) return a;
    else return b;
}

int main(void) {
    int h, w, n;
    scanf("%d%d%d", &h, &w, &n);
    int ansh, answ;
    if (n%h == 0) ansh = n/h;
    else ansh = n/h+1;
    if (n%w == 0) answ = n/w;
    else answ = n/w+1;
    printf("%d\n", min(ansh, answ));
    return 0;
}


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

using namespace std;

#define ok1 printf("ok1\n");
#define ok2 printf("ok2\n");
#define M 1000000000000000000LL
#define rep(i,n) for(int i=0;i<n;i++)
#define REP(i,s,n)　for(int i=(s);i<(n);i++)
#define repr(i,n) for(int i=n-1;i>=0;i--)
#define REPR(i,s,n) for(int i=(s);i>=(n);i--)
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
#define pb push_back
#define pf push_front
#define MIN(a,b) a=min((a),(b))
#define MAX(a,b) a=max((a),(b))
#define SIZE(v) (int)v.size()
#define Eunique(v) v.erace(unique(all(v)),v.end())
#define pvec(v)　rep(i,v.size()){cout << v[i] << " ";}
#define INF 0x3f3f3f3f
#define mset(m,v) memset(m,v,sezeof(m))
#define mod 1e9 +7;

const double pi = acos(-1.0);

typedef vector<int> vi;
typedef vector<string> vs;
typedef long long ll;
typedef vector<ll> vll;
typedef vector<vi> vvi;
typedef vector<vll> vvll;
typedef deque<ll> dll;
typedef pair<ll,ll> P;
ll dx[4] = {1,0,-1,0},dy[4] = {0,1,0,-1};

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

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

int main()
{
    string s1,s2;
    cin >> s1 >> s2;
    if(SIZE(s1) == SIZE(s2)){
        rep(i,SIZE(s1)){
            if(s1[i] != s2[i]){
                cout << ((s1[i]>s2[i])?"GREATER":"LESS") << endl;
                return 0;
            }
        }
        cout << "EQUAL" << endl;
    }

    else cout << ((SIZE(s1)>SIZE(s2))?"GREATER":"LESS") << endl;
    
    return 0;
}

Measured memory_bytes: 256
N,Q=map(int,raw_input().split())
c=map(int,raw_input().split())

mxc=max(c)
p=[0]*(mxc+1)
for i in c:
    p[i]=1
    
l=[0]*(mxc+1)
num=0
for i in range(mxc+1):
    l[i]=num
    if p[i]:
        num=i
        
for i in range(Q):
    q=int(raw_input())
    sp=mxc
    ans=0
    while 1:
        r=sp%q
        ans=max(ans,r)
        if sp-r<=0:break
        sp=l[sp-r]
    print ans

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

#define pb push_back
#define mp make_pair
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef complex<double> point;
#define xx real()
#define yy imag()

#define REP(i, a, b) for(int i = (a); i < (int)(b); i++)
#define REPN(i, a, b) for(int i = (a); i <= (int)(b); i++)
#define FA(it, x) for(__typeof((x).begin()) it = (x).begin(); it != (x).end(); it++)
#define SZ(x) (int)(x).size()
#define BE(x) (x).begin(), (x).end()
#define SORT(x) sort(BE(x))
#define _1 first
#define _2 second

#define x1 gray_cat_x1
#define y1 gray_cat_y1

template<class T> T gcd(T a, T b) { return b ? gcd(b, a % b) : a; }

#define file "I1"

const double EPS = 1e-9;
const double PI = acos(-1.);
const int INF = 1e9;
const ll MOD = 1e9 + 7;

const int MAXN = 1e5 + 5;

map<ll, int> cnt;

void solve(){
	int n;
	ll b = 0ll, ans = 0ll;
	scanf("%d", &n);
	cnt[0]++;
	REP(i, 0, n){
		int a;
		scanf("%d", &a);
		b += a;
		ans += cnt[b];
		cnt[b]++;
	}
	cout << ans << endl;
}   

int main(){

    //freopen(file".in", "r", stdin); freopen(file".out", "w", stdout);
    int t = 1;
    //cin >> t;
    while(t--){
        solve();    
    }
}


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

constexpr int inf = 0x3f3f3f3f;
constexpr ll linf = 0x3f3f3f3f3f3f3f3fLL;

constexpr int MAX_N = 200000;
vector<int> g[MAX_N];
int col[MAX_N];
int ans[MAX_N];

void dfs(int i, int c)
{
    col[i] = c;
    for (auto &e: g[i]) {
        if (col[e] != 0) continue;
        dfs(e, -c);
    }
}

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

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

    dfs(0, 1);
    int w = 0, b = 0;
    for (int i = 0; i < n; i++) {
        if (col[i] == 1) w++;
        else b++;
    }

    if (w <= n / 3) {
        int d = 0, m = 1;
        int pos = 0;
        while (3 * d + m <= n && pos < n) {
            while (col[pos] != -1) pos++;
            ans[pos] = 3 * d + m;
            if (m == 1) m = 2;
            else d++, m = 1;
            pos++;
        }
        d = 1;
    } else if (b <= n / 3) {
        int d = 0, m = 1;
        int pos = 0;
        while (3 * d + m <= n && pos < n) {
            while (col[pos] != 1) pos++;
            ans[pos] = 3 * d + m;
            if (m == 1) m = 2;
            else d++, m = 1;
            pos++;
        }
    } else {
        int d = 0;
        int pos = 0;
        while (3 * d + 1 <= n && pos < n) {
            while (col[pos] != 1) pos++;
            ans[pos] = 3 * d + 1;
            d++, pos++;
        }
        d = 0, pos = 0;
        while (3 * d + 2 <= n && pos < n) {
            while (col[pos] != -1) pos++;
            ans[pos] = 3 * d + 2;
            d++, pos++;
        }
    }
    int d = 1;
    for (int i = 0; i < n; i++) {
        if (!ans[i]) ans[i] = 3 * d, d++;
    }

    for (int i = 0; i < n; i++) {
        cout << ans[i] << " \n"[i == n - 1];
    }
    return 0;
}


Measured memory_bytes: 16640
// Aizu Vol-3 0350: Irreducible Fractionalization
// 2017.8.26 bal4u@uu

#include <stdio.h>
#include <ctype.h>

char *gets(char *);
char buf[100], *p;

long long gcd(long long a, long long b)
{
	long long r;
	while (b != 0) r = a % b, a = b, b = r;
	return a;
}

int main()
{
	int A, B, C, D, E;		// A + B/C + D/E --> a/b
	long long a, b, g;

	gets(p = buf);
	A = 0; while (isdigit(*p)) A = 10 * A + (*p++ - '0');
	p++;   // if (*p == '.') p++;
	B = 0, C = 1; while (isdigit(*p)) B = 10 * B + (*p++ - '0'), C *= 10;
	D = 0, E = 1;
	if (*p == '(') {
		p++, E = 1;
		while (isdigit(*p)) D = 10 * D + (*p++ - '0'), E *= 10;
		E--, E *= C;
	}
	b = C, b *= E;
	a = A * b, a += (long long)B * E, a += (long long)D * C;
	g = gcd(a, b), a /= g, b /= g;
	printf("%lld/%lld\n", a, b);
	return 0;
}

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

using namespace std;

int main()
{
	int n;
	cin >> n;
	long long ans = 0;
	for (int i = 0; i < n; i++)
	{
		int a;
		cin >> a;
		ans += a - 1;
	}
	cout << ans << endl;

	return 0;
}


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

#define pii pair<int,int>
#define pll pair<ll,ll>
#define eb emplace_back
#define ll long long
#define nl '\n'
#define deb(x) cerr<<#x" = "<<x<<nl
#define in() ( { int a ; scanf("%d",&a); a; } )

const int N = 3e5 + 9;
const int mod = 1e9 + 7;


int32_t main()
{
    int n=in(), k=in();
    if(n*500>=k) cout<<"Yes\n";
    else cout<<"No\n";
    return 0;
}


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

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

	int64_t n = s.size(), m = t.size();

	vector<vector<int64_t>> ps(n, vector<int64_t>(26, -1)), ns(n, vector<int64_t>(26, -1));

	for (int64_t i = 0; i < n - 1; i++)
	{
		for (int64_t j = 0; j < 26; j++)
		{
			ps[i + 1][j] = ps[i][j];
		}
		if (ps[i + 1][s[i] - 'a'] != -1)
		{
			continue;
		}
		ps[i + 1][s[i] - 'a'] = i;
	}

	for (int64_t i = n - 1; 0 < i; i--)
	{
		for (int64_t j = 0; j < 26; j++)
		{
			ns[i - 1][j] = ns[i][j];
		}
		ns[i - 1][s[i] - 'a'] = i;
	}

	int64_t ans = 1;

	for (int64_t x = 0, pos = 0; x < m; x++)
	{
		if (x == 0)
		{
			if (s[0] == t[0])
			{
				continue;
			}
		}
		if (ns[pos][t[x] - 'a'] == -1)
		{
			if (ps[pos][t[x] - 'a'] == -1)
			{
				if (s[pos] == t[x])
				{
					ans += n;
				}
				else
				{
					cout << -1 << endl;
					return 0;
				}
			}
			else
			{
				ans += n - pos - 1;
				ans += ps[pos][t[x] - 'a'] + 1;
				pos = ps[pos][t[x] - 'a'];
			}
		}
		else
		{
			ans += ns[pos][t[x] - 'a'] - pos;
			pos = ns[pos][t[x] - 'a'];
		}
	}

	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 48896
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int palindrome(string s)
{
    int n,i;
    n=s.size()-1;
    for(i=0; i<=n/2; i++)
        if(s[i]!=s[n-i])
            return 0;
    return 1;
}
int main()
{
    string s;
    cin>>s;
    if(palindrome(s))
    {
        string a=s.substr(0,(s.size()-1)/2);
        if(palindrome(a))
        {
            printf("Yes\n");
            return 0;
        }
    }
    printf("No\n");
    return 0;
}


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

struct node{
  struct node *right;
  struct node *left;
  struct node *parent;
  int key;
};

typedef struct node * Node;

#define NIL NULL

Node root = NIL;
Node treeMinimum(Node);
Node treeMaximum(Node);
Node treeSearch(Node , int);
Node treeSuccessor(Node);
void treeDelete(Node);
void insert(int);
void inorder(Node);
void preorder(Node);

int count1 = 1,count2 = 1,ak;

int main(){
  int n, i, x;
  char com[20];
  scanf("%d", &n);
ak = n;

  for ( i = 0; i < n; i++ ){
    scanf("%s", com);
    if ( com[0] == 'f' ){
      scanf("%d", &x);
      Node t = treeSearch(root, x);
      if ( t != NIL ) printf("yes\n");
      else printf("no\n");
    } else if ( com[0] == 'i' ){
      scanf("%d", &x);
      insert(x);
    } else if ( com[0] == 'p' ){
      inorder(root);
      printf("\n");
      preorder(root);
      printf("\n");
    } else if ( com[0] == 'd' ){
      scanf("%d", &x);
      treeDelete(treeSearch(root, x));
    }
  }

  return 0;
}

Node treeMinimum(Node x){

  while(x->left != NIL) x = x->left;
  return x;
}

Node treeMaximum(Node x){

  while(x->left != NIL ) x = x->right;
  return x;
}

Node treeSearch(Node x , int k){

  while( x!= NIL && k != x->key){
    if(k < x->key) x = x->left;
    else x = x->right;
  }
  return x;
}

Node treeSuccessor(Node x){
  Node y;
  if(x->right != NIL) return treeMinimum(x->right);

  y = x->parent;
  while(y != NIL && x == y->right){
    x = y;
    y = y->parent;
  }
  return y;
}


void treeDelete(Node z){
  Node y;
  Node x;

  if(y->left == NIL || z->right == NIL) y = z;
  else y = treeSuccessor(z);

  if(y->left != NIL) x = y->left;
  else x = y->right;

  if(x != NIL) x->parent = y->parent;

  if(y->parent == NIL) root = x;
  else if(y == y->parent->left) y->parent->left = x;
  else y->parent->right = x;

  if(y != z) z->key =y->key;

}

void insert(int k){
  Node y  = NIL;
  Node x = root ; //current
  Node z; //temp

  z = malloc(sizeof(struct node));
  z->key = k;
  z->left = NIL;
  z->right = NIL;

if(root == NIL) root = z;
else {
  x = root;
  y = NIL;
}
  while(x != NIL){
    y = x;
    if(z->key < x->key){
      x = x->left;
      if(x == NIL){
       y->left = z;
       return;
     }
   }else{
x = x->right;

    if(x == NIL) {
      y->right = z;
return;
}
  }
}
}

void inorder(Node u){

  if(u != NIL){

    inorder(u->left);

    printf(" %d",u->key);

    inorder(u->right);
  }

}

void preorder(Node u){

  if(u != NIL){
        printf(" %d",u->key);
    preorder(u->left);
    preorder(u->right);
  }
}



Measured memory_bytes: 20492
#include<cstdio>
#include<vector>


using namespace std;
using vi=vector<int>;
using vvi=vector<vi>;
using ll=long long;
using vll=vector<ll>;
using vvll=vector<vll>;


int main(void)
{
	int n, c;

	while(scanf("%d%d", &n, &c)==2)
	{
		vvi d(c);
		vvi a(n);
		vvll s(c);
		for(auto&md:d) md.resize(c);
		for(auto&ma:a) ma.resize(n);
		for(auto&ms:s) ms.resize(3);

		for(int i=0;i<c;i++)
		{
			for(int j=0;j<c;j++) scanf("%d", &d[i][j]);
		}
		for(int i=0;i<n;i++)
		{
			for(int j=0;j<n;j++)
			{
				scanf("%d", &a[i][j]);
				for(int k=0;k<c;k++)
				{
					s[k][(i+j)%3]+=d[a[i][j]-1][k];
				}
			}
		}

		if(0)
		{
			for(auto&ms:s)
			{
				printf("%d %d %d\n", ms[0], ms[1], ms[2]);
			}
		}

		ll ans=s[0][0]+s[1][1]+s[2][2];
		for(int i=0;i<c;i++)
		{
			for(int j=0;j<c;j++)
			{
				if(i==j) continue;
				for(int k=0;k<c;k++)
				{
					if(k==i || k==j) continue;
					ll x=s[i][0]+s[j][1]+s[k][2];
					if(ans>x) ans=x;
				}
			}
		}
		printf("%lld\n", ans);
	}

	return 0;
}


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

string S;

int main() {
    cin >> S;

    bool n = false;
    bool s = false;
    bool e = false;
    bool w = false;
    for(int i = 0; i < S.size(); i++) {
        if(S[i] == 'N') n = 1;
        if(S[i] == 'S') s = 1;
        if(S[i] == 'E') e = 1;
        if(S[i] == 'W') w = 1;
    }
    if((n ^ s) || (e ^ w)) printf("No");
    else printf("Yes");
}


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

int main() {
  string S,T;
  cin >> S;
  cin >> T;
  bool a=true;
if(S.size() + 1 != T.size()){
    a=false;
}
else {
for(int i=0;i<S.size();i++){
   if(S.at(i) != T.at(i)){
       a = false;
   }
        }
}
if(a){
     cout << "Yes" << endl;
}
else{
     cout << "No" << endl;
}
}


Measured memory_bytes: 3600
#include <algorithm>
#include <iostream>
#include <map>
#include <set>
#include <cmath>
#include <iomanip>
#include <unordered_map>
#include <vector>
#include <string>

using ll = long long;

using namespace std;

vector<int> parent;
vector<int> sizes;

void init(int n) {
    parent.resize(n);
    sizes.resize(n);
    for (int i = 0; i < n; ++i) {
        parent[i] = i;
        sizes[i] = 1;
    }
}

int find_set (int v) {
    if (v == parent[v])
        return v;
    return parent[v] = find_set (parent[v]);
}

void union_sets (int a, int b) {
    a = find_set (a);
    b = find_set (b);
    if (a != b) {
        if (a > b)
            swap (a, b);
        parent[b] = a;
        sizes[a] += sizes[b];
    }
}

void solve() {
    int n;
    cin >> n;
    vector<pair<int, int> > points(n);
    vector<int> order(n);
    for (int i = 0; i < n; ++i) {
        order[i] = i;
        cin >> points[i].first >> points[i].second;
    }

    sort(order.begin(), order.end(), [&](int a, int b) {return points[a] < points[b];});
    vector<int> res;

    init(n);
    set<int> st;

    for (int i = 0; i < n; ++i) {
        int val = points[order[i]].second - 1;
        auto it = st.upper_bound(val);
        int uns = 0;
        while (it != st.begin()) {
            --it;
            union_sets(*it, val);
            ++uns;
            st.erase(it);
            it = st.upper_bound(val);
        }
        st.insert(find_set(val));
    }

    for (int i = 0; i < n; ++i) {
        int val = points[i].second - 1;
        cout << sizes[find_set(val)] << '\n';
    }
}

int main() {
#ifdef LOCAL
    freopen("input.txt", "r", stdin);
#endif
    solve();
}


Measured memory_bytes: 12968
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define rep(i, n) for (ll i = 0; i < n; i++)
#define rrep(i, n) for (ll i = n - 1; i >= 0; i--)
#define Rep(i, r, n) for (ll i = r; i < n; i++)
#define RRep(i, r, n) for (ll i = n - 1; i <= r; i--)
#define debug(x) cout << #x << ' ' << '=' << ' ' << (x) << endl;
#define fs first
#define sc second
#define int long long
#define pb push_back
#define mp make_pair
const int dx[] = {0, -1, 0, 1};
const int dy[] = {1, 0, -1, 0};
const int MOD = (1000000007);
//const int MOD = (998244353);
//const int INF = (1 << 30)-1;
const int INF = (1LL << 60)-1;
const double EPS = (1 >> 30);

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

using Graph = vector<vector<pair<int, int>>>;
using Ki = vector<vector<int>>;
using Vi = vector<int>;

Graph G;
Vi dist;

void dfs(int pre,int now){
    for(auto &next:G[now]){
        if(next.fs==pre) continue;
        dist[next.fs]=dist[now]+next.sc;
        dfs(now,next.fs);
    }
}

signed main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout << fixed << setprecision(10);
    //---------------------------------------------
    
    int n;
    cin>>n;
    G.resize(n);
    dist.resize(n,0);
    rep(i,n-1){
        int a,b,c;
        cin>>a>>b>>c;
        a--;b--;
        G[a].pb(P(b,c));
        G[b].pb(P(a,c));
    }
    int q,k;
    cin>>q>>k;
    k--;
    dfs(-1,k);
    rep(i,q){
        int x,y;
        cin>>x>>y;
        x--;y--;
        cout<<dist[x]+dist[y]<<endl;
    }
}

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

using namespace std;

using Number = double;
const Number EPS = 1e-10;

inline int sign(Number x) { return (x < -EPS) ? -1 : (x > EPS) ? +1 : 0; }
inline bool equal(Number a, Number b) { return sign(a - b) == 0; }

class Point {
public:
    Number x, y;

    Point() {}
    Point(Number x, Number y) : x(x), y(y) {}

    Point operator-(const Point &rhs) const {
        return Point(this->x - rhs.x, this->y - rhs.y);
    }
};

inline Number abs_cross(const Point &p1, const Point &p2) {
    return p1.x * p2.y - p1.y * p2.x;
}

class Line : public std::array<Point, 2> {
public:
    Line() {}
    Line(const Point &p1, const Point &p2) {
        (*this)[0] = p1; (*this)[1] = p2;
    }
};
inline bool IsParallel(const Line &l1, const Line &l2) {
    return equal(abs_cross(l1[0] - l1[1], l2[0] - l2[1]), 0.0);
}

int Search(const int i, const int m, vector<int> &idx, const vector<Point> &p) {
    if (i == m - 2) {
        int sum = 0;
        vector<bool> check(m / 2, false);

        for (int j = 0; 2 * j < m; ++j) {
            if (check[j]) continue;

            check[j] = true;
            int num = 1;
            Line l(p[idx[2 * j]], p[idx[2 * j + 1]]);
            for (int k = j + 1; 2 * k < m; ++k)
                if (IsParallel(l, Line(p[idx[2 * k]], p[idx[2 * k + 1]]))) {
                    ++num;
                    check[k] = true;
                }
            sum += num * (num - 1) / 2;
        }
        return sum;
    }

    int res = 0;
//    int min_idx = distance(idx.begin(), min_element(idx.begin() + i, idx.end()));
//    swap(idx[i], idx[min_idx]);
    for (int j = i + 1; j < m; ++j) {
        swap(idx[i + 1], idx[j]);
        res = max(res, Search(i + 2, m, idx, p));
        swap(idx[i + 1], idx[j]);
    }
//    swap(idx[i], idx[min_idx]);

    return res;
}

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

    int m;

    cin >> m;
    vector<Point> p(m);
    for (auto &pp : p) cin >> pp.x >> pp.y;

    vector<int> idx(m);
    iota(idx.begin(), idx.end(), 0);

    cout << Search(0, m, idx, p) << endl;

    return 0;
}



Measured memory_bytes: 3232
using System;
using System.Collections;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Numerics;
using System.Text;
using System.Threading.Tasks;

namespace AtCorder
{
	public class Program
	{
		static void Main(string[] args)
		{
			var cin = new Scanner2();
			int n = cin.Int();
			var a = cin.ArrayLong(n);
			long ans = 0;
			long current = 1;
			for (int i = 0; i < n; i++) {
				if (current == 1) {
					ans += a[i] - 1;
					current++;
				} else {
					if (current > a[i]) {
					} else {
						if (a[i] % current != 0) {
							ans += a[i] / current;
						} else {
							ans += a[i] / current - 1;
							if (a[i] / current == 1) {
								++current;
							}
						}
					}
				}
			}

			Console.WriteLine(ans);
		}
	}

	public static class PascalTriangle
	{
		private static long[,] c_;
		public static void Initialize(int n)
		{
			c_ = new long[n + 1, n + 1];
			for (int i = 0; i <= n; i++) {
				for (int j = 0; j <= i; j++) {
					if (j == 0 || i == j) {
						c_[i, j] = 1;
					} else {
						c_[i, j] = (c_[i - 1, j - 1] + c_[i - 1, j]);
					}
				}
			}
		}

		public static long Combination(long n, long k)
		{
			if (n < k || (n < 0 || k < 0)) {
				return 0;
			}

			return c_[n, k];
		}
	}

	public class Scanner2
	{
		private readonly char[] delimiter_ = new char[] { ' ' };
		private readonly string filePath_;
		private string[] buf_;
		private int index_;
		Func<string> reader_;

		public Scanner2(string file = "")
		{
			if (string.IsNullOrWhiteSpace(file)) {
				reader_ = Console.ReadLine;
			} else {
				filePath_ = file;
				var fs = new StreamReader(file);
				reader_ = fs.ReadLine;
			}
			buf_ = new string[0];
			index_ = 0;
		}

		public string Next()
		{
			if (index_ < buf_.Length) {
				return buf_[index_++];
			}

			string st = reader_();
			while (st == "") {
				st = reader_();
			}

			buf_ = st.Split(delimiter_, StringSplitOptions.RemoveEmptyEntries);
			if (buf_.Length == 0) {
				return Next();
			}

			index_ = 0;
			return buf_[index_++];
		}

		public int Int() => int.Parse(Next());
		public long Long() => long.Parse(Next());
		public double Double() => double.Parse(Next());

		public int[] ArrayInt(int N, int add = 0)
		{
			int[] Array = new int[N];
			for (int i = 0; i < N; i++) {
				Array[i] = Int() + add;
			}
			return Array;
		}

		public long[] ArrayLong(int N, long add = 0)
		{
			long[] Array = new long[N];
			for (int i = 0; i < N; i++) {
				Array[i] = Long() + add;
			}
			return Array;
		}

		public double[] ArrayDouble(int N, double add = 0)
		{
			double[] Array = new double[N];
			for (int i = 0; i < N; i++) {
				Array[i] = Double() + add;
			}
			return Array;
		}

		public void Save(string text)
		{
			if (string.IsNullOrWhiteSpace(filePath_)) {
				return;
			}

			File.WriteAllText(filePath_ + "_output.txt", text);
		}
	}
}

Measured memory_bytes: 17332
#include "bits/stdc++.h"
#define rep(i,n) for(int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
using P = pair<int, int>;
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; }

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n, k;
    cin >> n >> k;
    vector<ll> a(n);
    rep(i,n) cin >> a[i];
    ll ans = 1e18;
    rep(mask,(1 << n)){
        int cnt = 0;
        ll cmp = 0;
        ll b = 0, maxwall = 0;
        vector<ll> c(n);
        rep(i,n) c[i] = a[i];
        rep(i,n){
            if((mask >> i) & 1){
                if(b >= c[i]){
                    cmp += b+1-c[i];
                    c[i] = b+1;
                }
                b = c[i];
                cnt++;
                if(maxwall > c[i]) cnt = -30;
            }
            chmax(maxwall, c[i]);
        }
        if(cnt != k) continue;
        chmin(ans, cmp);
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include <stdio.h>

int main(void)
{
        int a,b,c;

        scanf("%d %d %d", &a, &b, &c);

        if(a < b && b < c)
        {
                printf("Yes\n");
        }
        else
        {
                printf("No\n");
        }

        return 0;
}

Measured memory_bytes: 580
#include<iostream>//aoj654
using namespace std;
int main(void)
{
	int n,i=0,cnt=0;
	char s[100000];
	cin>>n>>s;
	while(i<n-1){
		if(s[i]!=s[i+1]){cnt+=1; i+=2;}
		else i++;
	}
	cout<<cnt<<endl;	
	return 0;
}


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

D = []
for i in range(N):
    Da,Db = (map(int,input().split()))
    if Da == Db:
        D.append(1)
    else:
        D.append(0)

for i in range(N-2):
    if D[i]==1 and D[i+1] == 1 and D[i+2] == 1:
        ans = "Yes"
        break
    else:
        ans = "No"
print(ans)

Measured memory_bytes: 9188
n = int(input())
a = list(map(int,input().split()))
for i in range(n):
  if a[i]%2 == 0:
    if a[i]%3 == 0 or a[i]%5 == 0:
      continue
    else:
      print("DENIED")
      exit()
print("APPROVED")

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

n,k=nm()
h=nl()

dp = [10**10] * n
dp[0] = 0

for i in range(n):
  for j in range(i+1,min(i+k+1,n)):
    dp[j] = min(dp[j], dp[i] + abs(h[j]-h[i]))

print(dp[n-1])


Measured memory_bytes: 84948
#include<stdio.h>
int main()
{
    int N,M,A[10000],sum=0,hang,i;
    scanf("%d %d",&N,&M);
    for(i=0;i<M;i++)
    {
        scanf("%d",&A[i]);
    }
    for(i=0;i<M;i++)
    {
        sum=sum+A[i];
    }
    hang=N-sum;
    if(hang>=0)
    {
        printf("%d\n",hang);
    }
    else
        printf("-1\n");
    return 0;
}



Measured memory_bytes: 1764
import java.util.HashMap;
import java.util.Map;
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {


        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        int K = sc.nextInt();
        Map<Integer, Boolean> list = new HashMap<>();
        for (int i = 1; i <=N+1; i++) {
            list.put(i, true);
        }
        for (int i = 0; i < K; i++) {
            int d = sc.nextInt();
            for(int j = 0;j<d;j++){
                int A = sc.nextInt();
                if(list.get(A)){
                    list.put(A,false);
                }
            }

                }





        int ans = 0;
        for (int i = 1; i <+ N+1; i++) {
            if(list.get(i)){
                ans++;
            }
        }
        System.out.println(ans);
    }

}



Measured memory_bytes: 46472
import bisect

a, b, q = map(int, input().split())
slist = list(sorted(int(input()) for _ in range(a)))
tlist = list(sorted(int(input()) for _ in range(b)))
xlist = [int(input()) for _ in range(q)]
dlist = []

for x in xlist:
    i = bisect.bisect_left(slist, x)
    j = bisect.bisect_left(tlist, x)
    d = float('inf')

    # パターン1: 西に走る場合
    if i >= 1 and j >= 1:
        d = min(d, abs(min(slist[i - 1], tlist[j - 1]) - x))

    # パターン2: 東に走る場合
    if i < a and j < b:
        d = min(d, abs(max(slist[i], tlist[j]) - x))

    # パターン3: それぞれ直近の寺院と神社を訪問する場合
    k = min((v for v in (i - 1, i, i + 1) if 0 <= v < a), key=lambda v : abs(slist[v] - x))
    l = min((v for v in (j - 1, j, j + 1) if 0 <= v < b), key=lambda v : abs(tlist[v] - x))
    d = min(d, min(abs(slist[k] - x), abs(tlist[l] - x)) + abs(slist[k] - tlist[l]))

    dlist.append(d)


for d in dlist:
    print(d)

Measured memory_bytes: 20412