akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define all(x) (x).begin(),(x).end()
const int mod=1000000007,MAX=100001,INF=1<<30;

ll rui(ll a,ll b){
    if(b==1) return a%mod;
    else if(b==0) return 1;
    else if(b%2==0) return (rui(a,b/2)*rui(a,b/2))%mod;
    else return (rui(a,b-1)*a)%mod;
}

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

void make(){
    
    fac[0]=fac[1]=1;
    finv[0]=finv[1]=1;
    inv[1]=1;
    
    for(int i=2;i<MAX;i++){
        inv[i]=mod-inv[mod%i]*(mod/i)%mod;
        fac[i]=fac[i-1]*(ll)i%mod;
        finv[i]=finv[i-1]*inv[i]%mod;
    }
    
}

ll comb(ll a,ll b){
    if(a<b) return 0;
    return fac[a]*(finv[b]*finv[a-b]%mod)%mod;
}

int main(){

    int N,K;cin>>N>>K;
    make();
    ll dp[N+1][K+1];
    for(int i=0;i<N+1;i++){
        for(int j=0;j<K+1;j++){
            dp[i][j]=0;
        }
    }
    for(int j=0;j<K+1;j++){
        dp[0][j]=1;
    }
    
    dp[1][1]=1;
    for(int i=1;i<=N;i++){
        for(int j=1;j<=K;j++){
            if(i==1&&j==1) continue;
            if(i-j<0) dp[i][j]=dp[i][j-1];
            else dp[i][j]=(dp[i][j-1]+dp[i-j][j])%mod;
        }
    }
    
    cout<<dp[N][K]<<endl;
}




Measured memory_bytes: 13240
#include<iostream>
#include<vector>
#include<algorithm>
#include<map>
#include<cstring>
#include<math.h>
#include<bitset>
#include<queue>
#include<set>
#include<iomanip>
#include<math.h>
#include<assert.h>
// #include<bits/stdc++.h>
using namespace std;
typedef long long ll;
constexpr long long int INFLL = 1001001001001001LL;
constexpr int INF = 1000000007;
const int mod = 1000000007;

template<class T> inline bool chmin(T& a, T b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
}
template<class T> inline bool chmax(T& a, T b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}


//----------------------------------------------------------------


int main(){
int n,k;
cin>>n>>k;
vector<long long>h(100010);
for(int i=0;i<n;i++){
    cin>>h[i];
}
vector<long long>dp(100010);
for(int i=0;i<n;i++){
    dp[i]=INF;
}
dp[0]=0;
for(int i=0;i<n;i++){
    for(int j=1;j<=k;j++){
chmin(dp[i+j],dp[i]+abs(h[i]-h[i+j]));
}
}
cout<<dp[n-1]<<endl;
}











Measured memory_bytes: 1920
s =input()
t = input()
s = sorted(s, key=str.lower)
t = sorted(t, key=str.lower, reverse=True)
s = ''.join(s)
t = ''.join(t)
l = [s,t]
l.sort()
if l[0] == s and s != t:
    print('Yes')
else:
    print('No')

Measured memory_bytes: 61968
#include <bits/stdc++.h>
using namespace std;
#define modulo 998244353
#define mod(mod_x) ((((long long)mod_x+modulo))%modulo)
#define Inf 1000000005

int beki(int a,int b,int M = modulo){
	int x = 1;
	while(b!=0){
		if(b&1){
			x=((long long)x*a)%M;
		}
		a=((long long)a*a)%M;
		b>>=1;
	}
	return x;
}


int gyakugen(int a){
	return beki(a,modulo-2);
}

struct combi{
	deque<int> kaijou;
	deque<int> kaijou_;
	
	combi(int n){
		kaijou.push_back(1);
		for(int i=1;i<=n;i++){
			kaijou.push_back(mod(kaijou[i-1]*i));
		}
		
		int b=gyakugen(kaijou[n]);
		
		kaijou_.push_front(b);
		for(int i=1;i<=n;i++){
			int k=n+1-i;
			kaijou_.push_front(mod(kaijou_[0]*k));
		}
	}
	
	int combination(int n,int r){
		if(r>n)return 0;
		int a = mod(kaijou[n]*kaijou_[r]);
		a=mod(a*kaijou_[n-r]);
		return a;
	}
	
	int junretsu(int a,int b){
		int x = mod(kaijou_[a]*kaijou_[b]);
		x=mod(x*kaijou[a+b]);
		return x;
	}
	
	int catalan(int n){
		return mod(combination(2*n,n)*gyakugen(n+1));
	}
	
};


int main(){
	
	int N,M,K;
	cin>>N>>M>>K;
	int ans = 0;
	combi C(1000000);
	
	for(int i=0;i<=K;i++){
		int t = M;
		t = mod(t * beki(M-1,N-1-i));
		t = mod(t * C.junretsu(N-1-i,i));
		ans = mod(ans + t);
	}
	
	cout<<ans<<endl;
	
	return 0;
}


Measured memory_bytes: 11644
#include<bits/stdc++.h>
using namespace std;
int main()
{   int a,b,c,d,a1,a2;
	cin>>a>>b>>c>>d;
a1=a*b;
a2=c*d;
	if(a1==a2)
    cout<<a1;

	else if(a1>a2)
	cout<<a1;
    else if(a2>a1)
    cout<<a2;

	return 0;
}



Measured memory_bytes: 3580
inp = int(input())
lis = [1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51]
print(lis[(inp-1) % 32])


Measured memory_bytes: 2940
#include <stdio.h>
#include <stdlib.h>

static int find_representative(int *a, int i) {
  if (i != a[i]) a[i] = find_representative(a, a[i]);
  return a[i];
}

int main(int argc, char **argv) {
  int n, q, i, c, x, y;
  int *a;

  scanf("%d %d", &n, &q);
  a = (int *) malloc(sizeof(int) * n);
  for (i = 0; i < n; ++i) a[i] = i;
  for (i = 0; i < q; ++i) {
    scanf("%d %d %d", &c, &x, &y);
    switch (c) {
      case 0:
        a[find_representative(a, x)] = find_representative(a, y);
        break;
      case 1:
        printf("%d\n", find_representative(a, x) == find_representative(a, y));
        break;
    }
  }
  free(a);
}


