akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define ALL(v) v.begin(), v.end()
#define MOD 1000000007
#define MAX 510000
#define Rep(i, n) for(ll i = 0; i < (ll)(n); i++)
#define rep(i, n) for(ll i = 1; i <= (ll)(n); i++)

using namespace std;
typedef long long ll;
typedef pair<int, int> P;

//cout << fixed << setprecision(10);//
//最小公倍数//
ll gcd(ll x, ll y) {
	if (x == 0) return y;
	return gcd(y%x, x);
}
ll lcm(ll x, ll y) { return x * y / gcd(x, y); }

//べき//
ll squ(ll n, ll p, ll m){
	if(p==0) return 1;
	if(p%2==0){
		ll t=squ(n, p/2, m);
		return t*t%m;
	}
	return n*squ(n,p-1,m);
	
}


//逆元mod(mを法とするaの逆元)//
long long modinv(long long a, long long m) {
	long long b = m, u = 1, v = 0;
	while (b) {
		long long t = a / b;
		a -= t * b; swap(a, b);
		u -= t * v; swap(u, v);
	}
	u %= m;
	if (u < 0) u += m;
	return u;
}

//Cmonp//
ll fac[MAX], finv[MAX], inv[MAX];

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

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

//nが大

ll com(ll n,ll m){
	if(n<=0 || m<=0 || n==m){
		return 1;
	}
	if(n<m){
		return 0;
	}
	ll k=1;
	for(ll i=1;i<=m;i++){
       k*=(n-i+1); 
	   k%=MOD;
	   k*=modinv(i,MOD);
	   k%=MOD;
	}

	return k;
}


//


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




int main() {

ll n;
cin>>n;

ll a[n+1][3];
rep(i,n){
    Rep(j,3){
        cin>>a[i][j];
    }
}

ll dp[n+1][3];
Rep(i,n+1){
    Rep(j,3){
    dp[i][j]=0;
    }
}


rep(i,n){
    dp[i][0]=a[i][0]+max(dp[i-1][1],dp[i-1][2]);
     dp[i][1]=a[i][1]+max(dp[i-1][0],dp[i-1][2]);
 dp[i][2]=a[i][2]+max(dp[i-1][1],dp[i-1][0]);
}


ll ans=max(dp[n][1],max(dp[n][2],dp[n][0]));

cout<<ans<<endl;
return 0;
}



Measured memory_bytes: 4992
#include <algorithm>
#include <bitset>
#include <cstdio>
#include <cassert>
#include <cmath>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <tuple>
#include <utility>
#include <vector>
using namespace std;

constexpr int MOD = 1000000007;

typedef long long LL;
typedef pair<int, int> P;
typedef pair<LL, LL> PLL;

int K, T;
int a[100];

int main() {
    cin >> K >> T;
    for (int j = 0; j < T; ++j) {
        cin >> a[j];
    }
    sort(a, a+T);

    int s = 0;
    for (int j = 0; j < T-1; ++j) {
        s += a[j];
    }
    if (s >= a[T-1]-1) {
        cout << 0 << endl;
    } else {
        cout << a[T-1]-1-s << endl;
    }

    return 0;
}


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

int main()
{
	ios::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	
	map<int,int> mp;
	int n ;
	cin >> n;
	vector<int> A(n), B(n);
	for(int i=0; i<n; i++) cin >> A[i];
	for(int i=0; i<n; i++) cin >> B[i];
	reverse(B.begin(), B.end());
	int el = -1;
	for(int i=0; i<n; i++){
		if(A[i] == B[i]){
			el = A[i];
			break;
		}
	}
	if(el == -1){
		cout << "Yes\n";
		for(int i=0; i<n; i++) cout << B[i] << " ";
		return 0;
	}
	int l, r;
	for(int i=0; i<n; i++){
		if(A[i]==el && B[i]==el){
			l = i;
			break;
		}
	}
	for(int i=n-1; i>=0; i--){
		if(A[i]==el && B[i]==el){
			r = i;
			break;
		}
	}
	for(int i=0; i<n; i++){
		if(l>r) break;
		if(A[i]!=el && B[i]!=el){
			swap(B[i], B[l]);
			l++;
		}
	}
	if(l<=r){
		cout << "No\n";
		return 0;
	}
	cout << "Yes\n";
	for(int i=0; i<n; i++) cout << B[i] << " ";
	return 0;
}

Measured memory_bytes: 4756
/*input
8
WRWWRWRR
*/

// Nihesh Anderson - knandy

#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp> 

using namespace __gnu_pbds;
using namespace std;

typedef long long ll;
typedef long double ld;
typedef tree<ll,null_type,less<ll>,rb_tree_tag,tree_order_statistics_node_update> ordered_set; // find_by_order, order_of_key
ll MOD=1000000007;

#define endl '\n'
#define fast_cin() ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define pb push_back
ll INF = 2000000000000000001;
long double EPS = 1e-9;
ll power(ll a, ll n, ll md){if(n==0){return 1;}else{ll res=power(a,n/2,md);res=(res*res)%md;if(n%2!=0){res=(res*a)%md;}return res;}}
random_device rndm;
mt19937 grndm(rndm());
void mix(ll* a, ll* b){shuffle(a,b,grndm);}

int main(){
	fast_cin();
	// freopen("input.in","r",stdin);
	// freopen("output.out","w",stdout);
	ll n; cin >> n;
	string s; cin >> s;
	stack<ll> red;
	for(ll i = 0; i < n; i++) {
		if(s[i] == 'R') {
			red.push(i);
		}
	}
	ll ans = 0;
	for(ll i = 0; i < n; i++) {
		if(s[i] == 'W' && red.size() && red.top() > i) {
			ans++;
			red.pop();
		}
	}
	cout << ans << endl;
	return 0;
}




















Measured memory_bytes: 5092
a,b,c,d = map(int,input().split())
result = -1000000000000000000
ac = a * c
if result < ac:
    result = ac
ad = a * d
if result < ad:
    result = ad
bc = b * c
if result < bc:
    result = bc
bd = b * d
if result < bd:
    result = bd
print(result)



Measured memory_bytes: 9172
#include <stdio.h>
#include <math.h>

int main(){

  int n,i,j=3,count=0,flag=0;

  scanf("%d",&n);

  int A[n];

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

  
  for(i=0 ; i<n; i++){

    if(A[i] == 2){
      count++;
      continue;
    }

    if(A[i] == 1 || A[i]%2 == 0)continue;

    j = 3;
    
    while(j <= sqrt(A[i])){
 
      if(A[i]%j == 0){
	flag=1;
	break;
      }
	 
      else j = j + 2;

    }
    if(flag==0)count++;
    flag = 0;
  }

  printf("%d\n",count);
  
  return 0;
}

  

