akhauriyash/Code-Regression huggingface dataset:
package main

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

func main() {
	sc := NewScanner()

	n := sc.NextInt()
	mp := map[int]int{}
	mp[n]++
	prev := n
	i := 1
	for {
		i++
		if prev%2 == 0 {
			prev = prev / 2
		} else {
			prev = 3*prev + 1
		}
		//		fmt.Printf("%+v %d\n", prev, i) // output for debug
		if mp[prev] > 0 {

			break
		} else {
			mp[prev]++
		}

	}
	fmt.Printf("%v\n", i)

}

type Scanner struct {
	r   *bufio.Reader
	buf []byte
	p   int
}

func NewScanner() *Scanner {
	rdr := bufio.NewReaderSize(os.Stdin, 1000)
	return &Scanner{r: rdr}
}
func (s *Scanner) Next() string {
	s.pre()
	start := s.p
	for ; s.p < len(s.buf); s.p++ {
		if s.buf[s.p] == ' ' {
			break
		}
	}
	result := string(s.buf[start:s.p])
	s.p++
	return result
}
func (s *Scanner) NextLine() string {
	s.pre()
	start := s.p
	s.p = len(s.buf)
	return string(s.buf[start:])
}
func (s *Scanner) NextInt() int {
	v, _ := strconv.Atoi(s.Next())
	return v
}

func (s *Scanner) NextIntArray() []int {
	s.pre()
	start := s.p
	result := []int{}
	for ; s.p < len(s.buf); s.p++ {
		if s.buf[s.p] == ' ' {
			v, _ := strconv.Atoi(string(s.buf[start:s.p]))
			result = append(result, v)
			start = s.p + 1
		}
	}
	v, _ := strconv.Atoi(string(s.buf[start:s.p]))
	result = append(result, v)

	return result
}

func (s *Scanner) NextMap() map[int]bool {
	s.pre()
	start := s.p
	mp := map[int]bool{}
	for ; s.p < len(s.buf); s.p++ {
		if s.buf[s.p] == ' ' {
			v, _ := strconv.Atoi(string(s.buf[start:s.p]))
			mp[v] = true
			start = s.p + 1
		}
	}
	v, _ := strconv.Atoi(string(s.buf[start:s.p]))
	mp[v] = true

	return mp
}

func (s *Scanner) pre() {
	if s.p >= len(s.buf) {
		s.readLine()
		s.p = 0
	}
}
func (s *Scanner) readLine() {
	s.buf = make([]byte, 0)
	for {
		l, p, e := s.r.ReadLine()
		if e != nil {
			panic(e)
		}
		s.buf = append(s.buf, l...)
		if !p {
			break
		}
	}
}


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

using namespace std;

const int max_n = 100011, inf = 1000111222;

int n, x, b[max_n], l[max_n], r[max_n];
char used[max_n];
vector<pair<long long, int>> v;
long long sum;

bool check1(int k) {
    sum = 0;
    v.clear();
    for (int i = 0; i < n; ++i) {
        sum -= 1LL * l[i] * b[i];
        v.push_back({1LL * r[i] * x - 1LL * (r[i] - l[i]) * b[i], i});
    }
    sort(v.begin(), v.end());
    reverse(v.begin(), v.end());
    memset(used, 0, sizeof(used));
    for (int i = 0; i < k; ++i) {
        sum += v[i].first;
        used[v[i].second] = 1;
    }
    return sum >= 0;
}

int main() {
    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);
    scanf("%d%d", &n, &x);
    for (int i = 0; i < n; ++i) {
        scanf("%d%d%d", &b[i], &l[i], &r[i]);
    }
    int L = -1, R = n;
    while (R - L > 1) {
        int mid = (L + R) / 2;
        if (check1(mid)) {
            R = mid;
        } else {
            L = mid;
        }
    }
    if (R == 0) {
        puts("0");
        return 0;
    }
    const int k = R - 1;
    check1(k);
    int add = x;
    for (int i = 0; i < n; ++i) {
        if (used[i]) {
            sum -= 1LL * r[i] * x - 1LL * (r[i] - l[i]) * b[i];
            sum += v[k].first;
        }
        L = 0;
        R = x;
        while (R - L > 1) {
            int mid = (L + R) / 2;
            bool ok = false;
            for (int to = l[i]; to <= r[i]; to += r[i] - l[i]) {
                if (sum + 1LL * to * mid - 1LL * (to - l[i]) * b[i] >= 0) {
                    ok = true;
                    break;
                }
                if (l[i] == r[i]) {
                    break;
                }
            }
            if (ok) {
                R = mid;
            } else {
                L = mid;
            }
        }
        add = min(add, R);
        if (used[i]) {
            sum -= v[k].first;
            sum += 1LL * r[i] * x - 1LL * (r[i] - l[i]) * b[i];
        }
    }
    long long ans = 1LL * k * x + add;
    printf("%lld\n", ans);
    return 0;
}


Measured memory_bytes: 3572
#pragma GCC optimize("Ofast")
#pragma GCC target("avx,avx2,fma")

#include <bits/stdc++.h>

using namespace std;

#define int long long
#define all(a) (a).begin(), (a).end()
#define sz(a) (int) (a).size()
#define x first
#define y second

mt19937 rnd(chrono::steady_clock::now().time_since_epoch().count());

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

    int x;
    cin >> x;
    for (int a = -100; a <= 1000; a++){
        for (int b = -100; b <= 1000; b++) {
            if (a * a * a * a * a - b * b * b * b * b == x) {
                cout << a << " " << b << "\n";
                return 0;
            }
        }
    }

    return 0;
}


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

#define ASC(vec) vec.begin(), vec.end()		// 昇順ソート 例：sort(ASC(vec));
#define DESC(vec) vec.rbegin(), vec.rend()	// 降順ソート 例:sort(DESC(vec));
#define rep(i, n) for(int i = 0; i < n; i++)
#define Rep(i, n) for(int i = 1; i < n; i++)

const int mod = 1000000007;
const int inf = (int)1e9 + 7;
const long long INF = 1LL << 60;

using ii = pair<int, int>;
using ll = long long;
using vi = vector<int>;
using vd = vector<double>;
using vb = vector<bool>;
using vl = vector<ll>;
using vs = vector<string>;
using vvi = vector<vector<int>>;
using vvl = vector<vector<ll>>;
using vii = vector<pair<int, int>>;

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; }

ll GCD(ll a, ll b) { return b ? GCD(b, a % b) : a; }
ll LCM(ll a, ll b) { return (a * b) / GCD(a, b); }
int round_int(int a, int b) { return (a + (b - 1)) / b; }

// 素因数分解; 返り値は(素数, 乗数)のvector配列
vector<pair<ll, int>> factorize(ll n) {
	vector<pair<ll, int>> res;
	for (ll i = 2; i * i <= n; ++i) {
		if (n % i) continue;
		res.emplace_back(i, 0);
		while (n % i == 0) {
			n /= i;
			res.back().second++;
		}
	}
	if (n != 1) res.emplace_back(n, 1);
	return res;
}