Measured memory_bytes: 2144
#include<bits/stdc++.h>
#define up(j,k,i) for(ld i=j;i<k;i+=0.5)
#define down(j,k,i) for(ld i=j;i>k;i-=0.5)
#define M 1000000007
#define pp(n) printf("%lld\n",ll(n))
#define ps(n) printf("%lld ",ll(n))
#define pd(x,y) printf("%lld %lld\n",ll(x),ll(y))
#define is(n) scanf("%lld",&n)
#define inf LLONG_MAX
#define id(n,m) scanf("%lld%lld",&n,&m)
#define it(n,m,k) scanf("%lld%lld%lld",&n,&m,&k)
#define pb push_back
#define F first
#define S second
#define pll pair<ll,ll> 
#define db cout<<"######\n"
#define null(a) memset(a,0,sizeof(a))
#define neg(a) memset(a,255,sizeof(a))
typedef long double ld;
typedef long long int ll;
using namespace std;
ll i,j,k,z,n,m,sum,ans,x,y,maxm=0,minm=inf; bool flag;
map<ld,ld> lim,a; ll t[20005];ld v[20005];
int main()
{
	is(n); ld ans=0;
	
	for(int i=1;i<=n;i++)
	cin>>t[i],t[i]+=t[i-1];
	
	for(int i=1;i<=n;i++)
	cin>>v[i];
	
	for(int i=1;i<=n;i++)
	{
		lim[t[i-1]]=min(lim[t[i-1]],v[i]);
	
		up(t[i-1]+0.5,t[i]+0.5,j)
		lim[j]=v[i];
		
		
	}
	
	up(0.5,t[n]+0.5,i)
	{
		a[i]=min(a[i-0.5]+0.5,lim[i]);
	}
	
	a[t[n]]=0;
	
	down(t[n]-0.5,0,i)
	{
		a[i]=min(a[i+0.5]+0.5,a[i]);
	}
	
	
	
	up(0.5,t[n]+0.5,i)
	{
		ans+=a[i]/2;
		
		//cout<<i<<" "<<a[i]<<" "<<ans<<endl;
	}
	
	printf("%0.9LF",ans);
		
		
}

Measured memory_bytes: 6528
/**
 * File    : C.cpp
 * Author  : Kazune Takahashi
 * Created : 1/20/2019, 9:05:18 PM
 * Powered by Visual Studio Code
 */

#include <iostream>
#include <iomanip>   // << fixed << setprecision(xxx)
#include <algorithm> // do { } while ( next_permutation(A, A+xxx) ) ;
#include <vector>
#include <string> // to_string(nnn) // substr(m, n) // stoi(nnn)
#include <complex>
#include <tuple>
#include <queue>
#include <stack>
#include <map> // if (M.find(key) != M.end()) { }
#include <set>
#include <functional>
#include <random> // auto rd = bind(uniform_int_distribution<int>(0, 9), mt19937(19920725));
#include <chrono> // std::chrono::system_clock::time_point start_time, end_time;
// start = std::chrono::system_clock::now();
// double elapsed = std::chrono::duration_cast<std::chrono::milliseconds>(end_time-start_time).count();
#include <cctype>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <cstdlib>
using namespace std;

#define DEBUG 0 // change 0 -> 1 if we need debug.

typedef long long ll;

// const int dx[4] = {1, 0, -1, 0};
// const int dy[4] = {0, 1, 0, -1};

// const int C = 1e6+10;
// const ll M = 1000000007;

int N;
int h[110];

