akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
        #include <set>
        #include <stdio.h>
#include <string.h>
#include <vector>

#define ll long long
#define f first
#define s second
ll arr[500000];
 using namespace std;
 const ll MAX = 5000002; 
 vector<ll>p;
   unsigned ll phi[MAX+1]; 
 
int main()
{
               
    size_t found;
    long long c=0, c1=1,c2=1,g=1,h=1,z=4,k=1,maxi=1e10,msize,sum=0,sum1=0,sumi=0,sumf=0,ans=0;
    ll n,m,e,count=0,a=125,b,in,mod,gauss,mod1=0,euclid,cx1=0,cx2=0,c101=0,c102=0;
    ll expo;
 string s1="",s20="",x="",sx="",s="";
     bool t=0,t1=0,t2=0;
     cin>>n>>m;
     for(int i=0;i<n;i++){
     cin>>arr[i];
     sum+=arr[i];
     }
     if(sum==m)
     cout<<n;
    else if(m>sum)
    cout<<n-1;
else {
     sort(arr,arr+n);
       for(int i=0;i<n;i++){
           if (m-arr[i]>=0){
           c++;
           m-=arr[i];
    
           }
       }
       cout<<c;
}
     
     
}
 

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

using db = double;
using ll = long long;
using vi = vector <int>;
#define op operator
#define pb push_back

int main() {
	cout << fixed << setprecision(9);
	ios :: sync_with_stdio(0);

	int ans = 0;
	for(string s; cin >> s; )
		if(equal(s.begin(), s.end(), s.rend() - s.size()))
			ans ++;
	cout << ans << '\n';

	return 0;
}

Measured memory_bytes: 3108
#include <iostream>
#include <string>
#include <deque>

using namespace std;

int main() {
	deque<int> A;
	int q;
	int query;
	int x;
	int d;

	cin >> q;

	for (int i = 0; i < q; i++) {
		cin >> query;
		if (query == 0) {
			cin >> d >> x;
			if (d == 0)
				A.push_front(x);
			else
				A.push_back(x);
		}
		else if (query == 1) {
			cin >> x;
			cout << A[x] << endl;
		}
		else {
			cin >> d;
			if (d == 0) {
				A.pop_front();
			}
			else
				A.pop_back();
		}	
	}
}




Measured memory_bytes: 4680
#include <iostream>
#include <string>
#include <vector>
#include <cstdint>
#include <algorithm>

int main() {
	std::string s, t;
	std::cin >> s >> t;

	std::vector<int> index[26];
	for (int i = 0; i < s.size(); ++i)
		index[s[i] - 'a'].push_back(i);

	for (int i = 0; i < 26; ++i) {
		if (std::count(t.begin(), t.end(), 'a' + i) != 0 && index[i].empty()) {
			std::cout << -1 << std::endl;

			return 0;
		}
	}

	std::int64_t ans = 0;

	int prevIdx = -1;
	for (int i = 0; i < t.size(); ++i) {
		auto& sIdx = index[t[i] - 'a'];

		auto it = std::upper_bound(sIdx.begin(), sIdx.end(), prevIdx);
		if (it == sIdx.end()) {
			ans += s.size() - prevIdx + sIdx[0];
			prevIdx = sIdx[0];
		}
		else {
			ans += *it - prevIdx;
			prevIdx = *it;
		}
	}

	std::cout << ans << std::endl;
}

Measured memory_bytes: 1216
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i, n) for (int i = 0; i < (int)n; ++i)
#define repi(i, a, b) for (int i = int(a); i < int(b); ++i)
#define repr(i, n) for (int i = (int)n - 1; i >= 0; --i)
#define ALL(a) (a).begin(), (a).end()
const ll mod = 1e9 + 7;

int main() {
  int a,b;
  cin >> a >> b;
  cout << 6 - a - b << endl;
  return 0;
}

Measured memory_bytes: 256
import sys
sys.setrecursionlimit(10 ** 5 + 10)
def input(): return sys.stdin.readline().strip()

def resolve():
    
    h,m,hh,mm,k=map(int,input().split())
    val=(hh-1-h)*60+(mm+60-m)
    print(val-k)
    
resolve()

Measured memory_bytes: 61788
#include <iostream>
#include <cstdio>
#include <vector>
#include <iomanip>
#include <unordered_map>
#include <unordered_set>
#include <algorithm>
#include <map>
#include <set>
#include <cmath>
using namespace std;

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

    vector <int> sum(N);

    for (int i = 1; i < N; ++i) {
        int B;
        cin >> B;
        ++sum[B-1];
    }

    for (int i = 0; i < N; ++i) {
        cout << sum[i] << endl;
    }

    return 0;
}

Measured memory_bytes: 4052
#include<iostream>
#include<iomanip>
#include<vector>
#include<string>
#include<algorithm>
#include<cmath>
#include<functional>
#include<map>
#include<cstdlib>
#include<complex>
#include<numeric>
#include<set>
#include<deque>
#include<queue>

using namespace std;
using Int = long long;
Int INF = 1LL << 60;
const Int MOD = 1000000000 + 7;

int main() {

	cin.tie(nullptr);
	ios::sync_with_stdio(false);

	Int N;
	cin >> N;

	string s;
	cin >> s;

	char temp;
	Int len = s.size();

	for (Int i = 0; i < len; i++) {
		temp = s[i];
		temp -= 'A';

		temp += N;
		if (temp>25) {
			temp -= 26;
		}

		s[i] = temp + 'A';
	}

	cout << s << "\n";
}


Measured memory_bytes: 256
import java.util.*;
class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int W = Integer.parseInt(sc.next());
        int a = Integer.parseInt(sc.next());
        int b = Integer.parseInt(sc.next());
        if(b<a) {
            int t = a;
            a = b;
            b = t;
        }
        System.out.println(Math.max(0,(b-(a+W))));

    }
}

Measured memory_bytes: 22612
#include <bits/stdc++.h>
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define sz size()
#define all(a) a.begin(), a.end()
#define allr(a) a.rbegin(), a.rend()
#define mod 1000000007
#define forn(i, n) for (int i = 0; i < (int) (n); i++)
#define FOR(i, a, b) for (int i = (a); i < (b); i++)

using namespace std;

int main() {
   ios::sync_with_stdio(0);
   cin.tie(0);
   int n,k,x,y;
   cin >> n >> k >> x >> y;
   int price = 0;
   if(n < k){
       price = x*n;
   }else{
       price = x*k + y*(n-k);
   }
   cout << price;
   return 0;
}



Measured memory_bytes: 256
temp=input().split()
N=int(temp[0])
C=int(temp[1])
K=int(temp[2])
T=[int(input()) for i in range(N)]

T.sort()
ans=1
first=T[0]
bus=1
for i in range(1,N):
	if T[i]<=first+K:
		if bus<C:
			bus+=1
			continue
		else:
			ans+=1
			first=T[i]
			bus=1
	else:
		ans+=1
		bus=1
		first=T[i]
print(ans)

Measured memory_bytes: 7508
N = int(input())
T = [int(input()) for n in range(N)]


def gcd(a, b):
    while b:
        a, b = b, a % b
    return a


