akhauriyash/Code-Regression huggingface dataset:
#include <iostream>

using namespace std;

int main() {
    long long int N;
    long long int count=1;
    long long int ans=0;
    cin >> N;
    for(int n=0; n<N; n++) {
        long long int a;
        cin >> a;
        
        if(count==a) {
            count++;
        } else {
            ans++;
        }
    }
    
    if(ans==N) {
        cout << -1 << endl;
    } else {
        cout << ans << endl;
    }

    return 0;
    
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <vector>
#include <utility>
#include <set>
#define rep(i,n) for(int i=0;i<n;++i)
#define rep1(i,n) for(int i=1;i<=n;++i)
using namespace std;
template<class T>bool chmax(T &a, const T &b) { if(a < b){ a = b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if(a > b){ a = b; return 1; } return 0; }
int main()
{
  int n,k,q; cin >> n >> k >> q;
  vector<int> a(n);
  rep(i,n) cin >> a[i];

  using pi = pair<int,int>;
  vector<pi> b(n);
  rep(i,n) b[i] = {a[i], i};
  sort(b.begin(), b.end());

  set<int> st;
  vector<int> idx;
  st.insert(n);
  int res = 1e+9;
  rep(i,n) {
    int left = 0;
    multiset<int> vec;
    for(auto val: st) {
      multiset<int> part;
      for (int j = left; j < val; ++j) {
	part.insert(a[j]);
      }
      left = val + 1;
      if((int)part.size() - k < 0) continue;
      auto it = part.begin();
      rep(j,part.size() - k + 1) {
	vec.insert(*it);
	if(vec.size() == q + 1) {
	  auto itend = vec.end();
	  itend--;
	  vec.erase(itend);
	}
	++it;
      }
    }
    if(vec.size() < q) break;
    auto itend = vec.end();
    itend--;
    chmin(res, *itend - b[i].first);
    idx.push_back(b[i].second);
    if(i == n-1) continue;
    if(b[i].first != b[i+1].first) {
      for(auto val: idx) {
	st.insert(val);
      }
      idx.clear();
    }
  }

  cout << res << "\n";
  
  return 0;
}


Measured memory_bytes: 512
#include <iostream>
#include <string>
#include <vector>
#include <math.h>
#include <algorithm>
#include <cmath>
#include <ios>
#include <ctype.h>
#include <stack>
#include <istream>
#include <stdio.h>
#include <map>
#include <set>
#include <queue>
#include <unordered_map>
#include <functional>
#include <bitset>
#include <list>
#include <deque>
#include <time.h>
#include <random>
#include <iomanip>
#include <fstream>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define REP(i,a,b) for (int i = a; i < (b); ++i)
#define RREP(i,a,b) for (int i = a; i > (b); --i)
#define all(x) (x).begin(),(x).end()
#define YY cout << "Yes" << endl
#define NN cout << "No" << endl
const long long INF = 1000000007;
typedef long long ll;
using namespace std;
using Graph = vector<vector<int>>;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
ll gcd(ll a, ll b) { return b ? gcd(b, a%b) : a; }
ll lcm(ll a, ll b) { return (a * b) / gcd(a,b); }
int b[3][3];
int solve(){
  int n;
  cin>>n;
  cout<<(n+2-1)/2<<endl;
  return 0; 
}
int main(){
  // ios::sync_with_stdio(false);cin.tie(nullptr);
  // cout << fixed;cout << setprecision(16);
  solve();
  return 0;
}

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

typedef long long ll;

int q;
multiset <int> A, B;
ll sum, by;

void Fix()
{
    while (B.size() > A.size()) {
        int val = *B.begin(); B.erase(B.begin());
        sum -= 2 * val;
        A.insert(val);
    }
    while (A.size() > B.size() + 1) {
        multiset <int>::iterator it = A.end(); it--;
        int val = *it; A.erase(it);
        sum += 2 * val;
        B.insert(val);
    }
}

int main()
{
    scanf("%d", &q);
    while (q--) {
        int typ; scanf("%d", &typ);
        if (typ == 1) {
            int a, b; scanf("%d %d", &a, &b);
            by += b;
            if (!A.empty() && a > *A.rbegin()) {
                sum += a; B.insert(a);
            } else {
                sum -= a; A.insert(a);
            }
            Fix();
        } else {
            int x = *A.rbegin();
            printf("%d %lld\n", x, sum + ll(x) * (ll(A.size()) - ll(B.size())) + by);
        }
    }
    return 0;
}


Measured memory_bytes: 9600
#include <bits/stdc++.h>
#define MAX 100005
#define ll long long
#define upperlimit 1000100
#define INF 1e18
#define eps 1e-8
#define endl '\n'
#define pcc pair<char,char>
#define pii pair<int,int>
#define pll pair<ll,ll>
#define tr(container,it) for(typeof(container.begin()) it=container.begin();it!=container.end();it++)
#define MOD 1000000007
#define slld(t) scanf("%lld",&t)
#define sd(t) scanf("%d",&t)
#define pd(t) printf("%d\n",t)
#define plld(t) printf("%lld\n",t)
#define mp(a,b) make_pair(a,b)
#define FF first
#define SS second
#define pb(x) push_back(x)
#define vi vector<int>
#define clr(a) memset(a,0,sizeof(a))
#define debug(a) printf("check%d\n",a)
#define csl ios::sync_with_stdio(false);cin.tie(0);
#define fi(a,b,c) for(int i=a;i<b;i=i+c)
#define fj(a,b,c) for(int j=a;j<b;j+=c)
using namespace std;
 
ll gcd(ll n1,ll n2) {
	if(n1%n2==0)return n2;
	return gcd(n2,n1%n2);
}
ll powmod(ll base,ll exponent) {
	ll ans=1;
	while(exponent){
		if(exponent&1)ans=(ans*base)%MOD;
		base=(base*base)%MOD;
		exponent/=2;
	}
	return ans;
}
ll max(ll a,ll b,ll c) {
	return max(a,max(b,c));
}
int max(int a,int b,int c) {
	return max(a,max(b,c));
}
vi dp(100005, -1), e[100005];
int trav(int i){
	if(dp[i]!=-1){
		//cout<<i<<" ";
		return dp[i];
	}else{
		int mx=-1;
		for(int x=0;x<e[i].size();x++){
			mx=max(mx, trav(e[i][x]));
		}
		dp[i]=mx+1;
		return dp[i];
	}
}
int main()
{
	int n,m;
	sd(n);sd(m);
	vector<vector<int>> a, dp;
	for(int i=0;i<n;i++){
		string s;
		cin>>s;
		vi x;
		for(int j=0;j<m;j++){
			if(s[j]=='.'){
				x.pb(1);
			}else{
				x.pb(0);
			}
		}
		a.pb(x);
	}
	for(int i=0;i<n;i++){
		vi x;
		for(int j=0;j<m;j++){
			if(i==0){
				if(a[i][j]==0){
					x.pb(0);
				}else if(j==0){
					x.pb(1);
				}else{
					x.pb((x[j-1])%(1000000007));
				}
			}else{
				if(a[i][j]==0){
					x.pb(0);
				}else if(j==0){
					x.pb(dp[i-1][j]);
				}else{
					x.pb((dp[i-1][j]+x[j-1])%(1000000007));
				}
			}
		}
		dp.pb(x);
	}
	cout<<dp[n-1][m-1];
}

Measured memory_bytes: 10880
#include <cstdio>
using namespace std;

int n, k;
int a[100];
int dp[100][3][3];

int main(){
	scanf("%d %d", &n, &k);
	for(int i=0; i<k; i++){
		int t1, t2;
		scanf("%d %d", &t1, &t2);
		a[t1-1] = t2;
	}

	if(a[0] == 0){
		for(int i=0; i<3; i++){
			dp[0][i][0] = 1;
		}
	}else{
		dp[0][a[0]-1][0] = 1;
	}

	if(a[1] == 0){
		for(int i=0; i<3; i++){
			for(int j=0; j<3; j++){
				dp[1][i][j] = dp[0][j][0];
			}
		}
	}else{
		for(int i=0; i<3; i++){
			dp[1][a[1]-1][i] = dp[0][i][0];
		}
	}

	for(int i=2; i<n; i++){
		if(a[i] == 0){
			for(int p=0; p<3; p++){
				for(int q=0; q<3; q++){
					for(int r=0; r<3; r++){
						if(p == q && q == r) continue;
						else{
							dp[i][p][q] += dp[i-1][q][r];
							dp[i][p][q] %= 10000;
						}
					}
				}
			}
		}else{
			for(int p=0; p<3; p++){
				for(int q=0; q<3; q++){
					if(a[i] - 1 == p && p == q) continue;
					else{
						dp[i][a[i] - 1][p] += dp[i-1][p][q];
						dp[i][a[i] - 1][p] %= 10000;
					}
				}
			}
		}
	}
/*
	for(int i=0; i<n; i++)
		printf("%d\t", a[i]);
*/

/*	for(int i=0; i<n; i++){
		for(int j=0; j<3; j++){
			printf("%d\t", dp[i][j][0] + dp[i][j][1] + dp[i][j][2]);
		}
		printf("\n");
	}
*/
	int ans=0;
	for(int i=0; i<3; i++){
		for(int j=0; j<3; j++){
			ans += dp[n-1][i][j];
			ans %= 10000;
		}
	}
	printf("%d\n", ans);
	return 0;
}

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

int main(){
    int N,M;
    cin >> N >> M;
    cout << N*M<<endl;
}

Measured memory_bytes: 3624
#include <bits/stdc++.h>
#define int long long
#define pb push_back
#define fast_io() ios_base :: sync_with_stdio(0); cin.tie(0); cout.tie(0)
using namespace std;
int func(int n)
{
	return (n * (n + 1)) / 2;
}
int32_t main() {
	fast_io();
	int n;
	cin >> n;
	int res = 0;
	for (int i = 1; i <= n; i++)
	{
		int y = n / i;
		res += (i * func(y));
	}
	cout << res << "\n";
	return 0;
}

Measured memory_bytes: 3532
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) FOR(i,0,n)

typedef vector<int> vi;
typedef vector<vi> vii;
typedef vector<string> vs;
typedef pair<int, int> pi;
typedef long long ll;
typedef unsigned long long ull;
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define MKP make_pair
#define SZ(a) int((a).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())

int N,ans = 0;


int main()
{
	cin.tie(0);
	ios::sync_with_stdio(false);
	cin >> N;
	vi A;
	REP(i, N) {
		int x;
		cin >> x;
		A.push_back(x);
	}
	REP(i, N) {
		while (1) {
			{
				if (A[i] % 2 == 0) {
					ans++;
					A[i] /= 2;
				}
				else {
					break;
				}
			}
		}
	}
	cout << ans << endl;
	return 0;
		
	
}


Measured memory_bytes: 384
#include <bits/stdc++.h>
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REP(i,n) FOR(i,0,n)

using namespace std;

int main()
{
        int m,ni,na;
        while(cin>>m>>ni>>na,m)
        {
                vector<int> p(m);
                REP(i,m)
                {
                        cin>>p[i];
                }
                sort(p.begin(), p.end());
                int md=0,mp=ni;
                FOR(i, m-na, m-ni+1)
                {
                        if(p[i]-p[i-1]>md)
                        {
                                //cout<<md<<i<<endl;
                                md=p[i]-p[i-1];
                                mp=m-i;
                        }
                }
                cout<<mp<<endl;
        }
}

Measured memory_bytes: 3052
N,M = map(int,input().split())
L = list(map(int,input().split()))
L = sorted(L)
S = []
if N >= M:
	print(0)
	exit()
for i in range(M-1):
	S.append(abs(L[i+1]-L[i]))
S=sorted(S)
print(sum(S[0:M-N]))


Measured memory_bytes: 13960
#pragma GCC optimize("O3")
#include <bits/stdc++.h>
#define ll long long
#define rep2(i,a,b) for(ll i=a;i<=b;++i)
#define rep(i,n) for(ll i=0;i<n;i++)
#define rep3(i,a,b) for(ll i=a;i>=b;i--)
#define pii pair<int,int>
#define pll pair<ll,ll>
#define pq priority_queue
#define pb push_back
#define eb emplace_back
#define veci vector<int>
#define vecll vector<ll>
#define vecpii vector<pii>
#define vec2(a,b) vector<vec>(a,vec(b))
#define vec2ll(a,b) vector<vec>(a,vecll(b))
#define vec3(a,b,c) vector<vector<vec>>(a,vec2(b,c))
#define vec3ll(a,b,c) vector<vector<vecll>>(a,vec2ll(b,c))
#define fi first
#define se second
#define all(c) begin(c),end(c)
#define ios ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0);
#define lb(c,x) distance(c.begin(),lower_bound(all(c),x))
#define ub(c,x) distance(c.begin(),upper_bound(all(c),x))


using namespace std;
int in() {int x;cin>>x;return x;}
ll lin() {ll x;cin>>x;return x;}
template<class T> inline bool chmax(T& a,T b){if(a<b){a=b;return 1;}return 0;}
template<class T> inline bool chmin(T& a,T b){if(a>b){a=b;return 1;}return 0;}
template<class T> inline void print(pair<T,T> p){cout<<"("<<p.first<<","<<p.second<<") ";}
//template<class T> inline void print(vector<pair<T,T>> v){for(auto e:v)print(e); cout<<endl;}
//template<class T> inline void print(T v){for(auto e:v)cout<<e<<" ";cout<<endl;}
template<typename T>
istream& operator >> (istream& is, vector<T>& vec){
    for(T& x:vec) is >> x;
    return is;
}
const ll INF=1e18+1;

int main()
{
    ll a,b,c,x,y;
    cin >> a >> b >> c >> x >> y;
    if(2*c>=a+b){
        cout << a*x+b*y << endl;
    }
    else{
        ll ans=-1;
        if(x<=y){
            ans=min(b*(y-x)+2*c*x,2*c*y);
        }
        else{
            ans=min(a*(x-y)+2*c*y,2*c*x);
        }
        cout << ans << endl;
    }
    
    return 0;
} 

Measured memory_bytes: 256
# coding: utf-8
# Your code here!
n=int(input())
A= [[int(i) for i in input().split()] for j in range(n)]

def bitcount(i): # i < 2^32
    i = i - ((i >> 1) & 0x55555555)
    i = (i & 0x33333333) + ((i >> 2) & 0x33333333)
    return (((i + (i >> 4) & 0xF0F0F0F) * 0x1010101) & 0xffffffff) >> 24
    

MOD=10**9+7
size=1<<n
dp = [0]*size
dp[0] = 1

for i in range(size-1):
#    num = bin(i).count("1")
    num = bitcount(i)
    for c in range(n):
        if A[num][c] and (1<<c)^i != i:
            dp[(1<<c)^i] += dp[i]
            if dp[(1<<c)^i] > MOD: dp[(1<<c)^i] -= MOD

print(dp[-1])


Measured memory_bytes: 58988
#include <stdio.h>

void qsort(int len, int a[len], int f, int l);

int main()
{
  int n,x;
  scanf("%d%d",&n,&x);
  int a[n];
  int i;
  i = 0;
  while (i < n)
  {
    scanf("%d",&a[i]);
    i++;
  }
  qsort(n,a,0,n-1);
  i = 0;
  while (x > 0 && i < n)
  {
    x -= a[i];
    i++;
  }
  if (x == 0)
    printf("%d",i);
  else
  	printf("%d",i - 1);
}

void qsort(int len, int a[len], int f, int l)
{
  int i,j;
  i = f;
  j = l;
  int threshold;
  int t;
  threshold = a[(f + l) / 2];
  while (1)
  {
    while (a[i] < threshold)
      i++;
    while (a[j] > threshold)
      j--;
    if (i >= j)
      break;
    t = a[i];
    a[i] = a[j];
    a[j] = t;
    i++;
    j--;
  }
  if (f < i - 1)
    qsort(len, a, f, i - 1);
  if (l > j+1)
    qsort(len, a, j+1, l);
}

Measured memory_bytes: 128
#include<bits/stdc++.h>
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i, n) for (int i = 0; i < (n); ++i)
#define int long long
#define vec(a,n) vector<int> (a)((n));
#define Vec(a,n) vector<string> (a)((n));
#define twovec(a,n,m) vector<vector<int>> a(n,vector<int>(m,0));
#define Twovec(a,n,m) vector<vector<double>> a(n,vector<double>(m,0));
#define P pair<int,int>
#define All(a) (a).begin(),(a).end()
#define Sort(a) sort(All(a));
#define Reverse(a) reverse(All(a));
#define PQ(n) priority_queue<P,vector<P>,greater<P>> (n)
#define pq(n) priority_queue<int> (n)
#define print(a) cout << (a) << endl
#define printD(a) cout << setprecision(15) << (a) << endl;
using namespace std;
int max_int = 2147483647;
int prime = 998244353;
void Debug(auto a);
double PI = 3.14159265358979;
void input(vector<auto>& a,int n);
int n;


