akhauriyash/Code-Regression huggingface dataset:
// SeeAlso: https://atcoder.jp/contests/abc154/tasks/abc154_d

#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;

#define MAX 100000
#define NIL -1
#define MOD 1000000007

typedef int _loop_int;
#define rep(i,n) for(int i = 0; i < n; i++)
#define FOR(i,a,b) for(_loop_int i=(_loop_int)(a);i<(_loop_int)(b);++i)
#define FORR(i,a,b) for(_loop_int i=(_loop_int)(b)-1;i>=(_loop_int)(a);--i)

#define debug(x) cout<<#x<<": "<<x<<endl
#define debig_vec(v) cout<<#v<<":";rep(i,v.size())cout<<" "<<v[i];cout<<endl
#define ALL(a) (a).begin(),(a).end()

// 最大公約数
inline constexpr ll gcd(ll a,ll b){if(!a||!b)return 0;while(b){ll c=b;b=a%b;a=c;}return a;}
// 最小公倍数
inline constexpr ll lcm(ll a,ll b){if(!a||!b)return 0;return a*b/gcd(a,b);}

#define print2D(h, w, arr) rep(i, h) { rep(j, w) cout << arr[i][j] << " "; cout << endl; }
template<class T> void print(const T& x){cout << setprecision(12) << x << endl;}
template<class T, class... A> void print(const T& first, const A&... rest) { cout << first << " "; print(rest...); }

int main (){ 
    ll k,n;
    cin >> n >> k;
    double p[n];
    double dp[1003];
    
    rep(i, 1003) {
        ll aa = i;
        double t = aa;
        rep(j,i) {
            aa--;
            t += aa;
        }

        t = t/i;

        dp[i] = t;
    }

    double ans = 0;
    double sum = 0;
    rep(i,n) {
        int a;
        cin >> a;
        p[i] = dp[a];
        
        sum += p[i];
        if(i>=k) {
            sum = sum-p[i-k];
            ans = max(sum, ans);
        } else {
            ans = sum;
        }
    }

    print(ans);
    return 0;
}


Measured memory_bytes: 1792
#![allow(unused_imports, unused_macros, dead_code)]

macro_rules! min {
    (.. $x:expr) => {{
        let mut it = $x.iter();
        it.next().map(|z| it.fold(z, |x, y| min!(x, y)))
    }};
    ($x:expr) => ($x);
    ($x:expr, $($ys:expr),*) => {{
        let t = min!($($ys),*);
        if $x < t { $x } else { t }
    }}
}
macro_rules! max {
    (.. $x:expr) => {{
        let mut it = $x.iter();
        it.next().map(|z| it.fold(z, |x, y| max!(x, y)))
    }};
    ($x:expr) => ($x);
    ($x:expr, $($ys:expr),*) => {{
        let t = max!($($ys),*);
        if $x > t { $x } else { t }
    }}
}
macro_rules! ewriteln {
    ($($args:expr),*) => { let _ = writeln!(&mut std::io::stderr(), $($args),*); };
}
macro_rules! trace {
    ($x:expr) => { ewriteln!(">>> {} = {:?}", stringify!($x), $x) };
    ($($xs:expr),*) => { trace!(($($xs),*)) }
}
macro_rules! put {
    (.. $x:expr) => {{
        let mut it = $x.iter();
        if let Some(x) = it.next() { print!("{}", x); }
        for x in it { print!(" {}", x); }
        println!("");
    }};
    ($x:expr) => { println!("{}", $x) };
    ($x:expr, $($xs:expr),*) => { print!("{} ", $x); put!($($xs),*) }
}

const M: i64 = 1_000_000_007;

fn main() {
    let mut sc = Scanner::new();
    let a: i64 = sc.cin();
    let v: i64 = sc.cin();
    let b: i64 = sc.cin();
    let w: i64 = sc.cin();
    let t: i64 = sc.cin();
    if v <= w {
        put!("NO");
    } else {
        if (v - w) * t >= (a - b).abs() {
            put!("YES");
        } else {
            put!("NO");
        }
    }
}

use std::collections::VecDeque;
use std::io::{self, Write};
use std::str::FromStr;

struct Scanner {
    stdin: io::Stdin,
    buffer: VecDeque<String>,
}
impl Scanner {
    fn new() -> Self {
        Scanner {
            stdin: io::stdin(),
            buffer: VecDeque::new(),
        }
    }
    fn cin<T: FromStr>(&mut self) -> T {
        while self.buffer.is_empty() {
            let mut line = String::new();
            let _ = self.stdin.read_line(&mut line);
            for w in line.split_whitespace() {
                self.buffer.push_back(String::from(w));
            }
        }
        self.buffer.pop_front().unwrap().parse::<T>().ok().unwrap()
    }
    fn chars(&mut self) -> Vec<char> {
        self.cin::<String>().chars().collect()
    }
    fn vec<T: FromStr>(&mut self, n: usize) -> Vec<T> {
        (0..n).map(|_| self.cin()).collect()
    }
}


Measured memory_bytes: 2136
#include<iostream>
using namespace std;
int f(int a){
    int cnt=0;
    while(a){
        a/=10;
        cnt++;
    }
    return cnt;
}
int b[]={9,909,90909};
int n,x,ans;
int main(){
    cin>>n;
    x=f(n);
        if(x==6)ans=b[2];
        if(x==5)ans=n-9999+b[1];
        if(x==4)ans=b[1];
        if(x==3)ans=n-99+9;
        if(x==2)ans=b[0];
        if(x==1)ans=n-0;
        cout<<ans<<endl;
}

Measured memory_bytes: 256
import java.util.*;
public class Main {
public static void main(String[] args){
Scanner sc = new Scanner(System.in);
int N=sc.nextInt();
int[] cost=new int[201];
 int[] a=new int[N];
 int temp=0;
 for(int k=0;k<N;k++){a[k]=sc.nextInt();}
for(int i=-100;i<=100;i++){
    temp=0;
    for(int j=0;j<N;j++){
        temp+=Math.pow((a[j]-i),2);
        }
    cost[i+100]=temp;
    }
Arrays.sort(cost);
System.out.println(cost[0]);
}
}

Measured memory_bytes: 21844
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main {
	public static void main(String[] args) throws IOException {
		BufferedReader bf = null;
		bf = new BufferedReader(new InputStreamReader(System.in));
		int n0 = 0,n1 = 0,ans = 0;
		String str = bf.readLine();
		for(int i = 0;i<str.length();++i) {
			if(str.charAt(i) == '0') {
				n0++;
			} else {
				n1++;
			}
		}
		if(n0 > n1) {
			ans = n1*2;
		} else {
			ans = n0*2;
		}
		System.out.println(ans);
	}
}

Measured memory_bytes: 23252
n, k = gets.split.map(&:to_i)
pp = gets.split.map{|e| e = e.to_i; [e, e, true]}

