akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
#define watch(x) cout << (#x) << " is " << (x) << endl
typedef long long ll;
using namespace std;
int static fast = [](){
  ios::sync_with_stdio(false);
  cin.tie(0); cout.tie(0); return 0;
}();
// freopen("input.txt", "r", stdin);

int main() {
    ll n, W;
    cin >> n >> W;
    map<int, int> dp;
    int wn, vn;
    int ans = 0;
    dp[0] = 0;
    int cur = 0;
    for(int i = 0; i < n; i++) {
        cin >> wn >> vn;
        map<int, int> new_dp;
        for(auto p: dp) {
            if (p.first + wn <= W) {
                new_dp[p.first+wn] = max(new_dp[p.first+wn], p.second + vn);
            }
            new_dp[p.first] = max(new_dp[p.first], p.second);
        }
        dp = map<int, int>();
        cur = -1;
        for(auto p: new_dp) {
            if (p.second <= cur) {
                continue;
            } else {
                dp[p.first] = p.second;
                cur = max(cur, p.second);
            }
        }
    }
    cout << cur << endl;
    return 0;
}





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

#define MOD 1000000007

int main() {
    ll n, k;
    cin >>n >>k;
    if (k<n) {
        cout <<0 <<endl;
        return 0;
    }
    ll S=1;
    while (n>0) {
        S *=k;
        k--;
        n--;
        S %=MOD;
    }
    cout <<S <<endl;
    return 0;
}



Measured memory_bytes: 3112
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#pragma GCC optimize("unroll-loops")
#include <bits/stdc++.h>

#define pb push_back
#define sz(x) ((int)(x).size())
#define all(x) (x).begin(),(x).end()
#define ll long long



using namespace std;

void file(){
	#ifndef ONLINE_JUDGE
    	freopen("in.txt", "r", stdin);
	#endif
}
int tc;
const int N=2e5+5,M=2e6+5,MOD=1e9+7,OO=1e9;

int main(){
	ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
	//file();	
 	
 	int n,k;

 	scanf("%d %d",&n,&k);

 	std::vector<double> a(n);

 	for(int i=0;i<n;i++)scanf("%lf",&a[i]);
 	double ans = 0;
 	double curr = 0;
 	for(int i=0;i<n;i++){
 		curr+=(a[i]+1)/2;
 		if(i>=k)curr-=((a[i-k]+1)/2);
 		if(i>=(k-1)){
 			ans = max(ans,curr);
 		}

 	}
 	printf("%.9lf\n",ans );
}		


Measured memory_bytes: 1792
#include <bits/stdc++.h>
using namespace std;
#define FOR(i, n) for(int i = 0; i < (n); i++)
#define MEM(a, x) memset(a, x, sizeof(a))
#define ALL(a) a.begin(), a.end()
#define UNIQUE(a) a.erase(unique(ALL(a)), a.end())
typedef long long ll;

int n, t;
int a[100005];

int main(int argc, char const *argv[]) {
	ios_base::sync_with_stdio(false);
	cin >> n >> t;
	map<int, int> mp;
	cin >> a[0];
	int mi = a[0], ma = 0;
	for (int i = 1; i < n; i++) {
		cin >> a[i];
		if (a[i] < mi) mi = a[i];
		else {
			mp[a[i]-mi]++;
			ma = max(ma, a[i]-mi);
		}
	}
	cout << mp[ma] << endl;
	return 0;
}

Measured memory_bytes: 5376
#include<iostream>
#include<algorithm>
#include<vector>
#include<cmath>

int main () {
    int n;
    long long y;
    std::cin >> n >> y;

    long long ansx, ansy, ansz;
    bool bf = false;
    for (int i = 0; i <= y / 10000 && i <= n; i++)
    {
        for (int j = 0; j <= y / 5000 && j <= n; j++) {
            long long z = (y - 10000 * i - 5000 * j) / 1000;
            if(z >= 0 && z <= n && i + j + z == n) {
                ansx = i;
                ansy = j;
                ansz = z;
                bf = true;
                break;
            }
            else
            {
                ansx = ansy = ansz = -1;
            }
        }

        if(bf) {
            break;
        }
    }

    std::cout << ansx << " " << ansy << " " << ansz << "\n";
}

Measured memory_bytes: 256
S[1<<20],Q[1<<20],q;b,u,x,i,n;main(c){for(;read(0,&c,1);)if(c-10)b=b*4+c%3+1,u=u*4+1;else{for(c=S[q=b]=0;b%u;c=S[b=Q[b]])for(x=b^b/4,i=0;x>3;i+=2,x/=4)(n=x&3)&&!Q[n=b&~(15<<i)^n*5<<i]?S[q=Q[q]=n]=c+1:0;b-1?b?printf("%d\n",S[b]):puts("NA"):0;memset(Q,c=b=u=0,4<<20);}}

Measured memory_bytes: 6396
#include<bits/stdc++.h>
#define forr(i, a, b) for(int i = (a); i < (b); i++)
#define rep(i,n) for(int i = 0; i < (n); i++)
#define rrep(i,n) for(int i = 1; i <= (n); i++)
#define ALL(a) (a.begin()),(a.end())
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
typedef pair<ll, ll> LP;
const ll LINF = 1LL<<60;
const int INF = 1001001001;
const int MOD = 1000000007;

/* --------------------------------------------------- */

unordered_map<int, int> memo;

int main() {
    int n;
    cin >> n;
    rrep(i, n) {
        int a;
        cin >> a;
        memo[i] = a;
    }
    int ans = 0;
    rrep(i, n) {
        if(memo[memo[i]] == i) ans++;
    }
    ans /= 2;
    cout << ans << endl;
    
    return 0;
}

Measured memory_bytes: 4388
#include <iostream>
#include <cmath>
#include <vector>
#include <string>
#include <map>
#include <algorithm>
#include <tuple>
#include <set>
#include <stack>
#include <queue>
#include <deque>
#define REP(i, n) for(LL i = 0;i < n;i++)
#define REPR(i, n) for(LL i = n;i >= 0;i--)
#define FOR(i, m, n) for(LL i = m;i < n;i++)
#define FORR(i, m, n) for(LL i = m;i >= n;i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define pb(a) push_back(a)
#define all(x) (x).begin(),(x).end()
#define INF 999999999
#define MOD 1000000007
using namespace std;
typedef long long LL;
//typedef LL int;
typedef pair<int, int> P;
typedef pair<LL, LL> LP;
typedef pair<int, P> PP;
typedef pair<LL, LP> LPP;
int dy[]={0, 0, 1, -1, 0};
int dx[]={1, -1, 0, 0, 0};

int main(){
    int n;
    cin >> n;
    set<int> ans;
    REP(i, n){
        int a;
        cin >> a;
        set<int>::iterator it = ans.find(a);
        if(it != ans.end()) ans.erase(a);
        else ans.insert(a);
    }

    cout << ans.size() << endl;
}


Measured memory_bytes: 4864
import std.stdio;
import std.conv;
import std.string;
void main()
{
  int[] a;// = to!( int[] )( readln.chomp() );
  for(;a.length<4;)a~= to!( int )( readln.chomp() );
  writeln(a[0] > a[1] ? a[1] * a[2] + (a[0] - a[1]) * a[3]:a[0] * a[2]);
}


