akhauriyash/Code-Regression huggingface dataset:
import java.util.*;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        long n = sc.nextLong();
        long min = sc.nextLong();
        for (int i = 0; i < 4; i++) {
            min = Math.min(min, sc.nextLong());
        }

        long ans = 4L + (n / min);
        if(n % min != 0) ans += 1L;
        System.out.println( ans);
        sc.close();
    }

}


Measured memory_bytes: 23124
#include<cstdio>
#include<cmath>
#include<cstring>
#include<iostream>
#include<algorithm>
using namespace std;
int a,b;
int main()
{
	scanf("%d%d",&a,&b);
	if(1<=a&&a<=9&&1<=b&&b<=9)
		printf("%d\n",a*b);
	else
		printf("-1\n");
	return 0;
}


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

int main(void) {
	int i, n, n2, s = 0;
	
	scanf("%d", &n);
	
	n2 = n;
	for (i = 9; i >= 0; i--) {
		s += n2 / (int)pow(10, i);
		n2 = n2 % (int)pow(10, i);
	}
	
	printf(n % s ? "No" : "Yes");
	
	return 0;
}

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

using namespace std;

using ll = long long;

#define N (int)1e5+10

int freq[(N)*2], a[(N)*2];

int main()
{
	ios_base :: sync_with_stdio( false );
	cin.tie( nullptr );
	int n;
	cin >> n;
	
	for (int i = 0 ; i < n; i++) cin >> a[i], ++freq[a[i]];
	
	ll ans = 0;
	
	for (int i = 0 ; i <= n; i++) 
		ans += (ll)freq[i]*(freq[i]-1)/2;

	for (int i = 0 ; i < n; i++) 
		cout << ans - freq[a[i]] + 1 << '\n';
	
	return 0;
}


Measured memory_bytes: 3712
#include <cstdio>
#include <vector>
#include <algorithm>
using namespace std;

int N,M;
const int MAX_N = 111;
int a[MAX_N],b[MAX_N*2],sz;
vector<int> odd,even;

vector<int> path[MAX_N*2];
bool visit[MAX_N*2];
int match[MAX_N*2];

bool dfs(int x){
	if(visit[x])return false;
	visit[x]=1;
	for(int i=0;i<path[x].size();i++){
		int y=path[x][i];
		if(match[y]<0){
			match[y]=x;
			return true;
		}else if(dfs(match[y])){
			match[y]=x;
			return true;
		}
	}
	return false;
}

bool isPrime(int x){
	if(x==1)return false;
	if(x%2==0)return false; // 2 is exception
	for(int i=3;i*i<=x;i+=2){
		if(x%i==0)return false;
	}
	return true;
}

int main(){
	scanf("%d",&N);
	for(int i=0;i<N;i++){
		scanf("%d",&a[i]);
	}

	b[sz++]=a[0];
	for(int i=1;i<N;i++){
		if(a[i-1]+1<a[i]){
			b[sz++]=a[i-1]+1;
			b[sz++]=a[i];
		}
	}
	b[sz++]=a[N-1]+1;

	for(int i=0;i<sz;i++){
		if(b[i]%2==0)even.push_back(b[i]);
		else odd.push_back(b[i]);
	}

	for(int i=0;i<even.size();i++){
		for(int j=0;j<odd.size();j++){
			if(isPrime(abs(even[i]-odd[j]))){
				path[i].push_back(j);
			}
		}
	}

	for(int i=0;i<odd.size();i++){
		match[i]=-1;
	}
	
	int cnt=0;
	for(int i=0;i<even.size();i++){
		for(int j=0;j<even.size();j++)visit[j]=0;
		if(dfs(i))cnt++;
	}

	int z0=even.size()-cnt;
	int z1=odd.size()-cnt;
	printf("%d\n",cnt+(z0/2+z1/2)*2+(z0%2)*3);

	return 0;
}


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


#define PB push_back
#define PF push_front
#define LB lower_bound
#define UB upper_bound
#define fr(x) freopen(x,"r",stdin)
#define fw(x) freopen(x,"w",stdout)
#define iout(x) printf("%d\n",x)
#define lout(x) printf("%lld\n",x)
#define REP(x,l,u) for(ll x = (l);x<=(u);x++)
#define RREP(x,l,u) for(ll x = (l);x>=(u);x--)
#define mst(x,a) memset(x,a,sizeof(x))
#define PII pair<int,int>
#define PLL pair<ll,ll>
#define MP make_pair
#define se second
#define fi first
#define dbg(x) cout<<#x<<" = "<<(x)<<endl;
#define sz(x) ((int)x.size())
#define cl(x) x.clear()

typedef  long long ll;
typedef unsigned long long ull;
typedef double db;
typedef long double ld;
using namespace std;

const int maxn = 100010;
const int mod = 1e9+7;
const int MAX = 1000000010;
const double eps = 1e-6;
const double PI = acos(-1);

template<typename T> inline void read(T &x){
x=0;T f=1;char ch;do{ch=getchar();if(ch=='-')f=-1;}while(ch<'0'||ch>'9');do x=x*10+ch-'0',ch=getchar();while(ch<='9'&&ch>='0');x*=f;
}

template<typename A,typename B> inline void read(A&x,B&y){read(x);read(y);}
template<typename A,typename B,typename C> inline void read(A&x,B&y,C&z){read(x);read(y);read(z);}
template<typename A,typename B,typename C,typename D> inline void read(A&x,B&y,C&z,D&w){read(x);read(y);read(z);read(w);}
template<typename A,typename B> inline A fexp(A x,B p){A ans=1;for(;p;p>>=1,x=1LL*x*x%mod)if(p&1)ans=1LL*ans*x%mod;return ans;}
template<typename A,typename B> inline A fexp(A x,B p,A mo){A ans=1;for(;p;p>>=1,x=1LL*x*x%mo)if(p&1)ans=1LL*ans*x%mo;return ans;}

int n,k,ans;

vector<int> has;

int f[maxn];

void Work(){
	n=has.size();
	REP(i,0,n-1){
		f[i]=fexp(k,(has[i]+1)>>1);
		REP(j,0,i-1)if(has[i]%has[j]==0)f[i]=(f[i]-f[j]+mod)%mod;
		if(has[i]&1)ans=(ans+1ll*f[i]*has[i])%mod;else ans=(ans+1ll*f[i]*has[i]/2)%mod;
	}
	iout(ans);
}

void Init(){
	read(n,k);
	REP(i,1,(int)sqrt(n+.5))if(n%i==0)has.PB(i),has.PB(n/i);
	sort(has.begin(),has.end());
	has.erase(unique(has.begin(),has.end()),has.end());
}

int main(){
	Init();
	Work();
	return 0;
}


Measured memory_bytes: 256
import sys
sys.setrecursionlimit(300000)
from collections import deque

def I(): return int(sys.stdin.readline())
def MI(): return map(int, sys.stdin.readline().split())
def LMI(): return list(map(int, sys.stdin.readline().split()))
MOD = 10 ** 9 + 7
INF = float('inf')


H, W = MI()
grid = [list(input()) for _ in range(H)]

seen = set()
q = deque()
for i in range(H):
    for j in range(W):
        if grid[i][j] == '#':
            q.append((i, j, 0))
            seen.add(i * W + j)
while len(q) > 0:
    h, w, d = q.popleft()
    for dh, dw in [(-1, 0), (0, -1), (1, 0), (0, 1)]:
        if 0 <= h + dh < H and 0 <= w + dw < W and (h + dh) * W + w + dw not in seen:
            q.append((h + dh, w + dw, d + 1))
            seen.add((h + dh) * W + w + dw)
