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

const int MAXN = 100055;

int A[MAXN], B[MAXN];

int N;

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

	cin >> N;
	for(int i = 1; i <= N; i++) cin >> A[i];
	for(int i = 2, t; i <= N; i++) {
		B[i] = B[i-1] + abs(A[i] - A[i-1]);
		if(2 < i) {
			t = B[i-2] + abs(A[i] - A[i-2]);
			if(t < B[i]) B[i] = t;
		}
	}

	cout << B[N] << endl;
	return 0;
}

Measured memory_bytes: 1024
#include <iostream>
using namespace std;
typedef long long ll;
ll n,s[100000],L=2LL,H=3LL;
int main(void){
    cin>>n;
    for(int i=0;i<n;i++){
        cin>>s[i];
    }
    if(s[n-1]!=2){
        cout<<-1<<endl;
        return 0;
    }
    for(int i=n-2;i>=0;i--){
        //cout<<L<<" "<<H<<endl;
        L=(L-1)/s[i]+1;
        H=H/s[i];
        //cout<<L<<" "<<H<<endl;
        if(L>H){
            cout<<-1<<endl;
            return 0;
        }
        L*=s[i];
        H*=s[i];
        //cout<<H<<endl;
        H+=s[i]-1;
    }
    cout<<L<<" "<<H<<endl;
}


Measured memory_bytes: 1024
def calcs(x,y,ax,ay,bx,by) ((ax-x)*(by-y)-(bx-x)*(ay-y))/2.0 end
def inpf() a=gets.chomp.split(" ").map(&:to_f)end
def inps() a=gets.chomp.split(" ")end  
def copy(a) Marshal.load(Marshal.dump(a)) end
def kaizyo(n)(n < 2)? 1 : (2..n).inject(:*) end
def scount(a) b=na(a.max+1);a.each{|n|b[n]+=1};return b end
def na(n,d=0) Array.new(n,d)end
def na2(n,m,d=0) Array.new(n){Array.new(m,d)}end
def na3(n,m,l,d=0) Array.new(n){Array.new(m){Array.new(l,d)}}end
def bit(n) n.to_s(2).split("").map(&:to_i) end
def inp() a=gets.chomp.split(" ").map(&:to_i)end
class Hp
  def initialize(len)
    @main = na(len,[999999999,-1])
    @ind = 1
    @main[0] = [-99999999,-1]
    @size = len - 5
  end
  def push(n)
    p "wa" if(@ind > @size)
    @main[@ind] = n
    sind = @ind
    while(sind != 0)
      nind = sind/2
      @main[sind], @main[nind] = @main[nind], @main[sind] if(@main[sind][0] < @main[nind][0])
      sind /= 2
    end
    @ind += 1
  end
  def put()
    return @main
  end
  def pop()
    ans = @main[1]
    @main[1] = @main[@ind]
    @main[@ind] = [999999999,-1]
    sind = 1
    while(true)
      nind = sind*2
      break if(nind > @ind)
      l = @main[nind]
      nind += 1 
      if(nind > @ind)
        ind = nind-1
        if(@main[ind][0] < @main[sind][0])
          @main[sind], @main[ind] = @main[ind], @main[sind] 
        end
        break 
      end
      r = @main[nind]
      ind = (l[0] > r[0])? nind : nind-1
      if(@main[ind][0] < @main[sind][0])
        @main[sind], @main[ind] = @main[ind], @main[sind] 
      end
      sind = ind
    end
    @ind -= 1
    return ans
  end
  def res()
    @ind = 1
    @main.push([999999999,-1])
  end
end
n,m = inp
pas = na2(n+1,0)
rec = na2(n+1,n+1,999999999)

test = []
m.times do 
  a,b,c=inp
  pas[a].push([b,c])
  pas[b].push([a,c])
  test.push([a,b,c])
end
#p pas
used = na(n)
hp = Hp.new(1100)
hp.push([1,1])
(1..n).each do |s|
  hp.put
  hp.res
  rec[s][s] = 0
  ind = s
  used = na(n+1,0)
  while(ind > 0) do
    used[ind] = true;
    max = 999999
    nex = -1
    tab = pas[ind]
    tab.each do |a|
      hi = a[0]
      next if(used[hi] == true)
      kyori = rec[s][ind] + a[1]
      rec[s][hi] = kyori if rec[s][hi] > kyori
      hp.push([kyori,hi]) 
    end
    d = hp.pop[1]
    while(used[d] == true )
      d = hp.pop[1]
      break if(d == -1)
    end
    nex = d
    used[nex] = true;
    ind = nex
  #rererereerer[missmissniu] += [waawawawawwa[bugbugbubg]] if(nex < 0)
  end
end
#p rec
c = 0
test.each do|a|
  if(rec[a[0]][a[1]] != a[2])
    c +=1
  end
end
p c

Measured memory_bytes: 2812
def main():
    N = int(input())
    a = []
    for _ in range(N):
        a.append(list(map(int, input().split())))

    for x in range(N):
        a[x].sort(reverse = True)
        if a[x][0] ** 2 == a[x][1] ** 2 + a[x][2] ** 2:
            print("YES")
        else:
            print("NO")


if __name__ == "__main__":
    main()

Measured memory_bytes: 7916
import itertools
import copy

num_list = [chr for chr in input()]
TF_list = [True, False]

boundary_list = list(itertools.product(TF_list, repeat = len(num_list) - 1))

num_sum = 0

for boundary in boundary_list:
    # initialize
    num_list_copy = copy.copy(num_list)
    boundary = list(boundary)
    boundary.append(True)
    boundary_list.reverse
    temp = []
    
    while num_list_copy:
        temp.append(num_list_copy.pop(0))
        if boundary.pop(0):
            post_temp = int(''.join(temp))
            num_sum += post_temp
            temp = []
            
print(num_sum)

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

int main() {
  int A, B, C, D, E;
  int tem, res, temp;

  cin >> A >> B >> C >> D >> E;

  if(A > 0) {
    tem = B - A;
    res = tem *	E;
  }
  else {
    res	= A * -1 * C;
    temp = B * E;
    res = res + temp + D;
  }

  cout << res << endl;
  return 0;
}



Measured memory_bytes: 3104
#include<iostream>
#include<functional>
#include<utility>
#include<cmath>
#include<iomanip>
#include<algorithm>
#include<string>
#include<vector>

#define MOD 1000000007
using namespace std;

int n, m;
string s;

int main() {
	cin >> n >> m;
	if (n < m) { cout << 0 << endl;return 0; }
	cout << 10 << endl;
}

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

