akhauriyash/Code-Regression huggingface dataset:
(defun string->duplicates-removed-list (string)
  (declare (optimize (speed 3) (safety 0) (debug 0)))
  (labels ((rec (n acc)
             (if (= n -1)
                 acc
                 (let ((c (char string n)))
                   (if (member c acc)
                       (rec (1- n) acc)
                       (rec (1- n) (cons c acc)))))))
    (rec (1- (length string)) nil)))

(defun f (str)
  (declare (optimize (speed 3) (safety 0) (debug 0)))
  (labels ((rec (lst acc)
             (if (null lst)
                 acc
                 (rec (cdr lst) (* (1+ (count (car lst) str)) acc)))))
    (1- (rec (string->duplicates-removed-list str) 1))))

(defparameter *n* (read))
(defparameter *s* (read))

(print (round (mod (f (string *s*)) (+ (expt 10 9) 7))))


Measured memory_bytes: 15332
#include <iostream>
#include <stdio.h>
#include <algorithm>
#include <string>
#include <cmath>
#include <vector>
#include <functional>
#include <stack>
#include <utility>
#include <map>
#include <queue>
#include <set>
#include <array>
#include <climits>
#include <cassert>

using namespace std;

typedef long long ll;

ll n, a, b, x[100005], ans = 0;