class SegTree
    def update(k); @d[k] = @op.call(@d[2 * k], @d[2 * k + 1]); end

    def initialize(v, e, &op)
        @n = v.size
        @log = (@n - 1).bit_length
        @size = 1 << @log
        @op = op

        @d = Array.new(2 * @size, e) # vector

        @n.times{|i| @d[@size + i] = v[i]}
        (@size - 1).downto(1) {|i| update(i)}
    end

    def set(pos, x)
        pos += @size
        @d[pos] = x
        1.upto(@log) {|i| update(pos >> i)}
    end

    def get(pos); @d[pos + @size]; end

    def prod(l, r)
        sml = smr = @d[0]
        l += @size
        r += @size

        while l < r
            (sml = @op.call(sml, @d[l]); l += 1) if l[0] == 1
            (r -= 1; smr = @op.call(@d[r], smr)) if r[0] == 1
            l >>= 1
            r >>= 1
        end
        @op.call(sml, smr)
    end

    def all_prod; @d[1]; end
end

st = SegTree.new(pp, -1) do |c1, c2|
    if c1 == -1
        c2
    elsif c2 == -1
        c1
    elsif c1[2] && c2[2] && c1[1] < c2[0]
        [c1[0], c2[1], true]
    else
        [[c1[0], c2[0]].min, [c1[1], c2[1]].max, false]
    end
end

ans = 1
f = st.prod(0, k)[2]
(n - k).times do |i|
    a = st.prod(i, i+k)
    b = st.prod(i+1, i+k+1)
    next if a[0] == pp[i][0] && b[1] == pp[i+k][0]
    next if f && b[2]
    f |= b[2]
    ans += 1
end
p ans

Measured memory_bytes: 51288
#include <bits/stdc++.h>
#include <string>
#include <cmath>
#include <sstream>
#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define FORD(i, a, b) for(int i = (a); i > (b); i--)
#define pb(a) push_back(a)
#define mp(a,b) make_pair(a,b)
typedef long long int ll;
using namespace std;
ll mod=1000000007;
//ll mod=67280421310721;
//ll mod=998244353;
ll INF=1e18;
int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	int test=1;
//	cin>>test;
	while(test--)
	{
		ll n;
		cin>>n;
		int a[n]={0},j;
		FOR(i,1,n)
		{
			cin>>j;
			a[j-1]++;
		}
		FOR(i,0,n)
		cout<<a[i]<<'\n';
	}
	return 0;
}


Measured memory_bytes: 4484
#include<stdio.h>

unsigned long greatest_common_divisor(unsigned long x, unsigned long y)
{
    unsigned long z;

    while(y!=0){
        z = x % y;
        x = y;
        y = z;
    }
    return x;
}

int main()
{
    unsigned long x,y;
 
    scanf("%lu", &x);
    scanf("%lu", &y);

    printf("%lu\n", greatest_common_divisor(x, y));
    
    return 0;
}

Measured memory_bytes: 1856
#include<stdio.h>
#include<stdlib.h>

typedef struct {
	char name[11];
	int time;
	int flag;
}Process;

Process *Q;
int head;
int tail;
int n;

Process dequeue();
void enqueue(Process);

int main() {
	int ms;
	int i;
	Process deq;
	int run = 0;

	scanf("%d%d", &n, &ms);

	head = 0;
	tail = 0;
	n++;

	Q = (Process *)malloc(n * sizeof(Process));
	for (i = 0; i < n - 1; i++) {
		scanf("%s", Q[i].name);
		scanf("%d", &Q[i].time);
		Q[i].flag = 1;
		tail++;
	}

	Q[i].flag = 0;

	i = 0;
	while (head != tail) {

		if (Q[i].flag == 1) {

			if (Q[i].time <= ms) {
				run += Q[i].time;
				deq = dequeue();
				printf("%s %d\n", deq.name, run);
			}

			else {
				run += ms;
				Q[i].time -= ms;

				deq = dequeue();
				enqueue(deq);
			}
		}

		i++;
		if (i == n)
			i = 0;
	}

	free(Q);
	return 0;
}

Process dequeue() {
	Process x;

	x = Q[head];
	x.flag = 0;

	if (head + 1 == n)
		head = 0;
	else
		head++;

	return x;
}

void enqueue(Process x) {
	
	Q[tail] = x;
	Q[tail].flag = 1;

	if (tail + 1 == n)
		tail = 0;
	else
		tail++;
}


Measured memory_bytes: 2276
#include <iostream>
#include <fstream>
#include <cstdio>
#include <cmath>
#include <vector>
#include <cstring>
#include <string>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <algorithm>
using namespace std;

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

typedef long long ll;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef vector<VI> VVI;
typedef pair<int,int> P;
typedef pair<ll,ll> PL;



int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n;
    int total = 0;
    priority_queue<int, vector<int>, greater<int>> minpq;
    cin >> n;
    REP(i, n){
        int s;
        cin >> s;
        minpq.push(s);
        total += s;
    }
    REP(i, n){
        if(total % 10 == 0){
            if(minpq.top() % 10 != 0){
                total -= minpq.top();
                break;
            }
            minpq.pop();
            if(i == n - 1) total = 0;
        }
    }

    cout << total << "\n";

    return 0;
}


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

typedef long long ll;
typedef pair<int, int> P;
int const MAX_V = 20001;
int const MAX_E = 100001;
int const INF = 1<<29;

vector<int> G[MAX_V];
int ord[MAX_V], low[MAX_V];

int V,E;
void init();
vector<int> ans;

void rec(int pos,int prev,int& k){
  low[pos]=ord[pos]=k++;
  int flg=0,child=0;
  for(int i=0;i<(int)G[pos].size();i++){
    int to=G[pos][i];
    if(to==prev)continue;
    if(ord[to]==-1){
      child++;
      rec(to,pos,k);
      low[pos]=min(low[pos],low[to]);
      if(low[to]>=ord[pos]&&prev!=-1)flg=true;
    }
    low[pos]=min(low[pos],ord[to]);
  }
  if(prev==-1&&child>=2)flg=true;
  if(flg)ans.push_back(pos);
}

void init() {
  ans.clear();
  for(int i=0;i<V;i++){
    low[i]=INF;
    ord[i]=-1;
    G[i].clear();
  }
}

int main(){

  cin>>V>>E;
  init();
  for(int i=0;i<E;i++){
    int u, v; 
    scanf("%d %d",&u,&v);
    //   u--,v--;
    G[u].push_back(v);
    G[v].push_back(u);
  }

  int k=0;
  for(int i=0;i<V;i++)
    if(ord[i]==-1)
      rec(i,-1,k);      
    
  //for(int i=0;i<V;i++)cout<<low[i]<<' '<<ord[i]<<' '<<i<<endl;
  sort(ans.begin(),ans.end());
  for(int i=0;i<(int)ans.size();i++)
    cout<<ans[i]<<endl;
  
  return 0;
}

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

int main() {
	int n, a[200], count = 0;
	cin >> n;
	while (1) {
		for (int i = 0; i<n; i++) {
			if(!count)cin >> a[i];
			if (a[i] % 2 == 0) {
				a[i] = a[i] / 2;
			}
			else{
              cout << count << endl;
              return 0;
            }
		}
		count++;
	}
}

Measured memory_bytes: 256
n=int(input())
A=[0]*n
a=round(n**0.5)+1
for x in range(1,a):
  for y in range(1,a):
    for z in range(1,a):
      b=x*x+y*y+z*z+x*y+y*z+z*x-1
      if b<n:
        A[b]+=1
