akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <algorithm>
#include <cstdlib>
#include <climits>
using namespace std;

enum stats_detail {
  WEIGHT = 0,
  PRICE  = 1,
  UNIT   = 2,
  RATE   = 3
};

enum shop {
  A = 0,
  B = 1,
  C = 2
};

const static int shop_stats[ 3 ][ 4 ] = {
  { 200, 380, 5, 20 },
  { 300, 550, 4, 15 },
  { 500, 850, 3, 12 }
};

const static int W_MAX = 5000;
const static int W_UNIT = 100;
const static int OPT_ARRAY_SIZE = W_MAX / W_UNIT + 1;

int get_price( shop id, int num ) {
  
  int discount_num = num - num % shop_stats[ id ][ UNIT ];
  return (
      shop_stats[ id ][ PRICE ] *
      discount_num *
      ( 100 - shop_stats[ id ][ RATE ] ) / 100  +
      shop_stats[ id ][ PRICE ] * ( num - discount_num )
 );
 
  return 0;
}
int main() {
  int opt[ OPT_ARRAY_SIZE ];
  fill( opt, opt + OPT_ARRAY_SIZE, INT_MAX );
  for( int i = 0; i <= W_MAX / shop_stats[ A ][ WEIGHT ]; i++ ) {
    int apr = get_price( A, i );
    int aw  = i * shop_stats[ A ][ WEIGHT ];
    for( int j = 0; j <= W_MAX / shop_stats[ B ][ WEIGHT ]; j++ ) {
      int bpr = get_price( B, j );
      int bw  = j * shop_stats[ B ][ WEIGHT ];
      for( int k = 0; k <= W_MAX / shop_stats[ C ][ WEIGHT ]; k++ ) {
        int cpr = get_price( C, k );
        int cw  = k * shop_stats[ C ][ WEIGHT ];
        int sumw = aw + bw + cw;
        if( sumw > W_MAX ) { continue; }
        opt[ sumw / W_UNIT ] = min( opt[ sumw / W_UNIT ], apr + bpr + cpr );
      }
    }
  } 
  while( 1 ) {
    int w;
    cin >> w;
    if( !w ) { break; }
    cout << opt[ w / W_UNIT ] << endl;
  }
  return EXIT_SUCCESS;
}

Measured memory_bytes: 1160
#include <cstdio>
#include <iostream>
#include <string>
#include <vector>
#include <map>

typedef long long ll;