def lcm(a, b):
    return a * b // gcd(a, b)


res = T[0]
for t in T:
    res = lcm(res, t)

print(res)


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

// 総数を1000000007（素数）で割った余り
const long long mod = 1e9 + 7;

using ll = long long;
using pii  = pair<int, int>;
using pll = pair<ll, ll>;
#define ull unsigned long long
#define ld long double
#define vi vector<int>
#define vll vector<ll>
#define vc vector<char>
#define vs vector<string>
#define vpii vector<pii>
#define vpll vector<pll>

#define rep(i, n) for (int i = 0, i##_len = (n); i < i##_len; i++)
#define rep1(i, n) for (int i = 1, i##_len = (n); i <= i##_len; i++)
#define repr(i, n) for (int i = ((int)(n)-1); i >= 0; i--)
#define rep1r(i, n) for (int i = ((int)(n)); i >= 1; i--)

#define sz(x) ((int)(x).size())
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()

#define SORT(v, n) sort(v, v + n);
#define VSORT(v) sort(v.begin(), v.end());
#define RSORT(x) sort(rall(x));
#define pb push_back
#define mp make_pair

#define INF (1e9)
#define PI (acos(-1))
#define EPS (1e-7)

ull gcd(ull a, ull b) { return b ? gcd(b, a % b) : a; }
ull lcm(ull a, ull b) { return a / gcd(a, b) * b; }

int main(){
    int n;
    cin >> n;
    vi x(n), y(n);
    rep(i, n) cin >> x[i] >> y[i];
    auto dist = [&](int i, int j) {
        double dx = (x[i] - x[j]);
        double dy = (y[i] - y[j]);
        return sqrt(dx * dx + dy * dy);
    };
    vi p(n);
    rep(i, n) p[i] = i;
    double len = 0.0;
    int cnt = 0;
    do {
        rep(i, n-1) len += dist(p[i], p[i+1]);
        ++cnt;
    } while (next_permutation(all(p)));
    double ans = len / cnt;
    printf("%.10f\n", ans);
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <cstring>
#include <chrono>
#include <complex>
#define int long
#define mod 1000000007
#define inf 1000000000000000001;
#define all(c) c.begin(),c.end()
#define mp(x,y) make_pair(x,y)
#define mem(a,val) memset(a,val,sizeof(a))
#define eb emplace_back
#define f first
#define s second
using namespace std;

int dp[100005][105];
int n;
int *val,*wt;
int func (int c,int i){
    if (c < 0) {
        return INT_MIN;
    }
    if (dp[c][i]!=-1) {
        return dp[c][i];
    }
    if (i < 0) {
        return 0;
    }
    int op1 = val[i] + func(c-wt[i], i-1);
    int op2 = func(c, i-1);
    return dp[c][i] = max(op1,op2);
}

int32_t main(){
    int c;
    cin>>n>>c;
    for (size_t i = 0 ; i < 100005; i++) {
        for (size_t j = 0 ; j < 105; j++) {
            dp[i][j] = -1;
        }
    }
    val = new int[n];
    wt = new int [n];
    for (size_t i = 0 ; i < n; i++) {
        cin>>wt[i]>>val[i];
    }
    cout<<func(c, n-1)<<endl;
    delete [] val;
    delete [] wt;
}


Measured memory_bytes: 85552
import math

N = int(input())

ans = 0

for i in range(int(math.log10(N)) + 1):
    if i % 2 != 0:
        pass
    elif i == int(math.log10(N)):
        ans += N - 10**i + 1
    else:
        ans += 10**(i+1) - 10**i

print(ans)

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

typedef long long int ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vi> vvi;
typedef vector<vl> vvl;
typedef vector<string>vst;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef vector<pii> vii;
typedef vector<pll> vll;
typedef map<int,int> dct;

#define fastio ios_base::sync_with_stdio(false);cin.tie(0)
#define all(ct) ct.begin() , ct.end()
#define endl "\n"
#define fr(i,a) for(auto i:a)
#define f(i,a,b) for(int i=a;i<b;++i)
#define fd(i,a,b) for(int i=a;i>=b;--i)
#define pb push_back
#define in(d,v) d.find(v)!=d.end()
#define mp make_pair
#define pi 3.14159265

bool compare(pll a, pll b){
    return a.first*b.second<a.second*b.first;
}

const ll mod = 1e9+7;
const ll inf = ll(1e18);

ll modexp(ll x,ll n){
    if(n==0)return 1;
    if(n%2==0)return modexp((x*x)%mod,n/2);
    return (x*modexp((x*x)%mod,n/2))%mod;
}

int main(){
    //clock_t tm = clock();
    fastio;
    ll n,k,s;
    cin>>n>>k>>s;
    f(i,0,k){
        cout<<s<<" ";
    }
    if(s<1e9){
        f(i,k,n){
            cout<<s+1<<" ";
        }
    }
    else{
        f(i,k,n){
            cout<<1<<" ";
        }
    }
    cout<<endl;
    //cout<<((clock()-tm)*1.0)/CLOCKS_PER_SEC<<endl;
}

Measured memory_bytes: 1280
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int h,n;
  cin>>h>>n;
  for(int i=0;i<n;i++){
    int a;
    cin>>a;
    h-=a;
    if (h<=0){
      break;
    }
  }
  if(h>0){
    cout<<"No"<<endl;
  }
  else{
    cout<<"Yes"<<endl;
  }
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define INF 0x3f3f3f3f
#define MAX_V 2501
#define MAX_E 5001

ll V, E, P;

struct edge {
    ll from;
    ll to;
    ll cost;
};

edge es[MAX_E];

ll d[MAX_V];
bool negative[MAX_V];

void bellman_ford(ll s) {
  for (ll i = 1; i <= V; i++) d[i] = INF;
  d[s] = 0;

  for (ll i = 0; i < V - 1; i++) {
    for (ll j = 0; j < E; j++) {
      edge e = es[j];
      if(d[e.from] != INF && d[e.from] + e.cost < d[e.to]) {
        d[e.to] = d[e.from] + e.cost;
      }
    }
  }
}

void find_negative_loop() {
  for (ll i = 1; i <= V; i++) negative[i] = false;
  for (ll i = 1; i <= V; i++) {
    for (ll j = 0; j < E; j++) {
      edge e = es[j];
      if(d[e.to] != INF && d[e.from] + e.cost < d[e.to]) {
        d[e.to] = d[e.from] + e.cost;
        negative[e.from] = true;
      }
      if(negative[e.from]) negative[e.to] = true;
    }
  }
}

int main() {

  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cin >> V >> E >> P;

  for (ll i = 0; i < E; i++) {
    ll a,b,c;
    cin >> a >> b >> c;
    edge e = {a, b, P - c};
    es[i] = e;
  }

  bellman_ford(1);
  ll answer = max(0LL, -d[V]);
  find_negative_loop();
  if(negative[V]) answer = -1;
  cout << answer << endl;
}


Measured memory_bytes: 3804
import sys
sys.setrecursionlimit(10**7)
INF = 10 ** 18
MOD = 10 ** 9 + 7
def YesNo(x): return 'Yes' if x else 'No'
def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x) - 1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def II(): return int(sys.stdin.readline())
def SI(): return input()
from itertools import product
from collections import Counter