int main() {
    cin >> n >> a >> b;
    for (int i = 0; i < n; i++) {
        cin >> x[i];
    }
    for(int i=1;i<n;i++){
        ans += min((x[i]-x[i-1])*a,b);
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int INF = 1e9;
const int MOD = 1e9+7;
const ll LINF = 1e18;
#define REP(i,n) for(ll i=0;i<(ll)(n);i++)
#define REPD(i,n) for(ll i=(ll)(n)-1;i>=0;i--)
#define FOR(i,a,b) for(ll i=(a);i<=(b);i++)
#define FORD(i,a,b) for(ll i=(a);i>=(b);i--)
#define ALL(x) (x).begin(),(x).end()
#define ALLR(x) (x).rbegin(),(x).rend()
#define SIZE(x) ((ll)(x).size())
#define MAX(x) *max_element(ALL(x))
#define MIN(x) *min_element(ALL(x))
#define SORTR(x) sort(ALLR(x));
#define SORT(x) sort(ALL(x));
#define SUM(x) accumulate(ALL(A), 0);
#define EACH(i,x) for(typeof((x).begin()) i=(x).begin(); i!=(x).end(); ++i)
typedef vector<ll> VI;
typedef vector<VI> VVI;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
template <class BidirectionalIterator>
bool next_partial_permutation(BidirectionalIterator first, BidirectionalIterator middle,BidirectionalIterator last){reverse(middle, last); return next_permutation(first , last);}


void Main()
{
	ll N,W;
	ll result=0;
	static ll dp[101][10100] = {};
	memset(dp, 0, sizeof(dp));
	cin>>N>>W;
	VI wei(N),val(N);
	REP(i, N) cin >> val[i]>>wei[i];

	REP(i,N){
		FOR(j,0,W){
			if(j>=wei[i]) dp[i+1][j]=max(dp[i+1][j-wei[i]]+val[i],dp[i][j]);
			else dp[i+1][j]=dp[i][j];
		}
	}
	result=dp[N][W];

	cout << result << "\n";
	return;
}

int main()
{
	std::cin.tie(0);
	std::ios_base::sync_with_stdio(false);
	std::cout << std::fixed << std::setprecision(15);
	Main();
}



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

typedef struct s_student{
	int	num;
	int	order;
}		t_student;

int	main()
{
	int		N;
	int		*stu;
	int		*order;

	scanf("%d\n", &N);
	stu = (int *)malloc(sizeof(int) * (N + 1));
	order = (int *)malloc(sizeof(int) * (N + 2));
	for (int i = 0; i < N; i++)
		scanf("%d ", &stu[i]);
	for (int i = 0; i < N; i++)
		order[stu[i]] = i + 1;
	for (int i = 1; i <= N; i++)
		printf("%d ", order[i]);
	printf("\n");
	return (0);
}

Measured memory_bytes: 1536
#include<bits/stdc++.h>
using namespace std;
int sz[55],f[55],x[55],y[55];
pair<int,int> Slope(int i,int j){
	return make_pair(x[j]-x[i],y[j]-y[i]);
}
int find(int x){
	return f[x]==x?x:f[x]=find(f[x]);
}
void merge(int a,int b){
	a=find(a);b=find(b);
	if(a!=b) sz[b]+=sz[a];
	f[a]=b;
}
signed main(){
	int n;
	cin>>n;
	for(int i=1;i<=n;++i)
		cin>>x[i]>>y[i];
	int ans=n;
	for(int i=1;i<=n;++i)
		for(int j=1;j<=n;++j){
			if(i==j) continue;
			for(int k=1;k<=n;++k)
				f[k]=k,sz[k]=1;
			int tmp=0;
			merge(i,j);
			for(int k=1;k<=n;++k)
				for(int l=1;l<=n;++l)
					if(k!=l && Slope(k,l)==Slope(i,j))
						merge(k,l);
			for(int k=1;k<=n;++k)
				if(find(k)==k) ++tmp;
			ans=min(ans,tmp);
		}
	cout<<ans;
	return 0;
}

Measured memory_bytes: 3620
#include<iostream>
using namespace std;
int main()
{
	int n;
	cin>>n;
	n%=10;
	if(n==3)
	{
		cout<<"bon"<<endl;
	}
	else if(n==0||n==1||n==6||n==8)
	{
		cout<<"pon"<<endl;
	}
	else
	{
		cout<<"hon"<<endl;
	}
	return 0;
}

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

int main()
{
	int n;
	cin >> n;
	vector<int>a(n);
	for(int i = 0;i<n;i++)
	{
		cin >> a[i];
	}
	int cnt = 0;
	for(int i = 0;i<n-2;i++)
	{
		if(a[i]<a[i+1]&&a[i+1]<a[i+2])
		{
			cnt++;
		}
		if(a[i]>a[i+1]&&a[i+1]>a[i+2])
		{
			cnt++;
		}
		
	}
	cout<<cnt<<endl;
	return 0;
}

Measured memory_bytes: 256
N, M, X = map(int,input().split())
skill_book = []
for i in range(N):
    skill_book.append(list(map(int, input().split())))
box = []
flag = 1
for i in range(1 << N):
    total = [0] * (M + 1)
    for j in range(N):
        if (i >> j) & 1:
            total = [x + y for (x, y) in zip(total, skill_book[j])]
    over = 1
    for j in range(1, len(total)):
        if not (total[j] >= X):
            over = 0
    if over == 1 and len(total) > 0:
        box.append(total[0])
if len(box) > 0:
    print(min(box))
else:
    print('-1')

Measured memory_bytes: 9200
#include <bits/stdc++.h>
#define rep(i,a,n) for(int i=a;i<n;i++)
#define repb(i,a,b) for(int i=a;i>=b;i--)
#define all(a) a.begin(),a.end()
#define o(a) cout<<a<<endl
#define int long long
#define fi first
#define se second
using namespace std;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int,int> pii;

//AOJ 0168(?????¢????????°)

int memo[31];

int dfs(int k) {
	if (k<= 1) return 1;
	if (k == 2) return 2;
	if (memo[k] == 0) {
		memo[k] = dfs(k - 1) + dfs(k - 2) + dfs(k - 3);
	}
	return memo[k];
}

signed main(){
	int n;
	while (cin>>n && n) {
		cout << (dfs(n) + 3649) / 3650 << endl;
	}
}

Measured memory_bytes: 1156
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ld long double
#define mp make_pair
#define pb push_back
#define yes "YES"
#define no "NO"
#define F first
#define S second
#define sorta(a) sort(a.begin(),a.end())
#define all(a) (a.begin(),a.end())
#define forn(i,a,b) for(i=a;i<b;i++)
long long mod =1000000007;
vector<ll>prime(10000001,1);
vector<ll>sdf(10000001,1);
long long inf=1000000000000000007;
//ll C[101][101];


int isprime(ll n)
{
    ll i;
    for(i=2;i*i<=n;i++)
    {
        if(n%i==0)
            {//cout<<i<<endl;
            return 0;}
    }
    return 1;
}
/*
int isperfectsq(ll n)
{


    long double x;
    x=(long double)(sqrt((long double )(n)));
    ll y=sqrt(n);
    if(x==y)
        return 1;
        else
            return 0;
}
*/
/*void ncr()
{
    C[0][0] = 1;
    for (int n = 1; n <= 500000; ++n) {
        C[n][0] = C[n][n] = 1;
        for (int k = 1; k < n; ++k)
            C[n][k] = C[n - 1][k - 1] + C[n - 1][k];
    }
}
*/
/*
void sieve()
{
    //cout<<"in1";
    ll i;
    //sdf[i]=1;
    ll j;
    prime[0]=prime[1]=0;
    for(i=2;i<=10000000;i++)
    {

            //isprime.push_back(i);
            for(j=i;j<=10000000;j+=i)
            {
                //prime[j]=0;

                sdf[j]++;
            }

    }

}
*/

long long modular_expo(long long x,long long y, long long mod)
{

    if(y==0)
        return 1;
    if(y%2==0)
        return modular_expo(((x%mod)*(x%mod))%mod,y/2,mod);
    if(y%2==1)
        return ((x%mod)*(modular_expo(((x%mod)*(x%mod))%mod,(y-1)/2,mod))%mod)%mod;


}
ll min3(ll a,ll b,ll c)
{
    ll m1=min(a,b);
    ll m2=min(a,c);
    return min(m1,m2);
}



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

    int n,i,j,k;
    cin>>n;
    vector<ll>a(n,0);
    for(i=0;i<n;i++)
        cin>>a[i];
    ll cnt=0;
   sorta(a);
    for(i=0;i<n;i++)
    {
        for(j=i+1;j<n;j++)
        {
            for(k=j+1;k<n;k++)
            {
                if(a[i]!=a[k]&&a[i]!=a[j]&&a[j]!=a[k]){
                if((a[i]+a[j])>a[k])
                  {
                       cnt++;
                       //cout<<i+1<<" "<<j+1<<" "<<k+1<<endl;
                  }
                }
            }
        }
    }
    cout<<cnt;

}




Measured memory_bytes: 159352
#pragma GCC optimize ("O3")
#include <bits/stdc++.h>
#define DEBUG true
#ifdef ONLINE_JUDGE
#undef DEBUG
#define DEBUG false
#endif 

using namespace std;

#define MAXN ((int)2e5+5)
#define MOD (100000009)
#define INF (100000009)
#define ll long long
#define _ << " " <<
#define CLEAR(a, b) memset(a, b, sizeof(a))
#define TRACE(x) if(DEBUG) cerr << #x << " = " << x << endl;
#define TRACE2(x,y) if(DEBUG) cerr << #x << " = " << x << " | " << #y << " = " << y << endl;
#define pb push_back
#define all(x) x.begin(), x.end()
#define endl "\n"
#define pii pair<int,int>
#define mid ((l+r)/2)

int n;
int h[MAXN];

void NO()
{
	cout << "No\n";
	exit(0);
}
int main()
{
	ios_base::sync_with_stdio(false);cin.tie(0);
	cin >> n;

	for (int i = 0; i < n; ++i)
		cin >> h[i];
	int last = h[n-1];

	for (int i = n-2; i >= 0; --i)
	{
		if(h[i] > last+1) NO();
		else
			last = min(h[i],last);
	}
	cout << "Yes\n";
}

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

// types
typedef long long ll;
typedef long double ld;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef pair<ld,ld> pdd;
typedef vector<ll> vll;

// macros
#define ALL(a) a.begin(),a.end()
#define SZ(a) ((int)a.size())
#define FI first
#define SE second
#define REP(i,n) for(int i=0;i<((int)n);i++)
#define REP1(i,n) for(int i=1;i<((int)n);i++)
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define PB push_back
#define EB emplace_back
#define MP(a,b) make_pair(a,b)
#define SORT_UNIQUE(c) (sort(c.begin(),c.end()), c.resize(distance(c.begin(),unique(c.begin(),c.end()))))
#define GET_POS(c,x) (lower_bound(c.begin(),c.end(),x)-c.begin())
#define Decimal fixed<<setprecision(20)
#define INF 1000000000
#define LLINF 1000000000000000000LL

// constants
const int inf = 1e9;
const ll linf = 1LL << 50;
const double eps = 1e-10;
const int MOD = 1e9 + 7;
const int dx[4] = {-1, 0, 1, 0};
const int dy[4] = {0, -1, 0, 1};


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

  ll n;
  cin >> n;
  string s;
  cin >> s;

  ll ans = 0;
  ll now = 0;
  REP(i, n){
    if(s[i] == 'I')
      now++;
    else
      now--;
    ans = max(ans, now);
  }

  cout << ans << endl;
}


Measured memory_bytes: 256
#include <stdio.h>
#include <stdbool.h>

int main(void) {
	long X;
	int y = 0;
	
	scanf("%ld", &X);
	
	for(long m = 100; m < X; y++, m*=1.01) {
		
	}
	
	printf("%d\n", y);
	
	return 0;
}


