akhauriyash/Code-Regression huggingface dataset:
import java.util.Scanner;

public class Main {
public static void main(String args[]) {
	int h,m,s,x;
	Scanner a = new Scanner(System.in);
	x = a.nextInt();
	
	h = x / 3600;
	m = x % 3600 / 60;
	s = x % 3600 % 60;
	System.out.println(h +":"+ m + ":" + s);
}
}

Measured memory_bytes: 26288
import java.io.*;
import java.util.Arrays;
import java.util.*;
public class Main{
	static int[] weights;
	static int[] values;
	static long[][]memo;
	static int n,w;
	public static void main(String[] args) throws Exception {
		Scanner sc=new Scanner(System.in);
		PrintWriter pw=new PrintWriter(System.out);
		n=sc.nextInt();
		w=sc.nextInt();
		weights=new int[n];
		values=new int[n];
		memo=new long[n+1][w+1];
		for(long[] x:memo) {
			Arrays.fill(x, -1);
		}
		for(int i=0;i<n;i++) {
			weights[i]=sc.nextInt();
			values[i]=sc.nextInt();
		}
		pw.println(maxsum(0,w));
		pw.close();
	}
	public static long maxsum(int idx,int av) {
		if (av<0)return -(int)1e9;
		if(idx==n)return 0;
		if(memo[idx][av]!=-1) {
			return memo[idx][av];
		}
		long take=values[idx]+maxsum(idx+1,av-weights[idx]);
		long leave=maxsum(idx+1,av);
		memo[idx][av]=Math.max(take, leave);
		return memo[idx][av];
	}
	static class Scanner {
		StringTokenizer st;
		BufferedReader br;
		public Scanner(InputStream s) {
			br = new BufferedReader(new InputStreamReader(s));
		}
		public Scanner(String file) throws FileNotFoundException {
			br = new BufferedReader(new FileReader(file));
		}

		public String next() throws IOException {
			while (st == null || !st.hasMoreTokens())
				st = new StringTokenizer(br.readLine());
			return st.nextToken();
		}
		
		public int nextInt() throws IOException {
			return Integer.parseInt(next());
		}
		public long nextLong() throws IOException {
			return Long.parseLong(next());
		}
		public String nextLine() throws IOException {
			return br.readLine();
		}
		public double nextDouble() throws IOException {
			return Double.parseDouble(next());
		}
		public boolean ready() throws IOException {
			return br.ready();
		}
	}


}


Measured memory_bytes: 131452
#include<bits/stdc++.h>
#define MAXN 200005
#define LL long long
#define P int(1e4+7)
using namespace std;

int N,N1;
vector<int> adj[MAXN];
int deg[MAXN], c[MAXN];
int dp[MAXN];
bool vis[MAXN];
int ans1, ans2;

void dfs(int u){
	//cout<<"dfs: "<<u<<endl;
	
	vis[u] = 1;
	dp[u] = (c[u]==1) - (c[u]==0);
	
	int v, m1 = -1e9;
	for(int k=0;k<adj[u].size();k++){
		v = adj[u][k];
		if(vis[v]) continue;
		
		
		dfs(v);
		ans2 = max(ans2, m1 + dp[u] + 1 + dp[v]);
		m1 = max(m1, 1 + dp[v]);
	}
	
	if(m1 != -1e9) dp[u] += m1;
	
	ans2 = max(ans2, dp[u]);//cout<<"dp[u]: "<<u<<" "<<dp[u]<<" "<<ans2<<endl;
	return;
}

string s;

void init(){
	cin>>N;
	for(int i=1;i<=N;i++) adj[i].clear();
	
	memset(deg,0,sizeof(deg));
	memset(c,0,sizeof(c));
	memset(vis,0,sizeof(vis));
	memset(dp,0,sizeof(dp));
	ans1 = ans2 = 0;
	
	int u,v;
	for(int i=1;i<N;i++){
		cin>>u>>v;
		
		adj[u].push_back(v);
		adj[v].push_back(u);
		++deg[u]; ++deg[v];
	}
	
	cin>>s;
	s = "$" + s;
	
	N1 = N;
	queue<int> q;
	for(int i=1;i<=N;i++){
		if(s[i]=='B' && deg[i]==1){
			q.push(i);
		}
	}
	
	//
	while(!q.empty()){
		u = q.front(); q.pop();
		--deg[u]; 
		vis[u] = 1; --N1;
		
		
		for(int k=0;k<adj[u].size();k++){
			v = adj[u][k];
			if(vis[v]) continue;
			--deg[v];
			if(deg[v]==1 && s[v]=='B'){
				q.push(v);
			}
		}
	}
}

void work(){
	ans1 = 2*(N1-1);
	for(int i=1;i<=N;i++){
		if(vis[i]) continue;
		
		c[i] = (deg[i] + (s[i]=='B') + 1) % 2;
		ans1 += c[i];
	}
	 
	if(N1==1){
		cout<<ans1<<endl;
		return;
	}
	
	//ans2
	for(int i=1;i<=N;i++){
		if(!vis[i]){
			dfs(i);
			break;
		}
	} 
	//cout<<"ans2: "<<ans2<<endl;
	if(ans2 > 0) ans2 = ans1 - ans2 - 1;
	else ans2 = ans1;
	
	cout<<max(0, min(ans1, ans2))<<endl;
}

int main(){
	ios::sync_with_stdio(0);
	//freopen("9.in","r",stdin);
	//freopen("10.out","w",stdout);
	
	int T;
	//cin>>T;
	
	T = 1;
	while(T--){
		init();
		work();
	}

	return 0;
}

Measured memory_bytes: 16364
#include <iostream>
#include <string>
#include <algorithm>
#include <cmath>
#include <deque>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <iomanip>
#include <bitset>
#include <set>
#include <map>
#include <stdio.h>
#include <numeric>
#include <cstring>

#define rep(i,n) for (int i = 0; i < (n); i++)
#define rep1(i,n) for (int i = 1; i < (n); i++)
#define FOR(i,a,b) for (int i=(a); i < (b); i++)
#define MOD 1000000007 //10^9+7
#define TEN5 100000 //10^5
#define TEN9 1000000000 //10^9
using namespace std;
using ll = long long;
using PII = pair<int, int>;
const int INF = numeric_limits<int>::max();

// 負の数にも対応した % 演算
long long mod(long long val, long long m) {
    long long res = val % m;
    if (res < 0) res += m;
    return res;
}

//greatest common divisor
long long gcd(ll a, ll b) 
{
    if (a % b == 0) {
        return b;
    } else {
        return gcd(b, a % b);
    }
}

//least common multiple
long long lcm(ll a, ll b)
{
    return a / gcd(a, b) * b ;
}