def main():
    N = II()
    if N == 1:
        return 1
    XY = []
    for _ in range(N):
        XY.append(LI())
    cnt = Counter()
    for p0, p1 in product(XY, repeat=2):
        dx, dy = p1[0] - p0[0], p1[1] - p0[1]
        if dx != 0 or dy != 0:
            cnt[(dx, dy)] += 1
    ans = N - max(cnt.values())
    return ans

print(main())

Measured memory_bytes: 3804
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define Rep(i,s,n) for(int i=s;i<n;i++)
#define fi first
#define sc second
#define all(c) c.begin(),c.end()
typedef long long int ll;
typedef pair<int, int> P;
typedef long double ld;
void ans(bool x){if(x) cout<<"Yes"<<endl;else cout<<"No"<<endl;}

const ll INF=1001001001;
const ll mod=10000000007;
int main(){
  ll n,k;
  cin>>n>>k;
  n=n%k;
  if(n>k-n){
    cout<<k-n<<endl;
  }
  else{
    cout<<n<<endl;
  }
}

Measured memory_bytes: 256
#include<cstdio>
#include<algorithm>
using namespace std;

long long arr[55];
long long stu[55];
long long ans = 0;
int n;
long long x;
void f(int d){
    if(x==arr[d]){//如果吃x层会整好吃完级别为 d 的汉堡
        ans += stu[d];
        return ;
    }else if(x){
        x--;// 吃掉最底层的 b
        if(x>arr[d-1]){// x 落在了上面的 L-1 级的汉堡
            x-=arr[d-1];//吃掉下面的 L-1 级的汉堡
            ans += stu[d-1];// L-1级别的汉堡有stu[l-1]层 p
            x--;// 吃掉中间的 p
            ans++;
            if(x)f(d-1);// 进入上面的 L-1 级的汉堡
            //这里可以不进行if判断直接进入 因为进入后还会判断x非零
        } else f(d-1);// 落点在下面的 L-1 级汉堡
    }
}
int main(){
    arr[0] = 1;
    arr[1] = 5;
    arr[2] = 13;
    stu[0] = 1;
    stu[1] = 3;
    stu[2] = 7;
    for(int i=3;i<51;i++){
        //arr[i] = 1+arr[i-1]+1+arr[i-1]+1;
        arr[i] = arr[i-1]*2+3;// 级别为 i 的汉堡的层数 b+p
        stu[i] = stu[i-1]*2+1;// 级别为 i 的汉堡的 p 的数量
    }
    scanf("%d%lld",&n,&x);
    f(n);
    printf("%lld\n",ans);
    return 0;
}

Measured memory_bytes: 128
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<iomanip>
#include<math.h>
#include<complex>
#include<queue>
#include<deque>
#include<stack>
#include<map>
#include<set>
#include<bitset>
#include<functional>
#include<assert.h>
#include<numeric>
using namespace std;
#define Rep(i,m,n) for(int i=(int)(m) ; i < (int) (n) ; ++i )
#define rep(i,n) Rep(i,0,n)
#define stop char nyaa;cin>>nyaa;
using ll = long long;
const int inf = 1e9 + 7;
const ll INF = 1LL << 60;
const ll mod = 1e9 + 7;

using P = pair<int, int>;

using LP = pair<ll, ll>;

map<ll, vector<LP>> mp;
void solve() {
	ll n, x, d; cin >> n >> x >> d;
	if (d == 0) {
		if (x == 0) {
			cout << 1 << endl;
		}
		else {
			cout << n + 1 << endl;
		}
		return;
	}
	ll le = 0, ri = 0;
	for (int i = 0; i <= n; i++) {
		ll s = i * x;
		ll r = (s%d + d) % d;
		ll dd = (s - r) / d;
		mp[r].push_back({ le+dd,ri+dd });

		le += i;
		ri += n - 1 - i;
	}
	ll ans = 0;
	for (auto&& p : mp) {
		vector<LP> &v = p.second;
		sort(v.begin(), v.end());
		ll ri = -INF;
		ll le = -INF+1;
		rep(i, v.size()) {
			if (v[i].first > ri) {
				ans += ri - le + 1;
				le = v[i].first;
				ri = v[i].second;
			}
			else {
				ri = max(ri, v[i].second);
			}
		}
		ans += ri - le + 1;
	}
	cout << ans << endl;
}


signed main() {
	solve();
	stop
	return 0;
}


Measured memory_bytes: 22144
#include<iostream>
#include<algorithm>
#include<cmath>
#include<map>
#include<stdio.h>
#include<vector>
using namespace std;
#define int long long
#define rep(s,i,n) for(int i=s;i<n;i++)
#define c(n) cout<<n<<endl;
#define ic(n) int n;cin>>n;
#define sc(s) string s;cin>>s;
#define mod 1000000007
#define inf 1000000000000000007
#define f first
#define s second
#define mini(c,a,b) *min_element(c+a,c+b)
#define maxi(c,a,b) *max_element(c+a,c+b)
//printf("%.12Lf\n",c);
int keta(int x){
	rep(0,i,30){
		if(x<10){
			return i+1;
		}
		x=x/10;
	}
}
int gcd(int x,int y){
	int aa=x,bb=y;
	rep(0,i,1000){
		aa=aa%bb;
		if(aa==0){
			return bb;
		}	
		bb=bb%aa;
		if(bb==0){
			return aa;
		}
	}
}	
int lcm(int x,int y){
	int aa=x,bb=y;
	rep(0,i,1000){
		aa=aa%bb;
		if(aa==0){
			return x/bb*y;
		}	
		bb=bb%aa;
		if(bb==0){
			return x/aa*y;
		}
	}
}
bool p(int x){
	if(x==1)return false;
	rep(2,i,sqrt(x)+1){
		if(x%i==0&&x!=i){
			return false;
		}
	}	
	return true;
}
int max(int a,int b){
	if(a>=b)return a;
	else return b;
}
int min(int a,int b){
	if(a>=b)return b;
	else return a;
}	
int n2[41];		
int nis[41]; 
int nia[41];
int mody[41];
int nn;
int com(int n,int y){
	int ni=1;
	for(int i=0;i<41;i++){
		n2[i]=ni;
		ni*=2;
	}
	int bunsi=1,bunbo=1;
	rep(0,i,y)bunsi=(bunsi*(n-i))%mod;
	rep(0,i,y)bunbo=(bunbo*(i+1))%mod;
	mody[0]=bunbo;
	rep(1,i,41){
		bunbo=(bunbo*bunbo)%mod;
		mody[i]=bunbo;
	}
	rep(0,i,41)nis[i]=0;
	nn=mod-2;
	for(int i=40;i>=0;i-=1){
		if(nn>n2[i]){
			nis[i]++;
			nn-=n2[i];
		}
	}
	nis[0]++;
	rep(0,i,41){
		if(nis[i]==1){
			bunsi=(bunsi*mody[i])%mod;
		}
	}
	return bunsi;
}
int yakuwa(int n){
	int sum=0;
	rep(1,i,sqrt(n+1)){
		if(n%i==0)sum+=i+n/i;
		if(i*i==n)sum-=i;
	}
	return sum;
}	
bool hei(int n){
	rep(0,i,100){
		if(i*i==n){
			return true;
		}
	}
	return false;
}		
int a[114514],b[114514];
string ss[114514];
signed main(){
	sc(s)
	if(s=="AAA"||s=="BBB"){
		c("No")
	}
	else c("Yes")	
}	

