akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<iomanip>
#include<math.h>
#include<complex>
#include<queue>
#include<deque>
#include<stack>
#include<map>
#include<set>
#include<bitset>
#include<functional>
#include<assert.h>
#include<numeric>
using namespace std;
#define REP(i,m,n) for(int i=(int)(m) ; i < (int) (n) ; ++i )
#define rep(i,n) REP(i,0,n)
#define stop char nyaa;cin>>nyaa;
using ll = long long;
const int inf = 1e9 + 7;
const ll longinf = 1LL << 60;
const ll mod = 1e9 + 7;

using P = pair<int, int>;

void solve() {
	int n; cin >> n;
	vector<int> a(n);
	rep(i, n) {
		cin >> a[i];
	}
	sort(a.begin(), a.end());
	ll ans = 0;
	rep(i, n) {
		int le = i;
		while (i + 1 < n&&a[i] == a[i + 1])i++;
		int cnt = i - le + 1;
		if (cnt >= a[i])ans += cnt - a[i];
		else ans += cnt;
	}
	cout << ans << endl;
}


int main() {
	solve();
	//stop
	return 0;
}


Measured memory_bytes: 640
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ

		Scanner sc = new Scanner(System.in);;

		int N=sc.nextInt();
		int i=sc.nextInt();
		int A;

		A=N-i+1;

		System.out.println(A);
		sc.close();

	}

}


Measured memory_bytes: 23124
import java.io.BufferedReader;
import java.io.InputStreamReader;
public class Main{
	public static void main(String[] args) throws Exception {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		int N = Integer.parseInt(br.readLine());
		if(N <1000) {
			System.out.println("ABC");
		} else if(N > 999) {
			System.out.println("ABD");
		}
	}
}


Measured memory_bytes: 21204
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;

template<long long mod>
struct mint {
private:
    long long x;
public:
    mint(long long x = 0) :x((mod + x) % mod) {}
    mint(std::string &s) {
        long long z = 0;
        for (int i = 0; i < s.size(); i++) {
            z *= 10;
            z += s[i] - '0';
            z %= mod;
        }
        this->x = z;
    }
    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) {
        long long n = mod - 2;
        mint<mod> u = 1, b = a;
        while (n > 0) {
            if (n & 1) {
                u *= b;
            }
            b *= b;
            n >>= 1;
        }
        return *this *= u;
    }
    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 operator/(const mint &a) const {
        mint res(*this);
        return res /= a;
    }
    friend std::ostream& operator<<(std::ostream &os, const mint &n) {
        return os << n.x;
    }
    bool operator==(const mint &a) const {
        return this->x == a.x;
    }
};

