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

int main()
{
  int N,M;scanf("%d",&N);
  string s[N];for(int i=0;i<N;i++)cin>>s[i];
  scanf("%d",&M);
  string t[M];
  for(int i=0;i<M;i++)cin>>t[i];
  map<string,int> m;
  for(int i=0;i<N;i++)m[s[i]]++;
  for(int i=0;i<M;i++)m[t[i]]--;
  int ans=0;
  for(auto ite : m)ans=max(m[ite.first],ans);
  printf("%d",ans);
}

Measured memory_bytes: 3764
#include <bits/stdc++.h>
using namespace std;
 
typedef long long int ll;
typedef unsigned long long ull;
typedef long double ld;
const int mod = 1e9 + 7;
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define INF 1999999999
#define MODA 1000000007
#define PI 3.1415926535897932384626433
//cout << fixed << setprecision(2);
 
 
int main()
{
    // freopen("input.txt", "r", stdin);
    // freopen("output.txt", "w", stdout);
    ios::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    int n;
    cin >> n;
    vector<ll> a(n);
    for (int i = 0; i < n; i++)
    {
        cin >> a[i];
        if (a[i] == 0)
        {
            cout << 0 << endl;
            return 0;
        }
    }
 
    ll ans = a[0];
    for (int j = 1; j < n; j++)
    {
        ans *= a[j];
        
    }
    if (0 < ans && ans <= 1000000000000000000)
    {
        cout << ans << endl;
    }
    else
        cout << "-1" << endl;
    return 0;
}

Measured memory_bytes: 3964
#include <iostream>
#include <map>
#include <vector>
#include <algorithm>
#include <string>
#include <queue>

#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

typedef long long int lli;
using namespace std;
// #define int long long int

inline void swap(int &a, int &b) {
    int tmp = a;
    a = b;
    b = tmp;
}

signed main() {
    int R, G, B, N;
    cin >> R >> G >> B >> N;

    int ans = 0;
    for (int r = 0; R * r <= N; r++) {
        for (int g = 0; R * r + G * g <= N; g++) {
            int need = N - (R * r + G * g);
            if (need % B == 0) ans++;
        }
    }

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


Measured memory_bytes: 256
#if 1
#include <iostream>
#include <fstream>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <unordered_map>
#include <unordered_set>
#include <queue>
#include <stack>
#include <array>
#include <deque>
#include <algorithm>
#include <utility>
#include <cstdint>
#include <functional>
#include <iomanip>
#include <numeric>
#include <assert.h>

auto& in = std::cin;
auto& out = std::cout;

template<typename T>
void fill_all(T& arr, const T& v) {
	arr = v;
}
template<typename T, typename ARR>
void fill_all(ARR& arr, const T& v) {
	for (auto& i : arr) { fill_all(i, v); }
}

int32_t N;
int32_t num[500];
int main()
{
	using std::endl;
	in.sync_with_stdio(false);
	out.sync_with_stdio(false);
	fill_all(num, 55);
	in >> N;
	for (int32_t i = 0; i < N; ++i)
	{
		char str[55];
		int32_t t[500] = {};
		in >> str;
		for (auto iter = str; *iter != '\0'; ++iter)
		{
			++t[*iter];
		}
		for (int32_t i = 0; i < 500; ++i)
		{
			num[i] = std::min(num[i], t[i]);
		}
	}

	for (int32_t i = 0; i < 500; ++i)
	{
		for (int32_t j = 0; j < num[i]; ++j) {
			out << (char)(i);
		}
	}
	out<<  endl;

	return 0;
}
#endif


Measured memory_bytes: 256
// Author : Mohamed Sameh
#include <bits/stdc++.h>
#define pb push_back
#define f first
#define s second
#define all(v) v.begin(),v.end()
#define rall(v) v.rbegin(),v.rend()
#define SZ(a) (int)a.size()
#define Flush fflush(stdout);
typedef long long ll ;
using namespace std ;
int main()
{
    ios::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
    int k ;
    cin >> k ;
    priority_queue<ll , vector<ll> , greater<ll>> pq ;
    pq.push(1);
    set<ll> st ;
    
    while (1)
    {
        k--;
        ll cur = pq.top();
        pq.pop(); 
        //cout << cur <<"\n";
        if (k == 0 )
        {
            cout << cur <<"\n"; 
            break; 
        }
        if (cur < 10 )
        {
            if (st.count(cur + 1 ) == 0 )
            pq.push(cur + 1 );  
            st.insert(cur + 1 );
        }
        
        if (st.count(cur * 10 + cur%10 ) == 0 )
        {
            pq.push(cur*10   + cur%10 ); 
            st.insert(cur * 10 + cur % 10 );
        }
        if(st.count(cur * 10 + cur%10 + 1 ) == 0 && cur % 10 != 9 )
        {
            pq.push(cur * 10 + cur%10 + 1 ); 
            st.insert(cur * 10 + cur % 10 + 1  );
        }
        if(st.count(cur * 10 + cur%10 - 1 ) == 0 && cur % 10 != 0  )
        {
            pq.push(cur * 10 + cur%10 - 1 );
            
            st.insert(cur * 10 + cur % 10- 1 );
        
        } 
    }
}


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

int main() {
  int A, B;
  cin >> A >> B;
  if (B==1) {
    cout << 0 << endl;
  }
  else {
    A--;
    B-=2;
    cout << B/A+1 << endl;
  }
}

Measured memory_bytes: 3640
H, W = map(int, input().split())
if H == 1 or W == 1:
    print(1)
elif H % 2 == 0:
    print(int(H * W / 2))
else:
    if W % 2 == 0:
        print(int(H * W / 2))
    else:
        print(int(((H * W) + 1) / 2))

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

typedef long long int ll;

ll fizzbuzz(ll x, ll y, ll r) {
    ll x1 = x / 3LL;
    ll x2 = x / 5LL;
    ll x3 = x / 15LL;

    ll y1 = y / 3LL;
    ll y2 = y / 5LL;
    ll y3 = y / 15LL;

    return ((x - y) - ((x1 + x2 - x3) - (y1 + y2 - y3))) * r + 4LL * ((x1 + x2) - (y1 + y2));
}

int main() {
    ll s;
    cin >> s;

    ll l = -1LL, r = 1.5e18;
    ll _sum;
    ll _c;
    while (r - l >= 1) {
        ll m = (r + l) / 2LL;
        ll sum = 0LL;
        ll c = 1LL;
        ll x = 1LL;
        bool flag = false;
        while (1) {
            ll add = fizzbuzz(x * 10LL - 1LL, x - 1LL, c);
            if (add < 0) {
                flag = true;
                break;
            }
            if (sum + add > s) break;
            if (x * 10LL > m) break;
            sum += add;
            x *= 10LL;
            c += 1LL;
        }

        ll fz = fizzbuzz(m, x-1LL, c);
        if (flag || fz < 0) {
            r = m;
            continue;
        }
        sum += fz;
        ll prefix = fizzbuzz(m, m-1LL, c);

        if (sum > s - 1 && sum - prefix < s) {
            l = r = m;
        }
        if (sum > s) {
            r = m;
        } else {
            l = m;
        }
        _sum = sum;
        _c = c;
    }

    string ans;
    for (ll i = l; (ll)ans.size() - fizzbuzz(l, l-1, _c) <= 20; i++) {
        if (i % 3LL == 0) {
            ans += "Fizz";
        }
        if (i % 5LL == 0) {
            ans += "Buzz";
        }
        if (i % 3LL && i % 5LL) {
            stringstream ss;
            ss << i;
            string tmp;
            ss >> tmp;
            ans += tmp;
        }
    }
    ll t = fizzbuzz(l, l-1, _c) - (_sum - s);

    cout << string(ans.begin() + t - 1, ans.begin() + t + 19) << endl;

    return 0;
}

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

using namespace std;

typedef long long ll;

const int MOD = 1e9 + 7;
const int MAXN = 100005;

int a[MAXN], inv[MAXN], pref[MAXN];

int n, res = 0; 

void init()
{
	inv[1] = 1;
	for (int i = 2; i <= n; i++)
		inv[i] = (ll)(MOD - MOD / i) * inv[MOD % i] % MOD;
	pref[1] = inv[1];
	for (int i = 2; i <= n; i++)
		pref[i] = ((ll)pref[i - 1] + inv[i]) % MOD;
}

int main()
{
	scanf("%d", &n);
	for (int i = 1; i <= n; i++)
		scanf("%d", &a[i]);
	init();
	for (int i = 1; i <= n; i++)
	{
		res = (res + ((ll)pref[i] + pref[n - i + 1] - pref[1]) % MOD * a[i] % MOD) % MOD;
		if (res < 0)
			res += MOD;
	}
	for (int i = 1; i <= n; i++)
		res = (ll)res * i % MOD;
	printf("%d\n", res);
	return 0;
}


Measured memory_bytes: 1408
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		var sc = new Scanner(System.in);
		var n = sc.nextInt();
		sc.close();

		var d = new int[n + 1];
		for (var i = 1; i <= n; i++) {
			for (var j = i; j <= n; j+=i) {
				d[j]++;
			}
		}

		var sum = 0L;
		for (var i = 1; i <= n; i++) {
			sum += (long)i * d[i];
		}

		System.out.println(sum);
	}
}