int main()
{
    int r, g, b, n; cin >> r >> g >> b >> n;
    int ans = 0;
    rep(i,3001) {
        rep(j,3001) {
            int v = i * r + j * g;
            if (v <= n && (n - v)%b == 0)
                ans++;
        }
    }
    cout << ans << endl;
    
    return 0;
}



Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<algorithm>
#include<cmath>
using namespace std;
int main() {
	long long n, m, b, e = 0;
	cin >> n;
	e = n;
	long long a[123456];
	for (int i = 0; i < n; i++) {
		cin >> a[i];
	}
	sort(a, a + n);
	for (int h = 0; h < n; h++) {
		if (a[h] == a[h + 1]) {
			e = e - 2;
			h++;
		}
	}
	cout << e << endl;
	cin >> e;
}

Measured memory_bytes: 1024
b,w = map(int,input().split())
mod = 10**9 + 7

## nCkのmodを求める関数
# テーブルを作る(前処理)
max = 2 * 10**5 + 100
fac, finv, inv = [0]*max, [0]*max, [0]*max

def comInit(max):
    fac[0] = fac[1] = 1
    finv[0] = finv[1] = 1
    inv[1] = 1

    for i in range(2,max):
      fac[i] = fac[i-1]* i% mod
      inv[i] = mod - inv[mod%i] * (mod // i) % mod
      finv[i] = finv[i-1] * inv[i] % mod

comInit(max)

# 二項係数の計算
def com(n,k):
    if(n < k):
        return 0
    if( (n<0) | (k < 0)):
        return 0
    return fac[n] * (finv[k] * finv[n-k] % mod) % mod



ans = []
ex2 = 1
b_end = 0
w_end = 0
n = b+w
for i in range(n):
    if(i >= b):
        b_end = (b_end*2 + com(i-1,i-b) )%mod
    if(i >= w):
        w_end = (w_end*2 + com(i-1,i-w) )%mod

    bw = (ex2 - b_end - w_end)% mod
    ex2 = (ex2*2)%mod
    ans.append( (w_end*2 + bw) * pow(ex2,mod-2,mod) % mod )

print('\n'.join(map(str,ans)))

Measured memory_bytes: 108020
#include <iostream> // cin, cout
#include <algorithm> // sort
#include <vector> // vector
#include <cstdio> // printf
#include <cmath> // M_PI
#include <numeric> // accumulate
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)n; i++)
#define ll long long

int		main(void)
{
	int m, h, r;
	cin >> m >> h >> r; // 入力
	while (m != -1 || h != -1 || r != -1) {
		if (m == -1 || h == -1)
			cout << "F" << endl;
		else if (m + h >= 80)
			cout << "A" << endl;
		else if (m + h >= 65)
			cout << "B" << endl;
		else if (m + h >= 50)
			cout << "C" << endl;
		else if (m + h >= 30) {
			if (r >= 50)
				cout << "C" << endl;
			else
				cout << "D" << endl;
		} else
			cout << "F" << endl;
		cin >> m >> h >> r; // 入力
	}
	return (0);
}



Measured memory_bytes: 3092
from collections import deque

N, M = map(int, input().split())
AB = [map(int, input().split()) for _ in range(M)]

links = [[] for _ in range(N + 1)]
for a, b in AB:
    links[a].append(b)
    links[b].append(a)

result = [-1] * (N + 1)
q = deque([1])
while q:
    i = q.popleft()
    for j in links[i]:
        if result[j] == -1:
            result[j] = i
            q.append(j)
print('Yes')
print('\n'.join(str(i) for i in result[2:]))

Measured memory_bytes: 106312
#include<stdio.h>
int main(void)
{
	int H, W,i,j;
	scanf("%d %d", &H, &W);
	while (H != 0 || W != 0)
	{
		for (i = 0; i < H; i++)
		{
			for (j = 0; j < W; j++)
			{
				printf("#");
			}
			printf("\n");
		}
		printf("\n");
		scanf("%d %d", &H, &W);
	}
	return 0;
}


Measured memory_bytes: 2144
#include <bits/stdc++.h>
 
#define pii pair<int, int>
#define endl "\n"
#define int long long
#define F first
#define S second
#define B begin
#define E end
#define RB rbegin
#define RE rend
 
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
 
const int INF = 1e9 + 1;
const double EPS = 1e-10;
const ll P = 1e9 + 7;
const int Q = 47;
 
using namespace std;
 
void hello()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    #ifdef LOCAL
        freopen("input.txt", "r", stdin);
        freopen("output.txt", "w", stdout);
    #endif
}
 
void show(vector<int>& arr)
{
    for (auto i : arr)
        cout << i << " ";
    cout << endl;
}
void show(vector<vector<int>>& arr)
{
    for (auto i : arr)
        show(i);
    cout << endl;
}


signed main()
{
    hello();
    
    int k;
    cin >> k;
    if (k % 7 == 0)
        k /= 7;
    int st = 1;
    int tst = 1;
    for (int i = 1; i <= k; ++i)
    {
        if (st % k == 0)
        {
            cout << i << endl;
            return 0;
        }
        tst = tst * 10 % k;
        st += tst;
        st %= k;
    }
    cout << -1 << endl;
}

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

int main(){
	string s; 
	cin >> s;
	if((s[0] == s[s.size()-1] && s.size()%2 == 0) || (s[0] != s[s.size()-1] && s.size()%2 == 1)){
		cout << "First" << endl;
    }else{
		cout << "Second" << endl;
    }
}


Measured memory_bytes: 512
import bisect,collections,copy,itertools,math,string
import sys
def I(): return int(sys.stdin.readline().rstrip())
def LI(): return list(map(int,sys.stdin.readline().rstrip().split()))
def S(): return sys.stdin.readline().rstrip()
def LS(): return list(sys.stdin.readline().rstrip.split())
def main():
    a,b,k = LI()
    x = max(a-k,0)
    y = b
    if k-a > 0:
        y = max(b-(k-a),0)
    print(x,y)
main()

Measured memory_bytes: 74556
#pragma once
#include <stdio.h>
#include <sstream>
#include <string.h>
#include <vector>
#include <map>
#include <algorithm>
#include <iostream>
#include <utility>
#include <set>
#include <cctype>
#include <queue>
#include <stack>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <deque>
#include <limits>
#include <iomanip>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
#define bit(x,v) ((ll)x << v)