int main() {
    int n; cin >> n;
    string s; cin >> s;
    vector<int> a(2 * n);
    if (s[0] == 'W') {
        puts("0");
        return 0;
    }
    a[0] = 0;
    for (int i = 1; i < 2 * n; i++) {
        if (s[i] == s[i - 1]) {
            a[i] = 1 - a[i - 1];
        }
        else {
            a[i] = a[i - 1];
        }
    }
    int cnt = 0;
    constexpr int MOD = 1e9 + 7;
    mint<MOD> ans = 1;
    for (int i = 2 * n - 1; i >= 0; i--) {
        if (a[i] == 0) {
            if (cnt == 0) {
                puts("0");
                return 0;
            }
            ans *= cnt;
            cnt--;
        }
        else {
            cnt++;
        }
    }
    if (cnt > 0) {
        puts("0");
        return 0;
    }
    for (int i = 2; i <= n; i++) {
        ans *= i;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 1412
package main

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

var rdr = bufio.NewReaderSize(os.Stdin, 1024)

func readLine() string {
	buf := make([]byte, 0, 1024)
	for {
		l, p, e := rdr.ReadLine()
		if e != nil {
			panic(e)
		}
		buf = append(buf, l...)
		if !p {
			break
		}
	}
	return string(buf)
}

func atoi(s string) int {
	i, e := strconv.Atoi(s)
	if e != nil {
		panic(e)
	}
	return i
}

func readStringArray() []string {
	return strings.Split(strings.TrimSpace(readLine()), " ")
}

func readInt() int {
	return atoi(readLine())
}

func readIntArray() []int {
	var a []int
	sa := readStringArray()
	for _, s := range sa {
		a = append(a, atoi(s))
	}
	return a
}

func main() {
	n := 5
	var pos []int
	for i := 0; i < n; i++ {
		pos = append(pos, readInt())
	}
	k := readInt()

	for i := 0; i < n-1; i++ {
		for j := i + 1; j < n; j++ {
			if pos[j]-pos[i] > k {
				fmt.Println(":(")
				os.Exit(0)
			}
		}
	}
	fmt.Println("Yay!")
}


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

#define ll long long
#define Fi first
#define Se second
#define Pb push_back
#define vi vector<int>
#define vp vector<pair<int,int>>
#define vvi vector<vector<int>>
#define vvp vector<vector<pair<int,int>>>

const int INF = 1e9;
const int MOD = 1e9+7;
using Graph = vector<vector<int>>; //Caution!! Segmentation Fault!! Don't forget to add +1!

#define all(v) v.begin(),v.end()
#define output_s(a) printf("%s\n",(a).c_str())

#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define Rep(i,n,m) for(int i=(int)(n);i<(int)(m);i++)
#define RepS(i,n,m) for(int i=(int)(n);i<=(int)(m);i++)
#define RRepS(i,n,m) for(int i=(int)(n);i>=(int)(m);i--)
#define RepA(x) for(auto &item:(x))

void CINT(){}
template <class Head,class... Tail>
void CINT(Head&& head,Tail&&... tail){
    cin>>head;
    CINT(move(tail)...);
}    
#define CIN(...) int __VA_ARGS__;CINT(__VA_ARGS__)
#define LCIN(...) ll __VA_ARGS__;CINT(__VA_ARGS__)
#define SCIN(...) string __VA_ARGS__;CINT(__VA_ARGS__)

template<typename TypeInt> //最大公約数
TypeInt GCD(TypeInt a,TypeInt b){
    if(a%b==0) return b;
    else return GCD(b,a%b);
}
template<typename TypeInt> //最小公倍数
TypeInt LCM(TypeInt a,TypeInt b){
    return a*b/GCD(a,b);
}

int IN_int(){
    int x;
    scanf("%d",&x);
    return x;
}

//library----------------------------------------------

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

const int NMAX = 100;
bool flag;

bool comp(int x,int y){
    return abs(0-x)<abs(0-y);
}

signed main(){
    int a=IN_int();
    int b=IN_int();
    int ans=0;
    RepS(i,a,b){
        string s=to_string(i);
        if(s[0]==s[4]&&s[1]==s[3]) ans++;
    }
    printf("%d\n",ans);

    return 0;
}

Measured memory_bytes: 256
N,M,X,Y = list(map(int, input().split()))
x = sorted(list(map(int, input().split())))
y = sorted(list(map(int, input().split())))

for Z in range(x[-1], y[0] + 1):
  if x[-1] < Z and y[0] <= Z and X < Z and Z <= Y:
    print("No War")
    exit()
print("War")

Measured memory_bytes: 3060
N, M = map(int,input().split())
ans = []

if N %2 == 0:
    L1 = list(range(1,N//2+1))
    L2 = list(range(N//2+1,N+1))
    L = len(L1)
    i = 0
    j = 0
    # print(L)
    for m in range(M):
        if m %2 == 0:
            ans.append([L1[L//2-1-i],L1[L//2+i]])
            i += 1
        else:
            ans.append([L2[L//2-1-j], L2[L//2+1+j]])
            j += 1

else:
    for i in range(1,M+1):
        ans.append([i,N+1-i])

for a in ans:
    print(*a)

Measured memory_bytes: 22552
//--------------------------------------------------template----------------------------------------//
//c
#include <stdio.h>
#include <time.h>
#include <math.h>
//c++
#include <cstdio>
#include <iostream>
#include <algorithm>
#include <functional>
#include <cstdlib>
#include <sstream>
#include <string>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <deque>
#include <vector>
#include <complex>
#include <cmath>
//c++11
#include <tuple>
#define all(c) ((c).begin(),(c).end())
#define rall(c) (c).rbegin(),(c).rend()
//#define sort(v,n) sort(v,v+n)
//#define vsort(v) sort(v.begin(),v.end())
#define vvsort(v) sort(v.rbegin(),v.rend())
#define ll long long
#define pb(a) push_back(a)
#define fi first
#define se second
#define inf 999999999
using namespace std;
const ll MOD = 1e9 + 7;
const double PI = acos(-1.0);
//---------------------------------------------------------------------------------------------//
int n;
int a[11];
int maxa=-1;
int main() {
	cin >> n;
	for (int i = 0; i < n; i++) {
		cin >> a[i];
		maxa = max(maxa, a[i]);
	}
	ll temp = maxa;
	for (ll i = maxa;; i += temp) {
		for (int j = 0; j < n; j++) {
			if (i % a[j] != 0)break;
			if (j == n - 1) {
				cout << i << endl;
				return 0;
			}
		}
	}
}

Measured memory_bytes: 3092
#include <cmath>
#include<iostream>
#include<vector>
#include<algorithm>
#include<functional>
#include<queue>
#include<set>
#include<tuple>
#include<bitset>
#include<iomanip>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
ll inf = 1000000007;
int main() {
	int x;
	cin >> x;
	if (x >= 30) {
		cout << "Yes" << endl;
	}
	else {
		cout << "No" << endl;
	}
	return 0;
}

Measured memory_bytes: 3632
N = int(input())
A = list(map(int,input().split()))
d = {}
for a in A:
  if(a in d):
    d[a] += 1
  else:
    d[a] = 1
x, y = 0, 0
for k, v in d.items():
  if(v >= 2 and k > y):
    if(k >= x):
      if(v >= 4):
        y = k
      else:
        y = x
      x = k
    else:
      y = k
print(x * y)

Measured memory_bytes: 18060
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define repr(i, n) for (int i = (n); i >= 0; --i)
#define FOR(i, m, n) for (int i = (m); i < (n); ++i)
#define FORR(i, m, n) for (int i = (m); i >= (n); --i)
using namespace std;
typedef long long ll;
const ll mod = 1000000007;
const ll mod2 = 998244353;
const int INF = 1000000005;

int n, pos = 0;
vector<int> pre, in, post;

void rec(int l, int r) {
  if (l >= r) return;
  int root = pre[pos++];
  int m = distance(in.begin(), find(in.begin(), in.end(), root));
  rec(l, m);
  rec(m+1, r);
  post.push_back(root);
}

int main() {
  cin >> n;
  int k;
  rep(i, n) {
    cin >> k;
    pre.push_back(k);
  }
  rep(i, n) {
    cin >> k;
    in.push_back(k);
  }

  rec(0, n);

  rep(i, n) {
    if (i) cout << " ";
    cout << post[i];
  }
  cout << endl;

  
  return 0;
}


Measured memory_bytes: 3164
// Undone
#include <bits/stdc++.h>
#define int long long
#define double long double
#define INF 1e18
#define MOD 1000000007
using namespace std;
signed main() {
  double N, A, B, C, D;
  cin >> N >> A >> B >> C >> D;
  cout << (int)min(ceil(N/A)*B, ceil(N/C)*D) << endl;
}




Measured memory_bytes: 3288
D=int(input())
c=list(map(int,input().split()))
s=[list(map(int,input().split())) for _ in range(D)]

last=[0]*26


for d in range(1,D+1):
    ans=[]
    for choice in range(1,27):
        ans_tmp=0
        ans_tmp+=s[d-1][choice-1]
        for i in range(26):
            if i+1==choice:
                continue
            ans_tmp-=c[i]*(d-last[i])*(D-d)//72
        ans.append((ans_tmp,choice))
    _,case=max(ans)
    last[case-1]=d
    print(case)



Measured memory_bytes: 9400
#include <bits/stdc++.h>
const int maxN = 1e5 + 10;
using namespace std;

map<string, int> mp;

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

    int n;
    cin >> n;

    for(int i = 1; i <= n; ++i)
    {
        string s;
        cin >> s;
        ++mp[s];
    }

    cout << "AC x " << mp["AC"] << endl;
    cout << "WA x " << mp["WA"] << endl;
    cout << "TLE x " << mp["TLE"] << endl;
    cout << "RE x " << mp["RE"] << endl;

}


Measured memory_bytes: 3660
use proconio::{
    fastout, input,
    marker::{Bytes, Chars, Isize1, Usize1},
};

use rand::{thread_rng, Rng};

fn calc(v: &Vec<Vec<isize>>, plan: &Vec<usize>, c: &Vec<isize>) -> isize {
    let mut last = vec![0; 26];
    let mut res = 0_isize;
    for (i, &x) in plan.iter().enumerate() {
        res += v[i][x];
        last[x] = i as isize + 1;
        for (j, &y) in last.iter().enumerate() {
            res -= c[j] * (i as isize + 1 - y);
        }
    }

    res
}

fn main() {
    input! {
        d:usize,
        c:[isize;26]
    }
    let mut v = vec![];
    for _ in 0..d {
        input! {
            buf:[isize;26]
        }
        v.push(buf);
    }
    let mut rng = rand::thread_rng();
    let mut plan = vec![0; d];
    let mut prev_score = calc(&v, &plan, &c);

    let mut k = std::cmp::min(30, d);

    for q in 0..50000 {
        let idx = vec![rng.gen_range(0, d); k];
        let to = vec![rng.gen_range(0, 26); k];
        let mut from = vec![];
        for &i in &idx {
            from.push(plan[i]);
        }
        for i in 0..idx.len() {
            plan[idx[i]] = to[i];
        }
        let next_score = calc(&v, &plan, &c);
        if next_score > prev_score {
            prev_score = next_score;
        } else {
            for i in 0..idx.len() {
                plan[idx[i]] = from[i];
            }
        }
        if k > 1 && q % 1000 == 0 {
            k -= 1;
        }
    }
    for i in plan {
        println!("{}", i + 1);
    }
}


Measured memory_bytes: 2784
import java.util.*;
public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int num1 = sc.nextInt();
        int num2 = sc.nextInt();
        int num3 = sc.nextInt();
        
        if(num1+num2+num3<=21){
            System.out.println("win");
        }else{
            System.out.println("bust");
        }
    }
}


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

#define INIT std::cin.tie(0);std::ios::sync_with_stdio(false);
#define ALL(c) (c).begin(), (c).end()
#define CALL(c) (c).cbegin(), (c).cend()
#define RALL(c) (c).rbegin(), (c).rend()
#define CRALL(c) (c).crbegin(), (c).crend()
#define REP(i, n) for (int i = 0; i < static_cast<int>(n); i++)
#define FOR(i, s, n) for (int i = s; i < static_cast<int>(n); i++)
#define ASC(t) [](t& x, t& y){ return x < y; }
#define DESC(t) [](t& x, t& y){ return x > y; }
#define PSORT(s,p,e) partial_sort((s), next((s), (p)), (e))
#define VIEW(v,t) for_each((v).begin(), (v).end(), [](t& a) { cout << a << " "; }); cout << endl;

#define IN(a, x, b) (a<=x && x<b)
template<class T> inline T CHMAX(T& x, const T y){return x=(x<y)?y:x;}
template<class T> inline T CHMIN(T& x, const T y){return x=(x>y)?y:x;}
#define OUT(dist) std::cout<<(dist);
#define WS std::cout<<" ";
#define NL std::cout<<"\n"

using PII = pair<int, int>;
using PLL = pair<long long, long long>;
using LL = long long;
using ULL = unsigned long long;
template<class T> using V = vector<T>;
template<class T> using V2 = vector<vector<T>>;
template<class T, int W=255> using A = array<T, W>;
template<class T, int W=255, int H=255> using A2 = array<array<T, W>, W>;

int n,a;

int main(){
    INIT;
    cin >> n; cin >> a;
    if(n%500 <= a) cout << "Yes" << "\n";
    else cout << "No" << "\n";
}

Measured memory_bytes: 256
#include <stdio.h>
#include <ctype.h>
int main(void) {
	char s[100];
	int i, n, sum = 0;

	while (fgets(s, 100, stdin) != NULL) {
		n = 0;
		for (i = 0; s[i] != '\0'; i++) {
			if (isdigit(s[i])) {
				n = n * 10 + (s[i] - '0');
			}
			else if (n) {
				sum += n;
				n = 0;
			}
		}
	}
	printf("%d\n", sum);
	return 0;
}

Measured memory_bytes: 524
#include<cstdio>
#include<cmath>
#include<cstring>
#include<algorithm>
#include<queue>
#include<map>
#include<vector>
#include<functional>
#include <random>
#include<iostream>
#include<iomanip>
using namespace std;

int H, N;
int A[1000], B[1000];

int min_mp[10001][1001];

int dp(int HP, int MAGIC) {
	if (min_mp[HP][MAGIC] >= 0) {
		return min_mp[HP][MAGIC];
	}

	if (MAGIC == N && HP > 0) {
		min_mp[HP][MAGIC] = 1000000000;
		return min_mp[HP][MAGIC];
	}
	if (MAGIC == N && HP == 0) {
		min_mp[HP][MAGIC] = 0;
		return min_mp[HP][MAGIC];
	}

	int ret = 0;
	/*いまいる魔法を使うことにした*/
	if (HP <= A[MAGIC]) {
		ret = B[MAGIC];
	}
	else {
		ret = B[MAGIC] + dp(HP - A[MAGIC], MAGIC);
	}

	/*使わないで次に進むことにした*/
	int ret2 = 0;
	ret2 = dp(HP, MAGIC + 1);

	if (ret > ret2) { min_mp[HP][MAGIC] = ret2; }
	else { min_mp[HP][MAGIC] = ret; }

	return min_mp[HP][MAGIC];
}

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

	for (int i = 0; i < H+1; i++) {
		for (int j = 0; j < N + 1; j++) {
			min_mp[i][j] = -1;
		}
	}
	

	cout << dp(H, 0);

}

Measured memory_bytes: 39808
#include <iostream>
#include <vector>
#include <cmath>
#include <algorithm>
#include <utility>

using namespace std;

constexpr long MOD = 1000000007;

int main() {
    int N;
    string upper;
    string lower;

    cin >> N;
    cin >> upper >> lower;

    vector<int> plm;
    plm.reserve(N);
    for (int i = 0; i < N; i++) {
        if (upper[i] == lower[i]) {
            plm.push_back(1);
        } else {
            plm.push_back(2);
            i++;
        }
    }

    long ans = plm[0] == 1 ? 3 : 6;
    int plmsize = plm.size();
    for (int i = 1; i < plmsize; i++) {
        if (plm[i - 1] == 1) {
            ans *= 2;
        } else if (plm[i] == 2) {
            ans *= 3;
        }
    }

    cout << ans % MOD << endl;
}


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

int main(void)
{
    int n, x;
    cin >> n >> x;

    vector<int> a(n);
    for (int i = 0;i < n;i++)
    {
        cin >> a[i];
    }

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

    int ans = 0;

    int idx = 0;
    while(x > 0 && idx < n)
    {
        if (x >= a[idx])
        {
            ans++;
            x -= a[idx];
        }
        else
        {
            break;
        }
        idx++;
    }
    if (x != 0 && idx == n && ans != 0) ans--;
    cout << ans << endl;
    
    return 0;
}


Measured memory_bytes: 3564
#pragma GCC optimize("O3")
#include <bits/stdc++.h>
#define ll long long
#define rep2(i,a,b) for(ll i=a;i<=b;++i)
#define rep(i,n) for(ll i=0;i<n;i++)
#define rep3(i,a,b) for(ll i=a;i>=b;i--)
#define pii pair<int,int>
#define pll pair<ll,ll>
#define pq priority_queue
#define pb push_back
#define eb emplace_back
#define veci vector<int>
#define vecll vector<ll>
#define vecpii vector<pii>
#define vec2(a,b) vector<vec>(a,vec(b))
#define vec2ll(a,b) vector<vec>(a,vecll(b))
#define vec3(a,b,c) vector<vector<vec>>(a,vec2(b,c))
#define vec3ll(a,b,c) vector<vector<vecll>>(a,vec2ll(b,c))
#define fi first
#define se second
#define all(c) begin(c),end(c)
#define ios ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0);
#define lb(c,x) distance(c.begin(),lower_bound(all(c),x))
#define ub(c,x) distance(c.begin(),upper_bound(all(c),x))


using namespace std;
int in() {int x;cin>>x;return x;}
ll lin() {ll x;cin>>x;return x;}
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<class T> inline void print(pair<T,T> p){cout<<"("<<p.first<<","<<p.second<<") ";}
//template<class T> inline void print(vector<pair<T,T>> v){for(auto e:v)print(e); cout<<endl;}
//template<class T> inline void print(T v){for(auto e:v)cout<<e<<" ";cout<<endl;}
template<typename T>
istream& operator >> (istream& is, vector<T>& vec){
    for(T& x:vec) is >> x;
    return is;
}
const ll INF=1e9+7;

int main()
{
    ll a,b,m;
    cin >> a >> b >> m;
    vector<ll> p(a);
    ll min_a=INF;
    ll min_b=INF;
    rep(i,a){
        cin >> p[i];
        min_a=min(min_a,p[i]);
        
    }
    vector<ll> q(b);
    rep(i,b){
        cin >> q[i];
        min_b=min(min_b,q[i]);
    }
    //cout << min_a << min_b << endl;
    ll ans=min_a+min_b;
    //cout << ans << endl;
    vector<ll> y(m);
    vector<ll> c(m);
    rep(i,m){
        int  e,f,g;
        cin >>  e >> f >> g;
        ll v=p[e-1]+q[f-1]-g;
        ans=min(ans,v);
    }
    cout << ans << endl;
    return 0;
} 

Measured memory_bytes: 3328
N, A, B = map(int, input().split())
S = list(input())

a_pass = 0
b_pass = 0

for s in S:
    if s == 'a':
        if (a_pass + b_pass) < (A + B):
            print('Yes')
            a_pass += 1
        else:
            print('No')
    elif s == 'b':
        if (a_pass + b_pass) < (A + B) and b_pass < B:
            print('Yes')
            b_pass += 1
        else:
            print('No')
    elif s == 'c':
        print('No')

Measured memory_bytes: 10012
#include <stdio.h>

int main(void)
{
	int a,b,c,d[7];
	for(c=0;c<7;c++){
		scanf("%d %d",&a,&b);
		d[c]=a-b;
	}
	for(c=0;c<7;c++){
		printf ("%d\n",d[c]);
	}
	return 0;
}



Measured memory_bytes: 2112
from itertools import accumulate
N = int(input())
S = input()
Di = list(accumulate([1 if s == 'D' else 0 for s in S]))
Mi = list(accumulate([1 if s == 'M' else 0 for s in S]))

dp = [0]*N
for i, s in enumerate(S):
    if s == 'M':
        dp[i] = dp[i-1] + Di[i]
    else:
        dp[i] = dp[i-1]

Q = int(input())
K = list(map(int, input().split()))

for k in K:
    ans = 0
    for i, s in enumerate(S):
        if s == 'C':
            if i - k < 0:
                ans += dp[i]
            else:
                ans += dp[i] - dp[i-k] - Di[i-k]*(Mi[i]-Mi[i-k])
    print(ans)


Measured memory_bytes: 153300
#include <stdio.h>

int main(int argc, char const *argv[])
{
	int H, W;
	while (1) {
		scanf("%d %d", &H, &W);
		if(H == 0 && W == 0) break;
		for(int i = 0; i < H; i++) {
			for(int j = 0; j < W; j++) {
				printf("#");
			}
			printf("\n");
		}
		printf("\n");

	}

	return 0;
}


Measured memory_bytes: 2140
#include<stdio.h>

int main(){
    int a,b;
    scanf("%d %d",&a,&b);
    if(a==b){
        printf("a == b\n");
    }else if(a<b){
        printf("a < b\n");
    }else if(a>b){
        printf("a > b\n");
    }
    return 0;
}


Measured memory_bytes: 2040
n, m, x = map(int, input().split())

c = []
reference = []
for i in range(n):
    price, *a = map(int, input().split())
    c.append(price)
    reference.append(a)

understanding = [0] * m
price = 0
ans = sum(c) + 1

for i in range(2**n):
    understanding = [0] * m
    price = 0
    for j in range(n):
        if (i >> j) & 1:
            price += c[j]
            for k in range(m):
                understanding[k] += reference[j][k]
    
    flg = True
    for j in range(m):
        if understanding[j] < x:
            flg = False
            break
    
    if flg:
        ans = min(ans, price)
        
if sum(c) < ans:
    print(-1)
else:
    print(ans)

Measured memory_bytes: 9108
fn main() {
    proconio::input! {
        n: usize,
        a: [u8;n],
    }
    let mut b=vec![0;n];
    let mut m=0;
    for i in (0..n).rev() {
        let mut c=0;
        let mut k=(i+1)*2-1;
        while k<n {
            c=(c+b[k])%2;
            k+=i+1;
        }
        if c!=a[i] {
            m+=1;
            b[i]=1;
        }
    }
    println!("{}",m);
    if m>0 {
        for (i,b) in b.into_iter().enumerate() {
            if b==1 {
                print!("{} ",i+1);
            }
        }
    }
}

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

template<class T>
T lcm(T a,T b){
    return a/__gcd(a,b)*b;
}

int main(){
	int h,w;cin >> h >> w;
  	string s;
  	for(int i=0;i<2+w;i++){
    	cout << "#";
    }
  	cout << endl;
    for(int j=0;j<h;j++){
        cin >> s;
        cout << "#"+s+"#" << endl;
    }
  
  	for(int i=0;i<2+w;i++){
    	cout << "#";
    }
  	
    return 0;
}


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

#define REP(i, n) for(int i = 0; i < (int)(n); ++i)
#define FOR(i, m, n) for(int i = (int)(m); i < (int)(n); ++i)

vector<int> a, b, c, d;


int dfs(vector<int> A, int ret, int N, int M, int Q){
    if(A.size() == N){
        int s = 0;
        REP(i, Q){
            if(A[b[i]] - A[a[i]] == c[i]) s += d[i];
        }
        return max(s, ret);
    }

    if(A.size() == 0) A.push_back(1);
    else A.push_back(A.back());
    FOR(i, A.back(), M+1){
        ret = max(ret, dfs(A, ret, N, M, Q));
        ++A.back();
    }

    return ret;
}

int main()
{
    int N, M, Q;
    cin >> N >> M >> Q;
    a = b = c= d= vector<int>(Q);
    REP(i, Q){
        cin >> a[i] >> b[i] >> c[i] >> d[i];
        --a[i], --b[i];
    }

    // あり得る数列を全探索
    cout << dfs(vector<int>(0), 0, N, M, Q) << endl;

    return 0;
}

Measured memory_bytes: 3152
s = gets.chomp.split("")
if s.length == 26
    i = 25
    a = []
    while(i>0)
        a << s[i]
        break if s[i-1] < s[i]
        a << s[i-1]
        i -= 1
    end
    if i == 0
        puts -1
    else
        b = a.select{|v| v > s[i-1]}.sort
        puts s[0,i-1].join + b[0]
    end
else
    a = ('a'..'z').to_a
    s.each {|v| a.delete(v)}
    puts s.join + a[0]
end

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

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

  int answer = 0;

  for (int i = 0; i <= a; i++) {
    for (int j = 0; j <= b; j++) {
      for (int k = 0; k <= c; k++) {
        if (500*i + 100*j + 50*k == x)
          answer++;
      }
    }
  }
  cout << answer << endl;
}

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

using namespace std;

#define rep(i, n) for (int i = 0; i < (n); ++i)
#define all(obj) (obj).begin(), (obj).end()
#define bit(n) (1LL << (n))

typedef long long ll;

template<class T> inline bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T> inline bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }

const long long INF = 1LL << 60;

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  
  int n,k; cin>>n>>k;
  
  vector<int> v;
  map<int,int> mp;
  
  int res = 0;
  
  rep(i,n) {
    int a; cin>>a;
    
    ++mp[a];
  }
  
  for (auto iter = mp.begin(); iter != mp.end(); ++iter) {
    v.push_back(iter->second);
  }
  
  sort(all(v));
    
  if(v.size() > k) {
    rep(i, v.size() - k) res += v[i];
  }
  
  cout<<res;

}

Measured memory_bytes: 13596
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll mod=1e9+7;
int main() {
	int n,k;
	scanf("%d%d",&n,&k);
	vector<ll>a(n);
	for(int i=0;i<n;i++) scanf("%lld",&a[i]);
	sort(a.begin(),a.end());
	ll ans=1,sign=1;
	int l=0,r=n-1;
	if(k%2){
        ans=a[r--];
        --k;
        if(ans<0) sign=-1;
	}
	while(k){
        ll x=a[l]*a[l+1],y=a[r]*a[r-1];
        if(x*sign>y*sign){
            ans=x%mod*ans%mod;
            l+=2;
        }else{
            ans=y%mod*ans%mod;
            r-=2;
        }
        k-=2;
	}
	printf("%lld",(ans+mod)%mod);
	return 0;
}

Measured memory_bytes: 4856
#include <bits/stdc++.h>
#define pb push_back
#define mp make_pair

using ll = long long;
using namespace std;
int x, y, z, l, m, n, r, q, k;

void solve() {
    cin>>n;
    cin>>r>>q; int ans = __gcd(r, q);
    for(int i=2;i<n;i++){
        cin>>r;
        ans = __gcd(r, ans);

    }
    cout<<ans<<'\n';

}

int main() 
{
    std::ios::sync_with_stdio(false); \
        std::cin.tie(NULL);
    int test;
    test = 1;
    while (test--) {
        solve();
    }
    return 0;
}

Measured memory_bytes: 3656
#include <bits/stdc++.h>
using namespace std;
int dx[4]={1,0,-1,0},dy[4]={0,1,0,-1};
typedef pair<int,int> p;
int jyo(int x,int y){//xのｙ乗
	int ans=1;
	for(int i=0;i<y;i++){
		ans*=x;
	}
	return ans;
}
int main() {
	int x;
	cin>>x;
	double n[x];
	for(int i=0;i<x;i++){
		cin>>n[i];
	}
	double ans=0;
	for(int i=0;i<x;i++){
		ans+=1/n[i];
	}
	cout<<1/ans<<endl;
	return 0;
}


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

using namespace std;

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

#define MOD 1000000007
#define REP(i, N) for (int i = 0; i < N; ++i)
#define REP1(i, N) for (int i = 1; i <= N; ++i)
#define RREP(i, N) for (int i = N - 1; i >= 0; --i)
#define ALL(a) a.begin(), a.end()

int main() {
  int n;
  cin >> n;
  int a[n];
  REP(i, n) {
    cin >> a[i];
    a[i]--;
  }
  int b[n];
  REP(i, n) cin >> b[i];
  int c[n];
  REP(i, n - 1) cin >> c[i + 1];
  int ans = 0;
  int before = -1;
  REP(i, n) {
    ans += b[a[i]];
    if (i && before + 1 == a[i]) {
      ans += c[a[i]];
    }
    before = a[i];
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256
import java.util.*;

public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in); 
    int L = sc.nextInt();
    int R = sc.nextInt();
    int d = sc.nextInt();
    System.out.println(R / d - (L - 1)/ d);
  }
}

Measured memory_bytes: 35636
#include <bits/stdc++.h>
using namespace std;
 
int main() {
	string s;
	cin >> s;

	if(s.at(0)==s.at(1) || s.at(1)==s.at(2) || s.at(2)==s.at(3))
		cout << "Bad" << endl;
	else
		cout << "Good" << endl;
}

Measured memory_bytes: 256
#![allow(unused_imports)]

use std::cmp::{max, min, Ordering};
use std::collections::*;
#[cfg(debug_assertions)]
include! {"./debug.rs"}

#[cfg(not(debug_assertions))]
macro_rules! debug {
    ($($arg:expr),*) => {};
}

macro_rules! read {
    ([$t:ident] ; $n:expr) =>
        ((0..$n).map(|_| read!([$t])).collect::<Vec<_>>());
    ([$t:ident]) =>
        (rl().split_whitespace().map(|w| read_type!(w, $t)).collect::<Vec<_>>());
    (_, [$t:ident] ; $n:expr) =>
        ((0..$n).map(|_| read!(_, [$t])).collect::<Vec<_>>());
    (_, [$t:ident]) =>
        (rl().split_whitespace().skip(1).map(|w| read_type!(w, $t)).collect::<Vec<_>>());
    ($($t:ident),+ ; $n:expr) =>
        ((0..$n).map(|_| read!($($t),+)).collect::<Vec<_>>());
    ($t:ident) => (read_type!(rl(), $t));
    ($($t:ident),*) => {{
        let buf = rl();
        let mut w = buf.split_whitespace();
        ($(read_type!(w.next().unwrap(), $t)),*)
    }};
}

macro_rules! read_type {
    ($s:expr, chars) => {
        $s.chars().collect::<Vec<char>>()
    };
    ($s:expr, usize1) => {
        read_type!($s, usize) - 1
    };
    ($s:expr, $t:ty) => {
        $s.parse::<$t>().unwrap()
    };
}

fn rl() -> String {
    let mut buf = String::new();
    std::io::stdin().read_line(&mut buf).unwrap();
    buf.trim_right().to_owned()
}

trait IteratorExt: Iterator + Sized {
    fn vec(self) -> Vec<Self::Item> {
        self.collect()
    }
}

impl<T: Iterator> IteratorExt for T {}

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

fn main() {
    let (h, w) = read!(usize, usize);
    let s = read!(chars; h);

    let mut lit_x = vec![vec![0; w]; h];
    for y in 0..h {
        let mut start_x = 0;
        while start_x < w {
            let mut lit = 0;
            let mut to_x = start_x;
            for x in start_x..w {
                if s[y][x] == '#' {
                    break;
                }
                lit += 1;
                to_x = x;
            }
            for l in &mut lit_x[y][start_x..to_x + 1] {
                *l = lit;
            }
            start_x = to_x + 1;
        }
    }

    let mut lit_y = vec![vec![0; w]; h];
    for x in 0..w {
        let mut start_y = 0;
        while start_y < h {
            let mut lit = 0;
            let mut to_y = start_y;
            for y in start_y..h {
                if s[y][x] == '#' {
                    break;
                }
                lit += 1;
                to_y = y;
            }
            for y in start_y..to_y + 1 {
                lit_y[y][x] = lit;
            }
            start_y = to_y + 1;
        }
    }
    debug!(lit_x);
    debug!(lit_y);

    let ans = lit_x
        .iter()
        .flat_map(|a| a)
        .zip(lit_y.iter().flat_map(|a| a))
        .map(|(&x, &y)| x + y - 1)
        .max()
        .unwrap();

    println!("{}", ans);
}


Measured memory_bytes: 53500
#include <iostream>
#include <vector>
#include <numeric>
#include <cstdlib>
#include <cmath>
#include <algorithm>
#include <string>
#include <cstring>
#include <queue>
#define myfor(i,N) for(i=0;i<N;i++)
#define myforFL(i,f,l) for(i=f;i<l;i++)
#define myforInv(i,N) for(i=N;i>=0;i--)
#define myforFLInv(i,f,l) for(i=f;i>l;i--)
using namespace std;

int add(int a, int b){
	return a+b;
}
int sub(int a, int b){
	return a-b;
}


int main(){
	string S;
	int i,j,k;
	string opr = "+-";
	

	cin >> S;
	int a,b,c,d,num;
	a = S[0] - '0';
	b = S[1] - '0';
	c = S[2] - '0';
	d = S[3] - '0';
	myfor(i,2){
		myfor(j,2){
			myfor(k,2){
				if(opr[i] == opr[0]) num = add(a,b);
				else num = sub(a,b);
				if(opr[j] == opr[0]) num = add(num,c);
				else num = sub(num,c);
				if(opr[k] == opr[0]) num = add(num,d);
				else num = sub(num,d);
				if(num == 7){
					string hoge = "hoge";
					string ans = hoge + S[0] + opr[i]+S[1]+opr[j]+S[2]+opr[k]+S[3]+"=7";
					
					cout << ans.substr(4) <<endl; 
					return 0;
				}
			}
		}
	}
	return 0;
}

Measured memory_bytes: 256
N = int(input())

# Fのデータを取得
list_f = []
for n in range(N):
  list_f.append(list(map(int,input().split())))

# Pのデータを取得
list_p = []
for n in range(N):
  list_p.append(list(map(int,input().split())))

'''考え方
各開店パターン毎に「その時の利益」を計算する
'''

from itertools import product

list_01 = [0,1]
array_prd = list(product(list_01,repeat=10))
max_prof = - 10 ** 18

for i in range(1024):
  if array_prd[i] == (0,0,0,0,0,0,0,0,0,0):
    continue
    
  tmp = 0
  
  for j in range(N):
    cnt_open = sum([ary * int(open_or_close) for ary,open_or_close in zip(array_prd[i],list_f[j])])
    tmp += list_p[j][cnt_open]
  
  if tmp > max_prof:
    max_prof = tmp

print(max_prof)


Measured memory_bytes: 3316
#include <iostream>
#include <string>
#include <sstream>
#include <cmath>
#include <vector>
#include <map>
#include <set>
#include <algorithm>
#include <numeric>
using namespace std;
typedef long long LL;
LL i,j,k,n,m;
LL mod=1000000007;
string s;

int main() {
  cin >>n;
  std::vector<LL> v(n),hv(n);
  LL sum =0;
  LL abssum =0;
  for(i=0;i<n;++i) {
    cin>>v[i];
    sum +=v[i];
    abssum +=abs(v[i]);
  }
  hv[0]=v[0];
  LL dsum = abssum;
  LL diff = sum - hv[0];
  dsum = min(dsum, abs(hv[0]-diff));
  for(i=1;i<n-1;++i) {
    hv[i] = v[i] + hv[i-1];
    diff = sum - hv[i];
    dsum = min(dsum, abs(hv[i]-diff));
  }
  cout << dsum << endl;
  return 0;
}


Measured memory_bytes: 3328
n=int(input())+1
import math
ans=0
for i in range(1,n):
    ans+=n-i
    for j in range(i+1,n):
        p=math.gcd(n-i,n-j)
        ans+=p*6
        for k in range(j+1,n):
            ans+=math.gcd(p,n-k)*6
print(ans)

Measured memory_bytes: 9072
import java.util.*;
public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int H = sc.nextInt();
		int W = sc.nextInt();
		int N = sc.nextInt();
		int a[]=new int[N];
		for(int i=0;i<N;i++)a[i]=sc.nextInt();
		sc.close();
		
		int field[][]= new int[H][W];
		int nowH = 0;
		int nowW = 0;
		int color = 1;
		boolean goRight = true;
		for(int t:a) {
			for(int i=0;i<t;i++) {
				field[nowH][nowW]=color;
		
				if(goRight) {
					if(nowW<W-1) nowW ++;
					else {
						nowH++;
						goRight = false;
					}
				}
				else {
					if(nowW>0) nowW --;
					else {
						nowH++;
						goRight = true;
					}
				}
				
			}
			color ++ ;
		}
		
		//output
		StringBuilder sb = new StringBuilder();
		for(int i=0;i<H;i++) {
			for(int j=0;j<W;j++) {
				sb.append(field[i][j]+" ");
			}
			sb.append("\n");
		}
		System.out.println(sb.toString());
	}
}


Measured memory_bytes: 31224
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
template<class T,class U> using P = pair<T,U>;
template<class T> using vec = vector<T>;
template<class T> using vvec = vector<vec<T>>;

constexpr ll mod = 1e9+7;
struct mint {
    ll x;
    mint(ll x=0):x((x%mod+mod)%mod){}
    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;
    }
};


int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll N;
    cin >> N;
    vec<ll> C(N);
    for(int i=0;i<N;i++){
        cin >> C[i];
    }
    sort(C.begin(),C.end());
    mint ans = 0;
    vec<mint> beki(2*N+1,1);
    for(int i=1;i<=2*N;i++) beki[i] = beki[i-1]*2;
    for(int i=0;i<N;i++){
        mint p = beki[2*i]*C[i]*2;
        if(i!=N-1) p *= beki[N-i-2]*(N-i-1)+beki[N-i-1];
        p *= beki[N-i-1];
        ans += p;
    }
    cout << ans.x << endl;
}

