akhauriyash/Code-Regression huggingface dataset:
// {{{
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cmath>
#include <complex>
#include <cstdint>
#include <cstdio>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <limits>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <tuple>
#include <utility>
#include <vector>
using namespace std;
// }}}
using ll = long long;

int N;
vector<vector<int>> graph;

pair<int, bool> solve(int v, int p) {
    int ans = 0, nonzero = 0;
    int n_children = graph[v].size() - (p == -1 ? 0 : 1);
    bool im = false;
    for (int w : graph[v]) {
        if (w == p) continue;
        int sa; bool sim;
        tie(sa, sim) = solve(w, v);
        ans += sa;
        im = im || sim;
        if (sa != 0) nonzero += 1;
    }
    ans += max(0, n_children-1 - nonzero);
    if (nonzero == n_children) im = false;
    if (p == -1 && im) ans += 1;
    // cout << v << " " << p << " " << n_children << " " << nonzero << " " << im << " " << ans << endl;
    return make_pair(ans, im);
}

int main() {
    cin.tie(0); ios::sync_with_stdio(false);
    cin >> N;
    graph.resize(N);
    for (int j = 0; j < N-1; ++j) {
        int x, y;
        cin >> x >> y;
        graph[x].push_back(y);
        graph[y].push_back(x);
    }

    int start = -1;
    for (int j = 0; j < N; ++j) {
        if (graph[j].size() >= 3) {
            start = j;
            break;
        }
    }
    cout << (start == -1 ? 1 : solve(start, -1).first) << endl;

    return 0;
}


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

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

using ll = long long;
constexpr ll INF = 1000000000;
constexpr ll 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 namespace std;

//fixed << setprecision(10)

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

int main() {
	ll n, k; cin >> n >> k;

	vector<ll>vec(n);
	rep(i, n)cin >> vec[i];

	ll cnt = 0;
	for (ll i = 0; i < n; i++) {
		for (ll j = i + 1; j < n; j++) {
			if (vec[i] > vec[j])cnt++;
		}
	}

	ll count = 0;
	for (ll i = 0; i < n; i++) {
		for (ll j = 0; j < n; j++) {
			if (vec[i] > vec[j])count++;
		}
	}

	ll ans = (((k * (k - 1) / 2) % mod) * count) % mod + (k * cnt) % mod;

	cout << ans % mod << endl;

	
}


Measured memory_bytes: 256
#include<cstdio>
#include<cstring>
#include<queue>
#include<algorithm>
using namespace std;
const int MAXN=805,fx[4][2]={{0,1},{0,-1},{1,0},{-1,0}};
int H,W,K;
int map[MAXN][MAXN],st[2];
bool vis[MAXN][MAXN];
struct node
{
	int x,y,t;
	node(){}
	node(int xx,int yy,int tt)
	{
		x=xx,y=yy,t=tt;
	}
};
queue<node>q;
int main()
{
	//freopen("room.in","r",stdin);
	//freopen("room.out","w",stdout);
	scanf("%d %d %d",&H,&W,&K);
	for(int i=1;i<=H;i++)
	{
		scanf("\n");
		for(int j=1;j<=W;j++)
		{
			char c;
			scanf("%c",&c);
			if(c=='.')
				map[i][j]=0;
			if(c=='#')
				map[i][j]=1;
			if(c=='S')
			{
				st[0]=i;
				st[1]=j;
			}
		}
	}
	if(st[0]==1||st[1]==1||st[0]==H||st[1]==W)
	{
		printf("0\n");
		return 0;
	}
	q.push(node(st[0],st[1],K));
	vis[st[0]][st[1]]=1;
	int ans=H*W;
	while(!q.empty())
	{
		node k=q.front();
		q.pop();
		int Mi=min(min(k.x-1,H-k.x),min(k.y-1,W-k.y));
		ans=min(1+(Mi+K-1)/K,ans);
		if(k.t==0)
			continue;
		for(int o=0;o<4;o++)
		{
			int xx=k.x+fx[o][0];
			int yy=k.y+fx[o][1];
			if(1<=xx&&xx<=H&&1<=yy&&yy<=W&&map[xx][yy]==0&&vis[xx][yy]==0)
			{
				vis[xx][yy]=1;
				q.push(node(xx,yy,k.t-1));
			}
		}
	}
	printf("%d\n",ans);
	fclose(stdin);
	fclose(stdout);
}

Measured memory_bytes: 3456
import java.io.File;
import java.io.IOException;
import java.util.ArrayDeque;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Comparator;
import java.util.Deque;
import java.util.List;
import java.util.Scanner;

public class Main {
 
	public static void main(String[] args) throws IOException {
		//File file = new File("input.txt");
		//Scanner sc = new Scanner(file);
		
		Scanner sc = new Scanner(System.in);
		
		int H = sc.nextInt();
		int W = sc.nextInt();
		char[][] board = new char[H][W];
		boolean[] Hb = new boolean[H];
		boolean[] Wb = new boolean[W];
		
		for(int i = 0; i < H; i++){
			String line = sc.next();
			for(int j = 0; j < W; j++){
				board[i][j] = line.charAt(j);
			}
		}
		
		for(int i = 0; i < H; i++){
			int count = W;
			for(int j = 0; j < W; j++){
				if(board[i][j] == '.') count--;
			}
			if(count == 0){
				Hb[i] = true;
			}
		}
		
		for(int j = 0; j < W; j++){
			int count = H;
			for(int i = 0; i < H; i++){
				if(board[i][j] == '.') count--;
			}
			if(count == 0){
				Wb[j] = true;
			}
		}
		
		for(int i = 0; i < H; i++){
			for(int j = 0; j < W; j++){
				if(Hb[i] || Wb[j]) ;
				else System.out.print(board[i][j]);
			}
			if(!Hb[i]) System.out.println();
		}
	}
}

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

#define REP(i, n ,N) for(ll i = (n); i < (N); i++)
#define RREP(i, n ,N) for(ll i = (N-1); i >= (n); i--)
#define p(s) cout<<(s)<<endl
#define p2(a, b) cout<<(a)<<" "<<(b)<<endl
using namespace std;
typedef long long ll;
ll mod = 1e9+7;
ll inf = 1e18;

ll T[2];
ll A[2], B[2];
ll d[2];
int main(){
	REP(i,0,2){
		cin >> T[i];
	}
	REP(i,0,2){
		cin >> A[i];
	}
	REP(i,0,2){
		cin >> B[i];
	}
	if(A[0]*T[0] + A[1]*T[1] == B[0]*T[0] + B[1]*T[1]){
		p("infinity");
		return 0;
	}
	if(A[0] < B[0]){
		REP(i,0,2){
			swap(A[i], B[i]);
		}
	}
	d[0] = A[0]*T[0];
	d[1] = B[0]*T[0];

	ll ans = 0;
	if(d[0] + A[1]*T[1] <= d[1] + B[1]*T[1]){
		ans++;
		d[0] += A[1]*T[1];
		d[1] += B[1]*T[1];
		ll dist = d[1] - d[0];
		assert(dist > 0);
		ll left = (A[0]*T[0] - B[0]*T[0]);
		ans += left / dist * 2 - (left % dist == 0);
	}else{
		ans = 0;
	}

	p(ans);
	return 0;
}

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

