akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <cstdio>
#include <cstring>
#include <queue>
using namespace std;
const int maxN = 205,maxM=2e6+5;
const int inf = 1e9;

struct edge
{
	int fr, to, nxt;
	int c, f;
} graph[maxM];
int head[maxN];
int totlen;
int level[maxN];
int n, m;
int s, t;

bool dinic_bfs()
{
	memset(level, 0, sizeof(level));
	queue<int> que;
	que.push(s);
	level[s] = 1;
	while (!que.empty())
	{
		int u = que.front(); que.pop();
		for (int i = head[u]; i != -1; i = graph[i].nxt)
		{
			int v = graph[i].to;
			if (!level[v] && graph[i].c > graph[i].f)
			{
				level[v] = level[u] + 1;
				que.push(v);
			}
		}
	}
	return level[t] != 0;
}

int dinic_dfs(int u, int cpflow)
{
	if (u == t) return cpflow;
	int addflow = 0;
	for (int i = head[u]; i != -1 && addflow < cpflow; i = graph[i].nxt)
	{
		int v = graph[i].to;
		if (level[u] + 1 == level[v] && graph[i].c > graph[i].f)
		{
			int tmpadd = dinic_dfs(v, min(cpflow - addflow, graph[i].c - graph[i].f));
			graph[i].f += tmpadd;
			graph[i ^ 1].f -= tmpadd;
			addflow += tmpadd;
		}
	}
	return addflow;
}

int dinic()
{
	int maxflow = 0;
	while (dinic_bfs())
		maxflow += dinic_dfs(s, inf);
	return maxflow;
}

void addEdge(int u, int v, int c, int i)
{
	graph[totlen].to = v;
	graph[totlen].fr = u;
	graph[totlen].nxt = head[u];
	graph[totlen].c = c;
	graph[totlen].f = 0;
	head[u] = totlen++;
	graph[totlen].to = u;
	graph[totlen].fr = v;
	graph[totlen].nxt = head[v];
	graph[totlen].c = 0;
	graph[totlen].f = 0;
	head[v] = totlen++;
}

void init()
{
	for (int i = 0; i <= n + 5; i++)
		head[i] = -1;
	totlen = 0;
}

int main()
{
	int h,w,sk,sl,tk,tl;
	char ch[105];
	scanf("%d%d",&h,&w);
	n=h+w+2;
	s=0;
	t=h+w+1;
	init();
	for(int i=1;i<=h;i++)
    {
        scanf("%s",ch+1);
        for(int l=1;l<=w;l++)
        {
            if(ch[l]=='o')
            {
                addEdge(i,h+l,1,0);
                addEdge(h+l,i,1,0);
            }
            if(ch[l]=='S')
            {
                sk=i;sl=l;
                addEdge(s,i,inf,0);
                addEdge(s,h+l,inf,0);
            }
            if(ch[l]=='T')
            {
                tk=i;tl=l;
                addEdge(i,t,inf,0);
                addEdge(h+l,t,inf,0);
            }
        }
    }
    if(sk==tk||sl==tl)printf("-1");
	else printf("%d\n",dinic());
	return 0;
}


Measured memory_bytes: 1024
#define _USE_MATH_DEFINES
#include<iostream>
#include<algorithm>
#include<math.h>
#include<cmath>
#include<string>
#include<set>
#include<map>
#include<stdlib.h>
#include<stdio.h>
#include<vector>
#include<utility>
#include<stdbool.h>
using namespace std;
typedef long long ll;
#define N (1000000000+7)
ll a[200010] = { 0 };

int main(void) {
	ll n;
	cin >> n;
	for (ll i = 1;i <= n;i++)cin >> a[i];
	if (n == 1) {
		cout << a[1] << endl;
		return 0;
	}
	if (n % 2 != 0) {
		for (ll i = n;i >= 1;i -= 2) {
			cout << a[i] << " ";
		}
		for (ll i = 2;i <= n - 1;i += 2) {
			if (i == n - 1)cout << a[i] << endl;
			else cout << a[i] << " " ;
		}
	}
	else {
		for (ll i = n;i >= 2;i -= 2) {
			cout << a[i] << " ";
		}
		for (ll i = 1;i <= n - 1;i += 2) {
			if (i == n - 1)cout << a[i] << endl;
			else cout << a[i] << " " ;
		}
	}
	return 0;
}

Measured memory_bytes: 3712
#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <fstream>
#include <sstream>
#include <set>
#include <map>
#include <vector>
#include <list>
#include <algorithm>
#include <cstring>
#include <cmath>
#include <string>
#include <queue>
#include <bitset>     //UWAGA - w czasie kompilacji musi byc znany rozmiar wektora - nie mozna go zmienic
#include <cassert>
#include <iomanip>        //do setprecision
#include <ctime>
#include <complex>
using namespace std;

#define FOR(i,b,e) for(int i=(b);i<(e);++i)
#define FORQ(i,b,e) for(int i=(b);i<=(e);++i)
#define FORD(i,b,e) for(int i=(b)-1;i>=(e);--i)
#define REP(x, n) for(int x = 0; x < (n); ++x)

#define ST first
#define ND second
#define PB push_back
#define MP make_pair
#define LL long long
#define ULL unsigned LL
#define LD long double

const double pi = 3.141592653589793238462643383279502884197169399375105820974944592307816406286208998628034825342;
const int mod=1000000007;