Measured memory_bytes: 256
import sys
input = sys.stdin.readline

N, M = map(int, input().split())

c = 0
if N * 2 <= M:
    c = N
    M = M - N * 2
elif N != 0:
    c = int(M / 2)
    M = M - c * 2
    
print(c + int(M / 4))

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

#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define pb push_back

typedef long long ll;
typedef pair<int,int> pi;
typedef vector<int> vi;

bool br[100010];

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

	cout<<n%k<<endl;

}


Measured memory_bytes: 256
// Author : Mohamed Sameh
#include <bits/stdc++.h>
#define pb push_back
#define f first
#define s second
#define all(v) v.begin(),v.end()
#define rall(v) v.rbegin(),v.rend()
#define SZ(a) (int)a.size()
#define Flush fflush(stdout);
typedef long long ll ;
using namespace std ;
int n;
double a[3000];
double dp[3000][3000];
double solve (int i =0 , int hd = 0 )
{
    if (i == n )
    {
        if (hd > n - hd )
            return 1;
        return 0 ;
    }
    double &ret = dp[i][hd];
    if (ret == ret )return ret ;
    ret = a[i] * solve(i+1,hd+1) + (1.0 - a[i])*solve(i+1,hd);
    return ret ;
}
int main()
{
    memset(dp , -1 ,sizeof dp);
    cin >> n ;
    for (int i = 0 ; i < n ;i++)
        cin >> a[i];
    printf ("%.9f\n" , solve());

}





Measured memory_bytes: 70784
object Main extends App{
    val Array(n,m,c) = scala.io.StdIn.readLine.split(" ").map(_.toInt)
    val b = scala.io.StdIn.readLine.split(" ").map(_.toInt)
    val a = for(_ <- 1 to n) yield scala.io.StdIn.readLine.split(" ").map(_.toInt)
    val munya = (for(count1 <- a) yield {
        (for(count2 <- 0 until m) yield {
            count1(count2) * b(count2)
        }).sum
    }).map(_ + c)
    println(munya.count(0 < _))
}


Measured memory_bytes: 27188
#include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <complex>
#include <cstring>
#include <cstdlib>
#include <string>
#include <cmath>
#include <queue>
using namespace std;

#define REP(i,n) for(int i=0;i<(int)n;++i)
#define FOR(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)
#define ALL(c) (c).begin(), (c).end()

const double EPS = 1e-8;
const double INF = 1e12;

typedef complex<double> P;
double dot(const P& a, const P& b) {
  return real(conj(a)*b);
}
struct L : public vector<P> {
  L(const P &a, const P &b) {
    push_back(a); push_back(b);
  }
};
struct C {
  P p; double r;
  C(const P &p, double r) : p(p), r(r) { }
};
bool intersectSC2(const L &s, const C &c) { // î{IÈ­zÍãÆ¯¶¾ªA]vÈÖðìéKvªÈ­Èé
  if (abs(s[0]-c.p) < c.r && abs(s[1]-c.p) < c.r) return false; // ~ÌÉüéÌÍð·Æ·é©µÈ¢©B
  P vc = c.p-s[0], vs = s[1]-s[0];
  if (dot(vc,vs) < 0) // n_æèàO 
    return abs(vc) < c.r + EPS;
  if (dot(c.p-s[1],-vs) < 0) // I_æèàO
    return abs(c.p-s[1]) < c.r + EPS;
  return norm(vc)-dot(vc,vs)/norm(vs)*dot(vc,vs) < c.r*c.r + EPS;
}

int main() {
  int n;
  while(cin >> n, n) {
    vector<C> v;
    REP(i,n) {
      double x,y,r;
      cin >> x >> y >> r;
      v.push_back(C(P(x,y),r));
    }
    int m;
    cin >> m;
    while(m--) {
      int tx,ty,sx,sy;
      cin >> tx >>ty >> sx >> sy;
      L l(P(tx,ty), P(sx,sy));
      bool danger = true;
      FOR(it, v) {
        if (intersectSC2(l, *it)) {
          cout << "Safe" << endl;
          danger = false;
          break;
        }
      }
      if (danger) {
        cout << "Danger" << endl;
      }
    }
  }
}

Measured memory_bytes: 0
while True:
    n, x = [int(s) for s in input().split()]
    if n == x == 0:
        break
    
    total = 0
    for i in range(1, n - 1):
        for j in range(i + 1, n):
            for k in range(j + 1, n + 1):
                st = i + j + k
                if x < st:
                    break
                if st == x:
                    total += 1
    print(total)

Measured memory_bytes: 7716
import java.io.IOException;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.stream.Collectors;
import java.util.stream.IntStream;

public class Main {

    public static void main(String[] args) throws IOException {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

        int cnt = -9;
        int range = -9;
        String line;
        List<Integer> inputs = new ArrayList<>();
        while ((line = br.readLine().trim()) != null && !line.isEmpty() && !"0 0".equals(line)) {
            if(cnt < 0) {
                List<Integer> list = Arrays.stream(line.split(" ")).map(Integer::valueOf).collect(Collectors.toList());
                cnt = list.get(0);
                range = list.get(1);
            } else {
                inputs.add(Integer.valueOf(line));
                if(--cnt==0) {
                    output(inputs, range);
                    inputs.clear();
                    cnt = -9;
                }
            }
        }
    }

    public static void output(List<Integer> list, int range) {
        int sum = IntStream.range(0,range).map(j->list.get(j)).sum();
        int max = sum;
        for(int i=range; i<list.size(); i++) {
            sum = sum - list.get(i-range) + list.get(i);
            if(max<sum) max=sum;
        }
        System.out.println(max);
    }
}

Measured memory_bytes: 41856
def cmb(n, r, mod):
    if ( r<0 or r>n ):
        return 0
    r = min(r, n-r)
    return g1[n] * g2[r] * g2[n-r] % mod

mod = 10**9+7 #出力の制限
N = 10**6
g1 = [1, 1] # 元テーブル
g2 = [1, 1] #逆元テーブル
inverse = [0, 1] #逆元テーブル計算用テーブル

