akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
#define INT(...) int __VA_ARGS__;in(__VA_ARGS__)
#define LL(...) ll __VA_ARGS__;in(__VA_ARGS__)
#define ULL(...) ull __VA_ARGS__;in(__VA_ARGS__)
#define STR(...) string __VA_ARGS__;in(__VA_ARGS__)
#define CHR(...) char __VA_ARGS__;in(__VA_ARGS__)
#define DBL(...) double __VA_ARGS__;in(__VA_ARGS__)
#define vec(type,name,...) vector<type> name(__VA_ARGS__)
#define VEC(type,name,size) vector<type> name(size);in(name)
#define vv(type,name,h,...) vector<vector<type>>name(h,vector<type>(__VA_ARGS__))
#define VV(type,name,h,...) vector<vector<type>>name(h,vector<type>(__VA_ARGS__));in(name)
#define vvv(type,name,h,w,...) vector<vector<vector<type>>>name(h,vector<vector<type>>(w,vector<type>(__VA_ARGS__)))
inline int scan(){ return getchar(); }
inline void scan(int &a){ scanf("%d", &a); }
inline void scan(unsigned &a){ scanf("%u", &a); }
inline void scan(long &a){ scanf("%ld", &a); }
inline void scan(long long &a){ scanf("%lld", &a); }
inline void scan(unsigned long long &a){ scanf("%llu", &a); }
inline void scan(char &a){ cin >> a; }
inline void scan(float &a){ scanf("%f", &a); }
inline void scan(double &a){ scanf("%lf", &a); }
inline void scan(long double &a){ scanf("%Lf", &a); }
inline void scan(vector<bool> &vec){ for(unsigned i = 0; i < vec.size(); i++) { int a; scan(a); vec[i] = a; } }
inline void scan(string &a){ cin >> a; }
template<class T> inline void scan(vector<T> &vec);
template<class T, size_t size> inline void scan(array<T, size> &vec);
template<class T, class L> inline void scan(pair<T, L> &p);
template<class T, size_t size> inline void scan(T (&vec)[size]);
template<class T> inline void scan(vector<T> &vec){ for(auto &i : vec) scan(i); }
template<class T, size_t size> inline void scan(array<T, size> &vec){ for(auto &i : vec) scan(i); }
template<class T, class L> inline void scan(pair<T, L> &p){ scan(p.first); scan(p.second); }
template<class T, size_t size> inline void scan(T (&vec)[size]){ for(auto &i : vec) scan(i); }
template<class T> inline void scan(T &a){ cin>>a; }
inline void in(){}
template <class Head, class... Tail> inline void in(Head &head, Tail&... tail){ scan(head); in(tail...); }
inline constexpr ll gcd(ll a,ll b){if(!a||!b)return 0;while(b){ll c=b;b=a%b;a=c;}return a;}
inline constexpr ll lcm(ll a,ll b){if(!a||!b)return 0;return a*b/gcd(a,b);}
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
using Graph = vector<vector<int>>;
/* 4方向への隣接頂点への移動を表すベクトル */
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};

const long long INF = 1LL << 60;

int main(){
    LL(N,K);
    ll point = 0LL;
    double ans = 0.0;
    for(ll i = 1; i <= N; ++i){
        point = i;
        double cnt = 0.0;
        while(1 <= point  && point <= K - 1){
            cnt++;
            point *= 2;
        }
        ans += pow((double)0.5,cnt);
    }
    cout << setprecision(12) << ans/N << endl;  
}

Measured memory_bytes: 256
#include"bits/stdc++.h"
using namespace std;
#define REP(k,m,n) for(int (k)=(m);(k)<(n);(k)++)
#define rep(i,n) REP((i),0,(n))
using ll = long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using tp3 = tuple<int, int, int>;
using Mat = vector<vector<ll>>;
constexpr int INF = 1 << 28;
constexpr ll INFL = 1ll << 60;
constexpr int dh[4] = { 0,1,0,-1 };
constexpr int dw[4] = { -1,0,1,0 };
bool isin(const int H, const int W, const int h, const int w) {
    return 0 <= h && h < H && 0 <= w && w < W;
}
// ============ template finished ============

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

    map<ll, ll> primes;
    for (int i = 2; i <= sqrt(N); i++) {
        while (N%i == 0) {
            primes[i]++;
            N /= i;
        }
    }
    if (N != 1)primes[N]++;

    ll res = 0;
    for (auto itr : primes) {
        ll cnt = itr.second;
        for (int i = 1; i < 100; i++) {
            if (i <= cnt) {
                cnt -= i;
                res++;
            }
            else {
                break;
            }
        }
    }
    cout << res << endl;
    return 0;
}


Measured memory_bytes: 3720
# frozen_string_literal: true
n = gets.to_i
h = gets.split.map(&:to_i)
sum = 0
temp = 0
(n - 1).times do |i|
  if h[i + 1] <= h[i]
    temp += 1
  else
    sum = temp if sum <= temp
    temp = 0
  end
end
sum = temp if sum <= temp
puts sum

Measured memory_bytes: 8580
#include<iostream>
#include<math.h>
#include<stdlib.h>
#include<string>
#include<limits.h>
#include<utility>
#include<vector>
#include<tuple>
#include<algorithm>
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
#define rep(i,n) for(int i=0;i<n;i++)
#define ALL(A) A.begin(),A.end()
vector<vector<bool>> seat;

int main() {
	int n;
	double d;
	cin >> n>>d;
	ll ans = 0;
	rep(i, n) {
		double x, y;
		cin >> x >> y;
		if (x * x + y * y <= d * d) {
			ans++;
		}
	}
	cout << ans << endl;
}


Measured memory_bytes: 3188
#include <iostream>
#include <cstring>
#include <stdlib.h>
#include <vector>
#include <algorithm>
#include <cmath>
#include <stack>
#include <queue>
#include <math.h>

using namespace std;

