akhauriyash/Code-Regression huggingface dataset:
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#include <time.h>
#include <iostream>
#include <algorithm>
#include <fstream>
#include <iomanip>
#include <vector>
#include <bitset>
#include <stack>
#include <queue>
#include <set>
#include <map>

using namespace std;

int n;

int popcount(int v)
{
	return v ? popcount(v - (v & -v)) + 1 : 0;
}

int main()
{
	ios::sync_with_stdio(0);
	cin >> n;
	if (popcount(n) == 1)
	{
		puts("No");
		return 0;
	}
	cout << "Yes" << endl;
	if (n % 2 == 1)
	{
		cout << 1 << ' ' << 2 << '\n';
		cout << 2 << ' ' << 3 << '\n';
		cout << 3 << ' ' << n + 1 << '\n';
		cout << n + 1 << ' ' << n + 2 << '\n';
		cout << n + 2 << ' ' << n + 3 << '\n';
		for (int i = 4;i <= n;i += 2)
		{
			cout << i << ' ' << i + 1 << '\n';
			cout << i + 1 << ' ' << n + 1 << '\n';
			cout << n + 1 << ' ' << n + i << '\n';
			cout << n + i << ' ' << n + i + 1 << '\n';
		}
	}
	else
	{
		cout << 1 << ' ' << 2 << '\n';
		cout << 2 << ' ' << 3 << '\n';
		cout << 3 << ' ' << n + 1 << '\n';
		cout << n + 1 << ' ' << n + 2 << '\n';
		cout << n + 2 << ' ' << n + 3 << '\n';
		for (int i = 4;i < n;i += 2)
		{
			cout << i << ' ' << i + 1 << '\n';
			cout << i + 1 << ' ' << n + 1 << '\n';
			cout << n + 1 << ' ' << n + i << '\n';
			cout << n + i << ' ' << n + i + 1 << '\n';
		}
		int c = (n & -n);
		cout << n + c << ' ' << n << '\n';
		cout << (n - c) + 1 << ' ' << n + n << '\n';
	}
	cout.flush();
	return 0;
}

Measured memory_bytes: 2816
//
#include "bits/stdc++.h"
#define REP(i,n) for(int i=0;i< (n);i++)
#define REPR(i, n) for(int i = (n);i >= 0;i--)
#define FOR(i, m, n) for(int i = (m);i < (n);i++)
#define FORR(i, m, n) for(int i = (m);i >= (n);i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define ll long long
#define pb(a) push_back(a)
#define ALL(obj) (obj).begin(),(obj).end()

using namespace std;

const int INF = 99999999;
const ll LINF = 9999999999999;

typedef pair<int, int> P;
typedef pair<ll, ll> LP;
int vx[4] = { 0,1,0,-1 };
int vy[4] = { 1,0,-1,0 };

string a;
signed main() {

	std::ios::sync_with_stdio(false);
	std::cin.tie(0);
	
	cin >> a;
	int count = 0;
	REP(i, 6) {
		if (a[i] == '1') {
			count++;
		}
	}

	cout << count << endl;

	return 0;

}


Measured memory_bytes: 764
#include <stdio.h>
#define _USE_MATH_DEFINES
#include <math.h>

int main(void){
	int n , i , j , k , num[8] , max , min , count;
	char num_c[9];
	scanf("%d" , &n);
	for(i=1;i<=n;i++){
		max = 0;
		min = 0;
		scanf("%s" , num_c);
		for(j=0;j<8;j++){
			num[j] = num_c[j] - '0';
		}
		count = 0;
		for(j=9;j>=0;j--){
			for(k=0;k<8;k++){
				if(num[k] == j){
					max += j * pow(10 , 7 - count);
					count++;
				}
			}
		}
		count = 0;
		for(j=0;j<=9;j++){
			for(k=0;k<8;k++){
				if(num[k] == j){
					min += j * pow(10 , 7 - count);
					count++;
				}
			}
		}
		printf("%d\n" , max - min);
	}
	return 0;
}

Measured memory_bytes: 0
#include <iostream>
#include <string>
using namespace std;

int main() {

    int red, green, blue;
    cin >> red >> green >> blue;

    int k;
    cin >> k;

    while (true) {
        if (red < green) {
            break;
        }
        green *= 2;
        k--;
    }

    while (true) {
        if (green < blue) {
            break;
        }
        blue *= 2;
        k--;
    }

    if (k >= 0) {
        cout << "Yes" << endl;
    } else {
        cout << "No" << endl;
    }
}


Measured memory_bytes: 3624
def examA():
    x = I()
    if x<1200:
        ans = "ABC"
    else:
        ans = "ARC"
    print(ans)

import sys
import copy
from collections import Counter,defaultdict,deque
def I(): return int(sys.stdin.readline())
def LI(): return list(map(int,sys.stdin.readline().split()))
def LS(): return sys.stdin.readline().split()
def S(): return sys.stdin.readline().strip()
mod = 10**9 + 7
inf = float('inf')

examA()

Measured memory_bytes: 3444
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
#define srep(i,s,t) for (int i = s; i < t; ++i)
#define rng(a) a.begin(),a.end()
using namespace std;
typedef long long int ll;
typedef pair<int,int> P;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<P> vp;
#define dame { puts("-1"); return 0;}
#define yn {puts("Yes");}else{puts("No");}
#define MAX_N 200005

/*
    NTL_1_A Prime Factorize
*/

vector<int> fact;
void Factorize(int n){
    if(2 <= n){
        for(int i = 2; i <= n; i++){
            if(n < i*i)break;
            while(n % i == 0){
                fact.push_back(i);
                n /= i;
            }
        }
        if(1 < n)fact.push_back(n);
        sort(fact.begin(), fact.end());
    }
}

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

    Factorize(n);
    cout << n << ": ";
    rep(i,fact.size()){
        cout << fact[i];
        if(i<fact.size()-1){
            cout << ' ';
        }
    }
    cout << endl;
    
    return 0;
}
 
 



Measured memory_bytes: 3168
#include<stdio.h>
int main()
{
  int a,b,i,j;
  while(1)
	   {
  scanf("%d%d",&a,&b);
  if(a==0&&b==0){break;}

  for(i=1;i<=a;i++)
    {
      for(j=1;j<=b;j++)
	{
	  if(j%2==1)
	    {
	      if(i%2==1)printf("#");
	      else printf(".");
	    }
	  else 
	    {
              if(i%2==1)printf(".");
	      else printf("#");
	    }
	}
      printf("\n");
    }
  printf("\n");
    
	   }
  return 0;
}



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

int main(){
  vector<int> x(5);
  for (int i=0 ; i<5 ; i++){
    cin >> x.at(i);
    if (x.at(i)==0){
      cout << i+1 <<endl;
      break;
    }
  }
}

Measured memory_bytes: 3544
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cstring> //memset
using namespace std;

int main()
{
	long long N, K, Q;

	cin >> N >> K >> Q;

	static long w[100010];
	memset(w, 0, sizeof(w));

	//! ���͂��Ȃ��琳�𐔂̐����グ
	for (long i = 0; i < Q; i++) {
		long win;

		cin >> win;

		w[win - 1] += 1;
	}

	for (long i = 0; i < N; i++) {
		if (Q - w[i] >= K) {
			cout << "No" << endl;
		}
		else {
			cout << "Yes" << endl;
		}
	}
}