int main(){
	LL a[8]={};
	FOR(i,0,7)cin>>a[i];
	LL ans=a[0]/2*2+a[1]+a[3]/2*2+a[4]/2*2;
	if(a[0]>0&&a[3]>0&&a[4]>0)ans=max(ans,3+(a[0]-1)/2*2+(a[1]-0)+(a[3]-1)/2*2+(a[4]-1)/2*2);
	cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 256
def euclid(a, b):
    while b:
        a, b = b, a%b
    return a

def multiple(a, b):
    return a*b // euclid(a, b)

A,B,C,D = map(int,input().split())

all = B - A + 1
x = B//C - (A-1)//C
y = B//D - (A-1)//D
lcm = multiple(C,D)
z = B//lcm - (A-1)//lcm

print(all - x - y + z)

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

#define name ""
#define ini freopen(name".inp","r",stdin); freopen(name".out","w",stdout)
#define foe(it,c) for (__typeof(c.begin()) it = c.begin(); it != c.end(); it++)
#define long long long 
#define db double 
#define pii pair <int, int>
#define pll pair <long, long>
#define all(c) c.begin(), c.end()
#define fastio ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0)

const int INF = 1e9+7;
const long MOD = 1e15+7;
const int dx[4] = {0,0,-1,1};
const int dy[4] = {-1,1,0,0};

long POW(long x, long n){
  if (n == 0) return 1;
  long y = POW(x, n / 2);
  y = y * y % MOD;
  if (n % 2) return x * y % MOD;
  else return y;
}

int main()
{
  fastio;
  long x; cin >> x;
  for (int i = -200; i <= 200; i++){
    for (int j = -200; j <= 200; j++){
      if (POW(i, 5) - POW(j, 5) == x) return cout << i << ' ' << j, 0;
    }
  }
  return 0;
}

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

int main()
{
  int n, k;
  cin >> n >> k;
  string s;
  cin >> s;
  int x = 0, y = 0, ans = 0;
  for (int i = 0; i < n-1; ++i) {
    if (s[i] == s[i + 1])
      ++x;
    else
      ++y;
  }
  cout << x + min(y, 2 * k) << endl;
}

Measured memory_bytes: 512
import math
a,b,x = map(int,input().split())

if(a * a * b / 2.0 <= x):
  print(math.degrees(math.atan(((x/a/a*2-b-b)*-1/a))))
                     
else:
  print(90-math.degrees(math.atan(2 * x / (a * b * b))))


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

const int INF = 1e9;

int main() {
	int v, e, r;
	cin >> v >> e >> r;
	vector<vector<pii>> g(v);
	rep(i, e) {
		int s, t, d;
		cin >> s >> t >> d;
		g[s].push_back(make_pair(t, d));
	}
	vector<int> ans(v, INF);
	ans[r] = 0;
	priority_queue<pii, vector<pii>, greater<pii>> q;
	q.push(make_pair(ans[r], r));
	while (!q.empty()) {
		pii p = q.top();
		q.pop();
		if (ans[p.second] < p.first) continue;
		for (auto a : g[p.second]) {
			if (ans[a.first] > ans[p.second] + a.second) {
				ans[a.first] = ans[p.second] + a.second;
				q.push(make_pair(ans[a.first], a.first));
			}
		}
	}
	rep(i, v) {
		if (ans[i] != INF) cout << ans[i] << endl;
		else cout << "INF" << endl;
	}
	return 0;
}


Measured memory_bytes: 12920
#include <iostream>
using namespace std;
int main()
{
	int tmp,i,i2,d[8][3]={{0,0,0},{0,0,1},{0,1,0},{0,1,1},{1,0,0},{1,0,1},{1,1,0},{1,1,1}};
	char c[4];
	cin>>c;
	for(i=0;i<4;i++)c[i]-=48;
	for(i=0;i<8;i++)
	{
		tmp=c[0];
		for(i2=0;i2<3;i2++)
		{
			if(d[i][i2])
			{
				tmp+=c[i2+1];
			}
			else 
			{
				tmp-=c[i2+1];
			}
		}
		if(tmp==7)
		{
			for(i2=0;i2<3;i2++)
			{
				c[i2]+=48;
				cout << c[i2];
				if(d[i][i2])
					cout << "+";
				else 
					cout << "-";
			}
			c[3]+=48,cout << c[3]<<"=7\n";
			return 0;
		}
	}
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
 
using namespace std;
 
typedef long long ll;
typedef unsigned long long u_ll;
typedef pair<int, int> pair_;
 
const int INF = 1001001001;
const int dx[] = {-1, 0, 1, 0};
const int dy[] = {0, -1, 0, 1};

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

   int n,m;
   cin >> n >> m;

    vector<int> h(n);
    rep(i,n) cin >> h[i];

    vector<vector<int>> road(n);

    rep(j,m) {
        int x, y;
        cin >> x >> y;
        if(h[x-1]>h[y-1]){
            road.at(y-1).push_back(x-1);
        }
        else if(h[x-1]==h[y-1]) {
            road.at(y-1).push_back(x-1);
            road.at(x-1).push_back(y-1);
        }
        else{
            road.at(x-1).push_back(y-1);
        }
        
    }
    int ans=0;
    rep(i, n){
        int sze=road.at(i).size();
        if(sze==0){
            ans++;
        }
    }

    cout << ans;


    return 0;
}

Measured memory_bytes: 7724
import java.io.*;
import java.util.StringTokenizer;

class Main {
    private static final double G = 9.8;

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

	try {
	    while ((buf = br.readLine())!=null) {
		double v = Double.parseDouble(buf);
		double t = v/G;
		double y = (G/2)*t*t;
		double N = (y+5)/5;
		System.out.println((int)Math.ceil(N));
	    }
	} catch (Exception e) {
	    e.printStackTrace();
	}
    } 
}

Measured memory_bytes: 16908
#include<stdio.h>
#include<math.h>

struct Point {
	double x, y;
};

void koch(int n, Point a, Point b) {
	if ( n == 0 ) return;
	Point s, t, u;
	double th = M_PI * 60.0 / 180.0; //将单位从度变为弧度
	s.x = (2.0 * a.x + 1.0 * b.x) / 3.0;
	s.y = (2.0 * a.y + 1.0 * b.y) / 3.0;
	t.x = (1.0 * a.x + 2.0 * b.x) / 3,0;
	t.y = (1.0 * a.y + 2.0 * b.y) / 3.0;
	u.x = (t.x - s.x) * cos(th) - (t.y - s.y) * sin(th) + s.x;
	u.y = (t.x - s.x) * sin(th) + (t.y - s.y) * cos(th) + s.y;
	koch(n-1, a, s);
	printf("%.8f %.8f\n", s.x, s.y);
	koch(n-1, s, u);
	printf("%.8f %.8f\n", u.x, u.y);
	koch(n-1, u, t);
	printf("%.8f %.8f\n", t.x, t.y);
	koch(n-1, t, b);
}

int main(){
	Point a, b;
	int n;
	scanf("%d", &n);
	a.x = 0;
	a.y = 0;
	b.x = 100;
	b.y = 0;
	printf("%.8f %.8f\n", a.x, a.y);
	koch(n, a, b);
	printf("%.8f %.8f\n", b.x, b.y);
	return 0;
}


Measured memory_bytes: 2720
def main():
    n = input()
    p = map(int,raw_input().split())
    for i in xrange(1,n):
        p.append(map(int,raw_input().split())[1])

    print mcm(p)

def mcm(p):
    n = len(p)-1
    m = [[0]*(n+1) for i in xrange(n+1)]

    for l in xrange(2,n+1):
        for i in xrange(1,n-l+2):
            j = i+l-1
            m[i][j] = float("inf")
            for k in xrange(i,j):
                m[i][j] = min(m[i][j],m[i][k]+m[k+1][j]+p[i-1]*p[k]*p[j])

    return m[1][n]
            

if __name__ == "__main__":
    main()

Measured memory_bytes: 6568
#include "bits/stdc++.h"
using namespace std;
#define repr(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define rep(i,n) repr(i,0,n)
#define reprrev(i,a,b) for(int i=(int)(b)-1;i>=(int)(a);i--)
#define reprev(i,n) reprrev(i,0,n)
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
#define mp make_pair
#define mt make_tuple
#define MOD 1000000007
#define PI 3.1415926535
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> Pi;
typedef pair<ll, ll> Pll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<bool> vb;
typedef vector<char> vc;
typedef vector<string> vs;
typedef vector<double> vd;
typedef vector<Pi> vPi;
typedef vector<Pll> vPll;
typedef vector<vector<int>> vvi;
typedef vector<vector<bool>> vvb;
typedef vector<vector<ll>> vvll;
typedef vector<vector<char>> vvc;
typedef vector<vector<string>> vvs;
typedef vector<vector<double>> vvd;
typedef vector<vector<Pi>> vvPi;
typedef priority_queue<int, vector<int>, greater<int>> pqli;
typedef priority_queue<ll, vector<ll>, greater<ll>> pqlll;
typedef priority_queue<Pi, vector<Pi>, greater<Pi>> pqlP;
string YN(bool y) { return (y?"YES":"NO"); }
string yn(bool y) { return (y?"Yes":"No"); }
string ON(bool y) { return (y?"OK":"NG"); }
int main(void)
{
	string s, s2;

	int k;

	priority_queue<string, vector<string>, greater<string>> ans;

	map<string, ll> m;

	cin>>s>>k;

	
	if(s.size()<=50){
		rep(i, s.size()){
			repr(j, i, s.size()){
				s2=s.substr(i, j-i+1);
				m[s2]++;
				if(m[s2]==1){
					ans.push(s2);
					//cout<<s2<<endl;
				}

			}
		}

		rep(i, k){
			s2=ans.top(); ans.pop();
			//cout<<s2<<endl;
		}
		cout<<s2<<endl;
	}else{
		vc s3(s.size());

		rep(i, s.size()){
			s3[i]=s[i];
		}
		sort(all(s3));
		

		vi mini;

		rep(i, s.size()){
			if(s3[k-1]>=(char)s[i]){
				mini.push_back(i);
				//cout<<i<<endl;
			}
		}

		rep(i, mini.size()){
			repr(j, 1, 6){
				if(i+j<s.size()+1){
					s2=s.substr(mini[i], j);
					m[s2]++;
					if(m[s2]==1){
						ans.push(s2);
					}
				}
			}
		}
		rep(i, k){
			s2=ans.top(); ans.pop();
			//cout<<s2<<endl;
		}
		cout<<s2<<endl;
	}
}


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

