akhauriyash/Code-Regression huggingface dataset:
{-# LANGUAGE BangPatterns #-}
import           Control.Exception           (assert)
import           Control.Monad
import           Control.Monad.Primitive
import qualified Control.Monad.ST            as ST
import qualified Data.Array.IO               as IO
import qualified Data.Array.ST               as ST
import qualified Data.Array.Unboxed          as A
import           Data.Bits
import qualified Data.ByteString.Char8       as BS
import           Data.Char
import           Data.Foldable
import           Data.List
import qualified Data.Map.Strict             as Map
import           Data.Maybe
import qualified Data.Sequence               as Seq
import qualified Data.Set                    as Set
import qualified Data.Vector                 as VB
import qualified Data.Vector.Mutable         as VBM
import qualified Data.Vector.Unboxed         as V
import qualified Data.Vector.Unboxed.Mutable as VM
import           Debug.Trace

readInt = fst . fromJust . BS.readInt
readIntList = map readInt . BS.words
getInt = readInt <$> BS.getLine
getIntList = readIntList <$> BS.getLine
getIntVec n = V.unfoldrN n (BS.readInt . BS.dropWhile isSpace) <$> BS.getLine

readInteger = fst . fromJust . BS.readInteger
readIntegerList = map readInteger . BS.words
getInteger = readInteger <$> BS.getLine
getIntegerList = readIntegerList <$> BS.getLine

inf :: Int
inf = 10^18

quickSortVec l u arr
  | l >= u    = return ()
  | otherwise = do
      VM.unsafeSwap arr l ((u+l)`div`2)
      t <- VM.unsafeRead arr l
      let i = l
          j = u + 1
      nj <- loopVec t u i j arr
      VM.unsafeSwap arr l nj
      quickSortVec l (nj-1) arr
      quickSortVec (nj+1) u arr

loopVec !t !u !i !j arr = do
  ni <- doWhile i (+1)         (< t)
  nj <- doWhile j (subtract 1) (> t)
  if ni > nj
    then return nj
    else do VM.unsafeSwap arr ni nj
            loopVec t u ni nj arr
              where
                {-# INLINE doWhile #-}
                doWhile k op p
                  | nk > u    = return nk
                  | otherwise = do
                      x <- VM.unsafeRead arr nk
                      if p x then
                        doWhile nk op p
                        else
                        return nk
                        where
                          nk = op k
main = do
  n <- getInt

  as <- VM.new n
  bs <- VM.new n

  forM_ [0..(n-1)] $ \i -> do
    [a, b] <- getIntList
    VM.write as i a
    VM.write bs i b

  quickSortVec 0 (n-1) as
  quickSortVec 0 (n-1) bs

  as' <- V.freeze as
  bs' <- V.freeze bs

  let ans_e = let i = n `div` 2
                  j = n `div` 2 + 1
                  ai = as' V.! (i-1)
                  bi = bs' V.! (i-1)
                  aj = as' V.! (j-1)
                  bj = bs' V.! (j-1)
              in (bi+bj) - (ai+aj) + 1

      ans_o = let i = (n+1) `div` 2
                  ai = as' V.! (i-1)
                  bi = bs' V.! (i-1)
              in bi - ai + 1

      ans = if even n then ans_e else ans_o

  print ans


Measured memory_bytes: 11092
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
#define REP(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define REPR(i,n) for(int i=n; i>-1; --i)
#define ALL(a) (a).begin(),(a).end()
#define INIT(a,n,x); REP(i,(n)){ (a)[i]=(x); }
#define CINA(a,n); REP(i,(n)){ cin >> (a)[i]; }
#define INIT2(a,n,m,x); REP(i,(n)){ REP(j,(m)){(a)[i][j]=(x);} }
#define CINA2(a,n,m); REP(i,(n)){ REP(j,(m)){cin >> (a)[i][j];} }
#define Liny "Yes\n"
#define Linn "No\n"
#define LINY "YES\n"
#define LINN "NO\n"

int main(){
  int A,B; cin>>A>>B;
  cout << max({A+B,A-B,A*B});
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <string>
#include <math.h>
#include <numeric>
#include <boost/math/constants/constants.hpp>
#include <boost/math/common_factor_rt.hpp>

using namespace std;
#define ll long long
#define rep(i, n) for(int i = 0;i < n;i++)
#define FOR(i, n, m) for(int i=n; i<m; ++i)

int main(){
  ll N;
  cin >> N;
  double a[1000];
  double b[1000];
  double sum=0;
  rep(i,N) cin >> a[i];
  
  rep(i,N) sum+=(1/a[i]);
  
  cout << 1/sum << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
#define all(x) (x).begin(),(x).end()
#define SZ(x) ((int)(x).size())
#define bit(n) (1<<(n))
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vi> vvi;
typedef vector<bool> vb;
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/gcd(a,b)*b;}
int const INF = 1001001001;


// modint: mod 計算を int を扱うように扱える構造体
template<int MOD> struct Fp {
long long val;
constexpr Fp(long long v = 0) noexcept : val(v % MOD) {
if (val < 0) val += MOD;
}
constexpr int getmod() { return MOD; }
constexpr Fp operator - () const noexcept {
return val ? MOD - val : 0;
}
constexpr Fp operator + (const Fp& r) const noexcept { return Fp(*this) += r; }
constexpr Fp operator - (const Fp& r) const noexcept { return Fp(*this) -= r; }
constexpr Fp operator * (const Fp& r) const noexcept { return Fp(*this) *= r; }
constexpr Fp operator / (const Fp& r) const noexcept { return Fp(*this) /= r; }
constexpr Fp& operator += (const Fp& r) noexcept {
val += r.val;
if (val >= MOD) val -= MOD;
return *this;
}
constexpr Fp& operator -= (const Fp& r) noexcept {
val -= r.val;
if (val < 0) val += MOD;
return *this;
}
constexpr Fp& operator *= (const Fp& r) noexcept {
val = val * r.val % MOD;
return *this;
}
constexpr Fp& operator /= (const Fp& r) noexcept {
long long a = r.val, b = MOD, u = 1, v = 0;
while (b) {
long long t = a / b;
a -= t * b; swap(a, b);
u -= t * v; swap(u, v);
}
val = val * u % MOD;
if (val < 0) val += MOD;
return *this;
}
constexpr bool operator == (const Fp& r) const noexcept {
return this->val == r.val;
}
constexpr bool operator != (const Fp& r) const noexcept {
return this->val != r.val;
}
friend constexpr ostream& operator << (ostream &os, const Fp<MOD>& x) noexcept {
return os << x.val;
}
friend constexpr Fp<MOD> modpow(const Fp<MOD> &a, long long n) noexcept {
if (n == 0) return 1;
auto t = modpow(a, n / 2);
t = t * t;
if (n & 1) t = t * a;
return t;
}
};

const int MOD = 1000000007;
using mint = Fp<MOD>;

// 愚直計算による二項係数計算
mint com(long long n, long long r) {
mint res = 1;
for (long long i = 0; i < r; ++i) {
res *= (n-i);
res /= (i+1);
}
return res;
}
// 残x個をp個のグループで山分け
mint res(long long x, long long p) {
    return com(x+p-1, x);
}

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

ll N,K;
cin >> N >> K;

rrep(i,K) {
    cout << com(N-K+1, i) * com(K-1, i-1) << endl;
}

return 0;
}

Measured memory_bytes: 256
function Main(input){
	input = input.split("\n")[0];
  var len = input.length;
  var min = 1000;
  for(var i = 0; i < len - 2; i++){
  	var a = ~~input[i];
    var b = ~~input[i+1];
    var c = ~~input[i+2];
    var abs = a*100 + b*10 + c - 753;
    if(abs < 0)abs *= -1;
    if(abs < min)min = abs;
  }
  return min;
}

// If you are interested in the algorithms I used, 
// there is no need to read down from this line.

((b,c,d)=>"undefined"!=typeof require?console.log(Main(require("fs").readFileSync("/dev/stdin","utf8"))):[b=b.split("\n").slice(1,-1).join("\n"),c=function(){try{return Main(b)}catch(f){return f.stack||f.message}}(),d=typeof c,"string"==d||(c=JSON.stringify(c)),$("<form>").append([[10,b],0,[1,d],0,[10,c]].map(f=>$(f?"<textarea>":"<br>",f&&{rows:f[0],cols:40,text:f[1]}))).appendTo("body")])(`
1234567876
`);

Measured memory_bytes: 22076
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()

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

const ll mod =  1000000007;  //出力は (ans % mod + mod) % mod  (負の剰余を正にする)
const int inf = 1e9;
const long long INF = 1LL << 60;   // INF = 1152921504606846976
const double PI = 3.1415926535897932;

int main()
{
    int k,x; cin >> k >> x;
    if(k * 500 >= x) cout << "Yes" << endl;
    else cout << "No" << endl;
}


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

int main(){
    int64_t a, b, c, d, _;
    cin >> a >> b >> _ >> c >> d >> _ >> _;
    int64_t ans = a/2*2 + b + c/2*2 + d/2*2;
    if(a && c && d){
        a--; c--; d--;
        int64_t ans2 = a/2*2 + b + c/2*2 + d/2*2 + 3;
        ans = max(ans, ans2);
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
n=int(input())
a=[int(input()) for _ in range(n)]
for i,x in enumerate(a):
  if x<=i:
    pass
  else:
    print(-1)
    exit()
ans=0
pre=0
for x in a[::-1]:
  if x>=pre:
    ans+=x
  if x<pre-1:
    print(-1)
    exit()
  pre=x
print(ans)


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

int main() {
	int R, C, K;
	cin >> R >> C >> K;
	vector<int> r(K), c(K), v(K);
	map<pair<int, int>, int> mp;
	for (int i=0;i<K;i++) {
		cin >> r[i] >> c[i] >> v[i];
		r[i]--;
		c[i]--;
		pair<int, int> p = make_pair(r[i], c[i]);
		mp[p] = v[i];
	}

	vector<vector<vector<long long>>> dp(R+1, vector<vector<long long>>(C+1, vector<long long>(4, 0LL)));
	for (int i=0;i<R;i++) {
		for (int j=0;j<C;j++) {
			dp[i+1][j+1][0] = max(dp[i+1][j+1][0], dp[i+1][j][0]);
			dp[i+1][j+1][1] = max(dp[i+1][j+1][1], dp[i+1][j][1]);
			dp[i+1][j+1][2] = max(dp[i+1][j+1][2], dp[i+1][j][2]);
			dp[i+1][j+1][3] = max(dp[i+1][j+1][3], dp[i+1][j][3]);

			dp[i+1][j+1][0] = max(dp[i+1][j+1][0], dp[i][j+1][0]);
			dp[i+1][j+1][0] = max(dp[i+1][j+1][0], dp[i][j+1][1]);
			dp[i+1][j+1][0] = max(dp[i+1][j+1][0], dp[i][j+1][2]);
			dp[i+1][j+1][0] = max(dp[i+1][j+1][0], dp[i][j+1][3]);
			pair<int, int> p = make_pair(i, j);
			if (mp.count(p)) {
				dp[i+1][j+1][1] = max(dp[i+1][j+1][1], dp[i+1][j][0]+mp[p]);
				dp[i+1][j+1][2] = max(dp[i+1][j+1][2], dp[i+1][j][1]+mp[p]);
				dp[i+1][j+1][3] = max(dp[i+1][j+1][3], dp[i+1][j][2]+mp[p]);

				dp[i+1][j+1][1] = max(dp[i+1][j+1][1], dp[i][j+1][0]+mp[p]);
				dp[i+1][j+1][1] = max(dp[i+1][j+1][1], dp[i][j+1][1]+mp[p]);
				dp[i+1][j+1][1] = max(dp[i+1][j+1][1], dp[i][j+1][2]+mp[p]);
				dp[i+1][j+1][1] = max(dp[i+1][j+1][1], dp[i][j+1][3]+mp[p]);
			}
		}
	}

	long long ans = 0LL;
	for (int i=0;i<4;i++) {
		ans = max(ans, dp[R][C][i]);
	}
	cout << ans << endl;
}

Measured memory_bytes: 650884
N, P = map(int, input().split())
if N==1:
    print(P)
    exit()
# 素因数分解
def prime_decomposition(n):
    i = 2
    table = []
    while i * i <= n:
        while n % i == 0:
            n //= i
            table.append(i)
        i += 1
    if n > 1:
        table.append(n)
    return table
L = prime_decomposition(P)

cnt = 0
ans = 1
vp = 0
for v in L:
    if vp==v:
        cnt += 1
        if cnt == N:
            cnt = 0
            ans *= v
    else:
        cnt = 1
        vp = v
#print(L)
print(ans)




Measured memory_bytes: 3064
#include<bits/stdc++.h>
using namespace std;
int main(){
  int n,a[101],sum=0;
  cin>>n;
  for(int i=0;i<n;i++){
    cin>>a[i];
    if(i%2==0&&a[i]%2!=0)sum++;
  }
  cout<<sum;
  return 0;
}

Measured memory_bytes: 3616
#include <stdio.h>
int main(void)
{

        int a,b,c,n,m;

        scanf("%d%d%d",&a,&b,&c);

        n=a; m=b;
        if(a>b && a>c){n=c;m=b;}

        if(b>a && b>c){n=a;m=c;}

        if(c>a && c>b){n=a;m=b;}

        printf("%d\n",n*m/2);

        return 0;
}

Measured memory_bytes: 128
#include<bits/stdc++.h>
using namespace std;
long long n,t,ans=0;

int main() 
{   cin>>n;
    if(n==2)
    {
        cout<<1<<endl;
        return 0;
    }
    t=sqrt(n);
    for(long long i=2;i<=t;++i)
        if(n%i==1)
            ans+=2ll;
    if(t*t==n-1 && n%t==1)
        --ans;
    for(long long i=2;i<=t;++i) 
    {
        if(n%i!=0)
            continue;
        long long nn=n;
        while(nn && nn%i==0)
        {
            nn/=i;
            if(nn%i==1)
            {
                ++ans;
                break;
            }
        }
    }
    cout<<ans+2<<endl;
    return 0;
}

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

int main(){
  int a = 0;
  string s;
  cin >> s;
  if(s[0] == 'R' && s[1] == 'R' && s[2] == 'R'){
    a = 3;
  }else if(s[0] == 'R' && s[1] == 'R'){
    a = 2;
  }else if(s[1] == 'R' && s[2] == 'R'){
    a = 2;
  }else if(s[2] == 'R' && s[3] == 'R'){
    a = 2;
  }else if(s[0] == 'R' || s[1] == 'R' || s[2] == 'R'){
    a = 1;
  }else{
    a = 0;
  }
  cout << a << endl;
}

  

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

int main() {
  int N,K;
  cin >> N >> K;
  vector<int> H(N);
  if(K>=N) {
    cout << 0 << endl;
    return 0;
  }
  else {
    for(int i =0; i<N; i++) {
      cin >> H.at(i);
    }
  }
  sort(H.begin(),H.end());
  long long ans = 0;
  for(int i=0; i<N-K; i++) ans += H.at(i);
  cout << ans << endl;
}

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

int main() {
    int n, ans = 0, temp = 0;
    string str;
    cin >> n >> str;
    rep(i, n) {
        if(str.at(i) == 'I') temp++;
        else if(str.at(i) == 'D') temp--;
        ans = max(ans, temp);
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
/*
				C++
				encoding: UTF-8
				Modified: <07/Jul/2019 06:31:46 PM>

				✪ H4WK3yE乡
				Mohd. Farhan Tahir
				Indian Institute Of Information Technology (IIIT), Gwalior
*/

#include <bits/stdc++.h>

using namespace std;

// clang-format off

#define         ll                     long long
#define         mod                    1000000007
#define         ve                     vector
#define         pb                     push_back
#define         umap                   unordered_map
#define         endl                   "\n";
#define         ff                     first
#define         ss                     second
#define         pii                    pair<int, int>
#define         len(v)                 int(v.size())
#define         all(v)                 v.begin(), v.end()
#define         reset(a, b)            memset(a, b, sizeof(a));
#define         sum(v)                 accumulate(v.begin(), v.end(), (ll)0);
#define         pr1(x)                 cout<<x<<"\n"
#define         pr2(x, y)              cout<<x<<" "<<y<<"\n"
#define         pr3(x, y, z)           cout<<x<<" "<<y<<" "<<z<<"\n"
#define         prv(v, s, n)           fr(i, s, n) cout<<v[i]<<" "; cout<<"\n"
#define         fr(i, s, n)            for (ll i = s ; i < n ; ++i)
#define         dfr(i, s, n)           for (ll i = s ; i > n ; --i)

// clang-format on

ll n, k;
const int N = 1e5 + 5;
ve< ll > graph[N];
ll ans = 1;
ll vis;

void dfs (ll node, ll parent) {
	if (node == 1) {
		ans *= k;
	}
	ll curr = 1;
	if (node != 1) curr += 1;
	for (ll to : graph[node]) {
		if (to == parent) continue;
		ans *= (k - curr);
		curr++;
		ans %= mod;
		dfs (to, node);
	}
}

signed main () {
	ios_base::sync_with_stdio (false), cin.tie (nullptr);
	cin >> n >> k;
	fr (i, 1, n) {
		ll u, v;
		cin >> u >> v;
		graph[u].pb (v);
		graph[v].pb (u);
	}

	dfs (1, 1);
	pr1 (ans);
	return 0;
}


Measured memory_bytes: 10368
s = input()
if s[0] == 'A' and s[2:-1].count('C') == 1:
    for i in range(1,len(s)):
        if s[i].islower() == True:
            continue
        else:
            if s[i] == 'C':
                continue
            else:
                print('WA')
                exit()
else:
    print('WA')
    exit()
print('AC')

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

# define C continue;
# define R return

# define D double
# define I insert
# define ll long long
# define ld long double

# define ull unsigned long long
# define ui unsigned int

# define pb push_back
# define pf push_front

# define vi vector < int >
# define vc vector < char >
# define vs vector < string >
# define vb vector < bool >
# define vd vector < D >
# define vll vector < ll >
# define vull vector < ull >
# define vld vector < ld >
# define PQ priority_queue

# define vvi vector < vector < int > >
# define vvb vector < vector < bool > >
# define vvc vector < vector < char > >
# define vvs vector < vs >
# define vvll vector < vector < ll > >
# define vvd vector < vector < D > >
# define vvld vector < vector < ld > >

# define all(v) (v).begin() , (v).end()
# define allrev(v) (v).rbegin() , (v).rend()
# define allcomp(v) v.begin() , v.end() , comp
# define allrevcomp(v) v.rbegin() , v.rend() , comp

# define pii pair < int , int >
# define pll pair < ll , ll >
# define pld pair < ld , ld >
# define pDD pair < D , D >

# define vpld vector < pld >
# define vpii vector < pii >
# define vpll vector < pll >
# define vpDD vector < pDD >

# define vvpii vector < vector < pii > >
# define F first
# define S second
# define mp make_pair

# define dist(a,b,p,q) sqrt((p-a)*(p-a) + (q-b)*(q-b))

# define pp(n) printf("%.10Lf",n);
# define line cout<<"\n";
# define fast ios_base::sync_with_stdio(false) ; cin.tie(0) ; cout.tie(0);

# define fr(a,b) for(int i = a; i < b; i++)
# define rep(i,a,b) for(int i = a; i < b; i++)

string vow = "aeiou";
int month[] = {-1, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};

const int dxhorse[] = {-2, -2, -1, -1, 1, 1, 2, 2};
const int dyhorse[] = {1, -1, 2, -2, 2, -2, 1, -1};

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

const ld pie = 3.1415926535897932384626 ;
const ll mod = 1e9 + 7 ;



void solve(){
    string s;
    cin >>s;
    int freq[26]={0};
    rep(i,0,s.size()) {
        ++freq[s[i]-'a'];
    }

    for(int i=0;i<26;i++){

        if(freq[i]%2!=0){
            cout << "No";
            return;


    }
    }
    cout << "Yes";
    line


}

int main(){
	fast
	int t=1;
	//cin >> t;
	while(t--){
             solve();
    }

	R 0;
}


Measured memory_bytes: 3616
#include <bits/stdc++.h>
using namespace std;
typedef unsigned long long ull;
typedef long long ll;
typedef pair<int, int> P;
map <int,int> mp;
vector<int> V;
#define INF (1<<29)
#define INFLL (1ll<<58)
#define EPS (1e-10)
static const int MAX=1e5;
static const int MOD=1e9+7;
static const int NMAX=50;
static const int MMAX=50;
int dx[4]={0,1,0,-1},dy[4]={-1,0,1,0};
string s;
int main(){
    cin.tie(0);  ios::sync_with_stdio(false);
    
    cin>>s;
    
    for(int i=0;i<4;i++) cout<<s[i];
    cout<<" ";
    for(int i=4;i<s.size();i++) cout<<s[i];
    cout<<"\n";
    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 n = sc.nextInt();
     int m = sc.nextInt();
     int[] a = new int[n];
     int sum=0;
     for(int i=0;i<n;i++){
       a[i]=sc.nextInt();
       sum+=a[i];
     }
     quick_sort(a,0,n-1);
     double border = (double)(sum/(4.0*m));
     if(a[n-m]<border){
       System.out.println("No");
     }else{
       System.out.println("Yes");
     }
   }
   static void quick_sort(int[] d, int left, int right) {
        if (left>=right) {
            return;
        }
        int p = d[(left+right)/2];
        int l = left, r = right, tmp;
        while(l<=r) {
            while(d[l] < p) { l++; }
            while(d[r] > p) { r--; }
            if (l<=r) {
                tmp = d[l]; d[l] = d[r]; d[r] = tmp;
                l++; r--;
            }
        }
        quick_sort(d, left, r);  // ピボットより左側をクイックソート
        quick_sort(d, l, right); // ピボットより右側をクイックソート
    }
}

Measured memory_bytes: 23124
import java.util.*;

class Main{
	public static void main(String args[]){
		int i;
		int stacksize = 100;
		String temp;
		int calc;
		int a,b;
		Deque<Integer> stack = new ArrayDeque<Integer>();
		String separator = System.getProperty("line.separator");
		Scanner sc1 = new Scanner(System.in);
		String str = sc1.nextLine();
		Scanner sc2 = new Scanner(str);
		sc2.useDelimiter(" ");
		
		while(sc2.hasNext()){
			temp = sc2.next();
			if(temp.equals("+")){
				calc = stack.removeFirst() + stack.removeFirst();
				stack.addFirst(calc);
			}else if(temp.equals("-")){
				a = stack.removeFirst();
				b = stack.removeFirst();
				calc = b - a;
				stack.addFirst(calc);
			}else if(temp.equals("*")){
				calc = stack.removeFirst() * stack.removeFirst();
				stack.addFirst(calc);
			}else{
				stack.addFirst(Integer.parseInt(temp));
			}
		}
		System.out.println(stack.removeFirst());
	}
}

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

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

vector<int> A(N), B(N), C(N - 1);

for (int i = 0; i < N; i++) cin >> A.at(i);
for (int i = 0; i < N; i++) cin >> B.at(i);
for (int i = 0; i < N - 1; i++) cin >> C.at(i);

int ans = 0;

for (int i = 0; i < N; i++) {
  ans += B.at(i);
}

for (int i = 1; i < N; i++) {
  if (A.at(i) - 1 == A.at(i - 1)) {
    ans += C.at(A.at(i) - 2);
  }
}

cout << ans << endl;

}


Measured memory_bytes: 256
using System;
using static System.Console;

class Program
{
    static long count(string s)
    {
	long ans = 0;
	char curr = '*';
	long nseries = 0;
	for (int i = 0; i < s.Length; i++)
	{
	    if (s[i] == curr) nseries++;
	    else
	    {
		ans += nseries / 2;
		curr = s[i];
		nseries = 1;
	    }
	}

	ans += nseries / 2;
	return ans;
    }

    public static void Main()
    {
	string s = ReadLine();
	long k = long.Parse(ReadLine());

	int L = s.Length;
	if (s[0] != s[L-1])
	{
	    WriteLine(count(s) * k);
	}
	else
	{
	    int n1 = 0;
	    while (n1 < L && s[n1] == s[0]) n1++;
	    int n3 = 0;
	    if (n1 < L)
		while (n3 < L && s[L-1-n3] == s[L-1]) n3++;
	    int n2 = L - n1 - n3;

	    if (n1 == L)
	    {
		WriteLine((n1 * k) / 2);
	    }
	    else
	    {
		string t = s.Substring(n1, n2);
		long ans = n1/2 + count(t)*k + (n3+n1)/2*(k-1) + n3/2;
		WriteLine(ans);
	    }
	}
    }
}


Measured memory_bytes: 11092
#include <iostream>

using namespace std;

#define out(v) cout<<v<<"\n"
#define rep(i,n) for(int i=0;i<(n);++i)

const int MOD = 1e9+7;
using ll = long long;

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

  ll x[N], y[M];
  rep(i, N)
    cin >> x[i];
  rep(i, M)
    cin >> y[i];

  ll X = 0, Y = 0;
  rep(i, N) {
    X += i * x[i] - (N-1-i)*x[i];
    X %= MOD;
  }
  rep(i, M) {
    Y += i * y[i] - (M-1-i)*y[i];
    Y %= MOD;
  }
  cout << (X * Y) % MOD << "\n";

  return 0;
}


Measured memory_bytes: 1792
def main():
  n = int(input())
  dict = {}
  for i in range(n):
    s = input()
    dict.setdefault(s, 0)
    dict[s] += 1
  max_val = 0
  ans_ls = []
  for kv in dict.items():
    if kv[1] > max_val:
      max_val = kv[1]
      ans_ls = [kv[0]]    
    elif kv[1] == max_val:
      ans_ls.append(kv[0])
  ans_ls = sorted(ans_ls)
  for name in ans_ls:
    print(name)
 
 
if __name__ == '__main__':
  main()

Measured memory_bytes: 99416
from copy import copy
n, k = map(int, input().split())
p = list(map(int,input().split()))
c = list(map(int, input().split()))
di = {}
for i in range(n):
    di[i+1] = False
l = 1
cc = 0
per = [] # ループの順番
while cc < n:
    tmp = []
    while True:
        if di[l]:
            break
        else:
            tmp.append(l)
            di[l] = True
            cc += 1
            l = p[l-1]
    per.append(tmp)
    for i in range(n):
        if not di[i+1]:
            l = p[i]
#print(per)
dd = {} # 何個目のループに属するか
for i in range(n):
    dd[i+1] = 0
for i in range(len(per)):
    for j in per[i]:
        dd[j] = i
#print(dd)
su = [] # ループ１週の和
for i in range(len(per)):
    tmp = 0
    for j in per[i]:
        tmp += c[j-1]
    su.append(tmp)
#print(su)
s2 = [] # ループ１週何個か
for i in range(len(per)):
    s2.append(len(per[i]))
#print(s2)
ans = -1*(10**10)
#d2 = {} # per[dd]の中でなんばんめにあるか(0インデックス)
#for i in range(len(per)):
#    for j in range(len(per[i])):
#        d2[per[i][j]] = j
#print(d2)
aa = []
for i in range(n):
    loop = dd[i+1]
    w = i+1
    kk = copy(k)
    if k < s2[loop]:
        tmp = 0
        m = -10**9
        for j in range(k):
            w = p[w-1]
            tmp += c[w-1]
            aa.append(tmp)
    else:
        if su[loop] <= 0:
            tmp = 0
            m = -10**9
            for j in range(s2[loop]+1):
                w = p[w-1]
                tmp += c[w-1]
                aa.append(tmp)
        else:
            m_loop = kk // (s2[loop])
            m_loop -= 1
            kk -= m_loop * s2[loop]
            tmp = su[loop]*m_loop
            m = -10**9
            for j in range(kk):
                w = p[w-1]
                tmp += c[w-1]
                if c[w-1] <= 0:
                    continue
                aa.append(tmp)
print(max(aa))


Measured memory_bytes: 742712
f=lambda:map(int,input().split())
R,C,K=f()
g=[[0]*(C+1) for _ in range(R+1)]
for _ in range(K):
  r,c,v=f()
  g[r][c]=v
dp=[[[0]*(C+2) for _ in range(R+2)] for _ in range(4)]
for i in range(1,R+1):
  for j in range(1,C+1):
    for k in range(3,-1,-1):
      if k: dp[k][i][j]=max(dp[k][i][j],dp[k-1][i][j]+g[i][j])
      dp[0][i+1][j]=max(dp[0][i+1][j],dp[k][i][j])
      dp[k][i][j+1]=max(dp[k][i][j+1],dp[k][i][j])
print(max(dp[k][R][C] for k in range(4)))

Measured memory_bytes: 429116
#include <bits/stdc++.h>
#include <boost/multiprecision/cpp_int.hpp>

#define rep(i,a,b) for(int i=a;i<b;i++)
#define rrep(i,b,a) for(int i=b;i>=a;i--)
#define fori(a) for(auto i : a )
#define all(a) begin(a), end(a)
#define set(a,b) memset(a,b,sizeof(a))
#define sz(a) a.size()
double pi=acos(-1);
#define ll long long
#define ull unsigned long long
#define pb push_back
#define PF push_front //deque
// #define mp make_pair
#define pq priority_queue
const ll mod=1000000007;
#define f first
#define s second
#define pii pair< int, int >
#define vi vector<int>
#define vpii vector<pii>
#define debug(v) for(auto i:v) cout<<i<<" ";
#define tc int t; cin >> t; while(t--)

using namespace boost::multiprecision;
using namespace std;
void optimizeIO(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
}


const int N=1000005;
ll fact[N],invfact[N];
ll power(ll x,ll y){
  if(y<=0) return 1LL;
  ll z=power(x,y/2);
  if(y%2) return (((z*z)%mod)*x)%mod;
  return (z*z)%mod;
}

void pre(){
  fact[0]=invfact[0]=invfact[1]=fact[1]=1;
  rep(i,2,N) fact[i]=(i*fact[i-1])%mod;
  rep(i,2,N) invfact[i]=(invfact[i-1]*power(i,mod-2))%mod;
}
ll nCr(ll n,ll k){ return (((fact[n]*invfact[n-k])%mod)*invfact[k])%mod; }



const int N1=1e6+1;
vector<int> isprime(N1,1),prime;
void seive(){
  rep(i,2,sqrt(N1)+1){
      if(isprime[i]){
        for(int j=i*i;j<N1;j+=i) isprime[j]=0;
        prime.pb(i);
      }
  }
  rep(i,sqrt(N1)+1,N1) if(isprime[i]) prime.pb(i);
}



struct dsu {
    vector<int> par, rank;
    dsu(int n): par(n+1), rank(n+1) {
        for (int i = 0; i <= n; i++) {
            par[i] = i;
            rank[i]= 1;
        }
    }
    int root(int a) {
        if (a == par[a]) return a;
        return par[a] = root(par[a]);
    }
    void merge(int a, int b) {
        a = root(a);
        b = root(b);
        if (a == b) return;
        if (rank[a] > rank[b]) swap(a, b);
        par[b] = a;
    }
    set<int> parent(int n){
        set<int> s;
        for(int i=1;i<=n;i++){
            s.insert(root(i));
        }
        return s;
    }
};

void solve(){
  int n;
  cin>>n;
  ll cnt=0;
  vector<ll> factors(n+1,1);
  rep(i,2,n+1)  for(int j=i;j<=n;j+=i) factors[j]++;
  rep(i,1,n) cnt+=factors[i];
  cout<<cnt<<endl;
}

int main(){
    optimizeIO();
    int r=1;
    // pre();
    {solve();}
}


Measured memory_bytes: 14696
#include<bits/stdc++.h>
#define rep(i,a,b) for (int i=(a); i<=(b); i++)
#define per(i,a,b) for (int i=(a); i>=(b); i--)
using namespace std;
typedef long long ll;

ll a, b, ans;
int mx = -1, mx2;

int main() {
	cin >> a >> b;
	if (a == b) {
		puts("1");
		return 0;
	}
	per (i, 60, 0)
		if ((a >> i & 1) && (b >> i & 1)) {
			a -= 1ll << i;
			b -= 1ll << i;
		}
		else if ((a >> i & 1) ^ (b >> i & 1))
			break;
	per (i, 60, 0) if (b >> i & 1) {
		if (mx == -1) mx = i;
		else { mx2 = i + 1; break; }
	}
	ans = (1ll << mx) - a;
	ans += (1ll << mx) - max(0ll, a - (1ll << mx2));
	cout << ans;
	
	return 0;
}

Measured memory_bytes: 256
from math import atan,pi

a,b,x=map(int,input().split())

if b-x/a**2 <= x/a**2:print(atan((b-x/a**2)/(a/2))*(180/pi))
else:
  y = x/a*2/b
  print(atan(b/y)*(180/pi))

Measured memory_bytes: 9372
#define _USE_MATH_DEFINES
#include<iostream>
#include<algorithm>
#include<string>
#include<iomanip>
#include<cmath>
#include<vector>
#include<deque>
#include<queue>
#include<map>
#include<set>
#define ll long long
#define str string
#define ld long double
#define vec vector
#define vll vec<ll>
#define rep(i,a,b) for(ll i=a;i<b;i++)
#define rrep(i,b,a) for(ll i=b;i>=a;i--)
#define ALL(a) a.begin(),a.end()
#define rALL(a) a.rbegin(),a.rend()
#define kai "\n"
#define yuque priority_queue
#define pub push_back
#define pob pop_back
#define puf push_front
#define pof pop_front
#define mie min_element
#define mae max_element
#define tos to_string
#define sep setprecision
#define lob lower_bound
#define upb upper_bound
#define nep next_permutation
#define MOD 1000000007ll
#define MIN (1e-10)
#define equal(a,b) (abs((a)-(b))<MIN)
#define v2 ten
#define chokusen senbun
#define tenten senbun
#define takaku vec<ten>
using namespace std;
void solve();
int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	cout<<fixed;
	solve();
}
struct pea{
	ll f,s;
	bool operator<(const pea &p)const{
		return f!=p.f?f<p.f:s<p.s;
	};
};
struct tri{
	ll f,s,t;
	bool operator<(const tri &p)const{
		if(f!=p.f)return f<p.f;
		if(s!=p.s)return s<p.s;
		return t<p.t;
	};
};
class ten{
public:
	ld x,y;
	ten operator+(ten p){return{x+p.x,y+p.y};}
	ten operator-(ten p){return{x-p.x,y-p.y};}
	ten operator*(ld k){return{k*x,k*y};}
	ten operator/(ld k){return{x/k,y/k};}
	ld abs(){return sqrt(abs2());}
	ld abs2(){return x*x+y*y;};
	bool operator<(const ten &p)const{return x!=p.x?x<p.x:y<p.y;};
	bool operator==(const ten &p)const{return (-MIN<x-p.x)&&(x-p.x<MIN)&&(-MIN<y-p.y)&&(y-p.y<MIN);};
	ld naiseki(v2 b){return x*b.x+y*b.y;}
	ld gaiseki(v2 b){return x*b.y-y*b.x;}
};
struct senbun{ten p1,p2;};
struct en{ten o;ld r;};
ll lcm(vector<ll> a){
	ll n;
	rep(i,1,a.size()){
		n=a[i-1]*a[i];
		ll k=a[i-1]%a[i];
		while(k!=0){
			a[i-1]=a[i];
			a[i]=k;
			k=a[i-1]%a[i];
		}
		n/=a[i];
		a[i]=n;
	}
	return n;
}
void solve(){
	ll n;cin>>n;
	vll a(n);
	rep(i,0,n)cin>>a[i];
	cout<<lcm(a)<<kai;
}


Measured memory_bytes: 3212
#include <iostream>
#include <algorithm>

#define LIM 2000000000
using namespace std;
typedef long long ll;

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

int main(void)
{
    ll L,R,mul,m = 2020;
    cin >> L >> R;
    R = R < L+2019 ? R : L+2019;
    for(ll i = L; i < R; i++) {
        for(ll j = i + 1; j <= R; j++) {
            mul = ((i % 2019)*(j % 2019)) % 2019;
            m = min(m, mul);
        }
    }
    cout << m << endl;

}


Measured memory_bytes: 256
string=input()
x=int(string[:2]);y=int(string[2:])
if 1<=x<=12 and 1<=y<=12:
    print("AMBIGUOUS")
elif 1<=x<=12:
    print("MMYY")
elif 1<=y<=12:
    print("YYMM")
else:
    print("NA")


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

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

    int n;
    cin>>n;
    int i;
   
    std::vector<int> v(100000000,0);

    int x,y,z;
    int br=0;
    for (x=1;x*x<=10000;x++) {

        if (x*x>n) break;

        for (y=1;y*y<=10000;y++) {

            if (x*x+y*y+x*y>n) break;

            for (z=1;z*z<=10000;z++) {
                if (x*x+y*y+z*z+x*y+y*z+z*x>n) break;
                v[x*x+y*y+z*z+x*y+y*z+z*x]++;
            }
        }
    }

    for (i=1;i<=n;i++)
        cout<<v[i]<<"\n";


    return 0;
}

Measured memory_bytes: 393904
N = int(input())
A = [int(input()) for _ in range(N)]
m = 0
ans = 0
for i in A:
  num = i + m
  d = num // 2
  if num % 2 == 0 or i == 0:
    m = 0
  else:
    m = 1
  ans += d
#  print(d, m, ans)
print(ans)

Measured memory_bytes: 7072
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
int main(void){
    ld x1, y1, x2, y2;
    cin >> x1 >> y1 >> x2 >> y2;
    ld zx = abs(x1 - x2), zy = abs(y1 - y2);
    ld ans = sqrt(zx * zx + zy * zy);
    cout << fixed << ans << endl;
    return 0;
}


Measured memory_bytes: 3284
n, k = map(int, input().split())
p = [int(i) for i in input().split()]
t = list(input())
a = 0
for i in range(n):
    if i < k or t[i] != t[i - k]:
        a += p["spr".index(t[i])]
    else:
        t[i] = "q"
print(a)

Measured memory_bytes: 4084
#include<stdio.h>

int main(){
    int a,b;
    int i=0;
    int r,tmp;
    scanf("%d%d",&a,&b);
    if(a<b){
    tmp = a;
    a = b;
    b = tmp;
  }
 
  /* ユークリッドの互除法 */
  r = a % b;
  while(r!=0){
    a = b;
    b = r;
    r = a % b;
  }

  printf("%d",b);
  printf("\n");
  return 0;
}



Measured memory_bytes: 2084
#include <cstdio>
#include <vector>
using namespace std;

int main() {
    int n, l;
    scanf("%d %d", &n, &l);
    vector<int> len(n);
    for (int i = 0; i < n; ++i) {
        scanf("%d", &len[i]);
    }

    int pick = -1;
    for (int i = 0; i + 1 < n; ++i) {
        if (len[i] + len[i + 1] >= l) {
            pick = i;
            break;
        }
    }
    if (pick == -1) {
        printf("Impossible\n");
        return 0;
    }

    printf("Possible\n");
    for (int i = 0; i < pick; ++i) {
        printf("%d\n", i + 1);
    }
    for (int i = n - 2; i > pick; --i) {
        printf("%d\n", i + 1);
    }
    printf("%d\n", pick + 1);
    return 0;
}

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

int main() {
  int N;
  cin >> N;
  vector< int > ans(N,0);
  REP(i,N-1) {
    int c,s,f;
    cin >> c >> s >> f;
    REP(j,i+1) {
      if (ans[j] > s ) {
        if (ans[j] % f == 0)
          ans[j] += c;
        else
          ans[j] += f - ans[j] % f + c;
      } else {
        ans[j] = s + c;
      }
    }
//    cout << "--- " << i << endl;
//    REP(i,N)  cout << ans[i] << endl;
  }
  REP(i,N) {
    cout << ans[i] << endl;
  }
}



Measured memory_bytes: 256
#include<iostream>
#include<cmath>
#include<climits>
#include<algorithm>
#include<vector>
#include<map>
#include<queue>
#include<string>
#include<set>

using namespace std;

void md(int index, vector<vector<int>> &child, vector<int> &height, vector<int> &r){
    for(int i = 0; i < child[index].size(); i++){
        r[child[index][i]]--;
        if(height[child[index][i]] < height[index] + 1){
            height[child[index][i]] = height[index] + 1;
        }
        if(r[child[index][i]] == 0) md(child[index][i], child, height, r);
    }
}



int main(void){
    int N, M;
    cin >> N >> M;
    int E = N - 1 + M;
    vector<vector<int>> child(E, vector<int>(0));
    vector<bool> isroot(E, true);
    vector<int> r(N, 0);
    for(int i = 0; i < E; i++){
        int A, B;
        cin >> A >> B;
        A--;
        B--;
        child[A].push_back(B);
        isroot[B] = false;
        r[B]++;
    }

    int root;
    for(root = 0; root < N; root++) if(isroot[root]) break;
    vector<int> height(N, -1);
    height[root] = 0;
    md(root, child, height, r);

    for(int i = 0; i < N; i++){
        for(int j = 0; j < child[i].size(); j++){
            if(height[child[i][j]] > height[i] + 1){
                child[i][j] = -1;
            }
        }
    }

    vector<int> parent(N, -1);
    for(int i = 0; i < N; i++){
        for(int j = 0; j < child[i].size(); j++){
            if(child[i][j] != -1){
                parent[child[i][j]] = i;
            }
        }
    }
     for(int i = 0; i < N; i++) cout << parent[i] + 1 << endl;
    return 0;
}

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

#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL); 

#define ll long long
#define ff first
#define ss second
#define pb push_back
#define pf push_front
#define mp make_pair
#define pu push
#define pp pop_back
#define in insert
#define ld long double
#define forn(low,high,i) for(i = low;i < high;i++)
#define forrev(high,low,i) for(i = high; i >= low;i--)
#define trace(x) cerr << #x << ": " << x << " " << endl;
#define all(v) v.begin(),v.end()
#define sz(v) (int)v.size()
#define line cout << __LINE__;
#define prv(a) for(auto x : a) cout << x << ' ';cout << '\n';
#define decimal_digits cout << fixed << setprecision(15);
#define dbg2(a,b) cerr << #a << " = " << a << " " << #b << " = " << b << '\n';        
#define debug(x) cerr << __LINE__ << ' ' << #x << " = " << x << '\n';
#define dln cerr << '\n';
#define dsp cerr << ' ';
#define pln cout << '\n';
#define psp cout << ' ';

typedef unordered_map<int,int> umi;
typedef unordered_map<ll,ll> uml;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vi> vvi;
typedef vector<vl> vvl;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef vector<pii> vpii;
typedef vector<pll> vpll;
mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());
const int inf = 1e9;
const ll INF = 1e18;
const ll mod = 1e9 + 7;