int gcd(int u, int v) {
  int r;
  while (0 != v) {
    r = u % v; u = v; v = r;
  }
  return u;
}
int lcm(int u,int v){
    int r = gcd(u,v);
    r = (u / r)*v;
    return r;
}

signed main(){
    std::cin.tie(nullptr);
    std::ios::sync_with_stdio(false);
    cin >> n;
    int ans = 1;
    REP(i,n){
        int x;
        cin >> x;
        ans = lcm(ans,x);
    }
    print(ans);
    return 0;
}

void Debug(auto a){
    cout << "{ ";
    for(auto b: a){
        cout << b << " ";
    }
    cout << "}" << endl;
}

void input(vector<auto>& a,int n){
    REP(i,n){
        cin >> a[i];
    }
}


Measured memory_bytes: 3608
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<cmath>
using ull = unsigned long long;
using ll = long long;
using namespace std;

int main(void) {
    int H, W;
    cin >> H >> W;
    vector<string> S(H);
    for (int i = 0; i < H; ++i) {
        cin >> S[i];
    }

    vector<vector<int>> HS(H, vector<int>(W, 0));
    vector<vector<int>> VS(H, vector<int>(W, 0));

    for (int iy = 0; iy < H; ++iy) {
        int con = 0;
        for (int ix = 0; ix < W; ++ix) {
            if (S[iy][ix] == '#') {
                int score = con;
                while (con > 0) {
                    HS[iy][ix-con] = score;
                    con--;
                }
                HS[iy][ix] == 0;
            } else {
                con += 1;
            }
        }
        if (con > 0) {
            const int score = con;
            while (con > 0) {   
                HS[iy][W-con] = score;
                con--;
            }
        }
    }

    for (int ix = 0; ix < W; ++ix) {
        int con = 0;
        for (int iy = 0; iy < H; ++iy) {
            if (S[iy][ix] == '#') {
                int score = con;
                while (con > 0) {
                    VS[iy-con][ix] = score;
                    con--;
                }
                VS[iy][ix] == 0;
            } else {
                con += 1;
            }
        }
        if (con > 0) {
            const int score = con;
            while (con > 0) {   
                VS[H-con][ix] = score;
                con--;
            }
        }
    }

    int ans = 0;

    for(int ix = 0; ix < W; ++ix) {
        for(int iy = 0; iy < H; ++iy) {
            ans = max({HS[iy][ix] + VS[iy][ix] - 1, ans});
        }
    }
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 42268
#include <iostream>
using namespace std;
int main(void){
    long long int N = 0;
    long long int A = 0;
    long long int B = 0;
    cin >> N >> A >> B;
    
    if (A == 0) {
        cout << 0 << endl;
        return 0;
    }
    
    long long int setNum = N / (A + B);
    long long int amari = N - setNum * (A + B);
    if (amari > A) {
        amari = A;
    }
    cout << setNum * A + amari << endl;
    return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;
import java.util.HashMap;
import java.util.Map;
import java.util.Collections;
import java.util.List;
import java.util.Arrays;
import java.util.ArrayList;
import java.lang.Math;

public class Main {

    private static Scanner sc = new Scanner(System.in);
    private static int mod = (int) 10e8 + 7;

    public static void main(String[] args) {
        int n = sc.nextInt();
        // double[] a = new double[n];
        double sum = 0;
        for (int i = 0; i < n; i++) {
            sum += 1 / sc.nextDouble();
        }
        System.out.println(1 / sum);
    }

}


Measured memory_bytes: 25300
using System;
using System.Linq;
using System.Collections.Generic;

namespace ABC167
{
    class B
    {
        static void Main(string[] args)
        {
            var ABCK = Console.ReadLine().Split().Select(long.Parse).ToArray();
            var A = ABCK[0]; var B = ABCK[1]; var C = ABCK[2]; var K = ABCK[3];

            var res = 0L;

            if (K <= A) res = K;
            else if (K <= A + B) res = A;
            else res = A + (K - (A + B)) * -1;

            Console.WriteLine(res);

        }
    }
}



Measured memory_bytes: 28248
#include<algorithm>//sort(all(変数),greater<型名>())　で降順に
#include<cmath>//切り上げceil(値)
#include<deque>
#include<iomanip>//setprecision(数字)
#include<iostream>
#include<list>
#include<map>
#include<numeric> //xとyの最大公約数は__gcd(x,y),xとyの最小公倍数は(x*y)/__gcd
#include<queue>
#include<set>
#include<stack>
#include<string>
#include<vector>

#include<bits/stdc++.h>
#include<cstdio>
#include<cstdlib>
#include<tuple>
#include<utility>
#define rep(i,n) for(ll i=0; i<n; i++)
#define vll vector<ll>
#define vi vector<int>
#define all(x) (x).begin(),(x).end()
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define mod 1000000007
using ll = long long;
using namespace std;

int main(){
  int ans = 0;
  int s; cin >> s;
  while(0 < s){
    if(s%10 == 1){
      ans++;
    }
    s /= 10;
  }
  cout << ans;
  return 0;
}


Measured memory_bytes: 256
#include <stdio.h>


int main()
{
	int A = 0;
	int B = 0;
	int C = 0;
	int c = 0;
	int d = 0;
	scanf("%d", &A);
	scanf("%d", &B);
	scanf("%d", &C);

	if (A == B)
	{
		if (B != C)
			c++;
		else
			d++;
	}
	if (C == B)
	{
		if (A != C)
			c++;
		else
			d++;
	}
	if (C == A)
	{
		if (A != B)
			c++;
		else
			d++;
	}
	if (A != B && B != C&& A != C)
	{ 
		printf("No"); 

	}

	if (c > 0) 
	{
		printf("Yes"); 
	}
	if (d >0)
	{
		printf("No");
	}





	return 0;
}


Measured memory_bytes: 128
import Control.Monad
import Control.Applicative
import Data.Functor
import Data.List
import Data.List.Split
import Data.Char
import Data.Ord
import Data.Array.IO

readInt = read :: String -> Int
getInt = readLn :: IO Int
getInts = map readInt . words <$> getLine
sjoin :: (Show a) => [a] -> String
sjoin = unwords . map show
cond :: a -> a -> Bool -> a
cond t f c = if c then t else f
-- end of templete

toOp '+' = (+)
toOp '-' = (-)
f n l = [(s ++ (op:show n), toOp op m n) | (s, m) <- l, op <- "+-"]


main = do
    [a,b,c,d] <- map digitToInt <$> getLine
    putStrLn . (++"=7") . fst .  head . filter ((==7) . snd) $ f d $ f c $ f b $ [(show a, a)]

Measured memory_bytes: 380
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (int)n; i++)
#define repb(i, n) for (int i = (int)n; i >= 0; i--)
#define reps(i, m, n) for (int i = (int)m; i < (int)n; i++)
#define repsb(i, m, n) for (int i = (int)m; i >= (int)n; i--)
#define SORT(v, n) sort(v, v + n);
#define VSORT(v) sort(v.begin(), v.end());
#define pb(a) push_back(a)
#define INF 999999999999999999
int dy[] = {0, 0, 1, -1, 0};
int dx[] = {1, -1, 0, 0, 0};
using namespace std;
int main(int argc, char const *argv[])
{
    int n;
    int k;
    double ans = 0, tmp;
    cin >> n >> k;
    rep(i, n)
    {
        tmp = n;
        rep(j, 99999999)
        {
            if ((i + 1) * pow(2, j) < k)
                tmp *= 2;
            else
            {
                break;
            }
        }
        ans += (1 / tmp);
    }
    cout << setprecision(10) << ans;
    return 0;
}

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


long long A,B,C,N;

int main(){
	cin>>A>>B>>C>>N;
	if(N%2){
		cout<<(B-A)<<endl;
	}else{
		cout<<(A-B)<<endl;
	}
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define ALL(a)  (a).begin(),(a).end()
#define SUM(a)  accumulate((a).begin(),(a).end(),0)
#define SORT(a) sort(ALL(a))
#define REV(a) reverse(ALL(a))
#define dump(x)  cerr << #x << " = " << (x) << endl;
typedef long long ll;
const int INTINF = 1<<29;
const ll LLINF = 1LL<<61;
const int MOD = (int)1e9 + 7;
const double EPS = 1e-9;
const int DX[8]={ 0, 1, 0,-1, 1, 1,-1,-1};
const int DY[8]={ 1, 0,-1, 0, 1,-1, 1,-1};


int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int n;
  cin >> n;
  int ans = -n;
  int a;
  REP(i,n){
    cin >> a;
    ans+=a;
  }
  cout << ans << endl;
}


Measured memory_bytes: 256
#include <iostream>

using namespace std;

int main() {
  int n, k;
  int x[100];
  int length = 0;
  cin >> n;
  cin >> k;
  for(int i = 0; i < 100; i++) {
    x[i] = 0;
  }
  for(int i = 0; i < n; i++) {
    cin >> x[i];
  }
  for(int i = 0; i < n; i++) {
    if(k - x[i] > x[i]) {
      length += x[i]*2;
    }
    else {
      length += (k-x[i])*2;
    }
  }
  cout << length << endl;
  return 0;
}

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

#define endl '\n'
#define ll long long

using namespace std;

int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);

	int a, b, c, d;
	cin >> a >> b >> c >> d;

	while (true)
	{
		c -= b;
		if (c <= 0) {
			cout << "Yes";
			break;
		}
		a -= d;
		if (a <= 0) {
			cout << "No";
			break;
		}
	}

	return 0;
}

