akhauriyash/Code-Regression huggingface dataset:
//#include "stdafx.h"
#include <stdio.h>
#include <iostream>
#include <set>
#include <queue>
#include <vector>
#include <algorithm>
#include <math.h>
#include <cmath>
#include <string>
#include <cstring>
#include <climits>
#include <sstream>
#include <iomanip>
#include <map>
#include <stack>
#include <tuple>
#include <numeric>
#include <assert.h>
#include <functional>
#include <unordered_map>
#include <cstdint>

using namespace std;

/*-----------------------------------------------------------------------------
　定義
 -------------------------------------------------------------------------------*/
#define REP(i, n)				for (int (i) = 0 ; (i) < (int)(n) ; ++(i))
#define REPN(i, m, n)			for (int (i) = m ; (i) < (int)(n) ; ++(i))
#define ALL(a)					(a).begin(),(a).end()
#define INF						2e9
#define MOD						(1000 * 1000 * 1000 + 7)
#define Ceil(x, n)				(((((x))+((n)-1))/n))		/* Nの倍数に切り上げ割り算 */
#define CeilN(x, n)				(((((x))+((n)-1))/n)*n)		/* Nの倍数に切り上げ */
#define FloorN(x, n)			((x)-(x)%(n))				/* Nの倍数に切り下げ */
#define IsOdd(x)				(((x)&0x01UL) == 0x01UL)			
#define IsEven(x)				(!IsOdd((x)))						
#define ArrayLength(x)			(sizeof( x ) / sizeof( x[ 0 ]))
#define	MAX_QWORD				((QWORD)0xFFFFFFFFFFFFFFFF)
#define M_PI					3.14159265358979323846
typedef long long				ll;
typedef unsigned long long int	QWORD;
typedef unsigned long long		SQWORD;
typedef pair<ll, ll>			P;

/*-----------------------------------------------------------------------------
　処理
 -------------------------------------------------------------------------------*/
int main()
{
	string S;
	cin >> S;

	bool find = false;
	bool ans = true;
	REP(i, S.size()) {
		if (i == 0) {
			if (S[i] != 'A') {
				ans = false;
				break;
			}
		} else if (1 == i || i  == S.size() - 1) {
			if (isupper(S[i])) {
				ans = false;
				break;
			}
		} else {
			if (find) {
				if (isupper(S[i])) {
					ans = false;
					break;
				}
			} else {
				if (S[i] == 'C') {
					find = true;
				} else {
					if (isupper(S[i])) {
						ans = false;
						break;
					}
				}
			}
		}
	}

	if (ans && find) {
		cout << "AC" << endl;
	} else {
		cout << "WA" << endl;
	}
	return 0;
}



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

int main(){
	ll x,n;cin>>x>>n;
	vector<ll> ex(102,0);
	rep(i,n){
		ll p;cin>>p;
		ex[p]=1;
	}


	ll mini,maxi;
	for(ll i=x;i>=-1;i--){
		if(ex[i]==0){
			mini=i;
			break;
		}
	}
	for(ll i=x;i<=101;i++){
		if(ex[i]==0){
			maxi=i;
			break;
		}
	}

	if(abs(mini-x)<=abs(maxi-x)){
		cout<<mini<<endl;
	}else{
		cout<<maxi<<endl;
	}

	return 0;
}

Measured memory_bytes: 3624
-- string-rotation.hs --- String Rotation

-- author: Seong Yong-ju <sei40kr@gmail.com>

rotate :: Int -> [x] -> [x]
rotate n xs = take (length xs) (drop n (cycle xs))

solve :: String -> String -> Bool
solve s t = any ((== t) . flip rotate s) [0 .. (length s)]

main :: IO ()
main = do
  s <- getLine
  t <- getLine
  putStrLn $
    if solve s t
      then "Yes"
      else "No"


Measured memory_bytes: 508
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.List;
import java.util.stream.Collectors;

class Node {
    long key;
    Node parent, left, right;

    Node(long key) {
        this.key = key;
    }
}

class BinarySearchTree {
    Node root = null;

    void insert(Node node) {
        if (root == null) {
            root = node;
        } else {
            Node parent = null;
            Node curr = root;
            while (curr != null) {
                parent = curr;
                if (node.key < parent.key)
                    curr = curr.left;
                else
                    curr = curr.right;
            }
            // Insert the node
            node.parent = parent;

            // Set the node as a child of the parent
            if (node.key < parent.key)
                parent.left = node;
            else
                parent.right = node;
        }
    }

    void inorderTreeWalk(List<Long> ret, Node curr) {
        if (curr == null) return;
        inorderTreeWalk(ret, curr.left);
        ret.add(curr.key);
        inorderTreeWalk(ret, curr.right);
    }

    void preorderTreeWalk(List<Long> ret, Node curr) {
        if (curr == null) return;
        ret.add(curr.key);
        preorderTreeWalk(ret, curr.left);
        preorderTreeWalk(ret, curr.right);
    }

    void print() {
        List<Long> arr = new ArrayList<>();
        inorderTreeWalk(arr, root);
        System.out.println(" " + arr.stream().map(String::valueOf).collect(Collectors.joining(" ")));

        arr.clear();
        preorderTreeWalk(arr, root);
        System.out.println(" " + arr.stream().map(String::valueOf).collect(Collectors.joining(" ")));
    }
}

public class Main {
    public static void main(String[] args) {
        try (BufferedReader in = new BufferedReader(new InputStreamReader(System.in))) {
            final int n = Integer.parseInt(in.readLine());
            BinarySearchTree btree = new BinarySearchTree();

            for (int i = 0; i < n; i++) {
                String[] line = in.readLine().split(" ");
                if (line[0].charAt(0) == 'i') {
                    Node node = new Node(Long.parseLong(line[1]));
                    btree.insert(node);
                } else {
                    btree.print();
                }
            }
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}



Measured memory_bytes: 219148
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")
}

use std::cmp::{max, min};

fn main() {
  let k = read::<i64>();
  let x = read::<i64>();

  for i in -k + 1..k {
    print!("{} ", x + i)
  }
  // println!("{}")
}



Measured memory_bytes: 4352
package main

import "fmt"

func main() {
	var s int
	fmt.Scan(&s)
	cnt := 1
	for {
		if s == 1 || s == 2 || s == 4 {
			fmt.Println(cnt + 3)
			break
		}
		if s%2 == 0 {
			s /= 2
		} else {
			s = 3*s + 1
		}
		cnt++
	}
}


Measured memory_bytes: 512
import copy
T = [[int(x) for  x in input().split()] for i in range(10)]

def E(ID):
#    if len(ID)!=4:
    #    print(len(ID))
    ret = 0
    for d in ID:
        d  =int(d)
        ret = T[ret][d]
    return ret

def solve(ID):
    e = E(ID)
    for i in range(4):
        for j in range(10):
            kari = copy.deepcopy(ID)
            if kari[i] == str(j):
                continue
            kari[i] = str(j)
            if T[E(kari)][e]==0:
                return 1
    for i in range(10):
        if T[E(ID)][i] == 0 and i!=e:
            return 1
    for i in range(3):
        kari = copy.deepcopy(ID)
        if kari[i] == kari[i+1]:
            continue
        kari[i],kari[i+1] =kari[i+1],kari[i]
        if T[E(kari)][e]==0:
            return 1
    if T[E(ID[:3]+[str(e)])][int(ID[3])]==0 and int(ID[3])!=e:
        return 1
    #print(ID ,e)
    return 0
ans = 0
for i in range(10000):
    ID  =[j for j in str(i)]
    ID = ['0']*(4-len(ID)) + ID
    ans += solve(ID)

print(ans)




Measured memory_bytes: 6348
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const double PI=acos(-1);
const ll mod=1e9+7;
typedef long long ll;
int f[65];
int main()
{
    int n;
    cin >> n;
    for(int i=0;i<n;i++){
        ll a;
        scanf("%lld",&a);
        for(ll j=0;j<62;j++)
            if(a&((ll)1<<j))
                f[j]++;
    }

    ll sum=0;
    for(ll i=0;i<62;i++){
  //      cout << f[i] << " ";
        sum+=(((((ll)1<<i)%mod)%mod)*(n-f[i])%mod)*f[i]%mod;
       // cout << f[i]*(n-f[i])*((ll)1<<i)<< endl;
        sum%=mod;
    }
    cout << sum << endl;
    return 0;
}




Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
    static Scanner sc;
    public static void main(String[] args) {
        sc = new Scanner(System.in);
        int N = sc.nextInt();
        int K = sc.nextInt();

        int ct = 0;
        for(int i = 0; i < N; i++) {
            int tmp = sc.nextInt();
            if(tmp >= K) {
                ct += 1;
            }
        }

        System.out.println(ct);
    }
}


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

