akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
int main(){
  long long n, a, b;
  cin>>n>>a>>b;
  if((b - a) % 2){
    long long x = (b - a) / 2;
  	long long ans = min(a, n - b + 1) + x;
  	cout<<ans<<endl;
  }
  else{
    cout<<(b - a) / 2<<endl;
  }
  return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
#include<stdlib.h>
#include<string.h>

#define YOSHI 1000000

struct Node{
    int key;
    struct Node *left;
    struct Node *right;
    struct Node *parent;
};

struct Node *root,*NIL;

void insert(int k){
    struct Node *y = NIL;
    struct Node *x = root;
    struct Node *z;
    
    z = (struct Node *)malloc(sizeof(struct Node));
    z -> key = k;
    z -> left = NIL;
    z -> right = NIL;
    
    while(x != NIL){
        y = x;
        if(z -> key < x -> key){
            x = x -> left;
        }
        else{
            x = x -> right;
        }
    }
    z -> parent = y;
    if(y == NIL){
        root = z;
    }
    else{
        if(z -> key < y -> key){
            y -> left = z;
        }
        else{
            y -> right = z;
        }
    }
}

void inorder(struct Node *u){
    if(u == NIL){
        return;
    }
    inorder(u -> left);
    printf(" %d",u -> key);
    inorder(u -> right);
}

void preorder(struct Node *u){
    if(u == NIL){
        return;
    }
    printf(" %d",u -> key);
    preorder(u -> left);
    preorder(u -> right);
}

void *find(struct Node *u,int k){
    while((u != NIL) && (k != u -> key)){
        if(k < u -> key){
            u = u -> left;
        }
        else{
            u = u -> right;
        }
    }
    return u;
}

int main(){
    int m,i,x;
    char com[6];
    struct Node *t;
    scanf("%d",&m);
    
    for(i = 0;i < m;i++){
        scanf("%s",com);
        if(strcmp(com,"insert") == 0){
            scanf("%d",&x);
            insert(x);
        }
        else if(strcmp(com,"print") == 0){
            inorder(root);
            printf("\n");
            preorder(root);
            printf("\n");
        }
        else if(strcmp(com,"find") == 0){
            scanf("%d",&x);
            t = find(root,x);
            if(t != NIL){
                printf("yes\n");
            }
            else{
                printf("no\n");
            }
        }
    }
    return 0;
}


Measured memory_bytes: 20480
program main
    implicit none
    integer n
    integer, allocatable, dimension(:) :: b, c
    integer i
    read(*,*) n
    allocate(b(n-1))
    allocate(c(n))
    read(*,*) b

    do i = 1, n
        c(i) = 0
    end do

    do i = 1, n-1
        c(b(i)) = c(b(i)) + 1
    end do

    do i = 1, n
        write(*,*) c(i)
    end do

end program

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

using namespace std;

using ll = long long;
using P = pair<ll, ll>;
using Graph = vector<vector<ll>>;
#define rep(i, n) for(ll i=0;i<(ll)(n);i++)
#define rep2(i, m, n) for(ll i=m;i<(ll)(n);i++)
#define rrep(i, n, m) for(ll i=n;i>=(ll)(m);i--)
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
const int ddx[8] = {0, 1, 1, 1, 0, -1, -1, -1};
const int ddy[8] = {1, 1, 0, -1, -1, -1, 0, 1};
const ll MOD = 1000000007;
const ll INF = 1000000000000000000L;
#ifdef __DEBUG

/**
 * For DEBUG
 * https://github.com/ta7uw/cpp-pyprint
 */
#include "cpp-pyprint/pyprint.h"

#endif

long double f(long double a, long double b, long double theta) {
    if(theta > M_PI_2 - 1e-10) {
        return 0.0;
    }
    long double ret;
    if(a * tan(theta) <= b) {
        ret = a * a * b - a * a * a * tan(theta) / 2.0;
    } else {
        ret = b * b / tan(theta) * a / 2.0;
    }
    return ret;
}

void Main() {
    long double a, b, x;
    cin >> a >> b >> x;
    long double ok = M_PI_2;
    long double ng = 0.0;
    long double eps = 1e-10;

    while (ok - ng > eps) {
        long double mid = (ok + ng) / 2.0;
        if (f(a, b, mid) < x) {
            ok = mid;
        }else{
            ng = mid;
        }
    }
    cout << ok / M_PI * 180 << '\n';
}

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(15);
    Main();
    return 0;
}


Measured memory_bytes: 512
#include <bits/stdc++.h>
const int MAX = 1e6 + 10;
typedef long long i64;
using namespace std;
const double EPS = 1e-6;
const int MOD = 1e9 + 7;
#define mul(a, b) ((i64)(a) * b % MOD)
int dp[2][55];
int main() {

    #ifdef LOCAL_DEBUG
    freopen ("data.in", "r", stdin );
    //freopen ("data.out", "w", stdout );
    #endif
    ios_base::sync_with_stdio(0); cin.tie(0);
    #define endl '\n'

   int n; cin >> n;
   map<int, int> M;
   for(int i = 0; i < n ; i++){
	   int a; cin >> a;
	   M[a] += 1;
   }
   int ss = 0;
   pair<int, int> ans;
   for(auto ii = M.rbegin(); ii != M.rend(); ii++){
	   if(ii->second >= 4){
		   ans.second = ii->first;
		   if(ss == 0){
			   ans.first = ii->first;
		   }
		   break;
	   }
	   else if(ii->second >= 2){
		   if(ss == 0){
			   ans.first = ii->first;
			   ss++;
		   }
		   else{
			   ans.second = ii->first;
			   break;
		   }
	   }
   }
   cout << (i64)ans.first *ans.second;
}



Measured memory_bytes: 4992
#include<stdio.h>
#include<stdlib.h>
#include<string.h>

typedef struct TREE{
	int id;
	struct TREE *parent;
	struct TREE *child[2];
	int depth;
	int height;
}Tree;

void insert(Tree **root, Tree *z){
	Tree *y = NULL;
	Tree *x = *root;
	while( x != NULL ){
		y = x;
		if( z->id < x->id ){
			x = x->child[0];
		}else{
			x = x->child[1];
		}
	}
	z->parent = y;
	if( y == NULL ){
		*root = z;
	}else if( z->id < y->id ){
		y->child[0] = z;
	}else{
		y->child[1] = z;
	}
	return;
}

Tree* find(Tree *node, int key){
	if( key < node->id ){
		if( node->child[0] == NULL ){ return NULL; }
		return find(node->child[0], key);
	}else if( key > node->id ){
		if( node->child[1] == NULL ){ return NULL; }
		return find(node->child[1], key);
	}
	return node;
}

Tree* getNextNode(Tree *node){
	if( node->child[0] == NULL ){ return node; }
	return getNextNode(node->child[0]);
}

