akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;

int main() {
    int H, W;
    cin >> H >> W;
    bool M[H][W];
    for(int i=0; i<H; i++)
        for(int j=0; j<W; j++) {
            char c;
            cin >> c;
            M[i][j] = (c == '#');
        }
    vector<vector<int>> dp(H, vector<int>(W, INT_MAX));
    dp[0][0] = M[0][0];
    for(int i=0; i<H; i++) {
        for(int j=0; j<W; j++) {
            if(i+1 < H) dp[i+1][j] = min(dp[i+1][j], dp[i][j] + (M[i+1][j] && !M[i][j]));
            if(j+1 < W) dp[i][j+1] = min(dp[i][j+1], dp[i][j] + (M[i][j+1] && !M[i][j]));
        }
    }
    cout << dp[H-1][W-1] << "\n";
}

Measured memory_bytes: 256
# AGC020B - Ice Rink Game
def main():
    K, *A = map(int, open(0).read().split())
    l, h = 2, 2  # low, high
    for i in A[::-1]:
        l += -l % i
        h += i - 1 - h % i
    if l > h:
        print(-1)
    else:
        print(l, h)


if __name__ == "__main__":
    main()

Measured memory_bytes: 14092
A = [
    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,
]
K = int(input())
print(A[K - 1])


Measured memory_bytes: 2940
#define ll long long
#define pb push_back
#define mpr make_pair
#define ff first
#define ss second
#include <bits/stdc++.h>
using namespace std;

int main(int argc, char const *argv[]) {
  ll a,b;
  cin>>a>>b;
  cout<<max(a+b,max(a-b,a*b))<<endl;
  return 0;
}


Measured memory_bytes: 764
#include<bits/stdc++.h>
 
using namespace std;
 
#define boost ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define ll long long int
#define vi vector<int>
#define pii pair<int, int>
#define vii vector<pii>
#define B begin()
#define E end()
#define F first
#define S second
#define loop(z, v) for(auto &z: v)
#define nl "\n"
#define fat 1000000007
 
int main()
{
    boost
    int a, b, x;
    cin >> a >> b >> x;

    double p = 2.0*(1.0*b - ((1.0*x) / (a*a)));

    if(p <= b + 1e-4)
        cout << setprecision(9) << (180.0 / M_PI)*atan(p / a) << endl;
    else
    {
        p = 2.0*((1.0*x) / (a*b));
        cout << setprecision(9) << (180.0 / M_PI)*atan(b / p) << endl;
    }
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <stdio.h>
#include <fstream>
#include <algorithm>
#include <string>
#include <map>
#include <set>
#include <queue>
#include <vector>
#include <limits.h>
#include <math.h>

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

using namespace std;

typedef long long ll;
typedef pair<int,int> Pii;
typedef vector<int> vint;

const int MAX_N = 112345;

const ll INF = LONG_LONG_MAX;


int main() {
    // insert code here...    return 0;
    //////
    // input from txt
    /*
     std::ifstream in("input.txt");
     std::cin.rdbuf(in.rdbuf());
     std::ofstream out("output.txt");
     std::cout.rdbuf(out.rdbuf());
     ////
     */
    int N,H;
    cin >> N >> H;
    vint swords_b;
    int max_sword_a=0;
    repeat(i, N){
        int a,b;
        cin >> a >> b;
        max_sword_a = max(max_sword_a,a);
        swords_b.push_back(-b);
    }
    sort(swords_b.begin(),swords_b.end());
    int ans = 0;
    for(auto sword:swords_b){
        if(H <= 0 || -sword < max_sword_a){
            break;
        }
        H += sword;
        ans++;
    }
    while(H>0){
        H -= max_sword_a;
        ans++;
    }
    cout << ans << endl;
    return 0;
}



Measured memory_bytes: 892
using System;
using System.Collections.Generic;
using System.Linq;
using System.Numerics;
using System.Text;
using static System.Console;
using static System.Math;

namespace AtCoder
{
    class Program
    {
        static void Main(string[] args)
        {
            var rbwg = ReadInts();
            WriteLine(rbwg.Sum());
        }
        private static string Read() { return ReadLine(); }
        private static string[] Reads() { return (Read().Split()); }
        private static int ReadInt() { return int.Parse(Read()); }
        private static long ReadLong() { return long.Parse(Read()); }
        private static double ReadDouble() { return double.Parse(Read()); }
        private static int[] ReadInts() { return Array.ConvertAll(Read().Split(), int.Parse); }
        private static long[] ReadLongs() { return Array.ConvertAll(Read().Split(), long.Parse); }
        private static double[] ReadDoubles() { return Array.ConvertAll(Read().Split(), double.Parse); }
    }
}



Measured memory_bytes: 18272
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <cmath>
typedef long long ll;

using namespace std;

class Edge
{
	public:
	int cost;
	int next;

	Edge(int n,int c)
	{
		next=n;
		cost=c;
	}
};

vector<Edge> v[200];
int mind[200];

int main()
{
	for(int i=0;i<200;i++)
	{
		mind[i]=1000000;
	}
	mind[0]=0;
	int n,s;
	int ans;
	cin>>n;
	//1行目
	for(int i=0;i<n;i++)
	{
		int c;
		cin>>c;
		if(i>0)
		{
			v[i-1].push_back(Edge(i,-1*c));
		}
		if(i==0)
		{
			s=c;
		}
	}
	//2行目
	for(int i=0;i<n;i++)
	{
		int c;
		cin>>c;
		//cerr<<i%n<<endl;
		if(i>0)
		{
			v[n+i-1].push_back(Edge(n+i,-1*c));
		}
		v[i].push_back(Edge(n+i,-1*c));
	}

	//ベルマンフォード
	for(int i=0;i<n*2;i++)
	{
		for(int j=0;j<2*n;j++)
		{
			for(int k=0;k<v[j].size();k++)
			{
				Edge e = v[j][k];
				if(mind[j] != 1000000 && mind[e.next] > mind[j]+e.cost)
				{
					mind[e.next] = mind[j]+e.cost;
					if(i==2*n-1)
					{
						//負閉路の存在
						//このプログラムでは空白
						cerr<<"minus loop"<<endl;
					}
				}
			}
		}
	}

	ans = -1*mind[2*n-1];
	ans += s;
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define all(x) x.begin(),x.end()
#define dbg(x) cout<<#x<<":"<<x<<endl
typedef long long ll;
typedef pair<ll,ll> P;
typedef pair<ll,P> PP;

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

  set<ll> s1,s2;
  s1.insert(n);
  s2.insert(1);

  ll ans=0;
  for(ll i=1;i<=n;i++){
    ll k=pa[i];
    ll r=*s1.lower_bound(k);
    ll l=-*s2.lower_bound(-k);
    ans+=i*(k-l)*(r-k);
    //   dbg(k);    dbg(l);    dbg(r);
    //    cout<<endl;
    s1.insert(k);
    s2.insert(-k);
  }
  
  cout<<ans<<endl;
  return 0;
}


Measured memory_bytes: 22272
n, m = map(int, input().split())

if n % 2 == 1:
    a = n // 2
    b = a + 1
    for _ in range(m):
        print(a, b)
        a -= 1
        b += 1
    exit()

a = n // 2
b = a + 1
for i in range(m):
    if i == n // 4:
        a -= 1
    print(a, b)
    a -= 1
    b += 1

Measured memory_bytes: 9272
#include <iostream>
#include <string>
#include <algorithm>
#include <math.h>
#include <vector>
#include <iomanip>
#include <map>
#include <queue>

using namespace std;

#define fori(x) for (int i = 0; i < x; ++i)
#define forj(x) for (int j = 0; j < x; ++j)

typedef long long ll;

const int INF = 2e9 + 5;
const int alength=100100;

int main() {
	int n;
	cin>>n;
	int b[110]={};
	fori(n){cin>>b[i];}
	b[n]=INF;
	int ans=0;
	fori(n){
		if(i==0){
   			ans+=b[0];
    	}else if(i==n-1){
      		ans+=b[n-2];
    	}else{
      		ans+=min(b[i-1],b[i]);
    	}
	}
	cout<<ans;
}

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

using namespace std;

typedef long long ll;
typedef pair<int, int> P;
const int INF = 1000000;

#define N 200005
int a[N];
deque<int> q1,q2;
void push(int x)
{
    while(!q1.empty()&&a[q1.back()]>a[x]) q1.pop_back();
    q1.push_back(x);
    while(!q2.empty()&&a[q2.back()]<a[x]) q2.pop_back();
    q2.push_back(x);
}
int mx[N],mi[N];
signed main()
{

    int n, k; cin >> n >> k;
    for(int i=1;i<=n;i++) cin >> a[i];
    for(int i=1;i<k;i++) push(i);
    int ans=0,res=1;
    for(int i=k;i<=n;i++)
    {
        while(!q1.empty()&&q1.front()<i-k+1) q1.pop_front();
        while(!q2.empty()&&q2.front()<i-k+1) q2.pop_front();
        push(i);
        mi[i]=a[q1.front()],mx[i]=a[q2.front()];
        if(i>k&&mx[i]==a[i]&&mi[i-1]==a[i-k]) continue;
        if(q1.size()==k)
        {
            ans+=res,res=0; continue;
        }
        ans++;
    }
    cout<<ans<<endl;

    return 0;
}

Measured memory_bytes: 2688
s=[int(i) for i in input()]
n=len(s)
ans=0
f=0
for i in range(n-1,-1,-1):
  j=s[i]+f
  if j<5:
    ans+=j
    f=0
  elif j>5:
    ans+=10-j
    f=1
  elif i and s[i-1]>=5:
    ans+=10-j
    f=1
  else:
    ans+=j
    f=0
print(ans+f)

Measured memory_bytes: 108104
#include <bits/stdc++.h>
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; }