Measured memory_bytes: 74844
#!/usr/bin/env python3
import sys


def solve(N: int):
    if N <= 999:
        print("ABC")
    else:
        print("ABD")


# Generated by 1.1.4 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    solve(N)

if __name__ == '__main__':
    main()


Measured memory_bytes: 2940
#include<iostream>
#include<cmath>
#include<algorithm>
#include<iomanip>
#include<string>
#include<vector>
#include<cstdio>
#include<cstring>
#include<map>
#include<set>
#include<fstream>
#include<sstream>
#include<queue>
#include<iterator>
using namespace std;
int main(){
	string s;
	cin>>s;
	cout<<s[0]<<s.size()-2<<s[s.size()-1]<<endl;






  return 0;
}


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

#define fr first
#define sc second
#define mk make_pair
#define pb push_back
#define ok puts("OK");
#define sz(s) (int)s.size()
#define all(s) s.begin(), s.end()

using namespace std;

int a, b, c, dp[105][105][105], ans = 1e9 + 7;

main()
{
    cin >> a >> b >> c;

    memset(dp, 0x3f3f3f3f, sizeof(dp) );

    dp[a][b][c] = 0;
    for (int i = a; i <= 100; i++)
        for (int j = b; j <= 100; j++)
            for (int k = c; k <= 100; k++)
            {
                if (i && j)
                    dp[i][j][k] = min( dp[i][j][k], dp[i - 1][j - 1][k] + 1 );
                if (i && k)
                    dp[i][j][k] = min( dp[i][j][k], dp[i - 1][j][k - 1] + 1 );
                if (j && k)
                    dp[i][j][k] = min( dp[i][j][k], dp[i][j - 1][k - 1] + 1 );
                if (i > 1)
                    dp[i][j][k] = min( dp[i][j][k], dp[i - 2][j][k] + 1 );
                if (j > 1)
                    dp[i][j][k] = min( dp[i][j][k], dp[i][j - 2][k] + 1 );
                if (k > 1)
                    dp[i][j][k] = min( dp[i][j][k], dp[i][j][k - 2] + 1 );
            }
    for (int i = 0; i <= 100; i++)
        ans = min(ans, dp[i][i][i]);

    cout << ans << endl;
}


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

#define rep(i, n) for(int i = 0; i < (n); i++)
#define repp(i, l, r) for(int i = (l); i < (r); i++)
#define per(i, n) for(int i = ((n)-1); i >= 0; i--)
#define perr(i, l, r) for(int i = ((r)-1); i >= (l); i--)
#define all(x) (x).begin(),(x).end()
#define MOD 1000000007
#define IINF 1000000000
#define LINF 1000000000000000000
#define SP <<" "<<
#define CYES cout<<"Yes"<<endl
#define CNO cout<<"No"<<endl
#define CFS cin.tie(0);ios::sync_with_stdio(false)

typedef long long LL;
typedef long double LD;

int main(){
  while(1){
    char t;
    cin >> t;
    if(t=='#') return 0;
    vector<vector<pair<int,char>>> card(4,vector<pair<int,char>>(13));
    map<char,int> mp;
    repp(i,2,10) mp['0'+i]=i;
    mp['T']=10,mp['J']=11,mp['Q']=12,mp['K']=13,mp['A']=14;
    char x;
    rep(i,4){
      rep(j,13){ 
        cin >> x >> card[i][j].second;
        card[i][j].first=mp[x];
      }
    }
    int leader=0;
    int ew=0,ns=0;
    rep(i,13){
      char l = card[leader][i].second;
      pair<int,int> x={-1,-1};
      rep(j,4){
        if(card[j][i].second==l) x=max(x,{card[j][i].first,j});
      }
      rep(j,4){
        if(card[j][i].second==t) x={-1,-1};
      }
      rep(j,4){
        if(card[j][i].second==t) x=max(x,{card[j][i].first,j});
      }
      if(x.second%2){
        ew++;
      }else{
        ns++;
      }
      leader=x.second;
    }
    if(ew>ns) cout << "EW" SP ew-6 << endl;
    else cout << "NS" SP ns-6 << endl;
  }
  return 0;
}



Measured memory_bytes: 2996
package main

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

func out(x ...interface{}) {
	fmt.Println(x...)
}

var sc = bufio.NewScanner(os.Stdin)

func getInt() int {
	sc.Scan()
	i, e := strconv.Atoi(sc.Text())
	if e != nil {
		panic(e)
	}
	return i
}

func getInts(N int) []int {
	ret := make([]int, N)
	for i := 0; i < N; i++ {
		ret[i] = getInt()
	}
	return ret
}

func getString() string {
	sc.Scan()
	return sc.Text()
}

