akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>

using namespace std;

#define FOR(i, x, y) for(int i = (x); i < (y); ++i)
#define REP(i, x, y) for(int i = (x); i <= (y); ++i)
#define MP make_pair
#define PB push_back
#define PH push
#define fst first
#define snd second
typedef long long ll;
typedef unsigned long long ull;
typedef double db;
typedef long double ldb;
typedef pair<int, int> pii;

const int magic = 1e5 + 5;
const int INF = 1e9 + 7;

int n, k;
int f[magic];
int ans;
vector<int> vec;

inline int qpow(ll x, int y){
	ll ret = 1;
	for(; y; y >>= 1){
		if(y & 1) (ret *= x) %= INF;
		(x *= x) %= INF;
	}
	return ret;
}

int main(){
	scanf("%d%d", &n, &k);
	for(int i = 1; i * i <= n; ++i) if(!(n % i)){
		vec.PB(i);
		if(n / i != i) vec.PB(n / i);
	}
	sort(vec.begin(), vec.end());
	FOR(i, 0, vec.size()){
		FOR(j, 0, i) if(!(vec[i] % vec[j])) ((f[i] -= f[j]) += INF) %= INF;
		(f[i] += qpow(k, (vec[i] + 1) / 2)) %= INF;
		if(vec[i] & 1) (ans += (1ll * vec[i] * f[i]) % INF) %= INF;
		else (ans += (1ll * vec[i] / 2 * f[i]) % INF) %= INF;
	}
	printf("%d\n", ans);
	return 0;
}

Measured memory_bytes: 256
#include <stdio.h>

int main(){
  int N;
  int i;
  int a[10] = {};//a[i] = 2^i
  scanf("%d", &N);
  for(i = 0; i < 10; i++){
    if(i == 0) a[i] = 1;
    else a[i] = a[i-1]*2;
  }
  i = 0;
  while(a[i+1] <= N){
    i++;
  }
  printf("%d\n", a[i]);
  return 0;
}


Measured memory_bytes: 128
#include <set>
#include <cstdio>
#include <algorithm>
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;

const int maxn=2e5+5,inf=2e9;

multiset<int>R,B;
ll Rmx=-inf,Rmn=inf,Bmx=-inf,Bmn=inf,ans;

int read() {
    int x=0,f=1;char ch=getchar();
    for(;ch<'0'||ch>'9';ch=getchar())if(ch=='-')f=-1;
    for(;ch>='0'&&ch<='9';ch=getchar())x=x*10+ch-'0';
    return x*f;
}

struct bags {
    int v1,v2;

    bags() {}

    bags(int _v1,int _v2) {
        v1=_v1,v2=_v2;
    }

    bool operator<(const bags &a)const {
        return v1<a.v1;
    }
}p[maxn];

ll calc() {
    return 1ll*(*R.rbegin()-*R.begin())*(*B.rbegin()-*B.begin());
}

int main() {
    int n=read();
    for(int i=1;i<=n;i++) {
        int x=read(),y=read();
        if(x>y)swap(x,y);
        p[i]=bags(x,y);
        R.insert(x),B.insert(y);
    }
    sort(p+1,p+n+1);
    ans=calc();
    for(int i=1;i<=n;i++) {
        int x=p[i].v1,y=p[i].v2;
        R.erase(R.find(x)),B.insert(x);
        B.erase(B.find(y)),R.insert(y);
        ans=min(ans,calc());
    }
    printf("%lld\n",ans);
    return 0;
}

Measured memory_bytes: 20608
use std::collections::HashSet;

fn main(){
  let xy = "xy".to_string();
  let yz = "yz".to_string();
  
  loop {
    let nh: Vec<usize> = read_vec();
    let n = nh[0];
    let h = nh[1];

    if n == 0 { break; }

    let mut hs: HashSet<(usize, usize, usize)> = HashSet::new();
    
    for _ in 0 .. h {
      let cab: Vec<String> = read_vec();
      let a: usize = cab[1].parse().unwrap();
      let b: usize = cab[2].parse().unwrap();

      if cab[0] == xy {
        for z in 1 .. n+1 {
          hs.insert((a, b, z));
        }
      } else if cab[0] == yz {
        for x in 1 .. n+1 {
          hs.insert((x, a, b));
        }
      } else {
        for y in 1 .. n+1 {
          hs.insert((a, y, b));
        }
      }
    }
    println!("{}", n * n * n - hs.len());
  }
}

fn read_vec<T>() -> Vec<T>
  where T: std::str::FromStr,
        T::Err: std::fmt::Debug
{
  let mut buf = String::new();
  std::io::stdin().read_line(&mut buf).expect("failed to read");
  buf.split_whitespace().map(|e| e.parse().unwrap()).collect()
}



Measured memory_bytes: 8172
#include <bits/stdc++.h>
using namespace std;
#define int           long long
#define pb            push_back
#define x             first
#define y             second
#define sz(v)         (int)v.size()
#define all(x)        (x).begin(),(x).end()
#define PI            3.14159265358979
#define N             200005

int ar[N],a[N],b[N],c[N],d[N],n,m,q,ans;
void calc(int x,int y){
    if(x==n+1){
        int s=0;
        for(int i=0; i<q; i++){
            if(ar[b[i]]-ar[a[i]]==c[i]) s+=d[i];
        }
        ans=max(ans,s);
        return;
    }
    for(int i=y; i<=m; i++){
        ar[x]=i;
        calc(x+1,i);
    }
}
int solve(){
    cin>>n>>m>>q;
    for(int i=0; i<q; i++){
        cin>>a[i]>>b[i]>>c[i]>>d[i];
    }
    calc(1,1);
    cout<<ans;
    return 0;
}

signed main() {
    ios::sync_with_stdio(0);
    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);
    int t=1;
    // cin>>t;
    while(t--) solve();
    return 0;
}

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

class Main {
    static Long[][] dp;
    static int INF = (int) 1e9 + 7;
    static Integer[][] arr;
    public static void main(String[] args) {
        Scanner s = new Scanner(System.in);
        int N = s.nextInt();
        arr = new Integer[N][2];
        for(int i = 0; i < N; i++) {
            arr[i][0] = s.nextInt();
            arr[i][1] = i;
        }
        Arrays.sort(arr, (a, b) -> b[0] - a[0]);
        dp = new Long[N][N];
        System.out.println(dfs(0, 0, N-1));
    }

    private static long dfs(int index, int left, int right) {
        if(index == arr.length) {
            return 0;
        }
        if(dp[left][right] != null) {
            return dp[left][right];
        }
        return dp[left][right] = Math.max(dfs(index+1, left+1, right) + (long)arr[index][0]*Math.abs(arr[index][1] - left),
                dfs(index+1, left, right-1) + (long)arr[index][0]*Math.abs(arr[index][1] - right));
    }
}


Measured memory_bytes: 108672
s = input().split()
N=int(s[0])
s = input().split()
a=s
s = input().split()
b=s
s = input().split()
sum=int(b[int(a[0])-1])
for i in range(1,N):
        if int(a[i])-int(a[i-1])==1:
                sum = sum+int(b[int(a[i])-1])+int(s[int(a[i-1])-1])
        else:
                sum += int(b[int(a[i])-1])

print(sum)