int main() {
    int n, x;
    cin >> n >> x;
    int a[n];
    for (int i = 0; i < n; i++) {
        cin >> a[i];
    }
    sort(a, a + n);
    int ans = 0;
    for (int i = 0; i < n; i++) {
        x -= a[i];
        if (x < 0) break;
        if (i == n - 1 && x > 0) break;
        ans++;
    }

    cout << ans << endl;
}

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

int main()
{
	string s;
	cin >> s;
	if (s == "MON")
	cout << "6";
	else if (s == "TUE")
	cout << "5";
	else if (s == "WED")
	cout << "4";
	else if (s == "THU")
	cout << "3";
	else if (s == "FRI")
	cout << "2";
	else if (s == "SAT")
	cout << "1";
	else if (s == "SUN")
	cout << "7";
}

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

int main(){
    
    double a,b,c,d,e,f,x,y;
    
    while(scanf("%lf %lf %lf %lf %lf %lf",&a,&b,&c,&d,&e,&f) != EOF){
        x = (c*e - b*f)/(a*e - b*d);
        y = (c*d - a*f)/(b*d - a*e);
        if(x == -0) x = 0;
        if(y == -0) y = 0;
        
        printf("%.3f %.3f\n", x,y);
        
    }

	return 0;
}


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

typedef long long ll;
typedef unsigned long long ull;

int main()
{
    ll N;
    cin >> N;
    int length = 1;
    ll num = 26;
    while(N > num){
        N -= num;
        length++;
        num *= 26;
    }
    string res;
    N--;
    for(int i=0; i<length; i++){
        res += 'a' + N % 26;
        N /= 26;
    }
    reverse(res.begin(), res.end());
    cout << res << endl;

    return 0;
}

Measured memory_bytes: 3636
#include <bits/stdc++.h>
using namespace std;
#define fr first
#define sc second
#define pb push_back
#define mk make_pair
#define OK puts("OK");
#define sz(s) (int)s.size()
#define pii pair<int,int>
#define all(s) s.begin(), s.end()
#define allr(s) s.rbegin(), s.rend()
#define rep(i,n) for (i=0;i<(n);++i)
#define rep1(i,n) for (i=1;i<=(n);++i)
#define ret return
#define int long long
#define scan1(a) scanf("%lld",&(a));
#define scan2(a,b) scanf("%lld %lld",&(a),&(b));
#define scan3(a,b,c) scanf("%lld %lld %lld",&(a),&(b),&(c));
#define nemeshay ios::sync_with_stdio(0),cin.tie(0);
const int INF=1e9+7,N=1e6+12;
int dp[N],v[N],w[N];
main(){
    int n,i,j,k;
    scan2(n,k)
    dp[0] = 1;
    rep1(i,n)
        scan2(w[i],v[i])
    rep1(j,n){
        for (i = 1e5;i>=0;--i){
            if (dp[i]>0){
                dp[i+w[j]] = max(dp[i+w[j]],dp[i]+v[j]);
            }
        }
    }
    int ans=0;
    for (i=0;i<=k;++i){
        ans=max(ans,dp[i]);
    }
    cout <<ans-1;
}










Measured memory_bytes: 6400
package main

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

type String []byte

func (s String) Len() int {
	return len(s)
}

func (s String) Less(i, j int) bool {
	return s[i] < s[j]
}

func (s String) Swap(i, j int) {
	s[i], s[j] = s[j], s[i]
}

func main() {
	sc.Split(bufio.ScanWords)
	sc.Buffer(make([]byte, initialBufSize), maxBufSize)
	defer wt.Flush()

	n := nextInt()

	m := map[string]int{}
	ans := 0
	for i := 0; i < n; i++ {
		s := String(next())
		sort.Sort(s)
		ans += m[string(s)]
		m[string(s)]++
	}

	puts(ans)
}

const (
	initialBufSize = 100000
	maxBufSize     = 10000000
)

var (
	sc = bufio.NewScanner(os.Stdin)
	wt = bufio.NewWriter(os.Stdout)
)

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

func nextInt() int {
	i, _ := strconv.Atoi(next())
	return i
}

func nextFloat64() float64 {
	f, _ := strconv.ParseFloat(next(), 64)
	return f
}

func nextInts(n int) []int {
	slice := make([]int, n)
	for i := 0; i < n; i++ {
		slice[i] = nextInt()
	}
	return slice
}

func nextFloat64s(n int) []float64 {
	slice := make([]float64, n)
	for i := 0; i < n; i++ {
		slice[i] = nextFloat64()
	}
	return slice
}

func putf(format string, a ...interface{}) {
	fmt.Fprintf(wt, format, a...)
}

func puts(a ...interface{}) {
	fmt.Fprintln(wt, a...)
}


Measured memory_bytes: 10496
#include<iostream>
#include<algorithm>
#include<string>
#include<map>
#include<cmath>
#include<iomanip>
#include<math.h>
#include<vector>
#include<queue>
using namespace std;
typedef long long ll;


int main(){
    int n, m; cin >> n >> m;
    int a[m], b[m], sign[n];
    vector<int> pair[n];
    queue<int> q;
    for(int i=0; i<m; i++){
        cin >> a[i] >> b[i];
        a[i]--;
        b[i]--;
        pair[a[i]].push_back(b[i]);
        pair[b[i]].push_back(a[i]);
    }
    //cout << "input end" << endl;
    int already[n];
    for(int i=0;  i<n; i++) already[i] = 0;
    for(int i=0; i<pair[0].size(); i++){
        q.push(pair[0][i]);
        sign[pair[0][i]] = 0;
        already[pair[0][i]] = 1;
    }
    int tmp1, tmp2;
    while(!q.empty()){
        tmp1 = q.front(); q.pop();
        for(int i=0; i<pair[tmp1].size(); i++){
            tmp2 = pair[tmp1][i];
            if(!already[tmp2]){
                q.push(tmp2);
                sign[tmp2] = tmp1;
                already[tmp2] = 1;
            }
        }
    }
    for(int i=0; i<n; i++){
        if(!already[i]){
            cout << "No" << endl;
            return 0;
        }
    }
    cout << "Yes" << endl;
    for(int i=1; i<n; i++) cout << sign[i]+1 << endl;
}

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

int main()
{
    int N;
    cin >> N;
    int l=0, r=N;
    cout << l << endl;
    string s;
    cin >> s;
    if(s == "Vacant") return 0;
    while(r-l>0)
    {
        int mid = (r+l) / 2;
        cout << mid << endl;
        string t;
        cin >> t;
        if(t == "Vacant") break;
        if(mid%2==0)
        {
            if(s==t) l=mid;
            else r=mid;
        }
        else
        {
            if(s==t) r=mid;
            else l=mid;
        }
    }

    return 0;
}


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

using VS = vector<string>;    using LL = long long;
using VI = vector<int>;       using VVI = vector<VI>;
using PII = pair<int, int>;   using PLL = pair<LL, LL>;
using VL = vector<LL>;        using VVL = vector<VL>;