int main()
{
  cin >> N;
  for (auto i = 0; i < N; i++)
  {
    cin >> h[i];
  }
  int ans = 0;
  for (auto i = 0; i < N; i++)
  {
    while (h[i] > 0)
    {
      for (auto j = i; j < N; j++)
      {
        if (h[j] > 0)
        {
          h[j]--;
        }
        else
        {
          break;
        }
      }
      ans++;
    }
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
const int N = 2e5 + 10;
#define fi first
#define se second
#define pb push_back
int n;
struct uzi{
  int a,b,i;
  bool operator <(const uzi &t)const{
    return a<t.a;
  }
}p[N];
int L[N];
LL f[N];
const LL mod=998244353;
int t[N];
void add(int p,int d){
  for(;p<N;p+=p&-p)t[p]=max(t[p],d);
}
int ge(int p,int d){
  int res=0;
  for(;p;p-=p&-p)res=max(res,t[p]);
  return res;
}
int main() {
  ios::sync_with_stdio(false);
  cin>>n;
  for(int i=1;i<=n;i++)cin>>p[i].a>>p[i].b,p[i].i=i;
  sort(p+1,p+1+n);
  auto get=[&](int x){
    int l=1,r=n,ans=1;
    while(l<=r){
      int mid=l+r>>1;
      if(p[mid].a<=x)ans=mid,l=mid+1;
      else r=mid-1;
    }
    return ans;
  };
  for(int i=n;i>=1;i--){
    L[i]=i;
    int x=get(p[i].a+p[i].b-1);
    L[i]=max(L[i],ge(x,1));
    add(i,L[i]);
  }
  f[1]=1;
  for(int i=1;i<=n;i++){
    f[i+1]+=f[i];//不开
    f[L[i]+1]+=f[i];//开
    f[i+1]%=mod;
    f[L[i]+1]%=mod;
  }
  cout<<f[n+1]<<endl;
  return 0;
}



Measured memory_bytes: 5760
#include <list>
#include <cstdio>
using namespace std;
int Q, a, e; char c[14]; list<int> l;
int main() {
	scanf("%d", &Q);
	for(int i = 0; i < Q; i++) {
		scanf("%s", c);
		switch(c[0] + c[6]) {
		case 105: scanf("%d", &a), l.push_front(a); break;
		case 170: l.pop_front(); break;
		case 176: l.pop_back(); break;
		default:
			scanf("%d", &a);
			for(list<int>::iterator it = l.begin(); it != l.end(); it++) {
				if(*it == a) {
					l.erase(it); break;
				}
			}
		}
	}
	for(list<int>::iterator it = l.begin(); it != l.end(); it++) printf(e++ ? " %d" : "%d", *it);
	printf("\n");
}

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

using namespace std;

int main(void){
	while(1){
		int n; cin >> n;
		if(!n) break;

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

		sort(a, a+n);

		int ans = 99999999;
		for(int i=0; i<n-1; i++){
			int tmp = a[i+1] - a[i];
			ans = min(ans, tmp);
		}

		cout << ans << endl;
	}

}


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

// iterator
#define REP(i,from, to) for(lli i=from;i<to;i++)
#define REPE(i,from, to) for(lli i=from;i<=to;i++)
#define REP_R(i,from, to) for(lli i=from;i>to;i--)
#define REPE_R(i,from, to) for(lli i=from;i>=to;i--)
#define REPIT(it,container) for(auto it = container.begin(); it != container.end(); it++)
#define REPIT_R(it,container) for(auto it = container.rbegin(); it != container.rend(); it++)

// input
#define cin1(x)             cin >> x
#define cin2(x, y)          cin >> x >> y
#define cin3(x, y, z)       cin >> x >> y >> z
#define ncin1(n, x)         REP(i, 0, n) { cin1(x[i]); }
#define ncin2(n, x, y)      REP(i, 0, n) { cin2(x[i], y[i]); }
#define ncin3(n, x, y, z)   REP(i, 0, n) { cin3(x[i], y[i], z[i]); }
#define ncinp(n, p)         REP(i, 0, n) { lli p1,p2; cin >> p1 >> p2; p[i] = P(p1, p2); }
#define ncin1_1(n, x)       REPE(i, 1, n) { cin1(x[i]); }
#define ncin2_1(n, x, y)    REPE(i, 1, n) { cin2(x[i], y[i]); }
#define ncin3_1(n, x, y, z) REPE(i, 1, n) { cin3(x[i], y[i], z[i]); }
#define ncinp_1(n, p)       REPE(i, 1, n) { lli p1,p2; cin >> p1 >> p2; p[i] = P(p1, p2); }

// output
#define cout1(x)         cout << #x << ": " << x << endl;
#define cout2(x, y)      cout << #x << ": " << x << ", " << #y << ": " << y << endl;
#define cout3(x, y, z)   cout << #x << ": " << x << ", " << #y << ": " << y << ", " << #z << ": " << z << endl;;
#define ncout1(n, x)     REP(i, 0, n) {cout << #x << "[" << i << "]: "<< x[i] << endl;}

#define coutp(p)         cout << #p << ":" <<  " (" << p.first << ", " << p.second << ")" << endl;

// sort
#define sort_r(x, y)        sort(x, y, greater<lli>()); // 降順(5,4,3,,,)

#define ARRAY_LENGTH(array) (sizeof(array) / sizeof(array[0]))

typedef long long int lli;
typedef pair<lli, lli> P;
typedef tuple<lli, lli, lli> tup;
typedef vector<lli> vlli;




int main() {
    lli n,m;
    cin2(n,m);
    lli x[n];
    lli y[n];
    lli z[n];
    ncin3(n,x,y,z);

    lli ans = 0;
    REP(i,0,8) {
        lli sum[n];
        REP(j,0,n) {
            lli cur_sum = 0;
            lli values[] = {x[j], y[j], z[j]};
            REP(k,0,3) {
                if (i & (1<<k)) {
                    cur_sum += values[k];
                }
                else {
                    cur_sum -= values[k];
                }
            }
            sum[j] = cur_sum;
        }
        sort_r(sum, sum+n);
        lli cur_ans = 0;
        REP(j,0,m) {
            cur_ans += sum[j];
        }
        ans = max(ans, cur_ans);
    }
    cout << ans << endl;

}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <string>
#include <cmath>
#include <set>
#include <algorithm>
#include <array>
#include <complex>
#include <string>
#include <utility>
#include <map>
#include <queue>
#include <list>
#include <functional>
#include <numeric>
#include <stack>
#include <tuple>

using namespace std;
int dx[4] = { -1,0,1,0 };
int dy[4] = { 0,1,0,-1 };
const int INF = 100000000;
const long long LINF = 1000000000000000000;
const long long MOD = 998244353;
const double EPS = 1e-6;
using pii = std::pair<int, int>;
using ll = long long;
using pLL = std::pair<ll, ll>;
#define SORT(v) std::sort(v.begin(), v.end())
#define RSORT(v) std::sort(v.rbegin(), v.rend())
constexpr auto PI = 3.14159265358979323846264338327950L;
int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N, M;
    cin >> N;
    string s;
    set<string> S;
    for (int i = 0; i < N; ++i) {
        cin >> s;
        S.insert(s);
    }
    cout << S.size() << endl;
    return 0;
}


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

int main() {
	int h=0,w=0;
    cin >> h >> w;
	vector<string> s(h);
  	for(int i=0;i<h;i++)cin >> s.at(i); 
  	for(int i=0;i<h;i++){
       for(int j=0;j<w;j++){
         int count = 0;
         if(s.at(i).at(j)== '#')cout<< '#';
         else{
           for(int k=i-1; k<i+2 ; k++){
           		for(int l=j-1; l<j+2 ; l++){
                  if(k!=-1 && k<h && l!=-1 && l<w){
                    if(s.at(k).at(l)== '#')count++;
                  }
                }
           	}
         cout<< count;	
         }
       }
       cout<< endl;
    }
}

Measured memory_bytes: 256
n,m = map(int,input().split())
k = []
l = []
ans = 0
for i in range(m):
    t = input().split()
    k.append(int(t[0]))
    l.append(list(map(int,t[1:])))
p = list(map(int,input().split()))
for i in range(2**n):
    sw = []
    for j in range(n):
        if (i>>j)&1:
            sw.append(True)
        else:
            sw.append(False)
    b = []
    for i in range(m):
        a = 0
        for si in l[i]:
            if sw[si-1]:
                a+=1
        b.append(a%2==p[i])
    ans+=all(b)
print(ans)

Measured memory_bytes: 3064
#include <iostream>
#include <vector>
#include <algorithm>
#include <numeric>
using namespace std;

int main() {
	int n,k;cin >> n >> k;
	vector<int>v(n);
	for (int i=0;i<n;++i) cin >>v[i];
	sort(v.begin(),v.end(),greater<int>());
	int sum = accumulate(v.begin(), v.begin()+k, 0);
	cout << sum << endl;
	return 0;
}

Measured memory_bytes: 256
H,W=map(  int,raw_input().split() )
A=[ list(raw_input())  for i in range(H)] 

for i in range(H):
	for j in range(W):
		if A[i][j]=="#":
			break
	else:
		for j in range(W):
			A[i][j]=0


for j in range(W):
	for i in range(H):
		if A[i][j]=="#":
			break
	else:
		for i in range(H):
			A[i][j]=0



for i in range(H):
	str=""
	for j in range(W):
		if A[i][j]!=0:
			str+=A[i][j]
	if len(str)!=0:
		print str


Measured memory_bytes: 32876
l,r=map(int,input().split())
m=2019
s=l%m
e=r%m
q=(r-l)//m
A=[0]*m
if s<=e:
    for i in range(m):
        if i<s or e<i:
            A[i]=q
        else:
            A[i]=q+1
else:
    for i in range(m):
        if i<=e or s<=i:
            A[i]=q+1
        else:
            A[i]=q
            
ans=m
for i in range(m):
    for j in range(m):
        if i==j:
            if A[i]>=2:
                ans=min(i*j%m,ans)
        else:
            if A[i]>0 and A[j]>0:
                ans=min(i*j%m,ans)
print(ans)

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

double dist[10][10];

int main(){
    ll N; cin >> N;
    pair<double,double> pos[10];
    rep(i,N){
        double x,y; cin >> x >> y;
        x--; y--;
        pos[i] = make_pair(x,y);
    }
    rep(i,N){
        rep(j,N){
            dist[i][j] = sqrt(pow(pos[i].first-pos[j].first,2) + pow(pos[i].second-pos[j].second,2));
        }
    }
    vector<ll> city(N);
    rep(i,N) city[i] = i;

    double len = 0, num = 0;
    do{
        rep(i,N-1){
            len += dist[city[i]][city[i+1]];
        }
        num++;
    }while(next_permutation(city.begin(),city.end()));
    cout << setprecision(7) << fixed;
    cout << len / num << endl;
}

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

int main(){
    int n, l;
    cin >> n >> l;
    int taste[n];
    for(int i = 0; i < n; i++){
        taste[i] = l+i;
    }
    sort(taste, taste+n);
    int ans = 0;
    if(taste[n-1] < 0){
        for(int i = 0; i < n-1; i++){
            ans += taste[i];
        }
    } else if(taste[0] > 0) {
        for(int i = 1; i < n; i++){
            ans += taste[i];
        }
    } else {
        for(int i = 0; i < n; i++){
            if(taste[i] != 0) ans += taste[i];
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
    public static void main(String [] args){
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        int K = sc.nextInt();
        int ans =1;
        for(int i=0;i<N;i++){
            if(ans*2 >= ans+K){
                ans = ans+K;
            }else{
                ans =ans*2;
            }
        }
        System.out.println(ans);
    }
}

Measured memory_bytes: 23764
while True:
    A,op,B=input().split()
    A=int(A)
    B=int(B)
    
    if op == "+":
        print(A+B)
    elif op == "-":
        print(A-B)
    elif op == "*":
        print(A*B)
    elif op == "/":
        print(A//B)
    else:
        break



Measured memory_bytes: 5596
using System.Linq;
using System;

public class hello
{
    public static void Main()
    {
        var n = int.Parse(Console.ReadLine().Trim());
        for (int i = 0; i < n; i++)
        {
            string[] line = Console.ReadLine().Trim().Split(' ');
            var p = Array.ConvertAll(line, int.Parse);
            Console.WriteLine(GetFormation(p));
        }
    }
    public static int GetFormation(int[] p)
    {
        var count = 0;
        while (true)
        {
            if (p.Min() == 0) break;
            p[0] -= 1; p[1] -= 1; p[2] -= 1;
            count++;
        }
        while (true)
        {
            if (p[0] < 2 | p[1] < 1) break;
            p[0] -= 2; p[1] -= 1;
            count++;
        }
        while (true)
        {
            if (p[0] < 3) break;
            p[0] -= 3;
            count++;
        }
        return count;
    }
}

Measured memory_bytes: 9748
def s():
  from sys import stdin
  read=stdin.buffer.readline
  n=int(read())
  l=list(map(int,read().split()))
  f=l[0]
  mod=10**9+7
  def gcd(s,d):
    s,d=max(s,d),min(s,d)
    while  d:
      s,d=d,s%d
    return s
  for i in l:
    f=i*f//gcd(i,f)
  ans=0
  for iu in l:
    ans+=(f*pow(iu,mod-2,mod))%mod
    ans%=mod
  print(ans)
  
if __name__=="__main__":s()


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

#define rep(i, N) for (int i = 0; i < (int)N; i++)
using namespace std;
typedef long long ll;
const ll LLINF = 9223372036854775807;
const int INF = pow(2,29);
const ll MOD = 1000000007;
const int L_MAX = 100010;

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

  ll pow2[L_MAX], pow3[L_MAX] = {};
  pow2[0] = 1; pow3[0] = 1;
  rep(i, L_MAX-1) {
    pow2[i+1] = (pow2[i]*2)%MOD;
    pow3[i+1] = (pow3[i]*3)%MOD;
  }

  ll count = 0, result = 0, l = L.length();
  rep(i,l) {
    if (i!=l-1) {
      if (L[i] =='1') {
        result += pow2[count] * pow3[l-i-1];
        result %= MOD;
        count++;
      }
    }
    else {
      result += pow2[count];
      if (L[i]=='1') result += pow2[count+1];
      result %= MOD;
    }
  }

  cout << result << endl;
  return 0;
}

Measured memory_bytes: 2048
from collections import defaultdict
d = defaultdict(int)

N, K = map(int, input().split())
A = list(map(int, input().split()))

inner = 0
for i in range(N):
  d[A[i]] += 1
  for j in range(i+1, N):
    if A[i] > A[j]:
      inner += 1
inner *= K

d = sorted(d.items())
outer = 0
cnt = d[0][1]
for k, v in d[1:]:
  outer += cnt * v
  cnt += v
outer *= K*(K-1)//2

print((inner + outer)%(10**9+7))

Measured memory_bytes: 9628
# include <bits/stdc++.h>
#define INF 1e9
using namespace std;

int main(){

  int N;
  cin >> N;
  int H[N];
  for(int i=0; i<N; i++){
    cin >> H[i];
  }
  int ans = 0;
  int ref = 0;
  for(int i = 0; i < N; i++){
    if(H[i] >= ref){
      ans++;
    }
    ref = max(ref, H[i]);
  }

  cout << ans << endl;

}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#define _USE_MATH_DEFINES
#include <math.h>
#include <iomanip>
#include <stdio.h>
#include <numeric>
#include <cmath>
#include <limits>
#include <bitset> 
#include <iterator> 
#include <map>
#include <queue>
#include <set>
#include<deque>
#include <regex>
#include <list> 
#define rep(i,n) for(ll i=0;i<(n); ++i)
#define per(i,n) for(ll i=n-1;i>=0; --i)
#define all(x) (x).begin(),(x).end()
#define _GLIBCXX_DEBUG
using namespace std;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
const long long INF = 1LL << 60;
typedef long long ll;
const ll MOD = 1000000007;
ll gcd(ll a, ll b) {
	if (b == 0) return a;
	return gcd(b, a % b);
}
ll getDigit(ll n) {
	ll cnt = 0;
	while (n != 0) {
		n /= 10;
		cnt++;
	}
	return cnt;
}
int main() {
	ll n,cnt=0;
	cin >> n;
	vector<ll>a(n);
	rep(i, n)cin >> a[i];
	map<string, ll>mp;
	rep(i, n) {
		if (1 <= a[i] && a[i] <= 399) mp["gray"]++;
		else if (400 <= a[i] && a[i] <= 799) mp["brown"]++;
		else if (800 <= a[i] && a[i] <= 1199) mp["green"]++;
		else if (1200 <= a[i] && a[i] <= 1599) mp["aqua"]++;
		else if (1600 <= a[i] && a[i] <= 1999) mp["blue"]++;
		else if (2000 <= a[i] && a[i] <= 2399) mp["yellow"]++;
		else if (2400 <= a[i] && a[i] <= 2799) mp["orange"]++;
		else if (2800 <= a[i] && a[i] <= 3199) mp["red"]++;
		else cnt++;
	}
	cout << (mp.size() == 0 ? 1 : mp.size())  << " "  << mp.size()+cnt << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll int64_t
#define f first
#define sec second
#define pb push_back
#define pf push_front
#define po pop_back
#define fast ios_base::sync_with_stdio(false)
#define vi vector<ll>
#define vii vector< pair<ll,ll> >
#define pi pair<ll,ll>
#define map map<ll,ll>
#define set set<ll>
#define tostr to_string
#define toint stoi
#define gcd __gcd


int main()
{
    fast;
    ll n,i;
    cin>>n;
    ll a[n];
    for(i=0;i<n;i++)
        cin>>a[i];

    ll pre=0;
    for(i=0;i<n;i++)
    {
       if(a[i]-pre==1)
       pre++;
    }
    if(pre==0)
        cout<<-1<<endl;
    else
    cout<<n-pre<<endl;

}


Measured memory_bytes: 1792
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define LLMAX (1ll << 60) - 1
#define INTMAX (1 << 30) - 1
#define MOD 1000000007 
#define NMAX 1000*100+1

#define numberOfSetBits(S) __builtin_popcount(S) // __builtin_popcountl(S) __builtin_popcountll(S)
#define MSET(x,y) memset(x,y,sizeof(x))
#define gcd(a,b) __gcd(a,b)
#define all(x)  x.begin(),x.end()
#define isOn(S, j) (S & (1 << j))
#define endl '\n'
#define setBit(S, j) (S |= (1 << j))
#define clearBit(S, j) (S &= ~(1 << j))
#define toggleBit(S, j) (S ^= (1 << j))
#define print(x)    for(auto it:x) cout<<it<<' '; cout<<endl;
#define printii(x)  for(auto it:x) cout<<it.F<<' '<<it.S<<'\t';  cout<<endl;
#define in(x,n)   for(int e=0;e<n;e++){ll y;cin>>y;x.pb(y);}

#define vi vector<ll>
#define vvi vector<vi>
#define ii pair<ll,ll>
#define pll pair<ll,ll>
#define vii vector<ii>
#define vvii vector<vii>
#define viii vector<pair<ii,ll>>
#define pb push_back
#define F first
#define S second
#define mp make_pair
#define mc(a,b,c) mp(mp(a,b),c)
ll c[13],a[13][13];
vi currskill;
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    ll n,x,t,m,y,z;
    cin>>n>>m>>x;
    for(int i=0;i<n;i++){
        cin>>c[i];
        for(int j=0;j<m;j++){
            cin>>a[i][j];
        }
    }
    ll ans = LLMAX;
    for(int mask=0;mask<(1ll<<n);mask++){
        currskill.assign(m,0);
        ll cost = 0;
        for(int j=0;j<n;j++){
            if((mask>>j)&1){
                cost+=c[j];
                for(int i=0;i<m;i++){
                    currskill[i]+=a[j][i];
                }
            }
        }
        bool ok = true;
        for(int i=0;i<m;i++){
            if(currskill[i]<x)
                ok = false;
        }
        if(ok){
            ans = min(ans,cost);
        }
    }
    if(ans==LLMAX){
        cout<<-1;
    }
    else{
        cout<<ans;
    }
    
    
    

    return 0;
}

Measured memory_bytes: 3656
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <tuple>

using namespace std;

void c()
{
    int n;
    cin >> n;
    vector<vector<int>> f(n, vector<int>(10));
    for(int i = 0; i < n; i++)
    {
        for(int j = 0; j < 10; j++)
        {
            cin >> f[i][j];
        }
    }
    vector<vector<int>> p(n, vector<int>(11));
    for(int i = 0; i < n; i++)
    {
        for(int j = 0; j < 11; j++)
        {
            cin >> p[i][j];
        }
    }
    vector<int> pattern = {1,1,1,1,1,1,1,1,1,1,0,0,0,0,0,0,0,0,0,0};
    sort(pattern.begin(), pattern.end());
    long long int benefit = -10e9;
    do{
        int check = 0;
        for(int i = 0; i < 10; i++)
        {
            check += pattern[i];
        }
        if(check == 0) continue;
        long long int temp_benefit = 0;
        for(int i = 0; i < n; i++)
        {
            int count = 0;
            for(int j = 0; j < 10; j++)
            {
                if(pattern[j] == 1 && f[i][j] == 1)
                {
                    count++;
                }
            }
            temp_benefit += p[i][count];
        }
        if(temp_benefit > benefit) {
            benefit = temp_benefit;
        }
    }while (next_permutation(pattern.begin(), pattern.end()));
    cout << benefit << endl;
}

void d()
{
    int n, c;
    cin >> n >> c;
    vector<tuple<int, int, int, int>> shows(n);
    for(int i = 0; i < n; i++)
    {
        int s, t, ci;
        cin >> s >> t >> ci;
        shows[i] = make_tuple(s * 10, t * 10, ci, i);
    }
    sort(shows.begin(), shows.end());
    vector<bool> flag(n, false);
    int rest = n;
    int count = 0;
    while(rest > 0)
    {
        count++;
        int last = -1;
        int last_channel = get<2>(shows[0]);
        for(auto show : shows)
        {
            if(flag[get<3>(show)]) continue;
            if(last_channel == get<2>(show))
            {
                rest--;
                last = get<1>(show);
                last_channel = get<2>(show);
                flag[get<3>(show)] = true;
            }else{
                if(get<0>(show) - 5 >= last)
                {
                    rest--;
                    last = get<1>(show);
                    last_channel = get<2>(show);
                    flag[get<3>(show)] = true;
                }else{
                }
            }
        }
    }
    cout << count << endl;
}

int main() {
    d();
    return 0;
}


Measured memory_bytes: 1792
import sys

import numba as nb
import numpy as np

input = sys.stdin.readline


@nb.njit("i8(i8[:],i8)", cache=True)
def binary_search(a, key):
    """Meguru type binary search"""
    ng = -1
    ok = len(a)

    def is_ok(a, key, idx):
        if key <= a[idx]:
            return True
        else:
            return False

    while (abs(ok - ng) > 1):
        mid = (ok + ng) // 2
        if is_ok(a, key, mid):
            ok = mid
        else:
            ng = mid

    return ok


@nb.njit("i8[:](i8,i8[:],i8[:],i8[:])", cache=True)
def solve(Q, S, T, X):
    ans = np.zeros(shape=Q, dtype=np.int64)
    INF = 10 ** 11
    for q, x in enumerate(X):
        min_dist = INF
        i_s = binary_search(S, x)
        i_t = binary_search(T, x)
        for s in (S[i_s - 1], S[i_s]):
            for t in (T[i_t - 1], T[i_t]):
                dist_s2t = abs(x - s) + abs(s - t)
                dist_t2s = abs(x - t) + abs(t - s)
                min_dist = min(min_dist, dist_s2t, dist_t2s)
        ans[q] = min_dist
    return ans


def main():
    A, B, Q = map(int, input().split())
    S = np.zeros(shape=(A + 2), dtype=np.int64)
    T = np.zeros(shape=(B + 2), dtype=np.int64)
    X = np.zeros(shape=Q, dtype=np.int64)
    for i in range(1, A + 1):
        S[i] = int(input())
    for i in range(1, B + 1):
        T[i] = int(input())
    for i in range(Q):
        X[i] = int(input())

    S[0] = T[0] = -10 ** 11
    S[-1] = T[-1] = 10 ** 11

    ans = solve(Q, S, T, X)
    print("\n".join(map(str, ans)))


if __name__ == "__main__":
    main()


Measured memory_bytes: 118260
#include <bits/stdc++.h>
#define rep(i, a, n) for(int i = a; i < n; i++)
#define int long long
using namespace std;
typedef pair<int, int> P;
const int mod = 998244353;
const int MAX = 1000000;

long long mod_pow(long long x, long long n){
    if(n == 0) return 1;
    long long res = mod_pow(x*x % mod, n / 2);
    if(n & 1) res = res*x % mod;
    return res;
}

int sum[MAX + 1];
int sum2[MAX + 1];

signed main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    int n;
    cin >> n;
    rep(i, 0, n){
        int in;
        cin >> in;
        (sum[in] += in) %= mod;
        (sum2[in] += in * in) %= mod;
    }
    for(int i = 1; i <= MAX; i++){
        for(int j = 2 * i; j <= MAX; j += i){
            (sum[i] += sum[j]) %= mod;
            (sum2[i] += sum2[j]) %= mod;
        }
    }
    for(int i = 1; i <= MAX; i++){
        sum[i] = sum[i] * sum[i] % mod;
    }
    for(int i = MAX; i >= 1; i--){
        for(int j = 2 * i; j <= MAX; j += i){
            (sum[i] = sum[i] - sum[j] + mod) %= mod;
            (sum2[i] = sum2[i] - sum2[j] + mod) %= mod;
        }
    }
    int ans = 0;
    for(int i = 1; i <= MAX; i++){
        int tmp = (sum[i] - sum2[i] + mod) % mod;
        tmp = tmp * mod_pow(2, mod - 2) % mod;
        tmp = tmp * mod_pow(i, mod - 2) % mod;
        ans += tmp;
        ans %= mod;
    }
    cout << ans << endl;
}

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


class Template
{
	static Scanner sc;

	public static void Main(string[] args)
	{
		sc = new Scanner();
		while (true)
		{
			string s = sc.next();
			if (s == null) break;
			int jcnt = 0, icnt = 0;
			bool jflag = false, iflag = false, joflag = false, ioflag = false;
			for (int i = 0; i < s.Length; i++)
			{
				if (s[i] == 'J')
				{
					jflag = true;
					if (joflag) joflag = false;
					if (iflag) iflag = false;
					if (ioflag) ioflag = false;
				}
				else if (s[i] == 'I')
				{
					iflag = true;
					if (jflag) jflag = false;
					if (ioflag)
					{
						icnt++; ioflag = false;
					}
					if (joflag)
					{
						jcnt++; joflag = false;
					}

				}
				else if (s[i] == 'O')
				{
					if (ioflag)
					{
						ioflag = false; continue;
					}
					if (joflag)
					{
						joflag = false; continue;
					}
					if (jflag)
					{
						joflag = true; jflag = false;
					}
					if (iflag)
					{
						ioflag = true; iflag = false;
					}
				}
				else
				{
					iflag = false;
					jflag = false;
					ioflag = false;
					joflag = false;
				}
			}
			Console.WriteLine(jcnt);
			Console.WriteLine(icnt);
		}
	}
}

public class Scanner
{
	public Scanner() { }
	public string next()
	{
		return Console.ReadLine();
	}
	public int nextInt()
	{
		return int.Parse(next());
	}
	public double nextDouble()
	{
		return double.Parse(next());
	}
	public long nextLong()
	{
		return long.Parse(next());
	}
	public string[] nextArray()
	{
		return next().Split(' ');
	}
	public int[] nextIntArray()
	{
		return Array.ConvertAll(nextArray(), e => int.Parse(e));
	}
	public long[] nextLongArray()
	{
		return Array.ConvertAll(nextArray(), e => long.Parse(e));
	}
	public double[] nextDoubleArray()
	{
		return Array.ConvertAll(nextArray(), e => double.Parse(e));
	}
}

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

const int Maxn = 1005;
const int Inf = 1000000007;

int D, G;
int p[Maxn], d[Maxn];
int res = Inf;

int main()
{
	scanf("%d %d", &D, &G);
	for (int i = 0; i < D; i++)
		scanf("%d %d", &p[i], &d[i]);
	for (int i = 0; i < 1 << D; i++) {
		int score = 0, solved = 0;
		for (int j = 0; j < D; j++)
			if (i & 1 << j) {
				score += p[j] * (j + 1) * 100 + d[j];
				solved += p[j];
			}
		for (int j = D - 1; j >= 0; j--)
			if (!(i & 1 << j) && score < G) {
				int tk = min((G - 1 - score) / ((j + 1) * 100) + 1, p[j]);
				score += tk * (j + 1) * 100; solved += tk;
			}
		res = min(res, solved);
	}
	printf("%d\n", res);
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main() {
  int a, b;
  cin >> a >> b;
  int ans = 0;
  ans += max(a, b);
  if(a <= b) b--;
  else a--;
  ans += max(a, b);
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256
a,b=gets.split.map(&:to_i)

if a==0 || b==0
   puts "Zero" 
elsif a<0 && 0<b
    puts "Zero"
elsif 0<a
    puts "Positive"
elsif (b-a)%2==1
    puts "Positive"
else
    puts "Negative"
end

Measured memory_bytes: 1788
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>
#include <climits>
#include <cstring>
#include <cassert>


using namespace std;
#define SZ(x) (int)(x.size())
#define REP(i, n) for(int i=0;i<n;++i)
#define FOR(i, a, b) for(int i=a;i<b;++i)
#define RREP(i, n) for(int i=n-1;i>=0;--i)
#define RFOR(i, a, b) for(int i=b-1;i>=a;--i)

#define all(x) begin(x),end(x)
#define dump(x) cerr<<#x<<" = "<<(x)<<endl
#define debug(x) cerr<<#x<<" = "<<(x)<<" (L"<<__LINE__<<")"<< endl;

using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vll = vector<ll>;
using vvll = vector<vll>;
using P = pair<int, int>;
const double eps = 1e-8;
const ll MOD = 1000000007;
const int INF = INT_MAX / 2;
const ll LINF = LLONG_MAX / 2;

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;
}


template<typename T1, typename T2>
ostream &operator<<(ostream &os, const pair<T1, T2> p) {
    os << p.first << ":" << p.second;
    return os;
}

template<class T>
ostream &operator<<(ostream &os, const vector<T> &v) {
    os << "[";
    REP(i, SZ(v)) {
        if (i) os << ", ";
        os << v[i];
    }
    return os << "]";
}

template<class T1, class T2>
ostream &operator<<(ostream &os, const map<T1, T2> &mp) {
    os << "[";
    for (auto it = mp.begin(); it != mp.end(); ++it) {
        if (it != mp.begin()) {
            os << ", ";
        }
        os << *it;
    }
    return os << "]";
}

// edit

void solve() {
    int N;
    cin >> N;

    ll ans = 0;
    for (int i = 1; i <= N; ++i) {
        ll tmp = 1ll * i * (i + 1) / 2;
        ans += tmp;
    }


    ll dec = 0;
    REP(i, N - 1) {
        ll x, y;
        cin >> x >> y;
        if (x > y) swap(x, y);

        ll tmp = x * (N - y + 1);
        dec += tmp;
    }

    ans -= dec;

    cout << ans << endl;


}


int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(10);
//    std::ifstream in("input.txt");
//    std::cin.rdbuf(in.rdbuf());

    solve();


    return 0;
}


Measured memory_bytes: 3168
#include<bits/stdc++.h>
 
typedef long  long ll;
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define endl "\n"
#define pb push_back
#define pl push_right
 
using namespace std;
 
		 
int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(nullptr);
	cout.precision(10);
	cout<<fixed;
	
		ll n, m;
    cin >> n >> m;
   
  ll p=n*m;
  cout<<p<<endl;
	
return 0;
}



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

int main()
{
    string o, e;
    cin >> o >> e;
    
    string ans = "";
    
    for(int i = 0; i < e.size(); ++i)
    {
        ans.push_back(o[i]);
        ans.push_back(e[i]);
    }
    
    if(o.size() - e.size())
    {
        ans.push_back(o.back());
    }
    
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include "bits/stdc++.h"
#define rep(i,n) for(int i = 0; i < (n); ++i)
using namespace std;
typedef long long int ll;
typedef pair<ll, int> P;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n, q;
    cin >> n >> q;
    string s;
    cin >> s;
    s = "!" + s + "!";
    vector<char> t(q), d(q);
    rep(i,q) cin >> t[i] >> d[i];
    int ok = 0, ng = n+1;
    while(ng - ok > 1){
        int mid = (ok + ng) / 2;
        int cur = mid;
        rep(i,q){
            if(s[cur] == t[i]){
                if(d[i] == 'L') --cur;
                else ++cur;
            }
        }
        if(cur == 0) ok = mid;
        else ng = mid;
    }
    int ans = ok;
    ok = n+1, ng = 0;
    while(ok - ng > 1){
        int mid = (ok + ng) / 2;
        int cur = mid;
        rep(i,q){
            if(s[cur] == t[i]){
                if(d[i] == 'L') --cur;
                else ++cur;
            }
        }
        if(cur == n+1) ok = mid;
        else ng = mid;
    }
    ans += n + 1 - ok;
    ans = n - ans;
    cout << ans << endl;
    return 0;
}


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

int main() {
  int n,x,t;
  cin >> n >> x >> t;
  
  for(int i=0;i<n;i++){
    if( i*x < n && n <= (i+1)*x )
      cout << (i+1)*t <<endl;
      
  }
    
}

Measured memory_bytes: 3632
import java.util.Scanner;

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

		Scanner sc = new Scanner(System.in);

        while(true) {
            int m = sc.nextInt();
            int f = sc.nextInt();
            int r = sc.nextInt();
            if(m == -1 && f == -1 && r == -1) {
            	break;
            }
            if(m == -1 || f == -1) {
                System.out.println("F");
                continue;
            }
            if(m + f >= 80) {
                System.out.println("A");
                continue;
            }else if(m + f >= 65) {
                System.out.println("B");
            }else if(m + f >= 50) {
                System.out.println("C");
            }else if(m +f < 30) {
                System.out.println("F");
            }else if (r >= 50){
                System.out.println("C");
            }else  {
            	System.out.println("D");
            }

        }

    }
}


