akhauriyash/Code-Regression huggingface dataset:
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for (int i = 0;i < (int)(n);i++)
using ll = long long;
const ll MOD=1000000007;
//const ll MOD=998244353;
const long long INF = 1LL << 60;
const double pi=acos(-1.0);

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



int main()
{
  string S; cin>>S;
  ll ans=0;
  ll N=S.size();
  rep(i,N){
    ans+=S[i]-'0';
    ans%=9;
  }
  
  if(ans==0) cout<<"Yes"<<endl;
  else cout<<"No"<<endl;
  
  return 0;
}

Measured memory_bytes: 3708
#include <iostream>
#include <cstdio>
#include <cmath>
#include <ctime>
#include <cstdlib>
#include <cassert>
#include <vector>
#include <list>
#include <stack>
#include <queue>
#include <deque>
#include <map>
#include <set>
#include <bitset>
#include <string>
#include <algorithm>
#include <utility>
#define llint long long
#define inf 1e18
#define rep(x, s, t) for(llint (x) = (s); (x) < (t); (x)++)
#define Rep(x, s, t) for(llint (x) = (s); (x) <= (t); (x)++)
#define chmin(x, y) (x) = min((x), (y))
#define chmax(x, y) (x) = max((x), (y))

using namespace std;
typedef pair<llint, llint> P;

llint n;
llint dp[200005], pop[200005];
llint ans[200005];
string s;

int main(void)
{
	ios::sync_with_stdio(0);
	cin.tie(0);
	
	cin >> n;
	cin >> s;
	reverse(s.begin(), s.end());
	
	llint spop = 0;
	for(int i = 0; i < s.size(); i++){
		if(s[i] == '1') spop++;
	}
	
	llint sum1 = 0, sum2 = 0, mul1 = 1, mul2 = 1, mod1 = spop+1, mod2 = spop-1;
	if(mod1 > 0){
		for(int i = 0; i < s.size(); i++){
			if(s[i] == '1') sum1 += mul1, sum1 %= mod1;
			mul1 *= 2, mul1 %= mod1;
		}
	}
	
	if(mod2 > 0){
		for(int i = 0; i < s.size(); i++){
			if(s[i] == '1') sum2 += mul2, sum2 %= mod2;
			mul2 *= 2, mul2 %= mod2;
		}
	}
	
	for(int i = 1; i < 200005; i++) pop[i] = pop[i&(i-1)] + 1;
	for(int i = 1; i < 200005; i++) dp[i] = dp[i%pop[i]] + 1;
	
	//cout << sum1 << " " << sum2 << endl;
	//cout << mod1 << " " << mod2 << endl;
	
	mul1 = 1, mul2 = 1;
	for(int i = 0; i < n; i++){
		if(s[i] == '0'){
			if(spop == 0){
				ans[i] = 1;
				continue;
			}
			llint tmp = (sum1 + mul1) % mod1;
			ans[i] = dp[tmp] + 1;
		}
		else{
			if(spop == 1){
				ans[i] = 0;
				continue;
			}
			llint tmp = (sum2 + mod2 - mul2) % mod2;
			//cout << i << " " << tmp << " " << mod2 << endl;
			ans[i] = dp[tmp] + 1;
		}
		if(mod1 > 0) mul1 *= 2, mul1 %= mod1;
		if(mod2 > 0) mul2 *= 2, mul2 %= mod2;
	}
	
	for(int i = n-1; i >= 0; i--) cout << ans[i] << endl;
	
	return 0;
}

Measured memory_bytes: 8452
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.PrintStream;
import java.util.HashMap;
import java.util.Map;
import java.util.Scanner;

public class Main {
    public static final Scanner in = new Scanner(new BufferedReader(new InputStreamReader(System.in)));
    public static final PrintStream out = System.out;

    public static void main(String[] args) {
        int N = in.nextInt();
        int[] H = new int[N];
        for (int i = 0; i < N; i++) {
            H[i] = in.nextInt();
        }

        int step = 0;
        for (int i : H) {
            if (i < step) {
                out.println("No");
                return;
            } else if (i <= step + 1) {
                continue;
            } else {
                step = i - 1;
            }
        }
        out.println("Yes");
    }
}


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

struct Ps{
  int r,c;
  Ps():r(0),c(0){}
  Ps(int r,int c):r(r),c(c){}
  Ps operator+(const Ps&p)const
  { return Ps(r+p.r,c+p.c);  }
  friend istream& operator>>(istream&is,Ps&p)
  {is >> p.r >> p.c; return is;  }
};

int main(){
  int h,w; cin >> h >> w;
  Ps s,g; cin >> s >> g;
  s = s+Ps(-1,-1);
  g = g+Ps(-1,-1);
  string mz[1000];
  for(int i = 0; i < h; ++i)cin >> mz[i];
  optional<int> distance[1000][1000];
  deque<pair<Ps,int>> dq;
  dq.emplace_front(s,0);
  while(!dq.empty()){
    auto [ps,di] = dq.front();
    dq.pop_front();
    if(distance[ps.r][ps.c])continue;
    distance[ps.r][ps.c] = di;
    static int mr[] = {0,0,1,-1};
    static int mc[] = {1,-1,0,0};
    for(int i = 0; i < 4; ++i){
      Ps nps = ps + Ps(mr[i],mc[i]);
      if(nps.r < 0 || nps.c < 0 || nps.r >= h || nps.c >= w)continue;
      if(mz[nps.r][nps.c] == '#')continue;
      if(distance[nps.r][nps.c])continue;
      dq.emplace_front(nps,di);      
    }
    for(int i = -2; i <= 2; ++i){
      for(int j = -2; j <= 2; ++j){
	Ps nps = ps + Ps(i,j);

	if(nps.r < 0 || nps.c < 0 || nps.r >= h || nps.c >= w)continue;
	if(mz[nps.r][nps.c] == '#')continue;
	if(distance[nps.r][nps.c])continue;
	dq.emplace_back(nps,di+1);
      }
    }
  }
  cout << (distance[g.r][g.c] ? distance[g.r][g.c].value() : -1) << endl;
}


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

int main(){
	int n;
	int bw[][2]={{2,380},{3,550},{5,850},{10,1520},{12,1870},{15,2244}};
	int dp[51]={0};
	for(int i=1;i<51;++i){
		dp[i]=1e+9;
	}
	for(int i=0;i<51;++i){
		for(int j=0; j<6 ; ++j){
			if(i>=bw[j][0]){
					dp[i]= min(dp[i] , dp[i-bw[j][0]]+bw[j][1]); //dp[i]=((dp[iSize-jSize]+jValue < dp[i]) ? dp[iSize-jSize]+jValue : dp[i]);
			}
		}
	}
	while(cin >> n , n){
		cout << dp[n/100] << endl;
	}
	return 0;
}

Measured memory_bytes: 1160
/*

*/
#include<iostream>
#include<iomanip>
#include<ios>
#include<vector>
#include<queue>
#include<stack>
#include<map>
#include<string>
#include<algorithm>
#include<utility>
#include<math.h>
#include<cstdlib>
#define rep(i, n) for(int i=0;i<n;i++)
#define repb(i, a, b) for(int i=a;i<b;i++)
#define MAX_N 10000