int main(){
    int N;
    double K;
    cin >> N >> K;
    /*
    vector<int> A(N);
    for(int i=0;i<N;i++){
        cin >> A[i];
    }
    auto iter = min_element(A.begin(),A.end());
    auto index = distance(A.begin(),iter);
    //cout << (index+1) / (K-1)  + ceil((N-index-1) / (K-1));
    */

    cout << ceil((N-1)/(K-1));

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll long long
#define rep(i, begin, end) for (__typeof(end) i = (begin) - ((begin) > (end)); i != (end) - ((begin) > (end)); i += 1 - 2 * ((begin) > (end))) // rep(i, 1, 5) --> {1,2,3,4} // rep(i, 5, 1) --> {4,3,2,1} // rep(it, end(v), begin(v)) --> *it

using namespace std;

int main()
{
    int n, m;
    cin >> n >> m;
    set<pair<int,int>> s;
    map<int, bool> mp;
    rep(i, 0, m)
    {
        int a, b;
        cin >> a >> b;
        s.insert({a,b});
    }
    for (auto x:s)
    {
        int a = x.first;
        int b = x.second;
        if (a == 1)
            mp[b] = true;
        if (b == n)
            if (mp[a] == true)
                return cout << "POSSIBLE", 0;
    }
    cout << "IMPOSSIBLE";    
    return 0;
}

Measured memory_bytes: 18944
#include<iostream>
#include<algorithm>
#include<string>
#include<vector>
#include<cmath>
#include<queue>
#define int long long
#define mod 1000000007
#define for0(i, n) for(int i = 0; i < (n); i++)
#define for1(i, n) for(int i = 1; i <= (n);i++)
#define mp make_pair
using namespace std;
int n, a, b, c, d; string s;
signed main() {
	cin >> n >> a >> b >> c >> d >> s;
	a--; b--; c--; d--;
	if (d < c) {
		//abdc
		bool b00l = 0; s += '#';
		for (int i = b - 1; i <= d - 1; i++) {
			if (s[i] == '.'&&s[i + 1] == '.'&&s[i + 2] == '.')b00l = 1;
		}
		if (!b00l) { cout << "No\n"; return 0; }
		int p = a;
		while (p != c)if (s[p + 1] == '.')p++; else if (s[p + 2] == '.')p += 2; else { cout << "No\n"; return 0; }
		cout << "Yes\n";
	}
	else {
		int p = b;
		while (p != d)if (s[p + 1] == '.')p++; else if (s[p + 2] == '.')p += 2; else { cout << "No\n"; return 0; }
		p = a;
		while (p != c)if (s[p + 1] == '.')p++; else if (s[p + 2] == '.')p += 2; else { cout << "No\n"; return 0; }
		cout << "Yes\n";
	}
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
#define rep3(i, s, n, a) for (int i = (s); i < (int)(n); i += a)
#define rep2(i, s, n) rep3(i, s, n, 1)
#define rep(i, n) rep2(i, 0, n)

using namespace std;
using ll = long long;
using ull = unsigned long long;
using P = pair<int, int>;

int main(){
    int h, w, n;
    cin >> h >> w >> n;
    if(h<w){
        cout << (n-1) / w + 1 << endl;
    }else{
        cout << (n - 1) / h + 1 << endl;
    }
    return 0;
}

Measured memory_bytes: 3636
#include<bits/stdc++.h> //Ithea Myse Valgulious
namespace chtholly{
typedef long long ll;
#define re0 register int
#define rec register char
#define rel register ll
#define gc getchar
#define pc putchar
#define p32 pc(' ')
#define pl puts("")
/*By Citrus*/
inline int read(){
  int x=0,f=1;char c=gc();
  for (;!isdigit(c);c=gc()) f^=c=='-';
  for (;isdigit(c);c=gc()) x=(x<<3)+(x<<1)+(c^'0');
  return f?x:-x;
  }
inline void read(rel &x){
  x=0;int f=1;char c=gc();
  for (;!isdigit(c);c=gc()) f^=c=='-';
  for (;isdigit(c);c=gc()) x=(x<<3)+(x<<1)+(c^'0');
  x=f?x:-x;
  }
template <typename mitsuha>
inline int write(mitsuha x){
  if (!x) return pc(48);
  if (x<0) x=-x,pc('-');
  re0 bit[20],i,p=0;
  for (;x;x/=10) bit[++p]=x%10;
  for (i=p;i;--i) pc(bit[i]+48);
  }
inline char fuhao(){
  rec c=gc();
  for (;isspace(c);c=gc());
  return c;
  }
}using namespace chtholly;
using namespace std;
ll n,m;

int judge(ll v){
ll a=n,b=m;
if (b>v*2) a+=(b-v*2)/2,b=v*2;
return a>=v&&b>=v*2; 
}

int main(){
read(n),read(m);
ll l=0,r=1e18;
for (;l<=r;){
  ll mid=l+r>>1;
  judge(mid)?l=mid+1:r=mid-1;
  }
write(l-1);
}

Measured memory_bytes: 256
/*
ID: y1197771
PROG: test
LANG: C++
*/
#include<bits/stdc++.h>
#define pb push_back
#define FOR(i, n) for (int i = 0; i < (int)n; ++i)
#define dbg(x) cout << #x << " at line " << __LINE__ << " is: " << x << endl
typedef long long ll;
using namespace std;
typedef pair<int, int> pii;
const int maxn = 1e5 + 10;
string a[] = {"dream", "dreamer", "erase", "eraser"};
int dp[maxn];
void solve() {
    string s;
    cin >> s;
    memset(dp, 0, sizeof dp);
    dp[0] = 1;
    for (int i = 1; i <= s.size(); i++) {
        for (int j = 0; j < 4; j++) {
            int sz = a[j].size();
            if(i - sz>= 0) {
                string t = s.substr(i - sz, sz);
                //cout << i << " " << t << endl;
                if(t == a[j] && dp[i - sz]) {
                    dp[i] = 1;
                    //cout << i << " " << t << endl;
                }
            }
        }
    }
    if(dp[s.size()])
        cout << "YES" << endl;
    else cout << "NO" << endl;
}
int main() {
   // freopen("test.in", "r", stdin);
    //freopen("test.out", "w", stdout);
    ios::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);
    //int _; _ = 3;
    //while(_--)
    solve();
    return 0;
}


Measured memory_bytes: 848
#include<iostream>
#include<stdio.h>
#include<cstring>
using namespace std;
char q[1000];
int main(){
	scanf("%s", q+1);
	int l = strlen(q + 1);
	bool f = 1;
	for (int i = 1; i <= l; i++){
		if (q[i] != q[l + 1 - i]){
			f = 0;
			break;
		}
	}
	for (int i = 1; i <= (l - 1) / 2; i++){
		if (q[i] != q[(l-1)/2 + 1 - i]){
			f = 0;
			break;
		}
	}
	for (int i = 0; i+(l+3)/2 <= l; i++){
		if (q[i+(l+3)/2] != q[l-i]){
			f = 0;
			break;
		}
	}
	if (f)
		puts("Yes");
	else
		puts("No");
	return 0;
}

Measured memory_bytes: 256
h1, h2 = map(int, input().split())
k1, k2 = map(int, input().split())
a, b, c, d = map(int, input().split())
h = h1*a + h2*b + h1//10*c + h2//20*d
k = k1*a + k2*b + k1//10*c + k2//20*d
if h > k:
    print('hiroshi')
elif h == k:
    print('even')
else:
    print('kenjiro')


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

using namespace std;

int main(){
    string T;
    while(cin >> T) {
        if(T == "-") {
            break;
        }
        int n,h;
        cin >> n;
        rep(i,n) {
            cin >> h;
            T = (T.substr(h, T.length() - h) + T.substr(0,h));
        }
        
        cout << T << endl;
    }
    
}


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

#define F first
#define S second
#define MP make_pair
#define PB emplace_back

using namespace std;

const int N = 1e5+100;

long long int dp[N];

vector<long long int> v[N];

bool viz[N];

void dfs(int x) {
    viz[x]=1;
    for(int u: v[x]) {
        if(!viz[u]) dfs(u);
        dp[x]=max(dp[x],dp[u]);
    }
    dp[x]++;
}

int main () {
    long long int n, m;
    cin >> n >> m;
    for(int i = 0 ; i < m ; i++ ) {
        long long int u1, u2;
        cin >> u1 >> u2;
        u1--;
        u2--;
        v[u1].PB(u2);
    }
    for(int i = 0 ; i < n ; i++ ) if(!viz[i]) dfs(i);
    cout << *max_element(dp,dp+n)-1;
}


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

using namespace std;

int high[10];

int main(){
	for (int i = 0; i < 10; i++){
		cin >> high[i];
		high[i] = -high[i];
	}

	sort(high, high + 10);

	for (int i = 0; i < 3; i++)	{
		cout << -high[i] << endl;
	}
}

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

using namespace std;

int cost[100005];
int dp[100005];

int main(){
    ios::sync_with_stdio(0); cin.tie();
     
    int N, a,k;
    cin >> N >> k;
    for(int i = 0 ;i < N+1 ; i++) dp[i] = 1000000002; //set value
    for(int i=0;i<N;i++){
        cin >> a;
        cost[i] = a;
    }
    dp[0] = 0;
    
    for(int i = 1 ; i < N ; i++){
        for(int j = 1; j < k+1 ; j++){
            
            if( i - j >= 0 ) dp[i] = min( dp[i], dp[i-j] + abs(cost[i] - cost[i-j])); 
            else{
                break;
            }
            
        }
    }
    cout << dp[N-1];
    
}


Measured memory_bytes: 1024
S=str(input())

cnt1=1
cnt2=0
a1=S[0]
t=0
for i in range(1,len(S)):
    if S[i]==a1:
        cnt1+=1
    elif t ==0:
        a2=S[i]
        t=1
        cnt2+=1
    elif a2==S[i]:
        cnt2+=1
    else:
        t=0
        break

if t==0:
    print("No")
else:
    print("Yes")
        

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

#define ll long long
// #define LOCAL

ll POW(int b) {
	ll ans = 1;
	if (b == 0) return ans;
	else if (b > 0) {
		for (int j = 1; j <= b; j++) ans = -(ans * 2);
		return ans;
	}
	else {
		return NULL;
	}
}

int main() {
	ll n; scanf("%lld", &n); vector<ll> V;

	if (n == 0) { printf("0\n"); return 0; }

	int i = 0; ll t = 0; 

	while (true) {
		if (i == 0) V.push_back(POW(0));
		else if (i == 1) V.push_back(POW(1));
		else V.push_back(V[i - 2] + POW(i));
		
		if (0 < n) { if (n <= V[i]) break; }
		else if (V[i] <= n) break;

		i++;
	}

#ifdef LOCAL
	for (auto it = V.begin(); it != V.end(); it++) {
		printf("%lld ", *it);
	}
	printf("\n");
#endif

	t += POW(i); i--; printf("1");

	while (true) {
		if (i < 2) break;

		if (i % 2 == 0) { // 正
			if (n <= t) {
				printf("0");
			}
			else { // t < n
				if (t + V[i - 2] < n) {
					printf("1"); t += POW(i);
				}
				else {
					printf("0");
				}
			}
		}
		else {
			if (t <= n) {
				printf("0");
			}
			else { // n < t
				if (n < t + V[i - 2]) {
					printf("1"); t += POW(i);
				}
				else {
					printf("0");
				}
			}
		}
		i--;
	}

	if (i == 1) {
		if (n < t) {
			printf("1"); t += POW(i);
		}
		else {
			printf("0");
		}
		i--;
	}

	if (i == 0) {
		if (t < n) {
			printf("1"); t += 1;
		}
		else {
			printf("0");
		}
	}

#ifdef LOCAL
	printf("\n%lld\n", t);
#endif

	return 0;
}


Measured memory_bytes: 256
#include <string>
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
typedef pair<int,P> P1;
typedef pair<P,P> P2;
#define pu push
#define pb push_back
#define mp make_pair
#define eps 1e-7
#define INF 1000000000
#define mod 1000000007
#define fi first
#define sc second
#define rep(i,x) for(int i=0;i<x;i++)
#define repn(i,x) for(int i=1;i<=x;i++)
#define SORT(x) sort(x.begin(),x.end())
#define ERASE(x) x.erase(unique(x.begin(),x.end()),x.end())
#define POSL(x,v) (lower_bound(x.begin(),x.end(),v)-x.begin())
#define POSU(x,v) (upper_bound(x.begin(),x.end(),v)-x.begin())
int n,h[100005];
ll dp[100005];
/*
bool compare_by_b(pair<int, int> a, pair<int, int> b) {
    if(a. != b.second){
        return a.second < b.second;
    }else{
        return a.first < b.first;
    }
}
*/


int main(){
	int x1,x2,y1,y2;
    std::cin >> x1 >> y1 >> x2 >> y2;
    printf("%d %d %d %d",x2-(y2-y1),y2+(x2-x1),x1-(y2-y1),y1+(x2-x1));
	return 0;
}

Measured memory_bytes: 256
h, w, k = map(int, input().split())
c = [[] for _ in range(h)]
numC, numR = [], []
for i in range(h):
    c[i] = list(input())

from itertools import permutations, product
from copy import deepcopy

res = 0

for u in product([0, 1], repeat=h): # よこ
    for v in product([0, 1], repeat=w): # たて
        tmp = deepcopy(c)
        for i in range(h):
            if u[i] == 0:
                for j in range(w):
                    if tmp[i][j] == '#':
                        tmp[i] = '.' * w
        for i in range(w):
            if v[i] == 0:
                for j in range(h):
                    if tmp[j][i] == '#':
                        tmp[j][i] = '.'
        # count
        cnt = 0
        for j in range(h):
            for i in range(w):
                if tmp[j][i] == '#':
                    cnt += 1
        if cnt == k:
            res += 1

print(res)

Measured memory_bytes: 73916
//fifer a tak luboin
#include <bits/stdc++.h>
// #include <ext/pb_ds/assoc_container.hpp>
// #include <ext/pb_ds/tree_policy.hpp>

typedef long long ll;

#define pb push_back
#define endl "\n"

// using namespace __gnu_pbds;
using namespace std;
// template <typename T> using ordered_set =  tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>; 

int main() {
    ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0); 
    // freopen("input.in.txt", "r", stdin);
    // freopen("output.txt", "w", stdout);
    vector <string> v = {"AC", "WA", "TLE", "RE"};
    int q;
    cin >> q;
    map <string, int> cnt;
    while (q--) {
        string t;
        cin >> t;
        cnt[t]++;
    }

    for (auto it: v) {
        cout << it << " x " << cnt[it] << endl;
    }
    return 0;  
}


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