Measured memory_bytes: 1152
#include<bits/stdc++.h>
using namespace std;
int main()
{
	int n,x,m[110],xi=9999;
	cin>>n>>x;
	for(int i=1;i<=n;i++)
	cin>>m[i];
	int sum=n;
	for(int i=1;i<=n;i++)
	x=x-m[i];
	for(int i=1;i<=n;i++)
	{
		if(m[i]<xi)
		xi=m[i];
	}
	sum=sum+x/xi;
	cout<<sum<<endl;
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cmath>
#include <string>
#include <algorithm>
#include <limits>
#include <ctype.h> 
#include <stdio.h> 
#include <set> 
#include <iomanip>
#include <vector>
 
using namespace std;
 
typedef long long ll;
typedef long double ld;
#define L(ID) ((ID*2)+1)
#define R(ID) ((ID*2)+2)
#define M(L,R) ((L+R)/2)
#define forr(start,end) for(int i = start; i < end; i++)
#define gap ' '

const int MAXN = 4*1e5;

//ll a[MAXN], ST[MAXN * 4], LZ[MAXN*4];

/*bool perfectSquare(ll x){
    ll s = sqrt(x);
    if(s *s == x) return true;
    else return false;
}*/
typedef long double ld;

ll a[MAXN], n = 0;


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


int main() { 
    int n = 0, m = 0, x = 0;
    cin >> n >> m >> x;
    int a = 0, l = 0, r = 0;
    for(int i = 0; i < m; ++i){
        cin >> a;
        if(a < x){
            ++l;
        }
        else{
            ++r;
        }
    }
    cout << min(l,r) << endl;
    

    return 0; 
} 


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ALL(x) x.begin(),x.end()
#define rep(i,n) for(int i=0;i<(n);i++)
#define debug(v) cout<<#v<<":";for(auto x:v){cout<<x<<' ';}cout<<endl;
#define INF 1000000000
#define mod 1000000007
using ll=long long;
const ll LINF=1001002003004005006ll;
int dx[]={1,0,-1,0};
int dy[]={0,1,0,-1};
// ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
template<class T>bool chmax(T &a,const T &b){if(a<b){a=b;return true;}return false;}
template<class T>bool chmin(T &a,const T &b){if(b<a){a=b;return true;}return false;}

ll dp[600][100100];
int k=9;

signed main(){
    cin.tie(0);
    ios::sync_with_stdio(0);
    
    int n;cin>>n;
    int v[n+1],w[n+1];
    for(int i=1;i<=n;i++) cin>>v[i]>>w[i];

    rep(i,600)rep(j,100100) dp[i][j]=0;
    for(int cur=1;cur<=min((1<<k),n);cur++){
        int par=cur/2;
        for(int i=100000;i>=0;i--){
            chmax(dp[cur][i],dp[par][i]);
            if(i+w[cur]<100100) chmax(dp[cur][i+w[cur]],dp[par][i]+v[cur]);
        }
    }

    int q;cin>>q;
    while(q--){
        int node,l;cin>>node>>l;

        if(node<(1<<k)){
            cout<<dp[node][l]<<endl;
            continue;
        }
        vector<int> vv,ww;
        for(;node>=(1<<k);node>>=1) vv.push_back(v[node]),ww.push_back(w[node]);

        int t=(int)vv.size();
        ll ans=0;
        for(int bit=0;bit<(1<<t);bit++){
            ll wsum=0,vsum=0;
            rep(i,t)if((bit>>i)&1)wsum+=ww[i],vsum+=vv[i];
            if(wsum<=l) chmax(ans,vsum+dp[node][l-wsum]);
        }
        cout<<ans<<endl;
    }
    return 0;
}


Measured memory_bytes: 474824
#include <algorithm>
#include <bitset>
#include <cmath>
#include <cstring>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>

const int MOD = 1e9 + 7;
const int iINF = 1000000000;
const long long int llINF = 1000000000000000000;

using namespace std;
using ll = long long int;
using P = pair<int, int>;
using edge = struct {
  int to;
  int cost;
};
#define ALL(a) (a).begin(), (a).end()
#define REP(i, n) for (ll i = 0; i < (n); i++)
#define RREP(i, n) for (ll i = (n)-1; i >= 0; i--)
#define MAX(vec) *std::max_element(vec.begin(), vec.end());
#define MIN(vec) *std::min_element(vec.begin(), vec.end());
#define MAXI(vec)                                                              \
  std::distance(vec.begin(), *std::max_element(vec.begin(), vec.end()));
#define MINI(vec)                                                              \
  std::distance(vec.begin(), *std::min_element(vec.begin(), vec.end()));
#define BIT(n, num) std::bitset<(n)>((num)).to_string()
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};

template <typename T, typename U> U read(ll V, T a, U b) {
  REP(i, V) {
    cin >> a;
    b.push_back(a);
  }
  return b;
}

