akhauriyash/Code-Regression huggingface dataset:
using System;
using System.Collections;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace AtCorder
{
	public class Program
	{
		static void Main(string[] args)
		{
			Scanner cin = new Scanner();
			int n = cin.Int();
			int k = cin.Int();
			int[] h = cin.ArrayInt(n);
			Array.Sort(h);
			int ans = 0;
			for (int i = 0; i < n; i++) {
				if (h[i] >= k) {
					ans = n - i;
					break;
				}
			}

			Console.WriteLine(ans);
		}
	}

	public class Scanner
	{
		private readonly char[] delimiter_ = new char[] { ' ' };
		private string[] buf_;
		private int index_;

		public Scanner()
		{
			buf_ = new string[0];
			index_ = 0;
		}

		public string Next()
		{
			if (index_ < buf_.Length) {
				return buf_[index_++];
			}

			string st = Console.ReadLine();
			while (st == "") {
				st = Console.ReadLine();
			}

			buf_ = st.Split(delimiter_, StringSplitOptions.RemoveEmptyEntries);
			if (buf_.Length == 0) {
				return Next();
			}

			index_ = 0;
			return buf_[index_++];
		}

		public int Int() => int.Parse(Next());
		public long Long() => long.Parse(Next());
		public double Double() => double.Parse(Next());

		public int[] ArrayInt(int N, int add = 0)
		{
			int[] Array = new int[N];
			for (int i = 0; i < N; i++) {
				Array[i] = Int() + add;
			}
			return Array;
		}

		public long[] ArrayLong(int N, long add = 0)
		{
			long[] Array = new long[N];
			for (int i = 0; i < N; i++) {
				Array[i] = Long() + add;
			}
			return Array;
		}

		public double[] ArrayDouble(int N, double add = 0)
		{
			double[] Array = new double[N];
			for (int i = 0; i < N; i++) {
				Array[i] = Double() + add;
			}
			return Array;
		}
	}
}

Measured memory_bytes: 17888
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define REP(i,n) for(ll i=0, i##_len=(n); i<i##_len; ++i)
#define REPR(i,n) for(ll i = n;i >= 0;--i)
#define FOR(i,m,n) for(ll i = m, i##_len=(n);i <i##_len; ++i)
#define all(x) (x).begin(),(x).end()
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
const int INF = 1e9;
const ll LLINF = 1e16;

ll modinv(ll a, ll m) {
    ll b = m, u = 1, v = 0;
    while (b) {
        ll t = a / b;
        a -= t * b; swap(a, b);
        u -= t * v; swap(u, v);
    }
    u %= m;
    if (u < 0) u += m;
    return u;
}

bool weql(string s1,string s2)
{
    REP(i,s1.size()){
        if(!(s1[i] == s2[i] || s2[i] == '?' || s1[i] == '?')){
            return false;
        }
    }
    return true;
}


int main(void)
{
    string s;
    string t;
    cin >> s;
    cin >> t;

    bool flag = false;
    REPR(i,s.size() - t.size()){
        if(weql(t,s.substr(i,t.size()))){
            REP(j,t.size()){
                s[i+j] = t[j];
            }
            flag = true;
            break;
        }
    }

    if(flag){
        REP(i,s.size()){
            if(s[i] == '?'){
                s[i] = 'a';
            }
        }
        cout << s << endl;
    }
    else{
        cout << "UNRESTORABLE" << endl;
    }

    return 0;
}

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

int main() {
  string S;
  cin >> S;
  regex R ("(dream(er)?|eraser?)+");
  // regex R ("(dream|dreamer|erase|eraser)+");
  cout << ((regex_match(S, R)) ? "YES" : "NO") << "\n";
}

Measured memory_bytes: 40960
#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>

using namespace std;

string solve(int a, int b){
    if(a <= 0 && b >= 0) return "Zero";
    if(b < 0){
        if((b - a + 1) % 2 == 0) return "Positive";
        return "Negative";
    }
    return "Positive";
}

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

    int a,b;
    cin >> a >> b;
    cout << solve(a,b) << endl;

    return 0;
}


Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace AOJ
{
	class Program
	{
		static void Main(string[] args)
		{
			var n = 0;
			while ((n = int.Parse(Console.ReadLine())) != -1)
			{
				var l = new List<char>();
				while (n > 0)
				{
					l.Add((char)(n % 4 + '0'));
					n /= 4;
				}
				if (l.Count == 0) l.Add('0');
				Console.WriteLine(new string(l.AsEnumerable().Reverse().ToArray()));
			}
		}
	}
}

Measured memory_bytes: 5656
#include <bits/stdc++.h>
#define all(x) begin(x), end(x)
#define dbg(x) cerr << #x << " = " << x << endl
#define _ << ' ' <<
using namespace std;
using ll = long long;
using vi = vector<int>;


int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    int x;
    cin >> x;
    if (x == 3 || x == 5 || x == 7)
        cout << "YES";
    else
        cout << "NO";
}


Measured memory_bytes: 256
#include <iostream>
#include <numeric>
#include <vector>
#include <cmath>
#include <string>
#include <algorithm>
#include <set>
#include <map>
using namespace std;
using ll=long long;
const ll MOD=1000000007;
#define rep(i,a,b) for(ll i=a;i<b;i++)

int main(){
    string s;
    cin>>s;
    ll ans=0,ss=s.size();
    rep(i,0,ss){
        if((s[i]^i)&1) ans++;
    }
    cout<<min(ans,ss-ans);
}


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

using namespace std;

#define int long long
#define all(v) begin(v), end(v)
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define reps(i, s, n) for(int i = (int)(s); i < (int)(n); i++)

template<class T1, class T2> void chmin(T1 &a, T2 b){if(a>b)a=b;}
template<class T1, class T2> void chmax(T1 &a, T2 b){if(a<b)a=b;}

using pint = pair<int, int>;
using tint = tuple<int, int, int>;
using vint = vector<int>;

const int inf = 1LL << 55;
const int mod = 1e9 + 7;

struct UnionFind {
  vector<int> data;
  UnionFind(){}
  UnionFind(int sz):data(sz, -1){}
  int find(int x) {
    return data[x] < 0 ? x : data[x] = find(data[x]);
  }
  int size(int x) {
    return -data[find(x)];
  }
  bool same(int x, int y) {
    return find(x) == find(y);
  }
  bool unite(int x, int y) {
    x = find(x), y = find(y);
    if(x == y) return false;
    if(data[x] < data[y]) swap(x, y);
    data[x] += data[y];
    data[y] = x;
    return true;
  }
};

#define MAX_N 100000

int N, M, num;
vint w, ord, low, cmp, conn, val, sz;
vector<vint> graph, tree;
vector< pair<int, int> > edges;
vector<bool> vis;

UnionFind uf;

void dfs(int u, int p, int &k) {
  vis[u] = true;
  ord[u] = low[u] = k++;
  for(int v : graph[u]) {
    if(!vis[v]) {
      dfs(v, u, k);
      chmin(low[u], low[v]);
      if(ord[u] >= low[v]) uf.unite(u, v);
    } else if(v != p) {
      chmin(low[u], ord[v]);
    }
  }
}