using namespace std;
typedef pair<int, int> P;
typedef long long int ll;

const int INF = 1<<30;
const ll MOD = ll(1e9+7);

int main(){
  int n, k;cin>>n>>k;
  int ans=0;
  while(n!=0){
    n/=k;ans++;
  }
  cout<<ans<<endl;
 //  system("read -n 1 -s -p \"Press any key to continue...\"");
}


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

#undef _P
#define _P(...) (void)printf(__VA_ARGS__)
#define FOR(x,to) for(x=0;x<(to);x++)
#define FORR(x,arr) for(auto& x:arr)
#define ITR(x,c) for(__typeof(c.begin()) x=c.begin();x!=c.end();x++)
#define ALL(a) (a.begin()),(a.end())
#define ZERO(a) memset(a,0,sizeof(a))
#define MINUS(a) memset(a,0xff,sizeof(a))
//-------------------------------------------------------

ll A[3];

void solve() {
	int i,j,k,l,r,x,y; string s;
	
	cin>>A[0]>>A[1]>>A[2];
	int ret=0;
	while(1) {
		if(A[0]%2) break;
		if(A[1]%2) break;
		if(A[2]%2) break;
		if(ret>100) {
			ret=-1;
			break;
		}
		ll B[3]={(A[1]+A[2])/2,(A[0]+A[2])/2,(A[0]+A[1])/2};
		A[0]=B[0];
		A[1]=B[1];
		A[2]=B[2];
		ret++;
	}
	
	cout<<ret<<endl;
}


int main(int argc,char** argv){
	string s;int i;
	if(argc==1) ios::sync_with_stdio(false), cin.tie(0);
	FOR(i,argc-1) s+=argv[i+1],s+='\n';
	FOR(i,s.size()) ungetc(s[s.size()-1-i],stdin);
	solve(); return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
const int maxn = 2e5 + 7;
typedef long long ll;
int n, m;

char ch[maxn];
int main()
{
    scanf("%d", &m);
    scanf("%d", &n);
    ll ans = 0, base = 1;
    while(m > 0){
        ans++;
        m /= n;
    }
    printf("%lld\n", ans);
    return 0;
}


Measured memory_bytes: 256
using namespace std;
#include<bits/stdc++.h>
#define BEGIN ios_base::sync_with_stdio(0);cin.tie(0)
#define END return EXIT_SUCCESS
#define FOR(I,A,B) for((I)=(A);(I)<(B);(I)++)
#define REP(I,N) FOR(I,0,N)
#define UP(I,A,B) for((I)=(A);(I)<=(B);(I)++)
#define DW(I,A,B) for((I)=(A);(I)>=(B);(I)--)
#define IN(P) cin>>(P)
#define IN2(P1,P2) cin>>(P1)>>(P2)
#define IN3(P1,P2,P3) cin>>(P1)>>(P2)>>(P3)
#define INS(I,N,V) REP(I,N) cin>>V[I]
#define INS2(I,N,V1,V2) REP(I,N) cin>>V1[I]>>V2[I];
#define INS3(I,N,V1,V2,V3) REP(I,N) cin>>V1[I]>>V2[I]>>V3[I];
#define OUT(P) cout<<P<<endl
#define OUT2(P1,P2) cout<<P1<<" "<<P2<<endl
#define OUT3(P1,P2,P3) cout<<P1<<" "<<P2<<" "<<P3<<endl
#define OUTS(I,N,V) REP(I,N) cout<<V[i]<<endl
#define ALL(C) (C).begin(),(C).end()
#define RALL(C) (C).rbegin(),(C).rend()
#define mp make_pair
#define pb push_back
typedef unsigned long ul;
typedef unsigned int ui;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }

long X;

inline void solve(){
  IN(X);
  OUT(ceil((-1+sqrt(1+8*X))/2));
}

int main(int argc,char**argv){
  BEGIN;
  solve();
  END;
}


Measured memory_bytes: 256
import java.util.Scanner;
public class Main{
    public static void main(String[] agrs){
            Scanner sc = new Scanner(System.in);
            while(true)
            {
                int n = sc.nextInt();
                if(n == 0)
                    break;
                int num[] = new int[n];
                int count = 0;
                for(int i = 0 ; i < n ; i++)
                    num[i] = sc.nextInt();
                int sum = 0;
                double ave = 0;
                for(int i = 0 ; i < n ; i++)
                    sum += num[i];
                ave = (double)sum / n;
                for(int i = 0 ;i < n ; i++)
                    if(num[i] <= ave)
                        count++;
                System.out.println(count);
            }
    }
}


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

int main(){
    int N, count;
    cin >> N;
    count = 0;
    vector<int> vec(N);
    for (int i = 0; i < N; i++){
        cin >> vec.at(i);
    }
    for (int i = 0; i < N - 1; i++){
        vec.at(i + 1) = __gcd(vec.at(i), vec.at(i + 1));
    }
    while(vec.at(N - 1) % 2 == 0){
        count++;
        vec.at(N - 1) = vec.at(N - 1) * 0.5;
    }
    cout << count << endl;
}

Measured memory_bytes: 3576
#include<iostream>

using namespace std;

int main () {

  while ( true ) {
    int n;
    cin >> n;
    if ( n == 0 )
      break;
    int sum = 0;
    int temp;
    for ( int i=0 ;i<(n-1)*n/2; i++ ) {
      cin >> temp;
      sum += temp;
    }

    sum = sum/(n-1);
    cout << sum << endl;
  }
}

Measured memory_bytes: 868
#include <iostream>
#include <vector>
#include <map>
#include <set>
#include <unordered_set>
#include <stack>
#include <queue>
#include <math.h>
#include <string>
#include <numeric>
#include <algorithm>
#include <utility>

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


// 68 11 55 - rank 3
// 69 12 19 - rank 3
// 70 12 34

ull gcd(ull a, ull b) {
    while (b != 0) {
        auto na = a % b;
        a = b;
        b = na;
    }
    return a;
}


void oneCase() {
    int n;
    cin >> n;
    vector<vector<pair<int, ll>>> edges(n);
    for (int i = 1; i < n; ++i) {
        int a, b;
        ll c;
        cin >> a >> b >> c;
        --a;
        --b;
        edges[a].emplace_back(b, c);
        edges[b].emplace_back(a, c);
    }
    int q, k;
    cin >> q >> k;
    --k;
    vector<ll> dist(n, 1e18);
    dist[k] = 0;
    stack<int> nodes;
    nodes.push(k);
    while (!nodes.empty()) {
        auto cur = nodes.top();
        nodes.pop();
        for (auto out : edges[cur]) {
            if (dist[out.first] < 1e18) {
                continue;
            }
            dist[out.first] = dist[cur] + out.second;
            nodes.emplace(out.first);
        }
    }
    for (int j = 0; j < q; ++j) {
        int x, y;
        cin >> x >> y;
        --x;
        --y;
        cout << dist[x] + dist[y] << "\n";
    }

}


int main() {
    int t = 1;
//    cin >> t;
    while (t--) {
       oneCase();
    }

    return 0;
}