for i in range( 2, N + 1 ):
    g1.append( ( g1[-1] * i ) % mod )
    inverse.append( ( -inverse[mod % i] * (mod//i) ) % mod )
    g2.append( (g2[-1] * inverse[-1]) % mod )

x,y = map(int,input().split())
mod = 10**9 + 7
if (x + y) % 3 > 0:
    print(0)
else:
    n = (x + y) //3
    r = x - n 
    print(cmb(n,r,mod))


Measured memory_bytes: 127816
#include <stdio.h>
int main(void){
    // Your code here!
    int n,m;
    long int k;
    scanf("%d %d %ld",&n,&m,&k);
    
    long int a[200000]={};
    long int A[200001]={};
    for(int i=0;i<n;i++){
        scanf("%ld",&a[i]);
        if(i==0){
            A[i]=0;
        }
        A[i+1]=A[i]+a[i];
        
    }
    
    long int b[200000]={};
    long int B[200001]={};
    for(int i=0;i<m;i++){
        scanf("%ld",&b[i]);
        if(i==0){
            B[i]=0;
        }
        B[i+1]=B[i]+b[i];
        
    }
    
    int p=0;
    int mo=m;
    for(int i=0;i<=n;i++){
        if(A[i]>k)break;
        
        for(int j=mo;j>=0;j--){
            if(A[i]+B[j]<=k){
                if(i+j>p)p=i+j;
                mo=j;
                break;
            }
        }
        
    }
    
    
    printf("%d",p);
}

Measured memory_bytes: 7936
#include <iostream>
using namespace std;
typedef long long llong;
llong w[100010];
int main() {
    int n,k,count = 1,num = 1;
    llong sum = 0,max = 0;
    cin >> n >> k;
    for (int i = 0; i < n; i++) {
        cin >> w[i];
        sum += w[i];
    }

    llong ans = sum / k + (sum % k == 0?0:1);

    while (count <= n) {
        count = 1,num = 1,max = 0;
        for (int i = 0; i < n; i++) {
            if (w[i] > ans) {
                ans = w[i] - 1;
                break;
            }else {
                max += w[i];
                if (max > ans) {
                    max = w[i] ;
                    num++;
                }
                if (num > k) {
                    break;
                }
                count++;
            }
        }
        if (count != n+1) {
            ans++;
        }
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 3876
#include<stdio.h>
#include<cmath>
#include<math.h>
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<complex>
#include<queue>
#include<set>
#include<utility>
#include<iomanip>
#include<limits>
#include<thread>
#include<map>
#include<stack>
#include<numeric>
#include<cassert>
#include<random>
#include<chrono>
#include<unordered_set>
#include<unordered_map>
#include<fstream>
#include<list>
#include<functional>
#include<bitset>
#include<tuple>

using namespace std;

template <class... A>
void prints() { cout << "\n"; }
template <class... A>
void prints_rest() { cout << "\n"; }
template <class T, class... A>
void prints_rest(const T &first, const A &... rest) { cout << " " << first; prints_rest(rest...); }
template <class T, class... A>
void prints(const T &first, const A &... rest) { cout << first; prints_rest(rest...); }

#define rep(i,n) for(int i=0; i<n; i++)
#define rep1(i,n) for(int i=1; i<n+1; i++)
#define repr(i,n) for(int i=n-1; i>=0; i--)
#define repr1(i,n) for(int i=n; i>0; i--)
#define souatari rep1(i,n-1)rep(j,i)
#define souatari1 for(int i=2; i<n+1; i++)rep1(j,i-1)
#define mp make_pair
#define F first
#define S second
#define elif else if

typedef long long ll;
typedef vector<int>  vi;
typedef vector<vi>  vvi;
typedef vector<ll> vll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef long double D;


const ll llinf =  numeric_limits<ll>::max();
const ll _llinf = numeric_limits<ll>::lowest();
const int inf = numeric_limits<int>::max();
const int _inf = numeric_limits<int>::lowest();
const double dinf = numeric_limits<double>::infinity();
const ll MOD = 1000000007;
const ll BIG = 10000000000000000;

vector<pii> e[100005];
int color[100005];


int main(){ 
    int n;
    cin >> n;
    rep(i,n-1){
        int a,b;
        cin >> a >> b;
        e[a].push_back(mp(b,i));
        e[b].push_back(mp(a,i));
    }

    int maxcount = 0;
    int place = 0;
    rep(i,n){
        if(maxcount<e[i].size()){
            maxcount = e[i].size();
            place = i;
        }
    }
    queue<array<int,3>> q;

    int c = 0;
    rep(i,maxcount){
        c++;
        q.push({e[place][i].F,place,c});
        color[e[place][i].S] = c;
    }

    while(!q.empty()){
        array<int,3> tmp = q.front();
        //prints(tmp[0],tmp[1],tmp[2]);
        q.pop();
        c = 0;
        rep(i,e[tmp[0]].size()){
            if(e[tmp[0]][i].F == tmp[1]) continue;
            c++;
            if(tmp[2] == c) c++;
            
            q.push({e[tmp[0]][i].F,tmp[0],c});
            color[e[tmp[0]][i].S] = c;
            
        }
        
    }
    prints(maxcount);
    rep(i,n-1){
        prints(color[i]);
    }


    return 0;

}

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

using namespace std;

int main() {
    int N;
    cin >> N;

    string S;
    cin >> S;

    string s = S;
    string::size_type pos;
    while ((pos = s.find("()")) != string::npos) {
        s.replace(pos, 2, "");
    }

    string::size_type kets = s.find('(');
    if (kets == string::npos)
        kets = s.size();
    string::size_type  bras = s.size() - kets;

    cout << string(kets, '(') + S + string(bras, ')') << endl;

    return 0;
}


Measured memory_bytes: 384
#include "bits/stdc++.h"
using namespace std;
using ll = long long;
using vi = vector<int>;
using vb = vector<bool>;
using vvi = vector<vector<int>>;
using vll = vector<long long>;
using pii = pair<int, int>;
using pll = pair<long long, long long>;
using vpi = vector<pair<int, int>>;

#define F first
#define S second
#define pb push_back
#define sz(x) (int)x.size()
#define all(x) x.begin(), x.end()

#define FOR(i, a, b) for (int i = (a); i <= (b); ++i)
#define F0R(i, a) for (int i = 0; i < (a); ++i)
#define RFOR(i, a, b) for (int i = (a); i >= (b); --i)

const char nl = '\n';
const ll MOD = 1e9 + 7;
const ll INF = 1e18;

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

    int n, m; cin >> n >> m;
    F0R (i, m / 2) {
        cout << (1 + i) << " " << (m - i) << endl;
    }
    F0R (i, (m + 1) / 2) {
        cout << (m + 1 + i) << " " << (2 * m + 1 - i) << endl;
    }
    return 0;
}


Measured memory_bytes: 3628
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0; i<(n); i++)
#define FOR(i,a,n) for(int i=(a); i<(n); i++)
#define all(v) v.begin(), v.end()
using namespace std;
typedef long long ll;
const int INF = 1e9;
const int MOD = 1e9+7;

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

    string s; cin >> s;
    if ((s == "AAA") || (s == "BBB")) puts ("No");
    else puts("Yes");
}

Measured memory_bytes: 256
from sys import stdin, stdout

rl = lambda: stdin.readline()
rll = lambda: stdin.readline().split()
rli = lambda: map(int, stdin.readline().split())

INF, NINF = float('inf'), float('-inf')

def main():
	n, m, x = rli()
	A = []
	for _ in range(n):
		A.append(list(rli()))
	mask = 0
	for i in range(n):
		mask |= (1 << i)

	opt = INF

	def process(s):
		nonlocal opt
		i = 0
		cost = 0
		algs = [0 for _ in range(m)]
		while s:
			s, bit = divmod(s, 2)
			if bit:
				cost += A[i][0]
				for j in range(1, m+1):
					algs[j-1] += A[i][j]
			i += 1
		if all(skill >= x for skill in algs):
			opt = min(opt, cost)

	process(mask)
	s = mask
	while s > 0:
		process(s)
		s = (s-1) & mask

	print(opt if opt < INF else -1)
	stdout.close()

if __name__ == "__main__":
	main()

Measured memory_bytes: 69416
#include <iostream>
#include <algorithm>
#include <iomanip>
#include <vector>
#include <queue>
#include <set>
#include <map>

using namespace std;
typedef long long ll;

ll H[200000];

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout << setprecision(10) << fixed;
    int N, K;
    cin >> N >> K;
    for(int i = 0; i < N; i++) cin >> H[i];
    sort(H, H+N, greater<ll>());
    ll ans = 0;
    for(int i = K; i < N; i++) ans += H[i];
    cout << ans << endl;
}

Measured memory_bytes: 1792
s=input()
flg=0
if len(s)%2!=0:
        flg+=1
else:
    for i in range(0,len(s)-1,2):
        if s[i:i+2]!="hi":
            flg +=1
            break
        continue
if flg==0:
    print("Yes")
else:
    print("No")

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

const int N = 2e6;

main() {
	clog << "Ready\n";
	
	int s, f, k;
	cin >> s >> f >> k;
	
	int cnt = 0;

	for (int i = min(s, f); i >= 1; -- i) {
		if (s % i == 0 and f % i == 0)
			++cnt;
		if (cnt == k)
			return cout << i, 0;
	}

	
	cerr << '\n';

	return 0;
}


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

typedef pair<int, string> P;
bool comp(P a, P b){
	return a.first > b.first;
}

int main(){
	string s;
	int n, w, l, d, f = 0;
	while(cin >> n, n){
		if(f)cout << endl;f = 1;
		vector<P> v;
		for(int i = 0;i < n;i++){
			cin >> s >> w >> l >> d;
			int x = w*3 + d;
			v.push_back(P(x, s));
		}
		sort(v.begin(), v.end(), comp);
		for(int i = 0;i < n;i++){
			cout << v[i].second << "," << v[i].first << endl;
		}
	}
	return 0;
}

Measured memory_bytes: 3164
import Data.Bits
import Data.List
import Control.Monad
import qualified Data.Vector.Unboxed as V
import qualified Data.Vector.Unboxed.Mutable as VM
import Data.Array
import Data.Array.MArray
import Data.Array.ST
import Control.Monad.ST
import Data.Maybe (fromMaybe)
import qualified Data.ByteString.Lazy.Char8 as B
import Debug.Trace


main :: IO ()
main = do
  n <- getLine
  let l = length n
  (print :: Int -> IO ()) $ if l == 1 then read n else (+) (if odd l then (read n) - 10^(l-1) + 1 else 0) $ sum [10^(l'-1)*9 | l' <- [1,3..if odd l then l-2 else l-1]]


Measured memory_bytes: 508
#include <bits/stdc++.h>
using namespace std;
int main(){
        int n, k; cin >> n >> k;
        vector<long long int> v;
        for (int x = 0; x < n; ++x){
            long long int q; cin >> q;
            v.push_back(q);
        }
        sort(v.begin(), v.end());
        if (k >= v.size()){
            cout << 0 << endl;
            return 0;
        }
        long long int ans = 0;
        for (int x = 0; x < n-k; ++x){
            ans += v[x];
        }
        cout << ans << endl;
    return 0;
}



Measured memory_bytes: 5260
#include<iostream>
#include<vector>
#define MAX 100000
#define INF (1 << 21)
using namespace std;

struct card{
  int val;
  char c;
};

struct card a[MAX];
struct card b[MAX];

int n;

void merge(int left, int mid, int right){
  int n1 = mid -left;
  int n2 = right - mid;

  struct card r[MAX/2 + 5];
  struct card l[MAX/2 + 5];

  int i, j;
  
  for(i = 0; i < n1; i++) l[i] = a[left + i];
  for(i = 0; i < n2; i++) r[i] = a[mid + i];

  l[n1].val = INF;
  r[n2].val = INF;

  i = 0;
  j = 0;

  for(int k = left; k < right; k++){
    if(l[i].val <= r[j].val){
      a[k] = l[i++];
    }

    else a[k] = r[j++];

  }
}

void mergeSort(int left, int right){
  if(left+1 < right){
    int mid = (left + right) / 2;

    mergeSort(left, mid);
    mergeSort(mid, right);
    merge(left, mid, right);
  }
}

int partition(int p, int r){
  struct card x = b[r];
  struct card dummy;
  int i = p - 1;

  for(int j = p; j < r; j++){

    if(b[j].val <= x.val){
      i++;
      dummy = b[i];
      b[i] = b[j];
      b[j] = dummy;
    }
  }
    
    dummy = b[i+1];
    b[i+1] = b[r];
    b[r] = dummy;
  
  return i+1;
  
}

void quickSort(int p, int r){
  int q;

  if(p < r){
    q = partition(p, r);
    quickSort(p, q-1);
    quickSort(q+1, r);
  }
}

int main()
{
  int x;
  char s;
  bool flag = true;
  
  cin >> n;
  
  for(int i = 0; i < n; i++){
    cin >> s >> x;

    a[i].c = s;
    a[i].val = x;
    
    b[i].c = s;
    b[i].val = x;

  }

  mergeSort(0, n);
  quickSort(0, n-1);

  for(int i = 0; i < n; i++){
    if(a[i].c != b[i].c) flag = false;
  }

  if(flag) cout << "Stable" << endl;
  else cout << "Not stable" << endl;

  for(int i = 0; i < n; i++){
    cout << b[i].c << " " << b[i].val << endl;
  }

  return 0;

}



Measured memory_bytes: 5424
n,m = [int(x) for x in input().split()]
a=[]
b=[]
for i in range(n): a.append([int(x) for x in input().split()])
for j in range(m): b.append(int(input()))
for a_row in a:
    print(sum([x*y for x,y in zip(a_row,b)]))

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

#define fr first
#define sc second
#define pb push_back
#define mk make_pair

using namespace std;
const int N = 1e5 + 7;

int k, a;

vector<pair<int, int>>v;
pair<bool, int>u[N];
vector<int>g[N];
bool used[N], fl;
bool us[N];

void dfs(int vv)
{
    us[v[vv].sc] = 1;
    used[vv] = 1;
//    cout << v[vv].fr << " " << vv << endl;
    int l = vv;
    while (v[l].sc == v[vv].sc)
    {
        l--;
    }
    l++;
    int pos = l;

    for (int i = 0; i < g[vv].size(); i++)
    {
        int to = g[vv][i];

        if (!used[to])
           dfs(to);
    }
    if (v[vv].sc != 1){

        for (int j = pos; j < v.size(); j++)
        {
            if (v[j].sc != v[vv].sc)
                return;
            if (!used[j] && g[j].size() > 0)
                dfs(j);
        }

    }

}
main()
{
    int n, m;
    cin >> n >> m;
    for (int i = 1; i <= n; i++)
    {
        scanf("%d",&k);
        for (int j = 1; j <= k; j++)
        {
            scanf("%d",&a);
            v.pb(mk(a, i));
        }
    }

    for (int i = 0; i < v.size(); i++)
    {
        if (u[v[i].fr].fr && v[i].sc != v[u[v[i].fr].sc].sc)
        {
            g[u[v[i].fr].sc].pb(i);
            g[i].pb(u[v[i].fr].sc);
        }
        u[v[i].fr] = (mk(1, i));
    }

    for(int i = 0; i < v.size(); i++)
    {
        if (v[i].sc != 1)
        {
            break;
        }
        if (g[i].size() > 0 && !used[i]){
            dfs(i);
        }
        else {
            us[1] = 1;
            used[i] = 1;
        }
        if (i == 1)
        {
            for (int j = 1; j <= n; j++)
            {
                if (!us[j])fl = 1;
            }
            if (!fl)
            {
                cout << "YES";
                return 0;
            }
        }
    }

    for (int i = 1; i <= n; i++)
    {
        if (!us[i])
        {
            cout << "NO";
            return 0;
        }
    }
    cout << "YES";
}




Measured memory_bytes: 11380
X = int(input())
if 400 <= X < 600:
    print(8)
elif 600 <= X < 800:
    print(7)
elif 800 <= X < 1000:
    print(6)
elif 1000 <= X < 1200:
    print(5)
elif 1200 <= X < 1400:
    print(4)
elif 1400 <= X < 1600:
    print(3) 
elif 1600 <= X < 1800:
    print(2)
else:
    print(1)

Measured memory_bytes: 9164
#include<iostream>
#include<bits/stdc++.h>
#include<algorithm>
typedef long long int ll;
typedef unsigned long long int ull;
using namespace std;
# define my_sizeof(type) ((char *)(&type+1)-(char*)(&type)) 
#define fastio() ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define loop(i,a,b) for(ull i=a;i<b;i++)
#define test() ull t;cin>>t;while(t--)
#define pb push_back
#define mkp make_pair
#define nl cout<<endl
#define MOD 1000000007
#define trace(s,a) cout<<s<<a,nl
#define MAXN 100002


ll operate( ll* a, ll n, ll b, ll c, ll k){
	ll i = k;
	while(i<n && i<k+b && a[i]<c){
		a[i] = c;
		i++;
	}

	return i;
}

int main(){
	

    ll n,m;
    cin>>n>>m;

    ll a[n], s[n] = {0};
    for(ll i=0; i<n; i++){
    	cin>>a[i];
    }

    sort(a, a+n);

    

    pair< ll, ll > p[m];
    for(ll i=0; i<m; i++){
    	cin>>p[i].second>>p[i].first;
    }

    sort(p, p+m);

    ll k=0;
    for(ll i=m-1; i>=0; i--){
    	k = operate(a, n, p[i].second, p[i].first, k);
    	if(k == n)
    		break;
    }
    ll sum = 0;
    for(ll i=0; i<n; i++){
    	sum += a[i]; 
    }
    
    cout<<sum;

}

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



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

    ll n;
    cin>>n;
    ll a[n];
    for(int i=0;i<n;i++){
        cin>>a[i];
    }
    sort(a,a+n);
    ll ans = a[n-1];
    for(int i=1;i<n-1;i++){
        if(a[i]<=0) ans -= a[i];
        else ans += a[i];
    }
    ans -= a[0];
    cout << ans <<endl;
    ll now = a[n-1];
    for(int i=1;i<n-1;i++){
        if(a[i]<=0){
            cout << now <<" "<<a[i] << endl;
            now -= a[i];
        }
    }
    ll nx = a[0];
    for(int i=1;i<n-1;i++){
        if(a[i]>0){
            cout << nx <<" "<< a[i] << endl;
            nx -= a[i];
        }
    }

    cout << now << " " << nx <<endl;


    
}

Measured memory_bytes: 2688
import sys


def LI(): return [int(x) for x in sys.stdin.readline().split()]


def I(): return int(sys.stdin.readline())


# A
def A():
    s = input()
    if s == "Sunny":
        print("Cloudy")
    elif s == "Cloudy":
        print("Rainy")
    else:
        print("Sunny")
    return


# B
def B():
    return


# C
def C():
    return


# D
def D():
    return


# E
def E():
    return


# F
def F():
    return


# Unittest
def resolve():
    A()
    return


# Solve
if __name__ == "__main__":
    A()


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

//conversion
//------------------------------------------
inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}

