akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i = 0; i < (n);i++)
#define sz(x) int(x.size())
typedef long long ll;
typedef pair<int,int> P;

int main(){ 
  int n, a, b;
  cin >> n >> a >> b;
  vector<int> h(n);
  rep(i,n) cin >> h[i];

  auto ok = [&](ll m) {
    ll cnt = 0;
    for (int i = 0; i < n; i++) {
      if (h[i] > b * m) {
        cnt += ((h[i] - b * m + (a-b-1))/(a-b));
      }
    }
    return cnt > m;
  };

  ll l = 0, r = 1e9;
  while (r - l > 1) {
    int m = (r + l) / 2;
    if (ok(m)) l = m;
    else r = m;
  }
  cout << r << endl;
  return 0;
} 

Measured memory_bytes: 640
//QWsin
#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
#define rep(i,x,y) for(int i=x;i<=y;++i)
#define out(i,u) for(int i=first[u];i!=-1;i=nxt[i])
#define repvc(i,vc) for(int i=0,Sz=vc.size();i<Sz;++i)
using namespace std;
inline int read()
{
	char ch=getchar();int ret=0,f=1;
	while(ch<'0' || ch>'9') {if(ch=='-')f=-1;ch=getchar();}
	for(;ch>='0' && ch<='9';ch=getchar()) ret=ret*10+ch-'0';
	return ret*f;
}

inline void print(string name,int *arr,int len){
	rep(i,1,len) printf("%s[%d]=%d\n",name.c_str(),i,arr[i]);puts("");
}
inline void print(string name,int a){
	printf("%s=%d\n",name.c_str(),a);puts("");
}

typedef long long ll;
const int INF=1<<30;

const int maxn=100000+10;
ll a[maxn],b[maxn];
int id[maxn];

int cmp(int x,int y){return a[x]+b[x]>a[y]+b[y];}

int main()
{
	int n;cin>>n;
	rep(i,1,n) scanf("%lld%lld",a+i,b+i),id[i]=i;
	
	sort(id+1,id+n+1,cmp);
	
	ll sum=0;
	for(int i=1;i<=n;++i)
	{
		if(!(i&1)) sum-=b[id[i]];
		else sum+=a[id[i]];
	}
	cout<<sum<<endl;
	return 0;
}




Measured memory_bytes: 2176
import itertools

N = int(input())
n = len(str(N))

def count_753(n):
    if n == 3:
        return (6, 18, 3)
    else:
        num_753 = count_753(n-1)[0] * 3 + count_753(n-1)[1]
        num_75 = count_753(n-1)[1] * 2 + count_753(n-1)[2] * 2
        return (num_753, num_75, 3)

if n <= 2:
    print(0)
else:
    count = 0
    for i in range(3, n+1):
        count += count_753(i)[0]
    #print('count :', count)

    for i in itertools.product(['7', '5', '3'], repeat=n):
        if len(set(i)) <= 2:
            continue
        s = 0
        for j,k in zip(range(n), reversed(range(n))):
            s += int(i[j]) * (10**k)
        if s > N:
            count -= 1
    
    print(count)

Measured memory_bytes: 3064
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <cstdio>
#include <cmath>
#include <vector>
#include <map>
#include <set>
#include <list>
#include <string>
#include <stack> // s.top()
#include <bitset>
#include <queue> // s.front()
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
#define print(x) cout<<(x)<<endl
#define INF10 1001001001 
#define INF5 100000
#define EPS 1e-10


int main() {
	int N; cin >> N;
	cout << N * N * N << endl;




	return 0;
}


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

using namespace std;
int main()
{
    int n,i,sum=0,sum1;
    cin>>n;
    int arr[n];
    
    for(i=0;i<n;i++)
    {
        cin>>arr[i];
        sum=sum^arr[i];

    }
    for(i=0;i<n;i++)
    {
       sum1=sum^arr[i];
      cout<<sum1<<" ";
    }
    


}

Measured memory_bytes: 4364
import heapq

n, m = map(int, input().split())
aa = list(map(int, input().split()))

h = [(-a, a) for a in aa]
heapq.heapify(h)
for _ in range(m):
    x = h[0]
    c = x[1] // 2
    x = (-c, c)

    heapq.heapreplace(h, x)

print(sum([-hh[0] for hh in h]))

Measured memory_bytes: 24516
#include <iostream>
#include <fstream>
#include <cmath>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <cstdlib>
#include <cstdio>
#include <string>
#include <cstring>
#include <cassert>
#include <utility>
#include <iomanip>

using namespace std;

#define sz(x) (int) x.size()
#define unique(x) x.erase(unique(x.begin(), x.end()), x.end())
#define all(a) a.begin(), a.end()
#define sqr(x) ((x) * (x)) 
#define y1 aksjdaskdjksjfksdjf
#define left kdnvldvoiwejifejg
#define right lkdsjflksdjfdjfk
#define prev asdasfsadjkjsdfjs

const int MAXN = 105000;
const int INF = (int) 1e9;

int n, total;
long long dp[MAXN];
int w[MAXN], v[MAXN];

int main() { 

  scanf("%d %d", &n, &total);

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

  for (int i = 0; i < MAXN; i++) {
    dp[i] = 1ll * INF * INF;
  }
  dp[0] = 0;

  for (int i = 0; i < n; i++) {
    for (int j = MAXN - 1; j >= v[i]; j--) {
      if (dp[j - v[i]] != INF) {
        dp[j] = min(dp[j], dp[j - v[i]] + w[i]);
      }
    }
  }

  for (int i = MAXN - 1; i >= 0; i--) {
    if (dp[i] <= total) {
      cout << i << endl;
      return 0;
    }
  }

  return 0;
}


Measured memory_bytes: 1152
function Main (input) {
  input = input.split("\n").map(inp => inp.split(" ").map(Number));
  var N = input[0][0];
  var M = input[0][1];
  var A = input[1];
  var st = 0;
  for (var i of A) {
    st += i;
  }
  var ans = "No";
  var n_nk = 0;
  for (var i of A) {
    if (i >= st/(4*M)) {
      n_nk++;
    }
    if (n_nk >= M) {
      ans = "Yes";
      break;
    }
  }
  console.log(ans);
}

Main(require("fs").readFileSync("/dev/stdin", "utf8"));

Measured memory_bytes: 7372
#include<map>
#include<set>
#include<list>
#include<cmath>
#include<queue>
#include<stack>
#include<cstdio>
#include<string>
#include<vector>
#include<complex>
#include<cstdlib>
#include<cstring>
#include<numeric>
#include<sstream>
#include<iostream>
#include<algorithm>
#include<functional>
 
#define mp       make_pair
#define pb       push_back
#define all(x)   (x).begin(),(x).end()
#define YES() printf("YES\n")
#define NO() printf("NO\n")
#define Yes() printf("Yes\n")
#define No() printf("No\n")
 
using namespace std;
 
#define int long long
//typedef    long long          ll;
typedef    unsigned long long ull;
typedef    vector<bool>       vb;
typedef    vector<int>        vi;
typedef    vector<vb>         vvb;
typedef    vector<vi>         vvi;
typedef    pair<int,int>      P;
 