int main(int argc, char* argv[])
{
  int n;
  int d, x;
  int a[100];
  int ans = 0;

  std::cin >> n;
  std::cin >> d;
  std::cin >> x;
  for (int i = 0; i < n; i++) {
    std::cin >> a[i];
  }

  ans = x;
  for (int i = 0; i < n; i++) {
    ans += 1 + (int)((d-1) / a[i]);
  }  

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


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

int main() {
	string X; cin >> X;
	int sa=0, ans=0;
	for(int i=0; i<X.size(); ++i){
	    if(X[i]=='S') --sa;
	    else ++sa;
	    ans=max(ans, sa);
	}
	cout << ans * 2 << endl;
	return 0;
}


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

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

const int NMAX = 100000;
const long long DMMAX = 200000 * 10000;
const long long UNKNOWN = DMMAX * 2;

vector<ll> pos;
vector<vector<P>> conds;
int N, M;

ll minx = 0;
ll maxx = 0;

int dfs(int i) {
    //cout << "on node " << i << endl;
    ll x = pos[i];
    for (P p : conds[i]) {
        int j = p.first;
        int d = p.second;
        //cout << "cond " << i << " -> " << j << " d = " << d << endl;

        if (pos[j] == UNKNOWN) {
            pos[j] = x + d;

            if (dfs(j) == -1) {
                return -1;
            }
        } else if (pos[j] != x + d){
            return -1;
        }
    }
    return 0;
}

int main(){
    cin >> N >> M;
    for (int i = 0; i < N; ++i) {
        pos.push_back(UNKNOWN);
        conds.push_back(vector<P>());
    }

    for (int i = 0; i < M; ++i) {
        int l, r, d;
        cin >> l >> r >> d;
        l--;
        r--;
        if (l > r) {
            int tmp = l; l = r; r = tmp;
            d *= -1;
        }

        conds[l].push_back(make_pair(r, d));
        conds[r].push_back(make_pair(l, -d));
    }
    bool ok = true;
    for (int i = 0; i < N; ++i) {
        if (pos[i] == UNKNOWN) {
            pos[i] = 0;

            if (dfs(i) == -1) {
                ok = false;
            }
        }
        if (!ok) break;
    }

    // for (ll pi : pos) {
        // cout << pi << " ";
    // }
    // cout << endl;
    cout << (ok ? "Yes" : "No") << endl;
}

Measured memory_bytes: 12328
A,B,H,M=map(int,input().split())
import math
H_k=H*30+M/60*30
M_k=M*6
if(M_k==0):
    M_k=360
if(H_k==0):
    H_k=360

if(H_k-M_k<=180 ):
    x=H_k-M_k

else:
    x=M_k-H_k
x=abs(x)

if(x==90):

    print((A**2+B**2)**0.5)
elif(x==180):
    print(A+B)
else:

    z=((A*(math.sin(math.radians(x))))**2+(B-(A*math.cos(math.radians(x))))**2)**0.5
    #zz=(A**2+B**2-2*B*A*math.cos(math.radians(x)))**0.5
    print(z)


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

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

const int mod=1e9+7;
const int mx=1077;

int main() {
	cin.tie(0); cout.tie(0); ios_base::sync_with_stdio(0);
	vector<bool> flag(mx,true);
	flag[0]=flag[1]=false;
	for (int i=2; i*i<mx; i++)
		if(flag[i])
			for (int j=i; j*i<mx; j++)
				flag[i*j]=false;
	vector<int> pr;
	for (int i=2; i<mx; i++)
		if(flag[i])
			pr.push_back(i);

	map<int,int> ct;
	int n; cin>>n;
	for (int x=2; x<=n; x++) {
		int y=x;
		for (auto p : pr) {
			if(p>y||y==1) break;
			if(y%p==0) {
				while(1) {
					if(y%p) break;
					ct[p]++, y/=p;
				}
			}
		}
	}

	ll ret=1;
	for (auto it : ct)
		ret=(ret*(it.second+1))%mod;
	cout << ret << endl;
	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <algorithm>
#include <string>
#include <cmath>
#include <cstdio>
#include <iomanip>
#include <fstream>
#include <cassert>
#include <cstring>
#include <numeric>
#include <ctime>
#include <complex>
#include <bitset>
#include <random>
#include <climits>
#include <stack>

using namespace std;

typedef long long ll;
typedef long double ld;

#define int ll
#define double ld
#define loop(i, n) for(int i = 0; i < (int)n; ++i)
#define loop1(i, n) for(int i = 1; i <= (int)n; ++i)
#define F first
#define S second
#define pb push_back
#define pi pair <int, int>
#define all(x) begin(x), end(x)
#define ti tuple <int, int, int>
#define Point Vect
#define no {cout << -1; return;}
#define yes {cout << "Yes"; return;}
#define mkp make_pair
#define mkt make_tuple
#define cerr if(0) cerr

const double PI = 3.14159265359, eps = 1e-8;

double len(double base, double v, double angle) {
    double trngl = base * base / (tan(angle) * 2);
    if (trngl > v)
        return sqrt(2 * v / tan(angle));
    return base / tan(angle) + (v - trngl) / base;
}

void solve() {
    double a, b, x;
    cin >> a >> b >> x;
    x /= a;
    double l = 0, r = PI / 2;
    while (r - l > eps) {
        double m = (l + r) / 2;
        if (len(a, x, m) > b)
            l = m;
        else
            r = m;
    }
    cout << fixed << setprecision(7) << 90 - l / PI * 180;
}

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


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

cs_view = input().rstrip('\r\n')
list_v = list(cs_view)

stack1 = []
all_sum = 0
sum_stack = []
for i, elem in enumerate(list_v):
    if elem == '\\':
        stack1.append(i)
    elif len(stack1) > 0 and elem == '/':
        j = stack1.pop()
        all_sum += i - j
        a = i - j
        while len(sum_stack) > 0 and sum_stack[-1][0] > j:
            a += sum_stack.pop()[1]
        sum_stack.append([j, a])

print(all_sum)
esum = []
for a in sum_stack:
    esum.append(a[1])
esum.insert(0, len(esum))
maped_esum = map(str, esum)
str_esum = ' '.join(maped_esum)
print(str_esum)



Measured memory_bytes: 6360
n = int(input())
B = list(map(int, input().split()))
A = []

for i in range(n, 0, -1):
    for j in range(i, 0, -1):
        if B[j-1] == j:
            A.append(j)
            del B[j-1]
            break
    else:
        print(-1)
        break
else:
    A = A[::-1]
    for i in range(n):
        print(A[i])

Measured memory_bytes: 3188
A,B,K=map(int,input().split())
if K%2==0:
	K=K/2
	for i in range(int(K)):
		if A%2==0:
			A=A/2
			B=B+A
			if B%2==0:
				B= B/2
				A=A+B
				
			else:
				B=(B-1)/2
				A=A+B
				
		else:
			A= (A-1)/2
			B=A+B
			if B%2==0:
				B= B/2
				A=A+B
				
			else:
				B=(B-1)/2
				A=A+B
				
else:
	K=(K-1)/2
	for i in range(int(K)):
		if A%2==0:
			A=A/2
			B=B+A
			if B%2==0:
				B= B/2
				A=A+B
				
			else:
				B=(B-1)/2
				A=A+B
				
		else:
			A= (A-1)/2
			B=A+B
			if B%2==0:
				B= B/2
				A=A+B
				
			else:
				B=(B-1)/2
				A=A+B
	
	if A%2==0:
		A=A/2
		B=B+A
	else:
		A=(A-1)/2
		B=A+B
	
print(str(int(A))+" "+str(int(B)))

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

typedef struct wordtree{
	struct wordtree *next;
	struct wordtree *prev;
	char *txt;
	int t_num;
	int t_size;
}wordtree;

wordtree *initTree(char *msg,int num,int size){
	wordtree *x;
	x=(wordtree *)malloc(sizeof(wordtree));
	x->prev=NULL;
	x->next=NULL;
	x->txt=(char *)malloc(sizeof(char)*32);
	strcpy(x->txt,msg);
	x->t_num=num;
	x->t_size=size;
	return x;
}
int cnt=0;often=0;length=0;
char *mod2,*mod3;
void graphtree(wordtree *tree,int mode){
	switch(mode){
		case 1:if(tree->txt!="")printf("msg=%s,num=%d,size=%d,depth=%d\n",tree->txt,tree->t_num,tree->t_size,cnt);
		case 2:if(tree->t_num>=often){often=tree->t_num;mod2=tree->txt;}
		case 3:if(tree->t_size>=length){length=tree->t_size;mod3=tree->txt;}
	}
	if(tree->next!=NULL){
		cnt++;
		graphtree(tree->next,mode);
	}
	if(tree->prev!=NULL){
		cnt--;
		graphtree(tree->prev,mode);
	}
	return ;
}
		
void addToTree(char *msg,wordtree *tree){
	wordtree *x;
	x=tree;
	if(strcmp(msg, x->txt)>0){
		if(x->next==NULL){
			x->next=initTree(msg,1,strlen(msg));
			return;
		}else{
			addToTree(msg,x->next);
		}
	}else{
		if(x->prev==NULL){
			x->prev=initTree(msg,1,strlen(msg));
			return;
		}else{
			addToTree(msg,x->prev);
		}
	}
}

wordtree *searchTree(char *msg,wordtree *tree){
	wordtree *x;
	x=tree;
	if(strcmp(msg,x->txt)>0){
		if(x->next==NULL)return NULL;
		else searchTree(msg,x->next);
	}else if(strcmp(msg,x->txt)<0){
		if(x->prev==NULL)return NULL;
		else searchTree(msg,x->prev);
	}else{
		return x;
	}
}

int main(){
	wordtree *r,*p;
	int i,j;
	char txt[1024],s[32];
	memset(s,'\0',sizeof(s));
	r=initTree("nn",0,0);//root
	while(fgets(txt,sizeof(txt),stdin)!=NULL){
		for(i=0,j=0;i<strlen(txt);i++){
			if((65<=txt[i]&&txt[i]<=90)||(97<=txt[i]&&txt[i]<=122)){
				if((65<=txt[i]&&txt[i]<=90))txt[i]+=32;
				s[j]=txt[i]; j++;
			}else{
				j=0;
				p=searchTree(s,r);
				if(p==NULL)	addToTree(s,r);
				else p->t_num++;
				memset(s,'\0',sizeof(s));
			}
		}
		//graphtree(r,1);
		graphtree(r,2);
		graphtree(r,3);
		printf("%s %s\n",mod2,mod3);
		return 0;	
	}
}

Measured memory_bytes: 568
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.NoSuchElementException;

public class Main{
	static int MAX = (int)1e5 + 10;
	int N;
	int[] imos;
	public void solve() {
		N = nextInt();
		imos = new int[MAX];
		for(int i = 0;i < N;i++){
			int a = nextInt();
			int b = nextInt();
			
			imos[a]++;
			imos[b + 1]--;
		}
		
		for(int i = 0;i < MAX - 1;i++){
			imos[i + 1] += imos[i];
		}
		
		int ans = 0;
		for(int i = 0;i < MAX;i++){
			if(imos[i] + 1>= i){
				ans = i - 1;
			}
		}
		out.println(ans);
	}

	public static void main(String[] args) {
		out.flush();
		new Main().solve();
		out.close();
	}

	/* Input */
	private static final InputStream in = System.in;
	private static final PrintWriter out = new PrintWriter(System.out);
	private final byte[] buffer = new byte[2048];
	private int p = 0;
	private int buflen = 0;

	private boolean hasNextByte() {
		if (p < buflen)
			return true;
		p = 0;
		try {
			buflen = in.read(buffer);
		} catch (IOException e) {
			e.printStackTrace();
		}
		if (buflen <= 0)
			return false;
		return true;
	}

	public boolean hasNext() {
		while (hasNextByte() && !isPrint(buffer[p])) {
			p++;
		}
		return hasNextByte();
	}

	private boolean isPrint(int ch) {
		if (ch >= '!' && ch <= '~')
			return true;
		return false;
	}

	private int nextByte() {
		if (!hasNextByte())
			return -1;
		return buffer[p++];
	}

	public String next() {
		if (!hasNext())
			throw new NoSuchElementException();
		StringBuilder sb = new StringBuilder();
		int b = -1;
		while (isPrint((b = nextByte()))) {
			sb.appendCodePoint(b);
		}
		return sb.toString();
	}

	public int nextInt() {
		return Integer.parseInt(next());
	}

	public long nextLong() {
		return Long.parseLong(next());
	}

	public double nextDouble() {
		return Double.parseDouble(next());
	}
}

Measured memory_bytes: 53144
/*
　　　  ∧＿∧　やあ
　　 （´・ω・｀)　　　　　/　　　　　ようこそ、バーボンハウスへ。
　　 ／∇y:::::＼　　　 [￣]　　　　　このテキーラはサービスだから、まず飲んで落ち着いて欲しい。
　　 |:⊃:|:::::|　　　|──|
￣￣￣￣￣￣￣￣￣￣￣￣￣￣￣￣￣|　うん、「また」なんだ。済まない。
￣￣￣￣￣￣￣￣￣￣￣￣￣￣￣|￣　  仏の顔もって言うしね、謝って許してもらおうとも思っていない。
￣￣￣￣￣￣￣￣￣￣￣￣￣￣／|
　　　　∇　∇　∇　∇　　　／.／|　　　でも、この提出を見たとき、君は、きっと言葉では言い表せない
　　　　┴　┴　┴　┴　／ ／　  |　　　「ときめき」みたいなものを感じてくれたと思う。
￣￣￣￣￣￣￣￣￣￣|／　　  |　　　殺伐としたコンテストの中で、そういう気持ちを忘れないで欲しい
￣￣￣￣￣￣￣￣￣￣　　　　 |　　　そう思って、この提出を投げたんだ。
　　　(⊆⊇)　(⊆⊇)　(⊆⊇)　　|
　    ||　　 ||　　||　　|　　　 じゃあ、判定を聞こうか。
　　.／|＼　／|＼ ／|＼
*/

#include <iostream>
#include <cstdlib>
#include <algorithm>
#include <array>
#include <bitset>
#include <climits>
#include <cmath>
#include <cstdio>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <string>
#include <vector>
using namespace std;
#define fst first
#define snd second
#define ALL(obj) (obj).begin(),(obj).end()
#define debug(x) cerr << #x << " -> " << x << " (line:" << __LINE__ << ")" << '\n';
#define debugpair(x, y) cerr << "(" << #x << ", " << #y << ") -> (" << x << ", " << y << ") (line:" << __LINE__ << ")" << '\n';
typedef long long lint;
typedef priority_queue<int> p_que;
typedef priority_queue<int, vector<int>, greater<int>()> p_que_rev;
// const int INF = INT_MAX;
const lint LINF = LLONG_MAX;
// const lint MOD = 1000000000 + 7;
const double EPS = 1e-9;
const double PI = acos(-1);
const int di[]{0, -1, 0, 1, -1, -1, 1, 1};
const int dj[]{1, 0, -1, 0, 1, -1, -1, 1};


int main()
{
    cin.tie(0);
    ios_base::sync_with_stdio(false);
    int a, b, c;
    cin >> a >> b >> c;
    if((a == 5 && b == 5 && c == 7) || (a == 5 && b == 7 && c == 5 ) || (a == 7 && b == 5 && c == 5)){
        cout << "YES" << endl;
    }
    else {
        cout << "NO" << endl;
    }
    return 0;
}

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

using namespace std;

int main(){

  int n;
  int max,min;
  int a;
  int sum;
  while(true){
    cin >>n;
    if(n==0)break;
    sum = 0;
    max = 0;
    min = 1001;
    for(int i=0;i<n;i++){
      cin >>a;

      if(a>max)max = a;
      if(a<min)min = a;
      sum+=a;
    }
    sum-=max+min;
    sum/=(n-2);
    cout <<sum<<endl;
  }


  return 0;
}

Measured memory_bytes: 0
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map.Entry;
import java.util.Scanner;

class Main {

	@SuppressWarnings("resource")
	public static void main(final String args[]) {
		
		Scanner scanner = new Scanner(System.in);
		int n = scanner.nextInt();
		int a = scanner.nextInt();
		List<Integer> x = new ArrayList<>();

		for (int i = 0; i < n; i++) {
			int tmp = scanner.nextInt();
			x.add(tmp - a);
		}
		
		HashMap<Integer,Long> mapa=new HashMap<Integer,Long>();
		HashMap<Integer,Long> mapb=new HashMap<Integer,Long>();
		
		mapa.put(0,1L);
		mapb.put(0, 1L);

		
		for (Integer num : x) {
			for (Entry<Integer, Long> entry : mapb.entrySet()) {
				int sum = entry.getKey() + num;
				long way = entry.getValue();
				if(mapa.containsKey(sum)){
					mapa.put(sum, mapa.get(sum) + way);
				}else{
					mapa.put(sum, way);
				}
			}
			mapb.clear();
			mapb.putAll(mapa);
		}
		System.out.println(mapb.get(0)-1);
	}
}


Measured memory_bytes: 24772
#include<bits/stdc++.h>
using namespace std;
const int MAX = 1e9+5;
signed main(){
  cin.tie(nullptr);
  ios::sync_with_stdio(false);
  string s,t,sub;
  bool b,flag=false;
  cin>>s>>t;
  int n=t.size(),m=s.size();
  if(n>m){cout<<"UNRESTORABLE";return 0;}
  else if(s=="?"){cout<<t;return 0;}
  for(int i=0;i<m-m+1;i++){
    if(s.substr(i,n)==t){flag=true;break;}
  }
  if(!flag){
      for(int i=m-1;i-n+1>=0;i--){
      sub=s.substr(i-n+1,n);
      if(s[i]==t[n-1]||s[i]=='?'){
        for(int j=0;j<n;j++){
          b=true;
          if(sub[j]==t[j]||sub[j]=='?'){continue;}
          else{b=false;break;}
        }
        if(b){
          for(int k=i-n+1;k<i+1;k++){s[k]=t[k-i+n-1];}
          i-=n;
          break;
          }
      }
    }
  }
  for(int i=0;i<m;i++){
    if(s[i]=='?'){s[i]='a';}
  }
  cout<<(b||flag?s:"UNRESTORABLE");
}

Measured memory_bytes: 256
n = int(input())
a = list(map(int, input().split()))

m1 = int(sum([a[i] * ((-1)**i) for i in range(n)]) / 2)

result = str(m1)

m = [None] * n
m[0] = m1
for i in range(1, n):
  m[i] = a[i-1] - m[i-1]

print(' '.join([str(x*2) for x in m]))

Measured memory_bytes: 78052
import sys, heapq
def LI(): return list(map(int, sys.stdin.readline().split()))
def LS(): return list(sys.stdin.readline())

N = int(input())
H = list(map(int, input().split()))

res = 0
cnt = 0
for i in range(N - 1):
    if H[i] < H[i + 1]:
        res = max(res, cnt)
        cnt = -1
    cnt += 1

res = max(res, cnt)
print(res)

Measured memory_bytes: 14152
#include <vector>
#include <map>
#include <set>
#include <stack>
#include <queue>
#include <deque>
#include <algorithm>
#include <utility>
#include <functional>
#include <sstream>
#include <iostream>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>
#include <climits>
using namespace std;
inline int toInt(string s) { int v; istringstream sin(s); sin >> v; return v;}
template<class T> inline string toString(T x) { ostringstream sout; sout << x; return sout.str();}
typedef vector<int> vi;
typedef vector<vi>  vvi;
typedef vector<string> vs;
typedef pair<int, int> pii;
typedef long long ll;
#define ALL(a) (a).begin(),(a).end()
#define RALL(a) (a).rbegin(),(a).rend()
#define EACH(t,i,c) for(t::iretator i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define FOR(i,a,b) for(int i=(a);i<=(b);++i)
#define REP(i,n) FOR(i,0,n-1)
const double EPS = 1e-10;
const double PI = acos(-1.0);

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

	int count = 0;
	REP(i, n) {
		string tmp;
		cin >> tmp;
		tmp += tmp;

		if(tmp.find(s) != string::npos) {
			count++;
		}
	}
	
	cout << count << endl;
	return 0;
}

Measured memory_bytes: 1212
using System;
using System.Collections.Generic;
using System.Linq;

namespace CSharpSample01
{
    
    class Program
    {
        
        static void Main(string[] args)
        {
            int N = int.Parse(Console.ReadLine());
            int[] A = Console.ReadLine().Split(' ').Select(x => int.Parse(x)).ToArray();

            int cnt_minus = 0;
            long sum = 0;
            long min = (long)Math.Pow(10, 9);

            for(int i = 0; i < N; i++)
            {
                sum += Math.Abs(A[i]);
                if(min > Math.Abs(A[i]))
                {
                    min = Math.Abs(A[i]);
                }
                if(A[i] < 0)
                {
                    cnt_minus++;
                }
            }

            
            if(cnt_minus % 2 == 0)
            {
                Console.WriteLine(sum);
            }
            else
            {
                Console.WriteLine(sum - min * 2);
            }
            
        }
    }
}


Measured memory_bytes: 31964
import java.util.Scanner;

public class Main{
	
	private static long[] numbers;
	public static long ans=0;
		
	
	
	public static void main(String[] arg) {
		Scanner scanner = new Scanner(System.in);
		char[] inputString = scanner.next().toCharArray();
		numbers = new long[inputString.length];
		
		for (int i = 0; i < inputString.length; i++) {
			String string = String.valueOf(inputString[i]);
			numbers[i] = Integer.parseInt(string);
		}
		
		long ans = 0;
		
		for (long i = 0; i < Math.pow(2, numbers.length-1); i++) {
			long add = numbers[0];
			for (int j = 0; j < numbers.length-1; j++) {
				if ((1&i>>j) == 1) {
					ans += add;
					add = numbers[j+1];
				}else {
					add = add*10 + numbers[j+1];
				}				
			}
			ans += add;
		}
		System.out.println(ans);
	}
}

Measured memory_bytes: 21716
fun main(args:Array<String>){
  var (a, b, k) = readLine()!!.split(" ").map {it.toInt()}
  println(fmt(solve(a, b, 1, k)))
}

fun fmt(n: Pair<Int, Int>) : String {
  var (a, b) = n
  return Integer.toString(a) + " " + Integer.toString(b)
}

fun solve(a:Int, b:Int, n:Int, k:Int) : Pair<Int, Int> {
  if (n > k) {
    return Pair(a, b)
  }
  var (a1, b1) = if (n % 2 == 1) Pair(a / 2, a / 2 + b) else Pair(b / 2 + a, b / 2)
  return solve(a1, b1, n + 1, k)
}


Measured memory_bytes: 36232
#include <bits/stdc++.h>
using namespace std;
const int MAXN = 2e5 + 10;

int main()
{
    int n;
    cin >> n;
    vector<int> p(n);
    for (int i = 0; i < n; ++i)
    {
        cin >> p[i];
    }

    long long int result = 0;
    int min = p[0];
    for (int i = 0; i < n; ++i)
    {
        if (p[i] <= min)
        {
            min = p[i];
            result++;
        }
    }
    cout << result << endl;
}

Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
int main(){
  cin.tie(NULL);
  ios::sync_with_stdio(false);
  int x,a,b;
  cin>>x>>a>>b;
  if(abs(x-a)<abs(x-b)){
    cout<<"A"<<'\n';
  }
  else{
    cout<<"B"<<'\n';
  }
  return 0;
}

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

namespace kp
{
    public class Program
    {
        static void Main(string[] args)
        {
            int N = Int32.Parse(Console.ReadLine());
            int[] d = Console.ReadLine().Split().Select(p => int.Parse(p)).ToArray();
            List<int> difficult = new List<int>(d);
            difficult.Sort();
            int k = difficult[difficult.Count / 2]; // ARC用で一番簡単
            int abc = difficult[difficult.Count / 2 -1]; // ABC用で一番難しい

            if (k == abc)
                Console.WriteLine("0");
            else
            {
                // abcより大きくて、kまでの整数を選べる
                Console.WriteLine((k - abc) + "");
            }
            
        }
    }
}


Measured memory_bytes: 20576
#include<iostream>
#include<cstdio>
#include<algorithm>
using namespace std;
int main()
{
	int N, K, a[100005], cnt = 0;
	cin >> N >> K;
	for (int i = 0; i < N; i++)
	{
		cin >> a[i];
		if (a[i] >= K)
			cnt++;
	}
	cout << cnt << endl;
	return 0;
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
#include <boost/range/algorithm.hpp>
#include <boost/range/numeric.hpp>
#include <boost/range/irange.hpp>
#include <boost/range/adaptor/indexed.hpp>
#define FOR(i,k,n)  for(int i = (k);i < (n);++i)
#define REP(i,n)    FOR(i,0,n)
#define ALL(x) begin(x),end(x)

using namespace std;
using namespace boost::adaptors;
using namespace std::string_literals;
using ll = int64_t;
using vecint = vector<int>;
using vecll = vector<ll>;
using boost::irange;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  int n;
  cin>>n;
  vector<double> t(n);
  for(auto&&e:t)cin>>e;
  vector<double> v(n);
  for(auto&&e:v)cin>>e;
  double ans = 0.;
  REP(i,n) {
    double vmax = 0;
    REP(j,i) {
      vmax += t[j];
      vmax = min(vmax, v[j]);
    }
    vmax = min(vmax, v[i]);
    double vmax2 = 0;
    for(int j = n-1; j > i; --j) {
      vmax2 += t[j];
      vmax2 = min(vmax2, v[j]);
    }
    vmax2 = min(vmax2, v[i]);
    vmax = min(vmax, vmax2 + t[i]);
    vmax2 = min(vmax2, vmax + t[i]);
    double t1 = 0.5 * (t[i] + vmax2 - vmax);
    double t2 = 0.5 * (t[i] + vmax - vmax2);
    t1 = min(t1, v[i] - vmax);
    t2 = min(t2, v[i] - vmax2);
    ans += vmax * t1 + 0.5 * t1 * t1;
    ans += vmax2 * t2 + 0.5 * t2 * t2;
    ans += v[i] * (t[i] - t1 - t2);
  }
  cout<<fixed<<setprecision(10)<<ans<<endl;
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define repe(i, n) for (int i = 0; i <= (n); ++i)
#define all(x) (x).begin(),(x).end()
using namespace std;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
typedef long long ll;
const int INF = 1e9;
const ll mod = 1000000007;
int gcd(int a,int b){return b?gcd(b,a%b):a;}
int lcm(int a,int b){return a*b / gcd(a,b);}

int main() {
    string s;
    cin >> s;
    reverse(s.begin(), s.end());
    s.replace(0, 8, "");
    reverse(s.begin(), s.end());

    cout << s << "\n";
}


Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main(void)
{
	int x1,x2;
	int y1,y2;
	int x, y;
	cin >> x1 >> y1 >> x2 >> y2;
	x = x2 - x1;
	y = y2 - y1;
	cout << x2-y <<" "<<y2+x<<" "<<x1-y<<" "<<y1+x;
}

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

using namespace std;

int main()
{
    int a,b,sum=0;
    cin>>a>>b;
    int count[1010];

    for(int i=0;i<a;i++){
        cin>>count[i];
    }

    sort(count,count+a);

    for(int i=0;i<b;i++){
        sum=sum+count[i];
    }

    cout<<sum<<endl;



    return 0;
}


Measured memory_bytes: 3640
function main( input ) {
    const args = input.split('\n');
    const N = parseInt(args[0], 10);
    const cards = args[1].split(' ').map( n => parseInt(n, 10) );
    let aSum = 0, bSum = 0;
    cards.sort( (a, b) => a < b ? 1 : -1 ).forEach( (v, i) => {
        (i%2 === 0) ? aSum += v : bSum += v;
    })
    console.log( aSum - bSum );
}

main( require('fs').readFileSync('/dev/stdin', 'utf8') );

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

int main(){
    double n;
    cin >> n;
    int res = 0;
    rep(i,n){
        if(i % 2 == 1) res++;
    }
    cout << fixed << setprecision(6) << res/n << endl;
}


Measured memory_bytes: 256
#include<stdio.h>
#include<string.h>
int main(void)
{
	int i,k,cnt;
	char n[100],a[100];
	scanf("%s",n);
	k=strlen(n);
	cnt=0;
	for(i=0;i<k;i++){
		if(n[i]!='B'){
			a[cnt]=n[i];
			cnt++;
		}	
		else if(cnt>0){
			cnt--;
		}
	}
	a[cnt]='\0';
	printf("%s\n",a);
	return 0;
}

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

int main(void) {
    int N, K;
    cin >> N >> K;
    if (N < K) {
        printf("1\n");
        return 0;
    }

    long long int cnt = 0;
    long long int start = 0;
    long long int end = 0;

    for (int i = 0; i < N+1; i++) {
        start += i;
        end += (N - i);
        if (i >= (K - 1)) {
            cnt += (end - start + 1);
        }
    }

    printf("%lld\n", cnt % 1000000007);

    return 0;
}

Measured memory_bytes: 3764
#![allow(non_snake_case, unused_imports)]

// Input
macro_rules! input { (source = $s:expr, $($r:tt)*) => { let mut iter = $s.split_whitespace(); let mut next = || { iter.next().unwrap() }; input_inner!{next, $($r)*} }; ($($r:tt)*) => { let stdin = std::io::stdin(); let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock())); let mut next = move || -> String{ bytes.by_ref().map(|r|r.unwrap() as char).skip_while(|c|c.is_whitespace()).take_while(|c|!c.is_whitespace()).collect() }; input_inner!{next, $($r)*} }; }
macro_rules! input_inner { ($next:expr) => {}; ($next:expr, ) => {}; ($next:expr, $var:ident : $t:tt $($r:tt)*) => { let $var = read_value!($next, $t); input_inner!{$next $($r)*} };}
macro_rules! read_value { ($next:expr, ( $($t:tt),* )) => { ( $(read_value!($next, $t)),* ) }; ($next:expr, [ $t:tt ; $len:expr ]) => { (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>() }; ($next:expr, chars) => { read_value!($next, String).chars().collect::<Vec<char>>() }; ($next:expr, bytes) => { read_value!($next, String).into_bytes() }; ($next:expr, usize1) => { read_value!($next, usize) - 1 }; ($next:expr, $t:ty) => { $next().parse::<$t>().expect("Parse error") }; }

// Module
use std::cmp::{min,max};
use std::collections::{HashSet,HashMap,BTreeMap,VecDeque};

// Functions

// Main
fn main(){
    input!{
        N: usize,
        S: [i64; N],
    }
    let mut ans = 0;
    let mut r = vec![0;0];
    for i in 0..N{
        ans += S[i];
        if S[i]%10 != 0{
            r.push(S[i]);
        }
    }
    r.sort();
    if ans%10==0{
        if r.len()>0{
            ans -= r[0];
        }else{
            ans = 0;
        }
    }
    println!("{}", ans);
}

Measured memory_bytes: 4352
import itertools
n = int(input())
p = list(map(int, input().split()))
q = list(map(int, input().split()))
cnt = 1
a = 0
b = 0
for i in itertools.permutations(range(1, n+1)):  # 0, 1, 2
    if tuple(p) == i:
        a = cnt
    if tuple(q) == i:
        b = cnt
    cnt += 1

print(abs(a-b))

Measured memory_bytes: 3064
#include <bits/stdc++.h>
#include <assert.h>
using namespace std;
using i64 = long long;

int main()
{
  i64 a, b;
  cin >> a >> b;
  if (abs(a - b) % 2 == 0)
    cout << (a + b) / 2 << endl;
  else
    cout << "IMPOSSIBLE" << endl;
  return 0;
}


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



typedef unsigned long ul;
typedef unsigned long long ull;
typedef long long ll;
typedef vector<ll> vint;
typedef vector< vector<ll> > vvint;
typedef vector< vector< vector<ll> > > vvvint;
typedef vector<string> vstring;
typedef vector< vector<string> > vvstring;
typedef vector<char> vchar;
typedef vector< vector<char> > vvchar;
typedef vector<long double> vdouble;
typedef vector< vector<long double> > vvdouble;
typedef vector< vector< vector<long double> > > vvvdouble;
typedef pair<ll,ll> pint;
typedef vector<pint> vpint;
typedef vector<bool> vbool;

#define rep(i,n) for(ll i=0;i<n;i++)
#define repf(i,f,n) for(ll i=f;i<n;i++)
#define repr(i,n) for(ll i=n-1;i>=0;i--)
#define mp make_pair
#define mt make_tuple
#define pb push_back
#define pf push_front
#define fi first
#define se second
#define ALL(obj) (obj).begin(), (obj).end()
// #define LLONG_MAX 9223372036854775806
#define vmax(vec) *max_element(vec.begin(), vec.end())
#define vmin(vec) *min_element(vec.begin(), vec.end())
#define vsort(vec) sort(vec.begin(), vec.end())
#define vsortgr(vec) sort(vec.begin(), vec.end(), greater<ll>())
#define MOD 1000000007
// #define MOD 998244353
// #define MOD LLONG_MAX
const double PI=3.14159265358979323846;

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




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




void printv(vint &v){
  for(auto e:v) cout<<e<<" ";
  cout<<endl;
}


int main() {


  cout<<fixed<<setprecision(10);

  string s; cin>>s;

  rep(i,s.size())cout<<"x";
  cout<<endl;


}

//


Measured memory_bytes: 256
c = [tuple(map(int, input().split())) for i in range(3)]
if c[0][0] + c[1][1] + c[2][2] == c[0][1] + c[1][2] + c[2][0] and c[0][0] + c[1][1] + c[2][2] == c[0][2] + c[1][0] + c[2][1]:
    print("Yes")
else:
    print("No")


Measured memory_bytes: 3444
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <limits.h>
#include <string.h>
#define ll long long int




int main()
{

    ll N, M ;
    scanf("%lld %lld",&N,&M);
    ll d = N+1;
    ll array[d];
    memset(array,0,sizeof(array[0])*d);
    array[0]=1;
    array[1]=1;
    ll idx=0;
    ll a[M];
    for (ll i = 0; i<M; i++)
    {
        scanf("%lld",&a[i]);
        if (a[i]==1)
        {
            array[1]=0;
            idx++;
        }
    }


    for (ll i = 2; i<=N; i++)
    {
        if (i==a[idx] && idx<M)
        {
            idx++;
            continue;

        }
        array[i]=array[i-1]+array[i-2];
        array[i]=array[i]%1000000007;
    }


    printf("%lld",array[N]% 1000000007);



    return 0;
}


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

using namespace std;

const int NMax = 100003;

int n;
int a[NMax],b[NMax],c[NMax];

int main(){
    cin >> n;
    for(int i = 1; i <= n; ++i){
        cin >> a[i];
    }
    for(int i = 1; i <= n; ++i){
        cin >> b[i];
    }
    for(int i = 1; i < n; ++i){
        cin >> c[i];
    }
    long long s = 0;
    for(int i = 1; i <= n; ++i){
        s += b[a[i]];
        if(a[i] == a[i - 1] + 1){
            s += c[a[i - 1]];
        }
    }
    cout << s << '\n';
    return 0;
}


Measured memory_bytes: 256
#!usr/bin/env python3
from collections import defaultdict,deque
from heapq import heappush, heappop
from itertools import permutations,product
import sys
import math
import bisect
def LI(): return [int(x) for x in sys.stdin.readline().split()]
def I(): return int(sys.stdin.readline())
def LS():return [list(x) for x in sys.stdin.readline().split()]
def S():
    res = list(sys.stdin.readline())
    if res[-1] == "\n":
        return res[:-1]
    return res
def IR(n):
    return [I() for i in range(n)]
def LIR(n):
    return [LI() for i in range(n)]
def SR(n):
    return [S() for i in range(n)]
def LSR(n):
    return [LS() for i in range(n)]

sys.setrecursionlimit(1000000)
mod = 1000000007

def solve():
    n = I()
    res = [[[0],0]]
    for i in range(n-1):
        res = [[x+[i],max(i,y)] for (x,y) in res for i in range(y+2)]
    for j,k in res:
        for i in j:
            print(chr(i+ord("a")),end = "")
        print()
    return

#Solve
if __name__ == "__main__":
    solve()


Measured memory_bytes: 124424
/**
 * code generated by JHelper
 * More info: https://github.com/AlexeyDmitriev/JHelper
 * @author tatsumack
 */

#include <iostream>
#include <fstream>

#include <bits/stdc++.h>

#define int long long
#define REP(i, n) for (int i = 0, i##_len = (n); i < i##_len; ++i)
#define FOR(i, a, b) for (int i = (a), i##_len = (b); i <= i##_len; ++i)
#define REV(i, a, b) for (int i = (a); i >= (b); --i)
#define CLR(a, b) memset((a), (b), sizeof(a))
#define DUMP(x) cout << #x << " = " << (x) << endl;
#define INF 1001001001001001001ll
#define fcout cout << fixed << setprecision(12)

using namespace std;

typedef pair<int, int> P;

class BGoToJail {
public:
    void solve(std::istream& cin, std::ostream& cout) {
        int N;
        cin >> N;
        vector<pair<int, int>> D(N);
        REP(i, N) {
            int a, b;
            cin >> a >> b;
            D[i] = {a, b};
        }
        int cnt = 0;
        REP(i, N) {
            if (D[i].first == D[i].second) {
                cnt++;
            } else {
                cnt = 0;
            }
            if (cnt == 3) {
                cout << "Yes" << endl;
                return;
            }
        }
        cout << "No" << endl;
    }
};


signed main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);
    std::istream& in(std::cin);
    std::ostream& out(std::cout);

    BGoToJail solver;
    solver.solve(in, out);
    return 0;
}


