akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
#include<cmath>
using namespace std;
const double eps = 1e-9;

bool eq(double a, double b){return abs(b-a)<eps;}
bool lt(double a, double b){return !eq(a,b)&&a<b;}
bool gt(double a, double b){return !eq(a,b)&&a>b;}
bool leq(double a, double b){return eq(a,b)||a<b;}
bool geq(double a, double b){return eq(a,b)||a>b;}

double f(double a, double b, double c, double d, double x)
{
  return a*pow(x,3.0)+b*pow(x,2.0)+c*x+d;
}

int xans2dim(double a, double b, double c, double *ans)
{
  double D = b*b - 4*a*c;
  if( lt(D,0) ){
    return 0;
  }else if( gt(D,0) ){
    ans[0]=(-b-sqrt(D))/(2*a);
    ans[1]=(-b+sqrt(D))/(2*a);
    return 2;
  }else{
    ans[0]=-b/(2*a);
    return 1;
  }
}

double det(double a3, double a2, double a1, double a0)
{
  return -4*pow(a1,3.0)*a3+
    pow(a1*a2,2.0)-4*a0*pow(a2,3.0)+
    18*a0*a1*a2*a3-27*pow(a0*a3,2.0);
}

int main()
{
  int N;

  cin >> N;
  for(int tc=0;tc<N;++tc){
    int a,b,c,d;
    int neg_ans = 0, pos_ans = 0;
    
    cin >> a >> b >> c >> d;

    double extreme[2];
    double f0=f(a,b,c,d,0);
    double D=det(a,b,c,d);
    xans2dim(3*a,2*b,c,extreme);
    if(gt(extreme[0],extreme[1]))swap(extreme[0],extreme[1]);

    if( gt(D,0) || eq(D,0) ){
      bool contPos=true;
      bool contNeg=true;

      if(a<0){
	if(leq(extreme[1],0)&&leq(f0,0))contPos=false;
	if(geq(extreme[0],0)&&geq(f0,0))contNeg=false;
      }else if(a>0){
	if(leq(extreme[1],0)&&geq(f0,0))contPos=false;
	if(geq(extreme[0],0)&&leq(f0,0))contNeg=false;
      }
      int M=-d*a;

      if(M<0){
	if(!contPos){
	  neg_ans=3;
	}else{
	  neg_ans=1;
	  pos_ans=2;
	}
      }else if(M>0){
	if(!contNeg){
	  pos_ans=3;
	}else{
	  neg_ans=2;
	  pos_ans=1;
	}
      }else{
	if(gt(extreme[0],0)&&gt(extreme[1],0)){
	  pos_ans=2;
	}else if(lt(extreme[0],0)&&lt(extreme[1],0)){
	  neg_ans=2;
	}else{
	  neg_ans=1;
	  pos_ans=1;
	}
	
	if(eq(D,0)){
	  if(eq(f(a,b,c,d,extreme[0]),0)||eq(f(a,b,c,d,extreme[1]),0)){
	    if(contPos){
	      neg_ans=0;
	      pos_ans=1;
	    }else if(contNeg){
	      neg_ans=1;
	      pos_ans=0;
	    }
	  }
	}
      }

      if( eq(D,0) && eq(-2*pow(b,3.0)+9*a*b*c-27*pow(a,2.0)*d,0) ){
	neg_ans=pos_ans=0;
	if(M<0){
	  neg_ans=3;
	}else if(M>0){
	  pos_ans=3;
	}
      }
      
    }else{
      int M=-d*a;
      if( M < 0 ){
	neg_ans=1;
      }else if( M > 0 ){
	pos_ans=1;
      }
    }

    cout << pos_ans << ' ' << neg_ans << endl;
  }
}

Measured memory_bytes: 0
#include<iostream>
#include<iomanip>
#include<map>
#include<unordered_map>
#include<set>
#include<unordered_set>
#include<vector>
#include<array>
#include<string>
#include<stack>
#include<queue>
#include<algorithm>
#include<cassert>
#include<functional>
#include<random>
#include<complex>
#include<bitset>
#include<chrono>
#include<boost/multiprecision/cpp_int.hpp>
#define int int64_t
#define uint uint64_t
#define REP(i, a, b) for (int64_t i = (int64_t)(a); i < (int64_t)(b); i++)
#define rep(i, a) REP(i, 0, a)
#define EACH(i, a) for (auto i: a)
#define ITR(x, a) for (auto x = a.begin(); x != a.end(); x++)
#define ALL(a) (a.begin()), (a.end())
#define HAS(a, x) (a.find(x) != a.end())
#define Min(x) *min_element(ALL(x))
#define Max(x) *max_element(ALL(x))
#define Unique(L) (L.erase(unique(ALL(L)), L.end()))
#define veccat(v1, v2) std::copy((v2).begin(),(v2).end(),std::back_inserter(v1)/*v1の後ろにv2を入れる*/)
#define intmax (std::numeric_limits<int64_t>::max() / 4)
using namespace std;
typedef boost::multiprecision::cpp_int bigint;
const double EPS = 1e-9;
const double PI = acos(-1.0);



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

	int N, M;
	cin >> N >> M;
	vector<vector<int>>xyz(N, vector<int>(3, 0));
	rep(i, N)rep(j, 3)cin >> xyz[i][j];

	int ans = -intmax;
	for (int x : vector<int>{ 1,-1 })for (int y : vector<int>{ 1,-1 })for (int z : vector<int>{ 1,-1 }) {
		vector<int>score;
		rep(i, N)score.push_back(xyz[i][0] * x + xyz[i][1] * y + xyz[i][2] * z);
		sort(ALL(score), std::greater<int>());
		int res = 0;
		rep(i, M)res += score[i];
		ans = max(ans, res);
	}

	cout << ans << endl;


	return 0;
}



Measured memory_bytes: 384
import java.util.*;
public class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    int n = sc.nextInt();
    long a[] = new long[n];
    long b[] = new long[n];
    long c[] = new long[n];
    for(int i = 0;i<n;i++){
      a[i] = sc.nextLong();
    }
    for(int i = 0;i<n;i++){
      b[i] = sc.nextLong();
    }
    for(int i = 0;i<n;i++){
      c[i] = sc.nextLong();
    }

    Arrays.sort(a);
    Arrays.sort(c);
    long ans = 0;
    for(int i = 0;i<n;i++){
      long ab = BinarySearch1(a,b[i]) + 1;
      long bc = BinarySearch2(c,b[i]+1);
      ans += ab * (c.length - bc);
    }
    System.out.println(ans);
  }

  //ソートされた配列a[]と、探索目標のtarget
  public static long BinarySearch1(long a[] , long target){
    target = (int)target;
    int left = -1; //left と right を範囲外に設定することで、
    int right = a.length ; //条件の矛盾を解消している
    while(right - left > 1){
      int mid = left + (right - left) / 2;
      if(a[mid] >= target){
        right = mid;
      }else{
        left = mid;
      }
    }
    return (long)left;//条件に適している最も左、つまり小さいインデックスが返却される
  }
  public static long BinarySearch2(long a[] , long target){
    int left = -1; //left と right を範囲外に設定することで、
    int right = a.length ; //条件の矛盾を解消している
    while(right - left > 1){
      int mid = left + (right - left) / 2;
      if(a[mid] >= target){
        right = mid;
      }else{
        left = mid;
      }
    }
    return right;//条件に適している最も左、つまり小さいインデックスが返却される
  }
}