#define ALL(a)  begin((a)),end((a))
#define RALL(a) (a).rbegin(), (a).rend()
#define SZ(a) int((a).size())
#define SORT(c) sort(ALL((c)))
#define RSORT(c) sort(RALL((c)))
#define UNIQ(c) (c).erase(unique(ALL((c))), end((c)))
#define FOR(i, s, e) for (int(i) = (s); (i) < (e); (i)++)
#define FORR(i, s, e) for (int(i) = (s); (i) > (e); (i)--)
//#pragma GCC optimize ("-O3") 
#ifdef YANG33
#include "mydebug.hpp"
#else
#define DD(x) 
#endif
const int INF = 1e9;                          const LL LINF = 1e16;
const LL MOD = 1000000007;                    const double PI = acos(-1.0);
int DX[8] = { 0, 0, 1, -1, 1, 1, -1, -1 };    int DY[8] = { 1, -1, 0, 0, 1, -1, 1, -1 };

/* -----  2019/04/03  Problem: ABC 050 A / Link: http://abc050.contest.atcoder.jp/tasks/abc050_a  ----- */


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

	LL A, B;
	char c;
	cin >> A >> c >> B;
	LL ans = 0;
	if (c == '+')ans = A + B;
	else ans = A - B;
	
	
	cout << (ans) << "\n";

	return 0;
}


Measured memory_bytes: 256
#include <iostream>
using namespace std;
int f(int n){return n % 2 == 0 ? n/2 : 3*n+1;}

int main(){
	int s;
	cin >> s;
	int a[1000001] = {0};
	bool in[1000001] = {false};
	a[1] = s; in[a[1]] = true;
	for(int i = 2;; i++){
		a[i] = f(a[i-1]);
		if(in[a[i]]){
			cout << i << endl;
			return 0;
		}
		else in[a[i]] = true;
	}
}


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

using namespace std;

vector<int> X={1, -1, 0, 0}, Y={0, 0, 1, -1};

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

    int h, w, sx, sy, tx, ty, ans=2000000000;
    cin >> h >> w >> sx >> sy >> tx >> ty;
    sx--, sy--, tx--, ty--;
    vector<vector<char> > arr(h, vector<char>(w));
    for(int i=0; i<h; i++)
        for(int j=0; j<w; j++)
            cin >> arr[i][j];
    if(arr[sx][sy]!='.'){
        cout << -1 << endl;
        return 0;
    }
    deque<pair<int, int> > dq;
    vector<vector<int> > dist(h, vector<int>(w, 2000000000));
    dist[sx][sy]=0;
    dq.push_back({sx, sy});
    while(!dq.empty()){
        int x=dq.front().first, y=dq.front().second;
        dq.pop_front();
        if(x==tx && y==ty){
            ans=dist[x][y];
            break;
        }
        for(int k=0; k<4; k++){
            int nx=x+X[k], ny=y+Y[k];
            if(nx>=0 && nx<h && ny>=0 && ny<w && arr[nx][ny]=='.'){
                if(dist[nx][ny]>dist[x][y]){
                    dist[nx][ny]=dist[x][y];
                    dq.push_front({nx, ny});
                }
            }
        }
        for(int i=x-2; i<=x+2; i++){
            for(int j=y-2; j<=y+2; j++){
                if(i>=0 && i<h && j>=0 && j<w && arr[i][j]=='.'){
                    if(dist[i][j]>dist[x][y]+1){
                        dist[i][j]=dist[x][y]+1;
                        dq.push_back({i, j});
                    }
                }
            }
        }
    }
    if(ans==2000000000) cout << -1 << endl;
    else cout << ans << endl;
	return 0;
}


Measured memory_bytes: 8636
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {

		Scanner sc = new Scanner(System.in);
		int a = sc.nextInt(); // 500円玉枚数
		int b = sc.nextInt(); // 100円玉枚数
		int c = sc.nextInt(); // 50円玉枚数
		int x = sc.nextInt(); // 合計金額

		int result = 0;

		for (int cntA = 0; cntA <= a; cntA++) {
			for (int cntB = 0; cntB <= b; cntB++) {
				for (int cntC = 0; cntC <= c; cntC++) {
					if ((500*cntA) + (100*cntB) + (50*cntC) == x) {
						result++;
					};
				}
			}
		}

		System.out.println(result);
	}
}



Measured memory_bytes: 35612
#include <stdio.h>
#include <algorithm>
#include <iostream>
#include <vector>
#include <assert.h>
#include <map>
#include <set>
#include <unordered_set>
#include <unordered_map>
#include <math.h>
#include <string>
#include <string.h>
#include <queue>
#include <complex>
#include <iomanip>
#include <stack>
using namespace std;
typedef long long int ll;
typedef unsigned long long int ull;
ll mod=1e9+7;
double eps=1e-7;
ll exp(ll x,ll y){if(y<0) return 0; ll ret=1;for(;y;y>>=1,x=(x*x)%mod){if(y&1)ret=(ret*x)%mod;}return ret;}
ull pexp(ull x,ull y){if(y<0) return 0; ull ret=1; for(;y;y>>=1,x=(x*x)){if(y&1)ret=(ret*x);}return ret;}
ll gcd(ll x,ll y){if(!x||!y) return x+y; return x%y==0?y:gcd(y,x%y);}
ll lcm(ll x,ll y){return x*(y/gcd(x,y));}
ll bsum(ll u,ll b){ll ret=0;if(u<b)return u;while(u){ret+=u%b;u/=b;}return ret;}
ll prival(ll u,ll p){ll cn=0;while(u%p==0){cn++;u=u/p;}return cn;}
ll minv(ll a,ll b){return 1<a?b-minv(b%a,a)*b/a:1;}
ll extm(ll a,ll b){ll ret=0;while(a!=0){if(a%2==1){ret+=b;ret%=mod;}a>>=1;b=(2*b)%mod;}return ret;}   
ll eaphi(ll x){ll t=x,ret=x,i;for(i=2;i*i<=x;i++){if(t%i==0){ret-=ret/i;while(t%i==0) t/=i;}}if(t!=1) ret-=ret/t;return ret;}
ll eadivc(ll x){ll ret=0;ll i;for(i=1;i*i<=x;i++){if(x%i==0 && i*i!=x) ret+=2;if(x%i==0 && i*i==x) ret+=1;}return ret;}
ll eadivs(ll x){ll ret=0;ll i;for(i=1;i*i<=x;i++){if(x%i==0 && i*i!=x) ret+=i+x/i;if(x%i==0 && i*i==x) ret+=i;}return ret;}
ll ndig(ll x, ll b){ll ret=0;while(x){x/=b; ret++;}return ret;}
ll rev(ll n, ll b){ll ret=0;while(n){ret=b*ret+n%b; n/=b;}return ret;}
ll sq(ll x){ll t=(ll)sqrt(x); for(ll i=t-2 ; i<=t+2 ; i++) if(i*i==x) return abs(i); return -1;}
ll extexp(ll x,ll y){if(y<0) return 0; ll ret=1;for(;y;y>>=1,x=extm(x,x)){if(y&1)ret=extm(ret,x);}return ret;}
bool isprime(ll x){if(x<=1) return false; for(ll i=2;i*i<=x;i++){if(x%i==0){return false;}}return true;}
ll A[222222];
ll n, ans;