constexpr array<int, 9> dx = { 0, 1, 0, -1, -1, 1, 1, -1, 0 };
constexpr array<int, 9> dy = { 1, 0, -1, 0, 1, 1, -1, -1, 0 };
constexpr auto MAX = 100010;

// ──────────────────────────────────────────────────────────────────────────────


int main() {
	int n;
	cin >> n;
	vi a(n);
	rep(i, n) cin >> a[i];
	sort(ASC(a));
	rep(i, n - 1) {
		if (a[i] == a[i + 1]) {
			cout << "NO" << endl;
			return 0;
		}
	}
	cout << "YES" << endl;
	return 0;
}

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

typedef long long ll;
const ll MOD = (ll)1e9 + 7;
ll mult(ll x, ll y)
{
	return (x * y) % MOD;
}

int main()
{
//	freopen("input.txt", "r", stdin);
//	freopen("output.txt", "w", stdout);

	ll ans = 1;
	int n;
	scanf("%d", &n);
	int m = 0;
	while(n--)
	{
		int x;
		scanf("%d", &x);
		if (2 * m + 1 > x)
		{
			ans = mult(ans, m + 1);
			m--;
		}
		m++;
	}
	while(m > 0)
	{
		ans = mult(ans, m);
		m--;
	}
	printf("%lld\n", ans);

	return 0;
}

Measured memory_bytes: 768
d,g = map(int,input().split())
p = []
c = []
for i in range(d):
    x,y = map(int,input().split())
    p.append(x)
    c.append(y)
ans = 10000
for i in range(1<<d):
    s = cnt = 0
    rest_max = -1
    for j in range(d):
        if (i>>j)&1:
            s += c[j] + 100*(j+1)*p[j]
            cnt += p[j]
        else:
            rest_max = j
    if s < g:
        if g-s > (p[rest_max]-1)*(rest_max+1)*100:
            continue
        else:
            cnt += (g-s-1)//((rest_max+1)*100)+1
    ans = min(ans, cnt)
print(ans)


Measured memory_bytes: 3064
#include<iostream>
#include<queue>
#include<memory>
#include<map>
#include<set>
#include<unordered_map>
#include<array>
#include<vector>
#include<algorithm>
#include<list>
#include<limits>
#include<stdio.h>
#include<math.h>
#include<string>

using namespace std;
using ll = long long;
using vec = vector<ll>;
using mat = vector<vec>;
using lst = list<ll>;

const ll MOD = 1000000007;

int main()
{
	int A, B;

	cin >> A >> B;

	cout << 6 - A - B << endl;

}

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

string add(string a, string b) {
  while(a.size() < b.size()) a.insert(0, "0");
  while(b.size() < a.size()) b.insert(0, "0");
  int n = a.size();
  string res(n, ' ');
  for(int i = n-1, d = 0; i >= 0; --i) {
    int p = a[i]-'0';
    int q = b[i]-'0';
    int r = p+q+d;
    d = r/10;
    res[i] = r%10 + '0';
    if(i == 0 && d != 0) res.insert(0, string(1,d+'0'));
  }
  return res;
}

int main() {
  int Tc;
  cin >> Tc;
  while(Tc--) {
    string a, b;
    cin >> a >> b;
    string tmp = add(a,b);
    if(tmp.size() > 80) cout << "overflow" << endl;
    else cout << tmp << endl;
  }
  return 0;
}

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


int main(){
    
    string divide[4] = {"dream","dreamer","erase","eraser"};

    string S;
    cin >> S;

    reverse(S.begin(),S.end());
    for(int i = 0; i < 4; i++){
         reverse(divide[i].begin(),divide[i].end());
    }     

    bool can = true;
    for(int i = 0; i < S.size();){
        bool can2 = false;
        for(int j = 0; j < 4; j++){
            string d = divide[j];
            if(d == S.substr(i,d.size())){
                can2 = true;
                i += d.size();
            }
        }
        if(!can2){ 
            can = false;
            break;
        }    
    }

    if(can) cout<<"YES\n";
    else cout <<"NO\n";

}


Measured memory_bytes: 512
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <utility>
#include <stack>
#include <functional>
#include <queue>
#include <cmath>
#include <set>
#include <map>

#define rep(i,j,k) for(int i=j;i<k;i++)
#define Sort(x) sort((x).begin(),(x).end())
#define all(x) (x).begin(),(x).end()
#define fi first
#define se second
#define vi vector<int>
#define INF 1000000000
#define MOD 1000000007
#define pb push_back
#define MP make_pair
typedef long long ll;
typedef std::pair<int,int> pii;
int dx[4]={0,1,0,-1},dy[4]={1,0,-1,0};

using namespace std;

int main() {
    int n;cin>>n;
    vector<vector<char>> v={{},{'.',',','!','?',' '},{'a','b','c'},{'d','e','f'},{'g','h','i'},{'j','k','l'},{'m','n','o'},{'p','q','r','s'},{'t','u','v'},{'w','x','y','z'}};
    bool f=false;
    rep(j,0,n){
        string s;
        cin>>s;
        int x,t=-1;
        rep(i,0,s.length()){
            if(!f){
                f=true;
                x=s[i]-'0';
            }
            
            if(s[i]!='0'){
                t++;
                if(x==9||x==7){
                    if(t==4)t=0;
                }else if(x==1){
                    if(t==5)t=0;
                }else{
                    if(t==3)t=0;
                }
            }else {
                if(t!=-1)cout<<v[x][t];
                f=false;
                t=-1;
            }
        }
        cout<<endl;
    }
    return 0;
}



Measured memory_bytes: 3052
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading.Tasks;
using System.Collections;
static class Extensions
{
    public static int ToInt(this string s) => int.Parse(s);
    public static long ToLong(this string s) => long.Parse(s);
    public static char ToChar(this string s) => char.Parse(s);
    public static double ToDouble(this string s) => double.Parse(s);
    public static int[] ToIntArray(this string s) => s.Replace(',', ' ').Split(' ').Select(x => x.ToInt()).ToArray();
    public static long[] ToLongArray(this string s) => s.Replace(',', ' ').Split(' ').Select(x => x.ToLong()).ToArray();
    public static double[] ToDoubleArray(this string s) => s.Replace(',', ' ').Split(' ').Select(x => x.ToDouble()).ToArray();
}

class Program
{
    static string[] ReadLines(int n) => Enumerable.Range(0, n).Select(s => Console.ReadLine()).ToArray();