const ll INF = 1000000007;
const ll MAX = 210000;
const ll MOD = 1000000007;

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(int n, int k) {
	if (n < k) return 0;
	if (n < 0 || k < 0) return 0;
	return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

ll gcd(ll a, ll b) {
	if (b == 0) return a;
	return gcd(b, a % b);
}
int pr[100010];
void uini(int n) {
	for (size_t i = 0; i <= n; i++)
	{
		pr[i] = i;
	}
}

int parent(int x) {
	if (x == pr[x]) return x;
	return pr[x] = parent(pr[x]);
}

bool unit(int x, int y) {
	int px = parent(x);
	int py = parent(y);

	if (px == py) return false;
	if (px < py) {
		pr[py] = px;
	}
	else {
		pr[px] = py;
	}
	return true;
}

// res[i][c] := i 文字目以降で最初に文字 c が登場する index (存在しないときは n)
vector<vector<int> > calcNext(const string & S) {
	int n = (int)S.size();
	vector<vector<int> > res(n + 1, vector<int>(26, n));
	for (int i = n - 1; i >= 0; --i) {
		for (int j = 0; j < 26; ++j) res[i][j] = res[i + 1][j];
		res[i][S[i] - 'a'] = i;
	}
	return res;
}
// mod 1000000007 の世界で a += b する関数
void add(long long& a, long long b) {
	a += b;
	if (a >= MOD) a -= MOD;
}
const ll ainf = 998244353;

void solv() {

	ll n, m;
	cin >> n >> m;
	if (n == 1) {
		cout << m << endl;
		return;
	}
	ll res = 1;

	for (ll i = 2; i * i < m; i++)
	{
		if (m % i != 0) continue;
		ll di = m / i;
		
		if (di < n) continue;
		res = max(i, res);

		if (i < n) continue;
		res = max(di, res);
	}
	cout << res << endl;
}

int main() {
	//COMinit();
	solv();

	return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <string.h>
#define ll long long
#define rep(i,n) for(ll i=0;i<(n);i++)
#define max(p,q) ((p)>(q)?(p):(q))
#define min(p,q) ((p)<(q)?(p):(q))
#define chmax(a,b) ((a)=(a)>(b)?(a):(b))
#define chmin(a,b) ((a)=(a)<(b)?(a):(b))
#define abs(p) ((p)>=(0)?(p):(-(p)))
#define MOD 1000000007
ll powll(ll a,ll b){ll r=1;rep(i,b){r*=a;}return r;}
#define swap(a,b) do{ll w=(a);(a)=(b);(b)=w;}while(0)
#define swapd(a,b) do{double w=(a);(a)=(b);(b)=w}while(0)
#define in(a) scanf("%lld", &(a))
#define in2(a,b) scanf("%lld %lld",&(a),&(b))
#define in3(a,b,c) scanf("%lld %lld %lld",&(a),&(b),&(c))
#define ind(a) scanf("%lf", &(a))
#define ins(a) scanf("%s", (a))
#define put(a) printf("%lld\n", (a))
#define putd(a) printf("%.15f\n", (a))
//      puts(a) printf("%s\n", a) 文字はこっち
//your code here!
int main(void){
    ll N, ans=1;
    in(N);
    while(1){
        if(powll(++ans,2)>N){
            put(powll(--ans, 2));
            break;
        }
    }
    return 0;
}


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

int main() {

  int k;
  string s;
  cin >> k >> s;
  
  if (s.size() <= k) {
    cout << s << endl;
  } else {
    for (int i = 0; i < k; i++) {
      cout << s[i];
      if (i == (k - 1)) {
        cout << "...";
      }
    }
  }
 
}


Measured memory_bytes: 3612
lst=[1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51]
k = int(input())
print(lst[k-1])

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

using ll = long long;

struct edge{int to; ll cost;};

const int mxc = 1e5+1;
ll depth[mxc];
vector<edge> G[mxc];
int n;


void dfs(int v, int p, ll dist) {
    depth[v] = dist;
    for(auto e : G[v]) {
        if(e.to == p) continue;
        dfs(e.to, v, dist + e.cost);
    }
}

int main() {
    cin >> n;
    for(int i = 0; i < n - 1; i++) {
        int a, b; 
        ll c;
        cin >> a >> b >> c;
        a--, b--;
        G[a].push_back({b, c});
        G[b].push_back({a, c});
    }

    int q, k;
    cin >> q >> k;
    k--;
    dfs(k, -1, 0);
    for(int i = 0; i < q; i++) {
        int x, y;
        cin >> x >> y;
        x--, y--;
        cout << depth[x] + depth[y] << endl;
    }

    return 0;
}

Measured memory_bytes: 14336
N,T=map(int,input().split())
root=[tuple(map(int,input().split())) for i in range(N)]

minc=1001
for cand in root:
    if cand[1]<=T:
        if cand[0]<minc:
            minc=cand[0]
if minc==1001:
    print("TLE")
else:
    print(minc)

Measured memory_bytes: 3060
R, C, N = map(int, input().split())

def makexy(x1, y1):
    if y1 == 0:
        return x1
    elif x1==R:
        return R+y1
    elif y1 == C:
        return R*2 + C - x1
    else:
        return R*2 + C*2 - y1


XY = []
XY2 = []
D = []
for _ in range(N):
    x1, y1, x2, y2 = map(int, input().split())
    if (x1 in [0, R] or y1 in [0, C]) and (x2 in [0, R] or y2 in [0, C]):
        xy1 = makexy(x1, y1)
        xy2 = makexy(x2, y2)
        xy1, xy2 = sorted((xy1, xy2))
        XY.append((xy1, xy2))
        XY2.append((xy1, 0))
        XY2.append((xy2, 1))
        D.append(xy2-xy1)

#print(XY)
XY.sort()
XY2.sort()
D.sort()

D2 = []
Stack = []
for xy in XY2:
    if xy[1] == 0:
        Stack.append(xy)
    else:
        D2.append(xy[0]-Stack[-1][0])
        del Stack[-1]

D2.sort()
#print(D, D2)
if D == D2:
    print("YES")
else:
    print("NO")


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

vector<string> split(string s) {
  s += " ";
  vector<string> res;
  string str;
  for (int i = 0; i < s.size(); ++i) {
    if (s[i] == ' ') {
      res.push_back(str);
      str = "";
    } else {
      str += s[i];
    }
  }

  return res;
}

vector<int> convert(int a, int b) {
  vector<int> res(26);
  for (int i = 0; i < 26; ++i) {
    res[i] = (a * i + b) % 26;
  }

  return res;
}

vector<string> calc(const vector<string> &v, const vector<int> &t) {
  vector<string> res;
  for (string s : v) {
    for (int i = 0; i < s.size(); ++i) {
      s[i] = (t[s[i] - 'a'] + 'a');
    }
    res.push_back(s);
  }

  return res;
}

void solver() {
  string s;
  getline(cin, s);
  vector<string> v = split(s);

  for (int i = 1; i < 26; ++i) {
    if (__gcd(i, 26) - 1) continue;
    for (int j = 0; j < 26; ++j) {
      vector<int> table = convert(i, j);
      vector<string> res = calc(v, table);

      bool f = false;
      for (string u : res) {
        if (u == "that" || u == "this") {
          f = true;
        }
      }

      if (f) {
        for (int k = 0; k < res.size(); ++k) {
          cout << res[k] << (k + 1 == res.size() ? "\n" : " ");
        }
        return;
      }
    }
  }
}

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

  for (int i = 0; i < n; ++i) {
    solver();
  }
}

Measured memory_bytes: 3172
package main

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

func main() {
	R := nextInt()
	G := nextInt()
	B := nextInt()
	N := nextInt()

	var ans int
	for x := 0; x <= N; x++ {
		for y := 0; y <= N; y++ {
			tmp := N - R*x - G*y
			if tmp >= 0 && tmp%B == 0 {
				ans++
			}
		}
	}

	fmt.Println(ans)
}

// Input. ----------

var sc = bufio.NewScanner(os.Stdin)

func init() {
	sc.Buffer([]byte{}, math.MaxInt64)
	sc.Split(bufio.ScanWords)
}

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

	return i
}