int main() {
	int n,p[101],m[101][101];cin>>n;for(int i=1;i<=n;i++)cin>>p[i-1]>>p[i];
	for(int i=1;i<=n;i++)m[i][i]=0;
	for(int l=2;l<=n;l++)
	{
		for(int i=1;i<=n-l+1;i++)
		{
			int j=i+l-1;m[i][j]=1<<21;
			for(int k=i;k<=j-1;k++)m[i][j]=min(m[i][j],m[i][k]+m[k+1][j]+p[i-1]*p[k]*p[j]);
		}
	}
	cout<<m[1][n]<<endl;
	return 0;
}

Measured memory_bytes: 3116
import java.util.*;
public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int a = sc.nextInt();
		int b = sc.nextInt();
		int c = sc.nextInt();
		if(a==b+c||b==c+a||c==a+b){
			System.out.println("Yes");
		}else{
			System.out.println("No");
		}
	}

}


Measured memory_bytes: 21972
#include <iostream>
#include <string>
#include <cstring>
#include <algorithm>
#include <functional>
#include <cmath>
#include <set>
#include <queue>
#include <vector>
#include <climits>
#include <sstream>
#include <iomanip>
#include <map>
#include <stack>
using namespace std;

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

	if (x < 1200)
	{
		cout << "ABC" << endl;
	}
	else
	{
		cout << "ARC" << endl;
	}

	return 0;
}

Measured memory_bytes: 256
import fractions
import math

a,b = map(int, input().split())

def factorize(n):#素因数分解
    fct = []  # prime factor
    b, e = 2, 0  # base, exponent
    while b * b <= n:
        while n % b == 0:
            n = n // b
            e = e + 1
        if e > 0:
            fct.append([b, e])
        b, e = b + 1, 0
    if n > 1:
        fct.append([n, 1])
    return fct

d = fractions.gcd(a, b)

l = factorize(d)

print(len(l) + 1)

Measured memory_bytes: 64108
#![allow(unused_imports, non_snake_case, dead_code)]
use proconio::{
    input, fastout,
    marker::{Chars, Bytes, Usize1}
};

const MOD: u64 = 1_000_000_007;

#[fastout]
fn main() {
    input! {
        S: Chars
    }
    let mut a = 0;
    let mut b = 0;
    let mut c = 0;
    let mut d = 1;
    for &x in S.iter().rev() {
        match x {
            '?' => {
                a = (3 * a + b) % MOD;
                b = (3 * b + c) % MOD;
                c = (3 * c + d) % MOD;
                d = 3 * d % MOD;
            },
            'A' => {
                a = (a + b) % MOD;
            },
            'B' => {
                b = (b + c) % MOD;
            },
            'C' => {
                c = (c + d) % MOD;
            },
            _ => ()
        }
    }
    println!("{}", a);
}

Measured memory_bytes: 2492
#define _USE_MATH_DEFINES
#include <iostream>
#include <fstream>
#include <sstream>
#include <string>
#include <cstring>
#include <vector>
#include <set>
#include <map>
#include <unordered_map>
#include <queue>
#include <deque>
#include <stack>
#include <algorithm>
#include <bitset>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <numeric>
#include <functional>
#include <cctype>
#include <list>
#include <limits>
#include <cassert>
#include <random>
#include <time.h>
#include <unordered_set>

using namespace std;
using Int = long long;

constexpr double EPS = 1e-10;
constexpr long long MOD = 1000000007;

long long mod_pow(long long x, long long n) {
    long long res = 1;
    for (int i = 0;i < 60; i++) {
        if (n >> i & 1) res = res * x % MOD;
        x = x * x % MOD;
    }
    return res;
}

long long my_mod_pow(long long x, long long n) {
	long long ret = 1;
	for (; n > 0; n >>= 1, x = x * x % MOD) {
		if (n & 1) {
			ret = ret * x % MOD;
		}
	}
	return ret;
}

template<typename T>
T gcd(T a, T b) {
    return b != 0 ? gcd(b, a % b) : a;
}

template<typename T>
T lcm(T a, T b) {
    return a * b / gcd(a, b);
}

void fastInput() {
    cin.tie(0);
    ios::sync_with_stdio(false);
}

int main(void) {
    long long A, B, N; cin >> A >> B >> N;
    long long ans = A * min(N, B-1) / B;
    cout << ans << endl;
}


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


int main(){
    ll x,y,a,b,c;cin>>x>>y>>a>>b>>c;
    ll p[100010],q[100010],r[100010];
    rep(i,0,a)cin>>p[i];
    rep(i,0,b)cin>>q[i];
    rep(i,0,c)cin>>r[i];
    
    sort(p,p+a,greater<>());
    sort(q,q+b,greater<>());
    sort(r,r+c,greater<>());
    
    ll rcn=0,bcn=0,rit=x-1,bit=y-1,wit=0,an=0;
    
    while(p[rcn]>=r[0]&&rcn<x){
        an+=p[rcn];
        rcn++;
    }
    while(q[bcn]>=r[0]&&bcn<y){
        an+=q[bcn];
        bcn++;
    }
    while(rcn<=rit||bcn<=bit){
        if(wit==c){
            rep(i,rcn,rit+1)an+=p[i];
            rep(i,bcn,bit+1)an+=q[i];
            break;
        }
        else if(rcn>rit){
            if(r[wit]>q[bit]){
                an+=r[wit];
                wit++;
                bit--;
            }
            else{
                an+=q[bit];
                bit--;
            }
        }
        else if(bcn>bit){
            if(r[wit]>p[rit]){
                an+=r[wit];
                wit++;
                rit--;
            }
            else{
                an+=p[rit];
                rit--;
            }
        }
        else{
            if(p[rit]>=q[bit]&&r[wit]>q[bit]){
                an+=r[wit];
                wit++;
                bit--;
            }
            else if(p[rit]<q[bit]&&r[wit]>p[rit]){
                an+=r[wit];
                wit++;
                rit--;
            }
            else{
                an+=p[rit]+q[bit];
                rit--;
                bit--;
            }
        }
    }
    cout<<an<<endl;

}







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