Measured memory_bytes: 4992
import sys


def input(): return sys.stdin.readline().strip()


def resolve():
    s1, s2, t1, t2 = map(int, input().split())
    l = []
    yoko = t1 - s1
    tate = t2 - s2
    if yoko > 0 and tate > 0:
        l.append('R' * yoko + 'U' * tate)
        l.append('L' * yoko + 'D' * tate)
        l.append('D' + 'R' * (yoko + 1) + 'U' * (tate + 1) + 'L')
        l.append('U' + 'L' * (yoko + 1) + 'D' * (tate + 1) + 'R')
        print(''.join(l))
    elif yoko > 0 and tate < 0:
        tate = -tate
        l.append('R' * yoko + 'D' * tate)
        l.append('L' * yoko + 'U' * tate)
        l.append('U' + 'R' * (yoko + 1) + 'D' * (tate + 1) + 'L')
        l.append('D' + 'L' * (yoko + 1) + 'U' * (tate + 1) + 'R')
        print(''.join(l))
    elif yoko < 0 and tate > 0:
        yoko = -yoko
        l.append('L' * yoko + 'U' * tate)
        l.append('R' * yoko + 'D' * tate)
        l.append('D' + 'L' * (yoko + 1) + 'U' * (tate + 1) + 'R')
        l.append('U' + 'R' * (yoko + 1) + 'D' * (tate + 1) + 'L')
        print(''.join(l))
    else:
        yoko = -yoko
        tate = -tate
        l.append('L' * yoko + 'D' * tate)
        l.append('R' * yoko + 'U' * tate)
        l.append('U' + 'L' * (yoko + 1) + 'D' * (tate + 1) + 'R')
        l.append('D' + 'R' * (yoko + 1) + 'U' * (tate + 1) + 'L')
        print(''.join(l))
