akhauriyash/Code-Regression huggingface dataset:
#include <stdio.h>
#include <algorithm>
int n, m, l, k, x, y, ans, g;
int a[18], b[18];
int t[18];
int te[18];
int rui[20];
int p[18], q[18];
int pn, qn;
int main() {
	ans = 1000000000;
	rui[0] = 1;
	for (int i = 1; i < 20; i++)rui[i] = rui[i - 1] * 2;
	scanf("%d", &n);
	for (int i = 0; i < n; i++) {
		scanf("%d", a + i);
	}
	for (int i = 0; i < n; i++) {
		scanf("%d", b + i);
	}
	for (int i = 0; i < n; i++) {
		if (i % 2) {
			x = a[i];
			a[i] = b[i];
			b[i] = x;
		}
	}
	l = n / 2;
	m = n - l;
	for (int i = 0; i < rui[n]; i++) {
		l = i;
		k = 0;
		for (int j = 0; j < n; j++) {
			t[j] = l % 2;
			l /= 2;
			if (t[j])k++;
		}
		if (k == m) {
			pn = 0; qn = 0; x = 0;
			for (int j = 0; j < n; j++) {
				if (t[j]) {
					p[pn] = a[j] * 100 + j;
					pn++;
				}
				else {
					q[qn] = b[j] * 100 + j;
					qn++;
				}
			}
			std::sort(p, p + pn);
			std::sort(q, q + qn);
			for (int j = 0; j < pn; j++) {
				te[p[j] % 100] = 2 * j;
			}
			for (int j = 0; j < qn; j++) {
				te[q[j] % 100] = 2 * j + 1;
			}
			for (int j = 0; j < n; j++) {
				for (int o = j + 1; o < n; o++) {
					if (te[o] < te[j])x++;
				}
			}
			g = 1;
			for (int j = 0; j < pn - (n % 2); j++) {
				if ((p[j] / 100) > (q[j] / 100))g = 0;
			}
			for (int j = 0; j < qn - ((n + 1) % 2); j++) {
				if ((q[j] / 100) > (p[j + 1] / 100))g = 0;
			}
			if (g && ans > x)ans = x;
		}
	}
	if (ans == 1000000000)printf("-1\n");
	else printf("%d\n", ans);
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define f first
#define s second
#define mp make_pair
#define ll long long 

int main () {
	int i,j,k,l,n,m,h,w,ans,num_part,ar[10][1003];
	cin>>h>>w>>k;
	ans = h*w;
	vector<int> part,sums;
	string s[10];
	for(i=0;i<h;i++)
		cin>>s[i];
	for(i=0;i<h;i++)
		for(j=0;j<w;j++)
			ar[i][j] = s[i][j]-'0';
	n=1;
	for(i=0;i<h-1;i++)
		n *= 2;
	for(i=0;i<n;i++) {
		int su=0;
		sums.clear();
		num_part = 0;
		part.clear();

		part.pb(0);
		j = i;
		l = 1;
		while(j) {
			if(j%2) {
				part.pb(l);
				num_part+=1;
			}
			j/=2;
			l++;
		}
		if(part[part.size()-1]!=h)
			part.pb(h);
		for(j=0;j<part.size()-1;j++)
			sums.pb(0);
		int sweep = 0;
		int last_sw = 0;
		while(sweep<w) {
			for(l=0;l<part.size()-1;l++)
				for(int l1=part[l];l1<part[l+1];l1++)
					sums[l] += ar[l1][sweep];
			int maxx = 0;
			for(j=0;j<sums.size();j++)
				maxx = max(sums[j],maxx);
			if(maxx>k) {
				if(last_sw==sweep)
					break;
				else {
					for(j=0;j<sums.size();j++)
						sums[j] = 0;
					num_part++;
					last_sw = sweep;
				}
			}
			else
				sweep++;
		}
		if(sweep==w)
			ans = min(num_part,ans);
	}
	cout<<ans<<endl;
	return 0;
}



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

#define ll          long long
#define pb          push_back
#define pii         pair<ll int,ll int>
#define vpii        vector< pii >
#define vi          vector<ll int>
#define vs			vector< string >
#define vvi         vector< vector< ll > >
#define inf			1'010'000'000'000'000'017LL
#define all(it,a)   for(auto it=(a).begin();it!=(a).end();it++) 
#define sz(x)       (ll int)x.size()
#define rep(i,a,b)	for(ll i=a;i<b;i++)
#define repr(i,a,b) for(ll i=a;i>b;i--)
#define lbnd        lower_bound
#define ubnd        upper_bound
#define mp          make_pair
#define whatis(x)   cout << #x << " is " << x << "\n";
#define graph(n)    adj(n,vector< ll > () )

using namespace std;

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


void Main()
{
	ll N, K;
	cin >> N >> K;
	vi H(N + K + 10, 0);
	rep(i, 0, N) cin >> H[i];

	vi dp(N + K + 10, inf);
	dp[0] = 0;

	rep(i, 0, N) {
		rep(j, 1, K + 1) {
			if (i + j >= N) continue;
			chmin(dp[i + j], dp[i] + abs(H[i] - H[i + j]));
		}
	}

	cout << dp[N - 1] << endl;

}

int main()
{
	cin.tie(nullptr);
	ios_base::sync_with_stdio(false);
	cout << fixed << setprecision(15);

	Main();
	return 0;
}

Measured memory_bytes: 4744
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<map>
#include<set>
#include<cstdio>
#include<cmath>
#include<numeric>
#include<queue>
#include<stack>
#define repp(i,a,b) for(int i=(int)a;i<(int)b;++i)
#define repm(i,a,b) for(int i=(int)a;i>(int)b;--i)
using ll=long long;
static const ll mod = 1e9 + 7;
static const ll INF = 1LL << 50;
using namespace std;

int main() {
	int n;
	cin >> n;
	vector<int>v(n+2,0);
	ll sum = 0;
	repp(i, 1, n + 1) {
		cin >> v[i];
		sum += abs(v[i] - v[i - 1]);
	}sum += abs(v[n]);
	ll copy = sum;
	repp(i, 1, n+1) {
		sum = copy;
			if (v[i-1] <= v[i]) {
				if (v[i] > v[i + 1])sum -= 2*min(abs(v[i] - v[i + 1]), abs(v[i-1] - v[i]));
			}
			else {
				if (v[i] < v[i + 1])sum -= 2*min(abs(v[i] - v[i + 1]), abs(v[i-1] - v[i]));
			}
		cout << sum << endl;
	}
	return 0;
}

Measured memory_bytes: 1664
#include <stdio.h>
#include <cmath>
#include <algorithm>
#include <cfloat>
#include <stack>
#include <queue>
#include <vector>
typedef long long int ll;
#define BIG_NUM 2000000000
#define MOD 1000000007
#define EPS 0.000001
using namespace std;

int H,W;

int main(){

	int maximum,map[10][10],tmp_sea_max,tmp_wall_min,tmp;

	while(true){
		scanf("%d %d",&H,&W);
		if(H == 0 && W == 0)break;

		for(int i = 0; i < H; i++){
			for(int k = 0; k < W; k++)scanf("%d",&map[i][k]);
		}

		maximum = 0;

		for(int sea_left = 1; sea_left <= W-2; sea_left++){
			for(int sea_right = sea_left; sea_right <= W-2; sea_right++){
				for(int sea_top = 1; sea_top <= H-2; sea_top++){
					for(int sea_bottom = sea_top; sea_bottom <= H-2; sea_bottom++){

						tmp_sea_max = 0;
						for(int row = sea_top;row <= sea_bottom;row++){
							for(int col = sea_left; col <= sea_right; col++){
								tmp_sea_max = max(tmp_sea_max,map[row][col]);
							}
						}

						tmp_wall_min = 100;
						for(int col = sea_left-1;col <= sea_right+1; col++)tmp_wall_min = min(tmp_wall_min,map[sea_top-1][col]);
						for(int col = sea_left-1;col <= sea_right+1; col++)tmp_wall_min = min(tmp_wall_min,map[sea_bottom+1][col]);
						for(int row = sea_top-1; row <= sea_bottom+1;row++)tmp_wall_min = min(tmp_wall_min,map[row][sea_left-1]);
						for(int row = sea_top-1; row <= sea_bottom+1;row++)tmp_wall_min = min(tmp_wall_min,map[row][sea_right+1]);

						if(tmp_sea_max >= tmp_wall_min)continue;

						tmp = 0;
						for(int row = sea_top;row <= sea_bottom;row++){
							for(int col = sea_left; col <= sea_right; col++){
								tmp += tmp_wall_min-map[row][col];
							}
						}

						maximum = max(maximum,tmp);
					}
				}
			}
		}

		printf("%d\n",maximum);

	}

	return 0;
}

Measured memory_bytes: 2680
#include <bits/stdc++.h>
using namespace std;
#define rep0(i, n) for (long long i = 0; i < (long long)(n); i++)
#define rep1(i,n) for(long long i=1;i<=(long long)(n);i++)
#define all(v) v.begin(),v.end()
#define Sort(v) sort(all(v))
#define Reverse(v) reverse(all(v))
#define Rsort(v) sort(all(v),greater)
#define pub(v) push_back(v)
#define pob(v) pop_back(v)
typedef long long ll;
typedef vector<ll> vel;
typedef vector<vector<ll>> vel2d;
typedef string str;
typedef pair<ll,ll> pal;
typedef vector<str> ves;
typedef vector<char> vech;


int main() {
    ll N,K,cnt=0;cin>>N>>K;
    map<ll,ll> data;
    rep0(i,K){
        ll d;cin>>d;
        vel A(d);rep0(j,d){cin>>A[j];}
        rep0(j,d){data[A[j]]++;}
    }
    rep1(i,N){
        if(1-data.count(i)){cnt++;}
    }
    cout<<cnt<<endl;

}


Measured memory_bytes: 3628
#include<map>
#include<cstdio>
#include<algorithm>
using namespace std;
int main() {
	int a[5]={0},ans=0;
	for(int i=1;i<=3;i++)
		scanf("%d",&a[i]);
	sort(a+1,a+4);
	ans+=(a[3]-a[1])/2;
	a[1]+=(a[3]-a[1])/2*2;
	ans+=(a[3]-a[2])/2;
	a[2]+=(a[3]-a[2])/2*2;
	while(a[1]!=a[2]||a[2]!=a[3]){
		sort(a+1,a+4);
		a[1]++;a[2]++;
		ans++;
	}
	printf("%d",ans);
	return 0;
}

Measured memory_bytes: 128
#include <iomanip>
#include <utility>
#include <algorithm>
#include <type_traits>
#include <set>
#include <string>
#include <iostream>
#include <fstream>
#include <cassert>
#include <memory>
#include <unordered_set>
#include <unordered_map>
#include <set>
#include <queue>
#include <vector>
#include <array>
#include <chrono>
#include <random>
#include <forward_list>
#include <iomanip>
#include <functional>
#include <stdio.h>
#include <string.h>

using namespace std;
#define MFOR(i,end) for(size_t i = 0, end_i = (end); i < end_i; ++ i)

uint64_t num[20];
uint32_t H, W;
std::unordered_map<uint64_t, char> map;//1～
const uint64_t INF = 1000000000;

int main()
{
	cin >> H>>W;
	num[0] = uint64_t(H - 2)*uint64_t(W - 2);
	uint32_t N;
	cin >> N;
	for (uint32_t i = 0; i < N; ++i)
	{
		uint32_t h, w;
		cin >> h >> w;
		for (int x = -1; x <= 1; ++x)
		{
			for (int y = -1; y <= 1; ++y)
			{
				if (w + x <= 1 || W <= w + x) { continue; }
				if (h + y <= 1 || H <= h + y) { continue; }
				--num[map[(h + y)*INF + w + x]];
				++map[(h + y)*INF + w + x];
				++num[map[(h + y)*INF + w + x]];
			}
		}
	}
	for (size_t i = 0; i < 10; ++i)
	{
		std::cout << num[i] << std::endl;
	}
}

Measured memory_bytes: 55300
#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;

class UnionFind {
public:
    vector <ll> par; // 各元の親を表す配列
    vector <ll> siz; // 素集合のサイズを表す配列(1 で初期化)
	vector <ll> rootsize;

    // Constructor
    UnionFind(ll n){
    	rep(i,n){
    		par.push_back(i); // 初期では親は自分自身
    		siz.push_back(1);
    		rootsize.push_back(1);
    	}
    }

    // Member Function
    // Find
    ll root(ll x) { // 根の検索
        while (par[x] != x) {
            x = par[x] = par[par[x]]; // x の親の親を x の親とする
        }
        return x;
    }

    // Union(Unite, Merge)
    bool merge(ll x, ll y) {
        ll rx = root(x);
        ll ry = root(y);
        if (rx == ry) return false;
        // merge technique（データ構造をマージするテク．小を大にくっつける）
        if (siz[rx] < siz[ry]) swap(rx, ry);
        siz[rx] += siz[ry];
        par[ry] = rx;
    	rootsize[rx] += rootsize[ry];
    	rootsize[ry] = rootsize[rx];
        return true;
    }

    bool issame(ll x, ll y) { // 連結判定
        return root(x) == root(y);
    }

    ll size(ll x) { // 素集合のサイズ
        return siz[root(x)];
    }
	
	ll getRootsize(ll x){ // xが属するグループの頂点数を返す
		return rootsize[root(x)];
	}
};


int main(){
    
    int n,m;
    cin >> n >> m;
	vector<P> bridge(m);
	UnionFind uf(n);
	rep(i,m){
		int a,b;
		cin >> a >> b;
		bridge[i] = make_pair(--a,--b);
	}
	reverse(bridge.begin(), bridge.end());
	
	vector<ll> csum(n);
	rep(i,n-1) csum[i+1] = csum[i] + i+1;
	
	vector<ll> res(m);
	res[0] = csum[n-1];
	
	rep(i,m-1){
		int n1 = bridge[i].first;
		int n2 = bridge[i].second;
		if(uf.issame(n1,n2)){
			res[i+1] = res[i];
		}
		else{
			int rs1 = uf.getRootsize(n1);
			int rs2 = uf.getRootsize(n2);
			res[i+1] = res[i] - rs1*rs2;
		}
		uf.merge(n1,n2);
	}
	reverse(res.begin(), res.end());
	rep(i,m) cout << res[i] << endl;
    return 0;
    
}


Measured memory_bytes: 6240
import sys
sys.setrecursionlimit(100000)
input = sys.stdin.readline
def ii(): return int(input())
def mi(): return map(int, input().rstrip().split())
def lmi(): return list(map(int, input().rstrip().split()))
def li(): return list(input().rstrip())
# template

# dfsの様々な実装例 in Python
# https://qiita.com/drken/items/a803d4fc4a727e02f7ba
# BEGIN CUT HERE


# v : 現在探索中の頂点，p : vの親（v が親のときは -1）
def dfs_tree(G,v,p):
    '''木上のdfsの実装例'''
    for nv in G[v]:
        if nv == p:
            continue
        dfs_tree(G, nv, v)
def main1():
    N = ii()
    G = [[] for i in range(N)]
    for i in range(N - 1):
        a, b = mi()
        G[a].append(b)
        G[b].append(a)
    
    root = 0
    dfs_tree(G, root, -1)

# 0を頂点とした木の根からの深さ，各頂点を根とした部分木のサイズを求める
# さっきのやつからすこし改造する
depth = [0] * (10 ** 5 + 10)
subtree_size = [0] * (10 ** 5 + 10)
# d : 頂点 v の深さ
def dfs_tree_kai(G, v, p, d):
    
    depth[v] = d
    for nv in G[v]:
        if nv == p:
            continue
        else:
            dfs_tree_kai(G, nv, v, d + 1)
    
    # 帰りがけ時に，部分木のサイズを求める
    subtree_size[v] = 1  # 自分自身
    for c in G[v]:
        if c == p:
            continue
        subtree_size[v] += subtree_size[c]
    return depth, subtree_size

def main2():
    '''木DPの簡単な例（部分木のサイズを求める）'''
    N = ii()
    G = [[] for i in range(N)]
    for i in range(N - 1):
        a, b = mi()
        a -= 1
        b -= 1
        G[a].append(b)
        G[b].append(a)
    
    root = 0  # 仮に頂点0を根とする
    dfs_tree_kai(G, root, -1, 0)
    
    for v in range(N):
        print(v, ": depth = ", depth[v], ", subtree_size = ", subtree_size[v])
    
def EDPC_P():
    N = ii()
    dp = [[1, 1] for _ in range(N)]
    G = [[] for i in range(N)]
    for i in range(N - 1):
        a, b = mi()
        a -= 1
        b -= 1
        G[a].append(b)
        G[b].append(a)
    depth = [0]*N
    def dfs_EDPC_P(G, v, p, d):
        depth[v] = d
        for nv in G[v]:
            if nv == p:
                continue
            dfs_EDPC_P(G, nv, v, d + 1)
        for c in G[v]:
            if c == p:
                continue
            dp[v][0] *= (dp[c][0] + dp[c][1]) % (10 ** 9 + 7)
            dp[v][1] *= dp[c][0]
    dfs_EDPC_P(G,0,-1,0)
    print((dp[0][0]+dp[0][1])%(10**9+7))
    
# END CUT HERE

if __name__ == '__main__':
    EDPC_P()

Measured memory_bytes: 136368
#include<bits/stdc++.h>
using namespace std;
#define REP(i,m,n) for(int i=(m);i<(n);i++)
#define rep(i,n) REP(i,0,n)
#define pb push_back
#define all(c) (c).begin(),(c).end()
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
const ll inf=1e9+7;
const ll mod=998244353;
int main(){
    ll n,k;cin>>n>>k;
    vector<ll>a(n);
    rep(i,n)cin>>a[i];
    ll t1=0;
    rep(i,n){
        rep(j,n)if(a[i]>a[j])t1++;
    }
    ll t=0;
    rep(i,n){
        REP(j,i,n){
            if(a[i]>a[j])t++;
        }
    }
    ll b;
    if(k%2==0)b=((k/2)%inf)*(k-1)%inf;
    else b=(((k-1)/2)%inf)*(k)%inf;
    cout<<((t*k)%inf+(b*t1)%inf)%inf<<endl;
}

Measured memory_bytes: 256
/*
    Author:zeke
    
    pass System Test!
    GET AC!!
*/
#include <iostream>
#include <queue>
#include <vector>
#include <iostream>
#include <vector>
#include <string>
#include <cassert>
#include <algorithm>
#include <functional>
#include <cmath>
#include <queue>
#include <set>
#include <stack>
#include <deque>
#include <map>
#include <iomanip>
#include <utility>
#include <stack>
#include <bitset>
using ll = long long;
using ld = long double;
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(), (x).end()
#define rep3(var, min, max) for (ll(var) = (min); (var) < (max); ++(var))
#define repi3(var, min, max) for (ll(var) = (max)-1; (var) + 1 > (min); --(var))
#define Mp(a, b) make_pair((a), (b))
#define F first
#define S second
#define Icin(s) \
    ll(s);      \
    cin >> (s);
#define Scin(s) \
    ll(s);      \
    cin >> (s);
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;
}
typedef pair<ll, ll> P;
typedef vector<ll> V;
typedef vector<V> VV;
typedef vector<P> VP;
ll mod = 1e9 + 7;
ll MOD = 1e9 + 7;
ll INF = 1e18;