void compose() {
  uf = UnionFind(N);
  vis.resize(N);
  ord.resize(N);
  low.resize(N);
  cmp.resize(N);
  int k = 0;
  dfs(0, -1, k);
  num = 0;
  conn.resize(N);
  rep(u, N) if(u == uf.find(u)) conn[u] = num++;
  rep(u, N) cmp[u] = conn[uf.find(u)];
  tree.resize(num);
  for(auto e : edges) {
    int x = cmp[e.first], y = cmp[e.second];
    if(x == y) continue;
    tree[x].push_back(y);
    tree[y].push_back(x);
  }
}

int dp1[MAX_N]; // modoreru
int dp2[MAX_N]; // modoranai

int solve(int u, int p) {
  int res = 0;
  for(int v : tree[u]) {
    if(v == p) continue;
    chmax(res, solve(v, u));
    dp1[u] += dp1[v];
  }
  if(sz[u] >= 3 || dp1[u] > 0) dp1[u] += val[u];
  res += val[u];
  for(int v : tree[u]) {
    if(v == p) continue;
    chmax(res, dp1[u]-dp1[v]+dp2[v]);
  }
  return dp2[u] = res;
}

signed main()
{
  cin.tie(0);
  ios_base::sync_with_stdio(0);
  cout << fixed << setprecision(12);

  cin >> N >> M;
  w.resize(N);
  rep(i, N) cin >> w[i];
  graph.resize(N);
  rep(i, M) {
    int u, v;
    cin >> u >> v; --u, --v;
    graph[u].push_back(v);
    graph[v].push_back(u);
    edges.emplace_back(minmax(u, v));
  }
  compose();
  val.resize(num);
  sz.resize(num);
  rep(u, N) {
    val[cmp[u]] += w[u];
    sz[cmp[u]] = uf.size(u);
  }
  cout << solve(cmp[0], -1) << endl;

  return 0;
}

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

using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
typedef tuple<ll,ll,ll> TUP;
#define a first
#define b second
#define sz size()
#define pb(x) push_back(x) 
#define bg begin()
#define ed end()
#define rep(i,n) for(ll i=0;i<n;i++)
#define rep1(i,n) for(ll i=1;i<=n;i++)
#define mp(x,y) make_pair(x,y)
const ll MOD=1000000007;

//a,b x
int main(){
	ll N; cin>>N;
    vector<ll> A(N);
    rep(i,N) cin>>A[i];
	sort(A.bg,A.ed);
	ll ma=A[N-1];
	//0~N-2で,*2がmaに近いもの添え字
	ll i=0;
	ll d=1000000000;
	ll ans=0;
	while(i<=N-2){
		if(abs(A[i]*2-ma)<=d){
			ans=A[i];
			d=abs(A[i]*2-ma);
		}
		i++;
	}
	printf("%lld %lld",ma,ans);
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
typedef long long ll;
#define  rep(i,a,b)for(long long i=a;i<b;++i)
#define  rrep(i,a,b)for(int i=a;i>=b;--i)
#define  yesno(flag)if(flag)cout<<"Yes"<<endl; else cout<<"No"<<endl;
using namespace std;
const ll INF=1000000000000LL;
const ll r197=1000000007;
typedef pair<ll,ll>P;
typedef pair<int,P>Pa;
bool Inframe(int a,int b,int c,int d,int h,int w){
	if(a+b>=0&&a+b<h&&c+d>=0&&c+d<w)return true;
	return false;
}

ll dp[101][100005],w;
int n,v[101],h[100];
int main() {
	memset(dp,0,sizeof(dp));
	cin>>n>>w;
	rep(i,0,n){
		cin>>h[i]>>v[i];
	}
	rep(i,0,n){
		rep(j,0,w){
			if(j+h[i]<=w){
				dp[i+1][j+h[i]]=max(dp[i+1][j+h[i]],dp[i][j]+v[i]);
			}
			dp[i+1][j]=max(dp[i+1][j],dp[i][j]);
		}
	}
	ll ans=0;
	rep(j,0,w+1){
		ans=max(ans,dp[n][j]);
	}
	cout<<ans<<endl;
	return 0;
}


Measured memory_bytes: 79104
#include <stdio.h>

int main(void) {

  long n,d,x,y,count = 0;
  scanf("%ld %ld", &n, &d);
  d = d*d;
  for (long i = 0; i < n; i++) {
    scanf("%ld %ld", &x, &y);
    if (x*x+y*y <= d) {
      count++;
    }
  }
  printf("%ld\n", count);

  return 0;
}

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

# define REP(i,n) for (int i=0;i<(n);++i)
# define rep(i,a,b) for(int i=a;i<(b);++i)
# define p(s) std::cout << s ;
# define pl(s)  std::cout << s << endl;
# define printIf(j,s1,s2) cout << (j ? s1 : s2) << endl;
# define YES(j) cout << (j ? "YES" : "NO") << endl;
# define Yes(j) std::cout << (j ? "Yes" : "No") << endl;
# define yes(j) std::cout << (j ? "yes" : "no") << endl;
# define all(v) v.begin(),v.end()
# define showVector(v) REP(i,v.size()){p(v[i]);p(" ")} pl("")
template<class T> inline bool chmin(T &a, T b){ if(a > b) { a = b; return true;} return false;}
template<class T> inline bool chmax(T &a, T b){ if(a < b) { a = b; return true;} return false;}
typedef long long int ll;
typedef pair<ll,ll> P_ii;
typedef pair<double,double> P_dd;

template<class T>
vector<T> make_vec(size_t a){
    return vector<T>(a);
}

template<class T, class... Ts>
auto make_vec(size_t a, Ts... ts){
  return vector<decltype(make_vec<T>(ts...))>(a, make_vec<T>(ts...));
}

template<typename T,typename V>
typename enable_if<is_class<T>::value==0>::type
fill_v(T &t,const V &v){t=v;}

template<typename T,typename V>
typename enable_if<is_class<T>::value!=0>::type
fill_v(T &t,const V &v){
  for(auto &e:t) fill_v(e,v);
}


const int MOD = 1000000007;
const int inf=1e9+7;
const ll longinf=1LL<<60 ;

void addM(long long &a, long long b) {
    a += b;
    if (a >= MOD) a -= MOD;
}

void mulM(long long &a, long long b) {
    a = ((a%MOD)*(b%MOD))%MOD ;
}

const int MAX = 510000;
long long fac[MAX], finv[MAX], inv[MAX];

// テーブルを作る前処理
void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}