int main(){
    string S;
    char cur='#';
    cin >> S;

    for(int i=0; i<S.length(); i++) {
        if(S[i] == cur) {
            cout << "Bad";
            return 0;
        } else {
            cur = S[i];
        }
    }
    cout << "Good";
    return 0;

}

Measured memory_bytes: 256
import java.util.*;
import java.io.*;

public class Main {
	public static void main(String[] args) throws IOException {
		//BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		Scanner sc = new Scanner(System.in);
		PrintWriter pw = new PrintWriter(System.out);
		
		int n = sc.nextInt();
		Integer[] tmep = new Integer[n];
		for(int i = 0; i < n; i++)
			tmep[i] = sc.nextInt();
		Arrays.sort(tmep);
		
		int[] array = new int[n];
		for(int i = 0; i < n; i++)
			array[i] = tmep[i];
		
		long count = 0;
		
		TreeMap<Integer, Integer> map = new TreeMap<>();
		for(int i = 0; i < n; i++)
			if(!map.containsKey(array[i]))
				map.put(array[i], i);
		
		for(int i = 0; i < n; i++) {
			for(int j = i + 1; j < n; j++) {
				
				int max = array[i] + array[j];
				int y = Arrays.binarySearch(array, max);
				
				if(y < 0)
					y = -(y + 1);
				
				if(y != array.length)
					y = map.get(array[y]) - 1;
				else
					y--;
				
				count += y - j;
			}
		}
		
		System.out.println(count);
	}
}