int delete(Tree **root, int key){
	Tree *node = find(*root, key);
	Tree *p = node->parent;
	if( node->child[0] == NULL && node->child[1] == NULL ){
		if( p != NULL ){
			free(node);
			p->child[(p->child[0]==node?0:1)] = NULL;
		}else{
			free(node);
			*root = NULL;
		}
	}else if( node->child[0] != NULL && node->child[1] != NULL ){
		Tree *nextNode = getNextNode(node->child[1]);
		int nnk = nextNode->id;
		delete(root, nnk);
		node->id = nnk;
	}else{
		//?????????????????????NULL??§?????????
		Tree *child = (node->child[0]!=NULL?node->child[0]:node->child[1]);
		if( p != NULL ){
			p->child[(p->child[0]==node?0:1)] = child;
			child->parent = p;
		}else{
			*root = child;
			child->parent = NULL;
		}
		free(node);
	}
	return 0;
}

int setDepthHeight(Tree *nt, int depth){
	if( nt == NULL ){ return -1; }
	nt->depth = depth;
	int lh = setDepthHeight(nt->child[0], depth+1);
	int rh = setDepthHeight(nt->child[1], depth+1);
	nt->height = (lh>rh?lh:rh) + 1;
	return nt->height;
}

void preOrder(Tree *tr){
	if( tr == NULL ){ return; }
	printf(" %d", tr->id);
	preOrder(tr->child[0]);
	preOrder(tr->child[1]);
	return;
}

void inOrder(Tree *tr){
	if( tr == NULL ){ return; }
	inOrder(tr->child[0]);
	printf(" %d", tr->id);
	inOrder(tr->child[1]);
	return;
}

void postOrder(Tree *tr){
	if( tr == NULL ){ return; }
	postOrder(tr->child[0]);
	postOrder(tr->child[1]);
	printf(" %d", tr->id);
	return;
}

void print(Tree *root){
	inOrder(root);
	printf("\n");
	preOrder(root);
	printf("\n");
	return;
}

int main(){
	int n, id, i, j;
	char str[128];
	Tree *root = NULL, *temp = NULL;
	scanf("%d", &n);
	for( i = 0; i < n; i++ ){
		scanf("%s", str);
		if( strcmp(str, "insert") == 0 ){
			scanf("%d", &id);
			scanf("%c", &str[0]);
			temp = (Tree*)malloc(sizeof(Tree));
			temp->id = id;
			temp->parent = NULL;
			temp->child[0] = NULL;
			temp->child[1] = NULL;
			insert(&root, temp);
		}else if( strcmp(str, "print") == 0 ){
			print(root);
		}else if( strcmp(str, "find") == 0 ){
			scanf("%d", &id);
			printf("%s\n", (find(root, id)!=NULL?"yes":"no"));
		}else if( strcmp(str, "delete") == 0 ){
			scanf("%d", &id);
			delete(&root, id);
		}
	}
	setDepthHeight(root, 0);
	return 0;
}

Measured memory_bytes: 19364
import java.util.Scanner;

public class Main {

	public static int gcd(int a, int b) {
		if(a < b) {
			int tmp = a;
			a = b;
			b = tmp;
		}
		int r = a % b;
		if(r == 0)return b;
		return gcd(b, r);
	}
	
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int a = sc.nextInt(), b =sc.nextInt();
		sc.close();
		int g = gcd(a, b), ans = 0;
		if(g == a)ans = a + b;
		else ans = b - a;
		System.out.println(ans);
	}

}


Measured memory_bytes: 22868
n = int(input())
li = [list(map(int, input().split())) for _ in range(n)]

ans = 0

for i in range(n-1, -1, -1):
    a = li[i][0]
    b = li[i][1]
    
    a += ans
    
    if a%b == 0:
        continue
    s = b - a%b
    ans += s
    
print(ans)

Measured memory_bytes: 27380
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define i_7 (ll)(1E9+7)
//#define i_7 998244353
#define i_5 i_7-2
ll mod(ll a){
    ll c=a%i_7;
    if(c>=0)return c;
    else return c+i_7;
}
typedef pair<ll,ll> l_l;
ll inf=(ll)1E17;
#define rep(i,l,r) for(ll i=l;i<=r;i++)
#define pb push_back
ll max(ll a,ll b){if(a<b)return b;else return a;}
ll min(ll a,ll b){if(a>b)return b;else return a;}
void Max(ll &pos,ll val){pos=max(pos,val);}//Max(dp[n],dp[n-1]);
void Min(ll &pos,ll val){pos=min(pos,val);}
void Add(ll &pos,ll val){pos=mod(pos+val);}
long double EPS=1E-9;
#define fastio ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
////////////////////////////////////////

#define no {No();return 0;}
void No(){
    cout<<-1<<endl;
}

int main(){fastio;
    string s;cin>>s;
    ll n=s.size();
    s=' '+s;
    if(s[n]=='1')no
    if(s[1]=='0')no
    vector<ll>v;
    for(ll i=1;i*2<=n;i++){
        if(s[i]!=s[n-i])no
        if(s[i]=='1')v.pb(i);
    }
    ll c=v.size();
    ll pos=c+1;
    rep(i,2,c){
        //cout<<"a ";
        cout<<i-1<<" "<<i<<endl;
    }
    rep(i,1,c-1){
        if(v[i-1]+2<=v[i])rep(j,v[i-1]+2,v[i]){
           // cout<<"b ";
            cout<<i+1<<" "<<pos<<endl;
            pos++;
        }
    }
    //cout<<"c ";
    cout<<c<<" "<<pos<<endl;
    rep(i,pos+1,n){
        //cout<<"d ";
        cout<<pos<<" "<<i<<endl;
    }
    
    
    
    return 0;
}





Measured memory_bytes: 2024
#include<cstdio>
#include<bits/stdc++.h>
#include<iostream>
#include<algorithm>
#include<queue>
#include<string>
using  ll = long long;
using namespace std;