Measured memory_bytes: 1736
#include <bits/stdc++.h>
using namespace std;
int main() {
    string S;
    cin >> S;
    for(int bit = 0; bit < (1<<3); bit++) {

       int res = 0;
       string pm = "";
       for(int i = 0; i < 3; i++) {
           if (bit & (1<<i)) {
               res += S.at(3-i) - '0';
               pm += "+";
           } else {
               res -= S.at(3-i) - '0';
               pm += "-";
           }
       }
       res += S.at(0) - '0';
       if (res == 7) {
          cout << S[0] << pm[2] << S[1]<< pm[1] << S[2] << pm[0] << S[3] << "=7"<< endl;
          return 0;
       }
    }
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
using namespace std;
typedef long long  ll;

#define rep(i,s,n)for(ll i=s;i<n;i++)
#define repe(i,s,n)for(ll i=s;i<=n;i++)

int main()
{
	ll H, W; cin >> H >> W;
	char S[51][51];
	char T[51][51];
	rep(i, 0, H) {
		rep(j, 0, W) {
			char c;
			cin >> c;
			S[i][j] = c;
			T[i][j] = c;
		}
	}
	int x[8] = { 1,1,1,0,0,-1,-1,-1 };
	int y[8] = { 1,0,-1,1,-1,1,0,-1 };
	rep(i, 0, H) {
		rep(j, 0, W) {
			if (S[i][j] == '#') {
				continue;
			}
			ll cnt = 0;
			rep(k, 0, 8) {
				if (i + x[k] >= -1 && i + x[k] < H && j + y[k] < W && j + y[k] >= 0) {
					if (S[i + x[k]][j + y[k]] == '#') {
						cnt++;
					}
				}
			}
			T[i][j] = (char)(cnt + '0');
		}
	}
	rep(i, 0, H) {
		rep(j, 0, W) {
			cout << T[i][j];
		}
		cout << endl;
	}

	return 0;
}

Measured memory_bytes: 256
using System;
using System.Linq;

class Hello{

    public static void Main(){
    
        int h;
        int n;
        int[] a;
        
        var inpts = Console.ReadLine().Split(' ');
        h = int.Parse(inpts[0]);
        n = int.Parse(inpts[1]);
        var waza = Console.ReadLine().Split(' ');
        a = new int[n];
        for(int i = 0;i < n;i++){
            a[i] = int.Parse(waza[i]);
        }
        if(h <= a.Sum())
            Console.WriteLine("Yes");
        else
            Console.WriteLine("No");
        
    }

}

Measured memory_bytes: 17632
package main

import "fmt"

func main() {
	var s, t string
	fmt.Scan(&s, &t)
	if len(s) != len(t){
		return
	}

	count := 0
	for i:=0; i<len(s); i++{
		if s[i] != t[i]{
			count++
		}
	}

	fmt.Println(count)
}

Measured memory_bytes: 3388
#include <iostream>
using namespace std;
 
int main(){
  int A,B,C,D;
  int area1,area2;
  cin >> A >> B >> C >> D;
  area1 = A*B;
  area2 = C*D;
  if (area1>area2){
  	cout << area1;
  }
  else cout << area2;
}

Measured memory_bytes: 256
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <queue>
#include <vector>
#include <algorithm>

using namespace std;

struct edge{
	int to;
	long long cost;
};
typedef pair<int,int> P;

const int MAX_V = 100000;
const long long INF = 1000000000000000;

int N;
vector<edge> G[MAX_V];
long long d[MAX_V];
int Q;
int K;

void dijktsra(int s){
	priority_queue<P, vector<P>, greater<P> > que;
	fill(d,d+N,INF);
	d[s] = 0;
	que.push(P(0,s));

	while(!que.empty()){
		P p = que.top(); que.pop();
		int v = p.second;
		if(d[v] < p.first) continue;
		for(int i=0;i<G[v].size();i++){
			edge e = G[v][i];
			if(d[e.to] > d[v]+e.cost){
				d[e.to] = d[v] + e.cost;
				que.push(P(d[e.to], e.to));
			}
		}
	}
}

int main(){
	scanf("%d",&N);
	for(int i=0;i<N-1;i++){
		int a,b;
		long long c;
		scanf("%d %d %lld",&a,&b,&c);
		a--;b--;
		struct edge t;
		t.to = b;
		t.cost = c;
		G[a].push_back(t);
		struct edge e;
		e.to = a;
		e.cost = c;
		G[b].push_back(e);
	}

	scanf("%d %d",&Q,&K);
	K--;
	dijktsra(K);

	for(int i=0;i<Q;i++){
		int x,y;
		scanf("%d %d",&x,&y);
		x--;y--;
		printf("%lld\n",d[x]+d[y]);
	}

	return 0;
}


Measured memory_bytes: 9984
#include <bits/stdc++.h>
#include <iostream>
#include <algorithm>
#include <set>
#include <vector>
#include <string>
#include <sstream>
#include <cstdio>
#include <cstring>
#include<cctype>
#define INF 0x3f3f3f3f
#define lb long double
#define LINF 0x3f3f3f3f3f3f3f3f
#define ull unsigned long long
#define random(x) (rand()%x)
#define rep(i, a, b) for(int i=a;i<b;i++)
#define req(j, a, b) for(int j=a;j<b;j++)
#define mem(a, b) memset(a, b, sizeof(a))
#define PI 3.14
#define K 20

using namespace std;
typedef long long ll;
const int maxn = 1e6+5;
const double eps = 1e-14;
const double pi = acos(-1);
const ll mod = 1e9 + 7;
const int hash_mod = 19260817;

inline int read()
{
    int X=0,w=0; char ch=0;
    while(!isdigit(ch)) {w|=ch=='-';ch=getchar();}
    while(isdigit(ch)) X=(X<<3)+(X<<1)+(ch^48),ch=getchar();
    return w?-X:X;
}

inline double dbread()
{
    double X=0,Y=1.0; int w=0; char ch=0;
    while(!isdigit(ch)) {w|=ch=='-';ch=getchar();}
    while(isdigit(ch)) X=X*10+(ch^48),ch=getchar();
    ch=getchar();//读入小数点
    while(isdigit(ch)) X+=(Y/=10)*(ch^48),ch=getchar();
    return w?-X:X;
}

inline void write(int x)
{
    if(x<0) putchar('-'),x=-x;
    if(x>9) write(x/10);
    putchar(x%10+'0');
}

int v[1005];
double w[1005];
int dp[1005][1005];

int sum = 0;

int main()
{
    int n;
    n = read();
    string a, b;
    cin >> a >> b;
    int l = 2 * n;
    for(int i=0;i<l;i++)
    {
        if(i % 2 == 0)
            cout << a[i/2];
        else if(i % 2 == 1)
            cout << b[i/2];
    }
    return 0;
}


Measured memory_bytes: 256
object Main extends App {
	val pw = new java.io.PrintWriter(System.out)

	@scala.annotation.tailrec
	def loop(start: Int, end: Int)(f: Int => Unit): Unit =
		if (start < end) {
			f(start)
			loop(start + 1, end)(f)
		}

	val n	 = Scanner.nextInt
	val ok = Seq.fill(n)((Scanner.nextInt, Scanner.nextInt)).sortBy(_._2).foldLeft(Some(0): Option[Int]) {
		case (Some(now), (a, b)) if (now + a <= b) => Some(now + a)
		case _ => None
	}.isDefined

	pw.println(if (ok) "Yes" else "No")
	pw.flush()
}

object Scanner {
	private val buf = new Array[Byte](1024); private var ptr = 0; private var len = 0

	@inline private def isPrintableChar(c: Int): Boolean = 33 <= c && c <= 126
	@inline private def hasNextByte(): Boolean = if (ptr >= len) { ptr = 0; len = System.in.read(buf); len > 0 } else true
	@inline private def hasNext(): Boolean = {
		while (hasNextByte() && !isPrintableChar(buf(ptr))) ptr += 1
		hasNextByte()
	}
	@inline private def readByte(): Byte = if (hasNextByte()) { val res = buf(ptr); ptr += 1; res } else -1

	def next(): String = {
		if(!hasNext()) ???
		val sb = new StringBuilder; var b = readByte()
		while (isPrintableChar(b)) { sb.append(b.toChar); b = readByte() }
		sb.toString
	}

	def nextInt(): Int = {
		val n = nextLong()
		if (n < Int.MinValue || Int.MaxValue < n) ???
		n.toInt
	}

	def nextLong(): Long = {
		if(!hasNext()) ???
		var minus = false; var b = readByte()
		if (b == '-') { minus = true; b = readByte() }

		@scala.annotation.tailrec
		def go (b: Byte, n: Long = 0): Long = if ('0' <= b && b <= '9') go(readByte(), n * 10 + b - '0') else if (minus) -n else n

		go(b)
	}

	def nextDouble(): Double = next().toDouble
}


Measured memory_bytes: 95568
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int MOD = 1e9 + 7;
const ll INF = 1e18;
const double pi = 3.14159265358979323846;

int main(){
    while(1){
        int x,y;cin>>x>>y;
        if(x==0&&y==0) break;
        else cout<<min(x,y)<<" "<<max(x,y)<<endl;
    }
}


Measured memory_bytes: 3060
def warshall_floyd(d):
    for i in range(10):
        for j, c2 in enumerate(d[j][i] for j in range(10)):
            for k, (c1,c3) in enumerate(zip(d[j], d[i])):
                if c1 > c2+c3:
                    d[j][k] = c2+c3
    return d

h,w = map(int,input().split())
d=[list(map(int,input().split())) for _ in range(10)] 
a=[list(map(int,input().split())) for _ in range(h)]
a_cnt=[0]*10
for i in range(h):
    for j in range(w):
        if a[i][j]==-1:
            continue
        a_cnt[a[i][j]]+=1
d=warshall_floyd(d)
ans=0
for i,j in enumerate(a_cnt):
    ans+=d[i][1]*j
print(ans)

Measured memory_bytes: 9528
#include <bits/stdc++.h>
using namespace std;
int ans=0;
char a[200005],b[200005];
int main(){
	for(int i=0;;i++){
		a[i]=getchar();
		if(a[i]=='\n'){
			break;
		}
	}
	for(int i=0;;i++){
		b[i]=getchar();
		if(a[i]=='\n'){
			break;
		}
	}
	int len=strlen(a);
	for(int i=0;i<len;i++){
		if(a[i]!=b[i]){
			ans++;
		}
	}
	cout<<ans;
}

Measured memory_bytes: 4020
import java.util.*;
import java.lang.*;

class Section{
    double min, max;
    public Section(double min, double max){
        this.min=min;
        this.max=max;
    }
    public Section(double elm){
        this(elm,elm);
    }
    public Section(){
        this(1e12, -1e12);
    }
    public void add(double elm){
        this.min = Math.min(this.min, elm);
        this.max = Math.max(this.max, elm);
    }
    public double minimum(){return min;}
    public double maximum(){return max;}
    public String toString(){
        return "["+min+", "+max+"]";
    }
}

public class Main {
    static double score(Section xStop, Section yStop, Section left, Section right, Section up, Section down, double time){
        double xMax = Math.max(xStop.maximum(), Math.max(left.maximum()-time, right.maximum()+time));
        double xMin = Math.min(xStop.minimum(), Math.min(left.minimum()-time, right.minimum()+time));
        double yMax = Math.max(yStop.maximum(), Math.max(up.maximum()+time, down.maximum()-time));
        double yMin = Math.min(yStop.minimum(), Math.min(up.minimum()+time, down.minimum()-time));
        return (xMax-xMin)*(yMax-yMin);
    }
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();

        Section xStop = new Section();
        Section yStop = new Section();
        Section left = new Section();
        Section right = new Section();
        Section up = new Section();
        Section down = new Section();

        for(int n=0; n<N; n++){
            double x = sc.nextDouble();
            double y = sc.nextDouble();
            char d = sc.next().charAt(0);
            switch(d){
                case 'R':
                    right.add(x);
                    yStop.add(y);
                    break;
                case 'L':
                    left.add(x);
                    yStop.add(y);
                    break;
                case 'U':
                    up.add(y);
                    xStop.add(x);
                    break;
                case 'D':
                    down.add(y);
                    xStop.add(x);
                    break;
            }
        }

        for(double t=0; t<10; t+=0.1) score(xStop,yStop,left,right,up,down,t);

        double minTime = 0, maxTime = 1e12;
        for(int q=0; q<1000; q++){
            double early = (minTime*2+maxTime)/3;
            double late = (minTime+maxTime*2)/3;
            if(score(xStop,yStop,left,right,up,down,early) < score(xStop,yStop,left,right,up,down,late)){
                maxTime = late;
            }
            else minTime = early;
        }
        System.out.println(score(xStop,yStop,left,right,up,down,minTime));

    }
}

