akhauriyash/Code-Regression huggingface dataset:
import java.awt.*;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.*;
import java.util.List;

public class Main {

  public static void main(String [] args) {
    InputReader scanner = new InputReader(System.in);
    int A = scanner.nextInt();
    String op = scanner.next();
    int B = scanner.nextInt();
    int res;
    if (op.equals("-")) res = A - B;
    else res = A + B;
    System.out.println(res);
  }

  static class Interval implements Comparable<Interval> {
    int a, b;
    public Interval(int a, int b) {
      this.a = a;
      this.b = b;
    }

    public int compareTo(Interval rhs) {
      if (b < rhs.b) return -1;
      if (b == rhs.b) {
        return a - rhs.a;
      }
      return 1;
    }
  }

  static class InputReader {
    private BufferedReader reader;
    private StringTokenizer tokenizer;

    public InputReader(InputStream stream) {
      reader = new BufferedReader(new InputStreamReader(stream), 32768);
      tokenizer = null;
    }

    public String nextLine() {
      try {
        return reader.readLine();
      } catch (IOException e) {
        return null;
      }
    }

    public boolean hasNext() {
      if (tokenizer == null) {
        try {
          tokenizer = new StringTokenizer(reader.readLine());
        } catch (IOException e) {
        }
      }
      return tokenizer.hasMoreTokens();
    }

    public String next() {
      if (tokenizer == null || !tokenizer.hasMoreTokens()) {
        try {
          tokenizer = new StringTokenizer(reader.readLine());
          if (!tokenizer.hasMoreTokens()) {
            return null;
          }
        } catch (IOException e) {
          throw new RuntimeException(e);
        }
      }
      return tokenizer.nextToken();
    }

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

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

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


Measured memory_bytes: 8148
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <sstream>
#include <cstring>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <numeric>

#define rep(i, n) for(int i = 0; i < (n); i++)
#define FOR(i, a, b) for(int i = (a); i < (b); i++)
#define ALL(v) (v).begin(), (v).end()
#define REV(s) (s).rbegin(), (s).rend()
#define MP make_pair
#define X first
#define Y second

using namespace std;

static const double eps = 1e-9;

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

template<class t>
inline t sq(t a){return a*a;}

int expr();
int term();
int fact();

string s;
int ptr;
int expr(){
	int x = term();
	while(s[ptr] == '+' || s[ptr] == '-'){
		if(s[ptr] == '+'){
			ptr++;
			x += term();
		}else{
			ptr++;
			x -= term();
		}
	}
	return x;
}

int term(){
	int x;
	x = fact();
	while(s[ptr] == '*' || s[ptr] == '/'){
		if(s[ptr] == '*'){
			ptr++;
			x *= fact();
		}
		else if(s[ptr] == '/'){
			ptr++;
			x/= fact();
		}
	}

	return x;
}

int fact(){
	int x = 0, y = 1;
	if(s[ptr] == '+') ptr++;
	if(s[ptr] == '-'){
		y = -1;
		ptr++;
	}
	if(s[ptr] == '('){
		ptr++;
		x = expr();
		ptr++;
	}else{
		while('0' <= s[ptr] && s[ptr] <= '9'){
			x *= 10;
			x += (s[ptr]-'0');
			ptr++;
		}
	}
	return x*y;
}

int main(){
	int n;
	cin >> n;
	while(n--){
		cin >> s;
		ptr = 0;
		cout << expr() << endl;
	}

	return 0;
}

Measured memory_bytes: 1204
#include <stdlib.h>
#include <stdio.h>
#include <iostream>
#include <string.h>
#include <string>
#include <vector>
#include <list>
using namespace std;
#include <stdio.h>
#include <map> 
#include <algorithm>
#include <functional>
#include <algorithm>
#include <functional>
#include <array>
#include <iostream>
#include <limits>
#include <numeric>
#include <type_traits>


std::vector<int> len;

int main()
{
	char N;
	std::string S;
	cin >> N;

	printf("%c\n", (N+1));

	return 0;
}




Measured memory_bytes: 256
//package com.grand9;

import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        long A[] =new long [N];
        long B[] = new long [N];

        for(int i=0;i<N;i++){
            A[i]= sc.nextInt();
            B[i]=sc.nextInt();
        }

        long ans = 0;
        for(int i =N-1;i>=0;i-- ){
            if((A[i]+ans)%B[i]!=0L){
                long plus = ((A[i]+ans)/B[i]+1L)*B[i]-A[i]-ans;
                ans += plus;
            }

            //System.out.println(ans);
        }


        System.out.println(ans);


        sc.close();

    }

 }


Measured memory_bytes: 74300
#include <iostream>
#include <stdio.h>
#include <cmath>
#include <algorithm>
#include <vector>

#define FOR(i, a, b) for (int i = a; i < b; i++)
#define FORN(i, a, b) for (int i = a; i <= b; i++)
#define P(s) cout << s << endl
#define PC(condition, _true, _false) if (condition) _true; else _false;
#define toInt(_char) _char - '0'

using namespace std;
//
// Created by karayuu on 2018-12-18.
//

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

    P(abs(a - b));
}


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

#define all(v)  begin(v), end(v)
#define endl    '\n';
#define int     long long
#define pii     pair<int, int>
#define sz(x)   (int) x.size()

void test_case() {
    int a;
    cin >> a;
    cout << a + a*a + a*a*a << endl;
}

int32_t main() { 
    ios_base::sync_with_stdio(0); 
    cin.tie(0);

    int t = 1;
    // cin >> t;

    while (t--) { 
        test_case();
    }
    return 0;
}


Measured memory_bytes: 3652
#include<bits/stdc++.h>
using namespace std;
#define LL long long
#define C(n,m) ((LL)fac[n]*ifac[m]%mo*ifac[(n)-(m)]%mo)

const int maxn=2<<19;
const int mo=924844033;

int n,sz[maxn],fac[maxn],ifac[maxn];
int tote,FIR[maxn],TO[maxn],NEXT[maxn];
int step,N,rev[maxn],wn[maxn];
int cc[maxn],bb[maxn],aa[maxn];

void addedge(int u,int v)
{
	TO[++tote]=v;
	NEXT[tote]=FIR[u];
	FIR[u]=tote;
}

void search(int u,int F)
{
	sz[u]=1;
	for (int p=FIR[u];p;p=NEXT[p])
	{
		int v=TO[p];
		if (v!=F)
		{
			search(v,u);
			sz[u]+=sz[v];
			cc[sz[v]]++;
			cc[n-sz[v]]++;
		}
	}
}

int power(int x,int k)
{
	int res=1;
	while (k)
	{
		if (k&1) res=(LL)res*x%mo;
		x=(LL)x*x%mo;
		k>>=1;
	}
	return res;
}

void fft(int a[],int flag)
{
	int i,j,k;
	for (i=0;i<N;i++)
		if (i<rev[i]) swap(a[i],a[rev[i]]);
	for (k=1;k<N;k<<=1)
	{
		int p=N+flag*N/(k<<1);
		for (i=0;i<N;i+=k<<1)
		{
			for (j=0;j<k;j++)
			{
				int x=a[i+j];
				int y=(LL)a[i+j+k]*wn[(LL)j*p%N]%mo;
				a[i+j]=(x+y)%mo;
				a[i+j+k]=(x+mo-y)%mo;
			}
		}
	}
	if (flag==-1)
	{
		int inv=power(N,mo-2);
		for (i=0;i<N;i++)
			a[i]=(LL)a[i]*inv%mo;
	}
}

