akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef unsigned int uint;
typedef unsigned char uchar;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;

#define REP(i,x) for(int i=0;i<(int)(x);i++)
#define REPS(i,x) for(int i=1;i<=(int)(x);i++)
#define RREP(i,x) for(int i=((int)(x)-1);i>=0;i--)
#define RREPS(i,x) for(int i=((int)(x));i>0;i--)
#define FOR(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();i++)
#define RFOR(i,c) for(__typeof((c).rbegin())i=(c).rbegin();i!=(c).rend();i++)
#define ALL(container) (container).begin(), (container).end()
#define RALL(container) (container).rbegin(), (container).rend()
#define SZ(container) ((int)container.size())
#define mp(a,b) make_pair(a, b)
#define pb push_back
#define eb emplace_back
#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() );

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 (a>b) { a=b; return 1; } return 0; }
template<class T> ostream& operator<<(ostream &os, const vector<T> &t) {
os<<"["; FOR(it,t) {if(it!=t.begin()) os<<","; os<<*it;} os<<"]"; return os;
}
template<class T> ostream& operator<<(ostream &os, const set<T> &t) {
os<<"{"; FOR(it,t) {if(it!=t.begin()) os<<","; os<<*it;} os<<"}"; return os;
}
template<class S, class T> ostream& operator<<(ostream &os, const pair<S,T> &t) { return os<<"("<<t.first<<","<<t.second<<")";}
template<class S, class T> pair<S,T> operator+(const pair<S,T> &s, const pair<S,T> &t){ return pair<S,T>(s.first+t.first, s.second+t.second);}
template<class S, class T> pair<S,T> operator-(const pair<S,T> &s, const pair<S,T> &t){ return pair<S,T>(s.first-t.first, s.second-t.second);}

const int INF = 1<<28;
const double EPS = 1e-8;
const int MOD = 1000000007;


int T, n, m;

