akhauriyash/Code-Regression huggingface dataset:
#pragma region _head

#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<cmath>
#include<map>
#include<set>
#include<iomanip>
#include<queue>
#include<stack>
#include<numeric>
#include<utility>
#include<regex>

#pragma region _define

#define f(i,a,b) for(int i=a;i<b;i++)
#define f_vI(v,n) f(i,0,n)cin>>v[i]
#define f_v2I(v1,v2,n) f(i,0,n)cin>>v1[i]>>v2[i]
#define f_v3I(v1,v2,v3,n) f(i,0,n)cin>>v1[i]>>v2[i]>>v3[i]
#define f_vO(v,n) f(i,0,n)cout<<v[i]<<endl
#define all(a) a.begin(),a.end()
#define size(s) s.size()
#define check() cout<<"! ! !"
#define endl "\n"
#define _y() cout<<"Yes"<<endl
#define _Y() cout<<"YES"<<endl
#define _n() cout<<"No"<<endl
#define _N() cout<<"NO"<<endl

#pragma endregion

#pragma region _using

using namespace std;

using LL = long long;
using st = string;
using vi = vector<LL>;
using vvi = vector<vi>;
using vvvi = vector<vvi>;
using vc = vector<char>;
using vs = vector<st>;
using vb = vector<bool>;
using vvb = vector<vb>;
using vvvb = vector<vvb>;
using si = stack<LL>;
using ss = stack<st>;
using pi = pair<LL, LL>;
using v_pi = vector<pi>;

#pragma endregion

#pragma region _graph

#define node 50  //グラフの最大位数　適宜変更
//bool graph[node][node]; bool visited[node] = { false };
#define link(a,b,m) f(i,0,m){cin>>a[i]>>b[i]; a[i]--; b[i]--; graph[a[i]][b[i]]=graph[b[i]][a[i]]=true;}

#pragma endregion

LL gcd(LL a, LL b) {
	LL r;
	while ((r = a % b) != 0) {
		a = b;
		b = r;
	}
	return b;
}
LL lcm(LL a, LL b) {
	return (a / gcd(a, b) * b);
}

//階乗計算
LL factorial(LL n) {
	LL a = 1, ret = 1;
	while (a < n) {
		a++;
		ret *= a;
		//ret %= 1000000007;
	}
	return ret;
}

#pragma endregion 

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

	int n, m;
	cin >> n >> m;
	int k;
	map<LL, LL>M;
	LL ans = 0;
	for (int i = 0; i < n; i++) {
		cin >> k;
		vi a(k);
		for (int j = 0; j < k; j++) {
			cin >> a[j];
			M[a[j]]++;
		}
		if (i == n - 1) {
			f(j, 0, k) {
				if (M[a[j]] == n) {
					ans++;
				}
			}
		}
	}
	cout << ans;
	return 0;
}

Measured memory_bytes: 256
def get_i() #空白区切の入力を数値(整数)の配列で返す
  return gets.chomp.split(" ").map(&:to_i)
end
def get_f() #空白区切の入力を数値(実数)の配列で返す
  return gets.chomp.split(" ").map(&:to_f)
end
def get() #空白区切の入力を文字列の配列で返す
  return gets.chomp.split(" ")
end
def get_nsp() #入力されたものを一文字ずつに区切った文字列の配列で返す
  return gets.chomp.split("")
end
def yn_judge(bool,y="Yes",n="No") #boolに真偽を投げることで、trueならy、falseならnの値を出力する
  return bool ? y : n 
end
def array(size1,init=nil,size2=-1) #size2に二次元配列時の最初の要素数、size1に次の配列の大きさ、initに初期値を投げることでその配列を返す
  if size2==-1
    return Array.new(size1){init}
  else
    return Array.new(size2){Array.new(size1){init}}
  end
end

x=gets.to_i
if x<=6
    puts 1
elsif (x%11).zero? or ((x-5)%11).zero? or ((x-6)%11).zero?
    puts x*2/11
else
    puts x*2/11+1
end

Measured memory_bytes: 1788
#include <iostream>

using namespace std;

int main() {
    int a, b;
    cin >> a >> b;
    int n = 0;
    for (int i = a; i <= b; ++i) {
        if ((((i / 10000) % 10) == (i % 10)) && (((i / 1000) % 10) == ((i / 10) % 10))) ++n;
    }
    cout << n << endl;
    return EXIT_SUCCESS;
}

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

int main(){
	int a,b ;
	cin >> a >> b ;
	for(int i=1;i<=1000000;i++){
		if(i*8/100==a&&i*10/100==b){
			cout << i << endl ;
			return 0 ;
		}
	}
	cout << -1 << endl ;
}


Measured memory_bytes: 256
#include <cstdio>
#include <cmath>
#include <cstring>
#include <ctime>
#include <iostream>
#include <algorithm>
#include <set>
#include <map>
#include <vector>
#include <sstream>
#include <typeinfo>
#include <fstream>
#include <limits>
 
using namespace std;
 
 
 
int main() {
    cin.tie(nullptr); ios::sync_with_stdio(false);
 
    int n , k;
    cin >> n >> k;
 
    vector<long long> a(n+1, 0);
    for(int i = 0; i < n; ++i){
        cin >> a[i];
    }
 
    // {
    //     long long sum = 0;
    //     bool isOk = false;
    //     for(int i = 0; i < n; ++i){
    //         sum += a[i];
    //         if(k<=sum) {
    //             isOk = true;
    //             break;
    //         }
    //     }
 
    //     if(!isOk) {
    //         // cout << n << endl;
    //         // return 0;
    //     }
    // }
 
 
    sort(a.rbegin(), a.rend());
    long long temp = 0; // sum
    long long first = 0;
    long long lastAns = -1;
    long long lastAnsNum = -1;
    for(int i = 0; i < n; ++i){
        // cout << a[i] << " ";
        temp += a[i];
        if(k<=temp) {
            // cout << "!" << endl;
            lastAns = i;
            if(lastAnsNum == -1) {
                lastAnsNum = min(a[i], k - (temp - a[i])); // a[i];
            } else {

                lastAnsNum = min(lastAnsNum, min(a[i], k - (temp - a[i]))); // a[i];
            }
            // cout << temp << endl;
            // cout << lastAnsNum << endl;
            // cout << k << " " << temp - a[i] << " " << k - (temp - a[i]) << endl;
            temp -= a[first];
            first += 1;
        }
        // cout << "temp" << temp << endl;
        // cout << "lastasn" << lastAns << endl;
        // cout << "----------------------------" << endl;
    }
 
    if(lastAnsNum == -1) {
        cout << n << endl;
        return 0;
    }
    long long ans = 0;
    for(int i = 0; i < n; ++i){
        // cout << lastAnsNum << " " << a[i] << endl;
        // cout << (a[i] < lastAnsNum) << endl;
        if (a[i] < lastAnsNum) {
        // cout << (a[i] < lastAnsNum) << endl;
            ans++;
        }
    }
    cout << ans << endl;
    return 0;
}


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