// 二項係数計算
long long COM(int n, int k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

vector<pair<long long, long long> > prime_factorize(long long n) {
    vector<pair<long long, long long> > res;
    for (long long p = 2; p * p <= n; ++p) {
        if (n % p != 0) continue;
        int num = 0;
        while (n % p == 0) { ++num; n /= p; }
        res.push_back(make_pair(p, num));
    }
    if (n != 1) res.push_back(make_pair(n, 1));
    return res;
}

map<ll,ll> memo;
 
ll rec(ll n){
    if(n == 0) return 1;
    if(n == 1) return 2;
    if(memo.count(n)) return memo[n];

    return memo[n] = (rec(n / 2) + rec(n / 2 - 1) + rec((n - 1) / 2))%MOD;;
}

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

    cout << rec(n) << endl;
  
    return 0;
}

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

using namespace std;
	
	
class Hoge{
			
		int iN,iK;
		string s0,s1;
		char* c1;
			
		public:
			Hoge(int);
		void convert();
									
		virtual ~Hoge(){	
						delete [] c1;
						}
};


Hoge::Hoge(int i0){
							
							//i0=3;
							//cout<<"i0?"<<endl;
							cin>>iN>>iK;
							c1=new char[iN];
							
							for(int icount=0;icount<iN;icount++){
							cin>>c1[icount];
							}//end for	
			}//end Hoge
void Hoge::convert(){
		
					//int i0=1;
					
			
			//	char* pc=c1;
							(c1[iK-1])=tolower(c1[iK-1]);
										
						for(int icount=0;icount<iN;icount++){
							cout<<c1[icount];
							}//end for
					
				
					}//endfunc
					