Measured memory_bytes: 3652
var readline = require('readline');
var rl = readline.createInterface({
  input: process.stdin,
  output: process.stdout,
  terminal: false
});

rl.on('line', function(line){
     if (line ==line.toUpperCase()) {
     console.log('A');
    }
    if (line == line.toLowerCase()){
    console.log('a');
    }
})

Measured memory_bytes: 30108
function solve()
    N=parse(Int,readline())
    D=zeros(Int,N)
    #D[1]=1
    for i in 2:ceil(Int, sqrt(N))
        if D[i]==0
            j=i*2
            while j <= N
                #println(i,j)
                D[j]=i
                j+=i
            end
        end
    end
    ans=0
    for AB = 1:(N-1)
        d=Dict{Int,Int}()
        while true
            _t=D[AB]
            if _t==0
                if haskey(d,AB)
                    d[AB]+=1
                else
                    d[AB]=1
                end
                break
            end

            # _t!=0
            if haskey(d,_t)
                d[_t]+=1
            else
                d[_t]=1
            end
            AB=div(AB,_t)
        end
        #
        #print(d)
        _a=1
        for (key,value) in d
            if key==1
                continue
            end
            _a*=(value+1)
        end
        ans+=_a
    end
    println(ans)

end

solve()

Measured memory_bytes: 214492
#include<iostream>
#include<iomanip>
#include<algorithm>
#include<array>
#include<bitset>
#include<cassert>
#include<cctype>
#include<cmath>
#include<cstdio>
#include<cstring>
#include<functional>
#include<limits>
#include<list>
#include<map>
#include<numeric>
#include<set>
#include<stack>
#include<string>
#include<sstream>
#include<unordered_map>
#include<queue>
#include<regex>
#include<vector>
using namespace std;