const int INF=1e+9;
const double EPS=1e-9;
const int MOD=1000000007;
 
const int dx[]={1,0,-1,0},dy[]={0,-1,0,1};

signed main(){
	int n,m,a[300][300],mi = INF;
	bool used[300] = {};
	queue<int> que[300];
	cin >> n >> m;
	for(int i = 0;i < n;i++){
		for(int j = 0;j < m;j++){
			cin >> a[i][j];
			a[i][j]--;
			que[i].push(a[i][j]);
		}
	}
	for(int i = 0;i < m;i++){
		int cnt[300] = {};
		for(int j = 0;j < n;j++){
			while(used[que[j].front()]) que[j].pop();
			cnt[que[j].front()]++;
		}
		int ma = 0;
		for(int j = 0;j < m;j++){
			if(cnt[j] > cnt[ma]) ma = j;
		}
		mi = min(mi,cnt[ma]);
		used[ma] = true;
	}
	cout << mi << endl;
	return 0;
}

Measured memory_bytes: 1792
#include<bits/stdc++.h>
using namespace std;
int main(){
	int n, k; cin>>n>>k;
	set<int>st;
	for(int i=0;i<k;i++){
		int d; cin>>d;
		for(int j=0;j<d;j++){
			int s; cin>>s;
			st.insert(s);
		}
	}
	int cnt=0;
	for(int i=1;i<=n;i++){
		if(!st.count(i)) cnt++;
	}
	cout<<cnt<<'\n';
	return 0;
}

Measured memory_bytes: 3608
#include <iostream>
using namespace std;
int main(){
    int n;
    string s;
    cin >> n >> s;
    for(int i = 0; i < s.length(); i++){
        s[i] += n;
        if(s[i] > 'Z'){
            s[i] -= 'Z'-'A'+1;
        }
    }
    cout << s << endl;
    return 0;
}

Measured memory_bytes: 256
from collections import Counter

def prime_factorize(n):
    a = []
    while n % 2 == 0:
        a.append(2)
        n //= 2
    f = 3
    while f * f <= n:
        if n % f == 0:
            a.append(f)
            n //= f
        else:
            f += 2
    if n != 1:
        a.append(n)
    return a

n = int(input())
a = prime_factorize(n)
c = Counter(a)
ans = 0
for k,v in c.items():
    ans += 1
    now = 1
    v -= now
    while now < v:
        ans += 1
        now += 1
        v -= now
print(ans)

Measured memory_bytes: 9360
using System;

public class Program
{
	public static void Main()
	{
		int N = int.Parse(Console.ReadLine());
		long power = 1;
		for (int i = 1; i <= N; i++)
		{
			power = (power * i) % (long)(1e9 + 7);
		}
		Console.WriteLine(power);
	}
}

Measured memory_bytes: 11092
n,a,b = map(int, input().split())
s = input()

x = 0
y = 0
for c in s:
    if c == "a":
        if x < a + b:
            print("Yes")
            x += 1
        else:
            print("No")
    elif c == "b":
        if x < a + b and y < b:
            print("Yes")
            x += 1
            y += 1
        else:
            print("No")
            y += 1
    else:
        print("No")

Measured memory_bytes: 53080
#include <bits/stdc++.h>
using namespace std;
const int mod = 1000000007;

int main() {
	int N,K;
	cin >> K>>N;
	vector<int>A(N);
	for (size_t i = 0; i < N; i++)
	{
		cin >> A.at(i);
	}
	sort(A.begin(), A.end());
	vector<int>d(N);
	for (size_t i = 0; i < N-1; i++)
	{
		d.at(i) = abs(A.at(i) - A.at(i + 1));
	}
	d.at(N - 1) = K-abs(A.at(0) - A.at(N - 1));
	sort(d.begin(), d.end(), greater<int>());
	cout << K - d.at(0);
}

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

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

  vector<int> v(n);
  rep(i,n) cin >> v.at(i);
  sort(v.begin(), v.end(), greater<int>());

  int cnt=0;
  int base=1000;
  rep(i,n){
    if(v.at(i) < base){
      cnt++;
      base = v.at(i);
    }
  }

  cout << cnt << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
#define PI  3.14159265358979323846
#define M 1000000007
ll gcd(ll a,ll b)
{
    if(a==0)
        return b;
    else
        return gcd(b%a,a);
}
ll fast(ll n,ll a,ll m)
{
    if(n==0)
        return 1;
    else if(n==1)
        return a;
    else
    {
        ll res=fast(n/2,a,m)%m;
        if(n%2==0)
            return (((res%m)*(res%m))%m);
        else
            return (((((res%m)*a)%m)*res)%m);
    }
}
ll lcm(ll x,ll y)
{
    ll P=x*y;
    P/=gcd(x,y);
    return P;
}
int main()
{
   ll n,K;
   cin>>n>>K;
   ll i,A[n];
   for(i=0;i<n;i++)
   {
       cin>>A[i];
   }
   sort(A,A+n);
   ll fac[n+1],inv[n+1];
   fac[0]=1;
   inv[0]=1;
   for(i=1;i<=n;i++)
   {
       fac[i]=(fac[i-1]*i)%M;
   }
   for(i=1;i<=n;i++)
   {
       inv[i]=fast(1e9+5,fac[i],M);
   }
   ll ans=0;
   ll res=inv[K-1];
   for(i=1;i<=n;i++)
   {
       ll P=0,Q=0;
       if(i-1>=K-1)
       {

           P=fac[i-1]%M;
           P=((P%M)*(inv[i-K]%M))%M;
           P=((P%M)*(res%M))%M;
       }
       if(n-i>=K-1)
           {
           Q=fac[n-i];
           Q=((Q%M)*(inv[n-i-K+1]%M))%M;
           Q=((Q%M)*(res%M))%M;
           P-=Q;
           if(P<0)
           {
               P+=M;
               P%=M;
           }
           }

           P=((P%M)*(A[i-1]%M))%M;
           if(P<0)
           {
               P+=M;
               P%=M;
           }
           ans=(ans%M+P%M)%M;
       }

   cout<<ans;
}




Measured memory_bytes: 2560
//
#include <vector>
#include <set>
#include <array>
#include <iostream>
#include <cstdio>
#include <cstdint>
#include <algorithm>
#include <numeric>
#include <bitset>

//
using ll = long long;
using namespace std;
#define rep(i,n) for(int i=0;i<(n);++i)
void yes(bool cond) { cond ? puts("Yes") : puts("No"); }

//
int main()
{
    cin.tie(0); ios::sync_with_stdio(false);
    ll N;
    vector<ll> p;
    cin >> N;
    rep(i, N)
    {
        ll t;
        cin >> t;
        p.push_back(t);
    }
    const auto calcCost = [&](ll i0, ll i1)
    {
        return abs(p[i1] - p[i0]);
    };
    vector<ll> costs(N,0);
    costs[0] = 0;
    costs[1] = costs[0] + calcCost(0,1);

    for(ll i =2;i<N;++i)
    {
        ll i0 = i - 2;
        ll i1 = i - 1;
        ll i2 = i;
        costs[i2] = min(costs[i1] + calcCost(i1, i2), costs[i0] + calcCost(i0, i2));
    }
    cout << costs.back();
}