int main(void)
{
	ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
	cin>>n; ll i, j;
	for(i=1 ; i<=n ; i++) cin>>A[i];
	for(i=1 ; i<=n ; i++) A[i]-=i;
	sort(A+1,A+n+1); ll b=A[(n+1)/2];
	for(i=1 ; i<=n ; i++) ans+=abs(A[i]-b);
	cout<<ans; return 0;
}

Measured memory_bytes: 1792
#include<iostream>
using namespace std;
 
int n,i,a;
string s[100];
int main()
{ 
cin >> n;
for(i=0;i<n;i++){
cin >> s[i];
}
for(i=0;i<n;i++){
if(s[i]=="Y"){a=1;
}
}
if(a==1){printf("Four");
}else{printf("Three");
}
}

Measured memory_bytes: 256
N = int(input())
A = [input().split() for _ in range(2)]
sum_A = [[0 for _ in range(N)] for _ in range(2)]
sum_A[0][0] = int(A[0][0])
sum_A[1][0] = int(A[0][0]) + int(A[1][0] )

for i in range(1, N):
  sum_A[0][i] = sum_A[0][i-1] + int(A[0][i])

for i in range(1, N):
  if (sum_A[1][i-1] + int(A[1][i])) > (sum_A[0][i] + int(A[1][i])):
    sum_A[1][i] = sum_A[1][i-1] + int(A[1][i])
  else:
    sum_A[1][i] = sum_A[0][i] + int(A[1][i])

print(sum_A[1][N-1])

Measured memory_bytes: 3064
A, B, C, D = map(int, input().split())

for i in range(1000):
  if i == 0:
    AOKI = C - B
    if AOKI <= 0:
      print('Yes')
      break
    TAKAHASHI = A - D
    if TAKAHASHI <= 0:
      print('No')
      break

  AOKI = AOKI - B
  if AOKI <= 0:
      print('Yes')
      break

  TAKAHASHI = TAKAHASHI - D
  if TAKAHASHI <= 0:
    print('No')
    break


Measured memory_bytes: 9184
rooms = [[[0 for k in range(10)] for j in range(3)] for i in range(4)]
n = int(input())

for _ in range(n):
    b, f, r, v = map(int, input().split())
    rooms[b - 1][f - 1][r - 1] += v

for b in range(4):
    for f in range(3):
        print(' ' + ' '.join(map(str, rooms[b][f])))
    if b is not 3:
        print('####################')

Measured memory_bytes: 7748
import java.util.*;

public class Main{
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		int n;
		int[] data = new int[2];
		int[] temp = new int[2];
		
		while(true){
			n = sc.nextInt();
			if(n == 0)break;
			data[0] = 0;
			data[1] = 0;
			
			for(int i=0;i<n;++i){
				
				temp[0] = sc.nextInt();
				temp[1] = sc.nextInt();
				
				if(temp[0] > temp[1]){
					data[0] += temp[0]+temp[1];
				}
				else if(temp[0] < temp[1]){
					data[1] += temp[0]+temp[1];
				}
				else{
					data[0] += temp[0];
					data[1] += temp[1];
				}
			}
			System.out.printf("%d %d\n",data[0],data[1]);
		}
		sc.close();
	}
}

Measured memory_bytes: 53304
import Debug.Trace


solve :: [Int] -> Int -> Int
solve (h:t) x
    | x == 1 = h
    | h == 1 = solve t (x-1)
    | otherwise = h

main :: IO ()
main = do
    s <- getLine
    x <- read <$> getLine
    let split = map (:[]) s
    let a = map read split
    print (solve a x)
    -- main



Measured memory_bytes: 508
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstring>
#include<string>
using namespace std;
char fie[1111][1111];
int rui[1111][1111];
main(){
  int N;
  while(1){
    cin >> N;
    if(N==0) break;
    for(int i=1;i<=N;i++){
      for(int j=1;j<=N;j++)
	cin >> fie[j][i];
    }
    memset(rui,0,sizeof(rui));
    for(int i=1;i<=N;i++){
      if(fie[1][i]=='.') rui[1][i]=1;
      for(int j=2;j<=N;j++){
	rui[j][i]=rui[j-1][i];
	if(fie[j][i]=='.') rui[j][i]++;
      }
    }

    for(int j=1;j<=N;j++){
      for(int i=2;i<=N;i++){
	rui[j][i]+=rui[j][i-1];
      }
    }
    /*
          for(int i=1;i<=N;i++){
	for(int j=1;j<=N;j++) printf("%2d ",rui[j][i]);
	puts("");
      }
    */
    int res=0;
    for(int i=1;i<=N;i++){
      for(int j=1;j<=N;j++){
	if(fie[j][i]=='*') continue;
	int st=0,ed=min(N-j,N-i);
	int ret=0;
	//	cout << j << ":" << i << endl;
	while(st<=ed){
	  int h=(st+ed)/2;
	  int r = rui[j+h][i+h]-rui[j+h][i-1]-rui[j-1][i+h]+rui[j-1][i-1];
	  //	  cout << r << " " <<rui[j+h][i+h]<<" "<<rui[j+h][i-1]<<" "<<rui[j-1][i+h]<<" "<<rui[i-1][j-1]<<" "<< h << endl;
	  if( r >= (h+1)*(h+1) ){
	    st = h+1;
	    ret=h+1;
	  }
	  else ed = h-1;
	}
	res = max(res,ret);
      }
    }
    cout << res << endl;

  }
}

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

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

    int k, a, b;
    cin>>k>>a>>b;
    bool flag = false;

    for(int i=a;i<=b;i++) {
        if(i%k == 0) {
            flag = true;
            break;
        }
    }

    if(flag)
     cout<<"OK";
    else cout<<"NG"; 


    return 0;
}

Measured memory_bytes: 3652
#include<bits/stdc++.h>
#define ll long long
#define rgi register int
#define rgl register ll
#define maxn 100005
#define mod 998244353LL
#define inf 1000000007LL
namespace lib
{
	using namespace std;
	class fastio
	{
		private:
			#define _NUMLEN 111
			char _num[_NUMLEN],_ch;
			int _f,_head;
			bool _useSTD;
		public:
			inline void ioSTD()
			{
				_useSTD=1;
				ios::sync_with_stdio(false);
				cin.tie(0),cout.tie(0);
			}
			inline void gc(char & _c)
			{
				if(_useSTD)cin>>_c;
				else _c=getchar();
			}
			inline void pc(char _c)
			{
				if(_useSTD)cout<<_c;
				else putchar(_c);
			}
			template<typename _T> inline fastio & operator - (_T & _x)
			{
				if(_useSTD)cin>>_x;
				else
				{
					_x=0;
					while(!isdigit(_ch)) _f|=_ch=='-',gc(_ch);
					while(isdigit(_ch)) _x=(_x<<1)+(_x<<3)+(_ch^48),gc(_ch);
					_f&&(_x=-_x,_f=0);
				}
				return *this; 
			}
			template<typename _T> inline fastio & operator + (_T _x)
			{
				if(_useSTD)cin>>_x;
				else
				{
					_T _k;
					if(_x==0) {pc('0'),pc(' ');return *this;}
					if(_x<0) pc('-'),_x=-_x;
					while(_x>0) _k=_x/10,++_head,_num[_head]=(_x-(_k<<1)-(_k<<3))^48,_x=_k;
					while(_head>0) pc(_num[_head]),--_head;
					pc(' ');
				}
				return *this; 
			}
			template<typename _T> inline fastio & operator >> (_T & _x) {cin>>_x;return *this;}
			template<typename _T> inline fastio & operator << (_T _x) {cout<<_x;return *this;}
			#define endln pc('\n')
		fastio() {_f=0,_head=0,_useSTD=0,_ch=' ';}
	}io;
	inline void fileio(string _r,string _w)
	{
		if(_r[0]!='-')freopen(_r.c_str(),"r",stdin);
		if(_w[0]!='-')freopen(_w.c_str(),"w",stdout);
	}
	#define mem(_x,_set) memset(_x,_set,sizeof(_x))
}using namespace lib;