//#define int long long
using ll = long long;
using ull = unsigned long long;
using pii = pair<int, int>;

#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(a) (a).begin(),(a).end()
#define dump(o) {cerr<<#o<<" "<<o<<endl;}
#define dumpc(o) {cerr<<#o; for(auto &e:(o))cerr<<" "<<e;cerr<<endl;}
#define INF 0x3f3f3f3f
#define INFL 0x3f3f3f3f3f3f3f3fLL
const int MOD = 1e9 + 7;

//split delimiter??§?????????
vector<string> split(const string& input, char delimiter) {
	vector<string> ret;
	istringstream stream(input);
	string s;
	while (getline(stream, s, delimiter)) ret.push_back(s);
	return ret;
}
#define MAX 50
signed main() {
	bool a[2][1000] = {};
	for (string s; getline(cin, s) && s != "0";) {
		fill(a[0], a[2], false);
		a[0][0] = true;
		vector<string> t = split(s, ' ');
		rep(i, 0, t.size()) {
			rep(j, 0, MAX)a[(i + 1) % 2][j] = false;
			rep(j, 0, MAX - 20) {
				if (stoi(t[i]) <= 10)
					if (a[i % 2][j])a[(i + 1) % 2][stoi(t[i]) + j] = true;
				if (stoi(t[i]) >= 11)
					if (a[i % 2][j])a[(i + 1) % 2][10 + j] = true;
				if (stoi(t[i]) == 1)
					if (a[i % 2][j])a[(i + 1) % 2][11 + j] = true;
			}
		}
		a[t.size() % 2][0] = true;
		rrep(i, 0, 22) {
			if (a[t.size() % 2][i]) {
				cout << i << endl;
				break;
			}
		}
	}
	return 0;
}