for i in range(n):
  print(A[i])

Measured memory_bytes: 9408
import sys
import math
import copy
from heapq import heappush, heappop, heapify
from functools import cmp_to_key
from bisect import bisect_left, bisect_right
from collections import defaultdict, deque, Counter
# sys.setrecursionlimit(1000000)

# input aliases
input = sys.stdin.readline
getS = lambda: input().strip()
getN = lambda: int(input())
getList = lambda: list(map(int, input().split()))
getZList = lambda: [int(x) - 1 for x in input().split()]

INF = float("inf")
MOD = 10**9 + 7
divide = lambda x: pow(x, MOD-2, MOD)



def solve():
    n, t = getList()
    li = []
    for i in range(n):
        li.append(getList())

    li.sort(key=lambda x: 30000 * x[0] + x[1])
    dp = [0] * t
    ans = 0
    for a, b in li:
        tmp = copy.copy(dp)
        ans = max(ans, dp[-1] + b)
        for idx, dd in enumerate(dp):
            # tmp[idx] = max(tmp[idx], dd)
            if idx + a < t:
                tmp[idx + a] = max(dp[idx + a], dp[idx] + b)
        dp = tmp
        for j in range(len(dp) - 1):
            dp[j+1] = max(dp[j], dp[j+1])
    #     print(dp)
    # print(li)
    print(ans)





def main():
    n = getN()
    for _ in range(n):
        solve()

    return
if __name__ == "__main__":
    # main()
    solve()







Measured memory_bytes: 70396
#include <bits/stdc++.h>
#define fi first
#define se second
using namespace std;
using p = pair<long long,long long>;

long long N,L;
vector<long long> memo,sum;
vector<p> lr;
map<long long,long long> mp;

long long solve();
bool asc(const p &l,const p & r){
    if(l.fi != r.fi)return l.fi < r.fi;
    return l.se > r.se;
}

int main(){
    cin >> N >> L;
    lr.resize(N);
    for(int i = 0;i < N;++i){
        cin >> lr[i].fi >> lr[i].se;
        memo.push_back(lr[i].fi);
        memo.push_back(lr[i].se);
    }
    sort(memo.begin(),memo.end());
    memo.erase(unique(memo.begin(),memo.end()),memo.end());
    cout << solve() << endl;
    return 0;
}

long long solve(){
    sort(lr.begin(),lr.end(),asc);
    sum.resize(memo.size(),0);
    long long ans = 0,now = 0,msize = memo.size();
    for(int i = 0;i < N;){
        long long nextp = now;
        while(i < N && lr[i].fi <= now){
            nextp = max(nextp,lr[i].se);
            ++i;
        }
        ++ans;
        now = nextp;
        if(nextp >= L){
            cout << ans << " ";
            break;
        }
    }
    for(int i = 0;i < msize;++i)
        mp[memo[i]] = i;
    for(int i = 0;i < N;++i){
        ++sum[mp[lr[i].fi]];
        if(mp[lr[i].se] + 1 < msize)--sum[mp[lr[i].se] + 1];
    }
    ans = sum[0];
    for(int i = 1;i < msize;++i)
        if(memo[i] <= L){
        sum[i] += sum[i-1];
        ans = min(ans,sum[i]);
    }
    return N - ans + 1;
}


Measured memory_bytes: 35780
#include <stdio.h>
#include <stdlib.h>

int isIn(int, int *, int);

int main(void)
{
  int n, q, i, count=0;
  scanf(" %d", &n);
  int *nArray = (int *) malloc(sizeof(int[n]));
  for (i=0; i<n; i++)
    scanf(" %d", nArray+i);
  scanf(" %d", &q);
  int *qArray = (int *) malloc(sizeof(int[q]));
  for (i=0; i<q; i++)
    scanf(" %d", qArray+i);
  for (i=0; i<q; i++)
    if (isIn(qArray[i], nArray, n))
      count++;
  printf("%d\n", count);
  return 0;
}

int isIn(int number, int *array, int length)
{
  int bottom=0, top=length-1;
  if (array[bottom]==number)
    return 1;
  if (array[top]==number)
    return 1;
  while (bottom!=(top-1))
    {
      int mid=(bottom+top)/2;
      if (array[mid]==number)
	return 1;
      else if (array[mid]<number)
	bottom=mid;
      else
	top=mid;
    }
  return 0;
}



Measured memory_bytes: 2304
import collections
N,M=map(int,input().split())
H=input().split()
tenboudai=[i for i in range(1,N+1)]
lose=[]
for i in range(M):
    X=input().split()
    A=int(X[0])
    B=int(X[1])
    if int(H[A-1])>int(H[B-1]):
        lose.append(B)
    elif int(H[A-1])<int(H[B-1]):
        lose.append(A)
    elif int(H[A-1])==int(H[B-1]):
        lose.append(A)
        lose.append(B)
    
a=len(tenboudai)
b=len(collections.Counter(lose))
 
print(a-b)

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

#define rep(i, n) for(int (i)=0;(i)<(n);(i)++)
using ll = long long;
bool custom1 (pair<int, int> a, pair<int, int> b) {
  return (a.first < b.first);
}
bool custom2(pair<int, int> a, pair<int, int> b) {
  return (a.second < b.second);
}

int main() {
  int n, r;
  cin >> n >> r;
  if(n >= 10) cout << r << endl;
  else cout << r + 100 * (10 - n) << endl;
}


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(void){
    string s, t;
    cin >> s;
    cin >> t;
    int length = s.size();
    
    for(int i = 0; i < length; i++){
        if(s.at(i) != t.at(i)){
            cout << "No" << endl;
            return 0;
        }
    }
    cout << "Yes" << endl;
        
}


Measured memory_bytes: 3632
import java.util.*;

public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
        int num = sc.nextInt();
        int sum = sc.nextInt();
        
        int cnt = 0;
        
        for(int x = 0; x<=num; x++){
            for(int y = 0; y<=num; y++){
                if((sum - (x+y) <= num) && (sum - (x+y) >= 0)){
                    cnt++;
                }
            }
        }
        
        System.out.println(cnt);
	}
}

Measured memory_bytes: 21844
#include<iostream>
#define DIM 100005
using namespace std;
int n, i;
int v[DIM];
long long sum[DIM], d[DIM], niv, total;
int main(){
    cin>> n;
    n++;
    for(i = 1; i <= n; i++){
        cin>> v[i];
    }
    if(v[1] > 1){
        cout<< -1;
        return 0;
    }
    niv = 1;
    for(i = 2; i <= n; i++){
        niv = (niv - v[i - 1]) * 2;
        if(niv < v[i]){
            cout<< -1;
            return 0;
        }
        if(niv > 100000000000000LL){
            break;
        }
    }
    for(i = n; i >= 1; i--){
        sum[i] = sum[i + 1] + v[i];
    }
    d[1] = total = 1;
    for(i = 2; i <= n; i++){
        d[i] = min(sum[i], 2 * (d[i - 1] - v[i - 1]) );
        total += d[i];
    }
    cout<< total;
}