int main(int argc, char *argv[]){
	ios::sync_with_stdio(false);
	cin >> n;
	int ans = 1;
	vi d(1);
	cin >> d[0];
	REP(i, n - 1){
		int x;
		cin >> x;
		if(x == d.back()) continue;
		if(d.size() == 1) d.pb(x);
		else if((d[0] < d[1]) == (d[1] < x)) d.back() = x;
		else {
			ans ++;
			d.clear();
			d.pb(x);
		}
	}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#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 vi vector<int>
#define vi2 vector<vector<int>>
#define vl vector<long long>
#define vl2 vector<vector<long long>>

template <class T> T maxAny(T a, T b){
    if(a > b) return a;
    else return b;
}

template <class T> T minAny(T a, T b){
    if(a > b) return b;
    else return a;
}

int main(){
    int n, m, p, ans = 0, pen = 0;
    cin >> n >> m;
    vi a(n,0), wa(n,0);
    rep(i, m) {
        string st;
        cin >> p >> st;
        if(st=="AC"&&!a[p-1]){
            ans++;
            pen += wa[p-1];
            a[p-1] = 1;
        }
        else if(st=="WA"&&!a[p-1]){
            wa[p-1]++;
        }
    }
    cout << ans << " " << pen << endl;
}

Measured memory_bytes: 1024
#include "vector"
#include "set"
#include "map"
#include "unordered_map"
#include "string"
#include "iostream"
#include "algorithm"
#include "queue"

using namespace std;

#define ll long long
#define INF 2e9
#define MOD 1000000007

typedef vector<int> vi;
typedef pair<int, int> pii;


template<typename T>
ostream& operator<<(ostream& os, const vector<T>& v) {
    bool first = true;
    for (const auto& x : v) {
        if (!first) {
            os << " ";
        }
        first = false;
        os << x;
    }
    return os;
}

template<typename T>
istream& operator>>(istream& is, vector<T>& v) {
    for (auto& elem : v) {
        is >> elem;
    }
    return is;
}

ll pw(ll x, int n) {
    if (n == 1) {
        return x;
    }
    if (n%2 == 0) {
        return pw((x*x) % MOD, n/2);
    }
    return (pw(x, n-1) * x) % MOD;
}

int get_min(map<int, set<int> >& m) {
    return m.begin()->first;
}

int get_min(set<int>& m) {
    return *m.begin();
}

int get_max(map<int, set<int> >& m) {
    auto it = m.end();
    it--;
    return it->first;
}

int get_max(set<int>& m) {
    auto it = m.end();
    it--;
    return *it;
}

void solve() {
    int x, y, na, nb, nc;
    cin >> x >> y >> na >> nb >> nc;

    vector<pii> a(na+nb+nc);

    for (int i=0; i<na; i++) {
        int x;
        cin >> x;
        a[i].first = x;
        a[i].second = 1;
    }
    for (int i=0; i<nb; i++) {
        int x;
        cin >> x;
        a[na+i].first = x;
        a[na+i].second = 2;
    }
    for (int i=0; i<nc; i++) {
        int x;
        cin >> x;
        a[na+nb+i].first = x;
        a[na+nb+i].second = 3;
    }

    sort(a.begin(), a.end());

    ll ans = 0;
    ll aa = 0;
    ll b = 0;
    ll c = 0;
    for (int i=a.size()-1; i>=0; i--) {
        //cout << a[i].first << ' ' << a[i].second << endl;
        if (a[i].second == 1 && aa < x) {
            aa++;
            ans+=a[i].first;
        } else if (a[i].second == 2 && b < y) {
            b++;
            ans += a[i].first;
        } else if (a[i].second == 3) {
            c++;
            ans += a[i].first;
        }

        if (aa+b+c == x+y) {
            break;
        }
    }

    cout << ans;
}

int main() {
    ios::sync_with_stdio(false), cin.tie(nullptr), cout.tie(nullptr);

    if (0) {
        int tests;
        cin >> tests;
        while (tests--) {
            solve();
            cout << endl;
        }
    } else {
        solve();
        cout << endl;
    }

    return 0;
}

Measured memory_bytes: 2560
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
//#define P pair<ll,ll>
#define FOR(I,A,B) for(ll I = ll(A); I < ll(B); ++I)
#define FORR(I,A,B) for(ll I = ll((B)-1); I >= ll(A); --I)
#define TO(x,t,f) ((x)?(t):(f))
#define SORT(x) (sort(x.begin(),x.end())) // 0 2 2 3 4 5 8 9
#define POSL(x,v) (lower_bound(x.begin(),x.end(),v)-x.begin()) //xi>=v  x is sorted
#define POSU(x,v) (upper_bound(x.begin(),x.end(),v)-x.begin()) //xi>v  x is sorted
#define NUM(x,v) (POSU(x,v)-POSL(x,v))  //x is sorted
#define REV(x) (reverse(x.begin(),x.end())) //reverse
ll gcd(ll a,ll b){if(a%b==0)return b;return gcd(b,a%b);}
ll lcm(ll a,ll b){ll c=gcd(a,b);return ((a/c)*(b/c)*c);}
#define NEXTP(x) next_permutation(x.begin(),x.end())
const ll INF=ll(1e18)+ll(7);
const ll MOD=1000000007LL;
#define out(a) cout<<fixed<<setprecision((a))



int main(){
	int h,w,x,y;
	cin >> h >> w >> x >> y;
	if( (h*w)%2 && (x+y)%2 ){
		cout << "No" << endl;
	}else{
		cout << "Yes" << endl;
	}
}



Measured memory_bytes: 3108
number = int(input())
date,remaining = map(int,input().split())
A = [int(input()) for i in range(number)]
consume = 0

for i in range(number):
    d = A[i]
    date_spot = 1
    count = 0
    while True:
        if date_spot > date:
            consume += count
            break
        count += 1
        date_spot += d

print(consume+remaining)


Measured memory_bytes: 3060
#include <stdio.h>
#include <string.h>
 
int main(void) {
    char str[201], tmp[201];
    int m, h, len;
    int i;
     
    while (scanf("%s", str), strcmp(str, "-")) {
        scanf("%d", &m);
         
        len = strlen(str);
         
        while (m--) {
            scanf("%d", &h);
             
            strcpy(tmp, &str[h]);
            strncat(tmp, str, h);
            tmp[len] = '\0';
             
            strcpy(str, tmp);
        }
         
        puts(str);
    }
    return 0;
}


Measured memory_bytes: 2044
#include<iostream>
#include<algorithm>
#include<vector>
#include<queue>
#include<map>
#include<utility>
#include<set>
#include<stack>
#include<list>
#include<deque>
#include<bitset>
#include<iomanip>
#include<cstring>
#include<sstream>
#include<cstdio>
#include<cstdlib>
#include<climits>
#include<cmath>
#include<cctype>


#define pb push_back
#define mp make_pair
#define rep(i,a,b) for(int i=a;i<=b;i++)
#define ren(i,a,b) for(int i=a;i>=b;i--)
#define ff first
#define ss second
#define pll pair<long long int,long long int>
#define pii pair<int,int>
#define vll vector<long long int>
#define vii vector<int>
#define gi(n) scanf("%d",&n)
#define gll(n) scanf("%lld",&n)
#define gstr(n) scanf("%s",n)
#define gl(n) cin >> n
#define oi(n) printf("%d",n)
#define oll(n) printf("%lld",n)
#define ostr(n) printf("%s",n)
#define ol(n) cout << n
#define os cout<<" "
#define on cout<<"\n"
#define o2(a,b) cout<<a<<" "<<b
#define all(n) n.begin(),n.end()
#define present(s,x) (s.find(x) != s.end())
#define cpresent(s,x) (find(all(s),x) != s.end())
#define tr(container, it) for(__typeof(container.begin()) it = container.begin(); it != container.end(); it++)
using namespace std;

typedef unsigned long long int ull;
typedef long long int ll;
typedef long double ld;
typedef vector<vector<ll> > mat;

vii v[100005];
ll ans=0,col[100005],vis[100005],f=1;

void dfs(int at,int c)
{
	vis[at]=1;
	col[at]=c;
	tr(v[at],it)
	{
		int to=*it;
		if(vis[to]==0)
		{
			dfs(to,1-c);
		}
		else
		{
			if(vis[to]==1)
			{
				if(col[at]==col[to])f=0;
			}
		}
	}
}

int main()
{ios_base::sync_with_stdio(false);
ll n,m;
cin>>n>>m;
ll ans=0;
rep(i,0,m-1)
{
	int x,y;
	cin>>x>>y;
	v[x].pb(y);
	v[y].pb(x);
}

dfs(1,0);

if(f)
{
	ll c1=0,c2=0;
	rep(i,1,n)c1+=col[i];
	c2=n-c1;
	ans=(n*(n-1))/2-m-(c1*(c1-1))/2-(c2*(c2-1))/2;
	ol(ans);
}
else
{
	ans=(n*(n-1))/2-m;
	ol(ans);
}
return 0;
}



Measured memory_bytes: 8064
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#define NUM 100


int main(void){
	int genkin;
	int i=0, j=0;
	int aprice,bprice;

	scanf("%d%d%d",&genkin,&aprice,&bprice);
	
	genkin -= aprice;

	do {
		genkin -= bprice;
	} while (genkin >= 0);
	

	printf("%d\n", genkin+bprice);

	return 0;
}

Measured memory_bytes: 128
#![allow(unused_imports)]
#![allow(non_snake_case)]
use std::cmp::*;
use std::collections::*;
use std::io::Write;

#[allow(unused_macros)]
macro_rules! debug {
    ($($e:expr),*) => {
        #[cfg(debug_assertions)]
        $({
            let (e, mut err) = (stringify!($e), std::io::stderr());
            writeln!(err, "{} = {:?}", e, $e).unwrap()
        })*
    };
}

fn make_tree(
    cur_idx: usize,
    parent_idx: usize,
    edges: &Vec<Vec<usize>>,
    tree: &mut Vec<Vec<usize>>,
    parent_dict: &mut HashMap<usize, usize>,
) {
    for child_idx in edges[cur_idx].iter() {
        if *child_idx == parent_idx {
            continue;
        }
        tree[cur_idx].push(*child_idx);
        parent_dict.insert(*child_idx, cur_idx);
        make_tree(*child_idx, cur_idx, edges, tree, parent_dict);
    }
}

fn topological_dfs(cur_idx: usize, tree: &Vec<Vec<usize>>, result: &mut Vec<usize>) {
    for child_idx in tree[cur_idx].iter() {
        result.push(*child_idx);
        topological_dfs(*child_idx, tree, result);
    }
}

fn main() {
    let n = read::<usize>();
    let mut edges: Vec<Vec<usize>> = vec![Vec::new(); 2 * (n - 1)];
    for _ in 0..n - 1 {
        let v = read_vec::<usize>();
        let (a, b) = (v[0] - 1, v[1] - 1);
        edges[a].push(b);
        edges[b].push(a);
    }

    let mut tree: Vec<Vec<usize>> = vec![Vec::new(); n];
    let mut parent_dict: HashMap<usize, usize> = HashMap::new();
    // 0 is root
    make_tree(0, n, &edges, &mut tree, &mut parent_dict);
    let mut topological_sorted_indexes = vec![0];
    topological_dfs(0, &tree, &mut topological_sorted_indexes);

    let mut is_odd = vec![true; n];
    for &ti in topological_sorted_indexes.iter().rev() {
        for &ci in tree[ti].iter() {
            is_odd[ti] ^= is_odd[ci];
        }
    }

    let mut from_parent = vec![false; n];
    for &ti in topological_sorted_indexes.iter() {
        let mut from_grand_parent = false;
        if ti != 0 {
            from_grand_parent = from_parent[ti];
        }
        for &ci in tree[ti].iter() {
            from_parent[ci] = (is_odd[ti] != is_odd[ci]) ^ from_grand_parent;
        }
    }
    debug!(is_odd);
    debug!(from_parent);

    for ti in 0..n {
        let mut odd_count = 0;
        for &ci in tree[ti].iter() {
            if is_odd[ci] {
                odd_count += 1;
            }
        }
        if from_parent[ti] {
            odd_count += 1;
        }
        if odd_count >= 2 {
            debug!(ti);
            println!("First");
            return;
        }
    }
    println!("Second");
}

fn read<T: std::str::FromStr>() -> T {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim().parse().ok().unwrap()
}

fn read_vec<T: std::str::FromStr>() -> Vec<T> {
    read::<String>()
        .split_whitespace()
        .map(|e| e.parse().ok().unwrap())
        .collect()
}


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

struct prime_num{
    int number;
    bool if_prime_num;
};

vector<prime_num> prime_nums;

long dp[int(2e5)];

long choose(int now){
    if(dp[now] != -1){
        return dp[now];
    }else if(now >= int(prime_nums.size()) - 1){
        return dp[now] = 1;
    }else if(!prime_nums[now].if_prime_num && prime_nums[now].number < prime_nums[now + 1].number){
        return dp[now] = choose(now + 1);
    }else if(!prime_nums[now].if_prime_num){
        return dp[now] = 0;
    }else if(!prime_nums[now + 1].if_prime_num && prime_nums[now].number < prime_nums[now + 1].number){
        return dp[now] = choose(now + 1);
    }else if(!prime_nums[now + 1].if_prime_num){
        return dp[now] = 0;
    }else if(now == int(prime_nums.size()) - 2 && prime_nums[now].number < prime_nums[now + 1].number){
        return dp[now] = 2;
    }else if(now == int(prime_nums.size()) - 2){
        return dp[now] = 1;
    }else if(prime_nums[now].number < prime_nums[now + 1].number && prime_nums[now].number < prime_nums[now + 2].number){
        return dp[now] = (choose(now + 1) + choose(now + 2)) % long(1e9 + 7);
    }else if(prime_nums[now].number < prime_nums[now + 1].number){
        return dp[now] = choose(now + 1);
    }else if(prime_nums[now].number < prime_nums[now + 2].number){
        return dp[now] = choose(now + 2);
    }else{
        return dp[now] = 0;
    }
}

int main(){
    int N;
    cin >> N;
    int if_prime[int(2e6)];
    fill(if_prime, if_prime + int(2e6), -1);
    if_prime[0] = 0;
    if_prime[1] = 0;
    for(int i = 2; i * i <= int(2e6); i++){
        if(if_prime[i] == -1){
            if_prime[i] = 1;
            for(int j = i * 2; j < int(2e6); j += i){
                if_prime[j] = 0;
            }
        }
    }
    int nums[N];
    for(int i = 0; i < N; i++){
        cin >> nums[i];
    }
    if(!if_prime[nums[0]]){
        cout << 0 << endl;
        return 0;
    }
    prime_nums.push_back({nums[0], true});
    for(int i = 1; i < N; i++){
        if(!if_prime[nums[i - 1]] && !if_prime[nums[i]]){
            cout << 0 << endl;
            return 0;
        }else if(!if_prime[nums[i]] && prime_nums.empty()){
            cout << 0 << endl;
            return 0;
        }else if(!if_prime[nums[i]]){
            prime_num insert_item = {prime_nums.back().number, false};
            prime_nums.pop_back();
            prime_nums.push_back(insert_item);
        }else{
            prime_nums.push_back({nums[i], true});
        }
    }
    fill(dp, dp + int(2e5), -1);
    cout << choose(0) << endl;
}



Measured memory_bytes: 15652
#include <stdio.h>
#define N 10

int main(void){
 int i,data[3],t;
 for(i=0;i<3;i++) data[i] = 0;
 for(i=0;i<N;i++){
  scanf("%d",&t);
  if(t>data[0]){
   data[2] = data[1];
   data[1] = data[0];
   data[0] = t;
  }
  else if(t>data[1]){
   data[2] = data[1];
   data[1] = t;
  }
  else if(t>data[2]) data[2] = t;
 }
 for(i=0;i<3;i++) printf("%d\n",data[i]);
 return 0;
}

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

using namespace std;

#define MOD 1000000007
#define N 100005
#define M 30
#define ll long long 
#define ld long double
#define pb push_back
#define ff first
#define ss second

ld a[N];

int main(){
	ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
	#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
	#endif
	int n, i; cin>>n;
	for(i=0; i<n; i++){
		cin>>a[i];
	}
	sort(a, a+n);
	ld ans = 1;
	ll res = 1;
	for(i=0; i<n; i++){
		ans = ans * sqrt(a[i]);
		if(ans > 1e9){
			cout<<"-1";
			return 0;
		}
		res = res * a[i];
	}
	cout<<res;
	return 0;
}

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

int main()
{

    //freopen("input.txt", "r", stdin);

    string s;
    int k;
    cin >> s >> k;

    int n = (int)s.size();
    vector<string> suff;
    for (int i = 0; i < n; ++i)
        suff.push_back(s.substr(i, n - i));

    sort(suff.begin(), suff.end());

    if ((int)suff[0].size() >= k)
    {
        cout << suff[0].substr(0, k);
        return 0;
    }
    else
        k -= (int)suff[0].size();

    for (int i = 1, ind; i < n; ++i)
    {
        ind = 0;
        while(ind < min((int)suff[i].size(), (int)suff[i - 1].size()) && suff[i][ind] == suff[i - 1][ind])
            ++ind;
        if (ind == (int)suff[i].size()) continue;
        if ((int)suff[i].size() - ind >= k)
        {
            cout << suff[i].substr(0, ind + k);
            return 0;
        }
        else
            k -= (int)suff[i].size() - ind;
    }
}


Measured memory_bytes: 16128
def resolve():
    import sys
    input = sys.stdin.readline
    n, m = map(int, input().split())
    if m == 0:
        print("{} {}".format(0, 0))
        exit()

    a = list(input().split() for _ in range(m))
    flag = [[0] * n for i in range(2)]
    miss = 0
    correct = 0
    for i in range(m):
        if flag[0][int(a[i][0]) - 1] == 0:
            if a[i][1] == "WA":
                flag[1][int(a[i][0]) - 1] += 1
            elif a[i][1] == "AC":
                correct += 1
                miss += flag[1][int(a[i][0]) - 1]
                flag[0][int(a[i][0]) - 1] = 1
    print("{} {}".format(correct, miss))
resolve()

Measured memory_bytes: 63464
#include <iostream>
#include <vector>
#include <cmath>

int main()
{
    long long N;
    std::cin >> N;
    long long sqr = std::sqrt(N);
    for (long long i=sqr+1; i>0; --i) {
        if (N % i == 0) {
            long long x = i;
            long long y = N / x;
            std::cout << (x-1)+(y-1) << std::endl;
            break;
        }
    }
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
int main() {
  set<char> s;
  int n;
  cin >> n;
  rep(i,n)
  {
    char c;
    cin >> c;
    s.insert(c);
  }
  cout << (s.size() == 4 ? "Four" : "Three");
}


Measured memory_bytes: 256
import java.util.*;

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

        System.out.println((a+b)*h/2);
    }

    public static void printArray(int[] array){
        for(int i=0; i<array.length; i++){
            if(i == array.length){
                System.out.println(array[i]);
            } else {
                System.out.print(String.format("%d ", array[i]));
            }
        }
    }
}


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