int main() {
  ll D, G;
  vector<ll> p, c;
  ll minc = llINF;
  cin >> D >> G;
  REP(i, D) {
    ll pi, ci;
    cin >> pi >> ci;
    p.push_back(pi);
    c.push_back(ci);
  }
  REP(i, pow(2, D)) {
    string b = BIT(10, i);
    ll score = 0;
    ll count = 0;
    ll maxi = 0;
    reverse(ALL(b));
    REP(j, D) {
      if (b[j] == '1') {
        score += (j + 1) * 100 * p[j];
        score += c[j];
        count += p[j];
      } else if (maxi < j) {
        maxi = j;
      }
    }
    if (score >= G) {
      if (count < minc)
        minc = count;
    } else if (G - score <= (maxi + 1) * 100 * p[maxi] &&
               minc > count + ceil((float)(G - score) / ((maxi + 1) * 100))) {
      minc = count + ceil((float)(G - score) / ((maxi + 1) * 100));
    }
  }
  cout << minc << endl;

  return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
#include <string.h>
#include <algorithm>
#include <iostream>
#include <string>
#include <vector>
#include <functional>
#include <map>
#include <iomanip>
#include <math.h> 
#include <stack>
#include <queue>
#include <bitset>
#include <cstdlib>
#include <tuple>
#include <cctype>
#include <ctype.h>
#include <set>
#include <sstream>
#include <time.h>
#include <numeric>
using namespace std;
//#define int long long
#define rep(i,s,n) for(int i = s;i<n;i++)
#define repe(i,s,n) for(int i = s;i<=n;i++)
#define rrep(i,s,n) for(int i = (n)-1;i>=(s);i--)
#define all(v) (v).begin(),(v).end()
#define pb push_back
#define fi first
#define se second
#define chmin(a,b) a=min((a),(b))
#define chmax(a,b) a=max((a),(b))
#define l1 list[index]
#define l2 list[index - 1]
#define l3 list[index + 1]
#define iif(i,j) ((i<0 && j<0) || (i>0 && j>0)) ? true : false 
typedef long long ll;
typedef pair<int, int>pint;
typedef vector<int>vint;
typedef vector<pint>vpint;
typedef pair<pint, int> P1;
typedef pair<int, pint> P2;
typedef pair<pint, pint> PP;
static const ll maxLL = (ll)1 << 62;
const ll MOD = 1000000007;
const ll INF = 1e18;
const double PI = 3.14159265359;
int ca[12] = { 31,28,31,30,31,30,31,31,30,31,30,31 };



signed main() {
	int a, b;

	cin >> a >> b;

	int num = a - (b * 2);

	if (num <= 0) {
		cout << 0 << endl;
	}
	else {
		cout << num << endl;
	}
	
	return 0;
}

Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;

namespace MyProject
{
    class Program
    {
        static void Main(string[] args)
        {
#if Local
            var sw = new Stopwatch();
            sw.Start();
            Console.SetIn(new StreamReader("input.in"));
#endif
            var line1 = Console.ReadLine();
            var line2 = Console.ReadLine();
            var line3 = Console.ReadLine();
            var solver = new Solver(line1, line2, line3);
            var answer = solver.Solve();
            Console.WriteLine(answer);
#if Local
            Console.WriteLine($"{sw.ElapsedMilliseconds}ms");
#endif
        }
    }

    class Solver
    {
        public Solver(string line1, string line2, string line3)
        {
            var item = line1.Split().Select(elem => long.Parse(elem)).ToArray();
            this.N = (int)item[0];
            this.M = (int)item[1];
            this.K = item[2];
            this.A = line2.Split().Select(elem => long.Parse(elem)).ToList();
            this.B = line3.Split().Select(elem => long.Parse(elem)).ToList();
        }

        public int N { get; set; }
        public int M { get; set; }
        public long K { get; set; }
        public List<long> A { get; set; }
        public List<long> B { get; set; }

        public string Solve()
        {
            var ret = 0L;

            var a = new List<long> { 0 };
            for (int i = 0; i < this.N; i++)
            {
                a.Add(a[i] + this.A[i]);
            }

            var b = new List<long> { 0 };
            for (int i = 0; i < this.M; i++)
            {
                b.Add(b[i] + this.B[i]);
            }

            var j = this.M;
            for (int i = 0; i <= this.N; i++)
            {
                if (a[i] > this.K)
                {
                    break;
                }


                ret = Math.Max(ret, i + this.UpperBound(b, this.K - a[i]));
                // while (b[j] > this.K - a[i])
                // {
                //     j -= 1;
                // }

                // ret = Math.Max(ret, i + j);
            }

            return ret.ToString();
        }

        private int UpperBound(List<long> b, long val)
        {
            int ret = -1;
            var left = 0;
            var right = b.Count() - 1;
            while (left <= right)
            {
                var mid = (left + right) / 2;
                if (b[mid] <= val)
                {
                    // これが答えかも。midより右をチェック
                    ret = Math.Max(ret, mid);
                    left = mid + 1;
                }
                else
                {
                    // これが答えではない。midより左をチェック
                    right = mid - 1;
                }
            }

            return ret;
        }
    }
}


Measured memory_bytes: 77192
#pragma GCC optimize("Ofast")
#include "bits/stdc++.h"
using namespace std;
using ll = long long;
using ull = unsigned long long;
#define PI 3.141592
#define MOD7 1000000007
#define LL_INF 9000000000000000000
#define LL_MINF -9000000000000000000
#define INT_INF 2000000000
#define INT_MINF -2000000000
#define all(a) (a).begin(), (a).end()
#define fi first
#define se second
const int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
const int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};


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

    ll r = 0, g = 0, b = 0;
    for(char c : S){
        if(c == 'R') r++;
        else if(c == 'G') g++;
        else if(c == 'B') b++;
    }

    ull count = r * g * b;

    for(int i = 0; i < N - 2; i++){
        for(int j = i + 1; j < N - 1; j++){
            ll k = 2 * j - i;
            
            if(S[i] != S[j] and S[j] != S[k] and S[k] != S[i] and 0 <= k and k < N){
                count--;
            }
        }
    }
    cout << count << endl;
}

Measured memory_bytes: 3648
#pragma GCC optimize("Ofast,no-stack-protector,unroll-loops")
#pragma GCC optimize("no-stack-protector,fast-math")
#define IO ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0);
#include<iostream>
#include<bits/stdc++.h>
using namespace std;
#define ll long long 
#define ld long double
const int N =1e2+5;
int n,k,d;
set<int >st;
int main()
{   
    scanf("%d %d",&n,&k);
    for(int j=0;j<k;j++)
    {
        cin>>d;
        int a[d];
        for(int i=0;i<d;i++)
        {
            cin>>a[i];
            st.insert(a[i]);
        }
    }
    printf("%d\n",n-st.size());
}


Measured memory_bytes: 3836
using System;
using System.Collections;
using System.Collections.Generic;
using System.IO;
using System.Linq;

namespace Tasks
{
    public class B
    {
        static void Main(string[] args)
        {
            var sw = new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false };
            Console.SetOut(sw);
            Solve();
            Console.Out.Flush();
        }

        public static void Solve()
        {
            var ABX = Console.ReadLine().Trim().Split(' ').Select(long.Parse).ToArray();
            var (A, B, X) = (ABX[0], ABX[1], ABX[2]);
            var answer = B / X - Math.Max(0, (A - 1)) / X;
            if (A == 0) answer++;
            Console.WriteLine(answer);
        }
    }
}


Measured memory_bytes: 28260
#include<iostream>

using namespace std;

int main(){
    int n, m;
    cin >>n >>m;
    char pic[n][n], tpic[m][m];
    for(int i = 0; i < n; i++){
        for(int j = 0; j < n; j++){
            cin >>pic[i][j];
        }
    }
    for(int i = 0; i < m; i++){
        for(int j = 0; j < m; j++){
            cin >>tpic[i][j];
        }
    }

    bool exist = false;

    for(int i = 0; i < n; i++){
        for(int j = 0; j < n; j++){
            //cout << "a" << endl;
            if(i + m - 1 >= n || j + m - 1 >= n) continue;

            bool match = true;
            //cout << "a" << endl;
            for(int k = 0; k < m; k++){
                for(int l = 0; l < m; l++){
                    //cout << pic[i + k][j + m] << ":" << tpic[k][l] << endl;
                    if(pic[i + k][j + l] != tpic[k][l]){
                        match = false;
                        //cout << "a" << endl;
                    }
                }
            }
            if(match) exist = true;
        }
    }

    if(exist){
        cout << "Yes" << endl;
    }else{
        cout << "No" << endl;
    }
}

Measured memory_bytes: 256
INFTY = 1000
H,W = map(int,input().split())
S = [["#" for _ in range(W+2)]]
for i in range(H):
    row = list(input())
    row.insert(0,"#")
    row.append("#")
    S.append(row)