Measured memory_bytes: 4600
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  string o,e;
  cin >> o>>e;
  for(int i = 0;i<o.size();i++){
    cout << o.at(i);
    if(i<e.size()){
      cout << e.at(i);
    }
  }
}

Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<cmath>
#include<cstring>
#include<algorithm>
#define fo(i,a,b) for(int i=a;i<=b;i++)
#define fod(i,a,b) for(int i=a;i>=b;i--)
using namespace std;
typedef long long ll;
const int N=1e5+10,inf=(1<<30);
ll f[N],p[N];int n,e,t;
int main()
{
	scanf("%d%d%d",&n,&e,&t);
	fo(i,1,n) scanf("%lld",&p[i]);
	memset(f,63,sizeof(f));f[0]=0;
	ll mn=inf;
	for(int i=1,j=0;i<=n;i++) {
		for(;t<=(p[i]-p[j+1])<<1;j++)
			mn=min(mn,f[j]-2*p[j+1]);
			if(j<i) f[i]=min(f[i],f[j]+t);
			f[i]=min(f[i],mn+2*p[i]);
	}
	printf("%lld\n",f[n]+e);
	return 0;
}

Measured memory_bytes: 1792
def main(A, B, K):
    i = min(A,B)+1
    counter = 0
    while(counter < K):
        i -= 1
        if(A%i == 0 and B%i == 0):
            counter += 1
        
    return i
        
    

args = input().split()

print(main(int(args[0]), int(args[1]), int(args[2])))


Measured memory_bytes: 2940
#include<iostream>
#include<math.h>
#include<vector>
using namespace std;
vector<int> dp(100001, -1); 
int minCost(int i,int k, vector<int> &a) {
  if(i==a.size()-1) return 0;
  if(dp[i]!=-1) return dp[i];
  dp[i] = INT_MAX;
  int s = a.size()-1>i+k ? i+k : a.size()-1;
  for(int j=i+1;j<=s;++j) {
    dp[i] =  min(dp[i],abs(a[j]-a[i]) + minCost(j, k, a));
  }
  return dp[i];
}
int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);
    int n,k;
    cin >> n >> k;
    vector<int> a(n);
    for(int i=0;i<n;++i) cin >> a[i];
    cout << minCost(0,k, a); 
    return 0;
}


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

#define fi first
#define se second
#define all(x) (x).begin(), (x).end()
#define pb push_back
#define endl '\n'

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<double, int> pdi;

const ll INF = 2e18;
const int MOD = 1e9 + 7;
const int MAXN = 1e5 + 5;

ll N, A[MAXN], L[MAXN], R[MAXN], ans;

int main() {
	ios::sync_with_stdio(0); cin.tie(0);
	cin >> N;
	for(int i=0; i<=N; i++) cin >> A[i];
	if(N == 0) {
		if(A[0] == 1) cout << 1;
		else if(A[0] == 0) cout << 0;
		else cout << -1;
		return 0;
	}
	L[N] = R[N] = A[N];
	for(int i=N-1; i>=0; i--) {
		L[i] = (L[i+1]+1)/2 + A[i];
		R[i] = R[i+1] + A[i];
		if(i<=60) R[i] = min(1LL << i, R[i]);
		if(L[i] > R[i]) {
			cout << -1;
			return 0;
		}
	}
	ll bef = 1; ans = 1;
	for(int i=1; i<=N; i++) {
		ll t = min(R[i], (bef-A[i-1])*2);
		if(t < L[i]) {
			cout << -1;
			return 0;
		}
		bef = t;
		ans += t;
	}
	cout << ans;
}



Measured memory_bytes: 5996
a = int(input())
b = int(input())
c = int(input())
x = int(input())

ans = 0
for i in range(a + 1):
    for j in range(b + 1):
        for k in range(c + 1):
            if 500 * i + 100 * j + 50 * k == x:
                ans += 1
print(ans)

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

int main()
{
    cin.tie(0); ios::sync_with_stdio(false);
    int A[9] = {0};
    bool B[9] = {false};
    rep(i, 3)
    {
        rep(j, 3)
        {
            cin >> A[i*3+j];
        }
    }

    int N;
    cin >> N;
    
    int b;
    rep(i, N)
    {
        cin >> b;
        rep(j,9)
        {
            if(A[j] == b)
            {
                B[j] = true;
            }
        }
    }

    int ans = 0;
    rep(i, 3)
    {
        int yoko=0, tate=0;
        rep(j, 3)
        {
            yoko += B[i*3+j]?1:0;
            tate += B[j*3+i]?1:0;
        }
        if(yoko==3)
        {
            cout << "Yes" << endl;
            return 0;
        }
        if(tate==3)
        {
            cout << "Yes" << endl;
            return 0;
        }
    }

    if(B[2]&&B[4]&&B[6] || B[0]&&B[4]&&B[8])
    {
        cout << "Yes" << endl;
        return 0;
    }

    cout << "No" << endl;

    return 0;
}


Measured memory_bytes: 256
def input_list():
    n = int(input())
    return n, [int(x) for x in input().split()]


def main(values):
    count = 0
    while all([x % 2 == 0 for x in values]):
        values = [x / 2 for x in values]
        count += 1
    print(count)


if __name__ == "__main__":
    _, x = input_list()
    main(x)


Measured memory_bytes: 9248
#include<stdio.h>
int main(){
int a,b,c,i,j,k;
scanf("%d%d%d",&a,&b,&c);

i=a+b;
j=b+c;
k=a+c;

if(i==c || j==a || k==b){
    printf("Yes\n");
}
else{
    printf("No\n");
}


return 0;
}


Measured memory_bytes: 128
import java.util.Arrays;
import java.util.PriorityQueue;
import java.util.Scanner;

//Online Quiz System
public class Main{

	int WORK = 0, START = 1, END = 2, SUBMIT = 3;
	
	class E implements Comparable<E>{
		int type, t, id;
		public E(int type, int t, int id) {
			this.type = type;
			this.t = t;
			this.id = id;
		}
		public int compareTo(E o) {
			return t!=o.t?t-o.t:type-o.type;
		}
	}
	