using ll = long long;

const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
const int INF = 1<<30;
const ll mod = 1000000007LL;

int main() {
  int N;
  cin>>N;
  vector<int> v(N);
  for(int i = 0; i < N; i++)cin>>v[i];
  map<int,int> m;
  for(int i = 0; i < N; i++) m[v[i]]=i;
  int t = 1;
  int l = 1,M=0;
  while(t<=N){
    if(t==N) {
      chmax(M,l);
      break;
    }
    else if(m[t]<m[t+1]) {
      t++;
      l++;
    }
    else {
      chmax(M,l);
      t++;
      l=1;
    }
  }
  cout<<N-M<<endl;
}
    

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

int main() {

  ld a,b,c;
  cin >> a >> b >> c;

  if (a + (2 * sqrt(a*b)) + b - c < 0) {
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }

  return 0;
}


Measured memory_bytes: 256
#include <stdio.h>

int main(){
  int x,y;
  scanf("%d",&x);
  scanf("%d",&y);
  if(((y&1)^1)&&(y>=(x<<1))&&(y<=(x<<2))){
    printf("Yes");
  }else{
    printf("No");
  }
  return(0);
}

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

using namespace std;

using ll = long long;
void max_self(ll &a ,ll b){
    a = max(a,b);
}

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

vector<ll> dp(w+1,0); // 0,1,2............w
// dp[i] = maximum value of items with total weight 



for(int item =0;item<n;item++){
    ll weight , value;
    cin>>weight>>value;
    for(int w_a = w-weight;w_a>=0;w_a--){


        max_self(dp[w_a + weight] , dp[w_a] + value);


    }
}
ll  answer =0;
for(int i =0;i<=w;i++){
    max_self(answer,dp[i]);
}

cout<<answer;

}


int main(){

    solve();
}

Measured memory_bytes: 1024
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <ctype.h>
#define max(a, b)	(((a) > (b)) ? (a) : (b))		/* ２個の値の最大値 */
#define min(a, b)	(((a) < (b)) ? (a) : (b))		/* ２個の値の最小値 */
#define ENTER		printf("\n")					/* 改行プリント */
/********************************************************************************************************************************/
/* main *************************************************************************************************************************/
/********************************************************************************************************************************/
int DEBUG = 0;										/* デバッグプリント 提出時は0 */
int main()
{
	int		a,b,c,i=0,ans=0;

	scanf("%d %d", &a,&b);

	printf("%d ",a/b);
	printf("%d ",a%b);
	printf("%.5f\n",(double)a/(double)b);
	
	return 0;
}



Measured memory_bytes: 2108
#include<iostream>
#include<vector>
#include<stack>

using namespace std;
int main(){
	int n; cin >> n;
	//int st = 0;
	//bool responce = false;
	//for (int i = 0; i < n; i++){
	//	string str; cin >> str;
	//	if (str == "A"){
	//		if (responce and st > 0){
	//			cout << "NO" << endl;
	//			return 0;
	//		}
	//		st++;
	//		responce = false;
	//	}else if(str == "Un"){
	//		st--;
	//		if (st < 0){
	//			cout << "NO" << endl;
	//			return 0;
	//		}
	//		responce = true;
	//	}
	//}
	//if (st == 0){
	//	cout << "YES" << endl;
	//}else{
	//	cout << "NO" << endl;
	//}


	stack<string> stack;
	for (int i = 0; i < n; i++){
		string str; cin >> str;
		if (str == "A"){
			stack.push("A");
		}else if (str == "Un"){
			if (stack.empty()){
				cout << "NO" << endl;
				return 0;
			}
			stack.pop();
		}
	}
		if (stack.empty()){
			cout << "YES" << endl;
		}else{
			cout << "NO" << endl;
		}
		
return 0;
}

Measured memory_bytes: 3160
#include <bits/stdc++.h>
using namespace std;
using Graph = vector<vector<int>>; // グラフ型
typedef long long ll;
#define _GLIBCXX_DEBUG

 // 深さ優先探索
vector<bool> seen;
int dfs(const Graph &G, ll v) {
    seen[v] = true; // v を訪問済にする
    int score = 0; 

    // v から行ける各頂点 next_v について
    for (auto next_v : G[v]) { 
        if (seen[next_v]) continue; // next_v が探索済だったらスルー

        // 負荷さ優先探索中の処理



        dfs(G, next_v); // 再帰的に探索, 毎回mat渡してええの？
    }
    return score;
} 