Measured memory_bytes: 40804
#!/usr/bin/env ruby

require 'pp'
attrs = Array.new
while line = $stdin.gets
  attrs << line.chomp.split
end

N = attrs[0][0].to_i
M = attrs[0][1].to_i

a = Array.new(N,-1)
x = Array.new(N).map{Array.new()}
M.times do |i|
  s = attrs[i+1][0].to_i - 1
  c = attrs[i+1][1].to_i
  x[s].push c
  if a[s] == -1 || a[s] > c then
    a[s-1] = c
  end
end

valid = true
res = Array.new()
x.each_with_index do |q, index|
  q.uniq!
  if q.length > 1 then
    valid = false
    break
  end
  if index == 0 then
    # 一桁の場合
    if N == 1 then
      if q.length == 0 then
        res.push 0
      else
        res.push q.first
      end
    else
      if q.length == 0 then
        res.push 1
      else
        if q.first == 0 then
          valid = false
          break
        else
          res.push q.first
        end
      end
    end
  else
    res.push(q.length == 0 ? 0 : q.first)
  end
end
puts valid ? res.join : -1

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

using namespace std;

#define ll long long

int cnt(int a[],int n,int len){
	int ans=0;
	for(int i=0;i<n;i++){
		// int low=1,high=1000;
		// for(int j=0;j<50;j++){
		// 	int mid = (low+high)/2;
		// 	float ha=a[i];
		// 	// cout<<ha/float(mid)<<" "<<mid<<" "<<high<<" "<<low<<endl;
		// 	if(ha/float(mid+1)<=len){
		// 		high=mid;
		// 	}
		// 	else
		// 	{
		// 		low=mid+1;
		// 	}
		// }
		int tempVal = (((a[i]-1)/len));
		// cout<<tempVal<<endl;
		ans+=tempVal;
	}
return ans;
}

int main() {
	int n,k;
	cin>>n>>k;
	int a[n];
	for(int i=0;i<n;i++){
		cin>>a[i];
	}
	int low=1,high=1e9 + 5;
	int ans=0;
	for(int i=0;i<50;i++){
		int mid = (high+low)/2;
		if(mid==0)
		continue;
		// cout<<mid<<endl;
		int value = cnt(a,n,mid); 
		if(value<=k){
			ans=mid;
			high=mid-1;
		}
		else{
			low=mid+1;	
		}
	}
	// while(1){
	// 	if(cnt(a,n,ans-1)==k){
	// 		ans--;
	// 	}
	// 	else
	// 	break;
	// }
	cout<<ans<<endl;
	return 0;
}



Measured memory_bytes: 4340
import sys
sys.setrecursionlimit(200000)
 
n = int(input())
 
h = [int(i) for i in input().split()]
 
d = {}
 
def dp(p):
  if p in d:
    return d[p]
  if p == n-1:
    return 0
  if p < n-2:
    m = min(dp(p+1)+abs(h[p]-h[p+1]), dp(p+2)+abs(h[p]-h[p+2]))
    d[p] = m
    return m
  if p == n-2:
    return dp(p+1)+abs(h[p]-h[p+1])

print(dp(0))


Measured memory_bytes: 103512
def golden_apple(N: int, D: int)->int:
    ans = N // (2*D+1)
    if N % (2*D+1):
        ans += 1
    return ans


if __name__ == "__main__":
    N, D = map(int, input().split())
    ans = golden_apple(N, D)
    print(ans)


Measured memory_bytes: 2940
s = int(input())
def f(n):
    if n % 2 == 0:
        return n // 2
    else:
        return 3 * n + 1
num = set({s})
cnt = 2
pre = s
while True:
    ai = f(pre)
    #print(ai)
    if ai in num:
        print(cnt)
        break
    else:
        num.add(ai)
        pre = ai
        cnt += 1

Measured memory_bytes: 3060
a,b,c,d=map(str,list(input()))
x,y,z=" "," "," "
cou=0
for i in range(1<<3):
    
    if i&1: x="+"
    else: x="-"
    if i&2: y="+"
    else: y="-"
    if i&4: z="+"
    else: z="-"
    
    if eval(a+x+b+y+c+z+d)==7:
        print(a+x+b+y+c+z+d+"=7")
        break
    cou+=1
if cou==8:
    print("No")

Measured memory_bytes: 3064
a = []
b = []
c = [0,0,0,0]
for i in range(3):
  ab = list(map(int,input().split()))
  a.append(ab[0])
  b.append(ab[1])
  a.append(ab[1])
  b.append(ab[0])
  c[ab[0]-1] += 1
  c[ab[1]-1] += 1
k = c.index(1)+1
for i in range(3):
  if k in a:
    j = a.index(k)
    k = b[j]
    a.pop(j)
    a.pop(j+-1*(j%2))
    b.pop(j)
    b.pop(j+-1*(j%2))
  else:
    print("NO")
    break
else:
  print("YES")

Measured memory_bytes: 3064
#include <iostream>
#include <cstdio>
#include <numeric>
using namespace std;

int main(void){
  int n,m;

  for(;;){
    scanf("%d %d",&n,&m);
    if(n==0 && m==0){return 0;}
    int h[n],t[m];
    
    for(int i=0;i<n;i++)
      scanf("%d",&h[i]);
    for(int i=0;i<m;i++)
      scanf("%d",&t[i]);
  
    int h_sum = accumulate(h,h+n,0);
    int m_sum = accumulate(t,t+m,0);

    int sa = h_sum - m_sum;

    //sa = 5 h_dasu - t_dasu = 5

    int ans1,ans2,sum=201;
    for(int i=0;i<n;i++){
      for(int j=0;j<m;j++){
	if(2*h[i]-2*t[j]==sa && h[i]+t[j]<sum){
	  ans1=h[i];ans2=t[j];
	  sum=ans1+ans2;
	}
      }
    }
    
    if(sum==201)
      printf("-1\n");
    else
      printf("%d %d\n",ans1,ans2);
  }
  return -1;
}

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

