akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <array>
#include <queue>
#include <deque>
#include <map>
#include <set>
#include <sstream>
#include <stdio.h>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <list>
#include <numeric>
#include <stack>
#include <iomanip>

//using namespace std;

#define Rep(i,a,b) for(int i = a; i < b; ++i)
#define rep(i,b) Rep(i,0,b)
#define allof(a) (a).begin(), (a).end()

typedef long long ll;
const int inf = 1e9 + 7;
const ll infll = 1ll << 60ll;
const ll mod = 1e9 + 7;
// 0~3までは右左下上 4~7までは斜め
constexpr int dx[] = { 1, 0, -1, 0, 1, 1, -1, -1 };
constexpr int dy[] = { 0, -1, 0, 1, 1, -1, -1, 1 };

template<typename T> void chmax(T& a, T b) { a = std::max(a, b); }
template<typename T> void chmin(T& a, T b) { a = std::min(a, b); }
template<typename T> void chadd(T& a, T b) { a = a + b; }

namespace {  // 名前なし名前空間
	// gcd, lcm は C++17 でstdに標準入りしたので言語のバージョンに注意
	// 最大公約数
	ll gcd(ll a, ll b) {
		if (b == 0) return a;
		return gcd(b, a % b);
	}

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

int main() {

	int a, b;
	std::cin >> a >> b;

	if (a >= 10 || b >= 10) {
		std::cout << -1 << std::endl;
		return 0;
	}

	std::cout << a * b << std::endl;

	return 0;
}

Measured memory_bytes: 256
#include<cstdio>
int main(){
	int n;
	scanf("%d",&n);
	int k=0;
	for(int i=0;i<7;i++){
		if((n-4*i)%7==0&&n-4*i>=0)k++;
	}
	if(k>=1)printf("Yes\n");
	else printf("No\n");
	return 0;
}

Measured memory_bytes: 128
#include<stdio.h>
int main() {
    int x, y, ans = 0;
    scanf("%d%d", &x, &y);
    if(x == 3) ans += 1;
    if(x == 2) ans += 2;
    if(x == 1) ans += 3;
    if(y == 3) ans += 1;
    if(y == 2) ans += 2;
    if(y == 1) ans += 3;
    if(x == 1 && y == 1) ans += 4;
    printf("%d\n", ans * 100000);
    return 0;
} 

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

using namespace std;
int main(){
    int n;
    while(cin >> n, n){
        vector<int> a(n);
        int sum = 0;
        for(auto&& x:a)cin >> x;
        for(auto&& x:a)sum += x;
        sum /= n;
        int ret = 0;
        for(auto&& x:a)if(x <= sum)ret++;
        cout << ret << endl;
    }
}


Measured memory_bytes: 3108
import itertools

a = input()
b = ["3", "5", "7"]
d = 0
for i in range(1, len(a)+1):
    for j in itertools.product(b, repeat=i):
        c = ""
        for k in range(len(j)):
            c += j[k]
        if int(c) <= int(a):
            if "3" in c and "5" in c and "7" in c:
                d += 1
print(d)


Measured memory_bytes: 3060
#include<stdio.h>
int main(void)
{
    double x;
    scanf("%lf",&x);
    int i=1;
    long long int n=100;
    int k;
    while(1){
        n=n*(1.01);
        if(n>=x){
            break;
        }
        i++;
    }
    printf("%d\n",i);

    return 0;
}

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

#define ll long long int
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define phi 3.1415926535
#define fastio() ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define endl '\n'
 
using namespace std;

const ll mod = 1000000007;    

ll tc, cnt = 0, number, many, total = 0, query;
// vector <vector <int> > adjList;
int rmove[8] = {1, 0, -1, 0, -1, 1, -1, 1};
int cmove[8] = {0, 1, 0, -1, 1, -1, -1, 1};

ll power(ll x, ll y, ll mod)
{
    if(y == 0)
        return 1;
    else if(y % 2 == 0)
        return (power(x, y / 2, mod) % mod * power(x, y / 2, mod) % mod) % mod;
    else
        return x * (power(x, y / 2, mod) % mod * power(x, y / 2, mod) % mod) % mod;
}

int main()
{
    fastio();
        
    // freopen("input.txt","r", stdin);
    // freopen("output.txt","w", stdout);
    // g++ -std=c++11 Default.cpp  -o test
    // g++ -Wl,--stack=268435456 -std=c++11 Default.cpp  -o test

    int row, column;
    cin >> row >> column;
 
    char arr[row][column];
    for(int i = 0; i < row; i++)
        for(int j = 0; j < column; j++)
            cin >> arr[i][j];
 
    int dp[row][column];
    int modulo = 1e9 + 7;
    memset(dp, 0, sizeof(dp));
 
    if(arr[0][0] == '.')
        dp[0][0] = 1;
 
    for(int i = 0; i < row; i++)
    {
        for(int j = 0; j < column; j++)
        {
            if(arr[i][j] == '.')
            {
                if(i > 0)
                    (dp[i][j] += dp[i - 1][j]) %= modulo;
                if(j > 0)
                    (dp[i][j] += dp[i][j - 1]) %= modulo;
            }
        }
    }
 
//    for(int i = 0; i < row; i++)
//    {
//        for(int j = 0; j < column; j++)
//            cout << dp[i][j] << " ";
//        cout << endl;
//    }

    cout << dp[row - 1][column - 1] << endl;

    //
    return 0;
}

Measured memory_bytes: 8488
#include <cstdio>
#include <cctype>
#include <cstring>
#include <algorithm>
int read(){
	register int x = 0;
	register char f = 1, ch = getchar();
	for (; !isdigit(ch); ch = getchar()) if (ch == '-') f ^= 1;
	for (; isdigit(ch); ch = getchar()) x = (x << 1) + (x << 3) + (ch ^ '0');
	return f ? x : -x;
}
int n, k, q, a[100005];
int main(){
	n = read(), k = read(), q = read();
	for (register int i = 1; i <= n; ++i) a[i] = k - q;
	for (register int i = 1; i <= q; ++i) ++a[read()];
	for (register int i = 1; i <= n; ++i) if (a[i] > 0) puts("Yes"); else puts("No");
}

Measured memory_bytes: 896
macro_rules! get {
    (Vec<$t:ty>) => {
        {
            let mut line: String = String::new();
            std::io::stdin().read_line(&mut line).unwrap();
            line.split_whitespace()
                .map(|t| t.parse::<$t>().unwrap())
                .collect::<Vec<_>>()
        }
    };
    ($t:ty) => {
        {
            let mut line: String = String::new();
            std::io::stdin().read_line(&mut line).unwrap();
            line.trim().parse::<$t>().unwrap()
        }
    };
    ($($t:ty),*) => {
        {
            let mut line: String = String::new();
            std::io::stdin().read_line(&mut line).unwrap();
            let mut iter = line.split_whitespace();
            (
                $(iter.next().unwrap().parse::<$t>().unwrap(),)*
            )
        }
    };
    ($t:ty; $n:expr) => {
        (0..$n).map(|_|
            get!($t)
        ).collect::<Vec<_>>()
    };
    ($($t:ty),*; $n:expr) => {
        (0..$n).map(|_|
            get!($($t),*)
        ).collect::<Vec<_>>()
    };
}

fn main() {
    let (N, x) = get!(usize, usize);
    let mut a = get!(Vec<usize>);

    a.sort();
    let (k, s) = a.iter().fold(
        (0, 0),
        |(res, acc), b| {
            (
                if acc + b <= x {
                    res + 1
                } else {
                    res
                },
                acc + b
            )
        }
    );
    let ans = if s >= x {
        k
    } else {
        k - 1
    };

    println!("{}", ans);
}


Measured memory_bytes: 4352
N = int(input())
S = input()
L = list(S)
count = 0

for i in range(0,1000):