/*
//桁数の計算
ll keta(ll num){
  ll ans= 0 ;
  ll rem;

  for (ll i = 4; i >= 0 ; i--){
    rem = pow(10,i);
    ans += (num / rem); 
    num = num % rem;
  }
  return ans;
}
*/



int main() {
  string t;cin>>t;
  for(int i=0;i<t.size();i++){
    if(t.at(i)=='?')
      t.at(i)='D';
  }
  cout<<t<<endl;

  return 0;
}

Measured memory_bytes: 3760
import numpy as np


def main():
    k, n = [int(v) for v in input().split(' ')]
    a = np.array([int(v) for v in input().split(' ')])
    d = np.zeros(a.shape)
    d[1:] = a[1:] - a[:-1]
    d[0] = k - a[-1] + a[0]
    ans = k - np.max(d)
    print(int(ans))


if __name__ == '__main__':
    main()


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

int main() {
  int a, b, c, x, y;
  scanf("%d %d %d %d %d", &a, &b, &c, &x, &y);

  if (x > y) {
    swap(x, y);
    swap(a, b);
  }

  int ans = min(a + b, c * 2) * x;
  y -= x;
  ans += min(b, c * 2) * y;

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

  return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
  int N, K;
  cin >> N >> K;
  vector<int> vec(N);
  for(int i=0; i<N; i++){
    cin >> vec.at(i);
  }      
  
  sort(vec.begin(),vec.end());
  vector<int> all(0);
  set<int> div;
  int a = 2;
  int b = vec.at(0);
  while(b >= a){
    if(b %a == 0){
      div.insert(a);
      b /= a;
    }
    else{
      a++;
    }
  }
  
  for(auto itr = div.begin(); itr != div.end(); itr++){
    int i = *itr;
    for(int j=1; j<N; j++){
      if(vec.at(j) %i != 0){
        break;
      }
      if(j == N-1){
        all.push_back(i);
      }
    }
  }
  
  bool ok = false;
  for(int i=0; i<all.size(); i++){
    if(K %all.at(i) == 0){
      ok = true;
    }
  }
  
  if(all.size() == 0){
    ok = true;
  }
 
  for(int i=0; i<N-1; i++){
    if(vec.at(i) != vec.at(i+1)){
      break;
    }
    if(i == N-2){
      if(vec.at(i) == K){
        ok = true;
      }
      else{
        ok = false;
      }
    }
  }
  
  if(vec.at(N-1) < K){
    ok = false;
  }
  
  if(ok){
    cout << "POSSIBLE" << endl;
  }
  else{
    cout << "IMPOSSIBLE" << endl;
  }
}

Measured memory_bytes: 640
#include <cstdio>
#include <iostream>
#include <array>
#include <vector>
#include <algorithm>
#include <functional>
#include <tuple>
#include <map>
#include <unordered_map>
#include <set>
#include <unordered_set>
#include <queue>
#include <utility>
#include <memory>
#include <valarray>
#include <climits>

using namespace std;

using ll = long long int;

#define loop(i, N) for (int i = 0; i < N; ++i)
#define scanInt(x) int x; scanf("%d", &x); getchar();
#define scanLLInt(x) ll x; scanf("%lld", &x); getchar();
#define scanVecInt(A, N) vector<int> A(N); loop(i, N){scanf("%d", &(A[i])); getchar();}
#define scanVecLLInt(A, N) vector<ll> A(N); loop(i, N){scanf("%lld", &(A[i])); getchar();}

int main()
{
    scanInt(N);
    vector<pair<int, int>> V; V.reserve(N);
    loop(i, N){
        scanInt(xi);
        scanInt(yi);
        V.emplace_back(xi, yi);
    }
    auto dist = [&](int xn, int yn){
        return min(abs(V[xn].first - V[yn].first), abs(V[xn].second - V[yn].second));
    };
    ll result = 0;
    multimap<int, int> xs;
    multimap<int, int> ys;
    loop(i, N){
        xs.emplace(V[i].first, i);
        ys.emplace(V[i].second, i);
    }
    auto remove_i = [&](int c){
        auto xit = xs.equal_range(V[c].first).first;
        while (xit->second != c) ++xit;
        xs.erase(xit);
        auto yit = ys.equal_range(V[c].second).first;
        while (yit->second != c) ++yit;
        ys.erase(yit);
    };
    unordered_set<int> used;
    priority_queue<pair<int, int>, vector<pair<int, int>>, greater<pair<int, int>>> passes;
    // multimap<int, int> passes;
    passes.emplace(0, 0);
    while (used.size() < N){
        // int len = passes.begin()->first;
        // int c = passes.begin()->second;
        // passes.erase(passes.begin());
        int len = passes.top().first;
        int c = passes.top().second;
        passes.pop();

        if (!used.insert(c).second) continue;
        result += len;
        remove_i(c);

        {
            auto xu = xs.lower_bound(V[c].first);
            if (xu != xs.end()) passes.emplace(dist(xu->second, c), xu->second);
            auto xl = xs.upper_bound(V[c].first);
            if (xl != xs.begin()) --xl;
            if (xl != xs.end()) passes.emplace(dist(xl->second, c), xl->second);
            auto yu = ys.lower_bound(V[c].second);
            if (yu != ys.end()) passes.emplace(dist(yu->second, c), yu->second);
            auto yl = ys.upper_bound(V[c].second);
            if (yl != ys.begin())--yl;
            if (yl != ys.end()) passes.emplace(dist(yl->second, c), yl->second);
        }

        // loop(i, N){
        //     if (used.find(i) == used.end()) {
        //         passes.emplace(dist(i, c), i);
        //     }
        // }
    }
    printf("%lld\n", result);
}


Measured memory_bytes: 15848
#include<iostream>
#include<vector>

using namespace std;
   
void primeCal()
{
    const int N = 1000000;
    
    vector<bool> prime(N, true);
    
    prime[0] = prime[1] = false;
    
    for (int i = 2; i*i < N; ++i) 
    {
        if (!prime[i]) 
        { 
            continue; 
        }
        
        for (int j = i*i; j < N; j += i) 
        {
            prime[j] = false;
        }
    }
    
    vector<int> count(N);
    
    for (int i = 1; i < N; ++i) 
    {
        count[i] = count[i-1] + prime[i];
    }
    
    int n;
    
    while (cin>>n)
    {
        cout << count[n] << endl;
    }
    
    return;
}
     
int main()
{     
    primeCal();
    return 0;
}

Measured memory_bytes: 5156
#include <algorithm>
#include <array>
#include <bitset>
#include <cassert>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <functional>
#include <iostream>
#include <map>
#include <memory>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <unordered_map>
#include <vector>

using namespace std;

typedef long long lint;

struct sushi_t {
  lint pos;
  int value;
};