ll fact(ll n, ll mod) {
    ll res = 1;
    while (n > 0) {
        res = (res * n) % mod;
        --n;
    }
    return res;
}


Measured memory_bytes: 9984
#include <bits/stdc++.h>
using namespace std;
#define int long long
using P = pair<int, int>;
using V = vector<int>;
constexpr array<int, 4> dx = {1, 0, -1, 0}, dy = {0, 1, 0, -1};
constexpr int INF = 1234567890, MOD = 1000000000 + 7;
// constexpr int MOD = 998244353;
// constexpr int INF2 = 1000000000000000000LL+7;
template <class T>
bool chmax(T &a, const T &b)
{
    if (a < b)
    {
        a = b;
        return 1;
    }
    return 0;
}
template <class T>
bool chmin(T &a, const T &b)
{
    if (b < a)
    {
        a = b;
        return 1;
    }
    return 0;
}
constexpr int ceil(int a, int b) { return (a + b - 1) / b; }
constexpr int gcd(int a, int b) { return b ? gcd(b, a % b) : a; }
constexpr int fact(int n) { return n > 1 ? n * fact(n - 1) % MOD : 1; }
constexpr int modpow(int a, int n)
{
    int rtn = 1;
    while (n > 0)
    {
        if (n & 1)
            rtn = rtn * a % MOD;
        a = a * a % MOD;
        n >>= 1;
    }
    return rtn;
}
int modinv(int a)
{
    int b = MOD, u = 1, v = 0;
    while (b)
    {
        int t = a / b;
        a -= t * b;
        swap(a, b);
        u -= t * v;
        swap(u, v);
    }
    u %= MOD;
    if (u < 0)
        u += MOD;
    return u;
}

constexpr bool canMakePair(P red, P blue) { return ((red.first < blue.first && red.second < blue.second) ? true : false); }

signed main()
{
    cin.tie(0);
    ios::sync_with_stdio(0);
    cout << setprecision(10);

    int n;
    cin >> n;
    vector<P> reds(n), blues(n);
    for (int i = 0; i < n; i++)
    {
        int a, b;
        cin >> a >> b;
        reds[i] = {a, b};
    }
    for (int i = 0; i < n; i++)
    {
        int a, b;
        cin >> a >> b;
        blues[i] = {a, b};
    }
    sort(reds.begin(), reds.end());
    sort(blues.begin(), blues.end());

    int n_pairs = 0;

    // 青い点について調べる
    for (int i = 0; i < n; i++)
    {
        // 青い点とペアが作れる赤い点の中で，もっともy座標が大きい点とペアを作る
        // 残りの青い点はこの青い点よりx座標が同じか大きい だからy座標が大きい（厳しい）点を貪欲的に取る
        int index_greedy_red_point = -1;
        int y_greedy_red_point = -1;

        for (int j = 0; j < n; j++)
        {
            // 今の青い点よりx座標が小さい赤い点を探す
            if (!(reds[j].first < blues[i].first))
                break;
            // この赤い点は青い点とペアを作れる
            if (reds[j].second < blues[i].second)
            {
                // y座標が最も大きい赤い点の情報を更新
                if (reds[j].second > y_greedy_red_point)
                {
                    index_greedy_red_point = j;
                    y_greedy_red_point = reds[j].second;
                }
            }
        }

        // 赤い点が見つかったなら ペアを作る 赤い点を使えなくする
        if (index_greedy_red_point != -1)
        {
            reds[index_greedy_red_point] = {INF, INF};
            sort(reds.begin(), reds.end());

            n_pairs++;
        }
    }

    cout << n_pairs << endl;
}


Measured memory_bytes: 256
//
// Created by Huang,Zhiqiang on 2018/7/1.
//

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

const int max_arr = 200005;
typedef long long ll;

ll A[max_arr];
ll sums[max_arr];
int n;
ll ans = INT64_MAX;

ll mixL(ll a, ll b) {
    if (a > b) return b;
    return a;
}

ll maxX(ll a, ll b) {
    if (a > b) return a;
    return b;
}

pair<ll, ll> findL(int index) {
    ll total = sums[index];
    ll half = total / 2;
    int l = 1, r = index, target = 0;
    while (l <= r) {
        int mid = (l + r) / 2;
        if (sums[mid] == half) {
            target = mid;
            break;
        }
        else if (sums[mid] < half) {
            ll ls = sums[mid];
            ll rs = total - ls;
            ll pls = sums[target];
            ll prs = total - pls;
            if (target == 0 || abs(ls - rs) < abs(pls - prs)) {
                target = mid;
            }
            l = mid + 1;
        } else {
            ll ls = sums[mid];
            ll rs = total - ls;
            ll pls = sums[target];
            ll prs = total - pls;
            if (target == 0 || abs(ls - rs) < abs(pls - prs)) {
                target = mid;
            }
            r = mid - 1;
        }
    }
    return make_pair(sums[target], total - sums[target]);
}

pair<ll, ll> findR(int index) {
    ll total = sums[n] - sums[index];
    ll half = total / 2;
    int l = index + 1, r = n, target = 0;
    while (l <= r) {
        int mid = (l + r) / 2;
        if (sums[mid] - sums[index] == half) {
            target = mid;
            break;
        }
        else if (sums[mid] - sums[index] < half) {
            ll ls = sums[mid] - sums[index];
            ll rs = total - ls;
            ll pls = sums[target] - sums[index];
            ll prs = total - pls;
            if (target == 0 || abs(ls - rs) < abs(pls - prs)) {
                target = mid;
            }
            l = mid + 1;
        } else {
            ll ls = sums[mid] - sums[index];
            ll rs = total - ls;
            ll pls = sums[target] - sums[index];
            ll prs = total - pls;
            if (target == 0 || abs(ls - rs) < abs(pls - prs)) {
                target = mid;
            }
            r = mid - 1;
        }
    }
    return make_pair(sums[target] - sums[index], total - sums[target] + sums[index]);
}

int main() {
    cin >> n;
    sums[0] = 0;
    A[0] = 0;
    for (int i = 1; i <= n; i++) {
        cin >> A[i];
        sums[i] = sums[i - 1] + A[i];
    }
    for (int i = 2; i < n - 1; i++) {
        pair<ll, ll> Lv = findL(i);
        pair<ll, ll> Rv = findR(i);
        vector<ll> vc;
        vc.push_back(Lv.first);vc.push_back(Lv.second);
        vc.push_back(Rv.first);vc.push_back(Rv.second);
        sort(vc.begin(), vc.end());
        ll t = vc[3] - vc[0];
        if (t < ans) ans = t;
    }
    cout << ans << endl;
}

Measured memory_bytes: 3328
#include <iostream>
#include <math.h>
#include <algorithm>
#include <vector>
#include <iomanip>
#include <string>

typedef long long int ll;
typedef unsigned long long int ull;

using namespace std;

int main()
{
  string s;
  int m = 0, c = 0;

  cin >> s;
  for (int i = 0; i < s.size(); i++)
  {
    if (s[i] == 'A' || s[i] == 'T' || s[i] == 'G' || s[i] == 'C')
    {
      c++;
    }
    else
    {
      c = 0;
    }
      m = max(c, m);
  }

  cout << m << endl;

  return 0;
}