int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(10);
    long long N, L;
    cin >> N >> L;
    vector<string> vec(N);
    for (int i = 0; i < N; i++)
    {
        cin >> vec[i];
    }
    sort(vec.begin(), vec.end());
    string s;
    for (int i = 0; i < N; i++)
    {
        s += vec[i];
    }
    cout << s << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <algorithm>
#include <climits>
#include <cmath>
#include <utility>
#include <string>
#include <cstring>
#include <functional>

using namespace std;

const int maxn = 200020;

int n, K;

struct Jewel
{
	int c;
	long long v;

	Jewel(int cc, long long vv) {
		c = cc;
		v = vv;
	}

	bool operator<(const Jewel &b) const {
		if (v == b.v)
			return c < b.c;
		else
			return v > b.v;
	}
};

const long long INF = ((long long)1) << 60;

int nums[maxn>>1];
vector<int> kinds[maxn>>1];
multiset<Jewel> x, y, z;

void mymin(long long &a, long long b) {
	if (a > b)
		a = b;
}

void mymax(long long &a, long long b) {
	if (a < b)
		a = b;
}

int main() {

	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	
	cin >> n >> K;

	for (int i = 0; i < n; ++i) {
		int c;
		long long v;
		cin >> c >> v;
		--c;

		kinds[c].push_back(v);
	}

	vector<Jewel> jewels;

	for (int i = 0; i < K; ++i)
		if (!kinds[i].empty()) {
			vector<int> &v = kinds[i];

			sort(v.begin(), v.end());
			reverse(v.begin(), v.end());

			// for (int j = 0; j < v.size(); ++j)
			// 	printf("%d ", v[j]);
			// printf("\n");

			jewels.push_back(Jewel(i, v[0] + v[1]));
			jewels.push_back(Jewel(i, v[0] + v[1]));

			for (int j = 2; j < v.size(); ++j)
				jewels.push_back(Jewel(i, v[j]<<1));

			y.insert(Jewel(i, v[0] + v[1]));

			if (v.size() >= 3)
				z.insert(Jewel(i, ((long long)v[0] + v[1] + v[2])<<1));
		}

	sort(jewels.begin(), jewels.end());

	long long min_value = INF, min_pair = INF, sum = 0;

	for (int i = 0; i < n; ++i) {
		long long ans = -2;
		int c = jewels[i].c;
		long long v = jewels[i].v;

		// printf("%d:%d %lld\n", i, c, v);

		if (nums[c] == 0) {
			if (!x.empty())
				mymax(ans, sum + x.begin()->v);
			if (!y.empty())
				mymax(ans, sum + y.begin()->v * 2 - min_value);
			if (!z.empty())
				mymax(ans, sum + z.begin()->v - min_pair);

			y.erase(y.find(jewels[i]));
			
			if (kinds[c].size() >= 3) {
				Jewel tmp(c, ((long long)kinds[c][0] + kinds[c][1] + kinds[c][2])<<1);
				z.erase(z.find(tmp));
			}

		} else {
			ans = sum + v;
			if (nums[c] == 1) {
				for (int j = 2; j < kinds[c].size(); ++j)
					x.insert(Jewel(c, kinds[c][j]<<1));

				mymin(min_pair, v << 1);
			} else {
				x.erase(x.find(jewels[i]));
				mymin(min_value, v);
			}
		}

		++nums[c];
		sum += v;

		cout << ans/2 << endl;
	}

	return 0;
}

