akhauriyash/Code-Regression huggingface dataset:
class dice:
  def __init__(self, dice):
    self.d = dice

  def roll(self, c):
    d = self.d
    if c == 'E':
      d[0], d[2], d[3], d[5] = d[3], d[0], d[5], d[2]
    elif c == 'W':
      d[0], d[2], d[3], d[5] = d[2], d[5], d[0], d[3]
    elif c == 'N':
      d[0], d[1], d[4], d[5] = d[1], d[5], d[0], d[4]
    elif c == 'S':
      d[0], d[1], d[4], d[5] = d[4], d[0], d[5], d[1]
    self.d = d
  def print(self):
    print(self.d[0])

d = dice([_ for _ in input().split()])

commands = input()
for c in commands:
  d.roll(c)
d.print()

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

long long modpow(long long a, long long n, long long mod) {
    long long res = 1;
    while (n > 0) {
        if (n & 1) res = res * a % mod;
        a = a * a % mod;
        n >>= 1;
    }
    return res;
}
 
int main() {
int n;
cin >> n;
int m;
cin >> m;
vector<long long> z(m);
  for(int i = m;i > 0;i--){
    z.at(i-1) =modpow(m/i,n,1000000007);
    for(int j = i*2;j <= m;j += i){
      z.at(i-1) = z.at(i-1)+1000000007-z.at(j-1);}
    z.at(i-1)%=1000000007;
  }
  long long ans=0;
  for(int i = 0;i < m;i++){
    ans = (ans+z.at(i)*(i+1))%1000000007;
  }
  cout << ans << endl;
}

