akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <cmath>
#include <vector>
#include <queue>
#include <utility>

using namespace std;
typedef long long ll;
const int LEN = 100000;

struct fastio{
  int it,len;
  char s[LEN + 5];
  fastio(){
    it = len = 0;
  }
  char get(){
    if(it < len) return s[it++];
    it = 0, len = fread(s,1,LEN,stdin);
    return len ? s[it++] : EOF;
  }
  bool notend(){
    char c;
    for(c = get();c == ' ' || c == '\n';c = get());
    if(it) it--;
    return c != EOF;
  }
  void put(char c){
    if(it == LEN) fwrite(s,1,LEN,stdout), it = 0;
    s[it++] = c;
  }
  void flush(){
    fwrite(s,1,it,stdout);
  }
}buff,bufo;
inline int getint(){
  char c; int res = 0, sig = 1;
  for(c = buff.get();c < '0' || c > '9';c = buff.get()) if(c == '-') sig = -1;
  for(;c >= '0' && c <= '9';c = buff.get()) res = res * 10 + (c - '0');
  return sig * res;
}
inline ll getll(){
  char c; ll res = 0, sig = 1;
  for(c = buff.get();c < '0' || c > '9';c = buff.get()) if(c == '-') sig = -1;
  for(;c >= '0' && c <= '9';c = buff.get()) res = res * 10 + (c - '0');
  return sig * res;
}
inline void putint(int x,char suf){
  if(!x) bufo.put('0');
  else{
    if(x < 0) bufo.put('-'), x = -x;
    int k = 0; char s[15];
    while(x){
      s[++k] = x % 10 + '0';
      x /= 10;
    }
    for(;k;k--) bufo.put(s[k]);
  }
  bufo.put(suf);
}
inline void putll(ll x,char suf){
  if(!x) bufo.put('0');
  else{
    if(x < 0) bufo.put('-'), x = -x;
    int k = 0; char s[25];
    while(x){
      s[++k] = x % 10 + '0';
      x /= 10;
    }
    for(;k;k--) bufo.put(s[k]);
  }
  bufo.put(suf);
}
inline char get_char(){
  char c;
  for(c = buff.get();c == ' ' || c == '\n';c = buff.get());
  return c;
}
#define maxn 100005
int n,a[maxn];
ll sum[maxn],m;
bool check(ll x){
  ll cnt = 0;
  for(int i = 1;i <= n;i++){
    cnt += a + n - lower_bound(a + 1,a + n + 1,x - a[i]) + 1;
  }
  return cnt >= m;
}
int main(){
  n = getint(), m = getll();
  for(int i = 1;i <= n;i++) a[i] = getint();
  sort(a + 1,a + n + 1);
  for(int i = 1;i <= n;i++) sum[i] = a[i] + sum[i - 1];
  ll lb = 1, rb = (ll)1e10;
  while(lb < rb){
    ll mid = (lb + rb + 1) >> 1ll;
    if(check(mid)) lb = mid;
    else rb = mid - 1;
  }
  ll ans = 0;
  for(int i = 1;i <= n;i++){
    int pos = upper_bound(a + 1,a + n + 1,lb - a[i]) - a;
    ans += sum[n] - sum[pos - 1];
    ans += (ll)a[i] * (n - pos + 1);
    m -= n - pos + 1;
  }
  ans += (ll)m * lb;
  putll(ans,'\n');
  bufo.flush();
  return 0;
}

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

int main(){
  int a, b;
  cin >> a >> b;

  if (a <= b){
    cout << a << endl;
  }
  else
  {
    cout << a - 1 << endl;
  }
  
}

Measured memory_bytes: 3580
#include <bits/stdc++.h>
#define ll long long
using namespace std;
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; }
const ll INF=(ll)1e9;
const ll MOD=(ll)1e9+7;
vector<int> dx={1,0,-1,0},dy={0,1,0,-1};

int main(){
  ll N,M;
  cin>>N>>M;
  vector<vector<ll>> v(N+1);
  vector<set<ll>> s(N+1);
  for(ll i=0;i<M;i++){
    ll a,b;
    cin>>a>>b;
    v[a].push_back(b);
    v[b].push_back(a);
    s[a].insert(b);
    s[b].insert(a);
  }
  for(ll i=0;i<v[1].size();i++){
    if(s[v[1][i]].count(N)){
      cout<<"POSSIBLE"<<endl;
      return 0;
    }
  }
  cout<<"IMPOSSIBLE"<<endl;
}


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