Measured memory_bytes: 22636
import java.util.*;

public class Main {
    public static void main(String[] args){
        Scanner scan = new Scanner(System.in);
        int a = scan.nextInt();
        int b = scan.nextInt();
        int c = scan.nextInt();
        int d = scan.nextInt();
        if(a * b < c * d){
            System.out.println(c * d);
        }else{
            System.out.println(a * b);
        }
    }
}

Measured memory_bytes: 21716
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<cassert>
#include<iostream>
#include<sstream>
#include<string>
#include<vector>
#include<queue>
#include<set>
#include<map>
#include<utility>
#include<numeric>
#include<algorithm>
#include<bitset>
#include<complex>

using namespace std;

typedef long long Int;
typedef vector<int> vint;
typedef pair<int,int> pint;
#define mp make_pair

template<class T> void pv(T a, T b) { for (T i = a; i != b; ++i) cout << *i << " "; cout << endl; }
template<class T> void chmin(T &t, T f) { if (t > f) t = f; }
template<class T> void chmax(T &t, T f) { if (t < f) t = f; }
int in() { int x; scanf("%d", &x); return x; }

int login[10100][1261];

int main() {
	int N,M;
	while(cin>>N>>M,N){
		int r,q;
		cin>>r;
		int i;
		memset(login,0,sizeof(login));
		for(i=0;i<r;i++){
			int t,n,m,s;
			cin>>t>>n>>m>>s;
			login[m][t]+=(s?1:-1);
		}
		int j;
		int l;
		for(j=0;j<=M;j++){
			l=0;
			for(i=540;i<=1260;i++){
				l+=login[j][i];
				login[j][i]=l;
//cout<<j<<" "<<i<<" "<<l<<endl;
			}
		}
		cin>>q;
		for(i=0;i<q;i++){
			int ts,te,m;
			cin>>ts>>te>>m;
			int res=0;
			for(j=ts;j<te;j++){
				if(login[m][j]>0)res++;
			}
			cout<<res<<endl;
		}
	}
	return 0;
}

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