Measured memory_bytes: 158912
/** author: __nishad__ **/

#include<bits/stdc++.h>
using namespace std;


typedef long long ll ;
typedef vector<ll> vll ;

#define IOS ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define all(v) (v).begin(),(v).end()
#define precision(k) cout<<setprecision(k)<<fixed;
#define loop(i,a) for(int i=0; i<a;i++)
#define loop2(i,a,b) for(int i=(a);i<=(b);++i)
#define minv(v) *min_element(all(v))
#define maxv(v) *max_element(all(v))
#define getpos(v,x) (lower_bound(v.begin(),v.end(),x)-v.begin())
#define unq(v) sort(all(v)),(v).erase(unique((v).begin(),(v).end()),(v).end())
#define pb push_back
#define pi 3.14159265358979323
#define endl "\n"

int main()
{
    IOS;

    ll n, sum=0, t;
    cin>>n;
    t=n;

    while(n != 0){
        sum = sum + n%10;
        n = n/10;
    }
    t = t%sum;

    cout<<(t==0? "Yes" : "No");

}



Measured memory_bytes: 256
#define _USE_MATH_DEFINES
#include<iostream>
#include<string>
#include<queue>
#include<cmath>
#include<map>
#include<set>
#include<list>
#include<iomanip>
#include<vector>
#include<random>
#include<functional>
#include<algorithm>
#include<stack>
#include<cstdio>
#include<bitset>
#include<unordered_map>
#include<climits>
#include<fstream>
using namespace std;
///////////////////library zone!!!!!!!!!!!!!!!!!!!!!!!!!!!!
typedef long long ll;
typedef long double ld;
#define all(a) (a).begin(),(a).end()
const ll Mod = 1000000007;
const ll mod = 998244353;
struct H {
	ll x, y;
	bool operator<(const H &b) const {
		if (x != b.x) return x < b.x;
		return y < b.y;
	}
	bool operator>(const H &b) const {
		if (x != b.x) return x > b.x;
		return y > b.y;
	}
	bool operator==(const H &b) const { return x == b.x&&y == b.y; }
	bool operator!=(const H &b) const { return (*this) != b; }
};
struct P {
	ll pos, cost;
	bool operator<(const P &b) const { return cost < b.cost; }
	bool operator>(const P &b) const { return cost > b.cost; }
};
struct B {
	ll to, cost;
};
struct E {
	ll from, to, cost;
	bool operator<(const E &b) const { return cost < b.cost; }
	bool operator>(const E &b) const { return cost > b.cost; }
};
template<typename T, typename U>
void chmin(T &a, U b) {
	if (a > b) a = b;
}
template<typename T, typename U>
void chmax(T &a, U b) {
	if (a < b) a = b;
}
template<typename T>
T max_0(T a) {
	if (a < 0) return 0;
	return a;
}
template<typename T>
T min_0(T a) {
	if (a > 0) return 0;
	return a;
}
ll read() {
	ll u;
	ll k = scanf("%lld", &u);
	return u;
}
ll gcd(ll i, ll j) {
	if (i > j) swap(i, j);
	if (i == 0) return j;
	return gcd(j%i, i);
}
ll mod_pow(ll x, ll n, ll p) {
	ll res = 1;
	while (n > 0) {
		if (n & 1) res = res * x % p;
		x = x * x % p;
		n >>= 1;
	}
	return res;
}//x^n%p
const ll Inf = 3023372036854775807;
const int inf = 1500000000;
#define int long long
//----------------------------------------------------
int a[2000];
signed main() {
	int n;
	while (cin >> n && n) {
	ld ans = 0, ave = 0;
		for (int i = 0; i < n; i++) {
			a[i] = read();
			ave += a[i];
		}
		ave /= n;
		for (int i = 0; i < n; i++) {
			ans += (a[i] - ave)*(a[i] - ave);
		}
		printf("%.20LF\n", sqrt(ans / n));
	}
}