int main(){
    int n,d,x;
    cin>>n>>d>>x;

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

    // vector<vector<int>> eat(n,vector(d));
    int eat=0;

    for(int i=0; i<n; i++){
        for(int j=0; j<d; j++){
            if(a[i]*j+1>d){
                break;
            }
            eat++;
        }
    }

    cout<<x+eat<<endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <cmath>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <string>

using namespace std;
using ll = long long int;
using vec = vector<int>;

#define rep(n) for(int i = 0; i < (n); ++i)
#define Sort(a)    sort(a.begin(), a.end())
#define gSort(a)   sort(a.begin(), a.end(), greater<int>())
const int INF = 2147483647;
const ll  MOD = 1000000007;

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

    int ans = 0;
    while(x >= 500) {
        ans += 1000;
        x -= 500;
    }

    while(x >= 5) {
        ans += 5;
        x -= 5;
    }

    cout << ans;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <stdlib.h>
#include <cstdint>
using namespace std;

int gets(int n) {
	int ret = 0;
	while(n != 0) {
		ret += n % 10;
		n /= 10;
	}
	return ret;
}

int main()
{
	int n;
	int ans = 0;

	cin >> n;

	int s = gets(n);

	if( (n % s) == 0 ) {
		cout << "Yes" << endl;
	}
	else {
		cout << "No" << endl;
	}

	return 0;
}


Measured memory_bytes: 256
def prime_or_not(x):
    
    if x == 2:
        return True
        
    if x < 2 or x % 2 == 0:
        return False

    i = 3
    while i <= pow(x, 0.5):
        if x % i == 0:
            return False
        i = i + 2

    return True

n = int(input())

result = 0
for i in range(n):
    x = int(input())
    
    if prime_or_not(x):
        result += 1
        
print(result)


Measured memory_bytes: 5672
local h, w = io.read("*n", "*n", "*l")
local str = ""
local t = {}
for i = 1, h do
  str = io.read()
  for j = 1, w do
    t[(i - 1) * w + j] = string.sub(str, j, j) == "#" and true or false
  end
end
local s = h * w
local allok = true
for i = 1, s do
  if(t[i]) then
    local isok = false
    if(w < i) then
      if(t[i - w]) then isok = true end
    end
    if(i <= s - w) then
      if(t[i + w]) then isok = true end
    end
    if(i % w ~= 0) then
      if(t[i + 1]) then isok = true end
    end
    if(i % w ~= 1) then
      if(t[i - 1]) then isok = true end
    end
    if(not isok) then allok = false break end
  end
end
print(allok and "Yes" or "No")


Measured memory_bytes: 256
#include <iostream>
#include <cmath>
struct bunk{
	int B;
	int T;
	int R;
	double data;
};

int main()
{
	int N;
	int Y;
	int ddata;
	bunk d;
	bunk dlast={-1,-1,-1,-1.0};
	std::cin>>N;
	while(N){
		std::cin>>Y;
		for(int i=0;i<N;i++){
			std::cin>>d.B>>d.R>>d.T;
			switch(d.T){
			case 1:
				d.data=1.0+(double)Y*(double)d.R/100.0;
				break;
			case 2:
				d.data=std::pow(1.0+(double)d.R/100.0,(double)Y);
				break;
			}
			if(d.data>dlast.data){
				dlast.data=d.data;
				dlast.B=d.B;
			}
		}
		std::cout<<dlast.B<<std::endl;
		dlast.data=-1;
		std::cin>>N;
	}
}

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

using namespace std;
typedef long long ll;
typedef long double ld;
ll gcd(ll a, ll b) { return b == 0 ? a : gcd(b, a % b); }
ll lcm(ll a, ll b) { return a * (b / gcd(a, b)); }

const int q = 1e9+9;
int a[1007],b[1007];

int main()
{
    int a=0,b=0,c=0;
    string s;
    cin>>s;
    for(int i=0;i<s.length();i++){
        if( !a && s[i]=='a' ) a=1;
        if( !b && s[i]=='b' ) b=1;
        if( !c && s[i]=='c' ) c=1;
    }
    if( a && b && c) cout<<"Yes"<<endl;
    else cout<<"No"<<endl;

    return 0;
}
// gotcha;


Measured memory_bytes: 256
#include<bits/stdc++.h>
#include<string>
#define FIO ios_base::sync_with_stdio(false), cin.tie(NULL), cout.tie(NULL)
#define ll long long
#define mod (ll)(1e9+7)
#define nax (ll)(1e5)
#define INFL LLONG_MAX
#define NINFL LLONG_MIN
#define INF INT_MAX
#define disp(a,n,arr) for(int i=a;i<(ll)n;i++) cout << arr[i] << " "; cout << "\n";
#define check cout << "Working\n";
#define pi pair<int,int>
#define pl pair<ll,ll>
#define vi vector<int>
#define vl vector<ll>
#define vpl vector<pl>
#define vpi vector<pi>
#define vb vector<bool>
#define pb push_back
#define mp make_pair
#define fi first
#define se second
using namespace std;


int main() {

#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif
	FIO;

	// Write your code here


	int t = 1;
	// cin >> t;
	while (t--) {
		ll n;
		cin >> n;
		ll x = n;
		map<ll, ll> mpp;
		for (ll i = 2; i * i <= n ; i++) {
			if (x % i == 0) {
				ll cnt = 0;
				while (x % i == 0) {
					x /= i;
					cnt++;
				}
				mpp[i] = cnt;
			}
			if (x == 1) break;
		}

		if (x > 1) mpp[x] = 1;
		ll cnt = 0;
		for (auto it : mpp) {
			x =  it.fi;
			ll lim = it.se;
			for (ll i = 0; i < lim; i++) {
				//cout << n << " " << x << "\n";
				if (n % x == 0) {
					cnt++;
					n /= x;
				}
				x *= it.fi;
			}
		}
		cout << cnt << "\n";
	}


	return 0;
}

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

int main()
{
    int n;
    cin>>n;
    int arr[n];
    for(int i=0; i<n; i++)
        cin>>arr[i];
    bool res = true;
    for(int i=n-2; i>=0; i--)
    {
        if(arr[i+1] < arr[i])
        {
            if(arr[i+1]+1 == arr[i])
                arr[i]--;
            else
            {
                res = false;
                break;
            }
        }
    }
    if(res)
        cout<<"Yes\n";
    else
        cout<<"No\n";
}


Measured memory_bytes: 640
#include<bits/stdc++.h>
using namespace std;
#define M 1000000007
int n,m,q,a[200001],s[1001],t,i,h[200001],nn,b[200001],c[200001],bb,cc,flg[2000001],j;
int main(void)
{
	scanf("%d %d %d",&n,&m,&q);
	for(i=0;i<m;i++) scanf("%d",&a[i]);
	for(i=0;i<q;i++) scanf("%d",&s[i]);
	for(i=0;i<n;i++) b[i]=i-1,c[i]=i+1;
	b[0]=n-1; c[n-1]=0;
	for(i=0;i<m;i++) h[i]=a[i]%2;
	for(i=0;i<n;i++) flg[i]=1;
	for(i=0;i<m;i++) a[i]=a[i]%(n-i);
	j=0; nn=n; bb=b[0]; cc=c[0];
	for(i=0;i<=a[j];i++){
		if(a[j]!=0){
			if(i==0) i=1;
			if(h[j]==0){
				bb=b[cc];
				cc=c[cc];
				//printf("bb%d cc%d ",bb,cc);
			}
			else {
				cc=c[bb];
				bb=b[bb];
				//printf("bb%d cc%d ",bb,cc);
			}
		}
		if(i==a[j]){
			//printf("%d\n",c[bb]);
			flg[c[bb]]=0;
			b[cc]=bb;
			c[bb]=cc;
			cc=c[cc];
			//printf("bb%d cc%d\n",bb,cc); 
			j++;
			i=-1;
		}
		if(j==m) break;
	}
	//for(i=0;i<nn;i++) printf("%d %d %d\n",i,b[i],c[i]);
	for(i=0;i<q;i++) printf("%d\n",flg[s[i]]);
	return 0;
}


Measured memory_bytes: 7044
#include<iostream>
#include<complex>
#include<cmath>
#include<algorithm>
#define REP(i,s,n) for(int i=s;i<n;i++)
#define rep(i,n) REP(i,0,n)
#define EPS 1e-10
#define PI 3.141592653589793238
// sqrtは重い
using namespace std;
typedef pair<double,double> P;

void display(complex<double> a,complex<double> b){
 cout << "(" << a.real() <<"," << a.imag() <<")"<< " " <<"("<< b.real() <<"," <<b.imag() << ")" << endl;
}

int main(){
  int n,ans;
  double xin,yin,X;
  complex<double> m;
  while(cin >> n && n){
    ans = 1;
    complex<double> point[n];
    for(int i=0;i<n;i++){
      cin >> xin >> yin;
      point[i] = complex<double>(xin,yin);
    }
    for(int i=0;i<n;i++){
      for(int j=0;j<n;j++){
	if(i == j)continue;
	complex<double> Rr = point[i]-point[j];
	if(abs(Rr) <= 2+EPS){

	  complex<double> UKPC,U,P1,P2;
	  UKPC = (point[i]+point[j])*0.5;
       
	  double T = sqrt(1-norm(point[i]-point[j])*0.25);

	  UKPC = (point[i]+point[j])*0.5;
	               /* unit vector(単位べく利ゅ)             *//* T倍に拡大 ９０度回転 */ 
  	  P1 = UKPC + (point[i]-point[j])/abs(point[i]-point[j])*polar(T,PI/2.0);
	  P2 = UKPC + (point[i]-point[j])/abs(point[i]-point[j])*polar(T,-PI/2.0);
	  //cout << "P1 = " << P1 << ", P2 = " << P2 << endl;
	  int cnt=0;
	  complex<double> CalcP;
	  double Calc;
	  for(int k=0;k<n;k++){
	    Calc = abs(P1-point[k]);
	    if(Calc < 1.0+EPS){
	      cnt++;
	    }
	  }	

	  ans = max(ans,cnt);
	  cnt = 0;
	  for(int k=0;k<n;k++){
	    Calc = abs(P2-point[k]);
	    if(fabs(Calc) < 1.0+EPS){
	      cnt++;
	    }
	  }	
  
	  ans = max(ans,cnt);
	  

	}

      }
    }

    cout << ans << endl;

  }
  return 0;
}

Measured memory_bytes: 988
#include <bits/stdc++.h>
using namespace std;
int main(void){
    int N,m=0,x=1;
    cin>>N;
    int a[N];
    for(int i=0;i<N;i++){
        cin>>a[i];
    }
    for(int i=0;i<N;i++){
        if(x==a[i]){
            x++;
            m++;
        }
    }
    if(m==0){
        cout<<-1<<endl;
    }
    else{
        cout<<N-m<<endl;
    }
}

Measured memory_bytes: 1024
#include <iostream>
#include <iomanip>
#include <vector>
#include <string>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <stack>
#include <queue>
#include <list>
#include <forward_list>
#include <algorithm>
#include <numeric>
#include <utility>
#define _USE_MATH_DEFINES
#include <cmath>

using namespace std;

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

  int a, b, h, m;
  cin >> a >> b >> h >> m;

  double a1 = m * M_PI / 30.0;
  double x1, y1;
  x1 = sin(a1) * b;
  y1 = +cos(a1) * b;

  double a2 = (30.0 * h + 0.5 * m) * M_PI / 180.0;
  double x2, y2;
  x2 = sin(a2) * a;
  y2 = cos(a2) * a;

  x1 -= x2;
  y1 -= y2;
  cout << fixed << setprecision(10) << sqrt(x1 * x1 + y1 * y1) << endl;
}