int n;
int ans;
string s; 
signed main()
{
	cin>>n>>s;
	for(int i=0;i<n;i++)
		if(s[i]=='A'&&s[i+1]=='B'&&s[i+2]=='C')
			ans++;
	cout<<ans;
	return 0;
}


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

int main() {
	ios::sync_with_stdio(0);
	cin.tie(0); cout.tie(0);
	string s; cin >> s;
	for (int i = 0; i < s.length() - 1; i++) if (s[i] == 'A' && s[i + 1] == 'C') {
		cout << "Yes" << endl;
		return 0;
	}
	cout << "No" << endl;
	return 0;
}



Measured memory_bytes: 3524
#include <iostream>
#include <algorithm>
#include <vector>
#include <bits/stdc++.h>
using namespace std;

int main()
{
    int keta;
    int num;

    vector<int> rule(4, -1); //要素を-1で初期化しておく

    cin >> keta >> num;

    int s;
    int c;

    for (int i = 1; i <= num; i++)
    {
        cin >> s >> c;

        //cが0で、1桁でないなら、先頭の桁でないか確認
        if (c == 0 && keta != 1)
        {
            if (s == 1)
            {
                cout << -1 << endl;
                return 0;
            }
        }

        //まだ指定されていないので、記憶
        if (rule[s] == -1)
        {
            rule[s] = c;
        }

        //既に指定された条件と矛盾しないか確認
        if (rule[s] != c)
        {
            cout << -1 << endl;
            return 0;
        }
    }

    //ここまでで条件は全て受け取った

    int ans = 0;

    //3桁、または2桁の場合
    if (keta == 3 || keta == 2)
    {
        //左から1桁目の条件があるか確認
        if (rule[1] != -1) //条件がある場合
        {
            ans = ans + pow(10, keta - 1) * rule[1];
        }
        else
        {
            //左から１桁目の条件がない場合は、1とする
            ans = ans + pow(10, keta - 1) * 1;
        }

        //左から２桁目を確認
        if (rule[2] != -1)
        {
            ans = ans + pow(10, keta - 2) * rule[2];
        }
        else
        {
            ans = ans + pow(10, keta - 2) * 0; //実際には何もしていない
        }

        //3桁の場合だけもう１桁ある
        if (keta == 3)
        {
            if (rule[3] != -1)
            {
                ans = ans + rule[3];
            }
            else
            {
                ans = ans + pow(10, keta - 2) * 0; //実際には何もしていない
            }
        }
    }
    else //1桁の場合
    {
        if(rule[1] != -1)
        {
            ans = rule[1];
        }else
        {
            ans = 0;
        }
        
    }

    cout << ans << endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
bool ck(string s){
	map<char,int>mp;
	for(int i=0;i<s.length();i++){
		mp[s[i]]++;
	}
	if(mp.size()==1)
	return 1;
	return 0;
} 
int cal(string s,char c){

	int ans=0;

			while(1){
		if(ck(s))
		{
			break;
		}
		else{
			ans++;
				map<char,int>m;
	for(int i=0;i<s.length();i++){
		m[s[i]]++;
	}
	
			string t;
			for(int i=0;i<s.length()-1;i++){
			if(s[i]==c||s[i+1]==c){
				t+=c;
			}
			else{
				if(m[s[i]]>=m[s[i+1]])
				t+=s[i];
				else
				t+=s[i+1];
				
			}
	}
	s=t;
			
		}
	
	}
	return ans;
	
	
	
}
int main(){
	string s;
	cin>>s;
	if(ck(s))
	{
		cout<<0<<endl;
		return 0;
	}
	int ans=1e9;
for(int i=1;i<s.length();i++){
	int tp=cal(s,s[i]);
	ans=min(tp,ans);
}
	cout<<ans<<endl;
	
	
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, a, b) for(int i = a; i < (b); ++i)
#define trav(a, x) for(auto& a : x)
#define all(x) x.begin(), x.end()
#define endl "\n"
#define sz(x) (int)(x).size()
using namespace std;
typedef long long int lli;
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;

int main() {
    lli x;
    cin >> x;
    int c500 = x/500;
    int rem_left = x%500;
    int c5 = rem_left/5;
    cout << (c500*1000) + (c5*5) << endl;
    return 0;
}

Measured memory_bytes: 256
#define _USE_MATH_DEFINES
#define _CRT_SECURE_NO_WARNINGS
#include<stdio.h>
#include<string>
#include<iostream>
#include<cctype>
#include<cstdio>
#include<vector>
#include<stack>
#include<queue>
#include <algorithm>
#include<math.h>
#include<set>
#include<map>
#include <sstream>
#include<iomanip>
#include <ctype.h>

//#include<bits/stdc++.h>




using namespace std;
vector<int>a(301234, 0);
vector<int>b(301234, 0);
int main() {
	int n;
	string p;
	cin >> n >> p;
	for (int i = 0; i < n; i++) {
		if (p[i] == 'W')a[i] = 1;
		else b[i] = 1;
	}
	vector<int>t(301234, 0);
	int x=0;
	for (int i = 0; i < n; i++) {
		t[i] = x;
		x += a[i];
	}
	int ans = 99999999;
	x = 0;
	for (int j = n - 1; j >= 0; j--) {
		t[j] += x;
		ans = min(ans, t[j]);

		x += b[j];
		//cout << t[j];
	}
	cout << ans << endl;


	return 0;
}

Measured memory_bytes: 4228
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) FOR(i,0,n)
#define ALL(v) begin(v),end(v)
#define fi first
#define se second
template<typename A, typename B> inline bool chmax(A &a, B b) { if (a<b) { a=b; return 1; } return 0; }
template<typename A, typename B> inline bool chmin(A &a, B b) { if (a>b) { a=b; return 1; } return 0; }
using ll = long long;
using pii = pair<int, int>;
constexpr ll INF = 1ll<<30;
constexpr ll longINF = 1ll<<60;
constexpr ll MOD = 1000000007;
constexpr bool debug = 0;
//---------------------------------//