clock_t time_p = clock();

void ktj(){
  time_p = clock() - time_p;
  cerr << "Time elapsed : " << (float)(time_p)/CLOCKS_PER_SEC << "\n";
}
inline ll add(ll a,ll b){
  return (a % mod + b % mod) % mod;
}

inline ll sub(ll a,ll b){
  return (a % mod - b % mod + mod) % mod;
}

inline ll mul(ll a,ll b){
  return(a % mod * b % mod) % mod;
}

inline ll modexpoo(ll a,ll b){
  ll res = 1;
  while(b > 0){
    if(b & 1)
      res = (res % mod * a % mod) % mod;
    a = (a % mod * a % mod) % mod;
    b >>= 1;
  }return res;
}

inline ll modinv_Fermat(ll a){
  return modexpoo(a,mod - 2);
}

inline ll divide(ll a,ll b){
  return(a%mod * modexpoo(b,mod - 2)%mod)%mod;
}

const ll N = 1e5 + 5;

ll dp[N][20];
ll expo[N];

void pre(){
  expo[0] = 1;
  for(ll i = 1; i < N; i++){
    expo[i] = (10 * expo[i - 1]) % 13;
  }
}
vl ques;

ll solve(ll idx, ll mod_sum, ll need, ll n){
  if(idx == n){
    return (mod_sum == need);
  }
  ll &ans = dp[idx][mod_sum];

  if(~ans)
    return ans;
  ans = 0;
  ll i;
  forn(0, 10, i){
    ans = add(ans, solve(idx + 1, (mod_sum % 13 + (expo[ques[idx]] * i) % 13) % 13, need, n));
  }

  return ans;
}