func nextFloat() float64 {
	sc.Scan()
	f64, err := strconv.ParseFloat(sc.Text(), 64)
	if err != nil {
		panic(err)
	}

	return f64
}

func nextString() string {
	sc.Scan()
	if err := sc.Err(); err != nil {
		panic(err)
	}

	return sc.Text()
}

// ---------- Input.

// Util. ----------

func abs(x int) int {
	return int(math.Abs(float64(x)))
}

func min(x, y int) int {
	return int(math.Min(float64(x), float64(y)))
}

func max(x, y int) int {
	return int(math.Max(float64(x), float64(y)))
}

// ---------- Util.


Measured memory_bytes: 640
// ---------- begin SegmentTree Point update Range query ----------
mod segment_tree {
    pub struct PURQ<T: Clone, F: Fn(T, T) -> T> {
        n: usize,
        a: Vec<T>,
        id: T,
        op: F,
    }
    #[allow(dead_code)]
    impl<T: Clone, F: Fn(T, T) -> T> PURQ<T, F> {
        pub fn new(n: usize, id: T, op: F) -> PURQ<T, F> {
            let mut k = 1;
            while k < n {
                k *= 2;
            }
            PURQ {
                n: k,
                a: vec![id.clone(); 2 * k],
                id: id,
                op: op,
            }
        }
        pub fn update(&mut self, x: usize, v: T) {
            let mut k = self.n + x;
            let a = &mut self.a;
            a[k] = v;
            k >>= 1;
            while k > 0 {
                a[k] = (self.op)(a[2 * k].clone(), a[2 * k + 1].clone());
                k >>= 1;
            }
        }
        pub fn update_tmp(&mut self, x: usize, v: T) {
            self.a[x + self.n] = v;
        }
        pub fn update_all(&mut self) {
            for k in (1..(self.n)).rev() {
                self.a[k] = (self.op)(self.a[2 * k].clone(), self.a[2 * k + 1].clone());
            }
        }
        pub fn find(&self, mut l: usize, mut r: usize) -> T {
            let mut p = self.id.clone();
            let mut q = self.id.clone();
            l += self.n;
            r += self.n;
            while l < r {
                if (l & 1) == 1 {
                    p = (self.op)(p, self.a[l].clone());
                    l += 1;
                }
                if (r & 1) == 1 {
                    r -= 1;
                    q = (self.op)(self.a[r].clone(), q);
                }
                l >>= 1;
                r >>= 1;
            }
            (self.op)(p, q)
        }
    }
}
// ---------- end SegmentTree Point update Range query ----------

use std::io::Read;
use std::io::Write;

fn run() {
    let out = std::io::stdout();
    let mut out = std::io::BufWriter::new(out.lock());
    let mut s = String::new();
    std::io::stdin().read_to_string(&mut s).unwrap();
    let mut it = s.trim().split_whitespace();
    let n: usize = it.next().unwrap().parse().unwrap();
    let s: Vec<usize> = it.next().unwrap().chars().map(|c| 1usize << (c.to_digit(36).unwrap() as usize)).collect();
    let mut seg = segment_tree::PURQ::new(n, 0usize, |a, b| a | b);
    for (i, d) in s.iter().enumerate() {
        seg.update_tmp(i, *d);
    }
    seg.update_all();
    let q: usize = it.next().unwrap().parse().unwrap();
    for _ in 0..q {
        let op: usize = it.next().unwrap().parse().unwrap();
        if op == 1 {
            let k: usize = it.next().unwrap().parse().unwrap();
            let v = 1usize << (it.next().unwrap().chars().next().unwrap().to_digit(36).unwrap() as usize);
            seg.update(k - 1, v);
        } else {
            let l: usize = it.next().unwrap().parse().unwrap();
            let r: usize = it.next().unwrap().parse().unwrap();
            let ans = seg.find(l - 1, r).count_ones();
            writeln!(out, "{}", ans).ok();
        }
    }
}

fn main() {
    run();
}


Measured memory_bytes: 19704
import math
from itertools import combinations
from itertools import combinations_with_replacement
from itertools import product
from collections import defaultdict
from collections import deque
from collections import Counter
import heapq


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


def input_int():
    return int(input())


N = input_int()
A_LI = input_li()
dp = [[0] * 2 for _ in range(N)]
dp[0][0] = A_LI[0]
dp[0][1] = -A_LI[0]
for i in range(1, N):
    dp[i][0] = max(dp[i - 1][0] + A_LI[i], dp[i - 1][1] - A_LI[i])
    dp[i][1] = max(dp[i - 1][0] - A_LI[i], dp[i - 1][1] + A_LI[i])
print(dp[-1][0])


Measured memory_bytes: 98652
#include <bits/stdc++.h>
const long long INF = 1LL << 60;
const long long MOD = 1000000007;
#define rep(i, n) for (ll i = 0; i < (n); ++i)
#define rep1(i, n) for (ll i = 1; i <= (n); ++i)
#define rrep(i, n) for (ll i = (n - 1); i >= 0; --i)
#define perm(c) sort(ALL(c));for(bool c##p=1;c##p;c##p=next_permutation(ALL(c)))
#define ALL(obj) (obj).begin(), (obj).end()
#define RALL(obj) (obj).rbegin(), (obj).rend()
#define MAX max<ll>
#define MIN min<ll>
#define pb push_back
#define to_s to_string
#define len(v) (ll)v.size()
#define UNIQUE(v) v.erase(unique(v.begin(), v.end()), v.end())
#define print(x) cout << (x) << '\n'
#define drop(x) cout << (x) << '\n', exit(0)
#define debug(x) cout << #x << ": " << (x) << '\n'
using namespace std;
using ll = long long;
typedef pair<ll, ll> P;
typedef vector<ll> vec;
typedef vector<vector<ll>> vec2;
typedef vector<vector<vector<ll>>> vec3;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
ll devc(ll x, ll y) { return (x + y - 1) / y; }

int main()
{
    cin.tie(0);
    ios::sync_with_stdio(0);
    cout << fixed << setprecision(20);

    ll X, Y;
    cin >> X >> Y;
    ll ans = 0;
    while(X <= Y){
        X *= 2;
        ++ans;
    }
    print(ans);

    return 0;
}

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

L.sort()
#print(L)

ans=0
for i in range(0, N-2):
    for j in range(i+1, N-1):


        left, right = j, N

        while right-left > 1:
            mid=(left+right) // 2
            if L[i]+L[j] <= L[mid]:
                right=mid
            else:
                left=mid
        ans += left - j
        #print(i,j,left)
print(ans)

Measured memory_bytes: 44380
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.StringTokenizer;

/**
 * @author Don Li
 */
public class Main {
    void solve() {
        int H = in.nextInt(), W = in.nextInt();
        int h = in.nextInt(), w = in.nextInt();
        
        int painted = h * W + H * w - h * w;
        out.println(H * W - painted);
    }
    
    public static void main(String[] args) {
        in = new FastScanner(new BufferedReader(new InputStreamReader(System.in)));
        out = new PrintWriter(System.out);
        new Main().solve();
        out.close();
    }
    