int main()
{
	
	Hoge* ph0=new Hoge(0);
	ph0->convert();

	//ph0->input();
	//ph0->output(3);
	//ph0->output0(3);
	
	

	
	//cout<<ph0->getichange()<<endl;
	
	
	delete ph0;
	
	
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using lint = long long;
template<class T = int> using V = vector<T>;
template<class T = int> using VV = V< V<T> >;

int main() {
  cin.tie(nullptr); ios::sync_with_stdio(false);
  int n; cin >> n;
  V<> a(n); for (auto&& e : a) cin >> e;
  int mn = 1e9;
  for (int i = 1; i < n; ++i) {
    int s = 0, t = 0;
    for (int j = 0; j < n; ++j) {
      (j < i ? s : t) += a[j];
    }
    mn = min(mn, abs(s - t));
  }
  cout << mn << '\n';
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const ll MOD = 1e9 + 7;
const ll INF = 1LL << 60;
#define rep(i, a, n) for (ll i = (a); i < (n); i++)
#define debug(x) cerr << #x << ": " << x << endl;
template<typename T1,typename T2> inline void chmin(T1 &a,T2 b){if(a>b) a=b;}
template<typename T1,typename T2> inline void chmax(T1 &a,T2 b){if(a<b) a=b;}

int main() {
    ll h, w, k;
    cin >> h >> w >> k;
    vector<string> s(h);
    rep(i, 0, h) cin >> s[i];

    ll ans = INF;
    vector<ll> id(h);
    rep(div, 0, 1<<(h-1)) {
        ll g = 0;
        rep(i, 0, h) {
            id[i] = g;
            if(div>>i&1) g++;
        }
        g++;
        vector<vector<ll>> c(h, vector<ll>(w, 0));
        rep(i, 0, h) rep(j, 0, w) c[id[i]][j] += (s[i][j] - '0');

        ll num = g-1;
        vector<ll> now(g);
        auto add = [&](ll j) {
            rep(i, 0, g) now[i] += c[i][j];
            rep(i, 0, g) if(now[i] > k) return false;
            return true;
        };
        rep(j, 0, w) {
            if(!add(j)) {
                num++;
                now = vector<ll>(g);
                if(!add(j)) {
                    num = INF;
                    break;
                }
            }
        }
        chmin(ans, num);
    }
    cout << ans << endl;
}

Measured memory_bytes: 384
#include <iostream>

using namespace std;

int main() {
    int D; cin >> D;
    if(D==25){
        cout << "Christmas" << endl;
    }else if(D==24){
        cout << "Christmas Eve" << endl;
    }else if(D==23){
        cout << "Christmas Eve Eve" << endl;
    }else if(D==22){
        cout << "Christmas Eve Eve Eve" << endl;
    }
    return 0;
}

Measured memory_bytes: 256
import java.util.Arrays;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {

		new Main().run();
	}

	private void run() {
		Scanner scanner = new Scanner(System.in);
		int t = scanner.nextInt();
		StringBuilder builder = new StringBuilder();
		while (t-- > 0) {
			g = new char[12][6];
			ps = new boolean[12][6];
			for (int y = 0; y < 12; y++)
				g[y] = scanner.next().toCharArray();
			for (int i = 0;; i++) {
				boolean co = false;
				for (int j = 0; j < 12; j++) {
					Arrays.fill(ps[j], false);
				}

				for (int y = 0; y < 12; y++) {
					for (int x = 0; x < 6; x++) {
						step = 0;
						if (!cn(y, x, g[y][x]))
							continue;
						cr(y, x, g[y][x]);
						co = true;
					}
				}
				if (!co) {
					builder.append(i).append('\n');
					break;
				}
				for (int j = 0; j < 11; j++)
					for (int y = 0; y < 11; y++)
						for (int x = 0; x < 6; x++) {
							if (g[y][x] != '.' && g[y + 1][x] == '.') {
								g[y + 1][x] = g[y][x];
								g[y][x] = '.';
							}
						}
			}
			
		}
		System.out.print(builder);
	}

	private void cr(int y, int x, char p) {
		if (g[y][x] != p)
			return;
		g[y][x] = '.';
		for (int i = 0; i < 4; i++) {
			int nx = x + dx[i];
			int ny = y + dy[i];
			if (!isOK(nx, ny))
				continue;
			if (g[ny][nx] == 'O') {
				g[ny][nx] = '.';
				continue;
			}
			cr(ny, nx, p);

		}
	}

	private boolean cn(int y, int x, char p) {
		if (p == 'O' || p == '.' || p != g[y][x] || ps[y][x])
			return false;
		step++;
		if (step == 4)
			return true;
		ps[y][x] = true;
		for (int i = 0; i < 4; i++) {
			int nx = x + dx[i];
			int ny = y + dy[i];
			if (!isOK(nx, ny))
				continue;

			if (cn(ny, nx, p))
				return true;
		}
		return false;
	}

	private boolean isOK(int nx, int ny) {
		return 0 <= nx && nx < 6 && 0 <= ny && ny < 12;
	}

	int step;
	char[][] g;
	boolean[][] ps;
	int dx[] = { 1, 0, -1, 0 };
	int dy[] = { 0, 1, 0, -1 };

}

Measured memory_bytes: 22616
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> iint;
typedef pair<ll,ll> llll;
#define ALL(x) (x).begin(),(x).end()
const ll zero = 0;
const ll INF = 3000000000000000000; //10^18
const int inINF = 1000000000; //10^9
const ll MOD = 1000000007; //10^9+7
const ll MOD2 = 998244353;
void Yes() {printf("Yes\n");}
void No() {printf("No\n");}
void YES() {printf("YES\n");}
void NO() {printf("NO\n");}

int main(){
    int N;
    cin >> N;
    printf("%d\n", 10-N/200);
}

Measured memory_bytes: 3760
#include <bits/stdc++.h>
	#include <cstdio>
	#include <cstring>
	#include <cmath>
	#include <cstring>
	#include <chrono>
	#include <complex>
	#define endl "\n"
	#define ll long long int
	#define vi vector<int>
	#define vll vector<ll>
	#define vvi vector < vi >
	#define pii pair<int,int>
	#define pll pair<long long, long long>
	#define mod 1000000007
	#define mod2 998244353
	#define inf 1000000000000000001;
	#define all(c) c.begin(),c.end()
	#define sz(v) ((ll)(v).size())
	#define mp(x,y) make_pair(x,y)
	#define mem(a,val) memset(a,val,sizeof(a))
	#define eb emplace_back
	#define pb push_back
	#define f first
	#define s second
	#define dbg(a) cout<<#a<<" --> "<<(a)<<"\n";
	#define forn(i,n) for (ll i=0; i<(n); ++i)
	#define fornd(i,n) for (ll i=(n)-1; i>=0; --i)
	#define forab(i,a,b) for (ll i=(a); i<=(b); ++i)
	#define fast_io ios_base::sync_with_stdio(false),cin.tie(NULL),cout.tie(NULL)
	using namespace std;
	bool isPowerOfTwo(int x) {
    return x && (!(x & (x - 1)));
	}
	int takemod(int x) {
    return (x % mod + mod) % mod;
	}
 
	int fpow(int base, int power, int MOD) {
    int result = 1;
    base = base % MOD;
    while (power) {
        if (power & 1)
            result = (result * base) % MOD;
        base = (base * base) % MOD;
        power = power >> 1;
    }
    return result;
	}
 
	int modinv(int x) {return fpow(x, mod - 2, mod);}
	void solve()
	{
		ll n;
		cin>>n;
		vll A(n);
		ll sum=0;
		map<ll,ll> pq;
		forn(i,n)
		{
			cin>>A[i];
			pq[A[i]]++;
			sum+=A[i];
		}
		//dbg(sum);
		ll q;
		cin>>q;
		while(q--)
		{
			ll x,y;
			cin>>x>>y;
			pq[y]+=pq[x];
			cout<<sum-(x)*pq[x]+(pq[x])*y<<endl;
			sum=sum-(x)*pq[x]+(pq[x])*y;
			pq[x]=0;
			//dbg(sum);
		}

	}
	int main()
	{	
		#ifndef ONLINE_JUDGE
		freopen("input.txt","r",stdin);
		freopen("output.txt","w",stdout);
		#endif
		fast_io;
		int T=1;
	//	cin>>T;
		// cin.ignore(); must be there when using getline(cin, s)
		while(T--)
		{
			solve();
		}
		return 0;
	}


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

struct point{
	double x;
	double y;
};

struct line{
	point p1;
	point p2;
};

bool parallel(line l1, line l2){
	double dx1 = l1.p2.x - l1.p1.x;
	double dy1 = l1.p2.y - l1.p1.y;
	double dx2 = l2.p2.x - l2.p1.x;
	double dy2 = l2.p2.y - l2.p1.y;
	if(dy2 * dx1 == dy1 * dx2) return true;
	else return false;
}

int main(){
	line l1, l2;
	int n;
	cin >> n;
	for(int i = 0; i < n; i++){
		cin >> l1.p1.x >> l1.p1.y >> l1.p2.x >> l1.p2.y
			>> l2.p1.x >> l2.p1.y >> l2.p2.x >> l2.p2.y;
		if(parallel(l1,l2)) cout << "YES" << endl;
		else cout << "NO" << endl;
	}
	return 0;
}

Measured memory_bytes: 0
<?php
$n = intval(fgets(STDIN));
$A = array_map("intval", explode(" ", trim(fgets(STDIN))));
$A[] = 0;
$map = array_fill(0,13,0);
foreach($A as $a){
    $map[$a]++;
}
if($map[0] > 1){echo 0;exit;}
if($map[12] > 1){echo 0;exit;}
if(max($map) > 2){echo 0;exit;}
$count = 0;

for($i = 0; $i < 2**11; $i++){
    $map2 = array_fill(0,24,0);
    $map2[0] = $map[0];
    $map2[12] = $map[12];
    $bits = sprintf("%011b", $i);
    for($j = 1; $j <= 11; $j++){
        if($map[$j] == 0){
        }elseif($map[$j] == 1){
            if($bits[$j-1] == "0"){
                $map2[$j] = 1;
            }else{
                $map2[24-$j] = 1;
            }
        }else{
            $map2[$j] = 1;
            $map2[24-$j] = 1;
        }
    }
    $ret[implode("", $map2)] = true;
}
$maxGap = 0;
foreach($ret as $bits => $_){
    $minGap = 24;
    $bits2 = $bits.$bits;
    $gap = 24;
    for($i = 0; $i < strlen($bits2); $i++){
        if($bits2[$i] == 1){
            $minGap = min($minGap, $gap);
            $gap = 1;
        }else{
            $gap++;
        }
    }
    $maxGap = max($maxGap, $minGap);
}
echo $maxGap;


Measured memory_bytes: 4604
#include<bits/stdc++.h>
using namespace std;
int read() {
	int x=0; char ch;
	while(!isdigit(ch)) ch=getchar();
	while(isdigit(ch)) x=(x<<3)+(x<<1)+(ch^48), ch=getchar();
	return x;
}
int main() {
	int len, ans=0;
	string s;
	cin>>len>>s;
	for(int i=0;i+2<len;i++) {
		if(s[i]=='A'&&s[i+1]=='B'&&s[i+2]=='C') ans++;
	}
	cout<<ans;
}


Measured memory_bytes: 384
#include <iostream>
#include <sstream>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <string>
#include <vector>
#include <list>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <bitset>
#include <numeric>
#include <climits>
#include <cfloat>
using namespace std;

long long gcd(long long a, long long b){ // Ååöñ
    if(a == 0 || b == 0)
        return 0;
    if(b > a)
        swap(a, b);
    long long tmp;
    while((tmp = a % b) != 0){
        a = b;
        b = tmp;
    }
    return b;
}

long long lcm(long long a, long long b){ // Å¬ö{
    return a / gcd(a, b) * b;
}

int main()
{
    for(;;){
        long long a, b;
        if(!(cin >> a >> b))
            return 0;
        cout << gcd(a, b) << ' ' << lcm(a, b) << endl;
    }
}

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

// ----------- define --------------
#define int long long
#define vi vector<int>
#define vc vector<char>
#define ii pair<int,int>
#define fi first
#define sc second
#define all(x) (x).begin(),(x).end()
#define get_bit(x, k) ((x >> k) & 1)
// ---------------------------------

void MAIN() {
  int n, m;
  cin >> n >> m;
  vector<vector<ii>> a(n + 1);
  for (int i = 1; i <= m; i++) {
    int p, y;
    cin >> p >> y;
    a[p].push_back(ii(y, i));
  }
  vector<string> res(m + 1);
  for (int i = 1; i <= n; i++) {
    sort(all(a[i]));
    for (int j = 0; j < a[i].size(); j++) {
      string sa = to_string(i);
      while (sa.size() < 6) sa = "0" + sa;
      string sb = to_string(j + 1);
      while (sb.size() < 6) sb = "0" + sb;
      res[a[i][j].sc] = sa + sb;
    }
  }
  for (int i = 1; i <= m; i++) {
    cout << res[i] << '\n';
  }
}

signed main() {
  ios::sync_with_stdio(0); cin.tie(0);
  int T = 1;
  // cin >> T;
  while (T--) MAIN();
}


Measured memory_bytes: 11788
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int maxn = 6e3 + 7;
const ll mod = 1e9+7;

int n,m;

char c1[maxn], c2[maxn], c3[maxn];
int k1, k2, k3, len;

vector<bool> func(string s1, string s2){
    vector<bool> ans(len * 2 + 2, true);
    for(int i = -len; i <= len; i++){
        for(int j = 0; j < s1.size(); j++){
            int k = j - i;
            if(k >= 0 && k < s2.size() && (s1[j] != s2[k] && s1[j] != '?' && s2[k] != '?')){
                ans[i+len] = false;
                break;
            }
        }
    }
    return ans;
}

int main()
{
    string s1, s2, s3;
    cin >> s1 >> s2 >> s3;
    int ans = s1.size() + s2.size() + s3.size();
    len = ans;
    vector<bool> ab = func(s1, s2);
    vector<bool> ac = func(s1, s3);
    vector<bool> bc = func(s2, s3);
    //cout << s1 << '\n';
    //cout << s2 << '\n';
    //cout << s3 << '\n';
    for(int i = -len; i <= len; i++){
        if(ab[i + len] == false)continue;
        for(int j = -len; j <= len; j++){
            if(ac[j + len] == false)continue;
            int k = j - i;
            if(k >= -len && k <= len && bc[k + len]){
                int x = 0, y = i, z = j;
                int mn = min(x, min(y, z));
                x += s1.size();
                y += s2.size();
                z += s3.size();
                int mx = max(x, max(y, z));
                //cout << i << " " << j << " " << mn << ' ' << mx << '\n';
                ans = min(ans, mx - mn);
            }
        }
    }
    printf("%d\n", ans);



    return 0;
}


Measured memory_bytes: 384
import sys
sys.setrecursionlimit(200000)
input = sys.stdin.readline

N, = map(int, input().split())
A, = map(int, input().split())
L = [int(v) for v in input().split()]

ans = 0
for i in range(N):
    t = L[i]
    ans += min(t * 2, abs(A - t) * 2)

print(ans)

Measured memory_bytes: 3064
#include <iostream>
#include <vector>
#include <deque>
#include <algorithm>
#include <numeric>
#include <string>
#include <cstring>
#include <list>
#include <unordered_set>
#include <tuple>
#include <cmath>
#include <limits>
#include <type_traits>
#include <iomanip>
#include <map>
#include <unordered_map>
#include <queue>
#include <stack>
#include <set>
#include <bitset>
#include <regex>
#include <random>
#include<bits/stdc++.h>

using namespace std;

typedef long long ll;
#define rep(i,n)for(ll i=0;i<n;++i)
#define exout(x) printf("%.10f\n", x)
const double pi = acos(-1.0);
const ll MOD = 1000000007;
const ll INF = 1e18;
const ll MAX_N = 201010;

//組み合わせの余りを求める
ll fac[MAX_N], finv[MAX_N], inv[MAX_N];
void COMinit() {
	fac[0] = fac[1] = 1;
	finv[0] = finv[1] = 1;
	inv[1] = 1;
	for (int i = 2; i < MAX_N; i++) {
		fac[i] = fac[i - 1] * i % MOD;
		inv[i] = MOD - inv[MOD % i] * (MOD / i) % MOD;
		finv[i] = finv[i - 1] * inv[i] % MOD;
	}
}

// 二項係数計算
long long COM(ll n, ll k) {
	if (n < k) return 0;
	if (n < 0 || k < 0) return 0;
	return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

//最大公約数
ll gcd(ll x, ll y) {
	return y ? gcd(y, x % y) : x;
}

ll lcm(ll x, ll y) {
	if (x == 0 || y == 0)return 0;
	return (x / gcd(x, y) * y);
}

ll dx[4] = { 0,0,-1,1 };
ll dy[4] = { -1,1,0,0 };
char notes[110][10];

//long longしか使わない
//素数は1より大きい
//lower_boundは指定したkey以上の要素の一番左のイテレータをかえす
//upper_boundは指定したkeyより大きい要素の一番左のイテレータをかえす
int main() {
	ll n, k;
	cin >> n >> k;
	ll ans = 0;
	vector<ll>total(n + 1);
	rep(i, n+1) {
		total[i] = i;
	}
	rep(i, n) {
		total[i + 1] += total[i];
	}
	for (ll i = k;i <= n + 1;++i) {
		if (i != (n + 1)) {
			ans += (total[n] - total[n - i]) - total[i - 1] + 1;
		}
		else {
			ans++;
		}
		ans %= MOD;
	}
	cout << ans << endl;
	return 0;
}


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

int main()
{
  int n , r, i;
  cin>>n>>r;
  if(n <= 10)
  {
    i = r + 100 * (10 - n);
    cout<<i<<endl;
  }
  else
  {
	cout<<r<<endl;
  }
  return 0;
}
    

Measured memory_bytes: 256
using System;
class Program
{
	static void Main(string[] args)
  	{
    	string[] line = Console.ReadLine().Trim().Split(' ');
    	int a = int.Parse(line[0]);
    	int b = int.Parse(line[1]);
    	int c = int.Parse(line[2]);
      	
      	if(c - (a - b) < 0){
        Console.WriteLine(0);
        }else{
      	Console.WriteLine(c - (a - b));
        }
  	}
}

Measured memory_bytes: 11092
H,W = map(int,input().split())
f = list(list(str(input())) for i in range(H))

for i in range(H):
  for j in range(W):
    if f[i][j] == "#":
      continue
    
    count = 0
    if i > 0 and j > 0:
      if f[i-1][j-1] == "#":
        count+=1
    if i > 0:
      if f[i-1][j] == "#":
        count+=1
    if i > 0 and j < W-1:
      if f[i-1][j+1] == "#":
        count+=1
    if j > 0:
      if f[i][j-1] == "#":
        count+=1
    if j < W-1:
      if f[i][j+1] == "#":
        count+=1
    if i < H-1 and j > 0:
      if f[i+1][j-1] == "#":
        count+=1
    if i < H-1:
      if f[i+1][j] == "#":
        count+=1
    if i < H-1 and j < W-1:
      if f[i+1][j+1] == "#":
        count+=1
    
    f[i][j] = str(count)

for i in range(H):
  n = ""
  for j in range(W):
    n+=f[i][j]
  print(n)
    


Measured memory_bytes: 3188
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define MAXN 0x3f3f3f3f
int n;
int main()
{
    scanf("%d",&n);
    if(n%2)
    {
        cout<<n/2<<endl;
    }
    else
    {
        cout<<n/2-1<<endl;
    }
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
inline LL read()
{
    LL x=0,f=1;char ch=getchar();
    while(ch>'9'||ch<'0'){if(ch=='-')f=-1;ch=getchar();}
    while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();}
    return x*f;
}

const int maxn=1e5+7;
int cnt1[maxn],cnt2[maxn];
struct node
{
    int num,id;
    bool operator <(const node &b)const
    {
        return num>b.num;
    }
}a[maxn],b[maxn];

int main()
{
    int n=read();
    for(int i=1;i<maxn;i++){
        a[i].id=i;b[i].id=i;
    }
    int cntx=0,cnty=0;
    for(int i=1;i<=n;i++){
        int x=read();
        if(i&1){
            cntx++;
            a[x].num++;
        }
        else{
            cnty++;
            b[x].num++;
        }
    }
    sort(a+1,a+1+maxn-2);
    sort(b+1,b+1+maxn-2);
    int ans=maxn+7;
    if(a[1].id==b[1].id){
        ans=cntx+cnty-max(a[1].num+b[2].num,a[2].num+b[1].num);
    }
    else{
        ans=cntx+cnty-a[1].num-b[1].num;
    }
    printf("%d\n",ans);
    return 0;
}


Measured memory_bytes: 1792
#include <bits/stdc++.h>
#define rep(i,n) for(ll i=0;i<n;i++)
#define rep1(i,n) for(ll i=1;i<=n;i++)
#define repk(i,m,n) for(ll i=m;i<n;i++)
#define IOS ios::sync_with_stdio(false);cin.tie(0);
#define F first
#define S second
typedef long long ll;
typedef long double ld;
using namespace std;
const int MOD=1e9+7;
ll h[200005];
int main()
{
    ll n,k,sum=0;
    cin>>n>>k;
    rep(i,n)
    {
        cin>>h[i];
    }
    sort(h,h+n);
    if(k>=n) cout<<0;
    else
    {
        rep(i,n-k) sum+=h[i];
        cout<<sum;
    }
}


Measured memory_bytes: 1792
import java.util.*

fun main(args: Array<String>) {
    val sc = Scanner(System.`in`)

    val (x, y , a, b, c) = sc.nextLine().split(" ").map { it.toInt() }
    val p: List<Long> = sc.nextLine().split(" ").map { it.toLong() }.sortedDescending().subList(0, x)
    val q: List<Long> = sc.nextLine().split(" ").map { it.toLong() }.sortedDescending().subList(0, y)
    val r: List<Long> = sc.nextLine().split(" ").map { it.toLong() }.sortedDescending()

    println(listOf(p, q, r).flatten().sortedDescending().subList(0, x+y).sum())
}

Measured memory_bytes: 117848
def main():
    N=int(input())
    A=list(map(int,input().split()))
    B=list(map(int,input().split()))
    count=0
    for i in range(0,N):
        if A[i]<B[i]:
            count+=A[i]
            B[i]=B[i]-A[i]
            A[i]=0
            if A[i+1]<B[i]:
                count+=A[i+1]
                A[i+1]=0
            else:
                count+=B[i]
                A[i+1]=A[i+1]-B[i]
        else:
            count+=B[i]
    print(count)

if __name__ == '__main__':
    main()

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

I n;I vw[323456][2],dp[1024][100001];
I c1,c2;

void dfs(I i){
    I j=i/2;
    if(i>1){
        for(I k=c2;k+1;k--){
            if(dp[j-1][k]or!k){
                I ne=k+vw[i-1][1];
                if(ne<=c2)dp[i-1][ne]=max(dp[j-1][k]+vw[i-1][0],dp[i-1][ne]);
            }
            dp[i-1][k]=dp[j-1][k];
        }
    }
    if(i*2<=min(c1,n))dfs(i*2);
    if(i*2+1<=min(c1,n))dfs(i*2+1);
}

signed main(){
    cin>>n;
    //vw.resize(n);
    REP(i,n){I x,y;cin>>vw[i][0]>>vw[i][1];}
    c1=1024;c2=100000;
    //dp.resize(c1);REP(i,c1)dp[i].resize(c2+1);
    dp[0][vw[0][1]]=vw[0][0];
    dfs(1);
    REP(i,c1)REP(j,c2)dp[i][j+1]=max(dp[i][j],dp[i][j+1]);
    I q;cin>>q;
    REP(i,q){
        I v,l;cin>>v>>l;
        vector<I> cand;
        while(v>c1){
            cand.push_back(v);
            v=v/2;
        }
        I r=cand.size();
        I ans=0;
        REP(j,1<<r){
            I v_sub=0;I w_sub=0;
            REP(k,r){
                if(j>>k&1){
                    v_sub+=vw[cand[k]-1][0];
                    w_sub+=vw[cand[k]-1][1];
                }
            }
            if(w_sub<=l)ans=max(ans,dp[v-1][l-w_sub]+v_sub);
        }
        cout<<ans<<endl;
    }
}


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

// 総数を1000000007（素数）で割った余り
const long long mod = 1e9 + 7;

using ll = long long;
using pii  = pair<int, int>;
using pll = pair<ll, ll>;
#define ull unsigned long long
#define ld long double
#define vi vector<int>
#define vll vector<ll>
#define vc vector<char>
#define vs vector<string>
#define vpii vector<pii>
#define vpll vector<pll>

#define rep(i, n) for (int i = 0, i##_len = (n); i < i##_len; i++)
#define rep1(i, n) for (int i = 1, i##_len = (n); i <= i##_len; i++)
#define repr(i, n) for (int i = ((int)(n)-1); i >= 0; i--)
#define rep1r(i, n) for (int i = ((int)(n)); i >= 1; i--)

#define sz(x) ((int)(x).size())
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()

#define SORT(v, n) sort(v, v + n);
#define VSORT(v) sort(v.begin(), v.end());
#define RSORT(x) sort(rall(x));
#define pb push_back
#define mp make_pair

#define INF (1e9)
#define PI (acos(-1))
#define EPS (1e-7)

ull gcd(ull a, ull b) { return b ? gcd(b, a % b) : a; }
ull lcm(ull a, ull b) { return a / gcd(a, b) * b; }

int main(){
    int n, k;
    cin >> n >> k;
    vi l(n);
    rep(i, n) cin >> l[i];
    sort(l.begin(), l.end());
    int ans = 0;
    rep(i, k) ans += l[n-i-1];
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
import java.util.*;
public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int N = sc.nextInt();
    int ans = 1;
    int max = sc.nextInt();
    for(int i=1;i<N;i++){
      int H = sc.nextInt();
      max = Math.max(H,max);
      if(max==H){
        ans++;
      }
    }    
      System.out.println(ans);
  }
}

Measured memory_bytes: 35740
#include <iostream>
#include <set>
#include <map>
#include <vector>
#include <algorithm>
#include <iomanip>
#include <climits>
#include <numeric>
#include <cmath>
#include <queue>
#include <sstream>

using namespace std;
typedef long long ll;

int main() {
  int A, B, Q;
  cin >> A >> B >> Q;
  vector<ll> s(A), t(B);
  for (int i = 0; i < A; i++) {
    cin >> s[i];
  }
  for (int i = 0; i < B; i++) {
    cin >> t[i];
  }
  
  for (int i = 0; i < Q; i++) {
    ll x;
    cin >> x;
    ll res = LLONG_MAX;
    
    int it = lower_bound(s.begin(), s.end(), x) - s.begin();
    for (int i = max(0, it - 1); i < min(A, it + 1); i++) {
      ll y = s[i];
      int it2 = lower_bound(t.begin(), t.end(), y) - t.begin();
      for (int j = max(0, it2 - 1); j < min(B, it2 + 1); j++) {
        res = min(res, abs(x - y) + abs(y - t[j]));
      }
    }
    
    it = lower_bound(t.begin(), t.end(), x) - t.begin();
    for (int i = max(0, it - 1); i < min(B, it + 1); i++) {
      ll y = t[i];
      int it2 = lower_bound(s.begin(), s.end(), y) - s.begin();
      for (int j = max(0, it2 - 1); j < min(A, it2 + 1); j++) {
        res = min(res, abs(x - y) + abs(y - s[j]));
      }
    }
    cout << res << endl;
  }
  
  return 0;
}


Measured memory_bytes: 2944
#!/usr/bin/env python3
import sys
import fractions
from functools import reduce
def lcm(x, y):
    return (x * y) // fractions.gcd(x, y)

def lcm_list(numbers):
    return reduce(lcm, numbers)

def solve(N: int, M: int, a: "List[int]"):
    # 2でわれる回数が一緒じゃないとダメ
    b = a[0]
    count = 0

    while b%2 == 0:
        b //= 2
        count += 1

    for aa in a[1:]:
        tmp_count = 0

        while aa%2 == 0:
            aa //= 2
            tmp_count += 1
        
        if tmp_count == count:
            continue
        else:
            print(0)
            return
    lcm = lcm_list(a)
    print((M-lcm//2)//lcm + 1)
    return

def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    M = int(next(tokens))  # type: int
    a = [int(next(tokens)) for _ in range(N)]  # type: "List[int]"
    solve(N, M, a)

if __name__ == '__main__':
    main()


Measured memory_bytes: 18268
#!/usr/bin/env python3
import sys


def solve(X: int, Y: int, Z: int):
    print(Z, X, Y)
    return


# Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    X = int(next(tokens))  # type: int
    Y = int(next(tokens))  # type: int
    Z = int(next(tokens))  # type: int
    solve(X, Y, Z)


if __name__ == '__main__':
    main()


Measured memory_bytes: 3060
N = gets.to_i
hash = Hash.new(0)
CHECK = ["M","A","R","C","H"]
N.times do
  s = gets.chomp
  if CHECK.include?(s[0])
    hash[s[0]] += 1
  end
end
# p hash
if hash.size < 3
  puts 0
  exit
end
# binding.pry
ans = 0
htoa = hash.to_a
(1 << hash.size).times do |i|
  # p i.to_s(2)
  pre2 = 1
  count = 0
  # test = []
  hash.size.times do |j|
    if i >> j & 1 == 1
      count += 1
      pre2 *= htoa[j][1]
      # test << j
    end
  end
  if count == 3
    # p test, i
    # binding.pry
    ans += pre2
  end

end
puts ans

Measured memory_bytes: 2044
program Project1;

{$APPTYPE CONSOLE}

uses
  SysUtils;
var
  a,h,w,i,j,count,x,y,sw,m,n,b,c,soeji,sum,max,k,min:Integer;
  l:array of Integer;
  s,s123,s1,s2,s3:string;
  al:string = 'abcdefghijklmnopqrstuvwxyz';
  tf,tfl,tfr:Boolean;
begin
  try
    { TODO -oUser -cConsole メイン : ここにコードを記述してください }
    Readln(s);
    count:=0;
    max  :=0;
    min  :=100;

    Write  (10-strtoint(s[1]));
    Write  (10-strtoint(s[2]));
    Writeln(10-strtoint(s[3]));

    Readln;
  except
    on E: Exception do
      Writeln(E.ClassName, ': ', E.Message);
  end;
end.


Measured memory_bytes: 256
import java.util.Scanner;

class Main
{
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int x, y;
    while(true){
      x=sc.nextInt();
      y=sc.nextInt();
      if(x==0 && y==0) break;
      System.out.println( (x < y) ? x + " " + y : y + " " + x );
    }
  }
}

Measured memory_bytes: 36308
import java.util.Scanner;

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

    long M = 1_000_000_007;
    int N = scanner.nextInt();
    int[][] a = new int[N + 1][N];
    for (int i = 1; i <= N; i++) for (int j = 0; j < N; j++) a[i][j] = scanner.nextInt();

    long[] dp = new long[1 << N];
    dp[0] = 1;

    for (int i = 1; i < 1 << N; i++) {
      int j = countOnes(i);

      for (int k = 0; k < N; k++) {
        if ((i & (1 << k)) != 0) {
          dp[i] += dp[i ^ (1 << k)] * a[j][k];
          if (dp[i] > M) dp[i] -= M;
        }
      }
    }
    System.out.println(dp[(1 << N) - 1]);
  }

  public static int countOnes(int num) {
    num = num - ((num >> 1) & 0x55555555);
    num = (num & 0x33333333) + ((num >> 2) & 0x33333333);
    num = (num + (num >> 4)) & 0x0F0F0F0F;
    num = num + (num >> 8);
    num = num + (num >> 16);
    return num & 0x0000003F;
  }
}