//math
//-------------------------------------------
template<class T> inline T sqr(T x) {return x*x;}

//typedef
//------------------------------------------
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<bool> VB;
typedef vector<double> VD;
typedef vector<string> VS;
typedef vector<char> VC;
typedef pair<int, int> PII;
typedef long long LL;
typedef vector<LL> VLL;
typedef vector<VLL> VVLL;

//container util
//------------------------------------------
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define SQ(a) ((a)*(a))
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())
#define LB lower_bound
#define UB upper_bound

//repetition
//------------------------------------------
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)

//constant
//--------------------------------------------
const double EPS = 1e-10;
const double PI  = acos(-1.0);
const LL INF = 1e9;
const LL MOD = 1e9+7;

//other
//-------------------------------------------
#define chmin(x,y) x=min(x,y)
#define chmax(x,y) x=max(x,y)
#define FI first
#define SE second

int main() {
  int N;
  string S;
  cin >> N >> S;
  int sum = N;
  REP(i,N-1) {
    if(S.at(i) == S.at(i+1)) {
      sum--;
    }
  }
  cout << sum << endl;
  return 0;
}

Measured memory_bytes: 512
#include <stdio.h>

int main(void)
{
    int i, j, n, q, t, C, S[10000];

    C = 0;

    scanf("%d", &n);
    for (i = 0; i < n; i++)
        scanf("%d", S + i);
    
    scanf("%d", &q);
    for (i = 0; i < q; i++) {
        scanf("%d", &t);
        for (j = 0; j < n; j++)
            if (S[j] == t) {
                C++;
                break;
            }
    }

    printf("%d\n", C);
    return 0;
}