Measured memory_bytes: 3168
package main

import (
	"bufio"
	"fmt"
	"os"
	"sort"

	rbt "github.com/emirpasic/gods/trees/redblacktree"
)

type Point struct {
	x, y, idx int
}

func main() {
	defer writer.Flush()
	N := ReadInt()
	points := make([]*Point, N)
	for i := 0; i < N; i++ {
		points[i] = &Point{
			idx: i,
			x:   ReadInt(),
			y:   ReadInt(),
		}
	}

	uf := MakeUnionFind(N)
	var t *rbt.Tree

	sort.Slice(points, func(i, j int) bool {
		return points[i].x < points[j].x
	})
	t = rbt.NewWithIntComparator()
	for _, point := range points {
		node, _ := t.Floor(point.y)
		for node != nil {
			uf.Unite(point.idx, node.Value.(*Point).idx)
			node = node.Left
		}
		t.Put(point.y, point)
	}

	sort.Slice(points, func(i, j int) bool {
		return points[i].x > points[j].x
	})
	t = rbt.NewWithIntComparator()
	for _, point := range points {
		node, _ := t.Ceiling(point.y)
		for node != nil {
			uf.Unite(point.idx, node.Value.(*Point).idx)
			node = node.Right
		}
		t.Put(point.y, point)
	}

	sort.Slice(points, func(i, j int) bool {
		return points[i].y < points[j].y
	})
	t = rbt.NewWithIntComparator()
	for _, point := range points {
		node, _ := t.Floor(point.x)
		for node != nil {
			uf.Unite(point.idx, node.Value.(*Point).idx)
			node = node.Left
		}
		t.Put(point.x, point)
	}

	sort.Slice(points, func(i, j int) bool {
		return points[i].y > points[j].y
	})
	t = rbt.NewWithIntComparator()
	for _, point := range points {
		node, _ := t.Ceiling(point.x)
		for node != nil {
			uf.Unite(point.idx, node.Value.(*Point).idx)
			node = node.Right
		}
		t.Put(point.x, point)
	}

	for i := 0; i < N; i++ {
		Println(uf.Size(i))
	}
}