//int main()
//{
//	string S;
//
//	cin >> S;
//
//	bool bad = false;
//	for (int i = 0; i < S.size(); i++) {
//		if ((i+1) % 2 == 0) {
//			//����
//			if (S[i] == 'R') {
//				bad = true;
//				break;
//			}
//		}
//		else {
//			//�
//			if (S[i] == 'L') {
//				bad = true;
//				break;
//			}
//		}
//	}
//
//	if (bad == true) {
//		cout << "No" << endl;
//	}
//	else {
//		cout << "Yes" << endl;
//	}
//}

//int main()
//{
//	string S;
//
//	cin >> S;
//
//	if (S == "Sunny")
//	{
//		cout << "Cloudy" << endl;
//	}
//	else if(S == "Cloudy")
//	{
//		cout << "Rainy" << endl;
//	}
//	else {
//		cout << "Sunny" << endl;
//	}
//}

Measured memory_bytes: 1408
# B - String Palindrome

S = input()

ans = 'No'

N = len(S)
left = S[:(N - 1) // 2]
right = S[((N + 3) // 2) - 1:]
if left == right:
    if left == left[::-1] and right == right[::-1]:
        ans = 'Yes'

print(ans)

Measured memory_bytes: 3060
import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        long[] a = new long[3*n];
        for(int i=0; i<n*3; i++){
            a[i] = sc.nextLong();
        }
        sc.close();

        long ans = Long.MIN_VALUE;
        long[] a1 = Arrays.copyOfRange(a, 0, n);
        long[] a2 = Arrays.copyOfRange(a, 2*n, 3*n);
        PriorityQueue<Long> p1 = new PriorityQueue<Long>((Long x, Long y) -> Long.compare(x, y));
        PriorityQueue<Long> p2 = new PriorityQueue<Long>((Long x, Long y) -> Long.compare(-x, -y));
        long[] sum1 = new long[n+1];
        long[] sum2 = new long[n+1];
        Arrays.sort(a2);
        for(int i=0; i<n; i++){
            p1.add(a1[i]);
            p2.add(a2[i]);
            sum1[0] += a1[i];
            sum2[0] += a2[i];
        }
        for(int i=0; i<n; i++){
            long c1 = a[i+n];
            long m1 = p1.poll();
            sum1[i+1] = sum1[i] - m1;
            m1 = Math.max(c1, m1);
            sum1[i+1] += m1;
            p1.add(m1);
            long c2 = a[2*n-1-i];
            long m2 = p2.poll();
            sum2[i+1] = sum2[i] - m2;
            m2 = Math.min(c2, m2);
            sum2[i+1] += m2;
            p2.add(m2);
        }

        for(int i=0; i<n+1; i++){
            ans = Math.max(ans, sum1[i] - sum2[n-i]);
        }

        System.out.println(ans);
    }
}

Measured memory_bytes: 102576
// B - Checkpoints
#include <bits/stdc++.h>
using namespace std;
#define lli long long int
#define uli unsigned long long int
#define rep(i, m, n) for (lli i = m; i < (n); i++)
#define repe(i, m, n) for (lli i = m; i <= (n); i++)
#define ALL(x) (x).begin(), (x).end()
#define SIZE(x) ((lli)(x).size())
#define MAX(x) *max_element(ALL(x))
#define MIN(x) *min_element(ALL(x))
#define _GLIBCXX_DEBUG
const lli INF = 2147483647;
const lli MINF = -2147483648;
const lli LINF = 9223372036854775807;
const lli MOD = 1000000007; //10^9+7
const double PI = acos(-1);
#define SORT(n) sort(n.begin(), n.end())
#define SORTR(n) sort(n.begin(), n.end(), greater<int>())
#define REV(n) reverse(n.begin(), n.end())
#define pb push_back
#define eb emplace_back
#define mp make_pair
#pragma GCC optimize("Ofast")
using vi = vector<int>;
using vvi = vector<vi>;
using vvvi = vector<vvi>;
using vlli = vector<lli>;
using vvli = vector<vlli>;
using vs = vector<string>;
using vvs = vector<vs>;
using vb = vector<bool>;
using vvb = vector<vb>;
using ll = long long;
// vector入力
template <typename T>
istream &operator>>(istream &is, vector<T> &vec)
{
  for (T &x : vec)
    is >> x;
  return is;
}
// vector出力
template <typename T>
ostream &operator<<(ostream &os, vector<T> &vec)
{
  // os << '{';
  for (int i = 0; i < vec.size(); i++)
  {
    os << vec[i] << (i + 1 == vec.size() ? "" : "");
  }
  // os << '}';
  return os;
}
// aよりもbが大きいならばaをbで更新する(更新されたならばtrueを返す)
template <typename T>
bool chmax(T &a, const T &b)
{
  if (a < b)
  {
    a = b; // aをbで更新
    return true;
  }
  return false;
}
// aよりもbが小さいならばaをbで更新する(更新されたならばtrueを返す)
template <typename T>
bool chmin(T &a, const T &b)
{
  if (a > b)
  {
    a = b; // aをbで更新
    return true;
  }
  return false;
}

int main()
{
  ios::sync_with_stdio(false);
  cin.tie(0);
  lli a, b, c, d, h, n, m, w, ans = INF, count = 0;
  string s, t;
  vector<pair<lli, pair<lli, lli>>> pr, ch;
  cin >> n >> m;

  rep(i, 0, n)
  {
    cin >> a >> b;
    pr.eb(make_pair(i + 1, make_pair(a, b)));
  }
  rep(i, 0, m)
  {
    cin >> c >> d;
    ch.eb(make_pair(i + 1, make_pair(c, d)));
  }

  for (auto x : pr)
  {
    ans = INF;
    for (auto y : ch)
    {
      count = abs(x.second.first - y.second.first) + abs(x.second.second - y.second.second);
      ans = min(ans, count);
    }
    for (auto y : ch)
    {
      count = abs(x.second.first - y.second.first) + abs(x.second.second - y.second.second);
      if (count == ans)
      {
        cout << y.first << endl;
        break;
      }
    }
  }
}

Measured memory_bytes: 3632
import sys

def main():
    score1 = []
    for i in range(4):
        score1.append(int(input()))
    score1.sort()
    score2 = []
    for i in range(2):
        score2.append(int(input()))
    score2.sort()

    print(sum(score1[1:]+score2[1:]))
    return 0

if __name__ == '__main__':
    sys.exit(main())

Measured memory_bytes: 7728
n,m = map(int,input().split())
i_now = []
r_now = []

for k in range(m):
  i,r = map(int,input().split())
  
  i_now.append(i)
  r_now.append(r)

i_max = max(i_now)
r_min = min(r_now)

ans = r_min - i_max + 1

if ans <= 0:
  ans = 0
  
print(ans)

Measured memory_bytes: 56024
#pragma GCC optimize("Ofast")
#include<bits/stdc++.h>
#pragma GCC target("avx2")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
//#include<boost/multiprecision/cpp_int.hpp>
//#include<boost/multiprecision/cpp_dec_float.hpp>
//namespace mp=boost::multiprecision;
//#define mulint mp::cpp_int
//#define mulfloat mp::cpp_dec_float_100
using namespace std;
struct __INIT{__INIT(){cin.tie(0);ios::sync_with_stdio(false);cout<<fixed<<setprecision(15);}} __init;
#define max3(a,b,c) max(a,max(b,c))
#define min3(a,b,c) min(a,min(b,c))
constexpr int MOD=1000000007;
//constexpr int MOD=998244353;
#define INF (1<<30)
#define LINF (lint)(1LL<<56)
#define endl "\n"
#define rep(i,n) for(lint (i)=0;(i)<(n);(i)++)
#define reprev(i,n) for(lint (i)=(n-1);(i)>=0;(i)--)
#define Flag(x) (1<<(x))
#define Flagcount(x) __builtin_popcountll(x)
#define pint pair<int,int>
#define pdouble pair<double,double>
#define plint pair<lint,lint>
#define fi first
#define se second
typedef long long lint;
int dx[8]={1,1,0,-1,-1,-1,0,1};
int dy[8]={0,1,1,1,0,-1,-1,-1};
const int MAX_N=2e5+5;
//struct edge{lint to,num;};

vector<int> edge[MAX_N];
bool reach[MAX_N];
int ans[MAX_N];

void dfs(int now){
    if(reach[now]) return;
    reach[now]=true;
}

lint d[300][300]; // MAX_V
void warshallfloyd(int v){ // N
  rep(i,v) rep(j,v) rep(k,v) d[j][k]=min(d[j][k],d[j][i]+d[i][k]);
  return;
}


int main(void){
    int N;
    cin >> N;
    rep(i,N-1){
        int num;
        cin >> num;
        num--;
        ans[num]++;
    }
    rep(i,N) cout << ans[i] << endl;
}

Measured memory_bytes: 9148
def fct(n):
	v = 1
	for i in range(1, n+1):
		v = (v * i) % 1000000007
	return v
N, M = map(int, input().split())
ans = 0
if N == M:
	v = fct(N)
	ans = (v*v*2)%1000000007
elif abs(N-M) == 1:
	ans = (fct(N)*fct(M))%1000000007
print(ans)

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

int main(){
    int n;
    while(cin >> n){
        int appear[7] = {}, domino[7] = {};
        bool hasDup[7] = {};
        int a;

        for(int i = 0; i < n; i++){
            cin >> a;
            appear[a/10]++;
            appear[a%10]++;
            domino[a/10]++;
            if(a/10 != a%10)    domino[a%10]++;
            else                hasDup[a/10] = true;
        }

        int odd = 0;
        for(int i = 0; i < 7; i++){
            if(appear[i]%2) odd++;
        }

        bool judge = true;
        for(int i = 0; i < 7; i++){
            if(hasDup[i] && domino[i] == 1) judge = false;
        }

        bool rule1 = (odd == 0 || odd == 2);
        bool rule2 = (judge || n == 1);
        
        if(rule1 && rule2){
            cout << "Yes" << endl;
        }else{
            cout << "No" << endl;
        }
    }
    return 0;
}


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

int main()
{
    ll n,k ; 
    cin>>n>>k ; 

    vector<ll> v(n); 
    vector <ll> w(n);
    
    for(ll i=0;i<n;i++){
    	cin>>w[i]>>v[i] ;
    }
    
    ll dp[n+1][k+1] ; 
    for(ll i = 0; i <= n; i++){
    	for (ll j = 0; j <= k; ++j){
    		if(i==0||j==0){
    			dp[i][j] = 0 ; 
    		}else if(w[i-1]>j){
    			dp[i][j] = dp[i-1][j] ; 
    		}else{
    			dp[i][j] = max(v[i-1]+dp[i-1][j-w[i-1]] , dp[i-1][j]) ; 
    		}
    	}
    }

    cout<<dp[n][k] ; 
    
    return 0;
}


Measured memory_bytes: 79104
#include<iostream>
#include<vector>
#include<algorithm>
#include<cmath>
#include<string>
#include<set>
#include<climits>
#include<map>
#define ll long long
using namespace std;
int main() {
	ll n,count=0;
	cin >> n;
	for (ll i = 1; i <= n/2; i++) {
			if (i + (n-i) == n&&i!=(n-i)) {
				count++;
			}
		}
	
	cout << count << endl;

}



Measured memory_bytes: 256
S = input()
K = int(input())

l = len(S)
one = 0
el = S[0]
for i in range(l):
    if S[i]=='1':
        one += 1
    else:
        el = S[i]
        break
if K<=one:
    print(1)
else:
    print(el)
    
    

Measured memory_bytes: 2940
n,q=map(int,input().split())
s=input()
a=[0]*n
for i in range(n-1):
    if s[i]=="A" and s[i+1]=="C":
        a[i+1]=1
b=[0]*n        
b[0]=a[0]
for i in range(1,n):
    b[i]=b[i-1]+a[i]
for i in range(q):
    l,r=map(int,input().split())
    print(b[r-1]-b[l-1])

Measured memory_bytes: 8436
#include<bits/stdc++.h>
using namespace std;
int main(){
ios_base::sync_with_stdio(false);cin.tie(0);
  char c;
  cin>>c;
  if(isupper(c)){
    cout<<'A'<<'\n';
  }else{
    cout<<'a'<<'\n';
  }
}

Measured memory_bytes: 3652
import java.util.*;
 
public class Main {
	public static void main(String[] args) {
    	Scanner sc = new Scanner(System.in);
    	int n = sc.nextInt();
        int k = sc.nextInt();
        Integer hp[] = new Integer[n];
        for(int i = 0; i < n; i++){
        	hp[i] = sc.nextInt();
        }
        Arrays.sort(hp, Collections.reverseOrder());
        long ans = 0;
        for(int i = k; i < n; i++){
        	ans += hp[i];
        }
        System.out.println(ans);
    }
}

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


using namespace std;

#define MAXN 110
#define INF 10000000

int n;
int w[MAXN];
int pre[MAXN];

int main() {
    scanf("%d", &n);
    int i;
    pre[0]=0;
    for (i=1; i<=n; i++) {
        scanf("%d", &w[i]);
        pre[i]=pre[i-1]+w[i];
    }
    int ans = INF;
    for (i=1; i<=n-1; i++) {

        ans = min(ans, abs(pre[i] - (pre[n]-pre[i])));
    }
    printf("%d\n", ans);
    return 0;
}








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

using namespace std;

#define loop(i,a,b) for(int i=(a); i<(int)(b); i++)
#define rep(i,b) loop(i,0,b)

struct edge {
    int to, cost;
};

struct state {
    int v, d, rest;
    bool operator<(const state& s)const{
        return d>s.d;
    }
};

int main(){
    string a, b;
    while (cin >> a >> b, a != "0"){
        int aaa = 0;
        int bbb = 0;
        rep(i,4){
            char guess = b[i];
            if (a[i] == b[i])aaa++;
            if (a.find(guess) != string::npos)bbb++;
        }
        cout << aaa << " "<<bbb - aaa << endl;
    }
}

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

int main(){
    int n, q,flag=0,count=0,ans;
    int l,r;
    cin >> n >> q;
    char s[n-1];
    vector<int> cnt;
    cnt.push_back(0);
    scanf("%s", s);

    for ( int i = 1; i < n; i++ ){
        if(s[i-1] == 'A' && s[i] == 'C') count++;
        cnt.push_back(count);
    }

    for( int i=0; i<q; i++ ){
        scanf("%d %d", &l, &r);
        ans = cnt[r-1] - cnt[l-1];
        cout << ans << endl;
    }
  
    return 0;
}

Measured memory_bytes: 1400
#include <bits/stdc++.h>
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
// const bool debug=true;
const bool debug=false;
#define DEBUG if(debug==true)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
const ll MOD = 1000000007;

int main(void) {
    ll n;
    cin >>n;
    ll res=0;
    rep(i,n){
        ll tmp;
        cin >> tmp;
        res+=tmp-1;
    }
    cout << res << endl;
    return 0;
}


Measured memory_bytes: 256
s = raw_input().lower().split()
c1 = 0
c2 = 0
for w in set(s):
    c=s.count(w)
    if c>c1: c1,w1 = c,w
    c=len(w)
    if c>c2: c2,w2 = c,w
print w1, w2

Measured memory_bytes: 4200
//Shubham Vijayvargiya

#include<bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
using namespace std;

#define pb push_back
#define mp make_pair
#define eb emplace_back
#define F first
#define S second
#define sz(a) (int)(a.size())
#define set(a,b) memset(a,b,sizeof(a))
#define let(x,a) __typeof(a) x(a)
#define rep(i, begin, end) for (ll i = (begin) - ((begin) > (end)); i != (end) - ((begin) > (end)); i += 1 - 2 * ((begin) > (end)))
#define all(v) (v).begin(),(v).end()
#define sll(x) { scanf("%lld",&x); }
#define si(x) { scanf("%d",&x); }
#define slf(x) { scanf("%lf",&x); }
#define pll(x) { printf("%lld\n",x); }
#define pi(x) { printf("%d\n",x); }
#define tcases() long long testcases; cin>>testcases ; while(testcases--)

#define TRACE
#ifdef TRACE
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
    cerr << name << " = " << arg1 << std::endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
    const char* comma = strchr(names + 1, ',');cerr.write(names, comma - names) << " = " << arg1<<" | ";__f(comma+1, args...);
}