Measured memory_bytes: 3652
#include <bits/stdc++.h>
using namespace std;
#define reps(i,j,k) for(int i = j;i < k; i++)
#define rep(i,j) reps(i,0,j)
#define INF 1<<30
struct edge
{
	int to;
	int cost;
	int enemy;
	edge(){}
	edge(int _to,int _cost,int _enemy){
		to = _to;
		cost = _cost;
		enemy = _enemy;
	}
	bool operator<(const edge &a)const{
		return enemy>a.enemy;
	}
};
vector < edge > Graph[101];
int d[101][101];
int main(){
	int N,M,L;
	while(scanf("%d%d%d",&N,&M,&L),N|M|L){
		rep(i,101){
			Graph[i].clear();
		}
		rep(i,M){
			int a,b,d,e;
			scanf("%d%d%d%d",&a,&b,&d,&e);
			--a;--b;
			Graph[a].push_back(edge(b,d,e));
			Graph[b].push_back(edge(a,d,e));
		}
		priority_queue < edge > Q;
		Q.push(edge(0,L,0));
		rep(i,101){
			rep(j,101){
				d[i][j] = INF;
			}
		}
		int ans = -1;
		while(!Q.empty()){
			edge e = Q.top();Q.pop();
			if(d[e.to][e.cost] != INF)continue;
			d[e.to][e.cost] = e.enemy;
			if(e.to == N-1){
				ans = e.enemy;
				break;
			}
			rep(i,Graph[e.to].size()){
				if(Graph[e.to][i].cost > e.cost){
					Q.push(edge(Graph[e.to][i].to,e.cost,e.enemy+Graph[e.to][i].enemy));
				}
				else{
					Q.push(edge(Graph[e.to][i].to,e.cost,e.enemy+Graph[e.to][i].enemy));
					Q.push(edge(Graph[e.to][i].to,e.cost-Graph[e.to][i].cost,e.enemy));		
				}
			}
		}
		printf("%d\n",ans);
	}
	return 0;
}