Measured memory_bytes: 256
from math import sqrt,ceil,floor
def mi():return map(int,input().split())
def li():return list(mi())
def ii():return int(input())

n,k=mi()

m=[1]*(n+1)
a=li()
for i in range(k):
    x,y=mi()
    if(a[x-1]==a[y-1]):
        m[x]=0
        m[y]=0
    if(a[x-1]>a[y-1]):
        m[y]=0
    else:
        m[x]=0


m=m[1:]
print(m.count(1))

Measured memory_bytes: 85576
//g++ -std=gnu++14 a.cpp

#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <iostream>
#include <istream>
#include <iterator>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
#include <tuple>
#include <iomanip>
#include <random>
#include <math.h>
#include <stdio.h>

using namespace std;

#define ll long long
#define rep(i, n) for(ll i = 0; i < (n); i++)
ll MOD = 1e9 + 7;
int INF = 1 << 30;
ll INFL = 1LL << 60;
ll MODP = 998244353;

ll kai(ll x,ll y){
  if(y == 0)return 1;
  if(y == 1)return x;
  if(y&1){
    return (x*kai(x,y-1))%MOD;
  }else{
    ll t = kai(x,y/2);
    return (t*t)%MOD;
  }
}

ll comb(ll a,ll b,vector<ll> &p){
  if(a == 0)return 1;
  if(b == 0)return 1;
  ll ans = p[a+b];
  ans = (ans*kai(p[a],MOD-2))%MOD;
  ans = (ans*kai(p[b],MOD-2))%MOD;
  return ans;
}

ll mind(int x,vector<int> &v){
  int ok = v.size()-1,ng = -1;
  while(ok - ng > 1){
    int next = (ok+ng)/2;
    if(v[next] > x){
      ok = next;
    }else{
      ng = next;
    }
  }
  return ok;
}

ll maxd(int x,vector<int> &v){
  int ok = 0,ng = v.size();
  while(ng - ok > 1){
    int next = (ok+ng)/2;
    if(v[next] < x){
      ok = next;
    }else{
      ng = next;
    }
  }
  return ok;
}

int main(){
  ll N;
  cin >> N;
  vector<ll> A(N);
  rep(i,N)cin >> A[i];
  ll ans = 0;
  ll maxh = A[0];
  for(int i = 1;i <= N-1;i++){
    if(maxh < A[i]){
      maxh = A[i];
    }else{
      ans += (maxh-A[i]);
    }
  }

  cout << ans << endl;


  return 0;
}


Measured memory_bytes: 4820
import std.algorithm;
import std.array;
import std.ascii;
import std.container;
import std.conv;
import std.math;
import std.numeric;
import std.range;
import std.stdio;
import std.string;
import std.typecons;

void log(A...)(A arg) {
    stderr.writeln(arg);
}
int size(T)(in T s) {
    return cast(int)s.length;
}

const real EPS = 1e-8;

void main() {
    int N, M; scanf("%d %d\n", &N, &M);
    auto S = new int[][N];
    auto H = new int[][N];
    foreach (i; 0 .. N) {
        int k; scanf("%d", &k);
        S[i] = new int[k];
        H[i] = new int[k];
        foreach (j; 0 .. k) {
            scanf("%d %d", &S[i][j], &H[i][j]);
        }
    }

    real height(int i, real m) {
        real h = 0;
        int k = 0;
        while (m > 0 && k < S[i].size) {
            real d = min(H[i][k], m / S[i][k]);
            m -= d * S[i][k];
            assert(m >= -EPS);
            h += d;
            k++;
        }
        return h;
    }

    real ans = -1e8;
    foreach (int i; 0 .. N) {
        auto dp = new int[][](N + 1, M + 1);
        foreach (int n; 0 .. N) {
            dp[n + 1] = dp[n].dup;
            if (i == n) continue;
            int x = 0, h = 0;
            foreach (int k; 0 .. S[n].size) {
                x += S[n][k] * H[n][k];
                h += H[n][k];
                foreach (int m; 0 .. M + 1) {
                    if (m + x <= M) {
                        dp[n + 1][m + x] = max(dp[n + 1][m + x], dp[n][m] + h);
                    }
                }
            }
        }
        foreach (m; 0 .. M + 1) {
            int r = M - m;
            ans = max(ans, dp[N][m] + height(i, r));
        }
    }
    writefln("%.12f", ans);
}

Measured memory_bytes: 3956
import java.util.*;
public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);

		int x = sc.nextInt();

		boolean f = false;
		int t = 1;
		while ( !f ) {
			int tx = t*x;
			if ( tx%360==0 ) {
				f = !f;
			} else {
				t++;
			}
		}

		System.out.println(t);
	}
}

Measured memory_bytes: 35752
import collections
n = int(input())
v = list(map(int,input().split()))
e = v[0::2]
o = v[1::2]
e_com = collections.Counter(e).most_common(2)
o_com = collections.Counter(o).most_common(2)
if e_com[0][0] != o_com[0][0]:
  print(n - e_com[0][1] - o_com[0][1])