#else
#define trace(...)
#endif

template <typename T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

typedef long long ll;
typedef long double ld;
typedef pair<long long,long long> pll;
typedef vector<long long> vll;
typedef vector<pll> vpll;
typedef vector<vll> vvll;

const ll mod=1000000007;
//----------------------------------------------------------------------------------------------------------------------------------------------//


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

	ll q,h,s,d,n;
	cin>>q>>h>>s>>d>>n;

	s=min(s,min(4*q,2*h));
	d=min(d,2*s);
	ll ans;
	ans=(n/2)*d+(n%2)*s;
	cout<<ans<<endl;
	return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
int main(){
	int a, b, c, d, e, f;
	scanf("%d %d %d", &a, &b, &c);
	d=a+b;
	e=a+c;
	f=b+c;
	if(d<e && d<f){
		printf("%d", d);
	}
	else if(e<d && e<f){
		printf("%d", e);
	}
	else if(f<e && f<d){
		printf("%d", f);
	}
	else if(d==e && e==f){
		printf("%d", d);
	}
	return 0;
}

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

int main(){
	
	int n, m;
	cin >> n >> m;
	vector< vector<int> > a(n, vector<int>(m));  //??????????????????????????????
	vector<int> b(m);
	int c[100];

	for(int i = 0; i < a.size(); i++){
		for(int j = 0; j < b.size(); j++){
			cin >> a[i][j];
		}
	}

	for(int j = 0; j < b.size(); j++){
		cin >> b[j];
	}

	for(int i = 0; i < a.size(); i++){
		c[i] = 0;
		for(int j = 0; j < b.size(); j++){
			c[i] += a[i][j] * b[j];
		}
		cout << c[i] << endl;
	}

	return 0;
}