using namespace std;

using int64 = long long;


int64 N, L;

template< int char_size >
struct TrieNode {
  int nxt[char_size + 1];

  int exist; // 子ども以下に存在する文字列の数の合計
  vector< int > accept; // その文字列id

  TrieNode() : exist(0) {
    memset(nxt, -1, sizeof(nxt));
  }
};

template< int char_size, int margin >
struct Trie {
  using Node = TrieNode< char_size >;

  vector< Node > nodes;
  int root;

  Trie() : root(0) {
    nodes.push_back(Node());
  }

  virtual void direct_action(int node, int id) {}

  virtual void child_action(int node, int child, int id) {}

  void update_direct(int node, int id) {
    nodes[node].accept.push_back(id);
    direct_action(node, id);
  }

  void update_child(int node, int child, int id) {
    ++nodes[node].exist;
    child_action(node, child, id);
  }

  void add(const string &str, int str_index, int node_index, int id) {
    if(str_index == str.size()) {
      update_direct(node_index, id);
    } else {
      const int c = str[str_index] - margin;
      if(nodes[node_index].nxt[c] == -1) {
        nodes[node_index].nxt[c] = (int) nodes.size();
        nodes.push_back(Node());
      }
      add(str, str_index + 1, nodes[node_index].nxt[c], id);
      update_child(node_index, nodes[node_index].nxt[c], id);
    }
  }

  void add(const string &str, int id) {
    add(str, 0, 0, id);
  }

  void add(const string &str) {
    add(str, nodes[0].exist);
  }

  void query(const string &str, const function< void(int) > &f, int str_index, int node_index) {
    for(auto &idx : nodes[node_index].accept) f(idx);
    if(str_index == str.size()) {
      return;
    } else {
      const int c = str[str_index] - margin;
      if(nodes[node_index].nxt[c] == -1) return;
      query(str, f, str_index + 1, nodes[node_index].nxt[c]);
    }
  }

  void query(const string &str, const function< void(int) > &f) {
    query(str, f, 0, 0);
  }

  int size() const {
    return (nodes[0].exist);
  }

  int nodesize() const {
    return ((int) nodes.size());
  }

  int64 dfs(int idx, int dep) {
    if(nodes[idx].accept.size()) return 0;
    int64 ret = 0;
    for(int i = 0; i < 2; i++) {
      if(nodes[idx].nxt[i] == -1) {
        for(int64 j = 0; j < 62; j++) {
          if(((L - dep) >> j) & 1) {
            ret ^= 1LL << j;
            break;
          }
        }
      } else {
        ret ^= dfs(nodes[idx].nxt[i], dep + 1);
      }
    }
    return ret;
  }
};


int main() {
  cin >> N >> L;
  Trie< 2, '0' > trie;
  for(int i = 0; i < N; i++) {
    string s;
    cin >> s;
    trie.add(s);
  }
  if(trie.dfs(0, 0) == 0) puts("Bob");
  else puts("Alice");
}

Measured memory_bytes: 9616
#include <stdio.h>
int main() {

  int i,j,N,A[1000],v;
 
 scanf("%d",&N);
  for(i = 0; i < N; i++) {
    scanf("%d",&A[i]);
  }

  for(i = 0; i <= N-1; i++) {
    v = A[i];
    j = i - 1;

    while( j >= 0 && A[j] > v) {
      A[j+1] = A[j];
      j--;
      A[j+1] = v;
    }

    for(j = 0; j < N; j++) { 
      printf("%d",A[j]);
      if(j < N-1) printf(" ");
    }
    printf("\n");
  }
  return 0;
}

Measured memory_bytes: 608
#include<bits/stdc++.h>
using namespace std;
int main(){
  int n,cnt=0,a[5];
  for(int i=0;i<4;i++){
    char w;
    cin>>w;
    a[i]=w-'0';
  }
  if(a[0]==a[1]&&a[1]==a[2])cnt++;
  else if(a[1]==a[2]&&a[2]==a[3])cnt++;
  if(cnt>0)cout<<"Yes"<<endl;
  else  cout<<"No"<<endl;
  return(0);
}

Measured memory_bytes: 256
#!/usr/bin/env python

from collections import deque
import itertools as it
import sys

sys.setrecursionlimit(1000000)

N = input()
lst = []

for i in range(N):
    X, Y = map(int, raw_input().split())
    lst.append((X, Y))

if N % 2 != 0:
    print "NA"
    exit()

ansx = lst[0][0] + lst[N / 2][0]
ansy = lst[0][1] + lst[N / 2][1]

for i in range(N / 2):
    x = lst[i][0] + lst[i + N / 2][0]
    y = lst[i][1] + lst[i + N / 2][1]
    if x != ansx or y != ansy:
        print "NA"
        exit()

print str(ansx / 2.0) + " " + str(ansy / 2.0)


Measured memory_bytes: 5028
N = int( input() )
a = list( map( int, input().split() ) )