int main() {
	int n, a, b, c, d;
	cin >> n >> a >> b >> c >> d;
	long long st = 1ll*c*(n-1), ed = 1ll*d*(n-1);
	for(int i = 0; i < n; i++) {
		if(st-1ll*i*(c+d) <= b-a && ed-1ll*i*(c+d) >= b-a) {
			cout << "YES";
			return 0;
		}
	}
	cout << "NO";
}


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

namespace AOJ
{
    class AOJ203
    {
        public string solve(int x,int y)
        {
            string[][] cource;
            int[][] sum;
            cource = new string[y][];
            sum = new int[y][];
            for (int i = 0; i < y; i++)
            {
                sum[i] = new int[x];
                for (int j = 0; j < x; j++)
                {
                    sum[i][j] = 0;
                }
            }

            for (int i = 0; i < y; i++)
            {
                char[] delimi = new char[] { ' ' };
                string[] row = Console.ReadLine().Split(delimi);
                cource[i] = row;
            }

            for (int i = 0; i < x; i++)
            {
                if (cource[0][i].Equals("0"))
                {
                    sum[0][i] = 1;
                }
            }

            for (int i = 0; i < y-1; i++)
            {
                for (int j = 0; j < x; j++)
                {
                    switch (cource[i][j])
                    {
                        case "0":
                            if (!cource[i + 1][j].Equals("1"))
                            {
                                sum[i + 1][ j]+=sum[i][j];
                            }

                            if (j < x - 1)
                            {
                                if (cource[i + 1][j+1].Equals("0"))
                                {
                                    sum[i + 1][j+1] += sum[i][j];
                                }
                            }

                            if (j > 0)
                            {
                                if (cource[i + 1][j-1].Equals("0"))
                                {
                                    sum[i + 1][j-1] += sum[i][j];
                                }
                            }

                            break;
                        case "2":
                            if (i < y - 2 && !cource[i+2][j].Equals("1"))
                            {
                                sum[i + 2][j] += sum[i][ j];
                            }
                            break;
                    }
                }
            }

            int total = 0;
            for (int i = 0; i < x; i++)
            {
                total += sum[y - 1][i];

                //ジャンプ台分加算
                if(y>2 && cource[y - 2][i].Equals("2")){
                    total +=sum[y - 2][i];
                }
            }

            return total.ToString();
        }
    }
    class Program
    {
        
        static void Main(string[] args)
        {
            AOJ203 obj = new AOJ203();
            while (true)
            {
                char[] delimi = { ' ' };
                string[] str = Console.ReadLine().Split(delimi);
                int n = int.Parse(str[0]);
                int x = int.Parse(str[1]);
                if (n == 0 && x == 0) break;

                Console.WriteLine(obj.solve(n,x));
            }
        }
    }
}

Measured memory_bytes: 6012
using System;
using System.Collections.Generic;
using System.Linq;

class Program {
    static int ReadInt() { return int.Parse(Console.ReadLine()); }
    static int[] ReadInts() { return Console.ReadLine().Split().Select(int.Parse).ToArray(); }
    static string[] ReadStrings() { return Console.ReadLine().Split(); }

    class D {
        public char c;
        public int n;
    }

    static int Calc(string s) {

        var st = new Stack<D>();
        for (int i = 0; i < s.Length; i++) {
            if (st.Count == 0) {
                st.Push(new D { c = s[i], n = 1 });
                continue;
            }

            var d = st.Peek();
            if (d.c == s[i]) {
                d.n++;
            }
            else {
                if (d.c == 'S' && s[i] == 'T') {
                    d.n--;
                    if (d.n == 0) {
                        st.Pop();
                    }
                }
                else {
                    st.Push(new D { c = s[i], n = 1 });
                }
            }
        }

        int ans = 0;
        while  (st.Count > 0) {
            var d = st.Pop();
            ans += d.n;
        }
        return ans;
    }

    static void Main() {
        var s = Console.ReadLine();
        var ans = Calc(s);
        Console.WriteLine(ans);
    }
}

Measured memory_bytes: 3672
#include<stdio.h>

int main(){
  int i,a,b;
  int array[999];
  array[0]=1;
  for(i=1;i<999;i++){
    array[i]=array[i-1] + i+1;
  }

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

  i = b - a - 1;
  printf("%d\n",array[i-1]-a);
  return 0;
}

Measured memory_bytes: 128
import java.util.Scanner;


public class Main {
	Scanner sc = new Scanner(System.in);
	
	boolean leap(int a){
		boolean leap = false;
		if(a%4==0) leap = true;
		if(a%100==0) leap = false;
		if(a%400==0) leap = true;
		return leap;
	}
	
	void run(){
		boolean init = true;
		while(true){
			int a = sc.nextInt();
			int b = sc.nextInt();
			int cnt = 0;
			if(a == 0 && b == 0){
				break;
			}
			
			if(init){
				init = false;
			}else{
				System.out.println();
			}
			
			for(;a<=b;a++){
				if(leap(a)){
					System.out.println(a);
					cnt++;
				}
			}
			
			if(cnt==0)
				System.out.println("NA");
		}
	}
	
	public static void main(String[] args) {
		new Main().run();
	}
}

Measured memory_bytes: 20616
#include<iostream>
#include<algorithm>
#include<string>
#include<vector>
#include<math.h>
#include<map>
using namespace std;
int main() {
    int n;
    cin >> n;
    if(n % 10 ==2 || n % 10 == 4 || n % 10 == 5 || n % 10 == 7 || n % 10 == 9){
        cout << "hon" << endl;
    }else if(n % 10 == 0 ||n % 10 == 1 ||n % 10 == 6 ||n % 10 == 8){
        cout << "pon" << endl;
    }else{
        cout << "bon" << endl;
    }
}

Measured memory_bytes: 3620
#include<iostream>
#include<vector>
#include<algorithm>

typedef long long ll;

using namespace std;

int main(){
ll N,H; cin >> N >> H;
  vector<pair<ll,ll>> C(N);
 ll thrower = 0; ll a_max = 0; ll iter = 0;
  for(ll i = 0; i < N; i++){
    cin >> C[i].first >> C[i].second; 
    if( a_max < C[i].first){ a_max = C[i].first; iter = i;}  }
  vector<pair<ll,ll>> vec;
  for(ll i = 0; i < N; i++){
    if( a_max > C[i].second){ continue;} //捨てる
    else{ vec.push_back(make_pair(C[i].first,C[i].second));
                         thrower += C[i].second;}}
     //残った第二成分はすべてa_max以上
   if( thrower >= H){ //投げるだけで倒せる場合
     vector<pair<ll,ll>> vec2((ll)vec.size());
     for(ll i = 0; i < (ll) vec.size(); i++){
       vec2[i].first = vec[i].second; vec2[i].second = vec[i].first;}
     sort(vec2.begin(),vec2.end()); reverse(vec2.begin(),vec2.end());
     ll sum = 0; ll j = 0;
     while( sum + vec2[j].first < H){
       sum += vec2[j].first; j++;}
     cout << j + 1 << endl; return 0;}
    else{
      ll count = (ll) vec.size(); H -= thrower;
      sort(vec.begin(),vec.end()); reverse(vec.begin(),vec.end());
      ll knife = vec[0].first;
      count += ( H + knife - 1) / knife;
      cout << count << endl; return 0;}
                        }