resolve()

Measured memory_bytes: 3188
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
#define rep(i, n) for(ll (i) = 0; (i) < (n); (i)++)
template<class T> void chmax(T &a, const T &b){if(a < b){a = b;}}

ll flg[101010];

int main(){

    ll N, K;
    cin >> N >> K;
    priority_queue<P>Q;
    priority_queue<P, vector<P>, greater<P> >R;
    rep(i, N){
        ll t, d;
        cin >> t >> d;
        Q.push(P(d, t));        
    }
    ll v = 0, sum = 0;
    rep(i, K){
        ll d = Q.top().first;
        ll t = Q.top().second;
        Q.pop();
        sum += d;
        if(flg[t] == 0){
            flg[t] = 1;
            v++;
        }
        else R.push(P(d, t));
    }
    ll ans = sum + v * v;
    while(!Q.empty()){
        ll d = Q.top().first;
        ll t = Q.top().second;
        Q.pop();
        if(flg[t])continue;
        if(!R.empty()){
            ll rd = R.top().first;
            ll rt = R.top().second;
            R.pop();
            sum -= rd;
            sum += d;
            flg[t] = 1;
            v++;
        }
        chmax(ans, sum + v * v);
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 4080
import java.util.Scanner;

class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int h = sc.nextInt(), w = sc.nextInt(),r=sc.nextInt(),count=0;
        char[][] m=new char[h][w];
        for (int i = 0; i < h; i++) {
            m[i]=sc.next().toCharArray();
        }
        for (int i = 0; i < h; i++) {
            for (int j = 0; j < w; j++) {
                count+=getCountH(i,j,r,h,m);
                count+=getCountW(i,j,r,w,m);
            }
        }
        System.out.println(count);
    }
    static int getCountH(int i,int j,int r,int l,char[][] m) {
        if(i+r>l)return 0;
        for(int k=i;k<i+r;k++) {
            if(m[k][j]=='#') {
                return 0;
            }
        }
        return 1;
    }
    static int getCountW(int i,int j,int r,int l,char[][] m) {
        if(j+r>l)return 0;
        for(int k=j;k<j+r;k++) {
            if(m[i][k]=='#') {
                return 0;
            }
        }
        return 1;
    }
}