	void run(){
		Scanner sc = new Scanner(System.in);
		boolean[] just = new boolean[100], sub = new boolean[100];
		int[] L = new int[100], send = new int[100], rev = new int[100], delay = new int[100];
		for(boolean H=true;;H=false){
			int M = sc.nextInt(), N = sc.nextInt();
			if((M|N)==0)break;
			if(!H)System.out.println();
			Arrays.fill(send, 0); Arrays.fill(rev, 0);
			for(int i=0;i<M;i++)delay[i]=sc.nextInt();
			while(N--!=0){
				Arrays.fill(L, 0); Arrays.fill(just, false); Arrays.fill(sub, false);
				PriorityQueue<E> q = new PriorityQueue<E>();
				q.add(new E(START, 0, -1)); q.add(new E(END, 20000, -1));
				for(int t=1000;t<=20000;t+=1000)q.add(new E(WORK, t, -1));
				int k = sc.nextInt();
				while(k--!=0){
					int id = sc.nextInt(), t = sc.nextInt(), len = sc.next().length();
					q.add(new E(SUBMIT, t+delay[id]*2, id));
					L[id] = len;
				}
				while(!q.isEmpty()){
					E e = q.poll();
					if(e.type==START){
						for(int i=0;i<M;i++)rev[i]+=3;
					}
					else if(e.type==END){
						for(int i=0;i<M;i++)rev[i]+=4; break;
					}
					else if(e.type==SUBMIT){
						just[e.id] = sub[e.id] = true;
						send[e.id] += 5+L[e.id];
					}
					else{
						int newly = 0, submit = 0, allsize = 0, newlysize = 0;
						for(int i=0;i<M;i++){
							if(just[i])newly++;
							if(just[i])newlysize+=L[i];
							if(sub[i])submit++;
							if(sub[i])allsize+=L[i];
						}
						for(int i=0;i<M;i++){
							if(!sub[i]){
								if(0<newly){
									rev[i]+=4+newly;
								}
							}
							else if(just[i]){
								if(1<submit){
									rev[i]+=4+2*(submit-1)+allsize-L[i];
								}
							}
							else{
								if(0<newly){
									rev[i]+=4+2*newly+newlysize;
								}
							}
						}
						Arrays.fill(just, false);
					}
				}
			}
			int ress = 0, resr = 0;
			for(int i=0;i<M;i++){
				ress+=rev[i]; resr+=send[i];
			}
			System.out.println(ress+" "+resr);
			for(int i=0;i<M;i++)System.out.println(send[i]+" "+rev[i]);
		}
	}
	
	public static void main(String[] args) {
		new Main().run();
	}
}

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

int main() {
  int64_t H, W;
  cin >> H >> W;
  if (H == 1 || W == 1) cout << 1 << endl;
  
  else if (H % 2LL == 0LL || W % 2LL == 0LL) {
    cout << (H * W) / 2LL << endl;
  }
  else {
    cout << (H * W + 1LL) / 2LL << endl;
  }
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const int N = 1000;

ll n, m;
ll a[N][3];
ll ans = -1e18;

void f(string s) {
    if (s.size() == 3) {
        ll mul[3];
        for (int i = 0; i < 3; ++i) {
            if (s[i] == '+') mul[i] = 1;
            else mul[i] = -1;
        }
            
        ll score = 0;
        vector<ll> best;
        for (int i = 0; i < n; ++i) {
            ll tmp = 0;
            for (int j = 0; j < 3; ++j) {
                tmp += a[i][j] * mul[j];
            }
            best.push_back(tmp);
        }
        sort(best.begin(), best.end(), greater<ll>());
        for (int i = 0; i < m; ++i) score += best[i];
        ans = max(ans, score);
        return;
    }

    f(s + "+");
    f(s + "-");
}

int main() {
    cin.sync_with_stdio(0); cin.tie(0);
    cin >> n >> m;
    for (int i = 0; i < n; ++i) {
        for (int j = 0; j < 3; ++j) {
            cin >> a[i][j];
        }
    }

    f("");
    cout << ans;
}


Measured memory_bytes: 3696
#include<bits/stdc++.h>
#define REP(i, n) for(int i = 0; i < (int)n; i++)
#define all(x) x.begin(), x.end()
#define MOD 1000000007//1e9+7
typedef long long ll;
using namespace std;
int main()
{
  int a, b;
  cin >> a >> b;
  cout << (a - 1)* (b - 1) << endl;
}


Measured memory_bytes: 256
inf = 10**9+5
n = int(input())
h = list( map(int,input().split()))

dp = [inf]*n
dp[0] = 0
for i in range(n):
    for j in range(i+1,i+3):
        if j<n:
            dp[j] = min(dp[j],dp[i]+abs(h[i]-h[j]))
print(dp[-1])


Measured memory_bytes: 20572
import heapq
INF = 10**15
n = int(input())
a = [int(item) for item in input().split()]

k_max_h = a[:n]
k_min_h = [-item for item in a[2*n:]]
heapq.heapify(k_max_h)
heapq.heapify(k_min_h)
k_max_h_sum = sum(k_max_h)
k_min_h_sum = sum(k_min_h)

k_max_forward = [-INF] * (n * 3 - 1)
k_min_back = [INF] * (n * 3 - 1)
k_max_forward[n-1] = k_max_h_sum
k_min_back[2*n-1] = k_min_h_sum

for k in range(n, n*2):
    heapq.heappush(k_max_h, a[k])
    k_max_h_sum += a[k] - heapq.heappop(k_max_h)
    k_max_forward[k] = k_max_h_sum

for k in range(n*2-1, n-1, -1):
    heapq.heappush(k_min_h, -a[k])
    k_min_h_sum += -a[k] - heapq.heappop(k_min_h)
    k_min_back[k-1] = k_min_h_sum

ans = -INF
for i in range(n-1, 2*n):
    ans = max(ans, (k_max_forward[i]+k_min_back[i]))
print(ans)

Measured memory_bytes: 37212
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  unsigned long long int x;
  cin >> x;
  
  unsigned long long int money = 100, cnt = 0;
  while (money < x) {
    money *= 1.01;
    cnt++;
  }
  
  cout << cnt << endl;
}

Measured memory_bytes: 3608
#include <bits/stdc++.h>
using namespace std;
 
typedef vector<int> vi;
typedef vector<double> vd;
 
double mypow(double b ,int e){
      if(e == 0) return 1;
      if(e%2==0)
            return mypow( b*b, e/2 );
      else
            return mypow( b*b, e/2 ) * b;
}
 
int main(){
 
 
      int N,M,L; cin >> N >> M >> L ;
      if(N==1){
            cout << 1.0 << endl;
            return 0;
      }
      vector<vd> prob(N,vd(M+1,0.0));
      vector<vd> dist(N,vd(M+1,0.0));
 
      vd p(N),t(N),v(N);
      for(int i=0; i<N; i++) cin >> p[i] >> t[i] >> v[i];
 
      // PRE PROCESS
      for(int i=0; i<N; i++){
            dist[i][0] = (double)L / v[i];
            for(int j=1; j<=M; j++){
                  dist[i][j] = dist[i][j-1] + t[i];
            }
      }
      for(int i=0; i<N; i++)
            prob[i][0] = mypow((100-p[i])/100,M);
      for(int i=0; i<N; i++){
            for(int j=1; j<=M; j++){
                  if(p[i] != 100)
                        prob[i][j] = (prob[i][j-1] * (p[i]/100)) / ((100-p[i])/100);
                  else
                        prob[i][j] = 1.0;
            }
      }
      double comb = 1;
      for(int j=1; j<=M; j++){
            comb = comb * (M - j + 1) / j; 
            for(int i=0; i<N; i++){
                  prob[i][j] *= comb;
            }
      }
       
      vector<vd> sum = prob;
      for(int i=0; i<N; i++){
            for(int j=M-1; j>=0; j--){
                  sum[i][j] += sum[i][j+1];
                  if(sum[i][j] > 1) sum[i][j] = 1;
            }
      }
 
      vector<vd> ans = prob;
      for(int i=0; i<N; i++){
            for(int j=0; j<=M; j++){
                  for(int k=0; k<N; k++){
                        if(i==k) continue;
                        int id = upper_bound(dist[k].begin(),dist[k].end(), dist[i][j]) - dist[k].begin();
                        if(id > M) ans[i][j] = 0.0;
                        else       ans[i][j] *= sum[k][id];
 
                  }
            }
      }
 
      for(int i=0; i<N; i++){
            double tmp = 0.0;
            if(p[i] == 100) tmp = ans[i][M];
            else
                  for(int j=0; j<=M; j++)
                        tmp += ans[i][j];
            if(tmp > 1) tmp = 0;
            printf("%.10f\n",tmp);
      }
                         
}