int main(void){
  string str;
  getline(cin, str);
  for(int i = 0; i < str.length(); i++)
    if( str[i] >= 'a' && str[i] <= 'z')
      str[i] -= 'a' - 'A';
  
  cout << str << endl;
  return 0;
}

Measured memory_bytes: 1172
import java.io.InputStreamReader
import java.io.BufferedReader

fun main(args: Array<String>) {
  val br = BufferedReader(InputStreamReader(System.`in`))

  val(n, a, b) = br.readLine().split(" ").map { it.toInt() }

  tailrec fun rec(acc: Int, i: Int): Int =
    if(i == 0) acc
    else rec(acc + i%10, i/10)

  val ans = (1..n).fold(0) { acc, i ->
    val v = rec(0, i)
    if(v in a..b) acc + i else acc
  }

  println(ans)
}

Measured memory_bytes: 35880
from collections import Counter,defaultdict,deque
from heapq import heappop,heappush,heapify
import sys,bisect,math,itertools,fractions,pprint
sys.setrecursionlimit(10**8)
mod = 10**9+7
mod2 = 998244353
INF = float('inf')
def inp(): return int(sys.stdin.readline())
def inpl(): return list(map(int, sys.stdin.readline().split()))
def inpln(n): return list(int(sys.stdin.readline()) for i in range(n))

n,m = inpl()
g = [[] for i in range(n)]
for i in range(m):
    a,b = inpl()
    a -= 1
    b -= 1
    g[a].append(b)
    g[b].append(a)
res = 0
seen = [False] * n
def dfs(node,seen):
    global res
    seen[node] = True
    if sum(seen) == n:
        res += 1
    for now in g[node]:
        if not seen[now]:
          dfs(now,seen)  
    seen[node] = False
dfs(0,seen)
print(res)

Measured memory_bytes: 69080
#include<iostream>
#include<algorithm>
using namespace std;
#define N 100010
int a[N];
//• p1 ≥ p2 ≤ p3 ≥ ...
//• p1 ≤ p2 ≥ p3 ≤ ...
//两种情况下计算值独立
//ans1;ans2
int n;
long long deal()
{
    long long ans1=0;
    long long ans2=0;
    if(n%2==0)//偶数
    {
        //正影响：2*(n/2-1) 1*1
        //负影响：-2*(n/2-1) -1*1
        //两种模式下处理相同
        int i;
        for(i=1;i<=n/2-1;i++) ans1-=2*a[i];
        ans1-=a[i];
        i++;ans1+=a[i];
        i++;
        for(;i<=n;i++) ans1+=2*a[i];
        return ans1;
    }
    else//奇数
    {
        //正影响：1* 2  2*(n-3)/2
        //负影响：     -2*(n-1)/2
        //两种模式下处理不同,以下第一种
        int i;
        for(i=1;i<=(n-1)/2;i++) ans1-=2*a[i];
        ans1+=a[i];
        i++;
        ans1+=a[i];
        i++;
        for(;i<=n;i++)  ans1+=2*a[i];
        //以下第二种
        for(i=1;i<=(n-3)/2;i++) ans2-=2*a[i];
        ans2-=a[i];
        i++;
        ans2-=a[i];
        i++;
        for(;i<=n;i++) ans2+=2*a[i];
        return max(ans1,ans2);
    }
}
int main()
{
    ios::sync_with_stdio(false);
    while(cin>>n)
    {
        for(int i=1;i<=n;i++)
        {
            cin>>a[i];
        }
        sort(a+1,a+1+n);
        cout<<deal()<<endl;
    }
}


Measured memory_bytes: 640
#include<iostream>
#include<string>
#include<cstdio>
#include<algorithm>
#include<cstdlib>
#include<cmath>
#include<vector>
#include<utility>
#include<queue>
#include<stack>
#include<set>
#include<map>
#include<unordered_set>
#include<unordered_map>
#include<bitset>
using namespace std;
#define INF 2000000007
#define LINF 100000000000000007
#define MOD 1000000007
#define int long long
#define rep(i,n) for(int i=0;i<n;i++)
#define repb(i, n) for (int i = n - 1; i >= 0; i--)
#define MODE 0
#ifdef MODE
#define DEB(X) cout<< #X <<": "<<X<<" ";
#define ARDEB(i,X) cout<< #X <<"["<<i<<"]: "<<X[i]<<" ";
#define END cout<<endl;
#else
#define DEB(X) {}
#define ARDEB(i,X) {}
#define END {}
#endif
typedef long long ll;
typedef pair<int,int> P;
struct edge{int to,cost;};
int ceil2(int a,int b){if(a%b){return a/b+1;}else{return a/b;}}
using namespace std;
string k;
int n,m,x,ans=INF;
int c[14],a[14][14];
signed main(){
	cin>>n>>m>>x;
	rep(i,n){
		cin>>c[i];
		rep(j,m){
			cin>>a[i][j];
		}
	}
	//cout<<(1<<m)<<endl;
	rep(i,1<<n){
		int und[14]={0},cnt=0;
		rep(j,n){
			if(i&(1<<j)){
				cnt+=c[j];
				rep(k,m){
					und[k]+=a[j][k];
				}
			}
		}
		int f=1;
		rep(k,m){
			if(und[k]<x)f=0;
		}
		if(f)ans=min(cnt,ans);
	}
	if(ans==INF)cout<<-1<<endl;
	else cout<<ans<<endl;
}


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