int main(){
  string s; cin >> s;
  int L = s.size();
  cout << s[0] << L-2 << s[L-1] << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
using namespace std;
using ll = long long;

int n;

#include <vector>
template <typename T>
void print(vector<T> vec)
{
    int n = vec.size();
    for (int i = 0; i < n; i++)
    {
        cout << vec[i] << (i == n - 1 ? "\n" : " ");
    }
}

template <typename T>
void insertionSort(vector<T> &A, int g, int &cnt)
{
    int n = A.size();
    for (int i = g; i < n; i++)
    {
        int v = A[i], j = i - g;
        while (j >= 0 && A[j] > v)
        {
            A[j + g] = A[j], j = j - g, cnt++;
        }
        A[j + g] = v;
    }
}

#include <algorithm>
template <typename T>
void shellSort(vector<T> &A, int &cnt)
{
    cnt = 0;
    int n = A.size();
    vector<int> G;
    G.push_back(1);
    while (3 * G.back() + 1 < n)
    {
        G.push_back(3 * G.back() + 1);
    }
    int m = G.size();
    cout << m << endl;
    for (int i = m - 1; i >= 0; i--)
    {
        cout << G[i] << (i == 0 ? "\n" : " ");
    }
    for (int i = m - 1; i >= 0; i--)
    {
        insertionSort(A, G[i], cnt);
    }
}

int main()
{
    cin >> n;
    vector<int> v(n);
    for (int i = 0; i < n; i++)
    {
        cin >> v[i];
    }
    int c;
    shellSort(v, c);
    cout << c << endl;
    for (int i = 0; i < n; i++)
        cout << v[i] << endl;
}


Measured memory_bytes: 6768
<?php

$input = explode(' ', trim(fgets(STDIN)));
$N = $input[0];
$K = $input[1];
$h = explode(' ', trim(fgets(STDIN)));
$dp = [0];

for ($i = 1; $i < $N; ++$i) {
    $min = null;
    for($j = 1; $j <= $K; ++$j) {
      $cost = isset($h[$i - $j]) ? abs($h[$i] - $h[$i - $j]) + $dp[$i - $j] : null;
      if ($min === null || ($min > $cost && $cost !== null)) {
        $min = $cost;
      }
    }

    $dp[] = $min;

}

echo $dp[$N - 1].PHP_EOL;


Measured memory_bytes: 19060
#include <iostream>
#include <iomanip>
#include <ios> 
#include <vector>
#include <string>
#include <algorithm>
#include <functional>
#include <queue>
#include <stack>
#include <set>
#include <cmath>
#include <bitset>
#include <map>
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define rep1(i,n) for(int i=1;i<=(int)(n);i++)

using namespace std;
typedef long long int lli;
const int MAX=1e5+5;



int main(){
	int N;
	cin>>N;
	lli A[MAX],B[MAX];
	rep(i,N)cin>>A[i];
	rep(i,N)cin>>B[i];
	
	//できるか判定
	lli suma=0,sumb=0;
	rep(i,N){
		suma+=A[i];
		sumb+=B[i];
	}
	if(suma<sumb){
		cout<<-1;
		return 0;
	}
	lli D[MAX];
	rep(i,N)D[i]=A[i]-B[i];
	
	lli mn=0;
	vector<lli> pl;
	rep(i,N){
		if(D[i]>=0){
			pl.push_back(D[i]);
		}else{
			mn+=D[i];
		}
	}
	int l=pl.size();
	sort(pl.begin(),pl.end(),greater<lli>());
	int ch=0;
	while(mn<0){
		lli x=pl[ch];
      	ch++;
		mn+=x;
	}
	cout<<ch+(N-l);
}

Measured memory_bytes: 3576
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<(n);i++)
#define all(a) (a).begin(),(a).end()
#define ll long long
int main(){
  int K;
  cin>>K;
  cout<<(K/2)*((K+1)/2)<<endl;
}

Measured memory_bytes: 256
x,y=map(int,input().split())
d=[0,300000,200000,100000]
if x==1 and y==1:
    a=1000000
elif 1<=x<=3 and 1<=y<=3:
    a=d[x]+d[y]
elif 1<=x<=3:
    a=d[x]
elif 1<=y<=3:
    a=d[y]
else:
    a=0
print(a)

Measured memory_bytes: 3060
#include <iostream>
#include <vector>
#include <cmath>
#include <iomanip>

using vector = std::vector<int >;
using iterator = vector::iterator;

void partition(iterator begin, iterator end)
{
  auto pivot = *(end-1);
  auto swap = [](iterator a, iterator b){
                auto tmp = *a;
                *a = *b;
                *b = tmp;
              };

  auto left_end = begin - 1;
  for (auto itr = begin; itr<end; ++itr)
    {
      if (*itr <= pivot)
        {
          ++left_end;
          swap(itr, left_end);
        }
    }
  //swap(++left_end, end-1);

  for (auto itr=begin; itr<end; ++itr)
    {
      if (itr == left_end)
        {
          std::cout << "[" << pivot << "]";
        }
      else
        {
          std::cout << *itr;
        }

      if (itr == end-1) std::cout << std::endl;
      else std::cout << " ";
    }
}


int main ()
{
  int n;
  vector vec;

  std::cin >> n;
  for (int i=0; i<n; ++i)
    {
      int tmp;
      std::cin >> tmp;
      vec.push_back(tmp);
    }

  partition(vec.begin(), vec.end());
}



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

int main(){
  int x, a, b;
  cin >> x >> a >> b;
  if ((x-a)*(x-a)>(x-b)*(x-b)){//絶対値ってどうやってやるんだ、調べるのかったりい
    cout << "B" << endl;
  }else{
    cout << "A" << endl;
  }
}

Measured memory_bytes: 256
#include <iostream>
#include <sstream>
#include <iomanip>
#include <algorithm>
#include <functional>
#include <iterator>
#include <numeric>
#include <cstdint>
#include <cmath>
#include <bitset>
#include <string>
#include <list>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>

#define N_TIMES(i, n)     for ( uint64_t i = 0;     i <  n; ++i )
#define N_TIMES_REV(i, n) for (  int64_t i = n - 1; i >= 0; --i )

using namespace std;

const uint64_t INF = static_cast<uint64_t>(-1);

struct Edge
{
  uint64_t A, B;
  Edge(uint64_t A = INF, uint64_t B = INF) : A(A), B(B) {}
};

istream& operator>>(istream &is, Edge &edge)
{
  is >> edge.A >> edge.B;
  return is;
}

struct Exchange
{
  uint64_t C, D;
  Exchange(uint64_t C = INF, uint64_t D = INF) : C(C), D(D) {}
  long double rate() const {
    return static_cast<long double>(C) / static_cast<long double>(D);
  }
  bool operator<(const Exchange &ex) const {
    return C * ex.D < D * ex.C;
  }
};

istream& operator>>(istream &is, Exchange &exchange)
{
  is >> exchange.C >> exchange.D;
  return is;
}

struct SearchItem
{
  uint64_t pos, silver, time;
  SearchItem(uint64_t pos, uint64_t silver, uint64_t time)
    : pos(pos), silver(silver), time(time) {}
  bool operator<(const SearchItem &item) const {
    return time > item.time;
  }
};