// min, max, asub, absなど基本関数
func max(a, b int) int {
	if a > b {
		return a
	}
	return b
}

func min(a, b int) int {
	if a < b {
		return a
	}
	return b
}

func asub(a, b int) int {
	if a > b {
		return a - b
	}
	return b - a
}

func abs(a int) int {
	if a >= 0 {
		return a
	}
	return -a
}

func lowerBound(a []int, x int) int {
	idx := sort.Search(len(a), func(i int) bool {
		return a[i] >= x
	})
	return idx
}

func upperBound(a []int, x int) int {
	idx := sort.Search(len(a), func(i int) bool {
		return a[i] > x
	})
	return idx
}

// Trie :
type Trie struct {
	c     int
	child [26]int
	cnt   [26]int
	p     int
	fin   bool
}

func rev(str string) string {
	s := []byte(str)
	N := len(s)
	for i := 0; i < N/2; i++ {
		s[i], s[N-1-i] = s[N-1-i], s[i]
	}
	return string(s)
}

func main() {
	sc.Split(bufio.ScanWords)
	sc.Buffer([]byte{}, 1000000)

	trie := make([]Trie, 1100000)
	for i := 0; i < 1100000; i++ {
		for j := 0; j < 26; j++ {
			trie[i].child[j] = -1
		}
	}
	p := 1
	queries := make([]int, 0)

	n := getInt()
	for i := 0; i < n; i++ {
		str := rev(getString())
		now := 0
		for j := 0; j < len(str); j++ {
			c := int(str[j] - 'a')
			if trie[now].child[c] == -1 {
				trie[now].child[c] = p
				p++
				trie[trie[now].child[c]].p = now
			}
			now = trie[now].child[c]
			trie[now].c = c
		}
		trie[now].fin = true
		queries = append(queries, now)
		have := make([]bool, 26)
		for i := len(str) - 1; i >= 0; i-- {
			c := str[i] - 'a'
			have[c] = true
			now = trie[now].p
			for j := 0; j < 26; j++ {
				if have[j] {
					trie[now].cnt[j]++
				}
			}
		}
	}
	ans := 0
	for _, pos := range queries {
		p := trie[pos].p
		c := trie[pos].c
		ans += trie[p].cnt[c] - 1
	}
	out(ans)
}


Measured memory_bytes: 500376
#pragma comment(linker, "/STACK:1024000000,1024000000")
#include <iostream>
#include <cstdlib>
#include <cmath>
#include <string>
#include <cstring>
#include <cstdio>
#include <algorithm>
#include <queue>
#include <set>
#include <map>
#define re register
#define max(a,b) ((a)>(b)?(a):(b))
#define min(a,b) ((a)<(b)?(a):(b))
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
#define ms(arr) memset(arr, 0, sizeof(arr))
const int inf = 0x3f3f3f3f;
ll a,b,c;
int main() 
{
    cin>>a>>b>>c;
    if(a%2==0||b%2==0||c%2==0) {
        cout<<0;
        return 0;
    }
    cout<<min(min(a*b,a*c),b*c);
    return 0;
}

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

int N, K;
string S;

int main () {
	cin >> N;
	cin >> S;
	cin >> K;
	for(int i=0; i<S.length(); i++)
		if (S[i] != S[K-1])
			S[i] = '*';
	cout << S << endl;
	return 0;
}

Measured memory_bytes: 256
#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <math.h>
#include <cmath>
#include <vector>
#include <algorithm>
#include <map>
#include <set>
#include <unordered_map>
#include <unordered_set>
#include <cassert>
#include <random>
#include <deque>
#include <bitset>
#include <string>
#include <queue>
#include <complex>

//#define int long long

#define mp(a, b) make_pair(a, b)
#define all(v) (v).begin(), (v).end()
#define rall(v) (v).rbegin(), (v).rend()

#define endl '\n'

using namespace std;
typedef long long ll;
typedef long double ld;

mt19937 mrand(random_device{}());

double PI = acos((double)-1);
const ld eps = 1e-7;
const ll inf0 = 1023 * 1024 * 1024;
const ll inf = inf0 * inf0;
const ll mod = 1e9 + 7;
//const ll mod = 998244353;

void solve();
void scan();

signed main() {
#ifdef _DEBUG
	freopen("input.txt", "r", stdin);
	//freopen("output.txt", "w", stdout);
#endif
	cin.tie(0); cout.tie(0); ios_base::sync_with_stdio(false);
	cout << fixed; cout.precision(15);
	solve();
	return 0;
}

void solve() {
	ll a, b, c;
	cin >> a >> b >> c;
	if (c - a - b <= 1) cout << "No\n";
	else {
		ll t1 = (c - a - b) * (c - a - b);
		ll t2 = 4 * a * b;
		if (t2 < t1) cout << "Yes\n";
		else cout << "No\n";
	}
	return;
}

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

int main()
{
  ll n, k; cin>>n>>k;
  vector<ll> a(n, 0);
  rep(i, n) cin>>a[i];
  sort(a.begin(),a.end());
  ll x = lower_bound(a.begin(), a.end(), 0) - a.begin();
  ll y = upper_bound(a.begin(), a.end(), 0) - a.begin();
  ll nnum = x;
  ll znum = y-x;
  ll pnum = n-y;
  ll nc = nnum*pnum;
  ll zc = znum*(n-1+nnum+pnum)/2;
  if (nc<k && k<=nc+zc) {
    cout << 0 << endl;
    return 0;
  }

  vector<ll> vn, vp;
  for (int i=x-1; i>=0; i--) vn.push_back(-a[i]);
  for (int i=y; i<n; i++) vp.push_back(a[i]);

  ll l=0, r=1LL<<60;
  ll m = (l+r)/2;
  if (k <= nc) {
    // 答えの数値が負
    k = nc-k;
    while (l <= r) {
      ll sum = 0;
      for (int i=0; i<nnum; i++) {
        ll t = m/vn[i];
        sum += upper_bound(vp.begin(), vp.end(), t) - vp.begin();
      }
      if (k < sum) r = m-1;
      else l = m+1;
      m = (l+r)/2;
    }
    cout << -l << endl;

  } else {
    // 答えの数値が正
    k -= nc+zc;
    while (l <= r) {
      // 負同士
      ll nsum = 0;
      for (int i=0; i<nnum; i++) {
        ll t = m/vn[i];
        ll a = upper_bound(vn.begin(), vn.end(), t) - vn.begin();
        if (a > i) a--;
        nsum += a;
      }
      // 正同士
      ll psum = 0;
      for (int i=0; i<pnum; i++) {
        ll t = m/vp[i];
        ll a = upper_bound(vp.begin(), vp.end(), t) - vp.begin();
        if (a > i) a--;
        psum += a;
      }
      if (k <= (nsum+psum)/2) r = m-1;
      else l = m+1;
      m = (l+r)/2;
    }
    cout << l << endl;
  }

  return 0;
}


Measured memory_bytes: 4084
s = input()

x = len(s)

cnt = 1

ans = 0