Measured memory_bytes: 1256
#include <cstdio>
#include <string>
#include <iostream>
#include <cmath>
#include <vector>
#include <stack>

using namespace std;

int main(void) {
  int N, d, cnt=0;
  unsigned int i;

  vector<int> mochi;

  cin >> N;

  mochi.resize(N);

  while (N--) {
    cin >> d;
    for (i=0; i < mochi.size(); i++) {
      if (d == mochi[i]) break;
    }
    if (i == mochi.size()) {
      mochi.push_back(d);
      cnt++;
    }
  }

  cout << cnt << endl;
  return 0;
}


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

#define MAX 10000
#define NIL -1

typedef struct{
  int p;
  int l;
  int r;
}Node;

Node T[MAX];
int n;

void pre(int u){
  if(u == NIL)  return;
  printf(" %d", u);
  pre(T[u].l);
  pre(T[u].r);
}

void in(int u){
  if(u == NIL)  return;
  in(T[u].l);
  printf(" %d", u);
  in(T[u].r);
}

void post(int u){
  if(u == NIL)  return;
  post(T[u].l);
  post(T[u].r);
  printf(" %d", u);
}

int main(void){
  int i, v, l, r, root;

  scanf("%d", &n);

  for(i = 0; i < n; i++){
    T[i].p = NIL;
  }

  for(i = 0; i < n; i++){
    scanf("%d %d %d", &v, &l, &r);
    T[v].l = l;
    T[v].r = r;
    if(l != NIL)  T[l].p = v;
    if(r != NIL)  T[r].p = v;
  }

  for(i = 0; i < n; i++){
    if(T[i].p == NIL) root = i;
  }

  printf("Preorder\n");
  pre(root);
  printf("\n");
  printf("Inorder\n");
  in(root);
  printf("\n");
  printf("Postorder\n");
  post(root);
  printf("\n");

  return 0;
}



Measured memory_bytes: 2104
#include<bits/stdc++.h>
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
#define mod 1000000007
#define MAX 1000000000000000
#define all(v) v.begin(),v.end()
#define rep(i,a,b) for(i=(ll)a;i<(ll)b;i++)
#define revrep(i,a,b) for(i=(ll)a;i>=(ll)b;i--)
#define ii pair<ll,ll>
#define MP make_pair
#define pb push_back
#define f first
#define se second
#define ll long long int
#define vi vector<ll>
ll modexp(ll a,ll b){ ll res = 1; while(b > 0){  if(b & 1) res = (res * a)%mod;  a = (a * a)%mod;  b/=2;  }  return res; }
#define rs resize
typedef tree< ll, null_type, less<ll>, rb_tree_tag, tree_order_statistics_node_update > OST;
#define TRACE
#ifdef TRACE
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
    template <typename Arg1>
    void __f(const char* name, Arg1&& arg1){
        cout << name << " : " << arg1 << endl;
    }
    template <typename Arg1, typename... Args>
    void __f(const char* names, Arg1&& arg1, Args&&... args){
        const char* comma = strchr(names + 1, ','); cout.write(names, comma - names) << " : " << arg1<<" | ";__f(comma+1, args...);
    }
#else
#define trace(...)
#endif