int main() {
  int N;
  map<string,int> gacha;
  cin >> N;
  
  string s;
  for(int i=0;i<N;i++){
    cin >> s;
    gacha.emplace(s,1);
    //cout << s;
  }
  //cout << gacha["apple"] << endl;
  cout << gacha.size() << endl;
  
  return(0);
}

Measured memory_bytes: 19220
import sys
maisu,goukei = map(int,input().split())

for i in range(0,maisu+1):
  for s in range(0,maisu-i+1):
    tmpSum = i*1000+s*5000+(maisu-s-i)*10000
    if tmpSum == goukei:
      print(str(maisu-s-i)+' '+str(s)+' '+str(i))
      sys.exit()

print('-1 -1 -1')



Measured memory_bytes: 40684
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int main(){
	int n,k,w;
	cin>>n>>k;
	vector<ll> ac;
	for(int h=0;h<n;h++){
		cin>>w;
		ac.push_back(w);
	}
	long long  ans=0;
	for(int s=1;s<n;s++){
		if(ac[s]+ac[s-1]>k){
			int h=ac[s]+ac[s-1]-k;
			if(ac[s]-h>=0){
				ac[s]-=h;
			}
			else {
				// ac[s-1]-=(h-ac[s]);
				ac[s]=0;
			}
			ans+=h;
		}	
	}
	cout<<ans<<'\n';
}

Measured memory_bytes: 1528
#include <bits/stdc++.h>
using namespace std;
int n;
#define Maxn 100007
int a[Maxn];
map<int,int> mp;
int main()
{
    scanf("%d",&n);
    for (int i=1;i<=n;i++)
        scanf("%d",&a[i]);
    if (n%3==0)
    {
        for (int i=1;i<=n;i++)
            ++mp[a[i]];
        int tmp=0;
        bool check=true;
        for (map<int,int>::iterator it=mp.begin();it!=mp.end();it++)
            if ((*it).second%(n/3)!=0) check=false; 
            else if ((*it).second!=(n/3)*2) tmp^=(*it).first;
        if (check&&tmp==0) printf("Yes\n"); else printf("No\n");
    } else
    {
        bool flag=true;
        for (int i=2;i<=n;i++)
            if (a[i]!=a[1]) flag=false;
        if (flag&&a[1]==0) printf("Yes\n"); else printf("No\n");
    }
    return 0;
}

Measured memory_bytes: 7584
# encoding: utf-8
n = int(input())

n_tmp = n
ans = 0
for i in range(3):
    if n_tmp % 10 == 1: ans += 9 * (10 ** i)
    elif n_tmp % 10 == 9: ans += 1 * (10 ** i)
    else: ans += (n_tmp % 10) * (10 ** i)
    if i > 2: break
    n_tmp = n_tmp // 10

print(ans)

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

#define rep(i,n) for(int i=0; i<(n); ++i)
#define rrep(i,n) for(int i=1; i<=(n); ++i)
#define drep(i,n) for(int i=(n)-1; i>=0; --i)
#define srep(i,s,t) for (int i = s; i < t; ++i)
#define pb push_back
#define eb emplace_back
#define sz(x) (int)(x).size()
#define fi first
#define se second
#define v(T) vector<T>
#define imposs {cout<<"-1\n";return 0;}
#define LL_MAX LLONG_MAX
#define LL_MIN LLONG_MIN

typedef unsigned int uint;
typedef long long int ll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef pair<int,int> pii;
typedef vector<pii> vpii;
typedef set<int> si;
typedef multiset<int> msi;
template<typename T>string join(const v(T)&v)
{stringstream s;rep(i,sz(v))s<<' '<<v[i];return s.str().substr(1);}
template<typename T>inline ostream& operator<<(ostream&o,const v(T)&v)
{if(sz(v))o<<join(v);return o;}

struct mintree {
    int N, dat[2*400020];
    mintree() {}
    mintree(int n) {
        N = 1;
        while(N < n) N *= 2;
        for(int i = 0; i < 2*N-1; i++)
            dat[i] = INT_MAX;
    }
    // update k th element
    void update(int k, int a) {
        k += N-1; // leaf
        dat[k] = a;
        while(k > 0) {
            k = (k - 1) / 2;
            dat[k] = min(dat[k*2+1], dat[k*2+2]);
        }
    }
    // min [a, b)
    int query(int a, int b) { return query(a, b, 0, 0, N); }
    int query(int a, int b, int k, int l, int r) {
        if(r <= a or b <= l) return INT_MAX;
        if(a <= l and r <= b) return dat[k];
        int m = (l + r) / 2;
        return min(query(a, b, k*2+1, l, m), query(a, b, k*2+2, m, r));
    }
};

struct maxtree {
    int N, dat[2*400020];
    maxtree() {}
    maxtree(int n) {
        N = 1;
        while(N < n) N *= 2;
        for(int i = 0; i < 2*N-1; i++)
            dat[i] = INT_MIN;
    }
    // update k th element
    void update(int k, int a) {
        k += N-1; // leaf
        dat[k] = a;
        while(k > 0) {
            k = (k - 1) / 2;
            dat[k] = max(dat[k*2+1], dat[k*2+2]);
        }
    }
    // max [a, b)
    int query(int a, int b) { return query(a, b, 0, 0, N); }
    int query(int a, int b, int k, int l, int r) {
        if(r <= a or b <= l) return INT_MIN;
        if(a <= l and r <= b) return dat[k];
        int m = (l + r) / 2;
        return max(query(a, b, k*2+1, l, m), query(a, b, k*2+2, m, r));
    }
};

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

  int N, K;
  cin >> N >> K;
  auto ma = maxtree(N);
  auto mi = mintree(N);
  vi P(N);
  rep(i,N){
    cin >> P[i];
    ma.update(i,P[i]);
    mi.update(i,P[i]);
  }
  vi std(N-K+1);
  int a=0;
  rep(i,N-1){
    if(P[i]<P[i+1])a++;
    else a=0;
    if (a>=K-1){
      std[i-K+2]=1;
    }
  }
  int ans = 0;
  rep(i,N-K+1){
    if(std[i]) ans++;
  }
  ans = ans>1 ? (2-ans) : 1;
  rep(i,N-K) {
    if (mi.query(i,i+K+1)!=P[i] || ma.query(i,i+K+1)!=P[i+K]){
      ++ans;
    } else if (std[i] && std[i+1]) ++ans;
  }
  cout << ans << "\n";
  return 0;
}


Measured memory_bytes: 8064
#include <bits/stdc++.h>
#define rep(i, n) for(int i = 0;i < n;i++)
#define rev(i, n) for(int i = n;i >= 0;i--)
#define Rep(i, m, n) for(int i = m;i < n;i++)
#define repeatrev(i, m, n) for(int i = m;i >= n;i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define ll long long
#define pb(a) push_back(a)
#define INF 999999999
#define itn int
const int MAX = 510000;


using namespace std;
typedef pair<int, int> P;
typedef pair<ll, ll> LP;
typedef pair<int, P> PP;
typedef pair<ll, LP> LPP;
typedef priority_queue<int> Pr;

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

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n;
    cin >> n;
    bool hantei = false;
    while(n >= 0){
        if(n % 4 == 0){
            hantei = true;
            break;
        }
        else{
            n -= 7;
        }
    }
    if(hantei) cout << "Yes" << endl;
    else cout << "No" << endl;
}