int main(){
    int n;
    cin >> n;
    int sum = 0;
    for(int i = 1; i <= n; i++){
        sum += i;
        if(sum >= n){
            for(int j = 1; j <= i; j++){
                if(j != sum - n) cout << j << endl;
            }
            return 0;
        }
    }
    return 0;
}

Measured memory_bytes: 256
import Control.Monad
import Data.List

toInt :: String -> Int
toInt = read :: String -> Int

main = do
  [n, d] <- map toInt . words <$> getLine
  l <- replicateM n $ map toInt . words <$> getLine
  print $ length $ filter (\[x, y] -> x*x+y*y <= d*d) l


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

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

void solve() {
    int H; cin >> H;
    int A; cin >> A;
    cout << (H+A-1)/A << "\n";
}

signed main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    solve();
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <stdio.h>
#include <math.h>
#include <string.h>
#include <time.h>
#include <stdlib.h>
#include <string>
#include <bitset>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <algorithm>
#include <sstream>
#include <stack>
#include <iomanip>
using namespace std;
#define pb push_back
#define mp make_pair
typedef pair<int,int> pii;
typedef long long ll;
typedef double ld;
typedef vector<int> vi;
#define fi first
#define se second
#define fe first
#define FO(x) {freopen(#x".in","r",stdin);freopen(#x".out","w",stdout);}
#define Edg int M=0,fst[SZ],vb[SZ],nxt[SZ];void ad_de(int a,int b){++M;nxt[M]=fst[a];fst[a]=M;vb[M]=b;}void adde(int a,int b){ad_de(a,b);ad_de(b,a);}
#define Edgc int M=0,fst[SZ],vb[SZ],nxt[SZ],vc[SZ];void ad_de(int a,int b,int c){++M;nxt[M]=fst[a];fst[a]=M;vb[M]=b;vc[M]=c;}void adde(int a,int b,int c){ad_de(a,b,c);ad_de(b,a,c);}
#define es(x,e) (int e=fst[x];e;e=nxt[e])
#define esb(x,e,b) (int e=fst[x],b=vb[e];e;e=nxt[e],b=vb[e])
#define VIZ {printf("digraph G{\n"); for(int i=1;i<=n;i++) for es(i,e) printf("%d->%d;\n",i,vb[e]); puts("}");}
#define VIZ2 {printf("graph G{\n"); for(int i=1;i<=n;i++) for es(i,e) if(vb[e]>=i)printf("%d--%d;\n",i,vb[e]); puts("}");}
#define SZ 666666
int n,_a[SZ],*a=_a+1;
int main()
{
	scanf("%d",&n);
	for(int i=0;i<n;++i)
		scanf("%d",a+i);
	sort(a,a+n); reverse(a,a+n); a[-1]=a[0];
	int g=0; while(g<n&&g<a[g]) ++g; --g;
	int h=a[g]-g+1,y=0;
	while(y+g<n&&a[y+g]>g) ++y; ++y;
	if((h&1)||(y&1)) puts("First");
	else puts("Second");
}


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

using ll = long long;
template <class T> using p = pair<T, T>;
template <class T> using vt = vector<T>;

#define rep(i, n)   for (int i = 0; i < (n); i++)
#define sz(x)       (int)(x).size()
#define eb          emplace_back
#define pb          push_back
#define all(x)      (x).begin(), (x).end()
#define rall(x)     (x).rbegin(), (x).rend()
#define fi          first
#define se          second

signed main() {
  ios::sync_with_stdio(0), cin.tie(0);

  int a, b, c;
  cin >> a >> b >> c;
  cout << c * (a / b + (a % b != 0)) << endl;

  return 0;
}

Measured memory_bytes: 3660
#include<bits/stdc++.h> 
//#define <- プログラムの文字列を置換する
//typedef <- 新しい型に名前を付けるためのキーワード

using namespace std;

typedef long long ll;
typedef pair<int,int> pii;

const long long MOD = 1e9 + 7;
const long long INF = 1e15;
const int INF_INT = 1e9;

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

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

template<class TYPE>
struct edge{
    TYPE to,cost; 
    edge(TYPE t,TYPE c){
        to = t;
        cost = c;
    }
};