int main(){
	cin.tie(0);
   	ios::sync_with_stdio(false);
	
	ll N;
	cin>>N;
    ll a,b;
    vector<deque<ll>> dq(N);
    rep(i,N-1){
        cin>>a>>b;
        --a;
        --b;
        dq[a].push_back(b);
        dq[b].push_back(a);
    }
    vector<ll> c_ar(N,-1);
    deque<ll> q,next;
    q.push_back(0);
    next.push_back(1);
    c_ar[0] = 0;
    ll n_1 = 0;
    ll c;
    while(!q.empty()){
        a = q.front();q.pop_front();
        if(c_ar[a]==0){
            c = 1;
        }else{
            c = 0;
        }
        for(auto v : dq[a]){
            if(c_ar[v]== -1){
                c_ar[v] =c;
                q.push_back(v);
                if(c==1) ++n_1;
            }
        }
    }
    // rep(i,N){
    //     cout<<c_ar[i]<<" ";
    // }
    // cout<<n_1;
    // cout<<"\n";

    //塗り終わったはず
    vector<ll> ans(N);
    deque<ll> p1,p2,p0;
    rep(i,N){
        if((i+1)%3==1){
            p1.push_back(i+1);
        }else if((i+1)%3==2){
            p2.push_back(i+1);
        }else{
            p0.push_back(i+1);
        }
    }

    ll tmp_ans;
    if(n_1 <= N/3){
        rep(i,N){
            if(c_ar[i] ==1){
                ans[i] = p0.front();
                p0.pop_front();
            }else{
                if(!p1.empty()){
                    ans[i] = p1.front();
                    p1.pop_front();
                }else if(!p2.empty()){
                    ans[i] = p2.front();
                    p2.pop_front();
                }else{
                    ans[i] = p0.front();
                    p0.pop_front();  
                }
            }
        }

    }else if(N-n_1<=N/3){
        rep(i,N){
            if(c_ar[i] !=1){
                ans[i] = p0.front();
                p0.pop_front();
            }else{
                if(!p1.empty()){
                    ans[i] = p1.front();
                    p1.pop_front();
                }else if(!p2.empty()){
                    ans[i] = p2.front();
                    p2.pop_front();
                }else{
                    ans[i] = p0.front();
                    p0.pop_front();  
                }
            }
        }
    }else{
        rep(i,N){
            if(c_ar[i] ==1){
                if(!p2.empty()){
                    ans[i] = p2.front();
                    p2.pop_front();
                }else{
                    ans[i] = p0.front();
                    p0.pop_front();  
                }
            }else{
                if(!p1.empty()){
                    ans[i] = p1.front();
                    p1.pop_front();
                }else{
                    ans[i] = p0.front();
                    p0.pop_front();  
                }
            }
        }
    }
    rep(i,N-1){
        cout<<ans[i]<<" ";
    }
    cout<<ans[N-1]<<"\n";
	return 0;
}

