akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <vector>
#include <queue>
#include <cmath>
#include <bitset>
#include <algorithm>
#include <set>
#include <string>
#include <queue>

#define rep(i, N) for(int (i) = 0; (i) < (N); (i) ++)
typedef long long ll;

using namespace std;
typedef pair<int, int> pii;

ll Min(ll x, ll y){
    return min(x, y);
}

void read(vector<ll> &as, int size){
    rep(i, size){
        cin >> as[i];
    }
}

vector<ll> ans(vector<ll> &arg1, vector<ll> &arg2, int x, int y){
    vector<ll> ans;
    rep(i, Min(x, arg1.size())){
        rep(j, Min(y, arg2.size())){
            ll tmp = arg1[i] + arg2[j];
            ans.push_back(tmp);
        }
    }
    sort(ans.begin(), ans.end(), greater<ll>());
    return ans;
}

int main(){
    int X, Y, Z, K;
    cin >> X >> Y >> Z >> K;
    vector<ll> as(X);
    vector<ll> bs(X);
    vector<ll> cs(X);

    read(as, X);
    read(bs, Y);
    read(cs, Z);

    sort(as.begin(), as.end(), greater<ll>());
    sort(bs.begin(), bs.end(), greater<ll>());
    sort(cs.begin(), cs.end(), greater<ll>());

    vector<ll> ans1 = ans(as, bs, K, K);
    vector<ll> ans2 = ans(ans1, cs, K, K);

    rep(i, K){
        cout << ans2[i] << endl;
    }

    return 0;
}


Measured memory_bytes: 43368
NN=raw_input()
N=raw_input()
A = [int(i) for i in N.split()]
swap=0

for i in range(int(NN)):
  mini = i
  for j in range(i,int(NN)):
    if A[j] < A[mini]:
      mini = j
  if i != mini:
    t = A[i]
    A[i] = A[mini]
    A[mini] = t
    swap+=1
      
print ' '.join([str(k) for k in A])
print swap

Measured memory_bytes: 4656
#include <cmath>
#include <cstdio>
#include <iostream>

using namespace std;

int main() {
    
    double a, b, c, d, e, f;
    while (cin >> a >> b >> c >> d >> e >> f) {
        double x = (e * c - b * f) / (e * a - b * d);
        double y = (d * c - a * f) / (d * b - a * e);
        
        printf("%.3f %.3f\n", floor(x * 1000 + 0.5) / 1000, floor(y * 1000 + 0.5) / 1000);
    }
    
    return 0;   
}

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

using namespace std;

using ld = double;

template <typename T>
void printv(const vector<T> &v)
{
    int sz = v.size();
    for (int i = 0; i < sz; i++)
    {
        cout << v[i] << " \n"[i == sz - 1];
    }
}

ld dx[8] = {1.0/sqrt(2),1,1.0/sqrt(2),0,-1.0/sqrt(2),-1,-1.0/sqrt(2),0}, dy[8] = {1.0/sqrt(2),0,-1.0/sqrt(2),-1,-1.0/sqrt(2),0,1.0/sqrt(2),1};

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

    int n,k;cin>>n>>k;
    vector<ld> x(n), y(n);
    for(int i=0;i<n;i++)
    {
        cin >> x[i] >> y[i];
    }
    constexpr int C_MAX = 80000;
    int count = C_MAX;
    ld ret = 1e15, xpos = 0, ypos = 0;
    ld dif = 200.0;
    while(count--)
    {
        if(count%20==0) dif /= 2;
        ld xtmp = xpos, ytmp = ypos;
        for(int i=0;i<8;i++)
        {
            ld nx = xtmp + dif * dx[i];
            ld ny = ytmp + dif * dy[i];
            vector<ld> dis;
            for(int j=0;j<n;j++)
            {
                ld d = (x[j]-nx) * (x[j]-nx) + (y[j]-ny) * (y[j]-ny);
                dis.push_back(sqrt(d));
            }
            sort(dis.rbegin(),dis.rend());
            ld sum = 0;
            for(int j=0;j<k;j++) sum += dis[j];
            if(sum < ret)
            {
                ret = sum;
                xpos = nx;
                ypos = ny;
            }
        }
    }
    cout << fixed << setprecision(10) << ret << endl;
    //cerr << xpos << " " << ypos << endl;
}



Measured memory_bytes: 3284
def myAnswer(N:int) -> int:
   lis = [i for i in range(1,N+1)]
   MAX = 0
   ans = 0
   for l in lis:
      counter = 0
      tmp = l
      while l != 0:
         l = l//2
         counter+=1
      if(MAX < counter):
         MAX = counter
         ans = tmp
   return ans


   

def modelAnswer():
   tmp=1
def main():
   N = int(input())
   print(myAnswer(N))

if __name__ == '__main__':
   main()

Measured memory_bytes: 3064
#include <stdio.h>
using namespace std;
int main(void){
   int i,j,H,W;
  
   while(1){
     scanf("%d %d",&H,&W);
   if(H==0&&W==0)break;
for ( int i = 0; i < H; i++ ){
   if(i==0||i==H-1){
      for(int j=0;j<W;j++)
      printf("#");
   printf("\n");
   }else{
   
   
   
   
    for ( int j = 0; j < W; j++ ){
        if(j==0||j==W-1 ){
            printf("#");
        } else {
            printf(".");
        }
    }
    printf("\n");
}
}
 printf("\n");

    
}

    
}



Measured memory_bytes: 2624
#include<bits/stdc++.h>
#define FAST ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0)
#define dofloat cout<<fixed<<setprecision(8)
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define bitcount __builtin_popcount
#define all(vec) vec.begin(),vec.end()
#define rall(vec) vec.rbegin(),vec.rend()
using namespace std;
typedef long long ll;
typedef long double ld;
typedef vector<long long> vl;
typedef pair<long long,long long> pll;
typedef vector<pair<long long,long long> > vll;
typedef vector<pair<int,int> > vii;
typedef vector<int> vi;
typedef pair<int,int> ii;
const long long MOD=1000000007;
const long long MAX=100005;
const long double PI=3.14159265359;
const long double G=9.807;
const long long INF=1e18;
const long double EPS=1e-6;
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
bool isprime(ll a){
  if(a==2)return 1;
  if(!(a&1))return 0;
  for(ll i=3;i*i<=a;i+=2)
    if(a%i==0)return 0;
  return 1;
}
ll mpow(ll base,ll exponent,ll modulus){
  if(modulus==1)return 0;
  long long result = 1;
  base=base%modulus;
  while(exponent){
    if(exponent%2 == 1)
	  result=(result*base)%modulus;
	  exponent=exponent>>1;
	  base=(base*base)%modulus;
  }
  return result;
}
ll minv(ll a,ll mod){
  ll _gcd=gcd(a,mod);
  assert(_gcd==1);
  return mpow(a,mod-2,mod);
}