int main()
{
#ifdef h10
	freopen("F.in","r",stdin);
	freopen("F.out","w",stdout);
#endif
	int i,u,v;
	scanf("%d",&n);
	fac[0]=1;
	for (i=1;i<=n;i++)
		fac[i]=(LL)fac[i-1]*i%mo;
	ifac[n]=power(fac[n],mo-2);
	for (i=n;i>=1;i--)
		ifac[i-1]=(LL)ifac[i]*i%mo;
	for (i=1;i<n;i++)
	{
		scanf("%d%d",&u,&v);
		addedge(u,v);
		addedge(v,u);
	}
	search(1,0);
	for (i=1;i<=n;i++)
		cc[i]=(LL)cc[i]*fac[i]%mo;
	for (i=0;i<=n;i++)
		bb[i]=ifac[n-i];

	for (step=0,N=1;N<=n+n;step++,N<<=1);
	int w=power(5,(mo-1)/N);
	wn[0]=1;
	for (i=1;i<N;i++)
		wn[i]=(LL)wn[i-1]*w%mo;
	for (i=0;i<N;i++)
		rev[i]=(rev[i>>1]>>1)|((i&1)<<(step-1));
	fft(cc,+1);
	fft(bb,+1);
	for (i=0;i<N;i++)
		aa[i]=(LL)cc[i]*bb[i]%mo;
	fft(aa,-1);
	for (i=1;i<=n;i++)
	{
		int A=(n-1ll)*C(n,i)%mo;
		int B=(LL)aa[n+i]*ifac[i]%mo;
		printf("%lld\n",((A+mo-B)%mo+C(n,i))%mo);
	}
}


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

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

fn read_vec2<T: std::str::FromStr>(n: u32) -> Vec<Vec<T>> {
    (0..n).map(|_| read_vec()).collect()
}
fn main(){
    let mut t = read_vec::<i64>();
    t.sort();
    println!("{}",t[0]+ t[2]* 10 + t[1]);

}

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

using namespace std;

using ll = long long;

const int MAXV = 100000;
const ll INF = 1000000000000LL;

int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	int n;
	ll W;
	cin >> n >> W;
	vector<ll> dp(MAXV + 1, INF);
	dp[0] = 0;

	for (int i = 0; i < n; i++) {
		ll w;
		int v;
		cin >> w >> v;
		for (int j = MAXV; j >= v; j--) {
			dp[j] = min(dp[j], dp[j - v] + w);
		}
	}

	for (int i = MAXV; i >= 0; i--) {
		if (dp[i] <= W) {
			cout << i << endl;
			break;
		}
	}
	return 0;
}

Measured memory_bytes: 1024
using System;
using System.Collections;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Numerics;
using System.Text;
using System.Threading.Tasks;
using static System.Console;
using static System.Math;
class Z { static void Main() => new K(); }
class K
{
	int F => int.Parse(Str);
	long FL => long.Parse(Str);
	int[] G => Strs.Select(int.Parse).ToArray();
	long[] GL => Strs.Select(long.Parse).ToArray();
	double[] GR => Strs.Select(double.Parse).ToArray();
	string Str => ReadLine();
	string[] Strs => Str.Split(new char[] { ' ', '\t' }, StringSplitOptions.RemoveEmptyEntries);
	const int MOD = 1000000007;
	const long INFL = 4011686018427387913L;
	public K()
	{
		SetOut(new StreamWriter(OpenStandardOutput()) { AutoFlush = false });
		Solve();
		Out.Flush();
	}
	void Solve()
	{
		var I = G;
		int N = I[0], K = I[1];
		var a = G;
		var dp = new long[N + 1, K + 1];
		dp[0, 0] = 1;
		for (var n = 0; n < N; n++)
		{
			var sum = new long[K + 2];
			for (var k = 0; k < K + 1; k++) sum[k + 1] = (sum[k] + dp[n, k]) % MOD;
			for (var k = 0; k <= K; k++) dp[n + 1, k] = (sum[k + 1] - sum[Max(k - a[n], 0)]) % MOD;
		}
		if (dp[N, K] < 0) dp[N, K] += MOD;
		WriteLine(dp[N, K]);
	}
}


Measured memory_bytes: 115328
#include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <utility>
#include <string>

using namespace std;

int calc(int x) {
	int sum = 0;
	while (x > 0) {
		sum += x % 10;
		x /= 10;
	}
	return sum;
}

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


	int ans = 1e9;

	for (int i = 1; i < n; i++) {
		ans = min(ans, calc(i) + calc(n - i));
	}

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


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

from bisect import bisect_left, bisect_right

INF = 10**18 + 100
N,A,B = map(int,input().split())
S = [-INF] + [int(x) for x in sys.stdin.read().split()]

MOD = 10**9 + 7

dpX = [0] * (N+1) # 最後にYを選んだとして、直前に選んだXがどこにあるか
dpY = [0] * (N+1) # 最後にXを選んだとして、直前に選んだYがどこにあるか
dpX[0] = 1
dpY[0] = 1
dpX_cum = [1] * (N+1) + [0] # -1
dpY_cum = [1] * (N+1) + [0] # -1
dpX_left = 0
dpY_left = 0
for n,x in enumerate(S[2:],2):
    iA = bisect_right(S,x-A)
    iB = bisect_right(S,x-B)
    # ....XY
    xy = dpY_cum[iB-1] - dpY_cum[dpY_left-1] if iB >= dpY_left else 0
    # ....YX
    yx = dpX_cum[iA-1] - dpX_cum[dpX_left-1] if iA >= dpX_left else 0
    # ....XX が不可能なら捨てる。明示的に捨てるのではなく、生きている番号だけ持つ
    if iA != n:
        dpY_left = n-1
    if iB != n:
        dpX_left = n-1
    dpX[n-1] = xy
    dpX_cum[n-1] = (dpX_cum[n-2] + xy) % MOD
    dpX_cum[n] = dpX_cum[n-1]
    dpY[n-1] = yx
    dpY_cum[n-1] = (dpY_cum[n-2] + yx) % MOD
    dpY_cum[n] = dpY_cum[n-1]

answer = dpX_cum[N-1] - dpX_cum[dpX_left-1]
answer += dpY_cum[N-1] - dpY_cum[dpY_left-1]
answer %= MOD
print(answer)

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

#define fio ios_base::sync_with_stdio(false);cin.tie(NULL)
// #define int long long 

using namespace std;

int32_t main()
{
	fio;
	string s1,s2;
	cin>>s1>>s2;
	bool flag=true;
	for(int i=0;s1[i]!='\0';i++)
	{
		if(s1[i]!=s2[i])
		{
			flag=false;
			break;
		}
	}

	if(flag)
	{
		cout<<"Yes"<<endl;
	}
	else
	{
		cout<<"No"<<endl;
	}
	return 0;
}

Measured memory_bytes: 3580
/*
 * atcoder/abc130/a.cpp
 */

// C++ 14
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <cstring> // memset
#include <cassert>

using namespace std;

#define ll long long

#define loop(__x, __start, __end) for(int __x = __start; __x < __end; __x++)
template <class T> bool chmin(T &a, T b) { if (a > b) {a = b; return true; } return false; }
template <class T> bool chmax(T &a, T b) { if (a < b) {a = b; return true; } return false; }