    static void Main()
    {
        int N = Console.ReadLine().ToInt();
                
        int[] cnt = new int[N + 1];

        for(int i = 2; i <= N; i++)
        {
            foreach(var x in calc(i))
            {
                cnt[x] += 1;
            }
        }
        
        int ans = 0;

        //かけて75になるのは
        //5 * 5 * 3
        for(int i = 0; i < cnt.Length; i++)
        {
            for (int j = i+1; j < cnt.Length; j++)
            {
                for (int k = j + 1; k < cnt.Length; k++)
                {
                    if (cnt[i] >= 4 && cnt[j] >= 4 && cnt[k] >= 2) ans++;
                    if (cnt[i] >= 4 && cnt[j] >= 2 && cnt[k] >= 4) ans++;
                    if (cnt[i] >= 2 && cnt[j] >= 4 && cnt[k] >= 4) ans++;
                }
            }
        }

        //25 * 3
        for (int i = 0; i < cnt.Length; i++)
        {
            for (int j = i + 1; j < cnt.Length; j++)
            {
                if (cnt[i] >= 2 && cnt[j] >= 24) ans++;
                if (cnt[i] >= 24 && cnt[j] >= 2) ans++;
            }
        }

        //15 * 5
        for (int i = 0; i < cnt.Length; i++)
        {
            for (int j = i + 1; j < cnt.Length; j++)
            {
                if (cnt[i] >= 14 && cnt[j] >= 4) ans++;
                if (cnt[i] >= 4 && cnt[j] >= 14) ans++;
            }
        }

        //75
        ans += cnt.Count(n => n >= 74);

        Console.WriteLine(ans);
    }

    static IEnumerable<int> calc(int n)
    {
        int nCpy = n;

        for(int i = 2; i <= nCpy; i++)
        {
            while(n % i == 0)
            {
                n /= i;
                yield return i;
            }
        }
    }
}

Measured memory_bytes: 13268
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const double pi = acos(-1);
#define FOR(i,a,b) for (ll i=(a),__last_##i=(b);i<__last_##i;i++)
#define RFOR(i,a,b) for (ll i=(b)-1,__last_##i=(a);i>=__last_##i;i--)
#define REP(i,n) FOR(i,0,n)
#define RREP(i,n) RFOR(i,0,n)
#define __GET_MACRO3(_1, _2, _3, NAME, ...) NAME
#define rep(...) __GET_MACRO3(__VA_ARGS__, FOR, REP)(__VA_ARGS__)
#define rrep(...) __GET_MACRO3(__VA_ARGS__, RFOR, RREP)(__VA_ARGS__)
template<typename T> ostream& operator<<(ostream& os, const vector<T>& v) {
    REP(i,v.size()){if(i)os<<" ";os<<v[i];}return os;}
template<typename T> ostream& operator<<(ostream& os, const vector<vector<T>>& v) {
    REP(i,v.size()){if(i)os<<endl;os<<v[i];}return os;}

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; }

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

vector< vector<int> > Graph;
vector< int > value;



int main(int argc, const char * argv[]) {
    
   

    cin.tie(0);
    ios::sync_with_stdio(false);
   
    
    string s; cin >> s;
    if(   (s[0]==s[1]&&s[1]==s[2]) || (s[1]==s[2]&&s[2]==s[3])    ) cout << "Yes" << endl;
    else cout << "No" << endl;
    
    
}


Measured memory_bytes: 256
n=int(input())
l=list(map(int,input().split()))
count=0
for a in range(n):
    for b in range(a+1,n):
        for c in range(b+1,n):
            if l[a]+l[b]>l[c] and l[a]+l[c]>l[b] and l[c]+l[b]>l[a]:
                if l[a]==l[b] or l[a]==l[c] or l[b]==l[c]:
                    pass
                else:
                    count=count+1
            else:
                pass
print(count)

Measured memory_bytes: 9208
import heapq
from operator import itemgetter

N,M = map(int,input().split())
AB = []
hq = []
heapq.heapify(hq)
ans = 0

for i in range(N):
    tmpA,tmpB = map(int,input().split())
    if tmpA <= M:
        AB.append([tmpA,tmpB])

AB2 = sorted(AB,key = itemgetter(0))  
maxlen = len(AB2)
last = 0

for i in range(1,M+1):
    for j in range(last,maxlen):
        if AB2[j][0] == i:
            heapq.heappush(hq,-AB2[j][1])

            if j == maxlen -1:
                if len(hq) >= 1:
                    ans += -heapq.heappop(hq)

        else:
            last = j
            if len(hq) >= 1:
                ans += -heapq.heappop(hq)
            break

print(ans)

Measured memory_bytes: 24944
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i,n) for(ll i=0; i<n; ++i)
#define rep1(i,n) for(ll i=1; i<=n; ++i)
#define revrep(i,n) for(ll i=n-1; i>=0; --i)
inline constexpr ll Inf = (1ULL << 62) -1;
#define fastio cin.tie(nullptr); ios_base::sync_with_stdio(false);
#define endl '\n'
template <class T> bool updmax(T& a, T b) { if (b > a) { a = b; return true;} return false;}
template <class T> bool updmin(T& a, T b) { if (b < a) { a = b; return true;} return false;}

int main() {
    fastio;
    ll ans=0;
    string s;
    cin >> s;
  if (s.back() == 's') s += "es";
  else s += "s";
    cout << s << endl;
}


Measured memory_bytes: 3648
// copied from https://atcoder.jp/contests/abc177/submissions/16358885

#include <iostream>
#include <vector>
#define ll long long
using namespace std;