elif e_com[0][0] == o_com[0][0]:
  if len(e_com) > 1 and len(o_com)>1:
    print(min(n - e_com[1][1] - o_com[0][1], n - e_com[0][1] - o_com[1][1]))
  elif len(e_com) > 1 and len(o_com) == 1:
    print(n - e_com[1][1])
  elif len(e_com) == 1 and len(o_com) > 1:
    print(n - o_com[1][1])
  else:
    print(n//2)

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

int check(int x, int y, int z, int N, int Y){
        if(x<0 || y<0 || z<0) return -1;
        if(x+y+z!=N) return -1;
        if((10000*x+5000*y+1000*z)!=Y) return -1;
        return 0;
}

int main(int argc, char* argv[]){
        char buf[128]={0};
        char* p=NULL;
        int N=0, Y=0;
        int x=0, y=0, z=0;

        if(fgets(buf, sizeof(buf)-1, stdin)==NULL){
                return 1;
        }
        p = strtok(buf, " ");
        N = atoi(p);

        p = strtok(NULL, " ");
        Y = atoi(p);

        int Y2 = Y/1000;
        int c = Y2 - N;

        if(c<0){
                x=-1, y=-1, z=-1;
        }
        else if(c==0){
                x=0, y=0, z=N;
        }
        else{ //c>0
                int v = c;
                while(v>=0){
                        if(v%4==0){
                                y = (c-(9*x))/4;
                                z = N - x - y;
                                if(check(x, y, z, N, Y)==0){
                                    break;
                                }
                        }
                        v -= 9;
                        x++;
                }
                if(v>=0){
                        y = (c - (9*x))/4;
                        z = N - x - y;
                        if(check(x, y, z, N, Y)!=0){
                                x=-1, y=-1, z=-1;
                        }
                }
                else{
                        x=-1, y=-1, z=-1;
                }
        }
        printf("%d %d %d\n", x, y, z);
        return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
#define rep(i,n)for(long long i=0;i<(long long)(n);++i)
#define all(a) a.begin(), a.end()
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
 
const ll MOD=1e9+7;
const ll INF=1e18;
const double pi=acos(-1);
int dx[8] = {1,0,-1,0,1,1,-1,-1};
int dy[8] = {0,1,0,-1,-1,1,1,-1};

const int MAX=510000;
int main(){
  cin.tie(0);
  ios::sync_with_stdio(false); 
  
  int n,m;
  cin >> n >> m;
  cout << n*(n-1)/2+m*(m-1)/2<<endl;
  return 0;
}

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

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

    long long k, n;
    cin >> k >> n;

    vector<long long> A(n);
    for(int i = 0; i < n; i++){
        cin >> A[i];
    }
    vector<int> B;
    for(int i = 1; i < n; i++){
        B.push_back(A[i] - A[i - 1]);
    }
    B.push_back(k - A[n - 1] + A[0]);

    sort(B.begin(), B.end());

    int bs = B.size();
    long long ans = 0;
    for(int i = 0; i < bs - 1; i++){
        ans += B[i];
    }

    cout << ans << endl;

    return 0;
}

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

using namespace std;

typedef long long ll;
const ll INF = 1LL<<60;

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

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

ll modpow(ll a, ll n, ll mod) {
  ll res = 1;
  while (n > 0) {
    if (n & 1) res = res * a % mod;
    a = a * a % mod;
    n >>= 1;
  }
  return res;
}

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

  ll N, K;
  cin >> N >> K;

  vector<ll> sumA(N+1);
  sumA[0] = 0;
  ll A;
  for(int i = 0; i < N; i++){
    cin >> A;
    A--;
    sumA[i+1] = (sumA[i] + A) % K;
  }

  map<ll, vector<ll>> mp;
  for(int i = 0; i <= N; i++){
    mp[sumA[i]].push_back(i);
  }

  ll ans = 0;
  for(auto itr = mp.begin(); itr != mp.end(); itr++){
    vector<ll> ind_vec = itr->second;

    int right = 0;
    ll res = 0;
    for(int left = 0; left < ind_vec.size(); left++){
      while(right < ind_vec.size()-1 && 
      ind_vec[right+1] - ind_vec[left] < K){
        ++right;
      }
      res += right - left;
    }
    ans += res;
  }

  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 23680
#pragma region include
#include <iostream>
#include <iomanip>
#include <stdio.h>

#include <sstream>
#include <algorithm>
#include <iterator>
#include <cmath>
#include <complex>

#include <string>
#include <cstring>
#include <vector>
#include <tuple>
#include <bitset>

#include <queue>
#include <complex>
#include <set>
#include <map>
#include <stack>
#include <list>

#include <fstream>
#include <random>
//#include <time.h>
#include <ctime>
#pragma endregion //#include
/////////
#define REP(i, x, n) for(int i = x; i < n; ++i)
#define rep(i,n) REP(i,0,n)
#define ALL(X) X.begin(), X.end()
/////////
#pragma region typedef
typedef long long LL;
typedef long double LD;
typedef unsigned long long ULL;
typedef std::pair<LL,LL> PLL;//
typedef std::pair<int,int> PII;//
#pragma endregion //typedef
////定数
const int INF = (int)1e9;
const LL MOD = (LL)1e9+7;
const LL LINF = (LL)4e18+20;
const LD PI = acos(-1.0);
const double EPS = 1e-9;
/////////
using namespace::std;

void solve(){
	LL N,M;
	cin >> N >> M;
	LL ans = M*1900 + (N-M)*100;
	ans <<= M;
	cout << ans << endl;
}

#pragma region main
signed main(void){
	std::cin.tie(0);
	std::ios::sync_with_stdio(false);
	std::cout << std::fixed;//小数を10進数表示
	cout << setprecision(16);//小数点以下の桁数を指定//coutとcerrで別	

	solve();
}
#pragma endregion //main()

Measured memory_bytes: 256
//http://mayokoex.hatenablog.com/entry/2016/06/25/114813
//http://mmxsrup.hatenablog.com/entry/2016/07/05/110031
//を参考
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll INF=1e12;
const ll MOD=1e9+7;
int main(void)
{
    int N,T;
    cin >> N >> T;
    ll dp[N-1];
    memset(dp,0,sizeof(dp));
    dp[0]=1;
    vector<ll> A(N);
    for(int i=0;i<N;i++)
    {
        cin >> A[i];
    }
    sort(A.begin(),A.end());
    for(int i=1;i<N;i++)
    {
        ll left=(ll)(lower_bound(A.begin(),A.end(),A[i]-T)-A.begin());
        dp[i]=(dp[i-1]*(i-left+1))%MOD;
    }
    cout << dp[N-1] << endl;
    return 0;
}


Measured memory_bytes: 4376
<?php
fscanf(STDIN, '%d %d', $n, $k);
$numbers = fgets(STDIN);
$exploded_numbers = explode(' ', trim($numbers));

function cumulative_sum($args_array) {
  $sum = 0;
  $result_array = [0];
  foreach ($args_array as $key => $val) {
    $sum += ($val+1) / 2;
    $result_array[] = $sum;
  }
  return $result_array;
}

$cumulatived_sum = cumulative_sum($exploded_numbers);
$max_range_sum = 0;
for ($i=0; $i<=$n-$k; $i++) {
  $tmp_range_sum = $cumulatived_sum[$i+$k] - $cumulatived_sum[$i];
  if ($tmp_range_sum > $max_range_sum) {
    $max_range_sum = $tmp_range_sum;
  }
}

echo $max_range_sum;

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

int main()
{
    ll N;
    cin >> N;
    vector<ll> A(N), B(N), C(N);
    rep(i, N) cin >> A[i];
    // rep(i, N) cin >> B[i];
    ll sum = 0, tmp;
    rep(i, N)
    {
        cin >> tmp;
        sum += tmp;
    }
    rep(i, N - 1) cin >> C[i];

    ll now = -2;
    for (ll a : A)
    {
        if (a - now == 1)
            sum += C[now - 1];
        now = a;
    }
    cout << sum << endl;

    return 0;
}


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

int main() 
{
    int N, K;
    cin >> N >> K;
    vector<int>L(N);
    for (int i = 0; i < N; i++) {
        cin >> L[i];
    }
    sort(L.begin(), L.end(), greater<int>());
    
    int ans = 0;
    for (int i = 0; i < K; i++) {
        ans += L[i];
    }
    cout << ans << endl;
}

Measured memory_bytes: 3608
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cmath>
#include <ctime>
#include <cstring>
#include <functional>
#include <iostream>
#include <iomanip>
#include <limits>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <regex>
#include <vector>

#define fix(n)          cout<<fixed<<setprecision(n)
#define rep(i,n)        for (int i = 0; i < (n); ++i)
#define sort(a)         sort((a).begin(), (a).end())
#define uniq(a)         sort(a);(a).erase(unique((a).begin(), (a).end()), (a).end())
#define reverse(a)      reverse((a).begin(), (a).end())
#define ctos(c)         string(1, (c))
#define out(d)          cout << (d)
#define outl(d)         std::cout<<(d)<<"\n"
#define YES()           cout << "YES" << endl
#define NO()            cout << "NO" << endl
#define Yes()           cout << "Yes" << endl
#define No()            cout << "No" << endl
#define ceil(x, y)      ((x + y - 1) / (y))
#define debug(x)        cerr << #x << ": " << (x) << '\n'
#define debug2(x, y)    cerr << #x << ": " << (x) << ", " << #y << ": " << (y) << '\n'
#define debug3(x, y, z) cerr << #x << ": " << (x) << ", " << #y << ": " << (y) << ", " << #z << ": " << (z) << '\n'
#define dbg(v)          for (size_t _ = 0; _ < v.size(); ++_){ cerr << #v << "[" << _ << "] : " << v[_] << '\n'; }

using namespace std;
using ll = long long;
using ld = long double;
using P = pair<ll,ll>;

const ll MOD = 1000000007; // 10^9 + 7

void solve() {
  ll n, k; cin >> n >> k;
  outl(k * ll(pow(k - 1, n - 1)));
}

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  srand((unsigned)time(NULL));
  fix(12);

  solve();
}