Measured memory_bytes: 98512
#include <bits/stdc++.h>
#include<string>
using namespace std;
#define ll long long
#define ld long double
#define endl '\n'
#define FAST ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
const int maxn=1*1e5+5;
ll lcm(ll a,ll b)
{
    return (a*b)/__gcd(a,b);
}
map<int,int>mm;
map<int,bool>vis;
int main()
{
    FAST
    int n,m;
    cin>>n>>m;
    int ans1=0,ans2=0;
    pair<int,string>*p=new pair<int,string>[m];
    for(int i=0; i<m; i++)
    {
        int a;
        string h;
        cin>>a>>h;
        p[i]=make_pair(a,h);
    }

    for(int i=0;i<m;i++)
    {
        if(p[i].second=="AC" && !vis[p[i].first])
        {
            ans1++;
            ans2+=mm[p[i].first];
            vis[p[i].first]=1;
        }
        else
        {
         mm[p[i].first]++;
        }
    }
    cout<<ans1<<" "<<ans2<<endl;

        return 0;
}


Measured memory_bytes: 15872
const input = require("fs").readFileSync("/dev/stdin", "utf8")

;(input => {

    const lines = input.split('\n')
    let N = lines[0] - 0
    const A = lines[1].split(' ').map(Number)

    let h = 0
    let m = 1000

    for (let i = 0; i < N - 1; i++) {
        if (A[i] < A[i + 1]) {
            const n = Math.floor(m / A[i])
            h += n
            m -= A[i] * n
        } else if (A[i] > A[i + 1]) {
            m += A[i] * h
            h = 0
        }
    }

    m += A[N -1] * h

    console.log(m)

})(input)


Measured memory_bytes: 30600
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.InputMismatchException;
import java.io.IOException;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        FastReader in = new FastReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        DFloorFunction solver = new DFloorFunction();
        solver.solve(1, in, out);
        out.close();
    }

    static class DFloorFunction {
        public void solve(int testNumber, FastReader s, PrintWriter out) {
            long a = s.nextLong(), b = s.nextLong(), n = s.nextLong();

            long i = b - 1;
            if (i > n) {
                i = n;
            }
            out.println((a * i) / b - (a * (i / b)));


        }

    }

    static class FastReader {
        private InputStream stream;
        private byte[] buf = new byte[1024];
        private int curChar;
        private int numChars;
        private FastReader.SpaceCharFilter filter;

        public FastReader(InputStream stream) {
            this.stream = stream;
        }

        public int read() {
            if (numChars == -1) {
                throw new InputMismatchException();
            }
            if (curChar >= numChars) {
                curChar = 0;
                try {
                    numChars = stream.read(buf);
                } catch (IOException e) {
                    throw new InputMismatchException();
                }
                if (numChars <= 0) {
                    return -1;
                }
            }
            return buf[curChar++];
        }

        public long nextLong() {
            int c = read();
            while (isSpaceChar(c)) {
                c = read();
            }
            int sgn = 1;
            if (c == '-') {
                sgn = -1;
                c = read();
            }
            long res = 0;
            do {
                if (c < '0' || c > '9') {
                    throw new InputMismatchException();
                }
                res *= 10;
                res += c - '0';
                c = read();
            } while (!isSpaceChar(c));
            return res * sgn;
        }

        public boolean isSpaceChar(int c) {
            if (filter != null) {
                return filter.isSpaceChar(c);
            }
            return isWhitespace(c);
        }

        public static boolean isWhitespace(int c) {
            return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
        }

        public interface SpaceCharFilter {
            public boolean isSpaceChar(int ch);

        }

    }
}



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


int main()
{
    long long int n;
    cin >> n;
    vector<long long int> b(n), ans;
    for(long long int i = 0;i < n;i++){
        cin >> b[i];
    }

    long long int last, cnt = 0;
    while(b.size() > 0 && cnt < n){
        last = -1;
        for(long long int i = 0;i < b.size();i++){
            if(b[i] == i + 1){
                last = b[i];
            }
        }
        if(last < 0){
            break;
        }
        b.erase(b.begin() + last - 1);
        ans.push_back(last);
        cnt++;
    }

    if(cnt == n){
        for(long long int i = n - 1;i >= 0;i--){
            cout << ans[i] << endl;
        }
    }
    else{
        cout << -1;
    }

    
    return 0;
}

Measured memory_bytes: 256
n = int(input())

buttons = [0] * 10**5

for i in range(n):
    buttons[i] = int(input())

next = 1
i = 0
while i <= 10**5:
    i += 1
    next = buttons[next-1]
    if next == 2:
        print(i)
        exit()

print(-1)


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

using namespace std;
typedef long long ll;

int main() {
    int x;
    cin >> x;
    vector<bool> isPrime(200000, true);
    for (ll i = 2; i <= x; i++) {
        if (isPrime[i]) {
            for (ll j = i * i; j < 200000; j += i)isPrime[j] = false;
        }
    }

    for (int i = x; i < 200000; i++) {
        if (isPrime[i]) {
            cout << i << endl;
            break;
        }
    }
    return 0;
}


Measured memory_bytes: 256
#!/usr/bin/python3
def left(i):
    return i * 2

def right(i):
    return i * 2 + 1

def maxHeapify(A, i):
    H = len(A) - 1
    l = left(i)
    r = right(i)

    child = {}
    child[i] = A[i] 
    if l <= H:
        child[l] = A[l]
    if r <= H:
        child[r] = A[r]
    largest = max(child.items(), key=lambda x:x[1])[0]

    
    if largest != i:
        A[i], A[largest] = A[largest], A[i]
        maxHeapify(A, largest)