int main()
{
    int n, a;
    cin >> n >> a;
    cout << n*n-a;
    
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <stdio.h>
using namespace std;

const int MAXN = 2e5 + 10;
int a[MAXN];

int main(void){
    int n;
    scanf("%d", &n);
    for(int i = 0; i < n; i++){
        scanf("%d", &a[i]);
    }
    int index = n - 1;
    while(index >= 0){
        printf("%d ", a[index]);
        index -= 2;
    }
    if(index == -1) index = 0;
    else index = 1;
    while(index < n){
        printf("%d ", a[index]);
        index += 2;
    }
    printf("\n");
    return 0;
}

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

const int M=2e5+5;
int cnt[M];

int main()
{
	int n; scanf("%d",&n);
	int ai;
	for(int i=1;i<n;i++)
	{
		scanf("%d",&ai);
		cnt[ai]++;
	}
	for(int i=1;i<=n;i++)
		printf("%d\n",cnt[i]);
	return 0;
}

Measured memory_bytes: 4492
#include<iostream>
#include<string>
#include<cstdio>
#include<vector>
#include<cmath>
#include<algorithm>
#include<functional>
#include<iomanip>
#include<queue>
#include<ciso646>
#include<random>
#include<map>
#include<set>
#include<complex>
#include<bitset>
#include<stack>
#include<unordered_map>
using namespace std;
typedef long long ll;
typedef unsigned int ui;
const ll mod = (1e+9)+7;
const ll INF = (ll)1000000007 * 1000000007;
typedef pair<int, int> P;
#define stop char nyaa;cin>>nyaa;
#define rep(i,n) for(int i=0;i<n;i++)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define per1(i,n) for(int i=n;i>=1;i--)
#define Rep1(i,sta,n) for(int i=sta;i<=n;i++)
typedef long double ld;
typedef complex<ld> Point;
const ld eps = 1e-8;
const ld pi = acos(-1.0);
typedef pair<ll, ll> LP;
typedef pair<ld, ld> LDP;
map<string, priority_queue<int,vector<int>,greater<int>>> mp;
int main(){
	int n; cin >> n;
	rep(i, n) {
		string s; int d; cin >> s >> d;
		mp[s].push(d);
	}
	string ans = "Yes";
	int m; cin >> m;
	int now = -1;
	rep(i, m) {
		string s; cin >> s;
		bool added = false;
		while (!mp[s].empty()) {
			int x = mp[s].top(); mp[s].pop();
			if (x > now) {
				now = x; added = true; break;
			}
		}
		if (!added)ans = "No";
	}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 21980
#include <bits/stdc++.h>
using namespace std;
 
int main(){
int N;  cin >> N;
vector<int> A(N); 
int first = 0;
int second = 0;
for (int i = 0; i < N; i++) {
    cin >> A[i];
    vector<int> B = {first, second, A[i]};
    sort(B.begin(), B.end());
    first = B[2];
    second = B[1];
}

for (int i = 0; i < N; i++) {
    if (A[i] == first) cout << second << endl;
    else cout << first << endl;
}

}

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

int main() {
  long long S, mod=pow(10, 9)+7;
  cin >> S;
  long long T=S/3;
  long long x=0;
  for (long long i=1; i<=T; i++) {
    long long s=S-3*i;
    if (s==0) {
      x+=1;
      x=x-x/mod*mod;
      continue;
    }
    vector<vector<long long>> V(s, vector<long long>(i, 1));
    for (long long j=0; j<i; j++) {
      V[0][j]=j+1;
    }
    for (long long j=1; j<s; j++) {
      for (long long k=1; k<i; k++) {
        V[j][k]=V[j][k-1]+V[j-1][k];
        V[j][k]=V[j][k]-V[j][k]/mod*mod;
      }
    }
    x+=V[V.size()-1][V[0].size()-1];
    x=x-x/mod*mod;
  }
  cout << x << endl;
}

Measured memory_bytes: 6076
#include <iostream>
#include <string>
#include <vector>


std::string find(std::vector<std::vector<int>> dp, std::string s, std::string t) {
    std::string res = "";
    int i = (int)s.size();
    int j = (int)t.size();
    while(i > 0 && j > 0) {
        if(s[i-1] == t[j-1]) {
            res = s[i-1] + res;
            --i;
            --j;
        } else if(dp[i][j] == dp[i-1][j]) {
            --i;
        } else {
            --j;
        }
    }
    return res;
}

int main() {
    std::string s, t;
    std::getline(std::cin, s);
    std::getline(std::cin, t);
    std::vector<std::vector<int>> dp(s.size()+1, std::vector<int>(t.size()+1));
    for(int i = 0; i < s.size()+1; ++i) {
        dp[i][0] = 0;
    }
    for(int j = 0; j < t.size()+1; ++j) {
        dp[0][j] = 0;
    }
    for(int i = 1; i < s.size()+1; ++i) {
        for(int j = 1; j < t.size()+1; ++j) {
            if(s[i-1] == t[j-1]) {
                dp[i][j] = std::max(1 + dp[i-1][j-1], std::max(dp[i-1][j], dp[i][j-1]));
            } else {
                dp[i][j] = std::max(dp[i-1][j], dp[i][j-1]);
            }
        }
    }
    std::cout << find(dp, s, t) << "\n";
    return 0;
}


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

int main(){
    uint32_t n;
    std::cin >> n;
    std::vector<char> str(n, 0);
    for(int i=0; i<n; i++){
        std::cin >> str[i];
    }

    if((n % 2) == 1){
        std::cout << "No" << std::endl;
        return 0;
    }

    for(int k=0; k<(n/2); k++){
        if(str[k] != str[k+(n/2)]){
            std::cout << "No" << std::endl;
            return 0;
        }
    }

    std::cout << "Yes" << std::endl;
    return 0;
}

Measured memory_bytes: 888
#include <bits/stdc++.h>
using namespace std::literals::string_literals;
using i64 = long long;
using std::cout;
using std::endl;
using std::cin;

template<typename T>
std::vector<T> make_v(size_t a){return std::vector<T>(a);}

template<typename T,typename... Ts>
auto make_v(size_t a,Ts... ts){
  return std::vector<decltype(make_v<T>(ts...))>(a,make_v<T>(ts...));
}

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

	auto getType = [](std::string s) {
		if(s == "Vacant") return 0;
		if(s == "Female") return 1;
		if(s == "Male") return 2;
	};
	
	int left = 0, right = n - 1;
	std::string L, R;
	
	cout << left << endl;
	cin  >> L;
	if(L == "Vacant") return 0;

	cout << right << endl;
	cin >> R;
	if(R == "Vacant") return 0;
	
	while(true) {
		int mid = (left + right) >> 1;
		cout << mid << endl;
		std::string M; cin >> M;
		if(M == "Vacant") return 0;

		if((right - mid + 1) % 2 != (M == R)) {
			left = mid;
			L = M;
		} else {
			right = mid;
			R = M;
		}
	}
	return 0;
}


Measured memory_bytes: 852
#include <iostream>
#include<bits/stdc++.h>
using namespace std;
vector<int> graph[100002];
int dp[100002];
int dfs(int src)
{
    int ans=0;

    if(dp[src]!=-1)
    {
        return dp[src];
    }
    for(int i=0;i<graph[src].size();i++)
    {
        int v=graph[src][i];
        ans=max(ans,dfs(v)+1);
    }
    return dp[src]=ans;
}
int main() {
    int n,m;
    cin>>n>>m;
    for(int i=0;i<m;i++)
    {
        int u,v;
        cin>>u>>v;
        graph[u].push_back(v);
    }

    int max_ans=0;
    memset(dp,-1,sizeof(dp));
    for(int i=1;i<=n;i++)
    {
        max_ans=max(max_ans,dfs(i));
    }
    cout<<max_ans<<endl;
}


Measured memory_bytes: 11492
#include<cstdio>
#include<cstring>
#include<iostream>
using namespace std;
int main() {
	char n[10];
	cin>>n+1;
	for(int i=1;i<=3;i++)
		{
			if(n[i]=='9') printf("1");
			else printf("9");
		}
		printf("\n");
		return 0;
	}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
const long long mod=1e9+7;

int main(void) {
    int N,M;
    cin>>N>>M;

    vector<int>oks(N+1,true);
    for (int i = 0; i < M; ++i) {
        int a;cin>>a;
        oks[a]=false;
    }

    vector<long long int>dp(N+1);
    dp[0]=1;
    for (int i = 0; i < N; ++i) { 
        for (int j = i+1; j <=min(N,i+2); ++j) {
            if(oks[j]) {
                dp[j]+=dp[i];
                dp[j]%=mod;
            }
        }
    }

    cout<<dp[N]<<endl;
    return 0;
}

Measured memory_bytes: 1408
#include<stdio.h>
#include<algorithm>
#include<string.h>
#include<string>
#include<math.h>
#include<stdlib.h>
#include<time.h>
#include<map>
#include<queue>
#include<set>
#define fo(i,a,b) for(int i=a;i<=b;i++)
#define fd(i,a,b) for(int i=a;i>=b;i--)
using namespace std;
int d0[50],d1[50],m,mm;
long long ans,d,wei,te,ten[18];
//81000 wei+3
void dfs(int x,long long v,long long s){
	//if (abs(v)>d*10000) return;//12
	if (v<-d*105) return;
	if (v>d*105&&v>(ten[m-x]-ten[x-1])*105) return;
	//printf("%d %lld %lld\n",x,v,s);
	if (x>mm){//>m
		if (v==d){
			//printf("%d %lld %lld\n",x,v,s);
			if (m&1) ans+=s*10;else ans+=s;//(m>2)&&
		}
		return;
	}
	if (x==1){
		fo(i,-9,8) dfs(x+1,v+i*(ten[m-x]-ten[x-1]),s*d1[i+20]);//m-i+1 i
		return;
	}
	fo(i,-9,9) dfs(x+1,v+i*(ten[m-x]-ten[x-1]),s*d0[i+20]);
}
inline void sol(int wei){
	if (wei<=1) return;
	m=wei;mm=m/2;
	dfs(1,0,1);
}
int main(){
	scanf("%lld",&d);
	if (d%9!=0){
		printf("0\n");
		return 0;
	}
	if (d==9){
		printf("8\n");
		return 0;
	}
	ten[0]=1;fo(i,1,17) ten[i]=ten[i-1]*10;
	fo(i,0,9) fo(j,0,9) d0[i-j+20]++;
	fo(i,0,9) fo(j,1,9) d1[i-j+20]++;
	te=d;
	while (te){
		wei++;
		te/=10;
	}
	//printf("%lld\n",wei);
	fo(i,-9,9) sol(wei+i);//-8..8
	printf("%lld\n",ans);
	return 0;
}

Measured memory_bytes: 128
import sys
N = int(input())
A = list(map(int, input().split()))
i = 0
cnt = 0
while i < N:
    while i < N - 1 and A[i + 1] == A[i]:
        i += 1
    if i >= N - 1:
        cnt += 1
        print(cnt)
        sys.exit()
    if A[i + 1] < A[i]:
        while i < N - 1 and A[i + 1] <= A[i]:
            i += 1
    else:
        while i < N - 1 and A[i + 1] >= A[i]:
            i += 1
    cnt += 1
    i += 1
print(cnt)


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

typedef long long ll;
#define MOD = 1000000007;
#define rep(i, n) for(int i = 0; i < (n); i++)
#define ALL(a) begin(a),end(a)
#define COUNTOF(a) (sizeof(a)/sizeof(a[0]))
template<class T> istream& operator >> (istream& s, vector<T>& v)
{ for (T& x: v) { s >> x; } return s;}
template<class T> inline bool chmin(T& a, T b) {return a>b?a=b,true:false;}
template<class T> inline bool chmax(T& a, T b) {return a<b?a=b,true:false;}
template<class T> inline bool is_overlap(const T& as, const T& ae, const T& bs, const T& be)
{ return bs <=ae && as <= be; }
#define SP << " " <<
#define FMT(a) #a<<":"<<a 
#define FMT2(a,b) #a<<":"<<a<<", "<<#b<<":"<<b 
#define FMT3(a,b,c) #a<<":"<<a<<", "<<#b<<":"<<b<<", "<<#c<<":"<<c 
#define FMT4(a,b,c,d) #a<<":"<<a<<", "<<#b<<":"<<b<<", "<<#c<<":"<<c<<", "<<#d<<":"<<d 
#define ANS(a) cout<<a<<endl
void yes(bool f){cout<<(f?"yes":"no")<<endl;}
void Yes(bool f){cout<<(f?"Yes":"No")<<endl;}
void YES(bool f){cout<<(f?"YES":"NO")<<endl;}

int main()
{
    cin.tie(0); ios::sync_with_stdio(false);
    //cout<<std::fixed<<std::setprecision(10);

    int N;
    cin >> N;
    vector<int> A(N), B(N), C(N-1);
    cin >> A >> B>> C;

    int ans = 0;
    rep (i, N) {
        ans += B[A[i] - 1];
        if (i != 0 && A[i - 1] + 1 == A[i]) {
            ans += C[A[i - 1] - 1];
        }
    }

    cout << ans << endl;
}


Measured memory_bytes: 256
main(n,m,s,c,i){for(;scanf("%d%d ",&n,&m)*n;printf("%d\n",s))for(s=c=i=0;i<m;i++,c%2&&c/2>=n&&s++)getchar()-79?c%2?c=1:c++:c%2?c++:(c=0);}

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

int p[250000];

int main() {
  memset(p, 0, sizeof(p));
  for(int i=4; i<250000; i+=2) p[i] = 1;
  for(int i=3; i*i<250000; i+=2)
    if(p[i] == 0)
      for(int j=2; i*j<250000; ++j)
        p[i*j] = 1;

  int n;
  while(cin>>n, n) {
    int cnt = 0;
    for(int i=n+1; i<=2*n; ++i)
      if(p[i] == 0) cnt++;
    cout<<cnt<<endl;
  }
}

Measured memory_bytes: 0
N, X = map(int, input().split())

a, p = [1], [1]
for i in range(N-1):
    a.append(3 + 2 * a[i])
    p.append(1 + 2 * p[i])


def f(N, X):
    if N == 0:
        return 0 if X <= 0 else 1
    elif X <= a[N-1] + 1:
        return f(N-1, X-1)
    else:
        return p[N-1] + 1 + f(N-1, X - (a[N-1]+2))

print(f(N, X))	

Measured memory_bytes: 3064
#include<iostream>
using namespace std;
#define MAX 500000
#define SENTINEL 2000000000

int L[MAX / 2 + 2], R[MAX / 2 + 2];
int cnt;

void merge(int A[], int n, int left, int mid, int right){
  int n1 = mid - left;
  int n2 = right - mid;
  for(int i = 0 ; i < n1 ; i++) L[i] = A[left + i];
  for(int i = 0 ; i < n2 ; i++) R[i] = A[mid + i];
  L[n1] = R[n2] = SENTINEL;
  int i = 0, j = 0;
  for(int k = left ; k < right ; k++){
    cnt++;
    if(L[i] <= R[j]){
      A[k] = L[i++];
    }
    else{
      A[k] = R[j++];
    }
  }
}

void mergeSort(int A[], int n, int left, int right){
  if(left + 1 < right){
    int mid = (left + right) / 2;
    mergeSort(A, n, left, mid);
    mergeSort(A, n, mid, right);
    merge(A, n, left, mid, right);
  }
}

int main(){
  int A[MAX], n, i;
  cnt = 0;

  cin >> n;

  for(i = 0 ; i < n ; i++) cin >> A[i];

  mergeSort(A, n, 0, n);
  
  for(i = 0 ; i < n ; i++){
    if( i ) cout << " ";
    cout << A[i];
  }
  cout << endl;

  cout << cnt << endl;

  return 0;
}


Measured memory_bytes: 6900
def solve(n, H):
    dp = [0] * n
    dp[0] = 0
    dp[1] = abs(H[0] - H[1])
    for i in range(2, n):
        dp[i] = min(
            dp[i - 1] + abs(H[i] - H[i - 1]),
            dp[i - 2] + abs(H[i] - H[i - 2])
        )
    return dp[n - 1]

_n = int(input())
_H = list(map(int, input().split()))
print(solve(_n, _H))


Measured memory_bytes: 13928
n = gets.to_i
marches = [0,0,0,0,0]

n.times do
  case gets()[0]
  when "M"
    marches[0] += 1
  when "A"
    marches[1] += 1
  when "R"
    marches[2] += 1
  when "C"
    marches[3] += 1
  when "H"
    marches[4] += 1
  end
end

ans = 0
([0,1,2,3,4]).combination(3) {|a, b, c|
  ans += marches[a] * marches[b] * marches[c]
}

puts ans.to_s

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

int main() {
	
	int n,k;
	cin >> n >> k;
	
	vector<int> v(n);
	for(int i=0; i<n; ++i)
	cin >> v[i];
	
	vector<bool> dp(k+1);
	for(int stones=0; stones<=k; ++stones) {
		for(int i=0; i<n; ++i) {
			if(stones >= v[i] && !dp[stones-v[i]])
			dp[stones] = true;
		}
	}
	
	if(dp[k])
	cout << "First" << endl;
	else
	cout << "Second" << endl;
	
	return 0;
	
}

Measured memory_bytes: 3608
#include <iostream>
#include <algorithm>
#include <deque>
using namespace std;
typedef long long lint;
typedef pair<lint,lint> pp;

lint N;
const int MAX_N = 2005;
const lint MOD = 1e9+7;
lint d[61][MAX_N];
lint dp[61][4];

int sol(int n){
	d[0][0] = d[0][1] = d[0][2] = 1;
	for(lint i=1;i<=60;i++){
		for(lint j=0;j<=n;j++){
			d[i][j] = d[i-1][j];
			if(j>=(1ll<<i))d[i][j] += d[i-1][j-(1ll<<i)];
			if(j>=(2ll<<i))d[i][j] += d[i-1][j-(2ll<<i)];
			d[i][j] %= MOD;
		}
	}
	lint ret = 0;
	for(lint i=0;i<=N;i++){
		ret += d[60][i];
		ret %= MOD;
	}
	return ret;
}

lint f(lint n,lint k){
	for(int i=k-1;i>=0;i--){
		if(n>>i&1){
			if(n==(2ll<<i)-1)return (k-1)*dp[i+1][0]%MOD;
			return ((k-i)*(f(n^(1ll<<k),i)+dp[i][0]))%MOD;
		}
	}
	return k+1;
}

void init(deque<pp>& a){
	sort(a.begin(),a.end());
	for(int i=1;i<(int)a.size();i++){
		if(a[i-1].first==a[i].first){
			a[i].second += a[i-1].second;
			a[i].second %= MOD;
			a[i-1].first = -1;
		}
	}
	sort(a.begin(),a.end());
	while(!a.empty()&&a[0].first<0)a.pop_front();
}

int main(){
	ios::sync_with_stdio(false);

	cin>>N;
	lint k;
	for(k=1;k<=N;k<<=1);
	k--;

	deque<pp> a;
	a.push_back({k-N,1});
	a.push_back({k-N+1,1});
	a.push_back({k-N+2,1});
	a.push_back({k-N+3,0});
	lint i;
	for(i=1;i<=60;i++){
		for(auto& j:a){
			if(j.first<4){
				dp[i-1][j.first] += j.second;
				dp[i-1][j.first] %= MOD;
				j.first = -1;
			}
			j.first>>=1;
		}
		init(a);
		int l = a.size();
		for(int j=0;j<l;j++){
			a.push_back({a[j].first+1,a[j].second});
			a.push_back({a[j].first+2,a[j].second});
		}
		init(a);

		if((1ll<<i)>k)break;
		for(int j=0;j<2;j++){
			dp[i][j] += dp[i-1][j*2]+dp[i-1][j*2+1]; 
			dp[i][j] %= MOD;
		}
		for(int j=3;j>=0;j--){
			if(j>=2)dp[i][j] += dp[i][j-2];
			if(j>=1)dp[i][j] += dp[i][j-1];
			dp[i][j] %= MOD;
		}
	}

	cout << (dp[i-1][0]+dp[i-1][1])%MOD << endl;
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
    string s;
    cin >> s;
    int t=s.size();
    stack<char>st;
    for(int i=0; i<s.size(); i++)
    {
        if(st.size()&&st.top()!=s[i])
            st.pop();
        else
            st.push(s[i]);
    }
    cout << t-st.size() << endl ;
    return 0;
}


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

#define fr(i,n) _back
#define pb	push_back
#define eb	emplace_back
#define mk	make_pair
#define fi	first
#define se	second
#define endl	'\n'

typedef long long ll;
typedef pair<int,int> ii;
typedef vector<ii> vii;
const int INF = 0x3f3f3f3f;
const double PI = acos(-1.0);
const int N = 300;

int n,m,gol;
ll dp[10][N];
vector<int> g[10];

ll solve(int u, int mask) {
    if(mask == gol) return 1;
    ll &r = dp[u][mask];
    if(~r) return r;
    r = 0;

    for(int v : g[u]) {
        if(mask & (1 << v)) continue;
        r += solve(v, mask | (1 << v));
    }

    return r;
}

int main() {
    ios_base::sync_with_stdio(false);
    memset(dp,-1,sizeof dp);
    cin >> n >> m;
    gol = pow(2,n)-1;

    while(m--) {
        int a,b; cin >> a >> b;
        a--; b--;
        g[a].pb(b);
        g[b].pb(a);
    }

    cout << solve(0,1) << endl;

    return 0;
}


Measured memory_bytes: 256
N = int(input())
A1 = list(map(int, input().split()))
A2 = list(map(int, input().split()))
max = 0
for x in range(0, N):
    count = 0
    for i in range(0, x+1):
        count = count+A1[i]
    for i in range(x, N):
        count = count+A2[i]
    if max<count:
        max = count
print("{}".format(max))


Measured memory_bytes: 3060
INF=10**15
N,M,L=map(int,input().split())
d=[[INF for i in range(N)] for j in range(N)]
d1=[[INF for i in range(N)] for j in range(N)]
for i in range(N):
    d[i][i]=0
for m in range(M):
    A,B,C=map(int,input().split())
    d[A-1][B-1]=C
    d[B-1][A-1]=C

for k in range(N):
    for i in range(N):
        for j in range(N):
            d[i][j]=min(d[i][j],d[i][k]+d[k][j])
for i in range(N):
        for j in range(N):
            if i!=j and d[i][j]<=L:
                d1[i][j]=1
                d1[j][i]=1
for k in range(N):
    for i in range(N):
        for j in range(N):
            d1[i][j]=min(d1[i][j],d1[i][k]+d1[k][j])

Q=int(input())
for _ in range(Q):
    s,t=map(int,input().split())
    dis=d1[s-1][t-1]
    if dis==INF:
        print(-1)
    else:
        print(dis-1)



Measured memory_bytes: 61020
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <cctype>
#include <cassert>
#include <climits>
 #include <iostream>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <cctype>
#include <cassert>
#include <climits>
#include <string>
#include <bitset>
#include <cfloat>
#include <unordered_set>
#pragma GCC optimize('Ofast')
using namespace std;
typedef long double ld;
typedef long long int ll;
typedef unsigned long long int ull;
typedef vector<int> vi;
typedef vector<char> vc;
typedef vector<bool> vb;
typedef vector<double> vd;
typedef vector<string> vs;
typedef vector<ll> vll;
typedef vector<pair<int,int> > vpii;
typedef vector<vector<int> > vvi;
typedef vector<vector<char> > vvc;
typedef vector<vector<string> > vvs;
typedef vector<vector<ll> > vvll;
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define irep(it, stl) for(auto it = stl.begin(); it != stl.end(); it++)
#define drep(i,n) for(int i = (n) - 1; i >= 0; --i)
#define fin(ans) cout << (ans) << endl
#define mp(p,q) make_pair(p, q)
#define pb(n) push_back(n)
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define Sort(a) sort(a.begin(), a.end())
#define Rort(a) sort(a.rbegin(), a.rend())
#define MATHPI acos(-1)
int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};
template <class T> inline bool chmax(T& a,T b){if(a<b){a=b;return 1;} return 0;}
template <class T> inline bool chmin(T& a,T b){if(a>b){a=b;return 1;} return 0;}
struct io{io(){ios::sync_with_stdio(false);cin.tie(0);}};
const int INF = INT_MAX;
const ll LLINF = 1LL<<60;
const ll MOD = 1000000007;
const double EPS = 1e-9;
int main(void) {
    ll N,K;
    cin >> N >> K;
    vll A(N),Max(N+1);//maxは例えば３なら２までのmaxが入る
    int m = -1;
    rep(i,N){ 
        cin >> A[i];
        Max[i+1] = A[i];//まずは普通に高さを入れるだけ
        };
    rep(i,N) {
        Max[i+1] = max(Max[i+1],Max[i]);//直前までのmaxを入れる
    }
    
    ll value=LLINF;
    rep(bit,1<<N){
        //操作するidxを保管
        vll idxs;
        rep(i,N){
            if(bit&1<<i){
                idxs.push_back(i);
            }
        }

        if(idxs.size() != K) continue;
        ll maxH = 0 ,res=0;
        rep(i,K){
            maxH = max(maxH,Max[idxs[i]]);

            if(A[idxs[i]] <= maxH){
                //ここで操作するidxをそのidxまでのmax+1としてmaxH++、resはどれだけお金を費やしたか
                maxH++;
                res += maxH - A[idxs[i]];
            }else{
                maxH = A[idxs[i]];
            }
        }

        value = min(value,res);



    }
    fin(value);

}