Measured memory_bytes: 2056
#include <iostream>
#include <cstring>
#include <algorithm>
#include <vector>
#include <string>
#include <math.h>
#include <iomanip>
#include <limits>
#include <list>
#include <queue>
#include <tuple>
#include <map>
#include <stack>
#include <set>
using namespace std;
#define MOD (long long int)(1e9+7)
#define ll long long int
#define rep(i,n) for(int i=0; i<(int)(n); i++)
#define reps(i,n) for(int i=1; i<=(int)(n); i++)
#define REP(i,n) for(int i=n-1; i>=0; i--)
#define REPS(i,n) for(int i=n; i>0; i--)
#define INF (int)(1123456789)
#define LINF (long long int)(112345678901234567)
#define chmax(a, b) a = (((a)<(b)) ? (b) : (a))
#define chmin(a, b) a = (((a)>(b)) ? (b) : (a))
#define all(v) v.begin(), v.end()

const int N = (int)3e5+3;

ll mpow(ll a, ll b){
	if(b==0) return 1;
	else if(b%2==0){ll memo = mpow(a,b/2); return memo*memo%MOD;}
	else return mpow(a,b-1) * a % MOD;
}
ll gcd(ll a, ll b){
	if(b==0) return a;
	else return gcd(b, a%b);
}
vector<ll> kaijo_memo;
ll kaijo(ll n){
	if(kaijo_memo.size() > n) return kaijo_memo[n];
	if(kaijo_memo.size() == 0) kaijo_memo.push_back(1);
	while(kaijo_memo.size() <= n) kaijo_memo.push_back(kaijo_memo[kaijo_memo.size()-1] * kaijo_memo.size() % MOD);
	return kaijo_memo[n];
}
ll nCr(ll n, ll r){
	if(n < r || r < 0) return 0;
	ll ret = 1;
	ret *= kaijo(n); ret %= MOD;
	ret *= mpow(kaijo(r), MOD-2); ret %= MOD;
	ret *= mpow(kaijo(n-r), MOD-2); ret %= MOD;
	return ret;
}