Measured memory_bytes: 43988
<?php
fscanf(STDIN, "%d", $n);
$a = explode(" ", trim(fgets(STDIN)));
$b = explode(" ", trim(fgets(STDIN)));
$c = explode(" ", trim(fgets(STDIN)));
$ans = array_sum($b);
for ($i = 1; $i < $n; $i++) if ($a[$i] - $a[$i - 1] == 1) $ans += $c[$a[$i] - 2];
echo $ans;
?>

Measured memory_bytes: 4604
#include<bits/stdc++.h>
using ll = long long;
using namespace std;
const ll INF = 10000000000000000;
const ll mod = 1000000007;
ll tate[12345678], yoko[12345678], cost[4321][4321];
signed main() {
	ll n, m, cntn = 0, cntm = 0, ans = 0; cin >> n >> m;
	for (int h = 0; h < n; h++) { cin >> tate[h]; }
	sort(tate, tate + n);
	for (int h = 0; h < m; h++) { cin >> yoko[h]; }
	sort(yoko, yoko + m);
	ll ngtate = 0, ngyoko = 0;// n++; m++;
	while (true) {
		if (cntn == n && cntm == m) { break; }
		if (cntn == n) {
			ans += yoko[cntm];
			cntm++; continue;
		}
		if (cntm == m) {
			ans += tate[cntn];
			cntn++; continue;
		}
		if (tate[cntn] < yoko[cntm]) {
			ans += tate[cntn] * (m + 1 - ngyoko);
			ngtate++; cntn++;
		}
		else {
			ans += yoko[cntm] * (n + 1 - ngtate);
			ngyoko++; cntm++;
		}
	}
	cout << ans << endl;
	cin >> n; return 0;
}

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