Measured memory_bytes: 256
#include<bits/stdc++.h>
#define y first
#define s second
#define m second.first
#define d second.second 
using namespace std;

typedef pair<int,int> p;
typedef pair<int,p> P;

int main(){
  P a,b;
  cin>>a.y>>a.m>>a.d>>b.y>>b.m>>b.d;
  if(a>b)swap(a,b);
  int ans=b.y-a.y;
  if(a.s<b.s)ans++;
  cout<<ans<<endl;
  return 0;
}

Measured memory_bytes: 3100
def a():return input()#s
def ai():return int(input())#a,n or k
def ma():return map(int, input().split())#a,b,c,d or n,k
def ms():return map(str, input().split())#,a,b,c,d
def lma():return list(map(int, input().split()))#x or y
def lms():return list(map(str, input().split()))#x or y
a = ai()
x = lma()
print(sum(x)-a)

Measured memory_bytes: 3316
#include<iostream>

using namespace std;

int main()
{
	long long a,b,c;
	cin >> a >> b >> c;
	if(a%2==1 and b%2==1 and c%2==1)
	{
		cout << min(a*b,min(b*c,c*a)) << endl;
		return 0;
	}
	cout << 0 << endl;
}

Measured memory_bytes: 256
def main():
    N = int(input())
    A = [0] + [int(i) for i in input().split()] + [0]
    S = sum((abs(A[i] - A[i+1]) for i in range(N+1)))
    for i in range(1, N+1):
        print(S + abs(A[i-1] - A[i+1]) -
              (abs(A[i-1] - A[i]) + abs(A[i] - A[i+1])))