int N, T;
double A;
double H[1001];

int main() {
  // cout.precision(15);

  cin >> N >> T >> A;
  double min_ = 100000000.0;
  int ans = 1;
  loop(n,1,N+1) {
    cin >> H[n];
    double a = T - H[n] * 0.006;
    if (chmin(min_, fabs(A-a))) ans = n;
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
N, x = map(int, input().split())
A = list(map(int, input().split()))
ans = 0

for i in range(N-1):
    gap = A[i] + A[i+1] - x
    if gap > 0:
        ans += gap
        A[i+1] -= gap
        if A[i+1] < 0:
            A[i+1] = 0

print(ans)


Measured memory_bytes: 14060
import java.util.Arrays;
import java.util.Scanner;

public class Main {
    static final int MODULUS = 1_000_000_007;

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

        int N = sc.nextInt();

        System.out.println(solve(N));

        sc.close();
    }

    static int solve(int N) {
        int[] counts = new int[N + 1];
        for (int i = 1; i <= N; ++i) {
            int x = i;
            for (int j = 2; j < counts.length; ++j) {
                while (x % j == 0) {
                    x /= j;
                    ++counts[j];
                }
            }
        }

        return Arrays.stream(counts).map(x -> x + 1).reduce((x, y) -> (int) ((long) x * y % MODULUS)).getAsInt();
    }
}

Measured memory_bytes: 26836
#include<iostream>
#include<algorithm>
#include<vector>
#include<queue>
#include<functional>
#include<utility>

using namespace std;
typedef pair<int, int> P;
const int INF = (1 << 30);
int V, E, r;
int dp[100000];
struct edge{
	int to, cost;
	edge(int to,int cost=1):to(to),cost(cost){}
};
vector<edge> G[100000];

int main()
{
	cin.tie(0);
	ios::ios_base::sync_with_stdio(false);
	cin >> V >> E >> r;
	int s, t, d;
	for (int i = 0; i < E; ++i) {
		cin >> s >> t >> d;
		edge e(t,d);
		G[s].emplace_back(e);
	}
	fill(dp, dp + V, INF);
	dp[r] = 0;
	priority_queue<P, vector<P>, greater<P>> que;
	que.push(P(0, r));
	while (!que.empty()) {
		P p = que.top(); que.pop();
		if (dp[p.second] < p.first)continue;
		int v = p.second;
		for (int i = 0; i < G[v].size(); ++i) {
			edge e = G[v][i];
			if (dp[e.to]>dp[v] + e.cost) {
				dp[e.to] = dp[v] + e.cost;
				que.push(P(dp[e.to], e.to));
			}
		}
	}
	for (int i = 0; i < V; ++i) {
		if (dp[i] == INF)cout << "INF\n";
		else cout << dp[i] << "\n";
	}
	cout << flush;
	return 0;
}

Measured memory_bytes: 11284
from collections import defaultdict

def solve():
    N = int(input())
    d = defaultdict(int)
    m = 0
    for _ in range(N):
        a = input()
        d[a] += 1
        m = max(d[a], m)

    l = []
    for k, v in d.items():
        if m == v:
            l.append(k)
    l.sort()
    for ans in l:
        print(ans)
    
solve()

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

using namespace std;
using i64 = long long int;
using ui64 = unsigned long long int;

////////////////////////////////

i64 dfs(int n,int k,int s){
  i64 ret = 0LL;
  if(k == 0){
    if(s == 0)return 1LL;
    else return 0LL;
  }
  for(int i=n-1;i>0;i--){
    ret += dfs(i,k-1,s-i);
  }
  return ret;
}

int main()
{
  int n,k,s;
  while(cin >> n >> k >> s,n && k && s){
    cout << dfs(n+1,k,s) << endl;
  }
  
}




Measured memory_bytes: 3092
#include <bits/stdc++.h>
#define maxc 100005
#define maxn 105
using namespace std;

const int mod = 1e9 + 7;

int arr[maxn], dp[2][maxc];
int n, k;

int sum(int x, int l, int r) {
    l = max(l, 0);
    if(l == 0) return dp[x][r];
    return (dp[x][r] - dp[x][l - 1] + mod) % mod;
}

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    cin >> n >> k;
    for(int i = 1; i <= n; i++) {
        cin >> arr[i];
    }
    for(int i = 0; i <= k; i++) {
        dp[0][i] = 1;
    }
    for(int i = 1; i <= n; i++) {
        int cur = i & 1;
        for(int j = 0; j <= k; j++) {
            dp[cur][j] = sum(cur ^ 1, j - arr[i], j);
        }
        for(int j = 1; j <= k; j++) {
            dp[cur][j] += dp[cur][j - 1];
            dp[cur][j] %= mod;
        }
    }
    cout << sum(n & 1, k, k)<< '\n';
    return 0;
}


Measured memory_bytes: 4392
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.nio.charset.StandardCharsets;

public class Main {
    public static void main(String[] args) throws IOException {
        InputStreamReader reader = new InputStreamReader(System.in, StandardCharsets.UTF_8);
        BufferedReader in = new BufferedReader(reader);
        long size = Long.parseLong(in.readLine());
        String[] str = in.readLine().split(" ");
        long num1 = 0;
        long num2 = 0;
        long step = 0;
        long res = 0;

        for(int i=0; i < size-1; i++) {
        	num1 = Long.parseLong(str[i]) + step;
        	num2 = Long.parseLong(str[i+1]);

        	if(num1 > num2) {
        		step = num1 - num2;
        		res += step;
        	}else {
        		step = 0;
        	}
        }

        System.out.println(res);

    }
}

Measured memory_bytes: 61080
#include <iostream>

using namespace std;



int main(){
    char S[7];
    cin >> S;
    
    if(S[0] == 'S'){
        cout << "Cloudy" << endl;
    }else if(S[0] == 'C'){
        cout << "Rainy" << endl;
    }else{
        cout << "Sunny" << endl;
    }
    
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define FOR(i,s,e) for(int (i) = (s);(i) <= (e);(i)++)
#define RFOR(i,s,e) for(int (i) = (s);(i) >= (e);(i)--)
#define rep(i,n) FOR(i,0,n-1)

int check[4][30];

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

    rep(i,2)rep(j,28) check[i][j] = -1;

    rep(i,s.size())
    {
        if(check[0][s[i]-'a']!=-1)
        {
            if(check[0][s[i]-'a'] != t[i]-'a')
            {
                cout << "No" << endl;
                return 0;
            }
        }

        if(check[1][t[i]-'a']!=-1)
        {
            if(check[1][t[i]-'a'] != s[i]-'a')
            {
                cout << "No" << endl;
                return 0;
            }
        }

        check[0][s[i]-'a'] = t[i]-'a';
        check[1][t[i]-'a'] = s[i]-'a';
    }

    cout << "Yes"<< endl;

}


Measured memory_bytes: 776
#include <iostream>
#include <string>
using namespace std;
int main( void )
{
  ios::sync_with_stdio(false);
  string s;
  cin >> s;
  if( s[0] == s[1] && s[1] == s[2] ) {
    cout << "Yes" << endl;
  } else if( s[2] == s[3] && s[1] == s[2] ) {
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }
}

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