int main() {
	int N;
	cin >> N;
	vector<int> X(N), L(N);
	REP(i, N) scanf("%d %d", &X[i], &L[i]);
	
	vector<int> cx;
	REP(i, N) cx.emplace_back(X[i] - L[i]);
	REP(i, N) cx.emplace_back(X[i] + L[i]);
	sort(ALL(cx));
	cx.erase(unique(ALL(cx)), cx.end());
	
	vector<vector<int>> g(cx.size());
	REP(i, N) {
		int from = lower_bound(ALL(cx), X[i] - L[i]) - cx.begin();
		int to = lower_bound(ALL(cx), X[i] + L[i]) - cx.begin();
		g[from].emplace_back(to);
	}
	
	vector<int> dp(cx.size() + 1);
	REP(i, cx.size()) {
		chmax(dp[i + 1], dp[i]);
		for (int v : g[i]) chmax(dp[v], dp[i] + 1);
	}
	cout << dp[cx.size()] << endl;
	return 0;
}


Measured memory_bytes: 13620
#include<iostream>
#include<cstdio>
#include<cstring>
#include<string>
using namespace std;
int main()
{
	int l;
	string a;
	cin>>a;
	l=a.length();
	for(int i=0;i<l;i++)
	{
		if(a[i]==',')	cout<<' ';
		else	cout<<a[i];
	}
	printf("\n");
	return 0;
}