int main(void){
	int x;
	cin>>x;
	int ans = 1;
	for(int i=2; i<= sqrt(x) +2; i++){
		for(int j=2; pow(i,j) <= x; j++){
			if(pow(i,j) <= x){
				ans = max(ans, (int)pow(i,j));
			}
		}
	}
	cout<<ans<<endl;

	return 0;
}


Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
#define lp(i,n) for(int i=0; i<n ; ++i)
#define all(v) v.begin() , v.end()
#define sz(v) (int(v.size()))
typedef unsigned long long ul;
typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef vector<string> vs;
typedef vector<vector<int> > vii;
typedef pair<int, int> pii;
typedef vector<pii> vp;
int OO = 2e9;
const double eps = 1e-9 ;
const int N = 200;
int mx = -1e9 , mn = 1e9 ;
int arr[N] , arr2[N];

int main()
{
    string s; cin >> s;
    int a = 0 , b = 0 ;
    lp(i,s.size()){
        if(s[i] == '1')
            ++a;
        else
            ++b;
    }
    cout << min(a,b) * 2 << endl;


    return 0;
}


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

int main() {
  vector<int> A(3);
  rep(i, 0, 3) cin >> A[i];
  sort(A.begin(), A.end());
  cout << A[2] - A[0] << endl;
  return 0;
}


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

signed main()
{
    ios_base::sync_with_stdio(false); 
    cin.tie(NULL);
    cout.tie(NULL);
    //cout<<"I must do it...Yeahhh";
    
    int t=1;
    //cin>>t;
    while(t--)
    {
        int n;
        cin>>n;
        int sum=0;
        for(int i=1;i<=n;i++)
            for(int j=1;j<=n;j++)
                for(int k=1;k<=n;k++)
                    sum+=__gcd(i,__gcd(j,k));
        cout<<sum;
    }
    //cerr<<"[Execution : "<<(1.0*clock())/CLOCKS_PER_SEC<<"s]\n";
    return 0;
}

Measured memory_bytes: 3616
#include <vector>
#include <queue>
#include <algorithm>
#include <iostream>
#include <string>
#include <ctime>
#include <map>
#include <stack>
#include <sstream>
#include <set>
#include <cmath>
#include <functional>
#include <numeric>

using namespace std;

int main(void)
{
	int r, g, b;

	cin >> r >> g >> b;

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

	return 0;
}

Measured memory_bytes: 256
#include <iostream>

using namespace std;

int main()
{
	int a, b, c;
	cin >> a >> b >> c;

	int count5 = 0;
	int count7 = 0;

	if(a == 5) {
		++count5;
	} else if(a == 7) {
		++count7;
	}

	if(b == 5) {
		++count5;
	} else if(b == 7) {
		++count7;
	}

	if(c == 5) {
		++count5;
	} else if(c == 7) {
		++count7;
	}

	if(count5 == 2 && count7 == 1) {
		cout << "YES" << endl;
		return 0;
	}

	cout << "NO" << endl;

	return 0;
}


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

#define sz(v)           ((int)((v).size()))
#define clr(v, d)       memset(v, d, sizeof(v))
#define rep(i, v)       for(int i=0; i<sz(v); ++i)
#define lp(i, n)        for(int i=0; i<(int)(n); ++i)
#define lpi(i, j, n)    for(int i=(j); i<(int)(n); ++i)
#define lpd(i, j, n)    for(int i=(j); i>=(int)(n); --i)
#define INF             1000000000

typedef long long ll;
typedef pair<int, int> ii;
typedef vector<ii> vii;
typedef vector<int> vi;

int main() {
	int a, b, digits = 0, res = 0;
	cin >> a;
	b = a;
	while (b) {
		++digits;
		b /= 10;
	}

	for (int i = 1; i < digits; i += 2) {
		res += (power(10, i) - power(10, i - 1));
	}
	if (digits % 2) {
		res += (a + 1 - power(10, digits - 1));
	}
	cout << res;
	return 0;
}

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

int main(void){
    int n;
    cin >> n;
    
    vector<vector<int>> a(2,vector<int>(n));
    
    for (int i = 0; i < 2; i++){
        for (int j = 0; j < n; j++) cin >> a[i][j];
    
    }
    
    /*
    dp[i][j] : 上からi行目, 左からj列目(0-index)にいるときの
    回収できるアメの最大値を表す
    */
    vector<vector<int>> dp(2,vector<int>(n));
    
    dp[0][0] = a[0][0];
    
    for (int i = 1; i < n; i++) dp[0][i] = dp[0][i-1] + a[0][i];
    
    dp[1][0] = dp[0][0] + a[1][0];
    
    for (int i = 1; i < n; i++) dp[1][i] = max(dp[0][i], dp[1][i-1]) + a[1][i];
    
    cout << dp[1][n-1] << endl;
}


Measured memory_bytes: 256
n = gets.to_i
s = gets.chomp

count = 0
n.times do |i|
  break if s[i+1].nil?
  tmp_count = 0
  left = s[0..i]
  right = s[i+1..-1]
  left.chars.uniq.each do |c|
    tmp_count += 1 if right.include?(c)
  end
  count = [count, tmp_count].max
end

puts count

Measured memory_bytes: 1788
#include <algorithm>
#include <iostream>
#include <string>
#include <vector>
using namespace std;
typedef long long ll;
#define rep(i, n) for(int i = 0; i < (n); ++i)
ll gcd(ll a, ll b) {
  if(b == 0) return a;
  return gcd(b, a % b);
}
ll lcm(ll a, ll b) { return a * b / gcd(a, b); }

int main(void) {
  ll a, b, c, d;
  cin >> a >> b >> c >> d;
  auto f = [&](ll x) {
    return x - (x / c + x / d - x / (lcm(c, d)));
  };
  cout << f(b) - f(a - 1) << endl;
  return 0;
}

Measured memory_bytes: 256
#include <algorithm>
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(), (x).end()
#define ll long long
#define INF 1000000000000000000

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

    ll H;
    cin >> H;
    ll sum = 0, cnt = 0;
    while (H / 2 > 0) {
        H /= 2;
        cnt++;
        sum += (ll)pow(2, cnt);
    }
    sum += 1;

    cout << sum << endl;
}

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