S.append(["#" for _ in range(W+2)])
G = {(i,j):[] for i in range(1,H+1) for j in range(1,W+1)}
for i in range(1,H+1):
    for j in range(1,W+1):
        if S[i][j]==".":
            if S[i][j+1]==".":
                G[(i,j)].append((i,j+1))
            if S[i-1][j]==".":
                G[(i,j)].append((i-1,j))
            if S[i][j-1]==".":
                G[(i,j)].append((i,j-1))
            if S[i+1][j]==".":
                G[(i,j)].append((i+1,j))
tot = 0
for i in range(1,H+1):
    for j in range(1,W+1):
        if S[i][j]==".":
            tot += 1
dist = [[INFTY for j in range(W+2)] for i in range(H+2)]
d = [[0 for j in range(W+2)] for i in range(H+2)]
cur = (1,1)
dist[cur[0]][cur[1]] = 0
d[cur[0]][cur[1]] = 1
while True:
    for x in G[cur]:
        if d[x[0]][x[1]]==0:
            if dist[x[0]][x[1]]>dist[cur[0]][cur[1]]+1:
                dist[x[0]][x[1]] = dist[cur[0]][cur[1]]+1
    dmin = INFTY
    for i in range(1,H+1):
        for j in range(1,W+1):
            if d[i][j]==0:
                if dist[i][j]<dmin:
                    cur = (i,j)
                    dmin = dist[i][j]
    if dmin==INFTY:
        break
    else:
        d[cur[0]][cur[1]]=1
if dist[H][W]==INFTY:
    print(-1)
else:
    print(tot-2-dist[H][W]+1)
    

Measured memory_bytes: 4212
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define ii pair <int, int>
#define app push_back
#define all(a) a.begin(), a.end()
#define bp __builtin_popcount
#define ll long long
#define mp make_pair
#define f first
#define s second
#define Time (double)clock()/CLOCKS_PER_SEC
const int N = 3e6 + 7;

const int MOD = 998244353;
int mod(int n) {
    n %= MOD;
    if (n < 0) return n + MOD;
    else return n;
}   
int fp(int a, int p) {
    int ans = 1, c = a;
    for (int i = 0; (1ll << i) <= p; ++i) {
        if ((p >> i) & 1) ans = mod(ans * c);
        c = mod(c * c);
    }   
    return ans;
}   
int dv(int a, int b) { return mod(a * fp(b, MOD - 2)); }
int f[N], inv[N];
int C(int n, int k) {
    return mod(f[n] * mod(inv[k] * inv[n - k]));
}
int comp(int n, int k) {
    return C(n + k - 1, k - 1);
}   

int get(int sum, int n, int mx) {
    int ans = 0;
    for (int i = 0; i <= sum && i <= n && i <= mx; ++i) {
        if ((i & 1) == (sum & 1)) {
            ans = mod(ans + C(n, i) * comp((sum - i) / 2, n));
        }
    }   
    return ans;
}   

int solve(int n, int m) {
    if (n == 0)
        return 0;
    int all = get(3 * m, n, m);
    int bad = mod(get(m, n, m) - comp(m, n - 1));
    bad = mod(bad * n);
    return mod(all - bad);
}   

signed main() {
    #ifdef HOME
    freopen("input.txt", "r", stdin);
    #else
    #define endl '\n'
    ios_base::sync_with_stdio(0); cin.tie(0);
    #endif

    f[0] = 1;
    for (int i = 1; i < N; ++i)
        f[i] = mod(f[i - 1] * i);
    for (int i = 0; i < N; ++i)
        inv[i] = fp(f[i], MOD - 2);

    int n, m;        
    cin >> n >> m;
    cout << solve(n, m) << endl;
}

Measured memory_bytes: 47232
n=int(input())
h=list(map(int,input().split()))
inf=10**9
h+=[inf]
ans='Yes'
for i in range(n):
    if h[i]==h[i+1]+1:
        h[i+1]+=1
    elif h[i]>h[i+1]+1:
        ans='No'
        break
print(ans) 

Measured memory_bytes: 14396
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.InputMismatchException;
import java.util.StringTokenizer;

public class Main {

	public static void main(String[] args) throws IOException {
		InputStream inputStream = System.in;
		OutputStream outputStream = System.out;
		InputReader in = new InputReader(inputStream);
		PrintWriter out = new PrintWriter(outputStream);
		TaskX solver = new TaskX();
		solver.solve(1, in, out);
		out.close();
	}

	static int INF = 1 << 30;
	static long LINF = 1L << 55;
	static int MOD = 1000000007;
	static int[] mh4 = { 0, -1, 1, 0 };
	static int[] mw4 = { -1, 0, 0, 1 };
	static int[] mh8 = { -1, -1, -1, 0, 0, 1, 1, 1 };
	static int[] mw8 = { -1, 0, 1, -1, 1, -1, 0, 1 };

	static class TaskX {

		public void solve(int testNumber, InputReader in, PrintWriter out) {

			int[] a = in.nextIntArray(3);
			Arrays.sort(a);
			out.println(a[2] * 10 + a[1] + a[0]);

		}
	}

	static class InputReader {
		BufferedReader in;
		StringTokenizer tok;

		public String nextString() {
			while (!tok.hasMoreTokens()) {
				try {
					tok = new StringTokenizer(in.readLine(), " ");
				} catch (IOException e) {
					throw new InputMismatchException();
				}
			}
			return tok.nextToken();
		}

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

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

		public double nextDouble() {
			return Double.parseDouble(nextString());
		}

		public int[] nextIntArray(int n) {
			int[] res = new int[n];
			for (int i = 0; i < n; i++) {
				res[i] = nextInt();
			}
			return res;
		}

		public int[] nextIntArrayDec(int n) {
			int[] res = new int[n];
			for (int i = 0; i < n; i++) {
				res[i] = nextInt() - 1;
			}
			return res;
		}

		public int[] nextIntArray1Index(int n) {
			int[] res = new int[n + 1];
			for (int i = 0; i < n; i++) {
				res[i + 1] = nextInt();
			}
			return res;
		}

		public long[] nextLongArray(int n) {
			long[] res = new long[n];
			for (int i = 0; i < n; i++) {
				res[i] = nextLong();
			}
			return res;
		}

		public long[] nextLongArrayDec(int n) {
			long[] res = new long[n];
			for (int i = 0; i < n; i++) {
				res[i] = nextLong() - 1;
			}
			return res;
		}

		public long[] nextLongArray1Index(int n) {
			long[] res = new long[n + 1];
			for (int i = 0; i < n; i++) {
				res[i + 1] = nextLong();
			}
			return res;
		}

		public double[] nextDoubleArray(int n) {
			double[] res = new double[n];
			for (int i = 0; i < n; i++) {
				res[i] = nextDouble();
			}
			return res;
		}

		public InputReader(InputStream inputStream) {
			in = new BufferedReader(new InputStreamReader(inputStream));
			tok = new StringTokenizer("");
		}
	}

}


Measured memory_bytes: 23252
import math
n = int(input())
P = list(map(int,input().split()))
Q = list(map(int,input().split()))