Measured memory_bytes: 5576
#include<cstdio>
#include<cstring>
#include<algorithm>
#define MN 16
using namespace std;
inline int in(){
    int x=0;bool f=0; char c;
    for (;(c=getchar())<'0'||c>'9';f=c=='-');
    for (x=c-'0';(c=getchar())>='0'&&c<='9';x=(x<<3)+(x<<1)+c-'0');
    return f?-x:x;
}
int f[1<<MN][MN],sum[1<<MN],mp[MN][MN];
int n,m,a,b,c;
int main()
{
	n=in();m=in();
	for (int i=1;i<=m;++i){
		a=in()-1;b=in()-1;c=in();
		mp[a][b]=mp[b][a]=c;
	}memset(f,-0X3F,sizeof(f));f[1][0]=0;
	for (int s=0;s<(1<<n);++s)
	for (int i=0;i<n;++i) if (s&(1<<i))
	for (int j=i+1;j<n;++j) if (s&(1<<j)) sum[s]+=mp[i][j];
	for (int s=0;s<(1<<n);++s)
	for (int i=0;i<n;++i) if (s&(1<<i)){
		for (int j=0;j<n;++j)
		if (!(s&(1<<j))&&mp[i][j])
		f[s|(1<<j)][j]=max(f[s|(1<<j)][j],f[s][i]+mp[i][j]);
		int r=((1<<n)-1)-s;
		for (int t=r;t;t=((t-1)&r)) f[s|t][i]=max(f[s|t][i],f[s][i]+sum[t+(1<<i)]);
	}
	printf("%d",sum[(1<<n)-1]-f[(1<<n)-1][n-1]);return 0;
}

Measured memory_bytes: 4480
class Trio:
    __pre=None
    __val=None
    __nex=None
    def __init__(self,val,p=None,n=None):
        self.__pre=p
        self.__val=val
        self.__nex=n
    
    def get_pre(self):return self.__pre
    
    def get_nex(self):return self.__nex
    
    def set_nex(self,n):self.__nex=n
    
    def set_val(self,n):self.__val=n
    
    def get_val(self):return self.__val

class Stack:
    member=Trio(None)
    def __init__(self,stri):
        if(isinstance(stri,str)):
            for i,e in enumerate(stri):
                if(i==0):
                    self.member.set_val(e)
                else:
                    self.push(e)

    
    def push(self,n):
        self.member.set_nex(Trio(n,self.member,None))
        self.member=self.member.get_nex()

    def pop(self):
        if(self.member==None):
            return None
        d=self.member.get_val()
        self.member=self.member.get_pre()
        return d

s=input()
stk = Stack(None)
stri=""
for i in s:
    if(i==" "):
        stk.push(stri)
        stri=""
    elif(i.isdigit()):
        stri="".join([stri,i])
    elif(i=="+" or i=="-" or i=="*"):
        b=stk.pop()
        b=int(b)
        a=int(stk.pop())
        if(i=="+"):
            stri=(str(a+b))
        elif(i=="-"):
            stri=(str(a-b))
        else:
            stri=(str(a*b))

print(stri)

Measured memory_bytes: 7748
#include <bits/stdc++.h>
#define ll long long int
#define mod_ceil(a, b) (a % b) ? a / b + 1 : a / b
using namespace std;

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

    ll n, tmp = 0, x;
    cin >> n;
    vector<ll> A(n);
    vector<ll> sum(n);
    for (ll i = 0; i < n; i++)
    {
        cin >> x;
        sum[i] = x + tmp;
        tmp = sum[i];
    }
    vector<ll> sum1 = sum;

    // positive
    ll ans = 0, prev = 0, ans1 = 0;
    for (ll i = 0; i < n; i++)
    {
        sum[i] += prev;
        if (i % 2 == 0 and not(sum[i] > 0))
        {
            prev += -sum[i] + 1;
            ans += -sum[i] + 1;
            sum[i] = -sum[i] + 1;
        }
        if (i % 2 == 1 and not(sum[i] < 0))
        {
            prev += -sum[i] - 1;
            ans += sum[i] + 1;
            sum[i] = -sum[i] - 1;
        }
    }

    // negative
    prev = 0;
    for (ll i = 0; i < n; i++)
    {
        sum1[i] += prev;
        if (i % 2 == 1 and not(sum1[i] > 0))
        {
            prev += -sum1[i] + 1;
            ans1 += -sum1[i] + 1;
            sum1[i] = -sum1[i] + 1;
        }
        if (i % 2 == 0 and not(sum1[i] < 0))
        {
            prev += -sum1[i] - 1;
            ans1 += sum1[i] + 1;
            sum1[i] = -sum1[i] - 1;
        }
    }

    cout << min(ans, ans1) << endl;
}

Measured memory_bytes: 2560
import java.util.Scanner;

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

        int result = 0;
        for(int i = 1; i <= n; i++) {
            int sum = 0;
            int j = i;
            while (j != 0) {
              sum += j % 10;
              j /= 10;
            }
            if ((a <= sum) && (sum <= b)) {
                result += i;
            }
        }
        System.out.println(result);
    }
}


Measured memory_bytes: 21844
#include <stdio.h>
#include <vector>
#include <algorithm>

using namespace std;

int main(){
	int n,loc1,loc2;
	double x1,x2,x3,y1,y2,y3,xp,yp,xq,yq;
	double calc1,calc2,calc3,calc4,calc5,calc6;


	scanf("%d",&n);

	for(int i = 0; i < n; i++){
		scanf("%lf %lf %lf %lf %lf %lf %lf %lf %lf %lf",&x1,&y1,&x2,&y2,&x3,&y3,&xp,&yp,&xq,&yq);

		calc1 = (x2-x1)*(yp-y1)-(y2-y1)*(xp-x1);
		calc2 = (x3-x2)*(yp-y2)-(y3-y2)*(xp-x2);
		calc3 = (x1-x3)*(yp-y3)-(y1-y3)*(xp-x3);

		calc4 = (x2-x1)*(yq-y1)-(y2-y1)*(xq-x1);
		calc5 = (x3-x2)*(yq-y2)-(y3-y2)*(xq-x2);
		calc6 = (x1-x3)*(yq-y3)-(y1-y3)*(xq-x3);

		if((calc1>0&&calc2>0&&calc3>0) || (calc1<0&&calc2<0&&calc3<0)){
			loc1 = 0;
		}else{
			loc1 = 1;
		}

		if((calc4>0&&calc5>0&&calc6>0) || (calc4<0&&calc5<0&&calc6<0)){
			loc2 = 0;
		}else{
			loc2 = 1;
		}

		if(loc1 == loc2)printf("NG\n");
		else{
			printf("OK\n");
		}

	}

    return 0;
}

Measured memory_bytes: 2576
# coding: utf-8

def f(n, k, h):
    dp = [0 for _ in range(n)]
    for i in range(1, n):
        js = max(i - k, 0)
        dp[i] = min(dp[j] + abs(h[i] - h[j]) \
            for j in range(js, i))
        # print(dp)
    return(dp[i])

n, k = map(int, input().rstrip().split())    # 2 <= n <= 10^5, 1 <= k <= 100
h = list(map(int, input().rstrip().split()))

print(f(n, k, h))


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