Measured memory_bytes: 3388
#include<stdio.h>

#define MAX 100000
int partition(int [],int,int );

int A[MAX];

int main(){
	int n,i,j,q;

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

	q=partition(A,0,n-1);

	for(i=0;i<n-1;i++){
		if(i == q){
			printf("[%d] ",A[i]);
		}
		else printf("%d ",A[i]);
	}
	printf("%d\n",A[i]);

	return 0;

}

int partition(int A[],int p,int r){
	int i,j,x,t;
x=A[r];
i=p-1;

for(j=p;j<r;j++){
	if(A[j]<=x){
		i++;
		t=A[i];
		A[i]=A[j];
		A[j]=t;
	}
}

t=A[i+1];
A[i+1]=A[r];
A[r]=t;

return i+1;
}

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

int main()
{
    int b;
    cin>>b;
    int a[32]={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};
    std::cout << a[b-1] << std::endl;
}


Measured memory_bytes: 3592
#include <algorithm>
#include <cassert>
#include <climits>
#include <cstdio>
#include <deque>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <unordered_map>
#include <utility>
#include <vector>

using namespace std;

template <class T>
bool chmax(T &a, const T &b) {
    if (a < b) {
        a = b;
        return 1;
    }
    return 0;
}
template <class T>
bool chmin(T &a, const T &b) {
    if (b < a) {
        a = b;
        return 1;
    }
    return 0;
}

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

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

    vector<string> table = {
        "SUN",
        "MON",
        "TUE",
        "WED",
        "THU",
        "FRI",
        "SAT"
    };

    for (int i = 0; i < table.size(); i++) {
        // cout << table[i] << endl;
        if (S == table[i]) {
            cout << 7 - i << endl;
        }
    }
    return 0;
}


Measured memory_bytes: 256
int main(void)
{
        int n,d[100],i,index,tmp,c=1,j;

        scanf("%d",&n);

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

        for (i=0;i<n-1;i++) {
                index=i;
                for (j=i+1;j<n;j++)
                        if (d[j]>d[index]) index=j;
                 tmp=d[index]; d[index]=d[i]; d[i]=tmp;
        }

        for (i=0;i<n-1;i++){
                if (d[i]>d[i+1])
                        c++;
        }

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

         return 0;
}

Measured memory_bytes: 128
#include "bits/stdc++.h"
using namespace std;
#define FAST ios_base::sync_with_stdio(false); cin.tie(0);
#define LLINF (long long) 1e18//1234567890987654321
#define INF 1234567890ll
#define pb push_back
#define ins insert
#define f first
#define s second	
#define db 0
#define EPS (1e-7)    //0.0000001 the value
#define PI (acos(-1))
#define MAXN (300006)
#define MAXK 26
#define MAXX 15000006
#define ll long long int 
#define ld long double
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());    //can be used by calling rng() or shuffle(A, A+n, rng)
#define FOR(ii, ss, ee) for(ll ii = ss; ii < ee; ii++)
#define space " "
#define cbr cerr << "hi\n"
#define mmst(x, v) memset((x), v, sizeof ((x)))
#define siz(x) ((ll)x.size())
#define ph push
#define btinpct(x) __builtin_popcountll(x)
#define p2(x) (1LL<<(x))
#define all(x) (x).begin(), (x).end()
#define lbd(x, y) lower_bound(all(x), y)
#define ubd(x, y) upper_bound(all(x), y)
typedef pair <ll, ll> pi;
typedef pair <ll, pi> spi;
typedef pair <pi, pi> dpi;
inline ll rand(ll x, ll y) { ++y; return (rng() % (y-x)) + x; } //inclusivesss
ll n, m, x;
int main()
{
	cin>>n>>m>>x;
	cout << ( (n==m&&m==x) ? "Yes\n" :"No\n");
}


Measured memory_bytes: 256
#include<iostream>
using namespace std;
int main(){
    int a,b,c;
    cin >> a >> b >> c;
    
    if (a<=b && b<=c) cout<<a<<" "<<b<<" "<<c<<endl;
    else if (b<=c && c<=a) cout<<b<<" "<<c<<" "<<a<<endl;
    else if (c<=a && a<=b) cout<<c<<" "<<a<<" "<<b<<endl;
    else if (a<=c && c<=b) cout<<a<<" "<<c<<" "<<b<<endl;
    else if (b<=a && a<=c) cout<<b<<" "<<a<<" "<<c<<endl;
    else if (c<=b && b<=a) cout<<c<<" "<<b<<" "<<a<<endl;
    return 0;
    
}


Measured memory_bytes: 3084
#include <iostream>

using namespace std;

int main(void)
{
	long long a[6];
	for (int i = 0; i < 6; i++) {
		cin >> a[i];
	}
	
	long long min = a[1];
	for (int i = 2; i < 6; i++) {
		if (min > a[i]) {
			min = a[i];
		}
	}
	cout << (a[0] + min - 1) / min + 4 << endl;
	
	return 0;
}

Measured memory_bytes: 256
#define _USE_MATH_DEFINES
#include  <cmath>
#include <cstdio>
#include <vector>
#include <iostream>
#include <algorithm>
#include <string>
#include<math.h>
#include<iomanip>
#include<stdio.h>
#include <stdlib.h>
#include<stdio.h>
#include <queue>
#include<map>
#include <sstream>
#include<set>
#include<stack>

//#include<bits/stdc++.h>


using namespace std;



int main() {

	int n, m, c;
	cin >> n >> m >> c;
	vector<int>b(m);
	int r = 0;
	for (int i = 0; i < m; i++)cin >> b[i];
	for (int i = 0; i < n; i++) {
		long long int t = 0;
		for (int j = 0; j < m; j++) {
			int x;
			cin >> x;
			t += x*b[j];
		}
		if (t+c > 0)r++;
	}
	cout << r << endl;
	return 0;

}

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

struct Restaurant{
    int index;
    string city;
    int score;
};

int main(void){
    int n;
    cin>>n;
    vector<Restaurant> rest;
    for(int i=0;i<n;i++){
        string s;
        int p;
        cin>>s>>p;
        Restaurant res;
        res.index=i+1;
        res.city=s;
        res.score=p;
        rest.push_back(res);
    }
    sort(rest.begin(),rest.end(),[](const Restaurant &a,const Restaurant &b){
        return a.score>b.score; 
    });
    stable_sort(rest.begin(),rest.end(),[](const Restaurant &a,const Restaurant &b){
        return a.city<b.city; 
    });
    for(int i=0;i<n;i++){
        cout<<rest[i].index<<endl;
    }
    return 0;
}