lint solve(lint length, const vector<sushi_t> &sushis) {
  const int n = sushis.size();
  lint result = 0;
  vector<pair<lint, lint>> cands;
  lint acc_value = 0;
  for (int i = 0; i < n; ++i) {
    acc_value += sushis[i].value;
    pair<lint, lint> cand{sushis[i].pos, acc_value - sushis[i].pos};
    result = max(result, cand.second);
    if (cands.empty() || cand.second > cands.back().second)
      cands.push_back(cand);
  }
  acc_value = 0;
  int j = cands.size();
  for (int i = n - 1; i >= 0; --i) {
    acc_value += sushis[i].value;
    while (j - 1 >= 0 && cands[j - 1].first >= sushis[i].pos) --j;
    if (j - 1 >= 0) {
      result = max(result, cands[j - 1].second + acc_value -
                               2LL * (length - sushis[i].pos));
    }
  }
  return result;
}

int main() {
  int n;
  lint length;
  scanf("%d %lld", &n, &length);
  vector<sushi_t> sushis(n);
  for (int i = 0; i < n; ++i)
    scanf("%lld %d", &sushis[i].pos, &sushis[i].value);
  lint result = 0;
  result = max(result, solve(length, sushis));
  for (int i = 0; i < n; ++i)
    sushis[i].pos = length - sushis[i].pos;
  reverse(sushis.begin(), sushis.end());
  result = max(result, solve(length, sushis));
  printf("%lld\n", result);
  return 0;
}


Measured memory_bytes: 5460
#include <bits/stdc++.h>
#define WHOLE(v) (v).begin(), (v).end()
#define REV_WHOLE(v) (v).rbegin(), (v).rend()
using i64 = int64_t;
using namespace std;
int64_t divceil(int64_t a, int64_t b) {
    return a / b + (a > 0 && a % b ? 1 : 0);
}
int main() {
    int N;
    cin >> N;
    i64 x = -1, y = -1;
    for(int i = 0; i < N; i++) {
        i64 a, b;
        cin >> a >> b;
        if(x < 0) {
            x = a, y = b;
        } else {
            i64 n = max(divceil(x, a), divceil(y, b));
            x = a * n, y = b * n;
        }
    }
    cout << (x + y) << endl;
    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<set>
#include<map>
#include<iterator>
using namespace std;

int main()
{
  int n;
  cin>>n;
  int a[n+1];
  map<int,int> m;
  for(int i=0;i<n;i++)
  {
    cin>>a[i];
    m[a[i]]++;
  }
  sort(a,a+n);
  int maxi=a[n-1];
  for(int i=0;i<n;i++)
  {
      for(int j=2;j*a[i]<=maxi;j++)
      {
        m[a[i]*j]=-1;
      }
  }
  int cnt=0;
  for(int i=0;i<n;i++)
  {
    if(a[i]!=-1 && m[a[i]]==1)
      cnt++;
  }
  cout<<cnt;
  return 0;
}


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

using namespace std;

#define ll long int

int main(){

  ll a,b,c,d,sum=0;
  
  cin>>a >>b >>c >>d;
    
    sum = a;
  
  if( a + b > d)
  {
  	 cout<<min(a,d) <<endl;
  }
  else
  {
  		sum = sum - (d - a - b );
    	cout<<sum<<endl;
  }
    
    
	return 0;
}

Measured memory_bytes: 3620
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  string S;
   int A = 0;
  cin >> S;
  if(S[0] == S[1])A++;
  if(S[1] == S[2])A++;
  if(S[2] == S[3])A++;
  if(A > 0){
    cout << "Bad" << endl;
  }
  else{
    cout << "Good"<< endl;
  }
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
const int tot=26+26+10;
char enc(int t){
	if(t<10)return '0'+t;
	t-=10;
	if(t<26)return 'a'+t;
	t-=26;
	return 'A'+t;
}
 
string s[tot];
int sum=tot;
int ttm=0;
int query(string s){
	if(s.length()>128)return 0x3f3f3f3f;
	++ttm;
	if(ttm>=850)while(1);
	cout << "?" << " " << s << endl;
	fflush(stdout);
	int ans=0;
	cin >> ans;
	return ans;
}
 
 
int len=0x3f3f3f3f;
int q[tot];
 
string merge(string a,string b){
	int i=0,j=0;
	int la=a.length(),lb=b.length();
	string fir=string();
	while(i<la&&j<lb){
		string qr=fir;
		qr+=a[i];
		for(int k=j;k<lb;k++){
			qr+=b[k];
		}
		if(query(qr)+qr.length()==len){
			fir+=a[i++];
		}else {
			fir+=b[j++];
		}
	}
	while(i<la)fir+=a[i++];
	while(j<lb)fir+=b[j++];
	return fir;
}
 
int main()
{
	for(int i=0;i<tot;i++){
		s[i]+=enc(i);
		q[i]=query(s[i])+1;
		len=min(len,q[i]);
	}
	for(int i=0;i<tot;i++){
		if(q[i]==len){
			while(query(s[i]+enc(i))+s[i].length()+1==len)s[i]+=enc(i);
		}else s[i]=string();
	}
	while(1){
		for(int i=0;i<tot;i++)for(int j=i+1;j<tot;j++)if(s[i].length()>s[j].length())swap(s[i],s[j]);
		int t=0;
		while(!s[t].length())++t;
		if(t+1==tot)break ;
		string nw=merge(s[t],s[t+1]);
		s[t+1]=nw;
		s[t]=string();
	}
	assert(query(s[tot-1])==0);
	cout << "! "<< s[tot-1] << endl;
	fflush(stdout);
}

Measured memory_bytes: 3772
#include <iostream>

using namespace std;

int main(){
  int a[5];
  cin >> a[0];
  cin >> a[1];
  cin >> a[2];
  cin >> a[3];
  cin >> a[4];

  int min = 0;
  for(int i=1;i<5;i++){
    if(a[min]%10>a[i]%10){
      if(a[i]%10!=0){
	min=i;
      }
    }
  }
  for(int i=0;i<5;i++){
    if(i!=min){
      if(a[i]%10!=0){
	a[i]=a[i]+10-a[i]%10;
      }
    }
  }
  cout << (a[0]+a[1]+a[2]+a[3]+a[4])<< "\n";
  return 0;
}

  


Measured memory_bytes: 256
using System;
using System.CodeDom.Compiler;
using System.Collections.Generic;
using System.Linq;
using System.Text.RegularExpressions;
using System.Xml;

class Program
{
	static void Main(string[] args)
	{
		int[] intArray = Console.ReadLine().Split(' ').Select(i => int.Parse(i)).ToArray();
		int N = intArray[0];
		int M = intArray[1];

		List<int> A = new List<int>(Console.ReadLine().Split(' ').Select(i => int.Parse(i)).ToArray());
		A.Sort();
		A.Reverse();
		decimal line = (decimal)A.Sum() / (decimal)(4 * M);
		Boolean ok = true;
		
		for(int i = 0;i < M; i++)
		{
			if (A[i] < line)
			{
				ok = false;
				break;
			}
		}
		if (ok) Console.WriteLine("Yes");
		else Console.WriteLine("No");
	}
}

//string s = Console.ReadLine();
//int[] intArray = Console.ReadLine().Split(' ').Select(i => int.Parse(i)).ToArray();
//int H = intArray[0];
//int W = intArray[1];
//int N = int.Parse(Console.ReadLine());
//List<int> A = new List<int>(Console.ReadLine().Split(' ').Select(i => int.Parse(i)).ToArray());
//Boolean ok = false;

//Console.WriteLine(ans);
//Console.WriteLine("Yes");
//Console.WriteLine("No");
//Console.ReadKey();

//string[] strArray = Console.ReadLine().Split(' ').ToArray();
//string S = strArray[0];
//string T = strArray[1];


Measured memory_bytes: 13396
#include <iostream>
#include <string>
#include <algorithm>
#include <math.h>
using namespace std;

int x;
bool f[1200];

int pow(int x,int y){
    int val=1;
    for(int i=0;i<y;i++){
        val*=x;
    }
    return val;
}

void op(){
    for(int i=2;i<=34;i++){
        int j=2;
        while(true){
            if(pow(i,j)<=1000){
                f[pow(i,j)]=true;
                j++;
            }
            else break;
        }
    }
}

int main(){

    f[1]=true;
    op();
    cin>>x;
    for(int i=x;i>=1;i--){
        if(f[i]){
            cout<<i<<endl;
            return 0;
        }
    }
}

Measured memory_bytes: 256
N = int(input())
A = [0] * N
X = [[] for _ in range(N)]
for i in range(N):
  A[i] = int(input())
  for j in range(A[i]):
    X[i].append(list(map(int, input().split())))
Truth = 2 ** N
ans = 0
while(bin(Truth) != bin(2 ** (N + 1))):
  for i in range(N):
    if(bin(Truth)[i+3] == "1"):
      for j in range(A[i]):
        if(int(bin(Truth)[X[i][j][0] + 2]) != X[i][j][1]):
          break
      else:
        continue
      Truth += 1
      break
  else:
    ans = sum(list(map(int,list(bin(Truth)[3:]))))
    Truth += 1
print(ans)

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define mp make_pair
long long n,x,tot;
string s;
long long fir(long long k){
    int res;
    while (k>0){
        res=k%10;
        k/=10;
    }
    return res;
}
long long las(long long k){
    return k%10;
}
long long numdigit(long long k){
    int res=0;
    while (k>0){
        k/=10;
        res++;
    }
    return res;
}
long long power(long long k){
    int res=1;
    while (k>0){
        res*=10;
        k--;
    }
    return res;
}
void fill(long long k){
    while (k>0){
        char t=k%10+'0';
        s.pb(t);
        k/=10;
    }
    reverse(s.begin(),s.end());
}
long long memo[10][2];
long long dp(int index,bool ssf,int lastdigit){
    //cout<<index<<' '<<ssf<<' '<<lastdigit<<'\n';
    if (index==x-1){
        //cout<<"me\n";
        if (ssf && lastdigit>s[x-1]-'0'){
            return 0;
        }
        //cout<<"me\n";
        return 1;
    }
    if (memo[index][ssf]!=-1) return memo[index][ssf];
    int largest=9,ans=0;
    if (ssf) largest=s[index]-'0';
    for (int i=0;i<=largest;i++){
        ans+=dp(index+1,ssf && (i==largest),lastdigit);
    }
    //cout<<index<<' '<<ssf<<' '<<lastdigit<<' '<<ans<<'\n';
    return memo[index][ssf]=ans;
}
int main(){
    //ios_base::sync_with_stdio(false);
    //cin.tie(NULL);
    cin>>n;
    if (x==1){
        cout<<n;
        return 0;
    }
    if (n<10){
        for (int i=1;i<=n;i++){
            for (int j=1;j<=n;j++){
                if (fir(i)==las(j) && fir(j)==las(i)){
                    tot++;
                }
            }
        }
        cout<<tot;
        return 0;
    }
    fill(n);
    x=s.size();
    //cout<<x<<' '<<s<<'\n';
    for (int i=1;i<=n;i++){
        int one=fir(i);
        int two=las(i);
        if (one==two) tot++; //one digit
        if (two==0) continue;
        //cout<<i<<' '<<one<<' '<<two<<' ';
        //cout<<tot<<'\n';
        for (int j=1;j<x;j++){
            if (two>s[0]-'0' && j==1) continue;
            memset(memo,-1,sizeof(memo));
            bool lol=true;
            if (j!=1) lol=false;
            if (two!=s[0]-'0') lol=false;
            //cout<<i<<' '<<j<<' '<<lol<<'\n';
            int ans=dp(j,lol,one);
            //cout<<ans<<'\n';
            tot+=ans;
        }
        //cout<<i<<' '<<one<<' '<<two<<' ';
        //cout<<tot<<'\n';
    }
    cout<<tot;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ll long long int
#define M 1000000007
#define mod 998244353
#define mp(x,y) make_pair(x,y)
#define pb(x) push_back(x)
#define pi pair<ll,ll>
#define endl "\n"
using namespace std;
const ll N=500010;

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);

    ll n;
    cin>>n;
    string ss;
    cin>>ss;
    string s="";
    for(int i=0;i<n;++i){
        if(ss[i]=='R'){s+="0";}
        else if(ss[i]=='G'){s+="1";}
        else{s+="2";}
    }

    int pre[n][3];
    for(int i=0;i<n;++i){
        for(int j=0;j<3;++j){
            if(i==0){pre[i][j]=0;}
            else{pre[i][j]=pre[i-1][j];}
        }
        ++pre[i][s[i]-'0'];
    }

    ll ans=0;
    for(ll j=1;j<n;++j){
        for(ll k=j+1;k<n;++k){
            if(s[j]==s[k]){continue;}
            int si=3-(s[j]-'0')-(s[k]-'0');
            ll ch=pre[j-1][si];
            if(j-(k-j)>=0){
                ll i=j-(k-j);
                if(s[i]-'0'==si){--ch;}
            }
            ans+=ch;
        }
    }
    cout<<ans;

    return (0);
}