def get_num(A,N_list):
    num = 0
    nlist = N_list
    for m in range(n):
        a = N.index(A[m])
        x = a*math.factorial(n-m-1)
        num += x
        nlist.remove(A[m])
    return num

N = list(range(1,n+1))
p = get_num(P,N)
N = list(range(1,n+1))
q = get_num(Q,N)
print(abs(p-q))

Measured memory_bytes: 38256
//raja1999

//#pragma comment(linker, "/stack:200000000")
//#pragma GCC optimize("Ofast")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,avx,avx2")

#include <bits/stdc++.h>
#include <vector>
#include <set>
#include <map>
#include <string> 
#include <cstdio>
#include <cstdlib>
#include <climits>
#include <utility>
#include <algorithm>
#include <cmath>
#include <queue>
#include <stack>
#include <iomanip> 
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp> 
//setbase - cout << setbase (16)a; cout << 100 << endl; Prints 64
//setfill -   cout << setfill ('x') << setw (5); cout << 77 <<endl;prints xxx77
//setprecision - cout << setprecision (14) << f << endl; Prints x.xxxx
//cout.precision(x)  cout<<fixed<<val;  // prints x digits after decimal in val

using namespace std;
using namespace __gnu_pbds;
#define f(i,a,b) for(i=a;i<b;i++)
#define rep(i,n) f(i,0,n)
#define fd(i,a,b) for(i=a;i>=b;i--)
#define pb push_back
#define mp make_pair
#define vi vector< int >
#define vl vector< ll >
#define ss second
#define ff first
#define ll long long
#define pii pair< int,int >
#define pll pair< ll,ll >
#define sz(a) a.size()
#define inf (1000*1000*1000+5)
#define all(a) a.begin(),a.end()
#define tri pair<int,pii>
#define vii vector<pii>
#define vll vector<pll>
#define viii vector<tri>
#define mod (998244353)
#define pqueue priority_queue< int >
#define pdqueue priority_queue< int,vi ,greater< int > >
//#define int ll

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


//std::ios::sync_with_stdio(false);
ll inv[200013],mult[200013],invmult[200013],a[200013],coun[200013];
ll gcd(ll a,ll b){
	while(b!=0){
		
		a=a%b;
		swap(a,b);
	}
	return a;
}

ll extend_gcd(ll a,ll b,ll &x,ll &y){
	if(b==0){
		x=1;
		y=0;
		return a;
	}
	ll x1,y1;
	ll ans =extend_gcd(b,a%b,x1,y1);
	x=y1;
	y=x1-(a/b)*y1;

	return ans;
}
ll combination(ll n,ll r){
	if(r==0)
		return 1;
	if(n<r)
		return 0;
	ll ans=1;
	ans*=mult[n];
	ans%=mod;
	ans*=invmult[r];
	ans%=mod;
	ans*=invmult[n-r];
	ans%=mod;
	return ans;
}

ll initcombi(){
	int i;
	f(i,1,200011){
		ll x,y;
		ll val=extend_gcd(mod,i,x,y);
		if(y>0)
			inv[i]=y%mod;
		else{
				inv[i]=(y+mod)%mod;
		}
	}
	mult[0]=1;
	f(i,1,200011){
		mult[i]=mult[i-1]*i;
		mult[i]%=mod;
	}
	invmult[0]=1;
	f(i,1,200011){
		invmult[i]=invmult[i-1]*inv[i];
		invmult[i]%=mod;
	}
	return 0;
}


// do initcombi(); 
ll power[200010];
int main(){
	std::ios::sync_with_stdio(false); cin.tie(NULL);
	ll n,m,k,i,val,ans=0;
	cin>>n>>m>>k;
	power[0]=1;
	f(i,1,n+5){
		power[i]=power[i-1]*(m-1);
		power[i]%=mod;
	}
	initcombi();
	f(i,n-k,n+1){
		val=n-i;
		val+=i-1;
		val=combination(val,i-1);
		val*=m;
		val%=mod;
		val*=power[i-1];
		val%=mod;
		ans+=val;
		ans%=mod;
	}
	cout<<ans<<endl;
	return 0;
} 


Measured memory_bytes: 9852
#include<map>
#include<set>
#include<ctime>
#include<cmath>
#include<queue>
#include<bitset>
#include<vector>
#include<cstdio>
#include<cctype>
#include<string>
#include<cstring>
#include<cstdlib>
#include<iostream>
#include<algorithm>
#define gc getchar()//(p1==p2&&(p2=(p1=buf)+fread(buf,1,size,stdin),p1==p2)?EOF:*p1++)
#define lc (x<<1)
#define rc (x<<1|1)
#define fi first
#define se second
#define mk make_pair
#define pb push_back
#define ll long long
#define pi pair<int,int>
using namespace std;
const int N=1e5+10,size=1<<20,mod=998244353;

//char buf[size],*p1=buf,*p2=buf;
template<class o> void qr(o &x) {
	x=0; int f=1; char c=gc;
	while(!isdigit(c)){if(c=='-')f=-1; c=gc;}
	while(isdigit(c))x=x*10+c-'0',c=gc;
	x*=f;
}
template<class o> void qw(o x) {
	if(x<0) putchar('-'),x=-x;
	if(x>9) qw(x/10);
	putchar(x%10+'0');
}
template<class o> void pr1(o x) {qw(x); putchar(' ');}
template<class o> void pr2(o x) {qw(x); puts("");}

//math
ll gcd(ll x,ll y) {return !x?y:gcd(y%x,x);}
ll lcm(ll x,ll y) {return x/gcd(x,y)*y;}
ll power(ll a,ll b=mod-2) {
	ll c=1;
	while(b) {
		if(b&1) c=c*a%mod;
		b /= 2; a=a*a%mod;
	}
	return c;
}


int a,b,h,m;
double x,y,PI;

int main() {
	qr(a); qr(b); qr(h); qr(m); PI=acos(-1.0);
	x=(h+m/60.0)/12.0*PI*2; y=m/60.0*PI*2; 
	x=min(abs(x-y),2*PI-abs(x-y));
	printf("%.11lf\n",sqrt(a*a+b*b-2*a*b*cos(x)));
	return 0;
}



Measured memory_bytes: 4192
#include<stdio.h>
#include<math.h>
#define N 10000

int false = 0;
int true = 1;
int isPrime(int x);

int main(){
  int i,n,A[N],s=0;
  
  scanf("%d",&n);
  for(i=0 ; i<n ; i++){
    scanf("%d",&A[i]);
  }
  
  for(i=0 ; i<n ; i++){
    if(isPrime(A[i]) == 1) s++;
  }
  printf("%d\n",s);

  return 0;
}

int isPrime(int x){
  int i=3;
  
  if(x == 2) return 1;
  
  else if(x < 2 || x%2 ==0) return 0;
  
  while(i <= sqrt(x)){
    if(x%i == 0) return 0;
    
    i+=2;
  }
  return 1;
}

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