print(d)

Measured memory_bytes: 198140
#define _USE_MATH_DEFINES
#include <cstdio>
#include <iostream>
#include <sstream>
#include <fstream>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <complex>
#include <string>
#include <vector>
#include <array>
#include <list>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <bitset>
#include <numeric>
#include <limits>
#include <climits>
#include <cfloat>
#include <functional>
#include <iterator>
#include <memory>
#include <regex>
using namespace std;

bool makeNext(vector<int>& v, int m)
{
    int n = v.size();
    int k = n - 1;
    while(k >= 0 && v[k] == m)
        -- k;
    if(k < 0)
        return false;

    ++ v[k];
    for(int i=k+1; i<n; ++i)
        v[i] = v[k];
    return true;
}

int main()
{
    int n, m, q;
    cin >> n >> m >> q;
    vector<int> a(q), b(q), c(q), d(q);
    for(int i=0; i<q; ++i){
        cin >> a[i] >> b[i] >> c[i] >> d[i];
        -- a[i];
        -- b[i];
    }

    int maxScore = 0;
    vector<int> v(n, 1);
    do{
        int score = 0;
        for(int i=0; i<q; ++i){
            if(v[b[i]] - v[a[i]] == c[i])
                score += d[i];
        }
        maxScore = max(maxScore, score);
    }while(makeNext(v, m));
    cout << maxScore << endl;

    return 0;
}


Measured memory_bytes: 3632
#include<bits/stdc++.h>
using namespace std;
typedef double db;
typedef long long ll;
typedef vector<int> vi;
typedef pair<int, int> pii;
#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define pw(x) (1ll << (x))
#define sz(x) ((int)(x).size())
#define all(x) (x).begin(),(x).end()
#define rep(i,l,r) for(int i=(l);i<(r);++i)
#define per(i,l,r) for(int i=(r)-1;i>=(l);--i)
#define dd(x) cout << #x << " = " << x << ", "
#define de(x) cout << #x << " = " << x << endl