Measured memory_bytes: 28028
package main

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

func pop(stack *[]int) (v int, err error) {
	var s = *stack
	if len(s) == 0 {
		return 0, errors.New("no values")
	}
	v = s[len(s)-1]
	*stack = s[0 : len(s)-1]
	return v, nil
}
func push(stack *[]int, v int) {
	var s = *stack
	*stack = append(s, v)
}

func main() {
	var scanner = bufio.NewScanner(os.Stdin)
	scanner.Scan()
	var text = scanner.Text()
	arr := strings.Split(text, " ")
	var stack = make([]int, 0)
	for _, v := range arr {
		var a, b int
		var val, _ = strconv.Atoi(v)
		switch v {
		case "+":
			a, _ = pop(&stack)
			b, _ = pop(&stack)
			push(&stack, a+b)
		case "-":
			a, _ = pop(&stack)
			b, _ = pop(&stack)
			push(&stack, b-a)
		case "*":
			a, _ = pop(&stack)
			b, _ = pop(&stack)
			push(&stack, b*a)
		default:
			push(&stack, val)
		}
	}
	var result, _ = pop(&stack)
	fmt.Println(result)
}



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

int gcd(int a, int b) {
  if (a < b) swap(a, b);
  if (b == 0) return a;
  return gcd(a % b, b);
}