Measured memory_bytes: 140800
from collections import defaultdict, deque, Counter
from heapq import heappush, heappop
from itertools import permutations, accumulate, combinations
from math import sqrt, ceil, floor
from bisect import bisect_left, bisect_right
from copy import deepcopy
from operator import itemgetter
from fractions import gcd
import sys
def I(): return int(input())  # '123' -> 123
def Is(): return map(int, input().split())  # '123 456' -> 123, 456
def LI(): return list(map(int, input().split()))  # '123 456' -> [123, 456]
def TI(): return tuple(map(int, input().split()))  # '123 456' -> (123, 456)
def IR(n): return [I() for _ in range(n)]
def LIR(n): return [LI() for _ in range(n)]
def TIR(n): return [TI() for _ in range(n)]
def S(): return input()
def Ss(): return input().split()  # 'aa bb' -> 'aa','bb' or ['aa','bb']
def LS(): return list(input())  # 'abc123' -> ['a','b','c','1','2','3']
def SR(n): return [S() for _ in range(n)]
def SsR(n): return [Ss() for _ in range(n)]
def LSR(n): return [LS() for _ in range(n)]
sys.setrecursionlimit(1000000)
MOD = 1000000007
INF = float('inf')

N, K = Is()

ans = 0
for i in range(K, N+2):
    minsum = int((0+i-1)*i/2)
    maxsum = int((N-i+1+N)*i/2)
    ans += maxsum - minsum + 1

print(ans % MOD)


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

int main(){
  string S;
  cin>>S;
  for(int i=S.size()-2;i>0;i-=2){
    bool bo=false;
    for(int j=0;j<i/2;j++)
      if(S[j]!=S[j+i/2]){
        bo=true;
        break;
      }
    if(bo)
      continue;
    cout<<i<<endl;
    return 0;
  }
}

Measured memory_bytes: 256
#include <cstdio>
#include <algorithm>
int main() {
	int n,x;scanf("%d%d",&n,&x);
	int a[100];for(int i=0;i<n;++i) scanf("%d",&a[i]);
	std::sort(a,a+n);int i;
	for(i=0;i<n&&x>=a[i];++i) x-=a[i];if(i==n&&x) --i;
	printf("%d\n",i);
	return 0;
}


Measured memory_bytes: 128
#include<bits/stdc++.h>
using namespace std;
#define vi vector<int>
#define ff first
#define ss second
#define file_se_input  freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout);
#define pp long long int
#define setbits(x)      __builtin_popcountll(x)
#define zrobits(x)      __builtin_ctzll(x)
#define pb push_back
#define mp make_pair
#define pi 3.141592653589793238
#define eb emplace_back
#define rep(i,a,b) for (int i = a; i <= b; i++)
#define zip(i,a,b) for(int i=a;i<b;i++)
#define ll unsigned long long int
#define test long int t;cin>>t; while(t--)
#define um unordered_map
#define en '\n'
#define us unordered_set
#define mm 1000000007