int main() {
    int n;
    vector<string> s;
    cin >> n;
    for (int i = 0; i < n; i++) {
        string c;
        cin >> c;
        s.push_back(c);
    }

    vector<string> last_a;
    vector<string> first_b;
    vector<string> other;
    for (int i = 0; i < n; i++) {
        string t = s[i];
        //先頭がBの文字列と末尾Aの文字列とその他に分ける
        if (t[t.size() - 1] == 'A') last_a.push_back(t);
        else if (t[0] == 'B') first_b.push_back(t);
        else other.push_back(t);
    }
    //先頭Bで末尾Aの文字列とそうではないものに分ける
    vector<string> last_a1; //BOOOA
    vector<string> last_a2; //OOOOA
    for (int i = 0; i < last_a.size(); i++) {
        string t = last_a[i];
        if (t[0] == 'B') last_a1.push_back(t);
        else last_a2.push_back(t);
    }

    string ans;
    //先頭がBではない末尾Aの文字列を一つ入れる
    if (!last_a2.empty()) {
        ans += last_a2[last_a2.size() - 1]; //OOOOA
        last_a2.pop_back();
    }
    //先頭がBでAが末尾を接続
    if (!last_a1.empty()) {
        for (int i = last_a1.size() - 1; i >= 0; i--) {
            ans += last_a1[i]; //BOOOA
        }
    }
    //先頭がBではない末尾Aの文字列を一つ入れる
    if (!first_b.empty()) {
        ans += first_b[first_b.size() - 1]; //BOOOO
        first_b.pop_back();
    }
    //この時点でOOOOABOOOABOOOO
    int j = last_a2.size() - 1;
    int k = first_b.size() - 1;
    while (1) {
        if (j < 0 && k < 0) break;

        if (j >= 0) {
            ans += last_a2[j]; //OOOOA
            j--;
        }
        if (k >= 0) {
            ans += first_b[k]; //BOOOO
            k--;
        }
    }

    for (int i = other.size() - 1; i >= 0; i--) {
        ans += other[i]; //OOOOOO
    }
    
    int cnt = 0;
    for (int i = 0; i < ans.size() - 1; i++) {
        if (ans[i] == 'A' && ans[i + 1] == 'B') cnt++;
    }

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

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

int main(){
  string a,b;
  cin >> a >> b;
  vector<char>ast(a.size());
  vector<char>bst(b.size());
  for(int i=0;i<a.size();i++)
    ast.at(i)=a.at(i);
  for(int i=0;i<b.size();i++)
    bst.at(i)=b.at(i);
  sort(ast.begin(),ast.end());
  sort(bst.begin(),bst.end(),greater());
  bool ans=false,br=false;
  for(int i=0;i<min(ast.size(),bst.size());i++){
    if(ast.at(i)!=bst.at(i)){
      if(ast.at(i)<bst.at(i))
        ans=true;
      else
        ans=false;
      br=true;
      break;
    }
  }
  if(!br)
    ans=a.size()<b.size();
  cout << (ans?"Yes":"No") << endl;
}

Measured memory_bytes: 3564
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define FOR(i, a, b) for(int i=(a);i<(b);++i)
#define rep(i, n) FOR(i, 0, n)
#define whole(x) (x).begin(),(x).end()
#define UNIQUE(v) v.erase(unique(v.begin(), v.end()), v.end())
using 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 k;
  cin >> k;
  cout << k/2*(k-k/2) << endl;
  return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<climits>
 
using namespace std;
 
int ans[100001]={-1};
 
int main(){
    int n=0;
    cin>>n;
	for(int i=1;i<n+1;i++){
		ans[i]=INT_MAX;
	}
    for(int i=0;i<n;i++){
        int input=0;
        cin>>input;
		ans[lower_bound(ans,ans+n,input)-ans]=input;
	}
	cout<<lower_bound(ans,ans+n+1,INT_MAX)-ans-1<<endl;
    return 0;
}

Measured memory_bytes: 1548
n = int(input())
a = []
for i in range(n):
  a1 = list(map(int, input().split()))
  a.append(a1)
a.reverse()
ans = 0
b = 0
for i in a:
  if i[1] != 1:
    c = i[1] - (i[0]+b) % i[1]
    if c == i[1]:
      c = 0
    ans += c
    b += c
print(ans)

Measured memory_bytes: 27380
import sys
def t(A,p,r):
 x=A[r][1];i=p-1
 for j in range(p,r):
  if A[j][1]<=x:i+=1;A[i],A[j]=A[j],A[i]
 A[i+1],A[r]=A[r],A[i+1]
 return i+1
def k(A,p,r):
 if p<r:q=t(A,p,r);k(A,p,q-1);k(A,q+1,r)
def s(A):
 for i in range(n-1):
  if A[i][1]==A[i+1][1]:
   if A[i][2]>A[i+1][2]:return 0
 return 1
n=int(input())
f=lambda x,i:(x[0],int(x[1]),i)
A=[f(sys.stdin.readline().split(),i)for i in range(n)]
k(A,0,n-1)
print(['Not s','S'][s(A)]+'table')
for e in A:print(*e[:2])


Measured memory_bytes: 20428
#include<stdio.h>

int main(){
    int n;
    scanf("%d",&n);

    if(n % 10  == 3)printf("bon\n");
    else if(n % 10 == 0 || n % 10 == 1 || n % 10 == 6 || n % 10 == 8)printf("pon\n");
    else printf("hon\n");
    return 0;
}

Measured memory_bytes: 1656
#include"bits/stdc++.h"
using namespace std;
#define int int64_t
int32_t main()
{
    ios::sync_with_stdio(false);
    cin.tie(NULL);
    string ans;cin>>ans;
    cout<<ans[0]<<ans[1]<<ans[2]<<"\n";
    return 0;
}



Measured memory_bytes: 3636
#include <bits/stdc++.h> 
using namespace std;
#define ll long long 
#define f(i, a, b) for(ll i=a;i<b;i++)
#define fi(i, a, b) for(ll i=b-1;i>=a;i--)
#define pb push_back
#define vi vector<int>
#define vl vector<ll>
#define ml map<ll,ll> 
#define pll pair<ll,ll>

ll M = (ll)(1e9+7);

void solve()
{
   ll n,k;
   cin>>n>>k;     
   ll a[n];
   f(i,0,n)
   cin>>a[i];
   ll dp[n+1][k+1];
   f(i,0,k+1)
   if(i<=a[0]) dp[1][i]=1;
   else dp[1][i]=0;
   f(i,2,n+1)
   dp[i][0]=1;
   
   f(i,2,n+1)
   {
      ll to_add = dp[i-1][0];
      f(j,1,k+1){
         if(j<=a[i-1])
         {
            to_add +=(dp[i-1][j]);
            to_add%=M;
            dp[i][j] = to_add;
         }
         else
         {
            to_add+=(dp[i-1][j]-dp[i-1][j-a[i-1]-1]);
            to_add = (to_add+M)%M;
            dp[i][j] = to_add;
         }
         // cout<<i<<" "<<j<<" "<<dp[i][j]<<"\n";
      }
   }
   cout<<dp[n][k];

}

int main()
{
   ll t;
   t=1;
//    cin>>t;
   while (t--)
   {
       solve();
   }  
}

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

typedef struct process {
public:
    int time;
    string name;
};

int main() {
    int n, q;
    cin >> n >> q;
    process* a = new process[n];
    for (int i = 0; i < n; i++) {
        cin >> a[i].name >> a[i].time;
    }
    int count = 0;
    int keika = 0;
    int counts = 0;
    while (1) {
        int flag = 0;
        a[count].time -= q;
        if (a[count].time <= 0) {
            keika += q + a[count].time;
            cout << a[count].name << " " << keika << endl;
            if (n == 1)break;
        }
        else {
            keika += q;
        }
        count++;
        if (count == n) {
            int iranai = -1;
            int flag = 0;
            int nokori = 0;
            int i = 0;
            while (i < n) {
                if (a[i].time <= 0) {
                    if (flag == 0)iranai = i;
                    flag++;
                }
                else if (flag > 0) {
                    a[iranai] = a[i];
                    a[i].time = 0;
                    i = iranai;
                    flag = 0;
                    nokori++;
                }
                else {
                    nokori++;
                }
                i++;
            }
            n = nokori;
            count = 0;
        }
        if (n <= 0)break;
    }
    delete[] a;
    return 0;
}


Measured memory_bytes: 5920
#include <map>
#include <set>
#include <ctime>
#include <cmath>
#include <queue>
#include <stack>
#include <ctime>
#include <string>
#include <vector>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <iostream>
#include <algorithm>
//#include <random>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef double db;
#define PB push_back
#define MP make_pair
#define INF 2073741824
#define inf 1152921504606846976
#define pi 3.14159265358979323846
//#pragma comment(linker,"/STACK:10240000,10240000")
//mt19937 rand_(time(0));
const int N=3e5+7,M=2e6;
const long long mod=1e9+7;
inline int read(){int ret=0;char ch=getchar();bool f=1;for(;!isdigit(ch);ch=getchar()) f^=!(ch^'-');for(;isdigit(ch);ch=getchar()) ret=(ret<<1)+(ret<<3)+ch-48;return f?ret:-ret;}
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
ll ksm(ll a,ll b,ll mod){int ans=1;while(b){if(b&1) ans=(ans*a)%mod;a=(a*a)%mod;b>>=1;}return ans;}
ll inv2(ll a,ll mod){return ksm(a,mod-2,mod);}//逆元
//int head[N],NEXT[M],ver[M],tot;void link(int u,int v){ver[++tot]=v;NEXT[tot]=head[u];head[u]=tot;}

int a[N],dp[N];
int main(){
    //freopen("1.txt","r",stdin);
    //ios::sync_with_stdio(false);
    int n,k;
    scanf("%d%d",&n,&k);
    for(int i=1;i<=n;i++){
        scanf("%d",&a[i]);
        dp[i]=INF;
    }
    dp[1]=0;
    for(int i=1;i<=n;i++){
        for(int j=max(i-k,1);j<=i;j++){
            dp[i]=min(dp[j]+abs(a[i]-a[j]),dp[i]);
        }
    }
    printf("%d\n",dp[n]);
    //cout << "time: " << (long long)clock() * 1000 / CLOCKS_PER_SEC << " ms" << endl;
    return 0;
}




Measured memory_bytes: 1024
#include <bits/stdc++.h>
#define int long long 
 
#define _overload(_1,_2,_3,name,...) name
#define _rep(i,n) _range(i,0,n)
#define _range(i,a,b) for(int i=(int)(a);i<(int)(b);++i)
#define rep(...) _overload(__VA_ARGS__,_range,_rep,)(__VA_ARGS__)
 
#define _rrep(i,n) _rrange(i,n,0)
#define _rrange(i,a,b) for(int i=(int)(a)-1;i>=(int)(b);--i)
#define rrep(...) _overload(__VA_ARGS__,_rrange,_rrep,)(__VA_ARGS__)
 
#define _all(arg) begin(arg),end(arg)
#define uniq(arg) sort(_all(arg)),(arg).erase(unique(_all(arg)),end(arg))
#define getidx(ary,key) lower_bound(_all(ary),key)-begin(ary)
#define clr(a,b) memset((a),(b),sizeof(a))
#define bit(n) (1LL<<(n))
 
// #define DEBUG
 
#ifdef DEBUG
    #define dump(...) fprintf(stderr, __VA_ARGS__)
#else
    #define dump(...)
#endif
 
template<class T>bool chmax(T &a, const T &b) { return (a<b)?(a=b,1):0;}
template<class T>bool chmin(T &a, const T &b) { return (b<a)?(a=b,1):0;}
 
using namespace std;
using ll=long long;
using vi=vector<int>;
using vll=vector<ll>;
 
const double EPS = 1e-10;
const double PI = acos(-1.0);
const ll inf =1LL << 62;
const ll mod=1000000007LL;
const int dx[4]={1,0,-1,0};
const int dy[4]={0,1,0,-1};
 
 
ll extgcd(ll a,ll b,ll& x,ll& y){x=1,y=0;ll g=a;if(b!=0) g=extgcd(b,a%b,y,x),y-=a/b*x;return g;}
ll ADD(const ll &a, const ll &b,const ll &mod) { return (a+b)%mod;}
ll SUB(const ll &a, const ll &b,const ll &mod) { return (a-b+mod)%mod;}
ll MUL(const ll &a, const ll &b,const ll &mod) { return (1LL*a*b)%mod;}
ll DIV(const ll &a, const ll &b,const ll &mod) {ll x,y; extgcd(b,mod,x,y);return MUL(a,(x+mod)%mod,mod);}
 
random_device rd;
mt19937 mt(rd());
uniform_int_distribution<int> dice(1,6);
uniform_real_distribution<double> score(0.0,10.0);

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

    int n; cin >> n;
    vll A(n); for(auto& e : A) cin >> e;

    int M = 61;
    vll hist(M);
    for(auto& e : A){
        rep(i, M){
            if((e >> i) & 1){
                hist[i]++;
            }
        }
    }

    ll res = 0LL;
    rep(i, M){
        hist[i] = max(0LL, hist[i] * (n - hist[i])) % mod;
        ll mul = (1LL << i) % mod;
        ll val = MUL(hist[i], mul, mod);

        res = ADD(res, val, mod);
    }

    cout << res << endl;

    return 0;
}