c = [ 0 ] * N
for i in range( N , 0, -1 ):
  s = 0
  for j in range( 2, N // i + 1 ):
    s += c[ i * j - 1 ]
  if s % 2 != a[ i - 1 ]:
    c[ i - 1 ] = 1

m = 0
b = ""
for i in range( N ):
  if c[i] > 0:
    m += 1
    b += str( i + 1 ) + " "
print( m )
print( b[:-1] )


Measured memory_bytes: 9916
using System;

public class Hello
{
    public static void Main()
    {
        string[] line = Console.ReadLine().Trim().Split(' ');
        var x1 = int.Parse(line[0]);
        var y1 = int.Parse(line[1]);
        var x2 = int.Parse(line[2]);
        var y2 = int.Parse(line[3]);
        var dx = x2 - x1;
        var dy = y2 - y1;
        var x3 = -dy + x2;
        var y3 = dx + y2;
        var x4 = -dy + x1;
        var y4 = dx + y1;
        Console.WriteLine("{0} {1} {2} {3}", x3, y3, x4, y4);
    }
}


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

int cnt=0, ab=0;
int ans[2]={};
vector<int> p(10500);
vector<int> q(10500);
vector<int> g(10500);
bool used[100];

void calc(int cnt, vector<int> com, int n){
    for(int i=1; i<=n; i++){
      if(com[i]!=g[i]){
        return;
      }else if(com[i]==g[i] && i==n){
        ans[ab] = cnt;
        ab++;
      }
    }
}

void DFS(int depth, int n){
    if(depth==n+1){
      cnt++;
      calc(cnt, p, n);
      calc(cnt, q, n);
    }else{
      for(int i=1; i<=n; i++){
        if(!used[i]){
          g[depth] = i;
          used[i]=true;
          DFS(depth+1, n);
          used[i]=false;
        }
      }
    }

}
int main()
{
  int n;
  cin >> n;
  for(int i=1; i<=n; i++){
    cin >> p[i];
  }

  for(int i=1; i<=n; i++){
    cin >> q[i];
  }

  DFS(1, n);

  cout << abs(ans[0]-ans[1]) << endl;
}


Measured memory_bytes: 384
using System;
namespace AFirstGrader {
	class Program {
		const int Limit = 21;
		const int Sentry = 10;
		static void Main(string[] args) {
			long[] list = new long[Limit + 2 * Sentry];
			long[] list_tmp = new long[Limit];

			int N = int.Parse(Console.ReadLine());
			string[] str = Console.ReadLine().Split(' ');
			
			list[int.Parse(str[0]) + Sentry] = 1;
			for (int n = 1; n < N - 1; n++) {
				for (int i = 0; i < Limit; i++) {
					int num = int.Parse(str[n]);
					list_tmp[i] = list[i - num + Sentry] + list[i + num + Sentry];
				}
				list_tmp.CopyTo(list, Sentry);
			}
			Console.WriteLine(list[int.Parse(str[N-1]) + Sentry]);
		}
	}
}

Measured memory_bytes: 5644
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {

		Scanner sc = new Scanner(System.in);
		int w =sc.nextInt();
		int n =sc.nextInt();
		int[] values = new int[w];
		
		for(int i= 0; i< values.length; i++) {
			values[i] = i+ 1;
		}
		
		for(int i =0; i<n ; i++){
			String str =sc.next();
			String[] ab = str.split(",");
			int a = Integer.parseInt(ab[0])- 1;
			int b = Integer.parseInt(ab[1])- 1;
			int c =values[a];
			values[a]=values[b];
			values[b]= c;
		}
		
		for(int i = 0; i<n ;i++){
		System.out.println(values[i]);
		}
	}
}

Measured memory_bytes: 25836
// UNNECESSARY
// #include <chrono>//std::chrono::/system_clock/steady_clock/high_resolution_clock/duration
// #include <cstdio>//printf/scanf/fopen/fclose/fprintf/fscanf/snprintf/putc/puts/getc/gets
// #include <fstream>//ifstream/ofstream

// DATA STRUCTURES
#include <array>
#include <bitset>
#include <list>
#include <queue>
#include <map>
#include <set>
#include <stack>
#include <tuple>
#include <valarray>
#include <vector>

// MISCELLANEOUS
#include <algorithm>//min/max/sort(rand-access it)/merge
#include <cassert>
#include <climits>//INT_MAX/INT_MIN/ULLONG_MAX
#include <cmath>//fmin/fmax/fabs/sin(h)/cos(h)/tan(h)/exp/log/pow/sqrt/cbrt/ceil/floor/round/trunc
#include <cstdlib>//abs/atof/atoi/atol/atoll/strtod/strtof/..., srand/rand, calloc/malloc, exit, qsort
#include <iomanip>//setfill/setw/setprecision/fixed/scientific
#include <iostream>//cin/cout/wcin/wcout/left/right/internal/dec/hex/oct/fixed/scientific
#include <iterator>
#include <limits>//numeric_limits<type>::max/min/lowest/epsilon/infinity/quiet_NaN/signaling_NaN
#include <new>
#include <string>//stoi/stol/stoul/stoll/stoull/stof/stod/stold/to_string/getline
#include <utility>//pair

#ifndef REP
#define REP(i,n) for (int i = 0; i < n; ++i)
#endif

#ifndef REPST
#define REPST(i,n) for (size_t i = 0; i < n; ++i)
#endif

#ifndef READ
#define READ(x) std::cin >> x
#endif

typedef unsigned int ui;
typedef long long ll;
typedef unsigned long long ull;
typedef std::pair<int, int> pii;
typedef std::pair<ll, int> plli;
typedef std::pair<ull, int> puli;
typedef std::pair<double, int> pdi;
typedef std::pair<ll, ll> pllll;
typedef std::pair<ull, ull> pulul;
typedef std::pair<double, double> pdd;
typedef std::tuple<int, int, int> ti3;
typedef std::tuple<int, int, int, int> ti4;

const bool debug = true;

// --------------------------------------------------------------------------------------

using namespace std;

int main(void)
{
    int A, B;
    cin >> A >> B;

    cout << ((A <= 8 && B <= 8) ? "Yay!" : ":(") << endl;

    return 0;
}


Measured memory_bytes: 256
n,m= map(int,input().split())
num = 0

f_n = False
f_m = False

num_n = 0
num_m = 0

while True:
  num_n = int(num * 0.08)
  num_m = int(num * 0.1)
  if int(num_n) == n:
    f_n = True
  if int(num_m) == m:
    f_m = True
  if f_m == True and f_n == True:
    print(num)
    break
  if num_m > 100 or num_n > 100 :
    print(-1)
    break
  f_m = False
  f_n = False
  num += 1
  
    
    

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

int main(){
    using namespace std;
    constexpr unsigned long C = 26;
    unsigned long D;
    cin >> D;
    vector<unsigned long> c(C);
    for(auto&& i : c)cin >> i;
    vector v(D, vector<unsigned long>(C));
    for(auto&& i : v)for(auto&& j : i)cin >> j;

    vector<unsigned long> t(D);
    for(auto&& i : t){
        cin >> i;
        --i;
    }

    long satisfy{0};
    vector<unsigned long> last(C);
    for(unsigned long i{0}; i < D; ++i){
        satisfy += v[i][t[i]];
        last[t[i]] = i + 1;
        for(unsigned long j{0}; j < C; ++j)satisfy -= c[j] * static_cast<long>(i + 1 - last[j]);
        cout << satisfy << endl;
    }

    return 0;
}

Measured memory_bytes: 3712
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<cmath>
#include<queue>
#include<map>
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
typedef long long ll;
typedef pair<int,int> P;
template<class T> inline bool chmax(T&a , T b){
    if(a<b){
        a=b; return true;
    }else{
        return false;
    }
}
template<class T> inline bool chmin(T&a , T b){
    if(a>b){
        a=b; return true;
    }else{
        return false;
    }
}

const int INF = 1e9;
const int MOD = 1e9+7;
const ll LINF = 1e18;

int dp[100005];