Measured memory_bytes: 256
#define _CRT_SECURE_NO_WARNINGS
#pragma GCC target("avx")
#pragma GCC optimize("O3")
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cfloat>
#include <climits>
#include <cmath>
#include <complex>
#include <ctime>
#include <deque>
#include <fstream>
#include <functional>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <list>
#include <map>
#include <memory>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string>
#include <string.h>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>
#define rep(i,n) for(int i=0;i<(lint)(n);i++)
#define REP(i,n) for(int i=1;i<=(lint)(n);i++)
#define all(V) V.begin(),V.end()
#define stackReplaceBegin(size)\
	void* p=malloc(size);\
	esp_new=(lint)p+size-1;\
	void * stack_extend_memory_ = malloc(size);\
	void * stack_extend_origin_memory_;\
	char * stack_extend_dummy_memory_ = (char*)alloca((1+(int)(((long long)stack_extend_memory_)&127))*16);\
	*stack_extend_dummy_memory_ = 0;\
	asm volatile("mov %%rsp, %%rbx\nmov %%rax, %%rsp":"=b"(stack_extend_origin_memory_):"a"((char*)stack_extend_memory_+(size)-1024));
typedef long long lint;
typedef unsigned long long ulint;
typedef std::pair<int, int> P;
constexpr int INF = INT_MAX/2;
constexpr lint LINF = LLONG_MAX/2;
constexpr double eps = DBL_EPSILON;
constexpr double PI=3.141592653589793238462643383279;
lint esp_new;
template<class T>
class prique :public std::priority_queue<T, std::vector<T>, std::greater<T>> {};
template <class T, class U>
inline bool chmax(T& lhs, const U& rhs) {
	if (lhs < rhs) {
		lhs = rhs;
		return 1;
	}
	return 0;
}
template <class T, class U>
inline bool chmin(T& lhs, const U& rhs) {
	if (lhs > rhs) {
		lhs = rhs;
		return 1;
	}
	return 0;
}
inline lint gcd(lint a, lint b) {
	while (b) {
		lint c = a;
		a = b; b = c % b;
	}
	return a;
}
inline lint lcm(lint a, lint b) {
	return a / gcd(a, b) * b;
}
bool isprime(lint n) {
	if (n == 1)return false;
	for (int i = 2; i * i <= n; i++) {
		if (n % i == 0)return false;
	}
	return true;
}
template<typename T>
T mypow(T a, unsigned int b) {
	T res(1),now(a);
	while(b){
		if(b&1)res*=now;
		b>>=1;
		now*=now;
	}
	return res;
}
template<typename T>
void printArray(std::vector<T>& vec) {
	rep(i, vec.size() - 1)std::cout << vec[i] << " ";
	std::cout << vec.back() << std::endl;
}
template<typename T>
void printArray(T l, T r) {
	T rprev = r;
	rprev--;
	for (T i = l; i != rprev; i++) {
		std::cout << *i << " ";
	}
	std::cout << *rprev << std::endl;
}
bool a[30],b[30];
int main() {
	int N,ans=0;
	std::string S;
	std::cin>>N>>S;
	for(int i=1;i<N;i++){
		for(int j=0;j<26;j++){
			a[j]=b[j]=false;
		}
		std::string t=S.substr(0,i),r=S.substr(i,N-i);
		for(char c:t)a[c-'a']=true;
		for(char c:r)b[c-'a']=true;
		int cnt=0;
		for(int j=0;j<26;j++){
			if(a[j]&&b[j])cnt++;
		}
		ans=std::max(ans,cnt);
	}
	std::cout<<ans<<std::endl;
	return 0;
}

Measured memory_bytes: 3632
#include<bits/stdc++.h>
using namespace std;
#define MAX_N 101

int N, W, v[MAX_N], w[MAX_N];

void solve(){
    int C[N + 1][W + 1], ans = 0;
    fill(C[0], C[0] + W + 1, 0);
    for(int i = 1; i <= N; i++){
        fill(C[i], C[i] + W + 1, 0);
        for(int j = 0; j <= W; j++){
            if(j >= w[i])
                C[i][j] = max(C[i - 1][j], C[i][j - w[i]] + v[i]);
            else
                C[i][j] = C[i - 1][j];
            ans = max(ans, C[i][j]);
        }
    }
    cout << ans << endl;
}

int main(){
    cin >> N >> W;
    for(int i = 1; i <= N; i++){
        cin >> v[i] >> w[i];
    }
    solve();
    return 0;
}


Measured memory_bytes: 7044
#include <bits/stdc++.h>
using namespace std;
#define fi first
#define se second
#define rep(i,s,t) for(ll i=s ; i<t ; i++)
typedef long long ll;
typedef pair<ll,ll> P;
const int max_n = 1e5;
const ll mod = 1e9+7;
map<ll,ll> prime_factor(ll n){
  map<ll,ll> ma;
  rep(i,2,n+1){
    while(n%i == 0){
      ma[i]++;
      n /= i;
    }
  }
  if(n != 1) ma[n]=1;
  return ma;
}
int main(){
  ll n,m; cin >> n >> m;
  priority_queue<ll> que;
  rep(i,0,n){
    ll x; cin >> x;
    que.push(x);
  }
  while(m>0){
    ll x = que.top(); que.pop();
    x /= 2;
    que.push(x);
    m--;
  }
  ll sum = 0;
  while(que.size()){
    sum += que.top();
    que.pop();
  }
  cout << sum << endl;
  return 0;
}


Measured memory_bytes: 1400
/*By Mohan Abhyas V*/
#pragma GCC optimize ("-O3")
#include <bits/stdc++.h>  
 
using namespace std;
 
typedef long long ll;
typedef long double ld;
typedef pair<int,int> p32;
typedef pair<ll,ll> p64;
typedef pair<double,double> pdd;
typedef vector<ll> v64;
typedef vector<int> v32;
typedef vector<vector<int> > vv32;
typedef vector<vector<ll> > vv64;
typedef vector<vector<p64> > vvp64;
typedef vector<p64> vp64;
typedef vector<p32> vp32;
ll MOD = 998244353;
#define forn(i,e) for(ll i = 0; i < e; i++)
#define forsn(i,s,e) for(int i = s; i < e; i++)
#define rforn(i,s) for(ll i = s; i >= 0; i--)
#define rforsn(i,s,e) for(ll i = s; i >= e; i--)
#define ln "\n"
#define dbg(x) cout<<#x<<" = "<<x<<ln
#define mp make_pair
#define pb push_back
#define fi first
#define se second
#define INF 1e18
#define fast_cin() ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL)
#define all(x) (x).begin(), (x).end()
#define sz(x) ((ll)(x).size())

ll mpow(ll a, ll b){
	if(b >= (MOD-1)) b %= (MOD-1);
	if(b==0) return 1;
	ll t1 = mpow(a,b/2);
	t1 *= t1;
	t1 %= MOD;
	if(b%2) t1 *= a;
	t1 %= MOD;
	return t1;
}