def buildMaxHeap(A):
    H = len(A) - 1
    for i in range(H//2, 0, -1):
        maxHeapify(A, i)
    print(' ' + ' '.join(list(map(str, A[1:]))))

# main
H = int(input())
A = list(map(int, input().split()))
B = [0]
B.extend(A)
buildMaxHeap(B)

Measured memory_bytes: 70164
#include <iostream>
#include <string>
#include <algorithm>
#include <set>
using namespace std;
int main(){
    int N, K;
    cin >> N >> K;
    int d[N];
    for(int i = 0; i < N; i++)
        cin >> d[i];
    int num[200000] = {0};
    for(int i = 0; i < N; i++){
        num[d[i]]++;
    }
    sort(num, num + N, greater<int>());
      int total = 0;
    for(int i = 0; i < K; i++){
        total += num[i];
    }
    cout << N - total << endl;
    return 0;
}


Measured memory_bytes: 1792
#include <stdio.h>

int main(void)
{
	char s[11];
	scanf("%s",s);
	
	if(s[0] == 'Y' && s[1] == 'A' && s[2] == 'K' && s[3] == 'I')
		printf("Yes");
	else
		printf("No");
	
	return  0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
#define int long long 
using ldb = long double;
using pa = pair < int, int >;
#define pb push_back
#define F  first
#define S  second
#define f(i,x,n) for(int i=x;i<n;i++) 
#define all(c) c.begin(),c.end()
#define fast() ios_base::sync_with_stdio(false);cin.tie(NULL)

const int MOD = 1e9 + 7, N = 5e5 + 10;
const int LINF = LLONG_MAX;
int a,b,c,d;
string s1,s2,s3,s;
int ans,sum;
int32_t main() {
    fast();
    cin >>a >> b ;
    while(a>0){
        c++;
        a/=b;
    }

    cout<<c;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define maxn (int)2e5+5
struct Edge{
	long long next,to;
}edges[maxn*2];
long long b_cnt=0;
long long head[maxn*2];
long long n,m;
long long cnt[2];
bool flag=1;
long long color[maxn];
void clear()
{
	memset(cnt,0,sizeof(cnt));
	memset(color,-1,sizeof(color));
}
void addedge(long long u,long long v)
{
	edges[++b_cnt].next=head[u];
	edges[b_cnt].to=v;
	head[u]=b_cnt;
}
inline long long calc(long long a,long long b)
{
	return (long long) (a*b-m);
}
inline void dfs(long long now,int c,long long fa)
{
	color[now]=c;
	if (color[now]!=-1)cnt[c]++;
	for (long long i=head[now];i;i=edges[i].next)
	{
		long long v=edges[i].to;
		if (color[v]!=-1)
		{
			if (color[v]==c)
			  {
			  	flag=0;
			  	long long t=n;
				t=t*(n-1)/2;
				cout<<t-m<<endl;
				exit(0);
			  }
			}
			 else dfs(v,c^1,now);
		if (!flag) return;
	}
}
int main()
{
	scanf("%lld%lld",&n,&m);
	clear();
	for (long long i=1;i<=m;i++)
	{
		long long u,v;
		scanf("%lld%lld",&u,&v);
		addedge(u,v);addedge(v,u);
	}
	dfs(1,0,1);
	printf("%lld\n",calc(cnt[0],cnt[1]));
	return 0;
}


Measured memory_bytes: 6656
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define endl "\n"
#define ld long double
#define si(x) (ll)((x).size())
#define pb push_back
#define F first
#define S second
#define rep(i,n) for(ll i=0;i<n;i++)
#define per(i,n) for(ll i=n-1;i>=0;i--)
#define rep1(i,n) for(ll i=1;i<=n;i++)
#define per1(i,n) for(ll i=n;i>=1;i--)
#define all(x) (x).begin(), (x).end()
#define make_unique(x) (x).resize(unique(all(x))-(x).begin())
#define pr_vec(v) for(ll _=0;_<v.size();_++) cout << v[_] << " " ;
const int N = 1e6 + 7;
ll m = 998244353;

std::vector<ll> e[N];
bool vis[N];
ll d[N];
ll dfs(ll x)
{
    if(vis[x])
        return d[x];
    vis[x]=1;

    for(auto i:e[x])
        d[x]=max(dfs(i)+1,d[x]);

    return d[x];
}
void solve()
{
    ll n,m,x,y,ans=0;
    cin>>n>>m;
    rep(_,m)
    {
        cin>>x>>y;
        e[x].pb(y);
    }
    rep1(i,n)
        if(!vis[i])
            ans=max(ans,dfs(i));

    
    cout<<ans;    


}




int main()
{




    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    ll t = 1;
    // cin >> t;


    rep1(i, t)
    {
        // cout << "Case #" << i << ": ";
        solve();
        cout << endl;
    }


}

Measured memory_bytes: 31616
import java.util.*;

class Main{
public static void main(String[] args){
 Scanner sc =new Scanner(System.in);
         int   N = sc.nextInt();
         int   X=  sc.nextInt();
         int   Y= sc.nextInt();
         System.out.print(Math.min(X,Y)+" ");
        if(N>(X+Y)){
         System.out.print(0);
}else if(N==X&&N==Y){
System.out.print(N);
}else if(N==X||N==Y) {
System.out.print(Math.min(X,Y));
//}else if((N==X||N==Y)&&(X==0||Y==0)){
//System.out.print(0);
}else{
System.out.print((X+Y)-N);
}           
   }
}

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

int main() {
  string s; cin >> s;
  if((s[5]=='0')&&(s[6]=='1'||s[6]=='2'||s[6]=='3'||s[6]=='4')) cout << "Heisei" << endl;
  else cout << "TBD" << endl;
}




Measured memory_bytes: 256
#include <iostream>
static const int INF=1<<20;
using namespace std;

int digitSum(int n){
    int res=0;
    while(n>0){
        res+=n%10;
        n/=10;
    }
    return res;
}



int main(){
    int N;
    cin>>N;
    int Min=INF;
    for(int i=1;i<=N/2;i++){
        Min=min(digitSum(i)+digitSum(N-i),Min);
    }
    printf("%d",Min);
    return 0;
}



Measured memory_bytes: 256
package main

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

var sc = bufio.NewScanner(os.Stdin)

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

func judge(bingo map[int]bool) bool {
	if _, ok1 := bingo[1]; ok1 {
		// 1行目
		if _, ok2 := bingo[2]; ok2 {
			if _, ok3 := bingo[3]; ok3 {
				return true
			}
		}
		// 1列目
		if _, ok2 := bingo[4]; ok2 {
			if _, ok3 := bingo[7]; ok3 {
				return true
			}
		}
		// 右下斜め
		if _, ok2 := bingo[5]; ok2 {
			if _, ok3 := bingo[9]; ok3 {
				return true
			}
		}
		
	}
	// 2列目
	if _, ok1 := bingo[2]; ok1 {
		if _, ok2 := bingo[5]; ok2 {
			if _, ok3 := bingo[8]; ok3 {
				return true
			}
		}
	}
	// 3列目
	if _, ok1 := bingo[3]; ok1 {
		if _, ok2 := bingo[6]; ok2 {
			if _, ok3 := bingo[9]; ok3 {
				return true
			}
		}
		if _, ok2 := bingo[5]; ok2 {
			if _, ok3 := bingo[7]; ok3 {
				return true
			}
		}
	}
	if _, ok1 := bingo[4]; ok1 {
		if _, ok2 := bingo[5]; ok2 {
			if _, ok3 := bingo[6]; ok3 {
				return true
			}
		}
	}
	if _, ok1 := bingo[7]; ok1 {
		if _, ok2 := bingo[8]; ok2 {
			if _, ok3 := bingo[9]; ok3 {
				return true
			}
		}
	}
	return false
}

func main() {
	bingo := make(map[int]int, 9)
	sc.Split(bufio.ScanWords)

	for i := 0; i < 3; i++ {
		for j := 0; j < 3; j++ {
			 bingo[nextInt()] = i * 3 + j + 1
		}
	}

	n := nextInt()
	bingo_num := make(map[int]bool, 9)
	for i := 0; i< n; i++ {
		v := nextInt()
		if b, ok := bingo[v]; ok {
			bingo_num[b] = true
		}
	}
	if judge(bingo_num) {
		fmt.Println("Yes")
		return
	}
	fmt.Println("No")
}

Measured memory_bytes: 640
from collections import Counter
def parse_card(card):
  suit = card[-1]
  num = card[:-1]
  if num == "A":num = 1
  elif num == "K":num = 13
  elif num == "Q":num = 12
  elif num == "J":num = 11
  elif num == "T":num = 10
  else:num = int(num)
  return (num, suit)
  
def parse_hand(hand):
  return sorted((map(parse_card, hand)))

def judge(hand):
  nums = [num for num, _ in hand]
  flash_flag = len({suit for _, suit in hand}) == 1
  head = nums[0]
  straight_flag = [head, head + 1, head + 2, head + 3, head + 4] == nums or \
                  [1, 10, 11, 12, 13] == nums
  dist = sorted(Counter(nums).values())
  
  if nums == [1, 10, 11, 12, 13] and flash_flag:return 9
  if straight_flag and flash_flag:return 8
  if dist == [1, 4]:return 7
  if dist == [2, 3]:return 6
  if flash_flag:return 5
  if straight_flag:return 4
  if dist == [1, 1, 3]:return 3
  if dist == [1, 2, 2]:return 2
  if dist == [1, 1, 1, 2]:return 1
  else:return 0

def score(hand, dic, point):
  ret = 0
  for num, suit in hand:
    ret += dic[suit][num - 1]
  ret *= point[judge(hand)]
  return ret

def main():
  first_flag = True
  while True:
    try:
      n = int(input())
    except EOFError:
      break
    
    if not first_flag:print()
    else:first_flag = False
    
    dic = {}
    dic["S"] = list(map(int, input().split()))
    dic["C"] = list(map(int, input().split()))
    dic["H"] = list(map(int, input().split()))
    dic["D"] = list(map(int, input().split()))
    point = [0] + list(map(int, input().split()))
    for _ in range(n):
      hand = parse_hand(input().split())
      print(score(hand, dic, point))

main()


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

"""
input:
5 6
0 1
1 0
1 2
2 4
4 3
3 2
4
0 1
0 3
2 3
3 4

output:
1
0
1
1
"""

import sys
from math import isinf

sys.setrecursionlimit(int(1e5))


def generate_adj_table(_v_info):
    for v_detail in _v_info:
        v_from, v_to = map(int, v_detail)
        init_adj_table[v_from].append(v_to)
    return init_adj_table


def Tarjan(current, low, dfn, scc_stack, in_scc_stack):
    global timer
    dfn[current] = low[current] = timer
    timer += 1

    scc_stack.append(current)
    in_scc_stack[current] = True

    current_scc_set = set()
    for adj in adj_table[current]:
        if isinf(dfn[adj]):
            Tarjan(adj, low, dfn, scc_stack, in_scc_stack)
            low[current] = min(low[current], low[adj])

        elif in_scc_stack[adj]:
            low[current] = min(low[current], dfn[adj])

    scc_candidate = -1
    if dfn[current] == low[current]:
        while scc_candidate != current:
            scc_candidate = scc_stack.pop()
            in_scc_stack[scc_candidate] = False
            current_scc_set.add(scc_candidate)

        init_scc_sets_list.append(current_scc_set)

    return None


def scc_cluster():
    dfn = [float('inf')] * vertices
    low = [float('inf')] * vertices
    scc_stack = list()
    in_scc_stack = [False] * vertices

    for v in range(vertices):
        if isinf(dfn[v]):
            Tarjan(v, low, dfn, scc_stack, in_scc_stack)

    return init_scc_sets_list


def solve(_scc_sets_list):
    for question in q_list:
        flag = False
        ele1, ele2 = map(int, question)
        for each in _scc_sets_list:
            if (ele1 in each) and (ele2 in each):
                flag = True
                break
        if flag:
            print('1')
        else:
            print('0')

    return None


if __name__ == '__main__':
    _input = sys.stdin.readlines()
    vertices, edges = map(int, _input[0].split())
    v_info = map(lambda x: x.split(), _input[1:edges + 1])
    q_num = int(_input[edges + 1])
    q_list = map(lambda x: x.split(), _input[edges + 2:])

    init_adj_table = tuple([] for _ in range(vertices))
    adj_table = generate_adj_table(v_info)

    timer = 0
    init_scc_sets_list = []
    scc_sets_list = scc_cluster()

    solve(scc_sets_list)

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

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int k = sc.nextInt();
		char[] s = sc.next().toCharArray();
		boolean seen = false;
		for(int i = 1; i < n && k > 0; i++) {
			if(!seen && s[i] == s[0]) continue;
			else if(!seen && s[i] != s[0]) {
				s[i] = s[0];
				seen = true;
			}
			else if(seen && s[i] != s[0]) {
				s[i] = s[0];
			}
			else if(seen && s[i] == s[0]) {
				seen = false;
				k--;
			}
		}
		int res = 0;
		for(int i = 1; i < n; i++) {
			if(s[i] == s[i-1]) res++;
		}
		System.out.println(res);
	}

}


Measured memory_bytes: 26276
#include <bits/stdc++.h>
using namespace std;
int a[200010],b[200010];
int main()
{
    int n=0;
    scanf("%d",&n);
    for(int i=0;i<n;i++){
        scanf("%d",&a[i]);
        b[i]=a[i];
    }
    sort(b,b+n);
    for(int i=0;i<n;++i){
        if(a[i]==b[n-1]) printf("%d\n",b[n-2]);
        else printf("%d\n",b[n-1]);
    }
    return 0;
}

Measured memory_bytes: 3200
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <climits>
#include <iostream>
#include <vector>
#include <string>
#include <sstream>
#include <algorithm>
#include <utility>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <deque>
#include <functional>

using namespace std;

#define int long long
#define fst first
#define scd second
#define PB push_back
#define MP make_pair
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define omajinai ios::sync_with_stdio(false);cin.tie(0)
#define rep(i,x) for(int i=0;i<(int)(x);++i)
#define rep1(i,x) for(int i=1;i<=(int)(x);++i)
#define rrep(i,x) for(int i=(int)x-1;i>=0;--i)
#define rrep1(i,x) for(int i=(int)x;i>=1;--i)

using ll=long long;
using ld=long double;
using vi=vector<int>;
using vvi=vector<vi>;
using pii=pair<int, int>;
using vpii=vector<pii>;

template<class T,class U>ostream&operator<<(ostream&os,const pair<T,U>p){os<<"("<<p.fst<<", "<<p.scd<<")";return os;}
template<class T>ostream&operator<<(ostream&os,const vector<T>v){rep(i,v.size()){if(i)os<<", ";os<<v[i];}return os;}
template<typename T>T&max(T&a,T&b){if(a>=b)return a;return b;}
template<typename T>T&min(T&a,T&b){if(a < b)return a;return b;}
template<typename T>bool chmax(T&a,T b){if(a < b){a=b;return true;}return false;}
template<typename T>bool chmin(T&a,T b){if(a > b){a=b;return true;}return false;}

constexpr int TEN(int n){return n == 0 ? 1 : 10*TEN(n - 1);}

constexpr int inf = 3*TEN(18);
constexpr double eps = 1e-9;

int N, M, K;

signed main()
{
    cin >> N >> M >> K;
    vi A(N + 1), B(M + 1);
    rep1(i, N) cin >> A[i];
    rep1(i, M) cin >> B[i];
    rep1(i, N) A[i] += A[i - 1];
    rep1(i, M) B[i] += B[i - 1];

    int ans = -inf;

    rep(i, N + 1) {
        int zan = K - A[i];
        if (zan < 0) continue;
        int b = upper_bound(all(B), zan) - begin(B) - 1;
        chmax(ans, i + b);
    }

    cout << ans << endl;
}



Measured memory_bytes: 6400
#include <iostream>
#include <string>
using namespace std;
#define ll long long
const ll mod = 1e9 + 7;
string l;
long long quick_pow(long long a, long long b)
{
    if (b == 0)
        return 1;
    long long temp = quick_pow(a, b >> 1);
    if (b & 1)
        return a % mod * temp % mod * temp % mod;
    else
        return temp % mod * temp % mod; //快速幂
}
int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    cin >> l;
    int len = l.length();
    ll ans = 0;
    int num = 0;
    for (int i = 0; i < len; i++)
    {
        if (l[i] == '1')
        {
            ans = (ans + quick_pow(2, num++) * quick_pow(3, len - 1 - i)) % mod;
        }
    }
    ans = (ans + quick_pow(2, num)) % mod;
    cout << ans % mod << endl;
    //system("pause");
    return 0;
}