bool check_prime(long long n)
{
	int flag = 0;
	for (long long i = 2; i * i <= n; i++)
	{
		if (n % i == 0)
		{
			flag = 1;
			break;
		}
	}
	if (n == 1)
		return false;
	else if (flag == 0 || n == 2 || n == 3)
	{
		return true;
	}
	else
	{
		return false;
	}

}

int binaryExponentiation(int x, int n) //function to calculate x raise to power n
{
	int result = 1;
	while (n > 0)
	{
		if (n % 2 == 1)
			result = result * x;
		x = x * x;
		n = n / 2;
	}
	return result;
}

int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(0);
#ifndef ONLINE_JUDGE
	if (fopen("input.txt", "r"))
	{
		freopen ("input.txt" , "r" , stdin);
		freopen ("output.txt" , "w" , stdout);
	}
#endif
	//_______________________________-code starts-______________________________________________________________________________

	int k, n;
	cin >> k >> n;
	int a[n];
	zip(i, 0, n)
	{
		cin >> a[i];
	}
	ll ans = 0;
	zip(i, 0, n )
	{
		int x;
		if (i < n - 1)
		{
			x = abs(a[i] - a[i + 1]);
		}
		else if (i == n - 1)
		{
			x = abs(k + a[0] - a[i] );
			//cout << x << en;
		}
		if (x >= ans)
		{
			ans = x;
		}
	}
	//cout << ans << en;
	cout << (k - ans) << en;
	return 0;

}


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