int main()
{
  uint64_t N, M, S;
  cin >> N >> M >> S;

  uint64_t A_max = 0;
  vector<vector<Edge>> edges(N, vector<Edge>(N));
  N_TIMES(m, M) {
    uint64_t U, V;
    Edge E;

    cin >> U >> V >> E;
    --U; --V;
    edges[U][V] = E;
    edges[V][U] = E;
    A_max = max(A_max, E.A);
  }

  vector<Exchange> exchanges(N);
  N_TIMES(n, N) { cin >> exchanges[n]; }

  vector<vector<uint64_t>> times(N, vector<uint64_t>(A_max * N, INF));
  if (S > A_max * N) { S = A_max * N - 1; }
  times[0][S] = 0;

  priority_queue<SearchItem> q;
  q.emplace(0, S, 0);

  while (!q.empty()) {
    SearchItem item = q.top(); q.pop();
    if (item.time == INF) { continue; }

    // 移動
    N_TIMES(v, N) {
      Edge edge = edges[item.pos][v];
      // 線路があり，かつ運賃を支払える
      if ((edge.B != INF) && (edge.A <= item.silver)) {
        SearchItem new_item(v, item.silver - edge.A, item.time + edge.B);
        if (new_item.time < times[new_item.pos][new_item.silver]) {
          times[new_item.pos][new_item.silver] = new_item.time;
          q.push(new_item);
        }
      }
    }

    // 両替
    Exchange exchange = exchanges[item.pos];
    if (item.silver + exchange.C < A_max * N) {
      SearchItem new_item(item.pos, item.silver + exchange.C, item.time + exchange.D);
      if (new_item.time < times[new_item.pos][new_item.silver]) {
        times[new_item.pos][new_item.silver] = new_item.time;
        q.push(new_item);
      }
    }
  }

  for (uint64_t n = 1; n < N; ++n) {
    uint64_t ans = INF;
    N_TIMES(s, A_max * N) { ans = min(ans, times[n][s]); }
    cout << ans << endl;
  }

  return 0;
}

Measured memory_bytes: 7456
n,m=map(int,input().split())
K=[]
for i in range(m):
    _,*a=map(int,input().split())
    K.append(a)
P=list(map(int,input().split()))

ans=0
for i in range(2**n):
    S=[]
    flag=0
    for j in range(n):
        S.append(i>>j)
    for j in range(m):
        lamp=K[j]
        cnt=0
        for k in lamp:
            cnt+=S[k-1]
        if cnt%2!=P[j]:
            flag=1
            break
    if flag==0:
        ans+=1
print(ans)

Measured memory_bytes: 3188
n = int(input())
for i in range(1,n+1):
    x = i
    if x%3 == 0:
        print(f' {i}',end='')
        continue
    while x>0:
        if x%10 == 3:
            print(f' {i}',end='')
            break
        x = int(x/10)
print()


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

using namespace std;

int main() {
   ios_base::sync_with_stdio(false); cin.tie(nullptr);
   int N; cin >> N;
   map<pair<int, int>, int> cnts;
   while (N--) {
      string s; cin >> s;
      int64_t up = 0;
      int pivot = find(s.begin(), s.end(), '.') - s.begin();
      for (int i = 0; i < pivot; ++i) {
         up = up * 10 + s[i] - '0';
      }
      int64_t down = 1;
      for (int i = pivot + 1; i < s.size(); ++i) {
         up = up * 10 + s[i] - '0';
         down = down * 10;
      }
      int cnt2 = 0;
      int cnt5 = 0;
      while (up % 2 == 0) cnt2++, up /= 2;
      while (up % 5 == 0) cnt5++, up /= 5;
      while (down % 2 == 0) cnt2--, down /= 2;
      while (down % 5 == 0) cnt5--, down /= 5;
      cnts[{cnt2, cnt5}]++;
   }
   int64_t ans = 0;
   for (auto z0 : cnts) {
      for (auto z1 : cnts) {
         if (z0 > z1) continue;
         bool good = z0.first.first + z1.first.first >= 0 && z0.first.second + z1.first.second >= 0;
         if (good) {
            if (z0 == z1) ans += int64_t(z0.second) * (z0.second - 1) / 2;
            else ans += int64_t(z0.second) * z1.second;
         }
      }
   }
   cout << ans << '\n';
   return 0;
}


Measured memory_bytes: 3628
#include <algorithm>
#include <cmath>
#include <iostream>
#include <string>
#include <vector>

using namespace std;
using ll = long long;

int main() {
  int A, B, C, X, Y;
  cin >> A >> B >> C >> X >> Y;
  ll price;
  if (A + B >= 2 * C) {
    // ABの方がトク
    int AB = min(X, Y);
    price = (2 * C * AB);
    if (X > Y) {
      price += A * (X - Y);
    } else {
      price += B * (Y - X);
    }
    if (price > 2 * C * max(X, Y)) {
      price = 2 * C * max(X, Y);
    }
  } else {
    price = A * X + B * Y;
  }
  cout << price << endl;
  return 0;
}

Measured memory_bytes: 256
#include <stdio.h>

#define min(a, b) (((a) < (b)) ? (a) : (b))
#define max(a, b) (((a) > (b)) ? (a) : (b))

#define INF 1000000000

inline int nextInt(void) {
	int ch;
	int sign, x;

	do {
		ch = getchar();
	} while (ch < '-');

	if (ch == '-') {
		sign = -1;
		ch = getchar();
	} else
		sign = 1;

	x = 0;
	while (ch >= '0' && ch <= '9') {
		x = x * 10 + ch - '0';
		ch = getchar();
	}

	return sign * x;
}

int main(void) {
	int i, j, o;
	int n, m, l, k, a, h;

	while (scanf("%d %d %d %d %d %d", &n, &m, &l, &k, &a, &h), n) {
		int canFreeze[100] = {0}, adj[100][100];

		canFreeze[a] = canFreeze[h] = 1;
		for (i = 0; i < l; i++)
			canFreeze[nextInt()] = 1;

		for (i = 0; i < n; i++)
			for (j = 0; j < n; j++)
				adj[i][j] = INF;
		for (i = 0; i < k; i++) {
			const int x = nextInt(), y = nextInt(), t = nextInt();
			adj[x][y] = adj[y][x] = t;
		}

		for (o = 0; o < n; o++)
			for (i = 0; i < n; i++)
				for (j = 0; j < n; j++)
					adj[i][j] = min(adj[i][j], adj[i][o] + adj[o][j]);

		for (i = 0; i < n; i++)
			for (j = 0; j < n; j++)
				if (!canFreeze[i] || !canFreeze[j] || adj[i][j] > m)
					adj[i][j] = INF;

		for (o = 0; o < n; o++)
			for (i = 0; i < n; i++)
				for (j = 0; j < n; j++)
					adj[i][j] = min(adj[i][j], adj[i][o] + adj[o][j]);

		if (adj[a][h] != INF)
			printf("%d\n", adj[a][h] + max(0, adj[a][h] - m));
		else
			puts("Help!");
	}

	return 0;
}

Measured memory_bytes: 656
#include<iostream>
#include<algorithm>
#include<vector>
#include<map>
#include<cstdint>
#include<cassert>
#include<cstdlib>
template<typename T>
void fin(T const& t){ std::cout << t << std::endl; exit(0); }