    fst = 0
    snd = 0
    thd = 0
    tmp = 0

    if(i<10):
        num = "00"+str(i)
    elif(i<100):
        num = "0"+str(i)
    else:
        num = str(i)

    if num[0] in L:
        fst = L.index(num[0]) + 1
        tmp += 1
    if num[1] in L[fst:]:
        snd = fst + L[fst:].index(num[1]) + 1
        tmp += 1
    if num[2] in L[snd:]:
        thd = snd + L[snd:].index(num[2]) + 1
        tmp += 1
    if tmp == 3:
        count+= 1
        


print(count)
    
    

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

int main() {
	int n;
	cin >> n;
	vector<int> a(n);
	vector<vector<int>> x(n), y(n);
	rep(i, n) {
		cin >> a[i];
		rep(j, a[i]) {
			int X, Y; cin >> X >> Y;
			X--;
			x[i].emplace_back(X);
			y[i].emplace_back(Y);
		}
	}
	int ans = 0;
	rep(bit, (1 << n)) {
		bool elf = true;
		rep(i, n) {
			if (bit & (1 << i)) {
				rep(j, a[i]) {
					if (y[i][j] == 1) {
						if (!(bit & (1 << x[i][j]))) elf = false;
					}
					else {
						if (bit & (1 << x[i][j])) elf = false;
					}
				}
			}
		}
		if (!elf) continue;
		int cnt = 0;
		rep(i, n) if (bit & (1 << i)) cnt++;
		ans = max(ans, cnt);
	}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 256
import sys
from collections import deque
import copy
import math
def get_read_func(fileobject):
    if fileobject == None :
        return raw_input
    else:
        return fileobject.readline

def main():
    if len(sys.argv) > 1:
        f = open(sys.argv[1])
    else:
        f = None
    read_func = get_read_func(f);
    input_raw = read_func().strip().split()
    [N] = [int(input_raw[0])]
    input_raw = read_func().strip().split()
    A = []
    for i in range(N):
        A.append(int(input_raw[i]))
    input_raw = read_func().strip().split()
    B = []
    for i in range(N):
        B.append(int(input_raw[i]))
    input_raw = read_func().strip().split()
    C = []
    for i in range(N):
        C.append(int(input_raw[i]))
    A.sort()
    B.sort()
    C.sort()

    A_backet = {}
    C_backet = {}
    A_ptr = 0L
    C_ptr = 0L
    count = 0L
    for i in range(N):
        while A_ptr < N and A[A_ptr] < B[i]:
            A_ptr += 1L
        while C_ptr < N and C[C_ptr] <= B[i]:
            C_ptr += 1L
        count += A_ptr * (N - C_ptr)
    print count




if __name__ == '__main__':
    main()


Measured memory_bytes: 25372
#include <iostream>
#include <vector>
#include <set>
#include <algorithm>
#include <map>
#include <math.h>
#define ll long long

using namespace std;


ll A[2222];

map<ll,ll> hashed[4444];

ll Solve(ll x, ll y,bool who,int pos,int N) {
    if (pos == N+1)
        return abs(x-y);
    
    
    // who=0 maximize
    // who=1 minimize
    
    if (hashed[pos*2+who].find(y) != hashed[pos*2+who].end())
        return hashed[pos*2+who][y];
    
    
    ll optval = -1;
    
    for(int j=pos;j<=N;j++) {
        ll curr = Solve(y, A[j], !who, j+1, N);
        if (!who) {
            if (optval == -1 || curr > optval)
                optval=curr;
        } else {
            if (optval == -1 || curr < optval)
                optval=curr;
        }
    }
    return hashed[pos*2+who][y]=optval;
}

int main() {
    int N,Z,W;
    cin>>N>>Z>>W;
    for(int i=1;i<=N;i++) {
        cin>>A[i];
    }
    
    cout << Solve(Z,W,0,1,N) << endl;
    
}

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

using namespace std;

#define ll long long
#define md 1000000007
#define loop(i,a,b) for(int i=a; i<b; i++)
#define lloop(i,a,b) for (long long i=a; i<b; i++)
#define loopr(i,a,b) for(int i = a; i>=b; i--)
#define iterate(it, v) for (auto it = v.begin(); it!= v.end(); it++)
#define mk make_pair
#define pb push_back

template <typename T>
void printArray(T *arr, int n){
    loop(i,0,n){
        cout << arr[i] << " ";
    } cout << endl;
}

template <typename T>
void printMatrix(T **arr, int m, int n){
    loop(i,0,m){
        loop(j,0,n) cout << arr[i][j] << " ";
    } cout << endl;
}

ll int getMax(int **arr, int n) {
    int dp[n][3];
    dp[0][0] = arr[0][0];
    dp[0][1] = arr[0][1];
    dp[0][2] = arr[0][2];

    loop(i,1,n) {
        dp[i][0] = arr[i][0] + max(dp[i-1][1], dp[i-1][2]);
        dp[i][1] = arr[i][1] + max(dp[i-1][0], dp[i-1][2]);
        dp[i][2] = arr[i][2] + max(dp[i-1][1], dp[i-1][0]);

    }

    return max(dp[n-1][0], max(dp[n-1][1], dp[n-1][2]));
}

int main(){
    
	int n;
  	cin >> n;
  	int **arr = new int*[n];
    loop(i,0,n) arr[i] = new int[3];

    loop(i,0,n) loop(j,0,3) cin >> arr[i][j];

    cout << getMax(arr, n) << endl;
    
}

Measured memory_bytes: 5376
#include <bits/stdc++.h>
using namespace std;
#define mp(a,b) make_pair(a,b)
#define ff first
#define setp setprecision(6)<<fixed
#define ss second
#define fori(v) for(lli i=0; i<v; i++)
#define forj(v) for(int j=0; j<v; j++)
#define fork(v) for(int k=0; k<v; k++)
#define forl(v) for(int l=0; l<v; l++)
#define fort(v) for(int t=0; t<v; t++)
#define forz(v) for(int z=0; z<v; z++)
#define lli long long int
#define MAX 220020
#define ld long double
#define pb push_back
int inf = pow(10,9)+7;
lli modulo = pow(10,9)+7;
double eps = 1e-11;
ifstream in;
ofstream out;
//#define cin in
//#define cout out
void disp(vector<pair<int,int> > edg, vector<int> w, int n){
	cout<<n<<" "<<edg.size()<<endl;
	fori(edg.size())
		cout<<edg[i].ff<<" "<<edg[i].ss<<" "<<w[i]<<endl;
}
void deal(){
	cin.tie(0);
	ios_base::sync_with_stdio(0);
	int l;
	cin>>l;
	int n = 20;
	int m = 19;
	vector<pair<int,int> > edg;
	vector<int> w;
	--l;
	fori(19)
		edg.pb(mp(i+1,i+2)), w.pb(0);
	if(l){
		int bg = 0;
		fori(20)
			if((1<<i) & l)
				bg = i;
		fori(bg){
			edg.pb(mp(n-i-1,n-i));
			w.pb(1<<i);
		}	
		int indi = 1<<bg;
		while(1){
			int nw = -1;
			forj(bg)
				if((1<<j)&l)
					nw = j;
			if(nw==-1){
				edg.pb(mp(1,n)), w.pb(indi);
				break;
			}
			bg = nw;
			int xansi = n-bg;
			edg.pb(mp(1,xansi)), w.pb(indi);
			indi^=1<<bg;
		}
	}
	disp(edg,w,n);
}

int main() {
	deal();
	return 0;
}   

Measured memory_bytes: 256
package main

import "fmt"

func main() {
	var t, ans, m int
	for i := 0; i < 5; i++ {
		fmt.Scan(&t)
		ans += t
		if t%10 != 0 {
			w := 10 - (t % 10)
			ans += w
			if m < w {
				m = w
			}
		}
	}
	ans -= m
	fmt.Println(ans)
}


Measured memory_bytes: 512
#include <iostream>
#include <vector>
#include <unordered_set>
#include <unordered_map>
#include <queue>
#include <stack>
#include <fstream>
#include <string>
#include <sstream>
#include <algorithm>
#include <climits>
#include <cmath>

using namespace std;

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

    int h1, m1, h2, m2, k;
    cin >> h1 >> m1 >> h2 >> m2 >> k;
    int sleeptime = h2* 60 + m2;
    int begtime = h1 * 60 + m1;

    cout << sleeptime - k - begtime << "\n"; 
    
	return 0;
}


Measured memory_bytes: 3196
#include <iostream>
#include<math.h>
#include<list>
#include <algorithm>
#include<set>
#include<vector>
#include<math.h>
#include<map>
#include<string>
using namespace std;
using ll = long long;
using vll = vector<long long>;
using sll = set<long long>;

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

#define in(x) cin >> x
#define out(x) cout << x
#define outn(x) cout << x << '\n'
#define outs(x) cout << x << ' '
#define rep(i,s,e) for(long i=s;i<e;i++)
#define repeq(i,s,e) for(long i=s;i<=e;i++)


int main() {
	ll n,total=0;
	in(n);
	vll a(n+1),b(n+1,0);

	repeq(i, 1, n) {
		in(a[i]);
		b[i] -= abs(a[i - 1] - a[i]);
		if (i > 1) {
			b[i - 1] += abs(a[i - 2] - a[i]) - abs(a[i - 1] - a[i]);
		}
		total += abs(a[i - 1] - a[i]);
	}

	b[n] += abs(a[n - 1]) - abs(a[n]);
	total += abs(a[n]);

	repeq(i, 1, n) {
		outn(total + b[i]);
	}

	return 0;

	}
	

Measured memory_bytes: 2816
#include<cstdio>
#include<cctype>
#include<algorithm>
#include<iostream>
#include<cstring>

#define X first
#define Y second
#define mp make_pair
#define pb push_back
#define debug(...) fprintf(stderr,__VA_ARGS__)

using namespace std;

inline char nc(){ static char buf[100000] , *p1,*p2; return p1 == p2 && (p2 = (p1 = buf) + fread(buf,1,100000,stdin),p1 == p2) ? EOF : *p1++;}
template<class T>inline void rd(T & x){ x = 0;char ch = nc();for(;!isdigit(ch);ch = nc()); for(;isdigit(ch);ch = nc()) x = x * 10 - 48 + ch;}

typedef long long ll;

const int maxn = 600 + 10;
const int mod = 1e9 + 7;

int f[maxn][maxn] , g[maxn][maxn] , h[maxn] , a[maxn] , b[maxn];

template<class T>inline T add(T a,T b){ a += b; if(a > mod) a -= mod; return a;}
template<class T>inline T sub(T a,T b){ a -= b; if(a < 0) a += mod; return a;}
template<class T>inline T mul(T a,T b){ return (ll)a * b % mod;}


int main(){
	int n,m;
	rd(n); rd(m);
	for(int i = 1;i <= m;i++){
		rd(a[i]);
		rd(b[i]);
	}	
	h[0] = 1;
	for(int i = 1;i <= n;i++) h[i] = mul(h[i - 1],(i << 1) - 1);
	int ans = 0;
	for(int l = n * 2;l;l--){
		for(int r = l + 1;r <= n * 2;r += 2){
			bool flag = 1;
			int in = 0;
			for(int i = 1;i <= m;i++){
				int t = (a[i] >= l && a[i] <= r) + (b[i] >= l && b[i] <= r);
				if(t == 1){
					flag = 0;
					break;
				}
				if(t) in++;
			}
			if(flag){
				in = (r - l + 1 >> 1) - in;
				int out = n - m - in;
				f[l][r] = g[l][r] = h[in];
				for(int i = l + 1;i < r;i += 2){
					f[l][r] = sub(f[l][r],mul(f[l][i],g[i + 1][r]));
				}
				ans = add(ans,mul(f[l][r],h[out]));
			}
		}
	}
	printf("%d\n",ans);
}
 

Measured memory_bytes: 3072
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		String str = scan.nextLine();
		String[] distance = str.split(" ");
		double x = Math.abs(Double.parseDouble(distance[0]) - Double.parseDouble(distance[2]));
		double y = Math.abs(Double.parseDouble(distance[1]) - Double.parseDouble(distance[3]));
		double ans = Math.pow((Math.pow(x, 2) + Math.pow(y, 2)), 0.5);
		System.out.printf("%.8f",ans);
		

	}

}