int main()
{
  int a1, a2, a3;
  
  cin >> a1 >> a2 >> a3;
  
  if (a1 + a2 + a3 <= 21) {
    cout << "win" << endl;
  }
  else {
    cout << "bust" << endl;
  }
  return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;;;;
int N,i,j,a;char s[100]
,t[100];int p[101][101]
;main(){scanf("%d%s%s",
&N,s,t)         ;for(i=
0;i<N;i         ++){for
(j=-0;j         <N;++j)
if(s[i]         ==t[j])
p[i+1][j+1]=p[i][j]+1;;
}for(i=0;i<=N;i++)a=max
(a,max(p[N][i],p[i][N])
);i+=1;         ;cout<<
2*N-a<<         endl;""
;return         0;i++;}

Measured memory_bytes: 256
N=gets.to_i
as=gets.split.map(&:to_i)
s1=Array.new(N,0)
s1[0]=as[0]
N.times do |i|
    next if i==0
    s1[i]=s1[i-1]+as[i]
end
s1.unshift(0)
hs=Hash.new{0}
(N+1).times do |i|
    hs[s1[i]]+=1
end
cnt=0
hs.values.each do |e|
    cnt+=e*(e-1)/2
end
puts cnt

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

int main()
{
    int N,R;

    cin>>N>>R;

    if(N>=10)
    {
        cout<<R<<endl;
        return 0;
    }
    else
    {
        cout<<R + 100 * (10 - N)<<endl;
        return 0;
    }
    
}

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

int main(){
	string st,ansst;
	int s1=0,s2=0,i;
	for(i=1;i<=3;i++){
		cin>>st;
		ansst+=st[0];
	}
	cout<<ansst<<endl;
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#define REP(i, a, n) for(int i = (a); i < (n); i++)
using namespace std;
typedef pair<int, int> PII;

int M, NMIN, NMAX, P[200];

int main(void) {
  while(cin >> M >> NMIN >> NMAX, M) {
    REP(i, 0, M) cin >> P[i];

    vector<PII> vec;
    REP(i, NMIN, NMAX + 1) vec.push_back(PII(P[i - 1] - P[i], i));
    sort(vec.begin(), vec.end());
    reverse(vec.begin(), vec.end());

    cout << vec[0].second << endl;
  }
}

Measured memory_bytes: 3000
import java.io.PrintStream;
import java.util.Scanner;

public class Main {
	static final PrintStream out = System.out;
	static Scanner sc = new Scanner(System.in);
	static final long Mod = 1000_000_007L;
	public static void main(String[] args) {
		Main main = new Main();
		main.solve();
		System.exit(0);
	}

	void solve() {
		int K = nextInt();
		int X = nextInt();

		for(int i=X-(K-1);i<=X+(K-1);i++) {
			out.print(i);
			if(i<X+(K-1)) {
				out.print(" ");
			}
		}
		out.println(" ");
	}

	public int[] nextIntArray(int n) {
		int[] a = new int[n];
		for (int i = 0; i < n; i++)a[i] = nextInt();
		return a;
	}
	public long[] nextLongArray(int n) {
		long[] a = new long[n];
		for (int i = 0; i < n; i++)a[i] = nextLong();
		return a;
	}
	public int nextInt() {
		return Integer.parseInt(next());
	}
	public long nextLong() {
		return Long.parseLong(next());
	}
	public String next() {
		return sc.next();
	}
}

Measured memory_bytes: 21844
#pragma warning(disable:4996)
#include "bits/stdc++.h"
using namespace std;

//macro
#define REP(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define rep(i,n) REP(i,0,n)
#define RREP(i,a,b) for(int i=(int)(b) - 1;i>=(int)(a);i--)
#define rrep(i,n) RREP(i,0,n)
#define each(i, ctn) for (auto &&i : (ctn))
#define all(a) (a).begin(),(a).end()
#define mp make_pair
#define INFL 1145148100000000000LL
#define EPS (1e-8)
#define MOD 1000000007
#define PI 3.141592653589793
#define equals(a,b)(fabs((a)-(b))<EPS)

//alias
using ll = long long;
using ull = unsigned long long;
using vb = vector<bool>;
using vi = vector<int>;
using vll = vector<ll>;
using vvb = vector<vb>;
using vvi = vector<vi>;
using vvll = vector<vll>;
using vs = vector<string>;
using P = pair<ll, ll>;
template<class T> using heap = priority_queue<T>;
template<class T> using minheap = priority_queue<T, vector<T>, greater<T>>;

//func
template<typename A, typename T>void assign2d(A&arr, ll H, ll W, T t) { arr.resize(H);	rep(i, H) arr[i].assign(W, t); }
template<class T> ostream &operator<<(ostream &os, const vector<T> &v) { int n = v.size(); rep(i, n)os << v[i] << (i == n - 1 ? "\n" : " "); return os; }
template <class T = int> inline T in() { T x; cin >> x; return x; }
template<class T> inline void print(const T &x) { cout << x << '\n'; }
struct pre_ { pre_() { cin.tie(nullptr); ios::sync_with_stdio(false); cout << fixed << setprecision(12); } } pre__;


int main()
{
	string N;
	bool f1 =true;
	bool f2 = true;
	cin >> N;
	rep(i, 2) {
		if (N[0] != N[i+1]) {
			f1 = false;
			break;
		}
	}
	rep(i, 2) {
		if (N[3] != N[i+1]) {
			f2 = false;
			break;
		}

	}
	if (f1 || f2) {
		print("Yes");
	}
	else {
		print("No");
	}
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll long long
#define SIZE_OF_ARRAY(array) (sizeof(array)/sizeof(array[0]))

using namespace std;

int gcd(int x, int y) { return (x % y)? gcd(y, x % y): y; }

int main(){
    double a,b; cin >> a >> b;
    double h,m;  cin >> h >> m;
    double min = h*60+m;
    double l = 0.5*min;
    double s = 6.0*m;
    double t = abs(l-s);
//    if(l>=s){
//        t = fmod(l-s, 180.0);
//    } else {
//        t = fmod(s-l, 180.0);
//    }

    double ans = sqrt(pow(a,2.0) + pow(b,2.0)-2.0*a*b*cos(M_PI*t/180.0));

    cout << fixed << setprecision(20) << ans << endl;


    return 0;
}


Measured memory_bytes: 4256
#include <cstdio>

int main()
{
  int n;
  scanf("%d", &n);
  long long d[50];
  for (int i = 0; i < n; ++i)
  {
    scanf("%lld", d + i);
  }
  long long ans = 0;
  for (int i = 0; i < n - 1; ++i)
  {
    for (int j = i + 1; j < n; ++j)
    {
      ans += d[i] * d[j];
    }
  }
  printf("%lld\n", ans);
  return 0;
}

Measured memory_bytes: 128
import math

a, b = map(int, input().split())
fa = []
fb = []

tmp = int(math.sqrt(a)) + 1
for i in range(2,tmp):
    while a % i == 0:
        a //= i
        fa.append(i)
if a != 1:
    fa.append(a)

tmp = int(math.sqrt(b)) + 1
for i in range(2,tmp):
    while b % i == 0:
        b //= i
        fb.append(i)
if b != 1:
    fb.append(b)

print(len(list(set(fa) & set(fb))) + 1)

Measured memory_bytes: 3064
import sys
readline = sys.stdin.buffer.readline
read = sys.stdin.read
sys.setrecursionlimit(10 ** 8)
INF = float('inf')
MOD = 10 ** 9 + 7

def main():
    N = int(readline())
    A = list(map(int, readline().split()))
    total = 0
    for a in A:
        total ^= a

    ans = [0] * N

    for i,a in enumerate(A):
        ans[i] = total^a

    print(' '.join(map(str, ans)))


if __name__ == '__main__':
    main()


Measured memory_bytes: 42408
sml = list("qwertyuiopasdfghjklzxcvbnm")
big = list("QWERTYUIOPASDFGHJKLZXCVBNM")

s = list(input())

if s[0] != "A" or s[1] in big or s[-1] in big:
  print("WA")
else:
  bigc = s[2:-1]
  cnt_c = 0
  cnt_big = 0
  for item in bigc:
    if item == "C":
      cnt_c += 1
    elif item in big:
      cnt_big += 1
  if cnt_c == 1 and cnt_big == 0:
    print("AC")
  else:
    print("WA")

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

int main(){
  int n,A[1000];
  int i,j,l,key;

  scanf("%d",&n);

  if(n > 100 || n < 1){
    exit(0);
  }
  for(i = 0; i < n; i++){
    scanf("%d",&A[i]);
    if(A[i] < 0 || 1000 < A[i]){
      exit(1);
    }
  }
  for(i = 0; i < n; i++){
    if(i == 0){
      printf("%d",A[i]);
      continue;
    }
    printf(" %d",A[i]);
  }
  printf("\n");

  for(i = 1; i < n; i++){
    key = A[i];
    j = i - 1;

    while(j >= 0 && A[j] > key){
      A[j+1] = A[j];
      j--;
    }
    A[j+1] = key;
    

    for(l = 0; l < n; l++){
      if(l == 0){
	printf("%d",A[l]);
	continue;
      }
      printf(" %d",A[l]);
    }
    printf("\n");
  }

  return 0;
}



Measured memory_bytes: 2072
F=->{gets.split.map &:to_i}
*,k=F[]
a,B=F[]<<k,F[]
m=i=a.index{0>k-=_1}
A=a[0..i]
loop{ 
k+=A.pop
(k-=B.shift;i+=1)until B[0]>k
m=[m,1+i-=1].max
}rescue p m>i ?m:i

Measured memory_bytes: 41804
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
int main(){
    long long r,g,b,n,ans=0;
    cin>>r>>g>>b>>n;
    rep(i,n+1)rep(j,n+1){
        if(n-i*r-j*g>=0&&(n-i*r-j*g)%b==0) ans++;
    }
    cout<<ans;
}

Measured memory_bytes: 256
import sys
import  math
from heapq import *
import fractions
from collections import defaultdict
stdin = sys.stdin
     
ns = lambda: stdin.readline().rstrip()
ni = lambda: int(stdin.readline().rstrip())
nm = lambda: map(int, stdin.readline().split())
nl = lambda: list(map(int, stdin.readline().split()))


def factorization(n):
    arr = []
    temp = n
    for i in range(2, int(-(-n**0.5//1))+1):
        if temp%i==0:
            cnt=0
            while temp%i==0:
                cnt+=1
                temp //= i
            arr.append([i, cnt])

    if temp!=1:
        arr.append([temp, 1])

    if arr==[]:
        arr.append([n, 1])

    return arr


N=int(input())
mod_l=factorization(N)
ans=0

if(N==1):
    print(0)
    sys.exit(0)
    
for i in mod_l:
    tmp=i[1]
    c=1
    while(c<=tmp):
        tmp-=c
        c+=1
        ans+=1

print(ans)


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


 int N,M;
 double p;
 double l2ceil;
 
 double ans=0;


 int main () {
      cin >> N >> M ;

      vector<int> id(N), gate(M);
      int min_id = 0,
      max_id = N;
      for(int i = 0; i < M; i++) {
          int Li, Ri;
          cin >> Li >> Ri;
          if(min_id < Li) min_id = Li;
          if(max_id > Ri) max_id = Ri;
      }

      int id_num = max_id - min_id+1;
      if(id_num < 0) id_num = 0;
      cout << id_num << endl;
      return 0;
 
 }


Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;;
#define ll long long
#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 FORR(i, m, n) for(int i = m;i >= n;i--)
#define INF 1<<30
#define LINF 1LL<<62
#define all(x) (x).begin(), (x).end()
#define mp make_pair
#define pb push_back
const int MOD = 1000000007;
 
typedef pair<ll, ll> P;
typedef pair<ll, P> PP;


int main(){
  ios::sync_with_stdio(false);
  cin.tie(0);
  ll a,b;cin >> a >> b;
  cout << (b-1 + a-2)/(a-1) << endl;
}

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

int main(){
	int n, count=0;
	int arr[100010]={};
	cin>> n;
	for(int i=1; i<=n; i++) cin>> arr[i];
	for(int i=1; i<=n; i++){
		if(arr[i]==i){
			count++;
			if(arr[i+1]==i+1){
				i++;
			}
		}
	}
	cout<<count;
}

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

using namespace std;
typedef long long ll;
typedef long double ld;
#define MAX 5000000000000000000LL
#define MIN -5000000000000000000LL

ll n, q;
ll all, bll;
ll ans;

struct lazysegtree
{
	ll seg[5000010], lazy[5000010];
	
	/*ll init(ll no, ll s, ll e)
	{
		if(s == e)
			return seg[no] = a[s];
		
		ll mid = (s + e) / 2;
		ll lef = init(no * 2, s, mid);
		ll rig = init(no * 2 + 1, mid + 1, e);
		
		return seg[no] = min(lef, rig);
	}*/
	
	ll update(ll no, ll s, ll e, ll l, ll r, ll v)
	{
		if(lazy[no])
		{
			seg[no] = min(seg[no], lazy[no]);
			
			if(s != e)
			{
				lazy[no * 2] = min(lazy[no * 2], lazy[no]);
				lazy[no * 2 + 1] = min(lazy[no * 2 + 1], lazy[no]);
			}
			
			lazy[no] = n;
		}
		
		if(l > e || r < s)
			return seg[no];
		
		if(l <= s && e <= r)
		{
			seg[no] = min(seg[no], v);
			
			if(s != e)
			{
				lazy[no * 2] = min(lazy[no * 2], v);
				lazy[no * 2 + 1] = min(lazy[no * 2 + 1], v);
			}
			
			return seg[no];
		}
		
		ll mid = (s + e) / 2;
		ll al = update(no * 2, s, mid, l, r, v);
		ll bl = update(no * 2 + 1, mid + 1, e, l, r, v);
		
		seg[no] = min(al, bl);
		return seg[no];
	}
	
	ll query(ll no, ll s, ll e, ll l, ll r)
	{
		if(lazy[no])
		{
			seg[no] = min(seg[no], lazy[no]);
			
			if(s != e)
			{
				lazy[no * 2] = min(lazy[no * 2], lazy[no]);
				lazy[no * 2 + 1] = min(lazy[no * 2 + 1], lazy[no]);
			}
			
			lazy[no] = n;
		}
		
		if(l > e || r < s)
			return n;
		
		if(l <= s && e <= r)
			return seg[no];
		
		ll mid = (s + e) / 2;
		ll lef = query(no * 2, s, mid, l, r);
		ll rig = query(no * 2 + 1, mid + 1, e, l, r);
		
		return min(lef, rig);
	}
};

lazysegtree r, c;

int main(void)
{
	scanf("%lld %lld", &n, &q);
	
	ans = (n - 2) * (n - 2);
	
	for(ll i = 0 ; i < 5000010 ; i++)
	{
		r.seg[i] = n;
		r.lazy[i] = n;
		c.seg[i] = n;
		c.lazy[i] = n;
	}
	
	while(q--)
	{
		scanf("%lld %lld", &all, &bll);
		
		if(all == 1)
		{
			ll qq = r.query(1, 1, n, bll, bll);
			//printf("%lld\n", qq);
			ans -= max(0LL, qq - 2);
			c.update(1, 1, n, 1, qq, bll);
		}
		
		else
		{
			ll qq = c.query(1, 1, n, bll, bll);
			//printf("%lld\n", qq);
			ans -= max(0LL, qq - 2);
			r.update(1, 1, n, 1, qq, bll);
		}
	}
	
	printf("%lld", ans);
	return 0;
}

Measured memory_bytes: 160080
#include <iostream>
#include <cmath>
using namespace std;
const double EPS = 1e-10;
int m[3] = {0};

int is(double a){
	if(abs(a) < EPS)return 1;
	if(a < 0)return 0;
	if(a > 0)return 2;
}

double mysqrt(double x){
	double l = 0 , r = x;
	for(int i = 0 ; i < 64 ; i++){
		double m = (l+r) / 2.0;
		if(m * m < x) l = m;
		else r = m;
	}
	return l;
}

double solve(double a,double b,double c,double d){
	//cout << a << " " << b << " " << c << " " << d << endl;
	if(a == 0){
		if(c * c - 4 * b * d < -EPS)return 0.0;
		double one = ( -c + mysqrt(c*c-4*b*d)  )/(2*b);
		double two = ( -c - mysqrt(c*c-4*b*d)  )/(2*b);
		//cout << one << "<>" << two << endl;
		m[is(one)]++;
		m[is(two)]++;
		return 0.0;
	}
	
	double l = -1000.0 , r = 1000.0;
	
	if(a < 0){ a *= -1; b *= -1; c *= -1; d *= -1;}
	
	for(int i=0;i<64;i++){
		double x = (l+r)/2.0;
		double res = a*x*x*x+b*x*x+c*x+d;
		if(res>0){
			r = x;
		}else{
			l = x;
		}
	}
	
	return l;
}
int main(){
	int N; cin >> N;
	while(N--){
		int a,b,c,d;
		cin >> a >> b >> c >> d;
		m[0] = m[1] = m[2] = 0;
		
		double n = solve(a,b,c,d); // 三次方程式には必ず一つ以上実根が含まれているので、それを見つける。
		m[is(n)]++;
		
		solve(0,a,a*n+b,n*(a*n+b)+c);
		cout << m[2] << " " << m[0] << endl;
	}
}


Measured memory_bytes: 3004
#include<iostream>
#include<cstdio>
#include<cstring>
#define N 1000
using namespace std;

int main() {
	char num[N];
	int sum = 0;

	while (1) {
		cin >> num;
		if (num[0] == '0') break;
		for (int i = 0; i < strlen(num); i++) {
			sum += num[i] - '0';
		}
		cout << sum << endl;
		sum = 0;
	}
	return 0;
}


Measured memory_bytes: 3072
n,y = map(int,input().split())
if 10000*n == y:
	print('{0} 0 0'.format(n))
elif 5000*n == y:
	print('0 {0} 0'.format(n))
else:
	a = 0
	b = 0
	c = 0
	i = 0
	while i < n:
		for k in range(n-i):
			total = 10000*i + 5000*k + 1000*(n-i-k)
			if total == y:
				 a = i
				 b = k
				 c = n-i-k
				 break
		i += 1
	if 10000*a + 5000*b + 1000*c == y:
		print('{0} {1} {2}'.format(a,b,c))
	else:
		print('-1 -1 -1')

Measured memory_bytes: 3188
#include <bits/stdc++.h>
 
#define fi first
#define se second
#define mp make_pair
#define mt make_tuple
#define pb push_back
#define INF  (1<<30)
#define INFL (1LL<<60)
#define EPS ((ld)(1e-9))
 
#define sz(x) ((int)(x).size())
#define setz(x) memset(x, 0, sizeof(x))
#define all(x) (x).begin(), (x).end()
#define rep(i, e) for (int i = 0, _##i = (e); i < _##i; i++)
#define repp(i, s, e) for (int i = (s), _##i = (e); i < _##i; i++)
#define repr(i, s, e) for (int i = (s)-1, _##i = (e); i >= _##i; i--)
#define repi(i, x) for (auto &i : (x))
#define ARR(...) vector<int>({__VA_ARGS__})
#define ARS(...) vector<string>({__VA_ARGS__})
 
 
using namespace std;
 
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef complex<double> base;
typedef pair<int, int> pii;
typedef pair<double, double> pdd;
typedef pair<ll, ll> pll;
 
template<typename T, typename V>
ostream &operator<<(ostream &os, const pair<T, V> pai) { 
    return os << '(' << pai.first << ' ' << pai.second << ')';
}
 
template<typename T>
ostream &operator<<(ostream &os, const vector<T> v) {
    cout << '[';
    for (auto p : v) cout << p << ",";
    cout << "]";
    return os;
}
 
template<typename T, typename V>
ostream &operator<<(ostream &os, const set<T, V> v) {
    cout << "{";
    for (auto p : v) cout << p << ",";
    cout << "}";
    return os;
}
 
template<typename T, typename V>
ostream &operator<<(ostream &os, const map<T, V> v) {
    cout << "{";
    for (auto p : v) cout << p << ",";
    cout << "}";
    return os;
}
 
#ifndef __DJKIM613
#define debug(...) 0
#define endl '\n'
#else
#define debug(...) cout << " [-] ", _dbg(#__VA_ARGS__, __VA_ARGS__)
template<class TH> void _dbg(const char *sdbg, TH h){ cout << sdbg << '=' << h << endl; }
template<class TH, class... TA> void _dbg(const char *sdbg, TH h, TA... a) {
    while(*sdbg != ',') cout << *sdbg++;
    cout << '=' << (h) << ','; 
    _dbg(sdbg+1, a...);
}
#endif
 
template<typename T> void get_max(T &a, T b) {a = max(a, b);}
template<typename T> void get_min(T &a, T b) {a = min(a, b);}

const int MAXN = 1e5 + 10;
int N, K;
int H[MAXN];
int D[MAXN];
int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr); cout.tie(nullptr);

    cin >> N >> K;
    for(int i = 1 ; i <= N ; i++) cin >> H[i];

    for(int i = 2 ; i <= N ; i++) {
        D[i] = D[i - 1] + abs(H[i] - H[i - 1]);
        repp(j, 1, min(i - 1, K) + 1) D[i] = min(D[i], D[i - j] + abs(H[i] - H[i - j]));
    } 

    cout << D[N];
    return 0;
}


Measured memory_bytes: 1024
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <cstdio>
#include <cstring>
using namespace std;

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

    string t;

    for (char &c: s) {
        t += c;

        while (t.length() >= 2 && t[t.length() - 2] == 'S' && t[t.length() - 1] == 'T') {
            t.pop_back();
            t.pop_back();
        }
    }

    cout << t.length() << endl;

    return 0;
}

Measured memory_bytes: 776
#include <cstdio>
#include <iostream>
#include <cstring>
#include <cmath>
#include <vector>
#include <string>
#include <algorithm>
#include <queue>
using namespace std;
typedef long long ll;
const int maxn = 100005;
 
int X,Y,Z;
int n;
struct P {
    ll x,y,z;
    bool operator<(const P&a)const {
        return x+a.y>y+a.x;
    }
} p[maxn];
 
struct cmp1 {
    bool operator()(int x,int y) {
        return p[x].x+p[y].z>p[y].x+p[x].z;
    }
};
struct cmp2 {
    bool operator()(int x,int y) {
        return p[x].y+p[y].z<p[x].z+p[y].y;
    }
};
 
bool in_silver[maxn];
int main() {
   //freopen("in.cpp","r",stdin);
    cin>>X>>Y>>Z;
    n=X+Y+Z;
    for(int i=0; i<n; i++)scanf("%lld%lld%lld",&p[i].x,&p[i].y,&p[i].z);
    sort(p,p+n);
    ll ret=0;
    priority_queue<int,vector<int>,cmp1>left_gold;
    priority_queue<int,vector<int>,cmp2>right_bronze;
    for(int i=0; i<X; i++) {
        ret+=p[i].x;
        left_gold.push(i);
    }
    for(int i=n-1; i>=X; i--) {
        ret+=p[i].z;
        right_bronze.push(i);
        if(right_bronze.size()>Z) {
            int tt=right_bronze.top();
            right_bronze.pop();
            ret-=p[tt].z;
            ret+=p[tt].y;
            in_silver[tt]=true;
        }
    }
    ll cur=ret;
    for(int i=X; i<X+Z; i++) {
        ll tmp=cur;
        tmp+=p[i].x;
        left_gold.push(i);
        int tt=left_gold.top();
        left_gold.pop();
        tmp-=p[tt].x;
        tmp+=p[tt].z;
        if(in_silver[i]) {
            tmp-=p[i].y;
            while(!right_bronze.empty()) {
                int tt=right_bronze.top();
                if(tt<=i) {
                    right_bronze.pop();
                } else {
                    right_bronze.pop();
                    in_silver[tt]=true;
                    tmp-=p[tt].z;
                    tmp+=p[tt].y;
                    break;
                }
            }
        } else {
            tmp-=p[i].z;
        }
        ret=max(ret,tmp);
        cur=tmp;
    }
    cout<<ret<<endl;
    return 0;
}

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


void solve()
{
  ll n;
  cin>>n;
  ll a[n];
  fo(i,n) cin>>a[i];
  
  ll ans=0;
  ll val=a[0];
  for(ll i=1;i<n;i++)
  {
      if(a[i]>val)
      val=a[i];
      if(val>a[i])
      ans+=(val-a[i]);
  }
  cout<<ans;
   
   
    
    
    
}

int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	ll t=1;
	//cin>>t;
	while(t--)
	{
	    solve();
	}
 
	return 0;
}


Measured memory_bytes: 5076
#include<iostream>
#include<map>
#include<cmath>
using namespace std;
#define REP(i,b,n) for(int i=b;i<n;i++)
#define rep(i,n)   REP(i,0,n)
const int DIV =256;
double calc(int S,int A,int C,int *I,int n){
  int R[n+1];
  int O[n];
  map<int,int>M;
  R[0]=S;
  REP(i,1,n+1)R[i]=(A*R[i-1]+C)%DIV;
  rep(i,n)O[i]=(I[i]+R[i+1])% DIV,M[O[i]]++;
  double ret=0;
  map<int,int>::iterator itr = M.begin();
  while(itr != M.end()){
    int t=(*itr).second;
    double tmp=(double)t/(double)n;
    ret+= -tmp*log(tmp);
    itr++;
  }
  return ret;
}


void solve(int n,int *I){
  double ans = 1e300;
  int a=100,s=100,c=100;
  rep(S,16){
    rep(A,16){
      rep(C,16){
	double tmp = calc(S,A,C,I,n);
	if ( tmp+1e-10 < ans){
	  ans=tmp;
	  a=A;s=S;c=C;
	}
	else if(  abs(tmp-ans)<1e-10){
	  if ( S<s){
	    a=A;s=S;c=C;
	    ans=tmp;
	  }else if ( S == s){
	    if ( A < a){
	      a=A;s=S;c=C;ans=tmp;
	    }else if ( a == A){
	      if (C<c){a=A;s=S;c=C;ans=tmp;}
	    }
	  }
	}
      }
    }
  }
  cout <<s << " " << a << " " << c << endl;
}

main(){
  int n;
  while(cin>>n &&n){
    int a[n];
    rep(i,n)cin>>a[i];
    solve(n,a);
  }
}

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

using namespace std;

using ll = long long;
const double eps = 1e-10;
const int MOD = 1000000007;
const int INF = 1000000000;
const ll LINF = 1ll<<50;

template<typename T>
void printv(const vector<T>& s) {
  for(int i=0;i<(int)(s.size());++i) {
    cout << s[i];
    if(i == (int)(s.size())-1) cout << endl;
    else cout << " ";
  }
}

int main() {
    cin.tie(0);
    cout << fixed << setprecision(10);

    int m, d; cin >> m >> d;
    int cnt = 0;
    for(int i=1;i<=m;++i) {
      for(int j=1;j<=d;++j) {
        int d1 = j%10, d10 = j/10;
        if(d1 >= 2 && d10 >= 2 && i == d1 * d10) cnt++;
      }
    }
    cout << cnt << endl;
}

Measured memory_bytes: 256
// ===========================================
// 20.02.27
// 
// 
// ===========================================

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
#define ET "\n"
#define CLR(arr) memset(arr, 0, sizeof(arr))
#define PAIR pair<int, int>
const ll INF = 1LL << 50;


int main(){
    
    ios::sync_with_stdio(false); cin.tie(0);
    
    const int MAX = 200020;
    
    int arr[MAX];
    int arc[MAX];
    
    int n; cin >> n;
    for(int i = 1; i <= n; i++){
        cin >> arr[i];
        arc[i] = arr[i];
    }
    
    sort(arr + 1, arr + n + 1, greater<int>());
    int mid = n/2;
    
    for(int i = 1; i <= n; i++){
        if(arc[i] < arr[mid]) 
            cout << arr[mid] << ET;
        else
            cout << arr[mid+1] << ET;
        
    }
    
}



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

template<typename T, typename U> bool chmin(T &a, const U &b) {
	return (a > b ? a = b, true : false);
}
template<typename T, typename U> bool chmax(T &a, const U &b) {
	return (a < b ? a = b, true : false);
}
const long long INF = 1000000000;

typedef long long ll;

#define writeln(n) cout<<n<<"\n";

typedef pair<int, int> P;
typedef pair<string, int> Psi;

int d[200010];
int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);

	char alf;cin>>alf;

	cout<<(char)(alf+1)<<endl;


}




