akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
//----***やべーやつら***----
using namespace std;
#define int long long

//----***型定義***----
using ll = long long;
using P = pair<int,int>;

//----***Like a Pythonista***----
#define REP(ii,jj,nn) for (ll ii=jj;ii<(nn);ii++)
#define RREP(ii,nn,jj) for (ll ii = nn; jj<ii;ii--)
#define each(i,...) for (auto&& i:__VA_ARGS__)
#define ALL(vec) (vec).begin(),(vec).end()
#define sum(...) accumulate(ALL(__VA_ARGS__),0LL)
#define dsum(...) accumulate(ALL(__VA_ARGS__),0.0)
#define vec(type,name,...) vector<type> name(__VA_ARGS__)
template<class T> inline auto max(const T& a){ return *max_element(ALL(a)); }
template<class T> inline auto min(const T& a){ return *min_element(ALL(a)); }
inline ll gcd(ll a,ll b){if(b == 0) return a;return  gcd(b,a%b);}
inline ll lcm(ll a,ll b){ll g = gcd(a,b);return a / g * b;}

//----***定数***----
#define MOD 1000000007
#define INF 100000000000000000
#define EPS 1e-9
const vector<vector<int>> DXY={{-1,0},{1,0},{0,-1},{0,1}};

//----***パーツ***----
#define fi first
#define se second
#define pb push_back
#define re return
#define br break

//----***入出力***---
void print() { std::cout << "\n"; }
template <class T>void print(const T &x) {std::cout << x<<"\n";}
template <class T, class... Args>void print(const T &x, const Args &... args) {std::cout << x << " ";print(args...);}
#define debug(var)  do{std::cerr << #var << " ↓ "<<"\n";view(var);}while(0);
#define dbg cerr<<"🥺🥺🥺🥺🥺🥺"<<endl;
template<typename T> void view(T e){std::cout << e << std::endl;}
template<typename T> void view(const std::vector<T>& v){for(const auto& e : v){ std::cout << e << " "; } std::cout << std::endl;}
template<typename T> void view(const std::vector<std::vector<T> >& vv){ for(const auto& v : vv){ view(v); } }

//----***初期時読み込み***----
struct initial{initial(){cin.tie(0); ios::sync_with_stdio(0); cout<<fixed<<setprecision(15);};}initial_;

signed main(){
  int A,B;cin>>A>>B;
  string S;cin>>S;
  bool flg=false;
  REP(i,0,A){
    if(!('0'<=S.at(i)&&S.at(i)<='9')){
      print("No");
      return 0;
    }
  }
  if(S.at(A)!='-'){
    print("No");
    return 0;
  }
  REP(i,A+1,A+B+1){
    if(!('0'<=S.at(i)&&S.at(i)<='9')){
      print("No");
      return 0;
    }
  }
  print("Yes");


}


Measured memory_bytes: 256
///Bismillahir Rahmanir Rahim
#include<bits/stdc++.h>

#define                           ll                         long long int
#define mp make_pair

using namespace std;

int main(){

     ll i,n,m,s=0,sum=0,x=0;
     cin>>n>>m>>s;
      while(-1){
        sum+=s;
        if(sum>=n && sum<=m){
            x++;
        }
        if(sum>m) break;
      }
    cout<<x<<endl;

}



Measured memory_bytes: 3596
import java.util.Scanner;

public class Main {
    public static void main(String[] args) throws Exception {
        Scanner sc = new Scanner(System.in);
        String token = sc.next();
        String[] strArray = token.split("");

        int result = 0;

        if (strArray[0].equals("1")) {
            result++;
        }

        if (strArray[1].equals("1")) {
            result += 1;
        }

        if (strArray[2].equals("1")) {
            result += 1;
        }

        System.out.println(result);

        sc.close();
    }
}