Measured memory_bytes: 256
import collections
n = int(input())
v = list(map(int, input().split()))
a = []
b = []
for i in range(n // 2):
    a.append(v[(i+1)*2-1])
    b.append(v[(i+1)*2-2])
a = collections.Counter(a)
b = collections.Counter(b)


if a.most_common()[0][0] != b.most_common()[0][0]:
    print(n - a.most_common()[0][1] - b.most_common()[0][1])
elif len(a.most_common()) == 1 and len(b.most_common()) == 1:
    print(n//2)
elif a.most_common()[1][1] + b.most_common()[0][1] > a.most_common()[0][1] + b.most_common()[1][1]:
    print(n - a.most_common()[1][1] - b.most_common()[0][1])
else:
    print(n - a.most_common()[0][1] - b.most_common()[1][1])

Measured memory_bytes: 18656
#include <vector>
#include <iostream>
#include <algorithm>
#include <cstdio>
#include <cassert>


template <typename T> struct BIT {
  std::vector<T> tree;
  long long int size;

  BIT(long long int n) : tree(n + 1, (T)0), size(n) {}

  T sum(long long k) {
    T s = 0;
    assert(0 <= k && k < size);

    for (long long int i = k + 1; i > 0; i -= i & -i) {
      s = s + tree[i];
    }
    return s;
  }

  T range(long long int start, long long int end) {
    return sum(end) - sum(start - 1);
  }

  void add(long long int k, T v) {
    assert(0 <= k && k < size);
    for (long long int i = k + 1; i <= size; i += i & -i) {
      tree[i] = tree[i] + v;
    }
  }

  void debug() {
    for (long long int i = 0; i <= size; i++) {
      std::cout << tree[i] << " ";
    }
    std::cout << std::endl;
  }
};

using namespace std;
using ll = long long int;

ll N;
vector<ll> A;


bool check(ll mid) {
  //二分探索の目標値。 #{ m[i] | x <= m[i]} = objective となる最大の x を探す
  const ll comb = (N + 1) * N / 2;
  const ll objective = (comb + 1) / 2;

  vector<ll> s(N + 1);
  s[0] = 0;

  for (int i = 0; i < N; i++) {
    ll inc = A[i] < mid ? -1 : 1;
    s[i + 1] = s[i] + inc;
  }

  BIT<ll> bit(2 * N + 3);

  ll invs = 0;
  for (int i = 0; i <= N; i++) {
    ll idx = s[i] + N + 1;
    invs += bit.sum(idx);
    bit.add(idx, 1);
  }

  return invs >= objective;
}


int main() {
  cin >> N;
  for (int i = 0; i < N; i++)  {
    ll tmp; cin >> tmp; A.push_back(tmp);
  }

  ll left = 1;
  ll right = (ll)1e9 + 10;

  while (left < right) {
    ll mid = (left + right + 1) / 2;

//    printf("(%lld, %lld, %lld) - %lld \n", left, mid, right, invs);
//    for (ll n : s) cout << n << " "; cout << endl;

    if (check(mid)) { // satisfies
      left = mid;
    } else {
      right = mid - 1;
    }
  }

  assert(check(left + 1) == false);
  assert(find(A.begin(), A.end(), left) != A.end());

  cout << left << endl;
  return 0;
}


Measured memory_bytes: 3572
#include <iostream>
#include <stdlib.h>
#include <algorithm>
#include <string>
#include <vector>
#define rep(i, s, n) for (int i = s; i < (n); i++)
#define ll long long int
using namespace std;

int main(void) {
  ll a,b,c,k;
  
  cin >> a >> b >> c >> k;
  
  if (k - a <= 0) {
    cout << 1*k << endl;
  }
    else if (k - a- b <= 0) {
      cout << 1*a << endl;
    }
    else {
      cout << 1*a + (-1)*(k-a-b) << endl;
    }
    
  
  return 0;
}



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

int main() 
{
    int a, b;
    cin >> a >> b;
    int c = a+b;
    int d = a-b;
    int e = a*b;
    if (c >= d && c >= e) cout << c << endl;
    else if(d >= c && d >= e) cout << d << endl;
    else cout << e;
}

Measured memory_bytes: 256
#include <cstdio>
#include <algorithm>
#include <stack>
#include <utility>

using namespace std;

typedef pair<int, int> point;

int h, w;
int p[8][8], q[8][8];
const int d[4][2] = {{1, 0}, {0, 1}, {-1, 0}, {0, -1}};

void change(int c)
{
    stack<point> s;

    int b = q[0][0];
    s.push(point(0, 0));
    q[0][0] = c;
    while (!s.empty()) {
        int x = s.top().first, y = s.top().second;
        s.pop();

        for (int i = 0; i < 4; ++i) {
            int xx = x + d[i][0], yy = y + d[i][1];
            if (xx >= 0 && xx < w && yy >= 0 && yy < h && q[xx][yy] == b) {
                s.push(point(xx, yy));
                q[xx][yy] = c;
            }
        }
    }
}

int count()
{
    stack<point> s;
    bool v[8][8] = {};

    int c = 0;
    int b = q[0][0];
    s.push(point(0, 0));
    v[0][0] = true;
    while (!s.empty()) {
        int x = s.top().first, y = s.top().second;
        s.pop();

        ++c;
        for (int i = 0; i < 4; ++i) {
            int xx = x + d[i][0], yy = y + d[i][1];
            if (xx >= 0 && xx < w && yy >= 0 && yy < h && !v[xx][yy] && q[xx][yy] == b) {
                s.push(point(xx, yy));
                v[xx][yy] = true;
            }
        }
    }

    return c;
}

int main()
{
    for (;;) {
        int c;

        scanf("%d %d %d", &h, &w, &c);
        if (h == 0 && w == 0 && c == 0)
            break;

        for (int i = 0; i < h; ++i)
            for (int j = 0; j < w; ++j)
                scanf("%d", &p[j][i]);

        int m = 0;
        // 519 or 520 color patterns
        for (int i = 0; i < 6 * 6 * 6 * 6; ++i) {
            int b[5];
            b[0] = i / (6 * 6 * 6) % 6 + 1;
            b[1] = i / (6 * 6) % 6 + 1;
            b[2] = i / 6 % 6 + 1;
            b[3] = i % 6 + 1;
            b[4] = c;

            if (b[0] == p[0][0])
                continue;
            if (b[3] == c)
                continue;
            if (b[0] == b[1] || b[1] == b[2] || b[2] == b[3] || b[3] == b[4])
                continue;

            for (int i = 0; i < 8; ++i)
                for (int j = 0; j < 8; ++j)
                    q[i][j] = p[i][j];

            for (int j = 0; j < 5; ++j)
                change(b[j]);

            m = max(count(), m);
        }

        printf("%d\n", m);
    }

    return 0;
}

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

using namespace std;

int main() {
  int n;
  cin >> n;
  string s;
  cin >> s;
  int res = 0;
  for (int i = 0; i < n; i++) {
    if (s.substr(i, 3) == "ABC") {
      res += 1;
    }
  }
  cout << res << '\n';
  return 0;
}


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

using namespace std;
typedef long long ll;
typedef pair<int, int> P;

#define REP(i,n) for(int i=0;i<(int)n;++i)
#define REP2(i,n,s) for(int i=(int)s;i<(int)n;++i)
#define FOR(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)
#define ALL(c) (c).begin(), (c).end()

int main() {
    int h,w;cin>>h>>w;
    vector<string> s(h);
    REP(i,h) {
        string t;cin>>t;
        s[i] = t;
    }
    vector<P> d{
        P(0,1), P(1,1), P(1,0), P(1,-1), P(0,-1), P(-1,-1), P(-1,0), P(-1,1)
    };

    REP(i,h) {
        REP(j,w) {
            if(s[i][j] == '.') {
                int cnt = 0;
                FOR(k,d) {
                    if(i+(k->second)>=0 && i+(k->second)<h && j+(k->first)>=0 && j+(k->first)<w) {
                        if(s[i+(k->second)][j+(k->first)] == '#') cnt++;
                    }
                }
                s[i][j] = to_string(cnt)[0];
            }
        }
    }

    REP(i,h) {
        cout << s[i] << endl;
    }
}


Measured memory_bytes: 256
from bisect import bisect_left as bisect

s, t = input(), input()
lens, sets = len(s), set(s)

if not all(i in sets for i in t):
    print(-1)
    exit()

alp = [[] for i in range(26)]
for i, si in enumerate(s):
    alp[ord(si) - 97].append(i)

ans, cnt = 1 - lens, 0
for i in t:
    li = alp[ord(i) - 97]
    ans += lens * (cnt == 0)
    num = bisect(li, cnt)
    ans += lens * (num == len(li))
    cnt = (li[num % len(li)] + 1) % lens 
print(ans + (cnt - 1) % lens)


Measured memory_bytes: 80100
#include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define ALL(v) v.begin(), v.end()

typedef long long lint;

bool kaibun(string s){
    int size = s.size();
    bool flag = false;
    if(size == 1)
        return true;
    REP(i,size / 2){
        if(s[i] == s[size - 1 - i])
            flag = true;
        else{
            flag = false;
            break;
        }
    }
    return flag;
}
int main(){
    string s;
    cin >> s;
    if(!kaibun(s)){
        cout << "No" << endl;
        return 0;
    }
    string s1 = s.substr(0,(s.size() - 1) / 2);
    if(!kaibun(s1)){
        cout << "No" << endl;
        return 0;
    }
    string s2 = s.substr(((s.size() + 3)/2) - 1);
    if(!kaibun(s2)){
        cout << "No" << endl;
        return 0;
    }
    cout << "Yes" << endl;


    

}

Measured memory_bytes: 256
#include <iostream>

int main(){
  using namespace std;
  int n;
  cin >> n;
  int a[n];
  for(int i = 0; i < n; i++)
    cin >> a[i];
  int temp;
  int sum = 0;
  for(int i = 0; i < n; i++){
    cin >> temp;
    sum += temp;
  }
  int c[n - 1];
  for(int i = 0; i < n - 1; i++)
    cin >> c[i];
  
  int pre = n;
  for(int i = 0; i < n; i++){
    int current = a[i];
    if (current == pre + 1)
      sum += c[pre - 1];
    pre = current;
  }
  cout << sum << endl;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <string.h>
#include <math.h>
#include <algorithm>
#include <vector>
#include <iostream>
using namespace std;
int main(void){
	int n,i;
	long long int bnum;
	long long int anum;
	long long int sum=0;
	cin >> n;
	std::vector<long long int> a(n),b(n),c(n);
	for(i=0;i<n;i++){
		cin >> a[i];
	}
	for(i=0;i<n;i++){
		cin >> b[i];
	}
	for(i=0;i<n;i++){
		cin >> c[i];
	}
	std::sort(a.begin(),a.end());
	std::sort(b.begin(),b.end());
	std::sort(c.begin(),c.end());
	sum = 0;
	for(i=0;i<n;i++){
		anum = std::lower_bound(a.begin(),a.end(),b[i])-a.begin();
		bnum = std::upper_bound(c.begin(),c.end(),b[i])-c.begin();
		sum += anum*(n-bnum);
	}
	cout << sum << endl;
	return 0;
}

Measured memory_bytes: 2560
#include<iostream>
using namespace std;
int main()
{
  int n;
  for(;cin>>n;)
    {
      int a,v;
      cin>>a>>v;
      for(int i=1;i<n;i++)
	{
	  int ta,tv;
	  cin>>ta>>tv;
	  if(tv>v || (tv==v && a>ta))
	    {
	      v=tv;
	      a=ta;
	    }
	}
      cout<<a<<" "<<v<<endl;
    }
}

Measured memory_bytes: 1160
#include <bits/stdc++.h>
using namespace std;
//#include <boost/multiprecision/cpp_int.hpp>
//using multiInt = boost::multiprecision::cpp_int;

using ll = long long int;
using ld = long double;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
template<typename Q_temp>
using smaller_queue = priority_queue <Q_temp, vector<Q_temp>, greater<Q_temp> >;

const int INF = (int) 1e9;
const ll LINF = (ll) 4e18;
const ll MOD = (ll) (1e9 + 7);
const double PI = acos(-1.0);

#define REP(i,m,n) for(ll i = m; i < (ll)(n); ++i)
#define rep(i,n) REP(i, 0, n)
#define MP make_pair
#define MT make_tuple
#define YES(n) cout << ((n) ? "YES" : "NO") << endl
#define Yes(n) cout << ((n) ? "Yes" : "No") << endl
#define Possible(n) cout << ((n) ? "Possible" : "Impossible") << endl
#define all(v) v.begin(), v.end()
#define NP(v) next_permutation(all(v))
#define dbg(x_) cerr << #x_ << ":" << x_ << endl;
#define dbg2(x_) for(auto a_ : x_) cerr << a_ << " "; cerr << endl;
#define dbg3(x_ , sx_) rep(i, sx_) cerr << x_[i] << " "; cerr << endl;
vector<int> Dx = {0, 0, -1, 1, -1, 1, -1, 1, 0};
vector<int> Dy = {1, -1, 0, 0, -1, -1, 1, 1, 0};

inline ll CEIL(ll a, ll b) {
    return (a + b - 1) / b;
}

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

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int a, b;
    cin >> a >> b;
    cout << a - b + 1 << endl;

    return 0;
}



Measured memory_bytes: 256
#include <cstdio>

int k,x1,x2,x3,y1,y2,y3;
long long s;

int main()
{
	scanf("%lld",&s);
	for (x2=1,y3=1;1LL*(x2+10000)*(y3+10000)<s;x2=x2+10000,y3=y3+10000);
	for (k=1;1LL*x2*y3<s;k=k^1)
		if (k)
			x2++;
		else
			y3++;
	y2=1,x3=1LL*x2*y3-s;
	printf("%d %d %d %d %d %d\n",x1,y1,x2,y2,x3,y3);
	return 0;
}

Measured memory_bytes: 128
import java.util.*;
import static java.lang.Math.*;
import java.math.BigInteger;

public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		
		// 入力
		int n = sc.nextInt();
		long k = sc.nextLong();
		int MOD = 1000000007;
		ArrayList<Integer>[] list = new ArrayList[n+1];
		for(int i = 1; i <= n; i++){
		    list[i] = new ArrayList<Integer>();
		}
		for(int i = 0; i < n-1; i++){
		    int from = sc.nextInt();
		    int to = sc.nextInt();
		    list[from].add(to);
		    list[to].add(from);
		}

		// 計算
		long result = k;
		PriorityQueue<Integer> pq = new PriorityQueue<Integer>();
		int[] visited = new int[n+1];
		pq.add(1);
		visited[1] = 1;
		while(!pq.isEmpty()){
		    Integer now = pq.poll();
		    ArrayList<Integer> next = list[now];
		    long cnt = k - 1;
		    if(now == 1) cnt = k;
		    for(Integer i : next){
		        if(visited[i] == 1) continue;
		        visited[i] = 1;
		        pq.add(i);
		        cnt = max(cnt - 1, 0);
		        result = (result * cnt)%MOD;
		    }
		}

		// 出力
		System.out.println(result);

	}
}