Measured memory_bytes: 384
#include<bits/stdc++.h>
using namespace std;
//Optimisations
#pragma GCC target ("avx2")
#pragma GCC optimization ("unroll-loops")
#pragma GCC optimize("O2")
//shortcuts for functions
#define pb push_back
#define mp make_pair
#define ff first 
#define ss second
#define all(v) v.begin(),v.end()
#define prec(n) fixed<<setprecision(n)
#define n_l '\n'
// make it python 
#define gcd __gcd
#define append push_back
#define str to_string
// utility functions shortcuts
#define max3(a,b,c) max(a,max(b,c))
#define min3(a,b,c) min(a,min(b,c))
#define sswap(a,b) {a=a^b;b=a^b;a=a^b;}
#define swap(a,b) {auto temp=a; a=b; b=temp;}
#define init(dp) memset(dp,-1,sizeof(dp));
#define set0(dp) memset(dp,0,sizeof(dp));
#define bits(x) __builtin_popcount(x)
#define SORT(v) sort(all(v))
#define endl "\n"
#define forr(i,n) for(ll i=0;i<n;i++)
// declaration shortcuts
typedef long long int ll;
#define int ll
// Constants
constexpr int dx[] = {-1, 0, 1, 0, 1, 1, -1, -1};
constexpr int dy[] = {0, -1, 0, 1, 1, -1, 1, -1};
constexpr ll INF = 1999999999999999997; 
constexpr int inf= INT_MAX;
constexpr int MAXSIZE = int(1e6)+5;
constexpr auto PI  = 3.14159265358979323846L;
constexpr auto oo  = numeric_limits<int>::max() / 2 - 2;
constexpr auto eps = 1e-6;
constexpr auto mod = 1000000007;
constexpr auto MOD = 1000000007;
constexpr auto MOD9 = 1000000009;
constexpr auto maxn = 100006;
//void IOfile(){
//freopen(file_name, reade_mode, stdin);
//freopen(file_name, write_mode, stdout);
//}
void fastio(){
ios_base::sync_with_stdio(false);
cin.tie(NULL);
}
int32_t main(){
	fastio();
	int n,a,b;
	cin >> n >> a >> b;
	cout << min(n * a ,b);
}