Measured memory_bytes: 2560
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < n; i++)
#define REPR(i, n) for (int i = n; i >= 0; i--)
#define FOR(i, m, n) for (int i = m; i < n; i++)
#define ALL(v) v.begin(), v.end()
using namespace std;
typedef long long ll;
typedef long double ld;
int main()
{
  int m,n,c;
  cin >> n >> m >> c;
  vector<int> a(m),b(m);
  REP(i,m) cin >> b[i];
  int cnt=0;
  REP(i,n){
    int sum = c;
    REP(j,m){
      cin >> a[j];
      sum += a[j]*b[j];
    }
    if(sum>0) cnt++;
  }
  cout << cnt << endl;
  return 0;
}


Measured memory_bytes: 256
import math as m
from Queue import Queue

class Program:
    
    def main(self):
        a = int(raw_input())
        b = int(raw_input())
        h = int(raw_input())
        
        ans = (a + b) * h * 1 / 2
        print ans
        
if __name__ == '__main__':
    p=Program();
    p.main()

Measured memory_bytes: 3308
import java.util.Scanner;
public class Main{
	public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int w = sc.nextInt();
        int n = sc.nextInt();
        int[] a = new int[n];
        int[] b = new int[n];
        for(int i = 0; i < n; i++){
            String s = sc.next();
            String[] S = s.split(",");
            a[i] = Integer.parseInt(S[0]);
            b[i] = Integer.parseInt(S[1]);
        }
        int[] ans = new int[w];
        for(int i = 0; i < w; i++){
            int x = i + 1;
            for(int j = 0; j < n; j++){
                if(a[j] == x) x = b[j];
                else if(b[j] == x) x = a[j];
            }
            ans[x - 1] = i + 1;
        }