type UnionFind []int

func MakeUnionFind(size int) UnionFind {
	uf := make([]int, size)
	for i := 0; i < size; i++ {
		uf[i] = -1
	}
	return uf
}
func (uf UnionFind) Root(x int) int {
	if uf[x] < 0 {
		return x
	}
	uf[x] = uf.Root(uf[x])
	return uf[x]
}
func (uf UnionFind) Unite(x, y int) {
	x, y = uf.Root(x), uf.Root(y)
	if x == y {
		return
	}
	if uf[x] > uf[y] {
		x, y = y, x
	}
	uf[x] += uf[y]
	uf[y] = x
}
func (uf UnionFind) Connected(x, y int) bool { return uf.Root(x) == uf.Root(y) }
func (uf UnionFind) Size(x int) int          { return -uf[uf.Root(x)] }

var reader = bufio.NewReader(os.Stdin)

func Scan(a ...interface{}) {
	if _, err := fmt.Fscan(reader, a...); err != nil {
		panic(err)
	}
}
func ReadInt() (i int)       { Scan(&i); return }
func ReadString() (s string) { Scan(&s); return }
func ReadInts(n int) (a []int) {
	for i := 0; i < n; i++ {
		a = append(a, ReadInt())
	}
	return
}

var writer = bufio.NewWriter(os.Stdout)