if __name__ == '__main__':
    main()


Measured memory_bytes: 65772
import java.util.*;

public class Main{
  public static void main(String[] args) {
    Scanner in = new Scanner(System.in);
    String[] input = in.nextLine().split(" ");
    in.close();

    int result = 0;
    
    Stack<Integer> numbers = new Stack<Integer>();
    
    for (int i = 0; i < input.length; i++) {
      try {
        numbers.push(Integer.parseInt(input[i]));
      } catch(Exception e) {
        //pop last two from stack and compute
        int second = numbers.pop();
        int first = numbers.pop();
        
        // evaluate based on operator
        if (input[i].equals("+")) {
          result = first + second;
        } else if (input[i].equals("-")) {
          result = first - second;
        } else {
          result = first * second;
        }
        numbers.push(result);
      }
    }
    // print results
    System.out.println(result);
  }
}


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

int main()
{
	int64_t n, a, b;
	cin >> n >> a >> b;

	if ((b - a) % 2 == 0)
	{
		cout << (b - a) / 2 << endl;
	}
	else
	{
		cout << min({n - a, b - 1, (n - b) + (b - a) / 2 + 1, (a - 1) + (b - a) / 2 + 1}) << endl;
	}

	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <cmath>
#include <vector>
#include <string>
#include <algorithm>
#include <cstdlib>
#include <limits>
#include <numeric>

using namespace std;

int main()
{
	string a;
	cin >> a;
	a.replace(5, 1, " ");
	a.replace(13, 1, " ");

	cout << a << endl;

	return 0;
}

Measured memory_bytes: 256
//パソコン甲子園2010 問題番号03 塾のクラス分け
#include<stdio.h>

int main(void){

	int i1, i2, i3, n, pm, pe, pj, ave1, ave2;

	scanf("%d",&n);
	while(n != 0){

		for(i1 = 1; i1 <= n; i1++){

			scanf("%d %d %d",&pm,&pe,&pj);

			ave1 = (pm + pe + pj) / 3;
			ave2 = (pm + pe) / 2;
			i2 = pm;

			if(i2 < pe) i2 = pe;

			if(i2 < pj) i3 = pj;
			else		i3 = i2;

			if(i3 == 100 || ave1 >= 80 || ave2 >= 90)
				printf("A\n");
			else if( ave1 >= 70 || ( ave1 >= 50 && i2 >= 80 ) )
				printf("B\n");
			else
				printf("C\n");

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

	}
	return 0;
}

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

int main(){
  int a, b, c, d;
  cin >> a >> b >> c >> d;
  while (true) {
    c -= b;
    a -= d;
    if (c <= 0) {
      cout << "Yes" << endl;
      break;
    }
    if (a <= 0) {
      cout << "No" << endl;
      break;
    }
  }
}

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

int main(){
  int N,K; cin >> N >> K;
  //明らかに,1を含めて連続したK個をはじめに選ぶ必要が有る.
  vector<int> A(N);
  for(int i = 0;i < N;i++)cin >> A[i];
  vector<int> v(N,0);

  int ans = 0;
  int now_index = 0;
  while(v[N-1] == 0){
    for(int i = 0;i < K;i++){
      if(now_index+i <= N-1)v[now_index + i] = 1;
      else break;
    }
    now_index = now_index + K-1;
    ans++;
  }

  cout << ans << endl;

}


Measured memory_bytes: 1024
/*
author: Apoorv Singh
*/

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

typedef vector <long long> vi;
typedef pair <long long, long long> pii;
#define pb push_back   
#define all(c) c.begin(), c.end()
#define FOR(i, a, b) for (long long i = a; i < b; ++i)
#define FORR(i, a, b) for (long long i = a; i > b; --i)
#define um unordered_map
#define F first
#define S second
#define int long long
#define inf LLONG_MAX
#define endl "\n"
#pragma comment(linker, "/stack:200000000")
#pragma GCC optimize ("O3")
#pragma GCC optimize ("unroll-loops")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#define _CRT_SECURE_NO_WARNINGS

#define TRACE
#ifndef ONLINE_JUDGE
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
    cout << name << " : " << arg1 << endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
    const char* comma = strchr(names + 1, ',');cout.write(names, comma - names) << " : " << arg1<<" | ";__f(comma+1, args...);
}
#else
#define trace(...)
#endif

template <class X>
void printarr(X arr[], int n)
{
    for (int i = 0; i < n; ++i)
        cout << arr[i] << " ";
    cout << endl;
}
template <typename X> ostream& operator << (ostream& x,const vector<X>& v){ for (X a : v) x << a << ' '; return x;} 
template <typename X, typename Y> ostream& operator << (ostream& x, const vector< pair<X, Y> >& v) {for (pair <X, Y> it : v) x << it.first << ' ' << it.second << endl; return x;} 
template <typename T, typename S> ostream& operator << (ostream& os, const map<T, S>& v) { for (pair <T, S> it : v) os << it.first << " => " << it.second << endl; return os; }

double pi = 3.14159265358979323846264338327950288419716939937510582097494459230;
int modulo = 1e9 + 7;

int fpow(int a, int n)
{
    int ans = 1;
    while (n)
    {
        if (n&1)
            ans = (ans * a)%modulo;
        a = (a*a)%modulo;
        n = n >> 1;
    }
    return ans;
}

/*
const int M = 1e6 + 10;
int composite[M] = {0};

void sieve()
{
    FOR(i,2,M)
    {
        if (!composite[i])
        {
            for (int j = 2*i; j < M; j += i)
                composite[j] = max(composite[j], i);
        }
    }
}
*/

signed main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    int n,k; cin >> n >> k;
    int maxi = ((n-1)*(n-2))/2;
    if (maxi < k)
    {
        cout << -1;
        return 0;
    }
    vector <pii> ans;
    FOR(i,2,n+1) ans.pb({1,i});
    int curr = maxi, valid = 0;
    FOR(i,2,n+1)
    {
        FOR(j,i+1,n+1)
        {
            if (curr == k)
            {
                valid = 1;
                break;
            }
            ans.pb({i,j});
            --curr;
        }
        if (valid) break;
    }
    cout << ans.size() << endl;
    for (pii a : ans) cout << a.F << ' ' << a.S << endl;
    return 0;
}