//-----
int n, m;
bool ban[10];
vi v;
int dfs(int cur) {
	if (cur >= n) return cur;
	int ret = INT_MAX;
	for (auto e : v) if (cur * 10 + e) {
		ret = min(ret, dfs(cur * 10 + e));
	}
	return ret;
}
int main() {
	std::ios::sync_with_stdio(false);
	std::cin.tie(0);
	cin >> n >> m;
	rep(i, 0, m) {
		int ai; cin >> ai;
		ban[ai] = true;
	}
	rep(i, 0, 10) if (!ban[i]) v.pb(i);
	cout<<dfs(0);
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <utility>
#include <vector>
#include <set>
#include <algorithm>
#define llint long long
#define inf 1e9

using namespace std;
typedef pair<llint, llint> P;

llint n;
llint a, b;
int succ[20][800005];
vector<P> vecl, vec;
set<P> S;
int N = 1000000;

int main(void)
{
	ios::sync_with_stdio(0);
	cin.tie(0);
	
	cin >> n;
	for(int i = 0; i < n; i++){
		cin >> a >> b;
		vecl.push_back(make_pair(a, b-1));
		vecl.push_back(make_pair(b, a-1+N));
	}
	for(int i = 0; i < 2*n; i++){
		P p = vecl[i];
		vecl.push_back(make_pair(p.first+N, p.second+N));
		//vecl.push_back(make_pair(p.first+2*N, p.second+2*N));
	}
	for(int i = 0; i < vecl.size(); i++){
		P p = vecl[i];
		vec.push_back(make_pair(p.second, p.first));
	}
	sort(vec.begin(), vec.end());
	
	/*cout << vec.size() << endl;
	for(int i = 0; i < vec.size(); i++){
		cout << vec[i].second << " " << vec[i].first << endl;
	}*/
	
	for(int i = 0; i < vec.size(); i++) succ[0][i] = inf;
	for(llint i = 0; i < vec.size(); i++){
		llint l = vec[i].second, r = vec[i].first;
		auto p = S.lower_bound(make_pair(l, 0LL));
		if(p != S.begin()){
			for(auto it = S.begin(); it != p; it++){
				succ[0][it->second] = i;
			}
			S.erase(S.begin(), p);
		}
		S.insert(make_pair(r, i));
	}
	
	for(int j = 1; j < 20; j++){
		for(int i = 0; i < vec.size(); i++){
			if(succ[j-1][i] >= inf) succ[j][i] = inf;
			else succ[j][i] = succ[j-1][succ[j-1][i]];
		}
	}
	
	/*for(int i = 0; i < 5; i++){
		for(int j = 0; j < vec.size(); j++){
			 cout << succ[i][j] << " ";
		}
		cout << endl;
	}*/
	
	llint ans = inf;
	for(int i = 0; i < n; i++){
		llint s = i, p = s, tmp = 0;
		for(int j = 19; j >= 0; j--){
			int np = succ[j][p];
			if(np < inf && vec[np].first < vec[i].first+N) tmp += 1<<j, p = np;
		}
		tmp++;
		//cout << i << " " << tmp << endl;
		ans = min(ans, tmp);
	}
	cout << (ans+1) / 2 << endl;
	
	return 0;
}


Measured memory_bytes: 102736
#include <stdio.h>
#include <math.h>
#define LL long long int
int main(){
  LL n,fla,ans;
  scanf("%lld", &n);
  LL s = 1;
  ans = n/s - 1;
  for(s=2; s<= sqrt(n); s++)
  {
    if(n%s == 0)
      ans = (n/s - 1) +(s - 1);
  }
  printf("%lld", ans);
  return 0;
}

Measured memory_bytes: 2176
#include<stdio.h>

int main(){
    int A, B, C;

    scanf("%d%d%d", &A, &B, &C);

    if((A==B && B!=C) || (B==C && C!=A) || (C==A && A!=B)){
        printf("Yes\n");
    }

    else{
        printf("No\n");
    }
    return 0;
}


Measured memory_bytes: 128
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main {
	public static void main(String[] args) throws NumberFormatException, IOException {
		BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
		String[] n = in.readLine().split("");
		int sum = 0;
		for (String c : n) {
			sum += Integer.parseInt(c);
		}
		if (sum%9 == 0)
			System.out.println("Yes");
		else
			System.out.println("No");
	}
}


Measured memory_bytes: 42872
N = int(input())
A = list(map(int,input().split()))

pos = []
neg = []
zeros = 0
for a in A:
    if a > 0:
        pos.append(a)
    elif a < 0:
        neg.append(a)
    else:
        zeros += 1

pos.sort()
neg.sort()

ope = []

if len(pos) == len(neg) == 0:
    print(0)
    for i in range(N-1):
        print(0,0)
    exit()

if len(neg) == 0:
    if zeros:
        ope.append((0,pos[-1]))
        neg.append(-pos[-1])
        zeros -= 1
        pos.pop()
    else:
        ope.append((pos[0],pos[-1]))
        neg.append(pos[0] - pos[-1])
        pos = pos[1:-1]

elif len(pos) == 0:
    if zeros:
        ope.append((0,neg[0]))
        pos.append(-neg[0])
        zeros -= 1
        neg = neg[1:]
    else:
        ope.append((neg[-1],neg[0]))
        pos.append(neg[-1] - neg[0])
        neg = neg[1:-1]

for p in pos[:-1]:
    ope.append((neg[0], p))
    neg[0] -= p

for n in neg[1:]:
    ope.append((pos[-1], n))
    pos[-1] -= n

ope.append((pos[-1], neg[0]))
ans = pos[-1] - neg[0]
for z in range(zeros):
    ope.append((ans, 0))

print(ans)
for x,y in ope:
    print(x,y)

Measured memory_bytes: 20992
#pragma GCC optimize("O3")
#pragma GCC target("avx")
#include <bits/stdc++.h>
#define rep(i ,n) for(int i=0;i<(int)(n);++i)
#define repr(i ,n) for(int i=n;i>(int)(n);--i)
#define rep1(i ,n) for(int i=1;i<=(int)(n);++i)
#define ALL(a) a.begin(), a.end()
#define RSORT(a) sort(ALL(a),greater<>())
#define SORT(a) sort(ALL(a))
#define bit_check(bit, i) ((bit>>(i)) & 1)
#define PRINT(x) printf("%d\n",(x));
#define ENDL printf("\n");
using namespace std;
typedef long long int i64;
typedef unsigned long long u64;
template<class T> using V = vector<T>;
using I = int;
using VI = V<I>;
const int INF = 2e9;
const i64 MOD = 1e9 + 7;

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

VI a;
VI dp;

int binary_search(VI a ,int key){ //time limit ecxeeded
    int left = 0;
    int right = a.size()-1;
    int middle;
    while(left <= right){
        middle = ( left + right ) / 2;
        if( key == a[middle]) return middle;
        else if ( key < a[middle]) right = middle - 1;
        else left = middle + 1;
    }
    return left;
}

signed main(){
    int n;cin >> n;
    a.resize(n);
    dp.resize(n,INF);
    rep(i ,n) cin >> a[i];
    dp[0] = a[0];
    for(int i = 1 ; i < n ; ++i){
        *lower_bound(ALL(dp) , a[i]) = a[i];
    }
    int ans = 0;
    rep(i , n){
        if(dp[i] != INF) ++ans;
        else break;
    }
    PRINT(ans);
}


Measured memory_bytes: 3624
def InputToInt():
    A = input().split()
    for i in range(len(A)):
        A[i] = int(A[i])
    return A

if __name__ == '__main__':
    N = int(input())
    A = InputToInt()
    B = InputToInt()

    C = 0
    for i in range(N):
        if B[i] <= A[i]:
            C += B[i]
        elif B[i] <= A[i] + A[i+1]:
            C += B[i]
            A[i+1] -= B[i] - A[i]
        else:
            C += A[i] + A[i+1]
            A[i+1] = 0
    print(C)


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

using namespace std;
typedef long long ll;
const int MAXN = 5100;

int N, K;
int arr[MAXN];
int pdp[MAXN][MAXN];
int sdp[MAXN][MAXN];

int main()
{
    ios_base::sync_with_stdio(0);

    cin >> N >> K;
    for (int i = 0; i < N; i++)
    {
        cin >> arr[i];
        if (arr[i] > K) arr[i] = K;
    }

    pdp[0][0] = 1;
    for (int i = 0; i < N; i++)
    {
        for (int j = 0; j <= K; j++)
            pdp[i+1][j] = pdp[i][j];

        for (int j = 0; j <= K - arr[i]; j++)
            pdp[i+1][j+arr[i]] |= pdp[i][j];
    }
    sdp[0][0] = 1;
    for (int i = 0; i < N; i++)
    {
        for (int j = 0; j <= K; j++)
            sdp[i+1][j] = sdp[i][j];

        for (int j = 0; j <= K - arr[N-1-i]; j++)
            sdp[i+1][j+arr[N-1-i]] |= sdp[i][j];
    }

    int ans = 0;
    for (int i = 0; i < N; i++)
    {
        int ploc = i, sloc = N - 1 - i;

        int ggoal = K - arr[i];
        int cloc = 0;
        for (int j = K; j >= 0; j--)
        {
            if (cloc + j < ggoal)
                cloc = ggoal - j;
            while (cloc < K && !sdp[sloc][cloc])
                cloc++;

            if (pdp[ploc][j] && sdp[sloc][cloc] && (j + cloc >= ggoal) && (j + cloc < K))
            {
                ans++;
                break;
            }
        }
    }
    cout << N - ans << "\n";
}

Measured memory_bytes: 203008
/*{{{*/
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<string>
#include<iostream>
#include<sstream>
#include<set>
#include<map>
#include<queue>
#include<bitset>
#include<vector>
#include<limits.h>
#include<assert.h>
#define SZ(X) ((int)(X).size())
#define ALL(X) (X).begin(), (X).end()
#define REP(I, N) for (int I = 0; I < (N); ++I)
#define REPP(I, A, B) for (int I = (A); I < (B); ++I)
#define FOR(I, A, B) for (int I = (A); I <= (B); ++I)
#define FORS(I, S) for (int I = 0; S[I]; ++I)
#define RS(X) scanf("%s", (X))
#define SORT_UNIQUE(c) (sort(c.begin(),c.end()), c.resize(distance(c.begin(),unique(c.begin(),c.end()))))
#define GET_POS(c,x) (lower_bound(c.begin(),c.end(),x)-c.begin())
#define CASET int ___T; scanf("%d", &___T); for(int cs=1;cs<=___T;cs++)
#define MP make_pair
#define PB push_back
#define MS0(X) memset((X), 0, sizeof((X)))
#define MS1(X) memset((X), -1, sizeof((X)))
#define LEN(X) strlen(X)
#define F first
#define S second
using namespace std;
typedef long long LL;
typedef unsigned long long ULL;
typedef long double LD;
typedef pair<int,int> PII;
typedef vector<int> VI;
typedef vector<LL> VL;
typedef vector<PII> VPII;
typedef pair<LL,LL> PLL;
typedef vector<PLL> VPLL;
template<class T> void _R(T &x) { cin >> x; }
void _R(int &x) { scanf("%d", &x); }
void _R(LL &x) { scanf("%lld", &x); }
void _R(double &x) { scanf("%lf", &x); }
void _R(char &x) { scanf(" %c", &x); }
void _R(char *x) { scanf("%s", x); }
void R() {}
template<class T, class... U> void R(T &head, U &... tail) { _R(head); R(tail...); }
template<class T> void _W(const T &x) { cout << x; }
void _W(const int &x) { printf("%d", x); }
void _W(const LL &x) { printf("%lld", x); }
void _W(const double &x) { printf("%.16f", x); }
void _W(const char &x) { putchar(x); }
void _W(const char *x) { printf("%s", x); }
template<class T,class U> void _W(const pair<T,U> &x) {_W(x.F); putchar(' '); _W(x.S);}
template<class T> void _W(const vector<T> &x) { for (auto i = x.begin(); i != x.end(); _W(*i++)) if (i != x.cbegin()) putchar(' '); }
void W() {}
template<class T, class... U> void W(const T &head, const U &... tail) { _W(head); putchar(sizeof...(tail) ? ' ' : '\n'); W(tail...); }
#ifdef HOME
 #define DEBUG(...) {printf("# ");printf(__VA_ARGS__);puts("");}
#else
 #define DEBUG(...)
#endif
int MOD = 1e9+7;
void ADD(LL& x,LL v){x=(x+v)%MOD;if(x<0)x+=MOD;}
/*}}}*/
const int SIZE = 1e6+10;
int main(){
    string s;
    R(s);
    printf("%c%d%c\n",s[0],SZ(s)-2,s.back());
    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<cmath>
#include<cstring>

using namespace std;
const int mod = 1e9+7;
int ad(int x,int y) { x+=y; return x>=mod?x-mod:x; }
int mu(int x,int y) { return 1ll*x*y%mod; }
int sb(int x,int y) { x-=y; return x<0?x+mod:x; }
int ksm(int a,int b) {
	int ans = 1;
	for(;b;b>>=1,a=mu(a,a))
		if(b&1) ans = mu(ans,a);
	return ans;
}
int n,h[1005];

struct node{
	int s0,s1;
}; //s0 no xiangling s1 suiyi

node DC(int l,int r,int lm) {
	int x0 = 1 , x1 = 1 , cc = 0;
	int mimi = 0x3f3f3f3f;
	for(int i=l;i<=r;i++) {
		mimi = min(mimi,h[i]);
	}
	for(int i=l;i<=r;i++) cc += (h[i]==mimi);
	for(int i=l,j;i<=r;i=j+1) {
		j = i;
		if(h[i]>mimi) {
			while(j+1<=r&&h[j+1]!=mimi) j++;
			node yoo = DC(i,j,mimi);
			x0 = mu(x0,yoo.s0); x1 = mu(x1,ad(yoo.s0,yoo.s1));
		}
	}
	return (node){mu(x0,ksm(2,mimi-lm)),ad(mu(x0,sb(ksm(2,mimi-lm),2) ),mu(x1,ksm(2,cc))) };
}

int main() {
	scanf("%d",&n);
	for(int i=1;i<=n;i++) {
		scanf("%d",&h[i]);
	}
	node ans = DC(1,n,0);
	printf("%d",ans.s1);
}
//

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

typedef long long int ll;
typedef pair<ll, ll> p_ll;
typedef vector<pair<ll, ll>> vec_p; //vector<pair<ll, ll>> pairs(n) ,pairs.at(i) = make_pair(i*i, i)

#define ture ture
#define flase false
#define falg flag

#define REP(i, x) for (ll i = 0; i < (ll)(x); 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()

const ll MOD = pow(10, 9) + 7;
const ll LLINF = pow(2, 61) - 1;//llの最大9*10^18
const int INF = pow(2, 30) - 1;

ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }

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

    ll N,X,T;
    string S;
    cin >> N>>X>>T;

    ll tmp=N/X;
    if(N%X==0){
        cout << tmp*T<<endl;
    }
    else{
        cout << tmp*T+T<<endl;
    }

}  