Measured memory_bytes: 256
N = int(input())
cur = 1
ans = []
while N > 0:
	to_test = int(str(cur) + "1")
	for j in range(2,int(to_test ** 0.5) + 1):
		if to_test % j == 0:
			break
	else:
		ans.append(str(to_test))
		N -= 1
	cur += 1
print(" ".join(ans))


Measured memory_bytes: 3060
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0; i<n; i++)
#define PI 3.14159265359
#define INF 1000100100
#define MOD 1000000007
#define all(x) (x).begin(),(x).end()
typedef long long ll;
#define P pair<int, int>
#define PP pair<P,int>
#define T tuple<int,int,int> 
using namespace std;

int main(){
    int n,q; cin >> n >> q;
    vector<T> rw(n);
    rep(i,n){
        int a,b,c; cin >> a >> b >> c;
        rw[i]=T(c,a,b);
    }
    vector<int> d(q);
    rep(i,q) cin >> d[i];
    sort(all(rw));

    vector<int> ans(q,-1);

    set<P> s;
    rep(i,q) s.insert(P(d[i],i));

    rep(i,n){
        int x,l,r;
        tie(x,l,r) = rw[i];
        l-=x;
        r=r-x;
        auto it = s.lower_bound(P(l,-1));
        while(it!=s.end()){
            if(it->first >= r) break;
            ans[it->second]=x;
            s.erase(it++);
        }
    }

    rep(i,q) cout << ans[i] << endl;
    return 0;
}


Measured memory_bytes: 16384
#include <cstdio>
int main() {
	int n;
	while (scanf("%d",&n)) {
		if (n == 0) break;
		int res = 0;
		for (int i=0; i<n/4; i++) {
			int in; scanf("%d",&in);
			res += in;
		}
		printf("%d\n",res);
	}
}

Measured memory_bytes: 0
from collections import defaultdict
N = int(input())
S = input()
S = S[:N]+S[2*N-1:N-1:-1]
ldic = defaultdict(int)
rdic = defaultdict(int)
for i in range(2**N):
  lred = ""
  lblue = ""
  rred = ""
  rblue = ""
  for j in range(N):
    if i%2==1:
      lred += S[j]
      rred += S[N+j]
    else:
      lblue += S[j]
      rblue += S[N+j]
    i >>= 1
  ldic[(lred,lblue)] += 1
  rdic[(rred,rblue)] += 1

ans = 0
for k in ldic.keys():
  ans += ldic[k]*rdic[k]
print(ans)

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

def main():
    a,b = map(int,input().split())
    if a<=0 and 0<=b:
        print("Zero")
        return
    elif a<0 and b<0:
        if (b-a)%2 == 0:
            print("Negative")
            return
    print("Positive")

if __name__ == '__main__':
    main()


Measured memory_bytes: 2940
#116_B
def f(n):
    if n%2==0:
        return n//2
    else:
        return 3*n+1
    
s=int(input())
A=[0,s]
for i in range(2,10**7+1):
    x=f(A[i-1])
    if x in A:
        print(i)
        exit()
    A.append(x)

Measured memory_bytes: 3060
import sys, re, os
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians, acos, atan, asin, log, log10
from itertools import permutations, combinations, product, accumulate
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from fractions import gcd
def debug(*args):
    if debugmode:
        print(*args)
def input(): return sys.stdin.readline().strip()
def STR(): return input()
def INT(): return int(input())
def FLOAT(): return float(input())
def MAP(): return map(int, input().split())
def S_MAP(): return map(str, input().split())
def LIST(): return list(map(int, input().split()))
def S_LIST(): return list(map(str, input().split()))
def lcm(a, b): return a * b // gcd(a, b)
sys.setrecursionlimit(10 ** 9)
inf = sys.maxsize
mod = 10 ** 9 + 7
dx = [0, 0, 1, -1, 1, -1, -1, 1]
dy = [1, -1, 0, 0, 1, -1, 1, -1]
debugmode = True

n, t = MAP()
ans = inf
for _ in range(n):
    c, tt = MAP()
    if tt <= t:
        ans = min(ans, c)
if ans == inf:
    ans = 'TLE'
print(ans)

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

#define endl '\n'
using namespace std;
using ll = long long;

const int N = 1003;
const int M = 20004;

struct Block
{
    ll w, s, v;
    bool operator < (const Block &that)
    {
        return this->w + this->s < that.w + that.s;
        
        // WA : this operator doesn't follow transitive closure
//        return this->w <= that.s && this->s < that.w;
    }
};

int n;
Block arr[N];
ll dp[N][M];

void init();
void process();

int main()
{
    ios::sync_with_stdio(false); cin.tie(0);
    init();
    process();
    cout.flush();
    return 0;
}

void init()
{
    cin >> n;
    for(int i = 1; i <= n; i++) cin >> arr[i].w >> arr[i].s >> arr[i].v;
    sort(arr+1, arr+1+n);
}

void process()
{
    for(int i = 1; i <= n; i++)
    {
        // both are correct
        for(int j = 0; j < M; j++)
        {
            dp[i][j] = dp[i-1][j];
            if(j-arr[i].w >= 0 && arr[i].s >= j-arr[i].w) 
                dp[i][j] = max(dp[i][j], dp[i-1][j-arr[i].w]+arr[i].v);
        }
        /*
        for(int j = 0; j < M; j++)
        {
            dp[i][j] = max(dp[i][j], dp[i-1][j]);
            if(j <= arr[i].s && j+arr[i].w < M) 
                dp[i][j+arr[i].w] = max(dp[i][j+arr[i].w], dp[i-1][j]+arr[i].v);
        }
        */
    }
    ll ans = 0;
    for(int i = 0; i < M; i++) ans = max(ans, dp[n][i]);
    cout << ans << endl;
}



Measured memory_bytes: 156544
import bisect

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

l.sort()
# print(l)

cnt = 0

for i in range(n):
    for j in range(i+1, n-1):
        t = l[i] + l[j]
        idx = bisect.bisect_left(l, t)
        cnt += idx - (j + 1)
print(cnt)


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

using pii = pair<int,int>;
using ll = long long;
#define rep(i, j) for(int i=0; i < (int)(j); i++)
#define repeat(i, j, k) for(int i = (j); i < (int)(k); i++)
#define all(v) v.begin(),v.end()
#define debug(x) cerr << #x << " : " << x << endl

template<class T> bool set_min(T &a, const T &b) { return a > b  ? a = b, true : false; }
template<class T> bool set_max(T &a, const T &b) { return a < b  ? a = b, true : false; }
// vector
template<class T> istream& operator >> (istream &is , vector<T> &v) { for(T &a : v) is >> a; return is; }
template<class T> ostream& operator << (ostream &os , const vector<T> &v) { for(const T &t : v) os << "\t" << t; return os << endl; }
// pair
template<class T, class U> ostream& operator << (ostream &os , const pair<T, U> &v) { return os << "<" << v.first << ", " << v.second << ">"; }

