akhauriyash/Code-Regression huggingface dataset:
#!/usr/bin/env python
import string
import sys
from itertools import chain, dropwhile, takewhile


def read(
    *shape, f=int, it=chain.from_iterable(sys.stdin), whitespaces=set(string.whitespace)
):
    def read_word():
        w = lambda c: c in whitespaces
        nw = lambda c: c not in whitespaces
        return f("".join(takewhile(nw, dropwhile(w, it))))

    if not shape:
        return read_word()
    elif len(shape) == 1:
        return [read_word() for _ in range(shape[0])]
    elif len(shape) == 2:
        return [[read_word() for _ in range(shape[1])] for _ in range(shape[0])]


def readi(*shape):
    return read(*shape)


def readi1(*shape):
    return [i - 1 for i in readi(*shape)]


def readf(*shape):
    return read(*shape, f=float)


def reads(*shape):
    return read(*shape, f=str)


def arr(*shape, fill_value=0):
    if len(shape) == 1:
        return [fill_value] * shape[0]
    elif len(shape) == 2:
        return [[fill_value] * shape[1] for _ in range(shape[0])]


def dbg(**kwargs):
    print(
        ", ".join("{} = {}".format(k, repr(v)) for k, v in kwargs.items()),
        file=sys.stderr,
    )


from collections import defaultdict
import sys

sys.setrecursionlimit(100000)

def main():
    N, M = readi(2)
    edges = readi(M, 3)
    pred = defaultdict(list)
    for a, b, _ in edges:
        pred[b].append(a)
    # dbg(pred=pred)
    s = set()
    s2 = set()

    def rec(n):
        if n not in s2:
            s2.add(n)
            for m in pred[n]:
                s.add(m)
                rec(m)

    rec(N)
    # dbg(s=s)
    dist = arr(N + 1, fill_value=float("-inf"))
    dist[1] = 0
    for i in range(N):
        for a, b, c in edges:
            new_d = dist[a] + c
            if new_d > dist[b]:
                if i == N - 1 and b in s:
                    print("inf")
                    return
                dist[b] = new_d
    print(dist[N])


if __name__ == "__main__":
    main()


Measured memory_bytes: 5108
#define _CRT_SECURE_NO_WARNINGS
#include<stdio.h>
#include<vector>
#include<functional>
#include<algorithm>
#include<stdlib.h>
#include<string>
#include<string.h>
#define _USE_MATH_DEFINES
#include<math.h>
#include<deque>
#include<set>
#include<map>
#include<queue>
#include<list>
#include<iostream>
#include <bitset>
using namespace std;
typedef long long ll;
#define rep(i,a,b) for(auto i=a;i<b;i++)
#define all(_x) _x.begin(), _x.end()
#define r_sort(_x) sort(_x.begin(), _x.end(), std::greater<int>())
#define vec_cnt(_a, _n) (upper_bound(all(_a), _n) - lower_bound(all(_a), _n))
#define vec_unique(_a) _a.erase(std::unique(all(_a)), _a.end());
#define vvec vector<vector<ll>>
ll gcd(ll a, ll b) { return a % b == 0 ? b : gcd(b, a % b); }
ll lcm(ll a, ll b) { return (a / gcd(a, b)) * b; }
#define INF 1 << 30
const int mod = 1000000007;
ll power(ll x, ll p) { ll a = 1; while (p > 0) { if (p % 2 == 0) { x *= x; p /= 2; } else { a *= x; p--; } }return a; }
ll mpower(ll x, ll p) { ll a = 1; while (p > 0) { if (p % 2 == 0) { x = x * x % mod; p /= 2; } else { a = a * x % mod; p--; } }return a; }
ll ac(ll n, ll k) { ll a = 1; rep(i, 1, k) { a *= n - i + 1; a /= i; }return a; }
ll mc(ll n, ll m) { ll k = 1, l = 1; rep(i, n - m + 1, n + 1) k = k * i % mod; rep(i, 1, m + 1) l = l * i % mod; l = mpower(l, mod - 2); return k * l % mod; }
int D;
vector<int> c(26);
vector<int> last(26, 0);
vector<vector<int>> s(365, vector<int>(26));
void input();
int score;
int next_num;
const int Way = 12;
const int Nest = 3;
/*void dfs(int nest, int d) {
	int M = 0, temp = score;
	int prev, n;
	vector<pair<int, int>> kouho(26);
	rep(j, 0, 26) {
		score = temp;
		score += s[d - 1][j];
		prev = last[j];
		last[j] = d;
		rep(k, 0, 26)score -= c[k] * (d - last[k]);
		kouho[j].first = score;
		kouho[j].second = j;
		last[j] = prev;
	}
	//sort(all(kouho), greater<pair<int, int>>());
	rep(j, 0, Way) {
		//prev = last[kouho[j].second];
		//last[kouho[j].second] = d;
		score = kouho[j].first;
		if (nest && d < D)dfs(nest - 1, d + 1);
		if (M < score)M = score, n = kouho[j].second;
		printf("j:%2d score:%d\n", j, score);
		//last[kouho[j].second] = prev;
	}
	score = M;
	next_num = n;
}*/
int dfs(int nest, int i) {
	ll M = -1 << 30, temp = score;
	int prev, p;
	vector<pair<int, int>> kouho(26);
	rep(j, 0, 26) {
		score = temp + s[i - 1][j];
		rep(k, 0, 26)if (j != k)score -= c[k] * (i - last[k]);
		kouho[j].first = score;
		kouho[j].second = j;
	}
	sort(all(kouho), greater<pair<int, int>>());
	rep(j, 0, Way){
		score = kouho[j].first;
		prev = last[kouho[j].second];
		last[kouho[j].second] = i;
		if (nest && i < D)dfs(nest - 1, i + 1);
		last[kouho[j].second] = prev;
		if (M < score)M = score, p = kouho[j].second;
	}
	score = M;
	return p;
}
int main()
{
	input();
	/*rep(i, 1, D + 1) {
		//score = 0;
		dfs(Nest, i);
		printf("%d\n", next_num + 1);
		last[next_num] = i;
		printf("%d\n", score);
	}*/
	rep(i, 1, D + 1) {
		score = 0;
		int p = dfs(Nest, i);
		last[p] = i;
		printf("%d\n", p + 1);
		//printf("%d\n", score);
	}
	return 0;
}
void input() {
	cin >> D;
	rep(i, 0, 26)cin >> c[i];
	rep(i, 0, D) {
		rep(i2, 0, 26)cin >> s[i][i2];
	}
}

Measured memory_bytes: 3752
import collections

N=int(input())
a=list(map(int,input().split()))
Q=int(input())
l=[0]*Q
for i in range(Q):
    l[i]=list(map(int,input().split()))

answer=sum(a)

b=collections.Counter(a)
    
for i in range(Q):    
    num=b[l[i][0]]
    variance=l[i][1]-l[i][0]
    answer+=variance*num
    print(answer)
    b[l[i][0]]=0
    b[l[i][1]]+=num

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

int main() {
  int N,M;
  cin>>N>>M;
  vector<int> D(N);
  vector<int> A(2);
  for(int i=0;i<M;i++){
    cin>>A.at(0)>>A.at(1);
    D.at(A.at(0)-1)++;
    D.at(A.at(1)-1)++;
  }
  for(int i=0;i<N;i++){
    cout<<D.at(i)<<endl;
  }
}


    

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define int long long
using namespace std;
signed main(){
	//freopen(".in","r",stdin);
	//freopen(".out","w",stdout);
	int n;
	cin>>n;
	if(n%1000==0){
		cout<<'0'<<endl;
		return 0;
	}else{
		int sum=1000;
		while(sum<n){
			sum+=1000;
		}
		cout<<sum-n<<endl;
	}
	return 0;
}