Measured memory_bytes: 888
from collections import defaultdict
from collections import deque
from collections import Counter
import itertools
import math

def readInt():
  return int(input())
def readInts():
  return list(map(int, input().split()))
def readChar():
  return input()
def readChars():
  return input().split()

h,w = readInts()
a = [list(input()) for i in range(h)]
check = [["."]*w for i in range(h)]
check[0][0]="#"

now = (0,0)
goal = (h-1,w-1)

while 1:
  if now==goal and check==a:
    print("Possible")
    break
  s = (now[0],now[1]+1)
  t = (now[0]+1,now[1])
  if s[1]<w and a[s[0]][s[1]]=="#":
    check[s[0]][s[1]]="#"
    now = s
  elif t[0]<h and a[t[0]][t[1]]=="#":
    check[t[0]][t[1]]="#"
    now = t
  else:
    print("Impossible")
    break

Measured memory_bytes: 9404
# include <bits/stdc++.h>
using namespace std;
typedef long long i64;
const int N = 100005;
# define INF 1000000001
# define MOD 1000000007
# define pb push_back
# define mp make_pair
typedef pair<int, int> Pi;

int main ()
{
    int n, k, s;
    cin >> n >> k >> s;
    if (s == INF-1) {
        for (int i = 1; i <= k; ++i) cout << s << " ";
        for (int i = k+1; i <= n; ++i) cout << 1 << " ";
        cout << endl;
    }
    else {
        for (int i = 1; i <= k; ++i) cout << s << " ";
        for (int i = k+1; i <= n; ++i) cout << s+1 << " ";
        cout << endl;
    }
    return 0;
}


Measured memory_bytes: 1280
#include<bits/stdc++.h>
using namespace std;
int a[2010101],b[2010101];
int br[2010101];
int n,ans,len;
bool check(int v)
{
	for (int i=1;i<=len;++i) 
	{
		if (a[i]>=v) b[i]=1;
		else b[i]=0;
	}
//	for (int i=1;i<=len;++i) printf("%d ",b[i]);
//	printf("\n");

	br[1]=-1;
	for (int i=2;i<=len;++i) 
	{
		if (b[i]==b[i-1]) br[i]=br[i-1]=b[i];
		else br[i]=-1;
	}
	
	if (br[n]!=-1) return br[n];

	int d[2];
	d[0]=d[1]=len;
	for (int i=1;i<=len;++i) if (br[i]!=-1) d[br[i]]=min(d[br[i]],abs(n-i));
	if (d[0]==len && d[1]==len)
	{
		int sss=b[n];
		if (n%2==0) sss=1-sss;
		return sss;
	}
	if (d[0]<d[1]) return 0;
	else return 1;
}
int main()
{
	scanf("%d",&n);
	len=2*n-1;
	for (int i=1;i<=len;++i) scanf("%d",&a[i]);

	int l=1,r=len;
	while (l<=r)
	{
		int mid=(l+r)/2;
//		printf("%d : %d\n",mid,check(mid));
		if (check(mid))
		{
			ans=max(ans,mid);
			l=mid+1;
		}
		else r=mid-1;
	}
	printf("%d\n",ans);
	return 0;
}

Measured memory_bytes: 9216
#include <bits/stdc++.h>
using namespace std;
#define all(n) begin(n), end(n)
const long long INF = numeric_limits<long long>::max();
typedef long long ll;
typedef vector<int> vint;
typedef vector<vector<int>> vvint;
typedef vector<ll> vll;
typedef vector<vector<ll>> vvll;
typedef unsigned long long ull;
template <class T>
bool chmax(T &a, const T &b)
{
    if (a < b)
    {
        a = b;
        return 1;
    }
    return 0;
}
template <class T>
bool chmin(T &a, const T &b)
{
    if (b < a)
    {
        a = b;
        return 1;
    }
    return 0;
}
template <typename T>
vector<T> make_v(size_t a) { return vector<T>(a); }

template <typename T, typename... Ts>
auto make_v(size_t a, Ts... ts)
{
    return vector<decltype(make_v<T>(ts...))>(a, make_v<T>(ts...));
}
template <typename T, typename V>
typename enable_if<is_class<T>::value == 0>::type
fill_v(T &t, const V &v) { t = v; }

template <typename T, typename V>
typename enable_if<is_class<T>::value != 0>::type
fill_v(T &t, const V &v)
{
    for (auto &e : t)
        fill_v(e, v);
}
int main()
{
    int N,C;
    cin>>N>>C;
    vint s(N),t(N),c(N);
    const int MAX = 1e5+10;
    auto imos = make_v<int>(C,MAX);
    for (size_t i = 0; i < N; i++)
    {
        cin>>s[i]>>t[i]>>c[i];
        s[i]--;c[i]--;
        imos[c[i]][s[i]]++;
        imos[c[i]][t[i]]--;
    }
    for (auto &&i : imos)
    {
        partial_sum(all(i),i.begin());
    }
    int ans = 0;
    for (size_t i = 0; i < MAX; i++)
    {
        int cnt = 0;
        for (size_t j = 0; j < C; j++)
        {
            if(imos[j][i]>0)
            cnt++;
        }
        chmax(ans,cnt);
    }
    cout<<ans<<endl;
    return 0;
}

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

int main(){
  int a,b;
  cin >> a >> b;
  if(a >= 13){
    cout << b << endl;
  }else if(a >= 6 && a <= 13){
    cout << b/2 << endl;
  }else{
    cout << 0 << endl;
  }
}

Measured memory_bytes: 256
n = int(input())
a_s = [int(item) for item in input().split()]
b_s = [int(item) for item in input().split()]
total = sum(a_s)

for i, b in enumerate(b_s):
    if b <= a_s[i]:
        a_s[i] -= b
        continue
    elif b > a_s[i]:
        a_s[i+1] = max(0, a_s[i+1] - (b - a_s[i]))
        a_s[i] = 0
    
print(total - sum(a_s))

Measured memory_bytes: 19648
import sys
import math
import collections