int main() {
  std::cin.tie(0); std::ios::sync_with_stdio(false);
  int N;  std::cin >> N;
  std::vector<std::pair<int,int>> AB(N);
  for(int i = 0; i < N; ++i) std::cin >> AB[i].first >> AB[i].second;
  int64_t ans = 0, cur;
  auto reduce = [&]()->int64_t {
    std::sort(AB.begin(), AB.end(),
      [&](auto const& l, auto const& r){ return l.first-l.second < r.first-r.second; });
    if(AB.front().first==AB.front().second && AB.back().first==AB.back().second) return 0;
    int64_t sum = 0;
    int i = 0;
    while(AB[i].first <= AB[i].second) {
      sum += AB[i].second;
      ++i;
    }
    for(int j = 0; j+i < AB.size() ; ++j) AB[j] = AB[j+i];
    AB.resize(AB.size() - i);
    std::sort(AB.begin(), AB.end(),
      [&](auto const& l, auto const& r){ return l.second > r.second; });
    for(auto& p: AB) p.first = p.second;
    --AB.front().first;
    ++AB.back().first;
    return sum;
  };
  while((cur = reduce()) > 0) ans += cur;
  fin(ans);
  return 0;
}


Measured memory_bytes: 384
#include <iostream>
#include <algorithm>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <string>
#include <iomanip>
using namespace std;
long long mod=1e9+7;
int n;
int u,v;
vector<int> ch[100000];
int fu[100000];
int fv[100000];
bool used[100000];
void dfsu(int now,int mow){
	fu[now]=mow;
	used[now]=1;
	for(int i=0;i<ch[now].size();i++){
		if(!used[ch[now][i]]){
			dfsu(ch[now][i],mow+1);
		}
	}
}
void dfsv(int now,int mow){
	fv[now]=mow;
	used[now]=1;
	for(int i=0;i<ch[now].size();i++){
		if(!used[ch[now][i]]){
			dfsv(ch[now][i],mow+1);
		}
	}
}
int main(){
	cin>>n>>u>>v;
	u--;v--;
	for(int i=0;i<n-1;i++){
		int a,b;
		cin>>a>>b;
		a--;
		b--;
		ch[a].push_back(b);
		ch[b].push_back(a);
	}
	used[u]=1;
	dfsu(u,0);
	for(int i=0;i<n;i++){
		used[i]=0;
	}
	used[v]=1;
	dfsv(v,0);
	int ma=0;
	for(int i=0;i<n;i++){
		if(fu[i]<fv[i]){
			int a=fu[i];
			int b=fv[i]-fu[i];
			if(b%2==0){
				ma=max(ma,a+b/2*2-1);
			}else{
				ma=max(ma,a+b/2*2);
			}
		}else if(fu[i]==fv[i]){
			int a=fu[v];
			if(a%2==0){
				ma=max(ma,a/2*2-1);
			}else{
				ma=max(ma,a/2*2);
			}
		}
	}
	cout<<ma<<endl;
	return 0;
}


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

int N,i,j,sum;

int main(){
	cin>>N;
	for (i = 1;i <= 9;i ++) {
		for (j = 1;j <=9;j ++){
			if ((i * j) == N)
			sum++;
		}
	}
	if (sum > 0){
		cout<<"Yes"<<endl;
	}
	else {
		cout<<"No"<<endl;
	}
}


Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ConsoleApp5
{
    class Program
    {
        static void Main(string[] args)
        {
            var ab = Console.ReadLine().Split().Select(int.Parse).ToArray();
            int a = ab[0];
            int b = ab[1];
            Console.WriteLine("{0} {1}", a * b, a*2+b*2);
        }
    }
}

Measured memory_bytes: 9524
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using static System.Convert;
using static System.Console;
using static System.Math;
class MainClass
{
	static void Main(string[] args)
	{
		Answer(new ConsoleInput(Console.In, ' '));
	}
	public static void Answer(ConsoleInput cin)
	{
		int a = cin.ReadInt + cin.ReadInt;
        int b = 2;
        WriteLine((a + b - 1) / b);
	}
    public class ConsoleInput
    {
        private readonly System.IO.TextReader _stream;
        private char _separator = ' ';
        private Queue<string> inputStream;
        public ConsoleInput(System.IO.TextReader stream, char separator = ' ')
        {
            this._separator = separator;
            this._stream = stream;
            inputStream = new Queue<string>();
        }
        public string Read
        {
            get
            {
                if (inputStream.Count != 0) return inputStream.Dequeue();
                string[] tmp = _stream.ReadLine().Split(_separator);
                for (int i = 0; i < tmp.Length; ++i)
                    inputStream.Enqueue(tmp[i]);
                return inputStream.Dequeue();
            }
        }
        public string ReadLine { get { return _stream.ReadLine(); }}
        public int ReadInt { get { return int.Parse(Read); }}
        public long ReadLong { get { return long.Parse(Read); }}
        public double ReadDouble { get { return double.Parse(Read); }}
        public string[] ReadStrArray(long N) { var ret = new string[N]; for (long i = 0; i < N; ++i) ret[i] = Read; return ret;}
        public int[] ReadIntArray(long N) { var ret = new int[N]; for (long i = 0; i < N; ++i) ret[i] = ReadInt; return ret;}
        public long[] ReadLongArray(long N) { var ret = new long[N]; for (long i = 0; i < N; ++i) ret[i] = ReadLong; return ret;}
    }
}

Measured memory_bytes: 13268
while True:
    n,x = list(map(int,input().split()))
    
    if n == 0 and x == 0:
        break
    ans = 0
    for i in range(1,n+1-2):    
        for j in range(i+1,n+1-1):
            for k in range(j+1,n+1):
                if i+j+k == x:
                    # print("i,j,kは",i,j,k)
                    ans = ans + 1
    print(ans)
# print(n,x)

# print(n,x)


Measured memory_bytes: 5596
#include<bits/stdc++.h>
int n,x,y,i,j,ans[2001];main(){std::cin>>n>>x>>y;for(;++i<=n;)for(j=i;++j<=n;)ans[std::min(j-i,abs(x-i)+1+abs(y-j))]++;for(i=0;++i<n;)printf("%d\n",ans[i]);}