Measured memory_bytes: 4048
import itertools
from collections import deque,defaultdict,Counter
from itertools import accumulate
import bisect
from heapq import heappop,heappush,heapify
import math
from copy import deepcopy
import queue
#import numpy as np
# sympy as syp(素因数分解とか)
Mod = 1000000007
fact = [1, 1]
factinv = [1, 1]
inv = [0, 1] 
for i in range(2, 10**5 + 1):
    fact.append((fact[-1] * i) % Mod)
    inv.append((-inv[Mod % i] * (Mod // i)) % Mod)
    factinv.append((factinv[-1] * inv[-1]) % Mod)
    
def cmb(n, r, p):
    if (r < 0) or (n < r):
        return 0
    r = min(r, n - r)
    return fact[n] * factinv[r] * factinv[n - r] % p
    
def sieve_of_eratosthenes(n):
    if not isinstance(n,int):
        raise TypeError("n is not int")
    if n<2:
        raise ValueError("n is not effective")
    prime = [1]*(n+1)
    for i in range(2,int(math.sqrt(n))+1):
        if prime[i] == 1:
            for j in range(2*i,n+1):
                if j%i == 0:
                    prime[j] = 0
    res = []
    for i in range(2,n+1):
        if prime[i] == 1:
            res.append(i)
    return res

 
class UnionFind:
    def __init__(self,n):
        self.parent = [i for i in range(n+1)]
        self.rank = [0 for i in range(n+1)]
    
    def findroot(self,x):
        if x == self.parent[x]:
            return x
        else:
            y = self.parent[x]
            y = self.findroot(self.parent[x])
            return y
    
    def union(self,x,y):
        px = self.findroot(x)
        py = self.findroot(y)
        if px < py:
            self.parent[y] = px
        else:
            self.parent[px] = py
 
    def same_group_or_no(self,x,y):
        return self.findroot(x) == self.findroot(y)
import string
def main():  #startline-------------------------------------------
    n = int(input())
    ans = ""
    while n > 0:
        n -= 1
        ans += chr(ord("a") + n % 26)
        n //= 26
    print(ans[::-1])
if __name__ == "__main__":
    main() #endline===============================================

Measured memory_bytes: 21996
#include "bits/stdc++.h"
using namespace std;
#define rep(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define ALL(x) (x).begin(), (x).end()
#define SZ(x) ((int)(x).size)
#define MOD 1000000007
const long long mod = 1e9+7;
typedef vector<long long> Vl;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<Vl> VVl;
typedef pair<int, int> PII;

int main(){
    int a,b;
    int n;
    cin >> n;
    vector<PII> p(n);
    rep(i,n){ 
        cin >> p[i].second >> p[i].first; 
    }
    sort(ALL(p));
    int sum = 0;
    bool f = true;
    rep(i,n) { 
        sum += p[i].second;  // 単位時間aの総和を求める
        if (sum > p[i].first) {
            f = false;
            break;
        }
    }
    cout  << ( f ? "Yes" : "No" ) << endl;
    return 0;
}
   


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

int main()
{
    int arr[3][3];
    for (int i = 0; i < 3; i++)
    {
        for (int j = 0; j < 3; j++)
        {
            cin >> arr[i][j];
        }
    }

    int n;
    cin >> n;
    for (int k = 0; k < n; k++)
    {
        int ab;
        cin >> ab;

        for (int i = 0; i < 3; i++)
        {
            for (int j = 0; j < 3; j++)
            {
                if (arr[i][j] == ab)
                {
                    arr[i][j] = 0;
                }
            }
        }
    }

    if ((arr[0][0] + arr[0][1] + arr[0][2] == 0) || (arr[1][0] + arr[1][1] + arr[1][2] == 0) || (arr[2][0] + arr[2][1] + arr[2][2] == 0) ||
        (arr[0][0] + arr[1][0] + arr[2][0] == 0) || (arr[0][1] + arr[1][1] + arr[2][1] == 0) || (arr[0][2] + arr[1][2] + arr[2][2] == 0) ||
        (arr[0][0] + arr[1][1] + arr[2][2] == 0) || (arr[2][0] + arr[1][1] + arr[0][2] == 0))
    {
        cout << "Yes" << endl;
    }
    else
    {
        cout << "No" << endl;
    }
    return 0;
}

Measured memory_bytes: 256
class Main
{
	public static void main(String[] av)
	{
		java.util.Scanner sc = new java.util.Scanner(System.in);
		java.util.ArrayList<Integer> vec = new java.util.ArrayList<Integer>();
		while( sc.hasNextInt() )
		{
			vec.add( sc.nextInt() );	
		}
		java.util.Collections.sort( vec );
		java.util.Collections.reverse( vec );
		for ( int i = 0; i < 3; ++i )
		{
			System.out.println( vec.get(i) );
		}
	}
}

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

#define pb push_back
#define all(x) (x).begin(),(x).end()
#define SZ(x) ((int)(x).size())
#define REP(i,n) for(int _n=n, i=0;i<_n;++i)
#define FOR(i,a,b) for(int64_t i=(a),_b=(b);i<=_b;++i)
#define FORD(i,a,b) for(int64_t i=(a),_b=(b);i>=_b;--i)
using ull = uint64_t;
using ll = int64_t;
using PII = pair<int, int>;
using VI = vector<int>;

string to_string(string s) { return '"' + s + '"'; }
string to_string(const char* s) { return to_string((string) s); }
string to_string(bool b) { return (b ? "true" : "false"); }
template <typename A, typename B> string to_string(pair<A, B> p) {
  return "(" + to_string(p.first) + ", " + to_string(p.second) + ")"; }
template <typename A> string to_string(A v) {
bool first = true; string res = "{";
for (const auto &x : v) { if (!first) { res += ", "; } first = false; res += to_string(x); }
res += "}"; return res; }
void debug_out() { cerr << endl; }
template <typename Head, typename... Tail> void debug_out(Head H, Tail... T) {
  cerr << " " << to_string(H); debug_out(T...); }
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)

const ll md = 1000000007;

int main() {
    ios::sync_with_stdio(false), cin.tie(0);
    int a;
    cin >> a;
    cout << a + a * a + a * a * a << endl;
}

Measured memory_bytes: 3648
N, M = map(int, input().split())
city = []
for i in range(M):
  P, Y = map(int, input().split())
  city.append([P, Y, i])
id = [''] * M

city.sort(key = lambda x: (x[0], x[1]))
prev_P = 0
count = 0
for i in city:
  if prev_P == i[0]:
    count += 1
  else:
    count = 1
  id[i[2]] = str(i[0]).zfill(6) + str(count).zfill(6)
  prev_P = i[0]

for i in range(M):
  print(id[i])

Measured memory_bytes: 31564
#include<bits/stdc++.h>
using namespace std;
const int maxn=1e5+5;
vector<int>v[maxn];
priority_queue<int>q;
int main()
{
    int n,m;
    scanf("%d%d",&n,&m);
    int a,b;
    for(int i=0;i<n;i++){
        scanf("%d%d",&a,&b);
        v[a].push_back(b);
    }
    int ans=0;
    for(int i=1;i<=m;i++){
        for(auto c:v[i]) q.push(c);
        if(!q.empty()){
            ans+=q.top();
            q.pop();
        }
    }
    printf("%d\n",ans);
}

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

# define REP(i,n) for (int i=0;i<(n);++i)
# define rep(i,a,b) for(int i=a;i<(b);++i)
# define p(s) std::cout << s ;
# define pl(s)  std::cout << s << endl;
# define printIf(j,s1,s2) cout << (j ? s1 : s2) << endl;
# define YES(j) cout << (j ? "YES" : "NO") << endl;
# define Yes(j) std::cout << (j ? "Yes" : "No") << endl;
# define yes(j) std::cout << (j ? "yes" : "no") << endl;
# define all(v) v.begin(),v.end()
# define showVector(v) REP(i,v.size()){p(v[i]);p(" ")} pl("")
template<class T> inline bool chmin(T &a, T b){ if(a > b) { a = b; return true;} return false;}
template<class T> inline bool chmax(T &a, T b){ if(a < b) { a = b; return true;} return false;}
typedef long long int ll;
typedef pair<ll,ll> P_ii;
typedef pair<double,double> P_dd;

template<class T>
vector<T> make_vec(size_t a){
    return vector<T>(a);
}

template<class T, class... Ts>
auto make_vec(size_t a, Ts... ts){
  return vector<decltype(make_vec<T>(ts...))>(a, make_vec<T>(ts...));
}

template<typename T,typename V>
typename enable_if<is_class<T>::value==0>::type
fill_v(T &t,const V &v){t=v;}

template<typename T,typename V>
typename enable_if<is_class<T>::value!=0>::type
fill_v(T &t,const V &v){
  for(auto &e:t) fill_v(e,v);
}


const int MOD = 1000000007;
const int inf=1e9+7;
const ll longinf=1LL<<60 ;

void addM(long long &a, long long b) {
    a += b;
    if (a >= MOD) a -= MOD;
}

void mulM(long long &a, long long b) {
    a = ((a%MOD)*(b%MOD))%MOD ;
}

// テーブルを作る前処理
const int MAX = 510000;
long long fac[MAX], finv[MAX], inv[MAX];
void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}

// 二項係数計算
long long COM(ll n, ll k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

int main() {
    ll N, L;
    cin >> N >> L;

    vector<ll> a(N);
    REP(i, N) cin >> a[i];

    int l, r;
    bool flg = false;
    REP(i, N - 1) {
        if(a[i] + a[i + 1] >= L){
            r = i + 1;
            flg = true;
            break;
        }
    }

    if (flg) {
        cout << "Possible" << endl;
        for (int i = 1 ; i < r; i++) cout << i << endl;
        for (int i = N - 1 ; i >= r; i--) cout << i << endl;
    } else {
        cout << "Impossible" << endl;
    }


    return 0;
}


Measured memory_bytes: 1664
//#include <boost/multiprecision/cpp_dec_float.hpp>
//#include <boost/multiprecision/cpp_int.hpp>
#include <stdio.h>
#include <iostream>
#include <vector>
#include <string>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <math.h>
#include <algorithm>
#include <bitset>
#include <iomanip>
using namespace std;
//namespace mp = boost::multiprecision;
//using llll = mp::cpp_int;
// 仮数部が1024ビットの浮動小数点数型(TLEしたら小さくする)
//using Real = mp::number<mp::cpp_dec_float<1024>>;
using ll = long long;
const double EPS = 1e-10;
const ll MOD = 7+(1e+9);

int main(){
  ll n,k,ans=(ll)1e+14;
  cin>>n>>k;
  vector<ll>v(n,0);
  for(ll i=0;i<n;i++){
    cin>>v[i];
  }
  vector<vector<vector<ll> > >dp(n+1,vector<vector<ll> >((k+1),vector<ll>((n+1),-1)));
  dp[0][0][0]=0;
  for(ll i=0;i<n;i++){
    for(ll j=0;j<k+1;j++){
      for(ll l=0;l<n+1;l++){
        if(dp[i][j][l]>=0){
          if(dp[i+1][j][i+1]==-1)dp[i+1][j][i+1]=dp[i][j][l]+max((ll)0,v[i]-(l==0?0:v[l-1]));
          else dp[i+1][j][i+1]=min(dp[i][j][l]+max((ll)0,v[i]-(l==0?0:v[l-1])),dp[i+1][j][i+1]);
          if(j<k){
            if(dp[i+1][j+1][l]==-1)dp[i+1][j+1][l]=dp[i][j][l];
            else dp[i+1][j+1][l]=min(dp[i][j][l],dp[i+1][j+1][l]);
          }
        }
      }
    }
  }
  for(ll i=0;i<k+1;i++){
    for(ll j=0;j<n+1;j++){
      if(dp[n][i][j]>=0)ans=min(dp[n][i][j],ans);
    }
  }
  cout<<ans<<endl;
}


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

int main() {
	string S;

	cin >> S;

	if (S == "hi" || S == "hihi" || S == "hihihi" || S == "hihihihi" || S == "hihihihihi") cout << "Yes" << endl;
	else cout << "No" << endl;

	return 0;
}


Measured memory_bytes: 256
class Restaurant:
	def __init__(self,id,name,score):
		self.id = id
		self.name = name
		self.score = score

N=int(input())

arr=[]

for n in range(N):
	name,score=input().split()
	arr.append(Restaurant(n+1,name,-1*int(score)))

arr.sort(key=lambda x: (x.name,x.score))

ans = ""
for a in arr:
	print(a.id)



Measured memory_bytes: 3060
h,w = map(int,input().split())
l = list(list(input()) for i in range(h))
for i in l:
  if i.count('.') ==w:
    i.clear()
l= [i for i in l if i!=[]]
#print(l)
t = len(l)
for i in range(w):
  if all (l[q][i]=="." for q in range(t)):
    for q in range(t):
      l[q][i] =""
if "" in l:
  for z in l:
    z.remove("")
for m in l:
  print("".join(m))



Measured memory_bytes: 3064
#include <iostream>
#include <string>

using namespace std;

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

	a = stoi(x, nullptr, 16);
	b = stoi(y, nullptr, 16);

	if (a < b) cout << '<' << endl;
	else if (a == b) cout << '=' << endl;
	else cout << '>' << endl;
}

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

const int MOD { (int)1e9 + 7 };

int main() {
  int N; cin >> N;
  auto f = [=](int i) { return (i < N) ? -1 : 1; };
  vector<P> s;
  for (int i = 0; i < 2 * N; i++) {
    int n; cin >> n;
    s.push_back({ n, f(i) });
  }
  sort(s.begin(), s.end());
  ll x {}, ans { 1 };
  for (int i = 0; i < 2 * N; i++) {
    int t { s[i].second };
    if (abs(x + t) < abs(x)) {
      ans *= abs(x);
      ans %= MOD;
    }
    x += t;
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 2420
#include <bits/stdc++.h>
using namespace std;
#define int long long int
int dp[3005][3005];
vector<char> v;

int32_t main(){
	string s,t;
	cin>>s>>t;
	for(int i=0;i<=s.length();i++){
		for(int j=0;j<=t.length();j++){
			if(i==0 || j==0) dp[i][j]=0;
			else if(s[i-1]==t[j-1]) dp[i][j]=1+dp[i-1][j-1];
			else dp[i][j]=max(dp[i-1][j],dp[i][j-1]);
			//cout<<dp[i][j]<<" ";
		}
		//cout<<"\n";
	}
	int i = s.length();
	int j = t.length();
	while(i>0 && j>0){
		//cout<<i<<" "<<j<<"\n";
		if(s[i-1]==t[j-1]){
			v.push_back(s[i-1]);
			i--;j--;
		}
		else if(dp[i-1][j]>dp[i][j-1]) i--;
		else j--;
	}
	//if(s[i]==t[j]) v.push_back(s[i]);
	reverse(v.begin(),v.end());
	//cout<<v.size();
	for(auto c:v) cout<<c;
}


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

int main(){
	string s,s1;
	cin>>s;
	cin>>s1;
	int a=0;
	for(int i=0;i<3;i++)
	{
		if(s[i]==s1[i])a++;
	}
	cout<<a;
	
	return 0;
}

Measured memory_bytes: 256
n,m=map(int,input().split())
lrd=[list(map(int,input().split())) for _ in range(m)]
g=[[] for _ in range(n)]
for l,r,d in lrd:
  g[l-1].append([d,r-1])
  g[r-1].append([-d,l-1])

no_seen=set(range(n))
inf=float('inf')
dst=[inf]*n
while no_seen:
  todo=[[0,no_seen.pop()]]
  #print(todo)
  while todo:
    d,t=todo.pop()
    no_seen.discard(t)
    l=g[t]
    for di,ti in l:
      if dst[ti]!=inf and dst[ti]!=d+di:
        print('No')
        exit()
      elif dst[ti]!=inf and dst[ti]==d+di:
        pass
      else:
        todo.append([d+di,ti])
        dst[ti]=d+di

print('Yes')

Measured memory_bytes: 127248
//g++ -std=c++14 test.cpp -o test.out
//問題URL
//https://atcoder.jp/contests/abc159/tasks/abc159_f
//数え上げのDPでは多項式を用いる方法がある

//例えば、数列{2,4,2}の部分和問題を考える
//この数列から1個以上選び出して4を作る場合の数を求める

//まず先頭の2について考えると、この2を選ぶ場合と選ばない場合について、
//+0と+2、両方の場合が考えられる
//よって2を(x^0 + x^2) = (1 + x^2)に対応させる
//4,2についても同じことをして
//{2,4,2}を
//(1 + x^2),(1 + x^4),(1 + x^2)
//に対応させる

//この全てを乗算してf(x)=(1 + x^2)(1 + x^4)(1 + x^2)とする。
//これを展開するとx^nの係数は
//数列{2,4,2}からいくつか要素を取り出して和をnに
//できるような組み合わせの個数を表す

//例えば今回はf(x) = x^8 + 2x^6 + 2x^4 + 2x^2 + 1　となるが、
//x^4　の係数は 2 となっている

//これは{2,4,2}から和を4にするような要素を選ぼうとすると
//{2,2}と{4}の二通りあることを意味する

//しかし例えば
//{2,4,2}から和を7にするような要素の組み合わせを選ぼうとしても
//そんな組み合わせは作れないのでx^7の係数は0になっている

#include <string.h>
#include <stdlib.h>
#include <math.h>
#include <cassert>
#include <algorithm>
#include <functional>
#include <iostream>
#include <iomanip>
#include <vector>
#include <queue>
#include <map> 
#include <utility>
#include <limits.h>
#include <bitset>
#include <set>
using namespace std;
 
#define LL long long int
const LL INF = (LL)(1e18)+1;
const int INF_INT = 2147483647-1e6;
const LL mod = 1000000007ll;
const int mod_int = 1000000007;

const LL MOD = 998244353LL;

int N,S;
int A[3000];

LL ans = 0;

void solve(){
    vector<LL> dp(S+1,0);//多項式f(x)を格納
    //数列を前からi番目まで見た時について考える
    for(int i=0;i<N;i++){
        dp[0] += 1;// f(x) += 1
        //1 = x^0 の係数は数列から選び出したときに、和を0にできるような組の数を表す
        //f(x) *= (1+x^A[i])を実行
        vector<LL> dp_new(S+1,0);//多項式を格納
        for(int j=0;j<=S;j++){//x^jについて計算する
            dp_new[j] += dp[j];//f(x)のx^jの項の係数を持ってくる
            //その項にx^A[i]をかける
            //項の次数がSを超える→その項の係数は和がSより大きくなる組み合わせを表すが
            //今回は必要ないのでカット
            if(j+A[i]<=S){
                //x^(j+A[i])の係数にx^jの係数を足す
                dp_new[j+A[i]] += dp[j];
                dp_new[j+A[i]] %= MOD;
            }
        }
        dp = dp_new;
        ans += dp[S];
        ans %= MOD;
    }
}
 
int main(){
    cin >> N >> S;
    for(int i=0;i<N;i++){
        cin >> A[i];
    }
 
    solve();

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

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>

using namespace std;

int main() {
	int T, P, R;
	while (cin >> T >> P >> R) {
		if (T == 0 && P == 0 && R == 0) {
			break;
		}
		int team[50][10] = {0};
		int pena[50][2] = {0};
		for (int i = 0; i < R; i++) {
			int tid, pid, time;
			string message;
			cin >> tid >> pid >> time >> message;
			if (message == "CORRECT") {
				pena[tid-1][0]++;
				pena[tid-1][1] += team[tid-1][pid-1] * 1200 + time;
			} else {
				team[tid-1][pid-1]++;
			}
		}
		int juni[50];
		for (int i = 0; i < T; i++) {
			juni[i] = i+1;
		}
		for (int i = 0; i < T; i++) {
			for (int j = T-1; j > i; j--) {
				if (pena[j][0] > pena[j-1][0]) {
					swap(pena[j][0], pena[j-1][0]);
					swap(pena[j][1], pena[j-1][1]);
					swap(juni[j], juni[j-1]);
				} else if (pena[j][0] == pena[j-1][0]) {
					if (pena[j][1] < pena[j-1][1]) {
						swap(pena[j][0], pena[j-1][0]);
						swap(pena[j][1], pena[j-1][1]);
						swap(juni[j], juni[j-1]);
					}
				} 
			}
		}
		for (int i = 0; i < T; i++) {
			cout << juni[i] << ' ' << pena[i][0] << ' ' << pena[i][1] << endl;
		}
	}
	return 0;
}

Measured memory_bytes: 1216
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.AbstractMap;
import java.util.StringTokenizer;

public class Main {

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

		solve(sc,out);
		
		out.flush();
	}

	public static void solve(FastScanner sc, PrintWriter out) {
		String s = sc.next();

		int m = Integer.parseInt(s.charAt(2) + "" + "" + s.charAt(3));
		int y = Integer.parseInt(s.charAt(0) + "" + "" + s.charAt(1));

			if(y <= 12 && m <= 12 && y > 0 && m > 0){
				out.println("AMBIGUOUS");
				return;
			}
			if(m > 0 && m <= 12){
				out.println("YYMM");
				return;
			}
			if(y > 0 && y <= 12){
				out.println("MMYY");
				return;
			}
		out.println("NA");

	}

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

class Pair<K, V> extends AbstractMap.SimpleEntry<K, V> {

    public Pair(final K key, final V value) {
        super(key, value);
    }
 }

class FastScanner {
    private BufferedReader reader = null;
    private StringTokenizer tokenizer = null;

    public FastScanner(InputStream in) {
        reader = new BufferedReader(new InputStreamReader(in));
        tokenizer = null;
    }

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

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

        return tokenizer.nextToken("\n");
    }

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

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

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

    public int[] nextIntArray(int n) {
        int[] a = new int[n];
        for (int i = 0; i < n; i++)
            a[i] = nextInt();
        return a;
    }

    public long[] nextLongArray(int n) {
        long[] a = new long[n];
        for (int i = 0; i < n; i++)
            a[i] = nextLong();
        return a;
    }
}

Measured memory_bytes: 21076
#include <algorithm>
#include <iostream>
#include <cstring>
#include <string>
#include <vector>
#include <queue>
#include <cmath>
#include <stack>
#include <set>
#include <map>
typedef long long ll;
typedef unsigned int uint;
using namespace std;

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

    ll q, h, s, d, n;
    cin >> q >> h >> s >> d >> n;

    ll one = min({4*q, 2*h, s});
    ll two = min(2*one, d);

    cout << n/2*two + (n%2)*one << "\n";
    return 0;
}

Measured memory_bytes: 256
#include<iostream>

int main()
{
    int a, b, c;
    std::cin >> a >> b >> c;
    int max;
    if(a > b){
        if(a > c){
            max = a;
        }
        else{
            max = c;
        }
    }
    else{
        if(b > c){
            max = b;
        }
        else{
            max = c;
        }
    }
    int delta = 3 * max - a - b -c;
    if(delta % 2 == 0){
        std::cout << delta / 2 << std::endl;
    }
    else{
        std::cout << delta / 2 + 2 << std::endl;
    }
    return 0;
}

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

#define sim template < class c
#define ris return * this
#define dor > debug & operator <<
#define eni(x) sim > typename \
  enable_if<sizeof dud<c>(0) x 1, debug&>::type operator<<(c i) {
sim > struct rge { c b, e; };
sim > rge<c> range(c i, c j) { return rge<c>{i, j}; }
sim > auto dud(c* x) -> decltype(cerr << *x, 0);
sim > char dud(...);
struct debug {
#ifdef LOCAL
~debug() { cerr << endl; }
eni(!=) cerr << boolalpha << i; ris; }
eni(==) ris << range(begin(i), end(i)); }
sim, class b dor(pair < b, c > d) {
  ris << "(" << d.first << ", " << d.second << ")";
}
sim dor(rge<c> d) {
  *this << "[";
  for (auto it = d.b; it != d.e; ++it)
    *this << ", " + 2 * (it == d.b) << *it;
  ris << "]";
}
#else
sim dor(const c&) { ris; }
#endif
};
#define imie(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "

typedef long long LL;

const int INF = 0x3f3f3f3f;


int main(void) {
    std::ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);

    int n, k;
    cin >> n >> k;
    if (n <= k) {cout << "0" << endl; return 0;}

    int h[n];
    for (int i = 0; i < n; ++i) cin >> h[i];

    sort(h, h+n, greater<int>());

    LL ans = 0;
    for (int i = k; i < n; ++i) {
        ans += h[i];
    }

    cout << ans << endl;

    return 0;
}