Measured memory_bytes: 512
#include<stdio.h>

int main(){
	
	int a,b,d,r;
	double f;
	
	scanf("%d %d",&a,&b);
	
	d=a/b, r=a%b, f=(double)a/(double)b;
	
	printf("%d %d %.8lf\n",d,r,f);
	
	return 0;
	
}

Measured memory_bytes: 640
# -*- coding: utf-8 -*-
x = int(input())

ans = 1
for i in range(x + 1):
    for j in range(int(pow(x, 0.5)) + 1):
        for k in range(int(pow(x, 0.5)) + 1):
            if i == pow(j, k) and ans < i:
                ans = i
print(ans)


Measured memory_bytes: 2940
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()
const double PI = acos(-1);
const ll MOD = 1000000007;
using Graph = vector<vector<int>>;

ll N,K;
vector<ll> A,F;
bool f(ll x) {
  ll k = K;
  rep(i,N) {
    k -= max(A[i] - x / F[i],ll(0));
    if (k < 0) return false;
  }
  return true;
}

int main() {
  cin >> N >> K;
  A.resize(N); F.resize(N);
  rep(i,N) cin >> A[i];
  rep(i,N) cin >> F[i];

  sort(all(A));
  sort(all(F));
  reverse(all(F));

  ll left = -1;
  ll right = 1e18;
  while (left + 1 < right) {
    ll mid = left + (right - left) / 2;
    if (f(mid)) right = mid;
    else left = mid;
  }
  cout << right << endl;
}