Measured memory_bytes: 3656
import java.util.*;
public class Main {
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    int v[] = new int[3];
    for(int i = 0;i < 3;i++){
      v[i] = sc.nextInt();
    }
    Arrays.sort(v);
    System.out.println(v[2]-v[1]+v[1]-v[0]);
  }
}

Measured memory_bytes: 22996
using System;
using System.Collections.Generic;

class Program
{
    static void Main () 
    {
        String s = Console.ReadLine();
        String t = Console.ReadLine();
        long ans = 0;
        for (int i = 0; i < s.Length; i++)
        {
            if(s[i] != t[i])
            {
                ans++;
            }
        }
        Console.WriteLine(ans);
    }
}

Measured memory_bytes: 27432
#include<iostream>

using namespace std;
typedef long long ll;

int main(){ll a,b,x; cin >> a >> b >> x;
           ll s = a / x; ll t = b / x; 
           ll rem_a = a % x; 
           if(rem_a == 0){cout << t - s + 1 << endl; return 0;}
           else{cout << t - s << endl; return 0;}
          }

Measured memory_bytes: 256
// ███▓▓▓▓▓▓▓▓▓╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬▓▓▓╬╬╬╬╬╬▓█
// ███▓███████▓▓╬╬╬╬╬╬╬╬╬╬╬╬▓███▓▓▓▓█▓╬╬╬▓█
// ███████▓█████▓▓╬╬╬╬╬╬╬╬▓███▓╬╬╬╬╬╬╬▓╬╬▓█
// ████▓▓▓▓╬╬▓█████╬╬╬╬╬╬███▓╬╬╬╬╬╬╬╬╬╬╬╬╬█
// ███▓▓▓▓╬╬╬╬╬╬▓██╬╬╬╬╬╬▓▓╬╬╬╬╬╬╬╬╬╬╬╬╬╬▓█
// ████▓▓▓╬╬╬╬╬╬╬▓█▓╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬▓█
// ███▓█▓███████▓▓███▓╬╬╬╬╬╬▓███████▓╬╬╬╬▓█
// ████████████████▓█▓╬╬╬╬╬▓▓▓▓▓▓▓▓╬╬╬╬╬╬╬█
// ███▓▓▓▓▓▓▓╬╬▓▓▓▓▓█▓╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬▓█
// ████▓▓▓╬╬╬╬▓▓▓▓▓▓█▓╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬▓█
// ███▓█▓▓▓▓▓▓▓▓▓▓▓▓▓▓╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬▓█
// █████▓▓▓▓▓▓▓▓█▓▓▓█▓╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬▓█
// █████▓▓▓▓▓▓▓██▓▓▓█▓╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬██
// █████▓▓▓▓▓████▓▓▓█▓╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬██
// ████▓█▓▓▓▓██▓▓▓▓██╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬██
// ████▓▓███▓▓▓▓▓▓▓██▓╬╬╬╬╬╬╬╬╬╬╬╬█▓╬▓╬╬▓██
// █████▓███▓▓▓▓▓▓▓▓████▓▓╬╬╬╬╬╬╬█▓╬╬╬╬╬▓██
// █████▓▓█▓███▓▓▓████╬▓█▓▓╬╬╬▓▓█▓╬╬╬╬╬╬███
// ██████▓██▓███████▓╬╬╬▓▓╬▓▓██▓╬╬╬╬╬╬╬▓███
// ███████▓██▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓╬╬╬╬╬╬╬╬╬╬╬████
// ███████▓▓██▓▓▓▓▓╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬▓████
// ████████▓▓▓█████▓▓╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬▓█████
// █████████▓▓▓█▓▓▓▓▓███▓╬╬╬╬╬╬╬╬╬╬╬▓██████
// ██████████▓▓▓█▓▓▓╬▓██╬╬╬╬╬╬╬╬╬╬╬▓███████
// ███████████▓▓█▓▓▓▓███▓╬╬╬╬╬╬╬╬╬▓████████
// ██████████████▓▓▓███▓▓╬╬╬╬╬╬╬╬██████████
// ███████████████▓▓▓██▓▓╬╬╬╬╬╬▓███████████
//#include "grader.h"
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <cstdio>
#include <numeric>
#include <cstring>
#include <ctime>
#include <cstdlib>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <list>
#include <cmath>
#include <bitset>
#include <cassert>
#include <queue>
#include <deque>
#include <cassert>
#define x first
#define y second
#define pb push_back
#define mp make_pair
#define read(FILENAME) assert(freopen((FILENAME + ".in").c_str(), "r", stdin))
#define write(FILENAME) assert(freopen((FILENAME + ".out").c_str(), "w", stdout))
#define files(FILENAME) read(FILENAME), write(FILENAME)
using namespace std;
template <typename A, typename B> void chkmin(A &x, B y) {if (x > y) x = y;}
template <typename A, typename B> void chkmax(A &x, B y) {if (x < y) x = y;}
     
typedef pair <int, int> point;
     
const string FILENAME = "input";
const int MAXN = 1e5 + 1, p = 1e9 + 7;


int dsu[MAXN];

int get(int i) {
	if (dsu[i] == i) return i;
	return dsu[i] = get(dsu[i]); 
}

int n;
point arr[MAXN];
vector <pair <int, point>> que;
vector <int> coor;
int ans;

bool cmp(int i, int j) {
	return arr[i] < arr[j];
}

