akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <iomanip>
#include <string>
#include <cmath>
#include <numeric>
#include <climits>
#include <vector>
#include <list>
#include <map>
#include <set>
#include <unordered_map>
#include <unordered_set>
#include <stack>
#include <queue>
#include <deque>
#include <algorithm>
#include <functional>
#include <utility>
#include <cctype>
#include <iterator>
////////////////////////////////////////////////
#define REP(i, n) for (int i = 0; i < (int)n; i++)
#define FOR(i, m, n) for (int i = (int)m; i < (int)n; i++)
#define REPvec(itr, mp) for (auto itr = mp.begin(); itr != mp.end(); itr++)
#define REPe(e, mp) for (auto& e : mp)
#define all(x) x.begin(), x.end()
#define MOD 1000000007  // 1e9+7
using namespace std;
using ll = long long int;
using vecint = vector<int>;
using vecll = vector<ll>;
using vec2int = vector<vector<int>>;
using P = pair<int, int>;
////////////////////////////////////////////////
////////////////////////////////////////////////
int main() {
  ////////////////////////////////////////////////
  cin.tie(nullptr);
  ios_base::sync_with_stdio(false);
  ////////////////////////////////////////////////
  ll n;
  cin >> n;
  ll m = 0;
  ll x = 0;
  vector<ll> b;
  while (x <= n) {
    x = x + pow(26LL, m);
    b.push_back(x);
    m++;
  }
  // REPe(e, b) cout << e << endl;
  m--;
  n -= b[m - 1];
  // cout << n << endl;
  vecint a(m, 0);
  ll k = 26;
  for (int i = 0; i < m; i++) {
    a[i] = n % k;
    n = n / k;
    // cout << k << " " << a[i] << " " << n << endl;
  }
  // REP(i, m) { cout << a[i] << endl; }
  string s(m, 'a');
  REP(i, m) { s[m - i - 1] = ('a' + a[i]); }
  cout << s << endl;
}


Measured memory_bytes: 4056
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <vector>
#include <cmath>

using namespace std;

#define ll long long
#define mp make_pair
#define pb push_back

#define maxN 100011

int n, i, pos, cnt;
int a[maxN];
vector<int> ord[2], need, aux;

int main()
{
//    freopen("test.in", "r", stdin);

    scanf("%d", &n);
    for (i = 1; i <= n; i++) scanf("%d", &a[i]), ord[i & 1].pb(a[i]);

    sort(ord[0].begin(), ord[0].end());
    sort(ord[1].begin(), ord[1].end());
    sort(a + 1, a + n + 1);
    for (i = 1; i <= n; i += 2) need.pb(a[i]);

    aux = ord[1]; pos = 0;
    for (i = 0; i < aux.size(); i++) {
        while (pos < need.size()) {
            if (need[pos] >= aux[i]) break;
            pos++;
        }

        if (pos < need.size()) {
            if (need[pos] == aux[i]) {
                pos++;
                cnt++;
            }
        }
    }

    printf("%d", aux.size() - cnt);


    return 0;
}


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