Measured memory_bytes: 3624
#include<algorithm>
#include<algorithm>     //sort,二分探索,など
#include<bitset>        //固定長bit集合
#include<cmath>         //pow,logなど
#include<complex>       //複素数
#include<deque>         //両端アクセスのキュー
#include<functional>    //sortのgreater
#include<iomanip>       //setprecision(浮動小数点の出力の誤差)
#include<iostream>      //入出力
#include<iterator>      //集合演算(積集合,和集合,差集合など)
#include<map>           //map(辞書)
#include<numeric>       //iota(整数列の生成),gcdとlcm(c++17)
#include<queue>         //キュー
#include<set>           //集合
#include<stack>         //スタック
#include<string>        //文字列
#include<unordered_map> //イテレータあるけど順序保持しないmap
#include<unordered_set> //イテレータあるけど順序保持しないset
#include<utility>       //pair
#include<vector>        //可変長配列

using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<ld> vld;
typedef vector<string> vs;
typedef vector<bool> vb;
typedef vector<vector<int>> vvi;
typedef vector<vector<ll>> vvll;
typedef vector<vector<ld>> vvld;
typedef vector<vector<string>> vvs;
typedef vector<vector<bool>> vvb;
const ll MOD = 1000000007;
const ll INF = 1000000000000000000;
#define rep(i,n) for(int i=0;i<n;i++)
#define repl(i,s,e) for(int i=s;i<e;i++)
#define reple(i,s,e) for(int i=s;i<=e;i++)
#define revrep(i,n) for(int i=n-1;i>=0;i--)
#define all(x) (x).begin(),(x).end()

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

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

    int N, W;
    cin >> N >> W;

    vll w(N), v(N);
    rep(i, N) cin >> w[i] >> v[i];

    vvll dp(N + 1, vll(W + 1));

    rep(i, N)
    {
        reple(j, 0, W)
        {
            dp[i + 1][j] = dp[i][j];

            if (j - w[i] >= 0) chmax(dp[i + 1][j], dp[i][j - w[i]] + v[i]);
        }
    }

    cout << dp[N][W] << endl;

    return 0;
}

Measured memory_bytes: 80256
#include <algorithm>
#include <cstdlib>
#include <iostream>
#include <vector>

using cost_type = int;

cost_type sub(std::vector<cost_type> h)
{
	std::vector<cost_type> dp(h.size());
	dp[0] = 0;
	dp[1] = std::abs(h[0] - h[1]);
	for (std::size_t i = 2; i < dp.size(); ++i) {
		dp[i] = std::min(dp[i - 1] + std::abs(h[i - 1] - h[i]),
			dp[i - 2] + std::abs(h[i - 2] - h[i]));
	}
	return dp.back();
}

int main(void)
{
	std::size_t N;
	std::cin >> N;

	std::vector<cost_type> h(N);

	for (auto& x : h) {
		std::cin >> x;
	}

	std::cout << sub(h) << std::endl;

	return 0;
}


Measured memory_bytes: 1408
#include<iostream>
#include<algorithm>
#include<climits>

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

using namespace std;

int digits(long long n){
  int total = 0;
  while(n > 0){
    n /= 10;
    total++;
  }
  return total;
}

int main()
{
  long long n;
  int  x = INT_MAX;
  cin >> n;

  for(long long i=1; i * i <= n; i++){
      if(n % i != 0)
        continue;
      long long j = n / i;
      //cout << i << " " << j << endl;
     // cout << digits(i) << ' ' << digits(j) << endl;
     int ans = max(digits(i),digits(j));
      if(x > ans)
        x = ans;
  }
  cout << x << endl;
}


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

int main() {
  string s,t;
  cin >> s >> t;
  sort(s.begin(),s.end());
  sort(t.begin(),t.end(),greater<char>());
  if(s<t) cout << "Yes" << endl;
  else cout << "No" << endl;
  return 0;
}


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

#define REP(i,n) for(ll i=0;i<ll(n);++i)
#define RREP(i,n) for(ll i=ll(n)-1;i>=0;--i)
#define FOR(i,m,n) for(ll i=m;i<ll(n);++i)
#define RFOR(i,m,n) for(ll i=ll(n)-1;i>=ll(m);--i)
#define ALL(v) (v).begin(),(v).end()
#define UNIQUE(v) v.erase(unique(ALL(v)),v.end());
#define INF 1000000001ll
#define MOD 1000000007ll
#define EPS 1e-9

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


using namespace std;

using ll = long long;
using vi = vector<int>;
using vl = vector<ll>;
using vvi = vector<vi>;
using vvl = vector<vl>;
using pii = pair<int, int>;
using pll = pair<ll, ll>;

template <class T> bool chmin(T & a, T b) { if (a > b) { a = b; return true; } return false; }
template <class T> bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
struct Edge {
	int from, to, cost;
	bool operator < (Edge& rhs) const {
		return this->cost < rhs.cost;
	}
};
#include "bits/stdc++.h"
struct UnionFind {
	std::vector<int> par;
	std::vector<int> sizes;

	UnionFind(int n) {
		par.resize(n);
		sizes.resize(n);
		for (int i = 0; i < n; ++i) {
			par[i] = i;
			sizes[i] = 1;
		}
	}

	int root(int a) {
		return par[a] == a ? a : par[a] = root(par[a]);
	}

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

	void unite(int x, int y) {
		x = root(x);
		y = root(y);
		if (x == y)return;
		if (sizes[x] < sizes[y]) std::swap(x, y);

		par[y] = x;
		sizes[x] += sizes[y];
	}
	int size(int x) {
		return sizes[root(x)];
	}
};


using Graph=vector<vector<Edge>>;
int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	int n, m;
	while (cin >> n >> m, n) {
		vector<Edge> e(m);
		REP(i, m) {
			int a, b, c; cin >> a >> b >> c;
			e[i] = { a - 1,b - 1,c };
		}
		sort(ALL(e));
		{
			UnionFind uf(n);
			REP(i, m)uf.unite(e[i].from, e[i].to);
			if (uf.size(0) != n) {
				cout << -1 << endl;
				continue;
			}
		}
		int ans = INF;
		REP(i, m) {
			UnionFind uf(n);
			FOR(j, i, m) {
				uf.unite(e[j].from, e[j].to);
				if (uf.size(0) == n) {
					chmin(ans, e[j].cost - e[i].cost);
					break;
				}
			}
		}
		cout << ans << endl;
	}

}


Measured memory_bytes: 3272
def getTableKMP(Ss):
    Ss += '$'
    lenS = len(Ss)
    table = [-1] * lenS
    j = -1
    for i in range(lenS-1):
        while j >= 0 and Ss[i] != Ss[j]:
            j = table[j]
        j += 1
        if Ss[i+1] == Ss[j]:
            table[i+1] = table[j]
        else:
            table[i+1] = j
    return table

def getPosPtnsKMP(Ss, ptn, table):
    anss = []
    lenS, lenP = len(Ss), len(ptn)
    iS, iP = 0, 0
    while iS < lenS:
        if Ss[iS] == ptn[iP]:
            iS += 1
            iP += 1
            if iP == lenP:
                anss.append(iS-lenP)
                iP = table[iP]
        else:
            iP = table[iP]
            if iP == -1:
                iS += 1
                iP = 0
    return anss