Measured memory_bytes: 35676
#include <bits/stdc++.h>
using namespace std;
int main(){
    int n;
    cin >>n;
    vector<char> inp;
    char temp, temp1 = 'A';
    while(cin >> temp ){
        inp.push_back(temp);
    }
    for(int i = 0; i< inp.size(); ++i){
        if(n+inp[i] > 'Z'){
            cout << char(64 + (n+inp[i])%90);
        }
        else{
            cout<< char(n + inp[i]);
        }
    }
    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cmath>
#include<math.h>
#include<string>
#include<string.h>
#include<stack>
#include<queue>
#include<vector>
#include<utility>
#include<set>
#include<map>
#include<stdlib.h>
#include<iomanip>

using namespace std;

#define ll long long
#define ld long double
#define EPS 0.0000000001
#define INF 1e9
#define rep(i,n) for(i=0;i<n;i++)
#define loop(i,a,n) for(i=a;i<n;i++)
#define all(in) in.begin(),in.end()
#define shosu(x) fixed<<setprecision(x)

typedef vector<int> vi;
typedef pair<int,int> pii;

int main(void) {
  int i,j;
  ll a,b,c,d;
  cin>>a>>b>>c>>d;
  cout<<max(a*b,c*d)<<endl;
}


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

const ll MOD = 1000003;
int Q;
ll x, d, n;
ll F[3*MOD];
ll inv[3*MOD];

ll powmod(ll a, ll x, ll m) {
    ll ret = 1;
    while (x) {
        if (x % 2) ret = ret * a % m;
        a = a * a % m;
        x /= 2;
    }
    return ret;
}

void solve() {
    F[0] = F[1] = 1;
    REP2(i, 2, 3*MOD) F[i] = F[i-1] * i % MOD;
    REP(i, 3*MOD) inv[i] = powmod(i, MOD-2, MOD);

    cin >> Q;

    while (Q--) {
        cin >> x >> d >> n;
        if (x == 0 && d == 0) {
            cout << 0 << "\n";
            continue;
        } else if (d == 0) {
            cout << powmod(x, n, MOD) << "\n";
            continue;
        } else if (n >= MOD) {
            cout << 0 << "\n";
            continue;
        }
        ll a = powmod(d, n, MOD);
        ll b = x * inv[d] % MOD;
        ll c = F[b+n-1] * inv[F[b-1]] % MOD;
        cout << a * c % MOD << "\n";
    }

}

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


Measured memory_bytes: 47744
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
#include<math.h>

int main(){
    int k,s;
    int ans = 0;
    int x,y;
    scanf("%d %d",&k,&s);
  
  for(x=0;x<=k;x++){
    for(y=0;y<=k;y++){
        if((s-(x+y) <= k) && (x+y <= s)){
          ans += 1;
        }
      }
    }
printf("%d",ans);
return 0;
}

Measured memory_bytes: 128
//大文字->小文字 tolower(),逆はtoupper()
//int a = stoi(c); 文字列をintへ
//途中の出力をそのまま残さない
//数値計算 個数以外はdouble
//map<キー,値> p は辞書。p[キー] = 値
//map 全探索
//auto begin = p.begin(), end = p.end();
//for (auto it = begin; it != end; it++) {}
//mapのキー：it->first mapのバリュー：it->second
//絶対値 abs()
//入力は空白で切れる
//大文字判定 isupper(文字) 小文字判定 islower(文字)
//do{}while(next_permutation(ALL(配列)))
//while(N)で回すとき、Nはコピーを作っておく
//小文字に対応する文字コード：S[i] - 'a'
//文字コード→小文字：(char)(数字+'a')
//グラフの距離:隣接行列で扱う
//等価なものに変換する思考
//bool型　初期値はTrue
//島渡りの問題：中間ノードに着目
#include <bits/stdc++.h>
#define rep(i,N) for(int i = 0; i < N;i++)
#define ALL(a) (a).begin(),(a).end()
#define ll long long int
using namespace std;

// K進数でのNの桁数
ll dig(ll N,ll K) {
	ll dig = 0;
	while (N) {
		dig++;
		N /= K;
	}
	return dig;
}
// a,bの最大公約数
ll gcd(ll a, ll b) {
	if (b == 0) return a;
	return gcd(b,a%b);
}

ll lcm(ll a, ll b) {
	ll g = gcd(a, b);
	return a / g * b;
}

//nC2の計算
ll C(ll N) {
	return N * (N - 1) / 2;
}

//円周率
const double PI = 3.14159265358979323846;

int main() {
	ll N; cin >> N;
	vector<ll> a(N); rep(i, N)cin >> a[i];

	sort(ALL(a));

	vector<ll> cnt(a[N - 1] + 1);
	rep(i, N) cnt[a[i]]++;
	

	ll mx = cnt[0] + cnt[1];
	for (int i = 1; i <= a[N - 1]; i++) {
		if (i == a[N - 1]) {
			mx = max(mx, cnt[i - 1] + cnt[i]);
			continue;
		}
		mx = max(mx, cnt[i - 1] + cnt[i] + cnt[i + 1]);
	}

	cout << mx << endl;
}

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

typedef long long int ll;
ll MOD = 1000000007;
ll INFL = 1ll << 60;
ll INF = 1 << 30;
int dx[8] = {0, 1, 1, 1, 0, -1, -1, -1};
int dy[8] = {1, 1, 0, -1, -1, -1, 0, 1};

int main() {
  int w, h, n, x, y, a;
  cin >> w >> h >> n;
  int v[h][w] = {};
  for (int k = 0; k < n; k++) {
    cin >> x >> y >> a;

    if (a == 1)
      for (int py = 0; py < h; py++)
        for (int px = 0; px < x; px++)
          v[py][px] = 1;
    if (a == 2)
      for (int py = 0; py < h; py++)
        for (int px = x; px < w; px++)
          v[py][px] = 1;
    if (a == 3)
      for (int py = 0; py < y; py++)
        for (int px = 0; px < w; px++)
          v[py][px] = 1;
    if (a == 4)
      for (int py = y; py < h; py++)
        for (int px = 0; px < w; px++)
          v[py][px] = 1;
  }

  int ans = 0;
  for (int y = h - 1; 0 <= y; y--)
    for (int x = 0; x < w; x++)
      if (v[y][x] == 0)
        ans++;

  cout << ans << endl;
}


Measured memory_bytes: 256
class PriorityQueue
  attr_accessor :data, :size

  def initialize(array = [])
    @data = []
    array.each {|a| push(a) }
  end

  def push(element)
    current = @data.size
    while current > 0
      p_index = parent(current)
      break if @data[p_index] <= element
      @data[current] = @data[p_index]
      current = p_index
    end
    @data[current] = element
  end

  def pop
    ret = @data.first
    x = @data.last
    current = 0
    while have_child?(current)
      a_index = left_child_index(current)
      b_index = right_child_index(current)
      a_index = b_index if b_index < @data.size - 1 && @data[b_index] < @data[a_index]
      break if @data[a_index] >= x
      @data[current] = @data[a_index]
      current = a_index
    end
    @data[current] = x
    @data.pop

    ret
  end

  def size
    @data.size
  end

  def front
    @data.first
  end

  def empty?
    @data.empty?
  end

  private

  def parent(num)
    (num - 1) / 2
  end

  def left_child_index(num)
    2 * num + 1
  end

  def right_child_index(num)
    2 * num + 2
  end

  def have_child?(index)
    left_child_index(index) < @data.size
  end
end

n, m = gets.split.map(&:to_i)
nums = gets.split.map(&:to_i)
pq = PriorityQueue.new(nums.map { |i| -i } )
m.times { pq.push((pq.pop / 2.0).ceil) }
puts -pq.data.inject(:+) 


Measured memory_bytes: 10324
#include <stdio.h>
#include <math.h>
int main(){
	double x1,x2;
	double y1,y2;
	scanf("%lf %lf",&x1,&y1);
	scanf("%lf %lf",&x2,&y2);
	x1-=x2;
	y1-=y2;
	printf("%lf\n",sqrt(x1*x1+y1*y1));
	return 0;
}

Measured memory_bytes: 652
/*
         ██╗ ██████╗ ██╗███╗   ██╗    ██╗   ██╗███████╗
         ██║██╔═══██╗██║████╗  ██║    ██║   ██║██╔════╝
         ██║██║   ██║██║██╔██╗ ██║    ██║   ██║███████╗
    ██   ██║██║   ██║██║██║╚██╗██║    ██║   ██║╚════██║
    ╚█████╔╝╚██████╔╝██║██║ ╚████║    ╚██████╔╝███████║
     ╚════╝  ╚═════╝ ╚═╝╚═╝  ╚═══╝     ╚═════╝ ╚══════╝
*/
//password:+BdCHpO8dQvpo5fnV3/u
#include<bits/stdc++.h>

using namespace std;
typedef long long ll;
const int maxn = 5e5 + 5;
const int inf = 0x3f3f3f3f;
int n;
int a[maxn],b[maxn];
int dp[maxn];
int fuck(int x,int y)
{
  return ((x%y==0)?(x/y):(x/y+1));
}
int main() {
  cin>>n;
  for(int i=1;i<=n;i++)
    cin>>a[i]>>b[i];
  ll x=a[1],y=b[1];
  for(int i=2;i<=n;i++)
  {
    ll m=max((x-1)/a[i]+1,(y-1)/b[i]+1);
    x=m*a[i];
    y=m*b[i];
  }
  cout<<x+y<<endl;
  return 0;
}

Measured memory_bytes: 2304
#include <iostream>
using namespace std;
#define MAX 10005
int main(void) {
    int n, q, G[MAX];
    cin >> n >> q;
    for (int i = 0; i < n; i++) {
        G[i] = 0;
    }
    int group = 1;
    while (q--) {
        int com, x, y;
        cin >> com >> x >> y;
        if (com == 0) {
            if (G[x] == 0 && G[y] == 0) {
                G[x] = G[y] = group;
                group++;
            } else if (G[x] == 0 || G[y] == 0) {
                if (G[x] == 0)
                    G[x] = G[y];
                else
                    G[y] = G[x];
            } else {
                int g = G[x];
                for (int i = 0; i < n; i++) {
                    if (G[i] == g)
                        G[i] = G[y];
                }
            }
        } else {
            if (G[x] != 0 && G[x] == G[y]) 
                cout << 1 << endl;
            else
                cout << 0 << endl;
        }
    }
}


Measured memory_bytes: 3120
#include <iostream>
#include <vector>
#include <set>
#include <deque>
#include <map>
#include <iomanip>
#include <queue>
#include <stack>
#include <algorithm>
#include <cmath>
#include <cstring>
#include <utility>
using namespace std;
int ky[8] = {-1,1,-2,2,-2,2,-1,1}; 
int kx[8] = {-2,-2,-1,-1,1,1,2,2};
int dy[4] = {-1,0,1,0};
int dx[4] = {0,1,0,-1};
int ddy[8] = {-1,0,1,-1,1,-1,0,1};
int ddx[8] = {-1,-1,-1,0,0,1,1,1};
typedef long long ll;
#define pi pair
#define MP make_pair
#define PB push_back
#define F first
#define S second
#define rep1(i,a,b) for(int i = a; i < b; i++)
#define rep2(i,a,b) for(int i = a; i <= b; i++) 
#define INF 999999999999
const double PI = acos(-1.0); 
int x,y;
int a,b;

int main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
    //freopen("input.txt","r",stdin);
    //freopen("output.txt","w",stdout);
    cin >> x >> y;
    b = y - 2 * x;
    a = 4 * x - y;
    if(a < 0 || b < 0) cout << "No";
    else{
        if(a % 2 == 0 && b % 2 == 0) cout << "Yes";
        else cout << "No";
    }
   
	return 0;
}