    static FastScanner in;
    static PrintWriter out;
    
    static class FastScanner {
        BufferedReader in;
        StringTokenizer st;
        
        public FastScanner(BufferedReader in) {
            this.in = in;
        }
        
        public String nextToken() {
            while (st == null || !st.hasMoreTokens()) {
                try {
                    st = new StringTokenizer(in.readLine());
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
            return st.nextToken();
        }
        
        public int nextInt() {
            return Integer.parseInt(nextToken());
        }
        
        public long nextLong() {
            return Long.parseLong(nextToken());
        }
        
        public double nextDouble() {
            return Double.parseDouble(nextToken());
        }
    }
}


Measured memory_bytes: 21076
package main

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

var scanner = bufio.NewScanner(os.Stdin)

func nextString() string {
	scanner.Scan()
	return scanner.Text()
}

func nextInt() (int, error) {
	return strconv.Atoi(nextString())
}

func nextFloat64() (float64, error) {
	return strconv.ParseFloat(nextString(), 64)
}

func stringifyArray(arr []int) string {
	return strings.TrimRight(fmt.Sprintf("%+v", arr)[1:], "]")
}

func main() {
	scanner.Split(bufio.ScanRunes)

	var alphabets = regexp.MustCompile(`^[a-zA-Z]$`)
	counts := make([]int, 26)
	for {
		c := nextString()
		if c == "" {
			break
		}
		if alphabets.MatchString(c) {
			c = strings.ToLower(c)
			counts[int(c[0])-97]++
		}
	}

	for i := range counts {
		fmt.Printf("%c : %d\n", rune(i+97), counts[i])
	}
}



Measured memory_bytes: 1276
#define _GLIBCXX_DEBUG
// header {{{
#include <bits/stdc++.h>
using namespace std;
#define CPP_STR(x) CPP_STR_I(x)
#define CPP_CAT(x,y) CPP_CAT_I(x,y)
#define CPP_STR_I(args...) #args
#define CPP_CAT_I(x,y) x ## y
#define ASSERT(expr...) assert((expr))
using i8  = int8_t;
using u8  = uint8_t;
using i16 = int16_t;
using u16 = uint16_t;
using i32 = int32_t;
using u32 = uint32_t;
using i64 = int64_t;
using u64 = uint64_t;
using f32 = float;
using f64 = double;
using f80 = __float80;
// }}}
constexpr i64 INF = 1'010'000'000'000'000'017LL;
constexpr i64 MOD = 1'000'000'007LL;
constexpr f64 EPS = 1e-12;
constexpr f64 PI = 3.14159265358979323846;
// util {{{
#define FOR(i, start, end) for(i64 i = (start), CPP_CAT(i,xxxx_end)=(end); i < CPP_CAT(i,xxxx_end); ++i)
#define REP(i, n) FOR(i, 0, n)
#define ALL(f,c,...) (([&](decltype((c)) cccc) { return (f)(std::begin(cccc), std::end(cccc), ## __VA_ARGS__); })(c))

template<typename C>
i64 SIZE(const C& c) { return static_cast<i64>(c.size()); }
template<typename T, size_t N>
i64 SIZE(const T (&)[N]) { return static_cast<i64>(N); }
template<typename T, typename U, typename Comp=less<>>
bool chmax(T& xmax, const U& x, Comp comp={}) {
    if(comp(xmax, x)) {
        xmax = x;
        return true;
    }
    return false;
}

template<typename T, typename U, typename Comp=less<>>
bool chmin(T& xmin, const U& x, Comp comp={}) {
    if(comp(x, xmin)) {
        xmin = x;
        return true;
    }
    return false;
}
// }}}

// init {{{
struct ProconInit {
    static constexpr int IOS_PREC = 15;
    static constexpr bool AUTOFLUSH = false;