Measured memory_bytes: 3672
package main

import (
	"fmt"
	"sort"
)

type Product struct {
	Price    int64
	Quantity int
}

type ArrProduct []Product

func (a ArrProduct) Len() int           { return len(a) }
func (a ArrProduct) Swap(i, j int)      { a[i], a[j] = a[j], a[i] }
func (a ArrProduct) Less(i, j int) bool { return a[i].Price < a[j].Price }

func main() {
	var N, M, B, t int
	var A, total int64
	var arr ArrProduct
	fmt.Scan(&N, &M)
	for i := 0; i < N; i++ {
		fmt.Scan(&A, &B)
		arr = append(arr, Product{A, B})
	}
	sort.Sort(ArrProduct(arr))
	for i := 0; i < M && t < M; i++ {
		q := arr[i].Quantity
		for j := 0; j < q && t < M; j++ {
			total += arr[i].Price
			t++
		}
	}
	fmt.Println(total)
}

Measured memory_bytes: 8960
#include <iostream>
#include <vector>
#include <string>
#include <cstdlib>
#include <algorithm>
#include <cstdio>
#include <cstring>
#include <stack>
#include <math.h>
#include <string.h>
#include <map>
#define Z class
#define ln cout<<'\n'
#define ll long long
#define rep(i, n) for(int i = 0; i < (n); ++i)
//ASCII a=97, A=65
// int H[N]; rep(i,N) scanf("%d", &H[i]);
// int max_x = *std::max_element(x.begin(), x.end());
// int min_y = *std::min_element(y.begin(), y.end());
// sort(vec.begin(), vec.end()); std::greater<>()
// reverse(vec.begin(), vec.end());
// scanf("%s",s);
// printf("%d\n",end-start+1);
using namespace std;
template<class T> inline bool chmax(T& a, T b){ if(a < b) { a=b; return 1; }return 0;}
template<class T> inline bool chmin(T& a, T b){ if(a > b) { a=b; return 1; }return 0;}
template<Z A>void pr(A a){cout<<a;ln;}
template<Z A,Z B>void pr(A a,B b){cout<<a<<' ';pr(b);}
template<Z A,Z B,Z C>void pr(A a,B b,C c){cout<<a<<' ';pr(b,c);}
template<Z A,Z B,Z C,Z D>void pr(A a,B b,C c,D d){cout<<a<<' ';pr(b,c,d);}
template<Z A>void PR(A a,ll n){rep(i,n){if(i)cout<<' ';cout<<a[i];}ln;}