/*long long int f(int i, int j, vector<vector<bool>>& vis,
     vector<vector<long long int>>& dp, vector<int>& a)
{
  auto& ret = dp[i][j];
  if (vis[i][j])
    return ret;
  if (i == j)
    return a[i];
  vis[i][j] = true;

    return ret = max(a[i] - f(i + 1, j, vis, dp, a), a[j] - f(i, j - 1,  vis, dp,a));
}
*/


int main()
{
  int n;
  cin >> n;
  vector<int> a(n);
  for (int i = 0; i < n; ++i)
    cin >> a[i];
  vector<vector<long long int>> dp(n, vector<long long int>(n));
  for (int i = 0; i < n; ++i)
    dp[i][i] = a[i];
  for (int len = 2; len <= n; ++len)
  {
    for (int i = 0; i + len - 1 < n; ++i)
    {
      int j = i + len - 1;
      dp[i][j] = max(a[i] - dp[i+1][j], a[j] - dp[i][j-1]);
    }
  }

  cout << dp[0][n-1] << '\n';

  return 0;
}


Measured memory_bytes: 70656
process.stdin.resume();
process.stdin.setEncoding('utf8');

var g_input = '';
process.stdin.on('data', function(chunk) {
    g_input += chunk;
});

process.stdin.on('end', function() {
    Main(g_input.split(/\r?\n/));
});

function Main(input) {

    var n = parseInt(input[0], 10);
    var astr = input[1].split(' ');

    var i = 0;
    var a = new Array(n);
    for (i = 0; i < n; i++) {
        a[i] = parseInt(astr[i], 10);
    }

    var ans = 0;
    for (i = 0; i < n; i++) {
        var temp = a[i];
        while (temp % 2 === 0) {
            ans++;
            temp /= 2;
        }
    }

    console.log(ans);

    return 0;
}


Measured memory_bytes: 21448
W = input()
W = W.lower()
N = 0
while True:
 T = list(input().split())
 if len(T)==0:
  continue
 if T[0]=="END_OF_TEXT":
  break
 for ti in range(len(T)):
  if T[ti].lower()==W:
   N = N+1
print(N)



Measured memory_bytes: 5560
#include<stdio.h>

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

  
  for(int i = 0;i < n-1;i ++){
    for(int j = i;j < n;j ++){
      if(a[i]<a[j]){
        int temp = a[i];
        a[i] = a[j];
        a[j] = temp;
    }
  }}
   int A = 0,B =0;
  
  for(int i = 0;i < n;i ++){
    if(i%2==0){
      A +=a[i];
    }
    else{
      B += a[i];
    }
  }
  
 printf("%d",A-B);
  
  return 0;
}

Measured memory_bytes: 128
//#pragma GCC optimize "trapv"
#include<bits/stdc++.h>
#define  all(v)            v.begin(), v.end()
#define  sz(x)             (long long)x.size()
#define  debug(x)          cout << #x << ':' << x << endl;
#define  rep(i,n)          for(int i = 0; i <  n ; i++)
#define  reps(i,n)         for(int i = 1; i <= n ; i++)
#define  make_unique(v)    sort(all(v));v.erase(unique(all(v)), v.end());
#define  REMOVE(v,a)       v.erase(remove(v.begin(),v.end(), a), v.end());
#define  pb                push_back
#define  mp                make_pair
#define  endl              '\n'
#define  fi                first
#define  se                second
#define  ajs(a)            (a<0)?(-1*a):a

using namespace std;
typedef long long          ll;
typedef vector<long long>  vll;
typedef pair<ll,ll>        pll;
typedef vector<int>        vi;
const ll MOD = 1e9+7;
const int dx4[4] = {0, 1, 0, -1};
const int dy4[4] = {-1, 0, 1, 0};
const int dx8[8] = { -1, -1, -1, 0, 1, 1, 1, 0};
const int dy8[8] = { -1, 0, 1, 1, 1, 0, -1, -1};
bool cmp(int X, int Y) {return X > Y;}


ll gcd(ll a, ll b) {return !b ? a : gcd(b, a % b);}
ll lcm(ll a, ll b) {return (a / gcd(a, b)) * b;}
ll modpow(ll a, ll b, ll m=MOD){a %= m; ll res = 1; while (b) {if (b & 1)res = (res * a) % m; a = (a * a) % m; b >>= 1;} return res;}
ll bpow(ll a, ll b){if(b<0){return 0;}ll res = 1; while (b) {if (b & 1)res = res * a; a = a * a; b >>= 1;} return res;}
ll modinv(ll a, ll m = MOD) {return modpow(a, m - 2, m);}


const int N = 1e6 + 5;
vi adj[N];
ll vis[102][102];



int main(){ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
ll n;cin>>n;
ll a[n];
rep(i,n){
	cin>>a[i];
	}

ll mx = a[0];
ll ans = 0;
rep(i,n){
	if(a[i]<mx){
		ans+=(mx - a[i]);
		}
	mx = max(mx, a[i]);
	}
cout<<ans;	

}





	
	




		



Measured memory_bytes: 28612
#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[i];
    
    double sum = 0;
    for (int i = 0; i < N; i++) sum += 1.0 / A[i];
    cout << fixed << setprecision(6) << 1.0 / sum << endl;
}

Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main() {
    int n;
    cin >> n;
    int a[100001] = {0}, x, q, b, c;
    long long s;
    for (int i = 0; i < n; ++i) {
        cin >> x;
        s += x;
        ++a[x];
    }
    cin >> q;
    for (int i = 0; i < q; ++i) {
        cin >> b >> c;
        a[c] += a[b];
        s += c * a[b] - b * a[b];
        a[b] = 0;
        cout << s << endl;
    }
}

Measured memory_bytes: 4004
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time,copy,functools

sys.setrecursionlimit(10**7)
inf = 10**20
eps = 1.0 / 10**10
mod = 10**9+7
dd = [(-1,0),(0,1),(1,0),(0,-1)]
ddn = [(-1,0),(-1,1),(0,1),(1,1),(1,0),(1,-1),(0,-1),(-1,-1)]

def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def S(): return input()
def pf(s): return print(s, flush=True)


def main():
    d,g = LI()
    p = []
    c = []
    for _ in range(d):
        t = LI()
        p.append(t[0])
        c.append(t[1])

    r = inf
    for i in range(2**d):
        tg = 0
        tr = 0
        for j in range(d):
            if 2**j & i:
                tg += c[j]
                tg += (j+1) * p[j] * 100
                tr += p[j]
        for j in range(d-1,-1,-1):
            if tg >= g:
                break
            if 2**j & i:
                continue
            ng = g - tg
            k = ng // ((j+1) * 100)
            if ng % ((j+1) * 100) > 0:
                k += 1
            if p[j] >= k:
                tr += k
                break
            tr += p[j]
            tg += p[j] * (j+1) * 100
        if r > tr:
            r = tr
    return r


print(main())


Measured memory_bytes: 6100
a,b,m=map(int,input().split())
al=list(map(int,input().split()))
bl=list(map(int,input().split()))
ans=min(al)+min(bl)
for i in range(m):
    c,d,x=map(int,input().split())
    ans=min(ans,al[c-1]+bl[d-1]-x)
print(ans)

Measured memory_bytes: 18612