Measured memory_bytes: 17164
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <string>
#include <sstream>
#include <complex>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
#include <iomanip>
using namespace std;
typedef long long ll;
template<typename T> using min_priority_queue = priority_queue<T, vector<T>, greater<T>>;

#define EPS (1e-7)
#define INF (1e15)
#define PI (acos(-1))
#define MOD 1000000007

#define REP(i,n) for(int i=0;i<n;i++)
#define REPS(i,f,n) for(int i=(f);i<(n);i++)
#define EACH(it,v) for(__typeof((v).begin()) it=(v).begin();it!=(v).end();it++)

#define dump(x)  cout << #x << " = " << (x) << endl;
#define debug(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;
#define arrdump(n,a) for(int i=0;i<n;i++) {cout<<((i>0)? " ":"")<<a[i];}cout<<"\n";


typedef pair<int, int> P;
typedef pair<ll, ll> LP;
typedef pair<int, P> PP;
typedef pair<ll, LP> LPP;

int dy4[]={0, 0, 1, -1};
int dx4[]={1, -1, 0, 0};
int dx8[]={0, 0, 1, -1, 1, 1, -1, -1};
int dy8[]={1, -1, 0, 0, 1, -1, -1, 1};

// https://atcoder.jp/contests/abc045/tasks/arc061_a