ll mpow(ll a, ll b, ll p){
	if(b==0) return 1;
	ll t1 = mpow(a,b/2,p);   t1 *= t1;
	t1 %= p;
	if(b%2) t1 *= a;
	t1 %= p;
	return t1;
}
ll modinverse(ll a, ll m){
	ll m0 = m; 
    ll y = 0, x = 1; 
    if (m == 1) return 0; 
    while (a > 1){
        ll q = a / m; 
        ll t = m; 
        m = a % m, a = t; 
        t = y; 
        y = x - q * y; 
        x = t; 
    }
    if (x < 0) x += m0; 
    return x; 
}
ll range(ll l, ll r){
	return l + rand()%(r-l+1);
}

p64 hashFn(v64 vc)
{
    ll p1 = 31, p2 = 97;
    ll m1 = 1e9+9, m2 = 998244353;
    ll hsv1 = 0, hsv2 = 0, p_pow1 = 1, p_pow2 = 1;
    forn(i, vc.size())
    {
        hsv1 = ((hsv1 + vc[i] + 1) * p_pow1) % m1;
        p_pow1 = (p_pow1 * p1) % m1;

        hsv2 = ((hsv2 + vc[i] + 1) * p_pow2) % m2;
        p_pow2 = (p_pow2 * p2) % m2;
    }
    return mp(hsv1, hsv2);
}
     
void solve(){
	ll h,w;
	cin>>h>>w;
	vector<string> vc(h);
	forn(i, h)
	{
		cin>>vc[i];
	}
	ll dp[h][w];
	dp[h-1][w-1] = 1;
	if(vc[h-1][w-1] == '.')
	{
		dp[h-1][w-1] = 0;
	}
	rforn(i, h-1)
	{
		rforn(j, w-1)
		{
			if(i == h-1 && j == w-1) continue;
			ll t1 = INF,t2 = INF;
			if(i+1 < h)
			{
				t1 = dp[i+1][j];
				if(vc[i][j] == '#' && vc[i+1][j] == '.')
				{
					t1 = dp[i+1][j]+1;
				}
			}
			if(j+1 < w)
			{
				t2 = dp[i][j+1];
				if(vc[i][j] == '#' && vc[i][j+1] == '.')
				{
					t2 = dp[i][j+1]+1;
				}
			}
			dp[i][j] = min(t1,t2);
		}
	}
	// forn(i, h)
	// {
	// 	forn(j, w)
	// 	{
	// 		cout<<dp[i][j]<<" ";
	// 	}
	// 	cout<<ln;
	// }
	cout<<dp[0][0]<<ln;
}
 
int main()
{
	fast_cin();
    ll t=1;
    //cin>>t;
    forn(i,t) {
    	// cout << "Case #" << i+1 << ": ";
    	solve();
    }
    return 0;
}

/*
1) try dp
2) meet in the middle
3) correct complexity analysis
4) randomized algorithm
5) brute force

*/

Measured memory_bytes: 384
#include <stdio.h>

int main(void)
{
    int a, b;
    char op;

    while(1){
        scanf("%d %c %d", &a, &op, &b);
        if(op == '+'){
            printf("%d\n", a + b);
        }else if(op == '-'){
            printf("%d\n", a - b);
        }else if(op == '*'){
            printf("%d\n", a * b);
        }else if(op == '/'){
            printf("%d\n", a / b);
        }else{
            break;
        }
    }

    return 0;
}