const ll N = 1e2 + 5;
ll i,n,k,a,ans;
int main()
{
    std::ios_base::sync_with_stdio(false); cin.tie(NULL);
    cin>>n>>k;
    rep(i,0,n){
        cin>>a;
        ans += a >= k;
    }
    cout<<ans;
    return 0;
}

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

int main() {
	int M, D;
	cin >> M;
	cin >> D;
	int days = 0;
		for(int i = 4; i <= M; i++) {
			for(int j = 22; j <= D; j++) {
				if(j%10 >= 2 && (j%10) * (j/10) == i) {
					days++;
				}
			}
		}
	cout << days;
	return 0;
}

Measured memory_bytes: 256
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10 ** 7)

S = input().rstrip()

T = S[::-1]
T = T.replace('b','*').replace('d','b').replace('*','d')
T = T.replace('p','*').replace('q','p').replace('*','q')

answer = 'Yes' if S == T else 'No'
print(answer)

Measured memory_bytes: 3376
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
using namespace std;
long long rui(long long n, long long k, long long p) {
	if (k == 0) {
		return 1;
	}
	else {
		long long a = rui(n, k / 2, p);
		if (k % 2 == 0) {
			return (a*a) % p;
		}
		return (((a*a) % p)*n) % p;
	}
}
int main(){
	int h, w, s, t;
	cin >> h >> w >> s >> t;
	string y = "Yes";
	string n = "No";
	if (h == 1) {
		if (t == 1 or t == w) {
			cout << y << endl;
		}
		else {
			cout << n << endl;
		}
	}
	else if (w == 1) {
		if (s == 1 or s == h) {
			cout << y << endl;
		}
		else {
			cout << n << endl;
		}
	}
	else {
		if ((h*w) % 2 == 0) {
			cout << y << endl;
		}
		else if ((s + t) % 2 == 0) {
			cout << y << endl;
		}
		else{
			cout << n << endl;
		}
	}
}


Measured memory_bytes: 3224
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
const int INF = 1e9;
const ll LINF = 1e18;
inline ll gcd(ll a, ll b) { return b ? gcd(b, a%b) : a; }
inline ll lcm(ll a, ll b) { return a / gcd(a, b)*b; }
template<class S,class T> ostream& operator << (ostream& out,const pair<S,T>& o){ out << "(" << o.first << "," << o.second << ")"; return out; }
template<class T> ostream& operator << (ostream& out,const vector<T>& V){ for(int i = 0; i < V.size(); i++){ out << V[i]; if(i!=V.size()-1) out << " ";} return out; }
template<class T> ostream& operator << (ostream& out,const vector<vector<T> >& Mat){ for(int i = 0; i < Mat.size(); i++) { if(i != 0) out << endl; out << Mat[i];} return out; }
template<class S,class T> ostream& operator << (ostream& out,const map<S,T>& mp){ out << "{ "; for(auto it = mp.begin(); it != mp.end(); it++){ out << it->first << ":" << it->second; if(mp.size()-1 != distance(mp.begin(),it)) out << ", "; } out << " }"; return out; }
template<typename T>vector<T> make_v(size_t a){return vector<T>(a);}
template<typename T,typename... Ts>auto make_v(size_t a,Ts... ts){return vector<decltype(make_v<T>(ts...))>(a,make_v<T>(ts...));}
template<typename T,typename V> typename enable_if<is_class<T>::value==0>::type fill_v(T &t,const V &v){t=v;}
template<typename T,typename V> typename enable_if<is_class<T>::value!=0>::type fill_v(T &t,const V &v){for(auto &e:t) fill_v(e,v);}
/*
 <url:https://atcoder.jp/contests/abc133/tasks/abc133_d>
 問題文============================================================
 =================================================================
 解説=============================================================
 ================================================================
 */

template<class Type>
Type solve(Type res = Type()){
    ll N; cin >> N;
    vector<ll> A(N); for(auto& in:A) cin >> in;
    vector<ll> ans(N);
    
    for(int i = 0; i < N;i++){
        ans[0] += i%2==0?A[i]:-A[i];
    }
    for(int i = 1; i < N; i++){
        ans[i] = 2*(A[i-1]-ans[i-1]/2);
    }
    res = ans;
    return res;
}
int main(void) {
    cin.tie(0); ios_base::sync_with_stdio(false);
    // solve(0);
    cout << fixed << setprecision(15) << solve<vector<ll>>() << endl;
    return 0;
}


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

using namespace std;

int main()
{
    long long N;
    bool breakFlag = false;
    bool zeroFlag = false;
    long double res = 1;
    long long ans;
    cin >> N;
    vector<long long> A(N, 0);
    for (long long i = 0; i < N; i++)
    {
        cin >> A.at(i);
        if (A[i] == 0)
        {
            zeroFlag = true;
        }
    }
    if (zeroFlag) {
        cout << 0 << endl;
        return 0;
    }
    for (long long i = 0; i < N; i++)
    {
        res *= A[i];
        if (res > 1000000000000000000)
        {
            breakFlag = true;
            break;
        }
    }
    if (breakFlag)
    {
        cout << -1 << endl;
    }
    else
    {
        ans = res;
        cout << ans << endl;
    }
    return 0;
}

Measured memory_bytes: 4052
#define _CRT_SECURE_NO_WARNINGS

#include <iostream>
#include <cstdio>
#include <vector>

class DrawLots
{
private:
	int w;					// 縦線の数
	int n;					// 横線の数
	int a, b;				// 入れ替える数値(実際は-1することによってインデックスになる)
	std::vector<int> W;		// int型の動的配列Wを作成
public:
	DrawLots();
	~DrawLots();
	void Print();
	void ExchengeElement();
};

int main()
{
	DrawLots DL = DrawLots();
	DL.ExchengeElement();
	DL.Print();
}

DrawLots::DrawLots()
{
	std::cin >> w;
	std::cin >> n;
	
	W = std::vector<int>(w);

	W.assign(w, 1);

	for (int i = 0; i < w; i++)
	{
		W[i] = i + 1;
	}
}

DrawLots::~DrawLots()
{
}

void DrawLots::ExchengeElement()
{
	int tmp;
	for (int i = 0; i < n; i++)
	{
		
		scanf("%d,%d", &a, &b);

		tmp = W[a-1];
		W[a-1] = W[b-1];
		W[b-1] = tmp;

	}
}

void DrawLots::Print()
{
	for (unsigned int i = 0; i < W.size(); i++)
	{
		std::cout << W[i] << std::endl;
	}
}


Measured memory_bytes: 3224
#include<iostream>
using namespace std;
int main(){
	int n;
	cin>>n;
	unsigned long long a[n+1];
	a[0]=2;
	a[1]=1;
	for(int i=2;i<=n;i++){
		a[i]=a[i-1]+a[i-2];
	}
	cout<<a[n];
}

Measured memory_bytes: 384
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define mod 1000000007LL

ll f[3010][3010];
int num[3010],n,m;

inline int rd()
{
	int x=0;char ch=getchar();
	for (;ch<'0'||ch>'9';ch=getchar());
	for (;ch>='0'&&ch<='9';ch=getchar()) x=x*10+ch-'0';
	return x;
}