int main() {
    string S; cin >> S;
    int len = S.length();

    ll ans = 0;
    for (int msk = 0; msk < 1 << (len-1); msk++) {
        ll num = S[0] - '0';
        for (int i = 0; i < len-1; i++) {
            if (msk & 1 << i) {
                ans += num;
                num = 0;
            }
            num = num * 10 + (S[i+1] - '0');
        }
        ans += num;
    }

    cout << ans << "\n";

    return 0;
}


Measured memory_bytes: 256
//in the name of ALLAH
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int main()
{
    ll n;
    cin>>n;
    ll a[n];
    set<ll>s,s1;
    set<ll>:: iterator it;
    vector<ll>v,v1;
    for(int i=0;i<n;i++)
    {
        cin>>a[i];
        s.insert(a[i]);
    }
    sort(a,a+n);
    ll c=0,ans=0,ans1=0;
    if(s.size()==n)
        ans=0;
    else
    {
        for(it=s.begin();it!=s.end();it++)
        {
            int u=upper_bound(a,a+n,*it)-a;
            int l=lower_bound(a,a+n,*it)-a;
            c=u-l;
            if(c>=2)
                v.push_back(*it);
                if(c>=4)
                    v1.push_back(*it);
        }
        sort(v.begin(),v.end());
        sort(v1.begin(),v1.end());
        if(v.size()>=2)
        {
            ans=v[v.size()-1]*v[v.size()-2];
        }
        if(v1.size()>=1)
        {
            ans1=v1[v1.size()-1]*v1[v1.size()-1];
        }
        ans=max(ans1,ans);
        //cout<<ans1<<endl;

    }
    cout<<ans<<endl;
}



Measured memory_bytes: 8960
use strict;
use warnings;

main();

sub main{
	my $in = <STDIN>;
	
	(my $A, my $B) = split(/ /, $in);
	my $mul = $A * $B;
	if($mul%2){ print "Odd\n"}
	else{ print "Even\n"}

	# printf "> %d\n", $mul;	
	# printf ">> %d\n", $mul%2;	
	1;
}

Measured memory_bytes: 640
#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 pb emplace_back
#define mk make_pair

int n;
vector<string> a;
vector<int> b;
vector<vector<string>> d;
vector<vector<int>> g;
vector<long long> e;

typedef long long ll;

int dfs(int i, ll s) {
	if(i == n) {
		return 0;
	}

	if((s >> i) & 1) {
		return dfs(i + 1, s);
	}

	int ret = 0;
	ll mask = (1LL << n) - 1;
	mask = mask - ((1LL << i) - 1);
	
	if(i != 0 && !((s & e[i] & mask) == (e[i] & mask))) {
		ret = dfs(i + 1, s);
	}

	{
		ll ns = s | e[i];

		ret = max(ret, dfs(i + 1, ns) + b[i]);
	}

	return ret;
}

int main(){
	while(true) {
		cin >> n;
		if(n == 0) {
			break;
		}

		a = vector<string>(n);
		b = vector<int>(n);
		d = vector<vector<string>>(n);
		e = vector<long long>(n);
		rep(i, n) {
			int c;
			cin >> a[i] >> b[i] >> c;
			d[i].resize(c);

			rep(j, c) {
				cin >> d[i][j];
			}
		}

		map<string, int> m;
		rep(i, n) {
			m.insert(make_pair(a[i], m.size()));
		}

		g = vector<vector<int>>(n);

		rep(i, n) {
			for(auto to : d[i]) {
				g[i].push_back(m[to]);
				e[i] = e[i] | (1LL << g[i].back());
			}
		}

		cout << dfs(0, 0) << endl;
	}
	
	return 0;
}


Measured memory_bytes: 3348
#include <iostream>
#include <string>

using namespace std;

int main() {
    string s;
    cin >> s;
    string key = "keyence";

    bool flag = false;
    for (int i = 0; i <= 7; i++) {
        if (s.substr(0, i) == key.substr(0, i)
                && s.substr(s.length()-(7-i), 7-i) == key.substr(i, 7-i)) {
            flag = true;
        }
    }

    cout << (flag ? "YES" : "NO") << endl;

    return 0;
}

Measured memory_bytes: 256
#include <stdio.h>

int
main ()
{
  int n;
  float x1, y1, x2, y2, x3, y3, x4, y4;
  scanf("%d\n", &n);
  
  while (n--){
    scanf ("%f %f %f %f %f %f %f %f\n", &x1, &y1, &x2, &y2, &x3, &y3, &x4, &y4);
    
    if (x1 == x2 && x3 == x4)
      {
	printf ("YES\n");
      }
    else if ((x1 == x2 && x3 != x4) || (x1 != x2 && x3 == x4))
      {
	printf ("NO\n");
      }
    else
      {
	if((y1 - y2) / (x1 - x2) ==  (y3 - y4) / (x3 - x4))
	  {
	    printf ("YES\n");
	  }
	else
	  {
	    printf ("NO\n");
	  }
      }
  }
  return 0;
}



Measured memory_bytes: 2044
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ

		Scanner sc = new Scanner(System.in);

		int N = sc.nextInt();
		int A = sc.nextInt();
		int c = N % 500;

		if (A >= c) {
			System.out.println("Yes");

		} else {

			System.out.println("No");

		}
	}

}


Measured memory_bytes: 21844
using System;
class Program
{
    static void Main(string[] args)
    {
        char[] s = Console.ReadLine().ToCharArray();
        char[] t = Console.ReadLine().ToCharArray();

        int count = 0;

        for (int i = 0; i < s.Length; i++)
        {
            if (s[i] != t[i])
            {
                count++;
            }
        }

        Console.WriteLine(count);
    }
}


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

int main(){
  int n,k,x,y;
  cin >> n;
  cin >> k;
  cin >> x;
  cin >> y;
  if(n <= k){
    cout << n*x << endl;
  }else{
    cout << k*x+(n-k)*y << endl;
  }
}

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

int sentou_matubi[10][10];

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

    for (int i = 1; i <= n; ++i) {
        int ketasu =
            i < 10 ? 1
                   : i < 100
                         ? 10
                         : i < 1000
                               ? 100
                               : i < 10000 ? 1000 : i < 100000 ? 10000 : 100000;
        int sentou = i / ketasu;
        int matubi = i % 10;
        sentou_matubi[sentou][matubi]++;
    }

    long long ans = 0LL;
    for (int i = 1; i <= 9; ++i) {
        for (int j = 1; j <= 9; ++j) {
            int ij = sentou_matubi[i][j];
            int ji = sentou_matubi[j][i];
            ans += ij * ji;
        }
    }

    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(){
    int  x1,x2;
    cin>>x1>>x2;
    if(x1<x2){
        cout<<x2-x1<<endl;
        }else if(x1>x2){
            cout<<x1-x2<<endl;
        }else{
            cout<<"0"<<endl;
        }

}