Measured memory_bytes: 1024
#include <stdio.h>

int main(void)
{
	int i, j;
	
	for (i = 1; i <= 9; i++){
		for (j = 1; j <= 9; j++){
			printf("%dx%d=%d\n", i, j, i * j);
		}
	}
	
	return (0);
}

Measured memory_bytes: 524
A, B, C, X = map(int, [input() for i in range(4)])
count = 0

for i in range(min(X // 500, A)+1):
  Y = X - 500 * i
  for j in range(min(Y // 100, B)+1):
    Z = Y - 100 * j
    for k in range(min(Z // 50, C)+1):
      Q = Z - 50 * k
      if Q == 0:
        count += 1
      else:
        continue
print(count)

Measured memory_bytes: 3064
/***
 **   A S M Atikur Rahman
 **   Update: 01-04-2020
***/

//#include <bits/stdc++.h>
#include<iostream>
#include<stdio.h>
#include<stdlib.h>
#include<math.h>
#include<cstring>
#include<time.h>
#include<limits.h>
#include<vector>
#include<string>
#include<stack>
#include<queue>
#include<map>
#include<unordered_map>
#include<set>
#include<unordered_set>
#include<bitset>
#include<utility>
#include<iterator>
#include<algorithm>
#include<cassert>
#include<iomanip> ///setprecision


#define IOS ios_base::sync_with_stdio(false);cin.tie(nullptr);cout.tie(nullptr);
#define sci(x) scanf("%d%*c", &(x))
#define sci2(x,y) scanf("%d%*c%d%*c", &(x), &(y))
#define sci3(x,y,z) scanf("%d%*c%d%*c%d%*c", &(x), &(y), &(z))
#define scll(x) scanf("%lld%*c", &(x))
#define scll2(x,y) scanf("%lld%*c%lld%*c", &(x), &(y))
#define scll3(x,y,z) scanf("%lld%*c%lld%*c%lld%*c", &(x), &(y), &(z))
#define scd(x) scanf("%lf%*c", &(x))
#define scd2(x,y) scanf("%lf%*c%lf%*c", &(x), &(y))
#define scstr(x) scanf("%s", x)
#define pfi(x) printf("%d", (x))
#define pfi2(x,y) printf("%d %d", (x), (y))
#define pfll(x) printf("%lld", (x))
#define pfll2(x,y) printf("%lld %lld", (x), (y))
#define pfd(x) printf("%f", (x))
#define pfstr(x) printf("%s", (x))
#define ps printf(" ")
#define pn printf("\n")
#define pfdot printf("..")

#define For(a,n) for(int i=(a); i<(n); i++)
#define rFor(n,a) for(int i=n-1; i>=0; i--)
#define trav(a,x) for (auto &a : x)
#define Mset(ara, val) memset(ara, val, sizeof(ara))

#define mkp make_pair
#define pb push_back
#define ff first
#define ss second
#define lb lower_bound
#define ub upper_bound

#define pi  (2*acos(0))


using namespace std;

using ll=long long;
using pii= pair<int,int>;
using pll= pair<long long, long long>;
using pcc= pair<char, char>;
using pdd= pair<double, double>;

#define V(a) vector<a>
using vi= vector<int>;
using vs= vector<string>;
using vll= vector<ll>;
using vpii= vector<pii>;
using vc= vector<char>;
using vd= vector<double>;

//ll POW(ll a,ll b){if(b==0)return 1;ll x=POW(a,b/2);x=(x*x);if(b&1)x=(x*a);return x;}
//ll Sqrt(ll a) { ll x=(ll)sqrt(a); if((x+1)*(x+1)==a) x++; return x; }

/*------------------------Bitmask--------------------------*/

//int Set(int n, int p){return n= n|(1<<p);}
//ll Set(ll n, ll p){return n= n|(1ll<<p);}
//int Reset(int n,int p){return n= n&(~(1<<p));}
//ll Reset(ll n,ll p){return n= n&(~(1ll<<p));}
//bool Check(int n, int p){return (bool) (n&(1<<p));}
//bool Check(ll n, ll p){return (bool) (n&(1ll<<p));}
//int Toggle(int n, int p){return n= n^(1<<p);}
//ll Toggle(ll n, ll p){return n= n^(1ll<<p);}

/*----------------------------------------------------------*/



/*------------------------Declarations------------------------*/

//priority_queue<int,vector<int>, greater<int>>  //priority queue sorted in increasing order

/*------------------------------------------------------------*/




int main( int argc, char *argv[] )
{
//    freopen("input.txt", "r", stdin);
//    freopen("output.txt", "w", stout);
    int a,b,c;
    sci3(a,b,c);
    cout<<c<<" "<<a<<" "<<b<<endl;


    return 0;
}

























Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
struct Edge {
    int to;     // 辺の行き先
    int weight; // 辺の重み
    Edge(int t, int w) : to(t), weight(w) { }
};
using Graph = vector<vector<Edge>>;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define reprep(i,j,h,w) rep(i,h)rep(j,w)
#define rrep(i,m, n) for(int i = m; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()
#define aall(x,n) (x).begin(),(x).begin()+(n)
#define VEC(type,name,n) std::vector<type> name(n);rep(i,n)std::cin >> name[i];
#define pb push_back
#define pf push_front
#define lb lower_bound
#define ub upper_bound
#define fi first
#define se second
#define sum accumulate
#define keta fixed<<setprecision
#define vvector(name,typ,m,n,a)vector<vector<typ> > name(m,vector<typ> (n,a))
#define vvvector(name,t,l,m,n,a) vector<vector<vector<t> > > name(l, vector<vector<t> >(m, vector<int>(n,a)));
typedef long long ll;
const int INF = 2000000000;
const long INF64 = 1000000000000000ll;
const ll MOD = 1000000007LL;
typedef unsigned int uint;
int main(){
  int a,b;
  std::cin >> a>>b;
  std::cout << max({a+b,a-b,a*b}) << std::endl;
  
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <sstream>
#include <queue>
#include <deque>
#include <bitset>
#include <iterator>
#include <list>
#include <stack>
#include <map>
#include <set>
#include <functional>
#include <numeric>
#include <utility>
#include <limits>
#include <time.h>
#include <math.h>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <assert.h>

using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef vector<ll> vec;
typedef vector<vec> vec2;
typedef map<ll,ll> MPll;
typedef set<ll> setl;

template <typename T>
struct UnionFindTree{

    vector<T> par;

    ll num;

    UnionFindTree(T n) : par(n){
        for (int i = 0; i < n; ++i) {
            par[i] = i;
        }
    }

    T root(T x){
        if(par[x] == x) return x;
        else  return par[x] = root(par[x]);
    }

    void unite(T x,T y){
        if(!same(x,y)) par[root(x)] = root(par[y]);
    }

    T same(T x,T y){
        return root(x) == root(y);
    }


    bool operator<(const UnionFindTree &another) const{
        return this->num < another.num;
    }


};

signed main(){
    ll n,q;
    cin >> n >> q;
    UnionFindTree<ll> uft(n);
    for (int i = 0; i < q; ++i) {
        ll p,x,y;
        cin >>p>>x>>y;
        if(p == 0){
            uft.unite(x,y);
        }else{
            if(uft.same(x,y)) cout << 1 << endl;
            else cout << 0 << endl;
        }
    }

}



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

vector<string> split(string str, char del) {
  int first = 0;
  int last = str.find_first_of(del);
  vector<string> result;

  while (first < str.size()) {
    result.push_back(str.substr(first, last - first));
    first = last + 1;
    last = str.find_first_of(del, first);
    if (last == string::npos) last = str.size();
  }
  return result;
}

void solve(long long A, long double B){
  long double ret = B * A;
  vector<string> v = split(to_string(ret), '.');
  cout << v[0] << endl;
}

int main(){
    long long A;
    scanf("%lld",&A);
    long double B;
    scanf("%Lf",&B);
    solve(A, B);
    return 0;
}


Measured memory_bytes: 3832
const input = require('fs').readFileSync('/dev/stdin', 'utf8');
const lines = input.trim().split('\n');

while (line = lines.shift()) {
    const numbers = line.split(' ').map(Number);

    // Edit from here
    let a = numbers[0, 0];
    let b = numbers[0, 1];

    if ( a === 0 && b === 0 ) { break; }

    if ( a > b ) {
        const tmp = a;
        a = b;
        b = tmp;
    } 

    const output = a + ' ' + b;
    // to here
    
    console.log(output);
    
}


Measured memory_bytes: 18824
#include <bits/stdc++.h>
using namespace std;
#pragma optimize("O3")

int A[55];
bool boleh[55];
int B[55];
int C[55];
int indx[55];
long long ncr[55][55];

long long ncrUpTo[55][55];

int cnt2[(1<<18)+5];
int s[55];

int main(){
    int N, K, S, T;
    scanf("%d%d%d%d", &N, &K, &S, &T);

    if( ((S&T) == S) && ((S|T) == T) ){
    }else{
        printf("0");
        return 0;
    }

    memset(ncr, 0, sizeof(ncr));
    ncr[0][0] = 1;
    for(int i = 1; i <= N; i ++){
        ncr[i][0] = 1;
        for(int j = 1; j <= i; j ++){
            ncr[i][j] = ncr[i-1][j] + ncr[i-1][j-1];
        }
    }

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

    for(int i = 0; i < N; i ++){
        scanf("%d", &A[i]);
        boleh[i] = true;
        //printf("A[%d]=%d\n", i, A[i]);
    }

    int L = 0;
    for(int i = 0; i < 20; i ++){
        if( (S&(1<<i)) == (T&(1<<i)) ){
            for(int j = 0; j < N; j ++){
                if( (S&(1<<i)) != (A[j]&(1<<i)) ){
                    boleh[j] = false;
                    //printf("boleh[%d]=false\n", j);
                }
            }
        }else{
            indx[L ++] = i;
        }
    }

    for(int i = 0; i < L; i ++){
        for(int j = 0; j < N; j ++){
            if(A[j]&(1<<indx[i])){
                B[j] |= (1<<i);
            }
        }
    }

    int M = 0;
    for(int i = 0; i < N; i ++){
        if(boleh[i]){
            C[M ++] = B[i];
        }
    }

    for(int i = 0; i < M; i ++){
        //printf("C[%d]=%d\n", i, C[i]);
    }

    memset(cnt2, 0, sizeof(cnt2));
    long long ans = 0;
    for(int U = 0; U < (1<<L); U ++){
        long long f = 0;

        int sizeS = 0;
        for(int i = 0; i < M; i ++){
            if(!cnt2[U&C[i]]){s[sizeS++] = (U&C[i]);}
            cnt2[U&C[i]] ++;
        }

        for(int k = 0; k < sizeS; k ++){
            int j = s[k];
            int cnt = cnt2[j];
            f += ncrUpTo[cnt][K];
            cnt2[j] = 0;
        }

        int temp = __builtin_popcount(U);
        if(temp&1){
            ans -= f;
        }else{
            ans += f;
        }
    }

    printf("%lld", ans);
    return 0;
}


Measured memory_bytes: 4864
n,k=gets.chomp.split.map(&:to_i)
v=gets.chomp.split.map(&:to_i)
vs1=[0]
vs2=[0]
1.upto(n) do |i|
  vs1 << vs1[i-1] + v[i-1]
  vs2 << vs2[i-1] + v[n-i]
end

ans = 0

1.upto([k,n].min) do |i|
  # 左からいくつとるか
  i.downto(0) do |l|
    t = 0
    minus = []
    # 右からとる数
    r = i - l
    0.upto(l-1) do |j|
      t += v[j]
      minus << v[j] if v[j] < 0
    end
    0.upto(r-1) do |j|
      t += v[n-j-1]
      minus << v[n-j-1] if v[n-j-1] < 0
    end
    minus.sort!
    if k-i>0
      0.upto([minus.size-1,k-i-1].min) do |k|
        t -= minus[k]
      end
    end

    ans = t if t > ans
  end
end
puts ans

Measured memory_bytes: 2172
t = list(int(input()) for _ in range(3))
x = int(input())
c = 0
for i in range(min(x//500,t[0])+1):
    a = t[:]
    d = x-500*i
    if d <= 100*a[1]+50*a[2]:
        for j in range(a[1]+1):
            if d >= 100*j:
                r = d-100*j
                if r <= 50*a[2]:
                    c += 1
            else:
                break
print(c)

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

struct node{
  struct node *right;
  struct node *left;
  struct node *parent;
  int key;
};
typedef struct node * Node;

void insert(int);
void preorder(Node);
void inorder(Node);
void treeDelete(Node);
Node treeMinimum(Node);
Node getSuccessor(Node);
Node treeSearch(Node, int);

#define NIL NULL

Node root;

Node treeMinimum(Node x){
while(x->left != NIL) x = x->left;
return x;
}

Node treeSearch(Node u, int k){
    while (u != NIL && k != u->key){
        if(k < u->key) u = u->left;
        else u = u->right;
    }
    return u;
}

void treeDelete(Node z){
    Node x;
    Node y;
    if(z->left == NIL || z->right == NIL) y = z;
    else y = getSuccessor(z);
    if(y->left != NIL) x = y->left;
    else x = y->right;
    if(x != NIL) x->parent = y->parent;
    if(y->parent == NIL) root = x;
    else if(y == y->parent->left) y->parent->left = x;
    else y->parent->right = x;
    if(y!=z)z->key = y->key;
}

Node getSuccessor(Node x){
    Node y;
    if(x->right != NIL) return treeMinimum(x->right);
    y = x->parent;
    while(y != NIL && x == y->right){
        x = y;
        y = y->parent;
    }
    return y;
    }

void insert(int k){
  Node y = NIL;
  Node x = root;
  Node z;

  z = malloc(sizeof(struct node));
  z->key = k;
  z->left = NIL;
  z->right = NIL;

     while (x != NIL){
         y = x;
         if (z->key < x->key)
             x = x->left;
         else 
             x = x->right;
     }
     z->parent = y;
    if (y == NIL)
        root = z;
    else if (z->key < y->key)
        y->left = z;
    else 
        y->right = z;

}

void inorder(Node u){
if (u == NIL) return;
inorder(u->left);
printf(" %d", u->key);
inorder(u->right);
}

void preorder(Node u){
    if(u == NIL) return;
    printf(" %d", u->key);
preorder(u->left);
preorder(u->right);
}


int main(){
  int n, i, x;
  char com[20];
  scanf("%d", &n);
  
  for ( i = 0; i < n; i++ ){
      scanf("%s", com);
      if ( com[0] == 'f' ){
      scanf("%d", &x);
      Node t = treeSearch(root, x);
      if ( t != NIL ) printf("yes\n");
      else printf("no\n");
      }
      if(com[0] == 'i'){
          scanf("%d", &x);
      insert(x);
      }
      else if(com[0] == 'p'){
      inorder(root);
      printf("\n");
      preorder(root);
      printf("\n");
}
 else if ( com[0] == 'd' ){
      scanf("%d", &x);
      treeDelete(treeSearch(root, x));
    }
}
  return 0;
}



Measured memory_bytes: 20440
using System;
using System.Collections.Generic;

class B
{
	static void Main()
	{
		var M = 1000000007;
		var n = int.Parse(Console.ReadLine());
		var c = Array.ConvertAll(new int[n], _ => int.Parse(Console.ReadLine()));

		var map = new Stack<int>[200001];
		for (int i = n - 1; i >= 0; i--)
		{
			if (map[c[i]] == null) map[c[i]] = new Stack<int>();
			map[c[i]].Push(i);
		}

		var dp = new long[n];
		dp[0] = 1;

		for (int i = 0; i < n - 1; i++)
		{
			map[c[i]].Pop();

			dp[i + 1] = (dp[i + 1] + dp[i]) % M;
			if (map[c[i]].TryPeek(out var j) && j - i >= 2)
				dp[j] = (dp[j] + dp[i]) % M;
		}

		Console.WriteLine(dp[^1]);
	}
}


Measured memory_bytes: 50004
#include <bits/stdc++.h>
typedef long long ll;
const int mod=1e9+7;
const int maxn=2e6+16;
const ll INF=100000000000005;
const double eps=1e-11;
using namespace std;
ll n,m,p;
map<ll,ll>mp;
ll sum[maxn];
ll num[maxn];
int main()
{
    ll res=0;//记录最终答案
    scanf("%lld%lld",&n,&m);
    for(int i=1;i<=n;i++)
    {
        scanf("%lld",&num[i]);
        sum[i]=sum[i-1]+num[i];
    }
    for(int i=1;i<=n;i++)
        sum[i]=(sum[i]-i%m+m)%m;//预处理前缀和
    ll low=min(m-1,n);
    for(int i=0;i<=low;i++)
    {
        res+=mp[sum[i]];
        mp[sum[i]]++;
    }
    for(int i=low+1;i<=n;i++)
    {
        mp[sum[i-m]]--;
        res+=mp[sum[i]];
        mp[sum[i]]++;
    }
    printf("%lld\n",res);
    return 0;
}

Measured memory_bytes: 18560
import std.stdio;
import std.conv;
import std.algorithm;
import std.string;
import std.file;
import std.math;
int main() {
	char[] digits = ['0', '1', '2', '3', '4', '5', '6', '7', '8', '9'];
	
	string l;
	while((l = readln().chomp, l.length)){
		bool overflow = false;
		
		int n = to!int(l);
		
		char[] a, b, c;
		for(int i=0; i<80; i++) c ~= '0';
		
		a = ['1'];
		if(a.length > 80) overflow = true;
		a = c ~ a;
		a = a[$ - 80 .. $];
		
		for(char k = 1; k <= n; k++){
			for(int i = 79; i >= 0; i--){
				int t = (c[i] - '0') + (a[i] - '0') * k;
				if(t >= 10){
					if(i == 0) overflow = true, t = 0;
					else while(t >= 10) c[i-1] += 1, t -= 10;
					}
				c[i] = digits[t];
				}
			a[] = c[];
			for(int i=0; i<80; i++) c[i] = '0';
			}
		
		if(overflow) printf("overflow\n");
		else{
			int i;
			for(i = 0; i < 79; i++){
				if(a[i] != '0') break;
				}
			a = a[i .. $];
			write(a ~ '\n');
			}
		}
	return 0;
	}

Measured memory_bytes: 1084
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define pb push_back
#define mp make_pair
#define F first
#define S second

signed main(){
#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif

	string s,t;
	cin >> s >> t;
	int a = s.size(), b = t.size();
	int m = 1000;
	for(int i=0; i<=a-b; i++){
		int x=0;
		for(int j=i; j<i+b; j++){
			if(s[j]!=t[j-i])
				x++;
		}
		m = min(m,x);
	}

	cout << m;


	
	

	return 0;
}

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

int main()
{
  int n, l;
  vector<string> S;
  string ans;
  cin >> n >> l;
  for (int i = 0; i < n; i++)
  {
    string buf;
    cin >> buf;
    S.push_back(buf);
  }
  for (int i = 0; i < n; i++)
  {
    ans += *min_element(S.begin(), S.end());
    int bufIndex = min_element(S.begin(), S.end()) - S.begin();
    S.erase(S.begin() + bufIndex);
  }
  cout << ans << endl;
}


Measured memory_bytes: 3648
#include <bits/stdc++.h>
using namespace std;
#include<chrono>
#define ll long long
#define ld long double
#define eb emplace_back
#define pb push_back
#define mt make_tuple
#define tc  ll t; cin>>t; while(t--)
#define io ios::sync_with_stdio(false),cin.tie(NULL),cout.tie(NULL);
#define F first
#define S second
#define vi vector<ll>
#define pii pair<ll,ll>
#define mp make_pair
#define all(x) (x).begin(),(x).end()
#define vii vector<pair<ll,ll>>
ll gcd(ll n,ll m)
{
    if(n==0)
            return m;
    return gcd(m%n,n);
}
bool ifprime(ll n)
{
if(n==1)
return false;
    ll i;
for(i=2;i*i<=n;i++)
{
if(n%i==0)
return false;
 
}
return true;
}
void disp(vi v)
{
    for(auto u:v)
    cout<<u<<" ";
    cout<<"\n";
}
void remleadzero(vector<int> &v)
{
    vector<int> u;
    int i=0;
    while(v[i]==0)
        i++;
    while(i<v.size())
    {
        u.push_back(v[i]);
        i++;
    }
    v=u;
}
#define mod 1000000007LL
/*
void myscanf(long long *n)
{
    register long long c=getchar_unlocked();
    *n=0;
    for(;(c<48 ||c>57);c=getchar_unlocked())
        ;
    for(;(c>47 && c<58);c=getchar_unlocked())
    {
        *n=(*n<<1)+(*n<<3)+(c&15);
    }
 
}
void fastscan(long long &number)
{
    bool negative = false;
    register long long c;
 
    number = 0;
 
    c = getchar_unlocked();
    if (c=='-')
    {
 
        negative = true;
 
        c = getchar_unlocked();
    }
 
 
    for (; (c>47 && c<58); c=getchar_unlocked())
        number = number *10 + c - 48;
 
 
    if (negative)
        number *= -1;
}
*/
ll fast_expo(ll n,ll m, ll md)
{
    ll a=1;
    while(m>0)
    {
        if(m&1) a=(a*n)%md;
        n=(n*n)%md;
        m/=2;
    }
    return a%md;
}
long long sqroot(long long n){
    long double N = n;
    N = sqrtl(N);
    long long sq = N-2;
    sq = max(sq,0LL);
    while(sq*sq<n){
        sq++;
    } 
    if((sq*sq)==n)
        return sq;
    return -1;
}
int dig(int n){
    int ret=0;
    while(n>0){
        n/=10;
        ret++;
    }
    return ret;
}
int main()
{
    io;
    char a;
    cin>>a;
    a++;
    cout<<a;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll long long
#define INF (1LL << 60)
#define MOD 1000000007
#define EPS 1e-10
#define rep(i,n) for(int i=0;i<(int)(n);++i)
#define rrep(i,n) for(int i=(int)(n)-1;i>=0;--i)
#define srep(i,s,t) for(int i=(int)(s);i<(int)(t);++i)
#define each(a,b) for(auto& (a): (b))
#define all(v) (v).begin(),(v).end()
#define len(v) (int)(v).size()
#define zip(v) sort(all(v)),v.erase(unique(all(v)),v.end())
#define cmx(x,y) x=max(x,y)
#define cmn(x,y) x=min(x,y)
#define fi first
#define se second
#define pb push_back
#define show(x) cout<<#x<<" = "<<(x)<<endl
#define spair(p) cout<<#p<<": "<<p.fi<<" "<<p.se<<endl
#define sar(a,n) cout<<#a<<":";rep(pachico,n)cout<<" "<<a[pachico];cout<<endl
#define svec(v) cout<<#v<<":";rep(pachico,v.size())cout<<" "<<v[pachico];cout<<endl
#define svecp(v) cout<<#v<<":";each(pachico,v)cout<<" {"<<pachico.first<<":"<<pachico.second<<"}";cout<<endl
#define sset(s) cout<<#s<<":";each(pachico,s)cout<<" "<<pachico;cout<<endl
#define smap(m) cout<<#m<<":";each(pachico,m)cout<<" {"<<pachico.first<<":"<<pachico.second<<"}";cout<<endl

using namespace std;

typedef pair<int,int> P;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<double> vd;
typedef vector<P> vp;
typedef vector<string> vs;

const int MAX_N = 100005;

ll f[1001];
ll dp[33][1001];
int mn[33][1001];

int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int a,b,K;
    cin >> a >> b >> K;
    vl t(K+1);
    rep(i,K+1){
        cin >> t[i];
    }
    rep(i,b-a+1){
        f[i] = INF;
    }
    f[1] = 0;
    srep(i,2,b-a+1){
        rep(j,K+2){
            rep(k,i+1){
                dp[j][k] = INF;
                mn[j][k] = 0;
            }
        }
        dp[0][0] = 0;
        rep(j,K+1){
            srep(k,j+1,i+1){
                srep(l,max(mn[j][k],j),k){
                    if(dp[j+1][k] > dp[j][l]+(k-l)*t[j]+f[k-l]){
                        dp[j+1][k] = dp[j][l]+(k-l)*t[j]+f[k-l];
                        mn[j+1][k] = l;
                    }
                }
            }
        }
        srep(j,2,K+2){
            cmn(f[i],dp[j][i]);
        }
    }
    printf("%.12lf\n",(double)f[b-a]/(b-a));
    return 0;
}



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

int main(void){
    int h1, m1, h2, m2, k;
    cin >> h1 >> m1 >> h2 >> m2 >> k;
    int x = h2 * 60 + m2 - (h1 * 60 + m1);
    x -= k;
    
    cout << x << endl;
    
    return 0;
}


Measured memory_bytes: 3636
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;
public class Main {

	public static void main(String[] args) throws IOException{
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		ArrayList<Double> list = new ArrayList<Double>();
		
		while(true){
			String num1 = br.readLine();
			String num2 = br.readLine();
 			double x = Double.parseDouble(num1);
			double y = Double.parseDouble(num2);
			if(x == 0 && y == 0) break;
			list.add(x);
			list.add(y);
		}
		for (int i = 0 ; i < list.size() ; i++ ){
			double a = list.get(i);
			double b = list.get(i+1);
			System.out.printf("%.8f\n",a*Math.sqrt(4*b*b+a*a)+a*a);
			i++;
		}
	}
}

Measured memory_bytes: 16928
h,w=gets.split.map(&:to_i)
l=[0]*26
h.times do
  a=gets.chomp
  a.each_char do |c|
    l[c.ord-"a".ord]+=1
  end
end
l.delete(0)
i=0
k=h*w
l.size.times do |i|
  k-=l[i]/4*4
  l[i]%=4
end
if h*w-((h/2*2)*(w/2*2))<k
  puts "No"
  exit
end
l.size.times do |i|
  k-=l[i]/2*2
  l[i]%=2
end
if (h*w).odd?&&k>2||(h*w).even?&&k>1
  puts "No"
else
  puts "Yes"
end


Measured memory_bytes: 14348
#include <iostream>
#include <algorithm>
using namespace std;
int main(){
  long long n,a,b;
  cin >> n >> a >> b;
  long long ans = 0;
  long long x_prev,x_next;
  cin >> x_next;
  for(int i = 0; i < n-1; i++){
    x_prev = x_next;
    cin >> x_next;
    ans += min((x_next - x_prev) * a, b);
  }
  cout << ans << endl;
}


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

using namespace std;

int main(){
  int n, a, b, i, j, tmp, sum = 0;
  cin >> n >> a >> b;
  string s;
  for(i=0; i<=n; i++) {
    tmp = 0;
  	s = to_string(i);
    for(j=0; j<s.length(); j++) {
       tmp += (int)(s[j] - '0');
    }
    if(a <= tmp && tmp <= b) sum += i; 
  }
  
  printf("%d", sum);
  return 0;
}

Measured memory_bytes: 256
def gcd(x, y):
    while y != 0:
        (x, y) = (y, x % y)
    return x
N = int(input())

out = 0
for i in range(1,N+1):
    for j in range(i,N+1):
        for k in range(j,N+1):   
            gcd_num = gcd(gcd(i,j),k)
            if i == j and j == k:
                out += gcd_num
            elif i == j or j == k:
                out += 3 * gcd_num
            else:
                out += 6 * gcd_num
print(out)

Measured memory_bytes: 9228
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define pb push_back
#define mp make_pair
#define SORT(x) sort(x.begin(),x.end())

int main(){
  int N,M;
  cin >> N >> M;
  vector<int> count(N+1,0);
  
  
  rep(i,M){
    int L,R;
    cin >> L >> R;
    L--;
    count.at(L)++;
    count.at(R)--;
  }
  
  int ans = 0;
  rep(i,N){
    if(count.at(i)==M) ans++;
    count.at(i+1) += count.at(i);
  }
  cout << ans << endl;
}

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

int a[100000],l=0,r=0,lb=0,rb=0,cnta=0,cntb=0;
string b[100000];

int a_empty(){
  if(cnta==0) return 1;
  else return 0;
}
void a_push(int n){
  a[r]=n;
  r++;
  if(cnta==100000) exit(1);
  cnta++;
  if(r==100000) r=0;
}

void b_push(string n){
  b[rb]=n;
  rb++;
  if(cntb==100000) exit(2);
  cntb++;
  if(rb==100000) rb=0;
}

int a_front(){
  return a[l];
}

string b_front(){
  return b[lb];
}

int a_pop(){
  int p;
  p=a[l];
  l++;
  cnta--;
  if(l==100000) l=0;
  return p;
}

string b_pop(){
  string p;
  p=b[lb];
  lb++;
  cntb--;
  if(lb==100000) lb=0;
  return p;
}


int main(){
  int n,q,N,cnt=0;
  string s;
  cin>>n>>q;
  for(int i=0;i<n;i++){
    cin>>s>>N;
    a_push(N);
    b_push(s);
  }
  while(!a_empty()){
    if(a_front()-q > 0){
      cnt+=q;
      a_push(a_front()-q);
      a_pop();
      b_push(b_front());
      b_pop();
    }else{
      cnt+=a_front();
      cout<<b_front()<<" "<<cnt<<endl;
      a_pop();
      b_pop();
    }
  }
  return 0;
}



Measured memory_bytes: 6648