inline ll ksm(ll x,ll y) { ll res=1;for (;y;y>>=1,x=x*x%mod) if (y&1) res=res*x%mod;return res; }

const ll inv2=ksm(2,mod-2);

int main()
{
	n=rd();m=rd();
	for (int i=1;i<=n;i++) num[i]=rd();
	for (int i=1;i<=n;i++) for (int j=1;j<=n;j++) f[i][j]=(num[i]>num[j]);
	ll hhh=ksm(2,m);
	while (m--)
	{
		int x=rd(),y=rd();
		f[x][y]=f[y][x]=(f[x][y]+f[y][x])*inv2%mod;
		for (int i=1;i<=n;i++)
		{
			if (i==x||i==y) continue;
			f[x][i]=f[y][i]=(f[x][i]+f[y][i])*inv2%mod;
			f[i][x]=f[i][y]=(f[i][x]+f[i][y])*inv2%mod;
		}
	}
	ll ans=0;
	for (int i=1;i<n;i++) for (int j=i+1;j<=n;j++) ans=(ans+f[i][j])%mod;
	printf("%lld\n",ans*hhh%mod);
	return 0;
}

Measured memory_bytes: 70784
#include "bits/stdc++.h"
using namespace std;
#ifdef _DEBUG
#include "dump.hpp"
#else
#define dump(...)
#endif

//#define int long long
#define rep(i,a,b) for(int i=(a);i<(b);i++)
#define rrep(i,a,b) for(int i=(b)-1;i>=(a);i--)
#define all(c) begin(c),end(c)
const int INF = sizeof(int) == sizeof(long long) ? 0x3f3f3f3f3f3f3f3fLL : 0x3f3f3f3f;
const int MOD = (int)(1e9) + 7;
template<class T> bool chmax(T &a, const T &b) { if (a < b) { a = b; return true; } return false; }
template<class T> bool chmin(T &a, const T &b) { if (b < a) { a = b; return true; } return false; }

int n;
vector<vector<int>> g;
vector<int> match;
vector<bool> used;
void init(int n_) {
	n = n_;
	g.assign(n, vector<int>());
	match.assign(n, -1);
	used.assign(n, false);
}
void addEdge(int u, int v) {
	g[u].emplace_back(v);
	g[v].emplace_back(u);
}
bool augment(int v) {
	used[v] = true;
	for (int u : g[v]) {
		int w = match[u];
		if (w == -1 || (!used[w] && augment(w))) {
			match[v] = u;
			match[u] = v;
			return true;
		}
	}
	return false;
}

int maximumMatching() {
	int cnt = 0;
	fill(match.begin(), match.end(), -1);
	for (int v = 0; v < n; v++) {
		if (match[v] == -1) {
			fill(used.begin(), used.end(), false);
			if (augment(v))cnt++;
		}
	}
	return cnt;
}

signed main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	for (int N, M, L; cin >> N >> M >> L&&N;) {
		vector<vector<int>> g(N, vector<int>(N, INF));
		rep(i, 0, M) {
			int u, v, d; cin >> u >> v >> d;
			g[u][v] = g[v][u] = d;
		}
		rep(i, 0, N)
			g[i][i] = 0;
		rep(k, 0, N)rep(i, 0, N)rep(j, 0, N) {
			if (g[i][k] != INF&&g[k][j] != INF)
				g[i][j] = min(g[i][j], g[i][k] + g[k][j]);
		}

		vector<int> p(L), t(L); rep(i, 0, L) {
			cin >> p[i] >> t[i];
		}
		init(L + L);
		int source = L + L, sink = source + 1;
		rep(i, 0, L) {
			rep(j, 0, L) {
				if (i == j)continue;
				if (g[p[i]][p[j]] <= t[j] - t[i]) {
					addEdge(i, L + j);
				}
			}
		}
		auto ans = L - maximumMatching();
		cout << ans << endl;
	}
	return 0;
}

Measured memory_bytes: 8296
from collections import deque

L=input().split()

d = deque()

for l in L:
    if l in '+':
        a=d.pop()
        b=d.pop()
        d.append(a+b)
    elif l in '-':
        a=d.pop()
        b=d.pop()
        d.append(b-a)
    elif l in '*':
        a=d.pop()
        b=d.pop()
        d.append(a*b)
    elif l in '/':
        a=d.pop()
        b=d.pop()
        d.append(b/a)
    else:
        d.append(int(l))
        
print_num = d.pop()
print(print_num)


Measured memory_bytes: 5996
#include <iostream>
#include <iomanip>

int main() {
    int n{}, k{};
    std::cin >> n >> k;
    double result{};
    for (int i = 1; i <= n; i++) {
        auto tmp = 1.0 / n;
        auto score = i;
        while (score < k) {
            score *= 2;
            tmp /= 2;
        }
        result += tmp;
    }
    std::cout << std::fixed << std::setprecision(15) << result << std::endl;
    return 0;
}

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

using namespace std;
using ll = long long int;
using P = pair<int, int>;

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

int func(int m){
    int temp = 1;
    for(int i = 0;i < m;i++){
        temp *= 2;
    }

    return temp;
}

int main(void){

    int n, m;
    cin >> n >> m;

    cout << (1900*m+100*(n-m))*func(m);

    return 0;
}

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

using namespace std;

#define ll long long

int main(){
    int n;
    cin>>n;
    int x=n,sum=0;
    while(n!=0){
        sum=sum+n%10;
        n=n/10;
    }
    if(x%sum==0) cout<<"Yes"<<endl;
    else cout<<"No"<<endl;

}




Measured memory_bytes: 256
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<climits>
#include<iostream>
#include<sstream>
#include<utility>
#include<map>
#include<vector>
#include<queue>
#include<algorithm>
#include<set>
#include<stack>

using namespace std;
typedef long long ll;
typedef pair<int,int>P;


int main()
{
	int ax,ay,bx,by,cx,cy,dx,dy,x,y;
	cin>>ax>>ay>>bx>>by;
	x=abs(ax-bx);
	y=abs(ay-by);

	if(ax<bx)
	{
		cy=by+x;
		dy=ay+x;
	}
	else
	{
		cy=by-x;
		dy=ay-x;
	}

	if(ay<by)
	{
		cx=bx-y;
		dx=ax-y;
	}
	else
	{
		cx=bx+y;
		dx=ax+y;
	}

	printf("%d %d %d %d\n",cx,cy,dx,dy);
	return 0;
	
}


Measured memory_bytes: 256
#include<iostream>
using namespace std;
  
int main(){
  int A,B,C;
  cin>>A>>B>>C;
  if(A==B){
    if(B==C)cout<<"No"<<endl;
    else if(B!=C)cout<<"Yes"<<endl;
  }
  else{
    if(A==C || B==C)cout<<"Yes"<<endl;
    else cout<<"No"<<endl;
  }
}
    
    


Measured memory_bytes: 256
#!/usr/bin/env python3
import sys
input = sys.stdin.readline
from collections import Counter

n = int(input())
a = [int(item) for item in input().split()]

total = 0
for item in a:
    total ^= item

ans = [0] * n
for i, item in enumerate(a):
    ans[i] = total ^ item
print(*ans)

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

using namespace std;