Measured memory_bytes: 3620
/* Shell Sort */
#include <stdio.h>

int main()
{
    int A[1000000]={0}, N, i, j, k, v, cnt=0, m, G[100]={0};

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

    i = 0;
    G[0] = 1;
    while(1){
        if(G[i] > N){
            m = i;
            break;
        } else {
            G[i+1] = (3 * G[i]) + 1;
            i++;
        }
    }

    for(i=0; i < m; i++){
        for(j = G[m-1-i]; j<N; j++){
            v = A[j];
            k = j - G[m-1-i];
            while(k >= 0 && A[k] > v){
                A[k + G[m-1-i]] = A[k];
                k = k - G[m-1-i];
                cnt++;
            }
            A[k + G[m-1-i]] = v;
        }
    }

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


Measured memory_bytes: 5748
#include<bits/stdc++.h>
#define debug1 cout<<"?"<<endl;
#define debug2 cout<<"?"<<i<<endl;
typedef long long ll;
#define PII pair<ll,ll>
const int maxn=1e5+9;
const double pi=acos(-1);
const int mod=1e9+7;
const int INF=0x3f3f3f3f;
const double ep=1e-10;
using namespace std;
int main()
{
	char s[maxn];
	scanf("%s",s+1);
	int i,len=strlen(s+1);
	for(i=1;i<=len/2;i++)
	{
		if(s[i]!=s[len-i+1])
		{
			puts("No");return 0;
		}
	}
	for(i=1;i<=(len/2)/2;i++)
	{
		if(s[i]!=s[len/2-i+1])
		{
			puts("No");return 0;
		}
	}
	for(i=len/2+2;i<=len;i++)
	{
		if(s[i]!=s[len-i+len/2+2])
		{
			puts("No");return 0;
		}
	}
	puts("Yes");
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0;i < n;i++)
#define ll long long
using namespace std;
//typedef vector<unsigned int>vec;
//typedef vector<ll>vec;
//typedef vector<vec> mat;
typedef pair<int, int> P;
typedef pair<ll,ll> LP;
const int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
const int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};
const int INF = 1000000000;
const ll LINF = 1000000000000000000;//1e18
//const ll MOD = 1000000007;
const ll MOD = 998244353;
const double PI = acos(-1.0);
const double EPS = 1e-10;

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
//template<class T> inline void add(T &a, T b){a = ((a+b) % MOD + MOD) % MOD;};