Measured memory_bytes: 3108
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for (int i = 0;i < (int)(n);i++)
using ll = long long;
const ll MOD=1000000007;
//const ll MOD=998244353;
const long long INF = 1LL << 60;
const double pi=acos(-1.0);

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



int main()
{
  ll N; cin>>N;
  vector<string> vec(N); rep(i,N) cin>>vec[i];
  
  ll ans=0;
  ll numB=0,numA=0,numBA=0;
  for(auto str:vec){
    ll n=str.size();
    rep(i,n-1) if(str.substr(i,2)=="AB") ans++;
    if(str[0]=='B'&&str[n-1]=='A') {numBA++; continue;}
    if(str[0]=='B') numB++;
    if(str[n-1]=='A') numA++;
  }
  ll alpha=max(numBA-1,(ll)0);
  if(numBA>0){
    if(numA>0) {alpha++; numA--;}
    if(numB>0) {alpha++; numB--;}
  }
  alpha+=min(numA,numB);
  
  cout<<ans+alpha<<endl;
  
  return 0;
}

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

int main() {
	int n;
	cin>>n;
	vector<vector<int>> a(n,vector<int>(3));
	for(int i=0;i<n;i++){
		for(int j=0;j<3;j++){
			cin>>a[i][j];
		}
	}
	vector<vector<int>>dp(100010,vector<int>(3));
	for(int i=0;i<n;i++){
		for(int j=0;j<3;j++){
			for(int k=0;k<3;k++){
				if(j!=k){
					dp[i+1][j] = max(dp[i+1][j],dp[i][k] + a[i][j]);
				}
			}
		}
	}
	cout<<max(max(dp[n][0],dp[n][1]),dp[n][2])<<endl;
}


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

struct edge { int to, cost; };
typedef pair<int, int> P;
typedef pair<string, int> SP;
#define rep(i, n) for(int i = 0; i < n; ++i)

const int INF = 1e9 + 7;
using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vvvi = vector<vvi>;

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    // vvvi V (50, vvi(50, vi(2500)));

    int S, W;
    cin >> S >> W;
    if(W >= S){
        cout << "unsafe" << endl;
    }
    else{
        cout << "safe" << endl;
    }

    return 0;
}

Measured memory_bytes: 3652
package main

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

func GCD(a, b int) int {
	if a%b == 0 {
		return b
	}
	return GCD(b, a%b)
}

var scanner = bufio.NewScanner(os.Stdin)

func init() {
	scanner.Split(bufio.ScanWords)
}

func ScanInt() int {
	scanner.Scan()
	t := scanner.Text()
	n, _ := strconv.Atoi(t)
	return n
}

func main() {
	n := ScanInt()
	gcd := ScanInt()
	for i := 1; i < n; i++ {
		gcd = GCD(gcd, ScanInt())
	}
	fmt.Println(gcd)
}


Measured memory_bytes: 3400
while True:
    n, x = map(int, input().split())
    count = 0
    if n == 0 and x == 0:
        break

    for a in range(1, n + 1):
        for b in range(1, n + 1):
            for c in range(1, n + 1):
                if a + b + c == x and a > b > c:
                    count += 1
                else:
                    continue
    print(count)



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

using namespace std;

#define pb push_back
#define pp pop_back
#define mp make_pair
#define F first
#define S second
#define xmax(x,y) ((x) = max((x),(y)))
#define xmin(x,y) ((x) = min((x),(y)))
#define all(x) (x).begin(),(x).end()
#define mem(x) memset(x , 0 , sizeof(x))
#define _ ios_base::sync_with_stdio(false),cin.tie(NULL),cout.tie(NULL);
#define FP(a , b , c)  for(ll (a) = (b) ; (a) < (c) ; (a++));
#define FM(a , b , c)  for(ll (a) = (b) ; (a) >= (c) ; (a--));
#define connect(a , b , c) a[b].pb(c) , a[c].pb(b)

typedef long long int ll;
typedef unsigned long long int ull;
typedef string str;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef vector <ll> vl;
typedef vector <int> vi;
typedef vector <string> vs;

const ll Maxn3 = 1e3 + 10;
const ll Maxn4 = 1e4 + 10;
const ll Maxn5 = 1e5 + 10;
const ll Maxn6 = 1e6 + 10;
const ll Maxn7 = 1e7 + 10;
const ll Maxn8 = 1e8 + 10;
const ll Maxn9 = 1e9 + 10;
const ll Maxn18 = 1e18 + 10;
const ll Mod1 = 1e7 + 7;
const ll Mod2 = 1e9 + 7;
const ll LLMax = LLONG_MAX;
const ll LLMin  = LLONG_MIN;
const ll INTMax = INT_MAX;
const ll INTMin  = INT_MIN;

ll mn = LLMax , mx = LLMin;
ll t[5];
int main()
{_
    ll n , res = 0 , s = 0; cin >> n; str d;
    for(ll i = 0 ; i < n ; i++)
    {
        cin >> d;
        if(d[0] == 'M') t[0]++;
        if(d[0] == 'A') t[1]++;
        if(d[0] == 'R') t[2]++;
        if(d[0] == 'C') t[3]++;
        if(d[0] == 'H') t[4]++;
    }
    for(ll i = 0 ; i < 5 ; i++)
        if(t[i] != 0) res++;
    if(res == 0) return cout << 0 , 0;
    for(ll i = 0 ; i < 5 ; i++)
        if(t[i])for(ll j = i + 1 ; j < 5 ; j++)
            if(t[j])for(ll k = j + 1 ; k < 5 ; k++)
                if(t[k]) s += (t[i] * t[j] * t[k]);
    return cout << s , 0;
}
///SAliB


Measured memory_bytes: 256
#import torch
class solution(object):

    def __init__(self, D: int, T: int, S: int)-> None:
        self.D = D
        self.T = T
        self.S = S
    
    def solve(self)->bool:
        return ['No','Yes'][(self.D/self.S) <= self.T]
    
if __name__=='__main__':
    # x = int(input())
    D,T,S= map( int , input().split())
    problem = solution(D, T, S)
    ans = problem.solve()
    print(ans)


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

int main(){
    int a, b;
    cin >> a >> b;
    int c = (a + b + 1)/ 2;
    cout << c << endl;
}

Measured memory_bytes: 256
N, A, B, C = map(int, input().split())
L = []
INF = float('inf')
for i in range(N):
    L.append(int(input()))


def dfs(k, a, b, c):
    if k == N:
        if min(a, b, c) == 0:
            return INF
        else:
            return abs(A - a) + abs(B - b) + abs(C - c) - 30
    else:
        d0 = dfs(k + 1, a, b, c)
        d1 = dfs(k + 1, a + L[k], b, c) + 10
        d2 = dfs(k + 1, a, b + L[k], c) + 10
        d3 = dfs(k + 1, a, b, c + L[k]) + 10
        return min(d0, d1, d2, d3)