int main(){
    int N,M,K;
    cin >> N >> M;
    int cntr[M];
    for(int i=0;i<M;i++){
        cntr[i]=0;
    }
    int food;
    for(int i=0;i<N;i++){
        cin >> K;
        for(int j=1;j<=K;j++){
            cin >> food;
            cntr[food-1]++;
        }
    }
    int ans = 0;
    for(int i=0;i<M;i++){
        if(cntr[i]==N){
            ans++;
        }
    }
    cout << ans;
}


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

#define rep(i, n) for (int (i) = 0; (i) < (n); (i)++)
#define rng(i, a, b) for (int (i) = (a); (i) < (b); (i)++)
#define rbf(i, v) for (auto& (i) : (v))
#define All(x) (x).begin(),(x).end()
#define cAll(x) (x).cbegin(),(x).cend()
#define COL(x) cout << x << endl
#define CO(x) cout << x
//#define int long long

using LL = long long;
using ULL = unsigned long long;
using PII = pair<int, int>;
using VI = vector<int>;
using VVI = vector<VI>;
using VS = vector<string>;
using VP = vector<PII>;

const double PI = 3.141592653589793;
const int MOD = 1000000007;
const LL INF64 = INT64_MAX >> 1;
const int INF = INT_MAX >> 1;

inline int sqr(int x) { return (x * x); }
inline void printd(double x) { printf("%.10lf\n", x); }
inline void upsort(VI& x) { sort((x).begin(), (x).end()); }
inline void downsort(VI& x) { sort((x).begin(), (x).end(), greater<int>()); }
inline int absdiff(int a, int b) {
	if (b > a) return absdiff(b, a);
	return (a - b);
}
int gcd(int a, int b) { // 最大公約数
	if (a < b) return gcd(b, a);
	int r;
	while ((r = a % b)) {
		a = b;
		b = r;
	}
	return b;
}
inline int lcm(int a, int b) { return a * b / gcd(a, b); } // 最小公倍数
#pragma endregion



signed main()
{	
	string S0, T;
	cin >> S0;
	cin >> T;

	if (T.size() > S0.size()) {
		COL("UNRESTORABLE");
		return 0;
	}

	string Sa(S0), Sa2(S0);
	rbf(s, Sa) {
		if (s == '?') s = 'a';
	}

	string Stmp(T);
	VS SS;
	rep(i, S0.size() - T.size() + 1) {
		Stmp = S0.substr(i, T.size());
		rep(j, T.size()) {
			if (Stmp[j] == '?') Stmp[j] = T[j];
		}
		if (Stmp == T) {
			Sa2 = Sa;
			SS.push_back(Sa2.replace(i, Stmp.size(), Stmp));
		}
	}

	if(SS.empty()) COL("UNRESTORABLE");
	else {
		sort(All(SS));
		COL(SS[0]);
	}

	return 0;
}

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

int main() {
    int n;
    cin >> n;
    vector<int> a(n);
    vector<int> b(n);
    vector<int> c(n-1);
    rep(i,n) cin >> a[i];
    rep(i,n) cin >> b[i];
    rep(i,n-1) cin >> c[i];
    int sum = 0;
    rep(i,n) sum += b[i];
    rep(i,n-1) {
        if(a[i] + 1 == a[i+1]) {
           sum += c[a[i]-1];
        }
    }
    cout << sum << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long int llint;
typedef unsigned long long int ullint;
std::string YesNo[] = {"No","Yes"};
#define loop(i,N) for(int i=0; i<(N); i++)
template<typename T>
auto sort_all(T& v) { return std::sort(v.begin(),v.end()); }
template<typename T>
auto sum_all(const T& v) { auto z = v[0]; z = 0;
    return std::accumulate(v.begin(),v.end(),z); }
template<typename T>
auto input(int N) {
    std::vector<T> v(N);
    loop(i,N) std::cin >> v[i];
    return std::move(v);
}

template<typename T>
class heapq : public std::vector<T>
{
private:
    void down_heapify(std::size_t i) {
        auto m = i;
        auto first_leaf = this->size()/2;
        while(i < first_leaf) {
            auto left = i*2 + 1;
            auto right = i*2 + 2;
            for(auto k : {left, right}) {
                if(k < this->size() && (*this)[k] < (*this)[m]) {
                    m = k;
                }
            }
            if(m == i) {
                return;
            } else {
                std::swap((*this)[i], (*this)[m]);
                i = m;
            }
        }
    };

    void up_heapify(std::size_t i) {
        while(i > 0) {
            auto parent = (i-1)/2;
            if((*this)[i] < (*this)[parent]) {
                std::swap((*this)[i], (*this)[parent]);
                i = parent;
            } else {
                return;
            }
        }
    };

public:
    template<typename ...Args>
    heapq(Args ...args) : std::vector<T>(args...) {
        heapify();
    };

    void heapify() {
        auto first_leaf = this->size()/2;
        for(auto i=first_leaf; i>0; i--) {
            down_heapify(i-1);
        }
    };

    void heappush(const T& x) {
        this->push_back(x);
        up_heapify(this->size()-1);
    };

    T heappop() {
        auto ret = std::move(this->front());
        this->front() = std::move(this->back());
        this->pop_back();
        down_heapify(0);
        return ret;
    };

    T heappoppush(const T& x) {
        auto ret = std::move(this->front());
        this->front() = x;
        down_heapify(0);
        return ret;        
    };

    T heappushpop(const T& x) {
        if(x <= this->front()) {
            return x;
        } else {
            return heappoppush(x);
        }
    };
};

typedef llint Int;

int main(void)
{
    Int N, D, A, ans, d;
    cin >> N >> D >> A;
    auto q = heapq<tuple<Int,Int,Int>>(0);
    loop(i, N) {
        Int x, h;
        cin >> x >> h;
        q.heappush(std::tuple<Int,Int,Int>(x, 0, h));
    }

    ans = 0;
    d = 0;
    while (q.size() > 0) {
        auto p = q.heappop();
        Int x = std::get<0>(p);
        Int s = std::get<1>(p);
        Int h = std::get<2>(p);
        if (s == 0) {
            h -= d;
            if (h <= 0) {
                continue;
            } else {
                Int k = (h-1)/A + 1;
                q.heappush(std::tuple<Int,Int,Int>(x+2*D, 1, k*A));
                d += k*A;
                ans += k;
            }
        } else {
            d -= h;
        }
    }
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 8304
#include <iostream>
#include <string>
#include <vector>
#include <set>
#include <queue>
#include <stack>
#include <map>
#include <algorithm>
#include <math.h>
#include <cassert>
#define rep(i,n) for(int i = 0; i < n; ++i )
using namespace std;
using ll = long long;
using P = pair<int,int>;

int main() {
  int n;
  cin >> n;
  vector<P> x(n);
  vector<int> a(n),b(n);
  rep(i,n) cin >> a[i] >> b[i];
  sort(a.begin(),a.end());
  sort(b.begin(),b.end());
  ll ans = 0;
  if(n%2==0){
    ans = b[n/2]+b[n/2-1]-a[n/2]-a[n/2-1]+1;
  }else{
    ans = b[(n-1)/2]-a[(n-1)/2]+1;
  }
  cout << ans << endl;
}


Measured memory_bytes: 6432
n = int(input())
stone = list(input())
l = 0
r = n-1
ans = 0
while l < r:
    if stone[l]=='W':
        if stone[r]=='R':
            ans += 1
            l += 1
            r -= 1
        else:
            r -= 1
    else:
        l += 1
        if stone[r]=='W':
            r -= 1
print(ans)

Measured memory_bytes: 82236
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define pa(x,n) for(ll i=0;i<n;i++){cout<<(x[i])<<" \n"[i==n-1];};
#define pb push_back

using ll = long long;
using namespace std;
using pint = pair<int,int>;
using pll = pair<ll,ll>;
const int INFint = 1e9;
const ll INFll = 1e18;
ll MOD=1e9+7;

ll gcd(ll a, ll b) { return __gcd(a,b); } //最大公約数
ll lcm(ll a, ll b) { return a/gcd(a,b)*b; } //最大公倍数

// aのn乗をMODで割りながら計算する
ll modpow(ll a, ll n) {
  long long res = 1;
  while (n > 0) {
    if (n & 1) res = res * a % MOD;
    a = a * a % MOD;
    n >>= 1; // right shift
  }
  return res;
}

// MODを法としたaの逆元を計算する
ll modinv(ll a) {
  return modpow(a, MOD - 2);
}

int main(){
  int N,L,a[100000];
  cin>>N>>L;
  rep(i,N) cin>>a[i];
  int ma(0);
  int tmpi(0);
  for (int i(0); i < N - 1; i++){
    if (a[i] + a[i+1] > ma){
      ma = max(ma,a[i] + a[i+1]);
      tmpi = i;
    }
  }
  if (ma < L){
    cout << "Impossible" << endl;
  }else{
    cout << "Possible" << endl;
    for (int i(0);i<tmpi;i++){
      cout << i+1 << endl;
    }
    for (int i(N-2);i>=tmpi;i--){
      cout << i+1 << endl;
    }
  }
  return 0;
}


Measured memory_bytes: 1152
#include<stdio.h>
#include<string.h>

int main(){
	int i,j,k,n,h,ren;
	char card[201],shuf[999],x[201],emp[201];
	
	while(1){
		scanf("%s",card);
		if(card[0]=='-')break;
	ren=strlen(card);
	strcpy(shuf,card);
	scanf("%d",&n);
	
	for(i=0;i<n;i++){
			scanf("%d",&h);
				strncat(shuf,card,h);
		for(j=ren+h;j>=h;j--){
		x[j-h]=shuf[j];
			}
			strcpy(shuf,x);
			strcpy(card,shuf);
		}
		printf("%s\n",shuf);
	}
return 0;
}

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

int main(){
    string s;
    cin >> s;
    int l = s.size();
    if(s[l-1] == 's'){
        s = s + "es";
    }else{
        s = s + "s";
    }
    cout << s << endl;
}

Measured memory_bytes: 3624
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(n);++i)
#define rrep(i,n) for(int i=1;i<(n);++i)
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
const int inf = 1001001001;
const int mod = 1000000007;

int main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	int n, k;
	cin >> n >> k;
	vector<int> d(k);
	rep(i, k) cin >> d[i];
	for (int i = 1; i <= 99999; ++i) {
		if (i < n) continue;
		vector<int> res;
		int tmp = i;
		while (tmp) {
			res.emplace_back(tmp % 10);
			tmp /= 10;
		}
		bool elf = false;
		for (auto& c : res) {
			rep(j, k) if (c == d[j]) elf = true;
		}
		if (!elf) {
			cout << i << endl;
			break;
		}
	}
	return 0;
}