Measured memory_bytes: 256
import java.util.HashMap;
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		HashMap<Integer, Integer> hashMap = new HashMap<Integer, Integer>();
		int min = 14;
		while(scan.hasNext()) {
			String num = scan.nextLine();
			String[] block = num.split(",");
			int[] nums = new int[block.length];
			for(int i = 0;i < block.length;i++) {
				nums[i] = Integer.parseInt(block[i]);
			}
			for(int i = 0 ;i < block.length;i++) {
				int count = 0;
				if(hashMap.containsKey(nums[i])) {
					count = hashMap.get(nums[i]);
				}
				if(min > nums[i]) {
					min = nums[i];
				}
				hashMap.put(nums[i], count + 1);
			}

			if(hashMap.containsValue(4)) {
				System.out.println("four card");
			}else if(hashMap.containsValue(3)&&hashMap.containsValue(2)) {
				System.out.println("full house");
			}else if(hashMap.containsValue(3)) {
				System.out.println("three card");
			}else if(hashMap.containsValue(2)) {
				for(Integer key : hashMap.keySet()) {
					if(hashMap.get(key) == 2) {
						hashMap.remove(key);
						break;
					}
				}
				if(hashMap.containsValue(2)) {
					System.out.println("two pair");
				}else {
					System.out.println("one pair");
				}
			}else if(hashMap.containsKey(min) && hashMap.containsKey(min + 1) && hashMap.containsKey(min + 2)
					&& hashMap.containsKey(min + 3) && hashMap.containsKey(min +4)) {
				System.out.println("straight");
			}else if(hashMap.containsKey(10) && hashMap.containsKey(11) && hashMap.containsKey(12)
					&& hashMap.containsKey(13) && hashMap.containsKey(1)) {
				System.out.println("straight");
			}else {
				System.out.println("null");
			}
			hashMap.clear();
			min = 14;
		}
		scan.close();
	}
}


Measured memory_bytes: 26088
//include
//------------------------------------------
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>
#include <climits>
#include <queue>

using namespace std;

//typedef
//------------------------------------------
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef long long LL;

//container util
//------------------------------------------
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())

//repetition
//------------------------------------------
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)

//constant
//--------------------------------------------
const double EPS = 1e-10;
const double PI  = acos(-1.0);

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

  int n; cin >> n;
  map<int,int> s;
  REP(i,n){
	int x; cin >> x;
	s[x]++;
  }

  int q, ans = 0; cin >> q;
  REP(i,q){
	int x; cin >> x;
	if(s[x] > 0) ++ans;
  }

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

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

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

fn main() {
    let s1: String = read();
    let s2: String = read();
    let s3: String = read();

    let mut ans: String = "".to_string();

    ans.push(s1.to_uppercase().chars().nth(0).unwrap());
    ans.push(s2.to_uppercase().chars().nth(0).unwrap());
    ans.push(s3.to_uppercase().chars().nth(0).unwrap());
    println!("{}", ans);
}


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

int n;

void solve() {
    std::vector<std::pair<int, int>> edges;

    if (n & 1) {
        for (int i = 1; i <= n - 1; i++) {
            edges.push_back({i, n});
        }
        for (int i = 1; i <= n - 1; i++) {
            for (int j = i + 1; j <= n - 1; j++) {
                if (j != n - i) {
                    edges.push_back({i, j});
                }
            }
        }
    } else {
        for (int i = 2; i <= n - 1; i++) {
            edges.push_back({i, n});
            edges.push_back({i, 1});
        }
        for (int i = 2; i <= n - 1; i++) {
            for (int j = i + 1; j <= n - 1; j++) {
                if (j != (n + 1) - i) {
                    edges.push_back({i, j});
                }
            }
        }
    }

    std::cout << edges.size() << std::endl;
    for (auto edge: edges) {
        printf("%d %d\n", edge.first, edge.second);
    }
}

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

    solve();

    return 0;
}

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

int gi() {
	int x=0,o=1;char ch=getchar();
	while(!isdigit(ch)&&ch!='-') ch=getchar();
	if(ch=='-') o=-1,ch=getchar();
	while(isdigit(ch)) x=x*10+ch-'0',ch=getchar();
	return x*o;
}

int n,m,x[N],t[N];
bool l[N],r[N];

int main() {
	cin>>n>>m;
	ll ans=0;
	for(int i=1;i<=n;i++) x[i]=gi();
	for(int i=1;i<=n;i++) {
		t[i]=gi();
		if(t[i]%(m<<1)==0) ans+=t[i];
		else {
			ans+=1ll*(t[i]/(m<<1)+1)*(m<<1);
			t[i]%=(m<<1);
			if(t[i]<=2*x[i]) l[i]=1;
			if(t[i]<=2*(m-x[i])) r[i]=1;
		}
	}
	int x=0,y=0;
	for(int i=1;i<n;i++) {
		if(x&&r[i]) {
			y+=l[i];ans-=(m<<1);--x;
		}
		else if(r[i]&&!l[i]) {
			if(y) --y,++x;
		}
		else if(l[i]) ++x;
	}
	if(!r[n]) ans+=(m<<1);
	cout<<ans;
	return 0;
}


Measured memory_bytes: 3200
using System;

class HelloWorld {

    const int MIN_N = 1;
    const int MAX_N = 100;
    const int MIN_A = 0;
    const int MAX_A = 1000;

    static void Main(string[] args) {
	//InsertionSort sort = new InsertionSort();

	// ??°????????????N???????????????
	int N = int.Parse(Console.ReadLine());
	N = Math.Min(N, MAX_N); // 100??\?????????
	N = Math.Max(N, MIN_N); // 1??\?????????

	// N????????´??°????????????????????§????????????
	string[] input = Console.ReadLine().Split(' ');

	int[] A = new int[N];

	// ???????´????????§£?????????????????£??\??????
	for (int i = 0; i < N; i++) {
	    A[i] = int.Parse(input[i]);
	}

	// ????????????????????????
	for (int s = 0; s < N; s++) {
	    if (s == N - 1) {
		Console.WriteLine(A[s]);
		continue;
	    }
	    Console.Write(A[s] + " ");
	}

	// ?????\??????????????¢?????´?????????
	for (int k = 1; k < N; k++) {
	    int v = A[k];
	    int j = k - 1;
	    while (j >= 0 && A[j] > v) {
		A[j + 1] = A[j];
		j--;
		A[j + 1] = v;
	    }
	    // ??????
	    for (int s = 0; s < N; s++) {
		if (s == N - 1) {
		    Console.WriteLine(A[s]);
		    continue;
		}
		Console.Write(A[s] + " ");
	    }
	}
    }
}

Measured memory_bytes: 9324
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int N;
  cin >> N;
  int ans;
  vector<int> valueC(N);
  vector<int> valueV(N);
  vector<int> diff(N);
  for(int i=0;i<N;i++){
    cin >> valueC.at(i);
    }
  for(int i=0;i<N;i++){
    cin >> valueV.at(i);
  }
  for(int i=0;i<N;i++){
    diff.at(i) = valueC.at(i) - valueV.at(i);
  }
  for(int i=0;i<N;i++){
    if(diff.at(i) <= 0){
      diff.at(i) = 0;
    }
    ans += diff.at(i);
  }
  
  cout << ans << endl;

}

  
      
 

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

using ll = long long;
constexpr ll INF = 1000000000;
constexpr ll mod = 1e9 + 7;

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

using namespace std;

//fixed << setprecision(10)

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

int main() {
	ll a; cin >> a;

	ll cnt = 0;



	while (a != 0) {
		a /= 2;
		cnt++;
	}
	
	ll ans = 0;
	for (ll i = 0; i < cnt; i++) {
		ans += pow(2, i);
	}
	cout << ans << endl;
}