int main(){
    int n,k;
    cin >> n >> k;
    int a[n];
    rep(i,n) cin >> a[i];

    dp[0] = 0;
    for(int i=1;i<=k;i++){
        for(int j=0;j<n;j++){
            if(i-a[j]>=0 && dp[i-a[j]]==0){
                dp[i] = 1;
                break;
            }
        }
    }
    string ans;
    if(dp[k]) ans = "First";
    else ans = "Second";

    cout << ans << endl;

}

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

#define fi first
#define se second
#define pb push_back
#define sz(a) (int)(a).size()
using ll = long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using vi = vector<int>;
using vvi = vector<vi>;
using vll = vector<ll>;
using vvll = vector<vll>;

const ll MOD = 1e9 + 7;
const ll INF = 1e18;
const ll IINF = INT_MAX;

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    ll h;
    int n;
    cin >> h >> n;
    for (int i = 0; i < n; i++) {
        ll x;
        cin >> x;
        h -= x;
    }
    if (h <= 0) {
        cout << "Yes" << '\n';
    } else {
        cout << "No" << '\n';
    }
    return 0;
}

Measured memory_bytes: 256
n,W=map(int,input().split())
w0=0
w,v=[],[]
for i in range(n):
  ww,vv=map(int,input().split())
  if i==0:w0=ww
  w.append(ww-w0)
  v.append(vv)
dp=[[[0]*(n+1) for i in range(3*(n+1))] for i in range(n+1)]

for i in range(n):
  for j in range(3*n):
    for k in range(n):
      if j-w[i]>=0:
        dp[i][j][k+1]=dp[i-1][j-w[i]][k]+v[i]
      dp[i][j][k]=max(dp[i][j][k],dp[i-1][j][k])

ans=0
for i in range(n):
  for j in range(3*n):
    for k in range(n+1):
      if j+k*w0<=W:
        ans=max(dp[i][j][k],ans)
print(ans)


Measured memory_bytes: 70492
def main():
  n=int(input())
  a=list(map(int,input().split()))
  mod=pow(10,9)+7
  dp=[0,0,0] # dp[j]:前から順番に見た時の帽子jの数
  ans=1
  for ai in a:
    if ai in dp:
      ans*=dp.count(ai)
      ans%=mod
      dp[dp.index(ai)]+=1
    else:
      print(0)
      exit()
  print(ans)
if __name__=='__main__':
  main()


Measured memory_bytes: 13964
import itertools

N,M,Q = map(int,(input().split()))
a = [0]*Q
b = [0]*Q
c = [0]*Q
d = [0]*Q
for i in range(Q):
    a[i],b[i],c[i],d[i] = map(int,(input().split()))

l = list(itertools.combinations_with_replacement(range(1,M+1), N))

nax = 0
for x in l:
    score = 0
    for i in range(Q):
        if int(x[b[i]-1]) - int(x[a[i]-1]) == c[i]:
            score += d[i]
    nax = max(nax,score)

print(nax)

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

int main() {
	
	int K=0;
	double L=0;
	scanf("%d", &K);
	if(K%2==0){
		double P=K;
		L = pow ((P/2), 2);
		printf("%.0lf", L);
	}
	else{
		int O=0;
		O = (K-1)/2;
		O*(O+1);
		printf("%d", O*(O+1));
	}
	
	return 0;
}

Measured memory_bytes: 128
import sys
sys.setrecursionlimit(10**6)
from collections import deque

def num_way(stair):
  memo = ["EMPTY"]*(stair+1)
  def _fib(stair):
    if stair == 1 or stair == 0:
      return 1
    elif stair == 2:
      return 2
    elif memo[stair] != "EMPTY":
      return memo[stair]
    else:
      memo[stair] = _fib(stair-1)+_fib(stair-2)
      return memo[stair]
  return _fib(stair)

N, M = map(int,input().split())
a = deque([0])
path_poss = 1
ans = 1
for m in range(M):
  start = a.popleft()
  buff = int(input())
  end = buff-1
  if (end-start) <= -1:
    path_poss = 0
    break
  a.append(buff+1)
  ans *= num_way(end-start)
  ans %= 1000000007

if path_poss == 0:
  print(0)
else:
  start = a.popleft()
  end = N
  if(end-start) <= -1:
    path_poss = 0
  if path_poss == 0:
    print(0)
  else:
    ans *= num_way(end-start)
    print(ans%1000000007)

Measured memory_bytes: 513644
from collections import deque

INF = float("inf")

H, W, K = map(int, input().split())
A = [list(input()) for _ in range(H)]

Si, Sj = (0, 0)
for i, a in enumerate(A):
    if "S" in a:
        Si, Sj = (i, a.index("S"))
        break

dist = [[INF] * W for _ in range(H)]
dist[Si][Sj] = 0


ans = INF

Q = deque([(Si, Sj)])
while Q:
    i, j = Q.popleft()

    ans = min(
        ans,
        1 + (i + K - 1) // K,
        1 + (j + K - 1) // K,
        1 + (H - 1 - i + K - 1) // K,
        1 + (W - 1 - j + K - 1) // K
    )

    if dist[i][j] == K:
        continue

    distance = dist[i][j] + 1

    for di, dj in ((1, 0), (0, 1), (-1, 0), (0, -1)):
        ni, nj = i + di, j + dj

        if not (0 <= ni < H and 0 <= nj < W and A[ni][nj] == "."):
            continue

        A[ni][nj] = "#"

        if dist[ni][nj] > distance:
            dist[ni][nj] = distance
            Q.append((ni, nj))

print(ans)


Measured memory_bytes: 103772
import sys
import itertools
# import numpy as np
import time
import math
import heapq
from collections import defaultdict
sys.setrecursionlimit(10 ** 7)
 
INF = 10 ** 9 + 7
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

# map(int, input().split())

MOD = 10 ** 4 + 7

N = int(input())
if N == 1:
    print("Yes")
    print(2)
    print(1, 1)
    print(1, 1)
    exit()
i = 1
K = 0
while i ** 2 <= 2 * N:
    if i * (i + 1) == 2 * N:
        K = i + 1
        break
    i += 1

if K == 0:
    print("No")
    exit()

print("Yes")
print(K)
ladder = [i for i in range(1, K - 1)]
start = 1
base = [start]
for l in ladder:
    base.append(base[-1] + l)
for i in range(K - 1):
    num = K - 1
    s = [base[i]]
    for j in range(i):
        s.append(s[0] + j + 1)
    for j in range(i + 1, K - 1):
        s.append(base[j] + i)
    print(K - 1, *s)
diagnal = [1]
for l in ladder[1:] + [K - 1]:
    diagnal.append(diagnal[-1] + l)
print(K - 1, *diagnal)

Measured memory_bytes: 9680
N = int(input())
D_L = [[int(x) for x in input().split()] for y in range(N)]

cnt = 0
for di1, di2 in D_L:
    if di1 == di2:
        cnt += 1
    else:
        cnt = 0
    if cnt == 3:
        print("Yes")
        exit(0)
print("No")


Measured memory_bytes: 9104
MOD = 10 ** 9 + 7