int main() {
  int A, B, C, D, E, F; cin >> A >> B >> C >> D >> E >> F;
  int maxW = 100 * A, maxS = 0;
  for (int a = 0; a <= F; a += 100 * A) {
    for (int b = a; b <= F; b += 100 * B) {
      for (int c = 0; c <= F - b; c += C) {
        for (int d = c; d <= F - b; d += D) {
          if (((100 + E) * d <= (b + d) * E ) && (d * (maxW + maxS) > maxS * (b + d))) {
            maxW = b; maxS = d;
          }
        }
      }
    }
  }
  cout << (maxW + maxS) << " " << maxS << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define f first
#define s second


int main()
{
	ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    
    int n;
    cin>>n;
    ll h[n];
    ll sum=0,mh=0;
    
    for(int i=0;i<n;i++){
    	cin>>h[i];
    	sum+=max((ll)0,mh-h[i]);
    	mh=max(mh,h[i]);
	}
	
	cout<<sum;
    return 0;
}

Measured memory_bytes: 5200
#include<bits/stdc++.h>
#define maxn 100005
#define pii pair<int,int>
using namespace std;
int n;
map<int,int> cnt1,cnt2;
int main() {
	ios::sync_with_stdio(0);
	cin.tie(0);
	cin >> n;
	for(int i=0,val1,val2;i<n/2;i++) {
		cin >> val1 >> val2;
		cnt1[val1]++;
		cnt2[val2]++;
	}
	vector<pii> v1,v2;
	for(pii now : cnt1)
		v1.emplace_back(now);
	for(pii now : cnt2)
		v2.emplace_back(now);
	v1.emplace_back(pii{-1,0});
	v2.emplace_back(pii{-2,0});
	sort(v1.begin(),v1.end(),[=](pii a,pii b)->bool
	    {return a.second > b.second;});
	sort(v2.begin(),v2.end(),[=](pii a,pii b)->bool
	    {return a.second > b.second;});
	int ans = n;
	for(int i=0;i<2;i++)
		for(int j=0;j<2;j++)
			if(v1[i].first != v2[j].first)
				ans = min(ans,n-v1[i].second-v2[j].second);
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 6140
#include <stdio.h>
int main(){
  int a,b,x;
  char op;
 
  while(1){
    scanf("%d %c %d",&a,&op,&b);
    if(op == '?') break;
  
  
  if(op == '+'){
    x=a+b;
   
  }
  
  else if(op == '-'){
    x=a-b;
     
  }
  
  else if(op == '*'){
    x=a*b;
     
  }
  
  else if(op == '/'){
      x=a/b;
      
  }
  
  printf("%d\n",x);
  }
  return 0;
}

Measured memory_bytes: 600
// AOJ 2001

#include <iostream>

using namespace std;

int main(void)
{
	int n, m, a;
	while (cin >> n >> m >> a, n && m){
		int h, q, p;
		int data[1050][128];
		for (int i = 0; i < 1050; i++){
			for (int j = 0; j < 128; j++){
				data[i][j] = 0;
			}
		}
		// 下から上
		for (int i = 0; i < m; i++){
			cin >> h >> p >> q;
			data[h][p] = q;
			data[h][q] = p;
		}

		for (int i = 1000; 0 < i; i--){
			if (data[i][a]){
				a = data[i][a];
			}
		}

		cout << a << endl;
	}

	return 0;

}

Measured memory_bytes: 1684
class Heap
  attr_reader :size

  def initialize
    @size = 0
    @heap = []
  end

  def empty?
    @size.zero?
  end

  def push(val)
    index = size
    @size += 1

    while index > 0
      parent = (index - 1) / 2

      break if @heap[parent] <= val

      @heap[index] = @heap[parent]
      index = parent
    end

    @heap[index] = val
  end

  alias_method :<<, :push

  def pop
    val = @heap.first
    root = @heap[size - 1]
    @heap[size - 1] = nil
    @size -= 1
    index = 0

    while index * 2 + 1 < @size
      left = 2 * index + 1
      right = left + 1

      if right < size && @heap[right] < @heap[left]
        left = right
      end

      break if @heap[left] >= root

      @heap[index] = @heap[left]
      index = left
    end

    @heap[index] = root
    val
  end

  def top
    @heap.first
  end
end

N, K = gets.split.map(&:to_i)
P = gets.split.map(&:to_i)

list = []

sum = 0
ans = 0

min_heap = Heap.new
max_heap = Heap.new

no_sort = false
gone = Hash.new(false)
cur = -1
suc = 0

N.times do |i|
  if cur < P[i]
    suc += 1
  else
    suc = 1
  end

  cur = P[i]
  
  min_heap.push(P[i])
  max_heap.push(-P[i])

  next if K - 1 > i

  no_change = false

  if i >= K
    v = P[i - K]
    gone[v] = true

    while !max_heap.empty? && gone[-max_heap.top]
      max_heap.pop
    end

    if -max_heap.top == P[i] && min_heap.top == v
      no_change = true
    end

    while !min_heap.empty? && gone[min_heap.top]
      min_heap.pop
    end
  end

  if suc < K
    ans += 1 unless no_change
  else
    no_sort = true
  end
end

if no_sort
  ans += 1
end

puts ans


Measured memory_bytes: 31252
N, K = map(int, raw_input().split())

As = map(int, raw_input().split())

a = N
for i in range(len(As)):
  start = As[i]
  stop = As[i-1]
  a_t = stop-start
  if a_t <= 0: a_t += N
  if a_t < a: a = a_t

print a

Measured memory_bytes: 20032
#include<iostream>
#include<vector>
#include<algorithm>

using namespace std;

int main(void){

  int prime[300000],a[300000];

  fill(prime,prime+300000,1);
  fill(a,a+300000,0);

  for(int i=0;i<300000;i++)if(i%7==1||i%7==6)a[i]=1;

  prime[0]=prime[1]=0;

  for(int i=2;i*i<300000;i++)
    if(a[i]==1)
      for(int j=i*2;j<300000;j+=i)
	prime[j]=0;

  int x;
  vector<int>ans;
  while(cin >> x,x!=1){
    ans.clear();
    for(int i=0;i<=x;i++)
      if(prime[i] && a[i] && x%i==0)ans.push_back(i);
    
    cout << x <<": ";

    for(int i=0;i<ans.size();i++){
      cout << ans[i];
      if(i==ans.size()-1)cout << endl;
      else cout << " ";
    }
  }

  return 0;
}

Measured memory_bytes: 3560
#pragma GCC optimize("Ofast")
#include<bits/stdc++.h>
using namespace std;
struct __INIT{__INIT(){cin.tie(0);ios::sync_with_stdio(false);cout<<fixed<<setprecision(15);}} __init;
#define max3(a,b,c) max(a,max(b,c))
#define min3(a,b,c) min(a,min(b,c))
#define MOD 1000000007
#define INF (1<<30)
#define LINF (lint)(1LL<<56)
#define endl "\n"
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define reprev(i,n) for(int (i)=(n-1);(i)>=0;(i)--)
#define Flag(x) (1<<(x))
#define Flagcount(x) __builtin_popcount(x)
#define pint pair<int,int>
#define pdouble pair<double,double>
#define plint pair<lint,lint>
#define fi first
#define se second
typedef long long lint;
int dx[8]={1,1,0,-1,-1,-1,0,1};
int dy[8]={0,1,1,1,0,-1,-1,-1};

int main(void){
    lint A,B,M;
    cin >> A >> B >> M;
    lint a[A],b[B];
    rep(i,A) cin >> a[i];
    rep(i,B) cin >> b[i];
    lint x[M],y[M],c[M];
    rep(i,M) cin >> x[i] >> y[i] >> c[i];
    lint ans=*min_element(a,a+A)+*min_element(b,b+B);
    rep(i,M){
        x[i]--,y[i]--;
        ans=min(ans,a[x[i]]+b[y[i]]-c[i]);
    }
    cout << ans << endl;
}

Measured memory_bytes: 4224
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N=1e5+5;
int n,a[N];
ll dp[N];
int main()
{
    scanf("%d",&n);
    for(int i=1;i<=n;i++) scanf("%d",&a[i]);
    dp[2]=abs(a[1]-a[2]);
    for(int i=3;i<=n;i++)
    {
        dp[i]=min(dp[i-1]+abs(a[i]-a[i-1]),dp[i-2]+abs(a[i]-a[i-2]));
    }
    printf("%d\n",dp[n]);
}


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

int main() {
	int N,l,r;
    int sums = 0;
    cin >> N;
      
    for (int i = 0; i < N; i++){
    	cin >> l >> r;
      	sums += r - l + 1;
    }
cout << sums << endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<stdio.h>
#include<vector>
#include<algorithm>
#include<string>

using namespace std;

int main(){
    char b;
    cin >> b;
    char a;
    if(b=='A')a = 'T';
    else if(b=='C')a = 'G';
    else if(b=='G')a = 'C';
    else if(b=='T')a = 'A';
    cout << a << endl;
    return 0;
}


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

int main() {
  int n;
  vector<int> a(9);
  vector<int> c(9);
  for(int i=0;i<9;i++) cin >> a.at(i);
  cin >> n;
  vector<int> b(n);
  for(int i=0;i<n;i++) {
    cin >> b.at(i);
    for(int j=0;j<9;j++) {
      if(a.at(j)==b.at(i)) c.at(j)=1;
    };
  };
  string ans="No";
  if(c.at(0)+c.at(1)+c.at(2)==3) ans="Yes";
  if(c.at(3)+c.at(4)+c.at(5)==3) ans="Yes";
  if(c.at(6)+c.at(7)+c.at(8)==3) ans="Yes";
  if(c.at(0)+c.at(3)+c.at(6)==3) ans="Yes";
  if(c.at(1)+c.at(4)+c.at(7)==3) ans="Yes";
  if(c.at(2)+c.at(5)+c.at(8)==3) ans="Yes";
  if(c.at(0)+c.at(4)+c.at(8)==3) ans="Yes";
  if(c.at(2)+c.at(4)+c.at(6)==3) ans="Yes";
  cout << ans << endl;
}

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

int main(){
    int n; cin >> n;
    map<string, int> map;
    string key;
    for (int i = 0; i < n; i++)
    {
        cin >> key;
        map[key] = 1;
    }
    cout << map.size() << endl;
    return 0;
}

Measured memory_bytes: 19228
#include<bits/stdc++.h>
#include<numeric>
using namespace std;
#define ll  long long
#define mp make_pair
#define fi first
#define se second
#define pii pair<ll,ll>
#define pb push_back
#define io ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define what_is(x) cerr << #x << " is " << x << endl;
#define mod 1000000007
// #define max INT_MAX
int main()
{
    int n;string str;
    cin >> n;
    cin >> str;
    int dp[26]={0};
    for(int i=0;i<str.size();i++)
    dp[str[i]-'a']++;
    int temp[26]={0};
    for(int i=1;i<n;i++)
    {
        cin >> str;
        for(int i=0;i<str.size();i++)
        {
            temp[str[i]-'a']++;
        }
        for(int i=0;i<26;i++)
        {
            dp[i] = min(dp[i],temp[i]);
            temp[i]=0;
        }
    }
    for(int i=0;i<26;i++)
    {
        for(int j=0;j<dp[i];j++)
        {
            char ch = i+'a';
            cout << ch ;
            
        }
    }
}

Measured memory_bytes: 256
a, b = map(int, input().split())
for n in range(1010):
    a1 = int(n * 8/100)
    b1 = int(n * 10/100)
    if a1 == a and b1 == b:
        n1 = n
        break
    else:
        n1 = "-1"
print(n1)

Measured memory_bytes: 3060
while 1:
    n=input()
    if n==0:break
    a=[int(raw_input()) for _ in xrange(n)]
    wa=[0]*(n+1)
    max_a=-1000000
    for i in xrange(n):
        wa[i+1]=a[i]+wa[i]
    for i in xrange(n):
        for j in xrange(i+1,n+1):
            if max_a<wa[j]-wa[i]:
                max_a=wa[j]-wa[i]
    print(max_a)

Measured memory_bytes: 6512
import collections

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

o=[]
e=[]
for i in range(n):
    if i%2==0:
        e.append(v[i])
    else:
        o.append(v[i])
count_o=collections.Counter(o)
count_e=collections.Counter(e)
count_o=list(count_o.items())
count_e=list(count_e.items())
count_o=sorted(count_o,key=lambda x:x[1])
count_e=sorted(count_e,key=lambda x:x[1])
if count_o[-1][0]==count_e[-1][0]:
    if len(count_e)==1:
        addnum_e=0
    else:
        addnum_e=count_e[-2][1]
    if len(count_o)==1:
        addnum_o=0
    else:
        addnum_o=count_o[-2][1]
    oe=count_o[-1][1]+addnum_e
    eo=addnum_o+count_e[-1][1]
    total=max(oe,eo)
else:
    total=count_o[-1][1]+count_e[-1][1]
print(n-total)

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

int main()
{
    ll N;
    cin >> N;
    vector<ll> h(N);
    for(int i = 0; i < N; i++)
    {
        cin >> h[i];
    }
    ll count = 0;
    for(int i = 0; i < N; i++)
    {
        while(h[i] != 0)
        {
            for(int j = i; j < N; j++)
            {
                if(h[j] == 0)break;
                h[j]--;
            }
            count++;
        }
    }
    cout << count << endl;
}

Measured memory_bytes: 256
N=int(input())
i=1
t=0
while i<N+1:
    a,b,c=map(int,input().split())
    if a>b:
        t=a;a=b;b=t
    if b>c:
        t=b;b=c;c=t
    if a>b:
        t=a;a=b;b=t 
    if a*a + b*b == c*c:
        print("YES")
    else:
        print("NO") 
    i=i+1



Measured memory_bytes: 5592
#include <bits/stdc++.h>
#define rep(i,n) for (long long i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
using P = pair<int,int>;
  
int main() {
  int a, b, c;
  cin >> a >> b >> c;
  cout << max(a,max(b,c)) - min(a,min(b,c));
  return 0;
}



Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define inf 1e18
#define IOS ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define pb push_back
#define ff first
#define ss second
#define vll vector<ll>
#define pii pair<ll,ll>
#define sz(v) (v).size()
#define srt(v) sort(v.begin(),v.end())
#define ull unsigned long long
#define tell(a) cout<<a<<" "
#define el cout<<endl
#define rev(v) reverse(v.begin(),v.end())
#define rep(i,a,n) for(int i=a;i<n;i++)
#define ld long double
#define mem(a,b) memset(a,b,sizeof(a) )
#define M 4000010
#define md 1000000007

ll power(ll x, ll y, ll p){ll res = 1;x = x % p;while (y > 0){   if (y & 1)res = (res*x) % p;y = y>>1;
x = (x*x) % p;}return res;}
/*inline ll add(ll a,ll b){return (a+b)%md;}
inline ll mul(ll a,ll b){return (a*b)%md;}
ll f[M],iv[M];
ll C(ll n,ll r){return mul(f[n],mul(iv[r],iv[n-r]));}
void prep_fac(){
    f[0]=1;
    rep(i,1,M)f[i]=mul(i,f[i-1]);
    iv[M-1]=power(f[M-1],md-2,md);
    for(ll i=M-2;i>=0;--i)iv[i]=mul(i+1,iv[i+1]);
}*/



int main()
{
	IOS;
	ll k;
	cin>>k;
	ll p=7;
	string s="-1";
	for(int i=0;i<10000000;i++)
	{
		if(p%k==0){
			s=to_string(i+1);
			break;
		}
		p=(p*10+7)%k;
	}
	cout<<s;
}



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

vector<vector<long long>> matmul(vector<vector<long long>> A, vector<vector<long long>> B, int mod=0) {
  assert(A[0].size() == B.size());
  int n = A.size(), m=A[0].size(), l=B[0].size();
  vector<vector<long long>> C(n, vector<long long>(l));
  for(int i=0; i<m; i++) for(int j=0; j<n; j++) for(int k=0; k<l; k++) {
    C[j][k] += A[j][i] * B[i][k];
    if(mod) C[j][k] %= mod;
  }
  return C;
}

vector<long long> matmul(vector<vector<long long>> A, vector<long long> b, int mod=0) {
  assert(A[0].size() == b.size());
  int n = A.size(), m=A[0].size();
  vector<long long> C(n);
  for(int i=0; i<m; i++) for(int j=0; j<n; j++) {
    C[j] += A[j][i] * b[i];
    if(mod) C[j] %= mod;
  }
  return C;
}

vector<vector<long long>> matpow(vector<vector<long long>> A, long long p, int mod=0) {
  assert(A.size() == A[0].size());
  int n = A.size();
  vector<vector<long long>> B(n, vector<long long>(n));
  for(int i=0; i<n; i++) B[i][i] = 1;
  vector<vector<long long>> C(A);
  while (p > 0) {
    if (p & 1) {B = matmul(B, C, mod);}
    C = matmul(C, C, mod);
    p >>= 1;
  }
  return B;
}

signed main() {
#if 1 // https://atcoder.jp/contests/dp/tasks/dp_r
  int N; long long K;
  cin >> N >> K;
  vector<vector<long long>> a(N, vector<long long>(N));
  for(int i=0; i<N; i++) for(int j=0; j<N; j++) cin >> a[i][j];

  auto ak = matpow(a, K, 1000000007);
  int ans = 0;
  for(int i=0; i<N; i++) for(int j=0; j<N; j++) ans = (ans + ak[i][j]) % 1000000007;
  cout << ans << endl;

#elif 0 // http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=ITP1_6_D
  int n,m;
  cin >> n >> m;
  vector<vector<long long>> A(n, vector<long long>(m));
  vector<long long> b(m);
  for(int i=0; i<n; i++) for(int j=0; j<m; j++) cin >> A[i][j];
  for(int i=0; i<m; i++) cin >> b[i];
  auto C = matmul(A, b);
  for(int i=0; i<n; i++) printf("%lld\n", C[i]);

#else // http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=ITP1_7_D
  int n, m, l;
  cin >> n >> m >> l;
  vector<vector<long long>> A(n, vector<long long>(m));
  vector<vector<long long>> B(m, vector<long long>(l));

  for(int i=0; i<n; i++) for(int j=0; j<m; j++) cin >> A[i][j];
  for(int i=0; i<m; i++) for(int j=0; j<l; j++) cin >> B[i][j];

  auto C = matmul(A,B);

  for(int i=0; i<n; i++) for(int j=0; j<l; j++) 
      printf("%lld%s", C[i][j], j==l-1 ? "\n" : " ");
#endif
}

Measured memory_bytes: 384
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.io.IOException;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.InputStream;

import java.util.*;

public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        InputReader in = new InputReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);

        int H = in.nextInt();
        int W = in.nextInt();
        char[][] s = new char[H][W];
        int white = 0;
        for (int i=0;i<H;i++) {
            String S = in.next();
            for (int j=0;j<W;j++) {
                s[i][j] = S.charAt(j);
                if (s[i][j]=='.') {
                    white++;
                }
            }
        }

        int ans = 0;
        int[][] flag = new int[H][W];
        ArrayDeque<int[]> queue = new ArrayDeque<int[]>();
        int[] first = {0, 0, 1};
        queue.add(first);
        while (!queue.isEmpty()) {
            int[] rem = queue.poll();
            if (0<=rem[0] && rem[0]<H && 0<=rem[1] && rem[1]<W && flag[rem[0]][rem[1]]==0 && s[rem[0]][rem[1]]!='#') {
                flag[rem[0]][rem[1]]=1;
                int[] add_1 = {rem[0]+1, rem[1], rem[2]+1};
                int[] add_2 = {rem[0]-1, rem[1], rem[2]+1};
                int[] add_3 = {rem[0], rem[1]+1, rem[2]+1};
                int[] add_4 = {rem[0], rem[1]-1, rem[2]+1};
                queue.add(add_1);
                queue.add(add_2);
                queue.add(add_3);
                queue.add(add_4);
                if (rem[0]==H-1 && rem[1]==W-1) {
                    ans = rem[2];
                }
            }
        }

        if (ans==0) {
            out.println(-1);
        } else {
            out.println(white-ans);
        }
        out.close();
    }

    static class InputReader {
        public BufferedReader reader;
        public StringTokenizer tokenizer;

        public InputReader(InputStream stream) {
            reader = new BufferedReader(new InputStreamReader(stream), 32768);
            tokenizer = null;
        }

        public String next() {
            while (tokenizer == null || !tokenizer.hasMoreTokens()) {
                try {
                    tokenizer = new StringTokenizer(reader.readLine());
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }
            return tokenizer.nextToken();
        }

        public int nextInt() {
            return Integer.parseInt(next());
        }

        public long nextLong() {
            return Long.parseLong(next());
        }

    }
}


Measured memory_bytes: 21460
#include <iostream>
#include <vector>
#include <set>
#include <algorithm>
#include <string>
#include <cmath>
#include <iomanip>
#include <map>
#include <set>
using namespace std;
#define loop(i,N) for(ll (i)=0; (i)<(N);++(i))
struct _OMAZINAI_ { _OMAZINAI_() { std::ios::sync_with_stdio(false); std::cin.tie(0); } } __omazinai_instance__;
#define INF ((1LL<<61) + (1<<29))
#define YesNo(x) {std::cout << ((x)?"Yes":"No") << std::endl;}
#define YESNO(x) {std::cout << ((x)?"YES":"NO") << std::endl;}
#define OddEven(x) {std::cout << ((x)%2?"Odd":"Even") << std::endl;}
#define ODDEVEN(x) {std::cout << ((x)%2?"ODD":"EVEN") << std::endl;}
typedef long long int ll;
ll my_gcd(ll a, ll b) { return b ? my_gcd(b, a%b) : a; };
void _INPUT_IMPL_() {};
template <class T, class... Args> void _INPUT_IMPL_(T& dest, Args&... args) { cin >> dest; _INPUT_IMPL_(args...); }
void _OUTPUT_IMPL_() {};
template <class T, class... Args> void _OUTPUT_IMPL_(T dest, Args... args) { cout << dest << (sizeof...(Args) ? " " : ""); _OUTPUT_IMPL_(args...); }
#define in(type, ...) type __VA_ARGS__; _INPUT_IMPL_(__VA_ARGS__)
#define in_v(type, name, cnt) vector<type> name(cnt); loop(i, cnt) cin >> name[i];
#define sort_v(v) std::sort(v.begin(), v.end())
#define unique_v(v) v.erase(std::unique(v.begin(), v.end()), v.end()) //必ずソート後に実行
#define out(...) (_OUTPUT_IMPL_(__VA_ARGS__), std::cout<<std::endl)
#define set_fix(x) ((std::cerr<<std::fixed<<std::setprecision(x)),(std::cout<<std::fixed<<std::setprecision(x)))
//小さい方に寄る
#define space_op(x, y, a, b, c) ([](auto x_, auto y_, auto a_, auto b_, auto c_){if(x_<y_)return a_;if(x_>y_)return c_;return b_;}(x,y,a,b,c))
#define space_out(x, y, a, b, c) out(space_op(x, y, a, b, c))

// ^^^ Template ^^^ //


int main() {
	in(ll, A, B, C, X, Y);
	ll AB = min(A + B, 2 * C);
	A = min(A, 2 * C);
	B = min(B, 2 * C);
	ll m = min(X, Y);
	out(min(X, Y)*AB + (X - m)*A + (Y - m)*B);
	return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
int main()
{
  int W,H,x,y,r;
  scanf("%d %d %d %d %d",&W,&H,&x,&y,&r);
  if((x+r)<=W&&(x-r)>=0&&(y+r)<=H&&(y-r)>=0){
    printf("Yes\n");
  }
  else{
    printf("No\n");
  }
  return 0;
}



Measured memory_bytes: 2148
#include<bits/stdc++.h>
using namespace std;
long long n,d;
int ans=0;
int main()
{
    cin>>n>>d;
    int a,b;
    double c;
    while(n>0)
    {
        cin>>a>>b;
        c=sqrt(pow(a,2)+pow(b,2));
        if(c<=d)
            ans++;
        n--;
    }
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 3644
#include <iostream>
#include <fstream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <numeric>
#include <type_traits>
#include <map>

using namespace std;

vector<long long> t(100001,0);
vector<long long> gx(100001,0);
vector<long long> gy(100001,0);
int n;

int main(int argc, const char * argv[]) {
  int n;
  cin >> n;
  for(int i = 1; i <= n; i++){
    cin>> t[i] >> gx[i] >> gy[i];;
  }
  bool ans = true;
  for(int i = 0; i < n; i++){
    //cout << abs(gx[i+1] - gx[i]) + abs(gy[i+1] - gy[i]) << "," <<t[i+1] - t[i]<<endl;
    //cout << (abs(gx[i+1] - gx[i]) + abs(gy[i+1] - gy[i])) % 2 << "," << abs(t[i+1] - t[i])%2 << endl;
    ans &= abs(gx[i+1] - gx[i]) + abs(gy[i+1] - gy[i]) <= t[i+1] - t[i];
    ans &= (abs(gx[i+1] - gx[i]) + abs(gy[i+1] - gy[i])) % 2 == (t[i+1] - t[i])%2;
  }
  
  cout << (ans ? "Yes" : "No") << endl;
  return 0;
  
}


Measured memory_bytes: 2560
n = int(input())
a = list(map(int, input().split()))

limit = 10**18
total = 1

for i in a:
    if (i == 0):
        total = 0

if (total != 0):
    for i in a:
        total *= i
        if (total > limit):
            total = -1
            break

print(total)

Measured memory_bytes: 21576
#include <bits/stdc++.h>
 
using namespace std;
 
#define ALL(x) x.begin(), x.end()
 
typedef long long int lld;
typedef pair<int, int> pii;
 
int main(){
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
	cout.precision(15);
	cout << fixed;
 
	lld n = 0;
	cin >> n;

	cout << (1 + n) * n / 2 - n << '\n';
 
 
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i,c) for(int i=0;i<c;++i)
int main(){
 int a;
 cin >> a;
 if(a<1200){
     cout << "ABC" << endl;
 }else{
     cout << "ARC" << endl;
 }
 return 0;
}

Measured memory_bytes: 256
N = int(input())
C = input()

a = [0]
b = [0]
for c in C:
    if c == "W":
        a.append(a[-1]+1)
    else:
        a.append(a[-1])
    if c == "R":
        b.append(b[-1]+1)
    else:
        b.append(b[-1])

# print(a, b)

# min_num = 10**18
# for i in range(N+1):
#     print(C[:i], C[i:])
#     print((a[i]-a[0]) - (b[N]-b[i]))
#     if a[i]-a[0] - b[N]-b[i] == 0:
#         min_num = min(a[i]-a[0], min_num)

# print(min_num)

def solve(x):
    r = (b[N]-b[x]) - (a[x]-a[0])
    # print(r)
    return r >= 0

# 右側のRの個数 - 左側のWの個数 >= 0 の最大
ok, ng = 0, N+1
while abs(ok-ng) > 1:
    mid = (ok+ng)//2
    # print(ok, ng, mid)
    if solve(mid):
        ok = mid
    else:
        ng = mid

# print(a, b)
# print(ok)

print(a[ok])



Measured memory_bytes: 19108
n, k= map(int, input().split())
x = [0]*n
for i in range(k):
  z = int(input())
  if z == 1:
    x[int(input())-1] +=1
  else:
    a = list(map(int, input().split()))
    for j in a:
      x[j-1] +=1
print(x.count(0))

Measured memory_bytes: 9116
/**
    @Author:Monk78
    @Topic:K-Stones
**/
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<ll>Vl;
typedef pair<ll,ll>PII;
typedef vector<PII>Vll;
typedef vector<pair<ll,pair<ll,ll> > >Vlll;
typedef priority_queue<ll>PQL;
typedef map<ll,ll>MP;
#define S second;
#define F first;
#define rep(i, begin, end) for (__typeof(end) i = (begin) - ((begin) > (end));i != (end) - ((begin) > (end)); i += 1 - 2 * ((begin) > (end)))
#define mp make_pair
#define ms(x,y) memset(x,y,sizeof(x))
#define pb push_back
#define mod 1000000009
#define MAX 100005
#define f(i,a,b) for(int i=(a);i<(b);i++)
#define rf(i,a,b) for(int i=(a);i>=b;i--)
#define sl(n) scanf("%lld",&n)
#define pl(n) printf("%lld",n)
#define vpshVar() int main()
vpshVar(){
    ll N,K;
    sl(N);sl(K);
    ll arr[N];
    for(ll i=0;i<N;i++){
        sl(arr[i]);
    }
    bool dp[K+1];
    ms(dp,false);
    //K=K-arr[0];
    for(ll i=0;i<=K;i++){
        for(ll j=0;j<N;j++){
            if(i>=arr[j] && !dp[i-arr[j]])dp[i]=true;
        }
    }
    string str=(dp[K])?"First":"Second";
    cout<<str<<endl;
return 0;
}


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

using namespace std;



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

	//x
	string q = '1' + s;
	int f = 0;
	string left = q.substr(1, (s.size() - 1) / 2);
	string right = left;
	reverse(left.begin(), left.end());

	if (left == right)
		++f;
	int k = s.size() - (s.size() + 3) / 2;
	left = q.substr((s.size() + 3) / 2, k + 1);
	right = left;
	reverse(left.begin(), left.end());
	if (left == right)
		++f;
	string b = s;
	reverse(s.begin(), s.end());
	if (b == s) ++f;
	if (f == 3) puts("Yes");
	else puts("No");
	

	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define fi first
#define se second
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
#define srep(i,s,t) for (int i = s; i < t; ++i)
#define rng(a) a.begin(),a.end()
#define sz(x) (int)(x).size()
#define uni(x) x.erase(unique(rng(x)),x.end())
#define show(x) cout<<#x<<" = "<<x<<endl;
#define PQ(T) priority_queue<T,v(T),greater<T> >
#define newline puts("")
#define v(T) vector<T>
#define vv(T) v(v(T))
#define chmin(x,y) x=min(x,y)
#define chmax(x,y) x=max(x,y)
#define EPS (1e-10)
#define equals(a, b) (fabs((a)-(b)) < EPS)
using namespace std;
typedef long long int ll;
typedef pair<int,int> P;
typedef set<int> S;
typedef queue<int> Q;
typedef queue<P> QP;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<P> vp;
const ll LINF = 1001002003004005006ll;
const int INF = 1001001001;
const int MOD = 1000000007;

void printCmd(vi &ans) {
  cout << "Yes" << endl;
  for(int c:ans) {
    string s = "";
    s += c+'A';
    cout << s << endl;
  }
}
  
int main() {
  int N;
  cin >> N;
  vl st(3);
  rep(i,3) {
    cin >> st[i];
  }
  vi cmd(N);
  rep(i,N) {
    string s;
    cin >> s;
    if(s=="AB") {
      cmd[i]=0;
    } else if(s=="BC") {
      cmd[i]=1;
    } else {
      cmd[i]=2;
    }
  }
  vi ans;
  bool ok=true;
  vl now(st);
  auto calc = [&](int x,int y,int i) {
    if(now[x]>st[x]&&st[x]>0) {
      ans.push_back(y);
      now[x]--;
      now[y]++;
    } else if(now[y]>st[y]&&st[y]>0) {
      ans.push_back(x);
      now[y]--;
      now[x]++;
    } else {
      if(i==N-1) {
        if(now[y]>0) {
          ans.push_back(x);
          now[y]--;
          now[x]++;
        } else if(now[x]>0) {
          ans.push_back(y);
          now[x]--;
          now[y]++;
        } else {
          ok=false;
        }
      } else {
        if(now[x]==0) {
          ans.push_back(x);
          now[x]++;
          now[y]--;
          if(now[y]<0) {
            ok=false;
          }
        } else if(now[y]==0) {
          ans.push_back(y);
          now[y]++;
          now[x]--;
          if(now[x]<0) {
            ok=false;
          }
        } else if(cmd[i+1]==y||cmd[i+1]==(y+2)%3) {
          ans.push_back(y);
          now[x]--;
          now[y]++;
          if(now[x]<0) {
            ok=false;
          }
        } else {
          ans.push_back(x);
          now[y]--;
          now[x]++;
          if(now[y]<0) {
            ok=false;
          }
        }
      }
    }
  };
  
  rep(i,N) {
    if(!ok) break;
    switch (cmd[i])
    {
    case 0:
      calc(0,1,i);
      break;
    case 1:
      calc(1,2,i);
      break;
    case 2:
      calc(2,0,i);
      break;
    }
  }
  if(!ok) {
    cout << "No" << endl;
    return 0;
  }
  printCmd(ans);
  return 0;
}

Measured memory_bytes: 4308
#include <iostream>
#include <cstring>
#include <algorithm>
#include <vector>
#include <string>
#include <math.h>
#include <iomanip>
#include <limits>
#include <list>
#include <queue>
#include <tuple>
#include <map>
using namespace std;
#define MOD (long long int)(1e9+7)
#define ll long long int
#define rep(i,n) for(int i=0; i<(int)(n); i++)
#define reps(i,n) for(int i=1; i<=(int)(n); i++)
#define REP(i,n) for(int i=n-1; i>=0; i--)
#define REPS(i,n) for(int i=n; i>0; i--)
#define INF (int)(1123456789)
#define LINF (long long int)(112345678901234567)
#define chmax(a, b) a = (((a)<(b)) ? (b) : (a))
#define chmin(a, b) a = (((a)>(b)) ? (b) : (a))


int main(void){
	bool ok=true;
	vector<int> inp;
	int a;

	rep(i,6){
		cin >> a;
		inp.push_back(a);
	}
	cout<<(inp[4]-inp[0]<=inp[5]?"Yay!":":(")<<endl;
	return 0;
}


Measured memory_bytes: 384
use std::io::prelude::*;

fn input<T>() -> T
where
    T: std::str::FromStr,
{
    let stdin = std::io::stdin();
    let token: String = stdin
        .lock()
        .bytes()
        .map(|c| c.unwrap() as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().unwrap()
}

fn main() {
    let n: usize = input();
    let xy: Vec<(i64, i64)> = (0..n)
        .map(|_| {
            let x = input();
            let y = input();
            (x, y)
        })
        .collect();

    let mut ixy: Vec<(usize, i64, i64)> = xy
        .iter()
        .enumerate()
        .map(|(i, &(x, y))| (i, x, y))
        .collect();
    let mut edge = vec![];

    ixy.sort_by_key(|&(_, x, _)| x);
    for i in 1..n {
        edge.push((ixy[i - 1].0, ixy[i].0, (ixy[i - 1].1 - ixy[i].1).abs()));
    }
    ixy.sort_by_key(|&(_, _, y)| y);
    for i in 1..n {
        edge.push((ixy[i - 1].0, ixy[i].0, (ixy[i - 1].2 - ixy[i].2).abs()));
    }

    edge.sort_by_key(|&(_, _, c)| c);

    let mut ans = 0;
    let mut uf = UnionFind::new(n);
    for (i, j, c) in edge {
        if uf.find(i) == uf.find(j) {
            continue;
        }

        ans += c;
        uf.union(i, j);
    }

    println!("{}", ans);
}

struct UnionFind {
    parent: Vec<usize>,
    size: Vec<usize>,
}

impl UnionFind {
    fn new(n: usize) -> UnionFind {
        let mut p = vec![0; n];
        for i in 0..n {
            p[i] = i;
        }
        UnionFind {
            parent: p,
            size: vec![1; n],
        }
    }

    fn find(&mut self, x: usize) -> usize {
        if self.parent[x] == x {
            x
        } else {
            let p = self.parent[x];
            self.parent[x] = self.find(p);
            self.parent[x]
        }
    }

    fn union(&mut self, x: usize, y: usize) {
        let mut x = self.find(x);
        let mut y = self.find(y);

        if x == y {
            return;
        }

        if self.size[x] < self.size[y] {
            let t = x;
            x = y;
            y = t;
        }

        self.parent[y] = x;
        self.size[x] += self.size[y];
    }
}


Measured memory_bytes: 19488
<?php
list($n,$q)=explode(" ",trim(fgets(STDIN)));
$i=1;
while($i<$n){
  list($a,$b)=explode(" ",trim(fgets(STDIN)));
  $t[$b]=$a;
  ++$i;
}
$ans=array_fill(1,$n,0);
$s=0;
$i=0;
while($i<$q){
  list($p,$x)=explode(" ",trim(fgets(STDIN)));
  if($p==1){
    $s+=$x;
  }else{
    $ans[$p]+=$x;
  }
  ++$i;
}
echo $s." ";
$m[1]=$s;
$i=2;
while($i<=$n){
  $c=0;
  $j=$i;
  while($j>=$i){
    $c+=$ans[$j];
    $j=$t[$j];
  }
  $c+=$m[$j];
  $m[$i]=$c;
  ++$i;
  echo $c." ";
}

Measured memory_bytes: 38772
#include <bits/stdc++.h>
using ll = long long;
using namespace std;
#define rep(i, n) for (int i = 0, i##_len = (int)(n); i < i##_len; i++)
#define reps(i, n) for (int i = 1, i##_len = (int)(n); i <= i##_len; i++)
#define rrep(i, n) for (int i = ((int)(n)-1); i >= 0; i--)
#define rreps(i, n) for (int i = ((int)(n)); i > 0; i--)
#define repi(i, x) \
	for (auto i = (x).begin(), i##_fin = (x).end(); i != i##_fin; i++)
#define all(x) (x).begin(), (x).end()
#define F first
#define S second
#define mp make_pair
#define mt make_tuple
#define pb push_back
#define eb emplace_back
string solve(bool a) { return ((a) ? "Yes" : "No"); }
typedef vector<int> Vi;
typedef vector<Vi> VVi;
typedef pair<int, int> Pi;
typedef vector<Pi> VPi;
typedef vector<long long> V;
typedef vector<V> VV;
typedef pair<long long, long long> P;
typedef vector<P> VP;
template <class T>
inline bool chmax(T& a, T b) {
	if (a < b) {
		a = b;
		return 1;
	}
	return 0;
}
template <class T>
inline bool chmin(T& a, T b) {
	if (a > b) {
		a = b;
		return 1;
	}
	return 0;
}
template <class T, class U>
ostream& operator<<(ostream& os, const pair<T, U>& p) {
	os << "(" << p.first << "," << p.second << ")";
	return os;
}
template <class T>
ostream& operator<<(ostream& os, const vector<T>& v) {
	rep(i, v.size()) {
		if (i) os << " ";
		os << v[i];
	}
	return os;
}
template <class T, class U>
istream& operator>>(istream& is, pair<T, U>& p) {
	is >> p.first >> p.second;
	return is;
}
template <class T>
istream& operator>>(istream& is, vector<T>& v) {
	rep(i, v.size()) { is >> v[i]; }
	return is;
}
const long long INFLL = 1LL << 60;
const int INF         = 1 << 30;
const double PI       = acos(-1);
int main() {
	string s;
	cin >> s;
	VVi path(s.size(), Vi(20));
	rep(j, 20) {
		rep(i, s.size()) {
			if (j == 0) {
				if (s[i] == 'L') {
					path[i][0] = i - 1;
				} else {
					path[i][0] = i + 1;
				}
			}else{
				path[i][j] = path[path[i][j-1]][j-1];
			}
		}
	}
	Vi ans(s.size(), 0);
	rep(i, s.size()) { ans[path[i][19]]++; }
	cout << ans << endl;
}

Measured memory_bytes: 15336
def main():
    n, k = map(int,input().split())
    d = list(input().split())


    ans = n

    Flag = False
    while True:
        for i in range(k):
            if list(str(ans)).count(d[i]) > 0:
                ans+=1
                Flag = True
                break
            if i == k -1:
                print(ans)
                exit()


if __name__ == "__main__":
        main()


Measured memory_bytes: 3064
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashSet;
import java.util.List;
import java.util.Scanner;
import java.util.Set;

//Alien's Counting
public class Main{

	Set<Integer>[] e, rev, in, out;
	int N, M;
	long MOD = 1000000007;
	
	int[] scc;
	boolean[] u;
	List<Integer> list;
	
	long[][] dp;
	
	void dfs(int k){
		u[k] = true;
		for(int v:e[k])if(!u[v])dfs(v);
		list.add(k);
	}
	void rdfs(int k, int id){
		u[k] = true;
		scc[k] = id;
		for(int v:rev[k])if(!u[v])rdfs(v, id);
	}

	long get(int k){
		if(dp[k][0]!=-1)return (dp[k][0]+dp[k][1])%MOD;
		if(out[k].isEmpty()){
			dp[k][0] = dp[k][1] = 1;
			return 2;
		}
		dp[k][0] = dp[k][1] = 1;
		for(int v:out[k]){
			dp[k][1]*=get(v);
			dp[k][1]%=MOD;
			dp[k][0]*=dp[v][0];
			dp[k][0]%=MOD;
		}
//		dp[k][1] = (dp[k][1]+dp[k][0])%MOD;
		return (dp[k][0]+dp[k][1])%MOD;
	}
	
	@SuppressWarnings("unchecked")
	void run(){
		Scanner sc = new Scanner(System.in);
		N = sc.nextInt();
		M = sc.nextInt();
		e = new Set[N];
		rev = new Set[N];
		for(int i=0;i<N;i++){
			e[i] = new HashSet<Integer>();
			rev[i] = new HashSet<Integer>();
		}
		while(M--!=0){
			int s = sc.nextInt()-1, t = sc.nextInt()-1;
			e[s].add(t);
			rev[t].add(s);
		}
		list = new ArrayList<Integer>();
		u = new boolean[N];
		for(int i=0;i<N;i++)if(!u[i])dfs(i);
		Arrays.fill(u, false);
		int ID = 0;
		scc = new int[N];
		for(int i=list.size()-1;i>=0;i--){
			int j = list.get(i);
			if(u[j])continue;
			rdfs(j, ID);
			ID++;
		}
		in = new Set[ID];
		out = new Set[ID];
		for(int i=0;i<ID;i++){
			in[i] = new HashSet<Integer>();
			out[i] = new HashSet<Integer>();
		}
		for(int i=0;i<N;i++){
			for(int v:rev[i]){
				if(scc[i]==scc[v])continue;
				out[scc[i]].add(scc[v]);
				in[scc[v]].add(scc[i]);
			}
		}
//		debug(scc);
//		System.out.println("ID:"+ID);
//		for(int i=0;i<ID;i++){
//			System.out.print("i:"+i+" in:"+in[i].size()+" outs:");
//			for(int o:out[i])System.out.print(" "+o);
//					System.out.println();
//		}
		
		
		dp = new long[ID][2];
		for(long[]d:dp)Arrays.fill(d, -1);
		long res = 1;
		for(int i=0;i<ID;i++)if(in[i].isEmpty()){
			res*=get(i);
			res%=MOD;
		}
//		System.out.println("get(2):"+get(2)+" 0:"+dp[2][0]+" 1:"+dp[2][1]);
//		System.out.println("get(3):"+get(3)+" 0:"+dp[3][0]+" 1:"+dp[3][1]);
		System.out.println(res);
		
//		debug(dp);
	}
	
	void debug(Object...o){
		System.out.println(Arrays.deepToString(o));
	}
	
	public static void main(String[] args) {
		new Main().run();
	}
}

Measured memory_bytes: 13000
#include<stdio.h>
#define N 100
#define INF 1<<21
 
int B[N][N],p[N],H[N],L[N];
 
int min(int d,int r){
  if(d<r) return d;
  else return r;
   
}
 
 
int main(){
   
  int x,i,j,l,a,b,c;
   
  scanf("%d",&x);
   
  for(i=1;i<=x;i++){
    B[i][i]=0;
  }
for(i=1;i<=x;i++){
scanf("%d%d",&H[i],&L[i]);
}
 
p[0]=H[1];
 p[1] = L[1];
 
 for(i=2;i<=x;i++){
   p[i] = L[i];
 }
   
  for(i=2;i<=x;i++){
    for(j = 1;j<=x-i+1;j++){
      a=j+i-1;
      B[j][a] = INF;
      for(l = j;l<=a-1;l++){
    b = B[j][l] + B[l+1][a] + p[j-1]*p[l]*p[a];
    B[j][a] = min(B[j][a],b);
      }
    }
  }
       
  printf("%d\n",B[1][x]);
 
 
return 0;
}

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

using namespace std;

int main()
{
  int N;
  while(cin >> N, N){
    int W, H;
    int field[101][101] = {{0}};
    cin >> W >> H;
    for(int i = 0; i < N; i++){
      int x, y;
      cin >> x >> y;
      x--, y--;
      field[x][y] = 1;
    }
    int S, T;
    cin >> S >> T;
    int ans = 0;
    for(int i = 0; i <= W - S; i++){
      for(int j = 0; j <= H - T; j++){
	int cnt = 0;
	for(int s = 0; s < S; s++){
	  for(int t = 0; t < T; t++){
	    cnt += field[i + s][j + t];
	  }
	}
	ans = max(ans, cnt);
      }
    }
    cout << ans << endl;
  }
  return 0;
}

Measured memory_bytes: 1204
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define pb push_back
#define mp make_pair
#define nt _int128
#define mod 1000000007
ll n ,arr[200005],brr[200005];
ll dp[200005];
void update(ll i,ll val)
{
    while(i<=n)
    {
        dp[i]=max(dp[i],val);
        i+=(i&-i);
    }
}
ll query(ll i)
{
    ll max1=0;
    while(i>0)
    {
        max1=max(max1,dp[i]);
        i=i-(i&-i);
    }
    return max1;
}
ll func(ll i)
{
    ll max1 =0LL;
    for(ll i=1;i<=n;i++)
    {
        ll x=query(arr[i]-1);
        update(arr[i],brr[i]+x);
        max1=max(max1,x+brr[i]);
    }
    return max1;
}
int main()
{
// #ifndef ONLINE_JUDGE
//        freopen("input.txt","r",stdin);
//     freopen("output.txt","w",stdout);
// #endif
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    ll t;
    // cin >> t;
    t  = 1;
    while(t--)
    {
        cin>>n;
        for(ll i=1;i<=n;i++)
            cin>>arr[i];
        for(ll i=1;i<=n;i++)
            cin>>brr[i];
        memset(dp,0,sizeof(dp));
        ll x=func(1);
        cout<<x;
    }
    return 0;
}

Measured memory_bytes: 4992
#include <stdio.h>

typedef struct {
	int key, id;
} data;

void merge_sort(data x[], int n)
{
	static data y[3001] = {};
	if (n == 1) return;
	merge_sort(&(x[0]), n/2);
	merge_sort(&(x[n/2]), (n+1)/2);
	
	int i, p, q;
	for (i = 0, p = 0, q = n/2; i < n; i++) {
		if (p >= n/2) y[i] = x[q++];
		else if (q >= n) y[i] = x[p++];
		else y[i] = (x[p].key < x[q].key)? x[p++]: x[q++];
	}
	for (i = 0; i < n; i++) x[i] = y[i];
}

int main()
{
	int i, N, T, A[3001], B[3001];
	scanf("%d %d", &N, &T);
	for (i = 1; i <= N; i++) scanf("%d %d", &(A[i]), &(B[i]));
	
	data d[3001];
	for (i = 0; i < N; i++) {
		d[i].key = B[i+1];
		d[i].id = i + 1;
	}
	merge_sort(d, N);
	
	int j, dp[3001][3001][2] = {};
	for (i = N - 1; i >= 0; i--) {
		for (j = 0; j < T; j++) dp[i][j][1] = (dp[i+1][j][1] > dp[i+1][j][0] + B[d[i].id])? dp[i+1][j][1]: dp[i+1][j][0] + B[d[i].id];
		for (j = 0; j < T - A[d[i].id]; j++) {
			dp[i][j+A[d[i].id]][0] = dp[i+1][j][0] + B[d[i].id];
			if (dp[i][j+A[d[i].id]][1] < dp[i+1][j][1] + B[d[i].id]) dp[i][j+A[d[i].id]][1] = dp[i+1][j][1] + B[d[i].id];
		}
	}
	
	printf("%d\n", dp[0][T-1][1]);
	fflush(stdout);
	return 0;
}

Measured memory_bytes: 72136
#include <iostream>
#include <iomanip>
#include <string>
#include <cmath>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <list>
#include <stack>
#include <queue>

#define FOR(i, b, e) for(ll i = (ll)(b); i < (ll)(e); ++i)
#define RFOR(i, b, e) for(ll i = (ll)(e-1); i >= (ll)(b); --i)
#define REP(i, n) FOR(i, 0, n)
#define RREP(i, n) RFOR(i, 0, n)
#define REPC(x,c) for(const auto& x:(c))
#define VS vector<string>
#define VL vector<long long>
#define VI vector<int>
#define VVI vector<vector<int>>
#define VVL vector<vector<ll>>
#define ALL(x) (x).begin(),(x).end()
#define SORT(x) sort(ALL(x))
#define RSORT(x) sort((x).rbegin(),(x).rend())
#define PAIR pair<ll,ll>
#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() );

using  ll = long long;
constexpr ll MOD = 1000000007;
using std::cout;
using std::endl;
using std::cin;
using std::string;
using std::vector;
using std::list;
using std::map;
using std::unordered_map;
using std::multimap;
using std::set;
using std::unordered_set;
using std::multiset;

ll gcd(ll a, ll b) { return b ? gcd(b, a%b) : a; }
ll lcm(ll a, ll b) { return a / gcd(a, b) * b; }
ll pow(ll a, ll b) {
	ll ans = 1;
	while (b > 0) {
		if (b % 2 == 1) {
			ans *= a;
			ans %= MOD;
		}
		b /= 2;
		a *= a;
		a %= MOD;
	}
	return ans;
}
ll comb(ll a, ll b) {
	if (a - b < b) { return comb(a, a - b); }
	ll c = 1;
	FOR(i, a - b + 1, a + 1) {
		c *= i;
		c %= MOD;
	}
	ll k = 1;
	FOR(i, 2, b + 1) {
		k *= i;
		k %= MOD;
	}
	c *= pow(k, MOD - 2);
	return c % MOD;
}
multiset<ll> prime_decomposition(ll n) {
	ll i = 2;
	multiset<ll> table{};
	while (i * i <= n) {
		while (n % i == 0) {
			n /= i;
			table.emplace(i);
		}
		++i;
	}
	if (n > 1) {
		table.emplace(n);
		return table;
	}
	return table;
}

int main() {
	int n;
	cin >> n;
	VVL v(2, VL(n));
	REP(i, 2)REP(j, n) { cin >> v[i][j]; }

	VVL dp(2, VL(n));
	dp[0][0] = v[0][0];
	REP(i, 2)REP(j, n) {
		if (i == 0 && j == 0) { continue; }
		if (i > 0 && j > 0) {
			dp[i][j] = std::max(dp[i][j - 1] + v[i][j], dp[i - 1][j] + v[i][j]);
		} else if (i > 0) {
			dp[i][j] = dp[i - 1][j] + v[i][j];
		} else {
			dp[i][j] = dp[i][j - 1] + v[i][j];
		}
	}
	cout << dp[1][n - 1] << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll inf = 1e9;
#define Fast    ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define sz      200005

ll arr[sz];
int brr[sz];


int main(){
    Fast;
    ll n,k,i;

    cin>>n>>k;
    for(i=1; i<=n; i++){
        cin>>arr[i];
    }
    memset(brr,0,sizeof(brr));

    i=1;
    while(k && brr[i]==0){
        k--;
        brr[i]=1;
        i=arr[i];
    }
    if(k==0){
        cout<<i<<endl;
        return 0;
    }

    ll cnt=0;
    memset(brr,0,sizeof(brr));
    while(k && brr[i]==0){
        k--;
        cnt++;
        brr[i]=1;
        i=arr[i];
    }
    if(k==0){
        cout<<i<<endl;
        return 0;
    }
    k=k%cnt;
    memset(brr,0,sizeof(brr));
    while(k && brr[i]==0){
        k--;
        brr[i]=1;
        i=arr[i];
    }
    cout<<i<<endl;

    return 0;
}



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

// #undef DEBUG  // Uncomment this line to forcefully disable debug print.
#if DEBUG
template <typename T>
void debug(T value) {
  std::cerr << value;
}
template <typename T, typename... Ts>
void debug(T value, Ts... args) {
  std::cerr << value << ", ";
  debug(args...);
}
#define dbg(...)                              \
  do {                                        \
    cerr << #__VA_ARGS__ << ": ";             \
    debug(__VA_ARGS__);                       \
    cerr << " (L" << __LINE__ << ")" << endl; \
  } while (0)
#else
#define dbg(...)
#endif

void read_from_cin() {}
template <typename T, typename... Ts>
void read_from_cin(T& value, Ts&... args) {
  std::cin >> value;
  read_from_cin(args...);
}
#define in(type, ...) \
  type __VA_ARGS__;   \
  read_from_cin(__VA_ARGS__);

template <typename T>
void write_to_cout(const T& value) {
  std::cout << value << std::endl;
}
template <typename T, typename... Ts>
void write_to_cout(const T& value, const Ts&... args) {
  std::cout << value << ' ';
  write_to_cout(args...);
}
#define out(...) write_to_cout(__VA_ARGS__);

#define all(x) (x).begin(), (x).end()
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)

using ll = long long;

using namespace std;

bool acgt(char c) { return string("ACGT").find(c) != string::npos; }

int main() {
  in(string, s);
  int ans = 0;
  rep(i, s.size()) for (int j = i; j < s.size(); ++j) {
    bool ok = true;
    for (int k = i; k <= j; ++k)
      if (!acgt(s[k])) ok = false;
    if (ok) ans = max(ans, j - i + 1);
  }
  out(ans);
}


Measured memory_bytes: 3628
import sys
input = sys.stdin.readline

def main():
    K,S = [int(x) for x in input().split()]

    count = 0

    for x in range(K+1):
        for y in range(K+1):
            z = S - (x + y)
            if z >= 0 and z <= K:
                count += 1

    print(count)

if __name__ == '__main__':
    main()

Measured memory_bytes: 3060