print(dfs(0, 0, 0, 0))



Measured memory_bytes: 3064
#[allow(unused_imports)]
use proconio::marker::{Bytes, Chars, Usize1};
use proconio::{fastout, input};
#[fastout]
fn main() {
    input! {
        n: usize,
        x_ori : [usize; n]
    }
    let mut x = x_ori.clone();
    x.sort();
    for i in 0..n {
        if x_ori[i] >= x[n / 2] {
            println!("{} ", x[(n - 1) / 2]);
        } else {
            println!("{} ", x[n / 2]);
        }
    }
}


Measured memory_bytes: 7664
#include <iostream>
#include <cstring>
using namespace std;
#define rep(i,n) for(int i=0;i<(n);++i)
string s;
int memo[500][501];
bool cat(int l,int r){
	if(memo[l][r]!=0) return memo[l][r]>0;
	int sz=r-l;
	if(sz==0) return true;
	string t=s.substr(l,sz);
	if(t[0]!='m' || t[sz-1]!='w'){
		memo[l][r]=-1;
		return false;
	}
	bool ok=false;
	rep(i,sz){
		if(t[i]!='e') continue;
		if(cat(l+1,l+i) && cat(l+i+1,r-1)) ok=true;
	}
	memo[l][r]=(ok ? 1 : -1);
	return ok;
}
int main(){
	cin >> s;
	cout << (cat(0,s.size()) ? "Cat\n" : "Rabbit\n");
	return 0;
}

Measured memory_bytes: 2004
/**********************************************************************************************
******************************AUTHOR:**********************************************************
****************************ASHISH RANJAN******************************************************
***********************************************************************************************/
#include<iostream>
#include<algorithm>
#include<cmath>
#include<chrono>
#include<vector>
#include<string>
#include<cstring>
using namespace std;
using namespace std::chrono;
/*
auto start = high_resolution_clock::now();
auto stop = high_resolution_clock::now();
  auto duration = duration_cast<microseconds>(stop - start); 
  
    cout << "Time taken by function: "
         << duration.count() << " microseconds" << endl;
*/
#define fast() ios_base::sync_with_stdio(false);cin.tie(NULL)
#define ll long long
#define mod 1000000007
#define fr(i,n) for(int i=0;i<n;i++)
#define frs(i,a,b) for(int i = a;i<b;i++)
#define meme(a,b,c) memset(a,b,sizeof(c)); //works only for 0 and -1
int main(){
  fast();
string s,t;
cin>>s>>t;
int total=0;
fr(i,s.size()){
   if(s[i]!=t[i])total++;
}
cout<<total;

 return 0;
}


Measured memory_bytes: 3788
#include <iostream>
//#include <iomanip>
//#include <algorithm>
//#include <numeric>
//#include <queue>
//#include <stack>
//#include <math.h>
#include <vector>
//#include <unordered_map>
//#include <string>
typedef long long LL;
//typedef long double LD;
using namespace std;
vector<LL> p;
vector<LL> burger;

LL eat_burger(int n_in, LL x_in){
    if(n_in==0){
        if(x_in<=0){
            return 0;
        }else{
            return 1;
        }
    }else if(x_in<=burger[n_in-1]+1){
        //cout << "test1 " << x_in << " " << burger[n_in-1]+1 << endl;
        return eat_burger(n_in-1, x_in-1);
    }else{
        //cout << "test2 " << x_in << " " << burger[n_in-1]+1 << " " << x_in-2-burger[n_in-1] << endl;
        return p[n_in-1] + 1 + eat_burger(n_in-1, x_in-2-burger[n_in-1]);
    }
}

int main() {
    int n;
    LL x;
    LL tmp_p;
    LL tmp_burger;
    LL ans;
    cin >> n >> x;

    p.push_back(1);
    burger.push_back(1);
    for(int i=0; i<n; i++){
        tmp_p = p[i]*2 + 1;
        tmp_burger = burger[i]*2 + 3;
        p.push_back(tmp_p);
        burger.push_back(tmp_burger);
    }

    ans = eat_burger(n, x);
    cout << ans << endl;
}

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

using namespace std;

using ll = long long;

#define ALL(A) A.begin(),A.end()

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

    vector<int> A(N);
    for(int i=0;i<N;i++)
    {
        cin >> A.at(i);
    }

    int counter = 0;

    for(int i=0;i<N;i++)
    {
        int j=A.at(i);
        if(A.at(j-1)==i+1)
        {
            counter++;
        }
    }

    cout << counter / 2 << endl;

    return 0;
}

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

int main()
{
	int N,M;
	int Nt[100],Mt[100];
	int a,b;
	cin >> N;
	for(int i = 0;i < N;i++){
		cin >> a >> b;
		Nt[i] = a *60 + b;
	}
	cin >> M;
	for(int i = 0;i < M;i++){
		cin >> a >> b;
		Mt[i] = a * 60 + b;
	}
	int i = 0,j = 0;
	while(1){
		if(j == M ||(i != N && Nt[i] < Mt[j])){
			cout << Nt[i]/60 << ':' << setw(2) << setfill('0') << Nt[i]%60;
			i++;
		}else if(i == N ||(j != M && Mt[j] < Nt[i])){
			cout << Mt[j]/60 << ':' << setw(2) << setfill('0') << Mt[j]%60;
			j++;
		}else if(Nt[i] && Mt[j]){
			cout << Nt[i]/60 << ':' << setw(2) << setfill('0') << Nt[i]%60;
			i++;
			j++;
		}
		if(i == N && j == M){
			cout << endl;
			break;
		}
		cout << ' ';
	}
	return 0;
}


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

int main() {
  string a;
  cin>>a;
  if(a[0]==a[1]){
    cout<<"Bad";
  }else if(a[1]==a[2]){
    cout<<"Bad";
  }else if(a[2]==a[3]){
    cout<<"Bad";
  }else{
    cout<<"Good";
  }
	return 0;
}


Measured memory_bytes: 3532
n = gets.to_i

n.times do
  ax, ay, bx, by, cx, cy = gets.split.map(&:to_f)
  a1 = 2 * (bx - ax)
  b1 = 2 * (by - ay)
  c1 = ax * ax - bx * bx + ay * ay - by * by
  a2 = 2 * (cx - ax)
  b2 = 2 * (cy - ay)
  c2 = ax * ax - cx * cx + ay * ay - cy * cy;

  px = (b1 * c2 - b2 * c1) / (a1 * b2 - a2 * b1)
  py = (c1 * a2 - c2 * a1) / (a1 * b2 - a2 * b1)

  r = Math.sqrt((px - ax) * (px - ax) + (py - ay) * (py - ay))

  printf "%.3f %.3f %.3f\n", px, py, r
end


Measured memory_bytes: 6888
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.StringTokenizer;

public class Main {

    private static class FastReader {
        BufferedReader br;
        StringTokenizer st;