Measured memory_bytes: 3608
#include <bits/stdc++.h>
#include <boost/multi_array.hpp>
#include <boost/range/algorithm.hpp>
#define rep(i, n) for (int i = 0; i < (n); ++i)
using namespace std;
typedef long long ll;

bool check(char c) {
  if ((c == 'A') || (c == 'T') || (c == 'G') || (c == 'C'))
    return true;
  else
    return false;
}

int main() {
  int n;
  cin >> n;
  vector<int> a(n);
  rep(i, n) { cin >> a[i]; }
  int sum = 0;
  int sqsum = 0;
  rep(i, n) {
    sum += a[i];
    sqsum += a[i] * a[i];
  }
  int ans = (sum * sum - sqsum) / 2;
  cout << ans << endl;
  return 0;
}


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



public class Main{
	 private enum pType{
	    	p1(1),
	    	p2(2),
	    	p3(3),
	    	pInfinity(0);

		 	private int p;
		 	private pType(int p){
		 		this.p = p;
		 	}
		 	private int getPType(){
		 		return p;
		 	}
	    }

	public static void main(String[] args) throws IOException{
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        int n = Integer.parseInt(br.readLine());
        int[] x = convertStringToInt(br.readLine().split(" "));
        int[] y = convertStringToInt(br.readLine().split(" "));

        System.out.println(calcMD(x,y,pType.p1));
        System.out.println(calcMD(x,y,pType.p2));
        System.out.println(calcMD(x,y,pType.p3));
        System.out.println(calcMD(x,y,pType.pInfinity));
    }

	private static int[] convertStringToInt(String[] str){
		int[] list = new int[str.length];
		for(int i=0; i<str.length;i++){
			list[i] = Integer.parseInt(str[i]);
		}
		return list;
	}


    private static double calcMD(int[] x, int[] y,pType type){
    	double D=0;
    	if(type.equals(pType.pInfinity)){
    		for(int i=0;i<x.length;i++){
    			double d = Math.abs(x[i]-y[i]);
    			if(D<=d){
    				D=d;
    			}
    		}
    	}else{
    		double d=0;
    		for(int i=0;i<x.length;i++){
    			d += Math.pow(Math.abs(x[i] - y[i]), type.getPType());
    		}
    		//d = Math.sqrt(d);
			D  =Math.pow(d, (double)1/type.getPType());
    	}
    	return D;
    }
}

Measured memory_bytes: 24556
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
ld err=0.000000001;
#define    N       2000005
#define   ESP     1e-9
#define    pii      pair<int,int>
#define    vi       vector<int>
#define    vl       vector<ll>
#define    pb       push_back
#define    pp       pop_back
int ar[1000];
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int W,H,w,h;
    cin>>W>>H>>w>>h;
    ll ans=W*H;
    ans=ans-((H*w)+((W-w)*h));
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 384
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <memory.h>
#include <math.h>
#include <assert.h>
#include <queue>
#include <map>
#include <set>
#include <string>
#include <algorithm>
#include <iostream>
#include <functional>
#include <unordered_map>
#include <unordered_set>
#include <list>
#include <bitset>

using namespace std;
typedef pair<int, int> Pi;
typedef long long ll;
#define pii Pi
#define pll PL
#define Fi first
#define Se second
#define pb(x) push_back(x)
#define sz(x) ((int)(x).size())
#define rep(i, n) for(int i=0;i<n;i++)
#define all(x) (x).begin(), (x).end()
typedef tuple<int, int, int> t3;
typedef pair<ll, ll> pll;
typedef long double ldouble;

int n, A[300020];

void solve(){
	scanf("%d", &n);
	for(int i=1;i<=n*3;i++) scanf("%d", A+i);
	ll L[300030] = {}, R[300030] = {};
	priority_queue <int, vector<int>, greater<int> > pq;
	for(int i=1;i<=n;i++) pq.push(A[i]), L[n] += A[i];
	for(int i=n+1;i<=n+n;i++) {
		pq.push(A[i]); L[i] = L[i-1] + A[i] - pq.top(); pq.pop();
	}
	while(!pq.empty())pq.pop();
	for(int i=2*n+1;i<=3*n;i++) pq.push(-A[i]), R[n+n+1] += A[i];
	for(int i=2*n;i>n;i--){
		pq.push(-A[i]); R[i] = R[i+1] + A[i] + pq.top(); pq.pop();
	}
	ll ans = -1e18;
	for(int i=n;i<=n+n;i++) ans = max(ans, L[i] - R[i+1]);
	printf("%lld\n", ans);
}

int main(){
	int Tc = 1; // scanf("%d\n", &Tc);
	for(int tc=1;tc<=Tc;tc++){
		solve();
	}
	return 0;
};


Measured memory_bytes: 6780
#include<iostream>
#include<cstring>
using namespace std;
char s[100000+100];
int a[100]; 
int main(){
	memset(a,0,sizeof(a));
	cin>>s;
	int len=strlen(s);
	for(int i=0;i<=len-1;i++){
		int x=int (s[i])-96;
		a[x]=1;
	}
	bool flag=false;
	for(int i=1;i<=26;i++){
		if(a[i]==0){
			char ch=char(i+96);
			cout<<ch<<endl;
			flag=true;
			break;
		}
	}
	if(flag==false){
		cout<<"None"<<endl;
	}
	return 0;
}

Measured memory_bytes: 384
import collections

n=int(input())
a=list(map(int,input().split()))

ca =collections.Counter(a)
res = []
for kca in list(ca.keys()):
    if ca[kca] >= 2:
        res.append(kca)
    if ca[kca] >= 4:
        res.append(kca)

res.sort()
if len(res)>= 2:
    print(res[-1]*res[-2])
else:
    print(0)

Measured memory_bytes: 69528
#include <iostream>
#include <vector>
#include <climits>
#include <algorithm>
#include <cmath>
#include <map>
#include <set>
#include <string>
#include <bitset>
#include <utility>
#include <numeric>
#include <queue>
#include <stack>

using ll = long long;
using namespace std;

constexpr int MOD = 1e9 + 7;
constexpr ll MOD_LL = ll(1e9) + 7;