Measured memory_bytes: 628
#include<cstdio>
#define mod 1000000007
using namespace std;
typedef long long ll;
int main(){
    int n;
    ll k,two[60],a[60][50][50]={},b[50][50]={},c[50][50],ans=0;
    scanf("%d %lld",&n,&k);
    for(int i=0;i<n;i++){
        for(int j=0;j<n;j++){
            scanf("%lld",&a[0][i][j]);
        }
    }
    two[0]=1;
    for(int i=1;i<60;i++){
        two[i]=two[i-1]*2;
        for(int j=0;j<n;j++){
            for(int k=0;k<n;k++){
                for(int l=0;l<n;l++){
                    a[i][j][k]+=a[i-1][j][l]*a[i-1][l][k];
                    a[i][j][k]%=mod;
                }
            }
        }
    }
    for(int i=0;i<n;i++){
        b[i][i]=1;
    }
    for(int i=0;i<60;i++){
        if((k&two[i])){
            for(int j=0;j<n;j++){
                for(int k=0;k<n;k++){
                    c[j][k]=0;
                    for(int l=0;l<n;l++){
                        c[j][k]+=b[j][l]*a[i][l][k];
                        c[j][k]%=mod;
                    }
                }
            }
            for(int j=0;j<n;j++){
                for(int k=0;k<n;k++){
                    b[j][k]=c[j][k];
                }
            }
        }
    }
    for(int i=0;i<n;i++){
        for(int j=0;j<n;j++){
            ans+=b[i][j];
            ans%=mod;
        }
    }
    printf("%lld\n",ans);
}

Measured memory_bytes: 1408
#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;
//1-indexed
#include<vector>
template<typename T>
struct BIT{
	int n;
	vector<T>bit;
	BIT(int n_=0):n(n_),bit(n_+1){}
	T sum(int i)
	{
		T ans=0;
		for(;i>0;i-=i&-i)ans+=bit[i];
		return ans;
	}
	void add(int i,T a)
	{
		if(i==0)return;
		for(;i<=n;i+=i&-i)bit[i]+=a;
	}
	int lower_bound(T k)//k<=sum(ret)
	{
		if(k<=0)return 0;
		int ret=0,i=1;
		while((i<<1)<=n)i<<=1;
		for(;i;i>>=1)
			if(ret+i<=n&&bit[ret+i]<k)k-=bit[ret+=i];
		return ret+1;
	}
};
int N,K;
int A[1<<17];
main()
{
	cin>>N>>K;
	for(int i=0;i<N;i++)
	{
		cin>>A[i];A[i]-=K;
	}
	long S=0;
	vector<long>X(1,0);
	for(int i=0;i<N;i++)
	{
		S+=A[i];
		X.push_back(S);
	}
	sort(X.begin(),X.end());
	X.erase(unique(X.begin(),X.end()),X.end());
	BIT<int>P(X.size());
	long ans=0;S=0;
	for(int i=-1;i<N;i++)
	{
		if(i>=0)S+=A[i];
		int id=lower_bound(X.begin(),X.end(),S)-X.begin();
		ans+=P.sum(id+1);
		P.add(id+1,1);
	}
	cout<<ans<<endl;
}



Measured memory_bytes: 4500
#include <cstdio>

using namespace std;

int main() {
    int n, a, b, ans, i;
    
    scanf("%d %d %d", &n, &a, &b);
    
    ans = n;
    
    for (i = 0; i < n; i++) {
        int x;
        
        scanf("%d", &x);
        
        if (x >= a && x < b) ans--;
    }
    
    printf("%d\n", ans);
    
    return 0;
}


Measured memory_bytes: 128
import numpy as np
H, W = map(int, input().split())
area = []
for _ in range(H):
  s = input()
  area.append(list(s))

counterh = []
area = [area[i] for i in range(len(area)) if area[i].count('.')!=len(area[i])]

counterw = [1 for i in range(len(area[0]))]
for j in range(len(area)):
  for k in range(len(area[0])):
    if area[j][k] == '#':
      counterw[k] *= 0
Answer = []
for item in area:
  item = [item[i] for i in range(len(item)) if counterw[i] == 0]
  Answer.append(item)    

for o in range(len(Answer)):
  print(''.join(Answer[o]))

Measured memory_bytes: 12616
n=int(input())
li=[int(k) for k in input().split()]
dp=[0]*(n)
dp[0]=0
dp[1]=abs(li[1]-li[0])

for i in range(2,n):
  dp[i]=min(abs(li[i]-li[i-1])+dp[i-1],abs(li[i]-li[i-2])+dp[i-2])
#print(dp)
print(dp[n-1]) 


Measured memory_bytes: 13928
#include <bits/stdc++.h>
#define rep(i,a,b) for(ll i=ll(a);i<ll(b);i++)
#define irep(i,a,b) for(ll i=ll(a);i>=ll(b);i--)
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; }
#define pb push_back
#define mp make_pair
#define F .first
#define S .second 
#define pll pair<ll,ll>
using ll=long long;
using ld=long double;
const ll INF = 1LL<<60;
const ll mod=1e9+7;
using namespace std;
ll gcd(ll a, ll b) { return b ? gcd(b, a%b) : a; }

ll a[1100];
int main(){
    ll n,ans=0;
    cin>>n;
    rep(i,0,n)cin>>a[i];
    rep(i,0,n){
        if(i%2==0&&a[i]%2==1)ans++;
    }
    cout<<ans;
}




Measured memory_bytes: 3484
#include<stdio.h>
#define N 8
#define nfree -1
#define free 1

int A[N][N];
int row[N],col[N],dpos[2*N-1],dneg[2*N-1];
void putQueen(int i){
  int j;
 
  if(i==N){
    print();
    return;
  }
   
  for(j=0; j<N; j++){
    if(nfree==col[j]||nfree==dpos[i+j]||nfree==dneg[i-j+N-1]) continue;
    row[i] = j;
    col[j] = dpos[i+j] = dneg[i-j+N-1] = nfree;
    putQueen(i+1);
    row[i] = col[j] = dpos[i+j] = dneg[i-j+N-1] = free;
  }
}
 
void print(){
   
  int i,j;
   
  for(i=0; i<N; i++){
    for(j=0; j<N; j++){
      if(A[i][j]){
    if(row[i]!=j) return;
      }
    }
  }
   
  for(i=0; i<N; i++){
    for(j=0; j<N; j++){
      if(row[i]==j) printf("Q");
      else printf(".");
    }
    printf("\n");
  }
}
int main(){
 
  int n;
  int i,j;
  int x,y;
   
  for(i=0; i<N; i++){
    for(j=0; j<N; j++){
      A[i][j] = 0;
    }
  }
   
  for(j=0; j<N; j++){
    row[j]=0;
    col[j]=0;
  }
  for(j=0; j<2*N-1; j++){
    dpos[j]=0;
    dneg[j]=0;
  }
   
  scanf("%d",&n);
   
  for(i=0; i<n; i++){
    scanf("%d %d",&x,&y);
    A[x][y] = 1;
  }
   
  putQueen(0);
 
  return 0;
}
 

Measured memory_bytes: 572
#include<bits/stdc++.h>
using namespace std;
string s;
int main()
{
	cin>>s;
	for(int i=0;i<s.size();i++)
	{
		if(s[i]=='9')
		{
			cout<<"Yes"<<endl;
			return 0;
		}
	}
	cout<<"No"<<endl;
	return 0;
}

Measured memory_bytes: 256
#include <sstream>
#include <string>
#include <vector>
#include <map>
#include <algorithm>
#include <iostream>
#include <utility>
#include <set>
#include <cctype>
#include <queue>
#include <stack>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <climits>
using namespace std;
#define INF 100000000
#define MAXK 110
typedef long long ll;

int N, K;
int S[MAXK];

int main(void) {
    while (1) {
        cin >> N >> K;
        if (N == 0 && K == 0) break;
        for (int i = 0; i < K; i++) {
            cin >> S[i];
        }
        for (int i = 0; i < N; i++) {
            for (int j = 0; j < K; j++) {
                int b;
                cin >> b;
                S[j] -= b;
            }
        }
        int i;
        for (i = 0; i < K; i++) {
            if (S[i] < 0) break;
        }
        if (i == K) cout << "Yes" << endl;
        else cout << "No" << endl;
    }
    return 0;
}