        public FastReader() {
            br = new BufferedReader(new InputStreamReader(System.in));
        }

        String next() {
            while (st == null || !st.hasMoreElements()) {
                try {
                    st = new StringTokenizer(br.readLine());
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
            return st.nextToken();
        }

        int nextInt() {
            return Integer.parseInt(next());
        }

        long nextLong() {
            return Long.parseLong(next());
        }

        double nextDouble() {
            return Double.parseDouble(next());
        }

        String nextLine() {
            String str = "";
            try {
                str = br.readLine();
            } catch (IOException e) {
                e.printStackTrace();
            }
            return str;
        }
    }

    private static final int[] a = { 1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5,
            4, 1, 4, 1, 51 };

    public static void main(final String[] args) throws IOException {
        FastReader in = new FastReader();
        PrintWriter out = new PrintWriter(System.out, true);

        int k = in.nextInt();
        out.println(a[k - 1]);
    }
}


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

ll max2val(ll a, ll b) {
    if (a > b) {
        return a;
    }
    else {
        return b;
    }
}

int main() {
 ll X;
 cin>>X;
 if(30<=X){
     cout<<"Yes"<<endl;
 }else{
     cout<<"No"<<endl;
 }
 }



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

int main()
{
	while (true) {
		int n, m;

		cin >> n >> m;

		if (n == 0 && m == 0) {
			break;
		}

		vector<int> taro, hanako;
		int t_sum = 0, h_sum = 0;

		for (int i = 0; i < n; i++) {
			int temp;
			cin >> temp;
			taro.push_back(temp);
			t_sum += temp;
		}

		for (int i = 0; i < m; i++) {
			int temp;
			cin >> temp;
			hanako.push_back(temp);
			h_sum += temp;
		}

		int t = 1000, h = 1000;

		for (int i = 0; i < n; i++) {
			for (int j = 0; j < m; j++) {
				int t_sum2 = t_sum;
				int h_sum2 = h_sum;

				t_sum2 = t_sum2 - taro[i] + hanako[j];
				h_sum2 = h_sum2 - hanako[j] + taro[i];

				if (t_sum2 == h_sum2) {
					if (taro[i] + hanako[j] < t + h) {
						t = taro[i];
						h = hanako[j];
					}
				}
			}
		}

		if (t == 1000 && h == 1000) {
			cout << -1 << endl;
		}
		else {
			cout << t << " " << h << endl;
		}
	}

	return 0;
}

Measured memory_bytes: 3016
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        char c = sc.next().charAt(0);
        if (c == 'a' || c == 'e' || c == 'i' || c == 'o' || c == 'u') {
            System.out.println("vowel");
        } else {
            System.out.println("consonant");
        }
    }
}


Measured memory_bytes: 22996
using System;
using System.Linq;

namespace ConsoleApp1
{
    class Program
    {
        static void Main(string[] args)
        {
            int[] inp = Array.ConvertAll(Console.ReadLine().Split(' '), int.Parse);
            Console.WriteLine(inp.Sum() > 21 ? "bust" : "win");
        }
    }
}


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

int q;

int main(void){
    
    cin >> q;
    for(int i = 0; i < q; ++i){
        string a, b; cin >> a >> b;
        vector<vector<int>> dp(1001, vector<int>(1001, 0));
        
        for(int i = 1; i <= a.size(); ++i){
            for(int j = 1; j <= b.size(); ++j){
                dp[i][j] = max({dp[i - 1][j - 1] + (a[i - 1] == b[j - 1] ? 1 : 0), dp[i - 1][j], dp[i][j - 1]});
            }
        }
        
        cout << dp[a.size()][b.size()] << endl;
        
    }
    
    return 0;
}



Measured memory_bytes: 6920
#include<iostream>
#include<algorithm>
#include<math.h>
#include<vector>
#include<map>
#include<set>

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

using namespace std;
using ll = long long;
using ull = unsigned long long;

int N, M, Q;
vector<int> a, b, c, d;
int ans;

void dfs(vector<int> A) {
    // 配列 A が N 個揃ったら得点の判定をおこない，処理を終了する
    if (A.size() == N + 1) { // 初期値を A_0 ＝1 としたため + 1 する
        int now = 0;
        rep(i, Q) {
            if (A[b[i]] - A[a[i]] == c[i]) now += d[i]; 
        }
        ans = max(ans, now);
        return;
    }

    // 配列 A が N 個揃うまでは配列を追加する
    A.push_back(A.back());

    while (A.back() <= M) {
        dfs(A);
        A.back()++; // 最後の要素に 1 追加
    }
}

int main() {
    cin >> N >> M >> Q;

    a = vector<int>(Q);
    b = vector<int>(Q);
    c = vector<int>(Q);
    d = vector<int>(Q);
    rep(i, Q) cin >> a[i] >> b[i] >> c[i] >> d[i];

    dfs(vector<int>(1, 1));  // dfs の最初の A.back() でエラーとならないよう初期値を設定

    cout << ans << endl;
    return 0;
}



Measured memory_bytes: 3604
N, K = map(int, input().split())
snuke = [0] * N
for n in range(K):
    snack = int(input())
    d_snuke = map(int, input().split())
    for d in d_snuke:
        snuke[d-1] = snack
c = 0
for n in range(N):
    if snuke[n] == 0:
        c += 1
print(c)

Measured memory_bytes: 9172
#include<iostream>
#include<set>
#include<algorithm>
#include<queue>
#include<string>
using namespace std;
#define REP(i,b,n) for(int i=b;i<n;i++)
#define rep(i,n)   REP(i,0,n)
string edge[10][2];

string substitute(string tar,string &from,string &to){
  string ret;
  for(int i=0;i<tar.size();i++){
    bool flag=true;
    rep(j,from.size()){
      if ( i+j == tar.size()){flag=false;break;}
      if ( from[j]!=tar[i+j]){flag=false;break;}
    }
    if ( flag == false)ret+=tar[i];
    else {
      ret+=to;
      i+=from.size()-1;
    }
  }
  return ret;
}

int bfs(string &start,string &goal,int n){
  queue<pair<string,int> > Q;
  set<string>S;
  Q.push(make_pair(start,0));
  S.insert(start);
  while(!Q.empty()){
    pair<string,int> now =Q.front();
    Q.pop();
    if ( now.first == goal)return now.second;
    rep(i,n){
      string next = substitute(now.first,edge[i][0],edge[i][1]);
      if ( S.find(next) == S.end() && next.size()<= goal.size()){
	S.insert(next);
	Q.push(make_pair(next,now.second+1));
      }
    }
    
  }
  return -1;
}


main(){

  int n;
  while(cin>>n && n){
    string start,goal;
    rep(i,n)cin>>edge[i][0]>>edge[i][1];
    cin>>start>>goal;
    cout << bfs(start,goal,n) <<endl;
  }
}

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

public class Main 
{
	static long gcd(long a, long b) 
    { 
        if (a == 0) 
            return b; 
        return gcd(b % a, a); 
    } 
	