int main() {
    string a, b, c;
    cin >> a >> b >> c;
    string ans;
    ans += (char)(a[0] - 'a' + 'A');
    ans += (char)(b[0] - 'a' + 'A');
    ans += (char)(c[0] - 'a' + 'A');
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
import static java.lang.Math.*;
import static java.util.Arrays.*;
import java.util.*;
import java.io.*;

public class Main {
	public static void main(String[] args) {
		try {
			System.setIn( new FileInputStream("src/aoj0021/aoj0021.in"));	
			System.setOut( new PrintStream( new FileOutputStream("src/aoj0021/result.txt")));
		} catch (FileNotFoundException e) {
		}
		new Main().run();
	}

	void run() {
		Scanner sc = new Scanner(System.in);
		for(int N = sc.nextInt(); N > 0; N--) {
			P a = new P(sc.nextDouble(), sc.nextDouble());
			P b = new P(sc.nextDouble(), sc.nextDouble());
			P c = new P(sc.nextDouble(), sc.nextDouble());
			P d = new P(sc.nextDouble(), sc.nextDouble());
			
			boolean parallel = abs(b.sub(a).cross(c.sub(d))) < EPS;
			System.out.println(parallel ? "YES" : "NO");
		}
	}
	double EPS = 1e-8;
	class P implements Comparable<P> {
		double x, y;
		P(double x, double y) {
			this.x = x;
			this.y = y;
		}
		P sub(P p) {
			return new P(x - p.x, y - p.y);
		}
		double dot(P p) {
			return x * p.x + y * p.y;
		}
		double cross(P p) {
			return x * p.y - y * p.x;
		}
		double abs() {
			return hypot(x, y);
		}
		public int compareTo(P o) {
			if (x != o.x) return Double.compare(x, o.x);
			return Double.compare(y, o.y);
		}
	}
}

Measured memory_bytes: 12000
import sys
def LI(): return [int(x) for x in sys.stdin.readline().split()]
def II(): return int(sys.stdin.readline())
def LS(): return sys.stdin.readline().split()
sys.setrecursionlimit(10**7)
INF = 10 ** 18
MOD = 10 ** 9 + 7
def LI_(): return [int(x) - 1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def SI(): return input()
YN = lambda b: print('YES') if b else print('NO')
yn = lambda b: print('Yes') if b else print('No')

def main():
    N, K = LI()
    S = SI().strip()

    searching = 1
    count = [0]
    head = 0
    for i in range(N):
        if int(S[i]) == searching:
            count[head] += 1
        else:
            searching = (searching+1)%2
            head += 1
            count.append(1)
    if len(count)//2 <= K:
        print(N)
        sys.exit()

    count.append(0)

    current_sum = sum(count[0:2*K+1])
    max_length = current_sum
    try:
        for k in range(1, N):
            if 2*k+2*K > len(count): break
            current_sum = current_sum - count[2*k-2] - count[2*k-1] + count[2*k+2*K-1] + count[2*k+2*K]
            max_length = max(current_sum, max_length)
    except:
        pass
    print(max_length)

main()

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

def func1(k,l):
    if k>l:
        return l
    else:
        return k

def func(x):
    if (x[2]>x[1]) or (x[0]>x[3]):
        return 0
    else:
        if x[0]>x[2]:
            return (func1(x[1],x[3])-x[0])
        else:
            return (func1(x[1],x[3])-x[2])

print(func(n))

Measured memory_bytes: 3064
N = int(input())
array = list(map(int, input().split()))
array.sort()
sum_1 = 0
sum_2 = 0

for i in range(N):
    if i % 2 == 0:
        sum_1 += array[-1]
        array.pop(-1)
        
    else:
        sum_2 += array[-1]
        array.pop(-1)
print(sum_1 - sum_2)


Measured memory_bytes: 9116
/*  ex7_3 Grid Compression
    pandacodeb  */

#include <stdio.h>
#include <stdlib.h>

int main(void){
    int row, col;
    int i, j;

    //サイズの入力
    scanf("%d %d", &row, &col);
    char** table;
    int* delRow; int* delCol;

    //マス目の
    table = (char**) calloc(row, sizeof(char*));
    if (table == NULL)
        exit(1);
    for(i = 0; i < row; i++){
        table[i] = (char*) calloc(col, sizeof(char));
        if (table[i] == NULL)
            exit(1);
    }
    for (i = 0; i < row; i++){
        for (j = 0; j < col; j++){
            scanf(" %c", &table[i][j]);
        }
    }
    
    //行の状態を保存する配列 (出力する -> 0, しない -> 1)
    delRow = (int*) calloc(row, sizeof(int));
    if (delRow == NULL)
        exit(1);
    for (i = 0; i < row; i++)
        delRow[i] = 0;

    //列の状態を保存する配列 (出力する -> 0, しない -> 1)
    delCol = (int*) calloc(col, sizeof(int));
    if (delCol == NULL)
        exit(1);
    for (i = 0; i < col; i++)
        delCol[i] = 0;

    //白いマスしかないの行を探す
    for (i = 0; i < row; i++){
        for (j = 0; j < col; j++){
            if (table[i][j] == '#')
                break;
            else if (j == col - 1)
                delRow[i] = 1;
        }
    }
    //白いマスしかないの列を探す
    for (j = 0; j < col; j++){
        for (i = 0; i < row; i++){
            if (table[i][j] == '#')
                break;
            else if (i == row - 1)
                delCol[j] = 1;
        }
    }

    //出力
    for (i = 0; i < row; i++){
        if (delRow[i] == 1)
            continue;
        for (j = 0; j < col; j++){
            if (delCol[j] == 1)
                continue;
            
            printf("%c", table[i][j]);
        }
        printf("\n");
    }

    //配列の開放
    for (i = 0; i < row; i++)
        free(table[i]);
    free(table);
    free(delRow);
    free(delCol);
    return 0;
}

Measured memory_bytes: 1628
N, K = map(int, input().split())
A = list(map(int, input().split()))
import fractions
import functools
gcd = functools.reduce(fractions.gcd, A)
A_max = max(A)
if (A_max >= K and K % gcd == 0):
    print('POSSIBLE')
else:
    print('IMPOSSIBLE')

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

#define llint long long int
#define pb push_back

using namespace std;

int main(){
  int n;
  cin >> n;
  int a;
  int mx = 0;
  int ans = 0;
  for(int i = 0; i < n; i++){
    cin >> a;
    ans += a;
    if(a > mx)
      mx = a;
  }
  ans -= mx/2;
  cout << ans;
  return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define fi first
#define se second
#define pb push_back
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
#define srep(i,s,t) for (int i = s; i < t; ++i)
#define rng(a) a.begin(),a.end()
#define rrng(a) a.rbegin(),a.rend()
#define uni(x) x.erase(unique(rng(x)),x.end())
#define PQ(T) priority_queue<T,v(T),greater<T> >
#define dup(x,y) (((x)+(y)-1)/(y))
#define v(T) vector<T>
#define vv(T) v(v(T))
using ll = int64_t;
using ull = uint64_t;
using uint = uint32_t;
using pii = pair<int,int>;
using pll = pair<ll,ll>;
using pil = pair<int,ll>;
using vi = vector<int>;
using vvi = vector<vi>;
using vl = vector<ll>;
template<typename T>inline istream& operator>>(istream&i,v(T)&v)
{rep(j,v.size())i>>v[j];return i;}
template<typename T>string join(const v(T)&v)
{stringstream s;rep(i,v.size())s<<' '<<v[i];return s.str().substr(1);}
template<typename T>inline ostream& operator<<(ostream&o,const v(T)&v)
{if(v.size())o<<join(v);return o;}
template<typename T1,typename T2>inline istream& operator>>(istream&i,pair<T1,T2>&v)
{return i>>v.fi>>v.se;}
template<typename T1,typename T2>inline ostream& operator<<(ostream&o,const pair<T1,T2>&v)
{return o<<v.fi<<","<<v.se;}
const double eps = 1e-6;
const ll LINF = 100200300400500600ll;
const int INF = 1001001001;
//--------------------------------------------------------
#define fastio cin.tie(nullptr); std::ios::sync_with_stdio(false);
#define myio ifstream iofi; if(argc>1){iofi.open(argv[1]); std::cin.rdbuf(iofi.rdbuf());}
#define myloopset int loop = 1; if(argc>2) loop =stoi(argv[2]); rep(i,loop)
//--------------------------------------------------------------
template <class T> T chmin(T &a,T b){if(a>b){a=b; return 1;}else return 0;}
template <class T> T chmax(T &a,T b){if(a<b){a=b; return 1;}else return 0;}
const int dx[4] = {0,1,0,-1};
const int dy[4] = {-1,0,1,0};
const int mod = 1000000007;

void Main(){
  int n;
  cin>>n;
  cout<<dup(n,2)<<endl;


} signed main(int argc,char** argv)
{fastio; myio; myloopset Main();}


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

using namespace std;
typedef long long LL;
typedef pair<LL, LL> P;

int main(void)
{
  LL N, Q;
  string S;

  cin >> N >> Q;
  cin >> S;

  vector<LL> ac(N, 0);
  vector<LL> res;

  for (LL i = N - 1; i >= 1; i--) {
    if (S[i - 1] == 'A' && S[i] == 'C') {
      ac[i - 1] = ac[i] + 1;
    }
    else {
      ac[i - 1] = ac[i];
    }
  }

  for (LL i = 0; i < Q; i++) {
    LL lt, rt;
    cin >> lt >> rt;

    res.push_back(ac[lt - 1] - ac[rt - 1]);
  }

  for (LL i = 0; i < Q; i++) {
    cout << res[i] << endl;
  }

  return 0;
}


Measured memory_bytes: 2676
#include <iostream>
#include <string>
#include <vector>
#include <set>
#include <algorithm>
#include <numeric>//accumulateを使うためにインクルード

using namespace std;

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

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

int main() {
    int a,b,c;
    cin >> a >> b >> c;
    if(b >= c) cout << "delicious" << endl;
    else if(a + b >= c) cout << "safe" << endl;
    else cout << "dangerous" << endl;
 }

Measured memory_bytes: 256
N,X,Y = map(int, input().split())
D = [0] * N
for i in range(1,N):
  for j in range(i+1,N+1):
    D[min(abs(i-j),abs(X-i)+abs(Y-j)+1,abs(Y-i)+abs(X-j)+1)] += 1 
print (*D[1:], sep="\n")

Measured memory_bytes: 3444
import java.util.Scanner;

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

        String a = sc.next();
        String b = sc.next();
        String c = sc.next();
        String A = a.toUpperCase();
        String B = b.toUpperCase();
        String C = c.toUpperCase();
        System.out.print(A.charAt(0));
        System.out.print(B.charAt(0));
        System.out.println(C.charAt(0));
    }
}

Measured memory_bytes: 23252
# Resale

N = int(input())
V = list(map(int, input().split()))
C = list(map(int, input().split()))

def answer():
    ans = 0
    for i in range(N):
        profit = V[i] - C[i]
        if profit >= 0:
            ans += profit

    return ans

def main():
    print(answer())


if __name__ == '__main__':
    main()


Measured memory_bytes: 2940
n=gets.chomp.to_i
l=gets.chomp.split(" ").map{|s| s.to_i}
m=[]
m[1]=0
for i in 0..n-1
  m[1]+=l[i]  if i%2==0
  m[1]-=l[i]  if i%2==1
end
m[1]=m[1]/2

i=n-1
m[n]=l[n-1]-m[1]

while i!=1
  m[i]=l[i-1]-m[i+1]
  i-=1
end

for i in 1..n
  print "#{m[i]*2} "
end

Measured memory_bytes: 14092
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace D
{
    class Program
    {
        static long N, K;
        static void Main(string[] args)
        {
            var temp = ReadLinesToIntListList(1);
            N = temp[0][0];
            K = temp[0][1];
            long sum = 0;
            if(K == 0)
            {
                Console.WriteLine(N * N);
                return;
            }
            for (long b = K + 1; b <= N; b++)
            {
                var threshold = b - K;
                var q = N / b;
                var mod = N % b;
                var tmp = mod - K + 1;

                sum += q * threshold + (tmp > 0 ? tmp : 0);
            }
            Console.WriteLine(sum);
        }

        static List<List<int>> ReadLinesToIntListList(int n)
        {
            List<List<int>> list = new List<List<int>>();
            for(int i = 0; i < n; i++)
            {
                var temp = Console.ReadLine().Split(' ').Select(s => int.Parse(s)).ToList();
                list.Add(temp);
            }
            return list;
        }

        static List<int> ReadLinesToIntList(int n)
        {
            List<int> list = new List<int>();
            for(int i = 0; i < n; i++)
            {
                var temp = int.Parse(Console.ReadLine());
                list.Add(temp);
            }
            return list;
        }
    }
}

Measured memory_bytes: 11348
#include <stdio.h>
#include <string.h>
int main()
{
	char s[10];
	scanf("%s",s);
	if (strcmp(s, "Sunny") == 0)
		printf("Cloudy");
	else if (strcmp(s, "Cloudy") == 0)
		printf("Rainy");
	else if (strcmp(s, "Rainy") == 0)
		printf("Sunny");
	return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define MOD 1000000007
#define print(A,n) for(ll i=0;i<n;++i)cout<<A[i]<<' ';cout<<endl;
#define take(A,n) for(ll i=0;i<n;++i)cin>>A[i];
//    for(auto& it : m)
void fastio(){ios_base::sync_with_stdio(false);cin.tie(NULL);}
//  priority_queue<ll int> pq;
//  priority_queue <ll int, vector<ll int>, greater<ll int> > pq;
//  vector<ll int> v;
//  vector< pair<ll int,ll int> > v;
//  set<ll int>::iterator it=s.begin();
//  unordered_map<  pair<ll int,ll int>, ll int> mp;
 
int main() 
{ 
  fastio();
ll int T;//cin>>T;
T=1;while(T--)
{
ll int n,k,i;
cin>>n>>k;ll int a[n+1],b[n+1],s[n+1];
for(i=0;i<=n;i++)
a[i]=i;
for(i=1;i<=n;i++)
{
  a[i]+=a[i-1];
 // a[i]%=1000000007;
}
for(i=0;i<=n;i++)
{
  b[i]=i;
  //b[i]%=1000000007;
}
for(i=n-1;i>=0;i--)
{
  b[i]+=b[i+1];
 // b[i]%=1000000007;
}
reverse(b,b+n+1);


k--;
ll int ans=0;
vector<pair<ll int,ll int>> vect;
for(i=k;i<=n;i++)
{
 vect.push_back(make_pair(a[i],b[i]));
  

}
sort(vect.begin(),vect.end());

ans=vect[0].second-vect[0].first+1;ll int mx=vect[0].second;ans%=1000000007;
for(i=1;i<vect.size();i++)
{

    ans+=vect[i].second-vect[i].first+1;mx=vect[i].second;
    ans%=1000000007;
  
 
}
cout<<ans<<endl;
}
       
    return 0; 
} 


Measured memory_bytes: 10524
X, K, D = map(int, input().split())
X = abs(X)

if X // D >= K:
  print(X - K * D)
  
else:
  if K % 2 == 0 and X // D % 2 == 0:
    print(X - D * (X // D))
  elif K % 2 == 0 and X // D % 2 == 1:
    print(abs(X - D * (X // D) - D))
  elif K % 2 == 1 and X // D % 2 == 0:
    print(abs(X - D * (X // D) - D))
  elif K % 2 == 1 and X // D % 2 == 1:
    print(X - D * (X // D))

Measured memory_bytes: 9196
#include <iostream>
#include <vector>
#include <array>
#include <algorithm>
#include <cstring>
#include <queue>
#include <iomanip>
#include <numeric>
#include <cmath>
#include <cstdlib>
#include <sstream>
#include <bitset>

using namespace std;

//#define SIZE_OF_ARRAY(array) (sizeof(array)/sizeof(array[0]))

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

//static const ll MOD = 1000000007;
//static const ll INF = 100000000;

int main() {
    // input
    ll A, B, C;
    cin >> A >> B >> C;

    // process
    if (A == B) {
        if (B != C) {
            cout << "Yes";
            return 0;
        }
    }
    if (A == C) {
        if (B != C) {
            cout << "Yes";
            return 0;
        }
    }
    if (B == C) {
        if (A != C) {
            cout << "Yes";
            return 0;
        }
    }

    cout << "No";
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define FOR(i, a, b) for(int i=(a);i<(b);++i)
#define rep(i, n) FOR(i, 0, n)
#define rep1(i, n) FOR(i, 1, n+1)
#define rrep(i, n) for (int i = ((int)(n)-1); i >= 0; --i)
#define whole(x) (x).begin(),(x).end()
#define rwhole(x) (x).rbegin(), (x).rend()
#define UNIQUE(v) v.erase(unique(v.begin(), v.end()), v.end())
#define P pair<int, int>
#define debug(var) cerr << "[" << #var << "] " << var << endl
#define chmin(x, y) x = min(x, y)
#define chmax(x, y) x = max(x, y)
const ll mod = 1000000007;
const int dx[] = {-1,0,1,0};
const int dy[] = {0,-1,0,1};


int main(){
    int n;
    cin >> n;
    vector<int> t(n);
    rep(i, n) cin >> t[i];
    int m;
    cin >> m;
    int ans = 0;
    rep(i, n) ans += t[i];
    
    rep(i, m) {
        int p, x;
        cin >> p >> x;
        p--;
        int z = t[p]-x;
        cout << ans-z << endl;
    }
    
    
    return 0;
}


Measured memory_bytes: 3600
/**
*
* Author: Mouhanad
* Lang: GNU C++14
*
**/
#include<bits/stdc++.h>
using namespace std;

#define F first
#define S second
#define ii pair < int , int >
#define LS pair < ll , string >
typedef long long ll;
const int inf = 1<<30;
const int N =100100;
int n , a[N] , q ;

int main ( ){
 cin >> n >> q ;
 if (  (n+q) % 3 == 0  || n % 3 == 0 || q % 3 == 0  ) puts("Possible");
 else puts("Impossible");

return 0 ;
}


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

int main(){
    string s;
    cin >> s;
    ll ans = 0;
    int n = s.size();
    rep(bit,1<<n-1){
        string temp = "";
        rep(i,n-1){
            temp += s[i];
            if(bit >> i & 1){
                ans += stol(temp);
                temp = "";
            }
        }
        temp += s[n-1];
        ans += stol(temp);
     }
     cout << ans << endl;
    }

Measured memory_bytes: 3632
#include<stdio.h>
#include<string.h>
#include<bitset>
#include<queue>
char m[32][32];
const int dx[]={0,1,0,-1,0},dy[]={1,0,-1,0,0};
std::bitset<1<<24 >f;
template<int N>
struct S
{
void I2P(int a,int*x,int*y)
{
	for(int i=0;i<N;++i)
	{
		y[N-i-1]=a&15;
		x[N-i-1]=(a>>4)&15;
		a>>=8;
	}
}
int P2I(int*x,int*y)
{
	int res=0,i;
	for(i=0;i<N;++i)
		res=(res<<8)|(x[i]<<4)+y[i];
	return res;
}
int EQ(int*x,int*y,int*gx,int*gy)
{
	for(int i=0;i<N;++i)
		if(x[i]!=gx[i]||y[i]!=gy[i])
			return 0;
	return 1;
}
void G(std::queue<int>&q, int*x,int*y,int*nx,int*ny,int/* i*/)
{
	int i,j,k,a;
	for(i=0;i<5;++i)
	{
		nx[0]=x[0]+dx[i];
		ny[0]=y[0]+dy[i];
		if(m[ny[0]][nx[0]]=='#')continue;
		if(N==1)
		{
			a=P2I(nx,ny);
			if(!f[a])
				q.push(a);
			continue;
		}
		for(j=0;j<5;++j)
		{
			nx[1]=x[1]+dx[j];
			ny[1]=y[1]+dy[j];
			if(m[ny[1]][nx[1]]=='#' || nx[0]==nx[1]&&ny[0]==ny[1])continue;
			if(x[0]==nx[1]&&y[0]==ny[1]&&x[1]==nx[0]&&y[1]==ny[0])
				continue;
			if(N==2)
			{
				a=P2I(nx,ny);
				if(!f[a])
					q.push(a);
				continue;
			}
			for(k=0;k<5;++k)
			{
				nx[2]=x[2]+dx[k];
				ny[2]=y[2]+dy[k];
				if(m[ny[2]][nx[2]]=='#' || nx[0]==nx[2]&&ny[0]==ny[2] || nx[1]==nx[2]&&ny[1]==ny[2])continue;
				if(x[0]==nx[2]&&y[0]==ny[2]&&x[2]==nx[0]&&y[2]==ny[0] || 
				   x[1]==nx[2]&&y[1]==ny[2]&&x[2]==nx[1]&&y[2]==ny[1])
					continue;
				a=P2I(nx,ny);
				if(!f[a])
					q.push(a);
			}
		}
	}
}
int F(int (&x)[3],int (&y)[3],int (&gx)[3],int(&gy)[3])
{
	f.reset();
	std::queue<int>q;
	q.push(P2I(x,y));
	q.push(-1);
	int a,res=0;
	int nx[3],ny[3];
	for(;;)
	{
		a=q.front();
		q.pop();
		if(a<0)
		{
			++res;
			q.push(a);
			continue;
		}
		if(f[a])continue;
		f[a]=true;
		I2P(a,x,y);
		if(EQ(x,y,gx,gy))return res;
		G(q,x,y,nx,ny,0);
	}
}
};
int main()
{
	int h,w,n,i,x[3],y[3],gx[3],gy[3];
	char*p;
	while(scanf("%d%d%d",&w,&h,&n),n)
	{
		fgets(m[0],32,stdin);
		for(i=0;i<h;++i)
		{
			fgets(m[i],32,stdin);
			for(p=m[i];p=strpbrk(p,"abc");++p)
			{
				y[*p-'a']=i;
				x[*p-'a']=p-m[i];
			}
			for(p=m[i];p=strpbrk(p,"ABC");++p)
			{
				gy[*p-'A']=i;
				gx[*p-'A']=p-m[i];
			}
		}
		int r = (n==3?S<3>().F(x,y,gx,gy):
				n==2?S<2>().F(x,y,gx,gy):
				S<1>().F(x,y,gx,gy));
		printf("%d\n",r);
	}
	return 0;
}

Measured memory_bytes: 0
import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        String s = sc.next();
        StringBuilder sb = new StringBuilder();
        for (int i = 0; i < s.length(); i++) {
            if (s.charAt(i) == 'B') {
                if (sb.length() > 0) sb.setLength(sb.length() - 1);
            } else {
                sb.append(s.charAt(i));
            }
        }
        System.out.println(sb.toString());
    }
}


Measured memory_bytes: 21716
#include<cmath>
#include<algorithm>
#include<iostream>
#include<vector>
#include<cstdio>

double EPS = 1e-10;

using namespace std;

double add(double a, double b){
  if(abs(a+b) < EPS * (abs(a)+abs(b)))return 0;
  return a+b;
}

struct point{
  double x, y;
  point(){}
  point(double x,double y) : x(x) , y(y){}

  point operator + (point p){
    return point(add(x,p.x), add(y,p.y));
  }

  point operator - (point p){
    return point(add(x,-p.x), add(y,-p.y));
  }

  point operator * (double d){
    return point(x*d,y*d);
  }

  point operator / (double d){
    return point(x/d,y/d);
  }
};

int rect_cross(point p1, point p2, point p3, point p4){
  return !(p2.x<p3.x || p4.x<p1.x || p2.y<p3.y || p4.y<p1.y);
}

int main(void){
  point p[5];

  while(true){

    for(int i=1;i<5;i++)
      if(scanf("%lf %lf",&p[i].x,&p[i].y)==EOF)return 0;

    if(rect_cross(p[1],p[2],p[3],p[4]))
      cout << "YES" << endl;
    else cout << "NO" << endl;
  }

return 0;
}

Measured memory_bytes: 0
n,m = map(int,input().split())
youbou = [list(map(int,input().split())) for i in range(m)]
youbou.sort(key = lambda x: x[1])
ans,prev = 0,-1
for p in youbou:
	if prev < p[0]:
		prev = p[1] - 1
		ans += 1
print(ans)

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

int main(){
	int a[10],i,z,x;
	for(i=0;i<10;i++){
		cin>>a[i];
		}
	cout<<a[0]+a[1]+a[2]+a[3]+a[4]+a[5]+a[6]+a[7]+a[8]+a[9]<<endl;
	return 0;
	}

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

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

const int INT_INF = 2147483646;
const ll LL_INF = 9223372036854775807;

bool SecondCompare(const pair<int,int> &a,const pair<int,int> &b)
{
       return a.second<b.second;
}
 
bool SecondCompareDes(const pair<int,int> &a,const pair<int,int> &b)
{
       return a.second>b.second;
}

ll minll(ll a, ll b){
    if(a >= b)  return b;
    else    return a;
}

ll maxll(ll a, ll b){
    if(a >= b)  return a;
    else    return b;
}

string s;

int main(){
    cin >> s;

    ll co = 0;
    for(int i = 0; i < s.length(); i++){
        if(s[i] == 'x') ++co;
    }
    if(co >= 8) cout << "NO\n";
    else
    {
        cout << "YES\n";
    }
    
}

Measured memory_bytes: 256