Measured memory_bytes: 5104
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include<cmath>
#define rep(i,n) for(int i = 0;i < (n);i++)
using namespace std;

int main(){
    int H,N;
    cin >> H >> N;
    
    int A[100001];
    int sum = 0;
    rep(i,N){
        cin >> A[i];
        sum += A[i];
    }
    
    if(sum >= H){
        cout << "Yes" << endl;
    }
    else{
        cout << "No" << endl;
    }
}


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

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

typedef long long ll;

const int INF = 1 << 30;
const ll LLINF = 1LL << 62;

int mod = 1000000007;

struct UnionFind {
    vector<int> par;
    
    UnionFind(int n) : par(n, -1) { }
    void init(int n) { par.assign(n, -1); }
    
    int root(int x) {
        if (par[x] < 0) return x;
        else return par[x] = root(par[x]);
    }
    
    bool issame(int x, int y) {
        return root(x) == root(y);
    }
    
    bool merge(int x, int y) {
        x = root(x); y = root(y);
        if (x == y) return false;
        if (par[x] > par[y]) swap(x, y); // merge technique
        par[x] += par[y];
        par[y] = x;
        return true;
    }
    
    int size(int x) {
        return -par[root(x)];
    }
};

vector<int> nodes[100000];
vector<int> block[100000];

int main(void){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int N, M, K; cin >> N >> M >> K;
    UnionFind uf(N);
    rep(i, M){
        int a, b; cin >> a >> b;
        a--; b--;
        nodes[a].push_back(b);
        nodes[b].push_back(a);
        uf.merge(a, b);
    }
    rep(i, K){
        int a, b; cin >> a >> b;
        a--; b--;
        block[a].push_back(b);
        block[b].push_back(a);
    }
    int cnt[N+1] = {};
    rep(i, N){
        rep(j, block[i].size()){
            if(uf.issame(i, block[i][j])) cnt[i]++;
        }
    }

    rep(i, N){
        cout << uf.size(i) - 1 - nodes[i].size() - cnt[i] << " ";
    }
    cout << endl;

    return 0;
}

Measured memory_bytes: 12664
#include <bits/stdc++.h>
#define SORT(a) sort(a.begin(), a.end())
#define RSORT(a) sort(a.rbegin(), a.rend())
#define REP(i, n) for (long long i = 0; i < n; i++)
#define RREP(i, n) for (long long i = n - 1; 0 <= i; i--)
#define FOR(i, start, end) for (long long i = start; i < end; i++)
#define RFOR(i, start, end) for (long long i = start - 1; 0 <= i; i--)
#define ALL(a) a.begin(), a.end()
#define MOD(a) a %= 1'000'000'007
using ll = long long;
using namespace std;
const int INF32       = 1'050'000'000;
const long long INF64 = 4'000'000'000'000'000'000;
const int MOD7        = 1'000'000'007;
const int MOD9        = 1'000'000'009;
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;
}
void print() { std::cout << '\n'; }
template <class H, class... T> void print(H &&head, T &&... args) {
    std::cout << head;
    sizeof...(args) == 0 ? std::cout << "" : std::cout << ' ';
    print(std::forward<T>(args)...);
}
template <class T> void print(std::vector<T> &v) {
    for (int i = 0; i < v.size(); i++) {
        std::cout << v[i];
        i == v.size() - 1 ? std::cout << '\n' : std::cout << ' ';
    }
}
template <class T> void print(std::vector<std::vector<T>> &v) {
    for (int i = 0; i < v.size(); i++) {
        for (int j = 0; j < v[i].size(); j++) {
            std::cout << v[i][j];
            j == v[i].size() - 1 ? std::cout << '\n' : std::cout << ' ';
        }
    }
}

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

    int a, b;
    cin >> a >> b;
    print(max({a + b, a - b, a * b}));

    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string.h>