for i in s:
    if cnt == 1:
        cnt = 0
        if i != "L":
            ans += 1
    else:
        cnt = 1
        if i != "R":
            ans += 1

if ans == x:
    print("Yes")
else:
    print("No")

Measured memory_bytes: 3060
L,R=[int(s) for s in input().split()]
if R-L>2018:
  print(0)
else:
  Lmod=L%2019
  Rmod=R%2019
  if Rmod<Lmod:
    print(0)
  else:
    ans=set()
    for i in range(Lmod,Rmod):
      for j in range(i+1,Rmod+1):
        ans.add(i*j%2019)
    print(min(ans))

Measured memory_bytes: 3188
def func(a):
    if a % 2 == 0:
        return a//2
    else:
        return 3*a + 1

tab = [False]*1000001
now = int(input())
ind = 1
while not tab[now]:
    tab[now] = True
    now = func(now)
    ind += 1

print(ind)


Measured memory_bytes: 10740
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<bitset>
#include<set>
#include<map>
#include<stack>
#include<queue>
#include<deque>
#include<iomanip>
#include<math.h>
using namespace std;

#define repr(i, a, b) for (int i = (int)(a); i < (int)(b); i++)
#define rep(i, n) repr(i, 0, n)
#define INF 2e9
#define MOD 1000000007
#define LINF (long long)4e18

using ll = long long;
using Pi = pair<int,int>;
using Pl = pair<ll,ll>;


int main(){
    int N; cin >> N;
    vector<int> H(N);
    rep(i,N) cin >> H[i];
    int M = 0;
    bool ok = true;
    rep(i,N){
        if(H[i] < M) ok = false;
        M = max(M,H[i] - 1);
    }
    if(ok) cout << "Yes" << endl;
    else cout << "No" << endl;
}


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


int main(){
  int n,k;
  ll sum=0;
  cin >> n >>k;
  vector<ll> a(n);
  rep(i,n)cin >> a[i];
  sort(a.begin(),a.end());
  rep(i,n-k) sum+=a[i];
  cout << sum << endl;
}

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

int main() {
	long long n, t, x=0;
	vector<long long> time;
	
	cin >> n >> t;
	for (int i = 0; i < n; i++) {
		long long v;
		cin >> v;
		time.push_back(v);
	}

	long long s = time[0];
	long long g = time[0] + t;

	for (int i = 1; i < n; i++) {
		long long node = time[i];
		if (node < g) {
			x += node - s;
			s = node;
			g = s + t;
		}
		else {
			x += t;
			s = node;
			g = s + t;
		}
	}

	x += t;
	cout << x << endl;
	
}

Measured memory_bytes: 2420
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cmath>
#include<vector>
using namespace std;

long long cnt;
int l;
int A[1000000];
int n;
vector<int> G;
//??????g????????????????????\?????????
void insertionSort(int A[], int n, int g){
	for (int i = g; i < n; i++) {
		int v = A[i];
		int j = i - g;
		while (j >= 0 && A[j] > v) {
			A[j + g] = A[j];
			j -= g;
			cnt++;
		}
		A[j + g] = v;
	}
}

void shellSort(int A[], int n) {
	//??°???G={1,4,13,40,121,364,1093.....?????????
	for (int h = 1; ;) {
		if (h > n)break;
		G.push_back(h);
		h = 3 * h + 1;
	}
	for (int i = G.size() - 1; i >= 0; i--) {
		insertionSort(A, n, G[i]);
	}
}
int main() {
	cin >> n;
	//??????????????\???scanf??¢??°????????¨
	for (int i = 0; i < n; i++) {
		scanf("%d", &A[i]);
		cnt = 0;
	}

	shellSort(A, n);
	cout << G.size() << endl;
	for (int i = G.size() - 1; i >= 0; i--) {
		printf("%d", G[i]);
		if (i)printf(" ");
	}
	printf("\n");
	printf("%d\n", cnt);
	for (int i = 0; i < n; i++)printf("%d\n", A[i]);
	return 0;
}

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

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)   FOR(i,0,n)
#define ALL(a)     (a).begin(),(a).end()
#define VI         vector<int>
#define MOD 1000000007

typedef long long int ll;

const ll INF=(ll)1e19;
//const int INF=(1<<30);


int main(){
  int m,n;
  cin >> n >> m;
  vector<int> a(n);
  int sum=0;
  REP(i,n){
    cin >> a[i];
    sum += a[i];
  }

  sort(ALL(a));
  reverse(ALL(a));

  int cnt=0;
  REP(i,n){
    if(a[i]*4*m >= sum)cnt++;
    else break;
  }
  cout << (cnt>=m ? "Yes" : "No") << endl;

}



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

long long memo[41];

long long solve(int rem){
  if(rem == 0) {
    return 1;
  }
  if(memo[rem] > 0) return memo[rem];

  long long sum = 0;
  for(int i=1;i<=3;i++){
    if(rem >= i) sum += solve(rem-i);
  }
  return (memo[rem] = sum);
}

int main(void){
  int n;

  while(cin>>n && n){
    long long day = solve(n);
    if(day % 3650 == 0) cout<<day / 3650<<endl;
    else cout<<day / 3650 + 1 << endl;
  }

  return 0;
}

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

int main() {
	
	int a, b;
	cin >> a >> b;
	if(a > b) cout << a - 1 << endl;
	else cout << a << endl;
	return 0;
}

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

struct Edge {
    int to;
};
using Graph = vector<vector<Edge>>;

// 幅優先探索
const int INF = 1e8;
vector<int> dist;  // 始点からの距離を記録
vector<int> dp;    // 前の点を記録
void bfs(const Graph &G, int s) {
    dist.assign((int)G.size(), INF);  // 初期化
    dp.assign((int)G.size(), INF);    // 初期化

    queue<int> que;
    que.emplace(s);  // sから探索する
    dist[s] = 0;
    while (que.size() != 0) {   // 幅優先探索
        int now = que.front();  // 現在の状態
        que.pop();
        for (auto e : G[now]) {
            if (dist[e.to] == INF) {  // 未探索の時のみ行う
                dist[e.to] = dist[now] + 1;
                dp[e.to] = now;
                que.emplace(e.to);
            }
        }
    }
}

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

    int V, E;
    cin >> V >> E;

    Graph G(V);
    for (int i = 0; i < E; i++) {
        int a, b;
        cin >> a >> b;
        a--, b--;
        G[a].push_back({b});
        G[b].push_back({a});
    }

    bfs(G, 0);

    for (int i = 0; i < V; i++) {
        if (dist[i] == INF) {
            cout << "No\n";
            return 0;
        }
    }

    cout << "Yes\n";
    for (int i = 1; i < V; i++) {
        cout << dp[i] + 1 << "\n";
    }

    return 0;
}


Measured memory_bytes: 10500
s = input().split()