int main() {
  int n;
  cin >> n;
  
  //f(n)の個数を調べる
  for(int i = 1; i <= n; i++) {
    int count = 0;
    //x, y, z全探索してnと合致しているか調べる
    for(int j = 1; j <= 105; j++) {
      for(int k = 1; k <= 105; k++) {
        for(int l = 1; l <= 105; l++) {
	        int a = j*j + k*k + l*l + j*k + k*l + l*j;
    	    if(a == i) {
              //cout << a << n << j << k << l << endl;
              count++;
            }
          	else if (a > i) break;
        }
      }
    }
  cout << count << endl;
  }

}

Measured memory_bytes: 3576
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define ll long long
#define ld long double
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
using P=pair<long long,long long>;
#define rep(i,n) for(long long i=0; i<(long long)n; i++)
#define req(i,n) for(long long i=n-1; i>=0; i--)
#define range(i,a,b) for(long long i=a; i<b; i++)
#define all(x) (x).begin(), (x).end()
#define sz(x) ((long long)(x).size())
#define COUT(x) cout << x << endl
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define onBoard(y,x) (y>=0 && y<h && x>=0 && x<w)
#define pri_que priority_queue
#define vint vector<int>
#define vvint vector<vector<int>>
#define vi vector<int>
#define vvi vector<vector<int>>
#define vs vector<string>
#define vvc vector<vector<char>>
#define vc vector<char>
#define vp vector<pair<int,int>>
#define vb vector<bool>
#define vvb vector<vector<bool>>
#define show(x) cout<<#x<<"="<<x<<endl;
#define SUM(x) accumulate(x.begin(),x.end(),0)
#define MAX(x) *max_element(x.begin(),x.end())
#define MIN(x) *min_element(x.begin(),x.end())
#define couty cout<<"Yes"<<endl
#define coutn cout<<"No"<<endl
#define coutY cout<<"YES"<<endl
#define coutN cout<<"NO"<<endl
#define yn(x) cout<<(x?"Yes":"No")<<endl
#define YN(x) cout<<(x?"YES":"NO")<<endl
long long gcd(long long a,long long b){return b?gcd(b,a%b):a;}
long long lcm(long long a, long long b){return a/gcd(a,b)*b;}
const long long dx[8]={1,0,-1,0,1,-1,-1,1};
const long long dy[8]={0,1,0,-1,1,1,-1,-1};
const long long INF = 1e15;
const long long MOD = 1e9+7;

signed main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    cout<<fixed<<setprecision(15);

    string s; cin >> s;
    int k; cin >> k;
    int n=s.size();

    rep(i,n){
        if(s[i]=='a' && i!=n-1) continue;
        if('z'-s[i]+1<=k){
            k-=('z'-s[i]+1); s[i]='a'; 
        }
        if(i==n-1 && k>0){
            s[i]=(char)((s[i]-'a'+k)%26+'a');
        }
    }
    cout<<s<<endl;
}

Measured memory_bytes: 3748
package main

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

var (
	rdr   = bufio.NewReaderSize(os.Stdin, 1000000)
	reply string
)

func main() {
	var h, w, n string
	fmt.Scan(&h, &w, &n)
	solve([]string{h, w, n})
}

func solve(buf []string) {
	h, _ := strconv.Atoi(buf[0])
	w, _ := strconv.Atoi(buf[1])
	n, _ := strconv.Atoi(buf[2])
	var sum, count int

	if h < w {
		h = w
	}
	for ; sum < n; count++ {
		sum += h
	}
	reply = strconv.Itoa(count)
	fmt.Println(reply)
}

func hoge(a int, s string) int {
	sum := a
	for i := 1; i < len(s); i++ {
		n, _ := strconv.Atoi(s[:i])
		sum += hoge(a+n, s[i:])
	}
	ab, _ := strconv.Atoi(s)
	return ab + sum
}

func readLine() string {
	buf := make([]byte, 0, 1000000)
	for {
		l, p, e := rdr.ReadLine()
		if e != nil {
			panic(e)
		}
		buf = append(buf, l...)
		if !p {
			break
		}
	}
	return string(buf)
}

func nextSlice() []string {
	return strings.Split(readLine(), " ")
}

func atoi(a []string) (b []int) {
	b = make([]int, len(a))
	for i := range a {
		b[i], _ = strconv.Atoi(a[i])
	}
	return
}

func atof(a []string) (b []float64) {
	b = make([]float64, len(a))
	for i := range a {
		b[i], _ = strconv.ParseFloat(a[i], 64)
	}
	return
}

func scanSlice2(n int) (a []int, b []int) {
	a = make([]int, n)
	b = make([]int, n)
	for i := 0; i < n; i++ {
		fmt.Scan(&a[i], &b[i])
	}
	return
}

func scanFloatSlice2(n int) (a []float64, b []float64) {
	a = make([]float64, n)
	b = make([]float64, n)
	for i := 0; i < n; i++ {
		fmt.Scan(&a[i], &b[i])
	}
	return
}

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

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

func gcd(a, b int) int {
	if b == 0 {
		return a
	}
	return gcd(b, a%b)
}

func min(a ...int) int {
	min := a[0]
	for i := 1; i < len(a); i++ {
		if min > a[i] {
			min = a[i]
		}
	}
	return min
}

func max(a ...int) int {
	max := a[0]
	for i := 1; i < len(a); i++ {
		if max < a[i] {
			max = a[i]
		}
	}
	return max
}

func sum(a []int) (ans int) {
	for i := range a {
		ans += a[i]
	}
	return
}

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

func yesOrNo(b bool) {
	if b {
		reply = "Yes"
		fmt.Println(reply)
		return
	}
	reply = "No"
	fmt.Println(reply)
}

func yesorNO(b bool) {
	if b {
		reply = "Yes"
		fmt.Println(reply)
		return
	}
	reply = "No"
	fmt.Println(reply)
}

Measured memory_bytes: 640
import java.util.HashMap;
import java.util.Map;
import java.util.Scanner;

public class Main {

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

        final int N = sc.nextInt();
        Map<Integer, Integer> map = new HashMap<>();
        for (int i = 0; i < N; i++) {
            int a = sc.nextInt();
            if (!map.containsKey(a)) map.put(a, 0);
            map.put(a, map.get(a) + 1);
        }

        for (int value: map.values()) {
            if (value > 1) {
                System.out.println("NO");
                return;
            }
        }
        System.out.println("YES");
    }
}


Measured memory_bytes: 100820
from collections import defaultdict, Counter
from heapq import heapify, heappop, heappush
from sys import stdin
 
def main():
    n = int(input())
    S = ["".join(sorted(input())) for _ in range(n)]

    ans = 0
    dd = defaultdict(int)
    for s in S:
        ans += dd[s]
        dd[s] += 1
    print(ans)
 
input = lambda: stdin.readline().rstrip()
main()

Measured memory_bytes: 19740
import java.util.*;
class Main {
	public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        String s = sc.next();
        if(s.equals(s.toLowerCase())&&!s.equals(s.toUpperCase())){
            System.out.println("a");
        } else {
            System.out.println("A");
        }
    }
}


Measured memory_bytes: 35656
import java.util.*;

public class Main {