Measured memory_bytes: 3064
#include <bits/stdc++.h>
typedef long long ll;
using namespace std;
#define repr(i,a,b) for(int i=a;i<b;i++)
#define rep(i,n) for(int i=0;i<n;i++)
#define invrepr(i,a,b) for(int i=b-1;i>=a;i--)
#define invrep(i,n) invrepr(i,0,n)
#define repitr(itr,a) for(auto itr=a.begin();itr!=a.end();++itr)
#define P pair<int,int>
const int MOD=998244353;
const ll INF=2e15;
const double PI=acos(-1);

vector<ll> a(55),p(55);

ll f(ll n,ll x) {
    if (n==0) return 1;
    else if (x<=n) return 0;
    else if (x<=1+a[n-1]) return f(n-1,x-1);
    else if (x==2+a[n-1]) return p[n-1]+1;
    else return p[n-1]+1+f(n-1,x-a[n-1]-2);

}



int main() {
    ios_base::sync_with_stdio(false); 

    ll n,x;
    cin >> n >> x;
    a[0]=1;
    p[0]=1;
    rep(i,n) {
        a[i+1]=2*a[i]+3;
        p[i+1]=2*p[i]+1;
    }
    cout << f(n,x) << endl;
    


    return 0;
}


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

int main() {
  int a, p;
  cin >> a >> p;
  cout << (a * 3 + p) / 2 << endl;
}