Measured memory_bytes: 512
#include <stdio.h>
#include <iostream>
#include <string>
#include <stdlib.h>
#include <math.h>
#include <algorithm>
#include <sstream>
#include <fstream>
#include <iomanip>
#include <vector>

#define rep(i,a,b) for(long long i=a;i<b;i++)

using namespace std;


int main(void) {

	long long N = 0, K = 0, H = 0, W = 0, C = 0;
	char a[100][100] = {};
	int b[100] = {};
	long long c[300] = { 0 };
	long long d[300] = { 0 };
	//long long y[20] = {};
	string s;
	
	vector<vector<int>> xx;
		
	long long min = 0, min2 = 0;
	long long dif = 0;
	long long hoge = 0;
	long long sum = 0;
	long long up = 0;

	cin >> b[0] >> b[1] >> b[2] >> b[3];


	if (b[2] - b[0] >= 0 && b[3] - b[1] >= 0) {
		b[4] = b[2] - abs(b[3] - b[1]);
		b[5] = b[3] + abs(b[2] - b[0]);
		b[6] = b[4] - abs(b[2] - b[0]);
		b[7] = b[5] - abs(b[3] - b[1]);
	}else if (b[2] - b[0] <= 0 && b[3] - b[1] >= 0) {
			b[4] = b[2] - abs(b[3] - b[1]);
			b[5] = b[3] - abs(b[2] - b[0]);
			b[6] = b[4] + abs(b[2] - b[0]);
			b[7] = b[5] - abs(b[3] - b[1]);
	}else if (b[2] - b[0] <= 0 && b[3] - b[1] <= 0) {
		b[4] = b[2] + abs(b[3] - b[1]);
		b[5] = b[3] - abs(b[2] - b[0]);
		b[6] = b[4] + abs(b[2] - b[0]);
		b[7] = b[5] + abs(b[3] - b[1]);
	}
	else if (b[2] - b[0] >= 0 && b[3] - b[1] <= 0) {
		b[4] = b[2] + abs(b[3] - b[1]);
		b[5] = b[3] + abs(b[2] - b[0]);
		b[6] = b[4] - abs(b[2] - b[0]);
		b[7] = b[5] + abs(b[3] - b[1]);
	}
	
	cout << b[4]<< " "<< b[5] << " " << b[6] << " " << b[7] << endl;
	
	return 0;
	
}