int main(void) {
	int n, m;
	cin >> n >> m;
	
	vector<int> x(m);
	for(int i = 0; i < m; ++i) {
		cin >> x[i];
	}
	
	if( n >= m ) {
		cout << 0 << endl;
		return 0;
	}
	
	sort(x.begin(), x.end());
	
	vector<ll> diff(m, 0);
	ll sum = 0LL; 
	for(int i = 0; i < m - 1; ++i) {
		diff[i] = abs(x[i] - x[i + 1]);
		sum += diff[i];
	}
	
	sort(diff.begin(), diff.end(), greater<int>());
	
	for(int i = 0; i < n - 1; ++i) {
		sum -= diff[i];
	}
	
	cout << sum << endl;
	
	return 0;
}


Measured memory_bytes: 1408
def count(line)
  line.chunk {|i| i.nonzero?}.select(&:first).map {|l| l.last.size}.max || 0
end

until (n = $<.gets.to_i).zero?
  field = n.times.map {$<.gets.chomp.chars.map(&:to_i)}
  
  max_l = field.map {|l| count(l)}.max
  max_l = [field.transpose.map {|l| count(l)}.max, max_l].max
  l = n - 1
  n.times do |i|
    line = (i + 1).times.map {|j| field[i - j][j]}
    tmp1 = count(line)
    line = (i + 1).times.map {|j| field[l - i + j][l - j]}
    tmp2 = count(line)
    line = (i + 1).times.map {|j| field[i - j][l - j]}
    tmp3 = count(line)
    line = (i + 1).times.map {|j| field[l - i + j][j]}
    tmp4 = count(line)
    max_l = [tmp1, tmp2, tmp3, tmp4, max_l].max
  end
  
  puts max_l
end


Measured memory_bytes: 11796
#include <stdio.h>
 
int main(void){
  int x[5];
  
	scanf("%d %d %d %d %d",&x[0],&x[1],&x[2],&x[3],&x[4]); 
  
  
 	int i;
  for(i=0;i<5;i++){
    //scanf("%d", &x);
    if((i+1)!=x[i]){
      printf("%d", i+1);
    }
  }
  
 
  return 0;
}


Measured memory_bytes: 1708
# -*- coding: utf-8 -*-
#C - Synthetic Kadomatsu
import sys 
from itertools import product
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
N, A, B, C = map(int, readline().split())
l = list(map(int,read().split()))
INF = 10**31
ans = INF

for patterns in product(range(4), repeat=N):
    x = [0]*4
    MP = 0
    for i,take in enumerate(patterns):
        if take == 0:
            continue
        if x[take] != 0:
            MP += 10
        x[take] += l[i]
    if x[1] == 0 or x[2] == 0 or x[3] == 0:
        continue
    MP += abs(x[1]-A)
    MP += abs(x[2]-B)
    MP += abs(x[3]-C)
    ans = min(MP,ans)
print(ans)
    

Measured memory_bytes: 74272
s[50],j,p,q;main(i){for(;p=atoi(gets(s));printf("%d\n",i)){for(i=0;i<p;s[i++]=strlen(gets(s+i)));for(i=j=0;j<7;)for(p=i++,j=q=1;q>0;)for(q=8939616>>j++*4&15;q>1;q-=s[p++]);}}

Measured memory_bytes: 532
#include<bits/stdc++.h>
using namespace std;
const int uchiha=1e5+6;
int main(){
long long a,b;
int x,c1=0;
cin>>a>>b;
for(int i=a;i<=b;i++){
   x=i;
    int z=x%10;
    x/=10;
    int y=x%10;
    x/=10;
    int p=x%10;
    x/=10;
    int n=x%10;
    x/=10;
    int q=x%10;
    if(z==q&&y==n){
        c1++;
    }
}
cout<<c1;
}

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

int main() {
  string w;
  cin >> w;
  bitset<26> s;
  for (auto c : w) {
    if (s.test(c-'0'-49)) s.set(c-'0'-49, 0);
    else s.set(c-'0'-49, 1);
  }
  cout << (!s.any() ? "Yes" : "No") << endl;
}

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

#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define rep3(i,m,n) for(int (i)=m;(i)<=(n);(i)++)
#define rep3rev(i,m,n) for(int (i)=m;(i)>=(n);(i)--)
#define all(a) (a.begin()),(a.end())
#define rall(a) (a.rbegin()),(a.rend())
#define fi first
#define se second

typedef long long ll;
typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef pair<int, int> pii;

void Main()
{
	int a, b;
  	cin >> a >> b;
	cout << (a-1)*(b-1) << endl;
	return;
}

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


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

constexpr int D = 365;
constexpr int T = 26;
int c[D];
int s[D][T];
vector<int> ans;

void Input() {
    int tmp; cin >> tmp;
    REP(i, T) cin >> c[i];
    REP(i, D) REP(j, T) cin >> s[i][j];
    return;
}

void Commit(int day, int contest, int& score, vector<int>& last) {
    last[contest] = day;
    score += s[day - 1][contest];
    REP(type, T) score -= c[type] * (day - last[type]);
    return;
}

void Output() {
    for(auto contest: ans) cout << contest + 1 << endl;
    return;
}

double lambda1 = 6.1; // 6.1 is better
int FindMaxProfitContest(int day, vector<int>& last) {
    double max_profit = -1e9;
    int argmax = -1;
    REP(type, T) {
        double profit = 0;
        profit += s[day - 1][type];
        profit += lambda1 * c[type] * (day - last[type]);
        if(profit > max_profit) {
            max_profit = profit;
            argmax = type;
        }
    }
    return argmax;
}

int Greedy(int start_day, vector<int>& last) {
    int score = 0;
    vector<int> last_copy = last;
    for(int day = start_day; day <= D; day++) {
        int contest = FindMaxProfitContest(day, last_copy);
        Commit(day, contest, score, last_copy);
    }
    return score;
}

double lambda2 = 6.1;
int FindMaxProfitContestWithPredict(int day, vector<int>& last) {
    double max_profit = -1e9;
    int argmax = -1;
    REP(type, T) {
        double profit = 0;

        profit += s[day - 1][type];
        profit += lambda2 * c[type] * (day - last[type]);

        int tmp = last[type];
        last[type] = day;
        profit += Greedy(day + 1, last);
        last[type] = tmp;

        if(profit > max_profit) {
            max_profit = profit;
            argmax = type;
        }
    }
    return argmax;
}

int main() {
    Input();
    int score = 0;
    vector<int> last(T, 0);
    for(int day = 1; day <= D; day++) {
        int contest = FindMaxProfitContestWithPredict(day, last);
        ans.push_back(contest);
        Commit(day, contest, score, last);
    }
    Output();
    // cerr << score << endl;
    return 0;
}


Measured memory_bytes: 3636
import sys
input = sys.stdin.readline
INF = 1001001001
from collections import deque

def linput(ty=int, cvt=list):
	return cvt(map(ty,input().split()))

def pad(mxy, wall="#"):
	w = len(mxy[0])
	gp = wall*(w+2)
	re = [gp,]
	re_app = re.append
	for vx in mxy:
		re_app(wall+vx+wall)
	re_app(gp)
	return re

vD = [(0,1),(1,0),(0,-1),(-1,0)]
vQ = deque([])
vQ_app, vQ_popl = vQ.append, vQ.popleft