Measured memory_bytes: 3572
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define INF 1e9
#define PI 3.14159265359
#define MOD 1000000007
#define ALL(v) v.begin(),v.end()
#define ALLR(v) v.rbegin(),v.rend()
typedef long long ll;
const int dx[4] = {1,0,-1,0};
const int dy[4] = {0,1,0,-1};
//isPrime
//modpow modinv
//getDigit
int main() {
  cout << fixed << setprecision(10);
  int r;
  cin >> r;
  cout << r*r << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <queue>
#include <stack>
#include <vector>
#include <algorithm>
#include <map>
#include <deque>

long long nC2(int n){
  if (n==0){
    return 0;
  } else {
    return (long long)n*(n-1)/2;
  }
}

int main(){
  int N;
  scanf("%d", &N);
  std::vector<int > A(N);
  std::map<int, int> mp;
  long long sum = 0;
  for (int i=0; i<N; i++){
    scanf("%d", &A[i]);
    mp[A[i]]++;
  }
  for (int i=1; i<=N; i++){
    sum += nC2(mp[i]);
  }
  for (int i=0; i<N; i++){
    long long minus = mp[A[i]]-1;
    printf("%lld\n", sum-minus);
  }
  return 0;
}


Measured memory_bytes: 12800
#include <stdio.h>
    int main(void){     
    int i,x;
    

    for (i=1;  i <=100000; i++){
     scanf("%d", &x);
    if ( x == 0 ) 
    
    break;
    
    printf("Case %d: %d\n",i,x);
    
    }
    
    return 0;
    
}



Measured memory_bytes: 2108
# -*- coding: utf-8 -*-
import bisect
import heapq
import math
import random
import sys
from collections import Counter, defaultdict, deque
from decimal import ROUND_CEILING, ROUND_HALF_UP, Decimal
from functools import lru_cache, reduce
from itertools import combinations, combinations_with_replacement, product, permutations
from operator import add, mul, sub

sys.setrecursionlimit(100000)
input = sys.stdin.readline
INF = 2**62-1

def read_int():
    return int(input())


def read_int_n():
    return list(map(int, input().split()))


def read_float():
    return float(input())


def read_float_n():
    return list(map(float, input().split()))


def read_str():
    return input().strip()


def read_str_n():
    return list(map(str, input().split()))


def error_print(*args):
    print(*args, file=sys.stderr)


def mt(f):
    import time

    def wrap(*args, **kwargs):
        s = time.time()
        ret = f(*args, **kwargs)
        e = time.time()

        error_print(e - s, 'sec')
        return ret

    return wrap


@mt
def slv(A, B, C):
    return 'Yes' if len(set([A, B, C])) == 2 else 'No'


def main():
    A, B, C = read_int_n()
    print(slv(A, B, C))


if __name__ == '__main__':
    main()


Measured memory_bytes: 6724
#include <bits/stdc++.h>
#include <boost/math/common_factor_rt.hpp>

using namespace std;

int solve(const std::vector<int>& xs, int x) {
  if (xs.size() == 1) {
    return abs(x - xs.front());
  }
  int ret = abs(x - xs.front());
  for (int i = 1; i < xs.size(); ++i) {
    ret = boost::math::gcd(abs(xs[i] - xs[i - 1]), ret);
  }
  return ret;
}

int main() {
  std::cin.tie(nullptr);
  std::ios::sync_with_stdio(false);
  int n, x;
  std::cin >> n >> x;
  std::vector<int> xs(n);
  for (auto& x : xs) {
    std::cin >> x;
  }
  std::sort(xs.begin(), xs.end());
  std::cout << solve(xs, x) << std::endl;
  return 0;
}


Measured memory_bytes: 640
#include <stdio.h>  
#include <algorithm>  
#include <assert.h>
#include <bitset>
#include <cmath>  
#include <complex>  
#include <deque>  
#include <functional>  
#include <iostream>  
#include <limits.h>  
#include <map>  
#include <math.h>  
#include <queue>  
#include <set>  
#include <stdlib.h>  
#include <string.h>  
#include <string>  
#include <time.h>  
#include <unordered_map>  
#include <unordered_set>  
#include <vector>  

#pragma warning(disable:4996)  
#pragma comment(linker, "/STACK:336777216")  
using namespace std;

#define mp make_pair  
#define Fi first  
#define Se second  
#define pb(x) push_back(x)  
#define szz(x) ((int)(x).size())  
#define rep(i, n) for(int i=0;i<n;i++)  
#define all(x) (x).begin(), (x).end()  
#define ldb ldouble  

typedef tuple<int, int, int> t3;
typedef long long ll;
typedef unsigned long long ull;
typedef double db;
typedef long double ldb;
typedef pair <int, int> pii;
typedef pair <ll, ll> pll;
typedef pair <ll, int> pli;
typedef pair <db, db> pdd;

int IT_MAX = 1 << 19;
const ll MOD = 1000000007;
const int INF = 0x3f3f3f3f;
const ll LL_INF = 0x3f3f3f3f3f3f3f3f;
const db PI = acos(-1);
const db ERR = 1e-10;

int in[100050][2];

int u[100050];

int r[100050];
int root(int x) {
	return (x == r[x]) ? x : (r[x] = root(r[x]));
}
vector <pair<ll, pii>> Vu;
int main() {
	int N, i;
	scanf("%d", &N);
	for (i = 1; i <= N; i++) scanf("%d %d", &in[i][0], &in[i][1]);

	for (i = 1; i <= N; i++) u[i] = r[i] = i;
	sort(u + 1, u + N + 1, [](int a, int b) {
		return in[a][0] < in[b][0];
	});
	for (i = 1; i < N; i++) Vu.emplace_back(in[u[i + 1]][0] - in[u[i]][0], pii(u[i], u[i + 1]));
	sort(u + 1, u + N + 1, [](int a, int b) {
		return in[a][1] < in[b][1];
	});
	for (i = 1; i < N; i++) Vu.emplace_back(in[u[i + 1]][1] - in[u[i]][1], pii(u[i], u[i + 1]));

	sort(all(Vu));
	ll ans = 0;
	for (auto it : Vu) {
		if (root(it.second.first) == root(it.second.second)) continue;
		ans += it.first;
		r[root(it.second.first)] = root(it.second.second);
	}
	return !printf("%lld\n", ans);
}

Measured memory_bytes: 8048
#include <bits/stdc++.h>
using namespace std;
#define REP(i,a) for(int i = 0; i < (a); i++)
#define ALL(a) (a).begin(),(a).end()
typedef long long ll;
typedef pair<int, int> P;
const int INF = 1e9;
const int MOD = 1e9 + 7;
#define MAX_N 3000
#define MAX_M 3000

int dp[MAX_N + 1][MAX_M + 1];

signed main(){
    string s,t;
    cin >> s;
    cin >> t;
    int n = s.size(), m = t.size();
    for(int i = 0; i < n; i++){
        for(int j = 0; j < m; j++){
            if(s[i] == t[j]){
                dp[i + 1][j + 1] = dp[i][j] + 1;
            }else{
                dp[i + 1][j + 1] = max(dp[i][j + 1], dp[i + 1][j]);
            }
        }
    }
    string ans;
    while(n > 0 && m > 0){
        if(s[n - 1] == t[m - 1]){
            ans += s[n - 1];
            n--;
            m--;
        }else if(dp[n - 1][m] > dp[n][m - 1]){
            n--;
        }else{
            m--;
        }
    }
    reverse(ans.begin(), ans.end());
    cout << ans << endl;
}

Measured memory_bytes: 35456
use proconio::input;
#[allow(unused_imports)]
use proconio::marker::{Bytes, Chars};
#[allow(unused_imports)]
use std::cmp::{min, max};

fn main() {
	input! {
		cs: Chars,
	}

	let mut p = 700;
	for i in 0..3 {
		if cs[i] == 'o' {
			p += 100;
		}
	}
	println!("{}", p);
}



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

int main() {
    string target;
    cin >> target;
    if (target.size() == 2)
    {
        cout << target << endl;
    }
    else if(target.size() == 3)
    {
        //string output(target.rbegin(), target.rend());
        //cout << target << endl;
        cout << target[2] << target[1] << target[0] << endl;
    }
  
}

Measured memory_bytes: 256
#define _USE_MATH_DEFINES
#include<iostream>
#include<string>
#include<queue>
#include<cmath>
#include<map>
#include<set>
#include<list>
#include<iomanip>
#include<vector>
#include<random>
#include<functional>
#include<algorithm>
#include<stack>
#include<cstdio>
#include<cstring>
#include<bitset>
#include<unordered_map>
#include<climits>
#include<fstream>
#include<time.h>
#include<cassert>
#include<functional>
#include<numeric>
#include <tuple>

using namespace std;
using ll = long long;
using ld = long double;
#define int long long
#define all(a) (a).begin(),(a).end()
#define EPS (1e-7)
#define fs first
#define sc second
#define xx first
#define yy second.first
#define zz second.second
#define H pair<int, int>
#define P pair<int, pair<int, int>>
#define Q(i,j,k) mkp(i,mkp(j,k))
#define rep(i,n) for(int (i) = 0 ; (i) < (n) ; (i)++)
#define reo(i,n) for(int (i) = 1 ; (i) <= (n) ; (i)++)
#define rng(i,s,n) for(int (i) = (s) ; (i) < (n) ; (i)++)
#define req(n,i) for(int (i) = (n) - 1 ; (i) >= 0 ; (i)--)
#define mkp make_pair
#define mem0(x) memset(x,0,sizeof(x))
#define vec vector
#define pb push_back
#define lb lower_bound
#define ub upper_bound
#define crdcomp(b) sort(all((b)));(b).erase(unique(all((b))),(b).end())
#define ssp(i,n) (i==n-1?"\n":" ")
#define ctoi(c) (int)(c-'a')
#define itoc(c) (char)(c+'a')
#define itn int
#define pri_que priority_queue
#define pp(x,y) pb(H{x,y})
#define ppp(x,y,z) pb(Q(x,y,z))
#define cyes cout<<"Yes\n"
#define cno cout<<"No\n"
const int mod = 1e9 + 7;
const int Mod = 998244353;
const ll inf = 3 * 1e18;
const int Inf = 15 * 1e8;
const vec<int>dx{ 0,0,-1,1 }, dy{ 1,-1,0,0 };
template<class T>bool chmax(T& a, const T& b) { if (a < b) { a = b; return 1; } return 0; }
template<class T>bool chmin(T& a, const T& b) { if (b < a) { a = b; return 1; } return 0; }
ll read() { ll u, k = scanf("%lld", &u); return u; }
string reads() { string s; cin >> s; return s; }
ll gcd(ll i, ll j) { return j ? gcd(j, i % j) : i; }
ll mod_pow(ll x, ll n, ll p) {
	ll res = 1;
	while (n > 0) {
		if (n & 1) res = res * x % p;
		x = x * x % p;
		n >>= 1;
	}
	return res;
}//x^n%p
ll bitcount(ll x) {
	int sum = 0; for (int i = 0; i < 60; i++)if ((1ll << i) & x) sum++;
	return sum;
}
const int fn_ = 600000;
ll fact_[fn_], comp_[fn_];
ll comb(ll x, ll y, ll Mod = mod) {
	if (!fact_[0]) {
		fact_[0] = 1; comp_[0] = 1;
		for (int i = 1; i < fn_; i++) {
			fact_[i] = fact_[i - 1] * i % Mod;
			comp_[i] = mod_pow(fact_[i], Mod - 2, Mod);
		}
	}
	if (x < y) return 0;
	return fact_[x] * comp_[x - y] % Mod * comp_[y] % Mod;
}
//---------------------------------------------------------------
signed main() {
	int h, n;
	cin >> h >> n;
	int sum = 0;
	rep(i, n) sum += read();
	if (h > sum) cout << "No\n";
	else cyes;

}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define lb(xx) (xx&(-xx))
#define MOD 1000000007
using namespace std;
inline void Add(int &a,int b)
{a+=b;a>=MOD?a-=MOD:1;}
inline int add(int a,int b)
{a+=b;return a>=MOD?a-MOD:a;}
inline int sub(int a,int b)
{a-=b;return a<0?a+MOD:a;}
inline int mul(int a,int b)
{return 1ll*a*b%MOD;}
int p2[1234];
int f[1<<16],num[1<<16][16];
int main()
{
	int n,m;
	scanf("%d%d",&n,&m);
	p2[0]=1;
	for(int i=1;i<=m;i++)
		p2[i]=add(p2[i-1],p2[i-1]);
	for(int i=1,x,y;i<=m;i++)
		scanf("%d%d",&x,&y),--x,--y,++num[1<<y][x];
	for(int i=0;i<(1<<n);i++)
		for(int j=0;j<n;j++)
			num[i][j]=num[lb(i)][j]+num[i^lb(i)][j];
	f[0]=1;
	for(int i=1;i<(1<<n);i++){
		if((i&1)!=(i>>1&1))continue;
		for(int j=i;j;j=(j-1)&i){
			if((j&1)!=(j>>1&1))continue;
			int pi=f[i^j],cc=0;
			for(int k=0;k<n;k++)
				if(!(i>>k&1))pi=mul(pi,p2[num[j][k]]-1);
				else if((i^j)>>k&1)cc+=num[j][k];
			Add(f[i],mul(pi,p2[cc]));
		}
	}
	printf("%d\n",sub(p2[m],f[(1<<n)-1]));
	return 0;
}

Measured memory_bytes: 5992
#include <iostream>
#include <vector>
#include <string>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <iomanip>
#include <assert.h>
#include <numeric>

using namespace std;

#define ll long long
#define rep(i, n) for (i = 0; i < n; i++)

int n, m, q;
vector<int> a, b, c, d;
int mx = 0;

void dfs(vector<int> v)
{
  if (v.size() == n)
  {
    int k = 0;
    for (int i = 0; i < q; i++)
    {
      if (v[b[i]] - v[a[i]] == c[i])
      {
        k += d[i];
      }
    }
    mx = max(mx, k);
    return;
  }

  for (int i = v.back(); i <= m; i++)
  {
    vector<int> v_ = v;
    v_.push_back(i);
    dfs(v_);
  }
}

int main()
{
  cin >> n >> m >> q;
  a.resize(q);
  b.resize(q);
  c.resize(q);
  d.resize(q);
  for (int i = 0; i < q; i++)
  {
    cin >> a[i] >> b[i] >> c[i] >> d[i];
    a[i]--;
    b[i]--;
  }
  dfs({1});
  cout << mx << endl;
}


Measured memory_bytes: 3628
#include <iostream>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <cmath>
#include <algorithm>

using namespace std;

const vector<int> dx4 = {-1,  0,  1,  0};
const vector<int> dy4 = { 0,  1,  0, -1};
const vector<int> dx8 = {-1, -1, -1,  0,  1,  1,  1,  0};
const vector<int> dy8 = {-1,  0,  1,  1,  1,  0, -1, -1};

int main(){
    int n, k;
    long long ans;

    cin >> n >> k;

    ans = k;
    for(int i = 1; i < n; i++){
        ans *= (k - 1);
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <stack>
#include <cstdlib>
using namespace std;

/* http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=ALDS1_3_A
Sample Input 1
1 2 +
Sample Output 1
3
Sample Input 2
1 2 + 3 4 - *
Sample Output 2
-3
 */
int main() {
    int ret = 0;
    stack<int> st;
    string s;
    int a, b;

    while(cin >> s) {
        if(s[0] == '+') {
            b = st.top(); st.pop();
            a = st.top(); st.pop();
            st.push(a + b);
        } else if(s[0] == '-') {
            b = st.top(); st.pop();
            a = st.top(); st.pop();
            st.push(a - b);
        } else if(s[0] == '*') {
            b = st.top(); st.pop();
            a = st.top(); st.pop();
            st.push(a * b);
        } else {
            st.push(atoi(s.c_str()));
        }
    }

    cout << st.top() << endl;
    return ret;
} 



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

int main(){
    string s;
    int a[26] = {};
    while(getline(cin, s)){
        for (int i = 0; i < s.size(); i++){
            int idx;
            if (s[i] >= 'a' && s[i] <= 'z'){
                idx = s[i] - 'a';
    			a[idx]++;
            }
            else if (s[i] >= 'A' && s[i] <= 'Z'){
                idx = s[i] - 'A';
    			a[idx]++;
            }
        }
    }
    char out = 'a';
    for (int i = 0; i < 26; i++){
        cout << out << " : " << a[i] << endl;
		out++;
    }
}


Measured memory_bytes: 3192
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include <cctype>
using namespace std;
#define rep(i,n) for(int i=0;i<(int)(n);i++)
typedef long long ll;

int main(){
    int k,a,b;
    cin >> k;
    cin >> a >> b;
    int ans=1;
    for(int i=a;i<=b;i++){
        if(i%k==0){
            ans=0;
            break;
        }
    }
    if(ans==0) cout << "OK" << endl;
    else cout << "NG" << endl;
}


Measured memory_bytes: 3624
#include "iostream"
#include "climits"
#include "list"
#include "queue"
#include "stack"
#include "set"
#include "functional"
#include "algorithm"
#include "string"
#include "map"
#include "unordered_map"
#include "unordered_set"
#include "iomanip"
#include "cmath"
#include "random"
#include "bitset"
#include "cstdio"

using namespace std;

const long long int MOD = 1000000007;
const long double EPS = 1e-8;

long long int N, M, K, H, W, L, R;

struct Coordinate {
	long double x;
	long double y;
	bool operator <(const Coordinate& c)const {
		if (y < c.y)return true;
		if (y > c.y)return false;
		if (x < c.x)return true;
		return false;
	}
	bool operator >(const Coordinate& c)const {
		if (y > c.y)return true;
		if (y < c.y)return false;
		if (x > c.x)return true;
		return false;
	}
	Coordinate operator +(const Coordinate& c)const {
		Coordinate box;
		box.x = x + c.x;
		box.y = y + c.y;
		return box;
	}
	Coordinate operator -(const Coordinate& c)const {
		Coordinate box;
		box.x = x - c.x;
		box.y = y - c.y;
		return box;
	}
	long double det(Coordinate a) {
		return x*a.y - y*a.x;
	}
};

struct Convex_hull {
	vector<Coordinate>node;
	vector<Coordinate>ret;
	bool line;
	Convex_hull(bool l) {
		line = l;
	}
	void Add_node(Coordinate n) {
		node.push_back(n);
	}
	vector<Coordinate>solve() {
		sort(node.begin(), node.end());
		int index = 0;
		int num = node.size();
		ret.resize(num * 2);
		for (int i = 0; i < num; i++) {
			if (line) {
				while (index > 1 && (ret[index - 1] - ret[index - 2]).det(node[i] - ret[index - 1]) < -EPS) {
					index--;
				}
			}
			else {
				while (index > 1 && (ret[index - 1] - ret[index - 2]).det(node[i] - ret[index - 1]) < EPS) {
					index--;
				}
			}
			ret[index++] = node[i];
		}
		int box = index;
		for (int i = num - 2; i >= 0; i--) {
			if (line) {
				while (index > box && (ret[index - 1] - ret[index - 2]).det(node[i] - ret[index - 1]) < -EPS) {
					index--;
				}
			}
			else {
				while (index > box && (ret[index - 1] - ret[index - 2]).det(node[i] - ret[index - 1]) < EPS) {
					index--;
				}
			}
			ret[index++] = node[i];
		}
		ret.resize(index - 1);
		return ret;
	}
};

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

	cin >> N;
	list<int>ans;
	while (N) {
		Convex_hull ch(true);
		for (int i = 0; i < N; i++) {
			Coordinate c;
			string s;
			cin >> s;
			string t = s;
			for (int i = 0; i < s.size(); i++) {
				if (s[i] == ',') {
					s.resize(i);
					break;
				}
			}
			reverse(t.begin(), t.end());
			for (int i = 0; i < t.size(); i++) {
				if (t[i] == ',') {
					t.resize(i);
					break;
				}
			}
			reverse(t.begin(), t.end());
			c.x = stold(s);
			c.y = stold(t);
			ch.Add_node(c);
		}
		auto box = ch.solve();
		ans.push_back(N - box.size());
		cin >> N;
	}
	for (auto i : ans) {
		cout << i << endl;
	}
	return 0;
}



Measured memory_bytes: 3256
n,c=map(int,input().split())
l=sorted([list(map(int,input().split())) for _ in [0]*n],key=lambda x:[x[2],x[0]])
m=[l[0]]
for i in range(1,n):
    if l[i][2]==m[-1][2] and l[i][0]==m[-1][1]:
        m.append([m.pop()[0],l[i][1],l[i][2]])
    else:m.append(l[i])
for x in m:
    x[0]-=1
ans=[0]*max(x[1] for x in m)
for x in m:
    for i in range(x[0],x[1]):
        ans[i]+=1
print(max(ans))

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

int main(){
    int a, b, i;
    while(1){
        a=0; b=0;
        char s[101]={'\0'};
        cin >> s;
        if(s[0]=='0') break;
        for(i=1; s[i]!='\0' && s[i]!= '\n';i++){
            if(s[i]=='A') a++;
            else if(s[i]=='B') b++;
        }
        if(a>b) a++;
        else if(a<b) b++;
        cout << a << " " << b << endl;
    }
    return 0;
}

Measured memory_bytes: 1140
#include <stdio.h>
int main(void){
     int i,j,n,x,card[256][14];

    int mark[4]={'S','H','C','D'};

    for(i=0;i<256;i++){

        for(j=0;j<14;j++){

           card[i][j]=0;

        }

    }

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

    for(i=0;i<n;i++){

        char c;

        int num=0;

        scanf("%c %d\n",&c,&num);
        if(c=='S'){
            x=0;
        }
        if(c=='H'){
            x=1;
        }
        if(c=='C'){
            x=2;
        } 
        if(c=='D'){
            x=3;
        }

        card[x][num]=1;

    }

    for(j=0;j<4;j++){

        for(i=1;i<14;i++){

            if(card[j][i]==0){
                if(x==0){
                    j=='S';
                }
                if(x==1){
                    j=='H';
                }
                if(x==2){
                    j=='C';
                }
                if(x==3){
                    j=='D';
                }

               printf("%c %d\n",mark[j],i);

            }

        }

    }

   return 0;
}


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


namespace エクサウィザーズ
{
    class B
    {
        static void Main(string[] args)
        {
            int n = int.Parse(Console.ReadLine());
            string s = Console.ReadLine();
            int r = 0;
            for (int i = 0; i < n; i++)
            {
                if (s[i] == 'R') { r++; }
            }
            Console.WriteLine(r > n - r ? "Yes" : "No");
        }
    }
}

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

int main(){
    int n; cin>>n;
    for(int i=64;;i/=2){
        for(int j=n;j>=1;j--){
            if(j%i==0){
                cout<<j<<endl;
                return 0;
            }
        }
    }
}


Measured memory_bytes: 256
a = int(input())
b = [int(i) for i in input().split()]

numbers = 0
theend = False

while theend == False:
    if b.count(0) == a:
        theend = True
        break

    indexnotzero = 0

    for i in range(len(b)):
        if b[i] == 0:
            continue
        else:
            indexnotzero = i
            break

    if indexnotzero == len(b) - 1:
        numbers += b[len(b) - 1]
        break

    try:
        length = b.index(0, indexnotzero)
    except ValueError:
        length = len(b)
    minimum = min(b[indexnotzero:length])

    numbers += minimum

    b[indexnotzero:length] = [i - minimum for i in b[indexnotzero:length]]

print(numbers)

Measured memory_bytes: 3064
#include <bits/stdc++.h>
#define int long long

using namespace std;

int32_t main(void){

  int X,Y,A,B,C;
  cin >> X >> Y >> A >> B >> C;
  vector<int> p(A),q(B),r(C);
  for(int i=0;i<A;i++) cin >> p[i];
  for(int i=0;i<B;i++) cin >> q[i];
  for(int i=0;i<C;i++) cin >> r[i];

  sort(p.begin(),p.end(),greater<int>());
  sort(q.begin(),q.end(),greater<int>());

  vector<int> ans;
  for(int i=0;i<X;i++){
    ans.push_back(p[i]);
  }
  for(int i=0;i<Y;i++){
    ans.push_back(q[i]);
  }
  for(int i=0;i<C;i++){
    ans.push_back(r[i]);
  }

  sort(ans.begin(),ans.end(),greater<int>());
  int ans_sum=0;
  for(int i=0;i<X+Y;i++){
    ans_sum+=ans[i];
  }

  cout << ans_sum << "\n";


  //my own(WA)
  // int x_sum=0;
  // int y_sum=0;
  // int c_counter=0;

  // for(int i=0;i<Y;i++){
  //   if(c_counter==C) break;
  //   if(q[i]<r[c_counter]){
  //     q[i] = r[c_counter];
  //     c_counter++;
  //   }
  // }
  // for(int i=0;i<X;i++){
  //   if(c_counter==C) break;
  //   if(p[i]<r[c_counter]){
  //     p[i] = r[c_counter];
  //     c_counter++;
  //   }
  // }

  // for(int i=0;i<X;i++){
  //   x_sum+=p[i];
  // }
  // for(int i=0;i<Y;i++){
  //   y_sum+=q[i];
  // }
  // printf("%d\n", x_sum+y_sum);

  //for debug
  /*
  printf("\n%d %d %d %d %d\n", X,Y,A,B,C);
  for(int i=0;i<A;i++){
    printf("%d ", p[i]);
  }
  printf("\n");
  for(int i=0;i<B;i++){
    printf("%d ", q[i]);
  }
  printf("\n");
  for(int i=0;i<C;i++){
    printf("%d ", r[i]);
  }
  printf("\n");
  */

  return 0;
}


Measured memory_bytes: 8560
import java.io.*;

class Main {
	public static void main(String[] args) throws IOException {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		StringBuilder sb = new StringBuilder();
		while (true) {
			String[] cut = br.readLine().split(" ");
			int H = Integer.parseInt(cut[0]);
			int W = Integer.parseInt(cut[1]);
			if (H == 0 && W == 0){
				break;
			}
			for (int i = 0; i < W; i++) {
				sb.append("#");

			}
			sb.append("\n");
			for (int k = 0; k < H-2; k++) {
				sb.append("#");
				for (int j = 0; j < W - 2; j++) {
					sb.append(".");
				}
				sb.append("#");
				sb.append("\n");
			}
			for (int i = 0; i < W; i++) {
				sb.append("#");
			}
			sb.append("\n");
			sb.append("\n");
		}
		System.out.print(sb);

	}

}

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

#define INF 1001001001
#define LINF 1001001001001001001
#define MOD 1000000007
#define MOD2 998244353

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

#define rep(i,n) for(int i=0,_i=(n);i<_i;++i)
#define rep1(i,a,b) for(int a_=(a),b_=(b),i=a_;i<b_;++i)
#define repr(i,n) for(int _i=(n),i=_i;i>0;--i)

#define db(x) cerr<<#x<<" = "<<x<<" ";
#define db2(x,y) cerr<<"("<<#x<<", "<<#y<<") = ("<<x<<", "<<y<<") ";
#define db3(x,y,z) cerr<<"("<<#x<<", "<<#y<<", "<<#z<<") = ("<<x<<", "<<y<<", "<<z<<") ";
#define ln cout<<endl;

#define all(a)  (a).begin(),(a).end()
#define dig(n)  to_string(n).length()

#define pb push_back
#define eb emplace_back
#define mp make_pair
#define se second
#define fi first

typedef long long ll;

typedef pair<int,int> P;
typedef pair<int,P> iP;
typedef pair<P,P> PP;

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 dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};

int main(){

    bool flag=false;
    ll ans=0,sum=0;

    double n,m;
    cin>>n;

    cout <<fixed<<setprecision(16)<< n * 2 * 3.14159265<< endl;

    //if(flag)cout << "Yes" <<endl;
    //else cout << "No" <<endl;

    return 0;
}


Measured memory_bytes: 3684
if __name__ == "__main__":
    # スペース区切りの整数の入力
    N, K = map(int, input().split())
    s = input()

    # s = aaa[0:N]
    s_list = list(s)

    s_list[K-1] = s_list[K-1].lower()

    ans_str = ""
    for a in s_list:
        ans_str += a
    print(ans_str)


Measured memory_bytes: 2940
#include <bits/stdc++.h>
using namespace std;
int main(){
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    int a,b;
    string si;
    cin>>a>>si>>b;
    if(si=="+"){
        cout<<a+b<<endl;
    }else{
        cout<<a-b<<endl;
    }
	return 0;
}


Measured memory_bytes: 256
# include "cstdio"

using namespace std;

const int maxm=1000+10;

int n; 

bool f[maxm];

int main(){
	f[1]=true;
	register int i,j;
	for(i=2;i<=1000;i++){
		for(j=i*i;j<=1000;j*=i){
			f[j]=true;
		}
	}
	scanf("%d",&n); 
	for(i=n;i>=1;i--){
		if(f[i]){
			printf("%d",i);
			return 0; 
		} 
	}
	return 0;
}

Measured memory_bytes: 128
fun main(args: Array<String>) {
    val x = readLine()!!.toInt()
    val y = readLine()!!.split(" ").map { it.toInt() }

    val ans = y.fold(Pair(0, (Triple(0,0,0)))) {n,t ->
     val current = Triple(n.second.second, n.second.third, t)
     when {
         listOf(current.first,current.second, current.third).sorted()[1] == current.second && (current.first != 0)-> {
             Pair(n.first + 1 , current)
         }
         else -> {
             Pair(n.first, current)
         }
     }
    }.first

    println(ans)
}


Measured memory_bytes: 37940
#include<bits/stdc++.h>
using namespace std;
int n,k,ans;
char s[100005];
int main(){
  	scanf("%d%d%s",&n,&k,s+1);
    for (int i=2;i<=n;i++)
      	if (s[i]==s[i-1]) ++ans;
    printf("%d\n",min(n-1,2*k+ans));
}

Measured memory_bytes: 384
from sys import stdin
from operator import itemgetter

input = stdin.readline

N = int(input())

ab = [[int(j) for j in input().split()] for i in range(N)]

cd = [[int(j) for j in input().split()] for i in range(N)]


def main():
    # y 降順
    ab.sort(key=itemgetter(1), reverse=True)

    # x 昇順
    cd.sort(key=itemgetter(0))

    # ペアになった赤
    done = [False] * N

    ans = 0

    for i in range(N):
        for j in range(N):
            if not done[j] and ab[j][0] < cd[i][0] and ab[j][1] < cd[i][1]:
                done[j] = True
                ans += 1
                break

    print(ans)
    return


main()


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

using namespace std;
typedef long long ll;

#define rep(i, n) for (int i = 0; i < (n); i++)
#define rep2(i, a, b) for (int i = (a); i < (b); ++i)
#define all(a) (a).begin(), (a).end()
#define all2(a, b) (a).begin(), (a).begin() + (b)
#define debug(vari) cerr << #vari << " = " << (vari) << endl;

int sum_digit(int a, int b)
{
    int res = 0;
    while (a || b)
    {
        res += a % 10 + b % 10;
        a /= 10;
        b /= 10;
    }
    return res;
}

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

    int ans = 1001001001;

    for (int a = 1; a < n; a++)
    {
        int b = n - a;
        ans = min(sum_digit(a, b), ans);
    }

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 3620
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cfloat>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <memory>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <sstream>
#include <complex>
#include <stack>
#include <queue>
using namespace std;
static const double EPS = 1e-5;
typedef long long ll;
#define FOR(i,n) for(i=0;i<n;i++)
#define rep(i,n) for(int i=0;i<n;i++)

int main(){
	double a,b,c,d,e,f,r1,r2;
	for(;scanf("%lf %lf %lf %lf %lf %lf",&a,&b,&c,&d,&e,&f)!=EOF;){
		r1=(c*e-f*b)/(a*e-d*b);
		r2=(c*d-f*a)/(b*d-e*a);
		-0.001<r1&&r1<0.001&&(r1=0);
		-0.001<r2&&r2<0.001&&(r2=0);
		printf("%.3f %.3f\n",r1,r2);
	}
	return 0;
}

Measured memory_bytes: 0
//waz
#include <bits/stdc++.h>
#define mp make_pair
#define pb push_back
#define fi first
#define se second
#define ALL(x) (x).begin(), (x).end()
#define SZ(x) ((int)((x).size()))
using namespace std;
typedef pair<int, int> PII;
typedef vector<int> VI;
typedef long long int64;
typedef unsigned int uint;
typedef unsigned long long uint64;

vector<PII> p, ans;

void link(int a, int b) {
  if (a && b) {
  	ans.pb(mp(a, b));
  }
}

int main() {
  int n;
  cin >> n;
  if (n & 1) {
  	for (int i = 1; i <= n - 1; ++i) {
  	  if (i > (n - i)) {
  	  	break;
	  }
  	  p.pb(mp(i, n - i));
	}
	p.pb(mp(0, n));
  }
  else {
  	for (int i = 1; i <= n; ++i) {
  	  if (i > (n + 1 - i)) {
  	  	break;
	  }
	  p.pb(mp(i, n + 1 - i));
    }
  }
  
  int x = SZ(p);
  for (int i = 0; i < x; ++i) {
  	for (int j = i + 1; j < x; ++j) {
  	  link(p[i].fi, p[j].fi);
  	  link(p[i].fi, p[j].se);
  	  link(p[i].se, p[j].fi);
  	  link(p[i].se, p[j].se);
	}
  }
  printf("%d\n", SZ(ans));
  for (auto v : ans) {
  	printf("%d %d\n", v.fi, v.se);
  }
  return 0;
}


Measured memory_bytes: 384
//Compiler optimization
#pragma GCC optimize("Ofast")

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

//typedef
typedef long long ll;
typedef double db;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<string> vs;
typedef vector<char> vc;
typedef string S;
typedef queue<int> qi;
typedef pair<ll,ll> P;
typedef vector<P> vp;
typedef vector<vl> mat;

//macro
#define reverse(a) reverse(a.begin(),a.end())
#define unique(a) a.erase(unique(a.begin(),a.end()),a.end())
#define fr(i,n)for(ll i=0;i<(n);i++)
#define ifr(i,n)for(ll i=(n)-1;i>=0;i--)
#define all(x) x.begin(),x.end()
#define each(x, v) for (auto &x : v)

//abbreviation
#define pb push_back
#define elif else if
#define mp make_pair
#define endl '\n'

//debug
#define debug(x) cerr << #x << ": " << x << endl
#define v_debug(v) cerr << #v << endl;fr(i,v.size()) cerr << i << ": " << v[i] << endl

//const
const  ll INF = 1e18;


int main(){
    cin.tie(0);
    ios::sync_with_stdio(0);
    char x;cin >> x;
    if(x >= 'a' && x <= 'z')cout << 'a';
    else cout << 'A';
    return 0;
}

Measured memory_bytes: 3632
#include <iostream>
#include <string>
#include <stack>
#include <queue>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <algorithm>

using namespace std;
#define rep(i, n) for (int i = 0; i < (n); i++)
#define rep1(i, s, n) for (int i = (s); i <= (n); i++)
#define rrep(i, n) for (int i = (n) - 1; i >= 0; i--)
typedef long long ll;
typedef unsigned long long ull;

int main()
{
	string S;
	int ans = 0;
	cin >> S;
	rep(i, 4) {
		if (S[i] == '+') ans++;
		else ans--;
	}
	cout << ans << endl;

	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define fi first
#define se second
#define pb push_back
#define eb emplace_back
#define sz(x) (int)(x).size()
using namespace std;
using ll = long long;
using P = pair<int, int>;
using vi = vector<int>;
using vc = vector<char>;
using vb = vector<bool>;
using vs = vector<string>;
using vll = vector<long long>;
using vp = vector<pair<int, int>>;
using vvi = vector<vector<int>>;
using vvc = vector<vector<char>>;
using vvll = vector<vector<long long>>;
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 (b<a) {a=b; return 1;} return 0;}

const int mod = 1000000007;
// const int mod = 998244353;
struct mint {
    long long x;
    mint(long long 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 { return mint(*this) += a;}
    mint operator-(const mint a) const { return mint(*this) -= a;}
    mint operator*(const mint a) const { return mint(*this) *= a;}
    mint pow(long long t) const {
        if (!t) return 1;
        mint a = pow(t>>1);
        a *= a;
        if (t&1) a *= *this;
        return a;
    }
    mint inv() const { return pow(mod-2);}
    mint& operator/=(const mint a) { return *this *= a.inv();}
    mint operator/(const mint a) const { return mint(*this) /= a;}
};
istream& operator>>(istream& is, const mint& a) { return is >> a.x;}
ostream& operator<<(ostream& os, const mint& a) { return os << a.x;}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    
    int n;
    cin >> n;
    vi a(n);
    rep(i, n) cin >> a[i];
    sort(a.begin(), a.end());
    bool flag = true;
    if (n%2 == 0) {
        for (int i = 0; i < n; i += 2) {
            if (a[i] == a[i+1] && a[i] == i+1) continue; 
            flag = false;
            break;
        }
    } else {
        if (a[0] != 0) flag = false;
        for (int i = 1; i < n; i += 2) {
            if (a[i] == a[i+1] && a[i] == 2*((i+1)/2)) continue;
            flag = false;
            break;
        }
    }
    if (flag) {
        cout << mint(2).pow(n/2) << endl;
    } else {
        cout << 0 << endl;
    }
}

Measured memory_bytes: 640
#include <iostream>
#include <bits/stdc++.h>
using namespace std;
typedef  long long int ll;
typedef long double db;
#define pb push_back
#define mp make_pair
#define ub(v,val) upper_bound(v.begin(),v.end(),val)
#define lb(v,val) lower_bound(v.begin(),v.end(),val)
#define sortv(vec) sort(vec.begin(),vec.end())
#define rev(p) reverse(p.begin(),p.end());
#define v vector
#define PI 3.1415926535
#define len length()
#define repc(i,s,e) for(ll i=s;i<e;i++)
#define np(str) next_permutation(str.begin(),str.end())
#define fi first
#define se second
#define mset(a,val) memset(a,val,sizeof(a));
#define mt make_tuple
#define repr(i,n) for(i=n-1;i>=0;i--)
#define rep(i,n) for( i=0;i<n;i++)
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
const int M = 1e9 + 7;
ll INF = 1e7;
ll n, m;

int main() {
	// your code goes here
	IOS;

#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif
	ll  i, j,  k, x, y,   N;
	char z;
	cin >> n;
	unordered_map<ll, v<ll>> u, d, l, r, u1, u2, r1, r2, l1, l2, d1, d2;
	rep(i, n) {
		cin >> x >> y >> z;
		if (z == 'U') {
			u[x].pb(y);
			u1[x - y].pb(x);
			u2[x + y].pb(x);

		}
		if (z == 'R') {
			r[y].pb(x);
			r1[(x - y)].pb(x);
			r2[x + y].pb(x);

		}
		if (z == 'D') {
			d[x].pb(y);
			d1[(x - y)].pb(x);
			d2[x + y].pb(x);

		}
		if (z == 'L') {
			l[y].pb(x);
			l1[(x - y)].pb(x);
			l2[x + y].pb(x);
		}
	}
	for (auto &dm : u) {
		sortv(dm.se);
	}
	for (auto &dm : u1) {
		sortv(dm.se);
	}
	for (auto &dm : u2) {
		sortv(dm.se);
	}
	for (auto &dm : r) {
		sortv(dm.se);
	}
	for (auto &dm : r1) {
		sortv(dm.se);
	}
	for (auto &dm : r2) {
		sortv(dm.se);
	}
	for (auto &dm : l) {
		sortv(dm.se);
	}
	for (auto &dm : l1) {
		sortv(dm.se);
	}
	for (auto &dm : l2) {
		sortv(dm.se);
	}
	for (auto &dm : d) {
		sortv(dm.se);
	}
	for (auto &dm : d1) {
		sortv(dm.se);
	}
	for (auto &dm : d2) {
		sortv(dm.se);
	}
	ll ans = INF;
	//u and d;

	for (auto dm : u) {
		x = dm.fi;
		for (auto dm2 : u[x]) {
			auto ind = ub(d[x], dm2);
			if (ind != d[x].end()) {
				ans = min(ans, (*ind - dm2) * 5);
			}

		}
	}
	//r and l
	for (auto dm : r) {
		x = dm.fi;
		for (auto dm2 : r[x]) {
			auto ind = ub(l[x], dm2);
			if (ind != l[x].end()) {
				ans = min(ans, (*ind - dm2) * 5);
			}

		}
	}
	//u and l
	for (auto dm : u1) {
		x = dm.fi;
		for (auto dm2 : u1[x]) {
			auto ind = ub(l1[x], dm2);
			if (ind != l1[x].end()) {
				ans = min(ans, (*ind - dm2) * 10);
			}
		}
	}
	//u and r
	for (auto dm : r2) {
		x = dm.fi;

		for (auto dm2 : r2[x]) {
			auto ind = ub(u2[x], dm2);
			if (ind != u2[x].end()) {
				ans = min(ans, (*ind - dm2) * 10);
			}
		}
	}
	//d and l
	for (auto dm : d2) {
		x = dm.fi;

		for (auto dm2 : d2[x]) {
			auto ind = ub(l2[x], dm2);
			if (ind != l2[x].end()) {
				ans = min(ans, (*ind - dm2) * 10);
			}
		}
	}
	//d and r
	for (auto dm : r1) {
		x = dm.fi;

		for (auto dm2 : r1[x]) {
			auto ind = ub(d1[x], dm2);
			if (ind != d1[x].end()) {
				ans = min(ans, (*ind - dm2) * 10);
			}
		}
	}
	if (ans == INF)
		cout << "SAFE";
	else cout << ans;






	return 0;
}



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

#define pb push_back
#define all(v) v.begin(), v.end()
#define sz(v) int(v.size())
#define pii pair<int, int>
#define mp make_pair
#define f first
#define ll long long
#define s second
#define vec vector<int>

using namespace std;

const int N = (int) 1e5 + 10;
const int M = (int) 1e6 + 10;
const int K = (int) 500 + 10;
const int mod1 = (int) 1e9 + 7;
const int mod2 = (int) 1e9 + 9; 

int a, b, c, d;

int f(int cur) {
	map<int, int> w;
	while (1) {
		if (cur < b) 
			return 0;
		if (w[cur]) 
			return 1;
		w[cur] = 1;
		if (cur <= c) 
			cur += d;
	}
}

int g() {
	return (1 + rand() % 3) * 2;
}

void add(pii &x, pii y) {
	x = mp((x.f + y.f) % mod1, (x.s + y.s) % mod2);
}

pii mult(pii x, pii y) {
	return mp(x.f * 1ll * y.f % mod1, x.s * 1ll * y.s % mod2);
}

const pii operator - (pii x, pii y) {
	x.f -= y.f;
	x.s -= y.s;
	if (x.f < 0) x.f += mod1;
	if (x.s < 0) x.s += mod2;
	return x;
}

const pii operator + (pii x, pii y) {
	x.f += y.f;
	x.s += y.s;
	if (x.f >= mod1) x.f -= mod1;
	if (x.s >= mod2) x.s -= mod2;
	return x;
}

pii p[40];

int main() {
	#ifdef sony
		freopen("input.txt", "r", stdin);
		freopen("output.txt", "w", stdout);
	#endif
	srand(time(0));
	string s = "";
	for (int i = 0; i < 5; i++) {
		int cnt = g();
		while (cnt--) {
			s += char(i + 'a');
		}
	}
	random_shuffle(all(s));
	//cout << s << "\n";
	int n;
	cin >> n >> s;
	p[0] = mp(1,1);
	for (int i = 1; i <= 2 * n; i++) {
		p[i] = mult(p[i - 1], mp(31, 31));
	}
	vector<pair<int, pii> > v1, v2;
	for (int i = 0; i < (1 << n); i++) {
		string ca = "", cb = "";
		for (int j = 0; j < n; j++) {
			if ((i >> j) % 2) {
				ca += s[j];
			} else {
				cb += s[j];
			}
		}
		pii ma = mp(0, 0), mb = mp(0, 0);
		for (int j = 0; j < sz(ca); j++) {
			add(ma, mult(p[j], mp(ca[j] - 'a' + 1, ca[j] - 'a' + 1)));
		}
		for (int j = 0; j < sz(cb); j++) {
			add(mb, mult(p[n - j - 1], mp(cb[j] - 'a' + 1, cb[j] - 'a' + 1)));
		}
		v1.pb(mp(sz(ca), ma - mb));
	}
	for (int i = 0; i < (1 << n); i++) {
		string ca = "", cb = "";
		for (int j = 0; j < n; j++) {
			if ((i >> j) % 2) {
				ca += s[n + j];
			} else {
				cb += s[n + j];
			}
		}
		pii ma = mp(0, 0), mb = mp(0, 0);
		for (int j = 0; j < sz(ca); j++) {
			add(ma, mult(p[j + n - sz(ca)], mp(ca[j] - 'a' + 1, ca[j] - 'a' + 1)));
		}
		for (int j = 0; j < sz(cb); j++) {
			add(mb, mult(p[sz(cb) - j - 1], mp(cb[j] - 'a' + 1, cb[j] - 'a' + 1)));
		}	
		v2.pb(mp(sz(ca), mb - ma));
	}
	sort(all(v1));
	sort(all(v2));
	ll ans = 0;
	for (auto i : v1) {
		ans += upper_bound(all(v2), mp(n - i.f, i.s)) - lower_bound(all(v2), mp(n - i.f, i.s));
	}
	cout << ans;
	return 0;
}

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

using namespace std;

const int INF = 1 << 30;

template <typename T>
bool chmin(T &a, const T &b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}

int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  int N, M;
  cin >> N >> M;
  map<pair<int, int>, vector<pair<pair<int, int>, int>>> G;
  for (int i = 0; i < M; i++) {
    int u, v, c;
    cin >> u >> v >> c;
    u--, v--;
    G[make_pair(u, c)].emplace_back(make_pair(make_pair(v, c), 0));
    G[make_pair(v, c)].emplace_back(make_pair(make_pair(u, c), 0));
    G[make_pair(u, c)].emplace_back(make_pair(make_pair(u, -1), 0));
    G[make_pair(v, c)].emplace_back(make_pair(make_pair(v, -1), 0));
    G[make_pair(u, -1)].emplace_back(make_pair(make_pair(v, c), 1));
    G[make_pair(v, -1)].emplace_back(make_pair(make_pair(u, c), 1));
  }
  deque<pair<int, pair<int, int>>> que;
  que.push_front(make_pair(0, make_pair(0, -1)));  // d, u, c
  set<pair<int, int>> st;
  vector<int> dist(N, INF);
  dist[0] = 0;
  while (!que.empty()) {
    auto q = que.front();
    que.pop_front();
    int d = q.first, u = q.second.first, a = q.second.second;
    if (st.find(make_pair(u, a)) != st.end()) continue;
    st.insert(make_pair(u, a));
    for (auto g : G[make_pair(u, a)]) {
      int v = g.first.first, b = g.first.second, c = g.second;
      if (st.find(make_pair(v, b)) != st.end()) continue;
      if (c == 0) {
        que.push_front(make_pair(d + c, make_pair(v, b)));
      } else {
        que.push_back(make_pair(d + c, make_pair(v, b)));
      }
      if (b == -1) chmin(dist[v], d + c);
    }
  }
  if (dist[N - 1] == INF) {
    cout << -1 << '\n';
  } else {
    cout << dist[N - 1] << '\n';
  }
  return 0;
}


Measured memory_bytes: 86016
def up(x):
    return x-1

n = int(input())
h = [int(x) for x in input().split()]

sum = 0

for j in range(max(h)):
    if h[0] <= 0:
        cnt = 0
    else:
        cnt = 1
    flag = 1
    for i in range(n):
        if flag == 1 and h[i] <= 0:
            flag = 0
        elif flag == 0 and h[i] > 0:
            flag = 1
            cnt += 1
    h = list(map(up, h))
    sum = sum + cnt

print(sum)

Measured memory_bytes: 3064