Measured memory_bytes: 4140
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define chmin(x, y) x = min(x, y)
#define chmax(x, y) x = max(x, y)
#define MOD (int) (1e9+7)
#define INF (int) 2e9
#define LLINF (ll) 2e18

int table[10][10];

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

    int ans = 0;
    int keta10 = 1;
    for (int i = 1; i <= n; i++) {
        if(i==10){
            keta10 = 10;
        }else if(i==100){
            keta10 = 100;
        }else if(i==1000){
            keta10 = 1000;
        }else if(i==10000){
            keta10 = 10000;
        }else if(i==100000){
            keta10 = 100000;
        }
        
        int shimo = i%10;
        int kami = i/keta10;

        int tmp = table[shimo][kami];
        if(shimo==kami){
            ans += tmp*2+1;
        }else{
            ans += tmp*2;
        }

        table[kami][shimo]++;
    }
    

    cout << ans << endl;
    // printf("%d\n", N);
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
using ll = long long;
int main(){
    int n,sum;
    cin >>n;
    vector<int> d(n);
    rep(i,n) cin>>d[i];
    rep(i,n){
        rep(j,n){
            if (i!=j) sum +=d[i]*d[j];
        }
    }
    cout << sum/2 <<endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <list>
#include <random>
#include <iomanip>
#include <map>

using namespace std;

typedef long long ll;

int main() {
    int N;
    ll H, W, a, b;
    vector<ll> A, B;
    cin >> N >> H >> W;
    for (int i = 0; i < N; i++) {
        cin >> a >> b;
        A.push_back(a);
        B.push_back(b);
    }
    
    int ans = 0;
    for (int i = 0; i < N; i++) {
        if (A.at(i) >= H && B.at(i) >= W) ans++;
    }
    
    cout << ans << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <cmath>
#include <iomanip>
#include <algorithm>
#include <queue>
using namespace std;
#define rep(i,n) for(int i=0; i<(n); i++)

int main() {
    int n,m,c,pt,ans=0;
    cin>>n>>m>>c;
    vector<int>b(m);
    vector<vector<int>>a(n,vector<int>(m));
    rep(j,m)cin>>b[j];
    rep(i,n)rep(j,m)cin>>a[i][j];
	rep(i,n){
		pt=c;
		rep(j,m)pt+=b[j]*a[i][j];
		if(pt>0)ans++;
	}
	cout<<ans;
	return 0;
}


Measured memory_bytes: 3640
#include<iostream>
#include<string>
#include<vector>
#include<stack>
#include<queue>
#include<map>
#include<algorithm>
#include<numeric>

#define reps(i, j, k) for (int i = (j); i < (k); i++)
#define rep(i, j) reps(i, 0, j)
#define fs first
#define sc second
#define pub push_back
#define puf push_front
#define pob pop_back
#define pof pop_front

using namespace std;

using ll = long long;
using pii = pair<int, int>;
using vi = vector<int>;

const int mod = 1e9 + 7;
const long double pi = 3.141592653589793238462643383279502884197;
const long double eps = 1e-7;

int N;
int d[100];
int num = 0;

int main() {
	cin >> N;
	rep(i, N) {
		cin >> d[i];

		bool check = true;
		rep(j, i) {
			if (d[i] == d[j]) {
				check = false;
				break;
			}
		}

		if (check) num++;
	}

	cout << num << endl;
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main(void){
    int n;
    long long a,b=0,c=0,d=0,e=0;
    cin>>n;
    for(int i=0;i<n;i++){
        cin>>a;
        b+=a;
        c+=a;
        if(i%2==0){
            if(b>=0){
                d+=b+1;
                b=-1;
            }
            if(c<=0){
                e+=-c+1;
                c=1;
            }
        }else{
            if(b<=0){
                d+=-b+1;
                b=1;
            }
            if(c>=0){
                e+=c+1;
                c=-1;
            }
        }
    }
    cout<<min(d,e)<<endl;
}


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

typedef long long LL;

const int OO = 1e9;
const int MOD = 1e9 + 7;

bool bad[10];

bool is_good(int n) {
	while (n > 0) {
		if (bad[n % 10])
			return false;
		n /= 10;
	}
	return true;
}

void solve() {
	int n, k;
	scanf("%d%d", &n, &k);
	for (int i = 0; i < k; ++i) {
		int d;
		scanf("%d", &d);
		bad[d] = true;
	}

	while (!is_good(n))
		++n;

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

int32_t main() {
// #ifndef ONLINE_JUDGE
// 	freopen("input.txt", "r", stdin);

// 	clock_t begin = clock();
// #endif

	solve();

// #ifndef ONLINE_JUDGE
// 	clock_t end = clock();
// 	printf("ELAPSED TIME: %f\n", (double) (end - begin) / CLOCKS_PER_SEC);
// #endif

	return 0;
}


Measured memory_bytes: 256
import sys
h,w=map(int,input().split())
a=[]
for i in range(h):
  a.append(input())
for i in range(h):
  for j in range(w):
    if a[i][j]=='#':
      flag=1
      if i>0 and a[i-1][j]=='#':
        flag=0
      if j>0 and a[i][j-1]=='#':
        flag=0
      if i<h-1 and a[i+1][j]=='#':
        flag=0
      if j<w-1 and a[i][j+1]=='#':
        flag=0
      if flag==1:
        print('No')
        sys.exit()
print('Yes')

Measured memory_bytes: 66208
namespace ABC141.A
{
    using System;
    using static System.Console;

    public class Program
    {
        public static void Main(string[] args)
        {
            WriteLine(Solve(ReadLine()));
        }

        public static string Solve(string weather)
        {
            switch (weather)
            {
                case "Sunny": return "Cloudy";
                case "Cloudy": return "Rainy";
                case "Rainy": return "Sunny";
                default:
                    throw new ArgumentException($"{nameof(weather)} must be a weather");
            }
        }
    }
}


Measured memory_bytes: 11092
#include <iostream>
#include <cmath>
#include <algorithm>
#include <bitset>
#include <iomanip>
#include <cstdio>
#include <new>
#include <vector>
#include <cstdlib>
#include <string>
#include <set>
#include <tuple>
#include<map>

using namespace std;
int main() {
	char c;
	cin >> c;

	bool ans = false;

	switch (c) {
	case 'a':
		ans = true;
		break;
	case 'i':
		ans = true;
		break;
	case'u':
		ans = true;
		break;
	case'e':
		ans = true;
		break;
	case'o':
		ans = true;
		break;
	}
	
	if (ans) {
		cout << "vowel" << endl;
	}else{
		cout << "consonant" << endl;
	}

}

Measured memory_bytes: 3596
def delta(a, b):                                 
    return abs(a - b)                            
                                                 
n, *hs = [int(x) for x in open(0).read().split()]
l = len(hs)                                      
delta = lambda a, b: abs(hs[a] - hs[b])          
dp = [0, delta(1, 0)]                            
for i in range(2, l):                            
    dp.append(min(                               
        dp[i - 1] + delta(i, i - 1),             
        dp[i - 2] + delta(i, i - 2)))            
print(dp[-1])                                    

Measured memory_bytes: 13876
#define _USE_MATH_DEFINES
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#include <ctype.h>
#include <limits.h>
#define EPS 1e-10
#define sq(n) ((n)*(n))
#define rep(i,n) for(i=0;i<n;i++)
#define rev(i,n) for(i=n-1;i>=0;i--)
#define sort(a,n) qsort(a,n,sizeof(TYPE),cmp)
#define sort_r(a,n) qsort(a,n,sizeof(TYPE),cmp_r);
#define chsort(s,n) qsort(s,n,sizeof(char),cmp)
#define chsort_r(s,n) qsort(s,n,sizeof(char),char_cmp_r);
#define TYPE int
#define MEMSET(a) memset(a,0,sizeof(a))
long long mod=(long long)1e09+7;
int inf=1<<29;
long long llinf=1ll<<60;

int in(void){
    int i;scanf("%d",&i);
    return i;
}
long long llin(void){
    long long i;scanf("%lld",&i);
    return i;
}
double din(void){
    double i;scanf("%lf",&i);
    return i;
}
void chin(char s[]){
    scanf("%s",s);
}
void print(int a){
    printf("%d\n",a);
}
void llprint(long long a){
    printf("%lld\n",a);
}
void dprint(double a){
    printf("%.10f\n",a);
}
void print2(int a,int b){
    printf("%d %d\n",a,b);
}
long long max(long long a,long long b){
    return a>b?a:b;
}
long long min(long long a,long long b){
    return a<b?a:b;
}
int cmp(const void *a,const void *b){
    return *(TYPE *)a-*(TYPE *)b;
}
int cmp_r(const void *a,const void *b){
    return *(TYPE *)b-*(TYPE *)a;
}
int char_cmp(const void *a,const void *b){
    return strcmp((char *)a,(char *)b);
}
int char_cmp_r(const void *a,const void *b){
    return strcmp((char *)b,(char *)a);
}
void swap(int *a,int *b){
    int t=*a;
    *a=*b;
    *b=t;
}
long long gcd(long long x,long long y){
    return x%y?gcd(y,x%y):y;
}
long long lcm(long long x,long long y){
    return x/gcd(x,y)*y;
}

// write codes below this
// when you use 'sort',
// make sure TYPE macro is correct
int i;
char s[10001];
int solve(void){
    int j,k=0,tmp[10000],ret=0;
    if(s[i+1]!='['){
        while(s[++i]!=']')
            ret=ret*10+s[i]-'0';
        return (ret+1)/2;
    }
    while(s[++i]!=']')
        tmp[k++]=solve();
    sort(tmp,k);
    rep(j,(k+1)/2)ret+=tmp[j];
    return ret;
}

int main(void){
    int n=in(),j;
    while(n--){
        chin(s);
        i=0;
        print(solve());
    }
    return 0;
}


Measured memory_bytes: 1980
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> lpair;
const ll MOD = 1e9 + 7;
const ll INF = 1e18;
#define REP(i,m,n) for(int i=(int)(m) ; i < (int) (n) ; ++i )
#define rep(i,n) REP(i,0,n)
#define rREP(i,m,n) for(ll i = (m); i >= (n); i--)
#define print(x) cout << (x) << endl;
#define printa(x,n) for(ll i = 0; i < n; i++){ cout << (x[i]) << " ";} cout<<endl;
int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    int n,k;
    cin >> n >> k;

    if (k%2==0)
    {
      ll tmpnk = n/k;
      ll ans1 = tmpnk * tmpnk * tmpnk;
      ll tmpnk2 = n/(k/2) - tmpnk;
      ll ans2 = tmpnk2 * tmpnk2 * tmpnk2;

      cout << ans1 + ans2 << endl;
    }
    else
    {
      ll tmpnk = n/k;
      cout << tmpnk * tmpnk * tmpnk << endl;
    }
    
}


Measured memory_bytes: 256
#include <stdio.h>
#include <vector>
using namespace std;

struct Params{
    int t;
    int x;
    int y;
};

int main()
{
    int n, t, x, y;
    bool isOK = true;
    scanf("%d", &n);

    vector<Params> v;
    v.push_back({0, 0, 0});
    for(int i = 1; i <= n; i++)
    {
        scanf("%d %d %d", &t, &x, &y);
        v.push_back({t, x, y});

        if(isOK){
            int dt = v[i].t - v[i-1].t;
            int dx = v[i].x - v[i-1].x;
            int dy = v[i].y - v[i-1].y;

            if(dx + dy > dt) isOK = false;
            else if((dt - dx - dy) % 2 != 0) isOK = false;
            else isOK = true;
        }
    }
    printf("%s", isOK ? "Yes" : "No");
    return 0;
}

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

int main() {
  int N, H;
  cin >> N >> H;
  vector<int> A(N), B(N);
  for (int i = 0; i < N; i++) cin >> A.at(i) >> B.at(i);
  int mx = *max_element(A.begin(), A.end());
  sort(B.rbegin(), B.rend());
  int cnt = 0;
  for (int i = 0; i < N; i++) {
    if (B.at(i) > mx) H -= B.at(i), cnt++;
    if (H <= 0) return cout << cnt << "\n", 0;
  }
  cout << cnt + (H + mx - 1) / mx << "\n";
}

Measured memory_bytes: 1024
N, M, K = map(int, input().split())

A = list(map(int, input().split()))
B = list(map(int, input().split()))

cuma = [0]

for a in A:
  cuma.append(cuma[-1]+a)

cumb = [0]
for b in B:
  cumb.append(cumb[-1]+b)

ans = 0
from bisect import bisect
for i, ca in enumerate(cuma):
  if ca > K: break
  t = K - ca
  j = bisect(cumb, t)
  ans = max(ans, i+j-1)

print(ans)

Measured memory_bytes: 132908
import sys
import math
from collections import defaultdict

sys.setrecursionlimit(10**7)
def input():
    return sys.stdin.readline()[:-1]

mod = 10**9 + 7

def I(): return int(input())
def LI(): return list(map(int, input().split()))
def LIR(row,col):
    if row <= 0:
        return [[] for _ in range(col)]
    elif col == 1:
        return [I() for _ in range(row)]
    else:
        read_all = [LI() for _ in range(row)]
        return map(list, zip(*read_all))

#################

# 互いに素なa,bについて、a*x+b*y=1の一つの解[x,y]を出力
def extgcd(a,b):
    r = [1,0,a]
    w = [0,1,b]
    while w[2] != 1:
        q = r[2]//w[2]
        r2 = w
        w2 = [r[0]-q*w[0],r[1]-q*w[1],r[2]-q*w[2]]
        r = r2
        w = w2
    return [w[0],w[1]]

# aの逆元(mod M)を求める（aとMは互いに素）
def mod_inv(a,M=mod):
    x = extgcd(a,M)[0]
    return (M+x%M)%M

def nCk2(n,k):
    x = [0]*(k+1)
    x[0] = 1
    for i in range(1,k+1):
        x[i] = x[i-1]*(n-k+i)*mod_inv(i) % mod
    return x[-1]

n,a,b = LI()

ans = pow(2,n,mod)-1
ans -= nCk2(n,a)
ans %= mod
ans -= nCk2(n,b)
ans %= mod

print(ans)

Measured memory_bytes: 80592
data = [[[0 for r in range(10)] for f in range(3)] for b in range(4)]
n = int(input())
for _ in range(n):
    (b,f,r,v) = [int(i) for i in input().split()]
    data[b - 1][f - 1][r - 1] += v

for b in range(4):
    for f in range(3):
        for r in range(10):
            print('',data[b][f][r], end='')
        print()
    if b < 3:
        print('#' * 20)

Measured memory_bytes: 7800
#include <stdio.h>
 
int main(void){
  int n,m,l=0;
  int i,sum=0;
  int c=0;
  scanf("%d",&n);
  scanf("%d",&m);
  int a[1000];
  for(i=0;i<n;i++){
    scanf("%d",&a[i]);
    sum+=a[i];
  }
  for(i=0;i<n;i++){
    l=a[i]*(4*m);
    if(l>=sum){
      c++;
    }
  }
  if(c>=m)
    puts("Yes");
  else
    puts("No");
  return 0;
}

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

typedef long long ll;
const ll mod = (ll)1e9 + 7;
const int N = (int)2e6 + 50;

int n;
ll dp[N][4];
ll add[N];
ll cumu = 0;

int main() {
    cin >> n;
    if(n == 1) return cout << 1 << endl, 0;
    dp[1][1] = 1;
    dp[1][2] = 1;
    ll res = 0;
    for(int i = 2; i <= n; i++) {
        cumu += add[i]; cumu %= mod;
        res += ((n - 1) * dp[i-1][2] % mod * (n - 1)) % mod;
        res %= mod;
        add[i + 1] += dp[i-1][2]; add[i + 1] %= mod;

        add[i + n] -= dp[i-1][2]; add[i + n] %= mod;

        dp[i][1] = (dp[i-1][1] + cumu) % mod;
        dp[i][2] = dp[i-1][1];
    }
    for(int i = n + 1; i <= 2 * n; i++) {
        cumu += add[i]; cumu %= mod;
        res += cumu;
        res %= mod;
    }
    res += dp[n][1] + dp[n][2] * (n - 1);
    res = (res % mod + mod) % mod;
    cout << res << endl;

}

Measured memory_bytes: 47360
#include<iostream>
using namespace std;
int main()
{
    // 整数の入力
    int N;
    cin >> N;
    
  	if(N%2==0){
      cout << 1.0/2.0;
    }else{
      cout << ((N/2)+1) / static_cast<double>(N);
    }
    
    return 0;
}

Measured memory_bytes: 256
import java.util.*;

class Main {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        String[] abc = scanner.nextLine().split(" ", 3);

        int[] nums = new int[3];
        nums[0] = Integer.parseInt(abc[0]);
        nums[1] = Integer.parseInt(abc[1]);
        nums[2] = Integer.parseInt(abc[2]);
        Arrays.sort(nums);

        int k = Integer.parseInt(scanner.nextLine());
        for (int i = 0; i < k; i++) {
            nums[2] *= 2;
        }

        System.out.println(nums[0] + nums[1] + nums[2]);
    }
}


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

using namespace std;

int main() {
    string s;
    cin >> s;
    if (s.size() % 2) {
        cout << "No";
    } else {
        for (int i = 0; i < s.size(); i += 2) {
            if (s[i] != 'h' || s[i + 1] != 'i') {
                cout << "No";
                return 0;
            }
        }
        cout << "Yes";
    }
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <vector>
#include <map>
#include <set>
#include <string>
#include <queue>
#include <stack>
#include <iomanip>
#include <numeric>
#include <bitset>

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

using namespace std;

typedef long long ll;

int data[15][15];

bool is_valid(int bit, int n) {
  rep(i, n) {
    if ( (bit>>i) & 1 ) {
      rep(j, n) {
        if (data[i][j] == 1) {
          if ( ( (bit>>j) & 1 ) != 1) return false;
        } else if (data[i][j] == 0) {
          if ( ( (bit>>j) & 1 ) != 0) return false;
        }
      }
    }
  }
  return true;
}

int main () {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout << setprecision(20) << fixed;

  int n; cin >> n;
  int a[15] = {0};
  rep(i, 15) rep(j, 15) data[i][j] = 2;

  // input
  rep(i, n) {
    cin >> a[i];
    rep(j, a[i]) {
      int x, y;
      cin >> x >> y;
      data[i][x-1] = y;
    }
  }
  /* for debug
  rep(i, n) {
    rep(j, 15) {
      cout << data[i][j] << " ";
    }
    cout << endl;
  }
  */

  int ans = 0;
  // bit 全探索
  for (int bit = 0; bit < (1<<n); bit++){
    if ( is_valid(bit, n) ) {
      ans = max(ans, (int)bitset<32>(bit).count()); 
    }
  }
  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 256
#include <iostream>

static int H;

void maxHeapify(int *A, int i) {
    int left = i * 2;
    int right = left + 1;

	int largest = i;
    if (left <= H && A[left] > A[i]) {
        largest = left;
    }
    if (right <= H && A[right] > A[largest]) {
        largest = right;
    }

    if (largest != i) {
        std::swap(A[largest], A[i]);
        maxHeapify(A, largest);
    }
}

void buildMaxHeap(int *A) {
    for (auto i = H / 2; i > 0; i--) {
        maxHeapify(A, i);
    }
}

int main() {
    std::cin >> H;

    int A[H];
    for (int i = 1; i < H + 1; i++) {
        std::cin >> A[i];
    }
    
    buildMaxHeap(A);

    for (int i = 1; i < H + 1; i++) {
        std::cout << " " << A[i];
    }
    std::cout << std::endl;
}



Measured memory_bytes: 4944
import java.util.*;

public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		String str=sc.next();
		
		if(str.endsWith("2")||
		str.endsWith("4")||
		str.endsWith("5")||
		str.endsWith("7")||
		str.endsWith("9")
		){
			System.out.println("hon");
		}
		else if(str.endsWith("0")||
		str.endsWith("1")||
		str.endsWith("6")||
		str.endsWith("8")
		){	System.out.println("pon");
		}
		else{
			System.out.println("bon");
		}
	}
}


Measured memory_bytes: 35812
d = int(input())
clist = list(map(int,input().split()))
last_c = [0]*26

slist = [0] * d
for i in range(d):
    slist[i] = list(map(int,input().split()))

tlist = [0]*d
for i in range(d):
    tlist[i] = int(input())

satisfy = [0]*(d+1)

for i in range(1,d+1):
    satisfy[i] = slist[i-1][tlist[i-1]-1] + satisfy[i-1]
    last_c[tlist[i-1]-1] = i
    for j in range(26):
        satisfy[i] -= clist[j] * (i - last_c[j])

#remove first
satisfy.remove(0)

for i in satisfy:
    print(i)


Measured memory_bytes: 9400
#include<bits/stdc++.h>
typedef long long int ll;
typedef unsigned long long int ull;
#define BIG_NUM 2000000000
#define HUGE_NUM 1000000000000000000
//#define MOD 1000000007
#define EPS 0.000000001
using namespace std;


#define MOD 998244353
#define SIZE 200005

struct Info{
	bool operator<(const struct Info &arg) const{

		return x < arg.x;
	}
	ll x,y;
};

ll num_point,N;
ll POW[SIZE],BIT[SIZE];
ll LU[SIZE],LD[SIZE],RU[SIZE],RD[SIZE];
Info info[SIZE];
vector<ll> X,Y;
map<ll,ll> map_X,map_Y;


void add(ll loc,ll value){

	BIT[loc] += value;

	loc += loc & -loc; //最後の1ビットを足した場所が次の★更新★場所

	while(loc <= N){
		BIT[loc] += value;
		loc += loc & -loc;
	}
}

ll getSum(ll loc){

	ll sum = BIT[loc];

	loc -= loc & -loc; //最後の1ビットを引いた場所が次の★加算★場所

	while(loc > 0){
		sum += BIT[loc];
		loc -= loc & -loc;
	}
	return sum;
}



ll func(ll lu,ll ld,ll ru,ll rd){

	ll all[4],not_zero[4];
	all[0] = POW[lu],all[1] = POW[ld],all[2] = POW[ru],all[3] = POW[rd];
	for(int i = 0; i < 4; i++){

		not_zero[i] = all[i]-1;
		if(not_zero[i] < 0){
			not_zero[i] += MOD;
		}
	}

	//対象の点を選ぶ場合
	ll ret = 1;
	for(int i = 0; i < 4; i++){

		ret *= all[i];
		ret %= MOD;
	}

	//対象の点を選ばない場合
	ll add = (not_zero[0]*not_zero[3])%MOD;
	add *= all[1];
	add %= MOD;
	add *= all[2];
	add %= MOD;

	ret += add;
	ret %= MOD;

	add = (not_zero[1]*not_zero[2])%MOD;
	add *= all[0];
	add %= MOD;
	add *= all[3];
	add %= MOD;

	ret += add;
	ret %= MOD;

	add = 1;
	for(int i = 0; i < 4; i++){

		add *= not_zero[i];
		add %= MOD;
	}

	ret -= add;
	if(ret < 0){

		ret += MOD;
	}

	return ret;
}



int main(){

	POW[0] = 1;
	for(int i = 1; i < SIZE; i++){

		POW[i] = POW[i-1]*2;
		POW[i] %= MOD;
	}

	scanf("%lld",&num_point);

	for(int i = 0; i < num_point; i++){

		scanf("%lld %lld",&info[i].x,&info[i].y);
		X.push_back(info[i].x);
		Y.push_back(info[i].y);
	}

	sort(X.begin(),X.end());
	sort(Y.begin(),Y.end());

	for(ll i = 0; i < X.size(); i++){

		map_X[X[i]] = i+1;
	}
	for(ll i = 0; i < Y.size(); i++){

		map_Y[Y[i]] = i+1;
	}

	N = X.size();

	sort(info,info+num_point);

	for(ll i = 0; i <= N; i++){

		BIT[i] = 0;
	}

	//左→右
	for(int i = 0; i < num_point; i++){

		ll tmp = getSum(map_Y[info[i].y]);
		LD[i] = tmp;
		LU[i] = i-tmp;

		add(map_Y[info[i].y],1);
	}

	for(ll i = 0; i <= N; i++){

		BIT[i] = 0;
	}

	ll num = 0;

	//右→左
	for(int i = num_point-1; i >= 0; i--,num++){

		ll tmp = getSum(map_Y[info[i].y]);
		RD[i] = tmp;
		RU[i] = num-tmp;

		add(map_Y[info[i].y],1);
	}

	ll ans = 0;

	for(int i = 0; i < num_point; i++){

		ans += func(LU[i],LD[i],RU[i],RD[i]);
		ans %= MOD;
	}

	printf("%lld\n",ans);

	return 0;
}


Measured memory_bytes: 40932
#include <cstdio>
#include <vector>
#include <algorithm>
#include <cstring>
#include <string>
#include <cctype>
#include <sstream>
#include <cmath>
#include <climits>
#include <set>
#include <iostream>
#include <map>
#include <functional>

using namespace std;

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

typedef vector<int> vi;

int main()
{
	int n;
	scanf("%d", &n);

	char str[9];
	rep(i, n){
		scanf(" %s", str);
		sort(str, str+8);
		int low = atoi(str);

		sort(str, str+8, greater<char>());
		int high = atoi(str);
		printf("%d\n", high-low);
	}

	return 0;
}

Measured memory_bytes: 0
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace AtCoder
{
    class Program
    {
        static void Main()
        {
            Solve();

            Console.ReadKey();
        }

        static void Solve()
        {
            var str = IO.GetIntList();
            var L = IO.GetIntList();
            var Di = 0;
            var ans = 1;
            while (Di < str[1])
            {
                Di += L[ans-1];
                if (Di <= str[1]) { ans++; }
                if (ans >= str[0] + 1) break;
            }

            Console.WriteLine(ans);
        }
    }


    static class IO
    {
        static public string GetString() { return Console.ReadLine(); }
        static public int GetInt() { return int.Parse(Console.ReadLine()); }
        static public long GetLong() { return long.Parse(Console.ReadLine()); }
        static public List<string> GetStringList() { return Console.ReadLine().Split(' ').ToList(); }
        static public List<int> GetIntList() { return Console.ReadLine().Split(' ').Select(int.Parse).ToList(); }
        static public List<long> GetLongList() { return Console.ReadLine().Split(' ').Select(long.Parse).ToList(); }
        static public List<double> GetDoubleList() { return Console.ReadLine().Split(' ').Select(double.Parse).ToList(); }
        static public void WriteStrings<T>(IEnumerable<T> values) { foreach (var o in values) { Console.Write(o + " "); } }
    }
}

Measured memory_bytes: 11348
//R<3S
#include <bits/stdc++.h>
#define hell 1000000007
#define PI 3.14159265358979323844
#define mp make_pair
#define pb push_back
#define fi first 
#define se second
#define ALL(v) v.begin(), v.end()
#define SORT(v) sort(ALL(v))  
#define REVERSE(v) reverse(ALL(v))
#define endl "\n"
#define vecmax(v) max_element(all(v))
#define vecmin(v) min_element(all(v))
#define GCD(m,n) __gcd(m,n)
#define LCM(m,n) m*(n/GCD(m,n))
#define rep(i, n)    for(int i = 0; i < (n); ++i)
#define repA(i, a, n)  for(int i = a; i <= (n); ++i)
#define repD(i, a, n)  for(int i = a; i >= (n); --i)
#define trav(x) for(auto i : x)
#define sz(a) (int)a.size()
#define sl(a) (int)a.length()
#define int long long
#define ld long double 
#define pii std::pair<int, int> 
#define pll std::pair<ll, ll>  
#define vi vector<int>  
#define vl vector<ll>
#define vvi vector<vi > 
#define vii vector<pii >
#define mii map<int,int>
#define mll map<ll,ll>


using namespace std;

void solve()
  {

	int n,m;
	cin>>n>>m;
	int dp[n+1][m+1];
	char a[n+1][m+1];
	repA(i,1,n)repA(j,1,m)cin>>a[i][j];
	
	repA(i,0,n)repA(j,0,m)dp[i][j]=0;
	dp[0][1]=1;
	
	repA(i,1,n)
	{
		repA(j,1,m)
		{
			if(a[i][j]=='#')continue;
			dp[i][j]+=dp[i-1][j]+dp[i][j-1];
			dp[i][j]%=hell;
		}
	}
	cout<<dp[n][m];

  }



signed main()
{
   std::ios_base::sync_with_stdio(false);
   cin.tie(0);
   cout.tie(0);
   int t;
   t=1;
   //cin>>t;
   while(t--)
    {
        solve();
    }


   return 0;
}


Measured memory_bytes: 12348
#include <bits/stdc++.h>
#define rep(i, a, b) for(int i = a; i < b; i++)
#define Rep(i, a, b) for(int i = a; i <= b; i++)
#define repr(i, a, b) for(int i = b-1; i >= a; i--)
// #define _GLIBCXX_DEBUG
#define Vl vector<ll>
#define Vs vector<string>
#define Vp vector<pair<ll, ll>>
using ll = long long;
#define ALL(v) (v).begin(),(v).end()
#define endl "\n"
#define chmin(x, y) x = min(x, y)
#define chmax(x, y) x = max(x, y)
#define co(x) cout << x << endl
#define coel cout << endl
#define pb push_back
#define sz(v) ((ll)(v).size())
using namespace std;  
const double pi = acos(-1.0);
const ll MOD = 1e9 + 7;
const ll INF = 1LL << 60;
#define pp pair<ll, pair<ll, ll>> 
#define fi first
#define se second

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

ll n, k; 
Vl a;

bool C(double x){
    int num = 0;
    rep(i, 0, n){
        num += (a[i]+x-1)/x - 1;
    }
    return num <= k;
}

int main() {
    cin >> n >> k;
    a.resize(n);
    ll l = 0, r = 0;
    rep(i, 0, n){
        cin >> a[i];
        chmax(r, a[i]);
    }

    ll m;
    r++;
    while(r-l > 1){
        m = (l+r)/2;
        if(C(m)) r = m;
        else l = m;
        // co(m << " " << l << " " << r);
    }
    
    cout << r << endl;
    
    return 0;
}




Measured memory_bytes: 4776
#include <bits/stdc++.h>
using namespace std;
 int main(){
   int N,X;
   cin >>N>>X;
   int L;
   int LSum=0;
   int ans=0;
   
   for(int i=0;i<N+1;i++){
     if(LSum<=X){ans++;}
     else{break;}
     cin >>L;
     LSum+=L;
   }
   cout <<ans<<endl;
 }

Measured memory_bytes: 256
#include <iostream>
int main() {
  int x, y;
  do {
    std::cin >> x >> y;
    if (x != 0 || y != 0) {
      if (x < y) {
        std::cout << x << " " << y << std::endl;
      } else {
        std::cout << y << " " << x << std::endl;
      }
    }
  } while (x != 0 || y != 0);
}

Measured memory_bytes: 1164
//g++  5.4.0
// Time_Complexity : O( 2^n * n )
#include<bits/stdc++.h>
using namespace std;
 
#define ff first
#define ss second
#define int long long
#define pb push_back
#define pii pair< int,int >
#define fast ios::sync_with_stdio(0) , cin.tie(0) , cout.tie(0) ;

const int nax = 1e5+10;
const int mod = 1e9+7;
vector<int> g[nax];
int dp[nax][2];

// 0 - white
// 1 - black
signed main()
{
    fast;
    int n;
    cin >> n;
    
    for(int i=1 ; i<n ; i++ )
    {
        int u , v;
        cin >> u >> v;
        g[u].pb( v);
        g[v].pb(u);
    }
    function< void(int,int) > dfs_dp = [&](int v,int p)
    {
        dp[v][1] = dp[v][0] = 1;
        for( auto u : g[v] )
        {
            if( u!=p )
            {
                dfs_dp( u,v );
                dp[v][0] *= ( dp[u][0] + dp[u][1]) %mod;
                dp[v][0] %= mod;
                dp[v][1] *= dp[u][0];
                dp[v][1] %= mod;
            }
        }
        return ;
    };
        
    dfs_dp(1,0);
    cout << ( dp[1][0] + dp[1][1]) %mod;
}

Measured memory_bytes: 15616
using System;
using System.Collections.Generic;
using System.Linq;


public class B{
	
	public static void Main(){
	
		string[] args;
		
		args = Console.ReadLine().Split(' ');
		int N = Int32.Parse(args[0]);
		int T = Int32.Parse(args[1]);
		
		List<int> cost = new List<int>(N);
		List<int> time = new List<int>(N);
		for(int i = 0; i < N; i++)
		{
			args = Console.ReadLine().Split(' ');
			int c = Int32.Parse(args[0]);
			int t = Int32.Parse(args[1]);
			if(t > T) continue;
			cost.Add(c);
			time.Add(t);			
		}
		
		if(cost.Count == 0)
		{
			Console.WriteLine("TLE");
		}
		else
		{
			int tmpMinCost = cost[0];
			for(int i = 1; i < cost.Count; i++)
			{
				if(cost[i] < tmpMinCost)
					tmpMinCost = cost[i];
			}
			Console.WriteLine(tmpMinCost);
		}
		
	}
	
}

Measured memory_bytes: 13140
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#define ll long long
using namespace std;
int read()
{
    char ch=getchar();int f=0,x=1;
    while(ch<'0'||ch>'9'){if(ch=='-') x=-1;ch=getchar();}
    while(ch>='0'&&ch<='9'){f=(f<<1)+(f<<3)+ch-'0';ch=getchar();}
    return f*x;
}
int main()
{
	int a,b,c,x,y;
	cin>>a>>b>>c>>x>>y;
	int ans=2000000000;
	for(int i=0;i<=max(x,y)*2;i++)
	{
		//cout<<i*c+a*max(0,x-c/2)+b*max(0,y-c/2)<<" ";
		ans=min(ans,i*c+a*max(0,x-i/2)+b*max(0,y-i/2));
	}
	cout<<ans;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define int long long
#define pb emplace_back
#define mp make_pair
#define mt make_tuple
#define all(v) v.begin(),v.end()
#define rep(i,start,lim) for(long long (i)=(start);i<(lim);i++)
#define revrep(i,n) for(long long i=n-1;i>=0;i--)
#define boost ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define osit ostream_iterator<int> output (cout," ")
#define endl '\n'
#define f first
#define s second
#define PI 3.141592653589793
#define MOD 1000000007
#define set0(x) memset(x,0,sizeof(x))
#define set1(x) memset(x,1,sizeof(x))
using namespace std;
typedef vector<int> vi;
typedef list<int> li;
typedef pair<int,int> ii;
typedef vector<ii> vii;
typedef tuple<int, int, int> iii;
template<typename T> T gcd(T a,T b){if(a==0) return b; return gcd(b%a,a);}
template<typename P> P dectobin(P a){if(a==0)return 0; else return(a%2 + 10*dectobin(a/2));}
template<typename Y> Y bintodec(Y a){int ans=0,b=1,t=a; while (t){int ld=t%10; t/=10;ans+=ld* b;b=b*2;} return ans; }
template<typename H> H modExp(H x, H n){ int r=1; while(n>0){if(n%2==1){r=(r*x)%MOD;}x=(x*x)%MOD;n/=2;}return r;}
template<typename T> T isPowerOfTwo(T x){return x && (!(x & (x - 1)));}	
template<typename T> T lcm(T a,T b) {return a*b/gcd(a,b);}
//template<typename T> T extendedEuclid(T A,T B){if(B==0){d=A; x=1;y=0;}else{ extendedEuclid(B,A%B);int temp=x; x=y; y=temp-(A
//B)*y;}}
int count(int A, int B, int M) 
{ 
    if (A % M == 0) 
        return (B / M) - (A / M) + 1; 
    return (B / M) - (A / M); 
}
int32_t main(){
	boost;osit;
	int a,b,c,d;
	cin>>a>>b>>c>>d;
	int l=lcm(c,d);
	int p=count(a,b,c);
	int q=count(a,b,d);
	int r=count(a,b,l);
	cout<<(b-a+1)-(p+q)+(r);
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
  int n;
  cin >> n;
  vector<int>a(n);
  for(int i=0;i<n;i++){
    cin >> a.at(i);
  }
  int max=a.at(0),min=a.at(0);
  for(int i=1;i<n;i++){
		if(min>a.at(i))
			min=a.at(i);
		if(max<a.at(i))
			max=a.at(i);
  }
  cout << max-min << endl;
}

Measured memory_bytes: 256
w,h,n=map(int,input().split())
minx=0
maxx=w
miny=0
maxy=h
for i in range(n):
    x,y,a=map(int,input().split())
    if a==1:
        minx=max(minx,x)
    elif a==2:
        maxx=min(maxx,x)
    elif a==3:
        miny=max(miny,y)
    elif a==4:
        maxy=min(maxy,y)
print(max((maxx-minx),0)*max(0,(maxy-miny)))

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
#define ll long long
int main(){
  int n; 
  cin>>n;
  vector<pair<int,int>>a[100];
  for(int i=0;i<n;i++){
      int l; 
      cin>>l;
     for (int j=0;j<l;j++){
        int x,y; 
        cin>>x>>y;
       a[i].push_back(make_pair(x-1,y));
    }
  }
  ll ans=0;
  for(int i=0; i<(1<<n); i++){
    int flag=1;
    ll cnt=0;
    for (int j=0;j<n;j++){
      
      if((i>>j)&1){
        cnt++;
        for(auto x : a[j]){
          if(x.second==1 && !((i>>x.first)&1)||x.second==0 &&  ((i>>x.first)&1)) 
            flag=0;
        }
    }
        
    }
    if(flag) 
       ans=max(ans,cnt);
  }
  cout<<ans<<endl;
}



Measured memory_bytes: 3612
//Author rahuliitkgp

/*A thing of beauty is a joy forever,
Its loveliness increases,
it will never pass into nothingness.*/
//Men at Work :)

#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
using namespace std;
typedef long long int ll;

#define setbits(x)      __builtin_popcountll(x)
#define mod             1000000007
#define ps(x,y)         fixed<<setprecision(y)<<x
#define w(x)            int x; cin>>x; while(x--)
#define INF (int)1e9 + (int)1e8
mt19937_64 mt(chrono::steady_clock::now().time_since_epoch().count());

double pi = 3.14159265358979323846264338327;

typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> pbds;

void cpp(){
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
}

int main() {
    cpp();
    ll n;
    cin>>n;
    ll p = -1;
    ll ans = 0;
    for(ll i=0; i<n; i++){
        ll x;
        cin>>x;
        ans+=max(p-x, 0ll);
        p = max(p, x);
    }
    cout<<ans<<endl;
    return 0;
}




Measured memory_bytes: 3628
#include<iostream>
#include<cstdio>
#include<string>
#include<algorithm>
#include<utility>
#include<numeric>
#include<vector>
#include<map>
#include<unordered_map>
#include<set>
#include<tuple>
#include<stack>
#include<queue>
#include<functional>
#include<iterator>
#include<cmath>
#include<cctype>

using namespace std;

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

const int INF = 1e9;
const ll LINF = 1e18;

struct edge{int to,cost;};

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

	int a,b;
	cin >> a >> b;

	int tmp=b;
	while(tmp >= 1){
		tmp/=10;
		a*=10;
	}
	a += b;
	for(int i=1;i*i <= a;i++){
		if(i*i == a){
			cout << "Yes\n";
			return 0;
		}
	}
	cout << "No\n";

	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0, i##_len = (n); i < i##_len; ++i)
#define reps(i, n) for (int i = 1, i##_len = (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 rep2(i, s, n) for (int i = (s); i < (int)(n); i++)
#define repc2(i, s, n) for (int i = (s); i <= (int)(n); i++)
#define inf 2e9
#define linf 9000000000000000000ll
#define all(v) v.begin(), v.end()
using namespace std;
typedef long long ll;

int m;
ll d[200001], c[200001];
ll digitsum(ll n) {
    ll res = 0;
    while (n != 0) {
        res += n % 10;
        n /= 10;
    }
    return res;
}
int main() {
    cin >> m;
    rep(i, m) { cin >> d[i] >> c[i]; }
    ll sum = 0;
    ll dignum = 0;
    rep(i, m) {
        dignum += c[i];
        sum += d[i] * c[i];
    }
    cout << dignum - 1 + (sum - 1) / 9 << endl;
    return 0;
}

Measured memory_bytes: 6724