int main(){
  fastio
  pre();
  string s;
  cin >> s; 
  ll n = sz(s);
  ll sum = 0;
  ll i, j, k;
  reverse(all(s));
  forn(0, n, i){
    if(s[i] <= '9' and s[i] >= '0'){
      ll dig = s[i] - '0';
      sum = (sum % 13 + (dig % 13 * expo[i] % 13) % 13) % 13;
    }else{
      ques.push_back(i);
    }
  }

  memset(dp, -1, sizeof dp);

  cerr << sum << '\n';

  ll need = (5 - sum + 13) % 13;

  cerr << need << '\n';

  n = sz(ques);
  // prv(ques);
  cout << solve(0, 0, need, n) << '\n';

  ktj();
}


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

const int MOD = 1000000007;
const int INF = 1e9;

int main(){
  int n;
  const int max_n = 1e6;
  cin >> n;

  long long a,b,c;
  long long res;
  long long ans = 0;

  int num[max_n + 1] = {};
  for(int i = 1; i <= n; i++){
    int now = i;
    while(now <= n){
      num[now] ++;
      now += i;
    }
  }

  for(int i = 1; i <= n; i++){
    c = i;
    res = n - c;
    ans += num[res];
  }
  cout << ans << endl;

  return 0;
}

Measured memory_bytes: 7552
#define _USE_MATH_DEFINES
#define _CRT_SECURE_NO_WARNINGS
#include <bits/stdc++.h>
using namespace std;