/*
ll ncr(ll N,ll K){
	if(N<K)return 0;
	if(K==0)return 1;
	if(N==0)return 0;

	ll den=1;
	for(ll i=1;i<=K;i++)den*=i;
	ll num=1;
	while(K--){
		num*=N;
		if(num%den==0){
			num/=den;
			den=1;
		}
		N--;
	}

	return num;
}
*/
map<vl,ll>M;
ll n;
int main(){FAST;
cin>>n;
for(ll i=1;i<=n;i++){
	string s;
	cin>>s;
	vl f(26);
	for(auto it:s){
		f[it-'a']++;
	}
	M[f]++;
}
ll ans=0;
for(auto it:M){
	ans+=(it.se)*(it.se-1)/2;
}
cout<<ans;
return 0;
}

Measured memory_bytes: 29952
#include<iostream>
using namespace std;
int main(){
  int w;
  int B[10]={1,2,4,8,16,32,64,128,256,512};
  while(cin>>w){
    int u[10],c=0;
    for(int i=9;i>-1;i--){
      if(w>=B[i]){
	w-=B[i];
	u[c]=B[i];
	c++;
      }
    }
    for(int i=c-1;i>-1;i--){
      cout<<u[i];
      if(i!=0)cout<<" ";
    }
    cout<<"\n";
  }
  return 0;
}
    

Measured memory_bytes: 1160
# Aizu Problem 0297: The Last is the Best

import sys, math, os

# read input:
PYDEV = os.environ.get('PYDEV')
if PYDEV=="True":
    sys.stdin = open("sample-input.txt", "rt")


n = int(input())
for __ in range(n):
    K, P = [int(_) for _ in input().split()]
    K %= P
    print(K if K > 0 else P)

Measured memory_bytes: 7828
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> 
using namespace __gnu_pbds; 
using namespace std;
 
#define ff              first
#define ss              second
#define int             long long
#define pb              push_back
#define mp              make_pair
#define pii             pair<int,int>
#define vi              vector<int>
#define mii             map<int,int>
#define pqb             priority_queue<int>
#define pqs             priority_queue<int,vi,greater<int> >
#define MX              200005
#define mod             1000000007
#define inf             1e18
#define ps(x,y)         fixed<<setprecision(y)<<x
#define mk(arr,n,type)  type *arr=new type[n];
#define w(x)            int x; cin>>x; while(x--)
#define pw(b,p)         pow(b,p) + 0.1
mt19937                 rng(chrono::steady_clock::now().time_since_epoch().count());
 
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> pbds;
 
void codeforces()
{
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    #ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
    #endif
}
int32_t main()
{
    
    // w(t)
    {
        int n;
        cin>>n;
        map<string, int> m;
        for(int i=0; i<n; i++){
            string a;
            cin>>a;
            m[a]++;
        }
        cout<<"AC x "<<m["AC"]<<endl;
        cout<<"WA x "<<m["WA"]<<endl;
        cout<<"TLE x "<<m["TLE"]<<endl;
        cout<<"RE x "<<m["RE"]<<endl;
    }
    return 0;
}

Measured memory_bytes: 3636
#include <iostream>
using namespace std;
int a[100006];
int main () {
    int N;
    cin >> N;
    for (int x=1; x<=100; x++) {
        for (int y=1; y<=100; y++) {
            for(int z=1; z<=100; z++) {
                a[x*x+y*y+z*z+x*y+y*z+z*x]++;
            }
        } 
    }
    for (int i=1; i<=N; i++) {
        cout << a[i] << endl;
    }
}

Measured memory_bytes: 3816
N_K = list(map(int,input().split()))
h = list(map(int,input().split()))
h.sort()

for i in range(N_K[0]):
    if h[i] >= N_K[1]:
        print(N_K[0]-i)
        break
    elif i == (N_K[0]-1):
        print(0)

Measured memory_bytes: 11908
#include "bits/stdc++.h"
using namespace std;
using ll = long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using vi = vector<int>;
using vl = vector<ll>;
using vvi = vector<vi>;
using vvl = vector<vl>;
const ll INF = 1LL << 60;
const ll MOD = 1000000007;
template <class T>
bool chmax(T &a, const T &b) {
    return (a < b) ? (a = b, 1) : 0;
}
template <class T>
bool chmin(T &a, const T &b) {
    return (b < a) ? (a = b, 1) : 0;
}

struct UnionFind {
    vector<int> rank, parent, size;

    // +1 for 1-indexed nodes
    UnionFind(int n) : rank(n + 1, 0), parent(n + 1), size(n + 1, 1) {
        iota(parent.begin(), parent.end(), 0); // parent is itself
    }
    int root(int x) {
        if (x != parent[x]) {
            parent[x] = root(parent[x]);
        }
        return parent[x];
    }
    bool isSame(int x, int y) { return root(x) == root(y); }
    bool unite(int x, int y) { return link(root(x), root(y)); }
    bool link(int x, int y) {
        if (x == y)
            return false;
        if (rank[x] > rank[y]) {
            parent[y] = x;
            size[x] += size[y];
        } else {
            parent[x] = y;
            size[y] += size[x];
            if (rank[x] == rank[y]) {
                rank[y]++;
            }
        }
        return true;
    }
    int getSize(int x) { return size[root(x)]; }
};

int main() {
    int n, k, l;
    cin >> n >> k >> l;
    UnionFind road(n);
    UnionFind train(n);
    for (int i = 0; i < k; ++i) {
        int a, b;
        cin >> a >> b;
        a--;
        b--;
        road.unite(a, b);
    }
    for (int i = 0; i < l; ++i) {
        int a, b;
        cin >> a >> b;
        a--;
        b--;
        train.unite(a, b);
    }
    vi roadgrp(n, 0);
    vi traingrp(n, 0);
    map<pii, int> groups;
    for (int i = 0; i < n; ++i) {
        roadgrp[i] = road.root(i);
        traingrp[i] = train.root(i);
        groups[{roadgrp[i], traingrp[i]}]++;
    }
    for (int i = 0; i < n; ++i) {
        cout << groups[{roadgrp[i], traingrp[i]}];
        if (i == n - 1)
            cout << "\n";
        else
            cout << " ";
    }
    return 0;
}

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

public class Main {
    public static void main(String[] args) throws IOException {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        while (true) {
            String[] lines = br.readLine().split(" ");
            int h = Integer.parseInt(lines[0]);
            int w = Integer.parseInt(lines[1]);
            if (h == 0 && w == 0) {
                break;
            }
            char[][] list = new char[h][w];
            int[][] root = new int[h][w];
            for (int i = 0; i < h; i++) {
                list[i] = br.readLine().toCharArray();
            }
            int x = 0;
            int y = 0;
            boolean isLoop = false;
            while (list[y][x] != '.') {
                switch (list[y][x]) {
                case '>':
                    x++;
                    break;
                case 'v':
                    y++;
                    break;
                case '<':
                    x--;
                    break;
                case '^':
                    y--;
                    break;
                case '.':
                    break;
                }
                root[y][x]++;
                if (root[y][x] == 2) {
                    isLoop = true;
                    break;
                }
            }
            if (isLoop) {
                System.out.println("LOOP");
            } else {
                System.out.println(x + " " + y);
            }
        }
    }
}