Measured memory_bytes: 1152
import java.util.Scanner;

public class Main {

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

		int K = sc.nextInt();
		int S = sc.nextInt();
		int count = 0;

		for (int x = 0; x <= K; x++) {
			for (int y = 0; y <= K; y++) {
				int z = S - x - y;
				if (0 <= z && z <= K) {
					count++;
				}

			}
		}

		System.out.println(count);

	}

}


Measured memory_bytes: 23764
import java.util.*;
import static java.util.Arrays.*;
import static java.lang.Math.*;

// AOJ 0021
public class Main {

	static Scanner sc = new Scanner(System.in);
	static int N;
	static final double EPS = 1e-8;
	public static void main(String[] args) {
		N = sc.nextInt();
		double[] x = new double[4], y = new double[4];
		for (int i = 0; i < N; i++) {
			for (int j = 0; j < 4; j++) {
				x[j] = sc.nextDouble();
				y[j] = sc.nextDouble();
			}
			
			Complex 
				p1 = new Complex(x[0], y[0]),
				p2 = new Complex(x[1], y[1]),
				p3 = new Complex(x[2], y[2]),
				p4 = new Complex(x[3], y[3]);
			
			if (!isCross(p1, p2, p3, p4)) {
				System.out.println("YES");
			} else {
				System.out.println("NO");
			}
		}
	}
	
	static boolean isCross(Complex p1, Complex p2, Complex p3, Complex p4) {
		double det = p1.sub(p2).crossProduct(p3.sub(p4));
		if (Math.abs(det) < Complex.EPS) {
			return false;
		} else {
			return true;
		}
	}
}

class Complex {
	static final double EPS = 1e-10;
	
	double re, im;
	
	Complex (double r, double i) {
		re = r; im = i;
	}

	double arg() {
		return Math.atan2(im, re);
	}
	
	double abs2() {
		return re * re + im * im;
	}
	
	double abs() {
		return Math.sqrt(abs2());
	}
	
	double innerProdut(Complex o) {
		return re * o.re + im * o.im;
	}
	
	double crossProduct(Complex o) {
		return re * o.im - im * o.re;
	}
	
	static Complex polar(double theta, double r) {
		return new Complex(r * Math.cos(theta), r * Math.sin(theta));
	}
	
	Complex conj() {
		return new Complex(re, -im);
	}
	
	Complex add(Complex o) {
		return new Complex(re + o.re, im + o.im);
	}

	Complex sub(Complex o) {
		return new Complex(re - o.re, im - o.im);
	}
	
	Complex mul(Complex o) {
		return new Complex(re * o.re - im * o.im, re * o.im + im * o.re);
	}
	
	Complex div(Complex o) {
		return new Complex((re * o.re + im * o.im) / o.abs2(), (im * o.re - re * o.im) / o.abs2());
	}
}

Measured memory_bytes: 12000
//Daniel Grzegorzewski
#include <bits/stdc++.h>

#define MP make_pair
#define PB push_back
#define ST first
#define ND second

using namespace std;

typedef pair<int, int> PII;
typedef vector<int> VI;
typedef vector<PII> VII;
typedef long long LL;

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

const int N = 3*(int)1e5+10;
bool used[N];
int res[N], n, x;

int main()
{
    init_ios();
    cin >> n >> x;
    if (n == 2) {
    	if (x != 2) {
    		cout<<"No\n";
    		return 0;
    	}
    	cout<<"Yes\n1\n2\n3\n";
    	return 0;
    }
    n = 2*n-1;
    if (x == 1 || x == n) {
    	cout<<"No\n";
    	return 0;
    }
    res[n/2] = x;
    res[n/2-1] = x-1;
    res[n/2+1] = x+1;
    used[x] = used[x-1] = used[x+1] = true;
    int nr = 1;
    for (int i = 0; i < n; ++i) {
    	if (res[i] == 0) {
    		while (used[nr])
    			++nr;
    		res[i] = nr++;
    	}
    }
    cout<<"Yes\n";
    for (int i = 0; i < n; ++i)
    	cout<<res[i]<<"\n";
}

Measured memory_bytes: 2304
#include <bits/stdc++.h>
using namespace std;
template<typename T> T GCD(T a, T b) {
    if (b == 0) return a;
    if (a % b == 0) return b;
    return (GCD(b, a % b));
}
template<typename T> T LCM(T a, T b) {
    return (a / GCD(a, b) * b);
}
template<class T, class U> struct SegmentTree {
    using F = function<T(T, T)>;
    using G = function<T(T, U)>;
    int n;
    T id;
    vector<T> data;
    F f;
    G g;
    
    SegmentTree(int sz, F f, G g, T def) : f(f), g(g) {
        n = 1; id = def;
        while (n < sz) n *= 2;
        data = vector<T>(2*n-1, id);
    }
    void update (int i, T x) {
        i += n - 1;
        data[i] = g(data[i], x);
        while (i > 0) {
            i = (i - 1) / 2;
            data[i] = f(data[i * 2 + 1], data[i * 2 + 2]);
        }
    }
    T query(int a, int b, int k = 0, int l = 0, int r = -1) {
        if (r < 0) r = n;
        if (r <= a || b <= l) return id;
        if (a <= l && r <= b) return data[k];
        T vl = query(a, b, 2 * k + 1, l, (l + r) / 2);
        T vr = query(a, b, 2 * k + 2, (l + r) / 2, r);
        return f(vl, vr);
    }
};