Measured memory_bytes: 256
import java.util.*;

public class Main {
    static Scanner scanner = new Scanner(System.in);

    public static void main(String[]$) {
        int n = scanner.nextInt();
        long p = 1;
        for (int i = 1; i <= n; i++) {
            p = p * i % 1000000007;
        }
        System.out.println(p);
    }
}

Measured memory_bytes: 21716
/***************************************************************
	File name: C.cpp
	Author: ljfcnyali
	Create time: 2019年07月20日 星期六 20时08分16秒
***************************************************************/
#include<bits/stdc++.h>

using namespace std;

#define REP(i, a, b) for ( int i = (a), _end_ = (b); i <= _end_; ++ i ) 
#define mem(a) memset ( (a), 0, sizeof ( a ) ) 
#define str(a) strlen ( a ) 

const int maxn = 200010;

int Max, Maxx, n, k1;

int main()
{
    scanf("%d", &n);    
    REP(i, 1, n) 
    { 
        int x; scanf("%d", &x); 
        if ( x >= Max ) { Maxx = Max; Max = x; k1 = i; continue ; }
        else if ( x > Maxx ) { Maxx = x; }
    }
    REP(i, 1, n)
    {
        if ( k1 == i ) printf("%d\n", Maxx);
        else printf("%d\n", Max);
    }
    return 0;
}

Measured memory_bytes: 1664
import sys
import math
import bisect

def main():
    a, b, c, d = map(int, input().split())
    if a + b > c + d:
        print('Left')
    elif a + b < c + d:
        print('Right') 
    else:
        print('Balanced')

if __name__ == "__main__":
    main()