int main() {
	srand(time(0));
	ios::sync_with_stdio(0);
	//read(FILENAME);
	cin >> n;
	for (int i = 0; i < n; ++i) {
		cin >> arr[i].x >> arr[i].y;
		coor.pb(i);
		dsu[i] = i;
	}
	for (int t = 0; t < 2; ++t) {
		sort(coor.begin(), coor.end(), cmp);
		for (int i = 1; i < n; ++i) {
			que.pb({arr[coor[i]].x - arr[coor[i - 1]].x, {coor[i], coor[i - 1]}});
		}
		for (int i = 0; i < n; ++i) swap(arr[i].x, arr[i].y);
	}
	sort(que.begin(), que.end());
	for (auto i: que) {
		int u = i.y.x, v = i.y.y, c = i.x;
		//cout << u << ' ' << v << ' ' << c << endl;
		//cout << get(u) << ' ' << get(v) << endl;
		if (get(u) != get(v)) {
			dsu[dsu[u]] = dsu[v];
			ans += c;
		}
	}
	cout << ans << endl;
}	




Measured memory_bytes: 6640
#include <algorithm>
#include <bits/stdc++.h>
#include <cstdint>
#include <functional>
#include <iostream>
#include <iterator>
#include <vector>

// lib/less_by.hpp
#ifndef LESS_BY_HPP
#define LESS_BY_HPP


/*
usage:

std::sort(a.begin(), a.end(), tools::less_by([](int a_i) { return std::abs(x); }));
*/

namespace tools {
  template <class T, class R>
  class less_by {
  private:
    ::std::function<R(T)> selector;

  public:
    less_by(const ::std::function<R(T)>& selector) : selector(selector) {
    }

    bool operator()(const T& x, const T& y) const {
      return selector(x) < selector(y);
    }

    using first_argument_type = T;
    using second_argument_type = T;
    using result_type = bool;
  };
}

#endif

// lib/util.hpp
#ifndef UTIL_HPP
#define UTIL_HPP


typedef ::std::int_fast64_t i64;
typedef ::std::uint_fast64_t u64;
typedef ::std::int_fast32_t i32;
typedef ::std::uint_fast32_t u32;

namespace tools {
  template <typename T>
  void read(::std::istream& is, ::std::vector<T>& vector, const typename ::std::vector<T>::size_type size) {
    vector.reserve(size);
    ::std::copy_n(::std::istream_iterator<T>(is), size, ::std::back_inserter(vector));
  }
  template <typename T>
  void read(::std::vector<T>& vector, const typename ::std::vector<T>::size_type size) {
    ::tools::read(::std::cin, vector, size);
  }

  template <typename T, ::std::size_t N>
  void read(::std::istream& is, ::std::array<T, N>& array) {
    ::std::copy_n(std::istream_iterator<T>(is), N, array.begin());
  }
  template <typename T, ::std::size_t N>
  void read(::std::array<T, N>& array) {
    ::tools::read(::std::cin, array);
  }
}

#endif

// main.cpp

class robot {
public:
  i64 X;
  i64 L;
  friend std::istream& operator>>(std::istream& is, robot& self) {
    return is >> self.X >> self.L;
  }
};

int main() {
  i64 N;
  std::cin >> N;
  std::vector<robot> robots;
  tools::read(robots, N);

  std::sort(robots.begin(), robots.end(), tools::less_by<robot, i64>([](const robot& robot) { return robot.X + robot.L; }));
  i64 max = std::numeric_limits<i64>::min();
  i64 answer = 0;
  for (const robot& robot : robots) {
    if (max <= robot.X - robot.L) {
      max = robot.X + robot.L;
      ++answer;
    }
  }

  std::cout << answer << std::endl;
  return 0;
}

Measured memory_bytes: 1792
import java.io.*;
import java.util.*;
public class Main
{
	
	private void solve()throws IOException
	{
		int n=nextInt();
		int m=nextInt();
		int p[]=new int[n+1];
		for(int i=1;i<=n;i++)
			p[i]=nextInt();
		UnionFind dsu=new UnionFind(n);
		for(int i=1;i<=m;i++)
		{
			int u=nextInt();
			int v=nextInt();
			dsu.union(u,v);
		}
		int ans=0;
		for(int i=1;i<=n;i++)
			if(dsu.find(i)==dsu.find(p[i]))
				ans++;
		out.println(ans);
	}
	class UnionFind
	{       
		int parent[],rank[],size[],num;
		UnionFind(int n) 
		{
			num=n;
			parent=new int[n+1];
			rank=new int[n+1];
			size=new int[n+1];
			for(int i=1;i<=n;i++)
			{
				parent[i]=i;
				size[i]=1;
				rank[i]=0;
			}
		}
		int find(int a){
			if(parent[a]==a)
				return a;
			parent[a]=find(parent[a]);
			return parent[a];
		}
		void union(int a,int b){
			a=find(a);
			b=find(b);
			if(a==b)
				return;
			num--;
			if(rank[a]>rank[b])
			{
				parent[b]=a;
				size[a]+=size[b];
			}
			else
			{
				if(rank[a]==rank[b])
					rank[b]++;
				parent[a]=b;
				size[b]+=size[a];
			}
		}
	}

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

	public void run()throws IOException
	{
		br=new BufferedReader(new InputStreamReader(System.in));
		st=null;
		out=new PrintWriter(System.out);

		solve();
		
		br.close();
		out.close();
	}
	public static void main(String args[])throws IOException{
		new Main().run();
	}
	BufferedReader br;
	StringTokenizer st;
	PrintWriter out;
	String nextToken()throws IOException{
		while(st==null || !st.hasMoreTokens())
		st=new StringTokenizer(br.readLine());
		return st.nextToken();
	}
	String nextLine()throws IOException{
		return br.readLine();
	}
	int nextInt()throws IOException{
		return Integer.parseInt(nextToken());
	}
	long nextLong()throws IOException{
		return Long.parseLong(nextToken());
	}
	double nextDouble()throws IOException{
		return Double.parseDouble(nextToken());
	}
}

Measured memory_bytes: 44884
import java.io.PrintWriter;
import java.util.*;
public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		PrintWriter out = new PrintWriter(System.out);
		int N = Integer.parseInt(sc.next());
		int d[] = new int[N];
		for (int i = 0; i < N; i++) {
			d[i] = Integer.parseInt(sc.next());
		}

		int result = Arrays.stream(d).distinct().toArray().length;
		out.println(result);
		out.flush();
	}
}

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

#define M 1046527
#define L 14

char H[M][L]; /* Hash Table */

int getChar(char ch){
  if ( ch == 'A') return 1;
  else if ( ch == 'C') return 2;
  else if ( ch == 'G') return 3;
  else if ( ch == 'T') return 4;
  else return 0;
}
long long getKey(char str[]){
  long long sum = 0, p = 1, i;
  for ( i = 0; i < strlen(str); i++ ){
    sum += p*(getChar(str[i]));
    p *= 5;
  }
  return sum;
}

int h1(int key){
  return (key%M);
}
int h2(int key){
  return 1+(key%(M-1));
   /* your task */
}

int find(char str[]){
  long long key, i ,k;
  key=getKey(str);
  for ( i = 0;; i++) {
    k=((h1(key)+i*h2(key))%M);
    if(strcmp(H[k],str)==0) return 1;
    else if(strlen(H[k])==0) return 0;
  }
  return 0;
}

int insert(char str[]){
  long long key, i ,k;
  key=getKey(str);
  for ( i = 0;; i++) {
    k=((h1(key)+i*h2(key))%M);
    if(strcmp(H[k],str)==0) return 1;
    else if(strlen(H[k])==0){
      strcpy(H[k],str);
      return 0;
    }
  }
  return 0;
}