int main(void) {
	int N;
	cin >> N;
	int A[N];
	ll B[N+1];
	int mod = 1000000007;

	for (int i = 0; i < N; i++) {
		cin >> A[i];
		B[i + 1] = B[i] + A[i];
	}

	long ans = 0;

	//i について全探索する
	for (int i = 0; i < N; i++) {
		//累積和を使ってA[i+1] + ... + A[N] を求める
		long long sum = (B[N] - B[i + 1]) % mod;

		ans += A[i] * sum;
		ans %= mod;
	}

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



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

#define lugan "FROG1"
#define pb push_back
#define fi first
#define se second
#define all(x) x.begin(), x.end()
#define endl '\n'
#define _io ios_base::sync_with_stdio(0);   cin.tie(NULL); cout.tie(NULL);

using namespace std;

typedef long long ll;
typedef pair<int, int> pii;
const int N = 1e5+7;
const int oo = 1e9+7;

inline void initf()
{
    freopen(lugan".inp", "r", stdin);
    freopen(lugan".out", "w", stdout);
}

int n;
int a[N], dp[N];

int main()
{
    _io
    cin >> n;
    a[0] = oo;
    for (int i=1; i<=n; i++)
        cin >> a[i];
    for (int i=2; i<=n; i++)
        dp[i] = min(dp[i-1] + abs(a[i] - a[i-1]), dp[i-2] + abs(a[i] - a[i-2]));
    cout << dp[n];
    return 0;
}



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

int main() {
    int n, m;
    int result;
    cin >> n >> m;
    vector<int> a(m);
    for (int i = 0; i < m; i++) {
        cin >> a.at(i);
    }
    result = n - accumulate(a.begin(), a.end(), 0);
    if (result < 0) result = -1;
    cout << result;
}

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

void main()
{
    auto hwk = readln.split.to!(int[]);
    auto H = hwk[0];
    auto W = hwk[1];
    auto K = hwk[2];
    auto MAP = new char[][](H, W);
    auto MEMO = new bool[][](H, W);
    int sx, sy;
    foreach (i; 0..H) foreach (j, c; readln.chomp.to!(char[])) {
        if (c == 'S') {
            sx = j.to!int;
            sy = i;
            MEMO[i][j] = true;
        }
        MAP[i][j] = c;
    }
    auto ss = [[sx, sy]];
    foreach (_; 0..K) {
        int[][] nss;
        foreach (s; ss) {
            auto x = s[0];
            auto y = s[1];
            static foreach (d; [[1,0], [0,1], [-1,0], [0,-1]]) {{
                auto xx = x+d[0];
                auto yy = y+d[1];
                if (0 <= xx && xx < W && 0 <= yy && yy < H && MAP[yy][xx] == '.' && !MEMO[yy][xx]) {
                    MEMO[yy][xx] = true;
                    nss ~= [xx, yy];
                    if (xx == 0 || xx == W-1 || yy == 0 || yy == H-1) {
                        writeln(1);
                        return;
                    }
                }
            }}
        }
        ss = nss;
    }
    auto r = int.max;
    foreach (i; 0..H) foreach (j; 0..W) if (MEMO[i][j]) {
        r = min(r, min((i-1+K)/K, (j-1+K)/K, (H-i-2+K)/K, (W-j-2+K)/K));
    }
    writeln(r+1);
}

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

#define F first
#define S second
#define FOR(i,a,b) for (int i = (a); i <= (b); ++i)
#define NFOR(i,a,b) for(int i = (a); i >= (b); --i)
#define all(x) (x).begin(), (x).end()
#define sz(x) int(x.size())
typedef long long ll; typedef pair <int, int> ii; typedef vector <int> vi; const int inf = 1e9 + 7;
#define pr(...) dbs(#__VA_ARGS__, __VA_ARGS__)
template <class T> void dbs(string str, T t) {cout << str << " : " << t << endl;}
template <class T, class... S> void dbs(string str, T t, S... s) {int idx = str.find(','); cout << str.substr(0, idx) << " : " << t << ","; dbs(str.substr(idx + 1), s...);}
template <class S, class T>ostream& operator <<(ostream& os, const pair<S, T>& p) {return os << "(" << p.first << ", " << p.second << ")";}
template <class T>ostream& operator <<(ostream& os, const vector<T>& p) {os << "[ "; for (auto& it : p) os << it << " "; return os << "]";}
template <class T>ostream& operator <<(ostream& os, const set<T>& p) {os << "[ "; for (auto& it : p) os << it << " "; return os << "]";}
template <class S, class T>ostream& operator <<(ostream& os, const map<S, T>& p) {os << "[ "; for (auto& it : p) os << it << " "; return os << "]";}
template <class T> void prc(T a, T b) {cout << "["; for (T i = a; i != b; ++i) {if (i != a) cout << ", "; cout << *i;} cout << "]";cout<<endl;}

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

	int n; cin >> n;
	vi p(n); FOR (i, 0, n - 1) cin >> p[i], --p[i];

	int ans = 0;
	FOR (i, 0, n - 1) if (p[i] == i) {
		int j = i; while (j < n and p[j] == j) ++j;
		--j;
		ans += (j - i + 2) / 2;
		i = j;
	}
	cout << ans;

	return 0;
}


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

int main()
{
    int n, m;
    cin >> n;
    vector<string> s(n);
    for(int i=0;i<n;i++){
        cin >> s[i];
    }
    cin >> m;
    vector<string> t(m);
    for(int i=0;i<m;i++){
        cin >> t[i];
    }
    int ans = 0;
    for(int j=0;j<n;j++){
        int tmp = 0;
        for(int k=0;k<n;k++){
            if(s[j] == s[k]){tmp++;}
        }
        for(int l=0;l<m;l++){
            if(s[j] == t[l]){tmp--;}
        }
        if(tmp > ans){ans = tmp;}
    }
    cout << ans << endl;
    return 0;
}

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

int main() {
  string S;
  cin >> S;
  int N = S.size();
  int ans=0;
  //string comp='0';
  
  for(int i=0; i < N; i=i+2){
      if(S[i]=='0'){
          ans++;
      }
  }

  for(int i=1; i < N; i=i+2){
      if(S[i]=='1'){
          ans++;
      }
  }

  if(N - ans < ans){
      ans = N - ans;
  }

  cout << ans << "\n";
  return 0;
}

Measured memory_bytes: 512
#include<stdio.h>
#include<stdlib.h>
int H[200005];
int comp( const void *a,const void *b){
	return *(int*)a-*(int*)b;
} 
int main(){
	int n,k;
	scanf("%d %d",&n,&k);
	long long i;
	for(i=0;i<n;i++){
		scanf("%d",&H[i]);
	}
	qsort(H,n,sizeof(int),comp);
	long long sum;
	if(k>=n){
		printf("0");
	}
	else{
		sum=0;
		for(i=0;i<n-k;i++){
			sum=sum+(long long)H[i];
		}
			printf("%lld",sum);
	}

	return 0;
}

Measured memory_bytes: 1788
#include<bits/stdc++.h>
using namespace std;
int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  int n;
  cin >> n;
  int ans = 0;
  int cnt = 0;
  int f;
  cin >> f;
  for(int i = 1; i < n; i++){
    long long h;
    cin >> h;
    if(f >= h) cnt++;
    else cnt = 0;
    ans = max(cnt, ans);
    f = h;
  }
  cout << ans << endl;
  return 0;
}

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

int main(){
    int N;
    cin >> N;
    bool f =0;
    char c;
    for (int i = 0; i < N; i++) {
        cin >> c;
        if (c =='Y') f = 1;
    }
    if(f == 0) cout << "Three" << endl;
    else cout << "Four" << endl;
}

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

int cnt[27];

int main(){

    cin.sync_with_stdio(0); cin.tie(0); cout.tie(0);

    string s; cin >> s;
    int n = s.size();

    for(char i : s)
        ++cnt[i - 'a'];

    long long tot = 1;

    for(int i = 0; i < n; ++i){
        --cnt[s[i] - 'a'];
        tot += (n - i - 1) - cnt[s[i] - 'a'];
    }

    cout << tot << "\n";

    return 0;

}

Measured memory_bytes: 720
#include <stdio.h>
int in()
{
	int n = 0, c = getchar_unlocked();
	do n = 10*n + (c & 0xf), c = getchar_unlocked(); while (c >= '0');
	return n;
}