int main() {
  int N;
  cin >> N;
  vector<int> A(N);
  for (int i = 0; i < N; i++) cin >> A[i];
  
  vector<int> L(N + 1, 0); // 1-idx
  for (int i = 0; i < N; i++) L[i+1] = gcd(A[i], L[i]);
  vector<int> R(N + 1, 0); // 0-idx
  for (int i = N - 1; i >= 0; i--) R[i] = gcd(A[i], R[i+1]);
  
  int ret = 0;
  for (int i = 0; i < N; i++) {
    ret = max(ret, gcd(L[i], R[i+1]));
  }
  cout << ret << endl;
}

Measured memory_bytes: 1408
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define REP(i,a,b) for (int i = a; i < (b); ++i)
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
#define YY cout << "Yes" << endl;
#define NN cout << "No" << endl;
#define ve vector
#define pint pair<int,int>
const int INF = 1000000007;
const long double EPS = 1e-15;
const long double PI = acos(-1);
typedef long long ll;
using namespace std;
using Graph = vector<vector<int>>;
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; }
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); }
// *max_element(all(d))
int solve(){
  int n;
  cin >> n;
  cout << 0 << endl;
  string f;
  cin >> f;
  int l = 0,r = n;
  if(f!="Vacant")while(1){
    int m = (l + r) / 2;
    cout << m << endl;
    string s;
    cin >> s;
    if(s == "Vacant")break;
    if(m % 2 && s != f || m % 2 == 0 && s == f)l = m + 1;
    else r = m;
  }
  return 0; 
}
int main(){
  // ios::sync_with_stdio(false);cin.tie(nullptr);
  cout << fixed;cout << setprecision(16);
  solve();
  return 0;
}

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

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

    int left1 = a;
    int left2 = a + k - 1;

    int right1 = b - k + 1;
    int right2 = b;


    if(left2 < right1){
        for(int i = a; i <= b; i++ ){
            if(left2 < i && i < right1) continue;
            cout << i << endl;
        }
    }
    else{
        for(int i = a; i <= b; i++){
            cout << i << endl;
        }
    }
    return 0;
}

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