stack = []
for i in s:
    if i.isdigit():
        stack.append(int(i))
    else:
        if i == "+":
            f = lambda x, y: x + y
        elif i == "-":
            f = lambda x, y: x - y
        elif i == "*":
            f = lambda x, y: x * y

        y = stack.pop()
        x = stack.pop()
        stack.append(f(x, y))

print(stack[0])


Measured memory_bytes: 5600
#pragma optimization_level 3
#pragma GCC optimize("Ofast,no-stack-protector,unroll-loops,fast-math,O3")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
//#pragma GCC target("avx,avx2,fma")
#include<bits/stdc++.h>
#define F first
#define S second
#define vec vector
#define pb push_back
#define pll pair<ll,ll>
#define pdd pair<ld, ld>
#define pq priority_queue
#define umap unordered_map
#define uset unordered_set
#define pii pair<int, int>
#define pnn pair<Node*, Node*>
#define uid uniform_int_distribution
#define FILE ifstream in("input.txt");ofstream out("output.txt");
#define fast cin.tie(0);cout.tie(0);cin.sync_with_stdio(0);cout.sync_with_stdio(0);
using namespace std;
typedef string str;
typedef long long ll;
typedef long double ld;
typedef unsigned int uint;
typedef unsigned long long ull;
mt19937 rnd(chrono::steady_clock::now().time_since_epoch().count());

int main() {
    fast;
    ll a; cin>>a;
    vec<ll> m;
    ll g = sqrt(a);
    for(ll q=2; q<=g; q++){
        if(a%q) continue;
        int c = 0;
        for(;a%q==0; c++) a/=q;
        m.pb(c);
    }
    if(a>1) m.pb(1);
    ll o = 0;
    for(ll i : m){
        ll tyt =0 ;
        for(ll q=1,u=1;;q++, u+=q){
            if(i>=u) tyt = q;
            else break;
        }
        o += tyt;
    }
    cout<<o;
}

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

int i,j,k;

int main(){
    int ans=0;
    int n,m,l;
    l=0;
    cin>>n>>m;
    int a[m];
    REP(i,m){
        cin>>a[i];
        l+=a[i];
    }
    if(l>n){
        ans=-1;
    }
    else{
        ans=n-l;
    }
    
    
    cout<<ans<<endl;
}

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

inline int read() {
	int ret, cc;
	while (!isdigit(cc = getchar()));
	ret = cc - 48;
	while ( isdigit(cc = getchar()))
		ret = cc - 48 + ret * 10;
	return ret;
}
const int MAXN = 600010;
int n;
int a[MAXN];
int main() {
	n = read();
	std::generate(a + 1, a + 3 * n + 1, read);
	std::sort(a + 1, a + 3 * n + 1);
	long long ans = 0;
	for (int i = n + 1; i <= 3 * n; i += 2)
		ans += a[i];
	printf("%lld\n", ans);
}


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

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    ll n,i,j,k,flag=0,sum=0;
    char temp;
    cin>>n>>k;
    string s;
    cin>>s;
    temp=s[0];
    j=0;
    while(k--)
    {
        flag=1;
        
        for(i=j+1;i<s.length();i++)
        {
            
            if(s[i]!=temp)
            {
            s[i]=temp;
            flag=2;
            sum++;
            }
            else if(flag==2)
            {
            break;
                
            }
            else
            {
                sum++;
            }
        j=i;
        
    }
    }
    for(i=j+1;i<s.length();i++)
    {
        if(s[i-1]==s[i])
        sum++;
    }


    cout<<sum;
    


     

  return 0;
    
}
    


Measured memory_bytes: 512
#include<bits/stdc++.h>
#include<algorithm>
#include<math.h>
using namespace std;
long long int lcm(long long int a,long long int b){
  long long int n;
  n=a*b/__gcd(a,b);
  return n;
}
using ll =long long int;
#define ci(a) cin>>a
#define co(a) cout<<a<<endl
#define gcd(a,b) __gcd(a,b)
#define vec vector<ll>
#define for(i,a,b) for(int i=a;i<b;i++)
#define sort(a,b) sort(a.begin(),b.end())
//gcd 最大公約数
//lcm 最小公倍数
//double 少数（変数）
//string 文字列（変数）
//sqrt 平方根
//ceil 天井関数
//floor 床関数
//abs 絶対値
//pow 累乗
//cbrt  立方根
//hypot 平方和の平方根
 
int main() {
  ll a;
  ci(a);
  vec b(a);
  for(i,0,a)
    ci(b[i]);
  sort(b,b);
  double c=b[0];
  for(i,1,a)
    c=(c+b[i])/2;
  co(c);
}

Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<algorithm>
using namespace std;

typedef long long LL;

const int N=100005;

int n,a[N],b[N],c[N];
LL s[N];

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

int main()
{
	n=read();
	for (int i=1;i<=n;i++) a[i]=read();
	for (int i=1;i<=n;i++) b[i]=read();
	for (int i=1;i<=n;i++) c[i]=read();
	sort(a+1,a+n+1);
	sort(b+1,b+n+1);
	sort(c+1,c+n+1);
	for (int i=1;i<=n;i++) s[i]=lower_bound(a+1,a+n+1,b[i])-a-1;
	for (int i=1;i<=n;i++) s[i]+=s[i-1];
	LL ans=0;
	for (int i=1;i<=n;i++)
	{
		int x=lower_bound(b+1,b+n+1,c[i])-b-1;
		ans+=s[x];
	}
	cout<<ans;
	return 0;
}

Measured memory_bytes: 2304
a, b, k = gets.chomp.split(" ").map(&:to_i)
ans = []
if b-a < k
    ans = [*a..b]
else
    a.upto(a+k-1) do |i|
        ans << i
    end
    b.downto(b-k+1) do |i|
        ans << i
    end
end

puts ans.sort.uniq

Measured memory_bytes: 1788
#include <bits/stdc++.h>
using namespace std;
#define forn(i, n) for(int i = 0; i < int(n); i++)
#define fore(i, l, r) for(int i = int(l); i < int(r); i++)
#define pb push_back
#define deb(x) cout<<#x<<" "<<x<<endl;
#define deb2(x, y) cout<<#x<<" "<<x<<" "<<#y<<" "<<y<<endl;
#define deb3(x, y, z) cout<<#x<<" "<<x<<" "<<#y<<" "<<y<<" "<<#z<<" "<<z<<endl;
#define all(x) x.begin(), x.end()
typedef long long ll;
typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
typedef vector<string> vs;
typedef vector<bool> vb;
typedef pair<int, int> pii;
const int mod = 1e9 + 7;
template<class T, class U> inline void add_self(T &a, U b){a += b;if (a >= mod) a -= mod;if (a < 0) a += mod;}
template<class T, class U> inline void min_self(T &x, U y) { if (y < x) x = y; }
template<class T, class U> inline void max_self(T &x, U y) { if (y > x) x = y; }