Measured memory_bytes: 3328
#include<bits/stdc++.h>
#define _GLIBCXX_DEBUG
#define rep(i,n) for (int i = 0; i < (int)(n); i++)
#define all(v) v.begin(),v.end()
#define puts(i) cout << i << endl
#define INF INT_MAX
#define INFL LLONG_MAX
typedef long long ll;
using namespace std;
int main(){
  int n,m; cin >> n >> m;
  bool ok = false;
  vector<bool> checked1(n);
  vector<bool> checked2(n);

  rep(i,m){
    int a,b; cin >> a >> b;
    if(b==n){
      if(checked1.at(a-1)) ok = true;
      checked2.at(a-1)=true;
    }else if(a==1){
      if(checked2.at(b-1)) ok = true;
      checked1.at(b-1) = true;
    }
  }

  if(ok) puts("POSSIBLE");
  else puts("IMPOSSIBLE");

}


Measured memory_bytes: 3684
#include <bits/stdc++.h>
using namespace std;
#ifdef LOCAL
#include "debug.h"
#else
#define dump(...)
#endif
#define endl "\n"
#define ll long long
#define FOR(i, a, b) for (int i = (int)(a); i < (int)(b); i++)
#define REP(i, x) for (int i = 0; i < (int)(x); i++)
#define REPS(i, x) for (int i = 1; i <= (int)(x); i++)
#define RREP(i, x) for (int i = ((int)(x)-1); i >= 0; i--)
#define RREPS(i, x) for (int i = ((int)(x)); i > 0; i--)
#define INF (1 << 30)
#define LLINF (1LL << 60)
#define vi vector<int>
#define vvi vector<vector<int>>
#define pi pair<int, int>
#define ALL(a) (a).begin(), (a).end()
#define BIT(n) (1LL << (n))
#define UNIQUE(v) v.erase(unique(v.begin(), v.end()), v.end()) //sortしてからつかうこと
constexpr ll MOD = 1e9 + 7;
int dx[8] = {1, 0, -1, 0, 1, 1, -1, -1};
int dy[8] = {0, 1, 0, -1, 1, -1, 1, -1};
ll A, B, C, D, E, F, G, H, N, M, L, K, P, Q, R, W, X, Y, Z;
string S, T;
ll ans = 0;

template <typename T>
istream &operator>>(istream &is, vector<T> &vec) {
    for (T &x : vec)
        is >> x;
    return is;
}