        for(int i = 0; i < w; i++){
            System.out.println(ans[i]);
        }

        sc.close();
        
    }
}



Measured memory_bytes: 26092
#include "bits/stdc++.h"
using namespace std;

static const int N=1000;
int lcs(string X,string Y){
	int c[N+1][N+1];
	int m=X.length();
	int n=Y.length();
	int maxl=0;
	X= " " +X;
	Y= " " +Y;
	for (int i = 0; i <= m; ++i) {c[i][0]=0;	}
	for (int j = 0; j <= n; ++j) {c[0][j]=0;	}

	for (int i = 1; i <= m; ++i) {
		for (int j = 1; j <= n; ++j) {
			if(X[i]==Y[j]){
				c[i][j]=c[i-1][j-1]+1;
			}else{
				c[i][j]=max(c[i-1][j],c[i][j-1]);
			}
			maxl=max(maxl,c[i][j]);
		}
	}
	return maxl;
}

int main(){
string s1,s2;
int n;cin>>n;
for (int i = 0; i < n; ++i) {
	cin>>s1;
	cin>>s2;
	cout<<lcs(s1,s2)<<endl;
}
	return 0;
}

Measured memory_bytes: 7068
#include <stdio.h>
#include <string.h>
#define LEN 100005

typedef struct pp{
  char name[100];
  int t;
}P;

P Q[LEN+1];
int head, tail, n;

void enqueue(P x){
  Q[tail] = x;
  tail = (tail + 1) % LEN;
}

P dequeue(){
  P x;
  x = Q[head];
  head = (head + 1) % LEN;

  return x;
}

int min(int a,int b)
{
  if(a > b) return b;
  else return a;
}



int main(){
  int elaps = 0, c;
  int i, q;
  P u;
  scanf("%d %d", &n, &q);

  for ( i = 1; i <= n; i++){
    scanf("%s", Q[i].name);
    scanf("%d", &Q[i].t);
  }
  head = 1;
  tail = n + 1;

  while(head != tail)
    {
      u = dequeue();
      c = min(q,u.t);

      u.t -= c;
      elaps += c;
      
      if(u.t > 0) enqueue(u);
      else printf("%s %d\n",u.name,elaps);
    }
  
  return 0;
}



Measured memory_bytes: 11888
import sys

input = sys.stdin.readline


def main():
    N = int(input())
    A = [0] * N
    for i in range(N):
        A[i] = int(input())

    if N == 1:
        ans = A[0] // 2
    else:
        ans = 0
        for i in range(N - 1):
            if A[i + 1] == 0:
                ans += A[i] // 2
            else:
                q, r = divmod(A[i] + A[i + 1], 2)
                ans += q
                A[i + 1] = r

    print(ans)


if __name__ == "__main__":
    main()


Measured memory_bytes: 12620
#include<bits/stdc++.h>
typedef long long int ll;
typedef unsigned long long int ull;
#define BIG_NUM 2000000000
#define HUGE_NUM 1000000000000000000
#define MOD 1000000007
#define EPS 0.000000001
using namespace std;




int main(){

	char S[105],T[105];

	scanf("%s %s",S,T);

	int len;
	for(len = 0; S[len] != '\0'; len++);

	for(int head = 0; head <= len-1; head++){
		bool FLG = true;
		for(int k = 0; k < len; k++){
			if(S[(head+k)%len] != T[k]){
				FLG = false;
				break;
			}
		}

		if(FLG){

			printf("Yes\n");
			return 0;
		}
	}

	printf("No\n");

	return 0;
}


Measured memory_bytes: 3760
import sys
sys.setrecursionlimit(10**6)

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

costs = [0]*n
for i in range(q):
    p, x = map(int, input().split())
    costs[p-1]+=x
visited = [0]*n

def dfs(idx):
    visited[idx]=1
    for i in g[idx]:
        if visited[i]==1:
            continue
        costs[i]+=costs[idx]
        dfs(i)
    return

dfs(0)
print(*costs)

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

using namespace std;

typedef long long ll;

const int MOD = 1e9 + 7; // change if needed

struct Modint {
  ll val;
  
  Modint (ll _val = 0)
    : val(_val % MOD) {}

  Modint operator+ (Modint other) const {
    return Modint(val + other.val);
  }

  void operator+= (Modint other) {
    val += other.val;
    val %= MOD;
  }

  Modint operator- () const {
    return Modint(MOD - val);
  }

  Modint operator- (Modint other) const {
    return Modint(val + MOD - other.val);
  }

  void operator-= (Modint other) {
    val += MOD - other.val;
    val %= MOD;
  }

  Modint operator* (Modint other) const {
    return Modint(val * other.val);
  }

  void operator*= (Modint other) {
    val *= other.val;
    val %= MOD;
  }

  bool operator== (Modint other) const {
    return val == other.val;
  }

  bool operator!= (Modint other) const {
    return val != other.val;
  }
};

Modint exp (Modint a, int k) {
  if (k == 0) {
    return Modint(1);
  } else if (k % 2 == 0) {
    Modint half = exp(a, k / 2);
    return half * half;
  } else {
    return a * exp(a, k - 1);
  }
}

Modint inv (Modint a) {
  return exp(a, MOD - 2);
}

ostream& operator<< (ostream& out, Modint p) {
  out << p.val;
  return out;
}

const int MAX_N = 1e3 + 5;

int root [MAX_N];

int find (int u) {
  if (root[u] != u) {
    root[u] = find(root[u]);
  }
  return root[u];
}

void merge (int u, int v) {
  u = find(u);
  v = find(v);

  root[u] = v;
}

void reset () {
  for (int i = 0; i < MAX_N; i++) {
    root[i] = i;
  }
}

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

  ll X;
  cin >> X;
  
  vector<pair<ll, pair<int, int>>> edges (m);
  for (int i = 0; i < m; i++) {
    cin >> edges[i].second.first >> edges[i].second.second >> edges[i].first;
  }

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

  int cl = 0, ce = 0, cg = 0;
  for (int i = 0; i < m; i++) {
    reset();
    ll curw = 0;
    if (1) {
      int u = edges[i].second.first;
      int v = edges[i].second.second;
      ll w = edges[i].first;

      if (find(u) != find(v)) {
        merge(u, v);
        curw += w;
      }      
    }
    
    for (int j = 0; j < m; j++) {
      if (j != i) {
        int u = edges[j].second.first;
        int v = edges[j].second.second;
        ll w = edges[j].first;

        if (find(u) != find(v)) {
          merge(u, v);
          curw += w;
        }
      }
    }

    if (curw < X) cl++;
    else if (curw == X) ce++;
    else if (curw > X) cg++;
  }

  if (cl == 0) {
    if (ce == 0) {
      cout << 0 << endl;
    } else {
      cout << (exp(Modint(2), ce) - 2) * exp(Modint(2), cg) << endl;
    }
  } else {
    cout << Modint(2) * (exp(Modint(2), ce) - 1) * exp(Modint(2), cg) << endl;
  }
}