const ll INFL = 1LL << 60;


class Solver {
  public:    

    void fail() {
        cout << "No" << endl;
        exit(0);
    }
    // I'm at A[now]. I can go to { B[e.first] | e in AE[now] }
    // => (min A[i], min B[j])
    tuple<ll, ll> visit(int now, ll val, vector<ll> &A, vector<ll> &B, vector<vector<pii>> &AE, vector<vector<pii>> &BE) {
        if(A[now] == -INFL) A[now] = val;
        else if(A[now] != val) fail();
        else return make_tuple(A[now], INFL);
        ll min_a = A[now], min_b = INFL;
        for(pii &e : AE[now]) {
            ll rb, ra;
            tie(rb, ra) = visit(e.first, e.second - A[now], B, A, BE, AE);
            set_min(min_a, ra);
            set_min(min_b, rb);
        }
        cerr << now << " " << min_a << " " << min_b << endl;
        return make_tuple(min_a, min_b);
    }
    
    bool solve() {
        int R, C; cin >> R >> C;
        int N; cin >> N;
        vector<vector<pii>> Ey(R), Ex(C);
        rep(i, N) {
            int y, x, a; cin >> y >> x >> a;
            y--; x--;
            Ey[y].push_back(make_pair(x, a));
            Ex[x].push_back(make_pair(y, a));
        }
        vector<ll> x(C, -INFL), y(R, -INFL);

        rep(i, C) {
            if(x[i] != -INFL) continue;
            ll ra, rb;
            tie(ra, rb) = visit(i, 0, x, y, Ex, Ey);
            if(ra + rb < 0) fail();            
        }
        rep(i, R) {
            if(y[i] != -INFL) continue;
            ll ra, rb;
            tie(ra, rb) = visit(i, 0, y, x, Ey, Ex);
            if(ra + rb < 0) fail();            
        }       
        cout << "Yes" << endl;
        return 0;
    }
};

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    Solver s;
    s.solve();
    return 0;
}


Measured memory_bytes: 15872
import java.util.Scanner;
import java.lang.Math;

public class Main {
	public static void main(String args[]) {
		Scanner in = new Scanner(System.in);
		int n = in.nextInt();
		int W = in.nextInt();
		int[] w = new int[n];
		long[] v = new long[n];
		for(int i=0;i<n;i++)
		{
			w[i] = in.nextInt();
			v[i] = in.nextLong();
		}
		long[][] dp = new long[n+1][W+1];
		for(int i=1;i<=n;i++)
		{
			for(int j=0;j<=W;j++)
			{
				if(i==0 || j==0) dp[i][j] = 0;
				else if(j-w[i-1]>=0) dp[i][j] = Math.max(dp[i-1][j], dp[i-1][j-w[i-1]] + v[i-1]);
				else dp[i][j] = dp[i-1][j];
			}
		}
		long ans = 0;
		for(int i=0;i<=W;i++)
		{
			ans = Math.max(ans, dp[n][i]);
		}
		System.out.print(ans);
	}
}


Measured memory_bytes: 138708
import java.util.*;

public class Main {

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

    if (b >= a) {
      System.out.println(a);
    } else {
      System.out.println(a-1);
    }
  }
}


Measured memory_bytes: 22740
#include <iostream>

using namespace std;

int main(){
	long long int a, b, c, k, ans = 0;
	cin >> a >> b >> c >> k;
	if(k <= a){
		ans = k;
	}
	else if(k > a){
		ans = a;
		k -= a;
		if(k > b){
			k -= b;
			ans -= k;
		}
	}
	cout << ans;
	return 0;
}

Measured memory_bytes: 3596
#include <cassert>
#include <cstdio>
#include <cmath>
#include <iostream>
#include <iomanip>
#include <sstream>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <numeric>
#include <algorithm>

using namespace std;
using lint = long long;
constexpr int MOD = 1000000007, INF = 1010101010;
constexpr lint LINF = 1LL << 60;

#ifdef _DEBUG
#include "../../library/library/debug_template.cpp"
#define DMP(...) dump(#__VA_ARGS__, __VA_ARGS__)
#else 
#define DMP(...) ((void)0)
#endif

struct init {
	init() {
		cin.tie(nullptr); ios::sync_with_stdio(false);
		cout << fixed << setprecision(10);
	}
} init_;

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

int main() {

	int N;
	cin >> N;

	vector<lint> A(N + 1);
	for (int i = 0; i <= N; i++) cin >> A[i];

	// if N not 0 B_0 = 1
	// B_(i-1) <= A_i + B_i <= 2*B_(i-1)
	// B_N=0
	vector<lint> B(N + 1);
	B[0] = 1;
	for (int i = 1; i <= N; i++) {
		if (B[i - 1] > LINF) {
			B[i] = LINF - A[i];
		}
		else {
			B[i] = 2 * B[i - 1] - A[i];
		}
	}
	DMP(B);
	DMP(accumulate(B.begin(), B.end(), 0LL));

	lint sum = 0;
	for (int i = N; i >= 0; i--) {
		chmin(B[i], sum);
		sum += A[i];
	}
	DMP(B);
	DMP(accumulate(B.begin(), B.end(), 0LL));

	lint ans = 0;
	if (any_of(B.begin(), B.end(), [](auto b) { return b < 0; }) || A[0] != 0 && N != 0 || A[0] != 1 && N == 0) {
		ans = -1;
	}
	else {
		ans = accumulate(A.begin(), A.end(), 0LL) + accumulate(B.begin(), B.end(), 0LL);
	}

	cout << ans << "\n";

	return 0;
}



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

int main(){
    string s;
    cin>>s;
    string t = s;
    int count=0;
    reverse(t.begin(),t.end());
    for(int i=0;i<s.size();i++){
        if(s.at(i)!=t.at(i)){
            count++;
        }
    }
    cout<<count/2<<endl;
}


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