    ProconInit() {
        cin.tie(nullptr);
        ios::sync_with_stdio(false);
        cout << fixed << setprecision(IOS_PREC);
        if(AUTOFLUSH)
            cout << unitbuf;
    }
} PROCON_INIT;
// }}}

//--------------------------------------------------------------------

signed main() {
    int a,b;
    cin>>a>>b;

    cout<< max(0, a - 2*b ) <<endl;

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

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

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

    int n = s.length() / 2;
    for(int i=n-1; i>=1; i--){
        if(s.substr(0,i) == s.substr(i,i)){
            cout << 2 * i << endl;
            return 0;
        }
    }
}

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

char march[] = {'M', 'A', 'R', 'C', 'H'};

int next_combination(int sub) {
    int x = sub & -sub, y = sub + x;
    return (((sub & ~y) / x) >> 1) | y;
}

int main() {
    int N; cin >> N; 
    map<char, int> cnt_by_ini;
    for (char c : march) cnt_by_ini[c] = 0;
    for (int i = 0; i < N; i++) {
        string name; cin >> name;
        if (cnt_by_ini.count(name[0])) cnt_by_ini[name[0]]++;
    }

    ll ans = 0;
    int mask = (1 << 3) - 1;
    for (; mask < (1 << 5); mask = next_combination(mask)) {
        ll pattern = 1;
        for (int i = 0; i < 5; i++) {
            if ((mask >> i & 1) == 1) {
                pattern *= (ll) cnt_by_ini[march[i]];
            }
        }
        ans += pattern;
    }

    cout << ans << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define FOR(var, begin, end) for (int var = (begin); var <= (end); var++)
#define RFOR(var, begin, end) for (int var = (begin); var >= (end); var--)
#define REP(var, length) FOR(var, 0, length - 1)
#define RREP(var, length) RFOR(var, length - 1, 0)
#define EACH(value, var) for (auto value : var)
#define SORT(var) sort(var.begin(), var.end())
#define REVERSE(var) reverse(var.begin(), var.end())
#define RSORT(var) SORT(var); REVERSE(var)
#define OPTIMIZE_STDIO ios::sync_with_stdio(false); cin.tie(0); cout.precision(10); cout << fixed
#define endl '\n'

const int INF = 1e9;
const int MOD = 1e9 + 7;
const ll LINF = 1e18;

void solve(istream& cin, ostream& cout) {
  ll n;
  cin >> n;
  ll ans = 0;
  FOR(x, 1, n) {
    ll num = n / x;
    ll y = num * x;
    ans += (x + y) * num / 2;
  }
  cout << ans << endl;
}

#ifndef TEST
int main() {
  OPTIMIZE_STDIO;
  solve(cin, cout);
  return 0;
}
#endif


Measured memory_bytes: 3652
s=input()
n=len(s)
mod=10**9+7
dp=[[0]*3 for i in range(n)]
data=[0]*(n)
data[0]=1
for i in range(1,n):
    data[i]=data[i-1]*3%mod
count=0
if s[0]=="A":
    dp[0][0]=1
if s[0]=="?":
    dp[0][0]=1
    count+=1
for i in range(1,n):
    if s[i]=="A":
        dp[i][0]=(dp[i-1][0]+data[count])%mod
        dp[i][1]=dp[i-1][1]
        dp[i][2]=dp[i-1][2]
    elif s[i]=="B":
        dp[i][0]=dp[i-1][0]
        dp[i][1]=(dp[i-1][1]+dp[i-1][0])%mod
        dp[i][2]=dp[i-1][2]
    elif s[i]=="C":
        dp[i][0]=dp[i-1][0]
        dp[i][1]=dp[i-1][1]
        dp[i][2]=(dp[i-1][2]+dp[i-1][1])%mod
    else:
        dp[i][0]=(3*dp[i-1][0]+data[count])%mod
        dp[i][1]=(3*dp[i-1][1]+dp[i-1][0])%mod
        dp[i][2]=(3*dp[i-1][2]+dp[i-1][1])%mod
        count+=1
print(dp[n-1][2])

Measured memory_bytes: 53996
#K-th CommonDivisor(B)
a, b, k = map(int, input().split())
if a > b:
    c = b
    d = a
else:
    c = a
    d = b

lst = []
for i  in range(1, c+1):
    if (c % i == 0) and (d % i == 0):
        lst.append(i)

lst = sorted(lst, reverse=True)
print(lst[k-1])

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

int my_strlen(char *str){
  int len = 0;
  while(str[len]){
    len++;
  }
  return len;
}

int main(){
  char A[101];
  char B[101];

  scanf("%s", A);
  scanf("%s", B);

  int a = my_strlen(A);
  int b = my_strlen(B);

  if(a>b){
    printf("GREATER\n");
    return 0;
  }else if(b>a){
    printf("LESS\n");
    return 0;
  }else{
    int i = 0;
    while(i < a){
      if(A[i]>B[i]){
        printf("GREATER\n");
        return 0;
      }else if(B[i]>A[i]){
        printf("LESS\n");
        return 0;
      }
      i++;
    }
    printf("EQUAL\n");
    return 0;
  }
}


Measured memory_bytes: 128
function Main(input) {
  const args = input.split("\n");
  const num = parseInt(args[0]);
  const half = num / 2;
  const str = args[1];
  var ret = false;
  var countR = 0;
  var countB = 0;

  for(var i = 0; i < num; i ++) {
    var ch = str[i];
    if (ch === 'R') {
      countR++;
      if (countR > half) {
        ret = true;
        break;
      }
    } else {
      countB++;
      if (countB >= half) {
        ret = false;
        break;
      }
    }
  }

  console.log(ret ? 'Yes' : 'No');
}


Main(require("fs").readFileSync("/dev/stdin", "utf8"));

Measured memory_bytes: 7372
import sys
input = lambda: sys.stdin.readline().rstrip()

N = int(input())
A = int(input())
B = int(input())
C = int(input())
D = int(input())
E = int(input())

min_move = min(A,B,C,D,E)

print((N+min_move-1) // min_move + 4)

Measured memory_bytes: 38256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
int main(){
  int i,a=8,n;
  cin >> n;
  for(i=599;;i+=200){
    if(n<=i){
      cout << a << endl;
      return 0;
    }
    a--;
  }
}

Measured memory_bytes: 3632
//Coded by tzc_wk
/*
数据不清空，爆零两行泪。
多测不读完，爆零两行泪。
边界不特判，爆零两行泪。
贪心不证明，爆零两行泪。
D P 顺序错，爆零两行泪。
大小少等号，爆零两行泪。
变量不统一，爆零两行泪。
越界不判断，爆零两行泪。
调试不注释，爆零两行泪。
溢出不 l l，爆零两行泪。
忘文件操作，爆零两行泪。
*/
#include <bits/stdc++.h>
using namespace std;
#define fi			first
#define se			second
#define fz(i,a,b)	for(int i=a;i<=b;i++)
#define fd(i,a,b)	for(int i=a;i>=b;i--)
#define foreach(it,v) for(__typeof(v.begin()) it=v.begin();it!=v.end();it++)
#define all(a)		a.begin(),a.end()
#define giveup(...) return printf(__VA_ARGS__),0;
#define fill0(a)	memset(a,0,sizeof(a))
#define fill1(a)	memset(a,-1,sizeof(a))
#define fillbig(a)	memset(a,0x3f,sizeof(a))
#define fillsmall(a) memset(a,0xcf,sizeof(a))
#define mask(a)		(1ll<<(a))
#define maskx(a,x)	((a)<<(x))
#define _bit(a,x)	(((a)>>(x))&1)
#define _sz(a)		((int)(a).size())
#define filei(a)	freopen(a,"r",stdin);
#define fileo(a)	freopen(a,"w",stdout);
#define fileio(a) 	freopen(a".in","r",stdin);freopen(a".out","w",stdout)
#define eprintf(...) fprintf(stderr,__VA_ARGS__)
#define put(x)		putchar(x)
#define eoln        put('\n')
#define space		put(' ')
#define y1			y_chenxiaoyan_1
#define y0			y_chenxiaoyan_0
#define int long long
typedef pair<int,int> pii;
inline int read(){
	int x=0,neg=1;char c=getchar();
	while(!isdigit(c)){
		if(c=='-')	neg=-1;
		c=getchar();
	}
	while(isdigit(c))	x=x*10+c-'0',c=getchar();
	return x*neg;
}
inline void print(int x){
	if(x<0){
		putchar('-');
		print(abs(x));
		return;
	}
	if(x<=9)	putchar(x+'0');
	else{
		print(x/10);
		putchar(x%10+'0');
	}
}
inline int qpow(int x,int e,int _MOD){
	int ans=1;
	while(e){
		if(e&1)	ans=ans*x%_MOD;
		x=x*x%_MOD;
		e>>=1;
	}
	return ans;
}
int suf[200005],n,cnt[2020],ans=0;
char s[200005];
const int MOD=2019;
signed main(){
	cin>>s+1;
	n=strlen(s+1);
	cnt[0]++;
	fd(i,n,1)	suf[i]=(suf[i+1]+(s[i]-'0')*qpow(10,n-i,MOD))%MOD,cnt[suf[i]]++;
	fz(i,0,2018)	ans+=(cnt[i])*(cnt[i]-1)/2;
	cout<<ans<<endl;
	return 0;
}

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

#define __STDC_FORMAT_MACROS
#define p64 PRId64

#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i, n) FOR (i, 0, n)
#define ALL(f, x, ...)                                                         \
    ([&] (decltype ((x)) ALL) {                                                \
        return (f) (begin (ALL), end (ALL), ##__VA_ARGS__);                    \
    }) (x)

using namespace std;
using ll = int64_t;

int main() {
    int N;
    cin >> N;
    vector<int> p (N, 0);
    REP (i, N) cin >> p[i];
    int cnt = 0;
    REP (i, N) if (p[i] != i + 1) cnt++;
    cout << (cnt <= 2 ? "YES" : "NO") << endl;
    return 0;
}

Measured memory_bytes: 3584
#include <bits/stdc++.h>
  
using namespace std;
  
#define rep(i,n) REP(i,0,n)
#define REP(i,s,e) for(int i=(s); i<(int)(e); i++)
#define pb push_back
#define all(r) r.begin(),r.end()
#define rall(r) r.rbegin(),r.rend()
#define fi first
#define se second
  
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
 
const int INF = 1e9;
const ll MOD = 1e9 + 7;
double EPS = 1e-8;

int main(){
	int n;
	cin>>n;
	vl a(n);
	rep(i, n) cin>>a[i];
	if(n == 1){
		cout<<"YES"<<endl;
		return 0;
	}
	ll sum = 0LL;
	rep(i, n) sum += a[i];
	if(sum % ((ll)n*(n+1LL)/2LL) != 0) {
		cout<<"NO"<<endl;
		return 0;
	}
	ll k = sum / ((ll)n*(n+1LL)/2LL);
	vl d(n);
	rep(i, n) d[i] = a[(i+1)%n] - a[i];
	sort(all(d));
	ll kk = 0LL;
	rep(i, n-1){
		ll dif = (ll)d[i+1]-d[i];
		if(dif%n != 0) {
			cout<<"NO"<<endl;
			return 0;
		}
		ll t = dif / n;
		kk += t * (i+1LL);
	}
	if(kk == k) cout<<"YES"<<endl;
	else cout<<"NO"<<endl;
}


Measured memory_bytes: 1792
import java.util.*;
 
public class Main {
	
    public static void main(String[] args) {
    	Scanner sc = new Scanner(System.in);
    	int S = sc.nextInt();
    	List<Integer> list = new ArrayList<>();
    	list.add(S);
    	while (true) {
        	if (S%2 == 0) {
        		S /= 2;
        		if (list.contains(S)) {
        			break;
        		} else {
        			list.add(S);
        		}
        	} else {
        		S = 3*S+1;
        		if (list.contains(S)) {
        			break;
        		} else {
        			list.add(S);
        		}
        	}
    	}
    	System.out.println(list.size()+1);
    }
}

Measured memory_bytes: 21588
/*      ░░█ ▄▀█ █   █▀ █░█ █▀█ █▀▀ █▀▀   █▀█ ▄▀█ █▀▄▀█
        █▄█ █▀█ █   ▄█ █▀█ █▀▄ ██▄ ██▄   █▀▄ █▀█ █░▀░█     */

// Author : Udit "luctivud" Gupta @ (https://www.linkedin.com/in/udit-gupta-1b7863135/)


#include <bits/stdc++.h>
#pragma GCC optimize "trapv"

using namespace std;

typedef long long int lld;
typedef unsigned long long int llu;


#define       TESTCASES()  cin >> (T3X0); T353 = T3X0; while(T3X0--)
#define       _input(V3C)  for(auto &V3C_I7 : (V3C)) cin >> (V3C_I7)
#define mems(A77AY, V4LU)  memset((A77AY), (V4LU), sizeof((A77AY)))
#define  CH3K(I7, E4, S7)  (((S7)<0) ? (I7)>(E4) : (I7)<(E4))
#define for4(I7,S4,E4,S7)  for(auto I7=(S4); CH3K(I7,E4,S7); (I7)+=(S7))




void solveEachTest(lld T35TC453N = 1) {

	lld n; cin >> n;
	vector <lld> arr(n);
	_input(arr);

	vector<lld> count(n, 0);
	for4 (i, 0ll, n, 1ll) {
		lld c = 0ll;
		while (arr[i] % 2 == 0) {
			c += 1;
			arr[i] /= 2;
		}
		count[i] = c;
	}

	cout << *min_element(count.begin(), count.end());

	cout << "\n";

	return;
}


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

	lld T3X0 = 0, T353 = 1;

	// TESTCASES()
	solveEachTest(T353 - T3X0);
	return 0;
}
// Random Thought :  AtCoder Practice

Measured memory_bytes: 3640
s=list(input())
n=len(s)
k=int(input())
count=[]
i=0
while i<=n-1:
    j=0
    while i+j+1<=n-1 and s[i+j]==s[i+j+1]:
        j+=1
    count.append(j+1)
    i+=(j+1)

length=len(count)
if length==1:
    print((n*k)//2)
   
else:
    if s[0]==s[-1]:
        ans=0
        for l in range(length):
            if l!=0 and l!=length-1:
                ans+=(count[l]//2)*k
        ans+=(count[0]//2+count[-1]//2)
        ans+=((count[0]+count[-1])//2)*(k-1)
        print(ans)
    else:
        ans=0
        for m in count:
            ans+=(m//2)*k
        print(ans)



Measured memory_bytes: 9244
import itertools
N, M, Q = map(int, input().split())
buff = [list(map(int, input().split())) for _ in range(Q)]

ans = 0
for A in itertools.combinations_with_replacement(range(1, M+1), N):
    score = 0
    for a, b, c, d in buff:
        if A[b-1] - A[a-1] == c:
            score += d
    ans = max(ans, score)

print(ans)

Measured memory_bytes: 9192
import java.util.*;

public class Main{
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        int B[] = new int[N - 1];
        for(int i = 0; i < N - 1; i++){
            B[i] = sc.nextInt();
        }
        int result = B[0] + B[N - 2];
        for(int i = 0; i < N - 2; i++){
            if(B[i] > B[i + 1]){
                result += B[i + 1];
            }else{
                result += B[i];
            }
        }
        System.out.println(result);
    }
}

Measured memory_bytes: 21972
#include<bits/stdc++.h>
using namespace std;
struct cube{
  int p[30];
  int d;
  bool check(){
    int i;
    for(i=0;i<8;i++) if(p[i]!=p[i+1]) return false;
    for(i=9;i<11;i++) if(p[i]!=p[i+1]) return false;
    for(i=12;i<14;i++) if(p[i]!=p[i+1]) return false;
    for(i=15;i<17;i++) if(p[i]!=p[i+1]) return false;
    for(i=18;i<20;i++) if(p[i]!=p[i+1]) return false;
    for(i=21;i<29;i++) if(p[i]!=p[i+1]) return false;
    return true;
  }
  cube rotate(int x){
    cube c;c.d=d+1;
    for(int i=0;i<30;i++) c.p[i]=p[i];
    if(x==0){
      c.p[6]=p[21];c.p[21]=p[6];
      c.p[7]=p[22];c.p[22]=p[7];
      c.p[8]=p[23];c.p[23]=p[8];
      c.p[12]=p[17];c.p[17]=p[12];
      c.p[9]=p[11];c.p[11]=p[9];
      return c;
    }
    if(x==1){
      c.p[2]=p[21];c.p[21]=p[2];
      c.p[5]=p[24];c.p[24]=p[5];
      c.p[8]=p[27];c.p[27]=p[8];
      c.p[11]=p[18];c.p[18]=p[11];
      c.p[12]=p[14];c.p[14]=p[12];
      return c;
    }
    if(x==2){
      c.p[2]=p[29];c.p[29]=p[2];
      c.p[1]=p[28];c.p[28]=p[1];
      c.p[0]=p[27];c.p[27]=p[0];
      c.p[14]=p[15];c.p[15]=p[14];
      c.p[18]=p[20];c.p[20]=p[18];
      return c;
    }
    if(x==3){
      c.p[6]=p[29];c.p[29]=p[6];
      c.p[3]=p[26];c.p[26]=p[3];
      c.p[0]=p[23];c.p[23]=p[0];
      c.p[9]=p[20];c.p[20]=p[9];
      c.p[15]=p[17];c.p[17]=p[15];
      return c;
    }
  }
};
int main(){
  int n;cin>>n;
  while(n--){
    int i,j,k;
    cube c;
    for(i=0;i<30;i++) cin >> c.p[i];
    c.d=0;
    queue<cube> q;
    q.push(c);
    int o = 8;
    while(!q.empty()){
      c=q.front();q.pop();
      if(c.d>=o) continue;
      if(c.check()) {
	o=min(o,c.d);
	continue;
      }
      for(i=0;i<4;i++) q.push(c.rotate(i));
    }
    cout << o << endl;
  }
  return 0;
}

Measured memory_bytes: 9524
#include <stdio.h>

int main( int argc, char *argv[] )
{
	int k,s;
	scanf("%d%d",&k,&s);
	if(s-k<0)k=s;
	int ans=0,extra=0;
	for(int i=0; i<=k; i++){
		if(s-i<0 || s-i > 2*k){}		
		else if(s-i<k)ans+=s-i+1;
		else ans+=2*k+1-(s-i);
		//printf("x=%d\n%d\n",i,ans);
	}
	printf("%d\n",ans);
	return 0;
}


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

struct sta{
  int t;
  int from;
  int to;
};

int main(){
  while(1){
    int n,m;
    cin >> n >> m;
    if(n==0) return 0;
    vector<sta> e(m);
    int t,s,d;
    for(int i=0;i<m;i++){
      cin >> e[i].t >> e[i].from >> e[i].to;
      e[i].from--,e[i].to--;
    }
    sort(e.begin(),e.end(),[](const sta &l, const sta &r){
	    return l.t < r.t;
    });
    vector<int> a(n,0);
    a[0]=1;
    int count=1;
    for(int i=0;i<m;i++){
      if(a[e[i].from]==1) if(a[e[i].to]==0) a[e[i].to]=1,count++;
    }
    cout << count << endl;
  }
  return 0;
}


Measured memory_bytes: 3420
//#include "pch.h" 
#include <iostream>
#include <string>
#include <string.h>
#include <algorithm>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <cmath>
#include <stdio.h>
#include <vector>
#include <time.h>
#include <iomanip>
#include <thread>
#include <atomic>
#include <mutex>
#include <future>
#define double long double
#define int long long
#define low lower_bound
#define upp upper_bound
#define mod 1000000007 //10^9+7
#define inf 10000000000000000 //10^16
#define rep(i,n) for(int i=0;i<n;i++)
#define all(vec) vec.begin(),vec.end()
#define vsort(vec) sort(all(vec))
#define vrever(vec) reverse(all(vec));
#define vunsort(vec) vsort(vec); vrever(vec);
#define bisea binary_search
using namespace std;
int n;
vector<int>b;
signed main() {
	cin >> n;
	bool can = true;
	rep(i, n) {
		int a;
		cin >> a;
		b.push_back(a);
		if (i + 1 < b[i]) {
			can = false;
		}
	}
	if (!can) {
		cout << -1 << endl;
	}
	else {
		vector<int>ans;
		while(1<b.size()) {
			bool can = false;
			for (int i = b.size() - 1; i >= 0; i--) {
				if (i + 1 <= b[i]) {
					can = true;
					ans.push_back(b[i]);
					b.erase(b.begin() + i);
					break;
				}
			}
			if (!can) {
				ans.push_back(b[1]);
				b.erase(b.begin() + 1);
			}
			/*for (int i: b) {
				cout << i << " ";
			}
			cout << endl;*/
		}
		ans.push_back(1);
		vrever(ans);
		rep(i, n) {
			cout << ans[i] << endl;
		}
	}
}

Measured memory_bytes: 256
#include <algorithm>
#include <array>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <deque>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <string>
#include <stack>
#include <vector>

using namespace std;
using ll = long long;

#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))

#define MOD ((ll)1000000007)


int main(int argc, char const *argv[])
{
	cin.tie(nullptr);
	ios::sync_with_stdio(false);
	cout << fixed << setprecision(15);

	int N;
	cin >> N;

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

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

	int p_alice = 0;
	int p_bob = 0;

	for (int i = N - 1; i >= 0; i -= 2)
	{
		p_alice += a[i];
	}

	for (int i = N - 2; i >= 0; i -= 2)
	{
		p_bob += a[i];
	}

	cout << (p_alice - p_bob) << endl;
	return 0;
}


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

int main() {
	bool IsNine = false;
	int num;
	cin >> num;
	if (num % 10 == 9) IsNine = true;
	else {
		num /= 10;
		if (num == 9) IsNine = true;
	}
	if (IsNine) cout << "Yes" << endl;
	else cout << "No" << endl;
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
long long x[10000010];
#define rep(i,n) for(int i=0; i<(n); i++)
#define reps(i,n) for(int i=1; i<(n); i++)
#define pii pair<long,long>
#define all(x) (x).begin(), (x).end()
#define int long long
#define setout(n,x) setw(n) << setfill(x)
#define Fixed fixed << setprecision(10)
using namespace std;
signed main(){

    cin.tie(0);
    ios::sync_with_stdio(false);


    rep(i,5) cin>>x[i];

    sort(x,x+5);

    int h;
    cin>>h;

    if(x[4]-x[0]<=h) cout<<"Yay!"<<'\n';
    else cout<<":("<<'\n';
}

Measured memory_bytes: 256
#include <iostream>
#include <fstream>
#include <string>
#include <cmath>
#include <cstdio>
#include <algorithm>
#include <iomanip>
#include <vector>
#include <utility>
#include <numeric>
#include <stack>
#include <queue>
#include <map>
#include <unordered_map>
#define MOD 1000000007
#define int long long
using namespace std;
using P = pair<int, int>;
using ll = long long;
using prique = priority_queue<int>;
int n,m;
vector<bool> reached(50);
vector<int> g[50];
vector<P> h;
void dfs(int a,int p){
    reached[a]=true;
    for(int i=0;i<g[a].size();i++){
        if(h[p].first==a&&h[p].second==g[a][i])continue;
        if(h[p].second==a&&h[p].first==g[a][i])continue;
        else if(reached[g[a][i]]==false){
            dfs(g[a][i],p);
        }
    }
    return;
}
signed main(){
    cin>>n>>m;
    for(int i=0;i<m;i++){
        int a,b;
        cin>>a>>b;
        g[a-1].push_back(b-1);
        g[b-1].push_back(a-1);
        h.push_back(make_pair(a-1,b-1));
    }
    int ans=0;
    for(int i=0;i<m;i++){
        for(int j=0;j<n;j++){
            reached[j]=false;
        }
        dfs(0,i);
        bool c=true;
        for(int i=0;i<n;i++){
            if(reached[i]==false)c=false;
        }
        if(c==false){
            ans++;
        }
    }
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 256