def set_debug(debug_mode=False):
    if debug_mode:
        fin = open('input.txt', 'r')
        sys.stdin = fin


def int_split_input():
    return list(map(int, input().split()))


if __name__ == '__main__':
    # set_debug(True)

    # t = int(input())
    t = 1

    for ti in range(1, t + 1):
        # n = int(input())
        s = input()
        t = input()

        res = 0
        for i in range(len(s)):
            if s[i] != t[i]:
                res += 1

        print(res)



Measured memory_bytes: 9732
import java.util.*;

class Main{           
 
   public static void main(String[] args){
      
      Scanner sc = new Scanner(System.in);
            
      String S1 = sc.next();
      
      String T = sc.next();
      int l = T.length();
      
      String S3 = "";
      
      for(int i = 0;i < S1.length()-l+1;i++){
          String S2 = S1.substring(i,i+l);
          boolean flag =true;
          for(int j = 0;j < S2.length();j++){
              if(S2.charAt(j) == T.charAt(j) || S2.charAt(j) == '?'){
                  continue;
              }else{
                  flag = false;
                  break;
              }
          }
          if(flag){
             S3 = S1.substring(0,i) + T + S1.substring(i+T.length());
          }                        
      }
      
      if(S3.isEmpty()){
          System.out.println("UNRESTORABLE");
          return;
      }
      
      S3 = S3.replace("?","a");
                  
      System.out.println(S3);
                                                
   }   
 }

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

using namespace std;
typedef long long ll;
#define int ll

template<typename T1,typename T2> inline void chmin(T1 &a, T2 b){ if(a > b) a = b; }
template<typename T1,typename T2> inline void chmax(T1 &a, T2 b){ if(a < b) a = b; }

#define REP(i,n) for(int i=0;i<n;++i)
#define SORT(name) sort(name.begin(), name.end())
#define ZERO(p) memset(p, 0, sizeof(p))
#define MINUS(p) memset(p, -1, sizeof(p))
#if 1
#  define DBG(fmt, ...) printf(fmt, ##__VA_ARGS__)
#else
#  define DBG(fmt, ...)
#endif

const ll LLINF = (1LL<<60);
const int INF = (1LL<<30);
const double DINF = std::numeric_limits<double>::infinity();
const int MOD = 1000000007;
const int MAX_N = 100010;

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

    int N;
    cin >> N;

    map<string, int> cnt;
    REP(i, N) {
        string s;
        cin >> s;
        cnt[s]++;
    }
    vector< pair<int, string> > cnt2;
    for(auto& p : cnt) {
        cnt2.push_back(make_pair(p.second, p.first));
    }
    SORT(cnt2);
    reverse(cnt2.begin(), cnt2.end());

    vector<string> ans;
    int val = -1;
    for(auto& p : cnt2) {
        if(val == -1 || val == p.first) {
            val = p.first;
            ans.push_back(p.second);
        }
        else {
            break;
        }
    }
    SORT(ans);
    for(auto& s : ans) {
        cout << s << endl;
    }

    return 0;
}



Measured memory_bytes: 31340
#include <stdio.h>
#include <cmath>
#include <bits/stdc++.h>



using namespace std;

typedef vector<int> VI;
typedef vector<string> VS;


//container util
#define SORT(c) sort((c).begin(),(c).end())

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


#define MAX 100000

int main(void){

	int N; cin >> N;
	
	int ans = 0;
	REP(i,N){
	 int l, r; cin >> l >> r;
	 FOR(j,l,r+1) ans++;
	}

	cout << ans << endl;

	return 0;

}


Measured memory_bytes: 256
#include <iostream>
#include <queue>
#include <vector>
using namespace std;
typedef pair <int,pair <int,int> > P;
#define dis first
#define node second.first
#define mo second.second
#define INF 1000000000;
int N,M,L;
pair <int,int> mp[101][101];

P mk(int a,int b, int c){
  P res;
  res.dis = a, res.node = b; res.mo = c;
  return res;
}

int dijkstra(){
  priority_queue < P, vector<P>, greater<P> > Q;
  int D[101][101],visited[101][101]={};
  for(int i=0;i<=L;i++)
    for(int j=0;j<=N;j++) D[i][j] = INF;
  Q.push(mk(0,1,0)),  D[0][1] = 0;

  while(!Q.empty()) {
    P t = Q.top(); Q.pop();
    if(visited[t.mo][t.node] != 0) continue;
    visited[t.mo][t.node] = 1;
    if(t.node == N) return t.dis;

    for(int i=1;i<=N;i++){
      if(mp[t.node][i].first == -1) continue;
      int nmo = t.mo+mp[t.node][i].first;
      int ndis = t.dis + mp[t.node][i].second;
      if(nmo <=L && D[nmo][i] > t.dis )Q.push(mk(t.dis,i,nmo));
      if(D[t.mo][i] > ndis ) Q.push(mk(ndis,i,t.mo));
    }
  }
  return -1;   
}

int main() {

  while(1) {
  cin >> N >> M >> L;
  if(N==0 && M==0 && L==0) break;
  for(int i=0;i<=N;i++)
    for(int j=0;j<=N;j++) mp[i][j].first= -1;

  for(int i=0;i<M;i++){
    int x,y,z,w;
    cin >> x >> y >> z >> w;
    mp[x][y].first = z,mp[x][y].second = w;
    mp[y][x].first = z,mp[y][x].second = w;
  }
  cout << dijkstra() <<endl;
  }
  return 0;
}

Measured memory_bytes: 1844
#include<stdio.h>

typedef struct{
  int a;
  int b;
  int p;
  int s;
}P;

void print(int);
void rec(int,int);
void hei1(int);
void hei2(int);
void hei3(int);

P T[25];
int C[25];
int n,h;

int main(){
  int i,j,L,R,id,r;
  int c[25];
  scanf("%d",&n);
  for(i=0;i<n;i++){
    T[i].a=T[i].b=T[i].p=T[i].s=-1;
  }
  for(i=0;i<n;i++){
    c[i]=-1;
  }
  for(i=0;i<n;i++){
    scanf("%d%d%d",&id,&L,&R);
    if(i==0){
      T[id].a=L;
      T[id].b=R;
      T[L].s=R;
      T[R].s=L;
      c[L]=id;
      c[R]=id;
      C[i]=0;
    }else{
      T[id].a=L;
      T[id].b=R;
      if(c[id]!=-1){
	T[id].p=c[id];
      }
      if(c[L]==-1){
	T[L].p=id;
      }
      if(c[R]==-1){
	T[R].p=id;
      }
      T[L].s=R;
      T[R].s=L;
      c[L]=id;
      c[R]=id;
    }
  }
  for(i=0;i<n;i++){
    if(T[i].p == -1){
      r = i;
    }
  }
  rec(r,0);
  for(i=0;i<n;i++){
  	if(C[i]==0){
		h=i;
		break;
	}
  }
    print(h);
  return 0;
}

void rec(int a,int b){
  C[a] = b;
  if(T[a].a != -1)rec(T[a].a,b+1);
  if(T[a].b != -1)rec(T[a].b,b+1);
}