void solve(){
    int L;
    cin >> L;
    int r = 0;
    ll cur = 1;
    while(cur <= L){
        r++;
        cur *= 2;
    }
    vector<tuple<int, int, int>> ans;
    for(int i=0;i<r-1;i++){
        ans.emplace_back(i+1, i+2, 0);
        ans.emplace_back(i+1, i+2, (1LL<< i));
    }
    for(int i=r-2;i>=0;i--){
        if(L <= (1LL << (i + 1))) continue;
        ll rem = L - (1LL << i);
        if(rem < (1LL << (r - 1))) continue;
        ans.emplace_back(i+1, r, rem);
        L = rem;
    }
    cout << r << " " << ans.size() << endl;
    for(auto [x,y,z] : ans){
        cout << x << " " << y << " " << z << endl;
    }
}

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    solve();
    // int T; cin >> T; REP(t,T) solve();
}


Measured memory_bytes: 3640
use proconio::input;

fn main() {
    input! {
        n: usize,
        mut a: [u128; n]
    }

    a.sort();
    solve(n, &a);
}

fn solve(n: usize, a: &[u128]) {
    let mut m = 1;
    for i in 0..n {
        m *= a[i];

        if m > 10u128.pow(18) {
            println!("-1");
            return;
        }
    }
    println!("{}", m);
}


Measured memory_bytes: 6092
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int a;
  cin >> a;
  if(a == 0){
    cout << "0" << endl;
  }else if(a==1){
    cout << "1" << endl;
  }else if(a==10){
    cout << "1" << endl;
  }else if(a==100){
    cout << "1" << endl;
  }else if(a==11){
    cout << "2" << endl;
  }else if(a==101){
    cout << "2" << endl;
  }else if(a==110){
    cout << "2" << endl;
  }else{
    cout << "3" << endl;
  }
}

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

using namespace std;

int main(int argc, char *argv[])
{
	ios::sync_with_stdio(false); cin.tie(0);
	int a, b, c;
	cin >> a >> b >> c;
	int ans = c - min(a - b, c);
	cout << ans << endl;

	return 0;
}


Measured memory_bytes: 256
import std.stdio, std.array, std.string, std.conv, std.algorithm;
import std.typecons, std.range, std.random, std.math, std.container;
import std.numeric, std.bigint, core.bitop, std.bitmanip;

void main() {
    auto N = readln.chomp.to!int;
    auto A = N.iota.map!(_ => readln.chomp.to!long).array;

    if (A[0] != 0) {
        writeln(-1);
        return;
    }

    if ((N-1).iota.map!(i => A[i+1] - A[i] > 1).any) {
        writeln(-1);
        return;
    }

    long ans = 0;
    foreach (i; 1..N) {
        if (A[i] - A[i-1] == 1)
            ans += 1;
        else if (A[i] > 0)
            ans += A[i];
    }

    ans.writeln;
}


Measured memory_bytes: 4732
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N=1e5+5; 

#define endl "\n"

ll gcd(ll x,ll y){
	if(y) return gcd(y,x%y);
	return x;
} 

ll lcm(ll x,ll y){
	return x/gcd(x,y)*y;
}

int a[N];

int main(){
	ios::sync_with_stdio(0),cin.tie(0),cout.tie(0);
	ll n,m,tmp,X;
	cin>>n>>m;
	X=1;
	for(int i=0;i<n;i++){
		cin>>a[i];
		a[i]>>=1;
		X=lcm(X,a[i]);
		if(X>m) {
			cout<<0<<endl;
			return 0;
		}
	}
	for(int i=0;i<n;i++){
		tmp=X/a[i];
		if(!(tmp&1)){
			cout<<0<<endl;
			return 0;
		}
	}
	ll ans=m/X;
	cout<<((ans+1)>>1)<<endl;
	return 0;
}

Measured memory_bytes: 640
s_o = str(input().strip())
t_o = str(input().strip())
dic = []

for i in range(len(s_o)-len(t_o)+1):
    s = s_o
    t = t_o
    flg = 0
    for j in range(len(t_o)):
        if s[i+j] == t[j] or s[i+j] == "?":
            s = s[:i+j] + t[j] + s[i+j+1:]
        else:
            flg = 1
            break
    if flg:
        continue
    s = s.replace("?", "a")
    dic.append(s)

if len(dic) == 0:
    print("UNRESTORABLE")
else:
    dic.sort()
    print(dic[0])

Measured memory_bytes: 9084
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int N;
  cin >> N;
  int cnt = 0;
  for(int i=0;i<=26;i++){
    for(int j=0;j<=15;j++){
      if(4*i+7*j==N){
        cnt++;
      }
    }
  }
  if(cnt==0){
    cout << "No" << endl;
  }else{
    cout << "Yes" << endl;
  }
}

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

using namespace std;

typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<ld> vld;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;

#define INF ((int)1e9)
#define INFLL ((ll)1e18)
#define MOD (1000000007LL)