int main(){
    int i, n, h;
    char str[L], com[9];
    for ( i = 0; i <M;i++ ) H[i][0] = '\0';
    scanf("%d", &n);
    for ( i = 0; i<n; i++ ){
	     scanf("%s %s", com, str);
	      if( com[0] == 'i' ) insert(str);
        else{
	         if(find(str))
		          printf("yes\n");
              else printf("no\n");
	           }
    }
    return 0;
}

Measured memory_bytes: 14916
#include <bits/stdc++.h>
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 (b<a) { a=b; return 1; } return 0; }

using ll = long long;

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

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

int main() {
  ll N;
  cin>>N;
  vector<ll> A(N),B(N);
  for(ll i = 0LL; i < N; i++) cin>>A[i];
  for(ll i = 0LL; i < N; i++) cin>>B[i];
  vector<ll> d(N);
  ll mi=0LL,pl=0LL;
  for(ll i = 0LL; i < N; i++){
    d[i]=B[i]-A[i];
    if(d[i]>0LL) pl+=d[i]-(d[i]%2LL);
    if(d[i]<0LL) mi-=d[i];
  }
  if(pl>=mi*2LL)cout<<"Yes"<<endl;
  else cout<<"No"<<endl;
}
  

Measured memory_bytes: 512
#include <iostream>
#include <algorithm>
#include <math.h>
using namespace std;

int main(){
  double a,b,c;
  int cnt[4];
  fill(cnt,cnt+4,0);
  while(cin >> a >> b >> c){
    double array[3];
    int sum = a + b + c;
    int Max = max(a,max(b,c));
    int remain = sum - Max;

    if(Max >= remain){
      break;
    }

    array[0] = a;
    array[1] = b;
    array[2] = c;
    sort(array,array+3);

    double Max_angle = 0;
    do{
      double tmp = (array[0]*array[0]+array[2]*array[2]-array[1]*array[1])/
	(2*array[0]*array[2]);

      Max_angle = max(Max_angle,acos(tmp));
    }while(next_permutation(array,array+3));

    cnt[0]++;

    if(Max_angle > M_PI / 2.0) cnt[3]++;
    else if(Max_angle < M_PI / 2.0) cnt[2]++;
    else cnt[1]++;

  }
  for(int i=0; i<4; i++){
    if(i == 0) cout << cnt[i];
    else cout << " " << cnt[i];
  }
  cout << endl;
  
  return 0;
}

Measured memory_bytes: 1288
#include <bits/stdc++.h>
//#include <ext/pb_ds/tree_policy.hpp>
//#include <ext/pb_ds/assoc_container.hpp>
using namespace std;
//using namespace __gnu_pbds;
//template<typename key, typename val>
//using ordered_tree =
//  tree<key, val, greater<>, rb_tree_tag, tree_order_statistics_node_update>;
typedef long long int64;
typedef complex<double> comp;
const double pi = 3.14159265358979323846;
const int inf = (int)1e+9 + 2;
const int64 inf64 = (int64)1e+18 + 2;
const double dinf = 1e+20;
const int mod = 1'000'000'007;//998244353;
const int base = 2187;
const double eps = 1e-8;
const int N = 100'000;
const int LOGN = 19;

int n, m, k;

void solve(int test) {
  string s;
  cin >> n >> s;
  s.erase(unique(begin(s), end(s)), end(s));
  cout << s.size() << '\n';
}

void precalc() {
}

int main() {
  ios::sync_with_stdio(0);
  cin.tie(0), cout.tie(0);
  precalc();
  int test = 1;
  //cin >> test;
  //auto start = chrono::high_resolution_clock::now();
  for (int i = 1; i <= test; ++i) {
    solve(i);
  }
  //cerr << chrono::duration_cast<chrono::milliseconds>(chrono::high_resolution_clock::now() - start).count() << '\n';
  return 0;
}




Measured memory_bytes: 512
# C TLE
# -*- coding: utf-8 -*-
K = int(input())

if K % 2 == 0 or K % 5 == 0:
    print(-1)
else:
    num = 7
    for i in range(10 ** 6):
        mod_num = num % K
        if mod_num == 0:
            print(i + 1)
            break
        num = mod_num * 10 + 7
    

Measured memory_bytes: 9100
n,m = gets.chomp.split(" ").map(&:to_i)

ary = []
cost = 0
nums = 0

n.times do
  ab = gets.chomp.split(" ").map(&:to_i)
  ary.push(ab)
end

ary = ary.sort { |s,t| s[0] <=> t[0] }

i = 0
while nums < m do
  c = 0
  while c < ary[i][1] do
    cost += ary[i][0]
    nums += 1
    c += 1
    break if nums == m
  end
  i += 1
end

p cost


Measured memory_bytes: 11128
#include <cstdio>
#include <iostream>

using namespace std;

double data[10];
double n;
double ans=0;

int main(){
	while(cin >> n){
		ans = 0;
		data[0] = n;
		for(int i=1;i<10;i++){
			if((i+1)%2 == 0){
				data[i] = data[i-1] * 2;
			}else{
				data[i] = data[i-1] / 3;
			}
		}

		for(int i=0;i<10;i++)ans += data[i];

		printf("%0.8lf\n",ans);
	}
}

Measured memory_bytes: 3036
#include <stdio.h>
#include <iostream>
#include <string>
#include <algorithm>
#include <numeric>
#include <cmath>
#include <vector>
using namespace std;

int main(){
    // input
    int N, X; cin >> N >> X;
    vector<int> m(N);
    for (int i = 0; i < N; i++){
        cin >> m.at(i);
    }
    
    // compute
    vector<int> num;
    int sum = accumulate(m.begin(), m.end(), 0);
    int rest = X - (sum);
    for (int i = 0; i < N; i++){
        num.push_back(floor(rest/m.at(i)));
    }

    int ans = *max_element(num.begin(), num.end()) + N;

    // output
    cout << ans << endl;
}



Measured memory_bytes: 256
#include<iostream>
#include<string>
using namespace std;
int main(){
	bool a[30];
	int b[28];
	for(int i=0;i<30;i++)
		a[i]=false;
	for(int i=0;i<28;i++)
		cin>>b[i];
	 for(int i=0;i<27;i++){
         for(int j=27;j>i;j--){
	        if(b[j]<b[j-1]){
	        int t=b[j];
	        b[j]=b[j-1];
	        b[j-1]=t;
	        }
         }
    }
	for(int i=0;i<28;i++)
		a[b[i]]=true;
	for(int i=1;i<=30;i++){
		if(a[i]==false)
			cout<<i<<endl;
	}
	return 0;
}

Measured memory_bytes: 1160
#include<bits/stdc++.h>
using namespace std;
int main()
{
    long long int sum = 0;
    int n;
    cin>>n;
    for(int i=1;i<=n;i++){
        if(i%3==0 || i%5==0){
            continue;
        }
        else {
            sum+=i;
        }
    }
    cout<<sum<<endl;
}


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

typedef long long ll;
#define re(n) cin >> n
#define all(a) a.begin(),a.end()
#define pb push_back
#define mp make_pair
#define ff(i,x,n) for(ll i=(int)x;i<(int)n;i++)
#define f(i,n) ff(i,0,n)
#define fast std::ios_base::sync_with_stdio(false),cin.tie(0),cout.tie(0)
#define te(t) ll t; re(t); while(t--)
#define MOD 1000000007

int main(){
	string s;
	re(s);
	ll con = 0;
	ll ans = 0;
	f(i, 3){
		if(s[i]==s[i-1]&&s[i]=='R'&&i!=0)
			con++;
		else if(s[i]=='R'){
			ans = max(ans, con);
			con = 1;
		}
	}
	ans = max(ans, con);
	cout << ans << "\n";
	return 0;
}