Measured memory_bytes: 2112
#include<iostream>
#include<stdio.h>
#include<string>
#include<vector>
#include<map>
#include<tuple>
#include<algorithm>
#include<cmath>
#include<limits>
#include<set>
#include<deque>
#include<queue>
#include<stack>
using namespace std;
#define int long long int
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define dup(x,y) (((x)+(y)-1)/(y))
int gcd(int a, int b) { return b ? gcd(b, a % b) : a; }
int lcm(int a, int b) { return a / gcd(a, b) * b; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
typedef pair<int, int>P;
const int MOD = 1e9 + 7;
//const int MOD = 998244353;
const int INF = 1e18;
const long double PI = (acos(-1));


signed main() {
	int N;
	cin >> N;
	vector<char>ans;
	for (int i = N; i > 0; i = (i - 1) / 26) {
		char c = 'a' + (i - 1) % 26;
		ans.push_back(c);
	}
	rep(i, ans.size())cout << ans[ans.size() - 1 - i];
}

Measured memory_bytes: 3628
str = input()
a1 = str[0]
a2 = str[1]
a3 = str[2]
a4 = str[3]

if str.count(a1) == 2 and str.count(a2) == 2 and str.count(a3) == 2 and str.count(a4) == 2:
  print("Yes")
else:
  print("No")

Measured memory_bytes: 9120
#include <bits/stdc++.h>
#define _ ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define int long long
#define sz(i) (int)(i.size())
#define F first
#define S second
#define L long double
#define P pair<int, int>
const int inf = 0x3f3f3f3f3f3f3f3LL;
const int mod = (int)1e9 + 7;
using namespace std;
#if LOCAL
#include "../../tr.h"
#else
#define tr(...)
#define endl '\n'
#endif
template<class T> void smin(T& a, T val) {if (a > val) a = val;}template<class T> void smax(T& a, T val) {if (a < val) a = val;}
const int N = 5*(int)1e5 + 10;

void yes(){
   cout<<"Yes"<<endl;
   //exit (0);
}
void no(){
   cout<<"No"<<endl;
   //exit (0);   
}

int n, a[N];
string s, t;

int32_t main(){_
   
   int x, y;
   cin >> x >> y;

   int ans = (x*y);
   ans = (ans + 1)/2;
   if(x == 1 or y == 1)
      ans = 1;
   cout << ans;

   return 0;
}

Measured memory_bytes: 256
//
//  main.cpp
//  MST2ND
//
//  Created by Dong Truong on 7/13/19.
//  Copyright © 2019 Dong Truong. All rights reserved.
//

#include <iostream>
#include <stdio.h>
#include <fstream>
#include <algorithm>
#include <vector>
#include <queue>
#include <cmath>
#include <iomanip>

using namespace std;
#define long long long

const long maxn = 1e6+2 , cm=1e9+7 , ba=31;
struct elem
{
    long x,y;
};

long n,p[maxn],ha[maxn];string s,t;
void pre()
{
    p[0]=1;
    for (int i=1;i<=n;++i)
        p[i]=(p[i-1]*ba)%cm;
    s="%";
    for (int i=0;i<n;++i) s+=t[i];
    for (int i=1;i<=n;++i)
        ha[i]=(ha[i-1]*ba+s[i]-'a'+1)%cm;
}
void nhap()
{
    cin>>t;
    n=t.length();
    pre();
    long gt=-1,bg=1,sl=0;
    for (int i=1;i<=n;++i)
    {
        long o=(ha[i]-ha[bg-1]*p[i-bg+1]+cm*cm)%cm;
        if (o!=gt)
        {
            ++sl;
            bg=i+1;
            gt=o;
        }
    }
    cout<<sl;
}
int main(int argc, const char * argv[]) {
    //freopen("a.inp","r",stdin);
    nhap();
    return 0;
}


Measured memory_bytes: 6408
# -*- coding: utf-8 -*-

import sys, re
from collections import deque, defaultdict, Counter
from math import sqrt, hypot, factorial, pi, sin, cos, radians
from heapq import heappop, heappush, heapify, heappushpop
from bisect import bisect_left, bisect_right
from itertools import permutations, combinations, product
from operator import itemgetter, mul
from copy import deepcopy
from functools import reduce, partial
from fractions import Fraction
from string import ascii_lowercase, ascii_uppercase, digits

def input(): return sys.stdin.readline().strip()
def ceil(a, b=1): return int(-(-a // b))
def round(x): return int((x*2+1) // 2)
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
MOD = 10 ** 9 + 7

S = list(input())
N = len(S)

ans = 0
w_sm = 0
for i in range(N):
    # Wを見つけたら、動かせるだけ左に動かす
    if S[i] == 'W':
        ans += i - w_sm
        # 今左に溜まっているWの数
        w_sm += 1
print(ans)


Measured memory_bytes: 7124
fun main(args: Array<String>) {
    val (N, M) = readLine()!!.split(" "). map { it.toInt() }
    val list = Array(N) { mutableListOf<Int>() }
    val sorted = mutableListOf<Int>() // ソートされたグラフ
    // 入次数
    val indegree = IntArray(N)
    for (i in 0 until M) {
        val (x, y) = readLine()!!.split(" "). map { it.toInt() }
        list[x-1].add(y-1)
        indegree[y-1]++ // 入次数をincrement
    }

    // 入次数が0の物がグラフの始点
    val st = mutableListOf<Int>() // 注意 : Stackの方が良い
    list.forEachIndexed { index, mutableList ->
        if (indegree[index] == 0) st.add(index)
    }

    // ソート
    while(st.isNotEmpty()) {
        val i = st[0]; st.removeAt(0)
        sorted.add(i) // ソート済みのリストに追加

        // 隣接する頂点
        list[i].forEach { j ->
            indegree[j]-- // 隣接する頂点の入次数をデクリメント
            if (indegree[j] == 0) st.add(j) // 入次数が0になればstに追加
        }
    }

    // 最長パスを判定
    val ans = IntArray(N)
    ans[0] = 0
    sorted.forEach { i ->
        list[i].forEach {
            ans[it] = Math.max(ans[it], ans[i] + 1)
        }
    }
    println(ans.max())
}

Measured memory_bytes: 79212
#include <iostream>
#include <cstdlib>
#include <cstdio>
#include <cstring>
#include <queue>
using namespace std;
const int maxn=10005;
bool used[maxn];
long long  d[maxn];
int n,m;
int len;
struct Tree{
   int to;
  int from;
  int value;
  int next;
  int cost;

}tree[maxn*maxn];
int head[maxn];
long long  cost[maxn];
void add(int u,int v,int c,int d)
{   tree[len].from=u;
   tree[len].to=v;
    tree[len].value=c;
    tree[len].next=head[u];
    tree[len].cost=d;
    head[u]=len++;




}
void init()
{  memset(head,-1,sizeof(head));
   len=0;
   memset(cost,0x3f,sizeof(cost));


}
/*int spfa()
{  queue<int>q;
//int sum=0;
   memset(d,0x3f,sizeof(d));
   memset(used,false,sizeof(used));
   d[0]=0;
   cost[0]=0;
   while(!q.empty()) q.pop();
   used[1]=true;
   q.push(1);
   d[1]=0;
   cost[1]=0;
    while(!q.empty())
    {    //ceshi=false;
        int u=q.front();
       used[u]=false;
       q.pop();
        for(int i=head[u];i!=-1;i=tree[i].next)
        {    int  s=tree[i].to;
              int w=tree[i].cost;
            if(d[s]>d[u]+tree[i].value)
              {   if(!used[s])
                     {used[s]=true;
                      q.push(s);
                     }
                  d[s]=d[u]+tree[i].value;
                  cost[s]=w;

                  }
               else if(d[s]==d[u]+tree[i].value)
                  {  if(cost[s]>w)
                      cost[s]=w;

                  }
        }
        //q.pop();
    }
    for(int i=1;i<=n;i++)
       cost[0]+=cost[i];
       printf("%lld\n",cost[0]);
return 0;

}*/
int spfa(int n)
{  queue<int>q;
    int u,sum2=0;
    d[0]=0;
    cost[0]=0;
    for(int i=1; i<=n; i++)
    {
        d[i]=0x3f3f3f3f;
        cost[i]=0x3f3f3f3f;
    }
    memset(used,false,sizeof(used));
    while(!q.empty())
        q.pop();
    q.push(1);
    //sum2++;
    used[1]=true;
    d[1]=0;
    cost[1]=0;
    while(!q.empty())
    {
        u=q.front();
        q.pop();
        used[u]=false;

        for(int i=head[u]; i!=-1; i=tree[i].next)
        {
            int v=tree[i].to;
            int w=tree[i].cost;
            int dd=tree[i].value;
            if(d[v]>d[u]+dd)//不能在?里直接用等号，用了之后第三??例?不去
            {
                d[v]=d[u]+dd;
                cost[v]=w;
                if(!used[v])
                {
                    used[v]=true;
                    q.push(v);
                }

            }
            else if(d[v]==d[u]+dd)
            {
                if(cost[v]>w)
                    cost[v]=w;
            }
        }
    }
    for(int i=1;i<=n;i++)
        cost[0]+=cost[i];
        return cost[0];

}
int main()
{   int a,b,c,d;
     while(~scanf("%d%d",&n,&m),m+n)
    {   init();
        for(int i=1;i<=m;i++)
     {   scanf("%d%d%d%d",&a,&b,&c,&d);
         add(a,b,c,d);
         add(b,a,c,d);

     }
     //spfa();
     printf("%d\n",spfa(n));


    }

return 0;
}

Measured memory_bytes: 4108
unittest
{
	assert( [ "29" ].parse.expand.solve == "Yes" );
	assert( [ "72" ].parse.expand.solve == "No" );
	assert( [ "91" ].parse.expand.solve == "Yes" );
}



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

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

auto parse( Range )( Range input )
if( isInputRange!Range && is( ElementType!Range == string ) )
{
	auto n = input.front.strip.to!( long );
	return tuple( n );
}

auto solve( long n )
{
	return ( n % 10 == 9 || n / 10 == 9 ) ? "Yes" : "No";
}


Measured memory_bytes: 256
a=int(input())
b=int(input())
c=int(input())
d=int(input())
e=int(input())
f=int(input())
A=[a,b,c,d]
B=[e,f]
x=sorted(A)
y=sorted(B)
print(x[3]+x[1]+x[2]+y[1])


Measured memory_bytes: 5596
import itertools
N = int(input())
shougens = []
for _ in range(N):
    A = int(input())
    s = [] 
    for _ in range(A):
        s.append(tuple(map(int, input().split())))
    shougens.append(s)

maxcount = 0
for li in itertools.product([0, 1], repeat=N):
    for man, shojiki in enumerate(li):
        ss = shougens[man]
        is_break = False
        for x, y in ss:
            x = x - 1
            if shojiki and li[x] != y:
                # 現在のパターンと矛盾した場合
                is_break = True
                break
            
        if is_break:
            break
    else:
        # iのビット1の数
        maxcount = max(maxcount, sum(li))

print(maxcount)

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

int main() {
    int D, N;
    cin >> D >> N;
    int ans = N * pow(100, D);
    if (N == 100)
    {
        ans += pow(100, D);
    }
    
    cout << ans << endl;

  return 0;
}

Measured memory_bytes: 256
import sys, bisect, math, itertools, string, queue, copy
# import numpy as np
# import scipy
from collections import Counter,defaultdict,deque
from itertools import permutations, combinations, combinations_with_replacement
from heapq import heappop, heappush
from fractions import gcd
# input = sys.stdin.readline
sys.setrecursionlimit(10**8)
mod = 10**9+7
def inp(): return int(input())
def inpm(): return map(int,input().split())
def inpl(): return list(map(int, input().split()))
def inpls(): return list(input().split())
def inplm(n): return list(int(input()) for _ in range(n))
def inplL(n): return [list(input()) for _ in range(n)]
def inplT(n): return [tuple(input()) for _ in range(n)]
def inpll(n): return [list(map(int, input().split())) for _ in range(n)]
def inplls(n): return sorted([list(map(int, input().split())) for _ in range(n)])

def main():
    a,b = inpm()
    print(a*b)
    
if __name__ == "__main__":
    main()

Measured memory_bytes: 10848
import sys
input = lambda : sys.stdin.readline().rstrip()

M = 998244353

n = int(input())
xs = [0] * n
ds = [0] * n
for i in range(n):
    x, d = (int(c) for c in input().split())
    ds[i] = d
    xs[i] = (x,i)

import sys
sys.setrecursionlimit(max(1000,n))

xs.sort()
index = [x[1] for x in xs]
xs = [x[0] for x in xs]
ds = [ds[ind] for ind in index]

def _sub(i):
    # 深さ優先探索しながらi番目以下の組み合わせと、次に調べるべき番号を返す
    if i==n-1:
        return 2, n
    res = 1
    ind = i+1
    while True:
        if (xs[i]+ds[i] <= xs[ind]):
            break
        o, ind = _sub(ind)
        res *= o
        res %= M
        if ind>=n:
            break
    return res+1, ind
out = []
done = 0
while True:
    o, done = _sub(done)
    out.append(o)
    if done>=n:
        break
result = 1
for o in out:
    result *= o
    result %= M
print(result)

Measured memory_bytes: 198700
#pragma GCC optimize("O3")
#include<bits/stdc++.h>
#define INF 2147483647
#define LLINF 9223372036854775807
using namespace std;
int main(){
	int h,w,n;
	cin>>h>>w>>n;
	if(h<w)swap(h,w);
	if(n%h==0){
		cout<<n/h<<endl;
		return 0;
	}
	else{
		cout<<n/h+1<<endl;
		return 0; 
	}
	return 0;
}

Measured memory_bytes: 256
#ifdef _DEBUG
#define _CRT_SECURE_NO_WARNINGS
#include "MyLib.h"
#else
#define main_B main
#include "bits/stdc++.h" 
#include <regex>
#define _USE_MATH_DEFINES
#include <math.h>
#define FOR(i,s,e) for (int i = int(s); i < int(e); ++i)
#define REP(i,e) FOR(i,0,e)
#define INF (INT_MAX/2)
#define EPS (1.0e-8)
#define MGN 8
#define LINF (LONG_MAX/2)
using namespace std;
typedef long long ll; typedef unsigned long long ull;
typedef vector<int> vi; typedef vector<vi> vvi; 
typedef vector<ll> vl; typedef vector<vl> vvl;
typedef vector<double> vd; typedef vector<string> vs;
typedef pair<int, int> pii; typedef pair<ll, ll> pll;
typedef vector<bool> vb; typedef vector<vb> vvb;
template <typename T>
using keyVal = pair<string, T>;
template<typename T>
bool val_greater(const keyVal<T>& left, const keyVal<T>& right) {
    return left.second > right.second;}
vs split(string str, char sep) {
    vs v; stringstream ss(str); string t;
    while (getline(ss, t, sep)) v.push_back(t);
    return v;}
vs re_search_g(string s, regex re) {
    vs ret; smatch mc; auto it = s.cbegin();
    while (regex_search(it, s.cend(), mc, re)) {
        ret.push_back(mc[0]);
        it += mc.position(0) + mc.length();}
    return ret;}
#endif

void init_global_B() {}

bool isEvenString(string s){
    int L = s.size();

    if (L % 2 == 1) return false;
    
    for(int i=0; i<L/2; i++) {
        if (s[i] != s[L / 2 + i]) return false;
    }

    return true;
}

int main_B() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    string S; cin >> S;

    string t = S.substr(0, S.size() - 1);

    int ans = 0;
    while(t.size() > 0) {
        if (isEvenString(t)) {
            ans = t.size();
            break;
        }else {
            t = t.substr(0, t.size() - 1);
        }
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256
#include <cstdio>
#include <cstring>
#include <functional>
#include <vector>

using namespace std;

#define int long long
#define dotimes(i, n) for (int i = 0, i##max__ = (n); i < i##max__; i++)
#define whole(x, f, ...) ([&](decltype((x)) c) { return (f)(begin(c), end(c), ## __VA_ARGS__); })(x)

int rint() {
  int x;
  scanf("%lld", &x);
  return x;
}

void wint(int x) {
  printf("%lld\n", x);
}

template<typename T> int size(T const& c) { return static_cast<int>(c.size()); }
template <typename T> bool maxs(T& a, T const& b) { return a < b ? a = b, true : false; }
template <typename T> bool mins(T& a, T const& b) { return a > b ? a = b, true : false; }
inline int lg(int x) { return 63 - __builtin_clzll(static_cast<unsigned int>(x)); }

signed main() {
  constexpr int n_max = 2e5;
  char s[n_max+1], r[n_max+1];
  scanf("%s\n", s);
  const int n = strlen(s), m = 1 << (lg(2*n-1) + 1);
  const int k = rint();
  s[n] = 127;
  vector<pair<int, int>> xs(m);
  dotimes(i, n) {
    xs[m/2+i].first = 1;
    xs[m/2+i].second = i;
  }
  dotimes(i, m/2 - n) {
    xs[m/2+n+i].first = 0;
    xs[m/2+n+i].second = n;
  }
  for (int i = m/2 - 1; i >= 1; i--) {
    xs[i].first = xs[2*i].first + xs[2*i+1].first;
    xs[i].second = xs[2*i + (s[xs[2*i+1].second] < s[xs[2*i].second])].second;
  }
  function<int(int, int)> rec;
  rec =
    [&](int i, int l) {
      if (xs[i].first <= l)
        return xs[i].second;
      if (xs[2*i].first >= l)
        return rec(2*i, l);
      int a = xs[2*i].second, b = rec(2*i+1, l - xs[2*i].first);
      return s[b] < s[a] ? b : a;
    };
  int i = 0;
  for (int l = k; i < n && l > 0; i++) {
    int j = rec(1, l+1);
    r[i] = s[j];
    xs[m/2+j].first = 0;
    xs[m/2+j].second = n;
    int c = 0;
    for (int a = (m/2+j)/2, b = m/2+j; a >= 1; b = a, a /= 2) {
      int p = 2*a, q = 2*a+1;
      if (b == q)
        c += xs[p].first;
      xs[a].first = xs[p].first + xs[q].first;
      xs[a].second = xs[p + (s[xs[q].second] < s[xs[p].second])].second;
    }
    l -= c;
  }
  if (i < n)
    dotimes(j, n)
      if (xs[m/2+j].first)
        r[i++] = s[j];
  r[n] = 0;
  puts(r);
  return 0;
}



Measured memory_bytes: 10848