int main()
{
	int n, a, min, ans;

	n = in()-2;
	min = in(), a = in();
	ans = a-min;
	if (a < min) min = a;
	while (n--) {
		a = in();
		if (a < min) min = a;
		else if (a-min > ans) ans = a-min;
	}
	printf("%d\n", ans);
	return 0;
}


Measured memory_bytes: 2104
#include <iostream>
#include <vector>
#include <map>
#include <algorithm>
#include <cmath>

using namespace std;

#define B       (cout << "Sehen Sie mich!" << endl)
#define VB(val) (cout << val << endl)

inline int ctoi(const char c){
        if('0' <= c && c <= '9') return (c -'0');
        return -1;
}

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

        for (int i = n; i >= 0; i--) {
                for (int j = 1; j * j <= n; j++) {
                        if (j * j == i) {
                                VB(i);
                                return 0;
                        }
                }
        }

}

Measured memory_bytes: 256
def main2():
    A, B, C = map(int, input().split())

    ans = 0
    if A % 2 == 1 or B % 2 == 1 or C % 2 == 1:
        print(ans)
        exit()

    elif (2 * A - B - C) == 0 and (2 * B - A - C) == 0 and (2 * C - A - B) == 0:
        print(-1)
        exit()

    else:
        while True:
            if A % 2 == 1 or B % 2 == 1 or C % 2 == 1:
                print(ans)
                exit()

            A, B, C = (B + C)//2, (A + C)//2, (A + B)//2
            ans += 1


if __name__ == "__main__":
    main2()

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

using namespace std;

#define INF 1000007
#define MOD 1000000007
#define int long long int
#define maxn 100
#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define rep(i, n) FOR(i, 0, n)

int gcd(int a, int b)
{
    return b ? gcd(b, a % b) : a;
}

int lcm(int a, int b) { return a / gcd(a, b) * b; }

int mpow(int N, int P, int M) //繰り返し自乗法
{
    if (P == 0)
        return 1;
    if (P % 2 == 0)
    {
        int t = mpow(N, P / 2, M);
        return t * t % M;
    }
    return N * mpow(N, P - 1, M) % M;
}

int counter(int x)
{ //bit計算
    if (x == 0)
        return 0;
    return counter(x >> 1) + (x & 1);
}

vector<bool> prime(maxn + 1, true); //素数テーブル
void prime_table(void)
{
    prime[0] = false;
    prime[1] = false;
    for (int i = 2; i * i <= maxn; i++)
    {
        if (!prime[i])
        {
            continue;
        }
        for (int j = i + i; j <= maxn; j += j + i)
        {
            prime[j] = false;
        }
    }
}

bool IsPrime(int num)
{ //素数判定
    if (num < 2)
        return false;
    else if (num == 2)
        return true;
    else if (num % 2 == 0)
        return false;

    double sqrtNum = sqrt(num);
    for (int i = 3; i <= sqrtNum; i += 2)
    {
        if (num % i == 0)
        {
            return false;
        }
    }

    return true;
}
vector<int> divisor(int n) //約数列挙
{
    vector<int> ret;
    for (int i = 1; i * i <= n; i++)
    {
        if (n % i == 0)
        {
            ret.push_back(i - 1);
            if (i * i != n)
            {
                ret.push_back((n / i) - 1);
            }
        }
    }
    sort(ret.begin(), ret.end());
    return (ret);
}
signed main()
{
    int N;
    cin >> N;
    vector<int> ans;
    ans = divisor(N);
    int ANS = 0;
    rep(i, ans.size())
    {
        if (ans[i] == 0)
            continue;
        if (N / ans[i] == N % ans[i])
        {
            ANS += ans[i];
        }
    }
    cout << ANS << endl;
}


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

typedef long long int ll;

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

    for(ll i=a; i<=b; i++)
    {
        if(i%k==0)
        {
            cout<<"OK"<<endl;
            return 0;
        }

    }

    cout<<"NG"<<endl;

    return 0;
}


Measured memory_bytes: 3604
#include <iostream>
#include <iomanip>
#include <vector>
#include <set>
#include <string>
#include <queue>
#include <algorithm>
#include <map>
#include <cmath>
#include <numeric>
#include <list>
#include <stack>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <tuple>

#define rep(i, n) for (int i = 0; i < (n); i++)
#define rep1(i, n) for (int i = 1; i <= (n); i++)
#define show(a, n) rep(i,n) {cout<<a[i]<<' ';} cout<<endl
#define show2(a, n, m) rep(i, n) { rep(j, m) {cout << a[i][j] << ' ';} cout << endl;} 
#define chmin(a, b) a = min(a, b)
#define chmax(a, b) a = max(a, b)

using namespace std;
typedef vector<int> vi;
typedef pair<int, int> pii;
typedef long long ll;
typedef vector<ll> vll;
typedef pair<long long, long long> pll;
typedef long double ld;

const int INF = 1 << 30;
const long long INFL = 1LL << 60;
const int MOD = 1000000007;
const int MAX = 100000;
const int N = 100010;

struct mint {
    ll x;
    mint(ll x=0):x((x%MOD+MOD)%MOD){}
    mint operator-() const { return mint(-x);}
    mint& operator+=(const mint a) {if ((x+=a.x)>=MOD) x-=MOD; return *this;}
    mint& operator-=(const mint a) {if ((x+=MOD-a.x)>=MOD) x-=MOD; return *this;}
    mint& operator*=(const mint a) {(x*=a.x)%=MOD; return *this;}
    mint operator+(const mint a) const {mint res(*this); return res+=a;}
    mint operator-(const mint a) const {mint res(*this); return res-=a;}
    mint operator*(const mint a) const {mint res(*this); return res*=a;}
    mint pow(ll t) const {
        if (!t) return 1;
        mint a = pow(t>>1);
        a *= a;
        if (t&1) a *= *this;
        return a;
    }

    // for prime mod
    mint inv() const { return pow(MOD-2);}
    mint& operator/=(const mint a) { return (*this) *= a.inv();}
    mint operator/(const mint a) const {mint res(*this); return res/=a;}
};

const int cmax = 700000;
mint fac[cmax],finv[cmax],inv[cmax];

void com_init() {
    fac[0]=fac[1]=1;
    finv[0]=finv[1]=1;
    inv[1]=1;
    for (int i=2; i<cmax; i++) {
        fac[i]=fac[i-1]*i;
        inv[i]=-inv[MOD%i]*(MOD/i);
        finv[i]=finv[i-1]*inv[i];
    }
}

ll com(int n, int k) {
    if (n<k) return 0;
    if (n<0||k<0) return 0;
	mint ret=fac[n]*finv[k]*finv[n-k];
    return ret.x;
}

int main() {
//	cout << fixed << setprecision(15);
	int x, y;
	cin >> x >> y;
	if((x + y) % 3 != 0 || 2 * x < y || 2 * y < x) {
		cout << 0 << endl;
		return 0;
	}
	int a = (x + y) / 3;
	int b = (2 * x - y) / 3;
	com_init();
	cout << com(a, b) << endl;
}