Measured memory_bytes: 1876
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cstdio>
#include <numeric>
#include <cmath>
#include <map>
#include <set>
#define ull unsigned long long
#define ll long long
using namespace std;

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    string s,cmp="CODEFESTIVAL2016";
    cin >> s;
    int cnt=0;
    for(int i=0;i<16;i++){
        if(s[i]!=cmp[i]){
            cnt++;
        }
    }
    cout << cnt << endl;
    return 0;
}

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

int main(){
int A[2];
int B[2];
cin >> A[0] >> A[1] >> B[0] >> B[1];

while(1){
B[0] = B[0]-A[1];
if(B[0]<=0){
    cout << "Yes" << endl;
    break;
}
A[0] = A[0]-B[1];
if(A[0]<=0){
    cout<< "No"<<endl;
    break;
}
}

}

Measured memory_bytes: 3620
#include<iostream>
#include<algorithm>
#include<cstring>
#include<cstdio>
using namespace std;

int a[110][110];
int ans;

int judge(string s)
{
	int now=0;
	for(int i=0;i<5;i++)
		now=a[now][s[i]];
	return now;
}

int check(int x)
{
	//if(x==2016)
		//puts("fuck");
	int tt=0,x1=x;;
	string s="";
	for(int i=4;i>=1;i--)
	{
		s+=x%10;
		x/=10;
	}
	reverse(s.begin(),s.end());
	int now=0;
	for(int i=0;i<4;i++)
		now=a[now][s[i]];
	s+=now;
	string s1=s;
	for(int i=0;i<5;i++)
		for(int j=0;j<10;j++)
		{
			s1=s;
			if(j==s[i])
				continue;
			s1[i]=j;
			if(!judge(s1))
				return 1;
		}
	s1=s;
	for(int i=0;i<4;i++)
	{
		s1=s;
		if(s1[i]==s1[i+1])
			continue;
		swap(s1[i],s1[i+1]);
		if(!judge(s1))
			return 1;
	}
	return 0;
}