int main(){
  string S;
  cin >> S;
  int N= S.size();

  int64_t ans= 0;
  // すべての+の入れ方を試して、総和を調べる
  for(int tmp=0; tmp < (1<<(N-1)); tmp++){
    bitset<9> bits(tmp);  // +が入る可能性があるのは最大9(=10-1)箇所

    // ビット列の1のビットに対応する箇所に+を入れたとみなして総和を求める
    int64_t buf= S.at(0)- '0';
    for(int i=0; i<N-1; i++){
      if( bits.test(i) ){
        ans+= buf;
        buf= S.at(i+1)- '0';
      }
      else{
        buf*= 10;
        buf+= S.at(i+1)- '0';
      }
    }
    ans+= buf;
  }

  cout << ans << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <cctype>
#include <limits>
using namespace std;

int op[256];
int64_t expr0(string &S, int &i);
int64_t expr1(string &S, int &i);
int64_t expr2(string &S, int &i);
int64_t factor(string &S, int &i);
int64_t number(string &S, int &i);

int64_t expr0(string &S, int &i){
    int64_t ret = expr1(S,i);
    while(true){
        if(op[S[i]]==0){
            switch(S[i++]){
                case '+':
                    ret+=expr1(S,i);
                    break;
                case '-':
                    ret-=expr1(S,i);
                    break;
                case '*':
                    ret*=expr1(S,i);
                    break;
            }
        }else{
            break;
        }
    }
    return ret;
}
int64_t expr1(string &S, int &i){
    int64_t ret = expr2(S,i);
    while(true){
        if(op[S[i]]==1){
            switch(S[i++]){
                case '+':
                    ret+=expr2(S,i);
                    break;
                case '-':
                    ret-=expr2(S,i);
                    break;
                case '*':
                    ret*=expr2(S,i);
                    break;
            }
        }else{
            break;
        }
    }
    return ret;
}
int64_t expr2(string &S, int &i){
    int64_t ret = factor(S,i);
    while(true){
        if(op[S[i]]==2){
            switch(S[i++]){
                case '+':
                    ret+=factor(S,i);
                    break;
                case '-':
                    ret-=factor(S,i);
                    break;
                case '*':
                    ret*=factor(S,i);
                    break;
            }
        }else{
            break;
        }
    }
    return ret;
}

int64_t factor(string &S, int &i){
    int64_t ret;
    if(S[i]=='('){
        i++;
        ret = expr0(S,i);
        i++;
    }else{
        ret = number(S,i);
    }
    return ret;
}

int64_t number(string &S, int &i){
    int64_t ret = 0;
    while(isdigit(S[i])){
        ret*=10;
        ret+=S[i]-'0';
        i++;
    }
    return ret;
}

int main(){
    string S;
    cin>>S;
    int64_t ans=numeric_limits<int64_t>::min();
    fill(op,op+256,255);
    for(op['+']=0;op['+']<3;op['+']++){
        for(op['-']=0;op['-']<3;op['-']++){
            for(op['*']=0;op['*']<3;op['*']++){
                int i=0;
                ans = max(ans,expr0(S,i));
            }
        }
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 3212
#include<bits/stdc++.h>
#include <vector>
#include <iostream>
using namespace std;
int main(){
  int n;
  long long int x,es;
  cin>>n>>x;
  long long int a[n];
  long long int ans=(long long int)0;
  cin>>a[0];
  for(int i=1;i<n;i++){
    cin>>a[i];
    if(a[i]+a[i-1]>x){
      es=a[i]+a[i-1]-x;
      if(a[i-1]>x){
	ans+=a[i];
	ans+=(es-a[i]);
	a[i-1]=a[i-1]-(es-a[i]);
	a[i]=(long long int)0;
      }else{
	ans+=es;
	a[i]=a[i]-(es);
      }
    }
  }
  cout<<ans<<endl;
  return(0);
}


Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
#define rep(i,j,n) for(int i=(int)(j);i<(int)(n);i++)
#define REP(i,j,n) for(int i=(int)(j);i<=(int)(n);i++)
#define MOD 1000000007
#define int long long
#define ALL(a) (a).begin(),(a).end()
#define vi vector<int>
#define vii vector<vi>
#define pii pair<int,int>
#define priq priority_queue<int>
#define disup(A,key) distance(A.begin(),upper_bound(ALL(A),(int)(key)))
#define dislow(A,key) distance(A.begin(),lower_bound(ALL(A),(int)(key)))
#define tii tuple<int,int,int>
signed main(){
  int N,K; cin>>N>>K;
  vector<pii> A(N);
  rep(i,0,N) cin>>A[i].second>>A[i].first;
  sort(ALL(A),greater<pii>());
  int sum=0;
  map<int,int> M;
  priority_queue<int,vi,greater<int>> S;
  rep(i,0,K){
    sum+=A[i].first;
    if(M.count(A[i].second))
      S.push(A[i].first);
    else
      M[A[i].second]=A[i].first;
  }
  int Q=M.size();
  int ans=sum+Q*Q;
  rep(i,K,N){
    if(S.size()==0)
      break;
    if(!M.count(A[i].second)){
      sum-=S.top();
      S.pop();
      sum+=A[i].first;
      M[A[i].second]=A[i].first;
      int P=M.size();
      ans=max(ans,sum+P*P);
    }
  }
  cout<<ans<<endl;
  }



Measured memory_bytes: 6140
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<stdbool.h>
#include<math.h>
#include<limits.h>
int main(){
    int A,B,C,D;
    scanf("%d %d %d %d",&A,&B,&C,&D);
    while(1){
        C -= B;
        if(C <= 0){
            printf("Yes");
            break;
        }
        A -= D;
        if(A <= 0){
            printf("No");
            break;
        }
    }
}


Measured memory_bytes: 1728
#include <queue>
#define REP(i,n) for(int i=0; i<(int)(n); i++)

#include <cstdio>
#include <iostream>
#include <set>
using namespace std;

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

  vector<int> memo(13);
  for(int i = 30; i <= 120; i += 10){
    memo[i / 10] = i;
    REP(j,i) putchar('+');
    if(i != 120) putchar('>');
  }

  int pos = 12;
  for(const char cc : s){
    const int c = static_cast<int>(cc);
    const int dist = (c + 5) / 10;

    if(pos < dist){
      REP(i,dist-pos) putchar('>');
    }else{
      REP(i,pos-dist) putchar('<');
    }
    pos = dist;

    if(memo[pos] < c){
      REP(i,c-memo[pos]) putchar('+');
    }else{
      REP(i,memo[pos]-c) putchar('-');
    }
    memo[pos] = c;

    putchar('.');
  }

  return 0;
}

Measured memory_bytes: 1160
#include <cstdio>
#include <vector>
#include <map>
#include <unordered_map>
#include <string>
#include <utility>
#include <algorithm>

using namespace std;

int main() {
	int a, b, c;
	scanf("%d %d %d", &a, &b, &c);
	if ((a <= c && c <= b) || (b <= c && c <= a)){
		printf("Yes");
		return 0;
	}
	printf("No");
	return 0;
}

Measured memory_bytes: 128
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <vector>
#include <functional>
#include <queue>
#include <string>
#include <cstring>
#include <numeric>
#include <cstdlib>
#include <cmath>
using namespace std;

typedef long long ll;

#define INF 10e10
#define rep(i,n) for(int i=0; i<n; i++)
#define rep_r(i,n,m) for(int i=m; i<n; i++)
#define END cout << endl
#define MOD 1000000007
#define pb push_back
// 昇順sort
#define sorti(x) sort(x.begin(), x.end())
// 降順sort
#define sortd(x) sort(x.begin(), x.end(), std::greater<int>())

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

  vector<ll> x(m), diff;
  rep(i, m) cin >> x[i];

  if (n >= m) {
    cout << 0 << endl;
    return 0;
  }

  sorti(x);
  ll sum = 0;
  for (int i = 0; i < m - 1; ++i) {
    diff.push_back(abs(x[i+1] - x[i])); 
  }

  sorti(diff);

  for (int i = 0; i < diff.size() - (n - 1); ++i) {
    sum += diff[i];
  }

  cout << sum << endl;
}


Measured memory_bytes: 2168