template <typename T>void print(T v, bool show_index = false){int w = 2;if(show_index){for(int i=0; i<v.size(); i++)cout<<setw(w)<<i<<" ";cout<<endl;}for(auto i= v.begin(); i!=v.end(); i++)cout<<setw(w)<<*i<<" ";cout<<endl;}
template <typename T>void print_vv(T v){if(v.size()==0) {cout<<"Empty"<<endl; return;} int w = 3;cout<<setw(w)<<" ";for(int j=0; j<v[0].size(); j++)cout<<setw(w)<<j<<" ";cout<<endl;for(auto i= 0; i<v.size(); i++){cout<<i<<" {";for(auto j = 0; j!=v[i].size(); j++){cout<<setw(w)<<v[i][j]<<",";}cout<<"},"<<endl;}cout<<endl;}
template <class T, class U> void print_m(map<T,U> m, int w=3){if(m.empty()){cout<<"Empty"<<endl; return;}for(auto x: m)cout<<"("<<x.first<<": "<<x.second<<"),"<<endl;cout<<endl;}

int main(){
    ll n,k;
    while(cin>>n>>k){
        ll out = n%k;
        cout<<min(out, k - out)<<endl;
    }
    return 0;
}

Measured memory_bytes: 256
import sys
stdin = sys.stdin

sys.setrecursionlimit(10 ** 7)

def li(): return map(int, stdin.readline().split())
def li_(): return map(lambda x: int(x) - 1, stdin.readline().split())
def lf(): return map(float, stdin.readline().split())
def ls(): return stdin.readline().split()
def ns(): return stdin.readline().rstrip()
def lc(): return list(ns())
def ni(): return int(stdin.readline())
def nf(): return float(stdin.readline())

n, k = li()
s = ns()

if len(set(list(s))) == 1:
    print(n-1)
else:
    init = 0
    bef = ""
    for si in s:
        if si == bef:
            init += 1
        bef = si
    print(min(n-1, init + 2*k))

Measured memory_bytes: 4084
#include <bits/stdc++.h>
#include <math.h>
using namespace std;
int main(){
    int N;
    cin >>N;
    int ans = 123456789;
    for(int i = 1;i < 10;i++){
        if(N <= 111*i) ans = min(ans,111*i - N);
    }
    cout << ans + N << endl;
}

Measured memory_bytes: 256
# coding:utf-8                                                                                     

N = int(raw_input())
C = []
S = []
F = []

for i in range(N-1):
    c, s, f = map(int, raw_input().split())
    C.append(c)
    S.append(s)
    F.append(f)

res = []

for i in range(N-1):
    t = 0
    for j in range(i, N-1):
        if S[j] >= t:
            t = 0
            t += S[j] + C[j]
        elif t % F[j] == 0:
            t += C[j]
        else:
            t = S[j] + F[j] * ((t - S[j]) / F[j]) + F[j] + C[j]
    print t

print 0

Measured memory_bytes: 2692
//#include <bits/stdc++.h>
#include <iostream>
#include <complex>
#include <sstream>
#include <string>
#include <algorithm>
#include <deque>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <vector>
#include <set>
#include <limits>
#include <cstdio>
#include <cctype>
#include <cmath>
#include <cstring>
#include <cstdlib>
#include <ctime>
#include <climits>
#include <iomanip>
#include <stack>
#include <bitset>

#define REP(i, n) for(int i = 0; i < (int)(n); i++)
#define FOR(i, j, k) for(int i = (int)(j); i < (int)(k); ++i)
#define ROF(i, j, k) for(int i = (int)(j); i >= (int)(k); --i)
#define FORLL(i, n, m) for(long long i = n; i < (long long)(m); i++)
#define SORT(v, n) sort(v, v+n)
#define REVERSE(v) reverse((v).begin(), (v).end())

using namespace std;
using ll = long long;
const ll MOD=1000000007LL;
typedef pair<int, int> P;

ll ADD(ll x, ll y) { return (x+y) % MOD; }
ll SUB(ll x, ll y) { return (x-y+MOD) % MOD; }
ll MUL(ll x, ll y) { return x*y % MOD; }
ll POW(ll x, ll e) { ll v=1; for(; e; x=MUL(x,x), e>>=1) if (e&1) v = MUL(v,x); return v; }
ll DIV(ll x, ll y) { /*assert(y%MOD!=0);*/ return MUL(x, POW(y, MOD-2)); }

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

#define MAXN 100010
#define vi vector<int>

vi edges[MAXN];
vi costs[MAXN];
 
int color[MAXN];
int parent[MAXN];

void dfs(int node, int col){
  color[node] = col;
  for(int i= 0; i<edges[node].size(); i++){
    if(edges[node][i] != parent[node]){
      //接続先の親を自分に
      parent[edges[node][i]] = node;
      if(costs[node][i] %2 == 0){
	dfs(edges[node][i], col);
      }
      else{
	//反転
	dfs(edges[node][i], col ^ 1);
      }
    }
  }
}

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

  ll n;
  cin >> n;

  REP(i, n-1){
    ll u, v, w;
    cin >> u >> v >> w;
    edges[u].push_back(v);
    edges[v].push_back(u);
    costs[u].push_back(w);
    costs[v].push_back(w);    
  }
  dfs(1, 0);
  FOR(i,1,n+1){
    cout << color[i] << endl;
  }
    
  return 0;
}


Measured memory_bytes: 15616
#include <bits/stdc++.h>
using namespace std;
int N, K;
vector<int> P;
int solve() {
	sort(P.rbegin(), P.rend());
	for(int i = 0; i < K; i++) {
		if(P[i] == 0) return 0;
		P[i]--;
	}
	return 1;
}
int main() {
	// greedy
	cin >> N >> K;
	string p;
	P = vector<int>(26);
	for(int i = 0; i < 26; i++) {
		P[i] = 0;
	}
	for(int i = 0; i < N; i++) {
		cin >> p;
		P[p[0] - 0x41]++;
	}
	int ans = 0;
	while(solve())ans++;
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
N, M = map(int, input().split())
edges = [list(map(int, input().split())) for _ in range(M)]

graph = [[0] * N for _ in range(N)]
for a, b in edges:
    graph[a - 1][b - 1] = 1
    graph[b - 1][a - 1] = 1


def dfs(v):
    visited[v] = 1
    for v2 in range(N):
        if graph[v][v2]==0:
            continue
        if visited[v2]==1:
            continue
        dfs(v2)


ans = 0
for a, b in edges:
    graph[a - 1][b - 1] = 0
    graph[b - 1][a - 1] = 0
    visited = [0] * N

    dfs(0)
    # print(visited)

    bridge = 0
    for i in range(N):
        if visited[i] == 0:
            bridge = 1
    if bridge==1:
        ans += 1

    graph[a - 1][b - 1] = 1
    graph[b - 1][a - 1] = 1

print(ans)

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

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

    if (a + b > c + d) {
        cout << "Left" << endl;
    }
    else if (a + b == c + d) {
        cout << "Balanced" << endl;
    }
    else {
        cout << "Right" << endl;
    }

    return 0;
}


Measured memory_bytes: 256
n, d = list(map(int, input().split()))

p = [0]*n
q = [0]*n

for i in range(n):
    p[i], q[i] = list(map(int, input().split()))