#define FOR(i, a, b) for (int i = (a); i < (b); i++)

typedef long long ll;

struct Node {
  int depth;
  int x;
  map<int, Node *> children;
  Node(int in_x) : depth(0), x(in_x) {}
};

void SetNum(Node *parent, const int &num) {
  if (parent->depth == 3) return;
  FOR(i, 0, 10) {
    if (parent->children.count(i)) {
      SetNum(parent->children[i], num);
    }
  }
  if (parent->children.count(num) == 0) {
    Node *n = new Node(num);
    n->depth = parent->depth + 1;
    parent->children[num] = n;
  }
}

int main() {
  int n;
  cin >> n;
  vector<int> vec(n);
  FOR(i, 0, n) {
    char c;
    cin >> c;
    vec[i] = (int)c - 48;
  }

  Node *root = new Node(-1);
  FOR(i, 0, n) {
    SetNum(root, vec[i]);
    int a;
    a++;
  }

  int ans = 0;
  FOR(i, 0, 1000) {
    int digit0 = i / 100;
    int digit1 = (i % 100) / 10;
    int digit2 = (i % 10);
    if (root->children.count(digit0)) {
      if (root->children[digit0]->children.count(digit1)) {
        if (root->children[digit0]->children[digit1]->children.count(digit2)) {
          ans++;
        }
      }
    }
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 512
#include <bits/stdc++.h>
#define all(a) (a).begin(), (a).end()
#define REP(i, n) for(int (i)=0; (i)<(n); (i)++)
#define RREP(i, n) for(int (i)=(n)-1, (i)>=0; (i)--)
#define ios() cin.tie(0), ios::sync_with_stdio(false)
typedef long long ll;
typedef unsigned long long ull;
ll const MOD = 1e9+7;
ll const INF = 1e18;
using namespace std;

int main(){
    int a, b, c;
    cin >> a >> b >> c;
    string ans = "NO";
    int d = a;
    REP(i, b){
        if(d%b == c){
            ans = "YES";
        }
        d += a;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include<cstdio>
#include<cstdlib>
#include<cmath>
#include<climits>
#include<iostream>
#include<algorithm>
#include<stack>
#include<queue>
#include<vector>
#include<list>
#include<map>
#include<set>
typedef long long ll;
typedef unsigned long long ull;
using namespace std;
#define pb push_back
int dy[]={0, 0, 1, -1, 0};
int dx[]={1, -1, 0, 0, 0};

#define FOR(i,a,b) for (int i=(a);i<(b);i++)
#define RFOR(i,a,b) for (int i=(b)-1;i>=(a);i--)
#define REP(i,n) for (int i=0;i<(n);i++)
#define RREP(i,n) for (int i=(n)-1;i>=0;i--)
ll n,t,l,b;
bool isl[200],isb[200];
double dp[200][200];

ll index(ll i) {
    if(i > n) {
        return n - (i - n);
    }
    return i;
}

int main(){
    while(1) {
        cin >> n >> t >> l >> b;
        if(n < 5) {
            break;
        }
        REP(i,n + 1) {
            isl[i] = false;
            isb[i] = false;
        }

        REP(i,l) {
            ll lose;
            cin >> lose;
            isl[lose] = true;
        }
        REP(i,b) {
            ll back;
            cin >> back;
            isb[back] = true;
        }
        REP(i,t + 1) {
            REP(j,n + 1) {
                dp[i][j] = 0;
            }
        }

        REP(i,n + 1) {
            dp[0][i] = (i == 0);
        }

        REP(i,t) {
            REP(j,n) {
                FOR(k,1,7) {
                    if(isb[j]) {
                        dp[i + 1][k] += dp[i][j] * (1.0 / 6);
                    }else if(isl[j]) {
                        dp[i + 2][index(j + k)] += dp[i][j]  * (1.0 / 6);
                    }else {
                        dp[i + 1][index(j + k)] += dp[i][j] * (1.0 / 6);
                    }
                }
            }
        }
        double ans = 0;
        REP(i,t + 1) {
            ans += dp[i][n];
        }
        printf("%0.10f\n",ans);
    }
}




Measured memory_bytes: 3232
#define _CRT_SECURE_NO_WARNINGS
#define _USE_MATH_DEFINES
#pragma comment(linker, "/STACK:1024000000")
#pragma warning( disable : 6031)
#pragma warning( disable : 4244)
#include <cstdlib>
#include <cstdio>
#include <cstring>
#include <cstdint>
#include <climits>
#include <cassert>
#include <string>
#include <vector>
#include <iostream>
#include <map>
#include <stack>
#include <set>
#include <queue>
#include <numeric>
#include <algorithm>
#include <utility>
#include <bitset>
#include <cmath>
#include <sstream>
#include <functional>
#include <iomanip>
#include <random>
#include <unordered_map>
#include <unordered_set>
#include <chrono>

#define all(a) (a).begin(),(a).end()
#define sz(a) (int)(a).size()
#define eps (1e-15)

using namespace std;

mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

typedef long long ll;
typedef vector<int> vi;
typedef vector< vi > vvi;
typedef vector<double> vd;
typedef vector< vd > vvd;
typedef vector< string > vs;
typedef pair< int, int > pii;
typedef vector< pii > vpii;
typedef vector<ll> vll;
typedef vector<vector<long long>> vvll;
typedef tuple<int, int, int> tiii;
const long long mod = int(1e8);
const double eps9 = 1e-9;


int main() {
#ifdef LOCAL_MACHINE
	freopen("input.txt", "rt", stdin);
	freopen("output.txt", "wt", stdout);
#endif
	ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0); cout << setprecision(18) << fixed;
	int n;
	cin >> n;
	vector<bool> h(n), u(n);
	vector<vector<pii>> a(n);
	for (int i = 0; i < n; i++)
	{
		int an;
		cin >> an;
		for (int j = 0; j < an; j++)
		{
			int x, y;
			cin >> x >> y;
			x--;
			a[i].emplace_back(x, y);
		}
	}
	int res = 0;
	for (int mask = 0; mask < 1 << n; mask++)
	{
		bool ok = true;
		for (int i = 0; i < n; i++)
		{
			if (!(mask & (1 << i)))
				continue;
			for (auto pi : a[i])
			{
				if (bool(mask & (1 << pi.first)) != (bool)pi.second)
				{
					ok = false;
					break;
				}
			}
			if (!ok)
				break;
		}
		if (ok)
		{
			int cres = 0;
			int cmask = mask;
			while (cmask)
			{
				cres += 1 & cmask;
				cmask >>= 1;
			}
			res = max(res, cres);
		}

	}
	cout << res;
	return 0;

}

Measured memory_bytes: 256