akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
const int INF = 1e9;
const int MOD = 1e9+7;
using LL = long long;
const LL LINF = 1e18;
const double EPS = 1e-10;
using namespace std;
#define COUT(v) cout<<(v)<<endl
#define CIN(n)  int(n);cin >> (n)
#define LCIN(n) LL(n);cin >> (n)
#define SCIN(n) string(n);cin >> (n)
#define YES(n) cout<<((n)? "YES" : "NO")<<endl
#define Yes(n) cout<<((n)? "Yes" : "No")<<endl
#define POSSIBLE(n) cout << ((n) ? "POSSIBLE" : "IMPOSSIBLE"  ) << endl
#define Possible(n) cout << ((n) ? "Possible" : "Impossible"  ) <<endl

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

#define FOREACH(x,a) for(auto& (x) : (a) )

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

#define P pair<int,int>
#define I vector<int>
#define pb(v) push_back(v)
#define V vector
#define rt return
#define rmsame(a) sort(ALL(a)),a.erase(unique(ALL(a)), a.end())
#define ENDL cout<<endl
#define MAXE(a,b) a=max(a,b)
#define MINE(a,b) a=min(a,b)

typedef string::const_iterator State;
class PalseError {};
class Edge{
public:
    int from,to,value;
    Edge(LL a,LL b,LL c){
        from = a;
        to = b;
        value = c;
    }
    Edge(LL a,LL b){
        from = a;
        to = b;
    }
};

class UnionFind {
 vector<int> data;
public:
 UnionFind(int size) : data(size, -1) { }
 bool unionSet(int x, int y) {
  x = root(x); y = root(y);
  if (x != y) {
   if (data[y] < data[x]) swap(x, y);
   data[x] += data[y]; data[y] = x;
  }
  return x != y;
 }
 bool findSet(int x, int y) {
  return root(x) == root(y);
 }
 int root(int x) {
  return data[x] < 0 ? x : data[x] = root(data[x]);
 }
 int size(int x) {
  return -data[root(x)];
 }
};;
int H,W;
int decode(int i,int j){
    return i*W+j;
}
/*
pair<int,int> uku(int d){
    return make_pair(d/W,d%W);
}
*/
int main(){
    cin >> H >> W;
    UnionFind Uni(H*W);
    vector<string> vec;
    for(int a = 0;a < H;a++){
        SCIN(str);
        vec.push_back(str);
    }
    int dx[] = {1,0,-1,0};
    int dy[] = {0,1,0,-1};
    for(int a = 0;a < H;a++){
        for(int b = 0;b < W;b++){
            for(int index = 0;index < 4;index++){
                if(0 <= dx[index] + a && dx[index] + a <= H-1 && 0 <= b + dy[index] && b+ dy[index] <= W-1){
                    if(vec.at(a).at(b)!=vec.at(a+dx[index]).at(b+dy[index]))Uni.unionSet(decode(a,b),decode(dx[index]+a,dy[index]+b));
                }
            }
        }
    }
    //rt 0;
    map<LL,pair<LL,LL>> mp;
    for(int a = 0;a < H ;a++){
        for(int b = 0;b < W;b++){
           // cout<<Uni.root(decode(a,b))<<" ";
            if(vec.at(a).at(b) == '#')mp[Uni.root(decode(a,b))].second++;
            else mp[Uni.root(decode(a,b))].first++;
        }
        //cout<<endl;
    }
    LL ans = 0;
    for(auto a : mp){
        ans += a.second.second*a.second.first;
    }
    COUT(ans);
    return 0;
}


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

int main() {
  long double N;
  cin >> N;
  vector<int> x(N);
  vector<int> y(N);
  for (int i = 0; i<N; i++) {
    cin >> x.at(i) >> y.at(i);
  };
  long double M = 0;
  for (int i = 0; i<N-1; i++) {
    M = M+i+1;
  };
  long double L = 0;
  for (int i = 0; i<N; i++) {
    long double xi = x.at(i);
    long double yi = y.at(i);
    for (int j = i+1; j<N; j++) {
      long double xj = x.at(j);
      long double yj = y.at(j);
      L += (sqrtl((xi-xj)*(xi-xj)+(yi-yj)*(yi-yj)))*(N-1)/M;
    };
  };
  cout << fixed << setprecision(10);
  cout << L << endl;
}

Measured memory_bytes: 256
//問２　2736 渡辺彩子
import java.util.Scanner;
public class Main{
    