#define REP(i,k,n) for(int i=k;i<n;i++)
#define rep(i,n) for(int i=0;i<n;i++)

using namespace std;
typedef long long ll;

int main()
{
    string s;
    while(cin >> s) {
        if(s == "#") break; 
        
        vector<char> v;
        rep(i,s.size()) {
            if(s[i] == 'w') v.push_back('w');
            if(s[i] == 'n') v.push_back('n');
        }

        int a = 0,b = 1;
        if(v[v.size()-1] == 'w') a = 90;
        else a = 0;

        for(int i=v.size()-2;i>=0;i--) {
            b *= 2;
            if(v[i] == 'w') a = a*2 + 90;
            else a = a*2 - 90;
        }

        while(__gcd(a,b) != 1) {
            int d = __gcd(a,b);
            a /= d;
            b /= d;
        }

        if(b == 1) cout << a << endl;
        else cout << a << "/" << b << endl;
        
    }

    return 0;
}

Measured memory_bytes: 1212
import java.util.Scanner;

public class Main {

    public static final int MOD = 1000000007;

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int a = Integer.parseInt(sc.next());
        int b = Integer.parseInt(sc.next());
        System.out.println(a * b);
    }
}

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

using namespace std;
using ll = long long;

int main(){
  ll N;
  cin >> N;
  
  if(N==1){
    cout << 0 << endl;
    return 0;
  }
  
  vector<ll> H(N);
  vector<ll> can_move(N-1);
  cin >> H[0];
  for(int i=1; i<N; i++){
    cin >> H[i];
    if(H[i-1]>=H[i]){
      can_move[i-1] = 1;
    }else{
      can_move[i-1] = 0;
    }
  }
  
  int cnt = 0;
  int i = 0;
  int ans = 0;
  while(true){
    
    if(can_move[i]==1){
      cnt += 1;
      ans = max(ans, cnt);
    }else{
      cnt = 0;
    }
    
    i += 1;
    if(i==N-1) break;
  }
  
  cout << ans << endl;

  return 0;
}

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