    public static void main(String[] args) {

        Scanner sc = new Scanner(System.in);

        int a = sc.nextInt();
        int b = sc.nextInt();
        int c = sc.nextInt();

        String result = "Yes";
        if (a == b && a == c) {
            result = "No";
        } else if (a != b && a != c && b != c) {
            result = "No";
        }


        System.out.println(result);
    }
}

Measured memory_bytes: 21844
if __name__ == '__main__':
    n, x, y = map(int, input().split())
    x, y = x - 1, y - 1
    k = [0] * (n - 1)
    for i in range(n):
        tmp = 0
        for j in range(i):
            if i == j:
                continue
            t = min(abs(i - j), abs(i - x) + 1 + abs(y - j), abs(i - y) + 1 + abs(x - j))
            k[t - 1] += 1
    for i in k:
        print(i)


Measured memory_bytes: 46556
#include <bits/stdc++.h>
#define mod 1000000007
#define mod998 998244353
#define sp ' '
#define intmax 2147483647
#define llmax 9223372036854775807
#define mkp make_pair
typedef long long ll;
using namespace std;

int N, A, c[300000], s[300000], res, p;

int main() {
	cin >> N;
	for (int i = 0; i < N; i++) {
		cin >> A;
		c[A - 1]++;
	}
	sort(c, c + N);
	s[0] = c[0];
	for (int i = 1; i < N; i++) {
		s[i] = s[i - 1] + c[i];
	}
	res = N;
	p = N - 1;
	for (int i = 1; i <= N; i++) {
		while ((s[p] + (N - 1 - p)*res) / i < res) {
			res--;
			while (p&&c[p] >= res) {
				p--;
			}
		}
		cout << res << endl;
	}
}

Measured memory_bytes: 3200
#include <bits/stdc++.h>
#define ft first
#define sc second
#define lb lower_bound
#define ub upper_bound
#define pb push_back
#define pt(sth) cout << sth << "\n"
#define chmax(a, b) {if(a<b) a=b;}
#define chmin(a, b) {if(a>b) a=b;}
#define moC(a, s, b) (a)=((a)s(b)+MOD)%MOD
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
static const ll INF=1e18;
static const ll MAX=1e5+7;
static const ll MOD=1e9+7;
ll max(ll a, ll b) {return a>b?a:b;}
ll min(ll a, ll b) {return a<b?a:b;}


int main(void) {
  ll N;
  cin >> N;
  
  ll max=0;
  ll ans=0;
  
  for(ll i=0; i<N; i++) {
    ll h;
    cin >> h;
    chmax(max, h);
    if(max<=h) ans++;
  }
  
  pt(ans);
}












Measured memory_bytes: 256
# D
L = int(input())
A_list = [0]*L
for i in range(L):
    A_list[i] = int(input())
    
DP = [0]*5
for i in range(L):
    r0 = A_list[i]
    r1 = (A_list[i] + 1) % 2
    if A_list[i] == 0:
        r2 = 2
    else:
        r2 = A_list[i] % 2
        
    DP[4] = min(DP[0], DP[1], DP[2], DP[3], DP[4]) + r0
    DP[3] = min(DP[0], DP[1], DP[2], DP[3]) + r2
    DP[2] = min(DP[0], DP[1], DP[2]) + r1
    DP[1] = min(DP[0], DP[1]) + r2
    DP[0] = DP[0] + r0
    
print(min(DP))

Measured memory_bytes: 10868
n, k = map(int, input().split())
scaffolds = list(map(int, input().split()))
dp = [10 ** 5 * 10 ** 4] * n
dp[0] = 0
for i in range(n):
    for j in range(1, k + 1):
        if i + j >= n:
            break
        dp[i + j] = min(dp[i + j], abs(scaffolds[i] - scaffolds[i + j]) + dp[i])
print(dp[-1])

Measured memory_bytes: 52448
import std.stdio, std.array, std.string, std.conv, std.algorithm;
import std.typecons, std.range, std.random, std.math, std.container;
import std.numeric, std.bigint, core.bitop, core.stdc.string;

void main() {
    auto s = readln.split.map!(to!int);
    auto N = s[0];
    auto Q = s[1];
    auto st = new LazySegmentTree!(long, long, min, (a,b)=>a+b, (a,b)=>a+b, (a,b)=>a, 1L<<59, 0L)(N+1);
    st.table[] = 0L;

    while (Q--) {
        s = readln.split.map!(to!int);
        int q = s[0];
        int l = s[1];
        int r = s[2];
        if (q == 0) {
            long v = s[3];
            st.update(l, r, v);
        } else {
            st.query(l, r).writeln;
        }
    }
}


class LazySegmentTree(T, L, alias opTT, alias opTL, alias opLL, alias opPrd, T eT, L eL) {
    T[] table;
    L[] lazy_;
    int n;
    int size;

    this(int n) {
        this.n = n;
        size = 1;
        while (size <= n) size <<= 1;
        size <<= 1;
        table = new T[](size);
        lazy_ = new T[](size);
        table[] = eT;
        lazy_[] = eL;
    }

    void push(int i, int a, int b) {
        if (lazy_[i] == eL) return;
        table[i] = opTL(table[i], opPrd(lazy_[i], b - a + 1));
        if (i * 2 + 1 < size) {
            lazy_[i*2] = opLL(lazy_[i*2], lazy_[i]);
            lazy_[i*2+1] = opLL(lazy_[i*2+1], lazy_[i]);
        }
        lazy_[i] = eL;
    }

    T query(int l, int r) {
        if (l > r) return eT;
        return query(l, r, 1, 0, n-1);
    }

    T query(int l, int r, int i, int a, int b) {
        if (b < l || r < a) return eT;
        push(i, a, b);
        if (l <= a && b <= r) {
            return table[i];
        } else {
            return opTT(query(l, r, i*2, a, (a+b)/2), query(l, r, i*2+1, (a+b)/2+1, b));
        }
    }

    void update(int l, int r, L val) {
        if (l > r) return;
        update(l, r, 1, 0, n-1, val);
    }

    void update(int l, int r, int i, int a, int b, L val) {
        if (b < l || r < a) {
            push(i, a, b);
        } else if (l <= a && b <= r) {
            lazy_[i] = opLL(lazy_[i], val);
            push(i, a, b);
        } else {
            push(i, a, b);
            update(l, r, i*2, a, (a+b)/2, val);
            update(l, r, i*2+1, (a+b)/2+1, b, val);
            table[i] = opTT(table[i*2], table[i*2+1]);
        }
    }
}



Measured memory_bytes: 7416
#include<iostream>
#define ll long long
#define mp make_pair
using namespace std;
const int mxn=3e5+5;
int n,m,x,y;
int a[mxn],b[mxn];
int main(){
	int ans=0;
	cin>>n>>m;
	for(int i=1;i<=n;++i){
		for(int j=20;j<=m;++j){
			if(j%10<2)continue;
			if((j%10)*(int)(j/10)==i){
//				cerr<<i<<' '<<j<<endl;
				++ans;
			}
		}
	}
	cout<<ans<<endl;
}

Measured memory_bytes: 888
using System;