Ss = input()
Ts = input()

lenS, lenT = len(Ss), len(Ts)
num = (lenT+lenS-1+lenS-1) // lenS
S2s = Ss * num

tableKMP = getTableKMP(Ts)
posPtns = getPosPtnsKMP(S2s, Ts, tableKMP)

isFounds = [False] * lenS
for pos in posPtns:
    if pos >= lenS:
        break
    isFounds[pos] = True

ans = 0
numDone = 0
for i in range(lenS):
    if not isFounds[i]:
        i = (i+lenT) % lenS
        for num in range(lenS+1):
            if not isFounds[i]:
                ans = max(ans, num)
                numDone += num+1
                break
            i = (i+lenT) % lenS
        else:
            ans = -1
            break

if numDone < lenS:
    ans = -1
print(ans)


Measured memory_bytes: 33552
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<iomanip>
#include<math.h>
#include<complex>
#include<queue>
#include<deque>
#include<stack>
#include<map>
#include<set>
#include<bitset>
#include<functional>
#include<assert.h>
#include<numeric>
#include<stdio.h>
#include <cstdint>
using namespace std;
#define REP(i,m,n) for(int i=(int)(m) ; i < (int) (n) ; ++i )
#define rep(i,n) REP(i,0,n)
using ll = long long;
const int inf = 1e9 + 7;
const ll longinf = 1LL << 60;
const ll mod = 1e9 + 7;



int main() {

	while (true) {
		int n, k, ans = 0;
		int a[100002], b[100002];
		cin >> n >> k;
		if (n == 0 && k == 0)break;
		rep(i, n)cin >> a[i];
		b[0] = 0;
		REP(i, 1, n + 1)b[i] = b[i - 1] + a[i - 1];

		REP(i, k, n + 1)ans = max(ans, b[i] - b[i - k]);

		cout << ans << endl;
	}

	return 0;
}


Measured memory_bytes: 3876
#include <cstdio>
#include <cmath>
#include <cstring>
#include <iostream>
#include <sstream>

#include <memory>
#include <string>
#include <vector>
#include <queue>
#include <list>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <stack>
#include <deque>
#include <algorithm>
#include <random>
#include <iomanip>
using namespace std;

int main(int argc, char *argv[]) {
	int n, k;
	long long int res = 0;
	cin >> n >> k;
	vector<long long int> v;
	for (int i = 0; i < n; i++) {
		long long int t;
		cin >> t;
		v.push_back(t);
	}
	unordered_map<int, int> um;
	long long int c = 0;
	um[0] = 1;
	vector<long long int> vv;
	vv.push_back(0);
	for (int i = 0; i < n; i++) {
		if (i - k + 1>= 0) {
			um[vv[i + 1- k]]--;
		}
		c += v[i];
		c %= k;
		long long int target = c - i - 1;
		if (target < 0) {
			target += (-target) / k * k + k;
		}
		target %= k;
		// cout << target << " ";
		res += um[(target) % k];
		um[target]++;
		vv.push_back(target);
	}
	cout << res << endl;
}


Measured memory_bytes: 11632
#include <iostream>
//#include <set>
//#include <map>
//#include <iomanip>
//#include <algorithm>
//#include <numeric>
//#include <queue>
//#include <stack>
//#include <math.h>
#include <vector>
//#include <string>
//#include <list>
//#include <deque>
//#include <unordered_map>
typedef long long LL;
//typedef long double LD;
using namespace std;
 
//#define MOD 1000000007
//#define MAX 200100
//#define NIL -1