int main() {
    int N; long long X;
    cin >> N >> X;
    vector<long long> A(N+1, X);
    for (int i = 0; i < N; i++) cin >> A[i];
    sort(A.begin(), A.end());
    
    auto f = [](long long a, long long b) { return GCD(a, b); };
    auto g = [](long long i, long long x) { return x; };
    SegmentTree<long long, long long> sg(N, f, g, 0);
    for (int i = 0; i < N; i++) {
        long long dist = abs(A[i]-A[i+1]);
        sg.update(i, dist);
    }
    
    long long ans = sg.query(0, N);
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3072
#include <iostream>
#include <algorithm>
#include <functional>
#include <cstdlib>
#include <sstream>
#include <string>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <deque>
#include <complex>
#include <vector>
#include <bitset>
#include <cstdio>
#include <cmath>
#include <time.h>
#include <tuple>
#define all(c) ((c).begin(),(c).end())
#define rall(c) ((c).rbegin(),(c).rend())
//#define sort(v,n) sort(v,v+n)
#define ll long long
#define fi first
#define se second
#define inf 999999999
using namespace std;
const ll MOD = 1e9 + 7;
const double PI = acos(-1.0);
//---------------------------------------------------------------------------------------------//
int n;
inline string j(string a) {
	string res;
	res = a.substr(1, a.length() - 1);
	res += a[0];
	return res;
}
inline string c(string a) {
	string res;
	res = a[a.length() - 1];
	res += a.substr(0, a.length() - 1);
	return res;
}
inline string e(string a) {
	string res, b, c;
	if ((int)a.length() & 1) {
		b = a.substr(0, a.length() / 2);
		c = a.substr(a.length() / 2 + 1, a.length() / 2);
		//cout << "b=" << b << " c=" << c << endl;
		res = c;
		res += a[a.length() / 2];
		res += b;
		return res;
	}
	else {
		b = a.substr(0, a.length() / 2);
		c = a.substr(a.length() / 2, a.length() / 2);
		res = c + b;
		return res;
	}
}
inline string a(string a) {
	reverse(a.begin(), a.end());
	return a;
}
inline string p(string a) {
	char b[] = { '1','2','3','4','5','6','7','8','9','0' };
	for (int i = 0; i < a.length(); i++) {
		for (int j = 0; j < 10; j++) {
			if (a[i] == b[j]) {
				if (j < 9) {
					a[i] = b[j + 1];
				}
				else {
					a[i] = b[0];
				}
				j = 10;
			}
		}
	}
	return a;
}
inline string m(string a) {
	char b[] = { '1','2','3','4','5','6','7','8','9','0' };
	for (int i = 0; i < a.length(); i++) {
		for (int j = 0; j < 10; j++) {
			if (a[i] == b[j]) {
				if (j > 0) {
					a[i] = b[j - 1];
				}
				else {
					a[i] = b[9];
				}
				j = 10;
			}
		}
	}
	return a;
}
int main() {
	cin >> n;
		for (int i = 0; i < n; i++) {
			string s, t;
			cin >> s >> t;
			for (int k = s.length() - 1; k >= 0; k--) {
				if (s[k] == 'A') {
					t=a(t);
				}
				else if (s[k] == 'J') {
					t=c(t);
				}
				else if (s[k] == 'M') {
					t=p(t);
				}
				else if (s[k] == 'P') {
					t=m(t);
				}
				else if (s[k] == 'E') {
					t=e(t);
				}
				else {
					t=j(t);
				}
				//cout <<"t="<< t << endl;
			}
			cout << t << endl;
		}
	return 0;
}

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

#define ll long long

int main() {
  ll N;
  cin>>N;
  if(N%2!=0)cout<<0<<endl;
  else{
    ll ans=0,f=5;
    N/=2;
    while(N/f>0){
      ans+=N/f;
      f*=5;
    }
    cout<<ans<<endl;
  }
}

Measured memory_bytes: 3568
#include <bits/stdc++.h>
#define be(v) (v).begin(),(v).end()
#define pb(q) push_back(q)
typedef long long ll;
using namespace std;
const ll mod=1000000007, INF=mod*mod*3LL;
#define doublecout(a) cout<<fixed<<setprecision(10)<<a<<endl;

struct edge{
	ll to,cost,time;
};


int main() {
    cin.tie(0);
    cout.tie(0);
    ios::sync_with_stdio(false);
    ll n, m, s;
    cin >> n >> m >> s; s = min(s,2500LL);
    ll C[100],D[100];
    vector<vector<edge> > v(51);
    for(int i=0;i<m;i++){
    	ll x,y,z,w;
    	cin >> x >> y >> z >> w;
    	x--;y--;
    	v[x].push_back({y,z,w});
    	v[y].push_back({x,z,w});
    }
    for(int i=0;i<n;i++){
    	cin >> C[i] >> D[i];
    }
    multiset<pair<pair<ll,bool>, pair<ll,ll> > > ms;

    ll dp[n][2501];
    for(int i=0;i<n;i++)for(int j=0;j<=2500;j++)dp[i][j] = INF;
    dp[0][s] = 0; 
    ms.insert({{0,0},{0,s}});// time now.n coin
    auto f = [&] (ll nowv,ll coin,ll t){
    	bool cst = false;
    	if(coin >= 2500LL)cst = true, coin = 2500;
    	if(dp[nowv][coin] > t){
    		dp[nowv][coin] = t;
    		ms.insert({{t, cst}, {nowv, coin}});
    	}
    };
    while(!ms.empty()){
    	ll t,nowv,coin;
    	pair<pair<ll,bool>,pair<ll,ll> > p=*ms.begin();
    	ms.erase(ms.begin());
    	t = p.first.first;
    	bool cst = p.first.second;
    	nowv = p.second.first;
    	coin = p.second.second;
    	if(dp[nowv][coin] < t)continue;
    	if(!cst)f(nowv, coin + C[nowv], t + D[nowv]);
    	for(auto& e:v[nowv]){
    		if(cst) f(e.to, coin, t + e.time);
    		else if(coin >= e.cost) f(e.to, coin - e.cost, t + e.time);
    	}
    }
    for(int i=1;i<n;i++){
    	ll ans = INF;
    	for(int j=0;j<=2500;j++){
    		ans = min(ans, dp[i][j]);
    	}
    	cout << ans << endl;
    }
    return 0;
}


Measured memory_bytes: 10440
# -*- coding: utf-8 -*-
H, W = [int(s) for s in input().split(" ")]

maze = [list(input()) for _ in range(H)]

distance = [[float("inf") for i in range(W)] for j in range(H)]

def bfs():
    queue = []
    sx = 0
    sy = 0
    gx = H-1
    gy = W-1

    queue.insert(0, (sx, sy))

    distance[sx][sy] = 0

    while len(queue):
        x, y = queue.pop()

        if x == gx and y == gy:
            break

        for i in range(0, 4):
            nx, ny = x + [1, 0, -1, 0][i], y + [0, 1, 0, -1][i]
            
            if (0 <= nx < H and 0 <= ny < W):
                if maze[nx][ny] != '#' and distance[nx][ny] == float("inf"):
                    queue.insert(0, (nx, ny))
                    distance[nx][ny] = distance[x][y] + 1

    return distance[gx][gy]

d = bfs()
cnt = 0
for i in range(H):
    for j in range(W):
        if maze[i][j] == ".":
            cnt += 1
if  d == float("inf"):
    print(-1)
else:
    print(cnt - d - 1)


Measured memory_bytes: 3064
#include<stdio.h>

int main()
{
	int a , b , c;
	int max , min , total;
	scanf("%d %d %d" , &a , &b , &c);
	total = a + b + c;
	if(a > b && a > c)
	{
		max = a;
	}
	else if(b > a && b > c)
	{
		max = b;
	}
	else
	{
		max = c;
	}
	if(a < b && a < c)
	{
		min = a;
	}
	else if(b < a && b < c)
	{
		min = b;
	}
	else
	{
		min = c;
	}
	printf("%d %d %d\n" , min ,total - min - max, max);
	return 0;
} 


Measured memory_bytes: 2712
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <utility>
#include <math.h>
#define REP(i,n) for(int i=0;i<n;i++)
#define REP2(i,n1,n2) for(int i=n1;i<n2;i++)
using namespace std;
typedef long long ll;

int main() {
    int n;
    cin >> n;
    int a[2][101];
    REP(i,2){
        REP(j,n){
            cin >> a[i][j];
        }
    }
    int res = 0;
    REP(i,n){
        int m = 0;
        REP2(j,0,i+1){
            m += a[0][j];
        }
        REP2(j,i,n){
            m += a[1][j];
        }
        res = max(res,m);
    }
    cout << res << endl;
    return 0;
}


Measured memory_bytes: 256
#include<iostream>

using namespace std;

int main(){
    int n, a[100009];
    cin >> n;
    for(int i=0;i<n;i++){
        cin >> a[i];
        a[i]--;
    }
    bool ans=false;
    int cur=0;
    for(int i=0;i<n;i++){
        cur = a[cur];
        if(cur==1){
            cout << i+1 << endl;
            ans=true;
            break;
        }
    }
    if(!ans){
        cout << -1 <<endl;
    }
}

Measured memory_bytes: 640
#include<bits/stdc++.h>
typedef int LL;
inline LL Read(){
	LL x(0),f(1); char c=getchar();
	while(c<'0' || c>'9'){
		if(c=='-') f=-1; c=getchar();
	}
	while(c>='0' && c<='9'){
		x=(x<<3)+(x<<1)+c-'0'; c=getchar();
	}return x*f;
}
LL T,n,a,b,c;
int main(){
	a=Read(); b=Read(); c=Read();
	LL ret(a-b);
	printf("%d",c-std::min(c,ret));
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define FAST_IO ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
typedef long long ll;
#define endl '\n'

void solve() {
    int n, m;
    cin >> n >> m;

    vector<int> h(n);
    for (int i = 0; i < n; ++i) {
        cin >> h[i];
    }
    int a, b;
    vector<int> adj[n];
    for (int i = 0; i < m; ++i) {
        cin >> a >> b;
        --a;
        --b;
        adj[a].push_back(b);
        adj[b].push_back(a);
    }

    int res = 0;
    for (int i = 0; i < n; ++i) {
        if (adj[i].size() == 0) {
            ++res;
            continue;
        }
        int hto = h[i];
        bool po = true;
        for (auto next: adj[i]) {
            if (h[next] >= hto) {
                po = false;
            }
        }
        if (po) {
            ++res;
        }
    }
    cout << res << endl;
}

int main() {
    FAST_IO;

    int t;
    // cin >> t;
    t = 1;

    while (t--) {
        solve();
    }
    
    return 0;
}

Measured memory_bytes: 8752
package main

import "fmt"

func main() {
	var (
		n int
		t float64
		a float64
	)
	fmt.Scan(&n, &t, &a)

	var bestPlace int
	diffTemp := 9999999999.0
	for i := 0; i < n; i++ {
		var x float64
		fmt.Scan(&x)

		temp := t - (x * 0.006)
		if abs(a-temp) < diffTemp {
			diffTemp = abs(a - temp)
			bestPlace = i + 1
		}
	}
	fmt.Println(bestPlace)
}

func abs(n float64) float64 {
	if n < 0 {
		return -n
	}
	return n
}


Measured memory_bytes: 512
#include <stdio.h>
#include <unordered_map>

typedef long long ll;

ll N,M;
ll a;

std::unordered_map<ll,ll> hash;

int main(){
        scanf("%lld %lld",&N,&M);

        ll sum = 0;
        hash[0] = 1;
        for(int i = 0; i < N; i++){
                scanf("%lld",&a);
                sum += a;
                hash[sum % M]++;
        }

        ll ans = 0;
        for(auto it = hash.begin(); it != hash.end(); it++){
                ans += (it->second >= 2) ? it->second*(it->second -1)/2 : 0;
        }

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

Measured memory_bytes: 3596
/*
* Created by: WeirdBugsButOkay
*/

#include <bits/stdc++.h>

#define ll long long
#define ld long double
#define ff first
#define ss second

using namespace std;

void solve()
{
    int a;
    cin >> a;
    cout << a + a * a + a * a * a << endl;
}

int main()
{
    int q = 1;
    //scanf("%d", &q);
    for(int i = 1; i <= q; i++)
    {
        solve();
    }
    return 0;
}

Measured memory_bytes: 3592
N, A, B = map(int, input().split())

if (B - A)%2 == 0:
  print((B - A) // 2)

else:
  if A - 1 > N - B:
    tmp = N - B
    B = N
    A = A + tmp + 1
    print((B - A) // 2 + tmp + 1)

  else:
    tmp = A - 1
    A = 1
    B = B - tmp - 1
    print((B - A) // 2 + tmp + 1)

Measured memory_bytes: 3060
#include <bits/stdc++.h>
#define N 100010
using namespace std;
typedef long long ll;
inline int read()
{
	int x=0,f=1; char ch=getchar();
	while(ch<'0'||ch>'9'){if(ch=='-')f=-1; ch=getchar();}
	while(ch>='0'&&ch<='9'){x=x*10+ch-'0'; ch=getchar();}
	return x*f;
}
int n,k,A[N],B[N];
int main()
{
	//freopen("read.in","r",stdin);
	ll Ans=0;
	n=read(); k=read();	
	for(int i=1;i<=n;i++)
		A[i]=read(), B[i]=read();
	for(int i=0;i<30;i++)
	{
		if(!(k&(1<<i))) continue;
		ll tmp=0;
		for(int j=1;j<=n;j++)
		{
			if(A[j]&(1<<i)) continue;
			int fg=0;
			for(int t=29;t>i;t--)
			{
				if(!(k&(1<<t))&&(A[j]&(1<<t)))
				{
					fg=1; break;
				}
			}
			if(!fg) tmp+=B[j];
		}
		Ans=max(Ans,tmp);
	}
	ll tmp=0;
	for(int j=1;j<=n;j++)
	{
		int fg=0;
		for(int t=29;t>=0;t--)
		{
			if(!(k&(1<<t))&&(A[j]&(1<<t)))
			{
				fg=1; break;
			}
		}
		if(!fg) tmp+=B[j];
	}
	Ans=max(Ans,tmp);
	cout << Ans << endl;
	return 0;
}

Measured memory_bytes: 1152
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#include <iostream>
#include <string>
#include <algorithm>
using namespace std;

long long int p9=1;
long long int p8=1;
int main(){
    int n;
    cin >>n;
    long long int ans = 0;
    for(int i=1; i < n; i++){
        p9=(p9*9)%1000000007;
        p8=(p8*8)%1000000007;
        ans = (ans*10+2*(p9+1000000007-p8))%1000000007;
    }
    cout << ans << endl;
}

Measured memory_bytes: 3176
#include <inttypes.h>
#include <math.h>
#include <stdbool.h>
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

struct robot {
    intmax_t X;
    intmax_t L;
    bool d;
};

int compare(const void *a, const void *b)
{
    if ((((struct robot *)a)->X + ((struct robot *)a)->L) < (((struct robot *)b)->X + ((struct robot *)b)->L))
        return -1;
    if ((((struct robot *)a)->X + ((struct robot *)a)->L) > (((struct robot *)b)->X + ((struct robot *)b)->L))
        return 1;
    return 0;
}

int main(void)
{
    intmax_t N;
    struct robot robot[100000] = {};
    intmax_t ans = 0;

    scanf("%jd", &N);
    for (size_t i = 0; i < N; i++) {
        scanf("%jd%jd", &robot[i].X, &robot[i].L);
    }

    qsort(robot, N, sizeof(struct robot), compare);

    intmax_t e = robot[0].X + robot[0].L;
    ans = 1;
    for (size_t i = 1; i < N; i++) {
        if (e > (robot[i].X - robot[i].L))
            continue;
        ans++;
        e = (robot[i].X + robot[i].L);
    }

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

    return 0;
}


Measured memory_bytes: 4860
#include <bits/stdc++.h>
#define all(x) (x).begin(), (x).end()
typedef long long ll;
#define MOD 998244353
using namespace std;
int main() {
    int n;
    cin >> n;
    vector<int> a(n);
    for(int i = 0; i < n; i++) {
        cin >> a[i];
    }
    int ans = 0;
    for(int i = 0; i < n; i++) {
        if(a[i] == i + 1) {
            swap(a[i], a[i + 1]);
            ans++;
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 640
#[allow(dead_code)]
fn main() {
    let (n, h, w) = i::u3();
    println!(
        "{}",
        i::uv2(n).iter().filter(|ab| ab.0 >= h && ab.1 >= w).count()
    );
}

#[allow(unused_imports)]
use std::cmp::*;
#[allow(unused_imports)]
use std::collections::{BTreeMap, BTreeSet, HashMap, HashSet, VecDeque};
#[allow(unused_imports)]
use std::io::*;
#[allow(unused_imports)]
use std::num::*;
#[allow(unused_imports)]
use std::str::*;

#[allow(dead_code)]
mod i {
    use super::*;

    pub fn read<T: FromStr>() -> T {
        stdin()
            .bytes()
            .map(|c| c.unwrap() as char)
            .skip_while(|c| c.is_whitespace())
            .take_while(|c| !c.is_whitespace())
            .collect::<String>()
            .parse::<T>()
            .ok()
            .unwrap()
    }
    pub fn str() -> String {
        read()
    }
    pub fn s() -> Vec<char> {
        str().chars().collect()
    }
    pub fn i() -> i64 {
        read()
    }

    pub fn u() -> usize {
        read()
    }

    pub fn u2() -> (usize, usize) {
        (read(), read())
    }

    pub fn u3() -> (usize, usize, usize) {
        (read(), read(), read())
    }

    pub fn u4() -> (usize, usize, usize, usize) {
        (read(), read(), read(), read())
    }

    pub fn u5() -> (usize, usize, usize, usize, usize) {
        (read(), read(), read(), read(), read())
    }

    pub fn u6() -> (usize, usize, usize, usize, usize, usize) {
        (read(), read(), read(), read(), read(), read())
    }

    pub fn f() -> f64 {
        read()
    }

    pub fn c() -> char {
        read::<String>().pop().unwrap()
    }

    pub fn iv(n: usize) -> Vec<i64> {
        (0..n).map(|_| i()).collect()
    }

    pub fn iv2(n: usize) -> Vec<(i64, i64)> {
        (0..n).map(|_| iv(2)).map(|a| (a[0], a[1])).collect()
    }

    pub fn iv3(n: usize) -> Vec<(i64, i64, i64)> {
        (0..n).map(|_| iv(3)).map(|a| (a[0], a[1], a[2])).collect()
    }

    pub fn uv(n: usize) -> Vec<usize> {
        (0..n).map(|_| u()).collect()
    }

    pub fn uv2(n: usize) -> Vec<(usize, usize)> {
        (0..n).map(|_| uv(2)).map(|a| (a[0], a[1])).collect()
    }

    pub fn uv3(n: usize) -> Vec<(usize, usize, usize)> {
        (0..n).map(|_| uv(3)).map(|a| (a[0], a[1], a[2])).collect()
    }

    pub fn uv4(n: usize) -> Vec<(usize, usize, usize, usize)> {
        (0..n)
            .map(|_| uv(4))
            .map(|a| (a[0], a[1], a[2], a[3]))
            .collect()
    }

    pub fn fv(n: usize) -> Vec<f64> {
        (0..n).map(|_| f()).collect()
    }

    pub fn cmap(h: usize) -> Vec<Vec<char>> {
        (0..h).map(|_| s()).collect()
    }
}


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

int main() {
  int N, M;
  cin >> N >> M;
  vector<pair<int,int>> problem(N);
  int ACnum = 0, WAnum = 0;
  int p; string S;
  rep(i,M) {
    cin >> p >> S;
    if (problem.at(p-1).first == 0) {
      if (S == "AC") {
        problem.at(p-1).first = 1;
        ACnum++;
        WAnum += problem.at(p-1).second;
      }
      else if (S == "WA") {
        problem.at(p-1).second++;
      }
    }
  }
  cout << ACnum << " " << WAnum << endl;
}

Measured memory_bytes: 1024
#include <iostream>
#include<vector>
#include<algorithm>
#include<cstring>
#include<string>
#include <set>
#include <cassert>
#include"math.h"
using namespace std;
#define MOD 1000000007
class UnionFind {
	vector<int> data;
public:
	UnionFind(int size) : data(size, -1) { }
	bool unionSet(int x, int y) {
		x = root(x); y = root(y);
		if (x != y) {
			if (data[y] < data[x]) swap(x, y);
			data[x] += data[y]; data[y] = x;
		}
		return x != y;
	}
	bool findSet(int x, int y) {
		return root(x) == root(y);
	}
	int root(int x) {
		return data[x] < 0 ? x : data[x] = root(data[x]);
	}
	int size(int x) {
		return -data[root(x)];
	}
};

int find(vector<long long> &arr, long long obj) {
	if (arr[arr.size() - 1] < obj)return arr.size()-1;
	if (arr[0] > obj)return -1;

	int min = 0; int max = arr.size() - 1;
	for (int i = 0; i < arr.size(); i++) {
		if (arr[min+(max-min) / 2] > obj) {
			max = min + (max - min) / 2;
		}
		else {
			min = min + (max - min) / 2;
		}
		if (max - min == 1) {
			return min;
		}
	}


}

int main() {
	int n;
	cin >> n;
	int *l = new int[n];
	int max = 0;
	int maxnum;
	for (int i = 0; i < n; i++) {
		cin >> l[i];
		if (max < l[i]) {
			max = l[i];
			maxnum = i;
		}
	}
	int temp = 0;
	for (int i = 0; i < n; i++) {
		if (i != maxnum) {
			temp += l[i];
		}
	}
	if (max < temp) {
		cout << "Yes";
	}
	else {
		cout << "No";
	}


	return 0;
}


Measured memory_bytes: 256
#include <iostream>

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

using namespace std;
typedef pair<string, int> P;
/** Problem0174 : Badminton **/
int main()
{
	int a, b;
	string s;
	while (cin>>s, s!="0") {
		a=0; b=0;
		s[0]='#';
		rep(i, s.length()) {
			if (s[i] == 'A') a++;
			else if (s[i] == 'B') b++;
		}
		if (a>b) a++;
		else b++;
		
		cout << a << " " << b << endl;
	}
	return 0;
}

Measured memory_bytes: 1184
#include<iostream>
using namespace std;
int main(){
    cout<<"1x1=1"<<endl;
    cout<<"1x2=2"<<endl;
    cout<<"1x3=3"<<endl;
    cout<<"1x4=4"<<endl;
    cout<<"1x5=5"<<endl;
    cout<<"1x6=6"<<endl;
    cout<<"1x7=7"<<endl;
    cout<<"1x8=8"<<endl;
    cout<<"1x9=9"<<endl;
    cout<<"2x1=2"<<endl;
    cout<<"2x2=4"<<endl;
    cout<<"2x3=6"<<endl;
    cout<<"2x4=8"<<endl;
    cout<<"2x5=10"<<endl;
    cout<<"2x6=12"<<endl;
    cout<<"2x7=14"<<endl;
    cout<<"2x8=16"<<endl;
    cout<<"2x9=18"<<endl;
    cout<<"3x1=3"<<endl;
    cout<<"3x2=6"<<endl;
    cout<<"3x3=9"<<endl;
    cout<<"3x4=12"<<endl;
    cout<<"3x5=15"<<endl;
    cout<<"3x6=18"<<endl;
    cout<<"3x7=21"<<endl;
    cout<<"3x8=24"<<endl;
    cout<<"3x9=27"<<endl;
    cout<<"4x1=4"<<endl;
    cout<<"4x2=8"<<endl;
    cout<<"4x3=12"<<endl;
    cout<<"4x4=16"<<endl;
    cout<<"4x5=20"<<endl;
    cout<<"4x6=24"<<endl;
    cout<<"4x7=28"<<endl;
    cout<<"4x8=32"<<endl;
    cout<<"4x9=36"<<endl;
    cout<<"5x1=5"<<endl;
    cout<<"5x2=10"<<endl;
    cout<<"5x3=15"<<endl;
    cout<<"5x4=20"<<endl;
    cout<<"5x5=25"<<endl;
    cout<<"5x6=30"<<endl;
    cout<<"5x7=35"<<endl;
    cout<<"5x8=40"<<endl;
    cout<<"5x9=45"<<endl;
    cout<<"6x1=6"<<endl;
    cout<<"6x2=12"<<endl;
    cout<<"6x3=18"<<endl;
    cout<<"6x4=24"<<endl;
    cout<<"6x5=30"<<endl;
    cout<<"6x6=36"<<endl;
    cout<<"6x7=42"<<endl;
    cout<<"6x8=48"<<endl;
    cout<<"6x9=54"<<endl;
    cout<<"7x1=7"<<endl;
    cout<<"7x2=14"<<endl;
    cout<<"7x3=21"<<endl;
    cout<<"7x4=28"<<endl;
    cout<<"7x5=35"<<endl;
    cout<<"7x6=42"<<endl;
    cout<<"7x7=49"<<endl;
    cout<<"7x8=56"<<endl;
    cout<<"7x9=63"<<endl;
    cout<<"8x1=8"<<endl;
    cout<<"8x2=16"<<endl;
    cout<<"8x3=24"<<endl;
    cout<<"8x4=32"<<endl;
    cout<<"8x5=40"<<endl;
    cout<<"8x6=48"<<endl;
    cout<<"8x7=56"<<endl;
    cout<<"8x8=64"<<endl;
    cout<<"8x9=72"<<endl;
    cout<<"9x1=9"<<endl;
    cout<<"9x2=18"<<endl;
    cout<<"9x3=27"<<endl;
    cout<<"9x4=36"<<endl;
    cout<<"9x5=45"<<endl;
    cout<<"9x6=54"<<endl;
    cout<<"9x7=63"<<endl;
    cout<<"9x8=72"<<endl;
    cout<<"9x9=81"<<endl;
    return 0;
}

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

int main()
{
  string s;
  cin >> s;
  
  string ans = "";
  int n = s.size();
  int an = 0;
  rep(i,n){
    if(s[i] == '0'){
      ans += '0';
    }else if(s[i] == '1'){
      ans += '1';
    }else if(s[i] == 'B' && (ans[an-1] == '0' || ans[an-1] == '1')){
      ans.erase(an-1);
    }
    an = ans.size();
  }
  
  cout << ans << endl;
}


Measured memory_bytes: 3592
#include <iostream>
#include <algorithm>
#include <string>
#include <cmath>
using namespace std;

int main(){

    int n,a,b,cnt=0;
    cin >> n;
  	cin >> a;
    cin >> b;

    for(int i=1;i<=n;++i){
        int wa = i/10000 + (i/1000)%10 + (i/100)%10 + (i/10)%10 + i%10;
        if(a <= wa && wa <= b) cnt+=i ;
    }

    cout << cnt;
    return 0;
}

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

#define rep(i, n) for(int i = 0; i<(n); i++)
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
using namespace std;
using ll = long long;

// https://www.creativ.xyz/segment-tree-abstraction-979/
template<class T>
class SegTree {
    int n;                       // 葉の数
    vector<T> data;              // データを格納するvector
    T def;                       // 初期値かつ単位元
    function<T(T, T)> operation; // 区間クエリで使う処理
    function<T(T, T)> update;    // 点更新で使う処理

    // 区間[a,b)の総和。ノードk=[l,r)に着目している。
    T _query(int a, int b, int k, int l, int r) {
        if (r <= a || b <= l) return def; // 交差しない
        if (a <= l && r <= b)
            return data[k]; // a,l,r,bの順で完全に含まれる
        else {
            T c1 = _query(a, b, 2 * k + 1, l, (l + r) / 2); // 左の子
            T c2 = _query(a, b, 2 * k + 2, (l + r) / 2, r); // 右の子
            return operation(c1, c2);
        }
    }

public:
    // _n:必要サイズ, _def:初期値かつ単位元, _operation:クエリ関数,
    // _update:更新関数
    SegTree(size_t _n, T _def, function<T(T, T)> _operation,
            function<T(T, T)> _update)
            : def(_def), operation(_operation), update(_update) {
        n = 1;
        while (n < _n) {
            n *= 2;
        }
        data = vector<T>(2 * n - 1, def);
    }

    // 場所i(0-indexed)の値をxで更新
    void change(int i, T x) {
        i += n - 1;
        data[i] = update(data[i], x);
        while (i > 0) {
            i = (i - 1) / 2;
            data[i] = operation(data[i * 2 + 1], data[i * 2 + 2]);
        }
    }

    // [a, b)の区間クエリを実行
    T query(int a, int b) {
        return _query(a, b, 0, 0, n);
    }

    // 添字でアクセス
    T operator[](int i) {
        return data[i + n - 1];
    }
};


int main() {
    int N;
    cin >> N;
    SegTree<ll> st(N + 1, 0, [](ll a, ll b) { return max(a, b); }, [](ll a, ll b) { return b; });
    vector<ll> H(N), A(N);
    rep(i, N) cin >> H[i];
    rep(i, N) cin >> A[i];

    rep(i, N) {
        ll val = st.query(0, H[i]) + A[i];
        st.change(H[i], val);
    }

    cout << st.query(0, N + 1) << endl;
}

Measured memory_bytes: 7424
using System;
using System.Collections;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;

namespace AtCoder
{
	public class ABC
	{
		static readonly int mod = 1000000007;  // 10^9+7

		static void Main(string[] args)
		{
			//System.Diagnostics.Stopwatch sw = new System.Diagnostics.Stopwatch(); sw.Start();
			//Console.SetOut(new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false });


			string s = Console.ReadLine();
			//int n = int.Parse(Console.ReadLine());
			//long x = long.Parse(Console.ReadLine());
			//int[] vs = Console.ReadLine().Split().Select(int.Parse).ToArray();
			//long[] vs = Console.ReadLine().Split().Select(long.Parse).ToArray();
			if (s[2] == s[3] && s[4] == s[5]) {
				Console.WriteLine("Yes");
			} else {
				Console.WriteLine("No");
			}



			//Console.Out.Flush();
			//System.Diagnostics.Debug.WriteLine(sw.Elapsed);
		}
	}
}

Measured memory_bytes: 13140
N, M = gets.split.map(&:to_i)

lists = []
N.times do
  lists << gets.split.map(&:to_i)
end
# p lists
lists.sort_by!{|x, y|x}
# p lists
num = M
ans = 0
lists.each do |list|
  if num >= list[1]
    num -= list[1]
    ans += list[0] * list[1]
  else
    ans += list[0] * num
    break
  end
end
puts ans


Measured memory_bytes: 12792
import java.util.Scanner;
   
class Main{
    public static void main(String[] args){
        Scanner stdIn = new Scanner(System.in);
   
        int i;
        int[] height = new int[10];
        int[] h = new int[]{0, 0, 0};
        for(i = 0; i < 10; i++){
            height[i] = stdIn.nextInt();
   
            if(h[0] <= height[i]){
                h[2] = h[1];
                h[1] = h[0];
                h[0] = height[i];
            } else if(h[1] <= height[i]) {
                h[2] = h[1];
                h[1] = height[i];
            } else if(h[2] <= height[i])
                h[2] = height[i];
        }
   
        for(int j = 0; j < 3; j++)
            System.out.println(h[j]);
    }
}

Measured memory_bytes: 26080
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <time.h>
#include <math.h>
#include <vector>
#include <queue>
#include <map>
#include <set>
#include <algorithm>
#include <iterator>
#include <sstream>
#include <string>
#include <bitset>
using namespace std;
#define FOR(I,F,N) for(int I = F; I < (int)(N); I++)
#define rep(i, n) FOR(i, 0, n)
#define FIN(V) cout<<V<<endl
#define pb push_back
#define INF (1 << 28)

template<typename T>
void remove(vector<T>& vector, unsigned int index){
vector.erase(vector.begin() + index);
}

typedef pair<int, int> P;
typedef long long ll;
typedef priority_queue<int> pq;
int StrToInt(string);
string IntToStr(int);
int dx[4] = {1, -1, 0, 0};
int dy[4] = {0, 0, 1, -1};

map<int, bool> memo;
vector<int> era;
void Eratosthenes(int N){
	int arr[N];
	for(int i = 0; i < N; i++){
		arr[i] = 1;
	}
	for(int i = 2; i < sqrt(N); i++){
		if(arr[i]){
			for(int j = 0; i * (j + 2) < N; j++){
				arr[i *(j + 2)] = 0;
			}
		}
	}

	for(int i = 2; i < N; i++){
		if(arr[i]){
			memo[i] = true;
			era.push_back(i);
		}
	}
}
int main(void){
	Eratosthenes(1<<16);
	int in;
	while(cin >> in, in){
		int ans = 0;
		rep(k,era.size()){
			int i = era[k];
			if(i > in)break;
			if(!memo[i])continue;
			rep(l,era.size()){
				int j = era[l];
				if(j > in)break;
				if(i + j > in)break;
				if(i < j)break;
				if(memo[j] && i+j == in){
					//cout << i << "+" << j << " = " << i+j << endl;
					ans++;
				}
			}
		}
		cout << ans << endl;
	}
	return 0;
}



int StrToInt(string s){
	stringstream ss;
	ss << s;
	int val;
	ss >> val;
	return val;
}
string IntToStr(int i){
	stringstream ss;
	ss << i;
	return ss.str();
}

Measured memory_bytes: 1808
#include<bits/stdc++.h>
using namespace std;
#define N 100
#define int long long

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

int32_t main()
{
     int a,b;
     cin>>a>>b;
     //int N=max(a,b);
     int lcm=(a*b)/gcd(a,b);
   cout<<lcm;
   return 0;
}

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

using namespace std;
using ll = long long;

int main()
{
    int n, k; cin >> n >> k;
    vector<ll> sum(n + 1);
    for(int i = 0; i < n; i++) {
        int a; cin >> a; sum[i + 1] = sum[i] + a;
    }
    vector<ll> a;
    for(int i = 0; i < n; i++){
        for(int j = i + 1; j <= n; j++)a.push_back(sum[j] - sum[i]);
    }

    ll res = 0;

    for(int i = 60; i >= 0; i--) {
        vector<ll> nxt;
        for(auto j : a) {
            if(j & (1LL << i))nxt.push_back(j);
        }
        if((int)nxt.size() >= k) {
            res |= (1LL<<i);
            a = nxt;
        }
    }
    cout << res << endl;
}

Measured memory_bytes: 6128
#include<iostream>
#include<algorithm>

using namespace std;

int main()
{
	int N;
	int ans = 0;
	cin >> N;
	int s[100];
	for (int i = 0; i < N; i++)
	{
		cin >> s[i];
		ans += s[i];
	}
	
	if (ans % 10 != 0)
	{
		cout << ans << endl;
		return 0;
	}
	
	int minans = 101;

	for (int i = 0; i < N; i++)
	{
		if (s[i] % 10 != 0)
		{
			minans = min(s[i], minans);
		}
	}

	if(minans == 101) cout << "0" << endl;
	else cout << (ans - minans) << endl;

	return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>	
#include<map>
#include<set>
#include<utility>
#include<cmath>
#include<cstring>
#include<queue>
#include<stack>
#include<cstdio>
#include<sstream>
#include<iomanip>
#include<assert.h>
#define loop(i,a,b) for(int i=a;i<b;i++) 
#define rep(i,a) loop(i,0,a)
#define pb push_back
//#define mt make_tuple
#define all(in) in.begin(),in.end()
#define shosu(x) fixed<<setprecision(x)
using namespace std;
//kaewasuretyuui
typedef long long ll;
typedef int Def;
typedef pair<Def,Def> pii;
typedef vector<Def> vi;
typedef vector<vi> vvi;
typedef vector<pii> vp;
typedef vector<vp> vvp;
typedef vector<string> vs;
typedef vector<double> vd;
//typedef tuple<int,int,int> tp;
//typedef vector<tp> vt;
typedef vector<vd> vvd;
typedef pair<Def,pii> pip;
typedef vector<pip>vip;
const double PI=acos(-1);
const double EPS=1e-7;
const int inf=1e9;
const ll INF=2e18;
int dx[]={0,1,0,-1};
int dy[]={1,0,-1,0};
int main(){
	int n;
	while(cin>>n,n){
		vi in(n+1);
		in[0]=2e9;
		rep(i,n){
			string s;
			cin>>s;
			if(s=="x"){
				if(i%2)in[i+1]=2e9+1;
				else in[i+1]=-2e9-1;
			}else in[i+1]=stoi(s);
		}
		if(n%2)in.pb(2e9);
		else in.pb(-2e9);
		int l=-2e9,r=2e9;
		bool h=true;
		loop(i,1,n+1){
			if(abs(in[i])==2e9+1&&abs(in[i+1])==2e9+1)h=false;
			if(i%2){
				if(in[i]>=min(in[i-1],in[i+1]))h=false;
				if(abs(in[i])==2e9+1){
					r=min(r,min(in[i-1],in[i+1])-1);
				}
			}else{
				if(in[i]<=max(in[i-1],in[i+1]))h=false;
				if(abs(in[i])==2e9+1){
					l=max(l,1+max(in[i-1],in[i+1]));
				}
			}
		}
		if(!h)cout<<"none"<<endl;
		else if(l==r)cout<<l<<endl;
		else if(l<r)cout<<"ambiguous"<<endl;
		else cout<<"none"<<endl;
	}
}

Measured memory_bytes: 3132
#include<bits/stdc++.h>
using ll = long long;
using P = std::pair<ll,ll>;

int main(){
        ll n, k;
        scanf("%lld %lld", &n, &k);

        std::vector<P> arr(n);
        for(ll i=0; i<n; i++) scanf("%lld %lld", &arr[i].first, &arr[i].second);
        std::sort(arr.begin(), arr.end());

        for(ll i=0; i<n; i++){
                k -= arr[i].second;
                if(k<=0){
                        printf("%lld\n", arr[i].first);
                        return 0;
                }
        }
        return 0;
}

Measured memory_bytes: 1792