int main(){
    int N,M;
    cin >> N >> M;
    priority_queue<int> q;
    for(int i = 0; i < N; i++){
        int a;
        cin >> a;
        q.push(a);
    }
    for(int i = 0; i < M; i++){
        int maxi = q.top();
        q.pop();
        q.push(maxi/2);
    }
    ll ans = 0;
    while(!q.empty()){
        int value = q.top();
        q.pop();
        ans += value;
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 3924
#include <bits/stdc++.h>
using namespace std;
int main(){
  int n,k;
  cin>>n>>k;
  int w=k;
  int m=k-1;
  for(int i=0;i<n;i++){
      if(i==0){
        continue;
      }
      if(m==1){
        break;
      }
        w=w*m;
  }
  cout<<w<<endl;
}

Measured memory_bytes: 256
#include <iostream>

using namespace std;

int N;

void solve() {
    int counter = 0;
    if (!N)
        return;

    while (true) {
        ++counter;
        int kagen = counter * (counter - 1) / 2;
        int jyogen = counter * (counter + 1) / 2;
        if (kagen < N && N <= jyogen) {
            cout << counter << endl;
            N -= counter;
            break;
        }
    }

    solve();
}

int main() {
    cin >> N;

    solve();
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
using namespace std;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
const long long INF = 1LL<<60;

const int MAX_N = 110;
const int MAX_V = 100100;


int main() 
{
	long long n, s = 0;
	cin >> n;
	vector<long long> a(n);
	for (int i = 0; i < n; ++i) {
		cin >> a[i];
		s += a[i];
	}

	long long as = 0;
	for (int i = 1; i < n; i += 2)
		as += a[i];

	long long x = (s - 2 * as);	
	cout << x;
	for (int i = 1; i < n; i++) {
		x = (2 * a[i-1] - x);
		cout << " " << x;
	}

	cout << endl;
	return 0;
}



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

int main()
{
	int residence[4][3][10] = {};//?£????????????¨?±?
	int InputSize = 0;
	int b = 0;//building??????
	int f = 0;//floor??????
	int r = 0;//room??????
	int mem = 0;


			  /*
			  ???????????????
			  ???????????????????????????????§?????????°??????????????????????????????????§??????£??????????????¨?????¨?????????
			  ???????????????????????????????????£????????????
			  */



			  //??\?????????
	cin >> InputSize;
	for (int i = 0; i<InputSize; i++)
	{
		cin >> b >> f >> r;
		//b,f,r??????1????????°?????\????????????????????¢????????????????????¨????????????
		cin >> mem;
		residence[b - 1][f - 1][r - 1]+=mem;
	}


	//????????????
	for (int i = 0; i<4; i++)//?£?????????????
	{
		for (int j = 0; j<3; j++)//???????????????
		{
			for (int k = 0; k<10; k++)//??¨?±?????????????
			{
				cout <<' '<< residence[i][j][k];
			}
			cout << endl;
		}
		//?£??????????????????¨???????????£??????'#'???20??¨??????????????????????????????????¬?????£???¨????????????????????????
		//3??????????£???§???'#'?????¨?????????????????§if??§?????¶???????????????
		if (i<3)cout << "####################" << endl;
	}
	return 0;
}
//???????????¨???????????????????§???§???

Measured memory_bytes: 3020
#include <iostream>
#include <vector>
#include <algorithm>
#include <functional>
#include <cmath>
#include <map>
#include <string>

#define reps(i,s,n) for(int (i) = (s); (i) < (n); (i)++)
#define rep(i,n) reps(i,0,n)
using namespace std;
using ll = long long;

int main(){
	string str, str2;
	cin >> str >> str2;
	map<string, int> num;
	num["A"] = 10;
	num["B"] = 11;
	num["C"] = 12;
	num["D"] = 13;
	num["E"] = 14;
	num["F"] = 15;
	if (num[str] > num[str2]) cout << ">" << endl;
	else if (num[str] < num[str2]) cout << "<" << endl;
	else cout << "=" << endl;

    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll INF = 1LL << 40;
#define FOR(i,k,n) for(int i=(k);i<(n);++i)
#define all(x) ((x).begin(),(x).end())

int main(){
    int N, M; cin >> N >> M;
    int a, b;
    vector<int> v(N,0);
    FOR(i,0,M){
        cin >> a >> b;
        a--; b--;
        v[a]++; v[b]++;
    }
    FOR(i,0,N){
        cout << v[i] << endl;
    }
    return 0;

}

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

int main()
{
    long long s;
    cin >> s;
    int n = to_string(s).length();
    unsigned long long answer = 0;
    for(int i = 0; i < n; i++){
        long long sub = s / pow(10, n - 1 - i);
        if(i < n - 1){
            answer = answer + sub * pow(2, n - 2 - i);
        }
        else {
            answer = answer + sub * pow(2, n - 1 - i);
        }
    }
    for(int i = 1; i < n; i++){
        for(int j = i; j < n; j++){
            long long sub = (s % (int)pow(10, n - i)/ pow(10, n - 1 - j));
            if(j < n - 1){
                answer = answer + sub * pow(2, n - 1 - (j - i) - 2);
                }
                else {
                    answer = answer + sub * pow(2, n - 1 - (j - i) - 1);
                    }
                }
    }
    cout << answer << endl;
    return 0;
}

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


int main()
{
    int n,k,a,sum=0;
    cin>>n>>k;
    for(int i=0 ; i<n ; i++)
    {
        cin>>a;
        if(a>=k)
        sum++;
    }
    cout<<sum;
    
    
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define INF 2147483647
#define inf 1000000007
#define SYOU(x) setprecision(x)
#define abs(x,y) (max(x,y)-min(x,y))
#define lol long long
#define mp make_pair
#define fi first
#define se second
using namespace std;
long long i[3000000];
lol u[111111];
lol ii[121111];
bool o;
bool ans[5];
signed main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  long long a,b,c,d=0,e=0,f=0,g=0,h=0,j=0,can;
  string s;
  o=true;
  cin >>a;
  for(int n=0;n<a;n++){
    cin >>i[n]>>u[n]>>ii[n];
    e=i[n]-j,can=abs(g,u[n])+abs(h,ii[n]);
    g=u[n],h=ii[n],j=i[n];
    if(e<can) o=false;
    else{
      if((e-can)%2!=0) o=false;
    }
  }
  if(o) cout <<"Yes\n";
  else cout <<"No\n";
  return (0);
}


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

using namespace std;

int main(){
	int N, C; cin>>N>>C;
	int a[110];
	for(int n=0; n<N; n++)
		cin>>a[n];
	sort(a, a+N);
	int nh = 0;
	for(int x=0; x<N; x++){
		if(a[x]<=C){
			C -= a[x];
			nh++;
		} else {
			C = 0;
			break;
		}
	}
	if(C>0)
		nh--;
	cout << nh << endl;
	return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
using Int = long long;
template<typename T1,typename T2> void chmin(T1 &a,T2 b){if(a>b) a=b;};
template<typename T1,typename T2> void chmax(T1 &a,T2 b){if(a<b) a=b;};

template <typename T, typename E>
struct SegmentTree{
  using F = function<T(T,T)>;
  using G = function<T(T,E)>;
  using H= function<E(E,E)>;

  Int n, height;
  F f;
  G g;
  H h;
  T ti;
  E ei;

  vector<T> dat;
  vector<E> laz;
  SegmentTree(F f, G g, H h, T ti, E ei):
    f(f), g(g), h(h), ti(ti), ei(ei){}

  void init(Int n_){
    n = 1;
    height = 0;
    while(n < n_) n <<= 1, height++;
    dat.assign(2*n, ti);
    laz.assign(2*n, ei);
  }

  void build(const vector<T> &v){
    Int n_ = v.size();
    init(n_);
    for(Int i=0;i<n_;i++) dat[n+i] = v[i];
    for(Int i=n-1;i;i--)
      dat[i] = f(dat[(i<<1)|0], dat[(i<<1)|1]);
  }

  inline T reflect(Int k){
    return laz[k] == ei? dat[k]:(g(dat[k], laz[k]));
  }

  inline void eval(Int k){
    if(laz[k] == ei) return;
    laz[(k<<1) | 0] = h(laz[(k<<1) | 0], laz[k]);
    laz[(k<<1) | 1] = h(laz[(k<<1) | 1], laz[k]);
    dat[k] = reflect(k);
    laz[k] = ei;
  }

  inline void thrust(Int k){
    for(Int i=height;i;i--) eval(k>>i);
  }

  inline void recalc(Int k){
    while(k>>=1)
      dat[k] = f(reflect((k<<1)|0), reflect((k<<1)|1));
  }
  void update(Int a, Int b, E x) {
    thrust(a+=n);
    thrust(b+=n-1);
    for(Int l=a, r=b+1; l<r; l>>=1, r>>=1){
      if(l&1) laz[l] = h(laz[l],x), l++;
      if(r&1) --r, laz[r] = h(laz[r], x);
    }

    recalc(a);
    recalc(b);
  }

  void set_val(Int a, T x){
    thrust(a+=n);
    dat[a] = x; laz[a] = ei;
    recalc(a);
  }

  T query(Int a,Int b){
    thrust(a += n);
    thrust(b+=n-1);
    T vl = ti, vr = ti;
    for(Int l=a, r=b+1; l < r; l>>=1, r>>=1){
      if(l&1) vl = f(vl, reflect(l++));
      if(r&1) vr = f(reflect(--r), vr);
    }
    return f(vl, vr);
  }
};

signed main(){
  cin.tie(0);
  ios::sync_with_stdio(false);

  Int n;
  cin>>n;
  vector<Int> v(n);
  for(Int i=0;i<n;i++) cin>>v[i];

  const Int MAX = 1e5+100;
  auto f=[](Int a,Int b){return a+b;};

  SegmentTree<Int, Int> seg1(f,f,f,0,0);
  SegmentTree<Int, Int> seg2(f,f,f,0,0);

  seg1.build(vector<Int>(MAX,0));
  seg2.build(vector<Int>(MAX,0));
  
  vector<Int> dp1(n,0),dp2(n,0);
  for(Int i=0;i<n;i++){
    dp1[i]=seg1.query(v[i]+1,MAX);
    seg1.update(v[i],v[i]+1,1);    
  }
  for(Int i=n-1;i>=0;i--){
    dp2[i]=seg2.query(v[i]+1,MAX);
    seg2.update(v[i],v[i]+1,1);    
  }
  
  Int ans=0;  
  for(Int i=0;i<n;i++) ans+=min(dp1[i],dp2[i]);
  cout<<ans<<endl;
  return 0;
}



Measured memory_bytes: 13392
n = int(input())
x = list(map(int, input().split()))
# 1 ≤ x ≤ 100 に注目すると, 集合地点を全探索できる
ans = 1e100
for p in range(101):
  cnt = 0
  for i in x:
    cnt += (p - i) ** 2
  if ans > cnt:
    ans = cnt
print(ans)

Measured memory_bytes: 3060
# B - Distance
def calc_distance(X, Y):
	return math.sqrt(X ** 2 + Y ** 2)	
	

import math

N, D = map(int, input().split())
ans = 0

for _ in range(N):
	X, Y = map(int, input().split())
	d = calc_distance(X, Y)
	
	if d <= D:
		ans += 1

print(ans)

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

int main(){
  int n;
  cin>>n;
  vector<ll> a(n);
  rep(i,n) cin>>a[i];
  
  sort(a.begin(),a.end());
  
  vector<ll> b(n);
  b[0]=a[0];
  for(int i=1;i<n;i++) b[i]=a[i]+b[i-1];
  
  for(int i=n-2;i>=0;i--){
    if(b[i]*2>=a[i+1]) continue;
    else{
      cout << n-i-1 <<endl;
      return 0;
    }
  }
  cout << n << endl;
}

Measured memory_bytes: 1792
//
//  ROIGold.cpp
//  Main calisma
//
//  Created by Rakhman on 05/02/2019.
//  Copyright © 2019 Rakhman. All rights reserved.
//

#include <cstring>
#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 <queue>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <cassert>
#include <iterator>

#define ios ios_base::sync_with_stdio(0), cout.tie(0), cin.tie(0);
#define S second
#define F first
#define pb push_back
#define nl '\n'
#define NL cout << '\n';
#define EX exit(0)
#define all(s) s.begin(), s.end()
#define FOR(i, start, finish, k) for(int i = start; i <= finish; i += k)

const int MXN = 1e5 + 2;
const long long MNN = 2e3 + 200;
const long long MOD = 1e9 + 7;
const long long INF = 1e18;
const int OO = 1e9 + 500;

typedef long long llong;
typedef unsigned long long ullong;

using namespace std;

string s, t;
int nx[MXN][30];
llong cnt, pos;

void upd(char ch){
    pos = nx[pos][ch - 'a'] + 1;
    if(pos - 1 == s.size()){
        pos = 0;
        cnt++;
    }
}

int main () {
    ios;
    cin >> s >> t;
    for(int j = 0; j < 26; j++){
        nx[s.size()][j] = -1;
    }
    for(int i = s.size() - 1; i >= 0; i--){
        for(int j = 0; j < 26; j++){
            nx[i][j] = nx[i + 1][j];
        }
        nx[i][s[i] - 'a'] = i;
    }
    for(int j = 0; j < t.size(); j++){
        if(nx[pos][t[j] - 'a'] != -1){
            upd(t[j]);
        }else{
            if(nx[0][t[j] - 'a'] == -1) return cout << -1, 0;
            else{
                cnt++;
                pos = 0;
                upd(t[j]);
            }
        }
    }
    cout << cnt * s.size() + pos;
    return 0;
}


Measured memory_bytes: 12240
<?php
// A
fscanf(STDIN, '%d', $n);

switch ($n % 10) {
    case 2:
    case 4:
    case 5:
    case 7:
    case 9:
        $ans = 'hon';
        break;
    case 0:
    case 1:
    case 6:
    case 8:
        $ans = 'pon';
        break;
    case 3:
        $ans = 'bon';
        break;
}
echo $ans;

Measured memory_bytes: 16124
#include <stdio.h>
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>

using namespace std;

struct Gem{
	int x; int y; bool isFound;
	Gem(){ x = 10; y = 10; isFound = false; }
};

int main(){
	int n;

	while(cin >> n && n != 0){
		Gem gems[20], robot;
		for (int i = 0; i < n; ++i){
			cin >> gems[i].x >> gems[i].y;
		}

		int m;
		cin >> m;
		for (int i = 0; i < m; ++i){
			char s; int dist;
			cin >> s >> dist;
			
			for (int j = 0; j < dist; ++j){
				switch (s)
				{
				case (int)'N':
					robot.y += 1;
					break;
				case (int)'E':
					robot.x += 1;
					break;
				case (int)'S':
					robot.y -= 1;
					break;
				case (int)'W':
					robot.x -= 1;
					break;
				}
				for (int i = 0; i < n; ++i){
					if (robot.x == gems[i].x && robot.y == gems[i].y){
						gems[i].isFound = true;
					}
				}
			}

		}


		int res = 1;
		for (int i = 0; i < n; ++i){
				res *= gems[i].isFound;
		}
		cout << ((res == 1) ? "Yes" : "No") << endl;


	}


	return 0;
}

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

const int MAXW = 1e5 + 10;

long long knapsack[MAXW];
int N,W;

int main(){

	cin >> N >> W;

	for(int item = 1;item<=N;item++){
		int w,v;
		cin >> w >> v;
		for(int i = W;i>=w;i--) knapsack[i] = max(knapsack[i-w] + v,knapsack[i]);
	}

	cout << knapsack[W] << endl;

	return 0;

}

Measured memory_bytes: 1024
#include<stdio.h>
int flg[1000000];
int main(void)
{
	int n,i,j,cnt;
	for(i=2;i<=999999;i++)	{
		flg[i]=1;
	}
	for(i=2;i*i<=999999;i++)	{
		if(flg[i]==1)	{
			j=2;
			while(i*j<=999999)	{
				flg[i*j]=0;
				j++;
			}
		}
	}
	while(scanf("%d",&n)!=EOF)	{
		cnt=0;
		for(i=2;i<=n;i++)	{
			if(flg[i]==1)	{
				cnt++;
			}
		}
		printf("%d\n",cnt);
	}
	return 0;
}


Measured memory_bytes: 4928
#include <iostream>
#include <cstdlib>
#include <vector>
#include <algorithm>
#include <cassert>
#include <numeric>

using namespace std;

using ll = long long;

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

    vector<int> a;
    a.reserve(n);
    
    if (n >= 15000) {
        int r = n - 15000;
        for (int i = 2; i <= 30000; i++) {
            if (i % 6 == 0) {
                if (r > 0) {
                    a.push_back(i);
                    r--;
                }
            } else if (i % 2 == 0 || i % 3 == 0) {
                a.push_back(i);   
            }
        }
    } else if (n == 3) {
        a = {2, 5, 63};   
    } else {
        a.push_back(2);
        a.push_back(3);
        a.push_back(4);
        a.push_back(9);
        
        for (int i = 1; 6 * i + 2 <= 30000 && a.size() + 2 <= n; i++) {
            a.push_back(6 * i + 2);
            a.push_back(6 * i + 4);
        }
        
        for (int i = 1; 12 * i + 3 <= 30000 && a.size() + 2 <= n; i++) {
            a.push_back(12 * i + 3);
            a.push_back(12 * i + 9);
        }
        
        if (a.size() != n) {
            a.push_back(6);   
        }
    }
    
    sort(a.begin(), a.end());
    
    for (int i = 0; i < n; i++) {
        cout << a[i] << " \n"[i + 1 == n];   
    }
}


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

typedef long long ll;

const int INF = 1e9;
const int MOD = 1e9+7;
const ll LLINF = 1e18;

#define YES(n) cout << ((n) ? "YES" : "NO"  ) << endl
#define Yes(n) cout << ((n) ? "Yes" : "No"  ) << endl
#define ANS(n) cout << (n) << endl

#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define FORR(i,a,b) for(int i=(a);i>=(b);i--)

#define ALL(obj) (obj).begin(),(obj).end()

#define pii pair<int,int>

#define pb(a) push_back(a)
#define mp make_pair

int main()
{
	int a,b,c;
	cin >> a >> b >> c;
	Yes(a == b && b == c);
	return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<array>
#include<algorithm>
#include<cstdint>
#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 D; std::cin >> D;
  int c[26];
  for(int& ci: c) std::cin >> ci;
  std::vector<std::array<int,26>> s(D);
  for(int d = 0; d < D; ++d) {
    for(int& si: s[d]) std::cin >> si;
  }
  std::vector<int> t(D);
  for(int& ti: t) std::cin >> ti;
  
  auto score = [&]()->int { 
    int ans = 0;
    int last[26];
    std::fill_n(last, 26, -1);
    for(int d = 0; d < D; ++d) {
      ans += s[d][t[d]-1];
      last[t[d]-1] = d;
      for(int cx = 0; cx < 26; ++cx) {
        ans -= (d-last[cx])*c[cx];
      }
    }
    return ans;
  };
  int M; std::cin >> M;
  for(int m = 0; m < M; ++m) {
    int d, q; std::cin >> d >> q;
    t[d-1] = q;
    std::cout << score() << "\n";
  }
  return 0;
}


Measured memory_bytes: 3684
#include <stdio.h>
int main(void)
{
    int n,i;
    long a[3]={2,1};
    scanf("%d",&n);
    for(i=0;i<n;i++){
        a[2]=a[0]+a[1];
        a[0]=a[1];
        a[1]=a[2];
    }
    printf("%ld",a[0]);
    return 0;
}


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

int main(){
  vector<int> v,v2;
  int counter,tmp,max,second,result;
  
  cin >> counter;
  
  for(int i=0;i<counter;i++){
  	cin >> tmp;
    v.emplace_back(tmp);
  }
  max=*max_element(v.begin(),v.end());
  v2=v;
  sort(v2.begin(),v2.end(),greater<int>());
  second=v2[1];
  for(int i=0;i<counter;i++){
    if(v[i]==max){
      cout << second << endl;
      continue;
    }
    cout << max << endl;
  }
  
  return 0;
}

Measured memory_bytes: 3316
data = input().split()
A = int(data[0])
B = int(data[1])
K = int(data[2])
cnt = 0

for lop in range(100,0,-1):
    if A%lop == 0 and B%lop == 0:
        cnt+=1
    if cnt == K:
        print(lop)
        break



Measured memory_bytes: 2940
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstring>
#include<cmath>
using namespace std;
inline int read(){
	int x = 0; char ch = getchar(); bool positive = 1;
	for (; !isdigit(ch); ch = getchar())	if (ch == '-')	positive = 0;
	for (; isdigit(ch); ch = getchar())	x = x * 10 + ch - '0';
	return positive ? x : -x;
}
inline void write(int a){
    if(a>=10)write(a/10);
    putchar('0'+a%10);
}
inline void writeln(int a){
    write(a); puts("");
}
int n,m,k;
int main(){
    n=read(); m=read(); k=read();
    for(int i=0;i<=n;i++){
    	for(int j=0;j<=m;j++){
    		if(i*m+j*n-2*i*j==k){
    			puts("Yes"); return 0;
			}
		}
	}
	puts("No");
}

Measured memory_bytes: 888
#include<iostream>
#include<math.h>
#include<iomanip>
using namespace std;

int main(){
    double r,round,s;
    cin >> r;
    round = 2*M_PI*r;
    s = M_PI*r*r;
    cout << setprecision(20)<< s << " " << round << endl;
}



Measured memory_bytes: 3264
#include <cstdio>
#include <cstring>
#include <climits>
#include <algorithm>

using namespace std;

int r[100], c[100];
int dp[100][100];

int optMat(int left, int right)
{
	if (dp[left][right] >= 0){
		return (dp[left][right]);
	}
	if (left == right){
		return (0);
	}
	
	int res = INT_MAX;
	for (int i = left; i < right; i++){
		res = min(res, optMat(left, i) + optMat(i + 1, right) + r[left] * c[i] * c[right]);
	}
	
	return (dp[left][right] = res);
}

int main()
{
	int N;
	
	scanf("%d", &N);
	
	for (int i = 0; i < N; i++){
		scanf("%d %d", &r[i], &c[i]);
	}
	
	memset(dp, -1, sizeof(dp));
	
	printf("%d\n", optMat(0, N - 1));
	
	return (0);
}

Measured memory_bytes: 1076
#include <bits/stdc++.h>
using namespace std;
#define rep(i,N) for(int i=0;i<int(N);++i)
#define rep1(i,N) for(int i=1;i<int(N);++i)
#define all(a) (a).begin(),(a).end()		//sort(all(vi S)) sort(all(string S))
#define print(v) { cerr<<#v<<": [ "; for(auto _ : v) cerr<<_<<", "; cerr<<"]"<<endl; }
#define printpair(v) { cerr<<#v<<": [ "; for(auto _ : v) cerr<<"{"<<_.first<<","<<_.second<<"}"<<", "; cerr<<"]"<<endl; }

using P = pair<int, int>;		//P.first, P.second
typedef long long ll;
typedef vector<int> vi;
typedef set<int> seti;
typedef vector<string> vs;

const int MOD = 1e9+7;
const int INF = 1e9;
int a[540][540];
int H,W;
bool is_in(int x, int y){
	return 0<=x&&x<H&&0<=y&&y<W;
}
int main() {
	cin>>H>>W;
	rep(i,H)rep(j,W){
		cin>>a[i][j];
	}
	vector<int> x1,y1,x2,y2;
	rep(i,H)rep(j,W-1){
		if(a[i][j]%2==1){
			a[i][j]--;
			a[i][j+1]++;
			x1.push_back(i+1);
			y1.push_back(j+1);
			x2.push_back(i+1);
			y2.push_back(j+2);
			//cout<<i+1<<" "<<j+1<<" "<<i+1<<" "<<j+2<<endl;
		}
	}
	rep(i,H-1){
		if(a[i][W-1]%2==1){
			a[i][W-1]--;
			a[i+1][W-1]++;
			//cout<<i+1<<" "<<W<<" "<<i+2<<" "<<W<<endl;
			x1.push_back(i+1);
			y1.push_back(W);
			x2.push_back(i+2);
			y2.push_back(W);
		}
	}
	int N = x1.size();
	cout<<N<<endl;
	rep(i,N){
		cout<<x1[i]<<" "<<y1[i]<<" "<<x2[i]<<" "<<y2[i]<<endl;
	}
}

Measured memory_bytes: 5220
#include <bits/stdc++.h>
#define ll long long
#define ld long double
#pragma 03
using namespace std;
pair <int, int> a[100005], b[100005];
int par[100005];
int cfind(int x){
    if (par[x] == x) return x;
    return par[x] = cfind(par[x]);
}
void uni(int x, int y){
    x = cfind(x);
    y = cfind(y);
    if (x != y) par[x] = y;
}
int main(){
 	int n;
    cin >> n;
    for (int i = 0; i<n; i++){
        cin >> a[i].first;
        a[i].second = i;
    }
    for (int i = 0; i<n; i++){
        cin >> b[i].first;
        b[i].second = i;
    }
    sort(a, a+n);
    sort(b, b+n);
    bool bad = false;
    for (int i = 0; i<n; i++){
        if (a[i].first > b[i].first) bad = true;
    }
    if (bad){
        cout << "No\n";
        return 0;
    }
 	for (int i = 0; i<n; i++) par[i] = i;
 	bool okay = false;
    for (int i = 0; i<n; i++){
        uni(a[i].second, b[i].second);
        if (i && a[i] <= b[i-1]) okay = true;
    }
 	bool nbad = true;
    for (int i = 0; i < n; i++){
        if (cfind(i) != cfind(0)) nbad = false;
	}
    if (nbad && !okay) cout << "No\n";
    else cout << "Yes\n";
    return 0;
}

Measured memory_bytes: 3712
#include <iostream>
#include <cmath>
#include <string>
#include <algorithm>
#include <set>
#include <vector>
#include <map>
#include <list>
#include <stack>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <queue>
#define mkp make_pair
#define pr(num) cout << num << "\n"
#define max(a, b) ((a)>(b) ? (a):(b))
#define min(a, b) ((a)<(b) ? (a):(b))
#define chmax(a, b) (a<b ? a=b : 0)
#define chmin(a, b) (a>b ? a=b : 0)
#define INF 1000000000000000000
#define MOD 1000000007LL
#define MAX 100010
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
typedef map<ll, ll> Map;




int main(void) {
    ll N;
    ll A, B;
    cin >> N;
    cin >> A >> B;
    ll i;
    ll p;
    ll a=0, b=0, c=0;
    
    for(i=0; i<N; i++) {
        cin >> p;
        if(p<=A) a++;
        else if(A+1<=p && p<=B) b++;
        else if(B+1<=p) c++;
        
    }
    
    pr(min(a, min(b, c)));
    
}














Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define f first
#define s second
#define pb push_back
typedef long long ll;
typedef unsigned long long ull;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef pair<ll, ll> pll;
typedef vector<pii> vpii;
typedef vector<pll> vpll;
typedef vector<ll> vll;
typedef pair<string, int> psi;
const int MN = 27, BASE = 31, MOD = 1e9+7;
ll fpow(ll b, ll exp, ll mod){if(exp == 0) return 1;ll t = fpow(b,exp/2,mod);if(exp&1) return t*t%mod*b%mod;return t*t%mod;}
ll divmod(ll i, ll j, ll mod){i%=mod,j%=mod;return i*fpow(j,mod-2,mod)%mod;}
int x, y, a, b, c;
vll p;
vll q;
vll r;
priority_queue<ll, vll, greater<ll>> pq;
int main() {
    ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
    cin >> x >> y >> a >> b >> c;
    for (int i = 0, z; i<a;i++) {
        cin >> z;
        p.pb(z);
    }
    for (int i = 0, z; i<b;i++) {
        cin >> z;
        q.pb(z);
    }
    for (int i =0, z;i<c;i++) {
        cin >> z;
        r.pb(z);
    }
    sort(p.begin(), p.end(), greater<int>());
    sort(q.begin(), q.end(), greater<int>());
    sort(r.begin(), r.end());
    ll sume = 0;
    for (int i = 0; i<x;i++) {
        pq.push({p[i]});
        sume += p[i];
    }
    for (int i = 0; i<y;i++) {
        pq.push({q[i]});
        sume += q[i];
    }
    while (!pq.empty()) {
        int bye = pq.top();
        if (r.empty()) {
            break;
        }
        int replace = r.back();
        if (replace > bye){
            pq.pop();
            r.pop_back();
            sume -= bye;
            sume += replace;
        }
        else {
            break;
        }
    }
    cout << sume << '\n';
    return 0;
}

Measured memory_bytes: 4852
import sys


stdin = sys.stdin
def ns(): return stdin.readline().rstrip()
def ni(): return int(stdin.readline().rstrip())
def nm(): return map(int, stdin.readline().split())
def nl(): return list(map(int, stdin.readline().split()))


def main():
    n = ni()
    xy = list(nl() for _ in range(n))

    xpy = [x + y for x, y in xy]
    xmy = [x - y for x, y in xy]

    print(max(max(xpy) - min(xpy), max(xmy) - min(xmy)))


if __name__ == '__main__':
    main()


Measured memory_bytes: 61340
#include "iostream"
#include "climits"
#include "list"
#include "queue"
#include "stack"
#include "set"
#include "functional"
#include "algorithm"
#include "string"
#include "map"
#include "unordered_map"
#include "unordered_set"
#include "iomanip"
#include "cmath"
#include "random"
#include "bitset"
#include "cstdio"
#include "numeric"
#include "ctime"

using namespace std;

const long long int MOD = 1000000007;
//const int MOD = 998244353;

//long long int N, M, K, H, W, L, R;
long long int N, M, K, H, W, L, R;



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

	cin >> N;
	vector<long long int>a(N);
	vector<long long int>b(N);
	for (auto &i : a)cin >> i;
	for (auto &i : b)cin >> i;
	vector<long long int>v;
	for (int i = 0; i < N; i++) {
		v.push_back(a[i] - b[i]);
	}
	sort(v.begin(), v.end());
	if (accumulate(v.begin(), v.end(), 0LL) < 0) {
		cout << -1 << endl;
		return 0;
	}
	int ans = 0;
	long long int sum = 0;
	for (auto i : v) {
		if (i < 0) {
			sum -= i;
			ans++;
		}
	}
	reverse(v.begin(), v.end());
	for (auto i : v) {
		if (sum > 0) {
			ans++;
			sum -= i;
		}
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 3064
#include <iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<map>
#include<set>
#include<stack>
#include<queue>
#include<math.h>
using namespace std;
typedef long long ll;
#define int long long
typedef vector<int> VI;
typedef pair<int, int> pii;
typedef priority_queue<int> PQ;
#define fore(i,a) for(auto &i:a)
#define REP(i,n) for(int i=0;i<n;i++)
#define eREP(i,n) for(int i=0;i<=n;i++)
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define eFOR(i,a,b) for(int i=(a);i<=(b);++i)
#define SORT(c) sort((c).begin(),(c).end())
#define rSORT(c) sort((c).rbegin(),(c).rend())
#define LB(x,a) lower_bound((x).begin(),(x).end(),(a))
#define UB(x,a) upper_bound((x).begin(),(x).end(),(a))
#define INF 1000000000
#define LLINF 9223372036854775807
#define mod 1000000007
//vector<vector<int> > dp;
//vector<vector<vector<int> > > vvvi;
//dp=vector<vector<int> >(N, vector<int>(M,0));
//vector<pair<int,int> > v;
//v.push_back(make_pair(x,y));
//priority_queue<int,vector<int>, greater<int> > q2;



signed main(){
cin.tie(0);
ios::sync_with_stdio(false);

	int N,cnt=0,ans=LLINF;
	cin >> N;
	VI A(N + 1, 0);

	eFOR(i, 1, N) {
		cin >> A[i];
		A[i] += A[i - 1];
	}

	FOR(i, 2, N) {
		int left = 0;
		int right = i;
		while (1 < right - left) {
			int mid = (right + left) / 2;
			if (A[mid] < A[i] - A[mid]) {
				left = mid;
			}
			else {
				right = mid;
			}
		}
		int B = A[left];
		int C = A[i] - A[left];
		int B2 = A[right];
		int C2 = A[i] - A[right];
		int mi1 = min(B, C);
		int ma1 = max(B, C);
		if (abs(B2 - C2) < abs(B - C)) {
			mi1 = min(B2, C2);
			ma1 = max(B2, C2);
		}

		left = i;
		right = N;
		while (1 < right - left) {
			int mid = (right + left) / 2;
			if (A[mid] - A[i] < A[N] - A[mid]) {
				left = mid;
			}
			else {
				right = mid;
			}
		}
		int D = A[left] - A[i];
		int E = A[N] - A[left];
		int D2 = A[right] - A[i];
		int E2 = A[N] - A[right];
		int mi2 = min(D, E);
		int ma2 = max(D, E);
		if (abs(D2 - E2) < abs(D - E)) {
			mi2 = min(D2, E2);
			ma2 = max(D2, E2);
		}
		ans = min(ans, max(ma1, ma2) - min(mi1, mi2));
	}

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



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

int main() {
  int N, ma, mi;
  cin >> N;
  vector<int> A(N);
  
  for(int i=0; i<N; i++){
    cin >> A.at(i);
  }
  
  sort(A.begin(), A.end());
  
  cout << A.at(N-1) - A.at(0) << endl;
  
  return 0;
}

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

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

int A[SIZE];
int B[SIZE];

int main()
{
	int n;
	scanf("%d",&n);
	vector <int> vx;
	for(int i=0;i<n;i++)
	{
		scanf("%d",&A[i]);
		vx.push_back(A[i]);
	}
	sort(A,A+n);
	sort(vx.begin(),vx.end());
	vx.erase(unique(vx.begin(),vx.end()),vx.end());
	if(vx.size()>3)
	{
		puts("No");
		return 0;
	}
	for(int i=0;i<vx.size();i++)
	{
		for(int j=0;j<vx.size();j++)
		{
			int a=vx[i],b=vx[j];
			B[0]=a,B[1]=b;
			for(int k=2;k<n;k++) B[k]=B[k-2]^B[k-1];
			bool up=true;
			for(int k=0;k<n;k++)
			{
				int S=B[k];
				int T=B[(k-1+n)%n]^B[(k+1)%n];
				if(S!=T) up=false;
			}
			if(up)
			{
				sort(B,B+n);
				for(int k=0;k<n;k++) if(B[k]!=A[k]) up=false;
				if(up)
				{
					puts("Yes");
					return 0;
				}
			}
		}
	}
	puts("No");
	return 0;
}


Measured memory_bytes: 1528
A = gets.to_i
B = gets.to_i
C = gets.to_i
X = gets.to_i

result = 0

([X / 500, A].min + 1).times do |a|
    remain = X - a * 500
    ([remain / 100, B].min + 1).times do |b|
        result += 1 if (remain - b * 100) / 50 <= C
    end
end

print result

Measured memory_bytes: 1788
#include <bits/stdc++.h>
using namespace std;
const int N = 100000;
int x[N], y[N], d[N];

int main(){
  ios_base::sync_with_stdio();
  cin.tie(); cout.tie();
  int h, w, D;
  cin >> h >> w >> D;
  for(int i=0;i<h;i++){
	for(int j=0;j<w;j++){
	  int t;
      cin >> t;
      x[t] = i;
      y[t] = j;
    }
  }
  for(int i = D+1; i<=h*w; i++){
    d[i] = d[i-D] + abs(x[i]-x[i-D]) + abs(y[i]-y[i-D]);
  }
  int q;
  cin >> q;
  while(q--){
    int l, r;
    cin >> l >> r;
    cout << d[r]-d[l] << '\n';
  }return 0;
}

Measured memory_bytes: 4660
#include <bits/stdc++.h>
using namespace std;
#define rep(i,N) for(int i=0,i##_max=(N);i<i##_max;++i)
#define repp(i,l,r) for(int i=(l),i##_max=(r);i<i##_max;++i)
#define per(i,N) for(int i=(N)-1;i>=0;--i)
#define perr(i,l,r) for(int i=r-1,i##_min(l);i>=i##_min;--i)
#define all(arr) (arr).begin(), (arr).end()
#define SP << " " <<
#define SPF << " "
#define SPEEDUP cin.tie(0);ios::sync_with_stdio(false);
#define MAX_I INT_MAX //1e9
#define MIN_I INT_MIN //-1e9
#define MAX_UI UINT_MAX //1e9
#define MAX_LL LLONG_MAX //1e18
#define MIN_LL LLONG_MIN //-1e18
#define MAX_ULL ULLONG_MAX //1e19
  typedef long long ll;
  typedef pair<int,int> PII;
  typedef pair<char,char> PCC;
  typedef pair<ll,ll> PLL;
  typedef pair<char,int> PCI;
  typedef pair<int,char> PIC;
  typedef pair<ll,int> PLI;
  typedef pair<int,ll> PIL; 
  typedef pair<ll,char> PLC; 
  typedef pair<char,ll> PCL; 

inline void YesNo(bool b){ cout << (b?"Yes" : "No") << endl;}
inline void YESNO(bool b){ cout << (b?"YES" : "NO") << endl;}
inline void Yay(bool b){ cout << (b?"Yay!" : ":(") << endl;}

int main(void){
  SPEEDUP
  cout << setprecision(15);
  int N;cin >> N;
  int digit = 0;
  while(N!=0){
    digit += N%10;
    N/=10;
  }
  if(digit == 1) cout << 10;
  else cout << digit << endl;
  return 0;
}


Measured memory_bytes: 256