Measured memory_bytes: 256
#include <stdio.h>

int main(void){
	int H,W,h,w;
	scanf("%d %d \n %d %d",&H,&W,&h,&w);
	int white;
	if(0<=W<=20 && 0<=H<=20){
		if(1<=h<=H && 1<=w<=W){
			white = H*W - (H*w + W*h - h*w);
			printf("%d", white);  
			return 0;
		}else{
			return -1;
		}
	}else{
		return -1;
	}
}

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

#define lp(var,start,end) for (ll var = start; var <end ; ++var)
#define rlp(var,start,end) for(ll var = start; var>=end ; var--)
#define pb push_back
#define mp make_pair
#define pf push_front
#define ff first
#define ss second
#define vll vector<ll>
#define vld vector<ld>
#define pll pair<ll,ll> 
#define pld pair<ld,ld> 
#define vpll vector<pll>
#define vpld vector<pld>
#define all(X) X.begin(),X.end()
#define endl "\n"
#define sz(x) ((ll)((x).size()))
const ll N=1e5+5,inf=1e18;

int main()
{
	ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
	ll k,a,b;
	cin >> k >> a >> b;
	ll d=(a/k)*k;
	if(d<a)d+=k;
	if(d<=b)
	{
		cout<<"OK"<<endl;
	}	    
	else
	{
		cout<<"NG"<<endl;
	}
	return 0;
}

Measured memory_bytes: 3668
import std.stdio, std.algorithm, std.conv, std.array, std.string, std.math, std.typecons, std.numeric;

long P = 10^^9+7;
long[10^^5*2+50] F, RF;

long pow(long x, long n) {
    long y = 1;
    while (n) {
        if (n%2 == 1) y = (y * x) % P;
        x = x^^2 % P;
        n /= 2;
    }
    return y;
}

void init()
{
    F[0] = F[1] = 1;
    foreach (i, ref x; F[2..$]) x = (F[i+1] * (i+2)) % P;

    {
        RF[$-1] = 1;
        auto x = F[$-1];
        auto k = P-2;
        while (k) {
            if (k%2 == 1) RF[$-1] = (RF[$-1] * x) % P;
            x = x^^2 % P;
            k /= 2;
        }
    }
    foreach_reverse(i, ref x; RF[0..$-1]) x = (RF[i+1] * (i+1)) % P;
}

long comb(N)(N n, N k)
{
    if (k > n) return 0;
    auto n_b = F[n];    // n!
    auto nk_b = RF[n-k]; // 1 / (n-k)!
    auto k_b = RF[k];    // 1 / k!

    auto nk_b_k_b = (nk_b * k_b) % P; // 1 / (n-k)!k!

    return (n_b * nk_b_k_b) % P;  // n! / (n-k)!k!
}

void main()
{
    init();
    auto nab = readln.split.to!(long[]);
    auto n = nab[0];
    auto a = nab[1];
    auto b = nab[2];

    auto r = (pow(2, n) - 1 + P) % P;

    long aa = 1;
    foreach_reverse (x; n-a+1..n+1) aa = (aa * x) % P;
    aa = (aa * RF[a]) % P;
    long bb = 1;
    foreach_reverse (x; n-b+1..n+1) bb = (bb * x) % P;
    bb = (bb * RF[b]) % P;
    
    r = (r - aa + P) % P;
    r = (r - bb + P) % P;
    writeln(r);
}

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

int main() {
    int n;
    cin >> n;
    vector<int> a(n);
    vector<vector<int>> x(n);
    vector<vector<int>> y(n);
    rep(i, n) {
        cin >> a[i];
        int xin, yin;
        rep(j, a[i]) {
            cin >> xin >> yin;
            xin--;
            x[i].push_back(xin);
            y[i].push_back(yin);
        }
    }
    int ans = 0;
    for (int bit = 0; bit < (1 << n); bit++) {
        bool flag = true;
        int count = 0;
        for (int i = 0; i < n; i++) {
            if ((1 << i) & bit) {
                count++;
                for (int j = 0; j < a[i]; j++) {
                    if (y[i][j]) {
                        if (!((1 << x[i][j]) & bit))
                            flag = false;
                    }
                    else {
                        if ((1 << x[i][j]) & bit)
                            flag = false;
                    }
                }
            }
        }
        if (flag)
            ans = max(ans, count);
    }
    cout << ans << endl;
    return 0;
}

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

using namespace std;

typedef long long ll;
typedef pair<ll, ll> P;

const ll mod = 1e9 + 7;
const ll mmod = 998244353;

vector<ll> dx = {1, -1, 0, 0};
vector<ll> dy = {0, 0, 1, -1};

vector<string> g;
vector<vector<bool>> used;
vector<ll> d;

int main() {
    
    
    cin.tie(0);
    ios_base::sync_with_stdio(0);
    
    ll n, k;
    cin >> n >> k;
    vector<ll> p(n);
    for (int i = 0; i < n; ++i)
    {
        cin >> p[i];
    }
    sort(p.begin(), p.end());
    ll ret = 0;
    for (int i = 0; i < k; ++i)
    {
        ret += p[i];
    }
    
    cout << ret << endl;
    
    return 0;
}

Measured memory_bytes: 3620
#include<stdio.h>
#include<string.h>
#define SIZE 3010

// 2つの文字列の最長部分列(LCS)を求めて出力
void solve(char *s1,char *s2,int len1,int len2){
    int lcs[SIZE][SIZE] = {},i,j,cnt;
    char answer[SIZE];
    // lcs[i][j] := s1のi文字目とs2のj文字目までのLCSの長さ
    // answer := LCS

    // 更新
    for(i = 0;i < len1-1;i ++){
        for(j = 0;j < len2-1;j ++){
            // 同じ文字ならば+1
            if(s1[i]==s2[j]) lcs[i+1][j+1] = lcs[i][j] + 1;
            else {
                // 異るならば大きい方から遷移
                if(lcs[i+1][j] < lcs[i][j+1]) lcs[i+1][j+1] = lcs[i][j+1];
                else lcs[i+1][j+1] = lcs[i+1][j];
            }
        }
    }
    cnt = lcs[len1-1][len2-1];
    i = len1-1;
    j = len2-1;
    // lcsテーブルの右下からたどる
    // テーブルの値が0で終了
    while(cnt){
        // 上と左が共に現在の場所の値と異るならばそこが端点なので答えの文字
        if(lcs[i][j]!=lcs[i-1][j] && lcs[i][j]!=lcs[i][j-1]){
            answer[cnt-1] = s1[i-1];
            cnt --;
            i --;
            j --;
        }else if(lcs[i][j]==lcs[i-1][j]){
            i --;
        }else{
            j --;
        }
    }
    printf("%s\n",answer);
}

int main(){
    char string1[SIZE],string2[SIZE];

    fgets(string1,SIZE,stdin);
    fgets(string2,SIZE,stdin);

    solve(string1,string2,strlen(string1),strlen(string2));

    return 0;
}