using namespace std;
int main() {
  	int a,b,c;
    scanf("%d %d %d",&a,&b,&c);
    if(a==b && a==c)		
      printf("No");
    else if (a == b |b == c|c == a)
      printf("Yes"); 
    else 
      printf("No");
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <set>
#include <queue>
#include <stack>
#include <map>
#include <algorithm>
#include <math.h>
#include <cassert>
#define rep(i,n) for(int i = 0; i < n; ++i )
using namespace std;
using ll = long long;
using P = pair<int,int>;
// auto mod int
const int mod = 1000000007;
struct mint {
  ll x; // typedef long long ll;
  mint(ll x=0):x((x%mod+mod)%mod){}
  mint operator-() const { return mint(-x);}
  mint& operator+=(const mint a) {if ((x += a.x) >= mod) x -= mod; return *this;}
  mint& operator-=(const mint a) {if ((x += mod-a.x) >= mod) x -= mod; return *this;}
  mint& operator*=(const mint a) { (x *= a.x) %= mod; return *this;}
  mint operator+(const mint a) const { return mint(*this) += a;}
  mint operator-(const mint a) const { return mint(*this) -= a;}
  mint operator*(const mint a) const { return mint(*this) *= a;}
  mint pow(ll t) const {
    if (!t) return 1;
    mint a = pow(t>>1);
    a *= a;
    if (t&1) a *= *this;
    return a;
  }
  // for prime mod
  mint inv() const { return pow(mod-2);}
  mint& operator/=(const mint a) { return *this *= a.inv();}
  mint operator/(const mint a) const { return mint(*this) /= a;}
};
istream& operator>>(istream& is, const mint& a) { return is >> a.x;}
ostream& operator<<(ostream& os, const mint& a) { return os << a.x;}

int main() {
  int n;
  cin >> n;
  string s[2];
  cin >> s[0] >> s[1];

  mint ans;
  bool p;
  rep(i,n){
    bool x = s[0][i]==s[1][i];
    if(i==0){
      ans = x ? 3 : 6;
    }else{
      if(x&&p) ans *= 2;
      if(!x&&p) ans *= 2;
      if(x&&!p) ans *= 1;
      if(!x&&!p) ans *= 3;
    }
    p = x;
    if(!x) ++i;
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
const int N = 605;
vector<int> dx , dy;
int n , d1 , d2;

int d[N][N] , w[N][N];
vector<pair<int,int>> p[3];
vector<pair<int , int>> A , B;

void dfs(int x , int y , int ww) {
    if (x < 0 || x >= n + n || y < 0 || y >= n + n) return;
    if (!w[x][y]) return;
    if (d[x][y]) {
        assert(d[x][y] == ww);
        return;
    }
    p[ww].emplace_back(x , y); d[x][y] = ww;
    for (int k = 0 ; k < dx.size() ; ++ k) {
        dfs(x + dx[k] , y + dy[k] , 3 - ww);
    }
}

int main() {
    cin >> n >> d1 >> d2;
    for (int i = -2 * n ; i <= 2 * n ; ++ i) {
        for (int j = -2 * n ; j <= 2 * n ; ++ j) {
            if (i * i + j * j == d1) {
                dx.emplace_back(i);
                dy.emplace_back(j);
            }
        }
    }
    memset(w , 1 , sizeof(w));
    for (int i = 0 ; i < 2 * n ; ++ i) {
        for (int j = 0 ; j < 2 * n ; ++ j) {
            if (!d[i][j]) {
                p[1].clear();
                p[2].clear();
                dfs(i , j , 1);
                if (p[1].size() > p[2].size()) {
                    swap(p[1] , p[2]);
                }
                while (!p[2].empty()) {
                    A.push_back(p[2].back());
                    p[2].pop_back();
                }
            }
        }
    }
    dx.clear();
    dy.clear();
    memset(w , 0 , sizeof(w));
    for (auto &it : A) w[it.first][it.second] = 1;
    for (int i = -2 * n ; i <= 2 * n ; ++ i) {
        for (int j = -2 * n ; j <= 2 * n ; ++ j) {
            if (i * i + j * j == d2) {
                dx.emplace_back(i);
                dy.emplace_back(j);
            }
        }
    }
    memset(d , 0 , sizeof(d));
    for (auto &it : A) {
        int i = it.first, j = it.second;
        if (!d[i][j]) {
            p[1].clear();
            p[2].clear();
            dfs(i , j , 1);
            if (p[1].size() > p[2].size()) {
                swap(p[1] , p[2]);
            }
            while (!p[2].empty()) {
                B.push_back(p[2].back());
                p[2].pop_back();
            }
        }
    }
    for (int i = 0 ; i < n * n ; ++ i) {
        printf("%d %d\n" , B[i].first , B[i].second);
    }

}


Measured memory_bytes: 27236
#include <iostream>
#include <cstdio>
#include <cmath>
#include <cstring>
using namespace std;

#define M 1046527

long long T[M];
//???????????\??¢??°
int h1(long long key) { return key % M; }

int h2(long long key) { return 1 + (key % (M - 1)); }

int h(long long key, int i) { return ((h1(key)) + i*h2(key)) % M; }

void insert(long long key)
{
	int i = 0;
	while (1) {
		int j = h(key, i);
		if (!T[j]) {
			T[j] = key;
			return;
		}
		else if (T[j] == key) return;
		else i++;
	}
}

bool find(long long key)
{
	int i = 0;
	while (1) {
		int j = h(key, i);
		if (T[j] == key) return 1;
		else if (!T[j]) return 0;
		else i++;
	}
}

long long getKey(char *p)
{
	long long key = 0;
	for (int i = (strlen(p) - 1); i >= 0; i--) {
		int x = p[i] % 9;
		key += x * pow(10, i);
	}
	return key;
}

int main()
{
	int n;
	char order[10], word[15];
	scanf("%d", &n);

	for (int i = 0; i < n; i++) {
		scanf("%s %s", order, word);
		if (order[0] == 'i') insert(getKey(word));
		else if (find(getKey(word))) printf("yes\n");
		else printf("no\n");
	}
	return 0;
}

Measured memory_bytes: 9396
from collections import deque
import sys
sys.setrecursionlimit(10 ** 7)
readline = sys.stdin.readline


def main():
    a = input()
    d = deque(a)
    n = int(input())
    flagr = 1
    for i in range(n):
        j = list(readline().split())
        if len(j) == 3 and j[1] == "1" and flagr == 1:
            d.appendleft(j[2])
        elif len(j) == 3 and j[1] == "2" and flagr == 1:
            d.append(j[2])
        elif len(j) == 3 and j[1] == "2" and flagr == -1:
            d.appendleft(j[2])
        elif len(j) == 3 and j[1] == "1" and flagr == -1:
            d.append(j[2])
        else:
            flagr *= -1
    if flagr == -1:
        d.reverse()
    ans = ""
    for j in d:
        ans = ans + j
    print(ans)


if __name__ == '__main__':
    main()


Measured memory_bytes: 7020
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N=sc.nextInt();
		int R=sc.nextInt();
		if (N<=9)
		System.out.println(R+(100*(10-N)));
		else System.out.println(R);
		
	}

}


Measured memory_bytes: 22100
#include<bits/stdc++.h>
#define pb push_back
#define mp make_pair
#define forn(i,a,b) for(int i =a;i<b;i++)
#define fi first
#define se second
#define fast ios_base::sync_with_stdio(false);
using namespace std;

typedef long long int ll;
typedef vector<ll> vi;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
const int mxn = 1e5;
// int cnt1[mxn+2],cnt2[mxn+2];

void solve(){
	int n;
	cin >> n;
	string s;
	cin >> s;
	int base = 1;
	while(base<n){
		base<<=1;
	}
	int t[26][2*base];
	memset(t,0,sizeof(t));

	for(int i =0;i<n;i++){
		char c = s[i];
		t[c-'a'][i+base]++;
		// for(int j = (i+base)/2;j>0;j>>=1){
		// 	t[c-'a'][j] = t[c-'a'][j<<1] + t[c-'a'][j<<1|1];
		// }
	}
	// for(int i =0;i<26;i++){
	// 	for(int j =base;j<n+base;j++){
	// 		cout << t[i][j]<< " " << i << " " << j  << endl;
	// 	}
	// }
	for(int j = 0;j<26;j++){
		for(int i =base-1;i>0;--i){
			t[j][i]  = t[j][i<<1]+ t[j][i<<1|1];
		}
	}
	// for(int i =0;i<2;i++){
	// 	cout << t[i][1] << endl;
	// }
	int q;
	cin >> q;
	while(q--){
		int type;
		cin >> type;
		if(type==1){
			int idx;char c;
			cin >> idx >> c;
			--idx;
			t[s[idx]-'a'][idx+base]--;
			t[c-'a'][idx+base]++;
			for(int j = (idx+base)/2;j>0;j>>=1){
				t[s[idx]-'a'][j] = t[s[idx]-'a'][j<<1] + t[s[idx]-'a'][j<<1|1];
				t[c-'a'][j] =t[c-'a'][j<<1] + t[c-'a'][j<<1|1];
			}
			s[idx] = c;
			// cout << s << endl;
		}
		else{
			int l; int r;
			cin >> l >> r;
			int cpyl,cpyr;
			cpyl = l; cpyr = r;
			cpyl--;
			int ans =0;
			--l;
			for(int i =0;i<26;i++){
				int is_there = 0;
				for(l=cpyl+base,r=cpyr+base;l<r;l>>=1, r>>=1){
					if(l&1) is_there+=t[i][l++];
					if(r&1) is_there+=t[i][--r];
				}
				// cout << i << " " << is_there << endl;
				if(is_there>0)
					ans++;
			}
			cout << ans << endl;

		}
	}
}

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

	// int t;cin >> t;while(t--)
		solve();
}