Measured memory_bytes: 3176
from collections import defaultdict

n = int(input())
a = list(map(int, input().split()))
q = int(input())
bc = [list(map(int, input().split())) for i in range(q)]

ans = sum(a)
dic = defaultdict(int)
for i in a:
    dic[i] += 1
for b,c in bc:
    if dic[b] == 0:
        print(ans)
        continue
    ans += (c-b) * dic[b]
    print(ans)
    dic[c] += dic[b]
    dic[b] = 0

Measured memory_bytes: 102976
#include<cstdio>
#include<vector>
#include<cstring>
#include<memory.h>
#include<algorithm>
#include<ctime>
#define ll long long
#define For(i,j,k)  for(ll i=j;i<=k;++i)
#define FOr(i,j,k)  for(ll i=j;i>=k;--i)
using namespace std;
inline ll read(){ll x=0,f=1;char ch=getchar();   while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}  while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();}  return x*f; }
inline void write(ll x){    if (x<0) putchar('-'),x=-x; if (x>=10) write(x/10);putchar(x%10+'0');  }
inline void writeln(ll x){ write(x);   puts("");   }
const ll mod=1e9+7,N=3010;
ll f[2][N][2],m,n,ans,c;
inline void add(ll &x,ll y){	x=(x+y)%mod;	}
int main(){
//	freopen("piling.in","r",stdin);
//	freopen("piling.out","w",stdout);
	n=read();	m=read()-1;
	For(i,0,n-1)	f[c][i][!i]=1;
	For(i,0,m-1){
		memset(f[c^1],0,sizeof f[c^1]);
		For(j,0,n)	For(k,0,1)	if (f[c][j][k]){
			add(f[c^1][j][k],f[c][j][k]*2);
			if (j>0)	add(f[c^1][j-1][k||j-1==0],f[c][j][k]);
			if (j<n-1)	add(f[c^1][j+1][k],f[c][j][k]);
		}
		c^=1;
	}
	For(i,0,n)	add(ans,f[c][i][1]);
	writeln(ans*4LL%mod);
}

Measured memory_bytes: 256
A,B,K=map(int,input().split())

for i in range(K):
    if i%2==0:
        if A%2==1:
            A-=1
        A//=2
        B+=A
    else:
        if B%2==1:
            B-=1
        B//=2
        A+=B

print(str(A)+' '+str(B))

Measured memory_bytes: 3060
#include<bits/stdc++.h>
using namespace std;
#define inf 1000000000
#define INF 1000000000000000
#define ll long long
#define ull unsigned long long
#define M 1000000007
#define P pair<int,int>
#define PLL pair<ll,ll>
#define FOR(i,m,n) for(int i=(int)m;i<(int)n;i++)
#define RFOR(i,m,n) for(int i=(int)m;i>=(int)n;i--)
#define rep(i,n) FOR(i,0,n)
#define rrep(i,n) RFOR(i,n,0)
#define all(a) a.begin(),a.end()
#define IN(a,n) rep(i,n){ cin>>a[i]; }
const int vx[4] = {0,1,0,-1};
const int vy[4] = {1,0,-1,0};
#define PI 3.14159265
#define F first
#define S seconnd
#define int ll
#define PB push_back


int n;
int a[10000];