int main()
{
	for(int i=0;i<10;i++)
		for(int j=0;j<10;j++)
			cin>>a[i][j];
	for(int i=0;i<=9999;i++)
		ans+=check(i);
	cout<<ans<<endl;
	return 0;
} 

Measured memory_bytes: 3180
#include<iostream>
#include<algorithm>
#include<set>
#include<math.h>
#include<vector>
#include<sstream>
#include<queue>
#include<functional>
#include<bitset>
#include<cstdio>
#include<iomanip>
#include<map>
#include<unordered_map>
#include<unordered_set>
#include <string.h>
using ll = long long;

#define rep(i, n) for(ll i = 0; i < (ll)(n); i++)
#define reps(i,x) for(ll i=1;i<=(ll)(x);i++)
#define rrep(i,x) for(ll i=((ll)(x)-1);i>=0;i--)
#define rreps(i,x) for(ll i=(ll)(x);i>0;i--)
#define all(x) (x).begin(),(x).end()
#define m0(x) memset(x,0,sizeof(x))
#define vll vector<ll>
#define vi vector<int>
#define vpll vector<pair<ll,ll>>
#define vpi vector<pair<int,int>>
#define mod 1000000007 
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

using namespace std;
int a[100000];
int b[100000];
int c[100000];
long long w[110], v[110];

long long dp[110][100100];
int main() {
  ll n, W;
  cin >> n >> W;
  reps(i, n) cin >> w[i] >> v[i];
  reps(i, n)
    reps(j, W){
      if(j - w[i] >= 0) chmax(dp[i][j],  v[i] + dp[i - 1][j - w[i]]);
      chmax(dp[i][j],  dp[i - 1][j]);
    }
  cout << dp[n][W] << endl;
}


Measured memory_bytes: 79360
/*
        _            _                  _            _       _     _         _   _          _          _             _        
       / /\         / /\               / /\         / /\    / /\  /\ \      /\_\/\_\ _     /\ \       /\ \     _    /\ \      
      / /  \       / /  \             / /  \       / / /   / / /  \ \ \    / / / / //\_\   \ \ \     /  \ \   /\_\ /  \ \     
     / / /\ \__   / / /\ \           / / /\ \__   / /_/   / / /   /\ \_\  /\ \/ \ \/ / /   /\ \_\   / /\ \ \_/ / // /\ \_\    
    / / /\ \___\ / / /\ \ \         / / /\ \___\ / /\ \__/ / /   / /\/_/ /  \____\__/ /   / /\/_/  / / /\ \___/ // / /\/_/    
    \ \ \ \/___// / /  \ \ \        \ \ \ \/___// /\ \___\/ /   / / /   / /\/________/   / / /    / / /  \/____// / / ______  
     \ \ \     / / /___/ /\ \        \ \ \     / / /\/___/ /   / / /   / / /\/_// / /   / / /    / / /    / / // / / /\_____\ 
 _    \ \ \   / / /_____/ /\ \   _    \ \ \   / / /   / / /   / / /   / / /    / / /   / / /    / / /    / / // / /  \/____ / 
/_/\__/ / /  / /_________/\ \ \ /_/\__/ / /  / / /   / / /___/ / /__ / / /    / / /___/ / /__  / / /    / / // / /_____/ / /  
\ \/___/ /  / / /_       __\ \_\\ \/___/ /  / / /   / / //\__\/_/___\\/_/    / / //\__\/_/___\/ / /    / / // / /______\/ /   
 \_____\/   \_\___\     /____/_/ \_____\/   \/_/    \/_/ \/_________/        \/_/ \/_________/\/_/     \/_/ \/___________/    
                                                                                                                              
*/
#include<bits/stdc++.h>
using namespace std;
#define ALL(obj) (obj).begin(), (obj).end()
#define REP(i, n) for(int i = 0;i < (n);++i)

#define endl '\n'
#define pb emplace_back
#define mkp make_pair
#define p_q priority_queue
#define INF 1000000000
#define PI 3.1415926
#define coutdb cout << fixed << setprecision(10)

const int dx[]={1,0,-1,0}, dy[]={0,-1,0,1};
const int dx_8[]={1,1,0,-1,-1,-1,0,1}, dy_8[]={0,-1,-1,-1,0,1,1,1};
const long long MOD = 1e9+7;

typedef long long ll;
// #define int long long

template <typename T> inline T GCD(T a,T b){T c;while(b!=0){c=a%b;a=b;b=c;}return a;}
template <typename T> inline T LCM(T a,T b){T c=GCD(a,b);a/=c;return a*b;}
template <typename T> inline T nCr(T a,T b){T i,r=1;for(i=1;i<=b;i++){r*=(a+1-i);r/=i;}return r;}
template <typename T> inline T nHr(T a,T b){return nCr(a+b-1,b);}

bool need[105][105];

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

  int N, M, a[1000], b[1000], c[1000]; cin >> N >> M;
  int d[105][105];
  REP(i, 105) REP(j, 105) {
    if(i == j) d[i][j] = 0;
    else d[i][j] = INF;
  }
  REP(i, M){
    cin >> a[i] >> b[i] >> c[i];
    a[i]--; b[i]--;
    d[a[i]][b[i]] = d[b[i]][a[i]] = c[i];
  }
  REP(k, N) REP(i, N) REP(j, N) d[i][j] = min(d[i][j], d[i][k]+d[k][j]);

  int ans = M;
  REP(i, M){
    bool shortest = 0;
    REP(s, N) REP(t, N) if(d[s][a[i]]+c[i]+d[b[i]][t] == d[s][t] or d[s][b[i]]+c[i]+d[a[i]][t] == d[s][t]) shortest = 1;
    if(shortest) ans--;
  }
  cout << ans << endl;

  return 0;
}