def main():
	H,W = linput()
	mM = [input().rstrip() for _ in [0,]*H]
	mM = pad(mM,"$")
	
	res = 0
	cnt = 0
	
	mV = [[INF,]*(W+2) for _ in [INF,]*(H+2)]
	for sr in range(1,H+1):
		for sc in range(1,W+1):
			if mM[sr][sc]==".":
				continue
			mV[sr][sc] = 0
			vQ_app((sr,sc))
	
	while vQ:
		r,c = vQ_popl()
		now_cost = mV[r][c]
		for dr,dc in vD:
			nr,nc = r+dr, c+dc
			if mM[nr][nc]=="$":
				continue
			if now_cost + 1 < mV[nr][nc]:
				vQ_app((nr,nc))
				mV[nr][nc] = now_cost + 1
				res = max(now_cost+1, res)
		
		cnt += 1
		#print(res,cnt,X,Y,H)
		if cnt>4999999: break
	
	print(res)

if __name__ == "__main__":
	main()


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

using namespace std;

int main(){
    string a, b;
    cin >> a >> b;
    if (a[0] == 'H'){
        if (b[0] == 'H'){
            cout << 'H' << endl; 
        }else{
            cout << 'D' << endl; 
        }
    }else{
        if (b[0] == 'H'){
            cout << 'D' << endl; 
        }else{
            cout << 'H' << endl; 
        }        
    }
    
}

Measured memory_bytes: 256
#include <iostream>
#include <fstream>
#include <set>
#include <map>
#include <string>
#include <vector>
#include <queue>
#include <stack>
#include <functional>
#include <algorithm>
#include <climits>
#include <cmath>
using namespace std;
#define ll long long int
#define rep(i,n) for( int i = 0; i < n; i++ )
#define rrep(i,n) for( int i = n; i >= 0; i-- )
#define REP(i,s,t) for( int i = s; i <= t; i++ )
#define RREP(i,s,t) for( int i = s; i >= t; i-- )
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define INF 2000000000
#define mod 1000000007
#define INF2 1000000000000000000

char inv[127];
int main(void)
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n; cin >> n;
    string S; cin >> S;
    inv['S'] = 'W';
    inv['W'] = 'S';
    rep(bit, 4) {
        string T = "";
        if (bit & 1) T += 'S';
        else T += 'W';
        if (bit & 2) T += 'S';
        else T += 'W';
        rep(i, n) {
            if (S[(i + 1) % n] == 'o' && T[i + 1] == 'S') T += T[i];
            if (S[(i + 1) % n] == 'x' && T[i + 1] == 'S') T += inv[T[i]];
            if (S[(i + 1) % n] == 'o' && T[i + 1] == 'W') T += inv[T[i]];
            if (S[(i + 1) % n] == 'x' && T[i + 1] == 'W') T += T[i];
        }
        //cout << T << endl;
        if(T[0] == T[n] && T[1] == T[n + 1]) {
            T.pop_back();T.pop_back();
            cout << T << endl;
            return 0;
        }
    }
    cout << -1 << endl;

    return 0;
}
//  ooxoox
// SWWSSSSW

Measured memory_bytes: 720
#解説解答
n,k = map(int,input().split())
a = list(map(int,input().split()))
for i in range(n):
  a[i] -= 1
  a[i] %= k
#print(a)
b = [0]
for i in range(n):
  b.append((b[-1]+a[i])%k)
#print(b)

ans = 0
now = {}
for i in range(n+1):
  if b[i] in now:
    ans += now[b[i]]
    now[b[i]] += 1
  else:
    now[b[i]] = 1
  if i - k + 1 >= 0:
    now[b[i-k+1]] -= 1
  #print(now,i,ans)
print(ans)

Measured memory_bytes: 111104
t = [list(map(int, input().split())) for _ in range(3)]
n = int(input())
m = [int(input()) for i in range(n)]
x = 0
for i in range(3):
        if t[i][0] in m and t[i][1] in m and t[i][2] in m:
            print('Yes')
            break
        elif t[0][i] in m and t[1][i] in m and t[2][i] in m:
            print('Yes')
            break
        elif t[0][0] in m and t[1][1] in m and t[2][2] in m:
            print('Yes')
            break
        elif t[0][2] in m and t[1][1] in m and t[2][0] in m:
            print('Yes')
            break
        else:
            x += 1
if x == 3:
    print('No')

Measured memory_bytes: 3064
INF = 2**31-1
n, q = map(int, input().split())
size = 2**((n-1).bit_length())
seg_tree = [INF]*(size*2)

import sys
input = sys.stdin.readline

def update(i, x):
    ind = size+i
    seg_tree[ind] = x
    while ind>1:
        ind >>= 1
        left = seg_tree[ind*2]
        right = seg_tree[ind*2+1]
        seg_tree[ind] = min(left, right)
    
def find(s,t):
    L = s+size
    R = t+size
    ret = INF
    while L<R:
        if R&1:
            R-=1
            ret = min(ret, seg_tree[R])
        if L&1:
            ret = min(ret, seg_tree[L])
            L+=1
        L=L>>1
        R=R>>1
    return ret

for _ in range(q):
    com, x, y = map(int, input().split())
    if not com:
        update(x, y)
    else:
        print(find(x,y+1))


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

int main()
{
    int N, K; cin >> N >> K;
    vector<pair<int,int>> edges;
    if (K == 0) {
        // complete graph
        for (int u = 1; u <= N-1; u++) {
            for (int v = u+1; v <= N; v++) {
                edges.push_back(make_pair(u, v));
            }
        }
    } else if (K > N * (N-1) / 2 - (N-1)) {
        // nop
    } else {
        for (int v = 1; v < N; v++) {
            edges.push_back(make_pair(v, N));
        }
        int surplus = (N-1) * (N-2) / 2 - K;
        for (int u = 1; u <= N-2 && surplus > 0; u++) {
            for (int v = u + 1; v <= N-1 && surplus > 0; v++) {
                edges.push_back(make_pair(u, v));
                surplus--;
            }
        }
    }
    if (edges.size() == 0) {
        cout << -1 << endl;
    } else {
        cout << edges.size() << endl;
        for (const auto& e : edges) {
            cout << e.first << " " << e.second << endl;
        }
    }
}


Measured memory_bytes: 384
import java.util.*;
import java.math.*;

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

      Scanner sc = new Scanner(System.in);
         
      int N = sc.nextInt();
      
      int n = (int)Math.pow(3,N);
      
      int sum = 1;
      for(int i = 0;i < N;i++){
          int a = sc.nextInt();
          if(a%2 == 0){
              sum *=2;
          }else{
              sum *= 1;
          }          
      }
           
      System.out.println(n - sum);
      
   }
}
        

Measured memory_bytes: 23764
#include<stdio.h>
int main (){
	int num;
	int k;
	int a,b;
	scanf("%d %d %d %d",&num,&k,&a,&b);
	int sum=0;
	if(num<=k){
		sum=num*a;
	}
	if(num>k){
		sum=k*a+(num-k)*b;
	}
	printf("%d",sum);
	return 0;
}

Measured memory_bytes: 128
#include <iostream>
#include <vector>
#include <map>
#include <algorithm>
#include <cstdlib>
#include <cmath>
#include <numeric>
#include <tuple>
#include <stack>

#define rep(i,n) for (int i = 0; i < (n); ++i)
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(),x.rend()
#define print(s) cout << s << endl
typedef long long ll;
using namespace std;

int ctoi(char c) {
	if (c >= '0' && c <= '9') {
		return c - '0';
	}
	return 0;
}