signed main() {
    cin >> N;
    vi b(N - 1);
    cin >> b;
    vi a(N);
    ans += b[0] + b[N - 2];
    for (int i = 1; i < N - 1; i++) {
        ans += min(b[i - 1], b[i]);
    }
    cout << ans << endl;
}

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

using namespace std;
typedef long long  ll;

#define rep(i,s,n)for(ll i=s;i<n;i++)
#define repe(i,s,n)for(ll i=s;i<=n;i++)
ll MOD = 1000000007;

int main() {
	ll A, B, K; cin >> A >> B >> K;
	set<int> se;

	rep(i, A, min(A + K, B)) {
		se.insert(i);
	}

	repe(i, max(B - K + 1, A), B) {
		se.insert(i);
	}

	for (set<int>::iterator it = se.begin(); it != se.end(); it++)
	{
		cout << *it << endl;
	}

	return 0;
}

Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
#define _USE_MATH_DEFINES
#include <math.h>
#define rep(i,n) for(int i = 0;i < n;i++)
#define NIL = -1;
#define all(x) x.begin(),x.end()
const ll INF = 1e9;
const ll mod = 1e9 + 7;

int digit(ll x) {
    if (x / 10 == 0) return 1;
    return digit(x / 10) + 1;
}

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

ll lcm(ll a,ll b){
    return ((a * b == 0)) ? 0 : (a / gcd(a,b) * b);
}

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


//////////////////////////////////////////////////////////////////////////////////////

int main(){
    ll n,sum = 0,use = 0,ans = 0;
    cin >> n;
    vector<long long> a(n);

    for (int i = 0;i < n;i++){
        cin >> a[i];
        sum += a[i];
    }

    for (int i = 0;i < n - 1;i++){
        use += a[i];
        ans += a[i] * ((sum - use) % mod);
        ans %= mod;
    }

    cout << ans << endl;
}


Measured memory_bytes: 4824
#include <stdio.h>
#include <string.h>
#include <queue>
#include <utility>
#define INF 0x3f3f3f3f
using namespace std;
typedef pair < int, int > P;
const int maxn = 10005, max_M = 20005;
int n, m;
struct node
{
    int to, d, c;
};
int head[max_M*2], next[max_M*2], pos;
node mp[max_M*2];
int d[maxn], ans[maxn];
void init ( )
{
    memset ( head, -1, sizeof ( head ) );
}
void add_Edge ( int u, node t )
{
    mp[pos] = t;
    next[pos] = head[u];
    head[u] = pos ++;
}
void Dijkstra ( int s )
{
    memset ( d, 0x3f, sizeof ( d ) );
    memset ( ans, 0x3f, sizeof ( ans ) );
    d[s] = ans[s] = 0;
    priority_queue < P, vector < P >, greater < P > > q;
    q.push ( P ( 0, s ) );
    while ( ! q.empty ( ) )
    {
        P p = q.top ( );
        q.pop ( );
        int u = p.second;
        for ( int i = head[u]; ~ i; i = next[i] )
        {
            node e = mp[i];
            if ( d[e.to] > d[u]+e.d )
            {
                d[e.to] = d[u]+e.d;
                ans[e.to] = e.c;
                q.push ( P ( d[e.to], e.to ) );
            }
            else if ( d[e.to] == d[u]+e.d && ans[e.to] > e.c )
            {
                d[e.to] = d[u]+e.d;
                ans[e.to] = e.c;
                q.push ( P ( d[e.to], e.to ) );
            }
        }
    }
}
void solve ( )
{
    int u, v, di, ci;
    while ( ~ scanf ( "%d%d", &n, &m ) && ( n || m ) )
    {
        init ( );
        pos = 0;
        for ( int i = 0; i < m; i ++ )
        {
            scanf ( "%d%d%d%d", &u, &v, &di, &ci );
            add_Edge ( u, ( node ) { v, di, ci } );
            add_Edge ( v, ( node ) { u, di, ci } );
        }
        Dijkstra ( 1 );
        int res = 0;
        for ( int i = 1; i <= n; i ++ )
            res += ans[i];
        printf ( "%d\n", res );
    }
}
int main ( )
{
    solve ( );
    return 0;
}

Measured memory_bytes: 2012
// Solution #1 : Max path length = 83 907 014 282
 
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
 
long long N, a[11][11], r = 1, e[10] = { 1, 2, 4, 7, 12, 20, 29, 38, 52 };
 
long long solve() {
	vector<long long>E, F;
	for (int i = 0; i < N; i++) E.push_back(i);
 
	do {
		long long s = 0;
		for (int i = 0; i < N - 1; i++) {
			s += a[E[i]][E[i + 1]];
		}
		F.push_back(s);
	} while (next_permutation(E.begin(), E.end()));
 
	sort(F.begin(), F.end());
	F.erase(unique(F.begin(), F.end()), F.end());
 
	long long LIM = 1;
	for (int i = 1; i <= N; i++) LIM *= i;
	LIM /= 2;
 
	//cout << F.size() << " " << LIM << endl;
	if (F.size() == LIM) return F[F.size() - 1];
	return (1LL << 60);
}
 
int main() {
	cin >> N; a[0][1] = 1; a[1][0] = 1; a[0][2] = 2; a[2][0] = 2; a[1][2] = 3; a[2][1] = 3;
 
	for (int i = 3; i < N; i++) {
		long long NN = N; N = i;
		long long V = solve(); N = NN;
		r = V + 1;
		for (int j = 0; j < i; j++) {
			long long cost = r * e[j];
			a[i][j] = cost; a[j][i] = cost;
		}
	}
	for (int i = 0; i < N; i++) {
		for (int j = 0; j < N; j++) { if (j) cout << " "; cout << a[i][j]; } cout << endl;
	}
	return 0;
}

Measured memory_bytes: 5560
#include<math.h>
#include <bits/stdc++.h>
#include <algorithm>
#define rep(i, n) for (int i = 0; i < (int)n; i++)
#define ll long long int
#define ull unsigned long long
#define py printf("Yes\n")
#define pn printf("No\n")
#define in cin>>
using namespace std;
int INF = 1001001001;
const int MOD=1e9+7;

int main()
{
  int a,v,b,w,t;
  in a>>v>>b>>w>>t;
  long long relv = v - w;
  if(relv <= 0)
    {
      cout << "NO" << endl;
      return 0;
    }
    long long reld = b - a;
    if(reld < 0)
    {
      reld = reld * (-1);
    }
    double tim = (double)reld / (double)relv;
    if(tim <= (double)t)
    {
        cout<<"YES"<<endl;
        return 0;
    }
    cout<<"NO"<<endl;
	return 0;
}


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

// region template
#define rep(i, a, b) for (int i = (a); i < (b); ++i)
#define trav(a, x) for (auto &a : x)
#define all(x) begin(x), end(x)
#define sz(x) (int)(x).size()
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef vector<int> vi;

ll gcd(ll a, ll b) { return __gcd(a, b); }

ll euclid(ll a, ll b, ll &x, ll &y) {
    if (b) { ll d = euclid(b, a % b, y, x);
        return y -= a/b * x, d; }
    return x = 1, y = 0, a;
}