public class ABC114B {
  static public void Main(string[] args){
    string[] buf;
    buf = Console.ReadLine().Split(' ');
    string S = buf[0];
    int target = 753;
    int minDiff = int.MaxValue;
    for (int i = 0; i < S.Length - 2; i++) {
      int num = int.Parse(S.Substring(i, 3));
      int diff = Math.Abs(num - target);
      if (diff < minDiff) {
        minDiff = diff;
      }
    }
    Console.WriteLine(minDiff);
  }
}


Measured memory_bytes: 11092
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(ll i = 0, i##_len = (n); i < i##_len; ++i)
#define rep2(i, x, n) for(ll i = x, i##_len = (n); i < i##_len; ++i)
#define all(n) begin(n), end(n)
using ll = long long;
using P = pair<ll, ll>;
using vi = vector<int>;
using vl = vector<ll>;
using vs = vector<string>;
using vc = vector<char>;
using vb = vector<bool>;
using vd = vector<double>;
vi dir = {-1, 0, 1, 0, -1, -1, 1, 1, -1};

int main() {
  ll n, k;
  cin >> n >> k;
  vector<P> p(n);
  rep(i, n) cin >> p[i].second >> p[i].first;
  sort(all(p), greater<P>());
  set<ll> type;
  priority_queue<ll, vl, greater<ll>> q;
  ll base = 0;
  rep(i, k) {
    if(type.count(p[i].second))
      q.push(p[i].first);
    else
      type.insert(p[i].second);
    base += p[i].first;
  }
  ll ans = base + type.size() * type.size();
  rep2(i, k, n) {
    if(q.empty()) break;
    if(type.count(p[i].second)) continue;
    type.insert(p[i].second);
    base += p[i].first;
    ll mn = q.top();
    q.pop();
    base -= mn;
    ans = max(ans, base + ll(type.size() * type.size()));
  }
  cout << ans << endl;
}

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

int main(){
	string n;
	cin>>n;
	int len=sizeof(n);
	for(int i=0;i<len;i++){
		if(n[i]=='7'){
			printf("Yes");
			return 0;
		}
		else{
			continue;
		}
	}
	printf("No");
	return 0;
}

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

const int MOD=1000000007;
const int INF=0x3f3f3f3f;
const ll INFL=0x3f3f3f3f3f3f3f3f;

#include <atcoder/dsu>
using namespace atcoder;

int main(){
	int n,q;cin>>n>>q;
	dsu uf(n);
	rep(i,q){
		int t,u,v;cin>>t>>u>>v;
		if(t==0)uf.merge(u,v);
		else cout<<(uf.same(u,v)?1:0)<<endl;
	}
}

Measured memory_bytes: 3968
#include<bits/stdc++.h>
#define ll long long
#define pb push_back

using namespace std;

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int a, h;
    cin>>h>>a;
    int ans = 0;
    if(h%a == 0)
        ans = h/a;
    else
    {
        ans = h/a + 1;
    }
    cout<<ans;
}

Measured memory_bytes: 256
#
# 　　  ⋀_⋀　 
#　　  (･ω･)  
# .／ Ｕ ∽ Ｕ＼
#  │＊　合　＊│
#  │＊　格　＊│ 
#  │＊　祈　＊│ 
#  │＊　願　＊│ 
#  │＊　　　＊│ 
#      ￣
#
import sys
sys.setrecursionlimit(10**6)
input=sys.stdin.readline
from math import floor,ceil,sqrt,factorial,hypot,log #log2ないｙｐ
from heapq import heappop, heappush, heappushpop
from collections import Counter,defaultdict,deque
from itertools import accumulate,permutations,combinations,product,combinations_with_replacement
from bisect import bisect_left,bisect_right
from copy import deepcopy
inf=float('inf')
mod = 10**9+7
def pprint(*A): 
    for a in A:     print(*a,sep='\n')
def INT_(n): return int(n)-1
def MI(): return map(int,input().split())
def MF(): return map(float, input().split())
def MI_(): return map(INT_,input().split())
def LI(): return list(MI())
def LI_(): return [int(x) - 1 for x in input().split()]
def LF(): return list(MF())
def LIN(n:int): return [I() for _ in range(n)]
def LLIN(n: int): return [LI() for _ in range(n)]
def LLIN_(n: int): return [LI_() for _ in range(n)]
def LLI(): return [list(map(int, l.split() )) for l in input()]
def I(): return int(input())
def F(): return float(input())
def ST(): return input().replace('\n', '')
def main():
    S=ST()
    if 15-len(S)+S.count("o")>=8:
        print("YES")
    else:
        print("NO")
if __name__ == '__main__':
    main()

Measured memory_bytes: 38512
N = int(input())

p = list(map(int, input().split()))

res = 0

if p[0] == 1:
    p[0] = p[1]
    p[1] = 1
    res += 1

if p[N - 1] == N:
    p[N - 1] = p[N - 2]
    p[N - 2] = N
    res += 1


for i in range(1, N - 1):
    if p[i] == i + 1:
        p[i + 1] = i + 1
        res += 1

print(res)

Measured memory_bytes: 20552
#include <stdio.h>
#include <string.h>

int main(){
  int i;
  int n,m;
  int k;
  int x;

  scanf("%d %d",&n,&m);

  if(n==1){
    i=m;
  }else{
    for(i=m/2+1; i>=1; i--){
      if(m%i==0){
        if((m/i)>=n){
          break;
        }
      }
    }
  }

  printf("%d\n",i);

  return 0;
}


Measured memory_bytes: 128
import sys


def solve():
    readline = sys.stdin.buffer.readline
    mod = 10 ** 9 + 7
    n, h = list(map(int, readline().split()))
    a, b = [], []
    for i in range(n):
        av, bv = list(map(int, readline().split()))
        a.append(av)
        b.append(bv)
    a.sort()
    b.sort()
    cnt = 0
    while True:
        if h != 0:
            av = a.pop()
            if len(b) != 0:
                bv = b.pop()
                if bv > av:
                    cnt += 1
                    h -= min(h, bv)
                    a.append(av)
                else:
                    cnt += (h + av - 1) // av
                    h = 0
            else:
                cnt += (h + av - 1) // av
                h = 0
        else:
            print(cnt)
            exit()


if __name__ == '__main__':
    solve()


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

int main()
{
	int H, W;
	while (true) {
		cin >> H >> W;
		if ((H == 0) && (W == 0))break;
		for (int i = 1; i <= H; i++) {
			if ((i == 1) || (i == H)) {
				for (int j = 1; j <= W; j++) cout << "#";
				cout << endl;
			}
			else {
				for (int j = 1; j <= W; j++) {
					if ((j == 1) || (j == W)) cout << "#";
					else cout << ".";
				}
				cout << endl;
			}
		}
		cout << endl;
	}
	
}


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


#define ll long long int
#define pb push_back
#define F first
#define S second 
#define f(i,n) for(ll i = 0; i < n; i++)
using namespace std;
ll solve(ll n, ll coins[])