int GCD(int a, int b) { return b ? GCD(b, a%b) : a; }
const long long INF = 1LL << 60;

int main(){
    char c; cin >> c;
    if(c=='a' || c=='i' || c=='u' || c=='e' || c=='o') pr("vowel");
    else pr("consonant");
}


Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
#ifdef _DEBUG
#define dlog(str) cout << "====" << str << endl;
#else
#define dlog(str)
#endif
#define INF 999999999
#define MOD 1000000007
#define REP(i, n) for(int i = 0, i##_l = (n); i < i##_l; i++)
#define FOR(i, s, e) for(int i = s, i##_l = (e); i < i##_l; i++)
#define LLI long long int
#define _min(a,b) ((a<b)?a:b)
#define _max(a,b) ((a<b)?b:a)
#define chmax(a, b) a = _max(a, b)
#define chmin(a, b) a = _min(a, b)
#define bit(a, shift) ((a>>shift)&1))
#define pm(a) ((a)?1:-1)
#define SORT(v) sort(v.begin(),v.end())
#define RSORT(v) sort((v).rbegin(), (v).rend())
// int 2.14E±9    lli 9.2E±18    double 1.7E±380


int main()
{
	cout << fixed << setprecision(10);

	int x, y;
	cin >> x >> y;

	REP(i, 100)
	{
		REP(j, 100)
		{
			if (i * 2 + j * 4 == y && i + j == x)
			{
				cout << "Yes";
				return 0;
			}
		}
	}
	cout << "No";
	return 0;
}