using namespace std;

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

  int n;
  cin >> n;
  vector<int64_t> a(n);
  int64_t sum = 0;
  for (auto& e : a) {
    cin >> e;
    sum += e;
  }
  sum /= n;

  uint64_t cost = 0, cost1 = 0;
  for (int i = 0; i < n; ++i) {
    cost += pow(a[i] - sum, 2);
    cost1 += pow(a[i] - sum - 1, 2);
  }
  cout << min(cost, cost1) << "\n";
}


Measured memory_bytes: 256
// mod custom_lib;

use std::cmp;

fn main() {
  let p = read::<u32>();
  let q = read::<u32>();
  let r = read::<u32>();
  let answer = cmp::min(p + q, cmp::min(q + r, r + p));
  println!("{}", answer);
}

use std::io::*;
use std::str::FromStr;

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

Measured memory_bytes: 4352
#include <algorithm>
#include <iostream>
#include <iomanip>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <unordered_map>

using namespace std;

using ll = long long;
using ld = long double;

#define REP(i, s, e) for (ll i = s; i < e; ++i)

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

    int N; cin >> N;
    vector<int> B(N-1);
    REP(i, 0, N - 1) cin >> B[i];
    int result = B[0] + B[N - 2];
    REP(i, 0, N - 2)
    {
        result += min(B[i], B[i + 1]);
    }

    cout << result << endl;
}


Measured memory_bytes: 256
N = int(input())
a = list(map(int, input().split()))

res = 0
for i in range(N):
  fi_flg = False
  while fi_flg is False:
    if a[i] % 2 == 0:
      a[i] = int(a[i]/2)
      res += 1
    else:
      fi_flg = True
      
print(res)

Measured memory_bytes: 70444
import java.util.*;

public class Main{
    public static void main(String args[]){
        Scanner sc = new Scanner(System.in);
        
        int N = sc.nextInt();
        int[] v = new int[N];
        int[] c = new int[N];
        for(int i = 0; i < N; i++)
            v[i] = sc.nextInt();
        for(int i = 0; i < N; i++)
            c[i] = sc.nextInt();
        
        int sum = 0;

        for(int i = 0; i < N; i++){
            if (v[i] - c[i] > 0)
                sum += (v[i] - c[i]);
        }

        System.out.println(sum);
        sc.close();
    }
}

Measured memory_bytes: 23764