typedef unsigned long long ull;
typedef long double ld;
ull mod_mul(ull a, ull b, ull M) {
    ll ret = a * b - M * ull(ld(a) * ld(b) / ld(M));
    return ret + M * (ret < 0) - M * (ret >= (ll)M);
}
ull mod_pow(ull b, ull e, ull mod) {
    ull ans = 1;
    for (; e; b = mod_mul(b, b, mod), e /= 2)
        if (e & 1) ans = mod_mul(ans, b, mod);
    return ans;
}

const ll mod = 1000000007;
struct Mod {
    ll x;
    Mod(ll xx) : x(xx) {}
    Mod operator+(Mod b) { return Mod((x + b.x) % mod); }
    Mod operator-(Mod b) { return Mod((x - b.x) % mod); }
    Mod operator*(Mod b) { return Mod((x * b.x) % mod); }
    Mod operator/(Mod b) { return *this * invert(b); }
    Mod invert(Mod a) {
        ll x, y, g = euclid(a.x, mod, x, y);
        assert(g == 1); return Mod((x + mod) % mod);
    }
    Mod operator^(ll e) {
        if (!e) return Mod(1);
        Mod r = *this ^ (e / 2); r = r * r;
        return e & 1 ? *this * r : r;
    }
};
// endregion

int main() {
    cin.sync_with_stdio(0); cin.tie(0); cin.exceptions(cin.failbit);

    while (true) {
        int n; cin >> n;
        if (n == 0) break;
        vector<pair<int, int>> points(n);
        points[0] = {0, 0};
        rep(i, 1, n) {
            int r, t; cin >> r >> t;
            if (t == 0) points[i] = {points[r].first - 1, points[r].second};
            if (t == 1) points[i] = {points[r].first, points[r].second + 1};
            if (t == 2) points[i] = {points[r].first + 1, points[r].second};
            if (t == 3) points[i] = {points[r].first, points[r].second - 1};
        }
        int xmin, xmax, ymin, ymax;
        xmin = xmax = ymin = ymax = 0;
//        rep(i, 0, n) cout << points[i].first << " " << points[i].second << "; "; cout << endl;
        rep(i, 0, n)
            xmin = min(xmin, points[i].first), xmax = max(xmax, points[i].first),
            ymin = min(ymin, points[i].second), ymax = max(ymax, points[i].second);
        cout << (xmax - xmin + 1) << " " << (ymax - ymin + 1) << endl;
    }
}


Measured memory_bytes: 3080
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
#define ll long long
#define For(a, b, c) for(int a = b; a < c; ++a)
#define Ford(a, b, c) for(int a = b; a > c; --a)

#define int long long
#define ii pair<int,int>
#define fi first
#define se second
#define pb push_back
#define all(a) a.begin(),a.end()
#define reset(a, b) memset(a, b, sizeof(a))
#define bit(x, i) (x >> (i - 1) & 1ll)
#define onbit(x, i) (x | (1ll << (i - 1)))
#define offbit(x, i) (x & ~(1ll << (i - 1)))
#define bitone(i) __builtin_popcountll(i)
#define bitl(i) __builtin_clz(i)
#define bitr(i) __builtin_ctz(i)
#define INF 1000000000000
#define vll vector<ll>
#define vi vector<int>
#define fio ifstream cin("a1.in"); ofstream cout("a1.out")
/********************************************************

Digvijay Bahadur Singh
MNNIT

*********************************************************/


const int MOD=998244353;
const int N = 1e6+100;

/********************************************************************/
                 /* GRAPH*/
//vector<vector<ll>> g;
//vector<bool> vis1,vis2;
/*******************************************************************/
ll power(ll a,ll b)
{
   ll ans =1;
   while(b>0){
   if(b&1) ans = (ans%MOD * a%MOD)%MOD;
   a = (a%MOD * a%MOD)%MOD;
   b=b>>1;
   }
   return ans%MOD;
}
int dp[6200][6200];
int lps(string s)
{
   int n=s.length();
   
   for(int i=0;i<n;i++)
   {
      dp[i][i]=1;
   }
   for(int l=2;l<=n;l++)
   {
      for(int j=0;j<n;j++)
      {
        int i=j+l-1;
         if(s[j]==s[i]&&l==2)
         {
            dp[j][i]=2;

         }
         else if(s[j]==s[i])
         {
            dp[j][i]=dp[j+1][i-1]+2;
         }
         else
         {
            dp[j][i]=max(dp[j+1][i],dp[j][i-1]);
         }
         
      }
   }
   return dp[0][n-1];
}

signed main(){
	ios::sync_with_stdio(0); cin.tie(0);cout.tie(0);
   // fio;
  
    	ll T=1;
   //  cin>>T;
  
   
    
    while(T--)
  {
     int a[]={1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51};
     int n;
     cin>>n;
     cout<<a[n-1]<<"\n";

    

     

     

  }

  
}


Measured memory_bytes: 256
#include <stdio.h>
#include <string.h>
int main(){
  char s1[12], s2[12];
  scanf("%s%s", s1, s2);
  for(int i=0; i<strlen(s1); i++){
    if(s1[i] != s2[i]){
      printf("No\n");
      return 0;
    }}
  printf("Yes\n");
 
 
 
 
  return 0;
}


Measured memory_bytes: 1628
#include <bits/stdc++.h>
using namespace std;
using lint = long long;
template<class T = int> using V = vector<T>;
template<class T = int> using VV = V< V<T> >;

int main() {
  cin.tie(nullptr); ios::sync_with_stdio(false);
  int n; cin >> n;
  cout << n * n * n << '\n';
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int l,r,d;
int main(){
  while(~scanf("%d%d%d",&l,&r,&d)){
  //printf("%d\n",r/d);
  //printf("%d\n",(l+d-1)/d);
  printf("%d\n",r/d-(l+d-1)/d+1);
}
 return 0; 
}

Measured memory_bytes: 3800
import java.util.Scanner;

public class Main {

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

        int n=scan.nextInt();
        int sum=0;
        for(int i=1;i<=n;i++){
            sum+=i;
        }
        System.out.println(sum);
    }
}


Measured memory_bytes: 9940
import java.util.*;
public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        TreeSet<Integer> set = new TreeSet<>();
        set.add(1);
        for(int i = 2 ; i <= Math.sqrt(n) ; i++){
            for(int j = i*i ; j <= n; j*=i){
                set.add(j);
            }
        }
        System.out.println(set.last());

    }
}

Measured memory_bytes: 21716
#include<stdio.h>
int main() {
	int x;
	int y[10];
	int z = 0;
	int a = 1;
	scanf("%d", &x);
	for (int i = 0; i < 10; i++) {
		z = z + (x / a) % 10;
		a = a * 10;
	}
	if (x%z == 0) {
		printf("Yes\n");
	}
	else {
		printf("No\n");
	}
	return 0;
}

Measured memory_bytes: 128
from decimal import Decimal
N, M = map(int, input().split())
i = 1
ans = 0
time = 1900 * M + 100 * (N - M)
while True:
    ex = time * i *  ((1/2) ** M) * ((1 - (1/2) ** M) ** (i - 1))
    if ex < 0.000000001:
        break
    ans += ex
    i += 1
print(Decimal(str(ans)).quantize(0, rounding="ROUND_HALF_UP"))

Measured memory_bytes: 5076