Measured memory_bytes: 107420
private class UnionFind(n: Int) {

    private val par = IntArray(n) { -1 }

    fun find(x: Int): Int {
        if (par[x] < 0) {
            return x
        }
        par[x] = find(par[x])
        return par[x]
    }

    fun unite(x: Int, y: Int) {
        val x1 = find(x)
        val y1 = find(y)
        if (x1 == y1) return

        val (x2, y2) = if (par[x1] > par[y1]) {
            Pair(y1, x1)
        } else {
            Pair(x1, y1)
        }

        par[x2] += par[y2]
        par[y2] = x2
    }

    fun same(x: Int, y: Int): Boolean {
        return find(x) == find(y)
    }

    fun size(x: Int): Int {
        return -par[find(x)]
    }

}

fun main(args: Array<String>) {
    val (n, m) = readLine()!!.split(' ').map { it.toInt() }
    val cs = (0 until m).map {
        val (x, y, z) = readLine()!!.split(' ').map { it.toInt() }
        Triple(x, y, z)
    }

    val uf = UnionFind(n + 1)

    for (i in cs.indices) {
        uf.unite(cs[i].first, cs[i].second)
    }

    val set = mutableSetOf<Int>()

    for (i in 1..n) {
        set.add(uf.find(i))
    }

    println(set.size)
}


Measured memory_bytes: 78992
#if !defined(__clang__) && defined(__GNUC__)
#include <bits/stdc++.h>
#else
#include <cstdlib>
#include <climits>
#include <iostream>
#include <cstdint>
#include <vector>
#include <string>
#include <complex>
#include <bitset>
#include <queue>
#include <deque>
#include <stack>
#include <utility>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <regex>
#endif //  !defined(__clang__) && defined(__GNUG__)
#include <boost/lexical_cast.hpp>
#include <boost/algorithm/string.hpp>
#include <boost/multi_array.hpp>
#include <boost/optional.hpp>

using namespace std;

int main()
{
    int64_t N, X;
    std::cin >> N >> X;

    std::vector<int64_t> A;
    for (int64_t i = 0; i < N; ++i) {
        int64_t t;
        std::cin >> t;
        A.push_back(t);
    }

    int64_t result = INT64_MAX;
    std::vector<int64_t> costs(N, INT64_MAX);

    for (int64_t rot = 0; rot < N; ++rot) {
        for (int64_t i = 0; i < N; ++i) {
            int64_t idx;
            if (i - rot < 0) {
                idx = N - (rot - i);
            }
            else {
                idx = i - rot;
            }
            costs[i] = std::min(costs[i], A[idx]);
        }
        int64_t t = std::accumulate(costs.begin(), costs.end(), 0LL) + X * rot;

        result = std::min(result, t);
    }
    std::cout << result << std::endl;

    return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
	Scanner scanner = new Scanner(System.in);
	long a  = scanner.nextInt();
	long b  = scanner.nextLong();
	long n  = scanner.nextLong();
	if (n>=b) {
		n=b-1;
		System.out.println(a*n/b-a*(n/b));
	}
	else {
		System.out.println(a*n/b-a*(n/b));
	}
	scanner.close();}}

Measured memory_bytes: 35660
a, b, c = map(int, input().split())
 
if a % 2 != 0 or b % 2 != 0 or c % 2 != 0:
    print(0)    
    exit() 
    
if a == b == c:
    print(-1)
    exit()
    
cnt = 0
while (a % 2 == 0 and b % 2 == 0 and c % 2 == 0): 
    a, b, c = (b+c)//2, (a+c)//2, (a+b)//2
    cnt += 1
 
print(cnt)


Measured memory_bytes: 9096
#include<iostream>
#include<vector>
#define MOD 1000000007

std::vector<int>G[100005];
long long dp[100005][2];
int parent[100005];

void dfs(int source, int previous)
{
    dp[source][0] = dp[source][1] = 1;
    for(unsigned int i = 0; i < G[source].size(); i++){
        if(G[source][i] != previous){
            dfs(G[source][i], source);
            dp[source][0] = (dp[source][0] * (dp[G[source][i]][0] + dp[G[source][i]][1]))%MOD;
            dp[source][1]=(dp[source][1] * dp[G[source][i]][0])%MOD;
        }
    }
}


int main(){
    int n;
    std::cin >> n; 
    for(int i = 0; i < n-1; i++){
        int x, y;
        std::cin >> x >> y;

        G[x].push_back(y);
        G[y].push_back(x);
    }

    dfs(1, 0);
    std::cout << (dp[1][0]+dp[1][1])%MOD;
    return 0;
}

Measured memory_bytes: 14208
#include<stdio.h>
#define NUM 13
   
int main(){
 int num[NUM*4-1],ncmp,n,i,j;
 char pcmp;
 for(i=0; i<NUM; i++){
  num[NUM*0+i] = i+1;
  num[NUM*1+i] = i+1;
  num[NUM*2+i] = i+1;
  num[NUM*3+i] = i+1;
 }
 scanf("%d", &n);
 for(i=0; i<n; i++){
  scanf(" %c",&pcmp);
  scanf("%d", &ncmp);
  for(j=0; j<NUM; j++){
   switch(pcmp){
    case 'S': if(ncmp==num[NUM*0+j]){num[NUM*0+j] = -1;} break;     
    case 'H': if(ncmp==num[NUM*1+j]){num[NUM*1+j] = -1;} break;
    case 'C': if(ncmp==num[NUM*2+j]){num[NUM*2+j] = -1;} break;
    case 'D': if(ncmp==num[NUM*3+j]){num[NUM*3+j] = -1;} break;
    defult:break;
   }
  }
 }
 for(i=0; i<NUM*4; i++){
  if(num[i]!=-1){
   if(i<NUM){printf("S %d\n", num[i]);}
   else if(NUM*1<=i&&i<NUM*2){printf("H %d\n", num[i]);}
   else if(NUM*2<=i&&i<NUM*3){printf("C %d\n", num[i]);}
   else if(NUM*3<=i&&i<NUM*4){printf("D %d\n", num[i]);}
  }
 }
 return 0;
}

Measured memory_bytes: 596
package main

import "fmt"

func max(a ...int) int {
	m := a[0]
	for i, v := range a {
		if i == 0 {
			continue
		}
		if m < v {
			m = v
		}
	}
	return m
}
func main() {
	// Code for B - K Cakes
	var K, T int
	fmt.Scan(&K, &T)

	a := make([]int, T)
	var maxNum int
	var sum int
	for i := 0; i < T; i++ {
		fmt.Scan(&a[i])
		maxNum = max(maxNum, a[i])
		sum += a[i]
	}

	ans := max(0, maxNum-(sum-maxNum)-1)
	fmt.Println(ans)
}


Measured memory_bytes: 1768
S = input()
length = len(S)

S_odd = []
S_even = []

for i in range(0, length, 2):
    S_odd.append(S[i])

for i in range(1, length, 2):
    S_even.append(S[i])


if ("L" in S_odd) or ("R" in S_even):
    print("No")
else:
    print("Yes")


Measured memory_bytes: 3060