Measured memory_bytes: 3060
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text.RegularExpressions;
using static kyoupuro.Input;
using static kyoupuro.MyMath;

namespace kyoupuro {

    class MainClass {

        public static void Main() {
            var N = NextInt();
            var T = NextInt();
            var list = new List<Tuple<int, int>>();
            for (int i = 0; i < N; i++) {
                list.Add(Tuple.Create(NextInt(), NextInt()));
            }

            if(list.Any(x => x.Item2 <= T)) {
                Console.WriteLine(list.Where(x => x.Item2 <= T).OrderBy(x => x.Item1).First().Item1);
            } else {
                Console.WriteLine("TLE");
            }
        }
    }

    class MyMath {
        public static long Gcd(long a, long b) {
            return b == 0 ? a : Gcd(b, a % b);
        }
    }

    class Input {
        static IEnumerator<string> enumerator = new string[] { }.AsEnumerable().GetEnumerator();

        public static string Line() {
            return Console.ReadLine();
        }

        public static int NextInt() {
            while (!enumerator.MoveNext()) {
                enumerator = StrArr().AsEnumerable().GetEnumerator();
            }
            return int.Parse(enumerator.Current);
        }

        public static long NextLong() {
            while (!enumerator.MoveNext()) {
                enumerator = StrArr().AsEnumerable().GetEnumerator();
            }
            return long.Parse(enumerator.Current);
        }

        public static string[] StrArr() {
            return Line().Split(' ');
        }

        public static List<int> IntList() {
            return StrArr().Select(int.Parse).ToList();
        }

        public static List<long> LongList() {
            return StrArr().Select(long.Parse).ToList();
        }

        public static void Skip(int line = 1) {
            enumerator.Reset();
            for (int i = 0; i < line; i++) Console.ReadLine();
        }

        public static void Reset() {
            enumerator.Reset();
        }
    }
}

Measured memory_bytes: 13524
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(k,i,n) for(ll i=k;i<n;++i)
int main(void){
    ll a,b;
    cin>>a>>b;
    bool T=false;
    rep(0,i,2000){
        if((i*8)/100==a && (i*10)/100==b){
            cout<<i<<endl;
            return 0;
        }
    }
    if(!T){
        cout<<-1<<endl;
    }
}

Measured memory_bytes: 256
fun main(args: Array<String>) {
    val (n, r) = getInts()
    if (n >= 10) println(r)
    else println(r + 100 * (10 - n))
}

fun getInt() = readLine()!!.toInt()
fun getInts() = readLine()!!.split(" ").map { it.toInt() }

Measured memory_bytes: 37932
#include<set>
#include<map>
#include<stack>
#include<cmath>
#include<ctime>
#include<queue>
#include<cstdio>
#include<vector>
#include<climits>
#include<cstring>
#include<iostream>
#include<algorithm>
using namespace std;
#define LL long long
int read(){
    int f=1,x=0;char c=getchar();
    while(c<'0'||'9'<c){if(c=='-')f=-1;c=getchar();}
    while('0'<=c&&c<='9') x=(x<<3)+(x<<1)+c-'0',c=getchar();
	x*=f;
    return x;
}
#define MAXN 100
#define INF 0x3f3f3f3f
int main(){
	double a,b;
	scanf("%lf %lf",&a,&b);
	cout<<a/b<<endl;
	return 0;
}

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

using namespace std;

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

  int n, k, s;
  cin >> n >> k >> s;
  int val = (s == 1e9 ? 1 : s + 1);
  for (int i = 0; i < n; ++i) {
    if (i < k) {
      cout << s << ' ';
    } else {
      cout << val << ' ';
    }
  }

  return 0;
}

Measured memory_bytes: 1280
#include<bits/stdc++.h>
using namespace std;
#define ll long long                                    // long long省略
#define pb push_back                                    // push_back省略
#define mp make_pair                                    // make_pair省略
#define fi first                                        // first省略
#define se second                                       // second省略
#define itn int                                         // int誤字保険
#define count cout                                      // cout誤字保険
#define vecotr vector                                   // vector誤字保険
#define ednl endl                                       // endl誤字保険
#define opt() cin.tie(0); ios::sync_with_stdio(false)   // 入出力速度改善

#define rep(i,l,r) for(ll i=(l);i<(r);i++)               // 範囲[l, r)で刻み1のfor文(順方向)
#define repp(i,l,r,k) for(ll i=(l);i<(r);i+=(k))         // 範囲[l, r)で刻みkのfor文(順方向)
#define rrep(i,l,r) for(ll i=(r-1);i>=(l);i--)           // 範囲[l, r)で刻み1のfor文(逆方向)
#define rrepp(i,l,r,k) for(ll i=(r-1);i>=(l);i-=(k))     // 範囲[l, r)で刻みkのfor文(逆方向)
#define all(x) (x).begin(), (x).end()                   // vectorのポインタ位置指定用
#define max(p,q)((p)>(q)?(p):(q))                       // max拡張
#define min(p,q)((p)<(q)?(p):(q))                       // min拡張
#define bit(n,m)(((n)>>(m))&1)                          // 変数nのm番目のbitを取り出す

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

int dy[]={0, 1, 0, -1};                                 // 4方向近傍
int dx[]={1, 0, -1, 0};                                 // 4方向近傍

int main(){
    string s;cin>>s;
    cout << (s<="2019/04/30"?"Heisei":"TBD") << ednl;
}


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

int main()
{
  int n, w;
  cin >> n >> w;
  pair<int, int> p[n];
  for(int i = 0; i < n; i++)
  {
    cin >> p[i].first >> p[i].second;
  }
  long long dp[n + 1][w + 1];
  memset(dp, 0, sizeof dp);
  for(int i = 1; i <= n; i++)
  {
    for(int j = 1; j <= w; j++)
    {
      if(p[i - 1].first <= j)
        dp[i][j] = max(dp[i - 1][j], p[i - 1].second + dp[i - 1][j - p[i - 1].first]);
      else 
        dp[i][j] = dp[i - 1][j];
    }
  }
  cout << dp[n][w];
  
  return 0;
}

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

int main(){
  int n;cin >> n;
  for(int i = 0;i < n;i++){
      char x;cin >> x;
      if(x == 'Y'){
          cout << "Four" << '\n';
          return 0;
      }
  }
  cout << "Three" << '\n';
  return 0;
}


Measured memory_bytes: 3604
N = int(input())
a = [list(map(str, input().split())) for _ in range(N)]
tmp = sorted(a, key = lambda x:(int(x[1])), reverse = True)
array = sorted(tmp, key = lambda x:(x[0]))

for i in range(N):
    print(a.index(array[i]) + 1)