Measured memory_bytes: 24668
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vvvi = vector<vvi>;
using vll = vector<ll>;
using vvll = vector<vll>;
using vvvll = vector<vvll>;
using vs = vector<string>;
using pll = pair<ll, ll>;
using vp = vector<pll>;
#define rep(i, n) for (int i = 0; i < (n); i++)
#define rea(i, a, b) for (int i = (a); i < (b); i++)
#define ALL(a) (a).begin(), (a).end()
#define SZ(x) ((int)(x).size())
#define PRINT(V) for (auto v:(V)) {cerr << v << " ";} cerr << endl
#define dump(x) cerr << #x << " : " << (x) << endl
#define dump2(x, y) cerr << "(" << #x << ", " << #y << ") = (" << x << ", " << y << ")" << endl
inline ll GCD(ll a, ll b){return b ? GCD(b, a % b) : a;}
const ll MOD = 1000000007;
const ll INF = 100000000000000000LL;
/* END OF TEMPLATE */

// 解説
int main(){
    cin.tie(0); ios::sync_with_stdio(false);
    ll N;
    cin >> N;
    vll s(N);
    rep(i, N){
        cin >> s[i];
    }
    ll ans = 0;
    rea(c, 1, N-1){
        ll score = 0;
        set<ll> st;
        st.clear();
        rep(k, N-1){
            ll A = N-1-k*c;
            ll B = A-c;
            if(B <= 0) break;
            if(st.find(N-1-k*c) != st.end() || st.find(k*c) != st.end())
                break;
            if(N-1-k*c == k*c) break;
            if(A <= 0 || A <= B) continue;
            score += s[N-1-k*c] + s[k*c];
            st.emplace(N-1-k*c);
            st.emplace(k*c);
            ans = max(ans, score);
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 7808
#include <iostream>
#include <string>
#include <vector>

typedef long long ll;

using namespace std;
int main() {
	int n;
	vector<int> hats(3,0);
	
	ll ans = 1;
	cin >> n;

	for (int i = 0; i < n; i++) {
		int a;
		cin >> a;
		ll count = 0;
		int last = 2;
		for(int j = 0; j < 3; j++) {
			if (hats[j] == a) {
				count++;
				last = j;
			}
		}
		ans = (ans * count) % 1000000007LL;
		hats[last]++;
	}




	cout << ans << endl;

	return 0;
}

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

int main() {
	int n, w[100], sum, s1, min, i;
	scanf("%d", &n);
	sum = 0;
	for (i = 0; i < n; i++) {
		scanf("%d", &w[i]);
		sum += w[i];
	}
	s1 = 0;
	min = sum;
	for (i = 0; i < n; i++) {
		s1 += w[i];
		if (abs(sum - 2 * s1) < min) {
			min = abs(sum - 2 * s1);
		}
	}
	printf("%d", min);
	return 0;
}

Measured memory_bytes: 128
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<map>
#include<set>
typedef long long ll;
static const int mod = 1e9;
using namespace std;

int main() {
	int r, g, b, n;
	int count = 0;
	cin >> r >> g >> b >> n;
	for (int i = 0; i <= n / r + 1; ++i) {
		for (int j = 0; j <= n / g + 1; ++j) {
			if((n-r*i-g*j)/b>=0&&(n-r*i-g*j)%b==0)++count;
		}
	}
	cout << count << endl;
	return 0;
}


Measured memory_bytes: 256
#include <string>
#include <iostream>
#include <algorithm>
using namespace std;
int n; string s, t[52];
int main() {
	while (cin >> n, n) {
		for (int i = 0; i < n; i++) {
			cin >> s; t[i] = s[0];
			for (int j = 1; j < s.size(); j++) {
				if (string("aeiou").find(s[j - 1]) != string::npos) t[i] += s[j];
			}
			t[i] += string(50 - t[i].size(), '_');
		}
		int ret = -1;
		for (int i = 1; i <= 50; i++) {
			string g[50];
			for (int j = 0; j < n; j++) g[j] = t[j].substr(0, i);
			sort(g, g + n);
			bool flag = true;
			for (int j = 1; j < n; j++) {
				if (g[j - 1] == g[j]) {
					flag = false; break;
				}
			}
			if (flag) {
				ret = i; break;
			}
		}
		cout << ret << endl;
	}
}

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

////////////
// ModInt //
////////////

// 四則演算の最も左に存在する値がModIntでなければキャストでバグる
// 例えばx = mint * 1000;やx = ModInt(1000) * mint;はいいがx = 1000 * mint;は駄目。
template<int64_t mod_ = 1'000'000'007>
class ModInt {
private:
	int64_t integer_;

public:
	constexpr ModInt(const int64_t initial_number = 0)
		: integer_(initial_number){}
	
	// 四則演算
	constexpr ModInt operator+(const ModInt& operand) const
	{
		ModInt ret{this->integer_ + operand.integer_};
		if (ret.integer_ >= mod_)
			ret.integer_ -= mod_;
		return ret;
	}
	constexpr ModInt operator-(const ModInt& operand) const
	{
		ModInt ret{this->integer_ - operand.integer_};
		if (ret.integer_ < 0)
			ret.integer_ += mod_;
		return ret;
	}
	constexpr ModInt operator*(const ModInt& operand) const
	{
		return {this->integer_ * operand.integer_ % mod_};
	}
	constexpr ModInt operator/(const ModInt& operand) const
	{
		return *this * (operand ^ (mod_ - 2));
	}

	// 単項演算子
	constexpr ModInt& operator++()
	{
		if (integer_ + 1 == mod_) integer_ = 0;
		else integer_++;
		return *this;
	}

	constexpr ModInt& operator--()
	{
		if (integer_ == 0) integer_ = mod_ - 1;
		else integer_--;
		return *this;
	}

	constexpr ModInt operator+()
	{
		return *this;
	}

	constexpr ModInt operator-()
	{
		if (integer_ == 0) return ModInt(0ll);
		else return ModInt(mod_ - integer_);
	}

	// 累乗
	constexpr ModInt operator^(const int64_t operand) const
	{
		ModInt ret{1}, pow_ope{this->integer_};
		for (int64_t pow{operand}; pow > 0; pow >>= 1)
		{
			if (pow & 1) ret *= pow_ope;
			pow_ope *= pow_ope;
		}
		return ret;
	}

	// 代入
	constexpr ModInt& operator=(const ModInt& operand)
	{
		this->integer_ = operand.integer_;
		return *this;
	}
	constexpr ModInt& operator+=(const ModInt& operand)
	{
		*this = *this + operand;
		return *this;
	}
	constexpr ModInt& operator-=(const ModInt& operand)
	{
		*this = *this - operand;
		return *this;
	}
	constexpr ModInt& operator*=(const ModInt& operand)
	{
		*this = *this * operand;
		return *this;
	}
	constexpr ModInt& operator/=(const ModInt& operand)
	{
		*this = *this / operand;
		return *this;
	}

	// その他
	constexpr operator int64_t() { return integer_; }

	constexpr ModInt getOne() const
	{
		return ModInt(1ll);
	}
	constexpr ModInt getZero() const
	{
		return ModInt(0ll);
	}

	static constexpr int64_t mod{mod_};
};
using Mint = ModInt<>;

int main()
{
	int N;
	scanf("%d", &N);
	std::vector<int64_t> A(N);
	for (auto& e: A)
		scanf("%lld", &e);
	int64_t count[60][2]{};
	Mint ans{};
	for (auto& e: A)
		for (int i{}; i < 60; i++)
		{
			Mint tmp{(1ll << i) % Mint::mod};
			tmp *= Mint(count[i][~e >> i & 1]);
			ans += tmp;
			count[i][e >> i & 1]++;
		}
	std::cout << ans << std::endl;

	return 0;
}

Measured memory_bytes: 2560
#include<bits/stdc++.h>
using namespace std;
#define ll long long int 
#define f first
#define s second
#define pb push_back
#define mod 1000000007
#define mp make_pair
#define fast 
#define f first
#define s second
#define endl "\n"
#define pie 3.1415926535

int main(){
    int n;
    cin >> n;
    long long sum=0;
    for(int i=1;i<=n;i++){
        for(int j=1;j<=n;j++){
            for(int k=1;k<=n;k++){
                sum+= __gcd(__gcd(i,j),k);
            }
        }
    }
    
    cout << sum <<endl;
}






Measured memory_bytes: 3636
import java.util.Scanner;

public class Main{
	public static void main(String args[]) {
		Scanner scan = new Scanner(System.in);
		int w = scan.nextInt();
		int n = scan.nextInt();
		int[] s = new int[w + 1];
		for (int i = 0; i < w; i++) {
			s[i] = i + 1;
		}
		s[w] = 0;
		for (int j = 0; j < n; j++) {
			String str = scan.next();
			String[] ab = str.split(",");
			int a = Integer.parseInt(ab[0]);
			int b = Integer.parseInt(ab[1]);
			s[w] = s[a - 1];
			s[a - 1] = s[b - 1];
			s[b - 1] = s[w];
		}
		for (int k = 0; k < w; k++) {
			System.out.println(s[k]);
		}
	}
}

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

public class Main {

	public static void main(String[] args) {
		final Scanner sc = new Scanner(System.in);
		
		final int N = sc.nextInt();
		sc.nextLine();
		
		final int[] hs = new int[N];
		for (int i = 0; i < N; i++) {
			hs[i] = sc.nextInt();
		}
		
		int count = 0;
		while (true) {
			int l = -1;
			for (int i = 0; i < N; i++) {
				final int h = hs[i];
				if (h > 0) {
					if (l < 0) {
						l = i;
					}
				} else {
					if (l >= 0) {
						// supply water
						for (int j = l; j < i; j++) {
							hs[j] = hs[j] - 1;
						}
						count++;
					}
					
					l = -1;
				}
			}
			
			if (l >= 0) {
				// supply water
				for (int j = l; j < N; j++) {
					hs[j] = hs[j] - 1;
				}
				count++;
			}
			
			if (Arrays.stream(hs).allMatch(j -> j == 0)) {
				break;
			}
		}
		
		System.out.println(count);
	}

}

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

typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> P;

#define fi first
#define se second
#define repl(i,a,b) for(ll i=(ll)(a);i<(ll)(b);i++)
#define rep(i,n) repl(i,0,n)
#define all(x) (x).begin(),(x).end()
#define dbg(x) cout<<#x"="<<x<<endl
#define mmax(x,y) (x>y?x:y)
#define mmin(x,y) (x<y?x:y)
#define maxch(x,y) x=mmax(x,y)
#define minch(x,y) x=mmin(x,y)
#define uni(x) x.erase(unique(all(x)),x.end())
#define exist(x,y) (find(all(x),y)!=x.end())
#define bcnt __builtin_popcount

#define INF 1e17
#define mod 1000000007

ll N,X,D;
ll x[55],y[55];
vector<int> g[55];
ll d1,d2;
vector<ll> ds;
ll dp[2][125001];
vector<int> idxs;

void dfs(ll v){
  for(int nv : g[v]){
    dfs(nv);
    x[v]+=x[nv];
    y[v]+=y[nv];
  }
}

int main(){
  cin>>N>>X>>D;
  cin>>x[0];
  y[0]=1;
  repl(i,1,N){
    ll p;
    cin>>x[i]>>p;
    p--;
    g[p].push_back(i);
    y[i]=1;
  }
  dfs(0);

  d1=mmin(50,D); d2=D-d1;
  for(ll i=1;i<d1;i*=2){
    ds.push_back(i);
    d1-=i;
  }
  if(d1>0)ds.push_back(d1);

  rep(i,2)rep(k,125001)dp[i][k]=INF;
  int crt=0,nxt=1;
  rep(j,51){
    if(j*y[0]<=125000)dp[crt][j*y[0]]=j*x[0];
  }
  repl(i,1,N){
    rep(j,ds.size()){
      rep(k,125001)dp[nxt][k]=INF;
      for(ll k=0;k<=125000;k++){
        if(k+y[i]*ds[j]<=125000)minch(dp[nxt][k+y[i]*ds[j]],dp[crt][k]+x[i]*ds[j]);
        minch(dp[nxt][k],dp[crt][k]);
      }
      swap(crt,nxt);
    }
  }

  ll res=0;
  rep(i,N)idxs.push_back(i);
  sort(all(idxs),[=](const int& a,const int& b){ return y[a]*x[b] > y[b]*x[a]; });
  rep(i,125001){
    ll rest=X-dp[crt][i];
    if(rest<0)continue;
    ll add=0;
    rep(j,N){
      if(x[idxs[j]]>1e9)continue;
      if(idxs[j]==0){
        ll cnt=rest/x[idxs[j]];
        rest-=x[idxs[j]]*cnt;
        add+=y[idxs[j]]*cnt;
        continue;
      }
      if(x[idxs[j]]*d2<=rest){
        rest-=x[idxs[j]]*d2;
        add+=y[idxs[j]]*d2;
      }else{
        ll cnt=rest/x[idxs[j]];
        rest-=x[idxs[j]]*cnt;
        add+=y[idxs[j]]*cnt;
      }
    }
    maxch(res,i+add);
  }
  cout<<res<<endl;
  return 0;
}


Measured memory_bytes: 2304
#include<iostream>
#include<algorithm>
#include<vector>
#include<string>
#include<queue>
#include<limits>
#include<math.h>

using namespace std;

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

    int t = 1, nd = n;
    while(nd/10 > 0){
        ++t;
        nd /= 10;
    }

    int ans = 0;

    for(int i=1; pow(10, i)<=n; i+=2){
        ans += pow(10, i) - 1 - pow(10, i-1) + 1;
    }

    if(t & 0b1) ans += n - pow(10, t-1) + 1;

    cout << ans << endl;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
//---------------------------
using namespace std;
//---------------------------
#define REP(i,n) for(int i = 0; i < (n); i++)
#define P(x) cout << (x) << "\n"

#define MOD 1000000007 // 1e9+7
#define PI 3.1415926525
#define ll long long int // 10^18
#define INF 1000000001 // 1e9+1

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

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

  // ifstream in("input.txt");
  // cin.rdbuf(in.rdbuf());

  int x;cin>>x;
  int maxn=1;
  for(int i=1;i<=50;i++){
    if(i*i<=x){
      maxn=max(maxn,i*i);
    }
    if(i*i*i<=x){
      maxn=max(maxn,i*i*i);
    }
    if(i*i*i*i<=x){
      maxn=max(maxn,i*i*i*i);
    }
    if(i*i*i*i*i<=x){
      maxn=max(maxn,i*i*i*i*i);
    }
    if(i*i*i*i*i*i<=x){
      maxn=max(maxn,i*i*i*i*i*i);
    }
    if(i*i*i*i*i*i*i<=x){
      maxn=max(maxn,i*i*i*i*i*i*i);
    }
    if(i*i*i*i*i*i*i*i<=x){
      maxn=max(maxn,i*i*i*i*i*i*i*i);
    }
    if(i*i*i*i*i*i*i*i*i<=x){
      maxn=max(maxn,i*i*i*i*i*i*i*i*i);
    }

  }
  P(maxn);
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <vector>
#include <algorithm>
#include <cmath>

using namespace std;
typedef long long int ll;

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

    for (int i = 1; i <= 9; i++) {
        for (int j = 1; j <= 9; j++) {
            if (i * j == N) {
                cout << "Yes" << endl;
                return 0;
            }
        }
    }
    cout << "No" << endl;
    return 0;
}


Measured memory_bytes: 256
import numpy as np

in_num = list(map(int, input().split()))
in_num2 = list(map(int, input().split()))
n = in_num[0]
m = in_num[1]
x = np.asarray(in_num2)

x = np.sort(x)
xsub = x[1:] - x[:-1] - 1

xsub = np.sort(xsub)[::-1]
xsum = np.max(x) - np.min(x)
xsub = np.sum(xsub[:n-1])
result = xsum + 1 - xsub - n
if result < 0:
    result = 0
print(result)

Measured memory_bytes: 23008
//@Author: wxyww
#include<cstdio>
#include<iostream>
#include<cstdlib>
#include<cstring>
#include<algorithm>
#include<queue>
#include<vector>
#include<ctime>
#include<cmath>
#include<map>
#include<string>
using namespace std;
typedef long long ll;
const int N = 1010;
ll read() {
	ll x = 0,f = 1; char c = getchar();
	while(c < '0' || c > '9') {if(c == '-') f = -1;c = getchar();}
	while(c >= '0' && c <= '9') {x = x * 10 + c - '0',c = getchar();}
	return x * f;
}
int ma[N][N];
struct node {
	int v,nxt;
}e[N * N];
int head[N * N],ejs;
void add(int u,int v) {
	e[++ejs].v = v;e[ejs].nxt = head[u];head[u] = ejs;
}
queue<int>q;
int du[N * N],ans,dep[N * N];
int main() {
	int tot = 0;
	int n = read();
	for(int i = 1;i <= n;++i)
		for(int j = 1;j < i;++j)
			ma[i][j] = ma[j][i] = ++tot;
	for(int i = 1;i <= n;++i) {
		int lst = 0;
		for(int j = 1;j < n;++j) {
			int x = read();
			add(ma[i][lst],ma[i][x]);
			du[ma[i][x]]++;
			lst = x;
		}
	}

	dep[0] = 0;
	q.push(0);
	while(!q.empty()) {
		int u = q.front();q.pop();
		for(int i = head[u];i;i = e[i].nxt) {
			int v = e[i].v;
			du[v]--;
			if(du[v] == 0) {
				dep[v] = dep[u] + 1;
				q.push(v);
			}
		}
	}

	for(int i = 1;i <= tot;++i) {
		if(!dep[i]) {
			puts("-1");return 0;
		}
		ans = max(ans,dep[i]);
	}
	cout<<ans;

	return 0;
}

Measured memory_bytes: 24064
class BinaryIndexedTree():
    def __init__(self, N):
        self.N = N
        self.arr = [0] * (N+1)

    def query(self, i):
        ret = 0
        i += 1
        while i:
            ret += self.arr[i]
            lsb = i & (-i)
            i -= lsb
        return ret

    def add(self, i, v):
        i += 1
        while i < self.N+1:
            lsb = i & (-i)
            self.arr[i] += v
            i += lsb

    def search(self, x):
        lo = -1
        hi = self.N
        while lo < hi:
            mid = (lo+hi)//2
            if self.query(mid) < x:
                lo = mid + 1
            else:
                hi = mid
        return lo


def main():
    N = int(input())
    P = list(map(int, input().split()))
    idx = [0] * N
    bit = BinaryIndexedTree(N)
    for i in range(N):
        idx[P[i]-1] = i
    ans = 0
    for i in range(N)[::-1]:
        bit.add(idx[i], 1)
        x = bit.query(idx[i])
        l = bit.search(x-1)
        ll = bit.search(x-2)
        r = bit.search(x+1)
        rr = bit.search(x+2)
        tmp = (idx[i]-l) * (rr-r) + (r-idx[i]) * (l-ll)
        ans += (i+1) * tmp
    print(ans)


if __name__ == "__main__":
    main()


Measured memory_bytes: 57580
#include <iostream>
#include <set>
using namespace std;
int main(){
  int n;
  set <int> a;

  cin>>n;
  for(int i=0,t;i<n&&cin>>t;i++) a.insert(t);

  for(int e:a){
    if(e!=*a.begin()) cout<<" ";
    cout<<e;
  }
  cout<<endl;
  return 0;

}



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

int main()
{
    int N;
    string S;
    cin >> N;
    cin >> S;
    
    string alpha = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
    
//    cout << alpha[25] << endl;
    
    for(int i=0; i<S.length(); i++){
//        cout << S[i] << endl;
        for(int j=0; j<alpha.length(); j++){
            if(S[i] == alpha[j]){
                cout << alpha[(j+N)%26];
            }
        }
    }
    cout << endl;
    return 0;
}


Measured memory_bytes: 256
#include <algorithm>
#include <cstdio>
#include <iostream>
#include <map>
#include <list>
#include <set>
#include <stack>
#include <string>
#include <queue>

using namespace std;

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

    if (A + B <= 2 * C) 
        printf("%d\n", X * A + Y * B);
    else {
        int t1 = min(X, Y), t2 = max(X, Y);
        int t3 = 2 * t1 * C + (X - t1) * A + (Y - t1) * B;
        int t4 = 2 * t2 * C;

        printf("%d\n", t3 <= t4 ? t3 : t4);
    }
}


Measured memory_bytes: 256
def main():
    N, M = map(int, input().split())
    cnts = [0 for _ in range(M)]
    for _ in range(N):
        A = list(map(int, input().split()))
        K = A.pop(0)
        for a in A:
            cnts[a-1] += 1
    
    ans = cnts.count(N)
    print(ans)


if __name__ == "__main__":
    main()

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

using namespace std;

void dfs(vector<vector<int>> &graph, vector<int> &counter, int child, int parent = 0) {
    for(int son : graph[child]) {
        if(son == parent) {
            continue;
        }

        counter[son] += counter[child];
        dfs(graph, counter, son, child);
    }
}

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

    vector<int> a(N), b(N);
    vector<int> p(Q), x(Q);

    vector<int> counter(N+1, 0);
    vector<vector<int>> graph(N+1, vector<int>{});

    for(int i = 0; i < N-1; i++) {
        cin >> a[i] >> b[i];
        graph[a[i]].push_back(b[i]);
        graph[b[i]].push_back(a[i]);
    }

    for(int i = 0; i < Q; i++) {
        cin >> p[i] >> x[i];
        counter[p[i]] += x[i];
    }

    dfs(graph, counter, 1);

    for(int i = 1; i <= N; i++) {
        cout << counter[i] << " ";
    }

	return 0;
}