signed main(){
  cin>>n;

  rep(i,2*n){
    int b;
    cin>>a[i];
  }

  sort(a,a+2*n);

  int sum=0;

  for(int i=0;i<2*n;i+=2){
    sum+=a[i];
  }

  cout<<sum<<endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main() {
  long A; long B; long K;
  cin >> A >> B >> K;
  
  long a = A;
  long b = B;
  
  if(a > K){
    a -= K;
  }else if(b > K - a){
    b -= K - a;
    a = 0;
  }else{
    a = 0;
    b = 0;
  }
  
  cout << a << " " << b << endl;
}


Measured memory_bytes: 256
import collections

n, k = map(int, input().split())
a = input().split()
a = [int(m) for m in a]
a.sort()
c = collections.Counter(a)

values, counts = zip(*c.most_common()[::-1])

count = 0
i = 0

if len(c) <= k:
    print(0)
    exit()
else:
    for j in counts:
        if i >= 0 and i <= len(counts) - 1 - k:
            count += j
        i += 1

print(count)

"""for i, name in enumerate(l, 1):
    print('{:03}_{}'.format(i, name))"""

Measured memory_bytes: 53504
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define ull unsigned long long
#define si(X) scanf("%d", &(X))
#define sll(X) scanf("%lld",&(X))
const ll mod = 1e9+7;
#define INFL 0x3f3f3f3f3f3f3f3fLL
 
//-------------------------<MATH>-------------------------------------------------------//
ll gcd(ll a,ll b){if(b==0)return a;return gcd(b,a%b);}
ll expo(ll base,ll pow){ll ans = 1;
   while(pow!=0){if(pow&1==1){ans = ans*base;ans = ans%mod;}
   base *= base;base%=mod;pow/=2;}return ans;}
ll inv(ll x){return expo(x,mod-2);}
ll mult_mod(ll a , ll b){a = a%mod; b = b%mod;
ll c = (a * b)%mod;
//cout << a << " " << b << endl;
return c;}
ll add_mod(ll a , ll b){a = (a + mod)%mod;b = (b + mod)%mod;ll c = (a + b)%mod;return c;}
ll fac[(int)(5e5 + 5)] , inv_fac[(int)(5e5 + 5)];
void precomp_factorial(int M){fac[0] = 1;for(int i = 1 ; i <= M ; i++) fac[i] = mult_mod(i , fac[i - 1]);
    inv_fac[M] = inv(fac[M]);for(int i = M - 1 ; i >= 0 ; i--) inv_fac[i] = mult_mod(i + 1 , inv_fac[i + 1]);}
ll nCk(ll n , ll k){ll ans = fac[n];ans = mult_mod(ans , inv_fac[n - k]);ans = mult_mod(ans , inv_fac[k]);return ans;}
int lo[(int)(1e3 + 6)];
void sieve(int M){for(int i = 2 ; i < M ; i++){ if(lo[i]) continue; for(int j = i ; j < M ; j += i)lo[j] = i;}}
int max_expo_prime_n_fac(ll N , int prime){int ress = 0;while(N){ress += (N/prime);N /= prime;}return ress;}
//-------------------------</MATH>-------------------------------------------------------//
 
//-------------------------<STRING>-------------------------------------------------------//
string get_prefix(string x , int MAX){return x.substr(0 , min((int)x.size() , MAX));}
string get_suffix(string x,int MAX){int dn=1;for(int i=x.size()-1;i>=0;i--){if(dn==MAX)return x.substr(i);dn++;}return x;}
string convert_to_binary(int x,int len) {string ans=""; while(x){if(x&1){ans='1'+ans;}
    else{ans ='0'+ans;}x/=2;}int k = ans.size();while(k < len){ans = '0' + ans;k++;}return ans;}
//-------------------------</STRING>-------------------------------------------------------//
 
ull llrand() {ull r = 0;for(int i = 0; i < 5; ++i){r = (r << 15)|(rand() & 0x7FFF);}return r & 0xFFFFFFFFFFFFFFFFULL;}
int dx[8] = {1 , 0 , -1 , 0 , 1 , -1 , -1 , 1};    // last 4 diagonal
int dy[8] = {0 , 1 , 0 , -1 , 1 , 1 , -1 , -1};
 
const int SZ = 2345678;

 int main(){
     
     int n;
     cin >> n;
     if(n >= 30) cout << "Yes" << endl;
     else cout << "No" << endl;
 }


Measured memory_bytes: 3632
#include<bits/stdc++.h>
using namespace std;
#define MOD 1000000007
#define BIG 1000000010
#define EPS 1e-9
#define fst first
#define scd second

#define debug(x) cout<<x<<endl;
#define repi(i,x,n) for(int i=x;i<n;i++)
#define rep(i,n) repi(i,0,n)
#define repn(i,n) for(int i=n;i>=0;i--)
#define int long long


signed main(){
  int n;
  cin>>n;
  pair<int,int> a[50];
  map<pair<int,int>,int> m;
  rep(i,n){
    int x,y;
    cin>>x>>y;
    a[i]=make_pair(x,y);
  }
  int ans=0;
  sort(a,a+n);
  rep(i,n){
    repi(j,i+1,n){
      int p=a[j].fst-a[i].fst;
      int q=a[j].scd-a[i].scd;
      pair<int,int> d=make_pair(p,q);
      m[d]++;
      // cout<<m[d]<<endl;
      ans=max(ans,m[d]);
    }
  }
  cout<<n-ans<<endl;
	  
  return 0;
}


Measured memory_bytes: 384
#include <stdio.h>
#include <string.h>

int main (){
	int x,y,z,jumlah=0;
	scanf("%d %d %d", &x, &y, &z);
	
	for(int a=x ; a<=y ; a++){
		if(a%z == 0){
			jumlah++;
		}
	}
	printf("%d", jumlah);
	return 0;
}

Measured memory_bytes: 1632
import std.algorithm;
import std.array;
import std.container;
import std.conv;
import std.math;
import std.numeric;
import std.range;
import std.stdio;
import std.string;
import std.typecons;

void scan(T...)(ref T a) {
    string[] ss = readln.split;
    foreach (i, t; T) a[i] = ss[i].to!t;
}
T read(T)() { return readln.chomp.to!T; }
T[] reads(T)() { return readln.split.to!(T[]); }
alias readint = read!int;
alias readints = reads!int;

const MOD = 10^^9 + 7;

long[][] pascal(int n, int mod) {
    auto g = new long[][](n + 1, n + 1);
    g[0][0] = 1;
    for (int i = 1; i < n; i++) {
        for (int j = 0; j <= i; j++) {
            g[i][j] = g[i-1][j];
            if (j > 0) {
                g[i][j] += g[i-1][j-1];
                g[i][j] %= mod;
            }
        }
    }
    return g;
}

void calc(int n, int k) {
    auto C = pascal(n + n, MOD);

    for (int i = 1; i <= k; i++) {
        // N - K 個の赤ボールのすき間から i 箇所を選ぶ
        long x = C[n - k + 1][i];

        // K 個の青ボールを i 箇所に配る配り方
        // H(i, K - i) = nck(i + K - i - 1, K - i)
        long y = C[k - 1][k - i];
        writeln(x * y % MOD);
    }
}

void main() {
    int n, k; scan(n, k);
    calc(n, k);
}


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

int main(){
    int S;
    cin>>S;
    if(S%100>12||S%100<1){
        if(S/100>12||S/100<1){
            cout<<"NA"<<endl;
        }
        if(S/100<=12&&S/100>=1){
            cout<<"MMYY"<<endl;
        }
    }
    if(S%100<=12&&S%100>=1){
        if(S/100>12||S/100<1){
            cout<<"YYMM"<<endl;
        }
        if(S/100<=12&&S/100>=1){
            cout<<"AMBIGUOUS"<<endl;
        }
    }
}


Measured memory_bytes: 256
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
int main()
{
    int i,len,x,y,z,a,diff,min=753;
    char s1[20];
    scanf("%s",&s1);
    len=strlen(s1);
    for(i=0; i<len-2; i++)
    {
        x=s1[i]-'0';
        y=s1[i+1]-'0';
        z=s1[i+2]-'0';
        a=(x*100)+(y*10)+z;
        //printf("%d\n",a);
        diff=abs(753-a);
        //printf("%d\n",diff);
        if(diff<=min)
            min=diff;
    }
    printf("%d",min);
}

Measured memory_bytes: 128
using System;
using System.Linq;
using System.Collections.Generic;
using static System.Console;

class Program
{
    static void Main(string[] args)
    {
        solve();
    }
    static Scanner cin;

    static int N;
    static int[] x;
    static void input()
    {
        cin = new Scanner();
        N = cin.nextInt();
        x = new int[N + 1];
        for(int i = 0; i < N + 1; i++)
        {
            x[i] = cin.nextInt();
        }
        Array.Sort(x);
    }
    static void solve()
    {
        input();
        long ans = x[1] - x[0];
        for(int i = 1; i < N; i++)
        {
            ans = Gcd(ans, x[i + 1] - x[i]);
        }
        WriteLine(ans);
    }

    
    class Scanner
    {
        string[] s;
        int i;

        char[] cs = new char[] { ' ' };

        public Scanner()
        {
            s = new string[0];
            i = 0;
        }
        
        public string next()
        {
            if (i < s.Length) return s[i++];
            string st = Console.ReadLine();
            while (st == "") st = Console.ReadLine();
            s = st.Split(cs, StringSplitOptions.RemoveEmptyEntries);
            if (s.Length == 0) return next();
            i = 0;
            return s[i++];
        }

        public int nextInt()
        {
            return int.Parse(next());
        }

        public int[] ArrayInt(int N, int add = 0)
        {
            int[] Array = new int[N];
            for(int i = 0; i < N; i++)
            {
                Array[i] = nextInt() + add;
            }
            return Array;
        }

        public long nextLong()
        {
            return long.Parse(next());
        }

        public long[] ArrayLong(int N, long add = 0)
        {
            long[] Array = new long[N];
            for(int i = 0; i < N; i++)
            {
                Array[i] = nextLong() + add;
            }
            return Array;
        }

        public double nextDouble()
        {
            return double.Parse(next());
        }

        public double[] ArrayDounble(int N, int add = 0)
        {
            double[] Array = new double[N];
            for (int i = 0; i < N; i++)
            {
                Array[i] = nextDouble() + add;
            }
            return Array;
        }
    }
      static long Gcd(long n, long m)
    {
        if (n < m) return Gcd(m, n);
        while(m != 0)
        {
            long r = n % m;
            n = m;
            m = r;
        }
        return n;
    }
}

Measured memory_bytes: 22368
#include <iostream>
#include <vector>
#define DEBUG false
using namespace std;

int main(){
  int plen,cnum,width,cspace;
  string s, t;
  vector<string> v;

  while( cin>>plen && plen ){
    /*
    cout << "************************"<<endl;
    cout << "plen=" << plen << endl;
    */
    cin >> cnum >> width >> cspace;

    v.clear();
    getline( cin,s ); // üsÌÇÝÝ
    while( getline(cin,s) && s!="?" ){
      while( (int)s.length()>width ){ // ÍÝo½ª
	v.push_back( s.substr( 0,width ) );
	s = s.substr( width );
      }
      while( (int)s.length()<width )
	s=s+".";
      v.push_back( s );
    }

    s=""; for( int i=0;i<width;i++ ) s+=".";
    int pN = plen*cnum;
    while( v.size()%pN!=0 ) v.push_back( s );

    if( DEBUG )
      for( unsigned int i=0;i<v.size();i++ )
	cout << "["<<v[i]<<"]"<<endl;

    s=""; for( int i=0;i<cspace;i++ ) s+=".";
    int Np = v.size()/pN;
    for( int np=0;np<Np;np++ ){
      for( int i=0;i<plen;i++ ){
	cout << v[ np*pN + i ]; 
	for( int cn=1;cn<cnum;cn++ )
	  cout << s << v[ np*pN + i + plen*cn ];
	cout << endl;
      }
      cout << "#"<<endl;
    }
    cout << "?"<<endl;

  }
  return 0;
}

Measured memory_bytes: 0
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define FASTIO ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define all(x) (x).begin(), (x).end()
#define pb push_back
#define pii pair<int, int>
#define ff first
#define ss second
#define PI acos(-1)
#define ld long double
//mt19937 rng((uint32_t)chrono::steady_clock::now().time_since_epoch().count());
const int mod = 1e9+7, N = 2e5+5;

int n, m, k;

void solve(int test_case){
	int i, j;
	cin >> n;
	vector<pii> a(n);
	
	for(i=0;i<n;i++)cin >> a[i].ff >> a[i].ss;
	vector<int> v;
	for(i=0;i<n;i++)v.pb(a[i].ff+a[i].ss);
	sort(all(v));
	int ans = v[n-1] - v[0];
	
	v.clear();
	for(i=0;i<n;i++){
		v.pb(a[i].ff-a[i].ss);
	}sort(all(v));
	ans = max(ans, abs(v[n-1]-v[0]));
	cout << ans;
	return;
}

signed main(){
	FASTIO;
#define MULTITEST 0
#if MULTITEST
	int ___T;
	cin >> ___T;
	for(int T_CASE = 1; T_CASE <= ___T; T_CASE++)
		solve(T_CASE);
#else
	solve(1);
#endif
	return 0;
}



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

using namespace std;

typedef long long ll;

const int Maxn = 100010;
const int INF = (int) 1e9;

int dp[Maxn], h[Maxn];

int main() {
    int n, k;
    cin >> n;
    for (int i = 0; i < n; ++i) {
        cin >> h[i];
    }
    fill(dp, dp + Maxn, INF);
    dp[0] = 0;
    for (int i = 0; i < n; ++i) {
        for (int j = 1; j < 3; ++j) {
            dp[i + j] = min(dp[i + j], dp[i] + abs(h[i + j] - h[i]));
        }
    }

    cout << dp[n - 1] << endl;


    return 0;
}

Measured memory_bytes: 1024
#include <iostream>
using namespace std;
#define rep(i,n) for(int i=0;i<(n);++i)

int main() {
  cin.tie(0); ios::sync_with_stdio(false);
  int N; cin >> N;
  string S, T; cin >> S >> T;

  rep(i, N) cout << S[i] << T[i];
  cout << "\n";

  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
//F6編譯，右上三角形執行，ctrl+c強制停止執行  F5開啟exe
#define ll long long
#define maxn 200005
#define mod 1000000007
using namespace std;

typedef pair<int, int> P;

int n;
vector<P> pos, zero, neg;

bool cmp1(P p1, P p2) { return (p1.second != p2.second) ? p1.second < p2.second : p1.first > p2.first; }
bool cmp2(P p1, P p2) { return p1.first + p1.second > p2.first + p2.second; }

int main()
{
    cin >> n;
    int cnt = 0;
    for (int i = 0; i < n; i++)
    {
        string s;
        cin >> s;
        int now = s.length();
        int small = 0;
        int tot = 0;
        for (int j = 0; j < now; j++)
        {
            if (s[j] == '(')
                tot++;
            else
                tot--;
            small = min(small, tot);
        }
        cnt += tot;
        if (tot > 0)
            pos.push_back(P(tot, -small));
        else if (tot < 0)
            neg.push_back(P(tot, -small));
        else
            zero.push_back(P(tot, -small));
    }
    if (cnt != 0)
    {
        printf("No\n");
        return 0;
    }
    bool ok = 1;
    cnt = 0;
    sort(pos.begin(), pos.end(), cmp1);
    for (int i = 0; i < pos.size(); i++)
    {
        if (pos[i].second > cnt)
            ok = 0;
        cnt += pos[i].first;
    }
    for (int i = 0; i < zero.size(); i++)
    {
        if (zero[i].second > cnt)
            ok = 0;
    }
    sort(neg.begin(), neg.end(), cmp2);
    for (int i = 0; i < neg.size(); i++)
    {
        if (neg[i].second > cnt)
            ok = 0;
        cnt += neg[i].first;
    }
    if (ok)
        printf("Yes\n");
    else
        printf("No\n");

    return 0;
}


Measured memory_bytes: 11140
#[allow(unused_imports)]
use std::char::*;
#[allow(unused_imports)]
use std::cmp::*;
use std::io::*;
use std::str::FromStr;

fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let stdin = stdin.lock();
    let token: String = stdin
        .bytes()
        .map(|c| c.expect("failed to read char") as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().expect("failed to parse token")
}

//const MAX:usize = 100006;
//const INF:u64 = u64::max_value();

fn main() {
    let s:Vec<char> = read::<String>().chars().collect();

    for i in 0..s.len() {
        let mut f:bool = match s[i as usize] {
            'U' => true,
            'D' => true,
            _ => false,
        };
        if f {continue}
        if i % 2 == 0 {
            f = match s[i as usize] {
                'R' => true,
                _ => false,
            };
        } else {
            f = match s[i as usize] {
                'L' => true,
                _ => false,
            };
        }
        if !f {
            println!("No");
            return ();
        }
    }

    println!("Yes");
    
}

Measured memory_bytes: 4352
#include<bits/stdc++.h>
using namespace std;
long long x[5],ans;
inline int read()
{
	int num=0,flag=1;
	char c=getchar();
	for (;c<'0'||c>'9';c=getchar())
	if (c=='-') flag=-1;
	for (;c>='0'&&c<='9';c=getchar())
	num=(num<<3)+(num<<1)+c-48;
	return num*flag;
}
int main()
{
	for (int i=1;i<=3;++i)
	x[i]=read();
	sort(x+1,x+4);
	ans=x[3]-x[2]+((x[2]-x[1])/2);
	if ((x[2]-x[1])%2==1) ans+=2;
	printf("%lld\n",ans);
	return 0;
}

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

namespace D
{
    class Program
    {
        const long M = 1000000007;
        static long Mul(long s, long e)
        {
            var ans = 1L;
            for (long now = s; now <= e; now++)
            {
                ans *= now;
                ans %= M;
            }
            return ans;
        }

        static long Pow(long b, long e)
        {
            if (e == 0) { return 1; }
            else if (e % 2 == 0) { return Pow((b * b) % M, e / 2); }
            else
            {
                return (b * Pow(b * b % M, (e - 1) / 2)) % M;
            }
        }

        static long Reciprocal(long x)
        {
            return Pow(x, M - 2);
        }
        static long Combination(long n, long r)
        {
            return factTable[n] * Reciprocal(factTable[n - r] * factTable[r] % M) % M;
        }
        static long Comb(long h, long w)
        {
            return Combination(h + w - 2, h - 1);
        }

        static long[] factTable;

        static void initTable(long max)
        {
            factTable = new long[max];
            long a = 1;
            factTable[0] = 1;
            for (int i = 1; i < max; i++)
            {
                a = a * i % M;
                factTable[i] = a;
            }
        }
        static void Main(string[] args)
        {
            var buff = Console.ReadLine().Split(' ').Select(long.Parse).ToArray();
            long H = buff[0], W = buff[1], A = buff[2], B = buff[3];
            initTable(300000);

            long ans = 0;
            for (int i = 0; i < H - A; i++)
            {
                ans += Comb(i + 1, B) * Comb(H - i, W - B) % M;
                ans %= M;
            }
            Console.WriteLine(ans);
            Console.Read();
        }
    }
}

Measured memory_bytes: 5208
#include <iostream>
using namespace std;
int main() {
	int n,f,s,t;
	cin >> n;
	t = n % 10;
	s = (n/10) % 10;
	f = (n/10) / 10;;;;

	if (f == t)
		cout << "Yes";
	else
		cout << "No";

}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define repd(i,a,b) for (int i=(a);i<(b);i++)
#define rep(i,n) repd(i,0,n)
#define all(x) (x).begin(),(x).end()
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
typedef long long ll;
const long long INF = 1LL << 60;
typedef pair<int, int> P;
int main()
{
    ll x, y, ans;
    cin >> x >> y;

    if (x >= 0) {
        if (y >= 0) {
            if (x > y) {
                ans = 2 + x - y;
            }
            else {
                ans = y - x;
            }
        }
        else {
            if (abs(x) > abs(y)) {
                ans = 1 + x + y;
            }
            else {
                ans = 1 - x - y;
            }
        }
        if (y == 0) {
            ans--;
        }
    }
    else {
        if (y >= 0) {
            if (abs(x) > abs(y)) {
                ans = - y - x + 1;
            }
            else {
                ans = 1 + y + x;
            }
            if (y == 0) {
                ans--;
            }
        }
        else {
            if (abs(x) > abs(y)) {
                ans = y - x;
            }
            else {
                ans = 2 + x - y;
            }
        }
    }
    if (abs(x) == abs(y)) {
        ans = 1;
    }

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

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

typedef long long ll;

int main()
{
  ll X, A, B;
  std::cin  >> X  >> A  >> B;
  
  std::string judge = "dangerous";
  if (B - A <= 0) {
    judge = "delicious";
  } else if (B - A <= X) {
    judge = "safe";
  }

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


Measured memory_bytes: 256
#!usr/bin/env python3
from collections import defaultdict
from collections import deque
from heapq import heappush, heappop
import sys
import math
import bisect
import random
import itertools
sys.setrecursionlimit(10**5)
stdin = sys.stdin
bisect_left = bisect.bisect_left
bisect_right = bisect.bisect_right
def LI(): return list(map(int, stdin.readline().split()))
def LF(): return list(map(float, stdin.readline().split()))
def LI_(): return list(map(lambda x: int(x)-1, stdin.readline().split()))
def II(): return int(stdin.readline())
def IF(): return float(stdin.readline())
def LS(): return list(map(list, stdin.readline().split()))
def S(): return list(stdin.readline().rstrip())
def IR(n): return [II() for _ in range(n)]
def LIR(n): return [LI() for _ in range(n)]
def FR(n): return [IF() for _ in range(n)]
def LFR(n): return [LI() for _ in range(n)]
def LIR_(n): return [LI_() for _ in range(n)]
def SR(n): return [S() for _ in range(n)]
def LSR(n): return [LS() for _ in range(n)]
mod = 1000000007
inf = float('INF')

#A
def A():
    a = input().split()
    a = list(map(lambda x: x.capitalize(), a))
    a,b,c = a
    print(a[0]+b[0]+c[0])
    return

#B
def B():
    a = II()
    b = II()
    if a > b:
        print("GREATER")
    if a < b:
        print("LESS")
    if a == b:
        print("EQUAL")
    return

#C
def C():
    II()
    a = LI()
    def f(suma, b):
        for i in a[1:]:
            if suma * (suma + i) < 0:
                suma += i
                continue
            b += (abs(suma + i) + 1)
            suma = (-1 * (suma > 0)) or 1
        return b

    if a[0] == 0:
        ans = min(f(1, 1), f(-1, 1))
    else:
        ans = min(f(a[0], 0), f(1 * (a[0] < 0) or - 1, abs(a[0]) + 1))
    print(ans)
    return

#D
def D():
    s = S()
    for i in range(len(s) - 1):
        if s[i] == s[i+1]:
            print(i + 1, i + 2)
            return
    for i in range(len(s) - 2):
        if s[i] == s[i + 2]:
            print(i + 1, i + 3)
            return
    print(-1, -1)
    return


#Solve
if __name__ == '__main__':
    C()


Measured memory_bytes: 59504