Measured memory_bytes: 3572
#include<cstdio>
#include<vector>
#include<algorithm>

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

using namespace std;

template<class T>
class d_heap_for_Dijkstra{
	static const int N_MAX=100;
	int n,d,key[N_MAX],pos[N_MAX];
	T val[N_MAX];

	void sift_up(int i,const T &x){
		val[i]=x;
		while(i!=0 && val[(i-1)/d]>val[i]){
			int p=(i-1)/d;
			swap(pos[key[p]],pos[key[i]]);
			swap(key[p],key[i]);
			swap(val[p],val[i]);
			i=p;
		}
	}
	void sift_down(int i,const T &x){
		val[i]=x;
		for(int j,k,c;;i=j){
			j=i;
			for(c=0,k=d*i+1;c<d;c++,k++) if(k<n && val[j]>val[k]) j=k;
			if(j==i) break;
			swap(pos[key[j]],pos[key[i]]);
			swap(key[j],key[i]);
			swap(val[j],val[i]);
		}
	}
public:
	d_heap_for_Dijkstra(int d):n(0),d(d){}
	int find_min()const{ return key[0]; }
	void insert(int u,const T &x){
		int i=n++;
		key[i]=u;
		pos[u]=i;
		sift_up(i,x);
	}
	void delete_min(){
		n--;
		pos[key[n]]=pos[key[0]];
		key[0]=key[n];
		sift_down(0,val[n]);
	}
	void decrease_key(int u,const T &x){
		sift_up(pos[u],x);
	}
	bool empty()const{ return n==0; }
	int size()const{ return n; }
};

const int INF=1<<29;

struct edge{ int v,cost1,cost2; };

int main(){
	for(int m,n;scanf("%d%d",&m,&n),n;){
		vector<edge> G[100];
		rep(i,m){
			int u,v,cost1,cost2; scanf("%d%d%d%d",&u,&v,&cost1,&cost2); u--; v--;
			G[u].push_back((edge){v,cost1,cost2});
			G[v].push_back((edge){u,cost1,cost2});
		}

		int q; scanf("%d",&q);
		while(q--){
			int s,t,type; scanf("%d%d%d",&s,&t,&type); s--; t--;

			int d[100];
			rep(u,n) d[u]=(u==s?0:INF);
			d_heap_for_Dijkstra<int> H(4);
			H.insert(s,0);
			while(!H.empty()){
				int u=H.find_min();
				H.delete_min();

				if(u==t) break;

				rep(i,G[u].size()){
					const edge &e=G[u][i];
					int d2=d[u]+(type==0?e.cost1:e.cost2);
					if(d[e.v]>d2){
						if(d[e.v]==INF) H.insert(e.v,d2);
						else            H.decrease_key(e.v,d2);
						d[e.v]=d2;
					}
				}
			}

			printf("%d\n",d[t]);
		}
	}

	return 0;
}

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

// 型定義
typedef long long ll;
typedef pair<ll, ll> P;

// forループ
#define REP(i,n) for(ll i=0; i<(ll)(n); ++i)

// 定数宣言
const int INF = 1e9;
const int MOD = 1e9+7;
const ll LINF = 1e18;

// グラフ表現
using Graph = vector<vector<int>>;

// グラフの辺表現
using Edge = map<pair<int,int>,int>;

// n次元配列の初期化。第２引数の型のサイズごとに初期化していく。
template<typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val){
    std::fill( (T*)array, (T*)(array+N), val );
}

// 最大公約数
ll gcd(ll a,ll b){
   if (a%b == 0) return(b);
   else return(gcd(b, a%b));
}

// 最小公倍数
ll lcm(ll a, ll b){
    return a*b/gcd(a, b);
}

int main()
{
    cout << fixed << setprecision(15);
    ll N, K, C;
    string S;
    cin >> N >> K >> C;
    cin >> S;

    vector<int> L;
    vector<int> R;

    int lcounter = 0;
    for(ll i=0; i<N; i++){
        if(S[i] == 'o'){
            L.push_back(i+1);
            i += C;
            lcounter++;
        }
        if(lcounter == K) break;
    }

    int rcounter = 0;
    for(ll i=N-1; i>=0; i--){
        if(S[i] == 'o'){
            R.push_back(i+1);
            i = i - C;
            rcounter++;
        }
        if(rcounter == K) break;
    }

    REP(i, K){
        if(L[i] == R[K-i-1]){
            cout << L[i] << endl;
        }
    }
    return 0;
}

Measured memory_bytes: 3448
#include<bits/stdc++.h>
#define MAX 100007
using namespace std;
typedef long long ll;

ll pre[MAX],cost[MAX];
vector<ll>adj[MAX];

int main()
{
    ll t,i,n,m,a,b,co,s;
    cin >> n >> m;
    for(i=0; i<m; i++)
    {
        cin >> a >> b;
        adj[a].push_back(b);
        adj[b].push_back(a);
    }

    for(i=1; i<=n; i++)cost[i]=1e9;

    deque<ll>q;
    q.push_back(1);
    pre[1]=1;
    cost[1]=0;
    while(!q.empty())
    {
        s=q.front();
        q.pop_front();
        co=cost[s];
        for(auto s1: adj[s])
        {
            if(cost[s1]>(co+1))
            {
                cost[s1]=co+1;
                pre[s1]=s;
                q.push_back(s1);
            }
        }
    }
    ll ok=1;
    for(i=2; i<=n; i++)ok &= cost[i]!=1e9;
    if(ok==0)cout << "No\n";
    else
    {
        cout << "Yes\n";
        for(i=2; i<=n; i++)cout << pre[i] << "\n";
    }
    return 0;
}



Measured memory_bytes: 13760
import collections
import heapq
n=int(input())
A=[int(i) for i in input().split()]
Ans=[0]*n
M=[0]#自分より前の最大値をメモ。これ以下だと現れない
for i in range(n):
  M.append(max(M[-1],A[i]))
D=collections.defaultdict(int)
H=[]
for i in range(n):
  j=n-1-i
  if A[j]<=M[j]:
    heapq.heappush(H,-A[j])#出現しないインデックスの数を管理。大きいほうから取り出す。
  else:
    Ans[j]=(A[j]-M[j])*(D[A[j]]+1)#自分より前の最大値と自分の差かける自分自身と同じ数のこれまでの出現回数
    D[M[j]]+=D[A[j]]+1#自分自身より後ろの自分と同じ数全てを自分より前の最大値まで減らすことで増える分
    ct=0
    while H:#自分より後ろで自分より小さいが、自分の前の最大値より大きいものを全て見る
      a=heapq.heappop(H)
      a=-a
      if a<=M[j]:
        heapq.heappush(H,-a)
        break
      else:
        Ans[j]+=a-M[j]
        D[M[j]]+=1

for a in Ans:
  print(a)


Measured memory_bytes: 25176
import java.util.*;

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

        int a = sc.nextInt();
        int b = sc.nextInt();
        int c = sc.nextInt();

        if(a > b){
            if(a>c) {
                if(b<c){
                    System.out.println("Yes");
                }else{
                    System.out.println("No");
                }
            }else{
                System.out.println("No");
            }

        }else{
            if(b>c){
                if(a<c){
                    System.out.println("Yes");
                }else{
                    System.out.println("No");
                }

            }else{
                System.out.println("No");
            }
        }

    }
}

Measured memory_bytes: 22996
#include <stdio.h>
#include <stdlib.h>

char conv_table(char index, char data);