Measured memory_bytes: 384
import java.util.*;
class Main{
    public static void main(String[]args){
        Scanner sc = new Scanner(System.in);
         
        for(;;){
        int dot[]= {1,2,3},sum=1,temp,n;
        n=sc.nextInt();
        if(n==0)break;
         for(;n>=0;n--){
        String s=sc.nextLine();
    if(s.equals("North")){
    	   temp=7-dot[0];
    	   dot[0]=dot[1];
    	   dot[1]=temp;
    	   sum+=dot[0];}
    else if(s.equals("East")){
    	   temp=7-dot[2];
    	   dot[2]=dot[0];
    	   dot[0]=temp;
    	   sum+=dot[0];}
    else if(s.equals("West")){
    	   temp=7-dot[0];
    	   dot[0]=dot[2];
    	   dot[2]=temp;
    	   sum+=dot[0];}
    else if(s.equals("South")){
    	   temp=7-dot[1];
    	   dot[1]=dot[0];
    	   dot[0]=temp;
    	   sum+=dot[0];}
    else if(s.equals("Right")){
    	   temp=7-dot[1];
    	   dot[1]=dot[2];
    	   dot[2]=temp;
    	   sum+=dot[0];}
    else if(s.equals("Left")){
    	   temp=7-dot[2];
    	   dot[2]=dot[1];
    	   dot[1]=temp;
    	   sum+=dot[0];
    }
      }
  System.out.println(sum);
    }
  }
 }

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

const int divisor = 1000000007;

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	vector<int> ansvec;

	// 100000!までの数をdivisorで割った余りを格納しておく
	long long* factmodary = new long long[100001];
	long long fact = 1;
	for (int i = 1; i <= 100000; i++){
		fact *= i;
		fact %= divisor;
		factmodary[i] = fact;
	}

	for (;;){
		int N, R;
		cin >> N;
		if (N == 0) break;
		cin >> R;

		int* word = new int[N];
		for (int i = 0; i < N; i++) word[i] = i + 1; //まず0番目の単語を入れておく

		for (int i = 0; i < R; i++){
			int s, t;
			cin >> s >> t;
			/* swap */
			int tmp = word[s - 1]; word[s - 1] = word[t - 1]; word[t - 1] = tmp;
		}

		long long ans = 0;
		map<int, int> bubblehist;

		for (int i = 0; i < N; i++){
			int facttime = word[i] - 1;
			int bubblenum;
			map<int, int>::iterator it = bubblehist.find(word[i] - 1);

			if (it != bubblehist.end()){
				bubblenum = it->second + 1;
			}
			else {
				it = bubblehist.find(word[i] + 1);
				if (it != bubblehist.end()){
					bubblenum = it->second;
				}
				else{
					bubblenum = 0;
					for (int j = 0; j < i; j++){
						if (word[j] < word[i]) bubblenum++;
					}
				}
			}
			pair<int, int> p;
			p.first = word[i];
			p.second = bubblenum;
			bubblehist.insert(it, p);
			for (map<int, int>::iterator it2 = bubblehist.upper_bound(word[i]); it2 != bubblehist.end(); it2++) ++(it2->second);

			facttime -= bubblenum;
			ans += factmodary[N - (i + 1)] * facttime;
			ans %= divisor;
		}

		delete[] word;
		ansvec.push_back((int)ans);
	}

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

	delete[] factmodary;
	return 0;
}

Measured memory_bytes: 6868
n = gets.to_i
ps = [0, *gets.split.map(&:to_i)]

v = ps.each_with_index.with_object(Array.new(n + 1, 1)) do |(p, i), arr|
  arr[p] = 0 if p == i
end[1..-1]

ans = 0

(n - 1).times do |i|
  next if v[i] == 1 || v[i] * v[i + 1] == 1

  v[i] = v[i + 1] = 1
  ans += 1
end

ans += 1 if v[-1] == 0

puts ans


Measured memory_bytes: 12292
#define _GLIBCXX_DEBUG
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define ALL(v) v.begin(), v.end()
typedef long long ll;

template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }

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

#define WHITE 0
#define GRAY 1
#define BLACK 2
#define INF 1000000010

int n;
int M[100][100];
int color[100],d[100],p[100];

void dik(int s){
  
  rep(i,n){
    color[i]=WHITE;
    d[i]=INF;
    p[i]=-1;
  }
  d[s]=0;
  
  int minc,u;
  while(1){
    minc=INF; 
    rep(i,n){
      if(color[i] != BLACK && d[i]<minc){
        minc=d[i];
        u=i;
      }
    }
    
    if(minc==INF) break;
    color[u]=BLACK;
    
    rep(v,n){
      if(color[v] != BLACK && M[u][v] != -1){
        if(d[u]+M[u][v]<d[v]){
          d[v]=d[u]+M[u][v];
          p[v]=u;
          color[v]=GRAY;
        }
      }
    }    
  }
  
}

int main(){
  cin>>n;
  
  rep(i,n){
    rep(j,n) M[i][j]=INF;
  }
  
  int x,y,z;
  rep(i,n){
    cin>>x>>y;
    rep(j,y){
      cin>>z;
      cin>>M[x][z];
    }
  }
  
  dik(0);
  rep(i,n) cout<<i<<" "<<d[i]<<endl;
  
  return 0;
}


Measured memory_bytes: 3112
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll LLINF = LLONG_MAX;
const int MAX_N = int(1e2 + 5);
#define REP(i, n) for (int i = 0; i < n; i++)

ll n, W, w[MAX_N], v[MAX_N], dp[MAX_N][100005]; // dp[i][j] i番目までみて価値jを作ったときの最小重量