func Printf(format string, a ...interface{}) { fmt.Fprintf(writer, format, a...) }
func Println(a ...interface{})               { fmt.Fprintln(writer, a...) }


Measured memory_bytes: 76572
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<algorithm>
using namespace std;
char s[101010];
int sa[101010];
int x[101010],y[101010];
int h[101010],t[101010];
int cnt[101010];
int main()
{
	int l,m=300,p;
	scanf("%s",s);
	l=strlen(s);
	memset(t,0,sizeof(t));
	x[l]=y[l]=-1;
	for(int i=0;i<l;i++)
		t[x[i]=s[i]]++;
	for(int i=1;i<m;i++)
		t[i]+=t[i-1];
	for(int i=l-1;i>=0;i--)
		sa[--t[x[i]]]=i;
	for(int i=1;;i<<=1)
	{
		p=0;
		for(int j=l-i;j<l;j++)
			y[p++]=j;
		for(int j=0;j<l;j++)
			if(sa[j]>=i)
				y[p++]=sa[j]-i;
		for(int j=0;j<m;j++)
			t[j]=0;
		for(int j=0;j<l;j++)
			t[x[j]]++;
		for(int j=1;j<m;j++)
			t[j]+=t[j-1];
		for(int j=l-1;j>=0;j--)
			sa[--t[x[y[j]]]]=y[j];
		swap(x,y);
		x[sa[0]]=0;
		m=0;
		for(int j=1;j<l;j++)
			if(y[sa[j]]==y[sa[j-1]]&&y[sa[j]+i]==y[sa[j-1]+i])
				x[sa[j]]=m;
			else
				x[sa[j]]=++m;
		m++;
		if(m==l)
			break;
	}
	int k=0;
	for(int i=0;i<l;i++)
	{
		if(x[i]==0)
			k=0;
		else
		{
			while(s[i+k]==s[sa[x[i]-1]+k])
				k++;
		}
		cnt[k+1]++;
		cnt[l-i+1]--;
		if(k)
			k--;
	}
	int ans=cnt[1];
	for(int i=2;i<=l;i++)
	{
		cnt[i]+=cnt[i-1];
		ans=max(ans,cnt[i]);
	}
	printf("%d\n",ans);
	return 0;
}

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

using namespace std;
typedef long long ll;

typedef struct edge_ {
    int to;
    ll cost;
} edge;

vector<ll> dist;
vector<vector<edge> > G;


void dfs(int s) {
    for (auto e: G[s]) {
        int u = e.to;   ll d = e.cost;
        if (dist[u] >= 0)
            continue;
        
        dist[u] = dist[s] + d;
        dfs(u);
    }
}

int main() {
    int n;  cin >> n;
    G.resize(n);
    vector<ll> ans;
    for (int i = 0; i < n-1; i++) {
        int a, b;   ll c;   cin >> a >> b >> c;
        edge e1 = {b-1, c}, e2 = {a-1, c};
        G[a-1].push_back(e1);
        G[b-1].push_back(e2);
    }

    int q, k;   cin >> q >> k;
    ans.resize(q);
    dist.resize(n, -1);
    dist[k-1] = 0;
    dfs(k-1);
    for (int i = 0; i < q; i++) {
        int x, y;   cin >> x >> y;
        ans[i] = dist[x-1] + dist[y-1];
    }

    for (int i = 0; i < q; i++)
        cout << ans[i] << endl;
    return 0;
}

Measured memory_bytes: 16272
#include<bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;++i)
#define rrep(i,n) for(int i=n-1;i>=0;--i)
#define yesno(flg) if(flg){cout<<"YES"<<endl;}else{cout<<"NO"<<endl;}
#define MAX_N 1002
#define i197 1000000007

using namespace std;

typedef long long ll;
typedef pair<ll,ll> P1;
typedef pair<int,int> Pi;
typedef pair<double,Pi> Pdi;
typedef pair<ll,int>Pli;
typedef pair<P1,ll> P2;
const ll INF=1000000000000000001;
struct edge{int to,cost;};
int dy[]={0, 0, 1, -1};
int dx[]={1, -1, 0, 0};
struct Road{double cost;int a,b;};