plist = [-1] * 65
def p(x):
    if plist[x] != -1:return plist[x]
    if x == 0:
        plist[x] = 1
        return 1
    if x % 2 == 0:
        plist[x] = p(x//2)*p(x//2)%MOD
        return plist[x]
    plist[x] = 2*(p(x//2)*p(x//2)%MOD)%MOD
    return plist[x]

def add(x,y):
    return (x+y) % MOD
def mul(x,y):
    return x*y % MOD

N = int(input())
S = input()

cnt = [0] * 26
for i in range(N):
    cnt[ord(S[i])-97] += 1

flag = True
for i in range(26):
    if cnt[i] > 1:
        flag = False

if flag:
     print(add(-1,p(N)))
else:
    ans = 1
    for i in range(26):
        ans = mul(ans,1+cnt[i])
    print(add(-1,ans))
    

Measured memory_bytes: 3188
import heapq

q = int(input())

nchange = 0
ming, maxg = [], []
heapq.heapify(ming)
heapq.heapify(maxg)
a = 0
b = 0
for i in range(q):
    qi = input()
    if qi[0] == '1':
        _, ai, bi = map(int, qi.split())
        b += bi
        nchange += 1
        if nchange % 2 == 1:
            if nchange == 1:
                x = ai
                continue
            Smax = -heapq.heappop(ming)
            Dmin = heapq.heappop(maxg)
            if Smax <= ai and ai <= Dmin:
                heapq.heappush(ming, -Smax)
                heapq.heappush(maxg, Dmin)
                x = ai
            elif ai < Smax:
                heapq.heappush(ming, -ai)
                heapq.heappush(maxg, Dmin)
                x = Smax
                a += Smax - ai
            else:
                heapq.heappush(ming, -Smax)
                heapq.heappush(maxg, ai)
                x = Dmin
                a += ai - Dmin
        else:
            heapq.heappush(ming, -min(x, ai))
            heapq.heappush(maxg, max(x, ai))
            a += abs(x - ai)
            x = -heapq.heappop(ming)
            heapq.heappush(ming, -x)
    else:
        print(x, a+b)

Measured memory_bytes: 11184
n,k=map(int,input().split())
w=input()
l=[]
c=0
w="1"+w
for i in range(1,1+n):
  if w[i]!=w[i-1]:
    l.append(c)
    c=1
  else:
    c+=1
l.append(c)
if k>=len(l)//2:
  print(n)
else:
  if w[-1]=="0":
    l.append(0)
  s=l[0]
  for i in range(1,1+k):
    s+=l[2*i]+l[2*i-1]
  s1=s
  c1=l[0]+l[1]
  for i in range(1,(len(l)+1)//2-k):
    s1=s1-l[2*i-2]-l[2*i-1]+l[2*i-1+2*k]+l[2*i+2*k]
    if s1>s:
      s=s1
  print(s)

Measured memory_bytes: 4120
s = input()
t = input()
s_list = []
t_list = []

for i in range(26):
    s_list.append(s.count(chr(97+i)))
    t_list.append(t.count(chr(97+i)))

s_list.sort()
t_list.sort()
true = 0
for i in range(26):
    if s_list[i] != t_list[i]:
        print('No')
        break
    else:
        true += 1
if true == 26:
    print('Yes')


Measured memory_bytes: 3632
from collections import deque
import sys
n,m = map(lambda x: int(x),input().split())
sys.setrecursionlimit(26000)

tree = [[]*n for j in range(n)]
seen = [0]*n
seen[0] = 1
ans_conut = 0
def DFS(x) :
    global ans_conut
    if seen.count(1) == n :
        ans_conut +=1
        return

    for i in tree[x] :
        if seen[i] == 0 :
            seen[i] += 1
            DFS(i)
            seen[i] = 0



for _ in range(m) :
    a,b = map(lambda x: int(x),input().split())
    tree[a-1].append(b-1)
    tree[b-1].append(a-1)

DFS(0)
print(ans_conut)


Measured memory_bytes: 3316
#!/usr/bin/env python3

import sys

DEBUG = False

def solve():
    return


def read_int_list(sep = " "):
    return [int(s) for s in sys.stdin.readline().rstrip().split(sep)]

def read_int():
    return int(sys.stdin.readline())

def dprint(*args, **kwargs):
    if DEBUG:
        print(*args, **kwargs)
    return

def divceil(a, b):
    return (a + b - 1) // b

def main():
    n = read_int()
    print(divceil(n, 2))


if __name__ == "__main__":
    main()

Measured memory_bytes: 3064
#include <algorithm>
#include <iostream>
#include <cstdlib>
#include <cstring>
#include <cstdio>
#include <cmath>
#define RG register
#define il inline
#define iter iterator
#define Max(a,b) ((a)>(b)?(a):(b))
#define Min(a,b) ((a)<(b)?(a):(b))
using namespace std;
const int LIM=47,N=1e5+5;
bool vis[N][LIM];int k,q[N*LIM][2];
void work()
{
   scanf("%d",&k);
   int t=0,sum=0,x,u;
   for(int i=1;i<=9;i++){
      q[++sum][0]=i%k;
      q[sum][1]=i;
      vis[i%k][i]=1;
   }
   int tx,tu,ans=1e5;
   while(t!=sum){
      t++;x=q[t][0];u=q[t][1];
      if(x==0)ans=Min(ans,u);
      for(int i=0;i<=9;i++){
         tx=(x*10+i)%k;
         tu=u+i;
         if(tu>=LIM)continue;
         if(!vis[tx][tu]){
            vis[tx][tu]=1;
            q[++sum][0]=tx;
            q[sum][1]=tu;
         }
      }
   }
   printf("%d\n",ans);
}

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


Measured memory_bytes: 41600
package main

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

var sc *bufio.Scanner

func init() {
	sc = bufio.NewScanner(os.Stdin)
	buffsize := 1000000
	buff := make([]byte, buffsize)
	sc.Buffer(buff, buffsize)
	sc.Split(bufio.ScanWords)
}

func loadint() (result int) {
	sc.Scan()
	result, _ = strconv.Atoi(sc.Text())
	return
}

func loadstr() string {
	sc.Scan()
	return sc.Text()
}

func loadints(n int) []int {
	xs := make([]int, n)
	for i := 0; i < n; i++ {
		xs[i] = loadint()
	}
	return xs
}

func main() {
	n := loadint()
	m := loadint()
	q := loadint()
	ls := make([]int, m)
	rs := make([]int, m)
	ps := make([]int, q)
	qs := make([]int, q)
	for i := 0; i < m; i++ {
		ls[i] = loadint()
		rs[i] = loadint()
	}
	for i := 0; i < q; i++ {
		ps[i] = loadint()
		qs[i] = loadint()
	}
	t := make([][]int, n+1)
	for i := 0; i <= n; i++ {
		t[i] = make([]int, n+1)
	}
	for i := 0; i < m; i++ {
		t[ls[i]][rs[i]]++
	}
	for i := 0; i <= n; i++ {
		r := 0
		for j := 0; j <= n; j++ {
			r += t[i][j]
			t[i][j] = r
		}
	}
	for i := 0; i <= n; i++ {
		r := 0
		for j := 0; j <= n; j++ {
			r += t[j][i]
			t[j][i] = r
		}
	}
	for i := 0; i < q; i++ {
		x := qs[i]
		y := ps[i] - 1
		result := t[x][x] - t[x][y] - t[y][x] + t[y][y]
		fmt.Println(result)
	}
}


Measured memory_bytes: 10496
import java.util.*;
public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		// 整数の入力
		int a = sc.nextInt();
		// スペース区切りの整数の入力
		long b = sc.nextLong();
		long c = sc.nextLong();
		System.out.println(((a - 1) / b + 1) * c);
		
		
	}
}

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

#define maxn 200010
#define INF 1e11
#define int ll
#define pb push_back
#define f first

typedef long long ll;
typedef vector <ll> vi;
typedef pair<ll,ll> pi;
#define s second

int N,M;

vi adj[maxn];
pi range[maxn];
int ans[maxn];



pi intersect(pi i,pi j){
	return pi(max(i.f,j.f),min(i.s,j.s));
}

bool np = 0;

void dfs(int x,int p){
	

	for (auto i: adj[x]){
		range[x] = intersect(range[x],pi(range[i].f-1,range[i].s + 1));
	}
	
	for (auto i: adj[x]){
		if (i != p) dfs(i,x);
	}
	
	for (auto i: adj[x]){
		range[x] = intersect(range[x],pi(range[i].f-1,range[i].s + 1));
	}
	
	if (range[x].f > range[x].s) np = 1;
}


void dfs2(int x,int val,int p){
	ans[x] = val;
	for (auto i: adj[x]){
		if (i != p){
			if (range[i].f <= val - 1 && val - 1 <= range[i].s) dfs2(i,val-1,x);
			else if (range[i].f <= val + 1 && val + 1 <= range[i].s) dfs2(i,val+1,x);
			else{
				np = 1;
			}
		}
	}
}
int32_t main(){
	cin>>N;
	
	for (int i=0;i<N-1;i++){
		int a,b; cin>>a>>b;
		adj[a].pb(b);
		adj[b].pb(a);
	}
	
	cin>>M;
	
	int x;
	for (int i=1;i<=N;i++) range[i] = pi(-INF,INF);
	
	for (int i=0;i<M;i++){
		int a,b; cin>>a>>b;
		x = a;

		range[a] = pi(b,b);
	}
	
	dfs(1,-1);
	dfs(1,-1);
	dfs2(x,range[x].f,-1);
	
	//for (int i=1;i<=N;i++) cout<<range[i].f<<' '<<range[i].s<<'\n';
	
	if (np) cout<<"No";
	else{
		cout<<"Yes\n";
		for (int i=1;i<=N;i++) cout<<ans[i]<<'\n';
	}
	
}


Measured memory_bytes: 20480
#include <bits/stdc++.h>
#define rep(i,a,b) for(int i = (a); i <= (b); i++)
#define rng(a) a.begin(), a.end()
#define ina(n,a) cin >> n; for(int i = 1; i <= n; i++) cin >> a[i]
#define sz(x) (int)(x).size()
#define se second
#define fi first
#define prev            coyhhhhhhyoc    
#define next          sdNNNmNNNNNNNmds  
#define y0           hNNNNy_yNNNNNN_sNh
#define y1          mNNNNNdtdNNNNNNtsNNm
#define yn          mNNNNNNNNy___smNNNms
#define tm            oooooosyysooooot 
#define read               tyhyt        
#define rank              ytmNmo         
#define index              yyy
#define pb push_back
#define pcnt __builtin_popcountll
#define rrep(i,a,b) for(int i = (b); i >= (a); i--)
#define rall(x,a) for(auto x : a)
#define MOD 1000000007
#define endl "\n"
typedef long long ll;
using namespace std;

signed main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    string s;
    cin >> s;
    rep(i, 1, sz(s)) {
        char c = s[i - 1];
        if(i & 1) {
            if(c != 'R' && c != 'U' && c != 'D') {
                cout << "No" << endl;
                return 0;
            } 
        } else {
            if(c != 'L' && c != 'U' && c != 'D') {
                cout << "No" << endl;
                return 0;
            }
        }
    }
    cout << "Yes" << endl;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
const ll INF = 100000000;
#define rep1(i, n) for (ll i=0; i<(n); i++) 
#define rep2(i, k, n) for (ll i=k; i<(n); i++)
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; }


int main() {
    ll w, h, x, y;
    cin >> w >> h >> x >> y;
    double ans = double(w * h) / (double)2;
    printf("%.12f", ans);
    if (x==w/2 && y==h/2 && w%2==0 && h%2==0) cout << " " << 1 << endl;
    else cout << " " << 0 << endl;
}

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


#define li          long long int
#define rep(i,to)   for(li i=0;i<((li)(to));i++)
#define repp(i,start,to)    for(li i=(li)(start);i<((li)(to));i++)
#define pb          push_back
#define sz(v)       ((li)(v).size())
#define bgn(v)      ((v).begin())
#define eend(v)     ((v).end())
#define allof(v)    (v).begin(), (v).end()
#define dodp(v,n)       memset(v,(li)n,sizeof(v))
#define bit(n)      (1ll<<(li)(n))
#define mp(a,b)     make_pair(a,b)
#define rin rep(i,n)
#define EPS 1e-12
#define ETOL 1e-8
#define MOD 1777777777ll
typedef pair<li, li> PI;

#define INF bit(60)

#define DBGP 1


#define idp if(DBGP)
#define F first
#define S second
#define p2(a,b)     idp cout<<a<<"\t"<<b<<endl
#define p3(a,b,c)       idp cout<<a<<"\t"<<b<<"\t"<<c<<endl
#define p4(a,b,c,d)     idp cout<<a<<"\t"<<b<<"\t"<<c<<"\t"<<d<<endl
#define p5(a,b,c,d,e)       idp cout<<a<<"\t"<<b<<"\t"<<c<<"\t"<<d<<"\t"<<e<<endl
#define p6(a,b,c,d,e,f)     idp cout<<a<<"\t"<<b<<"\t"<<c<<"\t"<<d<<"\t"<<e<<"\t"<<f<<endl
#define p7(a,b,c,d,e,f,g)       idp cout<<a<<"\t"<<b<<"\t"<<c<<"\t"<<d<<"\t"<<e<<"\t"<<f<<"\t"<<g<<endl
#define p8(a,b,c,d,e,f,g,h)     idp cout<<a<<"\t"<<b<<"\t"<<c<<"\t"<<d<<"\t"<<e<<"\t"<<f<<"\t"<<g<<"\t"<<h<<endl
#define p9(a,b,c,d,e,f,g,h,i)       idp cout<<a<<"\t"<<b<<"\t"<<c<<"\t"<<d<<"\t"<<e<<"\t"<<f<<"\t"<<g<<"\t"<<h<<"\t"<<i<<endl
#define p10(a,b,c,d,e,f,g,h,i,j)        idp cout<<a<<"\t"<<b<<"\t"<<c<<"\t"<<d<<"\t"<<e<<"\t"<<f<<"\t"<<g<<"\t"<<h<<"\t"<<i<<"\t"<<j<<endl
#define foreach(it,v)   for(__typeof((v).begin()) it=(v).begin(); it!=(v).end(); ++it)
#define p2p(x)      idp p2((x).F, (x).S)
#define dump(x,n)   idp{rep(i,n){cout<<x[i]<<" ";}puts("");}
#define dump2(x,n)  idp{rep(i,n){cout<<"["<<x[i].F<<" , "<<x[i].S<<"] ";}puts("");}
#define dumpi(x)    idp{foreach(it, x){cout<<(*it)<<" ";}puts("");}
#define dumpi2(x)   idp{foreach(it, x){cout<<"["<<(it)->F<<" , "<<(it)->S<<"] ";}puts("");}

#define read2d(a,w,h)   rep(i,h)rep(j,w)cin>>a[i][j]
#define dump2d(a,w,h)   rep(i,h){rep(j,w)cout<<a[i][j]<<" ";puts("");}

typedef pair<li, li> PI;


int main() {
    li a, b, c;
    cin >> a >> b >> c;
    if (a == b && a == c) {
        cout << (a % 2 > 0 ? 0 : -1) << endl;
        return 0;
    }
    li res = 0;
    while (true) {
        if (max({a % 2, b % 2, c % 2}) > 0) {
            break;
        }
        li a2 = a / 2;
        li b2 = b / 2;
        li c2 = c / 2;
        a = b2 + c2;
        b = a2 + c2;
        c = a2 + b2;
        res++;
    }
    cout << res << endl;



    return 0;
}


Measured memory_bytes: 256