cnt = 0

for i in range(n):
    if p[i]*p[i]+ q[i]*q[i]<=d*d :
        cnt = cnt+1

print(cnt)


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

int main(void){
  int K;
  cin >> K;
  string M;
  cin >> M;
  if(K >= M.size()){
    cout << M << endl;
  } else {
    M = M.erase(K) + "...";
    cout << M << endl;
  }
  return 0;
}


Measured memory_bytes: 3620
#include<iostream>
#include<vector>
#include<algorithm>
#include<map>
#include<cstring>
#include<math.h>
#include<bitset>
#include<queue>
#include<set>
#include<iomanip>
#include<math.h>
#include<assert.h>
#include<string>
#include<cstdlib>
#include<cctype>
#include<unordered_map>
#include<sstream>
// #include<bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<int,int>;
constexpr ll INF = 1LL << 40;
const double INFD = 1e100;
const ll mod = 1000000007;
const double PI = 3.1415926535897932384626433832795028841971;
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
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;
};

// intやllをstringに変換
template<typename T> inline string toString(const T &a){
  ostringstream oss;
  oss << a;
  return oss.str();
};
// ----------------------------------------------------------------------------
int main(){
  int H,W;
  cin >> H >> W;
  vector<string> S(H);
  for(int i=0; i<H; i++){
    cin >> S[i];
  }
  int ans = 0;
  for(int sy=0; sy<H; sy++){
    for(int sx=0; sx<W; sx++){
      for(int gy=0; gy<H; gy++){
        for(int gx=0; gx<W; gx++){
          if(S[sy][sx]=='#' || S[gy][gx]=='#') continue;
          vector<vector<int>> dist(H, vector<int> (W,-1));
          queue<P> que;
          dist[sy][sx] = 0;
          que.push(make_pair(sy,sx));
          while(!que.empty()){
              P v = que.front();
              que.pop();
              for(int i=0; i<4; i++){
                int ny = v.first + dy[i];
                int nx = v.second + dx[i];
                if(ny<0 || ny>=H || nx<0 || nx>=W) continue;
                if(S[ny][nx] == '#') continue;
                if(dist[ny][nx] != -1) continue;
                dist[ny][nx] = dist[v.first][v.second] + 1;
                que.push(make_pair(ny,nx));
              }
          }
          chmax(ans, dist[gy][gx]);
        }
      }
    }
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int H, W;
vector<string> S;
complex<int> f(int i, int j, char c) {
	if (!(0 <= i && i < H && 0 <= j && j < W)) return 0;
	if (S[i][j] != c) return 0;
	S[i][j] = '*';
	complex<int> r;
	if (c == '.') r.real(1); else r.imag(1);
	char cc = c == '.' ? '#' : '.';
	r += f(i+1,j,cc);
	r += f(i-1,j,cc);
	r += f(i,j+1,cc);
	r += f(i,j-1,cc);
	return r;
}
int main() {
	cin >> H >> W;
	S.resize(H);
	for (auto& x : S) cin >> x;
	long long r = 0;
	for (int i = 0; i < H; ++ i) for (int j = 0; j < W; ++ j) if (S[i][j] != '*') {
		auto n = f(i,j,S[i][j]);
		r += (long long)n.real() * n.imag();
	}
	cout << r << endl;
}


Measured memory_bytes: 10496
import java.util.Scanner;
import java.util.Arrays;
public class Main{
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		int w =sc.nextInt();
		int h=sc.nextInt();
		long[] p=new long[w];
		for(int i=0; i<w; i++){
			p[i]=sc.nextLong();
		}
		long[] q=new long[h];
		for(int i=0; i<h; i++){
			q[i]=sc.nextLong();
		}
		Arrays.sort(p);
		Arrays.sort(q);
		int i=0;
		int j=0;
		long ans=0;
		while(i<h || j<w){
			if(j==w || (i<h && p[j]>q[i])){
				ans+=q[i]*(w+1-j);
				i++;
			}else{
				ans+=p[j]*(h+1-i);
				j++;
			}
		}
		System.out.println(ans);
	}
}


Measured memory_bytes: 85352
#include<bits/stdc++.h>
#define REP(i, a, b) for(long long i=a; i<=b; ++i)
#define REPN(i, a, b) for(long long i=a; i<=b; --i)
#define rep(i, a, b) for(long long i=a; i<b; ++i)
#define rep0(i,b) for(long long i=0; i<b; ++i)
#define REP0(i,b) for(long long i=0; i<=b; ++i)
#include<cmath>
#include <iomanip>
using namespace std;


typedef long long ll;

int MODE = 1e9+7;

int main()
{

    int n,k;
    cin>>n>>k;
    ll arr[n+1];
    arr[0] = -1;
    rep0(i, n)
    {
        cin>>arr[i+1];
    }





    int dp[n+1][k+1];

    rep0(i, n+1)
    {
        dp[i][0] = 1;
    }
   // cout<<dp[0][0]<<endl;

    rep0(i, k+1)
    {
        dp[0][i] = 0;
    }
     dp[0][0] = 1;


    rep(i, 1,n+1)
    {
        vector<ll> prefixSum(k+1);
        prefixSum[0] = 1;
        rep(j, 1, k+1)
        {
            prefixSum[j] = (prefixSum[j-1]+dp[i-1][j] + MODE)%MODE ;
        }
        rep(j, 1, k+1)
        {
            if(j<=arr[i])
            {
                dp[i][j] = prefixSum[j];
            }
            else
            {
                dp[i][j] = (prefixSum[j] - prefixSum[j - arr[i] - 1] + MODE)%MODE;
            }
        }

    }

    //rep0(i, n+1)
    //{
      //  rep0(j, k+1)
        //{
          //  cout<<dp[i][j]<<"\t";
        //}
        //cout<<endl;
    //}

    cout<<dp[n][k]%MODE<<endl;


    return 0;

}


Measured memory_bytes: 43620
#include<iostream>
#include<vector>
#include<string>
#include<climits>
#include<algorithm>
#include<cmath>
#include<iomanip>
#include<set>
#include<queue>
#include<math.h>

int main(){
	int a;
	std::string s;

	std::cin>>a;
	std::cin>>s;

	if(a>= 3200)
		std::cout<<s<<std::endl;
	else
		std::cout<<"red"<<std::endl;


	return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
#define MAX 500001

int H;

void maxHeapify(int *B,int j)
{
  int l,r,largest;
  int temp;
  l = 2 * j;
  r = 2 * j + 1;
  if(l <= H && B[l] > B[j])
    largest = l;
  else
    largest = j;
  if(r <= H && B[r] > B[largest])
    largest = r;
  if(largest != j)
    {
      temp = B[j];
      B[j] = B[largest];
      B[largest] = temp;
      maxHeapify(B,largest);
    }
};

int main()
{
  int i,A[MAX];
  
  scanf("%d",&H);
  for(i = 1; i <= H; i++)
    scanf("%d",&A[i]);
  for(i = H/2; i >= 1; i--)
    maxHeapify(A,i);
  for(i = 1;i <= H; i++)
      printf(" %d",A[i]);
  printf("\n");
  
  return 0;
}



Measured memory_bytes: 3808
#include "bits/stdc++.h"
#define PRECISION(x) cout << fixed << setprecision(x)
#define FAST_IO ios::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define SZ(X) ((int)(X).size())
#define ALL(X) (X).begin(), (X).end()
#define ALLR(X) (X).rbegin(), (X).rend()
#define MP make_pair
#define PB push_back
#define EB emplace_back
#define F first
#define S second

using namespace std;
 
template<class T> void max_self(T & a, const T & b) { if(a < b) a = b; }
template<class T> void min_self(T & a, const T & b) { if(a > b) a = b; }
typedef long long LL;
const int INF = 1e9 + 7;
const double PI = acos(-1.0);
const double EPS = (1e-9);



int main(){
	FAST_IO
	
	int N, sum = 0;
	cin >> N;
	for(int M = N; M > 0; ){
		sum += M % 10;
		M /= 10;
	}
	
	if(N % sum) cout << "No\n";
	else cout << "Yes\n";
			
	return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
  string s;
  cin>>s;
  if(s[0]=='R')
  {
    cout<<"Sunny";
  }
  else if(s[0]=='S')
  {
    cout<<"Cloudy";
  }
  else
  {
    cout<<"Rainy";
  }
}

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

using namespace std;

vector<pair<int,int> >v;
int box[100000];
bool box2[100000];

int main(){
  int n,m;
  cin>>n>>m;
  for(int i = 0;i<m;i++){
    int x,y;
    cin>>x>>y;
    x--;
    y--;
    v.push_back(make_pair(x,y));
  }
  for(int i =0;i<n;i++){
    box[i] = 1;
  }

  box2[0] = true;
  for(int i = 0;i<m;i++){
    box[v[i].first]--;
    box[v[i].second]++;
    if(box2[v[i].first]){
      box2[v[i].second] = true;
      if(box[v[i].first] == 0)
	box2[v[i].first] = false;
    }
  }

  int ans = 0;
  for(int i = 0;i<n;i++){
    if(box2[i])
      ans++;
  }

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


Measured memory_bytes: 1652
#include <bits/stdc++.h>
 
using namespace std;
using ll = long long;
// #define int ll
using PII = pair<ll, ll>;
 
#define FOR(i, a, n) for (ll i = (ll)a; i < (ll)n; ++i)
#define REP(i, n) FOR(i, 0, n)
#define ALL(x) x.begin(), x.end()
 
template<typename T> T &chmin(T &a, const T &b) { return a = min(a, b); }
template<typename T> T &chmax(T &a, const T &b) { return a = max(a, b); }
template<typename T> bool IN(T a, T b, T x) { return a<=x&&x<b; }
template<typename T> T ceil(T a, T b) { return a/b + !!(a%b); }
 
template<typename T> vector<T> make_v(size_t a) { return vector<T>(a); }
template<typename T,typename... Ts>
auto make_v(size_t a,Ts... ts) { 
  return vector<decltype(make_v<T>(ts...))>(a,make_v<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); }
 
template<class S,class T>
ostream &operator <<(ostream& out,const pair<S,T>& a){
  out<<'('<<a.first<<','<<a.second<<')'; return out;
}
template<typename T>
istream& operator >> (istream& is, vector<T>& vec){
  for(T& x: vec) {is >> x;} return is;
}
template<class T>
ostream &operator <<(ostream& out,const vector<T>& a){
  out<<'['; for(T i: a) {out<<i<<',';} out<<']'; return out;
}
 
int dx[] = {0, 1, 0, -1}, dy[] = {1, 0, -1, 0}; // DRUL
const int INF = 1<<30;
const ll LLINF = 1LL<<60;
const ll MOD = 1000000007;

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

  ll n;
  cin >> n;
  ++n;
  vector<vector<ll>> g(n);
  REP(i, n-1) {
    ll p;
    cin >> p;
    g[p].push_back(i+1);
  }

  vector<ll> depth(n);
  function<void(ll,ll)> dep = [&](ll v, ll d) {
    depth[d]++;
    for(auto to: g[v]) {
      dep(to, d+1);
    }
  };

  struct node {
    ll x, y, z;
    node() {}
    node(ll x, ll y, ll z) : x(x), y(y), z(z) {}
    node plus(node n) {
      ll nx = x*n.x % MOD;
      ll ny = (y*n.x % MOD + x*n.y % MOD) % MOD;
      ll nz = (z*(n.x+n.y+n.z) % MOD + y*(n.y+n.z) % MOD + x*n.z % MOD) % MOD;
      return node(nx, ny, nz);
    }
  };

  function<deque<node>(ll)> dfs = [&](ll v) {
    deque<node> ret;
    ll sz = 0;
    for(auto to: g[v]) {
      auto dq = dfs(to);
      if(ret.size() < dq.size()) swap(ret, dq);
      // dq -> retへマージ
      REP(i, dq.size()) {
        ret[i] = ret[i].plus(dq[i]);
      }
      chmax(sz, (ll)dq.size());
    }
    REP(i, sz) {
      (ret[i].x += ret[i].z) %= MOD;
      ret[i].z = 0;
    }
    ret.push_front(node(1, 1, 0));
    return ret;
  };

  dep(0, 0);
  auto ret = dfs(0);

  vector<ll> pow2(n+1);
  pow2[0] = 1;
  FOR(i, 1, n+1) pow2[i] = pow2[i-1] * 2 % MOD;

  ll d = 0, ans = 0;
  for(auto i: ret) {
    (ans += i.y * pow2[n - depth[d++]] % MOD) %= MOD;
  }
  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 181504
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

int top, S[1000];

void push(int x)
{
    S[++top] = x;
}

int pop()
{
    top--;
    return S[top + 1];
}

int main()
{
    int a, b;
    top = 0;

    char s[100];

    while (scanf("%s", s) != EOF)
    {
        char str = s[0];
        if (str == '+' || str == '-' || str == '*')
        {
            int right = pop();
            int left = pop();
            if (str == '+')
            {
                push(right + left);
            }
            else if (str == '-')
            {
                push(left - right);
            }
            else if (str == '*')
            {
                push(right * left);
            }
        }
        else
        {
            push(atoi(s));
        }
    }
    printf("%d\n", pop());
}


Measured memory_bytes: 2100
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ
		Scanner scanner = new Scanner(System.in);

		double doubleX1 = scanner.nextDouble();
		double doubleY1 = scanner.nextDouble();
		double doubleX2 = scanner.nextDouble();
		double doubleY2 = scanner.nextDouble();
		double dbWidth = doubleX2 - doubleX1;
		double dbHeight = doubleY2 - doubleY1;

		double dbDistance = Math.sqrt(dbWidth * dbWidth + dbHeight * dbHeight);

		System.out.println(String.format("%.8f", dbDistance));
	}

}



Measured memory_bytes: 27992