int main() {
    cin >> n >> W;
    REP(i,n) cin >> w[i] >> v[i];
    REP(i,n+1)fill(dp[i],dp[i]+100005,LLINF/2);
    dp[0][0] = 0;
    REP(i,n){
        REP(j,100005){
            dp[i+1][j] = min(dp[i+1][j],dp[i][j]);
            if(j>=v[i]) dp[i+1][j] = min(dp[i+1][j],dp[i][j-v[i]]+w[i]);
        }
    }
    ll ans=0;
    REP(i,100001){
        if(dp[n][i] <= W) ans = i;
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 80128
#include <iostream>

using namespace std;
const int MAXN = 1e5+5;
int arr[MAXN];
int curr;
int mn = 1;
int n;
int mx=1;
int main() {
    cin>>n;
    for(int i=1;i<=n;i++){
        cin>>arr[i];

        if(arr[mx]<arr[i]){
            mx = i;
        }
        if(arr[mn]>arr[i]){
            mn= i ;
        }
    }
    if(abs(arr[mx])>=abs(arr[mn])){
        curr = mx;
    }else{
        curr = mn;
        
    }
    cout<<2*(n-1)<<endl;
    for(int i=1;i<=n;i++){
        if(i == curr){
            continue;
        }
        cout<<curr<<" "<<i<<endl;
    }
    if(arr[curr]>=0){
        for(int i=1;i<n;i++){
            cout<<i<<" "<<i+1<<endl;
        }
    }else{
        for(int i=n;i>1;i--){
            cout<<i<<" "<<i-1<<endl;
        }
    }
}

Measured memory_bytes: 256
#include<stdio.h>
int main(void)
{
	int i,j,n,r,p,c,a[51],b[51],d;

	while(1){
		scanf("%d %d",&n,&r);
		if(n==0&&r==0) break;
		for(i=1;i<=n;i++){
			a[n+1-i]=i;
		}
		for(i=1;i<=r;i++){
			scanf("%d %d",&p,&c);
			d=1;
			for(j=p;j<p+c;j++){
				b[d]=a[j];
				d++;
			}
			for(j=p-1;j>0;j--){
				a[j+c]=a[j];
			}
			for(j=1;j<=c;j++){
				a[j]=b[j];
			}
		}
		printf("%d\n",a[1]);
	}
}

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

typedef long long ll;
typedef pair<int,int> ii;

int main() {
	cin.tie(0); cout.tie(0); ios_base::sync_with_stdio(0);
	int P,Q,R; cin>>P>>Q>>R; cout<<P+Q+R-max({P,Q,R})<<"\n";
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define f first
#define s second
#define mp make_pair
#define pb push_back
#define lp(i,a,n) for(int i=a;i<=n;++i)
#define lpd(i,a,n) for(int i=a;i>=n;--i)
#define mem(a,b) memset(a,b,sizeof a)
#define all(v) v.begin(),v.end()
#define println(a) cout <<(a) <<endl
#define sz(x) ((int)(x).size())
#define readi(x) scanf("%d",&x)
#define read2i(x,y) scanf("%d%d",&x,&y)
#define read3i(x,y,z) scanf("%d%d%d",&x,&y,&z)
#define mod 1000000007
#define eps 1e-8
#define infi 1000000000
#define infll 1000000000000000000ll
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vll;
typedef set<int> si;
typedef map<int,int> mii;

const int N = 100002;
int n,a,b;

int main(){
    read3i(n,a,b);
    if((a&1) == (b&1)) cout <<"Alice";
    else cout <<"Borys";
}

/*
freopen("input.txt","r",stdin);
freopen("output.txt","w",stdout);
*/


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main(){
  int a,b,c,x; cin>>a>>b>>c>>x;
  int sum=0;
  for(int i=0;i<=a;i++){
    for(int j=0;j<=b;j++){
      if(0<=(x-500*i-100*j)/50 && (x-500*i-100*j)/50<=c) sum++;
    }
  }
  cout<<sum<<endl;
}

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

using namespace std;

#define REP(i, a, b) for(i = a; i < b; i++)
#define rep(i, n) REP(i, 0, n)

const int INF = 1<<29;

vector<vector<int> > warshall_floyd(vector<vector<int> > g){
  int i, j, k;

  rep(k, g.size()) rep(i, g.size()) rep(j, g.size()){
    g[i][j] = min(g[i][j], g[k][j] + g[i][k]);
  }

  return g;
}

int main(){
  int i, j, k;
  int n, m;

  while(1){
    cin >> n >> m;
    if(n == 0 && m == 0) break;

    int res = 0;
    int cost, delay;
    string s, p, g;
    vector<string> sta;
    vector<vector<int> > graf(n, vector<int>(n, INF));

    cin >> s >> p >> g;
    rep(i, m){
      string tmp1, tmp2;

      cin >> tmp1 >> tmp2;

      rep(j, sta.size()) if(sta[j] == tmp1) break;
      if(j == sta.size()){ sta.push_back(tmp1); j = sta.size()-1;}

      rep(k, sta.size()) if(sta[k] == tmp2) break;
      if(k == sta.size()){ sta.push_back(tmp2); k = sta.size()-1;}

      cin >> cost >> delay;
      cost /= 40; cost += delay;
      graf[j][k] = cost;
      graf[k][j] = cost;
    }

    int scor, pcor, gcor;
    rep(i, sta.size()){
      if(sta[i] == s) scor = i;
      if(sta[i] == p) pcor = i;
      if(sta[i] == g) gcor = i;
    }

    vector<vector<int> > d = warshall_floyd(graf);
    res += d[scor][pcor];
    res += d[pcor][gcor];

    cout << res << endl;
  }

  return 0;
}

Measured memory_bytes: 0
/*
                _____________   ______________       __
               / _________  /\ /_____   _____/\     / /\
              / /\       / /  \\    /  /\    \ \   / /  \
             / /  \_____/ /   / \__/  /  \____\/  / /   /
            / /   /    / /   /    /  /   /       / /   /
           / /   /    / /   /    /  /   /       / /   /
          / /   /    / /   /    /  /   /       / /   /
         / /___/____/ /   /    /  /   /       / /___/________
        /____________/   /    /__/   /       /______________/\
        \            \  /     \  \  /        \              \ \
         \____________\/       \__\/          \______________\/
           ___       ___               ___    ___________
          /  /\     /  /\             /  /\  /_______   /\
         /  /__\___/  /  \           /  /  \ \      /  /  \
        /____    ____/   /          /  /   /  \____/  /   /
        \   /   /\   \  /          /  /   /       /  /   /
         \_/   /  \___\/ ___      /  /   /       /  /   /
          /   /   /     /  /\    /  /   /       /  /   /
         /   /   /     /  /__\__/  /   /       /  /___/____
        /___/   /     /___________/   /       /___________/\
        \   \  /      \           \  /        \           \ \
         \___\/        \___________\/          \___________\/

          A FAN OF FIZZYDAVID

*/

#include <iostream>
#include <fstream>
#include <sstream>
#include <algorithm>
#include <cstdio>
#include <cassert>
#include <cmath>
#include <cstdlib>
#include <cstring>
#include <string>
#include <deque>
#include <queue>
#include <vector>
#include <list>
#include <map>
#include <set>
#include <bitset>
#include <stack>
#include <iomanip>
#include <utility>
#include <functional>
using namespace std;
//orz jzm
#define ll long long
#define ull unsigned ll
#define orz int
#define yjz main
#define fizzydavid return
#define ak 0
#define la ;
#define plusonesecond {ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);}
#define minusonesecond exit(0)
const double EPS=1e-8;
const ll PR=19260817;
const ll inv2=500000004;
const ll inv3=333333336;
bool cp[10];
bool isok(int n) {
	while (n) {
		if (!cp[n%10]) return false;
		n/=10;
	}
	return true;
}
orz yjz() {
	int n;
	int k;
	memset(cp, true, sizeof(cp));
	cin>>n>>k;
	while (k--) {
		int x;
		cin>>x;
		cp[x]=false;
	}
	for (; ; n++) {
		if (isok(n)) {
			printf("%d\n", n);
			return 0;
		}
	}
	fizzydavid ak la
}

Measured memory_bytes: 256
#include <cstdio>
#include <vector>
#include <algorithm>
#include <string>
#include <stack>

int testcase_ends() {
  char buf[128];
  fgets(buf, sizeof buf, stdin);
  std::string s=buf;
  if (s[0] == '.') {
    return 1;
  }

  std::stack<char> k;
  for (char ch: s) {
    if (ch == '(') {
      k.push(')');
    } else if (ch == '[') {
      k.push(']');
    } else if (ch == ')' || ch == ']') {
      if (k.empty()) 
        return !printf("no\n");
      if (k.top() == ch) {
        k.pop();
      } else {
        printf("no\n");
        return 0;
      }
    } 
  }
  printf("%s\n", k.empty()? "yes":"no");
  return 0;
}

int main() {
  while (!testcase_ends()) {}
}



Measured memory_bytes: 2712
#include <stdio.h>

int main(void)
{
	int i;
	int input;
	int score = 0;
	int ave;
	
	for (i = 0; i < 5; i++){
		scanf("%d", &input);
		if (input < 40){
			input = 40;
		}
		score += input;
	}
	
	ave = score / 5;
	
	printf("%d\n", ave);
	
	return (0);
}


Measured memory_bytes: 2044
#include<stdio.h>

char a[105];

int main()
{
	int x,n,i,max;
	max = x = 0;
	scanf("%d ",&n);
	for(i=0; i<n; i++)
	{
		scanf("%c",&a[i]);
		if(a[i] == 'I')
			x++;
		else 
			x--;
		if(x > max) max++;
	}
	printf("%d",max);
	return 0;
}

Measured memory_bytes: 128
#include<stdio.h>
#include<string.h>

#define LEN 100005

typedef struct pp
{
  char name[100];
  int t;
}P;

P Q[LEN];
int head,tail,n;

void enqueue(P);
P dequeue();
int min(int,int);

int main()
{
  int elaps=0,c;
  int i,q;
  P u;
  
  scanf("%d %d",&n,&q);

  for(i=1;i<=n;i++)
    {
      scanf("%s",Q[i].name);
      scanf("%d",&Q[i].t);
    }
  head=1;
  tail=n+1;
  
  while(head!=tail)
    {
      u=dequeue();
      c=min(q,u.t);
      u.t-=c;
      elaps +=c;
      if(u.t>0) enqueue(u);
      else printf("%s %d\n",u.name,elaps);
    }
  
  return 0;
}

void enqueue(P x)
{
  Q[tail]=x;
  tail=(tail+1)%LEN;
}

P dequeue()
{
  P x = Q[head];
  head=(head+1)%LEN;

  return x;
}

int min(int a,int b)
{
  if(a>=b) return b;
  else return a;
}



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

constexpr int INF = 2147483647;
constexpr long long int INF_LL = 9223372036854775807;
constexpr int MOD = 1000000007;
using namespace std;
using ll = long long int;
using ull =  unsigned long long int;

int main() {
	ll N, K;
	cin >> N >> K;
	vector<pair<ll, ll>> sushi(N);
	for (int i = 0; i < N; i++) {
		ll a, b;
		cin >> a >> b;
		sushi[i] = { b,a };
	}
	sort(sushi.begin(), sushi.end(), greater<>());
	priority_queue<pair<ll, ll>, vector<pair<ll, ll>>, greater<>> s;
	priority_queue<pair<ll, ll>> t;
	// s 食べない候補のネタ(昇順), t 食べる候補のネタ(降順)
	ll sum = 0; //合計おいしさ
	map<ll,bool> used; //ネタの使用状況
	vector<ll> f(N+1, -INF_LL); //i種類食べたときの最大の合計おいしさ
	for (int i = 0; i < K; i++) { 
		sum += sushi[i].first;
		if (used[sushi[i].second]) {//一番おいしいものは絶対食べる
			s.push(sushi[i]);
		}
		else {
			used[sushi[i].second] = true;
		}
	}
	for (int i = K; i < N; i++) {
		if (!used[sushi[i].second]) {//残りのネタは一番おいしいものしか考えなくて良い
			t.push(sushi[i]);
			used[sushi[i].second] = true;
		}
	}
	f[K - s.size()] = sum;
	for (int i = K - s.size() + 1; i <= N; i++) {
		if (s.empty() || t.empty())break;
		sum -= s.top().first; sum += t.top().first;
		s.pop(); t.pop();
		f[i] = sum;
	}
	ll ans = -INF_LL;
	for (ll i = 0; i <= N; i++) {
		ans = max(ans, f[i] + i * i);
	}
	cout << ans << endl;

}


Measured memory_bytes: 9588
use std::io::*;
use std::str::FromStr;
 
/* 
The read function reads a string according to each one. 
*/
fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let stdin = stdin.lock();
    let token: String = stdin
        .bytes()
        .map(|c| c.expect("failed to read char") as char) 
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().expect("failed to parse token")
}


//main function
fn main() {
    let a: i8 = read();
    let b: i8 = read();
    if a<=b {
	println!("{}",a);
    }else {
	println!("{}",a-1);
    }
}


Measured memory_bytes: 4352
#include<bits/stdc++.h> //Ithea Myse Valgulious
using namespace std;
const int yuzu=2e5;
typedef pair<int,int> pii;
typedef int fuko[yuzu|10];
fuko ans;
map<pii,int> mp;
int n,k,l;

struct dsu{
fuko fa;
void init(int n){
  for (int i=1;i<=n;++i) fa[i]=i;
  }
int find(int x){
  return fa[x]==x?x:fa[x]=find(fa[x]);
  }
void mg(int u,int v){
  fa[find(u)]=find(v);
  }
}gl,tl;

int main(){
int i;
scanf("%d%d%d",&n,&k,&l);
gl.init(n),tl.init(n);
for (i=1;i<=k;++i){
  int u,v;
  scanf("%d%d",&u,&v);
  gl.mg(u,v);
  }
for (i=1;i<=l;++i){
  int u,v;
  scanf("%d%d",&u,&v);
  tl.mg(u,v);
  }
for (i=1;i<=n;++i){
  mp[pii(gl.find(i),tl.find(i))]++; 
  }
for (i=1;i<=n;++i){
  printf("%d ",mp[pii(gl.find(i),tl.find(i))]);
  }
}

Measured memory_bytes: 13568
#include<iostream>
#include<algorithm>
#include<vector>
#include<stack>
#include<map>
#include<set>
#include<queue>
#include<cstdio>
#include<climits>
#include<cmath>
#include<cstring>
#include<string>
#include<sstream>
#include<numeric>
#include<cassert>

#define f first
#define s second
#define mp make_pair

#define REP(i,n) for(int i=0; i<(int)(n); i++)
#define rep(i,s,n) for(int i=(s); i<(int)(n); i++)
#define FOR(i,c) for(__typeof((c).begin()) i=(c).begin(); i!=(c).end(); i++)
#define ALL(c) (c).begin(), (c).end()
#define IN(x,s,g) ((x) >= (s) && (x) < (g))
#define ISIN(x,y,w,h) (IN((x),0,(w)) && IN((y),0,(h)))
#define print(x) printf("%d\n",x)

using namespace std;

typedef unsigned int uint;
typedef long long ll;

char buff[510][510];
int memo[510][510];
int w,h;

int main(){
  while(scanf("%d%d ",&h,&w), w+h){
    REP(i,h){
      int cnt = 0;
      fgets(buff[i],sizeof(buff[i]),stdin);
      for(int j=w-1; j>=0; j--){
        if(buff[i][j] == '.'){
          memo[i][j] = ++cnt;
        }else{
          memo[i][j] = cnt = 0;
        }
      }
    }

    int ans = 0;
    REP(i,h) REP(j,w){
      int ww = INT_MAX;
      int k = 0;
      while(i+k < h && buff[i][j] == '.'){
        ww = min(ww, memo[i+k][j]);
        ans = max(ans, (k+1) * ww);
        k++;
      }
    }

    print(ans);
  }
  return 0;
}

Measured memory_bytes: 2136