    public void solve(){
        Scanner sc=new Scanner(System.in);
        for(int a=0;a<4;a++){
            int ban=sc.nextInt();
            int suu=sc.nextInt();
            switch(ban){
             case 1:
                System.out.println(suu*6000);
                break;
             case 2:
                System.out.println(suu*4000);
                break;
             case 3:
                System.out.println(suu*3000);
                break;
             case 4:
                System.out.println(suu*2000);
                break;
            }
        }

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

Measured memory_bytes: 17364
#include<iostream>
#include<math.h>
#include<bits/stdc++.h>
#define ll long long int
#define hell 1000000007LL
using namespace std;
ll power(ll x, ll y, ll z){ 
    if(y==0)
     return 1;
    else
    {
        ll p=power(x,y/2,z);
        if(y%2==0)
         return (p*p)%z;
        else
        return (x*((p*p)%z))%z;
    }}
ll gcd(ll x,ll y)
{
    if(y==0)
     return x;
    else
    return gcd(y,x%y);
}
ll po(ll x)
{
    ll c=0;
    while(x>0)
    {
        x=x&(x-1);
        c++;
    }
    return c;
}
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.precision(20);
    ll n,x;
    cin>>n>>x;
    if(n>=10)
    cout<<x;
    else
    cout<<x+100*(10-n);}
   

Measured memory_bytes: 3652
#import pysnooper
#import numpy
#import os,re,sys,operator
from collections import Counter,deque
#from operator import itemgetter,mul
#from itertools import accumulate,combinations,groupby,combinations_with_replacement,permutations
from sys import stdin,setrecursionlimit
#from bisect import bisect_left,bisect_right
#from copy import deepcopy
#import heapq
#import math
#import string
#from time import time
#from functools import lru_cache,reduce
#from math import factorial
#import sys
#from fractions import gcd
setrecursionlimit(10**6)
input=stdin.readline
def m(t):
    r=0
    for i in t:
        r=max(r,max(i))
    return r

h,w=map(int,input().split())
s=[list(input()) for _ in range(h)]
dx=[0,0,1,-1]
dy=[1,-1,0,0]
ans=0
rf=range(4)
rh=range(h)
rw=range(w)
for sy in rh:
    for sx in rw:
        if s[sy][sx]=="#":
            continue
        dis=[[-1]*w for _ in rh]
        dis[sy][sx]=0
        q=deque([(sy,sx)])
        while len(q)>0:
            y,x=q.popleft()
            for i in rf:
                ny=y+dy[i]
                nx=x+dx[i]
                if ny<0 or nx<0 or ny==h or nx==w:
                    continue
                if s[ny][nx]=="#":
                    continue
                if dis[ny][nx]==-1:
                    dis[ny][nx]=dis[y][x]+1
                    q.append((ny,nx))
        ans=max(ans,m(dis))
print(ans)

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

typedef long long int ll;
const ll maxs = 1e5+5;

#define pb push_back

ll n,a,b;
std::vector<ll> Tree[maxs];
ll dist[2][maxs];

void go(ll s,ll p,ll ind)
{
    dist[ind][s] = dist[ind][p]+1;
    for(auto d : Tree[s])
    {
        if(d != p)
            go(d,s,ind);
    }
}

int main()
{
    cin>>n>>a>>b;
    for(ll i=0;i<n-1;i++)
    {
        ll s,d;
        cin>>s>>d;
        Tree[s].pb(d);
        Tree[d].pb(s);
    }
    dist[0][0] = dist[1][0] = -1;
    go(a,0,0);
    go(b,0,1);
    
    ll ans=0;
    for(ll i=1;i<=n;i++)
    {
        if( dist[0][i] < dist[1][i] )
        {
            ans = max(ans,dist[1][i] - 1);
        }
    }
    std::cout << ans << std::endl;
    return 0;
}

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

int main(){
  string A,B,C;
  cin>>A>>B>>C;
  int a,b,c;
  a=A.size( )-1;
  b=B.size( )-1;
  c=C.size( )-1;
  if(A[a]==B[0] && B[b]==C[0])
    cout<<"YES"<<endl;
  else
    cout<<"NO"<<endl;
  
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
constexpr int MAX = 10000;
int a[MAX + 1], b[MAX];
using P = std::pair<int, int>;
std::map<P, int> memo[31];
int main()
{
    std::cin.tie(0);
    std::ios::sync_with_stdio(false);
    int N, M;
    std::cin >> N >> M;
    for (int i = 0; i <= M; i++) { std::cin >> a[i]; }
    for (int i = 0; i < M; i++) { std::cin >> b[i]; }
    auto dp = [&](auto&& self, const int l, const int r, const int maxord, const int height) -> int {
        const int w = r - l;
        if (maxord == height and memo[maxord].find({l, r}) != memo[maxord].end()) { return memo[maxord][{l, r}]; }
        int ans = 0;
        const int ind = std::lower_bound(a, a + M + 1, r) - a;
        if (a[ind - 1] <= l) {
            const int ord = b[ind - 1];
            if (ord - height >= 1) {
                ans = w - (1 << (ord - height - 1));
            } else {
                if (ord == maxord) {
                    ans = w - 1;
                } else {
                    ans = w;
                }
            }
        } else {
            const int mid = (l + r) / 2;
            ans = std::min(self(self, l, mid, maxord, height + 1) + self(self, mid, r, height + 1, height + 1), self(self, l, mid, height + 1, height + 1) + self(self, mid, r, maxord, height + 1));
        }
        if (height == maxord) {
            return memo[maxord][{l, r}] = ans;
        } else {
            return ans;
        }
    };
    std::cout << dp(dp, 0, 1 << N, 0, 0) << std::endl;
    return 0;
}



Measured memory_bytes: 22712
n=int(input())

import sys
sys.setrecursionlimit(10 ** 7)

graph = [[] for _ in range(n)]
for i in range(n - 1):
    a, b = map(int, input().split())
    graph[a - 1].append((b - 1, i))
    graph[b - 1].append((a - 1, i))
# print(graph)

max_color=0
for graph_i in graph:
    max_color=max(max_color, len(graph_i))
print(max_color)

colors=[-1]*(n-1)

def dfs(v, color, pre):
    if color!=0:
        nc=0
    else:
        nc=1
    for e in graph[v]:
        # print(e,nc)
        if e[0]==pre:
            continue
        colors[e[1]]=nc
        dfs(e[0],nc,v)
        nc+=1
        if nc==color:
            nc+=1

dfs(0,-1,-1)

for c in colors:
    print(c+1)


Measured memory_bytes: 74684
#include <iostream>
#include <vector>
#include <array>
#include <list>
#include <string>
#include <stack>
#include <queue>
#include <deque>
#include <map>
#include <set>
#include <unordered_map>
#include <unordered_set>
#include <tuple>
#include <memory>
#include <cmath>
#include <algorithm>
#include <functional>
#include <iomanip>
#include <numeric>
#include <climits>
#include <cfloat>
#include <cassert>
#include <random>

int main() {
	int n; std::cin >> n;
	std::vector<int> blocks(n); for (auto& b : blocks) std::cin >> b;
	std::vector<bool> can_make(n + 1, false); can_make[0] = true;
	for (const auto b : blocks) {
		if (can_make[b - 1]) {
			can_make[b] = true;
		}
	}
	int max_index = 0;
	for (auto i = 1; i < can_make.size(); ++i) {
		if (can_make[i]) max_index = i;
	}
	if (max_index == 0) {
		std::cout << "-1\n";
	}
	else {
		std::cout << (n - max_index) << std::endl;
	}
}


Measured memory_bytes: 1024
#include<iostream>
#include<string>

using namespace std;

int main()
{
    string line;
    int m[6];
    int top=1,n=5,e=3;
    for(int i=0;i<6;i++) cin >> m[i];
    cin >> line;
    for(int i=0;i<(int)line.size();i++){
        int t=top;
        if(line[i]=='N'){
            top=7-n;
            n=t;
        }
        else if(line[i]=='S'){
            top=n;
            n=7-t;
        }
        else if(line[i]=='E'){
            top=7-e;
            e=t;
        }
        else{
            top=e;
            e=7-t;
        }

    }
    cout << m[top-1] << endl;
    return 0;
}



Measured memory_bytes: 3156
fun main(args: Array<String>) {
    val arr = readLine()!!.split(" ").map { s->s.toInt() }
    val n = arr[0]
    val m = arr[1]
    val unionFind = UnionFind(n)

    val bridges = Array(m) {
        readLine()!!.split(" ").map { s->s.toInt()-1 }
    }
    val count:Long = n.toLong()*(n-1)/2
    val result = Array(m){ count }
    for(i in 1 until m){
        val bridge = bridges[m-i]
        if(!unionFind.same(bridge[0],bridge[1])){
            result[i]=result[i-1]-unionFind.size(bridge[0])*unionFind.size(bridge[1])
            unionFind.unite(bridge[0],bridge[1])
        }else{
            result[i]=result[i-1]
        }
    }
    result.reverse()
    result.forEach { println(it) }
}

class UnionFind(size:Int){
    private val parents: Array<Int?> =  arrayOfNulls(size)
    private val sizes: Array<Int> =  Array(size) { i -> 1}

    fun root(node: Int):Int{
        return if (parents[node] == null){
            node
        }else{
            parents[node]=root(parents[node]!!)
            parents[node]!!
        }
    }

    fun unite(u:Int,v:Int){
        var ur = root(u)
        var vr = root(v)
        if(sizes[ur]>sizes[vr]){
            ur = vr .apply{vr=ur}
        }
        parents[ur] = vr
        sizes[vr] += sizes[ur]
    }

    fun same(u:Int,v:Int):Boolean = root(u)==root(v)

    fun size(u:Int):Int = sizes[root(u)]
}

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

int main(){
  int a, b, c, d;
  cin >> a >> b >> c >> d;
  
  if (a + b > c + d){
    cout << "Left" << endl;
  }
  
  else if (a + b == c + d){
    cout << "Balanced" <<endl;
  }
  
  else{
    cout << "Right" << endl;
  }
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#define MIN_DIF_MAX -1e9
#define MAX_MIN 2e9
using namespace std;

int main(){
  int n;
  int min_val = MAX_MIN;
  int dif_max = MIN_DIF_MAX;
  cin >> n;

  for(int i = 0; i < n; i++){
    int num;
    cin >> num;

    int dif = num - min_val;
    dif_max = max(dif_max, dif);
    min_val = min(min_val, num);
  }

  cout << dif_max << endl;
  
  return 0;
}

Measured memory_bytes: 3100
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;

typedef long long LL;

const int MAXN=100000;

int k,n;
LL a[MAXN+1],b[MAXN];

int main(){
	cin>>k>>n;
	if(k>n) k=n;
	k--;
	
	for(int i=1;i<=n;i++) cin>>a[i];
	sort(a+1,a+n+1);
	for(int i=1;i<n;i++) b[i]=a[i+1]-a[i];
	sort(b+1,b+n);
	
	LL ans=0;
	for(int i=1;i<=n-1-k;i++) ans+=b[i];
	cout<<ans<<"\n";
}


Measured memory_bytes: 1792
/**
 * Created by hiramekun at 20:53 on 2019-09-21.
 */
#include <bits/stdc++.h>

using namespace std;

using ll = long long;
using vl = vector<ll>;
using vvl = vector<vl>;
using vb = vector<bool>;
using P = pair<ll, ll>;
template<typename T> using pq = priority_queue<T>;
template<typename T> using minpq = priority_queue<T, vector<T>, greater<T>>;
template<typename T, typename K> using ump = unordered_map<T, K>;
const ll dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};
const ll mod = 1000000007;
const ll inf = ll(1e9);
const ll e5 = ll(1e5);
const ll ll_inf = ll(1e9) * ll(1e9);

#define rep(i, n) for(ll i = 0; i < (ll)(n); i++)
#define repr(i, n) for(ll i = ll(n - 1); i >= 0; i--)
#define each(i, mp) for(auto& i:mp)
#define eb emplace_back
#define F first
#define S second
#define all(obj) (obj).begin(), (obj).end()

template<class T>
ostream &operator<<(ostream &out, const vector<T> &list) {
    ll n = list.size();
    rep(i, n) out << list[i] << ' ';
    return out;
}

template<class T>
istream &operator>>(istream &in, vector<T> &list) {
    ll n = list.size();
    rep(i, n) in >> list[i];
    return in;
}

template<class T>
ostream &operator<<(ostream &out, const vector<vector<T>> &list) {
    ll n = list.size();
    rep(i, n) out << list[i] << '\n';
    return out;
}

/* ------------- ANSWER ------------- */
/* ---------------------------------- */

void solve() {
    ll h, w, a, b;
    cin >> h >> w >> a >> b;

    vvl ans(h, vl(w));
    rep(i, h) rep(j, w) ans[i][j] = 0;
    ll i = 0;
    while (b--) {
        rep(j, w) {
            ans[i][j] = 1;
        }
        i++;
    }
    i = 0;
    while (a--) {
        rep(j, h) {
            if (ans[j][i] == 0) ans[j][i] = 1;
            else ans[j][i] = 0;
        }
        i++;
    }
    rep(k, h) {
        rep(j, w) {
            cout << ans[k][j];
        }
        cout << '\n';
    }
}

int main() {
#ifdef MY_DEBUG
    while (true) {
#endif
        solve();
#ifdef MY_DEBUG
    }
#endif
    return 0;
}

Measured memory_bytes: 9088
from collections import deque
n, m = map(int, input().split())
lis = [[] for _ in range(n+1)]
for _ in range(m):
    a,b = map(int, input().split())
    lis[a].append(b)
    lis[b].append(a)
queue = deque([1])
dist_list = [-1]*(n+1)
dist_list[1] = 0
while len(queue) != 0:
    now = queue.popleft()
    for v in lis[now]:
        if dist_list[v] == -1:
            dist_list[v] = dist_list[now] + 1
            queue.append(v)
print("Yes")
for i in range(2, n+1):
    for v in lis[i]:
        if dist_list[v] == dist_list[i]-1:
            print(v)
            break

Measured memory_bytes: 94632
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <time.h>
#include <math.h>
#include <vector>
#include <queue>
#include <map>
#include <set>
#include <algorithm>
#include <iterator>
#include <sstream>
#include <string>
#include <bitset>
using namespace std;
#define FOR(I,F,N) for(int I = F; I < (int)(N); I++)
#define rep(i, n) FOR(i, 0, n)
#define FIN(V) cout<<V<<endl
#define pb push_back
#define INF (1 << 28)

template<typename T>
void remove(vector<T>& vector, unsigned int index){
vector.erase(vector.begin() + index);
}

typedef pair<int, int> P;
typedef long long ll;
typedef priority_queue<int> pq;
int StrToInt(string);
string IntToStr(int);
int dx[4] = {1, -1, 0, 0};
int dy[4] = {0, 0, 1, -1};

void convert(map<char, int> used){
	int sum = 0;
	string MCXI = "mcxi";
	int value[4] = {1000, 100, 10, 1};
	for(int i = 0; i < MCXI.size(); i++){
		sum += value[i]*used[MCXI[i]];
	}
	map<char, int> conv;
	for(int i = 0; i < MCXI.size(); i++){
		conv[MCXI[i]] += (sum / value[i]);
		sum %= value[i];
	}
	for(int i = 0; i < MCXI.size(); i++){
		if(!conv[MCXI[i]])continue;
		else if(conv[MCXI[i]] != 1)cout << conv[MCXI[i]];
		cout << MCXI[i];
	}
	cout << endl;
}

int main(void){
	int n;

	cin >> n;

	rep(l, n){
		map<char, int> used;
		int res = 0;
		for(int i = 0; i < 2; i++){
			string S;
			cin >> S;
			for(int j = 0; j < S.size(); j++){
				if(S[j] >= '0' && S[j] <= '9')continue;
				if(j == 0){used[S[j]]++;continue;}
				char c = S[j-1];
				if(!(c >= '0' && c <= '9')){used[S[j]]++;continue;}
				used[S[j]] += c-'0';
			}
		}
		convert(used);
	}

	return 0;
}



int StrToInt(string s){
	stringstream ss;
	ss << s;
	int val;
	ss >> val;
	return val;
}
string IntToStr(int i){
	stringstream ss;
	ss << i;
	return ss.str();
}

Measured memory_bytes: 1216
package main

import (
	"fmt"
	"os"
	"bufio"
	"strings"
)

func main(){
	var n int = 0
	var w string
	sc := bufio.NewScanner(os.Stdin)
	sc.Split(bufio.ScanWords)
	fmt.Scan(&w)
	for {
		sc.Scan()
	    t := sc.Text()
		if t == "END_OF_TEXT" {
			break
		}
		t = strings.ToLower(t)
		if t == w {
			n++
		}
	}
	fmt.Println(n)
}


Measured memory_bytes: 1136
I=lambda:map(int,input().split());F=1e21;r=range;n,m=I();f=[-F,F];X=[0]+f;Y=X[:];R=(f,F),(f,-F),;H=(F,f),(-F,f),
for i in r(n):*a,c=I();R+=(a,c),;Y+=c,;X+=a
for i in r(m):a,*b=I();H+=(a,b),;X+=a,;Y+=b
def g(X):s=dict(enumerate(sorted(set(X))));return{s[i]:i for i in s},s,len(s)
h,s,K=g(X);w,t,L=g(Y);V,U,v=[[[0]*-~K for i in r(L+1)]for j in r(3)]
for(a,b),c in R:U[w[c]][h[a]]+=1;U[w[c]][h[b]]-=1
for d,(e,f)in H:V[w[e]][h[d]]+=1;V[w[f]][h[d]]-=1
for i in r(L):
 for j in r(K):U[i][j+1]+=U[i][j];V[i+1][j]+=V[i][j]
q=[(h[0],w[0])];v[w[0]][h[0]]=1;a=0
while q:
 x,y=q.pop();a+=(s[x]-s[x+1])*(t[y]-t[y+1])
 for e,f in(-1,0),(1,0),(0,1),(0,-1),:
  c=x+e;d=y+f
  if 1-v[d][c]and U[(f>0)+y][x]*f+V[y][(e>0)+x]*e==0:q+=[(c,d)];v[d][c]=1
print([a,'INF'][a>F])

Measured memory_bytes: 551504
def dfs(i, p):
    if(p == n):
        return 1
    if(i == 2):
        return 0
    ret = 0
    for q in adj[p]:
        ret += dfs(i+1, q)
    return ret

n, m = map(int, input().split())
adj = [[] for i in range(n+1)]
for i in range(m):
    a, b = map(int, input().split())
    adj[a].append(b)
    adj[b].append(a)
ans = dfs(0, 1)

print("POSSIBLE" if(ans) else "IMPOSSIBLE")


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

int main(){
    char c;
    cin>> c ;
    
    if(c =='a'||c=='e'||c=='i' ||c=='o' ||c=='u'){
        cout <<"vowel"<<endl;
    }

    else{
        cout<<"consonant"<<endl;
    }
}


Measured memory_bytes: 256
#include <iostream>
#include <queue>
//#include <pair>
#include <tuple>
#define range(i,a,b) for(int i = (a); i < (b); i++)
#define rep(i,b) for(int i = 0; i < (b); i++)
#define all(a) (a).begin(), (a).end()
#define show(x)  cerr << #x << " = " << (x) << endl;
using namespace std;

template <typename X, typename T>
auto vectors(X x, T a) {
	return vector<T>(x, a);
}

template <typename X, typename Y, typename Z, typename... Zs>
auto vectors(X x, Y y, Z z, Zs... zs) {
	auto cont = vectors(y, z, zs...);
	return vector<decltype(cont)>(x, cont);
}

template<typename T>
ostream& operator << (ostream& os, vector<T>& v){
	rep(i,v.size()){ os << v[i] << (i == v.size() - 1 ? "" : " "); } return os;
}
template<typename T>
istream& operator >> (istream& is, vector<T>& v){
	for(T& x: v){ is >> x; } return is;
}

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

int main(){
	int h, w;
	while(cin >> w >> h,h||w){
		vector<vector<char>> m(h, vector<char>(w));
		queue<pair<int, int>> q;
		rep(i,h){
			rep(j,w){
				cin >> m[i][j];
				if(m[i][j] == '@') q.emplace(i,j);
			}
		}

		bool u[20][20] = {};
		while(not q.empty()){
			int y, x;
			tie(y, x) = q.front(); q.pop();
			if(u[y][x]) continue;
			u[y][x] = true;
			rep(d,4){
				int ny = y + dy[d];
				int nx = x + dx[d];
				if(ny < 0 or ny >= h or nx < 0 or nx >= w) continue;
				if(m[ny][nx] == '#') continue;
				q.emplace(ny,nx);
			}
		}

		int cnt = 0;
		rep(i,h){
			rep(j,w){
				cnt += u[i][j] == true;
			}
		}
		cout << cnt << endl;
	}
}



Measured memory_bytes: 3048
#include<bits/stdc++.h>
using namespace std;
int digit(int n){
	int digit=0;
	while(n>0){
		n/=10;
		digit++;
	}
	return digit;
}
int main(){
	int n,cnt=0;
	cin>>n;
	for(int i=1;i<=n;i++){
		if(digit(i)%2==1) cnt++;
		else continue;
	}
	cout<<cnt<<endl;
	return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<vector>
#include<map>
#include<string>
#define rep(i,N) for(int i=0;i<N;i++)

long long  INF=1000000000000000000;
long long mod=1000000007;
using namespace std;

int main(){
int x;
cin>>x;
int ans=1;
for(int i=100;i>1;i--){
    int beki=1;
    int t=0;
    while(beki<=x){
        beki*=i;
        t++;
    }
    beki/=i;
    if(t>=3)ans=max(beki,ans);
}

cout<<ans<<endl;

 return 0;
}
/*
10

9

1

1

999

961
*/

Measured memory_bytes: 256
n, m = map(int, input().split())
x = sorted(map(int, input().split()))
if n >= m:
    print(0)
else:
    dif = []
    for i in range(m-1):
        dif.append(x[i + 1] - x[i])
    print(sum(dif) if n == 1 else sum(sorted(dif)[:-(n-1)]))


Measured memory_bytes: 13968
def check(A, K, t):
    # K回で長さt以下にできるか？（t：整数）
    cnt = 0
    for a in A:
        cnt += (a - 1) // t
    return cnt <= K


def main():
    N, K = list(map(int, input().split()))
    A = list(map(int, input().split()))
    ng, ok = 0, max(A)
    while ok - ng > 1:
        mid = (ok + ng) // 2
        if check(A, K, mid):
            ok = mid
        else:
            ng = mid
    print(ok)


if __name__ == '__main__':
    main()

Measured memory_bytes: 93856
#include <iostream>
#include <stdio.h>
#include <cstring>
#include <vector>
#include <algorithm>
#include <cstdlib>
#include <cmath>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <ctime>
#include <cassert>
#include <unordered_map>
#include <fstream>
#include <random>
#include <cstring>
#include <complex>
#include <bitset>
 
#define all(a) (a).begin(), (a).end()
#define sz(a) (int)(a).size()
#define pb push_back
 
using namespace std;

mt19937 rr(random_device{}());

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef double ld;

const int INF = 1e9;

int solve(string &a, string &b) {
    int n = sz(a);
    vector<int> l(n, INF), r(n, INF);
    int last = -1;
    for (int i = 0; i < 2 * n; ++i) {
        if (b[i % n] == '1') {
            last = i;
        }
        if (last != -1) {
            l[i % n] = min(l[i % n], i - last);
        }
    }
    last = 2 * n;
    for (int i = 2 * n - 1; i >= 0; --i) {
        if (b[i % n] == '1') {
            last = i;
        }
        if (last != 2 * n) {
            r[i % n] = min(r[i % n], last - i);
        }
    }

    // for (int i = 0; i < n; ++i)
    //     cout << l[i] << " ";
    // cout << endl;

    // for (int i = 0; i < n; ++i)
    //     cout << r[i] << " ";
    // cout << endl;

    int ans = INF;

    for (int shift = 0; shift < n; ++shift) {
        vector<bool> used(n);
        int cnt = 0;
        for (int i = 0; i < n; ++i) {
            if (a[i] != b[(i + shift) % n]) {
                ++cnt;
            }
            if (a[i] != b[(i + shift) % n] && r[i] > shift) {
                used[i] = true;
            }
        }

        vector<pair<int, int>> p;
        for (int i = 0; i < n; ++i) {
            if (used[i]) {
                p.push_back({l[i], r[i] - shift});
            }
        }
        
        sort(all(p));

        int k = sz(p);
        vector<int> suff(k + 1);

        for (int i = k - 1; i >= 0; --i) {
            suff[i] = max(suff[i + 1], p[i].second);
        }

        int maxx = 0;
        for (int i = 0; i <= k; ++i) {
            ans = min(ans, 2 * (maxx + suff[i]) + shift + cnt);
            if (i < k)
                maxx = max(maxx, p[i].first);
        }
    }
    return ans;
}

int main() {    
    // freopen("input.txt", "r", stdin);
    // freopen("output.txt", "w", stdout);
    ios_base::sync_with_stdio(false);
    cin.tie(0);    
    cout.tie(0);

    string a, b;
    bool f = false;
    cin >> a;
    cin >> b;
    int n = sz(a);

    for (int i = 0; i < n; ++i)
        f |= (b[i] == '1');
    if (!f) {
        for (int i = 0; i < n; ++i) {
            if (a[i] == '1') {
                cout << "-1\n";
                return 0; 
            }
        }
        cout << "0\n";
        return 0;
    }

    int x = solve(a, b);
    reverse(all(a));
    reverse(all(b));
    int y = solve(a, b);
    cout << min(x, y) << endl;;


 
    return 0;
}

Measured memory_bytes: 384
function main(input) {
  const r = parseInt(input.trim(), 10)

  if (r >= 2800) {
    console.log('AGC')
  } else if (r >= 1200) {
    console.log('ARC')
  } else {
    console.log('ABC')
  }
}

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

Measured memory_bytes: 29488
#include <bits/stdc++.h>
#define REP(i,n) for(int i=0;i<n;i++)
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define SSTR( x ) static_cast< std::ostringstream & >( \
        ( std::ostringstream() << std::dec << x ) ).str()
#define ALL(s) (s).begin(), (s).end()
using namespace std;
typedef long long unsigned int llu;
typedef long long ll;


int main (){
  int n,q;
  while (cin >> n){
    int S[10000];

    REP(i,n){
      int s;
      cin >> s;
      S[i] = s;
    }

    cin >> q;
    int ans = 0;
    REP(i,q){
      int t;
      cin >> t;
      REP(j,n){
	if(S[j] == t){
	  ans++;
	  break;
	}
      }
    }

    cout << ans << endl;
  }

  return 0;
}



Measured memory_bytes: 3108
#Python

N = input()
a = map(int, raw_input().split())

b=[]
ans=0
sum=sum(a)

x=0
for i in range(N-1):
	x+=a[i]
	#print "x::"+str(x)
	if i==0:
		ans= abs( sum - x*2 )
	if ans>abs( sum - x*2 ):
		ans= abs( sum - x*2 )
	#print "ans::"+str(ans)

print ans


Measured memory_bytes: 18440
#include<bits/stdc++.h>
using namespace std;
#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define pb push_back
#define ll long long

void test_case()
{
    string s,t;
    cin>>s>>t;
    int n=s.size(),m=t.size();
    int i,j,dp[n+1][m+1];
    for(i=0;i<=n;i++)
    {
        for(j=0;j<=m;j++)
        {
            if(i==0 || j==0)
                dp[i][j]=0;
            else if(s[i-1]==t[j-1])
            {
                dp[i][j]=1+dp[i-1][j-1];
            }
            else
                dp[i][j]=max(dp[i][j-1] , dp[i-1][j]);
        }
    }
    i=n;j=m;
    string ans;
    while(i>0 && j>0)
    {
        if(s[i-1]==t[j-1])
        {
            ans+=s[i-1];
            i--;
            j--;
        }
        else if(dp[i][j-1]>dp[i-1][j])
        {
            j--;
        }
        else {
            i--;
        }
    }
    reverse(ans.begin(),ans.end());
    cout<<ans;
}

int main()
{
    fastio
//    int t;
//    cin>>t;
//    while(t--)
    test_case();
}


Measured memory_bytes: 35456
#include <iostream>
#include <algorithm>
#include <cstdio>

using namespace std;

int main(){
    long long w, h, x, y; cin >> w >> h >> x >> y;
    cout << (double)w*h/2 << " " << (x+x==w && y+y==h ? 1 : 0) << endl;
    return 0;
}


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

vector<vector<pair<int, int>>> edges;
int N;
int answer = 0;
vector<int> answerColors;

void dfs(int parentNode, int parentColor, int currentNode)
{
    int childColor = 1;
    for(auto nodePair: edges.at(currentNode))
    {
        int node = nodePair.first;
        int edgeIndex = nodePair.second;
        while(childColor == parentColor){
            childColor++;
        }
        answer = max(answer, childColor);
        answerColors.at(edgeIndex) = childColor;
        dfs(currentNode, childColor, node);
        childColor++;
    }
}

int main()
{
    cin >> N;
    edges = vector<vector<pair<int, int>>>(N, vector<pair<int, int>>(0));
    for(int i = 0; i < N - 1; i++)
    {
        int a, b;
        cin >> a >> b;
        a--;
        b--;

        edges.at(a).emplace_back(b, i);
    }
    answerColors = vector<int>(N - 1);
    dfs(-1, 0, 0);
    cout << answer << endl;
    for(int i = 0; i < N - 1; i++){
        cout << answerColors.at(i) << endl;
    }
    return 0;
}

Measured memory_bytes: 7424
#include <bits/stdc++.h>
#define F first
#define S second
#define sq(x) (x)*(x)
using namespace std;
typedef long long LL;
typedef pair<LL, LL> pii;
const LL INF = 0x3f3f3f3f3f3f3f3fLL;
const LL MOD = 1e9 + 7;
vector<LL> h, dp;
LL C;
LL a(int i) { return -2 * h[i]; }
LL b(int i) { return dp[i] + sq(h[i]); }
LL x(int i) { return h[i]; }
LL c(int i) { return sq(h[i]) + C; }
bool check(int X, int Y, int Z) {
    return (b(Z) - b(Y)) * (a(X) - a(Z)) <= (b(Z) - b(X)) * (a(Y) - a(Z));
}
void marmot0814() {
    int n; cin >> n >> C;
    h.resize(n);
    for (auto &v : h) cin >> v;
    dp.clear(); dp.resize(n, 0);
    // dp[i] = min{0<=j<i}(dp[j] + sq(h[i] - h[j]) + C)
    //       = min{0<=j<i}(dp[j] + sq(h[i]) + sq(h[j]) + C - 2 * h[i] * h[j]
    //       = min{0<=j<i}( -2*h[j] * h[i] + dp[j]+sq(h[j]) ) + sq(h[i])+C
    vector<int> dq{0};
    for (int i = 1 ; i < n ; i++) {
        int L = 0, R = dq.size();
        while (R - L > 2) {
            int M  = (R + L) >> 1;
            int MM = (R + M) >> 1;
            if (a(dq[M]) * x(i) + b(dq[M]) >= a(dq[MM]) * x(i) + b(dq[MM]))
                L = M;
            else
                R = MM;
        }
        L = dq[L], R = dq[R - 1];
        dp[i] = min(a(L) * x(i) + b(L), a(R) * x(i) + b(R)) + c(i);
        while (dq.size() >= 2 && check(dq[dq.size() - 2], dq[dq.size() - 1], i))
            dq.pop_back();
        dq.push_back(i);
    }
    cout << dp[n - 1] << '\n';
}
int main() {
    ios_base::sync_with_stdio(false); cin.tie(0);
    int t = 1, kase = 0; // cin >> t;
    while (t--) {
        // cout << "Case #" << ++kase << ":";
        marmot0814();
    }
}

Measured memory_bytes: 7328
use std::io;
use std::io::prelude::*;
use std::collections::HashMap;


fn main() {
    let sin = io::stdin();
    let mut l_iter = sin.lock().lines();
    
    let l = l_iter.next().unwrap().unwrap();
    let _n: usize = l.trim().parse().unwrap();

    let mut hash: HashMap<String, bool> = HashMap::new();

    for line in l_iter {
        let l1 = line.unwrap();
        let mut ws = l1.split_whitespace();
        let cmd = ws.next().unwrap().to_string();
        let val = ws.next().unwrap().to_string();

        match cmd.as_str() {
            "insert" => {
                hash.entry(val).or_insert(true);
            },
            "find" => {
                if let Some(_) = hash.get(&val) {
                    println!("yes");
                } else {
                    println!("no");
                };
            },
            _ => {;},
        }
    }
}



Measured memory_bytes: 37376
#!/usr/bin/env python3
import sys


def solve(A: int, B: int, C: int, D: int):
    s = max(A, C)
    e = min(B, D)
    print(max(e - s, 0))
    return


# Generated by 1.1.7.1 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word

    tokens = iterate_tokens()
    A = int(next(tokens))  # type: int
    B = int(next(tokens))  # type: int
    C = int(next(tokens))  # type: int
    D = int(next(tokens))  # type: int
    solve(A, B, C, D)


if __name__ == "__main__":
    main()


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

using namespace std;
int n,cnt;
string s;
vector<int> v;
int main(){
    ios_base::sync_with_stdio(0);cin.tie(nullptr);
    cin>>n>>s;
    for(int i=0; i<s.size(); i++) if(s[i]=='R') v.push_back(i+1);
    for(int i : v) if(i <= v.size()) cnt++;
    cout<<v.size()-cnt;
}


Measured memory_bytes: 4348
#include <bits/stdc++.h>
using namespace std;
int main(void){
    long long int i=0,j=0,c=0,n,k,m=99999999999,h[100000],a;
    string s;
    cin >> n >> k;
    for(i=0;i<n;i++)
    {
        cin >> h[i];
    }
    sort(h,h+n);
    for(i=0;i<=n-k;i++)
    {
        if(m>h[i+k-1]-h[i])
        {
            m=h[i+k-1]-h[i];
        }
    }
    cout << m << endl;
    return 0;

}


Measured memory_bytes: 4416
#include <cstdio>
#include <cstring>
#include <algorithm>
#define repu(i,x,y) for (int i=x; i<=y; ++i)
#define mid ((l+r)>>1)
using namespace std;

int n,tot,p[20100],id[20][20100],log_[20100],dfn[400100],low[400100],stk[400100],top,scc[400100],clk;
struct data
{
    int x,id;
    bool operator<(const data &t) const
    {
        return x<t.x;
    }
} a[20100];
struct edge
{
    int u,v;
    edge *nxt;
} pool[1000000],*tp=pool,*fst[400100],*bnd;

void addedge(int u,int v)
{
    *tp=(edge){u,v,fst[u]},fst[u]=tp++;
}

void add(int x,int l,int r)
{
    if (l>r)
        return;
    int t=p[x>n?x-n:x+n];
    if (l<=t && r>=t)
    {
        add(x,l,t-1),add(x,t+1,r);
        return;
    }
    t=log_[r-l+1];
    addedge(x,id[t][l]),addedge(x,id[t][r-(1<<t)+1]);
}

void dfs(int x)
{
    dfn[x]=low[x]=++clk,stk[++top]=x;
    for (edge *i=fst[x]; i; i=i->nxt)
    {
        if (!dfn[i->v])
            dfs(i->v);
        if (!scc[i->v])
            low[x]=min(low[x],low[i->v]);
    }
    if (dfn[x]==low[x])
        for (; stk[top+1]!=x; scc[stk[top--]]=x);
}

bool solve(int d)
{
    for (; tp>bnd; --tp,fst[tp->u]=tp->nxt);
    for (int i=1,l=1,r=1; i<=n*2; ++i)
    {
        for (; a[i].x-a[l].x>=d; ++l);
        for (; r<n*2 && a[r+1].x-a[i].x<d; ++r);
        add(a[i].id,l,i-1),add(a[i].id,i+1,r);
    }
    memset(dfn,0,sizeof(dfn));
    memset(scc,0,sizeof(scc));
    repu(i,1,tot)
        if (!dfn[i])
            dfs(i);
    repu(i,1,n)
        if (scc[i]==scc[i+n])
            return 0;
    return 1;
}

int main()
{
    scanf("%d",&n);
    repu(i,1,n)
    {
        int x,y;
        scanf("%d%d",&x,&y);
        a[i]=(data){x,i},a[i+n]=(data){y,i+n};
    }
    sort(a+1,a+1+n*2);
    repu(i,1,n*2)
        p[a[i].id]=i,id[0][i]=a[i].id>n?a[i].id-n:a[i].id+n;
    repu(i,2,n*2)
        log_[i]=log_[i>>1]+1;
    tot=n*2;
    repu(i,1,log_[n*2])
        repu(j,1,n*2-(1<<i)+1)
        {
            id[i][j]=++tot;
            addedge(id[i][j],id[i-1][j]);
            addedge(id[i][j],id[i-1][j+(1<<i-1)]);
        }
    bnd=tp;
    int l=1,r=1e9;
    while (l<r)
        solve(mid)?l=mid+1:r=mid;
    printf("%d\n",l-1);
    return 0;
}

Measured memory_bytes: 30848
#include <bits/stdc++.h>
#include <iostream>
#include <string>
#include <string.h>

using namespace std;

int main() {
  int a,b;
  cin >> a >> b;

  if((a+b) >= 10)
    cout << "error" << endl;
  else cout << a+b << endl;
}

Measured memory_bytes: 3600
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstring>
#include <vector>
#define rep(x, l, r) for(int x = l; x <= r; x++)
#define repd(x, r, l) for(int x = r; x >= l; x--)
#define clr(x, y) memset(x, y, sizeof(x))
#define all(x) x.begin(), x.end()
#define pb push_back
#define mp make_pair
#define MAXN 100005
#define fi first
#define se second
#define SZ(x) ((int)x.size())
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef pair<int, int> pii;
const int INF = 1 << 30;
const int p = 1000000009;
int lowbit(int x){ return x & (-x);}
int fast_power(int a, int b){ int x; for(x = 1; b; b >>= 1){ if(b & 1) x = 1ll * x * a % p; a = 1ll * a * a % p;} return x % p;}

bool flag[MAXN];
int sum[MAXN];

int main(){
	int n, m;
	scanf("%d%d", &n, &m);
	int ans1 = 0, ans2 = 0;
	rep(i, 1, m){
		int x;
		scanf("%d", &x);
		char st[5];
		scanf("%s", st);
		if(st[0] == 'A') flag[x] = 1;
		else if(!flag[x]) sum[x]++;
	}
	rep(i, 1, n)
		if(flag[i]){
			ans1++;
			ans2 += sum[i];
		}
	printf("%d %d\n", ans1, ans2);
    return 0;
}


Measured memory_bytes: 768
using System;

class Program
{
    static void Main(string[] args)
    {
        var n = int.Parse(Console.ReadLine());
        var d = Array.ConvertAll(Console.ReadLine().Split(), int.Parse);

        var array = new int[2005];
        for (int i = 0; i < d.Length; i++) array[d[i]]++;
        for (int i = 1; i < array.Length; i++) array[i] += array[i - 1];

        var ans = 0L;
        for (int i = 0; i < n - 1; i++)
        {
            for (int j = i + 1; j < n; j++)
            {
                var max = d[i] + d[j] - 1;
                var min = Math.Abs(d[i] - d[j]) + 1;
                ans += array[max] - array[min - 1];

                if (min <= d[i] && d[i] <= max) ans--;
                if (min <= d[j] && d[j] <= max) ans--;
            }
        }

        Console.WriteLine(ans / 3);
    }
}


Measured memory_bytes: 11204
#include <string.h>
#include <stdio.h>
#include <stdlib.h>
#include<math.h>
#define ll long long
long long min(long long a, long long b){
    if(a < b) return a;
    else return b;
}
long long max(long long a, long long b){
    if(a < b) return b;
    else return a;
}
int main(){
  int k,a,b;
  scanf("%d %d %d",&k,&a,&b);
  for(int i=a;i<=b;i++){
    if(i%k==0){
      printf("OK");
      return 0;
    }
  }
printf("NG");
  return 0;
}

Measured memory_bytes: 1736
import java.util.*;

public class Main{
    public static void main(String[] args){
        Scanner scan = new java.util.Scanner(System.in);
        String s = scan.next();
        char c = s.charAt(0);
        char out;
        switch(c){
            case 'a':
                out = 'b';
                System.out.println(out);
                break;
            case 'b':
                out = 'c';
                System.out.println(out);
                break;
            case 'c':
                out = 'd';
                System.out.println(out);
                break;
            case 'd':
                out = 'e';
                System.out.println(out);
                break;
            case 'e':
                out = 'f';
                System.out.println(out);
                break;
            case 'f':
                out = 'g';
                System.out.println(out);
                break;
            case 'g':
                out = 'h';
                System.out.println(out);
                break;
            case 'h':
                out = 'i';
                System.out.println(out);
                break;
            case 'j':
                out = 'k';
                System.out.println(out);
                break;
            case 'k':
                out = 'l';
                System.out.println(out);
                break;
            case 'l':
                out = 'm';
                System.out.println(out);
                break;
            case 'm':
                out = 'n';
                System.out.println(out);
                break;
            case 'n':
                out = 'o';
                System.out.println(out);
                break;
            case 'o':
                out = 'p';
                System.out.println(out);
                break;
            case 'p':
                out = 'q';
                System.out.println(out);
                break;
            case 'q':
                out = 'r';
                System.out.println(out);
                break;
            case 'r':
                out = 's';
                System.out.println(out);
                break;
            case 's':
                out = 't';
                System.out.println(out);
                break;
            case 't':
                out = 'u';
                System.out.println(out);
                break;
            case 'u':
                out = 'v';
                System.out.println(out);
                break;
            case 'v':
                out = 'w';
                System.out.println(out);
                break;
            case 'w':
                out = 'x';
                System.out.println(out);
                break;
            case 'x':
                out = 'y';
                System.out.println(out);
                break;
            case 'y':
                out = 'z';
                System.out.println(out);
                break;
        }
    }
}

Measured memory_bytes: 21716
#include <bits/stdc++.h>
#define dum(x) cout<<#x<<'='<<x<<endl
#define ll long long
using namespace std;

int main() {
  string s, t;
  cin >> s >> t;

  if (s.size() < t.size()) {
    cout << "UNRESTORABLE" << endl;
    return 0;
  }


  set<string> ans;
  for (int i = 0; i < s.size() - t.size() + 1; i++) {
    string st = s;
    string tmp = s.substr(i, t.size());
    bool flag = true;
    for (int j = 0; j < t.size(); j++) {
      if (tmp.at(j) == t.at(j) || tmp.at(j) == '?') {
        continue;
      }
        flag = false;
    }
    if (flag) {
      st.replace(i, t.size(), t);
      replace(st.begin(), st.end(), '?', 'a');
      ans.insert(st);
    }
  }

  if (ans.size() == 0) {
    cout << "UNRESTORABLE" << endl;
    return 0;
  } else {
    cout << *ans.begin() << endl;
    return 0;
  }

}


Measured memory_bytes: 256
long bit[3<<17],a,r,H,I;
n,h[2<<17],i,j;
main(n)
{
	for(scanf("%d",&n);i<n;)scanf("%d",h+i++);
	for(;~scanf("%d",&a);)
	{
		r=0;I=H=h[j++];
		for(;H;H-=H&-H)r=fmax(r,bit[H]);
		for(;I<3<<17;I+=I&-I)bit[I]=fmax(bit[I],a+r);
	}
	printf("%ld",bit[2<<17]);
}

Measured memory_bytes: 3968
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int x = sc.nextInt();
        int a = sc.nextInt();
        int b = sc.nextInt();
        if (a >= b) {
            System.out.println("delicious");
        } else if (a + x < b) {
            System.out.println("dangerous");
        } else {
            System.out.println("safe");
        }
    }

}


Measured memory_bytes: 21716
#include <bits/stdc++.h>
using namespace std;
#define int long long
using i64 = int64_t;
using vi = vector<i64>;
using vvi = vector<vi>;

int mergecount(vector<int> &a) {
  int count = 0;
  int n = a.size();
  if (n > 1) {
    vector<int> b(a.begin(), a.begin() + n/2);
    vector<int> c(a.begin() + n/2, a.end());
    count += mergecount(b);
    count += mergecount(c);
    for (int i = 0, j = 0, k = 0; i < n; ++i)
      if (k == c.size())       a[i] = b[j++];
      else if (j == b.size())  a[i] = c[k++];
      else if (b[j] <= c[k])   a[i] = b[j++];
      else                   { a[i] = c[k++]; count += n/2 - j; }
  }
  return count;
}

signed main() {
    string s;
    cin >> s;
    vector<int> a;
    for (char c : s) {
        if (c == 'B') {
            a.push_back(1);
        } else {
            a.push_back(0);
        }
    }
    cout << mergecount(a) << endl;
}

Measured memory_bytes: 5108
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll mod=1e9+7;
const int maxn=1e5+5;
const int maxm=5e2+5;
const int maxq=55;
const int INF=0x3f3f3f3f;
char s[maxn];
int main()
{
    while(~scanf("%s",s+1))
    {
        int len=strlen(s+1);
        int ans=0;
        for(int i=1,j=len-1;i<j;i++,j--)
        {
            if(s[i]!=s[j])
            {
                ans=-1;
                break;
            }
        }
        if(s[len]=='1'||s[1]=='0'||s[len-1]=='0') ans=-1;
        if(ans==-1)
        {
            puts("-1");
            continue;
        }
        int root=1,now=1;
        for(int i=1;i<=len/2;i++)
        {
            if(s[i]=='1')
            {
                printf("%d %d\n",root,++now);
                root=now;
            }
            else
                printf("%d %d\n",root,++now);
        }
        for(int i=len/2+1;i<len;i++)
        {
            printf("%d %d\n",root,++now);
        }
    }
}


Measured memory_bytes: 1536
package main
import "fmt"
func main() {
  var n,k int
  var m int64
  fmt.Scan(&n,&k)
  for b:=1;b<n+1;b++ {
    m += int64(n/b)*int64(max(0,b-k))+int64(max(0,n%b-k+1))
  }
  if k == 0 { m -= int64(n) }
  fmt.Println(m)
}
func max(n,m int) int {
  if n > m { return n }
  return m
}

Measured memory_bytes: 512
#include <iostream>

using namespace std;

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