int main(int argc, const char * argv[]) {
    int N;
    cin >> N;
    set<pii, greater<pii> > Red;
    set<pii> Blue;
    for (int n = 0; n < N; ++n) {
        int a, b;
        cin >> a >> b;
        Red.insert({a, b});
    }
    for (int n = 0; n < N; ++n) {
        int c, d;
        cin >> c >> d;
        Blue.insert({c, d});
    }
    
    int Res = 0;
    for (auto it = Red.begin(); it != Red.end(); ++it) {
        pii Tmp = *it;
        auto itTmp = Blue.end();
        for (auto it = lower_bound(Blue.begin(), Blue.end(), Tmp); it != Blue.end(); ++it) {
            if ((*it).second > Tmp.second) {
                if (itTmp == Blue.end()) {
                    itTmp = it;
                } else if ((*itTmp).second > (*it).second) {
                    itTmp  = it;
                }
            }
        }
        if (itTmp != Blue.end()) {
            ++Res;
            Blue.erase(itTmp);
        }
    }
    cout << Res << endl;

    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ull = unsigned long long;
#define REP(i,n) for (ll i = 0; i < (n); ++i)
#define RREP(i, n) for (ll i = (n) - 1; i >= 0; --i)
#define ALL(v) (v).begin(), (v).end()


int main(){
    double r;
    cin >> r;
    printf("%.10f\n", 2 * r * M_PI);
    return 0;
}


Measured memory_bytes: 3792
#include<bits/stdc++.h>
using namespace std;
#define int long long
struct node{
  int key;
  node *left,*right,*p;
  node(){}
  node(int key):key(key){left=right=p=NULL;};
};
node *root;
void insert(node z){
  node *y=NULL;
  node *x=root;
  while(x!=NULL){
    y=x;
    if(z.key<x->key) x=x->left;
    else x=x->right;
  }
  z.p=y;
  if(y==NULL) root=new node(z);
  else if(z.key<y->key) y->left=new node(z);
  else y->right=new node(z);
}
bool find(int z){
  node *x=root;
  while(x!=NULL){
    if(z==x->key) return true;
    if(z<x->key) x=x->left;
    else x=x->right;
  }
  return false;
}
node *nxt(node *x){
  if(x->left!=NULL) return nxt(x->left);
  return x;
}
void del(node *x){
  //cout<<x->key<<endl;
  node *y=x->p;
  if(x->left==NULL&&x->right==NULL){
    if(y!=NULL&&y->left==x) y->left=NULL;
    if(y!=NULL&&y->right==x) y->right=NULL;
    delete(x);
    return;
  }
  if(x->left==NULL&&x->right!=NULL){
    if(y!=NULL&&y->left==x) y->left=x->right;
    if(y!=NULL&&y->right==x) y->right=x->right;
    x->right->p=y;
    delete(x);
    return;
  }
  if(x->left!=NULL&&x->right==NULL){
    if(y!=NULL&&y->left==x) y->left=x->left;
    if(y!=NULL&&y->right==x) y->right=x->left;
    x->left->p=y;
    delete(x);
    return;
  }
  node *z=nxt(x->right);
  x->key=z->key;
  del(z);
}
void del(int k){
  node *x=root;
  while(x!=NULL){
    if(k==x->key) break;
    if(k<x->key) x=x->left;
    else x=x->right;
  }
  //cout<<k<<" "<<x->key<<endl;
  del(x);
}
void inorderTreeWalk(node *v){
  if(v==NULL) return;
  inorderTreeWalk(v->left);
  cout<<" "<<v->key;
  inorderTreeWalk(v->right);
}
void preorderTreeWalk(node *v){
  if(v==NULL) return;
  cout<<" "<<v->key;
  preorderTreeWalk(v->left);
  preorderTreeWalk(v->right);
}
signed main(){
  int n;
  cin>>n;
  root=NULL;
  for(int i=0;i<n;i++){
    string s;
    cin>>s;
    //cout<<(root==NULL?-1:root->key)<<endl;
    if(s=="print"){
      inorderTreeWalk(root);
      cout<<endl;
      preorderTreeWalk(root);
      cout<<endl;
      continue;
    }
    int x;
    cin>>x;
    if(s=="insert"){
      insert(node(x));
    }
    if(s=="find"){
      cout<<(find(x)?"yes":"no")<<endl;
    }
    if(s=="delete"){
      del(x);
    }
  }
  return 0;
}

Measured memory_bytes: 21956
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define REP(i, n) for(ll i=0; i<(ll)n; i++)
#define REPR(i, n) for(ll i=(ll)n-1; i>=0; i--)
#define FOR(i, m, n) for(ll i=(ll)m; i<(ll)n; i++)
#define FORR(i, m, n) for(ll i=(ll)m-1; i>=(ll)n; i--)
#define ALL(x) (x).begin(), (x).end()
#define ASC(v) sort(ALL(v));
#define DESC(v) sort(ALL(v), greater<int>());
#define UNIQ(a) sort(ALL(a));(a).resize(unique(ALL(a)) - a.begin());
#define PRINTD(x, d) cout << fixed << setprecision(d) << x << "\n";
#define DEBUG(x) cout<<#x<<": "<<x<<"\n"
const double PI = acos(-1);
ll lcm(ll a, ll b) { return a / __gcd(a, b) * b; }
bool isprime(int x){ int i; if(x<2)return 0; else if(x==2) return 1; if(x%2==0) return 0; for(i=3; i*i<=x; i+=2) if(x%i==0) return 0; return 1; }
int digsum(int n) { int r=0; while(n>0) { r+=n%10; n/=10; } return r; }
vector<string> split(string s, char p){vector<string>v;stringstream m(s);string b;while(getline(m,b,p))v.push_back(b);return v;}
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 (a>b) { a = b; return 1; } return 0; }
struct nya{ nya(){ cin.tie(0); ios::sync_with_stdio(false); } }nyan;

int main(){
    ll N; cin >> N;
    vector<ll> A(N);
    REP(n, N) cin >> A[n];
    DESC(A);
    ll ans = A[0];
    ll i = 1;
    REP(n, N-2) {
        ans += A[i];
        if (n%2==1) i++;
    }
    cout << ans << "\n";
}


Measured memory_bytes: 4760
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
//最大公約数
ll gcd(ll a,ll b)
{
    if(a%b == 0)
        return b;
    else
        return gcd(b, a % b);
}

int main(){
    int n;
    cin >> n;
    ll l[10];
    ll s = 0;
    for (int i = 0; i < n;i++)
    {
        cin >> l[i];
        s += l[i];
    }
    sort(l, l + n);
    if(l[n-1]<s-l[n-1])
        cout << "Yes" << endl;
    else
        cout << "No" << endl;

}

Measured memory_bytes: 256
#include<cstdio>
#include<iostream>

#define NMAX 200

using namespace std;

typedef struct{
	int x;
	int y;
}map;

int main(void){

	int N;
	int n,d;
	int dx[4]={-1, 0, 1, 0};///L D R U
	int dy[4]={ 0, 1, 0,-1};
	map box[NMAX];
	map max,min;
	
	while(1){
		cin>>N;
		if(N==0) break;
		box[0].x=0;
		box[0].y=0;
		for(int i=1;i<N;i++){
			cin>>n>>d;
			box[i].x=box[n].x+dx[d];
			box[i].y=box[n].y+dy[d];
		}
		max.x=box[0].x;
		min.x=box[0].x;
		max.y=box[0].y;
		min.y=box[0].y;
		for(int i=1;i<N;i++){
			if(max.x<box[i].x) max.x=box[i].x;
			if(min.x>box[i].x) min.x=box[i].x;
			if(max.y<box[i].y) max.y=box[i].y;
			if(min.y>box[i].y) min.y=box[i].y;
		}
		cout<<max.x-min.x+1<<" "<<max.y-min.y+1<<endl;
	}

	return 0;
}

Measured memory_bytes: 1160
#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;
using ll = long long;
const ll inf = (1 << 30) - 1;
const ll infll = (1LL << 61) - 1;
const ll mod = 1e9 + 7;

bool compareByBack(pair<ll, ll> a, pair<ll, ll> b) {
    if (a.second != b.second) {
        return a.second < b.second;
    } else {
        return a.first < b.first;
    }
}