int main()
{
    int     n, m;
    int     ii;
    char    buf[16];
    char    str[100000];
    
    while(1){
        fgets(buf, sizeof(buf), stdin);
        n = atoi(buf);
        if(n == 0){
            break;
        }
        for(ii = 0; ii < n; ii++){
            fgets(buf, sizeof(buf), stdin);
            conv_table(buf[0], buf[2]);
        }
        fgets(buf, sizeof(buf), stdin);
        m = atoi(buf);
        for(ii = 0; ii < m; ii++){
            fgets(buf, sizeof(buf), stdin);
            str[ii] = conv_table(buf[0], 0);
        }
        str[ii++] = '\n';
        str[ii] = 0;
        printf("%s", str);
        conv_table(0, 0);
    }
    
    return 0;
}

char conv_table(char index, char data)
{
    static char chart[62][2];
    static int  index_count = 0;
    int         loop_count = 0;
    
    if(data != 0){
        chart[index_count][0] = index;
        chart[index_count][1] = data;
        index_count++;
        return 0;
    }else if(index == 0){
        index_count = 0;
        return 0;
    }else{
        loop_count = 0;
        while(chart[loop_count][0] != index){
            loop_count++;
            if(index_count <= loop_count){
                return index;
            }
        }
        return chart[loop_count][1];
    }
}


Measured memory_bytes: 1928
use proconio::{fastout, input};

#[fastout]
fn main() {
    input! {n: String};

    let mut isSeven = false;
    for i in n.chars() {
        if i == '7' {
            isSeven = true;
            break;
        }
    }

    if isSeven {
        println!("Yes")
    } else {
        println!("No")
    }
}


Measured memory_bytes: 2132
#include <iostream>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <cstdlib>
#include <cmath>
#include <ctime>
#include <cstring>
#include <iomanip>
// #include <ext/pb_ds/assoc_container.hpp>
// #include <ext/pb_ds/tree_policy.hpp>
// #define ordered_set tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update>
#define int long long
#define For(i,x,y) for(int i = x; i <= y; ++i)
#define FOR For
#define rev_For(i,x,y) for(int i = x; i >= y; --i)
#define REV_FOR rev_For
#define ll long long
#define Size(v) ((int)v.size())
#define _section "\n--------------------\n"
#define fi first
#define se second
#define pb push_back
using namespace std;
// using namespace __gnu_pbds;


int n;
const int nax = 1e6  + 5;
int a[nax];

void input() {
	cin >> n;
}

void solve() {
	int sum = 0;
	FOR (i, 1, n) {
		if (i % 3 != 0 && i % 5 != 0) sum += i;
	}
	cout << sum;
}

signed main() {
#ifdef _DEBUG
	// freopen("INPUT.inp", "r", stdin);
	//freopen("OUTPUT.out", "w", stdout);
	clock_t start, end;
	start = clock();
#endif
	ios_base::sync_with_stdio(0);
	cin.tie(0);
//------------------------------------------------------------------------------------
//----------------------------------MAIN PROGRAM--------------------------------------
	int t = 1;
	while (t--) {
		input();
		solve();
	}
//--------------------------------------END-------------------------------------------
//------------------------------------------------------------------------------------
#ifdef _DEBUG
	end = clock();
	cerr << "\n----------\nTime Elapsed: " << fixed << double(end - start) / double(CLOCKS_PER_SEC) << setprecision(6) << '\n';
#endif
	return 0;
}

Measured memory_bytes: 3604
N,M = list(map(int,input().split()))
S = list("*"*N)
for i in range(M):
    s,c = list(map(int,input().split()))
    if S[s-1] == '*':
        S[s-1]=str(c)
        if S[0]=='0' and N != 1:
            print(-1)
            exit()
    
    elif S[s-1]!=str(c):
        print(-1)
        exit()
if S[0]=='*' and N>1:
    S[0]='1'
elif S[0] == '*' and N == 1:
    S[0] = '0'

for i in range(N):
    if S[i] == '*':
        S[i] = '0'
print("".join(S))
    


Measured memory_bytes: 9128
#include <bits/stdc++.h>
#define ll long long
#define pb push_back
#define mk make_pair
#define pll pair<ll,ll>
using namespace std;
const int MAXN=2e5+5;
vector<int> g[MAXN];
ll subsize[MAXN],ans[MAXN],fact[MAXN],inv_fact[MAXN],num_ways[MAXN];
const ll mod=1e9+7;
inline ll fastexpo(ll base,ll expo)
{
    ll result=1;
    while(expo>0)
    {
        if(expo%2)
        {
            result=result*base;
            result%=mod;
        }
        base=base*base;
        base%=mod;
        expo=expo/2ll;
    }
    return result;
}
inline void dfs(int pos,int prev)
{
    subsize[pos]++;
    num_ways[pos]=1;
    for(int i=0;i<g[pos].size();i++)
    {
        if(g[pos][i]!=prev)
        {
            dfs(g[pos][i],pos);
            subsize[pos]+=subsize[g[pos][i]];
            num_ways[pos]=(num_ways[pos]*num_ways[g[pos][i]])%mod;
            num_ways[pos]=(num_ways[pos]*inv_fact[subsize[g[pos][i]]])%mod;
        }
    }
    num_ways[pos]=(num_ways[pos]*fact[subsize[pos]-1])%mod;
}
stack<pll> sz,way;
inline void ndfs(int pos,int prev)
{
    if(pos!=1)
    {
        sz.push(mk(subsize[pos],subsize[prev]));
        way.push(mk(num_ways[pos],num_ways[prev]));
        num_ways[prev]=(num_ways[prev]*fastexpo(num_ways[pos],mod-2))%mod;
        num_ways[prev]=(num_ways[prev]*fact[subsize[pos]])%mod;
        num_ways[prev]=(num_ways[prev]*inv_fact[subsize[prev]-1])%mod;
        num_ways[pos]=(num_ways[pos]*inv_fact[subsize[pos]-1])%mod;
        subsize[prev]-=subsize[pos];
        subsize[pos]+=subsize[prev];
        num_ways[prev]=(num_ways[prev]*fact[subsize[prev]-1])%mod;
        num_ways[pos]=(num_ways[pos]*fact[subsize[pos]-1])%mod;
        num_ways[pos]=(num_ways[pos]*num_ways[prev])%mod;
        num_ways[pos]=(num_ways[pos]*inv_fact[subsize[prev]])%mod;
    }
    ans[pos]=num_ways[pos];
    for(int i=0;i<g[pos].size();i++)
    {
        if(g[pos][i]!=prev)
        {
            ndfs(g[pos][i],pos);
        }
    }
    if(pos!=1)
    {
        pll szs=sz.top();
        sz.pop();
        pll ways=way.top();
        way.pop();
        subsize[pos]=szs.first;
        subsize[prev]=szs.second;
        num_ways[pos]=ways.first;
        num_ways[prev]=ways.second;
    }
}
int main() {
	ll n;
	cin>>n;
	fact[0]=1;
	subsize[0]=1;
	for(int i=1;i<=n;i++)
	{
	    fact[i]=fact[i-1]*i;
	    fact[i]%=mod;
	}
	for(int i=0;i<=n;i++)
	{
	    inv_fact[i]=fastexpo(fact[i],mod-2);
	}
	for(int i=1;i<n;i++)
	{
	    int x,y;
	    cin>>x>>y;
	    g[x].pb(y);
	    g[y].pb(x);
	}
	dfs(1,0);
	ndfs(1,0);
	for(int i=1;i<=n;i++)
	{
	    cout<<ans[i]<<endl;
	}
	return 0;
}


Measured memory_bytes: 21748