Measured memory_bytes: 3060
N,M=map(int,input().split())
S=input()
T=input()
list_S=list(S)
list_T=list(T)
Number_i=[i for i in range(N)]
Number_iMN=[]
for i in Number_i:
  Number_iMN.append(i*M/N)
Number_j=[j for j in range(M)]
Kaburi_j=list(set(Number_iMN)&set(Number_j))
Kaburi_i=[]
for j in Kaburi_j:
  Kaburi_i.append(int(j*N/M))
counter=0
Flag=0
Kaburi_Size=len(Kaburi_i)
while counter<=Kaburi_Size-1:
  if list_S[int(Kaburi_i[counter])]==list_T[int(Kaburi_j[counter])]:
    pass
  else:
    Flag=1
    break
  counter+=1
def gcd(a,b):
  while b>0:
    a,b=b,a%b
  return a
if Flag==1:
  print(-1)
else:
  print(int(N*M/gcd(N,M)))
  
  
  



Measured memory_bytes: 22632
import java.util.*;
import static java.lang.Integer.*;
//import static java.lang.Long.*;
import static java.lang.System.*;

public class Main {
	public static int MOD = 1000000007;
	public static void main(String[] args) {
		int i,j;
		Scanner sc = new Scanner(in);
		int n = parseInt(sc.next());
		int m = parseInt(sc.next());
		PriorityQueue<Integer> a = new PriorityQueue<>(Comparator.reverseOrder());
		for(i=0;i<n;i++) {
			a.add(parseInt(sc.next()));
		}
		sc.close();
		for (i = 0; i < m; i++) {
			a.add(a.poll()>>1);
		}
		long sum = 0;
		for (Integer ii: a) {
			sum += ii;
		}
		out.println(sum);
	}
}


Measured memory_bytes: 47968
import java.util.Scanner;

/**
 * Created by Reopard on 2014/05/06.
 */
public class Main {
    public static void main(String arg[]) {
        int deck[] = new int[50];
        int save[] = new int[50];
        int n, r, p, c, tmp, pointer;
        Scanner sc = new Scanner(System.in);
        while(true){
            n = sc.nextInt();
            r = sc.nextInt();
            if(n == 0 && r == 0) break;
            for(int i = 0; i < n; i++) deck[i] = i;
            for(int i = 0; i < r; i++){
                p = sc.nextInt();
                c = sc.nextInt();
                for(int j = 0; j < c; j++){
                    pointer = n-(p-1+c);
                    tmp = deck[pointer];
                    for(; pointer < n-1; pointer++) deck[pointer] =deck[pointer+1];
                    deck[n-1] = tmp;
                }
            }
            System.out.println(deck[n-1]+1);
        }
    }
}

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

int par[100001];
int depth[100001];

void init(int n) {
    for(int i = 0; i < n; i++)
    {
        par[i] = i;
        depth[i] = 0;
    }
}

int root(int x) {
    if (par[x] == x) return x;
    else return par[x] = root(par[x]);
}

void unite(int x, int y) {
    x = root(x);
    y = root(y);
    if (x == y) return;

    if (depth[x] < depth[y]) par[x] = y;
    else {
        par[y] = x;
        if (depth[x] == depth[y]) depth[x]++;
    }
}

bool same(int x, int y) {
    return root(x) == root(y);
}

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

    init(n + 1);
    int x, y, z;
    for (int i = 0; i < m; i++)
    {
        cin >> x >> y >> z;
        unite(x, y);
    }
    
    vector<bool> p(n + 1, false);
    int cnt = 0;
    for (int i = 1; i <= n; i++)
    {
        int r = root(i);
        if (!p.at(r)) {
            cnt++;
            p.at(r) = true;
        }
    }
    cout << cnt << endl;
}

Measured memory_bytes: 1024
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <sstream>
#include <functional>
#include <map>

#define INPUT_FROM_FILE (0) 
#if INPUT_FROM_FILE
#include <fstream>
#endif


int main(){
	int q, com;
	std::string key;
	long x;
	std::map<std::string, long> m;

#if INPUT_FROM_FILE
	std::ifstream ifs("test.txt");
#endif

#if INPUT_FROM_FILE
	ifs >> q;
#else
	std::cin >> q;
#endif
	
	for(int i = 0; i < q; i++){
#if INPUT_FROM_FILE
		ifs >> com >> key;
#else
		std::cin >> com >> key;
#endif
		if(com == 0){
#if INPUT_FROM_FILE
			ifs >> x;
#else
			std::cin >> x;
#endif
			m[key] = x;
		}
		else if(com == 1){
			if(m.count(key) > 0){
				std::cout << m[key] << std::endl;
			}
			else{
				std::cout << "0" << std::endl;
			}
		}
		else if(com == 2){
			m.erase(key);
		}
		else{
	
		}
	}
	return 0;
}


Measured memory_bytes: 27652
#include<stdio.h>


int main()
{
	int H, W, i, j;
	char sky[100][102]={0};
	int ans[100][102];
	int flag=0;

	scanf("%d%d%d", &H, &W);

	for(i=0; i<H; i++){
		for(j=0; j<=W; j++){
			ans[i][j] = -1;
		}
	}
	for(i=0; i<H; i++){
		for(j=0; j<=W; j++){
			scanf("%c", &sky[i][j]);
		}
	}

	for(i=0; i<H; i++){
		for(j=0; j<=W; j++){
			if(flag==1){
				ans[i][j] = ans[i][j-1]+1;
			}
			if(sky[i][j] == 'c'){
				ans[i][j] = 0;
				flag=1;
			}
		}
		flag=0;
	}

	for(i=0; i<H; i++){
		for(j=0; j<W;j++){
			printf("%d", ans[i][j]);
			if(j != W-1)
				printf(" ");
		}
		printf("\n");
	}
	return 0;
}

Measured memory_bytes: 660
import java.util.Scanner;
 class Main {
    public static void main(String[]args){
        Scanner scan = new Scanner(System.in);
        int n = scan.nextInt();
        long arr[] = new long[n];
        for(int i=0;i<n;i++){
            arr[i]=scan.nextInt();
        }
        int count = 0 ;
        int max = 0 ;
        for(int i = 0 ; i< n-1 ;i++){
           if(arr[i+1]<= arr[i]){
               count++;
               //System.out.println(count);
           }else{
               //System.out.println(count);
               if(max<count)
                   max = count ;
               count = 0 ;
           }
        }
         if(max<count)
                   max = count ;
        
        System.out.println(max);
    }
}


Measured memory_bytes: 62116
import itertools

a,b,c=map(int, input().split())
k=int(input())
list()
for i,j in itertools.permutations(range(k+1), 2):
    if i+j != k:
        continue
    #if max([a,b,c]) != c:
        #c = c * 2
    #print(i,j)
    b_,c_ = b,c

    if i != 0:
        for l in range(i):
            b_ *= 2
    if j != 0:
        for l in range(j):
            c_ *= 2
    #print(b_,c_)
    if a < b_ and b_ < c_:
        print('Yes')
        quit()