Measured memory_bytes: 16640
#include <iostream>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <cmath>
#include <iomanip>
#include <algorithm>
using namespace std;
using ll = long long;

void print_ans(bool flag){
    if(flag){
        cout << "Yes" << endl;
    } else {
        cout << "No" << endl;
    }   
}

int main(){
    int a, b, c;
    cin >> a >> b >> c;
    bool ans = ((a+b) == c) || ((a+c) == b) || ((b+c) == a);
    print_ans(ans);
    return 0;
}


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

int main(){
  int n; cin >> n;
  vector<int> a(n);
  
  for(int i = 0; i < n; i++) cin >> a[i];
  
  sort(a.begin(), a.end());
  
  for(int i = 0; i < n-1; i++){
  	if(a[i]==a[i+1]){
    	cout << "NO" << endl;
    	return 0;
    }
  }
  cout << "YES" << endl;
}

Measured memory_bytes: 1024
N,M = list(map(int,input().split()))
City = [[i]+list(map(int,input().split())) +[""] for i in range(M)]

City2 = sorted(City,key = lambda x:(x[1],x[2]))
x = 1
cur_P = 0
for i,row in enumerate(City2):
    if cur_P != row[1]:
        x = 1
        cur_P = row[1]
    else:
        x += 1
    City2[i][3] = ("000000"+str(cur_P))[-6:] + ("000000"+str(x))[-6:]
for row in City:
    print(row[3])

Measured memory_bytes: 39452
#include <bits/stdc++.h>
#define fi first
#define se second
#define pb push_back
using namespace std;
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef long long ll;

const int N = 1e5+5,M = 1e9+7;;
ll f[N];
int p[N];
int loc[N];

int x,y;

ll pw(ll a, ll b) {
	if(!b) return 1;
	if(b&1) return a*pw(a,b-1)%M;
	ll t = pw(a,b/2);
	return t*t%M;
}

inline ll inv(ll a) {
	return pw(a,M-2);
}

ll ch(int a, int b) {
	if(a < b || a < 0 || b < 0) return 0;
	return f[a]*inv(f[a-b]*f[b]%M)%M;
}

int main() {
	ios::sync_with_stdio(0); cin.tie(0);
	f[0] = 1;
	for(int i = 1; i < N; ++i) {
		f[i] = f[i-1]*i%M;
	}
	int n;
	cin >> n;
	fill(loc,loc+N,-1);
	for(int i = 0; i <= n; ++i) {
		cin >> p[i];
		if(loc[p[i]] != -1) {
			x = loc[p[i]];
			y = i;
		}
		loc[p[i]] = i;
	}
	for(int k = 1; k <= n+1; ++k) {
		cout << ((ch(n-1,k) + 2*ch(n-1,k-1) - ch(x+(n-y),k-1) + ch(n-1,k-2))%M+M)%M<< "\n";
	}
	cout << "\n";
}

Measured memory_bytes: 2816
#include <iostream>
#include <set>
#include <map>
#include <cmath>
#include <vector>
#include <string>
#include <algorithm>
#include <iomanip>
#include <queue>
#include <deque>
#include <stack>
#include <climits>
#include <math.h>
#include <cassert>
#include <unordered_map>
using namespace std;
#pragma warning(disable : 4996)
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;




int main() {
#ifdef _DEBUG
	freopen("input1.txt", "r", stdin);
	freopen("output2.txt", "w", stdout);
#endif
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	int k, a, b;
	cin >> k >> a >> b;
	for (int i = a; i <= b; i++) {
		if (i % k == 0) {
			cout << "OK";
			return 0;
		}
	}
	cout << "NG";
}

Measured memory_bytes: 3584
#include <iostream>
using namespace std;
int main()
{
	int A,B,C,kys;
	cin>>A>>B>>C;
	for(int i=1;i<100;i++){
		if(A%i==0&&B%i==0) kys=i;
	}
	if(C%kys==0) cout<<"YES"<<endl;
	else cout<<"NO"<<endl;
	return 0;
}


Measured memory_bytes: 256
n = gets.chomp.to_i
a = gets.split.map(&:to_i)
b = gets.split.map(&:to_i)

cnt = 0
n.times do |i|
  if a[i] >= b[i]
    cnt += b[i]
  else
    cnt += a[i]
    e = b[i] - a[i]
    if e >= a[i+1]
      cnt += a[i+1]
      a[i+1] = 0
    else
      cnt += e
      a[i+1] -= e
    end
  end
end
p cnt

Measured memory_bytes: 15396
#include <algorithm>
#include <iostream>
#include <string.h>
#include <stdio.h>
#include <vector>
#include <queue>
#include <cmath>
#include <map>
#include <set>

#define pii pair <int, int>
#define pb push_back
#define ll long long
#define ss second
#define ff first
#define N 500010

using namespace std;

int n;
string s;
vector <char> V;