int main() {
	int n; cin >> n;
	vector<int> v(n),vv;
	rep(i,n){
		cin >> v[i];
		
	}
	sort(rall(v));
	rep(i,n){
		if (i == 0){
			vv.push_back(v[i]);
			continue;
		}
		if (vv[vv.size()-1] != v[i]){
			vv.push_back(v[i]);
		}
	}
	cout << vv.size() << endl;
}

Measured memory_bytes: 256
#include <iostream>
#define MAX_N 15
using namespace std;
int n,m=0,cnt,flag,change=0;
int s[MAX_N],p[MAX_N];

int main(){
	while(1){
		cin >> n;
		if(n==0)break;
		m=0;
		while(m!=n){
			cin >> s[m];
			m++;
		}
		change=0;
		while(1){
			for(int i=0;i<n;i++){
				cnt=0;
				for(int j=0;j<n;j++){
					if(s[i]==s[j])cnt++;
				}
				p[i]=cnt;
			}
			flag=0;
			for(int i=0;i<n;i++){
				if(s[i]==p[i])flag++;
				s[i]=p[i];
			}
			if(flag==n)break;
			change++;
		}
		cout <<change <<endl;
		for(int i=0;i<n-1;i++){
			cout << s[i]<<" ";
		}
		cout <<s[n-1]<<endl;
	}
	return 0;
}

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

int n;
int a[310];

int sum[310][310];
int dp[310][310];

const int inf=1<<26;

inline int cost(int a,int b){
	int c=0,res=0;
	while(a||b){
		int x=a%10,y=b%10;
		res+=x*y;
		c=(x+y+c>=10)?1:0;
		res+=c;
		a/=10,b/=10;
	}
	return res;
}

int main(void){
	cin >> n;
	rep(i,n) cin >> a[i];
	rep(i,n+1)rep(j,n+1){
		sum[i][j]=0;
		dp[i][j]=inf;
	}
	rep(i,n){
		sum[i][i+1]=a[i];
		dp[i][i+1]=0;
	}
	for(int d=2;d<=n;d++){
		for(int i=0;i+d<=n;++i){
			// dp[i][i+d]
			// = dp[i][j]+dp[j][i+d]
			for(int j=i+1;j<i+d;++j){
				sum[i][i+d]=sum[i][j]+sum[j][i+d];
				dp[i][i+d]=min(dp[i][i+d],dp[i][j]+dp[j][i+d]+cost(sum[i][j],sum[j][i+d]));
			}
		}
	}
	cout << dp[0][n] << endl;
}

Measured memory_bytes: 1896
#include <iostream>
#include <sstream>
#include <vector>
#include <algorithm>
#include <numeric>
#include <cmath>
#include <utility>
#include <map>
#include <list>
#include <climits>
#include <set>
#include <deque>
#include <stack>
#include <unordered_map>
#include <unordered_set>
#include <iomanip>
#include <bitset>

// #define cerr if(false)cerr
#define watch(x) cerr << "> " << #x << ": " << x << "\n";

using namespace std;

template <typename T>
std::ostream &operator <<(std::ostream &out, vector<T> &v) {
	for (typename vector<T>::size_type i = 0; i < v.size(); ++i)
		out << v[i] << " ";
	out << "\n";
    return out;
}
template <typename T, typename N>
std::ostream &operator <<(std::ostream &out, vector<pair<T, N> > &v) {
	for (size_t i = 0; i < v.size(); ++i)
		out << "(" << v[i].first << ", " << v[i].second << ") ";
	out << "\n";
    return out;
}
template <typename T>
std::ostream &operator <<(std::ostream &out, vector<vector<T> > &v) {
	for (size_t i = 0; i < v.size(); ++i) {
		for (size_t j = 0; j < v[i].size(); ++j) {
			out << v[i][j] << " ";
		}
		out << "\n";
	}
   	return out;
}

long long eval(long long a, long long b, long long x) {
	return (a * x / b) - a * (x / b);
}

int main() {

	std::ios::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);

	long long a, b, n;
	cin >> a >> b >> n;

	if (n < b) {
		cout << eval(a, b, n) << "\n";
	} else {
		if (n % b == 0) {
			cout << eval(a, b, n - 1) << "\n";
		} else {
			long long f = n / b;
			long long x = b * (f + 1) - 1;
			cout << eval(a, b, x) << "\n";
		}
	}

	return 0;

}

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

#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define copy(from, to) copy(from.begin(), from.end(), back_inserter(to))
#define sort(a) sort(a.begin(), a.end())
#define p(s) cout << (s) << endl

typedef long long ll;
using namespace std;

template<class T>
void load(vector<T> &v, int n) {
  for (int i = 0; i < n; ++i) {
    T t;
    cin >> t;
    v.push_back(t);
  }
}


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

  string ch = s.substr(0, 4);
  if (ch == "YAKI") {
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <boost/range/algorithm.hpp>
#include <boost/range/numeric.hpp>
#include <boost/integer/common_factor.hpp>
#include <boost/integer/common_factor_rt.hpp>
#include <boost/multiprecision/cpp_dec_float.hpp>
#include <boost/multiprecision/cpp_int.hpp>

using std::string;
using std::vector;
using std::set;
using std::multiset;
using std::unordered_set;
using std::map;
using std::multimap;
using std::unordered_map;
using std::pair;
using std::cin;
using std::cout;

using boost::multiprecision::cpp_int;
using cpp_dec_float_1000 = boost::multiprecision::number<boost::multiprecision::cpp_dec_float<1000>>;

typedef uintmax_t    ull;
typedef intmax_t     ll;
typedef uint64_t     ul;
typedef uint32_t     ui;
typedef uint8_t      uc;

constexpr char CRLF  = '\n';
constexpr char SPACE = ' ';
constexpr char VECTOR_COUT_SEPARATOR = SPACE;
constexpr ll INF = 1000'000'007;
constexpr int MOD = 1000'000'007;

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> std::ostream& operator<< (std::ostream& os, const std::vector<T>& vc) { for(auto it = vc.begin(); it != vc.end(); ++it) { if (std::next(it) == vc.end()) os << *it; else os << *it << VECTOR_COUT_SEPARATOR; } return os; }
template<class T1, class T2> inline std::ostream & operator<< (std::ostream & os, const std::pair<T1, T2> & p) { return os << p.first << ' ' << p.second; }
template<class T> T modinv(T a, T m) { T b = m, u = 1, v = 0; while (b) { T t = a / b; a -= t * b; boost::swap(a, b); u -= t * v; boost::swap(u, v); } u %= m; if (u < 0) u += m; return u; }

struct Tmp
{
public:
  Tmp(int N);
};

Tmp::Tmp(int N){}

constexpr int inf = (100000)*2 + 1;
std::array<std::array<int, inf>, 31> jikokuhyo{};

void solve(void)
{
  int N, C; cin >> N >> C;
  for (int i = 0; i < N; ++i) {
    int s, t, c; cin >> s >> t >> c;
    --c;
    jikokuhyo[c][s*2-1] += 1;
    jikokuhyo[c][t*2] -= 1;
  }

  for (int time = 1; time < inf; ++time) {
    for (int index = 0; index < C; ++index) {
      jikokuhyo[index][time] += jikokuhyo[index][time-1];
    }
  }
  vector<int> result(inf, 0);
  for (int t = 0; t < inf; ++t) {
    int res{};
    for (int i = 0; i < C; ++i) {
      if (jikokuhyo[i][t] > 0) {
        ++res;
      }
    }
    result[t] = res;
  }
  auto ans = boost::max_element(result);
  cout << *ans << CRLF;
  return;
}

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

  solve();

  return 0;
}