Measured memory_bytes: 26520
def main():
  import sys
  input = sys.stdin.readline
  n,m=map(int,input().split())
  ac,wa,l=0,0,[0]*n
  for _ in [0]*m:
    p,s=input().split()
    if type(l[int(p)-1])==int:
      if s=='AC':
        ac+=1
        wa+= l[int(p)-1]
        l[int(p)-1]=str(l[int(p)-1])
      else:
        l[int(p)-1]+=1
  print(ac,wa)
  
if __name__ == '__main__':
    main()

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

int main() {
	int n, k, a, ball[200000] = { 0 }, ans = 0;
	cin >> n >> k;
	rep(i, n) {
		cin >> a;
		ball[a]++;
	}

	sort(ball, ball + n, greater<>());

	rep(i, k) {
		ans += ball[i];
	}

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


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

int main() {
	int x, t;
	cin >> x >> t;
	if (x >= t) {
		cout << x - t << endl;
	}
	else {
		cout << "0" << endl;
	}



	return 0;
}

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

int main() { 
   int A,B,C,X,Y ;
  cin >>A>>B>>C>>X>>Y ;
  if ( A+B >= 2*C) {
    cout << min(A*(X-(min(X,Y))) +B*(Y-(min(X,Y)))+C*(min(X,Y)*2),C*2*max(X,Y)) <<endl;
   }else{
   
   cout << A*X+B*Y << endl;
}
}


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

typedef int64_t Int;
#define fi first
#define se second
#define all(x) (x).begin(), (x).end()
 
const double EPS = 1e-10;
const Int INF = 1e18;
const int inf = 1e9;
const Int mod = 1e9+7;

bool print_space_enable = false;
void print() { 
    cout << endl; 
    print_space_enable = false;
}

template <class Head, class... Tail>
void print(Head&& head, Tail&&... tail) {
    if (print_space_enable) cout << " ";
    cout << fixed << setprecision(15) << head;
    print_space_enable = true;
    print(std::forward<Tail>(tail)...);
}

template<typename T>
void print(vector<T> v) {
    for (size_t i = 0; i < v.size(); i++) {
        if (i > 0) std::cout << " ";
        std::cout << v[i];
    }
    std::cout << std::endl;
}

int main() {
    Int a, b;
    cin >> a >> b;
    Int res = (b - 1) / (a - 1);
    if ((b - 1) % (a - 1) != 0) res++;
    print(res);
    return 0;
}

Measured memory_bytes: 256
a = [input(),input(),input()]
l = [len(a[0]),len(a[1]),len(a[2])]
ans = l[0]+l[1]+l[2]

def check(a0, l0, a1, l1, delta):
    # stt1 >= stt0, stt1 - stt0 >=l0 must return True
    i = delta
    j = 0
    while (i<l0) and (j<l1):
        if a0[i] != a1[j]:
            if a0[i] != '?' and a1[j] != '?':
                return False
        i += 1
        j += 1
    return True

memoLen = ans-min(l[0],l[1],l[2])+1
memo = [[[1]*memoLen for i in range(3)] for j in range(3)]
comb2 = [(0,1),(1,0),(1,2),(2,1),(0,2),(2,0)]
for x, y in comb2:
    me = memo[x][y]
    a0, a1 = a[x],a[y]
    l0, l1 = l[x],l[y]
    for delta in range(0,l0):
        if not check(a0,l0, a1,l1, delta):
            me[delta] = 0

comb = [(0,1,2),(0,2,1),(1,0,2),(1,2,0),(2,1,0),(2,0,1)]
for i,j,k in comb:
    l0, l1, l2 = l[i],l[j],l[k]
    for stt1 in range(0,l0+1):
        if memo[i][j][stt1]:
            l01 = max(l0,stt1+l1)
            for stt2 in range(stt1,l01+1):
                if memo[j][k][stt2-stt1] and memo[i][k][stt2]:
                    l012 = max(l01,stt2+l2)
                    ans = min(ans,l012)
print(ans)

Measured memory_bytes: 50268
#include<stdio.h>
int main(void) {
    int n,x;
    scanf("%d %d",&n, &x);
    int i,j;
    int seq[n];
    for(i=0;i<n;i++)
        scanf("%d",&seq[i]);
    int count = 0;
    int pos = 0;
    while(count<=n && pos<=x) {
        pos = pos+seq[count];
        count++;
    }
    printf("%d\n",count);


}

Measured memory_bytes: 128
#include <iostream>
#include <algorithm>
#include <map>
#include <tuple>
using namespace std;

const int mod = 1000000007;
map<int,int> DP[2][10001];//[i][w][e]??????w??§???????????§???????????£????????????????°???????e

int main(){
    int N,W;
    cin>>N>>W;
    DP[0][0][W+1]=1;
    for(int i=0;i<N;i++){
        int w;
        cin>>w;
        for(int j=0;j<=W;j++) DP[i&1^1][j].clear();
        for(int j=0;j<=W;j++){
            for(auto p:DP[i&1][j]){
                int e,cnt;
                tie(e,cnt)=p;
                if(j+w<=W) DP[i&1^1][j+w][e]=(DP[i&1^1][j+w][e]+cnt)%mod;
                e=min(w,e);
                DP[i&1^1][j][e]=(DP[i&1^1][j][e]+cnt)%mod;
            }
        }
    }
    int ans=0;
    for(int j=0;j<=W;j++){
        for(auto p:DP[N&1][j]){
            int e,cnt;
            tie(e,cnt)=p;
            if(e+j>W) ans=(ans+cnt)%mod;
        }
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 11360
s=input().split()
n=int(s[0])
x=int(s[1])
y=int(s[2])
current=0
list=[0]*(n-1)
for i in range(n) :
  for j in range(i+1,n) :
    k=min(j-i,abs(x-i-1)+1+abs(y-j-1))
    
    list[k-1]+=1
for youso in list :
  print(youso)

Measured memory_bytes: 46556
#include<bits/stdc++.h>
#define int long long int
#define endl "\n"
#define pb push_back
#define arrinp(v) for(auto &i:v) cin>>i;
#define arrout(v) for(auto &i:v) cout<<i<<" ";
#define newline cout<<endl;
using namespace std;
const int mod=1e9+7;
int power(int x, int y) 
{ 
    int res = 1;     // Initialize result 
    for(int i=0;i<y;i++){
    	res=res*x%mod;
    }
    return res; 
}
signed main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
#ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#endif
    int t=1;
    // cin >> t;
    while (t--) {
        int n;
        cin>>n;
        if(n==3){
        	cout<<1<<endl;
        	return 0;
        }
        if(n<3){
        	cout<<0<<endl;
        	return 0;
        }

        int a[n+1]={0};
        int res=1;
        for(int i=3;i<=n;i++){
        	res+=a[i-3];
        	res%=mod;
        	a[i]=res;
        }
        cout<<a[n]<<endl;
    }
    return 0;
}

Measured memory_bytes: 3648
use std::io::*;
use std::str::FromStr;

#[allow(dead_code)]
fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let stdin = stdin.lock();
    let token: String = stdin
        .bytes()
        .map(|c| c.expect("failed to read char") as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().expect("failed to parse token")
}

fn main() {
    let a = read::<usize>();
    let b = read::<usize>();
    let c = read::<usize>();
    println!("{}", [a + b, b + c, c + a].iter().min().unwrap());
}


Measured memory_bytes: 4352
import sys
sys.setrecursionlimit(1000000)
import collections
def solve(N, A):
    c = collections.Counter(A)
    ans = []
    for i in range(N):
        if (i+1) not in c:
            ans.append("0")
        else:
            ans.append(str(c[i+1]))
    return "\n".join(ans)

if __name__ == "__main__":
    N = int(input())
    A = list(map(int, input().split(" ")))

    print(solve(N, A))


Measured memory_bytes: 42848
#!/usr/bin/env python3

import sys


def LI():
    return list(map(int, sys.stdin.buffer.readline().split()))


def I():
    return int(sys.stdin.buffer.readline())


def LS():
    return sys.stdin.buffer.readline().rstrip().decode('utf-8').split()


def S():
    return sys.stdin.buffer.readline().rstrip().decode('utf-8')


def IR(n):
    return [I() for i in range(n)]


def LIR(n):
    return [LI() for i in range(n)]


def SR(n):
    return [S() for i in range(n)]


def LSR(n):
    return [LS() for i in range(n)]


def SRL(n):
    return [list(S()) for i in range(n)]


def MSRL(n):
    return [[int(j) for j in list(S())] for i in range(n)]

# ----------------------------------------------------------------


def main():

    a, b, c = LI()

    if 4 * a * b < (c - a - b)**2 and (c - a - b) > 0:
        print("Yes")
    else:
        print("No")


main()


Measured memory_bytes: 3188
#include<bits/stdc++.h>
#define int long long
using namespace std;
signed main(){
  int n,k,a; 
  int l=0,r;
  int b=0;
  cin>>n>>k>>a;
  if(k>a||k-a>n) cout<<"0";
  else{
    
    l=(a*(n-1)+k)-(k*(n-1)+a-1);
      if(l>0) cout<<l;
  else cout<<"0";
  }

  cout<<"\n";
  }


Measured memory_bytes: 256
import Data.Char
import qualified Data.Vector as V
import qualified Data.Vector.Mutable as MV


main = do
  dataSet <- fmap lines getContents
  let strings = map (\(s,hs) -> shuffleLoop hs (V.fromList s)) . disassembe $ dataSet
  mapM_ (putStrLn . V.toList) strings
  -- putStrLn ""

shuffleLoop [] vector = vector
shuffleLoop (h:hs) vector = shuffleLoop hs (shuffle h vector)

shuffle h vector = newVec
  where
    (fstVec,sndVec) = V.splitAt h vector
    newVec = sndVec V.++ fstVec

disassembe list = loop list []
  where
    loop ["-"] stack = stack
    loop (s:m:xs) stack = loop ys (stack ++ [(s,map read hs :: [Int])])
      where
        (hs,ys) = splitAt (read m :: Int) xs



Measured memory_bytes: 4800