Measured memory_bytes: 104872
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <string.h>
#include <queue>
#include <algorithm>
using namespace std;
typedef unsigned int uint;
typedef long long ll;
typedef pair<int, int> P;
const int c_INF = 111111111;
const int c_mINF = -111111111;
const int c_YET = -1;
const int c_Dx[4] = { 0,0,1,-1 };
const int c_Dy[4] = { 1,-1,0,0 };
const int c_div = 1000000007; //10^9 + 7


int main() {
	
	int A, B, C, D;
	scanf("%d%d%d%d", &A, &B, &C, &D);

	if (A + B > C + D)printf("Left");
	else if (A + B < C + D)printf("Right");
	else printf("Balanced");

}

Measured memory_bytes: 128
#include <iostream>
#include <cstdio>
#include <vector>
#include <queue>
#include <cmath>
#include <algorithm>
#include <functional>
using namespace std;
#define rep(i,n) for(int i=0;i<(n);++i)
#define rep1(i,n) for(int i=1;i<=(n);++i)
#define all(c) (c).begin(),(c).end()
#define pb push_back
#define fs first
#define sc second
#define show(x) cout << #x << " = " << x << endl
string s;
string ci(int &be);
string St(int &be){
	if(s[be]=='['){
		be++;
		string a=ci(be);
		be++;
		reverse(all(a));
		return a;
	}else{
		int cnt=0;
		while(s[be]=='+'||s[be]=='-'){
			if(s[be]=='+') cnt++;
			else cnt--;
			be++;
		}
		string l;
		if(s[be]!='?') l=(s[be]-'A'+cnt+2600000)%26+'A';
		else l="?";
		be++;
		return l;
	}
}
string ci(int &be){
	string ret;
	while(s[be]!=']') ret+=St(be);
	return ret;
}
int main(){
	while(true){
		cin>>s;
		if(s[0]=='.') break;
		s+=']';
		int be=0;
		string ans=ci(be);
		rep(i,ans.size()) if(ans[i]=='?') ans[i]='A';
		cout<<ans<<endl;
	}
}

Measured memory_bytes: 1196
#include<iostream>
#include<algorithm>
#include<cstring>
#include<cctype>
#include<string>
#include<stack>
#include<queue>
#include<set>
#include<map>
#include<cmath>

using namespace std;
using ll = long long;
const ll N = 1e6;
const double PI = acos(-1.0);

ll read();
int main()
{
    string s;
    cin>>s;
    int ans = 0;
    string str = s;
    reverse(str.begin(),str.end());
    for(int i = 0;i<(int)s.size()/2;i++)
    {
        if(s[i]!=str[i])ans++;
    }
    cout<<ans<<endl;

    return "BT7274", NULL;
}

inline ll read() {
    ll hcy = 0, dia = 1;char boluo = getchar();
    while (!isdigit(boluo)) {if (boluo == '-')dia = -1;boluo = getchar();}
    while (isdigit(boluo)) {hcy = hcy * 10 + boluo - '0';boluo = getchar();}
    return hcy * dia;
}

Measured memory_bytes: 256
#include<iostream>
#include<stdio.h>
using namespace std;
int main(){
	char a;
	while(1){
		scanf("%c",&a);
		if('a'<= a && a <='z'){
			printf("%c",a-32);
		}else if('A'<=a && a <='Z'){
			printf("%c",a+32);
		}else {
			cout<<a;
		}if (a == '\n'){
			break;
		}
	}
	return 0;
}



Measured memory_bytes: 3168
#![allow(non_snake_case, unused)]
use std::cmp::*;
use std::collections::*;
use std::f64::consts::*;

macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

    ($next:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };

    ($next:expr, mut $var:ident : $t:tt $($r:tt)*) => {
        let mut $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
}

macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };

    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };

    ($next:expr, usize1) => {
        read_value!($next, usize) - 1
    };

    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}

fn main() {
    input!{
        mut s: chars,
    }

    s.pop();
    loop {
        s.pop();
        if s.len() % 2 == 0 {
            let tmp = s.split_at(s.len() / 2);
            if tmp.0 == tmp.1 {
                println!("{}", s.len());
                return;
            }
        }
    }
}


Measured memory_bytes: 4352
#include<stdio.h>
#include<iostream>
using namespace std;

char X,Y;
int main (){
    cin >> X >> Y;
    if( X - '0' == Y - '0') cout << "=" << endl;
    else if( X - '0' < Y - '0') cout << "<" << endl;
    else cout << ">" << endl;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<int, int>;

#define rep(i, n) for (int i = 0; i < n; ++i)
#pragma region Debug
template <typename T>
void view(const std::vector<T> &v)
{
    for (const auto &e : v)
    {
        std::cout << e << " ";
    }
    std::cout << std::endl;
}
template <typename T>
void view(const std::vector<std::vector<T>> &vv)
{
    for (const auto &v : vv)
    {
        view(v);
    }
}
#pragma endregion

int main()
{
    int H, A;
    cin >> H >> A;
    int ans = ceil((float)H / (float)A);

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256