{

    //matrix to store results

    ll dp[n][n];

 

    //dp[i][j]=maximum amount you can definitely win if you move first with available coins[i...j]

 

    ll i,j;

 

    //initialization

    //if we have only one coin and we have to move first, we will pick that coin

    for(j=0;j<n;j++)

    {

        dp[j][j]=coins[j];

    }

 

    //if we have only two coins and we have to move first, we will pick the coin of higher value

    for(j=0;j<n-1;j++)

        dp[j][j+1]=max(coins[j],coins[j+1]);

 

    //we will calculate results for a row of i coins 

    for(i=2;i<n;i++)

    {

        //we will calculate result dp[j][j+i]

        for(j=0;j+i<n;j++)

        {

            ll x=coins[j]+min(dp[j+2][j+i],dp[j+1][j+i-1]);

            ll y=coins[j+i]+min(dp[j+1][j+i-1],dp[j][j+i-2]);

 

            dp[j][j+i]=max(x,y);

        }

    }

 

    return dp[0][n-1];

}

 
int main()
{
 
     #ifndef ONLINE_JUDGE
     freopen("input.txt","r",stdin);
     freopen("output.txt","w",stdout);
     #endif
     //soe();
      ll n; cin>>n;
      ll a[n];
      ll sum = 0;
      ll x;
      f(i,n) 
      {
          cin>>x;
          sum += x;
          a[i] = x;
      }
      ll i = 0, j = n-1;
      
       
      //cout<<sum;
      if(n == 1)
      {
        cout<<a[0];
        return 0;
      }

      ll z = solve(n,a);
      ll o = sum - z;
      cout<<(z-o)<<endl;

     return 0;
}

Measured memory_bytes: 49760
#include<iostream>
#include<math.h>
#include<algorithm>
#include<stdint.h>
#include<vector>
#include<deque>
#include<stack>
#include<string>
#include<cstring>
#include<time.h>
#include<array>
#include<iomanip>
#include<list>
#include<set>
#include<unordered_map>
#include<unordered_set>
#include<random>
#include<bitset>
#include <queue>
#include <map>


using namespace std;
using ll = long long;
using ull = unsigned long long;
using uint = unsigned int;
using ldouble = long double;


//BDD,ZDD,kdtree, bdtree,bicalc, bolonoy, doloney,chinesemod,segmenttree,daikusutora, saidairyuu, 2bugurahu, heirokenshutu, topologicalsort, kyourenketuseibun


#define PRI(s) cout << s << endl
#define PRIY PRI("Yes")
#define PRIN PRI("No")

int ctoi(char c) {
	switch (c)
	{
	case '0': return 0;
	case '1': return 1;
	case '2': return 2;
	case '3': return 3;
	case '4': return 4;
	case '5': return 5;
	case '6': return 6;
	case '7': return 7;
	case '8': return 8;
	case '9': return 9;
	default:
		cout << "ERR_ctoi" << endl;
		return -1;
	}
}
int main() {
	string s;
	cin >> s;
	for (int i = 0; i < 3; ++i) {
		if (s[i] == '1') s[i] = '9';
		else s[i] = '1';
	}
	PRI(s);
	return 0;
}

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


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

struct edge {int to; ll cost; };

int dx[] = {-1, 1, 0,  0};
int dy[] = { 0, 0, 1, -1};
 