Measured memory_bytes: 24448
#include<bits/stdc++.h>
#define ll long long
using namespace std;
int tot,n,rt,e[500010],nt[500010],hd[500010],du[500010];
void build(int x,int y){
	tot++;
	e[tot]=y;
	nt[tot]=hd[x];hd[x]=tot;
}
int dfs(int x,int fa){
	int i,y,ans=0,flag=0;
	for(i=hd[x];i;i=nt[i]){
		if(e[i]==fa)continue;
		y=dfs(e[i],x);
		if(!y&&flag)ans++;
		if(!y&&!flag)flag=1;
		ans+=y;
	}
	return ans;
}
int main(){
	int i,x,y;
	scanf("%d",&n);
	for(i=1;i<n;i++){
		scanf("%d%d",&x,&y);x++;y++;
		build(x,y);build(y,x);
		du[x]++;du[y]++;
	}
	for(i=1;i<=n;i++)if(du[i]>2){
		rt=i;break;
	}
	if(du[rt]<=2){
		puts("1");return 0;
	}
	printf("%d",dfs(rt,0));
}

Measured memory_bytes: 8704
#include <iostream>
#include <map>
#include <string>
#include <algorithm>

int main() {
	int n;
	long long cnt = 0;
	std::cin >> n;
	std::map<std::string, long long> strs;
	for (int i = 0; i < n; i++) {
		std::string s;
		std::cin >> s;
		std::sort(s.begin(), s.end());
		if (strs.find(s) == strs.end()) {
			strs.insert(std::make_pair(s, 1));
		} else {
			cnt += strs.at(s);
			strs.at(s) += 1;
		}
	}
	std::cout << cnt << "\n";
	return 0;
}

Measured memory_bytes: 11396
#pragma region Template
#include <bits/stdc++.h>
using namespace std;
struct ios_accelerate { ios_accelerate() { ios::sync_with_stdio(false); cin.tie(nullptr); } } CALL;

#define REP(i, n) for(int i = 0; i < n; i++)
#define RNG(i, a, b) for(int i = a; i < b; i++)
#define RBF(i, v) for(auto& i : v)
#define ALL(x) x.begin(), x.end()

using LL = long long;
using UL = unsigned long;
using ULL = unsigned long long;
template<typename T> using V = vector<T>;
template<typename T> using VV = vector<vector<T>>;
template<typename T> using P = pair<T, T>;

const double PI = 3.141592653589793;
const int MOD = 1000000007;
const LL INF64 = static_cast<LL>(1e18) + 2;
const int INF = static_cast<int>(1e9) + 2;

template<typename T> inline void upsort(vector<T>& x) { sort(x.begin(), x.end()); }
template<typename T> inline void downsort(vector<T>& x) { sort(x.begin(), x.end(), greater<T>()); }
template<typename T> inline void col(T x) { cout << x << '\n'; }
template<> inline void col(double x) { cout << fixed << setprecision(12) << x << '\n'; }
#pragma endregion

signed main()
{	
	const int inf = static_cast<int>(1e9) + 2;
	int h, n;
	cin >> h >> n;
	vector<int> a(n), b(n);
	for (int i = 0; i < n; i++) {
		cin >> a[i] >> b[i];
	}

	// dp[i+1][j] := i番目までの魔法を使って体力jのモンスターを倒すのに必要な最小の魔力
	vector<vector<int>> dp(n + 1, vector<int>(h + 1, inf));
	for (int i = 0; i < n + 1; i++) {
		dp[i][0] = 0;
	}

	for (int i = 0; i < n; i++) {
		for (int j = 0; j < h+1; j++) {
			if (a[i] > j) dp[i + 1][j] = min(dp[i][j], dp[i + 1][0] + b[i]);
			else dp[i + 1][j] = min(dp[i][j], dp[i + 1][j - a[i]] + b[i]);
		}
	}

	cout << dp[n][h] << endl;
	return 0;
}


Measured memory_bytes: 42468
// 2014/10/27 Tazoe

#include <iostream>
using namespace std;

int Cnt;

void Merge(int A[500000], int left, int mid, int right)
{
	const int SENTINEL = 1000000001;

	int n1 = mid-left;
	int n2 = right-mid;

	int L[250001], R[250001];

	for(int i=0; i<n1; i++){
		L[i] = A[left+i];
	}
	for(int i=0; i<n2; i++){
		R[i] = A[mid+i];
	}
	L[n1] = SENTINEL;
	R[n2] = SENTINEL;

	for(int i=0, j=0, k=left; k<right; k++){
		if(Cnt++, L[i]<=R[j]){
			A[k] = L[i];
			i++;
		}
		else{
			A[k] = R[j];
			j++;
		}
	}
}

void Merge_Sort(int A[500000], int left, int right)
{
	if(left+1>=right)
		return;

	int mid = (left+right)/2;
	Merge_Sort(A, left, mid);
	Merge_Sort(A, mid, right);
	Merge(A, left, mid, right);
}

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

	int S[500000];
	for(int i=0; i<n; i++){
		cin >> S[i];
	}

	Cnt = 0;

	Merge_Sort(S, 0, n);

	for(int i=0; i<n; i++){
		cout << S[i];

		if(i<n-1){
			cout << ' ';
		}
		else{
			cout << endl;
		}
	}

	cout << Cnt << endl;

	return 0;
}

Measured memory_bytes: 5064
#include <stdio.h>
#include <stdlib.h>
#include <queue>
#include <utility>
#include <vector>

#define MAX_N (100000)
#define MAX_M (100000)

using namespace std;

// distances should be initialized to negative values
void dijkstra(const vector<vector<pair<long, long>>> &adj_lists,
              vector<long> &distances, long s) {
  priority_queue<pair<long, long>, vector<pair<long, long>>,
                 greater<pair<long, long>>>
      que;
  que.push(pair<long, long>(0, s));
  while (!que.empty()) {
    const long v = que.top().second, d = que.top().first;
    que.pop();
    if (distances[v] < 0) {
      distances[v] = d;
      for (const pair<long, long> &p : adj_lists[v]) {
        const long u = p.first, w = p.second;
        que.push(pair<long, long>(d + w, u));
      }
    }
  }
}