	static long GCD(long A, long B, long C)
	{
		long Result = A;
		Result = gcd(Result, B);
		Result = gcd(Result, C);
		return Result;
	}
	public static void main(String[] Arguments) throws IOException 
	{
		BufferedReader BR = new BufferedReader(new InputStreamReader(System.in));
		long K = Long.parseLong(BR.readLine()), Sum = 0;
		for (long i = 1; i <= K; i++)
			for (long j = 1; j <= K; j++)
				for (long k = 1; k <= K; k++)
					Sum += GCD(i, j, k);
		System.out.println(Sum);
	}
}


Measured memory_bytes: 25924
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;

bool Check(vector<int> vec,int c){
    
    for(int i=0;i<vec.size();i++){if(vec[i] == c) return false;}
    return true;
}
int main(){
    
    int N,M,a,b,ans=0; cin >> N >> M;
    vector<vector<int>> data(N+1);
    vector<int> one_case;
    for(int i=0;i<M;i++){
        cin >> a >> b;
        if(Check(data.at(a),b)) data.at(a).push_back(b);
        if(Check(data.at(b),a)) data.at(b).push_back(a);
    }
    for (int i=1;i<=N;i++) { one_case.emplace_back(i); }
    
    do {
        for(int i=0;i<N-1;i++){
            if(one_case[0] != 1)break;
            
            if(Check(data.at(one_case[i]),one_case[i+1]) == true) break;
            
            if(i == N-2) ans++;
        }
    } while (next_permutation(one_case.begin(), one_case.end()));
    
    cout << ans << endl;
}

Measured memory_bytes: 3612
def chess(h, w)
  for i in 1..h
      for n in 1..w
          if (i+n)%2 == 1
              print "."
          else
              print "#"
          end
      end
      puts "\n"
  end
  puts "\n"
end

loop {
  h, w = gets.split(" ").map(&:to_i)
  if h == 0 && w == 0
    break
  end
  chess(h, w)
}

Measured memory_bytes: 8656
#include <algorithm>
#include <cassert>
#include <cstring>
#include <iostream>

using namespace std;

#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i, n) FOR(i, 0, n)
#define TRACE(x) cout << #x << " = " << x << endl
#define _ << " _ " <<

typedef long long llint;

const int MAX = 20020;

int a[MAX], b[MAX], s[MAX];

int main(void) {
  int n;
  scanf("%d", &n);
  REP(i, n) {
    int x;
    scanf("%d", &x); --x;
    s[x] = i;
  }

  a[0] = 1;
  b[0] = s[0] - 1;
  for (int i = 1; i < n; ++i) {
    a[i] = a[i-1] + 1;
    b[i] = b[i-1] - 1;
    if (a[i] + b[i] < s[i]) {
      a[i] += s[i] - (a[i] + b[i]);
    } else {
      b[i] += s[i] - (a[i] + b[i]);
    }
  }

  int off = *min_element(b, b + n);
  REP(i, n) b[i] = b[i] - off + 1;

  REP(i, n) printf("%d ", a[i]); printf("\n");
  REP(i, n) printf("%d ", b[i]); printf("\n");
  return 0;
}


Measured memory_bytes: 768
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define rep(i,n) for(int i=0;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define rep2(i,n) for(int i=0;i<=n;i++)
#define repr(i,a,n) for(int i=a;i<n;i++)
#define all(a) a.begin(),a.end()
#define P pair<long long,long long>
#define double long double
#define INF 1e10
#define MOD 1e9+7
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 Graph = vector<vector<int>>;
int fg(int k){
    int sum = 1;
    for (int i = 1; i <= k; ++i)
    {
        sum *= i;
    }
    return sum;
}
signed main(){
  int n,k;
  cin>>n>>k;
  int x=n%k;
  cout<<min(x,k-x);
}


Measured memory_bytes: 256
#pragma GCC optimize ("O2")
#pragma GCC diagnostic ignored "-Wunused-variable"
#pragma GCC diagnostic ignored "-Wunused-result"
#pragma GCC diagnostic ignored "-Wunused-label"
#pragma GCC diagnostic ignored "-Wsign-compare"

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

#define trav(a, A) for (auto & a : A)
#define f first
#define s second

typedef long long ll;

const ll MOD = 1e+9+7;
const ll INFLL = 0x3f3f3f3f3f3f3f3f;
const int INF = 0x3f3f3f3f;
const ll MAXN = 1e+5+7;

int main ()
{
	ios_base::sync_with_stdio (0);
	cin.tie (0);
	int tc = 1; //cin >> tc;
	while (tc--)
	{
		int i, j, n, a, b;
		cin >> a >> b;
		bool ans = false;
		for (i = 0; i < 1e8; ++i)
			if (i*8/100 == a && i*10/100 == b)
			{
				ans = true;
				cout << i << '\n';
				break;
			}
		if (!ans) cout << "-1\n";
		
	}

	return 0;
}



Measured memory_bytes: 256
N, D=map(int, input().split())
x=[list(map(int, input().split())) for i in range(N)]
cnt=0
d=0
for i in range(N-1):
    for j in range(i+1, N):
        for k in range(D):
            d+=(x[i][k]-x[j][k])**2
        if (d**(1/2))%1==0:
            cnt+=1
        d=0
print(cnt)

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

#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define rep(i,n) FOR(i,0,n)
#define RFOR(i,a,b) for(int i=(a)-1;i>=(b);i--)
#define rrep(i,n) RFOR(i,n,0)

using namespace std;

typedef long long ll;
typedef unsigned long long ull;

const ll MOD = 1e9 + 7;
const ll max_n = 200003;
ll fact[max_n];
bool fact_init = false;

ll pow(ll a, ll b){
	if(b == 0) return 1;
	if(b % 2 == 1) return a * pow(a, b - 1) % MOD;

	ll d = pow(a, b / 2) % MOD;
	return d * d % MOD;
}

ll comb(ll n, ll k){
	if(!fact_init){
		fact[0] = 1;
		fact[1] = 1;

		for(ll i = 2; i<=max_n; i++){
			fact[i] = fact[i-1] * i;
			fact[i] %= MOD;
		}

		fact_init = true;
	}

	ll ret = fact[n];
	ret *= pow(fact[k],MOD-2);
	ret %= MOD;
	ret *= pow(fact[n-k],MOD-2);
	ret %= MOD;
	return ret;

	// X^(-1) = X^(p-2) (mod p) (Fermat's little theorem)
}


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

	ll n, m;
	cin >> n >> m;

	vector<ll> es;
	ll maxp = sqrt(m) + 1;
	for(ll p = 2; p <= maxp; p++){
		ll e = 0;
		while(m % p == 0){
			m /= p;
			e++;
		}
		if(e > 0) es.push_back(e);
	}

	if(m != 1) es.push_back(1);

	ll ans = 1;
	for(ll e : es){
		ans *= comb(n + e - 1, e);
		ans %= MOD;
	}

	// for(int i =1 ;i <= 10000;i++) cout << fact[i] << endl;
	cout << ans << endl;
}


Measured memory_bytes: 1792