int main() {
    int n;
    int m;
    vector<LL> h;
    LL tmp_h;
    vector<LL> h_ok;
    vector<int> a;
    vector<int> b;
    int tmp_a;
    int tmp_b;
    int ans=0;

    cin >> n >> m;
    for(int i=0; i<n; i++){
        cin >> tmp_h;
        h.push_back(tmp_h);
        h_ok.push_back(1);
    }

    for(int i=0; i<m; i++){
        cin >> tmp_a >> tmp_b;
        tmp_a--;
        tmp_b--;
        a.push_back(tmp_a);
        b.push_back(tmp_b);
    }

    for(int i=0; i<m; i++){
        if(h[a[i]]>=h[b[i]]){
            h_ok[b[i]]=0;
        }
        if(h[a[i]]<=h[b[i]]){
            h_ok[a[i]]=0;
        }        
    }

    for(int i=0; i<n; i++){
        ans+=h_ok[i];
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 6128
from collections import deque

n = int(input())
if n == 1:
    print('a')
else:
    q = deque(['a'])
    while q:
        x = q.popleft()
        l = len(x)
        s = len(set(x))
        for i in range(s+1):
            nx = x + chr(i + 97)
            if l + 1 == n:
                print(nx)
            if l < n - 1:
                q.append(nx)


Measured memory_bytes: 5532
#include "bits/stdc++.h"
using namespace std;

int main() {
	long long N, A, MIN = 1000000001, MAX = -1000000000, SUM = 0;
	cin >> N;
	for (int i = 0; i < N; i++) {
		cin >> A;
		MIN = min(MIN, A);
		MAX = max(MAX, A);
		SUM += A;
	}
	cout << MIN << " " << MAX << " " << SUM << endl;
}


Measured memory_bytes: 3116
#include<bits/stdc++.h>
#define FOR(i,a,b)for(int i=(a),_b=(b);i<=_b;i++)
#define FORN(i,b,a)for(int i=(b);_a=(a);i>=_a;i--)
#define REP(i,n)for(int i=0,_n=n;i<n;i++)
#define ll long long
#define pii pair<int,int>
#define re return
#define vi vector<int>
#define pb push_back
#define si set<int>
#define in insert
#define fl float
#define db double
#define ld long double
#define X first
#define Y second
#define st string
#define ull unsigned long long
using namespace std;
inline void read(int &x)
{
	short negative=1;
    x=0;
    char c=getchar();
    while(c<'0' || c>'9')
    {
		if(c=='-')
			negative=-1;
		c=getchar();
	}
    while(c>='0' && c<='9')
        x=(x<<3)+(x<<1)+(c^48),c=getchar();
    x*=negative;
}
int main()
{
	int n;
	int a[200100];
	int b[200100];
	cin>>n;
	REP(i,n)
	{
		cin>>a[i];
		b[i]=a[i];
	}
	sort(b,b+n);
	int ansa=b[n/2-1];
	int ansb=b[n/2];
	REP(i,n)
	{
		if(a[i]>=ansb)cout<<ansa<<endl;
		else cout<<ansb<<endl;
	}
	return 0;
}



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

int main(){
	string s = "aA";
	getline(cin, s);
	for(int i = 0;i < s.size();i++){
		if(s[i] >= 'a' && s[i] <= 'z')s[i]-=32;
	}
	cout << s << endl;
	return 0; 
}

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

using namespace std;

typedef long long ll;

ll N, x;
ll a[100010];

ll check(ll m)
{
  if(m > a[0]) return 1LL<<55;
  ll b[100010];
  for(int i = 0; i < N; i++) b[i] = a[i];
  ll ans = m;
  b[0] -= m;
  for(int i = 1; i < N; i++) {
    if(b[i] + b[i-1] > x) {
      ans += (b[i] + b[i-1]) - x;
      b[i] = max(x - b[i-1], 0LL);
    }
  }
  return ans;
}

int main()
{
  cin >> N >> x;
  for(int i = 0; i < N; i++) cin >> a[i];
  ll lb = 0, ub = 1LL<<55;
  ll ans = 1LL<<55;
  while(lb < ub) {
    ll mb = (lb + ub) / 2;
    ll tmp = check(mb);
    if(tmp <= ans) ans = tmp, ub = mb;
    else lb = mb + 1;
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 1792
s = list(input())

for i in range(len(s)):
    if s[i] == 'A':
        s = s[i:]
        break
for i in range(len(s) - 1, -1, -1):
    if s[i] == 'Z':
        s = s[:i + 1]
        break
print(len(s))


Measured memory_bytes: 6180
#include <iostream>
#include <stack>
#include <math.h>
#include <vector>
#include <string>
#include <algorithm>
#include <map>

#define rep(i,n) for(int i=0; i < n; i++)
using ll =  long long;
using namespace std;
#define pi 3.14159265358979

int main()
{
	string s;
	cin >> s;
	if ((s.find("N") != -1 && s.find("S") == -1) ||
		(s.find("S") != -1 && s.find("N") == -1) ||
		(s.find("W") != -1 && s.find("E") == -1) ||
		(s.find("E") != -1 && s.find("W") == -1))
		 cout << "No";
	else cout << "Yes";
	return 0;
}

Measured memory_bytes: 3600
import math
a, b, h, m = map(int, input().split())
minute = 2 * math.pi * m / 60
h += m / 60
hour = 2 * math.pi * h / 12
l = math.sqrt(a * a + b * b - 2 * a * b * math.cos(minute - hour))
print(l)   


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

// http://www.prefield.com/algorithm/misc/dice.html
enum FACE { TOP, BOTTOM, FRONT, BACK, LEFT, RIGHT };
class dice {
public:
	dice(int top,int front,int right,int left,int back,int bottom) {
		id[TOP] = top; id[FRONT] = front; id[RIGHT] = right;
		id[LEFT] = left; id[BACK] = back; id[BOTTOM] = bottom;
	}
	int& operator[] (FACE f) { return id[f]; }
	const int& operator[] (FACE f) const { return id[f]; }
	bool operator==(const dice &b) const {
		const dice &a = *this;
		return a[TOP] == b[TOP] && a[BOTTOM] == b[BOTTOM] &&
			a[FRONT] == b[FRONT] && a[BACK] == b[BACK] &&
			 a[LEFT] == b[LEFT] && a[RIGHT] == b[RIGHT];
	}
	void roll_north() { roll(TOP, FRONT, BOTTOM, BACK); }
	void roll_south() { roll(TOP, BACK, BOTTOM, FRONT); }
	void roll_east() { roll(TOP, LEFT, BOTTOM, RIGHT); }
	void roll_west() { roll(TOP, RIGHT, BOTTOM, LEFT); }
	void roll_right() { roll(FRONT, LEFT, BACK, RIGHT); }
	void roll_left() { roll(FRONT, RIGHT, BACK, LEFT); }
	void all_rolls(set<long long> &s){
		for (int k = 0; k < 6; (k&1?roll_east():roll_north()),++k)
			for (int i = 0; i < 4; roll_right(), ++i)
				s.insert(((long long)id[TOP]<<40) | ((long long)id[FRONT]<<32) | (id[RIGHT]<<24) | (id[LEFT]<<16) | (id[BACK]<<8) | (id[BOTTOM]<<0));
	}
private:
	void roll(FACE a, FACE b, FACE c, FACE d){
		int tmp = id[a];
		id[a] = id[b]; id[b] = id[c];
		id[c] = id[d]; id[d] = tmp;
	}
	int id[6];
};

int main(){
	int n,d[6];
	cin>>n;
	int i,j;
	set<long long>s;
	for(i=0;i<n;i++){
		for(j=0;j<6;j++)cin>>d[j];
		long long x=((long long)d[0]<<40) | ((long long)d[1]<<32) | (d[2]<<24) | (d[3]<<16) | (d[4]<<8) | (d[5]<<0);
		if(s.find(x)!=s.end()){
			cout<<"No"<<endl;
			return 0;
		}else{
			dice di(d[0],d[1],d[2],d[3],d[4],d[5]);
			di.all_rolls(s);
		}
	}
	cout<<"Yes"<<endl;
}

Measured memory_bytes: 1300
#include<cstdio>
int main()
{
	int n,i,x,max;
	char s[100];
	scanf("%d",&n);
	scanf("%s",s);
	x=0;
	max=0;
	for(i=0;i<n;i++){
		if(s[i]=='I') x+=1;
		else x-=1;
		if(max<x) max=x;
	}
	printf("%d\n",max);
	return 0;
}


Measured memory_bytes: 1720
#include <iostream>

using namespace std;

int main() {
    int n, a;
    cin >> n;
    for(int i = 0; i < n; i++) {
        cin >> a;
        if (a % 2 != 0) continue;
        if (a % 3 == 0 || a % 5 == 0) continue;
        cout << "DENIED" << endl;
        return 0;
    }
    cout << "APPROVED" << endl;
    return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
#include<stdlib.h>
#define MAXDATA 10001
int main(){
  int i,datanum,temp;
  int *a,*b;
  int c[MAXDATA];//a ni dainyu
  scanf("%d",&datanum);
  a = (int *)malloc(sizeof(int) * (datanum + 1));
  b = (int *)malloc(sizeof(int) * (datanum + 1)); //sizeがおおきすぎて、mallocじゃないとエラー吐く
  
  for(i=0;i<MAXDATA;i++){
    c[i] = 0;
  }
  for(i=0;i<datanum;i++){
    scanf("%d",&a[i + 1]);
    c[a[i + 1]]++; 
  }
  for(i=1;i<=MAXDATA;i++){
    c[i] = c[i] + c[i-1];
  }
  
  for(i=datanum;i>=1;i--){
    b[c[a[i]]] = a[i];
    c[a[i]]--;
  }
  for(i=1;i<=datanum;i++){
    if(i != 1)printf(" ");
    printf("%d",b[i]);
  }
  printf("\n");
  return 0;
}




Measured memory_bytes: 17408
#include <algorithm>
#include <iostream>
#include <queue>
#define m make_pair
#define INF (1e9)
#define N 20
using namespace std;
typedef pair<int,int> P;
typedef pair<int,P> P1;
void bfs();
int h,w,sx,sy,gy,gx,p,d[N][N],anst,ansy,ansx;
string str[N],pat;

int main(){
  while(1){
    cin>>h>>w;
    if(!h&&!w) break;
    for(int i=0;i<h;i++) cin>>str[i];
    cin>>pat;
    for(int i=0;i<h;i++)
      for(int j=0;j<w;j++){
	if(str[i][j]=='A') sx=j,sy=i;
	if(str[i][j]=='B') gx=j,gy=i;
      }
    bfs();
    int len=pat.size(),t=0,eflag=0;
    p=0;
    while(1){
      int cy=gy,cx=gx;
      if(pat[p]=='8') gy--;
      if(pat[p]=='6') gx++;
      if(pat[p]=='4') gx--;
      if(pat[p]=='2') gy++;
      p++;
      t++;
      if(p==len) p=0;
      if(gy<0||h<=gy||gx<0||w<=gx) gy=cy,gx=cx;
      if(d[gy][gx]!=INF&&d[gy][gx]<=t){
	anst=max(d[gy][gx],t);
	ansy=gy;
	ansx=gx;
	break;
      }
      if(t==100000){
	eflag=1;
	break;
      }
    }
    if(!eflag) cout<<anst<<' '<<ansy<<' '<<ansx<<endl;
    else cout<<"impossible"<<endl;
  }
  return 0;
}

void bfs(){
  int dy[4]={-1,0,1,0};
  int dx[4]={0,1,0,-1};
  queue<P1> q;
  for(int i=0;i<N;i++)
    for(int j=0;j<N;j++) d[i][j]=INF;
  d[sy][sx]=0;
  q.push(m(0,m(sy,sx)));
  while(!q.empty()){
    P1 t=q.front(); q.pop();
    int c=t.first,uy=t.second.first,ux=t.second.second;
    for(int i=0;i<4;i++){
      int ny=uy+dy[i],nx=ux+dx[i];
      if(ny<0||h<=ny||nx<0||w<=nx) continue;
      if(str[ny][nx]=='#') continue;
      if(d[ny][nx]>c+1){
	d[ny][nx]=c+1;
	q.push(m(d[ny][nx],m(ny,nx)));
      }
    }
  }
}

Measured memory_bytes: 1228
#include <iostream>
#include <cstdio>
#include <cmath>

using namespace std;

int n, m, k;
double ans;

void dfs(int node, int sum) {
    if (node == n) {
        if (sum-k < 1) sum = 1;
        else sum -= k;
        ans += sum;
        return;
    }
    for (int i = 1; i < m+1; i++) {
        dfs(node+1, sum+i);
    }
    return;
}

int main(void){
    while (cin>>n>>m>>k && n) {
        ans = 0;
        dfs(0, 0);
        printf("%.12lf\n", ans / pow(m,n));
    }
}

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

using namespace std;

int main() {
	int N;
	cin >> N;
	vector<int> A(N + 2);

	A[0] = 0;
	for(int i = 1; i <= N; i++) cin >> A[i];
	A[N + 1] = 0;

	int sum = 0;
	for(int i = 1; i <= N + 1; i++) sum += abs(A[i] - A[i - 1]);

	for(int i = 1; i <= N; i++) {
		int tmp = sum;
		tmp -= abs(A[i] - A[i - 1]) + abs(A[i + 1] - A[i]);
		tmp += abs(A[i + 1] - A[i - 1]);
		cout << tmp << endl;
	}
	
	return 0;
}


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

int main() {
  int N, M;
  cin >> N >> M;
  vector<vector<int> > vec(M, vector<int>(0));
  for(int i=0;i<M;i++) {
    int k;
    cin >> k;
    for(int j=0;j<k;j++) {
      int s;
      cin >> s;
      vec[i].push_back(s);
    }
  }

  vector<int> p(M);
  for(int i=0;i<M;i++) {
    cin >> p[i];
  }

  int ans = 0;

  for(int i=0;i<pow(2, N);i++) {
    bitset<10> b(i);
    bool ok = true;
    for(int j=0;j<M;j++) {
      int total = 0;
      for(int k=0;k<vec[j].size();k++) {
        int num = vec[j][k];
        if(b[num-1]) {
          total++;
        }
      }
      if(total % 2 == p[j]) {
        continue;
      } else {
        ok = false;
        break;
      }
    }

    if(ok) {
      ans++;
    }
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
from bisect import bisect_left as bl
from bisect import bisect_right as br
INF = 10 ** 20
w, h = map(int, input().split())
n = int(input())
xlst = []
ylst = []
for i in range(n):
  x, y = map(int,input().split())
  xlst.append(x)
  ylst.append(y)

sorted_xlst = sorted(xlst)
sorted_xlst_d = sorted(xlst * 2)
sorted_ylst = sorted(ylst)
sorted_ylst_d = sorted(ylst * 2)
accx = accy = 0
cum_sum_xlst = []
cum_sum_ylst = []

for i in range(n):
  accx += sorted_xlst[i]
  accy += sorted_ylst[i]
  cum_sum_xlst.append(accx)
  cum_sum_ylst.append(accy)

clx = sorted_xlst_d[n - 1]
crx = sorted_xlst_d[n]
cly = sorted_ylst_d[n - 1]
cry = sorted_ylst_d[n]

num = n * 2 - 1

ans = INF
ansx = 10 ** 10
ansy = 10 ** 10
for i in range(n):
  xi = xlst[i]
  yi = ylst[i]
  if xi <= clx:
    cx = crx
  else:
    cx = clx
  if yi <= cly:
    cy = cry
  else:
    cy = cly

  px = bl(sorted_xlst, cx)
  py = bl(sorted_ylst, cy)
 
  if px:
    xlen = (cx * px - cum_sum_xlst[px - 1]) * 2 + (accx - cum_sum_xlst[px - 1] - cx * (n - px)) * 2 - abs(xi - cx)
  else:
    xlen = (accx - cx * n) * 2 - abs(xi - cx)

  if py:
    ylen = (cy * py - cum_sum_ylst[py - 1]) * 2 + (accy - cum_sum_ylst[py - 1] - cy * (n - py)) * 2 - abs(yi - cy)
  else:
    ylen = (accy - cy * n) * 2 - abs(yi - cy)
  
  tlen = xlen + ylen
  if ans > tlen:
    ans = tlen
    ansx = cx
    ansy = cy
  elif ans == tlen:
    if ansx > cx:
      ansx = cx
      ansy = cy
    elif ansx == cx:
      if ansy > cy:
        ansy = cy 
print(ans)
print(ansx, ansy)


Measured memory_bytes: 29212
a,b = map(int,input().split())
s = input()
ans = "0123456789"

if len(s) == a+b+1 and s[a] == "-":
    x = s[:a]
    y = s[a+1:]
    for i in x:
        if i not in ans:
            print("No")
            break
    else:
        for j in y:
            if j not in ans:
                print("No")
                break
        else:
            print("Yes")
else:
    print("No")
    
        

Measured memory_bytes: 3060
#include <iostream>
#include <cmath>

using namespace std;

int main() {
	int a[5];
	for (int i = 0; i < 5; i++)
		cin >> a[i];

	int ans = 0, c = 10;
	for (int i = 0; i < 5; i++) {
		if (a[i] % 10 == 0) ans += (a[i] / 10) * 10;
		else {
			c = min(c, a[i] % 10);
			ans += (a[i] / 10 + 1) * 10;
		}
	}
	ans -= 10 - c;

	cout << ans << endl;

	return 0;
}

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

int main(){
	
	int n,k;
	cin>>n>>k;
	vector<int> v(n+1);
	for(int i=0;i<n;++i){
		cin>>v[i];
	}
	vector<int> dp(n+1,INT_MAX);
	dp[0]=0;
	for(int i=0;i<n;++i){
		for(int j=i+1;j<n && j<=i+k;++j){
			dp[j]=min(dp[j],abs(v[j]-v[i])+dp[i]);
		}
	}
	cout<<dp[n-1];
	return 0;
}


Measured memory_bytes: 4016
#include<bits/stdc++.h>
using namespace std;
int main()
{
    unsigned long long a,b,n;
    cin>>a>>b>>n;
    if(n>=b-1){
    cout<<(a*(b-1))/b;
    }
    else if(n<b-1){
        cout<<(a*n)/b;
    }
    return 0;

}






Measured memory_bytes: 3592
#include<cstdio>
#include<cstdlib>
#include<cmath>
#include<string>
#include<cstring>

using namespace std;

int main()
{
	int n,a,b,c,sum;
	while(~scanf("%d",&n))
	{
		a=n/100;
		b=(n/10)%10;
		c=n%10;
		sum=a+b+c;
		printf("%d\n",sum);
	}
	return 0;
}

Measured memory_bytes: 128
#include<bits/stdc++.h>
#include<boost/dynamic_bitset.hpp>
using namespace std;
using u64 = uint64_t;
using s64 = int64_t;

int main(void) {
    u64 K;
    cin >> K;
    
    if(K % 2 == 0) {
        cout << -1 << endl;
        return 0;
    }

    u64 t = 7;
    u64 l = 1;
    vector<bool> his(K);

    while(!his[t % K]) {
        if(t % K == 0) {
            cout << l << endl;
            return 0;
        }

        his[t % K] = true;
        l++;
        t = (t % K) * 10 + 7;
    }
        
    cout << -1 << endl;
    return 0;
}

Measured memory_bytes: 3740
class Problem
  attr_accessor *(?a..?z).to_a.map(&:to_sym)
  def initialize
    @r = gets.to_s.to_i
  end

  def solve
    return "AGC" if 2800 <= r
    return "ARC" if 1200 <= r
    "ABC"
  end

  def show(ans)
    puts ans
  end
end

Problem.new.instance_eval do
  show(solve)
end


Measured memory_bytes: 14244
#include <iostream>
#include <stack>
#include <queue>
#include <vector>
#include <algorithm>
#include <string>
#include <iomanip>
#include <functional>
#include <map>
#include <math.h>
#include <list>

using namespace std;

int main(void) {

	int ans = 0;
	int x;
	for (int i = 1; i <= 5; i++) {

		cin >> x;
		if (x == 0) ans = i;
	}
	cout << ans << endl;






	return 0;
}


Measured memory_bytes: 3564
#include <stdio.h>
#include <math.h>
#include <string.h>
#include <stdlib.h>
#define rad M_PI/3
#define N 500001
#define Max 10000
#define NTL -1
typedef struct{
  int key, left, right;
}Node;
 
Node tree[N+1];
int size;
 
void insert(int x){
  int p = 0;
  while(1){
    if(x < tree[p].key){
      if(tree[p].left == -1){
        tree[p].left = size;
        tree[size++].key = x;
        break;
      }else p = tree[p].left;
    }else{
      if(tree[p].right == -1){
        tree[p].right = size;
        tree[size++].key = x;
        break;
      }else p = tree[p].right;
    }
  }
}
 
void inorder(int p){
  if(tree[p].left != -1) inorder(tree[p].left);
  printf(" %d", tree[p].key);
  if(tree[p].right != -1) inorder(tree[p].right);
}
 
void preorder(int p){
  printf(" %d", tree[p].key);
  if(tree[p].left != -1) preorder(tree[p].left);
  if(tree[p].right != -1) preorder(tree[p].right);
}
int find(int p, int x){
  if(tree[p].key == x) return 1;
  if(x < tree[p].key && tree[p].left != -1) if(find(tree[p].left, x)) return 1;
  if(tree[p].key < x && tree[p].right != -1) if(find(tree[p].right, x)) return 1;
  return 0;
}
int main()
{
   int n, i, first;
  first = 1;
  scanf("%d", &n);
  for(i=0;i<=n;i++) tree[i].key = tree[i].left = tree[i].right = -1;
  size = 0;
  while(n--){
    char str[100];
    scanf("%s", str);
    if(!strcmp(str, "insert")){
      int in;
      scanf("%d", &in);
      if(first){
        tree[size++].key = in;
        first = 0;
      }
      else insert(in);
      }else if(!strcmp(str, "find")){
      int in;
      scanf("%d", &in);
      printf("%s\n", (find(0, in) ? "yes" : "no"));
    }else{
      inorder(0);
      printf("\n");
      preorder(0);
      printf("\n");
    }
  }
  return 0;
}


Measured memory_bytes: 7536
import sys
n = int(input())
k = int(input())

keta = len(str(n))
# dp[i桁まで検査済み][coincidence][0以外の個数]
dp = [[[0] * (k + 1) for i in range(2)] for j in range(keta + 1)]

dp[0][1][0] = 1
for a in range(1, keta + 1):
    digit = int(str(n)[a - 1])
    for b in range(2):
        for c in range(k + 1):
            if b == 0 and c == k:
                # 最大値と不一致で0以外の個数がk個になる
                dp[a][b][c] += dp[a-1][0][k] * 1
                dp[a][b][c] += dp[a-1][0][k-1] * 9
                # d != 0(仮に3) -> 0
                # d == 0 -> 0にすると最大値と一致するのでだめ
                dp[a][b][c] += dp[a-1][1][k] * (1 if digit != 0 else 0)
                # d != 0(仮に3) -> 1, 2(0はkにならないのでだめ、3はb == 1になるのでだめ)
                # d == 0 -> 0にするとkが増えないのでだめ
                dp[a][b][c] += dp[a-1][1][k-1] * (digit - 1 if digit != 0 else 0)
            elif b == 0 and c != k:
                # 最大値と不一致で0以外の個数がc個になる
                dp[a][b][c] += dp[a-1][0][c] * 1
                dp[a][b][c] += 0 if c == 0 else dp[a-1][0][c-1] * 9
                dp[a][b][c] += dp[a-1][1][c] * (1 if digit != 0 else 0)
                dp[a][b][c] += 0 if c == 0 else dp[a-1][1][c-1] * (digit - 1 if digit != 0 else 0)
            elif b == 1 and c == k:
                # 最大値と一致で0以外の個数がk個になる
                dp[a][b][c] += dp[a-1][1][k] * (1 if digit == 0 else 0)
                dp[a][b][c] += dp[a-1][1][k-1] * (1 if digit != 0 else 0)
            elif b == 1 and c != k:
                dp[a][b][c] += dp[a-1][1][c] * (1 if digit == 0 else 0)
                dp[a][b][c] += 0 if c == 0 else dp[a-1][1][c-1] * (1 if digit != 0 else 0)
            else:
                None
#     print("--", a)
#     for i in range(k + 1):
#         print(dp[a][0][i])
#     for i in range(k + 1):
#         print(dp[a][1][i])

print(dp[keta][0][k] + dp[keta][1][k])




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

int main() {
  int n,ans = 0;
  cin >> n;
  vector<bool>s(1000000000+1,false);
  for(int i = 0;i < n;i++){
    long a;
    cin >> a;
    s[a] = true;
  }
  int q;
  cin >> q;
  for(int i = 0;i < q;i++){
    long a;
    cin >> a;
    if(s[a]) ans++;
  }
  cout << ans << endl;
}



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

int main()
{
    int n;
    cin >> n;
    vector<int> t(n);
    int m;
    vector<int> p(m);
    vector<int> x(m);
    long long count = 0;
    for (int i = 0; i < n; i++)
    {
        cin >> t.at(i);
        count += t.at(i);
    }
    cin >> m;
    for (int i = 0; i < m; i++)
    {
        cin >> p.at(i) >> x.at(i);
        count -= t.at(p.at(i) - 1);
        count += x.at(i);
        cout << count << endl;
        count -= x.at(i);
        count += t.at(p.at(i) - 1);
      //cout<<'k'<<count<<endl;
    }
}


Measured memory_bytes: 512
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Scanner;

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

    static class TaskA {
        public void solve(int testNumber, Scanner in, PrintWriter out) {
            int X = in.nextInt();
            int A = in.nextInt();
            int B = in.nextInt();

            if (B - A <= 0)
                out.println("delicious");
            else if (B - A <= X)
                out.println("safe");
            else
                out.println("dangerous");
        }

    }
}



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

int main(){
        const int dx[2] = {-1, 1};
        const int dy[2] = {-1, 1};

        int h, w;
        cin >> h >> w;
        string s[h];
        for(int i = 0; i < h; i++) cin >> s[i];

        bool ng = false;
        for(int i = 0; i < h; i++){
                for(int j = 0; j < w; j++){
                        if(s[i][j] == '#'){
                                bool l_ng = true;
                                for(int d = 0; d < 2; d++){
                                        int nx = j + dx[d];
                                        if(nx >= 0 && nx < w)
                                                if(s[i][nx] == '#') l_ng = false;
                                        int ny = i + dy[d];
                                                if(ny >= 0 && ny < h)
                                                        if(s[ny][j] == '#') l_ng = false;
                                }
                                if(ng == false && l_ng == true){
                                        ng = true;
                                }
                        }
                }
        }
        if(ng) cout << "No" << endl;
        else cout << "Yes" << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
typedef long long ll;
int main() {
   ll a;
   double b;
   cin>>a>>b;
   ll b100=(ll)(b*100+0.001);
   cout<<a*b100/100<<endl;
}

Measured memory_bytes: 3720
#include <bits/stdc++.h>
using namespace std;
int main(){
	int n;
	cin >> n;
	int t[110];
	int count=0;
	for(int i=0;i<n;i++){
		cin >> t[i];
		count+=t[i];
	}
	int m;
	cin >> m;
	int p,x;
	for(int i=0;i<m;i++){
		cin>>p>>x;
        cout<<count-t[p-1]+x<<endl;
		}
	return 0;
}


Measured memory_bytes: 256
#include <cstdio>
#include <stdlib.h>
#include <iostream>
#include <algorithm>
#include <cstring>
#include <vector>
#include <queue>
#define min(a,b)    (((a) < (b)) ? (a) : (b))
#define max(a,b)    (((a) > (b)) ? (a) : (b))
#define abs(x)    ((x) < 0 ? -(x) : (x))
#define INF 0x3f3f3f3f
#define delta 0.85
#define eps 1e-3
#define PI 3.14159265358979323846
#define MAX_V 10005
using namespace std;
struct edge{
	int to, dist, cost;
	edge(int to, int dist, int cost) : to(to), dist(dist), cost(cost) {}
	bool operator > (const edge &other) const {
		return dist == other.dist ? cost > other.cost : dist > other.dist;
	}
};
int E, V;
int d[MAX_V], c[MAX_V];
bool vis[MAX_V];
vector<edge> G[MAX_V];

int dijkstra(int s){
	priority_queue<edge, vector<edge>, greater<edge> > que;
	memset(d, 0x3f, sizeof(int) * V);
	memset(vis, 0, sizeof(bool) * V);
	d[s] = 0;
	que.push(edge(s, 0, 0));
	int res = 0;
	while(!que.empty()){
		edge now = que.top(); que.pop();
		int u = now.to;
		if(vis[u]) continue;
		vis[u] = 1;
		res += now.cost;
		for(int i = 0; i < G[u].size(); i++){
			edge &e = G[u][i];
			int dist = d[u] + e.dist;
			if(d[e.to] > dist){
				d[e.to] = dist, c[e.to] = e.cost;
				que.push(edge(e.to, d[e.to], c[e.to]));
			}
			else if(d[e.to] == dist && c[e.to] > e.cost){
				c[e.to] = e.cost;
				que.push(edge(e.to, d[e.to], c[e.to]));
			}
		}
	}
	return res;
}

int main(){
	while(~scanf("%d%d", &V, &E) && V){
		for(int i = 0; i < V; i++) G[i].clear();
		for(int i = 0; i < E; i++){
			int u, v, d, c;
			scanf("%d%d%d%d", &u, &v, &d, &c);
			--u, --v;
			G[u].push_back(edge(v, d, c));
			G[v].push_back(edge(u, d, c));
		}
		printf("%d\n", dijkstra(0));
	}
	return 0;
}




Measured memory_bytes: 5208
N = int(input())
if N % 7:
    L = 9*N
else:
    L = 9*N//7
num = 1
if L % 2 and L % 5:
    i = 1
    while i <= L:
        num = (num*10) % L
        if num == 1:
            print(i)
            break

        else:

            i += 1

else:
    print(-1)


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

int a[105][2];

int main() {
  int n;
  cin >> n;
  for (int i = 1; i <= n; ++i)
    cin >> a[i][0] >> a[i][1];
  for (int i = 1; i <= n - 2; ++i)
    if (a[i][0] == a[i][1] && a[i + 1][0] == a[i + 1][1] && a[i + 2][0] == a[i + 2][1]) {
      cout << "Yes" << endl;
      return 0;
    }
  cout << "No" << endl;
  return 0;
}

Measured memory_bytes: 3156
#include<iostream>
#include<algorithm>
#include<vector>
#include<tuple>
using namespace std;
int main() {
  int n,v,w;
  cin >> n;
  char c;
  long long d;
  string s;
  vector<tuple<int,int,char,long long,string>> t(n);
  for(int i=0; i<n; i++) {
      cin >> v >> w >> c >> d >> s;
      t[i]=make_tuple(v,w,c,d,s);
  }
  sort(t.begin(),t.end());
  for(int i=0; i<n; i++) {
    v=get<0>(t[i]);
    w=get<1>(t[i]);
    c=get<2>(t[i]);
    d=get<3>(t[i]);
    s=get<4>(t[i]);
    cout << v << " " << w << " " << c << " " << d << " " << s << endl;
  }
}


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

using namespace std;
typedef  long long ll;

#define sint(a) scanf("%d",&a)
#define sint2(a,b) scanf("%d %d",&a,&b)
#define sdo(a) scanf("%lf",&a)
#define sdo2(a,b) scanf("%lf %lf",&a,&b)
#define sll(a) scanf("%lld",&a)
#define sll2(a,b) scanf("%lld %lld",&a,&b)
#define mem(a,i) memset(a,i,sizeof(a))
const int maxn=1e6+10;
const int mod=1e9+7;

int main()
{
    int a,b;
    cin>>a>>b;
    if(a<b)
        for(int i=0;i<b;i++)
        printf("%d",a);
    else
        for(int i=0;i<a;i++)
        printf("%d",b);
    return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
int main()
{
	int n,m,a[100][100]={0},b[100],c[100]={0};
	scanf("%d %d",&n,&m);
	for(int i=0;i<n;i++){
		for(int j=0;j<m;j++)
			scanf("%d",&a[i][j]);
	}
	for(int i=0;i<m;i++)
		scanf("%d",&b[i]);
	for(int i=0;i<n;i++){
		for(int j=0;j<m;j++){
			c[i]=c[i]+a[i][j]*b[j];
		}
		printf("%d\n",c[i]);
	}
	return 0;
}

Measured memory_bytes: 1076
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> iint;
typedef pair<ll,ll> llll;
#define ALL(x) (x).begin(),(x).end()
const ll zero = 0;
const ll INF = 3000000000000000000; //10^18
const int inINF = 1000000000; //10^9
const ll MOD = 1000000007; //10^9+7
const ll MOD2 = 998244353;

int main(){
    int N;
    cin >> N;
    N = N % 1000;
    printf("%d\n", (1000-N)%1000);
}   

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

using namespace std;
using llong = long long;
using P = pair<llong, llong>;

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

const llong inf = llong(1e18)+7;
const llong mod = 1e9+7;

struct data{
	int place;
	int cost;

	data(){};
	data(int place, int cost) :
		place(place),
		cost(cost)
	{}

	bool operator<(const data &ri) const{
		return cost < ri.cost;
	}
	bool operator>(const data &ri) const{
		return cost > ri.cost;
	}
};

int N, M;
vector<vector<P> > edges;

llong Dijkstra(int start, int goal){
	priority_queue<data> q;
	vector<llong> dis(edges.size(),inf);
	dis[start] = 0;

	q.push(data(start, 0));
	while(q.size()){
		data now = q.top(); q.pop();
		if(now.place == goal) return now.cost;
		if(now.cost >= 2) continue;
		if(dis[now.place] < now.cost) continue;

		for(int i = 0; i < edges[now.place].size(); i++){
			P edge = edges[now.place][i];
			data next(edge.first, now.cost + edge.second);
			if(dis[next.place] <= next.cost) continue;
			dis[next.place] = next.cost;
			q.push(next);
		}
	}

	return -1;
}


int main(){
	cin >> N >> M;
	edges.resize(N+1, vector<P>());

	int a, b;
	for(int i = 0; i < M; i++){
		cin >> a >> b;
		edges[a].push_back(P(b,1));
		edges[b].push_back(P(a,1));
	}

	if(Dijkstra(1,N) == 2)
		cout << "POSSIBLE" << endl;
	else
		cout << "IMPOSSIBLE" << endl;

	return 0;
}

Measured memory_bytes: 17632
n,m=map(int,input().split())
a=list(list(map(int,input().split())) for _ in range(m))
for i in range(1,n+1):
        x=0
        for j in range(m):
                if i in a[j]:
                        x+=a[j].count(i)
        print(x)
                


Measured memory_bytes: 3060
// abc134b: Golden Apple
#include <stdio.h>

int main(){
  int n,d,c=0;
  scanf("%d%d",&n,&d);
  int p=1;
  while(p<=n){
    c++;
    p+=d*2;
    ++p;
  }
  printf("%d\n",c);
  return 0;
}

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

set<long long int> S;

int s;

int main(void) {

	cin >> s;
	S.insert(s);
	for (int i=2;;i++) {
		if (s % 2 == 0) { s = s / 2; }
		else { s = 3 * s + 1; }
		if (S.count(s)>= 1) { cout << i << endl; break; }
		S.insert(s);
		//cout << s << endl;
	}


//	system("pause");
	return 0;
}

Measured memory_bytes: 256
// 2020-07-25 06:48:42
#include<bits/stdc++.h>
#ifdef LOCAL
#include "lib/debug.hpp"
#else
#define debug(...) 1
#endif
#define ALL(a) (a).begin(), (a).end()
#define rep(i, n) REP(i, 0, (n))
#define repc(i, n) REPC(i, 0, (n))
#define REP(i, n, m) for (int i = (int)(n); i < (int)(m); i++)
#define REPC(i, n, m) for (int i = (int)(n); i <= (int)(m); i++)
#define REPCM(i, n, m) for (int i = (int)(n); i >= (int)(m); i--)
using namespace std;
using ll = long long;
using ld = long double;
using pr = pair<ll, ll>;
using vll = vector<ll>;
using vpr = vector<pr>;
using P = pair<int, int>;
template<class T> inline bool chmin(T& a, const T& b) { if (a > b) { a = b; return true; } else return false; }
template<class T> inline bool chmax(T& a, const T& b) { if (a < b) { a = b; return true; } else return false; }
struct mint {
  ll divisor = 998244353;
  ll val;
  constexpr mint(ll v = 0) noexcept : val(v % divisor) {
    if (val < 0) val += divisor;
  }
  constexpr mint operator + (const mint& rhs) const noexcept {
    return mint(*this) += rhs;
  }
  constexpr mint operator - (const mint& rhs) const noexcept {
    return mint(*this) -= rhs;
  }
  constexpr mint operator * (const mint& rhs) const noexcept {
    return mint(*this) *= rhs;
  }
  constexpr mint operator / (const mint& rhs) const noexcept {
    return mint(*this) /= rhs;
  }
  constexpr mint operator ~ () const noexcept {
    ll a = this->val, b = divisor, u = 1, v = 0;
    while (b > 0) {
      ll t = a / b;
      a -= t * b;
      u -= t * v;
      ll c = a; a = b; b = c;
      ll w = u; u = v; v = w;
    }
    if (u < 0) u += divisor;
    u %= divisor;
    return u;
  }
  constexpr mint& operator += (const mint& rhs) noexcept {
    val += rhs.val;
    if (val >= divisor) val -= divisor;
    return *this;
  }
  constexpr mint& operator -= (const mint& rhs) noexcept {
    if (val < rhs.val) val += divisor;
    val -= rhs.val;
    return *this;
  }
  constexpr mint& operator *= (const mint& rhs) noexcept {
    val = val * rhs.val % divisor;
    return *this;
  }
  constexpr mint& operator /= (const mint& rhs) noexcept {
    val = val * (~(mint(rhs))).val % divisor;
    return *this;
  }
  friend mint modpow (mint a, ll n) noexcept {
    auto res = mint(1);
    while(n > 0) {
      if(n&1) res *= a;
      a *= a;
      n >>= 1;
    }
    return res;
  }
  friend std::ostream& operator << (std::ostream& os, const mint& a) noexcept {
    return os << a.val;
  }
  friend std::string debug_s (mint a) noexcept {
    return std::to_string(a.val);
  }
};
const int MX = 3030;
int a[MX];
mint dp[MX], p[MX];
void answer() {
  int n, s;
  cin >> n >> s;
  rep(i, n) cin >> a[i];
  mint ans = 0;
  rep(i, n) {
    dp[0] += 1;
    swap(p, dp);
    repc(j, s) {
      dp[j] = p[j];
      if(a[i] <= j) dp[j] += p[j-a[i]];
    }
    ans += dp[s];
  }
  cout << ans << '\n';
}
int main() {
  std::ios::sync_with_stdio(false);
  std::cin.tie(0);
  answer();
  return 0;
}

Measured memory_bytes: 3680
#import pysnooper
#import numpy
#import os,re,sys,operator
#from collections import Counter,deque
#from operator import itemgetter,mul
#from itertools import accumulate#,combinations,groupby,combinations_with_replacement,permutations
from sys import stdin,setrecursionlimit
#from bisect import bisect_left,bisect_right
#from copy import deepcopy
#import heapq
#import math
#import string
#from time import time
#from functools import lru_cache,reduce
#from math import factorial
#import sys
from fractions import gcd
setrecursionlimit(10**6)
input=stdin.readline

n=int(input())
if n%2==1:
    print(0)
else:
    div2,div5=0,0
    a=n//2
    while a>1:
        div2+=a//2
        a//=2
    a=n//2
    while a>1:
        div5+=a//5
        a//=5
    print(min(div2,div5))

Measured memory_bytes: 5048