print('No')

Measured memory_bytes: 9200
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> P;
typedef pair<ll, P> P3;
typedef pair<P ,P> PP;
constexpr ll MOD = ll(1e9+7);
constexpr int IINF = INT_MAX;
constexpr ll LLINF = LLONG_MAX;

struct edge{
    int from, to, d, c;
};

int n, m;
vector<vector<edge> > g;
vector<edge> es;
vector<int> dmin;

void dijkstra(){
    dmin.assign(n, IINF);
    priority_queue<P, vector<P>, greater<P> > que;
    dmin[0] = 0;
    que.push({0,0});
    while(!que.empty()){
        P p = que.top();
        que.pop();
        int u = p.second;
        if(dmin[u] < p.first) continue;
        for(auto &e : g[u]){
            if(dmin[e.to] > dmin[u] + e.d){
                dmin[e.to] = dmin[u] + e.d;
                que.push({dmin[e.to], e.to});
            }
        }
    }
}

int main() {
    while(cin >> n >> m, n){
        g.clear();
        g.resize(n);
        es.clear();
        for(int i=0;i<m;i++){
            int u, v, d, c;
            cin >> u >> v >> d >> c;
            u--; v--;
            g[u].push_back({u,v,d,c});
            g[v].push_back({v,u,d,c});
            es.push_back({u,v,d,c});
        }
        dijkstra();
        vector<int> mincost(n, IINF); // 各頂点に向かう最小路の最小コスト
        for(auto e : es){
            if(dmin[e.from] > dmin[e.to]) swap(e.from, e.to);
            if(dmin[e.from] + e.d == dmin[e.to]){
                mincost[e.to] = min(mincost[e.to], e.c);
            }
        }
        int ans = 0;
        for(int i=1;i<n;i++){
            ans += mincost[i];
        }
        cout << ans << endl;
    }
    return 0;
}



Measured memory_bytes: 4628
unittest
{
	assert( [ "3 3", "...", ".#.", "..." ].parse.expand.solve == 2 );
	assert( [ "6 6", "..#..#", "......", "#..#..", "......", ".#....", "....#." ].parse.expand.solve == 3 );

	assert( [ "1 1", "#" ].parse.expand.solve == 0 );		// 追加ケース
}



import std.conv;
import std.range;
import std.stdio;
import std.typecons;

void main()
{
	stdin.byLineCopy.parse.expand.solve.writeln;
}

auto parse( Range )( Range input )
if( isInputRange!Range && is( ElementType!Range == string ) )
{
	auto hw = input.front.split.to!( long[] );
	auto ass = new char[][]( hw[ 0 ], hw[ 1 ] );
	foreach( ref as; ass )
	{
		input.popFront;
		as = input.front.to!( char[] );
	}
	return tuple( ass );
}

auto solve( char[][] ass )
{
	// 黒マスの座標を配列化、白マスを数える
	Tuple!( long, long )[] bs;
	auto w = ass.length * ass[ 0 ].length;
	foreach( y, as; ass )
	{
		foreach( x, a; as )
		{
			if( a == '.' ) continue;
			bs ~= tuple( y.signed, x.signed );
			w--;
		}
	}
	
	// 黒マスを広げる
	for( auto i = 1L;; i++ )
	{
		if( w == 0 ) return i - 1;
		
		foreach( b; bs )
		{
			for( auto dy = 0L, dx = i; dy <= i; dy++, dx-- )
			{
				auto y1 = b[ 0 ] - dy;
				auto y2 = b[ 0 ] + dy;
				auto x1 = b[ 1 ] - dx;
				auto x2 = b[ 1 ] + dx;
				
				if( 0 <= y1 )
				{
					if( 0 <= x1               && ass[ y1 ][ x1 ] == '.' ) ass[ y1 ][ x1 ] = '#', w--;
					if( x2 < ass[ y1 ].length && ass[ y1 ][ x2 ] == '.' ) ass[ y1 ][ x2 ] = '#', w--;
				}
				if( y2 < ass.length )
				{
					if( 0 <= x1               && ass[ y2 ][ x1 ] == '.' ) ass[ y2 ][ x1 ] = '#', w--;
					if( x2 < ass[ y2 ].length && ass[ y2 ][ x2 ] == '.' ) ass[ y2 ][ x2 ] = '#', w--;
				}
			}
		}
	}
}


Measured memory_bytes: 36732
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
using namespace std;
typedef long long ll;
#define rep(i,n) for (int i=0;i < (int)(n);i++)

int main(){
 ll b,r,n;
 string s;
 ll ans=0;
 cin >> n >> b >> r;
 ans+=(n/(r+b))*b;
 n%=(r+b);
 if ( n <= b ) ans+=n;
 else ans+=b; 
 cout << ans << endl;
 return 0; 
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main()
{
    string s;
    cin>>s;
    if(s=="ABA"||s=="AAB"||s=="BAA"||s=="ABB"||s=="BAB"||s=="BBA")
        cout<<"Yes"<<endl;
    else
        cout<<"No"<<endl;
}


Measured memory_bytes: 3628
#include<iostream>
#include<string>
#include<string.h>
#include<algorithm>
#include<stdio.h>
#include<cmath>
#include<vector>
#include<utility>
#include<stack>
#include<queue>
#include<list>
#include<bitset>

#define FOR(i, a, b) for(int i=(a);i<=(b);i++)
#define RFOR(i, a, b) for(int i=(a);i>=(b);i--)
#define MOD 1000000007
#define INF 1000000000

using namespace std;

int main(void) {
	string s;
	int k, i, h, b, r;
	bool flag = true;

	cin >> s;
	k = s.find("K");
	i = s.find("I",k);
	h = s.find("H",i);
	b = s.find("B",h);
	r = s.find("R",b);
	if (k == -1 || i == -1 || h == -1 || b == -1 || r == -1) {
		flag = false;
	}
	if (i - k >= 2 || h - i >= 2 || b - h >= 3 || r - b >= 3) {
		flag = false;
	}
	if (s.size() - 1 - r >= 2) {
		flag = false;
	}
	if (k >= 2) {
		flag = false;
	}
	else if (k == 1) {
		if (s[0] != 'A') {
			flag = false;
		}
	}
	if (b - h == 2) {
		if (s[h + 1] != 'A') {
			flag = false;
		}
	}
	if (r - b == 2) {
		if (s[b + 1] != 'A') {
			flag = false;
		}
	}
	if (s.size() - 1 - r == 1) {
		if (s[r + 1] != 'A') {
			flag = false;
		}
	}

	if (flag) {
		cout << "YES" << endl;
	}
	else {
		cout << "NO" << endl;
	}
	return 0;
}

Measured memory_bytes: 256