Measured memory_bytes: 35584
#include <iostream>
#include <algorithm>
#include <set>
#include <string>
using namespace std;

const int kMax = 1048600;
const int kInf = 1000000000;

string S;
int N, Q;
int Qk[150010];

set< int > L, R;
int Tm[kMax], Td[kMax];

void read();
void solve();

void update(int, int, int, int, int, int);
int query(int, int, int, int, int);

int main() {
  read();
  solve();
  return 0;
}

void read() {
  ios::sync_with_stdio(false);

  cin >> N >> Q >> S, S = "#" + S;
  for (int i = 0; i < Q; ++i)
    cin >> Qk[i];
}

void solve() {
  fill(&Tm[0], &Tm[kMax], 0);

  for (int i = 1, s = 0; i <= N; ++i) {
    if (S[i] == '(')
      ++s, L.insert(i);
    else
      --s, R.insert(i);
    update(1, 0, N, i - 1, i, s);
  }

  for (int qi = 0; qi < Q; ++qi) {
    int p = Qk[qi], t;

    if (S[p] == '(') {
      // flip query
      S[p] = ')';
      update(1, 0, N, p - 1, N, -2);
      L.erase(p), R.insert(p);

      // find answer
      t = *R.begin();
      cout << t << "\n";

      // flip answer
      S[t] = '(';
      update(1, 0, N, t - 1, N, 2);
      R.erase(t), L.insert(t);
    }
    else {
      // flip query
      S[p] = '(';
      update(1, 0, N, p - 1, N, 2);
      R.erase(p), L.insert(p);

      // find answer
      int low = 1, up = N, mid;
      while (low < up) {
        mid = (low + up) / 2;
        if (query(1, 0, N, mid - 1, N) >= 2)
          up = mid;
        else
          low = mid + 1;
      }
      t = *L.lower_bound(up);
      cout << t << "\n";

      // flip answer
      S[t] = ')';
      update(1, 0, N, t - 1, N, -2);
      L.erase(t), R.insert(t);
    }
  }
}

void update(int u, int l, int r, int ql, int qr, int qd) {
  if (ql <= l && r <= qr)
    Tm[u] += qd, Td[u] += qd;
  else {
    int mid = (l + r) / 2;

    if (Td[u] != 0) {
      update(2 * u,     l, mid, l, mid, Td[u]);
      update(2 * u + 1, mid, r, mid, r, Td[u]);
      Td[u] = 0;
    }

    if (ql < mid) update(2 * u,     l, mid, ql, qr < mid ? qr : mid, qd);
    if (qr > mid) update(2 * u + 1, mid, r, ql > mid ? ql : mid, qr, qd);

    Tm[u] = min(Tm[2 * u], Tm[2 * u + 1]);
  }
}

int query(int u, int l, int r, int ql, int qr) {
  if (ql <= l && r <= qr)
    return Tm[u];
  else {
    int mid = (l + r) / 2;

    if (Td[u] != 0) {
      update(2 * u,     l, mid, l, mid, Td[u]);
      update(2 * u + 1, mid, r, mid, r, Td[u]);
      Td[u] = 0;
    }

    int ret = kInf;

    if (ql < mid) ret = min(ret, query(2 * u,     l, mid, ql, qr < mid ? qr : mid));
    if (qr > mid) ret = min(ret, query(2 * u + 1, mid, r, ql > mid ? ql : mid, qr));

    return ret;
  }
}

Measured memory_bytes: 24144
import java.util.*;
public class Main {

	public void doIt(){
		Scanner sc = new Scanner(System.in);
		while(true){
			int z = sc.nextInt();
			if(z == 0)
				break;
			int z3 = z * z * z;
			int x=1,y=1;
			int max = 0;
			for(x = 1; (x * x * x) + (y * y * y) <= z3; x++){
				for(y = 1; (x * x * x) + (y * y * y) <= z3;y++){
					max = Math.max(max, (x * x * x) + (y * y * y));
				}
				y = 1;
			}
			System.out.println(z3 - max);
		}


	}
	public static void main(String[] args) {
		Main obj = new Main();
		obj.doIt();
	}
}

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

#define REP(i,x) for(int i=0; i<(int)(x); i++)       // 0 <= i < x
#define REPS(i,x) for(int i=1; i<=(int)(x); i++)     // 0 < i <= x
#define RREP(i,x) for(int i=((int)(x)-1); i>=0; i--) // x > i >= 0
#define RREPS(i,x) for(int i=((int)(x)); i>0; i--)   // x >= i > 0
#define INF 999999999
#define ll long long

using namespace std;

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

#define MAX_N 100000

int main(void){
	ll N;
	ll a[MAX_N], b[MAX_N], c[MAX_N];
	scanf("%lld", &N);
	REP(i, N){
		scanf("%lld", &a[i]);
	}
	REP(i, N){
		scanf("%lld", &b[i]);
	}
	REP(i, N){
		scanf("%lld", &c[i]);
	}

	sort(a, a+N);
	//sort(b, b+N);
	sort(c, c+N);

	//Biより大きいCiの個数
	ll countc[N];
	ll counta[N];
	
	REP(i, N){
	    countc[i] = c + N - upper_bound(c, c+N, b[i]);
		counta[i] = lower_bound(a, a+N, b[i]) - a;
	}

	ll ans = 0;
	REP(i, N){
	    ans += countc[i]*counta[i];
	}

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

	return 0;
}


Measured memory_bytes: 4096
#include <iostream>

using namespace std ;

int main()
{
    int s ;
    cin >> s ;
    if((s % 10 == s/10 % 10 && s % 10 == s/100 % 10) || (s/1000 % 10 == s/100 % 10 && s/100 % 10 == s/10 % 10))
    cout << "Yes" ;
    else cout << "No" ;
    return 0 ;
}


Measured memory_bytes: 256
import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {
        
        Scanner sc = new Scanner(System.in);
        String line = sc.nextLine();
        long x = Long.parseLong(line);
        
        int a = 0;
        int b = 0;
        
        boolean flag = true;
        for(a = 1; a < 1000; a++)
        {
            
            for(b = -999; b < a; b++)
            {
                long aa = (long)Math.pow(a,5);
                long bb = (long)Math.pow(b,5);
                long result = aa - bb;
                
                if(result == x)
                {
                    flag = false;
                    break;
                }
            }
            if(flag == false)
            {
                break;
            }
            
        }
        
        System.out.println(a + " " + b);
    }
}


Measured memory_bytes: 38764
#include<bits/stdc++.h>
using namespace std;
int main(void)
{
  string s;cin >> s;
  int cnt=0;
  for(int i=0;i<s.size()-1;i++){
    cnt+=(s[i]!=s[i+1])?1:0;
  }
  cout << cnt << endl;
}

Measured memory_bytes: 512