int main()
{
	cin >> n >> s;
	
	int a = 0;
	
	for(int i=0; i < n; i++) {
		if(s[i] == '(')
			V.pb(s[i]);
		if(s[i] == ')' && !V.empty() && V.back() == '(')
			V.pop_back();
		else if(s[i] == ')' && (V.empty() || V.back() == ')'))
			a++;
	}
	
	for(int i=1; i <= a; i++)
		cout << "(";
	
	cout << s;
	
	for(int i=0; i < V.size(); i++)
		cout << ")";
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int inf = 0x3f3f3f3f;
const ll mod = 1e9 + 7;
const int maxn = 200005;
vector<int> a;
bool cmp(const int &a, const int &b) {
	return abs(a) > abs(b);
}
ll qpow(ll a, ll b) { //快速幂
	ll res = 1;
	while (b)
	{
		if (b & 1) res = res * a % mod; //可以换为快乘
		b >>= 1;
		a = a * a % mod;
	}
	return res;
}
ll exgcd(ll a,ll b,ll &x,ll &y)//扩展欧几里得算法 
{
    if(b==0)
    {
        x=1,y=0;
        return a;
    }
    ll ret=exgcd(b,a%b,y,x);
    y-=a/b*x;
    return ret;
}
ll getInv(int a,int mod)//求a在mod下的逆元，不存在逆元返回-1 
{
    ll x,y;
    ll d=exgcd(a,mod,x,y);
    return d==1?(x%mod+mod)%mod:-1;
}
int main()
{
	// int test=100;
	// cout<<getInv(5, mod)<<endl;
	// test *= getInv(5, mod);
	// test %= mod;
	// cout<<(test%mod+mod)%mod<<endl;
	// test=100;
	// test *= qpow(5, mod - 2);
	// test %= mod;
	// test *= 4;
	// test %= mod;
	// cout<<(test%mod+mod)%mod<<endl;
	int n, k, z = 0;
	cin >> n >> k;
	for (int i = 0, b; i < n; i++) {
		cin >> b;
		if (b == 0)z++;
		else a.push_back(b);
	}
	if (k > (int)a.size()) {
		cout << 0 << endl;
		return 0;
	}
	sort(a.begin(), a.end(), cmp);
	ll ans = 1;
	int zheng = inf, fu = inf;//最后一个正数/负数
	for (int i = 0; i < k; i++) {//前k个乘起来，存最后的正数和负数
		ans *= a[i];
		ans %= mod;
		if (a[i] > 0)zheng = a[i];
		else fu = a[i];
	}
	if (ans < 0) {
		int nzheng = inf, nfu = inf;//下一个正数和负数
		for (int i = k; i < (int)a.size(); i++)//k-后面里面找
			if (a[i] > 0 && nzheng == inf) nzheng = a[i];//只取最大的
			else if (a[i] < 0 && nfu == inf) nfu = a[i];
		if (nzheng == inf && nfu == inf) {//没有别的数
			if (z > 0)//出现0，答案变为0
				ans = 0;
		}
		else if (nzheng != inf && nfu == inf) {//后面只有正
			ans *= qpow(fu, mod - 2);//去掉最后一个最小的负数，乘上后面的正数
			ans %= mod;
			ans *= nzheng;
			ans %= mod;
		}
		else if (nzheng == inf && nfu != inf) {//后面只有负数
			if (zheng != inf) {//前面有正数
				ans *= qpow(zheng, mod - 2);//负数换正数
				ans %= mod;
				ans *= nfu;
				ans %= mod;
			}
			else {//前面也没有正数，全是负数
				if (z > 0) {
					ans = 0;
				}
				//全是负数，重新算答案
				else {
					ans = 1;
					for (int i = n - 1; i >= n - k; i--) {//后k个数乘起来
						ans *= a[i];
						ans %= mod;
					}
				}
			}
		}
		else {//后面有正有负
			if (zheng == inf) {//前面全是负数，正数换掉最小的负数
				ans *= qpow(fu, mod - 2);
				ans %= mod;
				ans *= nzheng;
				ans %= mod;
			}
			else if ((ll)zheng * nzheng < (ll)fu * nfu) {
				ans *= qpow(zheng, mod - 2);
				ans %= mod;
				ans *= nfu;
				ans %= mod;
			}
			else {
				ans *= qpow(fu, mod - 2);
				ans %= mod;
				ans *= nzheng;
				ans %= mod;
			}
		}
	}
	cout << (ans % mod + mod) % mod << endl;
	return 0;
}

Measured memory_bytes: 4304
def BFS(K,edges,N):
  dist=[-1]*N
  stack=[]
  stack.append(K)
  dist[K]=0
  while stack:
    label=stack.pop(-1)
    for i,c in edges[label]:
      if dist[i]==-1:
        dist[i]=dist[label]+c
        stack+=[i]
  return dist
 
N=int(input())
edges=[ [] for i in range(N)]
for i in range(N-1):
  a,b,c=map(int,input().split())
  edges[a-1]+=[(b-1,c)]
  edges[b-1]+=[(a-1,c)]
Q,K=map(int,input().split())
xy=[list(map(int,input().split())) for i in range(Q)]
distance=BFS(K-1,edges,N)
for i in range(Q):
  print(distance[xy[i][0]-1]+distance[xy[i][1]-1])

Measured memory_bytes: 67712
N = int(input())
A = [0]
A.extend(list(map(int, input().split())))
A.append(0)
B = []
sum_ = abs(A[0]) + abs(A[-2])
for a0, a1, a2 in zip(A, A[1:], A[2:]):
    sum_ += abs(a0-a1)
    if (a0-a1)*(a1-a2) >= 0:
        B.append(0)
    else:
        B.append(2*min(list(map(abs, [a0-a1, a1-a2]))))

for b in B:
    print(sum_ - b)

Measured memory_bytes: 14048
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll mod=1e9+7;
ll find(ll n,ll k){
	n%=mod,k%=mod;
	return (n-(k-2)+(k-1)*(n-(k-1)))%mod;
}
int main(){
	ll n,k;
	scanf("%lld%lld",&n,&k);
	ll ans=0;
	for(int i=k;i<=n+1;i++){
		ans=(ans+find(n,i))%mod;
	}
	printf("%lld\n",ans%mod);
}

Measured memory_bytes: 3812
/*
	Author: Luis Manuel D�az Bar�n (LUISMO)
	Problem:
	Online Judge:
	Idea:
*/
#include<bits/stdc++.h>
// Types
#define ll long long
#define ull unsigned long long
// IO
#define sf scanf
#define pf printf
#define mkp make_pair
#define fi first
#define se second
#define endl "\n"

using namespace std;

typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
const ll inf = 1e16 + 3;
const int mod = 1e9 + 7;
const int lim = 2e5 + 2;

int N, K;
ll hi[lim];

ll dp[lim];
int mark[lim];

ll DynamicProgramming(int idx)
{
    if(idx <= 0)
        return 0;

    if(mark[idx])
        return dp[idx];

    mark[idx] = true;

    DynamicProgramming(idx - 1);
    DynamicProgramming(idx - 2);


    int kidx =max(0,idx - K);
    ll aux = inf;
    for(int i = kidx; i < idx; i++)
    {
        ll curr = dp[i] + abs(hi[i] - hi[idx]);
        aux = min(aux, curr);
    }

    dp[idx] = aux;
    return dp[idx];
}


void solve()
{
    cin >> N >> K;
    for(int i = 0; i < N; i++) 
        cin >> hi[i];   

    ll answ = DynamicProgramming(N - 1);
    cout << answ;
}

void fastIO()
{
	cin.sync_with_stdio(false);
	cin.tie(0);
}

void IO()
{
	if(fopen("d:\\lmo.in","r") != NULL)
	{
		freopen("d:\\lmo.in","r",stdin);
	}
	else if(fopen("/media/Beijing/lmo.in","r") != NULL)
	{
		freopen("/media/Beijing/lmo.in", "r", stdin);
	}
}

int main()
{
	IO();

	fastIO();

	solve();
}


Measured memory_bytes: 5376
from enum import Enum
import sys
import math

BIG_NUM = 2000000000
MOD = 1000000007
EPS = 0.000000001

line = list(map(str,input().split()))
S=[]
for tmp_ch in line:
    if tmp_ch in ['+','-','*']:
        b=int(S.pop())
        a=int(S.pop())

        if tmp_ch == '+':
            S.append(a+b)
        elif tmp_ch =='-':
            S.append(a-b)
        else:
            S.append(a*b)
    else:
        S.append(tmp_ch)

print("%d"%(S[0]))



Measured memory_bytes: 6380
#include <bits/stdc++.h>
using namespace std;
#define _GLIBCXX_DEBUG
typedef long long ll;
typedef pair<int, int> P;
typedef pair<pair<int, int>, int> PP;
typedef bitset<61> Bitset;
const ll INFL = 1LL << 60;
const ll MOD = 1000000007;
const int INF = INT_MAX;
const int MAX = 300000;
ll GCD(ll a, ll b) { return b ? GCD(b, a % b) : a; }
ll LCM(ll a, ll b) { return (a * b) / GCD(a, b); }
//------------------------------------------------------------------------------------------------------------------------------

int main(void) {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int n;cin>>n;
    vector<int> V(n,0);
    for(int i = 1; i < n; i++){
        int a;cin>>a;a--;
        V[a]++;
    }
    for(int i = 0; i < n; i++) cout<<V[i]<<endl;



}


Measured memory_bytes: 3956
#include<bits/stdc++.h>
using namespace std;
int main(){
  int a;
  cin >> a;
  vector<int> A(a);
  for(int i = 0;i<a;i++)
    cin >> A.at(i);
  int count = 0;
  for(int i = 0;i<a;i++){
    for(int j = 0;j<a;j++){
      int differ = A.at(i) - A.at(j);
      count = max(count,differ);
    }
  }
  cout << count << endl;
}



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

class Myon
{
    public Myon() { }
    public static int Main()
    {
        new Myon().calc();
        return 0;
    }

    Scanner cin;
    Func cin2;
    void calc()
    {
        cin = new Scanner();
        cin2 = new Func();
        string a=cin.next();
        string b=cin.next();
        char ans='=';
        if(a[0]-b[0]<0)ans='<';
        else if(a[0]-b[0]>0)ans='>';
        Console.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[] ArrayDouble(int N, double add = 0)
    {
        double[] Array = new double[N];
        for (int i = 0; i < N; i++)
        {
            Array[i] = nextDouble() + add;
        }
        return Array;
    }
}

class Answer
{
    public void Int2DArrayAns(int[,]x,char c)
    {
        for(int i=0;i<x.GetLength(0);i++)
        {
            for(int j=0;j<x.GetLength(1)-1;j++)
            {
                Console.Write(x[i,j]);
                Console.Write(c);
            }
            Console.WriteLine(x[i,x.GetLength(1)-1]);
        }
    }
    public void Char2DArrayAns(char[,]x,char c)
    {
        for(int i=0;i<x.GetLength(0);i++)
        {
            for(int j=0;j<x.GetLength(1)-1;j++)
            {
                Console.Write(x[i,j]);
                Console.Write(c);
            }
            Console.WriteLine(x[i,x.GetLength(1)-1]);
        }
    }
}

class Func
{
    public long GCDLong(long a, long b)
    {
        while(a!=0)
        {
          long t=a;
          a=b%a;
          b= t;
        }
      
        return b;        
    }
}


Measured memory_bytes: 11092
#include <stdio.h>
int main(void)
{
	int n,a[101],i,b[10]={0,0,0,0,0,0,0,0,0},c=0;
	scanf("%d",&n);
	for(i=0; i<n; i++){
		scanf("%d",&a[i]);
		if(a[i]<=399)					b[0]=b[0]+1;
		if(a[i]>=400 && a[i]<=799)		b[1]=b[1]+1;
		if(a[i]>=800 && a[i]<=1199)		b[2]=b[2]+1;
		if(a[i]>=1200 && a[i]<=1599)	b[3]=b[3]+1;
		if(a[i]>=1600 && a[i]<=1999)	b[4]=b[4]+1;
		if(a[i]>=2000 && a[i]<=2399)	b[5]=b[5]+1;
		if(a[i]>=2400 && a[i]<=2799)	b[6]=b[6]+1;
		if(a[i]>=2800 && a[i]<=3199)	b[7]=b[7]+1;
		if(a[i]>=3200)					b[8]=b[8]+1;
	}
	if(b[0]!=0)	c=c+1;
	if(b[1]!=0)	c=c+1;
	if(b[2]!=0)	c=c+1;
	if(b[3]!=0)	c=c+1;
	if(b[4]!=0)	c=c+1;
	if(b[5]!=0)	c=c+1;
	if(b[6]!=0)	c=c+1;
	if(b[7]!=0)	c=c+1;
	if(c==0){
		printf("%d %d\n",1,b[8]);
	}else{
		printf("%d %d\n",c,c+b[8]);
	}
	return 0;
}

Measured memory_bytes: 128
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <math.h>
#define MOD 1000000007
typedef long long ll;
using namespace std;

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

  if(a%2||b%2||c%2){
    cout<<0<<endl;
    return 0;
  }

  ll m1=abs(a-b);
  ll m2=abs(a-c);
  ll m3=abs(b-c);
  ll ans=0;
  if(m1==0&&m2==0&&m3==0) cout<<-1<<endl;
  else{
    for(int i=0;;i++){
      if(m1%2||m2%2||m3%2){
        ans=i;
        break;
      }
      m1/=2;
      m2/=2;
      m3/=2;
    }
    cout<<ans<<endl;
  }

  return 0;
}


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

typedef long long ll;

int main() {
	int k; cin >> k;
	vector<ll> a(k);
	for (auto&& x : a)cin >> x;
	reverse(a.begin(), a.end());

	ll l = 2, r = 2;
	for (int i = 0; i < k; i++) {
		l = (l + a[i] - 1) / a[i] * a[i];
		r = ((r / a[i]) + 1) * a[i] - 1;
		if (l > r) {
			cout << -1 << endl;
			return 0;
		}
	}
	cout << l << ' ' << r << endl;
}

Measured memory_bytes: 1024
(N, K), As = readlines.map{_1.split.map(&:to_i)}
M = 10**9 + 7

as = As.sort
if as.last < 0 && K.odd?
  puts as.last(K).inject(1){|r, a| r*a % M}
else
  ans, c, l, r = 1, 0, 0, -1
  while c < K - 1
    ls, rs = as[l]*as[l + 1], as[r]*as[r - 1]
    if ls > rs
      ans = ans*ls % M
      l += 2
      c += 2
    else
      ans = ans*as[r] % M
      r -= 1
      c += 1
    end
  end
  ans = ans*as[r] % M if c == K - 1
  puts ans
end

Measured memory_bytes: 35516
#include<cstdio>
#include<algorithm>
#include<cmath>
#include<cstring>
using namespace std;
#define MAXN 200005
#define INF 0x3f3f3f3f
#define LL long long
int n,m=INF;
LL ans;
int a[MAXN],b[MAXN];
int main()
{
	scanf("%lld",&n);
	bool f=0;
	for(int i=1;i<=n;i++)
	{
		scanf("%d %d",&a[i],&b[i]);
		if(a[i]!=b[i]) f=1;
		ans+=a[i];
		if(a[i]>b[i]) m=min(m,b[i]);
	}
	if(f==0) 
	{
		printf("0\n");
		return 0;
	}
	printf("%lld\n",ans-m);
    return 0;
}


Measured memory_bytes: 384