int main() {
    ll n, a, b;
    cin >> n;
    vector<pair<ll, ll>> works(n);
    for (int i = 0; i < n; i++) {
        cin >> a >> b;
        works[i] = make_pair(a, b);
    }

    sort(works.begin(), works.end(), compareByBack);
    auto ans = "Yes";
    ll sum = 0;
    for (int i = 0; i < works.size(); i++) {
        sum += works[i].first;
        if (sum > works[i].second) {
            ans = "No";
            break;
        }
    }

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


Measured memory_bytes: 3328
import numpy as np
import math
import sys
sys.setrecursionlimit(10000000)
import heapq


def main():
    N, M = map(int, input().split())
    A = [int(c) for c in input().split()]
    queue = []

    for i in range(N):
        heapq.heappush(queue, - A[i])
    for i in range(M):
        max_ = heapq.heappop(queue)
        heapq.heappush(queue, int(max_/2))
    
    print(- sum(queue))


if __name__ == '__main__':
    main()

Measured memory_bytes: 23128
#include<iostream>
#include<vector>
#include<algorithm>
#include<stdbool.h>
using namespace std;
typedef long long ll;
bool from1[200010] = { false };
bool toN[200010] = { false };

int main(void) {
	ll n, m, a, b;
	cin >> n >> m;
	for (ll i = 0;i < m;i++) {
		cin >> a >> b;
		if (a == 1)from1[b] = true;
		else {
			if (b == n) {
				toN[a] = true;
			}
		}
	}
	for (ll i = 2;i < n;i++) {
		if (from1[i] && toN[i]) {
			cout << "POSSIBLE" << endl;
			return 0;
		}
	}
	cout << "IMPOSSIBLE" << endl;
	return 0;
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define ls (o<<1)
#define rs (o<<1|1)
#define pb push_back
const double PI= acos(-1.0);
const int M = 2e5+7;
/*
int head[M],cnt=1;
void init(){cnt=1,memset(head,0,sizeof(head));}
struct EDGE{int to,nxt,w;}ee[M*2];
void add(int x,int y,int w){ee[++cnt].nxt=head[x],ee[cnt].w=w,ee[cnt].to=y,head[x]=cnt;}
*/
ll a[M],b[M],sm[M];
int main()
{
	ios::sync_with_stdio(false);
  	cin.tie(0);
  	int n,m,k;
  	cin>>n>>m>>k;
  	for(int i=1;i<=n;i++)cin>>a[i];
  	for(int i=1;i<=m;i++)cin>>b[i],sm[i]=sm[i-1]+b[i];
  	ll sa=0;
	  int mx=0;
	for(int i=0;i<=n;i++)
  	{
  		sa+=a[i];
  		if(sa>k)break;
  		int id=upper_bound(sm+1,sm+1+m,k-sa)-sm;
  		id--;
  		mx=max(mx,i+id);
	}
	cout<<mx<<endl;
	return 0;
}

Measured memory_bytes: 8356
#include <stdio.h>
#define MAX 500001


int heap[MAX];
int size;


int left(int i){
  return 2*i;
}


int right(int i){
  return 2*i+1;
}


int parent(int i){
  return i/2;
}


void maxHeapify(int i){
  int l, r, x, largest;

  l = left(i);
  r = right(i);

  if( l < size && heap[l] > heap[i] ){
    largest = l;
  }
  else{ 
    largest = i;
  }

  if( r < size && heap[r] > heap[largest] ){
    largest = r;
  }

  if( largest != i ){
    x = heap[i];
    heap[i] = heap[largest];
    heap[largest] = x;
  
    maxHeapify(largest);
  }

}


void buildMaxHeap(void){
  int i;

  for( i = size/2; i > 0; i--){
    maxHeapify(i);
  }
  
}


main(){
  int i;

  scanf("%d", &size);

  size = size + 1;

  for( i = 1; i < size; i++){
    scanf("%d", &heap[i]);
  }

  buildMaxHeap();

  for( i = 1; i < size; i++){
    
    printf(" %d", heap[i]);

  }

  printf("\n");

  return 0;

}

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

using namespace std;
typedef long long int ll;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef vector<VI> VVI;
typedef vector<VL> VVL;
typedef pair<int, int> P;
typedef pair<ll, ll> PL;
#define FOR(i, a, b) for(int i = 0; i < (a); ++i)
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define all(obj) (obj).begin(), (obj).end()
#define rall(obj) (obj).rbegin(), (obj).rend()
#define debug(x) cout << #x << ": " << x << endl
#define out(x) cout << x << endl
//#define int long long int
const int MOD = 1000000007;
const ll LINF = (ll)1e18 - 1;
const int INF = 1e9 - 1;
const double EPS = 0.000000001;
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};

void print(const vector<int> &v) {
  for(auto x : v) {
    cout << x << " ";
  }
  cout << endl;
}

signed main()
{
  cin.tie(0);
  ios::sync_with_stdio(false);
  string s, t;
  cin >> s >> t;
  int n, m;
  n = s.size();
  m = t.size();
  s = s + s;
  map<char, vector<int>> mp;
  rep(i, 2 * n) {
    mp[s[i]].push_back(i);
  }
  bool flag = true;
  rep(i, m) {
    if(mp.find(t[i]) == mp.end()) flag = false;
  }
  ll ans = 0;
  int po = 0;
  if(flag) {
    rep(i, m) {
      auto it = lower_bound(all(mp[t[i]]), po);
      ans += *it - po + 1;
      po = (*it + 1) % n;
    }
  }
  else ans = -1;
  out(ans);
  return 0;
}


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

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
	int n,k;
	cin>>n>>k;
	vector<int> vec(n),vec1,vec2;
	for(int i=0;i<n;++i)
	{
		cin>>vec[i];
		
	}

	for(int i=0;i<n;++i)
	{
		if(vec[i]<0)
			vec1.push_back(vec[i]);
		else
			vec2.push_back(vec[i]);
	}

	long long min=9999999999999ll;
	int n1=vec1.size(),n2=vec2.size();
	for(int i=0;i<n1;++i)
	{
		int flag=0;
		long long temp1=n1-i;
		long long a=abs(vec1[i]);
		long long b=0;
		long long temp2=k-temp1;
		if(temp2<=0)
			flag=1;
		int x=temp2-1;
		if(x>=0&&x<n2)
		{
			flag=1;
			b=vec2[temp2-1];
		}
		if(flag==1)
		{
		long long count1=2*a+b;
		long long count2=a+2*b;
		long long count=std::min(count1,count2);
		if(count<min)
		{
			min=count;
		}
	}
	}

	
	for(int i=0;i<n2;++i)
	{
		int flag=0;
		long long temp1=i+1;
		long long a=abs(vec2[i]);
		long long b=0;
		long long temp2=k-temp1;
		if(temp2<=0)
			flag=1;
		int x=n1-temp2;
		if(x>=0&&x<n1)
		{
			flag=1;
			b=abs(vec1[x]);
		}
		if(flag==1)
		{
		long long count1=2*a+b;
		long long count2=a+2*b;
		long long count=std::min(count1,count2);
		if(count<min)
		{
			min=count;
		}
	}
	}

	cout<<min<<endl;


}


Measured memory_bytes: 1404