Measured memory_bytes: 256
import java.io.*;

public class Main {

    public static void main(String[] args) throws IOException {

        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        String[] line = br.readLine().split(" ");
        int a = Integer.parseInt(line[0]);
        int b = Integer.parseInt(line[1]);

        int d, r;
        double f;

        d = (int) ((int) a / b);
        r = (int) (a % b);
        f = (double) a / (double) b;

        System.out.printf("%d %d %.5f", d, r, f);

    }

}

Measured memory_bytes: 24984
N=int(input())
A=list(map(int,input().split()))
B=[]
C=[]
D=[]

for i in range(N):
  if A[i]<0:
    B.append(A[i])
  elif A[i]==0:
    C.append(A[i])
  else:
    D.append(A[i])

ans=[]
anss=0

if len(B)>0 and len(D)>0:
  for i in C:
    ans.append((B[0],0))
  for i in range(len(D)-1):
    ans.append((B[0],D[i]))
    B[0]-=D[i]
  for i in range(len(B)):
    ans.append((D[-1],B[i]))
    D[-1]-=B[i]
  anss=D[-1]

elif len(C)>0:
  for i in range(len(C)-1):
    ans.append((0,0))
  for i in B:
    ans.append((anss,i))
    anss-=i
  if(len(D)>0):
    for i in range(len(D)-1):
      ans.append((anss,D[i]))
      anss-=D[i]
    ans.append((D[-1],anss))
    anss=D[-1]-anss

else:
  E=sorted(B,reverse=True)+sorted(D)
  anss=E[0]
  for i in range(len(E)-2):
    ans.append((anss,E[i+1]))
    anss-=E[i+1]
  if anss<=0:
    ans.append((E[-1],anss))
    anss=E[-1]-anss
  else:
    ans.append((anss,E[-1]))
    anss-=E[-1]

print(anss)
for i in ans:
  print(*i)

Measured memory_bytes: 63468
#include<stdio.h>

int main(void){
    long n, max1=0, max2=0, maxnum=0;/*max1最大値, その次 */
    scanf("%ld", &n);
    long a[n];
    for(long i=0; i<n; i++){
        scanf("%ld", &a[i]);
        if(a[i] > max1){
            max2 = max1; 
            max1 = a[i];
            maxnum = i;//最大値を持つiを保存しておく
        } 
        else if(a[i] <= max1 && a[i] > max2) max2 = a[i];
    } 
    puts("");
    for(long i=0; i<n; i++){
        if(i == maxnum){
            printf("%ld\n", max2);
        }else{
            printf("%ld\n", max1);
        }
    }

    return 0;
}

Measured memory_bytes: 3072
#include<bits/stdc++.h>
using namespace std;
void solve()
{
int n;
  cin>>n;
  int arr[n];
  for(int i=0;i<n;i++)
    cin>>arr[i];
  long long ans=0;
  
  for(int i=1;i<n;i++)
  { 
    if(arr[i]<arr[i-1])
    {
    ans+=(arr[i-1]-arr[i]);
      arr[i]=arr[i-1];
    }
   
    
    
  }
  cout<<ans<<endl;
  
  
}
int main()
{
solve();
}


Measured memory_bytes: 4376
#include <vector>
#include <list>
#include <map>
#include <set>
#include <unordered_set>
#include <unordered_map>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <queue>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>
#include <fstream>
#include <cstdio>
#include <complex>
#include <cstdint>
#include <tuple>

#define M_PI       3.14159265358979323846

using namespace std;

//conversion
//------------------------------------------
inline int toInt(string s) { int v; istringstream sin(s); sin >> v; return v; }
template<class T> inline string toString(T x) { ostringstream sout; sout << x; return sout.str(); }
inline int readInt() { int x; scanf("%d", &x); return x; }

//typedef
//------------------------------------------
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef pair<int, PII> TIII;
typedef long long LL;
typedef unsigned long long ULL;
typedef vector<LL> VLL;
typedef vector<VLL> VVLL;

//container util

//------------------------------------------
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define SQ(a) ((a)*(a))
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())

//repetition
//------------------------------------------
#define FOR(i,s,n) for(int i=s;i<(int)n;++i)
#define REP(i,n) FOR(i,0,n)
#define MOD 1000000007

using edge = PII;// weight, to
using node = vector<edge>;
using graph = vector<node>;

LL pow2(int p) {
	LL ret = 1;
	REP(i, p) {
		ret <<= 1;
		ret %= MOD;
	}
	return ret;
}

LL getMST(const graph& g, int u, int v) {
	vector<bool> visit(g.size());
	visit[u] = visit[v] = true;
	priority_queue<PII, vector<PII>, greater<PII>> q;
	for (auto e : g[u]) if(!visit[e.second])q.push(e);
	for (auto e : g[v]) if (!visit[e.second])q.push(e);
	LL ans = 0;
	while (!q.empty()) {
		auto tmp = q.top();
		q.pop();
		if (visit[tmp.second])continue;
		visit[tmp.second] = true;
		ans += tmp.first;
		for (auto e : g[tmp.second]) if (!visit[e.second])q.push(e);
	}
	return ans;
}

int main() {
	int n, m;
	LL x;
	scanf("%d%d%lld", &n, &m, &x);
	auto g = graph(n);
	REP(i, m) {
		int u, v, w;
		scanf("%d%d%d", &u, &v, &w);
		u--, v--;
		g[u].PB(edge(w, v));
		g[v].PB(edge(w, u));
	}
	int c0 = 0, c1 = 0, c2 = 0;
	REP(i, n) {
		for (auto e : g[i]) {
			if (e.second < i)continue;
			LL w = getMST(g, i, e.second) + e.first;
			if (w == x) c1++;
			else if (w > x)c2++;
			else c0++;
		}
	}
	LL ans = (c0==0)?1:2;
	if (c1 == 0)ans = 0;
	ans *= pow2(c1) + MOD - 1 - (c0==0);
	ans %= MOD;
	ans *= pow2(c2);
	ans %= MOD;
	cout << ans << endl;
	return 0;
}

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

using namespace std;
using ll = long long int;

int main()
{
    ll w, h, x, y;
    cin >> w >> h >> x >> y;
    double area = (w * h) * 0.5;
    cout << fixed << setprecision(9);
    if(w % 2 == 0 && h % 2 == 0){
        if(x == w / 2 && y == h / 2){
            cout << area << " " << 1 << endl;
            return 0;
        }
    }
    cout << area << " " << 0 << endl;
}

Measured memory_bytes: 888