    double sum = 0;
    double x;
    string u;

    for(int i=0;i<n;i++){
        cin >> x >> u;
        if (u == "JPY"){
            sum += x;
        }
        else{
            sum += 380000.0*x;
        }
    }
    cout << sum;
}

Measured memory_bytes: 256
#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 "cassert"
#include "ctime"

using namespace std;

constexpr long long int MOD = 1000000007;
//constexpr int MOD = 1000000007;
//constexpr int MOD = 998244353;
//constexpr long long int MOD = 998244353;
constexpr double EPS = 1e-12;

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


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

	set<pair<int, pair<int, int>>>st;
	cin >> N >> M >> K;
	cin >> T;
	long long int ans = N * M + M * K + N * K;
	ans <<= 1;
	while (T--) {
		int a, b, c;
		cin >> a >> b >> c;
		int num = 0;
		if (a + 1 == N || st.find({ a + 1,{b,c} }) != st.end())num++;
		if (a == 0 || st.find({ a - 1,{b,c} }) != st.end())num++;
		if (b + 1 == M || st.find({ a,{ b + 1,c } }) != st.end())num++;
		if (b == 0 || st.find({ a,{ b - 1,c } }) != st.end())num++;
		if (c + 1 == K || st.find({ a,{ b,c + 1 } }) != st.end())num++;
		if (c == 0 || st.find({ a,{ b,c - 1 } }) != st.end())num++;
		ans += 6 - num * 2;
		st.insert({ a,{b,c} });
	}
	cout << ans << endl;
}


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

#define PI 3.1415926535897932
#define MOD 1000000007
#define INF 1e9

#define REP(i, n) for(int i = 0; i < (n); i++)
#define REP1(i, n) for(int i = 1; i <= (n); i++)
#define ALL(v) (v).begin(), (v).end()
#define YES cout << "YES" << endl
#define Yes cout << "Yes" << endl
#define NO  cout << "NO"  << endl
#define No  cout << "No"  << endl

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef vector<vi> vvi;
typedef vector<string> vs;
typedef vector<bool> vb;


void solve()
{
    ll H; cin >> H;
    ll ans = 0;
    ll t = 0;
    while(H > 1)
    {
        ans += pow(2, t);
        t += 1;
        H /= 2;
    }
    ans += pow(2, t);
    cout << ans << endl;
}
    
int main() 
{
    cin.tie(nullptr);
    ios_base::sync_with_stdio(false);
    cout << fixed << setprecision(20);

    solve();

    return 0;
}

Measured memory_bytes: 512