Measured memory_bytes: 256
using System;
namespace _2_3
{
    class Program
    {
        static void Main(string[] args)
        {
            int a, b, c;
            string[] str = Console.ReadLine().Split(' ');
            Array.Sort(str);
            a = int.Parse(str[0]);
            b = int.Parse(str[1]);
            c = int.Parse(str[2]);

           

            Console.WriteLine("{0} {1} {2}",a,b,c);

            
                

        }
    }
}



Measured memory_bytes: 9972
#include <stdio.h>
#include <vector>
#include <queue>
#include <map>
#include <set>
#include <string>
#include <iostream>
#include <algorithm>
#include <cstring>
#include <cassert>

using namespace std;
typedef long long LL;
typedef pair<int,int> pii;

const int MAXN = 1e5+1;
const int MOD = 1e9 + 7;
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define fi first
#define se second
#define FAILNO {printf("NO\n"); return 0;}
#define FAIL1 {printf("-1\n"); return 0;}

int N;
int A[MAXN];

int gcd(int a, int b) {
	return (b) ? gcd(b, a%b) : a;
}

int main() {
#ifdef OJ
	freopen("input.txt", "rt", stdin);
	//freopen("output.txt", "wt", stdout);
#endif

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

	if (N == 2) {
		printf("%d\n", max(A[0], A[1]));
		return 0;
	}

	sort(A,A+N);

	int m = N;
	int mn = A[0];
	for (int i = 1; i < N; i++)  {
		int g = gcd(A[i], A[0]);
		if (g < mn) {
			mn = g;
			m = i;
		}
	}
	
	int g = 0;
	for (int i = 0; i < N; i++) g = gcd(g, A[i]);

	int g1 = 0;
	for (int i = 1; i < N; i++) g1 = gcd(g1, A[i]);

	int g2 = 0;
	for (int i = 0; i < N; i++) if (i != m) g2 = gcd(g2, A[i]);

	printf("%d\n", max(g,max(g1,g2)));
	return 0;
}



Measured memory_bytes: 640
// 

#include <bits/stdc++.h>
using namespace std;

#define ll long long
#define pb push_back
#define FOR(i, a, b) for(int i=(a);i<(b);i++)
#define RFOR(i, a, b) for (int i=(a);i>(b);i--)
#define REP(i, n) FOR(i, 0, n)
#define RREP(i, n) RFOR(i, n, 0)
#define caset int ___T; cin >> ___T; while(___T--)
#define F first
#define S second
#define all(x) x.begin(), x.end()
#define clr(x) memset(x, 0, sizeof(x))
#define get1(a) ll int a; cin>>a;
#define get2(a,b) ll int a,b; cin>>a>>b;
#define get3(a,b,c) ll int a,b,c; cin>>a>>b>>c;
#define gets(s) string s; cin >> s;

#define fast_IO ios::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL)
#define endl "\n"

struct comp {
	bool operator() (pair <int, int> a, pair <int, int> b) {
		return min(a.first, a.second) < min(b.first, b.second);
	}
};

int main() {
	fast_IO;

	int n;
	cin >> n;

	vector <int> v(n);
	REP(i, n) cin >> v[i];

	sort(all(v), greater<int>());
	
	ll int comfort = v[0];
	priority_queue <pair <int, int>, vector <pair <int, int> >, comp> pq;

	pq.push({v[0], v[1]});
	pq.push({v[1], v[0]});
	for (int i = 2; i < n; ++i) {
		auto p = pq.top();
		pq.pop();
		comfort += min(p.first, p.second);
		pq.push({p.first, v[i]});
		pq.push({v[i], p.second});
	}

	cout << comfort << endl;

	cout << flush;
}


Measured memory_bytes: 6064