int main(){
  int n, m;
  cin >> n >> m;
  vector<int> a(n);
  for(int i=0; i<n; i++){
    cin >> a[i];
  }
  sort(a.begin(), a.end());
  vector<P> vt;
  for(int i=0; i<m; i++){
    int b, c;
    cin >> b >> c;
    vt.push_back(make_pair(c, b));
  }
  sort(vt.begin(), vt.end(), greater<P>());
  int k = 0;
  bool isend = false;
  for(int i=0; i<m; i++){
    if(k>=n) break;
    P p = vt[i];
    for(int j=0; j<p.second; j++){
      if(k>=n) break;
      if(a[k]>=p.first){
        isend=true;
        break;
      }
      a[k] = p.first;
      k++;
    }
    if(isend) break;
  }
  ll ans = 0;
  for(int i=0; i<n; i++){
    ans += a[i];
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 5680
#include <bits/stdc++.h>
#include <complex>
#include <iomanip>
using namespace std;
#define reps(i,s,n) for(int i = s; i < n; i++)
#define rep(i,n) reps(i,0,n)
#define fi first
#define se second
#define mp make_pair
typedef long long ll;
typedef vector<ll> vec;
typedef vector<vec> mat;

ll N,M,H,W,K,Q,A,B,C,L,R;
string S,T;
const ll MOD = (1e+9) + 7;
const ll INF = 1LL << 60;
const long double EPS = 1e-9;
typedef pair<ll,ll> P;

typedef vector<P> vp;
typedef vector<vp> matP;


int main() {
    cin>>N;
    vec a(N), b(N), c(N-1);
    rep(i,N) {
        cin>>A;
        a[i] = --A;
    }
    ll ans = 0, last = N;
    rep(i,N) {
        cin>>b[i];
        ans += b[i];
    }
    rep(i,N-1) cin>>c[i];
    rep(i,N){
        ll now = a[i];
        if(last + 1 == now) ans += c[last];
        last = now;
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < n; i++)
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
const int MAX_XYZ = 1005;
ll A[MAX_XYZ],B[MAX_XYZ],C[MAX_XYZ],ans[MAX_XYZ*3];
ll X,Y,Z,K;

bool f(ll x)
{
	ll cnt = 0;
	rep(i,X)
	{
		rep(j,Y)
		{
			ll s = A[i]+B[j];
			int l = -1, r = Z;
			while(l+1 < r)
			{
				int m = (l+r)/2;
				if (s+C[m] >= x) l = m;
				else r = m;
			}
			cnt += l+1;
		}
	}
	if (cnt >= K) return true;
	else return false;
}

int main()
{
	cin >> X >> Y >> Z >> K;
	rep(i,X)
	{
		cin >> A[i];
	}
	sort(A,A+X);
	reverse(A,A+X);
	rep(i,Y)
	{
		cin >> B[i];
	}
	sort(B,B+Y);
	reverse(B,B+Y);
	rep(i,Z)
	{
		cin >> C[i];
	}
	sort(C,C+Z);
	reverse(C,C+Z);
	ll l = 0, r = ll(1e11);
	while(l+1 < r)
	{
		ll m = (l+r)/2;
		if (f(m)) l = m;
		else r = m;
		//cout << l << " " << r << endl;
	}
	ll cnt = 0;
	bool flag;
	rep(i,X)
	{
		rep(j,Y)
		{
			flag = false;
			rep(k,Z)
			{
				if (A[i]+B[j]+C[k] > l)
				{
					ans[cnt] = A[i]+B[j]+C[k];
					cnt++;
				}
				else break;
			}
		}
	}
	while(cnt < K)
	{
		ans[cnt] = l;
		cnt++;
	}
	sort(ans,ans+cnt);
	reverse(ans,ans+cnt);
	rep(i,cnt)
	{
		cout << ans[i] << endl;
	}
	return 0;
}

Measured memory_bytes: 384
#include<iostream>
#include<string>
using namespace std;
int main(void)
{
    string s,t;
    bool a=false;
    int b=0;
    cin >> s >> t;
    if(t.size()==s.size()+1) a=true;
    for(int i=0;i<t.size()-1;i++)
        if(t[i]==s[i])
            b++;
    if(a==true && b==t.size()-1)
        cout << "Yes";
    else cout << "No";
    return 0;
}


Measured memory_bytes: 3596
#include <stdio.h>
using namespace std;
int div_cnt[205];
int N;
int main(void){
	scanf("%d", &N);
	for(int i = 1; i <= N; i++){
		for(int j = 1; j*i <= N; j++){
			div_cnt[j*i]++;
		}
	}
	int ans = 0;
	for(int i = 1; i <= N; i++){
		if(div_cnt[i] == 8 && i&1){
			ans++;
		}
	}
	printf("%d\n", ans);
	return 0;
}



Measured memory_bytes: 128
#pragma GCC optimize ("Ofast")
#pragma GCC target ("avx2")
//#include<bits/stdc++.h>
#include<cstdio>
#include<cstring>

//同じコードでそんなにばらつくんですか

using namespace std;
typedef long long ll;
#define rep(i, n) for(int i = 0; i < (n); i++)
#define rep1(i, n) for(int i = 1; i <= (n); i++)
#define co(x) cout << (x) << "\n"
#define cosp(x) cout << (x) << " "
#define ce(x) cerr << (x) << "\n"
#define cesp(x) cerr << (x) << " "
#define pb push_back
#define mp make_pair
#define chmin(x, y) x = min(x, y)
#define chmax(x, y) x = max(x, y)
#define Would
#define you
#define please

const int CM = 130000, CL = 12;
char cn[CM + CL], * ci = cn + CM + CL, * owa = cn + CM, ct;
const ll ma0 = 1157442765409226768;
const ll ma1 = 1085102592571150095;
const ll ma2 = 71777214294589695;
const ll ma3 = 281470681808895;
const ll ma4 = 4294967295;
inline int getint() {
	if (ci - owa > 0) {
		memcpy(cn, owa, CL);
		ci -= CM;
		fread(cn + CL, 1, CM, stdin);
	}
	ll tmp = *(ll*)ci;
	int dig = ((tmp & ma0) ^ ma0) ? 68 - __builtin_ctzll((tmp & ma0) ^ ma0) : 0;
	tmp = tmp << dig & ma1;
	tmp = tmp * 10 + (tmp >> 8) & ma2;
	tmp = tmp * 100 + (tmp >> 16) & ma3;
	tmp = tmp * 10000 + (tmp >> 32) & ma4;
	ci += (64 - dig >> 3);
	while ((ct = *ci++) >= '0') tmp = tmp * 10 + ct - '0';
	return tmp;
}

int H[100001];
bool NG[100001];
int main() {
	//cin.tie(0);
	//ios::sync_with_stdio(false);


	int N = getint(), M = getint();
	rep1(i, N) H[i] = getint();
	rep(i, M) {
		int a = getint(), b = getint();
		if (H[a] >= H[b]) NG[b] = 1;
		if (H[a] <= H[b]) NG[a] = 1;
	}
	int kotae = N;
	rep1(i, N) kotae -= NG[i];

	printf("%d", kotae);

	Would you please return 0;
}

Measured memory_bytes: 2216
#include <iostream>
#include <cmath>

using namespace std;

int main()
{
    cin.tie(0);
   	ios::sync_with_stdio(false);
    
    int n;
    cin >> n;
    
    long long a[n];
    
    for (int i = 0; i < n; i++) {
        cin >> a[i];
    }
    
    long long dp[n + 1][2];
    
    dp[0][0] = 0;
    dp[0][1] = -100000000000000;
    
    for (int i = 1; i <= n; i++) {
        dp[i][0] = max(dp[i - 1][0] + a[i - 1], dp[i - 1][1] - a[i - 1]);
        dp[i][1] = max(dp[i - 1][0] - a[i - 1], dp[i - 1][1] + a[i - 1]);
    }
    
    cout << dp[n][0] << endl;
}


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

using namespace std;

int main() {
  long long n, a, b;
  cin >> n >> a >> b;
  if(a == 0) cout << 0 << endl;
  else {
    long long result = n / (a+b) * a;
    result += min(n % (a+b), a);
    cout << result << endl;
  }
}


Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <cctype>
#include <cassert>
#include <climits>
#include <string>
#include <bitset>
#include <cfloat>
//#include <unordered_set>

using namespace std;

const int INF = INT_MAX;

struct SegmentTree {
  int n;
  vector<int> node;
  
  SegmentTree(const vector<int>& v) {
    int sz = v.size();
    n = 1; while(n < sz) n *= 2;
    node.resize(2*n-1, INF);
    
    //最下段
    for(int i=0; i<sz; i++) node[i+n-1] = v[i];
    //親に入れる（下から）
    for(int i=n-2; i>=0; i--) node[i] = min(node[2*i+1], node[2*i+2]);
  }
  
  void update(int x, int val) {
    x += n - 1;
    
    node[x] = val;
    while(x > 0) {
      x = (x - 1) / 2;
      node[x] = min(node[2*x+1], node[2*x+2]);
    }
  }
  
  int getmin(int a, int b, int k=0, int l=0, int r=-1) {
    if(r < 0) r = n;
    
    if(r <= a || b <= l) return INF;
    
    if(a <= l && r <= b) return node[k];
    
    int vl = getmin(a, b, 2*k+1, l, (l+r)/2);
    int vr = getmin(a, b, 2*k+2, (l+r)/2, r);
    return min(vl, vr);
  }
};


signed main(void) {
  cin.tie(0); ios::sync_with_stdio(false);
  
  int n, q;
  cin >> n >> q;
  
  vector<int> v(n);
  for(int i = 0; i < n; i++) {
    v[i] = INF;
  }
  SegmentTree seg(v);
  
  for(int i = 0; i < q; i++) {
    int qtype;
    cin >> qtype;
    if(qtype == 0) {
      int i, x;
      cin >> i >> x;
      seg.update(i, x);
    } else {
      int s, t;
      cin >> s >> t;
      ++t;
      cout << seg.getmin(s, t) << endl;
    }
  }  

}


Measured memory_bytes: 4052
#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <fstream>
#include <sstream>
#include <set>
#include <map>
#include <vector>
#include <list>
#include <algorithm>
#include <cstring>
#include <cmath>
#include <string>
#include <stack>
#include <queue>
#include <bitset>     //UWAGA - w czasie kompilacji musi byc znany rozmiar wektora - nie mozna go zmienic
#include <cassert>
#include <iomanip>        //do setprecision
#include <ctime>
#include <complex>
using namespace std;

#define FOR(i,b,e) for(int i=(b);i<(e);++i)
#define FORQ(i,b,e) for(int i=(b);i<=(e);++i)
#define FORD(i,b,e) for(int i=(b)-1;i>=(e);--i)
#define REP(x, n) for(int x = 0; x < (n); ++x)

#define ST first
#define ND second
#define PB push_back
#define PF push_front
#define MP make_pair
#define LL long long
#define ULL unsigned LL
#define LD long double
#define pii pair<int,int>
#define pll pair<LL,LL>
#define vi vector<int>
#define vl vector<LL>
#define vii vector<vi>
#define vll vector<vl>

const double pi = 3.14159265358979323846264;
const int mod=1000000007;

int func(LL n,LL d){
    int c=0;
    while(n!=0){
        if(n%d==0){
            c++;
            n/=d;
        }else{
            break;
        }
    }
    return c;
}

pair<int,int> parse(string s){
    LL nm=0,c=1000*1000*1000,f=0,ln=s.length();
    FOR(i,0,ln){
        if(s[i]=='.'){
            f=1;
        }else{
            nm*=10;
            nm+=s[i]-'0';
            if(f){
                c/=10;
            }
        }
    }
    nm*=c;
    //cerr<<"nm:"<<nm<<endl;
    return make_pair(func(nm,2),func(nm,5));
}

int main(){
	int n;
    cin>>n;
    vii v(25,vi(25,0));
    vector<pii> vp(n);
    FOR(i,0,n){
        string s;
        cin>>s;
        auto p=parse(s);
        //cerr<<"**"<<p.ST<<" "<<p.ND<<"**"<<endl;
        v[min(p.ST,22)][min(p.ND,22)]++;
        vp[i]=p;
    }

    LL ans=0;
    FOR(i,0,n){
        int c2=vp[i].ST;
        int c5=vp[i].ND;
        int r2=max(18-c2,0);
        int r5=max(18-c5,0);
        if(r2<=c2&&r5<=c5){
            ans--;
        }
        FOR(i,r2,23){
            FOR(j,r5,23){
                ans+=v[i][j];
            }
        }
    }
    cout<<ans/2<<endl;

}


Measured memory_bytes: 4740
#include <bits/stdc++.h>
using namespace std;
///////////////////////////////////////////
const long long int INF = 1LL<<60;
const long long int Mod = 1000000007;
using ll = long long int; using ci = const int;
using vi = vector<int>;  using Vi = vector<long long int>;
using P = pair<int, int>;  using PLL = pair<ll, ll>;
using matrix = vector<vector<ll>>;
#define pb(x) push_back(x)
#define mp(x,y) make_pair(x,y)
#define all(x) (x).begin(),(x).end()
#define rp(i,N) for(ll i = 0; i < (ll)N; i++)
#define repi(i,a,b) for(ll i = ll(a); i < ll(b); ++i)
template<class T>bool chmax(T &former, const T &b) { if (former<b) { former=b; return true; } return false; }
template<class T>bool chmin(T &former, const T &b) { if (b<former) { former=b; return true; } return false; }
template<class T>T sqar(T x){ return x*x; }//sqrt(x)は平方根;
#define Sort(v) std::sort(v.begin(), v.end(), std::greater<decltype(v[0])>()) //降順でVをソート
#define p_queue(v) priority_queue<v, vector<v>, greater<v> >
template<class T> inline void princ(T x){cout<<x<<" ";}; 
template<class T> inline void print(T x){cout<<x<<"\n";};
template<class T> inline void Yes(T condition){ if(condition) cout << "Yes" << endl; else cout << "No" << endl; }
template<class T> inline void YES(T condition){ if(condition) cout << "YES" << endl; else cout << "NO" << endl; }
///////////////////////////////////////////////////////////////////////////////////

void solve(){
    int n;
    cin >> n;
    if(n<1000){
        print("ABC");
    }
    else{
        print("ABD");
    }
    return;
}
int main(){
    cin.tie(0);ios::sync_with_stdio(false);
    std::cout<<std::fixed<<std::setprecision(30);
    solve();
    return 0;
}

Measured memory_bytes: 256
#include<cstdio>
#include<cmath>
#include<bitset>
#include<iostream>
#include<algorithm>
#include<string>
#include<vector>
#define IOS ios::sync_with_stdio(false),cin.tie(0)
using namespace std;
typedef long long ll;

int main() {
	IOS;
	ll ans = 0;
	ll tmp, digit, sum;
	string s;
	string ssum = "";
	vector<string> nums;
	cin >> s;
	ll bits;
	ll i;
	for (i = 0; i < s.size(); i++)nums.push_back(s.substr(i, 1));
	for (bits = 0; bits < (1 << (s.size() - 1));bits++) {
		sum = 0;
		tmp = 0;
		ssum = nums[0];
		for (i = 0; i < s.size() - 1 ; i++) {
			if (bits & (1 << i)) {
				sum += stol(ssum);
				ssum = "";
			}
			ssum += nums[i + 1];
		}
		sum += stol(ssum);
		ans += sum;
	}

	cout << ans << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <map>
#include <vector>
#include <queue>
#include <algorithm>

using namespace std;

//typedef pair<int,int> P;


int main(){
	map<long long, int> mp;

	int N;
	scanf("%d", &N);

	for(int i=0;i<N;i++){
		long long A;
		scanf("%lld", &A);
		if(mp.count(A) == 0){
			mp.insert(make_pair(A,i+1));
		}else{
			mp.erase(A);
		}
	}

	printf("%d\n", mp.size());

	return 0;
}


Measured memory_bytes: 6528
#include<iostream>
using namespace std;
int main()
{
    int n, m, a[30] = {0}, k, n_ans, ans = 0;
    cin >> n >> m;
    for(int i = 0; i < n; i++){
        cin >> k;
        for(int j = 0; j < k; j++){
            cin >> n_ans;
            ++a[n_ans - 1];
        }
    }
    for(int i = 0; i < m; i++){
        if(a[i] == n) ++ans;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cmath>
#include <vector>
#include <cctype>
#include <algorithm>
#include <string>
#include <queue>
using namespace std;

void dfs(int x, int y, char map[8][9]){
    if (map[y][x] != '1') return;
    map[y][x] = '0';
    for (int i = 1; i <= 3; i++){
	if (x - i >= 0) dfs(x-i, y, map);
	if (x + i < 8) dfs(x+i, y, map);
	if (y - i >= 0) dfs(x, y-i, map);
	if (y + i < 8) dfs(x, y+i, map);
    }
}


int main(){
    char map[8][9];
    int x, y;
    int max;
    cin >> max;

    for (int num = 1; num <= max; num++){
	for (int i = 0; i < 8; i++) cin >> map[i];
	cin >> x >> y;
	dfs(x - 1, y - 1, map);
	cout << "Data " << num << ":" << endl;
	for (int i = 0; i < 8; i++)
	    cout << map[i] << endl;
    }
    return 0;
}

Measured memory_bytes: 0
X = gets.chomp

chars = Array.new(X.size) {0}
sp = 0

decrease = 0
X.chars.each_with_index do |s, i|
  if s == 'S'
    sp += 1
  else
    next if sp == 0
    sp -= 1
    decrease += 1
  end
end

puts X.size - decrease * 2


Measured memory_bytes: 18300
#include <iostream>

using namespace std;

int main() {
    int n;
    cin >> n;
    // 社員番号iの社員の上司a[i]
    int a[n-1];
    // 上司
    int count[n];

    for(int i = 0; i < n-1; i++) {
        cin >> a[i];
        count[i] = 0;
    }
    count[n-1] = 0;

    for(int i = 0; i < n-1; i++) {
        count[a[i] - 1]++;
    }

    for(int i = 0; i < n; i++) {
        cout << count[i] << endl;
    }

    return 0;

}


Measured memory_bytes: 5160
#include <iostream>
#include <stdio.h>
#include <vector>
#include <algorithm>
#include <stack>
#include <queue>
#include <string.h>

using namespace std;

int main(){
	int A, B;
	cin >> A >> B;

	if (A % 3 == 0 || B % 3 == 0 || (A + B) % 3 == 0)
		printf("Possible\n");
	else
		printf("Impossible\n");


	return 0;
}


Measured memory_bytes: 256
n=int(input())
x=[int(x) for x in input().split()]
d={}
for i in x:
	if i not in d:
		d[i]=1
	else:d[i]+=1
s=sum(x)
q=int(input())
for i in range(q):
	b,c=map(int,input().split())
	if b in d:
		zz=d[b]
		d[b]=0
		if c not in d:
			d[c]=zz
		else:d[c]+=zz
		s-=b*zz
		s+=c*zz
		print(s)
	else:
		print(s)



Measured memory_bytes: 85432
import java.util.Scanner;

class Main{
    public static void main(String[] args){
        Scanner scan = new Scanner(System.in);

        int n = Integer.parseInt(scan.nextLine());
        double Rj = 0;
        double Ri = 0;
        double newR;
        double maxProfit = -1000000000;
        double tmpProfit = -1000000000;
        double tmp = 0;
        int value;
        
        newR = Integer.parseInt(scan.nextLine());
        Rj = newR;
        Ri = newR;

        for (int i=1; i<n; i++){
            newR = Integer.parseInt(scan.nextLine());
            if (newR < Ri){
                tmp = newR - Ri;
                if (tmp > tmpProfit)
                    tmpProfit = tmp;
                Ri = newR;
                Rj = newR;
                continue;
            }
            if (newR >= Rj){
                Rj = newR;
                tmp = Rj - Ri;
                if (tmp > maxProfit)
                    maxProfit = tmp;
                continue;
            }
        }

        if (tmpProfit > maxProfit)
            maxProfit = tmpProfit;

        System.out.println((int)(maxProfit));
    }
}

Measured memory_bytes: 163792
num, bricks, count, smash = int(input()), [int(x) for x in input().split(" ")], 1, 0
for x in bricks:
    if count == x: count += 1
    else: smash += 1
print(smash if smash != len(bricks) else 0 if len(bricks) == 1 else -1)

Measured memory_bytes: 26524
use std::io::*;

mod fenwick_tree {
    use std::ops::*;
    pub struct FenwickTree<T> {
        size: usize,
        data: Vec<T>,
        identity: T,
    }
    impl<T: Copy + Clone + AddAssign + Sub<Output = T>> FenwickTree<T> {
        pub fn new(size: usize, id: T) -> FenwickTree<T> {
            FenwickTree {
                size: size,
                data: vec![id; size + 2],
                identity: id,
            }
        }
        pub fn query(&self, i: usize) -> T {
            let mut res = self.identity;
            let mut idx = i as isize - 1;
            while idx >= 0 {
                res += self.data[idx as usize];
                idx = (idx & (idx + 1)) - 1;
            }
            res
        }
        pub fn update(&mut self, i: usize, x: T) {
            let mut idx = i;
            while idx <= self.size {
                self.data[idx] += x;
                idx |= idx + 1;
            }
        }
    }
}

fn main() {
    let mut s: String = String::new();
    std::io::stdin().read_to_string(&mut s).ok();
    let mut itr = s.trim().split_whitespace();
    let n: usize = itr.next().unwrap().parse().unwrap();
    let mut s: Vec<u8> = itr.next().unwrap().bytes().collect();
    let q: usize = itr.next().unwrap().parse().unwrap();

    use fenwick_tree::FenwickTree;
    let mut st: Vec<FenwickTree<i32>> =
        (0..26).map(|_| FenwickTree::<i32>::new(n + 1, 0)).collect();

    for i in 0..n {
        s[i] -= 'a' as u8;
        st[s[i] as usize].update(i, 1);
    }

    let mut out = Vec::new();
    for _ in 0..q {
        let t: usize = itr.next().unwrap().parse().unwrap();
        if t == 1 {
            let pos: usize = itr.next().unwrap().parse::<usize>().unwrap() - 1;
            let tmp: Vec<u8> = itr.next().unwrap().bytes().collect();
            let x = tmp[0] - 'a' as u8;
            st[s[pos] as usize].update(pos, -1);
            s[pos] = x;
            st[x as usize].update(pos, 1);
        } else {
            let l: usize = itr.next().unwrap().parse().unwrap();
            let r: usize = itr.next().unwrap().parse().unwrap();
            let mut ans = 0;
            for i in 0..26 {
                let tmp = st[i].query(r) - st[i].query(l - 1);
                ans += if tmp > 0 { 1 } else { 0 };
            }
            writeln!(out, "{}", ans).ok();
        }
    }

    stdout().write_all(&out).unwrap();
}


Measured memory_bytes: 54160
#pragma GCC optimize(2)
#pragma GCC optimize(3)
#pragma GCC optimize(4)
#include<bits/stdc++.h>
using namespace std;
#define y1 y11
#define fi first
#define se second
#define pi acos(-1.0)
#define LL long long
//#define mp make_pair
#define pb push_back
#define ls rt<<1, l, m
#define rs rt<<1|1, m+1, r
#define ULL unsigned LL
#define pll pair<LL, LL>
#define pli pair<LL, int>
#define pii pair<int, int>
#define piii pair<pii, int>
#define pdd pair<double, double>
#define mem(a, b) memset(a, b, sizeof(a))
#define debug(x) cerr << #x << " = " << x << "\n";
#define fio ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
//head

const int MOD = 1e9 + 7, inv2 = 500000004;
const int N = 2e3 + 5;
int a[N], c[N], n, k; 
struct BIT {
	int bit[N];
	inline void add(int x) {
		while(x < N) bit[x]++, x += x&-x;
	}
	inline int sum(int x) {
		int ans = 0;
		while(x) ans += bit[x], x -= x&-x;
		return ans;
	}
}b;
int main() {
	scanf("%d %d", &n, &k);
	for (int i = 1; i <= n; ++i) scanf("%d", &a[i]), c[a[i]]++;
	for (int i = 1; i < N; ++i) c[i] += c[i-1];
	LL ans = 0;
	for (int i = n; i >= 1; --i) {
		LL l = b.sum(a[i]-1), r = l+(k-1)*1LL*c[a[i]-1];
		ans += (l+r)%MOD*k%MOD*inv2%MOD;
		ans %= MOD; 
		b.add(a[i]);
	}
	printf("%lld\n", ans);
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i=3; i<n; i++)
typedef int64_t lint;
const int mod = 1000000007;
struct mint {
	lint x;
	mint(lint 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(lint 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, mint& a) { return is >> a.x;}
ostream& operator<<(ostream& os, const mint& a) { return os << a.x;}


int main() {
	int N;
	cin >> N;
	vector<mint> v(N);
	v[0] = 0, v[1] = 0, v[2] = 1;
	rep(i, N) {
		v[i] = v[i-1] + v[i-3];
	}
	std::cout << v[N-1] << '\n';
}


Measured memory_bytes: 3624