ll b[200002]={},c[200002]={};
int main() {

	ll n;
	string s;
	ll a=0,t=2000002;

	cin>>n;
	cin>>s;

	rep(i,n){
		b[i+1]=b[i];
		c[i+1]=c[i];
		if(s[i]=='#')b[i+1]++;
		if(s[i]=='.')c[i+1]++;
	}
	for(int i=0; i<n; i++){
		if(s[i]=='#')a=b[i]+(c[n]-c[i+1]);
		if(s[i]=='.')a=c[n]-c[i+1]+b[i+1];
		t=min(a,t);
	}
	a=min(b[n],c[n]);
	t=min(t,a);

	cout<<t<<endl;

	return 0;

}


Measured memory_bytes: 3716
$n, $m = gets.split.map(&:to_i)
edges = Hash.new {|h, k| h[k] = []}
edge_arr = []
$m.times do
  a, b = gets.split.map {|x| x.to_i - 1}
  edge_arr << [a, b]
  edges[a] << b
  edges[b] << a
end

def dfs(s, edges, visited)
  visited[s] = true
  edges[s].each do |ns|
    dfs(ns, edges, visited) unless visited[ns]
  end
end

def is_union(edges)
  visited = Array.new($n) { false }
  dfs(0, edges, visited)
  visited.all?
end

count = 0
edge_arr.each do |(a, b)|
  edges[a].delete(b)
  edges[b].delete(a)

  count += 1 unless is_union(edges)

  edges[a] << b
  edges[b] << a
end

puts count

Measured memory_bytes: 3836
N = int(input())
A = list(map(int,input().split()))

A.sort(reverse=True)

Alice = 0
Bob = 0

for i in range(N):
    if i%2 == 0:
        Alice = Alice + A[i]
    else:
        Bob = Bob + A[i]

ans = (Alice - Bob)

print(ans)

Measured memory_bytes: 3060
#include<iostream>
using namespace std;
void printAns(int arr[], int len) {
	using std::cout;
	using std::endl;
	for (int i = 0; i < len; i++)
	{
		if (i)
			cout << " ";
		cout << arr[i];
	}
	cout << endl;
}
int main() {
	int len;
	cin >> len;
	int* arr = new int[len];
	for (int i = 0; i < len; i++)
		cin >> arr[i];
	//insertion sort
	/* for (int i = 0; i < len - 1; i++) {
		printAns(arr, len);
		for (int j = i + 1; j > 0; j--) {
			if (arr[j - 1] > arr[j])
				swap(arr[j - 1], arr[j]);
		}
	}
	printAns(arr, len);*/
	//bubble sort
	int step = 0;
	for (int i = 0; i < len - 1; i++) {
		for (int j = len - 1; j > i; j--) {
			if (arr[j] < arr[j - 1]) {
				swap(arr[j], arr[j - 1]);
				step++;
			}
		}
	}
	printAns(arr, len);
	cout << step << endl;

	/*int step = 0;
	for (int i = 0; i < len - 1 ; i++) {
		if (arr[i] > arr[i + 1]) {
			swap(arr[i], arr[i + 1]);
			step++;
		}
		for(int j=i;j>0;j--){
			if (arr[j] < arr[j - 1]) {
				swap(arr[j], arr[j - 1]);
				step++;
			}
		}
	}
	printAns(arr, len);
	cout << step << endl;*/
	return 0;
}


Measured memory_bytes: 3100
/*
 * Author : Sadi
 * Fri 03/07/2020
 * 22:13:35.27
 */
#include <iostream>
#include <string>
#include <sstream>
#include <algorithm>
#include <vector>
#include <map>
#include <set>
#include <bitset>
#include <cassert>

using namespace std;

#define    watch(x); cout << "\n" <<  #x << " is: " << x << "\n";
#define    all(a) (a).begin(), (a).end()
#define    fi first
#define    se second

template<class A, class B>
ostream& operator << (ostream& output, const pair<A, B>& p) {
    output << "(" << p.first << ", " << p.second << ")";
    return output;
}

template<class A>
ostream& operator << (ostream& output, const vector<A>& a) {
    output << "[";
    for(auto it = a.begin(); it != a.end(); ++it) {
        if(it != a.begin()) {
            output << ", ";
        }
        output << *it;
    }
    output << "]";
    return output;
}

using lld = long long;
using pii = pair<int, int>;
using pll = pair<lld, lld>;

//const int inf = 1e9;
//const int mod = 1e9 + 7;
//const double PI = acos(-1.0);
//const int mx = 1e5 + 5;



int main()
{
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
#ifndef ONLINE_JUDGE
//    freopen("input.txt", "r", stdin);
//    freopen("output.txt", "w", stdout);
#endif // ONLINE_JUDGE

    int n;
    cin >> n;
    int maxprice = 0;
    int cost = 0;
    for(int i = 0; i < n; ++i) {
        int p;
        cin >> p;
        maxprice = max(maxprice, p);
        cost += p;
    }
    cout << cost - maxprice / 2 << endl;
    return 0;
}


Measured memory_bytes: 3648
#include <iostream>
#include <string>
#include <cmath>
#include <vector>
#include <map>
#include <numeric>
#include <algorithm>
#include <stdio.h>

int main(void){
  int n;
  long long s;
  std::cin >> n;
  std::vector<int> f(1000500);
  for(int x=1;x<=102;x++){
    for(int y=1;y<=102;y++){
      for(int z=1;z<=102;z++){
        s=x*x+y*y+z*z+x*y+y*z+z*x;
        f.at(s-1)+=1;
      }
    }
  }
  for(int i=0;i<n;i++){
    std::cout << f.at(i) << std::endl;
  }
  return 0;
}

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

int main(){
  int N; cin>>N;
  for(int i=0;i<50000;i++){
    if(i+i*8/100==N){
      cout<<i<<endl;
      return 0;
    }
  }
  cout<<":("<<endl;
  
}

Measured memory_bytes: 256
#include <cstdio>
#include <vector>
#define debug(...) fprintf(stderr, __VA_ARGS__)

typedef long long lolong;
inline int input() { int x; scanf("%d", &x); return x; }

const int maxn = 5005, mod = 1000000007;
lolong f[maxn][maxn], fu[maxn], g[maxn];
int size[maxn];
std::vector<int> G[maxn];

void dp(int u, int fa) {
	size[u] = 1;
	f[u][1] = 1;
	for(int v : G[u])
		if(v != fa) {
			dp(v, u);
			for(int i = 0; i <= size[u]; i ++) {
				fu[i] = f[u][i];
				f[u][i] = 0;
			}
			for(int i = 0; i <= size[u]; i ++)
				for(int j = 0; j <= size[v]; j ++)
					(f[u][i + j] += fu[i] * f[v][j]) %= mod;
			size[u] += size[v];
		}
	if(f[u][0]) puts("FUCK");
	for(int i = 1; i <= size[u]; i ++)
		(f[u][0] -= f[u][i] * g[i]) %= mod;
}

int main() {
	int n = input();
	for(int i = 1; i < n; i ++) {
		int u = input(), v = input();
		G[u].push_back(v);
		G[v].push_back(u);
	}
	g[0] = 1;
	for(int i = 2; i <= n; i ++)
		g[i] = g[i - 2] * (i - 1) % mod;
	dp(1, 0);
	printf("%lld\n", (mod - f[1][0]) % mod);
}

Measured memory_bytes: 195328