int main() {
  string s;
  cin >> s;
  
  if(s.at(2)==s.at(3) && s.at(4)==s.at(5)){
    cout << "Yes" << endl;
  }
  else{
    cout << "No" << endl;
  }
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
long long x,y,a,b,c,aa[101010],bb[101010],cc[101010],ans;
int main()
{
	cin>>x>>y>>a>>b>>c;
	for(int i=1;i<=a;i++)
	{
		cin>>aa[i];
	}
	for(int i=1;i<=b;i++)
	{
		cin>>bb[i];
	}
	for(int i=1;i<=c;i++)
	{
		cin>>cc[i];
	}
	sort(aa+1,aa+a+1);
	sort(bb+1,bb+b+1);
	sort(cc+1,cc+c+1);
	reverse(aa+1,aa+a+1);
	reverse(bb+1,bb+b+1);
	reverse(cc+1,cc+c+1);
	aa[0]=1e18;
	bb[0]=1e18;
	for(int i=1;i<=x;i++)
	{
		ans+=aa[i];
	}
	for(int i=1;i<=y;i++)
	{
		ans+=bb[i];
	}
	int p1=x,p2=y,p3=1;
	while(p3<=c && (p1>=1 || p2>=1))
	{
		long long mn=aa[p1],w=0;
		if(bb[p2]<mn)
		{
			mn=bb[p2];
			w=1;
		}
		if(mn>=cc[p3])
		{
			break;
		}
		if(w==0)
		{
			ans-=aa[p1];
			ans+=cc[p3];
			p1--;
		}
		else
		{
			ans-=bb[p2];
			ans+=cc[p3];
			p2--;
		}
		p3++;
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 2560
from collections import Counter

import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
N = int(readline())
S = read().split()

res = []
c = Counter(S)
max_num = c.most_common(1)[0][1]
for i, j in list(c.items()):
    if j == max_num:
        res.append(i)
        
res.sort()

        
print('\n'.join(list(map(lambda x:x.decode(), res))))


Measured memory_bytes: 43256
#include <iostream>
#include <iomanip>
#include <sstream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <climits>
#include <cfloat>
#include <vector>
#include <string>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <algorithm>
#include <functional>
#include <utility>
#include <numeric>
#include <iterator>

using namespace std;

typedef long long LL;
typedef unsigned long long ULL;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int,int> PII;
typedef vector<PII> VPII;
typedef istringstream ISS;
typedef ostringstream OSS;

#define REP( i, m, n ) for ( int i = (int)( m ); i < (int)( n ); ++i )
#define FOR( v, c ) for ( auto &v : c )
#define EACH( it, c ) for ( auto it = c.begin(); it != c.end(); ++it )
#define ALL( c ) (c).begin(), (c).end()
#define DRANGE( c, p ) (c).begin(), (c).begin() + p, (c).end()

#define PB( n ) push_back( n )
#define MP( a, b ) make_pair( ( a ), ( b ) )
#define EXIST( c, e ) ( (c).find( e ) != (c).end() )

#define fst first
#define snd second

#define DUMP( x ) cerr << #x << " = " << ( x ) << endl
#define DEBUG( x ) cerr << __FILE__ << ":" << __LINE__ << ": " << #x << " = " << ( x ) << endl

const int INF = INT_MAX / 4;

struct Edge
{
	int to, dist, emer;

	Edge( int t, int d, int e ) : to( t ), dist( d ), emer( e )
	{
		return;
	}
};

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

	for ( int n, m, l; cin >> n >> m >> l, n | m | l; )
	{
		vector< vector<Edge> > G( n );
		REP( i, 0, m )
		{
			int a, b, d, e;
			cin >> a >> b >> d >> e;
			a--;
			b--;

			G[a].PB( Edge( b, d, e ) );
			G[b].PB( Edge( a, d, e ) );
		}

		VVI costs( n, VI( l + 1, INF ) );
		costs[0][l] = 0;

		priority_queue< PII, VPII, greater<PII> > que;
		que.push( MP( 0, l ) );
		// ( cost, v * 1000 + money )

		while ( !que.empty() )
		{
			int c = que.top().fst;
			int v = que.top().snd / 1000;
			int money = que.top().snd % 1000;
			que.pop();

			if ( costs[v][ money ] < c )
			{
				continue;
			}

			FOR( e, G[v] )
			{
				if ( costs[v][ money ] + e.emer < costs[ e.to ][ money ] )
				{
					costs[ e.to ][ money ] = costs[v][ money ] + e.emer;
					que.push( MP( costs[v][ money ] + e.emer, e.to * 1000 + money ) );
				}
				if ( 0 <= money - e.dist && costs[v][ money ] < costs[ e.to ][ money - e.dist ] )
				{
					costs[ e.to ][ money - e.dist ] = costs[v][ money ];
					que.push( MP( costs[v][ money ], e.to * 1000 + money - e.dist ) );
				}
			}
		}

		cout << *min_element( ALL( costs.back() ) ) << endl;
	}

	return 0;
}

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

#define SKYLAGS UNSTOPPABLE
#define pb push_back
#define F first
#define S second
#define ALL(a) (a).begin(),(a).end()
#define SKY ios::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define int long long int

void solve()
{
    int n,k;
    cin>>n>>k;
    int a[n];
    for(int i=0;i<n;i++)
        cin>>a[i];
    
    int dp[n];
    
    dp[1]=abs(a[1]-a[0]);
    dp[0]=0;
    for(int i=2;i<n;i++)
    {
        dp[i]=LLONG_MAX;
        int allowed=0;
        for(int j=i-1;j>=0 and allowed<k ;j--,allowed++)
        {
            //allowed++;
        dp[i]=min(dp[i],dp[j]+abs(a[j]-a[i]));
        }
    }
    cout<<dp[n-1]<<"\n";
}

int32_t main()
{
    int T=1;
    //cin>>T;
    for(int i = 1 ; i <= T ; i++)
        solve();
    return 0;
}


Measured memory_bytes: 5144
#include <bits/stdc++.h>
using namespace std;
typedef pair<long long, long long> P;
#define override_rep(i, l, r, mes, ...) mes
#define rep1(i, n) for (int i = 0; i < n; i++)
#define rep2(i, l, r) for (int i = l; i < r; i++)
#define rep(...) override_rep(__VA_ARGS__, rep2, rep1)(__VA_ARGS__)
#define int long long
template<typename T, typename U>
istream& operator>>(istream& in, pair<T, U>& p) {
	in >> p.first >> p.second;
	return in;
}

signed main(signed argc, char* argv[]) {
	cin.tie(nullptr);
	ios::sync_with_stdio(false);
	const int MOD = 1e9 + 7;
	int h;
	cin>>h;
	int cnt=1,ans=0;
	while(h>0){
	    ans+=cnt;
	    cnt*=2;
	    h/=2;
	}
	cout<<ans<<endl;
}

Measured memory_bytes: 256
#include "bits/stdc++.h"
#include<unordered_map>
#include<unordered_set>
#pragma warning(disable:4996)
using namespace std;
using ld = long double;
template<class T>
using Table = vector<vector<T>>;


int M, N;
vector<string>sts;

int memo[1 << 12][128];

int getans(const vector<int>vs, bitset<11>used) {
	
	if (memo[used.to_ulong()][vs[0]] != -1)return memo[used.to_ulong()][vs[0]];
	if (vs.size() == 1){
		return memo[used.to_ulong()][vs[0]] = 0;
	}
	else {
		int ans = 11;
		for (int ask = 0; ask < M; ++ask) {
			if (!used[ask]) {
				vector<int>yess, nos;
				for (const auto v : vs) {
					if (sts[v][ask]=='1')yess.push_back(v);
					else nos.push_back(v);
				}
				if (nos.empty() || yess.empty())continue;
				used[ask] = true;
				ans = min(ans, 1+max(getans(yess, used), getans(nos, used)));
				used[ask] = false;
			}
		}
		return memo[used.to_ulong()][vs[0]] = ans;
	}

}
int main() {
	while (1) {
		for (int i = 0; i < (1 << 11); ++i) {
			for (int j = 0; j < 128; ++j) {
				memo[i][j] = -1;
			}
		}
		cin >> M >> N;
		if (!M)break;
		sts.clear();
		for (int i = 0; i < N; ++i) {
			string st; cin >> st;
			sts.push_back(st);
		}
		vector<int>a(N);
		iota(a.begin(), a.end(), 0);
		int aans = getans(a, bitset<11>(0));
		cout << aans << endl;
	}
	return 0;
}

Measured memory_bytes: 4088
#include <cmath>
#include <vector>
#include <iostream>
#include <limits>
#include <iostream>
#include <vector>
#include <cassert>
#include <complex>
#include <cstdio>
#include <cstring>
#include <map>
#include <cmath>
#include <set>
#include <algorithm>
#include <queue>
 
using namespace std;
typedef long long Long;
typedef pair<int,int> PII;

int N,M;
int ei,ej;
string MAT[105];
int H[105][105];
int getH(int i, int j1, int j2){
	if(j2 < j1) return 0;
	return H[i][j2] - (j1==0?0:H[i][j1-1]);
}
int V[105][105];
int getV(int j, int i1, int i2){
	if(i2 < i1)return 0;
	return V[i2][j] - (i1==0?0:V[i1-1][j]);
}
short memo[101][101][101][101];
int dp(int l,int u, int r,int d){
	int LVL = (N+M) - l - u - r - d;
	if(memo[l][u][r][d] != -1)return memo[l][u][r][d];
	
	int w = 0;
	
	// incrrement l
	if(l > 0){
		int dt = 0;
		int i1 = max(d,ei-u), i2 = min(N-1-u, ei+d);
		if(r <= ej-l)dt = getV(ej-l,i1,i2);
		int t = dp(l-1,u,r,d);
		w = max(w, t + dt);
	}

	// increment u
	if(u > 0){
		int dt = 0;
		int j1 = max(r,ej-l), j2 = min(M-1-l, ej+r);
		if(d <= ei-u)dt = getH(ei-u,j1,j2);
		w = max(w, dp(l,u-1,r,d) + dt);
	}

	// increment u
	if(r > 0){
		int dt = 0;
		int i1 = max(d,ei-u), i2 = min(N-1-u, ei+d);
		if(ej+r <= M-1-l)dt = getV(ej+r,i1,i2);
		w = max(w, dp(l,u,r-1,d) + dt);
	}

	// increment u
	if(d > 0){
		int dt = 0;
		int j1 = max(r,ej-l), j2 = min(M-1-l, ej+r);
		if(ei+d <= N-1-u)dt = getH(ei+d,j1,j2);
		w = max(w, dp(l,u,r,d-1) + dt);
	}
	

//	cout << string(3*LVL,' ') << l << u << r << d << ": " << w << endl;
	return memo[l][u][r][d] = w;
}

int main(){
	cin >> N >> M;
	for (int i = 0; i < N; ++i) {
		cin >> MAT[i];
		int h = 0;
		for (int j = 0; j < M; ++j) {
			int n = MAT[i][j] == 'o';
			h += n;
			H[i][j] = h;
			if(MAT[i][j] == 'E'){
				ei = i, ej = j;
			}
			if(i == 0){
				V[i][j] = n;
			}else{
				V[i][j] = V[i-1][j] + n;
			}
		}
	}
	memset(memo,-1,sizeof(memo));
	cout << dp(ej,ei,M-1-ej,N-1-ei) << endl;
	
}
 
 


Measured memory_bytes: 203648
//
//  main.cpp
//  A
//
//  Created by Sultan.
//  Copyright © 2017 Sultan. All rights reserved.
//
//  CF Handle : 2017_Scayre_TBIL_777
//
//  ARSEN TOKSYN ZVER UUUU!!!!
//

#include <map>
#include <set>
#include <list>
#include <cmath>
#include <ctime>
#include <deque>
#include <queue>
#include <stack>
#include <string>
#include <bitset>
#include <cstdio>
#include <limits>
#include <vector>
#include <climits>
#include <cstring>
#include <cstdlib>
#include <fstream>
#include <numeric>
#include <sstream>
#include <cassert>
#include <iomanip>
#include <iostream>
#include <algorithm>
#include <unordered_set>
#include <unordered_map>

#define ll long long
#define ull unsigned ll
#define ioi exit(0);

#define f first
#define s second

#define inf 1e9 + 7;

#define NFS ios_base :: sync_with_stdio(0), cin.tie(0), cout.tie(0);

#define mp make_pair

#define lb(x) lower_bound(x)
#define ub(x) upper_bound(x)

#define pb(x) push_back(x)
#define ppb(x) pop_back(x)

#define endl "\n"

#define in(x) insert(x)

#define rep(x,y,z) for(int x=y;x<=z;x++)
#define per(x,y,z) for(int x=y;x>=z;x--)

#define all(x) x.begin(),x.end()

using namespace std;

ll n,m;

char a[100][100];

int main(){
    
    NFS
    
    cin >> n >> m;
    
    for(int i=1;i<=n;i++){
    	for(int j=1;j<=m;j++){
    		cin >> a[i][j];
    	}
    }
    
    for(int i=1;i<=n;i++){
    	for(int j=1;j<=m;j++){
    		ll cnt=0;
    		if(a[i][j]=='.'){
    			if(a[i][j-1]=='#'){
    				cnt++;
    			}
    			if(a[i][j+1]=='#'){
    				cnt++;
    			}
    			if(a[i-1][j]=='#'){
    				cnt++;
    			}
    			if(a[i+1][j]=='#'){
    				cnt++;
    			}
    			if(a[i-1][j-1]=='#'){
    				cnt++;
    			}
    			if(a[i-1][j+1]=='#'){
    				cnt++;
    			}
    			if(a[i+1][j-1]=='#'){
    				cnt++;
    			}
    			if(a[i+1][j+1]=='#'){
    				cnt++;
    			}
    			a[i][j]='0'+cnt;
    		}
    	}
    }
    
    for(int i=1;i<=n;i++){
    	for(int j=1;j<=m;j++){
    		cout << a[i][j];
    	}
    	cout << endl;
    }
    
    ioi
}


Measured memory_bytes: 256