int main(int argc, char *argv[]) {
  // read inputs
  long n, m, s, t, us[MAX_M], vs[MAX_M], as[MAX_M], bs[MAX_M];
  scanf("%ld %ld %ld %ld", &n, &m, &s, &t);
  s--;  // NOTE : modified input
  t--;  // NOTE : modified input
  for (long k = 0; k < m; k++) {
    scanf("%ld %ld %ld %ld", &us[k], &vs[k], &as[k], &bs[k]);
    us[k]--;  // NOTE : modified input
    vs[k]--;  // NOTE : modified input
  }

  // create graph
  vector<vector<pair<long, long>>> adj_lists_yen(n, vector<pair<long, long>>());
  vector<vector<pair<long, long>>> adj_lists_snuk(n,
                                                  vector<pair<long, long>>());
  for (long k = 0; k < m; k++) {
    const long u = us[k], v = vs[k], a = as[k], b = bs[k];
    adj_lists_yen[u].push_back(pair<long, long>(v, a));
    adj_lists_yen[v].push_back(pair<long, long>(u, a));
    adj_lists_snuk[u].push_back(pair<long, long>(v, b));
    adj_lists_snuk[v].push_back(pair<long, long>(u, b));
  }

  // dijkstra
  vector<long> distances_yen(n, -1), distances_snuk(n, -1);
  dijkstra(adj_lists_yen, distances_yen, s);
  dijkstra(adj_lists_snuk, distances_snuk, t);

  // put into queue
  priority_queue<pair<long, long>, vector<pair<long, long>>,
                 greater<pair<long, long>>>
      que;
  for (int i = 0; i < n; i++) {
    // exchange at i
    que.push(pair<long, long>(distances_yen[i] + distances_snuk[i], i));
  }

  // solve
  for (int i = 0; i < n; i++) {
    // skip the impossible
    while (que.top().second < i) {  // NOTE : input is modified
      que.pop();
    }
    printf("%ld\n", 1000000000000000L - que.top().first);
  }

  return 0;
}


Measured memory_bytes: 22896
def solve():
    N = int(input())
    val = []

    for i in range(N):
        tmp = list(map(int, input().split()))
        val.append(tmp)
    
    dp = [[0] * 3 for i in range(N+1)]

    for i in range(N):
        for j in range(3):
            for k in range(3):
                if j == k:
                    continue
                dp[i+1][k] = max(dp[i+1][k], dp[i][j] + val[i][j])
    
    print(max(*dp[N]))

if __name__ == '__main__':
    solve()


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

const double PI = acos(-1);

int main() {
    int k;
    cin >> k;
    vector<ll> a;

    for (int i = 1; i <= 9; ++i) a.push_back(i);
    
    // 1ループで一桁ずつ増やす
    while (1) {
        if (k <= a.size()) {
            // rep(i, a.size()) printf("%lld, %s", a[i], " ");
            // cout << endl;
            cout << a[k-1] << endl;
            return 0;
        }
        k -= a.size();
        vector<ll> old; // 一桁少ないやつ
        swap(old, a); // oldに一桁くっつけたのをaにつっこむ
        for (ll x : old) { // 範囲for文 配列oldの中身をひとつずつxに入れる
            for (int i = -1; i <= 1; ++i) {
                int d = x%10 + i; // 末尾につける数字
                if (d < 0 || d > 9) continue;
                ll nx = x*10 + d;
                a.push_back(nx);
            }
        }
    }

    return 0;
}

Measured memory_bytes: 4648
n=int(input())
root=[i for i in range(n)]
oya_ko={}
ko_oya={}




#result[node]={[parent,[child]]}
for _ in range(n):
    temp=list(map(int,input().split()))
    #print(temp)
    node=temp[0]
    if temp[1]==0:
        child=[]
    else:
        child=temp[2:]

    oya_ko[node]=child

    for item in child:
        #print(root)
        ko_oya[item]=node
        root.remove(item)

depth={}

def makeDepth(x,y):
    depth[x]=y
    if oya_ko[x]==[]:
        return 0
    else:
        for item in oya_ko[x]:
            makeDepth(item,y+1)

makeDepth(root[0],0)
ko_oya[root[0]]=-1
"""
print(depth)
print(ko_oya)
print(oya_ko)
"""
for i in range(n):

    if i==root[0]:
        typ="root"
    elif oya_ko[i]==[]:
        typ="leaf"
    else:
        typ="internal node"
    print("node",str(i)+": parent =",str(ko_oya[i])+", depth =",str(depth[i])+",",typ+",",str(oya_ko[i]))
    



Measured memory_bytes: 39484
#include <stdio.h>
#include<stdlib.h>
#define MAX 100005
#define N -1

struct Node {int p,l,r;};

struct Node  T[MAX];
int n,D[MAX];

void Pre(int u){
  if(u == N) return;
  printf(" %d",u);
  Pre(T[u].l);
  Pre(T[u].r);
}

void In(int k){
  if(k == N) return;
  In(T[k].l);
  printf(" %d",k);
  In(T[k].r);
}

void Post(int h){
  if(h == N) return;
  Post(T[h].l);
  Post(T[h].r);
  printf(" %d",h);
}

int main(){

  int n,i,j,num,node,nodenum,c,left,right,r,root;

  scanf("%d",&n);
  if(n < 1 || n > 25)exit(1);

  for(i = 0 ; i < n ; i++) T[i].p = N;

  for(i = 0;i < n ; i++){
    scanf("%d %d %d",&node,&left,&right);
    T[node].l = left;
    T[node].r = right;
    if(left != N) T[left].p = node;
    if(right != N) T[right].p = node;

    }

  for(i = 0 ; i < n ; i++) if(T[i].p == N) root = i;

printf("Preorder\n");
Pre(root);
printf("\n");
printf("Inorder\n");
In(root);
printf("\n");
printf("Postorder\n");
Post(root);
printf("\n");

return 0;
}



Measured memory_bytes: 2132
#include <stdio.h>

int n;
int a[200010];
int memo[200010];

int main()
{
    scanf("%d",&n);
    for(int i=0;i<n-1;i++)scanf("%d",&a[i]);
    
    for(int i=0;i<n-1;i++)
    {
        memo[a[i]]++;
    }
    for(int i=0;i<n;i++)
    {
        printf("%d\n",memo[i+1]);
    }
}

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

int main(){
    int n;
    double res;
    cin >> n;
    vector<int> v(n);
    for(int i = 0;i < n;i++){
        cin >> v.at(i);
    }
    sort(v.begin(),v.end());
    res = v.at(0);
    for(int i = 1;i < n;i++){
        res = (res+v.at(i))/2.;
    }
    cout << res << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using ll = long long;
#define FOR(i, k, n) for(ll i = (k); i < (n); i++)
#define FORe(i, k, n) for(ll i = (k); i <= (n); i++)
#define FORr(i, k, n) for(ll i = (k)-1; i > (n); i--)
#define FORre(i, k, n) for(ll i = (k)-1; i >= (n); i--)
#define REP(i, n) FOR(i, 0, n)
#define REPr(i, n) FORre(i, n, 0)
#define ALL(x) (x).begin(), (x).end()
#define ALLr(x) (x).rbegin(), (x).rend()
#define chmin(x, y) x = min(x, y)
#define chmax(x, y) x = max(x, y)
using namespace std;

const int INF = 1001001001;

const double pi = acos(-1);

int main(void){
  double a, b , h, m;
  cin >> a >> b >> h >> m;
  double x = 360.0 / 12 * (h+m/60);
  double y = 360 / 60 * m;
  double z = (x-y)/180 * pi;
  double ans = sqrt(a*a+b*b -2*a*b*cos(z));
  printf("%.10f\n", ans);
  return 0;
}

Measured memory_bytes: 4164
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc  =new Scanner(System.in);
		int N = sc.nextInt();
		int K = sc.nextInt();
		int[] h = new int[N];
		int cnt = 0;
		for(int i = 0;i < N;i++) {
			h[i] = sc.nextInt();
			if(h[i] >= K) {
				cnt++;
			}
		}
		sc.close();
		System.out.println(cnt);
	}
}

Measured memory_bytes: 50244