void print(int a){
  int i,j;
  printf("Preorder\n");
  hei1(a);
  printf("Inorder\n");
  hei2(a);
  printf("Postorder\n");
  hei3(a);
}

void hei1(int u){
	printf(" %d",u);
  if(T[u].a!=-1)hei1(T[u].a);
  if(T[u].b!=-1)hei1(T[u].b);
  if(u==h)printf("\n");
}
void hei2(int u){
	if(u!=-1){
		hei2(T[u].a);
		printf(" %d",u);
		hei2(T[u].b);
		if(u==h)printf("\n");
	}
}
void hei3(int u){
	if(u!=-1){
		hei3(T[u].a);
		hei3(T[u].b);
		printf(" %d",u);
		if(u==h)printf("\n");
	}
}


Measured memory_bytes: 2144
import sys
import math
import fractions
from collections import deque
from collections import defaultdict
sys.setrecursionlimit(10**7)

N = int(input())
graph = [[] for _ in range(N)]
for _ in range(N - 1):
    a, b = map(int, input().split())
    a -= 1
    b -= 1
    graph[a].append(b)
    graph[b].append(a)

c = list(map(int, input().split()))
c.sort(reverse=True)
sum_val = sum(c) - max(c)

assign = [0] * N
index = 0

q = deque()
q.append(0)
visited = []

while len(q) != 0:
    cur = q.popleft()
    assign[cur] = c[index]
    index += 1
    for n in graph[cur]:
        if n not in visited:
            q.append(n)
    visited.append(cur)

print(sum_val)
print(" ".join(map(str, assign)))


Measured memory_bytes: 74452
#include "bits/stdc++.h"
using namespace std;
using ll     = long long;
using pii    = pair<int, int>;
using pll    = pair<ll, ll>;
using vi     = vector<int>;
using vl     = vector<ll>;
using vvi    = vector<vi>;
using vvl    = vector<vl>;
const ll INF = 1LL << 60;
const ll MOD = 1000000007;
template <class T>
bool chmax(T &a, const T &b) {
    return (a < b) ? (a = b, 1) : 0;
}
template <class T>
bool chmin(T &a, const T &b) {
    return (b < a) ? (a = b, 1) : 0;
}
template <class C>
void print(const C &c, std::ostream &os = std::cout) {
    std::copy(std::begin(c), std::end(c), std::ostream_iterator<typename C::value_type>(os, " "));
    os << std::endl;
}

int n, a, b, c;

int dfs(int x1, int x2, int x3, vi &l, int xn) {
    if (xn == n) {
        if (x1 == 0 || x2 == 0 || x3 == 0)
            return 100000000;
        else
            return abs(x1 - a) + abs(x2 - b) + abs(x3 - c) - 30;
    }
    int ret = 100000000;
    chmin(ret, dfs(x1, x2, x3, l, xn + 1));
    chmin(ret, 10 + dfs(x1 + l[xn], x2, x3, l, xn + 1));
    chmin(ret, 10 + dfs(x1, x2 + l[xn], x3, l, xn + 1));
    chmin(ret, 10 + dfs(x1, x2, x3 + l[xn], l, xn + 1));
    return ret;
}

int main() {
    cin >> n >> a >> b >> c;
    vi l(n);
    for (int i = 0; i < n; ++i) {
        cin >> l[i];
    }
    cout << dfs(0, 0, 0, l, 0) << "\n";
    return 0;
}

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

public class Main {
    public static void main(String[] args) throws Exception {
        Scanner sc = new Scanner(System.in);
        int k = sc.nextInt();
        int x = sc.nextInt();
        if(500*k >= x){
            System.out.println("Yes");
        }else{
            System.out.println("No");
        }
    }
}

Measured memory_bytes: 35420
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cctype>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdint>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>

using namespace std;

int main() {
    int n;
    scanf("%d", &n);
    vector<int> a(2 * n);
    for (int i = 0; i < 2 * n; i++)
        scanf("%d", &a[i]);
    sort(a.begin(), a.end());
    int sum = 0;
    for (int i = 0; i < (int)a.size(); i += 2)
        sum += a[i];
    printf("%d\n", sum);
}


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

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

using namespace std;
using lint=long long;

const long long INF=1LL<<61;

int n,a[3000];
lint memo[3001][3001];

lint dfs(int l,int r){
	if(l==r) return 0;
	if(memo[l][r]>-INF) return memo[l][r];
	return memo[l][r]=max(a[l]-dfs(l+1,r),a[r-1]-dfs(l,r-1));
}

int main(){
	scanf("%d",&n);
	rep(i,n) scanf("%d",&a[i]);

	rep(l,n+1) rep(r,n+1) memo[l][r]=-INF;

	printf("%lld\n",dfs(0,n));

	return 0;
}


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

void change( int& x, int& y )
{
    int temp;
    temp = x;
    x = y;
    y = temp;
}

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

    cin >> a >> b >> c;

    if( a > b)
        change( a, b );
    if( a > c )
        change( a , c );
    if( b > c)
        change( b ,c );
    
    cout << a << " " << b << " " << c << endl;

    return 0; 
}


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

using namespace std;

typedef long long LL;
#define repp(i,a,b) for(int i = (int)(a) ; i < (int)(b) ; ++i)
#define repm(i,a,b) for(int i = (int)(a) ; i > (int)(b) ; --i)

int main(){
	LL N; cin >> N;
	const LL mod = 1e9+7;
	vector<vector<LL>> dp(2,vector<LL>(2,0));
	dp[0][0] = 1;
	repm(k,59,-1){
		vector<vector<LL>> nx(2,vector<LL>(2,0));
		if(N&(1ll<<k)){
			nx[0][0] = dp[0][0];
			nx[0][1] = (dp[0][0]+dp[0][1])%mod;
			nx[1][0] = (dp[1][0]*2+dp[1][1]+dp[0][0]+dp[0][1])%mod;
			nx[1][1] = (dp[1][0]+dp[1][1]*2+dp[0][1])%mod;
		} else {
			nx[0][0] = (dp[0][0]+dp[0][1])%mod;
			nx[0][1] = dp[0][1];
			nx[1][0] = (dp[1][0]*2+dp[1][1])%mod;
			nx[1][1] = (dp[1][0]+dp[1][1]*2)%mod;
		}
		swap(dp,nx);
	}
	cout << (dp[1][0]+dp[0][0])%mod << endl;
	return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<algorithm>


using namespace std;

int main()
{
	int N;
	long long x;
	long long a[100001];
	long long count = 0;
	long long a_pre1=0;
	long long a_pre2 = 0;
	cin >> N >> x;
	for (int i = 0; i < N; ++i) cin >> a[i];

	for (int j = 0; j < N-1; ++j) {
	
		if (a[0] > x) {
			a_pre1 = a[0];
			a[0] = x;
			count = a_pre1 - a[0];
		}
		
		if (a[j] + a[j + 1] > x) {
			a_pre2 = a[j + 1];
				a[j + 1] = x - a[j];
				count = count + (a_pre2- a[j + 1]);
			}
		

	}


    cout << count << endl; 
	return 0;
}

Measured memory_bytes: 1024