Measured memory_bytes: 3632
import sys
import numpy as np
import random
from decimal import Decimal
import itertools
import re
import bisect
from collections import deque, Counter
from functools import lru_cache

sys.setrecursionlimit(10**9)
INF = 10**13
def LI(): return list(map(int, sys.stdin.buffer.readline().split()))
def I(): return int(sys.stdin.buffer.readline())
def LS(): return sys.stdin.buffer.readline().rstrip().decode('utf-8').split()
def S(): return sys.stdin.buffer.readline().rstrip().decode('utf-8')
def IR(n): return [I() for i in range(n)]
def LIR(n): return [LI() for i in range(n)]
def SR(n): return [S() for i in range(n)]
def LSR(n): return [LS() for i in range(n)]
def SRL(n): return [list(S()) for i in range(n)]
def MSRL(n): return [[int(j) for j in list(S())] for i in range(n)]
def SERIES(n): return np.fromstring(sys.stdin.buffer.read(), dtype=np.int32, sep=' ')
def GRID(h,w): return np.fromstring(sys.stdin.buffer.read(), dtype=np.int32, sep=' ').reshape(h,-1)[:,:w]
def GRIDfromString(h,w): return np.frombuffer(sys.stdin.buffer.read(), 'S1').reshape(h,-1)[:,:w]
MOD = 1000000007

def main():
	w, h, n = LI()
	left_x, right_x, lower_y, upper_y = 0, w, 0, h
	for _ in range(n):
		x, y, a = LI()
		if a == 1:
			left_x = max(x, left_x)
		elif a == 2:
			right_x = min(x, right_x)
		elif a == 3:
			lower_y = max(y, lower_y)
		elif a == 4:
			upper_y = min(y, upper_y)
	if right_x > left_x and upper_y > lower_y:
		print((right_x-left_x)*(upper_y-lower_y))
	else:
		print(0)


if __name__ == '__main__':
    main()

Measured memory_bytes: 27192