/*BigInteger
#include <boost/multiprecision/cpp_dec_float.hpp>
#include <boost/multiprecision/cpp_int.hpp>
#include <boost/rational.hpp>
namespace xxx = boost::multiprecision;
using Bint = xxx::cpp_int;
using Real = xxx::number<xxx::cpp_dec_float<1024>>;
*/

#define int long long
#define pb(x) push_back(x)
#define m0(x) memset((x), 0LL, sizeof(x))
#define mm(x) memset((x), -1LL, sizeof(x))

//container
#define ALL(x) (x).begin(), (x).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define EACH(i, c) for (typeof((c).begin()) i = (c).begin(); i != (c).end(); ++i)
#define EXIST(s, e) ((s).find(e) != (s).end())
#define UNIQUE(v) (v).erase(unique((v).begin(), (v).end()), (v).end());
#define PERM(c) \
  sort(ALL(c)); \
  for (bool c##p = 1; c##p; c##p = next_permutation(ALL(c)))

// debug
#define GET_VAR_NAME(variable) #variable
#define test(x) cout << GET_VAR_NAME(x) << " = " << x << endl;

// bit_macro
#define Bit(n) (1LL << (n))
#define Bitset(a, b) (a) |= (1LL << (b))
#define Bitunset(a, b) (a) &= ~(1LL << (b))
#define Bitcheck(a, b) ((((a) >> (b)) & 1LL) == 1LL)
#define Bitcount(a) __builtin_popcountll((a))

//typedef
typedef long long lint;
typedef unsigned long long ull;
typedef complex<long double> Complex;
typedef pair<int, int> P;
typedef tuple<int, int, int> TP;
typedef vector<int> vec;
typedef vector<vec> mat;

//constant
constexpr int INF = (int)1e18;
constexpr int MOD = (int)1e9 + 7;
constexpr double PI = (double)acos(-1);
constexpr double EPS = (double)1e-10;
constexpr int dx[] = {-1, 0, 0, 1, 0, -1, -1, 1, 1};
constexpr int dy[] = {0, -1, 1, 0, 0, 1, -1, 1, -1};

//
template <typename T>
void chmax(T &a, T b) { a = max(a, b); }
template <typename T>
void chmin(T &a, T b) { a = min(a, b); }
//
inline int toInt(string s) {
  int v;
  istringstream sin(s);
  sin >> v;
  return v;
}
template <class T>
inline string toString(T x) {
  ostringstream sout;
  sout << x;
  return sout.str();
}

//
struct Accelerate_Cin {
  Accelerate_Cin() {
    cin.tie(0);
    ios::sync_with_stdio(0);
    cout << fixed << setprecision(20);
  };
};

signed main() {
  int N, K;
  cin >> N >> K;
  int h[101010];
  vector<int> dp(N + 10, INF);

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

  dp[0] = 0;

  for (int i = 0; i < N; i++) {
    for (int j = 1; j <= K; j++) {
      if (i + j < N) {
        dp[i + j] = min(dp[i + j], dp[i] + abs(h[i + j] - h[i]));
      }
    }
  }

  cout << dp[N - 1] << endl;
  return 0;
}


Measured memory_bytes: 1792
from statistics import mean
import math

anslist = []

while(1):

    n = int(input())
    if n == 0:
        break
    elif n == 1:
        l = int(input())
        anslist.append(0)
    else:
        l = list(map(int, input().split()))
        ave = mean(l)
        sum = 0
        for s in l:
            sum += (s - ave)**2
        var = sum / n
        ans = math.sqrt(var)
        anslist.append(ans)

for ans in anslist:
    print(ans)



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

int main(){
    int n,i,l,r,g=0;
    
    
    cin>>n;
    for(i=0;i<n;i++){
        
        cin>>l>>r;
        g+=(r-l+1);
        
    }
    cout<<g<<endl;
    return 0;
    

    
}


Measured memory_bytes: 3452
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <algorithm>
#include <string>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <stack>
#include <queue>
#define llong long long
#define INF (__INT32_MAX__ / 2)
#define EPS 10e-8
#define MAX_N 200000

using namespace std;
typedef pair<int, int> ipair;
typedef pair<llong, llong> llpair;
llong modulo(llong left, llong right) { return (left % right + right) % right; }

int N, Q;
llpair nodes[MAX_N];    //(diff, cnter)
vector<int> adj_list[MAX_N];


bool isvisited[MAX_N];
void dfs(int node) {
    isvisited[node] = true;
    int cnter = nodes[node].second;

    for(int i = 0; i < adj_list[node].size(); ++i) {
        int next = adj_list[node][i];
        if(isvisited[next]) continue;

        nodes[next].second = cnter + nodes[next].first;
        dfs(next);
    } 
}

int main(int argc, char **argv) {
    cin >> N >> Q;
    for(int i = 0; i < N - 1; ++i) {
        int a, b;
        cin >> a >> b;
        adj_list[a - 1].push_back(b - 1);
        adj_list[b - 1].push_back(a - 1);
    }

    //init
    for(int i = 0; i < N; ++i)
        nodes[i].first = nodes[i].second = 0;
    
    for(int i = 0; i < Q; ++i) {
        int p, x;
        cin >> p >> x;
        nodes[p - 1].first += x;
    }

    //DFS
    nodes[0].second = nodes[0].first;
    dfs(0);

    for(int i = 0; i < N; ++i) {
        if(i != 0)
            cout << " ";
        cout << nodes[i].second;
    }
    cout << endl;
}

Measured memory_bytes: 25984
#include <iostream>
#include <vector>
#include <string>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <algorithm>	// require sort next_permutation count __gcd reverse etc.
#include <cstdlib>	// require abs exit atof atoi 
#include <cstdio>		// require scanf printf
#include <functional>
#include <numeric>	// require accumulate
#include <cmath>		// require fabs
#include <climits>
#include <limits>
#include <cfloat>
#include <iomanip>	// require setw
#include <sstream>	// require stringstream 
#include <cstring>	// require memset
#include <cctype>		// require tolower, toupper
#include <fstream>	// require freopen
#include <ctime>		// require srand
#define rep(i,n) for(int i=0;i<(n);i++)
#define ALL(A) A.begin(), A.end()

using namespace std;

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

int stoi (string s ){
	stringstream ss (s );
	int res;
	ss >> res;
	return res;
}

string itos (int n ){
	stringstream ss;
	ss << n;
	return ss.str();
}
	
int main()
{
	ios_base::sync_with_stdio(0);
	int Q; cin >> Q;

	while (Q--){
		string n = ""; cin >> n;
		int res = 0;
		set<int> same; same.clear();
		while (n.length() != 1 ){
			int cur = 0;
			rep (i, n.length() - 1 ){
 				string s = n.substr (0, i+1), t = n.substr(i+1);
				int sn = stoi (s ), tn = stoi (t );
//				cerr << "sn: " << sn << " tn: " << tn << endl;
				cur = max (cur, sn*tn );
			} // end rep
			if (!same.count (cur ) ){
				same.insert(cur );
			}else{
				res = -1;
				break;
			} // end if
			n = itos (cur );
			res++;
		} // end while
		cout << res << endl;

	} // end while
		
	return 0;
}

Measured memory_bytes: 1232
<?php
/**
 * ABC125 
 * D - Flipping Signs
 */

$n = trim(fgets(STDIN));
$a = array_map('intval', explode(' ', trim(fgets(STDIN))));

$abs_list = [];
$minus_num = 0;
foreach ($a as $value) {
    if ($value >= 0) {
        $abs_list[] = $value;
    } else {
        $abs_list[] = -1 * $value;
        $minus_num++;
    }
}

if ($minus_num % 2 == 0) {
    // 負の数が偶数個のとき、すべての数を正にできる
    $answer = array_sum($abs_list);
} else {
    // 負の数が奇数個のとき、1つだけ負の数になる
    $answer = array_sum($abs_list) - 2 * min($abs_list);
}

echo $answer, "\n";


Measured memory_bytes: 18932
h,w = map(int,input().split())
c = [list(map(int,input().split())) for i in range(10)]
a = [list(map(int,input().split())) for i in range(h)]
for k in range(10):
    for i in range(10):
        for j in range(10):
            c[i][j] = min(c[i][j], c[i][k] + c[k][j])
cost = 0
for i in range(h):
    for j in range(w):
        if a[i][j]==-1:
            continue
        cost += c[a[i][j]][1]
print(cost)

Measured memory_bytes: 3316
/*  ex6_1
    kosaq       */

#include <stdio.h>
#include <string.h>
#define SIZE 101//十分な要素数

int main(void){
    char string_s[SIZE];//入力に使う文字列を定義
    int number_total;//全文字数を定義

    scanf("%s", string_s);//文字列を入力

    number_total = strlen(string_s);//全文字数は入力された文字列の長さに等しい

    printf("%c%d%c\n", string_s[0], number_total - 2, string_s[number_total - 1]);
    //string_s[0]は先頭の文字を出力、number_total - 2は間の文字数を出力、string_s[number - 1]は最後の文字を出力
    return 0;
}

Measured memory_bytes: 128
L = input()
MOD = 10 ** 9 + 7
DP = [[0] * 2 for _ in range(2)]
if L[-1] == "0":
  DP[0][0] = 2
  DP[0][1] = 1
else:
  DP[0][1] = 3
for i in range(1, len(L)):
  if L[-1 - i] == "0":
    DP[1][0] = (DP[0][0] * 3 + DP[0][1] * 2) % MOD 
    DP[1][1] = DP[0][1]
  else:
    DP[1][0] = (DP[0][0] * 2) % MOD
    DP[1][1] = (DP[0][0] + DP[0][1] * 3) % MOD
  DP[0][0] = DP[1][0]
  DP[0][1] = DP[1][1]

print(DP[0][1])


Measured memory_bytes: 3188