Measured memory_bytes: 33520
#define _USE_MATH_DEFINES
#include<cmath>
#include<iostream>
#include<iomanip>
#include<string>
using namespace std;

int main(){
	double r;
	cin >> r;

	double S, L;
	S = M_PI*r*r;
	L = M_PI*r*2;

	cout << fixed << setprecision(5);
	cout << S << " " << L<<endl;

	return 0;
}

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

int main(){
    long long int a, b;
    cin >> a >> b;
    long long int ans = 0;
    if(a>b){
                      
        long long int i;
        for(i=1;i<1000000000000;i++){
        if((a*i)%b==0){
            ans = a*i;
            break;
        }
       
    }
    }
    else if(b>=a){
        
      long long int i;
    for(i=1;i<1000000000000;i++){
        if((b*i)%a==0){
            ans = b*i;
            break;
        }
       
    }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include<stdio.h>

int main(){
	
	char c;
	int i,j,k,l;
	int row,col;
	int table[101][101]={0};
	
	scanf("%d %d",&row,&col);
	
	for(i=0; i<row; i++){
		for(j=0; j<col; j++){
			scanf("%d%c",&table[i][j],&c);
			if(c == '\n'){
				break;
			}
		}
	}
		
	for(i=0; i<=row; i++){
		for(j=0; j<=col; j++){
			if(j!=0){
				printf(" ");
			}
			if(j<col){
				printf("%d",table[i][j]);
				table[i][col] += table[i][j];
				table[row][j] += table[i][j];
			}else{
				printf("%d",table[i][j]);
			}
		}
		printf("\n");
	}
	
	
	return 0;
}




Measured memory_bytes: 2076
n,m,c = map(int, input().split())
b = list(map(int, input().split()))

a = [list(map(int, input().split())) for i in range(n)]

def abc(aaa,bbb,c):
	tmp=sum([ai*bi for ai,bi in zip(aaa,bbb)])+c
	return tmp>0

count=0
for aaa in a:
	if abc(aaa,b,c):
		count+=1

print(count)

Measured memory_bytes: 3064
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cmath>
using namespace std;


int color[4];
int main(){
    memset(color,0,sizeof(color));
    cin>>color[0]>>color[1]>>color[2];

    int cnt=0;
    int ans=1;
    for(int i=0;i<3;i++){
        for(int j=i+1;j<3;j++){
            if(color[i]!=color[j]){
                cnt++;
            }
        }
        ans=max(ans,cnt);
    }
    printf("%d\n",ans);
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <climits>
#include <string>
#include <vector>
#include <utility>
#include <functional>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <cassert>

using namespace std;

typedef long long ll;
typedef pair<int, int> P;

#define REP(i, n) for (ll i = 0; i < n; i++)
#define REPR(i, n) for (ll i = n; i >= 0; i--)
#define FOR(i, m, n) for (ll i = m; i < n; i++)

int main() {
    int v,a[100][100]{};
    cin >> v;
    REP(i,v){
        int n,m;
        cin >> n >> m;
        REP(j,m){
            int u;
            cin >> u;
            a[i][u-1]=1;
        }
    }
    REP(i,v){
        cout << a[i][0];
        FOR(j,1,v){
            cout << " " << a[i][j];
        }
        cout << endl;
    }
    return 0;
}


Measured memory_bytes: 3120
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<cmath>
#include<random>
#include<stack>
#include<queue>
#include<bitset>
#include<sstream>

#define rep(i,n) for(int i=0;i<(n);i++) 
#define rep1(i,n) for(int i=1;i<(n);i++)
#define co(x) cout << x << endl
#define cosp(x) cout << x << " "

using namespace std;
using ll = long long;

int main(int argc, const char *argv[]){
    ll n,k,q;
    cin >> n >> k >> q;
    vector<ll> a(q),p(n,0);
    rep(i,q) cin >> a[i]; 
    rep(i,q){
        p[a[i]-1]++;
    }
    rep(i,n){
        if(p[i]>(q-k)){
            co("Yes");
        }else{co("No");}
    }
    return 0;
}

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

using namespace std;
typedef long long ll;
#define int ll

#define REP(i,n) for(ll i=0;i<n;++i)
#define SORT(name) sort(name.begin(), name.end())
#define ZERO(p) memset(p, 0, sizeof(p))
#define MINUS(p) memset(p, -1, sizeof(p))
#if 1
#  define DBG(fmt, ...) printf(fmt, ##__VA_ARGS__)
#else
#  define DBG(fmt, ...)
#endif

const ll LLINF = (1LL<<60);
const int INF = (1LL<<30);
const double DINF = std::numeric_limits<double>::infinity();
const int MOD = 1000000007;
#define MAX_N 100010
#define SUBMIT

ll N;
vector<ll> A;

// 現在 player のターンで、残りが cur
// 勝つ方を返す
enum Player { Alice = 0, Bob = 1 };
ll dfs(ll player, vector<ll> cur) {
    ll next_player = (player == Alice) ? Bob : Alice;
    // 判定
    ll valid = 0;
    ll valid_val = 0;
    REP(i, cur.size()) {
        if(cur[i] > 0) {
            valid++;
            valid_val = cur[i];
        }
        if(valid > 1) { break; }
    }
    if(valid == 1) {
        if(valid_val % 2 == 0) { return next_player; }
        return player;
    }
    for(int i = 1; i < (1 << cur.size()); ++i) {
        vector<ll> next_cur;
        copy(cur.begin(), cur.end(), back_inserter(next_cur));
        bool isDup = false;
        REP(j, cur.size()) {
            if( (i >> j) & 1 ) {
                if(next_cur[j] > 0) { next_cur[j]--; }
                else { isDup = true; }
            }
        }
        if(!isDup) {
            if(dfs(next_player, next_cur) == player) { return player; }
        }
    }
    return next_player;
}

string brute_force() {
    if(dfs(Alice, A) == Alice) { return "first"; }
    return "second";
}

string solve() {
    for(auto& a : A) {
        if(a % 2 != 0) { return "first"; }
    }
    return "second";
}

signed main()
{
#ifdef SUBMIT
    cin >> N;
    A.assign(N, 0);
    REP(i, N) { cin >> A[i]; }
    //string ans = brute_force();
    string ans = solve();
    printf("%s\n", ans.c_str());
#else

    auto Disp = [&]() {
        for(auto& a : A) { printf("%2lld ", a); }
        string ans = brute_force();
        printf("%s\n", ans.c_str());
    };

    N = 3;
    printf("N %lld\n", N);
    for(int i = 1; i <= 10; ++i) {
        A.assign(N, 0);
        A[0] = i;
        for(int j = 1; j <= 10; ++j) {
            A[1] = j;
            for(int k = 1; k <= 10; ++k) {
                A[2] = k;
                Disp();
            }
        }
    }
#endif
    return 0;
}


Measured memory_bytes: 1024
#include <iostream>
#include <vector>
#include <algorithm>
#include <functional>
#include <string>
#include <utility>
#include <cmath>
#include <iomanip>

using namespace std;

#define REP(i,n) for(int (i)=(0);(i)<(n);++i)
#define ll long long
#define INF 1000000000

int main()
{
	int n,ans=0;
	cin >> n;
	vector<int> p(n);

	REP(i,n){
		int a;
		cin >> a;
		p[i] = a;
	}

	sort(p.begin(),p.end(),greater<int>());

	p[0] /= 2;

	REP(i,n)ans += p[i];

	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 256
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <iostream>
#include <istream>
#include <iterator>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
#include <tuple>
#include <iomanip>
#include <climits>
using namespace std;

typedef long long ll;
typedef unsigned long long ull;
//typedef pair<ll, ll> P;
#define rep(i, n) for(ll i = 0; i < (n); i++)
#define revrep(i, n) for(ll i = (n)-1; i >= 0; i--)
#define pb push_back
#define f first
#define s second
#define chmin(x, y) x = min(x, y);
#define chmax(x, y) x = max(x, y);

//const ll INFL = LLONG_MAX;//10^18 = 2^60
const ll INFL = 1LL<<60;
//const int INF = INT_MAX;
const ll INF = 1 << 30;//10^9
ll MOD = 1000000007;
//ll MOD = 998244353;

vector<ll> dy = {0, 1, 0, -1, 1, 1, -1, -1, 0};
vector<ll> dx = {1, 0, -1, 0, 1, -1, 1, -1, 0};

void pres(double A, ll x = 10){cout << fixed << setprecision(x) << A << endl;}
void BinarySay(ll x, ll y = 60){rep(i, y) cout << (x>>(y-1-i) & 1); cout << endl;}
ll cnt_bit(ll x){return __builtin_popcountll(x);}

ll pow_long(ll x, ll k){
  ll res = 1;
  while(k > 0){
    if(k % 2) res *= x;
    x *= x; k /= 2;
  }
  return res;
}

ll pow_mod(ll x, ll k){
  ll res = 1;
  while(k > 0){
    if(k % 2){
      res *= x; res %= MOD;
    }
    x *= x; x %= MOD;
    k /= 2;
  }
  return res;
}

ll inverse(ll x){return pow_mod(x, MOD - 2);};

ll gcd(ll a, ll b){
    if(b == 0) return a;
    return gcd(b, a % b);
}

ll lcm(ll x, ll y){
  ll res = x / gcd(x, y);
  res *= y;
  return res;
};

//コンビネーション
const int MAXcomb = 200010;
ll fac[MAXcomb], finv[MAXcomb], inv[MAXcomb];
//facはn!,finvは1/n!
//invは逆元
void COMinit(){
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for(int i = 2; i < MAXcomb; 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;
    }
}
ll comb(int n, int k){
    if(n < k) return 0;
    if(n < 0 || k < 0) return 0;
    return fac[n] * finv[k] % MOD * finv[n-k] % MOD;
}

const int MAXkai = 200010;
ll kai_memo[MAXkai];
ll kai(ll N){
  if(kai_memo[N] != 0) return kai_memo[N];
  if(N <= 1) return 1;
  return kai_memo[N] = N * kai(N-1) % MOD;
}

ll H, W;
ll A[100][100];
bitset<30000> dp[100][100];
void solve(){
  cin >> H >> W;
  rep(i, H)rep(j, W) cin >> A[i][j];
  rep(i, H)rep(j, W){
    ll tmp; cin >> tmp;
    A[i][j] -= tmp;
    A[i][j] = abs(A[i][j]);
  }
  bitset<30000> x = 1, y = 1;
  x <<= (15000 - A[0][0]);
  y <<= (15000 + A[0][0]);
  dp[0][0] |= x;
  dp[0][0] |= y;
  rep(i, H)rep(j, W){
    if(i-1 >= 0){
      dp[i][j] |= (dp[i-1][j] << (A[i][j]));
      dp[i][j] |= (dp[i-1][j] >> (A[i][j]));
    }
    if(j-1 >= 0){
      dp[i][j] |= (dp[i][j-1] << (A[i][j]));
      dp[i][j] |= (dp[i][j-1] >> (A[i][j]));
    }
  }
  ll ans = INF;
  rep(i, 30000){
    if(dp[H-1][W-1][i]){
      ans = min(ans, abs(i - 15000));
    }
  }
  cout << ans << endl;
}


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


Measured memory_bytes: 33276
using System;
class ProgramD
    {
        static void Main(string[] args)
        {
            
            //入力
            string[] input = Console.ReadLine().Split();
            long x = long.Parse(input[0]);
            long y = long.Parse(input[1]);
            long mod = 1000000000 + 7;

            if( (x+y) % 3 != 0)
            {
                Console.WriteLine("0");
                return;
            }

            long m = 0;
            long n = 0;

            m = (2*x-y)/3;
            n = (2*y-x)/3;

            if(m < 0 || n < 0)
            {
                Console.WriteLine("0");
                return;
            }
            else if(m == 0 || n == 0)
            {
                Console.WriteLine("1");
                return;
            }
            else
            {
                if(m < n)
                {
                    long temp = n;
                    n = m;
                    m = temp;
                }
                
                long ans = 1;
                for(long i = 1;i <= n;i++)
                {
                    ans = (ans * (m + n - i + 1)) % mod ;
                }

                for(long i = 2;i <= n;i++)
                {
                    ans = ans * modinv(i,mod) % mod;
                }
                Console.WriteLine(ans);                    

                
            }

        }

        // mod. m での a の逆元 a^{-1} を計算する
        static long modinv(long a, long m)
         {
            long b = m, u = 1, v = 0;
            while (b > 0)
            {
                long t = a / b;
                a -= t * b; 
                long temp = a;
                a = b;
                b = temp;
                u -= t * v; 
                long temp2 = u;
                u = v;
                v = temp2;
            }
            u %= m;
            if (u < 0) u += m;
            return u;
        }
    }

Measured memory_bytes: 13140
//#include <iostream>
//#include <cstring>
//#include <algorithm>
//#include <cmath>
//#include <cstdio>
//#include <vector>
//#include <queue>
//#include <set>
//#include <map>
//#include <stack>
//#define ll long long
//#define local
//
//using namespace std;
//
//const int MOD = 1e9+7;
//const int inf = 0x3f3f3f3f;
//const int maxn = 1e2+10;
//const double PI = acos(-1.0);
//
//int a[maxn];
//int n, m;
//
//bool solve(int c) {
//    int ans = 0;
//    for (int i = 0; i < n; ++i) {
//        ans += (c-a[i]);
//    }
//    if (ans >= m) return 1;
//    else return 0;
//}
//
//int main() {
//#ifdef local
//    if(freopen("/Users/Andrew/Desktop/data.txt", "r", stdin) == NULL) printf("can't open this file!\n");
//#endif
//
//    int T;
//    scanf("%d", &T);
//    while (T--) {
//        int mn = inf, mx = -1;
//        scanf("%d", &n);
//        scanf("%d", &m);
//        for (int i = 0; i < n; ++i) {
//            scanf("%d", &a[i]);
//            mx = max(mx, a[i]);
//            mn = min(mn, a[i]);
//        }
//        mx += m;
//        int l = mn-1; int r = mx;
//        while (r-l > 1) {
//            int mid = (l+r)>>1;
//            if (solve(mid)) {
//                r = mid;
//            } else {
//                l = mid;
//            }
//        }
//        mn = r;
//        printf("%d %d\n", mn, mx);
//    }
//
//#ifdef local
//    fclose(stdin);
//#endif
//    return 0;
//}
//
//
//
//




#include <iostream>
#include <cstring>
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <stack>
#define ll long long
//#define local

using namespace std;

const int MOD = 1e9+7;
const int inf = 0x3f3f3f3f;
const int maxn = 1e5+10;
const double PI = acos(-1.0);

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

ll n, m;
char s[maxn];
char t[maxn];
map<ll, char> mp;

int main() {
#ifdef local
    if(freopen("/Users/Andrew/Desktop/data.txt", "r", stdin) == NULL) printf("can't open this file!\n");
#endif
    scanf("%lld%lld", &n, &m);
    scanf("%s%s", s, t);
    ll d = gcd(n, m);
    d = n/d*m;
    bool flag = 1;
    for (int i = 0; i < n; ++i) {
        mp[i*(d/n)+1] = s[i];
    }
    for (int i = 0; i < m; ++i) {
        if(!mp.count(i*(d/m)+1)) continue;
        if (mp[i*(d/m)+1] != t[i]) {
            flag = 0;
            break;
        }
    }
    printf("%lld\n", flag ? d:-1);
#ifdef local
    fclose(stdin);
#endif
    return 0;
}


















Measured memory_bytes: 6144
#include <bits/stdc++.h>
using namespace std;
int main() {
    string a,b;
    cin>>a>>b;
    int n,m;
    n=a.size();
    m=b.size();
    vector<vector<int> > v(26);
    for(int i=0;i<n;i++)
    {
        v[a[i]-'a'].push_back(i);
    }
    for(int i=0;i<n;i++)
    {
        v[a[i]-'a'].push_back(n+i);
    }
    long long cnt=0;
    for(int i=0;i<m;i++)
    {
       if(v[b[i]-'a'].size()==0)
       {
           cout<<"-1";
           return 0;
       }
    }int x=0;
    for(int i=0;i<m;i++)
    {
        int y=b[i]-'a';
         x=*lower_bound(v[y].begin(),v[y].end(),x)+1;
         if(x>n)
         {
             cnt++;
             x-=n;

         }
    }
	cnt=1ll*cnt*n;
	cnt+=1ll*x;
    cout<<cnt;
    return 0;
}

Measured memory_bytes: 1724
#include<stdio.h>

int main(){
  int a[1000000],n,i,q,key,sum = 0,right,left,mid;

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

  for(i = 0;i < q;i++){
    scanf("%d",&key);

    left = 0;
    right = n;
    while(left < right){
      mid = (right + left) / 2;
      if(key == a[mid]){
	sum++;
	break;
      }
      else if(key > a[mid]){
	left = mid + 1;
      }
      else{
	right = mid;
      }
    }
  }
  
  printf("%d\n",sum);
  
  return 0;
}



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

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

  long long n, m;
  cin >> n >> m;
  vector<ll> a(n);
  priority_queue<ll> que;
  for(int i=0;i<n;i++){
    cin >> a[i];
    que.push(a[i]);
  }
  for(int i=0;i<m;i++){
    long long maxv = que.top();
    que.pop();
    que.push(maxv >> 1);
  }
  long long ans=0;
  for(int i=0;i<n;i++){
    ans+=que.top();
    que.pop();
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 2168
from collections import defaultdict
n = int(input())

testimony = defaultdict(list)

for i in range(n):
   a = int(input())
   for _ in range(a):
      x, y = map(int, input().split())
      testimony[i+1].append((x, y))

def beki(lst):
   res = [set()]
   for x in lst:
      res = res + [s | {x} for s in res]
   return res

res = 0
for s in beki(range(1, n+1)):
   flag = True
   d = {}
   for i in s:
      for x, y in testimony[i]:
         if x in d and d[x] != y:
            flag = False
         elif y == 1 and x not in s:
            flag = False
         elif y == 0 and x in s:
            flag = False
         else:
            d[x] = y
   if flag:
      res = max(res, len(s))
print(res)

Measured memory_bytes: 20972